예제 #1
0
 /**
  * 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;
 }
예제 #2
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;
 }
예제 #3
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();
 }
예제 #4
0
 /**
  * Execute the controller.
  *
  * @return  mixed Return executed result.
  *
  * @throws  \LogicException
  * @throws  \RuntimeException
  */
 public function execute()
 {
     try {
         $id = $this->input->get('id');
         if ($id) {
             $author = Author::getAuthor($id);
             $author->image = "0";
             (new DataMapper('authors'))->updateOne($author, 'id');
         }
     } catch (\Exception $e) {
         $response = new Response();
         $response->setBody(json_encode(['error' => $e->getMessage()]));
         $response->setMimeType('text/json');
         $response->respond();
         exit;
     }
     $return = new Registry();
     $return['success'] = true;
     $return['image'] = UserHelper::getGavatar('*****@*****.**', 400);
     $response = new Response();
     $response->setBody((string) $return);
     $response->setMimeType('text/json');
     $response->respond();
     exit;
 }
예제 #5
0
 /**
  * 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;
 }
예제 #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);
     }
 }
예제 #7
0
 /**
  * Execute the controller.
  *
  * @return  mixed Return executed result.
  *
  * @throws  \LogicException
  * @throws  \RuntimeException
  */
 public function execute()
 {
     $files = $this->input->files;
     $field = $this->input->get('field', 'file');
     $id = $this->input->get('id');
     $author = Author::getAuthor($id);
     $user = User::get();
     $blog = Blog::get();
     try {
         if (!Author::isAdmin($blog, $user)) {
             throw new ValidFailException('You cannot edit this author.');
         }
         $src = $files->getByPath($field . '.tmp_name', null, InputFilter::STRING);
         $name = $files->getByPath($field . '.name', null, InputFilter::STRING);
         if (!$src) {
             throw new \Exception('File not upload');
         }
         $ext = pathinfo($name, PATHINFO_EXTENSION);
         $uuid = $author->uuid ?: Uuid::v4();
         $src = Thumb::createThumb($src);
         $dest = sprintf('author/%s/%s.%s', sha1($uuid), md5($uuid), $ext);
         $result = S3Helper::put($src, $dest);
         File::delete($src);
         if (!$result) {
             throw new \Exception('Upload fail.');
         }
     } catch (\Exception $e) {
         $response = new Response();
         $response->setBody(json_encode(['error' => $e->getMessage()]));
         $response->setMimeType('text/json');
         $response->respond();
         exit;
     }
     $return = new Registry();
     $return['filename'] = 'https://windspeaker.s3.amazonaws.com/' . $dest;
     $return['file'] = 'https://windspeaker.s3.amazonaws.com/' . $dest;
     $return['uuid'] = $uuid;
     if ($author->id) {
         $author->image = $return['filename'];
         (new DataMapper('authors'))->updateOne($author);
     }
     $response = new Response();
     $response->setBody((string) $return);
     $response->setMimeType('text/json');
     $response->respond();
     exit;
 }
예제 #8
0
 /**
  * Execute the controller.
  *
  * @return  mixed Return executed result.
  *
  * @throws  \LogicException
  * @throws  \RuntimeException
  */
 public function execute()
 {
     $model = new PostModel();
     $data = $this->input->getVar('post');
     $data['text'] = $this->input->getByPath('post.text', null, InputFilter::RAW);
     $data = new Data($data);
     $isNew = !$data['id'];
     try {
         $model->validate($data);
         if (!$isNew) {
             $oldData = (new DataMapper('posts'))->findOne($data['id']);
             $oldData->bind($data);
             $data = $oldData;
             $data->modified = (new Date())->format('Y-m-d H:i:s');
         } else {
             $data->blog = Blog::get()->id;
             $data->type = $this->input->get('type', 'post');
             $data->type = $data->type == 'post' ? $data->type : 'static';
             $data->created = (new Date())->format('Y-m-d H:i:s');
         }
         $data->author = $data->author ?: Author::get(User::get()->id, Blog::get()->id)->id;
         $text = preg_split('/(\\<\\!--\\s*\\{READMORE\\}\\s*--\\>)/', $data['text'], 2);
         $data->introtext = isset($text[0]) ? $text[0] : null;
         $data->fulltext = isset($text[1]) ? $text[1] : null;
         $data = $model->save($data);
     } catch (ValidFailException $e) {
         $return['msg'] = $e->getMessage();
         $return['success'] = false;
         $this->respond($return, 500);
         return false;
     } catch (\Exception $e) {
         if (WINDWALKER_DEBUG) {
             throw $e;
         }
         $return['msg'] = 'Save fail';
         $return['success'] = false;
         $this->respond($return, 500);
         return false;
     }
     $return['msg'] = 'Save success';
     $return['success'] = true;
     $return['item'] = $data;
     $this->respond($return, 200);
     return true;
 }
 /**
  * Execute the controller.
  *
  * @return  mixed Return executed result.
  *
  * @throws  \LogicException
  * @throws  \RuntimeException
  */
 public function execute()
 {
     $model = new PostsModel();
     $blog = Ioc::get('current.blog', 'front');
     $author = (new DataMapper('authors'))->findOne(['blog' => $blog->id, 'owner' => 1]);
     $user = (new DataMapper('users'))->findOne(['id' => $author->user]);
     $this->data['blog'] = $blog;
     $this->data['ownerUser'] = $user;
     $this->data['ownerAuthor'] = $author;
     $this->data['user'] = User::get();
     $this->data['author'] = Author::get($user->id, $blog->id);
     // Statics
     $model['blog.id'] = $blog->id;
     $model['list.start'] = null;
     $model['list.limit'] = null;
     $model['blog.published'] = true;
     $model['post.type'] = 'static';
     $model['post.ordering'] = 'id asc';
     $this->data['statics'] = $model->getItems();
     $this->data['blog']->link = 'http://' . $this->data['blog']->alias . '.windspeaker.co';
     $this->data['blog']->params = new Registry($this->data['blog']->params);
     $this->data['meta'] = new Data();
     return $this->doExecute();
 }
예제 #10
0
 /**
  * prepareData
  *
  * @param \Windwalker\Data\Data $data
  *
  * @return  void
  */
 protected function prepareData($data)
 {
     $data['avatar'] = Author::getAvatar($data['item']->id ?: -1, 650);
 }