Пример #1
1
 /**
  * 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;
 }
Пример #2
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;
 }
Пример #3
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;
 }
Пример #4
0
 /**
  * Execute the controller.
  *
  * @return  mixed Return executed result.
  *
  * @throws  \LogicException
  * @throws  \RuntimeException
  */
 public function execute()
 {
     $model = new BlogsModel();
     $view = new WidgetHtmlView();
     $model['user.id'] = User::get()->id;
     $view['blog'] = Blog::get();
     $view['blogs'] = $model->getItems();
     $view['activeMenu'] = $this->input->get('activeMenu', 'dashboard');
     return $view->setLayout('sidebar')->render();
 }
Пример #5
0
 /**
  * doExecute
  *
  * @return  string
  */
 protected function doExecute()
 {
     $model = new CategoriesModel();
     $view = new CategoriesHtmlView($this->data);
     $model['blog.id'] = Blog::get()->id;
     $model['list.start'] = $this->input->getInt('start');
     $model['list.limit'] = 10;
     $model['list.search'] = $this->input->getString('q');
     $cats = $model->getItems();
     $view['items'] = $cats;
     return $view->render();
 }
 /**
  * Execute the controller.
  *
  * @return  mixed Return executed result.
  *
  * @throws  \LogicException
  * @throws  \RuntimeException
  */
 public function execute()
 {
     $model = new BlogsModel();
     $model['user.id'] = User::get()->id;
     $data['activeMenu'] = $this->input->get('activeMenu', 'none');
     $data['hideMenu'] = $this->input->get('hideMenu', 0);
     $data['widget'] = new Data();
     // $data['widget']['sidebar'] = (new SidebarController($this->input, $this->app))->execute();
     $data['blog'] = Blog::get();
     $data['blogs'] = $model->getItems();
     $data['user'] = User::get();
     $data['profiler'] = WINDWALKER_DEBUG ? Ioc::getProfiler() : null;
     $this->data = $data;
     return $this->doExecute();
 }
Пример #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;
 }
Пример #9
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;
 }
Пример #10
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;
 }
Пример #11
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;
 }
Пример #12
0
 /**
  * checkPermission
  *
  * @param string $type
  * @param Data   $blog
  * @param Data   $user
  *
  * @return  boolean
  */
 public static function checkPermission($type = self::ADMIN, Data $blog = null, Data $user = null)
 {
     $user = $user ?: User::get();
     $blog = $blog ?: Blog::get();
     // TODO: cache it.
     $author = (new DataMapper('authors'))->findOne(['user' => $user->id, 'blog' => $blog->id]);
     if ($author->isNull()) {
         return false;
     }
     switch ($type) {
         case static::OWNER:
             return (bool) $author->owner;
             break;
         case static::ADMIN:
             return (bool) $author->owner || (bool) $author->admin;
             break;
         default:
         case static::MEMBER:
             return !$author->owner && !$author->admin;
             break;
     }
 }
Пример #13
0
 /**
  * getForm
  *
  * @param array $data
  *
  * @return  Form
  */
 public function getForm($data = array())
 {
     $form = new Form();
     $form->defineFormFields(new PostDefinition(Blog::get()));
     $form->bind($data);
     if ($this['post.type'] == 'static') {
         $form->removeField('category');
     }
     return $form;
 }