Example #1
0
 /**
  * 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);
     });
 }
Example #2
0
がありません。
<?php 
    }
} else {
    $is_image_enabled = conf('image.isEnabled', 'news');
    $is_tags_enabled = conf('tags.isEnabled', 'news');
    $title_trim_width = conf('viewParams.site.list.trim_width.title', 'news');
    $body_trim_width = conf('viewParams.site.list.trim_width.body', 'news');
    $body_format = \News\Site_Util::convert_format_key2value('raw');
    $col_class = 'xs';
    ?>
<div id="article_list">
<?php 
    foreach ($list as $id => $news) {
        $image_col_size = 0;
        if ($is_image_enabled && ($image = \News\Model_NewsImage::get_one4news_id($id))) {
            $image_col_size = 2;
        }
        $tags = $is_tags_enabled ? \News\Model_NewsTag::get_names4news_id($id) : array();
        ?>
	<div class="article">
		<div class="row">
			<div class="col-<?php 
        echo $col_class;
        ?>
-<?php 
        echo 12 - $image_col_size;
        ?>
">
				<h4 class="media-heading">
					<?php 
Example #3
0
 /**
  * News preview
  * 
  * @access  public
  * @params  integer
  * @return  Response
  */
 public function action_preview($slug = null)
 {
     if (!($news = Model_News::get4slug($slug, false))) {
         throw new \HttpNotFoundException();
     }
     $token = \Input::get('token');
     if (!$token || $token != $news->token) {
         throw new \HttpNotFoundException();
     }
     $images = \Config::get('news.image.isEnabled') ? \News\Model_NewsImage::get4news_id($news->id) : array();
     $files = \Config::get('news.file.isEnabled') ? \News\Model_NewsFile::get4news_id($news->id) : array();
     $tags = \Config::get('news.tags.isEnabled') ? \News\Model_NewsTag::get_names4news_id($news->id) : array();
     $title = array('name' => $news->title);
     $header_info = self::get_prview_header_info($news->is_published, $news->published_at);
     $this->set_title_and_breadcrumbs($title, null, null, null, $header_info, true);
     $this->template->subtitle = \View::forge('_parts/news_subinfo', array('news' => $news));
     $this->template->content = \View::forge('detail', array('news' => $news, 'images' => $images, 'files' => $files, 'tags' => $tags));
     if (Site_Util::check_editor_enabled()) {
         $this->template->content->set_safe('html_body', $news->body);
     }
 }
Example #4
0
 /**
  * News edit
  * 
  * @access  public
  * @params  integer
  * @return  Response
  */
 public function action_edit($id = null)
 {
     $news = \News\Model_News::check_authority($id);
     $val = self::get_validation_object($news);
     $news_images = array();
     $news_files = array();
     $images = array();
     $files = array();
     $is_enabled_image = conf('image.isEnabled', 'news');
     $is_insert_body_image = conf('image.isInsertBody', 'news');
     $is_modal_upload_image = conf('image.isModalUpload', 'news');
     if ($is_enabled_image && !$is_modal_upload_image) {
         $news_images = \News\Model_NewsImage::get4news_id($news->id);
         $images = \Site_Upload::get_file_objects($news_images, $news->id, true, null, 'img', $is_insert_body_image);
     }
     if ($is_enabled_file = \Config::get('news.file.isEnabled')) {
         $news_files = \News\Model_NewsFile::get4news_id($news->id);
         $files = \Site_Upload::get_file_objects($news_files, $news->id, true, null, 'file');
     }
     $posted_links = array();
     $saved_links = array();
     if ($is_enabled_link = \Config::get('news.link.isEnabled')) {
         $saved_links = $this->get_saved_links($news->id);
     }
     $tags = \Config::get('news.tags.isEnabled') ? \News\Model_NewsTag::get_names4news_id($news->id) : array();
     $image_tmps = array();
     $file_tmps = array();
     if (\Input::method() == 'POST') {
         \Util_security::check_csrf();
         if ($is_enabled_link) {
             $posted_links = $this->get_posted_links();
             $val = $this->add_validation_object_posted_links($val, $saved_links, true);
             $val = $this->add_validation_object_posted_links($val, $posted_links);
         }
         $moved_images = array();
         $moved_files = array();
         $news_image_ids = array();
         $news_file_ids = array();
         $error_message = '';
         try {
             if ($is_enabled_image) {
                 $image_tmps = \Site_FileTmp::get_file_tmps_and_check_filesize();
             }
             if ($is_enabled_file) {
                 $file_tmps = \Site_FileTmp::get_file_tmps_and_check_filesize(null, null, 'file');
             }
             // 識別名の変更がない場合は unique を確認しない
             if (trim(\Input::post('slug')) == $news->slug) {
                 $val->fieldset()->field('slug')->delete_rule('unique');
             }
             if (!$val->run()) {
                 throw new \FuelException($val->show_errors());
             }
             $post = $val->validated();
             if ($post['format'] == 2) {
                 $post['body'] = preg_replace('/^\\&gt;/um', '>', $post['body']);
             }
             $news->set_values($post);
             $message = sprintf('%sを%sしました。', term('news.view'), term('form.edit'));
             if ($is_published = !$news->is_published && empty($post['is_draft'])) {
                 $news->is_published = 1;
                 $message = sprintf('%sを%sしました。', term('news.view'), term('form.publish'));
             }
             if ($post['published_at_time'] && !\Util_Date::check_is_same_minute($post['published_at_time'], $news->published_at)) {
                 $news->published_at = $post['published_at_time'] . ':00';
             } elseif ($is_published) {
                 $news->published_at = date('Y-m-d H:i:s');
             }
             \DB::start_transaction();
             $news->save();
             if ($is_enabled_image) {
                 list($moved_images, $news_image_ids) = \Site_FileTmp::save_images($image_tmps, $news->id, 'news_id', 'news_image');
                 \Site_Upload::update_image_objs4file_objects($news_images, $images);
             }
             if ($is_enabled_file) {
                 list($moved_files, $news_file_ids) = \Site_FileTmp::save_images($file_tmps, $news->id, 'news_id', 'news_file', null, 'file');
                 \Site_Upload::update_image_objs4file_objects($news_files, $files);
             }
             if ($is_enabled_link) {
                 $this->save_posted_links($saved_links, $news->id, true);
                 $this->save_posted_links($posted_links, $news->id);
             }
             if (\Config::get('news.tags.isEnabled')) {
                 \News\Model_NewsTag::save_tags($post['tags'], $news->id);
             }
             //// timeline 投稿
             //if (is_enabled('timeline'))
             //{
             //	if ($is_published)
             //	{
             //		\Timeline\Site_Model::save_timeline($this->u->id, $note->public_flag, 'note', $note->id);
             //	}
             //	elseif ($is_update_public_flag)
             //	{
             //		// timeline の public_flag の更新
             //		\Timeline\Model_Timeline::update_public_flag4foreign_table_and_foreign_id($note->public_flag, 'note', $note->id, \Config::get('timeline.types.note'));
             //	}
             //}
             \DB::commit_transaction();
             // thumbnail 作成 & tmp_file thumbnail 削除
             \Site_FileTmp::make_and_remove_thumbnails($moved_images);
             \Session::set_flash('message', $message);
             \Response::redirect('admin/news/detail/' . $news->id);
         } catch (\Database_Exception $e) {
             $error_message = \Site_Controller::get_error_message($e, true);
         } catch (\FuelException $e) {
             $error_message = $e->getMessage();
         }
         if ($error_message) {
             if (\DB::in_transaction()) {
                 \DB::rollback_transaction();
             }
             if ($moved_images) {
                 \Site_FileTmp::move_files_to_tmp_dir($moved_images);
             }
             if ($moved_files) {
                 \Site_FileTmp::move_files_to_tmp_dir($moved_files);
             }
             $image_tmps = \Site_FileTmp::get_file_objects($image_tmps, $this->u->id, true, 'img');
             $file_tmps = \Site_FileTmp::get_file_objects($file_tmps, $this->u->id, true, 'file');
             \Session::set_flash('error', $error_message);
         }
     }
     $images = array_merge($images, $image_tmps);
     $files = array_merge($files, $file_tmps);
     $this->set_title_and_breadcrumbs(term('form.edit'), array('admin/news' => term('news.view', 'admin.view'), 'admin/news/' . $news->id => $news->title));
     $this->template->post_header = \View::forge('news/_parts/form_header');
     $this->template->post_footer = \View::forge('news/_parts/form_footer', array('news' => $news));
     $this->template->content = \View::forge('news/_parts/form', array('val' => $val, 'saved_links' => $saved_links, 'posted_links' => $posted_links, 'news' => $news, 'is_edit' => true, 'images' => $images, 'files' => $files, 'tags' => $tags));
 }