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
    • NavigationMain
    • 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
  • generateInfoButton
  • generateJs
  • getAktuellType
  • getAllClientsAndLanguages
  • getArtLang
  • getArtspec
  • getAvailableContentTypes
  • getCanonicalDay
  • getCanonicalMonth
  • getDirectorySize
  • getEffectiveSetting
  • getEffectiveSettingsByType
  • getEncodingByLanguage
  • getFileContents
  • getFileInformation
  • getFileType
  • getGroupOrUserName
  • getIDForArea
  • getLanguageNamesByClient
  • getLanguagesByClient
  • getmicrotime
  • getNamedFrame
  • getParam
  • getParentAreaId
  • getSearchResults
  • getStrExpandCollapseButton
  • getSystemProperties
  • getSystemPropertiesByType
  • getSystemProperty
  • getTemplateSelect
  • getUplExpandCollapseButton
  • htmldecode
  • htmlentities_iso88592
  • humanReadableSize
  • includePlugins
  • insertEmptyStrRow
  • ipMatch
  • isAlphanumeric
  • isArchive
  • isArtInMultipleUse
  • 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
  • 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 structure/category functions.
   4:  *
   5:  * @package Core
   6:  * @subpackage Backend
   7:  * @version SVN Revision $Rev:$
   8:  *
   9:  * @author Olaf Niemann
  10:  * @author Murat Purc <murat@purc.de>
  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: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
  17: 
  18: cInclude('includes', 'functions.con.php');
  19: cInclude('includes', 'functions.database.php');
  20: 
  21: /**
  22:  * Creates a new category tree (root category item).
  23:  *
  24:  * @param string $catname The category name
  25:  * @param string $catalias Alias of category
  26:  * @param int $visible Flag about visible status
  27:  * @param int $public Flag about public status
  28:  * @param int $iIdtplcfg Id of template configuration
  29:  * @return (int null) of new generated category or nothing on failure
  30:  */
  31: function strNewTree($catname, $catalias = '', $visible = 0, $public = 1, $iIdtplcfg = 0) {
  32:     global $client, $lang, $perm;
  33: 
  34:     // Flag to rebuild the category table
  35:     global $remakeCatTable, $remakeStrTable;
  36: 
  37:     if (trim($catname) == '') {
  38:         return;
  39:     }
  40: 
  41:     $catname = stripslashes($catname);
  42: 
  43:     $remakeCatTable = true;
  44:     $remakeStrTable = true;
  45: 
  46:     $catalias = trim($catalias);
  47:     if ($catalias == '') {
  48:         $catalias = trim($catname);
  49:     }
  50: 
  51:     $client = (int) $client;
  52:     $lang = (int) $lang;
  53: 
  54:     $visible = ($visible == 1)? 1 : 0;
  55:     if (!$perm->have_perm_area_action('str', 'str_makevisible')) {
  56:         $visible = 0;
  57:     }
  58: 
  59:     $public = ($public == 1)? 1 : 0;
  60:     if (!$perm->have_perm_area_action('str', 'str_makepublic')) {
  61:         $public = 1;
  62:     }
  63: 
  64:     // Get last category tree
  65:     $oCatColl = new cApiCategoryCollection();
  66:     $oLastCatTree = $oCatColl->fetchLastCategoryTree($client);
  67:     $lastCatTreeId = (is_object($oLastCatTree))? $oLastCatTree->get('idcat') : 0;
  68: 
  69:     // Insert new category tree
  70:     $oCatColl2 = new cApiCategoryCollection();
  71:     $oNewCat = $oCatColl2->create($client, 0, $lastCatTreeId, 0);
  72:     $newIdcat = $oNewCat->get('idcat');
  73: 
  74:     // Update last category tree
  75:     if (is_object($oLastCatTree)) {
  76:         $oLastCatTree->set('postid', $newIdcat);
  77:         $oLastCatTree->store();
  78:     }
  79: 
  80:     cInclude('includes', 'functions.rights.php');
  81: 
  82:     // Loop through languages
  83:     $aLanguages = array(
  84:         $lang
  85:     );
  86:     foreach ($aLanguages as $curLang) {
  87:         $name = $catname;
  88:         $urlname = conHtmlSpecialChars(cApiStrCleanURLCharacters($catalias), ENT_QUOTES);
  89: 
  90:         // Insert new category language entry
  91:         $oCatLangColl = new cApiCategoryLanguageCollection();
  92:         $oCatLangColl->create($newIdcat, $curLang, $name, $urlname, '', 0, $visible, $public, 0, '', 0);
  93: 
  94:         // Set correct rights for element
  95:         createRightsForElement('str', $newIdcat, $curLang);
  96:         createRightsForElement('con', $newIdcat, $curLang);
  97:     }
  98: 
  99:     // Assign template
 100:     strAssignTemplate($newIdcat, $client, $iIdtplcfg);
 101: 
 102:     return $newIdcat;
 103: }
 104: 
 105: /**
 106:  * Creates a new category.
 107:  *
 108:  * @param int $parentid Id of parent category
 109:  * @param string $catname The category name
 110:  * @param bool $remakeTree Flag to rebuild category tree structure
 111:  * @param string $catalias Alias of category
 112:  * @param int $visible Flag about visible status
 113:  * @param int $public Flag about public status
 114:  * @param int $iIdtplcfg Id of template configuration
 115:  * @return (int null) of new generated category or nothing on failure
 116:  */
 117: function strNewCategory($parentid, $catname, $remakeTree = true, $catalias = '', $visible = 0, $public = 1, $iIdtplcfg = 0) {
 118:     global $client, $lang, $perm;
 119: 
 120:     // Flag to rebuild the category table
 121:     global $remakeCatTable, $remakeStrTable;
 122: 
 123:     $parentid = (int) $parentid;
 124: 
 125:     if (trim($catname) == '') {
 126:         return;
 127:     }
 128: 
 129:     $catname = stripslashes($catname);
 130: 
 131:     $remakeCatTable = true;
 132:     $remakeStrTable = true;
 133: 
 134:     $catalias = trim($catalias);
 135:     if ($catalias == '') {
 136:         $catalias = trim($catname);
 137:     }
 138: 
 139:     $client = (int) $client;
 140:     $lang = (int) $lang;
 141: 
 142:     $visible = ($visible == 1)? 1 : 0;
 143:     if (!$perm->have_perm_area_action('str', 'str_makevisible')) {
 144:         $visible = 0;
 145:     }
 146: 
 147:     $public = ($public == 1)? 1 : 0;
 148:     if (!$perm->have_perm_area_action('str', 'str_makepublic')) {
 149:         $public = 1;
 150:     }
 151: 
 152:     // Get previous category on same level, if exists
 153:     $oCatColl = new cApiCategoryCollection();
 154:     $oCatColl->select('parentid=' . $parentid . ' AND postid = 0 AND idclient = ' . $client);
 155:     $oPrevCat = $oCatColl->next();
 156:     $preIdcat = (is_object($oPrevCat))? $oPrevCat->get('idcat') : 0;
 157: 
 158:     // Insert new category tree
 159:     $oCatColl2 = new cApiCategoryCollection();
 160:     $oNewCat = $oCatColl2->create($client, $parentid, $preIdcat, 0);
 161:     $newIdcat = $oNewCat->get('idcat');
 162: 
 163:     // Update previous category, if exists
 164:     if (is_object($oPrevCat)) {
 165:         $oPrevCat->set('postid', $newIdcat);
 166:         $oPrevCat->set('lastmodified', date('Y-m-d H:i:s'));
 167:         $oPrevCat->store();
 168:     }
 169: 
 170:     cInclude('includes', 'functions.rights.php');
 171: 
 172:     // Loop through languages
 173:     $aLanguages = array(
 174:         $lang
 175:     );
 176:     foreach ($aLanguages as $curLang) {
 177:         $name = $catname;
 178:         $urlname = conHtmlSpecialChars(cApiStrCleanURLCharacters($catalias), ENT_QUOTES);
 179: 
 180:         // Insert new category language entry
 181:         $oCatLangColl = new cApiCategoryLanguageCollection();
 182:         $oCatLangColl->create($newIdcat, $curLang, $name, $urlname, '', 0, $visible, $public, 0, '', 0);
 183: 
 184:         // Set correct rights for element
 185:         copyRightsForElement('str', $parentid, $newIdcat, $curLang);
 186:         copyRightsForElement('con', $parentid, $newIdcat, $curLang);
 187:     }
 188: 
 189:     if ($remakeTree == true) {
 190:         strRemakeTreeTable();
 191:     }
 192: 
 193:     // Assign template
 194:     strAssignTemplate($newIdcat, $client, $iIdtplcfg);
 195: 
 196:     return $newIdcat;
 197: }
 198: 
 199: /**
 200:  * Builds ordered post string for a passed category
 201:  *
 202:  * @param int $idcat
 203:  * @param string $poststring
 204:  * @return string
 205:  */
 206: function strOrderedPostTreeList($idcat, $poststring) {
 207:     $oCatColl = new cApiCategoryCollection();
 208:     $oCatColl->select('parentid = 0 AND preid = ' . (int) $idcat . ' AND idcat != 0');
 209:     if (($oCat = $oCatColl->next()) !== false) {
 210:         $postIdcat = $oCat->get('idcat');
 211:         $poststring = $poststring . ',' . $postIdcat;
 212:         $poststring = strOrderedPostTreeList($postIdcat, $poststring);
 213:     }
 214: 
 215:     return $poststring;
 216: }
 217: 
 218: /**
 219:  * Remakes the category tree structure in category tree table.
 220:  *
 221:  * It still uses manually build sql statements due to performance reasons.
 222:  */
 223: function strRemakeTreeTable() {
 224:     global $db, $client, $cfg;
 225: 
 226:     // Flag to rebuild the category table
 227:     global $remakeCatTable;
 228:     global $remakeStrTable;
 229: 
 230:     // Get all category ids
 231:     $oCatColl = new cApiCategoryCollection();
 232:     $idcats = $oCatColl->getCategoryIdsByClient($client);
 233:     if (0 === count($idcats)) {
 234:         // There are no categories to build the tree from!
 235:         return;
 236:     }
 237: 
 238:     $remakeCatTable = true;
 239:     $remakeStrTable = true;
 240: 
 241:     // Empty category tree table having specific categories
 242:     $sql = 'DELETE FROM ' . $cfg['tab']['cat_tree'] . ' WHERE idcat IN (' . implode(', ', $idcats) . ')';
 243:     $db->query($sql);
 244: 
 245:     // Delete entries from category table having idcat = 0
 246:     // @todo: Check this, how it is possible to have an invalid entry with
 247:     // primary key = 0
 248:     $sql = 'DELETE FROM ' . $cfg['tab']['cat'] . ' WHERE idcat = 0';
 249:     $db->query($sql);
 250: 
 251:     // Delete entries from category language table having idcat = 0
 252:     // @todo: Check this, how it is possible to have an invalid entry with
 253:     // primary key = 0
 254:     $sql = 'DELETE FROM ' . $cfg['tab']['cat_lang'] . ' WHERE idcat = 0';
 255:     $db->query($sql);
 256: 
 257:     // Get all categories by client
 258:     $sql = "SELECT idcat, parentid, preid, postid FROM " . $cfg['tab']['cat'] . " WHERE idclient = " . (int) $client . " ORDER BY parentid ASC, preid ASC, postid ASC";
 259:     $aCategories = array();
 260:     $db->query($sql);
 261:     while ($db->nextRecord()) {
 262:         $rs = $db->toArray();
 263:         if (!isset($aCategories[$rs['parentid']])) {
 264:             $aCategories[$rs['parentid']] = array();
 265:         }
 266:         $aCategories[$rs['parentid']][$rs['idcat']] = $rs;
 267:     }
 268: 
 269:     // Build INSERT statement
 270:     $sInsertQuery = "INSERT INTO " . $cfg['tab']['cat_tree'] . " (idcat, level) VALUES ";
 271:     $sInsertQuery = strBuildSqlValues($aCategories[0], $sInsertQuery, $aCategories);
 272:     $sInsertQuery = rtrim($sInsertQuery, " ,");
 273: 
 274:     // Lock db table and execute INSERT query
 275:     $db->query($sInsertQuery);
 276: }
 277: 
 278: /**
 279:  * Sorts passed assoziative categories array.
 280:  *
 281:  * @todo Check logic, move sorting to db layer, if possible!
 282:  * @param array $arr
 283:  * @return array
 284:  */
 285: function strSortPrePost($arr) {
 286:     $firstElement = null;
 287:     foreach ($arr as $row) {
 288:         if ($row['preid'] == 0) {
 289:             $firstElement = $row['idcat'];
 290:         }
 291:     }
 292: 
 293:     $curId = $firstElement;
 294:     $array = array();
 295: 
 296:     // Test for inifinite loops in the category list (1=>2; 2=>1 || 1=>1)
 297:     $checkedIds = array();
 298:     foreach ($arr as $row) {
 299:         if (in_array($row['postid'], $checkedIds) || $row['idcat'] == $row['postid']) {
 300:             // die(i18n("The list of categories is messed up. The order in the
 301:             // list creates an infinite loop. Check you database."));
 302:             continue;
 303:         }
 304:         $checkedIds[] = $row['idcat'];
 305:     }
 306: 
 307:     // Test for a last element in the category list
 308:     $fine = false;
 309:     foreach ($arr as $row) {
 310:         if ($row['postid'] == 0) {
 311:             $fine = true;
 312:             break;
 313:         }
 314:     }
 315:     if (!$fine) {
 316:         die(i18n("The list of categories is messed up. The order in the list creates an infinite loop. Check you database."));
 317:     }
 318: 
 319:     while ($curId != 0) {
 320:         $array[] = $arr[$curId];
 321:         $curId = $arr[$curId]['postid'];
 322:     }
 323: 
 324:     return $array;
 325: }
 326: 
 327: /**
 328:  * Builds values part of the SQL used to recreate the category tree table
 329:  *
 330:  * @param array|?? $aCats Assoziative categories array or something else, but
 331:  *            what?
 332:  * @param string $sInsertQuery The insert statement
 333:  * @param array $aAllCats Assoziative categories array holding the complete
 334:  *            category structure
 335:  * @param int $iLevel Category level
 336:  * @return string
 337:  */
 338: function strBuildSqlValues($aCats, $sInsertQuery, &$aAllCats, $iLevel = 0) {
 339:     if (is_array($aCats)) {
 340:         $aCats = strSortPrePost($aCats);
 341:         foreach ($aCats as $aCat) {
 342:             $sInsertQuery .= '(' . (int) $aCat['idcat'] . ', ' . (int) $iLevel . '), ';
 343:             if (is_array($aAllCats[$aCat['idcat']])) {
 344:                 $iSubLevel = $iLevel + 1;
 345:                 $sInsertQuery = strBuildSqlValues($aAllCats[$aCat['idcat']], $sInsertQuery, $aAllCats, $iSubLevel);
 346:             }
 347:         }
 348:     }
 349:     return $sInsertQuery;
 350: }
 351: 
 352: /**
 353:  * Returns id of next deeper category.
 354:  *
 355:  * @global int $lang
 356:  * @param int $idcat Category id to check next deeper item
 357:  * @param bool $ignoreLang Flag to check for existing entry in category language
 358:  *            table
 359:  * @return int
 360:  */
 361: function strNextDeeper($idcat, $ignoreLang = false) {
 362:     global $lang;
 363: 
 364:     $languageId = (true == $ignoreLang)? $lang : null;
 365:     $oCatColl = new cApiCategoryCollection();
 366:     return $oCatColl->getFirstChildCategoryId($idcat, $languageId);
 367: }
 368: 
 369: /**
 370:  * Checks, if passed category contains any articles
 371:  *
 372:  * @param int $idcat ID of category
 373:  * @return bool
 374:  */
 375: function strHasArticles($idcat) {
 376:     global $lang;
 377: 
 378:     $oCatArtColl = new cApiCategoryArticleCollection();
 379:     return $oCatArtColl->getHasArticles($idcat, $lang);
 380: }
 381: 
 382: /**
 383:  * Returns next post category id
 384:  *
 385:  * @param int $idcat ID of category
 386:  * @return int
 387:  */
 388: function strNextPost($idcat) {
 389:     $oCatColl = new cApiCategoryCollection();
 390:     return $oCatColl->getNextPostCategoryId($idcat);
 391: }
 392: 
 393: /**
 394:  * Returns next backwards category id
 395:  *
 396:  * @param int $idcat ID of category
 397:  * @return int
 398:  */
 399: function strNextBackwards($idcat) {
 400:     $oCatColl = new cApiCategoryCollection();
 401:     return $oCatColl->getParentsNextPostCategoryId($idcat);
 402: }
 403: 
 404: /**
 405:  * Returns list of child categories.
 406:  *
 407:  * @global int $lang
 408:  * @param int $idcat
 409:  * @param bool $ignoreLang
 410:  * @return array
 411:  */
 412: function strNextDeeperAll($idcat, $ignoreLang = false) {
 413:     global $lang;
 414: 
 415:     $languageId = (true == $ignoreLang)? $lang : null;
 416:     $oCatColl = new cApiCategoryCollection();
 417:     return $oCatColl->getAllChildCategoryIds($idcat, $languageId);
 418: }
 419: 
 420: /**
 421:  * Renames a category
 422:  *
 423:  * @param int $idcat Category id
 424:  * @param int $lang Language id
 425:  * @param string $newcategoryname New category name
 426:  * @param string $newcategoryalias New category alias
 427:  */
 428: function strRenameCategory($idcat, $lang, $newCategoryName, $newCategoryAlias) {
 429:     if (trim($newCategoryName) == '') {
 430:         return;
 431:     }
 432: 
 433:     $oCatLang = new cApiCategoryLanguage();
 434:     if (!$oCatLang->loadByCategoryIdAndLanguageId($idcat, $lang)) {
 435:         // Couldn't load category language
 436:         return;
 437:     }
 438: 
 439:     $oldData = array(
 440:         'idcat' => $oCatLang->get('idcat'),
 441:         'name' => $oCatLang->get('name'),
 442:         'urlname' => $oCatLang->get('urlname')
 443:     );
 444: 
 445:     $name = stripslashes($newCategoryName);
 446:     $urlName = (trim($newCategoryAlias) != '')? trim($newCategoryAlias) : $newCategoryName;
 447: 
 448:     if (trim($newCategoryAlias) != '') {
 449:         // overfluous assignment
 450:         // if ($oCatLang->get('urlname') != $newCategoryAlias) {
 451:         // $urlName = $newCategoryAlias;
 452:         // }
 453:         cInclude('includes', 'functions.pathresolver.php');
 454:         $client = cRegistry::getClientId();
 455:         prDeleteCacheFileContent($client, $lang);
 456:     }
 457: 
 458:     $oCatLang->set('name', $name);
 459:     $oCatLang->set('urlname', $urlName);
 460:     $oCatLang->set('lastmodified', date('Y-m-d H:i:s'));
 461:     $oCatLang->store();
 462: 
 463:     $newData = array(
 464:         'idcat' => $idcat,
 465:         'name' => $name,
 466:         'urlname' => $urlName
 467:     );
 468: 
 469:     cApiCecHook::execute('Contenido.Category.strRenameCategory', $newData, $oldData);
 470: }
 471: 
 472: /**
 473:  * Renames a category alias.
 474:  *
 475:  * @param int $idcat Category id
 476:  * @param int $lang Language id
 477:  * @param string $newcategoryalias New category alias
 478:  */
 479: function strRenameCategoryAlias($idcat, $lang, $newcategoryalias) {
 480:     $oCatLang = new cApiCategoryLanguage();
 481:     if (!$oCatLang->loadByCategoryIdAndLanguageId($idcat, $lang)) {
 482:         // Couldn't load category language
 483:         return;
 484:     }
 485: 
 486:     $oldData = array(
 487:         'idcat' => $oCatLang->get('idcat'),
 488:         'urlname' => $oCatLang->get('urlname')
 489:     );
 490: 
 491:     if (trim($newcategoryalias) == '') {
 492:         // Use categoryname as default -> get it escape it save it as urlname
 493:         $newcategoryalias = $oCatLang->get('name');
 494:     }
 495: 
 496:     $oCatLang->set('urlname', $newcategoryalias);
 497:     $oCatLang->set('lastmodified', date('Y-m-d H:i:s'));
 498:     $oCatLang->store();
 499: 
 500:     cInclude('includes', 'functions.pathresolver.php');
 501:     $client = cRegistry::getClientId();
 502:     prDeleteCacheFileContent($client, $lang);
 503: 
 504:     $newData = array(
 505:         'idcat' => $idcat,
 506:         'urlname' => $newcategoryalias
 507:     );
 508: 
 509:     cApiCecHook::execute('Contenido.Category.strRenameCategoryAlias', $newData, $oldData);
 510: }
 511: 
 512: /**
 513:  * Sets the visible status of the category and its childs
 514:  *
 515:  * @param int $idcat Category id
 516:  * @param int $lang Language id
 517:  * @param int $visible Visible status
 518:  */
 519: function strMakeVisible($idcat, $lang, $visible) {
 520:     global $cfg;
 521: 
 522:     $visible = (int) $visible;
 523:     $lang = (int) $lang;
 524: 
 525:     $categories = strDeeperCategoriesArray($idcat);
 526:     foreach ($categories as $value) {
 527:         $oCatLang = new cApiCategoryLanguage();
 528:         $oCatLang->loadByCategoryIdAndLanguageId($value, $lang);
 529:         $oCatLang->set('visible', $visible);
 530:         $oCatLang->set('lastmodified', date('Y-m-d H:i:s'));
 531:         $oCatLang->store();
 532:     }
 533: 
 534:     if ($cfg['pathresolve_heapcache'] == true && $visible = 0) {
 535:         $oPathresolveCacheColl = new cApiPathresolveCacheCollection();
 536:         $oPathresolveCacheColl->deleteByCategoryAndLanguage($idcat, $lang);
 537:     }
 538: }
 539: 
 540: /**
 541:  * Sets the public status of the category and its childs
 542:  *
 543:  * @param int $idcat Category id
 544:  * @param int $lang Language id
 545:  * @param int $public Public status
 546:  */
 547: function strMakePublic($idcat, $lang, $public) {
 548:     $categories = strDeeperCategoriesArray($idcat);
 549:     foreach ($categories as $value) {
 550:         $oCatLang = new cApiCategoryLanguage();
 551:         $oCatLang->loadByCategoryIdAndLanguageId($value, $lang);
 552:         $oCatLang->set('public', $public);
 553:         $oCatLang->set('lastmodified', date('Y-m-d H:i:s'));
 554:         $oCatLang->store();
 555:     }
 556: }
 557: 
 558: /**
 559:  * Returns all childs and childchilds of passed category
 560:  *
 561:  * @param int $startIdcat The start category
 562:  * @return array Contains all childs of $startIdcat and $startIdcat start itself
 563:  */
 564: function strDeeperCategoriesArray($startIdcat) {
 565:     global $client;
 566: 
 567:     $oCatColl = new cApiCategoryCollection();
 568:     return $oCatColl->getAllCategoryIdsRecursive($startIdcat, $client);
 569: }
 570: 
 571: /**
 572:  * Deletes the category and its template configurations.
 573:  *
 574:  * Only categories having no child categories and having no articles will be
 575:  * deleted!
 576:  *
 577:  * @param int $idcat Id of category to delete
 578:  */
 579: function strDeleteCategory($idcat) {
 580:     global $lang, $lang;
 581: 
 582:     // Flag to rebuild the category table
 583:     global $remakeCatTable, $remakeStrTable;
 584: 
 585:     if (strNextDeeper($idcat)) {
 586:         // Category has subcategories
 587:         return '0201';
 588:     } elseif (strHasArticles($idcat)) {
 589:         // Category has articles
 590:         return '0202';
 591:     }
 592: 
 593:     cInclude('includes', 'functions.rights.php');
 594: 
 595:     $remakeCatTable = true;
 596:     $remakeStrTable = true;
 597: 
 598:     // Load category language
 599:     $oCatLang = new cApiCategoryLanguage();
 600:     $oCatLang->loadByCategoryIdAndLanguageId($idcat, $lang);
 601: 
 602:     if ($oCatLang->isLoaded()) {
 603:         // Delete template configuration (deletes also all container
 604:         // configurations)
 605:         $oTemplateConfigColl = new cApiTemplateConfigurationCollection();
 606:         $oTemplateConfigColl->delete($oCatLang->get('idtplcfg'));
 607: 
 608:         // Delete category language
 609:         $oCatLangColl = new cApiCategoryLanguageCollection();
 610:         $oCatLangColl->delete($oCatLang->get('idcatlang'));
 611:     }
 612: 
 613:     // Are there any additional entries for other languages?
 614:     $oCatLangColl = new cApiCategoryLanguageCollection();
 615:     $oCatLangColl->select('idcat = ' . (int) $idcat);
 616:     if (($oCatLang = $oCatLangColl->next()) !== false) {
 617:         // More languages found, delete rights for current category
 618:         deleteRightsForElement('str', $idcat, $lang);
 619:         deleteRightsForElement('con', $idcat, $lang);
 620:         return;
 621:     }
 622: 
 623:     // Load category
 624:     $oCat = new cApiCategory((int) $idcat);
 625:     $preid = (int) $oCat->get('preid');
 626:     $postid = (int) $oCat->get('postid');
 627: 
 628:     // Update pre cat, set it to new postid
 629:     if ($preid != 0) {
 630:         $oPreCat = new cApiCategory($preid);
 631:         $oPreCat->set('postid', $postid);
 632:         $oPreCat->store();
 633:     }
 634: 
 635:     // Update post cat, set it to new preid
 636:     if ($postid != 0) {
 637:         $oPostCat = new cApiCategory($postid);
 638:         $oPostCat->set('preid', $preid);
 639:         $oPostCat->store();
 640:     }
 641: 
 642:     // Delete category
 643:     $oCatColl = new cApiCategoryCollection();
 644:     $oCatColl->deleteBy('idcat', (int) $idcat);
 645: 
 646:     $oCatLangColl = new cApiCategoryLanguageCollection();
 647:     $oCatLangColl->select('idcat = ' . (int) $idcat);
 648:     if (($oCatLang = $oCatLangColl->next()) !== false) {
 649:         // Delete template configuration (deletes also all container
 650:         // configurations)
 651:         $oTemplateConfigColl = new cApiTemplateConfigurationCollection();
 652:         $oTemplateConfigColl->delete($oCatLang->get('idtplcfg'));
 653:     }
 654: 
 655:     // Delete category language entry by category id
 656:     $oCatLangColl->resetQuery();
 657:     $oCatLangColl->deleteBy('idcat', (int) $idcat);
 658: 
 659:     // Delete category tree entry by category id
 660:     $oCatTreeColl = new cApiCategoryTreeCollection();
 661:     $oCatTreeColl->deleteBy('idcat', (int) $idcat);
 662: 
 663:     // Delete rights for element
 664:     deleteRightsForElement('str', $idcat);
 665:     deleteRightsForElement('con', $idcat);
 666: }
 667: 
 668: /**
 669:  * Moves a category upwards.
 670:  *
 671:  * @param int $idcat Id of category to upwards
 672:  */
 673: function strMoveUpCategory($idcat) {
 674:     // Flag to rebuild the category table
 675:     global $remakeCatTable, $remakeStrTable;
 676: 
 677:     // Load current category
 678:     $oCat = new cApiCategory();
 679:     $oCat->loadByPrimaryKey((int) $idcat);
 680:     $preid = $oCat->get('preid');
 681:     $postid = $oCat->get('postid');
 682: 
 683:     if (0 == $preid) {
 684:         // No preid, no way to move up
 685:         return;
 686:     }
 687: 
 688:     $remakeCatTable = true;
 689:     $remakeStrTable = true;
 690: 
 691:     // Load previous category
 692:     $oPreCat = new cApiCategory();
 693:     $oPreCat->loadByPrimaryKey((int) $preid);
 694:     $prePreid = $oPreCat->get('preid');
 695:     $preIdcat = $oPreCat->get('idcat');
 696: 
 697:     // Load category before previous category
 698:     $oPrePreCat = new cApiCategory();
 699:     if ((int) $prePreid > 0) {
 700:         $oPrePreCat->loadByPrimaryKey((int) $prePreid);
 701:     }
 702: 
 703:     // Load post category
 704:     $oPostCat = new cApiCategory();
 705:     if ((int) $postid > 0) {
 706:         $oPostCat->loadByPrimaryKey((int) $postid);
 707:     }
 708: 
 709:     // Update category before previous, if exists
 710:     if ($oPrePreCat->isLoaded()) {
 711:         $oPrePreCat->set('postid', $idcat);
 712:         $oPrePreCat->store();
 713:     }
 714: 
 715:     // Update previous category
 716:     $oPreCat->set('preid', $idcat);
 717:     $oPreCat->set('postid', $postid);
 718:     $oPreCat->store();
 719: 
 720:     // Update current category
 721:     $oCat->set('preid', $prePreid);
 722:     $oCat->set('postid', $preid);
 723:     $oCat->store();
 724: 
 725:     // Update post category, if exists!
 726:     $oPostCat->set('preid', $preIdcat);
 727:     $oPostCat->store();
 728: }
 729: 
 730: /**
 731:  * Moves a category downwards.
 732:  *
 733:  * @param int $idcat Id of category to move downwards
 734:  */
 735: function strMoveDownCategory($idcat) {
 736:     // Flag to rebuild the category table
 737:     global $remakeCatTable, $remakeStrTable;
 738: 
 739:     // Load current category
 740:     $oCat = new cApiCategory();
 741:     $oCat->loadByPrimaryKey((int) $idcat);
 742:     $preid = $oCat->get('preid');
 743:     $postid = $oCat->get('postid');
 744: 
 745:     if (0 == $postid) {
 746:         // No post, no way to move down
 747:         return;
 748:     }
 749: 
 750:     $remakeCatTable = true;
 751:     $remakeStrTable = true;
 752: 
 753:     // Load previous category
 754:     $oPreCat = new cApiCategory();
 755:     if ((int) $preid > 0) {
 756:         $oPreCat->loadByPrimaryKey((int) $preid);
 757:         $preIdcat = (int) $oPreCat->get('idcat');
 758:     } else {
 759:         $preIdcat = 0;
 760:     }
 761: 
 762:     // Load post category
 763:     $oPostCat = new cApiCategory();
 764:     $oPostCat->loadByPrimaryKey((int) $postid);
 765:     $postIdcat = $oPostCat->get('idcat');
 766:     $postPostid = $oPostCat->get('postid');
 767: 
 768:     if ($preIdcat != 0) {
 769:         // Update previous category, if exists
 770:         $oPreCat->set('postid', (int) $postIdcat);
 771:         $oPreCat->store();
 772:     }
 773: 
 774:     // Update current category
 775:     $oCat->set('preid', $postid);
 776:     $oCat->set('postid', $postPostid);
 777:     $oCat->store();
 778: 
 779:     // Update post category
 780:     $oPostCat->set('preid', $preIdcat);
 781:     $oPostCat->set('postid', $idcat);
 782:     $oPostCat->store();
 783: 
 784:     if ($postPostid != 0) {
 785:         // Update post post category, if exists
 786:         $oPostPostCat = new cApiCategory($postPostid);
 787:         $oPostPostCat->set('preid', $idcat);
 788:         $oPostPostCat->store();
 789:     }
 790: }
 791: 
 792: /**
 793:  * Moves a subtree to another destination.
 794:  *
 795:  * @param int $idcat Id of category
 796:  * @param int $newParentId Id of destination parent category
 797:  * @param int $newPreId Id of new previous category
 798:  * @param int $newPostId Id of new post category
 799:  */
 800: function strMoveSubtree($idcat, $newParentId, $newPreId = null, $newPostId = null) {
 801:     global $movesubtreeidcat;
 802: 
 803:     $idlang = cRegistry::getLanguageId();
 804:     $cat = new cApiCategoryCollection();
 805:     $children = $cat->getAllChildCategoryIds($idcat, $idlang);
 806: 
 807:     foreach ($children as $category) {
 808:         // avoids to move the main tree node in sub node of the same tree
 809:         if ($category == $newParentId) {
 810:             return false;
 811:         }
 812:     }
 813: 
 814:     if ($idcat == $newParentId) {
 815:         return false;
 816:     }
 817: 
 818:     if ($newParentId == 0 && $newPreId == 0) {
 819:         return false;
 820:     }
 821:     if (!isset($newPostId)) {
 822:         return false;
 823:     }
 824:     // flag to rebuild the category table
 825:     global $remakeCatTable, $remakeStrTable;
 826: 
 827:     $remakeCatTable = true;
 828:     $remakeStrTable = true;
 829: 
 830:     // check the post ID parameter
 831:     if (is_null($newPostId)) {
 832:         $newPostId = 0;
 833:     }
 834: 
 835:     if ($newParentId == -1) {
 836:         // stop moving the category without actually moving it
 837:         $movesubtreeidcat = 0;
 838:     } else if (is_null($newParentId)) {
 839:         // start moving the category withour moving it yet
 840:         $movesubtreeidcat = $idcat;
 841:     } else {
 842:         // move the category with the ID idcat to the category newParentId
 843:         $category = new cApiCategory($idcat);
 844:         $oldPreId = $category->get('preid');
 845:         $oldPostId = $category->get('postid');
 846: 
 847:         // update old predecessor (pre) category
 848:         if ($oldPreId != 0) {
 849:             $oldPreCategory = new cApiCategory($oldPreId);
 850:             $oldPreCategory->set('postid', $oldPostId);
 851:             $oldPreCategory->store();
 852:         }
 853: 
 854:         // update old follower (post) category
 855:         if ($oldPostId != 0) {
 856:             $oldPostCategory = new cApiCategory($oldPostId);
 857:             $oldPostCategory->set('preid', $oldPreId);
 858:             $oldPostCategory->store();
 859:         }
 860: 
 861:         // update new predecessor (pre) category
 862:         if (is_null($newPreId)) {
 863:             // if no new pre ID has been given, use the last category in the
 864:             // given parent category
 865:             $categoryCollection = new cApiCategoryCollection();
 866:             $categoryCollection->select("parentid = " . $newParentId . " AND postid = 0");
 867:             $newPreCategory = $categoryCollection->next();
 868:         } else {
 869:             $newPreCategory = new cApiCategory($newPreId);
 870:         }
 871:         if ($newPreCategory) {
 872:             $newPreCategory->set('postid', $idcat);
 873:             $newPreCategory->store();
 874:             $newPreId = $newPreCategory->get('idcat');
 875:         } else {
 876:             $newPreId = 0;
 877:         }
 878: 
 879:         // update new follower (post) category
 880:         if ($newPostId != 0) {
 881:             $newPostCategory = new cApiCategory($newPostId);
 882:             $newPostCategory->set('preid', $idcat);
 883:             $newPostCategory->store();
 884:         }
 885: 
 886:         // Update current category
 887:         $category->set('parentid', $newParentId);
 888:         $category->set('preid', $newPreId);
 889:         $category->set('postid', $newPostId);
 890:         $category->store();
 891: 
 892:         $movesubtreeidcat = 0;
 893:     }
 894: 
 895:     $sess = cRegistry::getSession();
 896:     $sess->register('movesubtreeidcat');
 897:     $sess->freeze();
 898: }
 899: 
 900: /**
 901:  * Checks if category is movable.
 902:  *
 903:  * @param int $idcat Id of category to move
 904:  * @param int $source Id of source category
 905:  * @return bool
 906:  */
 907: function strMoveCatTargetallowed($idcat, $source) {
 908:     return ($idcat == $source)? 0 : 1;
 909: }
 910: 
 911: /**
 912:  * Synchronizes a category from one language to another language.
 913:  *
 914:  * @param int $idcatParam Id of category to synchronize
 915:  * @param int $sourcelang Id of source language
 916:  * @param int $targetlang Id of target language
 917:  * @param bool $bMultiple Flag to synchronize child languages
 918:  */
 919: function strSyncCategory($idcatParam, $sourcelang, $targetlang, $bMultiple = false) {
 920:     $bMultiple = (bool) $bMultiple;
 921: 
 922:     $aCatArray = array();
 923:     if ($bMultiple == true) {
 924:         $aCatArray = strDeeperCategoriesArray($idcatParam);
 925:     } else {
 926:         $aCatArray[] = $idcatParam;
 927:     }
 928: 
 929:     foreach ($aCatArray as $idcat) {
 930:         // Check if category for target language already exists
 931:         $oCatLang = new cApiCategoryLanguage();
 932:         if ($oCatLang->loadByCategoryIdAndLanguageId($idcat, $targetlang)) {
 933:             return false;
 934:         }
 935: 
 936:         // Get source category language
 937:         $oCatLang = new cApiCategoryLanguage();
 938:         if ($oCatLang->loadByCategoryIdAndLanguageId($idcat, $sourcelang)) {
 939:             $aRs = $oCatLang->toArray();
 940: 
 941:             // Copy the template configuration, if exists
 942:             $newidtplcfg = ($aRs['idtplcfg'] != 0)? tplcfgDuplicate($aRs['idtplcfg']) : 0;
 943: 
 944:             $visible = 0;
 945:             $startidartlang = 0;
 946:             $urlpath = '';
 947: 
 948:             $oCatLangColl = new cApiCategoryLanguageCollection();
 949:             $oNewCatLang = $oCatLangColl->create($aRs['idcat'], $targetlang, $aRs['name'], $aRs['urlname'], $urlpath, $newidtplcfg, $visible, $aRs['public'], $aRs['status'], $aRs['author'], $startidartlang, $aRs['created'], $aRs['lastmodified']);
 950: 
 951:             // Execute CEC hook
 952:             $param = $aRs;
 953:             $param['idlang'] = $targetlang;
 954:             $param['idtplcfg'] = (int) $newidtplcfg;
 955:             $param['visible'] = $visible;
 956:             cApiCecHook::execute('Contenido.Category.strSyncCategory_Loop', $param);
 957: 
 958:             // Set correct rights for element
 959:             cInclude('includes', 'functions.rights.php');
 960:             createRightsForElement('str', $idcat, $targetlang);
 961:             createRightsForElement('con', $idcat, $targetlang);
 962:         }
 963:     }
 964: }
 965: 
 966: /**
 967:  * Checks if category has a start article
 968:  *
 969:  * @param int $idcat Id of category
 970:  * @param int $idlang The language id
 971:  * @return bool
 972:  */
 973: function strHasStartArticle($idcat, $idlang) {
 974:     $oCatLangColl = new cApiCategoryLanguageCollection();
 975:     return ($oCatLangColl->getStartIdartlangByIdcatAndIdlang($idcat, $idlang) > 0);
 976: }
 977: 
 978: /**
 979:  * Copies the category and it's existing articles into another category.
 980:  *
 981:  * @param int $idcat Id of category to copy
 982:  * @param int $destidcat Id of destination category
 983:  * @param bool $remakeTree Flag to rebuild category tree
 984:  * @param bool $bUseCopyLabel Flag to add copy label to the new categories
 985:  */
 986: function strCopyCategory($idcat, $destidcat, $remakeTree = true, $bUseCopyLabel = true) {
 987:     global $cfg, $lang;
 988: 
 989:     $newidcat = (int) strNewCategory($destidcat, 'a', $remakeTree);
 990:     if ($newidcat == 0) {
 991:         return;
 992:     }
 993: 
 994:     // Load old and new category
 995:     $oOldCatLang = new cApiCategoryLanguage();
 996:     if (!$oOldCatLang->loadByCategoryIdAndLanguageId($idcat, $lang)) {
 997:         return;
 998:     }
 999: 
1000:     $oNewCatLang = new cApiCategoryLanguage();
1001:     if (!$oNewCatLang->loadByCategoryIdAndLanguageId($newidcat, $lang)) {
1002:         return;
1003:     }
1004: 
1005:     // Worker objects
1006:     $oNewCat = new cApiCategory((int) $newidcat);
1007:     $oOldCat = new cApiCategory((int) $idcat);
1008: 
1009:     // Copy properties
1010:     if ($bUseCopyLabel == true) {
1011:         $oNewCatLang->set('name', sprintf(i18n('%s (Copy)'), $oOldCatLang->get('name')));
1012:     } else {
1013:         $oNewCatLang->set('name', $oOldCatLang->get('name'));
1014:     }
1015: 
1016:     $oNewCatLang->set('public', $oOldCatLang->get('public'));
1017:     $oNewCatLang->set('visible', 0);
1018:     $oNewCatLang->store();
1019: 
1020:     // Execute cec hook
1021:     cApiCecHook::execute('Contenido.Category.strCopyCategory', array(
1022:         'oldcat' => $oOldCat,
1023:         'newcat' => $oNewCat,
1024:         'newcatlang' => $oNewCatLang
1025:     ));
1026: 
1027:     // Copy template configuration
1028:     if ($oOldCatLang->get('idtplcfg') != 0) {
1029:         // Create new template configuration
1030:         $oNewCatLang->assignTemplate($oOldCatLang->getTemplate());
1031: 
1032:         // Copy the container configuration
1033:         $oContainerConfColl = new cApiContainerConfigurationCollection();
1034:         $oContainerConfColl->select('idtplcfg = ' . (int) $oOldCatLang->get('idtplcfg'));
1035: 
1036:         $oNewContainerConfColl = new cApiContainerConfigurationCollection();
1037:         while (($oItem = $oContainerConfColl->next()) !== false) {
1038:             $oNewContainerConfColl->create($oNewCatLang->get('idtplcfg'), $oItem->get('number'), $oItem->get('container'));
1039:         }
1040:     }
1041: 
1042:     $db = cRegistry::getDb();
1043: 
1044:     $oCatArtColl = new cApiCategoryArticleCollection();
1045: 
1046:     // Copy all articles
1047:     $sql = "SELECT A.idart, B.idartlang FROM %s AS A, %s AS B WHERE A.idcat = %d AND B.idart = A.idart AND B.idlang = %s";
1048:     $db->query($sql, $cfg['tab']['cat_art'], $cfg['tab']['art_lang'], $idcat, $lang);
1049: 
1050:     while ($db->nextRecord()) {
1051:         $newidart = (int) conCopyArticle($db->f('idart'), $newidcat, '', $bUseCopyLabel);
1052:         if ($db->f('idartlang') == $oOldCatLang->get('startidartlang')) {
1053:             $oCatArtColl->resetQuery();
1054:             $idcatart = $oCatArtColl->getIdByCategoryIdAndArticleId($newidcat, $newidart);
1055:             if ($idcatart) {
1056:                 conMakeStart($idcatart, 1);
1057:             }
1058:         }
1059:     }
1060: 
1061:     return $newidcat;
1062: }
1063: 
1064: /**
1065:  * Copies the categorytree (category and its childs) to an another category.
1066:  *
1067:  * @param int $idcat Id of category to copy
1068:  * @param int $destcat Id of destination category
1069:  * @param bool $remakeTree Flag to rebuild category tree
1070:  * @param bool $bUseCopyLabel Flag to add copy label to the new categories
1071:  */
1072: function strCopyTree($idcat, $destcat, $remakeTree = true, $bUseCopyLabel = true) {
1073:     $newidcat = strCopyCategory($idcat, $destcat, false, $bUseCopyLabel);
1074: 
1075:     $oCatColl = new cApiCategoryCollection();
1076:     $aIds = $oCatColl->getIdsByWhereClause('parentid = ' . (int) $idcat);
1077:     foreach ($aIds as $id) {
1078:         strCopyTree($id, $newidcat, false, $bUseCopyLabel);
1079:     }
1080: 
1081:     if ($remakeTree == true) {
1082:         strRemakeTreeTable();
1083:     }
1084: }
1085: 
1086: /**
1087:  * Assigns a template to passed category.
1088:  *
1089:  * @param int $idcat
1090:  * @param int $client
1091:  * @param int $idTplCfg
1092:  */
1093: function strAssignTemplate($idcat, $client, $idTplCfg) {
1094:     global $perm;
1095: 
1096:     // Template permission check
1097:     $iIdtplcfg = ($perm->have_perm_area_action('str_tplcfg', 'str_tplcfg'))? (int) $idTplCfg : 0;
1098: 
1099:     $idtpl = null;
1100:     if ($iIdtplcfg == 0) {
1101:         // Get default template
1102:         $oTemplateColl = new cApiTemplateCollection('defaulttemplate = 1 AND idclient = ' . (int) $client);
1103:         if (($oTemplate = $oTemplateColl->next()) !== false) {
1104:             $idtpl = $oTemplate->get('idtpl');
1105:         }
1106:     } else {
1107:         // Use passed template
1108:         $idtpl = $idTplCfg;
1109:     }
1110: 
1111:     if ($idtpl) {
1112:         // Assign template
1113:         $oCatLangColl = new cApiCategoryLanguageCollection('idcat = ' . (int) $idcat);
1114:         while (($oCatLang = $oCatLangColl->next()) !== false) {
1115:             $oCatLang->assignTemplate($idtpl);
1116:         }
1117:     }
1118: }
1119: 
CMS CONTENIDO 4.9.0 API documentation generated by ApiGen 2.8.0