Dotclear

source: admin/blog_theme.php @ 2189:eda746478da6

Revision 2189:eda746478da6, 11.7 KB checked in by Dsls, 12 years ago (diff)
  • Removed superfluous space in addNotice
  • Non-repeatable notifications, step 2 : blogs and categories
  • Fixed blogs breadcrumb

see #1710

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
13require dirname(__FILE__).'/../inc/admin/prepend.php';
14
15dcPage::check('admin');
16
17# Loading themes
18$core->themes = new dcThemes($core);
19$core->themes->loadModules($core->blog->themes_path,null);
20
21# Theme screenshot
22if (!empty($_GET['shot']) && $core->themes->moduleExists($_GET['shot']))
23{
24     if (empty($_GET['src'])) {
25          $f = $core->blog->themes_path.'/'.$_GET['shot'].'/screenshot.jpg';
26     } else {
27          $f = $core->blog->themes_path.'/'.$_GET['shot'].'/'.path::clean($_GET['src']);
28     }
29     
30     $f = path::real($f);
31     
32     if (!file_exists($f)) {
33          $f = dirname(__FILE__).'/images/noscreenshot.png';
34     }
35     
36     http::cache(array_merge(array($f),get_included_files()));
37     
38     header('Content-Type: '.files::getMimeType($f));
39     header('Content-Length: '.filesize($f));
40     readfile($f);
41     
42     exit;
43}
44
45$can_install = $core->auth->isSuperAdmin();
46$is_writable = is_dir($core->blog->themes_path) && is_writable($core->blog->themes_path);
47$default_tab = 'themes-list';
48
49# Selecting theme
50if (!empty($_POST['theme']) && !empty($_POST['select']) && empty($_REQUEST['conf']))
51{
52     $core->blog->settings->addNamespace('system');
53     $core->blog->settings->system->put('theme',$_POST['theme']);
54     $core->blog->triggerBlog();
55     $theme = $core->themes->getModules($_POST['theme']);
56     dcPage::addSuccessNotice(sprintf(
57          __('Current theme has been successfully changed to "%s".'),
58          __('Current theme has been successfully changed to "%s".'),
59          html::escapeHTML($theme['name']))
60     );
61
62     http::redirect('blog_theme.php');
63}
64
65if ($can_install && !empty($_POST['theme']) && !empty($_POST['remove']) && empty($_REQUEST['conf']))
66{
67     try
68     {
69          if ($_POST['theme'] == 'default') {
70               throw new Exception(__('You can\'t remove default theme.'));
71          }
72         
73          if (!$core->themes->moduleExists($_POST['theme'])) {
74               throw new Exception(__('Theme does not exist.'));
75          }
76         
77          $theme = $core->themes->getModules($_POST['theme']);
78         
79          # --BEHAVIOR-- themeBeforeDelete
80          $core->callBehavior('themeBeforeDelete',$theme);
81         
82          $core->themes->deleteModule($_POST['theme']);
83         
84          # --BEHAVIOR-- themeAfterDelete
85          $core->callBehavior('themeAfterDelete',$theme);
86         
87          http::redirect('blog_theme.php');
88     }
89     catch (Exception $e)
90     {
91          $core->error->add($e->getMessage());
92     }
93}
94
95# Theme upload
96if ($can_install && $is_writable && ((!empty($_POST['upload_pkg']) && !empty($_FILES['pkg_file'])) ||
97     (!empty($_POST['fetch_pkg']) && !empty($_POST['pkg_url']))))
98{
99     try
100     {
101          if (empty($_POST['your_pwd']) || !$core->auth->checkPassword(crypt::hmac(DC_MASTER_KEY,$_POST['your_pwd']))) {
102               throw new Exception(__('Password verification failed'));
103          }
104         
105          if (!empty($_POST['upload_pkg']))
106          {
107               files::uploadStatus($_FILES['pkg_file']);
108               
109               $dest = $core->blog->themes_path.'/'.$_FILES['pkg_file']['name'];
110               if (!move_uploaded_file($_FILES['pkg_file']['tmp_name'],$dest)) {
111                    throw new Exception(__('Unable to move uploaded file.'));
112               }
113          }
114          else
115          {
116               $url = urldecode($_POST['pkg_url']);
117               $dest = $core->blog->themes_path.'/'.basename($url);
118               
119               try
120               {
121                    $client = netHttp::initClient($url,$path);
122                    $client->setUserAgent('Dotclear - http://www.dotclear.org/');
123                    $client->useGzip(false);
124                    $client->setPersistReferers(false);
125                    $client->setOutput($dest);
126                    $client->get($path);
127               }
128               catch( Exception $e)
129               {
130                    throw new Exception(__('An error occurred while downloading the file.'));
131               }
132               
133               unset($client);
134          }
135         
136          $ret_code = dcModules::installPackage($dest,$core->themes);
137          if ($ret_code == 2) {
138               dcPage::addSuccessNotice(__('Theme has been successfully upgraded.'));
139          } else {
140               dcPage::addSuccessNotice(__('Theme has been successfully installed.'));
141          }
142          http::redirect('blog_theme.php');
143     }
144     catch (Exception $e)
145     {
146          $core->error->add($e->getMessage());
147          $default_tab = 'add-theme';
148     }
149}
150
151$theme_conf_mode = false;
152if (!empty($_REQUEST['conf']))
153{
154     $theme_conf_file = path::real($core->blog->themes_path.'/'.$core->blog->settings->system->theme).'/_config.php';
155     if (file_exists($theme_conf_file)) {
156          $theme_conf_mode = true;
157     }
158}
159
160function display_theme_details($id,$details,$current)
161{
162     global $core;
163     
164     $screenshot = 'images/noscreenshot.png';
165     if (file_exists($core->blog->themes_path.'/'.$id.'/screenshot.jpg')) {
166          $screenshot = 'blog_theme.php?shot='.rawurlencode($id);
167     }
168     
169     $radio_id = 'theme_'.html::escapeHTML($id);
170     if (preg_match('#^http(s)?://#',$core->blog->settings->system->themes_url)) {
171          $theme_url = http::concatURL($core->blog->settings->system->themes_url,'/'.$id);
172     } else {
173          $theme_url = http::concatURL($core->blog->url,$core->blog->settings->system->themes_url.'/'.$id);
174     }
175     $has_conf = file_exists(path::real($core->blog->themes_path.'/'.$id).'/_config.php');
176     $has_css = file_exists(path::real($core->blog->themes_path.'/'.$id).'/style.css');
177     $parent = $core->themes->moduleInfo($id,'parent');
178     $has_parent = (boolean)$parent;
179     if ($has_parent) {
180          $is_parent_present = $core->themes->moduleExists($parent);
181     }
182     
183     $res =
184     '<div class="theme-details'.($current ? ' current-theme' : '').'">'.
185     '<div class="theme-shot"><img src="'.$screenshot.'" alt="" /></div>'.
186     '<div class="theme-info">'.
187          '<h4>'.form::radio(array('theme',$radio_id),html::escapeHTML($id),$current,'','',($has_parent && !$is_parent_present)).' '.
188          '<label class="classic" for="'.$radio_id.'">'.
189          html::escapeHTML($details['name']).'</label></h4>'.
190          '<p><span class="theme-desc">'.html::escapeHTML($details['desc']).'</span> '.
191          '<span class="theme-author">'.sprintf(__('by %s'),html::escapeHTML($details['author'])).'</span> '.
192          '<span class="theme-version">'.sprintf(__('version %s'),html::escapeHTML($details['version'])).'</span> ';
193          if ($has_parent) {
194               if ($is_parent_present) {
195                    $res .= '<span class="theme-parent-ok">'.sprintf(__('(built on "%s")'),html::escapeHTML($parent)).'</span> ';
196               } else {
197                    $res .= '<span class="theme-parent-missing">'.sprintf(__('(requires "%s")'),html::escapeHTML($parent)).'</span> ';
198               }
199          }
200          if ($has_css) {
201               $res .= '<span class="theme-css"><a href="'.$theme_url.'/style.css">'.__('Stylesheet').'</a></span>';
202          }
203          $res .= '</p>';
204     $res .=
205     '</div>'.
206     '<div class="theme-actions">';
207          if ($current && $has_conf) {
208               $res .= '<p><a href="blog_theme.php?conf=1" class="button">'.__('Configure theme').'</a></p>';
209          }
210          if ($current) {
211               # --BEHAVIOR-- adminCurrentThemeDetails
212               $res .= $core->callBehavior('adminCurrentThemeDetails',$core,$id,$details);
213          }
214     $res .=
215     '</div>'.
216     '</div>';
217     
218     return $res;
219}
220
221if (!$theme_conf_mode)
222{
223     $breadcrumb = dcPage::breadcrumb(
224          array(
225               html::escapeHTML($core->blog->name) => '',
226               __('Blog appearance') => ''
227          ));
228} else {
229     $breadcrumb = dcPage::breadcrumb(
230          array(
231               html::escapeHTML($core->blog->name) => '',
232               __('Blog appearance') => 'blog_theme.php',
233               __('Theme configuration') => ''
234          ));
235}
236
237dcPage::open(__('Blog appearance'),
238     (!$theme_conf_mode ? dcPage::jsLoad('js/_blog_theme.js') : '').
239     dcPage::jsPageTabs($default_tab).
240     dcPage::jsColorPicker(),
241     $breadcrumb
242);
243
244if (!$theme_conf_mode)
245{
246     if (!empty($_GET['upd'])) {
247          dcPage::success(__('Theme has been successfully changed.'));
248     }
249     
250     if (!empty($_GET['added'])) {
251          dcPage::success(($_GET['added'] == 2 ? __('Theme has been successfully upgraded') : __('Theme has been successfully installed.')));
252     }
253     
254     if (!empty($_GET['del'])) {
255          dcPage::success(__('Theme has been successfully deleted.'));
256     }
257     
258     # Themes list
259     echo '<div class="multi-part" id="themes-list" title="'.__('Themes').'">'.
260     '<h3>'.__('Available themes in your installation').'</h3>';
261     
262     $themes = $core->themes->getModules();
263     if (isset($themes[$core->blog->settings->system->theme])) {
264          echo '<p>'.sprintf(__('You are currently using <strong>%s</strong>'),$themes[$core->blog->settings->system->theme]['name']).'.</p>';
265     }
266     
267     echo
268     '<form action="blog_theme.php" method="post" id="themes-form">'.
269     '<div id="themes">';
270     
271     if (isset($themes[$core->blog->settings->system->theme])) {
272          echo display_theme_details($core->blog->settings->system->theme,$themes[$core->blog->settings->system->theme],true);
273     }
274     
275     foreach ($themes as $k => $v)
276     {
277          if ($core->blog->settings->system->theme == $k) { // Current theme
278               continue;
279          }
280          echo display_theme_details($k,$v,false);
281     }
282     
283     echo '</div>';
284     
285     echo
286     '<div id="themes-actions">'.
287     
288     '<p>'.$core->formNonce().'<input type="submit" name="select" value="'.__('Use selected theme').'" /> '; 
289     if ($can_install) {
290          echo ' <input type="submit" class="delete" name="remove" value="'.__('Delete selected theme').'" />';
291     }
292     echo '</p>'.
293     
294     '</div>'.
295     '</form>'.
296     '</div>';
297     
298     # Add a new theme
299     if ($can_install)
300     {
301          echo
302          '<div class="multi-part clear" id="add-theme" title="'.__('Install or upgrade a theme').'">'.
303          '<h3>'.__('Add themes to your installation').'</h3>'.
304          '<p class="form-note info">'.sprintf(__('You can find additional themes for your blog on %s.'),
305          '<a href="http://themes.dotaddict.org/galerie-dc2/">Dotaddict</a>').'</p>';
306         
307          if ($is_writable)
308          {
309               echo '<p>'.__('You can also install themes by uploading or downloading zip files.').'</p>';
310               
311               # 'Upload theme' form
312               echo
313               '<form method="post" action="blog_theme.php" id="uploadpkg" enctype="multipart/form-data" class="fieldset">'.
314               '<h4>'.__('Upload a zip file').'</h4>'.
315               '<p class="field"><label for="pkg_file" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Theme zip file:').'</label> '.
316               '<input type="file" name="pkg_file" id="pkg_file" /></p>'.
317               '<p class="field"><label for="your_pwd1" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Your password:').'</label> '.
318               form::password(array('your_pwd','your_pwd1'),20,255).'</p>'.
319               '<p><input type="submit" name="upload_pkg" value="'.__('Upload theme').'" />'.
320               $core->formNonce().'</p>'.
321               '</form>';
322               
323               # 'Fetch theme' form
324               echo
325               '<form method="post" action="blog_theme.php" id="fetchpkg" class="fieldset">'.
326               '<h4>'.__('Download a zip file').'</h4>'.
327               '<p class="field"><label for="pkg_url" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Theme zip file URL:').'</label> '.
328               form::field(array('pkg_url','pkg_url'),40,255).'</p>'.
329               '<p class="field"><label for="your_pwd2" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Your password:').'</label> '.
330               form::password(array('your_pwd','your_pwd2'),20,255).'</p>'.
331               '<p><input type="submit" name="fetch_pkg" value="'.__('Download theme').'" />'.
332               $core->formNonce().'</p>'.
333               '</form>';
334          }
335          else
336          {
337               echo
338               '<p class="static-msg">'.
339               __('To enable this function, please give write access to your themes directory.').
340               '</p>';
341          }
342          echo '</div>';
343     }
344}
345else
346{
347     $theme_name = $core->themes->moduleInfo($core->blog->settings->system->theme,'name');
348     $core->themes->loadModuleL10Nresources($core->blog->settings->system->theme,$_lang);
349
350     echo
351     '<p><a class="back" href="blog_theme.php">'.__('Back to Blog appearance').'</a></p>';
352     
353     try
354     {
355          # Let theme configuration set their own form(s) if required
356          $standalone_config = (boolean) $core->themes->moduleInfo($core->blog->settings->system->theme,'standalone_config');
357
358          if (!$standalone_config)
359               echo '<form id="theme_config" action="blog_theme.php?conf=1" method="post" enctype="multipart/form-data">';
360
361          include $theme_conf_file;
362
363          if (!$standalone_config)
364               echo
365               '<p class="clear"><input type="submit" value="'.__('Save').'" />'.
366               $core->formNonce().'</p>'.
367               '</form>';
368
369     }
370     catch (Exception $e)
371     {
372          echo '<div class="error"><p>'.$e->getMessage().'</p></div>';
373     }
374}
375
376dcPage::close();
377?>
Note: See TracBrowser for help on using the repository browser.

Sites map