forked from ayang502/cms
/
cms.func.php
executable file
·1906 lines (1456 loc) · 56.2 KB
/
cms.func.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/* ------------------------------------
计数器
---------------------------------------
<cms action="COUNT" return="value" Function="count(*)" Field="" sql="" />
Function : count(*) | SUM(c.Price) | AVG(c.Price)
--------------------------------------- */
function CMS_COUNT($params)
{
global $db,$SYS_ENV,$table,$iWPC,$db_config,$cmsware,$PageInfo, $CONTENT_MODEL_INFO, $DSN_INFO;
$PageMode = false;
extract ($params, EXTR_PREFIX_SAME, "cms_");
$cache = empty($cache) ? 0 : 2;
$query = str_replace("#TABLE_HEADER#",$db_config['table_pre'], $query);
if(empty($nodeid)) { //所有节点
$list_where = '';
} elseif(preg_match("/^[0-9]+,[0-9]+/", $nodeid)) { //多个节点
$list_where.= " i.NodeID IN($nodeid)";
$nodeidArray = explode(',', $nodeid);
$NodeInfo = $iWPC->loadNodeInfo($nodeidArray[0]);
if(!$NodeInfo) {
echo "<B>Error:</B>The NodeID <font color=#FF0000>{$nodeidArray[0]}</font> you have set does not exist!";
return false;
}
} elseif(preg_match("/^all-[0-9]+/", $nodeid)) { //根节点并包括所有子节点
$nodeid = str_replace("all-",'',$nodeid);
$NodeInfo = $iWPC->loadNodeInfo($nodeid);
if(!$NodeInfo) {
echo "<B>Error:</B>The NodeID <font color=#FF0000>{$nodeid}</font> you have set does not exist!";
return false;
}
$nodeid=str_replace('%', ',', $NodeInfo[SubNodeID]);
$list_where.= " i.NodeID IN($nodeid)";
} elseif($nodeid == 'self') { //自动获取节点,可以多个节点共享一个模板,用的就是self
$nodeid = $GLOBALS[IN][NodeID];
$NodeInfo = $iWPC->loadNodeInfo($nodeid);
if(!$NodeInfo) {
echo "<B>Error:</B>The NodeID <font color=#FF0000>{$nodeid}</font> you have set does not exist!";
return false;
}
$list_where= " i.NodeID='$nodeid'";
} else {//单一一个节点
$NodeInfo = $iWPC->loadNodeInfo($nodeid);
if(!$NodeInfo) {
echo "<B>Error:</B>The NodeID <font color=#FF0000>{$nodeid}</font> you have set does not exist!";
return false;
}
$list_where= " i.NodeID='$nodeid'";
}
if(isset($nodeguid)) {
if(preg_match("/^[^,]+,[^,]+/", $nodeguid)) { //多个节点
//$list_where.= " AND i.NodeID IN($nodeid)";
foreach(explode(',', $nodeguid) as $key=>$var) {
$resultGUID = $db->getRow("select * from $table->site where NodeGUID='$var'", 2);
//$NodeInfo = $iWPC->loadNodeInfo($resultGUID['NodeID']);
if($key == 0) $nodeids = $resultGUID['NodeID'];
else $nodeids.=",".$resultGUID['NodeID'];
}
$list_where= " i.NodeID IN($nodeids)";
$NodeInfo = $iWPC->loadNodeInfo($resultGUID['NodeID']);
if(!$NodeInfo) {
echo "<B>Error:</B>The NodeGUID <font color=#FF0000>{$var}</font> you have set does not exist!";
return false;
}
} elseif(preg_match("/^all-[^,]+/", $nodeguid)) { //根节点并包括所有子节点
$nodeguid = str_replace("all-",'',$nodeguid);
$resultGUID = $db->getRow("select * from $table->site where NodeGUID='$nodeguid'",2);
$NodeInfo = $iWPC->loadNodeInfo($resultGUID['NodeID']);
if(!$NodeInfo) {
echo "<B>Error:</B>The NodeGUID <font color=#FF0000>{$nodeguid}</font> you have set does not exist!";
return false;
}
$nodeid=str_replace('%', ',', $NodeInfo[SubNodeID]);
$list_where.= " i.NodeID IN($nodeid)";
} else {
$resultGUID = $db->getRow("select * from $table->site where NodeGUID='$nodeguid'",2);
$NodeInfo = $iWPC->loadNodeInfo($resultGUID['NodeID']);
$list_where= " i.NodeID='".$resultGUID['NodeID']."'";
}
}
/**
自定义where标签
e.g : <where: c.Photo!=''> 可以实现只调用包括新闻图片的记录
*/
if(!empty($where)) {
$where = "AND ".$where;
}else {
$where = "";
}
/**
预设TableID,大部分情况下不用设置,系统会自动根据NodeID获取TableID
*/
if(empty($tableid)) {
if(!empty($NodeInfo))
$tableid = $NodeInfo[TableID];
}
//获得我们的内容模型表名称
$table_name = $db_config['table_pre'].$db_config['table_publish_pre'].'_'.$tableid;
$table_count = $db_config['table_pre'].'plugin_base_count';
$list_where1 = empty($list_where) ? "" : " AND ".$list_where;
if(empty($query)) {
$sql = "SELECT $function as TotalNum FROM $table->content_index i,$table->content_index i2 ,$table_name c where (i.PublishDate <= UNIX_TIMESTAMP() ) AND i.ParentIndexID=i2.IndexID AND i.IndexID =c.IndexID AND i2.State=1 AND i.State!=-1 AND i2.Type!=3 $list_where1 $where ";
} else {
$sql = $query;
}
//echo $sql;
$result = $db->getRow($sql);
return $result[TotalNum];
}
function CMS_SQL($params)
{ //print_r($params);
global $db,$SYS_ENV,$table,$iWPC,$db_config,$cmsware,$PageInfo, $CONTENT_MODEL_INFO, $DSN_INFO;
$PageMode = false;
extract ($params, EXTR_PREFIX_SAME, "cms_");
$cache = empty($cache) ? 0 : 2;
$query = str_replace("#TABLE_HEADER#",$db_config['table_pre'], $query);
/**
初始化调用数量sql
*/
if(empty($num)) {// 调用所有记录
$list_limit = ' ';
}elseif(preg_match("/^[0-9]+,[0-9]+$/", $num)){ //调用x,y条记录
list($start,$offset) = explode(",",$num);
$list_limit = " Limit $start,$offset ";
}elseif(preg_match("/^page-[0-9]+$/", $num)){ //分页调用
$offset = str_replace("page-",'', $num);
$offset = (int)$offset;
$PageMode = true;
}elseif(preg_match("/^[0-9]+$/", $num)) { //调用0,x条记录
$list_limit = " Limit 0,$num ";
}else
die("<font color =red >Fatal Error!</font> attribute 'num' invalid");
$sql_query = &$query;
//如果是分页调用模式.continue...
if($PageMode) {
if(preg_match("/select (.*) from/isU", $sql_query, $matches)) {
$sql_num = str_replace($matches[1], "Count(*) as TotalNum", $sql_query);
//echo $sql_num;
$result = $db->getRow($sql_num, 2);
$TotalNum = $result[TotalNum];
} else {
$TotalNum = 10;
}
$TotalPage = ceil($TotalNum/$offset);
$SYS_ENV[tpl_pagelist][run] = "yes";
if(empty($SYS_ENV[tpl_pagelist][page]))
$SYS_ENV[tpl_pagelist][page] = 0;
$start = ($SYS_ENV[tpl_pagelist][page])*$offset;
$SYS_ENV[tpl_pagelist][page] = $SYS_ENV[tpl_pagelist][page] + 1;
if(($start+$offset) >= $TotalNum)
$SYS_ENV[tpl_pagelist][run] = "no";
$list_limit = "Limit $start,$offset";
//if($NodeInfo[])
$list_page = list_page($TotalPage,$SYS_ENV[tpl_pagelist][page],$SYS_ENV[tpl_pagelist][filename]);
$cmsware['page'] = array (
'TotalNum' => $TotalNum,
'TotalPage' => $TotalPage,
'CurrentPage' => $SYS_ENV[tpl_pagelist][page],
'PageList' => $list_page,
'PageNum'=> $offset,
'URL'=> $SYS_ENV[tpl_pagelist][filename],
);
$PageInfo = $cmsware['page'];
//print_r($PageInfo);
}
$sql_query = $sql_query .' '. $list_limit;
//echo $sql_query;
$result = $db->Execute($sql_query, $cache);
while(!$result->EOF) {
if(isset($result->fields[NodeID])) {
$NInfo = $iWPC->loadNodeInfo($result->fields[NodeID]);
$result->fields[NodeInfo] = $NInfo;
$result->fields[NodeName] = $NInfo[Name];
$result->fields[NodeURL] = CMSware::cms_getHtmlURL($NInfo[IndexName], $NInfo);
}
$data[] = $result->fields;
$result->MoveNext();
}
return $data;
}
function CMS_LIST($params)
{
global $db,$SYS_ENV,$table,$iWPC,$db_config,$cmsware,$PageInfo, $CONTENT_MODEL_INFO, $DSN_INFO;
$PageMode = false;
extract ($params, EXTR_PREFIX_SAME, "cms_");
/**
初始化调用节点sql
*/
$cache = empty($cache) ? 0 : 2;
$isIgnore = false;
if(!empty($ignore)) {
$ignoreNodeIds = explode(',', $ignore);
$isIgnore = true;
}
//print_r($params);exit;
if(empty($nodeid)) { //所有节点
$list_where = '';
} elseif(preg_match("/^[0-9]+,[0-9]+/", $nodeid)) { //多个节点
$list_where.= " i.NodeID IN($nodeid)";
$nodeidArray = explode(',', $nodeid);
$NodeInfo = $iWPC->loadNodeInfo($nodeidArray[0]);
if(!$NodeInfo) {
echo "<B>Error:</B>The NodeID <font color=#FF0000>{$nodeidArray[0]}</font> you have set does not exist!";
return false;
}
} elseif(preg_match("/^all-[0-9]+/", $nodeid)) { //根节点并包括所有子节点
$nodeid = str_replace("all-",'',$nodeid);
$NodeInfo = $iWPC->loadNodeInfo($nodeid);
if(!$NodeInfo) {
echo "<B>Error:</B>The NodeID <font color=#FF0000>{$nodeid}</font> you have set does not exist!";
return false;
}
//$nodeid=str_replace('%', ',', $NodeInfo[SubNodeID]);
foreach(explode('%', $NodeInfo[SubNodeID]) as $key=>$var) {
if($isIgnore) {
if(in_array($var, $ignoreNodeIds)) {
continue;
} else {
$nodeid .= ",".$var;
}
$nodeid = substr($nodeid, 1);
} else {
if($key==0) $nodeid = $var;
else $nodeid .= ",".$var;
}
}
//add at 2006-1-10
if(substr($nodeid,0,1) == ',') $nodeid = substr($nodeid,1);
if(substr($nodeid,-1) == ',') $nodeid = substr($nodeid,0,-1);
$list_where.= " i.NodeID IN($nodeid)";
} elseif($nodeid == 'self') { //自动获取节点,可以多个节点共享一个模板,用的就是self
$nodeid = $GLOBALS[IN][NodeID];
$NodeInfo = $iWPC->loadNodeInfo($nodeid);
if(!$NodeInfo) {
echo "<B>Error:</B>The NodeID <font color=#FF0000>{$nodeid}</font> you have set does not exist!";
return false;
}
$list_where= " i.NodeID='$nodeid'";
} else {//单一一个节点
$NodeInfo = $iWPC->loadNodeInfo($nodeid);
if(!$NodeInfo) {
echo "<B>Error:</B>The NodeID <font color=#FF0000>{$nodeid}</font> you have set does not exist!";
return false;
}
$list_where= " i.NodeID='$nodeid'";
}
if(isset($nodeguid)) {
if(preg_match("/^[^,]+,[^,]+/", $nodeguid)) { //多个节点
//$list_where.= " AND i.NodeID IN($nodeid)";
foreach(explode(',', $nodeguid) as $key=>$var) {
$resultGUID = $db->getRow("select * from $table->site where NodeGUID='$var'", 2);
//$NodeInfo = $iWPC->loadNodeInfo($resultGUID['NodeID']);
if($key == 0) $nodeids = $resultGUID['NodeID'];
else $nodeids.=",".$resultGUID['NodeID'];
}
$list_where= " i.NodeID IN($nodeids)";
$NodeInfo = $iWPC->loadNodeInfo($resultGUID['NodeID']);
if(!$NodeInfo) {
echo "<B>Error:</B>The NodeGUID <font color=#FF0000>{$var}</font> you have set does not exist!";
return false;
}
} elseif(preg_match("/^all-[^,]+/", $nodeguid)) { //根节点并包括所有子节点
$nodeguid = str_replace("all-",'',$nodeguid);
$resultGUID = $db->getRow("select * from $table->site where NodeGUID='$nodeguid'",2);
$NodeInfo = $iWPC->loadNodeInfo($resultGUID['NodeID']);
if(!$NodeInfo) {
echo "<B>Error:</B>The NodeGUID <font color=#FF0000>{$nodeguid}</font> you have set does not exist!";
return false;
}
$nodeid=str_replace('%', ',', $NodeInfo[SubNodeID]);
$list_where.= " i.NodeID IN($nodeid)";
} else {
$resultGUID = $db->getRow("select * from $table->site where NodeGUID='$nodeguid'",2);
$NodeInfo = $iWPC->loadNodeInfo($resultGUID['NodeID']);
$list_where= " i.NodeID='".$resultGUID['NodeID']."'";
}
}
/**
初始化调用数量sql
*/
if(empty($num)) {// 调用所有记录
$list_limit = ' ';
}elseif(preg_match("/^[0-9]+,[0-9]+$/", $num)){ //调用x,y条记录
list($start,$offset) = explode(",",$num);
$list_limit = " Limit $start,$offset ";
}elseif(preg_match("/^page-[0-9]+$/", $num)){ //分页调用
$offset = str_replace("page-",'', $num);
$offset = (int)$offset;
$PageMode = true;
}elseif(preg_match("/^[0-9]+$/", $num)) { //调用0,x条记录
$list_limit = " Limit 0,$num ";
}else
die("<font color =red >Fatal Error!</font> attribute 'num' invalid");
/**
初始化排序字段sql
*/
$table_count_field = array(
'Hits_Total', 'Hits_Today', 'Hits_Week', 'Hits_Month', 'Hits_Date', 'CommentNum'
);
$INCLUDE_COUNT_TABLE = true; //包含计数表
$ORDER_BY_COUNT = false;
$orderby_field = preg_replace("/[\s]+DESC[\s]*/isU", "", $orderby);
$orderby_field = preg_replace("/[\s]+ASC[\s]*/isU", "", $orderby_field);
if(empty($orderby)) { //默认按照 置顶-权重-发布时间 排序
$list_orderby = " ORDER BY i.Top DESC,i.Sort DESC,i.PublishDate DESC";
} elseif($orderby == 'PublishDate'){ //兼容1.0.xx旧标签调用
$list_orderby = " ORDER BY i.Top DESC,i.Sort DESC,i.PublishDate DESC";
} elseif(in_array($orderby, $table_count_field)) {
$INCLUDE_COUNT_TABLE = true;
$ORDER_BY_COUNT = true;
$list_orderby = " ORDER BY {table_count}$orderby DESC";
} elseif(in_array($orderby_field, $table_count_field)) {
$INCLUDE_COUNT_TABLE = true;
$ORDER_BY_COUNT = true;
$list_orderby = " ORDER BY {table_count}$orderby ";
} else { //用户可以自定义orderby属性
$list_orderby = " ORDER BY $orderby ";
}
/**
自定义where标签
e.g : <where: c.Photo!=''> 可以实现只调用包括新闻图片的记录
*/
if(!empty($where)) {
$where = "AND ".$where;
}else {
$where = "";
}
/**
预设TableID,大部分情况下不用设置,系统会自动根据NodeID获取TableID
*/
if(empty($tableid)) {
if(!empty($NodeInfo))
$tableid = $NodeInfo[TableID];
}
//获得我们的内容模型表名称
$table_name = $db_config['table_pre'].$db_config['table_publish_pre'].'_'.$tableid;
$table_count = $db_config['table_pre'].'plugin_base_count';
if(!empty($returnkey)) {
foreach(explode(',', $returnkey) as $key=>$var) {
if($key==0) $c_return = "c.".$var;
else $c_return .= ",c.".$var;
}
} else {
$c_return .= "c.*";
}
//如果是分页调用模式.continue... date("Y-m-d H:i")
if($PageMode) {
$list_where1 = empty($list_where) ? "" : " AND ".$list_where;
$sql_num = "SELECT DISTINCT Count(*) as TotalNum FROM $table->content_index i,$table->content_index i2 ,$table_name c where (i.PublishDate <= UNIX_TIMESTAMP() ) AND i.ParentIndexID=i2.IndexID AND i2.IndexID =c.IndexID AND i2.State=1 AND i.State!=-1 AND i2.Type!=3 $list_where1 $where ";
//echo $sql_num;
$result = $db->getRow($sql_num, 2);
$TotalNum = $result[TotalNum];
$TotalPage = ceil($result[TotalNum]/$offset);
$SYS_ENV[tpl_pagelist][run] = "yes";
if(empty($SYS_ENV[tpl_pagelist][page]))
$SYS_ENV[tpl_pagelist][page] = 0;
$start = ($SYS_ENV[tpl_pagelist][page])*$offset;
$SYS_ENV[tpl_pagelist][page] = $SYS_ENV[tpl_pagelist][page] + 1;
if(($start+$offset) >= $TotalNum)
$SYS_ENV[tpl_pagelist][run] = "no";
$list_limit = "Limit $start,$offset";
//if($NodeInfo[])
$list_page = list_page($TotalPage,$SYS_ENV[tpl_pagelist][page],$SYS_ENV[tpl_pagelist][filename]);
$cmsware['page'] = array (
'TotalNum' => $TotalNum,
'TotalPage' => $TotalPage ,
'CurrentPage' => $SYS_ENV[tpl_pagelist][page],
'PageList' => $list_page,
'PageNum'=> $offset,
'URL'=> $SYS_ENV[tpl_pagelist][filename],
);
$PageInfo = $cmsware['page'];
//echo $list_where."-----------------------------------";
//print_r($PageInfo);
}
if($INCLUDE_COUNT_TABLE) {
//$sql_query = "SELECT i2.NodeID,i2.ContentID,i2.State,i2.URL,i.IndexID,i.PublishDate,i.Type,i.Sort,i.Pink, $c_return ,co.Hits_Total, co.Hits_Today, co.Hits_Week, co.Hits_Month, co.Hits_Date, co.CommentNum FROM $table->content_index i,$table->content_index i2 ,$table_name c LEFT JOIN $table_count co ON co.IndexID=i2.IndexID where (UNIX_TIMESTAMP() >= i.PublishDate) AND i.ParentIndexID=i2.IndexID AND i2.IndexID =c.IndexID AND i2.State=1 AND i.State=1 AND i2.Type!=3 $list_where $where $list_orderby $list_limit";
if($ORDER_BY_COUNT) {
if(empty($where)) {
$list_where = empty($list_where) ? '' : 'where'.$list_where;
$list_where = str_replace("i.","", $list_where);
$sql_query = "SELECT * From $table_count $list_where $list_orderby $list_limit";
$sql_query = str_replace("{table_count}","", $sql_query);
$result = $db->Execute($sql_query);
while(!$result->EOF) {
$NInfo = $iWPC->loadNodeInfo($result->fields[NodeID]);
$result->fields[NodeInfo] = $NInfo;
$result->fields[NodeName] = $NInfo[Name];
$result->fields[NodeURL] = CMSware::cms_getHtmlURL($NInfo[IndexName], $NInfo);
$tmpResult = $db->getRow("SELECT i.URL,i.PublishDate,i.Type,i.Sort,i.Pink, $c_return FROM $table->content_index i ,$table_name c where i.IndexID='".$result->fields['IndexID']."' AND c.ContentID=i.ContentID");
$data[] = array_merge($tmpResult, $result->fields);
$result->MoveNext();
}
// echo $sql_query;
return $data;
} else {
$list_where = empty($list_where) ? "" : " AND ".$list_where;
$sql_query = "SELECT i.NodeID,i.ContentID,i.State,i.URL,i.IndexID,i.PublishDate,i.Type,i.Sort,i.Pink, $c_return ,co.Hits_Total, co.Hits_Today, co.Hits_Week, co.Hits_Month, co.Hits_Date, co.CommentNum From $table_count co, $table->content_index i,$table_name c where co.IndexID=i.IndexID AND c.IndexID=i.IndexID $list_where $where $list_orderby $list_limit";
$sql_query = str_replace("{table_count}","co.", $sql_query);
}
} else {
$list_where = empty($list_where) ? "" : " AND ".$list_where;
$sql_query = "SELECT i2.NodeID,i2.ContentID,i2.State,i2.URL,i.IndexID,i.PublishDate,i.Type,i.Sort,i.Pink,co.*, $c_return FROM $table->content_index i,$table->content_index i2 , $table_name c , $table_count co where c.IndexID=i2.IndexID AND co.IndexID=i2.IndexID AND (UNIX_TIMESTAMP() >= i.PublishDate) AND i.ParentIndexID=i2.IndexID AND i2.State=1 AND i.State=1 AND i2.Type!=3 $list_where $where $list_orderby $list_limit";
}
//$result = $db->Execute($sql_query, $cache);
} else {
$list_where = empty($list_where) ? "" : " AND ".$list_where;
$sql_query = "SELECT i2.NodeID,i2.ContentID,i2.State,i2.URL,i.IndexID,i.PublishDate,i.Type,i.Sort,i.Pink,co.*, $c_return FROM $table->content_index i,$table->content_index i2 $table_name c , $table_count co where c.IndexID=i2.IndexID AND co.IndexID=i2.IndexID AND (UNIX_TIMESTAMP() >= i.PublishDate) AND i.ParentIndexID=i2.IndexID AND i2.State=1 AND i.State=1 AND i2.Type!=3 $list_where $where $list_orderby $list_limit";
}
if(!empty($debug)) {
echo $sql_num;
echo "<HR>".$sql_query."<HR>";
}
//echo $sql_query;
//$pub = new publishAdmin();
$result = $db->Execute($sql_query, $cache);
while(!$result->EOF) {
$NInfo = $iWPC->loadNodeInfo($result->fields[NodeID]);
//$pub->publishInfo = &$result->fields;
//$pub->NodeInfo = $NInfo;
//$pub->IndexID = $result->fields[ContentID];
/*foreach($result->fields as $key=>$var ) {
$pub->publishAll($var);
$result->fields[$key] = $var;
}*/
$result->fields[NodeInfo] = $NInfo;
$result->fields[NodeName] = $NInfo[Name];
$result->fields[NodeURL] = CMSware::cms_getHtmlURL($NInfo[IndexName], $NInfo);
$data[] = $result->fields;
$result->MoveNext();
}
return $data;
}
/**
* 内容调用CMS::CONTENT
* IndexID=1 return var[]
* IndexID=1,2,3 return var[IndexID][]
*/
function CMS_CONTENT($params)
{
global $db,$SYS_ENV,$table,$iWPC,$db_config,$cmsware;
extract ($params, EXTR_PREFIX_SAME, "cms_");
$cache = empty($cache) ? 0 : 2;
if(!empty($returnkey)) {
foreach(explode(',', $returnkey) as $key=>$var) {
if($key==0) $c_return = "c.".$var;
else $c_return .= ",c.".$var;
}
} else {
$c_return .= "c.*";
}
$pos = strpos($indexid, ',');
if(empty($indexid)) {// 调用所有记录
return false;
}elseif($pos !== false){ //调用x,y条记录
//exit($indexid);
$IndexIDs = explode(',', $indexid);
foreach($IndexIDs as $key=>$var) {
if(empty($var)) continue;
$NodeID= publishAdmin::getIndexInfo($var, $field = 'NodeID');
$NodeInfo = $iWPC->loadNodeInfo($NodeID);
if(!$NodeInfo) {
echo "<B>Error:</B>The IndexID <font color=#FF0000>{$indexid}</font> you have set does not exist!";
}
$table_name = $db_config['table_pre'].$db_config['table_publish_pre'].'_'.$NodeInfo[TableID];
$sql_query = "SELECT i2.NodeID,i2.ContentID,i2.State,i2.URL,i.IndexID,i.PublishDate,i.Type,i.Sort,i.Pink, $c_return FROM $table->content_index i,$table->content_index i2 ,$table_name c where (UNIX_TIMESTAMP() >= i.PublishDate) AND i.ParentIndexID=i2.IndexID AND i2.IndexID =c.IndexID AND i2.State=1 AND i.State!=-1 AND i2.Type!=3 AND i.IndexID='{$var}'";
$result[$var] = $db->getRow($sql_query, $cache);
$result[$var][NodeInfo] = $NodeInfo;
$result[$var][NodeName] = $NodeInfo[Name];
$result[$var][NodeURL] = CMSware::cms_getHtmlURL($NodeInfo[IndexName], $NodeInfo);
}
} else {
$NodeID= publishAdmin::getIndexInfo($indexid, $field = 'NodeID');
$NodeInfo = $iWPC->loadNodeInfo($NodeID);
if(!$NodeInfo) {
echo "<B>Error:</B>The IndexID <font color=#FF0000>{$indexid}</font> you have set does not exist!";
return false;
}
$table_name = $db_config['table_pre'].$db_config['table_publish_pre'].'_'.$NodeInfo[TableID];
$sql_query = "SELECT i2.NodeID,i2.ContentID,i2.State,i.URL,i.IndexID,i.PublishDate,i.Type,i.Sort,i.Pink, $c_return FROM $table->content_index i,$table->content_index i2 ,$table_name c where (UNIX_TIMESTAMP() >= i.PublishDate) AND i.ParentIndexID=i2.IndexID AND i2.IndexID =c.IndexID AND i2.State=1 AND i.State!=-1 AND i2.Type!=3 AND i.IndexID='{$indexid}'";
$returnResult = $db->getRow($sql_query, $cache);
$returnResult[NodeInfo] = $NodeInfo;
$returnResult[NodeName] = $NodeInfo[Name];
$returnResult[NodeURL] = CMSware::cms_getHtmlURL($NodeInfo[IndexName], $NodeInfo);
if($loopmode == '1') {
$result = array();
$result[] = $returnResult;
} else $result = $returnResult;
}
return $result;
}
/*
* 模板函数名称: 节点信息调用函数(标签调用)
*
* 用途: 获取指定NodeID的节点名称+节点首页的URL,返回一个2维数组
* array(
* [0] => array(
* 'Title'=> "节点名称"
* 'URL' => "节点首页URL"
* ...
* ..
* .
* )
* );
* 可以实现( 网站首页 | 新闻频道 | 下载频道 | 娱乐频道 | 生活频道 )这样的导航条的自动生成
* 甚至包括下拉菜单等的生成
* @access public
* @param array $params
* $params['type'] = sub|set 节点调用类型,sub(子节点调用,set(自定义节点调用)
* $params['nodeid'] = [0-9]+
* $params['ignore'] = [0-9]+,[0-9]+,[0-9]+...
* @return array
* @example 使用方法举例:
* 1. <CMS::NODELIST:List type="sub" nodeid="5">
* type="sub": 取nodeid为5下面的所有子节点,nodeid不能为空.
* 返回一个包含NodeInfo的2维数组
* 2. <CMS::NODELIST:List type="set" nodeid="2,5,8,12">
* type="set": 取指定nodeid的节点数据,nodeid的格式为"2,5,8,12"这样的格式, 节点间使用逗号分隔.
* 返回一个包含NodeInfo的2维数组
* $ignorenodeids:忽略节点id,使用,号分隔
*/
function CMS_NODELIST($params)
{
global $iWPC,$db,$table,$SYS_ENV,$db_config,$cmsware;
extract ($params, EXTR_PREFIX_SAME, "cms_");
$cache = empty($cache) ? 0 : 2;
$return = array();
$isIgnore = false;
if(!empty($ignore)) {
$ignoreNodeIds = explode(',', $ignore);
$isIgnore = true;
}
if(!empty($orderby)) {
$list_orderby = " ORDER BY $orderby ";
} else {
$list_orderby = " Order by NodeSort DESC ";
}
switch($type) {
case 'son':
case 'sub': //子节点
if($nodeid == '' && $nodeguid == '') {
$nodeid = $GLOBALS[IN][NodeID];
} elseif($nodeguid !='') {
$resultGUID = $db->getRow("select * from $table->site where NodeGUID='$nodeguid'", $cache);
$nodeid = $resultGUID['NodeID'];
}
$sql = "SELECT NodeID FROM $table->site WHERE ParentID='$nodeid' and Disabled=0 $list_orderby ";
$result = $db->Execute($sql, $cache);
while(!$result->EOF) {
if($isIgnore) {
if(in_array($result->fields[NodeID], $ignoreNodeIds)) {
$result->MoveNext();
continue;
}
}
$NInfo = $iWPC->loadNodeInfo($result->fields[NodeID]);
$NInfo['URL'] = CMSware::cms_getHtmlURL($NInfo[IndexName], $NInfo);
$NInfo['NodeURL'] = $NInfo['URL'];
$NInfo['NodeName'] = $NInfo[Name];
$NInfo['Title'] = $NInfo[Name];
$return[] = $NInfo;
$result->MoveNext();
}
break;
case 'parent': //父节点
if($nodeid == '' && $nodeguid == '') {
$nodeid = $GLOBALS[IN][NodeID];
} elseif($nodeguid !='') {
$resultGUID = $db->getRow("select * from $table->site where NodeGUID='$nodeguid'", $cache);
$nodeid = $resultGUID['NodeID'];
}
$ThisNodeInfo = $db->getRow("SELECT ParentID FROM $table->site WHERE NodeID='$nodeid' and Disabled=0 ", $cache);
$ParentNodeInfo = $db->getRow("SELECT ParentID FROM $table->site WHERE NodeID='".$ThisNodeInfo['ParentID']."' and Disabled=0 ", $cache);
$sql = "SELECT NodeID FROM $table->site WHERE ParentID='".$ParentNodeInfo['ParentID']."' and Disabled=0 $list_orderby ";
$result = $db->Execute($sql, $cache);
while(!$result->EOF) {
if($isIgnore) {
if(in_array($result->fields[NodeID], $ignoreNodeIds)) {
$result->MoveNext();
continue;
}
}
$NInfo = $iWPC->loadNodeInfo($result->fields[NodeID]);
$NInfo['URL'] = CMSware::cms_getHtmlURL($NInfo[IndexName], $NInfo);
$NInfo['NodeURL'] = $NInfo['URL'];
$NInfo['NodeName'] = $NInfo[Name];
$NInfo['Title'] = $NInfo[Name];
$return[] = $NInfo;
$result->MoveNext();
}
break;
case 'brother': //兄节点
if($nodeid == '' && $nodeguid == '') {
$nodeid = $GLOBALS[IN][NodeID];
} elseif($nodeguid !='') {
$resultGUID = $db->getRow("select * from $table->site where NodeGUID='$nodeguid'", $cache);
$nodeid = $resultGUID['NodeID'];
}
$ThisNodeInfo = $db->getRow("SELECT ParentID FROM $table->site WHERE NodeID='$nodeid' and Disabled=0 ", $cache);
$sql = "SELECT NodeID FROM $table->site WHERE ParentID='".$ThisNodeInfo['ParentID']."' and Disabled=0 $list_orderby ";
$result = $db->Execute($sql, $cache);
while(!$result->EOF) {
if($isIgnore) {
if(in_array($result->fields[NodeID], $ignoreNodeIds)) {
$result->MoveNext();
continue;
}
}
$NInfo = $iWPC->loadNodeInfo($result->fields[NodeID]);
$NInfo['URL'] = CMSware::cms_getHtmlURL($NInfo[IndexName], $NInfo);
$NInfo['NodeURL'] = $NInfo['URL'];
$NInfo['NodeName'] = $NInfo[Name];
$NInfo['Title'] = $NInfo[Name];
$return[] = $NInfo;
$result->MoveNext();
}
break;
break;
case 'set':
if($nodeid != '') {
$NodeIDs = explode(',', $nodeid);
foreach($NodeIDs as $key=>$var) {
$NInfo = $iWPC->loadNodeInfo($var);
$NInfo['URL'] = CMSware::cms_getHtmlURL($NInfo[IndexName], $NInfo);
$NInfo['NodeURL'] = $NInfo['URL'];
$NInfo['NodeName'] = $NInfo[Name];
$NInfo['Title'] = $NInfo[Name];
$return[] = $NInfo;
}
} elseif($nodeguid !='') {
foreach( explode(',', $nodeguid) as $key=>$var) {
$resultGUID = $db->getRow("select * from $table->site where NodeGUID='$var'", $cache);
$NInfo = $iWPC->loadNodeInfo($resultGUID['NodeID']);
$NInfo['URL'] = CMSware::cms_getHtmlURL($NInfo[IndexName], $NInfo);
$NInfo['NodeURL'] = $NInfo['URL'];
$NInfo['NodeName'] = $NInfo[Name];
$NInfo['Title'] = $NInfo[Name];
$return[] = $NInfo;
}
}
break;
}
//print_r($return);
return $return;
}
/**
* 获取节点内容
*
*
* <CMS::NODE:NodeInfo NodeID="$NodeID" >
* <a href=" [$NodeInfo.NodeURL]" title="确定">返回上一级</a> <br/>
* </CMS>
* $NodeID : '', 'self','parent','[0-9]*'
* '' : 自动获取NodeID,包括内容页属于的父节点NodeID,或者节点首页归属的节点NodeID
* 'self' : 等同于''
* 'parent' : 等同于''NodeID的父节点NodeID
* '[0-9]*' : 自定义NodeID,为数字
*
* @param array $params
* @access public
* @return array
*/
function CMS_NODE($params)
{
global $iWPC,$db,$table,$SYS_ENV,$db_config,$cmsware;
extract ($params, EXTR_PREFIX_SAME, "cms_");
$cache = empty($cache) ? 0 : 2;
if((empty($nodeid) || $nodeid == 'self') && $nodeguid =='') {
$nodeid = empty($GLOBALS[IN][NodeID]) ? $GLOBALS[NodeID] : $GLOBALS[IN][NodeID];
} elseif($nodeid == 'parent' && $nodeguid =='') {
$SonNodeID = empty($GLOBALS[IN][NodeID]) ? $GLOBALS[NodeID] : $GLOBALS[IN][NodeID];
$SonNodeInfo = $iWPC->loadNodeInfo($SonNodeID);
$nodeid = $SonNodeInfo['ParentID'];
} elseif($nodeguid !='') {
$resultGUID = $db->getRow("select * from $table->site where NodeGUID='$nodeguid'", $cache);
$nodeid = $resultGUID['NodeID'];
}
$NInfo = $iWPC->loadNodeInfo($nodeid);
$NInfo['URL'] = CMSware::cms_getHtmlURL($NInfo[IndexName], $NInfo);
$NInfo['NodeURL'] = $NInfo['URL'];
$NInfo['NodeName'] = $NInfo[Name];
$NInfo['Title'] = $NInfo[Name];
return $NInfo;
}
/**
* 获取节点内容
*
*
* <CMS action="ExtraPublish" NodeID="$NodeID" >
* <a href=" [$NodeInfo.NodeURL]" title="确定">返回上一级</a> <br/>
* </CMS>
* $NodeID : '', 'self','parent','[0-9]*'
* '' : 自动获取NodeID,包括内容页属于的父节点NodeID,或者节点首页归属的节点NodeID
* 'self' : 等同于''
* 'parent' : 等同于''NodeID的父节点NodeID
* '[0-9]*' : 自定义NodeID,为数字
*
* @param array $params
* @access public
* @return array
*/
function CMS_ExtraPublish($params)
{
global $iWPC,$db,$table,$SYS_ENV,$db_config,$cmsware,$_BeanFactory;
extract ($params, EXTR_PREFIX_SAME, "cms_");
$cache = empty($cache) ? 0 : 2;
if((empty($nodeid) || $nodeid == 'self') && $nodeguid =='') {
$nodeid = empty($GLOBALS[IN][NodeID]) ? $GLOBALS[NodeID] : $GLOBALS[IN][NodeID];
} elseif($nodeid == 'parent' && $nodeguid =='') {
$SonNodeID = empty($GLOBALS[IN][NodeID]) ? $GLOBALS[NodeID] : $GLOBALS[IN][NodeID];
$SonNodeInfo = $iWPC->loadNodeInfo($SonNodeID);
$nodeid = $SonNodeInfo['ParentID'];
} elseif($nodeguid !='') {
$resultGUID = $db->getRow("select * from $table->site where NodeGUID='$nodeguid'", $cache);
$nodeid = $resultGUID['NodeID'];
}
if(!empty($where)) {
$where = "AND ".$where;
}else {
$where = "";
}
$NodeInfo = $iWPC->loadNodeInfo($nodeid);
$ep = &$_BeanFactory->getBean('extra_publish');
//$extraInfo = $ep->getAll($nodeid);
$sql ="SELECT t.*, u.uName as LastModifiedUser FROM $table->extra_publish t left join $table->user u ON u.uId=t.LastModifiedUserID where t.NodeID='$nodeid' $where ";
$result = $db->Execute($sql);
while(!$result->EOF) {
$result->fields['URL'] = $ep->getView($result->fields['PublishID']);
$extraInfo[] = $result->fields;
$result->MoveNext();
}
return $extraInfo;
}
/*
* 模板函数名称:
* 用途: 搜索相关文章
* 传递的参数:
* nodeid 搜索节点id("1,2,3";"all-5";"self";"6","")
* field 搜索字段
* keywords 搜索关键字
* num 调用数量
* orderby 排序字段
$separator
$ignorecontentid
*/
function CMS_SEARCH($params)
{
global $iWPC,$db,$table,$SYS_ENV,$db_config,$cmsware,$PageInfo;
$PageMode = false;
extract ($params, EXTR_PREFIX_SAME, "cms_");
$cache = empty($cache) ? 0 : 2;
if(!empty($returnkey)) {
foreach(explode(',', $returnkey) as $key=>$var) {
if($key==0) $c_return = "c.".$var;
else $c_return .= ",c.".$var;
}
} else {
$c_return .= "c.*";
}
//exact精确查找
$exact = ($exact==1) ? true : false;
/**
初始化调用节点sql
*/
if(empty($nodeid)) { //所有节点
$list_where = '';