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