public function delete($f3) { $id = $f3->get('PARAMS.3'); $u = $this->Model->Users->fetch($id); if ($id == $this->Auth->user('id')) { \StatusMessage::add('You cannot remove yourself', 'danger'); return $f3->reroute('/admin/user'); } //Remove all posts and comments $posts = $this->Model->Posts->fetchAll(array('user_id' => $id)); foreach ($posts as $post) { $post_categories = $this->Model->Post_Categories->fetchAll(array('post_id' => $post->id)); foreach ($post_categories as $cat) { $cat->erase(); } $post->erase(); } $comments = $this->Model->Comments->fetchAll(array('user_id' => $id)); foreach ($comments as $comment) { $comment->erase(); } $u->erase(); \StatusMessage::add('User has been removed', 'success'); return $f3->reroute('/admin/user'); }
public function delete($f3) { $pagename = $f3->get('PARAMS.3'); $this->Model->Pages->delete($pagename); \StatusMessage::add('Page deleted succesfully', 'success'); return $f3->reroute('/admin/page'); }
public function index($f3) { if ($this->request->is('post')) { extract($this->request->data); $from = "From: {$from}"; mail($to, $subject, $message, $from); StatusMessage::add('Thank you for contacting us'); return $f3->reroute('/'); } }
public function beforeRoute($f3) { parent::beforeRoute($f3); //Check access of user $access = $this->Auth->user('level'); //No access if not logged in if (empty($access)) { \StatusMessage::add('Access Denied', 'danger'); return $f3->reroute('/'); } }
public function edit($f3) { $categoryid = $f3->get('PARAMS.3'); $category = $this->Model->Categories->fetchById($categoryid); if ($this->request->is('post')) { $category->title = $this->request->data['title']; $category->save(); \StatusMessage::add('Category updated succesfully', 'success'); return $f3->reroute('/admin/category'); } $f3->set('category', $category); }
public function edit($f3) { $id = $f3->get('PARAMS.3'); $comment = $this->Model->Comments->fetch($id); if ($this->request->is('post')) { $comment->copyfrom('POST'); $comment->save(); \StatusMessage::add('Comment updated succesfully', 'success'); return $f3->reroute('/admin/comment'); } $_POST = $comment; $f3->set('comment', $comment); }
public function index($f3) { $settings = $this->Model->Settings->fetchAll(); if ($this->request->is('post')) { foreach ($settings as $setting) { if (isset($this->request->data[$setting->setting])) { $setting->value = $this->request->data[$setting->setting]; $setting->save(); } else { $setting->value = 0; $setting->save(); } } \StatusMessage::add('Settings updated', 'success'); } $f3->set('settings', $settings); }
public function edit($f3) { $categoryid = $f3->get('PARAMS.3'); // get the ID of the category and if that empty return back to same page! $category = $this->Model->Categories->fetchById($categoryid); if (empty($category)) { \StatusMessage::add('Invalid post', 'danger'); return $f3->reroute('/admin/category'); } if ($this->request->is('post')) { $category->title = $this->request->data['title']; $category->save(); \StatusMessage::add('Category updated succesfully', 'success'); return $f3->reroute('/admin/category'); } $f3->set('category', $category); }
public function edit($f3) { $postid = $f3->get('PARAMS.3'); $post = $this->Model->Posts->fetchById($postid); $blog = $this->Model->map($post, array('post_id', 'Post_Categories', 'category_id'), 'Categories', false); if ($this->request->is('post')) { extract($this->request->data); $post->copyfrom('POST'); $post->modified = mydate(); $post->user_id = $this->Auth->user('id'); //Determine whether to publish or draft if (!isset($Publish)) { $post->published = null; } else { $post->published = mydate($published); } //Save changes $post->save(); $link = $this->Model->Post_Categories; //Remove previous categories $old = $link->fetchAll(array('post_id' => $postid)); foreach ($old as $oldcategory) { $oldcategory->erase(); } //Now assign new categories if (!isset($categories)) { $categories = array(); } foreach ($categories as $category) { $link->reset(); $link->category_id = $category; $link->post_id = $postid; $link->save(); } \StatusMessage::add('Post updated succesfully', 'success'); return $f3->reroute('/admin/blog'); } $_POST = $post->cast(); foreach ($blog['Categories'] as $cat) { if (!$cat) { continue; } $_POST['categories'][] = $cat->id; } $categories = $this->Model->Categories->fetchList(); $f3->set('categories', $categories); $f3->set('post', $post); }
public function profile($f3) { $id = $this->Auth->user('id'); extract($this->request->data); $u = $this->Model->Users->fetch($id); if ($this->request->is('post')) { $u->copyfrom('POST'); //Handle avatar upload if (isset($_FILES['avatar']) && isset($_FILES['avatar']['tmp_name']) && !empty($_FILES['avatar']['tmp_name'])) { $allowedTypes = array(IMAGETYPE_PNG, IMAGETYPE_JPEG); $detectedType = exif_imagetype($_FILES['avatar']['tmp_name']); if (!in_array($detectedType, $allowedTypes) || $_FILES['avatar']['size'] > 2 * 1024 * 1024 || !getimagesize($_FILES['avatar']['tmp_name'])) { \StatusMessage::add('Invalid image', 'danger'); return $f3->reroute('/user/profile'); } $ext = end(explode(".", $_FILES['avatar']['name'])); $_FILES['avatar']['name'] = "avatar_of_user_" . $id . "." . $ext; $url = File::Upload($_FILES['avatar']); $u->avatar = $url; } else { if (isset($reset)) { $u->avatar = ''; } } $u->save(); \StatusMessage::add('Profile updated succesfully', 'success'); return $f3->reroute('/user/profile'); } $_POST = $u->cast(); $f3->set('u', $u); }
public function search($f3) { if ($this->request->is('post')) { extract($this->request->data); $f3->set('search', $search); //Get search results $search = str_replace("*", "%", $search); //Allow * as wildcard $ids = $this->db->connection->exec("SELECT id FROM `posts` WHERE `title` LIKE \"%{$search}%\" OR `content` LIKE '%{$search}%'"); $ids = Hash::extract($ids, '{n}.id'); if (empty($ids)) { StatusMessage::add('No search results found for ' . $search); return $f3->reroute('/blog/search'); } //Load associated data $posts = $this->Model->Posts->fetchAll(array('id' => $ids)); $blogs = $this->Model->map($posts, 'user_id', 'Users'); $blogs = $this->Model->map($posts, array('post_id', 'Post_Categories', 'category_id'), 'Categories', false, $blogs); $f3->set('blogs', $blogs); $this->action = 'results'; } }
public function profile($f3) { $id = $this->Auth->user('id'); extract($this->request->data); $u = $this->Model->Users->fetch($id); if ($this->request->is('post')) { $u->copyfrom('POST'); //Handle avatar upload if (isset($_FILES['avatar']) && isset($_FILES['avatar']['tmp_name']) && !empty($_FILES['avatar']['tmp_name'])) { $url = File::Upload($_FILES['avatar']); $u->avatar = $url; } else { if (isset($reset)) { $u->avatar = ''; } } $u->save(); \StatusMessage::add('Profile updated succesfully', 'success'); return $f3->reroute('/user/profile'); } $_POST = $u->cast(); $f3->set('u', $u); }