Dotclear

source: admin/blog_theme.php @ 270:48858be15bda

Revision 270:48858be15bda, 10.8 KB checked in by Franck <carnet.franck.paul@…>, 13 years ago (diff)

Changement d'année

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

Sites map