/**
  * @see	\cms\system\content\type\IContentType::getOutput()
  */
 public function getOutput(Content $content)
 {
     if (empty($content->compiled[WCF::getLanguage()->languageCode])) {
         $compiled = WCF::getTPL()->getCompiler()->compileString('de.codequake.cms.content.type.template' . $content->contentID, $content->text);
         $contentData = $content->contentData;
         if (!is_array($contentData)) {
             $contentData = unserialize($contentData);
         }
         $contentData['compiled'][WCF::getLanguage()->languageCode] = $compiled;
         $contentAction = new ContentAction(array($content), 'update', array('data' => array('contentData' => $contentData)));
         $contentAction->executeAction();
     } else {
         $compiled = $content->compiled[WCF::getLanguage()->languageCode];
     }
     return WCF::getTPL()->fetchString($compiled['template']);
 }
Beispiel #2
0
 /**
  * Copies a specific page.
  */
 public function copy()
 {
     $object = $this->getSingleObject();
     $data = $object->getDecoratedObject()->getData();
     // remove unique or irrelevant properties
     unset($data['pageID']);
     unset($data['isHome']);
     unset($data['clicks']);
     // ensure unique aliases
     $i = 1;
     $alias = $data['alias'] . '-copy';
     do {
         $data['alias'] = $alias . $i;
         $i++;
     } while (!PageUtil::isAvailableAlias($data['alias'], $object->parentID));
     // perform creation of copy
     $this->parameters['data'] = $data;
     $page = $this->create();
     $pageID = $page->pageID;
     // copy contents
     $contents = $object->getContents();
     $tmp = array();
     foreach (array('body', 'sidebar') as $position) {
         foreach ($contents[$position] as $content) {
             //recreate
             $data = $content->getDecoratedObject()->getData();
             $oldID = $data['contentID'];
             unset($data['contentID']);
             $data['pageID'] = $pageID;
             $action = new ContentAction(array(), 'create', array('data' => $data));
             $return = $action->executeAction();
             $tmp[$oldID] = $return['returnValues']->contentID;
         }
     }
     // setting new IDs
     $contents = new ContentList();
     $contents->getConditionBuilder()->add('pageID = ?', array($pageID));
     $contents->readObjects();
     $contents = $contents->getObjects();
     foreach ($contents as $content) {
         $update = array();
         if (isset($tmp[$content->parentID])) {
             $editor = new ContentEditor($content);
             $update['parentID'] = $tmp[$content->parentID];
             $editor->update($update);
         }
     }
 }
 /**
  * Restores a specific revision.
  */
 public function restore()
 {
     // get available languages
     $availableLanguages = LanguageFactory::getInstance()->getLanguages();
     $revision = $this->getSingleObject();
     WCF::getDB()->beginTransaction();
     $pageData = base64_decode($revision->data);
     $pageData = @unserialize($pageData);
     $i18nfields = array();
     // save i18n
     foreach ($pageData as $key => $data) {
         if (($key == 'title' || $key == 'description' || $key == 'metaDescription' || $key == 'metaKeywords') && is_array($data)) {
             $langData = array();
             foreach ($availableLanguages as $lang) {
                 if (isset($data[$lang->countryCode])) {
                     $langData[$lang->languageID] = $data[$lang->countryCode];
                 } else {
                     $langData[$lang->languageID] = '';
                 }
             }
             I18nHandler::getInstance()->setValues($key, $langData);
             $i18nfields[] = $key;
             $pageData[$key] = '';
         }
     }
     // restore page
     $pageAction = new PageAction(array($revision->pageID), 'update', array('data' => $pageData));
     $pageAction->executeAction();
     // save i18n
     foreach ($pageData as $key => $data) {
         if (($key == 'title' || $key == 'description' || $key == 'metaDescription' || $key == 'metaKeywords') && in_array($key, $i18nfields)) {
             $this->saveI18nValue(new Page($revision->pageID), 'page', $key);
         }
     }
     // restore contents
     $contentData = base64_decode($revision->contentData);
     $contentData = @unserialize($contentData);
     $contentList = new ContentList();
     $contentList->getConditionBuilder()->add('content.pageID = ?', array($revision->pageID));
     $contentList->readObjects();
     $existingContentIDs = $contentList->getObjectIDs();
     $oldContents = array();
     foreach ($contentData as $data) {
         $oldContents[$data['contentID']] = $data;
     }
     // delete contents that where created after the revision
     $orphanedElementIDs = array_diff($existingContentIDs, array_keys($oldContents));
     if (!empty($orphanedElementIDs)) {
         $contentAction = new ContentAction($orphanedElementIDs, 'delete');
         $contentAction->executeAction();
     }
     foreach ($oldContents as $oldContent) {
         $objectType = ObjectTypeCache::getInstance()->getObjectType($oldContent['contentTypeID']);
         if (in_array($oldContent['contentID'], $existingContentIDs)) {
             // content this exists => update
             $i18ntitle = false;
             if (is_array($oldContent['title'])) {
                 $langData = array();
                 foreach ($availableLanguages as $lang) {
                     if (isset($oldContent['title'][$lang->countryCode])) {
                         $langData[$lang->languageID] = $oldContent['title'][$lang->countryCode];
                     } else {
                         $langData[$lang->languageID] = '';
                     }
                 }
                 I18nHandler::getInstance()->setValues($key, $langData);
                 $i18ntitle = true;
                 $oldContent['title'] = '';
             }
             $i18nfields = array();
             foreach ($objectType->getProcessor()->multilingualFields as $field) {
                 if (isset($oldContent['contentData'][$field]) && is_array($oldContent['contentData'][$field])) {
                     $langData = array();
                     foreach ($availableLanguages as $lang) {
                         if (isset($oldContent['contentData'][$field][$lang->countryCode])) {
                             $langData[$lang->languageID] = $oldContent['contentData'][$field][$lang->countryCode];
                         } else {
                             $langData[$lang->languageID] = '';
                         }
                     }
                     I18nHandler::getInstance()->setValues($field, $langData);
                     $i18nfields[] = $field;
                     $oldContent['contentData'][$field] = '';
                 }
             }
             $contentAction = new ContentAction(array($oldContent['contentID']), 'update', array('data' => $oldContent));
             $contentAction->executeAction();
             if ($i18ntitle) {
                 $this->saveI18nValue(new Content($oldContent['contentID']), 'content', 'title');
             }
             foreach ($objectType->getProcessor()->multilingualFields as $field) {
                 if (in_array($field, $i18nfields)) {
                     $this->saveI18nValue(new Content($oldContent['contentID']), 'content', $field, true);
                 }
             }
         } else {
             // content was deleted => re-create
             $i18ntitle = false;
             if (is_array($oldContent['title'])) {
                 $langData = array();
                 foreach ($availableLanguages as $lang) {
                     if (isset($oldContent['title'][$lang->countryCode])) {
                         $langData[$lang->languageID] = $oldContent['title'][$lang->countryCode];
                     } else {
                         $langData[$lang->languageID] = '';
                     }
                 }
                 I18nHandler::getInstance()->setValues($field, $langData);
                 $i18ntitle = true;
                 $oldContent['title'] = '';
             }
             $i18nfields = array();
             foreach ($objectType->getProcessor()->multilingualFields as $field) {
                 if (isset($oldContent['contentData'][$field])) {
                     $langData = array();
                     foreach ($availableLanguages as $lang) {
                         if (isset($oldContent['contentData'][$field][$lang->countryCode])) {
                             $langData[$lang->languageID] = $oldContent['contentData'][$field][$lang->countryCode];
                         } else {
                             $langData[$lang->languageID] = '';
                         }
                     }
                     I18nHandler::getInstance()->setValues($key, $langData);
                     $i18nfields[] = $field;
                     $oldContent['contentData'][$field] = '';
                 }
             }
             $contentAction = new ContentAction(array($oldContent['contentID']), 'create', array('data' => $oldContent));
             $contentAction->executeAction();
             if ($i18ntitle) {
                 $this->saveI18nValue(new Content($oldContent['contentID']), 'content', 'title');
             }
             foreach ($objectType->getProcessor()->multilingualFields as $field) {
                 if (in_array($field, $i18nfields)) {
                     $this->saveI18nValue(new Content($oldContent['contentID']), 'content', $field, true);
                 }
             }
         }
     }
     WCF::getDB()->commitTransaction();
 }
Beispiel #4
0
<?php

use cms\data\content\ContentAction;
use cms\data\content\ContentList;
use wcf\data\object\type\ObjectTypeCache;
/**
 * @author	Jens Krumsieck
 * @copyright	2013 - 2015 codeQuake
 * @license	GNU Lesser General Public License <http://www.gnu.org/licenses/lgpl-3.0.txt>
 * @package	de.codequake.cms
 */
$id = ObjectTypeCache::getInstance()->getObjectTypeIDByName('de.codequake.cms.content.type', 'de.codequake.cms.content.type.headline');
$list = new ContentList();
$list->getConditionBuilder()->add('content.position', array('sidebar'));
$list->getConditionBuilder()->add('content.contentTypeID', array($id));
$list->readObjects();
$affectedObjects = $list->getObjects();
//delete all headlines
$action = new ContentAction($affectedObjects, 'delete', array());
$action->executeAction();