Example #1
0
 public function relationshipAction()
 {
     $auth = Zend_Auth::getInstance();
     $registry = Zend_Registry::getInstance();
     $router = Zend_Controller_Front::getInstance()->getRouter();
     $request = $this->getRequest();
     $userInfo = $registry->get("userInfo");
     $contacts = Ml_Model_Contacts::getInstance();
     $ignore = Ml_Model_Ignore::getInstance();
     if (!$auth->hasIdentity()) {
         Zend_Controller_Front::getInstance()->registerPlugin(new Ml_Plugins_LoginRedirect());
     }
     //avoids self-relationship
     if ($auth->getIdentity() == $userInfo['id']) {
         $this->_redirect($router->assemble(array("username" => $userInfo['alias']), "contacts_1stpage"), array("exit"));
     }
     $relationship = $contacts->getRelationship($auth->getIdentity(), $userInfo['id']);
     if (isset($relationship['id'])) {
         $ignoreStatus = false;
     } else {
         $ignoreStatus = $ignore->status($auth->getIdentity(), $userInfo['id']);
     }
     if (is_array($ignoreStatus)) {
         $this->view->cannotAddIgnored = $ignoreStatus;
     } else {
         $form = $contacts->relationshipForm();
         if (isset($relationship['id'])) {
             $form->getElement("contact_relation")->setOptions(array("checked" => true));
         }
         if ($request->isPost() && $form->isValid($request->getPost())) {
             $wantContact = $form->getElement("contact_relation")->isChecked();
             if ($wantContact && !isset($relationship['id'])) {
                 $contacts->setRelationship($auth->getIdentity(), $userInfo['id']);
                 $changeRel = "?new_contact";
             } else {
                 if (!$wantContact && isset($relationship['id'])) {
                     $contacts->setRelationship($auth->getIdentity(), $userInfo['id'], Ml_Model_Contacts::RELATIONSHIP_TYPE_NONE);
                     $changeRel = "?removed_contact";
                 } else {
                     $changeRel = '';
                 }
             }
             $this->_redirect(Zend_Controller_Front::getInstance()->getRouter()->assemble(array("username" => $userInfo['alias']), "profile") . $changeRel, array("exit"));
             /*if (isset($new_rel) && $new_rel) {
                   $form->getElement("contact_relation")->setOptions(
                   array("checked" => true));
               }*/
         }
     }
     $this->view->relationshipForm = $form;
 }
Example #2
0
 public function switchAction()
 {
     $auth = Zend_Auth::getInstance();
     $registry = Zend_Registry::getInstance();
     $router = Zend_Controller_Front::getInstance()->getRouter();
     $ignore = Ml_Model_Ignore::getInstance();
     $request = $this->getRequest();
     $userInfo = $registry->get("userInfo");
     if (!$auth->hasIdentity()) {
         $this->_redirect($router->assemble(array(), "login"), array("exit"));
     }
     $signedUserInfo = $registry->get("signedUserInfo");
     if ($auth->getIdentity() == $userInfo['id']) {
         $this->_redirect($router->assemble(array(), "index"), array("exit"));
     }
     $ignoreStatus = $ignore->status($auth->getIdentity(), $userInfo['id']);
     if (is_array($ignoreStatus)) {
         $registry->set("is_ignored", true);
     }
     //the form has to be loaded after the line above
     $form = $ignore->form();
     if ($request->isPost() && $form->isValid($request->getPost())) {
         $formInfo = $form->getValues();
         if (isset($formInfo['ignore'])) {
             //ignore user
             $ignore->set($auth->getIdentity(), $userInfo['id']);
             $whatAction = "blocked";
         } else {
             if (isset($formInfo['removeignore'])) {
                 //remove ignore
                 $ignore->remove($auth->getIdentity(), $userInfo['id']);
                 $whatAction = "unblocked";
             }
         }
         if (isset($whatAction)) {
             $this->_redirect($router->assemble(array("username" => $userInfo['alias']), "profile"), array("exit"));
         }
     }
     $this->view->ignoreForm = $form;
     $this->view->ignoreStatus = $ignoreStatus;
 }
Example #3
0
 public function editAction()
 {
     $registry = Zend_Registry::getInstance();
     $auth = Zend_Auth::getInstance();
     $request = $this->getRequest();
     $userInfo = $registry->get("userInfo");
     $shareInfo = $registry->get("shareInfo");
     $comments = Ml_Model_Comments::getInstance();
     $ignore = Ml_Model_Ignore::getInstance();
     $commentId = $request->getUserParam("comment_id");
     $comment = $comments->getById($commentId);
     if (!$comment) {
         $registry->set("notfound", true);
         throw new Exception("Comment {$commentId} does not exists.");
     }
     if ($comment['uid'] != $auth->getIdentity() || $auth->getIdentity() != $comment['byUid'] && $ignore->status($userInfo['id'], $auth->getIdentity())) {
         $registry->set("notfound", true);
         throw new Exception("Can't edit the comment. Either ignored or not the author.");
     }
     if ($comment['share'] != $shareInfo['id']) {
         $registry->set("notfound", true);
         throw new Exception("From another share.");
     }
     $registry->set("commentInfo", $comment);
     $form = $comments->addForm();
     $form->setDefault("commentMsg", $comment['comments']);
     if ($request->isPost() && $form->isValid($request->getPost())) {
         $commentMsg = $form->getValue("commentMsg");
         $isSubmit = $form->getValue("commentPost");
         if (!empty($isSubmit)) {
             $comments->update($comment['id'], $commentMsg);
             $request->setParam("comment_id", $comment['id']);
             return $this->_forward("commentpermalink");
         }
         $this->view->commentPreview = $commentMsg;
     }
     $this->view->commentForm = $form;
 }
Example #4
0
 public function filepageAction()
 {
     $registry = Zend_Registry::getInstance();
     $auth = Zend_Auth::getInstance();
     $request = $this->getRequest();
     $config = $registry->get('config');
     $params = $request->getParams();
     $keys = array("deletetag" => array("tags" => "delete"), "addtags" => array("tags" => "add"), "favorite" => array("favorites" => "switch"), "unfavorite" => array("favorites" => "switch"), "tweet" => array("twitter" => "tweet"));
     $this->_helper->loadResource->pseudoshareSetUp();
     foreach ($keys as $key => $where) {
         if (array_key_exists($key, $params)) {
             return $this->_forward(current($where), key($where));
         }
     }
     $userInfo = $registry->get('userInfo');
     $shareInfo = $registry->get("shareInfo");
     if ($registry->isRegistered("signedUserInfo")) {
         $signedUserInfo = $registry->get("signedUserInfo");
     }
     $page = $request->getUserParam("page");
     $share = Ml_Model_Share::getInstance();
     $tags = Ml_Model_Tags::getInstance();
     $people = Ml_Model_People::getInstance();
     $comments = Ml_Model_Comments::getInstance();
     $twitter = Ml_Model_Twitter::getInstance();
     $ignore = Ml_Model_Ignore::getInstance();
     $paginator = $comments->getCommentsPages($shareInfo['id'], $config['share']['commentsPerPage'], $page);
     //Test if there is enough pages or not
     if (!$paginator->count() && $page != 1 || $paginator->getCurrentPageNumber() != $page) {
         $this->_redirect(Zend_Controller_Front::getInstance()->getRouter()->assemble(array("username" => $userInfo['alias'], "share_id" => $shareInfo['id']), "sharepage_1stpage"), array("exit"));
     }
     $tagsList = $tags->getShareTags($shareInfo['id']);
     if ($auth->hasIdentity()) {
         $ignore = Ml_Model_Ignore::getInstance();
         if ($auth->getIdentity() == $userInfo['id'] || !$ignore->status($userInfo['id'], $auth->getIdentity())) {
             $commentForm = $comments->addForm();
             //should The comment form processing should be in the CommentsController?
             if ($request->isPost() && $commentForm->isValid($request->getPost())) {
                 $newCommentMsg = $commentForm->getValue('commentMsg');
                 $previewFlag = $commentForm->getValue('getCommentPreview');
                 //check if it is a post or preview
                 if (!empty($previewFlag)) {
                     $this->view->commentPreview = $newCommentMsg;
                 } else {
                     $newComment = $comments->add($newCommentMsg, $auth->getIdentity(), $shareInfo);
                     if (!$newComment) {
                         $newComment = "#commentPreview";
                         $this->view->commentPreview = $newCommentMsg;
                     } else {
                         $request->setParam("comment_id", $newComment);
                         return $this->_forward("commentpermalink", "comments");
                     }
                 }
             }
             $this->view->commentForm = $commentForm;
             if ($twitter->getSignedUserTwitterAccount()) {
                 $this->view->twitterForm = $twitter->form();
             }
         }
     }
     $this->view->tagsList = $tagsList;
     $this->view->paginator = $paginator;
 }