[PC-BSD Commits] r1569 - in websites/pbidir.com/bibivu: bin etc/periodic/hourly

svn at pcbsd.org svn at pcbsd.org
Sun Mar 9 13:04:59 PST 2008


Author: fabry
Date: 2008-03-09 14:04:59 -0700 (Sun, 09 Mar 2008)
New Revision: 1569

Modified:
   websites/pbidir.com/bibivu/bin/start.php
   websites/pbidir.com/bibivu/etc/periodic/hourly/upd_mirr.php
Log:
fixed a problem with the automatic update of the mirrors

Modified: websites/pbidir.com/bibivu/bin/start.php
===================================================================
--- websites/pbidir.com/bibivu/bin/start.php	2008-03-09 20:53:17 UTC (rev 1568)
+++ websites/pbidir.com/bibivu/bin/start.php	2008-03-09 21:04:59 UTC (rev 1569)
@@ -1,655 +1,656 @@
-<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
-// ------------------------------------------------------------------------
-
-class start extends bibivu{
-	public $ajax = false;
-	/**
-	 * Initialize the default class
-	 *
-	 * @access	private
-	 * @return	void
-	 */ 
-	public function __construct(){
-		parent::__construct();
-		session_start();
-		$task = $this->uri->get(TASK_KEY, '');
-		switch($task){
-			case 'update':
-				$this->load_library($task);
-				return true;
-				break;
-			case 'mirrors':
-				set_time_limit(0);
-				$mirrors = load_library('mirror');
-				$tmps = $mirrors->get_all(array(),array('last_update DESC'));
-				if(isset($_GET['update'])){
-					foreach($tmps as $key=>$value){
-						$filters = array();
-						$filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
-						$filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$value['id']);
-						if($this->is_web()){
-							echo $value['id'].': '.$value['name'].' - '.$value['url'].' => '.$mirrors->get_record($filters)->update_mirror('PBI/.zupdate').'<br />';
-							flush();
-						}
-					}
-					return true;
-				}
-				break;
-			case 'lang':
-				load_library('lang')->set_lang($this->uri->get_num(3));
-				$task = 'home';
-				break;
-		}
-
-		$this->ajax	 = isset($_POST['ajax']) || isset($_GET['ajax']);
-		$this->load_library('table_prototype');
-		$this->load_library('pbi');			//this is enough
-		$this->load_library('permissions');
-		
-		if($this->permissions->is_logged()){
-			load_library('lang')->set_lang($this->permissions->get('lang',''));
-		}
-
-		$this->display->assign('is_logged',$this->permissions->is_logged());
-		$this->display->assign('pbi_uri',$this->uri->create_uri(array(TASK_KEY=>'pbi')));
-		load_library('menu')->create_menu($this->display);
-
-		if(method_exists($this,'web_'.$task) && is_callable(array($this,'web_'.$task))){
-			$this->display->assign('task',$task);
-			$this->{'web_'.$task}();
-		} else {
-			if($this->uri->get_num(1)==''){
-				$this->display->assign('task','home');
-				$this->web_home();
-			} else {
-				$this->display->assign('search_text',trim(str_replace('/',' ', at implode(' ', $this->uri->get_GETnum()))));
-				$this->display->assign('task','search');
-				$this->web_search();
-			}
-		}
-	}
-	
-	public function display($page='home', $show_head_foot=true){
-		$this->display->start($show_head_foot,'pbidir');
-		$this->display->show('pbidir/'.$page);
-		$this->display->end($show_head_foot,'pbidir');
-	}
-
-	public function web_home(){
-		$filters = array();
-		$filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
-		$filters[] = array('field'=>'show_on_site', 'operator'=>'=', 'value'=>'y');
-		$group = array();
-		$order = array('name');
-		$limit = '';
-		$this->display->assign('categories', $this->table_prototype->get_raw($filters, $order, $group, $limit,'category'));
-
-		$filters = array();
-		$filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
-		$filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
-		$group = array('pbi_id');
-		$order = array('date_last_status_id DESC');
-		$limit = 20;
-		$join = array();
-		$fields = array('max(date_last_status_id) date_last_status_id', 'MAX(id) id');
-		$this->display->assign('latest_releases', load_library('pbi_release')->get_all($filters, $order, $group, $limit, '', $join, $fields));
-		
-		$filters = array();
-		$filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
-		$filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
-		$group = array();
-		$order = array('date_added DESC');
-		$limit = 20;
-		$this->display->assign('latest', $this->pbi->get_raw($filters, $order, $group, $limit));
-
-		$filters = array();
-		$filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
-		$filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
-		$group = array();
-		$order = array('total_download DESC');
-		$limit = 20;
-		$this->display->assign('most_download', $this->pbi->get_raw($filters, $order, $group, $limit));
-
-		$this->display->assign('title', 'Your PC-BSD software');
-		$this->display('home');
-	}
-
-	public function web_contact_us(){
-		$this->display->assign('title', 'Contact Us');
-		$this->display('contact_us');
-	}
-	
-	public function web_category(){
-		$filters = array();
-		$filters[] = array('field'=>'web_alias', 'operator'=>'=', 'value'=>$this->uri->get_num(3));
-		$category = $this->table_prototype->get_record($filters,'category')->get_info();
-		if(!isset($category['id']) || $category['web_alias']!=$this->uri->get_num(3)){
-			//package doesn't exists
-			$this->display->assign('message', 'Category not found!');
-			$this->display('message');
-			return;
-		}
-
-		$pbis_per_page = 20;
-		$order = $this->uri->get_num(4, 'name');
-		$order_mode = $this->uri->get_num(5, 'asc');
-		$current_page = $this->uri->get_num(6,0);
-
-		switch(strtolower($order)){
-			case 'added':
-				$order_field = 'date_added';
-				break;
-			case 'rating':
-				$order_field = '(total_points+5)/(total_votes+1)';
-				break;
-			case 'download':
-				$order_field = 'total_download';
-				break;
-			case 'name':
-			default:
-				$order='name';
-				$order_field = 'name';
-		}
-		$order_mode = $order_mode=='desc'?'desc':'asc';
-
-		$filters = array();
-		$filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
-		$filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
-		$filters[] = array('field'=>'category_id', 'operator'=>'=', 'value'=>$category['id']);
-		list($category['total_pbis']) = $this->pbi->select()->fields(array('COUNT(*)'))->where($filters)->do_db()->db->fetch_row($this->pbi->last_result());
-
-		$this->display->assign('result', $category);
-		$this->display->assign('breadcrumb_text', $category['name']);
-		$pbis = $this->pbi->get_all($filters, array($order_field.' '.$order_mode, 'name'), array(), ($current_page*$pbis_per_page).','.$pbis_per_page);
-		$this->display->assign('pbis', $pbis);
-
-		$this->display->assign('order', $order);
-		$this->display->assign('order_mode', $order_mode);
-		$this->display->assign('pbis_per_page', $pbis_per_page);
-		$this->display->assign('current_page', $current_page);
-
-		$this->display->assign('title', $category['name']);
-		$this->display('search');
-	}
-
-	public function web_pbi(){
-		if(!is_numeric($this->uri->get_num(3))){
-			$this->redirect($this->display->get('home_uri'), 'Error opening this page', 3, true, 'pbidir');
-			return;
-		}
-		$filters = array();
-		$filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
-		$filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
-		$filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$this->uri->get_num(3));
-		$pbi = $this->pbi->get_record($filters)->get_info();
-		if(!isset($pbi['id']) || $pbi['id']!=$this->uri->get_num(3)){
-			//package doesn't exists
-			$this->display->assign('message', 'Package '.$this->uri->get_num(3).' not found!');
-			$this->display('message');
-			return;
-		}
-		if($this->uri->get_num(4)=='vote' && $this->uri->get_num(5)>0 && $this->permissions->can('pbi_vote')){
-			//voting the pbi
-			//return a normal TEXT message
-			$vote = $this->uri->get_num(5);
-			if($this->ajax){
-				$this->config->set('display_headers',array('Content-Type'=> 'text/plain'));			//text/plain = only text file
-				$this->display->start();
-			} else {
-				$uri = $this->display->get('pbi_uri').'/'.$pbi['id'];
-			}
-			if($this->pbi->vote_pbi($pbi['id'],$vote)){
-				if($this->ajax){
-					$ret = $this->pbi->get_vote($pbi['id']);
-					if(is_numeric($ret)){
-						echo number_format($ret, 2, '.', '');
-					} else {
-						echo 0;
-					}
-				} else {
-					$this->redirect($uri, 'Vote Saved Succesfully! '.$this->_get_redirect_messages('previous', $uri), 3, true, 'pbidir');
-				}
-			} else {
-				if($this->ajax){
-					echo 'problems saving your vote!';
-				} else {
-					$this->redirect($uri, 'Problems saving your vote! '.$this->_get_redirect_messages('previous', $uri), 3, true, 'pbidir');
-				}
-			}
-			if($this->ajax){
-				$this->display->end();
-			}
-			return;
-		} else {
-			$filters = array();
-			$filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$pbi['category_id']);
-			$category = load_library('category')->get_record($filters)->get_info();
-
-			$filters = array();
-			$filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
-			$filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
-			$filters[] = array('field'=>'pbi_id', 'operator'=>'=', 'value'=>$pbi['id']);
-			$limit = '';	//was 3
-			$this->display->assign('pbi_releases', load_library('pbi_release')->get_all($filters, array('date_added DESC'), array(), $limit));
-			
-			$filters = array();
-			$filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
-			$filters[] = array('field'=>'pbi_id', 'operator'=>'=', 'value'=>$pbi['id']);
-			$this->display->assign('pbi_images', load_library('pbi_image')->get_all($filters, array('`order`')));
-			
-			$filters = array();
-			$filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
-			$filters[] = array('field'=>'pbi_id', 'operator'=>'=', 'value'=>$pbi['id']);
-			$comments = $this->table_prototype->get_all($filters, array('date_added DESC'), array(), 20,'pbi_comment');
-			if(is_array($comments)){
-				foreach($comments as $key=>$value){
-					$comments[$key]['date'] = load_library('format')->datetime($value['date_added']);
-					$comments[$key]['profile_uri'] = '';
-				}
-			} else {
-				$comments = array();
-			}
-
-			$this->display->assign('comment_form_uri',$this->uri->create_uri(array(TASK_KEY=>'show_comment_form')).'/'.$pbi['id']);
-			
-			//subscription
-			if($this->display->get('is_logged')){
-				$filters = array();
-				$filters[] = array('field'=>'user_id', 'operator'=>'=', 'value'=>$this->permissions->get('id',''));
-				$filters[] = array('field'=>'pbi_id', 'operator'=>'=', 'value'=>$pbi['id']);
-				$limit = '1';
-				$this->display->assign('is_subscribed', (load_library('subscriptions')->get_all($filters, array(), array(), $limit)!=array()));
-
-				$this->display->assign('subscribe_uri',$this->uri->create_uri(array(TASK_KEY=>'subscribe')).'/'.$pbi['id']);
-			}
-
-			$this->display->assign('prev_vote',isset($_SESSION['votes'][$pbi['id']])?$_SESSION['votes'][$pbi['id']]:'');
-
-			$this->display->assign('can_vote',$this->permissions->can('pbi_vote', 'write'));
-			$this->display->assign('can_comment',$this->permissions->can('pbi_comment', 'write'));
-			if($this->permissions->can('pbi_comment', 'delete')){
-				$this->display->assign('can_comment_delete',true);
-				$this->display->assign('delete_comment_uri',$this->uri->create_uri(array(TASK_KEY=>'admin')).'/delete_comment/'.$pbi['id']);
-			} else {
-				$this->display->assign('can_comment_delete',false);
-			}
-
-			$owner = array('id'=>$pbi['id'],
-						   'table'=>'pbi',
-						   'field'=>'user_id',
-						   'field_id'=>'id',
-						   ); 
-			$this->display->assign('can_write',$this->permissions->can('pbi', 'write',$owner));
-
-			$this->display->assign('pbi', $pbi);
-			$this->display->assign('category', $category);
-			$this->display->assign('comments', $comments);
-
-			$this->display->assign('title', $pbi['name']);
-			$this->display('pbi');
-		}
-	}
-
-	public function web_subscribe(){
-		$filters = array();
-		$filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
-		$filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
-		$filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$this->uri->get_num(3));
-		$pbi = $this->pbi->get_record($filters)->get_info();
-		if(!isset($pbi['id']) || $pbi['id']!=$this->uri->get_num(3)){
-			$msg = 'PBI '.$this->uri->get_num(3).' not found !!';
-		} else {
-			$filters = array();
-			$filters[] = array('field'=>'user_id', 'operator'=>'=', 'value'=>$this->permissions->get('id',''));
-			$filters[] = array('field'=>'pbi_id', 'operator'=>'=', 'value'=>$pbi['id']);
-			$limit = '1';
-			$is_subscribed = (load_library('subscriptions')->get_all($filters, array(), array(), $limit)!=array());
-			if($is_subscribed){
-				$ret = load_library('subscriptions')->delete()->where($filters)->do_db();
-			} else {
-				$ret = load_library('subscriptions')->insert()->set('pbi_id',$pbi['id'])->set('user_id',$this->permissions->get('id',''))->do_db();
-			}
-			if($ret){
-				$msg = load_library('lang')->get($is_subscribed?'pbi_succesfully_unsubscribed':'pbi_succesfully_subscribed');
-			} else {
-				$msg = 'Problems while saving subscription! Please try again later.';
-			}
-		}
-
-		$this->config->set('display_headers',array('Content-Type'=> 'text/plain'));			//text/plain = only text file
-		$this->display->start();
-		echo $msg;
-		$this->display->end();
-	}
-
-	public function web_download(){
-		$filters = array();
-		$filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
-		$filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
-		$filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$this->uri->get_num(3));
-		$pbi = $this->pbi->get_record($filters)->get_info();
-		if(!isset($pbi['id']) || $pbi['id']!=$this->uri->get_num(3)){
-			//package doesn't exists
-			$this->display->assign('message', 'Package not found!');
-			$this->display('message');
-			return;
-		}
-
-		$this->load_library('pbi_release');
-		$filters = array();
-		$filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
-		$filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
-		$filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$this->uri->get_num(4));
-		$pbi_release = $this->pbi_release->get_record($filters)->get_info();
-		if(!isset($pbi_release['id']) || $pbi_release['id']!=$this->uri->get_num(4) || $pbi_release['pbi_id']!=$this->uri->get_num(3)){
-			//package doesn't exists
-			$this->display->assign('message', 'Package Release not found!');
-			$this->display('message');
-			return;
-		}
-		$this->display->assign('pbi', $pbi);
-		$this->display->assign('pbi_release', $pbi_release);
-		if($this->uri->get_num(5)>0){
-			$filters = array();
-			$filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
-			$filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$this->uri->get_num(5));
-			$mirror = $this->table_prototype->get_record($filters, 'mirror')->get_info();
-			if(!isset($mirror['id']) || $mirror['id']!=$this->uri->get_num(5)){
-				//package doesn't exists
-				$this->display->assign('message', 'Mirror not found!');
-				$this->display('message');
-				return;
-			}
-			$this->table_prototype->insert()->from('download')->set('pbi_id',$pbi['id'])->set('download_type_id','1')->set('mirror_id',$mirror['id'])->do_db();
-	
-			$filters = array();
-			$filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$pbi['id']);
-			$this->pbi->update()->set('total_download','total_download+1',true)->where()->do_db();
-	
-			$this->display->assign('mirror', $mirror);
-	
-			$this->display->assign('title', 'Downloading '.$pbi['name']);
-			$this->display('download');
-		} else {
-			//have to choose the mirror to use
-			$filters = array();
-			$filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
-			$filters[] = array('field'=>'last_update', 'operator'=>'>', 'value'=>$pbi['date_last_status_id']);
-			$mirror = $this->table_prototype->get_all($filters, array('name ASC','last_update DESC'), array(), '','mirror');
-			$this->display->assign('mirror', $mirror);
-			$this->display->assign('title', 'Downloading '.$pbi['name'].' - Choose a mirror');
-			$this->display('choose_mirror');
-		}
-	}
-	
-	/*
-	* This function will search the pbi database for a determinated value,
-	* and will show the page with the results
-	*/
-	public function web_search(){
-		$text = trim($this->display->get('search_text'));
-		$pbis_per_page = 20;
-		$order = $this->uri->get_num(5);
-		$order_mode = $this->uri->get_num(6);
-		$current_page = $this->uri->get_num(7,0);
-		switch(strtolower($order)){
-			case 'added':
-				$order_field = 'date_added';
-				break;
-			case 'rating':
-				$order_field = '(total_points+5)/(total_votes+1)';
-				break;
-			case 'download':
-				$order_field = 'total_download';
-				break;
-			case 'name':
-			default:
-				$order = 'name';
-				$order_field = 'name';
-		}
-		$order_mode = $order_mode=='desc'?'desc':'asc';
-		$order_mode = $order_mode=='desc'?'desc':'asc';
-
-		if($text==''){
-			$result['total_pbis'] = 0;
-			$this->display->assign('pbis', array());
-		} else {
-			$filters = array();
-			$filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
-			$filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
-			$filters[] = array('field'=>'name', 'operator'=>'LIKE', 'value'=>'%'.$text.'%');
-			list($result['total_pbis']) = $this->pbi->select()->fields(array('COUNT(*)'))->where($filters)->do_db()->db->fetch_row($this->pbi->last_result());
-			$this->display->assign('pbis', $this->pbi->get_all($filters, array($order_field.' '.$order_mode, 'name'),  array(), ($current_page*$pbis_per_page).','.$pbis_per_page));
-		}
-
-		$this->display->assign('result', $result);
-		$this->display->assign('order', $order);
-		$this->display->assign('order_mode', $order_mode);
-		$this->display->assign('pbis_per_page', $pbis_per_page);
-		$this->display->assign('current_page', $current_page);
-		$this->display->assign('breadcrumb_text', htmlentities($text));
-
-		$this->display->assign('pbi', load_library('lang')->get('search_page_title'));
-		$this->display->assign('title', load_library('lang')->get('search_page_title'));
-		$this->display('search');
-
-	}
-	
-	/************************************************
-	 *  ADMINISTRATION PART
-	 ************************************************/
-	private function _get_redirect_messages($key='', $uri=''){
-		if($key=='') return '';
-		$messages['home'] = sprintf(load_library('lang')->get('redirect_home'),$this->display->get('home_uri'));
-		$messages['previous'] = sprintf(load_library('lang')->get('redirect_home'),$uri);
-		
-		if(!isset($messages[$key])) return '';
-		else return $messages[$key];
-	}
-
-	public function web_admin(){
-		if(!$this->display->get('is_logged')){
-			$this->display->assign('task','login');
-			$this->web_admin_login();
-		} else {
-			$task = $this->uri->get_num(3);
-			if(method_exists($this,'web_admin_'.$task) && is_callable(array($this,'web_admin_'.$task))){
-				$this->display->assign('task',$task);
-				$this->{'web_admin_'.$task}();
-			} else {
-				$this->display->assign('task','home');
-				$this->web_home();
-			}
-		}
-	}
-
-	public function web_admin_login(){
-		$this->display->assign('registration_uri',$this->uri->create_uri(array(TASK_KEY=>'register')));
-		$this->display->assign('title', load_library('lang')->get('login_page_title'));
-		$user = '';
-		if(!$this->cookie_check()){
-			$this->display->assign('error',load_library('lang')->get('login_error_cookies'));
-		}elseif(isset($_POST['username']) && isset($_POST['pws'])){
-			$user = $_POST['username'];
-			$ret = $this->permissions->login($user, $_POST['pws']);
-			if($ret===false){
-				$this->display->assign('error',load_library('lang')->get('login_failed'));
-			} else {
-				$this->redirect($this->display->get('home_uri'), load_library('lang')->get('login_success').' '.$this->_get_redirect_messages('home'), 3, true, 'pbidir');
-				return true;
-			}
-		}
-		$this->display->assign('username',$user);
-		$this->display('login');
-	}
-	
-	public function web_register(){
-		$this->display->assign('registration_uri',$this->uri->create_uri(array(TASK_KEY=>'register')));
-		$user = '';
-		$email = '';
-		if(isset($_POST['username']) && isset($_POST['email'])){
-			$verification =& load_library('verification');
-			$user	= $_POST['username'];
-			$email	= $_POST['email'];
-			$vemail	= $_POST['vemail'];
-			$error	= array();
-			if($email!=$vemail){
-				$this->display->assign('error',load_library('lang')->get('registration_error_email_verification'));
-			} elseif(!$verification->email($email)){
-				$this->display->assign('error',load_library('lang')->get('registration_error_email_not_valid'));
-			} elseif(!$verification->alphanum($user)){
-				$this->display->assign('error',load_library('lang')->get('registration_error_user_alphanum'));
-			} elseif($this->permissions->user_exists($user)){
-				$this->display->assign('error',load_library('lang')->get('registration_error_user_exists'));
-			} else {
-				$ret = $this->permissions->register($user, $email);
-				if($ret===false){
-					$this->display->assign('error',load_library('lang')->get('registration_error_generic'));
-				} else {
-					$this->redirect($this->display->get('home_uri'), load_library('lang')->get('registration_success').' '.$this->_get_redirect_messages('home'), 10, true, 'pbidir');
-					return true;
-				}
-			}
-		}
-		$this->display->assign('title', load_library('lang')->get('registration_page_title'));
-		$this->display->assign('username',$user);
-		$this->display->assign('email',$email);
-		$this->display('registration');
-	}
-
-	public function web_admin_logout(){
-		$this->permissions->logout();
-		$this->redirect($this->display->get('home_uri'), load_library('lang')->get('login_logout_success').' '.$this->_get_redirect_messages('home'), 3, true, 'pbidir');
-	}
-	/************************************************
-	 *    COMMENTS
-	 ************************************************/
-	public function web_show_comment_form(){
-		$this->display->assign('comment_to_uri',$this->uri->create_uri(array(TASK_KEY=>'save_comment')).'/'.$this->uri->get_num(3));
-		$this->display('comment/form',false);
-	}
-	
-	public function web_admin_delete_comment(){
-		$this->config->set('display_headers',array('Content-Type'=> 'text/plain'));			//text/plain = only text file
-		$this->display->start();
-		if($this->pbi->delete_comment($this->uri->get_num(4),$this->uri->get_num(5))){
-			echo 'success';
-		} else {
-			echo 'Problems Deleting comment #'.$this->uri->get_num(5).' from pbi #'.$this->uri->get_num(4);
-		}
-		$this->display->end();
-	}
-
-	public function web_save_comment(){
-		//save the comment
-		$comment = trim($_POST['pbi_comment']);
-		$filters = array();
-		$filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
-		$filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
-		$filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$this->uri->get_num(3));
-		$pbi = $this->pbi->get_record($filters)->get_info();
-		if($this->ajax){
-			$this->config->set('display_headers',array('Content-Type'=> 'text/xml'));			//text/xml = xml file
-		} else {
-			$uri = $this->display->get('pbi_uri').'/'.$pbi['id'];
-		}
-		if($this->permissions->can('pbi_comment')){
-			if($comment!='' && $this->pbi->add_comment($pbi['id'], htmlentities($comment, ENT_COMPAT, 'UTF-8'), $this->permissions->get('id',''),$this->permissions->get('user',''), $this->permissions->IP())!==false){
-				if($this->ajax){
-					$xml = array('message'=>array(
-									'error'		=> '',
-									'cid'		=> $this->pbi->db->insert_id(),
-									'user'		=> $this->permissions->get('user',''),
-									'body'		=> htmlentities($comment, ENT_COMPAT, 'UTF-8'),
-									'date'		=> load_library('format')->datetime(),
-								)
-							);
-				} else {
-					$this->redirect($uri, 'Comment Saved Succesfully! '.$this->_get_redirect_messages('previous', $uri), 3, true, 'pbidir');
-				}
-			} else {
-				if($this->ajax){
-					$xml = array('message'=>array('error' => 'Problems saving your comment!  Try Again later!'));
-				} else {
-					$this->redirect($uri, 'Problems saving your comment! '.$this->_get_redirect_messages('previous', $uri), 3, true, 'pbidir');
-				}
-			}
-		} else {
-			if($this->ajax){
-				$xml = array('message'=>array('error' => 'You do not have permissions to send a comment !!'));
-			} else {
-				$this->redirect($uri, 'You do not have permissions to send a comment! '.$this->_get_redirect_messages('previous', $uri), 3, true, 'pbidir');
-			}
-		}
-		if($this->ajax){
-			$this->display->assign('xml',$xml);
-			$this->display('xml',false);
-		}
-	}
-	/************************************************
-	 *    RSS
-	 ************************************************/
-	 public function web_rss(){
-	 	load_library('feedcreator/include/feedcreator.class',false);
-		$rss = new UniversalFeedCreator();
-//		$rss->useCached();
-		$rss->description = 'pbiDIR - Your PC-BSD software';
-		$rss->link = 'http://ww.pbidir.com/';
-		$rss->syndicationURL = 'http://ww.pbidir.com/bt/rss/'.$this->uri->get_num(3,'pbi');
-
-	 	switch($this->uri->get_num(3,'pbi')){
-			case 'download.rss':
-			case 'download.xml':
-				$filters = array();
-				$filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
-				$filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
-				$group = array();
-				$order = array('total_download DESC');
-				$limit = 20;
-				$tmps = $this->pbi->get_raw($filters, $order, $group, $limit);
-				break;
-			case 'release.rss':
-			case 'release.xml':
-				$rss->title = 'pbiDIR - latest releases';
-				$filters = array();
-				$filters[] = array('field'=>'pbi_release.active', 'operator'=>'=', 'value'=>'y');
-				$filters[] = array('field'=>'pbi_release.current_status_id', 'operator'=>'=', 'value'=>'100');
-				$group = array('pbi_id');
-				$order = array('pbi_release.date_last_status_id DESC');
-				$limit = 20;
-				$join = array();
-				$fields = array('max(pbi_release.date_last_status_id) date_last_status_id', 'MAX(pbi_release.id) id');
-				$tmps =  load_library('pbi_release')->get_all($filters, $order, $group, $limit, '', $join, $fields);
-				break;
-			case 'pbi.rss':
-			case 'pbi.xml':
-			default:
-				$rss->title = 'pbiDIR - latest pbi';
-				$filters = array();
-				$filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
-				$filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
-				$group = array();
-				$order = array('date_added DESC');
-				$limit = 20;
-				$tmps = $this->pbi->get_raw($filters, $order, $group, $limit);
-				break;
-		}
-		$pbi_uri = $this->display->get('pbi_uri');
-		foreach($tmps as $pbi) {
-			$item = new FeedItem();
-
-			$item->title = isset($pbi['name'])?$pbi['name']:$pbi['pbi'].' '.$pbi['version'];
-			$item->link = $pbi_uri.'/'.$pbi['id'];
-			$item->description = $pbi['summary'];
-			$item->date = strtotime($pbi['date_last_status_id']);
-			$item->source = 'http://www.pbidir.com';
-			if(isset($pbi['vendor'])){
-				$item->author = $pbi['vendor'];
-			}
-			
-			$rss->addItem($item);
-		}
-		$rss->outputFeed('RSS1.0'); 
-	}
-}
+<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
+// ------------------------------------------------------------------------
+
+class start extends bibivu{
+	public $ajax = false;
+	/**
+	 * Initialize the default class
+	 *
+	 * @access	private
+	 * @return	void
+	 */ 
+	public function __construct(){
+		parent::__construct();
+		session_start();
+		$task = $this->uri->get(TASK_KEY, '');
+		switch($task){
+			case 'update':
+				$this->load_library($task);
+				return true;
+				break;
+			case 'mirrors':
+				set_time_limit(0);
+				$mirrors = load_library('mirror');
+				$tmps = $mirrors->get_all(array(),array('last_update DESC'));
+				if(isset($_GET['update'])){
+					foreach($tmps as $key=>$value){
+						$filters = array();
+						$filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
+						$filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$value['id']);
+						$dt = $mirrors->get_record($filters)->update_mirror('PBI/.zupdate');
+						if($this->is_web()){
+							echo $value['id'].': '.$value['name'].' - '.$value['url'].' => '.$dt.'<br />';
+							flush();
+						}
+					}
+					return true;
+				}
+				break;
+			case 'lang':
+				load_library('lang')->set_lang($this->uri->get_num(3));
+				$task = 'home';
+				break;
+		}
+
+		$this->ajax	 = isset($_POST['ajax']) || isset($_GET['ajax']);
+		$this->load_library('table_prototype');
+		$this->load_library('pbi');			//this is enough
+		$this->load_library('permissions');
+		
+		if($this->permissions->is_logged()){
+			load_library('lang')->set_lang($this->permissions->get('lang',''));
+		}
+
+		$this->display->assign('is_logged',$this->permissions->is_logged());
+		$this->display->assign('pbi_uri',$this->uri->create_uri(array(TASK_KEY=>'pbi')));
+		load_library('menu')->create_menu($this->display);
+
+		if(method_exists($this,'web_'.$task) && is_callable(array($this,'web_'.$task))){
+			$this->display->assign('task',$task);
+			$this->{'web_'.$task}();
+		} else {
+			if($this->uri->get_num(1)==''){
+				$this->display->assign('task','home');
+				$this->web_home();
+			} else {
+				$this->display->assign('search_text',trim(str_replace('/',' ', at implode(' ', $this->uri->get_GETnum()))));
+				$this->display->assign('task','search');
+				$this->web_search();
+			}
+		}
+	}
+	
+	public function display($page='home', $show_head_foot=true){
+		$this->display->start($show_head_foot,'pbidir');
+		$this->display->show('pbidir/'.$page);
+		$this->display->end($show_head_foot,'pbidir');
+	}
+
+	public function web_home(){
+		$filters = array();
+		$filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
+		$filters[] = array('field'=>'show_on_site', 'operator'=>'=', 'value'=>'y');
+		$group = array();
+		$order = array('name');
+		$limit = '';
+		$this->display->assign('categories', $this->table_prototype->get_raw($filters, $order, $group, $limit,'category'));
+
+		$filters = array();
+		$filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
+		$filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
+		$group = array('pbi_id');
+		$order = array('date_last_status_id DESC');
+		$limit = 20;
+		$join = array();
+		$fields = array('max(date_last_status_id) date_last_status_id', 'MAX(id) id');
+		$this->display->assign('latest_releases', load_library('pbi_release')->get_all($filters, $order, $group, $limit, '', $join, $fields));
+		
+		$filters = array();
+		$filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
+		$filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
+		$group = array();
+		$order = array('date_added DESC');
+		$limit = 20;
+		$this->display->assign('latest', $this->pbi->get_raw($filters, $order, $group, $limit));
+
+		$filters = array();
+		$filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
+		$filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
+		$group = array();
+		$order = array('total_download DESC');
+		$limit = 20;
+		$this->display->assign('most_download', $this->pbi->get_raw($filters, $order, $group, $limit));
+
+		$this->display->assign('title', 'Your PC-BSD software');
+		$this->display('home');
+	}
+
+	public function web_contact_us(){
+		$this->display->assign('title', 'Contact Us');
+		$this->display('contact_us');
+	}
+	
+	public function web_category(){
+		$filters = array();
+		$filters[] = array('field'=>'web_alias', 'operator'=>'=', 'value'=>$this->uri->get_num(3));
+		$category = $this->table_prototype->get_record($filters,'category')->get_info();
+		if(!isset($category['id']) || $category['web_alias']!=$this->uri->get_num(3)){
+			//package doesn't exists
+			$this->display->assign('message', 'Category not found!');
+			$this->display('message');
+			return;
+		}
+
+		$pbis_per_page = 20;
+		$order = $this->uri->get_num(4, 'name');
+		$order_mode = $this->uri->get_num(5, 'asc');
+		$current_page = $this->uri->get_num(6,0);
+
+		switch(strtolower($order)){
+			case 'added':
+				$order_field = 'date_added';
+				break;
+			case 'rating':
+				$order_field = '(total_points+5)/(total_votes+1)';
+				break;
+			case 'download':
+				$order_field = 'total_download';
+				break;
+			case 'name':
+			default:
+				$order='name';
+				$order_field = 'name';
+		}
+		$order_mode = $order_mode=='desc'?'desc':'asc';
+
+		$filters = array();
+		$filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
+		$filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
+		$filters[] = array('field'=>'category_id', 'operator'=>'=', 'value'=>$category['id']);
+		list($category['total_pbis']) = $this->pbi->select()->fields(array('COUNT(*)'))->where($filters)->do_db()->db->fetch_row($this->pbi->last_result());
+
+		$this->display->assign('result', $category);
+		$this->display->assign('breadcrumb_text', $category['name']);
+		$pbis = $this->pbi->get_all($filters, array($order_field.' '.$order_mode, 'name'), array(), ($current_page*$pbis_per_page).','.$pbis_per_page);
+		$this->display->assign('pbis', $pbis);
+
+		$this->display->assign('order', $order);
+		$this->display->assign('order_mode', $order_mode);
+		$this->display->assign('pbis_per_page', $pbis_per_page);
+		$this->display->assign('current_page', $current_page);
+
+		$this->display->assign('title', $category['name']);
+		$this->display('search');
+	}
+
+	public function web_pbi(){
+		if(!is_numeric($this->uri->get_num(3))){
+			$this->redirect($this->display->get('home_uri'), 'Error opening this page', 3, true, 'pbidir');
+			return;
+		}
+		$filters = array();
+		$filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
+		$filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
+		$filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$this->uri->get_num(3));
+		$pbi = $this->pbi->get_record($filters)->get_info();
+		if(!isset($pbi['id']) || $pbi['id']!=$this->uri->get_num(3)){
+			//package doesn't exists
+			$this->display->assign('message', 'Package '.$this->uri->get_num(3).' not found!');
+			$this->display('message');
+			return;
+		}
+		if($this->uri->get_num(4)=='vote' && $this->uri->get_num(5)>0 && $this->permissions->can('pbi_vote')){
+			//voting the pbi
+			//return a normal TEXT message
+			$vote = $this->uri->get_num(5);
+			if($this->ajax){
+				$this->config->set('display_headers',array('Content-Type'=> 'text/plain'));			//text/plain = only text file
+				$this->display->start();
+			} else {
+				$uri = $this->display->get('pbi_uri').'/'.$pbi['id'];
+			}
+			if($this->pbi->vote_pbi($pbi['id'],$vote)){
+				if($this->ajax){
+					$ret = $this->pbi->get_vote($pbi['id']);
+					if(is_numeric($ret)){
+						echo number_format($ret, 2, '.', '');
+					} else {
+						echo 0;
+					}
+				} else {
+					$this->redirect($uri, 'Vote Saved Succesfully! '.$this->_get_redirect_messages('previous', $uri), 3, true, 'pbidir');
+				}
+			} else {
+				if($this->ajax){
+					echo 'problems saving your vote!';
+				} else {
+					$this->redirect($uri, 'Problems saving your vote! '.$this->_get_redirect_messages('previous', $uri), 3, true, 'pbidir');
+				}
+			}
+			if($this->ajax){
+				$this->display->end();
+			}
+			return;
+		} else {
+			$filters = array();
+			$filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$pbi['category_id']);
+			$category = load_library('category')->get_record($filters)->get_info();
+
+			$filters = array();
+			$filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
+			$filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
+			$filters[] = array('field'=>'pbi_id', 'operator'=>'=', 'value'=>$pbi['id']);
+			$limit = '';	//was 3
+			$this->display->assign('pbi_releases', load_library('pbi_release')->get_all($filters, array('date_added DESC'), array(), $limit));
+			
+			$filters = array();
+			$filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
+			$filters[] = array('field'=>'pbi_id', 'operator'=>'=', 'value'=>$pbi['id']);
+			$this->display->assign('pbi_images', load_library('pbi_image')->get_all($filters, array('`order`')));
+			
+			$filters = array();
+			$filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
+			$filters[] = array('field'=>'pbi_id', 'operator'=>'=', 'value'=>$pbi['id']);
+			$comments = $this->table_prototype->get_all($filters, array('date_added DESC'), array(), 20,'pbi_comment');
+			if(is_array($comments)){
+				foreach($comments as $key=>$value){
+					$comments[$key]['date'] = load_library('format')->datetime($value['date_added']);
+					$comments[$key]['profile_uri'] = '';
+				}
+			} else {
+				$comments = array();
+			}
+
+			$this->display->assign('comment_form_uri',$this->uri->create_uri(array(TASK_KEY=>'show_comment_form')).'/'.$pbi['id']);
+			
+			//subscription
+			if($this->display->get('is_logged')){
+				$filters = array();
+				$filters[] = array('field'=>'user_id', 'operator'=>'=', 'value'=>$this->permissions->get('id',''));
+				$filters[] = array('field'=>'pbi_id', 'operator'=>'=', 'value'=>$pbi['id']);
+				$limit = '1';
+				$this->display->assign('is_subscribed', (load_library('subscriptions')->get_all($filters, array(), array(), $limit)!=array()));
+
+				$this->display->assign('subscribe_uri',$this->uri->create_uri(array(TASK_KEY=>'subscribe')).'/'.$pbi['id']);
+			}
+
+			$this->display->assign('prev_vote',isset($_SESSION['votes'][$pbi['id']])?$_SESSION['votes'][$pbi['id']]:'');
+
+			$this->display->assign('can_vote',$this->permissions->can('pbi_vote', 'write'));
+			$this->display->assign('can_comment',$this->permissions->can('pbi_comment', 'write'));
+			if($this->permissions->can('pbi_comment', 'delete')){
+				$this->display->assign('can_comment_delete',true);
+				$this->display->assign('delete_comment_uri',$this->uri->create_uri(array(TASK_KEY=>'admin')).'/delete_comment/'.$pbi['id']);
+			} else {
+				$this->display->assign('can_comment_delete',false);
+			}
+
+			$owner = array('id'=>$pbi['id'],
+						   'table'=>'pbi',
+						   'field'=>'user_id',
+						   'field_id'=>'id',
+						   ); 
+			$this->display->assign('can_write',$this->permissions->can('pbi', 'write',$owner));
+
+			$this->display->assign('pbi', $pbi);
+			$this->display->assign('category', $category);
+			$this->display->assign('comments', $comments);
+
+			$this->display->assign('title', $pbi['name']);
+			$this->display('pbi');
+		}
+	}
+
+	public function web_subscribe(){
+		$filters = array();
+		$filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
+		$filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
+		$filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$this->uri->get_num(3));
+		$pbi = $this->pbi->get_record($filters)->get_info();
+		if(!isset($pbi['id']) || $pbi['id']!=$this->uri->get_num(3)){
+			$msg = 'PBI '.$this->uri->get_num(3).' not found !!';
+		} else {
+			$filters = array();
+			$filters[] = array('field'=>'user_id', 'operator'=>'=', 'value'=>$this->permissions->get('id',''));
+			$filters[] = array('field'=>'pbi_id', 'operator'=>'=', 'value'=>$pbi['id']);
+			$limit = '1';
+			$is_subscribed = (load_library('subscriptions')->get_all($filters, array(), array(), $limit)!=array());
+			if($is_subscribed){
+				$ret = load_library('subscriptions')->delete()->where($filters)->do_db();
+			} else {
+				$ret = load_library('subscriptions')->insert()->set('pbi_id',$pbi['id'])->set('user_id',$this->permissions->get('id',''))->do_db();
+			}
+			if($ret){
+				$msg = load_library('lang')->get($is_subscribed?'pbi_succesfully_unsubscribed':'pbi_succesfully_subscribed');
+			} else {
+				$msg = 'Problems while saving subscription! Please try again later.';
+			}
+		}
+
+		$this->config->set('display_headers',array('Content-Type'=> 'text/plain'));			//text/plain = only text file
+		$this->display->start();
+		echo $msg;
+		$this->display->end();
+	}
+
+	public function web_download(){
+		$filters = array();
+		$filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
+		$filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
+		$filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$this->uri->get_num(3));
+		$pbi = $this->pbi->get_record($filters)->get_info();
+		if(!isset($pbi['id']) || $pbi['id']!=$this->uri->get_num(3)){
+			//package doesn't exists
+			$this->display->assign('message', 'Package not found!');
+			$this->display('message');
+			return;
+		}
+
+		$this->load_library('pbi_release');
+		$filters = array();
+		$filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
+		$filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
+		$filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$this->uri->get_num(4));
+		$pbi_release = $this->pbi_release->get_record($filters)->get_info();
+		if(!isset($pbi_release['id']) || $pbi_release['id']!=$this->uri->get_num(4) || $pbi_release['pbi_id']!=$this->uri->get_num(3)){
+			//package doesn't exists
+			$this->display->assign('message', 'Package Release not found!');
+			$this->display('message');
+			return;
+		}
+		$this->display->assign('pbi', $pbi);
+		$this->display->assign('pbi_release', $pbi_release);
+		if($this->uri->get_num(5)>0){
+			$filters = array();
+			$filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
+			$filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$this->uri->get_num(5));
+			$mirror = $this->table_prototype->get_record($filters, 'mirror')->get_info();
+			if(!isset($mirror['id']) || $mirror['id']!=$this->uri->get_num(5)){
+				//package doesn't exists
+				$this->display->assign('message', 'Mirror not found!');
+				$this->display('message');
+				return;
+			}
+			$this->table_prototype->insert()->from('download')->set('pbi_id',$pbi['id'])->set('download_type_id','1')->set('mirror_id',$mirror['id'])->do_db();
+	
+			$filters = array();
+			$filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$pbi['id']);
+			$this->pbi->update()->set('total_download','total_download+1',true)->where()->do_db();
+	
+			$this->display->assign('mirror', $mirror);
+	
+			$this->display->assign('title', 'Downloading '.$pbi['name']);
+			$this->display('download');
+		} else {
+			//have to choose the mirror to use
+			$filters = array();
+			$filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
+			$filters[] = array('field'=>'last_update', 'operator'=>'>', 'value'=>$pbi['date_last_status_id']);
+			$mirror = $this->table_prototype->get_all($filters, array('name ASC','last_update DESC'), array(), '','mirror');
+			$this->display->assign('mirror', $mirror);
+			$this->display->assign('title', 'Downloading '.$pbi['name'].' - Choose a mirror');
+			$this->display('choose_mirror');
+		}
+	}
+	
+	/*
+	* This function will search the pbi database for a determinated value,
+	* and will show the page with the results
+	*/
+	public function web_search(){
+		$text = trim($this->display->get('search_text'));
+		$pbis_per_page = 20;
+		$order = $this->uri->get_num(5);
+		$order_mode = $this->uri->get_num(6);
+		$current_page = $this->uri->get_num(7,0);
+		switch(strtolower($order)){
+			case 'added':
+				$order_field = 'date_added';
+				break;
+			case 'rating':
+				$order_field = '(total_points+5)/(total_votes+1)';
+				break;
+			case 'download':
+				$order_field = 'total_download';
+				break;
+			case 'name':
+			default:
+				$order = 'name';
+				$order_field = 'name';
+		}
+		$order_mode = $order_mode=='desc'?'desc':'asc';
+		$order_mode = $order_mode=='desc'?'desc':'asc';
+
+		if($text==''){
+			$result['total_pbis'] = 0;
+			$this->display->assign('pbis', array());
+		} else {
+			$filters = array();
+			$filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
+			$filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
+			$filters[] = array('field'=>'name', 'operator'=>'LIKE', 'value'=>'%'.$text.'%');
+			list($result['total_pbis']) = $this->pbi->select()->fields(array('COUNT(*)'))->where($filters)->do_db()->db->fetch_row($this->pbi->last_result());
+			$this->display->assign('pbis', $this->pbi->get_all($filters, array($order_field.' '.$order_mode, 'name'),  array(), ($current_page*$pbis_per_page).','.$pbis_per_page));
+		}
+
+		$this->display->assign('result', $result);
+		$this->display->assign('order', $order);
+		$this->display->assign('order_mode', $order_mode);
+		$this->display->assign('pbis_per_page', $pbis_per_page);
+		$this->display->assign('current_page', $current_page);
+		$this->display->assign('breadcrumb_text', htmlentities($text));
+
+		$this->display->assign('pbi', load_library('lang')->get('search_page_title'));
+		$this->display->assign('title', load_library('lang')->get('search_page_title'));
+		$this->display('search');
+
+	}
+	
+	/************************************************
+	 *  ADMINISTRATION PART
+	 ************************************************/
+	private function _get_redirect_messages($key='', $uri=''){
+		if($key=='') return '';
+		$messages['home'] = sprintf(load_library('lang')->get('redirect_home'),$this->display->get('home_uri'));
+		$messages['previous'] = sprintf(load_library('lang')->get('redirect_home'),$uri);
+		
+		if(!isset($messages[$key])) return '';
+		else return $messages[$key];
+	}
+
+	public function web_admin(){
+		if(!$this->display->get('is_logged')){
+			$this->display->assign('task','login');
+			$this->web_admin_login();
+		} else {
+			$task = $this->uri->get_num(3);
+			if(method_exists($this,'web_admin_'.$task) && is_callable(array($this,'web_admin_'.$task))){
+				$this->display->assign('task',$task);
+				$this->{'web_admin_'.$task}();
+			} else {
+				$this->display->assign('task','home');
+				$this->web_home();
+			}
+		}
+	}
+
+	public function web_admin_login(){
+		$this->display->assign('registration_uri',$this->uri->create_uri(array(TASK_KEY=>'register')));
+		$this->display->assign('title', load_library('lang')->get('login_page_title'));
+		$user = '';
+		if(!$this->cookie_check()){
+			$this->display->assign('error',load_library('lang')->get('login_error_cookies'));
+		}elseif(isset($_POST['username']) && isset($_POST['pws'])){
+			$user = $_POST['username'];
+			$ret = $this->permissions->login($user, $_POST['pws']);
+			if($ret===false){
+				$this->display->assign('error',load_library('lang')->get('login_failed'));
+			} else {
+				$this->redirect($this->display->get('home_uri'), load_library('lang')->get('login_success').' '.$this->_get_redirect_messages('home'), 3, true, 'pbidir');
+				return true;
+			}
+		}
+		$this->display->assign('username',$user);
+		$this->display('login');
+	}
+	
+	public function web_register(){
+		$this->display->assign('registration_uri',$this->uri->create_uri(array(TASK_KEY=>'register')));
+		$user = '';
+		$email = '';
+		if(isset($_POST['username']) && isset($_POST['email'])){
+			$verification =& load_library('verification');
+			$user	= $_POST['username'];
+			$email	= $_POST['email'];
+			$vemail	= $_POST['vemail'];
+			$error	= array();
+			if($email!=$vemail){
+				$this->display->assign('error',load_library('lang')->get('registration_error_email_verification'));
+			} elseif(!$verification->email($email)){
+				$this->display->assign('error',load_library('lang')->get('registration_error_email_not_valid'));
+			} elseif(!$verification->alphanum($user)){
+				$this->display->assign('error',load_library('lang')->get('registration_error_user_alphanum'));
+			} elseif($this->permissions->user_exists($user)){
+				$this->display->assign('error',load_library('lang')->get('registration_error_user_exists'));
+			} else {
+				$ret = $this->permissions->register($user, $email);
+				if($ret===false){
+					$this->display->assign('error',load_library('lang')->get('registration_error_generic'));
+				} else {
+					$this->redirect($this->display->get('home_uri'), load_library('lang')->get('registration_success').' '.$this->_get_redirect_messages('home'), 10, true, 'pbidir');
+					return true;
+				}
+			}
+		}
+		$this->display->assign('title', load_library('lang')->get('registration_page_title'));
+		$this->display->assign('username',$user);
+		$this->display->assign('email',$email);
+		$this->display('registration');
+	}
+
+	public function web_admin_logout(){
+		$this->permissions->logout();
+		$this->redirect($this->display->get('home_uri'), load_library('lang')->get('login_logout_success').' '.$this->_get_redirect_messages('home'), 3, true, 'pbidir');
+	}
+	/************************************************
+	 *    COMMENTS
+	 ************************************************/
+	public function web_show_comment_form(){
+		$this->display->assign('comment_to_uri',$this->uri->create_uri(array(TASK_KEY=>'save_comment')).'/'.$this->uri->get_num(3));
+		$this->display('comment/form',false);
+	}
+	
+	public function web_admin_delete_comment(){
+		$this->config->set('display_headers',array('Content-Type'=> 'text/plain'));			//text/plain = only text file
+		$this->display->start();
+		if($this->pbi->delete_comment($this->uri->get_num(4),$this->uri->get_num(5))){
+			echo 'success';
+		} else {
+			echo 'Problems Deleting comment #'.$this->uri->get_num(5).' from pbi #'.$this->uri->get_num(4);
+		}
+		$this->display->end();
+	}
+
+	public function web_save_comment(){
+		//save the comment
+		$comment = trim($_POST['pbi_comment']);
+		$filters = array();
+		$filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
+		$filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
+		$filters[] = array('field'=>'id', 'operator'=>'=', 'value'=>$this->uri->get_num(3));
+		$pbi = $this->pbi->get_record($filters)->get_info();
+		if($this->ajax){
+			$this->config->set('display_headers',array('Content-Type'=> 'text/xml'));			//text/xml = xml file
+		} else {
+			$uri = $this->display->get('pbi_uri').'/'.$pbi['id'];
+		}
+		if($this->permissions->can('pbi_comment')){
+			if($comment!='' && $this->pbi->add_comment($pbi['id'], htmlentities($comment, ENT_COMPAT, 'UTF-8'), $this->permissions->get('id',''),$this->permissions->get('user',''), $this->permissions->IP())!==false){
+				if($this->ajax){
+					$xml = array('message'=>array(
+									'error'		=> '',
+									'cid'		=> $this->pbi->db->insert_id(),
+									'user'		=> $this->permissions->get('user',''),
+									'body'		=> htmlentities($comment, ENT_COMPAT, 'UTF-8'),
+									'date'		=> load_library('format')->datetime(),
+								)
+							);
+				} else {
+					$this->redirect($uri, 'Comment Saved Succesfully! '.$this->_get_redirect_messages('previous', $uri), 3, true, 'pbidir');
+				}
+			} else {
+				if($this->ajax){
+					$xml = array('message'=>array('error' => 'Problems saving your comment!  Try Again later!'));
+				} else {
+					$this->redirect($uri, 'Problems saving your comment! '.$this->_get_redirect_messages('previous', $uri), 3, true, 'pbidir');
+				}
+			}
+		} else {
+			if($this->ajax){
+				$xml = array('message'=>array('error' => 'You do not have permissions to send a comment !!'));
+			} else {
+				$this->redirect($uri, 'You do not have permissions to send a comment! '.$this->_get_redirect_messages('previous', $uri), 3, true, 'pbidir');
+			}
+		}
+		if($this->ajax){
+			$this->display->assign('xml',$xml);
+			$this->display('xml',false);
+		}
+	}
+	/************************************************
+	 *    RSS
+	 ************************************************/
+	 public function web_rss(){
+	 	load_library('feedcreator/include/feedcreator.class',false);
+		$rss = new UniversalFeedCreator();
+//		$rss->useCached();
+		$rss->description = 'pbiDIR - Your PC-BSD software';
+		$rss->link = 'http://ww.pbidir.com/';
+		$rss->syndicationURL = 'http://ww.pbidir.com/bt/rss/'.$this->uri->get_num(3,'pbi');
+
+	 	switch($this->uri->get_num(3,'pbi')){
+			case 'download.rss':
+			case 'download.xml':
+				$filters = array();
+				$filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
+				$filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
+				$group = array();
+				$order = array('total_download DESC');
+				$limit = 20;
+				$tmps = $this->pbi->get_raw($filters, $order, $group, $limit);
+				break;
+			case 'release.rss':
+			case 'release.xml':
+				$rss->title = 'pbiDIR - latest releases';
+				$filters = array();
+				$filters[] = array('field'=>'pbi_release.active', 'operator'=>'=', 'value'=>'y');
+				$filters[] = array('field'=>'pbi_release.current_status_id', 'operator'=>'=', 'value'=>'100');
+				$group = array('pbi_id');
+				$order = array('pbi_release.date_last_status_id DESC');
+				$limit = 20;
+				$join = array();
+				$fields = array('max(pbi_release.date_last_status_id) date_last_status_id', 'MAX(pbi_release.id) id');
+				$tmps =  load_library('pbi_release')->get_all($filters, $order, $group, $limit, '', $join, $fields);
+				break;
+			case 'pbi.rss':
+			case 'pbi.xml':
+			default:
+				$rss->title = 'pbiDIR - latest pbi';
+				$filters = array();
+				$filters[] = array('field'=>'active', 'operator'=>'=', 'value'=>'y');
+				$filters[] = array('field'=>'current_status_id', 'operator'=>'=', 'value'=>'100');
+				$group = array();
+				$order = array('date_added DESC');
+				$limit = 20;
+				$tmps = $this->pbi->get_raw($filters, $order, $group, $limit);
+				break;
+		}
+		$pbi_uri = $this->display->get('pbi_uri');
+		foreach($tmps as $pbi) {
+			$item = new FeedItem();
+
+			$item->title = isset($pbi['name'])?$pbi['name']:$pbi['pbi'].' '.$pbi['version'];
+			$item->link = $pbi_uri.'/'.$pbi['id'];
+			$item->description = $pbi['summary'];
+			$item->date = strtotime($pbi['date_last_status_id']);
+			$item->source = 'http://www.pbidir.com';
+			if(isset($pbi['vendor'])){
+				$item->author = $pbi['vendor'];
+			}
+			
+			$rss->addItem($item);
+		}
+		$rss->outputFeed('RSS1.0'); 
+	}
+}
 ?>
\ No newline at end of file

Modified: websites/pbidir.com/bibivu/etc/periodic/hourly/upd_mirr.php
===================================================================
--- websites/pbidir.com/bibivu/etc/periodic/hourly/upd_mirr.php	2008-03-09 20:53:17 UTC (rev 1568)
+++ websites/pbidir.com/bibivu/etc/periodic/hourly/upd_mirr.php	2008-03-09 21:04:59 UTC (rev 1569)
@@ -1,12 +1,11 @@
-<?php
-if (!isset($_SERVER['argc']) || $_SERVER['argc'] == 0 || $_SERVER['argv'][0] != $_SERVER['PHP_SELF']){
-	//called from the web.. BAD BAD BAD BOYS
-	header('location: /');
-	exit(0);
-}
-
-$_GET['bt'] = 'mirrors';
-$_GET['update'] = true;
-require_once dirname(__FILE__).'/../../index_file.conf.php';
-require_once $index_file;//'index.php';
+<?php
+if (!isset($_SERVER['argc']) || $_SERVER['argc'] == 0 || $_SERVER['argv'][0] != $_SERVER['PHP_SELF']){
+	//called from the web.. BAD BAD BAD BOYS
+	header('location: /');
+	exit(0);
+}
+$_GET['bt'] = 'mirrors';
+$_GET['update'] = true;
+require_once dirname(__FILE__).'/../../index_file.conf.php';
+require_once $index_file;//'index.php';
 ?>
\ No newline at end of file



More information about the Commits mailing list