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
    • SIWECOS
    • 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
  • cRights
  • 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
  • Function
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: 
  3: /**
  4:  * This file contains the CONTENIDO template functions.
  5:  *
  6:  * @package          Core
  7:  * @subpackage       Backend
  8:  * @author           Olaf Niemann
  9:  * @author           Jan Lengowski
 10:  * @author           Munkh-Ulzii Balidar
 11:  * @copyright        four for business AG <www.4fb.de>
 12:  * @license          http://www.contenido.org/license/LIZENZ.txt
 13:  * @link             http://www.4fb.de
 14:  * @link             http://www.contenido.org
 15:  */
 16: 
 17: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 18: 
 19: cInclude("includes", "functions.con.php");
 20: 
 21: /**
 22:  * Edit or create a new Template
 23:  *
 24:  * @param unknown_type $changelayout
 25:  * @param unknown_type $idtpl
 26:  * @param unknown_type $name
 27:  * @param unknown_type $description
 28:  * @param unknown_type $idlay
 29:  * @param unknown_type $c
 30:  * @param unknown_type $default
 31:  *
 32:  * @return number|Ambigous <mixed, bool, multitype:>
 33:  *                         
 34:  * @throws cDbException
 35:  * @throws cException
 36:  * @throws cInvalidArgumentException
 37:  */
 38: function tplEditTemplate($changelayout, $idtpl, $name, $description, $idlay, $c, $default) {
 39:     global $db, $sess, $auth, $client, $cfg;
 40: 
 41:     $author = (string) $auth->auth['uname'];
 42: 
 43:     $template = new cApiTemplate();
 44:     /*CON-2545: load template by id and not by its name */
 45:     $template->loadByMany(array('idclient' => $client, 'idtpl' => $idtpl));
 46: 
 47:     if ($template->isLoaded() && $template->get('idtpl') != $idtpl) {
 48:         cRegistry::addErrorMessage(i18n("Template name already exists"));
 49:         return -1;
 50:     }
 51: 
 52:     if (true === cRegistry::getConfigValue('simulate_magic_quotes')) {
 53:         $name = stripslashes($name);
 54:         $description = stripslashes($description);
 55:     }
 56: 
 57:     if (!$idtpl) {
 58:         // Insert new entry in the Template table
 59:         $templateColl = new cApiTemplateCollection();
 60:         $template = $templateColl->create($client, $idlay, 0, $name, $description, 1, 0, 0);
 61:         $idtpl = $template->get('idtpl');
 62: 
 63:         // Insert new entry in the Template Conf table
 64:         $templateConfColl = new cApiTemplateConfigurationCollection();
 65:         $templateConf = $templateConfColl->create($idtpl);
 66:         $idtplcfg = $templateConf->get('idtplcfg');
 67: 
 68:         // Update new idtplconf
 69:         $template->set('idtplcfg', $idtplcfg);
 70:         $template->store();
 71: 
 72:         // Set correct rights for element
 73:         cRights::createRightsForElement('tpl', $idtpl);
 74:     } else {
 75: 
 76:         // Define lastmodified variable with actual date
 77:         $lastmodified = date('Y-m-d H:i:s');
 78: 
 79:         // Update existing entry in the Template table
 80:         $template = new cApiTemplate($idtpl);
 81:         $template->set('name', $name);
 82:         $template->set('description', $description);
 83:         $template->set('idlay', $idlay);
 84:         $template->set('author', $author);
 85:         $template->set('lastmodified', $lastmodified);
 86:         $template->store();
 87: 
 88:         // Delete all container assigned to this template
 89:         $containerColl = new cApiContainerCollection();
 90:         $containerColl->clearAssignments($idtpl);
 91: 
 92:         if (is_array($c) && (int)$changelayout !== 1) {
 93:             foreach ($c as $idcontainer => $dummyval) {
 94:                 $containerColl2 = new cApiContainerCollection();
 95:                 $containerColl2->create($idtpl, $idcontainer, $c[$idcontainer]);
 96:             }
 97:         }
 98: 
 99:         // Generate code
100:         conGenerateCodeForAllArtsUsingTemplate($idtpl);
101:     }
102: 
103:     if ($default == 1) {
104:         $sql = "UPDATE " . $cfg["tab"]["tpl"] . " SET defaulttemplate = 0 WHERE idclient = " . cSecurity::toInteger($client) . " AND idtpl != " . cSecurity::toInteger($template->get('idtpl'));
105:         $db->query($sql);
106: 
107:         $template->set('defaulttemplate', 1);
108:         $template->store();
109:     } else {
110:         $template->set('defaulttemplate', 0);
111:         $template->store();
112:     }
113: 
114:     // if layout is changed stay at 'tpl_edit' otherwise go to 'tpl'
115:     // if ($changelayout != 1) {
116:     //     $url = $sess->url("main.php?area=tpl_edit&idtpl=$idtpl&frame=4&blubi=blubxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
117:     //     header("location: $url");
118:     // }
119: 
120:     return $idtpl;
121: }
122: 
123: /**
124:  * Delete a template
125:  *
126:  * @param int $idtpl
127:  *         ID of the template to duplicate
128:  *
129:  * @throws cDbException
130:  * @throws cInvalidArgumentException
131:  */
132: function tplDeleteTemplate($idtpl) {
133: 
134:     global $db, $client, $lang, $cfg, $area_tree, $perm;
135: 
136:     $sql = "DELETE FROM " . $cfg["tab"]["tpl"] . " WHERE idtpl = '" . cSecurity::toInteger($idtpl) . "'";
137:     $db->query($sql);
138: 
139:     /* JL 160603 : Delete all unnecessary entries */
140: 
141:     $sql = "DELETE FROM " . $cfg["tab"]["container"] . " WHERE idtpl = '" . cSecurity::toInteger($idtpl) . "'";
142:     $db->query($sql);
143: 
144:     $idsToDelete = array();
145:     $sql = "SELECT idtplcfg FROM " . $cfg["tab"]["tpl_conf"] . " WHERE idtpl = '" . cSecurity::toInteger($idtpl) . "'";
146:     $db->query($sql);
147:     while ($db->nextRecord()) {
148:         $idsToDelete[] = $db->f("idtplcfg");
149:     }
150: 
151:     foreach ($idsToDelete as $id) {
152:         $sql = "DELETE FROM " . $cfg["tab"]["tpl_conf"] . " WHERE idtplcfg = '" . cSecurity::toInteger($id) . "'";
153:         $db->query($sql);
154: 
155:         $sql = "DELETE FROM " . $cfg["tab"]["container_conf"] . " WHERE idtplcfg = '" . cSecurity::toInteger($id) . "'";
156:         $db->query($sql);
157:     }
158: 
159:     cRights::deleteRightsForElement("tpl", $idtpl);
160: }
161: 
162: /**
163:  * Browse a specific layout for containers
164:  *
165:  * @param $idlay
166:  *
167:  * @return string
168:  *         &-separated string of all containers
169:  * 
170:  * @throws cInvalidArgumentException
171:  */
172: function tplBrowseLayoutForContainers($idlay) {
173:     global $db, $cfg, $containerinf, $lang;
174: 
175:     $layoutInFile = new cLayoutHandler($idlay, '', $cfg, $lang);
176:     $code = $layoutInFile->getLayoutCode();
177: 
178:     $containerNumbers = array();
179:     $returnStr = '';
180: 
181:     preg_match_all("/CMS_CONTAINER\[([0-9]*)\]/", $code, $containerMatches);
182:     $posBody = cString::findFirstPosCI($code, '<body>');
183:     $codeBeforeHeader = cString::getPartOfString($code, 0, $posBody);
184: 
185:     foreach ($containerMatches[1] as $value) {
186:         if (preg_match("/CMS_CONTAINER\[$value\]/", $codeBeforeHeader)) {
187:             $containerinf[$idlay][$value]["is_body"] = false;
188:         } else {
189:             $containerinf[$idlay][$value]["is_body"] = true;
190:         }
191:     }
192: 
193:     if (is_array($containerinf[$idlay])) {
194:         foreach ($containerinf[$idlay] as $key => $value) {
195:             $containerMatches[1][] = $key;
196:         }
197:     }
198: 
199:     foreach ($containerMatches[1] as $value) {
200:         if (!in_array($value, $containerNumbers)) {
201:             $containerNumbers[] = $value;
202:         }
203:     }
204:     asort($containerNumbers);
205: 
206:     $returnStr = implode('&', $containerNumbers);
207: 
208:     return $returnStr;
209: }
210: 
211: /**
212:  * Wrapper for tplPreparseLayout() and tplBrowseLayoutForContainers().
213:  * Calls both functions to get the container numbers from layout and return
214:  * the list of found container numbers.
215:  *
216:  * @param int $idlay
217:  *
218:  * @return array
219:  * 
220:  * @throws cInvalidArgumentException
221:  */
222: function tplGetContainerNumbersInLayout($idlay) {
223:     $containerNumbers = array();
224: 
225:     tplPreparseLayout($idlay);
226:     $containerNumbersStr = tplBrowseLayoutForContainers($idlay);
227:     if (!empty($containerNumbersStr)) {
228:         $containerNumbers = explode('&', $containerNumbersStr);
229:     }
230: 
231:     return $containerNumbers;
232: }
233: 
234: /**
235:  * Retrieve the container name
236:  *
237:  * @param int $idlay
238:  *         Layout number to browse
239:  * @param int $container
240:  *         Container number
241:  * @return string
242:  *         Container name
243:  */
244: function tplGetContainerName($idlay, $container) {
245:     global $db, $cfg, $containerinf;
246: 
247:     if (is_array($containerinf[$idlay])) {
248:         if (array_key_exists($container, $containerinf[$idlay])) {
249:             return $containerinf[$idlay][$container]["name"];
250:         }
251:     }
252: }
253: 
254: /**
255:  * Retrieve the container mode
256:  *
257:  * @param int $idlay
258:  *         Layout number to browse
259:  * @param int $container
260:  *         Container number
261:  * @return string|null
262:  *         Container name or null
263:  */
264: function tplGetContainerMode($idlay, $container) {
265:     global $containerinf;
266: 
267:     if (is_array($containerinf[$idlay])) {
268:         if (array_key_exists($container, $containerinf[$idlay])) {
269:             return $containerinf[$idlay][$container]["mode"];
270:         }
271:     }
272: }
273: 
274: /**
275:  * Retrieve the allowed container types
276:  *
277:  * @param int $idlay
278:  *         Layout number to browse
279:  * @param int $container
280:  *         Container number
281:  * @return array
282:  *         Allowed container types
283:  */
284: function tplGetContainerTypes($idlay, $container) {
285:     global $containerinf;
286: 
287:     if (is_array($containerinf[$idlay])) {
288:         if (array_key_exists($container, $containerinf[$idlay])) {
289:             if ($containerinf[$idlay][$container]["types"] != "") {
290:                 $list = explode(",", $containerinf[$idlay][$container]["types"]);
291: 
292:                 foreach ($list as $key => $value) {
293:                     $list[$key] = trim($value);
294:                 }
295:                 return $list;
296:             }
297:         }
298:     }
299: 
300:     return [];
301: }
302: 
303: /**
304:  * Retrieve the default module
305:  *
306:  * @param int $idlay
307:  *         Layout number to browse
308:  * @param int $container
309:  *         Container number
310:  * @return string|null
311:  *         Default module name or null
312:  */
313: function tplGetContainerDefault($idlay, $container) {
314:     global $containerinf;
315: 
316:     if (is_array($containerinf[$idlay])) {
317:         if (array_key_exists($container, $containerinf[$idlay])) {
318:             return $containerinf[$idlay][$container]["default"];
319:         }
320:     }
321: }
322: 
323: /**
324:  * Preparse the layout for caching purposes
325:  *
326:  * @param int $idlay
327:  *         Layout number to browse
328:  *
329:  * @throws cInvalidArgumentException
330:  */
331: function tplPreparseLayout($idlay) {
332:     global $db, $cfg, $containerinf, $lang;
333: 
334:     $layoutInFile = new cLayoutHandler($idlay, "", $cfg, $lang);
335:     $code = $layoutInFile->getLayoutCode();
336: 
337:     $parser = new HtmlParser($code);
338:     $bIsBody = false;
339: 
340:     while ($parser->parse()) {
341:         if (cString::toLowerCase($parser->getNodeName()) == 'body') {
342:             $bIsBody = true;
343:         }
344: 
345:         if ($parser->getNodeName() == "container" && $parser->getNodeType() == HtmlParser::NODE_TYPE_ELEMENT) {
346:             $idcontainer = $parser->getNodeAttributes('id');
347: 
348:             $mode = $parser->getNodeAttributes('mode');
349: 
350:             if ($mode == "") {
351:                 $mode = "optional";
352:             }
353: 
354:             $containerinf[$idlay][$idcontainer]["name"] = $parser->getNodeAttributes('name');
355:             $containerinf[$idlay][$idcontainer]["mode"] = $mode;
356:             $containerinf[$idlay][$idcontainer]["default"] = $parser->getNodeAttributes('default');
357:             $containerinf[$idlay][$idcontainer]["types"] = $parser->getNodeAttributes('types');
358:             $containerinf[$idlay][$idcontainer]["is_body"] = $bIsBody;
359:         }
360:     }
361: }
362: 
363: /**
364:  * Duplicate a template
365:  *
366:  * @param int $idtpl
367:  *         ID of the template to duplicate
368:  *
369:  * @return int
370:  *         ID of the duplicated template
371:  * @throws cDbException
372:  * @throws cException
373:  * @throws cInvalidArgumentException
374:  */
375: function tplDuplicateTemplate($idtpl) {
376:     global $db, $client, $lang, $cfg, $sess, $auth;
377: 
378:     $idtpl = cSecurity::toInteger($idtpl);
379:     $template = new cApiTemplate($idtpl);
380: 
381:     $newidtplcfg = 0;
382:     $idtplcfg = cSecurity::toInteger($template->get('idtplcfg'));
383:     if ($idtplcfg) {
384:         // NB: after inserted new template, we have to update idptl
385:         $templateConfigColl = new cApiTemplateConfigurationCollection();
386:         $templateConfig = $templateConfigColl->create(0);
387:         $newidtplcfg = cSecurity::toInteger($templateConfig->get('idtplcfg'));
388:     }
389: 
390:     // Copy template
391:     $templateColl = new cApiTemplateCollection();
392:     $newTemplate = $templateColl->copyItem($template, array(
393:         'idtplcfg' => $newidtplcfg,
394:         'name' => sprintf(i18n("%s (Copy)"), $template->get('name')),
395:         'author' => cSecurity::toString($auth->auth['uname']),
396:         'created' => date('Y-m-d H:i:s'),
397:         'lastmodified' => date('Y-m-d H:i:s'),
398:         'defaulttemplate' => 0
399:     ));
400:     $newidtpl = cSecurity::toInteger($newTemplate->get('idtpl'));
401: 
402:     // Update template configuration, set idtpl width new value
403:     if ($idtplcfg) {
404:         $templateConfig->set('idtpl', $newidtpl);
405:         $templateConfig->store();
406:     }
407: 
408:     // Copy container from old template to new template
409:     $containerColl = new cApiContainerCollection();
410:     $containerColl->select('idtpl = ' . $idtpl . ' ORDER BY number');
411:     while (($container = $containerColl->next()) !== false) {
412:         $containerColl2 = new cApiContainerCollection();
413:         $containerColl2->copyItem($container, array('idtpl' => $newidtpl));
414:     }
415: 
416:     // Copy container configuration from old template configuration to new template configuration
417:     if ($idtplcfg) {
418:         $containerConfigColl = new cApiContainerConfigurationCollection();
419:         $containerConfigColl->select('idtplcfg = ' . $idtplcfg . ' ORDER BY number');
420:         while (($containerConfig = $containerConfigColl->next()) !== false) {
421:             $containerConfigColl2 = new cApiContainerConfigurationCollection();
422:             $containerConfigColl2->copyItem($containerConfig, array('idtplcfg' => $newidtplcfg));
423:         }
424:     }
425: 
426:     cRights::copyRightsForElement('tpl', $idtpl, $newidtpl);
427: 
428:     return $newidtpl;
429: }
430: 
431: /**
432:  * Checks if a template is in use
433:  *
434:  * @param int $idtpl
435:  *         Template ID
436:  *
437:  * @return bool
438:  *         is template in use
439:  * 
440:  * @throws cDbException
441:  */
442: function tplIsTemplateInUse($idtpl) {
443:     global $cfg, $client, $lang;
444: 
445:     $db = cRegistry::getDb();
446:     // Check categorys
447:     $sql = "SELECT
448:                    b.idcatlang, b.name, b.idlang, b.idcat
449:             FROM
450:                 " . $cfg["tab"]["cat"] . " AS a,
451:                 " . $cfg["tab"]["cat_lang"] . " AS b
452:             WHERE
453:                 a.idclient  = '" . cSecurity::toInteger($client) . "' AND
454:                 a.idcat     = b.idcat AND
455:                 b.idtplcfg  IN (SELECT idtplcfg FROM " . $cfg["tab"]["tpl_conf"] . " WHERE idtpl = '" . $idtpl . "')
456:             ORDER BY b.idlang ASC, b.name ASC ";
457:     $db->query($sql);
458:     if ($db->numRows() > 0) {
459:         return true;
460:     }
461: 
462:     // Check articles
463:     $sql = "SELECT
464:                    b.idartlang, b.title, b.idlang, b.idart
465:             FROM
466:                 " . $cfg["tab"]["art"] . " AS a,
467:                 " . $cfg["tab"]["art_lang"] . " AS b
468:             WHERE
469:                 a.idclient  = '" . cSecurity::toInteger($client) . "' AND
470:                 a.idart     = b.idart AND
471:                 b.idtplcfg IN (SELECT idtplcfg FROM " . $cfg["tab"]["tpl_conf"] . " WHERE idtpl = '" . $idtpl . "')
472:             ORDER BY b.idlang ASC, b.title ASC ";
473: 
474:     $db->query($sql);
475: 
476:     if ($db->numRows() > 0) {
477:         return true;
478:     }
479: 
480:     return false;
481: }
482: 
483: /**
484:  * Get used datas if a template is in use
485:  *
486:  * @param int $idtpl
487:  *         Template ID
488:  *
489:  * @return array
490:  *         category name, article name
491:  * 
492:  * @throws cDbException
493:  */
494: function tplGetInUsedData($idtpl) {
495:     global $cfg, $client, $lang;
496: 
497:     $db = cRegistry::getDb();
498: 
499:     $aUsedData = array();
500: 
501:     // Check categorys
502:     $sql = "SELECT
503:                    b.idcatlang, b.name, b.idlang, b.idcat
504:             FROM
505:                 " . $cfg["tab"]["cat"] . " AS a,
506:                 " . $cfg["tab"]["cat_lang"] . " AS b
507:             WHERE
508:                 a.idclient  = '" . cSecurity::toInteger($client) . "' AND
509:                 a.idcat     = b.idcat AND
510:                 b.idtplcfg  IN (SELECT idtplcfg FROM " . $cfg["tab"]["tpl_conf"] . " WHERE idtpl = '" . $idtpl . "')
511:             ORDER BY b.idlang ASC, b.name ASC ";
512:     $db->query($sql);
513:     if ($db->numRows() > 0) {
514:         while ($db->nextRecord()) {
515:             $aUsedData['cat'][] = array(
516:                 'name' => $db->f('name'),
517:                 'lang' => $db->f('idlang'),
518:                 'idcat' => $db->f('idcat'),
519:             );
520:         }
521:     }
522: 
523:     // Check articles
524:     $sql = "SELECT
525:                    b.idartlang, b.title, b.idlang, b.idart
526:             FROM
527:                 " . $cfg["tab"]["art"] . " AS a,
528:                 " . $cfg["tab"]["art_lang"] . " AS b
529:             WHERE
530:                 a.idclient  = '" . cSecurity::toInteger($client) . "' AND
531:                 a.idart     = b.idart AND
532:                 b.idtplcfg IN (SELECT idtplcfg FROM " . $cfg["tab"]["tpl_conf"] . " WHERE idtpl = '" . $idtpl . "')
533:             ORDER BY b.idlang ASC, b.title ASC ";
534: 
535:     $db->query($sql);
536: 
537:     if ($db->numRows() > 0) {
538:         while ($db->nextRecord()) {
539:             $aUsedData['art'][] = array(
540:                 'title' => $db->f('title'),
541:                 'lang' => $db->f('idlang'),
542:                 'idart' => $db->f('idart'),
543:             );
544:         }
545:     }
546: 
547:     return $aUsedData;
548: }
549: 
550: /**
551:  * Copies a complete template configuration
552:  *
553:  * @param int $idtplcfg
554:  *         Template Configuration ID
555:  *
556:  * @return int
557:  *         new template configuration ID
558:  * 
559:  * @throws cDbException
560:  * @throws cException
561:  * @throws cInvalidArgumentException
562:  */
563: function tplcfgDuplicate($idtplcfg) {
564:     global $auth;
565: 
566:     $templateConfig = new cApiTemplateConfiguration(cSecurity::toInteger($idtplcfg));
567:     if (!$templateConfig->isLoaded()) {
568:         return 0;
569:     }
570: 
571:     // Copy template configuration
572:     $templateConfigColl = new cApiTemplateConfigurationCollection();
573:     $newTemplateConfig = $templateConfigColl->copyItem($templateConfig, array(
574:         'author' => (string) $auth->auth['uname'],
575:         'created' => date('Y-m-d H:i:s'),
576:         'lastmodified' => date('Y-m-d H:i:s'),
577:     ));
578:     $newidtplcfg = $newTemplateConfig->get('idtplcfg');
579: 
580:     // Copy container configuration from old template configuration to new template configuration
581:     if ($idtplcfg) {
582:         $containerConfigColl = new cApiContainerConfigurationCollection();
583:         $containerConfigColl->select('idtplcfg = ' . $idtplcfg . ' ORDER BY number');
584:         while (($containerConfig = $containerConfigColl->next()) !== false) {
585:             $containerConfigColl2 = new cApiContainerConfigurationCollection();
586:             $containerConfigColl2->copyItem($containerConfig, array('idtplcfg' => $newidtplcfg));
587:         }
588:     }
589: 
590:     return $newidtplcfg;
591: }
592: 
593: /**
594:  * This function fills in modules automatically using this logic:
595:  *
596:  * - If the container mode is fixed, insert the named module (if exists)
597:  * - If the container mode is mandatory, insert the "default" module (if exists)
598:  *
599:  * @todo Default module is only inserted in mandatory mode if container is empty. We need a better logic for handling "changes".
600:  *
601:  * @param int $idtpl
602:  *
603:  * @return bool
604:  * 
605:  * @throws cDbException
606:  * @throws cInvalidArgumentException
607:  */
608: function tplAutoFillModules($idtpl) {
609:     global $cfg, $db_autofill, $containerinf, $_autoFillcontainerCache;
610: 
611:     if (!is_object($db_autofill)) {
612:         $db_autofill = cRegistry::getDb();
613:     }
614: 
615:     $sql = "SELECT idlay FROM " . $cfg["tab"]["tpl"] . " WHERE idtpl = '" . cSecurity::toInteger($idtpl) . "'";
616:     $db_autofill->query($sql);
617: 
618:     if (!$db_autofill->nextRecord()) {
619:         return false;
620:     }
621: 
622:     $idlay = $db_autofill->f("idlay");
623: 
624:     if (!(is_array($containerinf) && array_key_exists($idlay, $containerinf) && array_key_exists($idlay, $_autoFillcontainerCache))) {
625:         $_autoFillcontainerCache[$idlay] = tplGetContainerNumbersInLayout($idlay);
626:     }
627: 
628:     $containerNumbers = $_autoFillcontainerCache[$idlay];
629: 
630:     $db = cRegistry::getDb();
631: 
632:     foreach ($containerNumbers as $containerNr) {
633:         $currContainerInfo = $containerinf[$idlay][$containerNr];
634: 
635:         switch ($currContainerInfo["mode"]) {
636:             /* Fixed mode */
637:             case "fixed":
638:                 if ($currContainerInfo["default"] != "") {
639:                     $sql = "SELECT idmod FROM " . $cfg["tab"]["mod"] . " WHERE name = '" . $db->escape($currContainerInfo["default"]) . "'";
640:                     $db_autofill->query($sql);
641: 
642:                     if ($db_autofill->nextRecord()) {
643:                         $idmod = $db_autofill->f("idmod");
644: 
645:                         $sql = "SELECT idcontainer FROM " . $cfg["tab"]["container"] . " WHERE idtpl = '" . cSecurity::toInteger($idtpl) . "' AND number = '" . cSecurity::toInteger($containerNr) . "'";
646:                         $db_autofill->query($sql);
647: 
648:                         if ($db_autofill->nextRecord()) {
649:                             $sql = "UPDATE " . $cfg["tab"]["container"] .
650:                                     " SET idmod = '" . cSecurity::toInteger($idmod) . "' WHERE idtpl = '" . cSecurity::toInteger($idtpl) . "'" .
651:                                     " AND number = '" . cSecurity::toInteger($containerNr) . "' AND " .
652:                                     " idcontainer = '" . cSecurity::toInteger($db_autofill->f("idcontainer")) . "'";
653:                             $db_autofill->query($sql);
654:                         } else {
655:                             $sql = "INSERT INTO " . $cfg["tab"]["container"] . " (idtpl, number, idmod) " .
656:                                     " VALUES ('$idtpl', '$containerNr', '$idmod')";
657:                             $db_autofill->query($sql);
658:                         }
659:                     }
660:                 }
661: 
662:             case "mandatory":
663: 
664:                 if ($currContainerInfo["default"] != "") {
665:                     $sql = "SELECT idmod FROM " . $cfg["tab"]["mod"] . " WHERE name = '" . $db->escape($currContainerInfo["default"]) . "'";
666:                     $db_autofill->query($sql);
667: 
668:                     if ($db_autofill->nextRecord()) {
669:                         $idmod = $db_autofill->f("idmod");
670: 
671:                         $sql = "SELECT idcontainer FROM " . $cfg["tab"]["container"] . " WHERE idtpl = '" . cSecurity::toInteger($idtpl) . "' AND number = '" . cSecurity::toInteger($containerNr) . "'";
672:                         $db_autofill->query($sql);
673: 
674:                         if ($db_autofill->nextRecord()) {
675:                             // donut
676:                         } else {
677:                             $sql = "INSERT INTO " . $cfg["tab"]["container"] . " (idtpl, number, idmod) " .
678:                                     " VALUES ('" . cSecurity::toInteger($idtpl) . "', '" . cSecurity::toInteger($containerNr) . "', '" . cSecurity::toInteger($idmod) . "')";
679:                             $db_autofill->query($sql);
680:                         }
681:                     }
682:                 }
683:         }
684:     }
685: }
686: 
687: /**
688:  * Takes over send container configuration data, stores send data (via POST) by article
689:  * or template configuration in container configuration table.
690:  *
691:  * @param int   $idtpl
692:  * @param int   $idtplcfg
693:  * @param array $postData
694:  *         Usually $_POST
695:  *
696:  * @throws cDbException
697:  * @throws cException
698:  * @throws cInvalidArgumentException
699:  */
700: function tplProcessSendContainerConfiguration($idtpl, $idtplcfg, array $postData) {
701: 
702:     $containerColl = new cApiContainerCollection();
703:     $containerConfColl = new cApiContainerConfigurationCollection();
704:     $containerData = array();
705: 
706:     // Get all container numbers, loop through them and collect send container data
707:     $containerNumbers = $containerColl->getNumbersByTemplate($idtpl);
708:     foreach ($containerNumbers as $number) {
709:         $CiCMS_VAR = 'C' . $number . 'CMS_VAR';
710: 
711:         if (!isset($containerData[$number])) {
712:             $containerData[$number] = '';
713:         }
714:         if (isset($postData[$CiCMS_VAR]) && is_array($postData[$CiCMS_VAR])) {
715:             foreach ($postData[$CiCMS_VAR] as $key => $value) {
716:                 $containerData[$number] = cApiContainerConfiguration::addContainerValue($containerData[$number], $key, $value);
717:             }
718:         }
719:     }
720: 
721:     // Update/insert in container_conf
722:     if (count($containerData) > 0) {
723:         // Delete all containers
724:         $containerConfColl->deleteBy('idtplcfg', (int) $idtplcfg);
725: 
726:         // Insert new containers
727:         foreach ($containerData as $col => $val) {
728:             $containerConfColl->create($idtplcfg, $col, $val);
729:         }
730:     }
731: 
732: }
733: 
CMS CONTENIDO 4.10.1 API documentation generated by ApiGen 2.8.0