public function recentAction() { //@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"); $this->_helper->verifyIdentity(); $recent = new Ml_Model_Recent(); if (!$registry->isRegistered("authedUserInfo")) { throw new Exception("Not authenticated."); } $userInfo = $registry->get("authedUserInfo"); $uploads = $recent->contactsUploads($userInfo['id']); //send response $doc = new Ml_Model_Dom(); $doc->formatOutput = true; $rootElement = $doc->createElement("items"); $doc->appendChild($rootElement); foreach ($uploads as $share) { $shareElement = $doc->createElement("item"); $avatarInfo = unserialize($share['people.avatarInfo']); if (isset($avatarInfo['secret'])) { $iconSecret = $avatarInfo['secret']; } else { $iconSecret = ''; } $shareData = array("type" => "file", "id" => $share['id']); foreach ($shareData as $name => $field) { $shareElement->appendChild($doc->newTextAttribute($name, $field)); } $shareData = array("title" => $share['share.title'], "short" => $share['share.short'], "url" => "http://" . $config['webhost'] . $router->assemble(array("username" => $share['people.alias'], "share_id" => $share['id']), "sharepage_1stpage")); foreach ($shareData as $name => $field) { $shareElement->appendChild($doc->newTextElement($name, $field)); } $filesizeElement = $doc->createElement("filesize"); $filesizeElement->appendChild($doc->newTextAttribute("bits", $share['share.fileSize'])); $filesizeElement->appendChild($doc->newTextAttribute("kbytes", ceil($share['share.fileSize'] / (1024 * 8)))); $shareElement->appendChild($filesizeElement); $ownerElement = $doc->createElement("owner"); $shareData = array("id" => $share['people.id'], "alias" => $share['people.alias'], "realname" => $share['people.name'], "iconsecret" => $iconSecret); foreach ($shareData as $name => $field) { $ownerElement->appendChild($doc->newTextAttribute($name, $field)); } $shareElement->appendChild($ownerElement); $rootElement->appendChild($shareElement); } $this->_helper->printResponse($doc); }
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); }
/** * Generates a URL path that can be used in URL creation, redirection, etc. * * @param array $userParams Options passed by a user used to override parameters * @param mixed $name The name of a Route to use * @param bool $reset Whether to reset to the route defaults ignoring URL params * @param bool $encode Tells to encode URL parts on output * @throws Zend_Controller_Router_Exception * @return string Resulting absolute URL path */ public function assemble($userParams, $name = null, $reset = false, $encode = true) { if ($name == null) { try { $name = $this->getCurrentRouteName(); } catch (Zend_Controller_Router_Exception $e) { $name = 'default'; } } if ($name == 'default') { if ($this->_useDefaultRoutes) { $this->addDefaultRoutes(); } } return parent::assemble($userParams, $name, $reset, $encode); }
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(); $profile = Ml_Model_Profile::getInstance(); $share = Ml_Model_Share::getInstance(); if (isset($params['username'])) { $userInfo = $people->getByUsername($params['username']); } else { if (isset($params['user_id'])) { $userInfo = $people->getById($params['user_id']); } else { if (isset($params['email'])) { $userInfo = $people->getByEmail($params['email']); if (!empty($userInfo) && $userInfo['private_email'] == true) { $registry->set("notfound", true); throw new Exception("User not found."); } } else { throw new Exception("No user params were given."); } } } if (empty($userInfo)) { $registry->set("notfound", true); throw new Exception("User not found."); } $profileInfo = $profile->getById($userInfo['id']); $doc = new Ml_Model_Dom(); $doc->formatOutput = true; $rootElement = $doc->createElement("person"); $doc->appendChild($rootElement); $rootElement->appendChild($doc->newTextAttribute('id', $userInfo['id'])); $avatarInfo = unserialize($userInfo['avatarInfo']); if (isset($avatarInfo['secret'])) { $iconSecret = $avatarInfo['secret']; } else { $iconSecret = ''; } $rootElement->appendChild($doc->newTextAttribute('iconsecret', $iconSecret)); $userData = array("username" => $userInfo['alias'], "realname" => $userInfo['name']); if (!$userInfo['private_email']) { $userData["mbox_sha1sum"] = sha1("mailto:" . $userInfo['email']); } $userData["location"] = $profileInfo['location']; $userData["url"] = "http://" . $config['webhost'] . $router->assemble(array("username" => $userInfo['alias']), "filestream_1stpage"); foreach ($userData as $field => $data) { $rootElement->appendChild($doc->newTextElement($field, $data)); } $sharesCounter = $share->countOfUser($userInfo['id']); $sharesElement = $doc->createElement("files"); $sharesCounterElement = $doc->createElement("count"); $sharesCounterElement->appendChild($doc->createTextNode($sharesCounter)); $sharesElement->appendChild($sharesCounterElement); $rootElement->appendChild($sharesElement); $this->_helper->printResponse($doc); }