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

  • cContentVersioning
  • cVersion
  • cVersionFile
  • cVersionLayout
  • cVersionModule
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: 
  3: /**
  4:  * This file contains the versioning class.
  5:  *
  6:  * @package Core
  7:  * @subpackage Versioning
  8:  * @version
  9:  *
 10:  * @author Jann Dieckmann
 11:  * @copyright four for business AG <www.4fb.de>
 12:  * @license http://www.contenido.org/license/LIZENZ.txt
 13:  * @link http://www.4fb.de
 14:  * @link http://www.contenido.org
 15:  */
 16: 
 17: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 18: 
 19: /**
 20:  * Versioning.
 21:  *
 22:  * @package Core
 23:  * @subpackage Versioning
 24:  */
 25: class cContentVersioning {
 26: 
 27:     /**
 28:      * db instance
 29:      *
 30:      * @var cDb
 31:      */
 32:     protected $db;
 33: 
 34:     /**
 35:      * article type (current, version, editable)
 36:      *
 37:      * @var string
 38:      */
 39:     protected $articleType;
 40: 
 41:     /**
 42:      * selected article language (version)
 43:      *
 44:      * @var cApiArticleLanguageVersion or cApiArticleLanguage
 45:      */
 46:     public $selectedArticle;
 47: 
 48:     /**
 49:      * editable article language version id
 50:      *
 51:      * @var integer
 52:      */
 53:     public $editableArticleId;
 54: 
 55:     /**
 56:      * Create new versioning class
 57:      */
 58:     public function __construct() {
 59:         $this->db = cRegistry::getDb();
 60:     }
 61: 
 62:     /**
 63:      * Cms type sort function for article output.
 64:      *
 65:      * @SuppressWarnings docBlocks
 66:      * @param array $result[cms type][typeId] = value
 67:      * @return array $result[cms type][typeId] = value
 68:      */
 69:     public function sortResults(array $result) {
 70: 
 71:         uksort($result, function($a, $b) {
 72: 
 73:             // cms type sort sequence
 74:             $cmsType = array(
 75:                 "CMS_HTMLHEAD",
 76:                 "CMS_HEAD",
 77:                 "CMS_HTML",
 78:                 "CMS_TEXT",
 79:                 "CMS_IMG",
 80:                 "CMS_IMGDESCR",
 81:                 "CMS_IMGEDITOR",
 82:                 "CMS_LINK",
 83:                 "CMS_LINKTARGET",
 84:                 "CMS_LINKDESCR",
 85:                 "CMS_LINKEDITOR",
 86:                 "CMS_DATE",
 87:                 "CMS_TEASER",
 88:                 "CMS_FILELIST",
 89:                 "CMS_RAW"
 90:             );
 91: 
 92:             return array_search($a, $cmsType) - array_search($b, $cmsType);
 93: 
 94:         });
 95: 
 96:         return $result;
 97: 
 98:     }
 99: 
100:     /**
101:      * Return date for select box.
102:      * If current time - lastModified < 1 hour return "%d minutes ago"
103:      * else return "Y-M-D H:I:S".
104:      *
105:      * @param unknown_type $lastModified
106:      * @return string
107:      */
108:     public function getTimeDiff($lastModified) {
109:         $currentTime = new DateTime(date('Y-m-d H:i:s'));
110:         $modifiedTime = new DateTime($lastModified);
111:         $diff = $currentTime->diff($modifiedTime);
112:         $diff2 = (int) $diff->format('%Y%M%D%H');
113: 
114:         if ($diff2 === 0) {
115:             return sprintf(i18n("%d minutes ago"), $diff->format('%i'));
116:         } else {
117:             return date('d.m.Y, H:i\h', strtotime($lastModified));
118:         }
119: 
120:     }
121: 
122:     /**
123:      * Returns the current versioning state (disabled (default), simple, advanced).
124:      *
125:      * @return string $versioningState
126:      */
127:     public static function getState() {
128: 
129:         static $versioningState;
130: 
131:         if (!isset($versioningState)) {
132: 
133:             // versioning enabled is a tri-state => disabled (default), simple, advanced
134:             $systemPropColl = new cApiSystemPropertyCollection();
135:             $prop = $systemPropColl->fetchByTypeName('versioning', 'enabled');
136:             $versioningState = $prop ? $prop->get('value') : false;
137: 
138:             if (false === $versioningState || NULL === $versioningState) {
139:                 $versioningState = 'disabled';
140:             } else if ('' === $versioningState) {
141:                 // NOTE: An non empty default value overrides an empty value
142:                 $versioningState = 'disabled';
143:             }
144: 
145:         }
146: 
147:         return $versioningState;
148: 
149:     }
150: 
151:     /**
152:      * Returns selected article.
153:      *
154:      * @todo $idArtlangVersion <-> $selectedArticleId
155:      * @param int $idArtLangVersion
156:      * @param int $idArtLang
157:      * @param string $articleType
158:      * @param int $selectedArticleId [optional]
159:      * @return cApiArticleLanguage|cApiArticleLanguageVersion $this->selectedArticle
160:      */
161:     public function getSelectedArticle($idArtLangVersion, $idArtLang, $articleType, $selectedArticleId = NULL) {
162: 
163:         $this->editableArticleId = $this->getEditableArticleId($idArtLang);
164:         $versioningState = $this->getState();
165:         $this->selectedArticle = NULL;
166:         if (is_numeric($selectedArticleId)) {
167:             $idArtLangVersion = $selectedArticleId;
168:         }
169: 
170:         if (($articleType == 'version' || $articleType == 'editable') && ($versioningState == 'advanced')
171:         || ($articleType == 'version' && $versioningState == 'simple')) {
172:             if (is_numeric($idArtLangVersion) && $articleType == 'version') {
173:                 $this->selectedArticle = new cApiArticleLanguageVersion($idArtLangVersion);
174:             } else if (isset($this->editableArticleId)) {
175:                 $this->selectedArticle = new cApiArticleLanguageVersion($this->editableArticleId);
176:              }
177:         } else if ($articleType == 'current' || $articleType == 'editable') {
178:             $this->selectedArticle = new cApiArticleLanguage($idArtLang);
179:         }
180: 
181:         return $this->selectedArticle;
182: 
183:     }
184: 
185:     /**
186:      * Returns $list[1] = CMS_HTMLHEAD for every content existing
187:      * in article/version with $idArtLang.
188:      *
189:      * @param int $idArtLang
190:      * @param string $articleType
191:      * @return array $list
192:      */
193:     public function getList($idArtLang, $articleType) {
194: 
195:         $sql = 'SELECT DISTINCT b.idtype as idtype, b.type as name
196:                 FROM %s AS a, %s AS b
197:                 WHERE a.idartlang = %d AND a.idtype = b.idtype
198:                 ORDER BY idtype, name';
199: 
200:         if (($articleType == 'version' || $articleType == 'editable') && $this->getState() == 'advanced'
201:                 || $articleType == 'version' && $this->getState() == 'simple') {
202:             $this->db->query($sql, cRegistry::getDbTableName('content_version'), cRegistry::getDbTableName('type'), $idArtLang);
203:         } else if ($articleType == 'current' || $articleType == 'editable' && $this->getState() != 'advanced') {
204:             $this->db->query($sql, cRegistry::getDbTableName('content'), cRegistry::getDbTableName('type'), $idArtLang);
205:         }
206: 
207:         $list = array();
208:         while ($this->db->nextRecord()) {
209:             $list[$this->db->f('idtype')] = $this->db->f('name');
210:         }
211: 
212:         return $list;
213: 
214:     }
215: 
216:     /**
217:      * Return max idcontent.
218:      *
219:      * @return int
220:      */
221:     public function getMaxIdContent() {
222: 
223:         $sql = 'SELECT max(idcontent) AS max FROM %s';
224:         $this->db->query($sql, cRegistry::getDbTableName('content'));
225:         $this->db->nextRecord();
226: 
227:         return $this->db->f('max');
228:     }
229: 
230:     /**
231:      * Returns type of article (current, version or editable).
232:      *
233:      * @param int $idArtLangVersion
234:      * @param int $idArtLang
235:      * @param string $action
236:      * @param mixed $selectedArticleId
237:      * @return string $this->articleType
238:      *
239:      */
240:     public function getArticleType($idArtLangVersion, $idArtLang, $action, $selectedArticleId) {
241: 
242:         $this->editableArticleId = $this->getEditableArticleId($idArtLang);
243: 
244:         if ($this->getState() == 'disabled' // disabled
245:             || ($this->getState() == 'simple' && ($selectedArticleId == 'current'
246:                 || $selectedArticleId == NULL)
247:                 && ($action == 'con_meta_deletetype' || $action == 'copyto'
248:                  || $action == 'con_content' || $idArtLangVersion == NULL
249:                  || $action == 'con_saveart' || $action == 'con_edit' || $action == 'con_meta_edit' || $action == 'con_editart'))
250:             || $idArtLangVersion == 'current' && $action != 'copyto'
251:             || $action == 'copyto' && $idArtLangVersion == $this->editableArticleId
252:             || $action == 'con_meta_change_version' && $idArtLang == 'current'
253:             || $selectedArticleId == 'current' && $action != 'copyto'
254:             || $this->editableArticleId == NULL
255:             && $action != 'con_meta_saveart' && $action != 'con_newart') { // advanced
256:             $this->articleType = 'current';
257:         } else if ($this->getState() == 'advanced' && ($selectedArticleId == 'editable'
258:             || $selectedArticleId == NULL || $this->editableArticleId === $selectedArticleId)
259:             && ($action == 'con_content' || $action == 'con_meta_deletetype'
260:                 || $action == 'con_meta_edit' || $action == 'con_edit' || $action == 'con_editart')
261:             || $action == 'copyto' || $idArtLangVersion == 'current'
262:             || $idArtLangVersion == $this->editableArticleId
263:             || $action == 'importrawcontent' || $action == 'savecontype'
264:             || $action == 'con_editart' && $this->getState() == 'advanced' && $selectedArticleId == 'editable'
265:             || $action == 'con_edit' && $this->getState() == 'advanced' && $selectedArticleId == NULL
266:             || $action == '20' && $idArtLangVersion == NULL
267:             || $action == 'con_meta_saveart' || $action == 'con_saveart'
268:             || $action == 'con_newart' || $action == 'con_meta_change_version'
269:             && $idArtLangVersion == $this->editableArticleId) {
270:             $this->articleType = 'editable';
271:         } else {
272:             $this->articleType = 'version';
273:         }
274: 
275:         return $this->articleType;
276: 
277:     }
278: 
279:     /**
280:      *
281:      * @param unknown_type $class
282:      * @param unknown_type $selectElement
283:      * @param unknown_type $copyToButton
284:      * @param unknown_type $infoText
285:      * @return string
286:      */
287:     public function getVersionSelectionField($class, $selectElement, $copyToButton, $infoText) {
288: 
289:         // TODO avoid inline CSS!!!
290:         $versionselection = '
291:             <div class="%s">
292:                 <div>
293:                     <span style="width: 280px; display: inline; padding: 0px 0px 0px 2px;">
294:                         <span style="font-weight:bold;color:black;">' . i18n('Select Article Version') . '</span>
295:                         <span style="margin: 0;"> %s %s
296:                         </span>
297:                         <a
298:                             href="#"
299:                             id="pluginInfoDetails-link"
300:                             class="main i-link infoButton"
301:                             title="">
302:                         </a>
303:                     </span>
304:                 </div>
305:                 <div id="pluginInfoDetails" style="display:none;" class="nodisplay">
306:                        %s
307:                 </div>
308:             </div>';
309: 
310:         return sprintf(
311:             $versionselection,
312:             $class,
313:             $selectElement,
314:             $copyToButton,
315:             $infoText
316:         );
317:     }
318: 
319:     /**
320:      * Returns idartlangversion of editable article.
321:      *
322:      * @param int $idArtLang
323:      * @return int $editableArticleId
324:      */
325:     public function getEditableArticleId($idArtLang) {
326: 
327:         if ($this->getState() == 'advanced') {
328: 
329:             $this->db->query(
330:                 'SELECT
331:                     max(idartlangversion) AS max
332:                 FROM
333:                     %s
334:                 WHERE
335:                     idartlang = %d',
336:                 cRegistry::getDbTableName('art_lang_version'),
337:                 $idArtLang
338:             );
339:             $this->db->nextRecord();
340:             $this->editableArticleId = $this->db->f('max');
341: 
342:             return $this->editableArticleId;
343: 
344:         } else if ($this->getState() == 'simple' || $this->getState() == 'disabled') {
345: 
346:             return $idArtLang;
347: 
348:         }
349: 
350:     }
351: 
352:     /**
353:      * Returns idcontent or idcontentversion.
354:      *
355:      * @todo check datatype of return value
356:      * @param int $idArtLang
357:      * @param int $typeId
358:      * @param int $type
359:      * @param int $versioningState
360:      * @param int $articleType
361:      * @param int $version
362:      * @return array $idContent
363:      */
364:     public function getContentId(
365:         $idArtLang, $typeId, $type, $versioningState, $articleType, $version
366:     ) {
367: 
368:         $idContent = array();
369:         $type = addslashes($type);
370: 
371:         if ($versioningState == 'simple' && $articleType != 'version'
372:         || $versioningState == 'advanced' && $articleType == 'current'
373:         || $versioningState == 'disabled') {
374:             $this->db->query("
375:                 SELECT
376:                     a.idcontent
377:                 FROM
378:                     " . cRegistry::getDbTableName('content') . " as a,
379:                     " . cRegistry::getDbTableName('type') . " as b
380:                 WHERE
381:                     a.idartlang=" . $idArtLang . "
382:                     AND a.idtype=b.idtype
383:                     AND a.typeid = " . $typeId . "
384:                     AND b.type = '" . $type . "'
385:                 ORDER BY
386:                     a.idartlang, a.idtype, a.typeid");
387:             while ($this->db->nextRecord()) {
388:                 $idContent = $this->db->f('idcontent');
389:             }
390:         } else {
391:             $this->db->query("
392:                 SELECT
393:                     a.idcontentversion
394:                 FROM
395:                     " . cRegistry::getDbTableName('content_version') . " as a,
396:                     " . cRegistry::getDbTableName('type') . " as b
397:                 WHERE
398:                     a.version <= " . $version . "
399:                     AND a.idartlang = " . $idArtLang . "
400:                     AND a.idtype = b.idtype
401:                     AND a.typeid = " . $typeId . "
402:                     AND b.type = '" . $type . "'
403:                 ORDER BY
404:                     a.version DESC, a.idartlang, a.idtype, a.typeid LIMIT 1");
405:             while ($this->db->nextRecord()) {
406:                 $idContent = $this->db->f('idcontentversion');
407:             }
408:         }
409: 
410:         return $idContent;
411: 
412:     }
413: 
414:     /**
415:      * Returns $artLangVersionMap[version][idartlangversion] = lastmodified
416:      * either from each article-/content- or metatag-version.
417:      *
418:      * @param int $idArtLang
419:      * @param string $selectElementType [optional]
420:      *         either 'content', 'seo' or 'config'
421:      * @return array
422:      */
423:     public function getDataForSelectElement($idArtLang, $selectElementType = '') {
424: 
425:         $artLangVersionMap = array();
426: 
427:         $artLangVersionColl = new cApiArticleLanguageVersionCollection();
428:         $artLangVersionColl->addResultField('version');
429:         $artLangVersionColl->addResultField('lastmodified');
430:         $artLangVersionColl->setWhere('idartlang', $idArtLang);
431:         $artLangVersionColl->setOrder('version desc');
432: 
433:         try {
434: 
435:             if ($selectElementType == 'content') {
436: 
437:                 // select only versions with different content versions
438:                 $contentVersionColl = new cApiContentVersionCollection();
439:                 $contentVersionColl->addResultField('version');
440:                 $contentVersionColl->setWhere('idartlang', $idArtLang);
441:                 $contentVersionColl->query();
442:                 $contentFields['version'] = 'version';
443: 
444:                 // check ...
445:                 if (0 >= $contentVersionColl->count()) {
446:                     throw new cException('no content versions');
447:                 }
448: 
449:                 $table = $contentVersionColl->fetchTable($contentFields);
450: 
451:                 // add ...
452:                 $contentVersionMap = array();
453:                 foreach ($table AS $key => $item) {
454:                     $contentVersionMap[] = $item['version'];
455:                 }
456:                 $contentVersionMap = array_unique($contentVersionMap);
457:                 $artLangVersionColl->setWhere('version', $contentVersionMap, 'IN');
458: 
459:             } else if ($selectElementType == 'seo') {
460: 
461:                 // select only versions with different seo versions
462:                 $metaVersionColl = new cApiMetaTagVersionCollection();
463:                 $metaVersionColl->addResultField('version');
464:                 $metaVersionColl->setWhere('idartlang', $idArtLang);
465:                 $metaVersionColl->query();
466:                 $metaFields['version'] = 'version';
467: 
468:                 // check...
469:                 if (0 >= $metaVersionColl->count()) {
470:                     throw new cException('no meta versions');
471:                 }
472: 
473:                 $table = $metaVersionColl->fetchTable($metaFields);
474: 
475:                 // add ...
476:                 $metaVersionMap = array();
477:                 foreach ($table AS $key => $item) {
478:                     $metaVersionMap[] = $item['version'];
479:                 }
480:                 $metaVersionMap = array_unique($metaVersionMap);
481:                 $artLangVersionColl->setWhere('version', $metaVersionMap, 'IN');
482: 
483:             } else if ($selectElementType == 'config') {
484: 
485:                 // select all versions
486: 
487:             }
488: 
489:         } catch (cException $e) {
490:             return $artLangVersionMap;
491:         }
492: 
493:         $artLangVersionColl->query();
494: 
495:         $fields['idartlangversion'] = 'idartlangversion';
496:         $fields['version'] = 'version';
497:         $fields['lastmodified'] = 'lastmodified';
498: 
499:         if (0 < $artLangVersionColl->count()) {
500:             $table = $artLangVersionColl->fetchTable($fields);
501: 
502:             foreach ($table AS $key => $item) {
503:                 $artLangVersionMap[$item['version']][$item['idartlangversion']] = $item['lastmodified'];
504:             }
505:         }
506: 
507:         return $artLangVersionMap;
508: 
509:     }
510: 
511:     /**
512:      * Prepares content for saving (consider versioning-mode; prevents multiple
513:      * storings for filelists e.g.).
514:      *
515:      * @param unknown_type $idartlang
516:      *         the contents idartlang
517:      * @param cApiContent $content
518:      *         the content to store
519:      * @param unknown_type
520:      *         the contents value to store
521:      *
522:      */
523:     public function prepareContentForSaving($idartlang, cApiContent $content, $value) {
524: 
525:         // Through a CONTENIDO bug filelists save each of their changes multiple
526:         // times. Therefore its necessary to check if the same change already
527:         // has been saved and prevent multiple savings.
528:         static $savedTypes = array();
529:         if (isset($savedTypes[$content->get('idtype') . $content->get('typeid')])) {
530:             return;
531:         }
532:         $savedTypes[$content->get('idtype').$content->get('typeid')] = $value;
533: 
534:         $versioningState = $this->getState();
535:         $date = date('Y-m-d H:i:s');
536:         $author = $auth->auth['uname'];
537: 
538:         switch ($versioningState) {
539:             case 'simple':
540:                 // Create Content Version
541:                 $idContent = NULL;
542:                 if ($content->isLoaded()) {
543:                     $idContent = $content->getField('idcontent');
544:                 }
545: 
546:                 if ($idContent == NULL) {
547:                     $idContent = $this->getMaxIdContent() + 1;
548:                 }
549: 
550:                 $parameters = array(
551:                     'idcontent' => $idContent,
552:                     'idartlang' => $idartlang,
553:                     'idtype' => $content->get('idtype'),
554:                     'typeid' => $content->get('typeid'),
555:                     'value' => $value,
556:                     'author' => $author,
557:                     'created' => $date,
558:                     'lastmodified' => $date
559:                 );
560: 
561:                 $this->createContentVersion($parameters);
562:             case 'disabled':
563:                 if ($content->isLoaded()) {
564:                     // Update existing entry
565:                     $content->set('value', $value);
566:                     $content->set('author', $author);
567:                     $content->set('lastmodified', date('Y-m-d H:i:s'));
568:                     $content->store();
569:                 } else {
570:                     // Create new entry
571:                     $contentColl = new cApiContentCollection();
572:                     $content = $contentColl->create(
573:                         $idartlang,
574:                         $content->get('idtype'),
575:                         $content->get('typeid'),
576:                         $value,
577:                         0,
578:                         $author,
579:                         $date,
580:                         $date
581:                     );
582:                 }
583: 
584:                 // Touch the article to update last modified date
585:                 $lastmodified = date('Y-m-d H:i:s');
586:                 $artLang = new cApiArticleLanguage($idartlang);
587:                 $artLang->set('lastmodified', $lastmodified);
588:                 $artLang->set('modifiedby', $author);
589:                 $artLang->store();
590: 
591:                 break;
592:             case 'advanced':
593:                 // Create Content Version
594:                 $idContent = NULL;
595:                 if ($content->isLoaded()) {
596:                     $idContent = $content->getField('idcontent');
597:                 }
598: 
599:                 if ($idContent == NULL) {
600:                     $idContent = $this->getMaxIdContent() + 1;
601:                 }
602: 
603:                 $parameters = array(
604:                     'idcontent' => $idContent,
605:                     'idartlang' => $idartlang,
606:                     'idtype' => $content->get('idtype'),
607:                     'typeid' => $content->get('typeid'),
608:                     'value' => $value,
609:                     'author' => $author,
610:                     'created' => $date,
611:                     'lastmodified' => $date
612:                 );
613: 
614:                 $this->createContentVersion($parameters);
615:             default:
616:                 break;
617:         }
618:     }
619: 
620:     /**
621:      * Create new content version.
622:      *
623:      * @param mixed[] $parameters {
624:      *     @type int $idContent
625:      *     @type int $idArtLang
626:      *     @type int $idType
627:      *     @type int $typeId
628:      *     @type string $value
629:      *     @type string $author
630:      *     @type string $created
631:      *     @type string $lastModified
632:      * }
633:     */
634:     public function createContentVersion(array $parameters) {
635: 
636:         // set parameters for article language version
637:         $currentArticle = cRegistry::getArticleLanguage();
638: 
639:         // create new article language version and get the version number
640:         $parametersArticleVersion = array(
641:             'idartlang' => $currentArticle->getField('idartlang'),
642:             'idart' => $currentArticle->getField('idart'),
643:             'idlang' => $currentArticle->getField('idlang'),
644:             'title' => $currentArticle->getField('title'),
645:             'urlname' => $currentArticle->getField('urlname'),
646:             'pagetitle' => $currentArticle->getField('pagetitle'),
647:             'summary' => $currentArticle->getField('summary'),
648:             'artspec' => $currentArticle->getField('artspec'),
649:             'created' => $currentArticle->getField('created'),
650:             'iscurrentversion' => 1,
651:             'author' => $currentArticle->getField('author'),
652:             'lastmodified' => date('Y-m-d H:i:s'),
653:             'modifiedby' => $currentArticle->getField('author'),
654:             'published' => $currentArticle->getField('published'),
655:             'publishedby' => $currentArticle->getField('publishedby'),
656:             'online' => $currentArticle->getField('online'),
657:             'redirect' => $currentArticle->getField('redirect'),
658:             'redirect_url' => $currentArticle->getField('redirect_url'),
659:             'external_redirect' => $currentArticle->getField('external_redirect'),
660:             'artsort' => $currentArticle->getField('artsort'),
661:             'timemgmt' => $currentArticle->getField('timemgmt'),
662:             'datestart' => $currentArticle->getField('datestart'),
663:             'dateend' => $currentArticle->getField('dateend'),
664:             'status' => $currentArticle->getField('status'),
665:             'time_move_cat' => $currentArticle->getField('time_move_cat'),
666:             'time_target_cat' => $currentArticle->getField('time_target_cat'),
667:             'time_online_move' => $currentArticle->getField('time_online_move'),
668:             'locked' => $currentArticle->getField('locked'),
669:             'free_use_01' => $currentArticle->getField('free_use_01'),
670:             'free_use_02' => $currentArticle->getField('free_use_02'),
671:             'free_use_03' => $currentArticle->getField('free_use_03'),
672:             'searchable' => $currentArticle->getField('searchable'),
673:             'sitemapprio' => $currentArticle->getField('sitemapprio'),
674:             'changefreq' => $currentArticle->getField('changefreq')
675:         );
676: 
677:         $artLangVersion = $this->createArticleLanguageVersion($parametersArticleVersion);
678: 
679:         // get the version number of the new article language version that belongs to the content
680:         $parameters['version'] = $artLangVersion->getField('version');
681: 
682:         $parametersToCheck = $parameters;
683:         unset(
684:             $parametersToCheck['lastmodified'],
685:             $parametersToCheck['author'],
686:             $parametersToCheck['value'],
687:             $parametersToCheck['created']
688:         );
689: 
690:         // if there already is a content type like this in this version,
691:         // create a new article version, too (needed for storing a version after
692:         // first change in simple-mode)
693:         $contentVersion = new cApiContentVersion();
694:         //$contentVersion->loadByMany($parameters);
695:         $contentVersion->loadByMany($parametersToCheck);
696:         if ($contentVersion->isLoaded()) {
697:             //foreach ($parameters AS $key => $value) {
698:                 //$contentVersion->set($key, $value);
699:                 $artLangVersion = $this->createArticleLanguageVersion($parametersArticleVersion);
700:                 $parameters['version'] = $artLangVersion->getField('version');
701:                 $contentVersionColl = new cApiContentVersionCollection();
702:                 $contentVersionColl->create($parameters);
703:             //}
704:             //$contentVersion->store();
705:         } else {
706:             // if there is no content type like this in this version, create one
707:             $contentVersionColl = new cApiContentVersionCollection();
708:             $contentVersionColl->create($parameters);
709:         }
710:     }
711: 
712:     /**
713:      * Create new article language version.
714:      *
715:      * @global int $lang
716:      * @global object $auth
717:      * @global string $urlname
718:      * @global string $page_title
719:      * @param mixed[] $parameters {
720:      *     @type int $idart
721:      *     @type int $idlang
722:      *     @type string $title
723:      *     @type string $urlname
724:      *     @type string $pagetitle
725:      *     @type string $summary
726:      *     @type int $artspec
727:      *     @type string $created
728:      *     @type int $iscurrentverseion
729:      *     @type string $author
730:      *     @type string $lastmodified
731:      *     @type string $modifiedby
732:      *     @type string $published
733:      *     @type string $publishedby
734:      *     @type int $online
735:      *     @type int $redirect
736:      *     @type string $redirect_url
737:      *     @type int $external_redirect
738:      *     @type int $artsort
739:      *     @type int $timemgmt
740:      *     @type string $datestart
741:      *     @type string $dateend
742:      *     @type int $status
743:      *     @type int $time_move_cat
744:      *     @type int $time_target_cat
745:      *     @type int $time_online_move
746:      *     @type int $locked
747:      *     @type mixed $free_use_01
748:      *     @type mixed $free_use_02
749:      *     @type mixed $free_use_03
750:      *     @type int $searchable
751:      *     @type float $sitemapprio
752:      *     @type string $changefreq
753:      * }
754:      * @return cApiArticleLanguageVersion
755:     */
756:     public function createArticleLanguageVersion(array $parameters) {
757: 
758:         global $lang, $auth, $urlname, $page_title;
759: 
760:         // Some stuff for the redirect
761:         global $redirect, $redirect_url, $external_redirect;
762: 
763:         // Used to indicate "move to cat"
764:         global $time_move_cat;
765: 
766:         // Used to indicate the target category
767:         global $time_target_cat;
768: 
769:         // Used to indicate if the moved article should be online
770:         global $time_online_move;
771: 
772:         global $timemgmt;
773: 
774:         $page_title = (empty($parameters['pagetitle'])) ? addslashes($page_title) : $parameters['pagetitle'];
775: 
776:         $parameters['title'] = stripslashes($parameters['title']);
777: 
778:         $redirect = (empty($parameters['redirect'])) ? cSecurity::toInteger($redirect) : $parameters['redirect'];
779:         $redirect_url = (empty($parameters['page_title'])) ? stripslashes($redirect_url) : stripslashes($parameters['redirect_url']);
780:         $external_redirect = (empty($parameters['external_redirect'])) ? stripslashes($external_redirect) : stripslashes($parameters['external_redirect']);
781: 
782:         $urlname = (trim($urlname) == '')? trim($parameters['title']) : trim($urlname);
783: 
784:         if ($parameters['isstart'] == 1) {
785:             $timemgmt = 0;
786:         }
787: 
788:         if (!is_array($parameters['idcatnew'])) {
789:             $parameters['idcatnew'][0] = 0;
790:         }
791: 
792:         // Set parameters for article language version
793:         $artLangVersionParameters = array(
794:             'idartlang' => $parameters['idartlang'],
795:             'idart' => $parameters['idart'],
796:             'idlang' => $lang,
797:             'title' => $parameters['title'],
798:             'urlname' => $urlname,
799:             'pagetitle' => $page_title,
800:             'summary' => $parameters['summary'],
801:             'artspec' => $parameters['artspec'],
802:             'created' => $parameters['created'],
803:             'iscurrentversion' => $parameters['iscurrentversion'],
804:             'author' => $parameters['author'],
805:             'lastmodified' => date('Y-m-d H:i:s'),
806:             'modifiedby' => $auth->auth['uname'],
807:             'published' => $parameters['published'],
808:             'publishedby' => $parameters['publishedby'],
809:             'online' => $parameters['online'],
810:             'redirect' => $redirect,
811:             'redirect_url' => $redirect_url,
812:             'external_redirect' => $external_redirect,
813:             'artsort' => $parameters['artsort'],
814:             'timemgmt' => $timemgmt,
815:             'datestart' => $parameters['datestart'],
816:             'dateend' => $parameters['dateend'],
817:             'status' => 0,
818:             'time_move_cat' => $time_move_cat,
819:             'time_target_cat' => $time_target_cat,
820:             'time_online_move' => $time_online_move,
821:             'locked' => 0,
822:             'free_use_01' => '',
823:             'free_use_02' => '',
824:             'free_use_03' => '',
825:             'searchable' => $parameters['searchable'],
826:             'sitemapprio' => $parameters['sitemapprio'],
827:             'changefreq' => $parameters['changefreq']
828:         );
829: 
830:         // Create article language version entry
831:         $artLangVersionColl = new cApiArticleLanguageVersionCollection();
832:         $artLangVersion = $artLangVersionColl->create($artLangVersionParameters);
833: 
834:         // version Contents if contents are not versioned yet
835:         if (isset($parameters['idartlang'])){
836:             $where = 'idartlang = ' . $parameters['idartlang'];
837:             $contentVersionColl = new cApiContentVersionCollection();
838:             $contentVersions = $contentVersionColl->getIdsByWhereClause($where);
839:         }
840: 
841:         if (empty($contentVersions)) {
842:             $artLang = new cApiArticleLanguage($parameters['idartlang']);
843:             $conType = new cApiType();
844:             $content = new cApiContent();
845:             foreach ($artLang->getContent() AS $type => $typeids) {
846:                 foreach ($typeids AS $typeid => $value) {
847:                     $conType->loadByType($type);
848:                     $content->loadByArticleLanguageIdTypeAndTypeId(
849:                         $parameters['idartlang'],
850:                         $conType->get('idtype'),
851:                         $typeid
852:                     );
853:                     $content->markAsEditable($artLangVersion->get('version'), 0);
854:                 }
855:             }
856:         }
857: 
858:         // version meta tags if they are not versioned yet
859:         if (isset($parameters['idartlang'])) {
860:             $where = 'idartlang = ' . $parameters['idartlang'];
861:             $metaTagVersionColl = new cApiMetaTagVersionCollection();
862:             $metaTagVersions = $metaTagVersionColl->getIdsByWhereClause($where);
863:         }
864: 
865:         if (empty($metaTagVersions)) {
866:             $where = 'idartlang = ' . $parameters['idartlang'];
867:             $metaTagColl = new cApiMetaTagCollection();
868:             $metaTags = $metaTagColl->getIdsByWhereClause($where);
869:             $metaTag = new cApiMetaTag();
870:             foreach ($metaTags AS $id) {
871:                 $metaTag->loadBy('idmetatag', $id);
872:                 $metaTag->markAsEditable($artLangVersion->get('version'));
873:             }
874:         }
875: 
876:         return $artLangVersion;
877:     }
878: 
879:     /**
880:      * Create new Meta Tag Version.
881:      *
882:      * @param mixed[] $parameters {
883:      *     @type int $idmetatag
884:      *     @type int $idartlang
885:      *     @type string $idmetatype
886:      *     @type string $value
887:      *     @type int version
888:      * }
889:      * @return cApiMetaTagVersion
890:     */
891:     public function createMetaTagVersion(array $parameters) {
892: 
893:         $coll = new cApiMetaTagVersionCollection();
894:         $item = $coll->create(
895:             $parameters['idmetatag'],
896:             $parameters['idartlang'],
897:             $parameters['idmetatype'],
898:             $parameters['value'],
899:             $parameters['version']
900:         );;
901: 
902:         return $item;
903: 
904:     }
905: }
906: 
CMS CONTENIDO 4.9.8 API documentation generated by ApiGen 2.8.0