Example #1
0
 public function hasRole($role)
 {
     $application = Stuffpress_Application::getInstance();
     // TODO this is temporary as it will only work in our
     // current simple scenario
     return $role == $application->role;
 }
Example #2
0
 public function init()
 {
     if (!Zend_Registry::isRegistered('user')) {
         if ($user = $this->getRequest()->getParam("user")) {
             $users = new Users();
             if ($user = $users->getUserFromUsername($user)) {
                 Zend_Registry::set("user", $user);
             }
         }
     }
     $this->_user = Zend_Registry::get("user");
     if (!Zend_Registry::isRegistered('shard')) {
         Zend_Registry::set("shard", $this->_user->id);
     }
     if (Zend_Registry::isRegistered("cache")) {
         $this->_cache = Zend_Registry::get("cache");
     }
     if (Zend_Registry::isRegistered("root")) {
         $this->_root = Zend_Registry::get("root");
     }
     if (Zend_Registry::isRegistered("configuration")) {
         $this->_config = Zend_Registry::get("configuration");
     }
     // Other global variables
     $this->_application = Stuffpress_Application::getInstance();
     $this->_properties = new Properties(array(Stuffpress_Db_Properties::KEY => $this->_user->id));
     $this->_admin = $this->_application->user && $this->_application->user->id == $this->_user->id ? true : false;
     // Disable layout if XMLHTTPRequest
     if ($this->_request->isXmlHttpRequest()) {
         $this->_helper->layout->disableLayout();
     }
 }
Example #3
0
 public function init()
 {
     $this->_application = Stuffpress_Application::getInstance();
     // If request is from a bookmarklet, we use another layout
     if ($this->_hasParam('bookmarklet') && $this->_getParam('bookmarklet')) {
         $this->_helper->layout->setlayout('bookmarklet');
         $this->_bookmarklet = true;
         $this->view->bookmarklet = true;
     }
 }
Example #4
0
 public function storiesAction()
 {
     $count = $this->getRequest()->getParam("count");
     $count = $count ? $count : 5;
     // Hit the cache
     $cache_id = "embed_stories_{$this->_user->id}_{$count}";
     if (!$this->_cache || !($script = $this->_cache->load($cache_id))) {
         // A few variable needed
         $base = "http://" . Stuffpress_Application::getDomain($this->_user);
         // Get the user properties
         $username = $this->_user->username;
         // Get all the items; if we are an admin, we also get the hidden one
         $stories = new Stories();
         $items = $stories->getStories($count, 0, false);
         $content = "<div id='storytlr_widget' class='storytlr_widget'>";
         if (count($items) == 0) {
             $content .= "<p>{$username} has not created any story yet.</p>";
         } else {
             foreach ($items as $item) {
                 $item['permalink'] = Stuffpress_Permalink::story($item['id'], $item['title']);
                 $date_from = date("F j, Y", $item['date_from']);
                 $date_to = date("F j, Y", $item['date_to']);
                 $item_content = "<table><tr>";
                 $item_content .= "<td class='thumbnail'><a href='{$base}/story/{$item['permalink']}'>";
                 if ($item['thumbnail']) {
                     $item_content .= "<img src='{$base}/thumbnail/{$item['thumbnail']}'>";
                 } else {
                     $item_content .= "<img src='{$base}/images/book50.jpg'>";
                 }
                 $item_content .= "</a></td>";
                 $item_content .= "<td class='overview'>";
                 $item_content .= "<div class='title'><a href='{$base}/story/{$item['permalink']}'>" . $this->escape($item['title']) . "</a></div>";
                 $item_content .= "<div class='subtitle'>" . $this->escape($item['subtitle']) . "</div>";
                 $item_content .= "<div class='date'>{$date_from} to {$date_to}</div>";
                 $item_content .= "</td>";
                 $item_content .= "</tr></table>";
                 $content .= $item_content;
             }
         }
         $content .= "</div>";
         $script = "document.write(\"<link href='{$base}/style/embed_stories.css' media='screen, projection' rel='stylesheet' type='text/css' />\");\r\n" . "document.write('<script src=\\'{$base}/js/controllers/embed_story.js\\' type=\\'text/javascript\\' /></script>');\r\n" . "document.write(\"<div id='storytlr'>\");\r\n" . "document.write(\"<h1>" . ucfirst($username) . "'s Stories</h1>\");\r\n" . "document.write(\"" . $content . "\");\r\n" . "document.write(\"<div class='bar'><a href='{$base}'><img src='{$base}/images/powered2.png'></a></div>\");\r\n" . "document.write(\"</div>\");";
         if ($this->_cache) {
             $this->_cache->save($script, $cache_id, array("stories_{$this->_user->id}"), 300);
         }
     }
     header("Content-Disposition: attachment; filename=\"stories.js\"");
     header("Content-type: text/javascript; charset=UTF-8");
     echo $script;
     ob_end_flush();
     die;
 }
Example #5
0
 public function indexAction()
 {
     $application = Stuffpress_Application::getInstance();
     // If we are not logged in, we have a problem
     if ($application->role != 'guest') {
         $sources = new Sources(array(Stuffpress_Db_Table::USER => $application->user->id));
         $mysources = $sources->getSources();
         if (count($mysources) > 1) {
             return $this->_forward('index', 'post', 'admin');
         } else {
             return $this->_forward('index', 'services', 'admin');
         }
     } else {
         return $this->_forward('index', 'auth', 'admin');
     }
 }
Example #6
0
 public function expand($token)
 {
     if (!($url = $this->getUrl($token))) {
         return false;
     }
     if ($url['internal']) {
         $users = new Users();
         if (!($user = $users->getUser($url['user_id']))) {
             return false;
         }
         $domain = Stuffpress_Application::getDomain($user);
         return "http://" . $domain . "/entry/" . $url['url'];
     } else {
         return $url['url'];
     }
 }
 public function indexAction()
 {
     // To do before anything else
     $this->initPage();
     // Action parameters
     $page = $this->getRequest()->getParam("page");
     $tab = $this->getRequest()->getParam("tab");
     // A bit of filtering
     $page = $page >= 0 ? $page : 0;
     $count = 50;
     // Get the list of sources to filter on
     if ($this->_page_properties->getProperty('sources_filter') > 0) {
         $sources = unserialize($this->_page_properties->getProperty('sources'));
         $types = unserialize($this->_page_properties->getProperty('types'));
     } else {
         $sources = false;
         $types = false;
     }
     // Get all the items; if we are an admin, we also get the hidden one
     $data = new Data();
     $items = $data->getLastItems($count, $page * $count, $this->_admin, $sources, $types);
     $this->view->items = $items;
     $this->view->models = $this->getModels();
     // Prepare the common elements
     $this->common();
     // Add description
     if ($description = $this->_page_properties->getProperty('description')) {
         $this->view->description = $description;
     }
     // Add paging
     $this->view->count = $count;
     $this->view->page = $page;
     $this->view->hasprevious = $page > 0 ? true : false;
     $this->view->hasnext = count($items) >= $count ? true : false;
     $this->view->nextlink = "home?tab={$tab}&page=" . ($page + 1);
     $this->view->previouslink = "home?tab={$tab}&page=" . ($page - 1);
     // Add atom link
     $domain = Stuffpress_Application::getDomain($this->_user);
     $this->view->headLink()->appendAlternate("http://{$domain}/updates.atom", "application/atom+xml", "Update stream in Atom");
     // Add specific styles and javascripts
     $this->view->headScript()->appendFile('js/controllers/timeline.js');
     if (!$this->_embed) {
         $this->view->headLink()->appendStylesheet('style/lightbox.css');
     }
 }
Example #8
0
 public function init()
 {
     // Set the user shard
     if (Zend_Registry::isRegistered("user")) {
         $this->_user = Zend_Registry::get("user");
     }
     if (!Zend_Registry::isRegistered('shard')) {
         Zend_Registry::set("shard", $this->_user->id);
     }
     // Get the config
     if (Zend_Registry::isRegistered("configuration")) {
         $this->_config = Zend_Registry::get("configuration");
     }
     // Set the domain
     $this->_domain = Stuffpress_Application::getDomain($this->_user, true);
     // Get the user properties
     $this->_properties = new Properties(array(Stuffpress_Db_Properties::KEY => $this->_user->id));
     // Prevent the layout to be rendered
     $this->_helper->viewRenderer->setNoRender();
     $this->_helper->layout->disableLayout();
 }
Example #9
0
 public function init()
 {
     if (Zend_Registry::isRegistered("cache")) {
         $this->_cache = Zend_Registry::get("cache");
     }
     if (Zend_Registry::isRegistered("configuration")) {
         $this->_config = Zend_Registry::get("configuration");
     }
     $this->_application = Stuffpress_Application::getInstance();
     if (!Zend_Registry::isRegistered('shard')) {
         Zend_Registry::set("shard", $this->_application->user->id);
     }
     if (Zend_Registry::isRegistered("root")) {
         $this->_root = Zend_Registry::get("root");
     }
     $this->_properties = new Properties(array(Stuffpress_Db_Properties::KEY => $this->_application->user->id));
     // Disable layout if XMLHTTPRequest
     if ($this->_request->isXmlHttpRequest()) {
         $this->_helper->layout->disableLayout();
         $this->_ajax = true;
     }
 }
Example #10
0
 public function submitAction()
 {
     if (!$this->getRequest()->isPost()) {
         return $this->_helper->json->sendJson(true);
     }
     $form = $this->getForm();
     if (!$form->isValid($_POST)) {
         return $this->_helper->json->sendJson($form->getErrorArray());
     }
     // Get the values and proceed
     $values = $form->getValues();
     $title = $values['title'];
     $id = $values['id'];
     // Get the user
     $application = Stuffpress_Application::getInstance();
     // Get the widget properties
     $properties = new WidgetsProperties(array(Properties::KEY => $id, Properties::USER => $application->user->id));
     // Save the new properties
     $properties->setProperty('title', $title);
     // Ok send the result
     return $this->_helper->json->sendJson(false);
 }
Example #11
0
    public function getPublicDomain($cname=true) {
		return Stuffpress_Application::getDomain($this->user, $cname);
    }
Example #12
0
 public static function parseDomain()
 {
     $config = Zend_Registry::get('configuration');
     $our_host = $config->web->host;
     $this_host = @$_SERVER['HTTP_HOST'];
     $uri = @$_SERVER['REQUEST_URI'];
     $application = Stuffpress_Application::getInstance();
     $users = new Users();
     // Save the uri for debug purposes
     self::$registry->uri = $uri;
     // Do we hit our main domain ?
     if ($our_host == $this_host) {
         self::$registry->host = $our_host;
         // Is a user specified in the config ?
         if (isset($config->app->user)) {
             if ($user = $users->getUserFromUsername($config->app->user)) {
                 self::$registry->user = $user;
             }
         }
         return;
     }
     // A user storytlr page
     if (preg_match("/(?<user>[a-zA-Z0-9]+).{$our_host}\$/", $this_host, $matches)) {
         $username = $matches['user'];
         if ($user = $users->getUserFromUsername($username)) {
             if ($config->web->redirect && strlen($user->domain) > 0) {
                 if (!isset($application->user) || $application->user->id != $user->id) {
                     $url = "http://{$user->domain}{$uri}";
                     header("Location: {$url}");
                     exit;
                 }
             }
             self::$registry->host = $this_host;
             self::$registry->user = $user;
             return;
         } else {
             header("Location: http://{$our_host}");
             exit;
         }
     }
     // A or CNAME ?
     if ($user = $users->getUserFromDomain($this_host)) {
         self::$registry->host = $this_host;
         self::$registry->user = $user;
         return;
     }
     // Maybe we should strip the www in front ?
     $matches = array();
     if (preg_match("/www.(.*)/", $this_host, $matches)) {
         if ($user = $users->getUserFromDomain($matches[1])) {
             self::$registry->host = $this_host;
             self::$registry->user = $user;
             return;
         }
     }
     // Last chance
     header("Location: http://{$our_host}");
     exit;
 }
Example #13
0
 public function myDomain($cname = true)
 {
     $application = Stuffpress_Application::getInstance();
     return $application->getPublicDomain($cname);
 }
Example #14
0
 public static function _unsetInstance()
 {
     self::$_registry = null;
 }
Example #15
0
 public function init()
 {
     $this->_application = Stuffpress_Application::getInstance();
     $this->view->section = 'tools';
 }
Example #16
0
 public function preDispatch()
 {
     $this->_application = Stuffpress_Application::getInstance();
 }
Example #17
0
 public function init()
 {
     $this->_application = Stuffpress_Application::getInstance();
 }
Example #18
0
 /**
  * Returns an entry of comment
  * 
  * @param Comment 				$comment
  * @param AtomEntryAdapter|null $entry
  * @return AtomEntryAdapter
  */
 public function buildCommentEntry($comment, $item, $entry = null)
 {
     $entry = $this->_prepareEntry($entry);
     $entry->id = $this->_getCommentId($comment);
     $entry->title = $comment->getAuthorName() . "\\'s comment";
     $entry->updated = toAtomDate(strtotime($comment->getPublished()));
     //actually this is published
     $entry->published = toAtomDate(strtotime($comment->getPublished()));
     $entry->content = $this->xmlentities($comment->getText());
     $entry->content->type = AtomNS::TYPE_HTML;
     // build the activity entry
     $activityEntry = $entry->getExtension(ActivityNS::NS);
     /* @var $activityEntry ActivityEntryExtension */
     $activityEntry->addVerb(ActivityNS::POST_VERB);
     //build the activity object
     $activityObject = $activityEntry->addObject();
     $activityObject->addObjectType(ActivityNS::COMMENT_OBJECT_TYPE);
     $activityObject->id = $comment->getCommentId($comment);
     $activityObject->title = '';
     $author = $activityObject->addAuthor();
     $name = $comment->getAuthorName();
     $uri = $comment->getAuthorWebsite();
     $email = $comment->getAuthorEmail();
     if ($name != '') {
         $author->name = $name;
     }
     if ($uri != '') {
         $author->uri = $uri;
     }
     if ($email != '') {
         $author->email = $email;
     }
     $activityObject->content = $comment->getText();
     $activityObject->content->type = AtomNS::TYPE_HTML;
     // Set Alternative Link
     $objectAltLink = $activityObject->addLink();
     $objectAltLink->setRel(AtomNS::REL_ALTERNATE);
     $objectAltLink->setType('text/html');
     $objectAltLink->setHref('');
     $application = Stuffpress_Application::getInstance();
     $href = 'http://' . $this->_domain . '/api/comments/' . $this->_getObjectId($item) . '/' . $this->_getCommentId($comment);
     // Set Edit Link
     $ObjectEditLink = $activityObject->addLink();
     $ObjectEditLink->setRel(AtomNS::REL_EDIT);
     $ObjectEditLink->setHref($href);
     return $entry;
 }
Example #19
0
 public function getAccountName()
 {
     return Stuffpress_Application::getInstance()->user->username;
 }