/** * Execute the controller. * * @throws \Exception * @return mixed Return executed result. */ public function execute() { $id = $this->input->get('id'); $authorMapper = new DataMapper('authors'); $return = $this->input->getBase64('return'); $return = $return ? base64_decode($return) : Router::buildHttp('admin:authors'); try { if (!$id) { throw new \Exception('Delete fail'); } $author = $authorMapper->findOne($id); $blog = Blog::get(); $user = User::get(); if ($author->owner) { throw new ValidFailException('You cannot delete owner.'); } if ($user->id != $author->user && $blog->id != $author->blog) { throw new ValidFailException('You cannot delete authors of other blog.'); } $authorMapper->delete(['id' => $id]); } catch (ValidFailException $e) { $this->setRedirect($return, $e->getMessage(), 'danger'); return false; } catch (\Exception $e) { if (WINDWALKER_DEBUG) { throw $e; } $this->setRedirect($return, 'Delete fail', 'danger'); return false; } $this->setRedirect($return, 'Remove Author success', 'success'); return true; }
/** * doExecute * * @return bool|string * * @throws \Exception */ protected function doExecute() { $view = new PostHtmlView($this->data); $model = new PostModel(); $id = $this->input->get('id'); $alias = $this->input->getString('alias'); $type = $this->input->get('type'); $view['type'] = $type; $view['post'] = $post = $model->getItem($id); $view['postAuthor'] = Author::getPostAuthor($post->author); $view['avatar'] = Author::getAvatar($view['postAuthor']->id, 200); if ($post->isNull()) { throw new \Exception('Post not found', 404); } if ($post->blog != $view['blog']->id) { throw new \Exception('Post not found', 404); } if (urldecode($alias) != $view['post']->alias) { $get = $this->input->get; $get->set('_rawRoute', null); $queries = $this->input->get->getArray(); $queries['alias'] = $view['post']->alias; $this->app->redirect(Router::buildHttp('front:post_default', $queries), true); return false; } return $view->render(); }
/** * Execute the controller. * * @throws \Exception * @return mixed Return executed result. */ public function execute() { $user = $this->input->getVar('registration'); $user = new Data($user); $session = Ioc::getSession(); $session['register.form.data'] = $user; $trans = Ioc::getDatabase()->getTransaction()->start(); try { $this->validate($user); // User $user = $this->createUser($user); // Blog $blogCtrl = $this->createBlog($user); // Articles $this->createDefaultArticle($blogCtrl); } catch (ValidFailException $e) { $trans->rollback(); $this->setRedirect(Router::buildHttp('user:registration'), $e->getMessage(), 'danger'); return false; } catch (\Exception $e) { $trans->rollback(); if (WINDWALKER_DEBUG) { throw $e; } $this->setRedirect(Router::buildHttp('user:registration'), 'Register fail', 'danger'); return false; } $trans->commit(); $session->remove('register.form.data'); // OK let's login User::makeUserLogin($user->id); $this->setRedirect(Router::buildHttp('user:login'), 'Register success.', 'success'); return true; }
/** * Execute the controller. * * @throws \Exception * @return mixed Return executed result. */ public function execute() { $id = $this->input->get('id'); $user = User::get(); $blog = Blog::get(); $type = $this->input->get('type'); $route = $type == 'static' ? 'statics' : 'posts'; try { if (!$id) { throw new ValidFailException('Where is your post ID?'); } if (!Author::isAdmin()) { throw new ValidFailException('Access deny'); } $postMapper = new DataMapper('posts'); $post = $postMapper->findOne($id); if ($post->blog != $blog->id) { throw new ValidFailException('You cannot change post of other blog.'); } $post['state'] = $this->input->get('state', 1); $postMapper->updateOne($post); } catch (ValidFailException $e) { $this->setRedirect(Router::buildHttp('admin:' . $route), $e->getMessage(), 'danger'); return false; } catch (\Exception $e) { if (WINDWALKER_DEBUG) { throw $e; } $this->setRedirect(Router::buildHttp('admin:' . $route), 'Fail', 'danger'); return false; } $this->setRedirect(Router::buildHttp('admin:' . $route), 'Success', 'success'); return true; }
/** * Execute the controller. * * @throws \Exception * @return mixed Return executed result. */ public function execute() { $id = $this->input->get('id'); $user = User::get(); $blog = Blog::get(); try { if (!$id) { throw new ValidFailException('No ID'); } if (!Author::isAdmin()) { throw new ValidFailException('Access deny'); } $postMapper = new DataMapper('posts'); $post = $postMapper->findOne($id); if ($post->blog != $blog->id) { throw new ValidFailException('You cannot delete post of other blog.'); } $postMapper->delete(['id' => $id]); } catch (ValidFailException $e) { $this->setRedirect(Router::buildHttp('admin:posts'), $e->getMessage(), 'danger'); return false; } catch (\Exception $e) { if (WINDWALKER_DEBUG) { throw $e; } $this->setRedirect(Router::buildHttp('admin:posts'), 'Delete fail', 'danger'); return false; } $this->setRedirect(Router::buildHttp('admin:posts'), 'Delete success', 'success'); return true; }
/** * Execute the controller. * * @throws \Exception * @return mixed Return executed result. */ public function execute() { $id = $this->input->get('id'); $blogMapper = new DataMapper('blogs'); $authorMapper = new DataMapper('authors'); $catMapper = new DataMapper('categories'); $postMapper = new DataMapper('posts'); try { if (!$id) { throw new \Exception('Delete fail'); } $author = $authorMapper->findOne(['blog' => $id, 'user' => User::get()->id]); if (!$author->owner) { throw new ValidFailException('Only owner can remove blog.'); } $blogMapper->delete(['id' => $id]); $authorMapper->delete(['blog' => $id]); $catMapper->delete(['blog' => $id]); $postMapper->delete(['blog' => $id]); } catch (ValidFailException $e) { $this->setRedirect(Router::buildHttp('admin:blogs'), $e->getMessage(), 'danger'); return false; } catch (\Exception $e) { if (WINDWALKER_DEBUG) { throw $e; } $this->setRedirect(Router::buildHttp('admin:blogs'), 'Delete fail', 'danger'); return false; } $this->setRedirect(Router::buildHttp('admin:blogs'), 'Delete Blog success', 'success'); return true; }
/** * Execute the controller. * * @return mixed Return executed result. * * @throws \LogicException * @throws \RuntimeException */ public function execute() { $ctrl = new \Admin\Controller\Blog\SaveController($this->input, $this->app); if (!$ctrl->execute()) { list($url, $msg, $type) = $ctrl->getRedirect(true); $this->setRedirect($url, $msg, $type); return false; } list($url, $msg, $type) = $ctrl->getRedirect(true); $this->setRedirect(Router::buildHttp('admin:settings'), $msg, $type); return true; }
/** * checkLogin * * @return boolean */ public static function checkLogin() { if (User::get()->notNull()) { return true; } $session = Ioc::getSession(); $current = Ioc::getConfig()->get('uri.current'); $current = base64_encode($current); $session->set('login.redirect.url', $current); Ioc::getApplication()->redirect(Router::buildHttp('user:login')); return true; }
/** * Execute the controller. * * @return mixed Return executed result. * * @throws \LogicException * @throws \RuntimeException */ public function execute() { $model = new LoginModel(); $user = User::get(); if ($user->isNull()) { $this->setRedirect('login', 'Already logout', 'success'); } $model->logout($user->username); // Session $session = Ioc::getSession(); $session->remove('current.blog'); $this->setRedirect(Router::buildHttp('front:home'), 'Logout success', 'success'); return true; }
/** * prepareData * * @param \Windwalker\Data\Data $data * * @return void */ protected function prepareData($data) { $markdown = new MarkdownExtra(); $text = $data['post']->introtext . $data['post']->fulltext; $data['post']['text'] = $markdown->defaultTransform($text); $data['post']['link'] = Router::buildHttp('front:post_default', ['id' => $data['post']['id'], 'alias' => $data['post']['alias']]); $data['post']->created = new Date($data['post']->created); $data['post']->created = $data['post']->created->format('F j, Y'); foreach ($data['statics'] as $post) { $post->link = Router::buildHtml('front:static_default', ['id' => $post->id, 'alias' => $post->alias]); } $data->bodyClass = $data['type'] ?: 'post'; // Meta $text = $data['post']->text; $desc = trim($data['post']->metadesc); $desc = $desc ?: Utf8String::substr(OutputFilter::cleanText($text), 0, 200); $data->meta->desc = $desc; }
/** * doExecute * * @return string */ protected function doExecute() { $type = $this->input->get('type', 'post'); $session = Ioc::getSession(); $currentPage = $session->get($type . '.current.page', 1); if ($currentPage != 1 && !$this->input->getInt('page')) { $this->setRedirect(Router::buildHttp('admin:' . $type . 's', ['page' => $currentPage])); return true; } $view = new PostsHtmlView($this->data); $model = new PostsModel(); $model['blog.id'] = $this->data['blog']->id; $model['post.type'] = $type; $model['list.page'] = $page = $this->input->getInt('page', 1); $model['list.limit'] = 10; $model['list.start'] = ($model['list.page'] - 1) * $model['list.limit']; $model['list.search'] = $this->input->getString('q'); $model['list.ordering'] = 'post.id desc'; $view->set('items', $model->getItems()); $view->set('pagination', $model->getPagination()->build()); $view->set('type', $type); $session->set($type . '.current.page', $page); return $view->render(); }
/** * Execute the controller. * * @throws \Exception * @return mixed Return executed result. */ public function execute() { $id = $this->input->get('id'); $blog = Blog::get(); try { $catMapper = new DataMapper('categories'); $category = $catMapper->findOne($id); if ($category->blog != $blog->id) { throw new ValidFailException('You cannot delete category of other blog.'); } $catMapper->delete(['id' => $id]); } catch (ValidFailException $e) { $this->setRedirect(Router::buildHttp('admin:categories'), $e->getMessage(), 'error'); return false; } catch (\Exception $e) { if (WINDWALKER_DEBUG) { throw $e; } $this->setRedirect(Router::buildHttp('admin:categories'), 'Delete fail', 'error'); return false; } $this->setRedirect(Router::buildHttp('admin:categories'), 'Delete success', 'success'); return true; }
/** * validate * * @param Data $data * * @return boolean */ protected function validate($data) { $form = new Form('blog'); $form->defineFormFields(new BlogDefinition()); $form->bind($data); if (!$form->validate()) { $errors = $form->getErrors(); foreach ($errors as $error) { $this->addFlash($error->getMessage(), 'danger'); } $this->setRedirect(Router::buildHttp('admin:blog', ['id' => $data->id ?: ''])); return false; } // Check exists $conditions['alias'] = $data['alias']; if ($data->id) { $conditions[] = 'id != ' . $data->id; } $blog = (new DataMapper('blogs'))->findOne($conditions); if ($blog->notNull()) { $this->setRedirect(Router::buildHttp('admin:blog', ['id' => $data->id ?: '']), 'Blog Name has already been used', 'danger'); return false; } return true; }
/** * permission * * @param string $permission * * @throws ValidFailException * @return boolean */ protected function permission($permission) { $authorMapper = new DataMapper('authors'); $id = $this->input->get('id'); $author = $authorMapper->findOne($id); if ($author->blog != Blog::get()->id) { throw new ValidFailException('You cannot change permission of author which in other blog.'); } if ($author->owner) { throw new ValidFailException('You cannot change permission of blog owner'); } $author['admin'] = $permission == Author::ADMIN ? 1 : 0; $authorMapper->updateOne($author, 'id'); $this->setRedirect(Router::buildHttp('admin:authors'), 'Save success', 'success'); return true; }
/** * validate * * @param Data $data * * @throws ValidFailException * @return boolean */ protected function validate($data) { $model = new ProfileModel(); $form = $model->getForm($data); if (!$form->validate()) { $errors = $form->getErrors(); foreach ($errors as $error) { $this->addFlash($error->getMessage(), 'danger'); } $this->setRedirect(Router::buildHttp('admin:profile', ['id' => $data->id ?: ''])); return false; } if ($data->password) { if ($data->password2 != $data->password) { throw new ValidFailException('Password not match'); } $password = new Password(); $data->password = $password->create($data->password); } else { unset($data->password); } return true; }