Dotclear


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • admin/blog_theme.php

    r2175 r2166  
    1515dcPage::check('admin'); 
    1616 
    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 -- 
     17# Loading themes 
    2718$core->themes = new dcThemes($core); 
    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 -- 
     19$core->themes->loadModules($core->blog->themes_path,null); 
     20 
     21# Theme screenshot 
    4522if (!empty($_GET['shot']) && $core->themes->moduleExists($_GET['shot'])) 
    4623{ 
     
    6643} 
    6744 
    68 # -- Check for module configuration -- 
    69 $conf_file = false; 
    70 if (!empty($_REQUEST['conf']) && !empty($_REQUEST['module'])) { 
    71      if (!$core->themes->moduleExists($_REQUEST['module'])) { 
    72           $core->error->add(__('Unknow module ID')); 
    73      } 
    74      else { 
    75           $module = $core->themes->getModules($_REQUEST['module']); 
    76           $module = adminModulesList::parseModuleInfo($_REQUEST['module'], $module); 
    77  
    78           if (!file_exists(path::real($module['root'].'/_config.php'))) { 
    79                $core->error->add(__('This module has no configuration file.')); 
    80           } 
    81           else { 
    82                $conf_file = path::real($module['root'].'/_config.php'); 
    83           } 
    84      } 
    85 } 
    86  
    87 # -- Display module configuration page -- 
    88 if ($conf_file) { 
    89      dcPage::open(__('Blog appearance'), 
    90  
    91           # --BEHAVIOR-- themesToolsHeaders 
    92           $core->callBehavior('themesToolsHeaders', $core, $module['id']), 
    93  
    94           dcPage::breadcrumb( 
    95                array( 
    96                     html::escapeHTML($core->blog->name) => '', 
    97                     __('Blog appearance') => 'blog_theme.php', 
    98                     '<span class="page-title">'.__('Theme configuration').'</span>' => '' 
    99                )) 
    100      ); 
    101  
    102      if (!empty($_GET['done'])){ 
    103           dcPage::success(__('Theme successfully configured.')); 
    104      } 
    105  
    106      try { 
    107           if (!$module['standalone_config']) { 
     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     if (preg_match('#^http(s)?://#',$core->blog->settings->system->themes_url)) { 
     159          $theme_url = http::concatURL($core->blog->settings->system->themes_url,'/'.$id); 
     160     } else { 
     161          $theme_url = http::concatURL($core->blog->url,$core->blog->settings->system->themes_url.'/'.$id); 
     162     } 
     163     $has_conf = file_exists(path::real($core->blog->themes_path.'/'.$id).'/_config.php'); 
     164     $has_css = file_exists(path::real($core->blog->themes_path.'/'.$id).'/style.css'); 
     165     $parent = $core->themes->moduleInfo($id,'parent'); 
     166     $has_parent = (boolean)$parent; 
     167     if ($has_parent) { 
     168          $is_parent_present = $core->themes->moduleExists($parent); 
     169     } 
     170      
     171     $res = 
     172     '<div class="theme-details'.($current ? ' current-theme' : '').'">'. 
     173     '<div class="theme-shot"><img src="'.$screenshot.'" alt="" /></div>'. 
     174     '<div class="theme-info">'. 
     175          '<h4>'.form::radio(array('theme',$radio_id),html::escapeHTML($id),$current,'','',($has_parent && !$is_parent_present)).' '. 
     176          '<label class="classic" for="'.$radio_id.'">'. 
     177          html::escapeHTML($details['name']).'</label></h4>'. 
     178          '<p><span class="theme-desc">'.html::escapeHTML($details['desc']).'</span> '. 
     179          '<span class="theme-author">'.sprintf(__('by %s'),html::escapeHTML($details['author'])).'</span> '. 
     180          '<span class="theme-version">'.sprintf(__('version %s'),html::escapeHTML($details['version'])).'</span> '; 
     181          if ($has_parent) { 
     182               if ($is_parent_present) { 
     183                    $res .= '<span class="theme-parent-ok">'.sprintf(__('(built on "%s")'),html::escapeHTML($parent)).'</span> '; 
     184               } else { 
     185                    $res .= '<span class="theme-parent-missing">'.sprintf(__('(requires "%s")'),html::escapeHTML($parent)).'</span> '; 
     186               } 
     187          } 
     188          if ($has_css) { 
     189               $res .= '<span class="theme-css"><a href="'.$theme_url.'/style.css">'.__('Stylesheet').'</a></span>'; 
     190          } 
     191          $res .= '</p>'; 
     192     $res .= 
     193     '</div>'. 
     194     '<div class="theme-actions">'; 
     195          if ($current && $has_conf) { 
     196               $res .= '<p><a href="blog_theme.php?conf=1" class="button">'.__('Configure theme').'</a></p>'; 
     197          } 
     198          if ($current) { 
     199               # --BEHAVIOR-- adminCurrentThemeDetails 
     200               $res .= $core->callBehavior('adminCurrentThemeDetails',$core,$id,$details); 
     201          } 
     202     $res .= 
     203     '</div>'. 
     204     '</div>'; 
     205      
     206     return $res; 
     207} 
     208 
     209if (!$theme_conf_mode) 
     210{ 
     211     $breadcrumb = dcPage::breadcrumb( 
     212          array( 
     213               html::escapeHTML($core->blog->name) => '', 
     214               __('Blog appearance') => '' 
     215          )); 
     216} else { 
     217     $breadcrumb = dcPage::breadcrumb( 
     218          array( 
     219               html::escapeHTML($core->blog->name) => '', 
     220               __('Blog appearance') => 'blog_theme.php', 
     221               __('Theme configuration') => '' 
     222          )); 
     223} 
     224 
     225dcPage::open(__('Blog appearance'), 
     226     (!$theme_conf_mode ? dcPage::jsLoad('js/_blog_theme.js') : ''). 
     227     dcPage::jsPageTabs($default_tab). 
     228     dcPage::jsColorPicker(), 
     229     $breadcrumb 
     230); 
     231 
     232if (!$theme_conf_mode) 
     233{ 
     234     if (!empty($_GET['upd'])) { 
     235          dcPage::success(__('Theme has been successfully changed.')); 
     236     } 
     237      
     238     if (!empty($_GET['added'])) { 
     239          dcPage::success(($_GET['added'] == 2 ? __('Theme has been successfully upgraded') : __('Theme has been successfully installed.'))); 
     240     } 
     241      
     242     if (!empty($_GET['del'])) { 
     243          dcPage::success(__('Theme has been successfully deleted.')); 
     244     } 
     245      
     246     # Themes list 
     247     echo '<div class="multi-part" id="themes-list" title="'.__('Themes').'">'. 
     248     '<h3>'.__('Available themes in your installation').'</h3>'; 
     249      
     250     $themes = $core->themes->getModules(); 
     251     if (isset($themes[$core->blog->settings->system->theme])) { 
     252          echo '<p>'.sprintf(__('You are currently using <strong>%s</strong>'),$themes[$core->blog->settings->system->theme]['name']).'.</p>'; 
     253     } 
     254      
     255     echo 
     256     '<form action="blog_theme.php" method="post" id="themes-form">'. 
     257     '<div id="themes">'; 
     258      
     259     if (isset($themes[$core->blog->settings->system->theme])) { 
     260          echo display_theme_details($core->blog->settings->system->theme,$themes[$core->blog->settings->system->theme],true); 
     261     } 
     262      
     263     foreach ($themes as $k => $v) 
     264     { 
     265          if ($core->blog->settings->system->theme == $k) { // Current theme 
     266               continue; 
     267          } 
     268          echo display_theme_details($k,$v,false); 
     269     } 
     270      
     271     echo '</div>'; 
     272      
     273     echo 
     274     '<div id="themes-actions">'. 
     275      
     276     '<p>'.$core->formNonce().'<input type="submit" name="select" value="'.__('Use selected theme').'" /> ';   
     277     if ($can_install) { 
     278          echo ' <input type="submit" class="delete" name="remove" value="'.__('Delete selected theme').'" />'; 
     279     } 
     280     echo '</p>'. 
     281      
     282     '</div>'. 
     283     '</form>'. 
     284     '</div>'; 
     285      
     286     # Add a new theme 
     287     if ($can_install) 
     288     { 
     289          echo 
     290          '<div class="multi-part clear" id="add-theme" title="'.__('Install or upgrade a theme').'">'. 
     291          '<h3>'.__('Add themes to your installation').'</h3>'. 
     292          '<p class="form-note info">'.sprintf(__('You can find additional themes for your blog on %s.'), 
     293          '<a href="http://themes.dotaddict.org/galerie-dc2/">Dotaddict</a>').'</p>'; 
     294           
     295          if ($is_writable) 
     296          { 
     297               echo '<p>'.__('You can also install themes by uploading or downloading zip files.').'</p>'; 
     298                
     299               # 'Upload theme' form 
    108300               echo 
    109                '<form id="module_config" action="'.$list->getPageURL('conf=1').'" method="post" enctype="multipart/form-data">'. 
    110                '<h3>'.sprintf(__('Configure theme "%s"'), html::escapeHTML($module['name'])).'</h3>'. 
    111                '<p><a class="back" href="'.$list->getPageURL().'#themes">'.__('Back').'</a></p>'; 
    112           } 
    113           define('DC_CONTEXT_THEME', true); 
    114  
    115           include $conf_file; 
    116  
    117           if (!$module['standalone_config']) { 
    118                echo 
    119                '<p class="clear"><input type="submit" name="save" value="'.__('Save').'" />'. 
    120                form::hidden('module', $module['id']). 
     301               '<form method="post" action="blog_theme.php" id="uploadpkg" enctype="multipart/form-data" class="fieldset">'. 
     302               '<h4>'.__('Upload a zip file').'</h4>'. 
     303               '<p class="field"><label for="pkg_file" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Theme zip file:').'</label> '. 
     304               '<input type="file" name="pkg_file" id="pkg_file" /></p>'. 
     305               '<p class="field"><label for="your_pwd1" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Your password:').'</label> '. 
     306               form::password(array('your_pwd','your_pwd1'),20,255).'</p>'. 
     307               '<p><input type="submit" name="upload_pkg" value="'.__('Upload theme').'" />'. 
    121308               $core->formNonce().'</p>'. 
    122309               '</form>'; 
    123           } 
    124      } 
    125      catch (Exception $e) { 
     310                
     311               # 'Fetch theme' form 
     312               echo 
     313               '<form method="post" action="blog_theme.php" id="fetchpkg" class="fieldset">'. 
     314               '<h4>'.__('Download a zip file').'</h4>'. 
     315               '<p class="field"><label for="pkg_url" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Theme zip file URL:').'</label> '. 
     316               form::field(array('pkg_url','pkg_url'),40,255).'</p>'. 
     317               '<p class="field"><label for="your_pwd2" class="classic required"><abbr title="'.__('Required field').'">*</abbr> '.__('Your password:').'</label> '. 
     318               form::password(array('your_pwd','your_pwd2'),20,255).'</p>'. 
     319               '<p><input type="submit" name="fetch_pkg" value="'.__('Download theme').'" />'. 
     320               $core->formNonce().'</p>'. 
     321               '</form>'; 
     322          } 
     323          else 
     324          { 
     325               echo 
     326               '<p class="static-msg">'. 
     327               __('To enable this function, please give write access to your themes directory.'). 
     328               '</p>'; 
     329          } 
     330          echo '</div>'; 
     331     } 
     332} 
     333else 
     334{ 
     335     $theme_name = $core->themes->moduleInfo($core->blog->settings->system->theme,'name'); 
     336     $core->themes->loadModuleL10Nresources($core->blog->settings->system->theme,$_lang); 
     337 
     338     echo 
     339     '<p><a class="back" href="blog_theme.php">'.__('Back to Blog appearance').'</a></p>'; 
     340      
     341     try 
     342     { 
     343          # Let theme configuration set their own form(s) if required 
     344          $standalone_config = (boolean) $core->themes->moduleInfo($core->blog->settings->system->theme,'standalone_config'); 
     345 
     346          if (!$standalone_config) 
     347               echo '<form id="theme_config" action="blog_theme.php?conf=1" method="post" enctype="multipart/form-data">'; 
     348 
     349          include $theme_conf_file; 
     350 
     351          if (!$standalone_config) 
     352               echo 
     353               '<p class="clear"><input type="submit" value="'.__('Save').'" />'. 
     354               $core->formNonce().'</p>'. 
     355               '</form>'; 
     356 
     357     } 
     358     catch (Exception $e) 
     359     { 
    126360          echo '<div class="error"><p>'.$e->getMessage().'</p></div>'; 
    127361     } 
    128  
    129      dcPage::close(); 
    130  
    131      # Stop reading code here 
    132      return; 
    133 } 
    134  
    135 # -- Execute actions -- 
    136 if (!empty($_POST) && empty($_REQUEST['conf']) && $core->auth->isSuperAdmin() && $list->isPathWritable()) { 
    137      try { 
    138           $list->executeAction('themes', $core->themes, $repository); 
    139      } 
    140      catch (Exception $e) { 
    141           $core->error->add($e->getMessage()); 
    142      } 
    143 } 
    144  
    145 # -- Page header -- 
    146 dcPage::open(__('Themes management'), 
    147 //   (!$conf_file ? dcPage::jsLoad('js/_blog_theme.js') : ''). 
    148      dcPage::jsPageTabs(). 
    149      dcPage::jsColorPicker(), 
    150  
    151      # --BEHAVIOR-- themesToolsHeaders 
    152      $core->callBehavior('themesToolsHeaders', $core, false), 
    153  
    154      dcPage::breadcrumb( 
    155           array( 
    156                html::escapeHTML($core->blog->name) => '', 
    157                '<span class="page-title">'.__('Blog appearance').'</span>' => '' 
    158           )) 
    159 ); 
    160  
    161 # -- Succes messages -- 
    162 if (!empty($_GET['msg'])) { 
    163      $list->displayMessage($_GET['msg']); 
    164 } 
    165  
    166 # -- Display modules lists -- 
    167 if ($core->auth->isSuperAdmin() && $list->isPathWritable()) { 
    168  
    169      # Updated modules from repo 
    170      $modules = $repository->get(true); 
    171      if (!empty($modules)) { 
    172           echo  
    173           '<div class="multi-part" id="update" title="'.html::escapeHTML(__('Update themes')).'">'. 
    174           '<h3>'.html::escapeHTML(__('Update themes')).'</h3>'. 
    175           '<p>'.sprintf( 
    176                __('There is one theme to update available from %2$s.', 'There are %s themes to update available from %s.', count($modules)), 
    177                count($modules), 
    178                '<a href="http://dotaddict.org/dc2/themes">Dotaddict</a>' 
    179           ).'</p>'; 
    180  
    181           $list 
    182                ->newList('theme-update') 
    183                ->setModules($modules) 
    184                ->setPageTab('update') 
    185                ->displayModulesList( 
    186                     /*cols */      array('sshot', 'name', 'desc', 'author', 'version', 'current_version', 'parent'), 
    187                     /* actions */  array('update') 
    188                ); 
    189  
    190           echo 
    191           '</div>'; 
    192      } 
    193 } 
    194  
    195 # List all active plugins 
    196 echo 
    197 '<div class="multi-part" id="themes" title="'.__('Installed themes').'">'; 
    198  
    199 $modules = $core->themes->getModules(); 
    200 if (!empty($modules)) { 
    201  
    202      echo 
    203      '<h3>'.__('Activated themes').'</h3>'. 
    204      '<p>'.__('Manage installed themes from this list.').'</p>'; 
    205  
    206      $list 
    207           ->newList('theme-activate') 
    208           ->setModules($modules) 
    209           ->setPageTab('themes') 
    210           ->displayModulesList( 
    211                /* cols */          array('sshot', 'name', 'config', 'desc', 'author', 'version', 'parent'), 
    212                /* actions */  array('deactivate', 'delete') 
    213           ); 
    214 } 
    215  
    216 echo  
    217 '</div>'; 
    218  
    219 if ($core->auth->isSuperAdmin() && $list->isPathWritable()) { 
    220  
    221      # New modules from repo 
    222      $search = $list->getSearchQuery(); 
    223      $modules = $search ? $repository->search($search) : $repository->get(); 
    224  
    225      echo 
    226      '<div class="multi-part" id="new" title="'.__('Add themes from Dotaddict').'">'. 
    227      '<h3>'.__('Add themes from Dotaddict repository').'</h3>'; 
    228  
    229      $list 
    230           ->newList('theme-new') 
    231           ->setModules($modules) 
    232           ->setPageTab('new') 
    233           ->displaySearchForm() 
    234           ->displayNavMenu() 
    235           ->displayModulesList( 
    236                /* cols */          array('expander', 'sshot', 'name', 'config', 'desc', 'author', 'version', 'parent'), 
    237                /* actions */  array('install'), 
    238                /* nav limit */     true 
    239           ); 
    240  
    241      echo 
    242      '<p class="info vertical-separator">'.sprintf( 
    243           __("Visit %s repository, the resources center for Dotclear."), 
    244           '<a href="http://dotaddict.org/dc2/themes">Dotaddict</a>' 
    245           ). 
    246      '</p>'. 
    247  
    248      '</div>'; 
    249  
    250      # Add a new plugin 
    251      echo 
    252      '<div class="multi-part" id="addtheme" title="'.__('Install or upgrade manually').'">'; 
    253  
    254      echo '<p>'.__('You can install themes by uploading or downloading zip files.').'</p>'; 
    255       
    256      $list->displayManualForm(); 
    257  
    258      echo 
    259      '</div>'; 
    260362} 
    261363 
Note: See TracChangeset for help on using the changeset viewer.

Sites map