Dotclear

source: admin/index.php @ 3781:a86e029cb95d

Revision 3781:a86e029cb95d, 12.9 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

Animate some counters on dashboard icons (nb of comments, spam comments and posts), just for fun

RevLine 
[0]1<?php
[3731]2/**
3 * @package Dotclear
4 * @subpackage Backend
5 *
6 * @copyright Olivier Meunier & Association Dotclear
7 * @copyright GPL-2.0-only
8 */
[0]9
10if (!empty($_GET['pf'])) {
[3703]11    require dirname(__FILE__) . '/../inc/load_plugin_file.php';
12    exit;
[0]13}
14
[3260]15if (!empty($_GET['vf'])) {
[3703]16    require dirname(__FILE__) . '/../inc/load_var_file.php';
17    exit;
[3260]18}
19
[3703]20require dirname(__FILE__) . '/../inc/admin/prepend.php';
[0]21
22if (!empty($_GET['default_blog'])) {
[3703]23    try {
24        $core->setUserDefaultBlog($core->auth->userID(), $core->blog->id);
25        $core->adminurl->redirect("admin.home");
26    } catch (Exception $e) {
27        $core->error->add($e->getMessage());
28    }
[0]29}
30
31dcPage::check('usage,contentadmin');
32
[3703]33if ($core->plugins->disableDepModules($core->adminurl->get('admin.home', array()))) {
34    exit;
[3066]35}
36
[0]37# Logout
38if (!empty($_GET['logout'])) {
[3703]39    $core->session->destroy();
40    if (isset($_COOKIE['dc_admin'])) {
41        unset($_COOKIE['dc_admin']);
42        setcookie('dc_admin', false, -600, '', '', DC_ADMIN_SSL);
43    }
44    $core->adminurl->redirect("admin.auth");
45    exit;
[0]46}
47
48# Plugin install
49$plugins_install = $core->plugins->installModules();
50
[13]51# Check dashboard module prefs
[157]52$ws = $core->auth->user_prefs->addWorkspace('dashboard');
[13]53if (!$core->auth->user_prefs->dashboard->prefExists('doclinks')) {
[3703]54    if (!$core->auth->user_prefs->dashboard->prefExists('doclinks', true)) {
55        $core->auth->user_prefs->dashboard->put('doclinks', true, 'boolean', '', null, true);
56    }
57    $core->auth->user_prefs->dashboard->put('doclinks', true, 'boolean');
[13]58}
59if (!$core->auth->user_prefs->dashboard->prefExists('dcnews')) {
[3703]60    if (!$core->auth->user_prefs->dashboard->prefExists('dcnews', true)) {
61        $core->auth->user_prefs->dashboard->put('dcnews', true, 'boolean', '', null, true);
62    }
63    $core->auth->user_prefs->dashboard->put('dcnews', true, 'boolean');
[13]64}
65if (!$core->auth->user_prefs->dashboard->prefExists('quickentry')) {
[3703]66    if (!$core->auth->user_prefs->dashboard->prefExists('quickentry', true)) {
67        $core->auth->user_prefs->dashboard->put('quickentry', false, 'boolean', '', null, true);
68    }
69    $core->auth->user_prefs->dashboard->put('quickentry', false, 'boolean');
[13]70}
[3557]71if (!$core->auth->user_prefs->dashboard->prefExists('nodcupdate')) {
[3703]72    if (!$core->auth->user_prefs->dashboard->prefExists('nodcupdate', true)) {
73        $core->auth->user_prefs->dashboard->put('nodcupdate', false, 'boolean', '', null, true);
74    }
75    $core->auth->user_prefs->dashboard->put('nodcupdate', false, 'boolean');
[3557]76}
[13]77
[1699]78// Handle folded/unfolded sections in admin from user preferences
79$ws = $core->auth->user_prefs->addWorkspace('toggles');
80if (!$core->auth->user_prefs->toggles->prefExists('unfolded_sections')) {
[3703]81    $core->auth->user_prefs->toggles->put('unfolded_sections', '', 'string', 'Folded sections in admin', null, true);
[1699]82}
83
[0]84# Dashboard icons
85$__dashboard_icons = new ArrayObject();
86
[2229]87$favs = $core->favs->getUserFavorites();
88$core->favs->appendDashboardIcons($__dashboard_icons);
[0]89
[2174]90# Check plugins and themes update from repository
[3703]91$checkStoreUpdate = function ($mod, $url, $img, $icon) {
92    $repo = new dcStore($mod, $url);
93    $upd  = $repo->get(true);
94    if (!empty($upd)) {
95        $icon[0] .= '<br />' . sprintf(__('An update is available', '%s updates are available.', count($upd)), count($upd));
96        $icon[1] .= '#update';
97        $icon[2] = 'images/menu/' . $img . '-b-update.png';
98    }
[3491]99};
[2174]100if (isset($__dashboard_icons['plugins'])) {
[3703]101    $checkStoreUpdate($core->plugins, $core->blog->settings->system->store_plugin_url, 'plugins', $__dashboard_icons['plugins']);
[2174]102}
103if (isset($__dashboard_icons['blog_theme'])) {
[3703]104    $themes = new dcThemes($core);
105    $themes->loadModules($core->blog->themes_path, null);
106    $checkStoreUpdate($themes, $core->blog->settings->system->store_theme_url, 'blog-theme', $__dashboard_icons['blog_theme']);
[2174]107}
108
[0]109# Latest news for dashboard
[3703]110$__dashboard_items = new ArrayObject(array(new ArrayObject(), new ArrayObject()));
[0]111
[13]112$dashboardItem = 0;
[0]113
[1378]114# Documentation links
115if ($core->auth->user_prefs->dashboard->doclinks) {
[3703]116    if (!empty($__resources['doc'])) {
117        $doc_links = '<div class="box small dc-box"><h3>' . __('Documentation and support') . '</h3><ul>';
[2566]118
[3703]119        foreach ($__resources['doc'] as $k => $v) {
120            $doc_links .= '<li><a class="outgoing" href="' . $v . '" title="' . $k . '">' . $k .
[3771]121                ' <img src="images/outgoing-link.svg" alt="" /></a></li>';
[3703]122        }
[2566]123
[3703]124        $doc_links .= '</ul></div>';
125        $__dashboard_items[$dashboardItem][] = $doc_links;
126        $dashboardItem++;
127    }
[1378]128}
129
[0]130$core->callBehavior('adminDashboardItems', $core, $__dashboard_items);
131
[480]132# Dashboard content
[3703]133$__dashboard_contents = new ArrayObject(array(new ArrayObject, new ArrayObject));
[480]134$core->callBehavior('adminDashboardContents', $core, $__dashboard_contents);
135
[2842]136# Editor stuff
137$admin_post_behavior = '';
138if ($core->auth->user_prefs->dashboard->quickentry) {
[3703]139    if ($core->auth->check('usage,contentadmin', $core->blog->id)) {
140        $post_format = $core->auth->getOption('post_format');
141        $post_editor = $core->auth->getOption('editor');
142        if ($post_editor && !empty($post_editor[$post_format])) {
143            // context is not post because of tags not available
144            $admin_post_behavior = $core->callBehavior('adminPostEditor', $post_editor[$post_format], 'quickentry', array('#post_content'), $post_format);
145        }
146    }
[2842]147}
148
[0]149/* DISPLAY
150-------------------------------------------------------- */
151dcPage::open(__('Dashboard'),
[3703]152    dcPage::jsLoad('js/_index.js') .
153    $admin_post_behavior .
154    # --BEHAVIOR-- adminDashboardHeaders
155    $core->callBehavior('adminDashboardHeaders'),
156    dcPage::breadcrumb(
157        array(
158            __('Dashboard') . ' : ' . html::escapeHTML($core->blog->name) => ''
159        ),
160        array('home_link' => false)
161    )
[0]162);
163
[2159]164if ($core->auth->getInfo('user_default_blog') != $core->blog->id && $core->auth->getBlogCount() > 1) {
[3703]165    echo
166    '<p><a href="' . $core->adminurl->get("admin.home", array('default_blog' => 1)) . '" class="button">' . __('Make this blog my default blog') . '</a></p>';
[0]167}
168
169if ($core->blog->status == 0) {
[3703]170    echo '<p class="static-msg">' . __('This blog is offline') . '.</p>';
[0]171} elseif ($core->blog->status == -1) {
[3703]172    echo '<p class="static-msg">' . __('This blog is removed') . '.</p>';
[0]173}
174
[374]175if (!defined('DC_ADMIN_URL') || !DC_ADMIN_URL) {
[3703]176    echo
177    '<p class="static-msg">' .
178    sprintf(__('%s is not defined, you should edit your configuration file.'), 'DC_ADMIN_URL') .
179    ' ' . __('See <a href="http://dotclear.org/documentation/2.0/admin/config">documentation</a> for more information.') .
180        '</p>';
[373]181}
182
[374]183if (!defined('DC_ADMIN_MAILFROM') || !DC_ADMIN_MAILFROM) {
[3703]184    echo
185    '<p class="static-msg">' .
186    sprintf(__('%s is not defined, you should edit your configuration file.'), 'DC_ADMIN_MAILFROM') .
187    ' ' . __('See <a href="http://dotclear.org/documentation/2.0/admin/config">documentation</a> for more information.') .
188        '</p>';
[0]189}
190
[1535]191$err = array();
192
193# Check cache directory
[3703]194if ($core->auth->isSuperAdmin()) {
195    if (!is_dir(DC_TPL_CACHE) || !is_writable(DC_TPL_CACHE)) {
196        $err[] = '<p>' . __("The cache directory does not exist or is not writable. You must create this directory with sufficient rights and affect this location to \"DC_TPL_CACHE\" in inc/config.php file.") . '</p>';
197    }
[1705]198} else {
[3703]199    if (!is_dir(DC_TPL_CACHE) || !is_writable(DC_TPL_CACHE)) {
200        $err[] = '<p>' . __("The cache directory does not exist or is not writable. You should contact your administrator.") . '</p>';
201    }
[1535]202}
203
204# Check public directory
[3703]205if ($core->auth->isSuperAdmin()) {
206    if (!is_dir($core->blog->public_path) || !is_writable($core->blog->public_path)) {
207        $err[] = '<p>' . __("There is no writable directory /public/ at the location set in about:config \"public_path\". You must create this directory with sufficient rights (or change this setting).") . '</p>';
208    }
[1705]209} else {
[3703]210    if (!is_dir($core->blog->public_path) || !is_writable($core->blog->public_path)) {
211        $err[] = '<p>' . __("There is no writable root directory for the media manager. You should contact your administrator.") . '</p>';
212    }
[1535]213}
214
215# Error list
216if (count($err) > 0) {
[3703]217    echo '<div class="error"><p><strong>' . __('Error:') . '</strong></p>' .
218    '<ul><li>' . implode("</li><li>", $err) . '</li></ul></div>';
[1535]219}
220
[0]221# Plugins install messages
[3703]222if (!empty($plugins_install['success'])) {
223    echo '<div class="success">' . __('Following plugins have been installed:') . '<ul>';
224    foreach ($plugins_install['success'] as $k => $v) {
225        echo '<li>' . $k . '</li>';
226    }
227    echo '</ul></div>';
[0]228}
[3703]229if (!empty($plugins_install['failure'])) {
230    echo '<div class="error">' . __('Following plugins have not been installed:') . '<ul>';
231    foreach ($plugins_install['failure'] as $k => $v) {
232        echo '<li>' . $k . ' (' . $v . ')</li>';
233    }
234    echo '</ul></div>';
[0]235}
[112]236# Errors modules notifications
[3703]237if ($core->auth->isSuperAdmin()) {
238    $list = $core->plugins->getErrors();
239    if (!empty($list)) {
240        echo
241        '<div class="error" id="module-errors" class="error"><p>' . __('Errors have occured with following plugins:') . '</p> ' .
242        '<ul><li>' . implode("</li>\n<li>", $list) . '</li></ul></div>';
243    }
[112]244}
245
[3412]246# Dashboard items and contents (processed first, as we need to know the result before displaying the icons.)
[1729]247$dashboardItems = '';
[3703]248foreach ($__dashboard_items as $i) {
249    foreach ($i as $v) {
250        $dashboardItems .= $v;
251    }
[3412]252}
253$dashboardContents = '';
[3703]254foreach ($__dashboard_contents as $i) {
255    foreach ($i as $v) {
256        $dashboardContents .= $v;
257    }
[112]258}
259
[3412]260# Dashboard elements: icons then boxes (items then contents)
[2116]261echo '<div id="dashboard-main">';
262
[3238]263if (!$core->auth->user_prefs->dashboard->nofavicons) {
[3703]264    # Dashboard icons
265    echo '<div id="icons">';
266    foreach ($__dashboard_icons as $i) {
267        echo
268        '<p><a href="' . $i[1] . '"><img src="' . dc_admin_icon_url($i[2]) . '" alt="" />' .
[3781]269            '<br /><span class="db-icon-title">' . $i[0] . '</span></a></p>';
[3703]270    }
271    echo '</div>';
[0]272}
273
[13]274if ($core->auth->user_prefs->dashboard->quickentry) {
[3703]275    if ($core->auth->check('usage,contentadmin', $core->blog->id)) {
276        # Getting categories
277        $categories_combo = dcAdminCombos::getCategoriesCombo(
278            $core->blog->getCategories(array())
279        );
[2566]280
[3703]281        echo
282        '<div id="quick">' .
283        '<h3>' . __('Quick entry') . sprintf(' &rsaquo; %s', $core->auth->getOption('post_format')) . '</h3>' .
284        '<form id="quick-entry" action="' . $core->adminurl->get('admin.post') . '" method="post" class="fieldset">' .
285        '<h4>' . __('New entry') . '</h4>' .
286        '<p class="col"><label for="post_title" class="required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Title:') . '</label>' .
[3725]287        form::field('post_title', 20, 255, array(
288            'class'      => 'maximal',
289            'extra_html' => 'required placeholder="' . __('Title') . '"'
290        )) .
[3703]291        '</p>' .
292        '<p class="area"><label class="required" ' .
293        'for="post_content"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Content:') . '</label> ' .
[3710]294        form::textarea('post_content', 50, 10, array('extra_html' => 'required placeholder="' . __('Content') . '"')) .
[3703]295        '</p>' .
296        '<p><label for="cat_id" class="classic">' . __('Category:') . '</label> ' .
297        form::combo('cat_id', $categories_combo) . '</p>' .
298        ($core->auth->check('categories', $core->blog->id)
299            ? '<div>' .
300            '<p id="new_cat" class="q-cat">' . __('Add a new category') . '</p>' .
301            '<p class="q-cat"><label for="new_cat_title">' . __('Title:') . '</label> ' .
[3725]302            form::field('new_cat_title', 30, 255) . '</p>' .
[3703]303            '<p class="q-cat"><label for="new_cat_parent">' . __('Parent:') . '</label> ' .
304            form::combo('new_cat_parent', $categories_combo) .
305            '</p>' .
306            '<p class="form-note info clear">' . __('This category will be created when you will save your post.') . '</p>' .
307            '</div>'
308            : '') .
309        '<p><input type="submit" value="' . __('Save') . '" name="save" /> ' .
310        ($core->auth->check('publish', $core->blog->id)
311            ? '<input type="hidden" value="' . __('Save and publish') . '" name="save-publish" />'
312            : '') .
313        $core->formNonce() .
314        form::hidden('post_status', -2) .
315        form::hidden('post_format', $core->auth->getOption('post_format')) .
316        form::hidden('post_excerpt', '') .
317        form::hidden('post_lang', $core->auth->getInfo('user_lang')) .
318        form::hidden('post_notes', '') .
[3730]319            '</p>' .
320            '</form>' .
[3703]321            '</div>';
322    }
[3730]323}
[0]324
[3730]325if ($dashboardContents != '' || $dashboardItems != '') {
326    echo
327        '<div id="dashboard-boxes">' .
328        ($dashboardItems != '' ? '<div class="db-items">' . $dashboardItems . '</div>' : '') .
329        ($dashboardContents != '' ? '<div class="db-contents">' . $dashboardContents . '</div>' : '') .
330        '</div>';
331}
332
333echo '</div>'; #end dashboard-main
334dcPage::helpBlock('core_dashboard');
335dcPage::close();
Note: See TracBrowser for help on using the repository browser.

Sites map