Location: PHPKode > projects > OSShare > osshare-project-v1.0.1/app/controllers/pages_controller.php
<?php
/* SVN FILE: $Id: pages_controller.php 4787 2007-04-05 18:10:39Z phpnut $ */

/**
 * Short description for file.
 *
 * This file is application-wide controller file. You can put all
 * application-wide controller-related methods here.
 *
 * PHP versions 4 and 5
 /*
OsShare v1 , 
Coded By Paimpozhil B. , SaravanaKumar M.S.
 *
 * CakePHP(tm) :  Rapid Development Framework <http://www.cakephp.org/>
 * Copyright 2005-2007, Cake Software Foundation, Inc.
 *								1785 E. Sahara Avenue, Suite 490-204
 *								Las Vegas, Nevada 89104
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @filesource
 * @copyright		Copyright 2005-2007, Cake Software Foundation, Inc.
 * @link				http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
 * @package			cake
 * @subpackage		cake.cake.libs.controller
 * @since			CakePHP(tm) v 0.2.9
 * @version			$Revision: 4787 $
 * @modifiedby		$LastChangedBy: phpnut $
 * @lastmodified	$Date: 2007-04-05 13:10:39 -0500 (Thu, 05 Apr 2007) $
 * @license			http://www.opensource.org/licenses/mit-license.php The MIT License
 */

/**
 * Short description for class.
 *
 * This file is application-wide controller file. You can put all
 * application-wide controller-related methods here.
 *
 * Add your application-wide methods in the class below, your controllers
 * will inherit them.
 *
 * @package		cake
 * @subpackage	cake.cake.libs.controller
 */
class PagesController extends AppController{

/**
 * Enter description here..
 *
 * @var unknown_type
 */
	 var $name = 'Pages';
	

/**
 * Enter description here...
 *
 * @var unknown_type
 */
	 var $helpers = array('Html','Form','Cache','Javascript');

/**
 * This controller does not use a model
 *
 * @var $uses
 */
	var $uses = array("Video","Category","Sitesetting","Rating","Linksite");

/**
 * Displays a view
 *
 */
	 function display() {
		  if (!func_num_args()) {
				$this->redirect('/');
		  }

		  $path=func_get_args();

		  if (!count($path)) {
				$this->redirect('/');
		  }

		  $count  =count($path);
		  $page   =null;
		  $subpage=null;
		  $title  =null;

		  if (!empty($path[0])) {
				$page = $path[0];
		  }

		  if (!empty($path[1])) {
				$subpage = $path[1];
		  }

		  if (!empty($path[$count - 1])) {
				$title = ucfirst($path[$count - 1]);
		  }

		  $this->set('page', $page);
		  $this->set('subpage', $subpage);
		  $this->set('title', $title);
		  
		    if (method_exists($this, $page)) {
  			  $this->$page();
			  } 
  
		  $this->render(join('/', $path));
	 }
	 
	 function contactus()
	 {
		$this->set('email',$this->ssettings['AdminEmail']);
	 }
	 
	 function privacy()
	 {
	 	$this->set('siteurl',str_replace('www.', '', $_SERVER['HTTP_HOST']));
	 }
	 
	 function aboutus()
	 {

	 }
	 
	 function terms()
	 {
	 	$this->set('siteurl',str_replace('www.', '', $_SERVER['HTTP_HOST']));
	 }
	 
	 
	 function home()
	 {
		
			$this->dolayout();				
	 		//latest With Cache
			$videos = Cache::read('latestvideos');
			if($videos==false)
			{
			$videos = $this->Video->findall("`Video`.is_encoded = 1",null,"`Video`.id DESC",5,1,null);
			$videos = $this->fix_width($videos,'Video','name',10);
			$videos = $this->fix_width($videos,'User','username',5);
			Cache::write('latestvideos',$videos,'+5 minute');
			}
			$this->set('lvideos',$videos);
			
			//most viewed with cache
			$videos = Cache::read('mostviewed');
			if($videos==false)
			{
			$videos = $this->Video->findall("`Video`.is_encoded = 1 ",null,"`Video`.views DESC",5,1,null);
			$videos = $this->fix_width($videos,'Video','name',10);
			$videos = $this->fix_width($videos,'User','username',5);
			Cache::write('mostviewed',$videos,'+20 minute');
			}
			
			$this->set('vvideos',$videos);
			
			//most rated with cache
			
			$videos = Cache::read('mostrated');
			if($videos==false)
			{
			$videos =  $this->Video->Rating->findAll("`Video`.is_encoded = 1  GROUP BY `Rating`.video_id","*,sum(`Rating`.rating) as maxrate,Avg(`Rating`.rating) as avgrate ","avgrate DESC,maxrate DESC" ,5,NULL,0);
				$videos = $this->fix_width($videos,'Video','name',10);
			$videos = $this->fix_width($videos,'User','username',5);
			Cache::write('mostrated',$videos,'+20 minute');
			}
			
			$this->set('rvideos',$videos);
			
			//most viewed channels with cache
			$tvvideos = Cache::read('mostviewedchannels');
			if($tvvideos==false)
			{
			$tvvideos = $this->Video->findall("`Video`.is_encoded = 1  GROUP BY `User`.id "," *,sum(`Video`.views) as totalviews","totalviews DESC",5,1,null);
			$tvvideos = $this->fix_width($tvvideos,'Video','name',10);
			$tvvideos = $this->fix_width($tvvideos,'User','username',5);
			Cache::write('mostviewedchannels',$tvvideos,'+20 minute');
			//debug($tvvideos);
			}
			$this->set('tvvideos',$tvvideos);
			
			//randomchannels with Cache
			$rchannels = Cache::read('randomchannels');
			if($rchannels==false)
			{
			$rchannels = $this->Video->findall("1 GROUP BY `User`.id "," *"," RAND() ",5,1,null);
			$rchannels = $this->fix_width($rchannels,'Video','name',10);
			$rchannels = $this->fix_width($rchannels,'User','username',8);
			Cache::write('randomchannels',$rchannels,'+20 minute');
			}
			$this->set('rchannels',$rchannels);

			
			//tags
			
			$collected_tags = Cache::read('latesttags');
			if($collected_tags == false)
			{
			$tags = $this->Video->findall("NOT (`Video`.tags = '') ",null,"`Video`.id DESC",10,1,null);
			$collected_tags = " ";
			
			
			
			foreach ($tags as $tag)
			{
				$collected_tags .= $tag["Video"]["tags"] . " ";  
			}
			Cache::write('latesttags',$collected_tags,'+1 hour');
			}
			
			
			$this->set('settings',$this->ssettings);

			
			$this->set('tags',$collected_tags);
			
			$cate = Cache::read('categories');
			if($cate == false){
			$cate = $this->Category->findall(NULL,NULL,NULL,NULL,NULL,0);
			$cate = $this->fix_width($cate,'Category','name',10);
			Cache::write('categories',$cate,'+10 minute');
			}
			$this->set('categories',$cate);
			$this->set('head_title',"Home");

			
	 }

	
}
?>
Return current item: OSShare