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'); }
public static function slug($title) { $title = (string) $title; $title = strtolower($title); $title = trim($title); $title = substr($title, 0, 75); $title = Stuffpress_Permalink::removeaccents($title); $title = preg_replace('/[^a-z0-9- ]/', '', $title); // remove all non-alphanumeric characters except for spaces and hyphens $title = str_replace(' ', '-', $title); return $title; }
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; }
public function addItem($data, $timestamp, $type, $tags=false, $location=false, $hidden=false, $title=false) { $data['source_id'] = $this->_source['id']; $columns = array(); $keys = array(); $timestamp = ($timestamp>=0) ? $timestamp : 0; foreach($data as $k => $v) { unset($data[$k]); if (!$v) continue; $columns[] = "$k"; $keys[] = ":$k"; $data[":$k"] = "$v"; } $sql = "INSERT IGNORE INTO {$this->_name} (".implode(',', $columns).") " . "VALUES(".implode(',', $keys).")"; $this->_db->query($sql, $data); if (!$id = (int) $this->_db->lastInsertId()) { return; } $data_table = $this->getDataTable(); $data_table->addItem($id, $this->_source['id'], $this->_source['user_id'], $this->_prefix, $type, $timestamp, $hidden); $data_table->setTags($this->_source['id'], $id, $tags); $data_table->setSlug($this->_source['id'], $id, Stuffpress_Permalink::entry($this->_source['id'], $id, $title)); if ($location) { $latitude = @$location['latitude']; $longitude = @$location['longitude']; $elevation = @$location['elevation']; $accuracy = @$location['accuracy']; if ($latitude && $longitude) { $data_table->setLocation($this->_source['id'], $id, $latitude, $longitude, $elevation, $accuracy); } } return $id; }