Ejemplo n.º 1
0
 /**
  * Add comment
  */
 public function addComment($content, $resource_id, $resource_type)
 {
     if (!Zend_Auth::getInstance()->hasIdentity()) {
         return false;
     }
     if (!is_string($content) || !is_string($resource_type) || strlen($content) < 1) {
         return false;
     }
     $content = Application_Plugin_Common::limitInput($content);
     $author_id = Zend_Auth::getInstance()->getIdentity()->id;
     // find resource author
     switch ($resource_type) {
         case 'post':
             $Posts = new Application_Model_Posts();
             $resource_author = $Posts->getPostAuthorId($resource_id);
             $resource_wall = $Posts->getPostsWallProfileData($resource_id);
             // for page comments written by page admin switch owner to be a page itself
             if ($resource_wall['type'] == 'page' && $resource_wall['owner'] == $author_id) {
                 $author_id = $resource_wall['id'];
                 $resource_author = $author_id;
             }
             break;
         case 'image':
             $Images = new Application_Model_Images();
             $image = $Images->getImage($resource_id);
             $resource_author = $image['data']['uploaded_by'];
             break;
         default:
             $resource_author = 0;
             break;
     }
     $ret = $this->insert(array('author_id' => $author_id, 'resource_type' => $resource_type, 'resource_id' => $resource_id, 'created_on' => Application_Plugin_Common::now(), 'content' => $content, 'is_hidden' => 0));
     $this->markOldAsHidden($resource_type, $resource_id);
     $Notifications = new Application_Model_Notifications();
     // notify all users involved in comment discussion
     $notify_users = $this->getUsersCommented($resource_type, $resource_id, true);
     // notify resource author if not already on the list
     if (array_search($resource_author, $notify_users) === false) {
         $notify_users[] = $resource_author;
     }
     $Notifications->pushNotification($notify_users, 1, 'comment', $ret);
     // trigger hooks
     $data = array('comment_id' => $ret, 'content' => $content);
     Zend_Registry::get('hooks')->trigger('hook_data_aftersavecomment', $data);
     return $ret;
 }
 /**
  * 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);
 }
Ejemplo n.º 3
0
 /**
  * get share modal content (via ajax)
  */
 public function shareAction()
 {
     $request = $this->getRequest();
     $resource_type = $request->getParam('resource_type', 0);
     $resource_id = $request->getParam('resource_id', 0);
     $base_link = Application_Plugin_Common::getFullBaseUrl();
     $repost_link = false;
     switch ($resource_type) {
         case 'post':
             $Posts = new Application_Model_Posts();
             $post = $Posts->getPost($resource_id);
             $profile = $Posts->getProfileDataByPostWall($resource_id);
             $profile_name = $profile['name'];
             $direct_link = $base_link . '/profiles/showpost/name/' . $profile_name . '/post/' . $resource_id;
             $repost_link = $base_link . '/posts/repost/post_id/' . $resource_id;
             break;
         case 'profile':
             $direct_link = $base_link . '/' . $resource_id;
             break;
         case 'image':
             $Images = new Application_Model_Images();
             $image = $Images->getImage($resource_id);
             $direct_link = $base_link . '/index/index/showimage/' . $image['data']['uid'];
             break;
         default:
             $direct_link = $base_link;
             break;
     }
     // drop repost link if not logged in
     if (!Zend_Auth::getInstance()->hasIdentity()) {
         $repost_link = false;
     }
     $this->view->repost_link = $repost_link;
     $this->view->direct_link = $direct_link;
     // trigger hooks
     Zend_Registry::get('hooks')->trigger('hook_app_share', $this);
     $html = $this->view->render('/partial/share_modal_content.phtml');
     $this->getHelper('json')->sendJson($html);
 }