[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

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

   1  <?php
   2  /*

   3  $Id: articles.php 3 2006-05-27 04:59:07Z user $

   4  

   5    osCMax Power E-Commerce

   6    http://oscdox.com

   7  

   8    Copyright 2006 osCMax

   9  

  10    Released under the GNU General Public License

  11  */
  12  
  13  // Parse and secure the tPath parameter values

  14    function tep_parse_topic_path($tPath) {
  15      // make sure the topic IDs are integers

  16      $tPath_array = array_map('tep_string_to_int', explode('_', $tPath));
  17  
  18  // make sure no duplicate topic IDs exist which could lock the server in a loop

  19      $tmp_array = array();
  20      $n = sizeof($tPath_array);
  21      for ($i=0; $i<$n; $i++) {
  22        if (!in_array($tPath_array[$i], $tmp_array)) {
  23          $tmp_array[] = $tPath_array[$i];
  24        }
  25      }
  26  
  27      return $tmp_array;
  28    }
  29  
  30  ////

  31  // Generate a path to topics

  32  // TABLES: topics

  33    function tep_get_topic_path($current_topic_id = '') {
  34      global $tPath_array;
  35  
  36      if (tep_not_null($current_topic_id)) {
  37        $cp_size = sizeof($tPath_array);
  38        if ($cp_size == 0) {
  39          $tPath_new = $current_topic_id;
  40        } else {
  41          $tPath_new = '';
  42          $last_topic_query = tep_db_query("select parent_id from " . TABLE_TOPICS . " where topics_id = '" . (int)$tPath_array[($cp_size-1)] . "'");
  43          $last_topic = tep_db_fetch_array($last_topic_query);
  44  
  45          $current_topic_query = tep_db_query("select parent_id from " . TABLE_TOPICS . " where topics_id = '" . (int)$current_topic_id . "'");
  46          $current_topic = tep_db_fetch_array($current_topic_query);
  47  
  48          if ($last_topic['parent_id'] == $current_topic['parent_id']) {
  49            for ($i=0; $i<($cp_size-1); $i++) {
  50              $tPath_new .= '_' . $tPath_array[$i];
  51            }
  52          } else {
  53            for ($i=0; $i<$cp_size; $i++) {
  54              $tPath_new .= '_' . $tPath_array[$i];
  55            }
  56          }
  57          $tPath_new .= '_' . $current_topic_id;
  58  
  59          if (substr($tPath_new, 0, 1) == '_') {
  60            $tPath_new = substr($tPath_new, 1);
  61          }
  62        }
  63      } else {
  64        $tPath_new = implode('_', $tPath_array);
  65      }
  66  
  67      return 'tPath=' . $tPath_new;
  68    }
  69  
  70  ////

  71  // Return the number of articles in a topic

  72  // TABLES: articles, articles_to_topics, topics

  73    function tep_count_articles_in_topic($topic_id, $include_inactive = false) {
  74      $articles_count = 0;
  75      if ($include_inactive == true) {
  76        $articles_query = tep_db_query("select count(*) as total from " . TABLE_ARTICLES . " a, " . TABLE_ARTICLES_TO_TOPICS . " a2t where (a.articles_date_available IS NULL or to_days(a.articles_date_available) <= to_days(now())) and a.articles_id = a2t.articles_id and a2t.topics_id = '" . (int)$topic_id . "'");
  77      } else {
  78        $articles_query = tep_db_query("select count(*) as total from " . TABLE_ARTICLES . " a, " . TABLE_ARTICLES_TO_TOPICS . " a2t where (a.articles_date_available IS NULL or to_days(a.articles_date_available) <= to_days(now())) and a.articles_id = a2t.articles_id and a.articles_status = '1' and a2t.topics_id = '" . (int)$topic_id . "'");
  79      }
  80      $articles = tep_db_fetch_array($articles_query);
  81      $articles_count += $articles['total'];
  82  
  83      $child_topics_query = tep_db_query("select topics_id from " . TABLE_TOPICS . " where parent_id = '" . (int)$topic_id . "'");
  84      if (tep_db_num_rows($child_topics_query)) {
  85        while ($child_topics = tep_db_fetch_array($child_topics_query)) {
  86          $articles_count += tep_count_articles_in_topic($child_topics['topics_id'], $include_inactive);
  87        }
  88      }
  89  
  90      return $articles_count;
  91    }
  92  
  93  ////

  94  // Return true if the topic has subtopics

  95  // TABLES: topics

  96    function tep_has_topic_subtopics($topic_id) {
  97      $child_topic_query = tep_db_query("select count(*) as count from " . TABLE_TOPICS . " where parent_id = '" . (int)$topic_id . "'");
  98      $child_topic = tep_db_fetch_array($child_topic_query);
  99  
 100      if ($child_topic['count'] > 0) {
 101        return true;
 102      } else {
 103        return false;
 104      }
 105    }
 106  
 107  ////

 108  // Return all topics

 109  // TABLES: topics, topic_descriptions

 110    function tep_get_topics($topics_array = '', $parent_id = '0', $indent = '') {
 111      global $languages_id;
 112  
 113      if (!is_array($topics_array)) $topics_array = array();
 114  
 115      $topics_query = tep_db_query("select t.topics_id, td.topics_name from " . TABLE_TOPICS . " t, " . TABLE_TOPICS_DESCRIPTION . " td where parent_id = '" . (int)$parent_id . "' and t.topics_id = td.topics_id and td.language_id = '" . (int)$languages_id . "' order by sort_order, td.topics_name");
 116      while ($topics = tep_db_fetch_array($topics_query)) {
 117        $topics_array[] = array('id' => $topics['topics_id'],
 118                                    'text' => $indent . $topics['topics_name']);
 119  
 120        if ($topics['topics_id'] != $parent_id) {
 121          $topics_array = tep_get_topics($topics_array, $topics['topics_id'], $indent . '&nbsp;&nbsp;');
 122        }
 123      }
 124  
 125      return $topics_array;
 126    }
 127  
 128  ////

 129  // Return all authors

 130  // TABLES: authors

 131    function tep_get_authors($authors_array = '') {
 132      if (!is_array($authors_array)) $authors_array = array();
 133  
 134      $authors_query = tep_db_query("select authors_id, authors_name from " . TABLE_AUTHORS . " order by authors_name");
 135      while ($authors = tep_db_fetch_array($authors_query)) {
 136        $authors_array[] = array('id' => $authors['authors_id'], 'text' => $authors['authors_name']);
 137      }
 138  
 139      return $authors_array;
 140    }
 141  
 142  ////

 143  // Return all subtopic IDs

 144  // TABLES: topics

 145    function tep_get_subtopics(&$subtopics_array, $parent_id = 0) {
 146      $subtopics_query = tep_db_query("select topics_id from " . TABLE_TOPICS . " where parent_id = '" . (int)$parent_id . "'");
 147      while ($subtopics = tep_db_fetch_array($subtopics_query)) {
 148        $subtopics_array[sizeof($subtopics_array)] = $subtopics['topics_id'];
 149        if ($subtopics['topics_id'] != $parent_id) {
 150          tep_get_subtopics($subtopics_array, $subtopics['topics_id']);
 151        }
 152      }
 153    }
 154  
 155  ////

 156  // Recursively go through the topics and retreive all parent topic IDs

 157  // TABLES: topics

 158    function tep_get_parent_topics(&$topics, $topics_id) {
 159      $parent_topics_query = tep_db_query("select parent_id from " . TABLE_TOPICS . " where topics_id = '" . (int)$topics_id . "'");
 160      while ($parent_topics = tep_db_fetch_array($parent_topics_query)) {
 161        if ($parent_topics['parent_id'] == 0) return true;
 162        $topics[sizeof($topics)] = $parent_topics['parent_id'];
 163        if ($parent_topics['parent_id'] != $topics_id) {
 164          tep_get_parent_topics($topics, $parent_topics['parent_id']);
 165        }
 166      }
 167    }
 168  
 169  ////

 170  // Construct a topic path to the article

 171  // TABLES: articles_to_topics

 172    function tep_get_article_path($articles_id) {
 173      $tPath = '';
 174  
 175      $topic_query = tep_db_query("select a2t.topics_id from " . TABLE_ARTICLES . " a, " . TABLE_ARTICLES_TO_TOPICS . " a2t where a.articles_id = '" . (int)$articles_id . "' and a.articles_status = '1' and a.articles_id = a2t.articles_id limit 1");
 176      if (tep_db_num_rows($topic_query)) {
 177        $topic = tep_db_fetch_array($topic_query);
 178  
 179        $topics = array();
 180        tep_get_parent_topics($topics, $topic['topics_id']);
 181  
 182        $topics = array_reverse($topics);
 183  
 184        $tPath = implode('_', $topics);
 185  
 186        if (tep_not_null($tPath)) $tPath .= '_';
 187        $tPath .= $topic['topics_id'];
 188      }
 189  
 190      return $tPath;
 191    }
 192  
 193  ////

 194  // Return an article's name

 195  // TABLES: articles

 196    function tep_get_articles_name($article_id, $language = '') {
 197      global $languages_id;
 198  
 199      if (empty($language)) $language = $languages_id;
 200  
 201      $article_query = tep_db_query("select articles_name from " . TABLE_ARTICLES_DESCRIPTION . " where articles_id = '" . (int)$article_id . "' and language_id = '" . (int)$language . "'");
 202      $article = tep_db_fetch_array($article_query);
 203  
 204      return $article['articles_name'];
 205    }
 206  
 207  ////

 208  //! Cache the articles box

 209  // Cache the articles box

 210    function tep_cache_topics_box($auto_expire = false, $refresh = false) {
 211      global $tPath, $language, $languages_id, $tree, $tPath_array, $topics_string;
 212  
 213      if (($refresh == true) || !read_cache($cache_output, 'topics_box-' . $language . '.cache' . $tPath, $auto_expire)) {
 214        ob_start();
 215        include (DIR_WS_BOXES . 'articles.php');
 216        $cache_output = ob_get_contents();
 217        ob_end_clean();
 218        write_cache($cache_output, 'topics_box-' . $language . '.cache' . $tPath);
 219      }
 220  
 221      return $cache_output;
 222    }
 223  
 224  ////

 225  //! Cache the authors box

 226  // Cache the authors box

 227    function tep_cache_authors_box($auto_expire = false, $refresh = false) {
 228      global $HTTP_GET_VARS, $language;
 229  
 230      $authors_id = '';
 231      if (isset($HTTP_GET_VARS['authors_id']) && tep_not_null($HTTP_GET_VARS['authors_id'])) {
 232        $authors_id = $HTTP_GET_VARS['authors_id'];
 233      }
 234  
 235      if (($refresh == true) || !read_cache($cache_output, 'authors_box-' . $language . '.cache' . $authors_id, $auto_expire)) {
 236        ob_start();
 237        include (DIR_WS_BOXES . 'authors.php');
 238        $cache_output = ob_get_contents();
 239        ob_end_clean();
 240        write_cache($cache_output, 'authors_box-' . $language . '.cache' . $authors_id);
 241      }
 242  
 243      return $cache_output;
 244    }
 245  
 246  ?>


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