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