connection =& mamboDatabase::getInstance();
}
<<<<<<< .mine
@set_magic_quotes_runtime( 0 );
if (@$mosConfig_error_reporting === 0) {
error_reporting( 0 );
} else if (@$mosConfig_error_reporting > 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 );
=======
function &getInstance () {
static $instance;
if (!is_object($instance)) {
$instance =& new mosAuthoriser();
>>>>>>> .theirs
}
return $instance;
}
function doSQL ($sql) {
$this->connection->setQuery($sql);
if (!$this->connection->query()) {
echo "\n";
exit();
}
}
function getAccessorData ($type, $id) {
if (isset($this->perm_found[$type][$id])) return;
$sql = "SELECT a.*, p.control, p.action, p.subject_type, p.subject_id, p.system FROM #__assignments AS a LEFT JOIN #__permissions AS p ON p.role=a.role WHERE a.access_type='$type'";
if (isset($this->perm_found[$type])) $sql .= " AND a.access_id='$id'";
else $sql .= " AND (a.access_id='$id' OR a.access_id='*' OR a.access_id='+')";
$this->doSQL($sql);
$new_permissions = $this->connection->loadObjectList();
if ($new_permissions) $this->permissions = array_merge($this->permissions, $new_permissions);
$this->perm_found[$type][$id] = 1;
}
function &getRoles ($type, $id) {
$this->getAccessorData ($type, $id);
$rolenames = array();
foreach ($this->permissions as $role) {
if (strcasecmp($role->access_type, $type) == 0
AND ($role->access_id == $id OR $role->access_id == '*' OR ($role->access_id == '+' AND $id != 0))
AND !in_array($role->role,$rolenames)) $rolenames[] = $role->role;
}
return $rolenames;
}
function accessorPermissionOrControl ($mask, $a_type, $a_id, $action, $s_type='*', $s_id='*') {
$this->getAccessorData ($a_type, $a_id);
foreach ($this->permissions as $permission) {
if ((strcasecmp($permission->access_type,$a_type) == 0 OR $permission->access_type == '*')
AND (strcasecmp($permission->access_id,$a_id) == 0 OR $permission->access_id == '*')
AND (strcasecmp($permission->action,$action)==0 OR $permission->action == '*' OR $action == '*')
AND (strcasecmp($permission->subject_type,$s_type)==0 OR $s_type=='*')
AND (strcasecmp($permission->subject_id,$s_id)==0 OR $permission->subject_id == '*')
AND ($permission->control&$mask)) return 1;
}
return 0;
}
function checkPermission ($a_type, $a_id, $action, $s_type='*', $s_id='*') {
return $this->accessorPermissionOrControl(2, $a_type, $a_id, $action, $s_type='*', $s_id='*');
}
function checkControl ($a_type, $a_id, $action, $s_type='*', $s_id='*') {
return $this->accessorPermissionOrControl(1, $a_type, $a_id, $action, $s_type='*', $s_id='*');
}
function checkGrant ($a_type, $a_id, $action, $s_type='*', $s_id='*') {
return $this->accessorPermissionOrControl(4, $a_type, $a_id, $action, $s_type='*', $s_id='*');
}
function rolePermissionOrControl ($mask, $role, $action, $s_type, $s_id) {
$sql = "SELECT * FROM #__permissions WHERE role='$role'";
$this->connection->setQuery($sql);
$permissions = $this->connection->loadObjectList();
if ($permissions) {
foreach ($permissions as $permission) {
if (strcasecmp($permission->role,$role) == 0
AND (strcasecmp($permission->action,$action)==0 OR $permission->action == '*')
AND (strcasecmp($permission->subject_type,$s_type)==0)
AND (strcasecmp($permission->subject_id,$s_id)==0 OR $permission->subject_id == '*')
AND ($permission->control&$mask)) return 1;
}
}
return 0;
}
function checkRolePermission ($role, $action, $s_type, $s_id) {
return $this->rolePermissionOrControl(2, $role, $action, $s_type, $s_id);
}
function checkRoleControl ($role, $action, $s_type, $s_id) {
return $this->rolePermissionOrControl(1, $role, $action, $s_type, $s_id);
}
<<<<<<< .mine
$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']);
}
}
=======
function checkRoleGrant ($role, $action, $s_type, $s_id) {
return $this->rolePermissionOrControl(4, $role, $action, $s_type, $s_id);
>>>>>>> .theirs
}
<<<<<<< .mine
/**
* 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();
=======
function &listPermissions ($a_type, $a_id, $action, $property) {
$this->getAccessorData ($a_type, $a_id);
$results = array();
foreach ($this->permissions as $permission) {
if (strcasecmp($permission->access_type,$a_type) == 0
AND (strcasecmp($permission->access_id,$a_id) == 0 OR $permission->access_id == '*' OR ($permission->access_id == '+' AND $a_id != 0))
AND (strcasecmp($permission->action,$action) == 0 OR $permission->action == '*')
AND $permission->subject_type != null AND $permission->subject_id != null) {
$results[] = $permission->$property;
>>>>>>> .theirs
}
}
return $results;
}
}
class mosAuthorisationAdmin {
var $connection;
var $roles = array();
function mosAuthorisationAdmin () {
$this->connection =& mamboDatabase::getInstance();
}
<<<<<<< .mine
/**
* @return mosUser A user object with the information from the current session
*/
function getUser() {
$user = new mosUser( $this->_db );
=======
>>>>>>> .theirs
<<<<<<< .mine
$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->mosConfig_register_globals = $mosConfig_register_globals;
$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 );
=======
function &getInstance () {
static $instance;
if (!is_object($instance)) {
$instance =& new mosAuthorisationAdmin();
>>>>>>> .theirs
}
return $instance;
}
function doSQL ($sql) {
$this->connection->setQuery($sql);
if (!$this->connection->query()) {
echo "\n";
exit();
}
}
function getRoles () {
if (count($this->roles) == 0) {
$sql = "SELECT DISTINCT role FROM #__assignments";
$this->connection->setQuery($sql);
$this->roles = $this->connection->loadResultArray();
$sql = "SELECT DISTINCT role FROM #__permissions";
$this->connection->setQuery($sql);
$more = $this->connection->loadResultArray();
foreach ($more as $role) $this->addRole($role);
}
return $this->roles;
}
function addRole ($role) {
if (!in_array($role, $this->roles)) $this->roles[] = $role;
}
function removeRole ($role) {
$key = array_search($role, $this->roles);
if ($key !== false) unset($this->roles[$key]);
}
function &permissionHolders ($subject_type, $subject_id) {
$sql = "SELECT role, action, control FROM #__permissions";
if ($subject_type != '*') $where[] = "(subject_type='$subject_type' OR subject_type='*')";
if ($subject_id != '*') $where[] = "(subject_id='$subject_id' OR subject_id='*')";
if (isset($where)) $sql .= " WHERE ".implode(' AND ', $where);
$this->connection->setQuery($sql);
$result = $this->connection->loadObjectList();
if (!$result) $result = array();
return $result;
}
function &nonLocalPermissionHolders ($subject_type, $subject_id) {
$sql = "SELECT role, action, control FROM #__permissions WHERE (action='*' OR subject_type='*' OR subject_id='*') AND ((subject_type='$subject_type' OR subject_type='*') AND (subject_id='$subject_id' OR subject_id='*'))";
$this->connection->setQuery($sql);
$result = $this->connection->loadObjectList();
if (!$result) $result = array();
return $result;
}
function permitSQL ($role, $control, $action, $subject_type, $subject_id) {
$sql = "REPLACE INTO #__permissions (role, control, action, subject_type, subject_id) VALUES ('$role', '$control', '$action', '$subject_type', '$subject_id');";
return $sql;
}
function permit ($role, $control, $action, $subject_type, $subject_id) {
$sql = $this->permitSQL($role, $control, $action, $subject_type, $subject_id);
$this->doSQL($sql);
$this->addRole($role);
}
function assign ($role, $access_type, $access_id) {
$sql = "REPLACE INTO #__assignments (role, access_type, access_id) VALUES ('$role', '$access_type', '$access_id')";
$this->doSQL($sql);
$this->addRole($role);
}
function dropAccess ($access_type, $access_id) {
$sql = "DELETE FROM #__assignments WHERE access_type='$access_type' AND access_id='$access_id'";
$this->doSQL($sql);
}
function &getControllingRoles ($access_type, $access_id, $action, $subject_type, $subject_id) {
$sql = "SELECT a.role FROM #__permissions AS p, #__assignments AS a WHERE a.access_type='$access_type'"
." AND a.access_id='$access_id' AND a.role=p.role AND (p.control&1)"
." AND p.action='$action' AND p.subject_type='$subject_type' AND p.subject_id='$subject_id'";
$this->doSQL($sql);
$roles = $this->connection->loadResultArray();
return $roles;
}
function &getMyPermissions ($access_type, $access_id) {
$sql = 'SELECT p.action, p.subject_type, p.subject_id, control FROM #__permissions AS p, #__assignments AS a'
. " WHERE p.role=a.role AND a.access_type='$access_type' AND (a.access_id='$access_id' OR a.access_id='*')"
. ' AND (p.control&1)';
$this->doSQL($sql);
$permissions =& $this->connection->loadObjectList();
return $permissions;
}
function getJointPermissions ($access_type, $access_id, $role) {
$sql = "SELECT p2.control AS hiscontrol, p1.control AS mycontrol, p1.action, p1.subject_type, p1.subject_id"
." FROM `mos_assignments` AS a, `mos_permissions` AS p1 LEFT JOIN `mos_permissions` AS p2"
." ON (p2.role='$role' AND p1.action=p2.action AND p1.subject_type=p2.subject_type AND p1.subject_id=p2.subject_id)"
." WHERE (p1.control&1) AND p1.role=a.role AND a.access_type='$access_type' AND (a.access_id='$access_id' OR a.access_id='*')";
$this->doSQL($sql);
$permissions =& $this->connection->loadObjectList();
return $permissions;
}
<<<<<<< .mine
}
/**
* 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 '
';
echo '' . $folder . '/ ';
echo '';
echo is_writable( "../$folder" ) ? ''.T_('Writeable').' ' : ''.T_('Unwriteable').' ' . ' ';
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 tag
* @param string The name of the object variable for the option value
* @param string The name of the object variable for the option text
* @param mixed The key that is selected
* @returns string HTML for the select list
*/
function selectList( &$arr, $tag_name, $tag_attribs, $key, $text, $selected=NULL ) {
reset( $arr );
$html = "\n";
for ($i=0, $n=count( $arr ); $i < $n; $i++ ) {
$k = $arr[$i]->$key;
$t = $arr[$i]->$text;
$id = @$arr[$i]->id;
$extra = '';
$extra .= $id ? " id=\"" . $arr[$i]->id . "\"" : '';
if (is_array( $selected )) {
foreach ($selected as $obj) {
$k2 = $obj->$key;
if ($k == $k2) {
$extra .= " selected=\"selected\"";
break;
=======
function getAccessLists ($access_type, $access_id, $action, $subject_type, $subject_id) {
$authoriser = mosAuthoriser::getInstance();
if ($authoriser->checkControl($access_type, $access_id, $action, $subject_type, $subject_id)) {
$cangrant = $authoriser->checkGrant($access_type, $access_id, $action, $subject_type, $subject_id);
$permissions = $this->permissionHolders($subject_type, $subject_id);
$allroles = $this->getRoles();
foreach ($allroles as $role) {
$itemc[] = $optionc = mosHTML::makeOption($role, $role);
$itema[] = $optiona = mosHTML::makeOption($role, $role);
if ($cangrant) $itemg[] = $optiong = mosHTML::makeOption($role, $role);
foreach ($permissions as $permission) {
if (($permission->action == '*' OR $permission->action == $action) AND $permission->role == $role) {
if ($permission->control & 1) $cselected[] = $optionc;
if ($permission->control & 2) $aselected[] = $optiona;
if ($cangrant AND $permission->control & 4) $gselected[] = $optiong;
>>>>>>> .theirs
}
}
}
$results[] = mosHTML::selectList($itema, $action.'_arole[]', 'multiple="multiple"', 'value', 'text', $aselected);
$results[] = mosHTML::selectList($itemc, $action.'_crole[]', 'multiple="multiple"', 'value', 'text', $cselected);
if ($cangrant) $results[] = mosHTML::selectList($itemg, $action.'_grole[]', 'multiple="multiple"', 'value', 'text', $gselected);
}
else $results = array();
return $results;
}
<<<<<<< .mine
/**
* Writes a select list of integers
* @param int The start integer
* @param int The end integer
* @param int The increment
* @param string The value of the HTML name attribute
* @param string Additional HTML attributes for the tag
* @param mixed The key that is selected
* @param string The printf format to be applied to the number
* @returns string HTML for the select list
*/
function integerSelectList( $start, $end, $inc, $tag_name, $tag_attribs, $selected, $format="" ) {
$start = intval( $start );
$end = intval( $end );
$inc = intval( $inc );
$arr = array();
for ($i=$start; $i <= $end; $i+=$inc) {
$fi = $format ? sprintf( "$format", $i ) : "$i";
$arr[] = mosHTML::makeOption( $fi, $fi );
}
return mosHTML::selectList( $arr, $tag_name, $tag_attribs, 'value', 'text', $selected );
}
/**
* Writes a select list of month names based on Language settings
* @param string The value of the HTML name attribute
* @param string Additional HTML attributes for the tag
* @param mixed The key that is selected
* @returns string HTML for the select list values
*/
function monthSelectList( $tag_name, $tag_attribs, $selected ) {
$arr = array(
mosHTML::makeOption( '01', T_('January') ),
mosHTML::makeOption( '02', T_('February') ),
mosHTML::makeOption( '03', T_('March') ),
mosHTML::makeOption( '04', T_('April') ),
mosHTML::makeOption( '05', T_('May') ),
mosHTML::makeOption( '06', T_('June') ),
mosHTML::makeOption( '07', T_('July') ),
mosHTML::makeOption( '08', T_('August') ),
mosHTML::makeOption( '09', T_('September') ),
mosHTML::makeOption( '10', T_('October') ),
mosHTML::makeOption( '11', T_('November') ),
mosHTML::makeOption( '12', T_('December') )
);
return mosHTML::selectList( $arr, $tag_name, $tag_attribs, 'value', 'text', $selected );
}
/**
* Generates an HTML select list from a tree based query list
* @param array Source array with id and parent fields
* @param array The id of the current list item
* @param array Target array. May be an empty array.
* @param array An array of objects
* @param string The value of the HTML name attribute
* @param string Additional HTML attributes for the tag
* @param string The name of the object variable for the option value
* @param string The name of the object variable for the option text
* @param mixed The key that is selected
* @returns string HTML for the select list
*/
function treeSelectList( &$src_list, $src_id, $tgt_list, $tag_name, $tag_attribs, $key, $text, $selected ) {
// establish the hierarchy of the menu
$children = array();
// first pass - collect children
foreach ($src_list as $v ) {
$pt = $v->parent;
$list = @$children[$pt] ? $children[$pt] : array();
array_push( $list, $v );
$children[$pt] = $list;
}
// second pass - get an indent list of the items
$ilist = mosTreeRecurse( 0, '', array(), $children );
// assemble menu items to the array
$this_treename = '';
foreach ($ilist as $item) {
if ($this_treename) {
if ($item->id != $src_id && strpos( $item->treename, $this_treename ) === false) {
$tgt_list[] = mosHTML::makeOption( $item->id, $item->treename );
=======
function resetPermissions ($action, $subject_type, $subject_id) {
$control_types = array ('crole', 'arole', 'grole');
$control_values = array (1,2,4);
$permissions = $this->nonLocalPermissionHolders($subject_type, $subject_id);
$this->dropPermissions($action, $subject_type, $subject_id);
foreach ($control_types as $i=>$type) {
$key = $action.'_'.$type;
if (isset($_POST[$key])) {
foreach ($_POST[$key] as $role) {
$value = isset($newpermits[$role]) ? $newpermits[$role] : 0;
$newpermits[$role] = $value | $control_values[$i];
>>>>>>> .theirs
}
}
}
<<<<<<< .mine
// build the html select list
return mosHTML::selectList( $tgt_list, $tag_name, $tag_attribs, $key, $text, $selected );
}
/**
* Writes a yes/no select list
* @param string The value of the HTML name attribute
* @param string Additional HTML attributes for the tag
* @param mixed The key that is selected
* @returns string HTML for the select list values
*/
function yesnoSelectList( $tag_name, $tag_attribs, $selected, $yes=null, $no=null ) {
// modified by csouza for gettext localization
if (is_null($yes)) $yes = T_('Yes');
if (is_null($yes)) $no = T_('No');
$arr = array(
mosHTML::makeOption( '0', $no ),
mosHTML::makeOption( '1', $yes ),
);
return mosHTML::selectList( $arr, $tag_name, $tag_attribs, 'value', 'text', $selected );
}
/**
* Generates an HTML radio list
* @param array An array of objects
* @param string The value of the HTML name attribute
* @param string Additional HTML attributes for the tag
* @param mixed The key that is selected
* @param string The name of the object variable for the option value
* @param string The name of the object variable for the option text
* @returns string HTML for the select list
*/
function radioList( &$arr, $tag_name, $tag_attribs, $selected=null, $key='value', $text='text' ) {
reset( $arr );
$html = "";
for ($i=0, $n=count( $arr ); $i < $n; $i++ ) {
$k = $arr[$i]->$key;
$t = $arr[$i]->$text;
$id = @$arr[$i]->id;
$extra = '';
$extra .= $id ? " id=\"" . $arr[$i]->id . "\"" : '';
if (is_array( $selected )) {
foreach ($selected as $obj) {
$k2 = $obj->$key;
if ($k == $k2) {
$extra .= " selected=\"selected\"";
=======
$sql = '';
foreach ($newpermits as $role=>$value) {
$needed = true;
foreach ($permissions as $permission) {
if (($permission->action == '*' OR $permission->action == $action) AND $permission->role == $role) {
if (($value & $permission->control) === $value) {
$needed = false;
>>>>>>> .theirs
break;
}
}
}
if ($needed) $sql .= $this->permitSQL ($role, $value, $action, $subject_type, $subject_id);
}
if ($sql) $this->doSQL($sql);
}
<<<<<<< .mine
/**
* Writes a yes/no radio list
* @param string The value of the HTML name attribute
* @param string Additional HTML attributes for the tag
* @param mixed The key that is selected
* @returns string HTML for the radio list
*/
function yesnoRadioList( $tag_name, $tag_attribs, $selected, $yes=null, $no=null ) {
// modified by csouza for gettext localization
if (is_null($yes)) $yes = T_('Yes');
if (is_null($yes)) $no = T_('No');
$arr = array(
mosHTML::makeOption( '0', $no, true ),
mosHTML::makeOption( '1', $yes, true )
);
return mosHTML::radioList( $arr, $tag_name, $tag_attribs, $selected );
=======
function roleExists ($role) {
$sql = "SELECT COUNT(role) FROM #__permissions WHERE role='$role' GROUP BY role";
$this->doSQL($sql);
if ($this->connection->loadResult()) return true;
$sql = "SELECT COUNT(role) FROM #__assignments WHERE role='$role' GROUP BY role";
$this->doSQL($sql);
if ($this->connection->loadResult()) return true;
else return false;
>>>>>>> .theirs
}
function dropRole ($role) {
$sql = "DELETE FROM #__permissions WHERE action='administer' AND subject_type='$role' AND system=0";
$this->doSQL($sql);
$sql = "DELETE a FROM #__assignments AS a LEFT JOIN #__permissions AS p ON a.role=p.role WHERE a.role='$role' AND (p.system=0 OR p.system=NULL)";
$this->doSQL($sql);
$this->dropRolePermissions($role);
$this->removeRole($role);
}
<<<<<<< .mine
function sortIcon( $base_href, $field, $state='none' ) {
global $mosConfig_live_site;
$alts = array(
'none' => T_('No Sorting'),
'asc' => T_('Sort Ascending'),
'desc' => T_('Sort Descending'),
);
$next_state = 'asc';
if ($state == 'asc') {
$next_state = 'desc';
} else if ($state == 'desc') {
$next_state = 'none';
}
$html = ""
. " "
. " ";
return $html;
=======
function dropRolePermissions ($role) {
$sql = "DELETE FROM #__permissions WHERE role='$role' AND system=0";
$this->doSQL($sql);
$this->roles = array();
>>>>>>> .theirs
}
<<<<<<< .mine
/**
* Writes Close Button
*/
function CloseButton ( &$params, $hide_js=NULL ) {
// displays close button in Pop-up window
if ( $params->get( 'popup' ) && !$hide_js ) {
?>
doSQL($sql);
$this->roles = array();
>>>>>>> .theirs
}
<<<<<<< .mine
/**
* Writes Back Button
*/
function BackButton ( &$params, $hide_js=NULL ) {
// Back Button
if ( $params->get( 'back_button' ) && !$params->get( 'popup' ) && !$hide_js) {
?>
]*>.*?'si", '', $text );
$text = preg_replace( '/]*>([^<]+)<\/a>/is', '\2 (\1)', $text );
$text = preg_replace( '//', '', $text );
$text = preg_replace( '/{.+?}/', '', $text );
$text = preg_replace( '/ /', ' ', $text );
$text = preg_replace( '/&/', ' ', $text );
$text = preg_replace( '/"/', ' ', $text );
$text = strip_tags( $text );
$text = htmlspecialchars( $text );
return $text;
}
/**
* Writes Print icon
*/
function PrintIcon( &$row, &$params, $hide_js, $link, $status=NULL ) {
global $mosConfig_live_site, $mosConfig_absolute_path, $cur_template, $Itemid;
if ( $params->get( 'print' ) && !$hide_js ) {
// use default settings if none declared
if ( !$status ) {
$status = 'status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=640,height=480,directories=no,location=no';
}
// checks template image directory for image, if non found default are loaded
if ( $params->get( 'icons' ) ) {
$image = mosAdminMenus::ImageCheck( 'printButton.png', '/images/M_images/', NULL, NULL, T_('Print') );
} else {
$image = _ICON_SEP .' '. T_('Print'). ' '. _ICON_SEP;
}
if ( $params->get( 'popup' ) && !$hide_js ) {
// Print Preview button - used when viewing page
?>
\n";
$replacement .= " \n";
$replacement .= " \n";
$replacement .= " \n";
$replacement .= T_('This email address is being protected from spam bots, you need Javascript enabled to view it');
$replacement .= "\n \n";
return $replacement;
}
function encoding_converter( $text ) {
// replace vowels with character encoding
$text = str_replace( 'a', 'a', $text );
$text = str_replace( 'e', 'e', $text );
$text = str_replace( 'i', 'i', $text );
$text = str_replace( 'o', 'o', $text );
$text = str_replace( 'u', 'u', $text );
return $text;
}
=======
>>>>>>> .theirs
}
<<<<<<< .mine
/**
* @param database A database connector object
*/
function mosCategory( &$db ) {
$this->mosDBTable( '#__categories', 'id', $db );
}
// overloaded check function
function check() {
// check for valid name
if (trim( $this->title ) == '') {
$this->_error = T_("Your Category must contain a title.");
return false;
}
if (trim( $this->name ) == '') {
$this->_error = T_("Your Category must have a name.");
return false;
}
// check for existing name
$this->_db->setQuery( "SELECT id FROM #__categories "
. "\nWHERE name='".$this->name."' AND section='".$this->section."'"
);
$xid = intval( $this->_db->loadResult() );
if ($xid && $xid != intval( $this->id )) {
$this->_error = T_("There is a category already with that name, please try again.");
return false;
}
return true;
}
}
=======
>>>>>>> .theirs
/**
* 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 */
<<<<<<< .mine
var $params='';
/**
* @param database A database connector object
*/
function mosSection( &$db ) {
$this->mosDBTable( '#__sections', 'id', $db );
}
// overloaded check function
function check() {
// check for valid name
if (trim( $this->title ) == '') {
$this->_error = T_("Your Section must contain a title.");
return false;
}
if (trim( $this->name ) == '') {
$this->_error = T_("Your Section must have a name.");
return false;
}
// check for existing name
$this->_db->setQuery( "SELECT id FROM #__sections "
. "\nWHERE name='$this->name' AND scope='$this->scope'"
);
$xid = intval( $this->_db->loadResult() );
if ($xid && $xid != intval( $this->id )) {
$this->_error = T_("There is a section already with that name, please try again.");
return false;
}
return true;
}
}
/**
* Module database table class
* @package Mambo
*/
class mosContent extends mosDBTable {
/** @var int Primary key */
var $id=null;
=======
var $admin_menu_link=null;
>>>>>>> .theirs
/** @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 );
}
}
<<<<<<< .mine
/**
* @param database A database connector object
*/
function mosUser( &$database ) {
$this->mosDBTable( '#__users', 'id', $database );
}
/**
* Validation and filtering
* @return boolean True is satisfactory
*/
function check() {
global $mosConfig_uniquemail;
// filter malicious code
//$this->filter();
// Validate user information
if (trim( $this->name ) == '') {
$this->_error = T_('Please enter your name.');
return false;
}
if (trim( $this->username ) == '') {
$this->_error = T_('Please enter a user name.');
return false;
}
if (eregi( "[\<|\>|\"|\'|\%|\;|\(|\)|\&|\+|\-]", $this->username) || strlen( $this->username ) < 3) {
$this->_error = sprintf( T_("Please enter a valid %s. No spaces, more than %d characters and containing only the characters 0-9,a-z, or A-Z"), T_('Username:'), 2 );
return false;
}
if ((trim($this->email == "")) || (preg_match("/[\w\.\-]+@\w+[\w\.\-]*?\.\w{1,4}/", $this->email )==false)) {
$this->_error = T_('Please enter a valid e-mail address.');
return false;
}
// check for existing username
$this->_db->setQuery( "SELECT id FROM #__users "
. "\nWHERE LOWER(username)=LOWER('$this->username') AND id!='$this->id'"
);
$xid = intval( $this->_db->loadResult() );
if ($xid && $xid != intval( $this->id )) {
$this->_error = T_('This username/password is already in use. Please try another.');
return false;
}
if ($mosConfig_uniquemail) {
// check for existing email
$this->_db->setQuery( "SELECT id FROM #__users "
. "\nWHERE email='$this->email' AND id!='$this->id'"
);
$xid = intval( $this->_db->loadResult() );
if ($xid && $xid != intval( $this->id )) {
$this->_error = T_('This e-mail is already registered. If you forgot the password click on "Password Reminder" and new password will be sent to you.');
return false;
}
}
return true;
}
function store( $updateNulls=false ) {
global $acl, $migrate;
$section_value = 'users';
$k = $this->_tbl_key;
$key = $this->$k;
if( $key && !$migrate) {
// existing record
$ret = $this->_db->updateObject( $this->_tbl, $this, $this->_tbl_key, $updateNulls );
// syncronise ACL
// single group handled at the moment
// trivial to expand to multiple groups
$groups = $acl->get_object_groups( $section_value, $this->$k, 'ARO' );
$acl->del_group_object( $groups[0], $section_value, $this->$k, 'ARO' );
$acl->add_group_object( $this->gid, $section_value, $this->$k, 'ARO' );
$object_id = $acl->get_object_id( $section_value, $this->$k, 'ARO' );
$acl->edit_object( $object_id, $section_value, $this->_db->getEscaped( $this->name ), $this->$k, 0, 0, 'ARO' );
} else {
// new record
$ret = $this->_db->insertObject( $this->_tbl, $this, $this->_tbl_key );
// syncronise ACL
$acl->add_object( $section_value, $this->_db->getEscaped( $this->name ), $this->$k, null, null, 'ARO' );
$acl->add_group_object( $this->gid, $section_value, $this->$k, 'ARO' );
}
if( !$ret ) {
$this->_error = strtolower(get_class( $this ))."::store failed " . $this->_db->getErrorMsg();
return false;
} else {
return true;
}
}
function delete( $oid=null ) {
global $acl;
$k = $this->_tbl_key;
if ($oid) {
$this->$k = intval( $oid );
}
$aro_id = $acl->get_object_id( 'users', $this->$k, 'ARO' );
// $acl->del_object( $aro_id, 'ARO', true );
$this->_db->setQuery( "DELETE FROM $this->_tbl WHERE $this->_tbl_key = '".$this->$k."'" );
if ($this->_db->query()) {
// cleanup related data
// :: private messaging
$this->_db->setQuery( "DELETE FROM #__messages_cfg WHERE user_id='".$this->$k."'" );
if (!$this->_db->query()) {
$this->_error = $this->_db->getErrorMsg();
return false;
}
$this->_db->setQuery( "DELETE FROM #__messages WHERE user_id_to='".$this->$k."'" );
if (!$this->_db->query()) {
$this->_error = $this->_db->getErrorMsg();
return false;
}
return true;
} else {
$this->_error = $this->_db->getErrorMsg();
return false;
}
}
}
=======
>>>>>>> .theirs
/**
* Template Table Class
*
* Provides access to the mos_templates table
* @package Mambo
*/
class mosTemplate extends mosDBTable {
/** @var int */
var $id=null;
/** @var string */
var $cur_template=null;
/** @var int */
var $col_main=null;
/**
* @param database A database connector object
*/
function mosTemplate( &$database ) {
$this->mosDBTable( '#__templates', 'id', $database );
}
}
/**
* Class mosMambot
* @package Mambo
*/
class mosMambot extends mosDBTable {
/** @var int */
var $id=null;
/** @var varchar */
var $name=null;
/** @var varchar */
var $element=null;
/** @var varchar */
var $folder=null;
/** @var tinyint unsigned */
var $access=null;
/** @var int */
var $ordering=null;
/** @var tinyint */
var $published=null;
/** @var tinyint */
var $iscore=null;
/** @var tinyint */
var $client_id=null;
/** @var int unsigned */
var $checked_out=null;
/** @var datetime */
var $checked_out_time=null;
/** @var text */
var $params=null;
function mosMambot( &$db ) {
$this->mosDBTable( '#__mambots', 'id', $db );
}
}
/**
* Module database table class
* @package Mambo
*/
class mosModule extends mosDBTable {
/** @var int Primary key */
var $id=null;
/** @var string */
var $title=null;
/** @var string */
var $showtitle=null;
/** @var int */
var $content=null;
/** @var int */
var $ordering=null;
/** @var string */
var $position=null;
/** @var boolean */
var $checked_out=null;
/** @var time */
var $checked_out_time=null;
/** @var boolean */
var $published=null;
/** @var string */
var $module=null;
/** @var int */
var $numnews=null;
/** @var int */
var $access=null;
/** @var string */
var $params=null;
/** @var string */
var $iscore=null;
/** @var string */
var $client_id=null;
/**
* @param database A database connector object
*/
function mosModule( &$db ) {
$this->mosDBTable( '#__modules', 'id', $db );
}
// overloaded check function
function check() {
// check for valid name
if (trim( $this->title ) == '') {
$this->_error = "Your Module must contain a title.";
return false;
}
// limitation has been removed
// check for existing title
//$this->_db->setQuery( "SELECT id FROM #__modules"
//. "\nWHERE title='$this->title'"
//);
// check for module of same name
//$xid = intval( $this->_db->loadResult() );
//if ($xid && $xid != intval( $this->id )) {
// $this->_error = "There is a module already with that name, please try again.";
// return false;
//}
return true;
}
}
<<<<<<< .mine
function insert() {
$ret = $this->_db->insertObject( $this->_tbl, $this );
if( !$ret ) {
$this->_error = strtolower(get_class( $this ))."::store() ". T_('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() ". T_('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( $inc=1800 ) {
$past = time() - $inc;
$query = "DELETE FROM $this->_tbl"
. "\nWHERE (time < $past)";
$this->_db->setQuery($query);
return $this->_db->query();
}
}
function mosObjectToArray($p_obj)
{
$retarray = null;
if(is_object($p_obj))
{
$retarray = array();
foreach (get_object_vars($p_obj) as $k => $v)
{
if(is_object($v))
$retarray[$k] = mosObjectToArray($v);
else
$retarray[$k] = $v;
}
}
return $retarray;
}
=======
>>>>>>> .theirs
/**
<<<<<<< .mine
* Checks the user agent string against known browsers
*/
function mosGetBrowser( $agent ) {
require( "includes/agent_browser.php" );
if (preg_match( "/msie[\/\sa-z]*([\d\.]*)/i", $agent, $m )
&& !preg_match( "/webtv/i", $agent )
&& !preg_match( "/omniweb/i", $agent )
&& !preg_match( "/opera/i", $agent )) {
// IE
return "MS Internet Explorer $m[1]";
} else if (preg_match( "/netscape.?\/([\d\.]*)/i", $agent, $m )) {
// Netscape 6.x, 7.x ...
return "Netscape $m[1]";
} else if ( preg_match( "/mozilla[\/\sa-z]*([\d\.]*)/i", $agent, $m )
&& !preg_match( "/gecko/i", $agent )
&& !preg_match( "/compatible/i", $agent )
&& !preg_match( "/opera/i", $agent )
&& !preg_match( "/galeon/i", $agent )
&& !preg_match( "/safari/i", $agent )) {
// Netscape 3.x, 4.x ...
return "Netscape $m[2]";
} else {
// Other
$found = false;
foreach ($browserSearchOrder as $key) {
if (preg_match( "/$key.?\/([\d\.]*)/i", $agent, $m )) {
$name = "$browsersAlias[$key] $m[1]";
return $name;
break;
}
}
}
return 'Unknown';
}
/**
* Checks the user agent string against known operating systems
*/
function mosGetOS( $agent ) {
require( "includes/agent_os.php" );
foreach ($osSearchOrder as $key) {
if (preg_match( "/$key/i", $agent )) {
return $osAlias[$key];
break;
}
}
return 'Unknown';
}
/**
* @param string SQL with ordering As value and 'name field' AS text
* @param integer The length of the truncated headline
*/
function mosGetOrderingList( $sql, $chop='30' ) {
global $database;
$order = array();
$database->setQuery( $sql );
if (!($orders = $database->loadObjectList())) {
if ($database->getErrorNum()) {
echo $database->stderr();
return false;
} else {
$order[] = mosHTML::makeOption( 1, 'first' );
return $order;
}
}
$order[] = mosHTML::makeOption( 0, '0 first' );
for ($i=0, $n=count( $orders ); $i < $n; $i++) {
if (strlen($orders[$i]->text) > $chop) {
$text = substr($orders[$i]->text,0,$chop)."...";
} else {
$text = $orders[$i]->text;
}
$order[] = mosHTML::makeOption( $orders[$i]->value, $orders[$i]->value.' ('.$text.')' );
}
$order[] = mosHTML::makeOption( $orders[$i-1]->value+1, ($orders[$i-1]->value+1).' last' );
return $order;
}
/**
* Makes a variable safe to display in forms
*
* Object parameters that are non-string, array, object or start with underscore
* will be converted
* @param object An object to be parsed
* @param int The optional quote style for the htmlspecialchars function
* @param string|array An optional single field name or array of field names not
* to be parsed (eg, for a textarea)
*/
function mosMakeHtmlSafe( &$mixed, $quote_style=ENT_QUOTES, $exclude_keys='' ) {
if (is_object( $mixed )) {
foreach (get_object_vars( $mixed ) as $k => $v) {
if (is_array( $v ) || is_object( $v ) || $v == NULL || substr( $k, 1, 1 ) == '_' ) {
continue;
}
if (is_string( $exclude_keys ) && $k == $exclude_keys) {
continue;
} else if (is_array( $exclude_keys ) && in_array( $k, $exclude_keys )) {
continue;
}
$mixed->$k = htmlspecialchars( $v, $quote_style );
}
}
}
/**
* Checks whether a menu option is within the users access level
* @param int Item id number
* @param string The menu option
* @param int The users group ID number
* @param database A database connector object
* @return boolean True if the visitor's group at least equal to the menu access
*/
function mosMenuCheck( $Itemid, $menu_option, $task, $gid ) {
global $database;
$dblink="index.php?option=$menu_option";
if ($Itemid!="" && $Itemid!=0) {
$database->setQuery( "SELECT access FROM #__menu WHERE id='$Itemid'" );
} else {
if ($task!="") {
$dblink.="&task=$task";
}
$database->setQuery( "SELECT access FROM #__menu WHERE link like '$dblink%'" );
}
$results = $database->loadObjectList();
$access = 0;
//echo ""; print_r($results); echo " ";
foreach ($results as $result) {
$access = max( $access, $result->access );
}
return ($access <= $gid);
}
/**
* Returns formated date according to current local and adds time offset
* @param string date in datetime format
* @param string format optional format for strftime
* @param offset time offset if different than global one
* @returns formated date
*/
function mosFormatDate( $date, $format="", $offset="" ){
global $mosConfig_offset;
if ( $format == '' ) {
// %Y-%m-%d %H:%M:%S
$format = _DATE_FORMAT_LC;
}
if ( $offset == '' ) {
$offset = $mosConfig_offset;
}
if ( $date && ereg( "([0-9]{4})-([0-9]{2})-([0-9]{2})[ ]([0-9]{2}):([0-9]{2}):([0-9]{2})", $date, $regs ) ) {
$date = mktime( $regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1] );
$date = $date > -1 ? strftime( $format, $date + ($offset*60*60) ) : '-';
}
return $date;
}
/**
* Returns current date according to current local and time offset
* @param string format optional format for strftime
* @returns current date
*/
function mosCurrentDate( $format="" ) {
global $mosConfig_offset;
if ($format=="") {
$format = _DATE_FORMAT_LC;
}
$date = strftime( $format, time() + ($mosConfig_offset*60*60) );
return $date;
}
/**
* Utility function to provide ToolTips
* @param string ToolTip text
* @param string Box title
* @returns HTML code for ToolTip
*/
function mosToolTip( $tooltip, $title='', $width='', $image='tooltip.png', $text='', $href='#' ) {
global $mosConfig_live_site;
if ( $width ) {
$width = ', WIDTH, \''.$width .'\'';
}
if ( $title ) {
$title = ', CAPTION, \''.$title .'\'';
}
if ( !$text ) {
$image = $mosConfig_live_site . '/includes/js/ThemeOffice/'. $image;
$text = ' ';
}
$style = 'style="text-decoration: none; color: #333;"';
if ( $href ) {
$style = '';
}
$tip = "". $text ." ";
return $tip;
}
/**
* Utility function to provide Warning Icons
* @param string Warning text
* @param string Box title
* @returns HTML code for Warning
*/
function mosWarning($warning, $title='Mambo Warning') {
global $mosConfig_live_site;
$tip = " ";
return $tip;
}
function mosCreateGUID(){
srand((double)microtime()*1000000);
$r = rand ;
$u = uniqid(getmypid() . $r . (double)microtime()*1000000,1);
$m = md5 ($u);
return($m);
}
function mosCompressID( $ID ){
return(Base64_encode(pack("H*",$ID)));
}
function mosExpandID( $ID ) {
return ( implode(unpack("H*",Base64_decode($ID)), '') );
}
/**
* Page generation time
* @package Mambo
*/
class mosProfiler {
var $start=0;
var $prefix='';
function mosProfiler( $prefix='' ) {
$this->start = $this->getmicrotime();
$this->prefix = $prefix;
}
function mark( $label ) {
return sprintf ( "\n$this->prefix %.3f $label
", $this->getmicrotime() - $this->start );
}
function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
}
/**
* Function to create a mail object for futher use (uses phpMailer)
* @param string From e-mail address
* @param string From name
* @param string E-mail subject
* @param string Message body
* @return object Mail object
*/
function mosCreateMail( $from='', $fromname='', $subject, $body ) {
global $mosConfig_absolute_path, $mosConfig_sendmail;
global $mosConfig_smtpauth, $mosConfig_smtpuser;
global $mosConfig_smtppass, $mosConfig_smtphost;
global $mosConfig_mailfrom, $mosConfig_fromname, $mosConfig_mailer;
$mail = new mosPHPMailer();
$mail->PluginDir = $mosConfig_absolute_path .'/includes/phpmailer/';
$mail->SetLanguage( 'en', $mosConfig_absolute_path . '/includes/phpmailer/language/' );
$mail->CharSet = substr_replace(_ISO, '', 0, 8);
$mail->IsMail();
$mail->From = $from ? $from : $mosConfig_mailfrom;
$mail->FromName = $fromname ? $fromname : $mosConfig_fromname;
$mail->Mailer = $mosConfig_mailer;
// Add smtp values if needed
if ( $mosConfig_mailer == 'smtp' ) {
$mail->SMTPAuth = $mosConfig_smtpauth;
$mail->Username = $mosConfig_smtpuser;
$mail->Password = $mosConfig_smtppass;
$mail->Host = $mosConfig_smtphost;
} else
// Set sendmail path
if ( $mosConfig_mailer == 'sendmail' ) {
if (isset($mosConfig_sendmail))
$mail->Sendmail = $mosConfig_sendmail;
} // if
$mail->Subject = $subject;
$mail->Body = $body;
return $mail;
}
/**
* Mail function (uses phpMailer)
* @param string From e-mail address
* @param string From name
* @param string/array Recipient e-mail address(es)
* @param string E-mail subject
* @param string Message body
* @param boolean false = plain text, true = HTML
* @param string/array CC e-mail address(es)
* @param string/array BCC e-mail address(es)
* @param string/array Attachment file name(s)
* @param string/array Reply-to e-mail address
* @param string/array Reply-to name
*/
function mosMail($from, $fromname, $recipient, $subject, $body, $mode=0, $cc=NULL, $bcc=NULL, $attachment=NULL, $replyto=NULL, $replytoname=NULL ) {
global $mosConfig_debug;
$mail = mosCreateMail( $from, $fromname, $subject, $body );
// activate HTML formatted emails
if ( $mode ) {
$mail->IsHTML(true);
}
if( is_array($recipient) ) {
foreach ($recipient as $to) {
$mail->AddAddress($to);
}
} else {
$mail->AddAddress($recipient);
}
if (isset($cc)) {
if( is_array($cc) )
foreach ($cc as $to) $mail->AddCC($to);
else
$mail->AddCC($cc);
}
if (isset($bcc)) {
if( is_array($bcc) )
foreach ($bcc as $to) $mail->AddBCC($to);
else
$mail->AddBCC($bcc);
}
if ($attachment) {
if ( is_array($attachment) )
foreach ($attachment as $fname) $mail->AddAttachment($fname);
else
$mail->AddAttachment($attachment);
} // if
if ($replyto) {
if ( is_array($replyto) ) {
reset($replytoname);
foreach ($replyto as $to) {
$toname = ((list($key, $value) = each($replytoname))
? $value : "");
$mail->AddReplyTo($to, $toname);
}
} else
$mail->AddReplyTo($replyto, $replytoname);
}
$mailssend = $mail->Send();
if( $mosConfig_debug ) {
//$mosDebug->message( "Mails send: $mailssend");
}
if( $mail->error_count > 0 ) {
//$mosDebug->message( "The mail message $fromname <$from> about $subject to $recipient failed $body ", false );
//$mosDebug->message( "Mailer Error: " . $mail->ErrorInfo . "" );
}
return $mailssend;
} // mosMail
/**
* Initialise GZIP
*/
function initGzip() {
global $mosConfig_gzip, $do_gzip_compress;
$do_gzip_compress = FALSE;
//zlib.output_compression and ob_gzhandler don't get along well so we'll check to make
//that zlib.output_compression is not enable in the php.ini before turning on ob_gzhandler
if ( $mosConfig_gzip == 1 && (int)ini_get('zlib.output_compression') != 1 ) {
$phpver = phpversion();
$useragent = mosGetParam( $_SERVER, 'HTTP_USER_AGENT', '' );
$canZip = mosGetParam( $_SERVER, 'HTTP_ACCEPT_ENCODING', '' );
if ( $phpver >= '4.0.4pl1' &&
( strpos($useragent,'compatible') !== false ||
strpos($useragent,'Gecko') !== false
)
) {
if ( extension_loaded('zlib') ) {
ob_start( 'ob_gzhandler' );
return;
}
} else if ( $phpver > '4.0' ) {
if ( strpos($canZip,'gzip') !== false ) {
if (extension_loaded( 'zlib' )) {
$do_gzip_compress = TRUE;
ob_start();
ob_implicit_flush(0);
header( 'Content-Encoding: gzip' );
return;
}
}
}
}
ob_start();
}
/**
* Perform GZIP
*/
function doGzip() {
global $do_gzip_compress;
if ( $do_gzip_compress ) {
/**
*Borrowed from php.net!
*/
$gzip_contents = ob_get_contents();
ob_end_clean();
$gzip_size = strlen($gzip_contents);
$gzip_crc = crc32($gzip_contents);
$gzip_contents = gzcompress($gzip_contents, 9);
$gzip_contents = substr($gzip_contents, 0, strlen($gzip_contents) - 4);
echo "\x1f\x8b\x08\x00\x00\x00\x00\x00";
echo $gzip_contents;
echo pack('V', $gzip_crc);
echo pack('V', $gzip_size);
} else {
ob_end_flush();
}
}
/**
* Random password generator
* @return password
*/
function mosMakePassword() {
$salt = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$len = strlen($salt);
$makepass="";
mt_srand(10000000*(double)microtime());
for ($i = 0; $i < 8; $i++)
$makepass .= $salt[mt_rand(0,$len - 1)];
return $makepass;
}
if (!function_exists('html_entity_decode')) {
/**
* html_entity_decode function for backward compatability in PHP
* @param string
* @param string
*/
function html_entity_decode ($string, $opt = ENT_COMPAT) {
$trans_tbl = get_html_translation_table (HTML_ENTITIES);
$trans_tbl = array_flip ($trans_tbl);
if ($opt & 1) { // Translating single quotes
// Add single quote to translation table;
// doesn't appear to be there by default
$trans_tbl["'"] = "'";
}
if (!($opt & 2)) { // Not translating double quotes
// Remove double quote from translation table
unset($trans_tbl["""]);
}
return strtr ($string, $trans_tbl);
}
}
/**
* 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 int Index of the mambot being loaded */
var $_loading=null;
/**
* Constructor
*/
function mosMambotHandler() {
$this->_events = array();
}
/**
* 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 $database, $my, $mosConfig_absolute_path;
global $_MAMBOTS;
$group = trim( $group );
$database->setQuery( "SELECT folder, element, published, CONCAT_WS('/',folder,element) AS lookup"
. "\nFROM #__mambots"
. "\nWHERE published >= 1 AND access <= $my->gid AND folder='$group'"
. "\nORDER BY ordering"
);
if (!($bots = $database->loadObjectList())) {
//echo "Error loading Mambots: " . $database->getErrorMsg();
return false;
}
$n = count( $bots);
for ($i = 0; $i < $n; $i++) {
$path = $mosConfig_absolute_path . '/mambots/' . $bots[$i]->folder . '/' . $bots[$i]->element . '.php';
if (file_exists( $path )) {
$this->_loading = count( $this->_bots );
$this->_bots[] = $bots[$i];
require_once( $path );
$this->_loading = null;
}
}
return true;
}
/**
* 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 );
}
/**
* 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 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 ) {
$result = array();
if ($args === null) {
$args = array();
}
if ($doUnpublished) {
// prepend the published argument
array_unshift( $args, null );
}
if (isset( $this->_events[$event] )) {
foreach ($this->_events[$event] as $func) {
if (function_exists( $func[0] )) {
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;
}
/**
* 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 ) {
$doUnpublished=false;
$args =& func_get_args();
array_shift( $args );
if (isset( $this->_events[$event] )) {
foreach ($this->_events[$event] as $func) {
if (function_exists( $func[0] )) {
if ($this->_bots[$func[1]]->published) {
return call_user_func_array( $func[0], $args );
}
}
}
}
return null;
}
}
/**
=======
>>>>>>> .theirs
* Tab Creation handler
* @package Mambo
* @author Phil Taylor
*/
class mosTabs {
/** @var int Use cookies */
var $useCookies = 0;
/**
* Constructor
* Includes files needed for displaying tabs and sets cookie options
* @param int useCookies, if set to 1 cookie will hold last used tab between page refreshes
*/
function mosTabs($useCookies) {
global $mosConfig_live_site;
echo " ";
echo "";
$this->useCookies = $useCookies;
}
/**
* creates a tab pane and creates JS obj
* @param string The Tab Pane Name
*/
function startPane($id){
echo "";
echo "\n";
}
/**
* Ends Tab Pane
*/
function endPane() {
echo "
";
}
/*
* Creates a tab with title text and starts that tabs page
* @param tabText - This is what is displayed on the tab
* @param paneid - This is the parent pane to build this tab on
*/
function startTab( $tabText, $paneid ) {
echo "";
echo "
".$tabText." ";
echo "";
}
/*
* Ends a tab page
*/
function endTab() {
echo "";
}
}
<<<<<<< .mine
if ( $id ) {
$order = mosGetOrderingList( "SELECT ordering AS value, name AS text"
. "\n FROM #__menu"
. "\n WHERE menutype='". $row->menutype ."'"
. "\n AND parent='". $row->parent ."'"
. "\n AND published != '-2'"
. "\n ORDER BY ordering"
);
$ordering = mosHTML::selectList( $order, 'ordering', 'class="inputbox" size="1"', 'value', 'text', intval( $row->ordering ) );
} else {
$ordering = ' '. T_('New items default to the last place. Ordering can be changed after this item is saved.');
}
return $ordering;
}
/**
* build the select list for access level
*/
function Access( &$row ) {
global $database;
$query = 'SELECT id AS value, name AS text FROM #__groups ORDER BY id';
$database->setQuery( $query );
$groups = $database->loadObjectList();
$access = mosHTML::selectList( $groups, 'access', 'class="inputbox" size="3"', 'value', 'text', intval( $row->access ) );
return $access;
}
/**
* build the select list for parent item
*/
function Parent( &$row ) {
global $database;
// get a list of the menu items
$query = "SELECT m.*"
. "\n FROM #__menu m"
. "\n WHERE menutype='$row->menutype'"
. "\n AND published <> -2"
. "\n ORDER BY ordering"
;
$database->setQuery( $query );
$mitems = $database->loadObjectList();
// establish the hierarchy of the menu
$children = array();
// first pass - collect children
foreach ( $mitems as $v ) {
$pt = $v->parent;
$list = @$children[$pt] ? $children[$pt] : array();
array_push( $list, $v );
$children[$pt] = $list;
}
// second pass - get an indent list of the items
$list = mosTreeRecurse( 0, '', array(), $children, 9999, 0, 0 );
// assemble menu items to the array
$mitems = array();
$mitems[] = mosHTML::makeOption( '0', 'Top' );
$this_treename = '';
foreach ( $list as $item ) {
if ( $this_treename ) {
if ( $item->id != $row->id && strpos( $item->treename, $this_treename ) === false) {
$mitems[] = mosHTML::makeOption( $item->id, $item->treename );
}
} else {
if ( $item->id != $row->id ) {
$mitems[] = mosHTML::makeOption( $item->id, $item->treename );
} else {
$this_treename = "$item->treename/";
}
}
}
$parent = mosHTML::selectList( $mitems, 'parent', 'class="inputbox" size="1"', 'value', 'text', $row->parent );
return $parent;
}
/**
* build a radio button option for published state
*/
function Published( &$row ) {
$published = mosHTML::yesnoRadioList( 'published', 'class="inputbox"', $row->published );
return $published;
}
/**
* build the link/url of a menu item
*/
function Link( &$row, $id, $link=NULL ) {
if ( $id ) {
if ( $link ) {
$link = $row->link;
} else {
$link = $row->link .'&Itemid='. $row->id;
}
} else {
$link = NULL;
}
return $link;
}
/**
* build the select list for target window
*/
function Target( &$row ) {
$click[] = mosHTML::makeOption( '0', T_('Parent Window With Browser Navigation') );
$click[] = mosHTML::makeOption( '1', T_('New Window With Browser Navigation') );
$click[] = mosHTML::makeOption( '2', T_('New Window Without Browser Navigation') );
$target = mosHTML::selectList( $click, 'browserNav', 'class="inputbox" size="4"', 'value', 'text', intval( $row->browserNav ) );
return $target;
}
/**
* build the multiple select list for Menu Links/Pages
*/
function MenuLinks( &$lookup, $all=NULL, $none=NULL ) {
global $database;
// get a list of the menu items
$database->setQuery( "SELECT m.*"
. "\n FROM #__menu m"
. "\n WHERE type != 'separator'"
. "\n AND link NOT LIKE '%tp:/%'"
. "\n AND published = '1'"
. "\n ORDER BY menutype, parent, ordering"
);
$mitems = $database->loadObjectList();
$mitems_temp = $mitems;
// establish the hierarchy of the menu
$children = array();
// first pass - collect children
foreach ( $mitems as $v ) {
$id = $v->id;
$pt = $v->parent;
$list = @$children[$pt] ? $children[$pt] : array();
array_push( $list, $v );
$children[$pt] = $list;
}
// second pass - get an indent list of the items
$list = mosTreeRecurse( intval( $mitems[0]->parent ), '', array(), $children, 9999, 0, 0 );
// Code that adds menu name to Display of Page(s)
$text_count = "0";
$mitems_spacer = $mitems_temp[0]->menutype;
foreach ($list as $list_a) {
foreach ($mitems_temp as $mitems_a) {
if ($mitems_a->id == $list_a->id) {
// Code that inserts the blank line that seperates different menus
if ($mitems_a->menutype <> $mitems_spacer) {
$list_temp[] = mosHTML::makeOption( -999, '----' );
$mitems_spacer = $mitems_a->menutype;
}
$text = $mitems_a->menutype." | ".$list_a->treename;
$list_temp[] = mosHTML::makeOption( $list_a->id, $text );
if ( strlen($text) > $text_count) {
$text_count = strlen($text);
}
}
}
}
$list = $list_temp;
$mitems = array();
if ( $all ) {
// prepare an array with 'all' as the first item
$mitems[] = mosHTML::makeOption( 0, T_('All') );
// adds space, in select box which is not saved
$mitems[] = mosHTML::makeOption( -999, '----' );
}
if ( $none ) {
// prepare an array with 'all' as the first item
$mitems[] = mosHTML::makeOption( -999, T_('None') );
// adds space, in select box which is not saved
$mitems[] = mosHTML::makeOption( -999, '----' );
}
// append the rest of the menu items to the array
foreach ($list as $item) {
$mitems[] = mosHTML::makeOption( $item->value, $item->text );
}
$pages = mosHTML::selectList( $mitems, 'selections[]', 'class="inputbox" size="26" multiple="multiple"', 'value', 'text', $lookup );
return $pages;
}
/**
* build the select list to choose a category
*/
function Category( &$menu, $id, $javascript='' ) {
global $database;
$query = "SELECT c.id AS `value`, c.section AS `id`, CONCAT_WS( ' / ', s.title, c.title) AS `text`"
. "\n FROM #__sections AS s"
. "\n INNER JOIN #__categories AS c ON c.section = s.id"
. "\n WHERE s.scope = 'content'"
. "\n ORDER BY s.name,c.name"
;
$database->setQuery( $query );
$rows = $database->loadObjectList();
$category = '';
if ( $id ) {
foreach ( $rows as $row ) {
if ( $row->value == $menu->componentid ) {
$category = $row->text;
}
}
$category .= ' ';
$category .= ' ';
} else {
$category = mosHTML::selectList( $rows, 'componentid', 'class="inputbox" size="10"'. $javascript, 'value', 'text' );
$category .= ' ';
}
return $category;
}
/**
* build the select list to choose a section
*/
function Section( &$menu, $id, $all=0 ) {
global $database;
$query = "SELECT s.id AS `value`, s.id AS `id`, s.title AS `text`"
. "\n FROM #__sections AS s"
. "\n WHERE s.scope = 'content'"
. "\n ORDER BY s.name"
;
$database->setQuery( $query );
if ( $all ) {
$rows[] = mosHTML::makeOption( 0, T_('- All Sections -') );
$rows = array_merge( $rows, $database->loadObjectList() );
} else {
$rows = $database->loadObjectList();
}
if ( $id ) {
foreach ( $rows as $row ) {
if ( $row->value == $menu->componentid ) {
$section = $row->text;
}
}
$section .= ' ';
$section .= ' ';
} else {
$section = mosHTML::selectList( $rows, 'componentid', 'class="inputbox" size="10"', 'value', 'text' );
$section .= ' ';
}
return $section;
}
/**
* build the select list to choose a component
*/
function Component( &$menu, $id ) {
global $database;
$query = "SELECT c.id AS value, c.name AS text, c.link"
. "\n FROM #__components AS c"
. "\n WHERE c.link <> ''"
. "\n ORDER BY c.name"
;
$database->setQuery( $query );
$rows = $database->loadObjectList( );
if ( $id ) {
// existing component, just show name
foreach ( $rows as $row ) {
if ( $row->value == $menu->componentid ) {
$component = $row->text;
}
}
$component .= ' ';
} else {
$component = mosHTML::selectList( $rows, 'componentid', 'class="inputbox" size="10"', 'value', 'text' );
}
return $component;
}
/**
* build the select list to choose a component
*/
function ComponentName( &$menu, $id ) {
global $database;
$query = "SELECT c.id AS value, c.name AS text, c.link"
. "\n FROM #__components AS c"
. "\n WHERE c.link <> ''"
. "\n ORDER BY c.name"
;
$database->setQuery( $query );
$rows = $database->loadObjectList( );
$component = 'Component';
foreach ( $rows as $row ) {
if ( $row->value == $menu->componentid ) {
$component = $row->text;
}
}
return $component;
}
/**
* build the select list to choose an image
*/
function Images( $name, &$active, $javascript=NULL, $directory=NULL ) {
global $mosConfig_absolute_path;
if ( !$javascript ) {
$javascript = "onchange=\"javascript:if (document.forms[0].image.options[selectedIndex].value!='') {document.imagelib.src='../images/stories/' + document.forms[0].image.options[selectedIndex].value} else {document.imagelib.src='../images/blank.png'}\"";
}
if ( !$directory ) {
$directory = '/images/stories';
}
$imageFiles = mosReadDirectory( $mosConfig_absolute_path . $directory );
$images = array( mosHTML::makeOption( '', T_('- Select Image -') ) );
foreach ( $imageFiles as $file ) {
if ( eregi( "bmp|gif|jpg|png", $file ) ) {
$images[] = mosHTML::makeOption( $file );
}
}
$images = mosHTML::selectList( $images, $name, 'class="inputbox" size="1" '. $javascript, 'value', 'text', $active );
return $images;
}
/**
* build the select list for Ordering of a specified Table
*/
function SpecificOrdering( &$row, $id, $query, $neworder=0 ) {
global $database;
if ( $neworder ) {
$text = T_('New items default to the first place. Ordering can be changed after this item is saved.');
} else {
$text = T_('New items default to the last place. Ordering can be changed after this item is saved.');
}
if ( $id ) {
$order = mosGetOrderingList( $query );
$ordering = mosHTML::selectList( $order, 'ordering', 'class="inputbox" size="1"', 'value', 'text', intval( $row->ordering ) );
} else {
$ordering = ' '. $text;
}
return $ordering;
}
/**
* Select list of active users
*/
function UserSelect( $name, $active, $nouser=0, $javascript=NULL, $order='name' ) {
global $database, $my;
$query = "SELECT id AS value, name AS text"
. "\n FROM #__users"
. "\n WHERE block = '0'"
. "\n ORDER BY ". $order
;
$database->setQuery( $query );
if ( $nouser ) {
$users[] = mosHTML::makeOption( '0', T_('- No User -') );
$users = array_merge( $users, $database->loadObjectList() );
} else {
$users = $database->loadObjectList();
}
$users = mosHTML::selectList( $users, $name, 'class="inputbox" size="1" '. $javascript, 'value', 'text', $active );
return $users;
}
/**
* Select list of positions - generally used for location of images
*/
function Positions( $name, $active=NULL, $javascript=NULL, $none=1, $center=1, $left=1, $right=1 ) {
if ( $none ) {
$pos[] = mosHTML::makeOption( '', T_('None') );
}
if ( $center ) {
$pos[] = mosHTML::makeOption( 'center', T_('Center') );
}
if ( $left ) {
$pos[] = mosHTML::makeOption( 'left', T_('Left') );
}
if ( $right ) {
$pos[] = mosHTML::makeOption( 'right', T_('Right') );
}
$positions = mosHTML::selectList( $pos, $name, 'class="inputbox" size="1"'. $javascript, 'value', 'text', $active );
return $positions;
}
/**
* Select list of active categories for components
*/
function ComponentCategory( $name, $section, $active=NULL, $javascript=NULL, $order='ordering', $size=1, $sel_cat=1 ) {
global $database;
$query = "SELECT id AS value, name AS text"
. "\n FROM #__categories"
. "\n WHERE section = '". $section ."'"
. "\n AND published = '1'"
. "\n ORDER BY ". $order
;
$database->setQuery( $query );
if ( $sel_cat ) {
$categories[] = mosHTML::makeOption( '0', T_('- All Categories -') );
$categories = array_merge( $categories, $database->loadObjectList() );
} else {
$categories = $database->loadObjectList();
}
if ( count( $categories ) < 1 ) {
mosRedirect( 'index2.php?option=com_categories§ion='. $section, T_('You must create a category first.') );
}
$category = mosHTML::selectList( $categories, $name, 'class="inputbox" size="'. $size .'" '. $javascript, 'value', 'text', $active );
return $category;
}
/**
* Select list of active sections
*/
function SelectSection( $name, $active=NULL, $javascript=NULL, $order='ordering' ) {
global $database;
$categories[] = mosHTML::makeOption( '0', T_('- All Sections -') );
$query = "SELECT id AS value, title AS text"
. "\n FROM #__sections"
. "\n WHERE published = '1'"
. "\n ORDER BY ". $order
;
$database->setQuery( $query );
$sections = array_merge( $categories, $database->loadObjectList() );
$category = mosHTML::selectList( $sections, $name, 'class="inputbox" size="1" '. $javascript, 'value', 'text', $active );
return $category;
}
/**
* Select list of menu items for a specific menu
*/
function Links2Menu( $type, $and ) {
global $database;
$query = "SELECT *"
. "\n FROM #__menu"
. "\n WHERE type = '". $type ."'"
. "\n AND published = '1'"
. $and
;
$database->setQuery( $query );
$menus = $database->loadObjectList();
return $menus;
}
/**
* Select list of menus
*/
function MenuSelect( $name='menuselect', $javascript=NULL ) {
global $database;
$query = "SELECT params"
. "\n FROM #__modules"
. "\n WHERE module = 'mod_mainmenu'"
;
$database->setQuery( $query );
$menus = $database->loadObjectList();
$total = count( $menus );
for( $i = 0; $i < $total; $i++ ) {
$params = mosParseParams( $menus[$i]->params );
$menuselect[$i]->value = $params->menutype;
$menuselect[$i]->text = $params->menutype;
}
// sort array of objects
SortArrayObjects( $menuselect, 'text', 1 );
$menus = mosHTML::selectList( $menuselect, $name, 'class="inputbox" size="10" '. $javascript, 'value', 'text' );
return $menus;
}
/**
* Internal function to recursive scan the media manager directories
* @param string Path to scan
* @param string root path of this folder
* @param array Value array of all existing folders
* @param array Value array of all existing images
*/
function ReadImages( $imagePath, $folderPath, &$folders, &$images ) {
$imgFiles = mosReadDirectory( $imagePath );
foreach ($imgFiles as $file) {
$ff_ = $folderPath . $file .'/';
$ff = $folderPath . $file;
$i_f = $imagePath .'/'. $file;
if ( is_dir( $i_f ) && $file <> 'CVS' ) {
$folders[] = mosHTML::makeOption( $ff_ );
mosAdminMenus::ReadImages( $i_f, $ff_, $folders, $images );
} else if ( eregi( "bmp|gif|jpg|png", $file ) && is_file( $i_f ) ) {
// leading / we don't need
$imageFile = substr( $ff, 1 );
$images[$folderPath][] = mosHTML::makeOption( $imageFile, $file );
}
}
}
function GetImageFolders( &$folders, $path ) {
$javascript = "onchange=\"changeDynaList( 'imagefiles', folderimages, document.adminForm.folders.options[document.adminForm.folders.selectedIndex].value, 0, 0); previewImage( 'imagefiles', 'view_imagefiles', '$path/' );\"";
$getfolders = mosHTML::selectList( $folders, 'folders', 'class="inputbox" size="1" '. $javascript, 'value', 'text', '/' );
return $getfolders;
}
function GetImages( &$images, $path ) {
if ( !isset($images['/'] ) ) {
$images['/'][] = mosHTML::makeOption( '' );
}
//$javascript = "onchange=\"previewImage( 'imagefiles', 'view_imagefiles', '$path/' )\" onfocus=\"previewImage( 'imagefiles', 'view_imagefiles', '$path/' )\"";
$javascript = "onchange=\"previewImage( 'imagefiles', 'view_imagefiles', '$path/' )\"";
$getimages = mosHTML::selectList( $images['/'], 'imagefiles', 'class="inputbox" size="10" multiple="multiple" '. $javascript , 'value', 'text', null );
return $getimages;
}
function GetSavedImages( &$row, $path ) {
$images2 = array();
foreach( $row->images as $file ) {
$temp = explode( '|', $file );
if( strrchr($temp[0], '/') ) {
$filename = substr( strrchr($temp[0], '/' ), 1 );
} else {
$filename = $temp[0];
}
$images2[] = mosHTML::makeOption( $file, $filename );
}
//$javascript = "onchange=\"previewImage( 'imagelist', 'view_imagelist', '$path/' ); showImageProps( '$path/' ); \" onfocus=\"previewImage( 'imagelist', 'view_imagelist', '$path/' )\"";
$javascript = "onchange=\"previewImage( 'imagelist', 'view_imagelist', '$path/' ); showImageProps( '$path/' ); \"";
$imagelist = mosHTML::selectList( $images2, 'imagelist', 'class="inputbox" size="10" '. $javascript, 'value', 'text' );
return $imagelist;
}
/**
* 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' ) {
global $mosConfig_absolute_path, $mosConfig_live_site, $mainframe;
$cur_template = $mainframe->getTemplate();
if ( $param ) {
$image = $mosConfig_live_site. $param_directory . $param;
if ( $type ) {
$image = ' ';
}
} else if ( $param == -1 ) {
$image = '';
} else {
if ( file_exists( $mosConfig_absolute_path .'/templates/'. $cur_template .'/images/'. $file ) ) {
$image = $mosConfig_live_site .'/templates/'. $cur_template .'/images/'. $file;
} else {
// outputs only path to image
$image = $mosConfig_live_site. $directory . $file;
}
// outputs actual html tag
if ( $type ) {
$image = ' ';
}
}
return $image;
}
/**
* 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 ImageCheckAdmin( $file, $directory='/administrator/images/', $param=NULL, $param_directory='/administrator/images/', $alt=NULL, $name=NULL, $type=1, $align='middle' ) {
global $mosConfig_absolute_path, $mosConfig_live_site, $mainframe;
$cur_template = $mainframe->getTemplate();
if ( $param ) {
$image = $mosConfig_live_site. $param_directory . $param;
if ( $type ) {
$image = ' ';
}
} else if ( $param == -1 ) {
$image = '';
} else {
if ( file_exists( $mosConfig_absolute_path .'/administrator/templates/'. $cur_template .'/images/'. $file ) ) {
$image = $mosConfig_live_site .'/administrator/templates/'. $cur_template .'/images/'. $file;
} else {
$image = $mosConfig_live_site. $directory . $file;
}
// outputs actual html tag
if ( $type ) {
$image = ' ';
}
}
return $image;
}
function menutypes() {
global $database;
$query = "SELECT params"
. "\n FROM #__modules"
. "\n WHERE module = 'mod_mainmenu'"
. "\n ORDER BY title"
;
$database->setQuery( $query );
$modMenus = $database->loadObjectList();
$query = "SELECT menutype"
. "\n FROM #__menu"
. "\n GROUP BY menutype"
. "\n ORDER BY menutype"
;
$database->setQuery( $query );
$menuMenus = $database->loadObjectList();
$menuTypes = '';
foreach ( $modMenus as $modMenu ) {
$check = 1;
mosMakeHtmlSafe( $modMenu) ;
$modParams = mosParseParams( $modMenu->params );
$menuType = @$modParams->menutype;
if (!$menuType) {
$menuType = 'mainmenu';
}
// stop duplicate menutype being shown
if ( !is_array( $menuTypes) ) {
// handling to create initial entry into array
$menuTypes[] = $menuType;
} else {
$check = 1;
foreach ( $menuTypes as $a ) {
if ( $a == $menuType ) {
$check = 0;
}
}
if ( $check ) {
$menuTypes[] = $menuType;
}
}
}
// add menutypes from mos_menu
foreach ( $menuMenus as $menuMenu ) {
$check = 1;
foreach ( $menuTypes as $a ) {
if ( $a == $menuMenu->menutype ) {
$check = 0;
}
}
if ( $check ) {
$menuTypes[] = $menuMenu->menutype;
}
}
// sorts menutypes
asort( $menuTypes );
return $menuTypes;
}
/*
* loads files required for menu items
*/
function menuItem( $item ) {
global $mosConfig_absolute_path;
$path = $mosConfig_absolute_path .'/administrator/components/com_menus/'. $item .'/';
include_once( $path . $item .'.class.php' );
include_once( $path . $item .'.menu.html.php' );
}
}
class mosCommonHTML {
function ContentLegend( ) {
?>
Pending') ?> |
Current') ?> |
Expired') ?> |
menutype; ?>
name; ?>
published ) {
case -2:
echo 'Trashed ';
break;
case 0:
echo 'UnPublished';
break;
case 1:
default:
echo 'Published ';
break;
}
?>
menutype; ?>
type; ?>
name; ?>
published ) {
case -2:
echo ''.T_('Trashed').' ';
break;
case 0:
echo T_('UnPublished');
break;
case 1:
default:
echo ''.T_('Published').' ';
break;
}
?>
checked_out_time, '%A, %d %B %Y' );
$time = mosFormatDate( $row->checked_out_time, '%H:%M' );
$checked_out_text = '';
$checked_out_text .= ''. $row->editor .' ';
$checked_out_text .= ''. $date .' ';
$checked_out_text .= ''. $time .' ';
$checked_out_text .= '
';
$hover = 'onMouseOver="return overlib(\''. $checked_out_text .'\', CAPTION, \'Checked Out\', BELOW, RIGHT);" onMouseOut="return nd();"';
}
$checked = ' ';
return $checked;
}
/*
* Loads all necessary files for JS Overlib tooltips
*/
function loadOverlib() {
global $mosConfig_live_site;
?>
access ) {
$color_access = 'style="color: green;"';
$task_access = 'accessregistered';
} else if ( $row->access == 1 ) {
$color_access = 'style="color: red;"';
$task_access = 'accessspecial';
} else {
$color_access = 'style="color: black;"';
$task_access = 'accesspublic';
}
$href = '
'. $row->groupname .'
'
;
return $href;
}
function CheckedOutProcessing( &$row, $i ) {
global $my;
if ( $row->checked_out ) {
$checked = mosCommonHTML::checkedOut( $row );
} else {
$checked = mosHTML::idBox( $i, $row->id, ($row->checked_out && $row->checked_out != $my->id ) );
}
return $checked;
}
function PublishedProcessing( &$row, $i ) {
$img = $row->published ? 'publish_g.png' : 'publish_x.png';
$task = $row->published ? 'unpublish' : 'publish';
$alt = $row->published ? T_('Published' ): T_('Unpublished');
$action = $row->published ? T_('Unpublish Item') : T_('Publish item');
$href = '
'
;
return $href;
}
}
/**
* Sorts an Array of objects
*/
function SortArrayObjects_cmp( &$a, &$b ) {
global $csort_cmp;
if ( $a->$csort_cmp['key'] > $b->$csort_cmp['key'] ) {
return $csort_cmp['direction'];
}
if ( $a->$csort_cmp['key'] < $b->$csort_cmp['key'] ) {
return -1 * $csort_cmp['direction'];
}
return 0;
}
/**
* Sorts an Array of objects
* sort_direction [1 = Ascending] [-1 = Descending]
*/
function SortArrayObjects( &$a, $k, $sort_direction=1 ) {
global $csort_cmp;
$csort_cmp = array(
'key' => $k,
'direction' => $sort_direction
);
usort( $a, 'SortArrayObjects_cmp' );
unset( $csort_cmp );
}
/**
* Sends mail to admin
*/
function mosSendAdminMail( $adminName, $adminEmail, $email, $type, $title, $author ) {
global $mosConfig_live_site;
$subject = T_('User Submitted')." '$type'";
$message = T_('_MAIL_MSG');
$message = sprintf(T_('Hello %s,\n\n\nA user submitted %s:\n [ %s ]\n has been just been submitted by user:\n [ %s ]\n for %s.\n\n\n\n
Please go to %s/administrator to view and approve this %s.\n\n
Please do not respond to this message as it is automatically generated and is for information purposes only\n'), $adminName, $type, $title, $author, $mosConfig_live_site, $mosConfig_live_site, $type);
mosMail($mosConfig_mailfrom, $mosConfig_fromname, $adminEmail, $subject, $message);
}
/*
* Includes pathway file
*/
function mosPathWay() {
$Itemid = mosGetParam($_REQUEST,'Itemid','');
require $GLOBALS['mosConfig_absolute_path'] . '/includes/pathway.php';
}
/**
* Displays a not authorised message
*
* If the user is not logged in then an addition message is displayed.
*/
function mosNotAuth() {
global $my;
echo T_('You are not authorized to view this resource.');
if ($my->id < 1) {
echo " " . T_('You need to login.');
}
}
/**
* Replaces & with & for xhtml compliance
*
* Needed to handle unicode conflicts due to unicode conflicts
*/
function ampReplace( $text ) {
$text = str_replace( '', '*-*', $text );
$text = str_replace( '&', '&', $text );
$text = str_replace( '*-*', '', $text );
return $text;
}
/**
* Prepares results from search for display
* @param string The source string
* @param int Number of chars to trim
* @param string The searchword to select around
* @return string
*/
function mosPrepareSearchContent( $text, $length=200, $searchword ) {
// strips tags won't remove the actual jscript
$text = preg_replace( "''si", "", $text );
$text = preg_replace( '/{.+?}/', '', $text);
//$text = preg_replace( '/]*>([^<]+)<\/a>/is','\2', $text );
return mosSmartSubstr( strip_tags( $text ), $length, $searchword );
}
/**
* returns substring of characters around a searchword
* @param string The source string
* @param int Number of chars to return
* @param string The searchword to select around
* @return string
*/
function mosSmartSubstr($text, $length=200, $searchword) {
$wordpos = strpos(strtolower($text), strtolower($searchword));
$halfside = intval($wordpos - $length/2 - strlen($searchword));
if ($wordpos && $halfside > 0) {
return '...' . substr($text, $halfside, $length);
} else {
return substr( $text, 0, $length);
}
}
/**
* Chmods files and directories recursively to given permissions. Available from 4.5.2 up.
* @param path The starting file or directory (no trailing slash)
* @param filemode Integer value to chmod files. NULL = dont chmod files.
* @param dirmode Integer value to chmod directories. NULL = dont chmod directories.
* @return TRUE=all succeeded FALSE=one or more chmods failed
*/
function mosChmodRecursive($path, $filemode=NULL, $dirmode=NULL)
{
$ret = TRUE;
if (is_dir($path)) {
$dh = opendir($path);
while ($file = readdir($dh)) {
if ($file != '.' && $file != '..') {
$fullpath = $path.'/'.$file;
if (is_dir($fullpath)) {
if (!mosChmodRecursive($fullpath, $filemode, $dirmode))
$ret = FALSE;
} else {
if (isset($filemode))
if (!@chmod($fullpath, $filemode))
$ret = FALSE;
} // if
} // if
} // while
closedir($dh);
if (isset($dirmode))
if (!@chmod($path, $dirmode))
$ret = FALSE;
} else {
if (isset($filemode))
$ret = @chmod($path, $filemode);
} // if
return $ret;
} // mosChmodRecursive
/**
* Chmods files and directories recursively to mos global permissions. Available from 4.5.2 up.
* @param path The starting file or directory (no trailing slash)
* @param filemode Integer value to chmod files. NULL = dont chmod files.
* @param dirmode Integer value to chmod directories. NULL = dont chmod directories.
* @return TRUE=all succeeded FALSE=one or more chmods failed
*/
function mosChmod($path)
{
global $mosConfig_fileperms, $mosConfig_dirperms;
$filemode = NULL;
if ($mosConfig_fileperms != '')
$filemode = octdec($mosConfig_fileperms);
$dirmode = NULL;
if ($mosConfig_dirperms != '')
$dirmode = octdec($mosConfig_dirperms);
if (isset($filemode) || isset($dirmode))
return mosChmodRecursive($path, $filemode, $dirmode);
return TRUE;
} // mosChmod
/**
* Function to convert array to integer values
*/
function mosArrayToInts( &$array, $default=null ) {
if (is_array( $array )) {
$n = count( $array );
for ($i = 0; $i < $n; $i++) {
$array[$i] = intval( $array[$i] );
}
} else {
if (is_null( $default )) {
return array();
} else {
return array( $default );
}
}
}
=======
>>>>>>> .theirs
// ----- NO MORE CLASSES OR FUNCTIONS PASSED THIS POINT -----
// Post class declaration initialisations
// some version of PHP don't allow the instantiation of classes
// before they are defined
?>