<?php
/**
* Author:  BrOncO       10.1.2009  http://www.xtutto.com 
* @package              Joomla seyret_aioajax module
* @license              GNU/GPL, see : http://www.gnu.org/copyleft/gpl.html
*/
define( '_JEXEC', 1 );
define( '_AIOAXTASK', 1 );
define( 'DS', DIRECTORY_SEPARATOR );

$path =str_replace(DS.'modules'.DS.'mod_seyret_aioajax', "", dirname(__FILE__));
define('JPATH_BASE', $path );


require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
require_once ( JPATH_BASE .DS.'libraries'.DS.'joomla'.DS.'application'.DS.'helper.php' );
include_once ( JPATH_BASE .DS.'modules'.DS.'mod_seyret_aioajax'.DS.'helper.php');

$mainframe =& JFactory::getApplication('site');
$cfg       =& JFactory::getConfig();
$database  =& JFactory::getDBO();



//joomla 1.0 compatibilità seyret 
define( '_VALID_MOS', 1 );
//for import joomla 1.0 files
		$mosConfig_absolute_path = JPATH_BASE;
        $mosConfig_live_site = JURI::root(false,'');
      //if ($displaytype=="player") {			  
		//convert mosgetparam	
        if (!function_exists("mosgetparam")){ 		
           function mosgetparam($no ,$name, $default=''){
             $par =  JRequest::getVar($name, $default);
             return $par;
           } 
        //}
}		
		
		
//language, not sure is compatible with jomfish!
$lang   = JComponentHelper::getParams('com_languages');
$lang =  $lang->get('site', 'en-GB');		
		
if (file_exists(JPATH_ROOT.DS.'modules'.DS.'mod_seyret_aioajax'.DS.'lang'.DS. $lang .'.php')){ 
   include_once(JPATH_ROOT.DS.'modules'.DS.'mod_seyret_aioajax'.DS.'lang'.DS. $lang .'.php');
}else{ 
   include_once(JPATH_ROOT.DS.'modules'.DS.'mod_seyret_aioajax'.DS.'lang'.DS.'en-GB.php');
}






//--------------------------------------include Sef Advance url
if (file_exists(JPATH_SITE.DS.'components'.DS.'com_sef'.DS.'sef_conf.php')) {
	
  require_once ( JPATH_SITE.DS.'components'.DS.'com_sef'.DS.'sef_conf.php' );
  $sef_config = new SEF_AdvanceConfig();

  if ($sef_config->mosConfig_sef && $sef_config->sef_enabled) {
    $router =& $mainframe->getRouter();
	require_once ( JPATH_SITE.DS.'components'.DS.'com_sef'.DS.'sef.php' );
	if (class_exists('SEF_AdvanceRouter')) {
		$router = new SEF_AdvanceRouter();
	}
  }
} 
//end Sef advance

// JoomSEF exists?
if (file_exists(JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_sef'.DS.'classes'.DS.'config.php')) {

	require_once ( JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_sef'.DS.'classes'.DS.'config.php' );
    $sefConfig = new SEFConfig();

	if ($sefConfig->enabled) {
	
	    $router =& $mainframe->getRouter();
		require_once ( JPATH_SITE.DS.'components'.DS.'com_sef'.DS.'sef.router.php' );
		if (class_exists('JRouterJoomsef')) {
			$router = new JRouterJoomsef();
		}
	}
}
// end JoomSEF

//$u =& JURI::getInstance();
//echo 'Request URI is ' . $u->toString() . "\n";

$config = array();

//user imput via javascript!!
$config['ist']                = intval(JRequest::getVar('ist'));
$config['videolisttype']      = intval(JRequest::getVar('ordby',1));
$config['incategories']       = JRequest::getVar('incat','');
$config['limitstart']         = intval(JRequest::getVar('start'));

//$total                        = intval(JRequest::getVar('total'));
$config['da']                 = intval(JRequest::getVar('da', 1));
$vid                          = JRequest::getVar('vid', null);

//load module param
$module                           = getModule('seyret_aioajax', $config['ist']);
$params                           = new JParameter( $module->params );

$config['videoid']                = ( $vid ? intval($vid) : $params->get ('videoid', '') );
$config['captureid']  	          = $params->get( 'captureid', '0' );
$config['userid']                 = $params->get( 'userid', '' );

$config['featuredorderby']   	  = $params->get( 'featuredorderby', 'latest' );
$config['videocount']		      = $params->get( 'count', '4' );
$config['seyretcolumns'] 		  = $params->get( 'seyretcolumns', '4');

$config['showpagin']              = $params->get ('showpagin', '0');
$config['typenav']                = $params->get ('typenav', '1');
$config['maxpage']                = $params->get ('maxpage', '');
$config['orderOn']                = $params->get ('orderOn', '1');
$config['displaytype'] 		      = $params->get( 'displaytype', 'thumbnail');

$config['videothumbwidth']	      = $params->get( 'videothumbwidth', '120' );
$config['videothumbheight'] 	  = $params->get( 'videothumbheight', '90' );
$config['videodetails']  		  = $params->get( 'videodetails', 'bottom' );
$config['videotitle'] 		      = $params->get( 'videotitle', 'notitle');
$config['videotitlelength'] 	  = $params->get( 'videotitlelength', '50');
$config['detaillabels']  		  = $params->get( 'detaillabels', 'text' );
$config['showdescription']  	  = $params->get( 'showdescription', '0' );
$config['descriptionlength'] 	  = $params->get( 'descriptionlength', '100');

$config['showvideoowner']  	      = $params->get( 'showvideoowner', '1' );
$config['seyretscreenname'] 	  = $params->get( 'seyretscreenname', 'username');
$config['usecblink'] 	          = $params->get( 'usecblink', 0);
$config['showrating']  		      = $params->get( 'showrating', '1' );
$config['showhit']  			  = $params->get( 'showhit', '1' );
$config['showcategory'] 		  = $params->get( 'showcategory', '0' );
$config['showdownloads']  	      = $params->get( 'showdownloads', '0' );
$config['showaddeddate']  	      = $params->get( 'showaddeddate', '1' );
$config['dateformat']             = $params->get( 'dateformat', '%d-%m-%Y' );

$config['seyretitemid']           = $params->get ('seyretitemid', '');
$config['cbitemid']               = $params->get ('cbitemid', '');
if($config['usecblink'] == 1 && $config['cbitemid'] == ''){
  $query = "SELECT id FROM #__menu WHERE link = 'index.php?option=com_comprofiler' AND published = '1'";
  $database->setQuery( $query, 0, 1 );
  $it = $database->loadResult();
  if(count($it)){
    $config['cbitemid'] = $it;
  }
}
if($config['seyretitemid'] == ''){
  $query = "SELECT id FROM #__menu WHERE link = 'index.php?option=com_seyret' AND published = '1'";
  $database->setQuery( $query, 0, 1 );
  $it = $database->loadResult();
  if(count($it)){
    $config['seyretitemid'] = $it;
  }
}



//style config
$config['mod_height']             = $params->get ('mod_height', '');
$config['videodescheight']        = $params->get ('videodescriptionheight', '');
$config['row1bakgrcolor'] 	      = $params->get( 'row1bakgrcolor', 'FFFFFF');
$config['row1fontcolor'] 		  = $params->get( 'row1fontcolor', '4F4F4F');
$config['row1linecolor'] 		  = $params->get( 'row1linecolor', '4F4F4F');
$config['row2bakgrcolor'] 	      = $params->get( 'row2bakgrcolor', 'EDEDED');
$config['row2fontcolor'] 		  = $params->get( 'row2fontcolor', '4F4F4F');
$config['row2linecolor'] 		  = $params->get( 'row2linecolor', '4F4F4F');
$config['videotitleline'] 	      = $params->get( 'videotitleline', '4F4F4F');
$config['videobottomline'] 	      = $params->get( 'videobottomline', '4F4F4F');

//end config array

//start helper class
$AioAjaxMod = new AioAjaxMod($config);

$result = $AioAjaxMod->FindVideoRows();

$rows   = $result['rows'];
$total  = $result['total'];

if($rows){
   //require(JModuleHelper::getLayoutPath('mod_seyret_aioajax'));
   include_once ( JPATH_BASE .DS.'modules'.DS.'mod_seyret_aioajax'.DS.'tmpl'.DS.'default.php');
}else{
   echo 'no video found';
}

?>
