-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
3454 lines (3453 loc) · 204 KB
/
Copy pathindex.php
File metadata and controls
3454 lines (3453 loc) · 204 KB
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
/*******************************************************************
| Raha TinyCMS v3.6.0
| ------------------------------------------------
| @copyright: (C) 2006-2008 Raha Group, All Rights Reserved
| @license: CC-BY-SA-4.0 <https://creativecommons.org/licenses/by-sa/4.0>
| @author: Mahdi NezaratiZadeh <HTTPS://Raha.Group>
| @since: 2006-03-01 00:00:00 GMT+0330 - 2008-06-06 18:57:33 GMT+0330
********************************************************************/
session_start();
!extension_loaded("zlib") or ob_start("ob_gzhandler");
error_reporting(E_ALL^E_NOTICE);
ini_set("display_errors", false);
ini_set("html_errors", false);
ini_set("error_reporting", E_ALL^E_NOTICE);
ini_set("max_execution_time", 180);
define("Raha", "3.6.0");
define("IP", IP());
define("Time", time());
define("MicroTime", microtime());
define("Now", gmdate("Y-m-d H:i:s"));
if (get_magic_quotes_gpc())
$_POST = killmq($_POST);
$_POST = addmq($_POST);
if (file_exists("configuration.php"))
require "configuration.php";
else {
$parser = new XMLParser(file_get_contents("data.xml"));
$tree = $parser->get_tree();
eval($tree["data"]["script"]["value"]);
}
$DB = new DataBase($database_host, $database_username, $database_password, $database_name, $table_prefix);
if (config("site->cache"))
header("Pragma: cache");
else {
header("Pragma: no-cache");
header("Cache-Control: no-cache");
}
header("Content-type: text/html; charset=".config("site->charset"));
$CFG = $pageTheme = array();
$mainScrip = $CPScript = "";
if (user("login")) {
$id = $_SESSION["user id"] = cache("get", "CMS", "loged in");
if (empty($_SESSION["last login"])) {
$_SESSION["last login"] = user("last login");
$_SESSION["last login ip"] = user("last login ip");
}
$DB->update($DB->user, array("last login ip" => IP, "last login" => Time), "id=$id");
if (isset($_SESSION["last time"]))
mysql_query("update $DB->user set `time online`=`time online`+'".(Time-$_SESSION["last time"])."' where id=$id");
$_SESSION["last time"] = Time;
$CP = new ControlPanel(user("level"));
$CP->access = array("تنظيمات" => "configuration", "شکلکها" => "emoticon", "اعلان" => "announcement", "کلمات ناپسند" => "bad word", "افراد اخراج شده" => "banned ip", "تگها" => "tag", "نظرسنجي" => "poll", "دفتر يادبود" => "guestbook", "پيوند" => "link", "وارد کردن پيوند" => "import link", "دسته بندي" => "category", "خبرنامه" => "newsletter", "پوسته" => "theme", "پلاگين" => "plugin", "کاربر" => "user", "مشخصات خود" => "profile", "تصاوير کاربران" => "user avatar", "سطح" => "level", "نويسنده" => "writer", "ويرايشگر" => "editor", "وارد کردن پست" => "import post", "نظرات" => "comment", "صندوق پيام" => "message", "پشتيبان پايگاه دادهها" => "backup", "شمارنده" => "counter", "وضعيت سايت" => "site state", "مردمي" => "demo");
}
define("logedIn", intval(isset($_SESSION["user id"]) ? $_SESSION["user id"] : 0));
$Jalali = new Jalali(config("site->date format"), config("site->time format"), config("site->time zone"));
$RQE = new Request();
$RQE->result();
$SC = new Cache;
function killmq($v) {
return is_array($v) ? array_map("killmq", $v) : stripslashes($v);
}
function addmq($a) {
foreach ($a as $k => $v)
$a[$k] = is_array($v) ? addmq($v) : str_replace(array("ك", "ي"), array("ک", "ی"), addslashes($v));
return $a;
}
function cache($action, $group, $key, $data = "") {
global $cache;
switch ($action) {
case "set":
$cache[$group][$key] = $data;
break;
case "get":
return $cache[$group][$key];
}
}
function url($q='') {
return "http://$_SERVER[SERVER_NAME]$_SERVER[REQUEST_URI]".($q == '' ? '' : ($_SERVER['REQUEST_URI'] == '/' ? '?' : '&').$q);
}
function generation($precision=3) {
$M = explode(" ", microtime());
$m = explode(" ", MicroTime);
return substr(number_format(($M[1]+$M[0])-($m[1]+$m[0]), $precision), 0, 5);
}
function mydate($t, $c=0) {
return $c ? strtotime($t) : date("Y-m-d H:i:s", $t);
}
function my_date($m="now", $c=0) {
global $Jalali;
return $Jalali->date($Jalali->date_format, $c ? strtotime($m) : $m);
}
function my_time($m = "now", $c=0) {
global $Jalali;
return $Jalali->date($Jalali->time_format, $c ? strtotime($m) : $m);
}
function HTML($content, $action = "") {
if ($action == "source")
return htmlspecialchars(str_replace(array("<br />", " "), array("\n", "\t"), $content));
elseif ($action == "convert")
return str_replace(array("\r\n", "\r", "\n", "\t"), array("\n", "\n", "<br />", " "), htmlspecialchars($content));
else {
foreach ((array)config("tag") as $tag => $replace)
$content = preg_replace($tag, $replace, $content);
$content = strtr($content, (array)config("bad word"));
empty($content) or $content = emoticons($content);
$content = preg_replace(array("/&#([0-9]+);/e"), array('chr("\\1")'), $content);
return preg_replace("/&#[Xx]([0-9A-Fa-f]+);/e", 'chr(hexdec("\\1"))', $content);
}
}
function cookie($a, $e=null) {
$c = config("cookie");
$e = Time+(empty($e) ? $c["expires"] : $e);
foreach ($a as $k => $v)
setcookie($k, $v, $e, $c["path"], $c["domain"], $c["secure"]);
}
function compress($c, $n, $l=9) {
if (strtolower(ini_get("zlib.output_compression")) == "on") {
$r = "\x1f\x8b\x08\x00\x00\x00\x00\x00".substr(gzcompress($c, $l), 0, -4).pack("V", crc32($c)).pack("V", strlen($c));
header('Content-Type: application/x-gzip; name="'.$n.'.gz"');
header('Content-disposition: attachment; filename="'.$n.'.gz"');
} else {
$r = $c;
header('Content-Type: text/x-delimtext; name="'.$n.'.txt"');
header('Content-disposition: attachment; filename="'.$n.'.txt"');
}
header("Content-Length: ".strlen($r));
return $r;
}
function IP() {
$ip_address = empty($_SERVER["HTTP_X_FORWARDED_FOR"]) ? $_SERVER["REMOTE_ADDR"] : $_SERVER["HTTP_X_FORWARDED_FOR"];
strpos($ip_address, ",") === false or list($ip_address, ) = explode(",", $ip_address);
return $ip_address;
}
function remote_fopen($uri) {
if (ini_get("allow_url_fopen")) {
$fp = fopen($uri, "r");
if (!$fp)
return false;
$l = "";
while ($r = fread($fp, 4194304))
$l .= $r;
fclose($fp);
return $l;
} elseif (function_exists("curl_init")) {
$h = curl_init();
curl_setopt($h, CURLOPT_URL, $uri);
curl_setopt($h, CURLOPT_CONNECTTIMEOUT, 1);
curl_setopt($h, CURLOPT_RETURNTRANSFER, 1);
$b = curl_exec($h);
curl_close($h);
return $b;
} else
return false;
}
function bulk($w) {
for ($s=array("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"), $i=0; $w/1024>1; $i++)
$w /= 1024;
return round($w, 3)." ".$s[$i];
}
function xmlrpc($server) {
$client = new IXR($server);
$url = config("site->url");
$title = config("site->title");
return $client->query('weblogUpdates.extendedPing', $title, $url, $url.'/rss.xml', $url.'/atom.xml') ? "با موفقیت انجام شد (بهترین نوع)" : ($client->query('weblogUpdates.ping', $title, $url) ? "با موفقیت انجام شد" : "متاسفانه انجام نشد");
}
function emoticons($action = "print emoticons") {
global $TPL;
$data = config("emoticon->data");
$path = config("emoticon->path");
switch ($action) {
case "print emoticons":
foreach ($data["code"] as $k => $v)
if ($data["state"][$k] == 1)
$emoticons .= ' <a href="javascript:void(0)" onclick="javascript:insertCode(\''.str_replace('"', """, $v).'\');"><img src="'.$path.$data["url"][$k].'" border=0 title="'.$data["description"][$k].'" alt="'.$data["description"][$k].'"></a>';
else
$more = 1;
if ($more)
$emoticons .= $v=$TPL->get("emoticons") ? $v : '<br><a href="#" onclick="window.open(\'emoticon.html\', \'_blank\', \'width=300, height=300, status=yes, scrollbars=yes, resizable=yes\');">بيشتر</a>';
return $emoticons;
default:
if (config("emoticon->convert") == 0)
return $action;
$a = array();
foreach ($data["code"] as $k => $v)
$a[$v] = '<img src="'.$path.$data["url"][$k].'" border=0 alt="'.$data["description"][$k].'" />';
uksort($a, create_function('$a,$b', 'return strlen($b)-strlen($a);'));
return strtr($action, $a);
}
}
function configure($a) {
if ($v=cache("get", "configuration", $a[0]))
foreach ($a as $i => $m)
$v = $i>0 ? $v[$m] : $v;
else {
global $DB;
$q = mysql_query("select value from $DB->configuration where name='$a[0]'");
if (mysql_num_rows($q)) {
$v = mysql_result($q, 0);
if (is_serialized($v)) {
$v = unserialize($v);
cache("set", "configuration", $a[0], $v);
foreach ($a as $i => $m)
$v = $i>0 ? $v[$m] : $v;
}
} else
$v = 0;
}
return $v;
}
function set_cfg($n, $V) {
global $DB;
if (is_array($V))
foreach ($V as $k => $v) {
unset($V[$k]);
$V[stripslashes($k)] = stripslashes($v);
}
$DB->update($DB->configuration, array("value" => $DB->escape(is_array($V) ? serialize($V) : $V)), "name='$n'");
}
function config($name, $value=null) {
global $DB;
$ID = explode("->", $name);
if ($value == null) {
if ($v=cache("get", "configuration", $name))
return $v;
$K = $ID[1];
$v = user("login") && $ID[0] == "site" && ($K == "date format" || $K == "time format" || $K == "time zone" || $K == "theme") ? mysql_result(mysql_query("select `$K` from $DB->user where id=".logedIn), 0) : configure($ID);
cache("set", "configuration", $name, $v);
return $v;
} elseif ($name == "delete") {
$ID = explode("->", $value);
if (count($ID) == 1) {
mysql_query("delete from $DB->configuration where name='$value'");
return "تنظيم $value حذف شد.";
} else {
foreach ($ID as $i => $k)
$keys .= ($i != 0) ? "[\"$k\"]" : "";
$var = str_replace(" ", "_", $ID[0]);
$$var = config($ID[0]);
eval('unset($'.$var.$keys.');');
config($ID[0], $$var);
return "آيتم $value حذف شد.";
}
} elseif ($name == "change")
return preg_replace("/configuration\((.*?)\)/ise", 'config("$1");', $value);
else {
$value = (count($ID) == 1 && (is_array($value) || is_object($value) || is_serialized($value))) ? serialize($value) : $value;
if (mysql_num_rows($q=mysql_query("select value from $DB->configuration where name='$ID[0]'"))) {
if (count($ID)>1) {
$values = unserialize(mysql_result($q, 0));
foreach ($ID as $index => $key)
$keys .= ($index > 0) ? "[\"$key\"]" : "";
if (is_array($value) || is_object($value) || is_serialized($value)) {
eval('$values'.$keys.' = array();');
foreach ($value as $k => $v)
$data .= '$values'.$keys."[\"$k\"] = '".$DB->escape($v)."';";
} else {
$data = '$values'.$keys.' = '."'".$DB->escape($value)."';";
}
eval($data);
$value = serialize($values);
} else
$value = $DB->escape($value);
mysql_query("update $DB->configuration set value='$value' where name='$ID[0]'");
return "تنظيم $name به روزرساني شد";
} else {
if (count($ID)>1) {
foreach ($ID as $i => $k)
$K .= $i>0 ? "[\"$k\"]" : "";
eval('$V'.$K.' = "'.addslashes($v).'";');
$value = serialize($V);
}
mysql_query("insert into $DB->configuration values('$ID[0]', '".$DB->escape($value)."')");
return "تنظيم $name اضافه شد";
}
}
}
function category($action, $id = "", $name = "") {
global $DB;
switch ($action) {
case "output":
$data = '<select class=select name="'.(empty($name) ? "category" : $name).'">';
$q = mysql_query("select id,name,parent from $DB->category");
while ($r=mysql_fetch_assoc($q))
$cat[$r["parent"]][$r["id"]] = $r["name"];
foreach ($cat[0] as $i => $n) {
$data .= '<option value="'.$i.'"'.($id == $i ? "selected" : "").'>'.$n.'</option>';
foreach ((array)$cat[$i] as $p => $n) {
$data .= '<option value="'.$p.'"'.($id == $p ? "selected" : "").'> '.$n.'</option>';
foreach ((array)$cat[$p] as $r => $n)
$data .= '<option value="'.$r.'"'.($id == $r ? "selected" : "").'> '.$n.'</option>';
}
}
$data .= "</select>";
return $data;
case "check moderator":
$ID = mysql_result(mysql_query("select parent from $DB->category where id='$id'"), 0);
if ($ID != 0) {
$in .= ",$ID";
$ID = mysql_result(mysql_query("select parent from $DB->category where id='$ID'"), 0);
if ($ID != 0)
$in .= ",$ID";
}
for ($q=mysql_query("select moderator from $DB->category where id in($id$in)"), $id=$name == "" && logedIn ? logedIn : "", $i=0; $i<mysql_num_rows($q); $i++)
if (mysql_result($q, $i))
foreach (explode("\r\n", mysql_result($q, $i)) as $user)
if ($id == $user && $user)
return 1;
return 0;
case "tree":
for ($Q=mysql_query("select * from $DB->category order by `".config("category->order")."` ".config("category->sort")), $N=mysql_num_rows($Q), $i=0; $i<$N; $i++)
$c[mysql_result($Q, $i)] = mysql_result($Q, $i, 3);
for ($q=mysql_query("select category from $DB->post"), $n=mysql_num_rows($q), $i=0; $i<$n; $i++) {
$C[mysql_result($q, $i)]++;
$C[$c[mysql_result($q, $i)]]++;
$C[$c[$c[mysql_result($q, $i)]]]++;
}
for ($i=0; $i<$N; $i++)
$r .= 'd.add('.mysql_result($Q, $i).', '.mysql_result($Q, $i, 3).', "'.mysql_result($Q, $i, 1).'('.($C[mysql_result($Q, $i)] ? $C[mysql_result($Q, $i)] : 0).')", "category-'.mysql_result($Q, $i).'.html", '.js(mysql_result($Q, $i, 2)).', "", "", "", 0);';
return "<script>d=new dTree('d');d.config.useSelection=false;d.config.useStatusText=true;d.config.inOrder=true;d.add(0, -1, 'دستهبندي', '', '', '', '', '', 0);".$r.'document.write(d);</script>';
default:
return mysql_result(mysql_query("select `$action` from $DB->category where id='$id'"), 0);
}
}
function check($t, $c = "", $s = "") {
global $DB;
$r = 1;
foreach (array_keys((array)config("bad word")) as $w)
if (strstr($c, $w))
$b .= "در اطلاعات وارد شدهي شما کلمهي ناپسند <b>$w</b> وارد شده است<br>";
if ($t == "author" && ($c == "" || $b))
$r = $b."لطفا نام خود را وارد نماييد";
elseif ($t == "content" && ($c == "" || $b))
$r = $b."لطفا پيام خود را وارد نماييد";
elseif ($t == "security code" && strtolower($c) != strtolower($_SESSION["security code"]))
$r = !empty($c) ? "کد امنيتي نامعتبر است" : "لطفا کد امنيتي را وارد نماييد";
elseif ($t == "subject" && ($c == "" || $b))
$r = "لطفا عنوان را وارد نماييد";
elseif ($t == "email" && !preg_match("/^[\.A-z0-9_\-]+[@][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z]{1,4}$/", $c))
$r = !empty($c) ? "آدرس ايميل نامعتبر است" : "لطفا ايميل خود را وارد نماييد";
elseif ($t == "password" && $c == "")
$r = "لطفا کلمه عبور را وارد نماييد";
elseif ($t == "repassword" && $c == "")
$r = "لطفا تکرار کلمه عبور را وارد نماييد";
elseif ($t == "passwords" && (empty($c) || empty($s) || $c != $s))
$r = empty($c) && empty($s) ? "لطفا قسمت کلمههاي عبور را وارد نماييد" : "کلمههاي عبور با هم مطابقت ندارند";
elseif ($t == "username" || $b) {
if ($c == "")
$r = "لطفا نام کاربري را وارد نماييد";
elseif (preg_match("/\s/", $c))
$r = "لطفا فاصلههاي موجود در نام کاربري را حذف کنيد";
elseif (strlen($c)>30)
$r = "طول نام کاربري بيش از 30 کاراکتر نميتواند باشد";
elseif (!preg_match("/^[\.A-z0-9_\-]{3,30}$/", $c))
$r = "نام کاربري نامعتبر است";
elseif (mysql_result(mysql_query("select count(*) from $DB->user where username='$c'"), 0))
$r = "نام کاربري $c قبلا ثبت شده است";
} elseif ($t == "nickname" && mysql_result(mysql_query("select count(*) from $DB->user where ((nickname='$c' and nickname!='') or username='$c') and id!='$s'"), 0))
$r = "نام مستعار انتخابي شما قبلا ثبت شده است";
elseif ($t == "url" && ($b || $c == "" || $c == "http://"))
$r = "لطفا آدرس سايت را وارد نماييد";
elseif ($t == "title" && ($b || $c == ""))
$r = "لطفا نام سايت را وارد نماييد";
elseif ($t == "referer" && !strstr(str_replace("www.", "", $_SERVER["HTTP_REFERER"]), str_replace("www.", "", $_SERVER["HTTP_HOST"])))
$r = 0;
return $r;
}
function is_serialized($data) {
return preg_match('/s:[0-9]+:.*;/', trim($data));
}
function form_value() {
$a = $_COOKIE["saveCookie"] ? array(" checked", $_COOKIE["privateMessage"] ? " checked" : "", "", $_COOKIE["author"], $_COOKIE["email"], $_COOKIE["url"]) : (logedIn ? array("", "", " disabled", user("name"), user("email") , user("url")) : array("", "", "", "", "", "http://"));
return array("saveCookie" => $a[0], "privateMessage" => $a[1], "disabled" => $a[2], "author" => $a[3], "email" => $a[4], "url" => $a[5]);
}
function comment($action, $id = "", $post_id = "") {
global $DB, $TPL;
switch ($action) {
case "count":
return $post_id == 1 || mysql_result(mysql_query("select `comment status` from $DB->post where id='$id'"), 0) == 1 ? mysql_result(mysql_query("select count(*) from $DB->comment where `post id`='$id' and status!=0"), 0) : -1;
case "block":
$postID = isset($_GET["comment"]) ? $_GET["comment"] : $_GET["post"];
$q = mysql_query("select * from $DB->post where id='$postID'");
$TPL->assign(array(
"post title" => mysql_result($q, 0, 1),
"post author" => user("name", mysql_result($q, 0, 3)),
"post date" => my_date(mysql_result($q, 0, 5), 1),
"post time" => my_time(mysql_result($q, 0, 5), 1),
"count private" => mysql_result(mysql_query("select count(*) from $DB->comment where `post id`='$postID' and status=2"), 0)
)
);
for ($q=mysql_query("select * from $DB->comment where status=1 and `post id`='$postID' order by `".config("comment->order")."` ".config("comment->sort")), $i=0; $i<mysql_num_rows($q); $i++)
$TPL->block("comment", mysql_result($q, $i, 2) ? array("id" => mysql_result($q, $i), "author" => user("name", mysql_result($q, $i, 2)), "email" => user("email", mysql_result($q, $i, 2)), "url" => user("url", mysql_result($q, $i, 2)) ? array("url" => user("url", mysql_result($q, $i, 2))) : array(""), "content" => html(mysql_result($q, $i, 4)), "ip" => mysql_result($q, $i, 7), "date" => my_date(mysql_result($q, $i, 8)), "time" => my_time(mysql_result($q, $i, 8))) : array("id" => mysql_result($q, $i), "author" => mysql_result($q, $i, 3), "email" => mysql_result($q, $i, 5), "url" => mysql_result($q, $i, 6) ? array("url" => mysql_result($q, $i, 6)) : array(""), "content" => html(mysql_result($q, $i, 4)), "ip" => mysql_result($q, $i, 7), "date" => my_date(mysql_result($q, $i, 8)), "time" => my_time(mysql_result($q, $i, 8))));
mysql_num_rows($q) or $TPL->block("comment");
$v = form_value();
$TPL->block("new comment", array(
"author" => '<input class=input name=author value="'.$v["author"].'" lang=fa size=[value]'.$v["disabled"].'>',
"email" => '<input class=input name=email dir=ltr value="'.$v["email"].'" size=[value]'.$v["disabled"].'>',
"url" => '<input class=input name=url dir=ltr value="'.$v["url"].'" size=[value]'.$v["disabled"].'>',
"content" => '<textarea class=textarea rows=10 cols=[value] name=content id=content '.(config("comment->html") ? 'editor=active' : 'lang=fa').'></textarea>',
"submit" => '<input type=submit class=button value="[value]">',
"reset" => '<input type=reset class=button value="[value]">',
"private message" => '<input type=checkbox class=checkbox name=privateMessage id=privateMessage'.$v["privateMessage"].'><label for=privateMessage>[value]</label>',
"result" => '<div id=commentResult></div>',
), '<form method=post ajax=commentResult><input type=hidden name=do value=comment><input type=hidden name=postID value='.$postID.'>', '</form>'
);
}
}
function post($field, $id) {
global $DB;
return mysql_result(mysql_query("select `$field` from $DB->post where id='$id'"), 0);
}
function table_data($t, $f, $i) {
global $DB;
return mysql_result(mysql_query("select `$f` from $t where id='$i'"), 0);
}
function linkbox($name, $url, $description, $count, $view, $creator, $time, $type, $status) {
global $DB;
mysql_query("insert into $DB->link values('', '$name', '$url', '$description', '$creator', $time, '$count', '$view', $type, $status)");
return ($type == 0 ? "پيوند" : ($type == 1 ? "پيوند روزانه" : "تبليغ"))." $name با موفقيت ارسال شد".($status == 1 ? "." : "، پس از تاييد مدير سايت به نمايش در ميآيد.");
}
function active_theme() {
return isset($_GET["theme"]) ? $_GET["theme"] : (isset($_COOKIE["theme"]) ? $_COOKIE["theme"] : config("site->theme"));
}
function theme($action, $field = "", $value = "") {
global $DB, $pageTheme;
switch ($action) {
case "add":
!mysql_query("select `$field` from $DB->theme") or mysql_query("alter table $DB->theme add `$field` longtext not null");
return "قالب $field اضافه شد.";
case "delete":
!mysql_query("select `$field` from $DB->theme") or mysql_query("alter table $DB->theme drop `$field`");
return "قالب $field حذف شد.";
case "page":
$pageTheme[] = array($field, $value);
break;
case "print":
if (isset($_GET["theme"])) {
$id = $_GET["theme"];
cookie(array("theme" => $id));
} else
$id = isset($_COOKIE["theme"]) ? $_COOKIE["theme"] : config("site->theme");
if (mysql_num_rows($q = mysql_query("select `$field` from $DB->theme where id='$id'")))
return mysql_result($q, 0);
else {
$r = mysql_fetch_assoc(mysql_query("select `$field` from $DB->theme"));
return $r[$field];
}
break;
case "data":
$data = mysql_result(mysql_query("select style from $DB->theme where id='$field'"), 0);
preg_match("|Name:(.*)|i", $data, $name);
preg_match("|URL:(.*)|i", $data, $url);
preg_match("|Description:(.*)|i", $data, $description);
preg_match("|Date:(.*)|i", $data, $date);
preg_match("|Version:(.*)|i", $data, $version);
preg_match("|Author:(.*)|i", $data, $author);
preg_match("|Author Email:(.*)|i", $data, $author_email);
preg_match("|Author URL:(.*)|i", $data, $author_url);
return array("name" => trim($name[1]), "url" => trim($url[1]), "description" => trim($description[1]), "date" => trim($date[1]), "version" => trim($version[1]), "author" => trim($author[1]), "author email" => trim($author_email[1]), "author url" => trim($author_url[1]));
}
}
function counter($m) {
global $TPL;
$data = config("counter");
$today = $data["today"];
$yesterday = $data["yesterday"];
$total = $data["total"];
$update = $data["update"];
$maxVisit = explode(" ", $data["max visit"]);
$maxOnline = explode(" ", $data["max online"]);
$onlines = array("explode" => $data["online"], "count" => count($data["online"]));
$referrer = array("URL" => $data["referrer"], "explode" => !empty($data["referrer"]) ? explode("\n", $data["referrer"]) : array());
$browser = $data["browser"];
switch ($m) {
case "block":
$TPL->block("counter", array("today" => $today, "yesterday" => $yesterday, "total" => $total, "online" => $onlines["count"], "max visit" => array("count" => $maxVisit[0], "date" => my_date($maxVisit[1]), "time" => my_time($maxVisit[1])), "max online" => array("count" => $maxOnline[0], "date" => my_date($maxOnline[1]), "time" => my_time($maxOnline[1])), "referrer" => count($referrer["explode"])));
break;
case "detail":
$r = '<div class="bc_center_title"><span style="color: #3d5262">» </span>آمار</div><div class="bc_center_tb"><table style="width:90%">';
foreach (array("بازديد امروز" => $today, "بازديد ديروز" => $yesterday, "بازديد کل" => $total, "افراد آنلاين" => $onlines["count"], "بيشترين بازديد" => $maxVisit[0], "تاريخ بيشترين بازديد" => my_date($maxVisit[1])." در ساعت ".my_time($maxVisit[1]), "بيشترين افراد آنلاين" => $maxOnline[0], "تاريخ بيشترين افراد آنلاين" => my_date($maxOnline[1])." در ساعت ".my_time($maxOnline[1]), "تعداد معرفها" => count($referrer["explode"])) as $n => $v)
$r .= "<tr><td width=50%>$n</td><td width=50%>$v</td></tr>";
$r .= '</table></div><br><div class="bc_center_title"><span style="color: #3d5262">» </span>مرورگر</div><div class="bc_center_tb"><table style="width:90%">';
foreach (array("InternetExplorer" => $browser["internet explorer"], "FireFox" => $browser["fire fox"], "Opera" => $browser["opera"], "NetScape" => $browser["net scape"], "Gecko" => $browser["gecko"], "ديگر" => $browser["other"]) as $n => $v)
$r .= "<tr><td width=50%>$n</td><td width=50%>$v</td></tr>";
return $r.'</table></div><br><div class="bc_center_title" onclick="load(\'CP&page=manage&part=counter&action=referrer\', \'counter_referrer\')"><span style="color: #3d5262">» </span>معرف</div><div class=bc_center_tb dir=ltr align=left id=counter_referrer></div><br><div class="bc_center_title" onclick="load(\'CP&page=manage&part=counter&action=keyword\', \'counter_keyword\')"><span style="color: #3d5262">» </span>کلمه کليدي</div><div class=bc_center_tb align=right id=counter_keyword></div>';
case "referrer":
$referrerList = array();
foreach ($referrer["explode"] as $site) {
$site = preg_replace("|^([^:]+)://([^:/]+)(:[\d]+)*(.*)|", "\\1://\\2", $site);
$name = str_replace(array("http://", "www."), "", $site);
if (!array_key_exists($name, $referrerList)) {
$referrerList[$name] = 1;
$referrerListURL[$name] = $site;
} else
$referrerList[$name]++;
}
arsort($referrerList);
foreach ($referrerList as $n => $c)
$r .= '<a href="'.$referrerListURL[$n].'">'.$n.'</a> ('.$c.')<br />';
return $r;
case "keyword":
$words = array();
foreach ($referrer["explode"] as $url)
if (preg_match("/([?&])(q|query)=(.*?)[&]/is", $url, $m))
if (!array_key_exists($k=str_replace(array("<", ">"), array("<", ">"), $word = urldecode($m[3])), $words))
$words[$k] = count(explode("=".urlencode($word), $referrer["URL"]));
arsort($words);
foreach ($words as $w => $c)
$r .= "$w ($c)<br />";
return $r;
case "update":
$timeOut = config("user->timeout");
$agent = strtolower($_SERVER["HTTP_USER_AGENT"]);
list($y, $m, $d) = explode("-", date("y-m-d", $update));
list($Y, $M, $D) = explode("-", date("y-m-d"));
if ($y == $Y && $m == $M && ($d == $D || $d+1 == $D))
if ($d == $D)
$today++;
elseif ($d+1 == $D) {
$yesterday = $today;
$today = 1;
}
else {
$today = 1;
$yesterday = 0;
}
$total++;
$maxVisit = ($maxVisit[0] <= $today) ? "$today ".Time : "$maxVisit[0] $maxVisit[1]";
$onlines["explode"][IP] = Time;
foreach ($onlines["explode"] as $ip => $date)
if (Time-$date <= $timeOut)
$onlines["data"][$ip] = $date;
$maxOnline = $maxOnline[0] <= count($onlines["data"]) ? count($onlines["data"])." ".Time : "$maxOnline[0] $maxOnline[1]";
if ($_SERVER["HTTP_REFERER"] && !preg_match("|http://".str_replace("www.", "", $_SERVER["HTTP_HOST"])."|is", str_replace("www.", "", $_SERVER["HTTP_REFERER"])))
$referrer["URL"] .= ($referrer["URL"] ? "\n" : "").$_SERVER["HTTP_REFERER"];
if (empty($_SESSION["counter"])) {
$browser[strpos($agent, "msie") !== false ? "internet explorer" : (strpos($agent, "firefox") !== false ? "fire fox" : (strpos($agent, "opera") !== false ? "opera" : (strpos($agent, "netscape") !== false ? "net scape" : (strpos($agent, "gecko") !== false ? "gecko" : "other"))))]++;
$_SESSION["counter"] = 1;
}
config("counter", array("today" => $today, "yesterday" => $yesterday, "total" => $total, "update" => Time, "max visit" => $maxVisit, "max online" => $maxOnline, "online" => $onlines["data"], "referrer" => $referrer["URL"], "browser" => $browser));
}
}
function level($action, $id = "") {
if ($action == "permission") {
$permission = $id;
foreach (config("level->access") as $id => $access)
if (in_array($permission, $access) && !in_array("demo", $access)) {
$level .= $comma.$id;
$comma = ",";
}
return "level in($level)";
} else {
if ($action == "active" || $action == 1)
return true;
$id = $id == "" ? (logedIn ? user("level") : "") : $id;
if ($v = cache("get", "level", "$id-$action"))
return $v;
$result = false;
if (config("level->access->$id") != false)
if (in_array($action, config("level->access->$id")))
$result = true;
cache("set", "level", "$id-$action", $result);
return $result;
}
}
function user($action, $id = "", $username = "", $password = "", $first_name = "", $last_name = "", $nickname = "", $birthday = "", $gender = "", $marriage = "", $eduction = "", $vocation = "", $amusement = "", $favorite = "", $about = "", $avatar = "", $signature = "", $location = "", $phone = "", $email = "", $url = "", $msn = "", $yahoo = "", $gmail = "", $aim = "", $icq = "", $visible = "", $date_format = "", $time_format = "", $time_zone = "", $start_of_week = "", $theme = 0, $level = "", $status = "", $send_email = 0) {
global $DB;
$id = ($id == "" && $action != "convert" && isset($_SESSION["user id"])) ? $_SESSION["user id"] : $id;
if (($action == "add" || $action == "update") && !config("user->signature html"))
$signature = html($signature, "convert");
$url = $url == "http://" ? "" : $url;
switch ($action) {
case "add":
($e = check("username", $username)) == 1 or $result .= "$e<br>";
($e = check("passwords", $password[0], $password[1])) == 1 or $result .= "$e<br>";
if (($error = check("email", $email)) != 1)
$result .= "$error<br>";
elseif (mysql_num_rows($q=mysql_query("select id from $DB->user where email='$email'")) == 1)
$result .= "ايميل $email توسط کاربر ".user("name", mysql_result($q, 0))." ثبت شده است.<br>";
($e = check("nickname", $nickname)) == 1 or $result .= "$e<br>";
if (empty($result)) {
mysql_query("insert into $DB->user values('', '".strtolower($username)."', '".md5($password[0])."', '$first_name', '$last_name', '$nickname', '$birthday', '$gender', '$marriage', '$eduction', '$vocation', '$amusement', '$favorite', '$about', '$avatar', '$signature', '$location', '$phone', '$email', '$url', '$aim', '$gmail', '$icq', '$msn', '$yahoo', '$visible', '$date_format', '$time_format', '$time_zone', '$start_of_week', '$theme', '".IP."', '".IP."', '".Time."', '".Time."', '', '$level', '$status')");
$id = mysql_insert_id();
if ($send_email == 1) {
contact($email, str_replace("[site title]", config("site->title"), config("user->membership subject")), str_replace(array("[name]", "[security code url]", "[url]", "[title]", "[description]", "[id]"), array(user("name", $id), config("site->url")."?action=membership&id=$id&securityCode=".$status, config("site->url"), config("site->title"), config("site->description"), $id), config("user->membership message")), "", config("site->email"), config("site->url"));
$result = "از عضويت شما ".user("name", $id)." عزيز متشکريم، يک نامه حاوي لينک فعال سازي به ايميل شما ارسال شد.";
} else
$result = "کاربر ".user("name", $id)." اضافه شد.";
securityCode();
}
break;
case "update":
if (!empty($password[0])) {
if (empty($password[2]))
$result .= "شما براي تغيير رمز عبور بايد رمز عبور قبلي را وارد کنيد<br>";
elseif (md5($password[2]) != user("password", $id))
$result .= "رمز عبور قلبي وارد شده با رمز عبور فعلي متفاوت است<br>";
($e = check("passwords", $password[0], $password[1])) == 1 or $result .= "$e<br>";
}
($e = check("nickname", $nickname, $id)) == 1 or $result .= "$e<br>";
($e = check("email", $email)) == 1 or $result .= "$e<br>";
if (empty($result)) {
$password = !empty($password[2]) && md5($password[2]) == user("password", $id) && $password[0] == $password[1] ? "`password`='".md5($password[0])."'," : "";
mysql_query("update $DB->user set $password `first name`='$first_name',`last name`='$last_name',nickname='$nickname',birthday='$birthday',gender='$gender',marriage='$marriage',eduction='$eduction',vocation='$vocation',amusement='$amusement',favorite='$favorite',about='$about',avatar='$avatar',signature='$signature',location='$location',phone='$phone',email='$email',url='$url',msn='$msn',yahoo='$yahoo',gmail='$gmail',aim='$aim',icq='$icq',visible='$visible',`date format`='$date_format',`time format`='$time_format',`time zone`='$time_zone',`start of week`='$start_of_week',theme='$theme',level='$level',status='$status' where id='$id'");
$result = "کاربر ".user("name", $id)." بروز رساني شد";
}
break;
case "delete":
$name = user("name", $id);
$DB->update($DB->user, array("status" => ""), "id='$id'");
return "کاربر $name حذف شد.";
case "name":
$q = mysql_query("select username, nickname from $DB->user where id='$id'");
return mysql_result($q, 0, mysql_result($q, 0, 1) ? 1 : 0);
case "security code":
$name = user("name", $id);
return mysql_num_rows(mysql_query("select username from $DB->user where id='$id' and (status='$username' || status=1)"), 0) && mysql_query("update $DB->user set status=1 where id='$id'") ? "عضويت کاربر $name فعال شد." : "عضويت کاربر $name فعال نشد.";
case "login":
$v = cache("get", "CMS", "loged in");
if (isset($v))
return $v != false ? true : false;
$r = mysql_num_rows($q = mysql_query("select id from $DB->user where ((username='$_SESSION[username]' and password='$_SESSION[password]') or (username='$_COOKIE[username]' and password='$_COOKIE[password]')) and status=1")) == 1 ? mysql_result($q, 0) : 0;
cache("set", "CMS", "loged in", $r);
return $r;
case "convert":
$field = $id;
$converter = $username;
$content = $password;
$parser = $first_name;
if ($content == "")
return;
if ($parser != "") {
foreach (explode($parser, $content) as $index => $value) {
$q = mysql_query("select `$converter` from $DB->user where `$field`='$value'");
$newContent .= ($index != 0 ? $parser : "").(mysql_num_rows($q) != 0 ? mysql_result($q, 0) : $value);
}
} else {
$q = mysql_query("select `$converter` from $DB->user where `$field`='$content'");
$newContent = mysql_num_rows($q) ? mysql_result($q, 0) : $content;
}
return $newContent;
default:
$q = mysql_query("select `$action` from $DB->user where id='$id'");
return mysql_num_rows($q) ? mysql_result($q, 0) : "";
}
return $result;
}
function status($table, $id, $change = 0, $print = 1) {
global $DB;
$r = mysql_result(mysql_query("select status from $table where id='$id'"), 0);
if ($change) {
mysql_query("update `$table` set `status`='".($r == 1 ? ($table == $DB->comment ? 2 : 0) : 1)."' where id='$id'");
if ($print)
return "آيتم مورد نظر ".($r ? ($table == $DB->comment ? "خصوصي" : "غير فعال") : "فعال")." شد.";
}
return $r == 1 ? "فعال" : ($r == 2 ? "خصوصي" : "غير فعال");
}
function gdversion() {
ob_start();
phpinfo(8);
return preg_match("/\bgd\s+version\b[^\d\n\r]+?([\d\.]+)/i", ob_get_clean(), $m) ? $m[1] : 0;
}
function dirsize($directory) {
if (!is_dir($directory))
return -1;
$size = 0;
if ($DIR = opendir($directory)) {
while (($dirfile = readdir($DIR)) !== false) {
if (@is_link($directory.'/'.$dirfile) || $dirfile == '.' || $dirfile == '..')
continue;
if (@is_file($directory.'/'.$dirfile))
$size += filesize($directory.'/'.$dirfile);
else if (@is_dir($directory.'/'.$dirfile)) {
$dirSize = dirsize($directory.'/'.$dirfile);
if ($dirSize >= 0)
$size += $dirSize;
else
return -1;
}
}
closedir($DIR);
}
return $size;
}
function encrypt($c) {
return trim(str_replace("/(\r\n|\n)+/", "\n", $c));
}
function security_code($width=50, $height=20) {
$im = imagecreate($width, $height);
$db = config("security code");
$BGC = dehexize($db["background color"]);
$BC = dehexize($db["border color"]);
$FGC = dehexize($db["foreground color"]);
$LC = dehexize($db["line color"]);
imagecolorallocate($im, $BGC[0], $BGC[1], $BGC[2]);
$FGC = imagecolorallocate($im, $FGC[0], $FGC[1], $FGC[2]);
$LC = imagecolorallocate($im, $LC[0], $LC[1], $LC[2]);
for ($i=0; $i<$db["line number"]; $i++)
imageline($im, $i, rand(15, 50), ($i+1)*20, $i, $LC);
imagestring($im, 5, 4, 1, $_SESSION["security code"], $FGC);
imagepng($im);
header("Content-type: image/png");
imagedestroy($im);
}
function securityCode($s=1) {
$c = strtoupper(substr(md5(rand(0, 99999)), 0, 5));
!$s or $_SESSION["security code"] = $c;
return $c;
}
function logo($width=80, $height=15) {
global $SC;
header("Content-type: image/png");
if ($SC->time("logo"))
$im = imagecreatefrompng("_/logo");
else {
$im = imagecreate($width, $height);
$db = config("logo");
$bgc = dehexize($db["background color"]);
$lc = dehexize($db["line color"]);
$bc = dehexize($db["border color"]);
$fgc = dehexize($db["foreground color"]);
$ic = dehexize($db["icon foreground color"]);
$ibc = dehexize($db["icon background color"]);
imagecolorallocate($im, $bgc[0], $bgc[1], $bgc[2]);
$fgc = imagecolorallocate($im, $fgc[0], $fgc[1], $fgc[2]);
$bc = imagecolorallocate($im, $bc[0], $bc[1], $bc[2]);
$lc = imagecolorallocate($im, $lc[0], $lc[1], $lc[2]);
$ic = imagecolorallocate($im, $ic[0], $ic[1], $ic[2]);
$ibc = imagecolorallocate($im, $ibc[0], $ibc[1], $ibc[2]);
imagefilledrectangle($im, 2, 2, 24, 12, $ibc);
imageline($im, 25, 2, 25, 12, $lc);
imagerectangle($im, 0, 0, $width-1, $height-1, $bc);
imagerectangle($im, 1, 1, $width-2, $height-2, $lc);
imagestring($im, 3, 7, 0, $db["icon content"], $ic);
imagestring($im, 1, 27, 4, $db["site name"], $fgc);
imagepng($im, "_/logo");
}
imagepng($im);
}
function compute($second, $num, $num2) {
return floor(($second/$num)%$num2);
}
function time_parser($t) {
return array("year" => ($v=compute($t, 31536000, 100))>0 ? array("year" => $v) : array(""), "month" => ($v=compute($t, 2592000, 12))>0 ? array("month" => $v) : array(""), "week" => ($v=compute($t, 604800, 5))>0 ? array("week" => $v) : array(""), "day" => ($v=compute($t, 86400, 7))>0 ? array("day" => $v) : array(""), "hour" => ($v=compute($t, 3600, 24))>0 ? array("hour" => $v) : array(""), "minute" => ($v=compute($t, 60, 60))>0 ? array("minute" => $v) : array(""), "second" => ($v=compute($t, 1, 60))>0 ? array("second" => $v) : array(""));
}
function element($t, $P = array(), $V = "") {
foreach ((array)$P as $p => $v)
$a .= " ".$p.'="'.str_replace('"', '"', $v).'"';
switch ($t) {
case "text":
case "password":
return "<input type=$t class=input".(empty($V) ? "" : ' value="'.str_replace('"', '"', $V).'"')."$a>";
case "button":
case "submit":
return "<input type=$t class=button".(empty($V) ? "" : ' value="'.$V.'"')."$a>";
case "checkbox":
case "radio":
return "<input type=$t class=$t id=$P[name]$a $V><lable for=$P[name]></label>";
case "select":
$r = "<$t class=$t$a>";
foreach ($V as $v => $n)
$r .= '<option value="'.$v.'"'.($v == $P["value"] ? " selected" : "").">$n</option>";
return "$r</$t>";
case "textarea":
return "<$t class=$t$a>".htmlspecialchars($V)."</$t>";
case "sort":
return element("select", array("name" => $P, "value" => $V), array("asc" => "صعودي", "desc" => "نزولي"));
case "status":
return element("select", array("name" => $P, "value" => $V), array(1 => "فعال", 0 => "غيرفعال"));
case "table":
$r = "<$t $a>";
foreach ($V as $f => $d)
$r .= "<tr><td width=50%>$f</td><td width=50%>$d</td></tr>";
return "$r</$t>";
case "line":
return "<hr class=$t$a>";
case "part":
return '<div class="bc_center_title"><span style="color: #3d5262">» </span>'.$P["title"].'</div><div class="bc_center_tb"'.(isset($P["align"]) ? "align=$P[align]" : "").'>'.$V.'</div><br>';
}
}
function server_parse($socket, $response, $line = __LINE__) {
while (substr($server_response, 3, 1) != ' ')
$server_response = fgets($socket, 256) or die("Couldn't get mail server response codes".$line. __FILE__);
substr($server_response, 0, 3) == $response or die("Ran into problems sending Mail. Response: $server_response".$line. __FILE__);
}
// Replacement or substitute for PHP's mail command
function smtpmail($mail_to, $SenderMail, $subject, $message, $headers="") {
$config = config("smtp");
// Fix any bare linefeeds in the message to make it RFC821 Compliant.
$message = preg_replace("#(?<!\r)\n#si", " ", $message);
if ($headers != "") {
if (is_array($headers))
$headers = sizeof($headers)>1 ? join("\n", $headers) : $headers[0];
$headers = chop($headers);
// Make sure there are no bare linefeeds in the headers
$headers = preg_replace("#(?<!\r)\n#si", " ", $headers);
// Ok this is rather confusing all things considered,
// but we have to grab bcc and cc headers and treat them differently
// Something we really didn't take into consideration originally
$header_array = explode(" ", $headers);
@reset($header_array);
$headers = "";
while (list(, $header) = each($header_array)) {
if (preg_match("#^cc:#si", $header))
$cc = preg_replace("#^cc:(.*)#si", "\1", $header);
else if (preg_match("#^bcc:#si", $header)) {
$bcc = preg_replace("#^bcc:(.*)#si", "\1", $header);
$header = "";
}
$headers .= ($header != "") ? $header." " : "";
}
$headers = chop($headers);
$cc = "";//explode(", ", $cc);
$bcc = "";//explode(", ", $bcc);
}
trim($subject) != "" or die("No email Subject specified". __LINE__ . __FILE__);
trim($message) != "" or die("Email message was blank". __LINE__ . __FILE__);
// Ok we have error checked as much as we can to this point let's get on
// it already.
$socket = @fsockopen($config["host"], 25, $errno, $errstr, 20) or die("Could not connect to smtp host : $errno : $errstr". __LINE__ . __FILE__);
// Wait for reply
server_parse($socket, "220", __LINE__);
// Do we want to use AUTH?, send RFC2554 EHLO, else send RFC821 HELO
// This improved as provided by SirSir to accomodate
if (!empty($config["username"]) && !empty($config["password"])) {
fputs($socket, "EHLO $config[host] ");
server_parse($socket, "250", __LINE__);
fputs($socket, "AUTH LOGIN ");
server_parse($socket, "334", __LINE__);
fputs($socket, base64_encode($config["username"])." ");
server_parse($socket, "334", __LINE__);
fputs($socket, base64_encode($config["password"])." ");
server_parse($socket, "235", __LINE__);
} else {
fputs($socket, "HELO $config[host] ");
server_parse($socket, "250", __LINE__);
}
// From this point onward most server response codes should be 250
// Specify who the mail is from....
fputs($socket, "MAIL FROM: <".$SenderMail."> ");
server_parse($socket, "250", __LINE__);
// Specify each user to send to and build to header.
$to_header = "";
// Add an additional bit of error checking to the To field.
$mail_to = trim($mail_to) == "" ? "Undisclosed-recipients:;" : trim($mail_to);
if (preg_match("#[^ ]+\@[^ ]+#", $mail_to)) {
fputs($socket, "RCPT TO: <$mail_to> ");
server_parse($socket, "250", __LINE__);
}
// Ok now we tell the server we are ready to start sending data
fputs($socket, "DATA ");
// This is the last response code we look for until the end of the message.
server_parse($socket, "354", __LINE__);
// Send the Subject Line...
fputs($socket, "Subject: $subject ");
// Now the To Header.
fputs($socket, "To: $mail_to ");
// Now any custom headers....
fputs($socket, "$headers ");
// Ok now we are ready for the message...
fputs($socket, "$message ");
// Ok the all the ingredients are mixed in let's cook this puppy...
fputs($socket, ". ");
server_parse($socket, "250", __LINE__);
// Now tell the server we are done and close the socket...
fputs($socket, "QUIT ");
fclose($socket);
return true;
}
function contact($mail_to, $subject, $message, $headers = "", $SenderMail = "", $site = "") {
$headers or $headers = "From: $SenderMail<$SenderMail>\nReply-To: $SenderMail\nWeb-Site: $site\nMIME-Version: 1.0\nContent-type: text/html; charset=".config("site->charset");
return config("smtp->status") ? smtpmail($mail_to, $SenderMail, $subject, $message, $headers) : mail($mail_to, $subject, $message, $headers);
}
function excerptLength($c) {
$l = config("site->excerpt length");
$C = strip_tags($c);
return strlen($C) <= $l ? $c : substr($C, 0, $l-1)."…";
}
function newsletter($type, $subject, $id, $title, $content, $date = 0) {
if (empty($subject))
$subject = str_replace("[site title]", config("site->title"), config("newsletter->subject"));
$subject = str_replace("[post title]", $type == "post" ? $title : "", $subject);
$n = user("name", logedIn);
$t = config("newsletter->template");
$C = config("site");
$c = excerptLength($content);
$emails = explode(",", config("newsletter->emails"));
$search = array("[name]", "[email]", "[url]", "[title]", "[description]", "[post title]", "[post content]", "[post author]", "[post date]", "[post time]", "[post url]");
foreach ($emails as $email) {
$name = explode("@", $email);
contact($email, $subject, $type == "post" ? str_replace($search, array($name[0], $email, $C["url"], $C["title"], $C["description"], $title, $c, $n, my_date($date, 1), my_time($date, 1), $C["url"]."/post-$id.html"), $t) : $id, "", $C["email"], $C["url"]);
}
return "پيام $subject با موفقيت براي اعضاي خبرنامه ارسال شد.";
}
function lock($t, $s) {
$s = trim($s);
switch ($t) {
case "js":
return CompressJavascript($s);
case "css":
return preg_replace(array('#/\*.*?\*/|\n|\r|\t|\f#is', '#\s*(\{|\}|\(|:|,|;)\s*#is'), array('', '$1'), $s);
case "html":
return "<!--\n|\tThis Program has written By MAHDI NEZARATI ZADEH\n|\tWEB : HTTPS://Raha.Group\n-->\n".str_replace("\r", "", $s)."\n".'<span style="color: #c0c0c0; font-size: 8pt">Programmed By <a href="//raha.group" style="color: #c0c0c0; font-size: 8pt" target="_blank">Raha.Group</a></span>'."\n<!-- Powered By WWW.Raha.Group -->";
}
}
function CompressJavascript($S) {
//remove windows cariage returns
$S = str_replace("\r", "", $S);
//array to store replaced literal strings
$literal_strings = array();
//explode the string into lines
$lines = explode("\n", $S);
//loop through all the lines, building a new string at the same time as removing literal strings
$clean = "";
$inComment = false;
$literal = "";
$inQuote = false;
$escaped = false;
$quoteChar = "";
for ($i=0; $i<count($lines); $i++) {
$line = $lines[$i];
$inNormalComment = false;
//loop through line's characters and take out any literal strings, replace them with ___i___ where i is the index of this string
for ($j=0; $j<strlen($line); $j++) {
$c = substr($line, $j, 1);
$d = substr($line, $j, 2);
//look for start of quote
if (!$inQuote && !$inComment) {
//is this character a quote or a comment
if (($c == '"' || $c == "'") && !$inComment && !$inNormalComment) {
$inQuote = true;
$inComment = false;
$escaped = false;
$quoteChar = $c;
$literal = $c;
} elseif ($d == "/*" && !$inNormalComment) {
$inQuote = false;
$inComment = true;
$escaped = false;
$quoteChar = $d;
$literal = $d;
$j++;
} elseif ($d == "//") { //ignore string markers that are found inside comments
$inNormalComment = true;
$clean .= $c;
} else {
$clean .= $c;
}
} else { //allready in a string so find end quote
if ($c == $quoteChar && !$escaped && !$inComment) {
$inQuote = false;
$literal .= $c;
//subsitute in a marker for the string
$clean .= "___".count($literal_strings)."___";
//push the string onto our array
array_push($literal_strings, $literal);
} elseif ($inComment && $d == "*/") {
$inComment = false;
$literal .= $d;
//subsitute in a marker for the string
$clean .= "___".count($literal_strings)."___";
//push the string onto our array
array_push($literal_strings, $literal);
$j++;
} elseif ($c == "\\" && !$escaped)
$escaped = true;
else
$escaped = false;
$literal .= $c;
}
}
if ($inComment)
$literal .= "\n";
$clean .= "\n";
}
//explode the clean string into lines again
$lines = explode("\n", $clean);
//now process each line at a time
for ($i=0; $i<count($lines); $i++) {
$line = $lines[$i];
//remove comments
$line = preg_replace("/\/\/(.*)/", "", $line);
//strip leading and trailing whitespace
$line = trim($line);
//remove all whitespace with a single space
$line = preg_replace("/\s+/", " ", $line);
//remove any whitespace that occurs after/before an operator
$line = preg_replace("/\s*([!\}\{;,&=\|\-\+\*\/\)\(:])\s*/", "\\1", $line);
$lines[$i] = $line;
}
//implode the lines
$S = implode("\n", $lines);
//make sure there is a max of 1 \n after each line
$S = preg_replace("/[\n]+/", "\n", $S);
//strip out line breaks that immediately follow a semi-colon
$S = preg_replace("/;\n/", ";", $S);
//curly brackets aren't on their own
$S = preg_replace("/[\n]*\{[\n]*/", "{", $S);
//finally loop through and replace all the literal strings:
for ($i=0; $i<count($literal_strings); $i++)