-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.dev.php
2026 lines (1645 loc) · 108 KB
/
core.dev.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
///////////////////////////////////////////////////////
///////////////////////////////////////////////////////
ini_set('arg_separator.output',';');
error_reporting(0); //error_reporting(E_ALL ^ E_NOTICE);
// AUTOMATED ACTIONS: First parses the query, connects to database, then checks the session
$qAction=parseQuery();
$db=mysql_connect(db('dbhost'),db('dbuname'),db('dbpass')) or die ('I cannot connect to the database because: '.mysql_error());
if(!$db) die(db('dberror')); if(!mysql_select_db(db('dbname'),$db)) die(db('dberror'));
$leap=new leapInit;
$leap->updateContent();
$leap->checkSession();
//Clear all global variables for XSS
$myFilter = new InputFilter();
$qAction = $myFilter->process($qAction);
if( isset($_POST['secureAction']) ) { //All admin functions are labelled as secure actions, they must be verified
$tknlbl=token_label();
if ( isset($_POST[$tknlbl]) && verify_token($_POST[$tknlbl]) ) $_POST = $_POST; // Token label and key must be true
else unset($_POST); // If the token isn't passed, the POST is completely unset
} else $_POST = $myFilter->process($_POST); //everything else is processed by the XSS filter
$_GET = $myFilter->process($_GET);
$_COOKIES = $myFilter->process($_COOKIES);
define('CHARSET',_value('character-encoding'));
mysql_query("SET CHARACTER SET ".CHARSET);
/* INCLUDING EXTENSIONS *///
if ($handle=@opendir(_value('extensions-folder'))) {
$q=mysql_query("SELECT * FROM ".db('prefix')."extensions WHERE active='1'");
while ($r=mysql_fetch_array($q)) { $INSTALLED_EXT.="`$r[path]`"; }
while($item=@readdir($handle)) { if(strstr($INSTALLED_EXT,$item)!=FALSE) $INC_LIST[]=$item; }
@closedir($handle);
if (!empty($INC_LIST)) {
foreach ($INC_LIST as $ext) { $ext='extensions/'.$ext.'/index.php'; include_once($ext); }
}
} //*/
//EXECUTE SPECIAL FUNCTIONS
if (in_array($qAction[0], $leap->SpecFuncTriggers, true)) {
$key= array_search($qAction[0], $leap->SpecFuncTriggers);
$SpecialFunction=$leap->SpecFuncNames[$key];
$SpecialFunction();
}
//SEPERATE QUERY
function parseQuery() { return explode(".",$_SERVER['QUERY_STRING']); }
//RECALL SYSTEM VALUES
function value($v) { echo ($v=='website') ? db($v): _value($v); }
function _value($v) { $s=@mysql_query("SELECT * FROM ".db("prefix")."system WHERE type='config' AND name LIKE '$v;;%'"); $r=@mysql_fetch_array($s); return $r['data']; }
//BREADCRUMBS
function breadcrumbs($sepchar=" · ") {
global $qAction;
if($_SESSION['validUser']==TRUE) $crumbs[]='<a href="'.db("website").'?admin">Admin</a>';
$crumbs[]='<a href="'.db("website").'">Home</a>';
$categories=categoryList();
if($qAction[0]=="search") $crumbs[]='<a href="'.db("website").'?search">Search</a>'; //For searches, just a link
elseif($qAction[0]=="list") { //For lists, check for subcategories
$id=$qAction[1]; $trigger= (is_numeric($id)) ? "id='$id'":"sef_title='$id'";
$position=search_in_array($id,$categories);
$key = key($position);
$crumbs[]='<a href="'.db("website").'?list.'.$categories[$key][0]['sef_title'].'">'.$categories[$key][0]['title'].'</a>';
$subkey = key($position[$key]) or FALSE;
if ($subkey) $crumbs[]='<a href="'.db("website").'?list.'.$categories[$key][$subkey][0]['sef_title'].'">'.$categories[$key][$subkey][0]['title'].'</a>';
}
elseif($qAction[0]=="article"||$qAction[0]=="page") { //For content, check for subcategories
$id=$qAction[1];
$trigger= (is_numeric($id)) ? "id='$id'":"sef_title='$id'";
$q=mysql_query("SELECT * FROM ".db("prefix")."content WHERE $trigger"); $r=mysql_fetch_array($q);
$position=search_in_array((int) $r['cat'],$categories);
$key = key($position);
$crumbs[]='<a href="'.db("website").'?list.'.$categories[$key][0]['sef_title'].'">'.$categories[$key][0]['title'].'</a>';
$subkey = key($position[$key]) or FALSE;
if ($subkey) $crumbs[]='<a href="'.db("website").'?list.'.$categories[$key][$subkey][0]['sef_title'].'">'.$categories[$key][$subkey][0]['title'].'</a>';
$crumbs[]=$r['title'];
}
$breadcrumbs=implode($sepchar, $crumbs);
echo $breadcrumbs;
}
//List parent/subcategories from base category
function categoryList() {
//Find all parent categories
$srch=mysql_query("SELECT * FROM ".db('prefix')."categories WHERE sub_id='0'");
while ($c=mysql_fetch_array($srch)) {
$id=(int) $c['id'];
$categories[$id][0]=array('id' => (int) $c['id'], 'title' => $c['title'],'sef_title' => $c['sef_title']);
}
//Find any possible child categories
foreach($categories as $id => $data) {
$srch=mysql_query("SELECT * FROM ".db('prefix')."categories WHERE sub_id='$id'");
while ($c=mysql_fetch_array($srch)) {
$subid=(int) $c['id'];
@$categories[$id][$subid][0]=array('id' => (int) $c['id'], 'title' => $c['title'],'sef_title' => $c['sef_title'], 'published' => $c['published']);
}
}
return $categories;
}
//Recursive Search in Array Function (used specifically for categories)
function search_in_array($needle,$haystack,$inverse=false,$limit=1){
#Settings
$path=array(); $count=0;
#Checkifinverse
if($inverse==true)
$haystack=array_reverse($haystack,true);
#Loop
foreach($haystack as $key=>$value){
#Checkforreturn
if($count>0&&$count==$limit)
return $path;
#Checkforval
if($value===$needle){
#Addtopath
$path[]=$key;
#Count
$count++;
}elseif(is_array($value)){
#Fetchsubs
$sub=search_in_array($needle,$value,$inverse,$limit);
#Checkiftherearesubs
if(count($sub)>0){
#Addtopath
$path[$key]=$sub;
#Addtocount
$count+=count($sub);
}
}
}
return $path;
}
//SQL FRIENDLY
//Makes code SQL and Textarea friendly
//Needs reworking
function SEFlinks() {
$pcs=func_get_args();
$seperator= (_value('enable-modrewrite')==0) ? '.':'/';
$qmark=(_value('enable-modrewrite')==0) ? '?':'';
return $qmark.implode($seperator, $pcs);
}
//PROCESS SYSTEM TITLE
function title($seperator='') {
global $qAction;
global $leap;
$title= ($seperator!='') ? _value('title')." $seperator "._value('slogan'): _value('title');
echo "<title>$title</title>";
if ($qAction[0]=="article"||$qAction[0]=="page") {
$col=(is_numeric($qAction[1])) ? 'id':'sef_title';
$q="SELECT * FROM ".db('prefix')."content WHERE $col='".$qAction[1]."'";
$r=mysql_fetch_array(mysql_query($q)); }
$keywords=_value('keywords');
if ($r['keywords']!='') $keywords.=', '.$r['keywords'];
$desc= ($r['description']!='') ? $r['description']:_value('description');
echo "\n".'<meta http-equiv="content-type" content="text/html; charset='._value('character-encoding').'" />'.
"\n".'<meta name="keywords" content="'.$keywords.'" />'."\n".'<meta name="description" content="'.$desc.'" />';
//Base HREF useful for ModRewrite
//echo "\n\n<base href=\"".db('website')."\" />\n\n";
//things that need to be performed in the header to go along with customized functions.
if (in_array($qAction[0], $leap->TitleFuncTriggers, TRUE)) {
$key= array_search($qAction[0], $leap->TitleFuncTriggers);
$TitleFunction=$leap->TitleFuncNames[$key];
$TitleFunction();
} //*/
}
//CHECK IF CURRENT VERSION OKAY
function checkUpdate() {
$check_url="http://leap.gowondesigns.com/checkupdate.php?"._value("version");
$handle=@fopen($check_url, "r"); $return=fgets($handle, 1024);
fclose($handle); $NEED_UPGRADE=explode(';',$return);
if ($NEED_UPGRADE[0]=='TRUE') $status="<p id=\"needUpgrade\"><a href=\"http://leap.gowondesigns.com/\">New version <b>$NEED_UPGRADE[1]</b> is available!</a></p>";
else $status="<p id=\"versionOkay\">Current version <b>$NEED_UPGRADE[1]</b> is okay!</p>";
return $status;
}
// SECURITY TOKEN FUNCTIONS
function rand_alphanumeric() {
$subsets[0] = array('min' => 48, 'max' => 57); // ascii digits
$subsets[1] = array('min' => 65, 'max' => 90); // ascii lowercase English letters
$subsets[2] = array('min' => 97, 'max' => 122); // ascii uppercase English letters
$s = rand(0, 2);
$ascii_code = rand($subsets[$s]['min'], $subsets[$s]['max']);
return chr( $ascii_code );
}
function token_label() { return md5( _value("security-key")); }
function make_token() {
$str = "";
for ($i=0; $i<7; $i++) $str .= rand_alphanumeric();
$pos = rand(0, 24);
$str .= chr(65 + $pos);
return $str . substr(md5($str . _value("security-key")), $pos, 8);
}
function verify_token($str) {
$rs = substr($str, 0, 8);
return $str == $rs . substr(md5($rs . _value("security-key")), ord($str[7])-65, 8);
}
//CONVERT FOR DB: Converting single- and double-quotes so they don't disrupt the Database
function convertForDb($input) {
//$input['text'] - The text being converted
//$input['type'] - options: db, screen
if($input['type']=='db') $text=str_replace(array("'",'"'),array("&#!","&##!"),$input['text']);
elseif($input['type']=='screen') $text=str_replace(array("&#!","&##!"),array("'",'"'),$input['text']);
return $text;
}
//Function to create simple HTML form elements
function formItem($item) {
$item['id']=(!$item['id']) ? '': ' id="'.$item['id'].'"';
$item['extra']=(!$item['extra']) ? '': ' '.$item['extra'];
if ($item['type']=='textarea'){
$item['value']=htmlentities($item['value'], ENT_QUOTES, _value('character-encoding'));
$formItem='<textarea name="'.$item['name'].'"'.$item['id'].$item['extra'].'>'.$item['value'].'</textarea>';
}
elseif ($item['type']=='checkbox'){
$item['value']=($item['value']==1) ? ' value="1" checked="checked"': ' value="1"';
$formItem='<input type="'.$item['type'].'"'.$class.' name="'.$item['name'].'"'.$item['id'].$item['value'].$item['extra'].' />';
}
else { //text, password, button, submit, refresh, checkbox, radio
if (ereg($item['type'],'(text|password)')) $class=' class="text"';
elseif (ereg($item['type'],'(button|submit|reset)')) $class=' class="button"';
else $class='';
$item['value']=(!isset($item['value'])) ? '': ' value="'.$item['value'].'"';
$formItem='<input type="'.$item['type'].'"'.$class.' name="'.$item['name'].'"'.$item['id'].$item['value'].$item['extra'].' />';
}
return $formItem."\n\n";
}
//FILE INCLUSION - slightly modified - from sNews 1.5 http://snews.solucija.com
function processIncludes($text, $shorten='') {
$fulltext= ($shorten!='') ? substr($text, 0, $shorten):$text;
$inc = strpos($fulltext, '[/include]');
if ($inc > 0) {
$text = str_replace('[include]', '|&|', $fulltext);
$text = str_replace('[/include]', '|&|', $text);
$text = explode('|&|', $text);
$num = count($text);
$extension = explode(',', _value('file-include-extensions'));
for ($i = 0; ; $i++) {
if ($i == $num) {break;}
if (!in_array(substr($text[$i], -4), $extension)) {echo substr($text[$i], 0);}
else {
if (preg_match("/^[a-z0-9_\-.\/]+$/i", $text[$i])) {
$filename = $text[$i];
file_exists($filename) ? include($filename) : print 'error_file_exists'; //MUST FINISH CODE
} else {echo 'error_file_name';} //MUST FINISH CODE
}
}
} else {echo $fulltext;}
}
// Function for timestamping and interpreting a pattern to adjust timestamp output
function timeStamp($data='',$format='') {
$format= ($format=='') ? _value('date-format'):$format;
if($data=='') $o=date("YmdHis"); //Creating timestamp YYYYMMDDHHMMSS
else { //Reformatting YYYYMMDDHHMMSS it into something readable
$yr=substr($data,0,4); $mo=substr($data,4,2);
$dy=substr($data,6,2); $hr=substr($data,8,2);
$mi=substr($data,10,2); $sc=substr($data,12,2);
$o=date($format, mktime($hr, $mi, $sc, $mo, $dy, $yr));
}
return $o; }
//Creating Search Engine Friendly names
function makeSEF($text) {
$text = trim($text);
if ( ctype_digit($text) ) return $text;
else {
$table = array(
''=>'S', ''=>'s', 'Ð'=>'Dj', ''=>'Z', ''=>'z', 'C'=>'C', 'c'=>'c', 'C'=>'C', 'c'=>'c',
'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E',
'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O',
'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U', 'Ú'=>'U', 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss',
'à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c', 'è'=>'e', 'é'=>'e',
'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o',
'ô'=>'o', 'õ'=>'o', 'ö'=>'o', 'ø'=>'o', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'ý'=>'y', 'þ'=>'b',
'ÿ'=>'y', 'R'=>'R', 'r'=>'r',
);
$text=strtr($text, $table);
// clean out the rest
$replace = array('/[^A-Za-z0-9 \-]+/','/(\s|\-)+/','/^-+|-+$/');
$with = array('','-','');
$text = preg_replace($replace,$with,$text);
}
return strtolower($text);
}
//Function used to truncate display text
function truncateText($string, $limit="", $break=" ") {
$limit=($limit=="") ? _value('list-char-limit'):$limit;
// return with no change if string is shorter than $limit
if($limit>0){ if(strlen($string)<=$limit) return $string; $string=substr($string,0,$limit);
if(false !== ($breakpoint=strrpos($string, $break))) $string=substr($string, 0, $breakpoint); }
if(false !== ($breakpoint=strrpos($string, "[BREAK]"))) $string=substr($string, 0, $breakpoint);
return $string; }
//PARSE OUTPUT TEXT
function parseText( $input ) {
//$input['type']; - arcticle, page, list, extra, custom
//$input['content-id']; if an article, page, list, or extra
//$input['custom-format'];
//$input['custom-text'];
//What format does the site need to be in
if ($input['type']=='list') $format=_value('list-format');
elseif ($input['type']=='article') $format=_value('article-format');
elseif ($input['type']=='page') $format='';
elseif ($input['type']=='custom') $format=$input['custom-format'];
$tags=array('[ID]','[SEF_TITLE]','[TITLE]','[DATE]','[MODIFIED]','[AUTHOR]','[EMAIL]','[EDIT]','[COMMENT]','[BODY]');
$nm=0;
if ($input['type']=='article'||$input['type']=='list') {
$oP=convertForDb(array('text' => $format, 'type' => 'screen'));
$s=mysql_query("SELECT * FROM ".db('prefix')."content WHERE id='".$input['content-id']."'"); $r=mysql_fetch_array($s);
$q=mysql_query("SELECT * FROM ".db('prefix')."users WHERE id='$r[auth]'"); $u=mysql_fetch_array($q);
$edit=($_SESSION['userId']==$r['auth']&&isAble('MANAGE_ARTICLES')||$_SESSION['userId']!=$r['auth']&&isAble('MANAGE_OTHER_ARTICLES')) ? "<p id=\"editContent\"><a href=\"?admin.articles.edit.$r[id]\">Edit</a></p>":'';
$d=mysql_query("SELECT * FROM ".db('prefix')."comments WHERE pid='$r[id]' AND approved='1' ORDER BY id DESC");
while($c=mysql_fetch_array($d)) $nm++;
$com=($nm>0) ? "View Comments ($nm)":"Add Comment"; $comment= (_value('allow-comment')==1&&$r['comments']==1) ? " <a href=\"?article.$r[sef_title]#comments\">$com</a>":'';
$body=convertForDb(array('text' => $r['body'], 'type' => 'screen')); $date=timeStamp($r['date']); $moddate=timeStamp($r['moddate']);
// Truncating text when in list mode
if($input['type']=='list' && FALSE !== ($breakpoint=strrpos($body, '[BREAK]'))) $body=substr($body, 0, $breakpoint);
else $body=str_replace('[BREAK]','',$body);
$title=convertForDb(array('text' => $r['title'], 'type' => 'screen'));
$code=array($r['id'],$r['sef_title'],$title,$date,$moddate,$u['name'],$u['mail'],$edit,$comment,$body);
$oP=str_replace($tags,$code,$oP);
$oP= (_value('allow-comment')==1&&$r['comments']==1) ? preg_replace('/\[C\=([ 0-9a-zA-Z]+)\]/',' <a href="#comments" title="Add/View Comments">\\1</a>',$oP):preg_replace('/\[C\=([ 0-9a-zA-Z]+)\]/','',$oP);
//Modify the output for a page
} elseif ($input['type']=='page') {
$s=mysql_query("SELECT * FROM ".db('prefix')."content WHERE id='".$input['content-id']."'"); $r=mysql_fetch_array($s);
$q=mysql_query("SELECT * FROM ".db('prefix')."users WHERE id='$r[auth]'"); $u=mysql_fetch_array($q);
$body=convertForDb(array('text' => $r['body'], 'type' => 'screen'));
//$edit=($_SESSION['userId']==$r['auth']&&isAble('CREATE_PAGE')||$_SESSION['userId']!=$r['auth']&&isAble('EDIT_OTHER_PAGE')) ? " <a href=\"?admin.pages.edit.$r[id]\">Edit P</a>":'';
$d=mysql_query("SELECT * FROM ".db('prefix')."comments WHERE pid='$r[id]' AND approved='1' ORDER BY id DESC");
while ($c=mysql_fetch_array($d)) $nm++;
$com=($nm>0) ? "View Comments ($nm)":"Add Comment"; $comment= (_value('allow-comment')==1&&$r['comments']==1) ? " <a href=\"?article.$r[sef_title]#comments\">$com</a>":'';
$date=timeStamp($r['date']); $moddate=timeStamp($r['moddate']);
// Truncating text
$body=str_replace('[BREAK]','',$body);
$title=convertForDb(array('text' => $r['title'], 'type' => 'screen'));
$code=array($r['id'],$r['sef_title'],$title,$date,$moddate,$u['name'],$u['mail'],'',$comment,'');
$oP=str_replace($tags,$code,$body);
$oP= (_value('allow-comment')==1&&$r['comments']==1) ? preg_replace('/\[C\=([ 0-9a-zA-Z]+)\]/',' <a href="#comments" title="Add/View Comments">\\1</a>',$oP):preg_replace('/\[C\=([ 0-9a-zA-Z]+)\]/','',$oP);
if (isAble('MANAGE_PAGES')) $oP.="\n<p id=\"editContent\"><a href=\"?admin.pages.edit.$r[id]\">Edit</a></p>";
}
return $oP;
}
//Menu Handler (To allow people to create and position their own menus)
function menu($menu){
$numargs=func_num_args(); $argument=func_get_args();
if ($numargs < 1) return FALSE;
$NOTITLE=FALSE;
$NOACTIVE=FALSE;
$NOLAST=FALSE;
$NOEDIT=FALSE;
$menuName=$argument[0];
$format=$argument[1];
for ($i = 2; $i < $numargs; $i++) {
if ($argument[$i]=='notitle') $NOTITLE=TRUE;
if ($argument[$i]=='noactive') $NOACTIVE=TRUE;
if ($argument[$i]=='nolast') $NOLAST=TRUE;
if ($argument[$i]=='noedit') $NOEDIT=TRUE;
}
if( $format == '' || $format == 'default') $format = "<li>%s</li>";
if( $format == 'nolist' ) $format = '%s';
$s=mysql_query("SELECT * FROM ".db("prefix")."menus WHERE name='$menuName'"); $r=mysql_fetch_array($s);
$m=explode(";;",$r['data']); $n=0;
$links_html= ($format == "<li>%s</li>") ? "\n<ul class=\"$menuName\">": "\n";
$links_html.= (!$NOTITLE && $format == "<li>%s</li>") ? "\n<li id=\"menutitle\">".$r['title'].'</li>': '';
while(count($m)>$n) {
$name=$m[$n]; $n++;
$url= (substr($m[$n],0,1)=="[" && substr($m[$n],strlen($m[$n])-1,1)=="]") ? '?'.substr($m[$n],1,strlen($m[$n])-2): $m[$n];
$link='<a href="'.$url.'"';
$link.= (!$NOACTIVE && db('query')==$m[$n]) ? ' id="active"': ''; //is the page currently on the URL of the link
$link.= (!$NOLAST && count($m)==$n+1) ? ' id="last"': ''; //last item in link
$link.='>'.$name.'</a>'; $n++;
$links_html.= sprintf( $format, $link);
}
if(!$NOEDIT && isAble('MANAGE_SYSTEM')) $links_html.= sprintf( $format,"\n".'<a href="?admin.menus.edit.'.$r['id'].'" id="edit">Edit Menu</a></li>');
$links_html.= ($format == "<li>%s</li>") ? "\n</ul>": '';
echo $links_html;
}
//VIEWING CONTENT
function viewContent() {
global $qAction; $id=$qAction[1];
$trigger= (is_numeric($id)) ? "id='$id'":"sef_title='$id'";
$q=mysql_query("SELECT * FROM ".db("prefix")."content WHERE $trigger"); $r=mysql_fetch_array($q);
if ($r['id']&&($r['published']==1||$r['published']!=1&&isAble('MANAGE_SYSTEM'))) {
$content=($r['type']=='page') ? parseText(array('type' => 'page', 'content-id' => $r['id'])):parseText(array('type' => 'article', 'content-id' => $r['id']));
processIncludes($content);
//COMMENTS
if (_value('allow-comment')==1&&$r['comments']==1) {
if ($_SESSION['ctime']>=time()&&$_SESSION['cid']==$r['id']) { $cdisable=TRUE;} //flood protection
elseif(isset($_POST['comment'])&&$_POST['confirmemail']=='') {
if(!$_POST['msg']) { $cstatus='<p>Error: There is no content.</p>'; }
else {
$pid=$r['id']; $name=$_POST['name']; $url=$_POST['url']; $date=timeStamp(); $msg=convertForDb(array('type' => 'screen', 'text' => $_POST['msg']));
$_SESSION['ctime']=time()+180; $_SESSION['cid']=$r['id']; $mcom= (_value('mod-comment')==1) ? 2:1;
$ip = $_SERVER['REMOTE_ADDR'];
$q="INSERT INTO ".db('prefix')."comments(pid,name,date,ip,url,comment,approved) VALUES('$pid','$name','$date','$ip','$url','$msg','$mcom')";
mysql_query($q) or $cstatus=mysql_error(); $cstatus='<p>Comment Posted.</p>';
}
}
$funcOutput.='<a name="comments"></a>';
$d=mysql_query("SELECT * FROM ".db('prefix')."comments WHERE pid='$r[id]' AND approved='1'");
$c=mysql_fetch_array($d);
if ($c['id']) {
$funcOutput.='<div id="comments"><h2>Comments</h2>';
$d=mysql_query("SELECT * FROM ".db('prefix')."comments WHERE pid='$r[id]' AND approved='1' ORDER BY id DESC");
while ($c=mysql_fetch_array($d)) {
$link= (stristr($c['url'], '@')!=FALSE) ? "mailto:$c[url]":$c['url'];
$funcOutput.="<p>".convertForDb(array('type' => 'screen', 'text' => $c['comment']))."<br />by <a href=\"$link\">$c[name]</a> at ".timeStamp($c['date'])."</p>";
}
$funcOutput.='</div>'; }
if ($cdisable!=TRUE) {
$funcOutput.='<div id="addcomments"><h2>Add Comment</h2>
<form action="?'.db('query').'" method="post">
<p>Name: '.formItem(array('type' => 'text', 'name' => 'name')).'</p>
<p>URL/Email: '.formItem(array('type' => 'text', 'name' => 'url')).'</p>
<p style="display: none;">Spam Control: '.formItem(array('type' => 'text', 'name' => 'confirmemail')).'</p>
<p>Comment: '.formItem(array('type' => 'textarea', 'name' => 'msg')).'</p>
<p>'.formItem(array('type' => 'submit', 'name' => 'comment', 'value'=>'Submit Comment'))."</p>$cstatus</form></div>";
}
}//finished comments
echo $funcOutput;
} else { echo '<p>Sorry, the page you are looking for is disabled or does not exist.
<br />You will be redirected to <a href="'.db('website').'">'.db('website').'</a>.</p><script language="javascript">//<!--
setTimeout("location.href = \''.db('website').'\';", 4000); //-->
</script>'; }
} //END OF FUNCTION
//EXTRA CONTENT FUNCTION
function extra() {
global $qAction; $contentId=''; $categoryId='';
$numargs=func_num_args(); $argument=func_get_args();
if ($numargs < 1) return FALSE;
$space="AND ( space='".implode("' OR space='",$argument)."')";
if ($qAction[0]=="article"||$qAction[0]=="page") {
$col=(is_numeric($qAction[1])) ? 'id':'sef_title';
$q="SELECT * FROM ".db('prefix')."content WHERE $col='".$qAction[1]."'";
$r=mysql_fetch_array(mysql_query($q));
$contentId="OR for_content LIKE '%(".$r['id'].")%'";
$categoryId="OR for_cat='0' OR for_cat='".$r['cat']."'";
}
$q=mysql_query("SELECT * FROM ".db('prefix')."extra WHERE ( ( for_process LIKE '%(".$qAction[0].")%' $categoryId $contentId ) AND published='1') $space ORDER BY position ASC");
while ($e=mysql_fetch_array($q)) {
$body=convertForDb(array('type' => 'screen', 'text' => $e['body']));
processIncludes($body);
//if(isAble('MANAGE_SYSTEM')) echo "<p id=\"admin\"><a href=\"?admin.pages.edit.$e[id]\">Edit</a></p>";
}
}
//Admin Link, will change depending on the user's status
function login() { $s=($_SESSION['validUser']==TRUE) ? 'Admin':'Login'; echo '<a href="?admin">'.$s.'</a>'; }
//Search Bar
function search() { echo '<form class="searchbar" action="?search" method="post"><p><input type="text" id="searchbar" name="searchterm" value="Search Site" onfocus="if (this.value == \'Search Site\') this.value=\'\';" onblur="if (this.value == \'\') this.value=\'Search Site\';" /> <input id="searchbutton" name="submit" type="submit" value="Search" /></p></form>'; }
//Search Function, Updated 2/28/08
function contentSearch() {
global $qAction; $searchterm=($qAction[1]) ? makeSEF($qAction[1]):makeSEF($_POST['searchterm']); $search=str_replace('-',' ',$searchterm);
echo '<div class="search"><form action="?search" method="post"><p>'.formItem(array('type'=>'text','name'=>'searchterm','value'=>$search)).formItem(array('type'=>'submit','name'=>'submit','value'=>'Search')).'</p></form>';
if($searchterm=='') {echo '</div>'; return FALSE; }
$max=_value('search-num-content'); $num= ($qAction[2]<1) ? 1:$qAction[2]; $pg=($num-1)*$max;
if (eregi(" AND | NOT | OR ",$search,$matches)) $search=str_replace($matches,'',$search);
$keywords = explode(' ', $search);
$keyCount = count($keywords);
$query = "SELECT *, 0.6 * MATCH(title) AGAINST('$search' IN BOOLEAN MODE) + 0.2 * MATCH(description) AGAINST('$search' IN BOOLEAN MODE) + 0.8 * MATCH(keywords) AGAINST('$search' IN BOOLEAN MODE) + 0.9 * MATCH(body) AGAINST('$search' IN BOOLEAN MODE) AS rank
FROM ".db('prefix')."content
WHERE MATCH(body,title,keywords,description) AGAINST('$search' IN BOOLEAN MODE) AND published='1'
ORDER BY rank DESC";
$pquery=$query.';'; $query.=" LIMIT $pg, $max;"; //echo $query;
$count = mysql_query($pquery);
$result = mysql_query($query);
$numrows = mysql_num_rows($count);
if (!$numrows) { echo '<p>No Results Found.</p></div>'; }
else {
foreach ($keywords as $searchitem) $searchlist.='<a href="?search.'.$searchitem.'">'.$searchitem.'</a> ';
echo '<p><strong>'.$numrows.'</strong> result(s) found for "<strong>'.$searchlist.'</strong>"</p></div>';
while ($r = mysql_fetch_array($result)) {
$tags = explode(',', $r['keywords']); $taglist='';
foreach ($tags as $tag) $taglist.='<a href="?search.'.makeSEF($tag).'">'.$tag.'</a> ';
$c = mysql_fetch_array(mysql_query("SELECT * FROM ".db('prefix')."categories WHERE id='".$r['cat']."'"));
echo "\n\n<hr class=\"searchruler\" /><p class=\"searchresult\">".ucwords($r['type']).': <strong><a href="?'.$r['type'].'.'.$r['sef_title'].'">'.$r['title'].'</a></strong> ( '.timeStamp($r['date']).' | <a href="?list.'.$c['sef_title'].'">'.$c['title'].'</a> )';
echo '<span id="rank"><strong>Rank:</strong> '.$r['rank'].'</span><br />Tags: '.$taglist.'</p>';
//if ($r['type']=='article') echo parseText(array('type' => $r['type'], 'content-id' => $r['id']));
}
}
//Pagination
pagination($pquery,$num,'',urlencode($searchterm));
}
//PERMISSION HANDLER
function permHandler($p) {
$permission['MANAGE_SYSTEM']= (strpos($p,'a')=== false) ? FALSE: TRUE;
$permission['MANAGE_USERS']= (strpos($p,'b')=== false) ? FALSE: TRUE;
$permission['MANAGE_EXTENSIONS']= (strpos($p,'c')=== false) ? FALSE: TRUE;
$permission['MANAGE_CATEGORIES']= (strpos($p,'d')=== false) ? FALSE: TRUE;
$permission['MANAGE_PAGES']= (strpos($p,'e')=== false) ? FALSE: TRUE;
$permission['MANAGE_ARTICLES']= (strpos($p,'f')=== false) ? FALSE: TRUE;
$permission['MANAGE_OTHER_ARTICLES']= (strpos($p,'g')=== false) ? FALSE: TRUE;
$permission['MANAGE_COMMENTS']= (strpos($p,'h')=== false) ? FALSE: TRUE;
return $permission;
}
function isAble($option) { return $_SESSION['userPerms'][$option]; }
//PAGINATION (JS Form and List Buttons)
function pagination($query,$page,$category='',$search='') {
$count=$s=mysql_query($query); $max=_value('num-articles'); $f=$g=0;
if ($category!='') $category='.'.$category; if ($page==0) $page=1;
$listnum=_value('pagination-button-number');
$prefix=($search=='') ? "list$category":"search.$search";
//echo mysql_num_rows($count);
if(mysql_num_rows($count)<=$max) return FALSE;
if(_value('js-enabled-pagination')==TRUE) { //JS Form
echo '<div id="pagination"><form action="#" id="page-jump"><p>';
if ($page>1) echo "<a href=\"?$prefix.".($page-1)."\" title=\"Go to the next page\"><<</a> ";
echo'Page: <select name="page" onchange="location=document.getElementById(\'page-jump\').page.options[document.getElementById(\'page-jump\').page.selectedIndex].value;">';
while($r=mysql_fetch_array($s)) { $f++; if($f%$max==0) { $g++; $d=($page==$g) ? ' selected="selected"':''; echo "\n<option value=\"?$prefix.$g\"$d>$g</option>"; } }
echo "</select>";
if ($page<$g) echo " <a href=\"?$prefix.".($page+1)."\" title=\"Go to the next page\">>></a>";
echo "</p></form>\n</div>";
} else { // Just Regular Links
$header="<div id=\"pagination\"><ul>\n"; $footer="</ul></div>\n";
if ($page>1) $header.="<li><a href=\"?$prefix.1\" title=\"Go to the first page\">First</a></li >";
if ($page>2) $header.="<li><a href=\"?$prefix.".($page-1)."\" title=\"Go to the previous page\">Prev</a></li> ";
while($r=mysql_fetch_array($s)) { $f++; if($f%$max==0) { $g++; $listItem[]="\n<li><a href=\"?$prefix.$g\">$g</a></li> "; } } //count total number of pages
if ($page<$g) $footer="<li><a href=\"?$prefix.".($g)."\" title=\"Go to the last page\">Last</a></li> $footer";
if ($page<($g-1)) $footer="<li><a href=\"?$prefix.".($page+1)."\" title=\"Go to the next page\">Next</a></li> $footer";
$hi=$lo=floor($listnum/2); //set high and low range
if (($page-$lo)<0) { $hi+=$lo-($page-0); $lo=$page; } //if current # - lo less than one
if (($page+$hi)>$g) { $lo+=$hi-($g-$page); $hi=$page; } //if current # + hi is greater than actual # of pages
//echo 'Total='.$g.'; Lo='.$lo.'; Hi='.$hi.'; Page='.$page; #Total=8; Lo=6; Hi=0; Page=5
for ($i=$page-$lo; $i<$page+$hi; $i++) { $list.=$listItem[$i].' '; }
echo $header.$list.$footer;
} } //End of Function
//Session handling class to improve security and consistency
class leapInit {
var $sessionNames='userName,userMail,userId,passWord,validUser,userPerms,lastLogin';
var $SpecFuncTriggers=array('rss');
var $SpecFuncNames=array('rss');
var $TitleFuncTriggers=array('rss');
var $TitleFuncNames=array('rss');
// TODO: Complete Archive and Sitemap functions
var $FuncTriggers=array('article','search','page','admin','list');
var $FuncNames=array('viewContent','contentSearch','viewContent','leapAdmin','createList');
//Check Session at the beginning of the script, then clean/set values
function checkSession() {
if($_POST['login']=='Login') { $_SESSION['userMail']=$_POST['email']; $_SESSION['passWord']=md5($_POST['pwd']);
//Cookie used for the Recent Activity feature
//setcookie("LeapLastLogin", $_COOKIE['LeapCurrentLogin'], time()+31556926);
$_SESSION['lastLogin']=$_COOKIE['LeapLastLogin'];
setcookie("LeapLastLogin", date("YmdHis"), time()+31556926);
}
$i=@mysql_query("SELECT * FROM ".db('prefix')."users WHERE mail='$_SESSION[userMail]' AND pwd='$_SESSION[passWord]'"); $d=@mysql_fetch_array($i);
$_SESSION['validUser']=(!$d['id']) ? FALSE:TRUE;
$_SESSION['userName']=$d['name']; $_SESSION['userId']=$d['id']; $_SESSION['userPerms']=permHandler($d['permissions']);
if ($_SESSION['validUser']==FALSE||$_POST['login']=='Logout') $this->cleanSession();
}
//Changing pre-existing session values, not meant to make any new ones.
function editSession($name,$value) { if (isset($_SESSION[$name])) $_SESSION[$name]=$value; else return FALSE; }
//Whenever someone logs out, the session is clean, not destroyed (so it won't disrupt other Session-reliant apps)
function cleanSession() { $name=explode(',',$this->sessionNames);
foreach ($name as $value) { unset($_SESSION[$value]); }
}
function updateContent() {
$query="UPDATE ".db('prefix')."content SET published='1' WHERE published='2' AND date<='".timeStamp()."'";
mysql_query($query);
$query="UPDATE ".db('prefix')."content SET published='0', unpublish='0' WHERE unpublish='1' AND enddate<='".timeStamp()."'";
mysql_query($query);
}
} //End of class
//for all "?list" actions
function createList() {
global $qAction;
if ($qAction[1]=="categories") {
echo "<ul id=\"categories\">";
$d=mysql_query("SELECT * FROM ".db('prefix')."categories WHERE published='1' ORDER BY id ASC");
while($c=mysql_fetch_array($d)) {
$s=mysql_query("SELECT * FROM ".db('prefix')."content WHERE published='1' AND type='article' AND cat='$c[id]' ORDER BY date DESC"); $nm=0;
while ($r=mysql_fetch_array($s)) { $nm++; }
$a= ($nm==1) ? "article":"articles";
echo "<li><h1><a href=\"?list.$c[sef_title]\">$c[title]</a> ($nm $a)</h1>";
echo "<h2>$c[description]</h2></li>";
}
$s=mysql_query("SELECT * FROM ".db('prefix')."content WHERE published='1' AND type='article' ORDER BY date DESC"); $nm=0;
while ($r=mysql_fetch_array($s)) { $nm++; }
$a= ($nm==1) ? "article":"articles";
echo "<li><h1><a href=\"?list\">View All</a> ($nm $a)</h1></li></ul>";
} else {
$query="SELECT * FROM ".db('prefix')."content WHERE published='1' AND type='article'";
$order=" ORDER BY date DESC";
if ($qAction[1]) {
// ?list.## - Global list at page ##
if (is_numeric($qAction[1])) $limit=" LIMIT ".($qAction[1]-1)*_value('num-articles').", "._value('num-articles');
// ?list.catname.## - List filtered with "catname" at page##
else {
$r=mysql_fetch_array(mysql_query("SELECT * FROM ".db('prefix')."categories WHERE sef_title='".$qAction[1]."'"));
$categoryID=$r['id']; $where=" AND cat='$categoryID'";
if ($qAction[2]) $limit=" LIMIT ".($qAction[2]-1)*_value('num-articles').", "._value('num-articles');
else $limit=" LIMIT 0, "._value('num-articles'); }
}
else $limit=" LIMIT 0, "._value('num-articles');
$s=mysql_query($query.$where.$order.$limit);
while($r=mysql_fetch_array($s)) { echo parseText(array('type' => 'list', 'content-id' => $r['id'])); }
//Pagination
if(isset($qAction[2])) $page=$qAction[2];
elseif(is_numeric($qAction[1])) $page=$qAction[1];
else $page=1;
$query="SELECT * FROM ".db('prefix')."content WHERE type='article'";
if (!is_numeric($qAction[1])&&$qAction[1]!='') $query.=$where;
$category=($categoryID!='') ? $qAction[1]:'';
pagination($query,$page,$category);
}
//End of function
}
function archive() { return FALSE; }
//SITEMAP FUNCTION
function sitemap() {
echo "<p>Pages</p>\n<p><ul><li><a href=\"?\">Home</a></li> ";
$s=mysql_query("SELECT * FROM ".db('prefix')."pages WHERE published='1'");
while ($r=mysql_fetch_array($s)) { echo "\n\n<li><a href=\"?$r[name]\">$r[name]</a></li> "; }
echo '<li><a href="?archive">Archive</a></li> <li><a href="?sitemap">Sitemap</a></li> <li><a href="?rss">RSS Feed</a></li> </ul></p>';
echo "\n\n<p><a href=\"?list\">Articles</a></p>";
$s=mysql_query("SELECT * FROM ".db('prefix')."categories WHERE published='1'");
while ($r=mysql_fetch_array($s)) {
echo "\n\n<p><a href=\"?list.$r[name]\">$r[title]</a><br /><ul> ";
$d=mysql_query("SELECT * FROM ".db('prefix')."content WHERE cat='$r[id]' LIMIT 0, 10");
while ($c=mysql_fetch_array($d)) { echo "\n\n<li><a href=\"?article.$c[id]\">$c[title]</a></li> "; }
echo "</ul></p>";
}
}
class adminPanel {
var $qAction;
var $panelTitle;
//this function creates the HTML for the Publish link
function pubButton($n,$id) { $pub[0]= ($n==1) ? 'unpublish':'publish'; if($n==1) $pub[1]='Unpub'; elseif($n==2) $pub[1]='Pending'; else $pub[1]='Pub'; return $isPub='<li><a href="?admin.'.$this->panelTitle.'.'.$pub[0].'.'.$id.'">'.$pub[1].'</a></li>'; }
// NEW ADMIN PANEL OPERATOR 1/14/2008 to replace the original
function panelContent() {
$this->qAction=parseQuery();
$this->panelTitle=$this->qAction[1];
$this->panelTable= (ereg($this->qAction[1],'(articles|pages)')) ? 'content':$this->panelTitle;
$title= (!$this->qAction[1]) ? 'Options':'Manage '.ucfirst($this->qAction[1]);
echo '<h1 class="adminheader" title="Manage your website" >'.$title.'</h1>
<div class="admindiv" id="panel2">';
if ($this->qAction[1]) {
if (ereg($this->qAction[2],'(add|edit)')) $this->addEditItem();
elseif ($this->qAction[2]=='delete') $this->deleteItem();
elseif ($this->qAction[2]=='purge') $this->purgeItem();
elseif ($this->qAction[2]=='settings') $this->editSystem();
elseif ($this->qAction[2]=='files') $this->fileManager();
elseif ($this->qAction[2]=='editfile') $this->editFile();
elseif ($this->qAction[2]=='deletefile') $this->deleteFile();
elseif ($this->qAction[2]=='rename') $this->renameFile();
elseif ($this->qAction[2]=='upload') $this->uploadFile();
elseif (ereg($this->qAction[2],'(unpublish|publish|reject|approve)')) $this->publishItem();
else $this->createList();
}
else { if(isAble('MANAGE_USERS')) echo '<p>Users: <a href="?admin.users.add">Add New</a> · <a href="?admin.users">Manage</a> · <a href="?admin.users.edit.'.$_SESSION['userId'].'">Edit My Account</a></p>';
if(isAble('MANAGE_SYSTEM')) echo '<p>Menus: <a href="?admin.menus.add">Add New</a> · <a href="?admin.menus">Manage</a></p>
<p>Extra Content: <a href="?admin.extra.add">Add New</a> · <a href="?admin.extra">Manage</a></p>';
if(isAble('MANAGE_EXTENSIONS')) echo '<p>Extensions: <a href="?admin.extensions">Manage</a></p>';
if(isAble('MANAGE_CATEGORIES')) echo '<p>Categories: <a href="?admin.categories.add">Add New</a> · <a href="?admin.categories">Manage</a></p>';
if(isAble('MANAGE_ARTICLES')||isAble('MANAGE_OTHER_ARTICLES')) echo '<p>Articles: <a href="?admin.articles.add">Add New</a> · <a href="?admin.articles">Manage</a> · <a href="?admin.articles.purge">Purge</a></p>';
if(isAble('MANAGE_PAGES')) echo '<p>Pages: <a href="?admin.pages.add">Add New</a> · <a href="?admin.pages">Manage</a></p>';
if(isAble('MANAGE_COMMENTS')) echo '<p>Comments: <a href="?admin.comments">Manage</a> · <a href="?admin.comments.purge">Purge</a></p>';
}
echo '</div>';
}
function editSystem() {
//did someone submit changes?
if (isset($_POST['editSystem'])) {
extract($_POST); $n=0;
while($total > $n) { mysql_query("UPDATE ".db('prefix')."system SET data='".convertForDb(array('type' => 'db', 'text' => $setting_data[$n]))."' WHERE type='config' AND id='$setting_id[$n]'"); $n++; }
echo "<p id=\"adminNotice\">Successfully Edited System<br /> <a href=\"?admin\">Return to Admin Home</a></p>";
return 0;
}
$s=mysql_query("SELECT * FROM ".db('prefix')."system WHERE type='config' AND id>1");
echo "<form method=\"post\" action=\"?".db('query')."\">"; //<input type=\"hidden\" name=\"name\" value=\"$r[name]\" /><input type=\"hidden\" name=\"$n\" value=\"$opt[$n]\" />"; $n++;
$n=0;
while($r=mysql_fetch_array($s)) { extract($r);
$namedata=explode(";;",$name);
$funcOutput.="<p><input type=\"hidden\" name=\"setting_id[$n]\" value=\"$id\" /><b>$namedata[1]</b><br />$namedata[2]<br />";
//$type=(ereg($name,'(keywords|description|list-format|article-format)')) ? 'textarea':'text';
$funcOutput.=formItem(array('type' => $namedata[3], 'name' => "setting_data[$n]", 'id' => "item_$n", 'value' => convertForDb(array('type' => 'screen', 'text' => $data)))).'</p>';
$n++;
}
echo $funcOutput.'<p>'.formItem(array('type' => 'hidden', 'name' => 'total', 'value' => $n)).formItem(array('type' => 'submit', 'name' => 'editSystem', 'value' => 'Save Settings')).formItem(array('type' => 'reset', 'value' => 'Reset')).'</p></form>';
}
function fileManager() {
if (isset($_POST['viewFolder'])) {
}
$file_dir=(isset($_POST['viewFolder'])) ? $_POST['path']:".";
$upload_view=".";
//Handle for the directory
if (!$handle=@opendir($upload_view)) echo "<span>Error!! Cannot open directory: ".$file_dir."</span>";
$ignore=array('..','.','.htaccess','cgi-bin','Thumbs.db','.htpasswd ');
while($item=@readdir($handle)) { if(!in_array($item,$ignore) && is_dir($item)) $dir[]=$item; if(!in_array($item,$ignore) && !is_dir($item)) $file[]=$item; }
@closedir($handle);
if($upload_view!=$file_dir) { $handle=@opendir($file_dir); unset($file);
while($item=@readdir($handle)) if(!in_array($item,$ignore) && !is_dir($item)) $file[]=$item;
@closedir($handle);
}
//Viewing Folders
echo '<p><form action="?admin.system.files" method="post">View Folder:<br /><select name="path">';
echo '<option value=".">/</option>';
foreach($dir as $d) echo '<option value="'.$d.'"'.(($d==$file_dir) ? ' selected="selected"':'').'>/'.$d.'/</option>';
echo '</select> '.formItem(array('type' => 'submit','name' =>'viewFolder','id'=>'view','value'=>'View')).' <a href="?admin">Return to Admin Home</a></p></form><p>';
foreach($file as $f) {
//get the filesize
$filesize=filesize($file_dir."/".$f);
$type=array('b','Kb','Mb');
for ($i=0; $filesize > 1024; $i++) $filesize /= 1024;
$filesize=round($filesize, 2).$type[$i];
//Check if the file is editable
$editable=array('.php','.css','.htm','html','.txt');
$ext=substr($f, -4);
$filepath=($file_dir!='.') ? str_replace(' ','%20', $file_dir.'%2F'.str_replace('.','%2E', $f)):str_replace(' ','%20',str_replace('.','%2E', $f));
$edit=(in_array($ext, $editable) && is_writable($f)) ? ' · <a href="?admin.system.editfile.'.$filepath.'">Edit</a>':'';
echo '<a href="'.$file_dir.'/'.$f.'">'.$f.'</a> ['.$filesize.']
<span>'.$edit.' · <a href="?admin.system.deletefile.'.$filepath.'">Del</a> · <a href="?admin.system.rename.'.$filepath.'">Rename</a></span><br />';
}
//Uploading Files
echo '</p><form action="?admin.system.upload" method="post" enctype="multipart/form-data"><p>Upload File:<br /><select name="path">';
echo '<option value=".">/</option>';
foreach($dir as $d) echo '<option value="'.$d.'"'.(($d==$file_dir) ? ' selected="selected"':'').'>/'.$d.'/</option>';
echo '</select> '.formItem(array('type' => 'file','name' => 'upfile')).' '.formItem(array('type' =>'submit','name'=>'uploadFile','value'=>'Upload File')).'<br />';
echo 'Save File As: (optional) '.formItem(array('type' => 'text','name' => 'saveas')).'</p></form>';
}
//DELETE FILE
function deleteFile() {
if (isset($_POST['deleteFile'])) {
$folder=(stristr($_POST['filepath'],'/')) ? explode('/',$_POST['filepath']): array('.',$_POST['filepath']);
unlink($_POST['filepath']);
echo "<p id=\"adminNotice\">Successfully Deleted <b>$folder[1]</b></p>";
$_POST['viewFolder']=TRUE;
$_POST['path']=$folder[0];
$this->fileManager();
return 0;
}
$filename=urldecode($this->qAction[3]);
$folder=(stristr($filename,'/')) ? explode('/',$filename): array('.',$filename);
echo '<form action="?admin.system.deletefile" method="post"><p>Are you sure you want to delete <b>/'.$filename.'</b>? This process cannot be reversed and the file cannot be recovered once deleted. <br />';
echo formItem(array('type' =>'hidden','name' =>'filepath','id'=>'filepath','value' =>$filename)).formItem(array('type' =>'submit','name'=>'deleteFile','id'=>'deleteFile','value'=>'Delete File')).'</p></form>';
}
//RENAME OR MOVE A FILE
function renameFile() {
if (isset($_POST['renameFile'])) {
$newpath=($_POST['newdir']=='.') ? $_POST['newname']:$_POST['newdir'].'/'.$_POST['newname'];
rename($_POST['oldpath'],$newpath);
echo "<p id=\"adminNotice\">Successfully Renamed <b>$_POST[newname]</b></p>";
$_POST['viewFolder']=TRUE;
$_POST['path']=$_POST['newdir'];
$this->fileManager();
return FALSE;
}
if (!$handle=@opendir('.')) echo "<span>Error!! Cannot open directory: </span>";
$ignore=array('..','.','.htaccess','cgi-bin','Thumbs.db','.htpasswd ');
while($item=@readdir($handle)) { if(!in_array($item,$ignore) && is_dir($item)) $dir[]=$item; }
@closedir($handle);
$filename=urldecode($this->qAction[3]);
$folder=(stristr($filename,'/')) ? explode('/',$filename): array('.',$filename);
echo '<form action="?admin.system.rename" method="post"><p>Move/Rename <b>/'.$filename.'</b>: <br /><select name="newdir">';
echo '<option value=".">/</option>';
foreach($dir as $d) echo '<option value="'.$d.'"'.(($d==$folder[0]) ? ' selected="selected"':'').'>/'.$d.'/</option>';
echo '</select> '.formItem(array('type'=>'hidden','name'=>'oldpath','value'=>$filename)).formItem(array('type'=>'text','name'=>'newname','value'=>$folder[1])).formItem(array('type'=>'submit','name'=>'renameFile','value'=>'Rename')).'</p></form>';
}
function uploadFile() {
if (isset($_POST['uploadFile']) && is_uploaded_file($_FILES["upfile"]["tmp_name"])) {
$filepath=$_POST['path'].'/';
$filename=(strlen($_POST['saveas'])>=6) ? $_POST['saveas']:$_FILES['upfile']['name'];
if ($_FILES["upfile"]["error"]>0) {
echo "<span id=\"adminNotice\">An Error Occured During Upload: <b>".$_FILES["upfile"]["error"]."</b></span>";
$this->fileManager();
}
elseif (file_exists($filepath.$filename)) {
echo "<span id=\"adminNotice\">An Error Occured During Upload: <b>$filename already exists</b></span>";
$this->fileManager();
} else {
move_uploaded_file($_FILES["upfile"]["tmp_name"],$filepath.$filename);
echo "<p id=\"adminNotice\">Successfully Uploaded <b>$filename</b>!</p>";
$_POST['viewFolder']=TRUE;
$this->fileManager();
}
} else $this->fileManager();
}
function editFile() {
//did someone submit changes?
if (isset($_POST['editFile'])) {
$content=stripslashes($_POST['content']);
$handle=fopen($_POST['filename'], 'w'); fwrite($handle, $content);
fclose($handle);
$folder=(stristr($_POST['filename'],'/')) ? explode('/',$_POST['filename']): array('.',$_POST['filename']);
echo "<p id=\"adminNotice\">Successfully Edited <b>$folder[1]</b></p>";
$_POST['viewFolder']=TRUE;
$_POST['path']=$folder[0];
$this->fileManager();
return FALSE;
}
$filename=urldecode($this->qAction[3]); //removeXSS($_POST['filename']);
if (file_exists($filename)&&is_writable($filename)) {
$handle = @fopen($filename, "r");
$contents = htmlentities(fread($handle, filesize($filename)),ENT_NOQUOTES);
fclose($handle);
echo "<form action=\"?admin.system.editfile\" method=\"post\">";