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;
    }
Example #2
0
function find_for_tags()
{
    $response = check_table_exist(strtolower($_GET['parameter']));
    if ($response == "FALSE") {
        $array = parse('https://www.mashape.com/explore' . switch_type($_GET['type']) . $_GET['parameter']);
        create_table(strtolower($_GET['parameter']), $array);
        echo json_encode($array);
    } else {
        $date = date("Y/m/d");
        $diff = get_count_days(strtolower($_GET['parameter']), $date);
        //  echo "diff".$diff;
        if ($diff > 6) {
            $array = parse('https://www.mashape.com/explore' . switch_type($_GET['type']) . $_GET['parameter']);
            $table = $_GET['parameter'];
            load_json_to_db($table, $array);
            echo json_encode($array);
        } else {
            $array = read_from_cache(strtolower($_GET['parameter']));
            echo json_encode($array);
        }
    }
}
    /**
     * 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 results_layered()
 {
     $url = $this->EE->uri->uri_to_assoc();
     $hash = $url["id"];
     if ($str = read_from_cache('search_' . $hash)) {
         $vars = unserialize($str);
     } else {
         $this->EE->functions->redirect($this->EE->functions->fetch_site_index(0, 0));
     }
     $url = $this->EE->uri->uri_to_assoc();
     $hash = $url["id"];
     $vars = $this->_filter_results($vars, $hash, false);
     $layered = $this->_layered_navigation($vars[0]["results"], $hash);
     $output = '';
     if (count($layered) >= 1) {
         $output = $this->EE->TMPL->parse_variables($this->EE->TMPL->tagdata, $layered);
     }
     return $output;
 }
 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);
 }