1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
|
<?php
/** * Ultimate SEO URLs Contribution - osCommerce MS-2.2 * * Ultimate SEO URLs offers search engine optimized URLS for osCommerce * based applications. Other features include optimized performance and * automatic redirect script. * @package Ultimate-SEO-URLs * @link http://www.oscommerce-freelancers.com/ osCommerce-Freelancers * @copyright Copyright 2005, Bobby Easland * @author Bobby Easland * @filesource */
/** * SEO_DataBase Class * * The SEO_DataBase class provides abstraction so the databaes can be accessed * without having to use tep API functions. This class has minimal error handling * so make sure your code is tight! * @package Ultimate-SEO-URLs * @link http://www.oscommerce-freelancers.com/ osCommerce-Freelancers * @copyright Copyright 2005, Bobby Easland * @author Bobby Easland */ class SEO_DataBase{ /** * Database host (localhost, IP based, etc) * @var string */ var $host; /** * Database user * @var string */ var $user; /** * Database name * @var string */ var $db; /** * Database password * @var string */ var $pass; /** * Database link * @var resource */ var $link_id;
/** * MySQL_DataBase class constructor * @author Bobby Easland * @version 1.0 * @param string $host * @param string $user * @param string $db * @param string $pass */ function SEO_DataBase($host, $user, $db, $pass){ $this->host = $host; $this->user = $user; $this->db = $db; $this->pass = $pass; $this->ConnectDB(); $this->SelectDB(); } # end function
/** * Function to connect to MySQL * @author Bobby Easland * @version 1.1 */ function ConnectDB(){ $this->link_id = mysql_connect($this->host, $this->user, $this->pass); } # end function /** * Function to select the database * @author Bobby Easland * @version 1.0 * @return resoource */ function SelectDB(){ return mysql_select_db($this->db); } # end function /** * Function to perform queries * @author Bobby Easland * @version 1.0 * @param string $query SQL statement * @return resource */ function Query($query){ $result = @mysql_query($query, $this->link_id); return $result; } # end function /** * Function to fetch array * @author Bobby Easland * @version 1.0 * @param resource $resource_id * @param string $type MYSQL_BOTH or MYSQL_ASSOC * @return array */ function FetchArray($resource_id, $type = MYSQL_BOTH){ if ($resource_id) { $result = mysql_fetch_array($resource_id, $type); return $result; } return false; } # end function /** * Function to fetch the number of rows * @author Bobby Easland * @version 1.0 * @param resource $resource_id * @return mixed */ function NumRows($resource_id){ return @mysql_num_rows($resource_id); } # end function
/** * Function to free the resource * @author Bobby Easland * @version 1.0 * @param resource $resource_id * @return boolean */ function Free($resource_id){ return @mysql_free_result($resource_id); } # end function
/** * Function to add slashes * @author Bobby Easland * @version 1.0 * @param string $data * @return string */ function Slashes($data){ return addslashes($data); } # end function } # end class
/** * Ultimate SEO URLs Installer and Configuration Class * * Ultimate SEO URLs installer and configuration class offers a modular * and easy to manage method of configuration. The class enables the base * class to be configured and installed on the fly without the hassle of * calling additional scripts or executing SQL. * @package Ultimate-SEO-URLs * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 1.1 * @link http://www.oscommerce-freelancers.com/ osCommerce-Freelancers * @copyright Copyright 2005, Bobby Easland * @author Bobby Easland */ class SEO_URL_INSTALLER{ /** * The default_config array has all the default settings which should be all that is needed to make the base class work. * @var array */ var $default_config; /** * Database object * @var object */ var $DB; /** * $attributes array holds information about this instance * @var array */ var $attributes; /** * SEO_URL_INSTALLER class constructor * @author Bobby Easland * @version 1.1 */ function SEO_URL_INSTALLER(){ $this->attributes = array(); $x = 0; $this->default_config = array(); $this->default_config['SEO_ENABLED'] = array('DEFAULT' => 'true'); $x++; $this->default_config['SEO_ADD_CID_TO_PRODUCT_URLS'] = array('DEFAULT' => 'false'); $x++; $this->default_config['SEO_ADD_CPATH_TO_PRODUCT_URLS'] = array('DEFAULT' => 'false'); $x++; $this->default_config['SEO_ADD_CAT_PARENT'] = array('DEFAULT' => 'false'); $x++;
$this->default_config['USE_SEO_HEADER_TAGS'] = array('DEFAULT' => 'false'); $x++; $this->default_config['SEO_REWRITE_TYPE'] = array('DEFAULT' => 'Rewrite'); $x++; $this->init(); } # end class constructor /** * Initializer - if there are settings not defined the default config will be used and database settings installed. * @author Bobby Easland * @version 1.1 */ function init(){ $this->eval_defaults();
} # end function /** * This function evaluates the default serrings into defined constants * @author Bobby Easland * @version 1.0 */ function eval_defaults(){ foreach( $this->default_config as $key => $value ){ if (!defined($key)) define($key, $value['DEFAULT']); } # end foreach } # end function } # end class
/** * Ultimate SEO URLs Base Class * * Ultimate SEO URLs offers search engine optimized URLS for osCommerce * based applications. Other features include optimized performance and * automatic redirect script. * @package Ultimate-SEO-URLs * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version 2.1 * @link http://www.oscommerce-freelancers.com/ osCommerce-Freelancers * @copyright Copyright 2005, Bobby Easland * @author Bobby Easland */ class SEO_URL{ var $attributes; /** * $base_url is the NONSSL URL for site * @var string */ var $base_url; /** * $base_url_ssl is the secure URL for the site * @var string */ var $base_url_ssl; /** * $reg_anchors holds the anchors used by the .htaccess rewrites * @var array */ var $reg_anchors; /** * $data array contains all records retrieved from database cache * @var array */ var $data; /** * $need_redirect determines whether the URL needs to be redirected * @var boolean */ var $need_redirect; /** * $is_seopage holds value as to whether page is in allowed SEO pages * @var boolean */ var $is_seopage; /** * $uri contains the $_SERVER['REQUEST_URI'] value * @var string */ var $uri; /** * $real_uri contains the $_SERVER['SCRIPT_NAME'] . '?' . $_SERVER['QUERY_STRING'] value * @var string */ var $real_uri; /** * $uri_parsed contains the parsed uri value array * @var array */ var $uri_parsed; /** * $path_info contains the getenv('PATH_INFO') value * @var string */ var $path_info; /** * $DB is the database object * @var object */ var $DB; /** * $installer is the installer object * @var object */ var $installer;
/** * SEO_URL class constructor * @author Bobby Easland * @version 1.1 * @param integer $languages_id */ function SEO_URL(){ $this->installer = new SEO_URL_INSTALLER;
$this->DB = new SEO_DataBase(DB_SERVER, DB_SERVER_USERNAME, DB_DATABASE, DB_SERVER_PASSWORD);
$this->data = array();
//ojp FILENAME_LINKS $seo_pages = array(FILENAME_PROD, FILENAME_PRODUCT_INFO); if ( defined('FILENAME_PAGES') ) $seo_pages[] = FILENAME_PAGES;
//ojp USE_SEO_CACHE_LINKS $this->attributes = array('SEO_ENABLED' => defined('SEO_ENABLED') ? SEO_ENABLED : 'false', 'SEO_ADD_CID_TO_PRODUCT_URLS' => defined('SEO_ADD_CID_TO_PRODUCT_URLS') ? SEO_ADD_CID_TO_PRODUCT_URLS : 'false', 'SEO_ADD_CPATH_TO_PRODUCT_URLS' => defined('SEO_ADD_CPATH_TO_PRODUCT_URLS') ? SEO_ADD_CPATH_TO_PRODUCT_URLS : 'false', 'SEO_ADD_CAT_PARENT' => defined('SEO_ADD_CAT_PARENT') ? SEO_ADD_CAT_PARENT : 'false', 'USE_SEO_HEADER_TAGS' => defined('USE_SEO_HEADER_TAGS') ? USE_SEO_HEADER_TAGS : 'false', 'SEO_REWRITE_TYPE' => defined('SEO_REWRITE_TYPE') ? SEO_REWRITE_TYPE : 'false', 'SEO_PAGES' => $seo_pages );
$this->base_url = HTTP_SERVER . DIR_WS_HTTP_CATALOG;
$this->reg_anchors = array('products_id' => 'produto/', 'cPath' => 'produtos/', 'id' => 'blog/' );
} # end constructor
/** * Function to return SEO URL link SEO'd with stock generattion for error fallback * @author Bobby Easland * @version 1.0 * @param string $page Base script for URL * @param string $parameters URL parameters * @param string $connection NONSSL/SSL * @param boolean $add_session_id Switch to add osCsid * @return string Formed href link */ function href_link($page = '', $parameters = '', $connection = 'NONSSL', $add_session_id = true){ // Some sites have hardcoded & $parameters = str_replace('&', '&', $parameters);
$link = $this->base_url ; $separator = '?'; if ($this->not_null($parameters)) { $link .= $this->parse_parameters($page, $parameters, $separator); } else { $link .= $page; } $link = $this->add_sid($link, $add_session_id, $connection, $separator);
return utf8_encode($link); } # end function
/** * Function to append session ID if needed * @author Bobby Easland * @version 1.2 * @param string $link * @param boolean $add_session_id * @param string $connection * @param string $separator * @return string */ function add_sid( $link, $add_session_id, $connection, $separator ){ global $request_type; // global variable
switch(true){ case (isset($_sid) && $this->not_null($_sid)): $return = $link . $separator . tep_output_string($_sid); break; default: $return = $link; break; } # end switch return $return; } # end function /** * SFunction to parse the parameters into an SEO URL * @author Bobby Easland * @version 1.2 * @param string $page * @param string $params * @param string $separator NOTE: passed by reference * @return string */ function parse_parameters($page, $params, &$separator){ $p = @explode('&', $params); krsort($p); $container = array(); foreach ($p as $index => $valuepair){ $p2 = @explode('=', $valuepair); switch ($p2[0]){ case 'products_id': $url = $this->make_url2($page, $this->get_prod_name($p2[1]), $p2[0], $p2[1], ''); break; case 'categoria': $url = $this->make_url2($page, $this->get_categoria($p2[1]), $p2[0], $p2[1], ''); break; case 'dtproduto': $url = $this->make_url2($page, $this->get_produto($p2[1]), $p2[0], $p2[1], ''); break; case 'cPath': $url = $this->make_url($page, $this->get_category_name($p2[1]), $p2[0], $p2[1], ''); break; case 'id': $url = $this->make_url2($page, $this->get_not_name($p2[1]), $p2[0], $p2[1], ''); break; default: if( isset($p2[1]) ) $container[$p2[0]] = $p2[1]; break; } # end switch } # end foreach $p $url = isset($url) ? $url : $page; if ( sizeof($container) > 0 ){ if ( $imploded_params = $this->implode_assoc($container) ){ $url .= $separator . $this->output_string( $imploded_params ); $separator = '&'; } }
return $url; } # end function
/** * Function to return the generated SEO URL * @author Bobby Easland * @version 1.0 * @param string $page * @param string $string Stripped, formed anchor * @param string $anchor_type Parameter type (idproduto, cPath, etc.) * @param integer $id * @param string $extension Default = .html * @param string $separator NOTE: passed by reference -- NOTE: not used so removed * @return string */ function make_url($page, $string, $anchor_type, $id, $extension = '.html'){ // Right now there is but one rewrite method since cName was dropped // In the future there will be additional methods here in the switch switch ( $this->attributes['SEO_REWRITE_TYPE'] ){ case 'Rewrite': return $this->reg_anchors[$anchor_type] . $id .'/'.$string . $extension;
// return $string . $this->reg_anchors[$anchor_type] . $id . $extension; break; default: break; } # end switch } # end function function make_url2($page, $string, $anchor_type, $id, $extension = '.html'){ // Right now there is but one rewrite method since cName was dropped // In the future there will be additional methods here in the switch switch ( $this->attributes['SEO_REWRITE_TYPE'] ){ case 'Rewrite': return $this->reg_anchors[$anchor_type] .$string . $extension;
// return $string . $this->reg_anchors[$anchor_type] . $id . $extension; break; default: break; } # end switch } # end function
/** * Function to get names of all parent categories * @author Jack_mcs * @version 1.0 * @param string $name * @param string $method * @return string */ /** * Function to get the category name. Use evaluated cache, per page cache, or database query in that order of precedent * @author Bobby Easland * @version 1.1 * @param integer $cID NOTE: passed by reference * @return string Stripped anchor text */ function get_category_name(&$cID){ $full_cPath = $this->get_full_cPath($cID, $single_cID); // full cPath needed for uniformity $sqlCmd = $this->attributes['USE_SEO_HEADER_TAGS'] == 'true' ? 'categoria as cName' : 'categoria as cName'; $sql = "SELECT " . $sqlCmd . " FROM categoria WHERE idcategoria='".(int)$single_cID."' LIMIT 1"; $result = $this->DB->FetchArray( $this->DB->Query( $sql ) ); $cName = $result['cName']; $cName = $this->strip($cName); $return = $cName; $cID = $full_cPath; return $return; } # end function function get_not_name(&$cID){ $full_cPath = $this->get_full_cPath($cID, $single_cID); // full cPath needed for uniformity
switch(true){ default:
$sqlCmd = 'url as pName'; $sql = "SELECT " . $sqlCmd . " FROM categoria_artigo WHERE idcategoria_artigo='".(int)$single_cID."' LIMIT 1"; $result = $this->DB->FetchArray( $this->DB->Query( $sql ) ); $cName = $result['pName']; break; } $cName = $this->strip($cName); $return = $cName; $cID = $full_cPath; return $return; } # end function
function get_prod_name(&$cID){ $full_cPath = $this->get_full_cPath($cID, $single_cID); // full cPath needed for uniformity
switch(true){ default:
$sqlCmd = $this->attributes['USE_SEO_HEADER_TAGS'] == 'true' ? 'produto as pName' : 'produto as pName'; $sql = "SELECT " . $sqlCmd . " FROM produto WHERE idproduto='".(int)$single_cID."' LIMIT 1"; $result = $this->DB->FetchArray( $this->DB->Query( $sql ) ); $cName = $result['pName']; break; } $cName = $this->strip($cName); $return = $cName; $cID = $full_cPath; return $return; } # end function function get_categoria(&$cID){ $full_cPath = $this->get_full_cPath($cID, $single_cID); // full cPath needed for uniformity
switch(true){ default:
$sqlCmd = 'slug as pName'; $sql = "SELECT " . $sqlCmd . " FROM artigo WHERE idartigo='".(int)$single_cID."' LIMIT 1"; $result = $this->DB->FetchArray( $this->DB->Query( $sql ) ); $cName = $result['pName']; break; } $cName = $this->strip($cName); $return = $cName; $cID = $full_cPath; return $return; } # end function function get_produto(&$cID){ $full_cPath = $this->get_full_cPath($cID, $single_cID); // full cPath needed for uniformity
switch(true){ default:
$sqlCmd = 'url as pName'; $sql = "SELECT " . $sqlCmd . " FROM produto WHERE idproduto='".(int)$single_cID."' LIMIT 1"; $result = $this->DB->FetchArray( $this->DB->Query( $sql ) ); $cName = $result['pName']; break; } $cName = $this->strip($cName); $return = $cName; $cID = $full_cPath; return $return; } # end function
/** * Function to retrieve full cPath from category ID * @author Bobby Easland * @version 1.1 * @param mixed $cID Could contain cPath or single category_id * @param integer $original Single category_id passed back by reference * @return string Full cPath string */ function get_full_cPath($cID, &$original){ // if ( is_numeric(strpos($cID, '_')) ){ $temp = @explode('_', $cID); $original = $temp[sizeof($temp)-1]; return $cID; // } } # end function
/** * Recursion function to retrieve parent categories from category ID * @author Bobby Easland * @version 1.0 * @param mixed $categories Passed by reference * @param integer $idcategoria */ function GetParentCategories(&$categories, $idcategoria) { $sql = "SELECT parente FROM categoria WHERE idcategoria='" . (int)$idcategoria . "' limit 1"; $parent_categories_query = $this->DB->Query($sql); while ($parent_categories = $this->DB->FetchArray($parent_categories_query)) { if ($parent_categories['parente'] == 0) return true; $categories[sizeof($categories)] = $parent_categories['parente']; if ($parent_categories['parente'] != $idcategoria) { $this->GetParentCategories($categories, $parent_categories['parente']); } } } # end function
/** * Function to check if a value is NULL * @author Bobby Easland as abstracted from osCommerce-MS2.2 * @version 1.0 * @param mixed $value * @return boolean */ function not_null($value) { if (is_array($value)) { if (sizeof($value) > 0) { return true; } else { return false; } } else { if (($value != '') && (strtolower($value) != 'null') && (strlen(trim($value)) > 0)) { return true; } else { return false; } } } # end function
/** * Function to check if the params contains a idproduto * @author Bobby Easland * @version 1.1 * @param string $params * @return boolean */ function is_product_string($params){ if ( is_numeric(strpos('products_id', $params)) ){ return true; } else { return false; } } # end function
/** * Function to check if cPath is in the parameter string * @author Bobby Easland * @version 1.0 * @param string $params * @return boolean */ function is_cPath_string($params){ if ( preg_match('/cPath/i', $params) ){ return true; } else { return false; } } # end function
/** * Function to strip the string of punctuation and white space * @author Bobby Easland * @version 1.1 * @param string $string * @return string Stripped text. Removes all non-alphanumeric characters. */ function strip($string, $slug = false) {
//Setamos o localidade setlocale(LC_ALL, 'pt_BR');
//Se a flag 'slug' for verdadeira, transformamos o texto para lowercase if($slug) $string = strtolower($string);
// Código ASCII das vogais $ascii['a'] = range(224, 230); $ascii['A'] = range(192, 197); $ascii['e'] = range(232, 235); $ascii['E'] = range(200, 203); $ascii['i'] = range(236, 239); $ascii['I'] = range(204, 207); $ascii['o'] = array_merge(range(242, 246), array(240, 248)); $ascii['O'] = range(210, 214); $ascii['u'] = range(249, 252); $ascii['U'] = range(217, 220);
// Código ASCII dos outros caracteres $ascii['b'] = array(223); $ascii['c'] = array(231); $ascii['C'] = array(199); $ascii['d'] = array(208); $ascii['n'] = array(241); $ascii['y'] = array(253, 255);
//Fazemos um loop para criar as regras de troca dos caracteres acentuados foreach ($ascii as $key => $item) {
$acentos = ''; foreach ($item AS $codigo) $acentos .= chr($codigo); $troca[$key] = '/[' . $acentos . ']/mi';
}
//Aplicamos o replace com expressao regular $string = preg_replace(array_values($troca), array_keys($troca), $string);
//Se a flag 'slug' for verdadeira... if ($slug) {
//Troca tudo que não for letra ou número por um caractere ($slug) $string = preg_replace('/[^a-z0-9]/mi', $slug, $string);
//Tira os caracteres ($slug) repetidos $string = preg_replace('/' . $slug . '{2,}/mi', $slug, $string); $string = trim($string, $slug);
} $string_array = array( ' ', // 1 ',', // 2 "'", // 3 'ç', // 4 '"', // 5 '+', // 6 '*', // 7 '/', // 8 ':', // 9 '?', // 10 '!', // 11 $string ); $string_atualizada = array( '-', // 1 '', // 2 '', // 3 'c', // 4 '', // 5 '', // 6 '', // 7 '', // 8 '', // 9 '', // 10 '', // 11 $string ); $string=str_replace($string_array, $string_atualizada, $string); return trim(strtolower($string));
} /** * Function to translate a string * @author Bobby Easland * @version 1.0 * @param string $data String to be translated * @param array $parse Array of tarnslation variables * @return string */ function parse_input_field_data($data, $parse) { return strtr(trim($data), $parse); } /** * Function to output a translated or sanitized string * @author Bobby Easland * @version 1.0 * @param string $sting String to be output * @param mixed $translate Array of translation characters * @param boolean $protected Switch for htemlspecialchars processing * @return string */ function output_string($string, $translate = false, $protected = false) { if ($protected == true) { return htmlspecialchars($string); } else { if ($translate == false) { return $this->parse_input_field_data($string, array('"' => '"')); } else { return $this->parse_input_field_data($string, $translate); } } }
/** * Function to convert time for cache methods * @author Bobby Easland * @version 1.0 * @param string $expires * @return string */ function convert_time($expires){ //expires date interval must be spelled out and NOT abbreviated !! $expires = explode('/', $expires); switch( strtolower($expires[1]) ){ case 'seconds': $expires = mktime( @date("H"), @date("i"), @date("s")+(int)$expires[0], @date("m"), @date("d"), @date("Y") ); break; case 'minutes': $expires = mktime( @date("H"), @date("i")+(int)$expires[0], @date("s"), @date("m"), @date("d"), @date("Y") ); break; case 'hours': $expires = mktime( @date("H")+(int)$expires[0], @date("i"), @date("s"), @date("m"), @date("d"), @date("Y") ); break; case 'days': $expires = mktime( @date("H"), @date("i"), @date("s"), @date("m"), @date("d")+(int)$expires[0], @date("Y") ); break; case 'months': $expires = mktime( @date("H"), @date("i"), @date("s"), @date("m")+(int)$expires[0], @date("d"), @date("Y") ); break; case 'years': $expires = mktime( @date("H"), @date("i"), @date("s"), @date("m"), @date("d"), @date("Y")+(int)$expires[0] ); break; default: // if something fudged up then default to 1 month $expires = mktime( @date("H"), @date("i"), @date("s"), @date("m")+1, @date("d"), @date("Y") ); break; } # end switch( strtolower($expires[1]) ) return @date("Y-m-d H:i:s", $expires); } # end function convert_time()
/** * Function to check if the url is valid * @author Jack York * @version 1.1 */ function VerifyLink(&$pStop, $pStart) { $r1 = $this->base_url.$this->uri_parsed['path']; $p1 = strpos($_SERVER['REQUEST_URI'], $this->attributes['SEO_REDIRECT']['URI_PARSED']['path']); $r2 = substr($_SERVER['REQUEST_URI'], 0, $p1); if (strpos($r1, $r2) === FALSE) { return true; } /*** begin check for characters at end of string before .html ***/ $endStr = substr($this->uri_parsed['path'], $pStart + 3, $pStop - $pStart - 3); if (! preg_match("/^([0-9_]+)$/", $endStr)) { $parts = explode("_",$endStr); for ($p = 0; $p < count($parts); ++$p) { $parts[$p] = (int)$parts[$p]; } $newStr = implode("_", $parts); $this->uri_parsed['path'] = str_replace($endStr, $newStr, $this->uri_parsed['path']); $pStop = strpos($this->uri_parsed['path'], ".html"); //recalculate the end return true; } return false; }
/** * Function to check if it's a valid redirect page * @author Bobby Easland * @version 1.1 */ function check_seo_page(){ switch (true){ case (@in_array($this->uri_parsed['path'], $this->attributes['SEO_PAGES'])): $this->is_seopage = true; break; case ($this->attributes['SEO_ENABLED'] == 'false'): default: $this->is_seopage = false; break; } # end switch $this->attributes['SEO_REDIRECT']['IS_SEOPAGE'] = $this->is_seopage ? 'true' : 'false'; } # end function check_seo_page /** * Function to parse the path for old SEF URLs * @author Bobby Easland * @version 1.0 * @param string $path_info * @return array */ function parse_path($path_info){ $tmp = @explode('/', $path_info); if ( sizeof($tmp) > 2 ){ $container = array(); for ($i=0, $n=sizeof($tmp); $i<$n; $i++) { $container[] = $tmp[$i] . '=' . $tmp[$i+1]; $i++; } return @implode('&', $container); } else { return @implode('=', $tmp); } } # end function parse_path /** * Function to perform redirect * @author Bobby Easland * @version 1.0 */ function do_redirect(){ $p = @explode('&', $this->uri_parsed['query']);
foreach( $p as $index => $value ){ $tmp = @explode('=', $value); switch($tmp[0]){ case 'products_id': if ( $this->is_attribute_string($tmp[1]) ){ $pieces = @explode('{', $tmp[1]); $params[] = (tep_not_null($tmp[0]) ? $tmp[0] . '=' . $pieces[0] : ''); } else { $params[] = (tep_not_null($tmp[0]) ? $tmp[0] . '=' . $tmp[1] : ''); } break; default: $params[] = (tep_not_null($tmp[0]) ? $tmp[0] . '=' . $tmp[1] : ''); break; } } # end foreach( $params as $var => $value ) $params = ( sizeof($params) > 1 ? implode('&', $params) : $params[0] ); $url = $this->href_link($this->uri_parsed['path'], $params, 'NONSSL', false);
switch(true){ default: $this->attributes['SEO_REDIRECT']['REDIRECT_URL'] = $url; break; } # end switch } # end function do_redirect } # end class ?>
|