/** * Mmeber setting timeline_view * * @access public * @return Response */ public function action_viewtype() { $page_name = term('timeline', 'site.view', 'site.setting'); $val = \Form_MemberConfig::get_validation($this->u->id, 'timeline_viewType'); if (Input::method() == 'POST') { Util_security::check_csrf(); try { if (!$val->run()) { throw new \FuelException($val->show_errors()); } $post = $val->validated(); \DB::start_transaction(); \Form_MemberConfig::save($this->u->id, $val, $post); \DB::commit_transaction(); \Session::set_flash('message', $page_name . 'を変更しました。'); \Response::redirect('member/setting'); } catch (\FuelException $e) { if (\DB::in_transaction()) { \DB::rollback_transaction(); } \Session::set_flash('error', $e->getMessage()); } } $this->set_title_and_breadcrumbs($page_name, array('member/setting' => term('site.setting', 'form.update')), $this->u); $this->template->content = \View::forge('member/setting/timeline_viewtype', array('val' => $val)); }
/** * Mmeber_profile edit * * @access public * @return Response */ public function action_edit($type = null) { list($type, $is_regist) = self::validate_type($type, $this->u->id); $form_member_profile = new Form_MemberProfile($type == 'regist' ? 'regist-config' : 'config', $this->u); $form_member_profile->set_validation(); if (\Input::method() == 'POST') { \Util_security::check_csrf(); try { $form_member_profile->validate(true); \DB::start_transaction(); $form_member_profile->seve(); if ($is_regist) { Model_MemberConfig::delete_value($this->u->id, 'terms_un_agreement'); } \DB::commit_transaction(); $message = $is_regist ? sprintf('%sが%sしました。', term('site.registration'), term('form.complete')) : term('profile') . 'を編集しました。'; $redirect_uri = $is_regist ? $this->after_auth_uri : 'member/profile'; \Session::set_flash('message', $message); \Response::redirect($redirect_uri); } catch (\FuelException $e) { if (\DB::in_transaction()) { \DB::rollback_transaction(); } \Session::set_flash('error', $e->getMessage()); } } $this->set_title_and_breadcrumbs(term('profile') . term($is_regist ? 'site.registration' : 'form.edit'), $is_regist ? array() : array('member/profile' => term('common.my', 'profile')), $is_regist ? null : $this->u); $this->template->content = View::forge('member/profile/edit', array('is_regist' => $is_regist, 'val' => $form_member_profile->get_validation(), 'member_public_flags' => $form_member_profile->get_member_public_flags(), 'profiles' => $form_member_profile->get_profiles(), 'member_profile_public_flags' => $form_member_profile->get_member_profile_public_flags())); }
/** * Mmeber setting viewtype * * @access public * @return Response */ public function action_index() { $page_name = term('notice', 'site.setting'); $val = \Form_MemberConfig::get_validation($this->u->id, 'notice', 'Notice'); if (\Input::method() == 'POST') { \Util_security::check_csrf(); try { if (!$val->run()) { throw new \FuelException($val->show_errors()); } $post = $val->validated(); \DB::start_transaction(); \Form_MemberConfig::save($this->u->id, $val, $post); \DB::commit_transaction(); \Session::set_flash('message', $page_name . 'を変更しました。'); \Response::redirect('member/setting'); } catch (\FuelException $e) { if (\DB::in_transaction()) { \DB::rollback_transaction(); } \Session::set_flash('error', $e->getMessage()); } } $this->set_title_and_breadcrumbs($page_name, array('member/setting' => term('site.setting', 'form.update')), $this->u); $this->template->content = \View::forge('member/setting/_parts/form', array('val' => $val, 'label_size' => 5, 'form_params' => array('common' => array('radio' => array('layout_type' => 'grid'))))); }
/** * manage and execute queues * */ public function run() { // check pids if (\Config::get('queue.queue_parallel_number') <= count(glob(\APPPATH . 'tmp/' . \Config::get('queue.queue_pid_prefix') . '_*.pid'))) { \Log::debug('queue limit over.'); return; } $this->__process_file_name = \Config::get('queue.queue_pid_prefix') . '_' . getmypid() . '.pid'; // create pid file \File::create(\APPPATH . 'tmp', $this->__process_file_name); try { // check dead queues $recover = \Model_TaskQueue::recover_zombie_queues(); if (!empty($recover)) { \Model_TaskQueue::notify('zombie task recovered. ids = ' . implode(',', $recover)); } // check queues $queue = \Model_TaskQueue::pickup(); if (empty($queue)) { return; } // exec queue call_user_func_array('\\' . $queue['method'], \Format::forge($queue['options'], 'json')->to_array()); // finish (update to success) queue \Model_TaskQueue::finish($queue['id'], \Model_TaskQueue::STATUS_SUCCESS); } catch (\Exception $e) { if (\DB::in_transaction()) { \DB::rollback_transaction(); } if (isset($queue) and !empty($queue)) { // finish (update to error) queue \Model_TaskQueue::finish($queue['id'], \Model_TaskQueue::STATUS_ERROR); // send to notify method $body = array(); $body[] = 'task queue error occured.'; $body[] = '--------------------------------'; $body[] = 'id: ' . $queue['id']; $body[] = 'method: ' . $queue['method']; $body[] = 'options: ' . $queue['options']; if (is_array($e->getMessage())) { $body[] = 'reason: ' . implode(' ', $e->getMessage()); } elseif (!empty($e->getMessage())) { $body[] = 'reason: ' . $e->getMessage(); } \Model_TaskQueue::notify($body); } } finally { \File::delete(\APPPATH . 'tmp/' . $this->__process_file_name); } }
public function action_change_password() { Util_security::check_method('POST'); Util_security::check_csrf(); $form = $this->form_setting_password(); $val = $form->validation(); if (!$val->run()) { Session::set_flash('error', $val->show_errors()); $this->action_password(); return; } $post = $val->validated(); $error_message = ''; $is_transaction_rollback = false; try { DB::start_transaction(); $this->change_password($post['old_password'], $post['password']); DB::commit_transaction(); $mail = new Site_Mail('memberSettingPassword'); $mail->send($this->u->member_auth->email, array('to_name' => $this->u->name)); Session::set_flash('message', term('site.password') . 'を変更しました。'); Response::redirect('member/setting'); } catch (EmailValidationFailedException $e) { Util_Toolkit::log_error('send mail error: ' . __METHOD__ . ' validation error'); $error_message = 'メール送信エラー'; } catch (EmailSendingFailedException $e) { Util_Toolkit::log_error('send mail error: ' . __METHOD__ . ' sending error'); $error_message = 'メール送信エラー'; } catch (WrongPasswordException $e) { $is_transaction_rollback = true; $error_message = sprintf('現在の%sが正しくありません。', term('site.password')); } catch (\Auth\SimpleUserUpdateException $e) { $is_transaction_rollback = true; $error_message = term('site.password') . 'の変更に失敗しました。'; } catch (Database_Exception $e) { $is_transaction_rollback = true; $error_message = Site_Controller::get_error_message($e, true); } catch (FuelException $e) { $is_transaction_rollback = true; $error_message = $e->getMessage(); } if ($error_message) { if ($is_transaction_rollback && DB::in_transaction()) { DB::rollback_transaction(); } Session::set_flash('error', $error_message); } $this->action_password(); }
/** * Mmeber leave * * @access public * @return Response */ public function action_index() { $val = self::get_validation_object(); if (\Input::method() == 'POST') { \Util_security::check_csrf(); $success_message = sprintf('%sを%sしました。', term('form.invite', 'site.mail'), term('form.post')); $error_message = ''; $is_transaction_rollback = false; try { if (!$val->run()) { throw new ValidationFailedException($val->show_errors()); } $post = $val->validated(); if (Model_MemberPre::get_one4invite_member_id_and_email($this->u->id, $post['email'])) { throw new ValidationFailedException(sprintf('その%sは既に%sです。', term('site.email'), term('form.invited'))); } DB::start_transaction(); $token = Model_MemberPre::save_with_token($post['email'], null, $this->u->id); DB::commit_transaction(); $mail = new Site_Mail('memberInvite'); $mail->send($post['email'], array('register_url' => sprintf('%s?token=%s', Uri::create('member/register'), $token), 'invite_member_name' => $this->u->name, 'invite_message' => $post['message'])); Session::set_flash('message', $success_message); Response::redirect('member/invite'); } catch (ValidationFailedException $e) { $error_message = Site_Controller::get_error_message($e); } catch (EmailValidationFailedException $e) { Util_Toolkit::log_error('send mail error: ' . __METHOD__ . ' validation error'); $error_message = 'メール送信エラー'; } catch (EmailSendingFailedException $e) { Util_Toolkit::log_error('send mail error: ' . __METHOD__ . ' sending error'); $error_message = 'メール送信エラー'; } catch (\Database_Exception $e) { $is_transaction_rollback = true; $error_message = Site_Controller::get_error_message($e, true); } catch (FuelException $e) { $is_transaction_rollback = true; $error_message = Site_Controller::get_error_message($e); } if ($is_transaction_rollback && DB::in_transaction()) { DB::rollback_transaction(); } if ($error_message) { Session::set_flash('error', $error_message); } } $this->set_title_and_breadcrumbs(term('form.invite_friend'), null, $this->u); $this->template->content = \View::forge('member/invite', array('val' => $val, 'member_pres' => Model_MemberPre::get4invite_member_id($this->u->id))); }
/** * Fetch the database connection name to use * * @param bool if true return the writeable connection (if set) * @return null|string */ public static function connection($writeable = false) { // if in tracsaction, conection force to be writable. if (\DB::in_transaction()) { $writeable = true; } if ($writeable) { if (empty(static::$_write_connection)) { static::$_write_connection = static::get_write_connection_default(); } return static::$_write_connection; } if (empty(static::$_connection)) { static::$_connection = static::get_read_connection_default(); } return static::$_connection; }
/** * Create timeline * * @access public * @param int $parent_id target parent id * @return Response(json) * @throws Exception in Controller_Base::controller_common_api * @see Controller_Base::controller_common_api */ public function post_create() { $this->controller_common_api(function () { $this->response_body['errors']['message_default'] = term('timeline') . 'の' . term('form.post') . 'に失敗しました。'; $moved_files = array(); $album_image_ids = array(); $timeline = Model_Timeline::forge(); $val = \Validation::forge(); $val->add_model($timeline); if (!$val->run()) { throw new \ValidationFailedException($val->show_errors()); } $post = $val->validated(); $file_tmps = \Site_FileTmp::get_file_tmps_and_check_filesize($this->u->id, $this->u->filesize_total); if (!strlen($post['body']) && !$file_tmps) { throw new \ValidationFailedException('Data is empty.'); } $type_key = 'normal'; $album_id = (int) \Input::post('album_id', 0); if ($file_tmps && $album_id) { $album = \Album\Model_Album::check_authority($album_id, $this->u->id); if (\Album\Site_Util::check_album_disabled_to_update($album->foreign_table, true)) { throw new \ValidationFailedException('Album id is invalid.'); } $type_key = 'album_image'; } try { \DB::start_transaction(); if ($file_tmps) { if (!$album_id) { $type_key = 'album_image_timeline'; $album_id = \Album\Model_Album::get_id_for_foreign_table($this->u->id, 'timeline'); } list($moved_files, $album_image_ids) = \Site_FileTmp::save_images($file_tmps, $album_id, 'album_id', 'album_image', $post['public_flag']); } else { $album_id = null; } $timeline = \Timeline\Site_Model::save_timeline($this->u->id, $post['public_flag'], $type_key, $album_id, null, $post['body'], $timeline, $album_image_ids); \DB::commit_transaction(); // thumbnail 作成 & tmp_file thumbnail 削除 \Site_FileTmp::make_and_remove_thumbnails($moved_files); } catch (\Exception $e) { if (\DB::in_transaction()) { \DB::rollback_transaction(); } if ($moved_files) { \Site_FileTmp::move_files_to_tmp_dir($moved_files); } throw $e; } $data = array('id' => $timeline->id, 'message' => term('timeline') . 'を' . term('form.post') . 'しました。'); if (conf('service.facebook.shareDialog.myhome.autoPopupAfterCreated')) { $link = \Uri::create(Site_Util::get_detail_uri($timeline->id, $timeline->type)); $data['shareFacebook'] = array('obj' => array('link' => $link)); if ($album_image_ids && ($album_image = \Album\Model_AlbumImage::find($album_image_ids[0]))) { $data['shareFacebook']['obj']['picture'] = \Site_Util::get_media_uri(img_uri($album_image->file_name, 'thumbnail'), true); } } $this->set_response_body_api($data); }); }
/** * Action image delete * * @access public * @params integer * @return Response */ public function action_delete($id = null) { \Util_security::check_csrf(); $site_image = \Model_SiteImage::check_authority($id); try { \DB::start_transaction(); $site_image->delete(); \DB::commit_transaction(); \Session::set_flash('message', term('site.image') . 'を削除しました。'); \Response::redirect('admin/content/image'); } catch (\Database_Exception $e) { $error_message = \Site_Controller::get_error_message($e, true); } catch (Exception $e) { $error_message = $e->getMessage(); } if (\DB::in_transaction()) { \DB::rollback_transaction(); } \Session::set_flash('error', $error_message); \Response::redirect('admin/content/image/' . $id); }
/** * The plugin sink for the auth_ajax_hab_import_comments hook. * Responds via authenticated ajax to requests for comment importing. * * @param AjaxHandler $handler The handler that handled the request, contains $_POST info */ public function action_auth_ajax_hab_import_comments($handler) { $inputs = $_POST->filter_keys('db_type', 'db_name', 'db_host', 'db_user', 'db_pass', 'db_prefix', 'commentindex', 'tag_import'); $inputs = $inputs->getArrayCopy($inputs); $inputs = array_merge($this->default_values, $inputs); $connect_string = $this->get_connect_string($inputs['db_type'], $inputs['db_host'], $inputs['db_name']); $db = $this->hab_connect($connect_string, $inputs['db_user'], $inputs['db_pass']); if (!$db) { EventLog::log(sprintf(_t('Failed to import from "%s"'), $inputs['db_name']), 'crit'); Session::error($e->getMessage()); echo '<p>' . _t('Failed to connect using the given database connection details.') . '</p>'; } DB::begin_transaction(); $commentcount = $db->get_value("SELECT count( id ) FROM {$inputs['db_prefix']}comments;"); $min = $inputs['import_index'] * IMPORT_BATCH + ($inputs['import_index'] == 0 ? 0 : 1); $max = min(($inputs['import_index'] + 1) * IMPORT_BATCH, $commentcount); echo "<p>Importing comments {$min}-{$max} of {$commentcount}.</p>"; $post_info = DB::get_results("SELECT post_id, value FROM {$inputs['db_prefix']}postinfo WHERE name= 'old_id';"); foreach ($post_info as $info) { $post_map[$info->value] = $info->post_id; } $comments = $db->get_results("\r\n\t\t\tSELECT\r\n\t\t\tc.id,\r\n\t\t\tc.content,\r\n\t\t\tc.name,\r\n\t\t\tc.email,\r\n\t\t\tc.url,\r\n\t\t\tc.ip,\r\n\t\t\tc.status,\r\n\t\t\tc.date,\r\n\t\t\tc.type,\r\n\t\t\tc.post_id as old_post_id\r\n\t\t\tFROM {$inputs['db_prefix']}comments c\r\n\t\t\tINNER JOIN\r\n\t\t\t{$inputs['db_prefix']}posts on {$inputs['db_prefix']}posts.id = c.post_id\r\n\t\t\tLIMIT {$min}, " . IMPORT_BATCH, array(), 'Comment'); foreach ($comments as $comment) { $carray = $comment->to_array(); if (isset($post_map[$carray['old_post_id']])) { $carray['post_id'] = $post_map[$carray['old_post_id']]; unset($carray['old_post_id']); $c = new Comment($carray); $infos = $db->get_results("SELECT name, value, type FROM {$inputs['db_prefix']}commentinfo WHERE comment_id = ?", array($carray['id'])); foreach ($infos as $info) { $fields = $info->get_url_args(); if ($fields['type'] == 1) { $fields['value'] = unserialize($fields['value']); } $c->info->{$fields}['name'] = $fields['value']; } try { $c->insert(); } catch (Exception $e) { EventLog::log($e->getMessage(), 'err', null, null, print_r(array($c, $e), 1)); Session::error($e->getMessage()); $errors = Options::get('import_errors'); $errors[] = $e->getMessage(); Options::set('import_errors', $errors); } } } if (DB::in_transaction()) { DB::commit(); } if ($max < $commentcount) { $ajax_url = URL::get('auth_ajax', array('context' => 'hab_import_comments')); $inputs['import_index']++; echo $this->get_ajax($ajax_url, $inputs); } else { EventLog::log('Import complete from "' . $inputs['db_name'] . '"'); echo '<p>' . _t('Import is complete.') . '</p>'; $errors = Options::get('import_errors'); if (count($errors) > 0) { echo '<p>' . _t('There were errors during import:') . '</p>'; echo '<ul>'; foreach ($errors as $error) { echo '<li>' . $error . '</li>'; } echo '</ul>'; } } }
/** * The edit_options action. * * @access public * @return void */ public function action_edit_options($id = null) { if (!$id || !($profile = \Model_Profile::find($id))) { throw new \HttpNotFoundException(); } if (!in_array($profile->form_type, \Site_Profile::get_form_types_having_profile_options())) { throw new \HttpInvalidInputException(); } $profile_options = \Model_ProfileOption::get4profile_id($id); $posted_vals = array(); if (\Input::method() == 'POST') { try { \Util_security::check_csrf(); $posted_vals = \Input::post('labels'); if (count($posted_vals) != count($profile_options)) { throw new \httpinvalidinputexception(); } \DB::start_transaction(); foreach ($profile_options as $profile_option) { $value = $posted_vals[$profile_option->id]; if (!strlen($value)) { throw new \httpinvalidinputexception('未入力の項目があります。'); } if ($value !== $profile_option->label) { $profile_option->label = $value; $profile_option->save(); } } \DB::commit_transaction(); \Session::set_flash('message', term('profile', 'form.choices') . 'を編集しました。'); \Response::redirect('admin/profile/options/' . $profile->id); } catch (\FuelException $e) { if (\DB::in_transaction()) { \DB::rollback_transaction(); } \Session::set_flash('error', $e->getMessage()); } } $vals = array(); foreach ($profile_options as $profile_option) { $vals[$profile_option->id] = isset($posted_vals[$profile_option->id]) ? $posted_vals[$profile_option->id] : $profile_option->label; } $this->set_title_and_breadcrumbs(sprintf('%s %s: %s', term('profile'), term('form.edit'), $profile->caption)); $this->template->content = \View::forge('profile/edit_options', array('profile' => $profile, 'vals' => $vals, 'profile_options' => $profile_options)); }
/** * Admin account delete * * @access public * @params integer * @return Response */ public function action_delete($id = null) { \Util_security::check_method('POST'); \Util_security::check_csrf(); if (check_original_user($id, true)) { throw new \HttpForbiddenException(); } $user = Model_AdminUser::check_authority($id); try { $auth = \Auth::instance(); \DB::start_transaction(); $auth->delete_user($user->username); \DB::commit_transaction(); \Session::set_flash('message', term('admin.user.view') . 'を削除しました。'); } catch (\FuelException $e) { if (\DB::in_transaction()) { \DB::rollback_transaction(); } \Session::set_flash('error', $e->getMessage()); } \Response::redirect(\Site_Util::get_redirect_uri('admin/account')); }
/** * News delete * * @access public * @params integer * @return Response */ public function action_delete($id = null) { $id = (int) $id; \Util_security::check_method('POST'); \Util_security::check_csrf(); $error_message = ''; $is_transaction_rollback = false; try { $member = \Model_Member::check_authority($id); $message = \Site_Member::remove($member); \Session::set_flash('message', $message); } catch (\EmailValidationFailedException $e) { \Util_Toolkit::log_error('send mail error: ' . __METHOD__ . ' validation error'); $error_message = 'メール送信エラー'; } catch (\EmailSendingFailedException $e) { \Util_Toolkit::log_error('send mail error: ' . __METHOD__ . ' sending error'); $error_message = 'メール送信エラー'; } catch (\Auth\SimpleUserUpdateException $e) { $is_transaction_rollback = true; $error_message = term('member.view') . 'が存在しません。'; } catch (\Database_Exception $e) { $is_transaction_rollback = true; $error_message = \Site_Controller::get_error_message($e, true); } catch (\FuelException $e) { $is_transaction_rollback = true; if (!($error_message = $e->getMessage())) { $error_message = term('site.left') . 'に失敗しました。'; } } if ($error_message) { if ($is_transaction_rollback && \DB::in_transaction()) { \DB::rollback_transaction(); } \Session::set_flash('error', $error_message); } \Response::redirect(\Site_Util::get_redirect_uri('admin/member')); }
/** * The edit_all action. * * @access public * @return void */ public function action_edit_all() { $news_categories = \News\Model_NewsCategory::get_all(); $posted_vals = array(); if (\Input::method() == 'POST') { try { \Util_security::check_csrf(); $posted_vals = \Input::post('labels'); if (count($posted_vals) != count($news_categories)) { throw new \httpinvalidinputexception(); } \DB::start_transaction(); foreach ($news_categories as $news_category) { $value = $posted_vals[$news_category->id]; if (!strlen($value)) { throw new \httpinvalidinputexception('未入力の項目があります。'); } if ($value !== $news_category->label) { $news_category->label = $value; $news_category->save(); } } \DB::commit_transaction(); \Session::set_flash('message', term('news.category.view') . 'を編集しました。'); \Response::redirect('admin/news/category'); } catch (\FuelException $e) { if (\DB::in_transaction()) { \DB::rollback_transaction(); } \Session::set_flash('error', $e->getMessage()); } } $vals = array(); foreach ($news_categories as $news_category) { $vals[$news_category->id] = isset($posted_vals[$news_category->id]) ? $posted_vals[$news_category->id] : $news_category->label; } $this->set_title_and_breadcrumbs(term('news.view', 'news.category.label', 'form.edit_all'), array('admin/news' => term('news.view', 'site.management'), 'admin/news/category' => term('news.category.view', 'site.management'))); $this->template->content = \View::forge('news/category/edit_all', array('vals' => $vals, 'news_categories' => $news_categories)); }
/** * The plugin sink for the auth_ajax_wp_import_comments hook. * Responds via authenticated ajax to requests for comment importing. * * @param AjaxHandler $handler The handler that handled the request, contains $_POST info */ public function action_auth_ajax_wp_import_comments($handler) { $valid_fields = array('db_name', 'db_host', 'db_user', 'db_pass', 'db_prefix', 'commentindex', 'category_import', 'utw_import'); $inputs = array_intersect_key($_POST->getArrayCopy(), array_flip($valid_fields)); extract($inputs); $wpdb = $this->wp_connect($db_host, $db_name, $db_user, $db_pass, $db_prefix); if ($wpdb) { if (!DB::in_transaction()) { DB::begin_transaction(); } $commentcount = $wpdb->get_value("SELECT count( comment_ID ) FROM {$db_prefix}comments;"); $min = $commentindex * IMPORT_BATCH + 1; $max = min(($commentindex + 1) * IMPORT_BATCH, $commentcount); echo "<p>Importing comments {$min}-{$max} of {$commentcount}.</p>"; $postinfo = DB::table('postinfo'); $post_info = DB::get_results("SELECT post_id, value FROM {$postinfo} WHERE name= 'wp_id';"); foreach ($post_info as $info) { $post_map[$info->value] = $info->post_id; } $comments = $wpdb->get_results("\n\t\t\t\tSELECT\n\t\t\t\tcomment_content as content,\n\t\t\t\tcomment_author as name,\n\t\t\t\tcomment_author_email as email,\n\t\t\t\tcomment_author_url as url,\n\t\t\t\tINET_ATON( comment_author_IP ) as ip,\n\t\t\t \tcomment_approved as status,\n\t\t\t\tcomment_date as date,\n\t\t\t\tcomment_type as type,\n\t\t\t\tID as wp_post_id\n\t\t\t\tFROM {$db_prefix}comments\n\t\t\t\tINNER JOIN\n\t\t\t\t{$db_prefix}posts on ( {$db_prefix}posts.ID= {$db_prefix}comments.comment_post_ID )\n\t\t\t\tLIMIT {$min}, " . IMPORT_BATCH, array(), 'Comment'); foreach ($comments as $comment) { switch ($comment->type) { case 'pingback': $comment->type = Comment::PINGBACK; break; case 'trackback': $comment->type = Comment::TRACKBACK; break; default: $comment->type = Comment::COMMENT; } $comment->content = MultiByte::convert_encoding($comment->content); $comment->name = MultiByte::convert_encoding($comment->name); $carray = $comment->to_array(); if ($carray['ip'] == '') { $carray['ip'] = 0; } switch ($carray['status']) { case '0': $carray['status'] = Comment::STATUS_UNAPPROVED; break; case '1': $carray['status'] = Comment::STATUS_APPROVED; break; case 'spam': $carray['status'] = Comment::STATUS_SPAM; break; } if (isset($post_map[$carray['wp_post_id']])) { $carray['post_id'] = $post_map[$carray['wp_post_id']]; unset($carray['wp_post_id']); $c = new Comment($carray); //Utils::debug( $c ); try { $c->insert(); } catch (Exception $e) { EventLog::log($e->getMessage(), 'err', null, null, print_r(array($c, $e), 1)); Session::error($e->getMessage()); $errors = Options::get('import_errors'); $errors[] = $e->getMessage(); Options::set('import_errors', $errors); } } } if (DB::in_transaction()) { DB::commit(); } if ($max < $commentcount) { $ajax_url = URL::get('auth_ajax', array('context' => 'wp_import_comments')); $commentindex++; $vars = Utils::addslashes(array('host' => $db_host, 'name' => $db_name, 'user' => $db_user, 'pass' => $db_pass, 'prefix' => $db_prefix)); echo <<<WP_IMPORT_AJAX1 \t\t\t\t\t<script type="text/javascript"> \t\t\t\t\t\$( '#import_progress' ).load( \t\t\t\t\t\t"{$ajax_url}", \t\t\t\t\t\t{ \t\t\t\t\t\t\tdb_host: "{$vars['host']}", \t\t\t\t\t\t\tdb_name: "{$vars['name']}", \t\t\t\t\t\t\tdb_user: "******", \t\t\t\t\t\t\tdb_pass: "******", \t\t\t\t\t\t\tdb_prefix: "{$vars['prefix']}", \t\t\t\t\t\t\tcategory_import: "{$category_import}", \t\t\t\t\t\t\tutw_import: "{$utw_import}", \t\t\t\t\t\t\tcommentindex: {$commentindex} \t\t\t\t\t\t} \t\t\t\t\t ); \t\t\t\t</script> WP_IMPORT_AJAX1; } else { EventLog::log('Import complete from "' . $db_name . '"'); echo '<p>' . _t('Import is complete.') . '</p>'; $errors = Options::get('import_errors'); if (count($errors) > 0) { echo '<p>' . _t('There were errors during import:') . '</p>'; echo '<ul>'; foreach ($errors as $error) { echo '<li>' . $error . '</li>'; } echo '</ul>'; } } } else { EventLog::log(sprintf(_t('Failed to import from "%s"'), $db_name), 'crit'); Session::error($e->getMessage()); echo '<p>' . _t('Failed to connect using the given database connection details.') . '</p>'; } }
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); }
/** * The plugin sink for the auth_ajax_chyrp_import_posts hook. * Responds via authenticated ajax to requests for post importing. * * @param AjaxHandler $handler The handler that handled the request, contains $_POST info */ public function action_auth_ajax_chyrp_import_posts($handler) { $inputs = $_POST->filter_keys('db_type', 'db_name', 'db_host', 'db_user', 'db_pass', 'postindex'); foreach ($inputs as $key => $value) { ${$key} = $value; } $connect_string = $this->get_connect_string($db_type, $db_host, $db_name); $db = $this->chryp_connect($connect_string, $db_user, $db_pass); if ($db) { DB::begin_transaction(); $postcount = $db->get_value("SELECT count(id) FROM posts;"); $min = $postindex * IMPORT_BATCH + ($postindex == 0 ? 0 : 1); $max = min(($postindex + 1) * IMPORT_BATCH, $postcount); // old_id was set when we imported the users $user_map = array(); $user_info = DB::get_results("SELECT user_id, value FROM {userinfo} WHERE name='old_id';"); foreach ($user_info as $info) { $user_map[$info->value] = $info->user_id; } // Posts // id INTEGER PRIMARY KEY AUTOINCREMENT, // feather VARCHAR(32) DEFAULT '', // clean VARCHAR(128) DEFAULT '', // url VARCHAR(128) DEFAULT '', // pinned BOOLEAN DEFAULT FALSE, // status VARCHAR(32) DEFAULT 'public', // user_id INTEGER DEFAULT 0, // created_at DATETIME DEFAULT NULL, // updated_at DATETIME DEFAULT NULL // // Post attributes // post_id INTEGER NOT NULL , // name VARCHAR(100) DEFAULT '', // value LONGTEXT, echo "<p>Importing posts {$min}-{$max} of {$postcount}.</p>"; $posts = $db->get_results("\r\n\t\t\t\tSELECT\r\n\t\t\t\t\tattr_body.value as content,\r\n\t\t\t\t\tid,\r\n\t\t\t\t\tattr_title.value as title,\r\n\t\t\t\t\tuser_id,\r\n\t\t\t\t\tcreated_at as pubdate,\r\n\t\t\t\t\tupdated_at as updated,\r\n\t\t\t\t\tupdated_at as modified,\r\n\t\t\t\t\tstatus\r\n\t\t\t\tFROM posts\r\n\t\t\t\tINNER JOIN post_attributes attr_title ON posts.id = attr_title.post_id AND attr_title.name = 'title'\r\n\t\t\t\tINNER JOIN post_attributes attr_body ON posts.id = attr_body.post_id AND attr_body.name = 'body'\r\n\t\t\t\tORDER BY id DESC\r\n\t\t\t\tLIMIT {$min}, " . IMPORT_BATCH, array(), 'Post'); $post_map = DB::get_column("SELECT value FROM {postinfo} WHERE name='old_id';"); foreach ($posts as $post) { if (in_array($post->id, $post_map)) { continue; } $post_array = $post->to_array(); $post_array['content_type'] = Post::type('entry'); $p = new Post($post_array); $p->slug = $post->slug; if (isset($user_map[$p->user_id])) { $p->user_id = $user_map[$p->user_id]; } else { $errors = Options::get('import_errors'); $errors[] = _t('Post author id %s was not found in the external database, assigning post "%s" (external post id #%d) to current user.', array($p->user_id, $p->title, $post_array['id'])); Options::set('import_errors', $errors); $p->user_id = User::identify()->id; } $p->guid = $p->guid; // Looks fishy, but actually causes the guid to be set. $p->info->old_id = $post_array['id']; // Store the old post id in the post_info table for later try { $p->insert(); $p->updated = $post_array['updated']; $p->update(); } catch (Exception $e) { EventLog::log($e->getMessage(), 'err', null, null, print_r(array($p, $e), 1)); Session::error($e->getMessage()); $errors = Options::get('import_errors'); $errors[] = $p->title . ' : ' . $e->getMessage(); Options::set('import_errors', $errors); } } if (DB::in_transaction()) { DB::commit(); } if ($max < $postcount) { $ajax_url = URL::get('auth_ajax', array('context' => 'chyrp_import_posts')); $postindex++; $vars = Utils::addslashes(array('host' => $db_host, 'name' => $db_name, 'user' => $db_user, 'pass' => $db_pass)); echo <<<IMPORT_POSTS \t\t\t\t\t<script type="text/javascript"> \t\t\t\t\t\$( '#import_progress' ).load( \t\t\t\t\t\t"{$ajax_url}", \t\t\t\t\t\t{ \t\t\t\t\t\t\tdb_type: "{$db_type}", \t\t\t\t\t\t\tdb_host: "{$vars['host']}", \t\t\t\t\t\t\tdb_name: "{$vars['name']}", \t\t\t\t\t\t\tdb_user: "******", \t\t\t\t\t\t\tdb_pass: "******", \t\t\t\t\t\t\tpostindex: {$postindex} \t\t\t\t\t\t} \t\t\t\t\t); \t\t\t\t</script> IMPORT_POSTS; } else { EventLog::log('Import complete from "' . $db_name . '"'); echo '<p>' . _t('Import is complete.') . '</p>'; $errors = Options::get('import_errors'); if (count($errors) > 0) { echo '<p>' . _t('There were errors during import:') . '</p>'; echo '<ul>'; foreach ($errors as $error) { echo '<li>' . $error . '</li>'; } echo '</ul>'; } } } else { EventLog::log(sprintf(_t('Failed to import from "%s"'), $db_name), 'crit'); Session::error($e->getMessage()); echo '<p>' . _t('The database connection details have failed to connect.') . '</p>'; } }
/** * Execute confirm signup * * @access public * @return Response */ public function action_confirm_signup() { Util_security::check_method('POST'); Util_security::check_csrf(); if (!($form = Fieldset::instance('confirm_signup'))) { $form = $this->get_form_signup_confirm(); } $val = $form->validation(); $val->fieldset()->field('email')->delete_rule('unique'); $redirect_uri = conf('login_uri.site'); $success_message = '仮登録が完了しました。受信したメール内に記載された URL より本登録を完了してください。'; $error_message = ''; $is_transaction_rollback = false; try { if (!$val->run()) { throw new \FuelException($val->show_errors()); } $post = $val->validated(); if (Model_MemberAuth::get4email($post['email'])) { if (conf('member.register.email.hideUniqueCheck')) { Session::set_flash('message', $success_message); Response::redirect($redirect_uri); } throw new FuelException('その' . term('site.email') . 'は登録できません。'); } DB::start_transaction(); $token = Model_MemberPre::save_with_token($post['email'], $post['password']); DB::commit_transaction(); $mail = new Site_Mail('memberSignup'); $mail->send($post['email'], array('register_url' => sprintf('%s?token=%s', Uri::create('member/register'), $token))); Session::set_flash('message', $success_message); Response::redirect($redirect_uri); } catch (EmailValidationFailedException $e) { Util_Toolkit::log_error('send mail error: ' . __METHOD__ . ' validation error'); $error_message = 'メール送信エラー'; } catch (EmailSendingFailedException $e) { Util_Toolkit::log_error('send mail error: ' . __METHOD__ . ' sending error'); $error_message = 'メール送信エラー'; } catch (\Database_Exception $e) { $is_transaction_rollback = true; $error_message = \Site_Controller::get_error_message($e, true); } catch (FuelException $e) { $is_transaction_rollback = true; $error_message = $e->getMessage(); } if ($is_transaction_rollback && DB::in_transaction()) { DB::rollback_transaction(); } Session::set_flash('error', $error_message); $this->action_signup(); }
protected function controller_common_api(callable $func) { try { $this->check_response_format($this->api_accept_formats); if (Input::method() != 'GET' && !$this->api_not_check_csrf) { Util_security::check_csrf(); } $this->response_body = $func() ?: $this->response_body; // execute main. if (Site_Model::check_is_orm_obj($this->response_body)) { throw new \FuelException('Response body not allowed Orm obj.'); } $status_code = 200; } catch (\HttpNotFoundException $e) { $status_code = 404; } catch (\ApiNotAuthorizedException $e) { $status_code = 401; } catch (\HttpForbiddenException $e) { $status_code = 403; } catch (\HttpMethodNotAllowed $e) { $status_code = 405; } catch (\HttpBadRequestException $e) { $status_code = 400; } catch (\HttpInvalidInputException $e) { $status_code = 400; } catch (\ValidationFailedException $e) { $this->response_body['errors']['message'] = Site_Controller::get_error_message($e); $status_code = 400; } catch (\DisableToUpdateException $e) { $this->response_body['errors']['message'] = $e->getMessage() ?: term('form.update') . 'が禁止されています。'; $status_code = 400; } catch (\Database_Exception $e) { $this->response_body['errors']['message'] = Site_Controller::get_error_message($e, true); $status_code = 500; } catch (\FuelException $e) { $status_code = 500; } catch (\Exception $e) { $status_code = 500; } if ($status_code == 500) { if (!empty($e)) { Util_Toolkit::log_error($e->getMessage()); } if (\DB::in_transaction()) { \DB::rollback_transaction(); } } $response_body = Site_Controller::supply_response_body($this->response_body, $status_code, $this->format); return self::response($response_body, $status_code); }
/** * Execute reset password. * * @access public * @return Response */ public function action_reset_password() { // Already logged in Auth::check() and Response::redirect('member'); $member_password_pre = Model_MemberPasswordPre::get4token(Input::param('token')); if (!$member_password_pre || !Site_Util::check_token_lifetime($member_password_pre->updated_at, conf('member.recover.password.token_lifetime'))) { Session::set_flash('error', sprintf('URLが%sです。', term('form.disabled'))); throw new HttpNotFoundException(); } $form = $this->form_reset_password(); $val = $form->validation(); if (Input::method() == 'POST') { Util_security::check_csrf(); $auth = Auth::instance(); $error_message = ''; $is_transaction_rollback = false; try { if (!$val->run()) { throw new FuelException($val->show_errors() ?: term('site.password') . 'が正しくありません'); } $post = $val->validated(); $to_email = $member_password_pre->email; $to_name = $member_password_pre->member->name; DB::start_transaction(); $auth->change_password_simple($member_password_pre->member_id, $post['password']); $member_password_pre->delete(); // 仮登録情報の削除 DB::commit_transaction(); $mail = new Site_Mail('memberResetPassword'); $mail->send($to_email, array('to_name' => $to_name)); $auth->login($to_email, $post['password']); Session::set_flash('message', term('site.password') . 'を登録しました。'); Response::redirect('member'); } catch (EmailValidationFailedException $e) { Util_Toolkit::log_error('send mail error: ' . __METHOD__ . ' validation error'); $error_message = 'メール送信エラー'; } catch (EmailSendingFailedException $e) { Util_Toolkit::log_error('send mail error: ' . __METHOD__ . ' sending error'); $error_message = 'メール送信エラー'; } catch (Auth\SimpleUserUpdateException $e) { $is_transaction_rollback = true; $error_message = term('site.password') . 'の登録に失敗しました。'; } catch (\Database_Exception $e) { $is_transaction_rollback = true; $error_message = \Site_Controller::get_error_message($e, true); } catch (FuelException $e) { $is_transaction_rollback = true; $error_message = $e->getMessage(); } if ($error_message) { if ($is_transaction_rollback && DB::in_transaction()) { DB::rollback_transaction(); } Session::set_flash('error', $error_message); } } $this->set_title_and_breadcrumbs(term('site.password') . 'の再登録'); $data = array('val' => $val, 'member_password_pre' => $member_password_pre); $this->template->content = View::forge('member/recover/reset_password', $data); $this->template->content->set_safe('html_form', $form->build('member/recover/reset_password')); // form の action に入る }
/** * Note publish * * @access public * @params integer * @return Response */ public function action_publish($id = null) { \Util_security::check_method('POST'); \Util_security::check_csrf(); $note = Model_Note::check_authority($id, $this->u->id); if ($note->is_published) { \Session::set_flash('error', '既に公開されています。'); \Response::redirect('note/detail/' . $id); } try { \DB::start_transaction(); list($is_changed, $is_published) = $note->save_with_relations($this->u->id, array('is_published' => 1)); \DB::commit_transaction(); \Session::set_flash('message', term('note') . 'を公開しました。'); } catch (\FuelException $e) { if (\DB::in_transaction()) { \DB::rollback_transaction(); } \Session::set_flash('error', $e->getMessage()); } \Response::redirect('note/detail/' . $id); }
public function provider_signup($provider, $response = null) { $service_name = isset($response['auth']['info']['name']) ? $response['auth']['info']['name'] : $response['auth']['info']['nickname']; $input = array('uid' => (string) $response['auth']['uid'], 'token' => $response['auth']['credentials']['token'], 'service_name' => $response['auth']['info']['name']); if (!empty($response['auth']['credentials']['expires'])) { $input['expires'] = strtotime($response['auth']['credentials']['expires']); } if ($service_url = $this->get_service_url($provider, $response)) { $input['service_url'] = $service_url; } try { $member_oauth = Model_MemberOauth::forge(); $val = Validation::forge('provider_signup'); $val->add_model($member_oauth); $val->fieldset()->field('member_id')->delete_rule('required'); if (!$val->run($input)) { throw new \FuelException($val->show_errors()); } $input = $val->validated(); $provider_id = Model_OauthProvider::get_id($provider); \DB::start_transaction(); $member = Model_Member::forge(); $member->name = str_replace(' ', '', $input['service_name']); list($member->sex, $member->sex_public_flag) = Site_Oauth::get_sex($response, $provider); list($member->birthyear, $member->birthyear_public_flag) = Site_Oauth::get_birthyear($response, $provider); list($member->birthday, $member->birthday_public_flag) = Site_Oauth::get_birthday($response, $provider); $member->filesize_total = 0; $member->register_type = $provider_id; if ($member->save() === false) { throw new \FuelException('Member save failed.'); } $member_oauth->member_id = $member->id; $member_oauth->oauth_provider_id = $provider_id; $member_oauth->uid = $input['uid']; $member_oauth->token = $input['token']; $member_oauth->secret = $input['secret']; $member_oauth->service_name = $input['service_name']; if (!empty($input['expires'])) { $member_oauth->expires = $input['expires']; } if (!empty($input['service_url'])) { $member_oauth->service_url = $input['service_url']; } if ($member_oauth->save() === false) { throw new \FuelException('Oauth data save failed.'); } if (!empty($response['auth']['info']['email'])) { Model_Memberauth::save_email($response['auth']['info']['email'], $member->id); } if (conf('auth.oauth.saveTermsUnAgreement')) { Model_MemberConfig::set_value($member->id, 'terms_un_agreement', 1); } // timeline 投稿 if (is_enabled('timeline')) { \Timeline\Site_Model::save_timeline($member->id, null, 'member_register', $member->id, $member->created_at); } \DB::commit_transaction(); if (!empty($response['auth']['info']['image'])) { $this->save_profile_image($response['auth']['provider'], $response['auth']['info']['image'], $member); } } catch (\FuelException $e) { if (\DB::in_transaction()) { \DB::rollback_transaction(); } if (conf('auth.oauth.log.isOutputErrorLog.provider_signup')) { \Util_Toolkit::log_error('OAuth provider_signup error: ' . isset($e) ? $e->getMessage() : ''); } return $this->login_failed(); } $this->force_login($member->id); if (conf('auth.oauth.forceSetRememberMe')) { Auth::remember_me(); } return $this->login_succeeded(); }
/** * Mmeber_Profile_Image delete * * @access public * @return Response */ public function action_delete($album_image_id = null) { try { Util_security::check_csrf(); if (!conf('upload.types.img.types.m.save_as_album_image')) { throw new HttpNotFoundException(); } $album_image = \Album\Model_AlbumImage::check_authority($album_image_id, $this->u->id); if ($album_image->album->foreign_table != 'member') { throw new FuelException('Disabled to set album image as profile image.'); } DB::start_transaction(); $album_image->delete(); DB::commit_transaction(); Session::set_flash('message', term('profile', 'site.picture') . 'を削除しました。'); } catch (Database_Exception $e) { if (DB::in_transaction()) { DB::rollback_transaction(); } Session::set_flash('error', Site_Controller::get_error_message($e, true)); } catch (FuelException $e) { if (DB::in_transaction()) { DB::rollback_transaction(); } Session::set_flash('error', $e->getMessage()); } Response::redirect('member/profile/image'); }
public function action_delete() { Util_security::check_method('POST'); Util_security::check_csrf(); $form = $this->form_leave(); $val = $form->validation(); if (!$val->run()) { Session::set_flash('error', $val->show_errors()); $this->action_index(); return; } if (!$this->u->check_registered_oauth(true) && !$this->auth_instance->check_password()) { Session::set_flash('error', term('site.password') . 'が正しくありません'); $this->action_index(); return; } $error_message = ''; $is_transaction_rollback = false; try { $message = Site_Member::remove($this->u); $this->auth_instance->logout(); Session::set_flash('message', $message); Response::redirect(conf('login_uri.site')); } catch (EmailValidationFailedException $e) { Util_Toolkit::log_error('send mail error: ' . __METHOD__ . ' validation error'); $error_message = 'メール送信エラー'; } catch (EmailSendingFailedException $e) { Util_Toolkit::log_error('send mail error: ' . __METHOD__ . ' sending error'); $error_message = 'メール送信エラー'; } catch (SimpleUserUpdateException $e) { $is_transaction_rollback = true; $error_message = term('member.view') . 'が存在しません。'; } catch (Database_Exception $e) { $is_transaction_rollback = true; $error_message = Site_Controller::get_error_message($e, true); } catch (FuelException $e) { $is_transaction_rollback = true; if (!($error_message = $e->getMessage())) { $error_message = term('site.left') . 'に失敗しました。'; } } if ($error_message) { if ($is_transaction_rollback && DB::in_transaction()) { DB::rollback_transaction(); } Session::set_flash('error', $error_message); } $this->action_index(); }
/** * News delete * * @access public * @params integer * @return Response */ public function action_delete($id = null) { \Util_security::check_method('POST'); \Util_security::check_csrf(); $content_page = \Content\Model_ContentPage::check_authority($id); $error_message = ''; try { \DB::start_transaction(); $content_page->delete(); \DB::commit_transaction(); \Session::set_flash('message', term('content.page') . 'を削除しました。'); } 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(); } \Session::set_flash('error', $error_message); } \Response::redirect(\Site_Util::get_redirect_uri('admin/content/page')); }
/** * Album_image edit * * @access public * @params integer * @return Response */ public function action_edit($id = null) { $album_image = Model_Albumimage::check_authority($id, $this->u->id); $val = self::get_validation_object($album_image); $is_enabled_map = is_enabled_map('image/edit', 'album'); $location = $is_enabled_map ? Model_AlbumimageLocation::get_locations4album_image_id($id) : null; if (\Input::method() == 'POST') { try { \Util_security::check_csrf(); if (!$val->run()) { throw new \FuelException($val->show_errors()); } $post = $val->validated(); if (empty($post['name']) && empty($post['shot_at_time']) && ($is_enabled_map && !strlen($post['latitude']) && !strlen($post['longitude']))) { throw new \FuelException('入力してください'); } $disabled_to_update_message = Site_Util::check_album_disabled_to_update($album_image->album->foreign_table); if ($disabled_to_update_message && isset($post['public_flag']) && $album_image->public_flag != $post['public_flag']) { throw new \FuelException($disabled_to_update_message); } \DB::start_transaction(); $album_image->update_with_relations($post); \DB::commit_transaction(); \Session::set_flash('message', term('album_image') . 'を編集をしました。'); \Response::redirect('album/image/' . $album_image->id); } catch (\FuelException $e) { if (\DB::in_transaction()) { \DB::rollback_transaction(); } \Session::set_flash('error', $e->getMessage()); } } $album_image_page_title = Site_Util::get_album_image_display_name($album_image, term('album_image', 'site.detail')); $this->set_title_and_breadcrumbs(sprintf('%sを%s', term('album_image'), term('form.do_edit')), array('/album/' . $album_image->album_id => $album_image->album->name, '/album/image/' . $id => $album_image_page_title), $album_image->album->member, 'album'); $this->template->post_header = \View::forge('_parts/datetimepicker_header'); $this->template->post_footer = \View::forge('image/_parts/edit_footer'); $this->template->content = \View::forge('image/edit', array('val' => $val, 'album_image' => $album_image, 'location' => $location)); }
/** * Reset action. * * @access public * @params integer * @return Response */ public function action_reset($db_key = null) { \Util_security::check_method('POST'); \Util_security::check_csrf(); if (!($template = \Model_Template::get4name($db_key))) { throw new \HttpNotFoundException(); } $error_message = ''; try { \DB::start_transaction(); $template->delete(); \DB::commit_transaction(); \Session::set_flash('message', 'デフォルトに戻しました。'); } 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(); } \Session::set_flash('error', $error_message); } \Response::redirect('admin/content/template/mail'); }
/** * Attempts to install the database. Returns the result of * the installation, adding errors to the theme if any * occur * * @return bool result of installation */ private function install_db() { $db_host = $this->handler_vars['db_host']; $db_type = $this->handler_vars['db_type']; $db_schema = $this->handler_vars['db_schema']; $db_user = $this->handler_vars['db_user']; $db_pass = $this->handler_vars['db_pass']; switch ($db_type) { case 'mysql': case 'pgsql': // MySQL & PostgreSQL requires specific connection information if (empty($db_user)) { $this->theme->assign('form_errors', array("{$db_type}_db_user" => _t('User is required.'))); return false; } if (empty($db_schema)) { $this->theme->assign('form_errors', array("{$db_type}_db_schema" => _t('Name for database is required.'))); return false; } if (empty($db_host)) { $this->theme->assign('form_errors', array("{$db_type}_db_host" => _t('Host is required.'))); return false; } break; case 'sqlite': // If this is a SQLite database, let's check that the file // exists and that we can access it. if (!$this->check_sqlite()) { return false; } break; } if (isset($this->handler_vars['table_prefix'])) { // store prefix in the Config singleton so DatabaseConnection can access it Config::set('db_connection', array('prefix' => $this->handler_vars['table_prefix'])); } if (!$this->connect_to_existing_db()) { $this->theme->assign('form_errors', array("{$db_type}_db_user" => _t('Problem connecting to supplied database credentials'))); return false; } DB::begin_transaction(); /* Let's install the DB tables now. */ $create_table_queries = $this->get_create_table_queries($this->handler_vars['db_type'], $this->handler_vars['table_prefix'], $this->handler_vars['db_schema']); DB::clear_errors(); DB::dbdelta($create_table_queries, true, true, true); if (DB::has_errors()) { $error = DB::get_last_error(); $this->theme->assign('form_errors', array('db_host' => _t('Could not create schema tables… %s', array($error['message'])))); DB::rollback(); return false; } // Cool. DB installed. Create the default options // but check first, to make sure if (!Options::get('installed')) { if (!$this->create_default_options()) { $this->theme->assign('form_errors', array('options' => _t('Problem creating default options'))); DB::rollback(); return false; } } // Create the Tags vocabulary if (!$this->create_tags_vocabulary()) { $this->theme->assign('form_errors', array('options' => _t('Problem creating tags vocabulary'))); DB::rollback(); return false; } // Create the standard post types and statuses if (!$this->create_base_post_types()) { $this->theme->assign('form_errors', array('options' => _t('Problem creating base post types'))); DB::rollback(); return false; } if (!$this->create_base_comment_types()) { $this->theme->assign('form_errors', array('options' => _t('Problem creating base comment types and statuses'))); DB::rollback(); return false; } // Let's setup the admin user and group now. // But first, let's make sure that no users exist $all_users = Users::get_all(); if (count($all_users) < 1) { $user = $this->create_admin_user(); if (!$user) { $this->theme->assign('form_errors', array('admin_user' => _t('Problem creating admin user.'))); DB::rollback(); return false; } $admin_group = $this->create_admin_group($user); if (!$admin_group) { $this->theme->assign('form_errors', array('admin_user' => _t('Problem creating admin group.'))); DB::rollback(); return false; } // create default tokens ACL::rebuild_permissions($user); } // create a first post, if none exists if (!Posts::get(array('count' => 1))) { if (!$this->create_first_post()) { $this->theme->assign('form_errors', array('post' => _t('Problem creating first post.'))); DB::rollback(); return false; } } /* Post::save_tags() closes transaction, until we fix that, check and reconnect if needed */ if (!DB::in_transaction()) { DB::begin_transaction(); } /* Store current DB version so we don't immediately run dbdelta. */ Version::save_dbversion(); /* Ready to roll. */ DB::commit(); return true; }
/** * Admin change email. * * @access public * @return Response */ public function action_change_email() { \Util_security::check_method('POST'); \Util_security::check_csrf(); $form = $this->form_setting_email(); $val = $form->validation(); if ($val->run()) { try { $post = $val->validated(); $email = $post['email']; \DB::start_transaction(); if (!$this->auth_instance->update_user(array('email' => $email))) { throw new \FuelException('change email error.'); } \DB::commit_transaction(); $maildata = array(); $maildata['from_name'] = conf('mail.admin.from_name'); $maildata['from_address'] = conf('mail.admin.from_email'); $maildata['subject'] = term('site.email', 'form.update', 'form.complete') . 'の' . term('site.notice'); $maildata['to_address'] = $email; $maildata['to_name'] = $this->u->username; $this->send_change_email_mail($maildata); \Session::set_flash('message', term('site.email') . 'を変更しました。'); \Response::redirect('admin/setting'); } catch (\EmailValidationFailedException $e) { $this->display_error(term('member.view') . '登録: 送信エラー', __METHOD__ . ' email validation error: ' . $e->getMessage()); return; } catch (\EmailSendingFailedException $e) { $this->display_error(term('member.view') . '登録: 送信エラー', __METHOD__ . ' email sending error: ' . $e->getMessage()); return; } catch (\Auth\SimpleUserUpdateException $e) { if (\DB::in_transaction()) { \DB::rollback_transaction(); } \Session::set_flash('error', sprintf('その%sは登録できません。', term('site.email'))); } catch (\FuelException $e) { if (\DB::in_transaction()) { \DB::rollback_transaction(); } \Session::set_flash('error', term('site.email') . 'の変更に失敗しました。'); } } else { \Session::set_flash('error', $val->show_errors()); } $this->action_email(); }
/** * Album upload image * * @access public * @return Response */ public function action_upload_image($album_id = null) { \Util_security::check_method('POST'); \Util_security::check_csrf(); $album = Model_Album::check_authority($album_id, $this->u->id, 'member'); if (Site_Util::check_album_disabled_to_update($album->foreign_table, true)) { throw new \HttpForbiddenException(); } try { $val = self::get_validation_public_flag(); if (!$val->run()) { throw new \ValidationFailedException($val->show_errors()); } $post = $val->validated(); \DB::start_transaction(); list($album_image, $file) = Model_AlbumImage::save_with_relations($album_id, $this->u, $post['public_flag'], null, 'album_image'); \DB::commit_transaction(); \Session::set_flash('message', '写真を投稿しました。'); } catch (\ValidationFailedException $e) { \Session::set_flash('error', $e->getMessage()); } catch (\FuelException $e) { if (\DB::in_transaction()) { \DB::rollback_transaction(); } \Session::set_flash('error', $e->getMessage()); } \Response::redirect('album/' . $album_id); }