/** * ブログの設定変更処理 */ private function settingEdit($white_list, $action) { $request = Request::getInstance(); $blog_settings_model = Model::load('BlogSettings'); $blog_id = $this->getBlogId(); // 初期表示時に編集データの取得&設定 if (!$request->get('blog_setting') || !Session::get('sig') || Session::get('sig') !== $request->get('sig')) { Session::set('sig', App::genRandomString()); $blog_setting = $blog_settings_model->findByBlogId($blog_id); $request->set('blog_setting', $blog_setting); return; } // 更新処理 $errors = array(); $errors['blog_setting'] = $blog_settings_model->validate($request->get('blog_setting'), $blog_setting_data, $white_list); if (empty($errors['blog_setting'])) { // コメント確認からコメントを確認せずそのまま表示に変更した場合既存の承認待ちを全て承認済みに変更する $blog_setting = $blog_settings_model->findByBlogId($blog_id); if ($blog_setting['comment_confirm'] == Config::get('COMMENT.COMMENT_CONFIRM.CONFIRM') && $blog_setting_data['comment_confirm'] == Config::get('COMMENT.COMMENT_CONFIRM.THROUGH')) { Model::load('Comments')->updateApproval($blog_id); } // ブログの設定情報更新処理 if ($blog_settings_model->updateByBlogId($blog_setting_data, $blog_id)) { // 一覧ページへ遷移 $this->setInfoMessage(__("I have updated the configuration information of the blog")); $this->redirect(array('action' => $action)); } } // エラー情報の設定 $this->setErrorMessage(__('Input error exists')); $this->set('errors', $errors); }
/** * 一覧表示 */ public function index() { $request = Request::getInstance(); $tags_model = Model::load('Tags'); $blog_id = $this->getBlogId(); Session::set('sig', App::genRandomString()); // 検索条件作成 $where = 'blog_id=?'; $params = array($blog_id); if ($name = $request->get('name')) { $name = Model::escape_wildcard($name); $name = "%{$name}%"; $where .= ' AND name LIKE ?'; $params = array_merge($params, array($name)); } // 並び順 $order = 'count DESC, id DESC'; switch ($request->get('order')) { default: case 'count_desc': break; case 'count_asc': $order = 'count ASC, id ASC'; break; case 'name_desc': $order = 'name DESC, id DESC'; break; case 'name_asc': $order = 'name ASC, id ASC'; break; } $options = array('where' => $where, 'params' => $params, 'limit' => $request->get('limit', Config::get('TAG.DEFAULT_LIMIT'), Request::VALID_POSITIVE_INT), 'page' => $request->get('page', 0, Request::VALID_UNSIGNED_INT), 'order' => $order); if ($options['limit'] > max(array_keys(Config::get('TAG.LIMIT_LIST')))) { $options['limit'] = Config::get('TAG.DEFAULT_LIMIT'); } if (ceil(PHP_INT_MAX / $options['limit']) <= $options['page']) { $options['page'] = 0; } $tags = $tags_model->find('all', $options); $paging = $tags_model->getPaging($options); $this->set('tags', $tags); $this->set('paging', $paging); }
/** * 新規作成 */ public function create() { $request = Request::getInstance(); $categories_model = Model::load('Categories'); $blog_id = $this->getBlogId(); // 親カテゴリー一覧 $options = $categories_model->getParentList($blog_id); $this->set('category_parents', array(0 => '') + $options); // カテゴリ登録数 $create_limit = Config::get('CATEGORY.CREATE_LIMIT'); $is_limit_create_category = $create_limit > 0 ? $create_limit <= count($options) : false; $this->set('is_limit_create_category', $is_limit_create_category); if ($is_limit_create_category) { $this->setErrorMessage(__('Exceeded the maximum number of registered category')); $request->set('category', null); return; } // 初期表示時 if (!$request->get('category') || !Session::get('sig') || Session::get('sig') !== $request->get('sig')) { Session::set('sig', App::genRandomString()); return; } // 新規登録処理 $category_request = $request->get('category'); $category_request['blog_id'] = $blog_id; $errors = $categories_model->validate($category_request, $data, array('parent_id', 'name', 'category_order')); if (empty($errors)) { $data['blog_id'] = $blog_id; if ($id = $categories_model->addNode($data, 'blog_id=?', array($blog_id))) { $this->setInfoMessage(__('I added a category')); $this->redirect(array('action' => 'create')); } } // エラー情報の設定 $this->setErrorMessage(__('Input error exists')); $this->set('errors', $errors); }
/** * 新規作成 */ public function create() { // IE11のエディター対応 if (stristr($_SERVER['HTTP_USER_AGENT'], 'trident')) { header('X-UA-Compatible: IE=EmulateIE10'); } $request = Request::getInstance(); $entries_model = Model::load('Entries'); $entry_categories_model = Model::load('EntryCategories'); $blog_id = $this->getBlogId(); // 初期表示時 if (!$request->get('entry') || !Session::get('sig') || Session::get('sig') !== $request->get('sig')) { Session::set('sig', App::genRandomString()); return; } // 新規登録処理 $errors = array(); $whitelist_entry = array('title', 'body', 'extend', 'open_status', 'password', 'auto_linefeed', 'comment_accepted', 'posted_at'); $errors['entry'] = $entries_model->validate($request->get('entry'), $entry_data, $whitelist_entry); $errors['entry_categories'] = $entry_categories_model->validate($request->get('entry_categories'), $entry_categories_data, array('category_id')); if (empty($errors['entry']) && empty($errors['entry_categories'])) { $entry_data['blog_id'] = $blog_id; if ($id = $entries_model->insert($entry_data)) { // カテゴリと紐付 $entry_categories_model->save($blog_id, $id, $entry_categories_data); // タグと紐付 Model::load('EntryTags')->save($blog_id, $id, $request->get('entry_tags')); // 一覧ページへ遷移 $this->setInfoMessage(__('I created a entry')); $this->redirect(array('action' => 'index')); } } // エラー情報の設定 $this->setErrorMessage(__('Input error exists')); $this->set('errors', $errors); }
/** * 編集 */ public function edit() { $request = Request::getInstance(); $files_model = Model::load('Files'); $id = $request->get('id'); $blog_id = $this->getBlogId(); // 詳細データの取得 if (!($file = $files_model->findByIdAndBlogId($id, $blog_id))) { $this->redirect(array('action' => 'index')); } $this->set('file', $file); if (!$request->get('file')) { $request->set('file', $file); $back_url = $request->getReferer(); if (!empty($back_url)) { $request->set('back_url', $back_url); // 戻る用のURL } Session::set('sig', App::genRandomString()); return; } if (!Session::get('sig') || Session::get('sig') !== $request->get('sig')) { $request->clear(); $this->redirect(array('action' => 'upload')); } // 新規登録処理 $errors = array(); $errors['file'] = $files_model->updateValidate($request->file('file'), $request->get('file'), $file, $data_file); if (empty($errors['file'])) { $tmp_name = isset($data_file['tmp_name']) ? $data_file['tmp_name'] : null; unset($data_file['tmp_name']); if ($files_model->updateByIdAndBlogId($data_file, $id, $blog_id)) { // ファイルの移動 if (!empty($tmp_name)) { $data_file['id'] = $id; $data_file['blog_id'] = $blog_id; $move_file_path = App::getUserFilePath($data_file, true); App::deleteFile($blog_id, $id); move_uploaded_file($tmp_name, $move_file_path); } $this->setInfoMessage(__('I have updated the file')); $back_url = $request->get('back_url'); if (!empty($back_url)) { $this->redirect($back_url); } $this->redirect(array('action' => 'upload')); } } // エラー情報の設定 $this->setErrorMessage(__('Input error exists')); $this->set('errors', $errors); $back_url = $request->get('back_url'); if (!empty($back_url)) { $request->set('back_url', $back_url); // 戻る用のURL } }
/** * 削除 */ public function delete() { $request = Request::getInstance(); // 退会チェック if (!$request->get('blog.delete') || !Session::get('sig') || Session::get('sig') !== $request->get('sig')) { Session::set('sig', App::genRandomString()); return; } $blog_id = $this->getBlogId(); $user_id = $this->getUserId(); // 削除データの取得 $blogs_model = Model::load('Blogs'); if (!($blog = $blogs_model->findByIdAndUserId($blog_id, $user_id))) { $this->redirect(array('action' => 'index')); } // 削除処理 $blogs_model->deleteByIdAndUserId($blog_id, $user_id); $this->setBlog(null); // ログイン中のブログを削除したのでブログの選択中状態を外す $this->setInfoMessage(__('I removed the blog')); $this->redirect(array('action' => 'index')); }
/** * 編集 */ public function edit() { $request = Request::getInstance(); $blog_templates_model = Model::load('BlogTemplates'); $id = $request->get('id'); $blog_id = $this->getBlogId(); // 使用中のテンプレート判定 $blog = $this->getBlog($blog_id); // 初期表示時に編集データの取得&設定 if (!$request->get('blog_template') || !Session::get('sig') || Session::get('sig') !== $request->get('sig')) { if (!($blog_template = $blog_templates_model->findByIdAndBlogId($id, $blog_id))) { $this->redirect(array('action' => 'index')); } $request->set('blog_template', $blog_template); Session::set('sig', App::genRandomString()); return; } // 更新処理 $errors = array(); $white_list = array('title', 'html', 'css'); $errors['blog_template'] = $blog_templates_model->validate($request->get('blog_template'), $blog_template_data, $white_list); if (empty($errors['blog_template'])) { if ($blog_templates_model->updateByIdAndBlogId($blog_template_data, $id, $blog_id)) { $this->setInfoMessage(__('I have updated the template')); $this->redirect(array('action' => 'index')); } } // エラー情報の設定 $this->setErrorMessage(__('Input error exists')); $this->set('errors', $errors); }
/** * 登録 */ public function register() { $request = Request::getInstance(); $plugins_model = Model::load('Plugins'); $id = $request->get('id'); $blog_id = $this->getBlogId(); // 登録データの取得 $blog_plugin = Model::load('BlogPlugins')->findByIdAndBlogId($id, $blog_id); if (!$blog_plugin) { $this->redirect(array('action' => 'index')); } $this->set('blog_plugin', $blog_plugin); if (!$request->get('plugin') || !Session::get('sig') || Session::get('sig') !== $request->get('sig')) { // 初期値入力 if ($blog_plugin['plugin_id']) { // 既に登録済み $plugin = $plugins_model->findByIdAndUserId($blog_plugin['plugin_id'], $this->getUserId()); $request->set('plugin.title', $plugin['title']); $request->set('plugin.body', $plugin['body']); } else { // 未登録 $request->set('plugin.title', $blog_plugin['title']); } Session::set('sig', App::genRandomString()); return; } // 新規登録処理 $errors = array(); $white_list = array('title', 'body'); $errors['plugin'] = $plugins_model->validate($request->get('plugin'), $plugin_data, $white_list); if (empty($errors['plugin'])) { // 登録処理 if (Model::load('Plugins')->register($blog_plugin, $plugin_data, $this->getUserId())) { $this->setInfoMessage(__('I have registered the plug-in')); } else { $this->setErrorMessage(__('I failed to register the plug-in')); } $this->redirect(array('action' => 'index')); } // エラー情報の設定 $this->setErrorMessage(__('Input error exists')); $this->set('errors', $errors); }