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; }
public function commentpermalinkAction() { $registry = Zend_Registry::getInstance(); $router = Zend_Controller_Front::getInstance()->getRouter(); $config = $registry->get("config"); $userInfo = $registry->get("userInfo"); $shareInfo = $registry->get("shareInfo"); $request = $this->getRequest(); $commentId = $request->getParam("comment_id"); //don't use getUserParam //because when we have new comments they are dispatched to here //and the setParam is used $comments = Ml_Model_Comments::getInstance(); $position = $comments->getCommentPosition($commentId, $registry['shareInfo']['id'], $config['share']['commentsPerPage']); if (!is_array($position)) { $registry->set("notfound", true); throw new Exception("Comment {$commentId} does not exists."); } if ($position['page'] == 1) { $route = 'sharepage_1stpage'; } else { $route = 'sharepage'; } $this->_redirect($router->assemble(array("username" => $userInfo['alias'], "share_id" => $shareInfo['id'], "page" => $position['page']), $route) . '#comment' . $commentId, array("exit")); }
public function infoAction() { //@todo route: do it the right way! $router = new Zend_Controller_Router_Rewrite(); $routeConfig = new Zend_Config_Ini(APPLICATION_PATH . '/configs/defaultRoutes.ini'); $router->addConfig($routeConfig, 'routes'); $registry = Zend_Registry::getInstance(); $config = $registry->get("config"); $request = $this->getRequest(); $params = $request->getParams(); $people = Ml_Model_People::getInstance(); $favorites = Ml_Model_Favorites::getInstance(); $comments = Ml_Model_Comments::getInstance(); $tags = Ml_Model_Tags::getInstance(); $numbers = new Ml_Model_Numbers(); $this->_helper->loadApiresource->share(); $shareInfo = $registry->get("shareInfo"); $userInfo = $people->getById($shareInfo['byUid']); $tagsList = $tags->getShareTags($shareInfo['id']); $countFavs = $favorites->count($shareInfo['id']); $countComments = $comments->count($shareInfo['id']); //begin of response $doc = new Ml_Model_Dom(); $doc->formatOutput = true; $rootElement = $doc->createElement("file"); $doc->appendChild($rootElement); $rootElement->appendChild($doc->newTextAttribute('id', $shareInfo['id'])); $rootElement->appendChild($doc->newTextAttribute('secret', $shareInfo['secret'])); $rootElement->appendChild($doc->newTextAttribute('download_secret', $shareInfo['download_secret'])); $ownerElement = $doc->createElement("owner"); $ownerData = array("id" => $userInfo['id'], "username" => $userInfo['alias'], "realname" => $userInfo['name']); foreach ($ownerData as $field => $data) { $ownerElement->appendChild($doc->newTextAttribute($field, $data)); } $rootElement->appendChild($ownerElement); $shareData = array("title" => $shareInfo['title'], "filename" => $shareInfo['filename'], "filetype" => $shareInfo['type'], "short" => $shareInfo['short'], "description" => $shareInfo['description_filtered'], "url" => "http://" . $config['webhost'] . $router->assemble(array("username" => $userInfo['alias'], "share_id" => $shareInfo['id']), "sharepage_1stpage"), "dataurl" => $config['services']['S3']['sharesBucketAddress'] . $userInfo['alias'] . "/" . $shareInfo['id'] . "-" . $shareInfo['download_secret'] . "/" . $shareInfo['filename'], "shorturl" => $config['URLshortening']['addr'] . $numbers->base58Encode($shareInfo['id']), "comments" => $countComments, "favorites" => $countFavs); foreach ($shareData as $field => $data) { $rootElement->appendChild($doc->newTextElement($field, $data)); } $filesizeElement = $doc->createElement("filesize"); $filesizeElement->appendChild($doc->newTextAttribute("bits", $shareInfo['fileSize'])); $filesizeElement->appendChild($doc->newTextAttribute("kbytes", ceil($shareInfo['fileSize'] / (1024 * 8)))); $rootElement->appendChild($filesizeElement); $checksumElement = $doc->createElement("checksum"); $checksumElement->appendChild($doc->newTextAttribute("hash", "md5")); $checksumElement->appendChild($doc->newTextAttribute("value", $shareInfo['md5'])); $rootElement->appendChild($checksumElement); $visibilityElement = $doc->createElement("visibility"); $visibilityElement->appendChild($doc->newTextAttribute("ispublic", "1")); $rootElement->appendChild($visibilityElement); $datesData = array("posted" => $shareInfo['uploadedTime'], "lastupdate" => $shareInfo['lastChange']); $datesElement = $doc->createElement("dates"); foreach ($datesData as $field => $data) { $datesElement->appendChild($doc->newTextAttribute($field, $data)); } $rootElement->appendChild($datesElement); $tagsElement = $doc->createElement("tags"); foreach ($tagsList as $tag) { $tagElement = $doc->createElement("tag"); $tagElement->appendChild($doc->newTextAttribute("id", $tag['id'])); $tagElement->appendChild($doc->newTextAttribute("raw", $tag['raw'])); $tagElement->appendChild($doc->createTextNode($tag['clean'])); $tagsElement->appendChild($tagElement); } $rootElement->appendChild($tagsElement); $this->_helper->printResponse($doc); }