public function process() { $this->get_value = $this->parsePath($_GET['articles_id']); $this->original_get = (int) $_GET['articles_id']; $this->cache_name = $this->setCacheString(__FILE__, 'article_info', $this->original_get); if (false !== $this->retrieve($this->cache_name)) { KissMT::init()->setCanonical($this->checkCanonical('articles_id')); return; } $query_replacements = array(':articles_id' => (int) $this->get_value, ':languages_id' => (int) KissMT::init()->retrieve('languages_id')); $query = str_replace(array_keys($query_replacements), array_values($query_replacements), $this->article_query); $result = KissMT::init()->query($query); $article_details = tep_db_fetch_array($result); tep_db_free_result($result); $name = trim($article_details['name']); $description = trim($article_details['description']); $breadcrumb = array_flip(KissMT::init()->retrieve('breadcrumb')); if (array_key_exists($name, $breadcrumb)) { unset($breadcrumb[$name]); } $breadcrumb = array_flip($breadcrumb); $leading_values = $name . (!empty($breadcrumb) ? '[-separator-]' . implode('[-separator-]', $breadcrumb) : ''); KissMT::init()->setCanonical($this->checkCanonical('articles_id')); $this->parse(KissMT::init()->entities($leading_values, $decode = true), KissMT::init()->entities($description, $decode = true)); }
public function process() { $this->get_value = ''; $this->original_get = ''; $this->cache_name = $this->setCacheString(__FILE__, 'listing', 'general'); if (false !== $this->retrieve($this->cache_name)) { KissMT::init()->setCanonical($this->checkCanonical()); return; } $query_replacements = array(':languages_id' => (int) KissMT::init()->retrieve('languages_id')); $query = str_replace(array_keys($query_replacements), array_values($query_replacements), $this->reviews_query); $result = KissMT::init()->query($query); $list_array = array(); while ($reviews_products_results = tep_db_fetch_array($result)) { if (tep_not_null($reviews_products_results['products_name'])) { $list_array[] = trim($reviews_products_results['products_name']); } } $list_string = implode('[-separator-]', $this->removeArrayDuplicates($list_array)); tep_db_free_result($result); $list_string = tep_not_null($list_string) ? $list_string : false; $leading_values = implode('[-separator-]', KissMT::init()->retrieve('breadcrumb')); KissMT::init()->setCanonical($this->checkCanonical()); $this->parse(KissMT::init()->entities(sprintf(KISSMT_REVIEWS_TEXT, $leading_values), $decode = true), KissMT::init()->entities($list_string, $decode = true)); }
public function retrieve() { if (SEO_URLS_ENABLED != 'false') { $query = str_replace(':cache_name', $this->cachename, $this->extract_query); $result = usu::query($query); $row = tep_db_fetch_array($result); tep_db_free_result($result); if (!empty($row)) { $cache_seconds = usu::$cachedays * 24 * 60 * 60; if (time() > strtotime($row['cache_date']) + $cache_seconds) { $this->gc(); } else { usu::$cachefile_size = number_format(strlen($row['cache_data']) / 1024, 2) . ' kb'; usu::$performance['time'] = microtime(true); $this->md5check = md5($row['cache_data']); $rawdata = gzinflate(base64_decode($row['cache_data'])); usu::$registry = unserialize($rawdata); usu::$performance['time'] = round(microtime(true) - usu::$performance['time'], 4); $this->retrieved = true; return true; } } } usu::$registry = Usu_Registry::getInstance(); }
protected function acquire($dependency, $fullpath) { $this->products_id = (int) $dependency; // Bypass the query if already in the registry if (false !== isset(usu::$registry->{$this->dependency}[$this->products_id])) { usu::$performance['queries_saved']++; return true; } $placeholders = array(':pid', ':languages_id'); // $values are already type cast $values = array($this->products_id, usu::$languages_id); $this->query = str_replace($placeholders, $values, $this->base_query); $result = usu::query($this->query); $this->query = null; $row = tep_db_fetch_array($result); tep_db_free_result($result); if (false === $row) { return false; } $this->link_text = $this->linkText($row['products_name']); if (false === isset(usu::$registry->{$this->dependency})) { usu::$registry->{$this->dependency} = array(); } usu::$registry->attach($this->dependency, $this->products_id, $this->getProperties()); }
public function process() { $this->cache_name = false; if (array_key_exists('tPath', $_GET)) { $this->get_value = $this->parsePath($_GET['tPath']); $this->original_get = is_numeric(str_replace('_', '', $_GET['tPath'])) ? $_GET['tPath'] : '1'; $this->cache_name = $this->setCacheString(__FILE__, 'articles_topic', $this->original_get); $get_key = 'tPath'; $query = $this->topics_query; } elseif (array_key_exists('authors_id', $_GET)) { $this->get_value = $this->parsePath($_GET['authors_id']); $this->original_get = (int) $_GET['authors_id']; $this->cache_name = $this->setCacheString(__FILE__, 'articles_author', $this->original_get); $get_key = 'authors_id'; $query = $this->authors_query; } else { $this->get_value = false; $this->original_get = false; $this->cache_name = $this->setCacheString(__FILE__, 'articles_all', 'general'); $get_key = false; $query = $this->all_topics_query; } if (false !== ($this->cache_name && $this->retrieve($this->cache_name))) { KissMT::init()->setCanonical($this->checkCanonical($get_key)); return; } if (false === $this->get_value) { $query_replacements = array(':languages_id' => (int) KissMT::init()->retrieve('languages_id')); $query = str_replace(array_keys($query_replacements), array_values($query_replacements), $query); $result = KissMT::init()->query($query); $description = ''; while ($row = tep_db_fetch_array($result)) { if (tep_not_null($row['name'])) { $description .= trim($row['name']) . '[-separator-]'; } } $description = tep_not_null($description) ? $description : false; $name = defined('HEADING_TITLE') ? HEADING_TITLE : ucfirst(str_replace('_', ' ', substr(KissMT::init()->retrieve('basename'), 0, strlen(KissMT::init()->retrieve('basename')) - 4))); } else { $query_replacements = array(':' . $get_key => $this->get_value, ':languages_id' => (int) KissMT::init()->retrieve('languages_id')); $query = str_replace(array_keys($query_replacements), array_values($query_replacements), $query); $result = KissMT::init()->query($query); $detail = tep_db_fetch_array($result); $name = trim($detail['name']); $description = tep_not_null($detail['description']) ? trim($detail['description']) : false; } tep_db_free_result($result); $breadcrumb = array_flip(KissMT::init()->retrieve('breadcrumb')); if (array_key_exists($name, $breadcrumb)) { unset($breadcrumb[$name]); } if (array_key_exists($description, $breadcrumb)) { unset($breadcrumb[$description]); } $breadcrumb = array_flip($breadcrumb); $leading_values = $name . (!empty($breadcrumb) ? '[-separator-]' . implode('[-separator-]', $breadcrumb) : ''); KissMT::init()->setCanonical($this->checkCanonical($get_key)); $this->parse(KissMT::init()->entities($leading_values, $decode = true), KissMT::init()->entities($description, $decode = true)); }
public function process() { $this->get_value = $this->parsePath($_GET['products_id']); $this->original_get = (int) $_GET['products_id']; $this->cache_name = $this->setCacheString(__FILE__, 'reviews_id', $this->original_get); if (false !== $this->retrieve($this->cache_name)) { $reviews_string = isset($_GET['reviews_id']) && is_numeric($_GET['reviews_id']) ? '&reviews_id=' . $_GET['reviews_id'] : ''; KissMT::init()->setCanonical($this->checkCanonical('products_id', $reviews_string)); return; } $query_replacements = array(':products_id' => (int) $this->get_value, ':languages_id' => (int) KissMT::init()->retrieve('languages_id')); $query = str_replace(array_keys($query_replacements), array_values($query_replacements), $this->products_query); $result = KissMT::init()->query($query); $reviews_text = ''; $products_model = ''; $products_name = ''; $manufacturers_name = ''; while ($product_results = tep_db_fetch_array($result)) { if (tep_not_null($product_results['products_model'])) { $products_model = trim($product_results['products_model']); } if (tep_not_null($product_results['products_name'])) { $products_name = trim($product_results['products_name']); } if (tep_not_null($product_results['manufacturers_name'])) { $manufacturers_name = trim($product_results['manufacturers_name']); } if (tep_not_null($product_results['reviews_text'])) { $reviews_text .= trim(rtrim($product_results['reviews_text'], '.') . '.') . '[-separator-]'; } } tep_db_free_result($result); $breadcrumb = array_flip(KissMT::init()->retrieve('breadcrumb')); if (array_key_exists($products_model, $breadcrumb)) { unset($breadcrumb[$products_model]); } if (array_key_exists($products_name, $breadcrumb)) { unset($breadcrumb[$products_name]); } if (array_key_exists(NAVBAR_TITLE, $breadcrumb)) { unset($breadcrumb[NAVBAR_TITLE]); } $breadcrumb = array_flip($breadcrumb); $leading_values = $products_name; if (tep_not_null($products_model)) { $leading_values .= '[-separator-]' . $products_model; } $leading_values .= '[-separator-]' . implode('[-separator-]', $breadcrumb); if (tep_not_null($manufacturers_name)) { $leading_values .= '[-separator-]' . sprintf(KISSMT_BRAND_TEXT, $manufacturers_name); } $reviews_string = isset($_GET['reviews_id']) && is_numeric($_GET['reviews_id']) ? '&reviews_id=' . $_GET['reviews_id'] : ''; KissMT::init()->setCanonical($this->checkCanonical('products_id', $reviews_string)); $this->parse(KissMT::init()->entities(sprintf(KISSMT_PRODUCT_REVIEWS_TEXT, $leading_values), $decode = true), KissMT::init()->entities($reviews_text, $decode = true)); }
public function process() { // Do we have a reviews_id if (array_key_exists('reviews_id', $_GET) && tep_not_null($_GET['reviews_id'])) { $this->get_value = $this->parsePath($_GET['reviews_id']); $this->original_get = (int) $_GET['reviews_id']; $this->cache_name = $this->setCacheString(__FILE__, 'ndesk_rev_info', $this->original_get); if (false !== $this->retrieve($this->cache_name)) { KissMT::init()->setCanonical($this->checkCanonical('newsPath')); return; } $query_replacements = array(':reviews_id' => (int) $this->get_value, ':languages_id' => (int) KissMT::init()->retrieve('languages_id')); $query = str_replace(array_keys($query_replacements), array_values($query_replacements), $this->query); $result = KissMT::init()->query($query); $description = ''; $name = ''; $details = tep_db_fetch_array($result); $name = trim($details['name']); $description .= trim($details['description']); $newsdesk_name = trim($details['newsdesk_name']); tep_db_free_result($result); $description = isset($description) && tep_not_null($description) ? $description : false; $name = isset($name) && tep_not_null($name) ? $name : ''; $newsdesk_name = isset($newsdesk_name) && tep_not_null($newsdesk_name) ? $newsdesk_name : ''; $breadcrumb = array_flip(KissMT::init()->retrieve('breadcrumb')); if (array_key_exists($name, $breadcrumb)) { unset($breadcrumb[$name]); } if (tep_not_null($breadcrumb)) { // Is there still something in the breadcrumb array? $breadcrumb = array_flip($breadcrumb); $leading_values = implode('[-separator-]', $breadcrumb) . (tep_not_null($newsdesk_name) ? '[-separator-]' . $newsdesk_name : '') . (tep_not_null($name) ? '[-separator-]' . $name : ''); } else { // Nothing in the breadcrumb array $leading_values = (tep_not_null($newsdesk_name) ? '[-separator-]' . $newsdesk_name : '') . (tep_not_null($name) ? $name : HEADING_TITLE); } } else { // No reviews_id so we'll work with what we have $leading_values = implode('[-separator-]', KissMT::init()->retrieve('breadcrumb')); $description = false; } KissMT::init()->setCanonical($this->checkCanonical('reviews_id')); $this->parse(KissMT::init()->entities($leading_values, $decode = true), KissMT::init()->entities(trim($description), $decode = true)); }
public function gc() { if (KISSMT_CACHE_RESET !== 'reset') { return false; } foreach (glob(KissMT::init()->retrieve('cache_path') . "*.cache") as $filename) { @unlink($filename); } $query = "SELECT configuration_id FROM " . TABLE_CONFIGURATION . " WHERE configuration_key = 'KISSMT_CACHE_RESET'"; $result = tep_db_query($query); $db_installed = tep_db_fetch_array($result); tep_db_free_result($result); if (false !== $db_installed) { $query = "UPDATE " . TABLE_CONFIGURATION . " SET configuration_value = 'false' WHERE configuration_key = 'KISSMT_CACHE_RESET'"; tep_db_query($query); } }
/** * Acquire an array of single or multiple link texts from the query * this will be cached for later retrieval. * * @see Usu_Main::query() * @uses trim() * * @access protected * @return array array of link test */ protected function acquireLinkText() { $result = Usu_Main::i()->query($this->query); $text_array = tep_db_fetch_array($result); tep_db_free_result($result); if (false === $text_array) { return false; } $final_text_array = array(); foreach ($text_array as $key => $text) { if (tep_not_null(trim($text))) { $final_text_array[$key] = $text; } } // We will cache this result return $final_text_array; }
// # important to keep historical pricing / costs for inventory since this can fluctuate with time. // # if no cost found in suppliers_products_groups, try the products table for old format // # costing from suppliers_products_groups table $cost_price_query = tep_db_query("SELECT suppliers_group_price FROM " . TABLE_SUPPLIERS_PRODUCTS_GROUPS . " WHERE products_id = '" . $orders_products['products_id'] . "' AND priority = '0' LIMIT 1"); $cost_price = tep_db_num_rows($cost_price_query) > 0 ? tep_db_result($cost_price_query, 0) : 0; tep_db_free_result($cost_price_query); // # costing from products table $cost_old_query = tep_db_query("SELECT products_price_myself FROM " . TABLE_PRODUCTS . " WHERE products_id = '" . $orders_products['products_id'] . "'"); $cost_old = tep_db_num_rows($cost_old_query) > 0 ? tep_db_result($cost_old_query, 0) : 0; tep_db_free_result($cost_old_query); // # if supplier cost is empty, use old format $cost = !empty($cost_price) ? $cost_price : $cost_old; // # Retrieve price from products_groups table. $pricing_query = tep_db_query("SELECT pg.customers_group_price \n\t\t\t\t\t\t\t\t\t\t FROM " . TABLE_PRODUCTS_GROUPS . " pg \n\t\t\t\t\t\t\t\t\t\t LEFT JOIN " . TABLE_CUSTOMERS . " c ON c.customers_group_id = pg.customers_group_id\n\t\t\t\t\t\t\t\t\t\t LEFT JOIN " . TABLE_ORDERS . " o ON o.customers_id = c.customers_id\n\t\t\t\t\t\t\t\t\t\t WHERE o.orders_id = '" . $oID . "'\n\t\t\t\t\t\t\t\t\t\t AND products_id = '" . $orders_products['products_id'] . "'\n\t\t\t\t\t\t\t\t\t\t "); $price = tep_db_num_rows($pricing_query) > 0 ? tep_db_result($pricing_query, 0) : $orders_products['products_price']; tep_db_free_result($pricing_query); // # populate orders_products_data array $order->products[$index] = array('qty' => $orders_products['products_quantity'], 'name' => str_replace("'", "'", $orders_products['products_name']), 'model' => $orders_products['products_model'], 'tax' => $orders_products['products_tax'], 'price' => (double) $price, 'cost' => (double) $cost, 'final_price' => $orders_products['final_price'], 'products_id' => $orders_products['products_id'], 'free_shipping' => $orders_products['free_shipping'], 'separate_shipping' => $orders_products['separate_shipping'], 'products_weight' => $orders_products['products_weight'], 'orders_products_id' => $orders_products['orders_products_id'], 'warehouse_id' => $orders_products['warehouse_id']); $subindex = 0; $attributes_query_string = "select * from " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " where orders_id = '" . (int) $oID . "' and orders_products_id = '" . (int) $orders_products['orders_products_id'] . "'"; $attributes_query = tep_db_query($attributes_query_string); if (tep_db_num_rows($attributes_query)) { while ($attributes = tep_db_fetch_array($attributes_query)) { $order->products[$index]['attributes'][$subindex] = array('option' => $attributes['products_options'], 'value' => $attributes['products_options_values'], 'prefix' => $attributes['price_prefix'], 'price' => $attributes['options_values_price'], 'orders_products_attributes_id' => $attributes['orders_products_attributes_id']); $subindex++; } } $index++; } // # END while ?>
/** * Acquire an array of single or multiple link texts from the query * this will be cached for later retrieval. * * @see Usu_Main::query() * @uses trim() * * @access protected * @return array array of link test */ protected function acquireLinkText() { if (false !== ($final_text_array = Usu_Main::i()->getVar('registry')->retrieve($this->key, $this->keys_index[$this->key]))) { if (Usu_Main::monitorPerformance()) { Usu_Main::$performance['queries_saved']++; } return $final_text_array; } $result = Usu_Main::i()->query($this->query); $text_array = tep_db_fetch_array($result); tep_db_free_result($result); if (false === $text_array) { return false; } $final_text_array = array(); foreach ($text_array as $key => $text) { if (tep_not_null(trim($text))) { $final_text_array[$key] = $text; } } // We will cache this result Usu_Main::i()->getVar('registry')->attach($this->key, $this->keys_index[$this->key], $final_text_array); return $final_text_array; }
function GenerateSpecialsSitemap($languages_id) { global $languages_id; $products_query = tep_db_query("SELECT p.products_id as pID, s.specials_date_added as date_added, s.specials_last_modified as last_mod, p.products_ordered\n FROM " . TABLE_PRODUCTS . " p left join " . TABLE_PRODUCTS_DESCRIPTION . " pd on p.products_id = pd.products_id left join " . TABLE_SPECIALS . " s on pd.products_id = s.products_id\n where p.products_status = '1' and s.status = '1' and pd.language_id = " . (int) $languages_id . " order by s.specials_date_added desc "); if (tep_db_num_rows($products_query) > 0) { $this->debug['QUERY']['SPECIALS']['STATUS'] = 'success'; $this->debug['QUERY']['SPECIALS']['NUM_ROWS'] = tep_db_num_rows($products_query); $container = array(); $number = 0; $top = 0; while ($result = tep_db_fetch_array($products_query)) { $top = max($top, $result['products_ordered']); $location = $this->hrefLink(FILENAME_PRODUCT_INFO, 'products_id=' . $result['pID'], 'NONSSL'); $lastmod = $this->NotNull($result['last_mod']) ? $result['last_mod'] : $result['date_added']; $changefreq = GOOGLE_SITEMAP_SPECIALS_CHANGE_FREQ; $ratio = $top > 0 ? $result['products_ordered'] / $top : 0; $priority = $ratio < 0.1 ? 0.1 : number_format($ratio, 1, '.', ''); $container[] = array('loc' => htmlspecialchars(utf8_encode($location)), 'lastmod' => date("Y-m-d", strtotime($lastmod)), 'changefreq' => $changefreq, 'priority' => $priority); if (sizeof($container) >= 50000) { $type = $number == 0 ? 'specials' : 'specials' . $number; $this->GenerateSitemap($container, $type); $container = array(); $number++; } } tep_db_free_result($products_query); if (sizeof($container) > 0) { $type = $number == 0 ? 'specials' : 'specials' . $number; return $this->GenerateSitemap($container, $type); } } else { $this->debug['QUERY']['SPECIALS']['STATUS'] = 'false'; $this->debug['QUERY']['SPECIALS']['NUM_ROWS'] = '0'; return $this->GenerateSitemap(array(), 'specials'); } }
/** * * Building the $categories array * * @param $filepath - Full path to cache * @param $order_by sort setting chosed in oscommerce admin * @param $languages_id * @return Returns the fully built $categories array as well as javascript * Copyright for SuckerTree Vertical Menu 1.1 * @copyright Dynamic Drive: http://www.dynamicdrive.com/style/ */ function buildCategoriesCache($filepath, $order_by, $languages_id) { $result = categoriesFullScan($order_by, $languages_id); $javamenustring = ''; /** * Loop through each row * creating the raw $categories array */ while ($row = tep_db_fetch_array($result)) { $categories[$row['categories_id']] = array('id' => $row['categories_id'], 'parent' => $row['parent_id'], 'sort' => $row['sort_order'], 'path' => '', 'name' => htmlentities($row['categories_name'])); } tep_db_free_result($result); // Housekeeping /** * Loop through the raw $categories array * This time we are adding the following: * $categories[<cat_id>]['children'] which is a comma seperated list of this categories children * $categories[<cat_id>]['path'] which is the cPath but only for parent categories * @param $javamenustring a comma seperated string which is later passed to $categories['menuid_string'] */ foreach ($categories as $cat_id => $key) { if ($key['parent'] != '0') { isset($categories[$key['parent']]['children']) && $categories[$key['parent']]['children'] !== NULL ? NULL : ($categories[$key['parent']]['children'] = ''); $categories[$key['parent']]['children'] .= $key['id'] . ','; } else { $javamenustring .= '"menu_' . $key['id'] . '",'; $categories[$key['id']]['path'] .= $key['id']; } } // added version 1.1.2 /** * Loop through the $categories array yet again * $categories[<cat_id>]['path'] is created for all categories EXCEPT parent categories * Calls on function setCpath to generate muli layer cPaths * */ foreach ($categories as $cat_id => $key) { $fullcatpath = ''; if ($key['parent'] != '0') { $fullcatpath = setCpath($categories, $key['id']); $categories[$key['id']]['path'] = $fullcatpath; } } $javamenustring = rtrim($javamenustring, ','); $categories['menuid_string'] = $javamenustring; $categories['menuid_js'] = <<<JSSCRIPT <script language="javascript" type="text/javascript"> function get_menu_ids() { var menuids=[{$javamenustring}] //Enter id(s) of SuckerTree UL menus, separated by commas return menuids; } </script> <script src="includes/javascript/suckertree.js" type="text/javascript"></script> JSSCRIPT; // Serialize and save the $categories array $serialized = serialize($categories); if (defined('FWR_MENU_RESET') && FWR_MENU_RESET == 'true' || defined('FWR_SUCKERTREE_MENU_ON') && 'true' === FWR_SUCKERTREE_MENU_ON && !file_exists($filepath . $languages_id . "_categories.ser")) { /** * We are deleting the old cache files so we will delete all files * on the relevant directory path with a .ser filename */ foreach (glob($filepath . "*.ser") as $filename) { unlink($filename); } // Write the new cache saveSerializedFile($filepath, $serialized, $languages_id, "_categories.ser"); // FWR DOM XML - uncomment the line below to activate //if( class_exists('DOMDocument') ) sitemapXML($filepath, $categories); $sql = "\r\nUPDATE " . TABLE_CONFIGURATION . "\r\nSET `configuration_value` = 'false'\r\nWHERE `configuration_key` = 'FWR_MENU_RESET'"; //Reset the FWR Menu reset back to false tep_db_query($sql) or die('Update failed ' . mysql_error()); } return $categories; }
function sk_set_language() { global $languages_id, $language_code; $language_query = tep_db_query('select languages_id, code from ' . TABLE_LANGUAGES); if (tep_db_num_rows($language_query) == 1 && ($language_row = tep_db_fetch_array($language_query))) { // Wenn nur eine Sprache definiert ist, benutzen wir diese. $languages_id = $language_row['languages_id']; $language_code = $language_row['code']; } else { if (!defined('PROD_DEFAULT_LANGUAGE_ID')) { trigger_error('Bitte setzen Sie in der Datei elmar_config.inc.php die Konstante PROD_DEFAULT_LANGUAGE_ID auf die in Ihrem Shop verwendete Sprach-ID.', E_USER_ERROR); } else { if (!defined('PROD_DEFAULT_LANGUAGE')) { trigger_error('Bitte setzen Sie in der Datei elmar_config.inc.php die Konstante PROD_DEFAULT_LANGUAGE auf den in Ihrem Shop verwendeten Sprachcode.', E_USER_ERROR); } else { $languages_id = PROD_DEFAULT_LANGUAGE_ID; $language_code = PROD_DEFAULT_LANGUAGE; } } } tep_db_free_result($language_query); }
function _get_attribute_values_list($products_id) { $res = tep_db_query("SELECT po.products_options_name, pov.products_options_values_name\n FROM " . TABLE_PRODUCTS_ATTRIBUTES . " pa\n INNER JOIN " . TABLE_PRODUCTS_OPTIONS . " po\n ON (pa.options_id = po.products_options_id\n AND po.language_id = {$GLOBALS['languages_id']})\n INNER JOIN " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov\n ON (pa.options_values_id = pov.products_options_values_id\n AND pov.language_id = {$GLOBALS['languages_id']})\n WHERE pa.products_id = {$products_id} "); $values = array(); while ($row = tep_db_fetch_array($res)) { $values[$row['products_options_name']][] = $row['products_options_values_name']; } reset($values); while (list($id, $value) = each($values)) { $result[$id] = implode(",", array_unique($value)); } tep_db_free_result($res); return $result; }
private function get_parents(&$categories, $categories_id) { $query = "SELECT parent_id \r\n FROM " . TABLE_CATEGORIES . " \r\n WHERE categories_id='" . (int) $categories_id . "'"; $parent_category_query = usu::query($query); $parent_category = tep_db_fetch_array($parent_category_query); tep_db_free_result($parent_category_query); if ($parent_category['parent_id'] == 0) { return; // We are at the top level so return ending the loop } $categories[count($categories)] = $parent_category['parent_id']; if ($parent_category['parent_id'] != $categories_id) { $this->get_parents($categories, $parent_category['parent_id']); } }
$options[$i]['options_values_price'][$products_options_id . $option_value_seperator . $products_options_values['products_options_values_id']] = $products_options_values['options_values_price']; } ++$i; } $combinations = combinations($options, $options_seperator); foreach ($combinations as $combination_id => $combination) { $combination['combination_id'] = $combination_id; $i_rows[$language_id][$products_id][] = array_merge($combination, $products[$language_id][$products_id]); } } } } } echo 'products attributes array built' . "\n"; ob_flush(); tep_db_free_result($products_attributes_query); } // echo 'feed generation in process...' . "\n"; ob_flush(); foreach ($feeds as $cur_feed_id => $cur_feed) { foreach ($products[$cur_feed['language_id']] as $row) { $rows = array(); if (isset($i_rows[$cur_feed['language_id']][$row['products_id']]) && $cur_feed['attributes_handling'] == 2) { $rows =& $i_rows[$cur_feed['language_id']][$row['products_id']]; } else { $rows[] =& $row; } foreach ($rows as $product) { if (!empty($cur_feed['include_record_function'])) { $include_record = call_user_func_array($cur_feed['include_record_function'], array(&$product));
function customers_returning() { $customers_returning_query = tep_db_query("SELECT COUNT(0)\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t \t FROM (\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t \tSELECT NULL\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM orders\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE date_purchased >= ADDDATE(CURDATE(), INTERVAL 1 - DAYOFWEEK(CURDATE())DAY)\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tAND customers_id !=0\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tGROUP BY customers_id\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tHAVING COUNT(*) > 1\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t) AS cnt"); $customers_returning = tep_db_num_rows($customers_new_query) > 0 ? tep_db_result($customers_returning_query, 0) : 0; tep_db_free_result($customers_returning_query); return $customers_returning; }
/** * Factory to extract data from the various cache strategies * * @see Usu_Main::getVar() * @see Data_Registry::load() * @uses microtime() * @uses str_replace() * @uses number_format() * @uses strlen() * @uses gzinflate() * @uses base64_decode() * @uses unserialize() * @uses is_readable() * @uses file_get_contents() * @param string $cache_name - cache name to extract * @param string $cache_type - e.g. mysql, file etc. * @param object $object iCache_System * * @access public * @return bool */ public function extractCacheData($cache_name, $cache_type, iCache_System $object) { $cache_seconds = (int) USU5_CACHE_DAYS * 24 * 60 * 60; $timestart = microtime(true); switch (true) { case $cache_type == 'mysql': $query = str_replace(':cache_name', $cache_name, $object->extract_query); $result = $this->query($query); $row = tep_db_fetch_array($result); tep_db_free_result($result); if (false === $row) { self::$performance['time_extracting_cache'] = number_format(microtime(true) - $timestart, 4); // return insert = true as there is nothing in the database return true; } if (time() > strtotime($row['cache_date']) + $cache_seconds) { // If the cache has expired $object->gc(); // Clear the cache self::$performance['time_extracting_cache'] = number_format(microtime(true) - $timestart, 4); // return insert = true as there is nothing in the database return true; } else { // the cache hasn't expired so we retrieve it and set the registry $cache_file_size = number_format(strlen($row['cache_data']) / 1024, 2) . ' kb'; $rawdata = gzinflate(base64_decode($row['cache_data'])); $this->getVar('registry')->load(unserialize($rawdata)); self::$performance['time_extracting_cache'] = number_format(microtime(true) - $timestart, 4); self::$performance['cache_loaded'] = 'true'; // return insert = false as we have extracted data from the database return false; } break; case $cache_type == 'file': if (is_readable($this->getVar('cache_system_path') . 'cache/' . $cache_name . '.cache')) { $this->getVar('registry')->load(unserialize(gzinflate(file_get_contents($this->getVar('cache_system_path') . 'cache/' . $cache_name . '.cache')))); self::$performance['cache_loaded'] = 'true'; self::$performance['time_extracting_cache'] = number_format(microtime(true) - $timestart, 4); return false; } else { self::$performance['time_extracting_cache'] = number_format(microtime(true) - $timestart, 4); return true; } break; case $cache_type == 'memcache': if (false === ($rawdata = $object->get($cache_name))) { self::$performance['time_extracting_cache'] = number_format(microtime(true) - $timestart, 4); // return insert = true as there is nothing in the database return true; } $rawdata = gzinflate(base64_decode($rawdata)); $this->getVar('registry')->load(unserialize($rawdata)); self::$performance['time_extracting_cache'] = number_format(microtime(true) - $timestart, 4); self::$performance['cache_loaded'] = 'true'; // return insert = false as we have extracted data from the database return false; break; case $cache_type == 'sqlite': $query = str_replace(':cache_name', $cache_name, $object->extract_query); $result = $object->getDb()->query($query); $row = $result->fetch(); if (empty($row)) { self::$performance['time_extracting_cache'] = number_format(microtime(true) - $timestart, 4); // return insert = true as there is nothing in the database return true; } if (time() > strtotime($row['cache_date']) + $cache_seconds) { // If the cache has expired $object->gc(); // Clear the cache self::$performance['time_extracting_cache'] = number_format(microtime(true) - $timestart, 4); // return insert = true as there is nothing in the database return true; } else { // the cache hasn't expired so we retrieve it and set the registry $cache_file_size = number_format(strlen($row['cache_data']) / 1024, 2) . ' kb'; $rawdata = gzinflate(base64_decode($row['cache_data'])); $this->getVar('registry')->load(unserialize($rawdata)); self::$performance['time_extracting_cache'] = number_format(microtime(true) - $timestart, 4); self::$performance['cache_loaded'] = 'true'; // return insert = false as we have extracted data from the database return false; } break; default: trigger_error(__CLASS__ . '::' . __FUNCTION__ . ' unknown type passed as: ' . $type, E_USER_WARNING); break; } }
function is_cached($name, &$is_cached, &$is_expired) { // NOTE: $is_cached and $is_expired is passed by reference !! # query for the expiration date $this->cache_query = tep_db_query("SELECT cache_expires FROM cache WHERE cache_id='" . md5($name) . "' AND cache_language_id='" . (int) $this->lang_id . "' LIMIT 1"); # check to see if there were any rows returned $is_cached = tep_db_num_rows($this->cache_query) ? true : false; if ($is_cached) { // there were rows returned # fetch the array $check = tep_db_fetch_array($this->cache_query); # check to see if it is expired $is_expired = $check['cache_expires'] <= date("Y-m-d h:i:s") ? true : false; # unset $check...clean as we go unset($check); } # free the result...clean as we go tep_db_free_result($this->cache_query); }
} else { sk_generate_line(); } } } else { $kategorie = sk_generate_category_path($products_id); //--> nur bestimmte Produktkategorien #if ($productfiletype!='pangora' || preg_match('/^hardware\|grafikkarten$|software|action/i', $kategorie)) //<-- sk_generate_line(); } } if (!$output_compression) { flush(); } tep_db_free_result($rs); $limit_from += DB_STEP; } while (!$db_part && $count == DB_STEP && $bytes < $to_bytes); if ($fh) { flock($fh, LOCK_UN); // release the lock fclose($fh); } if ($output_compression) { ob_end_flush(); } productLog(TRUE); exit; ########################################################################### // Erzeugt eine Zeile der Produktdatei function sk_generate_line($category_text = '', $category_id = '')
function backup() { global $HTTP_POST_VARS; $this->SET['comp_method'] = tep_not_null($HTTP_POST_VARS['compress']) && $HTTP_POST_VARS['compress'] != '0' ? intval($HTTP_POST_VARS['compress']) : ''; $this->SET['comp_level'] = 5; $tables = array(); $result = tep_db_query("SHOW TABLES"); $all = 0; while ($row = tep_db_fetch_row($result)) { $tables[] = $row[0]; } $tabs = count($tables); // Определение размеров таблиц $result = tep_db_query("SHOW TABLE STATUS"); $tabinfo = array(); $tab_charset = array(); $tab_type = array(); $tabinfo[0] = 0; $info = ''; while ($item = tep_db_fetch_array($result)) { if (in_array($item['Name'], $tables)) { $item['Rows'] = empty($item['Rows']) ? 0 : $item['Rows']; $tabinfo[0] += $item['Rows']; $tabinfo[$item['Name']] = $item['Rows']; $tabsize[$item['Name']] = 1 + round(LIMIT * 1048576 / ($item['Avg_row_length'] + 1)); if ($item['Rows']) { $info .= "|" . $item['Rows']; } if (!empty($item['Collation']) && preg_match("/^([a-z0-9]+)_/i", $item['Collation'], $m)) { $tab_charset[$item['Name']] = $m[1]; } $tab_type[$item['Name']] = isset($item['Engine']) ? $item['Engine'] : $item['Type']; } } $show = 10 + $tabinfo[0] / 50; $info = $tabinfo[0] . $info; $this->backup_file = DIR_FS_BACKUP . 'db_' . DB_DATABASE . '-' . date("YmdHis") . '.sql'; $fp = $this->fn_open($this->backup_file, "w"); $this->fn_write($fp, '#SKD101|{' . DB_DATABASE . '|' . $tabs . '|' . date("Y.m.d H:i:s") . '|' . $info . "\n\n"); $t = 0; $result = tep_db_query("SET SQL_QUOTE_SHOW_CREATE = 1"); // Кодировка соединения по умолчанию if ($this->mysql_version > 40101 && DB_CHARSET != 'auto') { tep_db_query("SET NAMES '" . DB_CHARSET . "'"); $last_charset = DB_CHARSET; } else { $last_charset = ''; } if (!is_array($tables)) { $tables = array(); } reset($tables); while (list(, $table) = each($tables)) { // Выставляем кодировку соединения соответствующую кодировке таблицы if ($this->mysql_version > 40101 && $tab_charset[$table] != $last_charset) { if (DB_CHARSET == 'auto') { tep_db_query("SET NAMES '" . $tab_charset[$table] . "'"); $last_charset = $tab_charset[$table]; } } // Создание таблицы $result = tep_db_query("SHOW CREATE TABLE `{$table}`"); $tab = tep_db_fetch_row($result); $tab = preg_replace('/(default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP|DEFAULT CHARSET=\\w+|COLLATE=\\w+|character set \\w+|collate \\w+)/i', '/*!40101 \\1 */', $tab); $this->fn_write($fp, "DROP TABLE IF EXISTS `{$table}`;\n{$tab[1]};\n\n"); // Проверяем нужно ли дампить данные if (in_array($tab_type[$table], $this->only_create)) { continue; } // Опредеделяем типы столбцов $NumericColumn = array(); $result = tep_db_query("SHOW COLUMNS FROM `{$table}`"); $field = 0; while ($col = tep_db_fetch_row($result)) { $NumericColumn[$field++] = preg_match("/^(\\w*int|year)/", $col[1]) ? 1 : 0; } $fields = $field; $from = 0; $limit = $tabsize[$table]; $limit2 = round($limit / 3); $i = 0; while (($result = tep_db_query("SELECT * FROM `{$table}` LIMIT {$from}, {$limit}")) && ($total = tep_db_num_rows($result))) { if ($i == 0) { $this->fn_write($fp, "INSERT INTO `{$table}` VALUES"); } while ($row = tep_db_fetch_row($result)) { $i++; $t++; for ($k = 0; $k < $fields; $k++) { if ($NumericColumn[$k]) { $row[$k] = isset($row[$k]) ? $row[$k] : "NULL"; } else { $row[$k] = isset($row[$k]) ? "'" . mysql_escape_string($row[$k]) . "'" : "NULL"; } $row[$k] = str_replace(array('\\\\"', '\\"', "\\\\'"), array('"', '"', "\\'"), $row[$k]); } $this->fn_write($fp, ($i == 1 ? "" : ",") . "\n(" . implode(", ", $row) . ")"); } tep_db_free_result($result); if ($total < $limit) { break; } $from += $limit; } if ($total > 0) { $this->fn_write($fp, ";\n\n"); } } $this->fn_close($fp); }
function export($filter = '', $dateMode = '', $date_from = '', $date_to = '', $channel = '') { $filename = SITE_DOMAIN . '_sales_stats_' . $this->date_from->format('m-d-Y') . '_to_' . $this->date_to->format('m-d-Y') . '.csv'; $filename = str_replace('www.', '', $filename); header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename=' . $filename); $header[] = 'Date, No. of Orders, No. of Items, Avg. Order Amount, Total Amount'; print implode(',', $header) . "\r\n"; if ($this->dateMode == 'H') { $datemode = '%H:00:00'; } elseif ($this->dateMode == 'Y') { $datemode = '%Y'; } elseif ($this->dateMode == 'd') { $datemode = '%m/%d/%Y'; } elseif ($this->dateMode == 'w') { $datemode = 'week %v %x'; } elseif ($this->dateMode == 'm') { $datemode = '%b - %Y'; } $export_query1 = "SELECT DATE_FORMAT(o.date_purchased, '" . $datemode . "') AS 'Date',\n\t\t\t\t\t\t \t\t COUNT(ot.value) AS 'No. of Orders',\n\t\t\t\t\t\t\t\t SUM(theitems) AS 'No. of Items',\n\t\t\t\t\t\t \t\t CONCAT('\$', FORMAT(AVG(ot.value), 2)) AS 'Avg. Order Amount',\n\t\t\t\t\t\t\t\t CONCAT('\$', FORMAT(SUM(ot.value), 2)) AS 'Total Amount'\n\t\t\t\t\t \t FROM " . TABLE_ORDERS . " o\n\t\t\t\t\t \t LEFT JOIN " . TABLE_ORDERS_TOTAL . " ot ON ot.orders_id = o.orders_id\n\t\t\t\t\t\t LEFT JOIN (SELECT orders_id, SUM(products_quantity) AS theitems FROM orders_products GROUP BY orders_id\n\t\t\t\t\t\t\t\t\t) op ON o.orders_id = op.orders_id\n\t\t\t\t\t\t WHERE ot.class = 'ot_total' \n\t\t\t\t\t \t " . $this->filter_sql . $this->channel; for ($i = 0; $i < $this->size; $i++) { $export_query = tep_db_query($export_query1 . " AND o.date_purchased >= '" . $this->dates_from[$i]->format('Y-m-d 00:00:01') . "' AND o.date_purchased <= '" . $this->dates_to[$i]->format('Y-m-d 23:59:59') . "'"); $row = tep_db_fetch_array($export_query); tep_db_free_result($export_query); foreach ($row as $value) { $values[] = '"' . str_replace('"', '""', html_entity_decode(strip_tags($value))) . '"'; } print implode(',', $values) . "\r\n"; unset($values); } exit; }
protected function acquire($base_path, $full_path) { $this->dependency_value = $full_path; // Full path perhaps with underscores /** * About placeholders * * The placeholders (items with a colon :) must match those in the query ( $this->base_query in the constructor ) */ $placeholders = array(':info_id', ':languages_id'); // Do the below values need to be typecast? $values = array((int) $base_path, (int) usu::$languages_id); // xxx These values will replace the placeholders above in $this->base_query $this->query = str_replace($placeholders, $values, $this->base_query); // Replace the placeholders with actual values $result = usu::query($this->query); // Action the query $this->query = null; // Unset the query for future usage $row = tep_db_fetch_array($result); // Return the array of data ( or false if there are no results ) tep_db_free_result($result); // Housekeeping if (false === $row) { return false; // No results for the query so abort } /** * Values obtained from the query, these properties will populate the registry via the method getProperties() * Method $this->linkText() should be used here to convert the text into seo url format e.g. * my great product .. may become .. my-great-product * You may have more than one of these like .. * $this->parentname, $this->catname dependent on how many results you retrieve from your query */ $this->information_title = $this->linkText($row['information_title']); // If the registry item doesn't exist as a key then set a blank array if (false === isset(usu::$registry->{self::DEPENDENCY})) { usu::$registry->{self::DEPENDENCY} = array(); } /** * Populate the registry with the properties we have set in this class */ usu::$registry->attach(self::DEPENDENCY, $this->dependency_value, $this->getProperties()); }
/** * Set the sort order of our configuration group id * @uses str_replace() * * @access public * @return Installer_Class - chaining */ public function getMaxSort() { $to_replace = array(':TABLE_CONFIGURATION_GROUP'); $replacements = array(TABLE_CONFIGURATION_GROUP); $result = tep_db_query(str_replace($to_replace, $replacements, $this->max_sort_query)); $row = tep_db_fetch_array($result); tep_db_free_result($result); $this->sort_order = $row['current_max'] + 1; return $this; }
private function descriptionsExtension($type = false) { if (false === (defined('KISSMT_DESCRIPTIONS_EXTENSION_ENABLE') && KISSMT_DESCRIPTIONS_EXTENSION_ENABLE == 'true')) { return false; } if ($type == 'category') { $query = "SELECT kissmt_categories_description FROM " . TABLE_CATEGORIES_DESCRIPTION . " WHERE categories_id = " . (int) $this->get_value . " AND language_id = " . (int) KissMT::init()->retrieve('languages_id') . ""; $result = tep_db_query($query); $row = tep_db_fetch_array($result); tep_db_free_result($result); if (false !== (false !== $row && tep_not_null($row['kissmt_categories_description']))) { $this->descriptions_extension = true; $this->description = array('kissmt_categories_description' => $row['kissmt_categories_description']); return; } } elseif ($type == 'manufacturer') { $query = "SELECT m.manufacturers_name, mi.kissmt_manufacturers_description FROM " . TABLE_MANUFACTURERS . " m INNER JOIN " . TABLE_MANUFACTURERS_INFO . " mi ON mi.manufacturers_id = m.manufacturers_id AND mi.languages_id = " . (int) KissMT::init()->retrieve('languages_id') . " WHERE m.manufacturers_id = " . (int) $this->get_value . ""; $result = tep_db_query($query); $row = tep_db_fetch_array($result); tep_db_free_result($result); if (false !== (false !== $row && tep_not_null($row['kissmt_manufacturers_description']))) { $this->descriptions_extension = true; $this->description = array('manufacturers_name' => $row['manufacturers_name'], 'kissmt_manufacturers_description' => $row['kissmt_manufacturers_description']); return; } } $this->descriptions_extension = false; $this->description = false; }
<td width="90%" > <a href="/admin/" class="logo"></a> </td> <td style="text-align:right; padding:15px 10px 5px 0;"><div style="background-color:#FFFFDF; width:380px; height:37px; border:1px solid #CCC; padding:4px 10px 5px 0;"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td width="35" valign="top"><div style="position:relative;"><div style="position:absolute; top:-9px; left:-9px;"><img src="images/admin_user.png" alt="" width="36" height="48"></div></div></td><td> <?php $query = tep_db_query("SELECT * FROM `admin_sessions` \r\n\t\t\t\t\t\t WHERE admin_user NOT LIKE 'dbfeed_%'\r\n\t\t\t\t\t\t ORDER BY `admin_sessions`.`access_time` DESC \r\n\t\t\t\t\t\t LIMIT 1, 1\r\n\t\t\t\t\t\t "); echo '<table border="0" cellspacing="0" cellpadding="1" align="right"><tr><td nowrap> <b style="color:#7395C3; font:bold 11px arial;">Domain: </b><b style="font:bold 11px arial;">' . preg_replace('/^www\\./', '', SITE_DOMAIN) . '</b></td>'; echo '<td rowspan ="2" style="text-align:right; line-height:17px; padding-left:17px;" nowrap><b style="color:#7395C3; font:bold 11px arial;">Last login: </b> <b style="font:bold 11px arial;">'; if (tep_db_num_rows($query) > 0) { while ($user = tep_db_fetch_array($query)) { echo date('n/j/Y g:ia', strtotime($user['access_time']) - 18000); echo '</b><br><b style="color:#7395C3">by: </b> <b style="font:bold 11px arial;">' . ($user['admin_user'] == '.intensecart' ? 'Admin' : $user['admin_user']) . '</b>'; } tep_db_free_result($query); } else { echo 'No users found!'; } echo '</td></tr><td nowrap>'; $logged_in_query = tep_db_query("SELECT admin_user FROM admin_sessions WHERE admin_sessid = '" . $_COOKIE['admin_sessid'] . "'"); $logged_in = tep_db_num_rows($logged_in_query) > 0 ? tep_db_result($logged_in_query, 0) : ''; echo '<b style="color:#7395C3; font:bold 11px arial;">Logged in as:</b> <b style="font:bold 11px arial; text-transform: capitalize;">' . ($logged_in == '.intensecart' ? 'Admin' : $logged_in) . '</b>'; echo '</td>'; echo '</tr></table>'; ?> </td></tr></table></div></td> </tr> <tr> <td colspan="2" valign="top">