[ Index ]
 

Code source de LifeType 1.2.4

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/class/template/smarty/plugins/ -> block.check_perms.php (source)

   1  <?php
   2  
   3  /**
   4   * Function used in the admin interface as a shorthand to check whether the user has the given permission
   5   *
   6   * @param perm
   7   * @param user
   8   * @param blog
   9   */
  10  function smarty_block_check_perms($params, $content, &$smarty)    
  11  {
  12      
  13      if( isset( $content )) {
  14          // fetch the user
  15          if( isset( $params["user"]))
  16              $user = $params["user"];
  17          else {
  18              // see if we can load the user from the smarty context
  19              if( isset( $smarty->_tpl_vars["user"] ))
  20                  $user = $smarty->_tpl_vars["user"];
  21              else
  22                  $smarty->trigger_error( "Cannot load a user" );            
  23          }
  24      
  25          // fetch the blog
  26          if( isset( $params["blog"]))
  27              $blog = $params["blog"];
  28          else {
  29              // see if we can load the user from the smarty context
  30              if( isset( $smarty->_tpl_vars["blog"] ))
  31                  $blog = $smarty->_tpl_vars["blog"];
  32              else
  33                  $smarty->trigger_error( "Cannot load a blog" );            
  34          }
  35      
  36          // fetch the permission name
  37          if( isset( $params["perm"] )) {
  38      
  39              $perm = $params["perm"];
  40  
  41              // if the user is an admin, he should be allowed
  42              if( $user->isSiteAdmin())
  43                  return $content;
  44      
  45              // if the user is the blog owner, he should be allowed
  46              if( $user->getId() == $blog->getOwnerId())
  47                  return $content;
  48                  
  49              $blogId = $blog->getId();
  50          }
  51          elseif( isset( $params["adminperm"] )) {
  52              $perm = $params["adminperm"];
  53              $blogId = 0;
  54          }
  55          else {
  56              $smarty->trigger_error( "'perm' and 'adminperm' parameters are both missing!" );            
  57          }
  58          
  59          // check the permission
  60          if( $user->hasPermissionByName( $perm, $blogId ))
  61              return $content;
  62              
  63          return "";
  64      }
  65  }
  66  ?>


Généré le : Mon Nov 26 21:04:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics