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
  • UploadSearchResultList

Functions

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