Пример #1
0
    function get_config()
    {
        // Container for configuration info
        $arr = array();
        // Try to get the configuration data
        // from a cached config file
        //
        // Added a disable option in 1.2.1 - dpd
        $disable_cache = $this->config->item('br_disable_system_cache') === TRUE ? 1 : 0;
        if ($disable_cache == 0) {
            if ($str = read_from_cache('config')) {
                $arr = unserialize($str);
                return $arr;
            }
        }
        // Get the store config
        $this->EE->db->select('	s.*, 
								c.code as currency,
								c.currency_id,
								c.marker as currency_marker')->from('br_store s')->join('br_currencies c', 'c.currency_id = s.currency_id');
        $query = $this->EE->db->get();
        foreach ($query->result_array() as $row) {
            $arr["store"][$row["site_id"]] = $row;
        }
        // Get the config data for each item
        $this->EE->db->select('*')->from('br_config_data')->order_by('sort');
        $query = $this->EE->db->get();
        foreach ($query->result_array() as $row) {
            $data[$row['config_id']][] = $row;
        }
        // Get the items
        $this->EE->db->select('*')->from('br_config')->order_by('sort');
        $query = $this->EE->db->get();
        foreach ($query->result_array() as $row) {
            $arr[$row["type"]][$row["site_id"]][$row["code"]] = $row;
            if (isset($data[$row["config_id"]])) {
                $arr[$row["type"]][$row["site_id"]][$row["code"]]["config_data"] = $data[$row["config_id"]];
            }
        }
        // Save the new array to cache
        save_to_cache('config', serialize($arr));
        return $arr;
    }
Пример #2
0
    /**
     * Get products into an array
     *
     * The method attempts to get the products by individual cached files  
     *
     * @access	public
     * @param	int,int,int
     * @return	array of products
     */
    public function get_products($product_id = '', $disabled = '', $cat = '')
    {
        // Now try to get it from
        if ($product_id != '') {
            // Try and return it from session cache
            if (isset($this->session->cache['get_products'][$product_id])) {
                $this->EE->TMPL->log_item('BrilliantRetail: return product_id (' . $product_id . ') from session data ' . round(memory_get_usage() / 1024 / 1024, 2) . 'MB');
                return $this->session->cache['get_products'][$product_id];
            }
            // Try to return from cache	unless it is disabeled in the
            // configuration file.
            $disable_cache = $this->config->item('br_disable_product_cache') === TRUE ? 1 : 0;
            if ($disable_cache == 0) {
                if ($str = read_from_cache('product_' . $product_id)) {
                    $arr[0] = unserialize($str);
                    // only return enabled cached products
                    if ($arr[0]["enabled"] == 1) {
                        $this->session->cache['get_products'][$product_id] = $arr;
                        $this->EE->TMPL->log_item('BrilliantRetail: return product_id (' . $product_id . ') from cache file ' . round(memory_get_usage() / 1024 / 1024, 2) . 'MB');
                        return $arr;
                    }
                }
            }
            // Get the specific product id
            $this->EE->db->where('product_id', $product_id);
        }
        if ($disabled == '') {
            $this->EE->db->where('enabled >', 0);
        }
        $this->EE->db->from('br_product p');
        if ($cat != "") {
            $this->EE->db->join("br_product_category c", "p.product_id=c.product_id");
            $this->EE->db->where("c.category_id", $cat);
        }
        $this->EE->db->where('p.site_id', $this->config->item('site_id'));
        $this->EE->db->order_by('p.product_id', 'desc');
        $query = $this->EE->db->get();
        $products = array();
        $i = 0;
        foreach ($query->result_array() as $row) {
            // General Product Details
            $products[$i] = $row;
            // Get Product Entry Id (Experimental)
            $products[$i]["entry_id"] = $this->get_product_entry($row["product_id"]);
            // Get Product Price
            $products[$i]["price_matrix"] = $this->get_product_price($row["product_id"], 1);
            // Get Product Sale Price
            $products[$i]["sale_matrix"] = $this->get_product_price($row["product_id"], 2);
            // Product Categories
            $products[$i]["categories"] = $this->get_product_categories($row["product_id"]);
            // Product Attributes
            $attributes = $this->get_attributes($row["attribute_set_id"], $row["product_id"]);
            $products[$i]["attributes"] = '<div id="product_attributes">';
            $j = 0;
            foreach ($attributes as $attr) {
                $val = isset($attr["value"][0]) ? $attr["value"][0] : $attr["value"];
                $products[$i]["attributes"] .= ' 	<p class="label">' . $attr["title"] . '</p>
															<p>' . $val . '<p>';
                $products[$i]["attribute"][$j] = $attr;
                $products[$i]["attribute"][$j]["label"] = $attr["title"];
                $j++;
            }
            $products[$i]["attributes"] .= '</div>';
            // Product Images
            $img = $this->get_product_images($row["product_id"]);
            $k = 0;
            $products[$i]["image_large"] = '';
            $products[$i]["image_thumb"] = '';
            foreach ($img as $key => $val) {
                // Set the name based on the key
                // Integers are the individual images
                // Non-int's are the thumb and large files
                if (is_integer($key)) {
                    $products[$i]['images'][$k] = $val;
                    $k++;
                } else {
                    $products[$i][$key] = $val;
                }
            }
            // Product Images
            $img = $this->get_product_images($row["product_id"], false);
            $k = 0;
            foreach ($img as $key => $val) {
                if (is_integer($key)) {
                    if ($val["exclude"] == 1) {
                        $products[$i]['images_excluded'][$k] = $val;
                        $k++;
                    }
                }
            }
            // Product Addon
            $products[$i]["addon"] = '';
            #$this->get_product_addon($row["product_id"]);
            // Product Related
            $products[$i]["related"] = $this->get_product_related($row["product_id"]);
            // Product Options
            $products[$i]["options"] = $this->get_product_options($row["product_id"]);
            // Bundle Product Type
            if ($row["type_id"] == 2) {
                $products[$i]["bundle"] = $this->get_product_bundle($row["product_id"]);
            }
            // Configurable Product Type
            if ($row["type_id"] == 3) {
                $products[$i]["configurable"] = $this->get_product_configurable($row["product_id"]);
            }
            // Download Product Type
            if ($row["type_id"] == 4) {
                $products[$i]["download"] = $this->get_product_download($row["product_id"]);
            }
            // Donation Product Type
            if ($row["type_id"] == 7) {
                $products[$i]["donation"] = $this->get_product_donation($row["product_id"]);
            }
            save_to_cache('product_' . $row["product_id"], serialize($products[$i]));
            $i++;
        }
        // Save it to the session cache
        if ($product_id != '') {
            $this->session->cache['get_products'][$product_id] = $products;
        }
        $this->EE->TMPL->log_item('BrilliantRetail: return product_id (' . $product_id . ') from database ' . round(memory_get_usage() / 1024 / 1024, 2) . 'MB');
        return $products;
    }
 function search()
 {
     // Load native EE helper to sanitize search term
     $this->EE->load->helper('search');
     // Set the return location
     $return = $this->EE->TMPL->fetch_param('return') ? $this->EE->TMPL->fetch_param('return') : 'catalog/result';
     // Get the product search collection
     $term = $this->EE->TMPL->fetch_param('term') ? $this->EE->TMPL->fetch_param('term') : $this->EE->input->post('search', TRUE);
     $term = sanitize_search_terms($term);
     $hits = $this->_search_index($term);
     $hash = sha1(time() . $term);
     $i = 0;
     $product = array();
     foreach ($hits as $hit) {
         $tmp = $this->EE->product_model->get_products($hit["product_id"]);
         // Check to make sure that a product is returned
         if (isset($tmp[0])) {
             if ($tmp[0]["site_id"] == $this->site_id) {
                 $product[$i] = $tmp[0];
                 $product[$i]["score"] = round(100 * $hit["score"], 2);
                 $product[$i]["row_count"] = $i + 1;
                 $i++;
             }
         }
     }
     // Count the products but set
     // a reasonable search result
     // limit
     $count = count($product);
     if ($count > $this->_config["result_limit"]) {
         $lim = $count - 1;
         for ($i = $this->_config["result_limit"]; $i <= $count; $i++) {
             unset($product[$i]);
         }
         $count = $this->_config["result_limit"];
     }
     $vars[0] = array('search_hash' => $hash, 'search_term' => $term, 'total_results' => count($product), 'results' => $product, 'no_results' => array(), 'result_filter_set' => '');
     save_to_cache('search_' . $hash, serialize($vars));
     $this->EE->product_model->log_search($term, $hash, count($product), $this->EE->session->userdata["member_id"]);
     $this->EE->functions->redirect($this->EE->functions->create_url($return . '/id/' . $hash));
 }
    ####################################################################################
    # BEGIN: Cache related stuff, PART 2
    # Hidden feature: remove object from cache, if 'nocache' parameter found in URL
    if ($site->fdat['nocache'] && is_numeric($site->fdat['id'])) {
        $sql = $site->db->prepare("DELETE FROM cache WHERE objekt_id=?", $site->fdat['id']);
        $sth = new SQL($sql);
        $site->debug->msg($sth->debug->get_msgs());
    }
    ##############################################
    # If vead on nahtav, siis ei salvesta cache!
    if (!$CMS_SETTINGS['cache_inserted'] && $CMS_SETTINGS['cache_expired'] && $CMS_SETTINGS['cache_enabled']) {
        $cache_data = ob_get_contents();
        ob_end_clean();
        if ($cache_data) {
            # if found smth to save
            save_to_cache(array('data' => $cache_data, 'objekt_id' => $_GET['id'], 'url' => $site->fullself, 'site_id' => $leht->objekt->all['keel']));
        }
    }
    ############## PRINT CACHE to screen:
    echo $cache_data;
}
# / 2. OR START saving page info
# / SHOW cached page or START SAVING cache info
##########################
##########################
# SHOW "speed_debug" message
if ($speed_debug) {
    $loppaeg = mygetmicrotime();
    $itog = $loppaeg - $startaeg;
    $sth = new SQL("SELECT count(*) FROM cache");
    $total_in_cache = $sth->fetchsingle();
Пример #5
0
 function get_sites_table()
 {
     $this->_secure(5);
     $grid_method = get_grid_method_from_page();
     $result = array();
     $user = $this->session->all_userdata();
     $this->load->model('model_sites');
     $this->load->model('model_client_attributes');
     $this->load->model('model_client_attribute_values');
     $url_params = $this->uri->uri_to_assoc(3);
     $post_data = $_POST;
     $client_tab_id = 0;
     $cache_key = '';
     $site_data = array();
     $total_stats = array();
     if (USE_CACHE && !empty($post_data)) {
         $cache_post_key = $post_data;
         if (isset($cache_post_key['sEcho'])) {
             unset($cache_post_key['sEcho']);
         }
         if (isset($cache_post_key['iDisplayStart'])) {
             unset($cache_post_key['iDisplayStart']);
         }
         if (isset($cache_post_key['iDisplayLength'])) {
             unset($cache_post_key['iDisplayLength']);
         }
         if (isset($cache_post_key['_search'])) {
             unset($cache_post_key['_search']);
         }
         if (isset($cache_post_key['page'])) {
             unset($cache_post_key['page']);
         }
         if (isset($cache_post_key['rows'])) {
             unset($cache_post_key['rows']);
         }
         if (isset($cache_post_key['nd'])) {
             unset($cache_post_key['nd']);
         }
         $cache_key = md5(serialize($cache_post_key));
         $site_data = from_cache($user['user_id'], 'site_data', $cache_key);
         $total_stats = from_cache($user['user_id'], 'total_stats', $cache_key);
         $all_site_ids = from_cache($user['user_id'], 'all_site_ids', $cache_key);
     }
     $total_visits = 0;
     $total_new_visits = 0;
     $total_visitors = 0;
     $total_page_views = 0;
     $total_bounces = 0;
     if (isset($url_params['client_tab_id'])) {
         $client_tab_id = $url_params['client_tab_id'];
     }
     $filters = array();
     $filters['client_id'] = $user['client_id'];
     $filters['user_id'] = $user['user_id'];
     if (isset($url_params['site_displayed_flag']) && $url_params['site_displayed_flag'] != '') {
         $filters['site_displayed_flag'] = $url_params['site_displayed_flag'];
     }
     if (isset($post_data['attribute_filter_count']) && $post_data['attribute_filter_count'] > 0) {
         $attribute_values = array();
         for ($i = 0; $i < $post_data['attribute_filter_count']; $i++) {
             $attribute_filter = $post_data['attribute_filter_' . ($i + 1)];
             $attribute_filter_parts = explode('-', $attribute_filter);
             $filter_name = $attribute_filter_parts[0];
             $filter_value = $attribute_filter_parts[1];
             if (isset($attribute_values[$filter_name])) {
                 $attribute_values[$filter_name][] = $filter_value;
             } else {
                 $attribute_values[$filter_name] = array($filter_value);
             }
         }
         $filters['attribute_values'] = $attribute_values;
     }
     if ($client_tab_id == '0') {
         $filters['user_site_type'] = 'M';
     } else {
         $filters['user_site_type'] = 'V';
     }
     $start_date = 0;
     $end_date = 0;
     if (isset($post_data['end_date'])) {
         $end_date = to_unixtime($post_data['end_date']);
         if (isset($post_data['interval'])) {
             $start_date = strtotime('-' . $post_data['interval'], $end_date);
         }
     }
     if (isset($post_data['start_date'])) {
         $start_date = to_unixtime($post_data['start_date']);
         if (isset($post_data['interval'])) {
             $end_date = strtotime('+' . $post_data['interval'], $start_date);
         }
     }
     if (isset($post_data['empty_google_sites'])) {
         $filters['empty_google_sites'] = $post_data['empty_google_sites'];
     }
     if (isset($post_data['google_sites'])) {
         $filters['google_sites'] = $post_data['google_sites'];
     }
     if (empty($site_data) || empty($total_stats)) {
         $client_attribute_filters = array();
         $client_attribute_filters['client_id'] = $user['client_id'];
         $client_attribute_filters['select_sql'] = '1';
         if ($client_tab_id == '0') {
             $filters['select'] = array('sites.site_id', 'sites.site_title', 'sites.site_notes', 'sites.site_displayed_flag');
             $client_attribute_filters['attribute_group_type'] = array('P', 'U');
             $client_attribute_filters['not_empty'] = '1';
         } else {
             $filters['select'] = array('sites.site_id', 'sites.site_title', 'sites.site_notes', 'sites.site_displayed_flag', 'sites.google_site_id');
             $client_attribute_filters['attribute_value_type'] = array('D', 'F', 'HS', 'I', 'M', 'PC', 'PT', 'SF', 'T', 'U');
         }
         $client_attributes = $this->model_client_attributes->get_records($client_attribute_filters, false, true);
         // Attribute fields
         if (!empty($client_attributes)) {
             foreach ($client_attributes as $client_attribute) {
                 $filters['select'][] = $client_attribute['select_sql'];
             }
         }
         $sites = $this->model_sites->get_records($filters, false, false);
         $all_site_ids = array();
         if (!empty($sites)) {
             $client_tab_columns = $this->_get_tab_columns();
             $site_data = $this->_get_dataset($sites, $all_site_ids, $client_tab_id, $client_tab_id == '0' ? $client_attributes : $client_tab_columns, $start_date, $end_date, $total_stats);
         }
         if (!empty($site_data) && isset($post_data['sSearch']) && !empty($post_data['sSearch'])) {
             $new_site_data = array();
             for ($i = 0; $i < sizeof($site_data); $i++) {
                 $matched = false;
                 for ($j = 0; $j < $post_data['iColumns']; $j++) {
                     if ($post_data['bSearchable_' . $j] == 'true') {
                         if (stristr(strip_tags($site_data[$i][$j]), $post_data['sSearch'])) {
                             $matched = true;
                             break;
                         }
                     }
                 }
                 if ($matched) {
                     $new_site_data[] = $site_data[$i];
                 }
             }
             $site_data = $new_site_data;
         } elseif (!empty($site_data) && isset($post_data['search']) && !empty($post_data['search'])) {
             $new_site_data = array();
             if ($client_tab_id == '0') {
                 for ($i = 0; $i < 3; $i++) {
                     $columns[] = $i;
                 }
                 if (!empty($client_attributes)) {
                     $counter = 2;
                     foreach ($client_attributes as $client_attribute) {
                         $columns[] = ++$counter;
                     }
                 }
             } else {
                 $columns = $client_tab_columns['columns'];
             }
             foreach ($site_data as $i => $site) {
                 $matched = false;
                 foreach ($columns as $column) {
                     if (stristr(strip_tags($site[$column]), $post_data['search'])) {
                         $matched = true;
                         break;
                     }
                 }
                 if ($matched) {
                     $new_site_data[] = $site;
                 }
             }
             $site_data = $new_site_data;
         }
         // Sorting for tab columns - all need to be in sync
         if (!empty($site_data) && isset($post_data['sColumns']) && isset($post_data['sort_column']) && isset($post_data['sort_direction'])) {
             $columns = explode(',', $post_data['sColumns']);
             $column_sort = array();
             $column_sort_index = -1;
             $column_sort_direction = null;
             for ($i = 0; $i < sizeof($columns); $i++) {
                 if ($columns[$i] == $post_data['sort_column']) {
                     $column_sort_index = $i + 1;
                     // Add 1 for the site_id (removed later)
                     break;
                 }
             }
             if ($column_sort_index != -1) {
                 for ($i = 0; $i < sizeof($site_data); $i++) {
                     $column_value = trim(strip_tags($site_data[$i][$column_sort_index]));
                     if (is_date($column_value)) {
                         $column_sort[] = to_unixtime($column_value);
                     } else {
                         $column_sort[] = strtolower($column_value);
                     }
                     if ($post_data['sort_direction'] == 'asc') {
                         $column_sort_direction = SORT_ASC;
                     } else {
                         $column_sort_direction = SORT_DESC;
                     }
                 }
             }
             if (!empty($column_sort)) {
                 array_multisort($column_sort, $column_sort_direction, SORT_REGULAR, $site_data);
             }
         } elseif (!empty($site_data) && isset($post_data['iSortingCols']) && !empty($post_data['iSortingCols'])) {
             // Original sort, using default functionality
             $column_sorts = array();
             $column_sort_index = 0;
             $column_sort_directions = array();
             for ($i = 0; $i < $post_data['iSortingCols']; $i++) {
                 if (isset($post_data['iSortCol_' . $i])) {
                     $column_sorts[$column_sort_index] = array();
                     for ($j = 0; $j < sizeof($site_data); $j++) {
                         $column_value = trim(strip_tags($site_data[$j][$post_data['iSortCol_' . $i]]));
                         if (is_date($column_value)) {
                             $column_sorts[$column_sort_index][] = to_unixtime($column_value);
                         } else {
                             $column_sorts[$column_sort_index][] = strtolower($column_value);
                         }
                     }
                     $column_sort_directions[$column_sort_index] = 'SORT_' . strtoupper($post_data['sSortDir_' . $i]);
                     $column_sort_index++;
                 }
             }
             if (!empty($column_sorts)) {
                 $eval = 'array_multisort(';
                 for ($i = 0; $i < sizeof($column_sorts); $i++) {
                     $eval .= ($i > 0 ? ',' : '') . '$column_sorts[' . $i . '],' . $column_sort_directions[$i] . ',SORT_REGULAR';
                 }
                 $eval .= ',$site_data);';
                 eval($eval);
             }
         } elseif (!empty($site_data) && isset($post_data['sidx']) && isset($post_data['sord'])) {
             if ($grid_method == 'jqgrid') {
                 $columns = $client_tab_columns['columns'];
                 $column_sort = array();
                 $column_sort_index = -1;
                 $column_sort_direction = null;
                 for ($i = 0; $i < sizeof($columns); $i++) {
                     if ($columns[$i]['name'] == $post_data['sidx']) {
                         $column_sort_index = $i + 1;
                         // Add 1 for the site_id (removed later)
                         break;
                     }
                 }
                 if ($column_sort_index != -1) {
                     foreach ($site_data as $i => $site) {
                         $column_value = trim(strip_tags($site[$column_sort_index]));
                         if (is_date($column_value)) {
                             $column_sort[] = to_unixtime($column_value);
                         } else {
                             $column_sort[] = strtolower($column_value);
                         }
                         if ($post_data['sord'] == 'asc') {
                             $column_sort_direction = SORT_ASC;
                         } else {
                             $column_sort_direction = SORT_DESC;
                         }
                     }
                 }
                 if (!empty($column_sort)) {
                     array_multisort($column_sort, $column_sort_direction, SORT_REGULAR, $site_data);
                 }
             } elseif ($grid_method == 'slick') {
                 $column_sort = array();
                 $column_sort_direction = null;
                 foreach ($site_data as $i => $site) {
                     $column_value = trim(strip_tags($site[$post_data['sidx']]));
                     if (is_date($column_value)) {
                         $column_sort[] = to_unixtime($column_value);
                     } else {
                         $column_sort[] = strtolower($column_value);
                     }
                     if ($post_data['sord'] == 'asc') {
                         $column_sort_direction = SORT_ASC;
                     } else {
                         $column_sort_direction = SORT_DESC;
                     }
                 }
                 if (!empty($column_sort)) {
                     array_multisort($column_sort, $column_sort_direction, SORT_REGULAR, $site_data);
                 }
             }
         }
         if (USE_CACHE) {
             save_to_cache($site_data, 0, $user['user_id'], 'site_data', $cache_key);
             save_to_cache($total_stats, 0, $user['user_id'], 'total_stats', $cache_key);
             save_to_cache($all_site_ids, 0, $user['user_id'], 'all_site_ids', $cache_key);
         }
     }
     if (!empty($total_stats)) {
         foreach ($total_stats as $total_stat) {
             $total_visits += $total_stat['visits'];
             $total_new_visits += $total_stat['new_visits'];
             $total_visitors += $total_stat['visitors'];
             $total_page_views += $total_stat['page_views'];
             $total_bounces += $total_stat['bounces'];
         }
     }
     // We need to clear out the sites we don't need here, otherwise things go awry!
     if (!empty($site_data) && isset($post_data['site_ids']) && !empty($post_data['site_ids'])) {
         $new_site_data = array();
         $all_site_ids = $post_data['site_ids'];
         if (!is_array($all_site_ids)) {
             $all_site_ids = explode(',', $all_site_ids);
         }
         foreach ($site_data as $i => $site) {
             if (isset($site['id'])) {
                 $site_id = $site['id'];
             } else {
                 $site_id = $site[0];
             }
             if (in_array($site_id, $all_site_ids)) {
                 $new_site_data[] = $site;
             }
         }
         $site_data = $new_site_data;
     }
     // Now we need to define the formats we need to send back to the client
     if ($grid_method == 'jqgrid' || $grid_method == 'slick') {
         if ($grid_method == 'jqgrid') {
             if (!empty($site_data)) {
                 foreach ($site_data as $i => $site) {
                     $site_data[$i] = array('id' => $site[0], 'cell' => array_slice($site, 1));
                 }
             }
         }
         if ($post_data['rows'] != 'All') {
             $result['total'] = ceil(sizeof($site_data) / $post_data['rows']);
         } else {
             $result['total'] = 1;
         }
         $result['rows'] = isset($post_data['rows']) ? $post_data['rows'] : '15';
         $result['page'] = isset($post_data['page']) ? $post_data['page'] : '1';
         $result['records'] = sizeof($site_data);
         $result['recCount'] = sizeof($site_data);
         $result['search'] = isset($post_data['search']) ? $post_data['search'] : '';
         $result['start_date'] = date('d/m/Y', $start_date);
         $result['end_date'] = date('d/m/Y', $end_date);
         $result['total_visits'] = number_format($total_visits);
         $result['total_new_visits'] = number_format($total_new_visits);
         $result['total_visitors'] = number_format($total_visitors);
         $result['total_page_views'] = number_format($total_page_views);
         if ($total_visits > 0) {
             $result['total_bounce_rate'] = number_format(round($total_bounces / $total_visits * 100, 2), 2, '.', '');
         } else {
             $result['total_bounce_rate'] = '0';
         }
         $result['site_ids'] = $all_site_ids;
         if (isset($post_data['rows']) && isset($post_data['page'])) {
             if ($post_data['rows'] != 'All') {
                 $start_index = ($post_data['page'] - 1) * $post_data['rows'];
                 $result['sites'] = array_slice($site_data, $start_index, $post_data['rows']);
             } else {
                 $result['sites'] = $site_data;
             }
         } else {
             $result['sites'] = $site_data;
         }
     } else {
         // Okay, we put the site_id into the array temporarily, so we could get it out here - now we need to store the values and remove the column
         if (!empty($site_data)) {
             foreach ($site_data as $i => $site) {
                 $site_ids[] = $site[0];
                 // Now we take off the site_id
                 $site_data[$i] = array_slice($site, 1);
             }
         }
         $result['sEcho'] = isset($post_data['sEcho']) ? $post_data['sEcho'] : '';
         $result['iTotalRecords'] = sizeof($site_data);
         $result['iTotalDisplayRecords'] = sizeof($site_data);
         $result['start_date'] = date('d/m/Y', $start_date);
         $result['end_date'] = date('d/m/Y', $end_date);
         $result['total_visits'] = number_format($total_visits);
         $result['total_new_visits'] = number_format($total_new_visits);
         $result['total_visitors'] = number_format($total_visitors);
         $result['total_page_views'] = number_format($total_page_views);
         if ($total_visits > 0) {
             $result['total_bounce_rate'] = number_format(round($total_bounces / $total_visits * 100, 2), 2, '.', '');
         } else {
             $result['total_bounce_rate'] = '0';
         }
         $result['site_ids'] = $all_site_ids;
         if (!empty($site_data) && isset($post_data['iDisplayStart']) && isset($post_data['iDisplayLength'])) {
             if ($post_data['iDisplayLength'] == -1) {
                 $result['aaData'] = array_slice($site_data, $post_data['iDisplayStart']);
             } else {
                 $result['aaData'] = array_slice($site_data, $post_data['iDisplayStart'], $post_data['iDisplayLength']);
             }
         } else {
             $result['aaData'] = $site_data;
         }
     }
     $data = array();
     $data['any'] = json_encode($result);
     $data['action_view'] = 'misc/any';
     $this->load->view('layouts/blank', $data);
 }
Пример #6
0
<?php

$service_doc['lugar|place'] = array('en' => array('patron' => '/ubigeo/place/DEPARTMENT[/PROVINCE[/DISTRICT]]', 'description' => 'Searches for the ubigeo codes (reniec, inei) for the place given as ' . '/DEPARTMENT[/PROVINCE[/DISTRICT]] (the last 2 parameters are optional)'), 'es' => array('patron' => '/ubigeo/lugar/DEPARTAMENTO[/PROVINCIA[/DISTRITO]]', 'descripción' => 'Busca los códigos de ubigeo (reniec, inei) para el lugar indicado por ' . 'el /DEPARTAMENTO/PROVINCIA/DISTRITO (los últimos dos parámetros son opcionales)'));
$flugar = function ($dpt, $prov = '', $dist = '') use($app, $db) {
    $key = strtoupper("{$dpt}/{$prov}/{$dist}");
    $res = get_from_cache($key);
    if ($res === false) {
        $stm = $db->prepare('select * from ubigeo where nombreCompleto = :lugar');
        $stm->bindValue(':lugar', $key, PDO::PARAM_STR);
        $stm->execute();
        $res = $stm->fetchAll();
        save_to_cache($key, $res);
    }
    if (count($res) === 0) {
        $app->getLog()->error('3:badlocation:' . $dpt . '/' . $prov . '/' . $dist);
        $res = array('error' => 3, 'msg' => 'no existe el lugar que ha indicado');
    }
    echo json_encode(array($app->request()->getResourceUri() => $res));
};
$app->get('/ubigeo/lugar/:dpt(/:prov(/:dist))', $flugar)->name('lugar');
$app->get('/ubigeo/place/:dpt(/:prov(/:dist))', $flugar)->name('place');
Пример #7
0
            $sql = 'select * from ubigeo where ';
            switch ($source) {
                case 'reniec':
                    $sql .= ' reniec = :codigo';
                    break;
                case 'inei':
                    $sql .= ' inei = :codigo';
                    break;
                case 'cualquiera':
                case 'any':
                    $sql .= ' inei = :codigo or reniec = :codigo';
                    break;
            }
            $stm = $db->prepare($sql);
            $stm->bindValue(':codigo', $ucode, PDO::PARAM_STR);
            $stm->execute();
            $res = $stm->fetchAll();
            save_to_cache($ucode . $source, $res);
        }
        if (empty($res)) {
            $app->getLog()->error('1:badcode:' . $ucode . ':' . $source);
            $res = array('error' => 1, 'msg' => 'no existe el código de ubigeo que ha indicado');
        }
    } else {
        $app->getLog()->error('2:badsource:' . $ucode . ':' . $source);
        $res = array('error' => 2, 'msg' => 'fuente de código no permitida, usar: reniec, inei, cualquiera');
    }
    echo json_encode(array($app->request()->getResourceUri() => $res));
};
$app->get('/ubigeo/codigo/:ucode(/:source)', $fcode)->conditions(array('ucode' => '\\d{6}'))->name('codigo');
$app->get('/ubigeo/code/:ucode(/:source)', $fcode)->conditions(array('ucode' => '\\d{6}'))->name('code');
 function _get_sidebar_help()
 {
     // set a flag for returning from cache
     $use_cache = 0;
     if ($resp = read_from_cache('dashboard_help')) {
         $a = explode('|', $resp);
         $life = $this->EE->localize->now - $a[0];
         if ($life < 60 * 60 * 24 * 30) {
             $response = ltrim($resp, $a[0] . '|');
             $use_cache = 1;
         }
     }
     if ($use_cache == 0) {
         $post = array('host' => $_SERVER["HTTP_HOST"], 'license' => $this->_config["store"][$this->site_id]["license"]);
         $post_str = '';
         foreach ($post as $key => $val) {
             $post_str .= $key . '=' . $val . '&';
         }
         $post_str = rtrim($post_str, '$');
         $ch = curl_init('http://www.brilliantretail.com/dashboard_help.php');
         curl_setopt($ch, CURLOPT_HEADER, 0);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $post_str);
         $response = urldecode(curl_exec($ch));
         save_to_cache('dashboard_help', $this->EE->localize->now . '|' . $response);
     }
     return json_decode($response, true);
 }
Пример #9
0
<?php

$service_doc['distritos|districts'] = array('en' => array('pattern' => '/ubigeo/districts/DEPARTMENT/PROVINCE', 'description' => 'Lists the ubigeo codes for all districts for a PROVINCE in a DEPARTMENT'), 'es' => array('patron' => '/ubigeo/distritos/DEPARTAMENTO/PROVINCIA', 'descripción' => 'Lista los códigos de ubigeo de los distritos en la PROVINCIA del DEPARTAMENTO'));
$fdist = function ($dpt, $prov) use($app, $db) {
    $dpto = strtoupper($dpt);
    $prov = strtoupper($prov);
    $res = get_from_cache("{$dpto}/{$prov}/distritos");
    if ($res === false) {
        $rows = $db->query("select reniec from ubigeo where nombreCompleto = '{$dpto}/{$prov}/'");
        $dpres = $rows->fetchAll();
        if (count($dpres) > 0) {
            $dpcode = $dpres[0]['reniec'];
            preg_match('/(\\d{4})\\d\\d/', $dpcode, $reg);
            $prefix = $reg[1];
            $stmnt = $db->query("select * from ubigeo where reniec like '{$prefix}%' and reniec <> '{$dpcode}'");
            $res = $stmnt->fetchAll();
            save_to_cache("{$dpto}/{$prov}/distritos", $res);
        } else {
            $app->getLog()->error('6:badprov:' . $dpto . ':' . $prov);
            $res = array('error' => 6, 'msg' => 'no existe una provincia de departamento con nombre ' . $dpto . '/' . $prov);
        }
    }
    echo json_encode(array($app->request()->getResourceUri() => $res));
};
$app->get('/ubigeo/distritos/:dpt/:prov', $fdist)->name('distritos');
$app->get('/ubigeo/districts/:dpt/:prov', $fdist)->name('districts');
Пример #10
0
if ($site->fdat['nocache'] && is_numeric($site->fdat['id'])){
	$sql = $site->db->prepare("DELETE FROM cache WHERE objekt_id=?", $site->fdat['id']);
	$sth = new SQL($sql);
	$site->debug->msg($sth->debug->get_msgs());
}

##############################################
# If vead on nahtav, siis ei salvesta cache!

if (!$CMS_SETTINGS['cache_inserted'] && $CMS_SETTINGS['cache_expired'] && $CMS_SETTINGS['cache_enabled'] /*&& is_numeric($_GET['id'])*/){
	$cache_data = ob_get_contents();
	ob_end_clean();
	if ($cache_data){ # if found smth to save
		save_to_cache(Array(
			'data' => $cache_data,
			'objekt_id' => $_GET['id'], # oldstyle, optional
			'url' => $site->fullself,
			'site_id' => $leht->objekt->all['keel'],
		));
	}
}

############## PRINT CACHE to screen:
	echo $cache_data;
	

} # / 2. OR START saving page info

# / SHOW cached page or START SAVING cache info
##########################

Пример #11
0
<?php

$service_doc['provincias|provinces'] = array('en' => array('pattern' => '/ubigeo/provinces/DEPARTMENT', 'description' => 'Lists the ubigeo codes for all provinces in DEPARTMENT'), 'es' => array('patron' => '/ubigeo/provincias/DEPARTAMENTO', 'descripción' => 'Lista los códigos de ubigeo de las provincias en DEPARTAMENTO'));
$fprovs = function ($dpt) use($app, $db) {
    $dpto = strtoupper($dpt);
    $res = get_from_cache($dpto . '/provincias');
    if ($res === false) {
        $rows = $db->query("select reniec from ubigeo where nombreCompleto = '{$dpto}//'");
        $dptores = $rows->fetchAll();
        if (count($dptores) > 0) {
            $dptocode = $dptores[0]['reniec'];
            preg_match('/(\\d\\d)\\d{4}/', $dptocode, $reg);
            $prefix = $reg[1];
            $stmt = $db->query("select * from ubigeo where reniec like '{$prefix}%00' and reniec <> '{$dptocode}'");
            $res = $stmt->fetchAll();
            save_to_cache($dpto . '/provincias', $res);
        } else {
            $app->getLog()->error('5:baddpto:' . $dpto);
            $res = array('error' => 5, 'msg' => 'no existe un departamento con nombre ' . $dpto);
        }
    }
    echo json_encode(array($app->request()->getResourceUri() => $res));
};
$app->get('/ubigeo/provincias/:dpt', $fprovs)->name('provincias');
$app->get('/ubigeo/provinces/:dpt', $fprovs)->name('provinces');
Пример #12
0
<?php

$service_doc['departamentos|departments'] = array('en' => array('pattern' => '/ubigeo/departments', 'description' => 'Lists the ubigeo codes for all departments'), 'es' => array('patron' => '/ubigeo/departamentos', 'descripción' => 'Lista los códigos de ubigeo de todos los departamentos'));
$fdepas = function () use($app, $db) {
    $res = get_from_cache('departamentos');
    if ($res === false) {
        $stmt = $db->query("select * from ubigeo where nombreCompleto like '%//'");
        $res = $stmt->fetchAll();
        save_to_cache('departamentos', $res);
    }
    echo json_encode(array($app->request()->getResourceUri() => $res));
};
$app->get('/ubigeo/departamentos', $fdepas)->name('departamentos');
$app->get('/ubigeo/departments', $fdepas)->name('departments');