Dotclear

source: admin/index.php @ 3918:350bc5990b82

Revision 3918:350bc5990b82, 16.1 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

Switch from p to div to cope with quick entry editor markup, fixes #2279

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', []))) {
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([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([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', ['#post_content'], $post_format);
145        }
146    }
147}
148
149# Dashboard drag'n'drop switch for its elements
150$core->auth->user_prefs->addWorkspace('accessibility');
151$dragndrop = '';
152if (!$core->auth->user_prefs->accessibility->nodragdrop) {
153    $dragndrop =
154    '<script type="text/javascript">' . "\n" .
155    dcPage::jsVar('dotclear.dragndrop_off', __('Dashboard area\'s drag and drop is disabled')) . "\n" .
156    dcPage::jsVar('dotclear.dragndrop_on', __('Dashboard area\'s drag and drop is enabled')) . "\n" .
157    "</script>\n" .
158    '<input type="checkbox" id="dragndrop" class="sr-only" title="' .
159        __('Dashboard area\'s drag and drop is disabled') . '" />' .
160    '<label for="dragndrop">' .
161    '<svg aria-hidden="true" focusable="false" class="dragndrop-svg">' .
162    '<use xlink:href="images/dragndrop.svg#mask"></use>' .
163    '</svg>' .
164    '<span id="dragndrop-label" class="sr-only">' . __('Dashboard area\'s drag and drop is disabled') . '</span>' .
165    '</label>';
166}
167
168/* DISPLAY
169-------------------------------------------------------- */
170dcPage::open(__('Dashboard'),
171    dcPage::jsLoad('js/jquery/jquery-ui.custom.js') .
172    dcPage::jsLoad('js/jquery/jquery.ui.touch-punch.js') .
173    dcPage::jsLoad('js/_index.js') .
174    $admin_post_behavior .
175    # --BEHAVIOR-- adminDashboardHeaders
176    $core->callBehavior('adminDashboardHeaders'),
177    dcPage::breadcrumb(
178        [
179            __('Dashboard') . ' : ' . html::escapeHTML($core->blog->name) => ''
180        ],
181        ['home_link' => false]
182    )
183);
184
185if ($core->auth->getInfo('user_default_blog') != $core->blog->id && $core->auth->getBlogCount() > 1) {
186    echo
187    '<p><a href="' . $core->adminurl->get("admin.home", ['default_blog' => 1]) . '" class="button">' . __('Make this blog my default blog') . '</a></p>';
188}
189
190if ($core->blog->status == 0) {
191    echo '<p class="static-msg">' . __('This blog is offline') . '.</p>';
192} elseif ($core->blog->status == -1) {
193    echo '<p class="static-msg">' . __('This blog is removed') . '.</p>';
194}
195
196if (!defined('DC_ADMIN_URL') || !DC_ADMIN_URL) {
197    echo
198    '<p class="static-msg">' .
199    sprintf(__('%s is not defined, you should edit your configuration file.'), 'DC_ADMIN_URL') .
200    ' ' . __('See <a href="http://dotclear.org/documentation/2.0/admin/config">documentation</a> for more information.') .
201        '</p>';
202}
203
204if (!defined('DC_ADMIN_MAILFROM') || !DC_ADMIN_MAILFROM) {
205    echo
206    '<p class="static-msg">' .
207    sprintf(__('%s is not defined, you should edit your configuration file.'), 'DC_ADMIN_MAILFROM') .
208    ' ' . __('See <a href="http://dotclear.org/documentation/2.0/admin/config">documentation</a> for more information.') .
209        '</p>';
210}
211
212$err = [];
213
214# Check cache directory
215if ($core->auth->isSuperAdmin()) {
216    if (!is_dir(DC_TPL_CACHE) || !is_writable(DC_TPL_CACHE)) {
217        $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>';
218    }
219} else {
220    if (!is_dir(DC_TPL_CACHE) || !is_writable(DC_TPL_CACHE)) {
221        $err[] = '<p>' . __("The cache directory does not exist or is not writable. You should contact your administrator.") . '</p>';
222    }
223}
224
225# Check public directory
226if ($core->auth->isSuperAdmin()) {
227    if (!is_dir($core->blog->public_path) || !is_writable($core->blog->public_path)) {
228        $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>';
229    }
230} else {
231    if (!is_dir($core->blog->public_path) || !is_writable($core->blog->public_path)) {
232        $err[] = '<p>' . __("There is no writable root directory for the media manager. You should contact your administrator.") . '</p>';
233    }
234}
235
236# Error list
237if (count($err) > 0) {
238    echo '<div class="error"><p><strong>' . __('Error:') . '</strong></p>' .
239    '<ul><li>' . implode("</li><li>", $err) . '</li></ul></div>';
240}
241
242# Plugins install messages
243if (!empty($plugins_install['success'])) {
244    echo '<div class="success">' . __('Following plugins have been installed:') . '<ul>';
245    foreach ($plugins_install['success'] as $k => $v) {
246        echo '<li>' . $k . '</li>';
247    }
248    echo '</ul></div>';
249}
250if (!empty($plugins_install['failure'])) {
251    echo '<div class="error">' . __('Following plugins have not been installed:') . '<ul>';
252    foreach ($plugins_install['failure'] as $k => $v) {
253        echo '<li>' . $k . ' (' . $v . ')</li>';
254    }
255    echo '</ul></div>';
256}
257# Errors modules notifications
258if ($core->auth->isSuperAdmin()) {
259    $list = $core->plugins->getErrors();
260    if (!empty($list)) {
261        echo
262        '<div class="error" id="module-errors" class="error"><p>' . __('Errors have occured with following plugins:') . '</p> ' .
263        '<ul><li>' . implode("</li>\n<li>", $list) . '</li></ul></div>';
264    }
265}
266
267# Get current main orders
268$main_order = $core->auth->user_prefs->dashboard->main_order;
269$main_order = ($main_order != '' ? explode(',', $main_order) : []);
270
271# Get current boxes orders
272$boxes_order = $core->auth->user_prefs->dashboard->boxes_order;
273$boxes_order = ($boxes_order != '' ? explode(',', $boxes_order) : []);
274
275# Get current boxes items orders
276$boxes_items_order = $core->auth->user_prefs->dashboard->boxes_items_order;
277$boxes_items_order = ($boxes_items_order != '' ? explode(',', $boxes_items_order) : []);
278
279# Get current boxes contents orders
280$boxes_contents_order = $core->auth->user_prefs->dashboard->boxes_contents_order;
281$boxes_contents_order = ($boxes_contents_order != '' ? explode(',', $boxes_contents_order) : []);
282
283$composeItems = function ($list, $blocks, $flat = false) {
284
285    $ret   = [];
286    $items = [];
287
288    if ($flat) {
289        $items = $blocks;
290    } else {
291        foreach ($blocks as $i) {
292            foreach ($i as $v) {
293                $items[] = $v;
294            }
295        }
296    }
297
298    # First loop to find ordered indexes
299    $order = [];
300    $index = 0;
301    foreach ($items as $v) {
302        if (preg_match('/<div.*?id="([^"].*?)".*?>/ms', $v, $match)) {
303            $id       = $match[1];
304            $position = array_search($id, $list, true);
305            if ($position !== false) {
306                $order[$position] = $index;
307            }
308        }
309        $index++;
310    }
311
312    # Second loop to combine ordered items
313    $index = 0;
314    foreach ($items as $v) {
315        $position = array_search($index, $order, true);
316        if ($position !== false) {
317            $ret[$position] = $v;
318        }
319        $index++;
320    }
321    # Reorder items on their position (key)
322    ksort($ret);
323
324    # Third loop to combine unordered items
325    $index = 0;
326    foreach ($items as $v) {
327        $position = array_search($index, $order, true);
328        if ($position === false) {
329            $ret[count($ret)] = $v;
330        }
331        $index++;
332    }
333
334    return join('', $ret);
335};
336
337# Compose dashboard items (doc, …)
338$dashboardItems = $composeItems($boxes_items_order, $__dashboard_items);
339# Compose dashboard contents (plugin's modules)
340$dashboardContents = $composeItems($boxes_contents_order, $__dashboard_contents);
341
342$__dashboard_boxes = [];
343if ($dashboardItems != '') {
344    $__dashboard_boxes[] = '<div class="db-items" id="db-items">' . $dashboardItems . '</div>';
345}
346if ($dashboardContents != '') {
347    $__dashboard_boxes[] = '<div class="db-contents" id="db-contents">' . $dashboardContents . '</div>';
348}
349$dashboardBoxes = $composeItems($boxes_order, $__dashboard_boxes, true);
350
351# Compose main area
352$__dashboard_main = [];
353if (!$core->auth->user_prefs->dashboard->nofavicons) {
354    # Dashboard icons
355    $dashboardIcons = '<div id="icons">';
356    foreach ($__dashboard_icons as $i) {
357        $dashboardIcons .= '<p><a href="' . $i[1] . '"><img src="' . dc_admin_icon_url($i[2]) . '" alt="" />' .
358            '<br /><span class="db-icon-title">' . $i[0] . '</span></a></p>';
359    }
360    $dashboardIcons .= '</div>';
361    $__dashboard_main[] = $dashboardIcons;
362}
363if ($core->auth->user_prefs->dashboard->quickentry) {
364    if ($core->auth->check('usage,contentadmin', $core->blog->id)) {
365        # Getting categories
366        $categories_combo = dcAdminCombos::getCategoriesCombo(
367            $core->blog->getCategories([])
368        );
369
370        $dashboardQuickEntry =
371        '<div id="quick">' .
372        '<h3>' . __('Quick entry') . sprintf(' &rsaquo; %s', $core->auth->getOption('post_format')) . '</h3>' .
373        '<form id="quick-entry" action="' . $core->adminurl->get('admin.post') . '" method="post" class="fieldset">' .
374        '<h4>' . __('New entry') . '</h4>' .
375        '<p class="col"><label for="post_title" class="required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Title:') . '</label>' .
376        form::field('post_title', 20, 255, [
377            'class'      => 'maximal',
378            'extra_html' => 'required placeholder="' . __('Title') . '"'
379        ]) .
380        '</p>' .
381        '<div class="area"><label class="required" ' .
382        'for="post_content"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Content:') . '</label> ' .
383        form::textarea('post_content', 50, 10, ['extra_html' => 'required placeholder="' . __('Content') . '"']) .
384        '</div>' .
385        '<p><label for="cat_id" class="classic">' . __('Category:') . '</label> ' .
386        form::combo('cat_id', $categories_combo) . '</p>' .
387        ($core->auth->check('categories', $core->blog->id)
388            ? '<div>' .
389            '<p id="new_cat" class="q-cat">' . __('Add a new category') . '</p>' .
390            '<p class="q-cat"><label for="new_cat_title">' . __('Title:') . '</label> ' .
391            form::field('new_cat_title', 30, 255) . '</p>' .
392            '<p class="q-cat"><label for="new_cat_parent">' . __('Parent:') . '</label> ' .
393            form::combo('new_cat_parent', $categories_combo) .
394            '</p>' .
395            '<p class="form-note info clear">' . __('This category will be created when you will save your post.') . '</p>' .
396            '</div>'
397            : '') .
398        '<p><input type="submit" value="' . __('Save') . '" name="save" /> ' .
399        ($core->auth->check('publish', $core->blog->id)
400            ? '<input type="hidden" value="' . __('Save and publish') . '" name="save-publish" />'
401            : '') .
402        $core->formNonce() .
403        form::hidden('post_status', -2) .
404        form::hidden('post_format', $core->auth->getOption('post_format')) .
405        form::hidden('post_excerpt', '') .
406        form::hidden('post_lang', $core->auth->getInfo('user_lang')) .
407        form::hidden('post_notes', '') .
408            '</p>' .
409            '</form>' .
410            '</div>';
411        $__dashboard_main[] = $dashboardQuickEntry;
412    }
413}
414if ($dashboardBoxes != '') {
415    $__dashboard_main[] = '<div id="dashboard-boxes">' . $dashboardBoxes . '</div>';
416}
417$dashboardMain = $composeItems($main_order, $__dashboard_main, true);
418
419echo $dragndrop . '<div id="dashboard-main">' . $dashboardMain . '</div>';
420
421dcPage::helpBlock('core_dashboard');
422dcPage::close();
Note: See TracBrowser for help on using the repository browser.

Sites map