· 10 years ago · Sep 14, 2016, 08:20 PM
1<?php
2define('USE_SEO_REDIRECT_DEBUG', 'false');
3/**
4 * Ultimate SEO URLs Contribution - osCommerce MS-2.2
5 *
6 * Ultimate SEO URLs offers search engine optimized URLS for osCommerce
7 * based applications. Other features include optimized performance and
8 * automatic redirect script.
9 * @package Ultimate-SEO-URLs
10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 * @version 2.1
12 * @link http://www.oscommerce-freelancers.com/ osCommerce-Freelancers
13 * @copyright Copyright 2005, Bobby Easland
14 * @author Bobby Easland
15 * @filesource
16 */
17
18/**
19 * SEO_DataBase Class
20 *
21 * The SEO_DataBase class provides abstraction so the databaes can be accessed
22 * without having to use tep API functions. This class has minimal error handling
23 * so make sure your code is tight!
24 * @package Ultimate-SEO-URLs
25 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
26 * @version 1.1
27 * @link http://www.oscommerce-freelancers.com/ osCommerce-Freelancers
28 * @copyright Copyright 2005, Bobby Easland
29 * @author Bobby Easland
30 */
31class SEO_DataBase{
32 /**
33 * Database host (localhost, IP based, etc)
34 * @var string
35 */
36 var $host;
37 /**
38 * Database user
39 * @var string
40 */
41 var $user;
42 /**
43 * Database name
44 * @var string
45 */
46 var $db;
47 /**
48 * Database password
49 * @var string
50 */
51 var $pass;
52 /**
53 * Database link
54 * @var resource
55 */
56 var $link_id;
57
58/**
59 * MySQL_DataBase class constructor
60 * @author Bobby Easland
61 * @version 1.0
62 * @param string $host
63 * @param string $user
64 * @param string $db
65 * @param string $pass
66 */
67 function SEO_DataBase($host, $user, $db, $pass){
68 $this->host = $host;
69 $this->user = $user;
70 $this->db = $db;
71 $this->pass = $pass;
72 $this->ConnectDB();
73 $this->SelectDB();
74 } # end function
75
76/**
77 * Function to connect to MySQL
78 * @author Bobby Easland
79 * @version 1.1
80 */
81 function ConnectDB(){
82 $this->link_id = mysql_connect($this->host, $this->user, $this->pass);
83 } # end function
84
85/**
86 * Function to select the database
87 * @author Bobby Easland
88 * @version 1.0
89 * @return resoource
90 */
91 function SelectDB(){
92 return mysql_select_db($this->db);
93 } # end function
94
95/**
96 * Function to perform queries
97 * @author Bobby Easland
98 * @version 1.0
99 * @param string $query SQL statement
100 * @return resource
101 */
102 function Query($query){
103 return @mysql_query($query, $this->link_id);
104 } # end function
105
106/**
107 * Function to fetch array
108 * @author Bobby Easland
109 * @version 1.0
110 * @param resource $resource_id
111 * @param string $type MYSQL_BOTH or MYSQL_ASSOC
112 * @return array
113 */
114 function FetchArray($resource_id, $type = MYSQL_BOTH){
115 return @mysql_fetch_array($resource_id, $type);
116 } # end function
117
118/**
119 * Function to fetch the number of rows
120 * @author Bobby Easland
121 * @version 1.0
122 * @param resource $resource_id
123 * @return mixed
124 */
125 function NumRows($resource_id){
126 return @mysql_num_rows($resource_id);
127 } # end function
128
129/**
130 * Function to fetch the last insertID
131 * @author Bobby Easland
132 * @version 1.0
133 * @return integer
134 */
135 function InsertID() {
136 return mysql_insert_id();
137 }
138
139/**
140 * Function to free the resource
141 * @author Bobby Easland
142 * @version 1.0
143 * @param resource $resource_id
144 * @return boolean
145 */
146 function Free($resource_id){
147 return @mysql_free_result($resource_id);
148 } # end function
149
150/**
151 * Function to add slashes
152 * @author Bobby Easland
153 * @version 1.0
154 * @param string $data
155 * @return string
156 */
157 function Slashes($data){
158 return addslashes($data);
159 } # end function
160
161/**
162 * Function to perform DB inserts and updates - abstracted from osCommerce-MS-2.2 project
163 * @author Bobby Easland
164 * @version 1.0
165 * @param string $table Database table
166 * @param array $data Associative array of columns / values
167 * @param string $action insert or update
168 * @param string $parameters
169 * @return resource
170 */
171 function DBPerform($table, $data, $action = 'insert', $parameters = '') {
172 reset($data);
173 if ($action == 'insert') {
174 $query = 'INSERT INTO `' . $table . '` (';
175 while (list($columns, ) = each($data)) {
176 $query .= '`' . $columns . '`, ';
177 }
178 $query = substr($query, 0, -2) . ') values (';
179 reset($data);
180 while (list(, $value) = each($data)) {
181 switch ((string)$value) {
182 case 'now()':
183 $query .= 'now(), ';
184 break;
185 case 'null':
186 $query .= 'null, ';
187 break;
188 default:
189 $query .= "'" . $this->Slashes($value) . "', ";
190 break;
191 }
192 }
193 $query = substr($query, 0, -2) . ')';
194 } elseif ($action == 'update') {
195 $query = 'UPDATE `' . $table . '` SET ';
196 while (list($columns, $value) = each($data)) {
197 switch ((string)$value) {
198 case 'now()':
199 $query .= '`' .$columns . '`=now(), ';
200 break;
201 case 'null':
202 $query .= '`' .$columns .= '`=null, ';
203 break;
204 default:
205 $query .= '`' .$columns . "`='" . $this->Slashes($value) . "', ";
206 break;
207 }
208 }
209 $query = substr($query, 0, -2) . ' WHERE ' . $parameters;
210 }
211 return $this->Query($query);
212 } # end function
213} # end class
214
215/**
216 * Ultimate SEO URLs Installer and Configuration Class
217 *
218 * Ultimate SEO URLs installer and configuration class offers a modular
219 * and easy to manage method of configuration. The class enables the base
220 * class to be configured and installed on the fly without the hassle of
221 * calling additional scripts or executing SQL.
222 * @package Ultimate-SEO-URLs
223 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
224 * @version 1.1
225 * @link http://www.oscommerce-freelancers.com/ osCommerce-Freelancers
226 * @copyright Copyright 2005, Bobby Easland
227 * @author Bobby Easland
228 */
229class SEO_URL_INSTALLER{
230 /**
231 * The default_config array has all the default settings which should be all that is needed to make the base class work.
232 * @var array
233 */
234 var $default_config;
235 /**
236 * Database object
237 * @var object
238 */
239 var $DB;
240 /**
241 * $attributes array holds information about this instance
242 * @var array
243 */
244 var $attributes;
245
246/**
247 * SEO_URL_INSTALLER class constructor
248 * @author Bobby Easland
249 * @version 1.1
250 */
251 function SEO_URL_INSTALLER(){
252
253 $this->attributes = array();
254
255 $x = 0;
256 $this->default_config = array();
257 $this->default_config['SEO_ENABLED'] = array('DEFAULT' => 'true',
258 'QUERY' => "INSERT INTO `".TABLE_CONFIGURATION."` VALUES ('', 'Enable SEO URLs?', 'SEO_ENABLED', 'true', 'Enable the SEO URLs? This is a global setting and will turn them off completely.', GROUP_INSERT_ID, ".$x.", NOW(), NOW(), NULL, 'tep_cfg_select_option(array(''true'', ''false''),')"
259 );
260 $x++;
261 $this->default_config['SEO_ADD_CPATH_TO_PRODUCT_URLS'] = array('DEFAULT' => 'false',
262 'QUERY' => "INSERT INTO `".TABLE_CONFIGURATION."` VALUES ('', 'Add cPath to product URLs?', 'SEO_ADD_CPATH_TO_PRODUCT_URLS', 'false', 'This setting will append the cPath to the end of product URLs (i.e. - some-product-p-1.html?cPath=xx).', GROUP_INSERT_ID, ".$x.", NOW(), NOW(), NULL, 'tep_cfg_select_option(array(''true'', ''false''),')"
263 );
264 $x++;
265 $this->default_config['SEO_ADD_CAT_PARENT'] = array('DEFAULT' => 'true',
266 'QUERY' => "INSERT INTO `".TABLE_CONFIGURATION."` VALUES ('', 'Add category parent to begining of URLs?', 'SEO_ADD_CAT_PARENT', 'true', 'This setting will add the category parent name to the beginning of the category URLs (i.e. - parent-category-c-1.html).', GROUP_INSERT_ID, ".$x.", NOW(), NOW(), NULL, 'tep_cfg_select_option(array(''true'', ''false''),')"
267 );
268 $x++;
269 $this->default_config['SEO_URLS_FILTER_SHORT_WORDS'] = array('DEFAULT' => '3',
270 'QUERY' => "INSERT INTO `".TABLE_CONFIGURATION."` VALUES ('', 'Filter Short Words', 'SEO_URLS_FILTER_SHORT_WORDS', '3', 'This setting will filter words less than or equal to the value from the URL.', GROUP_INSERT_ID, ".$x.", NOW(), NOW(), NULL, NULL)"
271 );
272 $x++;
273 $this->default_config['SEO_URLS_USE_W3C_VALID'] = array('DEFAULT' => 'true',
274 'QUERY' => "INSERT INTO `".TABLE_CONFIGURATION."` VALUES ('', 'Output W3C valid URLs (parameter string)?', 'SEO_URLS_USE_W3C_VALID', 'true', 'This setting will output W3C valid URLs.', GROUP_INSERT_ID, ".$x.", NOW(), NOW(), NULL, 'tep_cfg_select_option(array(''true'', ''false''),')"
275 );
276 $x++;
277 $this->default_config['USE_SEO_CACHE_GLOBAL'] = array('DEFAULT' => 'true',
278 'QUERY' => "INSERT INTO `".TABLE_CONFIGURATION."` VALUES ('', 'Enable SEO cache to save queries?', 'USE_SEO_CACHE_GLOBAL', 'true', 'This is a global setting and will turn off caching completely.', GROUP_INSERT_ID, ".$x.", NOW(), NOW(), NULL, 'tep_cfg_select_option(array(''true'', ''false''),')"
279 );
280 $x++;
281 $this->default_config['USE_SEO_CACHE_PRODUCTS'] = array('DEFAULT' => 'true',
282 'QUERY' => "INSERT INTO `".TABLE_CONFIGURATION."` VALUES ('', 'Enable product cache?', 'USE_SEO_CACHE_PRODUCTS', 'true', 'This will turn off caching for the products.', GROUP_INSERT_ID, ".$x.", NOW(), NOW(), NULL, 'tep_cfg_select_option(array(''true'', ''false''),')"
283 );
284 $x++;
285 $this->default_config['USE_SEO_CACHE_CATEGORIES'] = array('DEFAULT' => 'true',
286 'QUERY' => "INSERT INTO `".TABLE_CONFIGURATION."` VALUES ('', 'Enable categories cache?', 'USE_SEO_CACHE_CATEGORIES', 'true', 'This will turn off caching for the categories.', GROUP_INSERT_ID, ".$x.", NOW(), NOW(), NULL, 'tep_cfg_select_option(array(''true'', ''false''),')"
287 );
288
289 $x++;
290 $this->default_config['USE_SEO_CACHE_MANUFACTURERS'] = array('DEFAULT' => 'true',
291 'QUERY' => "INSERT INTO `".TABLE_CONFIGURATION."` VALUES ('', 'Enable manufacturers cache?', 'USE_SEO_CACHE_MANUFACTURERS', 'true', 'This will turn off caching for the manufacturers.', GROUP_INSERT_ID, ".$x.", NOW(), NOW(), NULL, 'tep_cfg_select_option(array(''true'', ''false''),')"
292 );
293
294 $x++;
295 $this->default_config['USE_SEO_CACHE_ARTICLES'] = array('DEFAULT' => 'true',
296 'QUERY' => "INSERT INTO `".TABLE_CONFIGURATION."` VALUES ('', 'Enable articles cache?', 'USE_SEO_CACHE_ARTICLES', 'true', 'This will turn off caching for the articles.', GROUP_INSERT_ID, ".$x.", NOW(), NOW(), NULL, 'tep_cfg_select_option(array(''true'', ''false''),')"
297 );
298 $x++;
299 $this->default_config['USE_SEO_CACHE_TOPICS'] = array('DEFAULT' => 'true',
300 'QUERY' => "INSERT INTO `".TABLE_CONFIGURATION."` VALUES ('', 'Enable topics cache?', 'USE_SEO_CACHE_TOPICS', 'true', 'This will turn off caching for the article topics.', GROUP_INSERT_ID, ".$x.", NOW(), NOW(), NULL, 'tep_cfg_select_option(array(''true'', ''false''),')"
301 );
302 $x++;
303 $this->default_config['USE_SEO_CACHE_INFO_PAGES'] = array('DEFAULT' => 'true',
304 'QUERY' => "INSERT INTO `".TABLE_CONFIGURATION."` VALUES ('', 'Enable information cache?', 'USE_SEO_CACHE_INFO_PAGES', 'true', 'This will turn off caching for the information pages.', GROUP_INSERT_ID, ".$x.", NOW(), NOW(), NULL, 'tep_cfg_select_option(array(''true'', ''false''),')"
305 );
306//ojp b
307 $x++;
308 $this->default_config['USE_SEO_CACHE_LINKS'] = array('DEFAULT' => 'true',
309 'QUERY' => "INSERT INTO `".TABLE_CONFIGURATION."` VALUES ('', 'Enable link directory cache?', 'USE_SEO_CACHE_LINKS', 'true', 'This will turn off caching for the link category pages.', GROUP_INSERT_ID, ".$x.", NOW(), NOW(), NULL, 'tep_cfg_select_option(array(''true'', ''false''),')"
310 );
311//ojp e
312 $x++;
313 $this->default_config['USE_SEO_REDIRECT'] = array('DEFAULT' => 'true',
314 'QUERY' => "INSERT INTO `".TABLE_CONFIGURATION."` VALUES ('', 'Enable automatic redirects?', 'USE_SEO_REDIRECT', 'true', 'This will activate the automatic redirect code and send 301 headers for old to new URLs.', GROUP_INSERT_ID, ".$x.", NOW(), NOW(), NULL, 'tep_cfg_select_option(array(''true'', ''false''),')"
315 );
316 $x++;
317 $this->default_config['SEO_REWRITE_TYPE'] = array('DEFAULT' => 'Rewrite',
318 'QUERY' => "INSERT INTO `".TABLE_CONFIGURATION."` VALUES ('', 'Choose URL Rewrite Type', 'SEO_REWRITE_TYPE', 'Rewrite', 'Choose which SEO URL format to use.', GROUP_INSERT_ID, ".$x.", NOW(), NOW(), NULL, 'tep_cfg_select_option(array(''Rewrite''),')"
319 );
320 $x++;
321 $this->default_config['SEO_CHAR_CONVERT_SET'] = array('DEFAULT' => '',
322 'QUERY' => "INSERT INTO `".TABLE_CONFIGURATION."` VALUES ('', 'Enter special character conversions', 'SEO_CHAR_CONVERT_SET', '', 'This setting will convert characters.<br><br>The format <b>MUST</b> be in the form: <b>char=>conv,char2=>conv2</b>', GROUP_INSERT_ID, ".$x.", NOW(), NOW(), NULL, NULL)"
323 );
324 $x++;
325 $this->default_config['SEO_REMOVE_ALL_SPEC_CHARS'] = array('DEFAULT' => 'false',
326 'QUERY' => "INSERT INTO `".TABLE_CONFIGURATION."` VALUES ('', 'Remove all non-alphanumeric characters?', 'SEO_REMOVE_ALL_SPEC_CHARS', 'false', 'This will remove all non-letters and non-numbers. This should be handy to remove all special characters with 1 setting.', GROUP_INSERT_ID, ".$x.", NOW(), NOW(), NULL, 'tep_cfg_select_option(array(''true'', ''false''),')"
327 );
328 $x++;
329 $this->default_config['SEO_URLS_CACHE_RESET'] = array('DEFAULT' => 'false',
330 'QUERY' => "INSERT INTO `".TABLE_CONFIGURATION."` VALUES ('', 'Reset SEO URLs Cache', 'SEO_URLS_CACHE_RESET', 'false', 'This will reset the cache data for SEO', GROUP_INSERT_ID, ".$x.", NOW(), NOW(), 'tep_reset_cache_data_seo_urls', 'tep_cfg_select_option(array(''reset'', ''false''),')"
331 );
332
333 $this->init();
334 } # end class constructor
335
336/**
337 * Initializer - if there are settings not defined the default config will be used and database settings installed.
338 * @author Bobby Easland
339 * @version 1.1
340 */
341 function init(){
342 foreach( $this->default_config as $key => $value ){
343 $container[] = defined($key) ? 'true' : 'false';
344 } # end foreach
345 $this->attributes['IS_DEFINED'] = in_array('false', $container) ? false : true;
346 switch(true){
347 case ( !$this->attributes['IS_DEFINED'] ):
348 $this->eval_defaults();
349 $this->DB = new SEO_DataBase(DB_SERVER, DB_SERVER_USERNAME, DB_DATABASE, DB_SERVER_PASSWORD);
350 $sql = "SELECT configuration_key, configuration_value
351 FROM " . TABLE_CONFIGURATION . "
352 WHERE configuration_key LIKE '%SEO%'";
353 $result = $this->DB->Query($sql);
354 $num_rows = $this->DB->NumRows($result);
355 $this->DB->Free($result);
356 $this->attributes['IS_INSTALLED'] = (sizeof($container) == $num_rows) ? true : false;
357 if ( !$this->attributes['IS_INSTALLED'] ){
358 $this->install_settings();
359 }
360 break;
361 default:
362 $this->attributes['IS_INSTALLED'] = true;
363 break;
364 } # end switch
365 } # end function
366
367/**
368 * This function evaluates the default serrings into defined constants
369 * @author Bobby Easland
370 * @version 1.0
371 */
372 function eval_defaults(){
373 foreach( $this->default_config as $key => $value ){
374 define($key, $value['DEFAULT']);
375 } # end foreach
376 } # end function
377
378/**
379 * This function removes the database settings (configuration and cache)
380 * @author Bobby Easland
381 * @version 1.0
382 */
383 function uninstall_settings(){
384 $this->DB->Query("DELETE FROM `".TABLE_CONFIGURATION_GROUP."` WHERE `configuration_group_title` LIKE '%SEO%'");
385 $this->DB->Query("DELETE FROM `".TABLE_CONFIGURATION."` WHERE `configuration_key` LIKE '%SEO%'");
386 $this->DB->Query("DROP TABLE IF EXISTS `cache`");
387 } # end function
388
389/**
390 * This function installs the database settings
391 * @author Bobby Easland
392 * @version 1.0
393 */
394 function install_settings(){
395 $this->uninstall_settings();
396 $sort_order_query = "SELECT MAX(sort_order) as max_sort FROM `".TABLE_CONFIGURATION_GROUP."`";
397 $sort = $this->DB->FetchArray( $this->DB->Query($sort_order_query) );
398 $next_sort = $sort['max_sort'] + 1;
399 $insert_group = "INSERT INTO `".TABLE_CONFIGURATION_GROUP."` VALUES ('', 'SEO URLs', 'Options for Ultimate SEO URLs by Chemo', '".$next_sort."', '1')";
400 $this->DB->Query($insert_group);
401 $group_id = $this->DB->InsertID();
402
403 foreach ($this->default_config as $key => $value){
404 $sql = str_replace('GROUP_INSERT_ID', $group_id, $value['QUERY']);
405 $this->DB->Query($sql);
406 }
407
408 $insert_cache_table = "CREATE TABLE `cache` (
409 `cache_id` varchar(32) NOT NULL default '',
410 `cache_language_id` tinyint(1) NOT NULL default '0',
411 `cache_name` varchar(255) NOT NULL default '',
412 `cache_data` mediumtext NOT NULL,
413 `cache_global` tinyint(1) NOT NULL default '1',
414 `cache_gzip` tinyint(1) NOT NULL default '1',
415 `cache_method` varchar(20) NOT NULL default 'RETURN',
416 `cache_date` datetime NOT NULL default '0000-00-00 00:00:00',
417 `cache_expires` datetime NOT NULL default '0000-00-00 00:00:00',
418 PRIMARY KEY (`cache_id`,`cache_language_id`),
419 KEY `cache_id` (`cache_id`),
420 KEY `cache_language_id` (`cache_language_id`),
421 KEY `cache_global` (`cache_global`)
422 ) TYPE=MyISAM;";
423 $this->DB->Query($insert_cache_table);
424 } # end function
425} # end class
426
427/**
428 * Ultimate SEO URLs Base Class
429 *
430 * Ultimate SEO URLs offers search engine optimized URLS for osCommerce
431 * based applications. Other features include optimized performance and
432 * automatic redirect script.
433 * @package Ultimate-SEO-URLs
434 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
435 * @version 2.1
436 * @link http://www.oscommerce-freelancers.com/ osCommerce-Freelancers
437 * @copyright Copyright 2005, Bobby Easland
438 * @author Bobby Easland
439 */
440class SEO_URL{
441 /**
442 * $cache is the per page data array that contains all of the previously stripped titles
443 * @var array
444 */
445 var $cache;
446 /**
447 * $languages_id contains the language_id for this instance
448 * @var integer
449 */
450 var $languages_id;
451 /**
452 * $attributes array contains all the required settings for class
453 * @var array
454 */
455 var $attributes;
456 /**
457 * $base_url is the NONSSL URL for site
458 * @var string
459 */
460 var $base_url;
461 /**
462 * $base_url_ssl is the secure URL for the site
463 * @var string
464 */
465 var $base_url_ssl;
466 /**
467 * $performance array contains evaluation metric data
468 * @var array
469 */
470 var $performance;
471 /**
472 * $timestamp simply holds the temp variable for time calculations
473 * @var float
474 */
475 var $timestamp;
476 /**
477 * $reg_anchors holds the anchors used by the .htaccess rewrites
478 * @var array
479 */
480 var $reg_anchors;
481 /**
482 * $cache_query is the resource_id used for database cache logic
483 * @var resource
484 */
485 var $cache_query;
486 /**
487 * $cache_file is the basename of the cache database entry
488 * @var string
489 */
490 var $cache_file;
491 /**
492 * $data array contains all records retrieved from database cache
493 * @var array
494 */
495 var $data;
496 /**
497 * $need_redirect determines whether the URL needs to be redirected
498 * @var boolean
499 */
500 var $need_redirect;
501 /**
502 * $is_seopage holds value as to whether page is in allowed SEO pages
503 * @var boolean
504 */
505 var $is_seopage;
506 /**
507 * $uri contains the $_SERVER['REQUEST_URI'] value
508 * @var string
509 */
510 var $uri;
511 /**
512 * $real_uri contains the $_SERVER['SCRIPT_NAME'] . '?' . $_SERVER['QUERY_STRING'] value
513 * @var string
514 */
515 var $real_uri;
516 /**
517 * $uri_parsed contains the parsed uri value array
518 * @var array
519 */
520 var $uri_parsed;
521 /**
522 * $path_info contains the getenv('PATH_INFO') value
523 * @var string
524 */
525 var $path_info;
526 /**
527 * $DB is the database object
528 * @var object
529 */
530 var $DB;
531 /**
532 * $installer is the installer object
533 * @var object
534 */
535 var $installer;
536
537/**
538 * SEO_URL class constructor
539 * @author Bobby Easland
540 * @version 1.1
541 * @param integer $languages_id
542 */
543 function SEO_URL($languages_id){
544 global $session_started, $SID;
545
546 $this->installer = new SEO_URL_INSTALLER;
547
548 $this->DB = new SEO_DataBase(DB_SERVER, DB_SERVER_USERNAME, DB_DATABASE, DB_SERVER_PASSWORD);
549
550 $this->languages_id = (int)$languages_id;
551
552 $this->data = array();
553
554//ojp FILENAME_LINKS
555 $seo_pages = array(FILENAME_DEFAULT,
556 FILENAME_PRODUCT_INFO,
557 FILENAME_POPUP_IMAGE,
558 FILENAME_PRODUCT_REVIEWS,
559 FILENAME_PRODUCT_REVIEWS_INFO);
560 if ( defined('FILENAME_ARTICLES') ) $seo_pages[] = FILENAME_ARTICLES;
561 if ( defined('FILENAME_ARTICLE_INFO') ) $seo_pages[] = FILENAME_ARTICLE_INFO;
562 if ( defined('FILENAME_INFORMATION') ) $seo_pages[] = FILENAME_INFORMATION;
563 //if ( defined('pollbooth.php') ) $seo_pages[] = 'pollbooth.php';
564 //$seo_pages[] = 'pollbooth.php';
565 // BOF: Faqdesk support added by faaliyet
566 if ( defined('FILENAME_FAQDESK_INFO') ) $seo_pages[] = FILENAME_FAQDESK_INFO;
567 if ( defined('FILENAME_FAQDESK_INDEX') ) $seo_pages[] = FILENAME_FAQDESK_INDEX;
568 if ( defined('FILENAME_FAQDESK_REVIEWS_INFO') ) $seo_pages[] = FILENAME_FAQDESK_REVIEWS_INFO;
569 if ( defined('FILENAME_FAQDESK_REVIEWS_ARTICLE') ) $seo_pages[] = FILENAME_FAQDESK_REVIEWS_ARTICLE;
570 // EOF: Faqdesk support added by faaliyet
571 // BOF: "Extra pages-info box w/ admin" support added by faaliyet
572 if ( defined('FILENAME_PAGES') ) $seo_pages[] = FILENAME_PAGES;
573 // EOF: "Extra pages-info box w/ admin" support added by faaliyet
574 if ( defined('FILENAME_NEWSDESK_INFO') ) $seo_pages[] = FILENAME_NEWSDESK_INFO;
575 if ( defined('FILENAME_NEWSDESK_INDEX') ) $seo_pages[] = FILENAME_NEWSDESK_INDEX;
576 if ( defined('FILENAME_NEWSDESK_REVIEWS_INFO') ) $seo_pages[] = FILENAME_NEWSDESK_REVIEWS_INFO;
577 if ( defined('FILENAME_NEWSDESK_REVIEWS_ARTICLE') ) $seo_pages[] = FILENAME_NEWSDESK_REVIEWS_ARTICLE;
578 if ( defined('FILENAME_LINKS') ) $seo_pages[] = FILENAME_LINKS;
579
580//ojp USE_SEO_CACHE_LINKS
581 $this->attributes = array('PHP_VERSION' => PHP_VERSION,
582 'SESSION_STARTED' => $session_started,
583 'SID' => $SID,
584 'SEO_ENABLED' => defined('SEO_ENABLED') ? SEO_ENABLED : 'false',
585 'SEO_ADD_CPATH_TO_PRODUCT_URLS' => defined('SEO_ADD_CPATH_TO_PRODUCT_URLS') ? SEO_ADD_CPATH_TO_PRODUCT_URLS : 'false',
586 'SEO_ADD_CAT_PARENT' => defined('SEO_ADD_CAT_PARENT') ? SEO_ADD_CAT_PARENT : 'true',
587 'SEO_URLS_USE_W3C_VALID' => defined('SEO_URLS_USE_W3C_VALID') ? SEO_URLS_USE_W3C_VALID : 'true',
588 'USE_SEO_CACHE_GLOBAL' => defined('USE_SEO_CACHE_GLOBAL') ? USE_SEO_CACHE_GLOBAL : 'false',
589 'USE_SEO_CACHE_PRODUCTS' => defined('USE_SEO_CACHE_PRODUCTS') ? USE_SEO_CACHE_PRODUCTS : 'false',
590 'USE_SEO_CACHE_CATEGORIES' => defined('USE_SEO_CACHE_CATEGORIES') ? USE_SEO_CACHE_CATEGORIES : 'false',
591 'USE_SEO_CACHE_MANUFACTURERS' => defined('USE_SEO_CACHE_MANUFACTURERS') ? USE_SEO_CACHE_MANUFACTURERS : 'false',
592 'USE_SEO_CACHE_ARTICLES' => defined('USE_SEO_CACHE_ARTICLES') ? USE_SEO_CACHE_ARTICLES : 'false',
593 'USE_SEO_CACHE_TOPICS' => defined('USE_SEO_CACHE_TOPICS') ? USE_SEO_CACHE_TOPICS : 'false',
594 'USE_SEO_CACHE_INFO_PAGES' => defined('USE_SEO_CACHE_INFO_PAGES') ? USE_SEO_CACHE_INFO_PAGES : 'false',
595 'USE_SEO_CACHE_LINKS' => defined('USE_SEO_CACHE_LINKS') ? USE_SEO_CACHE_LINKS : 'false',
596 'USE_SEO_REDIRECT' => defined('USE_SEO_REDIRECT') ? USE_SEO_REDIRECT : 'false',
597 'SEO_REWRITE_TYPE' => defined('SEO_REWRITE_TYPE') ? SEO_REWRITE_TYPE : 'false',
598 'SEO_URLS_FILTER_SHORT_WORDS' => defined('SEO_URLS_FILTER_SHORT_WORDS') ? SEO_URLS_FILTER_SHORT_WORDS : 'false',
599 'SEO_CHAR_CONVERT_SET' => defined('SEO_CHAR_CONVERT_SET') ? $this->expand(SEO_CHAR_CONVERT_SET) : 'false',
600 'SEO_REMOVE_ALL_SPEC_CHARS' => defined('SEO_REMOVE_ALL_SPEC_CHARS') ? SEO_REMOVE_ALL_SPEC_CHARS : 'false',
601 'SEO_PAGES' => $seo_pages,
602 'SEO_INSTALLER' => $this->installer->attributes
603 );
604
605 $this->base_url = HTTP_SERVER . DIR_WS_HTTP_CATALOG;
606 $this->base_url_ssl = HTTPS_SERVER . DIR_WS_HTTPS_CATALOG;
607 $this->cache = array();
608
609 $this->timestamp = 0;
610
611//ojp lPath -links- definition
612 $this->reg_anchors = array('products_id' => '-p-',
613 'cPath' => '-c-',
614 'manufacturers_id' => '-m-',
615 'pID' => '-pi-',
616 'tPath' => '-t-',
617 'articles_id' => '-a-',
618 'authors_id' => '-au-',
619 'products_id_review' => '-pr-',
620 'products_id_review_info' => '-pri-',
621 'info_id' => '-i-',
622 'faqdesk_id' => '-f-',
623 'faqPath' => '-fc-',
624 'faqdesk_reviews_id' => '-fri-',
625 'faqdesk_article_id' => '-fra-',
626 'pages_id' => '-pm-',
627 //'pollid' => '-po-',
628 'newsdesk_id' => '-n-',
629 'newsPath' => '-nc-',
630 'newsdesk_reviews_id' => '-nri-',
631 'newsdesk_article_id' => '-nra-',
632 'lPath' => '-links-'
633 );
634
635 $this->performance = array('NUMBER_URLS_GENERATED' => 0,
636 'NUMBER_QUERIES' => 0,
637 'CACHE_QUERY_SAVINGS' => 0,
638 'NUMBER_STANDARD_URLS_GENERATED' => 0,
639 'TOTAL_CACHED_PER_PAGE_RECORDS' => 0,
640 'TOTAL_TIME' => 0,
641 'TIME_PER_URL' => 0,
642 'QUERIES' => array()
643 );
644//ojp generate_link_cache
645 if ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true'){
646 $this->cache_file = 'seo_urls_v2_';
647 $this->cache_gc();
648 if ( $this->attributes['USE_SEO_CACHE_PRODUCTS'] == 'true' ) $this->generate_products_cache();
649 if ( $this->attributes['USE_SEO_CACHE_CATEGORIES'] == 'true' ) $this->generate_categories_cache();
650 if ( $this->attributes['USE_SEO_CACHE_MANUFACTURERS'] == 'true' ) $this->generate_manufacturers_cache();
651 if ( $this->attributes['USE_SEO_CACHE_ARTICLES'] == 'true' && defined('TABLE_ARTICLES_DESCRIPTION')) $this->generate_articles_cache();
652 if ( $this->attributes['USE_SEO_CACHE_TOPICS'] == 'true' && defined('TABLE_TOPICS_DESCRIPTION')) $this->generate_topics_cache();
653 if ( $this->attributes['USE_SEO_CACHE_INFO_PAGES'] == 'true' && defined('TABLE_INFORMATION')) $this->generate_information_cache();
654 if ( $this->attributes['USE_SEO_CACHE_LINK_PAGES'] == 'true' && defined('TABLE_LINK_CATEGORIES')) $this->generate_links_cache();
655
656 } # end if
657
658 if ($this->attributes['USE_SEO_REDIRECT'] == 'true'){
659 $this->check_redirect();
660 } # end if
661 } # end constructor
662
663/**
664 * Function to return SEO URL link SEO'd with stock generattion for error fallback
665 * @author Bobby Easland
666 * @version 1.0
667 * @param string $page Base script for URL
668 * @param string $parameters URL parameters
669 * @param string $connection NONSSL/SSL
670 * @param boolean $add_session_id Switch to add osCsid
671 * @return string Formed href link
672 */
673 function href_link($page = '', $parameters = '', $connection = 'NONSSL', $add_session_id = false){
674 $this->start($this->timestamp);
675 $this->performance['NUMBER_URLS_GENERATED']++;
676 if ( !in_array($page, $this->attributes['SEO_PAGES']) || $this->attributes['SEO_ENABLED'] == 'false' ) {
677 return $this->stock_href_link($page, $parameters, $connection, $add_session_id);
678 }
679 $link = $connection == 'NONSSL' ? $this->base_url : $this->base_url_ssl;
680 $separator = '?';
681 if ($this->not_null($parameters)) {
682 $link .= $this->parse_parameters($page, $parameters, $separator);
683 } else {
684 $link .= $page;
685 }
686 $link = $this->add_sid($link, $add_session_id, $connection, $separator);
687
688 $this->stop($this->timestamp, $time);
689 $this->performance['TOTAL_TIME'] += $time;
690 switch($this->attributes['SEO_URLS_USE_W3C_VALID']){
691 case ('true'):
692 if (!isset($_SESSION['customer_id']) && defined('ENABLE_PAGE_CACHE') && ENABLE_PAGE_CACHE == 'true' && class_exists('page_cache')){
693 return $link;
694 } else {
695 return htmlspecialchars(utf8_encode($link));
696 }
697 break;
698 case ('false'):
699 return $link;
700 break;
701 }
702 } # end function
703/**
704 * Stock function, fallback use
705 */
706 function stock_href_link($page = '', $parameters = '', $connection = 'NONSSL', $add_session_id = true, $search_engine_safe = true) {
707 global $request_type, $session_started, $SID;
708 if (!$this->not_null($page)) {
709 die('</td></tr></table></td></tr></table><br><br><font color="#ff0000"><b>Error!</b></font><br><br><b>Unable to determine the page link!<br><br>');
710 }
711 if ($page == '/') $page = '';
712 if ($connection == 'NONSSL') {
713 $link = HTTP_SERVER . DIR_WS_HTTP_CATALOG;
714 } elseif ($connection == 'SSL') {
715 if (ENABLE_SSL == true) {
716 $link = HTTPS_SERVER . DIR_WS_HTTPS_CATALOG;
717 } else {
718 $link = HTTP_SERVER . DIR_WS_HTTP_CATALOG;
719 }
720 } else {
721 die('</td></tr></table></td></tr></table><br><br><font color="#ff0000"><b>Error!</b></font><br><br><b>Unable to determine connection method on a link!<br><br>Known methods: NONSSL SSL</b><br><br>');
722 }
723 if ($this->not_null($parameters)) {
724 $link .= $page . '?' . $this->output_string($parameters);
725 $separator = '&';
726 } else {
727 $link .= $page;
728 $separator = '?';
729 }
730 while ( (substr($link, -1) == '&') || (substr($link, -1) == '?') ) $link = substr($link, 0, -1);
731 if ( ($add_session_id == true) && ($session_started == true) && (SESSION_FORCE_COOKIE_USE == 'False') ) {
732 if ($this->not_null($SID)) {
733 $_sid = $SID;
734 } elseif ( ( ($request_type == 'NONSSL') && ($connection == 'SSL') && (ENABLE_SSL == true) ) || ( ($request_type == 'SSL') && ($connection == 'NONSSL') ) ) {
735 if (HTTP_COOKIE_DOMAIN != HTTPS_COOKIE_DOMAIN) {
736 $_sid = $this->SessionName() . '=' . $this->SessionID();
737 }
738 }
739 }
740 if ( (SEARCH_ENGINE_FRIENDLY_URLS == 'true') && ($search_engine_safe == true) ) {
741 while (strstr($link, '&&')) $link = str_replace('&&', '&', $link);
742 $link = str_replace('?', '/', $link);
743 $link = str_replace('&', '/', $link);
744 $link = str_replace('=', '/', $link);
745 $separator = '?';
746 }
747 switch(true){
748 case (!isset($_SESSION['customer_id']) && defined('ENABLE_PAGE_CACHE') && ENABLE_PAGE_CACHE == 'true' && class_exists('page_cache')):
749 $page_cache = true;
750 $return = $link . $separator . '<osCsid>';
751 break;
752 case (isset($_sid)):
753 $page_cache = false;
754 $return = $link . $separator . tep_output_string($_sid);
755 break;
756 default:
757 $page_cache = false;
758 $return = $link;
759 break;
760 } # end switch
761 $this->performance['NUMBER_STANDARD_URLS_GENERATED']++;
762 $this->cache['STANDARD_URLS'][] = $link;
763 $time = 0;
764 $this->stop($this->timestamp, $time);
765 $this->performance['TOTAL_TIME'] += $time;
766 switch(true){
767 case ($this->attributes['SEO_URLS_USE_W3C_VALID'] == 'true' && !$page_cache):
768 return htmlspecialchars(utf8_encode($return));
769 break;
770 default:
771 return $return;
772 break;
773 }# end swtich
774 } # end default tep_href function
775
776/**
777 * Function to append session ID if needed
778 * @author Bobby Easland
779 * @version 1.2
780 * @param string $link
781 * @param boolean $add_session_id
782 * @param string $connection
783 * @param string $separator
784 * @return string
785 */
786 function add_sid( $link, $add_session_id, $connection, $separator ){
787 global $request_type; // global variable
788 if ( ($add_session_id) && ($this->attributes['SESSION_STARTED']) && (SESSION_FORCE_COOKIE_USE == 'False') ) {
789 if ($this->not_null($this->attributes['SID'])) {
790 $_sid = $this->attributes['SID'];
791 } elseif ( ( ($request_type == 'NONSSL') && ($connection == 'SSL') && (ENABLE_SSL == true) ) || ( ($request_type == 'SSL') && ($connection == 'NONSSL') ) ) {
792 if (HTTP_COOKIE_DOMAIN != HTTPS_COOKIE_DOMAIN) {
793 $_sid = $this->SessionName() . '=' . $this->SessionID();
794 }
795 }
796 }
797 switch(true){
798 case (!isset($_SESSION['customer_id']) && defined('ENABLE_PAGE_CACHE') && ENABLE_PAGE_CACHE == 'true' && class_exists('page_cache')):
799 $return = $link . $separator . '<osCsid>';
800 break;
801 case ($this->not_null($_sid)):
802 $return = $link . $separator . tep_output_string($_sid);
803 break;
804 default:
805 $return = $link;
806 break;
807 } # end switch
808 return $return;
809 } # end function
810
811/**
812 * SFunction to parse the parameters into an SEO URL
813 * @author Bobby Easland
814 * @version 1.2
815 * @param string $page
816 * @param string $params
817 * @param string $separator NOTE: passed by reference
818 * @return string
819 */
820 function parse_parameters($page, $params, &$separator){
821 $p = @explode('&', $params);
822 krsort($p);
823 $container = array();
824 foreach ($p as $index => $valuepair){
825 $p2 = @explode('=', $valuepair);
826 switch ($p2[0]){
827 case 'products_id':
828
829 //BOF: Attribute Fix
830 if ($this->is_attribute_string(urldecode($p2[1]))){
831 $prodID = urldecode($p2[1]);
832 //Split the attributes from the product ID:
833 $prodAttr = substr( $prodID, strpos($prodID, "{"));
834 $prodID = substr( $prodID, 0, strpos($prodID, "{"));
835 $p2[1] = $prodID;
836 $container["options"] = $prodAttr;
837 }
838 //EOF: Attribute Fix
839
840 switch(true){
841 case ( $page == FILENAME_PRODUCT_INFO && !$this->is_attribute_string($p2[1]) ):
842 $url = $this->make_url($page, $this->get_product_name($p2[1]), $p2[0], $p2[1], '.html', $separator);
843 $this->ValidateName($url, "p", $p2[1], $connection, $separator);
844 break;
845 case ( $page == FILENAME_PRODUCT_REVIEWS ):
846 $url = $this->make_url($page, $this->get_product_name($p2[1]), 'products_id_review', $p2[1], '.html', $separator);
847 $this->ValidateName($url, "pr", $p2[1], $connection, $separator);
848 break;
849 case ( $page == FILENAME_PRODUCT_REVIEWS_INFO ):
850 $url = $this->make_url($page, $this->get_product_name($p2[1]), 'products_id_review_info', $p2[1], '.html', $separator);
851 $this->ValidateName($url, "pw", $p2[1], $connection, $separator);
852 break;
853 default:
854 $container[$p2[0]] = $p2[1];
855 break;
856 } # end switch
857 break;
858 case 'cPath':
859 switch(true){
860 case ($page == FILENAME_DEFAULT):
861 $url = $this->make_url($page, $this->get_category_name($p2[1]), $p2[0], $p2[1], '.html', $separator);
862 $this->ValidateName($url, "c", $p2[1], $connection, $separator);
863 break;
864 case ( !$this->is_product_string($params) ):
865 if ( $this->attributes['SEO_ADD_CPATH_TO_PRODUCT_URLS'] == 'true' ){
866 $container[$p2[0]] = $p2[1];
867 }
868 break;
869 default:
870 $container[$p2[0]] = $p2[1];
871 break;
872 } # end switch
873 break;
874 case 'manufacturers_id':
875 switch(true){
876 case ($page == FILENAME_DEFAULT && !$this->is_cPath_string($params) && !$this->is_product_string($params) ):
877 $url = $this->make_url($page, $this->get_manufacturer_name($p2[1]), $p2[0], $p2[1], '.html', $separator);
878 $this->ValidateName($url, "m", $p2[1], $connection, $separator);
879 break;
880 case ($page == FILENAME_PRODUCT_INFO):
881 break;
882 default:
883 $container[$p2[0]] = $p2[1];
884 break;
885 } # end switch
886 break;
887 case 'pID':
888 switch(true){
889 case ($page == FILENAME_POPUP_IMAGE):
890 $url = $this->make_url($page, $this->get_product_name($p2[1]), $p2[0], $p2[1], '.html', $separator);
891 $this->ValidateName($url, "pID", $p2[1], $connection, $separator);
892 break;
893 default:
894 $container[$p2[0]] = $p2[1];
895 break;
896 } # end switch
897 break;
898//////---------BOFauthors
899 case 'authors_id':
900 switch(true){
901 case ($page == FILENAME_ARTICLES):
902 $url = $this->make_url($page, $this->get_authors_name($p2[1]), $p2[0], $p2[1], '.html', $separator);
903 $this->ValidateName($url, "au", $p2[1], $connection, $separator);
904 break;
905 default:
906 $container[$p2[0]] = $p2[1];
907 break;
908 } # end switch
909 break;
910
911//////////--------EOF AUTHORS
912 case 'tPath':
913 switch(true){
914 case ($page == FILENAME_ARTICLES):
915 $url = $this->make_url($page, $this->get_topic_name($p2[1]), $p2[0], $p2[1], '.html', $separator);
916 $this->ValidateName($url, "t", $p2[1], $connection, $separator);
917 break;
918 default:
919 $container[$p2[0]] = $p2[1];
920 break;
921 } # end switch
922 break;
923//ojp lPath
924 case 'lPath':
925 switch(true){
926 case ($page == FILENAME_LINKS):
927 $url = $this->make_url($page, $this->get_link_name($p2[1]), $p2[0], $p2[1], '.html', $separator);
928 $this->ValidateName($url, "l", $p2[1], $connection, $separator);
929 break;
930 default:
931 $container[$p2[0]] = $p2[1];
932 break;
933 } # end switch
934 break;
935
936 case 'articles_id':
937 switch(true){
938 case ($page == FILENAME_ARTICLE_INFO):
939 $url = $this->make_url($page, $this->get_article_name($p2[1]), $p2[0], $p2[1], '.html', $separator);
940 $this->ValidateName($url, "a", $p2[1], $connection, $separator);
941 break;
942 default:
943 $container[$p2[0]] = $p2[1];
944 break;
945 } # end switch
946 break;
947 case 'info_id':
948 switch(true){
949 case ($page == FILENAME_INFORMATION):
950 $url = $this->make_url($page, $this->get_information_name($p2[1]), $p2[0], $p2[1], '.html', $separator);
951 $this->ValidateName($url, "i", $p2[1], $connection, $separator);
952 break;
953 default:
954 $container[$p2[0]] = $p2[1];
955 break;
956 } # end switch
957 break;
958
959 // BOF: Faqdesk support added by faaliyet
960 case 'faqdesk_id':
961 switch(true){
962 case ($page == FILENAME_FAQDESK_INFO):
963 $url = $this->make_url($page, $this->get_faqdesk_name($p2[1]), $p2[0], $p2[1], '.html', $separator);
964 break;
965 case ($page == FILENAME_FAQDESK_REVIEWS_INFO):
966 $url = $this->make_url($page, $this->get_faqdesk_name($p2[1]), 'faqdesk_reviews_id', $p2[1], '.html', $separator);
967 break;
968 case ($page == FILENAME_FAQDESK_REVIEWS_ARTICLE):
969 $url = $this->make_url($page, $this->get_faqdesk_name($p2[1]), 'faqdesk_article_id', $p2[1], '.html', $separator);
970 break;
971 default:
972 $container[$p2[0]] = $p2[1];
973 break;
974 } # end switch
975 break;
976 case 'faqPath':
977 switch(true){
978 case ($page == FILENAME_FAQDESK_INDEX):
979 $url = $this->make_url($page, $this->get_faqdesk_categories_name($p2[1]), $p2[0], $p2[1], '.html', $separator);
980 break;
981 default:
982 $container[$p2[0]] = $p2[1];
983 break;
984 } # end switch
985 break;
986 // EOF: Faqdesk support added by faaliyet
987 // BOF: "Extra pages-info box w/ admin" support added by faaliyet
988 case 'pages_id':
989 switch(true){
990 case ($page == FILENAME_PAGES):
991 $url = $this->make_url($page, $this->get_pages_name($p2[1]), $p2[0], $p2[1], '.html', $separator);
992 break;
993 default:
994 $container[$p2[0]] = $p2[1];
995 break;
996 } # end switch
997 break;
998 // EOF: "Extra pages-info box w/ admin" support added by faaliyet
999/*
1000case 'pollid':
1001 switch(true){
1002 case ($page == 'pollbooth.php'):
1003 $url = $this->make_url($page, $this->get_polls_name($p2[1]), $p2[0], $p2[1], '.html', $separator);
1004 break;
1005 default:
1006 $container[$p2[0]] = $p2[1];
1007 break;
1008 } # end switch
1009 break;
1010*/
1011 case 'newsdesk_id':
1012 switch(true){
1013 case ($page == FILENAME_NEWSDESK_INFO):
1014 $url = $this->make_url($page, $this->get_newsdesk_name($p2[1]), $p2[0], $p2[1], '.html', $separator);
1015 break;
1016 case ($page == FILENAME_NEWSDESK_REVIEWS_INFO):
1017 $url = $this->make_url($page, $this->get_newsdesk_name($p2[1]), 'newsdesk_reviews_id', $p2[1], '.html', $separator);
1018 break;
1019 case ($page == FILENAME_NEWSDESK_REVIEWS_ARTICLE):
1020 $url = $this->make_url($page, $this->get_newsdesk_name($p2[1]), 'newsdesk_article_id', $p2[1], '.html', $separator);
1021 break;
1022 default:
1023 $container[$p2[0]] = $p2[1];
1024 break;
1025 } # end switch
1026 break;
1027 case 'newsPath':
1028 switch(true){
1029 case ($page == FILENAME_NEWSDESK_INDEX):
1030 $url = $this->make_url($page, $this->get_newsdesk_categories_name($p2[1]), $p2[0], $p2[1], '.html', $separator);
1031 break;
1032 default:
1033 $container[$p2[0]] = $p2[1];
1034 break;
1035 } # end switch
1036 break;
1037 default:
1038 $container[$p2[0]] = $p2[1];
1039 break;
1040 } # end switch
1041 } # end foreach $p
1042 $url = isset($url) ? $url : $page;
1043 if ( sizeof($container) > 0 ){
1044 if ( $imploded_params = $this->implode_assoc($container) ){
1045 $url .= $separator . $this->output_string( $imploded_params );
1046 $separator = '&';
1047 }
1048 }
1049 return $url;
1050 } # end function
1051
1052/**
1053 * Function to return the generated SEO URL
1054 * @author Bobby Easland
1055 * @version 1.0
1056 * @param string $page
1057 * @param string $string Stripped, formed anchor
1058 * @param string $anchor_type Parameter type (products_id, cPath, etc.)
1059 * @param integer $id
1060 * @param string $extension Default = .html
1061 * @param string $separator NOTE: passed by reference
1062 * @return string
1063 */
1064 function make_url($page, $string, $anchor_type, $id, $extension = '.html', &$separator){
1065 // Right now there is but one rewrite method since cName was dropped
1066 // In the future there will be additional methods here in the switch
1067 switch ( $this->attributes['SEO_REWRITE_TYPE'] ){
1068 case 'Rewrite':
1069 return $string . $this->reg_anchors[$anchor_type] . $id . $extension;
1070 break;
1071 default:
1072 break;
1073 } # end switch
1074 } # end function
1075
1076/**
1077 * Function to get the product name. Use evaluated cache, per page cache, or database query in that order of precedent
1078 * @author Bobby Easland
1079 * @version 1.1
1080 * @param integer $pID
1081 * @return string Stripped anchor text
1082 */
1083 function get_product_name($pID){
1084 switch(true){
1085 case ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true' && defined('PRODUCT_NAME_' . $pID)):
1086 $this->performance['CACHE_QUERY_SAVINGS']++;
1087 $return = constant('PRODUCT_NAME_' . $pID);
1088 $this->cache['PRODUCTS'][$pID] = $return;
1089 break;
1090 case ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true' && isset($this->cache['PRODUCTS'][$pID])):
1091 $this->performance['CACHE_QUERY_SAVINGS']++;
1092 $return = $this->cache['PRODUCTS'][$pID];
1093 break;
1094 default:
1095 $this->performance['NUMBER_QUERIES']++;
1096 $sql = "SELECT products_name as pName
1097 FROM ".TABLE_PRODUCTS_DESCRIPTION."
1098 WHERE products_id='".(int)$pID."'
1099 AND language_id='".(int)$this->languages_id."'
1100 LIMIT 1";
1101 $result = $this->DB->FetchArray( $this->DB->Query( $sql ) );
1102 $pName = $this->strip( $result['pName'] );
1103 $this->cache['PRODUCTS'][$pID] = $pName;
1104 $this->performance['QUERIES']['PRODUCTS'][] = $sql;
1105 $return = $pName;
1106 break;
1107 } # end switch
1108 return $return;
1109 } # end function
1110
1111/**
1112 * Function to get the category name. Use evaluated cache, per page cache, or database query in that order of precedent
1113 * @author Bobby Easland
1114 * @version 1.1
1115 * @param integer $cID NOTE: passed by reference
1116 * @return string Stripped anchor text
1117 */
1118 function get_category_name(&$cID){
1119 $full_cPath = $this->get_full_cPath($cID, $single_cID); // full cPath needed for uniformity
1120 switch(true){
1121 case ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true' && defined('CATEGORY_NAME_' . $full_cPath)):
1122 $this->performance['CACHE_QUERY_SAVINGS']++;
1123 $return = constant('CATEGORY_NAME_' . $full_cPath);
1124 $this->cache['CATEGORIES'][$full_cPath] = $return;
1125 break;
1126 case ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true' && isset($this->cache['CATEGORIES'][$full_cPath])):
1127 $this->performance['CACHE_QUERY_SAVINGS']++;
1128 $return = $this->cache['CATEGORIES'][$full_cPath];
1129 break;
1130 default:
1131 $this->performance['NUMBER_QUERIES']++;
1132 switch(true){
1133 case ($this->attributes['SEO_ADD_CAT_PARENT'] == 'true'):
1134 $sql = "SELECT c.categories_id, c.parent_id, cd.categories_name as cName, cd2.categories_name as pName
1135 FROM ".TABLE_CATEGORIES." c
1136 JOIN ".TABLE_CATEGORIES_DESCRIPTION." cd
1137 ON c.categories_id = cd.categories_id
1138 LEFT JOIN ".TABLE_CATEGORIES_DESCRIPTION." cd2
1139 ON c.parent_id=cd2.categories_id AND cd2.language_id='".(int)$this->languages_id."'
1140 WHERE c.categories_id='".(int)$single_cID."'
1141 AND cd.categories_id='".(int)$single_cID."'
1142 AND cd.language_id='".(int)$this->languages_id."'
1143 LIMIT 1";
1144 $result = $this->DB->FetchArray( $this->DB->Query( $sql ) );
1145 $cName = $this->not_null($result['pName']) ? $result['pName'] . ' ' . $result['cName'] : $result['cName'];
1146 break;
1147 default:
1148 $sql = "SELECT categories_name as cName
1149 FROM ".TABLE_CATEGORIES_DESCRIPTION."
1150 WHERE categories_id='".(int)$single_cID."'
1151 AND language_id='".(int)$this->languages_id."'
1152 LIMIT 1";
1153 $result = $this->DB->FetchArray( $this->DB->Query( $sql ) );
1154 $cName = $result['cName'];
1155 break;
1156 }
1157 $cName = $this->strip($cName);
1158 $this->cache['CATEGORIES'][$full_cPath] = $cName;
1159 $this->performance['QUERIES']['CATEGORIES'][] = $sql;
1160 $return = $cName;
1161 break;
1162 } # end switch
1163 $cID = $full_cPath;
1164 return $return;
1165 } # end function
1166
1167 function Validatename($url, $type, $realID, $connection, $separator)
1168 {
1169 $origUrl = strip_tags($this->requested_page()); //get the actual page requested
1170 $parts = explode("-", $origUrl);
1171
1172 if ($parts[count($parts) - 2] == $type) //make sure it is the correct type for this link
1173 {
1174 if (($pos = strpos($parts[count($parts) - 1], ".html")) !== FALSE)
1175 $id = substr($parts[count($parts) - 1], 0, $pos); //strip .html
1176
1177 $catalog = DIR_WS_HTTP_CATALOG;
1178 if ($catalog[0] == '/')
1179 $catalog = substr(DIR_WS_HTTP_CATALOG, 1); //strip leading slash if present
1180
1181 if (strpos($origUrl, $catalog) !== FALSE)
1182 $origUrl = substr($origUrl, strlen($catalog)); //remove the catalog from the url string
1183
1184 if (!empty($origUrl) && $id === $realID && $origUrl !== $url) //ID's match but not the text
1185 {
1186 $url = $this->base_url . $url;
1187 $link = $this->add_sid($url, true, $connection, $separator); //build the correct link with SID
1188 //header("HTTP/1.0 301 Moved Permanently"); //let the SE's know to not use this link
1189 //header("Location: $link"); //redirect to the real page
1190 }
1191 }
1192 }
1193
1194 function requested_page()
1195 {
1196 $protocol = ((int) $_SERVER['SERVER_PORT'] === 443)? 'https://' : 'http://';
1197 $current_page = $protocol . $_SERVER['HTTP_HOST'] . ((!empty($_SERVER['REQUEST_URI']))? $_SERVER['REQUEST_URI'] : '');
1198 $current_page = substr($current_page, strlen(HTTP_SERVER));
1199 if (($pos = strpos($current_page, "?osCsid")) !== FALSE)
1200 $current_page = substr($current_page, 0, $pos).'<br>';
1201 if ($current_page[0] == "/")
1202 $current_page = substr($current_page, 1);
1203
1204 return $current_page;
1205 }
1206
1207/**
1208 * Function to get the manufacturer name. Use evaluated cache, per page cache, or database query in that order of precedent.
1209 * @author Bobby Easland
1210 * @version 1.1
1211 * @param integer $mID
1212 * @return string
1213 */
1214 function get_manufacturer_name($mID){
1215 switch(true){
1216 case ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true' && defined('MANUFACTURER_NAME_' . $mID)):
1217 $this->performance['CACHE_QUERY_SAVINGS']++;
1218 $return = constant('MANUFACTURER_NAME_' . $mID);
1219 $this->cache['MANUFACTURERS'][$mID] = $return;
1220 break;
1221 case ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true' && isset($this->cache['MANUFACTURERS'][$mID])):
1222 $this->performance['CACHE_QUERY_SAVINGS']++;
1223 $return = $this->cache['MANUFACTURERS'][$mID];
1224 break;
1225 default:
1226 $this->performance['NUMBER_QUERIES']++;
1227 $sql = "SELECT manufacturers_name as mName
1228 FROM ".TABLE_MANUFACTURERS."
1229 WHERE manufacturers_id='".(int)$mID."'
1230 LIMIT 1";
1231 $result = $this->DB->FetchArray( $this->DB->Query( $sql ) );
1232 $mName = $this->strip( $result['mName'] );
1233 $this->cache['MANUFACTURERS'][$mID] = $mName;
1234 $this->performance['QUERIES']['MANUFACTURERS'][] = $sql;
1235 $return = $mName;
1236 break;
1237 } # end switch
1238 return $return;
1239 } # end function
1240
1241/**
1242 * Function to get the article name. Use evaluated cache, per page cache, or database query in that order of precedent.
1243 * @author Bobby Easland
1244 * @version 1.0
1245 * @param integer $aID
1246 * @return string
1247 */
1248 function get_article_name($aID){
1249 switch(true){
1250 case ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true' && defined('ARTICLE_NAME_' . $aID)):
1251 $this->performance['CACHE_QUERY_SAVINGS']++;
1252 $return = constant('ARTICLE_NAME_' . $aID);
1253 $this->cache['ARTICLES'][$aID] = $return;
1254 break;
1255 case ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true' && isset($this->cache['ARTICLES'][$aID])):
1256 $this->performance['CACHE_QUERY_SAVINGS']++;
1257 $return = $this->cache['ARTICLES'][$aID];
1258 break;
1259 default:
1260 $this->performance['NUMBER_QUERIES']++;
1261 $sql = "SELECT articles_name as aName
1262 FROM ".TABLE_ARTICLES_DESCRIPTION."
1263 WHERE articles_id='".(int)$aID."'
1264 AND language_id='".(int)$this->languages_id."'
1265 LIMIT 1";
1266 $result = $this->DB->FetchArray( $this->DB->Query( $sql ) );
1267 $aName = $this->strip( $result['aName'] );
1268 $this->cache['ARTICLES'][$aID] = $aName;
1269 $this->performance['QUERIES']['ARTICLES'][] = $sql;
1270 $return = $aName;
1271 break;
1272 } # end switch
1273 return $return;
1274 } # end function
1275
1276/**
1277 * Function to get the authors name. Use evaluated cache, per page cache, or database query in that order of precedent.
1278 * @author Bobby Easland
1279 * @version 1.0
1280 * @param integer $aID
1281 * @return string
1282 */
1283 function get_authors_name($auID){
1284 switch(true){
1285 case ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true' && defined('AUTHORS_NAME_' . $auID)):
1286 $this->performance['CACHE_QUERY_SAVINGS']++;
1287 $return = constant('AUTHORS_NAME_' . $auID);
1288 $this->cache['AUTHORS'][$auID] = $return;
1289 break;
1290 case ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true' && isset($this->cache['AUTHORS'][$auID])):
1291 $this->performance['CACHE_QUERY_SAVINGS']++;
1292 $return = $this->cache['AUTHORS'][$auID];
1293 break;
1294 default:
1295 $this->performance['NUMBER_QUERIES']++;
1296 $sql = "SELECT authors_name as auName
1297 FROM ".TABLE_AUTHORS."
1298 WHERE authors_id='".(int)$auID."'
1299
1300 LIMIT 1";
1301 $result = $this->DB->FetchArray( $this->DB->Query( $sql ) );
1302 $auName = $this->strip( $result['auName'] );
1303 $this->cache['AUTHORS'][$auID] = $auName;
1304 $this->performance['QUERIES']['AUTHORS'][] = $sql;
1305 $return = $auName;
1306 break;
1307 } # end switch
1308 return $return;
1309 } # end function
1310
1311/**
1312 * Function to get the topic name. Use evaluated cache, per page cache, or database query in that order of precedent.
1313 * @author Bobby Easland
1314 * @version 1.1
1315 * @param integer $tID
1316 * @return string
1317 */
1318 function get_topic_name($tID){
1319 switch(true){
1320 case ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true' && defined('TOPIC_NAME_' . $tID)):
1321 $this->performance['CACHE_QUERY_SAVINGS']++;
1322 $return = constant('TOPIC_NAME_' . $tID);
1323 $this->cache['TOPICS'][$tID] = $return;
1324 break;
1325 case ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true' && isset($this->cache['TOPICS'][$tID])):
1326 $this->performance['CACHE_QUERY_SAVINGS']++;
1327 $return = $this->cache['TOPICS'][$tID];
1328 break;
1329 default:
1330 $this->performance['NUMBER_QUERIES']++;
1331 $sql = "SELECT topics_name as tName
1332 FROM ".TABLE_TOPICS_DESCRIPTION."
1333 WHERE topics_id='".(int)$tID."'
1334 AND language_id='".(int)$this->languages_id."'
1335 LIMIT 1";
1336 $result = $this->DB->FetchArray( $this->DB->Query( $sql ) );
1337 $tName = $this->strip( $result['tName'] );
1338 $this->cache['ARTICLES'][$aID] = $tName;
1339 $this->performance['QUERIES']['TOPICS'][] = $sql;
1340 $return = $tName;
1341 break;
1342 } # end switch
1343 return $return;
1344 } # end function
1345
1346/** ojp
1347 * Function to get the link category file name. Use evaluated cache, per page cache, or database query in that order of precedent.
1348 * @author Oliver Passe
1349 * @version 1.0
1350 * @param integer $lPath
1351 * @return string
1352 */
1353 function get_link_name($lPath){
1354 switch(true){
1355 case ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true' && defined('LINK_NAME_' . $lPath)):
1356 $this->performance['CACHE_QUERY_SAVINGS']++;
1357 $return = constant('LINK_NAME_' . $lPath);
1358 $this->cache['LINKS'][$lPath] = $return;
1359 break;
1360 case ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true' && isset($this->cache['LINKS'][$lPath])):
1361 $this->performance['CACHE_QUERY_SAVINGS']++;
1362 $return = $this->cache['LINKS'][$lPath];
1363 break;
1364 default:
1365 $this->performance['NUMBER_QUERIES']++;
1366 $sql = "SELECT link_categories_name as lName
1367 FROM ".TABLE_LINK_CATEGORIES_DESCRIPTION."
1368 WHERE link_categories_id='".(int)$lPath."'
1369 AND language_id='".(int)$this->languages_id."'
1370 LIMIT 1";
1371 $result = $this->DB->FetchArray( $this->DB->Query( $sql ) );
1372 $lName = $this->strip( $result['lName'] );
1373 $this->cache['ARTICLES'][$aID] = $lName;
1374 $this->performance['QUERIES']['TOPICS'][] = $sql;
1375 $return = $lName;
1376 break;
1377 } # end switch
1378 return $return;
1379 } # end function
1380
1381/**
1382 * Function to get the informatin name. Use evaluated cache, per page cache, or database query in that order of precedent.
1383 * @author Bobby Easland
1384 * @version 1.1
1385 * @param integer $iID
1386 * @return string
1387 */
1388 function get_information_name($iID){
1389 switch(true){
1390 case ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true' && defined('INFO_NAME_' . $iID)):
1391 $this->performance['CACHE_QUERY_SAVINGS']++;
1392 $return = constant('INFO_NAME_' . $iID);
1393 $this->cache['INFO'][$iID] = $return;
1394 break;
1395 case ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true' && isset($this->cache['INFO'][$iID])):
1396 $this->performance['CACHE_QUERY_SAVINGS']++;
1397 $return = $this->cache['INFO'][$iID];
1398 break;
1399 default:
1400 $this->performance['NUMBER_QUERIES']++;
1401 $sql = "SELECT information_title as iName
1402 FROM ".TABLE_INFORMATION."
1403 WHERE information_id='".(int)$iID."'
1404 AND language_id='".(int)$this->languages_id."'
1405 LIMIT 1";
1406 $result = $this->DB->FetchArray( $this->DB->Query( $sql ) );
1407 $iName = $this->strip( $result['iName'] );
1408 $this->cache['INFO'][$iID] = $iName;
1409 $this->performance['QUERIES']['INFO'][] = $sql;
1410 $return = $iName;
1411 break;
1412 } # end switch
1413 return $return;
1414 } # end function
1415
1416/**
1417 * Function to get the faqdesk name. Use evaluated cache, per page cache, or database query in that order of precedent.
1418 * @author faaliyet
1419 * @version 2.4.1
1420 * @param integer $fID
1421 * @return string
1422 */
1423
1424 function get_faqdesk_name($fID){
1425 switch(true){
1426 case ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true' && defined('FAQDESK_NAME_' . $fID)):
1427 $this->performance['CACHE_QUERY_SAVINGS']++;
1428 $return = constant('FAQDESK_NAME_' . $fID);
1429 $this->cache['FAQDESK'][$fID] = $return;
1430 break;
1431 case ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true' && isset($this->cache['FAQDESK'][$fID])):
1432 $this->performance['CACHE_QUERY_SAVINGS']++;
1433 $return = $this->cache['FAQDESK'][$fID];
1434 break;
1435 default:
1436 $this->performance['NUMBER_QUERIES']++;
1437 $sql = "SELECT faqdesk_question as fName
1438 FROM " . TABLE_FAQDESK_DESCRIPTION . "
1439 WHERE faqdesk_id='".(int)$fID."'
1440 AND language_id='".(int)$this->languages_id."'
1441 LIMIT 1 ";
1442 $result = $this->DB->FetchArray( $this->DB->Query( $sql ) );
1443 $fName = $this->strip( $result['fName'] );
1444 $this->cache['FAQDESK'][$fID] = $fName;
1445 $this->performance['QUERIES']['FAQDESK'][] = $sql;
1446 $return = $fName;
1447 break;
1448
1449 } # end switch
1450 return $return;
1451 } # end function
1452
1453/**
1454 * Function to get the faqdesk name. Use evaluated cache, per page cache, or database query in that order of precedent.
1455 * @author faaliyet
1456 * @version 2.4.1
1457 * @param integer $fID
1458 * @return string
1459 */
1460
1461 function get_faqdesk_categories_name($fcID){
1462 switch(true){
1463 case ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true' && defined('FAQDESK_CATEGORIES_NAME_' . $fcID)):
1464 $this->performance['CACHE_QUERY_SAVINGS']++;
1465 $return = constant('FAQDESK_CATEGORIES_NAME_' . $fcID);
1466 $this->cache['FAQDESK_CATEGORIES'][$fcID] = $return;
1467 break;
1468 case ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true' && isset($this->cache['FAQDESK_CATEGORIES'][$fcID])):
1469 $this->performance['CACHE_QUERY_SAVINGS']++;
1470 $return = $this->cache['FAQDESK_CATEGORIES'][$fcID];
1471 break;
1472 default:
1473 $this->performance['NUMBER_QUERIES']++;
1474 $sql = "SELECT categories_name as fcName
1475 FROM " . TABLE_FAQDESK_CATEGORIES_DESCRIPTION . "
1476 WHERE categories_id='".(int)$fcID."'
1477 AND language_id='".(int)$this->languages_id."'
1478 LIMIT 1 ";
1479 $result = $this->DB->FetchArray( $this->DB->Query( $sql ) );
1480 $fcName = $this->strip( $result['fcName'] );
1481 $this->cache['FAQDESK_CATEGORIES'][$fcID] = $fcName;
1482 $this->performance['QUERIES']['FAQDESK_CATEGORIES'][] = $sql;
1483 $return = $fcName;
1484 break;
1485
1486 } # end switch
1487 return $return;
1488 } # end function
1489
1490/**
1491 * Function to get the informatin name. Use evaluated cache, per page cache, or database query in that order of precedent.
1492 * @author faaliyet
1493 * @version 2.5
1494 * @param integer $iID
1495 * @return string
1496 */
1497 function get_pages_name($pmID){
1498 switch(true){
1499 case ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true' && defined('PAGES_TITLE' . $pmID)):
1500 $this->performance['CACHE_QUERY_SAVINGS']++;
1501 $return = constant('PAGES_TITLE_' . $pmID);
1502 $this->cache['PAGES'][$pmID] = $return;
1503 break;
1504 case ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true' && isset($this->cache['PAGES'][$pmID])):
1505 $this->performance['CACHE_QUERY_SAVINGS']++;
1506 $return = $this->cache['PAGES'][$pmID];
1507 break;
1508 default:
1509 $this->performance['NUMBER_QUERIES']++;
1510 $sql = "SELECT pages_title as pmName
1511 FROM ".TABLE_PAGES_DESCRIPTION."
1512 WHERE pages_id='".(int)$pmID."'
1513 AND language_id='".(int)$this->languages_id."'
1514 LIMIT 1";
1515 $result = $this->DB->FetchArray( $this->DB->Query( $sql ) );
1516 $pmName = $this->strip( $result['pmName'] );
1517 $this->cache['PAGES'][$pmID] = $pmName;
1518 $this->performance['QUERIES']['PAGES'][] = $sql;
1519 $return = $pmName;
1520 break;
1521 } # end switch
1522 return $return;
1523 } # end function
1524
1525/**
1526 * Function to generate information cache entries
1527 * @author faaliyet
1528 * @version 2.5
1529 */
1530 function generate_pages_cache(){
1531 $this->is_cached($this->cache_file . 'pages', $is_cached, $is_expired);
1532 if ( !$is_cached || $is_expired ) { // it's not cached so create it
1533 $sql = "SELECT pages_id as id, pages_title as name
1534 FROM ".TABLE_PAGES_DESCRIPTION."
1535 WHERE language_id='".(int)$this->languages_id."'";
1536 $pages_query = $this->DB->Query( $sql );
1537 $pages_cache = '';
1538 while ($pages = $this->DB->FetchArray($pages_query)) {
1539 $define = 'define(\'PAGES_NAME_' . $pages['id'] . '\', \'' . $this->strip($pages['name']) . '\');';
1540 $pages_cache .= $define . "\n";
1541 eval("$define");
1542 }
1543 $this->DB->Free($pages_query);
1544 $this->save_cache($this->cache_file . 'pages', $pages_cache, 'EVAL', 1 , 1);
1545 unset($pages_cache);
1546 } else {
1547 $this->get_cache($this->cache_file . 'pages');
1548 }
1549 } # end function
1550
1551
1552/**
1553
1554 * Function to get the polls name. Use evaluated cache, per page cache, or database query in that order of precedent.
1555 * @author Antonello Venturino
1556 * @version 1.1
1557 * @param integer $poID
1558 * @return string
1559
1560 function get_polls_name($poID){
1561 switch(true){
1562 case ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true' && defined('POLLS_NAME_' . $poID)):
1563 $this->performance['CACHE_QUERY_SAVINGS']++;
1564 $return = constant('POLLS_NAME_' . $poID);
1565 $this->cache['POLLS'][$poID] = $return;
1566 break;
1567 case ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true' && isset($this->cache['POLLS'][$poID])):
1568 $this->performance['CACHE_QUERY_SAVINGS']++;
1569 $return = $this->cache['POLLS'][$poID];
1570 break;
1571 default:
1572 $this->performance['NUMBER_QUERIES']++;
1573 $sql = "SELECT optiontext as poName
1574 FROM " . TABLE_PHESIS_POLL_DATA . "
1575 WHERE pollid='".(int)$poID."'
1576 AND language_id='".(int)$this->languages_id."'
1577 LIMIT 1";
1578 $result = $this->DB->FetchArray( $this->DB->Query( $sql ) );
1579 $poName = $this->strip( $result['poName'] );
1580 $this->cache['POLLS'][$poID] = $poName;
1581 $this->performance['QUERIES']['POLLS'][] = $sql;
1582 $return = $poName;
1583 break;
1584
1585 } # end switch
1586 return $return;
1587 } # end function
1588*/
1589
1590/**
1591 * Function to get the newsdesk name. Use evaluated cache, per page cache, or database query in that order of precedent.
1592 * @author Antonello Venturino
1593 * @version 1.1
1594 * @param integer $nID
1595 * @return string
1596 */
1597 function get_newsdesk_name($nID){
1598 switch(true){
1599 case ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true' && defined('NEWSDESK_NAME_' . $nID)):
1600 $this->performance['CACHE_QUERY_SAVINGS']++;
1601 $return = constant('NEWSDESK_NAME_' . $nID);
1602 $this->cache['NEWSDESK'][$nID] = $return;
1603 break;
1604 case ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true' && isset($this->cache['NEWSDESK'][$nID])):
1605 $this->performance['CACHE_QUERY_SAVINGS']++;
1606 $return = $this->cache['NEWSDESK'][$nID];
1607 break;
1608 default:
1609 $this->performance['NUMBER_QUERIES']++;
1610 $sql = "SELECT newsdesk_article_name as nName
1611 FROM " . TABLE_NEWSDESK_DESCRIPTION . "
1612 WHERE newsdesk_id='".(int)$nID."'
1613 AND language_id='".(int)$this->languages_id."'
1614 LIMIT 1 ";
1615 $result = $this->DB->FetchArray( $this->DB->Query( $sql ) );
1616 $nName = $this->strip( $result['nName'] );
1617 $this->cache['NEWSDESK'][$nID] = $nName;
1618 $this->performance['QUERIES']['NEWSDESK'][] = $sql;
1619 $return = $nName;
1620 break;
1621 } # end switch
1622 return $return;
1623 } # end function
1624
1625/**
1626 * Function to get the newsdesk name. Use evaluated cache, per page cache, or database query in that order of precedent.
1627 * @author Antonello Venturino
1628 * @version 1.1
1629 * @param integer $ncID
1630 * @return string
1631 */
1632 function get_newsdesk_categories_name($ncID){
1633 switch(true){
1634 case ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true' && defined('NEWSDESK_CATEGORIES_NAME_' . $ncID)):
1635 $this->performance['CACHE_QUERY_SAVINGS']++;
1636 $return = constant('NEWSDESK_CATEGORIES_NAME_' . $ncID);
1637 $this->cache['NEWSDESK_CATEGORIES'][$ncID] = $return;
1638 break;
1639 case ($this->attributes['USE_SEO_CACHE_GLOBAL'] == 'true' && isset($this->cache['NEWSDESK_CATEGORIES'][$ncID])):
1640 $this->performance['CACHE_QUERY_SAVINGS']++;
1641 $return = $this->cache['NEWSDESK_CATEGORIES'][$ncID];
1642 break;
1643 default:
1644 $this->performance['NUMBER_QUERIES']++;
1645 $sql = "SELECT categories_name as ncName
1646 FROM " . TABLE_NEWSDESK_CATEGORIES_DESCRIPTION . "
1647 WHERE categories_id='".(int)$ncID."'
1648 AND language_id='".(int)$this->languages_id."'
1649 LIMIT 1 ";
1650 $result = $this->DB->FetchArray( $this->DB->Query( $sql ) );
1651 $ncName = $this->strip( $result['ncName'] );
1652 $this->cache['NEWSDESK_CATEGORIES'][$ncID] = $ncName;
1653 $this->performance['QUERIES']['NEWSDESK_CATEGORIES'][] = $sql;
1654 $return = $ncName;
1655 break;
1656
1657 } # end switch
1658 return $return;
1659 } # end function
1660
1661/**
1662 * Function to retrieve full cPath from category ID
1663 * @author Bobby Easland
1664 * @version 1.1
1665 * @param mixed $cID Could contain cPath or single category_id
1666 * @param integer $original Single category_id passed back by reference
1667 * @return string Full cPath string
1668 */
1669 function get_full_cPath($cID, &$original){
1670 if ( is_numeric(strpos($cID, '_')) ){
1671 $temp = @explode('_', $cID);
1672 $original = $temp[sizeof($temp)-1];
1673 return $cID;
1674 } else {
1675 $c = array();
1676 $this->GetParentCategories($c, $cID);
1677 $c = array_reverse($c);
1678 $c[] = $cID;
1679 $original = $cID;
1680 $cID = sizeof($c) > 1 ? implode('_', $c) : $cID;
1681 return $cID;
1682 }
1683 } # end function
1684
1685/**
1686 * Recursion function to retrieve parent categories from category ID
1687 * @author Bobby Easland
1688 * @version 1.0
1689 * @param mixed $categories Passed by reference
1690 * @param integer $categories_id
1691 */
1692 function GetParentCategories(&$categories, $categories_id) {
1693 $sql = "SELECT parent_id
1694 FROM " . TABLE_CATEGORIES . "
1695 WHERE categories_id='" . (int)$categories_id . "'";
1696 $parent_categories_query = $this->DB->Query($sql);
1697 while ($parent_categories = $this->DB->FetchArray($parent_categories_query)) {
1698 if ($parent_categories['parent_id'] == 0) return true;
1699 $categories[sizeof($categories)] = $parent_categories['parent_id'];
1700 if ($parent_categories['parent_id'] != $categories_id) {
1701 $this->GetParentCategories($categories, $parent_categories['parent_id']);
1702 }
1703 }
1704 } # end function
1705
1706/**
1707 * Function to check if a value is NULL
1708 * @author Bobby Easland as abstracted from osCommerce-MS2.2
1709 * @version 1.0
1710 * @param mixed $value
1711 * @return boolean
1712 */
1713 function not_null($value) {
1714 if (is_array($value)) {
1715 if (sizeof($value) > 0) {
1716 return true;
1717 } else {
1718 return false;
1719 }
1720 } else {
1721 if (($value != '') && (strtolower($value) != 'null') && (strlen(trim($value)) > 0)) {
1722 return true;
1723 } else {
1724 return false;
1725 }
1726 }
1727 } # end function
1728
1729/**
1730 * Function to check if the products_id contains an attribute
1731 * @author Bobby Easland
1732 * @version 1.1
1733 * @param integer $pID
1734 * @return boolean
1735 */
1736 function is_attribute_string($pID){
1737 if ( is_numeric(strpos($pID, '{')) ){
1738 return true;
1739 } else {
1740 return false;
1741 }
1742 } # end function
1743
1744/**
1745 * Function to check if the params contains a products_id
1746 * @author Bobby Easland
1747 * @version 1.1
1748 * @param string $params
1749 * @return boolean
1750 */
1751 function is_product_string($params){
1752 if ( is_numeric(strpos('products_id', $params)) ){
1753 return true;
1754 } else {
1755 return false;
1756 }
1757 } # end function
1758
1759/**
1760 * Function to check if cPath is in the parameter string
1761 * @author Bobby Easland
1762 * @version 1.0
1763 * @param string $params
1764 * @return boolean
1765 */
1766 function is_cPath_string($params){
1767 if ( eregi('cPath', $params) ){
1768 return true;
1769 } else {
1770 return false;
1771 }
1772 } # end function
1773
1774/**
1775 * Function used to output class profile
1776 * @author Bobby Easland
1777 * @version 1.0
1778 */
1779 function profile(){
1780 $this->calculate_performance();
1781 $this->PrintArray($this->attributes, 'Class Attributes');
1782 $this->PrintArray($this->cache, 'Cached Data');
1783 } # end function
1784
1785/**
1786 * Function used to calculate and output the performance metrics of the class
1787 * @author Bobby Easland
1788 * @version 1.0
1789 * @return mixed Output of performance data wrapped in HTML pre tags
1790 */
1791 function calculate_performance(){
1792 foreach ($this->cache as $type){
1793 $this->performance['TOTAL_CACHED_PER_PAGE_RECORDS'] += sizeof($type);
1794 }
1795 $this->performance['TIME_PER_URL'] = $this->performance['TOTAL_TIME'] / $this->performance['NUMBER_URLS_GENERATED'];
1796 return $this->PrintArray($this->performance, 'Performance Data');
1797 } # end function
1798
1799/**
1800 * Function to strip the string of punctuation and white space
1801 * @author Bobby Easland
1802 * @version 1.1
1803 * @param string $string
1804 * @return string Stripped text. Removes all non-alphanumeric characters.
1805 */
1806 function strip($string){
1807 if ( is_array($this->attributes['SEO_CHAR_CONVERT_SET']) ) $string = strtr($string, $this->attributes['SEO_CHAR_CONVERT_SET']);
1808 $pattern = $this->attributes['SEO_REMOVE_ALL_SPEC_CHARS'] == 'true'
1809 ? "([^[:alnum:]])+"
1810 : "([[:punct:]])+";
1811 $anchor = ereg_replace($pattern, '', mb_convert_case($string, MB_CASE_LOWER, "utf-8"));
1812 $pattern = "([[:space:]]|[[:blank:]])+";
1813 $anchor = ereg_replace($pattern, '-', $anchor);
1814 return $this->short_name($anchor); // return the short filtered name
1815 } # end function
1816
1817/**
1818 * Function to expand the SEO_CONVERT_SET group
1819 * @author Bobby Easland
1820 * @version 1.0
1821 * @param string $set
1822 * @return mixed
1823 */
1824 function expand($set){
1825 if ( $this->not_null($set) ){
1826 if ( $data = @explode(',', $set) ){
1827 foreach ( $data as $index => $valuepair){
1828 $p = @explode('=>', $valuepair);
1829 $container[trim($p[0])] = trim($p[1]);
1830 }
1831 return $container;
1832 } else {
1833 return 'false';
1834 }
1835 } else {
1836 return 'false';
1837 }
1838 } # end function
1839/**
1840 * Function to return the short word filtered string
1841 * @author Bobby Easland
1842 * @version 1.0
1843 * @param string $str
1844 * @param integer $limit
1845 * @return string Short word filtered
1846 */
1847 function short_name($str, $limit=3){
1848 if ( $this->attributes['SEO_URLS_FILTER_SHORT_WORDS'] != 'false' ) $limit = (int)$this->attributes['SEO_URLS_FILTER_SHORT_WORDS'];
1849 $foo = @explode('-', $str);
1850 foreach($foo as $index => $value){
1851 switch (true){
1852 case ( strlen($value) <= $limit ):
1853 continue;
1854 default:
1855 $container[] = $value;
1856 break;
1857 }
1858 } # end foreach
1859 $container = ( sizeof($container) > 1 ? implode('-', $container) : $str );
1860 return $container;
1861 }
1862
1863/**
1864 * Function to implode an associative array
1865 * @author Bobby Easland
1866 * @version 1.0
1867 * @param array $array Associative data array
1868 * @param string $inner_glue
1869 * @param string $outer_glue
1870 * @return string
1871 */
1872 function implode_assoc($array, $inner_glue='=', $outer_glue='&') {
1873 $output = array();
1874 foreach( $array as $key => $item ){
1875 if ( $this->not_null($key) && $this->not_null($item) ){
1876 $output[] = $key . $inner_glue . $item;
1877 }
1878 } # end foreach
1879 return @implode($outer_glue, $output);
1880 }
1881
1882/**
1883 * Function to print an array within pre tags, debug use
1884 * @author Bobby Easland
1885 * @version 1.0
1886 * @param mixed $array
1887 */
1888 function PrintArray($array, $heading = ''){
1889 echo '<fieldset style="border-style:solid; border-width:1px;">' . "\n";
1890 echo '<legend style="background-color:#FFFFCC; border-style:solid; border-width:1px;">' . $heading . '</legend>' . "\n";
1891 echo '<pre style="text-align:left;">' . "\n";
1892 print_r($array);
1893 echo '</pre>' . "\n";
1894 echo '</fieldset><br>' . "\n";
1895 } # end function
1896
1897/**
1898 * Function to start time for performance metric
1899 * @author Bobby Easland
1900 * @version 1.0
1901 * @param float $start_time
1902 */
1903 function start(&$start_time){
1904 $start_time = explode(' ', microtime());
1905 }
1906
1907/**
1908 * Function to stop time for performance metric
1909 * @author Bobby Easland
1910 * @version 1.0
1911 * @param float $start
1912 * @param float $time NOTE: passed by reference
1913 */
1914 function stop($start, &$time){
1915 $end = explode(' ', microtime());
1916 $time = number_format( array_sum($end) - array_sum($start), 8, '.', '' );
1917 }
1918
1919/**
1920 * Function to translate a string
1921 * @author Bobby Easland
1922 * @version 1.0
1923 * @param string $data String to be translated
1924 * @param array $parse Array of tarnslation variables
1925 * @return string
1926 */
1927 function parse_input_field_data($data, $parse) {
1928 return strtr(trim($data), $parse);
1929 }
1930
1931/**
1932 * Function to output a translated or sanitized string
1933 * @author Bobby Easland
1934 * @version 1.0
1935 * @param string $sting String to be output
1936 * @param mixed $translate Array of translation characters
1937 * @param boolean $protected Switch for htemlspecialchars processing
1938 * @return string
1939 */
1940 function output_string($string, $translate = false, $protected = false) {
1941 if ($protected == true) {
1942 return htmlspecialchars($string);
1943 } else {
1944 if ($translate == false) {
1945 return $this->parse_input_field_data($string, array('"' => '"'));
1946 } else {
1947 return $this->parse_input_field_data($string, $translate);
1948 }
1949 }
1950 }
1951
1952/**
1953 * Function to return the session ID
1954 * @author Bobby Easland
1955 * @version 1.0
1956 * @param string $sessid
1957 * @return string
1958 */
1959 function SessionID($sessid = '') {
1960 if (!empty($sessid)) {
1961 return session_id($sessid);
1962 } else {
1963 return session_id();
1964 }
1965 }
1966
1967/**
1968 * Function to return the session name
1969 * @author Bobby Easland
1970 * @version 1.0
1971 * @param string $name
1972 * @return string
1973 */
1974 function SessionName($name = '') {
1975 if (!empty($name)) {
1976 return session_name($name);
1977 } else {
1978 return session_name();
1979 }
1980 }
1981
1982/**
1983 * Function to generate products cache entries
1984 * @author Bobby Easland
1985 * @version 1.0
1986 */
1987 function generate_products_cache(){
1988 $this->is_cached($this->cache_file . 'products', $is_cached, $is_expired);
1989 if ( !$is_cached || $is_expired ) {
1990 $sql = "SELECT p.products_id as id, pd.products_name as name, m.manufacturers_name as manufacturer FROM ".TABLE_MANUFACTURERS." m, ".TABLE_PRODUCTS." p, ".TABLE_PRODUCTS_DESCRIPTION." pd WHERE p.products_id=pd.products_id and m.manufacturers_id = p.manufacturers_id and p.products_status='1' and pd.language_id='".(int)$this->languages_id."'";
1991 $product_query = $this->DB->Query( $sql );
1992 $prod_cache = '';
1993 while ($product = $this->DB->FetchArray($product_query)) {
1994 $define = 'define(\'PRODUCT_NAME_' . $product['id'] . '\', \'' . $this->strip($product['manufacturer'] . ' - ' . $product['name']) . '\');';
1995 $prod_cache .= $define . "\n";
1996 eval("$define");
1997 }
1998 $this->DB->Free($product_query);
1999 $this->save_cache($this->cache_file . 'products', $prod_cache, 'EVAL', 1 , 1);
2000 unset($prod_cache);
2001 } else {
2002 $this->get_cache($this->cache_file . 'products');
2003 }
2004 } # end function
2005
2006/**
2007 * Function to generate manufacturers cache entries
2008 * @author Bobby Easland
2009 * @version 1.0
2010 */
2011 function generate_manufacturers_cache(){
2012 $this->is_cached($this->cache_file . 'manufacturers', $is_cached, $is_expired);
2013 if ( !$is_cached || $is_expired ) { // it's not cached so create it
2014 $sql = "SELECT m.manufacturers_id as id, m.manufacturers_name as name
2015 FROM ".TABLE_MANUFACTURERS." m
2016 LEFT JOIN ".TABLE_MANUFACTURERS_INFO." md
2017 ON m.manufacturers_id=md.manufacturers_id
2018 AND md.languages_id='".(int)$this->languages_id."'";
2019 $manufacturers_query = $this->DB->Query( $sql );
2020 $man_cache = '';
2021 while ($manufacturer = $this->DB->FetchArray($manufacturers_query)) {
2022 $define = 'define(\'MANUFACTURER_NAME_' . $manufacturer['id'] . '\', \'' . $this->strip($manufacturer['name']) . '\');';
2023 $man_cache .= $define . "\n";
2024 eval("$define");
2025 }
2026 $this->DB->Free($manufacturers_query);
2027 $this->save_cache($this->cache_file . 'manufacturers', $man_cache, 'EVAL', 1 , 1);
2028 unset($man_cache);
2029 } else {
2030 $this->get_cache($this->cache_file . 'manufacturers');
2031 }
2032 } # end function
2033
2034/**
2035 * Function to generate categories cache entries
2036 * @author Bobby Easland
2037 * @version 1.1
2038 */
2039 function generate_categories_cache(){
2040 $this->is_cached($this->cache_file . 'categories', $is_cached, $is_expired);
2041 if ( !$is_cached || $is_expired ) { // it's not cached so create it
2042 switch(true){
2043 case ($this->attributes['SEO_ADD_CAT_PARENT'] == 'true'):
2044 $sql = "SELECT c.categories_id as id, c.parent_id, cd.categories_name as cName, cd2.categories_name as pName
2045 FROM ".TABLE_CATEGORIES." c
2046 JOIN ".TABLE_CATEGORIES_DESCRIPTION." cd
2047 ON c.categories_id = cd.categories_id
2048 LEFT JOIN ".TABLE_CATEGORIES_DESCRIPTION." cd2
2049 ON c.parent_id=cd2.categories_id AND cd2.language_id='".(int)$this->languages_id."'
2050 WHERE c.categories_id=cd.categories_id
2051 AND cd.language_id='".(int)$this->languages_id."'";
2052 break;
2053 default:
2054 $sql = "SELECT categories_id as id, categories_name as cName
2055 FROM ".TABLE_CATEGORIES_DESCRIPTION."
2056 WHERE language_id='".(int)$this->languages_id."'";
2057 break;
2058 } # end switch
2059 $category_query = $this->DB->Query( $sql );
2060 $cat_cache = '';
2061 while ($category = $this->DB->FetchArray($category_query)) {
2062 $id = $this->get_full_cPath($category['id'], $single_cID);
2063 $name = $this->not_null($category['pName']) ? $category['pName'] . ' ' . $category['cName'] : $category['cName'];
2064 $define = 'define(\'CATEGORY_NAME_' . $id . '\', \'' . $this->strip($name) . '\');';
2065 $cat_cache .= $define . "\n";
2066 eval("$define");
2067 }
2068 $this->DB->Free($category_query);
2069 $this->save_cache($this->cache_file . 'categories', $cat_cache, 'EVAL', 1 , 1);
2070 unset($cat_cache);
2071 } else {
2072 $this->get_cache($this->cache_file . 'categories');
2073 }
2074 } # end function
2075
2076/**
2077 * Function to generate articles cache entries
2078 * @author Bobby Easland
2079 * @version 1.0
2080 */
2081 function generate_articles_cache(){
2082 $this->is_cached($this->cache_file . 'articles', $is_cached, $is_expired);
2083 if ( !$is_cached || $is_expired ) { // it's not cached so create it
2084 $sql = "SELECT articles_id as id, articles_name as name
2085 FROM ".TABLE_ARTICLES_DESCRIPTION."
2086 WHERE language_id = '".(int)$this->languages_id."'";
2087 $article_query = $this->DB->Query( $sql );
2088 $article_cache = '';
2089 while ($article = $this->DB->FetchArray($article_query)) {
2090 $define = 'define(\'ARTICLE_NAME_' . $article['id'] . '\', \'' . $this->strip($article['name']) . '\');';
2091 $article_cache .= $define . "\n";
2092 eval("$define");
2093 }
2094 $this->DB->Free($article_query);
2095 $this->save_cache($this->cache_file . 'articles', $article_cache, 'EVAL', 1 , 1);
2096 unset($article_cache);
2097 } else {
2098 $this->get_cache($this->cache_file . 'articles');
2099 }
2100 } # end function
2101
2102
2103/**
2104* Function to generate authors cache entries
2105 * @author Bobby Easland
2106 * @version 1.0
2107 */
2108 function generate_authors_cache(){
2109 $this->is_cached($this->cache_file . 'authors', $is_cached, $is_expired);
2110 if ( !$is_cached || $is_expired ) { // it's not cached so create it
2111 $sql = "SELECT authors_id as id, authors_name as name
2112 FROM ".TABLE_AUTHORS."
2113 WHERE language_id='".(int)$this->languages_id."'";
2114 $authors_query = $this->DB->Query( $sql );
2115 $authors_cache = '';
2116 while ($authors = $this->DB->FetchArray($authors_query)) {
2117 $define = 'define(\'AUTHORS_NAME_' . $authors['id'] . '\', \'' . $this->strip($authors['name']) . '\');';
2118 $authors_cache .= $define . "\n";
2119 eval("$define");
2120 }
2121 $this->DB->Free($authors_query);
2122 $this->save_cache($this->cache_file . 'authors', $authors_cache, 'EVAL', 1 , 1);
2123 unset($authors_cache);
2124 } else {
2125 $this->get_cache($this->cache_file . 'authors');
2126 }
2127 } # end function
2128
2129/**
2130 * Function to generate topics cache entries
2131 * @author Bobby Easland
2132 * @version 1.0
2133 */
2134 function generate_topics_cache(){
2135 $this->is_cached($this->cache_file . 'topics', $is_cached, $is_expired);
2136 if ( !$is_cached || $is_expired ) { // it's not cached so create it
2137 $sql = "SELECT topics_id as id, topics_name as name
2138 FROM ".TABLE_TOPICS_DESCRIPTION."
2139 WHERE language_id='".(int)$this->languages_id."'";
2140 $topic_query = $this->DB->Query( $sql );
2141 $topic_cache = '';
2142 while ($topic = $this->DB->FetchArray($topic_query)) {
2143 $define = 'define(\'TOPIC_NAME_' . $topic['id'] . '\', \'' . $this->strip($topic['name']) . '\');';
2144 $topic_cache .= $define . "\n";
2145 eval("$define");
2146 }
2147 $this->DB->Free($topic_query);
2148 $this->save_cache($this->cache_file . 'topics', $topic_cache, 'EVAL', 1 , 1);
2149 unset($topic_cache);
2150 } else {
2151 $this->get_cache($this->cache_file . 'topics');
2152 }
2153 } # end function
2154
2155/** ojp
2156 * Function to generate topics cache entries
2157 * @author Bobby Easland
2158 * @version 1.0
2159 */
2160 function generate_links_cache(){
2161 $this->is_cached($this->cache_file . 'links', $is_cached, $is_expired);
2162 if ( !$is_cached || $is_expired ) { // it's not cached so create it
2163 $sql = "SELECT link_categories_id as id, link_categories_name as name
2164 FROM ".TABLE_LINK_CATEGORIES_DESCRIPTION."
2165 WHERE language_id='".(int)$this->languages_id."'";
2166 $link_query = $this->DB->Query( $sql );
2167 $link_cache = '';
2168 while ($link = $this->DB->FetchArray($link_query)) {
2169 $define = 'define(\'LINK_NAME_' . $link['id'] . '\', \'' . $this->strip($link['name']) . '\');';
2170 $link_cache .= $define . "\n";
2171 eval("$define");
2172 }
2173 $this->DB->Free($link_query);
2174 $this->save_cache($this->cache_file . 'links', $link_cache, 'EVAL', 1 , 1);
2175 unset($link_cache);
2176 } else {
2177 $this->get_cache($this->cache_file . 'links');
2178 }
2179 } # end function
2180
2181
2182
2183/**
2184 * Function to generate information cache entries
2185 * @author Bobby Easland
2186 * @version 1.0
2187 */
2188 function generate_information_cache(){
2189 $this->is_cached($this->cache_file . 'information', $is_cached, $is_expired);
2190 if ( !$is_cached || $is_expired ) { // it's not cached so create it
2191 $sql = "SELECT information_id as id, information_title as name
2192 FROM ".TABLE_INFORMATION."
2193 WHERE languages_id='".(int)$this->languages_id."'";
2194 $information_query = $this->DB->Query( $sql );
2195 $information_cache = '';
2196 while ($information = $this->DB->FetchArray($information_query)) {
2197 $define = 'define(\'INFO_NAME_' . $information['id'] . '\', \'' . $this->strip($information['name']) . '\');';
2198 $information_cache .= $define . "\n";
2199 eval("$define");
2200 }
2201 $this->DB->Free($information_query);
2202 $this->save_cache($this->cache_file . 'information', $information_cache, 'EVAL', 1 , 1);
2203 unset($information_cache);
2204 } else {
2205 $this->get_cache($this->cache_file . 'information');
2206 }
2207 } # end function
2208
2209/**
2210 * Function to save the cache to database
2211 * @author Bobby Easland
2212 * @version 1.0
2213 * @param string $name Cache name
2214 * @param mixed $value Can be array, string, PHP code, or just about anything
2215 * @param string $method RETURN, ARRAY, EVAL
2216 * @param integer $gzip Enables compression
2217 * @param integer $global Sets whether cache record is global is scope
2218 * @param string $expires Sets the expiration
2219 */
2220 function save_cache($name, $value, $method='RETURN', $gzip=1, $global=0, $expires = '30/days'){
2221 $expires = $this->convert_time($expires);
2222 if ($method == 'ARRAY' ) $value = serialize($value);
2223 $value = ( $gzip === 1 ? base64_encode(gzdeflate($value, 1)) : addslashes($value) );
2224 $sql_data_array = array('cache_id' => md5($name),
2225 'cache_language_id' => (int)$this->languages_id,
2226 'cache_name' => $name,
2227 'cache_data' => $value,
2228 'cache_global' => (int)$global,
2229 'cache_gzip' => (int)$gzip,
2230 'cache_method' => $method,
2231 'cache_date' => date("Y-m-d H:i:s"),
2232 'cache_expires' => $expires
2233 );
2234 $this->is_cached($name, $is_cached, $is_expired);
2235 $cache_check = ( $is_cached ? 'true' : 'false' );
2236 switch ( $cache_check ) {
2237 case 'true':
2238 $this->DB->DBPerform('cache', $sql_data_array, 'update', "cache_id='".md5($name)."'");
2239 break;
2240 case 'false':
2241 $this->DB->DBPerform('cache', $sql_data_array, 'insert');
2242 break;
2243 default:
2244 break;
2245 } # end switch ($cache check)
2246 # unset the variables...clean as we go
2247 unset($value, $expires, $sql_data_array);
2248 }# end function save_cache()
2249
2250/**
2251 * Function to get cache entry
2252 * @author Bobby Easland
2253 * @version 1.0
2254 * @param string $name
2255 * @param boolean $local_memory
2256 * @return mixed
2257 */
2258 function get_cache($name = 'GLOBAL', $local_memory = false){
2259 $select_list = 'cache_id, cache_language_id, cache_name, cache_data, cache_global, cache_gzip, cache_method, cache_date, cache_expires';
2260 $global = ( $name == 'GLOBAL' ? true : false ); // was GLOBAL passed or is using the default?
2261 switch($name){
2262 case 'GLOBAL':
2263 $this->cache_query = $this->DB->Query("SELECT ".$select_list." FROM cache WHERE cache_language_id='".(int)$this->languages_id."' AND cache_global='1'");
2264 break;
2265 default:
2266 $this->cache_query = $this->DB->Query("SELECT ".$select_list." FROM cache WHERE cache_id='".md5($name)."' AND cache_language_id='".(int)$this->languages_id."'");
2267 break;
2268 } # end switch ($name)
2269 $num_rows = $this->DB->NumRows($this->cache_query);
2270 if ( $num_rows ){
2271 $container = array();
2272 while($cache = $this->DB->FetchArray($this->cache_query)){
2273 $cache_name = $cache['cache_name'];
2274 if ( $cache['cache_expires'] > date("Y-m-d H:i:s") ) {
2275 $cache_data = ( $cache['cache_gzip'] == 1 ? gzinflate(base64_decode($cache['cache_data'])) : stripslashes($cache['cache_data']) );
2276 switch($cache['cache_method']){
2277 case 'EVAL': // must be PHP code
2278 eval("$cache_data");
2279 break;
2280 case 'ARRAY':
2281 $cache_data = unserialize($cache_data);
2282 case 'RETURN':
2283 default:
2284 break;
2285 } # end switch ($cache['cache_method'])
2286 if ($global) $container['GLOBAL'][$cache_name] = $cache_data;
2287 else $container[$cache_name] = $cache_data; // not global
2288 } else { // cache is expired
2289 if ($global) $container['GLOBAL'][$cache_name] = false;
2290 else $container[$cache_name] = false;
2291 }# end if ( $cache['cache_expires'] > date("Y-m-d H:i:s") )
2292 if ( $this->keep_in_memory || $local_memory ) {
2293 if ($global) $this->data['GLOBAL'][$cache_name] = $container['GLOBAL'][$cache_name];
2294 else $this->data[$cache_name] = $container[$cache_name];
2295 }
2296 } # end while ($cache = $this->DB->FetchArray($this->cache_query))
2297 unset($cache_data);
2298 $this->DB->Free($this->cache_query);
2299 switch (true) {
2300 case ($num_rows == 1):
2301 if ($global){
2302 if ($container['GLOBAL'][$cache_name] == false || !isset($container['GLOBAL'][$cache_name])) return false;
2303 else return $container['GLOBAL'][$cache_name];
2304 } else { // not global
2305 if ($container[$cache_name] == false || !isset($container[$cache_name])) return false;
2306 else return $container[$cache_name];
2307 } # end if ($global)
2308 case ($num_rows > 1):
2309 default:
2310 return $container;
2311 break;
2312 }# end switch (true)
2313 } else {
2314 return false;
2315 }# end if ( $num_rows )
2316 } # end function get_cache()
2317
2318/**
2319 * Function to get cache from memory
2320 * @author Bobby Easland
2321 * @version 1.0
2322 * @param string $name
2323 * @param string $method
2324 * @return mixed
2325 */
2326 function get_cache_memory($name, $method = 'RETURN'){
2327 $data = ( isset($this->data['GLOBAL'][$name]) ? $this->data['GLOBAL'][$name] : $this->data[$name] );
2328 if ( isset($data) && !empty($data) && $data != false ){
2329 switch($method){
2330 case 'EVAL': // data must be PHP
2331 eval("$data");
2332 return true;
2333 break;
2334 case 'ARRAY':
2335 case 'RETURN':
2336 default:
2337 return $data;
2338 break;
2339 } # end switch ($method)
2340 } else {
2341 return false;
2342 } # end if (isset($data) && !empty($data) && $data != false)
2343 } # end function get_cache_memory()
2344
2345/**
2346 * Function to perform basic garbage collection for database cache system
2347 * @author Bobby Easland
2348 * @version 1.0
2349 */
2350 function cache_gc(){
2351 $this->DB->Query("DELETE FROM cache WHERE cache_expires <= '" . date("Y-m-d H:i:s") . "'" );
2352 }
2353
2354/**
2355 * Function to convert time for cache methods
2356 * @author Bobby Easland
2357 * @version 1.0
2358 * @param string $expires
2359 * @return string
2360 */
2361 function convert_time($expires){ //expires date interval must be spelled out and NOT abbreviated !!
2362 $expires = explode('/', $expires);
2363 switch( strtolower($expires[1]) ){
2364 case 'seconds':
2365 $expires = mktime( date("H"), date("i"), date("s")+(int)$expires[0], date("m"), date("d"), date("Y") );
2366 break;
2367 case 'minutes':
2368 $expires = mktime( date("H"), date("i")+(int)$expires[0], date("s"), date("m"), date("d"), date("Y") );
2369 break;
2370 case 'hours':
2371 $expires = mktime( date("H")+(int)$expires[0], date("i"), date("s"), date("m"), date("d"), date("Y") );
2372 break;
2373 case 'days':
2374 $expires = mktime( date("H"), date("i"), date("s"), date("m"), date("d")+(int)$expires[0], date("Y") );
2375 break;
2376 case 'months':
2377 $expires = mktime( date("H"), date("i"), date("s"), date("m")+(int)$expires[0], date("d"), date("Y") );
2378 break;
2379 case 'years':
2380 $expires = mktime( date("H"), date("i"), date("s"), date("m"), date("d"), date("Y")+(int)$expires[0] );
2381 break;
2382 default: // if something fudged up then default to 1 month
2383 $expires = mktime( date("H"), date("i"), date("s"), date("m")+1, date("d"), date("Y") );
2384 break;
2385 } # end switch( strtolower($expires[1]) )
2386 return date("Y-m-d H:i:s", $expires);
2387 } # end function convert_time()
2388
2389/**
2390 * Function to check if the cache is in the database and expired
2391 * @author Bobby Easland
2392 * @version 1.0
2393 * @param string $name
2394 * @param boolean $is_cached NOTE: passed by reference
2395 * @param boolean $is_expired NOTE: passed by reference
2396 */
2397 function is_cached($name, &$is_cached, &$is_expired){ // NOTE: $is_cached and $is_expired is passed by reference !!
2398 $this->cache_query = $this->DB->Query("SELECT cache_expires FROM cache WHERE cache_id='".md5($name)."' AND cache_language_id='".(int)$this->languages_id."' LIMIT 1");
2399 $is_cached = ( $this->DB->NumRows($this->cache_query ) > 0 ? true : false );
2400 if ($is_cached){
2401 $check = $this->DB->FetchArray($this->cache_query);
2402 $is_expired = ( $check['cache_expires'] <= date("Y-m-d H:i:s") ? true : false );
2403 unset($check);
2404 }
2405 $this->DB->Free($this->cache_query);
2406 }# end function is_cached()
2407
2408/**
2409 * Function to initialize the redirect logic
2410 * @author Bobby Easland
2411 * @version 1.1
2412 */
2413 function check_redirect(){
2414 $this->need_redirect = false;
2415 $this->path_info = is_numeric(strpos(ltrim(getenv('PATH_INFO'), '/') , '/')) ? ltrim(getenv('PATH_INFO'), '/') : NULL;
2416 $this->uri = ltrim( basename($_SERVER['REQUEST_URI']), '/' );
2417 $this->real_uri = ltrim( basename($_SERVER['SCRIPT_NAME']) . '?' . $_SERVER['QUERY_STRING'], '/' );
2418 $this->uri_parsed = $this->not_null( $this->path_info )
2419 ? parse_url(basename($_SERVER['SCRIPT_NAME']) . '?' . $this->parse_path($this->path_info) )
2420 : parse_url(basename($_SERVER['REQUEST_URI']));
2421 $this->attributes['SEO_REDIRECT']['PATH_INFO'] = $this->path_info;
2422 $this->attributes['SEO_REDIRECT']['URI'] = $this->uri;
2423 $this->attributes['SEO_REDIRECT']['REAL_URI'] = $this->real_uri;
2424 $this->attributes['SEO_REDIRECT']['URI_PARSED'] = $this->uri_parsed;
2425 $this->need_redirect();
2426 $this->check_seo_page();
2427 if ( $this->need_redirect && $this->is_seopage && $this->attributes['USE_SEO_REDIRECT'] == 'true') $this->do_redirect();
2428 } # end function
2429
2430/**
2431 * Function to check if the URL needs to be redirected
2432 * @author Bobby Easland
2433 * @version 1.2
2434 */
2435 function need_redirect(){
2436 foreach( $this->reg_anchors as $param => $value){
2437 $pattern[] = $param;
2438 }
2439 switch(true){
2440 case ($this->is_attribute_string($this->uri)):
2441 $this->need_redirect = false;
2442 break;
2443 case ($this->uri != $this->real_uri && !$this->not_null($this->path_info)):
2444 $this->need_redirect = false;
2445 break;
2446 case (is_numeric(strpos($this->uri, '.htm'))):
2447 $this->need_redirect = false;
2448 break;
2449 case (@eregi("(".@implode('|', $pattern).")", $this->uri)):
2450 $this->need_redirect = true;
2451 break;
2452 case (@eregi("(".@implode('|', $pattern).")", $this->path_info)):
2453 $this->need_redirect = true;
2454 break;
2455 default:
2456 break;
2457 } # end switch
2458 $this->attributes['SEO_REDIRECT']['NEED_REDIRECT'] = $this->need_redirect ? 'true' : 'false';
2459 } # end function set_seopage
2460
2461/**
2462 * Function to check if it's a valid redirect page
2463 * @author Bobby Easland
2464 * @version 1.1
2465 */
2466 function check_seo_page(){
2467 switch (true){
2468 case (in_array($this->uri_parsed['path'], $this->attributes['SEO_PAGES'])):
2469 $this->is_seopage = true;
2470 break;
2471 case ($this->attributes['SEO_ENABLED'] == 'false'):
2472 default:
2473 $this->is_seopage = false;
2474 break;
2475 } # end switch
2476 $this->attributes['SEO_REDIRECT']['IS_SEOPAGE'] = $this->is_seopage ? 'true' : 'false';
2477 } # end function check_seo_page
2478
2479/**
2480 * Function to parse the path for old SEF URLs
2481 * @author Bobby Easland
2482 * @version 1.0
2483 * @param string $path_info
2484 * @return array
2485 */
2486 function parse_path($path_info){
2487 $tmp = @explode('/', $path_info);
2488 if ( sizeof($tmp) > 2 ){
2489 $container = array();
2490 for ($i=0, $n=sizeof($tmp); $i<$n; $i++) {
2491 $container[] = $tmp[$i] . '=' . $tmp[$i+1];
2492 $i++;
2493 }
2494 return @implode('&', $container);
2495 } else {
2496 return @implode('=', $tmp);
2497 }
2498 } # end function parse_path
2499
2500/**
2501 * Function to perform redirect
2502 * @author Bobby Easland
2503 * @version 1.0
2504 */
2505 function do_redirect(){
2506 $p = @explode('&', $this->uri_parsed['query']);
2507 foreach( $p as $index => $value ){
2508 $tmp = @explode('=', $value);
2509 switch($tmp[0]){
2510 case 'products_id':
2511 if ( $this->is_attribute_string($tmp[1]) ){
2512 $pieces = @explode('{', $tmp[1]);
2513 $params[] = $tmp[0] . '=' . $pieces[0];
2514 } else {
2515 $params[] = $tmp[0] . '=' . $tmp[1];
2516 }
2517 break;
2518 default:
2519 $params[] = $tmp[0].'='.$tmp[1];
2520 break;
2521 }
2522 } # end foreach( $params as $var => $value )
2523 $params = ( sizeof($params) > 1 ? implode('&', $params) : $params[0] );
2524 $url = $this->href_link($this->uri_parsed['path'], $params, 'NONSSL', false);
2525 switch(true){
2526 case (defined('USE_SEO_REDIRECT_DEBUG') && USE_SEO_REDIRECT_DEBUG == 'true'):
2527 $this->attributes['SEO_REDIRECT']['REDIRECT_URL'] = $url;
2528 break;
2529 case ($this->attributes['USE_SEO_REDIRECT'] == 'true'):
2530 header("HTTP/1.0 301 Moved Permanently");
2531 header("Location: $url"); // redirect...bye bye
2532 break;
2533 default:
2534 $this->attributes['SEO_REDIRECT']['REDIRECT_URL'] = $url;
2535 break;
2536 } # end switch
2537 } # end function do_redirect
2538} # end class
2539# BC Redirects shouldn't have '&'s in them
2540$url = preg_replace('/&/','&',$url);
2541?>