<?php

$seconds_to_cache = 2592000;
$ts = gmdate("D, d M Y H:i:s", time() + $seconds_to_cache) . " GMT";

header("Content-Type: text/html; charset=UTF-8");
header("Expires: $ts");
header('Cache-Control: public, max-age=2592000, pre-check=2592000');
header('X-UA-Compatible: IE=edge,chrome=1');
header("Pragma: cache");

//error_reporting(E_ALL);
require_once("/home/www/wwwbuzzerstar/library/Functions.inc.php");
require_once("/home/www/wwwbuzzerstar/library/Connection.inc.php");
require_once("/home/www/wwwbuzzerstar/library/Cache.inc.php");
require_once("/home/www/wwwbuzzerstar/library/Template.inc.php");

$design 			= new Template();
$cache				= new FileCache();
$config 			= new Config();
$func	 			= new Functions();
$key 				= 'getTicker:TextStream';

if (!$content = $cache->fetch($key)) {

	$conn 				= new Connection();
	$pdo				= $conn->prepareQuery();
	$table 				= $config->sql_tablename_publish_de();

	$stmt 				= $pdo->prepare("SELECT * FROM $table WHERE id>0 AND p_isonline=1 ORDER BY p_timestamp DESC LIMIT 10");
	$stmt->execute();

	$htmlcode	= "";
	$htmlcode	=<<<END
		<ul class="bxslider" style="width: 80%; height: 80%;">
END;
	while($rows = $stmt->fetch(PDO::FETCH_ASSOC)) {
		$shortcode			= $rows["p_shortcode"];
		$headline			= $rows["p_headline"];
		//$pic_desc			= $rows["p_picture_1_description"];
		$linkingcode		= "https://www.buzzerstar.com/".$func->makeArticleLink($shortcode);
		//$titlewrap 			= wordwrap(substr($headline,0,55), 20, "<br />", true);
		
		$htmlcode			.=<<<END
		<li><a href="$linkingcode#utm_source=textticker&utm_medium=textticker&utm_campaign=extern" target="_blank" title="$headline" style="font-size:107%">$headline</a></li>
END;
	}

	$htmlcode		.=<<<END
		</ul>
END;

	$stmt 	= null; // doing this is mandatory for connection to get closed
	$pdo   	= null;

	$content = array_merge(
		array('tickercontent'=>$htmlcode)
	);
	$cache->store($key,$content,$config->newsticker_cache_ttl());
} // if (!$content = $cache->fetch($key)) {

$design->setPath( "/home/www/wwwbuzzerstar/tpl-new/" );
$design->display_cache('ticker_text_de', $content, true, 3600*24*3);

exit(0);
?>