Dotclear

source: admin/index.php @ 3024:b4724a397193

Revision 3024:b4724a397193, 13.3 KB checked in by franck <carnet.franck.paul@…>, 10 years ago (diff)

Add syntax arg to adminPostEditor behaviour (may be 'wiki', 'xhtml', 'markdown', …), fixes #2042

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
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
13if (!empty($_GET['pf'])) {
14     require dirname(__FILE__).'/../inc/load_plugin_file.php';
15     exit;
16}
17
18require dirname(__FILE__).'/../inc/admin/prepend.php';
19
20if (!empty($_GET['default_blog'])) {
21     try {
22          $core->setUserDefaultBlog($core->auth->userID(),$core->blog->id);
23          $core->adminurl->redirect("admin.home");
24     } catch (Exception $e) {
25          $core->error->add($e->getMessage());
26     }
27}
28
29dcPage::check('usage,contentadmin');
30
31# Logout
32if (!empty($_GET['logout'])) {
33     $core->session->destroy();
34     if (isset($_COOKIE['dc_admin'])) {
35          unset($_COOKIE['dc_admin']);
36          setcookie('dc_admin',false,-600,'','',DC_ADMIN_SSL);
37     }
38     $core->adminurl->redirect("admin.auth");
39     exit;
40}
41
42# Plugin install
43$plugins_install = $core->plugins->installModules();
44
45# Check dashboard module prefs
46$ws = $core->auth->user_prefs->addWorkspace('dashboard');
47if (!$core->auth->user_prefs->dashboard->prefExists('doclinks')) {
48     if (!$core->auth->user_prefs->dashboard->prefExists('doclinks',true)) {
49          $core->auth->user_prefs->dashboard->put('doclinks',true,'boolean','',null,true);
50     }
51     $core->auth->user_prefs->dashboard->put('doclinks',true,'boolean');
52}
53if (!$core->auth->user_prefs->dashboard->prefExists('dcnews')) {
54     if (!$core->auth->user_prefs->dashboard->prefExists('dcnews',true)) {
55          $core->auth->user_prefs->dashboard->put('dcnews',true,'boolean','',null,true);
56     }
57     $core->auth->user_prefs->dashboard->put('dcnews',true,'boolean');
58}
59if (!$core->auth->user_prefs->dashboard->prefExists('quickentry')) {
60     if (!$core->auth->user_prefs->dashboard->prefExists('quickentry',true)) {
61          $core->auth->user_prefs->dashboard->put('quickentry',false,'boolean','',null,true);
62     }
63     $core->auth->user_prefs->dashboard->put('quickentry',false,'boolean');
64}
65
66// Handle folded/unfolded sections in admin from user preferences
67$ws = $core->auth->user_prefs->addWorkspace('toggles');
68if (!$core->auth->user_prefs->toggles->prefExists('unfolded_sections')) {
69     $core->auth->user_prefs->toggles->put('unfolded_sections','','string','Folded sections in admin',null,true);
70}
71
72
73# Dashboard icons
74$__dashboard_icons = new ArrayObject();
75
76$favs = $core->favs->getUserFavorites();
77$core->favs->appendDashboardIcons($__dashboard_icons);
78
79# Check plugins and themes update from repository
80function dc_check_store_update($mod, $url, $img, $icon)
81{
82     $repo = new dcStore($mod, $url);
83     $upd = $repo->get(true);
84     if (!empty($upd)) {
85          $icon[0] .= '<br />'.sprintf(__('An update is available', '%s updates are available.', count($upd)),count($upd));
86          $icon[1] .= '#update';
87          $icon[2] = 'images/menu/'.$img.'-b-update.png';
88     }
89}
90if (isset($__dashboard_icons['plugins'])) {
91     dc_check_store_update($core->plugins, $core->blog->settings->system->store_plugin_url, 'plugins', $__dashboard_icons['plugins']);
92}
93if (isset($__dashboard_icons['blog_theme'])) {
94     $themes = new dcThemes($core);
95     $themes->loadModules($core->blog->themes_path, null);
96     dc_check_store_update($themes, $core->blog->settings->system->store_theme_url, 'blog-theme', $__dashboard_icons['blog_theme']);
97}
98
99# Latest news for dashboard
100$__dashboard_items = new ArrayObject(array(new ArrayObject(),new ArrayObject()));
101
102$dashboardItem = 0;
103
104if ($core->auth->user_prefs->dashboard->dcnews) {
105     try
106     {
107          if (empty($__resources['rss_news'])) {
108               throw new Exception();
109          }
110
111          $feed_reader = new feedReader;
112          $feed_reader->setCacheDir(DC_TPL_CACHE);
113          $feed_reader->setTimeout(2);
114          $feed_reader->setUserAgent('Dotclear - http://www.dotclear.org/');
115          $feed = $feed_reader->parse($__resources['rss_news']);
116          if ($feed)
117          {
118               $latest_news = '<div class="box medium dc-box"><h3>'.__('Dotclear news').'</h3><dl id="news">';
119               $i = 1;
120               foreach ($feed->items as $item)
121               {
122                    $dt = isset($item->link) ? '<a href="'.$item->link.'" class="outgoing" title="'.$item->title.'">'.
123                         $item->title.' <img src="images/outgoing-blue.png" alt="" /></a>' : $item->title;
124
125                    if ($i < 3) {
126                         $latest_news .=
127                         '<dt>'.$dt.'</dt>'.
128                         '<dd><p><strong>'.dt::dt2str(__('%d %B %Y:'),$item->pubdate,'Europe/Paris').'</strong> '.
129                         '<em>'.text::cutString(html::clean($item->content),120).'...</em></p></dd>';
130                    } else {
131                         $latest_news .=
132                         '<dt>'.$dt.'</dt>'.
133                         '<dd>'.dt::dt2str(__('%d %B %Y:'),$item->pubdate,'Europe/Paris').'</dd>';
134                    }
135                    $i++;
136                    if ($i > 2) { break; }
137               }
138               $latest_news .= '</dl></div>';
139               $__dashboard_items[$dashboardItem][] = $latest_news;
140               $dashboardItem++;
141          }
142     }
143     catch (Exception $e) {}
144}
145
146# Documentation links
147if ($core->auth->user_prefs->dashboard->doclinks) {
148     if (!empty($__resources['doc']))
149     {
150          $doc_links = '<div class="box small dc-box"><h3>'.__('Documentation and support').'</h3><ul>';
151
152          foreach ($__resources['doc'] as $k => $v) {
153               $doc_links .= '<li><a class="outgoing" href="'.$v.'" title="'.$k.'">'.$k.
154               ' <img src="images/outgoing-blue.png" alt="" /></a></li>';
155          }
156
157          $doc_links .= '</ul></div>';
158          $__dashboard_items[$dashboardItem][] = $doc_links;
159          $dashboardItem++;
160     }
161}
162
163$core->callBehavior('adminDashboardItems', $core, $__dashboard_items);
164
165# Dashboard content
166$dashboardContents = '';
167$__dashboard_contents = new ArrayObject(array(new ArrayObject,new ArrayObject));
168$core->callBehavior('adminDashboardContents', $core, $__dashboard_contents);
169
170# Editor stuff
171$admin_post_behavior = '';
172if ($core->auth->user_prefs->dashboard->quickentry) {
173     if ($core->auth->check('usage,contentadmin',$core->blog->id))
174     {
175          $post_format = $core->auth->getOption('post_format');
176          $post_editor = $core->auth->getOption('editor');
177          if ($post_editor && !empty($post_editor[$post_format])) {
178               // context is not post because of tags not available
179               $admin_post_behavior = $core->callBehavior('adminPostEditor', $post_editor[$post_format], 'quickentry', array('#post_content'),$post_format);
180          }
181     }
182}
183
184/* DISPLAY
185-------------------------------------------------------- */
186dcPage::open(__('Dashboard'),
187     dcPage::jsLoad('js/_index.js').
188     $admin_post_behavior.
189     # --BEHAVIOR-- adminDashboardHeaders
190     $core->callBehavior('adminDashboardHeaders'),
191     dcPage::breadcrumb(
192          array(
193          __('Dashboard').' : '.html::escapeHTML($core->blog->name) => ''
194          ),
195          array('home_link' =>false)
196     )
197);
198
199# Dotclear updates notifications
200if ($core->auth->isSuperAdmin() && is_readable(DC_DIGESTS))
201{
202     $updater = new dcUpdate(DC_UPDATE_URL,'dotclear',DC_UPDATE_VERSION,DC_TPL_CACHE.'/versions');
203     $new_v = $updater->check(DC_VERSION);
204     $version_info = $new_v ? $updater->getInfoURL() : '';
205
206     if ($updater->getNotify() && $new_v) {
207          echo
208          '<div class="dc-update"><h3>'.sprintf(__('Dotclear %s is available!'),$new_v).'</h3> '.
209          '<p><a class="button submit" href="'.$core->adminurl->get("admin.update").'">'.sprintf(__('Upgrade now'),$new_v).'</a> '.
210          '<a class="button" href="'.$core->adminurl->get("admin.update", array('hide_msg' => 1)).'">'.__('Remind me later').'</a>'.
211          ($version_info ? ' </p>'.
212          '<p class="updt-info"><a href="'.$version_info.'">'.__('Information about this version').'</a>' : '').'</p>'.
213          '</div>';
214     }
215}
216
217if ($core->auth->getInfo('user_default_blog') != $core->blog->id && $core->auth->getBlogCount() > 1) {
218     echo
219     '<p><a href="'.$core->adminurl->get("admin.home",array('default_blog' => 1)).'" class="button">'.__('Make this blog my default blog').'</a></p>';
220}
221
222if ($core->blog->status == 0) {
223     echo '<p class="static-msg">'.__('This blog is offline').'.</p>';
224} elseif ($core->blog->status == -1) {
225     echo '<p class="static-msg">'.__('This blog is removed').'.</p>';
226}
227
228if (!defined('DC_ADMIN_URL') || !DC_ADMIN_URL) {
229     echo
230     '<p class="static-msg">'.
231     sprintf(__('%s is not defined, you should edit your configuration file.'),'DC_ADMIN_URL').
232     ' '.__('See <a href="http://dotclear.org/documentation/2.0/admin/config">documentation</a> for more information.').
233     '</p>';
234}
235
236if (!defined('DC_ADMIN_MAILFROM') || !DC_ADMIN_MAILFROM) {
237     echo
238     '<p class="static-msg">'.
239     sprintf(__('%s is not defined, you should edit your configuration file.'),'DC_ADMIN_MAILFROM').
240     ' '.__('See <a href="http://dotclear.org/documentation/2.0/admin/config">documentation</a> for more information.').
241     '</p>';
242}
243
244$err = array();
245
246# Check cache directory
247if ( $core->auth->isSuperAdmin() ) {
248     if (!is_dir(DC_TPL_CACHE) || !is_writable(DC_TPL_CACHE)) {
249          $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>';
250     }
251} else {
252     if (!is_dir(DC_TPL_CACHE) || !is_writable(DC_TPL_CACHE)) {
253          $err[] = '<p>'.__("The cache directory does not exist or is not writable. You should contact your administrator.").'</p>';
254     }
255}
256
257# Check public directory
258if ( $core->auth->isSuperAdmin() ) {
259     if (!is_dir($core->blog->public_path) || !is_writable($core->blog->public_path)) {
260          $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>';
261     }
262} else {
263     if (!is_dir($core->blog->public_path) || !is_writable($core->blog->public_path)) {
264          $err[] = '<p>'.__("There is no writable root directory for the media manager. You should contact your administrator.").'</p>';
265     }
266}
267
268# Error list
269if (count($err) > 0) {
270     echo '<div class="error"><p><strong>'.__('Error:').'</strong></p>'.
271     '<ul><li>'.implode("</li><li>",$err).'</li></ul></div>';
272}
273
274# Plugins install messages
275if (!empty($plugins_install['success']))
276{
277     echo '<div class="success">'.__('Following plugins have been installed:').'<ul>';
278     foreach ($plugins_install['success'] as $k => $v) {
279          echo '<li>'.$k.'</li>';
280     }
281     echo '</ul></div>';
282}
283if (!empty($plugins_install['failure']))
284{
285     echo '<div class="error">'.__('Following plugins have not been installed:').'<ul>';
286     foreach ($plugins_install['failure'] as $k => $v) {
287          echo '<li>'.$k.' ('.$v.')</li>';
288     }
289     echo '</ul></div>';
290}
291# Errors modules notifications
292if ($core->auth->isSuperAdmin())
293{
294     $list = $core->plugins->getErrors();
295     if (!empty($list)) {
296          echo
297          '<div class="error" id="module-errors" class="error"><p>'.__('Errors have occured with following plugins:').'</p> '.
298          '<ul><li>'.implode("</li>\n<li>", $list).'</li></ul></div>';
299     }
300}
301
302# Dashboard columns (processed first, as we need to know the result before displaying the icons.)
303$dashboardItems = '';
304
305foreach ($__dashboard_items as $i)
306{
307     if ($i->count() > 0)
308     {
309          $dashboardItems .= '';
310          foreach ($i as $v) {
311               $dashboardItems .= $v;
312          }
313          $dashboardItems .= '';
314     }
315}
316
317# Dashboard elements
318echo '<div id="dashboard-main">';
319
320# Dashboard icons
321echo '<div id="icons">';
322foreach ($__dashboard_icons as $i)
323{
324     echo
325     '<p><a href="'.$i[1].'"><img src="'.dc_admin_icon_url($i[2]).'" alt="" />'.
326     '<br /><span>'.$i[0].'</span></a></p>';
327}
328echo '</div>';
329
330if ($core->auth->user_prefs->dashboard->quickentry) {
331     if ($core->auth->check('usage,contentadmin',$core->blog->id))
332     {
333          # Getting categories
334          $categories_combo = dcAdminCombos::getCategoriesCombo(
335               $core->blog->getCategories(array('post_type'=>'post'))
336          );
337
338          echo
339          '<div id="quick">'.
340          '<h3>'.__('Quick entry').sprintf(' &rsaquo; %s',$core->auth->getOption('post_format')).'</h3>'.
341          '<form id="quick-entry" action="'.$core->adminurl->get('admin.post').'" method="post" class="fieldset">'.
342          '<h4>'.__('New entry').'</h4>'.
343          '<p class="col"><label for="post_title" class="required"><abbr title="'.__('Required field').'">*</abbr> '.__('Title:').'</label>'.
344          form::field('post_title',20,255,'','maximal').
345          '</p>'.
346          '<p class="area"><label class="required" '.
347          'for="post_content"><abbr title="'.__('Required field').'">*</abbr> '.__('Content:').'</label> '.
348          form::textarea('post_content',50,10).
349          '</p>'.
350          '<p><label for="cat_id" class="classic">'.__('Category:').'</label> '.
351          form::combo('cat_id',$categories_combo).'</p>'.
352          ($core->auth->check('categories', $core->blog->id)
353               ? '<div>'.
354               '<p id="new_cat" class="q-cat">'.__('Add a new category').'</p>'.
355               '<p class="q-cat"><label for="new_cat_title">'.__('Title:').'</label> '.
356               form::field('new_cat_title',30,255,'','').'</p>'.
357               '<p class="q-cat"><label for="new_cat_parent">'.__('Parent:').'</label> '.
358               form::combo('new_cat_parent',$categories_combo,'','').
359               '</p>'.
360               '<p class="form-note info clear">'.__('This category will be created when you will save your post.').'</p>'.
361               '</div>'
362               : '').
363          '<p><input type="submit" value="'.__('Save').'" name="save" /> '.
364          ($core->auth->check('publish',$core->blog->id)
365               ? '<input type="hidden" value="'.__('Save and publish').'" name="save-publish" />'
366               : '').
367          $core->formNonce().
368          form::hidden('post_status',-2).
369          form::hidden('post_format',$core->auth->getOption('post_format')).
370          form::hidden('post_excerpt','').
371          form::hidden('post_lang',$core->auth->getInfo('user_lang')).
372          form::hidden('post_notes','').
373          '</p>'.
374          '</form>'.
375          '</div>';
376     }
377}
378
379foreach ($__dashboard_contents as $i)
380{
381     if ($i->count() > 0)
382     {
383          $dashboardContents .= '';
384          foreach ($i as $v) {
385               $dashboardContents .= $v;
386          }
387          $dashboardContents .= '';
388     }
389}
390
391if ($dashboardContents != '' || $dashboardItems != '') {
392     echo
393     '<div id="dashboard-boxes">'.
394     '<div class="db-items">'.$dashboardItems.$dashboardContents.'</div>'.
395     '</div>';
396}
397
398echo '</div>'; #end dashboard-main
399dcPage::helpBlock('core_dashboard');
400dcPage::close();
Note: See TracBrowser for help on using the repository browser.

Sites map