Project

General

Profile

Feature #19503 » 0009633_v5_essentials.patch

Administrator Admin, 2009-02-20 21:41

View differences:

t3lib/class.t3lib_autoloaderregistrybuilder.php (Revision 0)
<?php
/***************************************************************
* Copyright notice
*
* (c) 2008 Dmitry Dulepov (dmitry@typo3.org)
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Contains class to build autoloader registry
*
* $Id: $
*
* @author Dmitry Dulepov <dmitry@typo3.org>
*/
/**
* [CLASS/FUNCTION INDEX of SCRIPT]
*/
require_once(PATH_t3lib . 'class.t3lib_autoloader.php');
/**
* This class contains methods to build TYPO3 autoloader registry.
*
* @author Dmitry Dulepov <dmitry@typo3.org>
*/
class t3lib_autoloaderRegistryBuilder implements t3lib_Singleton {
/**
* Contains information about classes and paths. Key is class name in lower case, value is file path.
*
* @var array
*/
protected $dataArray;
/**
* Create registry file
*
* @param string Registry file path
*
* @return mixed Registry array on success, false on failure
*/
public function createRegistry($path) {
// Initialize registry
$this->dataArray = array();
// Walk directories
$this->walkTree('t3lib');
$this->walkTree('typo3conf/ext');
if (TYPO3_MODE == 'BE') {
// Walk all of the main directory for BE
$this->walkTree(TYPO3_mainDir);
} else {
// Walk only extension directories for FE
$this->walkTree(TYPO3_mainDir . 'ext');
$this->walkTree(TYPO3_mainDir . 'sysext');
}
if ($this->writeRegistry($path)) {
return $this->dataArray;
} else {
return false;
}
}
/**
* Walks directory starting from the given point and updates $this->dataArray
* with all found classes and files
*
* @param string $directory Directory
* @return void
*/
protected function walkTree($directory) {
// Removes slash at the and of the directory name:
if (substr($directory, -1) == '/') {
$directory = substr($directory, 0, -1);
}
// Determines whether the given directory should be processed:
if ($this->shouldProcessDirectory($directory)) {
$sitePathLength = strlen(PATH_site);
// Walk files
$files = glob(PATH_site . $directory . '/{class,interface}.*.{php,inc}', GLOB_BRACE | GLOB_NOSORT);
foreach ($files as $file) {
$basename = basename($file);
$classNames = $this->extractClassNames($file);
$file = substr($file, $sitePathLength);
foreach ($classNames as $className) {
if (isset($this->dataArray[$className])) {
t3lib_div::sysLog('Duplicate class name "' . $className. '" found in ' . $file . ', previously defined in ' . $this->dataArray[$className], 'Core', 2);
} else {
$this->dataArray[$className] = $file;
}
}
}
unset($files);
// Walk subdirectories
$directories = glob(PATH_site . $directory . '/*', GLOB_NOSORT | GLOB_ONLYDIR);
foreach ($directories as $currentDirectory) {
if ($currentDirectory != '.' && $currentDirectory != '..') {
$this->walkTree(substr($currentDirectory, $sitePathLength));
}
}
}
}
/**
* Extracts class names from the given file.
*
* @param string $filePath File path (absolute)
* @return array Class names
*/
protected function extractClassNames($filePath) {
$fileContent = php_strip_whitespace($filePath);
$classNames = array();
if (function_exists('token_get_all')) {
$tokens = token_get_all($fileContent);
while(1) {
// look for "class" or "interface",
$token = $this->findToken($tokens, array(T_CLASS, T_INTERFACE));
if ($token === false) {
// end of file
break;
}
// look for the name (a string) skipping only whitespace and comments
$token = $this->findToken($tokens, array(T_STRING), array(T_WHITESPACE,T_COMMENT,T_DOC_COMMENT));
if ($token === false) {
// unexpected end of file or token: remove found names because of parse error
t3lib_div::sysLog('Parse error in "' . $file. '".', 'Core', 2);
$classNames = array();
break;
}
$token = t3lib_div::strtolower($token);
// exclude XLASS classes
if (strncmp($token, 'ux_', 3)) {
$classNames[] = $token;
}
}
} else {
// TODO: parse PHP - skip coments and strings, apply regexp only on the remaining PHP code
$matches = array();
preg_match_all('/^[ \t]*(?:(?:abstract|final)?[ \t]*(?:class|interface))[ \t\n\r]+([a-zA-Z][a-zA-Z_0-9]*)/mS', $fileContent, $matches);
$classNames = array_map('t3lib_div::strtolower', $matches[1]);
}
return $classNames;
}
/**
* Find tokens in the tokenList
*
* @param array $tokenList list of tokens as returned by token_get_all()
* @param array $wantedToken the tokens to be found
* @param array $intermediateTokens optional: list of tokens that are allowed to skip when looking for the wanted token
* @return mixed
*/
protected function findToken(array &$tokenList, array $wantedTokens, array $intermediateTokens = array()) {
$skipAllTokens = count($intermediateTokens) ? false : true;
$returnValue = false;
// Iterate with while since we need the current array position:
while (list(,$token) = each($tokenList)) {
// parse token (see http://www.php.net/manual/en/function.token-get-all.php for format of token list)
if (is_array($token)) {
list($id, $text) = $token;
} else {
$id = $text = $token;
}
if (in_array($id, $wantedTokens)) {
$returnValue = $text;
break;
}
// look for another token
if ($skipAllTokens || in_array($id, $intermediateTokens)) {
continue;
}
break;
}
return $returnValue;
}
/**
* Checks if directory should be processed. If directory refers to the
* extension and extension is not loaded, skips processing.
*
* @param string $path Path to check
* @return boolean true if directory should be processed
*/
protected function shouldProcessDirectory($path) {
$matches = array();
$result = true;
if (preg_match('#^(?:typo3conf/ext|' . preg_quote(TYPO3_mainDir, '#') . '(?:sys)?ext)/([^/]+)#', $path, $matches)) {
$result = t3lib_extMgm::isLoaded($matches[1]);
}
return $result;
}
/**
* Stores autoloader data into the data file
*
* @return boolean true in success
*/
protected function writeRegistry($path) {
$serializedData = serialize($this->dataArray);
// We use @ because we definitly do not want warning here! They will corrupt
// TYPO3 output. We rely on proper error handling in the calling class.
return @file_put_contents($path, $serializedData);
}
}
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_autoloadregistrybuilder.php']) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_autoloadregistrybuilder.php']);
}
?>
t3lib/class.t3lib_div.php (Arbeitskopie)
* @return string Final class name to instantiate with "new [classname]"
*/
public static function makeInstanceClassName($className) {
return class_exists('ux_'.$className) ? t3lib_div::makeInstanceClassName('ux_'.$className) : $className;
return class_exists('ux_'.$className, false) ? t3lib_div::makeInstanceClassName('ux_'.$className) : $className;
}
/**
......
* @return string Final class name to instantiate with "new [classname]"
*/
protected function getClassName($className) {
return class_exists('ux_' . $className) ? self::getClassName('ux_' . $className) : $className;
return class_exists('ux_' . $className, false) ? self::getClassName('ux_' . $className) : $className;
}
/**
t3lib/class.t3lib_autoloader.php (Revision 0)
<?php
/***************************************************************
* Copyright notice
*
* (c) 2008 Dmitry Dulepov (dmitry@typo3.org)
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Contains TYPO3 autoloader
*
* $Id: $
*
* @author Dmitry Dulepov <dmitry@typo3.org>
*/
/**
* [CLASS/FUNCTION INDEX of SCRIPT]
*/
require_once(PATH_t3lib . 'interfaces/interface.t3lib_singleton.php');
/**
* This class contains TYPO3 autoloader for classes.
*
* @author Dmitry Dulepov <dmitry@typo3.org>
*/
class t3lib_autoloader implements t3lib_Singleton {
/**
* Database name for the BE mode. BE mode includes all classes.
*
* @var string
*/
const REGISTRY_FILENAME_BE = 'autoload_be.ser';
/**
* Database name for the FE mode. FE mode does not include classes from
* typo3/ directory
*
* @var string
*/
const REGISTRY_FILENAME_FE = 'autoload_fe.ser';
/**
* Contains database of all classes in the system
*
* @var array
*/
protected $registry = null;
/**
* Creates an instance of this class.
*
* @return void
*/
public function __construct() {
// TODO: check which DB is required for CLI and AJAX, for now default to BE
if (TYPO3_MODE == 'FE') {
$registryFileName = self::REGISTRY_FILENAME_FE;
} else {
$registryFileName = self::REGISTRY_FILENAME_BE;
}
$this->loadRegistry(PATH_typo3conf . $registryFileName);
}
/**
* Installs TYPO3 autoloader
*
* @return boolean true in case of success
*/
public function registerAutoloader() {
return spl_autoload_register(array($this, 'autoload'));
}
/**
* Uninstalls TYPO3 autoloader. This function is for the sake of completeness.
* It is never called by the TYPO3 core.
*
* @return boolean true in case of success
*/
public function unregisterAutoloader() {
return spl_autoload_unregister(array($this, 'autoload'));
}
/**
* Checks autoloader registry. Currently just checks if files exist in
* typo3conf/ and they can be unserialized.
*
* @return boolean true if registry is ok
*/
public function checkRegistry() {
$result = true;
foreach (array(self::REGISTRY_FILENAME_BE, self::REGISTRY_FILENAME_FE) as $fileName) {
if (@is_file(PATH_typo3conf . $fileName)) {
$array = @unserialize(@file_get_contents(PATH_typo3conf . $fileName));
$result = is_array($array);
} else {
$result = false;
}
if (!$result) {
break;
}
}
return $result;
}
/**
* Autoload function for TYPO3.
*
* @param string $classname Class name
* @return void
*/
protected function autoload($className) {
// TODO. check if isCalledFromClassExists can safely be removed
// WHY DO WE NEED TO DO THIS? to protect old code that may be unaware of autoloader and use class_exist() without the 2nd parameter
// if (!$this->isCalledFromClassExists()) {
$lowerCaseClassName = t3lib_div::strtolower($className);
if (isset($this->registry[$lowerCaseClassName])) {
require_once(PATH_site . $this->registry[$lowerCaseClassName]);
}
// fallback: SPL's default handler
if (!class_exists($className, false)) {
spl_autoload($className);
if (!class_exists($className, false)) {
$this->logLoadingFailure($className);
}
}
// }
}
/**
* Checks if we are called from class_exists.
*
* @return boolean true if we are called from class_exists
*/
/* TODO remove this function
protected function isCalledFromClassExists() {
foreach(debug_backtrace() as $backtrace) {
if ($backtrace['function'] == 'class_exists') {
return true;
}
}
return false;
}
*/
/**
* Loads autoload registry.
*
* @param string $registryPath Registry path
* @return unknown
*/
protected function loadRegistry($registryPath) {
$result = false;
if (file_exists($registryPath)) {
$this->registry = @unserialize(file_get_contents($registryPath));
if (!is_array($this->registry)) {
$this->registry = array();
$this->logRegistryLoadingFailure(sprintf('Registry file "%s" cannot be unserialized!', $registryPath));
throw new Exception('Loading the autoloader registry failed.');
} else {
$result = true;
}
} else {
require_once(PATH_t3lib . 'class.t3lib_autoloaderregistrybuilder.php');
$this->registry = t3lib_div::makeInstance('t3lib_autoloaderRegistryBuilder')->createRegistry($registryPath);
if (!is_array($this->registry)) {
$this->logRegistryLoadingFailure(sprintf('Registry file "%s" could not be written!', $registryPath));
throw new Exception('Creating the autoloader registry failed.');
} else {
$result = true;
}
}
return $result;
}
/**
* Logs error message about failed autoloading
*
* @param string $className Class name
* @param string $filePath File name
* @return void
*/
protected function logLoadingFailure($className) {
$message = sprintf('Unable to autoload class "%s"', $className);
t3lib_div::sysLog($message, 'Core', 4);
if (TYPO3_DLOG) {
t3lib_div::devLog($message, 'Core', 3);
}
}
/**
* Logs warning message about failed registry loading
*
* @param string $className Class name
* @param string $filePath File name
* @return void
*/
protected function logRegistryLoadingFailure($message) {
t3lib_div::sysLog($message, 'Core', 2);
if (TYPO3_DLOG) {
t3lib_div::devLog($message, 'Core', 2);
}
}
}
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_autoload.php']) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_autoload.php']);
}
?>
typo3/mod/tools/em/class.em_index.php (Arbeitskopie)
$this->writeNewExtensionList($newExtList);
$this->refreshGlobalExtList();
$this->forceDBupdates($extKey, $inst_list[$extKey]);
$this->rebuildAutoloaderRegistry();
return array(true, 'Extension was already installed, it has been loaded.');
}
}
......
$this->refreshGlobalExtList();
$this->forceDBupdates($extKey, $inst_list[$extKey]);
$this->installTranslationsForExtension($extKey, $this->getMirrorURL());
$this->rebuildAutoloaderRegistry();
return array(true, 'Extension has been imported from repository and loaded.');
} else {
return array(false, 'Extension is in repository, but could not be loaded.');
......
}
if (!$updates || t3lib_div::_GP('_do_install')) {
$this->writeNewExtensionList($newExtList);
$this->rebuildAutoloaderRegistry();
$GLOBALS['BE_USER']->writelog(5,1,0,0,'Extension list has been changed, extension %s has been %s',array($extKey,($this->CMD['load']?'installed':'removed')));
if ($this->CMD['clrCmd'] || t3lib_div::_GP('_clrCmd')) {
if ($this->CMD['load'] && @is_file($absPath.'ext_conf_template.txt')) {
......
return $content.'</table><br/>';
}
/**
* Rebuilds autoload registry when extension was installed or uninstalled
*
* @return void
*/
protected function rebuildAutoloaderRegistry() {
$registryBuilder = t3lib_div::makeInstance('t3lib_autoloadRegistryBuilder');
/* @var $registryBuilder t3lib_autoloadRegistryBuilder */
$registryBuilder->createRegistry();
}
}
typo3/mod/tools/em/class.em_terconnection.php (Arbeitskopie)
$filesData = array();
foreach ($uArr['FILES'] as $filename => $infoArr) {
$content = (!defined('SOAP_1_2') && class_exists('soapclient')) ? base64_encode($infoArr['content']) : $infoArr['content']; // bug in NuSOAP - no automatic encoding
// Avoid autoloading "soapclient", since it's only a strategy check here:
$content = (!defined('SOAP_1_2') && class_exists('soapclient', false)) ? base64_encode($infoArr['content']) : $infoArr['content']; // bug in NuSOAP - no automatic encoding
$filesData['fileData'][] = array (
'name' => utf8_encode($infoArr['name']),
'size' => intval($infoArr['size']),
typo3/mod/tools/em/class.em_soap.php (Arbeitskopie)
}
if (!$options['implementation'] || $options['implementation'] == 'detect') {
// Avoid autoloading, since it's only a strategy check here:
if (defined('SOAP_1_2')) {
$options['implementation'] = 'phpsoap';
} elseif (class_exists('soapclient')) {
} elseif (class_exists('soapclient', false)) {
$options['implementation'] = 'nusoap';
} elseif (class_exists('SOAP_Client')) {
} elseif (class_exists('SOAP_Client', false)) {
$options['implementation'] = 'pearsoap';
}
}
typo3/init.php (Arbeitskopie)
require(PATH_t3lib.'config_default.php');
if (!defined ('TYPO3_db')) die ('The configuration file was not included.');
require_once(PATH_t3lib.'class.t3lib_db.php'); // The database library
// *********************
// Autoloader
// *********************
require_once(PATH_t3lib . 'class.t3lib_autoloader.php');
t3lib_div::makeInstance('t3lib_autoloader')->registerAutoloader();
/** @var TYPO3_DB t3lib_db */
$TYPO3_DB = t3lib_div::makeInstance('t3lib_DB');
$TYPO3_DB->debugOutput = $TYPO3_CONF_VARS['SYS']['sqlDebug'];
......
// *******************************
// $GLOBALS['LANG'] initialisation
// *******************************
require_once(PATH_typo3.'sysext/lang/lang.php');
$GLOBALS['LANG'] = t3lib_div::makeInstance('language');
$GLOBALS['LANG']->init($BE_USER->uc['lang']);
typo3/sysext/lang/class.language.php (Revision 0)
<?php
/***************************************************************
* Copyright notice
*
* (c) 1999-2008 Kasper Skaarhoj (kasperYYYY@typo3.com)
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Contains the TYPO3 Backend Language class
*
* $Id: lang.php 4433 2008-11-07 04:13:12Z flyguide $
* Revised for TYPO3 3.6.0
*
* @author Kasper Skaarhoj <kasperYYYY@typo3.com>
*/
/**
* [CLASS/FUNCTION INDEX of SCRIPT]
*
*
*
* 88: class language
* 138: function init($lang,$altPath='')
* 183: function addModuleLabels($arr,$prefix)
* 209: function hscAndCharConv($lStr,$hsc)
* 224: function makeEntities($str)
* 241: function JScharCode($str)
* 260: function getLL($index,$hsc=0)
* 278: function getLLL($index,$LOCAL_LANG,$hsc=0)
* 299: function sL($input,$hsc=0)
* 344: function loadSingleTableDescription($table)
* 396: function includeLLFile($fileRef,$setGlobal=1,$mergeLocalOntoDefault=0)
* 441: function readLLfile($fileRef)
* 451: function localizedFileRef($fileRef)
*
* TOTAL FUNCTIONS: 12
* (This index is automatically created/updated by the extension "extdeveval")
*
*/
/**
* Contains the TYPO3 Backend Language class
*
* For detailed information about how localization is handled,
* please refer to the 'Inside TYPO3' document which descibes this.
*
* This class is normally instantiated as the global variable $LANG in typo3/template.php
* It's only available in the backend and under certain circumstances in the frontend
*
* @author Kasper Skaarhoj <kasperYYYY@typo3.com>
* @package TYPO3
* @subpackage core
* @see typo3/template.php, template
*/
class language {
var $lang='default'; // This is set to the language that is currently running for the user
var $langSplit='default'; // Values like the labels in the tables.php-document are split by '|'. This values defines which language is represented by which position in the resulting array after splitting a value. (NOTICE: Obsolete concept!)
// Default charset in backend
var $charSet = 'iso-8859-1';
// Array with alternative charsets for other languages. (Moved to t3lib_cs, Set from csConvObj!)
var $charSetArray = array();
// This is the url to the TYPO3 manual
var $typo3_help_url= 'http://www.typo3.com/man_uk/';
// Array with alternative URLs based on language.
var $helpUrlArray = array(
'dk' => 'http://www.typo3.com/man_dk/',
);
var $debugKey = FALSE; // If true, will show the key/location of labels in the backend.
var $moduleLabels = Array(); // Can contain labels and image references from the backend modules. Relies on t3lib_loadmodules to initialize modules after a global instance of $LANG has been created.
// Internal
var $langSplitIndex=0; // Points to the position of the current language key as found in constant TYPO3_languages
var $LL_files_cache=array(); // Internal cache for read LL-files
var $LL_labels_cache=array(); // Internal cache for ll-labels (filled as labels are requested)
/**
* instance of the "t3lib_cs" class. May be used by any application.
*
* @var t3lib_cs
*/
var $csConvObj;
/**
* Initializes the backend language.
* This is for example done in typo3/template.php with lines like these:
*
* require (PATH_typo3.'sysext/lang/class.language.php');
* $LANG = t3lib_div::makeInstance('language');
* $LANG->init($BE_USER->uc['lang']);
*
* @param string The language key (two character string from backend users profile)
* @param string IGNORE. Not used.
* @return void
*/
function init($lang,$altPath='') {
// Initialize the conversion object:
$this->csConvObj = t3lib_div::makeInstance('t3lib_cs');
$this->charSetArray = $this->csConvObj->charSetArray;
// Internally setting the list of TYPO3 backend languages.
$this->langSplit=TYPO3_languages;
// Finding the requested language in this list based on the $lang key being inputted to this function.
$ls = explode('|',$this->langSplit);
while(list($i,$v)=each($ls)) {
if ($v==$lang) { // Language is found. Configure it:
$this->langSplitIndex=$i; // The index of the language as found in the TYPO3_languages list
$this->lang = $lang; // The current language key
if ($this->helpUrlArray[$this->lang]) $this->typo3_help_url=$this->helpUrlArray[$this->lang]; // The help URL if different from the default.
if ($this->charSetArray[$this->lang]) $this->charSet=$this->charSetArray[$this->lang]; // The charset if different from the default.
}
}
// If a forced charset is used and different from the charset otherwise used:
if ($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] && $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset']!=$this->charSet) {
// Set the forced charset:
$this->charSet = $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'];
if ($this->charSet!='utf-8' && !$this->csConvObj->initCharset($this->charSet)) {
t3lib_BEfunc::typo3PrintError ('The forced character set "'.$this->charSet.'" was not found in t3lib/csconvtbl/','Forced charset not found');
exit;
}
}
}
/**
* Adds labels and image references from the backend modules to the internal moduleLabels array
*
* @param array Array with references to module labels, keys: ['labels']['tablabel'], ['labels']['tabdescr'], ['tabs']['tab']
* @param string Module name prefix
* @return void
* @see t3lib_loadModules
*/
function addModuleLabels($arr,$prefix) {
if (is_array($arr)) {
reset($arr);
while(list($k,$larr)=each($arr)) {
if (!isset($this->moduleLabels[$k])) {
$this->moduleLabels[$k]=array();
}
if (is_array($larr)) {
reset($larr);
while(list($l,$v)=each($larr)) {
$this->moduleLabels[$k][$prefix.$l]=$v;
}
}
}
}
}
/**
* Will htmlspecialchar() the input string and before that any charset conversion will also have taken place if needed (see init())
* Used to pipe language labels through just before they are returned.
*
* @param string The string to process
* @param boolean If set, then the string is htmlspecialchars()'ed
* @return string The processed string
* @see init()
*/
function hscAndCharConv($lStr,$hsc) {
$lStr = $hsc ? htmlspecialchars($lStr) : $lStr;
// labels returned from a locallang file used to be in the language of the charset. Since TYPO3 4.1 they are always in the charset of the BE.
return $lStr;
}
/**
* Will convert the input strings special chars (all above 127) to entities. The string is expected to be encoded in the charset, $this->charSet
* This function is used to create strings that can be used in the Click Menu (Context Sensitive Menus). The reason is that the values that are dynamically written into the <div> layer is decoded as iso-8859-1 no matter what charset is used in the document otherwise (only MSIE, Mozilla is OK). So by converting we by-pass this problem.
*
* @param string Input string
* @return string Output string
*/
function makeEntities($str) {
// Convert string to UTF-8:
if ($this->charSet!='utf-8') $str = $this->csConvObj->utf8_encode($str,$this->charSet);
// Convert string back again, but using the full entity conversion:
$str = $this->csConvObj->utf8_to_entities($str);
return $str;
}
/**
* Converts the input string to a JavaScript function returning the same string, but charset-safe.
* Used for confirm and alert boxes where we must make sure that any string content does not break the script AND want to make sure the charset is preserved.
* Originally I used the JS function unescape() in combination with PHP function rawurlencode() in order to pass strings in a safe way. This could still be done for iso-8859-1 charsets but now I have applied the same method here for all charsets.
*
* @param string Input string, encoded with $this->charSet
* @return string Output string, a JavaScript function: "String.fromCharCode(......)"
*/
function JScharCode($str) {
// Convert string to UTF-8:
if ($this->charSet!='utf-8') $str = $this->csConvObj->utf8_encode($str,$this->charSet);
// Convert the UTF-8 string into a array of char numbers:
$nArr = $this->csConvObj->utf8_to_numberarray($str);
return 'String.fromCharCode('.implode(',',$nArr).')';
}
/**
* Returns the label with key $index form the globally loaded $LOCAL_LANG array.
* Mostly used from modules with only one LOCAL_LANG file loaded into the global space.
*
* @param string Label key
* @param boolean If set, the return value is htmlspecialchar'ed
* @return string
*/
function getLL($index,$hsc=0) {
// Get Local Language
if (strcmp($GLOBALS['LOCAL_LANG'][$this->lang][$index],'')) {
$output = $this->hscAndCharConv($GLOBALS['LOCAL_LANG'][$this->lang][$index], $hsc); // Returns local label if not blank.
} else {
$output = $this->hscAndCharConv($GLOBALS['LOCAL_LANG']['default'][$index], $hsc); // Returns default label
}
return $output.($this->debugKey ? ' ['.$index.']':'');
}
/**
* Works like ->getLL() but takes the $LOCAL_LANG array used as the second argument instead of using the global array.
*
* @param string Label key
* @param array $LOCAL_LANG array to get label key from
* @param boolean If set, the return value is htmlspecialchar'ed
* @return string
*/
function getLLL($index,$LOCAL_LANG,$hsc=0) {
// Get Local Language
if (strcmp($LOCAL_LANG[$this->lang][$index],'')) {
$output = $this->hscAndCharConv($LOCAL_LANG[$this->lang][$index], $hsc); // Returns local label if not blank.
} else {
$output = $this->hscAndCharConv($LOCAL_LANG['default'][$index], $hsc); // Returns default label
}
return $output.($this->debugKey ? ' ['.$index.']':'');
}
/**
* splitLabel function
* Historically labels were exploded by '|' and each part would correspond to the translation of the language found at the same 'index' in the TYPO3_languages constant.
* Today all translations are based on $LOCAL_LANG variables. 'language-splitted' labels can therefore refer to a local-lang file + index instead!
* It's highly recommended to use the 'local_lang' method (and thereby it's highly deprecated to use 'language-splitted' label strings)
* Refer to 'Inside TYPO3' for more details
*
* @param string Label key/reference
* @param boolean If set, the return value is htmlspecialchar'ed
* @return string
*/
function sL($input,$hsc=0) {
if (strcmp(substr($input,0,4),'LLL:')) { // Using obsolete 'language-splitted' labels:
$t = explode('|',$input);
$out = $t[$this->langSplitIndex] ? $t[$this->langSplitIndex] : $t[0];
return $this->hscAndCharConv($out, $hsc);
} else { // LOCAL_LANG:
if (!isset($this->LL_labels_cache[$this->lang][$input])) { // If cached label
$restStr = trim(substr($input,4));
$extPrfx='';
if (!strcmp(substr($restStr,0,4),'EXT:')) { // ll-file refered to is found in an extension.
$restStr = trim(substr($restStr,4));
$extPrfx='EXT:';
}
$parts = explode(':',$restStr);
$parts[0]=$extPrfx.$parts[0];
if (!isset($this->LL_files_cache[$parts[0]])) { // Getting data if not cached
$this->LL_files_cache[$parts[0]] = $this->readLLfile($parts[0]);
// If the current language is found in another file, load that as well:
$lFileRef = $this->localizedFileRef($parts[0]);
if ($lFileRef && is_string($this->LL_files_cache[$parts[0]][$this->lang]) && $this->LL_files_cache[$parts[0]][$this->lang]=='EXT') {
$tempLL = $this->readLLfile($lFileRef);
$this->LL_files_cache[$parts[0]][$this->lang] = $tempLL[$this->lang];
}
// Overriding file?
if (isset($GLOBALS['TYPO3_CONF_VARS']['BE']['XLLfile'][$parts[0]])) {
$ORarray = $this->readLLfile($GLOBALS['TYPO3_CONF_VARS']['BE']['XLLfile'][$parts[0]]);
$this->LL_files_cache[$parts[0]] = t3lib_div::array_merge_recursive_overrule($this->LL_files_cache[$parts[0]],$ORarray);
}
}
$this->LL_labels_cache[$this->lang][$input] = $this->getLLL($parts[1],$this->LL_files_cache[$parts[0]]);
}
$output = $hsc ? t3lib_div::deHSCentities(htmlspecialchars($this->LL_labels_cache[$this->lang][$input])) : $this->LL_labels_cache[$this->lang][$input]; // For the cached output charset conversion has already happend! So perform HSC right here.
return $output.($this->debugKey ? ' ['.$input.']':'');
}
}
/**
* Loading $TCA_DESCR[$table]['columns'] with content from locallang files as defined in $TCA_DESCR[$table]['refs']
* $TCA_DESCR is a global var
*
* @param string Table name found as key in global array $TCA_DESCR
* @return void
*/
function loadSingleTableDescription($table) {
global $TCA_DESCR;
if (is_array($TCA_DESCR[$table])
&& !isset($TCA_DESCR[$table]['columns'])
&& is_array($TCA_DESCR[$table]['refs'])) { // First the 'table' cannot already be loaded in [columns] and secondly there must be a references to locallang files available in [refs]
// Init $TCA_DESCR for $table-key
$TCA_DESCR[$table]['columns']=array();
// Get local-lang for each file in $TCA_DESCR[$table]['refs'] as they are ordered.
foreach ($TCA_DESCR[$table]['refs'] as $llfile) {
$LOCAL_LANG = $this->includeLLFile($llfile,0,1);
// Traverse all keys
if (is_array($LOCAL_LANG['default'])) {
foreach($LOCAL_LANG['default'] as $lkey => $lVal) {
// exploding by '.':
// 0 => fieldname,
// 1 => type from (alttitle,description,details,syntax,image_descr,image,seeAlso),
// 2 => special instruction, see switch construct
$kParts = explode('.',$lkey);
// Detecting 'hidden' labels, converting to normal fieldname
if ($kParts[0]=='_') $kParts[0]='';
if (substr($kParts[0],0,1)=='_') { $kParts[0] = substr($kParts[0],1); }
// Add label:
switch((string)$kParts[2]) {
case '+': // adding
$TCA_DESCR[$table]['columns'][$kParts[0]][$kParts[1]].= chr(10).$lVal;
break;
default: // Substituting:
$TCA_DESCR[$table]['columns'][$kParts[0]][$kParts[1]] = $lVal;
break;
}
}
}
}
}
}
/**
* Includes locallang file (and possibly additional localized version if configured for)
* Read language labels will be merged with $LOCAL_LANG (if $setGlobal=1).
*
* @param string $fileRef is a file-reference (see t3lib_div::getFileAbsFileName)
* @param boolean Setting in global variable $LOCAL_LANG (or returning the variable)
* @param boolean If $mergeLocalOntoDefault is set the local part of the $LOCAL_LANG array is merged onto the default part (if the local part exists) and the local part is unset.
* @return mixed If $setGlobal is true the LL-files will set the $LOCAL_LANG in the global scope. Otherwise the $LOCAL_LANG array is returned from function
*/
function includeLLFile($fileRef,$setGlobal=1,$mergeLocalOntoDefault=0) {
// Configure for global flag:
if ($setGlobal) {
global $LOCAL_LANG;
}
// Get default file:
$llang = $this->readLLfile($fileRef);
if (count($llang)) {
$LOCAL_LANG = t3lib_div::array_merge_recursive_overrule((array)$LOCAL_LANG,$llang);
// Localized addition?
$lFileRef = $this->localizedFileRef($fileRef);
if ($lFileRef && (string)$LOCAL_LANG[$this->lang]=='EXT') {
$llang = $this->readLLfile($lFileRef);
$LOCAL_LANG = t3lib_div::array_merge_recursive_overrule($LOCAL_LANG,$llang);
}
// Overriding file?
if (isset($GLOBALS['TYPO3_CONF_VARS']['BE']['XLLfile'][$fileRef])) {
$ORarray = $this->readLLfile($GLOBALS['TYPO3_CONF_VARS']['BE']['XLLfile'][$fileRef]);
$LOCAL_LANG = t3lib_div::array_merge_recursive_overrule($LOCAL_LANG,$ORarray);
}
// Merge local onto default:
if ($mergeLocalOntoDefault && strcmp($this->lang,'default') && is_array($LOCAL_LANG[$this->lang]) && is_array($LOCAL_LANG['default'])) {
$LOCAL_LANG['default'] = array_merge($LOCAL_LANG['default'],$LOCAL_LANG[$this->lang]); // array_merge can be used so far the keys are not numeric - which we assume they are not...
unset($LOCAL_LANG[$this->lang]);
}
}
// Return value if not global is set.
if (!$setGlobal) {
return $LOCAL_LANG;
}
}
/**
* Includes a locallang file and returns the $LOCAL_LANG array found inside.
*
* @param string Input is a file-reference (see t3lib_div::getFileAbsFileName) which, if exists, is included. That file is expected to be a 'local_lang' file containing a $LOCAL_LANG array.
* @return array Value of $LOCAL_LANG found in the included file. If that array is found it's returned. Otherwise an empty array
*/
function readLLfile($fileRef) {
return t3lib_div::readLLfile($fileRef, $this->lang, $this->charSet);
}
/**
* Returns localized fileRef (.[langkey].php)
*
* @param string Filename/path of a 'locallang.php' file
* @return string Input filename with a '.[lang-key].php' ending added if $this->lang is not 'default'
*/
function localizedFileRef($fileRef) {
if ($this->lang!='default' && substr($fileRef,-4)=='.php') {
return substr($fileRef,0,-4).'.'.$this->lang.'.php';
}
}
}
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/lang/class.language.php']) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/lang/class.language.php']);
}
?>
typo3/sysext/cms/tslib/media/scripts/fe_adminLib.inc (Arbeitskopie)
function sendHTMLMail($content,$recipient,$dummy,$fromEmail,$fromName,$replyTo='') {
if (trim($recipient) && trim($content)) {
$cls=t3lib_div::makeInstanceClassName('t3lib_htmlmail');
if (class_exists($cls)) { // If htmlmail lib is included, then generate a nice HTML-email
// Avoid autoloading of t3lib_htmlmail, since it's only a strategy check here:
if (class_exists($cls, false)) { // If htmlmail lib is included, then generate a nice HTML-email
$parts = spliti('<title>|</title>',$content,3);
$subject = trim($parts[1]) ? trim($parts[1]) : 'TYPO3 FE Admin message';
typo3/sysext/cms/tslib/class.tslib_content.php (Arbeitskopie)
$parts = explode('->',$funcName);
if (count($parts)==2) { // Class
$cls = t3lib_div::makeInstanceClassName($parts[0]);
// Check whether class is available and try to reload includeLibs if possible:
if ($this->isClassAvailable($cls, $conf)) {
// Check whether class is available:
if (class_exists($cls)) {
$classObj = new $cls;
if (method_exists($classObj, $parts[1])) {
$classObj->cObj = &$this;
......
return $librariesIncluded;
}
/**
* Checks whether a PHP class is available. If the check fails, the method tries to
* determine the correct includeLibs to make the class available automatically.
*
* TypoScript example that can cause this:
* | plugin.tx_myext_pi1 = USER
* | plugin.tx_myext_pi1 {
* | includeLibs = EXT:myext/pi1/class.tx_myext_pi1.php
* | userFunc = tx_myext_pi1->main
* | }
* | 10 = USER
* | 10.userFunc = tx_myext_pi1->renderHeader
*
* @param string $className: The name of the PHP class to be checked
* @param array $config: TypoScript configuration (naturally of a USER or COA cObject)
* @return boolean Whether the class is available
* @link http://bugs.typo3.org/view.php?id=9654
* @TODO This method was introduced in TYPO3 4.3 and can be removed if the autoload was integrated
*/
protected function isClassAvailable($className, array $config = NULL) {
if (class_exists($className)) {
return true;
} elseif ($config) {
$pluginConfiguration =& $GLOBALS['TSFE']->tmpl->setup['plugin.'][$className . '.'];
if (isset($pluginConfiguration['includeLibs']) && $pluginConfiguration['includeLibs']) {
$config['includeLibs'] = $pluginConfiguration['includeLibs'];
return $this->includeLibs($config);
}
}
return false;
}
typo3/sysext/cms/tslib/index_ts.php (Arbeitskopie)
define('PATH_tslib', t3lib_extMgm::extPath('cms').'tslib/');
}
require_once(PATH_t3lib.'class.t3lib_db.php');
// *********************
// Autoloader
// *********************
$TT->push('Register Autoloader', '');
require_once(PATH_t3lib . 'class.t3lib_autoloader.php');
t3lib_div::makeInstance('t3lib_autoloader')->registerAutoloader();
$TT->pull();
$TYPO3_DB = t3lib_div::makeInstance('t3lib_DB');
$TYPO3_DB->debugOutput = $TYPO3_CONF_VARS['SYS']['sqlDebug'];
......
if ($TSFE->beUserLogin) {
$BE_USER->initializeFrontendEdit();
if ($BE_USER->frontendEdit instanceof t3lib_frontendedit) {
require_once(t3lib_extMgm::extPath('lang').'lang.php');
$LANG = t3lib_div::makeInstance('language');
$LANG->init($BE_USER->uc['lang']);
typo3/sysext/cms/tslib/class.tslib_eidtools.php (Arbeitskopie)
public static function initLanguage($language = 'default') {
if (!is_object($GLOBALS['LANG'])) {
require_once(PATH_t3lib . 'class.t3lib_cs.php');
require_once(t3lib_extMgm::extPath('lang', 'lang.php'));
$GLOBALS['LANG'] = t3lib_div::makeInstance('language');
$GLOBALS['LANG']->init($language);
}
typo3/sysext/indexed_search/class.crawler.php (Arbeitskopie)
# To make sure the backend charset is available:
require_once(PATH_typo3.'sysext/lang/lang.php');
if (!is_object($GLOBALS['LANG'])) {
$GLOBALS['LANG'] = t3lib_div::makeInstance('language');
$GLOBALS['LANG']->init($GLOBALS['BE_USER']->uc['lang']);
(5-5/14)