0) {
error_reporting( $mosConfig_error_reporting );
}
$local_backup_path = $mosConfig_absolute_path.'/administrator/backups';
$media_path = $mosConfig_absolute_path.'/media/';
$image_path = $mosConfig_absolute_path.'/images/stories';
$image_size = 100;
require_once( $mosConfig_absolute_path . "/includes/version.php" );
require_once( $mosConfig_absolute_path . "/includes/database.php" );
require_once( $mosConfig_absolute_path . "/includes/gacl.class.php" );
require_once( $mosConfig_absolute_path . "/includes/gacl_api.class.php" );
require_once( $mosConfig_absolute_path . "/includes/phpmailer/class.phpmailer.php" );
require_once( $mosConfig_absolute_path . "/includes/mamboxml.php" );
require_once( $mosConfig_absolute_path . "/includes/phpInputFilter/class.inputfilter.php" );
/**
* Task routing class
* @package Mambo
* @abstract
*/
class mosAbstractTasker {
/** @var array An array of the class methods to call for a task */
var $taskMap = null;
/** @var string The name of the default task */
var $defaultTask = null;
/** @var string The name of the current task*/
var $task = null;
/** @var array An array of the class methods*/
var $_methods = null;
/** @var string A url to redirect to */
var $_redirect = null;
/** @var string A message about the operation of the task */
var $_message = null;
/**
* Constructor
*/
function mosAbstractTasker() {
$taskMap = array();
$this->_methods = array();
foreach (get_class_methods( get_class( $this ) ) as $method) {
$this->_methods[] = strtolower( $method );
}
$this->_redirect = '';
$this->_message = '';
}
/**
* Set a URL to redirect the browser to
* @param string A URL
*/
function setRedirect( $url, $msg = null ) {
$this->_redirect = $url;
if ($msg !== null) {
$this->_message = $msg;
}
}
/**
* Redirects the browser
*/
function redirect() {
if ($this->_redirect) {
mosRedirect( $this->_redirect, $this->_message );
}
}
/**
* Register (map) a task to a method in the class
* @param string The task
* @param string The name of the method in the derived class to perform for this task
*/
function registerTask( $task, $method ) {
if (in_array( strtolower( $method ), $this->_methods )) {
$this->taskMap[$task] = $method;
} else {
$this->methodNotFound( $method );
}
}
/**
* Register the default task to perfrom if a mapping is not found
* @param string The name of the method in the derived class to perform if the task is not found
*/
function registerDefaultTask( $method ) {
$this->registerTask( '__default', $method );
}
/**
* Perform a task by triggering a method in the derived class
* @param string The task to perform
* @return mixed The value returned by the function
*/
function performTask( $task ) {
$this->task = $task;
if (isset( $this->taskMap[$task] )) {
return call_user_func( array( &$this, $this->taskMap[$task] ) );
} else if (isset( $this->taskMap['__default'] )) {
return call_user_func( array( &$this, $this->taskMap['__default'] ) );
} else {
return $this->taskNotFound( $task );
}
}
/**
* Get the last task that was to be performed
* @return string The task that was or is being performed
*/
function getTask() {
return $this->task;
}
/**
* Basic method if the task is not found
* @param string The task
* @return null
*/
function taskNotFound( $task ) {
echo 'Task ' . $task . ' not found';
return null;
}
/**
* Basic method if the registered method is not found
* @param string The name of the method in the derived class
* @return null
*/
function methodNotFound( $name ) {
echo 'Method ' . $name . ' not found';
return null;
}
}
/**
* Class to support function caching
* @package Mambo
*/
class mosCache {
/**
* @return object A function cache object
*/
function &getCache( $group='' ) {
global $mosConfig_absolute_path, $mosConfig_caching, $mosConfig_cachepath, $mosConfig_cachetime;
require_once( "$mosConfig_absolute_path/includes/Cache/Lite/Function.php" );
$options = array(
'cacheDir' => "$mosConfig_cachepath/",
'caching' => $mosConfig_caching,
'defaultGroup' => $group,
'lifeTime' => $mosConfig_cachetime
);
$cache =& new Cache_Lite_Function( $options );
return $cache;
}
/**
* Cleans the cache
*/
function cleanCache( $group=false ) {
global $mosConfig_caching;
if ($mosConfig_caching) {
$cache =& mosCache::getCache( $group );
$cache->clean( $group );
}
}
}
/**
* Mambo Mainframe class
*
* Provide many supporting API functions
* @package Mambo
*/
class mosMainFrame {
/** @var database Internal database class pointer */
var $_db=null;
/** @var object An object of configuration variables */
var $_config=null;
/** @var object An object of path variables */
var $_path=null;
/** @var mosSession The current session */
var $_session=null;
/** @var string The current template */
var $_template=null;
/** @var array An array to hold global user state within a session */
var $_userstate=null;
/** @var array An array of page meta information */
var $_head=null;
/** @var string Custom html string to append to the pathway */
var $_custom_pathway=null;
/**
* Class constructor
* @param database A database connection object
* @param string The url option
* @param string The path of the mos directory
*/
function mosMainFrame( &$db, $option, $basePath, $isAdmin=false ) {
$this->_db =& $db;
// load the configuration values
//return( $this->loadConfig() );
$this->_setConfig( $basePath );
$this->_setTemplate( $isAdmin );
$this->_setAdminPaths( $option, $this->getCfg( 'absolute_path' ) );
if (isset( $_SESSION['session_userstate'] )) {
$this->_userstate =& $_SESSION['session_userstate'];
} else {
$this->_userstate = null;
}
$this->_head = array();
$this->_head['title'] = $GLOBALS['mosConfig_sitename'];
$this->_head['meta'] = array();
$this->_head['custom'] = array();
}
/**
* @param string
*/
function setPageTitle( $title=null ) {
if (@$GLOBALS['mosConfig_pagetitles']) {
$title = trim( htmlspecialchars( $title ) );
$this->_head['title'] = $title ? $GLOBALS['mosConfig_sitename'] . ' - '. $title : $GLOBALS['mosConfig_sitename'];
}
}
/**
* @param string The value of the name attibute
* @param string The value of the content attibute
* @param string Text to display before the tag
* @param string Text to display after the tag
*/
function addMetaTag( $name, $content, $prepend='', $append='' ) {
$name = trim( htmlspecialchars( $name ) );
$content = trim( htmlspecialchars( $content ) );
$prepend = trim( $prepend );
$append = trim( $append );
$this->_head['meta'][] = array( $name, $content, $prepend, $append );
}
/**
* @param string The value of the name attibute
* @param string The value of the content attibute to append to the existing
* Tags ordered in with Site Keywords and Description first
*/
function appendMetaTag( $name, $content ) {
$name = trim( htmlspecialchars( $name ) );
$n = count( $this->_head['meta'] );
for ($i = 0; $i < $n; $i++) {
if ($this->_head['meta'][$i][0] == $name) {
$content = trim( htmlspecialchars( $content ) );
if ( $content ) {
if ( !$this->_head['meta'][$i][1] ) {
$this->_head['meta'][$i][1] = $content ;
} else {
$this->_head['meta'][$i][1] = $content .', '. $this->_head['meta'][$i][1];
}
}
return;
}
}
$this->addMetaTag( $name , $content );
}
/**
* @param string The value of the name attibute
* @param string The value of the content attibute to append to the existing
*/
function prependMetaTag( $name, $content ) {
$name = trim( htmlspecialchars( $name ) );
$n = count( $this->_head['meta'] );
for ($i = 0; $i < $n; $i++) {
if ($this->_head['meta'][$i][0] == $name) {
$content = trim( htmlspecialchars( $content ) );
$this->_head['meta'][$i][1] = $content . $this->_head['meta'][$i][1];
return;
}
}
$this->addMetaTag( $name, $content );
}
/**
* Adds a custom html string to the head block
* @param string The html to add to the head
*/
function addCustomHeadTag( $html ) {
$this->_head['custom'][] = trim( $html );
}
/**
* @return string
*/
function getHead() {
$head = array();
$head[] = '
' . $this->_head['title'] . '';
foreach ($this->_head['meta'] as $meta) {
if ($meta[2]) {
$head[] = $meta[2];
}
$head[] = '';
if ($meta[3]) {
$head[] = $meta[3];
}
}
foreach ($this->_head['custom'] as $html) {
$head[] = $html;
}
return implode( "\n", $head ) . "\n";
}
/**
* @return string
*/
function getPageTitle() {
return $this->_head['title'];
}
/**
* @return string
*/
function getCustomPathWay() {
return $this->_custom_pathway;
}
function appendPathWay( $html ) {
$this->_custom_pathway[] = $html;
}
/**
* Gets the value of a user state variable
* @param string The name of the variable
*/
function getUserState( $var_name ) {
if (is_array( $this->_userstate )) {
return mosGetParam( $this->_userstate, $var_name, null );
} else {
return null;
}
}
/**
* Gets the value of a user state variable
* @param string The name of the user state variable
* @param string The name of the variable passed in a request
* @param string The default value for the variable if not found
*/
function getUserStateFromRequest( $var_name, $req_name, $var_default=null ) {
if (is_array( $this->_userstate )) {
if (isset( $_REQUEST[$req_name] )) {
$this->setUserState( $var_name, $_REQUEST[$req_name] );
} else if (!isset( $this->_userstate[$var_name] )) {
$this->setUserState( $var_name, $var_default );
}
return $this->_userstate[$var_name];
} else {
return null;
}
}
/**
* Sets the value of a user state variable
* @param string The name of the variable
* @param string The value of the variable
*/
function setUserState( $var_name, $var_value ) {
if (is_array( $this->_userstate )) {
$this->_userstate[$var_name] = $var_value;
}
}
/**
* Initialises the user session
*
* Old sessions are flushed based on the configuration value for the cookie
* lifetime. If an existing session, then the last access time is updated.
* If a new session, a session id is generated and a record is created in
* the mos_sessions table.
*/
function initSession() {
$session =& $this->_session;
$session = new mosSession( $this->_db );
$session->purge(intval( $this->getCfg( 'lifetime' ) ));
$sessionCookieName = md5( 'site'.$GLOBALS['mosConfig_live_site'] );
$sessioncookie = mosGetParam( $_COOKIE, $sessionCookieName, null );
$usercookie = mosGetParam( $_COOKIE, 'usercookie', null );
if ($session->load( md5( $sessioncookie . $_SERVER['REMOTE_ADDR'] ) )) {
// Session cookie exists, update time in session table
$session->time = time();
$session->update();
} else {
$session->generateId();
$session->guest = 1;
$session->username = '';
$session->time = time();
$session->gid = 0;
if (!$session->insert()) {
die( $session->getError() );
}
setcookie( $sessionCookieName, $session->getCookie(), time() + 43200, '/' );
//$_COOKIE["sessioncookie"] = $session->getCookie();
if ($usercookie) {
// Remember me cookie exists. Login with usercookie info.
$this->login($usercookie['username'], $usercookie['password']);
}
}
}
/**
* Login validation function
*
* Username and encoded password is compare to db entries in the mos_users
* table. A successful validation updates the current session record with
* the users details.
*/
function login( $username=null,$passwd=null ) {
global $acl;
$usercookie = mosGetParam( $_COOKIE, 'usercookie', '' );
$sessioncookie = mosGetParam( $_COOKIE, 'sessioncookie', '' );
if (!$username || !$passwd) {
$username = trim( mosGetParam( $_POST, 'username', '' ) );
$passwd = trim( mosGetParam( $_POST, 'passwd', '' ) );
$passwd = md5( $passwd );
$bypost = 1;
}
$remember = trim( mosGetParam( $_POST, 'remember', '' ) );
if (!$username || !$passwd) {
echo "\n";
exit();
} else {
$this->_db->setQuery( "SELECT id, gid, block, usertype"
. "\nFROM #__users"
. "\nWHERE username='$username' AND password='$passwd'"
);
$row = null;
if ($this->_db->loadObject( $row )) {
if ($row->block == 1) {
echo "\n";
exit();
}
// fudge the group stuff
$grp = $acl->getAroGroup( $row->id );
$row->gid = 1;
if ($acl->is_group_child_of( $grp->name, 'Registered', 'ARO' ) ||
$acl->is_group_child_of( $grp->name, 'Public Backend', 'ARO' )) {
// fudge Authors, Editors, Publishers and Super Administrators into the Special Group
$row->gid = 2;
}
$row->usertype = $grp->name;
$session =& $this->_session;
$session->guest = 0;
$session->username = $username;
$session->userid = intval( $row->id );
$session->usertype = $row->usertype;
$session->gid = intval( $row->gid );
$session->update();
$currentDate = date("Y-m-d\TH:i:s");
$query = "UPDATE #__users SET lastvisitDate='$currentDate' where id='$session->userid'";
$this->_db->setQuery($query);
if (!$this->_db->query()) {
die($this->_db->stderr(true));
}
if ($remember=="yes") {
$lifetime = time() + 365*24*60*60;
setcookie( "usercookie[username]", $username, $lifetime, "/" );
setcookie( "usercookie[password]", $passwd, $lifetime, "/" );
}
//mosCache::cleanCache('com_content');
mosCache::cleanCache();
} else {
if (isset($bypost)) {
echo "\n";
} else {
$this->logout();
mosRedirect("index.php");
}
exit();
}
}
}
/**
* User logout
*
* Reverts the current session record back to 'anonymous' parameters
*/
function logout() {
//mosCache::cleanCache('com_content');
mosCache::cleanCache();
$session =& $this->_session;
$session->guest = 1;
$session->username = '';
$session->userid = '';
$session->usertype = '';
$session->gid = 0;
$session->update();
// this is daggy??
$lifetime = time() - 1800;
setcookie( "usercookie[username]", " ", $lifetime, "/" );
setcookie( "usercookie[password]", " ", $lifetime, "/" );
setcookie( "usercookie", " ", $lifetime, "/" );
@session_destroy();
}
/**
* @return mosUser A user object with the information from the current session
*/
function getUser() {
$user = new mosUser( $this->_db );
$user->id = intval( $this->_session->userid );
$user->username = $this->_session->username;
$user->usertype = $this->_session->usertype;
$user->gid = intval( $this->_session->gid );
return $user;
}
/**
* Loads the configuration.php file and assigns values to the internal variable
* @param string The base path from which to load the configuration file
*/
function _setConfig( $basePath='.' ) {
$this->_config = new stdClass();
require( $basePath . '/configuration.php' );
$this->_config->offline = $mosConfig_offline;
$this->_config->host = $mosConfig_host;
$this->_config->user = $mosConfig_user;
$this->_config->password = $mosConfig_password;
$this->_config->db = $mosConfig_db;
$this->_config->dbprefix = $mosConfig_dbprefix;
$this->_config->lang = $mosConfig_lang;
$this->_config->absolute_path = $mosConfig_absolute_path;
$this->_config->live_site = $mosConfig_live_site;
$this->_config->sitename = $mosConfig_sitename;
$this->_config->shownoauth = $mosConfig_shownoauth;
$this->_config->useractivation = $mosConfig_useractivation;
$this->_config->uniquemail = $mosConfig_uniquemail;
$this->_config->offline_message = $mosConfig_offline_message;
$this->_config->error_message = $mosConfig_error_message;
$this->_config->lifetime = $mosConfig_lifetime;
$this->_config->MetaDesc = $mosConfig_MetaDesc;
$this->_config->MetaKeys = $mosConfig_MetaKeys;
$this->_config->debug = $mosConfig_debug;
$this->_config->vote = $mosConfig_vote;
$this->_config->hideAuthor = $mosConfig_hideAuthor;
$this->_config->hideCreateDate = $mosConfig_hideCreateDate;
$this->_config->hideModifyDate = $mosConfig_hideModifyDate;
$this->_config->hidePdf = $mosConfig_hidePdf;
$this->_config->hidePrint = $mosConfig_hidePrint;
$this->_config->hideEmail = $mosConfig_hideEmail;
$this->_config->enable_log_items = $mosConfig_enable_log_items;
$this->_config->enable_log_searches = $mosConfig_enable_log_searches;
$this->_config->enable_stats = $mosConfig_enable_stats;
$this->_config->sef = $mosConfig_sef;
$this->_config->vote = $mosConfig_vote;
$this->_config->hideModifyDate = $mosConfig_hideModifyDate;
$this->_config->multipage_toc = $mosConfig_multipage_toc;
$this->_config->allowUserRegistration = $mosConfig_allowUserRegistration;
$this->_config->error_reporting = $mosConfig_error_reporting;
$this->_config->link_titles = $mosConfig_link_titles;
$this->_config->list_limit = $mosConfig_list_limit;
$this->_config->caching = $mosConfig_caching;
$this->_config->cachepath = $mosConfig_cachepath;
$this->_config->cachetime = $mosConfig_cachetime;
$this->_config->mailer = $mosConfig_mailer;
$this->_config->mailfrom = $mosConfig_mailfrom;
$this->_config->fromname = $mosConfig_fromname;
$this->_config->smtpauth = $mosConfig_smtpauth;
$this->_config->smtpuser = $mosConfig_smtpuser;
$this->_config->smtppass = $mosConfig_smtppass;
$this->_config->smtphost = $mosConfig_smtphost;
$this->_config->back_button = $mosConfig_back_button;
$this->_config->item_navigation = $mosConfig_item_navigation;
$this->_config->secret = $mosConfig_secret;
$this->_config->pagetitles = $mosConfig_pagetitles;
$this->_config->readmore = $mosConfig_readmore;
$this->_config->hits = $mosConfig_hits;
$this->_config->icons = $mosConfig_icons;
if (@$mosConfig_error_reporting === 0) {
error_reporting( 0 );
} else if (@$mosConfig_error_reporting > 0) {
error_reporting( $mosConfig_error_reporting );
}
}
/**
* @param string The name of the variable (from configuration.php)
* @return mixed The value of the configuration variable or null if not found
*/
function getCfg( $varname ) {
if (isset( $this->_config->$varname )) {
return $this->_config->$varname;
} else {
return null;
}
}
// TODO
function loadConfig() {
unset( $this->_config );
$this->_db->setQuery( "SELECT name,value FROM #__config2" );
if (!$this->_config = $this->_db->loadObjectList( 'name' )) {
echo $this->_db->stderr();
return false;
}
return true;
}
function _setTemplate( $isAdmin=false ) {
global $Itemid;
$mosConfig_absolute_path = $this->getCfg( 'absolute_path' );
// Default template
$this->_db->setQuery( "SELECT template FROM #__templates_menu WHERE client_id='0' AND menuid='0'" );
$cur_template = $this->_db->loadResult();
// Assigned template
if (isset($Itemid) && $Itemid!="" && $Itemid!=0) {
$this->_db->setQuery( "SELECT template FROM #__templates_menu WHERE client_id='0' AND menuid='$Itemid' LIMIT 1" );
$cur_template = $this->_db->loadResult() ? $this->_db->loadResult() : $cur_template;
}
if ($isAdmin) {
$this->_db->setQuery( "SELECT template FROM #__templates_menu WHERE client_id='1' AND menuid='0'" );
$cur_template = $this->_db->loadResult();
$path = "$mosConfig_absolute_path/administrator/templates/$cur_template/index.php";
if (!file_exists( $path )) {
$cur_template = 'mambo_admin';
}
} else {
// TemplateChooser Start
$mos_user_template = mosGetParam( $_COOKIE, 'mos_user_template', '' );
$mos_change_template = mosGetParam( $_REQUEST, 'mos_change_template', $mos_user_template );
if ($mos_change_template) {
// check that template exists in case it was deleted
if (file_exists( "$mosConfig_absolute_path/templates/$mos_change_template/index.php" )) {
$lifetime = 60*10;
$cur_template = $mos_change_template;
setcookie( "mos_user_template", "$mos_change_template", time()+$lifetime);
} else {
setcookie( "mos_user_template", "", time()-3600 );
}
}
// TemplateChooser End
}
$this->_template = $cur_template;
}
function getTemplate() {
return $this->_template;
}
/**
* Determines the paths for including engine and menu files
* @param string The current option used in the url
* @param string The base path from which to load the configuration file
*/
function _setAdminPaths( $option, $basePath='.' ) {
$option = strtolower( $option );
$this->_path = new stdClass();
$prefix = substr( $option, 0, 4 );
if ($prefix != 'com_') {
// ensure backward compatibility with existing links
$name = $option;
$option = "com_$option";
} else {
$name = substr( $option, 4 );
}
// components
if (file_exists( "$basePath/templates/$this->_template/components/$name.html.php" )) {
$this->_path->front = "$basePath/components/$option/$name.php";
$this->_path->front_html = "$basePath/templates/$this->_template/components/$name.html.php";
} else if (file_exists( "$basePath/components/$option/$name.php" )) {
$this->_path->front = "$basePath/components/$option/$name.php";
$this->_path->front_html = "$basePath/components/$option/$name.html.php";
}
if (file_exists( "$basePath/administrator/components/$option/admin.$name.php" )) {
$this->_path->admin = "$basePath/administrator/components/$option/admin.$name.php";
$this->_path->admin_html = "$basePath/administrator/components/$option/admin.$name.html.php";
}
if (file_exists( "$basePath/administrator/components/$option/toolbar.$name.php" )) {
$this->_path->toolbar = "$basePath/administrator/components/$option/toolbar.$name.php";
$this->_path->toolbar_html = "$basePath/administrator/components/$option/toolbar.$name.html.php";
$this->_path->toolbar_default = "$basePath/administrator/includes/toolbar.html.php";
}
if (file_exists( "$basePath/components/$option/$name.class.php" )) {
$this->_path->class = "$basePath/components/$option/$name.class.php";
} else if (file_exists( "$basePath/administrator/components/$option/$name.class.php" )) {
$this->_path->class = "$basePath/administrator/components/$option/$name.class.php";
} else if (file_exists( "$basePath/includes/$name.php" )) {
$this->_path->class = "$basePath/includes/$name.php";
}
if (file_exists("$basePath/administrator/components/$option/admin.$name.php" )) {
$this->_path->admin = "$basePath/administrator/components/$option/admin.$name.php";
$this->_path->admin_html = "$basePath/administrator/components/$option/admin.$name.html.php";
} else {
$this->_path->admin = "$basePath/administrator/components/com_admin/admin.admin.php";
$this->_path->admin_html = "$basePath/administrator/components/com_admin/admin.admin.html.php";
}
}
/**
* Returns a stored path variable
*
*/
function getPath( $varname, $option='' ) {
global $mosConfig_absolute_path;
if ($option) {
$temp = $this->_path;
$this->_setAdminPaths( $option, $this->getCfg( 'absolute_path' ) );
}
$result = null;
if (isset( $this->_path->$varname )) {
$result = $this->_path->$varname;
} else {
switch ($varname) {
case 'com_xml':
$name = substr( $option, 4 );
$path = "$mosConfig_absolute_path/administrator/components/$option/$name.xml";
if (file_exists( $path )) {
$result = $path;
} else {
$path = "$mosConfig_absolute_path/components/$option/$name.xml";
if (file_exists( $path )) {
$result = $path;
}
}
break;
case 'mod0_xml':
// Site modules
if ($option == '') {
$path = $mosConfig_absolute_path . "/modules/custom.xml";
} else {
$path = $mosConfig_absolute_path . "/modules/$option.xml";
}
if (file_exists( $path )) {
$result = $path;
}
break;
case 'mod1_xml':
// admin modules
if ($option == '') {
$path = $mosConfig_absolute_path . '/administrator/modules/custom.xml';
} else {
$path = $mosConfig_absolute_path . "/administrator/modules/$option.xml";
}
if (file_exists( $path )) {
$result = $path;
}
break;
case 'bot_xml':
// Site mambots
$path = $mosConfig_absolute_path . "/mambots/$option.xml";
if (file_exists( $path )) {
$result = $path;
}
break;
case 'menu_xml':
$path = $mosConfig_absolute_path . "/administrator/components/com_menus/$option/$option.xml";
if (file_exists( $path )) {
$result = $path;
}
break;
case 'installer_html':
$path = $mosConfig_absolute_path . "/administrator/components/com_installer/$option/$option.html.php";
if (file_exists( $path )) {
$result = $path;
}
break;
case 'installer_class':
$path = $mosConfig_absolute_path . "/administrator/components/com_installer/$option/$option.class.php";
if (file_exists( $path )) {
$result = $path;
}
break;
}
}
if ($option) {
$this->_path = $temp;
}
return $result;
}
/**
* Detects a 'visit'
*
* This function updates the agent and domain table hits for a particular
* visitor. The user agent is recorded/incremented if this is the first visit.
* A cookie is set to mark the first visit.
*/
function detect() {
global $mosConfig_enable_stats;
if ($mosConfig_enable_stats == 1) {
if (mosGetParam( $_COOKIE, 'mosvisitor', 0 )) {
return;
}
setcookie( "mosvisitor", "1" );
if (phpversion() <= "4.2.1") {
$agent = getenv( "HTTP_USER_AGENT" );
$domain = gethostbyaddr( getenv( "REMOTE_ADDR" ) );
} else {
$agent = $_SERVER['HTTP_USER_AGENT'];
$domain = gethostbyaddr( $_SERVER['REMOTE_ADDR'] );
}
$browser = mosGetBrowser( $agent );
$this->_db->setQuery( "SELECT count(*) FROM #__stats_agents WHERE agent='$browser' AND type='0'" );
if ($this->_db->loadResult()) {
$this->_db->setQuery( "UPDATE #__stats_agents SET hits=(hits+1) WHERE agent='$browser' AND type='0'" );
} else {
$this->_db->setQuery( "INSERT INTO #__stats_agents (agent,type) VALUES ('$browser','0')" );
}
$this->_db->query();
$os = mosGetOS( $agent );
$this->_db->setQuery( "SELECT count(*) FROM #__stats_agents WHERE agent='$os' AND type='1'" );
if ($this->_db->loadResult()) {
$this->_db->setQuery( "UPDATE #__stats_agents SET hits=(hits+1) WHERE agent='$os' AND type='1'" );
} else {
$this->_db->setQuery( "INSERT INTO #__stats_agents (agent,type) VALUES ('$os','1')" );
}
$this->_db->query();
// tease out the last element of the domain
$tldomain = split( "\.", $domain );
$tldomain = $tldomain[count( $tldomain )-1];
if (is_numeric( $tldomain )) {
$tldomain = "Unknown";
}
$this->_db->setQuery( "SELECT count(*) FROM #__stats_agents WHERE agent='$tldomain' AND type='2'" );
if ($this->_db->loadResult()) {
$this->_db->setQuery( "UPDATE #__stats_agents SET hits=(hits+1) WHERE agent='$tldomain' AND type='2'" );
} else {
$this->_db->setQuery( "INSERT INTO #__stats_agents (agent,type) VALUES ('$tldomain','2')" );
}
$this->_db->query();
}
}
/**
* @return correct Itemid for Content Item
*/
function getItemid( $id, $typed=1, $link=1, $bs=1, $bc=1, $gbs=1 ) {
global $Itemid;
$_Itemid = '';
if ($_Itemid == '' && $typed) {
// Search for typed link
$this->_db->setQuery( "SELECT id "
."\nFROM #__menu "
."\nWHERE type='content_typed' AND published='1' AND link='index.php?option=com_content&task=view&id=$id'" );
$_Itemid = $this->_db->loadResult();
}
if ($_Itemid == '' && $link) {
// Search for item link
$this->_db->setQuery( "SELECT id "
."\nFROM #__menu "
."\nWHERE type='content_item_link' AND published='1' AND link='index.php?option=com_content&task=view&id=$id'" );
$_Itemid = $this->_db->loadResult();
}
if ($_Itemid == '') {
// Search in sections
$this->_db->setQuery( "SELECT m.id "
."\nFROM #__content AS i"
."\nLEFT JOIN #__sections AS s ON i.sectionid=s.id"
."\nLEFT JOIN #__menu AS m ON m.componentid=s.id "
."\nWHERE m.type='content_section' AND m.published='1' AND i.id=".$id );
$_Itemid = $this->_db->loadResult();
}
if ($_Itemid == '' && $bs) {
// Search in specific blog section
$this->_db->setQuery( "SELECT m.id "
."\nFROM #__content AS i"
."\nLEFT JOIN #__sections AS s ON i.sectionid=s.id"
."\nLEFT JOIN #__menu AS m ON m.componentid=s.id "
."\nWHERE m.type='content_blog_section' AND m.published='1' AND i.id=".$id );
$_Itemid = $this->_db->loadResult();
}
if ($_Itemid == '' && $bc) {
// Search in specific blog category
$this->_db->setQuery( "SELECT m.id "
."\nFROM #__content AS i"
."\nLEFT JOIN #__categories AS c ON i.catid=c.id"
."\nLEFT JOIN #__menu AS m ON m.componentid=c.id "
."\nWHERE m.type='content_blog_category' AND m.published='1' AND i.id=".$id );
$_Itemid = $this->_db->loadResult();
}
if ($_Itemid == '' && $gbs) {
// Search in global blog section
$this->_db->setQuery( "SELECT id "
."\nFROM #__menu "
."\nWHERE type='content_blog_section' AND published='1' AND componentid=0" );
$_Itemid = $this->_db->loadResult();
}
/*
if ($_Itemid == '') {
// Search in global blog category
$this->_db->setQuery( "SELECT id "
."\nFROM #__menu "
."\nWHERE type='content_blog_category' AND published='1' AND componentid=0" );
$_Itemid = $this->_db->loadResult();
}
*/
if ($_Itemid != "") {
return $_Itemid;
} else {
return $Itemid;
}
}
/**
* @return number of Published Blog Sections
*/
function getBlogSectionCount( ) {
$query = "SELECT COUNT( m.id )"
."\n FROM #__content AS i"
."\n LEFT JOIN #__sections AS s ON i.sectionid=s.id"
."\n LEFT JOIN #__menu AS m ON m.componentid=s.id "
."\n WHERE m.type='content_blog_section'"
."\n AND m.published='1'"
;
$this->_db->setQuery( $query );
$count = $this->_db->loadResult();
return $count;
}
/**
* @return number of Published Blog Categories
*/
function getBlogCategoryCount( ) {
$query = "SELECT COUNT( m.id )"
. "\n FROM #__content AS i"
. "\n LEFT JOIN #__categories AS c ON i.catid=c.id"
. "\n LEFT JOIN #__menu AS m ON m.componentid=c.id "
. "\n WHERE m.type='content_blog_category'"
. "\n AND m.published='1'"
;
$this->_db->setQuery( $query );
$count = $this->_db->loadResult();
return $count;
}
/**
* @return number of Published Global Blog Sections
*/
function getGlobalBlogSectionCount( ) {
$query = "SELECT COUNT( id )"
."\n FROM #__menu "
."\n WHERE type='content_blog_section'"
."\n AND published='1'"
."\n AND componentid=0"
;
$this->_db->setQuery( $query );
$count = $this->_db->loadResult();
return $count;
}
/**
* @return number of Static Content
*/
function getStaticContentCount( ) {
$query = "SELECT COUNT( id )"
."\n FROM #__menu "
."\n WHERE type='content_typed'"
."\n AND published='1'"
;
$this->_db->setQuery( $query );
$count = $this->_db->loadResult();
return $count;
}
/**
* @return number of Content Item Links
*/
function getContentItemLinkCount( ) {
$query = "SELECT COUNT( id )"
."\n FROM #__menu "
."\n WHERE type='content_item_link'"
."\n AND published='1'"
;
$this->_db->setQuery( $query );
$count = $this->_db->loadResult();
return $count;
}
}
/**
* Component database table class
* @package Mambo
*/
class mosComponent extends mosDBTable {
/** @var int Primary key */
var $id=null;
/** @var string */
var $name=null;
/** @var string */
var $link=null;
/** @var int */
var $menuid=null;
/** @var int */
var $parent=null;
/** @var string */
var $admin_menu_link=null;
/** @var string */
var $admin_menu_alt=null;
/** @var string */
var $option=null;
/** @var string */
var $ordering=null;
/** @var string */
var $admin_menu_img=null;
/** @var int */
var $iscore=null;
/** @var string */
var $params=null;
/**
* @param database A database connector object
*/
function mosComponent( &$db ) {
$this->mosDBTable( '#__components', 'id', $db );
}
}
/**
* Utility class for all HTML drawing classes
* @package Mambo
*/
class mosHTML {
function makeOption( $value, $text='' ) {
$obj = new stdClass;
$obj->value = $value;
$obj->text = trim( $text ) ? $text : $value;
return $obj;
}
function writableCell( $folder ) {
echo '
';
}
/**
* Generates an HTML select list
* @param array An array of objects
* @param string The value of the HTML name attribute
* @param string Additional HTML attributes for the