Overview

Packages

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

Classes

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

Functions

  • _getCurrentTypes
  • _processCmsTags
  • addArtspec
  • addslashes_deep
  • addSortImages
  • backToMainArea
  • buildArticleSelect
  • buildCategorySelect
  • buildCategorySelectRights
  • buildHeapTable
  • buildStackString
  • buildTree
  • buildUserOrGroupPermsFromRequest
  • callPluginStore
  • cApiCatGetLevelNode
  • cApiImageCheckCachedImageValidity
  • cApiImageCheckImageEditingPosibility
  • cApiImageGetCacheFileName
  • cApiImageGetTargetDimensions
  • cApiImageIsAnimGif
  • cApiImgScale
  • cApiImgScaleGetMD5CacheFile
  • cApiImgScaleHQ
  • cApiImgScaleImageMagick
  • cApiImgScaleLQ
  • cApiIsImageMagickAvailable
  • cApiStrCleanURLCharacters
  • cApiStrNormalizeLineEndings
  • cApiStrRecodeString
  • cApiStrReplaceDiacritics
  • cApiStrTrimAfterWord
  • cApiStrTrimHard
  • cApiStrTrimSentence
  • cDeprecated
  • cDie
  • cError
  • checkLangInClients
  • checkPathInformation
  • cInclude
  • compareUrlStrings
  • conChangeTemplateForCat
  • conCopyArticle
  • conCopyArtLang
  • conCopyContainerConf
  • conCopyContent
  • conCopyMetaTags
  • conCopyTemplateConfiguration
  • conCreateLocationString
  • conDeeperCategoriesArray
  • conDeleteart
  • conEditArt
  • conEditFirstTime
  • conFetchCategoryTree
  • conFlagOnOffline
  • conGenerateCode
  • conGenerateCodeForAllArts
  • conGenerateCodeForAllArtsInCategory
  • conGenerateCodeForAllartsUsingLayout
  • conGenerateCodeForAllartsUsingMod
  • conGenerateCodeForAllArtsUsingTemplate
  • conGenerateCodeForArtInAllCategories
  • conGenerateCodeForClient
  • conGenerateKeywords
  • conGetAvailableMetaTagTypes
  • conGetCategoryArticleId
  • conGetCategoryAssignments
  • conGetContainerConfiguration
  • conGetContentFromArticle
  • conGetHtmlTranslationTable
  • conGetMetaValue
  • conGetTemplateConfigurationIdForArticle
  • conGetTemplateConfigurationIdForCategory
  • conGetTopmostCat
  • conGetUsedModules
  • conHtmlentities
  • conHtmlEntityDecode
  • conHtmlSpecialChars
  • conIsLocked
  • conLock
  • conLockBulkEditing
  • conMakeArticleIndex
  • conMakeCatOnline
  • conMakeInlineScript
  • conMakeOnline
  • conMakeOnlineBulkEditing
  • conMakePublic
  • conMakeStart
  • conMoveArticles
  • conPhp54Check
  • conRemoveOldCategoryArticle
  • conSaveContentEntry
  • conSetCodeFlag
  • conSetCodeFlagBulkEditing
  • conSetMetaValue
  • conSyncArticle
  • copyRightsForElement
  • createBulkEditingFunction
  • createRandomName
  • createRightsForElement
  • cWarning
  • dbGetColumns
  • dbGetIndexes
  • dbGetPrimaryKeyName
  • dbTableExists
  • dbUpgradeTable
  • defineIfNotDefined
  • deleteArtspec
  • deleteRightsForElement
  • deleteSystemProperty
  • displayDatetime
  • emptyLogFile
  • endAndLogTiming
  • endsWith
  • extractNumber
  • generateDisplayFilePath
  • generateJs
  • getAllClientsAndLanguages
  • getArtLang
  • getArtspec
  • getAvailableContentTypes
  • getCanonicalDay
  • getCanonicalMonth
  • getDirectorySize
  • getEffectiveSetting
  • getEffectiveSettingsByType
  • getEncodingByLanguage
  • getFileContents
  • getFileInformation
  • getFileType
  • getGroupOrUserName
  • getIDForArea
  • getJsHelpContext
  • getLanguageNamesByClient
  • getLanguagesByClient
  • getmicrotime
  • getNamedFrame
  • getParam
  • getParentAreaId
  • getSearchResults
  • getStrExpandCollapseButton
  • getSystemProperties
  • getSystemPropertiesByType
  • getSystemProperty
  • getTemplateSelect
  • getUplExpandCollapseButton
  • htmldecode
  • htmlentities_iso88592
  • humanReadableSize
  • includePlugins
  • insertEmptyStrRow
  • ipMatch
  • isAlphanumeric
  • isArchive
  • isArtInMultipleUse
  • isFunctionDisabled
  • isGroup
  • isIPv4
  • isRunningFromWeb
  • isStartArticle
  • isUtf8
  • isValidMail
  • langActivateDeactivateLanguage
  • langDeleteLanguage
  • langEditLanguage
  • langGetTextDirection
  • langNewLanguage
  • langRenameLanguage
  • layDeleteLayout
  • layEditLayout
  • machineReadableSize
  • mailLogBulkEditingFunctions
  • mailLogDecodeAddresses
  • markSubMenuItem
  • mask
  • modDeleteModule
  • modEditModule
  • modTestModule
  • phpInfoToHtml
  • plugin_include
  • prCreateURLNameLocationString
  • prDeleteCacheFileContent
  • prGetCacheFileContent
  • prResolvePathViaCategoryNames
  • prResolvePathViaURLNames
  • prWriteCacheFileContent
  • putFileContents
  • recursiveCopy
  • removeFileInformation
  • renderBackendBreadcrumb
  • renderLabel
  • renderSelectProperty
  • renderTextProperty
  • saveGroupRights
  • saveRights
  • scanDirectory
  • scanPlugins
  • sendEncodingHeader
  • set_magic_quotes_gpc
  • setArtspecDefault
  • setArtspecOnline
  • setHelpContext
  • setSystemProperty
  • showTree
  • startTiming
  • statCreateLocationString
  • statDisplayTopChooser
  • statDisplayYearlyTopChooser
  • statGetAvailableMonths
  • statGetAvailableYears
  • statResetStatistic
  • statsArchive
  • statsDisplayInfo
  • statsOverviewAll
  • statsOverviewTop
  • statsOverviewTopYear
  • statsOverviewYear
  • strAssignTemplate
  • strBuildSqlValues
  • strCheckTreeForErrors
  • strCopyCategory
  • strCopyTree
  • strDeeperCategoriesArray
  • strDeleteCategory
  • strHasArticles
  • strHasStartArticle
  • stripslashes_deep
  • strMakePublic
  • strMakeVisible
  • strMoveCatTargetallowed
  • strMoveDownCategory
  • strMoveSubtree
  • strMoveUpCategory
  • strNewCategory
  • strNewTree
  • strNextBackwards
  • strNextDeeper
  • strNextDeeperAll
  • strNextPost
  • strOrderedPostTreeList
  • strRemakeTreeTable
  • strRenameCategory
  • strRenameCategoryAlias
  • strSortPrePost
  • strSyncCategory
  • systemHavePerm
  • tplAutoFillModules
  • tplBrowseLayoutForContainers
  • tplcfgDuplicate
  • tplDeleteTemplate
  • tplDuplicateTemplate
  • tplEditTemplate
  • tplGetContainerDefault
  • tplGetContainerMode
  • tplGetContainerName
  • tplGetContainerNumbersInLayout
  • tplGetContainerTypes
  • tplGetInUsedData
  • tplIsTemplateInUse
  • tplPreparseLayout
  • tplProcessSendContainerConfiguration
  • updateClientCache
  • updateFileInformation
  • uplCreateFriendlyName
  • uplDirectoryListRecursive
  • uplGetDirectoriesToExclude
  • uplGetFileExtension
  • uplGetFileIcon
  • uplGetFileTypeDescription
  • uplGetThumbnail
  • uplHasFiles
  • uplHasSubdirs
  • uplmkdir
  • uplRecursiveDBDirectoryList
  • uplRecursiveDirectoryList
  • uplRenameDirectory
  • uplSearch
  • uplSyncDirectory
  • uplSyncDirectoryDBFS
  • Overview
  • Package
  • Function
  • Tree
  • Deprecated
  • Todo
   1: <?php
   2: /**
   3:  * 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:     $catArtColl = new cApiCategoryArticleCollection();
 639:     $cats = $catArtColl->getIdsByWhereClause("idart = " . (int) $idart);
 640: 
 641:     // Fetch idcat
 642:     foreach ($cats as $idcat) {
 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: 
 652:     $contentColl = new cApiContentCollection();
 653:     $contentColl->deleteBy('idartlang', (int) $idartlang);
 654: 
 655:     $artLangColl = new cApiArticleLanguageCollection();
 656:     $artLangColl->delete((int) $idartlang);
 657: 
 658:     if ($idtplcfg != 0) {
 659:         $containerConfColl = new cApiContainerConfigurationCollection();
 660:         $containerConfColl->deleteBy('idtplcfg', (int) $idtplcfg);
 661: 
 662:         $tplConfColl = new cApiTemplateConfigurationCollection();
 663:         $tplConfColl->delete('idtplcfg', $idtplcfg);
 664:     }
 665: 
 666:     // Check if there are remaining languages
 667:     $artLangColl->resetQuery();
 668:     $artLangColl->select('idart = ' . (int) $idart);
 669:     if ($artLangColl->next()) {
 670:         return;
 671:     }
 672: 
 673:     $catArtColl = new cApiCategoryArticleCollection();
 674:     $catArtColl->select('idart = ' . (int) $idart);
 675:     while (($oCatArtItem = $catArtColl->next()) !== false) {
 676:         // Delete from code cache
 677:         if (cFileHandler::exists($cfgClient[$client]['code']['path'])) {
 678:             /**
 679:              * @var $file SplFileInfo
 680:              */
 681:             foreach (new DirectoryIterator($cfgClient[$client]['code']['path']) as $file) {
 682:                 if ($file->isFile() === false) {
 683:                     continue;
 684:                 }
 685: 
 686:                 $extension = substr($file, strrpos($file->getBasename(), '.') + 1);
 687:                 if ($extension != 'php') {
 688:                     continue;
 689:                 }
 690: 
 691:                 if (preg_match('/[0-9*].[0-9*].' . $oCatArtItem->get('idcatart') . '/s', $file->getBasename())) {
 692:                     cFileHandler::remove($cfgClient[$client]['code']['path'] . '/' . $file->getFilename());
 693:                 }
 694:             }
 695:         }
 696: 
 697:         // Delete from 'stat'-table
 698:         $statColl = new cApiStatCollection();
 699:         $statColl->deleteBy('idcatart', (int) $oCatArtItem->get('idcatart'));
 700:     }
 701: 
 702:     // delete values from con_cat_art only in the correct language
 703:     $catLangColl = new cApiCategoryLanguageCollection();
 704:     $catLangColl->select('`idlang`=' . cSecurity::toInteger($lang));
 705:     $idcats = $catLangColl->getAllIds();
 706:     $idcatsString = "('" . implode('\',\'', $idcats) . "')";
 707:     $catArtColl->resetQuery();
 708:     $catArtColl->deleteByWhereClause('`idart`=' . $idart . ' AND `idcat` IN ' . $idcatsString);
 709: 
 710:     // delete entry from con_art
 711:     $oArtColl = new cApiArticleCollection();
 712:     $oArtColl->delete((int) $idart);
 713: 
 714:     // this will delete all keywords associated with the article
 715:     $search = new cSearchIndex();
 716:     $search->start($idart, array());
 717: 
 718:     // Contenido Extension Chain
 719:     // @see docs/techref/plugins/Contenido Extension Chainer.pdf
 720:     $iterator = $_cecRegistry->getIterator("Contenido.Content.DeleteArticle");
 721:     while (($chainEntry = $iterator->next()) !== false) {
 722:         $chainEntry->execute($idart);
 723:     }
 724: }
 725: 
 726: /**
 727:  * Extract a number from a string
 728:  *
 729:  * @param string $string String var by reference
 730:  */
 731: function extractNumber(&$string) {
 732:     $string = preg_replace('/[^0-9]/', '', $string);
 733: }
 734: 
 735: /**
 736:  * Change the template of a category
 737:  *
 738:  * @param int $idcat Category Id
 739:  * @param int $idtpl Template Id
 740:  */
 741: function conChangeTemplateForCat($idcat, $idtpl) {
 742:     global $lang;
 743: 
 744:     $oCatLang = new cApiCategoryLanguage();
 745:     if (!$oCatLang->loadByCategoryIdAndLanguageId($idcat, $lang)) {
 746:         return;
 747:     }
 748: 
 749:     if ($oCatLang->get('idtplcfg')) {
 750:         // Delete old container configuration
 751:         $oContainerConfColl = new cApiContainerConfigurationCollection();
 752:         $oContainerConfColl->deleteBy('idtplcfg', (int) $oCatLang->get('idtplcfg'));
 753: 
 754:         // Delete old template configuration
 755:         $oTplConfColl = new cApiTemplateConfigurationCollection();
 756:         $oTplConfColl->delete('idtplcfg', (int) $oCatLang->get('idtplcfg'));
 757:     }
 758: 
 759:     // Parameter $idtpl is 0, reset the template
 760:     if (0 == $idtpl) {
 761:         $oCatLang->set('idtplcfg', 0);
 762:         $oCatLang->store();
 763:     } else {
 764:         // Check if a pre-configuration is assigned
 765:         $oTpl = new cApiTemplate();
 766:         $oTpl->loadBy('idtpl', (int) $idtpl);
 767: 
 768:         if (0 != $oTpl->get('idtplcfg')) {
 769:             // Template is pre-configured, create new configuration
 770:             $oTplConfColl = new cApiTemplateConfigurationCollection();
 771:             $oTplConf = $oTplConfColl->create($idtpl);
 772: 
 773:             // If there is a preconfiguration of template, copy its settings
 774:             // into templateconfiguration
 775:             $oTplConfColl->copyTemplatePreconfiguration($idtpl, $oTplConf->get('idtplcfg'));
 776: 
 777:             // Update category language
 778:             $oCatLang->set('idtplcfg', $oTplConf->get('idtplcfg'));
 779:             $oCatLang->store();
 780:         } else {
 781:             // Template is not pre-configured, create a new configuration.
 782:             $oTplConfColl = new cApiTemplateConfigurationCollection();
 783:             $oTplConf = $oTplConfColl->create($idtpl);
 784: 
 785:             // Update category language
 786:             $oCatLang->set('idtplcfg', $oTplConf->get('idtplcfg'));
 787:             $oCatLang->store();
 788:         }
 789:     }
 790: 
 791:     conGenerateCodeForAllartsInCategory($idcat);
 792: }
 793: 
 794: /**
 795:  * Returns category tree structure.
 796:  *
 797:  * @param int $client Uses global set client if not set
 798:  * @param int $lang Uses global set language if not set
 799:  * @return array
 800:  */
 801: function conFetchCategoryTree($client = false, $lang = false) {
 802:     if ($client === false) {
 803:         $client = $GLOBALS['client'];
 804:     }
 805:     if ($lang === false) {
 806:         $lang = $GLOBALS['lang'];
 807:     }
 808: 
 809:     $oCatTreeColl = new cApiCategoryTreeCollection();
 810:     $aCatTree = $oCatTreeColl->getCategoryTreeStructureByClientIdAndLanguageId($client, $lang);
 811: 
 812:     return $aCatTree;
 813: }
 814: 
 815: /**
 816:  * Fetch all deeper categories by a given id
 817:  *
 818:  * @param int $idcat Id of category
 819:  * @return array Array with all deeper categories
 820:  */
 821: function conDeeperCategoriesArray($idcat) {
 822:     global $client;
 823: 
 824:     $oCatColl = new cApiCategoryCollection();
 825:     $aCatIds = $oCatColl->getAllCategoryIdsRecursive($idcat, $client);
 826: 
 827:     return $aCatIds;
 828: }
 829: 
 830: /**
 831:  * Recursive function to create an location string
 832:  *
 833:  * @param int $idcat ID of the starting category
 834:  * @param string $seperator Seperation string
 835:  * @param string $catStr Category location string (by reference)
 836:  * @param bool $makeLink Create location string with links
 837:  * @param string $linkClass Stylesheet class for the links
 838:  * @param int $firstTreeElementToUse First navigation Level location string
 839:  *        should be printed out (first level = 0!!)
 840:  * @param int $uselang Id of language
 841:  * @param bool $final
 842:  * @param bool $usecache
 843:  * @return string Location string
 844:  */
 845: function conCreateLocationString($idcat, $seperator, &$catStr, $makeLink = false, $linkClass = '', $firstTreeElementToUse = 0, $uselang = 0, $final = true, $usecache = false) {
 846:     global $cfg, $client, $cfgClient, $lang, $sess;
 847: 
 848:     if ($idcat == 0) {
 849:         $catStr = i18n("Lost and found");
 850:         return;
 851:     }
 852: 
 853:     if ($uselang == 0) {
 854:         $uselang = $lang;
 855:     }
 856: 
 857:     $locationStringCache = cRegistry::getAppVar('locationStringCache');
 858:     $locationStringCacheFile = $cfgClient[$client]['cache']['path'] . "locationstring-cache-$uselang.txt";
 859: 
 860:     if ($final == true && $usecache == true) {
 861:         if (!is_array($locationStringCache)) {
 862:             if (cFileHandler::exists($locationStringCacheFile)) {
 863:                 $locationStringCache = unserialize(cFileHandler::read($locationStringCacheFile));
 864:             } else {
 865:                 $locationStringCache = array();
 866:             }
 867:             cRegistry::setAppVar('locationStringCache', $locationStringCache);
 868:         }
 869: 
 870:         if (array_key_exists($idcat, $locationStringCache)) {
 871:             if ($locationStringCache[$idcat]['expires'] > time()) {
 872:                 $catStr = $locationStringCache[$idcat]['name'];
 873:                 return;
 874:             }
 875:         }
 876:     }
 877: 
 878:     $db = cRegistry::getDb();
 879: 
 880:     $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";
 881: 
 882:     $sql = $db->prepare($sql, array(
 883:         'cat_lang' => $cfg['tab']['cat_lang'],
 884:         'cat' => $cfg['tab']['cat'],
 885:         'cat_tree' => $cfg['tab']['cat_tree'],
 886:         'idlang' => (int) $uselang,
 887:         'idclient' => (int) $client,
 888:         'idcat' => (int) $idcat
 889:     ));
 890:     $db->query($sql);
 891:     $db->nextRecord();
 892: 
 893:     if ($db->f('level') >= $firstTreeElementToUse) {
 894:         $name = $db->f('name');
 895:         $parentid = $db->f('parentid');
 896: 
 897:         // create link
 898:         if ($makeLink == true) {
 899:             $linkUrl = $sess->url("front_content.php?idcat=$idcat");
 900:             $name = '<a href="' . $linkUrl . '" class="' . $linkClass . '">' . $name . '</a>';
 901:         }
 902: 
 903:         $tmp_cat_str = $name . $seperator . $catStr;
 904:         $catStr = $tmp_cat_str;
 905:     }
 906: 
 907:     if ($parentid != 0) {
 908:         conCreateLocationString($parentid, $seperator, $catStr, $makeLink, $linkClass, $firstTreeElementToUse, $uselang, false);
 909:     } else {
 910:         $sep_length = strlen($seperator);
 911:         $str_length = strlen($catStr);
 912:         $tmp_length = $str_length - $sep_length;
 913:         $catStr = substr($catStr, 0, $tmp_length);
 914:     }
 915: 
 916:     if ($final == true && $usecache == true) {
 917:         $locationStringCache[$idcat]['name'] = $catStr;
 918:         $locationStringCache[$idcat]['expires'] = time() + 3600;
 919: 
 920:         if (is_writable($cfgClient[$client]['cache']['path'])) {
 921:             cFileHandler::write($locationStringCacheFile, serialize($locationStringCache));
 922:         }
 923:         cRegistry::setAppVar('locationStringCache', $locationStringCache);
 924:     }
 925: }
 926: 
 927: /**
 928:  * Set a start-article @fixme Do we still need the isstart.
 929:  * The old start
 930:  * compatibility has already been removed...
 931:  *
 932:  * @param int $idcatart Idcatart of the article
 933:  * @param bool $isstart Start article flag
 934:  */
 935: function conMakeStart($idcatart, $isstart) {
 936:     global $lang;
 937: 
 938:     // Load category article
 939:     $oCatArt = new cApiCategoryArticle((int) $idcatart);
 940:     if (!$oCatArt->isLoaded()) {
 941:         return;
 942:     }
 943:     $idart = $oCatArt->get('idart');
 944:     $idcat = $oCatArt->get('idcat');
 945: 
 946:     // Load article language
 947:     $oArtLang = new cApiArticleLanguage();
 948:     if (!$oArtLang->loadByArticleAndLanguageId($idart, $lang)) {
 949:         return;
 950:     }
 951:     $idartlang = $oArtLang->get('idartlang');
 952: 
 953:     // Update startidartlang for category language
 954:     $oCatLang = new cApiCategoryLanguage();
 955:     if ($oCatLang->loadByCategoryIdAndLanguageId($idcat, $lang)) {
 956:         if ($isstart == 1) {
 957:             $oCatLang->set('startidartlang', $idartlang);
 958:         } else {
 959:             $oCatLang->set('startidartlang', 0);
 960:         }
 961:         $oCatLang->store();
 962:     }
 963: 
 964:     if ($isstart == 1) {
 965:         // Deactivate time management if article is a start article
 966:         $oArtLang->set('timemgmt', 0);
 967:         $oArtLang->store();
 968:     }
 969: }
 970: 
 971: /**
 972:  * Create code for one article in all categorys
 973:  *
 974:  * @param int $idart Article ID
 975:  */
 976: function conGenerateCodeForArtInAllCategories($idart) {
 977:     $oCatArtColl = new cApiCategoryArticleCollection();
 978:     $ids = $oCatArtColl->getIdsByWhereClause('idart = ' . (int) $idart);
 979:     conSetCodeFlagBulkEditing($ids);
 980: }
 981: 
 982: /**
 983:  * Generate code for all articles in a category
 984:  *
 985:  * @param int $idcat Category ID
 986:  */
 987: function conGenerateCodeForAllArtsInCategory($idcat) {
 988:     $oCatArtColl = new cApiCategoryArticleCollection();
 989:     $ids = $oCatArtColl->getIdsByWhereClause('idcat = ' . (int) $idcat);
 990:     conSetCodeFlagBulkEditing($ids);
 991: }
 992: 
 993: /**
 994:  * Generate code for the active client
 995:  */
 996: function conGenerateCodeForClient() {
 997:     global $client;
 998:     $oCatArtColl = new cApiCategoryArticleCollection();
 999:     $ids = $oCatArtColl->getAllIdsByClientId($client);
1000:     conSetCodeFlagBulkEditing($ids);
1001: }
1002: 
1003: /**
1004:  * Create code for all arts using the same layout
1005:  *
1006:  * @param int $idlay Layout-ID
1007:  */
1008: function conGenerateCodeForAllartsUsingLayout($idlay) {
1009:     global $cfg;
1010: 
1011:     $db = cRegistry::getDb();
1012: 
1013:     $sql = "SELECT idtpl FROM " . $cfg["tab"]["tpl"] . " WHERE idlay='" . cSecurity::toInteger($idlay) . "'";
1014:     $db->query($sql);
1015:     while ($db->nextRecord()) {
1016:         conGenerateCodeForAllartsUsingTemplate($db->f("idtpl"));
1017:     }
1018: }
1019: 
1020: /**
1021:  * Create code for all articles using the same module
1022:  *
1023:  * @param int $idmod Module id
1024:  */
1025: function conGenerateCodeForAllartsUsingMod($idmod) {
1026:     $oContainerColl = new cApiContainerCollection();
1027:     $rsList = $oContainerColl->getFieldsByWhereClause(array(
1028:         'idtpl'
1029:     ), 'idmod = ' . (int) $idmod);
1030:     foreach ($rsList as $rs) {
1031:         conGenerateCodeForAllArtsUsingTemplate($rs['idtpl']);
1032:     }
1033: }
1034: 
1035: /**
1036:  * Generate code for all articles using one template
1037:  *
1038:  * @param int $idtpl Template-Id
1039:  */
1040: function conGenerateCodeForAllArtsUsingTemplate($idtpl) {
1041:     global $cfg, $client;
1042: 
1043:     $db = cRegistry::getDb();
1044: 
1045:     $oCatArtColl = new cApiCategoryArticleCollection();
1046: 
1047:     // Search all categories
1048:     $sql = "SELECT
1049:                 b.idcat
1050:             FROM
1051:                 " . $cfg['tab']['tpl_conf'] . " AS a,
1052:                 " . $cfg['tab']['cat_lang'] . " AS b,
1053:                 " . $cfg['tab']['cat'] . " AS c
1054:             WHERE
1055:                 a.idtpl     = " . cSecurity::toInteger($idtpl) . " AND
1056:                 b.idtplcfg  = a.idtplcfg AND
1057:                 c.idclient  = " . cSecurity::toInteger($client) . " AND
1058:                 b.idcat     = c.idcat";
1059: 
1060:     $db->query($sql);
1061: 
1062:     while ($db->nextRecord()) {
1063:         $oCatArtColl->resetQuery();
1064:         $ids = $oCatArtColl->getIdsByWhereClause('idcat = ' . cSecurity::toInteger($db->f('idcat')));
1065:         foreach ($ids as $id) {
1066:             conSetCodeFlag($id);
1067:         }
1068:     }
1069: 
1070:     // Search all articles
1071:     $sql = "SELECT
1072:                 b.idart
1073:             FROM
1074:                 " . $cfg['tab']['tpl_conf'] . " AS a,
1075:                 " . $cfg['tab']['art_lang'] . " AS b,
1076:                 " . $cfg['tab']['art'] . " AS c
1077:             WHERE
1078:                 a.idtpl     = " . cSecurity::toInteger($idtpl) . " AND
1079:                 b.idtplcfg  = a.idtplcfg AND
1080:                 c.idclient  = " . cSecurity::toInteger($client) . " AND
1081:                 b.idart     = c.idart";
1082: 
1083:     $db->query($sql);
1084: 
1085:     while ($db->nextRecord()) {
1086:         $oCatArtColl->resetQuery();
1087:         $ids = $oCatArtColl->getIdsByWhereClause('idart = ' . (int) $db->f('idart'));
1088:         foreach ($ids as $id) {
1089:             conSetCodeFlag($id);
1090:         }
1091:     }
1092: }
1093: 
1094: /**
1095:  * Create code for all articles
1096:  */
1097: function conGenerateCodeForAllArts() {
1098:     global $cfg;
1099: 
1100:     $db = cRegistry::getDb();
1101: 
1102:     $sql = "SELECT idcatart FROM " . $cfg['tab']['cat_art'];
1103:     $db->query($sql);
1104:     while ($db->nextRecord()) {
1105:         conSetCodeFlag($db->f("idcatart"));
1106:     }
1107: }
1108: 
1109: /**
1110:  * Set code creation flag for one category article id to true
1111:  *
1112:  * @param int $idcatart Category article id
1113:  */
1114: function conSetCodeFlag($idcatart) {
1115:     global $client, $cfgClient;
1116: 
1117:     // Set 'createcode' flag
1118:     $oCatArtColl = new cApiCategoryArticleCollection();
1119:     $oCatArtColl->setCreateCodeFlag($idcatart);
1120: 
1121:     // Delete also generated code files from file system
1122:     if (cFileHandler::exists($cfgClient[$client]['code']['path'])) {
1123:         /**
1124:          * @var $file SplFileInfo
1125:          */
1126:         foreach (new DirectoryIterator($cfgClient[$client]['code']['path']) as $file) {
1127:             if ($file->isFile() === false) {
1128:                 continue;
1129:             }
1130: 
1131:             $extension = substr($file, strrpos($file->getBasename(), '.') + 1);
1132:             if ($extension != 'php') {
1133:                 continue;
1134:             }
1135: 
1136:             if (preg_match('/[0-9*].[0-9*].' . $idcatart . '/s', $file->getBasename())) {
1137:                 cFileHandler::remove($cfgClient[$client]['code']['path'] . '/' . $file->getFilename());
1138:             }
1139:         }
1140:     }
1141: }
1142: 
1143: /**
1144:  * Set code creation flag for several category article ids to true
1145:  *
1146:  * @param array $idcatarts List of category article ids
1147:  */
1148: function conSetCodeFlagBulkEditing(array $idcatarts) {
1149:     global $client, $cfgClient;
1150: 
1151:     if (count($idcatarts) == 0) {
1152:         return;
1153:     }
1154: 
1155:     // Set 'createcode' flag
1156:     $oCatArtColl = new cApiCategoryArticleCollection();
1157:     $oCatArtColl->setCreateCodeFlag($idcatarts);
1158: 
1159:     if (cFileHandler::exists($cfgClient[$client]['code']['path']) === false) {
1160:         return;
1161:     }
1162: 
1163:     // Delete also generated code files from file system
1164:     foreach ($idcatarts as $id) {
1165:         /**
1166:          * @var $file SplFileInfo
1167:          */
1168:         foreach (new DirectoryIterator($cfgClient[$client]['code']['path']) as $file) {
1169:             if ($file->isFile() === false) {
1170:                 continue;
1171:             }
1172: 
1173:             $extension = substr($file, strrpos($file->getBasename(), '.') + 1);
1174:             if ($extension != 'php') {
1175:                 continue;
1176:             }
1177: 
1178:             if (preg_match('/[0-9*].[0-9*].' . $id . '/s', $file->getBasename())) {
1179:                 cFileHandler::remove($cfgClient[$client]['code']['path'] . '/' . $file->getFilename());
1180:             }
1181:         }
1182:     }
1183: }
1184: 
1185: /**
1186:  * Set articles on/offline for the time management function
1187:  */
1188: function conFlagOnOffline() {
1189:     global $cfg;
1190: 
1191:     $db = cRegistry::getDb();
1192: 
1193:     $oArtLangColl = new cApiArticleLanguageCollection();
1194: 
1195:     // Set all articles which are before our starttime to offline
1196:     $where = "NOW() < datestart AND datestart != '0000-00-00 00:00:00' AND datestart IS NOT NULL AND timemgmt = 1";
1197:     $ids = $oArtLangColl->getIdsByWhereClause($where);
1198:     foreach ($ids as $id) {
1199:         $sql = "UPDATE " . $cfg['tab']['art_lang'] . " SET online = 0 WHERE idartlang = " . (int) $id;
1200:         $db->query($sql);
1201:     }
1202: 
1203:     // Set all articles which are in between of our start/endtime to online
1204:     $where = "NOW() > datestart AND (NOW() < dateend OR dateend = '0000-00-00 00:00:00') AND " . "online = 0 AND timemgmt = 1";
1205:     $oArtLangColl->resetQuery();
1206:     $ids = $oArtLangColl->getIdsByWhereClause($where);
1207:     foreach ($ids as $id) {
1208:         $sql = "UPDATE " . $cfg['tab']['art_lang'] . " SET online = 1, published = datestart WHERE idartlang = " . (int) $id;
1209:         $db->query($sql);
1210:     }
1211: 
1212:     // Set all articles after our endtime to offline
1213:     $where = "NOW() > dateend AND dateend != '0000-00-00 00:00:00' AND timemgmt = 1";
1214:     $oArtLangColl->resetQuery();
1215:     $ids = $oArtLangColl->getIdsByWhereClause($where);
1216:     foreach ($ids as $id) {
1217:         $sql = "UPDATE " . $cfg['tab']['art_lang'] . " SET online = 0 WHERE idartlang = " . (int) $id;
1218:         $db->query($sql);
1219:     }
1220: }
1221: 
1222: /**
1223:  * Move articles for the time management function
1224:  */
1225: function conMoveArticles() {
1226:     global $cfg;
1227: 
1228:     $db = cRegistry::getDb();
1229: 
1230:     // Perform after-end updates
1231:     $fields = array(
1232:         'idartlang',
1233:         'idart',
1234:         'time_move_cat',
1235:         'time_target_cat',
1236:         'time_online_move'
1237:     );
1238:     $where = "NOW() > dateend AND dateend != '0000-00-00 00:00:00' AND timemgmt = 1 AND time_move_cat = 1";
1239:     $oArtLangColl = new cApiArticleLanguageCollection();
1240:     $rsList = $oArtLangColl->getFieldsByWhereClause($fields, $where);
1241: 
1242:     foreach ($rsList as $rs) {
1243:         $online = ($rs['time_online_move'] == '1')? 1 : 0;
1244:         $sql = array();
1245:         $sql[] = 'UPDATE ' . $cfg['tab']['art_lang'] . ' SET timemgmt = 0, online = 0 WHERE idartlang = ' . (int) $rs['idartlang'] . ';';
1246:         $sql[] = 'UPDATE ' . $cfg['tab']['cat_art'] . ' SET idcat = ' . (int) $rs['time_target_cat'] . ', createcode = 1 WHERE idart = ' . (int) $rs['idart'] . ';';
1247:         $sql[] = 'UPDATE ' . $cfg['tab']['art_lang'] . ' SET online = ' . (int) $online . ' WHERE idart = ' . (int) $rs['idart'] . ';';
1248: 
1249:         // $sql = implode("\n", $sql);
1250:         // cDebug::out($sql);
1251:         $db->query($sql[0]);
1252:         $db->query($sql[1]);
1253:         $db->query($sql[2]);
1254: 
1255:         // Execute CEC hook
1256:         cApiCecHook::execute('Contenido.Article.conMoveArticles_Loop', $rs);
1257:     }
1258: }
1259: 
1260: /**
1261:  * Copies template configuration entry from source template configuration.
1262:  *
1263:  * @param int $srcidtplcfg
1264:  */
1265: function conCopyTemplateConfiguration($srcidtplcfg) {
1266:     $oTemplateConf = new cApiTemplateConfiguration((int) $srcidtplcfg);
1267:     if (!$oTemplateConf->isLoaded()) {
1268:         return NULL;
1269:     }
1270: 
1271:     $oTemplateConfColl = new cApiTemplateConfigurationCollection();
1272:     $oNewTemplateConf = $oTemplateConfColl->create($oTemplateConf->get('idtpl'));
1273:     return (is_object($oNewTemplateConf))? $oNewTemplateConf->get('idtplcfg') : NULL;
1274: }
1275: 
1276: /**
1277:  * Copies container configuration entries from source container configuration to
1278:  * destination container configuration.
1279:  *
1280:  * @param int $srcidtplcfg
1281:  * @param int $dstidtplcfg
1282:  */
1283: function conCopyContainerConf($srcidtplcfg, $dstidtplcfg) {
1284:     $counter = 0;
1285:     $oContainerConfColl = new cApiContainerConfigurationCollection();
1286:     $oContainerConfColl->select('idtplcfg = ' . cSecurity::toInteger($srcidtplcfg));
1287:     while (($oContainerConf = $oContainerConfColl->next()) !== false) {
1288:         $oNewContainerConfColl = new cApiContainerConfigurationCollection();
1289:         $oNewContainerConfColl->copyItem($oContainerConf, array(
1290:             'idtplcfg' => cSecurity::toInteger($dstidtplcfg)
1291:         ));
1292:         $counter++;
1293:     }
1294:     return ($counter > 0)? true : false;
1295: }
1296: 
1297: /**
1298:  * Copies content entries from source article language to destination article
1299:  * language.
1300:  *
1301:  * @param int $srcidartlang
1302:  * @param int $dstidartlang
1303:  */
1304: function conCopyContent($srcidartlang, $dstidartlang) {
1305:     $oContentColl = new cApiContentCollection();
1306:     $oContentColl->select('idartlang = ' . cSecurity::toInteger($srcidartlang));
1307:     while (($oContent = $oContentColl->next()) !== false) {
1308:         $oNewContentColl = new cApiContentCollection();
1309:         $oNewContentColl->copyItem($oContent, array(
1310:             'idartlang' => cSecurity::toInteger($dstidartlang)
1311:         ));
1312:     }
1313: }
1314: 
1315: /**
1316:  * Copies meta tag entries from source article language to destination article
1317:  * language.
1318:  *
1319:  * @param int $srcidartlang
1320:  * @param int $dstidartlang
1321:  */
1322: function conCopyMetaTags($srcidartlang, $dstidartlang) {
1323:     $oMetaTagColl = new cApiMetaTagCollection();
1324:     $oMetaTagColl->select('idartlang = ' . cSecurity::toInteger($srcidartlang));
1325:     while (($oMetaTag = $oMetaTagColl->next()) !== false) {
1326:         $oNewMetaTagColl = new cApiMetaTagCollection();
1327:         $oNewMetaTagColl->copyItem($oMetaTag, array(
1328:             'idartlang' => cSecurity::toInteger($dstidartlang)
1329:         ));
1330:     }
1331: }
1332: 
1333: /**
1334:  * Copy article language entry.
1335:  *
1336:  * @global array $cfg
1337:  * @global int $lang
1338:  * @param int $srcidart
1339:  * @param int $dstidart
1340:  * @param int $newtitle
1341:  * @param int $useCopyLabel
1342:  */
1343: function conCopyArtLang($srcidart, $dstidart, $newtitle, $useCopyLabel = true) {
1344:     global $auth, $lang;
1345: 
1346:     $oSrcArtLang = new cApiArticleLanguage();
1347:     if (!$oSrcArtLang->loadByArticleAndLanguageId($srcidart, $lang)) {
1348:         return;
1349:     }
1350: 
1351:     // Copy the template configuration
1352:     if ($oSrcArtLang->get('idtplcfg') != 0) {
1353:         $newidtplcfg = conCopyTemplateConfiguration($oSrcArtLang->get('idtplcfg'));
1354:         conCopyContainerConf($oSrcArtLang->get('idtplcfg'), $newidtplcfg);
1355:     }
1356: 
1357:     $idart = $dstidart;
1358:     $idlang = $oSrcArtLang->get('idlang');
1359:     $idtplcfg = $newidtplcfg;
1360: 
1361:     if ($newtitle != '') {
1362:         $title = sprintf($newtitle, $oSrcArtLang->get('title'));
1363:     } else if ($useCopyLabel == true) {
1364:         $title = sprintf(i18n('%s (Copy)'), $oSrcArtLang->get('title'));
1365:     } else {
1366:         $title = $oSrcArtLang->get('title');
1367:     }
1368: 
1369:     // Create an article language entry
1370:     $oArtLangColl = new cApiArticleLanguageCollection();
1371:     $fieldsToOverwrite = array(
1372:         'idart' => $idart,
1373:         'idlang' => $idlang,
1374:         'idtplcfg' => cSecurity::toInteger($idtplcfg),
1375:         'online' => 0,
1376:         'title' => $title,
1377:         'created' => date('Y-m-d H:i:s'),
1378:         'lastmodified' => date('Y-m-d H:i:s'),
1379:         'modifiedby' => $auth->auth['uname'],
1380:         'published' => '',
1381:         'publishedby' => ''
1382:     );
1383:     $oNewArtLang = $oArtLangColl->copyItem($oSrcArtLang, $fieldsToOverwrite);
1384: 
1385:     if (!is_object($oNewArtLang)) {
1386:         return;
1387:     }
1388: 
1389:     // Copy content
1390:     conCopyContent($oSrcArtLang->get('idartlang'), $oNewArtLang->get('idartlang'));
1391: 
1392:     // Copy meta tags
1393:     conCopyMetaTags($oSrcArtLang->get('idartlang'), $oNewArtLang->get('idartlang'));
1394: 
1395:     // Execute CEC hook
1396:     cApiCecHook::execute('Contenido.Article.conCopyArtLang_AfterInsert', array(
1397:         'idartlang' => cSecurity::toInteger($oNewArtLang->get('idartlang')),
1398:         'idart' => cSecurity::toInteger($idart),
1399:         'idlang' => cSecurity::toInteger($idlang),
1400:         'idtplcfg' => cSecurity::toInteger($idtplcfg),
1401:         'title' => $title
1402:     ));
1403: 
1404:     // Update keyword list for new article
1405:     conMakeArticleIndex($oNewArtLang->get('idartlang'), $idart);
1406: }
1407: 
1408: /**
1409:  * Copy article entry.
1410:  *
1411:  * @global object $auth
1412:  * @param int $srcidart
1413:  * @param int $targetcat
1414:  * @param string $newtitle
1415:  * @param bool $useCopyLabel
1416:  * @return bool
1417:  */
1418: function conCopyArticle($srcidart, $targetcat = 0, $newtitle = '', $useCopyLabel = true) {
1419:     // Get source article
1420:     $oSrcArt = new cApiArticle((int) $srcidart);
1421:     if (!$oSrcArt->isLoaded()) {
1422:         return false;
1423:     }
1424:     $idclient = $oSrcArt->get('idclient');
1425: 
1426:     // Create destination article
1427:     $oArtCollection = new cApiArticleCollection();
1428:     $oNewArt = $oArtCollection->create($idclient);
1429:     if (!is_object($oNewArt)) {
1430:         return false;
1431:     }
1432:     $dstidart = $oNewArt->get('idart');
1433: 
1434:     conCopyArtLang($srcidart, $dstidart, $newtitle, $useCopyLabel);
1435: 
1436:     // Get source category article entries
1437:     $oCatArtColl = new cApiCategoryArticleCollection();
1438:     $oCatArtColl->select('idart = ' . (int) $srcidart);
1439:     while (($oCatArt = $oCatArtColl->next()) !== false) {
1440:         // Insert destination category article entry
1441:         $oCatArtColl2 = new cApiCategoryArticleCollection();
1442:         $fieldsToOverwrite = array(
1443:             'idcat' => ($targetcat != 0)? $targetcat : $oCatArt->get('idcat'),
1444:             'idart' => $dstidart,
1445:             'status' => ($oCatArt->get('status') !== '')? $oCatArt->get('status') : 0,
1446:             'createcode' => 1,
1447:             'is_start' => 0
1448:         );
1449:         $oCatArtColl2->copyItem($oCatArt, $fieldsToOverwrite);
1450: 
1451:         // If true, exit while routine, only one category entry is needed
1452:         if ($targetcat != 0) {
1453:             break;
1454:         }
1455:     }
1456: 
1457:     // Contenido Extension Chain
1458:     // @see docs/techref/plugins/Contenido Extension Chainer.pdf
1459:     $_cecRegistry = cApiCecRegistry::getInstance();
1460:     $iterator = $_cecRegistry->getIterator('Contenido.Content.CopyArticle');
1461:     while (($chainEntry = $iterator->next()) !== false) {
1462:         $chainEntry->execute($srcidart, $dstidart);
1463:     }
1464: 
1465:     return $dstidart;
1466: }
1467: 
1468: /**
1469:  *
1470:  * @todo Returns something....
1471:  * @global array $cfg
1472:  * @global int $client
1473:  * @global int $lang
1474:  * @param int $idcat
1475:  * @param int $minLevel
1476:  * @return int
1477:  */
1478: function conGetTopmostCat($idcat, $minLevel = 0) {
1479:     global $cfg, $client, $lang;
1480: 
1481:     $db = cRegistry::getDb();
1482: 
1483:     $sql = "SELECT a.name AS name, a.idcat AS idcat, b.parentid AS parentid, c.level AS level
1484:             FROM `:cat_lang` AS a, `:cat` AS b, `:cat_tree` AS c
1485:             WHERE a.idlang = :idlang AND b.idclient = :idclient AND b.idcat = :idcat
1486:             AND c.idcat = b.idcat AND a.idcat = b.idcat";
1487: 
1488:     $sql = $db->prepare($sql, array(
1489:         'cat_lang' => $cfg['tab']['cat_lang'],
1490:         'cat' => $cfg['tab']['cat'],
1491:         'cat_tree' => $cfg['tab']['cat_tree'],
1492:         'idlang' => (int) $lang,
1493:         'idclient' => (int) $client,
1494:         'idcat' => (int) $idcat
1495:     ));
1496:     $db->query($sql);
1497:     $db->nextRecord();
1498: 
1499:     $name = $db->f('name');
1500:     $parentid = $db->f('parentid');
1501:     $thislevel = $db->f('level');
1502: 
1503:     if ($parentid != 0 && $thislevel >= $minLevel) {
1504:         return conGetTopmostCat($parentid, $minLevel);
1505:     } else {
1506:         return $idcat;
1507:     }
1508: }
1509: 
1510: /**
1511:  * Synchronizes an article from source language to destination language.
1512:  *
1513:  * @param int $idart Article id
1514:  * @param int $srclang Source language id
1515:  * @param int $dstlang Destination language id
1516:  */
1517: function conSyncArticle($idart, $srclang, $dstlang) {
1518:     $auth = cRegistry::getAuth();
1519: 
1520:     // Check if article has already been synced to target language
1521:     $dstArtLang = new cApiArticleLanguage();
1522:     $dstArtLang->loadByArticleAndLanguageId($idart, $dstlang);
1523:     if ($dstArtLang->isLoaded()) {
1524:         // Article already exists in detination language
1525:         return;
1526:     }
1527: 
1528:     $srcArtLang = new cApiArticleLanguage();
1529:     $srcArtLang->loadByArticleAndLanguageId($idart, $srclang);
1530:     if (!$srcArtLang->isLoaded()) {
1531:         // Couldn't load article in source language
1532:         return;
1533:     }
1534:     $srcidartlang = $srcArtLang->get('idartlang');
1535: 
1536:     if ($srcArtLang->get('idtplcfg') != 0) {
1537:         $newidtplcfg = tplcfgDuplicate($srcArtLang->get('idtplcfg'));
1538:     } else {
1539:         $newidtplcfg = 0;
1540:     }
1541: 
1542:     // Create an article language entry for destination language
1543:     $artLangColl = new cApiArticleLanguageCollection();
1544:     $fieldsToOverwrite = array(
1545:         'idart' => $idart,
1546:         'idlang' => $dstlang,
1547:         'artspec' => 0,
1548:         'online' => 0,
1549:         'created' => date('Y-m-d H:i:s'),
1550:         'lastmodified' => date('Y-m-d H:i:s'),
1551:         'modifiedby' => $auth->auth['uname'],
1552:         'published' => '',
1553:         'publishedby' => '',
1554:         'timemgmt' => 0,
1555:         'datestart' => '',
1556:         'dateend' => '',
1557:         'status' => 0,
1558:         'time_move_cat' => 0,
1559:         'time_target_cat' => 0,
1560:         'time_online_move' => 0,
1561:         'free_use_01' => '',
1562:         'free_use_02' => '',
1563:         'free_use_03' => ''
1564:     );
1565:     $artLang = $artLangColl->copyItem($srcArtLang, $fieldsToOverwrite);
1566:     if (!is_object($artLang)) {
1567:         return;
1568:     }
1569: 
1570:     $newidartlang = $artLang->get('idartlang');
1571: 
1572:     // Execute CEC hook
1573:     $param = array();
1574:     $param['src_art_lang'] = $srcArtLang->toArray();
1575:     $param['dest_art_lang'] = $dstArtLang->toArray();
1576:     $param['dest_art_lang']['idartlang'] = cSecurity::toInteger($newidartlang);
1577:     $param['dest_art_lang']['idlang'] = cSecurity::toInteger($dstlang);
1578:     $param['dest_art_lang']['idtplcfg'] = cSecurity::toInteger($newidtplcfg);
1579:     cApiCecHook::execute('Contenido.Article.conSyncArticle_AfterInsert', $param);
1580: 
1581:     // Copy content
1582:     conCopyContent($srcidartlang, $newidartlang);
1583: 
1584:     // Copy meta tags
1585:     conCopyMetaTags($srcidartlang, $newidartlang);
1586: }
1587: 
1588: /**
1589:  * Checks if an article is a start article of a category.
1590:  *
1591:  * @param int $idartlang
1592:  * @param int $idcat
1593:  * @param int $idlang
1594:  * @param cDb|NULL $db (NOT used)
1595:  * @return bool
1596:  */
1597: function isStartArticle($idartlang, $idcat, $idlang, $db = NULL) {
1598:     $oCatLangColl = new cApiCategoryLanguageCollection();
1599:     return $oCatLangColl->isStartArticle($idartlang, $idcat, $idlang);
1600: }
1601: 
1602: /**
1603:  * Returns all categories in which the given article is in.
1604:  *
1605:  * @param int $idart Article ID
1606:  * @param cDb|NULL $db If specified, uses the given db object (NOT used)
1607:  * @return array Flat array which contains all category id's
1608:  */
1609: function conGetCategoryAssignments($idart, $db = NULL) {
1610: 
1611:     // Return empty array if idart is null (or empty)
1612:     if (empty($idart)) {
1613:         return array();
1614:     }
1615: 
1616:     $categories = array();
1617:     $oCatArtColl = new cApiCategoryArticleCollection();
1618:     $entries = $oCatArtColl->getFieldsByWhereClause(array(
1619:         'idcat'
1620:     ), 'idart = ' . (int) $idart);
1621:     foreach ($entries as $entry) {
1622:         $categories[] = $entry['idcat'];
1623:     }
1624:     return $categories;
1625: }
1626: 
1627: /**
1628:  * Deletes old category article entries and other related entries from other
1629:  * tables.
1630:  *
1631:  * @global array $cfgClient
1632:  * @param int $idcat
1633:  * @param int $idart
1634:  * @param int $idartlang
1635:  * @param int $client
1636:  * @param int $lang
1637:  */
1638: function conRemoveOldCategoryArticle($idcat, $idart, $idartlang, $client, $lang) {
1639:     global $cfgClient;
1640: 
1641:     // Get category article that will no longer exist
1642:     $oCatArtColl = new cApiCategoryArticleCollection();
1643:     $oCatArt = $oCatArtColl->fetchByCategoryIdAndArticleId($idcat, $idart);
1644:     if (!is_object($oCatArt)) {
1645:         return;
1646:     }
1647: 
1648:     $idcatart = $oCatArt->get('idcatart');
1649: 
1650:     // Delete frome code cache and delete corresponding code
1651:     /**
1652:      * @var $file SplFileInfo
1653:      */
1654:     foreach (new DirectoryIterator($cfgClient[$client]['code']['path']) as $file) {
1655:         if ($file->isFile() === false) {
1656:             continue;
1657:         }
1658: 
1659:         $extension = substr($file, strrpos($file->getBasename(), '.') + 1);
1660:         if ($extension != 'php') {
1661:             continue;
1662:         }
1663: 
1664:         if (preg_match('/[0-9*].[0-9*].' . $idcatart . '/s', $file->getBasename())) {
1665:             cFileHandler::remove($cfgClient[$client]['code']['path'] . '/' . $file->getFilename());
1666:         }
1667:     }
1668: 
1669:     // Delete statistics
1670:     $oStatColl = new cApiStatCollection();
1671:     $oStatColl->deleteByCategoryArticleAndLanguage($idcatart, $lang);
1672: 
1673:     // Delete category article
1674:     $oCatArtColl->delete($idcatart);
1675: 
1676:     // Remove startidartlang
1677:     if (isStartArticle($idartlang, $idcat, $lang)) {
1678:         $oCatLang = new cApiCategoryLanguage();
1679:         $oCatLang->loadByCategoryIdAndLanguageId($idcat, $lang);
1680:         if ($oCatLang->isLoaded()) {
1681:             $oCatLang->set('startidartlang', 0);
1682:             $oCatLang->store();
1683:         }
1684:     }
1685: 
1686:     // Delete template configuration
1687:     $oArtLang = new cApiArticleLanguage();
1688:     $oArtLang->loadByArticleAndLanguageId($idart, $lang);
1689:     if ($oArtLang->isLoaded() && $oArtLang->get('idtplcfg') > 0) {
1690:         $oTplCfgColl = new cApiTemplateConfigurationCollection();
1691:         $oTplCfgColl->delete($oArtLang->get('idtplcfg'));
1692:     }
1693: }
1694: 
1695: ?>
CMS CONTENIDO 4.9.4 API documentation generated by ApiGen 2.8.0