$options = IPSBWOptions::thawOptions( 18, 'user', 'forums' );
*/
static public function thaw( $bitfield, $type, $app='global' )
{
/* INIT */
$bitfield = intval($bitfield);
$array = array();
/* Generate bitwise array */
$bitArray = self::_getBitWiseArray( $type, $app );
if ( ! $bitArray OR ! count( $bitArray ) )
{
return array();
}
/* Build options */
foreach( $bitArray as $key => $bitvalue )
{
if ( $bitfield & intval( $bitvalue ) )
{
$array[ $key ] = 1;
}
else
{
$array[ $key ] = 0;
}
}
return $array;
}
/**
* Build an SQL query bit
*
* @param string Field (field name as assigned by thaw)
* @param string SQL field
* @param string Type (members, groups, etc )
* @param string App (global, forums, etc)
* @param string Type of SQL query (add/remove/has)
* @return string Formatted SQL field
*/
static public function sql( $bitField, $sqlField, $type, $app='global', $sql='has' )
{
/* Generate int sign */
switch( $sql )
{
default:
case 'has':
$_sign = '&';
break;
case 'remove':
$_sign = '-';
break;
case 'add':
$_sign = '+';
break;
}
/* Generate bitwise array */
$bitArray = self::_getBitWiseArray( $type, $app );
/* Do it.. .*/
if ( in_array( $bitField, array_keys( $bitArray ) ) )
{
return '( ' . $sqlField . ' ' . $_sign . ' ' . $bitArray[ $bitField ] . ' ) != 0';
}
else
{
return FALSE;
}
}
/**
* Freeze options
* Converts an array of options array( 'key' => 0 ... ) into an int for saving in a DB field
*
* @param array Array of key => values to save
* @param string Type of options to save
* @param string App
* @return int
*/
static public function freeze( $toSave, $type, $app='global' )
{
/* INIT */
$int = 0;
/* Generate bitwise array */
$bitArray = self::_getBitWiseArray( $type, $app );
if ( ! $bitArray OR ! count( $bitArray ) )
{
return 0;
}
foreach( $bitArray as $key => $value )
{
if ( isset( $toSave[ $key ] ) )
{
if ( $toSave[ $key ] == 1 )
{
$int += $value;
}
}
}
return intval( $int );
}
/**
* Fetch and build the bitwise array
*
* @param string Array key to return
* @return array
*/
static protected function _getBitWiseArray( $type, $app )
{
$bitArray = array();
$allOptions = ipsRegistry::fetchBitWiseOptions( $app );
if ( is_array( $allOptions ) )
{
if ( isset( $allOptions[ $type ] ) AND is_array( $allOptions[ $type ] ) )
{
$n = 1;
foreach( $allOptions[ $type ] as $key )
{
$bitArray[ $key ] = $n;
$n *= 2;
}
}
}
return $bitArray;
}
}
/**
* Time Class
*
* Class for handling timestamps
*
*/
class IPSTime
{
/**
* Current timestamp
*
* @var integer
*/
protected static $timestamp = IPS_UNIX_TIME_NOW;
/**
* Number of seconds in a minute
*
* @var integer
*/
protected static $minute = 60;
/**
* Number of seconds in a hour
*
* @var integer
*/
protected static $hour = 3600;
/**
* Number of seconds in a day
*
* @var integer
*/
protected static $day = 86400;
/**
* Number of seconds in a week
*
* @var integer
*/
protected static $week = 604800;
/**
* Number of seconds in a year
*
* @var integer
*/
protected static $year = 220752000;
/**
* Months with 31 days
*
* @var array
*/
protected static $months_31 = array( 01, 03, 05, 07, 08, 10, 12 );
/**
* Months with 30 days
*
* @var array
*/
protected static $months_30 = array( 04, 06, 09, 11 );
/**
* time_class::dmy_format()
* Generates a time stamp for the day/month/year
*
* @param integer [$ts] Timestamp to format, self::$timestamp used if none specified
* @return @e void
*/
static public function dmy_format( $ts=0 )
{
/* Set the timestamp */
$_ts = ( $ts ) ? $ts : self::$timestamp;
/* Break it into dmy format */
$_ts = date( "m,d,Y", $_ts );
$_ts = explode( ",", $_ts );
/* Return the timestamp */
return mktime( 0, 0, 0, $_ts[0], $_ts[1], $_ts[2] );
}
/**
* time_class::time_ago()
* Returns how long ago the specified time stamp was
*
* @param integer $ts Timestamp to format
* @return @e void
*/
static public function time_ago( $ts )
{
if( $ts == time() )
{
return '--';
}
if( $ts < 60 )
{
$plural = ( $ts == 1 ) ? '' : 's';
return sprintf( "%0d", $ts ) . " second$plural";
}
else if( $ts < self::$hour )
{
$plural = ( sprintf("%0d", ( $ts / self::$minute ) ) == 1 ) ? '' : 's';
return sprintf("%0d", ( $ts / self::$minute ) ) . " minute$plural";
}
else if( $ts < self::$day )
{
$plural = ( sprintf("%0d", ( $ts / self::$hour ) ) == 1 ) ? '' : 's';
return sprintf("%0d", ( $ts / self::$hour ) ) . " hour$plural";
}
else
{
$plural = ( sprintf("%0d", ( $ts / self::$day ) ) == 1 ) ? '' : 's';
return sprintf("%0d", ( $ts / self::$day ) ) . " day$plural";
}
}
/**
* Set the timestamp
*
* @param int New timestamp
* @return @e void
*/
static public function setTimestamp( $time )
{
self::$timestamp = $time;
}
/**
* Get the timestamp
*
* @return int Timestamp
*/
static public function getTimestamp()
{
return self::$timestamp;
}
/**
* time_class::add_minutes()
* Adds the specified number of minutes to the timestamp
*
* @param integer [$num] Number of minutes to add, 1 by default
* @return @e void
*/
static public function add_minutes( $num=1 )
{
self::$timestamp += self::$minute * $num;
}
/**
* time_class::add_hours()
* Adds the specified number of hours to the timestamp
*
* @param integer [$num] Number of hours to add, 1 by default
* @return @e void
*/
static public function add_hours( $num=1 )
{
self::$timestamp += self::$hour * $num;
}
/**
* time_class::add_days()
* Adds the specified number of days to the timestamp
*
* @param integer [$num] Number of days to add, 1 by default
* @return @e void
*/
static public function add_days( $num=1 )
{
self::$timestamp += self::$day * $num;
}
/**
* time_class::add_weeks()
* Adds the specified number of weeks to the timestamp
*
* @param integer [$num] Number of weeks to add, 1 by default
* @return @e void
*/
static public function add_weeks( $num=1 )
{
self::$timestamp += self::$week * $num;
}
/**
* time_class::add_month()
* Adds a single month to the current timestamp, takes into account leap years
*
* @return @e void
*/
static public function add_month()
{
$daysInMonth = date( 't', self::$timestamp );
self::$timestamp += self::add_days( intval( $daysInMonth ) );
}
/**
* time_class::add_months()
* Adds the specified number of months to the timestamp
*
* @param integer $num Number of months to add, 1 by default
* @return @e void
*/
static public function add_months( $num=1 )
{
for( $i = 0; $i < $num; $i++ )
{
self::add_month();
}
}
/**
* time_class::add_years()
* Adds the specified number of years to the timestamp
*
* @param integer $num Number of years to add, 1 by default
* @return @e void
*/
static public function add_years( $num=1 )
{
for( $i = 0; $i < $num; $i++ )
{
self::add_months( 12 );
self::remove_days( 1 );
}
}
/**
* time_class::remove_days()
* Removes the specified number of days to the timestamp
*
* @param integer [$num] Number of days to remove, 1 by default
* @return @e void
*/
static public function remove_days( $num=1 )
{
self::$timestamp -= self::$day * $num;
}
/**
* Convert unix timestamp into: (no leading zeros)
* array( 'day' => x, 'month' => x, 'year' => x, 'hour' => x, 'minute' => x );
* Written into separate static public function to allow for timezone to be used easily
*
* @param integer [$unix] Timestamp
* @return array Date parts
*/
static public function unixstamp_to_human( $unix=0 )
{
$tmp = gmdate( 'j,n,Y,G,i', $unix );
list( $day, $month, $year, $hour, $min ) = explode( ',', $tmp );
return array( 'day' => $day,
'month' => $month,
'year' => $year,
'hour' => $hour,
'minute' => $min );
}
/**
* Convert unix timestamp into mmddyyyy
*
* @param integer [$unix] Timestamp
* @param string [$sep] Separator
* @return string mm/dd/yyyy
*/
static public function unixstamp_to_mmddyyyy( $unix=0, $sep='/' )
{
if ( ! $unix )
{
return "";
}
$date = self::unixstamp_to_human( $unix );
return sprintf("%02d{$sep}%02d{$sep}%04d", $date['month'], $date['day'], $date['year'] );
}
/**
* Convert mmddyyyy into unix timestamp
*
* @param string [$date] Date
* @param string [$sep] Separator
* @param bool [$checkdate] Whether to validate date or not
* @return integer Timestamp
*/
static public function mmddyyyy_to_unixstamp( $date='', $sep='/', $checkdate=true )
{
if ( ! $date )
{
return "";
}
list( $month, $day, $year ) = explode( $sep, $date );
if ( $checkdate )
{
if ( ! checkdate( $month, $day, $year ) )
{
return "";
}
}
return self::human_to_unixstamp( $day, $month, $year, 0, 0 );
}
/**
* Wrapper for gmmktime (separated for timezone management)
*
* @param integer $day Day
* @param integer $month Month
* @param integer $year Year
* @param integer $hour Hour
* @param integer $minute Minute
* @return integer Timestamp
*/
static public function human_to_unixstamp( $day, $month, $year, $hour, $minute )
{
return gmmktime( intval($hour), intval($minute), 0, intval($month), intval($day), intval($year) );
}
/**
* My gmmktime() - PHP func seems buggy
*
* @param integer $hour Hour
* @param integer $min Minute
* @param integer $sec Second
* @param integer $month Month
* @param integer $day Day
* @param integer $year Year
* @return integer Timestamp
* @since 2.0
*/
static public function date_gmmktime( $hour=0, $min=0, $sec=0, $month=0, $day=0, $year=0 )
{
// Calculate UTC time offset
$offset = date( 'Z' );
// Generate server based timestamp
$time = mktime( $hour, $min, $sec, $month, $day, $year );
// Calculate DST on / off
$dst = intval( date( 'I', $time ) - date( 'I' ) );
return $offset + ($dst * 3600) + $time;
}
/**
* Hand rolled GETDATE method
*
* getdate doesn't work apparently as it doesn't take into account
* the offset, even when fed a GMT timestamp.
*
* @param integer Unix date
* @return array 0, seconds, minutes, hours, mday, wday, mon, year, yday, weekday, month
* @since 2.0
*/
static public function date_getgmdate( $gmt_stamp )
{
//$tmp = gmdate( 'j,n,Y,G,i,s,w,z,l,F,W,M', $gmt_stamp );
$format = '%e,%m,%Y,%H,%M,%S,%u,%j,%A,%B,%W,%b';
//-----------------------------------------
// Some flags not available on Windows
// @see http://www.php.net/manual/en/function.strftime.php#53340
//-----------------------------------------
if( strpos( strtolower( PHP_OS ), 'win' ) === 0 )
{
$mapping = array(
'%e' => sprintf("%' 2d", date("j", $gmt_stamp)),
'%u' => ($w = date("w", $gmt_stamp)) ? $w : 7,
);
$format = str_replace( array_keys($mapping), array_values($mapping), $format );
}
$tmp = gmstrftime( $format, $gmt_stamp );
list( $day, $month, $year, $hour, $min, $seconds, $wday, $yday, $weekday, $fmon, $week, $smon ) = explode( ',', $tmp );
return array( 0 => $gmt_stamp,
"seconds" => $seconds, // Numeric representation of seconds 0 to 59
"minutes" => $min, // Numeric representation of minutes 0 to 59
"hours" => $hour, // Numeric representation of hours 0 to 23
"mday" => trim($day), // Numeric representation of the day of the month 1 to 31
"wday" => $wday, // Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday)
"mon" => $month, // Numeric representation of a month 1 through 12
"year" => $year, // A full numeric representation of a year, 4 digits Examples: 1999 or 2003
"yday" => $yday, // Numeric representation of the day of the year 0 through 365
"weekday" => $weekday, // A full textual representation of the day of the week Sunday through Saturday
"month" => $fmon, // A full textual representation of a month, such as January or Mar
"week" => $week, // Week of the year
"smonth" => $smon,
"smon" => $smon
);
}
}
/**
* IPSLib
*
* Dumping ground for functions that don't fit anywhere else
*
*/
class IPSLib
{
/**
* FURL Templates
*
* @param array
*/
static protected $_furlTemplates = array();
/**
* Search configs
*
* @param array
*/
static protected $_searchConfigs = array();
/**
* Log in methods
*
* @param array
*/
static protected $_lims = array();
/**
* Returns the class name to be instantiated, the class file will already be included
*
* @param string $filePath File location of the class (leave an empty string if you've already loaded the main file)
* @param string $className Name of the class
* @param string $app Application (defaults to 'core')
* @return string Class Name
*/
static public function loadLibrary( $filePath, $className, $app='core' )
{
/* Get the class */
if ( $filePath != '' )
{
require_once( $filePath );/*noLibHook*/
}
/* Check for hooks */
$hooksCache = ipsRegistry::cache()->getCache('hooks');
if( isset( $hooksCache['libraryHooks'][ $app ][ $className ] ) AND is_array( $hooksCache['libraryHooks'][ $app ][ $className ] ) AND count( $hooksCache['libraryHooks'][ $app ][ $className ] ) )
{
foreach( $hooksCache['libraryHooks'][ $app ][ $className ] as $classOverloader )
{
/* Hooks: Do we have the hook file? */
if( is_file( IPS_HOOKS_PATH . $classOverloader['filename'] ) )
{
require_once( IPS_HOOKS_PATH . $classOverloader['filename'] );/*noLibHook*/
if( class_exists( $classOverloader['className'] ) )
{
/* Hooks: We have the hook file and the class exists - reset the classname to load */
$className = $classOverloader['className'];
}
}
}
}
/* Return Class Name */
return $className;
}
/**
* Returns the class name to be instantiated, the class file will already be included
*
* @param string $filePath File location of the class
* @param string $className Name of the class
* @return string Class Name
*/
static public function loadActionOverloader( $filePath, $className )
{
/* Get the class */
require_once( $filePath );/*noLibHook*/
/* Hooks: Are we overloading this class? */
$hooksCache = ipsRegistry::cache()->getCache('hooks');
if( isset( $hooksCache['commandHooks'][ $className ] ) AND is_array( $hooksCache['commandHooks'][ $className ] ) AND count( $hooksCache['commandHooks'][ $className ] ) )
{
foreach( $hooksCache['commandHooks'][ $className ] as $classOverloader )
{
/* Hooks: Do we have the hook file? */
if( is_file( IPS_HOOKS_PATH . $classOverloader['filename'] ) )
{
require_once( IPS_HOOKS_PATH . $classOverloader['filename'] );/*noLibHook*/
if( class_exists( $classOverloader['className'] ) )
{
/* Hooks: We have the hook file and the class exists - reset the classname to load */
$className = $classOverloader['className'];
}
}
}
}
/* Return Class Name */
return $className;
}
/**
* Checks if there are any data hooks to run
*
* @param array $dataArray Data to be passed into the hooks
* @param string $hookLocation Location the data was sent from
* @return @e void
*/
static public function doDataHooks( &$dataArray, $hookLocation )
{
/* Loop through the cache */
$hooksCache = ipsRegistry::cache()->getCache( 'hooks' );
if( isset($hooksCache['dataHooks'][ $hookLocation ]) AND is_array( $hooksCache['dataHooks'][ $hookLocation ] ) AND count( $hooksCache['dataHooks'][ $hookLocation ] ) )
{
foreach( $hooksCache['dataHooks'][ $hookLocation ] as $r )
{
/* Check for hook file */
if( is_file( IPS_HOOKS_PATH . $r['filename'] ) )
{
/* Check for hook class */
require_once( IPS_HOOKS_PATH . $r['filename'] );/*noLibHook*/
if( class_exists( $r['className'] ) )
{
/* Create and run the hook */
$_hook = new $r['className'];
$newArray = $_hook->handleData( $dataArray );
/* Make sure the array isn't wiped out */
if( is_array( $newArray ) && count( $newArray ) )
{
$dataArray = $newArray;
}
}
}
}
}
}
/**
* Returns an array of data hook locations
*
* @return array
*/
static public function getDataHookLocations()
{
$_locations = array();
/* Loop all apps and get back our locations! */
foreach( ipsRegistry::$applications as $app_dir => $application )
{
$dataHookLocations = array();
if( is_file( IPSLib::getAppDir( $app_dir ) . '/extensions/dataHookLocations.php' ) )
{
require_once( IPSLib::getAppDir( $app_dir ) . '/extensions/dataHookLocations.php' );/*noLibHook*/
if ( is_array($dataHookLocations) && count($dataHookLocations) )
{
$_locations = array_merge( $_locations, $dataHookLocations );
}
}
}
return $_locations;
}
/**
* Checks to see if there is a template hook installed at the specified location
*
*
* @param string $group
* @param array $id
* @return bool
*/
static public function locationHasHooks( $group, $ids )
{
/* Return right away if we don't have an ids to check */
if( ! is_array( $ids ) || ! count( $ids ) )
{
return false;
}
/* Reformat the cache on the first call, to save processing later */
static $formattedCache = array();
if( !isset($formattedCache[ $group ]) )
{
$formattedCache[ $group ] = array();
$hookCache = ipsRegistry::cache()->getCache( 'hooks' );
if ( isset( $hookCache['templateHooks'][ $group ] ) AND is_array($hookCache['templateHooks'][ $group ]) AND count($hookCache['templateHooks'][ $group ]) )
{
foreach( $hookCache['templateHooks'][ $group ] as $_hook )
{
$formattedCache[ $group ][] = $_hook['id'];
}
}
}
/* Use formatted cache to check */
if( count( $formattedCache[ $group ] ) )
{
foreach( $ids as $id )
{
if( in_array( $id, $formattedCache[ $group ] ) )
{
return true;
}
}
}
return false;
}
/**
* Quickly determines if we've got VK enabled and set up
*
* @access public
* @return boolean
*/
static public function vkontakte_enabled()
{
return ( ipsRegistry::$settings['vk_enabled'] AND ipsRegistry::$settings['vk_api_id'] AND ipsRegistry::$settings['vk_secret'] ) ? TRUE : FALSE;
}
/**
* Central setlocale method so we can adjust as needed
*
* @param string Locale to set
* @return @e void
* @link http://community.invisionpower.com/tracker/issue-16386-language-locale-gives-error/
* @link http://community.invisionpower.com/tracker/issue-18424-change-lang-locale/
*/
static public function setlocale( $locale='' )
{
if( !$locale )
{
return;
}
if ( stripos( $locale, 'tr_' ) !== FALSE )
{
setlocale( LC_COLLATE, $locale );
setlocale( LC_MONETARY, $locale );
setlocale( LC_NUMERIC, $locale );
setlocale( LC_TIME, $locale );
setlocale( LC_MESSAGES, $locale );
}
else
{
setlocale( LC_ALL, $locale );
}
}
/**
* Quickly determines if we've got FB enabled and set up
*
* @return boolean
*/
static public function fbc_enabled()
{
return ( ipsRegistry::$settings['fbc_enable'] AND ipsRegistry::$settings['fbc_appid'] AND ipsRegistry::$settings['fbc_secret'] ) ? TRUE : FALSE;
}
/**
* Quickly determines if we've got twitter enabled and set up
*
* @return boolean
*/
static public function twitter_enabled()
{
return ( ipsRegistry::$settings['tc_enabled'] AND ipsRegistry::$settings['tc_token'] AND ipsRegistry::$settings['tc_secret'] ) ? TRUE : FALSE;
}
/**
* Quickly determines if we've got other log in enabled and set up
*
* @return boolean
*/
static public function loginMethod_enabled( $method )
{
if ( ! count( self::$_lims ) )
{
if ( is_array( ipsRegistry::cache()->getCache('login_methods') ) )
{
$cache = ipsRegistry::cache()->getCache('login_methods');
foreach( $cache as $lim )
{
self::$_lims[ $lim['login_folder_name'] ] = $lim['login_folder_name'];
}
}
}
switch( $method )
{
case 'vkontakte':
return self::vkontakte_enabled();
break;
case 'facebook':
return self::fbc_enabled();
break;
case 'twitter':
return self::twitter_enabled();
break;
default:
return in_array( $method, self::$_lims ) ? true : false;
break;
}
}
/**
* Loop through the input request and create an array of ids based on a string prefix
*
* @param string Prefix
* @return array
*/
static public function fetchInputAsArray( $prefix='' )
{
//-----------------------------------------
// INIT
//-----------------------------------------
$ids = array();
if( !$prefix )
{
return $ids;
}
//-----------------------------------------
// GET from checkboxes
//-----------------------------------------
foreach ( ipsRegistry::$request as $k => $v )
{
if ( $v && preg_match( "/^" . $prefix . '(\d+)$/', $k, $match ) )
{
$ids[] = $match[1];
}
}
$ids = self::cleanIntArray( $ids );
return $ids;
}
/**
* Little function to return the version number data
*
* Handy to use when dealing with IN_DEV, etc
* Uses the constant where available
*
* @param string App ( Default 'core')
* @return array array( 'long' => x, 'human' => x )
*/
static public function fetchVersionNumber( $app='core' )
{
if ( ! defined( IPB_VERSION ) OR ! defined( IPB_LONG_VERSION ) )
{
require_once( IPS_ROOT_PATH . 'setup/sources/base/setup.php' );/*noLibHook*/
$XMLVersions = IPSSetUp::fetchXmlAppVersions( $app );
$tmp = $XMLVersions;
krsort( $tmp );
foreach( $tmp as $long => $human )
{
$return = array( 'long' => $long, 'human' => $human );
break;
}
}
else
{
$return = array( 'long' => IPB_LONG_VERSION, 'human' => IPB_VERSION );
}
return $return;
}
/**
* Cheeky little function to locate group table fields from other apps
*
* @return array Array of fields from different apps
*/
static function fetchNonDefaultGroupFields()
{
$fields = array();
foreach( array( 'calendar', 'gallery', 'blog', 'downloads', 'ccs', 'ipchat', 'nexus', 'ipseo' ) as $app )
{
$_file = IPSLib::getAppDir( $app ) . '/setup/versions/install/sql/' . $app . '_mysql_tables.php';
if ( is_file( $_file ) )
{
$TABLE = array();
require( $_file );/*noLibHook*/
foreach( $TABLE as $t )
{
if ( preg_match( '#^ALTER TABLE\s+?groups\s+?ADD\s+?(\S+?)\s#i', $t, $match ) )
{
$fields[] = $match[1];
}
}
}
}
return $fields;
}
/**
* Update settings
*
* @param array array('conf_key' => 'new value')
* @return true/false
* @author MarkWade
*/
static public function updateSettings($update=array())
{
$fields = array_keys($update);
ipsRegistry::DB()->build( array( 'select' => '*', 'from' => 'core_sys_conf_settings', 'where' => "conf_key IN ('" . implode( "','", $fields ) . "')" ) );
ipsRegistry::DB()->execute();
$db_fields = array();
while ( $r = ipsRegistry::DB()->fetch() )
{
$db_fields[ $r['conf_key'] ] = $r;
}
if (empty($db_fields))
{
return false;
}
foreach( $db_fields as $key => $data )
{
$value = str_replace( "'", "'", IPSText::safeslashes($update[ $key ]) );
$value = $value == '' ? "{blank}" : $value;
ipsRegistry::DB()->update( 'core_sys_conf_settings', array( 'conf_value' => $value ), 'conf_id=' . $data['conf_id'] );
}
ipsRegistry::DB()->build( array( 'select' => '*', 'from' => 'core_sys_conf_settings', 'where' => 'conf_add_cache=1' ) );
$info = ipsRegistry::DB()->execute();
while ( $r = ipsRegistry::DB()->fetch($info) )
{
$value = $r['conf_value'] != "" ? $r['conf_value'] : $r['conf_default'];
if ( $value == '{blank}' )
{
$value = '';
}
$settings[ $r['conf_key'] ] = $value;
}
ipsRegistry::cache()->setCache( 'settings', $settings, array( 'array' => 1 ) );
return true;
}
/**
* Retrieve the default language
*
* @return string Default language id (most likely a number)
*/
static public function getDefaultLanguage()
{
$cache = ipsRegistry::cache()->getCache('lang_data');
if( !count($cache) OR !is_array($cache) )
{
ipsRegistry::getClass('class_localization')->rebuildLanguagesCache();
$cache = ipsRegistry::cache()->getCache('lang_data');
}
$_default = 1;
foreach( $cache as $_lang )
{
if( $_lang['lang_default'] )
{
$_default = $_lang['lang_id'];
break;
}
}
return $_default;
}
/**
* Build a global caches array from the database
*
* @return @e array Array of global caches
*/
static public function buildGlobalCachesArray()
{
/* INIT */
$globalCaches = array();
/* Get apps with global caches */
ipsRegistry::DB()->build( array( 'select' => 'app_global_caches',
'from' => 'core_applications',
'where' => "app_enabled=1 AND app_global_caches != '' AND app_global_caches " . ipsRegistry::DB()->buildIsNull( false )
) );
ipsRegistry::DB()->execute();
while( $gc = ipsRegistry::DB()->fetch() )
{
$caches = explode( ',', $gc['app_global_caches'] );
foreach( $caches as $key )
{
if ( $key )
{
$globalCaches[] = $key;
}
}
}
/* Get hooks with global caches */
ipsRegistry::DB()->build( array( 'select' => 'hook_global_caches',
'from' => 'core_hooks',
'where' => "hook_enabled=1 AND hook_global_caches != '' AND hook_global_caches " . ipsRegistry::DB()->buildIsNull( false )
) );
ipsRegistry::DB()->execute();
while( $gc = ipsRegistry::DB()->fetch() )
{
$caches = explode( ',', $gc['hook_global_caches'] );
foreach( $caches as $key )
{
if ( $key )
{
$globalCaches[] = $key;
}
}
}
/* Let's have only unique values and return */
$globalCaches = array_unique( $globalCaches );
return $globalCaches;
}
/**
* Cache global caches
*
* @return @e boolean
*
* @exceptions
* CANNOT_WRITE Cannot write to cache file
* NO_DATA_TO_WRITE No data to write
*/
static public function cacheGlobalCaches()
{
/* Init vars */
$data = '';
$globalCaches = self::buildGlobalCachesArray();
/* Got any caches? */
if ( count( $globalCaches ) )
{
$_date = gmdate( 'r', time() );
$_var = var_export( $globalCaches, TRUE );
$data = <<
* # We want to replace all instances of with
* $text = IPSText::replaceRecursively( $text, "", array( 'myClass', 'replaceIt' ) );
* class myClass {
* static function replaceIt( $text, $openText, $closeText )
* {
* # $text contains the matched text between the tags, eg: "http://www.domain.com"
* # $openText contains the searched for opening, eg:
* # Remove http...
* $text = str_replace( 'http://', '', $text )
* # Remove quotes
* $text = str_replace( array( '"', "'" ), '', $text );
* return '"javascript:goLoad(\'' . $text . '\')"';
* }
* }
*
*/
public static function replaceRecursively( $text, $textOpen, $textClose, $callBackFunction )
{
//----------------------------------------
// INIT
//----------------------------------------
# Tag specifics
$foundOpenText_pointer = 0;
$foundCloseText_pointer = 0;
$foundOpenTextRecurse_pointer = 0;
//----------------------------------------
// Keep the server busy for a while
//----------------------------------------
while ( 1 == 1 )
{
# Reset pointer
$startOfTextAfterOpenText_pointer = 0;
# See if we have any 'textOpen' at all
$foundOpenText_pointer = strpos( $text, $textOpen, $foundCloseText_pointer );
# No?
if ( $foundOpenText_pointer === FALSE )
{
break;
}
# Do we have any close text?
$foundCloseText_pointer = strpos( $text, $textClose, $foundOpenText_pointer );
# No?
if ( $foundCloseText_pointer === FALSE )
{
return $text;
}
# Reset pointer for text between the open and close text
$startOfTextAfterOpenText_pointer = $foundOpenText_pointer + strlen( $textOpen );
# Check recursively
$foundOpenTextRecurse_pointer = $startOfTextAfterOpenText_pointer;
while ( 1 == 1 )
{
# Got any open text again?
$foundOpenTextRecurse_pointer = strpos( $text, $textOpen, $foundOpenTextRecurse_pointer );
# No?
if ( $foundOpenTextRecurse_pointer === FALSE OR $foundOpenTextRecurse_pointer >= $foundCloseText_pointer )
{
break;
}
# Yes! Reset recursive pointer
$foundCloseTextRecurse_pointer = $foundCloseText_pointer + strlen( $textClose );
# Yes! Reset close normal pointer to next close tag FROM the last found close point
$foundCloseText_pointer = strpos( $text, $textClose, $foundCloseTextRecurse_pointer );
# Make sure we have a closing text
if ( $foundCloseText_pointer === FALSE )
{
return $text;
}
$foundOpenTextRecurse_pointer += strlen( $textOpen );
}
# This is the text between the open text and close text
$foundText = substr( $text, $startOfTextAfterOpenText_pointer, $foundCloseText_pointer - $startOfTextAfterOpenText_pointer );
# Recurse
if ( strpos( $foundText, $textOpen ) !== FALSE )
{
$foundText = IPSText::replaceRecursively( $foundText, $textOpen, $textClose, $callBackFunction );
}
# Run the call back...
$_newText = call_user_func( $callBackFunction, $foundText, $textOpen, $textClose );
# Run the replacement
$text = substr_replace( $text, $_newText, $foundOpenText_pointer, ( $foundCloseText_pointer - $foundOpenText_pointer ) + strlen( $textClose ) );
# Reset pointer
$foundCloseText_pointer = $foundOpenText_pointer + strlen($_newText);
}
return $text;
}
/**
* Reset Text Classes
*
* @param string Classname to search for
* @return boolean True if successful, false if not
*/
static public function resetTextClass( $name )
{
if ( ! is_object( self::$_internalClasses[ $name ] ) )
{
return false;
}
switch( $name )
{
default:
case 'bbcode':
self::$_internalClasses[ $name ]->allow_cache_updates = 1;
self::$_internalClasses[ $name ]->bypass_badwords = intval( ipsRegistry::instance()->member()->getProperty('g_bypass_badwords') );
self::$_internalClasses[ $name ]->parse_smilies = 1;
self::$_internalClasses[ $name ]->parse_nl2br = 1;
self::$_internalClasses[ $name ]->parse_html = 0;
self::$_internalClasses[ $name ]->parse_bbcode = 1;
self::$_internalClasses[ $name ]->parsing_section = 'post';
self::$_internalClasses[ $name ]->error = '';
self::$_internalClasses[ $name ]->parsing_mgroup = '';
self::$_internalClasses[ $name ]->parsing_mgroup_others = '';
break;
case 'editor':
self::$_internalClasses[ $name ]->error = '';
break;
}
return true;
}
/**
* Clean _GET _POST key
*
* @param string Key name
* @return string Cleaned key name
* @since 2.1
*/
static public function parseCleanKey($key)
{
if ( $key == "" )
{
return "";
}
$key = htmlspecialchars( urldecode($key) );
$key = str_replace( ".." , "" , $key );
$key = preg_replace( '/\_\_(.+?)\_\_/' , "" , $key );
$key = preg_replace( '/^([\w\.\-\_]+)$/', "$1", $key );
return $key;
}
/**
* Clean _GET _POST value
*
* @param string Input
* @param bool Also run postParseCleanValue
* @return string Cleaned Input
* @since 2.1
*/
static public function parseCleanValue( $val, $postParse=true )
{
if ( $val == "" )
{
return "";
}
$val = str_replace( " ", " ", IPSText::stripslashes($val) );
# Convert all carriage return combos
$val = str_replace( array( "\r\n", "\n\r", "\r" ), "\n", $val );
$val = str_replace( "&" , "&" , $val );
$val = str_replace( "" , "-->" , $val );
$val = str_ireplace( "