Overview

Packages

  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Datatype
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
  • 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
  • cTinyMCEEditor
  • cWYSIWYGEditor
  • FrontendList
  • HtmlParser
  • TreeItem
  • UploadSearchResultList

Functions

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