PageRenderTime 26ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/var/Widget/Contents/Attachment/Admin.php

https://gitlab.com/wuhang2003/typecho
PHP | 125 lines | 44 code | 16 blank | 65 comment | 4 complexity | 53640ae17793ebffef39334921c6e00c MD5 | raw file
  1. <?php
  2. if (!defined('__TYPECHO_ROOT_DIR__')) exit;
  3. /**
  4. * 文件管理列表
  5. *
  6. * @category typecho
  7. * @package Widget
  8. * @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
  9. * @license GNU General Public License 2.0
  10. * @version $Id$
  11. */
  12. /**
  13. * 文件管理列表组件
  14. *
  15. * @category typecho
  16. * @package Widget
  17. * @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
  18. * @license GNU General Public License 2.0
  19. */
  20. class Widget_Contents_Attachment_Admin extends Widget_Abstract_Contents
  21. {
  22. /**
  23. * 用于计算数值的语句对象
  24. *
  25. * @access private
  26. * @var Typecho_Db_Query
  27. */
  28. private $_countSql;
  29. /**
  30. * 所有文章个数
  31. *
  32. * @access private
  33. * @var integer
  34. */
  35. private $_total = false;
  36. /**
  37. * 分页大小
  38. *
  39. * @access private
  40. * @var integer
  41. */
  42. private $pageSize;
  43. /**
  44. * 当前页
  45. *
  46. * @access private
  47. * @var integer
  48. */
  49. private $_currentPage;
  50. /**
  51. * 所属文章
  52. *
  53. * @access protected
  54. * @return Typecho_Config
  55. */
  56. protected function ___parentPost()
  57. {
  58. return new Typecho_Config($this->db->fetchRow(
  59. $this->select()->where('table.contents.cid = ?', $this->parentId)
  60. ->limit(1)));
  61. }
  62. /**
  63. * 执行函数
  64. *
  65. * @access public
  66. * @return void
  67. */
  68. public function execute()
  69. {
  70. $this->parameter->setDefault('pageSize=20');
  71. $this->_currentPage = $this->request->get('page', 1);
  72. /** 构建基础查询 */
  73. $select = $this->select()->where('table.contents.type = ?', 'attachment');
  74. /** 如果具有编辑以上权限,可以查看所有文件,反之只能查看自己的文件 */
  75. if (!$this->user->pass('editor', true)) {
  76. $select->where('table.contents.authorId = ?', $this->user->uid);
  77. }
  78. /** 过滤标题 */
  79. if (NULL != ($keywords = $this->request->filter('search')->keywords)) {
  80. $args = array();
  81. $keywordsList = explode(' ', $keywords);
  82. $args[] = implode(' OR ', array_fill(0, count($keywordsList), 'table.contents.title LIKE ?'));
  83. foreach ($keywordsList as $keyword) {
  84. $args[] = '%' . $keyword . '%';
  85. }
  86. call_user_func_array(array($select, 'where'), $args);
  87. }
  88. /** 给计算数目对象赋值,克隆对象 */
  89. $this->_countSql = clone $select;
  90. /** 提交查询 */
  91. $select->order('table.contents.created', Typecho_Db::SORT_DESC)
  92. ->page($this->_currentPage, $this->parameter->pageSize);
  93. $this->db->fetchAll($select, array($this, 'push'));
  94. }
  95. /**
  96. * 输出分页
  97. *
  98. * @access public
  99. * @return void
  100. */
  101. public function pageNav()
  102. {
  103. $query = $this->request->makeUriByRequest('page={page}');
  104. /** 使用盒状分页 */
  105. $nav = new Typecho_Widget_Helper_PageNavigator_Box(false === $this->_total ? $this->_total = $this->size($this->_countSql) : $this->_total,
  106. $this->_currentPage, $this->parameter->pageSize, $query);
  107. $nav->render('&laquo;', '&raquo;');
  108. }
  109. }