/** * 新規作成 */ public function upload() { $request = Request::getInstance(); $files_model = Model::load('Files'); $blog_id = $this->getBlogId(); Session::set('sig', App::genRandomString()); // 初期表示時 if ($request->file('file')) { // 新規登録処理 $errors = array(); $errors['file'] = $files_model->insertValidate($request->file('file'), $request->get('file'), $data_file); if (empty($errors['file'])) { $data_file['blog_id'] = $blog_id; $tmp_name = $data_file['tmp_name']; unset($data_file['tmp_name']); if ($id = $files_model->insert($data_file)) { // ファイルの移動 $data_file['id'] = $id; $move_file_path = App::getUserFilePath($data_file, true); App::mkdir($move_file_path); move_uploaded_file($tmp_name, $move_file_path); $this->setInfoMessage(__('I have completed the upload of files')); $this->redirect(array('action' => 'upload')); } } // エラー情報の設定 $this->setErrorMessage(__('Input error exists')); $this->set('errors', $errors); return; } // PCの場合はajaxでファイル情報を取得するので以下の処理は不要 if (App::isPC()) { return; } // 検索条件 $where = 'blog_id=?'; $params = array($blog_id); if ($keyword = $request->get('keyword')) { $keyword = Model::escape_wildcard($keyword); $keyword = "%{$keyword}%"; $where .= ' AND name LIKE ?'; $params = array_merge($params, array($keyword)); } // 並び順 $order = 'created_at DESC, id DESC'; switch ($request->get('order')) { default: case 'created_at_desc': break; case 'created_at_asc': $order = 'created_at 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', App::getPageLimit('FILE'), Request::VALID_POSITIVE_INT), 'page' => $request->get('page', 0, Request::VALID_UNSIGNED_INT), 'order' => $order); $files = $files_model->find('all', $options); $paging = $files_model->getPaging($options); $this->set('files', $files); $this->set('paging', $paging); }
/** * コメント投稿 */ public function comment_regist() { $blog_id = $this->getBlogId(); // ブログの設定情報取得(captchaの使用可否で画面切り替え) $blog_setting = Model::load('BlogSettings')->findByBlogId($blog_id); $is_captcha = $blog_setting['comment_captcha'] == Config::get('COMMENT.COMMENT_CAPTCHA.USE'); // FC2テンプレートにリクエスト情報を合わせる $request = Request::getInstance(); if (!$is_captcha || !$request->isArgs('token')) { Config::read('fc2_request.php'); $request->combine(Config::get('request_combine.comment_register')); // 引数のキーを入れ替える if ($request->get('comment.open_status') == 'on') { $request->set('comment.open_status', Config::get('COMMENT.OPEN_STATUS.PRIVATE')); } } $entry_id = $request->get('comment.entry_id'); // 記事詳細取得 $entry = Model::load('Entries')->getCommentAcceptedEntry($entry_id, $blog_id); if (!$entry) { $this->redirect(array('action' => 'view', 'blog_id' => $blog_id, 'id' => $entry_id)); } // CAPTCHA用に確認画面を挟む if ($is_captcha && !$request->isArgs('token')) { return; } // 記事のカテゴリ一覧を取得 TODO:後でcacheを使用する形に $entry['categories'] = Model::load('Categories')->getEntryCategories($blog_id, $entry_id); $entry['tags'] = Model::load('Tags')->getEntryTags($blog_id, $entry_id); $this->set('entry', $entry); // 入力チェック処理 $comments_model = Model::load('Comments'); $errors = array(); $white_list = array('entry_id', 'name', 'title', 'mail', 'url', 'body', 'password', 'open_status'); $errors['comment'] = $comments_model->registerValidate($request->get('comment'), $data, $white_list); $errors['token'] = $is_captcha ? $this->tokenValidate() : array(); // Token用のバリデート if (empty($errors['comment']) && empty($errors['token'])) { $data['blog_id'] = $blog_id; // ブログIDの設定 if ($id = $comments_model->insertByBlogSetting($data, $blog_setting)) { $this->redirect(array('action' => 'view', 'blog_id' => $blog_id, 'id' => $entry_id), '#comment' . $id); } } // Captcha使用時のエラー画面 if ($is_captcha) { $this->set('errors', $errors); return; } // コメント投稿エラー $this->fc2CommentError('comment', $errors['comment'], $data); // FC2用のテンプレートで表示 $this->setPageData(array(App::isPC() ? 'comment_area' : 'form_area')); return $this->fc2template($entry['blog_id']); }