/** * Send message */ public function sendMessage($to_user_id, $content, $message_type = 'pm') { if (!Zend_Auth::getInstance()->hasIdentity() || strlen($content) < 1) { return false; } $from_user_id = Zend_Auth::getInstance()->getIdentity()->id; if (!$to_user_id || $from_user_id == $to_user_id) { return false; } $ret = $this->insert(array('type' => $message_type, 'from_user_id' => $from_user_id, 'to_user_id' => $to_user_id, 'content' => $content, 'is_new' => 1, 'is_hidden' => 0, 'sent_on' => Application_Plugin_Common::now())); $Notifications = new Application_Model_Notifications(); $Notifications->pushNotification(array($to_user_id), 8, 'profile', $from_user_id, false); return $ret; }
/** * Like toggle */ public function toggleLike($resource_id, $resource_type) { if (!Zend_Auth::getInstance()->hasIdentity() || !$resource_id || !$resource_type) { return null; } $user_id = Zend_Auth::getInstance()->getIdentity()->id; if ($this->isLiked($resource_id, $resource_type)) { $result = $this->delete(array('resource_id = ?' => (int) $resource_id, 'resource_type = ?' => $resource_type, 'user_id = ?' => (int) $user_id)); $state = 0; } else { $data = array('user_id' => (int) $user_id, 'resource_type' => $resource_type, 'resource_id' => (int) $resource_id, 'created_on' => Application_Plugin_Common::now()); $ret = $this->insert($data); $state = 1; } $likes_count = $this->getLikesCount($resource_id, $resource_type); // notify author $Notifications = new Application_Model_Notifications(); if ($state == 1) { // find resource author switch ($resource_type) { case 'post': $Posts = new Application_Model_Posts(); $resource_author = array($Posts->getPostAuthorId($resource_id)); break; case 'comment': $Comments = new Application_Model_Comments(); $resource_author = array($Comments->getCommentAuthorId($resource_id)); break; case 'image': $Images = new Application_Model_Images(); $resource_author = array($Images->getImageOwnerId($resource_id)); break; default: $resource_author = false; break; } if ($resource_author) { // notify resource owner $Notifications->pushNotification($resource_author, 2, 'like', $ret); } } return array('count' => $likes_count, 'state' => $state); }
/** * Reject group membership request */ public function rejectGroupMembership($user_id, $follow_id) { $ret = $this->removeConnections($user_id, $follow_id); // notify user who sent the request that his request is accepted $Notifications = new Application_Model_Notifications(); $Notifications->pushNotification(array($user_id), 11, 'profile', $follow_id); return $ret; }
$Notifications->pushNotification(array($profile->id), 1001, 'post', $post_id); } }, $content); }); // push comment mention notifications $this->attach('hook_data_aftersavecomment', 10, function ($data) { $comment_id = $data['comment_id']; $Comments = new Application_Model_Comments(); $comment = $Comments->getComment($comment_id); $content = $data['content']; $users = preg_replace_callback("/(^|[\t\r\n\\s])@(\\w+)/u", function ($match) use($comment_id) { $Profiles = new Application_Model_Profiles(); $profile = $Profiles->getProfile($match[2]); if ($profile && $profile->type == 'user') { $Notifications = new Application_Model_Notifications(); $Notifications->pushNotification(array($profile->id), 1001, 'comment', $comment_id); } }, $content); }); // notifications $this->attach('hook_data_notificationsfix', 10, function (&$data) { $baseURL = Application_Plugin_Common::getFullBaseUrl(); $transl = Zend_Registry::get('Zend_Translate'); foreach ($data as &$row) { // user mentioned inside post/comment if ($row['notification_type'] == 1001) { $row['do_send_email'] = false; if ($row['commented_post_id']) { $row['html_link'] = '<a href="' . $baseURL . '/profiles/showpost/name/' . $row['commented_post_on_wall'] . '/post/' . $row['commented_post_id'] . '">'; $row['view_from_name'] = $row['comment_author_name']; $row['view_from_screen_name'] = $row['comment_author_screen_name'];
/** * 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; }
/** * Add new post */ public function addPost(array $content, $wall_id, $privacy, $attached_files) { if (!Zend_Auth::getInstance()->hasIdentity() || strlen($content['content']) < 1 && empty($attached_files)) { return false; } $content['content'] = Application_Plugin_Common::limitInput($content['content']); $Connections = new Application_Model_Connections(); $Profiles = new Application_Model_Profiles(); $Images = new Application_Model_Images(); $PostsMeta = new Application_Model_PostsMeta(); $wall_profile = $Profiles->getProfileByField('id', $wall_id); $author_id = Zend_Auth::getInstance()->getIdentity()->id; $insert_id = $this->insert(array('author_id' => $author_id, 'wall_id' => $wall_id, 'created_on' => Application_Plugin_Common::now(), 'content' => $content['content'], 'is_hidden' => 0, 'privacy' => $privacy)); // write post's meta data if (isset($content['meta'])) { foreach ($content['meta'] as $metakey => $metavalue) { $ret = $PostsMeta->metaUpdate($insert_id, $metakey, $metavalue); } } // move tmp file to posts folder and add meta data to post if (!empty($attached_files)) { $i = 0; foreach ($attached_files as $file) { ++$i; $file_data = array('name' => basename($file), 'size' => filesize($file)); // check max images per post if ($i > Zend_Registry::get('config')->get('max_images_per_post')) { break; } $Storage = new Application_Model_Storage(); $StorageAdapter = $Storage->getAdapter(); $original_filename = ''; if (Zend_Registry::get('config')->get('resample_images')) { Application_Plugin_ImageLib::resample(TMP_PATH . '/' . $file_data['name'], TMP_PATH . '/thumb_' . $file_data['name']); $filename = $StorageAdapter->moveFileToStorage('thumb_' . $file_data['name'], 'posts'); if (Zend_Registry::get('config')->get('keep_original')) { $original_filename = $StorageAdapter->moveFileToStorage($file_data['name'], 'posts'); } else { $original_filename = ''; unlink(TMP_PATH . '/' . $file_data['name']); // clean up } } else { $filename = $StorageAdapter->moveFileToStorage($file_data['name'], 'posts'); } // in case this is not a user's wall - image owner will become the network // (image owner could become the wall owner but that's a bad idea) if ($wall_profile['id'] != $author_id) { $owner = 0; } else { $owner = $author_id; } $Images->addImage($filename, $file_data['size'], $owner, $author_id, $insert_id, 0, $original_filename); } } // post on someone else's wall, notify wall owner if ($wall_profile['type'] === 'user' && $wall_id != $author_id) { $Notifications = new Application_Model_Notifications(); $Notifications->pushNotification(array($wall_id), 7, 'post', $insert_id); } // trigger hooks $data = array('post_id' => $insert_id, 'content' => $content); Zend_Registry::get('hooks')->trigger('hook_data_aftersavepost', $data); return true; }