Dotclear

source: admin/index.php @ 1492:a7112dcc916c

Revision 1492:a7112dcc916c, 9.8 KB checked in by Dsls, 12 years ago (diff)

Fusion avec default

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2011 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# Dashboard favorites
194$post_count = $core->blog->getPosts(array(),true)->f(0);
195$str_entries = ($post_count > 1) ? __('%d entries') : __('%d entry');
196
197$comment_count = $core->blog->getComments(array(),true)->f(0);
198$str_comments = ($comment_count > 1) ? __('%d comments') : __('%d comment');
199
200$ws = $core->auth->user_prefs->addWorkspace('favorites');
201$count = 0;
202foreach ($ws->dumpPrefs() as $k => $v) {
203     // User favorites only
204     if (!$v['global']) {
205          $fav = unserialize($v['value']);
206          if (($fav['permissions'] == '*') || $core->auth->check($fav['permissions'],$core->blog->id)) {
207               if (dc_valid_fav($fav['url'])) {
208                    $count++;
209                    $title = ($fav['name'] == 'posts' ? sprintf($str_entries,$post_count) : 
210                         ($fav['name'] == 'comments' ? sprintf($str_comments,$comment_count) : $fav['title']));
211                    $__dashboard_icons[$fav['name']] = new ArrayObject(array(__($title),$fav['url'],$fav['large-icon']));
212
213                    # Let plugins set their own title for favorite on dashboard
214                    $core->callBehavior('adminDashboardFavsIcon',$core,$fav['name'],$__dashboard_icons[$fav['name']]);
215               }
216          }
217     }
218}   
219if (!$count) {
220     // Global favorites if any
221     foreach ($ws->dumpPrefs() as $k => $v) {
222          $fav = unserialize($v['value']);
223          if (($fav['permissions'] == '*') || $core->auth->check($fav['permissions'],$core->blog->id)) {
224               if (dc_valid_fav($fav['url'])) {
225                    $count++;
226                    $title = ($fav['name'] == 'posts' ? sprintf($str_entries,$post_count) : 
227                         ($fav['name'] == 'comments' ? sprintf($str_comments,$comment_count) : $fav['title']));
228                    $__dashboard_icons[$fav['name']] = new ArrayObject(array(__($title),$fav['url'],$fav['large-icon']));
229
230                    # Let plugins set their own title for favorite on dashboard
231                    $core->callBehavior('adminDashboardFavsIcon',$core,$fav['name'],$__dashboard_icons[$fav['name']]);
232               }
233          }
234     }
235}
236if (!$count) {
237     // No user or global favorites, add "user pref" and "new entry" fav
238     if ($core->auth->check('usage,contentadmin',$core->blog->id)) {
239          $__dashboard_icons['new_post'] = new ArrayObject(array(__('New entry'),'post.php','images/menu/edit-b.png'));
240     }
241     $__dashboard_icons['prefs'] = new ArrayObject(array(__('My preferences'),'preferences.php','images/menu/user-pref-b.png'));
242}
243
244# Send dashboard icons to templates
245$icons = array();
246foreach ($__dashboard_icons as $i) {
247     $icons[] = array(
248          'title'   => $i[0],
249          'url'     => $i[1],
250          'img'     => dc_admin_icon_url($i[2])
251     );
252}
253$_ctx->dashboard_icons = $icons;
254
255# Dashboard items
256$__dashboard_items = new ArrayObject(array(new ArrayObject,new ArrayObject));
257$core->callBehavior('adminDashboardItems', $core, $__dashboard_items);
258
259# Send dashboard items to templates
260$items = array();
261foreach ($__dashboard_items as $i) {   
262     if ($i->count() > 0) {
263          foreach ($i as $v) {
264               $items[] = $v;
265          }
266     }
267}
268$_ctx->dashboard_items = $items;
269
270# Dashboard content
271$__dashboard_contents = new ArrayObject(array(new ArrayObject,new ArrayObject));
272$core->callBehavior('adminDashboardContents', $core, $__dashboard_contents);
273
274# Send dashboard contents to templates
275$contents = array();
276foreach ($__dashboard_contents as $i) { 
277     if ($i->count() > 0) {
278          foreach ($i as $v) {
279               $contents[] = $v;
280          }
281     }
282}
283$_ctx->dashboard_contents = $contents;
284
285# Blog status message
286if ($core->blog->status == 0) {
287     $_ctx->addMessageStatic(__('This blog is offline'));
288} elseif ($core->blog->status == -1) {
289     $_ctx->addMessageStatic(__('This blog is removed'));
290}
291
292# Config errors messages
293if (!defined('DC_ADMIN_URL') || !DC_ADMIN_URL) {
294     $_ctx->addMessageStatic(
295          sprintf(__('%s is not defined, you should edit your configuration file.'),'DC_ADMIN_URL').' '.
296          __('See <a href="http://dotclear.org/documentation/2.0/admin/config">documentation</a> for more information.')
297     );
298}
299if (!defined('DC_ADMIN_MAILFROM') || !DC_ADMIN_MAILFROM) {
300     $_ctx->addMessageStatic(
301          sprintf(__('%s is not defined, you should edit your configuration file.'),'DC_ADMIN_MAILFROM').' '.
302          __('See <a href="http://dotclear.org/documentation/2.0/admin/config">documentation</a> for more information.')
303     );
304}
305
306$_ctx->setBreadCrumb(__('Dashboard').' : '.html::escapeHTML($core->blog->name), false);
307$core->tpl->display('index.html.twig');
308?>
Note: See TracBrowser for help on using the repository browser.

Sites map