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', date("Y-m-d H:i:s", strtotime($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:  * @param int $online optional, if 0 the article will be offline, if 1 article will be online
 462:  */
 463: function conMakeOnline($idart, $lang, $online = -1) {
 464:     $auth = cRegistry::getAuth();
 465: 
 466:     $artLang = new cApiArticleLanguage();
 467:     if (!$artLang->loadByArticleAndLanguageId($idart, $lang)) {
 468:         return;
 469:     }
 470: 
 471:     // Reverse current value
 472:     if($online === -1) {
 473:         $online = ($artLang->get('online') == 0)? 1 : 0;
 474:     }
 475: 
 476:     $artLang->set('online', $online);
 477: 
 478:     if ($online == 1) {
 479:         // Update published date and publisher
 480:         $artLang->set('published', date('Y-m-d H:i:s'));
 481:         $artLang->set('publishedby', $auth->auth['uname']);
 482:     }
 483: 
 484:     $artLang->store();
 485: }
 486: 
 487: /**
 488:  * Set the status from articles to online or offline.
 489:  *
 490:  * @param array $idarts All articles
 491:  * @param int $idlang
 492:  * @param bool $online
 493:  */
 494: function conMakeOnlineBulkEditing($idarts, $idlang, $online) {
 495:     $auth = cRegistry::getAuth();
 496: 
 497:     // get all articles with the given idart and idlang
 498:     $idartString = implode("','", $idarts);
 499:     $artLangCollection = new cApiArticleLanguageCollection();
 500:     $artLangCollection->select("`idart` IN ('" . $idartString . "') AND `idlang`='" . cSecurity::toInteger($idlang) . "'");
 501: 
 502:     // iterate over articles and set online flag
 503:     while (($artLang = $artLangCollection->next()) !== false) {
 504:         $artLang->set('online', $online);
 505:         if ($online == 1) {
 506:             // update published date and publisher
 507:             $artLang->set('published', date('Y-m-d H:i:s'));
 508:             $artLang->set('publishedby', $auth->auth['uname']);
 509:         }
 510:         $artLang->store();
 511:     }
 512: }
 513: 
 514: /**
 515:  * Toggle the lock status of an article
 516:  *
 517:  * @param int $idart Article Id
 518:  * @param int $lang Language Id
 519:  */
 520: function conLock($idart, $lang) {
 521:     $artLang = new cApiArticleLanguage();
 522:     if (!$artLang->loadByArticleAndLanguageId($idart, $lang)) {
 523:         return;
 524:     }
 525: 
 526:     $locked = ($artLang->get('locked') == 0)? 1 : 0;
 527: 
 528:     $artLang->set('locked', $locked);
 529:     $artLang->store();
 530: }
 531: 
 532: /**
 533:  * Freeze/Lock more articles.
 534:  *
 535:  * @param array $idarts All articles
 536:  * @param int $idlang
 537:  * @param bool $lock
 538:  */
 539: function conLockBulkEditing($idarts, $idlang, $lock) {
 540:     // get all articles with the given idart and idlang
 541:     $idartString = implode("','", $idarts);
 542:     $artLangCollection = new cApiArticleLanguageCollection();
 543:     $artLangCollection->select("`idart` IN ('" . $idartString . "') AND `idlang`='" . cSecurity::toInteger($idlang) . "'");
 544: 
 545:     // iterate over articles and set online flag
 546:     while (($artLang = $artLangCollection->next()) !== false) {
 547:         $artLang->set('locked', $lock);
 548:         $artLang->store();
 549:     }
 550: }
 551: 
 552: /**
 553:  * Checks if a article is locked or not
 554:  *
 555:  * @param int $idart Article Id
 556:  * @param int $lang Language Id
 557:  * @return bool
 558:  */
 559: function conIsLocked($idart, $lang) {
 560:     $artLang = new cApiArticleLanguage();
 561:     if (!$artLang->loadByArticleAndLanguageId($idart, $lang)) {
 562:         return false;
 563:     }
 564:     return (1 == $artLang->get('locked'));
 565: }
 566: 
 567: /**
 568:  * Toggle the online status of a category
 569:  *
 570:  * @param int $idcat Id of the category
 571:  * @param int $lang Id of the language
 572:  * @param int $status Status of the category
 573:  */
 574: function conMakeCatOnline($idcat, $lang, $status) {
 575:     global $cfg;
 576: 
 577:     $catLang = new cApiCategoryLanguage();
 578:     if (!$catLang->loadByCategoryIdAndLanguageId($idcat, $lang)) {
 579:         return;
 580:     }
 581: 
 582:     $status = (1 == $status)? 1 : 0;
 583: 
 584:     $catLang->set('visible', $status);
 585:     $catLang->set('lastmodified', date('Y-m-d H:i:s'));
 586:     $catLang->store();
 587: 
 588:     if ($cfg['pathresolve_heapcache'] == true && !$status = 0) {
 589:         $oPathresolveCacheColl = new cApiPathresolveCacheCollection();
 590:         $oPathresolveCacheColl->deleteByCategoryAndLanguage($idcat, $lang);
 591:     }
 592: }
 593: 
 594: /**
 595:  * Toggle the public status of a category Almost the same function as
 596:  * strMakePublic in functions.str.php (conDeeperCategoriesArray instead of
 597:  * strDeeperCategoriesArray)
 598:  *
 599:  * @param int $idcat Category Id
 600:  * @param int $lang Language Id
 601:  * @param bool $public Public status of the Article
 602:  */
 603: function conMakePublic($idcat, $lang, $public) {
 604:     // $catLang = new cApiCategoryLanguage();
 605:     // if (!$catLang->loadByCategoryIdAndLanguageId($idcat, $lang)) {
 606:     // return;
 607:     // }
 608: 
 609:     // $public = (1 == $public) ? 1 : 0;
 610: 
 611:     // $catLang->set('public', $public);
 612:     // $catLang->set('lastmodified', date('Y-m-d H:i:s'));
 613:     // $catLang->store();
 614:     $categories = conDeeperCategoriesArray($idcat);
 615:     foreach ($categories as $value) {
 616:         $oCatLang = new cApiCategoryLanguage();
 617:         $oCatLang->loadByCategoryIdAndLanguageId($value, $lang);
 618:         $oCatLang->set('public', $public);
 619:         $oCatLang->set('lastmodified', date('Y-m-d H:i:s'));
 620:         $oCatLang->store();
 621:     }
 622: }
 623: 
 624: /**
 625:  * Delete an Article and all other related entries
 626:  *
 627:  * @param int $idart Article Id
 628:  */
 629: function conDeleteart($idart) {
 630:     global $lang, $_cecRegistry, $cfgClient, $client;
 631: 
 632:     // Get article language
 633:     $artLang = new cApiArticleLanguage();
 634:     if (!$artLang->loadByArticleAndLanguageId($idart, $lang)) {
 635:         return;
 636:     }
 637: 
 638:     $idartlang = $artLang->get('idartlang');
 639:     $idtplcfg = $artLang->get('idtplcfg');
 640: 
 641:     $catArtColl = new cApiCategoryArticleCollection();
 642:     $cats = $catArtColl->getIdsByWhereClause("idart = " . (int) $idart);
 643: 
 644:     // Fetch idcat
 645:     foreach ($cats as $idcat) {
 646:         // Reset startidartlang
 647:         if (isStartArticle($idartlang, $idcat, $lang)) {
 648:             $catLang = new cApiCategoryLanguage();
 649:             $catLang->loadByCategoryIdAndLanguageId($idcat, $lang);
 650:             $catLang->set('startidartlang', 0);
 651:             $catLang->store();
 652:         }
 653:     }
 654: 
 655:     $contentColl = new cApiContentCollection();
 656:     $contentColl->deleteBy('idartlang', (int) $idartlang);
 657: 
 658:     $artLangColl = new cApiArticleLanguageCollection();
 659:     $artLangColl->delete((int) $idartlang);
 660: 
 661:     if ($idtplcfg != 0) {
 662:         $containerConfColl = new cApiContainerConfigurationCollection();
 663:         $containerConfColl->deleteBy('idtplcfg', (int) $idtplcfg);
 664: 
 665:         $tplConfColl = new cApiTemplateConfigurationCollection();
 666:         $tplConfColl->delete('idtplcfg', $idtplcfg);
 667:     }
 668: 
 669:     // Check if there are remaining languages
 670:     $artLangColl->resetQuery();
 671:     $artLangColl->select('idart = ' . (int) $idart);
 672:     if ($artLangColl->next()) {
 673:         return;
 674:     }
 675: 
 676:     $catArtColl = new cApiCategoryArticleCollection();
 677:     $catArtColl->select('idart = ' . (int) $idart);
 678:     while (($oCatArtItem = $catArtColl->next()) !== false) {
 679:         // Delete from code cache
 680:         if (cFileHandler::exists($cfgClient[$client]['code']['path'])) {
 681:             /**
 682:              * @var $file SplFileInfo
 683:              */
 684:             foreach (new DirectoryIterator($cfgClient[$client]['code']['path']) as $file) {
 685:                 if ($file->isFile() === false) {
 686:                     continue;
 687:                 }
 688: 
 689:                 $extension = substr($file, strrpos($file->getBasename(), '.') + 1);
 690:                 if ($extension != 'php') {
 691:                     continue;
 692:                 }
 693: 
 694:                 if (preg_match('/[0-9*].[0-9*].' . $oCatArtItem->get('idcatart') . '/s', $file->getBasename())) {
 695:                     cFileHandler::remove($cfgClient[$client]['code']['path'] . '/' . $file->getFilename());
 696:                 }
 697:             }
 698:         }
 699: 
 700:         // Delete from 'stat'-table
 701:         $statColl = new cApiStatCollection();
 702:         $statColl->deleteBy('idcatart', (int) $oCatArtItem->get('idcatart'));
 703:     }
 704: 
 705:     // delete values from con_cat_art only in the correct language
 706:     $catLangColl = new cApiCategoryLanguageCollection();
 707:     $catLangColl->select('`idlang`=' . cSecurity::toInteger($lang));
 708:     $idcats = $catLangColl->getAllIds();
 709:     $idcatsString = "('" . implode('\',\'', $idcats) . "')";
 710:     $catArtColl->resetQuery();
 711:     $catArtColl->deleteByWhereClause('`idart`=' . $idart . ' AND `idcat` IN ' . $idcatsString);
 712: 
 713:     // delete entry from con_art
 714:     $oArtColl = new cApiArticleCollection();
 715:     $oArtColl->delete((int) $idart);
 716: 
 717:     // this will delete all keywords associated with the article
 718:     $search = new cSearchIndex();
 719:     $search->start($idart, array());
 720: 
 721:     // Contenido Extension Chain
 722:     // @see docs/techref/plugins/Contenido Extension Chainer.pdf
 723:     $iterator = $_cecRegistry->getIterator("Contenido.Content.DeleteArticle");
 724:     while (($chainEntry = $iterator->next()) !== false) {
 725:         $chainEntry->execute($idart);
 726:     }
 727: }
 728: 
 729: /**
 730:  * Extract a number from a string
 731:  *
 732:  * @param string $string String var by reference
 733:  */
 734: function extractNumber(&$string) {
 735:     $string = preg_replace('/[^0-9]/', '', $string);
 736: }
 737: 
 738: /**
 739:  * Change the template of a category
 740:  *
 741:  * @param int $idcat Category Id
 742:  * @param int $idtpl Template Id
 743:  */
 744: function conChangeTemplateForCat($idcat, $idtpl) {
 745:     global $lang;
 746: 
 747:     $oCatLang = new cApiCategoryLanguage();
 748:     if (!$oCatLang->loadByCategoryIdAndLanguageId($idcat, $lang)) {
 749:         return;
 750:     }
 751: 
 752:     if ($oCatLang->get('idtplcfg')) {
 753:         // Delete old container configuration
 754:         $oContainerConfColl = new cApiContainerConfigurationCollection();
 755:         $oContainerConfColl->deleteBy('idtplcfg', (int) $oCatLang->get('idtplcfg'));
 756: 
 757:         // Delete old template configuration
 758:         $oTplConfColl = new cApiTemplateConfigurationCollection();
 759:         $oTplConfColl->delete('idtplcfg', (int) $oCatLang->get('idtplcfg'));
 760:     }
 761: 
 762:     // Parameter $idtpl is 0, reset the template
 763:     if (0 == $idtpl) {
 764:         $oCatLang->set('idtplcfg', 0);
 765:         $oCatLang->store();
 766:     } else {
 767:         // Check if a pre-configuration is assigned
 768:         $oTpl = new cApiTemplate();
 769:         $oTpl->loadBy('idtpl', (int) $idtpl);
 770: 
 771:         if (0 != $oTpl->get('idtplcfg')) {
 772:             // Template is pre-configured, create new configuration
 773:             $oTplConfColl = new cApiTemplateConfigurationCollection();
 774:             $oTplConf = $oTplConfColl->create($idtpl);
 775: 
 776:             // If there is a preconfiguration of template, copy its settings
 777:             // into templateconfiguration
 778:             $oTplConfColl->copyTemplatePreconfiguration($idtpl, $oTplConf->get('idtplcfg'));
 779: 
 780:             // Update category language
 781:             $oCatLang->set('idtplcfg', $oTplConf->get('idtplcfg'));
 782:             $oCatLang->store();
 783:         } else {
 784:             // Template is not pre-configured, create a new configuration.
 785:             $oTplConfColl = new cApiTemplateConfigurationCollection();
 786:             $oTplConf = $oTplConfColl->create($idtpl);
 787: 
 788:             // Update category language
 789:             $oCatLang->set('idtplcfg', $oTplConf->get('idtplcfg'));
 790:             $oCatLang->store();
 791:         }
 792:     }
 793: 
 794:     conGenerateCodeForAllartsInCategory($idcat);
 795: }
 796: 
 797: /**
 798:  * Returns category tree structure.
 799:  *
 800:  * @param int $client Uses global set client if not set
 801:  * @param int $lang Uses global set language if not set
 802:  * @return array
 803:  */
 804: function conFetchCategoryTree($client = false, $lang = false) {
 805:     if ($client === false) {
 806:         $client = $GLOBALS['client'];
 807:     }
 808:     if ($lang === false) {
 809:         $lang = $GLOBALS['lang'];
 810:     }
 811: 
 812:     $oCatTreeColl = new cApiCategoryTreeCollection();
 813:     $aCatTree = $oCatTreeColl->getCategoryTreeStructureByClientIdAndLanguageId($client, $lang);
 814: 
 815:     return $aCatTree;
 816: }
 817: 
 818: /**
 819:  * Fetch all deeper categories by a given id
 820:  *
 821:  * @param int $idcat Id of category
 822:  * @return array Array with all deeper categories
 823:  */
 824: function conDeeperCategoriesArray($idcat) {
 825:     global $client;
 826: 
 827:     $oCatColl = new cApiCategoryCollection();
 828:     $aCatIds = $oCatColl->getAllCategoryIdsRecursive($idcat, $client);
 829: 
 830:     return $aCatIds;
 831: }
 832: 
 833: /**
 834:  * Recursive function to create an location string
 835:  *
 836:  * @param int $idcat ID of the starting category
 837:  * @param string $seperator Seperation string
 838:  * @param string $catStr Category location string (by reference)
 839:  * @param bool $makeLink Create location string with links
 840:  * @param string $linkClass Stylesheet class for the links
 841:  * @param int $firstTreeElementToUse First navigation Level location string
 842:  *        should be printed out (first level = 0!!)
 843:  * @param int $uselang Id of language
 844:  * @param bool $final
 845:  * @param bool $usecache
 846:  * @return string Location string
 847:  */
 848: function conCreateLocationString($idcat, $seperator, &$catStr, $makeLink = false, $linkClass = '', $firstTreeElementToUse = 0, $uselang = 0, $final = true, $usecache = false) {
 849:     global $cfg, $client, $cfgClient, $lang, $sess;
 850: 
 851:     if ($idcat == 0) {
 852:         $catStr = i18n("Lost and found");
 853:         return;
 854:     }
 855: 
 856:     if ($uselang == 0) {
 857:         $uselang = $lang;
 858:     }
 859: 
 860:     $locationStringCache = cRegistry::getAppVar('locationStringCache');
 861:     $locationStringCacheFile = $cfgClient[$client]['cache']['path'] . "locationstring-cache-$uselang.txt";
 862: 
 863:     if ($final == true && $usecache == true) {
 864:         if (!is_array($locationStringCache)) {
 865:             if (cFileHandler::exists($locationStringCacheFile)) {
 866:                 $locationStringCache = unserialize(cFileHandler::read($locationStringCacheFile));
 867:             } else {
 868:                 $locationStringCache = array();
 869:             }
 870:             cRegistry::setAppVar('locationStringCache', $locationStringCache);
 871:         }
 872: 
 873:         if (array_key_exists($idcat, $locationStringCache)) {
 874:             if ($locationStringCache[$idcat]['expires'] > time()) {
 875:                 $catStr = $locationStringCache[$idcat]['name'];
 876:                 return;
 877:             }
 878:         }
 879:     }
 880: 
 881:     $db = cRegistry::getDb();
 882: 
 883:     $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";
 884: 
 885:     $sql = $db->prepare($sql, array(
 886:         'cat_lang' => $cfg['tab']['cat_lang'],
 887:         'cat' => $cfg['tab']['cat'],
 888:         'cat_tree' => $cfg['tab']['cat_tree'],
 889:         'idlang' => (int) $uselang,
 890:         'idclient' => (int) $client,
 891:         'idcat' => (int) $idcat
 892:     ));
 893:     $db->query($sql);
 894:     $db->nextRecord();
 895: 
 896:     if ($db->f('level') >= $firstTreeElementToUse) {
 897:         $name = $db->f('name');
 898:         $parentid = $db->f('parentid');
 899: 
 900:         // create link
 901:         if ($makeLink == true) {
 902:             $linkUrl = $sess->url("front_content.php?idcat=$idcat");
 903:             $name = '<a href="' . $linkUrl . '" class="' . $linkClass . '">' . $name . '</a>';
 904:         }
 905: 
 906:         $tmp_cat_str = $name . $seperator . $catStr;
 907:         $catStr = $tmp_cat_str;
 908:     }
 909: 
 910:     if ($parentid != 0) {
 911:         conCreateLocationString($parentid, $seperator, $catStr, $makeLink, $linkClass, $firstTreeElementToUse, $uselang, false);
 912:     } else {
 913:         $sep_length = strlen($seperator);
 914:         $str_length = strlen($catStr);
 915:         $tmp_length = $str_length - $sep_length;
 916:         $catStr = substr($catStr, 0, $tmp_length);
 917:     }
 918: 
 919:     if ($final == true && $usecache == true) {
 920:         $locationStringCache[$idcat]['name'] = $catStr;
 921:         $locationStringCache[$idcat]['expires'] = time() + 3600;
 922: 
 923:         if (is_writable($cfgClient[$client]['cache']['path'])) {
 924:             cFileHandler::write($locationStringCacheFile, serialize($locationStringCache));
 925:         }
 926:         cRegistry::setAppVar('locationStringCache', $locationStringCache);
 927:     }
 928: }
 929: 
 930: /**
 931:  * Set a start-article @fixme Do we still need the isstart.
 932:  * The old start
 933:  * compatibility has already been removed...
 934:  *
 935:  * @param int $idcatart Idcatart of the article
 936:  * @param bool $isstart Start article flag
 937:  */
 938: function conMakeStart($idcatart, $isstart) {
 939:     global $lang;
 940: 
 941:     // Load category article
 942:     $oCatArt = new cApiCategoryArticle((int) $idcatart);
 943:     if (!$oCatArt->isLoaded()) {
 944:         return;
 945:     }
 946:     $idart = $oCatArt->get('idart');
 947:     $idcat = $oCatArt->get('idcat');
 948: 
 949:     // Load article language
 950:     $oArtLang = new cApiArticleLanguage();
 951:     if (!$oArtLang->loadByArticleAndLanguageId($idart, $lang)) {
 952:         return;
 953:     }
 954:     $idartlang = $oArtLang->get('idartlang');
 955: 
 956:     // Update startidartlang for category language
 957:     $oCatLang = new cApiCategoryLanguage();
 958:     if ($oCatLang->loadByCategoryIdAndLanguageId($idcat, $lang)) {
 959:         if ($isstart == 1) {
 960:             $oCatLang->set('startidartlang', $idartlang);
 961:         } else {
 962:             $oCatLang->set('startidartlang', 0);
 963:         }
 964:         $oCatLang->store();
 965:     }
 966: 
 967:     if ($isstart == 1) {
 968:         // Deactivate time management if article is a start article
 969:         $oArtLang->set('timemgmt', 0);
 970:         $oArtLang->store();
 971:     }
 972: }
 973: 
 974: /**
 975:  * Create code for one article in all categorys
 976:  *
 977:  * @param int $idart Article ID
 978:  */
 979: function conGenerateCodeForArtInAllCategories($idart) {
 980:     $oCatArtColl = new cApiCategoryArticleCollection();
 981:     $ids = $oCatArtColl->getIdsByWhereClause('idart = ' . (int) $idart);
 982:     conSetCodeFlagBulkEditing($ids);
 983: }
 984: 
 985: /**
 986:  * Generate code for all articles in a category
 987:  *
 988:  * @param int $idcat Category ID
 989:  */
 990: function conGenerateCodeForAllArtsInCategory($idcat) {
 991:     $oCatArtColl = new cApiCategoryArticleCollection();
 992:     $ids = $oCatArtColl->getIdsByWhereClause('idcat = ' . (int) $idcat);
 993:     conSetCodeFlagBulkEditing($ids);
 994: }
 995: 
 996: /**
 997:  * Generate code for the active client
 998:  */
 999: function conGenerateCodeForClient() {
1000:     global $client;
1001:     $oCatArtColl = new cApiCategoryArticleCollection();
1002:     $ids = $oCatArtColl->getAllIdsByClientId($client);
1003:     conSetCodeFlagBulkEditing($ids);
1004: }
1005: 
1006: /**
1007:  * Create code for all arts using the same layout
1008:  *
1009:  * @param int $idlay Layout-ID
1010:  */
1011: function conGenerateCodeForAllartsUsingLayout($idlay) {
1012:     global $cfg;
1013: 
1014:     $db = cRegistry::getDb();
1015: 
1016:     $sql = "SELECT idtpl FROM " . $cfg["tab"]["tpl"] . " WHERE idlay='" . cSecurity::toInteger($idlay) . "'";
1017:     $db->query($sql);
1018:     while ($db->nextRecord()) {
1019:         conGenerateCodeForAllartsUsingTemplate($db->f("idtpl"));
1020:     }
1021: }
1022: 
1023: /**
1024:  * Create code for all articles using the same module
1025:  *
1026:  * @param int $idmod Module id
1027:  */
1028: function conGenerateCodeForAllartsUsingMod($idmod) {
1029:     $oContainerColl = new cApiContainerCollection();
1030:     $rsList = $oContainerColl->getFieldsByWhereClause(array(
1031:         'idtpl'
1032:     ), 'idmod = ' . (int) $idmod);
1033:     foreach ($rsList as $rs) {
1034:         conGenerateCodeForAllArtsUsingTemplate($rs['idtpl']);
1035:     }
1036: }
1037: 
1038: /**
1039:  * Generate code for all articles using one template
1040:  *
1041:  * @param int $idtpl Template-Id
1042:  */
1043: function conGenerateCodeForAllArtsUsingTemplate($idtpl) {
1044:     global $cfg, $client;
1045: 
1046:     $db = cRegistry::getDb();
1047: 
1048:     $oCatArtColl = new cApiCategoryArticleCollection();
1049: 
1050:     // Search all categories
1051:     $sql = "SELECT
1052:                 b.idcat
1053:             FROM
1054:                 " . $cfg['tab']['tpl_conf'] . " AS a,
1055:                 " . $cfg['tab']['cat_lang'] . " AS b,
1056:                 " . $cfg['tab']['cat'] . " AS c
1057:             WHERE
1058:                 a.idtpl     = " . cSecurity::toInteger($idtpl) . " AND
1059:                 b.idtplcfg  = a.idtplcfg AND
1060:                 c.idclient  = " . cSecurity::toInteger($client) . " AND
1061:                 b.idcat     = c.idcat";
1062: 
1063:     $db->query($sql);
1064: 
1065:     while ($db->nextRecord()) {
1066:         $oCatArtColl->resetQuery();
1067:         $ids = $oCatArtColl->getIdsByWhereClause('idcat = ' . cSecurity::toInteger($db->f('idcat')));
1068:         foreach ($ids as $id) {
1069:             conSetCodeFlag($id);
1070:         }
1071:     }
1072: 
1073:     // Search all articles
1074:     $sql = "SELECT
1075:                 b.idart
1076:             FROM
1077:                 " . $cfg['tab']['tpl_conf'] . " AS a,
1078:                 " . $cfg['tab']['art_lang'] . " AS b,
1079:                 " . $cfg['tab']['art'] . " AS c
1080:             WHERE
1081:                 a.idtpl     = " . cSecurity::toInteger($idtpl) . " AND
1082:                 b.idtplcfg  = a.idtplcfg AND
1083:                 c.idclient  = " . cSecurity::toInteger($client) . " AND
1084:                 b.idart     = c.idart";
1085: 
1086:     $db->query($sql);
1087: 
1088:     while ($db->nextRecord()) {
1089:         $oCatArtColl->resetQuery();
1090:         $ids = $oCatArtColl->getIdsByWhereClause('idart = ' . (int) $db->f('idart'));
1091:         foreach ($ids as $id) {
1092:             conSetCodeFlag($id);
1093:         }
1094:     }
1095: }
1096: 
1097: /**
1098:  * Create code for all articles
1099:  */
1100: function conGenerateCodeForAllArts() {
1101:     global $cfg;
1102: 
1103:     $db = cRegistry::getDb();
1104: 
1105:     $sql = "SELECT idcatart FROM " . $cfg['tab']['cat_art'];
1106:     $db->query($sql);
1107:     while ($db->nextRecord()) {
1108:         conSetCodeFlag($db->f("idcatart"));
1109:     }
1110: }
1111: 
1112: /**
1113:  * Set code creation flag for one category article id to true
1114:  *
1115:  * @param int $idcatart Category article id
1116:  */
1117: function conSetCodeFlag($idcatart) {
1118:     global $client, $cfgClient;
1119: 
1120:     // Set 'createcode' flag
1121:     $oCatArtColl = new cApiCategoryArticleCollection();
1122:     $oCatArtColl->setCreateCodeFlag($idcatart);
1123: 
1124:     // Delete also generated code files from file system
1125:     if (cFileHandler::exists($cfgClient[$client]['code']['path'])) {
1126:         /**
1127:          * @var $file SplFileInfo
1128:          */
1129:         foreach (new DirectoryIterator($cfgClient[$client]['code']['path']) as $file) {
1130:             if ($file->isFile() === false) {
1131:                 continue;
1132:             }
1133: 
1134:             $extension = substr($file, strrpos($file->getBasename(), '.') + 1);
1135:             if ($extension != 'php') {
1136:                 continue;
1137:             }
1138: 
1139:             if (preg_match('/[0-9*].[0-9*].' . $idcatart . '/s', $file->getBasename())) {
1140:                 cFileHandler::remove($cfgClient[$client]['code']['path'] . '/' . $file->getFilename());
1141:             }
1142:         }
1143:     }
1144: }
1145: 
1146: /**
1147:  * Set code creation flag for several category article ids to true
1148:  *
1149:  * @param array $idcatarts List of category article ids
1150:  */
1151: function conSetCodeFlagBulkEditing(array $idcatarts) {
1152:     global $client, $cfgClient;
1153: 
1154:     if (count($idcatarts) == 0) {
1155:         return;
1156:     }
1157: 
1158:     // Set 'createcode' flag
1159:     $oCatArtColl = new cApiCategoryArticleCollection();
1160:     $oCatArtColl->setCreateCodeFlag($idcatarts);
1161: 
1162:     if (cFileHandler::exists($cfgClient[$client]['code']['path']) === false) {
1163:         return;
1164:     }
1165: 
1166:     // Delete also generated code files from file system
1167:     foreach ($idcatarts as $id) {
1168:         /**
1169:          * @var $file SplFileInfo
1170:          */
1171:         foreach (new DirectoryIterator($cfgClient[$client]['code']['path']) as $file) {
1172:             if ($file->isFile() === false) {
1173:                 continue;
1174:             }
1175: 
1176:             $extension = substr($file, strrpos($file->getBasename(), '.') + 1);
1177:             if ($extension != 'php') {
1178:                 continue;
1179:             }
1180: 
1181:             if (preg_match('/[0-9*].[0-9*].' . $id . '/s', $file->getBasename())) {
1182:                 cFileHandler::remove($cfgClient[$client]['code']['path'] . '/' . $file->getFilename());
1183:             }
1184:         }
1185:     }
1186: }
1187: 
1188: /**
1189:  * Set articles on/offline for the time management function
1190:  */
1191: function conFlagOnOffline() {
1192:     global $cfg;
1193: 
1194:     $db = cRegistry::getDb();
1195: 
1196:     $oArtLangColl = new cApiArticleLanguageCollection();
1197: 
1198:     // Set all articles which are before our starttime to offline
1199:     $where = "NOW() < datestart AND datestart != '0000-00-00 00:00:00' AND datestart IS NOT NULL AND timemgmt = 1";
1200:     $ids = $oArtLangColl->getIdsByWhereClause($where);
1201:     foreach ($ids as $id) {
1202:         $sql = "UPDATE " . $cfg['tab']['art_lang'] . " SET online = 0 WHERE idartlang = " . (int) $id;
1203:         $db->query($sql);
1204:     }
1205: 
1206:     // Set all articles which are in between of our start/endtime to online
1207:     $where = "NOW() > datestart AND (NOW() < dateend OR dateend = '0000-00-00 00:00:00') AND " . "online = 0 AND timemgmt = 1";
1208:     $oArtLangColl->resetQuery();
1209:     $ids = $oArtLangColl->getIdsByWhereClause($where);
1210:     foreach ($ids as $id) {
1211:         $sql = "UPDATE " . $cfg['tab']['art_lang'] . " SET online = 1, published = datestart WHERE idartlang = " . (int) $id;
1212:         $db->query($sql);
1213:     }
1214: 
1215:     // Set all articles after our endtime to offline
1216:     $where = "NOW() > dateend AND dateend != '0000-00-00 00:00:00' AND timemgmt = 1";
1217:     $oArtLangColl->resetQuery();
1218:     $ids = $oArtLangColl->getIdsByWhereClause($where);
1219:     foreach ($ids as $id) {
1220:         $sql = "UPDATE " . $cfg['tab']['art_lang'] . " SET online = 0 WHERE idartlang = " . (int) $id;
1221:         $db->query($sql);
1222:     }
1223: }
1224: 
1225: /**
1226:  * Move articles for the time management function
1227:  */
1228: function conMoveArticles() {
1229:     global $cfg;
1230: 
1231:     $db = cRegistry::getDb();
1232: 
1233:     // Perform after-end updates
1234:     $fields = array(
1235:         'idartlang',
1236:         'idart',
1237:         'time_move_cat',
1238:         'time_target_cat',
1239:         'time_online_move'
1240:     );
1241:     $where = "NOW() > dateend AND dateend != '0000-00-00 00:00:00' AND timemgmt = 1 AND time_move_cat = 1";
1242:     $oArtLangColl = new cApiArticleLanguageCollection();
1243:     $rsList = $oArtLangColl->getFieldsByWhereClause($fields, $where);
1244: 
1245:     foreach ($rsList as $rs) {
1246:         $online = ($rs['time_online_move'] == '1')? 1 : 0;
1247:         $sql = array();
1248:         $sql[] = 'UPDATE ' . $cfg['tab']['art_lang'] . ' SET timemgmt = 0, online = 0 WHERE idartlang = ' . (int) $rs['idartlang'] . ';';
1249:         $sql[] = 'UPDATE ' . $cfg['tab']['cat_art'] . ' SET idcat = ' . (int) $rs['time_target_cat'] . ', createcode = 1 WHERE idart = ' . (int) $rs['idart'] . ';';
1250:         $sql[] = 'UPDATE ' . $cfg['tab']['art_lang'] . ' SET online = ' . (int) $online . ' WHERE idart = ' . (int) $rs['idart'] . ';';
1251: 
1252:         // $sql = implode("\n", $sql);
1253:         // cDebug::out($sql);
1254:         $db->query($sql[0]);
1255:         $db->query($sql[1]);
1256:         $db->query($sql[2]);
1257: 
1258:         // Execute CEC hook
1259:         cApiCecHook::execute('Contenido.Article.conMoveArticles_Loop', $rs);
1260:     }
1261: }
1262: 
1263: /**
1264:  * Copies template configuration entry from source template configuration.
1265:  *
1266:  * @param int $srcidtplcfg
1267:  */
1268: function conCopyTemplateConfiguration($srcidtplcfg) {
1269:     $oTemplateConf = new cApiTemplateConfiguration((int) $srcidtplcfg);
1270:     if (!$oTemplateConf->isLoaded()) {
1271:         return NULL;
1272:     }
1273: 
1274:     $oTemplateConfColl = new cApiTemplateConfigurationCollection();
1275:     $oNewTemplateConf = $oTemplateConfColl->create($oTemplateConf->get('idtpl'));
1276:     return (is_object($oNewTemplateConf))? $oNewTemplateConf->get('idtplcfg') : NULL;
1277: }
1278: 
1279: /**
1280:  * Copies container configuration entries from source container configuration to
1281:  * destination container configuration.
1282:  *
1283:  * @param int $srcidtplcfg
1284:  * @param int $dstidtplcfg
1285:  */
1286: function conCopyContainerConf($srcidtplcfg, $dstidtplcfg) {
1287:     $counter = 0;
1288:     $oContainerConfColl = new cApiContainerConfigurationCollection();
1289:     $oContainerConfColl->select('idtplcfg = ' . cSecurity::toInteger($srcidtplcfg));
1290:     while (($oContainerConf = $oContainerConfColl->next()) !== false) {
1291:         $oNewContainerConfColl = new cApiContainerConfigurationCollection();
1292:         $oNewContainerConfColl->copyItem($oContainerConf, array(
1293:             'idtplcfg' => cSecurity::toInteger($dstidtplcfg)
1294:         ));
1295:         $counter++;
1296:     }
1297:     return ($counter > 0)? true : false;
1298: }
1299: 
1300: /**
1301:  * Copies content entries from source article language to destination article
1302:  * language.
1303:  *
1304:  * @param int $srcidartlang
1305:  * @param int $dstidartlang
1306:  */
1307: function conCopyContent($srcidartlang, $dstidartlang) {
1308:     $oContentColl = new cApiContentCollection();
1309:     $oContentColl->select('idartlang = ' . cSecurity::toInteger($srcidartlang));
1310:     while (($oContent = $oContentColl->next()) !== false) {
1311:         $oNewContentColl = new cApiContentCollection();
1312:         $oNewContentColl->copyItem($oContent, array(
1313:             'idartlang' => cSecurity::toInteger($dstidartlang)
1314:         ));
1315:     }
1316: }
1317: 
1318: /**
1319:  * Copies meta tag entries from source article language to destination article
1320:  * language.
1321:  *
1322:  * @param int $srcidartlang
1323:  * @param int $dstidartlang
1324:  */
1325: function conCopyMetaTags($srcidartlang, $dstidartlang) {
1326:     $oMetaTagColl = new cApiMetaTagCollection();
1327:     $oMetaTagColl->select('idartlang = ' . cSecurity::toInteger($srcidartlang));
1328:     while (($oMetaTag = $oMetaTagColl->next()) !== false) {
1329:         $oNewMetaTagColl = new cApiMetaTagCollection();
1330:         $oNewMetaTagColl->copyItem($oMetaTag, array(
1331:             'idartlang' => cSecurity::toInteger($dstidartlang)
1332:         ));
1333:     }
1334: }
1335: 
1336: /**
1337:  * Copy article language entry.
1338:  *
1339:  * @global array $cfg
1340:  * @global int $lang
1341:  * @param int $srcidart
1342:  * @param int $dstidart
1343:  * @param int $newtitle
1344:  * @param int $useCopyLabel
1345:  */
1346: function conCopyArtLang($srcidart, $dstidart, $newtitle, $useCopyLabel = true) {
1347:     global $auth, $lang;
1348: 
1349:     $oSrcArtLang = new cApiArticleLanguage();
1350:     if (!$oSrcArtLang->loadByArticleAndLanguageId($srcidart, $lang)) {
1351:         return;
1352:     }
1353: 
1354:     // Copy the template configuration
1355:     if ($oSrcArtLang->get('idtplcfg') != 0) {
1356:         $newidtplcfg = conCopyTemplateConfiguration($oSrcArtLang->get('idtplcfg'));
1357:         conCopyContainerConf($oSrcArtLang->get('idtplcfg'), $newidtplcfg);
1358:     }
1359: 
1360:     $idart = $dstidart;
1361:     $idlang = $oSrcArtLang->get('idlang');
1362:     $idtplcfg = $newidtplcfg;
1363: 
1364:     if ($newtitle != '') {
1365:         $title = sprintf($newtitle, $oSrcArtLang->get('title'));
1366:     } else if ($useCopyLabel == true) {
1367:         $title = sprintf(i18n('%s (Copy)'), $oSrcArtLang->get('title'));
1368:     } else {
1369:         $title = $oSrcArtLang->get('title');
1370:     }
1371: 
1372:     // Create an article language entry
1373:     $oArtLangColl = new cApiArticleLanguageCollection();
1374:     $fieldsToOverwrite = array(
1375:         'idart' => $idart,
1376:         'idlang' => $idlang,
1377:         'idtplcfg' => cSecurity::toInteger($idtplcfg),
1378:         'online' => 0,
1379:         'title' => $title,
1380:         'created' => date('Y-m-d H:i:s'),
1381:         'lastmodified' => date('Y-m-d H:i:s'),
1382:         'modifiedby' => $auth->auth['uname'],
1383:         'published' => '',
1384:         'publishedby' => ''
1385:     );
1386:     $oNewArtLang = $oArtLangColl->copyItem($oSrcArtLang, $fieldsToOverwrite);
1387: 
1388:     if (!is_object($oNewArtLang)) {
1389:         return;
1390:     }
1391: 
1392:     // Copy content
1393:     conCopyContent($oSrcArtLang->get('idartlang'), $oNewArtLang->get('idartlang'));
1394: 
1395:     // Copy meta tags
1396:     conCopyMetaTags($oSrcArtLang->get('idartlang'), $oNewArtLang->get('idartlang'));
1397: 
1398:     // Execute CEC hook
1399:     cApiCecHook::execute('Contenido.Article.conCopyArtLang_AfterInsert', array(
1400:         'idartlang' => cSecurity::toInteger($oNewArtLang->get('idartlang')),
1401:         'idart' => cSecurity::toInteger($idart),
1402:         'idlang' => cSecurity::toInteger($idlang),
1403:         'idtplcfg' => cSecurity::toInteger($idtplcfg),
1404:         'title' => $title
1405:     ));
1406: 
1407:     // Update keyword list for new article
1408:     conMakeArticleIndex($oNewArtLang->get('idartlang'), $idart);
1409: }
1410: 
1411: /**
1412:  * Copy article entry.
1413:  *
1414:  * @global object $auth
1415:  * @param int $srcidart
1416:  * @param int $targetcat
1417:  * @param string $newtitle
1418:  * @param bool $useCopyLabel
1419:  * @return bool
1420:  */
1421: function conCopyArticle($srcidart, $targetcat = 0, $newtitle = '', $useCopyLabel = true) {
1422:     // Get source article
1423:     $oSrcArt = new cApiArticle((int) $srcidart);
1424:     if (!$oSrcArt->isLoaded()) {
1425:         return false;
1426:     }
1427:     $idclient = $oSrcArt->get('idclient');
1428: 
1429:     // Create destination article
1430:     $oArtCollection = new cApiArticleCollection();
1431:     $oNewArt = $oArtCollection->create($idclient);
1432:     if (!is_object($oNewArt)) {
1433:         return false;
1434:     }
1435:     $dstidart = $oNewArt->get('idart');
1436: 
1437:     conCopyArtLang($srcidart, $dstidart, $newtitle, $useCopyLabel);
1438: 
1439:     // Get source category article entries
1440:     $oCatArtColl = new cApiCategoryArticleCollection();
1441:     $oCatArtColl->select('idart = ' . (int) $srcidart);
1442:     while (($oCatArt = $oCatArtColl->next()) !== false) {
1443:         // Insert destination category article entry
1444:         $oCatArtColl2 = new cApiCategoryArticleCollection();
1445:         $fieldsToOverwrite = array(
1446:             'idcat' => ($targetcat != 0)? $targetcat : $oCatArt->get('idcat'),
1447:             'idart' => $dstidart,
1448:             'status' => ($oCatArt->get('status') !== '')? $oCatArt->get('status') : 0,
1449:             'createcode' => 1,
1450:             'is_start' => 0
1451:         );
1452:         $oCatArtColl2->copyItem($oCatArt, $fieldsToOverwrite);
1453: 
1454:         // If true, exit while routine, only one category entry is needed
1455:         if ($targetcat != 0) {
1456:             break;
1457:         }
1458:     }
1459: 
1460:     // Contenido Extension Chain
1461:     // @see docs/techref/plugins/Contenido Extension Chainer.pdf
1462:     $_cecRegistry = cApiCecRegistry::getInstance();
1463:     $iterator = $_cecRegistry->getIterator('Contenido.Content.CopyArticle');
1464:     while (($chainEntry = $iterator->next()) !== false) {
1465:         $chainEntry->execute($srcidart, $dstidart);
1466:     }
1467: 
1468:     return $dstidart;
1469: }
1470: 
1471: /**
1472:  *
1473:  * @todo Returns something....
1474:  * @global array $cfg
1475:  * @global int $client
1476:  * @global int $lang
1477:  * @param int $idcat
1478:  * @param int $minLevel
1479:  * @return int
1480:  */
1481: function conGetTopmostCat($idcat, $minLevel = 0) {
1482:     global $cfg, $client, $lang;
1483: 
1484:     $db = cRegistry::getDb();
1485: 
1486:     $sql = "SELECT a.name AS name, a.idcat AS idcat, b.parentid AS parentid, c.level AS level
1487:             FROM `:cat_lang` AS a, `:cat` AS b, `:cat_tree` AS c
1488:             WHERE a.idlang = :idlang AND b.idclient = :idclient AND b.idcat = :idcat
1489:             AND c.idcat = b.idcat AND a.idcat = b.idcat";
1490: 
1491:     $sql = $db->prepare($sql, array(
1492:         'cat_lang' => $cfg['tab']['cat_lang'],
1493:         'cat' => $cfg['tab']['cat'],
1494:         'cat_tree' => $cfg['tab']['cat_tree'],
1495:         'idlang' => (int) $lang,
1496:         'idclient' => (int) $client,
1497:         'idcat' => (int) $idcat
1498:     ));
1499:     $db->query($sql);
1500:     $db->nextRecord();
1501: 
1502:     $name = $db->f('name');
1503:     $parentid = $db->f('parentid');
1504:     $thislevel = $db->f('level');
1505: 
1506:     if ($parentid != 0 && $thislevel >= $minLevel) {
1507:         return conGetTopmostCat($parentid, $minLevel);
1508:     } else {
1509:         return $idcat;
1510:     }
1511: }
1512: 
1513: /**
1514:  * Synchronizes an article from source language to destination language.
1515:  *
1516:  * @param int $idart Article id
1517:  * @param int $srclang Source language id
1518:  * @param int $dstlang Destination language id
1519:  */
1520: function conSyncArticle($idart, $srclang, $dstlang) {
1521:     $auth = cRegistry::getAuth();
1522: 
1523:     // Check if article has already been synced to target language
1524:     $dstArtLang = new cApiArticleLanguage();
1525:     $dstArtLang->loadByArticleAndLanguageId($idart, $dstlang);
1526:     if ($dstArtLang->isLoaded()) {
1527:         // Article already exists in detination language
1528:         return;
1529:     }
1530: 
1531:     $srcArtLang = new cApiArticleLanguage();
1532:     $srcArtLang->loadByArticleAndLanguageId($idart, $srclang);
1533:     if (!$srcArtLang->isLoaded()) {
1534:         // Couldn't load article in source language
1535:         return;
1536:     }
1537:     $srcidartlang = $srcArtLang->get('idartlang');
1538: 
1539:     if ($srcArtLang->get('idtplcfg') != 0) {
1540:         $newidtplcfg = tplcfgDuplicate($srcArtLang->get('idtplcfg'));
1541:     } else {
1542:         $newidtplcfg = 0;
1543:     }
1544: 
1545:     // Create an article language entry for destination language
1546:     $artLangColl = new cApiArticleLanguageCollection();
1547:     $fieldsToOverwrite = array(
1548:         'idart' => $idart,
1549:         'idlang' => $dstlang,
1550:         'artspec' => 0,
1551:         'online' => 0,
1552:         'created' => date('Y-m-d H:i:s'),
1553:         'lastmodified' => date('Y-m-d H:i:s'),
1554:         'modifiedby' => $auth->auth['uname'],
1555:         'published' => '',
1556:         'publishedby' => '',
1557:         'timemgmt' => 0,
1558:         'datestart' => '',
1559:         'dateend' => '',
1560:         'status' => 0,
1561:         'time_move_cat' => 0,
1562:         'time_target_cat' => 0,
1563:         'time_online_move' => 0,
1564:         'free_use_01' => '',
1565:         'free_use_02' => '',
1566:         'free_use_03' => ''
1567:     );
1568:     $artLang = $artLangColl->copyItem($srcArtLang, $fieldsToOverwrite);
1569:     if (!is_object($artLang)) {
1570:         return;
1571:     }
1572: 
1573:     $newidartlang = $artLang->get('idartlang');
1574: 
1575:     // Execute CEC hook
1576:     $param = array();
1577:     $param['src_art_lang'] = $srcArtLang->toArray();
1578:     $param['dest_art_lang'] = $dstArtLang->toArray();
1579:     $param['dest_art_lang']['idartlang'] = cSecurity::toInteger($newidartlang);
1580:     $param['dest_art_lang']['idlang'] = cSecurity::toInteger($dstlang);
1581:     $param['dest_art_lang']['idtplcfg'] = cSecurity::toInteger($newidtplcfg);
1582:     cApiCecHook::execute('Contenido.Article.conSyncArticle_AfterInsert', $param);
1583: 
1584:     // Copy content
1585:     conCopyContent($srcidartlang, $newidartlang);
1586: 
1587:     // Copy meta tags
1588:     conCopyMetaTags($srcidartlang, $newidartlang);
1589: }
1590: 
1591: /**
1592:  * Checks if an article is a start article of a category.
1593:  *
1594:  * @param int $idartlang
1595:  * @param int $idcat
1596:  * @param int $idlang
1597:  * @param cDb|NULL $db (NOT used)
1598:  * @return bool
1599:  */
1600: function isStartArticle($idartlang, $idcat, $idlang, $db = NULL) {
1601:     $oCatLangColl = new cApiCategoryLanguageCollection();
1602:     return $oCatLangColl->isStartArticle($idartlang, $idcat, $idlang);
1603: }
1604: 
1605: /**
1606:  * Returns all categories in which the given article is in.
1607:  *
1608:  * @param int $idart Article ID
1609:  * @param cDb|NULL $db If specified, uses the given db object (NOT used)
1610:  * @return array Flat array which contains all category id's
1611:  */
1612: function conGetCategoryAssignments($idart, $db = NULL) {
1613: 
1614:     // Return empty array if idart is null (or empty)
1615:     if (empty($idart)) {
1616:         return array();
1617:     }
1618: 
1619:     $categories = array();
1620:     $oCatArtColl = new cApiCategoryArticleCollection();
1621:     $entries = $oCatArtColl->getFieldsByWhereClause(array(
1622:         'idcat'
1623:     ), 'idart = ' . (int) $idart);
1624:     foreach ($entries as $entry) {
1625:         $categories[] = $entry['idcat'];
1626:     }
1627:     return $categories;
1628: }
1629: 
1630: /**
1631:  * Deletes old category article entries and other related entries from other
1632:  * tables.
1633:  *
1634:  * @global array $cfgClient
1635:  * @param int $idcat
1636:  * @param int $idart
1637:  * @param int $idartlang
1638:  * @param int $client
1639:  * @param int $lang
1640:  */
1641: function conRemoveOldCategoryArticle($idcat, $idart, $idartlang, $client, $lang) {
1642:     global $cfgClient;
1643: 
1644:     // Get category article that will no longer exist
1645:     $oCatArtColl = new cApiCategoryArticleCollection();
1646:     $oCatArt = $oCatArtColl->fetchByCategoryIdAndArticleId($idcat, $idart);
1647:     if (!is_object($oCatArt)) {
1648:         return;
1649:     }
1650: 
1651:     $idcatart = $oCatArt->get('idcatart');
1652: 
1653:     // Delete frome code cache and delete corresponding code
1654:     /**
1655:      * @var $file SplFileInfo
1656:      */
1657:     foreach (new DirectoryIterator($cfgClient[$client]['code']['path']) as $file) {
1658:         if ($file->isFile() === false) {
1659:             continue;
1660:         }
1661: 
1662:         $extension = substr($file, strrpos($file->getBasename(), '.') + 1);
1663:         if ($extension != 'php') {
1664:             continue;
1665:         }
1666: 
1667:         if (preg_match('/[0-9*].[0-9*].' . $idcatart . '/s', $file->getBasename())) {
1668:             cFileHandler::remove($cfgClient[$client]['code']['path'] . '/' . $file->getFilename());
1669:         }
1670:     }
1671: 
1672:     // Delete statistics
1673:     $oStatColl = new cApiStatCollection();
1674:     $oStatColl->deleteByCategoryArticleAndLanguage($idcatart, $lang);
1675: 
1676:     // Delete category article
1677:     $oCatArtColl->delete($idcatart);
1678: 
1679:     // Remove startidartlang
1680:     if (isStartArticle($idartlang, $idcat, $lang)) {
1681:         $oCatLang = new cApiCategoryLanguage();
1682:         $oCatLang->loadByCategoryIdAndLanguageId($idcat, $lang);
1683:         if ($oCatLang->isLoaded()) {
1684:             $oCatLang->set('startidartlang', 0);
1685:             $oCatLang->store();
1686:         }
1687:     }
1688: 
1689:     // Delete template configuration
1690:     $oArtLang = new cApiArticleLanguage();
1691:     $oArtLang->loadByArticleAndLanguageId($idart, $lang);
1692:     if ($oArtLang->isLoaded() && $oArtLang->get('idtplcfg') > 0) {
1693:         $oTplCfgColl = new cApiTemplateConfigurationCollection();
1694:         $oTplCfgColl->delete($oArtLang->get('idtplcfg'));
1695:     }
1696: }
1697: 
1698: ?>
CMS CONTENIDO 4.9.5 API documentation generated by ApiGen 2.8.0