Dotclear

source: admin/index.php @ 2911:5434e75ad738

Revision 2911:5434e75ad738, 9.8 KB checked in by Dsls, 11 years ago (diff)

Merge with default

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}
17if (!empty($_GET['tf'])) {
18     define('DC_CONTEXT_ADMIN',true);
19     require dirname(__FILE__).'/../inc/load_theme_file.php';
20     exit;
21}
22
23require dirname(__FILE__).'/../inc/admin/prepend.php';
24
25if (!empty($_GET['default_blog'])) {
26     try {
27          $core->setUserDefaultBlog($core->auth->userID(),$core->blog->id);
28          http::redirect('index.php');
29     } catch (Exception $e) {
30          $core->error->add($e->getMessage());
31     }
32}
33
34dcPage::check('usage,contentadmin');
35
36# Logout
37if (!empty($_GET['logout'])) {
38     $core->session->destroy();
39     if (isset($_COOKIE['dc_admin'])) {
40          unset($_COOKIE['dc_admin']);
41          setcookie('dc_admin',false,-600,'','',DC_ADMIN_SSL);
42     }
43     http::redirect('auth.php');
44     exit;
45}
46
47# Plugin install
48$plugins_install = $core->plugins->installModules();
49
50# Send plugins install messages to templates
51if (!empty($plugins_install['success'])) {
52     $_ctx->addMessagesList(__('Following plugins have been installed:'),$plugins_install['success']);
53}
54if (!empty($plugins_install['failure'])) {
55     $_ctx->addMessagesList(__('Following plugins have not been installed:'),$plugins_install['failure']);
56}
57
58# Send plugins errors messages to templates
59$_ctx->modules_errors = $core->auth->isSuperAdmin() ? $core->plugins->getErrors() : array();
60
61# Send Dotclear updates notifications to tempaltes
62$_ctx->updater = array();
63if ($core->auth->isSuperAdmin() && is_readable(DC_DIGESTS)) {
64
65     $updater = new dcUpdate(DC_UPDATE_URL,'dotclear',DC_UPDATE_VERSION,DC_TPL_CACHE.'/versions');
66     $new_v = $updater->check(DC_VERSION);
67     $version_info = $new_v ? $updater->getInfoURL() : '';
68
69     if ($updater->getNotify() && $new_v) {
70          $_ctx->updater = array(
71               'new_version'  => $new_v,
72               'version_info' => $version_info
73          );
74     }
75}
76
77# Check dashboard module prefs
78$ws = $core->auth->user_prefs->addWorkspace('dashboard');
79
80# Doclinks prefs
81if (!$core->auth->user_prefs->dashboard->prefExists('doclinks')) {
82     if (!$core->auth->user_prefs->dashboard->prefExists('doclinks',true)) {
83          $core->auth->user_prefs->dashboard->put('doclinks',true,'boolean','',null,true);
84     }
85     $core->auth->user_prefs->dashboard->put('doclinks',true,'boolean');
86}
87
88# Send doclinks to templates
89$_ctx->dashboard_doclinks = array();
90if ($core->auth->user_prefs->dashboard->doclinks && !empty($__resources['doc'])) {
91     $_ctx->dashboard_doclinks = $__resources['doc'];
92}
93
94# Dcnews prefs
95if (!$core->auth->user_prefs->dashboard->prefExists('dcnews')) {
96     if (!$core->auth->user_prefs->dashboard->prefExists('dcnews',true)) {
97          $core->auth->user_prefs->dashboard->put('dcnews',true,'boolean','',null,true);
98     }
99     $core->auth->user_prefs->dashboard->put('dcnews',true,'boolean');
100}
101
102# Send dcnews to templates
103$_ctx->dashboard_dcnews = array();
104if ($core->auth->user_prefs->dashboard->dcnews && !empty($__resources['rss_news'])) {
105     try
106     {
107          $feed_reader = new feedReader;
108          $feed_reader->setCacheDir(DC_TPL_CACHE);
109          $feed_reader->setTimeout(2);
110          $feed_reader->setUserAgent('Dotclear - http://www.dotclear.org/');
111          $feed = $feed_reader->parse($__resources['rss_news']);
112          if ($feed) {
113               $items = array();
114               $i = 1;
115               foreach ($feed->items as $item) {
116                    $items[] = array(
117                         'title' => $item->title,
118                         'link' => isset($item->link) ? $item->link : '',
119                         'date' => dt::dt2str(__('%d %B %Y'),$item->pubdate,'Europe/Paris'),
120                         'content' => html::clean($item->content)
121                    );
122                    $i++;
123                    if ($i > 3) { break; }
124               }
125               $_ctx->dashboard_dcnews = $items;
126          }
127     }
128     catch (Exception $e) {}
129}
130
131# Quick entry prefs
132if (!$core->auth->user_prefs->dashboard->prefExists('quickentry')) {
133     if (!$core->auth->user_prefs->dashboard->prefExists('quickentry',true)) {
134          $core->auth->user_prefs->dashboard->put('quickentry',true,'boolean','',null,true);
135     }
136     $core->auth->user_prefs->dashboard->put('quickentry',true,'boolean');
137}
138
139# Send quick entry to templates
140$_ctx->dashboard_quickentry = false;
141if ($core->auth->user_prefs->dashboard->quickentry &&$core->auth->check('usage,contentadmin',$core->blog->id))
142{
143     $categories_combo = array('&nbsp;' => '');
144     try {
145          $categories = $core->blog->getCategories(array('post_type'=>'post'));
146          while ($categories->fetch()) {
147               $categories_combo[$categories->cat_id] =
148                    str_repeat('&nbsp;&nbsp;',$categories->level-1).
149                    ($categories->level-1 == 0 ? '' : '&bull; ').
150                    html::escapeHTML($categories->cat_title);
151          }
152     } catch (Exception $e) { }
153
154     $form = new dcForm($core,array('quickentry','quick-entry'),'post.php');
155     $form
156          ->addField(
157               new dcFieldText('post_title','', array(
158                    'size'         => 20,
159                    'required'     => true,
160                    'label'        => __('Title'))))
161          ->addField(
162               new dcFieldTextArea('post_content','', array(
163                    'required'     => true,
164                    'label'        => __("Content:"))))
165          ->addField(
166               new dcFieldCombo('cat_id','',$categories_combo,array(
167                    "label" => __('Category:'))))
168          ->addField(
169               new dcFieldSubmit('save',__('Save'),array(
170                    'action' => 'savePost')))
171          ->addField(
172               new dcFieldHidden ('post_status',-2))
173          ->addField(
174               new dcFieldHidden ('post_format',$core->auth->getOption('post_format')))
175          ->addField(
176               new dcFieldHidden ('post_excerpt',''))
177          ->addField(
178               new dcFieldHidden ('post_lang',$core->auth->getInfo('user_lang')))
179          ->addField(
180               new dcFieldHidden ('post_notes',''))
181     ;
182     if ($core->auth->check('publish',$core->blog->id)) {
183          $form->addField(
184               new dcFieldHidden ('save-publish',__('Save and publish')));
185     }
186
187     $_ctx->dashboard_quickentry = true;
188}
189
190# Dashboard icons
191$__dashboard_icons = new ArrayObject();
192
193$favs = $core->favs->getUserFavorites();
194$core->favs->appendDashboardIcons($__dashboard_icons);
195
196
197# Check plugins and themes update from repository
198function dc_check_store_update($mod, $url, $img, $icon)
199{
200     $repo = new dcStore($mod, $url);
201     $upd = $repo->get(true);
202     if (!empty($upd)) {
203          $icon[0] .= '<br />'.sprintf(__('An update is available', '%s updates are available.', count($upd)),count($upd));
204          $icon[1] .= '#update';
205          $icon[2] = 'images/menu/'.$img.'-b-update.png';
206     }
207}
208if (isset($__dashboard_icons['plugins'])) {
209     dc_check_store_update($core->plugins, $core->blog->settings->system->store_plugin_url, 'plugins', $__dashboard_icons['plugins']);
210}
211if (isset($__dashboard_icons['blog_theme'])) {
212     $themes = new dcThemes($core);
213     $themes->loadModules($core->blog->themes_path, null);
214     dc_check_store_update($themes, $core->blog->settings->system->store_theme_url, 'blog-theme', $__dashboard_icons['blog_theme']);
215}
216
217# Latest news for dashboard
218$__dashboard_items = new ArrayObject(array(new ArrayObject(),new ArrayObject()));
219
220$dashboardItem = 0;
221
222
223if ($core->auth->user_prefs->dashboard->dcnews) {
224     try
225     {
226          if (empty($__resources['rss_news'])) {
227               throw new Exception();
228          }
229
230          $feed_reader = new feedReader;
231          $feed_reader->setCacheDir(DC_TPL_CACHE);
232          $feed_reader->setTimeout(2);
233          $feed_reader->setUserAgent('Dotclear - http://www.dotclear.org/');
234          $feed = $feed_reader->parse($__resources['rss_news']);
235          if ($feed)
236          {
237               $latest_news = '<div class="box medium dc-box"><h3>'.__('Dotclear news').'</h3><dl id="news">';
238               $i = 1;
239               foreach ($feed->items as $item)
240               {
241                    $dt = isset($item->link) ? '<a href="'.$item->link.'" class="outgoing" title="'.$item->title.'">'.
242                         $item->title.' <img src="images/outgoing-blue.png" alt="" /></a>' : $item->title;
243
244                    if ($i < 3) {
245                         $latest_news .=
246                         '<dt>'.$dt.'</dt>'.
247                         '<dd><p><strong>'.dt::dt2str(__('%d %B %Y:'),$item->pubdate,'Europe/Paris').'</strong> '.
248                         '<em>'.text::cutString(html::clean($item->content),120).'...</em></p></dd>';
249                    } else {
250                         $latest_news .=
251                         '<dt>'.$dt.'</dt>'.
252                         '<dd>'.dt::dt2str(__('%d %B %Y:'),$item->pubdate,'Europe/Paris').'</dd>';
253                    }
254                    $i++;
255                    if ($i > 2) { break; }
256               }
257               $latest_news .= '</dl></div>';
258               $__dashboard_items[$dashboardItem][] = $latest_news;
259               $dashboardItem++;
260          }
261     }
262     catch (Exception $e) {}
263}
264
265# Documentation links
266if ($core->auth->user_prefs->dashboard->doclinks) {
267     if (!empty($__resources['doc']))
268     {
269          $doc_links = '<div class="box small dc-box"><h3>'.__('Documentation and support').'</h3><ul>';
270
271          foreach ($__resources['doc'] as $k => $v) {
272               $doc_links .= '<li><a class="outgoing" href="'.$v.'" title="'.$k.'">'.$k.
273               ' <img src="images/outgoing-blue.png" alt="" /></a></li>';
274          }
275
276          $doc_links .= '</ul></div>';
277          $__dashboard_items[$dashboardItem][] = $doc_links;
278          $dashboardItem++;
279     }
280}
281
282$core->callBehavior('adminDashboardItems', $core, $__dashboard_items);
283
284# Dashboard content
285$dashboardContents = '';
286$__dashboard_contents = new ArrayObject(array(new ArrayObject,new ArrayObject));
287$core->callBehavior('adminDashboardContents', $core, $__dashboard_contents);
288
289# Blog status message
290if ($core->blog->status == 0) {
291     $_ctx->addMessageStatic(__('This blog is offline'));
292} elseif ($core->blog->status == -1) {
293     $_ctx->addMessageStatic(__('This blog is removed'));
294}
295
296# Config errors messages
297if (!defined('DC_ADMIN_URL') || !DC_ADMIN_URL) {
298     $_ctx->addMessageStatic(
299          sprintf(__('%s is not defined, you should edit your configuration file.'),'DC_ADMIN_URL').' '.
300          __('See <a href="http://dotclear.org/documentation/2.0/admin/config">documentation</a> for more information.')
301     );
302}
303if (!defined('DC_ADMIN_MAILFROM') || !DC_ADMIN_MAILFROM) {
304     $_ctx->addMessageStatic(
305          sprintf(__('%s is not defined, you should edit your configuration file.'),'DC_ADMIN_MAILFROM').' '.
306          __('See <a href="http://dotclear.org/documentation/2.0/admin/config">documentation</a> for more information.')
307     );
308}
309$_ctx->dashboard_icons = $__dashboard_icons;
310//print_r($__dashboard_icons);exit;
311$_ctx->setBreadCrumb(__('Dashboard').' : '.html::escapeHTML($core->blog->name), false);
312$core->tpl->display('index.html.twig');
313?>
Note: See TracBrowser for help on using the repository browser.

Sites map