Overview

Packages

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

Classes

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

Functions

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