| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * @package Dotclear |
|---|
| 4 | * @subpackage Backend |
|---|
| 5 | * |
|---|
| 6 | * @copyright Olivier Meunier & Association Dotclear |
|---|
| 7 | * @copyright GPL-2.0-only |
|---|
| 8 | */ |
|---|
| 9 | |
|---|
| 10 | if (!defined('DC_RC_PATH')) {return;} |
|---|
| 11 | |
|---|
| 12 | class dcBlogsActionsPage extends dcActionsPage |
|---|
| 13 | { |
|---|
| 14 | public function __construct($core, $uri, $redirect_args = array()) |
|---|
| 15 | { |
|---|
| 16 | parent::__construct($core, $uri, $redirect_args); |
|---|
| 17 | $this->redirect_fields = array('status', 'sortby', 'order', 'page', 'nb'); |
|---|
| 18 | $this->field_entries = 'blogs'; |
|---|
| 19 | $this->title_cb = __('Blogs'); |
|---|
| 20 | $this->loadDefaults(); |
|---|
| 21 | $core->callBehavior('adminBlogsActionsPage', $core, $this); |
|---|
| 22 | } |
|---|
| 23 | |
|---|
| 24 | protected function loadDefaults() |
|---|
| 25 | { |
|---|
| 26 | // We could have added a behavior here, but we want default action |
|---|
| 27 | // to be setup first |
|---|
| 28 | dcDefaultBlogActions::adminBlogsActionsPage($this->core, $this); |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | public function beginPage($breadcrumb = '', $head = '') |
|---|
| 32 | { |
|---|
| 33 | if ($this->in_plugin) { |
|---|
| 34 | echo '<html><head><title>' . __('Blogs') . '</title>' . |
|---|
| 35 | dcPage::jsLoad('js/_blogs_actions.js') . |
|---|
| 36 | $head . |
|---|
| 37 | '</script></head><body>' . |
|---|
| 38 | $breadcrumb; |
|---|
| 39 | } else { |
|---|
| 40 | dcPage::open( |
|---|
| 41 | __('Blogs'), |
|---|
| 42 | dcPage::jsLoad('js/_blogs_actions.js') . |
|---|
| 43 | $head, |
|---|
| 44 | $breadcrumb |
|---|
| 45 | ); |
|---|
| 46 | } |
|---|
| 47 | echo '<p><a class="back" href="' . $this->getRedirection(true) . '">' . __('Back to blogs list') . '</a></p>'; |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | public function endPage() |
|---|
| 51 | { |
|---|
| 52 | dcPage::close(); |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | public function error(Exception $e) |
|---|
| 56 | { |
|---|
| 57 | $this->core->error->add($e->getMessage()); |
|---|
| 58 | $this->beginPage(dcPage::breadcrumb( |
|---|
| 59 | array( |
|---|
| 60 | html::escapeHTML($this->core->blog->name) => '', |
|---|
| 61 | __('Blogs') => $this->core->adminurl->get('admin.blogs'), |
|---|
| 62 | __('Blogs actions') => '' |
|---|
| 63 | )) |
|---|
| 64 | ); |
|---|
| 65 | $this->endPage(); |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | public function getCheckboxes() |
|---|
| 69 | { |
|---|
| 70 | $ret = ''; |
|---|
| 71 | foreach ($this->entries as $id => $res) { |
|---|
| 72 | $ret .= |
|---|
| 73 | '<tr>' . |
|---|
| 74 | '<td class="minimal">' . form::checkbox(array($this->field_entries . '[]'), $id, |
|---|
| 75 | array( |
|---|
| 76 | 'checked' => true |
|---|
| 77 | )) . |
|---|
| 78 | '</td>' . |
|---|
| 79 | '<td>' . $res['blog'] . '</td>' . |
|---|
| 80 | '<td>' . $res['name'] . '</td>' . |
|---|
| 81 | '</tr>'; |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | return |
|---|
| 85 | '<table class="blogs-list"><tr>' . |
|---|
| 86 | '<th colspan="2">' . __('Blog id') . '</th><th>' . __('Blog name') . '</th>' . |
|---|
| 87 | '</tr>' . $ret . '</table>'; |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | protected function fetchEntries($from) |
|---|
| 91 | { |
|---|
| 92 | $params = array(); |
|---|
| 93 | if (!empty($from['blogs'])) { |
|---|
| 94 | $params['blog_id'] = $from['blogs']; |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | $bl = $this->core->getBlogs($params); |
|---|
| 98 | while ($bl->fetch()) { |
|---|
| 99 | $this->entries[$bl->blog_id] = array( |
|---|
| 100 | 'blog' => $bl->blog_id, |
|---|
| 101 | 'name' => $bl->blog_name |
|---|
| 102 | ); |
|---|
| 103 | } |
|---|
| 104 | $this->rs = $bl; |
|---|
| 105 | } |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | class dcDefaultBlogActions |
|---|
| 109 | { |
|---|
| 110 | public static function adminBlogsActionsPage($core, dcBlogsActionsPage $ap) |
|---|
| 111 | { |
|---|
| 112 | if (!$core->auth->isSuperAdmin()) { |
|---|
| 113 | return; |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | $ap->addAction( |
|---|
| 117 | array(__('Status') => array( |
|---|
| 118 | __('Set online') => 'online', |
|---|
| 119 | __('Set offline') => 'offline', |
|---|
| 120 | __('Set as removed') => 'remove' |
|---|
| 121 | )), |
|---|
| 122 | array('dcDefaultBlogActions', 'doChangeBlogStatus') |
|---|
| 123 | ); |
|---|
| 124 | $ap->addAction( |
|---|
| 125 | array(__('Delete') => array( |
|---|
| 126 | __('Delete') => 'delete')), |
|---|
| 127 | array('dcDefaultBlogActions', 'doDeleteBlog') |
|---|
| 128 | ); |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | public static function doChangeBlogStatus($core, dcBlogsActionsPage $ap, $post) |
|---|
| 132 | { |
|---|
| 133 | if (!$core->auth->isSuperAdmin()) { |
|---|
| 134 | return; |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | $action = $ap->getAction(); |
|---|
| 138 | $ids = $ap->getIDs(); |
|---|
| 139 | if (empty($ids)) { |
|---|
| 140 | throw new Exception(__('No blog selected')); |
|---|
| 141 | } |
|---|
| 142 | switch ($action) { |
|---|
| 143 | case 'online':$status = 1; |
|---|
| 144 | break; |
|---|
| 145 | case 'offline':$status = 0; |
|---|
| 146 | break; |
|---|
| 147 | case 'remove':$status = -1; |
|---|
| 148 | break; |
|---|
| 149 | default:$status = 1; |
|---|
| 150 | break; |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | $cur = $core->con->openCursor($core->prefix . 'blog'); |
|---|
| 154 | $cur->blog_status = $status; |
|---|
| 155 | //$cur->blog_upddt = date('Y-m-d H:i:s'); |
|---|
| 156 | $cur->update('WHERE blog_id ' . $core->con->in($ids)); |
|---|
| 157 | |
|---|
| 158 | dcPage::addSuccessNotice(__('Selected blogs have been successfully updated.')); |
|---|
| 159 | $ap->redirect(true); |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | public static function doDeleteBlog($core, dcBlogsActionsPage $ap, $post) |
|---|
| 163 | { |
|---|
| 164 | if (!$core->auth->isSuperAdmin()) { |
|---|
| 165 | return; |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | $ap_ids = $ap->getIDs(); |
|---|
| 169 | if (empty($ap_ids)) { |
|---|
| 170 | throw new Exception(__('No blog selected')); |
|---|
| 171 | } |
|---|
| 172 | |
|---|
| 173 | if (!$core->auth->checkPassword($_POST['pwd'])) { |
|---|
| 174 | throw new Exception(__('Password verification failed')); |
|---|
| 175 | } |
|---|
| 176 | |
|---|
| 177 | $ids = array(); |
|---|
| 178 | foreach ($ap_ids as $id) { |
|---|
| 179 | if ($id == $core->blog->id) { |
|---|
| 180 | dcPage::addWarningNotice(__('The current blog cannot be deleted.')); |
|---|
| 181 | } else { |
|---|
| 182 | $ids[] = $id; |
|---|
| 183 | } |
|---|
| 184 | } |
|---|
| 185 | |
|---|
| 186 | if (!empty($ids)) { |
|---|
| 187 | # --BEHAVIOR-- adminBeforeBlogsDelete |
|---|
| 188 | $core->callBehavior('adminBeforeBlogsDelete', $ids); |
|---|
| 189 | |
|---|
| 190 | foreach ($ids as $id) { |
|---|
| 191 | $core->delBlog($id); |
|---|
| 192 | } |
|---|
| 193 | |
|---|
| 194 | dcPage::addSuccessNotice(sprintf( |
|---|
| 195 | __( |
|---|
| 196 | '%d blog has been successfully deleted', |
|---|
| 197 | '%d blogs have been successfully deleted', |
|---|
| 198 | count($ids) |
|---|
| 199 | ), |
|---|
| 200 | count($ids)) |
|---|
| 201 | ); |
|---|
| 202 | } |
|---|
| 203 | $ap->redirect(false); |
|---|
| 204 | } |
|---|
| 205 | } |
|---|