Esempio n. 1
0
 /**
  * Renders the field's form element for editing in the admin site
  */
 public static function displayForm($value, &$settings, $model)
 {
     $class = get_called_class();
     $settings = static::settings($settings);
     $include_label = isset($settings['label']) ? $settings['label'] : true;
     $required = isset($settings['required']) ? $settings['required'] : false;
     $errors = $model->getErrorsForField($settings['mapping']['fieldName']);
     $has_errors = count($errors) > 0;
     $input_attributes = isset($settings['input_attributes']) ? $settings['input_attributes'] : array('class' => 'input-xxlarge');
     if (!isset($input_attributes['id'])) {
         $input_attributes['id'] = 'form_' . $settings['mapping']['fieldName'];
     }
     $attributes = array('class' => 'controls control-group' . ($has_errors ? ' error' : '') . ' field-type-' . $class::type($settings));
     $label_text = $settings['title'] . ($required ? ' *' : '');
     if (empty($value)) {
         $value = substr(\Security::generate_token(), 0, 16);
     }
     // Description?
     $description = isset($settings['description']) ? '<span class="help-block">' . $settings['description'] . '</span>' : '';
     // Build the input
     $input = '<input type="text" name="' . $settings['mapping']['fieldName'] . '" ' . array_to_attr($input_attributes) . ' value="' . \Security::htmlentities(strval($value), ENT_QUOTES) . '" />';
     // Build the label
     $label = !$include_label ? '' : html_tag('label', array('class' => 'item-label', 'for' => $settings['mapping']['fieldName']), $label_text . ($has_errors ? ' - ' . $errors[0] : ''));
     // Don't wrap the input if wrap is set to false
     if (isset($settings['wrap']) && $settings['wrap'] === false) {
         return $label . $input;
     }
     return html_tag('div', $attributes, $label . $description . $input);
 }
Esempio n. 2
0
 public static function create_instantly($user_id)
 {
     $obj = self::forge();
     $obj->slug = Site_Util::get_slug();
     $obj->title = date(conf('default.dateFormat')) . 'の' . term('news.view');
     $obj->users_id = $user_id;
     $obj->token = \Security::generate_token();
     $obj->is_published = 0;
     $obj->format = conf('form.formats.default', 'news');
     $obj->save();
     return $obj;
 }
Esempio n. 3
0
 public static function save_with_token($email, $password, $invite_member_id = null)
 {
     $obj = self::forge();
     $obj->email = $email;
     $obj->password = $password;
     $obj->token = Security::generate_token();
     $obj->invite_member_id = $invite_member_id;
     if (!$obj->save()) {
         return false;
     }
     return $obj->token;
 }
Esempio n. 4
0
 public static function save_with_token($member_id, $email)
 {
     if (!($obj = self::get4member_id($member_id))) {
         $obj = self::forge();
     }
     $obj->member_id = $member_id;
     $obj->email = $email;
     $obj->token = Security::generate_token();
     if (!$obj->save()) {
         return false;
     }
     return $obj->token;
 }
Esempio n. 5
0
 public static function save_with_token($member_id, $email)
 {
     if (!($obj = Model_MemberEmailPre::get4member_id($member_id))) {
         $obj = Model_MemberEmailPre::forge();
     }
     $obj->member_id = $member_id;
     $obj->email = $email;
     $obj->token = Security::generate_token();
     $obj->code = Util_String::get_random_code(static::$_properties['code']['form']['validation']['exact_length'][0]);
     if (!$obj->save()) {
         return false;
     }
     return $obj;
 }
Esempio n. 6
0
 /**
  * News create
  * 
  * @access  public
  * @return  Response
  */
 public function action_create()
 {
     // if insert image mode, forbidden to display create form.
     if (conf('image.isInsertBody', 'news')) {
         throw new \HttpNotFoundException();
     }
     $news = \News\Model_News::forge();
     $val = self::get_validation_object($news);
     $images = array();
     $files = array();
     $is_enabled_image = \Config::get('news.image.isEnabled');
     $is_enabled_file = \Config::get('news.file.isEnabled');
     $is_enabled_link = \Config::get('news.link.isEnabled');
     $posted_links = 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, $posted_links);
         }
         $image_tmps = array();
         $file_tmps = array();
         $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');
             }
             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);
             $news->users_id = $this->u->id;
             $news->token = \Security::generate_token();
             $news->is_published = $post['is_draft'] ? 0 : 1;
             if ($post['published_at_time']) {
                 $news->published_at = $post['published_at_time'] . ':00';
             } elseif ($news->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');
             }
             if ($is_enabled_file) {
                 list($moved_files, $news_file_ids) = \Site_FileTmp::save_images($file_tmps, $news->id, 'news_id', 'news_file', null, 'file');
             }
             if ($is_enabled_link) {
                 $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 ($note->is_published && is_enabled('timeline'))
             //{
             //	\Timeline\Site_Model::save_timeline($this->u->id, $post['public_flag'], 'note', $note->id);
             //}
             \DB::commit_transaction();
             // thumbnail 作成 & tmp_file thumbnail 削除
             \Site_FileTmp::make_and_remove_thumbnails($moved_images);
             $message = sprintf('%sを%sしました。', term('news.view'), $news->is_published ? term('form.publish') : term('form.draft'));
             \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);
             }
             $images = \Site_FileTmp::get_file_objects($image_tmps, $this->u->id, true, 'img');
             $files = \Site_FileTmp::get_file_objects($file_tmps, $this->u->id, true, 'file');
             \Session::set_flash('error', $error_message);
         }
     }
     $this->set_title_and_breadcrumbs(term('news.view', 'form.create'), array('admin/news' => term('news.view', 'admin.view')));
     $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, 'images' => $images, 'files' => $files, 'posted_links' => $posted_links));
 }