1 <?php
  2 
  3   4   5   6   7   8   9  10 
 11 
 12  13  14  15  16  17  18 
 19 function wc_pos_url( $page = '' ) {
 20   $slug = WC_POS\Admin\Permalink::get_slug();
 21   return home_url( $slug . '/' .$page );
 22 }
 23 
 24 
 25  26  27  28  29  30  31 
 32 function is_pos( $type = false ) {
 33 
 34   
 35   
 36   if( $type == 'template' || !$type ){
 37     global $wp;
 38     if( isset( $wp->query_vars['pos'] ) && $wp->query_vars['pos'] == 1 ){
 39       return true;
 40     }
 41   }
 42 
 43   
 44   if( $type == 'ajax' || !$type ) {
 45     
 46     if( isset( $_SERVER['HTTP_X_WC_POS'] ) && $_SERVER['HTTP_X_WC_POS'] == 1 ){
 47       return true;
 48     }
 49     
 50     if ( function_exists( 'getallheaders' ) && is_array( getallheaders() ) && array_key_exists( 'X-WC-POS', getallheaders() ) ) {
 51       return true;
 52     }
 53   }
 54 
 55   return false;
 56 }
 57 
 58  59  60 
 61 function is_pos_admin() {
 62   if ( function_exists( 'getallheaders' )
 63     && $headers = getallheaders()
 64     && isset( $headers['X-WC-POS-ADMIN'] )
 65   ) {
 66     return $headers['X-WC-POS-ADMIN'];
 67   } elseif ( isset( $_SERVER[ 'HTTP_X_WC_POS_ADMIN' ] ) ) {
 68     return $_SERVER[ 'HTTP_X_WC_POS_ADMIN' ];
 69   }
 70 
 71   return false;
 72 }
 73 
 74      75  76  77  78  79  80  81  82 
 83 function wc_pos_update_option( $name, $value, $autoload = 'no' ) {
 84   $success = add_option( $name, $value, '', $autoload );
 85 
 86   if ( ! $success ) {
 87     $success = update_option( $name, $value );
 88   }
 89 
 90   return $success;
 91 }
 92 
 93  94  95  96  97  98  99 100 101 102 103 104 
105 function wc_pos_json_encode($data){
106   $args = array( $data, JSON_FORCE_OBJECT );
107   return call_user_func_array( 'json_encode', $args );
108 }
109 
110 111 112 113 114 115 
116 function wc_pos_locate_template($path = ''){
117   $template = locate_template(array(
118     'woocommerce-pos/' . $path
119   ));
120 
121   if( !$template ){
122     $template = WC_POS_PLUGIN_PATH. 'includes/views/' . $path;
123   }
124 
125   if ( file_exists( $template ) ) {
126     return apply_filters('woocommerce_pos_locate_template', $template, $path);
127   }
128 }
129 
130 131 132 133 134 
135 function wc_pos_get_option( $id, $key = false ){
136   $handlers = (array) WC_POS\Admin\Settings::handlers();
137   if( ! array_key_exists( $id, $handlers ) )
138     return false;
139 
140   $settings = $handlers[$id]::get_instance();
141   return $settings->get( $key );
142 }
143 
144 145 146 147 148 149 
150 function wc_pos_trim_html_string( $str ) {
151   return preg_replace( '/^\s+|\n|\r|\s+$/m', '', $str );
152 }
153