get('category')) {
if (!preg_match('/^[1-9][0-9]*$/', $category)) {
trigger_error("Failed get category: {$category}", E_USER_WARNING);
return;
}
$module->category = $category;
} else if ($section = $params->get('section')) {
if (!preg_match('/^[1-9][0-9]*$/', $section)) {
trigger_error("Failed get section: {$section}", E_USER_WARNING);
return;
}
$module->section = $section;
} else {
trigger_error("Failed get section/category", E_USER_WARNING);
return;
}
$module->mosimage = $params->get('mosimage') ? true : false;
$module->orderby = $params->get('orderby_sec');
$module->limit = $params->get('limit', 10);
if (!preg_match('/^[1-9][0-9]*$/', $module->limit)) {
trigger_error("Failed get limit: {$module->limit}", E_USER_WARNING);
return;
}
$module->template_list = $params->get('template_list');
if (!$module->template_list) {
trigger_error("Failed get template list", E_USER_WARNING);
return;
}
$module->template_list = str_replace('
', "", $module->template_list);
$module->template_item = $params->get('template_item');
if (!$module->template_item) {
trigger_error("Failed get template item", E_USER_WARNING);
return;
}
$module->template_item = str_replace('
', "", $module->template_item);
$module->show();
}
/** @var int of section id */
var $section = 0;
/** @var int of category id */
var $category = 0;
/** @var string of orderby section */
var $orderby = '';
/** @var string of template for list */
var $template_list = '';
/** @var string of template for item */
var $template_item = '';
/** @var int of item limit */
var $limit = 0;
/** @var boolean of mosimage flag */
var $mosimage = true;
/**
* 表示処理
*/
function show() {
global $mainframe;
global $mosConfig_absolute_path;
global $database;
global $my;
global $_MAMBOTS;
require_once "{$mosConfig_absolute_path}/includes/patTemplate/patTemplate.php";
/* @var patTemplate */
$template =& patFactory::createTemplate();
$template->addGlobalVar('br', '
');
/* @var Section/category WHERE 条件 */
$where = '';
if ($this->category) {
/* カテゴリ指定 */
$category = $this->getCategory($this->category);
if (!$category) {
trigger_error("Failed get category: {$this->category}", E_USER_WARNING);
return;
}
$where = "con.catid = ".$database->Quote($this->category);
$template->addGlobalVar('category_id', $category->id);
$template->addGlobalVar('category_name', $category->name);
$template->addGlobalVar('category_title', $category->title);
$template->addGlobalVar('category_image', $category->image);
$template->addGlobalVar('category_description', $category->description);
$section = $this->getSection($category->section);
$template->addGlobalVar('section_id', $section->id);
$template->addGlobalVar('section_name', $section->name);
$template->addGlobalVar('section_title', $section->title);
$template->addGlobalVar('section_image', $section->image);
$template->addGlobalVar('section_description', $section->description);
/* カテゴリ指定 ここまで */
} else if ($this->section) {
/* セクション指定 */
$section = $this->getSection($this->section);
if (!$section) {
trigger_error("Failed get section: {$this->section}", E_USER_WARNING);
return;
}
$where = "con.sectionid = ".$database->Quote($this->section);
$template->addGlobalVar('section_id', $section->id);
$template->addGlobalVar('section_name', $section->name);
$template->addGlobalVar('section_title', $section->title);
$template->addGlobalVar('section_image', $section->image);
$template->addGlobalVar('section_description', $section->description);
/* セクション指定 ここまで */
} else {
trigger_error("Failed get section/category", E_USER_WARNING);
return;
}
$gid = $my->gid;
$nowdate = $database->Quote(_CURRENT_SERVER_TIME);
$nulldate = $database->Quote($database->getNullDate());
$orderby = '';
switch ( $this->orderby ) {
case 'date':
$orderby = 'con.created';
break;
case 'rdate':
$orderby = 'con.created DESC';
break;
case 'alpha':
$orderby = 'con.title';
break;
case 'ralpha':
$orderby = 'con.title DESC';
break;
case 'hits':
$orderby = 'con.hits DESC';
break;
case 'rhits':
$orderby = 'con.hits';
break;
case 'order':
$orderby = 'con.ordering';
break;
case 'author':
$orderby = 'con.created_by_alias, u.name';
break;
case 'rauthor':
$orderby = 'con.created_by_alias DESC, u.name DESC';
break;
default:
$orderby = 'con.ordering';
break;
}
$orderby and $orderby .= ',';
$orderby .= 'con.id';
$query = <<<__SQL__
SELECT con.*
,cusr.name as 'created_by_name'
,musr.name as 'modified_by_name'
FROM #__content as con
JOIN #__categories as cat
ON con.catid = cat.id
JOIN #__sections as sec
ON con.sectionid = sec.id
LEFT JOIN #__users as cusr
ON con.created_by = cusr.id
LEFT JOIN #__users as musr
ON con.modified_by = musr.id
WHERE {$where}
AND con.state = 1
AND cat.published = 1
AND sec.published = 1
AND (con.publish_up = {$nulldate} OR con.publish_up <= {$nowdate})
AND (con.publish_down = {$nulldate} OR con.publish_down >= {$nowdate})
AND con.access <= {$gid}
AND cat.access <= {$gid}
AND sec.access <= {$gid}
ORDER BY {$orderby}
__SQL__;
$database->setQuery($query, 0, $this->limit);
$rows = $database->loadObjectList();
if ($database->getErrorNum()) {
trigger_error("Failed query: ".$database->getErrorNum()." ".$database->getErrorMsg(), E_USER_WARNING);
return;
}
$items = '';
$nulldate = $database->getNullDate();
$params = new mosParameters("introtext=1\nintro_only=0");
$params->set('image', $this->mosimage);
$_MAMBOTS->loadBotGroup( 'content' );
foreach ($rows as $row) {
$row->introtext = str_replace('{mod_kingyoya_content_list}', '', $row->introtext);
$row->fulltext = str_replace('{mod_kingyoya_content_list}', '', $row->fulltext);
$row->text = $row->introtext.'{mod_kingyoya_content_list}'.$row->fulltext;
$results = botMosImage(true, $row, $params);
list($row->introtext,$row->fulltext) = explode('{mod_kingyoya_content_list}', $row->text);
$template->addVar('main', 'id', $row->id);
$template->addVar('main', 'title', $row->title);
$template->addVar('main', 'title_alias', $row->title_alias ? $row->title_alias : $row->title);
$template->addVar('main', 'introtext', $row->introtext);
$template->addVar('main', 'fulltext', $row->fulltext);
$template->addVar('main', 'publish_up', $row->publish_up === $nulldate ? '' : $row->publish_up);
$template->addVar('main', 'publish_down', $row->publish_down === $nulldate ? '' : $row->publish_down);
$template->addVar('main', 'created', $row->created);
$template->addVar('main', 'modified', $row->modified);
$template->addVar('main', 'created_by', $row->created_by);
$template->addVar('main', 'modified_by', $row->modified_by);
$template->addVar('main', 'created_by_name', $row->created_by_alias ? $row->created_by_alias : $row->created_by_name);
$template->addVar('main', 'modified_by_name', $row->modified_by_name);
$template->addVar('main', 'hits', $row->hits);
if (!$this->category) {
$category = $this->getCategory($row->catid);
$template->addVar('main', 'category_id', $category->id);
$template->addVar('main', 'category_name', $category->name);
$template->addVar('main', 'category_title', $category->title);
$template->addVar('main', 'category_image', $category->image);
$template->addVar('main', 'category_description', $category->description);
}
$template_item = "{$this->template_item}";
$template->readTemplatesFromInput($template_item, 'String');
$result = $template->getParsedTemplate('main');
if (patErrorManager::isError($result)) {
trigger_error("Failed parse template item", E_USER_WARNING);
return;
}
$items .= $result;
$template->freeTemplate('main');
}
$template_list = "{$this->template_list}";
$template->addVar('main', 'items', $items);
$template->readTemplatesFromInput($template_list, 'String');
$result = $template->displayParsedTemplate('main');
if (patErrorManager::isError($result)) {
trigger_error("Failed parse template list", E_USER_WARNING);
return;
}
}
/**
* カテゴリ情報を取得
* @param int of category id
* @return mosCategory
*/
function getCategory($id) {
static $categories = array();
if (!isset($categories[$id])) {
global $database;
$category =& new mosCategory($database);
$result = $category->load($id);
if (!$result) {
trigger_error("Unknown category: {$id}", E_USER_WARNING);
return false;
}
$categories[$id] =& $category;
}
return $categories[$id];
}
/**
* セクション情報を取得
* @param int of section id
* @return mosSection
*/
function getSection($id) {
static $sections = array();
if (!isset($sections[$id])) {
global $database;
$section =& new mosSection($database);
$result = $section->load($id);
if (!$result) {
trigger_error("Unknown section: {$id}", E_USER_WARNING);
return false;
}
$sections[$id] =& $section;
}
return $sections[$id];
}
}