Example #1
0
 public function view($itemID)
 {
     parent::view($itemID);
     $blogPosts = $this->view->getData('Tag')->BlogPosts;
     if (!$this->app->getCurrentUser()->hasRole('ADMIN')) {
         for ($i = 0; $i < count($blogPosts); $i++) {
             if (is_null($blogPosts[$i]->Published)) {
                 unset($blogPosts[$i]);
             }
         }
     }
     $this->view->setData('BlogPostList', $blogPosts);
     $this->view->setData('PreviewSize', 1);
 }
Example #2
0
 public function edit($itemID)
 {
     parent::edit($itemID);
     $users = $this->db->selectAll('User', 'ORDER BY FirstName, LastName');
     if (is_null($users)) {
         throw new DatabaseException('Error loading users.', 500);
     }
     $records = $this->db->fetchAll('SELECT UserID FROM User_Role WHERE RoleID = :RoleID', array('RoleID' => $this->view->getData('Role')->ID));
     if ($records === false) {
         throw new DatabaseException('Failed to retrieve role user IDs.', 500);
     }
     $itemUserIDs = array();
     foreach ($records as $record) {
         $itemUserIDs[] = $record['UserID'];
     }
     $this->view->setData(array('Users' => $users, 'RoleUserIDs' => $itemUserIDs));
 }
 public function view($itemID)
 {
     parent::view($itemID);
     $matchResult = preg_match('/<img\\s[^>]*src=[\'"]([^\'"]+)[\'"]/', $this->view->getData('BlogPost')->Body, $matches);
     if ($matchResult === false || $matchResult === 0) {
         $this->view->setData(array('ImageURL' => '', 'ImageWidth' => '', 'ImageHeight' => ''));
     } else {
         if (strpos($matches[1], 'http') === 0) {
             // Do not check dimensions of remote images. -- cwells
             $this->view->setData(array('ImageURL' => $matches[1], 'ImageWidth' => '', 'ImageHeight' => ''));
         } else {
             // Check the image dimensions. -- cwells
             $dimensions = getimagesize(preg_replace('/^(\\.\\.\\/\\.\\.)?/', '../public', $matches[1]));
             $this->view->setData(array('ImageURL' => preg_replace('/^(\\.\\.\\/\\.\\.)?/', PROTOCOL_HOST_PORT, $matches[1]), 'ImageWidth' => $dimensions[0], 'ImageHeight' => $dimensions[1]));
         }
     }
 }
Example #4
0
 public function save(array &$properties)
 {
     if (empty($properties) || !is_array($properties)) {
         throw new InvalidArgumentException('You must provide the values to update.', 400);
     }
     if (!empty($properties['SetPassword']) && $properties['SetPassword'] === 'yes') {
         $errorCode = 400;
         $errorMessage = '';
         if ($properties['Password'] !== $properties['ConfirmPassword']) {
             $errorMessage = 'Confirm Password must match Password.';
         } else {
             if (strlen($properties['Password']) < 10) {
                 $errorMessage = 'Password cannot be less than 10 characters long.';
             } else {
                 if (strlen($properties['Password']) > 100) {
                     $errorMessage = 'Password cannot be more than 100 characters long.';
                 } else {
                     // Create a User object just to generate the password hash. -- cwells
                     $user = new User($properties);
                     if (!$user->setPassword($properties['Password'])) {
                         $errorCode = 500;
                         $errorMessage = 'Failed to set the password. Please try again.';
                     }
                     $properties = $user->toArray();
                 }
             }
         }
         if (!empty($errorMessage)) {
             if (empty($properties[User::getPrimaryKeyName()])) {
                 $this->add($properties);
             } else {
                 $this->edit($properties);
             }
             $this->view->setStatus($errorMessage, $errorCode);
             return;
         }
     }
     // These are not actual properties on the User object. -- cwells
     unset($properties['SetPassword']);
     unset($properties['Password']);
     unset($properties['ConfirmPassword']);
     parent::save($properties);
 }