Dotclear

source: inc/admin/prepend.php @ 1949:ee535dc74914

Revision 1949:ee535dc74914, 13.4 KB checked in by Denis Jean-Chirstian <contact@…>, 12 years ago (diff)

Send lang code to l10n for plural form at stratégic places

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
13define('DC_CONTEXT_ADMIN',true);
14
15require_once dirname(__FILE__).'/../prepend.php';
16
17// HTTP/1.1
18header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
19header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
20
21// HTTP/1.0
22header("Pragma: no-cache");
23
24function dc_valid_fav($url) {
25     global $core;
26
27     if (preg_match('#plugin\.php\?p=([^&]+)#',$url,$matches)) {
28          if (isset($matches[1])) {
29               if (!$core->plugins->moduleExists($matches[1])) {
30                    return false;
31               }
32          }
33     }
34     return true;
35}
36
37function dc_prepare_url($url) {
38
39     $u = str_replace(array('?','&amp;','/'),array('\?','&','\\/'),$url);
40     return (!strpos($u,'\?') ? 
41          '/'.$u.'$/' :
42          (!strpos($u,'&') ? 
43          '/'.$u.'(\?.*)?$/' :
44          '/'.$u.'(&.*)?$/'));
45}
46
47function dc_load_locales() {
48     global $_lang, $core;
49     
50     $_lang = $core->auth->getInfo('user_lang');
51     $_lang = preg_match('/^[a-z]{2}(-[a-z]{2})?$/',$_lang) ? $_lang : 'en';
52     
53     l10n::lang($_lang);
54     if (l10n::set(dirname(__FILE__).'/../../locales/'.$_lang.'/date') === false && $_lang != 'en') {
55          l10n::set(dirname(__FILE__).'/../../locales/en/date');
56     }
57     l10n::set(dirname(__FILE__).'/../../locales/'.$_lang.'/main');
58     l10n::set(dirname(__FILE__).'/../../locales/'.$_lang.'/public');
59     l10n::set(dirname(__FILE__).'/../../locales/'.$_lang.'/plugins');
60}
61
62function dc_admin_icon_url($img)
63{
64     global $core;
65     
66     $core->auth->user_prefs->addWorkspace('interface');
67     $user_ui_iconset = @$core->auth->user_prefs->interface->iconset;
68     if (($user_ui_iconset) && ($img)) {
69          $icon = false;
70          if ((preg_match('/^images\/menu\/(.+)$/',$img,$m)) || 
71               (preg_match('/^index\.php\?pf=(.+)$/',$img,$m))) {
72               if ($m[1]) {
73                    $icon = path::real(dirname(__FILE__).'/../../admin/images/iconset/'.$user_ui_iconset.'/'.$m[1],false);
74                    if ($icon !== false) {
75                         $allow_types = array('png','jpg','jpeg','gif');
76                         if (is_file($icon) && is_readable($icon) && in_array(files::getExtension($icon),$allow_types)) {
77                              return DC_ADMIN_URL.'images/iconset/'.$user_ui_iconset.'/'.$m[1];
78                         }
79                    }
80               }
81          }
82     }
83     return $img;
84}
85
86if (defined('DC_AUTH_SESS_ID') && defined('DC_AUTH_SESS_UID'))
87{
88     # We have session information in constants
89     $_COOKIE[DC_SESSION_NAME] = DC_AUTH_SESS_ID;
90     
91     if (!$core->auth->checkSession(DC_AUTH_SESS_UID)) {
92          throw new Exception('Invalid session data.');
93     }
94     
95     # Check nonce from POST requests
96     if (!empty($_POST))
97     {
98          if (empty($_POST['xd_check']) || !$core->checkNonce($_POST['xd_check'])) {
99               throw new Exception('Precondition Failed.');
100          }
101     }
102     
103     if (empty($_SESSION['sess_blog_id'])) {
104          throw new Exception('Permission denied.');
105     }
106     
107     # Loading locales
108     dc_load_locales();
109     
110     $core->setBlog($_SESSION['sess_blog_id']);
111     if (!$core->blog->id) {
112          throw new Exception('Permission denied.');
113     }
114}
115elseif ($core->auth->sessionExists())
116{
117     # If we have a session we launch it now
118     try {
119          if (!$core->auth->checkSession())
120          {
121               # Avoid loop caused by old cookie
122               $p = $core->session->getCookieParameters(false,-600);
123               $p[3] = '/';
124               call_user_func_array('setcookie',$p);
125               
126               http::redirect('auth.php');
127          }
128     } catch (Exception $e) {
129          __error(__('Database error')
130               ,__('There seems to be no Session table in your database. Is Dotclear completly installed?')
131               ,20);
132     }
133     
134     # Check nonce from POST requests
135     if (!empty($_POST))
136     {
137          if (empty($_POST['xd_check']) || !$core->checkNonce($_POST['xd_check'])) {
138               http::head(412);
139               header('Content-Type: text/plain');
140               echo 'Precondition Failed';
141               exit;
142          }
143     }
144     
145     
146     if (!empty($_REQUEST['switchblog'])
147     && $core->auth->getPermissions($_REQUEST['switchblog']) !== false)
148     {
149          $_SESSION['sess_blog_id'] = $_REQUEST['switchblog'];
150          if (isset($_SESSION['media_manager_dir'])) {
151               unset($_SESSION['media_manager_dir']);
152          }
153          if (isset($_SESSION['media_manager_page'])) {
154               unset($_SESSION['media_manager_page']);
155          }
156         
157          # Removing switchblog from URL
158          $redir = $_SERVER['REQUEST_URI'];
159          $redir = preg_replace('/switchblog=(.*?)(&|$)/','',$redir);
160          $redir = preg_replace('/\?$/','',$redir);
161          http::redirect($redir);
162          exit;
163     }
164     
165     # Check blog to use and log out if no result
166     if (isset($_SESSION['sess_blog_id']))
167     {
168          if ($core->auth->getPermissions($_SESSION['sess_blog_id']) === false) {
169               unset($_SESSION['sess_blog_id']);
170          }
171     }
172     else
173     {
174          if (($b = $core->auth->findUserBlog($core->auth->getInfo('user_default_blog'))) !== false) {
175               $_SESSION['sess_blog_id'] = $b;
176               unset($b);
177          }
178     }
179     
180     # Loading locales
181     dc_load_locales();
182     
183     if (isset($_SESSION['sess_blog_id'])) {
184          $core->setBlog($_SESSION['sess_blog_id']);
185     } else {
186          $core->session->destroy();
187          http::redirect('auth.php');
188     }
189
190/*   
191     # Check add to my fav fired
192     if (!empty($_REQUEST['add-favorite'])) {
193          $redir = $_SERVER['REQUEST_URI'];
194          # Extract admin page from URI
195          # TO BE COMPLETED
196     }
197*/
198}
199
200if ($core->auth->userID() && $core->blog !== null)
201{
202     # Loading resources and help files
203     $locales_root = dirname(__FILE__).'/../../locales/';
204     require $locales_root.'/en/resources.php';
205     if (($f = l10n::getFilePath($locales_root,'resources.php',$_lang))) {
206          require $f;
207     }
208     unset($f);
209     
210     if (($hfiles = @scandir($locales_root.$_lang.'/help')) !== false)
211     {
212          foreach ($hfiles as $hfile) {
213               if (preg_match('/^(.*)\.html$/',$hfile,$m)) {
214                    $GLOBALS['__resources']['help'][$m[1]] = $locales_root.$_lang.'/help/'.$hfile;
215               }
216          }
217     }
218     unset($hfiles,$locales_root);
219     // Contextual help flag
220     $GLOBALS['__resources']['ctxhelp'] = false;
221
222     $core->auth->user_prefs->addWorkspace('interface');
223     $user_ui_nofavmenu = $core->auth->user_prefs->interface->nofavmenu;
224
225     # Standard favorites
226     $_fav = new ArrayObject();
227
228     # [] : Title, URL, small icon, large icon, permissions, id, class
229     # NB : '*' in permissions means any, null means super admin only
230     
231     $_fav['prefs'] = new ArrayObject(array('prefs','My preferences','preferences.php',
232          'images/menu/user-pref.png','images/menu/user-pref-b.png',
233          '*',null,null));
234
235     $_fav['new_post'] = new ArrayObject(array('new_post','New entry','post.php',
236          'images/menu/edit.png','images/menu/edit-b.png',
237          'usage,contentadmin',null,'menu-new-post'));
238     $_fav['posts'] = new ArrayObject(array('posts','Entries','posts.php',
239          'images/menu/entries.png','images/menu/entries-b.png',
240          'usage,contentadmin',null,null));
241     $_fav['comments'] = new ArrayObject(array('comments','Comments','comments.php',
242          'images/menu/comments.png','images/menu/comments-b.png',
243          'usage,contentadmin',null,null));
244     $_fav['search'] = new ArrayObject(array('search','Search','search.php',
245          'images/menu/search.png','images/menu/search-b.png',
246          'usage,contentadmin',null,null));
247     $_fav['categories'] = new ArrayObject(array('categories','Categories','categories.php',
248          'images/menu/categories.png','images/menu/categories-b.png',
249          'categories',null,null));
250     $_fav['media'] = new ArrayObject(array('media','Media manager','media.php',
251          'images/menu/media.png','images/menu/media-b.png',
252          'media,media_admin',null,null));
253     $_fav['blog_pref'] = new ArrayObject(array('blog_pref','Blog settings','blog_pref.php',
254          'images/menu/blog-pref.png','images/menu/blog-pref-b.png',
255          'admin',null,null));
256     $_fav['blog_theme'] = new ArrayObject(array('blog_theme','Blog appearance','blog_theme.php',
257          'images/menu/themes.png','images/menu/blog-theme-b.png',
258          'admin',null,null));
259
260     $_fav['blogs'] = new ArrayObject(array('blogs','Blogs','blogs.php',
261          'images/menu/blogs.png','images/menu/blogs-b.png',
262          'usage,contentadmin',null,null));
263     $_fav['users'] = new ArrayObject(array('users','Users','users.php',
264          'images/menu/users.png','images/menu/users-b.png',
265          null,null,null));
266     $_fav['plugins'] = new ArrayObject(array('plugins','Plugins management','plugins.php',
267          'images/menu/plugins.png','images/menu/plugins-b.png',
268          null,null,null));
269     $_fav['langs'] = new ArrayObject(array('langs','Languages','langs.php',
270          'images/menu/langs.png','images/menu/langs-b.png',
271          null,null,null));
272
273     $_fav['help'] = new ArrayObject(array('help','Global help','help.php',
274          'images/menu/help.png','images/menu/help-b.png',
275          '*',null,null));
276     
277     # Menus creation
278     $_menu['Dashboard'] = new dcMenu('dashboard-menu',null);
279     if (!$user_ui_nofavmenu)
280          $_menu['Favorites'] = new dcMenu('favorites-menu','My favorites');
281     $_menu['Blog'] = new dcMenu('blog-menu','Blog');
282     $_menu['System'] = new dcMenu('system-menu','System');
283     $_menu['Plugins'] = new dcMenu('plugins-menu','Plugins');
284     
285     # Loading plugins
286     $core->plugins->loadModules(DC_PLUGINS_ROOT,'admin',$_lang);
287
288     # Loading favorites info from plugins
289     $core->callBehavior('adminDashboardFavs', $core, $_fav);
290     
291     # Set menu titles
292     
293     $_menu['System']->title = __('System settings');
294     $_menu['Blog']->title = __('Blog');
295     $_menu['Plugins']->title = __('Plugins');
296     if (!$user_ui_nofavmenu)
297          $_menu['Favorites']->title = __('My favorites');
298
299/*   
300     if (!preg_match('/index.php$/',$_SERVER['REQUEST_URI'])) {
301          # Admin index can't be add in fav's
302          $_menu['Dashboard']->prependItem(__('Add this page to my favorites'),'#','images/menu/add_to_favorites.png',
303               false,$core->auth->check('usage,contentadmin',$core->blog->id),'fav-add');
304     }
305*/
306     $_menu['Blog']->prependItem(__('Blog appearance'),'blog_theme.php','images/menu/themes.png',
307          preg_match('/blog_theme.php(\?.*)?$/',$_SERVER['REQUEST_URI']),
308          $core->auth->check('admin',$core->blog->id));
309     $_menu['Blog']->prependItem(__('Blog settings'),'blog_pref.php','images/menu/blog-pref.png',
310          preg_match('/blog_pref.php(\?.*)?$/',$_SERVER['REQUEST_URI']),
311          $core->auth->check('admin',$core->blog->id));
312     $_menu['Blog']->prependItem(__('Media manager'),'media.php','images/menu/media.png',
313          preg_match('/media(_item)?.php(\?.*)?$/',$_SERVER['REQUEST_URI']),
314          $core->auth->check('media,media_admin',$core->blog->id));
315     $_menu['Blog']->prependItem(__('Categories'),'categories.php','images/menu/categories.png',
316          preg_match('/categories.php(\?.*)?$/',$_SERVER['REQUEST_URI']),
317          $core->auth->check('categories',$core->blog->id));
318     $_menu['Blog']->prependItem(__('Search'),'search.php','images/menu/search.png',
319          preg_match('/search.php(\?.*)?$/',$_SERVER['REQUEST_URI']),
320          $core->auth->check('usage,contentadmin',$core->blog->id));
321     $_menu['Blog']->prependItem(__('Comments'),'comments.php','images/menu/comments.png',
322          preg_match('/comments.php(\?.*)?$/',$_SERVER['REQUEST_URI']),
323          $core->auth->check('usage,contentadmin',$core->blog->id));
324     $_menu['Blog']->prependItem(__('Entries'),'posts.php','images/menu/entries.png',
325          preg_match('/posts.php(\?.*)?$/',$_SERVER['REQUEST_URI']),
326          $core->auth->check('usage,contentadmin',$core->blog->id));
327     $_menu['Blog']->prependItem(__('New entry'),'post.php','images/menu/edit.png',
328          preg_match('/post.php$/',$_SERVER['REQUEST_URI']),
329          $core->auth->check('usage,contentadmin',$core->blog->id),'menu-new-post');
330     
331     $_menu['System']->prependItem(__('Update'),'update.php','images/menu/update.png',
332          preg_match('/update.php(\?.*)?$/',$_SERVER['REQUEST_URI']),
333          $core->auth->isSuperAdmin() && is_readable(DC_DIGESTS));
334     $_menu['System']->prependItem(__('Languages'),'langs.php','images/menu/langs.png',
335          preg_match('/langs.php(\?.*)?$/',$_SERVER['REQUEST_URI']),
336          $core->auth->isSuperAdmin());
337     $_menu['System']->prependItem(__('Plugins management'),'plugins.php','images/menu/plugins.png',
338          preg_match('/plugins.php(\?.*)?$/',$_SERVER['REQUEST_URI']),
339          $core->auth->isSuperAdmin());
340     $_menu['System']->prependItem(__('Users'),'users.php','images/menu/users.png',
341          preg_match('/users.php$/',$_SERVER['REQUEST_URI']),
342          $core->auth->isSuperAdmin());
343     $_menu['System']->prependItem(__('Blogs'),'blogs.php','images/menu/blogs.png',
344          preg_match('/blogs.php$/',$_SERVER['REQUEST_URI']),
345          $core->auth->isSuperAdmin() ||
346          $core->auth->check('usage,contentadmin',$core->blog->id) && $core->auth->blog_count > 1);
347
348     if (!$user_ui_nofavmenu) {
349          // Set favorites menu
350          $ws = $core->auth->user_prefs->addWorkspace('favorites');
351          $count = 0;
352          foreach ($ws->dumpPrefs() as $k => $v) {
353               // User favorites only
354               if (!$v['global']) {
355                    $fav = unserialize($v['value']);
356                    if (dc_valid_fav($fav['url'])) {
357                         $count++;
358                         $_menu['Favorites']->addItem(__($fav['title']),$fav['url'],$fav['small-icon'],
359                              preg_match(dc_prepare_url($fav['url']),$_SERVER['REQUEST_URI']),
360                              (($fav['permissions'] == '*') || $core->auth->check($fav['permissions'],$core->blog->id)),$fav['id'],$fav['class']);
361                    }
362               }
363          }   
364          if (!$count) {
365               // Global favorites if any
366               foreach ($ws->dumpPrefs() as $k => $v) {
367                    $fav = unserialize($v['value']);
368                    if (dc_valid_fav($fav['url'])) {
369                         $count++;
370                         $_menu['Favorites']->addItem(__($fav['title']),$fav['url'],$fav['small-icon'],
371                              preg_match(dc_prepare_url($fav['url']),$_SERVER['REQUEST_URI']),
372                              (($fav['permissions'] == '*') || $core->auth->check($fav['permissions'],$core->blog->id)),$fav['id'],$fav['class']);
373                    }
374               }
375          }
376          if (!$count) {
377               // No user or global favorites, add "new entry" fav
378               $_menu['Favorites']->addItem(__('New entry'),'post.php','images/menu/edit.png',
379                    preg_match('/post.php$/',$_SERVER['REQUEST_URI']),
380                    $core->auth->check('usage,contentadmin',$core->blog->id),'menu-new-post',null);
381          }
382     }
383     
384     if (empty($core->blog->settings->system->jquery_migrate_mute)) {
385          $core->blog->settings->system->put('jquery_migrate_mute', true, 'boolean', 'Mute warnings for jquery migrate plugin ?', false);
386     }
387}
388?>
Note: See TracBrowser for help on using the repository browser.

Sites map