menu->params); $template = $params->get('template'); global $database; $contents = new mosContent($database); $category = new mosCategory($database); $section = new mosSection($database); if (!isset($id)) { $orderby = TASK_kingyoya_contents_view::_orderby_sec($params->get('latest_ordering')); 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; } // 最新取得クエリ $query = <<<__SQL__ SELECT c.id FROM #__content as c WHERE c.catid = {$category_id} __SQL__; if (!$params->get('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); $id = $database->loadResult(); if (!$id) { if ($num = $database->getErrorNum()) { trigger_error("Failed query; {$num} ".$database->getErrorMsg(), E_USER_WARNING); mosNotAuth(); return; } } else if (!preg_match('/^[1-9][0-9]$/', $id)) { trigger_error("Failed get id from category: {$category_id}", E_USER_WARNING); mosNotAuth(); return; } // コンテンツ読み込み $result = $contents->load($id); if (!$result) { trigger_error("Unknown contents: {$id}", E_USER_WARNING); mosNotAuth(); return; } /* カテゴリから最新 ここまで */ } 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; } // 最新取得クエリ $query = <<<__SQL__ SELECT c.id FROM #__content as c WHERE c.sectionid = {$section_id} __SQL__; if (!$params->get('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); $id = $database->loadResult(); if (!$id) { if ($num = $database->getErrorNum()) { trigger_error("Failed query; {$num} ".$database->getErrorMsg(), E_USER_WARNING); mosNotAuth(); return; } } else if (!preg_match('/^[1-9][0-9]$/', $id)) { trigger_error("Failed get id from section: {$section_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; } /* セクションから最新 ここまで */ } 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 (!$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; // 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); } $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_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; } } if ($option === 'com_kingyoya_contents_view') { TASK_kingyoya_contents_view::show($option, $gid, isset($_REQUEST['id']) ? $_REQUEST['id'] : null, $Itemid); }