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