Changeset 2196:234c9e083cfb for admin
- Timestamp:
- 10/02/13 00:10:37 (12 years ago)
- Branch:
- dcRepo
- Parents:
- 2195:70e4c0552ecc (diff), 2191:f3ecd85d5c32 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
admin/blog_theme.php
r2191 r2196 15 15 dcPage::check('admin'); 16 16 17 # Loading themes 17 # -------------------------------------------------- 18 # @todo Add settings to Dotclear update features 19 if ($core->blog->settings->system->repository_theme_url === null) { 20 $core->blog->settings->system->put( 21 'repository_theme_url', 'http://update.dotaddict.org/dc2/themes.xml', 'string', 'Themes XML feed location', true, true 22 ); 23 } 24 # -------------------------------------------------- 25 26 # -- Loading themes -- 18 27 $core->themes = new dcThemes($core); 19 $core->themes->loadModules($core->blog->themes_path,null); 20 21 # Theme screenshot 28 $core->themes->loadModules($core->blog->themes_path, null); 29 30 # -- Repository helper -- 31 $repository = new dcRepository( 32 $core->themes, 33 $core->blog->settings->system->repository_theme_url 34 ); 35 $repository->check(); 36 37 # -- Page helper -- 38 $list = new adminThemesList( 39 $core, 40 $core->blog->themes_path, 41 false 42 ); 43 44 # -- Theme screenshot -- 22 45 if (!empty($_GET['shot']) && $core->themes->moduleExists($_GET['shot'])) 23 46 { … … 43 66 } 44 67 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 50 if (!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 html::escapeHTML($theme['name'])) 68 # -- Display module configuration page -- 69 if ($list->setConfigurationFile($core->themes, $core->blog->settings->system->theme)) { 70 71 # Get content before page headers 72 include $list->getConfigurationFile(); 73 74 # Gather content 75 $list->setConfigurationContent(); 76 77 # Display page 78 dcPage::open(__('Blog appearance'), 79 dcPage::jsPageTabs(). 80 dcPage::jsColorPicker(). 81 82 # --BEHAVIOR-- themesToolsHeaders 83 $core->callBehavior('themesToolsHeaders', $core, true), 84 85 dcPage::breadcrumb( 86 array( 87 html::escapeHTML($core->blog->name) => '', 88 __('Blog appearance') => 'blog_theme.php', 89 '<span class="page-title">'.__('Theme configuration').'</span>' => '' 90 )) 59 91 ); 60 92 61 http::redirect('blog_theme.php'); 62 } 63 64 if ($can_install && !empty($_POST['theme']) && !empty($_POST['remove']) && empty($_REQUEST['conf'])) 65 { 66 try 67 { 68 if ($_POST['theme'] == 'default') { 69 throw new Exception(__('You can\'t remove default theme.')); 70 } 71 72 if (!$core->themes->moduleExists($_POST['theme'])) { 73 throw new Exception(__('Theme does not exist.')); 74 } 75 76 $theme = $core->themes->getModules($_POST['theme']); 77 78 # --BEHAVIOR-- themeBeforeDelete 79 $core->callBehavior('themeBeforeDelete',$theme); 80 81 $core->themes->deleteModule($_POST['theme']); 82 83 # --BEHAVIOR-- themeAfterDelete 84 $core->callBehavior('themeAfterDelete',$theme); 85 86 http::redirect('blog_theme.php'); 87 } 88 catch (Exception $e) 89 { 93 if (!empty($_GET['done'])){ 94 dcPage::success(__('Theme successfully configured.')); 95 } 96 97 # Display previously gathered content 98 $list->getConfigurationContent(); 99 100 dcPage::close(); 101 102 # Stop reading code here 103 return; 104 } 105 106 # -- Execute actions -- 107 if (!empty($_POST) && empty($_REQUEST['conf']) && $core->auth->isSuperAdmin() && $list->isPathWritable()) { 108 try { 109 $list->executeAction('themes', $core->themes, $repository); 110 } 111 catch (Exception $e) { 90 112 $core->error->add($e->getMessage()); 91 113 } 92 114 } 93 115 94 # Theme upload 95 if ($can_install && $is_writable && ((!empty($_POST['upload_pkg']) && !empty($_FILES['pkg_file'])) || 96 (!empty($_POST['fetch_pkg']) && !empty($_POST['pkg_url'])))) 97 { 98 try 99 { 100 if (empty($_POST['your_pwd']) || !$core->auth->checkPassword(crypt::hmac(DC_MASTER_KEY,$_POST['your_pwd']))) { 101 throw new Exception(__('Password verification failed')); 102 } 103 104 if (!empty($_POST['upload_pkg'])) 105 { 106 files::uploadStatus($_FILES['pkg_file']); 107 108 $dest = $core->blog->themes_path.'/'.$_FILES['pkg_file']['name']; 109 if (!move_uploaded_file($_FILES['pkg_file']['tmp_name'],$dest)) { 110 throw new Exception(__('Unable to move uploaded file.')); 111 } 112 } 113 else 114 { 115 $url = urldecode($_POST['pkg_url']); 116 $dest = $core->blog->themes_path.'/'.basename($url); 117 118 try 119 { 120 $client = netHttp::initClient($url,$path); 121 $client->setUserAgent('Dotclear - http://www.dotclear.org/'); 122 $client->useGzip(false); 123 $client->setPersistReferers(false); 124 $client->setOutput($dest); 125 $client->get($path); 126 } 127 catch( Exception $e) 128 { 129 throw new Exception(__('An error occurred while downloading the file.')); 130 } 131 132 unset($client); 133 } 134 135 $ret_code = dcModules::installPackage($dest,$core->themes); 136 if ($ret_code == 2) { 137 dcPage::addSuccessNotice(__('Theme has been successfully upgraded.')); 138 } else { 139 dcPage::addSuccessNotice(__('Theme has been successfully installed.')); 140 } 141 http::redirect('blog_theme.php'); 142 } 143 catch (Exception $e) 144 { 145 $core->error->add($e->getMessage()); 146 $default_tab = 'add-theme'; 147 } 148 } 149 150 $theme_conf_mode = false; 151 if (!empty($_REQUEST['conf'])) 152 { 153 $theme_conf_file = path::real($core->blog->themes_path.'/'.$core->blog->settings->system->theme).'/_config.php'; 154 if (file_exists($theme_conf_file)) { 155 $theme_conf_mode = true; 156 } 157 } 158 159 function display_theme_details($id,$details,$current) 160 { 161 global $core; 162 163 $screenshot = 'images/noscreenshot.png'; 164 if (file_exists($core->blog->themes_path.'/'.$id.'/screenshot.jpg')) { 165 $screenshot = 'blog_theme.php?shot='.rawurlencode($id); 166 } 167 168 $radio_id = 'theme_'.html::escapeHTML($id); 169 if (preg_match('#^http(s)?://#',$core->blog->settings->system->themes_url)) { 170 $theme_url = http::concatURL($core->blog->settings->system->themes_url,'/'.$id); 171 } else { 172 $theme_url = http::concatURL($core->blog->url,$core->blog->settings->system->themes_url.'/'.$id); 173 } 174 $has_conf = file_exists(path::real($core->blog->themes_path.'/'.$id).'/_config.php'); 175 $has_css = file_exists(path::real($core->blog->themes_path.'/'.$id).'/style.css'); 176 $parent = $core->themes->moduleInfo($id,'parent'); 177 $has_parent = (boolean)$parent; 178 if ($has_parent) { 179 $is_parent_present = $core->themes->moduleExists($parent); 180 } 181 182 $res = 183 '<div class="theme-details'.($current ? ' current-theme' : '').'">'. 184 '<div class="theme-shot"><img src="'.$screenshot.'" alt="" /></div>'. 185 '<div class="theme-info">'. 186 '<h4>'.form::radio(array('theme',$radio_id),html::escapeHTML($id),$current,'','',($has_parent && !$is_parent_present)).' '. 187 '<label class="classic" for="'.$radio_id.'">'. 188 html::escapeHTML($details['name']).'</label></h4>'. 189 '<p><span class="theme-desc">'.html::escapeHTML($details['desc']).'</span> '. 190 '<span class="theme-author">'.sprintf(__('by %s'),html::escapeHTML($details['author'])).'</span> '. 191 '<span class="theme-version">'.sprintf(__('version %s'),html::escapeHTML($details['version'])).'</span> '; 192 if ($has_parent) { 193 if ($is_parent_present) { 194 $res .= '<span class="theme-parent-ok">'.sprintf(__('(built on "%s")'),html::escapeHTML($parent)).'</span> '; 195 } else { 196 $res .= '<span class="theme-parent-missing">'.sprintf(__('(requires "%s")'),html::escapeHTML($parent)).'</span> '; 197 } 198 } 199 if ($has_css) { 200 $res .= '<span class="theme-css"><a href="'.$theme_url.'/style.css">'.__('Stylesheet').'</a></span>'; 201 } 202 $res .= '</p>'; 203 $res .= 204 '</div>'. 205 '<div class="theme-actions">'; 206 if ($current && $has_conf) { 207 $res .= '<p><a href="blog_theme.php?conf=1" class="button">'.__('Configure theme').'</a></p>'; 208 } 209 if ($current) { 210 # --BEHAVIOR-- adminCurrentThemeDetails 211 $res .= $core->callBehavior('adminCurrentThemeDetails',$core,$id,$details); 212 } 213 $res .= 214 '</div>'. 215 '</div>'; 216 217 return $res; 218 } 219 220 if (!$theme_conf_mode) 221 { 222 $breadcrumb = dcPage::breadcrumb( 116 # -- Page header -- 117 dcPage::open(__('Themes management'), 118 dcPage::jsLoad('js/_blog_theme.js'). 119 dcPage::jsPageTabs(). 120 dcPage::jsColorPicker(), 121 122 # --BEHAVIOR-- themesToolsHeaders 123 $core->callBehavior('themesToolsHeaders', $core, false), 124 125 dcPage::breadcrumb( 223 126 array( 224 127 html::escapeHTML($core->blog->name) => '', 225 __('Blog appearance') => '' 226 )); 227 } else { 228 $breadcrumb = dcPage::breadcrumb( 229 array( 230 html::escapeHTML($core->blog->name) => '', 231 __('Blog appearance') => 'blog_theme.php', 232 __('Theme configuration') => '' 233 )); 234 } 235 236 dcPage::open(__('Blog appearance'), 237 (!$theme_conf_mode ? dcPage::jsLoad('js/_blog_theme.js') : ''). 238 dcPage::jsPageTabs($default_tab). 239 dcPage::jsColorPicker(), 240 $breadcrumb 128 '<span class="page-title">'.__('Blog appearance').'</span>' => '' 129 )) 241 130 ); 242 131 243 if (!$theme_conf_mode) 244 { 245 if (!empty($_GET['upd'])) { 246 dcPage::success(__('Theme has been successfully changed.')); 247 } 248 249 if (!empty($_GET['added'])) { 250 dcPage::success(($_GET['added'] == 2 ? __('Theme has been successfully upgraded') : __('Theme has been successfully installed.'))); 251 } 252 253 if (!empty($_GET['del'])) { 254 dcPage::success(__('Theme has been successfully deleted.')); 255 } 256 257 # Themes list 258 echo '<div class="multi-part" id="themes-list" title="'.__('Themes').'">'. 259 '<h3>'.__('Available themes in your installation').'</h3>'; 260 261 $themes = $core->themes->getModules(); 262 if (isset($themes[$core->blog->settings->system->theme])) { 263 echo '<p>'.sprintf(__('You are currently using <strong>%s</strong>'),$themes[$core->blog->settings->system->theme]['name']).'.</p>'; 264 } 265 266 echo 267 '<form action="blog_theme.php" method="post" id="themes-form">'. 268 '<div id="themes">'; 269 270 if (isset($themes[$core->blog->settings->system->theme])) { 271 echo display_theme_details($core->blog->settings->system->theme,$themes[$core->blog->settings->system->theme],true); 272 } 273 274 foreach ($themes as $k => $v) 275 { 276 if ($core->blog->settings->system->theme == $k) { // Current theme 277 continue; 278 } 279 echo display_theme_details($k,$v,false); 280 } 281 282 echo '</div>'; 283 284 echo 285 '<div id="themes-actions">'. 286 287 '<p>'.$core->formNonce().'<input type="submit" name="select" value="'.__('Use selected theme').'" /> '; 288 if ($can_install) { 289 echo ' <input type="submit" class="delete" name="remove" value="'.__('Delete selected theme').'" />'; 290 } 291 echo '</p>'. 292 293 '</div>'. 294 '</form>'. 132 # -- Succes messages -- 133 if (!empty($_GET['msg'])) { 134 $list->displayMessage($_GET['msg']); 135 } 136 137 # -- Display modules lists -- 138 if ($core->auth->isSuperAdmin() && $list->isPathWritable()) { 139 140 # Updated modules from repo 141 $modules = $repository->get(true); 142 if (!empty($modules)) { 143 echo 144 '<div class="multi-part" id="update" title="'.html::escapeHTML(__('Update themes')).'">'. 145 '<h3>'.html::escapeHTML(__('Update themes')).'</h3>'. 146 '<p>'.sprintf( 147 __('There is one theme to update available from %2$s.', 'There are %s themes to update available from %s.', count($modules)), 148 count($modules), 149 '<a href="http://dotaddict.org/dc2/themes">Dotaddict</a>' 150 ).'</p>'; 151 152 $list 153 ->newList('theme-update') 154 ->setModules($modules) 155 ->setPageTab('update') 156 ->displayModulesList( 157 /*cols */ array('sshot', 'name', 'desc', 'author', 'version', 'current_version', 'parent'), 158 /* actions */ array('update') 159 ); 160 161 echo 162 '</div>'; 163 } 164 } 165 166 # List all active plugins 167 echo 168 '<div class="multi-part" id="themes" title="'.__('Installed themes').'">'; 169 170 $modules = $core->themes->getModules(); 171 if (!empty($modules)) { 172 173 echo 174 '<h3>'.__('Activated themes').'</h3>'. 175 '<p>'.__('Manage installed themes from this list.').'</p>'; 176 177 $list 178 ->newList('theme-activate') 179 ->setModules($modules) 180 ->setPageTab('themes') 181 ->displayModulesList( 182 /* cols */ array('sshot', 'name', 'config', 'desc', 'author', 'version', 'parent'), 183 /* actions */ array('select', 'deactivate', 'delete') 184 ); 185 } 186 187 $modules = $core->themes->getDisabledModules(); 188 if (!empty($modules)) { 189 190 echo 191 '<h3>'.__('Deactivated themes').'</h3>'. 192 '<p>'.__('Deactivated themes are installed but not usable. You can activate them from here.').'</p>'; 193 194 $list 195 ->newList('theme-deactivate') 196 ->setModules($modules) 197 ->setPageTab('themes') 198 ->displayModulesList( 199 /* cols */ array('name', 'distrib'), 200 /* actions */ array('activate', 'delete') 201 ); 202 } 203 204 echo 205 '</div>'; 206 207 if ($core->auth->isSuperAdmin() && $list->isPathWritable()) { 208 209 # New modules from repo 210 $search = $list->getSearchQuery(); 211 $modules = $search ? $repository->search($search) : $repository->get(); 212 213 echo 214 '<div class="multi-part" id="new" title="'.__('Add themes from Dotaddict').'">'. 215 '<h3>'.__('Add themes from Dotaddict repository').'</h3>'; 216 217 $list 218 ->newList('theme-new') 219 ->setModules($modules) 220 ->setPageTab('new') 221 ->displaySearchForm() 222 ->displayNavMenu() 223 ->displayModulesList( 224 /* cols */ array('expander', 'sshot', 'name', 'config', 'desc', 'author', 'version', 'parent', 'distrib'), 225 /* actions */ array('install'), 226 /* nav limit */ true 227 ); 228 229 echo 230 '<p class="info vertical-separator">'.sprintf( 231 __("Visit %s repository, the resources center for Dotclear."), 232 '<a href="http://dotaddict.org/dc2/themes">Dotaddict</a>' 233 ). 234 '</p>'. 235 295 236 '</div>'; 296 297 # Add a new theme 298 if ($can_install) 299 { 300 echo 301 '<div class="multi-part clear" id="add-theme" title="'.__('Install or upgrade a theme').'">'. 302 '<h3>'.__('Add themes to your installation').'</h3>'. 303 '<p class="form-note info">'.sprintf(__('You can find additional themes for your blog on %s.'), 304 '<a href="http://themes.dotaddict.org/galerie-dc2/">Dotaddict</a>').'</p>'; 305 306 if ($is_writable) 307 { 308 echo '<p>'.__('You can also install themes by uploading or downloading zip files.').'</p>'; 309 310 # 'Upload theme' form 311 echo 312 '<form method="post" action="blog_theme.php" id="uploadpkg" enctype="multipart/form-data" class="fieldset">'. 313 '<h4>'.__('Upload a zip file').'</h4>'. 314 '<p class="field"><label for="pkg_file" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Theme zip file:').'</label> '. 315 '<input type="file" name="pkg_file" id="pkg_file" /></p>'. 316 '<p class="field"><label for="your_pwd1" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Your password:').'</label> '. 317 form::password(array('your_pwd','your_pwd1'),20,255).'</p>'. 318 '<p><input type="submit" name="upload_pkg" value="'.__('Upload theme').'" />'. 319 $core->formNonce().'</p>'. 320 '</form>'; 321 322 # 'Fetch theme' form 323 echo 324 '<form method="post" action="blog_theme.php" id="fetchpkg" class="fieldset">'. 325 '<h4>'.__('Download a zip file').'</h4>'. 326 '<p class="field"><label for="pkg_url" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Theme zip file URL:').'</label> '. 327 form::field(array('pkg_url','pkg_url'),40,255).'</p>'. 328 '<p class="field"><label for="your_pwd2" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Your password:').'</label> '. 329 form::password(array('your_pwd','your_pwd2'),20,255).'</p>'. 330 '<p><input type="submit" name="fetch_pkg" value="'.__('Download theme').'" />'. 331 $core->formNonce().'</p>'. 332 '</form>'; 333 } 334 else 335 { 336 echo 337 '<p class="static-msg">'. 338 __('To enable this function, please give write access to your themes directory.'). 339 '</p>'; 340 } 341 echo '</div>'; 342 } 343 } 344 else 345 { 346 $theme_name = $core->themes->moduleInfo($core->blog->settings->system->theme,'name'); 347 $core->themes->loadModuleL10Nresources($core->blog->settings->system->theme,$_lang); 348 349 echo 350 '<p><a class="back" href="blog_theme.php">'.__('Back to Blog appearance').'</a></p>'; 351 352 try 353 { 354 # Let theme configuration set their own form(s) if required 355 $standalone_config = (boolean) $core->themes->moduleInfo($core->blog->settings->system->theme,'standalone_config'); 356 357 if (!$standalone_config) 358 echo '<form id="theme_config" action="blog_theme.php?conf=1" method="post" enctype="multipart/form-data">'; 359 360 include $theme_conf_file; 361 362 if (!$standalone_config) 363 echo 364 '<p class="clear"><input type="submit" value="'.__('Save').'" />'. 365 $core->formNonce().'</p>'. 366 '</form>'; 367 368 } 369 catch (Exception $e) 370 { 371 echo '<div class="error"><p>'.$e->getMessage().'</p></div>'; 372 } 237 238 # Add a new plugin 239 echo 240 '<div class="multi-part" id="addtheme" title="'.__('Install or upgrade manually').'">'; 241 242 echo '<p>'.__('You can install themes by uploading or downloading zip files.').'</p>'; 243 244 $list->displayManualForm(); 245 246 echo 247 '</div>'; 373 248 } 374 249
Note: See TracChangeset
for help on using the changeset viewer.