public function echoAction() { $doc = new Ml_Model_Dom(); $doc->formatOutput = true; $element = $doc->newTextElement("echo", $_SERVER['REQUEST_URI']); $doc->appendChild($element); $this->_helper->printResponse($doc); }
public function errorAction() { $registry = Zend_Registry::getInstance(); // Grab the error object from the request $errors = $this->_getParam('error_handler'); switch ($errors->type) { case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER: case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION: // 404 error -- controller or action not found $this->getResponse()->setHttpResponseCode(404); $code = 404; break; default: // application error if ($registry->isRegistered("notfound")) { $this->getResponse()->setHttpResponseCode(404); $code = 404; } else { $this->getResponse()->setHttpResponseCode(500); $code = 500; } break; } $doc = new Ml_Model_Dom(); $doc->formatOutput = true; $rootElement = $doc->createElement("error"); if (isset($_SERVER['REQUEST_URI'])) { $rootElement->appendChild($doc->newTextElement("request", $_SERVER['REQUEST_URI'])); } if ($code == 404) { $errorMsg = "Not found"; } else { $errorMsg = "Bad Request"; } $rootElement->appendChild($doc->newTextElement("message", $errorMsg)); if (APPLICATION_ENV == "development") { $exceptionElement = $doc->createElement("exception"); $exceptionElement->appendChild($doc->newTextElement("message", $errors->exception->getMessage())); //$exceptionElement->appendChild($doc->newTextElement("request", // print_r($errors->request, true))); $rootElement->appendChild($exceptionElement); } $doc->appendChild($rootElement); $this->_helper->printResponse($doc); }
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); }
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); }
public function userfeedAction() { $registry = Zend_Registry::getInstance(); $config = $registry->get("config"); $s3config = $config['services']['S3']; $request = $this->getRequest(); $router = Zend_Controller_Front::getInstance()->getRouter(); $userInfo = $registry->get("userInfo"); $share = Ml_Model_Share::getInstance(); $paginator = $share->getPages($userInfo['id'], 20, 1); $currentItems = $paginator->getCurrentItems()->toArray(); $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(); $doc = new Ml_Model_Dom(); $doc->formatOutput = true; $doc->encoding = "utf-8"; $rootElement = $doc->createElement("rss"); $rootElement->appendChild($doc->newTextAttribute("version", "2.0")); $rootElement->appendChild($doc->newTextAttribute("xmlns:atom", "http://www.w3.org/2005/Atom")); $doc->appendChild($rootElement); $channelElement = $doc->createElement("channel"); $channelElement->appendChild($doc->newTextElement("description", "Recent uploads to " . $config['applicationname'] . ".")); $rootElement->appendChild($channelElement); $userLink = "http://" . $config['webhost'] . $router->assemble(array("username" => $userInfo['alias']), "filestream_1stpage"); /*Instead of... * $firstElement = current($currentItems); if(!is_array($firstElement)) $x = 1; else $x =2; should see the last changed or published of the items... */ $userData = array("title" => "Shared files from " . $userInfo['name'], "link" => $userLink, "generator" => "http://" . $config['webhost'], "docs" => "http://blogs.law.harvard.edu/tech/rss", "ttl" => "180"); if (empty($config['webroot'])) { $userData['generator'] .= '/'; } else { $userData['generator'] .= "/" . $config['webroot'] . "/"; } foreach ($userData as $field => $value) { $channelElement->appendChild($doc->newTextElement($field, $value)); } $avatarInfo = unserialize($userInfo['avatarInfo']); if (isset($avatarInfo['secret'])) { $iconSecret = $avatarInfo['secret']; } else { $iconSecret = ''; } if (!empty($iconSecret)) { $imageElement = $doc->createElement("image"); $picUri = $s3config['headshotsBucketAddress'] . $userInfo['id'] . '-' . $iconSecret . '-s.jpg'; $imageElement->appendChild($doc->newTextElement("url", $picUri)); $imageElement->appendChild($doc->newTextElement("title", "Shares from " . $userInfo['name'])); $imageElement->appendChild($doc->newTextElement("link", $userLink)); $channelElement->appendChild($imageElement); } $atomLink = $doc->createElement("atom:link"); $atomLink->appendChild($doc->newTextAttribute("href", "http://" . $config['webhost'] . $router->assemble(array("username" => $userInfo['alias']), "userfeed"))); $atomLink->appendChild($doc->newTextAttribute("rel", "self")); $atomLink->appendChild($doc->newTextAttribute("type", "application/rss+xml")); $channelElement->appendChild($atomLink); foreach ($currentItems as $share) { $shareElement = $doc->createElement("item"); if (empty($share['description_filtered'])) { $description = $this->view->escape($share['short']); } else { $description = $share['description_filtered']; } $link = "http://" . $config['webhost'] . $router->assemble(array("username" => $userInfo['alias'], "share_id" => $share['id']), "sharepage_1stpage"); $shareDate = new Zend_Date($share['uploadedTime'], Zend_Date::ISO_8601); $shareData = array("title" => $share['title'], "link" => $link, "description" => $description, "pubDate" => $shareDate->get(Zend_Date::RSS)); foreach ($shareData as $field => $data) { $shareElement->appendChild($doc->newTextElement($field, $data)); } $shareElement->appendChild($doc->newTextElement("guid", $link)); $enclosureElement = $doc->createElement("enclosure"); $enclosureElement->appendChild($doc->newTextAttribute("url", $this->view->downloadLink($share, $userInfo))); $enclosureElement->appendChild($doc->newTextAttribute("length", $share['fileSize'])); $enclosureElement->appendChild($doc->newTextAttribute("type", $share['type'])); $shareElement->appendChild($enclosureElement); $channelElement->appendChild($shareElement); } $request = $this->getRequest(); $response = new Zend_Controller_Response_Http(); //I'm not serving as rss+xml for browsers because they get it wrong if (isset($_SERVER['HTTP_USER_AGENT']) && strstr($_SERVER['HTTP_USER_AGENT'], "Mozilla")) { $contenttype = 'text/xml'; } else { $contenttype = 'application/rss+xml'; } header('Content-Type: ' . $contenttype . '; charset=utf-8'); echo $doc->saveXML(); exit; }