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 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: 
  17: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
  18: 
  19: cInclude('includes', 'functions.con.php');
  20: cInclude('includes', 'functions.database.php');
  21: 
  22: /**
  23:  * Creates a new category tree (root category item).
  24:  *
  25:  * @param string $catname The category name
  26:  * @param string $catalias Alias of category
  27:  * @param int $visible Flag about visible status
  28:  * @param int $public Flag about public status
  29:  * @param int $iIdtplcfg Id of template configuration
  30:  * @return (int NULL) of new generated category or nothing on failure
  31:  */
  32: function strNewTree($catname, $catalias = '', $visible = 0, $public = 1, $iIdtplcfg = 0) {
  33:     global $client, $lang, $perm;
  34: 
  35:     // Flag to rebuild the category table
  36:     global $remakeCatTable, $remakeStrTable;
  37: 
  38:     if (trim($catname) == '') {
  39:         return;
  40:     }
  41: 
  42:     $catname = stripslashes($catname);
  43: 
  44:     $remakeCatTable = true;
  45:     $remakeStrTable = true;
  46: 
  47:     $catalias = trim($catalias);
  48:     if ($catalias == '') {
  49:         $catalias = trim($catname);
  50:     }
  51: 
  52:     $client = (int) $client;
  53:     $lang = (int) $lang;
  54: 
  55:     $visible = ($visible == 1) ? 1 : 0;
  56:     if (!$perm->have_perm_area_action('str', 'str_makevisible')) {
  57:         $visible = 0;
  58:     }
  59: 
  60:     $public = ($public == 1) ? 1 : 0;
  61:     if (!$perm->have_perm_area_action('str', 'str_makepublic')) {
  62:         $public = 1;
  63:     }
  64: 
  65:     // Get last category tree
  66:     $oCatColl = new cApiCategoryCollection();
  67:     $oLastCatTree = $oCatColl->fetchLastCategoryTree($client);
  68:     $lastCatTreeId = (is_object($oLastCatTree)) ? $oLastCatTree->get('idcat') : 0;
  69: 
  70:     // Insert new category tree
  71:     $oCatColl2 = new cApiCategoryCollection();
  72:     $oNewCat = $oCatColl2->create($client, 0, $lastCatTreeId, 0);
  73:     $newIdcat = $oNewCat->get('idcat');
  74:     $oldPostId = -1;
  75: 
  76:     // Update last category tree
  77:     if (is_object($oLastCatTree)) {
  78:         $oldPostId = $oLastCatTree->get('postid');
  79:         $oLastCatTree->set('postid', $newIdcat);
  80:         $oLastCatTree->store();
  81:     }
  82: 
  83:     $error = strCheckTreeForErrors();
  84:     if (!($error === false)) {
  85:         if ($oldPostId != -1) {
  86:             $oLastCatTree->set('postid', $oldPostId);
  87:             $oLastCatTree->store();
  88:         }
  89:         $oCatColl->delete($oNewCat->get('idcat'));
  90:         return;
  91:     }
  92: 
  93:     cInclude('includes', 'functions.rights.php');
  94: 
  95:     // Loop through languages
  96:     $aLanguages = array(
  97:         $lang
  98:     );
  99:     foreach ($aLanguages as $curLang) {
 100:         $name = $catname;
 101:         $urlname = conHtmlSpecialChars(cApiStrCleanURLCharacters($catalias), ENT_QUOTES);
 102: 
 103:         // Insert new category language entry
 104:         $oCatLangColl = new cApiCategoryLanguageCollection();
 105:         $oCatLangColl->create($newIdcat, $curLang, $name, $urlname, '', 0, $visible, $public, 0, '', 0);
 106: 
 107:         // Set correct rights for element
 108:         createRightsForElement('str', $newIdcat, $curLang);
 109:         createRightsForElement('con', $newIdcat, $curLang);
 110:     }
 111: 
 112:     // Assign template
 113:     strAssignTemplate($newIdcat, $client, $iIdtplcfg);
 114: 
 115:     return $newIdcat;
 116: }
 117: 
 118: /**
 119:  * Creates a new category.
 120:  *
 121:  * @param int $parentid Id of parent category
 122:  * @param string $catname The category name
 123:  * @param bool $remakeTree Flag to rebuild category tree structure
 124:  * @param string $catalias Alias of category
 125:  * @param int $visible Flag about visible status
 126:  * @param int $public Flag about public status
 127:  * @param int $iIdtplcfg Id of template configuration
 128:  * @return (int NULL) of new generated category or nothing on failure
 129:  */
 130: function strNewCategory($parentid, $catname, $remakeTree = true, $catalias = '', $visible = 0, $public = 1, $iIdtplcfg = 0) {
 131:     global $client, $lang, $perm;
 132: 
 133:     // Flag to rebuild the category table
 134:     global $remakeCatTable, $remakeStrTable;
 135: 
 136:     $parentid = (int) $parentid;
 137: 
 138:     if (trim($catname) == '') {
 139:         return;
 140:     }
 141: 
 142:     $catname = stripslashes($catname);
 143: 
 144:     $remakeCatTable = true;
 145:     $remakeStrTable = true;
 146: 
 147:     $catalias = trim($catalias);
 148:     if ($catalias == '') {
 149:         $catalias = trim($catname);
 150:     }
 151: 
 152:     $client = (int) $client;
 153:     $lang = (int) $lang;
 154: 
 155:     $visible = ($visible == 1) ? 1 : 0;
 156:     if (!$perm->have_perm_area_action('str', 'str_makevisible')) {
 157:         $visible = 0;
 158:     }
 159: 
 160:     $public = ($public == 1) ? 1 : 0;
 161:     if (!$perm->have_perm_area_action('str', 'str_makepublic')) {
 162:         $public = 1;
 163:     }
 164: 
 165:     // Get previous category on same level, if exists
 166:     $oCatColl = new cApiCategoryCollection();
 167:     $oCatColl->select('parentid=' . $parentid . ' AND postid = 0 AND idclient = ' . $client);
 168:     $oPrevCat = $oCatColl->next();
 169:     $preIdcat = (is_object($oPrevCat)) ? $oPrevCat->get('idcat') : 0;
 170: 
 171:     // Insert new category tree
 172:     $oCatColl2 = new cApiCategoryCollection();
 173:     $oNewCat = $oCatColl2->create($client, $parentid, $preIdcat, 0);
 174:     $newIdcat = $oNewCat->get('idcat');
 175:     $oldPostId = -1;
 176: 
 177:     // Update previous category, if exists
 178:     if (is_object($oPrevCat)) {
 179:         $oldPostId = $oPrevCat->get('postid');
 180:         $oPrevCat->set('postid', $newIdcat);
 181:         $oPrevCat->set('lastmodified', date('Y-m-d H:i:s'));
 182:         $oPrevCat->store();
 183:     }
 184: 
 185:     $error = strCheckTreeForErrors();
 186:     if (!($error === false)) {
 187:         if ($oldPostId != -1) {
 188:             $oPrevCat->set('postid', $oldPostId);
 189:             $oPrevCat->store();
 190:         }
 191:         $oCatColl2->delete($oNewCat->get('idcat'));
 192:         return;
 193:     }
 194: 
 195:     cInclude('includes', 'functions.rights.php');
 196: 
 197:     // Loop through languages
 198:     $aLanguages = array(
 199:         $lang
 200:     );
 201:     foreach ($aLanguages as $curLang) {
 202:         $name = $catname;
 203:         $urlname = conHtmlSpecialChars(cApiStrCleanURLCharacters($catalias), ENT_QUOTES);
 204: 
 205:         // Insert new category language entry
 206:         $oCatLangColl = new cApiCategoryLanguageCollection();
 207:         $oCatLangColl->create($newIdcat, $curLang, $name, $urlname, '', 0, $visible, $public, 0, '', 0);
 208: 
 209:         // Set correct rights for element
 210:         copyRightsForElement('str', $parentid, $newIdcat, $curLang);
 211:         copyRightsForElement('con', $parentid, $newIdcat, $curLang);
 212:     }
 213: 
 214:     if ($remakeTree == true) {
 215:         strRemakeTreeTable();
 216:     }
 217: 
 218:     // Assign template
 219:     strAssignTemplate($newIdcat, $client, $iIdtplcfg);
 220: 
 221:     return $newIdcat;
 222: }
 223: 
 224: /**
 225:  * Builds ordered post string for a passed category
 226:  *
 227:  * @param int $idcat
 228:  * @param string $poststring
 229:  * @return string
 230:  */
 231: function strOrderedPostTreeList($idcat, $poststring) {
 232:     $oCatColl = new cApiCategoryCollection();
 233:     $oCatColl->select('parentid = 0 AND preid = ' . (int) $idcat . ' AND idcat != 0');
 234:     if (($oCat = $oCatColl->next()) !== false) {
 235:         $postIdcat = $oCat->get('idcat');
 236:         $poststring = $poststring . ',' . $postIdcat;
 237:         $poststring = strOrderedPostTreeList($postIdcat, $poststring);
 238:     }
 239: 
 240:     return $poststring;
 241: }
 242: 
 243: /**
 244:  * Remakes the category tree structure in category tree table.
 245:  *
 246:  * It still uses manually build sql statements due to performance reasons.
 247:  */
 248: function strRemakeTreeTable() {
 249:     global $db, $client, $cfg;
 250: 
 251:     // Flag to rebuild the category table
 252:     global $remakeCatTable;
 253:     global $remakeStrTable;
 254: 
 255:     // Get all category ids
 256:     $oCatColl = new cApiCategoryCollection();
 257:     $idcats = $oCatColl->getCategoryIdsByClient($client);
 258:     if (0 === count($idcats)) {
 259:         // There are no categories to build the tree from!
 260:         return;
 261:     }
 262: 
 263:     $errors = strCheckTreeForErrors();
 264:     if (!($errors === false)) {
 265:         return;
 266:     }
 267: 
 268:     $remakeCatTable = true;
 269:     $remakeStrTable = true;
 270: 
 271:     // Empty category tree table having specific categories
 272:     $sql = 'DELETE FROM ' . $cfg['tab']['cat_tree'] . ' WHERE idcat IN (' . implode(', ', $idcats) . ')';
 273:     $db->query($sql);
 274: 
 275:     // Delete entries from category table having idcat = 0
 276:     // @todo: Check this, how it is possible to have an invalid entry with
 277:     // primary key = 0
 278:     $sql = 'DELETE FROM ' . $cfg['tab']['cat'] . ' WHERE idcat = 0';
 279:     $db->query($sql);
 280: 
 281:     // Delete entries from category language table having idcat = 0
 282:     // @todo: Check this, how it is possible to have an invalid entry with
 283:     // primary key = 0
 284:     $sql = 'DELETE FROM ' . $cfg['tab']['cat_lang'] . ' WHERE idcat = 0';
 285:     $db->query($sql);
 286: 
 287:     // Get all categories by client
 288:     $sql = "SELECT idcat, parentid, preid, postid FROM " . $cfg['tab']['cat'] . " WHERE idclient = " . (int) $client . " ORDER BY parentid ASC, preid ASC, postid ASC";
 289:     $aCategories = array();
 290:     $db->query($sql);
 291:     while ($db->nextRecord()) {
 292:         $rs = $db->toArray();
 293:         if (!isset($aCategories[$rs['parentid']])) {
 294:             $aCategories[$rs['parentid']] = array();
 295:         }
 296:         $aCategories[$rs['parentid']][$rs['idcat']] = $rs;
 297:     }
 298: 
 299:     // Build INSERT statement
 300:     $sInsertQuery = "INSERT INTO " . $cfg['tab']['cat_tree'] . " (idcat, level) VALUES ";
 301:     $sInsertQuery = strBuildSqlValues($aCategories[0], $sInsertQuery, $aCategories);
 302:     $sInsertQuery = rtrim($sInsertQuery, " ,");
 303: 
 304:     // Lock db table and execute INSERT query
 305:     $db->query($sInsertQuery);
 306: }
 307: 
 308: /**
 309:  * Sorts passed assoziative categories array.
 310:  *
 311:  * @todo Check logic, move sorting to db layer, if possible!
 312:  * @param array $arr
 313:  * @return array
 314:  */
 315: function strSortPrePost($arr) {
 316:     $firstElement = NULL;
 317:     foreach ($arr as $row) {
 318:         if ($row['preid'] == 0) {
 319:             $firstElement = $row['idcat'];
 320:         }
 321:     }
 322: 
 323:     $curId = $firstElement;
 324:     $array = array();
 325: 
 326:     // Test for a last element in the category list
 327:     $fine = false;
 328:     foreach ($arr as $row) {
 329:         if ($row['postid'] == 0) {
 330:             $fine = true;
 331:             break;
 332:         }
 333:     }
 334:     if (!$fine) {
 335:         die(); // we already displayed an error message through strCheckTree
 336:     }
 337: 
 338:     while ($curId != 0) {
 339:         $array[] = $arr[$curId];
 340:         $curId = $arr[$curId]['postid'];
 341:     }
 342: 
 343:     return $array;
 344: }
 345: 
 346: /**
 347:  * Builds values part of the SQL used to recreate the category tree table
 348:  *
 349:  * @param array|?? $aCats Assoziative categories array or something else, but
 350:  *            what?
 351:  * @param string $sInsertQuery The insert statement
 352:  * @param array $aAllCats Assoziative categories array holding the complete
 353:  *            category structure
 354:  * @param int $iLevel Category level
 355:  * @return string
 356:  */
 357: function strBuildSqlValues($aCats, $sInsertQuery, &$aAllCats, $iLevel = 0) {
 358:     if (is_array($aCats)) {
 359:         $aCats = strSortPrePost($aCats);
 360:         foreach ($aCats as $aCat) {
 361:             $sInsertQuery .= '(' . (int) $aCat['idcat'] . ', ' . (int) $iLevel . '), ';
 362:             if (is_array($aAllCats[$aCat['idcat']])) {
 363:                 $iSubLevel = $iLevel + 1;
 364:                 $sInsertQuery = strBuildSqlValues($aAllCats[$aCat['idcat']], $sInsertQuery, $aAllCats, $iSubLevel);
 365:             }
 366:         }
 367:     }
 368:     return $sInsertQuery;
 369: }
 370: 
 371: /**
 372:  * Returns id of next deeper category.
 373:  *
 374:  * @global int $lang
 375:  * @param int $idcat Category id to check next deeper item
 376:  * @param bool $ignoreLang Flag to check for existing entry in category language
 377:  *            table
 378:  * @return int
 379:  */
 380: function strNextDeeper($idcat, $ignoreLang = false) {
 381:     global $lang;
 382: 
 383:     $languageId = (true == $ignoreLang) ? $lang : NULL;
 384:     $oCatColl = new cApiCategoryCollection();
 385:     return $oCatColl->getFirstChildCategoryId($idcat, $languageId);
 386: }
 387: 
 388: /**
 389:  * Checks, if passed category contains any articles
 390:  *
 391:  * @param int $idcat ID of category
 392:  * @return bool
 393:  */
 394: function strHasArticles($idcat) {
 395:     global $lang;
 396: 
 397:     $oCatArtColl = new cApiCategoryArticleCollection();
 398:     return $oCatArtColl->getHasArticles($idcat, $lang);
 399: }
 400: 
 401: /**
 402:  * Returns next post category id
 403:  *
 404:  * @param int $idcat ID of category
 405:  * @return int
 406:  */
 407: function strNextPost($idcat) {
 408:     $oCatColl = new cApiCategoryCollection();
 409:     return $oCatColl->getNextPostCategoryId($idcat);
 410: }
 411: 
 412: /**
 413:  * Returns next backwards category id
 414:  *
 415:  * @param int $idcat ID of category
 416:  * @return int
 417:  */
 418: function strNextBackwards($idcat) {
 419:     $oCatColl = new cApiCategoryCollection();
 420:     return $oCatColl->getParentsNextPostCategoryId($idcat);
 421: }
 422: 
 423: /**
 424:  * Returns list of child categories.
 425:  *
 426:  * @global int $lang
 427:  * @param int $idcat
 428:  * @param bool $ignoreLang
 429:  * @return array
 430:  */
 431: function strNextDeeperAll($idcat, $ignoreLang = false) {
 432:     global $lang;
 433: 
 434:     $languageId = (true == $ignoreLang) ? $lang : NULL;
 435:     $oCatColl = new cApiCategoryCollection();
 436:     return $oCatColl->getAllChildCategoryIds($idcat, $languageId);
 437: }
 438: 
 439: /**
 440:  * Renames a category
 441:  *
 442:  * @param int $idcat Category id
 443:  * @param int $lang Language id
 444:  * @param string $newcategoryname New category name
 445:  * @param string $newcategoryalias New category alias
 446:  */
 447: function strRenameCategory($idcat, $lang, $newCategoryName, $newCategoryAlias) {
 448:     if (trim($newCategoryName) == '') {
 449:         return;
 450:     }
 451: 
 452:     $oCatLang = new cApiCategoryLanguage();
 453:     if (!$oCatLang->loadByCategoryIdAndLanguageId($idcat, $lang)) {
 454:         // Couldn't load category language
 455:         return;
 456:     }
 457: 
 458:     $oldData = array(
 459:         'idcat' => $oCatLang->get('idcat'),
 460:         'name' => $oCatLang->get('name'),
 461:         'urlname' => $oCatLang->get('urlname')
 462:     );
 463: 
 464:     $name = stripslashes($newCategoryName);
 465:     $urlName = (trim($newCategoryAlias) != '') ? trim($newCategoryAlias) : $newCategoryName;
 466: 
 467:     if (trim($newCategoryAlias) != '') {
 468:         // overfluous assignment
 469:         // if ($oCatLang->get('urlname') != $newCategoryAlias) {
 470:         // $urlName = $newCategoryAlias;
 471:         // }
 472:         cInclude('includes', 'functions.pathresolver.php');
 473:         $client = cRegistry::getClientId();
 474:         prDeleteCacheFileContent($client, $lang);
 475:     }
 476: 
 477:     $oCatLang->set('name', $name);
 478:     $oCatLang->set('urlname', $urlName);
 479:     $oCatLang->set('lastmodified', date('Y-m-d H:i:s'));
 480:     $oCatLang->store();
 481: 
 482:     $newData = array(
 483:         'idcat' => $idcat,
 484:         'name' => $name,
 485:         'urlname' => $urlName
 486:     );
 487: 
 488:     cApiCecHook::execute('Contenido.Category.strRenameCategory', $newData, $oldData);
 489: }
 490: 
 491: /**
 492:  * Renames a category alias.
 493:  *
 494:  * @param int $idcat Category id
 495:  * @param int $lang Language id
 496:  * @param string $newcategoryalias New category alias
 497:  */
 498: function strRenameCategoryAlias($idcat, $lang, $newcategoryalias) {
 499:     $oCatLang = new cApiCategoryLanguage();
 500:     if (!$oCatLang->loadByCategoryIdAndLanguageId($idcat, $lang)) {
 501:         // Couldn't load category language
 502:         return;
 503:     }
 504: 
 505:     $oldData = array(
 506:         'idcat' => $oCatLang->get('idcat'),
 507:         'urlname' => $oCatLang->get('urlname')
 508:     );
 509: 
 510:     if (trim($newcategoryalias) == '') {
 511:         // Use categoryname as default -> get it escape it save it as urlname
 512:         $newcategoryalias = $oCatLang->get('name');
 513:     }
 514: 
 515:     $oCatLang->set('urlname', $newcategoryalias);
 516:     $oCatLang->set('lastmodified', date('Y-m-d H:i:s'));
 517:     $oCatLang->store();
 518: 
 519:     cInclude('includes', 'functions.pathresolver.php');
 520:     $client = cRegistry::getClientId();
 521:     prDeleteCacheFileContent($client, $lang);
 522: 
 523:     $newData = array(
 524:         'idcat' => $idcat,
 525:         'urlname' => $newcategoryalias
 526:     );
 527: 
 528:     cApiCecHook::execute('Contenido.Category.strRenameCategoryAlias', $newData, $oldData);
 529: }
 530: 
 531: /**
 532:  * Sets the visible status of the category and its childs
 533:  *
 534:  * @param int $idcat Category id
 535:  * @param int $lang Language id
 536:  * @param int $visible Visible status
 537:  */
 538: function strMakeVisible($idcat, $lang, $visible) {
 539:     global $cfg;
 540: 
 541:     $visible = (int) $visible;
 542:     $lang = (int) $lang;
 543: 
 544:     $categories = strDeeperCategoriesArray($idcat);
 545:     foreach ($categories as $value) {
 546:         $oCatLang = new cApiCategoryLanguage();
 547:         $oCatLang->loadByCategoryIdAndLanguageId($value, $lang);
 548:         $oCatLang->set('visible', $visible);
 549:         $oCatLang->set('lastmodified', date('Y-m-d H:i:s'));
 550:         $oCatLang->store();
 551:     }
 552: 
 553:     if ($cfg['pathresolve_heapcache'] == true && $visible = 0) {
 554:         $oPathresolveCacheColl = new cApiPathresolveCacheCollection();
 555:         $oPathresolveCacheColl->deleteByCategoryAndLanguage($idcat, $lang);
 556:     }
 557: }
 558: 
 559: /**
 560:  * Sets the public status of the category and its childs
 561:  *
 562:  * @param int $idcat Category id
 563:  * @param int $lang Language id
 564:  * @param int $public Public status
 565:  */
 566: function strMakePublic($idcat, $lang, $public) {
 567:     $categories = strDeeperCategoriesArray($idcat);
 568:     foreach ($categories as $value) {
 569:         $oCatLang = new cApiCategoryLanguage();
 570:         $oCatLang->loadByCategoryIdAndLanguageId($value, $lang);
 571:         $oCatLang->set('public', $public);
 572:         $oCatLang->set('lastmodified', date('Y-m-d H:i:s'));
 573:         $oCatLang->store();
 574:     }
 575: }
 576: 
 577: /**
 578:  * Returns all childs and childchilds of passed category
 579:  *
 580:  * @param int $startIdcat The start category
 581:  * @return array Contains all childs of $startIdcat and $startIdcat start itself
 582:  */
 583: function strDeeperCategoriesArray($startIdcat) {
 584:     global $client;
 585: 
 586:     $oCatColl = new cApiCategoryCollection();
 587:     return $oCatColl->getAllCategoryIdsRecursive($startIdcat, $client);
 588: }
 589: 
 590: /**
 591:  * Deletes the category and its template configurations.
 592:  *
 593:  * Only categories having no child categories and having no articles will be
 594:  * deleted!
 595:  *
 596:  * @param int $idcat Id of category to delete
 597:  */
 598: function strDeleteCategory($idcat) {
 599:     global $lang, $lang;
 600: 
 601:     // Flag to rebuild the category table
 602:     global $remakeCatTable, $remakeStrTable;
 603: 
 604:     if (strNextDeeper($idcat)) {
 605:         // Category has subcategories
 606:         return '0201';
 607:     } elseif (strHasArticles($idcat)) {
 608:         // Category has articles
 609:         return '0202';
 610:     }
 611: 
 612:     cInclude('includes', 'functions.rights.php');
 613: 
 614:     $remakeCatTable = true;
 615:     $remakeStrTable = true;
 616: 
 617:     // Load category language
 618:     $oCatLang = new cApiCategoryLanguage();
 619:     $oCatLang->loadByCategoryIdAndLanguageId($idcat, $lang);
 620: 
 621:     if ($oCatLang->isLoaded()) {
 622:         // Delete template configuration (deletes also all container
 623:         // configurations)
 624:         $oTemplateConfigColl = new cApiTemplateConfigurationCollection();
 625:         $oTemplateConfigColl->delete($oCatLang->get('idtplcfg'));
 626: 
 627:         // Delete category language
 628:         $oCatLangColl = new cApiCategoryLanguageCollection();
 629:         $oCatLangColl->delete($oCatLang->get('idcatlang'));
 630:     }
 631: 
 632:     // Are there any additional entries for other languages?
 633:     $oCatLangColl = new cApiCategoryLanguageCollection();
 634:     $oCatLangColl->select('idcat = ' . (int) $idcat);
 635:     if (($oCatLang = $oCatLangColl->next()) !== false) {
 636:         // More languages found, delete rights for current category
 637:         deleteRightsForElement('str', $idcat, $lang);
 638:         deleteRightsForElement('con', $idcat, $lang);
 639:         return;
 640:     }
 641: 
 642:     // Load category
 643:     $oCat = new cApiCategory((int) $idcat);
 644:     $preid = (int) $oCat->get('preid');
 645:     $postid = (int) $oCat->get('postid');
 646: 
 647:     // Update pre cat, set it to new postid
 648:     if ($preid != 0) {
 649:         $oPreCat = new cApiCategory($preid);
 650:         $oPreCat->set('postid', $postid);
 651:         $oPreCat->store();
 652:     }
 653: 
 654:     // Update post cat, set it to new preid
 655:     if ($postid != 0) {
 656:         $oPostCat = new cApiCategory($postid);
 657:         $oPostCat->set('preid', $preid);
 658:         $oPostCat->store();
 659:     }
 660: 
 661:     $error = strCheckTreeForErrors(array(), array($idcat));
 662:     if (!($error === false)) {
 663:         if ($preid != 0) {
 664:             $oPreCat = new cApiCategory($preid);
 665:             $oPreCat->set('postid', $idcat);
 666:             $oPreCat->store();
 667:         }
 668:         if ($postid != 0) {
 669:             $oPostCat = new cApiCategory($postid);
 670:             $oPostCat->set('preid', $idcat);
 671:             $oPostCat->store();
 672:         }
 673:         return '0600';
 674:     }
 675: 
 676:     // Delete category
 677:     $oCatColl = new cApiCategoryCollection();
 678:     $oCatColl->deleteBy('idcat', (int) $idcat);
 679: 
 680:     $oCatLangColl = new cApiCategoryLanguageCollection();
 681:     $oCatLangColl->select('idcat = ' . (int) $idcat);
 682:     if (($oCatLang = $oCatLangColl->next()) !== false) {
 683:         // Delete template configuration (deletes also all container
 684:         // configurations)
 685:         $oTemplateConfigColl = new cApiTemplateConfigurationCollection();
 686:         $oTemplateConfigColl->delete($oCatLang->get('idtplcfg'));
 687:     }
 688: 
 689:     // Delete category language entry by category id
 690:     $oCatLangColl->resetQuery();
 691:     $oCatLangColl->deleteBy('idcat', (int) $idcat);
 692: 
 693:     // Delete category tree entry by category id
 694:     $oCatTreeColl = new cApiCategoryTreeCollection();
 695:     $oCatTreeColl->deleteBy('idcat', (int) $idcat);
 696: 
 697:     // Delete rights for element
 698:     deleteRightsForElement('str', $idcat);
 699:     deleteRightsForElement('con', $idcat);
 700: }
 701: 
 702: /**
 703:  * Moves a category upwards.
 704:  *
 705:  * @param int $idcat Id of category to upwards
 706:  */
 707: function strMoveUpCategory($idcat) {
 708:     // Flag to rebuild the category table
 709:     global $remakeCatTable, $remakeStrTable;
 710: 
 711:     // Load current category
 712:     $oCat = new cApiCategory();
 713:     $oCat->loadByPrimaryKey((int) $idcat);
 714:     $preid = $oCat->get('preid');
 715:     $postid = $oCat->get('postid');
 716: 
 717:     if (0 == $preid) {
 718:         // No preid, no way to move up
 719:         return;
 720:     }
 721: 
 722:     $remakeCatTable = true;
 723:     $remakeStrTable = true;
 724: 
 725:     // Load previous category
 726:     $oPreCat = new cApiCategory();
 727:     $oPreCat->loadByPrimaryKey((int) $preid);
 728:     $prePreid = $oPreCat->get('preid');
 729:     $preIdcat = $oPreCat->get('idcat');
 730: 
 731:     // Load category before previous category
 732:     $oPrePreCat = new cApiCategory();
 733:     if ((int) $prePreid > 0) {
 734:         $oPrePreCat->loadByPrimaryKey((int) $prePreid);
 735:     }
 736: 
 737:     // Load post category
 738:     $oPostCat = new cApiCategory();
 739:     if ((int) $postid > 0) {
 740:         $oPostCat->loadByPrimaryKey((int) $postid);
 741:     }
 742: 
 743:     $updateCats = array();
 744: 
 745:     // Update category before previous, if exists
 746:     if ($oPrePreCat->isLoaded()) {
 747:         $oPrePreCat->set('postid', $idcat);
 748:         $updateCats[$prePreid] = $oPrePreCat;
 749:     }
 750: 
 751:     // Update previous category
 752:     $oPreCat->set('preid', $idcat);
 753:     $oPreCat->set('postid', $postid);
 754:     $updateCats[$preid] = $oPreCat;
 755: 
 756:     // Update current category
 757:     $oCat->set('preid', $prePreid);
 758:     $oCat->set('postid', $preid);
 759:     $updateCats[$idcat] = $oCat;
 760: 
 761:     // Update post category, if exists!
 762:     $oPostCat->set('preid', $preIdcat);
 763:     $updateCats[$postid] = $oPostCat;
 764: 
 765:     $error = strCheckTreeForErrors($updateCats);
 766:     if ($error === false) {
 767:         foreach ($updateCats as $cat) {
 768:             $cat->store();
 769:         }
 770:     } else {
 771:         $string = '';
 772:         foreach ($error as $msg) {
 773:             $string .= $msg . '<br>';
 774:         }
 775:         $notification->displayNotification(cGuiNotification::LEVEL_WARNING, $msg . '<br><br>' . i18n('Something went wrong while trying to perform this operation. Please try again.'));
 776:         return;
 777:     }
 778: }
 779: 
 780: /**
 781:  * Moves a category downwards.
 782:  *
 783:  * @param int $idcat Id of category to move downwards
 784:  */
 785: function strMoveDownCategory($idcat) {
 786:     // Flag to rebuild the category table
 787:     global $remakeCatTable, $remakeStrTable;
 788: 
 789:     // Load current category
 790:     $oCat = new cApiCategory();
 791:     $oCat->loadByPrimaryKey((int) $idcat);
 792:     $preid = $oCat->get('preid');
 793:     $postid = $oCat->get('postid');
 794: 
 795:     if (0 == $postid) {
 796:         // No post, no way to move down
 797:         return;
 798:     }
 799: 
 800:     $remakeCatTable = true;
 801:     $remakeStrTable = true;
 802: 
 803:     // Load previous category
 804:     $oPreCat = new cApiCategory();
 805:     if ((int) $preid > 0) {
 806:         $oPreCat->loadByPrimaryKey((int) $preid);
 807:         $preIdcat = (int) $oPreCat->get('idcat');
 808:     } else {
 809:         $preIdcat = 0;
 810:     }
 811: 
 812:     // Load post category
 813:     $oPostCat = new cApiCategory();
 814:     $oPostCat->loadByPrimaryKey((int) $postid);
 815:     $postIdcat = $oPostCat->get('idcat');
 816:     $postPostid = $oPostCat->get('postid');
 817: 
 818:     $updateCats = array();
 819: 
 820:     if ($preIdcat != 0) {
 821:         // Update previous category, if exists
 822:         $oPreCat->set('postid', (int) $postIdcat);
 823:         $updateCats[$preIdcat] = $oPreCat;
 824:     }
 825: 
 826:     // Update current category
 827:     $oCat->set('preid', $postid);
 828:     $oCat->set('postid', $postPostid);
 829:     $updateCats[$idcat] = $oCat;
 830: 
 831:     // Update post category
 832:     $oPostCat->set('preid', $preIdcat);
 833:     $oPostCat->set('postid', $idcat);
 834:     $updateCats[$postid] = $oPostCat;
 835: 
 836:     if ($postPostid != 0) {
 837:         // Update post post category, if exists
 838:         $oPostPostCat = new cApiCategory($postPostid);
 839:         $oPostPostCat->set('preid', $idcat);
 840:         $updateCats[$postPostid] = $oPostPostCat;
 841:     }
 842: 
 843:     $error = strCheckTreeForErrors($updateCats);
 844:     if ($error === false) {
 845:         foreach ($updateCats as $cat) {
 846:             $cat->store();
 847:         }
 848:     } else {
 849:         $string = '';
 850:         foreach ($error as $msg) {
 851:             $string .= $msg . '<br>';
 852:         }
 853:         $notification->displayNotification(cGuiNotification::LEVEL_WARNING, $msg . '<br><br>' . i18n('Something went wrong while trying to perform this operation. Please try again.'));
 854:         return;
 855:     }
 856: }
 857: 
 858: /**
 859:  * Moves a subtree to another destination.
 860:  *
 861:  * @param int $idcat Id of category
 862:  * @param int $newParentId Id of destination parent category
 863:  * @param int $newPreId Id of new previous category
 864:  * @param int $newPostId Id of new post category
 865:  */
 866: function strMoveSubtree($idcat, $newParentId, $newPreId = NULL, $newPostId = NULL) {
 867:     global $movesubtreeidcat, $notification;
 868: 
 869:     $idlang = cRegistry::getLanguageId();
 870:     $cat = new cApiCategoryCollection();
 871:     $children = $cat->getAllChildCategoryIds($idcat, $idlang);
 872: 
 873:     foreach ($children as $category) {
 874:         // avoids to move the main tree node in sub node of the same tree
 875:         if ($category == $newParentId) {
 876:             return false;
 877:         }
 878:     }
 879: 
 880:     if ($idcat == $newParentId) {
 881:         return false;
 882:     }
 883: 
 884:     if ($newParentId == 0 && $newPreId == 0) {
 885:         return false;
 886:     }
 887:     if (!isset($newPostId)) {
 888:         //return false;
 889:     }
 890:     // flag to rebuild the category table
 891:     global $remakeCatTable, $remakeStrTable;
 892: 
 893:     $remakeCatTable = true;
 894:     $remakeStrTable = true;
 895: 
 896:     // check the post ID parameter
 897:     if (is_null($newPostId)) {
 898:         $newPostId = 0;
 899:     }
 900: 
 901:     if ($newParentId == -1) {
 902:         // stop moving the category without actually moving it
 903:         $movesubtreeidcat = 0;
 904:     } else if (is_null($newParentId)) {
 905:         // start moving the category withour moving it yet
 906:         $movesubtreeidcat = $idcat;
 907:     } else {
 908:         // move the category with the ID idcat to the category newParentId
 909:         $category = new cApiCategory($idcat);
 910:         $oldPreId = $category->get('preid');
 911:         $oldPostId = $category->get('postid');
 912:         $oldParentId = $category->get('parentid');
 913: 
 914:         $updateCats = array();
 915: 
 916:         // update old predecessor (pre) category
 917:         if ($oldPreId != 0) {
 918:             $oldPreCategory = new cApiCategory($oldPreId);
 919:             $oldPreCategory->set('postid', $oldPostId);
 920:             $updateCats[$oldPreId] = $oldPreCategory;
 921:         }
 922: 
 923:         // update old follower (post) category
 924:         if ($oldPostId != 0) {
 925:             if (isset($updateCats[$oldPostId])) {
 926:                 $updateCats[$oldPostId]->set('preid', $oldPreId);
 927:             } else {
 928:                 $oldPostCategory = new cApiCategory($oldPostId);
 929:                 $oldPostCategory->set('preid', $oldPreId);
 930:                 $updateCats[$oldPostId] = $oldPostCategory;
 931:             }
 932:         }
 933: 
 934:         // update new predecessor (pre) category
 935:         if (is_null($newPreId)) {
 936:             // if no new pre ID has been given, use the last category in the
 937:             // given parent category
 938:             $categoryCollection = new cApiCategoryCollection();
 939:             $categoryCollection->select("parentid = " . $newParentId . " AND postid = 0");
 940:             $newPreCategory = $categoryCollection->next();
 941:             $newPreId = 0;
 942:         } else {
 943:             if (isset($updateCats[$newPreId])) {
 944:                 $updateCats[$newPreId]->set('postid', $idcat);
 945:             } else {
 946:                 $newPreCategory = new cApiCategory($newPreId);
 947:                 $newPreCategory->set('postid', $idcat);
 948:                 $updateCats[$newPreId] = $newPreCategory;
 949:                 $newPreId = $newPreCategory->get('idcat');
 950:             }
 951:         }
 952: 
 953:         // update new follower (post) category
 954:         if ($newPostId != 0) {
 955:             if (isset($updateCats[$newPostId])) {
 956:                 $updateCats[$newPostId]->set('preid', $idcat);
 957:             } else {
 958:                 $newPostCategory = new cApiCategory($newPostId);
 959:                 $newPostCategory->set('preid', $idcat);
 960:                 $updateCats[$newPostId] = $newPostCategory;
 961:             }
 962:         }
 963: 
 964:         // Update current category
 965:         $category->set('parentid', $newParentId);
 966:         $category->set('preid', $newPreId);
 967:         $category->set('postid', $newPostId);
 968:         $updateCats[$idcat] = $category;
 969: 
 970:         $error = strCheckTreeForErrors($updateCats);
 971:         if ($error === false) {
 972:             foreach ($updateCats as $cat) {
 973:                 $cat->store();
 974:             }
 975:         } else {
 976:             $string = '';
 977:             foreach ($error as $msg) {
 978:                 $string .= $msg . '<br>';
 979:             }
 980:             $notification->displayNotification(cGuiNotification::LEVEL_WARNING, $msg . '<br><br>' . i18n('Something went wrong while trying to perform this operation. Please try again.'));
 981:             return false;
 982:         }
 983: 
 984:         $movesubtreeidcat = 0;
 985:     }
 986: 
 987:     $sess = cRegistry::getSession();
 988:     $sess->register('movesubtreeidcat');
 989:     $sess->freeze();
 990: }
 991: 
 992: /**
 993:  * Checks if category is movable.
 994:  *
 995:  * @param int $idcat Id of category to move
 996:  * @param int $source Id of source category
 997:  * @return bool
 998:  */
 999: function strMoveCatTargetallowed($idcat, $source) {
1000:     return ($idcat == $source) ? 0 : 1;
1001: }
1002: 
1003: /**
1004:  * Synchronizes a category from one language to another language.
1005:  *
1006:  * @param int $idcatParam Id of category to synchronize
1007:  * @param int $sourcelang Id of source language
1008:  * @param int $targetlang Id of target language
1009:  * @param bool $bMultiple Flag to synchronize child languages
1010:  */
1011: function strSyncCategory($idcatParam, $sourcelang, $targetlang, $bMultiple = false) {
1012:     $bMultiple = (bool) $bMultiple;
1013: 
1014:     $aCatArray = array();
1015:     if ($bMultiple == true) {
1016:         $aCatArray = strDeeperCategoriesArray($idcatParam);
1017:     } else {
1018:         $aCatArray[] = $idcatParam;
1019:     }
1020: 
1021:     foreach ($aCatArray as $idcat) {
1022:         // Check if category for target language already exists
1023:         $oCatLang = new cApiCategoryLanguage();
1024:         if ($oCatLang->loadByCategoryIdAndLanguageId($idcat, $targetlang)) {
1025:             return false;
1026:         }
1027: 
1028:         // Get source category language
1029:         $oCatLang = new cApiCategoryLanguage();
1030:         if ($oCatLang->loadByCategoryIdAndLanguageId($idcat, $sourcelang)) {
1031:             $aRs = $oCatLang->toArray();
1032: 
1033:             // Copy the template configuration, if exists
1034:             $newidtplcfg = ($aRs['idtplcfg'] != 0) ? tplcfgDuplicate($aRs['idtplcfg']) : 0;
1035: 
1036:             $visible = 0;
1037:             $startidartlang = 0;
1038:             $urlpath = '';
1039: 
1040:             $oCatLangColl = new cApiCategoryLanguageCollection();
1041:             $oNewCatLang = $oCatLangColl->create($aRs['idcat'], $targetlang, $aRs['name'], $aRs['urlname'], $urlpath, $newidtplcfg, $visible, $aRs['public'], $aRs['status'], $aRs['author'], $startidartlang, $aRs['created'], $aRs['lastmodified']);
1042: 
1043:             // Execute CEC hook
1044:             $param = $aRs;
1045:             $param['idlang'] = $targetlang;
1046:             $param['idtplcfg'] = (int) $newidtplcfg;
1047:             $param['visible'] = $visible;
1048:             cApiCecHook::execute('Contenido.Category.strSyncCategory_Loop', $param);
1049: 
1050:             // Set correct rights for element
1051:             cInclude('includes', 'functions.rights.php');
1052:             createRightsForElement('str', $idcat, $targetlang);
1053:             createRightsForElement('con', $idcat, $targetlang);
1054:         }
1055:     }
1056: }
1057: 
1058: /**
1059:  * Checks if category has a start article
1060:  *
1061:  * @param int $idcat Id of category
1062:  * @param int $idlang The language id
1063:  * @return bool
1064:  */
1065: function strHasStartArticle($idcat, $idlang) {
1066:     $oCatLangColl = new cApiCategoryLanguageCollection();
1067:     return ($oCatLangColl->getStartIdartlangByIdcatAndIdlang($idcat, $idlang) > 0);
1068: }
1069: 
1070: /**
1071:  * Copies the category and it's existing articles into another category.
1072:  *
1073:  * @param int $idcat Id of category to copy
1074:  * @param int $destidcat Id of destination category
1075:  * @param bool $remakeTree Flag to rebuild category tree
1076:  * @param bool $bUseCopyLabel Flag to add copy label to the new categories
1077:  */
1078: function strCopyCategory($idcat, $destidcat, $remakeTree = true, $bUseCopyLabel = true) {
1079:     global $cfg, $lang;
1080: 
1081:     $newidcat = (int) strNewCategory($destidcat, 'a', $remakeTree);
1082:     if ($newidcat == 0) {
1083:         return;
1084:     }
1085: 
1086:     // Load old and new category
1087:     $oOldCatLang = new cApiCategoryLanguage();
1088:     if (!$oOldCatLang->loadByCategoryIdAndLanguageId($idcat, $lang)) {
1089:         return;
1090:     }
1091: 
1092:     $oNewCatLang = new cApiCategoryLanguage();
1093:     if (!$oNewCatLang->loadByCategoryIdAndLanguageId($newidcat, $lang)) {
1094:         return;
1095:     }
1096: 
1097:     // Worker objects
1098:     $oNewCat = new cApiCategory((int) $newidcat);
1099:     $oOldCat = new cApiCategory((int) $idcat);
1100: 
1101:     // Copy properties
1102:     if ($bUseCopyLabel == true) {
1103:         $oNewCatLang->set('name', sprintf(i18n('%s (Copy)'), $oOldCatLang->get('name')));
1104:     } else {
1105:         $oNewCatLang->set('name', $oOldCatLang->get('name'));
1106:     }
1107: 
1108:     $oNewCatLang->set('public', $oOldCatLang->get('public'));
1109:     $oNewCatLang->set('visible', 0);
1110:     $oNewCatLang->store();
1111: 
1112:     // Execute cec hook
1113:     cApiCecHook::execute('Contenido.Category.strCopyCategory', array(
1114:         'oldcat' => $oOldCat,
1115:         'newcat' => $oNewCat,
1116:         'newcatlang' => $oNewCatLang
1117:     ));
1118: 
1119:     // Copy template configuration
1120:     if ($oOldCatLang->get('idtplcfg') != 0) {
1121:         // Create new template configuration
1122:         $oNewCatLang->assignTemplate($oOldCatLang->getTemplate());
1123: 
1124:         // Copy the container configuration
1125:         $oContainerConfColl = new cApiContainerConfigurationCollection();
1126:         $oContainerConfColl->select('idtplcfg = ' . (int) $oOldCatLang->get('idtplcfg'));
1127: 
1128:         $oNewContainerConfColl = new cApiContainerConfigurationCollection();
1129:         while (($oItem = $oContainerConfColl->next()) !== false) {
1130:             $oNewContainerConfColl->create($oNewCatLang->get('idtplcfg'), $oItem->get('number'), $oItem->get('container'));
1131:         }
1132:     }
1133: 
1134:     $db = cRegistry::getDb();
1135: 
1136:     $oCatArtColl = new cApiCategoryArticleCollection();
1137: 
1138:     // Copy all articles
1139:     $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";
1140:     $db->query($sql, $cfg['tab']['cat_art'], $cfg['tab']['art_lang'], $idcat, $lang);
1141: 
1142:     while ($db->nextRecord()) {
1143:         $newidart = (int) conCopyArticle($db->f('idart'), $newidcat, '', $bUseCopyLabel);
1144:         if ($db->f('idartlang') == $oOldCatLang->get('startidartlang')) {
1145:             $oCatArtColl->resetQuery();
1146:             $idcatart = $oCatArtColl->getIdByCategoryIdAndArticleId($newidcat, $newidart);
1147:             if ($idcatart) {
1148:                 conMakeStart($idcatart, 1);
1149:             }
1150:         }
1151:     }
1152: 
1153:     return $newidcat;
1154: }
1155: 
1156: /**
1157:  * Copies the categorytree (category and its childs) to an another category.
1158:  *
1159:  * @param int $idcat Id of category to copy
1160:  * @param int $destcat Id of destination category
1161:  * @param bool $remakeTree Flag to rebuild category tree
1162:  * @param bool $bUseCopyLabel Flag to add copy label to the new categories
1163:  */
1164: function strCopyTree($idcat, $destcat, $remakeTree = true, $bUseCopyLabel = true) {
1165:     $newidcat = strCopyCategory($idcat, $destcat, false, $bUseCopyLabel);
1166: 
1167:     $oCatColl = new cApiCategoryCollection();
1168:     $aIds = $oCatColl->getIdsByWhereClause('parentid = ' . (int) $idcat);
1169:     foreach ($aIds as $id) {
1170:         strCopyTree($id, $newidcat, false, $bUseCopyLabel);
1171:     }
1172: 
1173:     if ($remakeTree == true) {
1174:         strRemakeTreeTable();
1175:     }
1176: }
1177: 
1178: /**
1179:  * Assigns a template to passed category.
1180:  *
1181:  * @param int $idcat
1182:  * @param int $client
1183:  * @param int $idTplCfg
1184:  */
1185: function strAssignTemplate($idcat, $client, $idTplCfg) {
1186:     global $perm;
1187: 
1188:     // Template permission check
1189:     $iIdtplcfg = ($perm->have_perm_area_action('str_tplcfg', 'str_tplcfg')) ? (int) $idTplCfg : 0;
1190: 
1191:     $idtpl = NULL;
1192:     if ($iIdtplcfg == 0) {
1193:         // Get default template
1194:         $oTemplateColl = new cApiTemplateCollection('defaulttemplate = 1 AND idclient = ' . (int) $client);
1195:         if (($oTemplate = $oTemplateColl->next()) !== false) {
1196:             $idtpl = $oTemplate->get('idtpl');
1197:         }
1198:     } else {
1199:         // Use passed template
1200:         $idtpl = $idTplCfg;
1201:     }
1202: 
1203:     if ($idtpl) {
1204:         // Assign template
1205:         $oCatLangColl = new cApiCategoryLanguageCollection('idcat = ' . (int) $idcat);
1206:         while (($oCatLang = $oCatLangColl->next()) !== false) {
1207:             $oCatLang->assignTemplate($idtpl);
1208:         }
1209:     }
1210: }
1211: 
1212: /**
1213:  * Checks the category tree for errors
1214:  * Returns FALSE if there are NO errors.
1215:  * If there are errors, an array with erorr messages will be returned
1216:  *
1217:  * @param array $addCats An array of cApiCategory objects which overwrite categories from the database
1218:  * @param array $ignoreCats An array of idcat's which will be treated like they don't exist in the database
1219:  * @return multitype:string |boolean An array of error messages if something is wrong. If nothing is wrong false will be returned
1220:  */
1221: function strCheckTreeForErrors($addCats = array(), $ignoreCats = array()) {
1222:     $errorMessages = array();
1223: 
1224:     // Get all categories into memory
1225:     $cats = new cApiCategoryCollection();
1226:     $cats->select();
1227: 
1228:     $catArray = array();
1229:     // first add the ones from the parameters
1230:     foreach ($addCats as $addCat) {
1231:         if ($addCat->get('idcat') == 0) {
1232:             continue;
1233:         }
1234:         $catArray[$addCat->get('idcat')] = $addCat;
1235:     }
1236: 
1237:     // add every category from the database
1238:     while ($cat = $cats->next()) {
1239:         if (in_array($cat->get('idcat'), $ignoreCats)) {
1240:             continue;
1241:         }
1242:         if (isset($catArray[$cat->get('idcat')])) {
1243:             continue;
1244:         }
1245:         $catArray[$cat->get('idcat')] = $cat;
1246:     }
1247: 
1248:     ksort($catArray);
1249: 
1250:     // build an array with the parentids at the top level and every child category as member
1251:     // aka
1252:     // $parents[parentId][catIdOfChildToParentId] = cApiCategory(catIdOfChildToParent)
1253:     // check if every parent that is mentioned in the database actually exists
1254:     $fine = true;
1255:     $parents = array();
1256:     foreach ($catArray as $idcat => $cat) {
1257:         if (!array_key_exists($cat->get('parentid'), $catArray) && $cat->get('parentid') != 0) {
1258:             $fine = false;
1259:             $errorMessages[] = sprintf(i18n('Category %s has a parent id (%s) which does not exist!'), $idcat, $cat->get('parentid'));
1260:         }
1261:         $parents[$cat->get('parentid')][$idcat] = $cat;
1262:     }
1263: 
1264:     // check for consistency in every parent
1265:     foreach ($parents as $parentId => $parent) {
1266:         // first, check for multiple preids and postids
1267:         // the category tree will miss some categories if multiple categories share preids and/or postids
1268:         $preIds = array();
1269:         $postIds = array();
1270:         foreach ($parent as $idcat => $cat) {
1271:             $preId = $cat->get('preid');
1272:             $postId = $cat->get('postid');
1273:             if (in_array($preId, $preIds)) {
1274:                 $fine = false;
1275:                 $errorMessages[] = sprintf(i18n('There are multiple categories in %s that share the same pre-id (%s - second occurence at %s). Sorting will fail and not all categories will be shown.'), $parentId, $preId, $idcat);
1276:             }
1277:             if (in_array($postId, $postIds)) {
1278:                 $fine = false;
1279:                 $errorMessages[] = sprintf(i18n('There are multiple categories in %s that share the same post-id (%s - second occurence at %s). Sorting will fail and not all categories will be shown.'), $parentId, $postId, $idcat);
1280:             }
1281:             $preIds[] = $preId;
1282:             $postIds[] = $postId;
1283:         }
1284: 
1285:         // check the consistency of the postids
1286:         // find the start
1287:         $startCat = null;
1288:         foreach ($parent as $cat) {
1289:             if ($cat->get('preid') == 0) {
1290:                 $startCat = $cat;
1291:                 break;
1292:             }
1293:         }
1294:         // if not start was found then something is wrong
1295:         if ($startCat == null) {
1296:             $fine = false;
1297:             $errorMessages[] = sprintf(i18n('There is no defined start (a category with preid == 0) in %s. Sorting impossible.'), $parentId);
1298:             continue;
1299:         }
1300:         // loop through the categories using the postid
1301:         $actCat = $startCat;
1302:         $checkedCats = array();
1303:         $checkedCats[] = $startCat->get('idcat');
1304:         while ($actCat != null) {
1305:             $catId = $actCat->get('idcat');
1306:             $postId = $actCat->get('postid');
1307:             if ($postId == 0) {
1308:                 break;
1309:             }
1310:             // check if the postid is actually a child of the parent
1311:             if (!array_key_exists($postId, $parent)) {
1312:                 $fine = false;
1313:                 $errorMessages[] = sprintf(i18n('%s has an invalid post-id (%s). The category does not exist in this parent! Sorting impossible.'), $catId, $postId);
1314:                 break;
1315:             }
1316:             $actCat = $catArray[$postId];
1317:             // check if the postid was seen before. if yes that would mean there's a loop in the tree
1318:             if (in_array($actCat->get('idcat'), $checkedCats)) {
1319:                 $fine = false;
1320:                 $errorMessages[] = sprintf(i18n('The sorting in category %s creates an infinite loop (postid = %s). Sorting the category is impossible! (Cause of failure is near category %s)'), $parentId, $postId, $catId);
1321:                 break;
1322:             }
1323:             $checkedCats[] = $actCat->get('idcat');
1324: 
1325:             // check that all categories in this parent belong to the same client
1326:             if (isset($catArray[$parentId])) {
1327:                 $parentClientId = $catArray[$parentId]->get('idclient');
1328:                 if ($actCat->get('idclient') != $parentClientId) {
1329:                     $fine = false;
1330:                     $errorMessages[] = sprintf(i18n('The category %s has a sub category (%s) that belongs to another client!'), $parentId, $catId);
1331:                     break;
1332:                 }
1333:             }
1334:         }
1335: 
1336:         // check the consistency of the preids
1337:         // find the last element (which is the start of the preids)
1338:         $startCat = null;
1339:         foreach ($parent as $cat) {
1340:             if ($cat->get('postid') == 0) {
1341:                 $startCat = $cat;
1342:                 break;
1343:             }
1344:         }
1345:         // if no end was found => error (this most likely means there's some kind of loop too)
1346:         if ($startCat == null) {
1347:             $fine = false;
1348:             $errorMessages[] = sprintf(i18n('There is no defined end (a category with postid == 0) in %s. Sorting impossible.'), $parentId);
1349:             continue;
1350:         }
1351:         // loop through the categories using the preid
1352:         $actCat = $startCat;
1353:         $checkedCats = array();
1354:         $checkedCats[] = $startCat->get('idcat');
1355:         while ($actCat != null) {
1356:             $catId = $actCat->get('idcat');
1357:             $preId = $actCat->get('preid');
1358:             if ($preId == 0) {
1359:                 break;
1360:             }
1361:             // if the preid isn't a child of the parent => error
1362:             if (!array_key_exists($preId, $parent)) {
1363:                 $fine = false;
1364:                 $errorMessages[] = sprintf(i18n('%s has an invalid pre-id (%s). The category does not exist in this parent! Sorting impossible.'), $catId, $preId);
1365:                 break;
1366:             }
1367:             $actCat = $catArray[$preId];
1368:             // if we've seen this preid before, that means there is some kind of loop => error
1369:             if (in_array($actCat->get('idcat'), $checkedCats)) {
1370:                 $fine = false;
1371:                 $errorMessages[] = sprintf(i18n('The sorting in category %s creates an infinite loop (preid = %s). Sorting the category is impossible! (Cause of failure is near category %s)'), $parentId, $preId, $catId);
1372:                 break;
1373:             }
1374:             $checkedCats[] = $actCat->get('idcat');
1375:         }
1376:     }
1377:     // if everything is fine, return false
1378:     // otherwise return the collected error messages
1379:     if (!$fine) {
1380:         $messages = array();
1381:         foreach ($errorMessages as $errorMessage) {
1382:             if (in_array($errorMessage, $messages)) {
1383:                 continue;
1384:             }
1385:             $messages[] = $errorMessage;
1386:         }
1387:         return $messages;
1388:     } else {
1389:         return false;
1390:     }
1391: }
1392: 
CMS CONTENIDO 4.9.1 API documentation generated by ApiGen 2.8.0