public static function getInstance($handler = null, $options = array()) { static $now = null; MCacheStorage::addIncludePath(MPATH_WP_CNT . '/miwi/framework/cache/storage'); if (!isset($handler)) { $conf = MFactory::getConfig(); $handler = $conf->get('cache_handler'); if (empty($handler)) { return MError::raiseWarning(500, MText::_('MLIB_CACHE_ERROR_CACHE_HANDLER_NOT_SET')); } } if (is_null($now)) { $now = time(); } $options['now'] = $now; $handler = strtolower(preg_replace('/[^A-Z0-9_\\.-]/i', '', $handler)); $class = 'MCacheStorage' . ucfirst($handler); if (!class_exists($class)) { mimport('joomla.filesystem.path'); if ($path = MPath::find(MCacheStorage::addIncludePath(), strtolower($handler) . '.php')) { include_once $path; } else { return MError::raiseWarning(500, MText::sprintf('MLIB_CACHE_ERROR_CACHE_STORAGE_LOAD', $handler)); } } return new $class($options); }
public static function base($pathonly = false) { if (empty(self::$base)) { $config = MFactory::getConfig(); $live_site = $config->get('live_site'); if (trim($live_site) != '') { $uri = self::getInstance($live_site); self::$base['prefix'] = $uri->toString(array('scheme', 'host', 'port')); self::$base['path'] = rtrim($uri->toString(array('path')), '/\\'); if (is_admin()) { self::$base['path'] .= '/admin'; } } else { $uri = self::getInstance(); self::$base['prefix'] = $uri->toString(array('scheme', 'host', 'port')); if (strpos(php_sapi_name(), 'cgi') !== false && !ini_get('cgi.fix_pathinfo') && !empty($_SERVER['REQUEST_URI'])) { $script_name = $_SERVER['PHP_SELF']; } else { $script_name = $_SERVER['SCRIPT_NAME']; } self::$base['path'] = rtrim(dirname($script_name), '/\\'); } } return $pathonly === false ? self::$base['prefix'] . self::$base['path'] . '/' : self::$base['path']; }
public function __construct(array &$options) { // Call the parent constructor. parent::__construct($options); // The name of the text file defaults to 'error.php' if not explicitly given. if (empty($this->options['text_file'])) { $this->options['text_file'] = 'error.php'; } // The name of the text file path defaults to that which is set in configuration if not explicitly given. if (empty($this->options['text_file_path'])) { $this->options['text_file_path'] = MFactory::getConfig()->get('log_path'); } // False to treat the log file as a php file. if (empty($this->options['text_file_no_php'])) { $this->options['text_file_no_php'] = false; } // Build the full path to the log file. $this->path = $this->options['text_file_path'] . '/' . $this->options['text_file']; // Use the default entry format unless explicitly set otherwise. if (!empty($this->options['text_entry_format'])) { $this->format = (string) $this->options['text_entry_format']; } // Build the fields array based on the format string. $this->parseFields(); }
public static function getInstance($file = 'error.php', $options = null, $path = null) { // Deprecation warning. MLog::add('MLog::getInstance() is deprecated. See MLog::addLogger().', MLog::WARNING, 'deprecated'); // Get the system configuration object. $config = MFactory::getConfig(); // Set default path if not set and sanitize it. if (!$path) { $path = $config->get('log_path'); } // If no options were explicitly set use the default from configuration. if (empty($options)) { $options = (array) $config->get('log_options'); } // Fix up the options so that we use the w3c format. $options['text_entry_format'] = empty($options['format']) ? null : $options['format']; $options['text_file'] = $file; $options['text_file_path'] = $path; $options['logger'] = 'w3c'; // Generate a unique signature for the MLog instance based on its options. $signature = md5(serialize($options)); // Only create the object if not already created. if (empty(self::$legacy[$signature])) { self::$legacy[$signature] = new MLog(); // Register the configuration. self::$legacy[$signature]->configurations[$signature] = $options; // Setup the lookup to catch all. self::$legacy[$signature]->lookup[$signature] = (object) array('priorities' => MLog::ALL, 'categories' => array()); } return self::$legacy[$signature]; }
public static function hasCredentials($client) { $return = false; $client = strtolower($client); // Get (unmodified) credentials for this client switch ($client) { case 'ftp': $config = MFactory::getConfig(); $options = array('enabled' => $config->get('ftp_enable'), 'user' => $config->get('ftp_user'), 'pass' => $config->get('ftp_pass')); break; default: $options = array('enabled' => false, 'user' => '', 'pass' => ''); break; } if ($options['enabled'] == false) { // The client is disabled in global config, so let's pretend we are OK $return = true; } elseif ($options['user'] != '' && $options['pass'] != '') { // Login credentials are available in global config $return = true; } else { // Check if login credentials are available in the session $session = MFactory::getSession(); $user = $session->get($client . '.user', null, 'MClientHelper'); $pass = $session->get($client . '.pass', null, 'MClientHelper'); if ($user != '' && $pass != '') { $return = true; } } return $return; }
protected function getInput() { // Initialize some field attributes. $format = $this->element['format'] ? (string) $this->element['format'] : '%Y-%m-%d'; // Build the attributes array. $attributes = array(); if ($this->element['size']) { $attributes['size'] = (int) $this->element['size']; } if ($this->element['maxlength']) { $attributes['maxlength'] = (int) $this->element['maxlength']; } if ($this->element['class']) { $attributes['class'] = (string) $this->element['class']; } if ((string) $this->element['readonly'] == 'true') { $attributes['readonly'] = 'readonly'; } if ((string) $this->element['disabled'] == 'true') { $attributes['disabled'] = 'disabled'; } if ($this->element['onchange']) { $attributes['onchange'] = (string) $this->element['onchange']; } // Handle the special case for "now". if (strtoupper($this->value) == 'NOW') { $this->value = strftime($format); } // Get some system objects. $config = MFactory::getConfig(); $user = MFactory::getUser(); // If a known filter is given use it. switch (strtoupper((string) $this->element['filter'])) { case 'SERVER_UTC': // Convert a date to UTC based on the server timezone. if (intval($this->value)) { // Get a date object based on the correct timezone. $date = MFactory::getDate($this->value, 'UTC'); $date->setTimezone(new DateTimeZone($config->get('offset'))); // Transform the date string. $this->value = $date->format('Y-m-d H:i:s', true, false); } break; case 'USER_UTC': // Convert a date to UTC based on the user timezone. if (intval($this->value)) { // Get a date object based on the correct timezone. $date = MFactory::getDate($this->value, 'UTC'); $date->setTimezone(new DateTimeZone($user->getParam('timezone', $config->get('offset')))); // Transform the date string. $this->value = $date->format('Y-m-d H:i:s', true, false); } break; } return MHtml::_('calendar', $this->value, $this->name, $this->id, $format, $attributes); }
public function __construct($options) { $conf = MFactory::getConfig(); $this->_options = array('cachebase' => $conf->get('cache_path', MPATH_CACHE), 'lifetime' => (int) $conf->get('cachetime'), 'language' => $conf->get('language', 'en-GB'), 'storage' => $conf->get('cache_handler', ''), 'defaultgroup' => 'default', 'locking' => true, 'locktime' => 15, 'checkTime' => true, 'caching' => $conf->get('caching') >= 1 ? true : false); foreach ($options as $option => $value) { if (isset($options[$option]) && $options[$option] !== '') { $this->_options[$option] = $options[$option]; } } if (empty($this->_options['storage'])) { $this->_options['caching'] = false; } }
public static function published($value, $i, $prefix = '', $enabled = true, $checkbox = 'cb', $publish_up = null, $publish_down = null) { if (is_array($prefix)) { $options = $prefix; $enabled = array_key_exists('enabled', $options) ? $options['enabled'] : $enabled; $checkbox = array_key_exists('checkbox', $options) ? $options['checkbox'] : $checkbox; $prefix = array_key_exists('prefix', $options) ? $options['prefix'] : ''; } $states = array(1 => array('unpublish', 'MPUBLISHED', 'MLIB_HTML_UNPUBLISH_ITEM', 'MPUBLISHED', false, 'publish', 'publish'), 0 => array('publish', 'MUNPUBLISHED', 'MLIB_HTML_PUBLISH_ITEM', 'MUNPUBLISHED', false, 'unpublish', 'unpublish'), 2 => array('unpublish', 'MARCHIVED', 'MLIB_HTML_UNPUBLISH_ITEM', 'MARCHIVED', false, 'archive', 'archive'), -2 => array('publish', 'MTRASHED', 'MLIB_HTML_PUBLISH_ITEM', 'MTRASHED', false, 'trash', 'trash')); // Special state for dates if ($publish_up || $publish_down) { $nullDate = MFactory::getDBO()->getNullDate(); $nowDate = MFactory::getDate()->toUnix(); $tz = new DateTimeZone(MFactory::getUser()->getParam('timezone', MFactory::getConfig()->get('offset'))); $publish_up = $publish_up != $nullDate ? MFactory::getDate($publish_up, 'UTC')->setTimeZone($tz) : false; $publish_down = $publish_down != $nullDate ? MFactory::getDate($publish_down, 'UTC')->setTimeZone($tz) : false; // Create tip text, only we have publish up or down settings $tips = array(); if ($publish_up) { $tips[] = MText::sprintf('MLIB_HTML_PUBLISHED_START', $publish_up->format(MDate::$format, true)); } if ($publish_down) { $tips[] = MText::sprintf('MLIB_HTML_PUBLISHED_FINISHED', $publish_down->format(MDate::$format, true)); } $tip = empty($tips) ? false : implode('<br/>', $tips); // Add tips and special titles foreach ($states as $key => $state) { // Create special titles for published items if ($key == 1) { $states[$key][2] = $states[$key][3] = 'MLIB_HTML_PUBLISHED_ITEM'; if ($publish_up > $nullDate && $nowDate < $publish_up->toUnix()) { $states[$key][2] = $states[$key][3] = 'MLIB_HTML_PUBLISHED_PENDING_ITEM'; $states[$key][5] = $states[$key][6] = 'pending'; } if ($publish_down > $nullDate && $nowDate > $publish_down->toUnix()) { $states[$key][2] = $states[$key][3] = 'MLIB_HTML_PUBLISHED_EXPIRED_ITEM'; $states[$key][5] = $states[$key][6] = 'expired'; } } // Add tips to titles if ($tip) { $states[$key][1] = MText::_($states[$key][1]); $states[$key][2] = MText::_($states[$key][2]) . '::' . $tip; $states[$key][3] = MText::_($states[$key][3]) . '::' . $tip; $states[$key][4] = true; } } return self::state($states, $value, $i, array('prefix' => $prefix, 'translate' => !$tip), $enabled, true, $checkbox); } return self::state($states, $value, $i, $prefix, $enabled, true, $checkbox); }
protected function getGroups() { // Initialize variables. $groups = array(); $keyField = $this->element['key_field'] ? (string) $this->element['key_field'] : 'id'; $keyValue = $this->form->getValue($keyField); // If the timezone is not set use the server setting. if (strlen($this->value) == 0 && empty($keyValue)) { $this->value = MFactory::getConfig()->get('offset'); } // Get the list of time zones from the server. $zones = DateTimeZone::listIdentifiers(); // Build the group lists. foreach ($zones as $zone) { // Time zones not in a group we will ignore. if (strpos($zone, '/') === false) { continue; } // Get the group/locale from the timezone. list($group, $locale) = explode('/', $zone, 2); // Only use known groups. if (in_array($group, self::$zones)) { // Initialize the group if necessary. if (!isset($groups[$group])) { $groups[$group] = array(); } // Only add options where a locale exists. if (!empty($locale)) { $groups[$group][$zone] = MHtml::_('select.option', $zone, str_replace('_', ' ', $locale), 'value', 'text', false); } } } // Sort the group lists. ksort($groups); foreach ($groups as $zone => &$location) { sort($location); } // Merge any additional groups in the XML definition. $groups = array_merge(parent::getGroups(), $groups); return $groups; }
public function render($module, $attribs = array(), $content = null) { if (!is_object($module)) { $title = isset($attribs['title']) ? $attribs['title'] : null; $module_id = isset($attribs['number']) ? $attribs['number'] : null; $module = MModuleHelper::getModule($module, $title, $module_id); if (!is_object($module)) { if (is_null($content)) { return ''; } else { $tmp = $module; $module = new stdClass(); $module->params = null; $module->module = $tmp; $module->id = 0; $module->user = 0; } } } // Get the user and configuration object // $user = MFactory::getUser(); $conf = MFactory::getConfig(); // Set the module content if (!is_null($content)) { $module->content = $content; } // Get module parameters $params = new MRegistry(); $params->loadString($module->params); // Use parameters from template if (isset($attribs['params'])) { $template_params = new MRegistry(); $template_params->loadString(html_entity_decode($attribs['params'], ENT_COMPAT, 'UTF-8')); $params->merge($template_params); $module = clone $module; $module->params = (string) $params; } $contents = MModuleHelper::renderModule($module, $attribs); return $contents; }
public function __construct($table, $key, &$db) { // Set internal variables. $this->_tbl = $table; $this->_tbl_key = $key; $this->_db =& $db; // Initialise the table properties. if ($fields = $this->getFields()) { foreach ($fields as $name => $v) { // Add the field if it is not already present. if (!property_exists($this, $name)) { $this->{$name} = null; } } } // If we are tracking assets, make sure an access field exists and initially set the default. if (property_exists($this, 'asset_id')) { //$this->_trackAssets = true; } // If the access property exists, set the default. if (property_exists($this, 'access')) { $this->access = (int) MFactory::getConfig()->get('access'); } }
public function __construct(array &$options) { // Call the parent constructor. parent::__construct($options); // If both the database object and driver options are empty we want to use the system database connection. if (empty($this->options['db_object']) && empty($this->options['db_driver'])) { $this->dbo = MFactory::getDBO(); $this->driver = MFactory::getConfig()->get('dbtype'); $this->host = MFactory::getConfig()->get('host'); $this->user = MFactory::getConfig()->get('user'); $this->password = MFactory::getConfig()->get('password'); $this->database = MFactory::getConfig()->get('db'); $this->prefix = MFactory::getConfig()->get('dbprefix'); } else { $this->driver = empty($this->options['db_driver']) ? 'mysql' : $this->options['db_driver']; $this->host = empty($this->options['db_host']) ? '127.0.0.1' : $this->options['db_host']; $this->user = empty($this->options['db_user']) ? 'root' : $this->options['db_user']; $this->password = empty($this->options['db_pass']) ? '' : $this->options['db_pass']; $this->database = empty($this->options['db_database']) ? 'logging' : $this->options['db_database']; $this->prefix = empty($this->options['db_prefix']) ? 'jos_' : $this->options['db_prefix']; } // The table name is independent of how we arrived at the connection object. $this->table = empty($this->options['db_table']) ? '#__log_entries' : $this->options['db_table']; }
protected function cleanCache($group = null, $client_id = 0) { // Initialise variables; $conf = MFactory::getConfig(); $dispatcher = MDispatcher::getInstance(); $options = array('defaultgroup' => $group ? $group : (isset($this->option) ? $this->option : MRequest::getCmd('option')), 'cachebase' => MPATH_CACHE); $cache = MCache::getInstance('callback', $options); $cache->clean(); // Trigger the onContentCleanCache event. $dispatcher->trigger($this->event_clean_cache, $options); }
protected function cleanCache($group = null, $client_id = 0) { $conf = MFactory::getConfig(); $dispatcher = MEventDispatcher::getInstance(); $options = array('defaultgroup' => $group ? $group : (isset($this->option) ? $this->option : MFactory::getApplication()->input->get('option')), 'cachebase' => $client_id ? MPATH_ADMINISTRATOR . '/cache' : $conf->get('cache_path', MPATH_SITE . '/cache')); $cache = MCache::getInstance('callback', $options); $cache->clean(); // Trigger the onContentCleanCache event. $dispatcher->trigger($this->event_clean_cache, $options); }
public static function extract($archivename, $extractdir) { mimport('framework.filesystem.file'); mimport('framework.filesystem.folder'); $untar = false; $result = false; $ext = MFile::getExt(strtolower($archivename)); // Check if a tar is embedded...gzip/bzip2 can just be plain files! if (MFile::getExt(MFile::stripExt(strtolower($archivename))) == 'tar') { $untar = true; } switch ($ext) { case 'zip': $adapter = MArchive::getAdapter('zip'); if ($adapter) { $result = $adapter->extract($archivename, $extractdir); } break; case 'tar': $adapter = MArchive::getAdapter('tar'); if ($adapter) { $result = $adapter->extract($archivename, $extractdir); } break; case 'tgz': // This format is a tarball gzip'd $untar = true; case 'gz': case 'gzip': // This may just be an individual file (e.g. sql script) $adapter = MArchive::getAdapter('gzip'); if ($adapter) { $config = MFactory::getConfig(); $tmpfname = $config->get('tmp_path') . '/' . uniqid('gzip'); $gzresult = $adapter->extract($archivename, $tmpfname); if ($gzresult instanceof Exception) { @unlink($tmpfname); return false; } if ($untar) { // Try to untar the file $tadapter = MArchive::getAdapter('tar'); if ($tadapter) { $result = $tadapter->extract($tmpfname, $extractdir); } } else { $path = MPath::clean($extractdir); MFolder::create($path); $result = MFile::copy($tmpfname, $path . '/' . MFile::stripExt(MFile::getName(strtolower($archivename))), null, 1); } @unlink($tmpfname); } break; case 'tbz2': // This format is a tarball bzip2'd $untar = true; case 'bz2': case 'bzip2': // This may just be an individual file (e.g. sql script) $adapter = MArchive::getAdapter('bzip2'); if ($adapter) { $config = MFactory::getConfig(); $tmpfname = $config->get('tmp_path') . '/' . uniqid('bzip2'); $bzresult = $adapter->extract($archivename, $tmpfname); if ($bzresult instanceof Exception) { @unlink($tmpfname); return false; } if ($untar) { // Try to untar the file $tadapter = MArchive::getAdapter('tar'); if ($tadapter) { $result = $tadapter->extract($tmpfname, $extractdir); } } else { $path = MPath::clean($extractdir); MFolder::create($path); $result = MFile::copy($tmpfname, $path . '/' . MFile::stripExt(MFile::getName(strtolower($archivename))), null, 1); } @unlink($tmpfname); } break; default: MError::raiseWarning(10, MText::_('MLIB_FILESYSTEM_UNKNOWNARCHIVETYPE')); return false; break; } if (!$result || $result instanceof Exception) { return false; } return true; }
public static function test() { if ((extension_loaded('memcache') && class_exists('Memcache')) != true) { return false; } $config = MFactory::getConfig(); $host = $config->get('memcache_server_host', 'localhost'); $port = $config->get('memcache_server_port', 11211); $memcache = new Memcache(); $memcachetest = @$memcache->connect($host, $port); if (!$memcachetest) { return false; } else { return true; } }
public static function customErrorPage(&$error) { // Deprecation warning. MLog::add('MError::customErrorPage() is deprecated.', MLog::WARNING, 'deprecated'); // Initialise variables. $app = MFactory::getApplication(); $document = MDocument::getInstance('error'); if ($document) { $config = MFactory::getConfig(); // Get the current template from the application $template = $app->getTemplate(); // Push the error object into the document $document->setError($error); // If site is offline and it's a 404 error, just go to index (to see offline message, instead of 404) if ($error->getCode() == '404' && MFactory::getConfig()->get('offline') == 1) { MFactory::getApplication()->redirect('index.php'); } @ob_end_clean(); $document->setTitle(MText::_('Error') . ': ' . $error->get('code')); $data = $document->render(false, array('template' => $template, 'directory' => MPATH_THEMES, 'debug' => $config->get('debug'))); // Failsafe to get the error displayed. if (empty($data)) { self::handleEcho($error, array()); } else { // Do not allow cache MResponse::allowCache(false); MResponse::setBody($data); echo MResponse::toString(); } } else { // Must echo the error since there is no document // This is a common use case for Command Line Interface applications. self::handleEcho($error, array()); } $app->close(0); }
public function display($cachable = false, $urlparams = false) { $document = MFactory::getDocument(); $viewType = $document->getType(); $viewName = MRequest::getCmd('view', $this->default_view); $viewLayout = MRequest::getCmd('layout', 'default'); $view = $this->getView($viewName, $viewType, '', array('base_path' => $this->basePath, 'layout' => $viewLayout)); // Get/Create the model if ($model = $this->getModel($viewName)) { // Push the model into the view (as default) $view->setModel($model, true); } $view->document = $document; $conf = MFactory::getConfig(); // Display the view if ($cachable && $viewType != 'feed' && $conf->get('caching') >= 1) { $option = MRequest::getCmd('option'); $cache = MFactory::getCache($option, 'view'); if (is_array($urlparams)) { $app = MFactory::getApplication(); if (!empty($app->registeredurlparams)) { $registeredurlparams = $app->registeredurlparams; } else { $registeredurlparams = new stdClass(); } foreach ($urlparams as $key => $value) { // Add your safe url parameters with variable type as value {@see MFilterInput::clean()}. $registeredurlparams->{$key} = $value; } $app->registeredurlparams = $registeredurlparams; } $cache->get($view, 'display'); } else { $view->display(); } return $this; }
public function _replacePrefix($query) { $mainframe = MFactory::getApplication(); $msg = ''; $config_file = MPATH_CONFIGURATION . '/configuration.php'; list($prefix, $new_prefix) = sscanf(str_replace(array('`', '"', "'"), '', strtolower(trim($query))), "replace prefix %s to %s"); if (!is_writable($config_file)) { echo '<h2 style="color: red;">' . sprintf(MText::_('COM_MIWOSQL_CONFIG_NOT_WRITABLE'), $config_fname) . '</h2>'; return $msg; } $this->_db->setQuery("SHOW TABLES LIKE '" . $prefix . "%'"); $tables = $this->_db->loadResultArray(); foreach ($tables as $tbl) { $new_tbl = str_replace($prefix, $new_prefix, $tbl); $this->_db->setQuery('ALTER TABLE `' . $tbl . '` RENAME `' . $new_tbl . '`'); $this->_db->query(); if (!empty($this->_db->_errorMsg)) { echo '<small style="color:red;">' . $this->_db->_errorMsg . '</small><br/>'; } } $config = MFactory::getConfig(); if (version_compare(MVERSION, '1.6.0', 'ge')) { $config->set('dbprefix', $new_prefix); } else { $config->setValue('config.dbprefix', $new_prefix); } /*jimport('joomla.filesystem.path'); if (!$ftp['enabled'] && MPath::isOwner($config_fname) && !MPath::setPermissions($config_fname, '0644')) { MError::raiseNotice('SOME_ERROR_CODE', 'Could not make configuration.php writable'); }*/ mimport('framwork.filesystem.file'); if (version_compare(MVERSION, '1.6.0', 'ge')) { if (!MFile::write($config_file, $config->toString('PHP', array('class' => 'MConfig', 'closingtag' => false)))) { $msg = MText::_('COM_MIWOSQL_DONE'); } else { $msg = MText::_('ERRORCONFIGFILE'); } } else { if (MFile::write($config_file, $config->toString('PHP', 'config', array('class' => 'MConfig')))) { $msg = MText::_('COM_MIWOSQL_DONE'); } else { $msg = MText::_('ERRORCONFIGFILE'); } } return $msg; }
public static function keepalive() { // Only load once if (isset(self::$loaded[__METHOD__])) { return; } // Include jQuery MHtml::_('jquery.framework'); $config = MFactory::getConfig(); $lifetime = $config->get('lifetime') * 60000; $refreshTime = $lifetime <= 60000 ? 30000 : $lifetime - 60000; // Refresh time is 1 minute less than the liftime assined in the configuration.php file. // The longest refresh period is one hour to prevent integer overflow. if ($refreshTime > 3600000 || $refreshTime <= 0) { $refreshTime = 3600000; } $document = MFactory::getDocument(); $script = ''; $script .= 'function keepAlive() {'; $script .= ' jQuery.get("index.php");'; $script .= '}'; $script .= 'jQuery(function($)'; $script .= '{ setInterval(keepAlive, ' . $refreshTime . '); }'; $script .= ');'; $document->addScriptDeclaration($script); self::$loaded[__METHOD__] = true; return; }
protected function _createConfiguration($file) { MLoader::register('MConfig', $file); // Create the MConfig object. $config = new MConfig(); // Get the global configuration object. $registry = MFactory::getConfig(); // Load the configuration values into the registry. $registry->loadObject($config); return $config; }
public static function test() { $conf = MFactory::getConfig(); return is_writable($conf->get('cache_path', MPATH_CACHE)); }
protected function filterField($element, $value) { // Make sure there is a valid SimpleXMLElement. if (!$element instanceof SimpleXMLElement) { return false; } // Get the field filter type. $filter = (string) $element['filter']; // Process the input value based on the filter. $return = null; switch (strtoupper($filter)) { // Access Control Rules. case 'RULES': $return = array(); foreach ((array) $value as $action => $ids) { // Build the rules array. $return[$action] = array(); foreach ($ids as $id => $p) { if ($p !== '') { $return[$action][$id] = $p == '1' || $p == 'true' ? true : false; } } } break; // Do nothing, thus leaving the return value as null. // Do nothing, thus leaving the return value as null. case 'UNSET': break; // No Filter. // No Filter. case 'RAW': $return = $value; break; // Filter the input as an array of integers. // Filter the input as an array of integers. case 'INT_ARRAY': // Make sure the input is an array. if (is_object($value)) { $value = get_object_vars($value); } $value = is_array($value) ? $value : array($value); MArrayHelper::toInteger($value); $return = $value; break; // Filter safe HTML. // Filter safe HTML. case 'SAFEHTML': $return = MFilterInput::getInstance(null, null, 1, 1)->clean($value, 'string'); break; // Convert a date to UTC based on the server timezone offset. // Convert a date to UTC based on the server timezone offset. case 'SERVER_UTC': if (intval($value) > 0) { // Get the server timezone setting. $offset = MFactory::getConfig()->get('offset'); // Return an SQL formatted datetime string in UTC. $return = MFactory::getDate($value, $offset)->toSql(); } else { $return = ''; } break; // Convert a date to UTC based on the user timezone offset. // Convert a date to UTC based on the user timezone offset. case 'USER_UTC': if (intval($value) > 0) { // Get the user timezone setting defaulting to the server timezone setting. $offset = MFactory::getUser()->getParam('timezone', MFactory::getConfig()->get('offset')); // Return a MySQL formatted datetime string in UTC. $return = MFactory::getDate($value, $offset)->toSql(); } else { $return = ''; } break; // Ensures a protocol is present in the saved field. Only use when // the only permitted protocols requre '://'. See MFormRuleUrl for list of these. // Ensures a protocol is present in the saved field. Only use when // the only permitted protocols requre '://'. See MFormRuleUrl for list of these. case 'URL': if (empty($value)) { return false; } $value = MFilterInput::getInstance()->clean($value, 'html'); $value = trim($value); // <>" are never valid in a uri see http://www.ietf.org/rfc/rfc1738.txt. $value = str_replace(array('<', '>', '"'), '', $value); // Check for a protocol $protocol = parse_url($value, PHP_URL_SCHEME); // If there is no protocol and the relative option is not specified, // we assume that it is an external URL and prepend http://. if ($element['type'] == 'url' && !$protocol && !$element['relative'] || !$element['type'] == 'url' && !$protocol) { $protocol = 'http'; // If it looks like an internal link, then add the root. if (substr($value, 0) == 'index.php') { $value = MURI::root() . $value; } // Otherwise we treat it is an external link. // Put the url back together. $value = $protocol . '://' . $value; } elseif (!$protocol && $element['relative']) { $host = MURI::getInstance('SERVER')->gethost(); // If it starts with the host string, just prepend the protocol. if (substr($value, 0) == $host) { $value = 'http://' . $value; } else { $value = MURI::root() . $value; } } $return = $value; break; case 'TEL': $value = trim($value); // Does it match the NANP pattern? if (preg_match('/^(?:\\+?1[-. ]?)?\\(?([2-9][0-8][0-9])\\)?[-. ]?([2-9][0-9]{2})[-. ]?([0-9]{4})$/', $value) == 1) { $number = (string) preg_replace('/[^\\d]/', '', $value); if (substr($number, 0, 1) == 1) { $number = substr($number, 1); } if (substr($number, 0, 2) == '+1') { $number = substr($number, 2); } $result = '1.' . $number; } elseif (preg_match('/^\\+(?:[0-9] ?){6,14}[0-9]$/', $value) == 1) { $countrycode = substr($value, 0, strpos($value, ' ')); $countrycode = (string) preg_replace('/[^\\d]/', '', $countrycode); $number = strstr($value, ' '); $number = (string) preg_replace('/[^\\d]/', '', $number); $result = $countrycode . '.' . $number; } elseif (preg_match('/^\\+[0-9]{1,3}\\.[0-9]{4,14}(?:x.+)?$/', $value) == 1) { if (strstr($value, 'x')) { $xpos = strpos($value, 'x'); $value = substr($value, 0, $xpos); } $result = str_replace('+', '', $value); } elseif (preg_match('/[0-9]{1,3}\\.[0-9]{4,14}$/', $value) == 1) { $result = $value; } else { $value = (string) preg_replace('/[^\\d]/', '', $value); if ($value != null && strlen($value) <= 15) { $length = strlen($value); // if it is fewer than 13 digits assume it is a local number if ($length <= 12) { $result = '.' . $value; } else { // If it has 13 or more digits let's make a country code. $cclen = $length - 12; $result = substr($value, 0, $cclen) . '.' . substr($value, $cclen); } } else { $result = ''; } } $return = $result; break; default: // Check for a callback filter. if (strpos($filter, '::') !== false && is_callable(explode('::', $filter))) { $return = call_user_func(explode('::', $filter), $value); } elseif (function_exists($filter)) { $return = call_user_func($filter, $value); } else { $return = MFilterInput::getInstance()->clean($value, $filter); } break; } return $return; }
protected static function includeRelativeFiles($folder, $file, $relative, $detect_browser, $detect_debug) { // If http is present in filename if (strpos($file, 'http') === 0) { $includes = array($file); } else { // Extract extension and strip the file $strip = MFile::stripExt($file); $ext = MFile::getExt($file); // Detect browser and compute potential files if ($detect_browser) { $navigator = MBrowser::getInstance(); $browser = $navigator->getBrowser(); $major = $navigator->getMajor(); $minor = $navigator->getMinor(); // Try to include files named filename.ext, filename_browser.ext, filename_browser_major.ext, filename_browser_major_minor.ext // where major and minor are the browser version names $potential = array($strip, $strip . '_' . $browser, $strip . '_' . $browser . '_' . $major, $strip . '_' . $browser . '_' . $major . '_' . $minor); } else { $potential = array($strip); } // If relative search in template directory or media directory if ($relative) { // Get the template $app = MFactory::getApplication(); $template = $app->getTemplate(); // Prepare array of files $includes = array(); // For each potential files foreach ($potential as $strip) { $files = array(); // Detect debug mode if ($detect_debug && MFactory::getConfig()->get('debug')) { $files[] = $strip . '-uncompressed.' . $ext; } $files[] = $strip . '.' . $ext; // Loop on 1 or 2 files and break on first found foreach ($files as $file) { // If the file is in the template folder if (file_exists(MPATH_THEMES . "/{$template}/{$folder}/{$file}")) { $includes[] = MURI::base(true) . "/templates/{$template}/{$folder}/{$file}"; break; } else { // If the file contains any /: it can be in an media extension subfolder if (strpos($file, '/')) { // Divide the file extracting the extension as the first part before / list($extension, $file) = explode('/', $file, 2); // If the file yet contains any /: it can be a plugin if (strpos($file, '/')) { // Divide the file extracting the element as the first part before / list($element, $file) = explode('/', $file, 2); // Try to deal with plugins group in the media folder if (file_exists(MPATH_ROOT . "/media/{$extension}/{$element}/{$folder}/{$file}")) { $includes[] = MURL_WP_CNT . "/miwi/media/{$extension}/{$element}/{$folder}/{$file}"; break; } elseif (file_exists(MPATH_ROOT . "/media/{$extension}/{$folder}/{$element}/{$file}")) { $includes[] = MURL_WP_CNT . "/miwi/media/{$extension}/{$folder}/{$element}/{$file}"; break; } elseif (file_exists(MPATH_THEMES . "/{$template}/{$folder}/system/{$element}/{$file}")) { $includes[] = MURL_WP_CNT . "/miwi/templates/{$template}/{$folder}/system/{$element}/{$file}"; break; } elseif (file_exists(MPATH_ROOT . "/media/system/{$folder}/{$element}/{$file}")) { $includes[] = MURL_WP_CNT . "/miwi/media/system/{$folder}/{$element}/{$file}"; break; } } elseif (file_exists(MPATH_ROOT . "/media/{$extension}/{$folder}/{$file}")) { $includes[] = MURL_WP_CNT . "/miwi/media/{$extension}/{$folder}/{$file}"; break; } elseif (file_exists(MPATH_THEMES . "/{$template}/{$folder}/system/{$file}")) { $includes[] = MURL_WP_CNT . "/miwi/templates/{$template}/{$folder}/system/{$file}"; break; } elseif (file_exists(MPATH_ROOT . "/media/system/{$folder}/{$file}")) { $includes[] = MURL_WP_CNT . "/miwi/media/system/{$folder}/{$file}"; break; } } elseif (file_exists(MPATH_ROOT . "/media/system/{$folder}/{$file}")) { $includes[] = MURL_WP_CNT . "/miwi/media/system/{$folder}/{$file}"; break; } } } } } else { $includes = array(); foreach ($potential as $strip) { // Detect debug mode if ($detect_debug && MFactory::getConfig()->get('debug') && file_exists(MPATH_ROOT . "/{$strip}-uncompressed.{$ext}")) { $includes[] = MURI::root(false) . "/{$strip}-uncompressed.{$ext}"; } elseif (file_exists(MPATH_ROOT . "/{$strip}.{$ext}")) { $includes[] = MURI::root(false) . "/{$strip}.{$ext}"; } } } } return $includes; }