[ Index ] |
PHP Cross Reference of osCMax 2.0.4 |
[Summary view] [Print] [Text view]
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 function tep_get_topic_name($topic_id, $language_id) { 31 $topic_query = tep_db_query("select topics_name from " . TABLE_TOPICS_DESCRIPTION . " where topics_id = '" . (int)$topic_id . "' and language_id = '" . (int)$language_id . "'"); 32 $topic = tep_db_fetch_array($topic_query); 33 34 return $topic['topics_name']; 35 } 36 37 function tep_get_topic_tree($parent_id = '0', $spacing = '', $exclude = '', $topic_tree_array = '', $include_itself = false) { 38 global $languages_id; 39 40 if (!is_array($topic_tree_array)) $topic_tree_array = array(); 41 if ( (sizeof($topic_tree_array) < 1) && ($exclude != '0') ) $topic_tree_array[] = array('id' => '0', 'text' => TEXT_TOP); 42 43 if ($include_itself) { 44 $topic_query = tep_db_query("select cd.topics_name from " . TABLE_TOPICS_DESCRIPTION . " cd where cd.language_id = '" . (int)$languages_id . "' and cd.topics_id = '" . (int)$parent_id . "'"); 45 $topic = tep_db_fetch_array($topic_query); 46 $topic_tree_array[] = array('id' => $parent_id, 'text' => $topic['topics_name']); 47 } 48 49 $topics_query = tep_db_query("select c.topics_id, cd.topics_name, c.parent_id from " . TABLE_TOPICS . " c, " . TABLE_TOPICS_DESCRIPTION . " cd where c.topics_id = cd.topics_id and cd.language_id = '" . (int)$languages_id . "' and c.parent_id = '" . (int)$parent_id . "' order by c.sort_order, cd.topics_name"); 50 while ($topics = tep_db_fetch_array($topics_query)) { 51 if ($exclude != $topics['topics_id']) $topic_tree_array[] = array('id' => $topics['topics_id'], 'text' => $spacing . $topics['topics_name']); 52 $topic_tree_array = tep_get_topic_tree($topics['topics_id'], $spacing . ' ', $exclude, $topic_tree_array); 53 } 54 55 return $topic_tree_array; 56 } 57 58 function tep_generate_topic_path($id, $from = 'topic', $topics_array = '', $index = 0) { 59 global $languages_id; 60 61 if (!is_array($topics_array)) $topics_array = array(); 62 63 if ($from == 'article') { 64 $topics_query = tep_db_query("select topics_id from " . TABLE_ARTICLES_TO_TOPICS . " where articles_id = '" . (int)$id . "'"); 65 while ($topics = tep_db_fetch_array($topics_query)) { 66 if ($topics['topics_id'] == '0') { 67 $topics_array[$index][] = array('id' => '0', 'text' => TEXT_TOP); 68 } else { 69 $topic_query = tep_db_query("select cd.topics_name, c.parent_id from " . TABLE_TOPICS . " c, " . TABLE_TOPICS_DESCRIPTION . " cd where c.topics_id = '" . (int)$topics['topics_id'] . "' and c.topics_id = cd.topics_id and cd.language_id = '" . (int)$languages_id . "'"); 70 $topic = tep_db_fetch_array($topic_query); 71 $topics_array[$index][] = array('id' => $topics['topics_id'], 'text' => $topic['topics_name']); 72 if ( (tep_not_null($topic['parent_id'])) && ($topic['parent_id'] != '0') ) $topics_array = tep_generate_topic_path($topic['parent_id'], 'topic', $topics_array, $index); 73 $topics_array[$index] = array_reverse($topics_array[$index]); 74 } 75 $index++; 76 } 77 } elseif ($from == 'topic') { 78 $topic_query = tep_db_query("select cd.topics_name, c.parent_id from " . TABLE_TOPICS . " c, " . TABLE_TOPICS_DESCRIPTION . " cd where c.topics_id = '" . (int)$id . "' and c.topics_id = cd.topics_id and cd.language_id = '" . (int)$languages_id . "'"); 79 $topic = tep_db_fetch_array($topic_query); 80 $topics_array[$index][] = array('id' => $id, 'text' => $topic['topics_name']); 81 if ( (tep_not_null($topic['parent_id'])) && ($topic['parent_id'] != '0') ) $topics_array = tep_generate_topic_path($topic['parent_id'], 'topic', $topics_array, $index); 82 } 83 84 return $topics_array; 85 } 86 87 function tep_output_generated_topic_path($id, $from = 'topic') { 88 $calculated_topic_path_string = ''; 89 $calculated_topic_path = tep_generate_topic_path($id, $from); 90 for ($i=0, $n=sizeof($calculated_topic_path); $i<$n; $i++) { 91 for ($j=0, $k=sizeof($calculated_topic_path[$i]); $j<$k; $j++) { 92 $calculated_topic_path_string .= $calculated_topic_path[$i][$j]['text'] . ' > '; 93 } 94 $calculated_topic_path_string = substr($calculated_topic_path_string, 0, -16) . '<br>'; 95 } 96 $calculated_topic_path_string = substr($calculated_topic_path_string, 0, -4); 97 98 if (strlen($calculated_topic_path_string) < 1) $calculated_topic_path_string = TEXT_TOP; 99 100 return $calculated_topic_path_string; 101 } 102 103 //// 104 // Generate a path to topics 105 function tep_get_topic_path($current_topic_id = '') { 106 global $tPath_array; 107 108 if (tep_not_null($current_topic_id)) { 109 $cp_size = sizeof($tPath_array); 110 if ($cp_size == 0) { 111 $tPath_new = $current_topic_id; 112 } else { 113 $tPath_new = ''; 114 $last_topic_query = tep_db_query("select parent_id from " . TABLE_TOPICS . " where topics_id = '" . (int)$tPath_array[($cp_size-1)] . "'"); 115 $last_topic = tep_db_fetch_array($last_topic_query); 116 117 $current_topic_query = tep_db_query("select parent_id from " . TABLE_TOPICS . " where topics_id = '" . (int)$current_topic_id . "'"); 118 $current_topic = tep_db_fetch_array($current_topic_query); 119 120 if ($last_topic['parent_id'] == $current_topic['parent_id']) { 121 for ($i=0; $i<($cp_size-1); $i++) { 122 $tPath_new .= '_' . $tPath_array[$i]; 123 } 124 } else { 125 for ($i=0; $i<$cp_size; $i++) { 126 $tPath_new .= '_' . $tPath_array[$i]; 127 } 128 } 129 $tPath_new .= '_' . $current_topic_id; 130 131 if (substr($tPath_new, 0, 1) == '_') { 132 $tPath_new = substr($tPath_new, 1); 133 } 134 } 135 } else { 136 $tPath_new = implode('_', $tPath_array); 137 } 138 139 return 'tPath=' . $tPath_new; 140 } 141 142 function tep_get_generated_topic_path_ids($id, $from = 'topic') { 143 $calculated_topic_path_string = ''; 144 $calculated_topic_path = tep_generate_topic_path($id, $from); 145 for ($i=0, $n=sizeof($calculated_topic_path); $i<$n; $i++) { 146 for ($j=0, $k=sizeof($calculated_topic_path[$i]); $j<$k; $j++) { 147 $calculated_topic_path_string .= $calculated_topic_path[$i][$j]['id'] . '_'; 148 } 149 $calculated_topic_path_string = substr($calculated_topic_path_string, 0, -1) . '<br>'; 150 } 151 $calculated_topic_path_string = substr($calculated_topic_path_string, 0, -4); 152 153 if (strlen($calculated_topic_path_string) < 1) $calculated_topic_path_string = TEXT_TOP; 154 155 return $calculated_topic_path_string; 156 } 157 158 //// 159 // Return the authors URL in the needed language 160 // TABLES: authors_info 161 function tep_get_author_url($author_id, $language_id) { 162 $author_query = tep_db_query("select authors_url from " . TABLE_AUTHORS_INFO . " where authors_id = '" . (int)$author_id . "' and languages_id = '" . (int)$language_id . "'"); 163 $author = tep_db_fetch_array($author_query); 164 165 return $author['authors_url']; 166 } 167 168 //// 169 // Return the authors description in the needed language 170 // TABLES: authors_info 171 function tep_get_author_description($author_id, $language_id) { 172 $author_query = tep_db_query("select authors_description from " . TABLE_AUTHORS_INFO . " where authors_id = '" . (int)$author_id . "' and languages_id = '" . (int)$language_id . "'"); 173 $author = tep_db_fetch_array($author_query); 174 175 return $author['authors_description']; 176 } 177 178 //// 179 // Sets the status of an article 180 function tep_set_article_status($articles_id, $status) { 181 if ($status == '1') { 182 return tep_db_query("update " . TABLE_ARTICLES . " set articles_status = '1', articles_last_modified = now() where articles_id = '" . (int)$articles_id . "'"); 183 } elseif ($status == '0') { 184 return tep_db_query("update " . TABLE_ARTICLES . " set articles_status = '0', articles_last_modified = now() where articles_id = '" . (int)$articles_id . "'"); 185 } else { 186 return -1; 187 } 188 } 189 190 function tep_get_articles_name($article_id, $language_id = 0) { 191 global $languages_id; 192 193 if ($language_id == 0) $language_id = $languages_id; 194 $article_query = tep_db_query("select articles_name from " . TABLE_ARTICLES_DESCRIPTION . " where articles_id = '" . (int)$article_id . "' and language_id = '" . (int)$language_id . "'"); 195 $article = tep_db_fetch_array($article_query); 196 197 return $article['articles_name']; 198 } 199 200 function tep_get_articles_head_title_tag($article_id, $language_id = 0) { 201 global $languages_id; 202 203 if ($language_id == 0) $language_id = $languages_id; 204 $article_query = tep_db_query("select articles_head_title_tag from " . TABLE_ARTICLES_DESCRIPTION . " where articles_id = '" . (int)$article_id . "' and language_id = '" . (int)$language_id . "'"); 205 $article = tep_db_fetch_array($article_query); 206 207 return $article['articles_head_title_tag']; 208 } 209 210 function tep_get_articles_description($article_id, $language_id) { 211 $article_query = tep_db_query("select articles_description from " . TABLE_ARTICLES_DESCRIPTION . " where articles_id = '" . (int)$article_id . "' and language_id = '" . (int)$language_id . "'"); 212 $article = tep_db_fetch_array($article_query); 213 214 return $article['articles_description']; 215 } 216 217 function tep_get_articles_head_desc_tag($article_id, $language_id) { 218 $article_query = tep_db_query("select articles_head_desc_tag from " . TABLE_ARTICLES_DESCRIPTION . " where articles_id = '" . (int)$article_id . "' and language_id = '" . (int)$language_id . "'"); 219 $article = tep_db_fetch_array($article_query); 220 221 return $article['articles_head_desc_tag']; 222 } 223 224 function tep_get_articles_head_keywords_tag($article_id, $language_id) { 225 $article_query = tep_db_query("select articles_head_keywords_tag from " . TABLE_ARTICLES_DESCRIPTION . " where articles_id = '" . (int)$article_id . "' and language_id = '" . (int)$language_id . "'"); 226 $article = tep_db_fetch_array($article_query); 227 228 return $article['articles_head_keywords_tag']; 229 } 230 231 function tep_get_articles_url($article_id, $language_id) { 232 $article_query = tep_db_query("select articles_url from " . TABLE_ARTICLES_DESCRIPTION . " where articles_id = '" . (int)$article_id . "' and language_id = '" . (int)$language_id . "'"); 233 $article = tep_db_fetch_array($article_query); 234 235 return $article['articles_url']; 236 } 237 238 239 //// 240 // Count how many articles exist in a topic 241 // TABLES: articles, articles_to_topics, topics 242 function tep_articles_in_topic_count($topics_id, $include_deactivated = false) { 243 $articles_count = 0; 244 245 if ($include_deactivated) { 246 $articles_query = tep_db_query("select count(*) as total from " . TABLE_ARTICLES . " p, " . TABLE_ARTICLES_TO_TOPICS . " p2c where p.articles_id = p2c.articles_id and p2c.topics_id = '" . (int)$topics_id . "'"); 247 } else { 248 $articles_query = tep_db_query("select count(*) as total from " . TABLE_ARTICLES . " p, " . TABLE_ARTICLES_TO_TOPICS . " p2c where p.articles_id = p2c.articles_id and p.articles_status = '1' and p2c.topics_id = '" . (int)$topics_id . "'"); 249 } 250 251 $articles = tep_db_fetch_array($articles_query); 252 253 $articles_count += $articles['total']; 254 255 $childs_query = tep_db_query("select topics_id from " . TABLE_TOPICS . " where parent_id = '" . (int)$topics_id . "'"); 256 if (tep_db_num_rows($childs_query)) { 257 while ($childs = tep_db_fetch_array($childs_query)) { 258 $articles_count += tep_articles_in_topic_count($childs['topics_id'], $include_deactivated); 259 } 260 } 261 262 return $articles_count; 263 } 264 265 //// 266 // Count how many subtopics exist in a topic 267 // TABLES: topics 268 function tep_childs_in_topic_count($topics_id) { 269 $topics_count = 0; 270 271 $topics_query = tep_db_query("select topics_id from " . TABLE_TOPICS . " where parent_id = '" . (int)$topics_id . "'"); 272 while ($topics = tep_db_fetch_array($topics_query)) { 273 $topics_count++; 274 $topics_count += tep_childs_in_topic_count($topics['topics_id']); 275 } 276 277 return $topics_count; 278 } 279 280 function tep_remove_topic($topic_id) { 281 $topic_image_query = tep_db_query("select topics_image from " . TABLE_TOPICS . " where topics_id = '" . (int)$topic_id . "'"); 282 $topic_image = tep_db_fetch_array($topic_image_query); 283 284 $duplicate_image_query = tep_db_query("select count(*) as total from " . TABLE_TOPICS . " where topics_image = '" . tep_db_input($topic_image['topics_image']) . "'"); 285 $duplicate_image = tep_db_fetch_array($duplicate_image_query); 286 287 if ($duplicate_image['total'] < 2) { 288 if (file_exists(DIR_FS_CATALOG_IMAGES . $topic_image['topics_image'])) { 289 @unlink(DIR_FS_CATALOG_IMAGES . $topic_image['topics_image']); 290 } 291 } 292 293 tep_db_query("delete from " . TABLE_TOPICS . " where topics_id = '" . (int)$topic_id . "'"); 294 tep_db_query("delete from " . TABLE_TOPICS_DESCRIPTION . " where topics_id = '" . (int)$topic_id . "'"); 295 tep_db_query("delete from " . TABLE_ARTICLES_TO_TOPICS . " where topics_id = '" . (int)$topic_id . "'"); 296 297 if (USE_CACHE == 'true') { 298 tep_reset_cache_block('topics'); 299 tep_reset_cache_block('also_purchased'); 300 } 301 } 302 303 function tep_remove_article($article_id) { 304 tep_db_query("delete from " . TABLE_ARTICLES . " where articles_id = '" . (int)$article_id . "'"); 305 tep_db_query("delete from " . TABLE_ARTICLES_TO_TOPICS . " where articles_id = '" . (int)$article_id . "'"); 306 tep_db_query("delete from " . TABLE_ARTICLES_DESCRIPTION . " where articles_id = '" . (int)$article_id . "'"); 307 308 $article_reviews_query = tep_db_query("select reviews_id from " . TABLE_ARTICLE_REVIEWS . " where articles_id = '" . (int)$article_id . "'"); 309 while ($article_reviews = tep_db_fetch_array($article_reviews_query)) { 310 tep_db_query("delete from " . TABLE_ARTICLE_REVIEWS_DESCRIPTION . " where reviews_id = '" . (int)$article_reviews['reviews_id'] . "'"); 311 } 312 tep_db_query("delete from " . TABLE_ARTICLE_REVIEWS . " where articles_id = '" . (int)$article_id . "'"); 313 314 if (USE_CACHE == 'true') { 315 tep_reset_cache_block('topics'); 316 tep_reset_cache_block('also_purchased'); 317 } 318 } 319 320 // Topics Description contribution 321 function tep_get_topic_heading_title($topic_id, $language_id) { 322 $topic_query = tep_db_query("select topics_heading_title from " . TABLE_TOPICS_DESCRIPTION . " where topics_id = '" . $topic_id . "' and language_id = '" . $language_id . "'"); 323 $topic = tep_db_fetch_array($topic_query); 324 return $topic['topics_heading_title']; 325 } 326 327 function tep_get_topic_description($topic_id, $language_id) { 328 $topic_query = tep_db_query("select topics_description from " . TABLE_TOPICS_DESCRIPTION . " where topics_id = '" . $topic_id . "' and language_id = '" . $language_id . "'"); 329 $topic = tep_db_fetch_array($topic_query); 330 return $topic['topics_description']; 331 } 332 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Jan 1 13:43:16 2010 | Cross-referenced by PHPXref 0.7 |