<?php
$pfcache_ttl = 20 * 60;
$have_news = false;
$static_file = dirname(__FILE__) . "/../news/all_news_json.json";
if(file_exists($static_file)) {
	$allNews = json_decode(file_get_contents($static_file), true);

	if(isset($_REQUEST['debug'])) {
		echo '<pre>', var_export($allNews, true), '</pre>';
	}

	if(is_array($allNews) && count($allNews) > 0) {
		$have_news = true;
	}
}
$module_css_path = ($line_domain['theme'] != "" && $line_domain['theme'] != "default") ? ($path . ('assets/themes/' . $line_domain['theme'] . '/')) : $path;
if($have_news) {
	$optres['css'][] = $module_css_path . 'amodules/news_ticker/css/jquery.simplyscroll.css';
	$optres['js'][] = $path . 'amodules/news_ticker/js/jquery.simplyscroll.min.js';
	$optres['js'][] = $path . 'amodules/news_ticker/js/news_ticker.js';
	if(isset($_REQUEST['debug'])) {
		echo '<pre>', var_export($allNews, true), '</pre>';
	}
	?>
	<div class="box box-default box-compact">
        <div class="box-header">
            <b class="pull-left"><span class="glyphicon glyphicon-list-alt"></span> Latest Cyprus News</b> <span class="pull-right badge"><?php echo date("M d, Y");?></span>
        </div>
		<div class="box-body">
			<ul class="simply-scroll-list">
				<?php
                $cnt = 1;
				foreach ($allNews as $i=>$cn) {
					$cn_url_enc = str_replace('&amp;', '&', $cn['url']);
					$cn_url_enc = str_replace('&', '&amp;', $cn_url_enc);
					echo '<li>';
					echo '<a href="', $cn_url_enc, '" target="_blank" rel="nofollow" class="news-ticker-out">', $cn['title'], '</a> <span class="news-ticker-source" style="display: block;"><b>', $cn['newspaper'], '</b> - ', date("F d, Y", intval($cn['timestamp'])), '</span>';
					echo '</li>';
                    $cnt++;
				}

                $extra = $cnt%8;
                if($extra > 0) {
                    for($j=1; $j<=$extra; $j++) {
                        echo '<li>&nbsp;</li>';
                    }
                }
				?>
			</ul>
		</div>
	</div>

	<?php
}
else {
	if(isset($_REQUEST['debug'])) {
		echo '<br>There are no news.';
	}
}
?>