<?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/PhotoBlog.class.php");
require_once(dirname(__FILE__)."/../cms/Constants.inc.php");
	
/**
 * @title			: PhotoBlogBar
 * @description		: Manages PhotoBlogBar   
 * @date			: 15-Dec-2005   
 * @author			: Alberto Sfolcini  <a.sfolcini@gmail.com>
 */
class PhotoBlogBar {
	
	var $file;
	var $cms;
	var $blogID;
	
	/**
	 * Constructor
	 */
	function PhotoBlogBar($blogID){
		$this->blogID = $blogID;
		$this->file = new WriteFile(BLOG_PATH.$this->blogID.PHOTOBLOGSBAR,REWRITE);
		$this->cms  = new PhotoBlog($this->blogID);		
	}
	
	/**
	 * Generate photoBlogBar!
	 */
	function generate(){
		
		$pbs = array();
		$ordered = array();
		$pbs = $this->cms->getPhotoBlogID();
				
		for($i=0;$i<$this->cms->getPhotoBlogCount();$i++){
			error_reporting(E_USER_ERROR);
			$id = $pbs[$i];
			$text = $this->cms->getPhotoBlogText($id);
			$position = $this->cms->getPhotoBlogPosition($id);
			$ordered[$position] = array(PHOTOBLOG_ID => $id,PHOTOBLOG_TEXT => $text);
		}	
		if (file_exists(BLOG_PATH.$this->blogID.BLOG_ALBUM_TITLE))
			$title = file_get_contents(BLOG_PATH.$this->blogID.BLOG_ALBUM_TITLE);
		else 
			$title = "";
		$this->file->writeStr('<h2>'.$title.'</h2>');
		$this->file->writeStr('<ul>');
		
		for($i=1;$i<count($pbs)+1;$i++){
			$val = $ordered[$i];
			$id = $val[PHOTOBLOG_ID];
			$text = $val[PHOTOBLOG_TEXT];
			$this->file->writeStr('<li><a href="index.php?blog='.$this->blogID.'&photoblog='.$id.'">'.$text.'</a></li>');
		}		
		
		$this->file->writeStr('</ul>');
		$this->file->closeFile();
	}
	
	
}