Dotclear

Changeset 2900:d12215a1a1e7


Ignore:
Timestamp:
01/04/15 14:31:37 (11 years ago)
Author:
Dsls
Branch:
feature/perblog_activation
Message:

First shot for per_blog settings for plugins, see #2041

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • admin/blog_pref.php

    r2858 r2900  
    160160 
    161161# Update a blog 
    162 if ($blog_id && !empty($_POST) && $core->auth->check('admin',$blog_id)) 
     162if ($blog_id && $core->auth->check('admin',$blog_id)) 
    163163{ 
    164      $cur = $core->con->openCursor($core->prefix.'blog'); 
    165      if ($core->auth->isSuperAdmin()) { 
    166           $cur->blog_id = $_POST['blog_id']; 
    167           $cur->blog_url = preg_replace('/\?+$/','?',$_POST['blog_url']); 
    168           if (in_array($_POST['blog_status'],$status_combo)) { 
    169                $cur->blog_status = (integer) $_POST['blog_status']; 
    170           } 
    171      } 
    172      $cur->blog_name = $_POST['blog_name']; 
    173      $cur->blog_desc = $_POST['blog_desc']; 
    174  
    175      $media_img_t_size = abs((integer) $_POST['media_img_t_size']); 
    176      if ($media_img_t_size < 0) { $media_img_t_size = 100; } 
    177  
    178      $media_img_s_size = abs((integer) $_POST['media_img_s_size']); 
    179      if ($media_img_s_size < 0) { $media_img_s_size = 240; } 
    180  
    181      $media_img_m_size = abs((integer) $_POST['media_img_m_size']); 
    182      if ($media_img_m_size < 0) { $media_img_m_size = 448; } 
    183  
    184      $nb_post_for_home = abs((integer) $_POST['nb_post_for_home']); 
    185      if ($nb_post_for_home <= 1) { $nb_post_for_home = 1; } 
    186  
    187      $nb_post_per_page = abs((integer) $_POST['nb_post_per_page']); 
    188      if ($nb_post_per_page <= 1) { $nb_post_per_page = 1; } 
    189  
    190      $nb_post_per_feed = abs((integer) $_POST['nb_post_per_feed']); 
    191      if ($nb_post_per_feed <= 1) { $nb_post_per_feed = 1; } 
    192  
    193      $nb_comment_per_feed = abs((integer) $_POST['nb_comment_per_feed']); 
    194      if ($nb_comment_per_feed <= 1) { $nb_comment_per_feed = 1; } 
    195  
    196      try 
    197      { 
    198           if ($cur->blog_id != null && $cur->blog_id != $blog_id) { 
    199                $rs = $core->getBlog($cur->blog_id); 
    200  
    201                if ($rs) { 
    202                     throw new Exception(__('This blog ID is already used.')); 
    203                } 
    204           } 
    205  
    206           # --BEHAVIOR-- adminBeforeBlogUpdate 
    207           $core->callBehavior('adminBeforeBlogUpdate',$cur,$blog_id); 
    208  
    209           if (!preg_match('/^[a-z]{2}(-[a-z]{2})?$/',$_POST['lang'])) { 
    210                throw new Exception(__('Invalid language code')); 
    211           } 
    212  
    213           $core->updBlog($blog_id,$cur); 
    214  
    215           # --BEHAVIOR-- adminAfterBlogUpdate 
    216           $core->callBehavior('adminAfterBlogUpdate',$cur,$blog_id); 
    217  
    218           if ($cur->blog_id != null && $cur->blog_id != $blog_id) { 
    219                if ($blog_id == $core->blog->id) { 
    220                     $core->setBlog($cur->blog_id); 
    221                     $_SESSION['sess_blog_id'] = $cur->blog_id; 
    222                     $blog_settings = $core->blog->settings; 
    223                } else { 
    224                     $blog_settings = new dcSettings($core,$cur->blog_id); 
    225                } 
    226  
    227                $blog_id = $cur->blog_id; 
    228           } 
    229  
    230  
    231           $blog_settings->addNameSpace('system'); 
    232  
    233           $blog_settings->system->put('editor',$_POST['editor']); 
    234           $blog_settings->system->put('copyright_notice',$_POST['copyright_notice']); 
    235           $blog_settings->system->put('post_url_format',$_POST['post_url_format']); 
    236           $blog_settings->system->put('lang',$_POST['lang']); 
    237           $blog_settings->system->put('blog_timezone',$_POST['blog_timezone']); 
    238           $blog_settings->system->put('date_format',$_POST['date_format']); 
    239           $blog_settings->system->put('time_format',$_POST['time_format']); 
    240           $blog_settings->system->put('comments_ttl',abs((integer) $_POST['comments_ttl'])); 
    241           $blog_settings->system->put('trackbacks_ttl',abs((integer) $_POST['trackbacks_ttl'])); 
    242           $blog_settings->system->put('allow_comments',!empty($_POST['allow_comments'])); 
    243           $blog_settings->system->put('allow_trackbacks',!empty($_POST['allow_trackbacks'])); 
    244           $blog_settings->system->put('comments_pub',empty($_POST['comments_pub'])); 
    245           $blog_settings->system->put('trackbacks_pub',empty($_POST['trackbacks_pub'])); 
    246           $blog_settings->system->put('comments_nofollow',!empty($_POST['comments_nofollow'])); 
    247           $blog_settings->system->put('wiki_comments',!empty($_POST['wiki_comments'])); 
    248           $blog_settings->system->put('comment_preview_optional',!empty($_POST['comment_preview_optional'])); 
    249           $blog_settings->system->put('enable_xmlrpc',!empty($_POST['enable_xmlrpc'])); 
    250           $blog_settings->system->put('note_title_tag',$_POST['note_title_tag']); 
    251           $blog_settings->system->put('nb_post_for_home',$nb_post_for_home); 
    252           $blog_settings->system->put('nb_post_per_page',$nb_post_per_page); 
    253           $blog_settings->system->put('use_smilies',!empty($_POST['use_smilies'])); 
    254           $blog_settings->system->put('inc_subcats',!empty($_POST['inc_subcats'])); 
    255           $blog_settings->system->put('media_img_t_size',$media_img_t_size); 
    256           $blog_settings->system->put('media_img_s_size',$media_img_s_size); 
    257           $blog_settings->system->put('media_img_m_size',$media_img_m_size); 
    258           $blog_settings->system->put('media_img_title_pattern',$_POST['media_img_title_pattern']); 
    259           $blog_settings->system->put('media_img_use_dto_first',!empty($_POST['media_img_use_dto_first'])); 
    260           $blog_settings->system->put('media_img_no_date_alone',!empty($_POST['media_img_no_date_alone'])); 
    261           $blog_settings->system->put('media_img_default_size',$_POST['media_img_default_size']); 
    262           $blog_settings->system->put('media_img_default_alignment',$_POST['media_img_default_alignment']); 
    263           $blog_settings->system->put('media_img_default_link',!empty($_POST['media_img_default_link'])); 
    264           $blog_settings->system->put('nb_post_per_feed',$nb_post_per_feed); 
    265           $blog_settings->system->put('nb_comment_per_feed',$nb_comment_per_feed); 
    266           $blog_settings->system->put('short_feed_items',!empty($_POST['short_feed_items'])); 
    267           if (isset($_POST['robots_policy'])) { 
    268                $blog_settings->system->put('robots_policy',$_POST['robots_policy']); 
    269           } 
    270           $blog_settings->system->put('jquery_version',$_POST['jquery_version']); 
    271           $blog_settings->system->put('prevents_clickjacking',!empty($_POST['prevents_clickjacking'])); 
    272  
    273           # --BEHAVIOR-- adminBeforeBlogSettingsUpdate 
    274           $core->callBehavior('adminBeforeBlogSettingsUpdate',$blog_settings); 
    275  
    276           if ($core->auth->isSuperAdmin() && in_array($_POST['url_scan'],$url_scan_combo)) { 
    277                $blog_settings->system->put('url_scan',$_POST['url_scan']); 
    278           } 
    279           dcPage::addSuccessNotice(__('Blog has been successfully updated.')); 
    280  
    281           http::redirect(sprintf($redir,$blog_id)); 
    282      } 
    283      catch (Exception $e) 
    284      { 
    285           $core->error->add($e->getMessage()); 
     164     if (isset($_POST['save_blog'])) { 
     165          $cur = $core->con->openCursor($core->prefix.'blog'); 
     166          if ($core->auth->isSuperAdmin()) { 
     167               $cur->blog_id = $_POST['blog_id']; 
     168               $cur->blog_url = preg_replace('/\?+$/','?',$_POST['blog_url']); 
     169               if (in_array($_POST['blog_status'],$status_combo)) { 
     170                    $cur->blog_status = (integer) $_POST['blog_status']; 
     171               } 
     172          } 
     173          $cur->blog_name = $_POST['blog_name']; 
     174          $cur->blog_desc = $_POST['blog_desc']; 
     175 
     176          $media_img_t_size = abs((integer) $_POST['media_img_t_size']); 
     177          if ($media_img_t_size < 0) { $media_img_t_size = 100; } 
     178 
     179          $media_img_s_size = abs((integer) $_POST['media_img_s_size']); 
     180          if ($media_img_s_size < 0) { $media_img_s_size = 240; } 
     181 
     182          $media_img_m_size = abs((integer) $_POST['media_img_m_size']); 
     183          if ($media_img_m_size < 0) { $media_img_m_size = 448; } 
     184 
     185          $nb_post_for_home = abs((integer) $_POST['nb_post_for_home']); 
     186          if ($nb_post_for_home <= 1) { $nb_post_for_home = 1; } 
     187 
     188          $nb_post_per_page = abs((integer) $_POST['nb_post_per_page']); 
     189          if ($nb_post_per_page <= 1) { $nb_post_per_page = 1; } 
     190 
     191          $nb_post_per_feed = abs((integer) $_POST['nb_post_per_feed']); 
     192          if ($nb_post_per_feed <= 1) { $nb_post_per_feed = 1; } 
     193 
     194          $nb_comment_per_feed = abs((integer) $_POST['nb_comment_per_feed']); 
     195          if ($nb_comment_per_feed <= 1) { $nb_comment_per_feed = 1; } 
     196 
     197          try 
     198          { 
     199               if ($cur->blog_id != null && $cur->blog_id != $blog_id) { 
     200                    $rs = $core->getBlog($cur->blog_id); 
     201 
     202                    if ($rs) { 
     203                         throw new Exception(__('This blog ID is already used.')); 
     204                    } 
     205               } 
     206 
     207               # --BEHAVIOR-- adminBeforeBlogUpdate 
     208               $core->callBehavior('adminBeforeBlogUpdate',$cur,$blog_id); 
     209 
     210               if (!preg_match('/^[a-z]{2}(-[a-z]{2})?$/',$_POST['lang'])) { 
     211                    throw new Exception(__('Invalid language code')); 
     212               } 
     213 
     214               $core->updBlog($blog_id,$cur); 
     215 
     216               # --BEHAVIOR-- adminAfterBlogUpdate 
     217               $core->callBehavior('adminAfterBlogUpdate',$cur,$blog_id); 
     218 
     219               if ($cur->blog_id != null && $cur->blog_id != $blog_id) { 
     220                    if ($blog_id == $core->blog->id) { 
     221                         $core->setBlog($cur->blog_id); 
     222                         $_SESSION['sess_blog_id'] = $cur->blog_id; 
     223                         $blog_settings = $core->blog->settings; 
     224                    } else { 
     225                         $blog_settings = new dcSettings($core,$cur->blog_id); 
     226                    } 
     227 
     228                    $blog_id = $cur->blog_id; 
     229               } 
     230 
     231 
     232               $blog_settings->addNameSpace('system'); 
     233 
     234               $blog_settings->system->put('editor',$_POST['editor']); 
     235               $blog_settings->system->put('copyright_notice',$_POST['copyright_notice']); 
     236               $blog_settings->system->put('post_url_format',$_POST['post_url_format']); 
     237               $blog_settings->system->put('lang',$_POST['lang']); 
     238               $blog_settings->system->put('blog_timezone',$_POST['blog_timezone']); 
     239               $blog_settings->system->put('date_format',$_POST['date_format']); 
     240               $blog_settings->system->put('time_format',$_POST['time_format']); 
     241               $blog_settings->system->put('comments_ttl',abs((integer) $_POST['comments_ttl'])); 
     242               $blog_settings->system->put('trackbacks_ttl',abs((integer) $_POST['trackbacks_ttl'])); 
     243               $blog_settings->system->put('allow_comments',!empty($_POST['allow_comments'])); 
     244               $blog_settings->system->put('allow_trackbacks',!empty($_POST['allow_trackbacks'])); 
     245               $blog_settings->system->put('comments_pub',empty($_POST['comments_pub'])); 
     246               $blog_settings->system->put('trackbacks_pub',empty($_POST['trackbacks_pub'])); 
     247               $blog_settings->system->put('comments_nofollow',!empty($_POST['comments_nofollow'])); 
     248               $blog_settings->system->put('wiki_comments',!empty($_POST['wiki_comments'])); 
     249               $blog_settings->system->put('comment_preview_optional',!empty($_POST['comment_preview_optional'])); 
     250               $blog_settings->system->put('enable_xmlrpc',!empty($_POST['enable_xmlrpc'])); 
     251               $blog_settings->system->put('note_title_tag',$_POST['note_title_tag']); 
     252               $blog_settings->system->put('nb_post_for_home',$nb_post_for_home); 
     253               $blog_settings->system->put('nb_post_per_page',$nb_post_per_page); 
     254               $blog_settings->system->put('use_smilies',!empty($_POST['use_smilies'])); 
     255               $blog_settings->system->put('inc_subcats',!empty($_POST['inc_subcats'])); 
     256               $blog_settings->system->put('media_img_t_size',$media_img_t_size); 
     257               $blog_settings->system->put('media_img_s_size',$media_img_s_size); 
     258               $blog_settings->system->put('media_img_m_size',$media_img_m_size); 
     259               $blog_settings->system->put('media_img_title_pattern',$_POST['media_img_title_pattern']); 
     260               $blog_settings->system->put('media_img_use_dto_first',!empty($_POST['media_img_use_dto_first'])); 
     261               $blog_settings->system->put('media_img_no_date_alone',!empty($_POST['media_img_no_date_alone'])); 
     262               $blog_settings->system->put('media_img_default_size',$_POST['media_img_default_size']); 
     263               $blog_settings->system->put('media_img_default_alignment',$_POST['media_img_default_alignment']); 
     264               $blog_settings->system->put('media_img_default_link',!empty($_POST['media_img_default_link'])); 
     265               $blog_settings->system->put('nb_post_per_feed',$nb_post_per_feed); 
     266               $blog_settings->system->put('nb_comment_per_feed',$nb_comment_per_feed); 
     267               $blog_settings->system->put('short_feed_items',!empty($_POST['short_feed_items'])); 
     268               if (isset($_POST['robots_policy'])) { 
     269                    $blog_settings->system->put('robots_policy',$_POST['robots_policy']); 
     270               } 
     271               $blog_settings->system->put('jquery_version',$_POST['jquery_version']); 
     272               $blog_settings->system->put('prevents_clickjacking',!empty($_POST['prevents_clickjacking'])); 
     273 
     274               # --BEHAVIOR-- adminBeforeBlogSettingsUpdate 
     275               $core->callBehavior('adminBeforeBlogSettingsUpdate',$blog_settings); 
     276 
     277               if ($core->auth->isSuperAdmin() && in_array($_POST['url_scan'],$url_scan_combo)) { 
     278                    $blog_settings->system->put('url_scan',$_POST['url_scan']); 
     279               } 
     280               dcPage::addSuccessNotice(__('Blog has been successfully updated.')); 
     281 
     282               http::redirect(sprintf($redir,$blog_id)); 
     283               exit; 
     284          } 
     285          catch (Exception $e) 
     286          { 
     287               $core->error->add($e->getMessage()); 
     288          } 
     289     } elseif (isset($_POST['enable']) && is_array($_POST['enable'])) { 
     290          $blog_settings->addNamespace('pluginsactivated'); 
     291          foreach ($_POST['enable'] as $id => $desc) { 
     292               if ($core->plugins->moduleExists($id) &&  
     293                    ($blog_settings->pluginsactivated->get($id) !== null) && 
     294                    $core->plugins->moduleInfo($id,'perblog_activation')) { 
     295                    $blog_settings->pluginsactivated->put($id,true); 
     296               } 
     297          } 
     298          dcPage::addSuccessNotice(__('Plugin successfully enabled.')); 
     299          http::redirect(sprintf($redir,$blog_id)."#plugins"); 
     300          exit; 
     301     } elseif (isset($_POST['disable']) && is_array($_POST['disable'])) { 
     302          $blog_settings->addNamespace('pluginsactivated'); 
     303          foreach ($_POST['disable'] as $id => $desc) { 
     304               if ($core->plugins->moduleExists($id) &&  
     305                    ($blog_settings->pluginsactivated->get($id) !== null) && 
     306                    $core->plugins->moduleInfo($id,'perblog_activation')) { 
     307                    $blog_settings->pluginsactivated->put($id,false); 
     308               } 
     309          } 
     310          dcPage::addSuccessNotice(__('Plugin successfully disabled.')); 
     311          http::redirect(sprintf($redir,$blog_id)."#plugins"); 
     312          exit; 
    286313     } 
    287314} 
     
    340367 
    341368     echo 
    342      '<div class="fieldset"><h4>'.__('Blog details').'</h4>'. 
    343      $core->formNonce(); 
     369     '<div class="fieldset"><h4>'.__('Blog details').'</h4>'; 
    344370 
    345371     if ($core->auth->isSuperAdmin()) 
     
    645671 
    646672     echo 
    647      '<p><input type="submit" accesskey="s" value="'.__('Save').'" />'. 
     673     '<p><input type="submit" accesskey="s" name="save_blog" value="'.__('Save').'" />'. 
    648674     (!$standalone ? form::hidden('id',$blog_id) : ''). 
     675     $core->formNonce(). 
    649676     '</p>'. 
    650677     '</form>'; 
     
    773800     } 
    774801 
     802 
    775803     echo '</div>'; 
     804 
     805     # 
     806     # Per-blog activated plugins 
     807     $plugins = $core->plugins->getModules(); 
     808     $plugins_activation = array(); 
     809 
     810     foreach ($plugins as $id => $p) { 
     811          if ($core->plugins->moduleInfo($id,'perblog_activation')) { 
     812               $plugins_activation[$id]=$core->blog->settings->pluginsactivated->get($id); 
     813          } 
     814     } 
     815     echo 
     816     '<div class="multi-part" id="plugins" title="'.__('Plugins').'">'. 
     817     '<h3 class="out-of-screen-if-js">'.__('Plugins').'</h3>'. 
     818     '<div class="fieldset"><h4>'.__('Plugins activation for this blog').'</h4>'; 
     819     if (!count($plugins_activation)) { 
     820          echo '<p>'.__('No per-blog plugins configured for this blog').'</p>'; 
     821     } else { 
     822          echo 
     823               '<form action="'.$core->adminurl->getBase('admin.blog.pref').'" method="POST">'. 
     824               '<table><thead>'. 
     825               '<th class="first nowrap">'.__('Plugin').'</th>'. 
     826               '<th class="first nowrap maximal">'.__('Description').'</th>'. 
     827               '<th class="nowrap">'.__('Status').'</th>'. 
     828               '<th class="minimal nowrap">'.__('Action').'</th>'. 
     829               '</thead>'; 
     830          foreach ($plugins_activation as $id => $enabled) { 
     831               echo  
     832                    '<tr><td>'.$core->plugins->moduleInfo($id,'name').'</td>'. 
     833                    '<td>'.$core->plugins->moduleInfo($id,'desc').'</td>'; 
     834 
     835               if ($enabled) { 
     836                    echo 
     837                         '<td>'.__('Enabled').'</td>'. 
     838                         '<td><input type="submit" class="reset" name="disable['.$id.']" value="'.__('Disable for this blog').'"/></td>'; 
     839               } else { 
     840                    echo 
     841                         '<td>'.__('Disabled').'</td>'. 
     842                         '<td><input type="submit" name="enable['.$id.']" value="'.__('Enable for this blog').'"/></td>'; 
     843               } 
     844               '</tr>'; 
     845          } 
     846 
     847          echo  
     848               '</table>'. 
     849               '<p><input type="submit" accesskey="s" name="save_plugins" value="'.__('Save').'" />'. 
     850                    (!$standalone ? form::hidden('id',$blog_id) : ''). 
     851                    $core->formNonce(). 
     852                    $core->adminurl->getHiddenFormFields('admin.blog'); 
     853               '</p>'. 
     854               '</form>'; 
     855     } 
     856     echo '</div>'; 
     857     echo '</div>'; 
     858 
    776859} 
    777860 
  • inc/core/class.dc.modules.php

    r2708 r2900  
    117117          foreach ($this->modules as $id => $m) 
    118118          { 
     119               if ($m['perblog_activation'] && !$this->core->blog->settings->pluginsactivated->get($id)) { 
     120                    continue; 
     121               } 
    119122               if (file_exists($m['root'].'/_prepend.php')) 
    120123               { 
     
    184187                    'priority' => 1000, 
    185188                    'standalone_config' => false, 
    186                     'type' => null 
     189                    'type' => null, 
     190                    'perblog_activation' => false 
    187191               ), $properties 
    188192          ); 
     
    207211                    return; 
    208212               } 
     213          } 
     214 
     215          $this->core->blog->settings->addNamespace("pluginsactivated"); 
     216          # Per-blog activation settings 
     217          if ($properties['perblog_activation'] && ($this->core->blog->settings->pluginsactivated->get($this->id) === null)) { 
     218               $this->core->blog->settings->pluginsactivated->put($this->id,false,"boolean",sprintf(__('plugin "%s" activated'),$this->id),true,true); 
    209219          } 
    210220 
  • plugins/pages/_define.php

    r2662 r2900  
    1818     /* Version */       '1.4', 
    1919     array( 
    20           'permissions' =>    'contentadmin,pages', 
    21           'priority' =>  999, 
    22           'type'         =>        'plugin' 
     20          'permissions'        =>  'contentadmin,pages', 
     21          'priority'           =>  999, 
     22          'type'               =>  'plugin', 
     23          'perblog_activation' => true 
    2324     ) 
    2425); 
Note: See TracChangeset for help on using the changeset viewer.

Sites map