Dotclear

source: plugins/gallery/trunk/maintenance.php @ 2264

Revision 2264, 8.5 KB checked in by bruno, 14 years ago (diff)

DC 2.1.7 support

  • Property svn:executable set to *
Line 
1<?php
2# -- BEGIN LICENSE BLOCK ----------------------------------
3#
4# This file is part of Dotclear 2 Gallery plugin.
5#
6# Copyright (c) 2004-2008 Bruno Hondelatte, and contributors.
7# Many, many thanks to Olivier Meunier and the Dotclear Team.
8# Licensed under the GPL version 2.0 license.
9# See LICENSE file or
10# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11#
12# -- END LICENSE BLOCK ------------------------------------
13
14if (!defined('DC_CONTEXT_ADMIN')) { exit; }
15
16# Settings compatibility test
17if (!version_compare(DC_VERSION,'2.2alpha','>=')) {
18     $system_settings =& $core->blog->settings->system;
19} else {
20     $system_settings =& $core->blog->settings;
21}
22
23$can_install = $core->auth->isSuperAdmin();
24$themes_dir = path::fullFromRoot($core->gallery->settings->gallery_themes_path,DC_ROOT);
25$is_writable = is_dir($themes_dir) && is_writable($themes_dir);
26if (!$can_install)
27     return;
28
29require dirname(__FILE__)."/class.dc.gallery.themeadapter.php";
30
31$core->themes = new dcThemes($core);
32$core->themes->loadModules($core->blog->themes_path,null);
33
34function installGalTheme($zip_file)
35{
36     $zip = new fileUnzip($zip_file);
37     $zip->getList(false,'#(^|/)(__MACOSX|\.svn|\.DS_Store|Thumbs\.db)(/|$)#');
38     
39     $zip_root_dir = $zip->getRootDir();
40     $define = '';
41     if ($zip_root_dir == false || $zip_root_dir == 'gal_simple' || substr($zip_root_dir,0,4) != 'gal_') {
42          throw new Exception (__('Theme is invalid'));
43     } else {
44          $target = dirname($zip_file);
45          $destination = $target.'/'.$zip_root_dir;
46     }
47     
48     if ($zip->isEmpty()) {
49          unlink($zip_file);
50          throw new Exception(__('Empty module zip file.'));
51     }
52     
53     $ret_code = 1;
54     
55     if (is_dir($destination))
56     {
57          throw new Exception(sprintf(__('Theme %s already exists, delete it first.'),
58               html::escapeHTML(substr($zip_root_dir,4))));
59     }
60     $zip->unzipAll($target);
61     unlink($zip_file);
62     return $ret_code;
63}
64
65if (!empty($_POST['adapt_theme'])) {
66     $dc_theme = (!empty($_POST['dctheme']))?$_POST['dctheme']:"";
67     $overwrite = (isset($_POST['themeoverwrite']))?true:false;
68     $themeadapter = new dcGalleryThemeAdapter($core,$dc_theme);
69     if($themeadapter->generateAllTemplates($overwrite))
70          http::redirect('plugin.php?p=gallery&m=maintenance&adapted=1');
71} elseif ($can_install && $is_writable && ((!empty($_POST['upload_pkg']) && !empty($_FILES['pkg_file'])) ||
72     (!empty($_POST['fetch_pkg']) && !empty($_POST['pkg_url']))))
73{
74     try
75     {
76          if (empty($_POST['your_pwd']) || !$core->auth->checkPassword(crypt::hmac(DC_MASTER_KEY,$_POST['your_pwd']))) {
77               throw new Exception(__('Password verification failed'));
78          }
79         
80          if (!empty($_POST['upload_pkg']))
81          {
82               files::uploadStatus($_FILES['pkg_file']);
83               
84               $dest = $themes_dir.'/'.$_FILES['pkg_file']['name'];
85               if (!move_uploaded_file($_FILES['pkg_file']['tmp_name'],$dest)) {
86                    throw new Exception(__('Unable to move uploaded file.'));
87               }
88          }
89          else
90          {
91               $url = urldecode($_POST['pkg_url']);
92               $dest = $themes_dir.'/'.basename($url);
93               
94               try
95               {
96                    $client = netHttp::initClient($url,$path);
97                    $client->setUserAgent('Dotclear - http://www.dotclear.net/');
98                    $client->useGzip(false);
99                    $client->setPersistReferers(false);
100                    $client->setOutput($dest);
101                    $client->get($path);
102               }
103               catch( Exception $e)
104               {
105                    throw new Exception(__('An error occurred while downloading the file.'));
106               }
107               
108               unset($client);
109          }
110         
111          $ret_code = installGalTheme($dest);
112          http::redirect('plugin.php?p=gallery&m=maintenance&installed=1');
113     }
114     catch (Exception $e)
115     {
116          $core->error->add($e->getMessage());
117     }
118} elseif ($is_writable && !empty($_POST['remove'])) {
119     $entries = $_POST['themes'];
120     try {
121          foreach ($entries as $entry) {
122               $e='gal_'.trim(strtr($entry,"./",""));
123               if ($e !== 'gal_' && $e != 'gal_simple') {
124                    if (!files::deltree($themes_dir.'/'.$e)) {
125                         throw new Exception(sprintf(__('Could not remove theme %s'),
126                         html::escapeHTML($entry)));
127                    }
128               }
129          }
130          http::redirect('plugin.php?p=gallery&m=maintenance&deleted=1');
131     } catch (Exception $e) {
132          $core->error->add($e->getMessage());
133     }
134}
135
136
137
138?>
139<html>
140<head>
141  <title><?php echo __('Maintenance'); ?></title>
142  <?php echo dcPage::jsPageTabs("maintenance");
143  ?>
144  <script type="text/javascript">
145  //<![CDATA[
146  dotclear.msg.confirm_delete_themes = '<?php echo __('Are you sure you want to delete selected themes ?'); ?>';
147  $(function() {
148          $('input[name="remove"]').click(function() {
149                    return window.confirm(dotclear.msg.confirm_delete_themes);
150          });
151          });
152  //]]>
153  </script>
154</head>
155<body>
156
157<?php
158if (!empty($_GET['adapted'])) {
159          echo '<p class="message">'.__('The theme has been successfully adapted.').'</p>';
160}
161if (!empty($_GET['installed'])) {
162          echo '<p class="message">'.__('The theme has been successfully installed.').'</p>';
163}
164if (!empty($_GET['deleted'])) {
165          echo '<p class="message">'.__('The theme has been successfully deleted.').'</p>';
166}
167
168
169$dcthemes = $core->themes->getModules();
170$dcthemes_combo = array();
171foreach ($dcthemes as $k => $v) {
172     if ($k != 'simple')
173          $dcthemes_combo[$v['name']]=$k;
174}
175
176$galthemes_combo = $core->gallery->getThemes();
177/*if ($core->error->flag()) {
178     echo
179     '<div class="error"><strong>'.__('Errors:').'</strong>'.
180     $core->error->toHTML().
181     '</div>';
182}
183*/
184
185echo '<h2>'.html::escapeHTML($core->blog->name).' &gt; '.__('Galleries').' &gt; '.__('Maintenance').'</h2>';
186echo '<p><a href="plugin.php?p=gallery" class="multi-part">'.__('Galleries').'</a></p>';
187echo '<p><a href="plugin.php?p=gallery&amp;m=items" class="multi-part">'.__('Images').'</a></p>';
188echo '<p><a href="plugin.php?p=gallery&amp;m=newitems" class="multi-part">'.__('Manage new items').'</a></p>';
189echo '<p><a href="plugin.php?p=gallery&amp;m=options" class="multi-part">'.__('Options').'</a></p>';
190echo '<div class="multi-part" id="maintenance" title="'.__('Maintenance').'">';
191echo '<form action="plugin.php" method="post" id="theme_adapter">'.
192     '<fieldset><legend>'.__('Theme Adapter').'</legend>';
193echo '<p>'.__('This section enables to adapt gallery themes to a Dotclear theme, if needed.')."</p>".
194'<p>'.__('<strong>Caution :</strong> use the theme adapter only if you experience some layout problems when viewing galleries or images on your blog.')."</p>".
195     '<p><label class="classic">'.__('Dotclear theme').' : </label>'.form::combo('dctheme',$dcthemes_combo,$system_settings->theme).'</p>'.
196     '<p><label class="classic">'.__('Force template regeneration').'</label>&nbsp;'.form::checkbox('themeoverwrite',false,false).
197     '<p><input type="submit" name="adapt_theme" value="'.__('Adapt').'" /></p>'.
198     form::hidden('p','gallery').
199     form::hidden('m','maintenance').$core->formNonce().'</p>';
200echo '</fieldset></form>';
201if ($is_writable) {
202echo '<form action="plugin.php" method="post" id="theme_deleter">'.
203     '<fieldset><legend>'.__('Gallery Themes').'</legend>'.
204     '<table class="clear"><tr>'.
205     '<th colspan="2">'.__('Theme').'</th></tr>';
206
207     foreach ($galthemes_combo as $theme) {
208          if ($theme == 'simple'   )
209               echo '<tr><td>'.form::checkbox(array('themes[]'),$theme,'','','',true).'</td><td>'.$theme.'</td></tr>';
210          else
211               echo '<tr><td>'.form::checkbox(array('themes[]'),$theme).'</td><td>'.$theme.'</td></tr>';
212     }
213     echo '</table>'.
214     '<input type="submit" name="remove" value="'.__('Uninstall selected themes').'" />'.
215     form::hidden('p','gallery').
216     form::hidden('m','maintenance').
217     $core->formNonce().'</p>';
218echo '</fieldset></form>';
219echo '<form action="plugin.php" method="post" id="theme_uploader"  enctype="multipart/form-data">'.
220     '<fieldset><legend>'.__('Upload a new Gallery theme').'</legend>'.
221     '<p class="field"><label class=" classic required" title="'.__('Required field').'">'.__('Theme zip file:').' '.
222     '<input type="file" name="pkg_file" /></label></p>'.
223     '<p class="field"><label class="classic required" title="'.__('Required field').'">'.__('Your password:').' '.
224     form::password(array('your_pwd'),20,255).'</label></p>'.
225     '<input type="submit" name="upload_pkg" value="'.__('Upload theme').'" />'.
226     form::hidden('p','gallery').
227     form::hidden('m','maintenance').
228     $core->formNonce().
229     '</fieldset></form>';
230
231echo '<form action="plugin.php" method="post" id="theme_downloader">'.
232     '<fieldset><legend>'.__('Download a new Gallery theme').'</legend>'.
233     '<p class="field"><label class=" classic required" title="'.__('Required field').'">'.__('Theme zip file URL:').' '.
234     form::field(array('pkg_url'),40,255).'</label></p>'.
235     '<p class="field"><label class="classic required" title="'.__('Required field').'">'.__('Your password:').' '.
236     form::password(array('your_pwd'),20,255).'</label></p>'.
237     '<input type="submit" name="fetch_pkg" value="'.__('Download theme').'" />'.
238     form::hidden('p','gallery').
239     form::hidden('m','maintenance').
240     $core->formNonce().
241     '</fieldset></form>';
242}
243?>
244
245</div>
246</body>
247</html>
Note: See TracBrowser for help on using the repository browser.

Sites map