<?php

if(stristr(htmlentities($_SERVER['PHP_SELF']), "sidebar.php")){
	die("You cannot access this file directly!");
}

# Copyright (C) 2010 - onwards. The Napata CMS Project.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# http://www.gnu.org/copyleft/gpl.html

error_reporting(0);

function MenuArticles() {

	$dir = scandir("./articles");
	
	unset($dir[0], $dir[1]);#Remove '.' and '..' from the printed articles
	
	$random_article = array_keys($dir);
	
	shuffle($dir);
	
	$published = array_combine($random_article, $dir);
	
	echo '<h3>Articles</h3>';
	
	echo '<ul>';
	
		$num_articles = count($published);
		
		foreach($published as $key=>$article) {
		
			
				if($key !== 8)#Presumably show only upto 8 articles
				{
					if(substr($article, -4, 4) == '.txt')
					{
						if(strlen($article) > 20){
							$cut_article_link = substr_replace($article, "...", 18);
							echo '<li><a href="index.php?post='.basename($article, '.txt').'">'.ucfirst(basename($cut_article_link, '.txt')).'</a></li>';
						}
						else{
							echo '<li><a href="index.php?post='.basename($article, '.txt').'">'.ucfirst(basename($article, '.txt')).'</a></li>';
						}
					
					}
				}
				else
				{
				
					break;
					
				}
					
		}
	echo '</ul>';	
	
	echo '<a href="index.php?page=all">All Articles &raquo;</a>';

	
}

MenuArticles();

?>