/**
  * 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;
 }
 /**
  * Execute the controller.
  *
  * @return  mixed Return executed result.
  *
  * @throws  \LogicException
  * @throws  \RuntimeException
  */
 public function execute()
 {
     if (UserHelper::isLogin()) {
         Ioc::getApplication()->redirect(Router::build('admin:dashboard'));
     }
     $model = new LoginModel();
     $session = Ioc::getSession();
     $user = $this->input->getVar('user');
     $result = $model->login($user['username'], $user['password']);
     $package = $this->getPackage();
     $redirect = $session->get('login.redirect.url');
     if ($result) {
         $url = $redirect ? base64_decode($redirect) : $package->get('redirect.login');
         $msg = Language::translate('Login Success');
     } else {
         $router = Ioc::getRouter();
         $url = $router->build($this->package->getRoutingPrefix() . ':login');
         $msg = Language::translate('Login Fail');
     }
     $uri = new Uri($url);
     if (!$uri->getScheme()) {
         $url = $this->app->get('uri.base.full') . $url;
     }
     $session->remove('login.redirect.url');
     $this->setRedirect($url, $msg);
     return true;
 }
示例#3
0
 /**
  * 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;
 }
示例#5
0
 /**
  * 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();
 }
示例#6
0
 /**
  * prepareData
  *
  * @param \Windwalker\Data\Data $data
  *
  * @return  void
  */
 protected function prepareData($data)
 {
     $markdown = new MarkdownExtra();
     foreach ($data['posts'] as $post) {
         $post->link = Router::buildHtml('front:post_default', ['id' => $post->id, 'alias' => $post->alias]);
         $post->introtext = $markdown->defaultTransform($post->introtext);
         $post->author = Author::getPostAuthor($post->author);
         $post->created = new Date($post->created);
         $post->created = $post->created->format('F j, Y');
     }
     foreach ($data['statics'] as $post) {
         $post->link = Router::buildHtml('front:static_default', ['id' => $post->id, 'alias' => $post->alias]);
     }
     // Title
     if ($data->type == 'home') {
         $title = $data->blog->title;
         $suffix = '';
         $data->bodyClass = 'home posts page-' . $data->page;
     } else {
         $title = '';
         $suffix = $data->blog->title;
         $data->bodyClass = 'home posts page-' . $data->page;
     }
     $data->pageTitle = $title;
     $data->pageTitle .= $data->page > 1 ? ' - Page ' . $data->page : '';
     $data->pageTitle .= $suffix ? '|' . $suffix : '';
     // Meta
     $desc = $data->blog->description;
     $desc = OutputFilter::cleanText($desc);
     $desc = Utf8String::substr($desc, 0, 200);
     $data->meta->desc = $desc;
 }
 /**
  * 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;
 }
示例#9
0
 /**
  * prepareData
  *
  * @param \Windwalker\Data\Data $data
  *
  * @return  void
  */
 protected function prepareData($data)
 {
     $markdown = new MarkdownExtra();
     foreach ($data['posts'] as $post) {
         $post->link = Router::buildHtml('front:post_default', ['id' => $post->id, 'alias' => $post->alias]);
         $post->introtext = $markdown->defaultTransform($post->introtext);
         $post->author = Author::getPostAuthor($post->author);
     }
 }
示例#10
0
 /**
  * Execute the controller.
  *
  * @return  mixed Return executed result.
  *
  * @throws  \LogicException
  * @throws  \RuntimeException
  */
 public function execute()
 {
     if (UserHelper::isLogin()) {
         Ioc::getApplication()->redirect(Router::build('admin:dashboard'));
     }
     $model = new LoginModel();
     $view = new LoginHtmlView();
     $view['form'] = $model->getForm();
     return $view->render();
 }
示例#11
0
 /**
  * Execute the controller.
  *
  * @return  mixed Return executed result.
  *
  * @throws  \LogicException
  * @throws  \RuntimeException
  */
 public function execute()
 {
     if (UserHelper::isLogin()) {
         Ioc::getApplication()->redirect(Router::build('admin:dashboard'));
     }
     $model = new RegistrationModel();
     $view = new RegistrationHtmlView();
     $session = Ioc::getSession();
     $view['item'] = $session['register.form.data'] ?: array();
     $view['item'] = new Data($view['item']);
     return $view->render();
 }
示例#12
0
 /**
  * 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;
 }
示例#13
0
 /**
  * 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;
 }
示例#14
0
 /**
  * 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;
 }
示例#15
0
 /**
  * onViewBeforeRender
  *
  * @param Event $event
  *
  * @return  void
  */
 public function onViewBeforeRender(Event $event)
 {
     $data = $event['data'];
     $data->user = $data->user ?: User::get();
     $articleMapper = new ArticleMapper();
     $data->articles = $data->articles ?: $articleMapper->find(['state' => 1], 'ordering');
     foreach ($data->articles as $article) {
         $article->link = $article->url ?: Router::html('forum@article', ['id' => $article->id, 'alias' => $article->alias]);
     }
     // Template
     $config = Ioc::getConfig();
     if ($config['natika.theme']) {
         $event['view']->getRenderer()->addPath(WINDWALKER_TEMPLATES . '/theme/' . $config['natika.theme'] . '/' . $event['view']->getName(), Priority::HIGH);
     }
 }
示例#16
0
 /**
  * Execute the controller.
  *
  * @return  mixed Return executed result.
  *
  * @throws  \LogicException
  * @throws  \RuntimeException
  */
 public function execute()
 {
     $id = $this->input->get('id');
     $return = $this->input->get('return');
     $return = $return ? base64_decode($return) : Router::build('admin:dashboard');
     $user = User::get();
     $blogModel = new BlogModel();
     $blogModel['user.isAdmin'] = false;
     $blog = $blogModel->getCurrentBlog($user->id, $id);
     $session = Ioc::getSession();
     if (!$blog->isNull()) {
         $session->set('current.blog', $blog->id);
     }
     $this->setRedirect($return);
     return true;
 }
示例#17
0
 /**
  * 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;
 }
示例#18
0
 /**
  * getBreadcrumbs
  *
  * @param string $paths
  *
  * @return  Data[]
  */
 public static function getBreadcrumbs($paths)
 {
     if (!$paths) {
         return array();
     }
     $paths = explode('/', $paths);
     $record = new CategoryRecord();
     $breadcrumbs = array();
     foreach (range(1, count($paths)) as $i) {
         $item = new Data();
         $item->path = implode('/', $paths);
         $item->link = Router::html('forum:category', array('path' => $paths));
         $record->load(array('path' => $item->path));
         $item->title = $record->title;
         $breadcrumbs[] = $item;
         array_pop($paths);
     }
     $breadcrumbs[] = new Data(array('title' => 'Home', 'path' => '', 'link' => Router::html('forum:home')));
     $breadcrumbs = array_reverse($breadcrumbs);
     return $breadcrumbs;
 }
示例#19
0
 protected function doExecute()
 {
     $data = $this->input->getVar('category');
     $data = new Data($data);
     $data['title'] = trim($data['title']);
     if (!$data['title']) {
         $this->setRedirect(Router::build('admin:categories'), 'Title should not be empty', 'danger');
         return false;
     }
     if (!$data['blog']) {
         $data['blog'] = Blog::get()->id;
     }
     $data['alias'] = OutputFilter::stringURLSafe(trim($data['title']));
     $data['alias'] = $data['alias'] ?: OutputFilter::stringURLSafe((string) new Date());
     $data['state'] = 1;
     if (!$data['ordering']) {
         $max = $this->getMaxOrder($data['blog']);
         $data['ordering'] = $max + 1;
     }
     try {
         $category = new Record('categories');
         if ($data['id']) {
             $category->load($data['id']);
         }
         $category->bind($data);
         $category->check();
         $category->store(true);
     } catch (\Exception $e) {
         if (WINDWALKER_DEBUG) {
             throw $e;
         }
         $this->setRedirect(Router::build('admin:categories'), 'Save Error', 'danger');
         return false;
     }
     $this->setRedirect(Router::build('admin:categories'), 'Create success', 'success');
     return true;
 }
示例#20
0
 /**
  * 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;
 }
示例#21
0
 /**
  * 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();
 }
示例#22
0
<?php 
$this->block('content');
?>
<div class="container">
	<div class="row">
		<div class="col-md-12">
			<form action="<?php 
echo $data->uri['current'];
?>
" class="form-horizontal" method="post">
				<fieldset>
					<legend>LOGIN</legend>
					<?php 
echo $data->form->renderFields();
?>

					<div class="buttons">
						<button class="btn btn-primary" type="submit">Login</button>

						<a class="btn btn-success" href="<?php 
echo $data->uri['base.path'] . Router::build('user:registration');
?>
">Register</a>
					</div>
				</fieldset>
			</form>
		</div>
	</div>
</div>
<?php 
$this->endblock();
示例#23
0
 /**
  * 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;
 }
示例#24
0
 /**
  * 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;
 }
示例#25
0
 /**
  * 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;
 }
示例#26
0
					<a href="http://windspeaker.uservoice.com/" target="_blank">Contact</a>
				</li>
			</ul>
		</div>
	</nav>

	<div class="banner-cover">
		<section id="banner" style="background-image: url(<?php 
echo $banners[$num - 1];
?>
);">
			<div class="banner-cover"></div>
		</section>
	</div>

	<section class="banner-inner middle-box">
		<h1>Simple Platform For Team Blogging</h1>
		<h2>
			Share interesting things in you and your friends' life.
		</h2>
		<p>
			<a class="btn start-button" href="<?php 
echo Router::buildHtml('user:registration');
?>
">Start</a>
		</p>
	</section>

</body>
</html>