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
  • UploadList
  • UploadSearchResultList

Functions

  • _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
  • 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
  • getAktuellType
  • 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
  • tplGetContainerTypes
  • tplGetInUsedData
  • tplIsTemplateInUse
  • tplPreparseLayout
  • updateClientCache
  • updateFileInformation
  • uplCreateFriendlyName
  • uplDirectoryListRecursive
  • uplGetDirectoriesToExclude
  • uplGetFileExtension
  • uplGetFileIcon
  • uplGetFileTypeDescription
  • uplGetThumbnail
  • uplHasFiles
  • uplHasSubdirs
  • uplmkdir
  • uplRecursiveDBDirectoryList
  • uplRecursiveDirectoryList
  • uplRenameDirectory
  • uplSearch
  • uplSyncDirectory
  • uplSyncDirectoryDBFS
  • xmlFileToArray
  • 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($idclient, $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);
 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:     preg_match_all("/CMS_CONTAINER\[([0-9]*)\]/", $code, $a_container);
153:     $iPosBody = stripos($code, '<body>');
154:     $sCodeBeforeHeader = substr($code, 0, $iPosBody);
155: 
156:     foreach ($a_container[1] as $value) {
157:         if (preg_match("/CMS_CONTAINER\[$value\]/", $sCodeBeforeHeader)) {
158:             $containerinf[$idlay][$value]["is_body"] = false;
159:         } else {
160:             $containerinf[$idlay][$value]["is_body"] = true;
161:         }
162:     }
163: 
164:     if (is_array($containerinf[$idlay])) {
165:         foreach ($containerinf[$idlay] as $key => $value) {
166:             $a_container[1][] = $key;
167:         }
168:     }
169: 
170:     $container = Array();
171: 
172:     foreach ($a_container[1] as $value) {
173:         if (!in_array($value, $container)) {
174:             $container[] = $value;
175:         }
176:     }
177: 
178:     asort($container);
179: 
180:     if (is_array($container)) {
181:         $tmp_returnstring = implode("&", $container);
182:     }
183:     return $tmp_returnstring;
184: }
185: 
186: /**
187:  * Retrieve the container name
188:  *
189:  * @param int $idtpl Layout number to browse
190:  * @param int $container Container number
191:  *
192:  * @return string Container name
193:  */
194: function tplGetContainerName($idlay, $container) {
195:     global $db, $cfg, $containerinf;
196: 
197:     if (is_array($containerinf[$idlay])) {
198:         if (array_key_exists($container, $containerinf[$idlay])) {
199:             return $containerinf[$idlay][$container]["name"];
200:         }
201:     }
202: }
203: 
204: /**
205:  * Retrieve the container mode
206:  *
207:  * @param int $idtpl Layout number to browse
208:  * @param int $container Container number
209:  *
210:  * @return string Container name
211:  */
212: function tplGetContainerMode($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]["mode"];
218:         }
219:     }
220: }
221: 
222: /**
223:  * Retrieve the allowed container types
224:  *
225:  * @param int $idtpl Layout number to browse
226:  * @param int $container Container number
227:  *
228:  * @return array Allowed container types
229:  */
230: function tplGetContainerTypes($idlay, $container) {
231:     global $db, $cfg, $containerinf;
232: 
233:     if (is_array($containerinf[$idlay])) {
234:         if (array_key_exists($container, $containerinf[$idlay])) {
235:             if ($containerinf[$idlay][$container]["types"] != "") {
236:                 $list = explode(",", $containerinf[$idlay][$container]["types"]);
237: 
238:                 foreach ($list as $key => $value) {
239:                     $list[$key] = trim($value);
240:                 }
241:                 return $list;
242:             }
243:         }
244:     }
245: }
246: 
247: /**
248:  * Retrieve the default module
249:  *
250:  * @param int $idtpl Layout number to browse
251:  * @param int $container Container number
252:  *
253:  * @return array Allowed container types
254:  */
255: function tplGetContainerDefault($idlay, $container) {
256:     global $db, $cfg, $containerinf;
257: 
258:     if (is_array($containerinf[$idlay])) {
259:         if (array_key_exists($container, $containerinf[$idlay])) {
260:             return $containerinf[$idlay][$container]["default"];
261:         }
262:     }
263: }
264: 
265: /**
266:  * Preparse the layout for caching purposes
267:  *
268:  * @param int $idtpl Layout number to browse
269:  */
270: function tplPreparseLayout($idlay) {
271:     global $db, $cfg, $containerinf, $lang;
272: 
273:     $layoutInFile = new cLayoutHandler($idlay, "", $cfg, $lang);
274:     $code = $layoutInFile->getLayoutCode();
275: 
276:     $parser = new HtmlParser($code);
277:     $bIsBody = false;
278:     while ($parser->parse()) {
279:         if (strtolower($parser->iNodeName) == 'body') {
280:             $bIsBody = true;
281:         }
282: 
283:         if ($parser->iNodeName == "container" && $parser->iNodeType == HtmlParser::NODE_TYPE_ELEMENT) {
284:             $idcontainer = $parser->iNodeAttributes["id"];
285: 
286:             $mode = $parser->iNodeAttributes["mode"];
287: 
288:             if ($mode == "") {
289:                 $mode = "optional";
290:             }
291: 
292:             $containerinf[$idlay][$idcontainer]["name"] = $parser->iNodeAttributes["name"];
293:             $containerinf[$idlay][$idcontainer]["mode"] = $mode;
294:             $containerinf[$idlay][$idcontainer]["default"] = $parser->iNodeAttributes["default"];
295:             $containerinf[$idlay][$idcontainer]["types"] = $parser->iNodeAttributes["types"];
296:             $containerinf[$idlay][$idcontainer]["is_body"] = $bIsBody;
297:         }
298:     }
299: }
300: 
301: /**
302:  * Duplicate a template
303:  *
304:  * @param int $idtpl ID of the template to duplicate
305:  *
306:  * @return  int  ID of the duplicated template
307:  */
308: function tplDuplicateTemplate($idtpl) {
309:     global $db, $client, $lang, $cfg, $sess, $auth;
310: 
311:     $idtpl = (int) $idtpl;
312:     $template = new cApiTemplate($idtpl);
313: 
314:     $newidtplcfg = 0;
315:     $idtplcfg = (int) $template->get('idtplcfg');
316:     if ($idtplcfg) {
317:         // NB: after inserted new template, we have to update idptl
318:         $templateConfigColl = new cApiTemplateConfigurationCollection();
319:         $templateConfig = $templateConfigColl->create(0);
320:         $newidtplcfg = (int) $templateConfig->get('idtplcfg');
321:     }
322: 
323:     // Copy template
324:     $templateColl = new cApiTemplateCollection();
325:     $newTemplate = $templateColl->copyItem($template, array(
326:         'name' => sprintf(i18n("%s (Copy)"), $template->get('name')),
327:         'author' => (string) $auth->auth['uname'],
328:         'created' => date('Y-m-d H:i:s'),
329:         'lastmodified' => date('Y-m-d H:i:s'),
330:     ));
331:     $newidtpl = (int) $newTemplate->get('idtpl');
332: 
333:     // Update template configuration, set idtpl width new value
334:     if ($idtplcfg) {
335:         $templateConfig->set('idtpl', $newidtpl);
336:         $templateConfig->store();
337:     }
338: 
339:     // Copy container from old template to new template
340:     $containerColl = new cApiContainerCollection();
341:     $containerColl->select('idtpl = ' . $idtpl . ' ORDER BY number');
342:     while (($container = $containerColl->next()) !== false) {
343:         $containerColl2 = new cApiContainerCollection();
344:         $containerColl2->copyItem($container, array('idtpl' => $newidtpl));
345:     }
346: 
347:     // Copy container configuration from old template configuration to new template configuration
348:     if ($idtplcfg) {
349:         $containerConfigColl = new cApiContainerConfigurationCollection();
350:         $containerConfigColl->select('idtplcfg = ' . $idtplcfg . ' ORDER BY number');
351:         while (($containerConfig = $containerConfigColl->next()) !== false) {
352:             $containerConfigColl2 = new cApiContainerConfigurationCollection();
353:             $containerConfigColl2->copyItem($containerConfig, array('idtplcfg' => $newidtplcfg));
354:         }
355:     }
356: 
357:     cInclude('includes', 'functions.rights.php');
358:     copyRightsForElement('tpl', $idtpl, $newidtpl);
359: 
360:     return $newidtpl;
361: }
362: 
363: /**
364:  * Checks if a template is in use
365:  *
366:  * @param int $idtpl Template ID
367:  *
368:  * @return bool is template in use
369:  */
370: function tplIsTemplateInUse($idtpl) {
371:     global $cfg, $client, $lang;
372: 
373:     $db = cRegistry::getDb();
374:     // Check categorys
375:     $sql = "SELECT
376:                    b.idcatlang, b.name, b.idlang, b.idcat
377:             FROM
378:                 " . $cfg["tab"]["cat"] . " AS a,
379:                 " . $cfg["tab"]["cat_lang"] . " AS b
380:             WHERE
381:                 a.idclient  = '" . cSecurity::toInteger($client) . "' AND
382:                 a.idcat     = b.idcat AND
383:                 b.idtplcfg  IN (SELECT idtplcfg FROM " . $cfg["tab"]["tpl_conf"] . " WHERE idtpl = '" . $idtpl . "')
384:             ORDER BY b.idlang ASC, b.name ASC ";
385:     $db->query($sql);
386:     if ($db->numRows() > 0) {
387:         return true;
388:     }
389: 
390:     // Check articles
391:     $sql = "SELECT
392:                    b.idartlang, b.title, b.idlang, b.idart
393:             FROM
394:                 " . $cfg["tab"]["art"] . " AS a,
395:                 " . $cfg["tab"]["art_lang"] . " AS b
396:             WHERE
397:                 a.idclient  = '" . cSecurity::toInteger($client) . "' AND
398:                 a.idart     = b.idart AND
399:                 b.idtplcfg IN (SELECT idtplcfg FROM " . $cfg["tab"]["tpl_conf"] . " WHERE idtpl = '" . $idtpl . "')
400:             ORDER BY b.idlang ASC, b.title ASC ";
401: 
402:     $db->query($sql);
403: 
404:     if ($db->numRows() > 0) {
405:         return true;
406:     }
407: 
408:     return false;
409: }
410: 
411: /**
412:  * Get used datas if a template is in use
413:  *
414:  * @param int $idtpl Template ID
415:  *
416:  * @return array - category name, article name
417:  */
418: function tplGetInUsedData($idtpl) {
419:     global $cfg, $client, $lang;
420: 
421:     $db = cRegistry::getDb();
422: 
423:     $aUsedData = array();
424: 
425:     // Check categorys
426:     $sql = "SELECT
427:                    b.idcatlang, b.name, b.idlang, b.idcat
428:             FROM
429:                 " . $cfg["tab"]["cat"] . " AS a,
430:                 " . $cfg["tab"]["cat_lang"] . " AS b
431:             WHERE
432:                 a.idclient  = '" . cSecurity::toInteger($client) . "' AND
433:                 a.idcat     = b.idcat AND
434:                 b.idtplcfg  IN (SELECT idtplcfg FROM " . $cfg["tab"]["tpl_conf"] . " WHERE idtpl = '" . $idtpl . "')
435:             ORDER BY b.idlang ASC, b.name ASC ";
436:     $db->query($sql);
437:     if ($db->numRows() > 0) {
438:         while ($db->nextRecord()) {
439:             $aUsedData['cat'][] = array(
440:                 'name' => $db->f('name'),
441:                 'lang' => $db->f('idlang'),
442:                 'idcat' => $db->f('idcat'),
443:             );
444:         }
445:     }
446: 
447:     // Check articles
448:     $sql = "SELECT
449:                    b.idartlang, b.title, b.idlang, b.idart
450:             FROM
451:                 " . $cfg["tab"]["art"] . " AS a,
452:                 " . $cfg["tab"]["art_lang"] . " AS b
453:             WHERE
454:                 a.idclient  = '" . cSecurity::toInteger($client) . "' AND
455:                 a.idart     = b.idart AND
456:                 b.idtplcfg IN (SELECT idtplcfg FROM " . $cfg["tab"]["tpl_conf"] . " WHERE idtpl = '" . $idtpl . "')
457:             ORDER BY b.idlang ASC, b.title ASC ";
458: 
459:     $db->query($sql);
460: 
461:     if ($db->numRows() > 0) {
462:         while ($db->nextRecord()) {
463:             $aUsedData['art'][] = array(
464:                 'title' => $db->f('title'),
465:                 'lang' => $db->f('idlang'),
466:                 'idart' => $db->f('idart'),
467:             );
468:         }
469:     }
470: 
471:     return $aUsedData;
472: }
473: 
474: /**
475:  * Copies a complete template configuration
476:  *
477:  * @param int $idtplcfg Template Configuration ID
478:  * @return int new template configuration ID
479:  */
480: function tplcfgDuplicate($idtplcfg) {
481:     $templateConfig = new cApiTemplateConfiguration((int) $idtplcfg);
482:     if (!$templateConfig->isLoaded()) {
483:         return 0;
484:     }
485: 
486:     // Copy template configuration
487:     $templateConfigColl = new cApiTemplateConfigurationCollection();
488:     $newTemplateConfig = $templateConfigColl->copyItem($templateConfig, array(
489:         'author' => (string) $auth->auth['uname'],
490:         'created' => date('Y-m-d H:i:s'),
491:         'lastmodified' => date('Y-m-d H:i:s'),
492:     ));
493:     $newidtplcfg = $newTemplateConfig->get('idtplcfg');
494: 
495:     // Copy container configuration from old template configuration to new template configuration
496:     if ($idtplcfg) {
497:         $containerConfigColl = new cApiContainerConfigurationCollection();
498:         $containerConfigColl->select('idtplcfg = ' . $idtplcfg . ' ORDER BY number');
499:         while (($containerConfig = $containerConfigColl->next()) !== false) {
500:             $containerConfigColl2 = new cApiContainerConfigurationCollection();
501:             $containerConfigColl2->copyItem($containerConfig, array('idtplcfg' => $newidtplcfg));
502:         }
503:     }
504: 
505:     return $newidtplcfg;
506: }
507: 
508: /*
509:  * This function fills in modules automatically using this logic:
510:  *
511:  * - If the container mode is fixed, insert the named module (if exists)
512:  * - If the container mode is mandatory, insert the "default" module (if exists)
513:  *
514:  * TODO: The default module is only inserted in mandatory mode if the container
515:  *       is empty. We need a better logic for handling "changes".
516:  */
517: 
518: function tplAutoFillModules($idtpl) {
519:     global $cfg, $db_autofill, $containerinf, $_autoFillcontainerCache;
520: 
521:     if (!is_object($db_autofill)) {
522:         $db_autofill = cRegistry::getDb();
523:     }
524: 
525:     $sql = "SELECT idlay FROM " . $cfg["tab"]["tpl"] . " WHERE idtpl = '" . cSecurity::toInteger($idtpl) . "'";
526:     $db_autofill->query($sql);
527: 
528:     if (!$db_autofill->nextRecord()) {
529:         return false;
530:     }
531: 
532:     $idlay = $db_autofill->f("idlay");
533: 
534:     if (!(is_array($containerinf) && array_key_exists($idlay, $containerinf) && array_key_exists($idlay, $_autoFillcontainerCache))) {
535:         tplPreparseLayout($idlay);
536:         $_autoFillcontainerCache[$idlay] = tplBrowseLayoutForContainers($idlay);
537:     }
538: 
539:     $a_container = explode("&", $_autoFillcontainerCache[$idlay]);
540: 
541:     $db = cRegistry::getDb();
542: 
543:     foreach ($a_container as $container) {
544:         switch ($containerinf[$idlay][$container]["mode"]) {
545:             /* Fixed mode */
546:             case "fixed":
547:                 if ($containerinf[$idlay][$container]["default"] != "") {
548:                     $sql = "SELECT idmod FROM " . $cfg["tab"]["mod"]
549:                             . " WHERE name = '" .
550:                             $db->escape($containerinf[$idlay][$container]["default"]) . "'";
551: 
552:                     $db_autofill->query($sql);
553: 
554:                     if ($db_autofill->nextRecord()) {
555:                         $idmod = $db_autofill->f("idmod");
556: 
557:                         $sql = "SELECT idcontainer FROM " . $cfg["tab"]["container"] . " WHERE idtpl = '" . cSecurity::toInteger($idtpl) . "' AND number = '" . cSecurity::toInteger($container) . "'";
558: 
559:                         $db_autofill->query($sql);
560: 
561:                         if ($db_autofill->nextRecord()) {
562:                             $sql = "UPDATE " . $cfg["tab"]["container"] .
563:                                     " SET idmod = '" . cSecurity::toInteger($idmod) . "' WHERE idtpl = '" . cSecurity::toInteger($idtpl) . "'" .
564:                                     " AND number = '" . cSecurity::toInteger($container) . "' AND " .
565:                                     " idcontainer = '" . cSecurity::toInteger($db_autofill->f("idcontainer")) . "'";
566:                             $db_autofill->query($sql);
567:                         } else {
568:                             $sql = "INSERT INTO " . $cfg["tab"]["container"] .
569:                                     " (idtpl, number, idmod) " .
570:                                     " VALUES ( " .
571:                                     " '$idtpl', '$container', '$idmod')";
572:                             $db_autofill->query($sql);
573:                         }
574:                     }
575:                 }
576: 
577:             case "mandatory":
578: 
579:                 if ($containerinf[$idlay][$container]["default"] != "") {
580:                     $sql = "SELECT idmod FROM " . $cfg["tab"]["mod"] .
581:                             " WHERE name = '" .
582:                             $db->escape($containerinf[$idlay][$container]["default"]) . "'";
583: 
584:                     $db_autofill->query($sql);
585: 
586:                     if ($db_autofill->nextRecord()) {
587:                         $idmod = $db_autofill->f("idmod");
588: 
589:                         $sql = "SELECT idcontainer, idmod FROM " . $cfg["tab"]["container"]
590:                                 . " WHERE idtpl = '" . cSecurity::toInteger($idtpl) . "' AND number = '" . cSecurity::toInteger($container) . "'";
591: 
592:                         $db_autofill->query($sql);
593: 
594:                         if ($db_autofill->nextRecord()) {
595:                             // donut
596:                         } else {
597:                             $sql = "INSERT INTO " . $cfg["tab"]["container"] .
598:                                     " (idtpl, number, idmod) " .
599:                                     " VALUES ( " .
600:                                     " '" . cSecurity::toInteger($idtpl) . "', '" . cSecurity::toInteger($container) . "', '" . cSecurity::toInteger($idmod) . "')";
601:                             $db_autofill->query($sql);
602:                         }
603:                     }
604:                 }
605:         }
606:     }
607: }
608: 
CMS CONTENIDO 4.9.1 API documentation generated by ApiGen 2.8.0