<?php
/*
 *
 * sflog!
 * Copyright (C) 2005 Alberto Sfolcini <a.sfolcini@gmail.com>
 *
 * This file is a part of sflog!.
 *
 * sflog! 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; either version 2
 * of the License, or (at your option) any later version.
 *
 * sflog! 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.
 *
 */

require_once(dirname(__FILE__)."/../common/Ini.class.php");
require_once(dirname(__FILE__)."/../common/WriteFile.class.php");
require_once(dirname(__FILE__)."/../cms/Blog.class.php");
require_once(dirname(__FILE__)."/../cms/Constants.inc.php");
	
/**
 * @title			: BlogBar
 * @description		: Manages BlogBar   
 * @date			: 24-Oct-2005   
 * @author			: Alberto Sfolcini  <a.sfolcini@gmail.com>
 */
class BlogBar {
	
	var $file;
	var $cms;
	
	/**
	 * Constructor
	 */
	function BlogBar(){
		$this->file = new WriteFile(BLOGSBAR,REWRITE);
		$this->cms  = new Blog();		
	}
	
	/**
	 * Generate blogsbar!
	 */
	function generate(){
		
		$blogs = array();
		$ordered = array();
		$blogs = $this->cms->getBlogsID();
		
		for($i=0;$i<$this->cms->getBlogsCount();$i++){
			error_reporting(E_USER_ERROR);
			$id = $blogs[$i];
			$name = $this->cms->getBlogFullName($id);
			$position = $this->cms->getBlogPosition($id);
			$isVisible = $this->cms->isBlogVisible($id);
			$ordered[$position] = array(BLOG_ID => $id,BLOG_NAME => $name,BLOG_VISIBLE => $isVisible);
		}	
		
		for($i=1;$i<count($blogs)+1;$i++){
			$val = $ordered[$i];
			$id = $val[BLOG_ID];
			$name = $val[BLOG_NAME];
			$visible = $val[BLOG_VISIBLE];
			if ($visible){
				$this->file->writeStr("<a target=\"_top\" href=\"index.php?blog=".$id."\">".$name."</a>");
				$this->file->writeStr("&nbsp;&nbsp;");
			} else {
				$this->file->writeStr('<?if ($auth->isAuth()){?>');
				$this->file->writeStr("<a target=\"_top\" href=\"index.php?blog=".$id."\">[".$name."]</a>");
				$this->file->writeStr("&nbsp;&nbsp;");
				$this->file->writeStr('<?}?>');
			}	
		}		
		$this->file->closeFile();
	}
	
	
}