/** * [ADMIN] 管理者ログイン画面 * * @return void */ public function admin_login() { if ($this->BcAuth->loginAction != '/' . $this->request->url) { $this->notFound(); } if ($this->request->data) { $this->BcAuth->login(); $user = $this->BcAuth->user(); $userModel = $this->BcAuth->authenticate['Form']['userModel']; if ($user && $this->isAuthorized($user)) { if (!empty($this->request->data[$userModel]['saved'])) { if (Configure::read('BcRequest.agentAlias') != 'mobile') { $this->setAuthCookie($this->request->data); } else { $this->BcAuth->saveSerial(); } unset($this->request->data[$userModel]['save']); } else { $this->Cookie->destroy(); } App::uses('BcBaserHelper', 'View/Helper'); $BcBaser = new BcBaserHelper(new View()); $this->setMessage("ようこそ、" . $BcBaser->getUserName($user) . " さん。"); $this->redirect($this->BcAuth->redirect()); } else { $this->setMessage('アカウント名、パスワードが間違っています。', true); } } $pageTitle = 'ログイン'; $prefixAuth = Configure::read('BcAuthPrefix.' . $this->request->params['prefix']); if ($prefixAuth && isset($prefixAuth['loginTitle'])) { $pageTitle = $prefixAuth['loginTitle']; } /* 表示設定 */ $this->crumbs = array(); $this->subMenuElements = ''; $this->pageTitle = $pageTitle; }
/** * [PUBLIC] ブログアーカイブを表示する * * @param mixed blog_post_id / type * @param mixed blog_post_id / "" * @return void */ public function archives() { // パラメーター処理 $pass = $this->request->params['pass']; $type = $year = $month = $day = $id = ''; $crumbs = $posts = array(); $single = false; $posts = array(); if ($pass[0] == 'category') { $type = 'category'; } elseif ($pass[0] == 'author') { $type = 'author'; } elseif ($pass[0] == 'tag') { $type = 'tag'; } elseif ($pass[0] == 'date') { $type = 'date'; } $crumbs[] = array('name' => $this->request->params['Content']['title'], 'url' => $this->request->params['Content']['url']); switch ($type) { /* カテゴリ一覧 */ case 'category': $category = $pass[count($pass) - 1]; if (empty($category)) { //$this->notFound(); } // ナビゲーションを設定 $categoryId = $this->BlogCategory->field('id', array('BlogCategory.blog_content_id' => $this->contentId, 'BlogCategory.name' => urlencode($category))); if (!$categoryId) { $this->notFound(); } // 記事を取得 $posts = $this->_getBlogPosts(array('conditions' => array('category' => urlencode($category)))); $blogCategories = $this->BlogCategory->getPath($categoryId, array('name', 'title')); if (count($blogCategories) > 1) { foreach ($blogCategories as $key => $blogCategory) { if ($key < count($blogCategories) - 1) { $crumbs[] = array('name' => $blogCategory['BlogCategory']['title'], 'url' => $this->request->params['Content']['url'] . '/archives/category/' . $blogCategory['BlogCategory']['name']); } } } $this->pageTitle = $blogCategories[count($blogCategories) - 1]['BlogCategory']['title']; $template = $this->blogContent['BlogContent']['template'] . DS . 'archives'; $this->set('blogArchiveType', $type); break; case 'author': $author = h($pass[count($pass) - 1]); $posts = $this->_getBlogPosts(array('conditions' => array('author' => $author))); $data = $this->BlogPost->User->find('first', array('fields' => array('real_name_1', 'real_name_2', 'nickname'), 'conditions' => array('User.name' => $author))); App::uses('BcBaserHelper', 'View/Helper'); $BcBaser = new BcBaserHelper(new View()); $userName = $BcBaser->getUserName($data); $this->pageTitle = urldecode($userName); $template = $this->blogContent['BlogContent']['template'] . DS . 'archives'; $this->set('blogArchiveType', $type); break; /* タグ別記事一覧 */ /* タグ別記事一覧 */ case 'tag': $tag = h($pass[count($pass) - 1]); if (empty($this->blogContent['BlogContent']['tag_use']) || empty($tag)) { $this->notFound(); } $posts = $this->_getBlogPosts(array('conditions' => array('tag' => $tag))); $this->pageTitle = urldecode($tag); $template = $this->blogContent['BlogContent']['template'] . DS . 'archives'; $this->set('blogArchiveType', $type); break; /* 月別アーカイブ一覧 */ /* 月別アーカイブ一覧 */ case 'date': $year = h($pass[1]); $month = h(@$pass[2]); $day = h(@$pass[3]); if (!$year && !$month && !$day) { $this->notFound(); } $posts = $this->_getBlogPosts(array('conditions' => array('year' => $year, 'month' => $month, 'day' => $day))); $this->pageTitle = $year . '年'; if ($month) { $this->pageTitle .= $month . '月'; } if ($day) { $this->pageTitle .= $day . '日'; } $template = $this->blogContent['BlogContent']['template'] . DS . 'archives'; if ($day) { $this->set('blogArchiveType', 'daily'); } elseif ($month) { $this->set('blogArchiveType', 'monthly'); } else { $this->set('blogArchiveType', 'yearly'); } break; /* 単ページ */ /* 単ページ */ default: // プレビュー if ($this->BcContents->preview && !empty($this->request->data['BlogPost'])) { $post = $this->BlogPost->createPreviewData($this->request->data); } else { if (!empty($pass[0])) { $id = $pass[0]; } else { $this->notFound(); } // コメント送信 if (isset($this->request->data['BlogComment'])) { $this->add_comment($id); } $post = $this->_getBlogPosts(array('preview' => (bool) $this->BcContents->preview, 'conditions' => array('id' => $id))); if (!empty($post[0])) { $post = $post[0]; } else { $this->notFound(); } // 一覧系のページの場合、時限公開の記事が存在し、キャッシュがあると反映できないが、 // 詳細ページの場合は、記事の終了期間の段階でキャッシュが切れる前提となる為、キャッシュを利用する // プレビューでは利用しない事。 // コメント送信時、キャッシュはクリアされるが、モバイルの場合、このメソッドに対してデータを送信する為、 // キャッシュがあるとデータが処理されないので、キャッシュは全く作らない設定とする if (BcSite::findCurrent()->device != 'mobile') { $this->BcContents->useViewCache = true; } } if (BcUtil::isAdminUser()) { $this->set('editLink', array('admin' => true, 'plugin' => 'blog', 'controller' => 'blog_posts', 'action' => 'edit', $post['BlogPost']['blog_content_id'], $post['BlogPost']['id'])); } // ナビゲーションを設定 if (!empty($post['BlogPost']['blog_category_id'])) { $blogCategories = $this->BlogCategory->getPath($post['BlogPost']['blog_category_id'], array('name', 'title')); if ($blogCategories) { foreach ($blogCategories as $blogCategory) { $crumbs[] = array('name' => $blogCategory['BlogCategory']['title'], 'url' => $this->request->params['Content']['url'] . '/archives/category/' . $blogCategory['BlogCategory']['name']); } } } $this->pageTitle = $post['BlogPost']['name']; $single = true; $template = $this->blogContent['BlogContent']['template'] . DS . 'single'; if ($this->BcContents->preview) { $this->blogContent['BlogContent']['comment_use'] = false; } $this->set('post', $post); } // 表示設定 $this->crumbs = array_merge($this->crumbs, $crumbs); $this->set('single', $single); $this->set('posts', $posts); $this->set('year', $year); $this->set('month', $month); $this->render($template); }
/** * [PUBLIC] ブログアーカイブを表示する * * @param mixed blog_post_id / type * @param mixed blog_post_id / "" * @return void * @access public */ public function archives() { if (!$this->blogContent['BlogContent']['status']) { $this->notFound(); } // パラメーター処理 $pass = $this->params['pass']; $type = $year = $month = $day = $id = ''; $crumbs = $posts = array(); $single = false; $posts = array(); if ($pass[0] == 'category') { $type = 'category'; } elseif ($pass[0] == 'author') { $type = 'author'; } elseif ($pass[0] == 'tag') { $type = 'tag'; } elseif ($pass[0] == 'date') { $type = 'date'; } switch ($type) { /* カテゴリ一覧 */ case 'category': $category = $pass[count($pass) - 1]; if (empty($category)) { $this->notFound(); } // ナビゲーションを設定 $categoryId = $this->BlogCategory->field('id', array('BlogCategory.blog_content_id' => $this->contentId, 'BlogCategory.name' => urlencode($category))); if (!$categoryId) { $this->notFound(); } // 記事を取得 $posts = $this->_getBlogPosts(array('conditions' => array('category' => urlencode($category)))); $blogCategories = $this->BlogCategory->getPath($categoryId, array('name', 'title')); if (count($blogCategories) > 1) { foreach ($blogCategories as $key => $blogCategory) { if ($key < count($blogCategories) - 1) { $crumbs[] = array('name' => $blogCategory['BlogCategory']['title'], 'url' => '/' . $this->blogContent['BlogContent']['name'] . '/archives/category/' . $blogCategory['BlogCategory']['name']); } } } $this->pageTitle = $blogCategories[count($blogCategories) - 1]['BlogCategory']['title']; $template = $this->blogContent['BlogContent']['template'] . DS . 'archives'; $this->set('blogArchiveType', $type); break; case 'author': $author = h($pass[count($pass) - 1]); $posts = $this->_getBlogPosts(array('conditions' => array('author' => $author))); $data = $this->BlogPost->User->find('first', array('fields' => array('real_name_1', 'real_name_2', 'nickname'), 'conditions' => array('User.name' => $author))); App::uses('BcBaserHelper', 'View/Helper'); $BcBaser = new BcBaserHelper(new View()); $userName = $BcBaser->getUserName($data); $this->pageTitle = urldecode($userName); $template = $this->blogContent['BlogContent']['template'] . DS . 'archives'; $this->set('blogArchiveType', $type); break; /* タグ別記事一覧 */ /* タグ別記事一覧 */ case 'tag': $tag = h($pass[count($pass) - 1]); if (empty($this->blogContent['BlogContent']['tag_use']) || empty($tag)) { $this->notFound(); } $posts = $this->_getBlogPosts(array('conditions' => array('tag' => $tag))); $this->pageTitle = urldecode($tag); $template = $this->blogContent['BlogContent']['template'] . DS . 'archives'; $this->set('blogArchiveType', $type); break; /* 月別アーカイブ一覧 */ /* 月別アーカイブ一覧 */ case 'date': $year = h($pass[1]); $month = h(@$pass[2]); $day = h(@$pass[3]); if (!$year && !$month && !$day) { $this->notFound(); } $posts = $this->_getBlogPosts(array('conditions' => array('year' => $year, 'month' => $month, 'day' => $day))); $this->pageTitle = $year . '年'; if ($month) { $this->pageTitle .= $month . '月'; } if ($day) { $this->pageTitle .= $day . '日'; } $template = $this->blogContent['BlogContent']['template'] . DS . 'archives'; if ($day) { $this->set('blogArchiveType', 'daily'); } elseif ($month) { $this->set('blogArchiveType', 'monthly'); } else { $this->set('blogArchiveType', 'yearly'); } break; /* 単ページ */ /* 単ページ */ default: // プレビュー if ($this->preview) { $this->contentId = $pass[0]; if (!empty($pass[1])) { $id = $pass[1]; } elseif (empty($this->request->data['BlogPost'])) { $this->notFound(); } $post['BlogPost'] = $this->request->data['BlogPost']; if ($this->request->data['BlogPost']['blog_category_id']) { $blogCategory = $this->BlogPost->BlogCategory->find('first', array('conditions' => array('BlogCategory.id' => $this->request->data['BlogPost']['blog_category_id']), 'recursive' => -1)); $post['BlogCategory'] = $blogCategory['BlogCategory']; } if ($this->request->data['BlogPost']['user_id']) { $author = $this->BlogPost->User->find('first', array('conditions' => array('User.id' => $this->request->data['BlogPost']['user_id']), 'recursive' => -1)); $post['User'] = $author['User']; } if (!empty($this->request->data['BlogTag']['BlogTag'])) { $tags = $this->BlogPost->BlogTag->find('all', array('conditions' => array('BlogTag.id' => $this->request->data['BlogTag']['BlogTag']), 'recursive' => -1)); if ($tags) { $tags = Hash::extract($tags, '{n}.BlogTag'); $post['BlogTag'] = $tags; } } } else { if (!empty($pass[0])) { $id = $pass[0]; } else { $this->notFound(); } // コメント送信 if (isset($this->request->data['BlogComment'])) { $this->add_comment($id); } $_posts = $this->_getBlogPosts(array('conditions' => array('id' => $id))); if (!empty($_posts[0])) { $post = $_posts[0]; } else { $this->notFound(); } $user = $this->BcAuth->user(); if (empty($this->params['admin']) && !empty($user) && !Configure::read('BcRequest.agent')) { $this->set('editLink', array('admin' => true, 'plugin' => 'blog', 'controller' => 'blog_posts', 'action' => 'edit', $post['BlogPost']['blog_content_id'], $post['BlogPost']['id'])); } } // ナビゲーションを設定 if (!empty($post['BlogPost']['blog_category_id'])) { $blogCategories = $this->BlogCategory->getPath($post['BlogPost']['blog_category_id'], array('name', 'title')); if ($blogCategories) { foreach ($blogCategories as $blogCategory) { $crumbs[] = array('name' => $blogCategory['BlogCategory']['title'], 'url' => '/' . $this->blogContent['BlogContent']['name'] . '/archives/category/' . $blogCategory['BlogCategory']['name']); } } } $this->pageTitle = $post['BlogPost']['name']; $single = true; $template = $this->blogContent['BlogContent']['template'] . DS . 'single'; if ($this->preview) { $this->blogContent['BlogContent']['comment_use'] = false; } $this->set('post', $post); } // 表示設定 $this->crumbs = array_merge($this->crumbs, $crumbs); $this->set('single', $single); $this->set('posts', $posts); $this->set('year', $year); $this->set('month', $month); $this->layout = $this->blogContent['BlogContent']['layout']; $this->render($template); }
/** * ユーザーリストを取得する * 条件を指定する場合は引数を指定する * * @param array $conditions * @return array */ public function getUserList($conditions = array()) { $users = $this->find("all", array('fields' => array('id', 'real_name_1', 'real_name_2', 'nickname'), 'conditions' => $conditions)); $list = array(); if ($users) { App::uses('BcBaserHelper', 'View/Helper'); $BcBaser = new BcBaserHelper(new View()); foreach ($users as $key => $user) { $list[$user[$this->alias]['id']] = $BcBaser->getUserName($user); } } return $list; }