Dotclear

source: admin/index.php @ 3731:3770620079d4

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

Simplify licence block at the beginning of each file

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"><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-blue.png" 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/_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    )
162);
163
164if ($core->auth->getInfo('user_default_blog') != $core->blog->id && $core->auth->getBlogCount() > 1) {
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>';
167}
168
169if ($core->blog->status == 0) {
170    echo '<p class="static-msg">' . __('This blog is offline') . '.</p>';
171} elseif ($core->blog->status == -1) {
172    echo '<p class="static-msg">' . __('This blog is removed') . '.</p>';
173}
174
175if (!defined('DC_ADMIN_URL') || !DC_ADMIN_URL) {
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>';
181}
182
183if (!defined('DC_ADMIN_MAILFROM') || !DC_ADMIN_MAILFROM) {
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>';
189}
190
191$err = array();
192
193# Check cache directory
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    }
198} else {
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    }
202}
203
204# Check public directory
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    }
209} else {
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    }
213}
214
215# Error list
216if (count($err) > 0) {
217    echo '<div class="error"><p><strong>' . __('Error:') . '</strong></p>' .
218    '<ul><li>' . implode("</li><li>", $err) . '</li></ul></div>';
219}
220
221# Plugins install messages
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>';
228}
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>';
235}
236# Errors modules notifications
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    }
244}
245
246# Dashboard items and contents (processed first, as we need to know the result before displaying the icons.)
247$dashboardItems = '';
248foreach ($__dashboard_items as $i) {
249    foreach ($i as $v) {
250        $dashboardItems .= $v;
251    }
252}
253$dashboardContents = '';
254foreach ($__dashboard_contents as $i) {
255    foreach ($i as $v) {
256        $dashboardContents .= $v;
257    }
258}
259
260# Dashboard elements: icons then boxes (items then contents)
261echo '<div id="dashboard-main">';
262
263if (!$core->auth->user_prefs->dashboard->nofavicons) {
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="" />' .
269            '<br /><span>' . $i[0] . '</span></a></p>';
270    }
271    echo '</div>';
272}
273
274if ($core->auth->user_prefs->dashboard->quickentry) {
275    if ($core->auth->check('usage,contentadmin', $core->blog->id)) {
276        # Getting categories
277        $categories_combo = dcAdminCombos::getCategoriesCombo(
278            $core->blog->getCategories(array())
279        );
280
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>' .
287        form::field('post_title', 20, 255, array(
288            'class'      => 'maximal',
289            'extra_html' => 'required placeholder="' . __('Title') . '"'
290        )) .
291        '</p>' .
292        '<p class="area"><label class="required" ' .
293        'for="post_content"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Content:') . '</label> ' .
294        form::textarea('post_content', 50, 10, array('extra_html' => 'required placeholder="' . __('Content') . '"')) .
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> ' .
302            form::field('new_cat_title', 30, 255) . '</p>' .
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', '') .
319            '</p>' .
320            '</form>' .
321            '</div>';
322    }
323}
324
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