/
Archive.php
2275 lines (1954 loc) · 68.7 KB
/
Archive.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
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
/**
* Typecho Blog Platform
*
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
* @license GNU General Public License 2.0
* @version $Id: Posts.php 200 2008-05-21 06:33:20Z magike.net $
*/
/**
* 内容的文章基类
* 定义的css类
* p.more:阅读全文链接所属段落
*
* @package Widget
*/
class Widget_Archive extends Widget_Abstract_Contents
{
/**
* 调用的风格文件
*
* @access private
* @var string
*/
private $_themeFile;
/**
* 风格目录
*
* @access private
* @var string
*/
private $_themeDir;
/**
* 分页计算对象
*
* @access private
* @var Typecho_Db_Query
*/
private $_countSql;
/**
* 所有文章个数
*
* @access private
* @var integer
*/
private $_total = false;
/**
* 标记是否为从外部调用
*
* @access private
* @var boolean
*/
private $_invokeFromOutside = false;
/**
* 是否由聚合调用
*
* @access private
* @var boolean
*/
private $_invokeByFeed = false;
/**
* 当前页
*
* @access private
* @var integer
*/
private $_currentPage;
/**
* 生成分页的内容
*
* @access private
* @var array
*/
private $_pageRow = array();
/**
* 聚合器对象
*
* @access private
* @var Typecho_Feed
*/
private $_feed;
/**
* RSS 2.0聚合地址
*
* @access private
* @var string
*/
private $_feedUrl;
/**
* RSS 1.0聚合地址
*
* @access private
* @var string
*/
private $_feedRssUrl;
/**
* ATOM 聚合地址
*
* @access private
* @var string
*/
private $_feedAtomUrl;
/**
* 本页标题
*
* @access private
* @var string
*/
private $_metaTitle;
/**
* 本页关键字
*
* @access private
* @var string
*/
private $_keywords;
/**
* 本页描述
*
* @access private
* @var string
*/
private $_description;
/**
* 聚合类型
*
* @access private
* @var string
*/
private $_feedType;
/**
* 聚合类型
*
* @access private
* @var string
*/
private $_feedContentType;
/**
* 当前feed地址
*
* @access private
* @var string
*/
private $_currentFeedUrl;
/**
* 归档标题
*
* @access private
* @var string
*/
private $_archiveTitle = NULL;
/**
* 归档类型
*
* @access private
* @var string
*/
private $_archiveType = 'index';
/**
* 是否为单一归档
*
* @access private
* @var string
*/
private $_archiveSingle = false;
/**
* 是否为自定义首页, 主要为了标记自定义首页的情况
*
* (default value: false)
*
* @var boolean
* @access private
*/
private $_makeSinglePageAsFrontPage = false;
/**
* 归档缩略名
*
* @access private
* @var string
*/
private $_archiveSlug;
// modified_by_jiangmuzi 2015.09.22
/**
* 归档MID
*
* @access private
* @var string
*/
private $_archiveMid;
// end modified
/**
* 设置分页对象
*
* @access private
* @var Typecho_Widget_Helper_PageNavigator
*/
private $_pageNav;
/**
* 当前访问的用户
*
* @access private
* @var Widget_Users_Query
*/
private $_ucenter;
/**
* 分类自定义样式
*
* @access private
* @var Widget_Users_Query
*/
private $_archiveStyle;
/**
* 构造函数,初始化组件
*
* @param mixed $request
* @param mixed $response
* @param mixed $params
* @throws Typecho_Widget_Exception
*/
public function __construct($request, $response, $params = NULL)
{
parent::__construct($request, $response, $params);
$this->parameter->setDefault(array(
'pageSize' => $this->options->pageSize,
'type' => NULL,
'checkPermalink' => true
));
/** 用于判断是路由调用还是外部调用 */
if (NULL == $this->parameter->type) {
$this->parameter->type = Typecho_Router::$current;
} else {
$this->_invokeFromOutside = true;
}
/** 用于判断是否为feed调用 */
if ($this->parameter->isFeed) {
$this->_invokeByFeed = true;
}
/** 初始化皮肤路径 */
$this->_themeDir = rtrim($this->options->themeFile($this->options->theme), '/') . '/';
/** 处理feed模式 **/
if ('feed' == $this->parameter->type) {
$this->_currentFeedUrl = '';
/** 判断聚合类型 */
switch (true) {
case 0 === strpos($this->request->feed, '/rss/') || '/rss' == $this->request->feed:
/** 如果是RSS1标准 */
$this->request->feed = substr($this->request->feed, 4);
$this->_feedType = Typecho_Feed::RSS1;
$this->_currentFeedUrl = $this->options->feedRssUrl;
$this->_feedContentType = 'application/rdf+xml';
break;
case 0 === strpos($this->request->feed, '/atom/') || '/atom' == $this->request->feed:
/** 如果是ATOM标准 */
$this->request->feed = substr($this->request->feed, 5);
$this->_feedType = Typecho_Feed::ATOM1;
$this->_currentFeedUrl = $this->options->feedAtomUrl;
$this->_feedContentType = 'application/atom+xml';
break;
default:
$this->_feedType = Typecho_Feed::RSS2;
$this->_currentFeedUrl = $this->options->feedUrl;
$this->_feedContentType = 'application/rss+xml';
break;
}
$feedQuery = $this->request->feed;
//$this->parameter->type = Typecho_Router::$current;
//$this->request->setParams($params);
if ('/comments/' == $feedQuery || '/comments' == $feedQuery) {
/** 专为feed使用的hack */
$this->parameter->type = 'comments';
} else {
$matched = Typecho_Router::match($this->request->feed, 'pageSize=10&isFeed=1');
if ($matched && $matched instanceof Widget_Archive) {
$this->import($matched);
} else {
throw new Typecho_Widget_Exception(_t('聚合页不存在'), 404);
}
}
/** 初始化聚合器 */
$this->setFeed(new Typecho_Feed(Typecho_Common::VERSION, $this->_feedType, $this->options->charset, _t('zh-CN')));
/** 默认输出10则文章 **/
$this->parameter->pageSize = 10;
}
}
/**
* 评论地址
*
* @access protected
* @return string
*/
protected function ___commentUrl()
{
/** 生成反馈地址 */
/** 评论 */
$commentUrl = parent::___commentUrl();
//不依赖js的父级评论
$reply = $this->request->filter('int')->replyTo;
if ($reply && $this->is('single')) {
$commentUrl .= '?parent=' . $reply;
}
return $this->options->commentsAntiSpam ? $commentUrl : $this->security->getTokenUrl($commentUrl);
}
/**
* 设置分页对象
* @param array $pageRow
* @return void
*/
public function setPageRow($pageRow)
{
$this->_pageRow = $pageRow;
}
/**
* @param string $archiveSlug the $_archiveSlug to set
*/
public function setArchiveSlug($archiveSlug)
{
$this->_archiveSlug = $archiveSlug;
}
// modified_by_jiangmuzi 2015.09.22
/**
* @param string $archiveMid the $_archiveMid to set
*/
public function setArchiveMid($archiveMid)
{
$this->_archiveMid = $archiveMid;
}
// end modified
/**
* @param string $archiveSingle the $_archiveSingle to set
*/
public function setArchiveSingle($archiveSingle)
{
$this->_archiveSingle = $archiveSingle;
}
/**
* @param $_archiveType the $_archiveType to set
*/
public function setArchiveType($archiveType)
{
$this->_archiveType = $archiveType;
}
/**
* @param $_archiveTitle the $_archiveTitle to set
*/
public function setArchiveTitle($archiveTitle)
{
$this->_archiveTitle = $archiveTitle;
}
/**
* 增加标题
* @param string $archiveTitle 标题
* @return void
*/
public function addArchiveTitle($archiveTitle)
{
$current = $this->getArchiveTitle();
$current[] = $archiveTitle;
$this->setArchiveTitle($current);
}
/**
* @param $_feedType the $_feedType to set
*/
public function setFeedType($feedType)
{
$this->_feedType = $feedType;
}
/**
* @param $_description the $_metaTitle to set
*/
public function setMetaTitle($metaTitle)
{
$this->_metaTitle = $metaTitle;
}
/**
* @param $_description the $_description to set
*/
public function setDescription($description)
{
$this->_description = $description;
}
/**
* @param $_keywords the $_keywords to set
*/
public function setKeywords($keywords)
{
$this->_keywords = $keywords;
}
/**
* @param $_feedAtomUrl the $_feedAtomUrl to set
*/
public function setFeedAtomUrl($feedAtomUrl)
{
$this->_feedAtomUrl = $feedAtomUrl;
}
/**
* @param $_feedRssUrl the $_feedRssUrl to set
*/
public function setFeedRssUrl($feedRssUrl)
{
$this->_feedRssUrl = $feedRssUrl;
}
/**
* @param $_feedUrl the $_feedUrl to set
*/
public function setFeedUrl($feedUrl)
{
$this->_feedUrl = $feedUrl;
}
/**
* @param $_feed the $_feed to set
*/
public function setFeed($feed)
{
$this->_feed = $feed;
}
/**
* @param $_countSql the $_countSql to set
*/
public function setCountSql($countSql)
{
$this->_countSql = $countSql;
}
/**
* @param $_total the $_total to set
*/
public function setTotal($total)
{
$this->_total = $total;
}
/**
* @param $_themeFile the $_themeFile to set
*/
public function setThemeFile($themeFile)
{
$this->_themeFile = $themeFile;
}
/**
* @param $_themeDir the $_themeDir to set
*/
public function setThemeDir($themeDir)
{
$this->_themeDir = $themeDir;
}
/**
* 获取分页对象
* @return array
*/
public function getPageRow()
{
return $this->_pageRow;
}
/**
* @return the $_archiveSlug
*/
public function getArchiveSlug()
{
return $this->_archiveSlug;
}
// modified_by_jiangmuzi 2015.09.22
/**
* @return the $_archiveMid
*/
public function getArchiveMid()
{
return $this->_archiveMid;
}
// end modified
/**
* @return the $_archiveSingle
*/
public function getArchiveSingle()
{
return $this->_archiveSingle;
}
/**
* @return the $_archiveType
*/
public function getArchiveType()
{
return $this->_archiveType;
}
/**
* @return the $_archiveTitle
*/
public function getArchiveTitle()
{
return $this->_archiveTitle;
}
/**
* @return the $_feedType
*/
public function getFeedType()
{
return $this->_feedType;
}
/**
* @return the $_description
*/
public function getMetaTitle($slug='')
{
if(!empty($this->_archiveTitle) && empty($this->_metaTitle))
$this->_metaTitle = $this->_archiveTitle;
return empty($this->_metaTitle) ? '' : $this->_metaTitle . $slug;
}
/**
* @return the $_description
*/
public function getDescription()
{
return $this->_description;
}
/**
* @return the $_keywords
*/
public function getKeywords()
{
return $this->_keywords;
}
/**
* @return the $_feedAtomUrl
*/
public function getFeedAtomUrl()
{
return $this->_feedAtomUrl;
}
/**
* @return the $_feedRssUrl
*/
public function getFeedRssUrl()
{
return $this->_feedRssUrl;
}
/**
* @return the $_feedUrl
*/
public function getFeedUrl()
{
return $this->_feedUrl;
}
/**
* @return the $_feed
*/
public function getFeed()
{
return $this->_feed;
}
/**
* @return the $_countSql
*/
public function getCountSql()
{
return $this->_countSql;
}
/**
* @return the $_total
*/
public function getTotal()
{
if (false === $this->_total) {
$this->_total = $this->size($this->_countSql);
}
return $this->_total;
}
/**
* @return the $_currentPage
*/
public function getCurrentPage()
{
return $this->_currentPage;
}
/**
* 获取页数
*
* @return integer
*/
public function getTotalPage()
{
return ceil($this->getTotal() / $this->parameter->pageSize);
}
/**
* @return the $_themeFile
*/
public function getThemeFile()
{
return $this->_themeFile;
}
/**
* @return the $_themeDir
*/
public function getThemeDir()
{
return $this->_themeDir;
}
public function ucenter(){
return $this->_ucenter;
}
/**
* 检查链接是否正确
*
* @access private
* @return void
*/
private function checkPermalink()
{
$type = $this->parameter->type;
if (in_array($type, array('index', 'comment_page', 404))
|| $this->_makeSinglePageAsFrontPage // 自定义首页不处理
|| !$this->parameter->checkPermalink) { // 强制关闭
return;
}
if ($this->_archiveSingle) {
$permalink = $this->permalink;
} else {
$value = array_merge($this->_pageRow, array(
'page' => $this->_currentPage,
'u'=>$this->request->u
));
$path = Typecho_Router::url($type, $value);
$permalink = Typecho_Common::url($path, $this->options->index);
}
$requestUrl = $this->request->getRequestUrl();
$src = parse_url($permalink);
$target = parse_url($requestUrl);
if ($src['host'] != $target['host'] || urldecode($src['path']) != urldecode($target['path'])) {
$this->response->redirect($permalink, true);
}
}
/**
* 导入对象
*
* @access private
* @param Widget_Archive $widget 需要导入的对象
* @return void
*/
private function import(Widget_Archive $widget)
{
$currentProperties = get_object_vars($this);
foreach ($currentProperties as $name => $value) {
if (false !== strpos('|request|response|parameter|_feed|_feedType|_currentFeedUrl|', '|' . $name . '|')) {
continue;
}
if (isset($widget->{$name})) {
$this->{$name} = $widget->{$name};
} else {
$method = ucfirst(trim($name, '_'));
$setMethod = 'set' . $method;
$getMethod = 'get' . $method;
if (method_exists($this, $setMethod)
&& method_exists($widget, $getMethod)) {
$this->{$setMethod}($widget->{$getMethod}());
}
}
}
}
/**
* 处理index
*
* @access private
* @param Typecho_Db_Query $select 查询对象
* @param boolean $hasPushed 是否已经压入队列
* @return void
*/
private function indexHandle(Typecho_Db_Query $select, &$hasPushed)
{
$select->where('table.contents.type = ?', 'post');
/** 插件接口 */
$this->pluginHandle()->indexHandle($this, $select);
}
/**
* 默认的非首页归档处理
*
* @access private
* @param Typecho_Db_Query $select 查询对象
* @param boolean $hasPushed 是否已经压入队列
* @return void
* @throws Typecho_Widget_Exception
*/
private function archiveEmptyHandle(Typecho_Db_Query $select, &$hasPushed)
{
throw new Typecho_Widget_Exception(_t('请求的地址不存在'), 404);
}
/**
* 404页面处理
*
* @access private
* @param Typecho_Db_Query $select 查询对象
* @param boolean $hasPushed 是否已经压入队列
* @return void
*/
private function error404Handle(Typecho_Db_Query $select, &$hasPushed)
{
/** 设置header */
$this->response->setStatus(404);
/** 设置标题 */
$this->_archiveTitle = _t('页面没找到');
/** 设置归档类型 */
$this->_archiveType = 'archive';
/** 设置归档缩略名 */
$this->_archiveSlug = 404;
/** 设置归档模板 */
$this->_themeFile = '404.php';
/** 设置单一归档类型 */
$this->_archiveSingle = false;
$hasPushed = true;
/** 插件接口 */
$this->pluginHandle()->error404Handle($this, $select);
}
/**
* 独立页处理
*
* @access private
* @param Typecho_Db_Query $select 查询对象
* @param boolean $hasPushed 是否已经压入队列
* @return void
* @throws Typecho_Widget_Exception
*/
private function singleHandle(Typecho_Db_Query $select, &$hasPushed)
{
if ('comment_page' == $this->parameter->type) {
$params = array();
$matched = Typecho_Router::match($this->request->permalink);
if ($matched && $matched instanceof Widget_Archive && $matched->is('single')) {
$this->import($matched);
$hasPushed = true;
return;
}
}
/** 将这两个设置提前是为了保证在调用query的plugin时可以在插件中使用is判断初步归档类型 */
/** 如果需要更细判断,则可以使用singleHandle来实现 */
$this->_archiveSingle = true;
/** 默认归档类型 */
$this->_archiveType = 'single';
/** 匹配类型 */
if ('single' != $this->parameter->type) {
$select->where('table.contents.type = ?', $this->parameter->type);
}
/** 如果是单篇文章或独立页面 */
if (isset($this->request->cid)) {
$select->where('table.contents.cid = ?', $this->request->filter('int')->cid);
}
/** 匹配缩略名 */
if (isset($this->request->slug)) {
$select->where('table.contents.slug = ?', $this->request->slug);
}
/** 匹配时间 */
if (isset($this->request->year)) {
$year = $this->request->filter('int')->year;
$fromMonth = 1;
$toMonth = 12;
$fromDay = 1;
$toDay = 31;
if (isset($this->request->month)) {
$fromMonth = $this->request->filter('int')->month;
$toMonth = $fromMonth;
$fromDay = 1;
$toDay = date('t', mktime(0, 0, 0, $toMonth, 1, $year));
if (isset($this->request->day)) {
$fromDay = $this->request->filter('int')->day;
$toDay = $fromDay;
}
}
/** 获取起始GMT时间的unix时间戳 */
$from = mktime(0, 0, 0, $fromMonth, $fromDay, $year) - $this->options->timezone + $this->options->serverTimezone;
$to = mktime(23, 59, 59, $toMonth, $toDay, $year) - $this->options->timezone + $this->options->serverTimezone;
$select->where('table.contents.created > ? AND table.contents.created < ?', $from, $to);
}
/** 保存密码至cookie */
if ($this->request->isPost() && isset($this->request->protectPassword)) {
$this->security->protect();
Typecho_Cookie::set('protectPassword', $this->request->protectPassword, 0);
}
/** 匹配类型 */
$select->limit(1);
$this->query($select);
if (!$this->have()
|| (isset($this->request->category) && $this->category != $this->request->category)
|| (isset($this->request->directory) && $this->request->directory != implode('/', $this->directory))) {
if (!$this->_invokeFromOutside) {
/** 对没有索引情况下的判断 */
throw new Typecho_Widget_Exception(_t('请求的地址不存在'), 404);
} else {
$hasPushed = true;
return;
}
}
/** 设置模板 */
if ($this->template) {
/** 应用自定义模板 */
$this->_themeFile = $this->template;
}
/** 设置头部feed */
/** RSS 2.0 */
//对自定义首页使用全局变量
if (!$this->_makeSinglePageAsFrontPage) {
$this->_feedUrl = $this->feedUrl;
/** RSS 1.0 */
$this->_feedRssUrl = $this->feedRssUrl;
/** ATOM 1.0 */
$this->_feedAtomUrl = $this->feedAtomUrl;
/** 设置标题 */
$this->_archiveTitle = $this->title;
/** 设置关键词 */
$this->_keywords = implode(',', Typecho_Common::arrayFlatten($this->tags, 'name'));
/** 设置描述 */
$this->_description = $this->description;
}
/** 设置归档类型 */
$this->_archiveType = $this->type;
/** 设置归档缩略名 */
$this->_archiveSlug = ('post' == $this->type || 'attachment' == $this->type) ? $this->cid : $this->slug;
/** 设置403头 */
if ($this->hidden) {
$this->response->setStatus(403);
}
$hasPushed = true;
// modified_by_jiangmuzi 2015.09.23
if(isset($this->categories[0]))
$this->_archiveStyle = $this->categories[0]['style'];
// 更新浏览数
$this->db->query($this->db->update('table.contents')->rows(array('viewsNum' => (int)$this->viewsNum+1))->where('cid = ?', $this->cid));
// 判断是否收藏
if('post' == $this->type && $this->user->hasLogin()){
$this->isFavorite = $this->widget('Widget_Users_Favorites')->isFavorite('post',$this->cid);
}
/** 插件接口 */
$this->pluginHandle()->singleHandle($this, $select);
}
/**
* 处理分类
*
* @access private
* @param Typecho_Db_Query $select 查询对象
* @param boolean $hasPushed 是否已经压入队列
* @return void
* @throws Typecho_Widget_Exception
*/
private function categoryHandle(Typecho_Db_Query $select, &$hasPushed)
{
/** 如果是分类 */
$categorySelect = $this->db->select()
->from('table.metas')
->where('type = ?', 'category')
->limit(1);
if (isset($this->request->mid)) {
$categorySelect->where('mid = ?', $this->request->filter('int')->mid);
}
if (isset($this->request->slug)) {
$categorySelect->where('slug = ?', $this->request->slug);
}
if (isset($this->request->directory)) {
$directory = explode('/', $this->request->directory);
$categorySelect->where('slug = ?', $directory[count($directory) - 1]);
}
$category = $this->db->fetchRow($categorySelect);
if (empty($category)) {
throw new Typecho_Widget_Exception(_t('分类不存在'), 404);
}
$categoryListWidget = $this->widget('Widget_Metas_Category_List', 'current=' . $category['mid']);
$category = $categoryListWidget->filter($category);
if (isset($directory) && ($this->request->directory != implode('/', $category['directory']))) {
throw new Typecho_Widget_Exception(_t('父级分类不存在'), 404);