예제 #1
0
파일: api.php 프로젝트: uzura8/flockbird
 /**
  * Upload images
  * 
  * @access  public
  * @return  Response (json|html)
  * @throws  Exception in Controller_Base::controller_common_api
  * @see  Controller_Base::controller_common_api
  */
 public function post_upload($parent_id = null)
 {
     $this->api_accept_formats = array('html', 'json');
     $this->api_not_check_csrf = true;
     $this->controller_common_api(function () use($parent_id) {
         $upload_type = 'img';
         $news = \News\Model_News::check_authority($parent_id);
         if (!in_array($this->format, array('html', 'json'))) {
             throw new HttpNotFoundException();
         }
         $thumbnail_size = \Input::post('thumbnail_size');
         if (!\Validation::_validation_in_array($thumbnail_size, array('M', 'S'))) {
             throw new \HttpInvalidInputException('Invalid input data');
         }
         $insert_target = \Input::post('insert_target');
         $is_insert_body_image = conf('image.isInsertBody', 'news');
         $options = \Site_Upload::get_upload_handler_options($this->u->id, true, false, 'nw', $parent_id, true, 'img', $is_insert_body_image);
         $uploadhandler = new \MyUploadHandler($options, false);
         \DB::start_transaction();
         $files = $uploadhandler->post(false);
         $files['files'] = \News\Model_NewsImage::save_images($parent_id, $files['files']);
         \DB::commit_transaction();
         $files['upload_type'] = $upload_type;
         $files['thumbnail_size'] = $thumbnail_size;
         $files['insert_target'] = $insert_target;
         $files['model'] = 'news';
         $this->set_response_body_api($files, $this->format == 'html' ? 'filetmp/_parts/upload_images' : null);
     });
 }
예제 #2
0
파일: news.php 프로젝트: uzura8/flockbird
 private function change_publish_status($id, $target_status)
 {
     $target_status = \Util_string::cast_bool_int($target_status);
     \Util_security::check_method('POST');
     \Util_security::check_csrf();
     $news = \News\Model_News::check_authority($id);
     $msg_status = $target_status ? term('form.publish') : term('form.unpublish') . 'に';
     $redirect_uri = \Site_Util::get_redirect_uri('admin/news/' . $id);
     if ($news->is_published == $target_status) {
         \Session::set_flash('error', sprintf('既に%sされています。', $msg_status));
         \Response::redirect($redirect_uri);
     }
     try {
         \DB::start_transaction();
         $news->is_published = $target_status;
         if ($news->is_published && !isset_datatime($news->published_at)) {
             $news->published_at = date('Y-m-d H:i:s');
         }
         $news->save();
         //// timeline 投稿
         //if (is_enabled('timeline')) \Timeline\Site_Model::save_timeline($this->u->id, $note->public_flag, 'note', $note->id);
         \DB::commit_transaction();
         \Session::set_flash('message', sprintf('%sを%sしました。', term('news.view'), $msg_status));
     } catch (\FuelException $e) {
         if (\DB::in_transaction()) {
             \DB::rollback_transaction();
         }
         \Session::set_flash('error', $e->getMessage());
     }
     \Response::redirect($redirect_uri);
 }