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