Dotclear

source: admin/index.php @ 3833:ea88f004549f

Revision 3833:ea88f004549f, 15.3 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

Mainly every areas on the dashboard are now sortable

Line 
1<?php
2/**
3 * @package Dotclear
4 * @subpackage Backend
5 *
6 * @copyright Olivier Meunier & Association Dotclear
7 * @copyright GPL-2.0-only
8 */
9
10if (!empty($_GET['pf'])) {
11    require dirname(__FILE__) . '/../inc/load_plugin_file.php';
12    exit;
13}
14
15if (!empty($_GET['vf'])) {
16    require dirname(__FILE__) . '/../inc/load_var_file.php';
17    exit;
18}
19
20require dirname(__FILE__) . '/../inc/admin/prepend.php';
21
22if (!empty($_GET['default_blog'])) {
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    }
29}
30
31dcPage::check('usage,contentadmin');
32
33if ($core->plugins->disableDepModules($core->adminurl->get('admin.home', array()))) {
34    exit;
35}
36
37# Logout
38if (!empty($_GET['logout'])) {
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;
46}
47
48# Plugin install
49$plugins_install = $core->plugins->installModules();
50
51# Check dashboard module prefs
52$ws = $core->auth->user_prefs->addWorkspace('dashboard');
53if (!$core->auth->user_prefs->dashboard->prefExists('doclinks')) {
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');
58}
59if (!$core->auth->user_prefs->dashboard->prefExists('dcnews')) {
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');
64}
65if (!$core->auth->user_prefs->dashboard->prefExists('quickentry')) {
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');
70}
71if (!$core->auth->user_prefs->dashboard->prefExists('nodcupdate')) {
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');
76}
77
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')) {
81    $core->auth->user_prefs->toggles->put('unfolded_sections', '', 'string', 'Folded sections in admin', null, true);
82}
83
84# Dashboard icons
85$__dashboard_icons = new ArrayObject();
86
87$favs = $core->favs->getUserFavorites();
88$core->favs->appendDashboardIcons($__dashboard_icons);
89
90# Check plugins and themes update from repository
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    }
99};
100if (isset($__dashboard_icons['plugins'])) {
101    $checkStoreUpdate($core->plugins, $core->blog->settings->system->store_plugin_url, 'plugins', $__dashboard_icons['plugins']);
102}
103if (isset($__dashboard_icons['blog_theme'])) {
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']);
107}
108
109# Latest news for dashboard
110$__dashboard_items = new ArrayObject(array(new ArrayObject(), new ArrayObject()));
111
112$dashboardItem = 0;
113
114# Documentation links
115if ($core->auth->user_prefs->dashboard->doclinks) {
116    if (!empty($__resources['doc'])) {
117        $doc_links = '<div class="box small dc-box" id="doc-and-support"><h3>' . __('Documentation and support') . '</h3><ul>';
118
119        foreach ($__resources['doc'] as $k => $v) {
120            $doc_links .= '<li><a class="outgoing" href="' . $v . '" title="' . $k . '">' . $k .
121                ' <img src="images/outgoing-link.svg" alt="" /></a></li>';
122        }
123
124        $doc_links .= '</ul></div>';
125        $__dashboard_items[$dashboardItem][] = $doc_links;
126        $dashboardItem++;
127    }
128}
129
130$core->callBehavior('adminDashboardItems', $core, $__dashboard_items);
131
132# Dashboard content
133$__dashboard_contents = new ArrayObject(array(new ArrayObject, new ArrayObject));
134$core->callBehavior('adminDashboardContents', $core, $__dashboard_contents);
135
136# Editor stuff
137$admin_post_behavior = '';
138if ($core->auth->user_prefs->dashboard->quickentry) {
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    }
147}
148
149/* DISPLAY
150-------------------------------------------------------- */
151dcPage::open(__('Dashboard'),
152    dcPage::jsLoad('js/jquery/jquery-ui.custom.js') .
153    dcPage::jsLoad('js/jquery/jquery.ui.touch-punch.js') .
154    dcPage::jsLoad('js/_index.js') .
155    $admin_post_behavior .
156    # --BEHAVIOR-- adminDashboardHeaders
157    $core->callBehavior('adminDashboardHeaders'),
158    dcPage::breadcrumb(
159        array(
160            __('Dashboard') . ' : ' . html::escapeHTML($core->blog->name) => ''
161        ),
162        array('home_link' => false)
163    )
164);
165
166if ($core->auth->getInfo('user_default_blog') != $core->blog->id && $core->auth->getBlogCount() > 1) {
167    echo
168    '<p><a href="' . $core->adminurl->get("admin.home", array('default_blog' => 1)) . '" class="button">' . __('Make this blog my default blog') . '</a></p>';
169}
170
171if ($core->blog->status == 0) {
172    echo '<p class="static-msg">' . __('This blog is offline') . '.</p>';
173} elseif ($core->blog->status == -1) {
174    echo '<p class="static-msg">' . __('This blog is removed') . '.</p>';
175}
176
177if (!defined('DC_ADMIN_URL') || !DC_ADMIN_URL) {
178    echo
179    '<p class="static-msg">' .
180    sprintf(__('%s is not defined, you should edit your configuration file.'), 'DC_ADMIN_URL') .
181    ' ' . __('See <a href="http://dotclear.org/documentation/2.0/admin/config">documentation</a> for more information.') .
182        '</p>';
183}
184
185if (!defined('DC_ADMIN_MAILFROM') || !DC_ADMIN_MAILFROM) {
186    echo
187    '<p class="static-msg">' .
188    sprintf(__('%s is not defined, you should edit your configuration file.'), 'DC_ADMIN_MAILFROM') .
189    ' ' . __('See <a href="http://dotclear.org/documentation/2.0/admin/config">documentation</a> for more information.') .
190        '</p>';
191}
192
193$err = array();
194
195# Check cache directory
196if ($core->auth->isSuperAdmin()) {
197    if (!is_dir(DC_TPL_CACHE) || !is_writable(DC_TPL_CACHE)) {
198        $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>';
199    }
200} else {
201    if (!is_dir(DC_TPL_CACHE) || !is_writable(DC_TPL_CACHE)) {
202        $err[] = '<p>' . __("The cache directory does not exist or is not writable. You should contact your administrator.") . '</p>';
203    }
204}
205
206# Check public directory
207if ($core->auth->isSuperAdmin()) {
208    if (!is_dir($core->blog->public_path) || !is_writable($core->blog->public_path)) {
209        $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>';
210    }
211} else {
212    if (!is_dir($core->blog->public_path) || !is_writable($core->blog->public_path)) {
213        $err[] = '<p>' . __("There is no writable root directory for the media manager. You should contact your administrator.") . '</p>';
214    }
215}
216
217# Error list
218if (count($err) > 0) {
219    echo '<div class="error"><p><strong>' . __('Error:') . '</strong></p>' .
220    '<ul><li>' . implode("</li><li>", $err) . '</li></ul></div>';
221}
222
223# Plugins install messages
224if (!empty($plugins_install['success'])) {
225    echo '<div class="success">' . __('Following plugins have been installed:') . '<ul>';
226    foreach ($plugins_install['success'] as $k => $v) {
227        echo '<li>' . $k . '</li>';
228    }
229    echo '</ul></div>';
230}
231if (!empty($plugins_install['failure'])) {
232    echo '<div class="error">' . __('Following plugins have not been installed:') . '<ul>';
233    foreach ($plugins_install['failure'] as $k => $v) {
234        echo '<li>' . $k . ' (' . $v . ')</li>';
235    }
236    echo '</ul></div>';
237}
238# Errors modules notifications
239if ($core->auth->isSuperAdmin()) {
240    $list = $core->plugins->getErrors();
241    if (!empty($list)) {
242        echo
243        '<div class="error" id="module-errors" class="error"><p>' . __('Errors have occured with following plugins:') . '</p> ' .
244        '<ul><li>' . implode("</li>\n<li>", $list) . '</li></ul></div>';
245    }
246}
247
248# Get current main orders
249$main_order = $core->auth->user_prefs->dashboard->main_order;
250$main_order = ($main_order != '' ? explode(',', $main_order) : array());
251
252# Get current boxes orders
253$boxes_order = $core->auth->user_prefs->dashboard->boxes_order;
254$boxes_order = ($boxes_order != '' ? explode(',', $boxes_order) : array());
255
256# Get current boxes items orders
257$boxes_items_order = $core->auth->user_prefs->dashboard->boxes_items_order;
258$boxes_items_order = ($boxes_items_order != '' ? explode(',', $boxes_items_order) : array());
259
260# Get current boxes contents orders
261$boxes_contents_order = $core->auth->user_prefs->dashboard->boxes_contents_order;
262$boxes_contents_order = ($boxes_contents_order != '' ? explode(',', $boxes_contents_order) : array());
263
264$composeItems = function ($list, $blocks, $flat = false) {
265
266    $ret   = array();
267    $items = array();
268
269    if ($flat) {
270        $items = $blocks;
271    } else {
272        foreach ($blocks as $i) {
273            foreach ($i as $v) {
274                $items[] = $v;
275            }
276        }
277    }
278
279    # First loop to find ordered indexes
280    $order = array();
281    $index = 0;
282    foreach ($items as $v) {
283        if (preg_match('/<div.*?id="([^"].*?)".*?>/ms', $v, $match)) {
284            $id       = $match[1];
285            $position = array_search($id, $list, true);
286            if ($position !== false) {
287                $order[$position] = $index;
288            }
289        }
290        $index++;
291    }
292
293    # Second loop to combine ordered items
294    $index = 0;
295    foreach ($items as $v) {
296        $position = array_search($index, $order, true);
297        if ($position !== false) {
298            $ret[$position] = $v;
299        }
300        $index++;
301    }
302    # Reorder items on their position (key)
303    ksort($ret);
304
305    # Third loop to combine unordered items
306    $index = 0;
307    foreach ($items as $v) {
308        $position = array_search($index, $order, true);
309        if ($position === false) {
310            $ret[count($ret)] = $v;
311        }
312        $index++;
313    }
314
315    return join('', $ret);
316};
317
318# Compose dashboard items (doc, …)
319$dashboardItems = $composeItems($boxes_items_order, $__dashboard_items);
320# Compose dashboard contents (plugin's modules)
321$dashboardContents = $composeItems($boxes_contents_order, $__dashboard_contents);
322
323$__dashboard_boxes = array();
324if ($dashboardItems != '') {
325    $__dashboard_boxes[] = '<div class="db-items" id="db-items">' . $dashboardItems . '</div>';
326}
327if ($dashboardContents != '') {
328    $__dashboard_boxes[] = '<div class="db-contents" id="db-contents">' . $dashboardContents . '</div>';
329}
330$dashboardBoxes = $composeItems($boxes_order, $__dashboard_boxes, true);
331
332# Compose main area
333$__dashboard_main = array();
334if (!$core->auth->user_prefs->dashboard->nofavicons) {
335    # Dashboard icons
336    $dashboardIcons = '<div id="icons">';
337    foreach ($__dashboard_icons as $i) {
338        $dashboardIcons .= '<p><a href="' . $i[1] . '"><img src="' . dc_admin_icon_url($i[2]) . '" alt="" />' .
339            '<br /><span class="db-icon-title">' . $i[0] . '</span></a></p>';
340    }
341    $dashboardIcons .= '</div>';
342    $__dashboard_main[] = $dashboardIcons;
343}
344if ($core->auth->user_prefs->dashboard->quickentry) {
345    if ($core->auth->check('usage,contentadmin', $core->blog->id)) {
346        # Getting categories
347        $categories_combo = dcAdminCombos::getCategoriesCombo(
348            $core->blog->getCategories(array())
349        );
350
351        $dashboardQuickEntry =
352        '<div id="quick">' .
353        '<h3>' . __('Quick entry') . sprintf(' &rsaquo; %s', $core->auth->getOption('post_format')) . '</h3>' .
354        '<form id="quick-entry" action="' . $core->adminurl->get('admin.post') . '" method="post" class="fieldset">' .
355        '<h4>' . __('New entry') . '</h4>' .
356        '<p class="col"><label for="post_title" class="required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Title:') . '</label>' .
357        form::field('post_title', 20, 255, array(
358            'class'      => 'maximal',
359            'extra_html' => 'required placeholder="' . __('Title') . '"'
360        )) .
361        '</p>' .
362        '<p class="area"><label class="required" ' .
363        'for="post_content"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Content:') . '</label> ' .
364        form::textarea('post_content', 50, 10, array('extra_html' => 'required placeholder="' . __('Content') . '"')) .
365        '</p>' .
366        '<p><label for="cat_id" class="classic">' . __('Category:') . '</label> ' .
367        form::combo('cat_id', $categories_combo) . '</p>' .
368        ($core->auth->check('categories', $core->blog->id)
369            ? '<div>' .
370            '<p id="new_cat" class="q-cat">' . __('Add a new category') . '</p>' .
371            '<p class="q-cat"><label for="new_cat_title">' . __('Title:') . '</label> ' .
372            form::field('new_cat_title', 30, 255) . '</p>' .
373            '<p class="q-cat"><label for="new_cat_parent">' . __('Parent:') . '</label> ' .
374            form::combo('new_cat_parent', $categories_combo) .
375            '</p>' .
376            '<p class="form-note info clear">' . __('This category will be created when you will save your post.') . '</p>' .
377            '</div>'
378            : '') .
379        '<p><input type="submit" value="' . __('Save') . '" name="save" /> ' .
380        ($core->auth->check('publish', $core->blog->id)
381            ? '<input type="hidden" value="' . __('Save and publish') . '" name="save-publish" />'
382            : '') .
383        $core->formNonce() .
384        form::hidden('post_status', -2) .
385        form::hidden('post_format', $core->auth->getOption('post_format')) .
386        form::hidden('post_excerpt', '') .
387        form::hidden('post_lang', $core->auth->getInfo('user_lang')) .
388        form::hidden('post_notes', '') .
389            '</p>' .
390            '</form>' .
391            '</div>';
392        $__dashboard_main[] = $dashboardQuickEntry;
393    }
394}
395if ($dashboardBoxes != '') {
396    $__dashboard_main[] = '<div id="dashboard-boxes">' . $dashboardBoxes . '</div>';
397}
398$dashboardMain = $composeItems($main_order, $__dashboard_main, true);
399
400# Dashboard elements
401echo '<div id="dashboard-main">' . $dashboardMain . '</div>';
402
403dcPage::helpBlock('core_dashboard');
404dcPage::close();
Note: See TracBrowser for help on using the repository browser.

Sites map