menu->params); global $database; $contents = new mosContent($database); $category = new mosCategory($database); $section = new mosSection($database); $limit_category = $params->get('limit_category'); $limit_section = $params->get('limit_section'); $unpublish = $params->get('unpublish') ? true : false; if (!isset($id)) { $orderby = TASK_kingyoya_contents_view::_orderby_sec($params->get('latest_ordering')); if ($catid) { /* カテゴリ指定あり */ if (preg_match('/^[1-9][0-9]*$/', $catid)) { /* カテゴリID指定あり */ $catid = (int) $catid; $result = $category->load($catid); if (!$result) { trigger_error("Unknown category: {$category_id}", E_USER_WARNING); mosNotAuth(); return; } $result = $section->load($category->section); if (!$result) { trigger_error("Unknown section: {$category->section}", E_USER_WARNING); mosNotAuth(); return; } $result = $section->load($category->section); if (!$result) { trigger_error("Unknown section: {$category->section}", E_USER_WARNING); mosNotAuth(); return; } // 最新取得 $contents = TASK_kingyoya_contents_view::_get_latest_contents( $catid ,null ,$unpublish ,$orderby ); if (!$contents) { trigger_error("Unknown contents: {$id}", E_USER_WARNING); mosNotAuth(); return; } $id = (int) $contents->id; /* カテゴリID指定あり ここまで */ } else { /* カテゴリ名指定あり */ if (!$limit_section) { trigger_error("Failed get limit section", E_USER_WARNING); mosNotAuth(); return; } $result = $section->load($limit_section); if (!$result) { trigger_error("Unknown section: {$category->section}", E_USER_WARNING); mosNotAuth(); return; } $quoted_column_name = $database->NameQuote('name'); $quoted_catname = $database->Quote($catid); $query =<<<__SQL__ SELECT cat.* FROM #__categories as cat JOIN #__sections as sec ON cat.section = sec.id WHERE cat.{$quoted_column_name} = {$quoted_catname} LIMIT 1 __SQL__; $database->setQuery($query); $result = $database->loadObject($category); if (!$result) { if ($num = $database->getErrorNum()) { $msg = $database->getErrorMsg(); trigger_error( "Failed query: {$num}:{$msg}", E_USER_WARNING ); } mosNotAuth(); return; } if (!($category_id = $category->id)) { trigger_error("Failed get category: {$catid}", E_USER_NOTICE); mosNotAuth(); return; } // 最新取得 $contents = TASK_kingyoya_contents_view::_get_latest_contents( (int) $category_id ,null ,$unpublish ,$orderby ); if (!$contents) { trigger_error("Unknown contents: {$id}", E_USER_WARNING); mosNotAuth(); return; } $id = (int) $contents->id; /* カテゴリ名指定あり ここまで */ } /* カテゴリ指定あり ここまで */ } else { /* タイプ別取得 */ switch ($params->get('contents_type')) { case 'latest': /* 最新を表示 */ $now = $database->Quote(_CURRENT_SERVER_TIME); $nullDate = $database->Quote($database->getNullDate()); if ($category_id = $params->get('latest_category')) { /* カテゴリから最新 */ if (!preg_match('/^[1-9][0-9]*$/', $category_id)) { trigger_error("Failed get category id", E_USER_WARNING); mosNotAuth(); return; } $result = $category->load($category_id); if (!$result) { trigger_error("Unknown category: {$category_id}", E_USER_WARNING); mosNotAuth(); return; } $result = $section->load($category->section); if (!$result) { trigger_error("Unknown section: {$category->section}", E_USER_WARNING); mosNotAuth(); return; } // 最新取得 $contents = TASK_kingyoya_contents_view::_get_latest_contents( (int) $category_id ,null ,$unpublish ,$orderby ); if (!$contents) { trigger_error("Unknown contents: {$id}", E_USER_WARNING); mosNotAuth(); return; } $id = (int) $contents->id; /* カテゴリから最新 ここまで */ } else if ($section_id = $params->get('latest_section')) { /* セクションから最新 */ $result = $section->load($section_id); if (!$result) { trigger_error("Unknown section: {$category->section}", E_USER_WARNING); mosNotAuth(); return; } // 最新取得 $contents = TASK_kingyoya_contents_view::_get_latest_contents( null ,(int) $section_id ,$unpublish ,$orderby ); if (!$contents) { trigger_error("Unknown contents: {$id}", E_USER_WARNING); mosNotAuth(); return; } $id = (int) $contents->id; /* セクションから最新 ここまで */ } else { trigger_error("Latest category or section not set", E_USER_WARNING); mosNotAuth(); return; } break; /* 最新を表示 ここまで */ case 'select': /* 指定を表示 */ $id = $params->get('contents_select'); if (!$id) { trigger_error('Failed get id', E_USER_WARNING); mosNotAuth(); return; } if (!preg_match('/^[1-9][0-9]*$/', $id)) { trigger_error("Failed get id: {$id}", E_USER_WARNING); mosNotAuth(); return; } $result = $contents->load($id); if (!$result) { trigger_error("Unknown contents: {$id}", E_USER_WARNING); mosNotAuth(); return; } $result = $category->load($contents->catid); if (!$result) { trigger_error("Unknown category: {$contents->catid}", E_USER_WARNING); mosNotAuth(); return; } $result = $section->load($category->section); if (!$result) { trigger_error("Unknown section: {$category->section}", E_USER_WARNING); mosNotAuth(); return; } break; /* 指定を表示 ここまで */ default: trigger_error("Unknown type", E_USER_WARNING); mosNotAuth(); return; } } /* タイプ別取得 ここまえ */ /* 最新表示 ここまで */ } else if (!isset($id) && isset($catid)) { /* カテゴリ指定で表示 */ } else { /* 指定を表示 */ if (!$id) { trigger_error('Failed get id', E_USER_WARNING); mosNotAuth(); return; } if (!preg_match('/^[1-9][0-9]*$/', $id)) { trigger_error("Failed get id: {$id}", E_USER_WARNING); mosNotAuth(); return; } $result = $contents->load($id); if (!$result) { trigger_error("Unknown contents: {$id}", E_USER_WARNING); mosNotAuth(); return; } $result = $category->load($contents->catid); if (!$result) { trigger_error("Unknown category: {$contents->catid}", E_USER_WARNING); mosNotAuth(); return; } $result = $section->load($category->section); if (!$result) { trigger_error("Unknown section: {$category->section}", E_USER_WARNING); mosNotAuth(); return; } } if (!$id) { trigger_error('Failed get id', E_USER_WARNING); mosNotAuth(); return; } if (!preg_match('/^[1-9][0-9]*$/', $id)) { trigger_error("Failed get id: {$id}", E_USER_WARNING); mosNotAuth(); return; } $id = (int) $id; if ($limit_category) { if ($contents->catid !== $limit_category) { trigger_error("User can not access contents: {$id}", E_USER_WARNING); mosNotAuth(); return; } } else if ($limit_section) { if ($contents->sectionid !== $limit_section) { trigger_error("User can not access contents: {$id}", E_USER_WARNING); mosNotAuth(); return; } } // check access $access = (int) $contents->access; if ($access > $gid) { trigger_error("User can not access contents: {$id}", E_USER_WARNING); mosNotAuth(); return; } $access = (int) $category->access; if ($access > $gid) { trigger_error("User can not access category: {$id}", E_USER_WARNING); mosNotAuth(); return; } $access = (int) $section->access; if ($access > $gid) { trigger_error("User can not access category: {$id}", E_USER_WARNING); mosNotAuth(); return; } // check publishded $unpublish = $params->get('unpublish'); if (!$unpublish && !$contents->state) { if (!$contents->state) { trigger_error("Contents unpublished: {$id}", E_USER_NOTICE); mosNotAuth(); return; } else if (!$category->unpublished) { trigger_error("Category unpublished: {$id}", E_USER_NOTICE); mosNotAuth(); return; } else if (!$section->unpublished) { trigger_error("Section unpublished: {$id}", E_USER_NOTICE); mosNotAuth(); return; } } // set page title if ($page_title = $params->get('custom_page_title')) { $mainframe->setPageTitle($page_title); } else if ($params->get('contents_page_title')) { $mainframe->setPageTitle($category->title); } else if ($params->get('menu_page_title')) { $mainframe->setPageTitle($mainframe->menu->name); } // set constant if ($constant_name = $params->get('view_id_constant_name')) { define($constant_name, $id); } // 304 check if ($params->get('use304')) { $lastmodified = $contents->modified ? $contents->modified : $contents->created; $lastmodified = strtotime($lastmodified); $lastmodified = gmdate('r', $lastmodified); header("Last-Modified: {$lastmodified}"); if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $modified_since = $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) { if ($lastmodified == $modified_since) { header('Connection: close', true, 304); while(ob_end_clean()); flush(); return; } } } $created_by = new mosUser($database); $created_by->load($contents->created_by); $modified_by = new mosUser($database); if ($contents->modified_by) { $modified_by->load($contents->modified_by); } $template = $params->get('template'); $template_resource = $params->get('template_resource'); if ($template_resource === 'file') { global $mosConfig_absolute_path; $template = "{$mosConfig_absolute_path}/{$template}"; if (!is_file($template)) { trigger_error("Failed get template: {$template}", E_USER_NOTICE); mosNotAuth(); return; } $template = file_get_contents($template); } else { $template_content = new mosContent($database); $result = $template_content->load($template); if (!$result) { trigger_error("Failed get template content: {$template}", E_USER_NOTICE); mosNotAuth(); return; } $template_content->text = $template_content->introtext; $template_content_params = new mosParameters("introtext=1\nintro_only=0"); $template_content_params->set('image', true); global $_MAMBOTS; $_MAMBOTS->loadBotGroup( 'content' ); $results = botMosImage( true, $template_content, $template_content_params ); $template = $template_content->text; } // view HTML require_once $mainframe->getPath('front_html', $option); $html = new HTML_kingyoya_contents_view(); $html->option = $option; $html->id = $id; $Itemid and $html->Itemid = $Itemid; $html->contents = $contents; $html->category = $category; $html->section = $section; $html->created_by = $created_by; $html->modified_by = $modified_by; $html->template = $template; $html->params = $params; $html->show(); } /** * order by from com_content */ function _orderby_sec( $orderby ) { switch ( $orderby ) { case 'created': $orderby = 'c.created DESC'; break; case 'order': $orderby = 'c.ordering'; break; default: $orderby = 'c.ordering'; break; } return $orderby; } /** * 最新コンテンツ取得 */ function _get_latest_contents( $catid = null , $section = null , $unpublish , $orderby ) { global $database; global $gid; $now = $database->Quote(_CURRENT_SERVER_TIME); $nullDate = $database->Quote($database->getNullDate()); // 最新取得クエリ $query = <<<__SQL__ SELECT c.* FROM #__content as c __SQL__; if ($catid) { /* カテゴリで取得 */ if (!is_int($catid) || !($catid > 0) ) { trigger_error("Failed get catid", E_USER_WARNING); return null; } $query .= <<<__SQL__ WHERE c.catid = {$catid} __SQL__; /* カテゴリで取得 ココまで */ } else if ($section) { /* セクションで取得 */ if (!is_int($section) || !($section > 0) ) { trigger_error("Failed get section", E_USER_WARNING); return null; } $query .= <<<__SQL__ WHERE c.sectionid = {$section} __SQL__; /* セクションで取得 ここまで */ } else { trigger_error("Failed get catid and section", E_USER_WARNING); return null; } if (!$unpublish) { $query .= " AND (state > 0 OR state is null)\n"; } else { $query .= " AND (state >= 0 OR state is null)\n"; } $query .= <<<__SQL__ AND (c.publish_up = {$nullDate} OR c.publish_up <= {$now}) AND (c.publish_down = {$nullDate} OR c.publish_down >= {$now}) AND c.access <= {$gid} ORDER BY {$orderby}, c.id desc LIMIT 1 __SQL__; $database->setQuery($query); // コンテンツ読み込み $contents = new mosContent($database); $result = $database->loadObject($contents); if (!$result) { if ($num = $database->getErrorNum()) { trigger_error("Failed query; {$num} ".$database->getErrorMsg(), E_USER_WARNING); } return null; } return $contents; } /* 最新コンテンツ取得 ここまで */ } if ($option === 'com_kingyoya_contents_view') { TASK_kingyoya_contents_view::show( $option , $gid , isset($_REQUEST['id']) ? $_REQUEST['id'] : null , $Itemid , (isset($_REQUEST['catid']) ? $_REQUEST['catid'] : null) ); }