[ PHPXref.com ] [ Generated: Sun Jul 20 19:13:40 2008 ] [ osCommRes 1.2.0 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/includes/functions/ -> newsdesk_general.php (source)

   1  <?php
   2  /*

   3  

   4    osCommerce, Open Source E-Commerce Solutions

   5    http://www.oscommerce.com

   6  

   7    Copyright (c) 2003 osCommerce

   8    

   9    osCommRes, Services Online

  10    http://www.oscommres.com

  11  

  12    Copyright (c) 2005 osCommRes

  13  

  14    Released under the GNU General Public License

  15  */
  16  // -------------------------------------------------------------------------------------------------------------------------------------------------------------

  17  // Generate a path to categories

  18  // -------------------------------------------------------------------------------------------------------------------------------------------------------------

  19  function newsdesk_get_path($current_category_id = '') {
  20  global $newsPath_array;
  21  
  22  if ($current_category_id) {
  23      $cp_size = sizeof($newsPath_array);
  24      if ($cp_size == 0) {
  25          $newsPath_new = $current_category_id;
  26      } else {
  27          $newsPath_new = '';
  28          $last_category_query = tep_db_query("select parent_id from " . TABLE_NEWSDESK_CATEGORIES . " where categories_id = '" . $newsPath_array[($cp_size-1)] . "'");
  29          $last_category = tep_db_fetch_array($last_category_query);
  30          $current_category_query = tep_db_query("select parent_id from " . TABLE_NEWSDESK_CATEGORIES . " where categories_id = '" . $current_category_id . "'");
  31          $current_category = tep_db_fetch_array($current_category_query);
  32          if ($last_category['parent_id'] == $current_category['parent_id']) {
  33              for ($i=0; $i<($cp_size-1); $i++) {
  34                  $newsPath_new .= '_' . $newsPath_array[$i];
  35              }
  36          } else {
  37              for ($i=0; $i<$cp_size; $i++) {
  38                  $newsPath_new .= '_' . $newsPath_array[$i];
  39              }
  40          }
  41          $newsPath_new .= '_' . $current_category_id;
  42          if (substr($newsPath_new, 0, 1) == '_') {
  43              $newsPath_new = substr($newsPath_new, 1);
  44          }
  45      }
  46  } else {
  47      $newsPath_new = implode('_', $newsPath_array);
  48  }
  49  
  50  return 'newsPath=' . $newsPath_new;
  51  
  52  }
  53  // -------------------------------------------------------------------------------------------------------------------------------------------------------------

  54  
  55  
  56  // -------------------------------------------------------------------------------------------------------------------------------------------------------------

  57  // Parse and secure the newsPath parameter values

  58  function newsdesk_parse_category_path($newsPath) {
  59  // make sure the category IDs are integers

  60  $newsPath_array = array_map('tep_string_to_int', explode('_', $newsPath));
  61  
  62  // make sure no duplicate category IDs exist which could lock the server in a loop

  63  $tmp_array = array();
  64  $n = sizeof($newsPath_array);
  65  for ($i=0; $i<$n; $i++) {
  66      if (!in_array($newsPath_array[$i], $tmp_array)) {
  67          $tmp_array[] = $newsPath_array[$i];
  68      }
  69  }
  70  
  71  return $tmp_array;
  72  
  73  }
  74  // -------------------------------------------------------------------------------------------------------------------------------------------------------------

  75  
  76  
  77  // -------------------------------------------------------------------------------------------------------------------------------------------------------------

  78  // Return true if the category has subcategories

  79  // TABLES: categories

  80  // -------------------------------------------------------------------------------------------------------------------------------------------------------------

  81  function newsdesk_has_category_subcategories($category_id) {
  82  $child_category_query = tep_db_query("select count(*) as count from " . TABLE_NEWSDESK_CATEGORIES . " where parent_id = '" . $category_id . "'");
  83  $child_category = tep_db_fetch_array($child_category_query);
  84  
  85  if ($child_category['count'] > 0) {
  86      return true;
  87  } else {
  88      return false;
  89  }
  90  
  91  }
  92  // -------------------------------------------------------------------------------------------------------------------------------------------------------------

  93  
  94  
  95  // -------------------------------------------------------------------------------------------------------------------------------------------------------------

  96  // Construct a category path to the product

  97  // TABLES: products_to_categories

  98  function newsdesk_get_product_path($newsdesk_id) {
  99  $newsPath = '';
 100  
 101  $cat_count_sql = tep_db_query("select count(*) as count from " . TABLE_NEWSDESK_TO_CATEGORIES . " where newsdesk_id = '" . $newsdesk_id . "'");
 102  $cat_count_data = tep_db_fetch_array($cat_count_sql);
 103  
 104  if ($cat_count_data['count'] == 1) {
 105      $categories = array();
 106  
 107      $cat_id_sql = tep_db_query("select categories_id from " . TABLE_NEWSDESK_TO_CATEGORIES . " where newsdesk_id = '" . $newsdesk_id . "'");
 108      $cat_id_data = tep_db_fetch_array($cat_id_sql);
 109      newsdesk_get_parent_categories($categories, $cat_id_data['categories_id']);
 110  
 111      $size = sizeof($categories)-1;
 112      for ($i = $size; $i >= 0; $i--) {
 113          if ($newsPath != '') $newsPath .= '_';
 114              $newsPath .= $categories[$i];
 115      }
 116      if ($newsPath != '') $newsPath .= '_';
 117          $newsPath .= $cat_id_data['categories_id'];
 118  }
 119  
 120  return $newsPath;
 121  
 122  }
 123  // -------------------------------------------------------------------------------------------------------------------------------------------------------------

 124  
 125  
 126  // -------------------------------------------------------------------------------------------------------------------------------------------------------------

 127  // Recursively go through the categories and retreive all parent categories IDs

 128  // TABLES: categories

 129  function newsdesk_get_parent_categories(&$categories, $categories_id) {
 130  $parent_categories_query = tep_db_query("select parent_id from " . TABLE_NEWSDESK_CATEGORIES . " where categories_id = '" . $categories_id . "'");
 131  
 132  while ($parent_categories = tep_db_fetch_array($parent_categories_query)) {
 133      if ($parent_categories['parent_id'] == 0) return true;
 134          $categories[sizeof($categories)] = $parent_categories['parent_id'];
 135          if ($parent_categories['parent_id'] != $categories_id) {
 136              newsdesk_get_parent_categories($categories, $parent_categories['parent_id']);
 137          }
 138      }
 139  }
 140  // -------------------------------------------------------------------------------------------------------------------------------------------------------------

 141  
 142  
 143  
 144  /*

 145  

 146      osCommerce, Open Source E-Commerce Solutions ---- http://www.oscommerce.com

 147      Copyright (c) 2002 osCommerce

 148      Released under the GNU General Public License

 149  

 150      IMPORTANT NOTE:

 151  

 152      This script is not part of the official osC distribution but an add-on contributed to the osC community.

 153      Please read the NOTE and INSTALL documents that are provided with this file for further information and installation notes.

 154  

 155      script name:    NewsDesk

 156      version:        1.4.5

 157      date:            2003-08-31

 158      author:            Carsten aka moyashi

 159      web site:        www..com

 160  

 161  */
 162  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]