Example #1
0
 public function addPost($user_id, $title, $content)
 {
     $post = new Post();
     $post->savePost($user_id, $title, $content);
     $view = new PostView();
     $view->renderSavedPost();
 }
Example #2
0
 protected function makePost()
 {
     $post = new Post();
     $post->title = "titulo";
     $post->save();
     return $post;
 }
Example #3
0
 public function run()
 {
     $user = User::firstOrFail();
     $post1 = new Post();
     $post1->title = 'A Long Long';
     $post1->subtitle = 'In a Galaxy Far Far Away';
     $post1->content = 'Lorem ipsum dolor sit amet, ut numquam repudiandae vim, vix no novum saperet appellantur. Periculis signiferumque ea pri, et dolore conceptam sit. Nominavi facilisi cu vix, eos ut probatus suavitate, solum utinam epicuri ex vis. Quis appareat quaestio et sit, ei pri illud eripuit lobortis, vis modus vivendo tacimates at. Quem moderatius pri in, ut brute noster dicunt his, graeci definitiones mei an';
     $post1->image = '/img/264H.jpg';
     $post1->user_id = $user->id;
     $post1->save();
     $post2 = new Post();
     $post2->title = 'A Long Long Time';
     $post2->subtitle = 'In a Galaxy Far Far Away';
     $post2->content = 'Lorem ipsum dolor sit amet, ut numquam repudiandae vim, vix no novum saperet appellantur. Periculis signiferumque ea pri, et dolore conceptam sit. Nominavi facilisi cu vix, eos ut probatus suavitate, solum utinam epicuri ex vis. Quis appareat quaestio et sit, ei pri illud eripuit lobortis, vis modus vivendo tacimates at. Quem moderatius pri in, ut brute noster dicunt his, graeci definitiones mei an';
     $post2->image = '/img/264H.jpg';
     $post2->user_id = $user->id;
     $post2->save();
     $post3 = new Post();
     $post3->title = 'A Long Long Time Ago';
     $post3->subtitle = 'In a Galaxy Far Far Away';
     $post3->content = 'Lorem ipsum dolor sit amet, ut numquam repudiandae vim, vix no novum saperet appellantur. Periculis signiferumque ea pri, et dolore conceptam sit. Nominavi facilisi cu vix, eos ut probatus suavitate, solum utinam epicuri ex vis. Quis appareat quaestio et sit, ei pri illud eripuit lobortis, vis modus vivendo tacimates at. Quem moderatius pri in, ut brute noster dicunt his, graeci definitiones mei an';
     $post3->image = '/img/264H.jpg';
     $post3->user_id = $user->id;
     $post3->save();
 }
Example #4
0
 public function run()
 {
     $user = User::firstOrFail();
     $post1 = new Post();
     $post1->title = '1st Blog Post';
     $post1->username = '******';
     $post1->date = '2016-01-11';
     $post1->description = 'This is my first blog post on my laravel blog';
     $post1->user_id = $user->id;
     $post1->save();
     $post2 = new Post();
     $post2->title = '2nd Blog Post';
     $post2->username = '******';
     $post2->date = '2016-01-11';
     $post2->description = 'This is my second blog post.';
     $post2->user_id = $user->id;
     $post2->save();
     $post3 = new Post();
     $post3->title = '3rd Blog Post';
     $post3->username = '******';
     $post3->date = '2016-01-11';
     $post3->description = 'This is my third blog post';
     $post3->user_id = $user->id;
     $post3->save();
 }
 public function controlerJob($maincont)
 {
     if ($maincont->isLoggued()) {
         if (isset($_POST["title"])) {
             $p = new Post();
             $p->setTitle($_POST["title"]);
             $p->setBody($_POST["body"]);
             $p->setHour(date("h:i:s"));
             $p->setDate(date("Y-m-d"));
             // gestion des tags
             $tags = explode(" ", $_POST["tags"]);
             foreach ($tags as $t) {
                 if ($t == "") {
                     continue;
                 }
                 $ta = Tag::getByTag($t);
                 //echo "Tag : $t<br />";
                 if (count($ta) == 0) {
                     $mytag = new Tag();
                     $mytag->setTag($t);
                 } else {
                     $mytag = $ta[0];
                 }
                 // création du posttag liant le tag et le post
                 $pt = new Posttag();
                 $pt->setPostid($p->id);
                 $pt->setTagid($mytag->id);
             }
         }
         $maincont->goModule("post", "admin");
     } else {
         $maincont->goModule("home", "display");
     }
 }
 public function run()
 {
     $user = User::firstOrFail();
     $post1 = new Post();
     $post1->title = 'Calculator';
     $post1->body = 'Early in Codeup, I made a calculator that functions using JavaScript\'s internal math functions to do the computations. I styled the calculator to look somewhat real, and I was very happy with the glossy buttons I was able to make with some CSS befores and afters. I was also able to approximate the old school real LED display with some CSS gradients. Lastly, there\'s a not-at-all subtle Star Wars reference on the calculator in the lower left corner. Anyone catch the reference?';
     $post1->image_url = 'img/cal.png';
     $post1->user_id = $user->id;
     $post1->save();
     $post2 = new Post();
     $post2->title = 'Weather API';
     $post2->body = 'I got to say that the weather API was a lot of fun. It was incredible to see the two APIs (Open Weather and Google Maps) come together and see how AJAX requests work with JavaScript and jQuery. I kept the CSS simple here, but I like the layout in those square units I created. I feel like it gets the important info out there in a format that is easy to read and look at. I am especially proud of the search area which has the added reverse address look up. Normally, one types in an address and gets the weather for that location. But if one drags the map pin, the search area will also display an address for that location as well. Very neat!';
     $post2->image_url = 'img/weather.png';
     $post2->user_id = $user->id;
     $post2->save();
     $post3 = new Post();
     $post3->title = 'Simon Says';
     $post3->body = 'Simon Says was my first game using JavaScript and jQuery. I did my best to make my Simon to look like the childhood favorite of yesteryear. I\'m so happy with the name plate area. That CSS was a blast to figure out with the metalic shine and realistic buttons! Of course, the real star of this game is the jQuery animations that make it all work.';
     $post3->image_url = 'img/simon.png';
     $post3->user_id = $user->id;
     $post3->save();
     $post4 = new Post();
     $post4->title = 'Whack-a-mole';
     $post4->body = 'Or Whack-a-gopher as I\'ve made it! This game was an amazing build and it was so much fun! I admit it, I got carried away with making each and every game element out of HTML and CSS. I used no images whatsoever! And I think it was totally worth it. This is also where I started to really become fond of CSS animations as I figured out how to make each gopher spin like a 3D game piece upon being clicked. ';
     $post4->image_url = 'img/mole.png';
     $post4->user_id = $user->id;
     $post4->save();
     $post5 = new Post();
     $post5->title = 'Spatula City';
     $post5->body = 'Or our ad lister/Craigslist clone. I made this call-back to the 80s and Weird Al with Zeshan Segal and Reagan Wilkins. Together I think we made a fantastic site for selling and buying spatulas of all sorts, shapes and colors! I was responsible for the ad create form, the ad edit form, and the ads DB table. It was challenging to make the ad edit form which retrieved data from the DB for it to be altered. I also built the ads index page and the ads show pages. Within those two pages, I am super pleased with the categories bar that allows one to filter the ads showing on the ads index page in real time. I used PHP\'s ability to query MySQL and added a change listener with jQuery to submit the radio button selected. That was a great breakthrough for me. To showcase this project, which was never a live site, I have decided to show a few screenshots. Each screenshot shows one of the items I worked to develop such as the navbar, the ads index page (aka the Product page), and the deals page (the dancing spatulas).';
     $post5->image_url = 'img/adlister.png';
     $post5->user_id = $user->id;
     $post5->save();
 }
 public function testCounterIncrementsAndDecrementsWhen()
 {
     $post_with_comments = new Post();
     $post_with_comments->title = 'post 1';
     $this->assertTrue($post_with_comments->save());
     $post_without_comments = new Post();
     $post_without_comments->title = 'post 2';
     $this->assertTrue($post_without_comments->save());
     //Create 10 comments, ensure counter increments
     for ($i = 1; $i <= 10; $i++) {
         $comment = new Comment();
         $comment->postId = $post_with_comments->id;
         $comment->text = 'comment ' . $i;
         $this->assertTrue($comment->save());
         $post_with_comments->refresh();
         $post_without_comments->refresh();
         $this->assertEquals($post_with_comments->commentsCount, $i);
         $this->assertEquals($post_without_comments->commentsCount, 0);
     }
     //Delete all comments, ensure counter decrements
     $comments = Comment::find()->all();
     $count = count($comments);
     foreach ($comments as $comment) {
         $this->assertEquals($comment->delete(), 1);
         $count--;
         $post_with_comments->refresh();
         $this->assertEquals($post_with_comments->commentsCount, $count);
     }
 }
Example #8
0
 /**
  * 录入
  *
  */
 public function actionCreate()
 {
     parent::_acl();
     $model = new Post();
     $attr = $this->_gets->getPost('attr');
     $imageList = $this->_gets->getPost('imageList');
     $imageListSerialize = XUtils::imageListSerialize($imageList);
     if (isset($_POST['Post'])) {
         $style = $this->_gets->getPost('style');
         $acl = $this->_gets->getPost('acl');
         $styleFormat = XUtils::titleStyle($style);
         $file = XUpload::upload($_FILES['attach'], array('thumb' => true, 'thumbSize' => array(400, 250)));
         $model->attributes = $_POST['Post'];
         if (is_array($file)) {
             $model->attach_status = 'Y';
             $model->attach_file = $file['pathname'];
             $model->attach_thumb = $file['paththumbname'];
         }
         $model->title_style = $styleFormat['text'];
         $model->title_style_serialize = $styleFormat['serialize'];
         $model->acl = is_array($acl) ? implode(',', $acl) : '';
         $model->image_list = $imageListSerialize['dataSerialize'];
         if ($model->save()) {
             Attr::create($model->id, $attr);
             Post2tags::build('create', $_POST['Post']['tags'], $model->id, $model->catalog_id);
             AdminLogger::_create(array('catalog' => 'create', 'intro' => '录入内容,ID:' . $model->id));
             $this->redirect(array('index'));
         }
     }
     $attrData = Attr::dataReset($attr);
     $attrModel = Attr::lists($model->catalog_id, 'post');
     $this->render('create', array('model' => $model, 'imageList' => $imageListSerialize['data'], 'attrModel' => $attrModel, 'attrData' => $attrData));
 }
Example #9
0
 public function archiveMonths()
 {
     $postManager = new Post();
     $sql = "SELECT DISTINCT DATE_FORMAT(posted_at, '%Y') AS year, DATE_FORMAT(posted_at, '%m') AS month FROM posts WHERE is_active = 1 ORDER BY year DESC, month DESC";
     $res = $postManager->getAdapter()->query($sql)->fetchAll();
     return $res;
 }
Example #10
0
 /**
  * return the string to appear in the history
  *
  * @param Post $post
  * @return string
  */
 public static function toHistoryString($post)
 {
     $controller = sfContext::getInstance()->getController();
     $link = $controller->genUrl('@view_thread?thread_id=' . $post->getThreadId());
     $link = sprintf('<a href="%s">%s</a>', $link, 'forum thread');
     return sprintf('posted on a %s', $link);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function postCreate()
 {
     $rules = array('name' => 'required|min:3');
     $validator = Validator::make(Input::all(), $rules);
     // Check if the form validates with success
     if ($validator->passes()) {
         $this->escalations->name = Input::get('name');
         $this->escalations->delay = (int) Input::get('delay');
         $this->escalations->reply = Input::get('reply');
         $this->escalations->notify_admins = (int) Input::get('notify_admins');
         $this->escalations->flag = (int) Input::get('flag');
         $this->escalations->priority = json_encode(Input::get('priorities'));
         $this->escalations->new_status = (int) Input::get('new_status');
         $this->escalations->new_priority = (int) Input::get('new_priority');
         $this->escalations->new_department = (int) Input::get('new_department');
         $this->escalations->saveDeps(Input::get('departments'));
         $this->escalations->saveStatuses(Input::get('statuses'));
         $this->escalations->saveFlags(explode(',', Input::get('flags')));
         if ($this->escalations->save()) {
             return Api::to(array('success', Lang::get('l4cp-support::messages.create.success'))) ?: Redirect::to('admin/support/escalations/' . $this->escalations->id . '/edit')->with('success', Lang::get('l4cp-support::messages.create.success'));
         } else {
             return Api::to(array('error', Lang::get('l4cp-support::messages.create.error'))) ?: Redirect::to('admin/support/escalations/create')->with('error', Lang::get('l4cp-support::messages.create.error'));
         }
     } else {
         return Api::to(array('error', Lang::get('l4cp-support::messages.create.error'))) ?: Redirect::to('admin/support/escalations/create')->withInput()->withErrors($validator);
     }
 }
Example #12
0
 public function editPost(Post $post)
 {
     $STH = $this->DBH->prepare("UPDATE Posts SET textpost=:textpost, title=:title\n            WHERE id=:id");
     $STH->bindValue(":textpost", $post->getTextpost());
     $STH->bindValue(":title", $post->getTitle());
     $STH->execute();
 }
 public function send()
 {
     $author = !empty($_POST['author']) ? strip_tags($_POST['author']) : '';
     $content = !empty($_POST['content']) ? htmlspecialchars($_POST['content']) : '';
     $errors = array();
     if (!empty($_POST)) {
         $post = new Post();
         foreach ($_POST as $key => $value) {
             try {
                 $post->{$key} = $value;
             } catch (Exception $e) {
                 $errors[$key] = $e->getMessage();
             }
         }
         if (empty($errors)) {
             $result_id = $post->insert();
             if ($result_id > 0) {
                 header('Location: post.php?id=' . $result_id);
                 exit;
             }
             $errors['internal error'] = 'An error occured, please try again later';
         }
     }
     $vars = array('author' => $author, 'content' => $content, 'errors' => $errors);
     Post::displayTemplate('send.tpl', $vars);
 }
Example #14
0
 /**
  * inserts a new comment
  *
  * @param $data array
  *
  * @return int(id)|string(error)
  */
 public static function new_comment($data)
 {
     $database = new Database();
     $post = new Post();
     $PostID = $data['post_id'];
     $content = $data['content'];
     $token = $data['token'];
     if (empty(trim($content))) {
         die("Comment can't be empty");
     }
     $qna = new QNA();
     if (!is_object($qna->get_question($PostID)) && !is_array($post->get_post($PostID, true))) {
         die("Error! Post was not found.");
     }
     if (!Token::validateToken($token)) {
         die("Error! Please try again later");
     }
     unset($data['token']);
     $data['uid'] = USER_ID;
     $insert = $database->insert_data(TABLE_COMMENTS, $data);
     if ($insert === true && $database->error === false) {
         // success
         return (int) $database->lastId;
     } else {
         return array_shift($database->errors);
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function postCreate()
 {
     $rules = array('name' => 'required|min:3', 'flags' => 'required');
     $validator = Validator::make(Input::all(), $rules);
     // Check if the form validates with success
     if ($validator->passes()) {
         $this->department->name = Input::get('name');
         $this->department->description = Input::get('description');
         $this->department->email = Input::get('email');
         $this->department->pop_host = Input::get('pop_host');
         $this->department->pop_port = Input::get('pop_port');
         $this->department->pop_user = Input::get('pop_user');
         $this->department->pop_pass = Input::get('pop_pass');
         $this->department->clients_only = (int) Input::get('clients_only');
         $this->department->auto_respond = (int) Input::get('auto_respond');
         $this->department->hidden = (int) Input::get('hidden');
         $this->department->sort = (int) Input::get('sort');
         $this->department->saveFlags(Input::get('flags'));
         if ($this->department->save()) {
             return Api::to(array('success', Lang::get('l4cp-support::messages.create.success'))) ?: Redirect::to('admin/support/departments/' . $this->department->id . '/edit')->with('success', Lang::get('l4cp-support::messages.create.success'));
         } else {
             return Api::to(array('error', Lang::get('l4cp-support::messages.create.error'))) ?: Redirect::to('admin/support/departments/create')->with('error', Lang::get('l4cp-support::messages.create.error'));
         }
     } else {
         return Api::to(array('error', Lang::get('l4cp-support::messages.create.error'))) ?: Redirect::to('admin/support/departments/create')->withInput()->withErrors($validator);
     }
 }
Example #16
0
 public function viewAction()
 {
     $label = $this->_getParam('label');
     if ($label === null) {
         throw new Zend_Exception('No label specified in TagsController::viewAction()');
     }
     $tagManager = new Tag();
     $tag = $tagManager->fetchRow(array('label = ?' => $label));
     if ($tag === null) {
         throw new Zend_Exception('Tag not found in TagsController::viewAction()');
     }
     $this->view->tag = $tag;
     // get posts
     $page = array_key_exists('p', $_GET) ? $_GET['p'] : 1;
     $page = $page < 1 ? 1 : $page;
     $this->view->page = $page;
     $postManager = new Post();
     $postCount = $postManager->fetchAll(array('id IN (SELECT post_id FROM posts_tags WHERE tag_id = ?)' => $tag->id, 'is_active = ?' => 1))->count();
     $this->view->pageCount = ceil($postCount / 10);
     $this->view->posts = $postManager->fetchAll(array('id IN (SELECT post_id FROM posts_tags WHERE tag_id = ?)' => $tag->id, 'is_active = ?' => 1), 'posted_at DESC', 10, ($page - 1) * 10);
     $this->view->paginationBase = '/tags/' . $tag->label;
     // description
     $this->view->metaDescription = 'Read my posts tagged with \'' . $tag->title . '\'.';
     // set title
     $this->_title('Posts tagged with \'' . $tag->title . '\'');
     $this->_forward('listing', 'posts');
 }
 /**
  * Prepare sidebar data, random tags and archive list
  */
 private function prepareSidebar()
 {
     //if tags cache exist, skip retrieving from DB, expires every 5 minutes
     $cacheTagOK = Doo::cache('front')->testPart('sidebarTag', 300);
     if (!$cacheTagOK) {
         echo '<h2>Cache expired. Get Tags from DB!</h2>';
         //get random 10 tags
         Doo::loadModel('Tag');
         $tags = new Tag();
         $this->data['randomTags'] = $tags->limit(10, null, null, array('custom' => 'ORDER BY RAND()'));
     } else {
         $this->data['randomTags'] = array();
     }
     //if archive cache exist, skip retrieving from DB, archive expires when Post added, updated, deleted
     $cacheArchiveOK = Doo::cache('front')->testPart('sidebarArchive', 31536000);
     if (!$cacheArchiveOK) {
         echo '<h2>Cache expired. Get Archives from DB!</h2>';
         //you can pass data to constructor to set the Model properties
         Doo::loadModel('Post');
         $p = new Post(array('status' => 1));
         $this->data['archives'] = $p->getArchiveSummary();
     } else {
         $this->data['archives'] = array();
     }
 }
Example #18
0
function parseItem($blog, $item, $ts)
{
    if ($ts != 0 && $item->pubdate <= $ts) {
        logmsg('Zatrzymanie na wpisie: %s', StringUtils::removeAccents($item->title));
        return false;
    }
    logmsg('  - Parsowanie wpisu: %s', StringUtils::removeAccents($item->title));
    $post = new Post();
    $post->setBlog($blog);
    foreach ($item->tags as $name) {
        $tag = TagPeer::retriveByName($name, true);
        if ($post->addTag($tag)) {
            logmsg('    - Znaleziono tag: %s', $name);
        }
    }
    if ($post->hasTags()) {
        $shortened = $post->setFullContent($item->content);
        $post->setLink(htmlspecialchars($item->link));
        $post->setTitle($item->title);
        $post->setCreatedAt($item->pubdate);
        $post->setShortened($shortened);
        $post->save();
    } else {
        logmsg('    - Nie znaleziono tagow');
    }
    return true;
}
 protected function makePost()
 {
     $post = new Post();
     $post->text = 'Some title';
     $post->save();
     return $post;
 }
Example #20
0
 public function run()
 {
     $user = User::firstOrFail();
     $post1 = new Post();
     $post1->title = 'Zee\'s first blog';
     $post1->body = 'This is a blog post about my time creating my personal website. It has been interesting.';
     $post1->user_id = $user->id;
     $post1->save();
     $post2 = new Post();
     $post2->title = 'What new language should I learn? ';
     $post2->body = 'there has been plenty of talk about Python and Ruby. I don\'t know which way to go. But, I think Javascript is where I am going to focus mos tof my practice.... for now.';
     $post2->user_id = $user->id;
     $post2->save();
     $post3 = new Post();
     $post3->title = 'Codeup is where this was created.';
     $post3->body = 'Codeup is where I spent the last 6 months developing my skills as a software engineer. Locate din the heart of San Antonio, it has helped a few hundred folks get into the coding world.';
     $post3->user_id = $user->id;
     $post3->save();
     $post4 = new Post();
     $post4->title = 'Practice, Practice, Practice';
     $post4->body = 'Practice makes perfect, right? Well I need to keep developing my skills. Upddating and changing my website as needed.';
     $post4->user_id = $user->id;
     $post4->save();
     $post5 = new Post();
     $post5->title = 'This is a blog post about my life.';
     $post5->body = 'Born and raised in DFW, I moved to Austin at 18 years old. I have loved it ever since. It is the only city I have ever called home.';
     $post5->user_id = $user->id;
     $post5->save();
 }
 public function run()
 {
     $user = User::firstOrFail();
     $post1 = new Post();
     $post1->title = 'First post';
     $post1->subtitle = 'This is a subtitle';
     $post1->content = 'It is super easy to create a new post.';
     $post1->image = 'This is an image';
     $post1->user_id = $user->id;
     $post1->save();
     $post2 = new Post();
     $post2->title = 'Second post';
     $post2->subtitle = 'This is a subtitle';
     $post2->content = 'It is super easy to create a new post.';
     $post2->image = 'This is an image';
     $post2->user_id = $user->id;
     $post2->save();
     $post3 = new Post();
     $post3->title = 'Third post';
     $post3->subtitle = 'This is a subtitle';
     $post3->content = 'It is super easy to create a new post.';
     $post3->image = 'This is an image';
     $post3->user_id = $user->id;
     $post3->save();
     $post4 = new Post();
     $post4->title = 'Fourth post';
     $post4->subtitle = 'This is a subtitle';
     $post4->content = 'It is super easy to create a new post.';
     $post4->image = 'This is an image';
     $post4->user_id = $user->id;
     $post4->save();
 }
 /**
  * View a blog post.
  *
  * @param  string  $slug
  * @return Redirect
  */
 public function postView($slug)
 {
     $user = $this->user->currentUser();
     $canComment = $user->can('post_comment');
     if (!$canComment) {
         return Redirect::to($slug . '#comments')->with('error', 'You need to be logged in to post comments!');
     }
     // Get this blog post data
     $post = $this->post->where('slug', '=', $slug)->first();
     // Declare the rules for the form validation
     $rules = array('comment' => 'required|min:3');
     // Validate the inputs
     $validator = Validator::make(Input::all(), $rules);
     // Check if the form validates with success
     if ($validator->passes()) {
         // Save the comment
         $comment = new Comment();
         $comment->user_id = Auth::user()->id;
         $comment->content = Input::get('comment');
         // Was the comment saved with success?
         if ($post->comments()->save($comment)) {
             // Redirect to this blog post page
             return Redirect::to($slug . '#comments')->with('success', 'Your comment was added with success.');
         }
         // Redirect to this blog post page
         return Redirect::to($slug . '#comments')->with('error', 'There was a problem adding your comment, please try again.');
     }
     // Redirect to this blog post page
     return Redirect::to($slug)->withInput()->withErrors($validator);
 }
Example #23
0
 public function store()
 {
     $files = Input::file('path');
     $filesStatus = Input::get('file_status');
     $status = 'success';
     if ($files == null) {
         Session::flash('status', 'false');
         $errors_message[] = "Over max upload size!";
         Session::flash('errors_message', $errors_message);
         return Redirect::to('user/upload')->header('Cache-Control', 'no-store, no-cache');
     }
     foreach ($files as $index => $file) {
         if ($file->isValid() && $filesStatus[$index] != 0) {
             $post = new Post();
             $post->save();
             $album = $this->saveAlbum($index, $post);
             if ($album) {
                 if (!$this->saveImage($index, $album->id, $post)) {
                     $status = 'false';
                     break;
                 }
             } else {
                 $status = 'false';
                 break;
             }
         }
     }
     Session::flash('status', $status);
     return Redirect::to('album/create')->header('Cache-Control', 'no-store, no-cache');
 }
Example #24
0
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     // Delete the notice from database
     $this->notice->delete();
     // Fire Event and Listeners
     event(new DeletedNotice($this->notice));
 }
Example #25
0
 public function run()
 {
     $faker = Faker::create();
     for ($i = 0; $i < 30; $i++) {
         $tags = ['funny', 'troll', 'sad', 'current', 'serious', 'music', 'gaming', 'technology', 'business'];
         $j = 0;
         $tempArray = [];
         $randomNum = mt_rand(1, 3);
         $post = new Post();
         $post->title = $faker->catchPhrase . " " . $faker->catchPhrase;
         $post->body = $faker->realText(200, 2);
         $post->picture = $faker->image($dir = '/tmp', $width = 640, $height = 480);
         $post->user_id = User::all()->random(1)->id;
         do {
             $tag = $tags[mt_rand(0, sizeof($tags) - 1)];
             if ($j <= 1) {
                 array_push($tempArray, $tag);
                 unset($tags[$tag]);
             } else {
                 $tempArray = ["{$tag}"];
                 unset($tags[$tag]);
             }
             //var j to determine how many elements have been pushed
             $j++;
             $randomNum--;
         } while ($randomNum == 0);
         $post->tags = implode(", ", $tempArray);
         $post->save();
     }
 }
Example #26
0
 /**
  * 查看专题
  */
 public function actionShow($name)
 {
     $specialModel = Special::model()->find('title_alias=:titleAlias', array('titleAlias' => CHtml::encode(strip_tags($name))));
     if (false == $specialModel) {
         throw new CHttpException(404, '专题不存在');
     }
     //更新浏览次数
     $specialModel->updateCounters(array('view_count' => 1), 'id=:id', array('id' => $specialModel->id));
     $specialPostModel = new Post();
     $criteria = new CDbCriteria();
     $criteria->addCondition('t.status_is=:status AND special_id=:specialId');
     $criteria->params = array('status' => 'Y', 'specialId' => $specialModel->id);
     $criteria->order = 't.id DESC';
     $bagecmsSpecialCount = $specialPostModel->count($criteria);
     $postPage = new CPagination($bagecmsSpecialCount);
     $postPage->pageSize = 10;
     $postPageParams = XUtils::buildCondition($_GET, array());
     $postPageParams['#'] = 'list';
     $postPage->params = is_array($postPageParams) ? $postPageParams : array();
     $criteria->limit = $postPage->pageSize;
     $criteria->offset = $postPage->currentPage * $postPage->pageSize;
     $specialPostList = $specialPostModel->findAll($criteria);
     $this->_seoTitle = empty($specialModel->seo_title) ? $specialModel->title . ' - ' . $this->_conf['site_name'] : $specialModel->seo_title;
     $tpl = empty($specialModel->tpl) ? 'show' : $specialModel->tpl;
     $data = array('specialShow' => $specialModel, 'specialPostList' => $specialPostList, 'bagecmsPagebar' => $postPage);
     $this->render($tpl, $data);
 }
Example #27
0
 function parse()
 {
     $x = new DOMXPath($this->dom);
     $paragraphes = $x->evaluate('//*[@id="posts"]/li[ @id and not( contains(@class,"with_avatar") ) and not(@class="post") ]', $x->document);
     // prevent to leak sessionkey via referer.
     $anchors = $x->evaluate('//*[@id="posts"]/li//a', $x->document);
     foreach ($anchors as $k => $v) {
         $u = $v->getAttribute('href');
         if (preg_match('%^http://%i', $u)) {
             $u = to_mobile_url($u);
             $v->setAttribute('href', $u);
             $u = $v->getAttribute('href');
         }
     }
     $images = $x->evaluate('//*[@id="posts"]/li//img[ not(ancestor::li[contains(@class,"photo")]) ]', $x->document);
     foreach ($images as $k => $v) {
         $u = $v->getAttribute('src');
         if (!preg_match('%^http:\\/\\/(media|data|assets)\\.tumblr\\.com%i', (string) $u)) {
             $v->setAttribute('xOriginalsrc', $u);
             $v->setAttribute('src', '');
         }
     }
     $posts = array();
     foreach ($paragraphes as $k => $paragraph) {
         $posts[] = $p = new Post($x, $paragraph);
         $p->getPostInfo();
     }
     $this->posts = $posts;
 }
Example #28
0
 public function run()
 {
     $user = User::firstOrFail();
     $post1 = new Post();
     $post1->title = "Title 1";
     $post1->content = "Content 1";
     $post1->user_id = $user->id;
     $post1->save();
     $post2 = new Post();
     $post2->title = "Title 2";
     $post2->content = "Content 2";
     $post2->user_id = $user->id;
     $post2->save();
     $post3 = new Post();
     $post3->title = "Title 3";
     $post3->content = "Content 3";
     $post3->user_id = $user->id;
     $post3->save();
     $post4 = new Post();
     $post4->title = "Title 4";
     $post4->content = "Content 4";
     $post4->user_id = $user->id;
     $post4->save();
     $post5 = new Post();
     $post5->title = "Title 5";
     $post5->content = "Content 5";
     $post5->user_id = $user->id;
     $post5->save();
 }
Example #29
0
 public function populyar_post_by_visits()
 {
     $post = new Post();
     $posts = $post->order_by('time_created', 'desc');
     $posts = $posts->get();
     $res = $this->like('page', 'blog/post/', 'after')->get();
     $sluge = array();
     foreach ($res->all as $key => $value) {
         $post = explode('/', $value->page);
         if ($post[1] == 'post') {
             if (array_key_exists($post[2], $sluge)) {
                 $sluge[$post[2]]++;
             } else {
                 $sluge[$post[2]] = 1;
             }
         }
     }
     foreach ($posts->all as $post_key => $post_value) {
         if (!array_key_exists($post_value->slug, $sluge)) {
             $sluge[$post_value->slug] = 0;
         }
     }
     arsort($sluge);
     return $sluge;
 }
Example #30
0
 protected function makePost()
 {
     $post = new Post();
     $post->title = str_random(10);
     $post->save();
     return $post;
 }