b2evolution PHP Cross Reference Blogging Systems

Source: /inc/collections/views/_coll_perm_view.funcs.php - 271 lines - 8999 bytes - Summary - Text - Print

Description: This file implements the advanced collection user and group perms form functions. This file is part of the evoCore framework - {@link http://evocore.net/}

   1  <?php
   2  /**

   3   * This file implements the advanced collection user and group perms form functions.

   4   * 

   5   * This file is part of the evoCore framework - {@link http://evocore.net/}

   6   * 

   7   * @copyright (c)2003-2014 by Francois Planque - {@link http://fplanque.com/}

   8   * 

   9   * @package evocore

  10   * 

  11   * @version $Id: $

  12   */
  13  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  14  
  15  
  16  /**

  17   * Filter collectiion user/group perms list by user/group

  18   * 

  19   * @param object $Form

  20   */
  21  function filter_collobjectlist( & $Form )
  22  {
  23      static $count = 0;
  24  
  25      $count++;
  26      $Form->switch_layout( 'blockspan' );
  27      // TODO: javascript update other input fields (for other layouts):

  28      $Form->text( 'keywords'.$count, get_param('keywords'.$count), 20, T_('Keywords'), T_('Separate with space'), 50 );
  29      $Form->switch_layout( NULL ); // Restor previously saved

  30  }
  31  
  32  
  33  /**

  34   * Get the ID which correspond to table prefix

  35   * @param string prefix

  36   * @return string row id field name

  37   */
  38  function get_id_coll_from_prefix( $prefix )
  39  {
  40      switch( $prefix )
  41      {
  42          case 'bloguser_':
  43              return 'user_ID';
  44  
  45          case 'bloggroup_':
  46              return 'grp_ID';
  47  
  48          default:
  49              debug_die('Invalid table prefix on advanced collection perms form!');
  50      }
  51  }
  52  
  53  
  54  /**

  55   * Get collection perm checkbox

  56   * 

  57   * @param object the db row

  58   * @param string the prefix of the db row: 'bloguser_' or 'bloggroup_'

  59   * @param string permission name

  60   * @param string checkbox title

  61   * @param string the Id of the checkbox item

  62   */
  63  function coll_perm_checkbox( $row, $prefix, $perm, $title, $id = NULL )
  64  {
  65      global $permission_to_change_admin;
  66  
  67      $row_id_coll = get_id_coll_from_prefix( $prefix );
  68  
  69      $r = '<input type="checkbox"';
  70      if( !empty($id) )
  71      {
  72          $r .= ' id="'.$id.'"';
  73      }
  74      $r .= ' name="blog_'.$perm.'_'.$row->{$row_id_coll}.'"';
  75      if( !empty( $row->{$prefix.$perm} ) )
  76      {
  77           $r .= ' checked="checked"';
  78      }
  79      if( ! $permission_to_change_admin
  80              && ($row->{$prefix.'perm_admin'} || $perm == 'perm_admin' ) )
  81      { // No permission to touch nOR create admins
  82           $r .= ' disabled="disabled"';
  83      }
  84      $r .= ' class="checkbox" value="1" title="'.$title.'" />';
  85      return $r;
  86  }
  87  
  88  
  89  /**

  90   * Check if the current comment statuses perm value contains at least as much perms as anonymous users have

  91   * If anonymous users have no permission to post comments, then this will automatically return true;

  92   *

  93   * @param integer statuses perm value for the checked user/group

  94   * @return boolean true if the minimum required permission is granted, false otherwise

  95   */
  96  function check_default_create_comment_perm( $perm_statuses )
  97  {
  98      global $edited_Blog;
  99  
 100      if( $edited_Blog->get_setting( 'allow_comments' ) != 'any' )
 101      { // Anonymous users are not allowed to post comments
 102          return true;
 103      }
 104  
 105      $default_status = $edited_Blog->get_setting( 'new_feedback_status' );
 106      $default_status_perm_value = get_status_permvalue( $default_status );
 107      if( $perm_statuses & $default_status_perm_value )
 108      { // Posting comments with default status is allowed
 109          return true;
 110      }
 111  
 112      $published_perm_value = get_status_permvalue( 'published' );
 113      // Remove hihger perm vlaues then 'published' status perm value ( 'deprecated' and 'redirected' values are not important in this context )

 114      $perm_statuses = $perm_statuses & ( $published_perm_value + $published_perm_value - 1 );
 115      $review_perm_value = get_status_permvalue( 'review' );
 116      if( ( $perm_statuses > $default_status_perm_value ) || ( ( $default_status == 'draft' ) && (  $perm_statuses & $review_perm_value ) ) )
 117      {
 118          return true;
 119      }
 120  
 121      return false;
 122  }
 123  
 124  
 125  /**

 126   * Get perm post/comment statuses for a user or group

 127   * 

 128   * @param object db row

 129   * @param string the prefix of the db row: 'bloguser_' or 'bloggroup_'

 130   * @param string current perm status

 131   * @param string the title of the chekbox

 132   * @param string the type of the permission: 'post' or 'comment'

 133   */
 134  function coll_perm_status_checkbox( $row, $prefix, $perm_status, $title, $type )
 135  {
 136      global $edited_Blog, $permission_to_change_admin;
 137  
 138      $row_id_coll = get_id_coll_from_prefix( $prefix );
 139      $default_status = NULL;
 140  
 141      switch( $type )
 142      {
 143          case 'post':
 144              $perm_statuses = 'perm_poststatuses';
 145              $type_param = '';
 146              break;
 147  
 148          case 'comment':
 149              $perm_statuses = 'perm_cmtstatuses';
 150              if( ! check_default_create_comment_perm( $row->{$perm_statuses} ) )
 151              { // Doesn't have at least as high comment create permission as anonymous users have
 152                  $default_status = $edited_Blog->get_setting( 'new_feedback_status' );
 153              }
 154              $type_param = 'cmt_';
 155              break;
 156  
 157          default:
 158              debug_die('Invalid $type param on advanced perms form!');
 159      }
 160  
 161      $r = '<input type="checkbox"';
 162      if( !empty($id) )
 163      {
 164          $r .= ' id="'.$id.'"';
 165      }
 166      $r .= ' name="blog_perm_'.$perm_status.'_'.$type_param.$row->{$row_id_coll}.'"';
 167      if( get_status_permvalue( $perm_status ) & $row->{$perm_statuses} )
 168      {
 169           $r .= ' checked="checked"';
 170      }
 171      if( ! $permission_to_change_admin && $row->{$prefix.'perm_admin'} )
 172      {
 173           $r .= ' disabled="disabled"';
 174      }
 175      if( $perm_status == $default_status )
 176      {
 177          $title .= "\n".T_('Note: Anonymous users may create comments with this status. You will probably want to give the same permission to this user/group.');
 178      }
 179      $r .= ' class="checkbox" value="1" title="'.$title.'" />';
 180      if( $perm_status == $default_status )
 181      { // This is the default comment status checkbox, and user has no permission to create comment with this status ( like anonymous users ) or a higher status
 182          $r = '<span class="red-bordered-checkbox">'.$r.'</span>';
 183      }
 184      return $r;
 185  }
 186  
 187  
 188  /**

 189   * Get the post edit permission select input for user/group

 190   * 

 191   * @param object db row

 192   * @param string the prefix of the db row: 'bloguser_' or 'bloggroup_'

 193   */
 194  function coll_perm_edit( $row, $prefix )
 195  {
 196      global $permission_to_change_admin;
 197  
 198      $row_id_coll = get_id_coll_from_prefix( $prefix );
 199  
 200      $r = '<select id="blog_perm_edit_'.$row->{$row_id_coll}.'" name="blog_perm_edit_'.$row->{$row_id_coll}.'"';
 201      if( ! $permission_to_change_admin && $row->{$prefix.'perm_admin'} )
 202      {
 203           $r .= ' disabled="disabled"';
 204      }
 205      $r .= ' >';
 206      $perm_edit_value = $row->{$prefix.'perm_edit'};
 207      $r .= '<option value="no" '.( $perm_edit_value == 'no' ? 'selected="selected"' : '' ).'>No editing</option>';
 208      $r .= '<option value="own" '.( $perm_edit_value == 'own' ? 'selected="selected"' : '' ).'>Own posts</option>';
 209      $r .= '<option value="lt" '.( $perm_edit_value == 'lt' ? 'selected="selected"' : '' ).'>&lt; own level</option>';
 210      $r .= '<option value="le" '.( $perm_edit_value == 'le' ? 'selected="selected"' : '' ).'>&le; own level</option>';
 211      $r .= '<option value="all" '.( $perm_edit_value == 'all' ? 'selected="selected"' : '' ).'>All posts</option>';
 212      $r .= '</select>';
 213      return $r;
 214  }
 215  
 216  
 217  /**

 218   * Get the comment edit permission select input for user/group

 219   * 

 220   * @param object db row

 221   * @param string the prefix of the db row: 'bloguser_' or 'bloggroup_'

 222   */
 223  function coll_perm_edit_cmt( $row, $prefix )
 224  {
 225      global $permission_to_change_admin;
 226  
 227      $row_id_coll = get_id_coll_from_prefix( $prefix );
 228  
 229      $r = '<select id="blog_perm_edit_cmt'.$row->{$row_id_coll}.'" name="blog_perm_edit_cmt_'.$row->{$row_id_coll}.'"';
 230      if( ! $permission_to_change_admin && $row->{$prefix.'perm_admin'} )
 231      {
 232           $r .= ' disabled="disabled"';
 233      }
 234      $perm_edit_cmt_value = $row->{$prefix.'perm_edit_cmt'};
 235      $r .= ' >';
 236      $r .= '<option value="no" '.( $perm_edit_cmt_value == 'no' ? 'selected="selected"' : '' ).'>No editing</option>';
 237      $r .= '<option value="own" '.( $perm_edit_cmt_value == 'own' ? 'selected="selected"' : '' ).'>Own cmts</option>';
 238      $r .= '<option value="anon" '.( $perm_edit_cmt_value == 'anon' ? 'selected="selected"' : '' ).'>Annon cmts</option>';
 239      $r .= '<option value="lt" '.( $perm_edit_cmt_value == 'lt' ? 'selected="selected"' : '' ).'>&lt; own level</option>';
 240      $r .= '<option value="le" '.( $perm_edit_cmt_value == 'le' ? 'selected="selected"' : '' ).'>&le; own level</option>';
 241      $r .= '<option value="all" '.( $perm_edit_cmt_value == 'all' ? 'selected="selected"' : '' ).'>All cmts</option>';
 242      $r .= '</select>';
 243      return $r;
 244  }
 245  
 246  
 247  /**

 248   * Return link to check/uncheck all permission in a row

 249   * 

 250   * @param object db row

 251   * @param string the prefix of the db row: 'bloguser_' or 'bloggroup_'

 252   * @return string the link element

 253   */
 254  function perm_check_all( $row, $prefix )
 255  {
 256      global $permission_to_change_admin;
 257  
 258      $row_id_coll = get_id_coll_from_prefix( $prefix );
 259  
 260      if( ! $permission_to_change_admin && $row->{$prefix.'perm_admin'} )
 261      {
 262           return '&nbsp;';
 263      }
 264  
 265      $row_id_value = $row->{$row_id_coll};
 266      return '<a href="javascript:toggleall_perm(document.getElementById(\'blogperm_checkchanges\'), '.$row_id_value.' );setcheckallspan('.$row_id_value.');" title="'.TS_('(un)selects all checkboxes using Javascript').'">
 267                  <span id="checkallspan_'.$row_id_value.'">'.TS_('(un)check all').'</span>
 268              </a>';
 269  }
 270  
 271  ?>

title

Description

title

Description

title

Description

title

title

Body