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

Functions

  • _getCurrentTypes
  • _processCmsTags
  • addArtspec
  • addslashes_deep
  • addSortImages
  • backToMainArea
  • buildArticleSelect
  • buildCategorySelect
  • buildCategorySelectRights
  • buildHeapTable
  • buildStackString
  • buildTree
  • buildUserOrGroupPermsFromRequest
  • callPluginStore
  • cApiCatGetLevelNode
  • cApiImageCheckCachedImageValidity
  • cApiImageCheckImageEditingPosibility
  • cApiImageGetCacheFileName
  • cApiImageGetTargetDimensions
  • cApiImageIsAnimGif
  • cApiImgScale
  • cApiImgScaleGetMD5CacheFile
  • cApiImgScaleHQ
  • cApiImgScaleImageMagick
  • cApiImgScaleLQ
  • cApiIsImageMagickAvailable
  • cApiStrCleanURLCharacters
  • cApiStrNormalizeLineEndings
  • cApiStrRecodeString
  • cApiStrReplaceDiacritics
  • cApiStrTrimAfterWord
  • cApiStrTrimHard
  • cApiStrTrimSentence
  • cDeprecated
  • cDie
  • cError
  • checkLangInClients
  • checkPathInformation
  • cInclude
  • compareUrlStrings
  • conChangeTemplateForCat
  • conCopyArticle
  • conCopyArtLang
  • conCopyContainerConf
  • conCopyContent
  • conCopyMetaTags
  • conCopyTemplateConfiguration
  • conCreateLocationString
  • conDeeperCategoriesArray
  • conDeleteart
  • conEditArt
  • conEditFirstTime
  • conFetchCategoryTree
  • conFlagOnOffline
  • conGenerateCode
  • conGenerateCodeForAllArts
  • conGenerateCodeForAllArtsInCategory
  • conGenerateCodeForAllartsUsingLayout
  • conGenerateCodeForAllartsUsingMod
  • conGenerateCodeForAllArtsUsingTemplate
  • conGenerateCodeForArtInAllCategories
  • conGenerateCodeForClient
  • conGenerateKeywords
  • conGetAvailableMetaTagTypes
  • conGetCategoryArticleId
  • conGetCategoryAssignments
  • conGetContainerConfiguration
  • conGetContentFromArticle
  • conGetHtmlTranslationTable
  • conGetMetaValue
  • conGetTemplateConfigurationIdForArticle
  • conGetTemplateConfigurationIdForCategory
  • conGetTopmostCat
  • conGetUsedModules
  • conHtmlentities
  • conHtmlEntityDecode
  • conHtmlSpecialChars
  • conIsLocked
  • conLock
  • conLockBulkEditing
  • conMakeArticleIndex
  • conMakeCatOnline
  • conMakeInlineScript
  • conMakeOnline
  • conMakeOnlineBulkEditing
  • conMakePublic
  • conMakeStart
  • conMoveArticles
  • conPhp54Check
  • conRemoveOldCategoryArticle
  • conSaveContentEntry
  • conSetCodeFlag
  • conSetCodeFlagBulkEditing
  • conSetMetaValue
  • conSyncArticle
  • copyRightsForElement
  • createBulkEditingFunction
  • createRandomName
  • createRightsForElement
  • cWarning
  • dbGetColumns
  • dbGetIndexes
  • dbGetPrimaryKeyName
  • dbTableExists
  • dbUpgradeTable
  • defineIfNotDefined
  • deleteArtspec
  • deleteRightsForElement
  • deleteSystemProperty
  • displayDatetime
  • emptyLogFile
  • endAndLogTiming
  • endsWith
  • extractNumber
  • generateDisplayFilePath
  • generateJs
  • getAllClientsAndLanguages
  • getArtLang
  • getArtspec
  • getAvailableContentTypes
  • getCanonicalDay
  • getCanonicalMonth
  • getDirectorySize
  • getEffectiveSetting
  • getEffectiveSettingsByType
  • getEncodingByLanguage
  • getFileContents
  • getFileInformation
  • getFileType
  • getGroupOrUserName
  • getIDForArea
  • getJsHelpContext
  • getLanguageNamesByClient
  • getLanguagesByClient
  • getmicrotime
  • getNamedFrame
  • getParam
  • getParentAreaId
  • getSearchResults
  • getStrExpandCollapseButton
  • getSystemProperties
  • getSystemPropertiesByType
  • getSystemProperty
  • getTemplateSelect
  • getUplExpandCollapseButton
  • htmldecode
  • htmlentities_iso88592
  • humanReadableSize
  • includePlugins
  • insertEmptyStrRow
  • ipMatch
  • isAlphanumeric
  • isArchive
  • isArtInMultipleUse
  • isFunctionDisabled
  • isGroup
  • isIPv4
  • isRunningFromWeb
  • isStartArticle
  • isUtf8
  • isValidMail
  • langActivateDeactivateLanguage
  • langDeleteLanguage
  • langEditLanguage
  • langGetTextDirection
  • langNewLanguage
  • langRenameLanguage
  • layDeleteLayout
  • layEditLayout
  • machineReadableSize
  • mailLogBulkEditingFunctions
  • mailLogDecodeAddresses
  • markSubMenuItem
  • mask
  • modDeleteModule
  • modEditModule
  • modTestModule
  • phpInfoToHtml
  • plugin_include
  • prCreateURLNameLocationString
  • prDeleteCacheFileContent
  • prGetCacheFileContent
  • prResolvePathViaCategoryNames
  • prResolvePathViaURLNames
  • prWriteCacheFileContent
  • putFileContents
  • recursiveCopy
  • removeFileInformation
  • renderBackendBreadcrumb
  • renderLabel
  • renderSelectProperty
  • renderTextProperty
  • saveGroupRights
  • saveRights
  • scanDirectory
  • scanPlugins
  • sendEncodingHeader
  • set_magic_quotes_gpc
  • setArtspecDefault
  • setArtspecOnline
  • setHelpContext
  • setSystemProperty
  • showTree
  • startTiming
  • statCreateLocationString
  • statDisplayTopChooser
  • statDisplayYearlyTopChooser
  • statGetAvailableMonths
  • statGetAvailableYears
  • statResetStatistic
  • statsArchive
  • statsDisplayInfo
  • statsOverviewAll
  • statsOverviewTop
  • statsOverviewTopYear
  • statsOverviewYear
  • strAssignTemplate
  • strBuildSqlValues
  • strCheckTreeForErrors
  • strCopyCategory
  • strCopyTree
  • strDeeperCategoriesArray
  • strDeleteCategory
  • strHasArticles
  • strHasStartArticle
  • stripslashes_deep
  • strMakePublic
  • strMakeVisible
  • strMoveCatTargetallowed
  • strMoveDownCategory
  • strMoveSubtree
  • strMoveUpCategory
  • strNewCategory
  • strNewTree
  • strNextBackwards
  • strNextDeeper
  • strNextDeeperAll
  • strNextPost
  • strOrderedPostTreeList
  • strRemakeTreeTable
  • strRenameCategory
  • strRenameCategoryAlias
  • strSortPrePost
  • strSyncCategory
  • systemHavePerm
  • tplAutoFillModules
  • tplBrowseLayoutForContainers
  • tplcfgDuplicate
  • tplDeleteTemplate
  • tplDuplicateTemplate
  • tplEditTemplate
  • tplGetContainerDefault
  • tplGetContainerMode
  • tplGetContainerName
  • tplGetContainerNumbersInLayout
  • tplGetContainerTypes
  • tplGetInUsedData
  • tplIsTemplateInUse
  • tplPreparseLayout
  • tplProcessSendContainerConfiguration
  • updateClientCache
  • updateFileInformation
  • uplCreateFriendlyName
  • uplDirectoryListRecursive
  • uplGetDirectoriesToExclude
  • uplGetFileExtension
  • uplGetFileIcon
  • uplGetFileTypeDescription
  • uplGetThumbnail
  • uplHasFiles
  • uplHasSubdirs
  • uplmkdir
  • uplRecursiveDBDirectoryList
  • uplRecursiveDirectoryList
  • uplRenameDirectory
  • uplSearch
  • uplSyncDirectory
  • uplSyncDirectoryDBFS
  • Overview
  • Package
  • Function
  • Tree
  • Deprecated
  • Todo
   1: <?php
   2: /**
   3:  * This file contains the CONTENIDO 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: 
 187:     if (!($error === false)) {
 188:         if ($oldPostId != -1) {
 189:             $oPrevCat->set('postid', $oldPostId);
 190:             $oPrevCat->store();
 191:         }
 192:         $oCatColl2->delete($oNewCat->get('idcat'));
 193:         return;
 194:     }
 195: 
 196:     cInclude('includes', 'functions.rights.php');
 197: 
 198:     // Loop through languages
 199:     $aLanguages = array(
 200:         $lang
 201:     );
 202:     foreach ($aLanguages as $curLang) {
 203:         $name = $catname;
 204:         $urlname = conHtmlSpecialChars(cApiStrCleanURLCharacters($catalias), ENT_QUOTES);
 205: 
 206:         // Insert new category language entry
 207:         $oCatLangColl = new cApiCategoryLanguageCollection();
 208:         $oCatLangColl->create($newIdcat, $curLang, $name, $urlname, '', 0, $visible, $public, 0, '', 0);
 209: 
 210:         // Set correct rights for element
 211:         copyRightsForElement('str', $parentid, $newIdcat, $curLang);
 212:         copyRightsForElement('con', $parentid, $newIdcat, $curLang);
 213:     }
 214: 
 215:     if ($remakeTree == true) {
 216:         strRemakeTreeTable();
 217:     }
 218: 
 219:     // Assign template
 220:     strAssignTemplate($newIdcat, $client, $iIdtplcfg);
 221: 
 222:     return $newIdcat;
 223: }
 224: 
 225: /**
 226:  * Builds ordered post string for a passed category
 227:  *
 228:  * @param int $idcat
 229:  * @param string $poststring
 230:  * @return string
 231:  */
 232: function strOrderedPostTreeList($idcat, $poststring) {
 233:     $oCatColl = new cApiCategoryCollection();
 234:     $oCatColl->select('parentid = 0 AND preid = ' . (int) $idcat . ' AND idcat != 0');
 235:     if (($oCat = $oCatColl->next()) !== false) {
 236:         $postIdcat = $oCat->get('idcat');
 237:         $poststring = $poststring . ',' . $postIdcat;
 238:         $poststring = strOrderedPostTreeList($postIdcat, $poststring);
 239:     }
 240: 
 241:     return $poststring;
 242: }
 243: 
 244: /**
 245:  * Remakes the category tree structure in category tree table.
 246:  *
 247:  * It still uses manually build sql statements due to performance reasons.
 248:  */
 249: function strRemakeTreeTable() {
 250:     global $db, $client, $cfg;
 251: 
 252:     // Flag to rebuild the category table
 253:     global $remakeCatTable;
 254:     global $remakeStrTable;
 255: 
 256:     // Get all category ids
 257:     $oCatColl = new cApiCategoryCollection();
 258:     $idcats = $oCatColl->getCategoryIdsByClient($client);
 259:     if (0 === count($idcats)) {
 260:         // There are no categories to build the tree from!
 261:         return;
 262:     }
 263: 
 264:     $errors = strCheckTreeForErrors();
 265:     if (!($errors === false)) {
 266:         return;
 267:     }
 268: 
 269:     $remakeCatTable = true;
 270:     $remakeStrTable = true;
 271: 
 272:     // Empty category tree table having specific categories
 273:     $sql = 'DELETE FROM ' . $cfg['tab']['cat_tree'] . ' WHERE idcat IN (' . implode(', ', $idcats) . ')';
 274:     $db->query($sql);
 275: 
 276:     // Delete entries from category table having idcat = 0
 277:     // @todo: Check this, how it is possible to have an invalid entry with
 278:     // primary key = 0
 279:     $sql = 'DELETE FROM ' . $cfg['tab']['cat'] . ' WHERE idcat = 0';
 280:     $db->query($sql);
 281: 
 282:     // Delete entries from category language table having idcat = 0
 283:     // @todo: Check this, how it is possible to have an invalid entry with
 284:     // primary key = 0
 285:     $sql = 'DELETE FROM ' . $cfg['tab']['cat_lang'] . ' WHERE idcat = 0';
 286:     $db->query($sql);
 287: 
 288:     // Get all categories by client
 289:     $sql = "SELECT idcat, parentid, preid, postid FROM " . $cfg['tab']['cat'] . " WHERE idclient = " . (int) $client . " ORDER BY parentid ASC, preid ASC, postid ASC";
 290:     $aCategories = array();
 291:     $db->query($sql);
 292:     while ($db->nextRecord()) {
 293:         $rs = $db->toArray();
 294:         if (!isset($aCategories[$rs['parentid']])) {
 295:             $aCategories[$rs['parentid']] = array();
 296:         }
 297:         $aCategories[$rs['parentid']][$rs['idcat']] = $rs;
 298:     }
 299: 
 300:     // Build INSERT statement
 301:     $sInsertQuery = "INSERT INTO " . $cfg['tab']['cat_tree'] . " (idcat, level) VALUES ";
 302:     $sInsertQuery = strBuildSqlValues($aCategories[0], $sInsertQuery, $aCategories);
 303:     $sInsertQuery = rtrim($sInsertQuery, " ,");
 304: 
 305:     // Lock db table and execute INSERT query
 306:     $db->query($sInsertQuery);
 307: }
 308: 
 309: /**
 310:  * Sorts passed assoziative categories array.
 311:  *
 312:  * @todo Check logic, move sorting to db layer, if possible!
 313:  * @param array $arr
 314:  * @return array
 315:  */
 316: function strSortPrePost($arr) {
 317:     $firstElement = NULL;
 318:     foreach ($arr as $row) {
 319:         if ($row['preid'] == 0) {
 320:             $firstElement = $row['idcat'];
 321:         }
 322:     }
 323: 
 324:     $curId = $firstElement;
 325:     $array = array();
 326: 
 327:     // Test for a last element in the category list
 328:     $fine = false;
 329:     foreach ($arr as $row) {
 330:         if ($row['postid'] == 0) {
 331:             $fine = true;
 332:             break;
 333:         }
 334:     }
 335:     if (!$fine) {
 336:         die(); // we already displayed an error message through strCheckTree
 337:     }
 338: 
 339:     while ($curId != 0) {
 340:         $array[] = $arr[$curId];
 341:         $curId = $arr[$curId]['postid'];
 342:     }
 343: 
 344:     return $array;
 345: }
 346: 
 347: /**
 348:  * Builds values part of the SQL used to recreate the category tree table
 349:  *
 350:  * @param array|?? $aCats Assoziative categories array or something else, but
 351:  *        what?
 352:  * @param string $sInsertQuery The insert statement
 353:  * @param array $aAllCats Assoziative categories array holding the complete
 354:  *        category structure
 355:  * @param int $iLevel Category level
 356:  * @return string
 357:  */
 358: function strBuildSqlValues($aCats, $sInsertQuery, &$aAllCats, $iLevel = 0) {
 359:     if (is_array($aCats)) {
 360:         $aCats = strSortPrePost($aCats);
 361:         foreach ($aCats as $aCat) {
 362:             $sInsertQuery .= '(' . (int) $aCat['idcat'] . ', ' . (int) $iLevel . '), ';
 363:             if (is_array($aAllCats[$aCat['idcat']])) {
 364:                 $iSubLevel = $iLevel + 1;
 365:                 $sInsertQuery = strBuildSqlValues($aAllCats[$aCat['idcat']], $sInsertQuery, $aAllCats, $iSubLevel);
 366:             }
 367:         }
 368:     }
 369:     return $sInsertQuery;
 370: }
 371: 
 372: /**
 373:  * Returns id of next deeper category.
 374:  *
 375:  * @global int $lang
 376:  * @param int $idcat Category id to check next deeper item
 377:  * @param bool $ignoreLang Flag to check for existing entry in category language
 378:  *        table
 379:  * @return int
 380:  */
 381: function strNextDeeper($idcat, $ignoreLang = false) {
 382:     global $lang;
 383: 
 384:     $languageId = (true == $ignoreLang) ? NULL : $lang;
 385:     $oCatColl = new cApiCategoryCollection();
 386:     return $oCatColl->getFirstChildCategoryId($idcat, $languageId);
 387: }
 388: 
 389: /**
 390:  * Checks, if passed category contains any articles
 391:  *
 392:  * @param int $idcat ID of category
 393:  * @return bool
 394:  */
 395: function strHasArticles($idcat) {
 396:     global $lang;
 397: 
 398:     $oCatArtColl = new cApiCategoryArticleCollection();
 399:     return $oCatArtColl->getHasArticles($idcat, $lang);
 400: }
 401: 
 402: /**
 403:  * Returns next post category id
 404:  *
 405:  * @param int $idcat ID of category
 406:  * @return int
 407:  */
 408: function strNextPost($idcat) {
 409:     $oCatColl = new cApiCategoryCollection();
 410:     return $oCatColl->getNextPostCategoryId($idcat);
 411: }
 412: 
 413: /**
 414:  * Returns next backwards category id
 415:  *
 416:  * @param int $idcat ID of category
 417:  * @return int
 418:  */
 419: function strNextBackwards($idcat) {
 420:     $oCatColl = new cApiCategoryCollection();
 421:     return $oCatColl->getParentsNextPostCategoryId($idcat);
 422: }
 423: 
 424: /**
 425:  * Returns list of child categories.
 426:  *
 427:  * @global int $lang
 428:  * @param int $idcat
 429:  * @param bool $ignoreLang
 430:  * @return array
 431:  */
 432: function strNextDeeperAll($idcat, $ignoreLang = false) {
 433:     global $lang;
 434: 
 435:     $languageId = (true == $ignoreLang) ? NULL : $lang;
 436:     $oCatColl = new cApiCategoryCollection();
 437:     return $oCatColl->getAllChildCategoryIds($idcat, $languageId);
 438: }
 439: 
 440: /**
 441:  * Renames a category
 442:  *
 443:  * @param int $idcat Category id
 444:  * @param int $lang Language id
 445:  * @param string $newcategoryname New category name
 446:  * @param string $newcategoryalias New category alias
 447:  */
 448: function strRenameCategory($idcat, $lang, $newCategoryName, $newCategoryAlias) {
 449:     if (trim($newCategoryName) == '') {
 450:         return;
 451:     }
 452: 
 453:     $oCatLang = new cApiCategoryLanguage();
 454:     if (!$oCatLang->loadByCategoryIdAndLanguageId($idcat, $lang)) {
 455:         // Couldn't load category language
 456:         return;
 457:     }
 458: 
 459:     $oldData = array(
 460:         'idcat' => $oCatLang->get('idcat'),
 461:         'name' => $oCatLang->get('name'),
 462:         'urlname' => $oCatLang->get('urlname')
 463:     );
 464: 
 465:     $name = stripslashes($newCategoryName);
 466:     $urlName = (trim($newCategoryAlias) != '') ? trim($newCategoryAlias) : $newCategoryName;
 467: 
 468:     if (trim($newCategoryAlias) != '') {
 469:         // overfluous assignment
 470:         // if ($oCatLang->get('urlname') != $newCategoryAlias) {
 471:         // $urlName = $newCategoryAlias;
 472:         // }
 473:         cInclude('includes', 'functions.pathresolver.php');
 474:         $client = cRegistry::getClientId();
 475:         prDeleteCacheFileContent($client, $lang);
 476:     }
 477: 
 478:     $oCatLang->set('name', $name);
 479:     $oCatLang->set('urlname', $urlName);
 480:     $oCatLang->set('lastmodified', date('Y-m-d H:i:s'));
 481:     $oCatLang->store();
 482: 
 483:     $newData = array(
 484:         'idcat' => $idcat,
 485:         'name' => $name,
 486:         'urlname' => $urlName
 487:     );
 488: 
 489:     cApiCecHook::execute('Contenido.Category.strRenameCategory', $newData, $oldData);
 490: }
 491: 
 492: /**
 493:  * Renames a category alias.
 494:  *
 495:  * @param int $idcat Category id
 496:  * @param int $lang Language id
 497:  * @param string $newcategoryalias New category alias
 498:  */
 499: function strRenameCategoryAlias($idcat, $lang, $newcategoryalias) {
 500:     $oCatLang = new cApiCategoryLanguage();
 501:     if (!$oCatLang->loadByCategoryIdAndLanguageId($idcat, $lang)) {
 502:         // Couldn't load category language
 503:         return;
 504:     }
 505: 
 506:     $oldData = array(
 507:         'idcat' => $oCatLang->get('idcat'),
 508:         'urlname' => $oCatLang->get('urlname')
 509:     );
 510: 
 511:     if (trim($newcategoryalias) == '') {
 512:         // Use categoryname as default -> get it escape it save it as urlname
 513:         $newcategoryalias = $oCatLang->get('name');
 514:     }
 515: 
 516:     $oCatLang->set('urlname', $newcategoryalias);
 517:     $oCatLang->set('lastmodified', date('Y-m-d H:i:s'));
 518:     $oCatLang->store();
 519: 
 520:     cInclude('includes', 'functions.pathresolver.php');
 521:     $client = cRegistry::getClientId();
 522:     prDeleteCacheFileContent($client, $lang);
 523: 
 524:     $newData = array(
 525:         'idcat' => $idcat,
 526:         'urlname' => $newcategoryalias
 527:     );
 528: 
 529:     cApiCecHook::execute('Contenido.Category.strRenameCategoryAlias', $newData, $oldData);
 530: }
 531: 
 532: /**
 533:  * Sets the visible status of the category and its childs
 534:  *
 535:  * @param int $idcat Category id
 536:  * @param int $lang Language id
 537:  * @param int $visible Visible status
 538:  */
 539: function strMakeVisible($idcat, $lang, $visible) {
 540:     global $cfg;
 541: 
 542:     $visible = (int) $visible;
 543:     $lang = (int) $lang;
 544: 
 545:     $categories = strDeeperCategoriesArray($idcat);
 546:     foreach ($categories as $value) {
 547:         $oCatLang = new cApiCategoryLanguage();
 548:         $oCatLang->loadByCategoryIdAndLanguageId($value, $lang);
 549:         $oCatLang->set('visible', $visible);
 550:         $oCatLang->set('lastmodified', date('Y-m-d H:i:s'));
 551:         $oCatLang->store();
 552:     }
 553: 
 554:     if ($cfg['pathresolve_heapcache'] == true && $visible = 0) {
 555:         $oPathresolveCacheColl = new cApiPathresolveCacheCollection();
 556:         $oPathresolveCacheColl->deleteByCategoryAndLanguage($idcat, $lang);
 557:     }
 558: }
 559: 
 560: /**
 561:  * Sets the public status of the category and its childs
 562:  *
 563:  * @param int $idcat Category id
 564:  * @param int $lang Language id
 565:  * @param int $public Public status
 566:  */
 567: function strMakePublic($idcat, $lang, $public) {
 568:     $categories = strDeeperCategoriesArray($idcat);
 569:     foreach ($categories as $value) {
 570:         $oCatLang = new cApiCategoryLanguage();
 571:         $oCatLang->loadByCategoryIdAndLanguageId($value, $lang);
 572:         $oCatLang->set('public', $public);
 573:         $oCatLang->set('lastmodified', date('Y-m-d H:i:s'));
 574:         $oCatLang->store();
 575:     }
 576: }
 577: 
 578: /**
 579:  * Returns all childs and childchilds of passed category
 580:  *
 581:  * @param int $startIdcat The start category
 582:  * @return array Contains all childs of $startIdcat and $startIdcat start itself
 583:  */
 584: function strDeeperCategoriesArray($startIdcat) {
 585:     global $client;
 586: 
 587:     $oCatColl = new cApiCategoryCollection();
 588:     return $oCatColl->getAllCategoryIdsRecursive($startIdcat, $client);
 589: }
 590: 
 591: /**
 592:  * Deletes the category and its template configurations.
 593:  *
 594:  * Only categories having no child categories and having no articles will be
 595:  * deleted!
 596:  *
 597:  * @param int $idcat Id of category to delete
 598:  */
 599: function strDeleteCategory($idcat) {
 600:     global $lang, $lang;
 601: 
 602:     // Flag to rebuild the category table
 603:     global $remakeCatTable, $remakeStrTable;
 604: 
 605:     if (strNextDeeper($idcat)) {
 606:         // Category has subcategories
 607:         return '0201';
 608:     } elseif (strHasArticles($idcat)) {
 609:         // Category has articles
 610:         return '0202';
 611:     }
 612: 
 613:     cInclude('includes', 'functions.rights.php');
 614: 
 615:     $remakeCatTable = true;
 616:     $remakeStrTable = true;
 617: 
 618:     // Load category language
 619:     $oCatLang = new cApiCategoryLanguage();
 620:     $oCatLang->loadByCategoryIdAndLanguageId($idcat, $lang);
 621: 
 622:     if ($oCatLang->isLoaded()) {
 623:         // Delete template configuration (deletes also all container
 624:         // configurations)
 625:         $oTemplateConfigColl = new cApiTemplateConfigurationCollection();
 626:         $oTemplateConfigColl->delete($oCatLang->get('idtplcfg'));
 627: 
 628:         // Delete category language
 629:         $oCatLangColl = new cApiCategoryLanguageCollection();
 630:         $oCatLangColl->delete($oCatLang->get('idcatlang'));
 631:     }
 632: 
 633:     // Are there any additional entries for other languages?
 634:     $oCatLangColl = new cApiCategoryLanguageCollection();
 635:     $oCatLangColl->select('idcat = ' . (int) $idcat);
 636:     if (($oCatLang = $oCatLangColl->next()) !== false) {
 637:         // More languages found, delete rights for current category
 638:         deleteRightsForElement('str', $idcat, $lang);
 639:         deleteRightsForElement('con', $idcat, $lang);
 640:         return;
 641:     }
 642: 
 643:     // Load category
 644:     $oCat = new cApiCategory((int) $idcat);
 645:     $preid = (int) $oCat->get('preid');
 646:     $postid = (int) $oCat->get('postid');
 647: 
 648:     // Update pre cat, set it to new postid
 649:     if ($preid != 0) {
 650:         $oPreCat = new cApiCategory($preid);
 651:         $oPreCat->set('postid', $postid);
 652:         $oPreCat->store();
 653:     }
 654: 
 655:     // Update post cat, set it to new preid
 656:     if ($postid != 0) {
 657:         $oPostCat = new cApiCategory($postid);
 658:         $oPostCat->set('preid', $preid);
 659:         $oPostCat->store();
 660:     }
 661: 
 662:     $error = strCheckTreeForErrors(array(), array(
 663:         $idcat
 664:     ));
 665:     if (!($error === false)) {
 666:         if ($preid != 0) {
 667:             $oPreCat = new cApiCategory($preid);
 668:             $oPreCat->set('postid', $idcat);
 669:             $oPreCat->store();
 670:         }
 671:         if ($postid != 0) {
 672:             $oPostCat = new cApiCategory($postid);
 673:             $oPostCat->set('preid', $idcat);
 674:             $oPostCat->store();
 675:         }
 676:         return '0600';
 677:     }
 678: 
 679:     // Delete category
 680:     $oCatColl = new cApiCategoryCollection();
 681:     $oCatColl->deleteBy('idcat', (int) $idcat);
 682: 
 683:     $oCatLangColl = new cApiCategoryLanguageCollection();
 684:     $oCatLangColl->select('idcat = ' . (int) $idcat);
 685:     if (($oCatLang = $oCatLangColl->next()) !== false) {
 686:         // Delete template configuration (deletes also all container
 687:         // configurations)
 688:         $oTemplateConfigColl = new cApiTemplateConfigurationCollection();
 689:         $oTemplateConfigColl->delete($oCatLang->get('idtplcfg'));
 690:     }
 691: 
 692:     // Delete category language entry by category id
 693:     $oCatLangColl->resetQuery();
 694:     $oCatLangColl->deleteBy('idcat', (int) $idcat);
 695: 
 696:     // Delete category tree entry by category id
 697:     $oCatTreeColl = new cApiCategoryTreeCollection();
 698:     $oCatTreeColl->deleteBy('idcat', (int) $idcat);
 699: 
 700:     // Delete rights for element
 701:     deleteRightsForElement('str', $idcat);
 702:     deleteRightsForElement('con', $idcat);
 703: }
 704: 
 705: /**
 706:  * Moves a category upwards.
 707:  *
 708:  * @param int $idcat Id of category to upwards
 709:  */
 710: function strMoveUpCategory($idcat) {
 711:     // Flag to rebuild the category table
 712:     global $remakeCatTable, $remakeStrTable;
 713: 
 714:     // Load current category
 715:     $oCat = new cApiCategory();
 716:     $oCat->loadByPrimaryKey((int) $idcat);
 717:     $preid = $oCat->get('preid');
 718:     $postid = $oCat->get('postid');
 719: 
 720:     if (0 == $preid) {
 721:         // No preid, no way to move up
 722:         return;
 723:     }
 724: 
 725:     $remakeCatTable = true;
 726:     $remakeStrTable = true;
 727: 
 728:     // Load previous category
 729:     $oPreCat = new cApiCategory();
 730:     $oPreCat->loadByPrimaryKey((int) $preid);
 731:     $prePreid = $oPreCat->get('preid');
 732:     $preIdcat = $oPreCat->get('idcat');
 733: 
 734:     // Load category before previous category
 735:     $oPrePreCat = new cApiCategory();
 736:     if ((int) $prePreid > 0) {
 737:         $oPrePreCat->loadByPrimaryKey((int) $prePreid);
 738:     }
 739: 
 740:     // Load post category
 741:     $oPostCat = new cApiCategory();
 742:     if ((int) $postid > 0) {
 743:         $oPostCat->loadByPrimaryKey((int) $postid);
 744:     }
 745: 
 746:     $updateCats = array();
 747: 
 748:     // Update category before previous, if exists
 749:     if ($oPrePreCat->isLoaded()) {
 750:         $oPrePreCat->set('postid', $idcat);
 751:         $updateCats[$prePreid] = $oPrePreCat;
 752:     }
 753: 
 754:     // Update previous category
 755:     $oPreCat->set('preid', $idcat);
 756:     $oPreCat->set('postid', $postid);
 757:     $updateCats[$preid] = $oPreCat;
 758: 
 759:     // Update current category
 760:     $oCat->set('preid', $prePreid);
 761:     $oCat->set('postid', $preid);
 762:     $updateCats[$idcat] = $oCat;
 763: 
 764:     // Update post category, if exists!
 765:     $oPostCat->set('preid', $preIdcat);
 766:     $updateCats[$postid] = $oPostCat;
 767: 
 768:     $error = strCheckTreeForErrors($updateCats);
 769:     if ($error === false) {
 770:         foreach ($updateCats as $cat) {
 771:             $cat->store();
 772:         }
 773:     } else {
 774:         $string = '';
 775:         foreach ($error as $msg) {
 776:             $string .= $msg . '<br>';
 777:         }
 778:         $notification->displayNotification(cGuiNotification::LEVEL_WARNING, $msg . '<br><br>' . i18n('Something went wrong while trying to perform this operation. Please try again.'));
 779:         return;
 780:     }
 781: }
 782: 
 783: /**
 784:  * Moves a category downwards.
 785:  *
 786:  * @param int $idcat Id of category to move downwards
 787:  */
 788: function strMoveDownCategory($idcat) {
 789:     // Flag to rebuild the category table
 790:     global $remakeCatTable, $remakeStrTable;
 791: 
 792:     // Load current category
 793:     $oCat = new cApiCategory();
 794:     $oCat->loadByPrimaryKey((int) $idcat);
 795:     $preid = $oCat->get('preid');
 796:     $postid = $oCat->get('postid');
 797: 
 798:     if (0 == $postid) {
 799:         // No post, no way to move down
 800:         return;
 801:     }
 802: 
 803:     $remakeCatTable = true;
 804:     $remakeStrTable = true;
 805: 
 806:     // Load previous category
 807:     $oPreCat = new cApiCategory();
 808:     if ((int) $preid > 0) {
 809:         $oPreCat->loadByPrimaryKey((int) $preid);
 810:         $preIdcat = (int) $oPreCat->get('idcat');
 811:     } else {
 812:         $preIdcat = 0;
 813:     }
 814: 
 815:     // Load post category
 816:     $oPostCat = new cApiCategory();
 817:     $oPostCat->loadByPrimaryKey((int) $postid);
 818:     $postIdcat = $oPostCat->get('idcat');
 819:     $postPostid = $oPostCat->get('postid');
 820: 
 821:     $updateCats = array();
 822: 
 823:     if ($preIdcat != 0) {
 824:         // Update previous category, if exists
 825:         $oPreCat->set('postid', (int) $postIdcat);
 826:         $updateCats[$preIdcat] = $oPreCat;
 827:     }
 828: 
 829:     // Update current category
 830:     $oCat->set('preid', $postid);
 831:     $oCat->set('postid', $postPostid);
 832:     $updateCats[$idcat] = $oCat;
 833: 
 834:     // Update post category
 835:     $oPostCat->set('preid', $preIdcat);
 836:     $oPostCat->set('postid', $idcat);
 837:     $updateCats[$postid] = $oPostCat;
 838: 
 839:     if ($postPostid != 0) {
 840:         // Update post post category, if exists
 841:         $oPostPostCat = new cApiCategory($postPostid);
 842:         $oPostPostCat->set('preid', $idcat);
 843:         $updateCats[$postPostid] = $oPostPostCat;
 844:     }
 845: 
 846:     $error = strCheckTreeForErrors($updateCats);
 847:     if ($error === false) {
 848:         foreach ($updateCats as $cat) {
 849:             $cat->store();
 850:         }
 851:     } else {
 852:         $string = '';
 853:         foreach ($error as $msg) {
 854:             $string .= $msg . '<br>';
 855:         }
 856:         $notification->displayNotification(cGuiNotification::LEVEL_WARNING, $msg . '<br><br>' . i18n('Something went wrong while trying to perform this operation. Please try again.'));
 857:         return;
 858:     }
 859: }
 860: 
 861: /**
 862:  * Moves a subtree to another destination.
 863:  *
 864:  * @param int $idcat Id of category
 865:  * @param int $newParentId Id of destination parent category
 866:  * @param int $newPreId Id of new previous category
 867:  * @param int $newPostId Id of new post category
 868:  */
 869: function strMoveSubtree($idcat, $newParentId, $newPreId = NULL, $newPostId = NULL) {
 870:     global $movesubtreeidcat, $notification;
 871: 
 872:     $idlang = cRegistry::getLanguageId();
 873:     $cat = new cApiCategoryCollection();
 874:     $children = $cat->getAllChildCategoryIds($idcat, $idlang);
 875: 
 876:     foreach ($children as $category) {
 877:         // avoids to move the main tree node in sub node of the same tree
 878:         if ($category == $newParentId) {
 879:             return false;
 880:         }
 881:     }
 882: 
 883:     if ($idcat == $newParentId) {
 884:         return false;
 885:     }
 886: 
 887:     if ($newParentId == 0 && $newPreId == 0) {
 888:         return false;
 889:     }
 890:     if (!isset($newPostId)) {
 891:         // return false;
 892:     }
 893:     // flag to rebuild the category table
 894:     global $remakeCatTable, $remakeStrTable;
 895: 
 896:     $remakeCatTable = true;
 897:     $remakeStrTable = true;
 898: 
 899:     // check the post ID parameter
 900:     if (is_null($newPostId)) {
 901:         $newPostId = 0;
 902:     }
 903: 
 904:     if ($newParentId == -1) {
 905:         // stop moving the category without actually moving it
 906:         $movesubtreeidcat = 0;
 907:     } else if (is_null($newParentId)) {
 908:         // start moving the category withour moving it yet
 909:         $movesubtreeidcat = $idcat;
 910:     } else {
 911:         // move the category with the ID idcat to the category newParentId
 912:         $category = new cApiCategory($idcat);
 913:         $oldPreId = $category->get('preid');
 914:         $oldPostId = $category->get('postid');
 915:         $oldParentId = $category->get('parentid');
 916: 
 917:         $updateCats = array();
 918: 
 919:         // update old predecessor (pre) category
 920:         if ($oldPreId != 0) {
 921:             $oldPreCategory = new cApiCategory($oldPreId);
 922:             $oldPreCategory->set('postid', $oldPostId);
 923:             $updateCats[$oldPreId] = $oldPreCategory;
 924:         }
 925: 
 926:         // update old follower (post) category
 927:         if ($oldPostId != 0) {
 928:             if (isset($updateCats[$oldPostId])) {
 929:                 $updateCats[$oldPostId]->set('preid', $oldPreId);
 930:             } else {
 931:                 $oldPostCategory = new cApiCategory($oldPostId);
 932:                 $oldPostCategory->set('preid', $oldPreId);
 933:                 $updateCats[$oldPostId] = $oldPostCategory;
 934:             }
 935:         }
 936: 
 937:         // update new predecessor (pre) category
 938:         if (is_null($newPreId)) {
 939:             // if no new pre ID has been given, use the last category in the
 940:             // given parent category
 941:             $categoryCollection = new cApiCategoryCollection();
 942:             $categoryCollection->select("parentid = " . $newParentId . " AND postid = 0");
 943:             $newPreCategory = $categoryCollection->next();
 944:             if($newPreCategory != null) {
 945:                 $newPreId = $newPreCategory->get('idcat');
 946:                 $newPreCategory->set('postid', $idcat);
 947:                 $updateCats[$newPreId] = $newPreCategory;
 948:             }
 949:         } else {
 950:             if (isset($updateCats[$newPreId])) {
 951:                 $updateCats[$newPreId]->set('postid', $idcat);
 952:             } else {
 953:                 $newPreCategory = new cApiCategory($newPreId);
 954:                 $newPreCategory->set('postid', $idcat);
 955:                 $updateCats[$newPreId] = $newPreCategory;
 956:                 $newPreId = $newPreCategory->get('idcat');
 957:             }
 958:         }
 959: 
 960:         // update new follower (post) category
 961:         if ($newPostId != 0) {
 962:             if (isset($updateCats[$newPostId])) {
 963:                 $updateCats[$newPostId]->set('preid', $idcat);
 964:             } else {
 965:                 $newPostCategory = new cApiCategory($newPostId);
 966:                 $newPostCategory->set('preid', $idcat);
 967:                 $updateCats[$newPostId] = $newPostCategory;
 968:             }
 969:         }
 970: 
 971:         // Update current category
 972:         $category->set('parentid', $newParentId);
 973:         $category->set('preid', $newPreId);
 974:         $category->set('postid', $newPostId);
 975:         $updateCats[$idcat] = $category;
 976: 
 977:         $error = strCheckTreeForErrors($updateCats);
 978:         if ($error === false) {
 979:             foreach ($updateCats as $cat) {
 980:                 $cat->store();
 981:             }
 982:         } else {
 983:             $string = '';
 984:             foreach ($error as $msg) {
 985:                 $string .= $msg . '<br>';
 986:             }
 987:             $notification->displayNotification(cGuiNotification::LEVEL_WARNING, $msg . '<br><br>' . i18n('Something went wrong while trying to perform this operation. Please try again.'));
 988:             return false;
 989:         }
 990: 
 991:         $movesubtreeidcat = 0;
 992:     }
 993: 
 994:     $sess = cRegistry::getSession();
 995:     $sess->register('movesubtreeidcat');
 996:     $sess->freeze();
 997: }
 998: 
 999: /**
1000:  * Checks if category is movable.
1001:  *
1002:  * @param int $idcat Id of category to move
1003:  * @param int $source Id of source category
1004:  * @return bool
1005:  */
1006: function strMoveCatTargetallowed($idcat, $source) {
1007:     return ($idcat == $source) ? 0 : 1;
1008: }
1009: 
1010: /**
1011:  * Synchronizes a category from one language to another language.
1012:  *
1013:  * @param int $idcatParam Id of category to synchronize
1014:  * @param int $sourcelang Id of source language
1015:  * @param int $targetlang Id of target language
1016:  * @param bool $bMultiple Flag to synchronize child languages
1017:  */
1018: function strSyncCategory($idcatParam, $sourcelang, $targetlang, $bMultiple = false) {
1019:     $bMultiple = (bool) $bMultiple;
1020: 
1021:     $aCatArray = array();
1022:     if ($bMultiple == true) {
1023:         $aCatArray = strDeeperCategoriesArray($idcatParam);
1024:     } else {
1025:         $aCatArray[] = $idcatParam;
1026:     }
1027: 
1028:     foreach ($aCatArray as $idcat) {
1029:         // Check if category for target language already exists
1030:         $oCatLang = new cApiCategoryLanguage();
1031:         if ($oCatLang->loadByCategoryIdAndLanguageId($idcat, $targetlang)) {
1032:             return false;
1033:         }
1034: 
1035:         // Get source category language
1036:         $oCatLang = new cApiCategoryLanguage();
1037:         if ($oCatLang->loadByCategoryIdAndLanguageId($idcat, $sourcelang)) {
1038:             $aRs = $oCatLang->toArray();
1039: 
1040:             // Copy the template configuration, if exists
1041:             $newidtplcfg = ($aRs['idtplcfg'] != 0) ? tplcfgDuplicate($aRs['idtplcfg']) : 0;
1042: 
1043:             $visible = 0;
1044:             $startidartlang = 0;
1045:             $urlpath = '';
1046: 
1047:             $oCatLangColl = new cApiCategoryLanguageCollection();
1048:             $oNewCatLang = $oCatLangColl->create($aRs['idcat'], $targetlang, $aRs['name'], $aRs['urlname'], $urlpath, $newidtplcfg, $visible, $aRs['public'], $aRs['status'], $aRs['author'], $startidartlang, $aRs['created'], $aRs['lastmodified']);
1049: 
1050:             // Execute CEC hook
1051:             $param = $aRs;
1052:             $param['idlang'] = $targetlang;
1053:             $param['idtplcfg'] = (int) $newidtplcfg;
1054:             $param['visible'] = $visible;
1055:             cApiCecHook::execute('Contenido.Category.strSyncCategory_Loop', $param);
1056: 
1057:             // Set correct rights for element
1058:             cInclude('includes', 'functions.rights.php');
1059:             createRightsForElement('str', $idcat, $targetlang);
1060:             createRightsForElement('con', $idcat, $targetlang);
1061:         }
1062:     }
1063: }
1064: 
1065: /**
1066:  * Checks if category has a start article
1067:  *
1068:  * @param int $idcat Id of category
1069:  * @param int $idlang The language id
1070:  * @return bool
1071:  */
1072: function strHasStartArticle($idcat, $idlang) {
1073:     $oCatLangColl = new cApiCategoryLanguageCollection();
1074:     return ($oCatLangColl->getStartIdartlangByIdcatAndIdlang($idcat, $idlang) > 0);
1075: }
1076: 
1077: /**
1078:  * Copies the category and it's existing articles into another category.
1079:  *
1080:  * @param int $idcat Id of category to copy
1081:  * @param int $destidcat Id of destination category
1082:  * @param bool $remakeTree Flag to rebuild category tree
1083:  * @param bool $bUseCopyLabel Flag to add copy label to the new categories
1084:  */
1085: function strCopyCategory($idcat, $destidcat, $remakeTree = true, $bUseCopyLabel = true) {
1086:     global $cfg, $lang;
1087: 
1088:     $newidcat = (int) strNewCategory($destidcat, 'a', $remakeTree);
1089:     if ($newidcat == 0) {
1090:         return;
1091:     }
1092: 
1093:     // Load old and new category
1094:     $oOldCatLang = new cApiCategoryLanguage();
1095:     if (!$oOldCatLang->loadByCategoryIdAndLanguageId($idcat, $lang)) {
1096:         return;
1097:     }
1098: 
1099:     $oNewCatLang = new cApiCategoryLanguage();
1100:     if (!$oNewCatLang->loadByCategoryIdAndLanguageId($newidcat, $lang)) {
1101:         return;
1102:     }
1103: 
1104:     // Worker objects
1105:     $oNewCat = new cApiCategory((int) $newidcat);
1106:     $oOldCat = new cApiCategory((int) $idcat);
1107: 
1108:     // Copy properties
1109:     if ($bUseCopyLabel == true) {
1110:         $oNewCatLang->set('name', sprintf(i18n('%s (Copy)'), $oOldCatLang->get('name')));
1111:     } else {
1112:         $oNewCatLang->set('name', $oOldCatLang->get('name'));
1113:     }
1114: 
1115:     $oNewCatLang->set('public', $oOldCatLang->get('public'));
1116:     $oNewCatLang->set('visible', 0);
1117:     $oNewCatLang->store();
1118: 
1119:     // Execute cec hook
1120:     cApiCecHook::execute('Contenido.Category.strCopyCategory', array(
1121:         'oldcat' => $oOldCat,
1122:         'newcat' => $oNewCat,
1123:         'newcatlang' => $oNewCatLang
1124:     ));
1125: 
1126:     // Copy template configuration
1127:     if ($oOldCatLang->get('idtplcfg') != 0) {
1128:         // Create new template configuration
1129:         $oNewCatLang->assignTemplate($oOldCatLang->getTemplate());
1130: 
1131:         // Copy the container configuration
1132:         $oContainerConfColl = new cApiContainerConfigurationCollection();
1133:         $oContainerConfColl->select('idtplcfg = ' . (int) $oOldCatLang->get('idtplcfg'));
1134: 
1135:         $oNewContainerConfColl = new cApiContainerConfigurationCollection();
1136:         while (($oItem = $oContainerConfColl->next()) !== false) {
1137:             $oNewContainerConfColl->create($oNewCatLang->get('idtplcfg'), $oItem->get('number'), $oItem->get('container'));
1138:         }
1139:     }
1140: 
1141:     $db = cRegistry::getDb();
1142: 
1143:     $oCatArtColl = new cApiCategoryArticleCollection();
1144: 
1145:     // Copy all articles
1146:     $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";
1147:     $db->query($sql, $cfg['tab']['cat_art'], $cfg['tab']['art_lang'], $idcat, $lang);
1148: 
1149:     while ($db->nextRecord()) {
1150:         $newidart = (int) conCopyArticle($db->f('idart'), $newidcat, '', $bUseCopyLabel);
1151:         if ($db->f('idartlang') == $oOldCatLang->get('startidartlang')) {
1152:             $oCatArtColl->resetQuery();
1153:             $idcatart = $oCatArtColl->getIdByCategoryIdAndArticleId($newidcat, $newidart);
1154:             if ($idcatart) {
1155:                 conMakeStart($idcatart, 1);
1156:             }
1157:         }
1158:     }
1159: 
1160:     return $newidcat;
1161: }
1162: 
1163: /**
1164:  * Copies the categorytree (category and its childs) to an another category.
1165:  *
1166:  * @param int $idcat Id of category to copy
1167:  * @param int $destcat Id of destination category
1168:  * @param bool $remakeTree Flag to rebuild category tree
1169:  * @param bool $bUseCopyLabel Flag to add copy label to the new categories
1170:  */
1171: function strCopyTree($idcat, $destcat, $remakeTree = true, $bUseCopyLabel = true) {
1172:     $newidcat = strCopyCategory($idcat, $destcat, false, $bUseCopyLabel);
1173: 
1174:     $oCatColl = new cApiCategoryCollection();
1175:     $aIds = $oCatColl->getIdsByWhereClause('parentid = ' . (int) $idcat);
1176:     foreach ($aIds as $id) {
1177:         strCopyTree($id, $newidcat, false, $bUseCopyLabel);
1178:     }
1179: 
1180:     if ($remakeTree == true) {
1181:         strRemakeTreeTable();
1182:     }
1183: }
1184: 
1185: /**
1186:  * Assigns a template to passed category.
1187:  *
1188:  * @param int $idcat
1189:  * @param int $client
1190:  * @param int $idTplCfg
1191:  */
1192: function strAssignTemplate($idcat, $client, $idTplCfg) {
1193:     global $perm;
1194: 
1195:     // Template permission check
1196:     $iIdtplcfg = ($perm->have_perm_area_action('str_tplcfg', 'str_tplcfg')) ? (int) $idTplCfg : 0;
1197: 
1198:     $idtpl = NULL;
1199:     if ($iIdtplcfg == 0) {
1200:         // Get default template
1201:         $oTemplateColl = new cApiTemplateCollection('defaulttemplate = 1 AND idclient = ' . (int) $client);
1202:         if (($oTemplate = $oTemplateColl->next()) !== false) {
1203:             $idtpl = $oTemplate->get('idtpl');
1204:         }
1205:     } else {
1206:         // Use passed template
1207:         $idtpl = $idTplCfg;
1208:     }
1209: 
1210:     if ($idtpl) {
1211:         // Assign template
1212:         $oCatLangColl = new cApiCategoryLanguageCollection('idcat = ' . (int) $idcat);
1213:         while (($oCatLang = $oCatLangColl->next()) !== false) {
1214:             $oCatLang->assignTemplate($idtpl);
1215:         }
1216:     }
1217: }
1218: 
1219: /**
1220:  * Checks the category tree for errors
1221:  * Returns FALSE if there are NO errors.
1222:  * If there are errors, an array with error messages will be returned
1223:  *
1224:  * @param array $addCats An array of cApiCategory objects which overwrite
1225:  *        categories from the database
1226:  * @param array $ignoreCats An array of idcat's which will be treated like they
1227:  *        don't exist in the database
1228:  * @return multitype:string |boolean An array of error messages if something is
1229:  *         wrong. If nothing is wrong false will be returned
1230:  */
1231: function strCheckTreeForErrors($addCats = array(), $ignoreCats = array()) {
1232:     $errorMessages = array();
1233: 
1234:     // Get all categories into memory
1235:     $cats = new cApiCategoryCollection();
1236:     $cats->select("idclient = '" . cSecurity::toInteger(cRegistry::getClientId()) . "'");
1237: 
1238:     $catArray = array();
1239:     // first add the ones from the parameters
1240:     foreach ($addCats as $addCat) {
1241:         if ($addCat->get('idcat') == 0) {
1242:             continue;
1243:         }
1244:         $catArray[$addCat->get('idcat')] = $addCat;
1245:     }
1246: 
1247:     // add every category from the database
1248:     while ($cat = $cats->next()) {
1249:         if (in_array($cat->get('idcat'), $ignoreCats)) {
1250:             continue;
1251:         }
1252:         if (isset($catArray[$cat->get('idcat')])) {
1253:             continue;
1254:         }
1255:         $catArray[$cat->get('idcat')] = $cat;
1256:     }
1257: 
1258:     ksort($catArray);
1259: 
1260:     // build an array with the parentids at the top level and every child
1261:     // category as member
1262:     // aka
1263:     // $parents[parentId][catIdOfChildToParentId] =
1264:     // cApiCategory(catIdOfChildToParent)
1265:     // check if every parent that is mentioned in the database actually exists
1266:     $fine = true;
1267:     $parents = array();
1268:     foreach ($catArray as $idcat => $cat) {
1269:         if (!array_key_exists($cat->get('parentid'), $catArray) && $cat->get('parentid') != 0) {
1270:             $fine = false;
1271:             $errorMessages[] = sprintf(i18n('Category %s has a parent id (%s) which does not exist!'), $idcat, $cat->get('parentid'));
1272:         }
1273:         $parents[$cat->get('parentid')][$idcat] = $cat;
1274:     }
1275: 
1276:     // check for consistency in every parent
1277:     foreach ($parents as $parentId => $parent) {
1278:         // first, check for multiple preids and postids
1279:         // the category tree will miss some categories if multiple categories
1280:         // share preids and/or postids
1281:         $preIds = array();
1282:         $postIds = array();
1283:         foreach ($parent as $idcat => $cat) {
1284:             $preId = $cat->get('preid');
1285:             $postId = $cat->get('postid');
1286:             if (in_array($preId, $preIds)) {
1287:                 $fine = false;
1288:                 $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);
1289:             }
1290:             if (in_array($postId, $postIds)) {
1291:                 $fine = false;
1292:                 $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);
1293:             }
1294:             $preIds[] = $preId;
1295:             $postIds[] = $postId;
1296:         }
1297: 
1298:         // check the consistency of the postids
1299:         // find the start
1300:         $startCat = null;
1301:         foreach ($parent as $cat) {
1302:             if ($cat->get('preid') == 0) {
1303:                 $startCat = $cat;
1304:                 break;
1305:             }
1306:         }
1307:         // if not start was found then something is wrong
1308:         if ($startCat == null) {
1309:             $fine = false;
1310:             $errorMessages[] = sprintf(i18n('There is no defined start (a category with preid == 0) in %s. Sorting impossible.'), $parentId);
1311:             continue;
1312:         }
1313:         // loop through the categories using the postid
1314:         $actCat = $startCat;
1315:         $checkedCats = array();
1316:         $checkedCats[] = $startCat->get('idcat');
1317:         while ($actCat != null) {
1318:             $catId = $actCat->get('idcat');
1319:             $postId = $actCat->get('postid');
1320:             if ($postId == 0) {
1321:                 break;
1322:             }
1323:             // check if the postid is actually a child of the parent
1324:             if (!array_key_exists($postId, $parent)) {
1325:                 $fine = false;
1326:                 $errorMessages[] = sprintf(i18n('%s has an invalid post-id (%s). The category does not exist in this parent! Sorting impossible.'), $catId, $postId);
1327:                 break;
1328:             }
1329:             $actCat = $catArray[$postId];
1330:             // check if the postid was seen before. if yes that would mean
1331:             // there's a loop in the tree
1332:             if (in_array($actCat->get('idcat'), $checkedCats)) {
1333:                 $fine = false;
1334:                 $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);
1335:                 break;
1336:             }
1337:             $checkedCats[] = $actCat->get('idcat');
1338: 
1339:             // check that all categories in this parent belong to the same
1340:             // client
1341:             if (isset($catArray[$parentId])) {
1342:                 $parentClientId = $catArray[$parentId]->get('idclient');
1343:                 if ($actCat->get('idclient') != $parentClientId) {
1344:                     $fine = false;
1345:                     $errorMessages[] = sprintf(i18n('The category %s has a sub category (%s) that belongs to another client!'), $parentId, $catId);
1346:                     break;
1347:                 }
1348:             }
1349:         }
1350: 
1351:         // check the consistency of the preids
1352:         // find the last element (which is the start of the preids)
1353:         $startCat = null;
1354:         foreach ($parent as $cat) {
1355:             if ($cat->get('postid') == 0) {
1356:                 $startCat = $cat;
1357:                 break;
1358:             }
1359:         }
1360:         // if no end was found => error (this most likely means there's some
1361:         // kind of loop too)
1362:         if ($startCat == null) {
1363:             $fine = false;
1364:             $errorMessages[] = sprintf(i18n('There is no defined end (a category with postid == 0) in %s. Sorting impossible.'), $parentId);
1365:             continue;
1366:         }
1367:         // loop through the categories using the preid
1368:         $actCat = $startCat;
1369:         $checkedCats = array();
1370:         $checkedCats[] = $startCat->get('idcat');
1371:         while ($actCat != null) {
1372:             $catId = $actCat->get('idcat');
1373:             $preId = $actCat->get('preid');
1374:             if ($preId == 0) {
1375:                 break;
1376:             }
1377:             // if the preid isn't a child of the parent => error
1378:             if (!array_key_exists($preId, $parent)) {
1379:                 $fine = false;
1380:                 $errorMessages[] = sprintf(i18n('%s has an invalid pre-id (%s). The category does not exist in this parent! Sorting impossible.'), $catId, $preId);
1381:                 break;
1382:             }
1383:             $actCat = $catArray[$preId];
1384:             // if we've seen this preid before, that means there is some kind of
1385:             // loop => error
1386:             if (in_array($actCat->get('idcat'), $checkedCats)) {
1387:                 $fine = false;
1388:                 $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);
1389:                 break;
1390:             }
1391:             $checkedCats[] = $actCat->get('idcat');
1392:         }
1393:     }
1394:     // if everything is fine, return false
1395:     // otherwise return the collected error messages
1396:     if (!$fine) {
1397:         $messages = array();
1398:         foreach ($errorMessages as $errorMessage) {
1399:             if (in_array($errorMessage, $messages)) {
1400:                 continue;
1401:             }
1402:             $messages[] = $errorMessage;
1403:         }
1404:         return $messages;
1405:     } else {
1406:         return false;
1407:     }
1408: }
1409: 
CMS CONTENIDO 4.9.4 API documentation generated by ApiGen 2.8.0