setQuery("SELECT id FROM #__menu WHERE link = 'index.php?option=com_comprofiler' AND published=1 AND access " . ( $_CB_framework->myCmsGid() == 0 ? "= " : "<= " ) . (int) $_CB_framework->myCmsGid() );
$Itemid = (int) $_CB_database->loadResult();
// } else {
// $Itemid = (int) cbGetParam( $_REQUEST, 'Itemid', 0 );
// }
if ( ! $Itemid ) { // if no user profile, try getting itemid of the default list:
$_CB_database->setQuery("SELECT id FROM #__menu WHERE link = 'index.php?option=com_comprofiler&task=usersList' AND published=1 AND access " . ( $_CB_framework->myCmsGid() == 0 ? "= " : "<= " ) . (int) $_CB_framework->myCmsGid() );
$Itemid = (int) $_CB_database->loadResult();
}
if ( ( ! $Itemid ) && $defaultItemid && ( checkJversion() != 1 ) ) {
/** Nope, just use the homepage then. * NO: USE NONE: Homepage itemid isn't appropriate at all ! better use none !
$query = "SELECT id"
. "\n FROM #__menu"
. "\n WHERE menutype = 'mainmenu'"
. "\n AND published = 1"
. "\n ORDER BY parent, ordering"
. "\n LIMIT 1"
;
$_CB_database->setQuery( $query );
$Itemid = (int) $_CB_database->loadResult();
*/
$Itemid = 0;
}
$_CB__Cache_ProfileItemid = $Itemid;
}
if ( $_CB__Cache_ProfileItemid ) {
if ( is_bool( $htmlspecialchars ) ) {
return ( $htmlspecialchars ? "&" : "&") . "Itemid=" . $_CB__Cache_ProfileItemid;
} else {
return $_CB__Cache_ProfileItemid;
}
} else {
return null;
}
}
/**
* Includes CB library
* --- usage: cbimport('cb.xml.simplexml');
*
* @param string $path
*/
function cbimport( $lib ) {
global $_CB_framework;
static $imported = array();
static $tmpClasses = array( 'cb.html', 'cb.tabs', 'cb.field', 'cb.calendar', 'cb.connection', 'cb.notification' );
if ( ! isset( $imported[$lib] ) ) {
$imported[$lib] = true;
$liblow = strtolower( $lib );
$pathAr = explode( '.', $liblow );
if ( $pathAr[0] == 'language' ) {
$langPath = $_CB_framework->getCfg( 'absolute_path' ) . '/components/com_comprofiler/plugin/language';
$lang = $_CB_framework->getCfg( 'lang' );
if ( in_array( $pathAr[1], array( 'front', 'all' ) ) ) {
$filename = $lang . '.php';
} else {
$filename = $pathAr[1] . '_language.php';
}
if ( ! file_exists( $langPath . '/' . $lang . '/' . $filename ) ) {
$lang = 'default_language';
if ( in_array( $pathAr[1], array( 'front', 'all' ) ) ) {
$filename = $lang . '.php';
}
}
@include_once( $langPath . '/' . $lang . '/' . $filename );
} elseif ( $lib == 'cb.plugins' ) {
// this part is temporary until we refactor those 2 files into the corresponding CB libraries:
require_once( $_CB_framework->getCfg('absolute_path') . '/administrator/components/com_comprofiler/plugin.class.php' );
} elseif ( in_array( $lib, $tmpClasses ) ) {
// this part is temporary until we refactor those 2 files into the corresponding CB libraries:
if ( ! isset( $imported['cb.plugins'] ) ) {
$imported['cb.plugins'] = true;
require_once( $_CB_framework->getCfg('absolute_path') . '/administrator/components/com_comprofiler/plugin.class.php' );
}
if ( ! isset( $imported['class'] ) ) {
$imported['class'] = true;
require_once( $_CB_framework->getCfg('absolute_path') . '/administrator/components/com_comprofiler/comprofiler.class.php' );
}
} elseif ( $lib == 'cb.imgtoolbox' ) {
// this part is temporary until we refactor those 2 files into the corresponding CB libraries:
require_once( $_CB_framework->getCfg('absolute_path') . '/administrator/components/com_comprofiler/imgToolbox.class.php' );
} elseif ( $lib == 'cb.snoopy' ) {
require_once( $_CB_framework->getCfg('absolute_path') . '/administrator/components/com_comprofiler/Snoopy.class.php' );
} else {
array_pop( $pathAr );
$filepath = implode( '/', $pathAr ) . (count( $pathAr ) ? '/' : '' ) . $liblow . '.php';
require_once( $_CB_framework->getCfg('absolute_path') . '/administrator/components/com_comprofiler/library/' . $filepath );
}
}
}
/**
* Does the opposite of htmlspecialchars()
*
* @param string $text
* @return string
*/
function cbUnHtmlspecialchars( $text ) {
return str_replace( array( "&", """, "'", "<", ">" ), array( "&", "\"", "'", "<", ">" ), $text );
}
/**
* String based find and replace that is case insensitive and works on php4 too
* same as PHP5 str_ireplace()
*
* @param string $search value to look for
* @param string $replace value to replace with
* @param string $subject text to be searched
* @return string with text searched and replaced
*/
function cbstr_ireplace( $search, $replace, $subject ) {
if ( function_exists('str_ireplace') ) {
return str_ireplace($search,$replace,$subject); // php 5 only
}
$srchlen = strlen($search); // lenght of searched string
$result = "";
while ( true == ( $find = stristr( $subject, $search ) ) ) { // find $search text in $subject - case insensitiv
$srchtxt = substr($find,0,$srchlen); // get new case-sensitively-correct search text
$pos = strpos( $subject, $srchtxt ); // stripos is php5 only...
$result .= substr( $subject, 0, $pos ) . $replace; // replace found case insensitive search text with $replace
$subject = substr( $subject, $pos + $srchlen );
}
return $result . $subject;
}
/**
* Translates text strings from CB and core cms ('_UE_....') into current language
*
* @param string $text
* @return string
*/
function getLangDefinition($text) {
// check for '::' as a workaround of bug #42770 in PHP 5.2.4 with optimizers:
if ( ( strpos( $text, '::' ) === false ) && defined( $text ) ) {
$returnText = constant( $text );
} else {
$returnText = $text; // not yet: CBTxt::T( $text );
}
return $returnText;
}
/**
* Check Mambo/Joomla/others version for API
*
* @param string $info 'api', 'product', 'release'
* @return mixed 'api' : API version: =0 = mambo 4.5.0-4.5.3+Joomla 1.0.x, =1 = Joomla! 1.1, >1 newever ones: maybe compatible, <0: -1: Mambo 4.6
* 'product' : product name
* 'release' : php-style release number
*/
function checkJversion( $info = 'api' ) {
static $version = array();
if ( isset( $version[$info] ) ) {
return $version[$info];
}
if ( class_exists( 'JVersion' ) ) {
$VO = new JVersion();
} else {
global $_VERSION;
if ( $_VERSION ) {
$VO = $_VERSION;
} else {
trigger_error( 'Unable to determine CMS version.', E_USER_ERROR );
die();
}
}
switch ( $info ) {
case 'api':
if ( $VO->PRODUCT == "Mambo" ) {
if ( strncasecmp( $VO->RELEASE, "4.6", 3 ) < 0 ) {
$version[$info] = 0;
} else {
$version[$info] = -1;
}
} elseif ( $VO->PRODUCT == "Elxis" ) {
$version[$info] = 0;
} elseif ( $VO->PRODUCT == "MiaCMS" ) {
$version[$info] = -1;
} elseif ( ($VO->PRODUCT == "Joomla!") || ($VO->PRODUCT == "Accessible Joomla!") ) {
if (strncasecmp($VO->RELEASE, "1.0", 3)) {
$version[$info] = 1;
} else {
$version[$info] = 0;
}
} else {
$version[$info] = 0;
}
break;
case 'product':
$version[$info] = $VO->PRODUCT;
break;
case 'release':
$version[$info] = $VO->RELEASE;
break;
case 'dev_level':
$version[$info] = $VO->DEV_LEVEL;
break;
default:
break;
}
return $version[$info];
}
/**
* Utility function to return a value from a named array or a specified default.
* TO CONTRARY OF MAMBO AND JOOMLA mos Get Param:
* 1) DOES NOT MODIFY ORIGINAL ARRAY
* 2) Does sanitize ints
* 3) Does return default array() for a default value array(0) which indicates sanitizing an array of ints.
*
* @param array A named array
* @param string The key to search for
* @param mixed The default value to give if no key found
* @param int An options mask: _MOS_NOTRIM prevents trim, _MOS_ALLOWHTML allows safe html, _MOS_ALLOWRAW allows raw input
*/
define( "_CB_NOTRIM", 0x0001 );
//define( "_MOS_ALLOWHTML", 0x0002 );
define( "_CB_ALLOWRAW", 0x0004 );
function cbGetParam( &$arr, $name, $def=null, $mask=0 ) {
static $noHtmlFilter = null;
if ( isset( $arr[$name] ) ) {
if ( is_array( $arr[$name] ) ) {
$ret = array();
foreach ( array_keys( $arr[$name] ) as $k ) {
$ret[$k] = cbGetParam( $arr[$name], $k, $def, $mask);
if ( $def === array( 0 ) ) {
$ret[$k] = (int) $ret[$k];
}
}
} else {
$ret = $arr[$name];
if ( is_string( $ret ) ) {
if ( ! ( $mask & _CB_NOTRIM ) ) {
$ret = trim( $ret );
}
if ( ! ( $mask & _CB_ALLOWRAW ) ) {
if ( is_null( $noHtmlFilter ) ) {
cbimport( 'phpinputfilter.inputfilter' );
$noHtmlFilter = new CBInputFilter( /* $tags, $attr, $tag_method, $attr_method, $xss_auto */ );
}
$ret = $noHtmlFilter->process( $ret );
}
if ( is_int( $def ) ) {
$ret = (int) $ret;
} elseif ( is_float( $def ) ) {
$ret = (float) $ret;
} elseif ( ! get_magic_quotes_gpc() ) {
$ret = addslashes( $ret );
}
}
}
return $ret;
} elseif ( false !== ( $firstSeparator = strpos( $name, '[' ) ) ) {
// html-input-name-encoded array selection, e.g. a[b][c]
$indexes = null;
$mainArrName = substr( $name, 0, $firstSeparator );
$count = preg_match_all( '/\\[([^\\[\\]]+)\\]/', substr( $name, $firstSeparator ), $indexes );
if ( isset( $arr[$mainArrName] ) && ( $count > 0 ) ) {
$a = $arr[$mainArrName];
for ( $i = 0; $i < ( $count - 1 ); $i++ ) {
if ( ! isset( $a[$indexes[1][$i]] ) ) {
$a = null;
break;
}
$a = $a[$indexes[1][$i]];
}
} else {
$a = null;
}
if ( $a !== null ) {
return cbGetParam( $a, $indexes[1][$i], $def, $mask );
}
}
if ( $def === array( 0 ) ) {
return array();
}
return $def;
}
/**
* Redirects browser to new $url with a $message .
* No return from this function !
*
* @param string $url
* @param string $message
* @param string $messageType 'message', 'error'
*/
function cbRedirect( $url, $message = '', $messageType = 'message' ) {
global $_CB_framework, $_CB_database;
if ( ( $_CB_framework->getCfg( 'debug' ) > 0 ) && ( ob_get_length() || ( $_CB_framework->getCfg( 'debug' ) > 1 ) ) ) {
$outputBufferLength = ob_get_length();
echo ' During it's normal operations Community Builder often redirects you between pages and this causes potentially interesting debug information to be missed. "
. "When your site is in debug mode (global joomla/mambo config is site debug ON), some of these automatic redirects are disabled. "
. "This is a normal feature of the debug mode and does not directly mean that you have any problems.
Site Debug mode: CB redirection';
if ( $message ) {
echo ' with ' . $messageType . ' "' . $message . '"';
}
if ( $outputBufferLength ) {
echo ' without empty output';
}
echo "
';
foreach ( $_CB_database->_db->_log as $k => $sql ) {
echo $k + 1 . "\n" . htmlspecialchars( $sql ) . '
';
}
echo ''
. 'POST: ';
var_export( $_POST );
echo '';
die();
} else {
$_CB_framework->redirect( $url, $message, $messageType );
}
}
/**
* stripslashes() string or nested array of strings
*
* @param string|array with slashes
* @return string|array without slashes
*/
function cbStripslashes( $value ) {
$striped = '';
if ( is_string( $value ) ) {
$striped = stripslashes( $value );
} else {
if ( is_array( $value ) ) {
$striped = array();
foreach ( array_keys( $value ) as $k ) {
$striped[$k] = cbStripslashes( $value[$k] );
}
} else {
$striped = $value;
}
}
return $striped;
}
/**
* Returns full path to template directory, as live URL (live_site, by default), absolute directory path
*
* @param string $output 'live_site' (with trailing /), 'absolute_path' (without trailing /), 'dir' name only (depreciated was: int DEPRECIATED: info for backwards-compatibility: user interface : 1: frontend, 2: backend (not used anymore)
* @param string $templateName null: according to settings, string: name of template (directory)
* @return string Template directory path with trailing '/'
*/
function selectTemplate( $output = 'live_site', $templateName = null ) {
global $_CB_framework, $ueConfig;
if ( $templateName == null ) {
if ( $_CB_framework->getUi() == 1 ) {
$templateName = $ueConfig['templatedir'];
} else {
$templateName = 'luna';
}
}
if ( $output == 'dir' ) {
return $templateName;
} elseif ( $output == 'absolute_path' ) {
return $_CB_framework->getCfg( 'absolute_path' ) . '/components/com_comprofiler/plugin/templates/' . $templateName;
} else {
return $_CB_framework->getCfg( 'live_site' ) . '/components/com_comprofiler/plugin/templates/' . $templateName . '/';
}
}
function cbSpoofString( $string = null, $secret = null ) {
global $_CB_framework;
$date = date( 'dmY' );
if ( $string === null ) {
$salt = array();
$salt[0] = mt_rand( 1, 2147483647 );
$salt[1] = mt_rand( 1, 2147483647 ); // 2 * 31 bits random
} else {
$salt = sscanf( $string, 'cbm_%08x_%08x_%s' );
if ( $string != sprintf( 'cbm_%08x_%08x_%s', $salt[0], $salt[1], md5( $salt[0] . $date . $_CB_framework->getUi() . $_CB_framework->getCfg( 'db' ) . $_CB_framework->getCfg('secret') . $secret . $salt[1] ) ) ) {
$date = date( 'dmY', time() - 64800 ); // 18 extra-hours of grace after midnight.
}
}
return sprintf( 'cbm_%08x_%08x_%s', $salt[0], $salt[1], md5( $salt[0] . $date . $_CB_framework->getUi() . $_CB_framework->getCfg( 'db' ) . $_CB_framework->getCfg('secret') . $secret . $salt[1] ) );
}
function cbSpoofField() {
return 'cbsecuritym3';
}
/**
* Computes and returns an antifspoofing additional input tag
*
* @return string "\n";
}
function _cbjosSpoofCheck($array, $badStrings) {
foreach ($array as $v) {
foreach ($badStrings as $v2) {
if (is_array($v)) {
_cbjosSpoofCheck($v, $badStrings);
} else if (strpos( $v, $v2 ) !== false) {
header( "HTTP/1.0 403 Forbidden" );
exit( _UE_NOT_AUTHORIZED );
}
}
}
}
/**
* Checks spoof value and other spoofing and injection tricks
*
* @param string $secret extra-hashing value for this particular spoofCheck
* @param string $var 'POST', 'GET', 'REQUEST'
* @param int $mode 1: exits with script to display error and go back, 2: returns true or false.
* @return boolean or exit If $mode = 2 : returns false if session expired.
*/
function cbSpoofCheck( $secret = null, $var = 'POST', $mode = 1 ) {
global $_POST, $_GET, $_REQUEST;
if ( _CB_SPOOFCHECKS ) {
if ( $var == 'GET' ) {
$validateValue = cbGetParam( $_GET, cbSpoofField(), '' );
} elseif ( $var == 'REQUEST' ) {
$validateValue = cbGetParam( $_REQUEST, cbSpoofField(), '' );
} else {
$validateValue = cbGetParam( $_POST, cbSpoofField(), '' );
}
if ( ( ! $validateValue ) || ( $validateValue != cbSpoofString( $validateValue, $secret ) ) ) {
if ( $mode == 2 ) {
return false;
}
_cbExpiredSessionJSterminate( 200 );
exit;
}
}
// First, make sure the form was posted from a browser.
// For basic web-forms, we don't care about anything
// other than requests from a browser:
if (!isset( $_SERVER['HTTP_USER_AGENT'] )) {
header( 'HTTP/1.0 403 Forbidden' );
exit( _UE_NOT_AUTHORIZED );
}
// Make sure the form was indeed POST'ed:
// (requires your html form to use: action="post")
if (!$_SERVER['REQUEST_METHOD'] == 'POST' ) {
header( 'HTTP/1.0 403 Forbidden' );
exit( _UE_NOT_AUTHORIZED );
}
// Attempt to defend against header injections:
$badStrings = array(
'Content-Type:',
'MIME-Version:',
'Content-Transfer-Encoding:',
'bcc:',
'cc:'
);
// Loop through each POST'ed value and test if it contains
// one of the $badStrings:
foreach ($_POST as $v){
foreach ($badStrings as $v2) {
if (is_array($v)) {
_cbjosSpoofCheck($v, $badStrings);
} else if (strpos( $v, $v2 ) !== false) {
header( "HTTP/1.0 403 Forbidden" );
exit( _UE_NOT_AUTHORIZED );
}
}
}
// Made it past spammer test, free up some memory
// and continue rest of script:
unset( $v, $v2, $badStrings );
return true;
}
function _cbExpiredSessionJSterminate( $code = 403 ) {
if ( $code == 403 ) {
header( 'HTTP/1.0 403 Forbidden' );
}
echo " \n";
exit;
}
/**
* CB Classes
*/
/**
* Parameters handler
* @package Joomla/Mambo Community Builder
*/
class cbParamsBase {
/** @var object */
var $_params = null;
/** @var string The raw params string */
var $_raw = null;
/**
* Constructor
*
* @param string $paramsValues The raw parms text
*/
function cbParamsBase( $paramsValues ) {
$this->_params = $this->parse( $paramsValues );
$this->_raw = $paramsValues;
}
/**
* Loads from the plugins database
*
* @param string $element The plugin element name
* @return boolean true: could load, false: query error.
*/
function loadFromDB( $element ) {
global $_CB_database;
$_CB_database->setQuery("SELECT params FROM `#__comprofiler_plugin` WHERE element = '" . $_CB_database->getEscaped( $element ) . "'" );
$text = $_CB_database->loadResult();
$this->_params = $this->parse( $text );
$this->_raw = $text;
return ( $text !== null );
}
/**
* Transforms the existing params to a ini string
* @since 1.2.1
*
* @return string
*/
function toIniString() {
$txt = array();
foreach ( get_object_vars( $this->_params ) as $k => $v ) {
if ( strstr( $v, "\n" ) ) {
$v = str_replace( array( "\\", "\n", "\r" ), array( "\\\\", '\\n', '\\r' ) , $v );
}
$txt[] = $k . '=' . $v;
}
return implode( "\n", $txt );
}
/**
* Returns an array of all current params
*
* @return array
*/
function toParamsArray( ) {
return get_object_vars( $this->_params );
}
/**
* Sets a value to a param
*
* @param string $key The name of the param
* @param string $value The value of the parameter
* @return string The set value
*/
function set( $key, $value='' ) {
$this->_params->$key = $value;
return $value;
}
/**
* Un-Sets a param
* @since 1.2.1
*
* @param string $key The name of the param
*/
function unsetParam( $key ) {
unset( $this->_params->$key );
}
/**
* Sets a default value to param if not alreay assigned
*
* @param string $key The name of the param
* @param string $value The value of the parameter
* @return string The set value
*/
function def( $key, $value='' ) {
return $this->set( $key, $this->get( $key, $value ) );
}
/**
* Gets a param value
*
* @param string $key The name of the param
* @param mixed $default The default value if not found
* @return string
*/
function get( $key, $default=null ) {
if ( isset( $this->_params->$key ) ) {
if (is_array( $default ) ) {
return explode( '|*|', $this->_params->$key );
} else {
return $this->_params->$key;
}
} else {
return $default;
}
}
/**
* Parse an .ini string, based on phpDocumentor phpDocumentor_parse_ini_file function
*
* @param mixed $txt The ini string or array of lines
* @param boolean $process_sections Add an associative index for each section [in brackets]
* @param boolean $asArray Returns an array instead of an object
* @return object|array
*/
function parse( $txt, $process_sections = false, $asArray = false ) {
if (is_string( $txt )) {
$lines = explode( "\n", $txt );
} else if (is_array( $txt )) {
$lines = $txt;
} else {
$lines = array();
}
$obj = $asArray ? array() : new stdClass();
$sec_name = '';
$unparsed = 0;
if (!$lines) {
return $obj;
}
foreach ($lines as $line) {
// ignore comments
if ($line && $line[0] == ';') {
continue;
}
$line = trim( $line );
if ($line == '') {
continue;
}
if ($line && $line[0] == '[' && $line[strlen($line) - 1] == ']') {
$sec_name = substr( $line, 1, strlen($line) - 2 );
if ($process_sections) {
if ($asArray) {
$obj[$sec_name] = array();
} else {
$obj->$sec_name = new stdClass();
}
}
} else {
if ( false !== ( $pos = strpos( $line, '=' ) ) ) {
$property = trim( substr( $line, 0, $pos ) );
if (substr($property, 0, 1) == '"' && substr($property, -1) == '"') {
$property = stripcslashes(substr($property,1,count($property) - 2));
}
$value = trim( substr( $line, $pos + 1 ) );
if ($value == 'false') {
$value = false;
}
if ($value == 'true') {
$value = true;
}
if (substr( $value, 0, 1 ) == '"' && substr( $value, -1 ) == '"') {
$value = stripcslashes( substr( $value, 1, count( $value ) - 2 ) );
}
if ($process_sections) {
$value = str_replace( array( '\n', '\r' ), array( "\n", "\r" ), $value );
if ($sec_name != '') {
if ($asArray) {
$obj[$sec_name][$property] = $value;
} else {
$obj->$sec_name->$property = $value;
}
} else {
if ($asArray) {
$obj[$property] = $value;
} else {
$obj->$property = $value;
}
}
} else {
$value = str_replace( array( '\n', '\r' ), array( "\n", "\r" ), $value );
if ($asArray) {
$obj[$property] = $value;
} else {
$obj->$property = $value;
}
}
} else {
if ($line && trim($line[0]) == ';') {
continue;
}
if ($process_sections) {
$property = '__invalid' . $unparsed++ . '__';
if ($process_sections) {
if ($sec_name != '') {
if ($asArray) {
$obj[$sec_name][$property] = trim($line);
} else {
$obj->$sec_name->$property = trim($line);
}
} else {
if ($asArray) {
$obj[$property] = trim($line);
} else {
$obj->$property = trim($line);
}
}
} else {
if ($asArray) {
$obj[$property] = trim($line);
} else {
$obj->$property = trim($line);
}
}
}
}
}
}
return $obj;
}
}
/**
* Lightweight CB user class read-only for use outside CB
*
* @author Beat
* @license GPL v2
*/
class CBuser {
/**
* CB user object for database tables
* @var moscomprofilerUser
*/
var $_cbuser;
/**
* the CB tabs object for that user
* @var cbTabs
*/
var $_cbtabs = null;
/** Db
* @var CBdatabase */
var $_db;
/**
* Constructor
*/
function CBuser( ) {
/*
global $_CB_database, $database;
if ( $_CB_database ) {
$this->_db =& $_CB_database;
} else {
$this->_db =& $database;
}
*/
global $_CB_database;
$this->_db =& $_CB_database;
}
/*
* Gets The reference instance of CBuser for user id, or a new instance if $userId == 0
*
* @param int $userId
* @return CBUser|NULL Returns NULL if Id is specified, but not loaded.
*
function & getInstance( $userId ) {
static $instances = array();
$userIdInt = (int) $userId;
if ( $userIdInt ) {
if ( ! isset( $instances[$userIdInt] ) ) {
$instances[$userIdInt] = new CBuser();
if ( ! $instances[$userIdInt]->load( $userId ) ) {
$null = null;
return $null;
}
}
return $instances[$userIdInt];
} else {
$cbUser = new CBuser();
$cbUser->_cbuser = new moscomprofilerUser( $cbUser->_db );
return $cbUser;
}
}
*/
/**
* Gets The reference instance of CBuser for user id, or a new instance if $userId == 0
* @static
* *
* @param int|null $userId
* @return CBuser | null Returns NULL if Id is specified, but not loaded.
*/
function & getInstance( $userId ) {
if ( $userId !== null ) {
$userId = (int) $userId;
}
$user =& CBuser::_getOrSetInstance( $userId );
return $user;
}
/**
* Creates and sets a new instance of CBuser to $user
* @static
*
* @param moscomprofilerUser $user
* @return CBuser
*/
function & setUserGetCBUserInstance( & $user ) {
if ( is_object( $user ) ) {
return CBuser::_getOrSetInstance( $user );
} else {
trigger_error( 'CBUser::setUserGetCBUserInstance called without object', E_USER_ERROR );
$null = null;
return $null;
}
}
/**
* Private storage holder of the instances of CBUser
* @access private
* @static
*
* @param int|moscomprofilerUser|null $userOrValidId
* @return CBUser|null
*/
function & _getOrSetInstance( & $userOrValidId ) {
static $instances = array();
if ( is_int( $userOrValidId ) && ( $userOrValidId !== 0 ) ) {
if ( ! isset( $instances[$userOrValidId] ) ) {
$instances[$userOrValidId] = new CBuser();
if ( ! $instances[$userOrValidId]->load( $userOrValidId ) ) {
unset( $instances[$userOrValidId] );
$null = null;
return $null;
}
}
return $instances[$userOrValidId];
} elseif ( is_object( $userOrValidId ) && isset( $userOrValidId->id ) && $userOrValidId->id ) {
// overwrite on purpose previous cached user, if any:
$instances[(int) $userOrValidId->id] = new CBuser();
$instances[(int) $userOrValidId->id]->loadCbRow( $userOrValidId );
return $instances[(int) $userOrValidId->id];
} else {
$cbUser = new CBuser();
$cbUser->_cbuser = new moscomprofilerUser( $cbUser->_db );
return $cbUser;
}
}
function load( $cbUserId ) {
cbimport( 'cb.tables' );
$this->_cbuser = new moscomprofilerUser( $this->_db );
return $this->_cbuser->load( $cbUserId );
}
function loadCmsUser( $cmsUserId ) {
return $this->load( $cmsUserId ); // for now it's the same but use right one please
}
function loadCbRow( &$row ) {
$this->_cbuser =& $row;
}
/**
* Returns the User's profile data
*
* @return moscomprofilerUser
*/
function & getUserData( ) {
return $this->_cbuser;
}
// EXPERIMENTAL STUFF NEW IN 1.2 RC 3:
/**
* Creates if needed cbTabs object
*
* @param boolean $outputTabpaneScript
* @return cbTabs
*/
function & _getCbTabs( $outputTabpaneScript = true ) {
if ( $this->_cbtabs === null ) {
global $_CB_framework;
$this->_cbtabs = new cbTabs( 0, $_CB_framework->getUi(), null, $outputTabpaneScript );
}
return $this->_cbtabs;
}
/**
* Formatter:
* Returns a field in specified format
*
* @param string $fieldName Name of field to render
* @param mixed $defaultValue Value if field is not in reach of viewer user or innexistant
* @param string $output 'html', 'xml', 'json', 'php', 'csvheader', 'csv', 'rss', 'fieldslist', 'htmledit'
* @param string $formatting 'tr', 'td', 'div', 'span', 'none', 'table'??
* @param string $reason 'profile' for user profile view and edit, 'register' for registration, 'search' for searches
* @param int $list_compare_types IF reason == 'search' : 0 : simple 'is' search, 1 : advanced search with modes, 2 : simple 'any' search
* @return mixed
*/
function getField( $fieldName, $defaultValue = null, $output = 'html', $formatting = 'none', $reason = 'profile', $list_compare_types = 0 ) {
global $_CB_framework, $_PLUGINS;
$tabs =& $this->_getCbTabs();
$fields = $tabs->_getTabFieldsDb( null, $this->getInstance( $_CB_framework->myId() ), $reason, $fieldName );
if ( isset( $fields[0] ) ) {
$field = $fields[0];
$value = $_PLUGINS->callField( $field->type, 'getFieldRow', array( &$field, &$this->_cbuser, $output, $formatting, $reason, $list_compare_types ), $field );
} else {
$value = $defaultValue;
}
return $value;
}
function getPosition( $position ) {
$userViewTabs = $this->getProfileView( $position );
if ( isset( $userViewTabs[$position] ) ) {
return $userViewTabs[$position];
} else {
return null;
}
}
function getTab( $tab ) {
$tabs =& $this->_getCbTabs();
$tabs->generateViewTabsContent( $this->_cbuser, '', $tab );
return $tabs->getProfileTabHtml( $tab );
}
function getProfileView( $position = '' ) {
$tabs =& $this->_getCbTabs();
return $tabs->getViewTabs( $this->_cbuser, $position );
}
/**
* DO NOT USE: This function will disapear in favor of a new one in very next minor release.
*
* @param unknown_type $show_avatar
* @return unknown
*/
function avatarFilePath( $show_avatar = 2 ) {
global $_CB_framework;
$oValue = null;
if ( $this->_cbuser ) {
if ( $this->_cbuser->id ) {
$avatar = $this->_cbuser->avatar;
$avatarapproved = $this->_cbuser->avatarapproved;
$absolute_path = $_CB_framework->getCfg( 'absolute_path' );
$live_site = $_CB_framework->getCfg( 'live_site' );
if ( $avatarapproved == 0 ) {
return selectTemplate() . 'images/avatar/tnpending_n.png';
} elseif ( ( $avatar == '' ) && $avatarapproved == 1 ) {
$oValue = null;
} elseif ( strpos( $avatar, 'gallery/' ) === false ) {
$oValue = 'images/comprofiler/tn' . $avatar;
} else {
$oValue = 'images/comprofiler/' . $avatar;
}
if ( ! is_file( $absolute_path . '/' . $oValue ) ) {
$oValue = null;
}
}
if ( ( ! $oValue ) && ( $show_avatar == 2 ) ) {
return selectTemplate() . 'images/avatar/tnnophoto_n.png';
}
}
if ( $oValue ) {
$oValue = $live_site . '/' . $oValue;
}
return $oValue;
}
/**
* Replaces [fieldname] by the content of the user row (except for [password])
*
* @param string $msg
* @param boolean|array $htmlspecialchars on replaced values only: FALSE : no htmlspecialchars, TRUE: do htmlspecialchars, ARRAY: callback method
* @param boolean $menuStats
* @param array $extraStrings
* @param boolean $translateLanguage on $msg only
* @return string
*/
function replaceUserVars( $msg, $htmlspecialchars = true, $menuStats = true, $extraStrings = array(), $translateLanguage = true ){
if ( $translateLanguage ) {
$msg = getLangDefinition( $msg );
}
if ( strpos( $msg, '[' ) === false ) {
return $msg;
}
$row =& $this->_cbuser;
$msg = $this->_evaluateIfs( $msg );
$msg = $this->_evaluateCbTags( $msg );
if ( is_object( $row ) ) {
// old legacy modes:
$array = get_object_vars( $row );
foreach( $array AS $k => $v ) {
if( ( ! is_object( $v ) ) && ( ! is_array( $v ) ) ) {
if ( ! ( ( strtolower( $k ) == "password" ) && ( strlen($v) >= 32 ) ) ) {
/* do not translate content ! :
$vTranslated = ( $translateLanguage ? getLangDefinition( $v ) : $v );
if ( is_array( $htmlspecialchars ) ) {
$vTranslated = call_user_func_array( $htmlspecialchars, array( $vTranslated ) );
}
$msg = cbstr_ireplace("[".$k."]", $htmlspecialchars === true ? htmlspecialchars( $vTranslated ) : $vTranslated, $msg );
*/
if ( is_array( $htmlspecialchars ) ) {
$v = call_user_func_array( $htmlspecialchars, array( $v ) );
}
$msg = cbstr_ireplace("[".$k."]", $htmlspecialchars === true ? htmlspecialchars( $v ) : $v, $msg );
}
}
}
}
foreach( $extraStrings AS $k => $v) {
if( ( ! is_object( $v ) ) && ( ! is_array( $v ) ) ) {
/* do not translate content ! :
$vTranslated = ( $translateLanguage ? getLangDefinition( $v ) : $v );
if ( is_array( $htmlspecialchars ) ) {
$vTranslated = call_user_func_array( $htmlspecialchars, array( $vTranslated ) );
}
$msg = cbstr_ireplace("[".$k."]", $htmlspecialchars === true ? htmlspecialchars( $vTranslated ) : $vTranslated, $msg );
*/
if ( is_array( $htmlspecialchars ) ) {
$v = call_user_func_array( $htmlspecialchars, array( $v ) );
}
$msg = cbstr_ireplace("[".$k."]", $htmlspecialchars === true ? htmlspecialchars( $v ) : $v, $msg );
}
}
if ( $menuStats ) {
// find [menu .... : path1:path2:path3 /] and replace with HTML code if menu active, otherwise remove it all
$msg = $this->_replacePragma( $msg, $row, 'menu', 'menuBar' );
// no more [status ] as they are standard fields ! $msg = $this->_replacePragma( $msg, $row, 'status', 'menuList' );
}
$msg = str_replace( array( "&91;", "&93;" ), array( "[", "]" ), $msg );
return $msg;
}
/**
* INTERNAL PRIVATE METHODS:
*/
/**
* Explodes a text like: href="text1" img="text'it" alt='alt"joe' into an array with defined keys and values, but null for missing ones.
* @access private
*
* @param string $text text to parse
* @param array of string $validTags valid tag names
* @return array of string array( "tagname" => "tagvalue", "notsetTagname" => null)
*/
function _explodeTags( $text, $validTags ) {
$text = trim($text);
$result = array();
foreach ($validTags as $tagName) {
$result[$tagName] = null;
}
while ( $text != "" ) {
$posEqual = strpos( $text, "=" );
if ( $posEqual !== false ) {
$tagName = trim( substr( $text, 0, $posEqual ) );
$text = trim( substr( $text, $posEqual + 1 ) );
$quoteMark = substr( $text, 0, 1);
$posEndQuote = strpos( $text, $quoteMark, 1 );
$tagValue = false;
if ( ($posEndQuote !== false) && in_array( $quoteMark, array( "'", '"' ) ) ) {
$tagValue = substr( $text, 1, $posEndQuote - 1 );
$text = trim( substr( $text, $posEndQuote + 1 ) );
if ( in_array( $tagName, $validTags ) ) {
$result[$tagName] = $tagValue;
}
} else {
break;
}
} else {
break;
}
}
return $result;
}
/**
* Replaces "$1" in $text with $cbMenuTagsArray[$cbMenuTagsArrayKey] if non-null but doesn't tag if empty
* otherwise replace by $cbMenu[$cbMenuKey] if set and non-empty
* @access private
*
* @param array of string $cbMenuTagsArray
* @param string $cbMenuTagsArrayKey
* @param array of string $cbMenu
* @param string $cbMenuKey
* @param string $text
* @return string
*/
function _placeTags( $cbMenuTagsArray, $cbMenuTagsArrayKey, $cbMenu, $cbMenuKey, $text ) {
if ( $cbMenuTagsArray[$cbMenuTagsArrayKey] !== null) {
if ( $cbMenuTagsArray[$cbMenuTagsArrayKey] != "" ) {
return str_replace( '$1', /*allow tags! htmlspecialchars */ ( $cbMenuTagsArray[$cbMenuTagsArrayKey] ), $text );
} else {
return null;
}
} elseif ( isset($cbMenu[$cbMenuKey]) && ( $cbMenu[$cbMenuKey] !== null ) && ( $cbMenu[$cbMenuKey] !== "" ) ) {
return str_replace( '$1', $cbMenu[$cbMenuKey], $text );
} else {
return null;
}
}
/**
* Replaces complex pragmas
*
* @param string $msg
* @param stdClass $row
* @param string $pragma the tag between the brackets "[$pragma]"
* @param string $position the CB menu position
* @param boolean $htmlspecialcharsEncoded True if menu tags should remain htmlspecialchared
* @return unknown
*/
function _replacePragma( $msg, $row, $pragma, $position, $htmlspecialcharsEncoded = true ) {
global $_PLUGINS;
$msgResult = "";
$pragmaLen = strlen( $pragma );
while ( ( $foundPosBegin = strpos( $msg, "[" . $pragma ) ) !== false ) {
$foundPosEnd = strpos( $msg, "[/" . $pragma . "]", $foundPosBegin + $pragmaLen + 1 );
if ( $foundPosEnd !== false ) {
$foundPosTagEnd = strpos( $msg, "]", $foundPosBegin + $pragmaLen + 1 );
if ( ( $foundPosTagEnd !== false ) && ( $foundPosTagEnd < $foundPosEnd ) ) {
// found [menu .... : $cbMenuTreePath /] : check to see if $cbMenuTreePath is in current menu:
$cbMenuTreePath = substr( $msg, $foundPosTagEnd + 1, $foundPosEnd - ($foundPosTagEnd + 1) );
$cbMenuTreePathArray = explode( ":", $cbMenuTreePath );
$pm = $_PLUGINS->getMenus();
$pmc=count($pm);
for ( $i=0; $i<$pmc; $i++ ) {
if ( $pm[$i]['position'] == $position ) {
$arrayPos = $pm[$i]['arrayPos'];
foreach ( $cbMenuTreePathArray as $menuName ) {
if ( key( $arrayPos ) == trim( $menuName ) ) {
$arrayPos = $arrayPos[key( $arrayPos )];
} else {
// not matching full menu path: check next:
break;
}
}
if ( !is_array( $arrayPos ) ) {
// came to end of path: match found: stop searching:
break;
}
}
}
// replace by nothing in case not found:
$replaceString = "";
if ( $i < $pmc ) {
// found: replace with menu item: first check for qualifiers for special changes:
$cbMenuTags = substr( $msg, $foundPosBegin + $pragmaLen + 1, $foundPosTagEnd - ($foundPosBegin + $pragmaLen + 1) );
if ($htmlspecialcharsEncoded) {
$cbMenuTags = cbUnHtmlspecialchars( $cbMenuTags );
}
$cbMenuTagsArray = $this->_explodeTags( $cbMenuTags, array( "href", "target", "title", "class", "style", "img", "caption") );
if (substr(ltrim( $pm[$i]['url'] ),0,2) == '_placeTags( $cbMenuTagsArray, 'href', $pm[$i], 'url', '_placeTags( $cbMenuTagsArray, 'target', $pm[$i], 'target', ' target="$1"' )
. $this->_placeTags( $cbMenuTagsArray, 'title', $pm[$i], 'tooltip', ' title="$1"' )
. $this->_placeTags( $cbMenuTagsArray, 'class', $pm[$i], 'undef', ' class="$1"' )
. $this->_placeTags( $cbMenuTagsArray, 'style', $pm[$i], 'undef', ' style="$1"' )
. ">"
);
$replaceString .= $this->_placeTags( $cbMenuTagsArray, 'img', $pm[$i], 'img', '$1' );
$replaceString .= $this->_placeTags( $cbMenuTagsArray, 'caption', $pm[$i], 'caption', '$1' );
$replaceString .= $this->_placeTags( $cbMenuTagsArray, 'href', $pm[$i], 'url', '' );
/* $this->menuBar->addObjectItem( $pm[$i]['arrayPos'], $pm[$i]['caption'],
isset($pm[$i]['url']) ?$pm[$i]['url'] :"",
isset($pm[$i]['target'])?$pm[$i]['target'] :"",
isset($pm[$i]['img']) ?$pm[$i]['img'] :null,
isset($pm[$i]['alt']) ?$pm[$i]['alt'] :null,
isset($pm[$i]['tooltip'])?$pm[$i]['tooltip']:null,
isset($pm[$i]['keystroke'])?$pm[$i]['keystroke']:null );
*/
}
$msgResult .= substr( $msg, 0, $foundPosBegin );
$msgResult .= $replaceString;
$msg = substr( $msg, $foundPosEnd + $pragmaLen + 3 );
// $srchtxt = "[menu:".$cbMenuTreePath."]"; // get new search text
// $msg = str_replace($srchtxt,$replaceString,$msg); // replace founded case insensitive search text with $replace
} else {
break;
}
} else {
break;
}
}
return $msgResult . $msg;
}
function & _evaluateUserAttrib( $userAttrVal ) {
global $_CB_framework;
if ( $userAttrVal !== '' ) {
$uid = null;
if ( ( $userAttrVal == '#displayed' ) || ( $userAttrVal == '#displayedOrMe' ) ) {
$uid = $_CB_framework->displayedUser();
}
if ( ( $uid === null ) && ( ( $userAttrVal == '#displayedOrMe' ) || ( $userAttrVal == '#me' ) ) ) {
$uid = $_CB_framework->myId();
}
if ( ( $uid === null ) && preg_match( '/^[1-9][0-9]*$/', $userAttrVal ) ) {
$uid = (int) $userAttrVal;
}
if ( $uid ) {
if ( $uid == $this->_cbuser->id ) {
$user =& $this;
} else {
$user =& CBuser::getInstance( (int) $uid );
}
} else {
$user = null;
}
} else {
$user =& $this;
}
return $user;
}
function _evaluateIfs( $input ) {
// $regex = "#\[if ([^\]]+)\](.*?)\[/if\]#s";
// $regex = '#\[indent]((?:[^[]|\[(?!/?indent])|(?R))+)\[/indent]#s';
$regex = '#\[cb:if(?: +user="([^"/\[\] ]+)")?( +[^\]]+)\]((?:[^\[]|\[(?!/?cb:if[^\]]*])|(?R))+)\[/cb:if]#';
if ( is_array( $input ) ) {
$regex2 = '# +(?:(&&|and|\|\||or|) +)?([^= ]+) *(=|<|>|>=|<=|<>|!=) *"([^"]*)"#';
$conditions = null;
if (preg_match_all( $regex2, $input[2], $conditions ) ) {
$user =& $this->_evaluateUserAttrib( $input[1] );
if ( ( $user !== null ) || ( ( count( $conditions[0] ) == 1 ) && ( $conditions[2][0] == 'user_id' ) && ( $conditions[4][0] === '0' ) ) ) {
$resultsIdx = 0;
$results = array( $resultsIdx => true );
for ( $i = 0, $n = count( $conditions[0] ); $i < $n; $i++ ) {
$operator = $conditions[1][$i];
$field = $conditions[2][$i];
$compare = $conditions[3][$i];
$value = $conditions[4][$i];
if ( $user === null ) {
$var = '0';
} elseif ( $field && isset( $user->_cbuser->$field ) ) {
$var = $user->_cbuser->$field;
} else {
$var = null;
}
if ( ( $field == 'user_id' ) && ( $value == 'myid' ) ) {
global $_CB_framework;
$value = $_CB_framework->myId();
}
switch ( $compare ) {
case '=':
$r = ( $var == $value );
break;
case '<':
$r = ( $var < $value );
break;
case '>':
$r = ( $var > $value );
break;
case '>=':
$r = ( $var >= $value );
break;
case '<=':
$r = ( $var <= $value );
break;
case '<>':
case '!=':
$r = ( $var != $value );
break;
}
if ( in_array( $operator, array( 'or', '||' ) ) ) {
$resultsIdx++;
$results[++$resultsIdx] = true;
}
// combine and:
$results[$resultsIdx] = $results[$resultsIdx] && $r;
}
// combine or:
$r = false;
foreach ( $results as $rr ) {
$r = $r || $rr;
}
$input = ( $r ? $input[3] : '' );
} else {
$input = '';
}
} else {
$input = '';
}
}
return preg_replace_callback( $regex, array( $this, '_evaluateIfs' ), $input );
}
function _evaluateCbTags( $input ) {
$regex = '#\[cb:user(data +field|field +field|tab +tab|position +position)="([a-zA-Z0-9_]+)"(?: +user="([^"/\] ]+)")? */\]#';
if ( is_array( $input ) ) {
if ( isset( $input[3] ) ) {
$user =& $this->_evaluateUserAttrib( $input[3] );
} else {
$user =& $this;
}
if ( ( $user !== null ) && is_object( $user->_cbuser ) && isset( $user->_cbuser->id ) ) {
switch ( substr( $input[1], 0, 3 ) ) {
case 'dat':
return $user->_cbuser->get( $input[2] );
break;
case 'fie':
return $user->getField( $input[2] );
break;
case 'tab':
return $user->getTab( $input[2] );
break;
case 'pos':
return $user->getPosition( $input[2] );
break;
default:
return '';
}
}
return '';
}
return preg_replace_callback( $regex, array( $this, '_evaluateCbTags' ), $input );
}
}
/**
* CB HTML document class for Mambo 4.5.2+
* This class is experimental and not part as is of CB 1.2 !
* Use only $_CB_framework->document to access its public functions
* @author Beat
* @license GPL v2
*/
class CBdocumentHtml {
var $_output = 'html';
var $_head;
var $_cmsDoc = null;
var $_headsOutputed = true;
/**
* Constructor
* @access private
*
* @param callHandler $getDocFunction
* @return CBdocumentHtml
*/
function CBdocumentHtml( &$getDocFunction ) {
if ( $getDocFunction ) {
$this->_cmsDoc = call_user_func_array( $getDocFunction, array() );
}
$this->_renderingInit();
}
/**
* Sets or alters a meta tag.
*
* @param string $name MUST BE LOWERCASE: Name or http-equiv tag: 'generator', 'description', ...
* @param string $content Content tag value
* @param boolean $http_equiv META type "http-equiv" defaults to null
*/
function addHeadMetaData( $name, $content, $http_equiv = false ) {
if ( ! $this->_tryCmsDoc( 'setMetaData', array( $name, $content, $http_equiv ) ) ) {
if ( $http_equiv ) {
$metaTag = array( 'http-equiv' => $name, 'content' => $content );
} else {
$metaTag = array( 'name' => $name, 'content' => $content );
}
$this->_head['metaTags'][$http_equiv][$name] = $metaTag;
$this->_renderCheckOutput();
}
}
/**
* Adds
*
* @param string $url Href URL to the linked style sheet
* @param string $relation Relation to link
* @param string $relType 'rel' (default) for forward, or 'rev' for reverse relation
* @param array $attribs Additional attributes ( 'attrName' => 'attrValue' )
*/
function addHeadLinkCustom( $url, $relation, $relType = 'rel', $attribs = array() ) {
static $i = 0;
if ( ! $this->_tryCmsDoc( 'addHeadLink', array( $url, $relation, $relType, $attribs ) ) ) {
$this->_head['linksCustom']['link'][$i] = array( $relType => $relation, 'href' => $url );
if ( count( $attribs ) > 0 ) {
$this->_head['linksCustom']['link'][$i] = array_merge( $this->_head['linksCustom']['link'][$i], $attribs );
}
$i += 1;
$this->_renderCheckOutput();
}
}
/**
* Adds
*
* @param string $url Href URL to the linked style sheet (either full url, or if starting with '/', live_site will be prepended)
* @param boolean $minVersion If a minified version ".min.css" exists, will use that one when not debugging
* @param string $media Media type for stylesheet
* @param array $attribs Additional attributes ( 'attrName' => 'attrValue' )
* @param string $type MUST BE LOWERCASE: Mime type ('text/css' by default)
*/
function addHeadStyleSheet( $url, $minVersion = false, $media = null, $attribs = array(), $type = 'text/css' ) {
global $_CB_framework;
if ( $url[0] == '/' ) {
$url = $_CB_framework->getCfg( 'live_site' ) . $url;
}
if ( ! $this->_tryCmsDoc( 'addStyleSheet', array( $url, $type, $media, $attribs ) ) ) {
$this->_head['stylesheets'][$url] = array( 'type' => $type, 'rel' => 'stylesheet', 'href' => $url );
if ( $media ) {
$this->_head['stylesheets'][$url]['media'] = $media;
}
if ( count( $attribs ) > 0 ) {
$this->_head['stylesheets'][$url] = array_merge( $this->_head['stylesheets'][$url], $attribs );
}
$this->_renderCheckOutput();
}
}
/**
* Adds
*
* @param string $content Style declarations
* @param string $type Type of stylesheet (defaults to 'text/css')
* @return void
*/
function addHeadStyleInline( $content, $type = 'text/css' ) {
if ( ! $this->_tryCmsDoc( 'addStyleDeclaration', array( $content, $type ) ) ) {
$this->_head['styles'][$type][] = $content;
$this->_renderCheckOutput();
}
}
/**
* Adds
*
* @param string $url Src of script (either full url, or if starting with '/', live_site will be prepended) DO htmlspecialchars BEFORE calling if needed (&->&)
* @param boolean $minVersion Minified version exist, named .min.js
* @param string $preScript Script that must be just before the file inclusion
* @param string $postScript Script that must be just after the file
* @param string $preCustom Any html code just before the scripts incl. pre
* @param string $postCustom Any html code just after the scripts incl. post
* @param string|array $type String: type="$type" : MUST BE LOWERCASE: Type of script ('text/javascript' by default), Array: e.g. array( 'type' => 'text/javascript', 'charset' => 'utf-8' )
*/
function addHeadScriptUrl( $url, $minVersion = false, $preScript = null, $postScript = null, $preCustom = null, $postCustom = null, $type = 'text/javascript' ) {
global $_CB_framework;
if ( $minVersion && ! $_CB_framework->getCfg( 'debug' ) ) {
$url = str_replace( '.js', '.min.js', $url );
}
if ( $url[0] == '/' ) {
$url = $_CB_framework->getCfg( 'live_site' ) . $url;
}
// if ( ! $this->_tryCmsDoc( 'addScript', array( $url, $type ) ) ) { // The core ones are broken as they do not keep the strict ordering of scripts
$this->_head['scriptsUrl'][$url] = array( 'pre' => $preScript, 'post' => $postScript, 'preC' => $preCustom, 'postC' => $postCustom, 'type' => $type );
$this->_renderCheckOutput();
// }
}
/**
* Adds
*
* @param string $content Script
* @param string $type MUST BE LOWERCASE: Mime type ('text/javascript' by default)
*/
function addHeadScriptDeclaration( $content, $type = 'text/javascript' ) {
// if ( ! $this->_tryCmsDoc( 'addScriptDeclaration', array( $content, $type ) ) ) { // The core ones are broken as they do not keep the strict ordering of scripts
$this->_head['scripts'][$type][] = $content;
$this->_renderCheckOutput();
// }
}
/**
* Adds custom $html into portion
*
* @param string $html
*/
function addHeadCustomHtml( $html ) {
// if ( ! $this->_tryCmsDoc( 'addCustomTag', array( $html ) ) ) { // The core ones are broken as they do not keep the strict ordering of scripts
$this->_head['custom'][] = $html;
$this->_renderCheckOutput();
// }
}
/**
* Tries to add head tags to CMS document.
* @access private
*
* @param string $type
* @param array $params
* @return boolean Returns true for success and false if it couldn't use.
*/
function _tryCmsDoc( $type, $params ) {
if ( $this->_cmsDoc ) {
call_user_func_array( array( $this->_cmsDoc, $type ), $params );
return true;
}
return false;
}
function _outputToHeadCollectionStart( ) {
$this->_headsOutputed = false;
}
/**
* Outputs the headers to the CMS handler or returns them if it can't
* @access private
*
* @return string|null string for header to be echoed worst case, null if it could echo
*/
function _outputToHead( ) {
global $_CB_framework, $ueConfig;
$jVersion = checkJversion();
$customHead = $this->_renderHead();
if ( $this->_headsOutputed && ( $jVersion == 0 ) ) {
return $customHead . "\n";
}
if ( ! $this->_tryCmsDoc( 'addCustomTag', $customHead ) ) {
if ( isset( $ueConfig['xhtmlComply'] ) && $ueConfig['xhtmlComply']
&& ( ( ( $_CB_framework->getUi() == 1 ) || ( ( $jVersion == 0 ) && function_exists( 'josHashPassword' ) ) ) && method_exists( $_CB_framework->_baseFramework, 'addCustomHeadTag' ) ) )
{
// versions 1.0.13 (in fact 1.0.12 too) and above have it in backend too:
$_CB_framework->_baseFramework->addCustomHeadTag( $customHead );
} else {
return $customHead . "\n";
}
}
$this->_headsOutputed = true;
return null;
}
function _renderCheckOutput( ) {
if ( $this->_headsOutputed ) {
// $customHead = $this->_renderHead();
// echo $customHead; // better late than never...
echo $this->_outputToHead();
}
}
function _renderingInit() {
$this->_head = array( 'metaTags' => array(), 'linksCustom' => array(), 'stylesheets' => array(), 'styles' => array(), 'scriptsUrl' => array(), 'scripts' => array(), 'custom' => array() );
}
/**
* Renders the portion going into the if CMS doesn't support correct ordering
* @access private
*
* @return string HTML for or NULL if done by CMS
*/
function _renderHead( ) {
$html = null;
if ( $this->_output == 'html' ) {
if ( $this->_cmsDoc === null ) {
//