Overview

Packages

  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Datatype
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationMain
    • NavigationTop
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • cAjaxRequest
  • cAutoload
  • cBackend
  • cEffectiveSetting
  • cGuiScrollListAlltranslations
  • cHTMLValidator
  • cMailer
  • cModuleFileTranslation
  • cModuleHandler
  • cModuleSearch
  • cModuleSynchronizer
  • cModuleTemplateHandler
  • CodeMirror
  • cPasswordRequest
  • cPermission
  • cRegistry
  • cSystemPurge
  • cSystemtest
  • cTinyMCEEditor
  • cWYSIWYGEditor
  • FrontendList
  • HtmlParser
  • TreeItem
  • UploadList
  • UploadSearchResultList

Functions

  • _processCmsTags
  • addArtspec
  • addslashes_deep
  • addSortImages
  • backToMainArea
  • buildArticleSelect
  • buildCategorySelect
  • buildCategorySelectRights
  • buildHeapTable
  • buildStackString
  • buildTree
  • buildUserOrGroupPermsFromRequest
  • callPluginStore
  • cApiCatGetLevelNode
  • cApiImageCheckCachedImageValidity
  • cApiImageCheckImageEditingPosibility
  • cApiImageGetCacheFileName
  • cApiImageGetTargetDimensions
  • cApiImageIsAnimGif
  • cApiImgScale
  • cApiImgScaleGetMD5CacheFile
  • cApiImgScaleHQ
  • cApiImgScaleImageMagick
  • cApiImgScaleLQ
  • cApiIsImageMagickAvailable
  • cApiStrCleanURLCharacters
  • cApiStrNormalizeLineEndings
  • cApiStrRecodeString
  • cApiStrReplaceDiacritics
  • cApiStrTrimAfterWord
  • cApiStrTrimHard
  • cApiStrTrimSentence
  • cDeprecated
  • cDie
  • cError
  • checkLangInClients
  • checkPathInformation
  • cInclude
  • compareUrlStrings
  • conChangeTemplateForCat
  • conCopyArticle
  • conCopyArtLang
  • conCopyContainerConf
  • conCopyContent
  • conCopyMetaTags
  • conCopyTemplateConfiguration
  • conCreateLocationString
  • conDeeperCategoriesArray
  • conDeleteart
  • conEditArt
  • conEditFirstTime
  • conFetchCategoryTree
  • conFlagOnOffline
  • conGenerateCode
  • conGenerateCodeForAllArts
  • conGenerateCodeForAllArtsInCategory
  • conGenerateCodeForAllartsUsingLayout
  • conGenerateCodeForAllartsUsingMod
  • conGenerateCodeForAllArtsUsingTemplate
  • conGenerateCodeForArtInAllCategories
  • conGenerateCodeForClient
  • conGenerateKeywords
  • conGetAvailableMetaTagTypes
  • conGetCategoryArticleId
  • conGetCategoryAssignments
  • conGetContainerConfiguration
  • conGetContentFromArticle
  • conGetHtmlTranslationTable
  • conGetMetaValue
  • conGetTemplateConfigurationIdForArticle
  • conGetTemplateConfigurationIdForCategory
  • conGetTopmostCat
  • conGetUsedModules
  • conHtmlentities
  • conHtmlEntityDecode
  • conHtmlSpecialChars
  • conIsLocked
  • conLock
  • conLockBulkEditing
  • conMakeArticleIndex
  • conMakeCatOnline
  • conMakeOnline
  • conMakeOnlineBulkEditing
  • conMakePublic
  • conMakeStart
  • conMoveArticles
  • conPhp54Check
  • conRemoveOldCategoryArticle
  • conSaveContentEntry
  • conSetCodeFlag
  • conSetCodeFlagBulkEditing
  • conSetMetaValue
  • conSyncArticle
  • copyRightsForElement
  • createBulkEditingFunction
  • createRandomName
  • createRightsForElement
  • cWarning
  • dbGetColumns
  • dbGetIndexes
  • dbGetPrimaryKeyName
  • dbTableExists
  • dbUpgradeTable
  • defineIfNotDefined
  • deleteArtspec
  • deleteRightsForElement
  • deleteSystemProperty
  • displayDatetime
  • emptyLogFile
  • endAndLogTiming
  • endsWith
  • extractNumber
  • generateDisplayFilePath
  • generateInfoButton
  • generateJs
  • getAktuellType
  • getAllClientsAndLanguages
  • getArtLang
  • getArtspec
  • getAvailableContentTypes
  • getCanonicalDay
  • getCanonicalMonth
  • getDirectorySize
  • getEffectiveSetting
  • getEffectiveSettingsByType
  • getEncodingByLanguage
  • getFileContents
  • getFileInformation
  • getFileType
  • getGroupOrUserName
  • getIDForArea
  • getLanguageNamesByClient
  • getLanguagesByClient
  • getmicrotime
  • getNamedFrame
  • getParam
  • getParentAreaId
  • getSearchResults
  • getStrExpandCollapseButton
  • getSystemProperties
  • getSystemPropertiesByType
  • getSystemProperty
  • getTemplateSelect
  • getUplExpandCollapseButton
  • htmldecode
  • htmlentities_iso88592
  • humanReadableSize
  • includePlugins
  • insertEmptyStrRow
  • ipMatch
  • isAlphanumeric
  • isArchive
  • isArtInMultipleUse
  • isGroup
  • isIPv4
  • isRunningFromWeb
  • isStartArticle
  • isUtf8
  • isValidMail
  • langActivateDeactivateLanguage
  • langDeleteLanguage
  • langEditLanguage
  • langGetTextDirection
  • langNewLanguage
  • langRenameLanguage
  • layDeleteLayout
  • layEditLayout
  • machineReadableSize
  • mailLogBulkEditingFunctions
  • mailLogDecodeAddresses
  • markSubMenuItem
  • mask
  • modDeleteModule
  • modEditModule
  • modTestModule
  • phpInfoToHtml
  • plugin_include
  • prCreateURLNameLocationString
  • prDeleteCacheFileContent
  • prGetCacheFileContent
  • prResolvePathViaCategoryNames
  • prResolvePathViaURLNames
  • prWriteCacheFileContent
  • putFileContents
  • recursiveCopy
  • removeFileInformation
  • renderBackendBreadcrumb
  • renderLabel
  • renderSelectProperty
  • renderTextProperty
  • saveGroupRights
  • saveRights
  • scanDirectory
  • scanPlugins
  • sendEncodingHeader
  • set_magic_quotes_gpc
  • setArtspecDefault
  • setArtspecOnline
  • setHelpContext
  • setSystemProperty
  • showTree
  • startTiming
  • statCreateLocationString
  • statDisplayTopChooser
  • statDisplayYearlyTopChooser
  • statGetAvailableMonths
  • statGetAvailableYears
  • statResetStatistic
  • statsArchive
  • statsDisplayInfo
  • statsOverviewAll
  • statsOverviewTop
  • statsOverviewTopYear
  • statsOverviewYear
  • strAssignTemplate
  • strBuildSqlValues
  • strCopyCategory
  • strCopyTree
  • strDeeperCategoriesArray
  • strDeleteCategory
  • strHasArticles
  • strHasStartArticle
  • stripslashes_deep
  • strMakePublic
  • strMakeVisible
  • strMoveCatTargetallowed
  • strMoveDownCategory
  • strMoveSubtree
  • strMoveUpCategory
  • strNewCategory
  • strNewTree
  • strNextBackwards
  • strNextDeeper
  • strNextDeeperAll
  • strNextPost
  • strOrderedPostTreeList
  • strRemakeTreeTable
  • strRenameCategory
  • strRenameCategoryAlias
  • strSortPrePost
  • strSyncCategory
  • systemHavePerm
  • tplAutoFillModules
  • tplBrowseLayoutForContainers
  • tplcfgDuplicate
  • tplDeleteTemplate
  • tplDuplicateTemplate
  • tplEditTemplate
  • tplGetContainerDefault
  • tplGetContainerMode
  • tplGetContainerName
  • tplGetContainerTypes
  • tplGetInUsedData
  • tplIsTemplateInUse
  • tplPreparseLayout
  • updateClientCache
  • updateFileInformation
  • uplCreateFriendlyName
  • uplDirectoryListRecursive
  • uplGetDirectoriesToExclude
  • uplGetFileExtension
  • uplGetFileIcon
  • uplGetFileTypeDescription
  • uplGetThumbnail
  • uplHasFiles
  • uplHasSubdirs
  • uplmkdir
  • uplRecursiveDBDirectoryList
  • uplRecursiveDirectoryList
  • uplRenameDirectory
  • uplSearch
  • uplSyncDirectory
  • uplSyncDirectoryDBFS
  • xmlFileToArray
  • Overview
  • Package
  • Function
  • Tree
  • Deprecated
  • Todo
   1: <?php
   2: /**
   3:  * Defines the 'con' related functions in CONTENIDO
   4:  *
   5:  * @package Core
   6:  * @subpackage Backend
   7:  * @version SVN Revision $Rev:$
   8:  *
   9:  * @author Olaf Niemann, Jan Lengowski
  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: // Compatibility: Include new functions.con2.php
  20: cInclude('includes', 'functions.con2.php');
  21: 
  22: /**
  23:  * Create a new article
  24:  *
  25:  * @param int $idcat
  26:  * @param int $idcatnew
  27:  * @param int $idart
  28:  * @param unknown_type $isstart
  29:  * @param int $idtpl
  30:  * @param int $idartlang
  31:  * @param int $idlang
  32:  * @param unknown_type $title
  33:  * @param unknown_type $summary
  34:  * @param unknown_type $artspec
  35:  * @param unknown_type $created
  36:  * @param unknown_type $lastmodified
  37:  * @param unknown_type $author
  38:  * @param unknown_type $online
  39:  * @param unknown_type $datestart
  40:  * @param unknown_type $dateend
  41:  * @param unknown_type $artsort
  42:  * @param unknown_type $keyart
  43:  * @param unknown_type $searchable
  44:  * @param unknown_type $sitemapprio
  45:  * @param unknown_type $changefreq
  46:  * @return int Id of the new article
  47:  */
  48: function conEditFirstTime($idcat, $idcatnew, $idart, $isstart, $idtpl, $idartlang, $idlang, $title, $summary, $artspec, $created, $lastmodified, $author, $online, $datestart, $dateend, $artsort, $keyart = 0, $searchable = 1, $sitemapprio = 0.5, $changefreq = '') {
  49:     global $client, $lang, $auth, $urlname, $page_title;
  50:     // Some stuff for the redirect
  51:     global $redirect, $redirect_url, $external_redirect;
  52:     global $time_move_cat; // Used to indicate "move to cat"
  53:     global $time_target_cat; // Used to indicate the target category
  54:     global $time_online_move; // Used to indicate if the moved article should be
  55:                               // online
  56:     global $timemgmt;
  57: 
  58:     $page_title = addslashes($page_title);
  59:     $title      = stripslashes($title);
  60:     $urlname = (trim($urlname) == '')? trim($title) : trim($urlname);
  61: 
  62:     if ($isstart == 1) {
  63:         $timemgmt = 0;
  64:     }
  65: 
  66:     if (!is_array($idcatnew)) {
  67:         $idcatnew[0] = 0;
  68:     }
  69: 
  70:     // Create article entry
  71:     $oArtColl = new cApiArticleCollection();
  72:     $oArt = $oArtColl->create($client);
  73:     $idart = $oArt->get('idart');
  74: 
  75:     $status = 0;
  76: 
  77:     // Create an category article entry
  78:     $oCatArtColl = new cApiCategoryArticleCollection();
  79:     $oCatArt = $oCatArtColl->create($idcat, $idart, $status);
  80:     $idcatart = $oCatArt->get('idcatart');
  81: 
  82:     $aLanguages = array(
  83:         $lang
  84:     );
  85: 
  86:     // Table 'con_art_lang', one entry for every language
  87:     foreach ($aLanguages as $curLang) {
  88:         $lastmodified = ($lang == $curLang)? $lastmodified : '';
  89:         $modifiedby = '';
  90: 
  91:         if ($online == 1) {
  92:             $published_value = date('Y-m-d H:i:s');
  93:             $publishedby_value = $auth->auth['uname'];
  94:         } else {
  95:             $published_value = '';
  96:             $publishedby_value = '';
  97:         }
  98: 
  99:         // Create an stat entry
 100:         $oStatColl = new cApiStatCollection();
 101:         $oStat = $oStatColl->create($idcatart, $curLang, $client, 0);
 102: 
 103:         // Create an article language entry
 104:         $oArtLangColl = new cApiArticleLanguageCollection();
 105:         $oArtLang = $oArtLangColl->create($idart, $curLang, $title, $urlname, $page_title, $summary, $artspec, $created, $auth->auth['uname'], $lastmodified, $modifiedby, $published_value, $publishedby_value, $online, $redirect, $redirect_url, $external_redirect, $artsort, $timemgmt, $datestart, $dateend, $status, $time_move_cat, $time_target_cat, $time_online_move, 0, '', '', '', $searchable, $sitemapprio, $changefreq);
 106: 
 107:         $lastId = $oArtLang->get('idartlang');
 108:         $availableTags = conGetAvailableMetaTagTypes();
 109:         foreach ($availableTags as $key => $value) {
 110:             conSetMetaValue($lastId, $key, $_POST['META' . $value['name']]);
 111:         }
 112:     }
 113: 
 114:     // Get all idcats that contain art
 115:     $oCatArtColl = new cApiCategoryArticleCollection();
 116:     $aCatsForArt = $oCatArtColl->getCategoryIdsByArticleId($idart);
 117:     if (count($aCatsForArt) == 0) {
 118:         $aCatsForArt[0] = 0;
 119:     }
 120: 
 121:     $aLanguages = getLanguagesByClient($client);
 122: 
 123:     foreach ($idcatnew as $value) {
 124:         if (!in_array($value, $aCatsForArt)) {
 125:             // New category article entry
 126:             $oCatArtColl = new cApiCategoryArticleCollection();
 127:             $oCatArt = $oCatArtColl->create($value, $idart);
 128:             $curIdcatart = $oCatArt->get('idcatart');
 129: 
 130:             // New statistics entry for each language
 131:             foreach ($aLanguages as $curLang) {
 132:                 $oStatColl = new cApiStatCollection();
 133:                 $oStatColl->create($curIdcatart, $curLang, $client, 0);
 134:             }
 135:         }
 136:     }
 137: 
 138:     foreach ($aCatsForArt as $value) {
 139:         if (!in_array($value, $idcatnew)) {
 140:             // Delete category article and other related entries that will no
 141:             // longer exist
 142:             conRemoveOldCategoryArticle($value, $idart, $idartlang, $client, $lang);
 143:         }
 144:     }
 145: 
 146:     if (!$title) {
 147:         $title = '--- ' . i18n("Default title") . ' ---';
 148:     }
 149: 
 150:     // Update article language for all languages
 151:     foreach ($aLanguages as $curLang) {
 152:         $curOnline = ($lang == $curLang)? $online : 0;
 153:         $curLastmodified = ($lang == $curLang)? $lastmodified : '';
 154: 
 155:         $oArtLang = new cApiArticleLanguage();
 156:         $oArtLang->loadByArticleAndLanguageId($idart, $curLang);
 157:         if (!$oArtLang->isLoaded()) {
 158:             continue;
 159:         }
 160: 
 161:         $oArtLang->set('title', $title);
 162:         $oArtLang->set('urlname', $urlname);
 163:         $oArtLang->set('pagetitle', $page_title);
 164:         $oArtLang->set('summary', $summary);
 165:         $oArtLang->set('artspec', $artspec);
 166:         $oArtLang->set('created', $created);
 167:         $oArtLang->set('lastmodified', $curLastmodified);
 168:         $oArtLang->set('modifiedby', $author);
 169:         $oArtLang->set('online', $curOnline);
 170:         $oArtLang->set('searchable', $searchable);
 171:         $oArtLang->set('sitemapprio', $sitemapprio);
 172:         $oArtLang->set('changefreq', $changefreq);
 173:         $oArtLang->set('redirect', $redirect);
 174:         $oArtLang->set('redirect_url', $redirect_url);
 175:         $oArtLang->set('external_redirect', $external_redirect);
 176:         $oArtLang->set('artsort', $artsort);
 177:         $oArtLang->set('datestart', $datestart);
 178:         $oArtLang->set('dateend', $dateend);
 179:         $oArtLang->store();
 180:     }
 181: 
 182:     return $idart;
 183: }
 184: 
 185: /**
 186:  * Edit an existing article
 187:  *
 188:  * @param int $idcat
 189:  * @param int $idcatnew
 190:  * @param int $idart
 191:  * @param unknown_type $isstart
 192:  * @param int $idtpl
 193:  * @param int $idartlang
 194:  * @param int $idlang
 195:  * @param unknown_type $title
 196:  * @param unknown_type $summary
 197:  * @param unknown_type $artspec
 198:  * @param unknown_type $created
 199:  * @param unknown_type $lastmodified
 200:  * @param unknown_type $author
 201:  * @param unknown_type $online
 202:  * @param unknown_type $datestart
 203:  * @param unknown_type $dateend
 204:  * @param unknown_type $published
 205:  * @param unknown_type $artsort
 206:  * @param unknown_type $keyart
 207:  * @param unknown_type $searchable
 208:  * @param unknown_type $sitemapprio
 209:  * @param unknown_type $changefreq
 210:  */
 211: function conEditArt($idcat, $idcatnew, $idart, $isstart, $idtpl, $idartlang, $idlang, $title, $summary, $artspec, $created, $lastmodified, $author, $online, $datestart, $dateend, $published, $artsort, $keyart = 0, $searchable = 1, $sitemapprio = -1, $changefreq = 'nothing') {
 212:     global $client, $lang, $redirect, $redirect_url, $external_redirect, $perm;
 213:     global $urlname, $page_title;
 214:     global $time_move_cat, $time_target_cat;
 215:     // Used to indicate if the moved article should be online
 216:     global $time_online_move;
 217:     global $timemgmt;
 218: 
 219:     // Add slashes because single quotes will crash the db
 220:     $page_title = addslashes($page_title);
 221:     $title      = stripslashes($title);
 222: 
 223:     $urlname = (trim($urlname) == '')? trim($title) : trim($urlname);
 224:     $usetimemgmt = ((int) $timemgmt == 1)? 1 : 0;
 225:     if ($timemgmt == '1' && (($datestart == '' && $dateend == '') || ($datestart == '0000-00-00 00:00:00' && $dateend == '0000-00-00 00:00:00'))) {
 226:         $usetimemgmt = 0;
 227:     }
 228: 
 229:     if ($isstart == 1) {
 230:         $usetimemgmt = 0;
 231:     }
 232: 
 233:     if (!is_array($idcatnew)) {
 234:         $idcatnew[0] = 0;
 235:     }
 236: 
 237:     $oArtLang = new cApiArticleLanguage((int) $idartlang);
 238:     if (!$oArtLang->isLoaded()) {
 239:         return;
 240:     }
 241: 
 242:     // Get all idcats that contain art
 243:     $oCatArtColl = new cApiCategoryArticleCollection();
 244:     $aCatsForArt = $oCatArtColl->getCategoryIdsByArticleId($idart);
 245:     if (count($aCatsForArt) == 0) {
 246:         $aCatsForArt[0] = 0;
 247:     }
 248: 
 249:     // Get idtplcfg
 250:     $idTplCfg = $oArtLang->get('idtplcfg');
 251: 
 252:     foreach ($idcatnew as $value) {
 253:         if (!in_array($value, $aCatsForArt)) {
 254:             // New category article entry
 255:             $oCatArtColl = new cApiCategoryArticleCollection();
 256:             $oCatArt = $oCatArtColl->create($value, $idart);
 257:             $curIdcatart = $oCatArt->get('idcatart');
 258: 
 259:             // Copy template configuration
 260:             if ($idTplCfg != 0) {
 261:                 $newIdTplCfg = conCopyTemplateConfiguration($idTplCfg);
 262:                 conCopyContainerConf($idTplCfg, $newIdTplCfg);
 263:             }
 264: 
 265:             $aLanguages = getLanguagesByClient($client);
 266: 
 267:             // New statistics entry for each language
 268:             foreach ($aLanguages as $curLang) {
 269:                 $oStatColl = new cApiStatCollection();
 270:                 $oStatColl->create($curIdcatart, $curLang, $client, 0);
 271:             }
 272:         }
 273:     }
 274: 
 275:     foreach ($aCatsForArt as $value) {
 276:         if (!in_array($value, $idcatnew)) {
 277:             // Delete category article and other related entries that will no
 278:             // longer exist
 279:             conRemoveOldCategoryArticle($value, $idart, $idartlang, $client, $lang);
 280:         }
 281:     }
 282: 
 283:     if ($title == '') {
 284:         $title = '--- ' . i18n('Default title') . ' ---';
 285:     }
 286: 
 287:     $oArtLang->set('title', $title);
 288:     $oArtLang->set('urlname', $urlname);
 289:     $oArtLang->set('summary', $summary);
 290:     $oArtLang->set('artspec', $artspec);
 291:     $oArtLang->set('created', $created);
 292:     $oArtLang->set('lastmodified', $lastmodified);
 293:     $oArtLang->set('modifiedby', $author);
 294:     $oArtLang->set('timemgmt', $usetimemgmt);
 295:     $oArtLang->set('redirect', $redirect);
 296:     $oArtLang->set('external_redirect', $external_redirect);
 297:     $oArtLang->set('redirect_url', $redirect_url);
 298:     $oArtLang->set('artsort', $artsort);
 299:     $oArtLang->set('searchable', $searchable);
 300:     if ($sitemapprio != -1) {
 301:         $oArtLang->set('sitemapprio', $sitemapprio);
 302:     }
 303:     if ($changefreq != "nothing") {
 304:         $oArtLang->set('changefreq', $changefreq);
 305:     }
 306:     $oArtLang->set('published', $published);
 307: 
 308:     // If the user has right for makeonline, update some properties.
 309:     if ($perm->have_perm_area_action('con', 'con_makeonline') || $perm->have_perm_area_action_item('con', 'con_makeonline', $idcat)) {
 310:         $oldOnline = $oArtLang->get('online');
 311:         $oArtLang->set('online', $online);
 312: 
 313:         // Check if old online value was 0, update published data if value
 314:         // changed from 0 to 1
 315:         if ((int) $online == 1 && $oldOnline == 0) {
 316:             $oArtLang->set('published', date('Y-m-d H:i:s'));
 317:             $oArtLang->set('publishedby', $author);
 318:         }
 319: 
 320:         $oArtLang->set('datestart', $datestart);
 321:         $oArtLang->set('dateend', $dateend);
 322:         $oArtLang->set('time_move_cat', $time_move_cat);
 323:         $oArtLang->set('time_target_cat', $time_target_cat);
 324:         $oArtLang->set('time_online_move', $time_online_move);
 325:     }
 326: 
 327:     // Update idtplcfg
 328:     if (!empty($newIdTplCfg) && $idTplCfg != $newIdTplCfg) {
 329:         $oArtLang->set('idtplcfg', $newIdTplCfg);
 330:     }
 331: 
 332:     $oArtLang->store();
 333: 
 334:     // article has been saved, so clear the article cache
 335:     $purge = new cSystemPurge();
 336:     $purge->clearArticleCache($idartlang);
 337: }
 338: 
 339: /**
 340:  * Save a content element and generate index
 341:  *
 342:  * @param int $idartlang idartlang of the article
 343:  * @param string $type Type of content element
 344:  * @param int $typeid Serial number of the content element
 345:  * @param string $value Content
 346:  * @param bool $bForce Not used: Was a flag to use existing db instance in
 347:  *        global scope
 348:  */
 349: function conSaveContentEntry($idartlang, $type, $typeid, $value, $bForce = false) {
 350:     global $auth, $cfgClient, $client, $_cecRegistry;
 351: 
 352:     $oType = new cApiType();
 353:     if (!$oType->loadByType($type)) {
 354:         // Couldn't load type...
 355:         return;
 356:     }
 357: 
 358:     $date = date('Y-m-d H:i:s');
 359:     $author = $auth->auth['uname'];
 360:     $value = str_replace(cRegistry::getFrontendUrl(), '', $value);
 361:     $value = stripslashes($value);
 362: 
 363:     $iterator = $_cecRegistry->getIterator('Contenido.Content.SaveContentEntry');
 364:     while (($chainEntry = $iterator->next()) !== false) {
 365:         $value = $chainEntry->execute($idartlang, $type, $typeid, $value);
 366:     }
 367: 
 368:     $idtype = $oType->get('idtype');
 369: 
 370:     $oContent = new cApiContent();
 371:     $oContent->loadByArticleLanguageIdTypeAndTypeId($idartlang, $idtype, $typeid);
 372:     if ($oContent->isLoaded()) {
 373:         // Update existing entry
 374:         $oContent->set('value', $value);
 375:         $oContent->set('author', $author);
 376:         $oContent->set('lastmodified', date('Y-m-d H:i:s'));
 377:         $oContent->store();
 378:     } else {
 379:         // Create new entry
 380:         $oContentColl = new cApiContentCollection();
 381:         $oContent = $oContentColl->create($idartlang, $idtype, $typeid, $value, 0, $author, $date, $date);
 382:     }
 383: 
 384:     // Touch the article to update last modified date
 385:     $lastmodified = date('Y-m-d H:i:s');
 386:     $oArtLang = new cApiArticleLanguage($idartlang);
 387:     $oArtLang->set('lastmodified', $lastmodified);
 388:     $oArtLang->set('modifiedby', $author);
 389:     $oArtLang->store();
 390: 
 391:     // content entry has been saved, so clear the article cache
 392:     $purge = new cSystemPurge();
 393:     $purge->clearArticleCache($idartlang);
 394: }
 395: 
 396: /**
 397:  * Generate index of article content.
 398:  *
 399:  * This is done by calling the hook 'Contenido.Content.AfterStore'.
 400:  *
 401:  * @param int $idartlang of article to index
 402:  * @param int $idart of article to index
 403:  */
 404: function conMakeArticleIndex($idartlang, $idart) {
 405: 
 406:     // get IDs of given article langauge
 407:     if (cRegistry::getArticleLanguageId() == $idartlang) {
 408:         // quite easy if given article is current article
 409:         $idclient = cRegistry::getClientId();
 410:         $idlang = cRegistry::getLanguageId();
 411:         $idcat = cRegistry::getCategoryId();
 412:         $idart = cRegistry::getArticleId();
 413:         $idcatlang = cRegistry::getCategoryLanguageId();
 414:         $idartlang = cRegistry::getArticleLanguageId();
 415:     } else {
 416:         // == for other articles these infos have to be read from DB
 417:         // get idclient by idart
 418:         $article = new cApiArticle($idart);
 419:         if ($article->isLoaded()) {
 420:             $idclient = $article->get('idclient');
 421:         }
 422:         // get idlang by idartlang
 423:         $articleLanguage = new cApiArticleLanguage($idartlang);
 424:         if ($articleLanguage->isLoaded()) {
 425:             $idlang = $articleLanguage->get('idlang');
 426:         }
 427:         // get first idcat by idart
 428:         $coll = new cApiCategoryArticleCollection();
 429:         $idcat = array_shift($coll->getCategoryIdsByArticleId($idart));
 430:         // get idcatlang by idcat & idlang
 431:         $categoryLanguage = new cApiCategoryLanguage();
 432:         $categoryLanguage->loadByCategoryIdAndLanguageId($idcat, $idlang);
 433:         if ($categoryLanguage->isLoaded()) {
 434:             $idcatlang = $articleLanguage->get('idlang');
 435:         }
 436:     }
 437: 
 438:     // build data structure expected by handlers of Contenido.Content.AfterStore
 439:     $articleIds = array(
 440:         'idclient' => $idclient,
 441:         'idlang' => $idlang,
 442:         'idcat' => $idcat,
 443:         'idcatlang' => $idcatlang,
 444:         'idart' => $idart,
 445:         'idartlang' => $idartlang
 446:     );
 447: 
 448:     // iterate chain Contenido.Content.AfterStore
 449:     $iterator = cRegistry::getCecRegistry()->getIterator('Contenido.Content.AfterStore');
 450:     while (false !== $chainEntry = $iterator->next()) {
 451:         $chainEntry->execute($articleIds);
 452:     }
 453: }
 454: 
 455: /**
 456:  * Toggle the online status of an article
 457:  *
 458:  * @param int $idart Article Id
 459:  * @param int $lang Language Id
 460:  */
 461: function conMakeOnline($idart, $lang) {
 462:     $auth = cRegistry::getAuth();
 463: 
 464:     $artLang = new cApiArticleLanguage();
 465:     if (!$artLang->loadByArticleAndLanguageId($idart, $lang)) {
 466:         return;
 467:     }
 468: 
 469:     // Reverse current value
 470:     $online = ($artLang->get('online') == 0)? 1 : 0;
 471: 
 472:     $artLang->set('online', $online);
 473: 
 474:     if ($online == 1) {
 475:         // Update published date and publisher
 476:         $artLang->set('published', date('Y-m-d H:i:s'));
 477:         $artLang->set('publishedby', $auth->auth['uname']);
 478:     }
 479: 
 480:     $artLang->store();
 481: }
 482: 
 483: /**
 484:  * Set the status from articles to online or offline.
 485:  *
 486:  * @param array $idarts All articles
 487:  * @param int $idlang
 488:  * @param bool $online
 489:  */
 490: function conMakeOnlineBulkEditing($idarts, $idlang, $online) {
 491:     $auth = cRegistry::getAuth();
 492: 
 493:     // get all articles with the given idart and idlang
 494:     $idartString = implode("','", $idarts);
 495:     $artLangCollection = new cApiArticleLanguageCollection();
 496:     $artLangCollection->select("`idart` IN ('" . $idartString . "') AND `idlang`='" . cSecurity::toInteger($idlang) . "'");
 497: 
 498:     // iterate over articles and set online flag
 499:     while (($artLang = $artLangCollection->next()) !== false) {
 500:         $artLang->set('online', $online);
 501:         if ($online == 1) {
 502:             // update published date and publisher
 503:             $artLang->set('published', date('Y-m-d H:i:s'));
 504:             $artLang->set('publishedby', $auth->auth['uname']);
 505:         }
 506:         $artLang->store();
 507:     }
 508: }
 509: 
 510: /**
 511:  * Toggle the lock status of an article
 512:  *
 513:  * @param int $idart Article Id
 514:  * @param int $lang Language Id
 515:  */
 516: function conLock($idart, $lang) {
 517:     $artLang = new cApiArticleLanguage();
 518:     if (!$artLang->loadByArticleAndLanguageId($idart, $lang)) {
 519:         return;
 520:     }
 521: 
 522:     $locked = ($artLang->get('locked') == 0)? 1 : 0;
 523: 
 524:     $artLang->set('locked', $locked);
 525:     $artLang->store();
 526: }
 527: 
 528: /**
 529:  * Freeze/Lock more articles.
 530:  *
 531:  * @param array $idarts All articles
 532:  * @param int $idlang
 533:  * @param bool $lock
 534:  */
 535: function conLockBulkEditing($idarts, $idlang, $lock) {
 536:     // get all articles with the given idart and idlang
 537:     $idartString = implode("','", $idarts);
 538:     $artLangCollection = new cApiArticleLanguageCollection();
 539:     $artLangCollection->select("`idart` IN ('" . $idartString . "') AND `idlang`='" . cSecurity::toInteger($idlang) . "'");
 540: 
 541:     // iterate over articles and set online flag
 542:     while (($artLang = $artLangCollection->next()) !== false) {
 543:         $artLang->set('locked', $lock);
 544:         $artLang->store();
 545:     }
 546: }
 547: 
 548: /**
 549:  * Checks if a article is locked or not
 550:  *
 551:  * @param int $idart Article Id
 552:  * @param int $lang Language Id
 553:  * @return bool
 554:  */
 555: function conIsLocked($idart, $lang) {
 556:     $artLang = new cApiArticleLanguage();
 557:     if (!$artLang->loadByArticleAndLanguageId($idart, $lang)) {
 558:         return false;
 559:     }
 560:     return (1 == $artLang->get('locked'));
 561: }
 562: 
 563: /**
 564:  * Toggle the online status of a category
 565:  *
 566:  * @param int $idcat Id of the category
 567:  * @param int $lang Id of the language
 568:  * @param int $status Status of the category
 569:  */
 570: function conMakeCatOnline($idcat, $lang, $status) {
 571:     global $cfg;
 572: 
 573:     $catLang = new cApiCategoryLanguage();
 574:     if (!$catLang->loadByCategoryIdAndLanguageId($idcat, $lang)) {
 575:         return;
 576:     }
 577: 
 578:     $status = (1 == $status)? 1 : 0;
 579: 
 580:     $catLang->set('visible', $status);
 581:     $catLang->set('lastmodified', date('Y-m-d H:i:s'));
 582:     $catLang->store();
 583: 
 584:     if ($cfg['pathresolve_heapcache'] == true && !$status = 0) {
 585:         $oPathresolveCacheColl = new cApiPathresolveCacheCollection();
 586:         $oPathresolveCacheColl->deleteByCategoryAndLanguage($idcat, $lang);
 587:     }
 588: }
 589: 
 590: /**
 591:  * Toggle the public status of a category Almost the same function as
 592:  * strMakePublic in functions.str.php (conDeeperCategoriesArray instead of
 593:  * strDeeperCategoriesArray)
 594:  *
 595:  * @param int $idcat Category Id
 596:  * @param int $lang Language Id
 597:  * @param bool $public Public status of the Article
 598:  */
 599: function conMakePublic($idcat, $lang, $public) {
 600:     $catLang = new cApiCategoryLanguage();
 601:     if (!$catLang->loadByCategoryIdAndLanguageId($idcat, $lang)) {
 602:         return;
 603:     }
 604: 
 605:     $public = (1 == $public)? 1 : 0;
 606: 
 607:     $catLang->set('public', $public);
 608:     $catLang->set('lastmodified', date('Y-m-d H:i:s'));
 609:     $catLang->store();
 610: }
 611: 
 612: /**
 613:  * Delete an Article and all other related entries
 614:  *
 615:  * @param int $idart Article Id
 616:  */
 617: function conDeleteart($idart) {
 618:     global $lang, $_cecRegistry, $cfgClient, $client;
 619: 
 620:     // Get article language
 621:     $artLang = new cApiArticleLanguage();
 622:     if (!$artLang->loadByArticleAndLanguageId($idart, $lang)) {
 623:         return;
 624:     }
 625: 
 626:     $idartlang = $artLang->get('idartlang');
 627:     $idtplcfg = $artLang->get('idtplcfg');
 628: 
 629:     // Fetch idcat
 630:     $catArt = new cApiCategoryArticle();
 631:     $catArt->loadBy('idart', (int) $idart);
 632:     $idcat = $catArt->get('idcat');
 633: 
 634:     // Reset startidartlang
 635:     if (isStartArticle($idartlang, $idcat, $lang)) {
 636:         $catLang = new cApiCategoryLanguage();
 637:         $catLang->loadByCategoryIdAndLanguageId($idcat, $lang);
 638:         $catLang->set('startidartlang', 0);
 639:         $catLang->store();
 640:     }
 641: 
 642:     $contentColl = new cApiContentCollection();
 643:     $contentColl->deleteBy('idartlang', (int) $idartlang);
 644: 
 645:     $artLangColl = new cApiArticleLanguageCollection();
 646:     $artLangColl->delete((int) $idartlang);
 647: 
 648:     if ($idtplcfg != 0) {
 649:         $containerConfColl = new cApiContainerConfigurationCollection();
 650:         $containerConfColl->deleteBy('idtplcfg', (int) $idtplcfg);
 651: 
 652:         $tplConfColl = new cApiTemplateConfigurationCollection();
 653:         $tplConfColl->delete('idtplcfg', $idtplcfg);
 654:     }
 655: 
 656:     // Check if there are remaining languages
 657:     $artLangColl->resetQuery();
 658:     $artLangColl->select('idart = ' . (int) $idart);
 659:     if ($artLangColl->next()) {
 660:         return;
 661:     }
 662: 
 663:     $catArtColl = new cApiCategoryArticleCollection();
 664:     $catArtColl->select('idart = ' . (int) $idart);
 665:     while (($oCatArtItem = $catArtColl->next()) !== false) {
 666:         // Delete from code cache
 667:         if (cFileHandler::exists($cfgClient[$client]['code']['path'])) {
 668:             /** @var $file SplFileInfo */
 669:             foreach (new DirectoryIterator($cfgClient[$client]['code']['path']) as $file) {
 670:                 if ($file->isFile() === false) {
 671:                     continue;
 672:                 }
 673: 
 674:                 $extension = substr($file, strrpos($file->getBasename(), '.') + 1);
 675:                 if ($extension != 'php') {
 676:                     continue;
 677:                 }
 678: 
 679:                 if (preg_match('/[0-9*].[0-9*].' . $oCatArtItem->get('idcatart') . '/s', $file->getBasename())) {
 680:                     cFileHandler::remove($cfgClient[$client]['code']['path'] . '/' . $file->getFilename());
 681:                 }
 682:             }
 683:         }
 684: 
 685:         // Delete from 'stat'-table
 686:         $statColl = new cApiStatCollection();
 687:         $statColl->deleteBy('idcatart', (int) $oCatArtItem->get('idcatart'));
 688:     }
 689: 
 690:     // delete values from con_cat_art only in the correct language
 691:     $catLangColl = new cApiCategoryLanguageCollection();
 692:     $catLangColl->select('`idlang`=' . cSecurity::toInteger($lang));
 693:     $idcats = $catLangColl->getAllIds();
 694:     $idcatsString = "('" . implode(',', $idcats) . "')";
 695:     $catArtColl->resetQuery();
 696:     $catArtColl->deleteByWhereClause('`idart`=' . $idart . ' AND `idcat` IN ' . $idcatsString);
 697: 
 698: 
 699:     // delete entry from con_art
 700:     $oArtColl = new cApiArticleCollection();
 701:     $oArtColl->delete((int) $idart);
 702: 
 703:     // Contenido Extension Chain
 704:     // @see docs/techref/plugins/Contenido Extension Chainer.pdf
 705:     $iterator = $_cecRegistry->getIterator("Contenido.Content.DeleteArticle");
 706:     while (($chainEntry = $iterator->next()) !== false) {
 707:         $chainEntry->execute($idart);
 708:     }
 709: }
 710: 
 711: /**
 712:  * Extract a number from a string
 713:  *
 714:  * @param string $string String var by reference
 715:  */
 716: function extractNumber(&$string) {
 717:     $string = preg_replace('/[^0-9]/', '', $string);
 718: }
 719: 
 720: /**
 721:  * Change the template of a category
 722:  *
 723:  * @param int $idcat Category Id
 724:  * @param int $idtpl Template Id
 725:  */
 726: function conChangeTemplateForCat($idcat, $idtpl) {
 727:     global $lang;
 728: 
 729:     $oCatLang = new cApiCategoryLanguage();
 730:     if (!$oCatLang->loadByCategoryIdAndLanguageId($idcat, $lang)) {
 731:         return;
 732:     }
 733: 
 734:     if ($oCatLang->get('idtplcfg')) {
 735:         // Delete old container configuration
 736:         $oContainerConfColl = new cApiContainerConfigurationCollection();
 737:         $oContainerConfColl->deleteBy('idtplcfg', (int) $oCatLang->get('idtplcfg'));
 738: 
 739:         // Delete old template configuration
 740:         $oTplConfColl = new cApiTemplateConfigurationCollection();
 741:         $oTplConfColl->delete('idtplcfg', (int) $oCatLang->get('idtplcfg'));
 742:     }
 743: 
 744:     // Parameter $idtpl is 0, reset the template
 745:     if (0 == $idtpl) {
 746:         $oCatLang->set('idtplcfg', 0);
 747:         $oCatLang->store();
 748:     } else {
 749:         // Check if a pre-configuration is assigned
 750:         $oTpl = new cApiTemplate();
 751:         $oTpl->loadBy('idtpl', (int) $idtpl);
 752: 
 753:         if (0 != $oTpl->get('idtplcfg')) {
 754:             // Template is pre-configured, create new configuration
 755:             $oTplConfColl = new cApiTemplateConfigurationCollection();
 756:             $oTplConf = $oTplConfColl->create($idtpl);
 757: 
 758:             // If there is a preconfiguration of template, copy its settings
 759:             // into templateconfiguration
 760:             $oTplConfColl->copyTemplatePreconfiguration($idtpl, $oTplConf->get('idtplcfg'));
 761: 
 762:             // Update category language
 763:             $oCatLang->set('idtplcfg', $oTplConf->get('idtplcfg'));
 764:             $oCatLang->store();
 765:         } else {
 766:             // Template is not pre-configured, create a new configuration.
 767:             $oTplConfColl = new cApiTemplateConfigurationCollection();
 768:             $oTplConf = $oTplConfColl->create($idtpl);
 769: 
 770:             // Update category language
 771:             $oCatLang->set('idtplcfg', $oTplConf->get('idtplcfg'));
 772:             $oCatLang->store();
 773:         }
 774:     }
 775: 
 776:     conGenerateCodeForAllartsInCategory($idcat);
 777: }
 778: 
 779: /**
 780:  * Returns category tree structure.
 781:  *
 782:  * @param int $client Uses global set client if not set
 783:  * @param int $lang Uses global set language if not set
 784:  * @return array
 785:  */
 786: function conFetchCategoryTree($client = false, $lang = false) {
 787:     if ($client === false) {
 788:         $client = $GLOBALS['client'];
 789:     }
 790:     if ($lang === false) {
 791:         $lang = $GLOBALS['lang'];
 792:     }
 793: 
 794:     $oCatTreeColl = new cApiCategoryTreeCollection();
 795:     $aCatTree = $oCatTreeColl->getCategoryTreeStructureByClientIdAndLanguageId($client, $lang);
 796: 
 797:     return $aCatTree;
 798: }
 799: 
 800: /**
 801:  * Fetch all deeper categories by a given id
 802:  *
 803:  * @param int $idcat Id of category
 804:  * @return array Array with all deeper categories
 805:  */
 806: function conDeeperCategoriesArray($idcat) {
 807:     global $client;
 808: 
 809:     $oCatColl = new cApiCategoryCollection();
 810:     $aCatIds = $oCatColl->getAllCategoryIdsRecursive2($idcat, $client);
 811: 
 812:     return $aCatIds;
 813: }
 814: 
 815: /**
 816:  * Recursive function to create an location string
 817:  *
 818:  * @param int $idcat ID of the starting category
 819:  * @param string $seperator Seperation string
 820:  * @param string $catStr Category location string (by reference)
 821:  * @param bool $makeLink Create location string with links
 822:  * @param string $linkClass Stylesheet class for the links
 823:  * @param int $firstTreeElementToUse First navigation Level location string
 824:  *        should be printed out (first level = 0!!)
 825:  * @param int $uselang Id of language
 826:  * @param bool $final
 827:  * @param bool $usecache
 828:  * @return string Location string
 829:  */
 830: function conCreateLocationString($idcat, $seperator, &$catStr, $makeLink = false, $linkClass = '', $firstTreeElementToUse = 0, $uselang = 0, $final = true, $usecache = false) {
 831:     global $cfg, $client, $cfgClient, $lang, $sess;
 832: 
 833:     if ($idcat == 0) {
 834:         $catStr = i18n("Lost and found");
 835:         return;
 836:     }
 837: 
 838:     if ($uselang == 0) {
 839:         $uselang = $lang;
 840:     }
 841: 
 842:     $locationStringCache = cRegistry::getAppVar('locationStringCache');
 843:     $locationStringCacheFile = $cfgClient[$client]['cache']['path'] . "locationstring-cache-$uselang.txt";
 844: 
 845:     if ($final == true && $usecache == true) {
 846:         if (!is_array($locationStringCache)) {
 847:             if (cFileHandler::exists($locationStringCacheFile)) {
 848:                 $locationStringCache = unserialize(cFileHandler::read($locationStringCacheFile));
 849:             } else {
 850:                 $locationStringCache = array();
 851:             }
 852:             cRegistry::setAppVar('locationStringCache', $locationStringCache);
 853:         }
 854: 
 855:         if (array_key_exists($idcat, $locationStringCache)) {
 856:             if ($locationStringCache[$idcat]['expires'] > time()) {
 857:                 $catStr = $locationStringCache[$idcat]['name'];
 858:                 return;
 859:             }
 860:         }
 861:     }
 862: 
 863:     $db = cRegistry::getDb();
 864: 
 865:     $sql = "SELECT a.name AS name, a.idcat AS idcat, b.parentid AS parentid, c.level as level " . "FROM `:cat_lang` AS a, `:cat` AS b, `:cat_tree` AS c " . "WHERE a.idlang = :idlang AND b.idclient = :idclient AND b.idcat = :idcat AND a.idcat = b.idcat AND c.idcat = b.idcat";
 866: 
 867:     $sql = $db->prepare($sql, array(
 868:         'cat_lang' => $cfg['tab']['cat_lang'],
 869:         'cat' => $cfg['tab']['cat'],
 870:         'cat_tree' => $cfg['tab']['cat_tree'],
 871:         'idlang' => (int) $uselang,
 872:         'idclient' => (int) $client,
 873:         'idcat' => (int) $idcat
 874:     ));
 875:     $db->query($sql);
 876:     $db->nextRecord();
 877: 
 878:     if ($db->f('level') >= $firstTreeElementToUse) {
 879:         $name = $db->f('name');
 880:         $parentid = $db->f('parentid');
 881: 
 882:         // create link
 883:         if ($makeLink == true) {
 884:             $linkUrl = $sess->url("front_content.php?idcat=$idcat");
 885:             $name = '<a href="' . $linkUrl . '" class="' . $linkClass . '">' . $name . '</a>';
 886:         }
 887: 
 888:         $tmp_cat_str = $name . $seperator . $catStr;
 889:         $catStr = $tmp_cat_str;
 890:     }
 891: 
 892:     if ($parentid != 0) {
 893:         conCreateLocationString($parentid, $seperator, $catStr, $makeLink, $linkClass, $firstTreeElementToUse, $uselang, false);
 894:     } else {
 895:         $sep_length = strlen($seperator);
 896:         $str_length = strlen($catStr);
 897:         $tmp_length = $str_length - $sep_length;
 898:         $catStr = substr($catStr, 0, $tmp_length);
 899:     }
 900: 
 901:     if ($final == true && $usecache == true) {
 902:         $locationStringCache[$idcat]['name'] = $catStr;
 903:         $locationStringCache[$idcat]['expires'] = time() + 3600;
 904: 
 905:         if (is_writable($cfgClient[$client]['cache']['path'])) {
 906:             cFileHandler::write($locationStringCacheFile, serialize($locationStringCache));
 907:         }
 908:         cRegistry::setAppVar('locationStringCache', $locationStringCache);
 909:     }
 910: }
 911: 
 912: /**
 913:  * Set a start-article @fixme Do we still need the isstart.
 914:  * The old start
 915:  * compatibility has already been removed...
 916:  *
 917:  * @param int $idcatart Idcatart of the article
 918:  * @param bool $isstart Start article flag
 919:  */
 920: function conMakeStart($idcatart, $isstart) {
 921:     global $lang;
 922: 
 923:     // Load category article
 924:     $oCatArt = new cApiCategoryArticle((int) $idcatart);
 925:     if (!$oCatArt->isLoaded()) {
 926:         return;
 927:     }
 928:     $idart = $oCatArt->get('idart');
 929:     $idcat = $oCatArt->get('idcat');
 930: 
 931:     // Load article language
 932:     $oArtLang = new cApiArticleLanguage();
 933:     if (!$oArtLang->loadByArticleAndLanguageId($idart, $lang)) {
 934:         return;
 935:     }
 936:     $idartlang = $oArtLang->get('idartlang');
 937: 
 938:     // Update startidartlang for category language
 939:     $oCatLang = new cApiCategoryLanguage();
 940:     if ($oCatLang->loadByCategoryIdAndLanguageId($idcat, $lang)) {
 941:         if ($isstart == 1) {
 942:             $oCatLang->set('startidartlang', $idartlang);
 943:         } else {
 944:             $oCatLang->set('startidartlang', 0);
 945:         }
 946:         $oCatLang->store();
 947:     }
 948: 
 949:     if ($isstart == 1) {
 950:         // Deactivate time management if article is a start article
 951:         $oArtLang->set('timemgmt', 0);
 952:         $oArtLang->store();
 953:     }
 954: }
 955: 
 956: /**
 957:  * Create code for one article in all categorys
 958:  *
 959:  * @param int $idart Article ID
 960:  */
 961: function conGenerateCodeForArtInAllCategories($idart) {
 962:     $oCatArtColl = new cApiCategoryArticleCollection();
 963:     $ids = $oCatArtColl->getIdsByWhereClause('idart = ' . (int) $idart);
 964:     conSetCodeFlagBulkEditing($ids);
 965: }
 966: 
 967: /**
 968:  * Generate code for all articles in a category
 969:  *
 970:  * @param int $idcat Category ID
 971:  */
 972: function conGenerateCodeForAllArtsInCategory($idcat) {
 973:     $oCatArtColl = new cApiCategoryArticleCollection();
 974:     $ids = $oCatArtColl->getIdsByWhereClause('idcat = ' . (int) $idcat);
 975:     conSetCodeFlagBulkEditing($ids);
 976: }
 977: 
 978: /**
 979:  * Generate code for the active client
 980:  */
 981: function conGenerateCodeForClient() {
 982:     global $client;
 983:     $oCatArtColl = new cApiCategoryArticleCollection();
 984:     $ids = $oCatArtColl->getAllIdsByClientId($client);
 985:     conSetCodeFlagBulkEditing($ids);
 986: }
 987: 
 988: /**
 989:  * Create code for all arts using the same layout
 990:  *
 991:  * @param int $idlay Layout-ID
 992:  */
 993: function conGenerateCodeForAllartsUsingLayout($idlay) {
 994:     global $cfg;
 995: 
 996:     $db = cRegistry::getDb();
 997: 
 998:     $sql = "SELECT idtpl FROM " . $cfg["tab"]["tpl"] . " WHERE idlay='" . cSecurity::toInteger($idlay) . "'";
 999:     $db->query($sql);
1000:     while ($db->nextRecord()) {
1001:         conGenerateCodeForAllartsUsingTemplate($db->f("idtpl"));
1002:     }
1003: }
1004: 
1005: /**
1006:  * Create code for all articles using the same module
1007:  *
1008:  * @param int $idmod Module id
1009:  */
1010: function conGenerateCodeForAllartsUsingMod($idmod) {
1011:     $oContainerColl = new cApiContainerCollection();
1012:     $rsList = $oContainerColl->getFieldsByWhereClause(array(
1013:         'idtpl'
1014:     ), 'idmod = ' . (int) $idmod);
1015:     foreach ($rsList as $rs) {
1016:         conGenerateCodeForAllArtsUsingTemplate($rs['idtpl']);
1017:     }
1018: }
1019: 
1020: /**
1021:  * Generate code for all articles using one template
1022:  *
1023:  * @param int $idtpl Template-Id
1024:  */
1025: function conGenerateCodeForAllArtsUsingTemplate($idtpl) {
1026:     global $cfg, $client;
1027: 
1028:     $db = cRegistry::getDb();
1029: 
1030:     $oCatArtColl = new cApiCategoryArticleCollection();
1031: 
1032:     // Search all categories
1033:     $sql = "SELECT
1034:                 b.idcat
1035:             FROM
1036:                 " . $cfg['tab']['tpl_conf'] . " AS a,
1037:                 " . $cfg['tab']['cat_lang'] . " AS b,
1038:                 " . $cfg['tab']['cat'] . " AS c
1039:             WHERE
1040:                 a.idtpl     = " . cSecurity::toInteger($idtpl) . " AND
1041:                 b.idtplcfg  = a.idtplcfg AND
1042:                 c.idclient  = " . cSecurity::toInteger($client) . " AND
1043:                 b.idcat     = c.idcat";
1044: 
1045:     $db->query($sql);
1046: 
1047:     while ($db->nextRecord()) {
1048:         $oCatArtColl->resetQuery();
1049:         $ids = $oCatArtColl->getIdsByWhereClause('idcat = ' . cSecurity::toInteger($db->f('idcat')));
1050:         foreach ($ids as $id) {
1051:             conSetCodeFlag($id);
1052:         }
1053:     }
1054: 
1055:     // Search all articles
1056:     $sql = "SELECT
1057:                 b.idart
1058:             FROM
1059:                 " . $cfg['tab']['tpl_conf'] . " AS a,
1060:                 " . $cfg['tab']['art_lang'] . " AS b,
1061:                 " . $cfg['tab']['art'] . " AS c
1062:             WHERE
1063:                 a.idtpl     = " . cSecurity::toInteger($idtpl) . " AND
1064:                 b.idtplcfg  = a.idtplcfg AND
1065:                 c.idclient  = " . cSecurity::toInteger($client) . " AND
1066:                 b.idart     = c.idart";
1067: 
1068:     $db->query($sql);
1069: 
1070:     while ($db->nextRecord()) {
1071:         $oCatArtColl->resetQuery();
1072:         $ids = $oCatArtColl->getIdsByWhereClause('idart = ' . (int) $db->f('idart'));
1073:         foreach ($ids as $id) {
1074:             conSetCodeFlag($id);
1075:         }
1076:     }
1077: }
1078: 
1079: /**
1080:  * Create code for all articles
1081:  */
1082: function conGenerateCodeForAllArts() {
1083:     global $cfg;
1084: 
1085:     $db = cRegistry::getDb();
1086: 
1087:     $sql = "SELECT idcatart FROM " . $cfg['tab']['cat_art'];
1088:     $db->query($sql);
1089:     while ($db->nextRecord()) {
1090:         conSetCodeFlag($db->f("idcatart"));
1091:     }
1092: }
1093: 
1094: /**
1095:  * Set code creation flag for one category article id to true
1096:  *
1097:  * @param int $idcatart Category article id
1098:  */
1099: function conSetCodeFlag($idcatart) {
1100:     global $client, $cfgClient;
1101: 
1102:     // Set 'createcode' flag
1103:     $oCatArtColl = new cApiCategoryArticleCollection();
1104:     $oCatArtColl->setCreateCodeFlag($idcatart);
1105: 
1106:     // Delete also generated code files from file system
1107:     if (cFileHandler::exists($cfgClient[$client]['code']['path'])) {
1108:         /** @var $file SplFileInfo */
1109:         foreach (new DirectoryIterator($cfgClient[$client]['code']['path']) as $file) {
1110:             if ($file->isFile() === false) {
1111:                 continue;
1112:             }
1113: 
1114:             $extension = substr($file, strrpos($file->getBasename(), '.') + 1);
1115:             if ($extension != 'php') {
1116:                 continue;
1117:             }
1118: 
1119:             if (preg_match('/[0-9*].[0-9*].' . $idcatart . '/s', $file->getBasename())) {
1120:                 cFileHandler::remove($cfgClient[$client]['code']['path'] . '/' . $file->getFilename());
1121:             }
1122:         }
1123:     }
1124: }
1125: 
1126: /**
1127:  * Set code creation flag for several category article ids to true
1128:  *
1129:  * @param array $idcatarts List of category article ids
1130:  */
1131: function conSetCodeFlagBulkEditing(array $idcatarts) {
1132:     global $client, $cfgClient;
1133: 
1134:     if (count($idcatarts) == 0) {
1135:         return;
1136:     }
1137: 
1138:     // Set 'createcode' flag
1139:     $oCatArtColl = new cApiCategoryArticleCollection();
1140:     $oCatArtColl->setCreateCodeFlag($idcatarts);
1141: 
1142:     if (cFileHandler::exists($cfgClient[$client]['code']['path']) === false) {
1143:         return;
1144:     }
1145: 
1146:     // Delete also generated code files from file system
1147:     foreach ($idcatarts as $id) {
1148:         /** @var $file SplFileInfo */
1149:         foreach (new DirectoryIterator($cfgClient[$client]['code']['path']) as $file) {
1150:             if ($file->isFile() === false) {
1151:                 continue;
1152:             }
1153: 
1154:             $extension = substr($file, strrpos($file->getBasename(), '.') + 1);
1155:             if ($extension != 'php') {
1156:                 continue;
1157:             }
1158: 
1159:             if (preg_match('/[0-9*].[0-9*].' . $id . '/s', $file->getBasename())) {
1160:                 cFileHandler::remove($cfgClient[$client]['code']['path'] . '/' . $file->getFilename());
1161:             }
1162:         }
1163:     }
1164: }
1165: 
1166: /**
1167:  * Set articles on/offline for the time management function
1168:  */
1169: function conFlagOnOffline() {
1170:     global $cfg;
1171: 
1172:     $db = cRegistry::getDb();
1173: 
1174:     $oArtLangColl = new cApiArticleLanguageCollection();
1175: 
1176:     // Set all articles which are before our starttime to offline
1177:     $where = "NOW() < datestart AND datestart != '0000-00-00 00:00:00' AND datestart IS NOT NULL AND timemgmt = 1";
1178:     $ids = $oArtLangColl->getIdsByWhereClause($where);
1179:     foreach ($ids as $id) {
1180:         $sql = "UPDATE " . $cfg['tab']['art_lang'] . " SET online = 0 WHERE idartlang = " . (int) $id;
1181:         $db->query($sql);
1182:     }
1183: 
1184:     // Set all articles which are in between of our start/endtime to online
1185:     $where = "NOW() > datestart AND (NOW() < dateend OR dateend = '0000-00-00 00:00:00') AND " . "online = 0 AND timemgmt = 1";
1186:     $oArtLangColl->resetQuery();
1187:     $ids = $oArtLangColl->getIdsByWhereClause($where);
1188:     foreach ($ids as $id) {
1189:         $sql = "UPDATE " . $cfg['tab']['art_lang'] . " SET online = 1, published = datestart WHERE idartlang = " . (int) $id;
1190:         $db->query($sql);
1191:     }
1192: 
1193:     // Set all articles after our endtime to offline
1194:     $where = "NOW() > dateend AND dateend != '0000-00-00 00:00:00' AND timemgmt = 1";
1195:     $oArtLangColl->resetQuery();
1196:     $ids = $oArtLangColl->getIdsByWhereClause($where);
1197:     foreach ($ids as $id) {
1198:         $sql = "UPDATE " . $cfg['tab']['art_lang'] . " SET online = 0 WHERE idartlang = " . (int) $id;
1199:         $db->query($sql);
1200:     }
1201: }
1202: 
1203: /**
1204:  * Move articles for the time management function
1205:  */
1206: function conMoveArticles() {
1207:     global $cfg;
1208: 
1209:     $db = cRegistry::getDb();
1210: 
1211:     // Perform after-end updates
1212:     $fields = array(
1213:         'idartlang',
1214:         'idart',
1215:         'time_move_cat',
1216:         'time_target_cat',
1217:         'time_online_move'
1218:     );
1219:     $where = "NOW() > dateend AND dateend != '0000-00-00 00:00:00' AND timemgmt = 1 AND time_move_cat = 1";
1220:     $oArtLangColl = new cApiArticleLanguageCollection();
1221:     $rsList = $oArtLangColl->getFieldsByWhereClause($fields, $where);
1222: 
1223:     foreach ($rsList as $rs) {
1224:         $online = ($rs['time_online_move'] == '1')? 1 : 0;
1225:         $sql = array();
1226:         $sql[] = 'UPDATE ' . $cfg['tab']['art_lang'] . ' SET timemgmt = 0, online = 0 WHERE idartlang = ' . (int) $rs['idartlang'] . ';';
1227:         $sql[] = 'UPDATE ' . $cfg['tab']['cat_art'] . ' SET idcat = ' . (int) $rs['time_target_cat'] . ', createcode = 1 WHERE idart = ' . (int) $rs['idart'] . ';';
1228:         $sql[] = 'UPDATE ' . $cfg['tab']['art_lang'] . ' SET online = ' . (int) $online . ' WHERE idart = ' . (int) $rs['idart'] . ';';
1229: 
1230:         $sql = implode("\n", $sql);
1231:         $db->query($sql);
1232: 
1233:         // Execute CEC hook
1234:         cApiCecHook::execute('Contenido.Article.conMoveArticles_Loop', $rs);
1235:     }
1236: }
1237: 
1238: /**
1239:  * Copies template configuration entry from source template configuration.
1240:  *
1241:  * @param int $srcidtplcfg
1242:  */
1243: function conCopyTemplateConfiguration($srcidtplcfg) {
1244:     $oTemplateConf = new cApiTemplateConfiguration((int) $srcidtplcfg);
1245:     if (!$oTemplateConf->isLoaded()) {
1246:         return null;
1247:     }
1248: 
1249:     $oTemplateConfColl = new cApiTemplateConfigurationCollection();
1250:     $oNewTemplateConf = $oTemplateConfColl->create($oTemplateConf->get('idtpl'));
1251:     return (is_object($oNewTemplateConf))? $oNewTemplateConf->get('idtplcfg') : null;
1252: }
1253: 
1254: /**
1255:  * Copies container configuration entries from source container configuration to
1256:  * destination container configuration.
1257:  *
1258:  * @param int $srcidtplcfg
1259:  * @param int $dstidtplcfg
1260:  */
1261: function conCopyContainerConf($srcidtplcfg, $dstidtplcfg) {
1262:     $counter = 0;
1263:     $oContainerConfColl = new cApiContainerConfigurationCollection();
1264:     $oContainerConfColl->select('idtplcfg = ' . cSecurity::toInteger($srcidtplcfg));
1265:     while (($oContainerConf = $oContainerConfColl->next()) !== false) {
1266:         $oNewContainerConfColl = new cApiContainerConfigurationCollection();
1267:         $oNewContainerConfColl->copyItem($oContainerConf, array(
1268:             'idtplcfg' => cSecurity::toInteger($dstidtplcfg)
1269:         ));
1270:         $counter++;
1271:     }
1272:     return ($counter > 0)? true : false;
1273: }
1274: 
1275: /**
1276:  * Copies content entries from source article language to destination article
1277:  * language.
1278:  *
1279:  * @param int $srcidartlang
1280:  * @param int $dstidartlang
1281:  */
1282: function conCopyContent($srcidartlang, $dstidartlang) {
1283:     $oContentColl = new cApiContentCollection();
1284:     $oContentColl->select('idartlang = ' . cSecurity::toInteger($srcidartlang));
1285:     while (($oContent = $oContentColl->next()) !== false) {
1286:         $oNewContentColl = new cApiContentCollection();
1287:         $oNewContentColl->copyItem($oContent, array(
1288:             'idartlang' => cSecurity::toInteger($dstidartlang)
1289:         ));
1290:     }
1291: }
1292: 
1293: /**
1294:  * Copies meta tag entries from source article language to destination article
1295:  * language.
1296:  *
1297:  * @param int $srcidartlang
1298:  * @param int $dstidartlang
1299:  */
1300: function conCopyMetaTags($srcidartlang, $dstidartlang) {
1301:     $oMetaTagColl = new cApiMetaTagCollection();
1302:     $oMetaTagColl->select('idartlang = ' . cSecurity::toInteger($srcidartlang));
1303:     while (($oMetaTag = $oMetaTagColl->next()) !== false) {
1304:         $oNewMetaTagColl = new cApiMetaTagCollection();
1305:         $oNewMetaTagColl->copyItem($oMetaTag, array(
1306:             'idartlang' => cSecurity::toInteger($dstidartlang)
1307:         ));
1308:     }
1309: }
1310: 
1311: /**
1312:  * Copy article language entry.
1313:  *
1314:  * @global array $cfg
1315:  * @global int $lang
1316:  * @param int $srcidart
1317:  * @param int $dstidart
1318:  * @param int $newtitle
1319:  * @param int $useCopyLabel
1320:  */
1321: function conCopyArtLang($srcidart, $dstidart, $newtitle, $useCopyLabel = true) {
1322:     global $auth, $lang;
1323: 
1324:     $oSrcArtLang = new cApiArticleLanguage();
1325:     if (!$oSrcArtLang->loadByArticleAndLanguageId($srcidart, $lang)) {
1326:         return;
1327:     }
1328: 
1329:     // Copy the template configuration
1330:     if ($oSrcArtLang->get('idtplcfg') != 0) {
1331:         $newidtplcfg = conCopyTemplateConfiguration($oSrcArtLang->get('idtplcfg'));
1332:         conCopyContainerConf($oSrcArtLang->get('idtplcfg'), $newidtplcfg);
1333:     }
1334: 
1335:     $idart = $dstidart;
1336:     $idlang = $oSrcArtLang->get('idlang');
1337:     $idtplcfg = $newidtplcfg;
1338: 
1339:     if ($newtitle != '') {
1340:         $title = sprintf($newtitle, $oSrcArtLang->get('title'));
1341:     } else if ($useCopyLabel == true) {
1342:         $title = sprintf(i18n('%s (Copy)'), $oSrcArtLang->get('title'));
1343:     } else {
1344:         $title = $oSrcArtLang->get('title');
1345:     }
1346: 
1347:     // Create an article language entry
1348:     $oArtLangColl = new cApiArticleLanguageCollection();
1349:     $fieldsToOverwrite = array(
1350:         'idart' => $idart,
1351:         'idlang' => $idlang,
1352:         'idtplcfg' => cSecurity::toInteger($idtplcfg),
1353:         'online' => 0,
1354:         'title' => $title,
1355:         'created' => date('Y-m-d H:i:s'),
1356:         'lastmodified' => date('Y-m-d H:i:s'),
1357:         'modifiedby' => $auth->auth['uname'],
1358:         'published' => '',
1359:         'publishedby' => ''
1360:     );
1361:     $oNewArtLang = $oArtLangColl->copyItem($oSrcArtLang, $fieldsToOverwrite);
1362: 
1363:     if (!is_object($oNewArtLang)) {
1364:         return;
1365:     }
1366: 
1367:     // Copy content
1368:     conCopyContent($oSrcArtLang->get('idartlang'), $oNewArtLang->get('idartlang'));
1369: 
1370:     // Copy meta tags
1371:     conCopyMetaTags($oSrcArtLang->get('idartlang'), $oNewArtLang->get('idartlang'));
1372: 
1373:     // Execute CEC hook
1374:     cApiCecHook::execute('Contenido.Article.conCopyArtLang_AfterInsert', array(
1375:         'idartlang' => cSecurity::toInteger($oNewArtLang->get('idartlang')),
1376:         'idart' => cSecurity::toInteger($idart),
1377:         'idlang' => cSecurity::toInteger($idlang),
1378:         'idtplcfg' => cSecurity::toInteger($idtplcfg),
1379:         'title' => $title
1380:     ));
1381: 
1382:     // Update keyword list for new article
1383:     conMakeArticleIndex($oNewArtLang->get('idartlang'), $idart);
1384: }
1385: 
1386: /**
1387:  * Copy article entry.
1388:  *
1389:  * @global object $auth
1390:  * @param int $srcidart
1391:  * @param int $targetcat
1392:  * @param string $newtitle
1393:  * @param bool $useCopyLabel
1394:  * @return bool
1395:  */
1396: function conCopyArticle($srcidart, $targetcat = 0, $newtitle = '', $useCopyLabel = true) {
1397:     // Get source article
1398:     $oSrcArt = new cApiArticle((int) $srcidart);
1399:     if (!$oSrcArt->isLoaded()) {
1400:         return false;
1401:     }
1402:     $idclient = $oSrcArt->get('idclient');
1403: 
1404:     // Create destination article
1405:     $oArtCollection = new cApiArticleCollection();
1406:     $oNewArt = $oArtCollection->create($idclient);
1407:     if (!is_object($oNewArt)) {
1408:         return false;
1409:     }
1410:     $dstidart = $oNewArt->get('idart');
1411: 
1412:     conCopyArtLang($srcidart, $dstidart, $newtitle, $useCopyLabel);
1413: 
1414:     // Get source category article entries
1415:     $oCatArtColl = new cApiCategoryArticleCollection();
1416:     $oCatArtColl->select('idart = ' . (int) $srcidart);
1417:     while (($oCatArt = $oCatArtColl->next()) !== false) {
1418:         // Insert destination category article entry
1419:         $oCatArtColl2 = new cApiCategoryArticleCollection();
1420:         $fieldsToOverwrite = array(
1421:             'idcat' => ($targetcat != 0)? $targetcat : $oCatArt->get('idcat'),
1422:             'idart' => $dstidart,
1423:             'status' => ($oCatArt->get('status') !== '')? $oCatArt->get('status') : 0,
1424:             'createcode' => 1,
1425:             'is_start' => 0
1426:         );
1427:         $oCatArtColl2->copyItem($oCatArt, $fieldsToOverwrite);
1428: 
1429:         // If true, exit while routine, only one category entry is needed
1430:         if ($targetcat != 0) {
1431:             break;
1432:         }
1433:     }
1434: 
1435:     // Contenido Extension Chain
1436:     // @see docs/techref/plugins/Contenido Extension Chainer.pdf
1437:     $_cecRegistry = cApiCecRegistry::getInstance();
1438:     $iterator = $_cecRegistry->getIterator('Contenido.Content.CopyArticle');
1439:     while (($chainEntry = $iterator->next()) !== false) {
1440:         $chainEntry->execute($srcidart, $dstidart);
1441:     }
1442: 
1443:     return $dstidart;
1444: }
1445: 
1446: /**
1447:  *
1448:  * @todo Returns something....
1449:  * @global array $cfg
1450:  * @global int $client
1451:  * @global int $lang
1452:  * @param int $idcat
1453:  * @param int $minLevel
1454:  * @return int
1455:  */
1456: function conGetTopmostCat($idcat, $minLevel = 0) {
1457:     global $cfg, $client, $lang;
1458: 
1459:     $db = cRegistry::getDb();
1460: 
1461:     $sql = "SELECT a.name AS name, a.idcat AS idcat, b.parentid AS parentid, c.level AS level
1462:             FROM `:cat_lang` AS a, `:cat` AS b, `:cat_tree` AS c
1463:             WHERE a.idlang = :idlang AND b.idclient = :idclient AND b.idcat = :idcat
1464:             AND c.idcat = b.idcat AND a.idcat = b.idcat";
1465: 
1466:     $sql = $db->prepare($sql, array(
1467:         'cat_lang' => $cfg['tab']['cat_lang'],
1468:         'cat' => $cfg['tab']['cat'],
1469:         'cat_tree' => $cfg['tab']['cat_tree'],
1470:         'idlang' => (int) $lang,
1471:         'idclient' => (int) $client,
1472:         'idcat' => (int) $idcat
1473:     ));
1474:     $db->query($sql);
1475:     $db->nextRecord();
1476: 
1477:     $name = $db->f('name');
1478:     $parentid = $db->f('parentid');
1479:     $thislevel = $db->f('level');
1480: 
1481:     if ($parentid != 0 && $thislevel >= $minLevel) {
1482:         return conGetTopmostCat($parentid, $minLevel);
1483:     } else {
1484:         return $idcat;
1485:     }
1486: }
1487: 
1488: /**
1489:  * Synchronizes an article from source language to destination language.
1490:  *
1491:  * @param int $idart Article id
1492:  * @param int $srclang Source language id
1493:  * @param int $dstlang Destination language id
1494:  * @return void
1495:  */
1496: function conSyncArticle($idart, $srclang, $dstlang) {
1497:     $auth = cRegistry::getAuth();
1498: 
1499:     // Check if article has already been synced to target language
1500:     $dstArtLang = new cApiArticleLanguage();
1501:     $dstArtLang->loadByArticleAndLanguageId($idart, $dstlang);
1502:     if ($dstArtLang->isLoaded()) {
1503:         // Article already exists in detination language
1504:         return;
1505:     }
1506: 
1507:     $srcArtLang = new cApiArticleLanguage();
1508:     $srcArtLang->loadByArticleAndLanguageId($idart, $srclang);
1509:     if (!$srcArtLang->isLoaded()) {
1510:         // Couldn't load article in source language
1511:         return;
1512:     }
1513:     $srcidartlang = $srcArtLang->get('idartlang');
1514: 
1515:     if ($srcArtLang->get('idtplcfg') != 0) {
1516:         $newidtplcfg = tplcfgDuplicate($srcArtLang->get('idtplcfg'));
1517:     } else {
1518:         $newidtplcfg = 0;
1519:     }
1520: 
1521:     // Create an article language entry for destination language
1522:     $artLangColl = new cApiArticleLanguageCollection();
1523:     $fieldsToOverwrite = array(
1524:         'idart' => $idart,
1525:         'idlang' => $dstlang,
1526:         'artspec' => 0,
1527:         'online' => 0,
1528:         'created' => date('Y-m-d H:i:s'),
1529:         'lastmodified' => date('Y-m-d H:i:s'),
1530:         'modifiedby' => $auth->auth['uname'],
1531:         'published' => '',
1532:         'publishedby' => '',
1533:         'timemgmt' => 0,
1534:         'datestart' => '',
1535:         'dateend' => '',
1536:         'status' => 0,
1537:         'time_move_cat' => 0,
1538:         'time_target_cat' => 0,
1539:         'time_online_move' => 0,
1540:         'free_use_01' => '',
1541:         'free_use_02' => '',
1542:         'free_use_03' => ''
1543:     );
1544:     $artLang = $artLangColl->copyItem($srcArtLang, $fieldsToOverwrite);
1545:     if (!is_object($artLang)) {
1546:         return;
1547:     }
1548: 
1549:     $newidartlang = $artLang->get('idartlang');
1550: 
1551:     // Execute CEC hook
1552:     $param = array();
1553:     $param['src_art_lang'] = $srcArtLang->toArray();
1554:     $param['dest_art_lang'] = $dstArtLang->toArray();
1555:     $param['dest_art_lang']['idartlang'] = cSecurity::toInteger($newidartlang);
1556:     $param['dest_art_lang']['idlang'] = cSecurity::toInteger($dstlang);
1557:     $param['dest_art_lang']['idtplcfg'] = cSecurity::toInteger($newidtplcfg);
1558:     cApiCecHook::execute('Contenido.Article.conSyncArticle_AfterInsert', $param);
1559: 
1560:     // Copy content
1561:     conCopyContent($srcidartlang, $newidartlang);
1562: 
1563:     // Copy meta tags
1564:     conCopyMetaTags($srcidartlang, $newidartlang);
1565: }
1566: 
1567: /**
1568:  * Checks if an article is a start article of a category.
1569:  *
1570:  * @param int $idartlang
1571:  * @param int $idcat
1572:  * @param int $idlang
1573:  * @param cDb|null $db (NOT used)
1574:  * @return bool
1575:  */
1576: function isStartArticle($idartlang, $idcat, $idlang, $db = null) {
1577:     $oCatLangColl = new cApiCategoryLanguageCollection();
1578:     return $oCatLangColl->isStartArticle($idartlang, $idcat, $idlang);
1579: }
1580: 
1581: /**
1582:  * Returns all categories in which the given article is in.
1583:  *
1584:  * @param int $idart Article ID
1585:  * @param cDb|null $db If specified, uses the given db object (NOT used)
1586:  * @return array Flat array which contains all category id's
1587:  */
1588: function conGetCategoryAssignments($idart, $db = null) {
1589:     $categories = array();
1590:     $oCatArtColl = new cApiCategoryArticleCollection();
1591:     $entries = $oCatArtColl->getFieldsByWhereClause(array(
1592:         'idcat'
1593:     ), 'idart = ' . (int) $idart);
1594:     foreach ($entries as $entry) {
1595:         $categories[] = $entry['idcat'];
1596:     }
1597:     return $categories;
1598: }
1599: 
1600: /**
1601:  * Deletes old category article entries and other related entries from other
1602:  * tables.
1603:  *
1604:  * @global array $cfgClient
1605:  * @param int $idcat
1606:  * @param int $idart
1607:  * @param int $idartlang
1608:  * @param int $client
1609:  * @param int $lang
1610:  */
1611: function conRemoveOldCategoryArticle($idcat, $idart, $idartlang, $client, $lang) {
1612:     global $cfgClient;
1613: 
1614:     // Get category article that will no longer exist
1615:     $oCatArtColl = new cApiCategoryArticleCollection();
1616:     $oCatArt = $oCatArtColl->fetchByCategoryIdAndArticleId($idcat, $idart);
1617:     if (!is_object($oCatArt)) {
1618:         return;
1619:     }
1620: 
1621:     $idcatart = $oCatArt->get('idcatart');
1622: 
1623:     // Delete frome code cache and delete corresponding code
1624:     /** @var $file SplFileInfo */
1625:     foreach (new DirectoryIterator($cfgClient[$client]['code']['path']) as $file) {
1626:         if ($file->isFile() === false) {
1627:             continue;
1628:         }
1629: 
1630:         $extension = substr($file, strrpos($file->getBasename(), '.') + 1);
1631:         if ($extension != 'php') {
1632:             continue;
1633:         }
1634: 
1635:         if (preg_match('/[0-9*].[0-9*].' . $idcatart . '/s', $file->getBasename())) {
1636:             cFileHandler::remove($cfgClient[$client]['code']['path'] . '/' . $file->getFilename());
1637:         }
1638:     }
1639: 
1640:     // Delete statistics
1641:     $oStatColl = new cApiStatCollection();
1642:     $oStatColl->deleteByCategoryArticleAndLanguage($idcatart, $lang);
1643: 
1644:     // Delete category article
1645:     $oCatArtColl->delete($idcatart);
1646: 
1647:     // Remove startidartlang
1648:     if (isStartArticle($idartlang, $idcat, $lang)) {
1649:         $oCatLang = new cApiCategoryLanguage();
1650:         $oCatLang->loadByCategoryIdAndLanguageId($idcat, $lang);
1651:         if ($oCatLang->isLoaded()) {
1652:             $oCatLang->set('startidartlang', 0);
1653:             $oCatLang->store();
1654:         }
1655:     }
1656: 
1657:     // Delete template configuration
1658:     $oArtLang = new cApiArticleLanguage();
1659:     $oArtLang->loadByArticleAndLanguageId($idart, $lang);
1660:     if ($oArtLang->isLoaded() && $oArtLang->get('idtplcfg') > 0) {
1661:         $oTplCfgColl = new cApiTemplateConfigurationCollection();
1662:         $oTplCfgColl->delete($oArtLang->get('idtplcfg'));
1663:     }
1664: }
1665: 
1666: ?>
CMS CONTENIDO 4.9.0 API documentation generated by ApiGen 2.8.0