Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • cAjaxRequest
  • cAutoload
  • cBackend
  • cEffectiveSetting
  • cGuiScrollListAlltranslations
  • cHTMLValidator
  • cMailer
  • cModuleFileTranslation
  • cModuleHandler
  • cModuleSearch
  • cModuleSynchronizer
  • cModuleTemplateHandler
  • CodeMirror
  • cPasswordRequest
  • cPermission
  • cRegistry
  • cSystemPurge
  • cSystemtest
  • cTinymce4Configuration
  • cTinyMCE4Editor
  • cTinyMCEEditor
  • cWYSIWYGEditor
  • FrontendList
  • HtmlParser
  • TODOBackendList
  • TreeItem
  • UploadList
  • UploadSearchResultList

Functions

  • addArtspec
  • addSortImages
  • backToMainArea
  • buildArticleSelect
  • buildCategorySelect
  • buildCategorySelectRights
  • buildHeapTable
  • buildStackString
  • buildTree
  • buildUserOrGroupPermsFromRequest
  • callPluginStore
  • cApiCatGetLevelNode
  • cApiImageCheckCachedImageValidity
  • cApiImageCheckImageEditingPosibility
  • cApiImageGetCacheFileName
  • cApiImageGetTargetDimensions
  • cApiImageIsAnimGif
  • cApiImgScale
  • cApiImgScaleGetMD5CacheFile
  • cApiImgScaleHQ
  • cApiImgScaleImageMagick
  • cApiImgScaleLQ
  • cApiIsImageMagickAvailable
  • cApiStrCleanURLCharacters
  • cApiStrNormalizeLineEndings
  • cApiStrRecodeString
  • cApiStrReplaceDiacritics
  • cApiStrTrimAfterWord
  • cApiStrTrimHard
  • cApiStrTrimSentence
  • cDeprecated
  • cDie
  • cError
  • checkLangInClients
  • checkPathInformation
  • cInclude
  • compareUrlStrings
  • conChangeTemplateForCat
  • conCopyArticle
  • conCopyArtLang
  • conCopyContainerConf
  • conCopyContent
  • conCopyMetaTags
  • conCopyTemplateConfiguration
  • conCreateLocationString
  • conDeeperCategoriesArray
  • conDeleteart
  • conEditArt
  • conEditFirstTime
  • conFetchCategoryTree
  • conFlagOnOffline
  • conGenerateCode
  • conGenerateCodeForAllArts
  • conGenerateCodeForAllArtsInCategory
  • conGenerateCodeForAllartsUsingLayout
  • conGenerateCodeForAllartsUsingMod
  • conGenerateCodeForAllArtsUsingTemplate
  • conGenerateCodeForArtInAllCategories
  • conGenerateCodeForClient
  • conGenerateKeywords
  • conGetAvailableMetaTagTypes
  • conGetCategoryArticleId
  • conGetCategoryAssignments
  • conGetContainerConfiguration
  • conGetContentFromArticle
  • conGetHtmlTranslationTable
  • conGetMetaValue
  • conGetTemplateConfigurationIdForArticle
  • conGetTemplateConfigurationIdForCategory
  • conGetTopmostCat
  • conGetUsedModules
  • conHtmlentities
  • conHtmlEntityDecode
  • conHtmlSpecialChars
  • conIsLocked
  • conLock
  • conLockBulkEditing
  • conMakeArticleIndex
  • conMakeCatOnline
  • conMakeInlineScript
  • conMakeOnline
  • conMakeOnlineBulkEditing
  • conMakePublic
  • conMakeStart
  • conMoveArticles
  • conPhp54Check
  • conRemoveOldCategoryArticle
  • conSaveContentEntry
  • conSetCodeFlag
  • conSetCodeFlagBulkEditing
  • conSetMetaValue
  • conSyncArticle
  • copyRightsForElement
  • createBulkEditingFunction
  • createRandomName
  • createRightsForElement
  • cWarning
  • dbGetColumns
  • dbGetIndexes
  • dbGetPrimaryKeyName
  • dbTableExists
  • dbUpgradeTable
  • defineIfNotDefined
  • deleteArtspec
  • deleteRightsForElement
  • deleteSystemProperty
  • displayDatetime
  • emptyLogFile
  • endAndLogTiming
  • extractNumber
  • generateDisplayFilePath
  • generateJs
  • getAllClientsAndLanguages
  • getArtLang
  • getArtspec
  • getAvailableContentTypes
  • getCanonicalDay
  • getCanonicalMonth
  • getDirectorySize
  • getEffectiveSetting
  • getEffectiveSettingsByType
  • getEncodingByLanguage
  • getFileContents
  • getFileInformation
  • getFileType
  • getGroupOrUserName
  • getIDForArea
  • getJsHelpContext
  • getLanguageNamesByClient
  • getLanguagesByClient
  • getmicrotime
  • getNamedFrame
  • getParam
  • getParentAreaId
  • getSearchResults
  • getStrExpandCollapseButton
  • getSystemProperties
  • getSystemPropertiesByType
  • getSystemProperty
  • getTemplateSelect
  • getUplExpandCollapseButton
  • htmldecode
  • htmlentities_iso88592
  • humanReadableSize
  • includePlugins
  • insertEmptyStrRow
  • ipMatch
  • isAlphanumeric
  • isArchive
  • isArtInMultipleUse
  • isFunctionDisabled
  • isGroup
  • isIPv4
  • isRunningFromWeb
  • isStartArticle
  • isUtf8
  • isValidMail
  • langActivateDeactivateLanguage
  • langDeleteLanguage
  • langEditLanguage
  • langGetTextDirection
  • langNewLanguage
  • langRenameLanguage
  • layDeleteLayout
  • layEditLayout
  • machineReadableSize
  • mailLogBulkEditingFunctions
  • mailLogDecodeAddresses
  • markSubMenuItem
  • mask
  • modDeleteModule
  • modEditModule
  • phpInfoToHtml
  • plugin_include
  • prCreateURLNameLocationString
  • prDeleteCacheFileContent
  • prGetCacheFileContent
  • prResolvePathViaCategoryNames
  • prResolvePathViaURLNames
  • prWriteCacheFileContent
  • putFileContents
  • recursiveCopy
  • removeFileInformation
  • renderBackendBreadcrumb
  • renderLabel
  • renderSelectProperty
  • renderTextProperty
  • saveGroupRights
  • saveRights
  • scanDirectory
  • scanPlugins
  • sendEncodingHeader
  • set_magic_quotes_gpc
  • setArtspecDefault
  • setArtspecOnline
  • setSystemProperty
  • showTree
  • startTiming
  • statCreateLocationString
  • statDisplayTopChooser
  • statDisplayYearlyTopChooser
  • statGetAvailableMonths
  • statGetAvailableYears
  • statResetStatistic
  • statsArchive
  • statsDisplayInfo
  • statsOverviewAll
  • statsOverviewTop
  • statsOverviewTopYear
  • statsOverviewYear
  • strAssignTemplate
  • strBuildSqlValues
  • strCheckTreeForErrors
  • strCopyCategory
  • strCopyTree
  • strDeeperCategoriesArray
  • strDeleteCategory
  • strHasArticles
  • strHasStartArticle
  • strMakePublic
  • strMakeVisible
  • strMoveCatTargetallowed
  • strMoveDownCategory
  • strMoveSubtree
  • strMoveUpCategory
  • strNewCategory
  • strNewTree
  • strNextBackwards
  • strNextDeeper
  • strNextDeeperAll
  • strNextPost
  • strOrderedPostTreeList
  • strRemakeTreeTable
  • strRenameCategory
  • strRenameCategoryAlias
  • strSortPrePost
  • strSyncCategory
  • systemHavePerm
  • tplAutoFillModules
  • tplBrowseLayoutForContainers
  • tplcfgDuplicate
  • tplDeleteTemplate
  • tplDuplicateTemplate
  • tplEditTemplate
  • tplGetContainerDefault
  • tplGetContainerMode
  • tplGetContainerName
  • tplGetContainerNumbersInLayout
  • tplGetContainerTypes
  • tplGetInUsedData
  • tplIsTemplateInUse
  • tplPreparseLayout
  • tplProcessSendContainerConfiguration
  • updateClientCache
  • updateFileInformation
  • uplCreateFriendlyName
  • uplDirectoryListRecursive
  • uplGetDirectoriesToExclude
  • uplGetFileExtension
  • uplGetFileIcon
  • uplGetFileTypeDescription
  • uplGetThumbnail
  • uplHasFiles
  • uplHasSubdirs
  • uplmkdir
  • uplRecursiveDBDirectoryList
  • uplRecursiveDirectoryList
  • uplRenameDirectory
  • uplSearch
  • uplSyncDirectory
  • uplSyncDirectoryDBFS
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: 
  3: /**
  4:  * This file contains the module file translation class.
  5:  * TODO: Rework comments of this class.
  6:  *
  7:  * @package    Core
  8:  * @subpackage Backend
  9:  * @version    SVN Revision $Rev:$
 10:  *
 11:  * @author     Rusmir Jusufovic
 12:  * @copyright  four for business AG <www.4fb.de>
 13:  * @license    http://www.contenido.org/license/LIZENZ.txt
 14:  * @link       http://www.4fb.de
 15:  * @link       http://www.contenido.org
 16:  */
 17: 
 18: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 19: 
 20: /**
 21:  * This class save the translations from a modul in a file
 22:  * and get it from file.
 23:  *
 24:  * @package    Core
 25:  * @subpackage Backend
 26:  */
 27: class cModuleFileTranslation extends cModuleHandler {
 28: 
 29:     /**
 30:      * Path to the modul directory
 31:      *
 32:      * @var string
 33:      */
 34:     private $_modulePath;
 35: 
 36:     /**
 37:      * Name of the translations file
 38:      *
 39:      * @var string
 40:      */
 41:     static $fileName = '';
 42: 
 43:     /**
 44:      * Translation array.
 45:      *
 46:      * @var array
 47:      */
 48:     static $langArray = array();
 49: 
 50:     /**
 51:      * The id of the modul
 52:      *
 53:      * @var int
 54:      */
 55:     static $savedIdMod = NULL;
 56:     static $originalTranslationDivider = '=';
 57: 
 58:     /**
 59:      *
 60:      * @param int $idmodul [optional]
 61:      * @param bool $static [optional]
 62:      *         if true it will load once the translation from file
 63:      * @param int $overrideIdlang [optional]
 64:      *         use different language if not NULL
 65:      */
 66:     public function __construct($idmodul = NULL, $static = false, $overrideIdlang = NULL) {
 67:         parent::__construct($idmodul);
 68: 
 69:         // $this->_debug = true;
 70: 
 71:         if ($idmodul != NULL) {
 72:             $this->_modulePath = $this->getModulePath();
 73:         }
 74: 
 75:         // override language if specified
 76:         if ($overrideIdlang != NULL) {
 77:             $this->_idlang = $overrideIdlang;
 78:         }
 79: 
 80:         $this->_encoding = self::getEncoding($this->_idlang);
 81: 
 82:         // dont open the translations file for each mi18n call
 83:         if ($static == true) {
 84:             if (self::$savedIdMod != $idmodul) {
 85:                 // set filename lang_[language]_[Country].txt
 86:                 $language = $this->_getValueFromProperties('language', 'code');
 87:                 $country = $this->_getValueFromProperties('country', 'code');
 88:                 self::$fileName = 'lang_' . $language . '_' . strtoupper($country) . '.txt';
 89: 
 90:                 self::$langArray = $this->getTranslationArray();
 91:                 self::$savedIdMod = $idmodul;
 92:             }
 93:         } else {
 94:             self::$savedIdMod = -1;
 95: 
 96:             // set filename lang_[language]_[Country].txt
 97:             $language = $this->_getValueFromProperties('language', 'code');
 98:             $country = $this->_getValueFromProperties('country', 'code');
 99:             self::$fileName = 'lang_' . $language . '_' . strtoupper($country) . '.txt';
100:         }
101:     }
102: 
103:     /**
104:      * Get the value of a item from properties db.
105:      *
106:      * @param string $type
107:      * @param string $name
108:      * @return string
109:      *         value
110:      */
111:     private function _getValueFromProperties($type, $name) {
112:         cApiPropertyCollection::reset();
113:         $propColl = new cApiPropertyCollection();
114:         $propColl->changeClient($this->_client);
115:         return $propColl->getValue('idlang', $this->_idlang, $type, $name, '');
116:     }
117: 
118:     /**
119:      * Get the lang array.
120:      *
121:      * @return array
122:      */
123:     public function getLangArray() {
124:         return self::$langArray;
125:     }
126: 
127:     /**
128:      * Save the hole translations for a idmod and lang.
129:      * For the upgrade/setup.
130:      */
131:     public function saveTranslations() {
132:         $db = cRegistry::getDb();
133: 
134:         $oLangColl = new cApiLanguageCollection();
135:         $ids = $oLangColl->getAllIds();
136:         foreach ($ids as $idlang) {
137:             $sql = 'SELECT * FROM `%s` WHERE idlang = %d AND idmod = %d';
138:             $sql = $db->prepare($sql, $this->_cfg['tab']['mod_translations'], $idlang, $this->_idmod);
139:             $db->query($sql);
140: 
141:             $this->_idlang = $idlang;
142:             // set filename lang_[language]_[Country].txt
143:             $language = $this->_getValueFromProperties('language', 'code');
144:             $country = $this->_getValueFromProperties('country', 'code');
145:             self::$fileName = 'lang_' . $language . '_' . strtoupper($country) . '.txt';
146: 
147:             $translations = array();
148:             while ($db->nextRecord()) {
149:                 $original = mb_convert_encoding(urldecode(cSecurity::unfilter($db->f('original'))), "UTF-8");
150:                 $translation = mb_convert_encoding(urldecode(cSecurity::unfilter($db->f('translation'))), "UTF-8");
151:                 $translations[$original] = $translation;
152:             }
153: 
154:             $text = $this->readInput();
155:             if (!$text) {
156:                 $text = "";
157:             }
158:             $text .= $this->readOutput();
159: 
160:             mb_ereg_search_init($text, 'mi18n\(["|\'](.*?)["|\']\)');
161:             while(mb_ereg_search()) {
162:                 $translation = mb_ereg_search_getregs();
163:                 if(!isset($translations[$translation[1]])) {
164:                     $translations[$translation[1]] = $translation[1];
165:                 }
166:             }
167: 
168:             if (count($translations) != 0) {
169:                 if ($this->saveTranslationArray($translations) == false) {
170:                     cWarning(__FILE__, __LINE__, 'Could not save translate idmod=' . $this->_idmod . ' !');
171:                 }
172:             }
173:         }
174:     }
175: 
176:     /**
177:      * This method serialize a array.
178:      * $key.[Divider].$value."\r\n"
179:      *
180:      * @param array $wordListArray
181:      * @return string
182:      */
183:     private function _serializeArray($wordListArray) {
184:         $retString = '';
185:         foreach ($wordListArray as $key => $value) {
186:             // Originall String [Divider] Translation String
187:             $retString .= $key . self::$originalTranslationDivider . $value . "\r\n";
188:         }
189: 
190:         return $retString;
191:     }
192: 
193:     /**
194:      * This method unserialize a string.
195:      * The contents of file looks like original String [Divider] Translation
196:      * String.
197:      * If divider is =
198:      * Example: Hello World=Hallo Welt
199:      *
200:      * @param string $string
201:      *         the contents of the file
202:      * @return array
203:      */
204:     private function _unserializeArray($string) {
205:         $retArray = array();
206: 
207:         $words = preg_split('((\r\n)|(\r)|(\n))', substr($string, 0, strlen($string) - strlen(PHP_EOL)));
208: 
209:         foreach ($words as $key => $value) {
210:             $oriTrans = preg_split('/(?<!\\\\)' . self::$originalTranslationDivider . '/', $value);
211: 
212:             if (isset($oriTrans[1])) {
213:                 $retArray[cString::recodeString($oriTrans[0], $this->_fileEncoding, $this->_encoding)] = cString::recodeString(str_replace("\=", "=", $oriTrans[1]), $this->_fileEncoding, $this->_encoding);
214:             } else {
215:                 // CON-1671 never use end(array_keys(...))
216:                 $keys = array_keys($retArray);
217:                 $lastKey = end($keys);
218:                 $newValue = PHP_EOL . cString::recodeString(str_replace("\=", "=", $oriTrans[0]), $this->_fileEncoding, $this->_encoding);
219:                 $retArray[$lastKey] .= $newValue;
220:             }
221:         }
222: 
223:         return $retArray;
224:     }
225: 
226:     /**
227:      * Save the contents of the wordListArray in file.
228:      *
229:      * @param array $wordListArray
230:      * @return bool
231:      *         true if success else false
232:      */
233:     public function saveTranslationArray($wordListArray) {
234:         $fileName = $this->_modulePath . $this->_directories['lang'] . self::$fileName;
235: 
236:         if (!$this->createModuleDirectory('lang') || !$this->isWritable($fileName, $this->_modulePath . $this->_directories['lang'])) {
237:             return false;
238:         }
239: 
240:         $escapedArray = array();
241:         foreach ($wordListArray as $key => $value) {
242:             $newKey = mb_ereg_replace("=", "\\=", $key);
243:             $newValue = mb_ereg_replace("=", "\\=", $value);
244:             $escapedArray[$newKey] = $newValue;
245:         }
246: 
247:         if (cFileHandler::write($fileName, $this->_serializeArray($escapedArray)) === false) {
248:             return false;
249:         } else {
250:             return true;
251:         }
252:     }
253: 
254:     /**
255:      * Get the translations array.
256:      *
257:      * @return array
258:      */
259:     public function getTranslationArray() {
260:         if (cFileHandler::exists($this->_modulePath . $this->_directories['lang'] . self::$fileName)) {
261:             $array = $this->_unserializeArray(cFileHandler::read($this->_modulePath . $this->_directories['lang'] . self::$fileName));
262:             return $array;
263:         } else {
264:             return array();
265:         }
266:     }
267: 
268: }
269: 
CMS CONTENIDO 4.9.8 API documentation generated by ApiGen 2.8.0