Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • 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
  • cTinymce4Configuration
  • cTinyMCE4Editor
  • cTinyMCEEditor
  • cWYSIWYGEditor
  • FrontendList
  • HtmlParser
  • TODOBackendList
  • TreeItem
  • UploadList
  • UploadSearchResultList

Functions

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