Example #1
0
 /**
  *
  * Edit Album form
  *
  */
 public function init()
 {
     $cname = explode('_', get_class());
     $this->preInit(end($cname));
     // use template file
     $this->setDecorators(array(array('ViewScript', array('viewScript' => 'forms/EditAlbum.phtml'))));
     // get group from database
     $request = Zend_Controller_Front::getInstance()->getRequest();
     $album_id = $request->getParam('id');
     $Albums = new Application_Model_Albums();
     $album = $Albums->getAlbum($album_id);
     $username_minchars = Zend_Registry::get('config')->get('username_minchars');
     $username_maxchars = Zend_Registry::get('config')->get('username_maxchars');
     // fields
     $id = new Zend_Form_Element_Hidden('id');
     $id->setValue($album);
     $album_name = new Zend_Form_Element_Text('album_name');
     $album_name->setDecorators(array('ViewHelper', 'Errors'))->addFilter('StringTrim')->addValidator('alnum', false, array('allowWhiteSpace' => true))->addValidator('stringLength', false, array($username_minchars, $username_maxchars))->setErrorMessages(array(sprintf($this->translator->translate('Please choose a valid name between %d and %d characters'), $username_minchars, $username_maxchars)))->setLabel($this->translator->translate('Album Name'))->setRequired(true)->setValue($album['name'])->setAttrib('class', 'form-control');
     $description = new Zend_Form_Element_Textarea('description');
     $description->setDecorators(array('ViewHelper', 'Errors'))->setAttrib('COLS', '')->setAttrib('ROWS', '4')->addFilter('StripTags')->setValue($album['description'])->setLabel($this->translator->translate('About this album'))->setAttrib('class', 'form-control');
     $submit = new Zend_Form_Element_Submit('formsubmit');
     $submit->setDecorators(array('ViewHelper'))->setLabel($this->translator->translate('Save'))->setAttrib('class', 'submit btn btn-default');
     $this->addElements(array($id, $album_name, $description, $submit));
     $this->postInit();
 }
 /**
  * move image to album (via ajax)
  */
 public function moveimageAction()
 {
     $Images = new Application_Model_Images();
     $Albums = new Application_Model_Albums();
     $current_user = Zend_Auth::getInstance()->getIdentity();
     $request = $this->getRequest();
     $image_id = $request->getParam('resource_id');
     $album_id = $request->getParam('album_id');
     // do some basic checks
     if (!$image_id || !$album_id) {
         $this->getHelper('json')->sendJson(false);
     }
     // see if this is a delete
     if ($album_id == 'trash') {
         $ret = $Images->deleteImage($image_id, 'posts');
         $this->getHelper('json')->sendJson($ret);
         return;
     }
     // see if this is "set as profile picture"
     if ($album_id == 'avatar' || $album_id == 'cover') {
         $image = $Images->getImage($image_id);
         $file_name = $image['data']['file_name'];
         $tmp_file_name = 'setas_' . $file_name;
         $Storage = new Application_Model_Storage();
         $StorageAdapter = $Storage->getAdapter();
         $StorageAdapter->getFileFromStorage($file_name, $tmp_file_name, 'posts');
         // save params to session and redirect to edit page
         $session = new Zend_Session_Namespace('Default');
         $pass_params = array('tmp_image' => $tmp_file_name, 'image_type' => $album_id, 'callback' => '', 'profile_name' => $current_user->name);
         $session->pass_params = $pass_params;
         $this->getHelper('json')->sendJson(true);
         return;
     }
     $album = $Albums->getAlbum($album_id);
     // see if this album belongs to the current user
     if (!isset($album['user_id']) || $album['user_id'] != $current_user->id) {
         $this->getHelper('json')->sendJson(false);
     }
     $ret = $Images->updateField($image_id, 'album_id', $album_id);
     if ($album['name']) {
         $ret = $album['name'];
     }
     $this->getHelper('json')->sendJson($ret);
 }
Example #3
0
 /**
  * Permanently remove all profile's associated data
  */
 public function removeAllProfilesData($profile_id)
 {
     // check if exists
     $profile = $this->getProfileByField('id', $profile_id);
     if (!$profile) {
         return false;
     }
     $Images = new Application_Model_Images();
     $Images->removeUsersImages($profile_id);
     $Albums = new Application_Model_Albums();
     $Albums->deleteAlbums($profile_id);
     $Comments = new Application_Model_Comments();
     $Comments->deleteComments($profile_id);
     $Connections = new Application_Model_Connections();
     $Connections->removeUsersConnections($profile_id);
     $Likes = new Application_Model_Likes();
     $Likes->removeUsersLikes($profile_id);
     $Notifications = new Application_Model_Notifications();
     $Notifications->removeUsersNotifications($profile_id);
     $Reports = new Application_Model_Reports();
     $Reports->removeUsersReports($profile_id);
     $Posts = new Application_Model_Posts();
     $Posts->removeUsersPosts($profile_id);
     $Messages = new Application_Model_Messages();
     $Messages->removeUsersMessages($profile_id);
     $ProfilesMeta = new Application_Model_ProfilesMeta();
     $ProfilesMeta->removeMetaForProfile($profile_id);
     return true;
 }
 /**
  * Delete album (via ajax)
  */
 public function deletealbumAction()
 {
     $request = $this->getRequest();
     $album_id = $request->getParam('album_id');
     $Albums = new Application_Model_Albums();
     $ret = $Albums->deleteAlbum($album_id);
     $this->getHelper('json')->sendJson($ret);
 }
 /**
  * Receive uploaded files (ajax/blueimp)
  */
 public function receivefileAction()
 {
     $ret = Zend_Registry::get('Zend_Translate')->translate('Server-side error');
     if ($this->getRequest()->isPost()) {
         $Images = new Application_Model_Images();
         $adapter = new Zend_File_Transfer_Adapter_Http();
         $adapter->addValidator('Extension', false, 'jpg,jpeg,png,gif');
         $files = $adapter->getFileInfo();
         $receive_to = $this->getRequest()->getParam('to');
         $form_unique_key = (int) $this->getRequest()->getParam('form_unique_key');
         $current_user_id = Zend_Auth::getInstance()->getIdentity()->id;
         $current_user_role = Zend_Auth::getInstance()->getIdentity()->role;
         foreach ($files as $file => $info) {
             // file uploaded & is valid
             if (!$adapter->isUploaded($file)) {
                 continue;
             }
             if (!$adapter->isValid($file)) {
                 continue;
             }
             // check max file size
             if ($info['size'] > Zend_Registry::get('config')->get('max_file_upload_size')) {
                 continue;
             }
             $filename = $adapter->getFileName($file);
             $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
             $fileinfo = $adapter->getFileInfo($file);
             $filesize = $fileinfo[$file]['size'];
             $profilename = Zend_Auth::getInstance()->getIdentity()->name;
             $randomstring = Application_Plugin_Common::getRandomString();
             // generate tmp filename
             $tmp_filename = 'post_' . $profilename . '_' . $form_unique_key . '_' . $randomstring . '.' . $extension;
             $tmp_filename_full = TMP_PATH . '/' . $tmp_filename;
             // set to rename uploaded file upon receiving to tmp folder
             $adapter->setDestination(TMP_PATH);
             $adapter->addFilter('rename', $tmp_filename_full);
             // receive the files into the tmp directory, must have
             $adapter->receive($file);
             // check if valid image
             if (!Application_Plugin_ImageLib::isValidImage($tmp_filename_full)) {
                 unlink($tmp_filename_full);
                 continue;
             }
             // check storage limits
             $max_files_per_user = 0 + Zend_Registry::get('config')->get('max_files_per_user');
             $max_storage_per_user = 0 + Zend_Registry::get('config')->get('max_storage_per_user');
             if ($current_user_role == 'user' && ($max_files_per_user || $max_storage_per_user)) {
                 $storage_usage = $Images->getStorageUsage($current_user_id);
                 if ($max_files_per_user && $storage_usage['image_count'] > $max_files_per_user || $max_storage_per_user && $storage_usage['image_size'] > $max_storage_per_user) {
                     $ret = Zend_Registry::get('Zend_Translate')->translate('Storage limits reached');
                     unlink($tmp_filename_full);
                     continue;
                 }
             }
             if ($receive_to !== 'tmp') {
                 // receive to album, check if user is an album owner
                 if ($receive_to > 0) {
                     $Albums = new Application_Model_Albums();
                     $album = $Albums->getAlbum($receive_to);
                     // exit on wrong album
                     if (!$album || $album['user_id'] != $current_user_id) {
                         $this->_helper->json(false);
                         return;
                     }
                 }
                 $Storage = new Application_Model_Storage();
                 $StorageAdapter = $Storage->getAdapter();
                 $original_filename = '';
                 if (Zend_Registry::get('config')->get('resample_images')) {
                     Application_Plugin_ImageLib::resample(TMP_PATH . '/' . $tmp_filename, TMP_PATH . '/thumb_' . $tmp_filename);
                     $image_filename = $StorageAdapter->moveFileToStorage('thumb_' . $tmp_filename, 'posts');
                     if (Zend_Registry::get('config')->get('keep_original')) {
                         $original_filename = $StorageAdapter->moveFileToStorage($tmp_filename, 'posts');
                     } else {
                         $original_filename = '';
                         unlink(TMP_PATH . '/' . $tmp_filename);
                         // clean up
                     }
                 } else {
                     $image_filename = $StorageAdapter->moveFileToStorage($tmp_filename, 'posts');
                 }
                 if ($image_filename) {
                     $ret = $Images->addImage($image_filename, $filesize, $current_user_id, $current_user_id, 0, $receive_to, $original_filename);
                 }
             }
             $ret = true;
         }
     }
     $this->_helper->json($ret);
 }
 /**
  * get lightbox data (via ajax)
  */
 public function getlightboxdataAction()
 {
     $Comments = new Application_Model_Comments();
     $Images = new Application_Model_Images();
     $Likes = new Application_Model_Likes();
     $Reports = new Application_Model_Reports();
     $Albums = new Application_Model_Albums();
     $add_comment_form = new Application_Form_AddComment();
     $request = $this->getRequest();
     $resource_id = $request->getParam('resource_id', 0);
     $context = $request->getParam('context');
     $image = $Images->getImage($resource_id, $context);
     if (!$image) {
         $this->getHelper('json')->sendJson(false);
         return;
     }
     $resource_type = 'image';
     $this->view->resource_type = $resource_type;
     $this->view->resource_id = $resource_id;
     $this->view->context = $context;
     $dropdown_options = array();
     $this->view->can_rotate = false;
     if (Zend_Auth::getInstance()->hasIdentity()) {
         // if owner is viewing, add albums for moving
         if ($image['data']['owner_id'] == Zend_Auth::getInstance()->getIdentity()->id) {
             $albums = $Albums->getAlbums(Zend_Auth::getInstance()->getIdentity()->id, false);
             if (!empty($albums)) {
                 foreach ($albums as $album) {
                     $dropdown_options[] = array('id' => $album['id'], 'name' => Zend_Registry::get('Zend_Translate')->translate('Move to ') . $album['name']);
                 }
             }
         }
         // add move to cover / profile options
         if (!empty($dropdown_options)) {
             $dropdown_options[] = array('id' => 'divider');
         }
         $dropdown_options[] = array('id' => 'avatar', 'name' => Zend_Registry::get('Zend_Translate')->translate('Set as profile picture'));
         $dropdown_options[] = array('id' => 'cover', 'name' => Zend_Registry::get('Zend_Translate')->translate('Set as cover picture'));
         // if owner, admin or reviewer - add trash link
         if ($image['data']['uploaded_by'] == Zend_Auth::getInstance()->getIdentity()->id || Zend_Auth::getInstance()->getIdentity()->role == 'admin' || Zend_Auth::getInstance()->getIdentity()->role == 'reviewer') {
             // add trash
             $dropdown_options[] = array('id' => 'divider');
             $dropdown_options[] = array('id' => 'trash', 'name' => Zend_Registry::get('Zend_Translate')->translate('Delete Image'));
         }
         // if owner - add rotate link
         if ($image['data']['uploaded_by'] == Zend_Auth::getInstance()->getIdentity()->id) {
             $this->view->can_rotate = true;
         }
     }
     $this->view->dropdown_options = $dropdown_options;
     // comments
     $show_hidden_comments = $context == 'single' ? true : false;
     $new_comments_data = $Comments->getCommentsForResources(array($resource_id), $resource_type, $show_hidden_comments);
     $add_comment_form->reset();
     $this->view->comments = isset($new_comments_data[$resource_id]) ? $new_comments_data[$resource_id] : array();
     $this->view->add_comment_form = $add_comment_form;
     // likes
     $this->view->is_liked = $Likes->isLiked($resource_id, $resource_type);
     $this->view->likes_count = $Likes->getLikesCount($resource_id, $resource_type);
     // reports
     $this->view->is_reported = $Reports->isReported($resource_id, $resource_type);
     $this->view->resource_owner_name = 'not-used';
     $this->view->btn_title = Zend_Registry::get('Zend_Translate')->translate('Report');
     $this->view->class = 'btn btn-default btn-xs';
     $this->view->image = $image;
     $html = $this->view->render('/partial/lightbox.phtml');
     $this->getHelper('json')->sendJson($html);
 }