// Following $deletePosts = $addPosts = $deleteUsers = $addUsers = array(); use app\models\User; use app\models\Post; use Exception; // for clarity's sake foreach ($data as $userData) { try { echo "Looking for User # " . $userData->uid . "\n"; $user = User::get($userData->uid); echo "User '" . $user . "' found\n"; // following posts foreach ($userData->posts as $postData) { list($_pid, $_status) = $postData; try { $post = Post::get($_pid); if ($_status) { $user->stopFollowingPost($post); echo "- User '" . $user . "' stopped following Post '" . $post . "'\n"; } else { $user->startFollowingPost($post); echo "+ User '" . $user . "' started following Post '" . $post . "'\n"; } } catch (Exception $ex2) { // Care! } } // following users foreach ($userData->users as $followUserData) { list($_uid, $_status) = $followUserData; $followUser = User::get($_uid);
public function add_post() { $validator = models\Post::validator('add'); if (!empty($_POST)) { if ($validator->validate($_POST)) { $insert = $validator->output; $insert['author_id'] = $this->user->UserID(); $insert['created_on'] = time(); if ($pid = models\Post::insert($insert)) { $post = models\Post::get($pid); Session::success('Post Created. Look:'); // Send e-mail to $this->user's followers /* foreach ( $this->user->user->followers AS $user ) { Email::make($user->email, 'New post by '.$user, $user.' posted a new message on the blog. Read it at '.$post->url(array('absolute' => true)))->send(); }*/ $this->_redirect($post->url()); } Session::error('Couldn\'t save... =( Try again!?'); } } $categories = $validator->options->categories; $messages = Session::messages(); return $this->tpl->display('blog/post_form', get_defined_vars()); }
public function post($slug) { $post = Post::get($slug); return view('posts.show')->withPost($post); }