<?php
if ($vbulletin->options['yilmaz_carousel_location'] =='0'){
require_once(DIR . '/includes/adminfunctions_template.php');
	$carousel_bul = trim(preg_replace('#^\$final_rendered = \'(.*)\';$#s', '\\1', compile_template('{vb:raw navbar}')));			
	$carousel_degistir = trim(preg_replace('#^\$final_rendered = \'(.*)\';$#s', '\\1', compile_template('{vb:raw navbar}
	{vb:raw template_hook.yilmaz_carousel}')));	
	if ($vbulletin->options['yilmaz_carousel_forumhome']){
    $vbulletin->templatecache['FORUMHOME'] = str_replace($carousel_bul, $carousel_degistir, $vbulletin->templatecache['FORUMHOME']);
	}
	$vbulletin->templatecache['FORUMDISPLAY'] = str_replace($carousel_bul, $carousel_degistir, $vbulletin->templatecache['FORUMDISPLAY']);
}
	
	

 // saat iþlevi baþ
function time_yilmaz_carousel ($zaman){
	global $vbphrase;
   $zaman =  strtotime($zaman);
   $zaman_farki = time() - $zaman;
   $saniye = $zaman_farki;
   $dakika = round($zaman_farki/60);
   $saat = round($zaman_farki/3600);
   $gun = round($zaman_farki/86400);
   $hafta = round($zaman_farki/604800);
   $ay = round($zaman_farki/2419200);
   $yil = round($zaman_farki/29030400);
   if( $saniye < 60 ){
      if ($saniye == 0){
         return ''.$vbphrase[just].'';
      } else {
         return $saniye .' '.$vbphrase[seconds_ago].'';
      }
   } else if ( $dakika < 60 ){
      return $dakika .' '.$vbphrase[minute_ago].'';
   } else if ( $saat < 24 ){
      return $saat.' '.$vbphrase[hours_ago].'';
   } else if ( $gun < 7 ){
      return $gun .' '.$vbphrase[days_ago].'';
   } else if ( $hafta < 4 ){
      return $hafta.' '.$vbphrase[weeks_ago].'';
   } else if ( $ay < 12 ){
      return $ay .' '.$vbphrase[month_ago].'';
   } else {
      return $yil.' '.$vbphrase[minute_ago].'';
   }
}
// saat iþlevi son

// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################

$yilmaz_carousel_forum_id = $vbulletin->options['yilmaz_carousel_forum_id'];


		
//slider sorgu show baþ
$sql_yilmaz_carousel = $db->query_read("SELECT
thread.visible, thread.votetotal, thread.votenum, thread.views as views, thread.title as title, thread.threadid as threadid, thread.replycount, thread.dateline, post.postid, post.pagetext as pagetext, thread.iconid, attachment.attachmentid AS attachmentid, forum.threadcount, forum.title as forumtitle, user.username as username, user.userid as userid
    FROM " . TABLE_PREFIX . "thread as thread
    LEFT JOIN " . TABLE_PREFIX . "post as post on (thread.firstpostid = post.postid)
    LEFT JOIN " . TABLE_PREFIX . "forum as forum on (thread.forumid = forum.forumid)
	LEFT JOIN  " . TABLE_PREFIX . "user AS user ON (user.username = thread.postusername)
	LEFT JOIN (" . TABLE_PREFIX . "attachment AS attachment
	INNER JOIN " . TABLE_PREFIX . "filedata AS filedata ON (attachment.filedataid = filedata.filedataid) ) ON (attachment.contentid = thread.firstpostid AND filedata.extension IN('jpg', 'gif', 'png', 'jpeg', 'bmp'))
    WHERE thread.visible = 1 AND thread.iconid = 0 AND thread.forumid IN (0,".$yilmaz_carousel_forum_id.")
    GROUP BY threadid
	ORDER BY thread.dateline DESC
    LIMIT 0,16");
//slider sorgu show son
//slider show süreü baþ
function temizle($tr1) {
$turkce=array("þ","Þ","ý","ü","Ü","ö","Ö","ç","Ç","þ","Þ","ý","ð","Ð","Ý","ö","Ö","Ç","ç","ü","Ü");
$duzgun=array("s","S","i","u","U","o","O","c","C","s","S","i","g","G","I","o","O","C","c","u","U");
$tr1=str_replace($turkce,$duzgun,$tr1);
$tr1 = preg_replace("@[^a-z0-9\-_þýüðçÝÞÐÜÇ]+@i","-",$tr1);
return $tr1;
}
while ($yilmaz_carousel = $vbulletin->db->fetch_array($sql_yilmaz_carousel)) {	 
  
  $metin_ss = $yilmaz_carousel['pagetext'];
    $yilmaz_carousel['resimurl'] = null;	
    if (stripos($metin_ss, '[/img]') !== false){
    
    preg_match('/\[(img|IMG)\]\s*(https?:\/\/([^*\r]+|[a-z0-9\/\\\._\- !]+))\[\/(img|IMG)\]/Ui',$metin_ss,$imgRs);
    $match[2] = $imgRs[2];
    
        
     if (isset($match[2]) && !empty($match[2])){
            $yilmaz_carousel['resimurl'] = $match[2];
        }
    } else if (stripos($metin_ss, '[/imgr]') !== false){
	preg_match('/\[(imgr|IMGR)\]\s*(https?:\/\/([^*\r]+|[a-z0-9\/\\\._\- !]+))\[\/(imgr|IMGR)\]/Ui',$metin_ss,$imgRs);
    $match[2] = $imgRs[2];
	if (isset($match[2]) && !empty($match[2])){
            $yilmaz_carousel['resimurl'] = $match[2];
        }
    } else if (stripos($metin_ss, '[/imgl]') !== false){
	preg_match('/\[(imgl|IMGL)\]\s*(https?:\/\/([^*\r]+|[a-z0-9\/\\\._\- !]+))\[\/(imgl|IMGL)\]/Ui',$metin_ss,$imgRs);
    $match[2] = $imgRs[2];
	} else if (stripos($metin_ss, '[/NOIMG]') !== false){
	preg_match('/\[(NOIMG|NOIMG)\]\s*(https?:\/\/([^*\r]+|[a-z0-9\/\\\._\- !]+))\[\/(NOIMG|NOIMG)\]/Ui',$metin_ss,$imgRs);
    $match[2] = $imgRs[2];
	if (isset($match[2]) && !empty($match[2])){
            $yilmaz_carousel['resimurl'] = $match[2];
        }	
    } else if (stripos($metin_ss, '[/imgg]') !== false){
	
	preg_match('/\[imgg=([^\]]+?)\]\s*(https?:\/\/([^*\r]+|[a-z0-9\/\\\._\- !]+))\[\/(imgg|IMGG)\]/Ui',$metin_ss,$imgRs);
    $match[2] = $imgRs[2];
	if (isset($match[2]) && !empty($match[2])){
            $yilmaz_carousel['resimurl'] = $match[2];
        }
	} else if ($yilmaz_carousel['attachmentid']) {      
$yilmaz_carousel['resimurl'] = "".$vbulletin->options['bburl']."/attachment.php?attachmentid=".$yilmaz_carousel['attachmentid']."";

}

$yilmaz_carousel['resimurl2'] = $yilmaz_carousel['resimurl'];

if (!$yilmaz_carousel['attachmentid']) { 
$yilmaz_carousel[resimurl] = 'includes/yilmaz/carousel/t.php?src='.$yilmaz_carousel[resimurl].'&amp;w=277&amp;h=156';
}


if (!$yilmaz_carousel['resimurl2']){
$ilk_harf = temizle($yilmaz_carousel['title']);
$ilk_harf = substr($ilk_harf, 0, 1);	
$ilk_harf=strtoupper($ilk_harf);
if ($vbulletin->options['yilmaz_carousel_dark_or_white']){
$yilmaz_carousel['resimurl'] = 'includes/yilmaz/png.php?r=1&amp;h='.$ilk_harf.'';
}else{
$yilmaz_carousel['resimurl'] = 'includes/yilmaz/png.php?r=2&amp;h='.$ilk_harf.'';	
}
}


 $trans = array(
	"&amp;" => "&",
	"&amp;quot;" => " ",
	"'" => '',
	'"' => ''
	);
	$yilmaz_carousel['pagetext'] = preg_replace('#\[IMG\](.+?)\[\/IMG\]#i'," ",$yilmaz_carousel['pagetext']);
    $yilmaz_carousel['pagetext'] = strip_bbcode($yilmaz_carousel['pagetext'], true, true, true, true) ;

	$pattern = '~\[([^\]]+?)(=[^\]]+?)?\](.+?)\[/\1\]~'; 
    preg_replace($pattern, ' ' , $yilmaz_carousel['pagetext']); 
	
$yilmaz_carousel['pagetext'] = strtr($yilmaz_carousel['pagetext'], $trans); 	
$yilmaz_carousel['pagetext'] = substr($yilmaz_carousel['pagetext'], 0, 55) . ''; 

$yilmaz_carousel['title'] = strtr($yilmaz_carousel['title'], $trans);	
	
$yilmaz_carousel['newDate2'] = date("d.m.Y, H:i:s", $yilmaz_carousel['dateline']);	
$yilmaz_carousel['newDate'] = date("Y-m-d H:i:s", $yilmaz_carousel['dateline']);
$yilmaz_carousel['tarih'] = time_yilmaz_carousel($yilmaz_carousel['newDate']);
	
	
$say = ++$a;
$sifir = $say-1;	

$byusername = construct_phrase($vbphrase['by_x_guest'], $yilmaz_carousel[username]);
	
$guncelbegeni = construct_phrase($vbphrase['thread_rating_x_votes_y_average'], $yilmaz_carousel[votenum], $yilmaz_carousel[votetotal]);

$yilmaz['yilmaz_carousel_bits'] .= '<!-- '.$say.' yilmaz_carousel bas -->
<article class="cactus-post-item hentry"> <div class="entry-content">  <div class="picture"> <div class="picture-content"> <a title="'.$yilmaz_carousel[title].'" target="_self" href="showthread.php?t='.$yilmaz_carousel[threadid].'"> <img width="277" height="156" data-src="'.$yilmaz_carousel[resimurl].'" data-srcset="'.$yilmaz_carousel[resimurl].' 277w, '.$yilmaz_carousel[resimurl].' 300w, '.$yilmaz_carousel[resimurl].' 768w, '.$yilmaz_carousel[resimurl].' 1024w, '.$yilmaz_carousel[resimurl].' 205w, '.$yilmaz_carousel[resimurl].' 320w, '.$yilmaz_carousel[resimurl].' 407w, '.$yilmaz_carousel[resimurl].' 565w, '.$yilmaz_carousel[resimurl].' 636w, '.$yilmaz_carousel[resimurl].' 800w, '.$yilmaz_carousel[resimurl].' 1200w" data-sizes="(max-width: 277px) 100vw, 277px" class="lazyload effect-fade" src="'.$yilmaz_carousel[resimurl].'" style="padding-top:56.317689530686%;" alt="'.$yilmaz_carousel[threadid].'"/><div class="ct-icon-video"></div> </a><div class="cactus-note font-size-1" title="'.$guncelbegeni.'"><i class="fa fa-thumbs-up"></i><span>'.$yilmaz_carousel[votenum].'</span></div><div class="cactus-note ct-time font-size-1"><span title="'.$vbphrase[posts].'">'.$yilmaz_carousel[replycount].'</span></div> </div> </div> <div class="content">  <h3 class="cactus-post-title entry-title h4"> <a href="showthread.php?t='.$yilmaz_carousel[threadid].'" title="'.$yilmaz_carousel[title].'">'.$yilmaz_carousel[title].'</a></h3> <div class="posted-on metadata-font"> <a href="member.php?u='.$yilmaz_carousel[userid].'" target="_self" class="author cactus-info font-size-1"><span>'.$byusername.'</span></a> <div class="date-time cactus-info font-size-1"><a href="showthread.php?t='.$yilmaz_carousel[threadid].'" target="_self" class="cactus-info" rel="bookmark"><time datetime="'.$yilmaz_carousel[newDate2].'" class="entry-date updated">'.$yilmaz_carousel[tarih].'</time></a></div> </div> </div> </div> </article> 
<!-- '.$say.' yilmaz_carousel son -->';
}

$template_hook['yilmaz_carousel'] .= '<div class="main-bottom-sidebar-wrap">
 <aside id="popular_posts_id-9" class="widget body-widget widget-popular-post"><style>#popular_posts_id-9 .ct-sub-w-title{color:FFFFFF !important; background:FF0000 !important}</style><div class="body-widget-inner widget-inner">
 <div class="cactus-carousel-style-bottom dark-div"> <div class="carousel-heading"> <div class="font-size-3 heading-font">'.$vbphrase[lastes_videos].' <div class="prev-slide"><i class="fa fa-angle-left"></i></div> <div class="next-slide"><i class="fa fa-angle-right"></i></div> </div> </div> <div class="cactus-listing-wrap"> <div class="cactus-listing-config style-2">  <div class="cactus-sub-wrap"> 
'.$yilmaz[yilmaz_carousel_bits].'
</div> </div> </div></div></div></aside>
 </div>';
 if ($vbulletin->options['yilmaz_carousel_location'] =='1'){
$template_hook['yilmaz_carousel_man'] = $template_hook['yilmaz_carousel'];	
}