예제 #1
0
 public function tweetAction()
 {
     require_once EXTERNAL_LIBRARY_PATH . '/twitter-async/EpiCurl.php';
     require_once EXTERNAL_LIBRARY_PATH . '/twitter-async/EpiOAuth.php';
     require_once EXTERNAL_LIBRARY_PATH . '/twitter-async/EpiTwitter.php';
     $auth = Zend_Auth::getInstance();
     $registry = Zend_Registry::getInstance();
     $config = $registry->get("config");
     $router = $this->getFrontController()->getRouter();
     $userInfo = $registry->get("userInfo");
     $shareInfo = $registry->get("shareInfo");
     $request = $this->getRequest();
     $params = $request->getParams();
     $twitter = Ml_Model_Twitter::getInstance();
     $twitterForm = $twitter->form();
     if ($request->isPost()) {
         if ($twitterForm->isValid($request->getPost())) {
             $msg = $twitterForm->getValue('tweet');
             $response = $twitter->tweet($msg);
             $this->view->tweetResponse = $response;
         } else {
             $errors = $twitterForm->getErrors();
             if (in_array("stringLengthTooLong", $errors['tweet'])) {
                 $this->view->tweetResponse = array("error" => "msg_too_long");
             }
         }
     }
     if (!$this->_request->isXmlHttpRequest()) {
         $this->_redirect($router->assemble($params, "sharepage_1stpage"), array("exit"));
     } else {
         $this->_helper->layout->disableLayout();
     }
 }
예제 #2
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;
 }
예제 #3
0
 public function twitterAction()
 {
     require_once EXTERNAL_LIBRARY_PATH . '/twitter-async/EpiCurl.php';
     require_once EXTERNAL_LIBRARY_PATH . '/twitter-async/EpiOAuth.php';
     require_once EXTERNAL_LIBRARY_PATH . '/twitter-async/EpiTwitter.php';
     $auth = Zend_Auth::getInstance();
     $registry = Zend_Registry::getInstance();
     $router = Zend_Controller_Front::getInstance()->getRouter();
     $config = $registry->get('config');
     $request = $this->getRequest();
     $twitterConf = $config['services']['twitter'];
     $params = $request->getParams();
     $twitter = Ml_Model_Twitter::getInstance();
     $twitterObj = new EpiTwitter($twitterConf['key'], $twitterConf['secret']);
     $removeTwitterForm = $twitter->removeForm();
     $addTwitterForm = $twitter->addForm();
     if ($request->isPost()) {
         if ($removeTwitterForm->isValid($request->getPost())) {
             $twitter->disassociateAccount($auth->getIdentity());
         } else {
             if ($addTwitterForm->isValid($request->getPost())) {
                 $twitterAuthenticateUrl = $twitterObj->getAuthenticateUrl();
                 if (Zend_Uri::check($twitterAuthenticateUrl)) {
                     $this->_redirect($twitterAuthenticateUrl, array("exit"));
                 }
             }
         }
     }
     $twitterInfo = $twitter->getSignedUserTwitterAccount();
     if (isset($params['oauth_token']) && !is_array($twitterInfo)) {
         try {
             $twitterObj->setToken($params['oauth_token']);
             $token = $twitterObj->getAccessToken();
             $tokenArray = array('oauth_token' => $token->oauth_token, 'oauth_token_secret' => $token->oauth_token_secret);
             $twitter->associateAccount($tokenArray);
             $this->_redirect($router->assemble(array(), "accounttwitter"), array("exit"));
         } catch (Exception $e) {
             $this->view->twitterApiError = true;
         }
     }
     if (!is_array($twitterInfo)) {
         $this->view->getTwitterOauth = true;
     } else {
         //how old is the data retrieved from Twitter?
         $lastCheckDate = new Zend_Date($twitterInfo['timestamp'], Zend_Date::ISO_8601);
         if ($lastCheckDate->getTimestamp() < time() - 86400) {
             try {
                 $twitter->associateAccount(false, $twitterInfo);
                 $twitterInfo = $twitter->getSignedUserTwitterAccount();
             } catch (Exception $e) {
                 $this->view->invalidTwitterAccount = true;
             }
         }
         $this->view->twitterInfo = $twitterInfo;
     }
     $this->view->addTwitterForm = $addTwitterForm;
     $this->view->removeTwitterForm = $removeTwitterForm;
 }