public function deleteAction() { // Get, check and setup the parameters $story_id = $this->getRequest()->getParam("id"); //Verify if the requested story exist $stories = new Stories(); if (!($story = $stories->getStory($story_id))) { return $this->_helper->json->sendJson(false); } // Check if we are the owner if ($this->_application->user->id != $story->user_id) { return $this->_helper->json->sendJson(false); } // Ok, we can hide the item $stories->deleteStory($story_id); return $this->_helper->json->sendJson(true); }
public function viewAction() { // Get another layout $this->_helper->layout->setlayout('story'); // Get, check and setup the parameters $story_id = $this->getRequest()->getParam("id"); $page = $this->getRequest()->getParam("page"); $page = $page == '' ? 'cover' : $page; $mode = $this->getRequest()->getParam("mode"); $embed = $this->getRequest()->getParam("embed"); $length = 8; //Verify if the requested user exist $stories = new Stories(); $story = $stories->getStory($story_id); // If not, then return to the home page with an error if (!$story) { throw new Stuffpress_NotFoundException("Story {$story_id} does not exist"); } //Get the story owner data for user properties $users = new Users(); $user = $users->getUser($story->user_id); // Load the user properties $properties = new Properties(array(Stuffpress_Db_Properties::KEY => $user->id)); // Are we the owner ? if (!$embed && $this->_application->user && $this->_application->user->id == $story->user_id) { $owner = true; } else { $owner = false; } // If the page is private, go back with an error if (!$owner && $properties->getProperty('is_private')) { throw new Stuffpress_AccessDeniedException("This page has been set as private."); } // If the story is draft, go back with an error if (!$owner && $story->is_hidden) { throw new Stuffpress_AccessDeniedException("This story has not been published yet."); } // Are we in edit mode ? if ($owner && $mode == 'edit') { $edit = true; } else { $edit = false; } $data = new StoryItems(); $count = $data->getItemsCount($story_id, $edit); $pages = ceil($count / $length); // Now we can check if the page number is valid if ($page != 'cover') { if ($page < 0) { $page = 0; } else { if ($page >= $pages) { $page = $pages - 1; } } } // If page is not a cover, get the items if ($page != 'cover') { $this->view->items = $data->getItems($story_id, $length, $page * $length, $edit); } // Add the data required by the view $this->view->embed = $embed; $this->view->username = $user->username; $this->view->edit = $edit; $this->view->owner = $owner; $this->view->image = $story->thumbnail; $this->view->user_id = $user->id; $this->view->story_id = $story->id; $this->view->story_title = $story->title; $this->view->story_subtitle = $story->subtitle; $this->view->is_private = $story->is_hidden; $this->view->is_geo = $stories->isGeo($story_id); // Navigation options $this->view->page = $page; $this->view->pages = $pages; // Add a previous button $e = $embed ? "embed/{$embed}/" : ""; if ($page == 'cover') { unset($this->view->previous); } else { if ($page == 0) { $action = $edit ? "edit" : "view"; $this->view->previous = "story/{$action}/id/{$story_id}/page/cover/{$e}"; } else { if ($page != 'cover' && $page > 0) { $action = $edit ? "edit" : "view"; $this->view->previous = "story/{$action}/id/{$story_id}/page/" . ($page - 1) . "/{$e}"; } } } // Add a next button if ($page == 'cover') { $action = $edit ? "edit" : "view"; $this->view->next = "story/{$action}/id/{$story_id}/page/0/{$e}"; } else { if ($page + 1 < $pages) { $action = $edit ? "edit" : "view"; $this->view->next = "story/{$action}/id/{$story_id}/page/" . ($page + 1) . "/{$e}"; } } // Prepare the generic view // Set the timezone to the user timezone $timezone = $story->timezone ? $story->timezone : $properties->getProperty('timezone'); date_default_timezone_set($timezone); // User provided footer (e.g. tracker) $user_footer = $properties->getProperty('footer'); $this->view->user_footer = $user_footer; // Javascript $this->view->headScript()->appendFile('js/prototype/prototype.js'); $this->view->headScript()->appendFile('js/scriptaculous/scriptaculous.js'); $this->view->headScript()->appendFile('js/storytlr/validateForm.js'); $this->view->headScript()->appendFile('js/controllers/story.js'); // Page title $this->view->headTitle($story->title . " | " . $story->subtitle); // Change layout if embedding if ($embed) { $this->_helper->layout->setlayout('embed_story'); } // Page layout $this->view->title = $properties->getProperty('title'); $this->view->subtitle = $properties->getProperty('subtitle'); $this->view->footer = $properties->getProperty('footer'); $this->view->section = "story"; }
public function storyAction() { $story_id = $this->getRequest()->getParam("id"); // Hit the cache $cache_id = "embed_story_{$story_id}"; if (!$this->_cache || !($script = $this->_cache->load($cache_id))) { //Verify if the requested user exist $stories = new Stories(); $story = $stories->getStory($story_id); // If not, then return to the home page with an error if (!$story) { throw new Stuffpress_NotFoundException("Story {$story_id} does not exist"); } // If the story is draft, go back with an error if ($story->is_hidden) { throw new Stuffpress_AccessDeniedException("This story has not been published yet."); } // Get the user properties $username = $this->_user->username; $host = $this->_config->web->host; // Get the data we need $id = $story->id; $uid = rand(0, 100) . $id; $title = $story->title; $sub = $story->subtitle; $image = $story->thumbnail; $script = "document.write('<link href=\\'http://{$host}/style/embed_story.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_embed\\' onclick=\\'showStory({$uid});\\' title=\\'Click to view story\\'>');\r\n" . "document.write('<div class=\\'logo\\'><img src=\\'http://{$host}/images/coverlogo.png\\' /></div>');\r\n" . "document.write('<div class=\\'cover\\'>');\r\n"; if ($image) { $script .= "document.write('<img src=\\'" . $this->getUrl($username, "/file/view/key/{$image}") . "\\' class=\\'cover\\'>');\r\n"; } $script .= "document.write('</div>');\r\n" . "document.write('<div class=\\'titles\\'>');\r\n" . "document.write('<span class=\\'title\\' id=\\'story_title\\'>" . $this->escape($title) . "</span>');\r\n" . "document.write('<span class=\\'subtitle\\' id=\\'story_subtitle\\'>" . $this->escape($sub) . "</span>');\r\n" . "document.write('</div>');\r\n" . "document.write('</div>');\r\n" . "document.write('<div class=\\'popoutwrapper\\'><div class=\\'popout\\'><a href=\\'" . $this->getUrl($username, "/story/view/id/{$id}") . "\\' target=\\'_blank\\' >View in new window <img src=\\'http://{$host}/images/popout.gif\\' /></a></div></div>');\r\n" . "document.write('<div class=\\'storytlr_mask\\' id=\\'storytlr_mask_{$uid}\\'>');\r\n" . "document.write('</div>');\r\n" . "document.write('<div class=\\'storytlr_container\\' id=\\'storytlr_container_{$uid}\\'>');\r\n" . "document.write('<div id=\\'storytlr_page\\'>');\r\n" . "document.write('<div id=\\'storytlr_control\\'>');\r\n" . "document.write('<a href=\\'javascript:hideStory({$uid});\\' title=\\'Close story\\'><img src=\\'http://{$host}/images/close.gif\\'/></a>');\r\n" . "document.write('</div>');\r\n" . "document.write('<iframe id=\\'storytlr_frame\\' src=\\'" . $this->getUrl($username, "/story/view/id/{$id}?embed=page") . "\\' width=\\'1050px\\' height=\\'620px\\' scrolling=\\'no\\' frameborder=\\'0\\'>Your browser doe snot support this. Check the lifestream here.</iframe>');\r\n" . "document.write('</div>');\r\n" . "document.write('</div>');\r\n"; if ($this->_cache) { $this->_cache->save($script, $cache_id, array("story_{$story_id}"), 300); } } header("Content-type: text/javascript"); header("Content-Disposition: attachment; filename=\"widget.js\""); echo $script; ob_end_flush(); die; }