<?php
/**
* @version $Id: mod_sliding_minifp.php 1.0
* Yose & Reni & Andy Sikumbang
* http://www.templateplazza.com
* @package Joomla 1.0.12
* -------------------------------------------------------------------------------------------
*/
/** ensure this file is being included by a parent file */
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
global $mosConfig_offset, $mosConfig_live_site, $mainframe;

// Get All Parameters
$moduleclass_sfx 	= $params->get( 'moduleclass_sfx', '' );
$module_id			= $params->get( 'module_id', '' );
$sections 			= $params->get( 'sections', '1,2,3' ) ;
$categories 		= $params->get( 'categories', '1,3,7' ) ;
$order				= $params->get( 'order', 1);
$period 			= intval( $params->get( 'period', 366 ) );
$loadorder 			= intval( $params->get( 'loadorder', 1 ) );
$cat_title 			= intval( $params->get( 'cat_title', 0 ) );
$show_front			= intval( $params->get( 'show_front', 0 ) );
$show_title 		= intval( $params->get( 'show_title', 1 ) );
$title_link 		= intval( $params->get( 'title_link', 1 ) );
$show_author 		= intval( $params->get( 'show_author', 0 ) );
$show_date 			= intval( $params->get( 'show_date', 0 ) );
$limit 				= intval( $params->get( 'limit', 200 ) );
$fulllink			= $params->get( 'fulllink','' );
$count 				= intval( $params->get( 'count', 5 ) );
$thumb_enable 		= 1;
$thumb_embed 		= intval( $params->get( 'thumb_embed', 0 ) );
$thumb_width 		= intval( $params->get( 'thumb_width', 32 ) );
$thumb_height 		= intval( $params->get( 'thumb_height', 32 ) );
$aspect 			= intval( $params->get( 'aspect', 0 ) );
$count_view			= intval( $params->get( 'count_view', 3 ) );
$limit_title		= intval( $params->get( 'limit_title', 100 ) );
$widthnews 			= intval( $params->get( 'widthnews', 700 ) );
$newsspeed			= intval( $params->get( 'newsspeed', 2000 ) );

if (!function_exists('call_jquery')) {
	function call_jquery() {
		global $mosConfig_live_site;
	?>
		<script type="text/javascript" src="<?php echo $mosConfig_live_site?>/modules/sliding_minifp/jquery-1.2.3.min.js"/></script>
	<?php
	}
}


$allowed_tags 		=  "<i><b>"; 

// please change these here
$skip = 0; // whether you want skip some items or not
$sep = " | "; // separator between articles date and creator

$columns = $count_view;	
if ($columns > 4) $columns = 4; // limit nmber of columns

if ($order == 0) $orderby = "created";
else $orderby = "hits";

// css classes - hardcoded
$class_date = "sliding-date";
$class_author = "sliding-date";
$class_another_links = "sliding-anotherlinks";
$class_minifulllink = "sliding-full_link";
$class_introtitle = 'sliding-introtitle';
$class_categoria = 'sliding-anotherlinks';

// if there's no image in an article, give it a default one - change image name here if you have one
$default_image_path = "/modules/sliding_minifp/default.gif";
/* used for finding images path on img tag */
$image_path = $params->get( 'image_path', 'images/stories' );

$now 		= _CURRENT_SERVER_TIME;
$access 	= !$mainframe->getCfg( 'shownoauth' );
$nullDate 	= $database->getNullDate();



?>
<link rel="stylesheet" href="<?php echo $mosConfig_live_site?>/modules/sliding_minifp/jq02.css" type="text/css" media="screen, projection" />
<?php
	call_jquery();
?>
<script type="text/javascript" src="<?php echo $mosConfig_live_site?>/modules/sliding_minifp/jq01.js"></script>




<style>



.sliding td { padding-right:5px;}
.sliding td p {
	margin-top:3px;}

.sliding-anotherlinks
{
	font-weight:bold;
	font-size:100%;
	display:block;

}

.sliding-anotherlinks-blank
{
	font-weight:bold;
	font-size:100%;
	display:block;


}


.sliding ul li {
	margin-left:20px;
	font-size:90%; 


}
.sliding ul li a:hover { 
	text-decoration:none;
	color: #0066CC;
}

.sliding-introtitle a {
	font-size:18px;

	font-weight:bold;
	color: #333;

}

.sliding-introtitle a:hover {
	text-decoration:underline;
	
}
.sliding-date {
	color:#666;
	font-size:9px;
	font-weight:normal;
	height:10px;
}
a.sliding-full_link {
	color:#0066CC;
	font-size:11px;
	font-weight:bold;
}
a:hover.sliding-full_link {
	text-decoration:underline;
}


<?
$visible = $count_view;
$news_slider_width = $widthnews ;
$news_slider_news_items_width = $news_slider_width - 40;
$news_slider_item_width = ceil(($news_slider_news_items_width -($news_cell * $visible))/$visible);
?>

.news_slider {
	position: relative; width: <?php echo $news_slider_width; ?>px; margin: 0 auto 0px auto; text-align: left;
}

.news_slider .news_items {
   
        /*The width must be equal to .item ((width + margin-right) * 2).*/
    
	position: relative; width: <?php echo $news_slider_news_items_width;?>px; top: 0; left: 20px; overflow: hidden;
}
.news_slider .item {
    
        /*Must contain a width and a margin-right.*/
    
	width: <?php echo $news_slider_item_width;?>px; margin-right: 0px;
}

</style>


<?php 
include($mosConfig_absolute_path."/modules/sliding_minifp/function.php");


?>







<?

$whereCatid = '';
if ($categories) {
	$catids = explode( ',', $categories );
	mosArrayToInts( $catids );
	$whereCatid = "\n AND ( a.catid=" . implode( " OR a.catid=", $catids ) . " )";
}
$whereSecid = '';
if ($sections) {
	$secids = explode( ',', $sections );
	mosArrayToInts( $secids );
	$whereSecid = "\n AND ( a.sectionid=" . implode( " OR a.sectionid=", $secids ) . " )";
}

$query = "SELECT a.*, u.name, cc.image AS image"
		. "\n FROM #__content AS a"
		. "\n LEFT JOIN #__content_frontpage AS f ON f.content_id = a.id"
		. "\n LEFT JOIN #__users AS u ON u.id = a.created_by"
		. "\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 = " . $database->Quote( $nullDate ) 
		. " OR a.publish_up <= " . $database->Quote( $now ) . " )"
		. "\n AND ( a.publish_down = " . $database->Quote( $nullDate ) 
		. " OR a.publish_down >= " . $database->Quote( $now ) . " )"
		. ( $access ? "\n AND a.access <= " . (int) $my->gid 
		. " AND cc.access <= " . (int) $my->gid 
		. " AND s.access <= " . (int) $my->gid : '' )
		. $whereCatid
		. $whereSecid
		. "\n AND ((TO_DAYS('" . date( 'Y-m-d', time()+$mosConfig_offset*60*60 ) . "') - TO_DAYS(a.created)) <= '" . $period . "')"
		. ( $show_front == '0' ? "\n AND f.content_id IS NULL" : '' )
		. "\n AND s.published = 1"
		. "\n AND cc.published = 1"
		. "\n ORDER BY a.$orderby DESC"
		. "\n limit $skip," . $count;

$database->setQuery( $query );
$rows = $database->loadObjectList();
echo $database->getErrorMsg();




$col = 0;
$pwidth = intval(100/$columns);

$rc = count($rows);


for ( $r = 0; $r < $rc; $r++) 
{
	if ($thumb_embed) 
	{	
	/* Regex tool for finding image path on img tag - thx to Jerson Figueiredo */	
	preg_match_all("#<img(.*)>#", $rows[$r]->introtext . $rows[$r]->fulltext, $txtimg);
	if (!empty($txtimg[0])) 
	{
		foreach ($txtimg[0] as $txtimgel) 
		{
			$rows[$r]->introtext = str_replace($txtimgel,"",$rows[$r]->introtext);
			if ( strstr($txtimgel, $image_path) ) 
			{
				if (strstr($txtimgel, 'src="/')) {
					preg_match_all("#src=\"\/" . addslashes($image_path) . "\/([\:\-\/\_A-Za-z0-9\.]+)\"#",$txtimgel,$txtimgelsr);
				}
				else {
					preg_match_all("#src=\"" . addslashes($image_path) . "\/([\:\-\/\_A-Za-z0-9\.]+)\"#",$txtimgel,$txtimgelsr);
				}
				
				if (!empty($rows[$r]->images)) {
					$rows[$r]->images = $txtimgelsr[1][0] . "\n" . $rows[$r]->images;
				}
				else {
					$rows[$r]->images = $txtimgelsr[1][0];
				}
			} 
			elseif (preg_match_all("#http#",$txtimgel,$txtimelsr,PREG_PATTERN_ORDER) > 0) {
				preg_match_all("#src=\"([\-\/\_A-Za-z0-9\.\:]+)\"#",$txtimgel,$txtimgelsr);
				if (!empty($rows[$r]->images)) {
					$rows[$r]->images = $txtimgelsr[1][0] . "\n" . $rows[$r]->images;
				}
				else {
					$rows[$r]->images = $txtimgelsr[1][0];
				}
			}
		}
		}
	} // end of thumbnail processing
	$rows[$r]->introtext= preg_replace("/{[^}]*}/","",$rows[$r]->introtext);
	$rows[$r]->itemid =  fptn_get_id_sliding_minifp($rows[$r]->id);

	// stripped html by default
	$rows[$r]->introtext = strip_tags($rows[$r]->introtext,$allowed_tags);
  	if($limit > 0) {
        $judul = $rows[$r]->title ;
		$rows[$r]->introtext     = fptn_limittext_sliding_minifp($rows[$r]->introtext,$limit);
		$rows[$r]->title 	     = fptn_limittext_sliding_minifp($rows[$r]->title,$limit_title);		
	}
	
}

$count_rows = count($rows);
?>


<div class="news_slider default">
	
<a href="#" class="prev"><img src="modules/sliding_minifp/arrow-left.gif" align="Previous" /></a>
<a href="#" class="next"><img src="modules/sliding_minifp/arrow-right.gif" align="Next" /></a>
	
<div class="news_items">
<div class="container fl">

<?php
$i =0;

$count_rows = count($rows);
foreach($rows as $row ){	
	$i++;	
	$ini_intro = 1;
	?> <div class="item fl"> <?
	
	// - add category title -
	if ($cat_title) {
		$query = "SELECT name FROM #__categories WHERE id =". $row->catid;
		$database->setQuery( $query );
		$database->loadObject($categ);
	}
				
		
	if ($show_title) {
		$title = '<a href="'. sefRelToAbs( 'index.php?option=com_content&amp;task=view&amp;id=' .$row->id . '&amp;Itemid=' . $row->itemid ) .'">'.  $row->title . '</a>';
	}
	else $title = "";				
		
			
	if ($loadorder == 1) 
	{
				
		showThumbNews_sliding_minifp($row->images,$row->image,$params,$row->itemid,$row->id);
							
	}
 
			
	if ($show_title) {
		if ($title_link == 1) { 
			echo '<span class="'.$class_introtitle.'">'.$title.'</span>'; 
		}
		else { 
			echo '<span class="'.$class_introtitle.'">'.  $row->title . '</span>'; 
		}
		
	echo "<p />";
	}
		if ($cat_title && $row->catid != $catid_before) 
		echo '<span class="'.$class_categoria.'">'.   $categ->name . '</span>';
	else if($cat_title && $row->catid == $catid_before){
		echo '<span class="sliding-anotherlinks-blank">&nbsp;</span>';
	}
	if ($show_date) {
		echo '<span class="'.$class_date.'">';
		echo mosFormatDate ($row->publish_up, $params->get( 'date_format' ));
		echo '</span>';
	}
			
	if ( $row->created_by_alias ) { $author = $row->created_by_alias; }
	else { $author = htmlspecialchars( $row->name ); }        
			
	if ($show_date && $show_author) {
		echo $sep;
    }
    	   	
	if ($show_author==1) {
		echo '<span class="'.$class_author.'">'.$author.'</span>';
	}
	echo "</p>";
	echo '<p />';
			
	if ($loadorder == 0) {
		    	
		showThumbNews_sliding_minifp($row->images,$row->image,$params,$row->itemid,$row->id);
	}		
				          
	echo $row->introtext; 
	
	echo '<br />';	
	if ($fulllink !="")
	{
		echo '<a class="sliding-link" href="'. sefRelToAbs( 'index.php?option=com_content&amp;task=view&amp;id=' . $row->id .'&amp;Itemid=' . $row->itemid) .'">'. $fulllink . '</a>' ;
	}
	echo "</p>";
	
	?>	
	
	
	</div>
	<?php
	
	
}//tutup for
?>
</div>
    </div>
    
    <div class="clear"></div>   
</div>

<script type="text/javascript">
	$(".default").accessNews({
        newsHeadline: "Computers &amp; Technology",
        newsSpeed: <?php echo $newsspeed;?>,
		visible:<?php echo $count_view;?>		
	});
</script>     



