modify mod_latestnew & mod_mostread to show the image
<?php
// no direct access
defined( '_VALID_MOS' ) or die( 'Restricted access' );
global $mosConfig_offset, $mosConfig_live_site, $mainframe;
$type = intval( $params->get( 'type', 1 ) );
$count = intval( $params->get( 'count', 5 ) );
$catid = trim( $params->get( 'catid' ) );
$secid = trim( $params->get( 'secid' ) );
$show_front = $params->get( 'show_front', 1 );
$now = date( 'Y-m-d H:i:s', time() );
$access = !$mainframe->getCfg( 'shownoauth' );
$nullDate = $database->getNullDate();
// select between Content Items, Static Content or both
switch ( $type ) {
case 2:
//Static Content only
$query = "SELECT distinct a.id, a.title, a.images"
. "\n FROM #__content AS a"
. "\n WHERE ( a.state = 1 AND a.sectionid = 0 )"
. "\n AND ( a.publish_up = '$nullDate' OR a.publish_up <= '$now' )"
. "\n AND ( a.publish_down = '$nullDate' OR a.publish_down >= '$now' )"
. ( $access ? "\n AND a.access <= $my->gid" : '' )
. "\n ORDER BY a.created DESC"
. "\n LIMIT $count"
;
$database->setQuery( $query );
$rows = $database->loadObjectList();
break;
case 3:
//Both
$query = "SELECT distinct a.id, a.title, a.sectionid, a.catid, a.images, cc.access AS cat_access, s.access AS sec_access, cc.published AS cat_state, s.published AS sec_state"
. "\n FROM #__content AS a"
. "\n LEFT JOIN #__content_frontpage AS f ON f.content_id = a.id"
. "\n LEFT JOIN #__categories AS cc ON cc.id = a.catid"
. "\n LEFT JOIN #__sections AS s ON s.id = a.sectionid"
. "\n WHERE a.state = 1"
. "\n AND ( a.publish_up = '$nullDate' OR a.publish_up <= '$now' )"
. "\n AND ( a.publish_down = '$nullDate' OR a.publish_down >= '$now' )"
. "\n AND a.sectionid != 11 AND a.sectionid != 12 AND a.sectionid !=26"
. ( $access ? "\n AND a.access <= $my->gid" : '' )
. ( $catid ? "\n AND ( a.catid IN ( $catid ) )" : '' )
. ( $secid ? "\n AND ( a.sectionid IN ( $secid ) )" : '' )
. ( $show_front == '0' ? "\n AND f.content_id IS NULL" : '' )
. "\n ORDER BY a.created DESC"
. "\n LIMIT $count"
;
$database->setQuery( $query );
$temp = $database->loadObjectList();
$rows = array();
if (count($temp)) {
foreach ($temp as $row ) {
if (($row->cat_state == 1 || $row->cat_state == '') && ($row->sec_state == 1 || $row->sec_state == '') && ($row->cat_access <= $my->gid || $row->cat_access == '' || !$access) && ($row->sec_access <= $my->gid || $row->sec_access == '' || !$access)) {
$rows[] = $row;
}
}
}
unset($temp);
break;
case 1:
default:
//Content Items only
$query = "SELECT distinct a.id, a.title, a.sectionid, a.catid, a.images"
. "\n FROM #__content AS a"
. "\n LEFT JOIN #__content_frontpage AS f ON f.content_id = a.id"
. "\n INNER JOIN #__categories AS cc ON cc.id = a.catid"
. "\n INNER JOIN #__sections AS s ON s.id = a.sectionid"
. "\n WHERE ( a.state = 1 AND a.sectionid > 0 )"
. "\n AND ( a.publish_up = '$nullDate' OR a.publish_up <= '$now' )"
. "\n AND ( a.publish_down = '$nullDate' OR a.publish_down >= '$now' )"
. ( $access ? "\n AND a.access <= $my->gid AND cc.access <= $my->gid AND s.access <= $my->gid" : '' )
. ( $catid ? "\n AND ( a.catid IN ( $catid ) )" : '' )
. ( $secid ? "\n AND ( a.sectionid IN ( $secid ) )" : '' )
. ( $show_front == '0' ? "\n AND f.content_id IS NULL" : '' )
. "\n AND s.published = 1"
. "\n AND cc.published = 1"
. "\n ORDER BY a.created DESC"
. "\n LIMIT $count"
;
$database->setQuery( $query );
$rows = $database->loadObjectList();
break;
}
// needed to reduce queries used by getItemid for Content Items
if ( ( $type == 1 ) || ( $type == 3 ) ) {
$bs = $mainframe->getBlogSectionCount();
$bc = $mainframe->getBlogCategoryCount();
$gbs = $mainframe->getGlobalBlogSectionCount();
}
// Output
?>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
...
$link = sefRelToAbs( 'index.php?option=com_content&task=view&id='. $row->id . $Itemid );
// ở đây cần xử lý Thumbnails cho image nhé.
if ($row->images!='') {
$images=explode('|',$row->images); //lấy ảnh đầu tiên của bài viết
} else $images[0]='default/default2.jpg';//nếu ko có ảnh thì thay bằng ảnh mặc định
?>
<tr>
<td>
<a href="<?php echo $link; ?>">
<img src="<?php echo $mosConfig_live_site.'/images/stories/'.$images[0];?>" border="0" width="50" height="50">
</a>
</td>
<td style="padding-left:5px; padding-bottom:5px; text-align:justify;">
<a href="<?php echo $link; ?>" class="latestnews<?php echo $moduleclass_sfx; ?>">
<?php echo $row->title; ?>
</a>
</td>
</tr>
<?php
}
?>
</table>
Xử lý tương tự cho module kia
// no direct access
defined( '_VALID_MOS' ) or die( 'Restricted access' );
global $mosConfig_offset, $mosConfig_live_site, $mainframe;
$type = intval( $params->get( 'type', 1 ) );
$count = intval( $params->get( 'count', 5 ) );
$catid = trim( $params->get( 'catid' ) );
$secid = trim( $params->get( 'secid' ) );
$show_front = $params->get( 'show_front', 1 );
$now = date( 'Y-m-d H:i:s', time() );
$access = !$mainframe->getCfg( 'shownoauth' );
$nullDate = $database->getNullDate();
// select between Content Items, Static Content or both
switch ( $type ) {
case 2:
//Static Content only
$query = "SELECT distinct a.id, a.title, a.images"
. "\n FROM #__content AS a"
. "\n WHERE ( a.state = 1 AND a.sectionid = 0 )"
. "\n AND ( a.publish_up = '$nullDate' OR a.publish_up <= '$now' )"
. "\n AND ( a.publish_down = '$nullDate' OR a.publish_down >= '$now' )"
. ( $access ? "\n AND a.access <= $my->gid" : '' )
. "\n ORDER BY a.created DESC"
. "\n LIMIT $count"
;
$database->setQuery( $query );
$rows = $database->loadObjectList();
break;
case 3:
//Both
$query = "SELECT distinct a.id, a.title, a.sectionid, a.catid, a.images, cc.access AS cat_access, s.access AS sec_access, cc.published AS cat_state, s.published AS sec_state"
. "\n FROM #__content AS a"
. "\n LEFT JOIN #__content_frontpage AS f ON f.content_id = a.id"
. "\n LEFT JOIN #__categories AS cc ON cc.id = a.catid"
. "\n LEFT JOIN #__sections AS s ON s.id = a.sectionid"
. "\n WHERE a.state = 1"
. "\n AND ( a.publish_up = '$nullDate' OR a.publish_up <= '$now' )"
. "\n AND ( a.publish_down = '$nullDate' OR a.publish_down >= '$now' )"
. "\n AND a.sectionid != 11 AND a.sectionid != 12 AND a.sectionid !=26"
. ( $access ? "\n AND a.access <= $my->gid" : '' )
. ( $catid ? "\n AND ( a.catid IN ( $catid ) )" : '' )
. ( $secid ? "\n AND ( a.sectionid IN ( $secid ) )" : '' )
. ( $show_front == '0' ? "\n AND f.content_id IS NULL" : '' )
. "\n ORDER BY a.created DESC"
. "\n LIMIT $count"
;
$database->setQuery( $query );
$temp = $database->loadObjectList();
$rows = array();
if (count($temp)) {
foreach ($temp as $row ) {
if (($row->cat_state == 1 || $row->cat_state == '') && ($row->sec_state == 1 || $row->sec_state == '') && ($row->cat_access <= $my->gid || $row->cat_access == '' || !$access) && ($row->sec_access <= $my->gid || $row->sec_access == '' || !$access)) {
$rows[] = $row;
}
}
}
unset($temp);
break;
case 1:
default:
//Content Items only
$query = "SELECT distinct a.id, a.title, a.sectionid, a.catid, a.images"
. "\n FROM #__content AS a"
. "\n LEFT JOIN #__content_frontpage AS f ON f.content_id = a.id"
. "\n INNER JOIN #__categories AS cc ON cc.id = a.catid"
. "\n INNER JOIN #__sections AS s ON s.id = a.sectionid"
. "\n WHERE ( a.state = 1 AND a.sectionid > 0 )"
. "\n AND ( a.publish_up = '$nullDate' OR a.publish_up <= '$now' )"
. "\n AND ( a.publish_down = '$nullDate' OR a.publish_down >= '$now' )"
. ( $access ? "\n AND a.access <= $my->gid AND cc.access <= $my->gid AND s.access <= $my->gid" : '' )
. ( $catid ? "\n AND ( a.catid IN ( $catid ) )" : '' )
. ( $secid ? "\n AND ( a.sectionid IN ( $secid ) )" : '' )
. ( $show_front == '0' ? "\n AND f.content_id IS NULL" : '' )
. "\n AND s.published = 1"
. "\n AND cc.published = 1"
. "\n ORDER BY a.created DESC"
. "\n LIMIT $count"
;
$database->setQuery( $query );
$rows = $database->loadObjectList();
break;
}
// needed to reduce queries used by getItemid for Content Items
if ( ( $type == 1 ) || ( $type == 3 ) ) {
$bs = $mainframe->getBlogSectionCount();
$bc = $mainframe->getBlogCategoryCount();
$gbs = $mainframe->getGlobalBlogSectionCount();
}
// Output
?>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
...
$link = sefRelToAbs( 'index.php?option=com_content&task=view&id='. $row->id . $Itemid );
// ở đây cần xử lý Thumbnails cho image nhé.
if ($row->images!='') {
$images=explode('|',$row->images); //lấy ảnh đầu tiên của bài viết
} else $images[0]='default/default2.jpg';//nếu ko có ảnh thì thay bằng ảnh mặc định
?>
<tr>
<td>
<a href="<?php echo $link; ?>">
<img src="<?php echo $mosConfig_live_site.'/images/stories/'.$images[0];?>" border="0" width="50" height="50">
</a>
</td>
<td style="padding-left:5px; padding-bottom:5px; text-align:justify;">
<a href="<?php echo $link; ?>" class="latestnews<?php echo $moduleclass_sfx; ?>">
<?php echo $row->title; ?>
</a>
</td>
</tr>
<?php
}
?>
</table>
Xử lý tương tự cho module kia
Nhận xét
Đăng nhận xét