';
}
}
}
}
/**
* Plugin handler
* @package Mambo
*/
class mosMambotHandler {
/** @var array An array of functions in event groups */
var $_events=null;
/** @var array An array of lists */
var $_lists=null;
/** @var array An array of mambots */
var $_bots=null;
/** @var array An array of bools showing if corresponding bot is registered */
var $_registered=array();
/** @var int Index of the mambot being loaded */
var $_loading=null;
/**
* Constructor
*/
function mosMambotHandler() {
$my = mamboCore::is_set('currentUser') ? mamboCore::get('currentUser') : null;
$gid = $my ? $my->gid : 0;
$this->_events = array();
$database =& mamboDatabase::getInstance();
$database->setQuery( "SELECT folder, element, published, params, CONCAT_WS('/',folder,element) AS lookup"
. "\nFROM #__mambots"
. "\nWHERE published >= 1 AND access <= $gid"
. "\nORDER BY ordering"
);
$this->_bots = $database->loadObjectList();
if (!$this->_bots) $this->_bots = array();
}
/**
* Singleton accessor
*/
function &getInstance () {
static $instance;
if (!is_object($instance)) $instance = new mosMambotHandler();
return $instance;
}
/**
* Register a class-type mambot, provided it has a perform method
* - can register for multiple events if desired
* @param object The mambot object
* @param mixed string or array of strings - the mambot events to be registered
* @param int the subscript for use in the main array of mambots
*/
function _botRegister (&$botObject, &$selected, $i) {
$function = array(&$botObject, 'perform');
if (!is_callable($function)) return;
if (is_array($selected)) foreach ($selected as $select) $this->_botRegister($botObject, $select);
$this->_events[$selected][] = array ($function, $i);
$this->_registered[$i] = true;
}
/**
* Loads all the bot files for a particular group
* @param string The group name, relates to the sub-directory in the mambots directory
*/
function loadBotGroup( $group ) {
global $_MAMBOTS;
$group = trim( $group );
$total = 0;
$basepath = mamboCore::get('mosConfig_absolute_path');
foreach ($this->_bots as $i=>$bot) {
if ($bot->folder != $group OR isset($this->_registered[$i])) continue;
$path = "$basepath/mambots/$bot->folder/$bot->element.php";
if (file_exists( $path )) {
$this->_loading = $i;
require_once( $path );
if (!isset($this->_registered[$i])) {
$botclass = str_replace('.','_',$bot->element);
if (class_exists($botclass)) {
$newbot = new $botclass();
if (is_callable(array(&$newbot, 'register'))) {
$selected = $newbot->register();
$this->_botRegister($newbot, $selected, $i);
}
}
}
$total++;
}
}
$this->_loading = null;
if ($total) return true;
return false;
}
/**
* Registers a function to a particular event group
* @param string The event name
* @param string The function name
*/
function registerFunction( $event, $function ) {
$this->_events[$event][] = array( $function, $this->_loading );
$this->_registered[$this->_loading] = true;
}
/**
* Makes a option for a particular list in a group
* @param string The group name
* @param string The list name
* @param string The value for the list option
* @param string The text for the list option
*/
function addListOption( $group, $listName, $value, $text='' ) {
$this->_lists[$group][$listName][] = mosHTML::makeOption( $value, $text );
}
/**
* @param string The group name
* @param string The list name
* @return array
*/
function getList( $group, $listName ) {
return $this->_lists[$group][$listName];
}
/**
* Calls all functions according to passed parameters
* @param string The event name
* @param array An array of arguments
* @param boolean True is unpublished bots are to be processed
* @return array An array of results from each function call
*/
function &_runBots ($event, $args, $doUnpublished=false) {
$result = array();
if (isset( $this->_events[$event] )) {
foreach ($this->_events[$event] as $func) {
if (is_callable( $func[0] )) {
$botparams = $this->_bots[$func[1]]->params;
$args[] = new mosParameters($botparams);
$args[] = $event;
if ($doUnpublished) {
$args[0] = $this->_bots[$func[1]]->published;
$result[] = call_user_func_array( $func[0], $args );
} else if ($this->_bots[$func[1]]->published) {
$result[] = call_user_func_array( $func[0], $args );
}
}
}
}
return $result;
}
/**
* Calls all functions associated with an event group
* @param string The event name
* @param array An array of arguments
* @param boolean True is unpublished bots are to be processed
* @return array An array of results from each function call
*/
function trigger( $event, $args=null, $doUnpublished=false ) {
if ($args === null) $args = array();
// prepend the published argument
if ($doUnpublished) array_unshift( $args, null );
$result =& $this->_runBots($event, $args, $doUnpublished);
return $result;
}
/**
* Same as trigger but only returns the first event and
* allows for a variable argument list
* @param string The event name
* @return array The result of the first function call
*/
function call( $event ) {
$args =& func_get_args();
array_shift( $args );
$result =& $this->_runBots($event, $args);
if (isset($result[0])) return $result[0];
return null;
}
}
/**
* Users Table Class
*
* Provides access to the mos_templates table
* @package Mambo
*/
class mosUser extends mosDBTable {
/** @var int Unique id*/
var $id=null;
/** @var string The users real name (or nickname)*/
var $name=null;
/** @var string The login name*/
var $username=null;
/** @var string email*/
var $email=null;
/** @var string MD5 encrypted password*/
var $password=null;
/** @var string */
var $usertype=null;
/** @var int */
var $block=null;
/** @var int */
var $sendEmail=null;
/** @var int The group id number */
var $gid=null;
/** @var int Group number from ACL */
var $grp=null;
/** @var datetime */
var $registerDate=null;
/** @var datetime */
var $lastvisitDate=null;
/** @var string activation hash*/
var $activation=null;
/** @var string */
var $params=null;
/**
* @param database A database connector object
*/
function mosUser() {
$database =& mamboDatabase::getInstance();
$this->mosDBTable( '#__users', 'id', $database );
}
/**
* Return true if this user is an administrator, false otherwise
*/
function isAdmin() {
return ( strtolower( $this->usertype ) == 'superadministrator' || strtolower( $this->usertype ) == 'super administrator' || $this->grp == 16 ) ? true : false;
}
/**
* Fill a user object with information from the current session
*/
function getSessionData() {
$session =& mosSession::getCurrent();
$this->id = intval( $session->userid );
$this->username = $session->username;
$this->usertype = $session->usertype;
$this->gid = intval ($session->gid);
}
function getSession () {
$this->id = mosGetParam( $_SESSION, 'session_user_id', 0 );
$this->username = mosGetParam( $_SESSION, 'session_username', '' );
$this->usertype = mosGetParam( $_SESSION, 'session_usertype', '' );
$this->gid = mosGetParam( $_SESSION, 'session_gid', 0 );
$this->grp = mosGetParam( $_SESSION, 'session_grp', 0);
}
/**
* Validation and filtering
* @return boolean True is satisfactory
*/
function check() {
$this->_error = '';
if ($this->name == '') $this->_error = _REGWARN_NAME;
elseif ($this->username == '') $this->_error = _REGWARN_UNAME;
elseif (strlen($this->username) < 3 OR preg_match("/[\\<\\>\\\"\\'\\%\\;\\(\\)\\&\\+\\-]/", $this->username)) $this->_error = sprintf( _VALID_AZ09, _PROMPT_UNAME, 2 );
elseif (($this->email == '') OR preg_match("/[\w\.\-]+@\w+[\w\.\-]*?\.\w{1,4}/", $this->email ) == 0) $this->_error = _REGWARN_MAIL;
else {
// check for existing username
$username = strtolower($this->username);
$this->_db->setQuery( "SELECT COUNT(id) FROM #__users "
. "\nWHERE LOWER(username)='$username' AND id!='$this->id'"
);
if ($this->_db->loadResult()) $this->_error = _REGWARN_INUSE;
elseif (mamboCore::get('mosConfig_uniquemail')) {
// check for existing email
$this->_db->setQuery( "SELECT COUNT(id) FROM #__users "
. "\nWHERE email='$this->email' AND id!='$this->id'"
);
if ($this->_db->loadResult()) $this->_error = _REGWARN_EMAIL_INUSE;
}
}
if ($this->_error) return false;
return true;
}
function store( $updateNulls=false ) {
global $acl, $migrate;
$section_value = 'users';
if( $this->id AND !$migrate) {
// update existing record
$ret = $this->_db->updateObject( $this->_tbl, $this, 'id', $updateNulls );
// syncronise ACL
// single group handled at the moment
// trivial to expand to multiple groups
$groups = $acl->get_object_groups( $section_value, $this->id, 'ARO' );
$acl->del_group_object( $groups[0], $section_value, $this->id, 'ARO' );
$acl->add_group_object( $this->gid, $section_value, $this->id, 'ARO' );
$object_id = $acl->get_object_id( $section_value, $this->id, 'ARO' );
$acl->edit_object( $object_id, $section_value, $this->_db->getEscaped( $this->name ), $this->id, 0, 0, 'ARO' );
}
else {
// new record
$ret = $this->_db->insertObject( $this->_tbl, $this, 'id' );
// syncronise ACL
$acl->add_object( $section_value, $this->_db->getEscaped( $this->name ), $this->id, null, null, 'ARO' );
$acl->add_group_object( $this->gid, $section_value, $this->id, 'ARO' );
}
if ($ret) return true;
$this->_error = "mosUser::store failed " . $this->_db->getErrorMsg();
return false;
}
function delete($oid=null) {
global $acl;
$k = $this->_tbl_key;
if ($oid) $this->id = intval( $oid );
$aro_id = $acl->get_object_id( 'users', $this->$k, 'ARO' );
$acl->del_object( $aro_id, 'ARO', true );
// $authoriser = mosAuthorisationAdmin::getInstance();
// $authoriser->dropAccess('mosUser', $this->id);
$this->_error = '';
$this->_db->setQuery( "DELETE FROM $this->_tbl WHERE id = '".$this->id."'" );
if ($this->_db->query()) {
// cleanup related data
// :: private messaging
$this->_db->setQuery( "DELETE FROM #__messages_cfg WHERE user_id='".$this->id."'" );
if (!$this->_db->query()) $this->_error = $this->_db->getErrorMsg();
else {
$this->_db->setQuery( "DELETE FROM #__messages WHERE user_id_to='".$this->$k."'" );
if (!$this->_db->query()) $this->_error = $this->_db->getErrorMsg();
}
} else $this->_error = $this->_db->getErrorMsg();
if ($this->_error) return false;
return true;
}
}
/**
* User login details class
* @package Mambo
*/
class mosLoginDetails {
var $_user = '';
var $_password = '';
var $_remember = '';
function mosLoginDetails ($user, $password='', $remember='') {
$this->_user = $user;
$this->_password = $password;
$this->_remember = $remember;
}
function getUser () {
return $this->_user;
}
function getPassword () {
return $this->_password;
}
function getRemember () {
return $this->_remember;
}
}
/**
* Mambo Mainframe class
*
* Provide many supporting API functions
* @package Mambo
*/
class mosMainFrame {
/** @var database Internal database class pointer */
var $_db=null;
/** @var object A default option (e.g. component) */
var $_option=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=array();
/**
* 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->_setTemplate($isAdmin);
if (substr($option,0,4) != 'com_') $this->_option = "com_$option";
else $this->_option = $option;
if (isset( $_SESSION['session_userstate'] )) $this->_userstate =& $_SESSION['session_userstate'];
else $this->_userstate = null;
$this->_head['title'] = $GLOBALS['mosConfig_sitename'];
$this->_head['meta'] = array();
$this->_head['custom'] = array();
mosMainFrame::getInstance($this);
}
/**
* Get the current user - deprecated - use mamboCore instead
*/
function getUser() {
return mamboCore::get('currentUser');
}
/**
* Logout the current user - deprecated - use the code here directly
*/
function logout() {
require_once(mamboCore::get('mosConfig_absolute_path').'/includes/authenticator.php');
$authenticator =& mamboAuthenticator::getInstance();
$authenticator->logoutUser();
}
/**
* Login a user given name and password - deprecated - use the code here directly
*/
function login ($username=null,$passwd=null) {
require_once(mamboCore::get('mosConfig_absolute_path').'/includes/authenticator.php');
$authenticator =& mamboAuthenticator::getInstance();
return $authenticator->loginUser($username, $passwd);
}
/**
* Singleton get instance
* @param object the mainframe instance (if called internally)
* Note that because of the need for creation parameters, this cannot
* be called successfully unless the mainframe object is already created
*/
function &getInstance () {
static $mainframe;
if (func_num_args()) {
$args = func_get_args();
$mainframe = $args[0];
}
if (isset($mainframe)) $result =& $mainframe;
else $result = null;
return $result;
}
/**
* @param string
*/
function setPageTitle( $title=null ) {
if (mamboCore::get('mosConfig_pagetitles')) {
$title = trim(htmlspecialchars($title));
$base = mamboCore::get('mosConfig_sitename');
$this->_head['title'] = $title ? $title.' - '.$base : $base;
}
}
/**
* @return string
*/
function getPageTitle() {
return $this->_head['title'];
}
/**
* @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='' ) {
list($name, $content) = $this->_tidyMetaData($name, $content);
$prepend = trim($prepend);
$append = trim($append);
$this->_head['meta'][$name] = array($content, $prepend, $append);
}
/**
* @param string The value of the name attibute
*/
function _getMetaTag ($name) {
return isset($this->_head['meta'][$name]) ? $this->_head['meta'][$name] : array('', '', '');
}
/**
* @param string The value of the name attibute
* @param string The value of the content attibute to append to the existing
*/
function _tidyMetaData($name, $content) {
$result[] = trim(htmlspecialchars($name));
$result[] = trim(htmlspecialchars($content));
return $result;
}
/**
* @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, $ifEmpty=false ) {
list($name, $content) = $this->_tidyMetaData($name, $content);
$tag = $this->_getMetaTag($name);
if ($tag[0] AND $ifEmpty) return;
if ($tag[0] AND $content) $content .= ', ';
$tag[0] = $content.$tag[0];
$this->_head['meta'][$name] = $tag;
}
/**
* @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 ) {
list($name, $content) = $this->_tidyMetaData($name, $content);
$tag = $this->_getMetaTag($name);
$tag[0] = $content.$tag[0];
$this->_head['meta'][$name] = $tag;
}
/**
* 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[] = ''.$this->_head['title'].'';
foreach ($this->_head['meta'] as $name=>$meta) {
if ($meta[1]) $head[] = $meta[1];
$head[] = '';
if ($meta[2]) $head[] = $meta[2];
}
foreach ($this->_head['custom'] as $html) $head[] = $html;
return implode( "\n", $head )."\n";
}
/**
* @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 ) {
return is_array($this->_userstate) ? mosGetParam($this->_userstate, $var_name, null) : 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;
}
/**
* 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 (isset($_REQUEST[$req_name])) $this->setUserState($var_name, $_REQUEST[$req_name]);
elseif (isset($var_default) AND !isset($this->userstate[$var_name])) $this->setUserState($var_name, $var_default);
return $this->getUserState($var_name);
}
/**
* 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 =& mosSession::getCurrent();
return $session;
}
/**
* @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 ) {
return mamboCore::get('mosConfig_'.$varname);
}
function _setTemplate( $isAdmin=false ) {
global $Itemid;
$cur_template = '';
$sql = "SELECT template, client_id, menuid FROM #__templates_menu WHERE (client_id=0 or client_id=1)";
if (isset($Itemid) AND $Itemid) $sql .= " AND (menuid=0 OR menuid=$Itemid)";
else $sql .= " AND menuid=0";
$sql .= " ORDER BY client_id, menuid";
$this->_db->setQuery($sql);
$templates = $this->_db->loadObjectList();
foreach ($templates as $template) {
if ($template->client_id == 1) {
if ($isAdmin) $cur_template = $template->template;
}
else $cur_template = $template->template;
}
if ($isAdmin) {
$path = mamboCore::get('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
$path = mamboCore::get('mosConfig_absolute_path')."/templates/$mos_change_template/index.php";
if (strpos($mos_change_template,'..') == false AND strpos($mos_change_template,':') == false AND file_exists($path)) {
$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;
}
/**
* Checks to see if an image exists in the current templates image directory
* if it does it loads this image. Otherwise the default image is loaded.
* Also can be used in conjunction with the menulist param to create the chosen image
* load the default or use no image
*/
function ImageCheck( $file, $directory='/images/M_images/', $param=NULL, $param_directory='/images/M_images/', $alt=NULL, $name='image', $type=1, $align='middle' ) {
$basepath = mamboCore::get('mosConfig_live_site');
if ($param) $image = $basepath.$param_directory.$param;
else {
$endpath = '/templates/'.$this->getTemplate().'/images/'.$file;
if (file_exists(mamboCore::get('mosConfig_absolute_path').$endpath)) $image = $basepath.$endpath;
else $image = $basepath.$directory.$file; // outputs only path to image
}
// outputs actual html tag
if ($type) $image = '';
return $image;
}
/**
* Returns the first to be found of one or more files, or null
*
*/
function tryFiles ($first_choice, $second_choice=null, $third_choice=null) {
if (file_exists($first_choice)) return $first_choice;
elseif ($second_choice AND file_exists($second_choice)) return $second_choice;
elseif ($third_choice AND file_exists($third_choice)) return $third_choice;
else return null;
}
/**
* Returns a standard path variable
*
*/
function getPath( $varname, $option='' ) {
$base = mamboCore::get('mosConfig_absolute_path');
$origoption = $option;
if (!$option) $option = $this->_option;
$name = substr($option,4);
$bac_admin = "$base/administrator/components/com_admin/";
$baco = "$base/administrator/components/$option/";
$bttc = "$base/templates/$this->_template/components/";
$bco = "$base/components/$option/";
$bai = "$base/administrator/includes/";
$bi = "$base/includes/";
switch ($varname) {
case 'front': return $this->tryFiles ($bco."$name.php");
case 'front_html': return $this->tryFiles ($bttc."$name.html.php", $bco."$name.html.php");
case 'admin': return $this->tryFiles ($baco."admin.$name.php", $bac_admin.'admin.admin.php');
case 'admin_html': return $this->tryFiles ($baco."admin.$name.html.php", $bac_admin.'admin.admin.html.php');
case 'toolbar': return $this->tryFiles ($baco."toolbar.$name.php");
case 'toolbar_html': return $this->tryFiles ($baco."toolbar.$name.html.php");
case 'toolbar_default': return $this->tryFiles ($bai.'toolbar.html.php');
case 'class': return $this->tryFiles ($bco."$name.class.php", $baco."$name.class.php", $bi."$name.php");
case 'com_xml': return $this->tryFiles ($baco."$name.xml", $bco."$name.xml");
case 'mod0_xml':
if ($origoption) $path = $base."/modules/$option.xml";
else $path = $base.'/modules/custom.xml';
return $this->tryFiles ($path);
case 'mod1_xml':
if ($origoption) $path = $base."/administrator/modules/$option.xml";
else $path = $base.'/administrator/modules/custom.xml';
return $this->tryFiles ($path);
case 'bot_xml': return $this->tryFiles ($base."/mambots/$option.xml");
case 'menu_xml': return $this->tryFiles ($base."/administrator/components/com_menus/$option/$option.xml");
case 'installer_html': return $this->tryFiles($base."/administrator/components/com_installer/$option/$option.html.php");
case 'installer_class': return $this->tryFiles($base."/administrator/components/com_installer/$option/$option.class.php");
}
}
/**
* 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() {
if (mamboCore::get('mosConfig_enable_stats') == 1) {
if (mosGetParam( $_COOKIE, 'mosvisitor', 0 )) return;
setcookie( "mosvisitor", "1" );
$agent = $_SERVER['HTTP_USER_AGENT'];
$browser = mosGetBrowser( $agent );
$os = mosGetOS( $agent );
$domain = gethostbyaddr( $_SERVER['REMOTE_ADDR'] );
// 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(*), type FROM #__stats_agents WHERE (agent='$browser' AND type=0) OR (agent='$os' AND type=1) OR (agent='$tldomain' AND type=2) GROUP BY type");
$stats = $this->_db->loadObjectList();
$sql['browser'] = "INSERT INTO #__stats_agents (agent,type) VALUES ('$browser',0)";
$sql['os'] = "INSERT INTO #__stats_agents (agent,type) VALUES ('$os',1)";
$sql['domain'] = "INSERT INTO #__stats_agents (agent,type) VALUES ('$tldomain',2)";
if ($stats) foreach ($stats as $stat) {
if ($stat->type == 0) $sql['agents'] = "UPDATE #__stats_agents SET hits=(hits+1) WHERE agent='$browser' AND type=0";
if ($stat->type == 1) $sql['os'] = "UPDATE #__stats_agents SET hits=(hits+1) WHERE agent='$os' AND type=1";
if ($stat->type == 2) $sql['domain'] = "UPDATE #__stats_agents SET hits=(hits+1) WHERE agent='$tldomain' AND type=2";
}
$this->_db->setQuery(implode('; ',$sql));
$this->_db->query_batch();
}
}
/**
* @return correct Itemid for Content Item
*/
function getItemid ($id, $typed=1, $link=1, $bs=1, $bc=1, $gbs=1) {
require_once(mamboCore::get('mosConfig_absolute_path').'/components/com_content/content.class.php');
$handler =& contentHandler::getInstance();
return $handler->getItemid($id, $typed, $link, $bs, $bc, $gbs);
}
function liveBookMark () {
// support for Firefox Live Bookmarks ability for site syndication
$c_handler =& mosComponentHandler::getInstance();
$params = $c_handler->getParamsByName('Syndicate');
$live_bookmark = $params->get( 'live_bookmark', 0 );
if ($live_bookmark) {
// custom bookmark file name
$bookmark_file = $params->get( 'bookmark_file', $live_bookmark );
$link_file = mamboCore::get('mosConfig_live_site').'/cache/'. $bookmark_file;
$filename = mamboCore::get('mosConfig_absolute_path').'/cache/'. $bookmark_file;
$cache = $params->get( 'cache', 1 );
$cache_time = $params->get( 'cache_time', 3600 );
$title = $params->def( 'title', mamboCore::get('mosConfig_sitename') );
// checks to see if cache file exists, to determine whether to create a new one
if ( !file_exists( $filename ) || ( ( time() - filemtime( $filename ) ) > $cache_time ) ) {
$task = 'live_bookmark';
// sets bookmark feed type
$_GET['feed'] = str_replace( '.xml', '', $live_bookmark );
// loads rss component to create bookmark file
require_once( mamboCore::get('mosConfig_absolute_path').'/components/com_rss/rss.php' );
}
// outputs link tag for page
?>
appendMetaTag( 'description', mamboCore::get('mosConfig_MetaDesc'), true );
$this->appendMetaTag( 'keywords', mamboCore::get('mosConfig_MetaKeys'), true );
echo $this->getHead();
if (mamboCore::get('mosConfig_sef')) {
echo "\r\n";
}
$my = mamboCore::get('currentUser');
if ( $my->id ) {
?>
liveBookMark();
// outputs link tag for page
$configuration =& mamboCore::getMamboCore();
?>
"$path/",
'caching' => $caching,
'defaultGroup' => $group,
'lifeTime' => $time
);
$cache =& new Cache_Lite_Function( $options );
return $cache;
}
/**
* Cleans the cache
*/
function cleanCache ($group=false) {
if (mamboCore::get('mosConfig_caching')) {
$cache =& mosCache::getCache( $group );
$cache->clean( $group );
}
}
}
/**
* Session database table class
* @package Mambo
*/
class mosSession extends mosDBTable {
/** @var int Primary key */
var $session_id=null;
/** @var time */
var $time=null;
/** @var int User ID */
var $userid=0;
/** @var string */
var $usertype=null;
/** @var string */
var $username='';
/** @var int User group ID */
var $gid=0;
/** @var int */
var $guest=1;
/** @var string */
var $_session_cookie=null;
/**
* @param database A database connector object
*/
function mosSession() {
$database =& mamboDatabase::getInstance();
$this->mosDBTable( '#__session', 'session_id', $database );
$this->time = time();
}
function validate ($user) {
// check against db record of session
$session_id = mosGetParam( $_SESSION, 'session_id', '' );
$logintime = mosGetParam( $_SESSION, 'session_logintime', '' );
if ($session_id == md5( $user->id.$user->username.$user->usertype.$logintime )) {
$current_time = time();
$database = mamboDatabase::getInstance();
$database->setQuery ("UPDATE #__session"
. "\nSET time='$current_time'"
. "\nWHERE session_id='$session_id'"
. " AND username = '" . $database->getEscaped( $user->username ) . "'"
. " AND userid = " . intval( $user->id )
);
if (!$result = $database->query()) echo $database->stderr();
elseif ($database->getAffectedRows() == 1) return true;
}
return false;
}
function &getCurrent () {
static $currentSession;
if (!is_object($currentSession)) {
$currentSession = new mosSession();
mosSession::purge();
$sessionCookieName = md5('site'.mamboCore::get('mosConfig_live_site'));
$sessioncookie = mosGetParam($_COOKIE, $sessionCookieName, null);
$usercookie = mosGetParam($_COOKIE, 'usercookie', null);
if ($currentSession->load(md5($sessioncookie.$_SERVER['REMOTE_ADDR']))) {
// Session cookie exists, update time in session table
$currentSession->time = time();
$currentSession->update();
} else {
$currentSession->generateId();
if (!$currentSession->insert()) {
die( $currentSession->getError() );
}
setcookie( $sessionCookieName, $currentSession->getCookie(), time() + 43200, '/' );
//$_COOKIE["sessioncookie"] = $session->getCookie();
if ($usercookie) {
// Remember me cookie exists. Login with usercookie info.
require_once (mamboCore::get('mosConfig_absolute_path').'/includes/authenticator.php');
$authenticator =& mamboAuthenticator::getInstance();
$authenticator->authenticateUser ($message, $usercookie['username'], $usercookie['password'], null, $currentSession);
}
}
}
return $currentSession;
}
function insert() {
$ret = $this->_db->insertObject( $this->_tbl, $this );
if( !$ret ) {
$this->_error = strtolower(get_class( $this ))."::store failed " . $this->_db->stderr();
return false;
} else {
return true;
}
}
function update( $updateNulls=false ) {
$ret = $this->_db->updateObject( $this->_tbl, $this, 'session_id', $updateNulls );
if( !$ret ) {
$this->_error = strtolower(get_class( $this ))."::store failed " . $this->_db->stderr();
return false;
} else {
return true;
}
}
function generateId() {
$failsafe = 20;
$randnum = 0;
while ($failsafe--) {
$randnum = md5( uniqid( microtime(), 1 ) );
if ($randnum != "") {
$cryptrandnum = md5( $randnum );
$this->_db->setQuery( "SELECT $this->_tbl_key FROM $this->_tbl WHERE $this->_tbl_key=MD5('$randnum')" );
if(!($result = $this->_db->query())) {
die( $this->_db->stderr( true ));
// todo: handle gracefully
}
if ($this->_db->getNumRows($result) == 0) {
break;
}
}
}
$this->_session_cookie = $randnum;
$this->session_id = md5( $randnum . $_SERVER['REMOTE_ADDR'] );
}
function getCookie() {
return $this->_session_cookie;
}
function purge () {
$past = time() - intval(mamboCore::get('mosConfig_lifetime'));
$adminpast = time() - 3600;
$database = mamboDatabase::getInstance();
$database->setQuery("DELETE FROM #__session WHERE (time<$past AND guest>=0) OR (time<$adminpast AND guest<0)");
return $database->query();
}
}
/**
* Parameters handler
* @package Mambo
*/
class mosParameters {
/** @var object */
var $_params = null;
/** @var string The raw params string */
var $_raw = null;
/**
* Constructor
* @param string The raw parms text
* @param string Path to the xml setup file
* @var string The type of setup file
*/
function mosParameters( $text, $process_sections = false) {
$this->_params = $this->parse( $text, $process_sections );
$this->_raw = $text;
}
/**
* Get the result of parsing the string provided on creation
* @return string parsed result
*/
function getParams () {
return $this->_params;
}
/**
* @param string The name of the param
* @param string The value of the parameter
* @return string The set value
*/
function set( $key, $value='' ) {
$this->_params->$key = $value;
return $value;
}
/**
* Sets a default value if not alreay assigned
* @param string The name of the param
* @param string The value of the parameter
* @return string The set value
*/
function def( $key, $value='' ) {
return $this->set( $key, $this->get( $key, $value ) );
}
/**
* @param string The name of the param
* @param mixed The default value if not found
* @return string
*/
function get( $key, $default='' ) {
if (isset( $this->_params->$key )) return $this->_params->$key === '' ? $default : $this->_params->$key;
else return $default;
}
/**
* Look to see if string is bracketed by opener and closer
* If so, extract and trim the bracketed string
* Otherwise, return a null string
**/
function getBracketed ($text, $opener, $closer) {
if (strlen($text) > 1 AND ($text[0] != $opener OR substr($text,-1) != $closer)) return '';
else return trim(substr($text,1,-1));
}
/**
* Parse an .ini string, based on phpDocumentor phpDocumentor_parse_ini_file function
* @param mixed The ini string or array of lines
* @param boolean add an associative index for each section [in brackets]
* @return object
*/
function parse( $txt, $process_sections = false ) {
$result = new stdClass();
if (is_string($txt)) $lines = explode( "\n", $txt );
elseif (is_array($txt)) $lines = $txt;
else return $result;
$sec_name = '';
$unparsed = 0;
foreach ($lines as $line) {
// ignore comments and null lines
$line = trim($line);
if (strlen($line) == 0 OR $line[0] == ';') continue;
if ($sec_name = $this->getBracketed($line, '[', ']')) {
if ($process_sections) $result->$sec_name = new stdClass();
continue;
}
if (count($propsetter = explode ('=', $line, 2)) == 2) {
$property = trim($propsetter[0]);
if ($pquoted = $this->getBracketed($property, '"', '"')) $property = stripcslashes($pquoted);
$value = trim($propsetter[1]);
if ($value == 'false') $value = false;
elseif ($value == 'true') $value = true;
else if ($vquoted = $this->getBracketed($value, '"', '"')) $value = stripcslashes($vquoted);
if ($process_sections AND $sec_name) $result->$sec_name->$property = $value;
else $result->$property = $value;
}
else {
$property = '__invalid' . $unparsed++ . '__';
if ($process_sections AND $sec_name) $result->$sec_name->$property = $line;
else $result->$property = $line;
}
}
return $result;
}
/**
* @param string The name of the control, or the default text area if a setup file is not found
* @return string HTML
*/
function render( $name='params' ) {
if (is_file($this->_path)) {
$parser = new mosXMLParams ($this->_path, $this, $name);
if (count($parser->html)) return implode("\n", $parser->html);
}
$raw = $this->_raw;
return "