dirname(__FILE__), 'left_delimiter' => '', 'cache_dir' => CACHE_DIR . 'template_c/top', 'caching' => false, 'cache_lifetime' => 0, ); // キャッシュディレクトリが無い場合は作成する if (!file_exists(CACHE_DIR)) { mkdir(CACHE_DIR, 0755); } $frontendOptions = array( 'lifeTime' => CACHE_LIFE_TIME, 'automaticSerialization' => CACHE_SERIALIZE ); $backendOptions = array( 'cacheDir' => CACHE_DIR ); $cache = Zend_Cache::factory('Output', 'File', $frontendOptions, $backendOptions); $cache->clean(Zend_Cache::CLEANING_MODE_OLD); // URLを解析して表示するカレンダーを決定する $request = route(); if (empty($request['action'])) { $request['action'] = $configure['top']['default_calendar']; } if (!$cache->start($request['action'])) { // model $model = new TopModel(DSN); if (isset($configure['calendar'][$request['action']])) { $url = sprintf('%s_%4d_%s', $configure['calendar'][$request['action']]['category'], YEAR, $request['action']); // アクティブなカレンダー情報 $entry_calendar = $model->getActiveCalendar($url); if (!empty($entry_calendar)) { // カレンダーのベース名称 $entry_calendar['basename'] = trim(mb_ereg_replace('Part[0-9]{1,}$', '', $entry_calendar['name'])); // アクティブカレンダーのベースURL $entry_calendar['baseurl'] = preg_replace('/[0-9]{1,}$/', '', $entry_calendar['url']); // Part1のカレンダー詳細情報を取得する $entry_calendar['part1_detail'] = $model->getPart1Detail($entry_calendar['baseurl']); // 過去の完成カレンダー情報を追加する if (preg_match('/([0-9]{1,})$/', $entry_calendar['url'], $matches)) { $entry_calendar['past_part'] = range(1, (int)$matches[1] - 1); $entry_calendar['now'] = $matches[1]; $entry_calendar['next'] = $matches[1]+1; } } // カレンダー登録数 $total_num = $model->getEntryCalendarTotal($url); if (isset($entry_calendar['id'])) { // 残り登録枠 $rest_num = $model->getEntryCalendarRest($entry_calendar['id'], YEAR); // カレンダーにエントリーされた写真 $entry_images = array(); foreach (range(1, 12) as $_v) { $entry_images[$_v] = $model->getEntryImageMonth($entry_calendar['id'], sprintf('%04d-%02d', YEAR, $_v)); $entry_images[$_v]['url'] = $entry_calendar['url']; } } // 口コミ情報 $twitter_file = "365%E3%82%AB%E3%83%AC%E3%83%B3%E3%83%80%E3%83%BC"; // 365カレンダー /****************************** twitter の API が変わった関係で、取得するデータ形式が rss(xml) から json に変更となった。 データ項目名も別物になったので作り直し。 // if (file_exists($configure['twitter']['writing_path'] . '/' . $request['action'] . '.rss')) if (file_exists($configure['twitter']['writing_path'] . '/' . $twitter_file . '.rss')) { // $review_rss = file_get_contents($configure['twitter']['writing_path'] . '/' . $request['action'] . '.rss'); $review_rss = file_get_contents($configure['twitter']['writing_path'] . '/' . $twitter_file . '.rss'); if (!empty($review_rss)) { $review_xml = @simplexml_load_string($review_rss); if (!empty($review_xml)) { $review_list = array(); $cnt = 0; foreach ($review_xml->channel->item as $val) { $_title = htmlspecialchars(mb_convert_encoding((string)$val->title, 'eucjp-win', 'utf-8'), ENT_QUOTES); $_link = htmlspecialchars(mb_convert_encoding((string)$review_xml->channel->link, 'eucjp-win', 'utf-8'), ENT_QUOTES); preg_match('/^(.+)@twitter\.com/', mb_convert_encoding((string)$val->author, 'eucjp-win', 'utf-8'), $_author); $review_list[] = array( 'title' => mb_ereg_replace(' #([^ ]+)', sprintf(' #\\1', $configure['twitter']['search_url']), $_title), 'link' => $_link, 'author' => empty($_author[1]) ? '' : $_author[1] ); $cnt++; if ($cnt >= 5) { break; } } } } } ******************************/ // $twitter_json_file = $configure['twitter']['writing_path'] . '/' . $request['action'] . '.json'; $twitter_json_file = $configure['twitter']['writing_path'] . '/' . $twitter_file . '.json'; if (file_exists($twitter_json_file)) { $json_text = file_get_contents($twitter_json_file); $jset = json_decode($json_text, true); $review_list = array(); foreach ($jset['statuses'] as $result) { $_title = htmlspecialchars(mb_convert_encoding($result['text'], 'eucjp-win', 'utf-8'), ENT_QUOTES); $_link = htmlspecialchars(mb_convert_encoding($result['user']['url'], 'eucjp-win', 'utf-8'), ENT_QUOTES); $_author = htmlspecialchars(mb_convert_encoding($result['user']['name'], 'eucjp-win', 'utf-8'), ENT_QUOTES); $_link_author = htmlspecialchars($result['user']['screen_name'], ENT_QUOTES); $review_list[] = array( 'title' => mb_ereg_replace(' #([^ ]+)', sprintf(' #\\1', $configure['twitter']['search_url']), $_title), 'link' => $_link, 'author' => empty($_author) ? '' : $_author, 'link_author' => empty($_link_author) ? '' : $_link_author, ); } } // フォトコンテスト $photo_contest_title = $model->getPhotoContestTitle(); $photo_contest = $model->getLatestPhotoContest(empty($photo_contest_title['cc_pkey']) ? 0 : $photo_contest_title['cc_pkey']); // ファンブログ $funblog_list = $model->getFunBlogList($entry_calendar['baseurl'], 5, 0); // コミュニティ/クラブ紹介 $owners_club_list = empty($owners_club[$request['action']]) ? array() : $owners_club[$request['action']]; } // 表示 $view = new Sporty($template_param); $view->assign('category', $configure['calendar'][$request['action']]['category']); $view->assign('year', YEAR); $view->assign('action', $request['action']); $view->assign('entry_calendar', empty($entry_calendar) ? array() : $entry_calendar); $view->assign('calendar_config', isset($configure['calendar'][$request['action']]) ? $configure['calendar'][$request['action']] : array()); $view->assign('calendar_archive', isset($configure['archive'][$request['action']]) ? $configure['archive'][$request['action']] : array()); $view->assign('total_num', empty($total_num) ? 0 : $total_num); $view->assign('rest_num', empty($rest_num) ? 0 : $rest_num); $view->assign('entry_images', empty($entry_images) ? array() : $entry_images); $view->assign('review_list', empty($review_list) ? array() : $review_list, false); $view->assign('funblog_list', empty($funblog_list) ? array() : $funblog_list); $view->assign('photo_contest_title', empty($photo_contest_title) ? array() : $photo_contest_title, false); $view->assign('photo_contest', empty($photo_contest) ? array() : $photo_contest); $view->assign('owners_club_list', empty($owners_club_list) ? array() : $owners_club_list); $view->assign('start_date', isset($entry_calendar['target_date']) ? date( "YmdH", strtotime( $entry_calendar['target_date'] ) ) : ""); print $view->fetch('tmpl_index.html'); $cache->end(); } /** * URLを解析してリクエスト情報を返す * @return array */ function route() { $result = array(); $pathinfo = getPathInfo($_SERVER['REQUEST_URI'], dirname($_SERVER['SCRIPT_NAME'])); $path_segs = explode('/', trim($pathinfo, '/')); // actionName if (isset($path_segs[0]) && !empty($path_segs[0])) { $result['action'] = array_shift($path_segs); } // params if (isset($path_segs[0]) && !empty($path_segs[0])) { for ($i = 0; $i < count($path_segs); $i = $i + 2) { $key = urldecode($path_segs[$i]); $val = isset($path_segs[$i + 1]) ? urldecode($path_segs[$i + 1]) : null; $result['param'][$key] = $val; } } return $result; } /** * URLをパースして結果を返す * @param string requestUri * @param string $basename * @return string */ function getPathInfo($requestUri, $basename = '') { $pathinfo = ''; $offset = strpos($requestUri, '?'); if ($offset !== false) { $requestUri = substr($requestUri, 0, $offset); } if (empty($basename)) { $pathinfo = $requestUri; } else { $pathinfo = substr($requestUri, strlen($basename)); } return $pathinfo; }