コード例 #1
0
 public function indexAction()
 {
     // To do before anything else
     $this->initPage();
     // Get, check and setup the parameters
     $page = $this->getRequest()->getParam("page");
     $tab = $this->getRequest()->getParam("tab");
     // A bit of filtering
     $page = $page >= 0 ? $page : 0;
     $count = 25;
     // Get the list of stories
     $storiesTable = new Stories();
     $stories = $storiesTable->getStories($count, $page * $count, $this->_admin);
     // Update stories with few gimicks and assign to view
     foreach ($stories as &$story) {
         $story['permalink'] = Stuffpress_Permalink::story($story['id'], $story['title']);
         $story['is_geo'] = $storiesTable->isGeo($story['id']);
     }
     $this->view->stories = $stories;
     // Navigation options
     $this->view->page = $page;
     $this->view->hasprevious = $page > 0 ? true : false;
     $this->view->hasnext = isset($items) && count($items) >= $count ? true : false;
     $this->view->nextlink = "home?tab={$tab}&page=" . ($page + 1);
     $this->view->previouslink = "home?tab={$tab}&page=" . ($page - 1);
     // Prepare the common elements
     $this->common();
     // Add page specific elements
     $this->view->headScript()->appendFile('js/controllers/stories.js');
 }
コード例 #2
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
         $host = $this->_config->web->host;
         // 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='http://{$username}.{$host}/story/{$item['permalink']}'>";
                 if ($item['thumbnail']) {
                     $item_content .= "<img src='" . $this->getUrl($username, "/thumbnail/{$item['thumbnail']}") . "'>";
                 } else {
                     $item_content .= "<img src='" . $this->getUrl($username, "/images/book50.jpg") . "'>";
                 }
                 $item_content .= "</a></td>";
                 $item_content .= "<td class='overview'>";
                 $item_content .= "<div class='title'><a href='" . $this->getUrl($username, "/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='http://{$host}/style/embed_stories.css' media='screen, projection' rel='stylesheet' type='text/css' />\");\r\n" . "document.write('<script src=\\'http://{$host}/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='http://{$host}'><img src='http://{$host}/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;
 }