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