-
Notifications
You must be signed in to change notification settings - Fork 1
/
global.php
1746 lines (1388 loc) · 52.3 KB
/
global.php
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
<?php
/**
* Allomani E-Store v1.0
*
* @package Allomani.E-Store
* @version 1.0
* @copyright (c) 2006-2018 Allomani , All rights reserved.
* @author Ali Allomani <[email protected]>
* @link http://allomani.com
* @license GNU General Public License version 3.0 (GPLv3)
*
*/
$version_number = "1.0" ;
//-----------------------------
define("GLOBAL_LOADED",true);
define("MEMBER_SQL","member_sql");
//------------------------------
//----------- current work dir definition -------
define('CWD', (($getcwd = getcwd()) ? str_replace("\\","/",$getcwd) : '.'));
//-----------------------------
require(CWD . "/config.php") ;
$data_cat_cache = array();
$cat_fields_cache = array();
$cat_short_fields_cache = array();
//---------- custom error handler --------//
if($custom_error_handler){
$old_error_handler = set_error_handler("error_handler");
}
//----- remove slashes if magic quotes -----//
function stripslashes_deep($value){
return (is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value));
}
if(get_magic_quotes_gpc()){
$_POST = array_map('stripslashes_deep',$_POST);
$_GET = array_map('stripslashes_deep',$_GET);
$_COOKIE = array_map('stripslashes_deep',$_COOKIE);
}
//--------- extract variabls -----------------------
if (!empty($_POST)) {extract($_POST);}
if (!empty($_GET)) {extract($_GET);}
if (!empty($_ENV)) {extract($_ENV);}
//-----------------------------------------------------
//------ clean global vars ---------//
$_SERVER['QUERY_STRING'] = strip_tags($_SERVER['QUERY_STRING']);
$_SERVER['PHP_SELF'] = strip_tags($_SERVER['PHP_SELF']);
$_SERVER['REQUEST_URI'] = strip_tags($_SERVER['REQUEST_URI']);
$PHP_SELF = strip_tags($_SERVER['PHP_SELF']);
define("CUR_FILENAME",$PHP_SELF);
//---------------------- common variables types -----------------------
if($id && !is_array($id)){$id=intval($id);}
if($cat && !is_array($cat)){ $cat=intval($cat);}
//------------- timezone ------------------
if($default_timezone){date_default_timezone_set($default_timezone);}
//-------------------------------------------
//-------------------------------------------------------------------
require(CWD . "/includes/functions_db.php") ;
//---------------------------
db_connect($db_host,$db_username,$db_password,$db_name);
// ------------- lang dir -------------
if($global_lang=="arabic"){
$global_dir = "rtl" ;
$global_align = "right" ;
$global_align_x = "left";
}else{
$global_dir = "ltr" ;
$global_align = "left" ;
$global_align_x = "right" ;
}
//--------------- Load Phrases ---------------------
$phrases = array();
$qr = db_query("select * from store_phrases");
while($data = db_fetch($qr)){
$phrases["$data[name]"] = $data['value'] ;
}
//------------------------------
//-------- fields in short details count ----//
$data=db_qr_fetch("select count(*) as count from store_fields_sets where in_short_details=1 and active=1");
$short_details_fields_count = intval($data['count']);
//---------------------------------------------//
$actions_checks = array(
"$phrases[main_page]" => 'main' ,
"$phrases[browse_products]" => 'browse',
"$phrases[product_details]" => 'product_details',
"$phrases[the_news]" => 'news',
"$phrases[pages]" => 'pages',
"$phrases[the_search]" => 'search' ,
"$phrases[the_votes]" => 'votes',
"$phrases[the_statics]" => 'statics',
"$phrases[contact_us]" => 'contactus'
);
$permissions_checks = array(
"$phrases[hot_items]" => 'hot_items' ,
"$phrases[the_templates]" => 'templates' ,
"$phrases[the_news]" => 'news' ,
"$phrases[the_phrases]" => 'phrases' ,
"$phrases[the_banners]" => 'adv',
"$phrases[the_votes]" => 'votes',
"$phrases[the_clients]" => 'clients',
"$phrases[the_orders]" => 'orders',
"$phrases[orders_status]" => 'orders_status'
);
$banners_places = array(
"$phrases[offers_menu]"=>'offer',
"$phrases[bnr_header]"=> 'header',
"$phrases[bnr_footer]"=> 'footer',
"$phrases[bnr_open]" => 'open',
"$phrases[bnr_close]" => 'close',
"$phrases[bnr_menu]"=> 'menu'
);
$orderby_checks = array(
"$phrases[the_date]" => 'id',
"$phrases[the_price]" => 'price',
"$phrases[the_name]" => 'name',
"$phrases[availability]" => 'available'
);
$settings = array();
//--------------- Get Settings --------------------------
function load_settings(){
global $settings ;
$qr = db_query("select * from store_settings");
while($data = db_fetch($qr)){
$settings["$data[name]"] = $data['value'] ;
}
}
//------------------ Load Settings ---------
load_settings();
$sitename = $settings['sitename'] ;
$section_name = $settings['section_name'] ;
$siteurl = "http://$_SERVER[HTTP_HOST]" ;
$script_path = trim(str_replace(rtrim(str_replace('\\', '/',$_SERVER['DOCUMENT_ROOT']),"/"),"",CWD),"/");
$scripturl = $siteurl . iif($script_path,"/".$script_path,"");
$upload_types = explode(',',str_replace(" ","",$settings['uploader_types']));
$mailing_email = $settings['mailing_email'];
//------ validate styleid functon ------
function is_valid_styleid($styleid){
if(is_numeric($styleid)){
$data = db_qr_fetch("select count(id) as num from store_templates_cats where id='$styleid' and selectable=1");
if($data['num']){
return true;
}else{
return false;
}
}else{
return false;
}
}
//----- check if valid styleid -------
$styleid=(isset($styleid) ? intval($styleid) : get_cookie("styleid"));
if(!is_valid_styleid($styleid)){
$styleid = $settings['default_styleid'];
if(!is_valid_styleid($styleid)){
$styleid = 1;
}
}
//----- get style settings ----//
$data_style = db_qr_fetch("select images from store_templates_cats where id='$styleid'");
$style['images'] = iif($data_style['images'],$data_style['images'],"images");
set_cookie('styleid', intval($styleid));
//----------- Load links -----------
$qr=db_query("select * from store_templates where name like 'links_%' and cat='$styleid'");
while($data=db_fetch($qr)){
$links[$data['name']] = $data['content'];
}
//------- theme file ---------
require(CWD . "/includes/functions_themes.php") ;
//---------
require(CWD . "/includes/functions_cart.php") ;
require(CWD . "/includes/functions_clients.php") ;
init_members_connector();
require(CWD . '/includes/class_tabs.php') ;
require(CWD . '/includes/class_security_img.php');
$sec_img = new sec_img_verification();
//-------- counter file ---------
require(CWD . "/counter.php");
function if_admin($dep="",$continue=0){
global $user_info,$phrases ;
if(!$dep){
if($user_info['groupid'] != 1){
if(!$continue){
print_admin_table("<center>$phrases[access_denied]</center>");
die();
}
return false;
}else{
return true;
}
}else{
if($user_info['groupid'] != 1){
$data=db_qr_fetch("select * from store_user where id='$user_info[id]'");
$prm_array = explode(",",$data['cp_permisions']);
if(!in_array($dep,$prm_array)){
if(!$continue){
print_admin_table("<center>$phrases[access_denied]</center>");
die();
}
return false;
}else{
return true;
}
}else{
return true;
}
}
}
//-------------------------------------------------------------
function get_image($src,$default="",$path=""){
global $style;
if($src){
return $path.$src ;
}else{
if($default){
return $path.$default;
}else{
return $path."$style[images]/no_pic.gif" ;
}
}
}
//------------ copyrights text ---------------------
function print_copyrights(){
global $_SERVER,$settings,$copyrights_lang ;
if(COPYRIGHTS_TXT_MAIN){
if($copyrights_lang == "arabic"){
print "<p align=center>ÌãíÚ ÇáÍÞæÞ ãÍÝæÙÉ áÜ :
<a target=\"_blank\" href=\"http://$_SERVER[HTTP_HOST]\">$settings[copyrights_sitename]</a> © " . date('Y') . " <br>
ÈÑãÌÉ <a target=\"_blank\" href=\"http://allomani.com/\"> ÇááæãÇäí ááÎÏãÇÊ ÇáÈÑãÌíÉ </a> © 2009";
}else{
print "<p align=center>Copyright © ". date('Y')." <a target=\"_blank\" href=\"http://$_SERVER[HTTP_HOST]\">$settings[copyrights_sitename]</a> - All rights reserved <br>
Programmed By <a target=\"_blank\" href=\"http://allomani.com/\"> Allomani </a> © 2009";
}
}
}
//---------------------- Read File ------------------------
function read_file($filename){
$fn = fopen($filename,"r");
$fdata = fread($fn,filesize($filename));
fclose($fn);
return $fdata ;
}
//---------- validate email --------
function check_email_address($email) {
if(filter_var($email, FILTER_VALIDATE_EMAIL) === false){
return false;
}else{
return true;
}
}
/*
function check_email_address($email) {
// First, we check that there's one @ symbol, and that the lengths are right
if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
// Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
return false;
}
// Split it into sections to make life easier
$email_array = explode("@", $email);
$local_array = explode(".", $email_array[0]);
for ($i = 0; $i < sizeof($local_array); $i++) {
if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {
return false;
}
}
if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name
$domain_array = explode(".", $email_array[1]);
if (sizeof($domain_array) < 2) {
return false; // Not enough parts to domain
}
for ($i = 0; $i < sizeof($domain_array); $i++) {
if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {
return false;
}
}
}
return true;
} */
//---------------------------------------------
function execphp_fix_tag($match)
{
// replacing WPs strange PHP tag handling with a functioning tag pair
$output = '<?php'. $match[2]. '?>';
return $output;
}
//------------------------------------------------------------
function run_php($content)
{
$content = str_replace(array("‘", "’"), "'",$content);
$content = str_replace(array("”", "“"), '"', $content);
$content = str_replace("″", '"', $content);
$content = str_replace("′", "'", $content);
// for debugging also group unimportant components with ()
// to check them with a print_r($matches)
$pattern = '/'.
'(?:(?:<)|(\[))[\s]*\?php'. // the opening of the <?php or [?php tag
'(((([\'\"])([^\\\5]|\\.)*?\5)|(.*?))*)'. // ignore content of PHP quoted strings
'\?(?(1)\]|>)'. // the closing ? > or ?] tag
'/is';
$content = preg_replace_callback($pattern, 'execphp_fix_tag', $content);
// to be compatible with older PHP4 installations
// don't use fancy ob_XXX shortcut functions
ob_start();
eval(" ?> $content ");
$output = ob_get_contents();
ob_end_clean();
print $output;
}
//---------------------------- Admin Login Function ---------------------------------
$user_info = array();
function check_login_cookies(){
global $user_info;
$user_info['username'] = get_cookie('admin_username');
$user_info['password'] = get_cookie('admin_password');
$user_info['id'] = intval(get_cookie('admin_id'));
if($user_info['id']){
$qr = db_query("select * from store_user where id='$user_info[id]'");
if(db_num($qr)){
$data = db_fetch($qr);
if($data['username'] == $user_info['username'] && md5($data['password']) == $user_info['password']){
$user_info['email'] = $data['email'];
$user_info['groupid'] = $data['group_id'];
return true ;
}else{
return false ;
}
}else{
return false ;
}
}else{
return false ;
}
}
//--------- Generate Random String -----------
function rand_string($length = 8){
// start with a blank password
$password = "";
// define possible characters
$possible = "0123456789bcdfghjkmnpqrstvwxyz";
// set up a counter
$i = 0;
// add random characters to $password until $length is reached
while ($i < $length) {
// pick a random character from the possible ones
$char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
// we don't want this character if it's already in the password
if (!strstr($password, $char)) {
$password .= $char;
$i++;
}
}
// done!
return $password;
}
//--------------------------------- Check Functions ---------------------------------
function check_safe_functions($condition_value){
global $safe_functions,$phrases ;
if (preg_match_all('#([a-z0-9_{}$>-]+)(\s|/\*.*\*/|(\#|//)[^\r\n]*(\r|\n))*\(#si', $condition_value, $matches))
{
$functions = array();
foreach($matches[1] AS $key => $match)
{
if (!in_array(strtolower($match), $safe_functions) && function_exists(strtolower($match)))
{
$funcpos = strpos($condition_value, $matches[0]["$key"]);
$functions[] = array(
'func' => stripslashes($match),
// 'usage' => substr($condition_value, $funcpos, (strpos($condition_value, ')', $funcpos) - $funcpos + 1)),
);
}
}
if (!empty($functions))
{
unset($safe_functions[0], $safe_functions[1], $safe_functions[2]);
foreach($functions AS $error)
{
$errormsg .= "$phrases[err_function_usage_denied]: <code>" . html_encode_chars($error['func']) . "</code>
<br>\n";
}
echo "<p dir=rtl>$errormsg</p>";
return false ;
}else{
return true ;
}
}
return true ;
}
//---------------------- Compile Safe Tempalte -------------------
function compile_template($template)
{
global $safe_functions ;
// $orig_template = $template;
// $template = addslashes($template);
// $template = process_template_conditionals($template) ;
// $template = str_replace('\\\\$', '\\$', $template);
if(check_safe_functions($template)){
run_php($template);
}
}
//---------------------- Send Email Function -------------------
function send_email($from_name,$from_email,$to_email,$subject,$msg,$html=0,$encoding=""){
global $PHP_SELF,$smtp_settings,$settings ;
$from_name = html_encode_chars($from_name);
$from_email = html_encode_chars($from_email);
$to_email = html_encode_chars($to_email);
$subject = html_encode_chars($subject);
// $msg=htmlspecialchars($msg);
if(!$encoding){$encoding = $settings['site_pages_encoding'];}
// $from = "$from_name <$from_email>" ;
$from = "=?".$encoding."?B?".base64_encode($from_name)."?= <$from_email>" ;
$subject = "=?".$encoding."?B?".base64_encode($subject)."?=";
$mailHeader = 'From: '.$from.' '."\r\n";
$mailHeader .= "Reply-To: $from_email\r\n";
$mailHeader .= "Return-Path: $from_email\r\n";
$mailHeader .= "To: $to_email\r\n";
$mailheader.="MIME-Version: 1.0\r\n";
$mailHeader .= "Content-Type: ".iif($html,"text/html","text/plain")."; charset=".$encoding."\r\n";
if($smtp_settings['enable']){
$mailHeader .= "Subject: $subject\r\n";
}
$mailHeader .= "Date: ".strftime("%a, %d %b %Y %H:%M:%S %Z")."\r\n";
$mailHeader .= "X-EWESITE: Allomani\r\n";
$mailHeader .= "X-Mailer: PHP/".phpversion()."\r\n";
$mailHeader .= "X-Mailer-File: "."http://".$_SERVER['HTTP_HOST'].($script_path ? "/".$script_path:"").$PHP_SELF."\r\n";
$mailHeader .= "X-Sender-IP: {$_SERVER['REMOTE_ADDR']}\r\n";
if($smtp_settings['enable']){
if(!class_exists("smtp_class")){
require_once(CWD ."/includes/class_smtp.php");
}
$smtp=new smtp_class;
$smtp->host_name=$smtp_settings['host_name'];
$smtp->host_port=$smtp_settings['host_port'];
$smtp->ssl=$smtp_settings['ssl'];
$smtp->localhost="localhost"; /* Your computer address */
$smtp->direct_delivery=0; /* Set to 1 to deliver directly to the recepient SMTP server */
$smtp->timeout=$smtp_settings['timeout']; /* Set to the number of seconds wait for a successful connection to the SMTP server */
$smtp->data_timeout=0; /* Set to the number seconds wait for sending or retrieving data from the SMTP server.
Set to 0 to use the same defined in the timeout variable */
$smtp->debug=$smtp_settings['debug']; /* Set to 1 to output the communication with the SMTP server */
$smtp->html_debug=1; /* Set to 1 to format the debug output as HTML */
if($smtp_settings['username'] && $smtp_settings['password']){
$smtp->pop3_auth_host=$smtp_settings['host_name']; /* Set to the POP3 authentication host if your SMTP server requires prior POP3 authentication */
$smtp->user=$smtp_settings['username']; /* Set to the user name if the server requires authetication */
$smtp->password=$smtp_settings['password']; /* Set to the authetication password */
$smtp->realm=""; /* Set to the authetication realm, usually the authentication user e-mail domain */
}
$smtp->workstation=""; /* Workstation name for NTLM authentication */
$smtp->authentication_mechanism=""; /* Specify a SASL authentication method like LOGIN, PLAIN, CRAM-MD5, NTLM, etc..
Leave it empty to make the class negotiate if necessary */
$mailResult = $smtp->SendMessage(
$from_email,
array(
$to_email
),
array(
$mailHeader
),
$msg,0);
if($mailResult){
return true ;
}else{
if($smtp_settings['show_errors']){
print "<b>SMTP Error: </b> ".$smtp->error ."<br>";
}
return false;
}
}else{
$mailResult = @mail($to_email,$subject,$msg,$mailHeader);
if($mailResult){
return true ;
}else{
return false;
}
}
}
//----------- Get Hooks ------------
function get_plugins_hooks(){
$hooklocations = array();
require_once(CWD . '/includes/class_xml.php');
$handle = opendir(CWD . '/xml/');
while (($file = readdir($handle)) !== false)
{
if (!preg_match('#^hooks_(.*).xml$#i', $file, $matches))
{
continue;
}
$product = $matches[1];
$phrased_product = $products[($product ? $product : 'allomani')];
if (!$phrased_product)
{
$phrased_product = $product;
}
$xmlobj = new XMLparser(false, CWD . "/xml/$file");
$xml = $xmlobj->parse();
if (!is_array($xml['hooktype'][0]))
{
// ugly kludge but it works...
$xml['hooktype'] = array($xml['hooktype']);
}
foreach ($xml['hooktype'] AS $key => $hooks)
{
if (!is_numeric($key))
{
continue;
}
//$phrased_type = isset($vbphrase["hooktype_$hooks[type]"]) ? $vbphrase["hooktype_$hooks[type]"] : $hooks['type'];
$phrased_type = $hooks['type'];
$hooktype = $phrased_product . ' : ' . $phrased_type;
$hooklocations["$hooktype"] = array();
if (!is_array($hooks['hook']))
{
$hooks['hook'] = array($hooks['hook']);
}
foreach ($hooks['hook'] AS $hook)
{
$hookid = (is_string($hook) ? $hook : $hook['value']);
$hooklocations["$hooktype"]["$hookid"] = $hookid;
}
}
}
ksort($hooklocations);
return $hooklocations ;
}
//--------- Get used hooks List -----------
$qr = db_query("select hookid from store_hooks where active='1'");
while($data = db_fetch($qr)){
$used_hooks[] = $data['hookid'];
}
unset($qr,$data);
//-------------- compile hook --------------
function compile_hook($hookid){
global $used_hooks;
if(is_array($used_hooks)){
if(in_array($hookid,$used_hooks)){
$qr = db_query("select code from store_hooks where hookid='".db_escape($hookid)."' and active='1' order by ord asc");
if(db_num($qr)){
while($data=db_fetch($qr)){
run_php($data['code']);
}
}else{
return false;
}
}else{
return false;
}
}else{
return false;
}
}
//--------- iif expression ------------
function iif($expression, $returntrue, $returnfalse = '')
{
return ($expression ? $returntrue : $returnfalse);
}
//------- set cookies function -----------
function set_cookie($name,$value=""){
global $cookies_prefix,$cookies_timemout,$cookies_path,$cookies_domain;
$name = $cookies_prefix . $name;
$k_timeout = time() + (60 * 60 * 24 * intval($cookies_timemout));
setcookie($name, $value, $k_timeout,$cookies_path,$cookies_domain);
}
//--------- get cookies funtion ---------
function get_cookie($name){
global $cookies_prefix,$_COOKIE;
$name = $cookies_prefix . $name;
return $_COOKIE[$name];
}
//--------- array replace --------
if(!function_exists('array_replace')){
function array_replace($tofind, $toreplace,$a){
if(!is_array($a)){$a = array($a);}
for($i=0;$i<count($a);$i++){
$a[$i] = str_replace($tofind,$toreplace,$a[$i]);
}
return $a ;
}
}
//---------- Flush Function -------------
function data_flush()
{
static $output_handler = null;
if ($output_handler === null)
{
$output_handler = @ini_get('output_handler');
}
if ($output_handler == 'ob_gzhandler')
{
// forcing a flush with this is very bad
return;
}
flush();
if (PHP_VERSION >= '4.2.0' AND function_exists('ob_flush') AND function_exists('ob_get_length') AND ob_get_length() !== false)
{
@ob_flush();
}
else if (function_exists('ob_end_flush') AND function_exists('ob_start') AND function_exists('ob_get_length') AND ob_get_length() !== FALSE)
{
@ob_end_flush();
@ob_start();
}
}
//----------- select row ------------
function print_select_row($name, $array, $selected = '', $options="" , $size = 0, $multiple = false,$same_values=false)
{
global $vbulletin;
$select = "<select name=\"$name\" id=\"sel_$name\"" . iif($size, " size=\"$size\"") . iif($multiple, ' multiple="multiple"') . iif($options , " $options").">\n";
$select .= construct_select_options($array, $selected,$same_values);
$select .= "</select>\n";
print $select;
}
function construct_select_options($array, $selectedid = '',$same_values=false)
{
if (is_array($array))
{
$options = '';
foreach($array AS $key => $val)
{
if (is_array($val))
{
$options .= "\t\t<optgroup label=\"" . $key . "\">\n";
$options .= construct_select_options($val, $selectedid, $tabindex, $htmlise);
$options .= "\t\t</optgroup>\n";
}
else
{
if (is_array($selectedid))
{
$selected = iif(in_array($key, $selectedid), ' selected="selected"', '');
}
else
{
$selected = iif($key == $selectedid, ' selected="selected"', '');
}
$options .= "\t\t<option value=\"".($same_values ? $val : $key). "\"$selected>" . $val . "</option>\n";
}
}
}
return $options;
}
//---------- print text row ----------
function print_text_row($name,$value="",$size="",$dir="",$options=""){
print "<input type=text name=\"$name\"".iif($value," value=\"$value\"").iif($size," size=\"$size\"").iif($dir," dir=\"$dir\"").iif($options," $options").">";
}
//--------- print admin table -------------
function print_admin_table($content,$width="50%",$align="center"){
print "<center><table class=grid width='$width'><tr><td align='$align'>$content</td></tr></table></center>";
}
//-------------- Get Remote filesize --------
function fetch_remote_filesize($url)
{
// since cURL supports any protocol we should check its http(s)
preg_match('#^((http|ftp)s?):\/\/#i', $url, $check);
if (ini_get('allow_url_fopen') != 0 AND $check[1] == 'http')
{
$urlinfo = @parse_url($url);
if (empty($urlinfo['port']))
{
$urlinfo['port'] = 80;
}
if ($fp = @fsockopen($urlinfo['host'], $urlinfo['port'], $errno, $errstr, 30))
{
fwrite($fp, 'HEAD ' . $url . " HTTP/1.1\r\n");
fwrite($fp, 'HOST: ' . $urlinfo['host'] . "\r\n");
fwrite($fp, "Connection: close\r\n\r\n");
while (!feof($fp))
{
$headers .= fgets($fp, 4096);
}
fclose ($fp);
$headersarray = explode("\n", $headers);
foreach($headersarray as $header)
{
if (stristr($header, 'Content-Length') !== false)
{
$matches = array();
preg_match('#(\d+)#', $header, $matches);
return sprintf('%u', $matches[0]);
}
}
}
}
else if (false AND !empty($check) AND function_exists('curl_init') AND $ch = curl_init())
{
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD');
/* Need to enable this for self signed certs, do we want to do that?
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
*/
$header = curl_exec($ch);
curl_close($ch);
if ($header !== false)
{
preg_match('#Content-Length: (\d+)#i', $header, $matches);
return sprintf('%u', $matches[1]);
}
}
return false;
}
//--------------- Get file Extension ----------
function file_extension($filename)
{
return substr(strrchr($filename, '.'), 1);
}
//-------------- Get Dir Files List ----------
function get_files($dir,$allowed_types="",$subdirs_search=1) {
$dir = (substr($dir,-1,1)=="/" ? substr($dir,0,strlen($dir)-1) : $dir);
if($dh = opendir($dir)) {
$files = Array();
$inner_files = Array();
while($file = readdir($dh)) {
if($file != "." && $file != ".." && $file[0] != '.') {
if(is_dir($dir . "/" . $file) && $subdirs_search) {
$inner_files = get_files($dir . "/" . $file,$allowed_types);
if(is_array($inner_files)) $files = array_merge($files, $inner_files);
}else{
$fileinfo= pathinfo($dir . "/" . $file);
$imtype = $fileinfo["extension"];
if(is_array($allowed_types)){
if(in_array($imtype,$allowed_types)){
$files[] = $dir . "/" . $file;
}
}else{
$files[] = $dir . "/" . $file;
}
}
}
}
closedir($dh);
return $files;
}
}
//----------- Number Format --------------------
function convert_number_format($number, $decimals = 0, $bytesize = false, $decimalsep = null, $thousandsep = null)
{
$type = '';
if (empty($number))
{
return 0;
}
else if (preg_match('#^(\d+(?:\.\d+)?)(?>\s*)([mkg])b?$#i', trim($number), $matches))
{
switch(strtolower($matches[2]))
{
case 'g':
$number = $matches[1] * 1073741824;
break;
case 'm':
$number = $matches[1] * 1048576;
break;
case 'k':
$number = $matches[1] * 1024;
break;
default:
$number = $matches[1] * 1;
}
}
if ($bytesize)
{
if ($number >= 1073741824)
{
$number = $number / 1073741824;
$decimals = 2;
$type = " GB";
}
else if ($number >= 1048576)
{
$number = $number / 1048576;
$decimals = 2;
$type = " MB";
}
else if ($number >= 1024)
{
$number = $number / 1024;
$decimals = 1;
$type = " KB";
}
else
{
$decimals = 0;
$type = " Byte";
}
}
if ($decimalsep === null)
{
// $decimalsep = ".";
}
if ($thousandsep === null)
{
// $thousandsep = ",";
}
if($decimalsep && $thousandsep){
return str_replace('_', ' ', number_format($number, $decimals, $decimalsep, $thousandsep)) . $type;
}else{
return str_replace('_', ' ', round($number,$decimals)) . $type;
}
}
//--------------------- preview Text ------------------------------------
function getPreviewText($text) {
global $preview_text_limit ;
// Strip all tags
$desc = strip_tags(html_entity_decode($text), "<a><em>");
$charlen = 0; $crs = 0;
if(strlen_HTML($desc) == 0)
$preview = substr($desc, 0, $preview_text_limit);
else
{
$i = 0;
while($charlen < 80)
{
$crs = strpos($desc, " ", $crs)+1;
$lastopen = strrpos(substr($desc, 0, $crs), "<");
$lastclose = strrpos(substr($desc, 0, $crs), ">");
if($lastclose > $lastopen)
{
// we are not in a tag
$preview = substr($desc, 0, $crs);
$charlen = strlen_noHTML($preview);
}
$i++;
}
}
return trim($preview) ;
}