[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

/includes/ -> seo_cache.php (source)

   1  <?php
   2  /*=======================================================================*\

   3  || #################### //-- SCRIPT INFO --// ########################## ||

   4  || #    Script name: includes/seo_cache.php

   5  || #    Contribution: Ultimate SEO URLs

   6  || #    Version: 2.0

   7  || #    Date: 30 January 2005

   8  || # ------------------------------------------------------------------ # ||

   9  || #################### //-- COPYRIGHT INFO --// ######################## ||

  10  || #    Copyright 2006 osCMax2005 Bobby Easland                                # ||

  11  || #    Internet moniker: Chemo                                            # ||    

  12  || #    Contact: [email protected]                                    # ||

  13  || #    Commercial Site: http://gigabyte-hosting.com/                    # ||

  14  || #    GPL Dev Server: http://mesoimpact.com/                            # ||

  15  || #                                                                    # ||

  16  || #    This script is free software; you can redistribute it and/or    # ||

  17  || #    modify it under the terms of the GNU General Public License        # ||

  18  || #    as published by the Free Software Foundation; either version 2    # ||

  19  || #    of the License, or (at your option) any later version.            # ||

  20  || #                                                                    # ||

  21  || #    This script is distributed in the hope that it will be useful,    # ||

  22  || #    but WITHOUT ANY WARRANTY; without even the implied warranty of    # ||

  23  || #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    # ||

  24  || #    GNU General Public License for more details.                    # ||

  25  || #                                                                    # ||

  26  || #    Script is intended to be used with:                                # ||

  27  || #    osCMax Power E-Commerce                    # ||

  28  || #    http://oscdox.com                                        # ||

  29  || #    Copyright 2006 osCMax                                    # ||

  30  || ###################################################################### ||

  31  \*========================================================================*/
  32  
  33  # strip functon

  34  # if anyone can help with international translations please correct the file and upload

  35    function strip($convert_me) {
  36      $strip_array = array("&#39",chr(33),chr(34),chr(35),chr(36),chr(37),chr(38),chr(39),chr(40),chr(41),chr(42),chr(43),chr(44),chr(45),chr(46),chr(47),chr(58),chr(59),chr(60),chr(61),chr(62),chr(63),chr(91),chr(92),chr(93),chr(94),chr(95),chr(96),chr(123),chr(124),chr(125),chr(126) );  
  37      $convert_me = str_replace($strip_array, '', $convert_me);
  38      $convert_me = str_replace(array(' ', '  ', '__', '--'), '-', $convert_me);
  39      $convert_me = strtolower($convert_me);
  40      return $convert_me;
  41    }
  42  
  43      # Set the cache name

  44      $cache_file = $cache_dir . 'seo_urls_';    
  45      
  46      # if the cache is not stored in the database

  47      $cache->is_cached($cache_file . 'products', $is_cached, $is_expired);      
  48      if ( !$is_cached || $is_expired ) { // it's not cached so create it
  49      # Query for the products

  50      $product_query = tep_db_query("select p.products_id, pd.products_name from products p left join products_description pd on p.products_id=pd.products_id and pd.language_id='".(int)$languages_id."' where p.products_status='1'");
  51      # Initialize the product array

  52      $prod_array = array();
  53      # Loop the returned rows

  54      while ($product = tep_db_fetch_array($product_query)) {
  55          $prod_array[$product['products_id']] = array('name' => strip($product['products_name']),
  56                                                       'id' => $product['products_id']);
  57      }
  58      # Free the memory - could be large, clean as we go!

  59      tep_db_free_result($product_query);
  60      # Initialize the container used to check for duplicate names

  61      $prod_container = array();
  62      # Loop the product array

  63      $prod_cache = '';
  64      foreach($prod_array as $record){
  65          $id = $record['id'];
  66          # If the product name hasn't been set        

  67          if ( !isset($prod_container[ $record['name'] ]) ){
  68              $name = $record['name'];
  69          } else { # This is a duplicate - get the counter and append
  70              # Increase the counter

  71              $prod_container[ $record['name'] ]['counter']++;
  72              $prod_counter = $prod_container[ $record['name'] ]['counter'];
  73              # Append the counter to the product name

  74              $name = $record['name'] . '-' . $prod_counter;
  75          }
  76          # Add the defines to the output string        

  77          $prod_cache .= 'define(\'PRODUCT_NAME_' . $id . '\', \'' . $name . '\'); ' . "\n";
  78          $prod_cache .= 'define(\'' . $name  . '\', \'products_id=' . $id . '\'); ' . "\n";
  79          # Add the product name to the container array

  80          $prod_container[$name] = array('name' => $name, 'counter' => 1);
  81      }
  82      # Save the cached data to database

  83      # Params: [ cache name, cache data, compressed, global ]

  84      $cache->save_cache($cache_file . 'products', $prod_cache, 'EVAL', 1 , 1);
  85      # Unset the variables used - could be large, clean as we go!

  86      unset($prod_array, $prod_container, $prod_cache);
  87      } # end if products is not cached

  88  
  89  /************************************************************\

  90      End of the product definitions - start of the manufacturers

  91  \************************************************************/    
  92  
  93      # if the cache is not stored in the database

  94      $cache->is_cached($cache_file . 'manufacturers', $is_cached, $is_expired);      
  95      if ( !$is_cached || $is_expired ) { // it's not cached so create it
  96      # Query for the manufacturers

  97      $manufacturers_query = tep_db_query("select m.manufacturers_id, m.manufacturers_name from manufacturers m left join manufacturers_info md on m.manufacturers_id=md.manufacturers_id and md.languages_id='".(int)$languages_id."'");
  98      # Initialize the product array

  99      $man_array = array();
 100      # Loop the returned rows

 101      while ($manufacturer = tep_db_fetch_array($manufacturers_query)) {
 102          $man_array[$manufacturer['manufacturers_id']] = array('name' => strip($manufacturer['manufacturers_name']),
 103                                                       'id' => $manufacturer['manufacturers_id']);
 104      }
 105      # Free the memory - could be large, clean as we go!

 106      tep_db_free_result($manufacturers_query);
 107      # Initialize the container used to check for duplicate names

 108      $man_container = array();
 109      # Loop the product array

 110      $man_cache = '';
 111      foreach($man_array as $record){
 112          $id = $record['id'];
 113          # If the product name hasn't been set        

 114          if ( !isset($man_container[ $record['name'] ]) ){
 115              $name = $record['name'];
 116          } else { # This is a duplicate - get the counter and append
 117              # Increase the counter

 118              $man_container[ $record['name'] ]['counter']++;
 119              $man_counter = $man_container[ $record['name'] ]['counter'];
 120              # Append the counter to the product name

 121              $name = $record['name'] . '-' . $man_counter;
 122          }
 123          # Add the defines to the output string        

 124          $man_cache .= 'define(\'MANUFACTURER_NAME_' . $id . '\', \'' . $name . '\'); ' . "\n";
 125          $man_cache .= 'define(\'' . $name  . '\', \'manufacturers_id=' . $id . '\'); ' . "\n";
 126          # Add the manufacturer name to the container array

 127          $man_container[$name] = array('name' => $name, 'counter' => 1);
 128      }
 129      # Save the cached data to database

 130      # Params: [ cache name, cache data, compressed, global ]

 131      $cache->save_cache($cache_file . 'manufacturers', $man_cache, 'EVAL', 1 , 1);
 132      # Unset the variables used - could be large, clean as we go!

 133      unset($man_array, $man_container, $man_cache);
 134      } # end if manufacturers is not cached

 135  
 136  /************************************************************\

 137      End of the manufacturers definitions - start of the categories

 138  \************************************************************/    
 139      
 140      # if the cache is not stored in the database

 141      $cache->is_cached($cache_file . 'categories', $is_cached, $is_expired);      
 142      if ( !$is_cached || $is_expired ) { // it's not cached so create it
 143      # Query for the categories

 144      $category_query = tep_db_query("select c.categories_id, c.parent_id, c.sort_order, cd.categories_name from categories c left join categories_description cd on c.categories_id=cd.categories_id and cd.language_id='".(int)$languages_id."' order by c.parent_id, c.sort_order ASC");
 145      # Initialize the cat array

 146      $cat_array = array();
 147      # Loop the returned rows

 148      while ($category = tep_db_fetch_array($category_query)) {    
 149          $cat_array[$category['categories_id']] = array('name' => strip($category['categories_name']),
 150                                                    'id' => $category['categories_id'],
 151                                                    'parent' => $category['parent_id']);
 152      }
 153      # Free the memory - could be large, clean as we go!

 154      tep_db_free_result($category_query);
 155      # Initialize the container used to check for duplicate names

 156      $cat_container = array();
 157      # Loop the cat array

 158      $cat_cache = '';
 159      foreach ($cat_array as $record){
 160          $name = $record['name'];
 161          $id = $record['id'];
 162          # If the category name hasn't been set

 163          if ( !isset($cat_container[ $cat_array[$record['parent']]['name'] .'-'.$name ]) ){
 164              $parent_name = ($record['parent']=='0' ? '' : $cat_array[$record['parent']]['name'].'-');
 165          } else { # This is a duplicate category - get the counter and append
 166              # Increase the counter

 167              $cat_container[ $cat_array[$record['parent']]['name'] .'-'.$name ]['counter']++;
 168              $parent_counter = $cat_container[ $cat_array[$record['parent']]['name'] .'-'.$name ]['counter'];
 169              # Append the counter to the parent name

 170              $parent_name = ($record['parent']=='0' ? '' : $cat_array[$record['parent']]['name'].'-'.$parent_counter.'-');
 171          }
 172          # Initialize the array to hold the category path

 173          $c = array();
 174          # Get the category path

 175          tep_get_parent_categories($c, $record['id']);
 176          # For some reason it seems to return in reverse order so reverse the array

 177          $c = array_reverse($c);
 178          # Implode the array to get the full category path

 179          $id = (implode('_', $c) ? implode('_', $c) . '_' . $record['id'] : $record['id']);
 180          # Add the defines to the output string        

 181          $cat_cache .= 'define(\'CATEGORY_NAME_' . $id . '\', \'' . $parent_name . $name . '\'); ' . "\n";
 182          $cat_cache .= 'define(\'' . $parent_name . $name . '\', \'cPath=' . $id . '\'); ' . "\n";        
 183          # Add the category name to the container array 

 184          $cat_container[$parent_name . $name] = array('id' => $id, 'counter' => 1);
 185      }
 186      # Save the cached data to the database

 187      # Params: [ cache name, cache data, compressed, global ]

 188      $cache->save_cache($cache_file . 'categories', $cat_cache, 'EVAL', 1 , 1);
 189      # Unset the arrays used - could be large, clean as we go!

 190      unset($cat_array, $cat_container, $cat_cache);
 191      }# end if categories is not cached

 192  ?>


Generated: Fri Jan 1 13:43:16 2010 Cross-referenced by PHPXref 0.7