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
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • PHP
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • 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
  • cApiImageCheckImageEditingPossibility
  • 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
  • conGetUniqueArticleUrlname
  • conGetUsedModules
  • conHtmlentities
  • conHtmlEntityDecode
  • conHtmlSpecialChars
  • conIsArticleUrlnameUnique
  • conIsLocked
  • conLock
  • conLockBulkEditing
  • conMakeArticleIndex
  • conMakeCatOnline
  • conMakeInlineScript
  • conMakeOnline
  • conMakeOnlineBulkEditing
  • conMakePublic
  • conMakeStart
  • conMoveArticles
  • conPhp54Check
  • conRemoveOldCategoryArticle
  • conSaveContentEntry
  • conSetCodeFlag
  • conSetCodeFlagBulkEditing
  • conSetMetaValue
  • conSetStartArticle
  • consoleLog
  • 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
  • getFileInformation
  • getFileType
  • getGroupOrUserName
  • getIDForArea
  • getJsHelpContext
  • getLanguageNamesByClient
  • getLanguagesByClient
  • getmicrotime
  • getNamedFrame
  • getParentAreaId
  • getRightsList
  • 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
  • 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
  • strCheckAlias
  • 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:  * This file contains the module file translation class.
  4:  *
  5:  * @todo refactor documentation
  6:  *
  7:  * @package    Core
  8:  * @subpackage Backend
  9:  * @author     Rusmir Jusufovic
 10:  * @copyright  four for business AG <www.4fb.de>
 11:  * @license    http://www.contenido.org/license/LIZENZ.txt
 12:  * @link       http://www.4fb.de
 13:  * @link       http://www.contenido.org
 14:  */
 15: 
 16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 17: 
 18: /**
 19:  * This class save the translations from a modul in a file and get it
 20:  * from file.
 21:  *
 22:  * @package    Core
 23:  * @subpackage Backend
 24:  */
 25: class cModuleFileTranslation extends cModuleHandler {
 26: 
 27:     /**
 28:      * Path to the modul directory.
 29:      *
 30:      * @var string
 31:      */
 32:     private $_modulePath;
 33: 
 34:     /**
 35:      * Name of the translations file.
 36:      *
 37:      * @var string
 38:      */
 39:     static $fileName = '';
 40: 
 41:     /**
 42:      * Translation array.
 43:      *
 44:      * @var array
 45:      */
 46:     static $langArray = array();
 47: 
 48:     /**
 49:      * The id of the modul.
 50:      *
 51:      * @var int
 52:      */
 53:     static $savedIdMod = NULL;
 54:     static $originalTranslationDivider = '=';
 55: 
 56:     /**
 57:      * Constructor to create an instance of this class.
 58:      *
 59:      * @param int  $idmodul        [optional]
 60:      * @param bool $static         [optional]
 61:      *                             if true it will load once the translation from file
 62:      * @param int  $overrideIdlang [optional]
 63:      *                             use different language if not NULL
 64:      *
 65:      * @throws cException
 66:      * @throws cInvalidArgumentException
 67:      */
 68:     public function __construct($idmodul = NULL, $static = false, $overrideIdlang = NULL) {
 69:         parent::__construct($idmodul);
 70: 
 71:         // $this->_debug = true;
 72: 
 73:         if ($idmodul != NULL) {
 74:             $this->_modulePath = $this->getModulePath();
 75:         }
 76: 
 77:         // override language if specified
 78:         if ($overrideIdlang != NULL) {
 79:             $this->_idlang = $overrideIdlang;
 80:         }
 81: 
 82:         $this->_encoding = self::getEncoding($this->_idlang);
 83: 
 84:         // dont open the translations file for each mi18n call
 85:         if ($static == true) {
 86:             if (self::$savedIdMod != $idmodul) {
 87:                 // set filename lang_[language]_[Country].txt
 88:                 $language = $this->_getValueFromProperties('language', 'code');
 89:                 $country = $this->_getValueFromProperties('country', 'code');
 90:                 self::$fileName = 'lang_' . $language . '_' . cString::toUpperCase($country) . '.txt';
 91: 
 92:                 self::$langArray = $this->getTranslationArray();
 93:                 self::$savedIdMod = $idmodul;
 94:             }
 95:         } else {
 96:             self::$savedIdMod = -1;
 97: 
 98:             // set filename lang_[language]_[Country].txt
 99:             $language = $this->_getValueFromProperties('language', 'code');
100:             $country = $this->_getValueFromProperties('country', 'code');
101:             self::$fileName = 'lang_' . $language . '_' . cString::toUpperCase($country) . '.txt';
102:         }
103:     }
104: 
105:     /**
106:      * Get the value of a item from properties db.
107:      *
108:      * @param string $type
109:      * @param string $name
110:      *
111:      * @return string
112:      *         value
113:      *
114:      * @throws cDbException
115:      * @throws cException
116:      */
117:     private function _getValueFromProperties($type, $name) {
118:         cApiPropertyCollection::reset();
119:         $propColl = new cApiPropertyCollection();
120:         $propColl->changeClient($this->_client);
121:         return $propColl->getValue('idlang', $this->_idlang, $type, $name, '');
122:     }
123: 
124:     /**
125:      * Get the lang array.
126:      *
127:      * @return array
128:      */
129:     public function getLangArray() {
130:         return self::$langArray;
131:     }
132: 
133:     /**
134:      * Save the hole translations for a idmod and lang.
135:      * For the upgrade/setup.
136:      *
137:      * @throws cDbException
138:      * @throws cException
139:      */
140:     public function saveTranslations() {
141:         $db = cRegistry::getDb();
142: 
143:         $oLangColl = new cApiLanguageCollection();
144:         $ids = $oLangColl->getAllIds();
145:         foreach ($ids as $idlang) {
146:             $sql = 'SELECT * FROM `%s` WHERE idlang = %d AND idmod = %d';
147:             $sql = $db->prepare($sql, $this->_cfg['tab']['mod_translations'], $idlang, $this->_idmod);
148:             $db->query($sql);
149: 
150:             $this->_idlang = $idlang;
151:             // set filename lang_[language]_[Country].txt
152:             $language = $this->_getValueFromProperties('language', 'code');
153:             $country = $this->_getValueFromProperties('country', 'code');
154:             self::$fileName = 'lang_' . $language . '_' . cString::toUpperCase($country) . '.txt';
155: 
156:             $translations = array();
157:             while ($db->nextRecord()) {
158:                 $original = mb_convert_encoding(urldecode(cSecurity::unFilter($db->f('original'))), "UTF-8");
159:                 $translation = mb_convert_encoding(urldecode(cSecurity::unFilter($db->f('translation'))), "UTF-8");
160:                 $translations[$original] = $translation;
161:             }
162: 
163:             $text = $this->readInput();
164:             if (!$text) {
165:                 $text = "";
166:             }
167:             $text .= $this->readOutput();
168: 
169:             mb_ereg_search_init($text, 'mi18n\(["|\'](.*?)["|\']\)');
170:             while(mb_ereg_search()) {
171:                 $translation = mb_ereg_search_getregs();
172:                 if(!isset($translations[$translation[1]])) {
173:                     $translations[$translation[1]] = $translation[1];
174:                 }
175:             }
176: 
177:             if (count($translations) != 0) {
178:                 if ($this->saveTranslationArray($translations) == false) {
179:                     cWarning(__FILE__, __LINE__, 'Could not save translate idmod=' . $this->_idmod . ' !');
180:                 }
181:             }
182:         }
183:     }
184: 
185:     /**
186:      * This method serialize an array.
187:      *
188:      * $key.[Divider].$value."\r\n"
189:      *
190:      * @param array $wordListArray
191:      * @return string
192:      */
193:     private function _serializeArray($wordListArray) {
194:         $retString = '';
195:         foreach ($wordListArray as $key => $value) {
196:             // Original String [Divider] Translation String
197:             if (cString::getStringLength($key) > 0) {
198:                 $retString .= trim($key . self::$originalTranslationDivider . $value) . "\r\n";
199:             }
200:         }
201: 
202:         return trim($retString);
203:     }
204: 
205:     /**
206:      * This method unserialize a string.
207:      * The contents of file looks like
208:      * <Original String><Divider><Translation String>.
209:      *
210:      * Example:
211:      * If divider is "="
212:      * Hello World=Hallo Welt
213:      *
214:      * @param string $string
215:      *         the contents of the file
216:      * @return array
217:      */
218:     private function _unserializeArray($string) {
219:         $retArray = array();
220: 
221:         $string = $string . PHP_EOL;
222:         $words = preg_split('((\r\n)|(\r)|(\n))', cString::getPartOfString($string, 0, cString::getStringLength($string) - cString::getStringLength(PHP_EOL)));
223: 
224:         foreach ($words as $key => $value) {
225:             $oriTrans = preg_split('/(?<!\\\\)' . self::$originalTranslationDivider . '/', $value);
226: 
227:             if (isset($oriTrans[1])) {
228:                 $retArray[cString::recodeString($oriTrans[0], $this->_fileEncoding, $this->_encoding)] = cString::recodeString(str_replace("\=", "=", $oriTrans[1]), $this->_fileEncoding, $this->_encoding);
229:             } else {
230:                 // CON-1671 never use end(array_keys(...))
231:                 $keys = array_keys($retArray);
232:                 $lastKey = end($keys);
233:                 $newValue = PHP_EOL . cString::recodeString(str_replace("\=", "=", $oriTrans[0]), $this->_fileEncoding, $this->_encoding);
234:                 $retArray[$lastKey] .= $newValue;
235:             }
236:         }
237: 
238:         return $retArray;
239:     }
240: 
241:     /**
242:      * Save the contents of the wordListArray in file.
243:      *
244:      * @param array $wordListArray
245:      *
246:      * @return bool
247:      *         true on success or false on failure
248:      * @throws cInvalidArgumentException
249:      */
250:     public function saveTranslationArray($wordListArray) {
251:         $fileName = $this->_modulePath . $this->_directories['lang'] . self::$fileName;
252: 
253:         if (!$this->createModuleDirectory('lang') || !$this->isWritable($fileName, $this->_modulePath . $this->_directories['lang'])) {
254:             return false;
255:         }
256: 
257:         $escapedArray = array();
258:         foreach ($wordListArray as $key => $value) {
259:             $newKey = cString::ereg_replace("=", "\\=", $key);
260:             $newValue = cString::ereg_replace("=", "\\=", $value);
261:             $escapedArray[$newKey] = $newValue;
262:         }
263: 
264:         if (cFileHandler::write($fileName, $this->_serializeArray($escapedArray) . "\r\n") === false) {
265:             return false;
266:         } else {
267:             return true;
268:         }
269:     }
270: 
271:     /**
272:      * Get the translations array.
273:      *
274:      * @return array
275:      * @throws cInvalidArgumentException
276:      */
277:     public function getTranslationArray() {
278:         if (cFileHandler::exists($this->_modulePath . $this->_directories['lang'] . self::$fileName)) {
279:             $array = $this->_unserializeArray(cFileHandler::read($this->_modulePath . $this->_directories['lang'] . self::$fileName));
280:             return $array;
281:         } else {
282:             return array();
283:         }
284:     }
285: 
286: }
287: 
CMS CONTENIDO 4.10.0 API documentation generated by ApiGen 2.8.0