[0] | 1 | <?php |
---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
| 3 | # |
---|
| 4 | # This file is part of Dotclear 2. |
---|
| 5 | # |
---|
[270] | 6 | # Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear |
---|
[0] | 7 | # Licensed under the GPL version 2.0 license. |
---|
| 8 | # See LICENSE file or |
---|
| 9 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
| 10 | # |
---|
| 11 | # -- END LICENSE BLOCK ----------------------------------------- |
---|
| 12 | |
---|
| 13 | if (!empty($_GET['pf'])) { |
---|
| 14 | require dirname(__FILE__).'/../inc/load_plugin_file.php'; |
---|
| 15 | exit; |
---|
| 16 | } |
---|
[1056] | 17 | if (!empty($_GET['tf'])) { |
---|
| 18 | define('DC_CONTEXT_ADMIN',true); |
---|
| 19 | require dirname(__FILE__).'/../inc/load_theme_file.php'; |
---|
| 20 | exit; |
---|
| 21 | } |
---|
[0] | 22 | |
---|
| 23 | require dirname(__FILE__).'/../inc/admin/prepend.php'; |
---|
| 24 | |
---|
| 25 | if (!empty($_GET['default_blog'])) { |
---|
| 26 | try { |
---|
| 27 | $core->setUserDefaultBlog($core->auth->userID(),$core->blog->id); |
---|
| 28 | http::redirect('index.php'); |
---|
| 29 | } catch (Exception $e) { |
---|
| 30 | $core->error->add($e->getMessage()); |
---|
| 31 | } |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | dcPage::check('usage,contentadmin'); |
---|
| 35 | |
---|
| 36 | # Logout |
---|
| 37 | if (!empty($_GET['logout'])) { |
---|
| 38 | $core->session->destroy(); |
---|
| 39 | if (isset($_COOKIE['dc_admin'])) { |
---|
| 40 | unset($_COOKIE['dc_admin']); |
---|
| 41 | setcookie('dc_admin',false,-600,'','',DC_ADMIN_SSL); |
---|
| 42 | } |
---|
| 43 | http::redirect('auth.php'); |
---|
| 44 | exit; |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | # Plugin install |
---|
| 48 | $plugins_install = $core->plugins->installModules(); |
---|
| 49 | |
---|
[1079] | 50 | # Send plugins install messages to templates |
---|
| 51 | if (!empty($plugins_install['success'])) { |
---|
| 52 | $_ctx->addMessagesList(__('Following plugins have been installed:'),$plugins_install['success']); |
---|
| 53 | } |
---|
| 54 | if (!empty($plugins_install['failure'])) { |
---|
| 55 | $_ctx->addMessagesList(__('Following plugins have not been installed:'),$plugins_install['failure']); |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | # Send plugins errors messages to templates |
---|
| 59 | $_ctx->modules_errors = $core->auth->isSuperAdmin() ? $core->plugins->getErrors() : array(); |
---|
| 60 | |
---|
| 61 | # Send Dotclear updates notifications to tempaltes |
---|
| 62 | $_ctx->updater = array(); |
---|
| 63 | if ($core->auth->isSuperAdmin() && is_readable(DC_DIGESTS)) { |
---|
| 64 | |
---|
| 65 | $updater = new dcUpdate(DC_UPDATE_URL,'dotclear',DC_UPDATE_VERSION,DC_TPL_CACHE.'/versions'); |
---|
| 66 | $new_v = $updater->check(DC_VERSION); |
---|
| 67 | $version_info = $new_v ? $updater->getInfoURL() : ''; |
---|
| 68 | |
---|
| 69 | if ($updater->getNotify() && $new_v) { |
---|
| 70 | $_ctx->updater = array( |
---|
| 71 | 'new_version' => $new_v, |
---|
| 72 | 'version_info' => $version_info |
---|
| 73 | ); |
---|
| 74 | } |
---|
| 75 | } |
---|
| 76 | |
---|
[13] | 77 | # Check dashboard module prefs |
---|
[157] | 78 | $ws = $core->auth->user_prefs->addWorkspace('dashboard'); |
---|
[1079] | 79 | |
---|
| 80 | # Doclinks prefs |
---|
[13] | 81 | if (!$core->auth->user_prefs->dashboard->prefExists('doclinks')) { |
---|
| 82 | if (!$core->auth->user_prefs->dashboard->prefExists('doclinks',true)) { |
---|
| 83 | $core->auth->user_prefs->dashboard->put('doclinks',true,'boolean','',null,true); |
---|
| 84 | } |
---|
| 85 | $core->auth->user_prefs->dashboard->put('doclinks',true,'boolean'); |
---|
| 86 | } |
---|
[1079] | 87 | |
---|
| 88 | # Send doclinks to templates |
---|
| 89 | $_ctx->dashboard_doclinks = array(); |
---|
| 90 | if ($core->auth->user_prefs->dashboard->doclinks && !empty($__resources['doc'])) { |
---|
| 91 | $_ctx->dashboard_doclinks = $__resources['doc']; |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | # Dcnews prefs |
---|
[13] | 95 | if (!$core->auth->user_prefs->dashboard->prefExists('dcnews')) { |
---|
| 96 | if (!$core->auth->user_prefs->dashboard->prefExists('dcnews',true)) { |
---|
| 97 | $core->auth->user_prefs->dashboard->put('dcnews',true,'boolean','',null,true); |
---|
| 98 | } |
---|
| 99 | $core->auth->user_prefs->dashboard->put('dcnews',true,'boolean'); |
---|
| 100 | } |
---|
[1079] | 101 | |
---|
| 102 | # Send dcnews to templates |
---|
| 103 | $_ctx->dashboard_dcnews = array(); |
---|
| 104 | if ($core->auth->user_prefs->dashboard->dcnews && !empty($__resources['rss_news'])) { |
---|
| 105 | try |
---|
| 106 | { |
---|
| 107 | $feed_reader = new feedReader; |
---|
| 108 | $feed_reader->setCacheDir(DC_TPL_CACHE); |
---|
| 109 | $feed_reader->setTimeout(2); |
---|
| 110 | $feed_reader->setUserAgent('Dotclear - http://www.dotclear.org/'); |
---|
| 111 | $feed = $feed_reader->parse($__resources['rss_news']); |
---|
| 112 | if ($feed) { |
---|
| 113 | $items = array(); |
---|
| 114 | $i = 1; |
---|
| 115 | foreach ($feed->items as $item) { |
---|
| 116 | $items[] = array( |
---|
| 117 | 'title' => $item->title, |
---|
| 118 | 'link' => isset($item->link) ? $item->link : '', |
---|
| 119 | 'date' => dt::dt2str(__('%d %B %Y'),$item->pubdate,'Europe/Paris'), |
---|
| 120 | 'content' => html::clean($item->content) |
---|
| 121 | ); |
---|
| 122 | $i++; |
---|
| 123 | if ($i > 3) { break; } |
---|
| 124 | } |
---|
| 125 | $_ctx->dashboard_dcnews = $items; |
---|
| 126 | } |
---|
| 127 | } |
---|
| 128 | catch (Exception $e) {} |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | # Quick entry prefs |
---|
[13] | 132 | if (!$core->auth->user_prefs->dashboard->prefExists('quickentry')) { |
---|
| 133 | if (!$core->auth->user_prefs->dashboard->prefExists('quickentry',true)) { |
---|
| 134 | $core->auth->user_prefs->dashboard->put('quickentry',true,'boolean','',null,true); |
---|
| 135 | } |
---|
| 136 | $core->auth->user_prefs->dashboard->put('quickentry',true,'boolean'); |
---|
| 137 | } |
---|
| 138 | |
---|
[1079] | 139 | # Send quick entry to templates |
---|
| 140 | $_ctx->dashboard_quickentry = false; |
---|
| 141 | if ($core->auth->user_prefs->dashboard->quickentry &&$core->auth->check('usage,contentadmin',$core->blog->id)) |
---|
| 142 | { |
---|
| 143 | $categories_combo = array(' ' => ''); |
---|
| 144 | try { |
---|
| 145 | $categories = $core->blog->getCategories(array('post_type'=>'post')); |
---|
| 146 | while ($categories->fetch()) { |
---|
| 147 | $categories_combo[] = new formSelectOption( |
---|
| 148 | str_repeat(' ',$categories->level-1). |
---|
| 149 | ($categories->level-1 == 0 ? '' : '• ').html::escapeHTML($categories->cat_title), |
---|
| 150 | $categories->cat_id |
---|
| 151 | ); |
---|
| 152 | } |
---|
| 153 | } |
---|
| 154 | catch (Exception $e) { } |
---|
| 155 | |
---|
| 156 | $form = new dcForm($core,'quickentry','post.php'); |
---|
| 157 | $form |
---|
| 158 | ->addField( |
---|
| 159 | new dcFieldText('post_title','', array( |
---|
| 160 | 'size' => 20, |
---|
| 161 | 'required' => true, |
---|
| 162 | 'label' => __('Title')))) |
---|
| 163 | ->addField( |
---|
| 164 | new dcFieldTextArea('post_content','', array( |
---|
| 165 | 'required' => true, |
---|
| 166 | 'label' => __("Content:")))) |
---|
| 167 | ->addField( |
---|
| 168 | new dcFieldCombo('cat_id','',$categories_combo,array( |
---|
| 169 | "label" => __('Category:')))) |
---|
| 170 | ->addField( |
---|
| 171 | new dcFieldSubmit('save',__('Save'),array( |
---|
| 172 | 'action' => 'savePost'))) |
---|
| 173 | ->addField( |
---|
| 174 | new dcFieldHidden ('post_status',-2)) |
---|
| 175 | ->addField( |
---|
| 176 | new dcFieldHidden ('post_format',$core->auth->getOption('post_format'))) |
---|
| 177 | ->addField( |
---|
| 178 | new dcFieldHidden ('post_excerpt','')) |
---|
| 179 | ->addField( |
---|
| 180 | new dcFieldHidden ('post_lang',$core->auth->getInfo('user_lang'))) |
---|
| 181 | ->addField( |
---|
| 182 | new dcFieldHidden ('post_notes','')) |
---|
| 183 | ; |
---|
| 184 | if ($core->auth->check('publish',$core->blog->id)) { |
---|
| 185 | $form->addField( |
---|
| 186 | new dcFieldHidden ('save-publish',__('Save and publish'))); |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | $_ctx->dashboard_quickentry = true; |
---|
| 190 | } |
---|
| 191 | |
---|
[0] | 192 | # Dashboard icons |
---|
| 193 | $__dashboard_icons = new ArrayObject(); |
---|
| 194 | |
---|
[3] | 195 | # Dashboard favorites |
---|
[0] | 196 | $post_count = $core->blog->getPosts(array(),true)->f(0); |
---|
| 197 | $str_entries = ($post_count > 1) ? __('%d entries') : __('%d entry'); |
---|
| 198 | |
---|
| 199 | $comment_count = $core->blog->getComments(array(),true)->f(0); |
---|
| 200 | $str_comments = ($comment_count > 1) ? __('%d comments') : __('%d comment'); |
---|
| 201 | |
---|
[3] | 202 | $ws = $core->auth->user_prefs->addWorkspace('favorites'); |
---|
| 203 | $count = 0; |
---|
| 204 | foreach ($ws->dumpPrefs() as $k => $v) { |
---|
| 205 | // User favorites only |
---|
| 206 | if (!$v['global']) { |
---|
| 207 | $fav = unserialize($v['value']); |
---|
| 208 | if (($fav['permissions'] == '*') || $core->auth->check($fav['permissions'],$core->blog->id)) { |
---|
[896] | 209 | if (dc_valid_fav($fav['url'])) { |
---|
| 210 | $count++; |
---|
| 211 | $title = ($fav['name'] == 'posts' ? sprintf($str_entries,$post_count) : |
---|
| 212 | ($fav['name'] == 'comments' ? sprintf($str_comments,$comment_count) : $fav['title'])); |
---|
| 213 | $__dashboard_icons[$fav['name']] = new ArrayObject(array(__($title),$fav['url'],$fav['large-icon'])); |
---|
[130] | 214 | |
---|
[896] | 215 | # Let plugins set their own title for favorite on dashboard |
---|
| 216 | $core->callBehavior('adminDashboardFavsIcon',$core,$fav['name'],$__dashboard_icons[$fav['name']]); |
---|
| 217 | } |
---|
[3] | 218 | } |
---|
| 219 | } |
---|
| 220 | } |
---|
| 221 | if (!$count) { |
---|
| 222 | // Global favorites if any |
---|
| 223 | foreach ($ws->dumpPrefs() as $k => $v) { |
---|
| 224 | $fav = unserialize($v['value']); |
---|
| 225 | if (($fav['permissions'] == '*') || $core->auth->check($fav['permissions'],$core->blog->id)) { |
---|
[896] | 226 | if (dc_valid_fav($fav['url'])) { |
---|
| 227 | $count++; |
---|
| 228 | $title = ($fav['name'] == 'posts' ? sprintf($str_entries,$post_count) : |
---|
| 229 | ($fav['name'] == 'comments' ? sprintf($str_comments,$comment_count) : $fav['title'])); |
---|
| 230 | $__dashboard_icons[$fav['name']] = new ArrayObject(array(__($title),$fav['url'],$fav['large-icon'])); |
---|
[130] | 231 | |
---|
[896] | 232 | # Let plugins set their own title for favorite on dashboard |
---|
| 233 | $core->callBehavior('adminDashboardFavsIcon',$core,$fav['name'],$__dashboard_icons[$fav['name']]); |
---|
| 234 | } |
---|
[3] | 235 | } |
---|
| 236 | } |
---|
[0] | 237 | } |
---|
[3] | 238 | if (!$count) { |
---|
| 239 | // No user or global favorites, add "user pref" and "new entry" fav |
---|
| 240 | if ($core->auth->check('usage,contentadmin',$core->blog->id)) { |
---|
| 241 | $__dashboard_icons['new_post'] = new ArrayObject(array(__('New entry'),'post.php','images/menu/edit-b.png')); |
---|
| 242 | } |
---|
| 243 | $__dashboard_icons['prefs'] = new ArrayObject(array(__('My preferences'),'preferences.php','images/menu/user-pref-b.png')); |
---|
| 244 | } |
---|
[0] | 245 | |
---|
[1079] | 246 | # Send dashboard icons to templates |
---|
| 247 | $icons = array(); |
---|
| 248 | foreach ($__dashboard_icons as $i) { |
---|
| 249 | $icons[] = array( |
---|
| 250 | 'title' => $i[0], |
---|
| 251 | 'url' => $i[1], |
---|
| 252 | 'img' => dc_admin_icon_url($i[2]) |
---|
| 253 | ); |
---|
| 254 | } |
---|
| 255 | $_ctx->dashboard_icons = $icons; |
---|
| 256 | |
---|
| 257 | # Dashboard items |
---|
[0] | 258 | $__dashboard_items = new ArrayObject(array(new ArrayObject,new ArrayObject)); |
---|
[1079] | 259 | $core->callBehavior('adminDashboardItems', $core, $__dashboard_items); |
---|
[0] | 260 | |
---|
[1079] | 261 | # Send dashboard items to templates |
---|
| 262 | $items = array(); |
---|
| 263 | foreach ($__dashboard_items as $i) { |
---|
| 264 | if ($i->count() > 0) { |
---|
| 265 | foreach ($i as $v) { |
---|
| 266 | $items[] = $v; |
---|
[13] | 267 | } |
---|
[0] | 268 | } |
---|
| 269 | } |
---|
[1079] | 270 | $_ctx->dashboard_items = $items; |
---|
[0] | 271 | |
---|
[480] | 272 | # Dashboard content |
---|
| 273 | $__dashboard_contents = new ArrayObject(array(new ArrayObject,new ArrayObject)); |
---|
| 274 | $core->callBehavior('adminDashboardContents', $core, $__dashboard_contents); |
---|
| 275 | |
---|
[1079] | 276 | # Send dashboard contents to templates |
---|
| 277 | $contents = array(); |
---|
| 278 | foreach ($__dashboard_contents as $i) { |
---|
| 279 | if ($i->count() > 0) { |
---|
| 280 | foreach ($i as $v) { |
---|
| 281 | $contents[] = $v; |
---|
| 282 | } |
---|
| 283 | } |
---|
| 284 | } |
---|
| 285 | $_ctx->dashboard_contents = $contents; |
---|
[0] | 286 | |
---|
[1079] | 287 | # Blog status message |
---|
| 288 | if ($core->blog->status == 0) { |
---|
| 289 | $_ctx->addMessageStatic(__('This blog is offline')); |
---|
| 290 | } elseif ($core->blog->status == -1) { |
---|
| 291 | $_ctx->addMessageStatic(__('This blog is removed')); |
---|
[0] | 292 | } |
---|
| 293 | |
---|
[1079] | 294 | # Config errors messages |
---|
| 295 | if (!defined('DC_ADMIN_URL') || !DC_ADMIN_URL) { |
---|
| 296 | $_ctx->addMessageStatic( |
---|
| 297 | sprintf(__('%s is not defined, you should edit your configuration file.'),'DC_ADMIN_URL').' '. |
---|
| 298 | __('See <a href="http://dotclear.org/documentation/2.0/admin/config">documentation</a> for more information.') |
---|
| 299 | ); |
---|
| 300 | } |
---|
| 301 | if (!defined('DC_ADMIN_MAILFROM') || !DC_ADMIN_MAILFROM) { |
---|
| 302 | $_ctx->addMessageStatic( |
---|
| 303 | sprintf(__('%s is not defined, you should edit your configuration file.'),'DC_ADMIN_MAILFROM').' '. |
---|
| 304 | __('See <a href="http://dotclear.org/documentation/2.0/admin/config">documentation</a> for more information.') |
---|
| 305 | ); |
---|
[0] | 306 | } |
---|
| 307 | |
---|
[1079] | 308 | $_ctx->setPageTitle(__('Dashboard')); |
---|
| 309 | $core->tpl->display('index.html.twig'); |
---|
[0] | 310 | ?> |
---|