Ejemplo n.º 1
0
 /**
  *
  * Generates HTML with drop-down roles menu
  * and a Shred button if current Viewer has necessary
  * permissions
  *
  * @param Registry $Registry
  * @param User $User user whose profile is being viewed now
  * @return string html fragment with Form and button
  */
 public static function getHtml(Registry $Registry, User $User)
 {
     $oACL = $Registry->Acl;
     $options = '';
     $shredButton = '';
     $token = '';
     $uid = $User->getUid();
     $role = $Registry->Viewer->getRoleId();
     d('role: ' . $role);
     if ($oACL->isAllowed($role, null, 'change_user_role')) {
         d('change_user_role is allowed');
         $userRole = $User->getRoleId();
         $roles = $oACL->getRegisteredRoles();
         $token = Form::generateToken();
         foreach ($roles as $roleName => $val) {
             $selected = $roleName === $userRole ? ' selected' : '';
             $options .= "\n" . vsprintf('<option value="%1$s"%2$s>%1$s</option>', array($roleName, $selected));
         }
     }
     if ($oACL->isAllowed($role, null, 'shred_user')) {
         d('getting shred button');
         $shredButton = '<div class="fl cb"><input type="button" class="ajax btn_shred rounded4" value="@@Shred User@@" id="shred' . $uid . '"></div>';
     }
     if (empty($options) && empty($shredButton)) {
         return '';
     }
     return \tplSelectrole::parse(array($token, $uid, $options, $shredButton), false);
 }
Ejemplo n.º 2
0
 /**
  * If User has permission to upload images
  * based on user group and reputation
  * and if Image upload is not disabled in !config.ini
  * by the way of setting IMAGE_UPLOAD_FILE_SIZE to 0
  * then return the value of IMAGE_UPLOAD_FILE_SIZE
  * OR false if user should not be allowed to upload image
  *
  * @static
  *
  * @param \Lampcms\Registry $Registry
  * @param \Lampcms\User     $User
  *
  * @throws \Lampcms\AccessException is User group is not allowed to upload images
  * or if user does not have enough reputation to upload images
  *
  * @return mixed false | int max upload size in Megabytes
  */
 public static function getMaxFileSize(\Lampcms\Registry $Registry, \Lampcms\User $User)
 {
     $ImgUploadOptions = $Registry->Ini->getSection('EDITOR');
     $maxSize = $ImgUploadOptions['IMAGE_UPLOAD_FILE_SIZE'];
     if (empty($maxSize)) {
         throw new AccessException('@@Image upload is disabled by administrator@@');
     }
     $Acl = $Registry->Acl;
     if (!$Acl->isAllowed($User->getRoleId(), null, 'upload_image')) {
         throw new AccessException('@@You do not have permissions to upload images@@');
     }
     $minReputation = (int) $ImgUploadOptions['IMAGE_UPLOAD_MIN_REPUTATION'];
     $rep = $User->getReputation();
     if ($rep < $minReputation) {
         throw new AccessException('@@You do not have enough reputation points to upload images@@');
     }
     return $maxSize;
 }