Skip to content

Commit

Permalink
Added news theme module type (combines list and view)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Öttl committed May 25, 2013
1 parent 4ca88b8 commit bfdbac6
Show file tree
Hide file tree
Showing 9 changed files with 329 additions and 9 deletions.
41 changes: 41 additions & 0 deletions acptemplates/newsThemeModuleType.tpl
@@ -0,0 +1,41 @@
<fieldset>
<legend>{lang}moxeo.acp.theme.module.news.data{/lang}</legend>

<div class="formElement{if $errorField == 'newsArchiveIDs'} formError{/if}" id="newsArchiveIDsDiv">
<div class="formFieldLabel">
<label for="newsArchiveIDs">{lang}moxeo.acp.theme.module.news.newsArchiveIDs{/lang}</label>
</div>
<div class="formField">
<select name="newsArchiveIDs[]" id="newsArchiveIDs" multiple="multiple" size="5">
{htmloptions options=$newsArchiveOptions selected=$newsArchiveIDs}
</select>
{if $errorField == 'newsArchiveIDs'}
<p class="innerError">
{if $errorType == 'empty'}{lang}wcf.global.error.empty{/lang}{/if}
</p>
{/if}
</div>
<div class="formFieldDesc hidden" id="newsArchiveIDsHelpMessage">
<p>{lang}moxeo.acp.theme.module.news.newsArchiveIDs.description{/lang}</p>
<p>{lang}wcf.global.multiSelect{/lang}</p>
</div>
</div>
<script type="text/javascript">//<![CDATA[
inlineHelp.register('newsArchiveIDs');
//]]></script>

<div class="formElement" id="newsItemsPerPageDiv">
<div class="formFieldLabel">
<label for="newsItemsPerPage">{lang}moxeo.acp.theme.module.news.newsItemsPerPage{/lang}</label>
</div>
<div class="formField">
<input type="text" class="inputText" id="newsItemsPerPage" name="newsItemsPerPage" value="{@$newsItemsPerPage}" />
</div>
<div class="formFieldDesc hidden" id="newsItemsPerPageHelpMessage">
<p>{lang}moxeo.acp.theme.module.news.newsItemsPerPage.description{/lang}</p>
</div>
</div>
<script type="text/javascript">//<![CDATA[
inlineHelp.register('newsItemsPerPage');
//]]></script>
</fieldset>
6 changes: 6 additions & 0 deletions de.xml
Expand Up @@ -20,6 +20,7 @@
</category>
<category name="wcf.theme">
<item name="wcf.theme.module.type.category.news"><![CDATA[Nachrichten]]></item>
<item name="wcf.theme.module.type.news"><![CDATA[Nachrichten (Auflistung und Anzeige)]]></item>
<item name="wcf.theme.module.type.newsItem"><![CDATA[Nachrichtenanzeige]]></item>
<item name="wcf.theme.module.type.newsItemList"><![CDATA[Nachrichtenauflistung]]></item>
</category>
Expand Down Expand Up @@ -112,6 +113,11 @@
<item name="moxeo.acp.theme.module.newsItemList.newsArchiveIDs.description"><![CDATA[Die Nachrichten aus welchen Archiven sollen in der Auflistung angezeigt werden?]]></item>
<item name="moxeo.acp.theme.module.newsItemList.newsItemsPerPage"><![CDATA[Nachrichten pro Seite]]></item>
<item name="moxeo.acp.theme.module.newsItemList.newsItemsPerPage.description"><![CDATA[Geben Sie hier die Anzahl der Nachrichten pro Seite an.]]></item>
<item name="moxeo.acp.theme.module.news.data"><![CDATA[Daten]]></item>
<item name="moxeo.acp.theme.module.news.newsArchiveIDs"><![CDATA[Archive]]></item>
<item name="moxeo.acp.theme.module.news.newsArchiveIDs.description"><![CDATA[Die Nachrichten aus welchen Archiven sollen in der Auflistung angezeigt werden?]]></item>
<item name="moxeo.acp.theme.module.news.newsItemsPerPage"><![CDATA[Nachrichten pro Seite]]></item>
<item name="moxeo.acp.theme.module.news.newsItemsPerPage.description"><![CDATA[Geben Sie hier die Anzahl der Nachrichten pro Seite an.]]></item>
</category>
<category name="moxeo.comment">
<item name="moxeo.comment.commentableObjectType.newsItem"><![CDATA[Nachricht]]></item>
Expand Down
6 changes: 6 additions & 0 deletions en.xml
Expand Up @@ -20,6 +20,7 @@
</category>
<category name="wcf.theme">
<item name="wcf.theme.module.type.category.news"><![CDATA[News]]></item>
<item name="wcf.theme.module.type.news"><![CDATA[News (list and view)]]></item>
<item name="wcf.theme.module.type.newsItem"><![CDATA[News view]]></item>
<item name="wcf.theme.module.type.newsItemList"><![CDATA[News list]]></item>
</category>
Expand Down Expand Up @@ -112,6 +113,11 @@
<item name="moxeo.acp.theme.module.newsItemList.newsArchiveIDs.description"><![CDATA[The news from which archives should be displayed in the news list?]]></item>
<item name="moxeo.acp.theme.module.newsItemList.newsItemsPerPage"><![CDATA[News per page]]></item>
<item name="moxeo.acp.theme.module.newsItemList.newsItemsPerPage.description"><![CDATA[Enther the number of news per page here.]]></item>
<item name="moxeo.acp.theme.module.news.data"><![CDATA[Data]]></item>
<item name="moxeo.acp.theme.module.news.newsArchiveIDs"><![CDATA[Archives]]></item>
<item name="moxeo.acp.theme.module.news.newsArchiveIDs.description"><![CDATA[The news from which archives should be displayed in the news list?]]></item>
<item name="moxeo.acp.theme.module.news.newsItemsPerPage"><![CDATA[News per page]]></item>
<item name="moxeo.acp.theme.module.news.newsItemsPerPage.description"><![CDATA[Enther the number of news per page here.]]></item>
</category>
<category name="moxeo.comment">
<item name="moxeo.comment.commentableObjectType.newsItem"><![CDATA[News]]></item>
Expand Down
79 changes: 79 additions & 0 deletions files/lib/data/theme/module/type/NewsThemeModuleType.class.php
@@ -0,0 +1,79 @@
<?php
// moxeo imports
require_once(MOXEO_DIR.'lib/data/news/archive/NewsArchive.class.php');

// wcf imports
require_once(WCF_DIR.'lib/data/theme/module/type/ViewableThemeModuleType.class.php');

/**
* Represents the news theme module type.
*
* @author Sebastian Oettl
* @copyright 2009-2012 WCF Solutions <http://www.wcfsolutions.com/>
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @package com.wcfsolutions.moxeo.news
* @subpackage data.theme.module.type
* @category Moxeo Open Source CMS
*/
class NewsThemeModuleType extends ViewableThemeModuleType {
/**
* @see ViewableThemeModuleType::$pageElement
*/
public $pageElement = 'news';

/**
* @see ViewableThemeModuleType::$pageElementDir
*/
public $pageElementDir = MOXEO_DIR;

// form methods
/**
* @see ThemeModuleType::readFormParameters()
*/
public function readFormParameters() {
// news archive ids
$this->formData['newsArchiveIDs'] = array();
if (isset($_POST['newsArchiveIDs'])) $this->formData['newsArchiveIDs'] = ArrayUtil::toIntegerArray($_POST['newsArchiveIDs']);

// news items per page
$this->formData['newsItemsPerPage'] = 10;
if (isset($_POST['newsItemsPerPage'])) $this->formData['newsItemsPerPage'] = intval($_POST['newsItemsPerPage']);
}

/**
* @see ThemeModuleType::validate()
*/
public function validate() {
// news archive ids
foreach ($this->formData['newsArchiveIDs'] as $key => $newsArchiveID) {
try {
$newsArchive = new NewsArchive($newsArchiveID);
}
catch (IllegalLinkException $e) {
unset($this->formData['newsArchiveIDs'][$key]);
}
}
if (!count($this->formData['newsArchiveIDs'])) {
throw new UserInputException('newsArchiveIDs');
}
}

/**
* @see ThemeModuleType::assignVariables()
*/
public function assignVariables() {
WCF::getTPL()->assign(array(
'newsArchiveOptions' => NewsArchive::getNewsArchives(),
'newsArchiveIDs' => (isset($this->formData['newsArchiveIDs']) ? $this->formData['newsArchiveIDs'] : array()),
'newsItemsPerPage' => (isset($this->formData['newsItemsPerPage']) ? $this->formData['newsItemsPerPage'] : 10)
));
}

/**
* @see ThemeModuleType::getFormTemplateName()
*/
public function getFormTemplateName() {
return 'newsThemeModuleType';
}
}
?>
14 changes: 7 additions & 7 deletions files/lib/page/element/NewsItemListPageElement.class.php
Expand Up @@ -40,19 +40,19 @@ class NewsItemListPageElement extends ThemeModulePageElement {
public function readParameters() {
parent::readParameters();

// init news item list
$this->newsItemList = new NewsItemList();
$this->newsItemList->sqlConditions = " news_item.newsArchiveID IN (".implode(',', $this->themeModule->newsArchiveIDs).")
AND news_item.enabled = 1
AND (news_item.publishingStartTime = 0 OR news_item.publishingStartTime > ".TIME_NOW.")
AND (news_item.publishingEndTime = 0 OR news_item.publishingStartTime <= ".TIME_NOW.")";

// get content item
if (!isset($this->additionalData['contentItem'])) {
throw new SystemException('no content item given');
}
$this->contentItem = $this->additionalData['contentItem'];

// init news item list
$this->newsItemList = new NewsItemList();
$this->newsItemList->sqlConditions = " news_item.newsArchiveID IN (".implode(',', $this->themeModule->newsArchiveIDs).")
AND news_item.enabled = 1
AND (news_item.publishingStartTime = 0 OR news_item.publishingStartTime > ".TIME_NOW.")
AND (news_item.publishingEndTime = 0 OR news_item.publishingEndTime <= ".TIME_NOW.")";

// news items per page
if ($this->themeModule->newsItemsPerPage) $this->itemsPerPage = $this->themeModule->newsItemsPerPage;
}
Expand Down
169 changes: 169 additions & 0 deletions files/lib/page/element/NewsPageElement.class.php
@@ -0,0 +1,169 @@
<?php
// moxeo imports
require_once(MOXEO_DIR.'lib/data/news/NewsItemList.class.php');
require_once(MOXEO_DIR.'lib/data/news/archive/NewsArchive.class.php');

// wcf imports
require_once(WCF_DIR.'lib/page/element/ThemeModulePageElement.class.php');

/**
* Represents a news element.
*
* @author Sebastian Oettl
* @copyright 2009-2012 WCF Solutions <http://www.wcfsolutions.com/>
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @package com.wcfsolutions.moxeo.news
* @subpackage page.element
* @category Moxeo Open Source CMS
*/
class NewsPageElement extends ThemeModulePageElement {
// system
public $templateName = 'newsItemList';

/**
* news item list object
*
* @var NewsItemList
*/
public $newsItemList = null;

/**
* content item object
*
* @var ContentItem
*/
public $contentItem = null;

/**
* news item alias
*
* @var string
*/
public $newsItemAlias = '';

/**
* news item object
*
* @var NewsItem
*/
public $newsItem = null;

/**
* news archive object
*
* @var NewsArchive
*/
public $newsArchive = null;

/**
* list of comments
*
* @var CommentList
*/
public $commentList = null;

/**
* @see Page::readParameters()
*/
public function readParameters() {
parent::readParameters();

$this->newsItemAlias = ContentItemRequestHandler::getInstance()->getFilename();
if ($this->newsItemAlias) {
// get news item
$this->newsItem = NewsItem::getNewsItemByAlias($this->newsItemAlias);
if (!$this->newsItem->newsItemID) {
throw new IllegalLinkException();
}

// get news archive
$this->newsArchive = new NewsArchive($this->newsItem->newsArchiveID);
$this->newsItem->enter();

// check news archive
if (!in_array($this->newsArchive->newsArchiveID, $this->themeModule->newsArchiveIDs)) {
throw new IllegalLinkException();
}

// init comment list
if ($this->newsItem->enableComments) {
require_once(MOXEO_DIR.'lib/data/comment/CommentList.class.php');
$this->commentList = new CommentList();
$this->commentList->sqlConditions .= "comment.commentableObjectID = ".$this->newsItem->newsItemID." AND comment.commentableObjectType = 'newsItem'";
$this->commentList->sqlOrderBy = 'comment.time DESC';
}
}
else {
// init news item list
$this->newsItemList = new NewsItemList();
$this->newsItemList->sqlConditions = " news_item.newsArchiveID IN (".implode(',', $this->themeModule->newsArchiveIDs).")
AND news_item.enabled = 1
AND (news_item.publishingStartTime = 0 OR news_item.publishingStartTime > ".TIME_NOW.")
AND (news_item.publishingEndTime = 0 OR news_item.publishingEndTime <= ".TIME_NOW.")";

// get content item
if (!isset($this->additionalData['contentItem'])) {
throw new SystemException('no content item given');
}
$this->contentItem = $this->additionalData['contentItem'];

// news items per page
if ($this->themeModule->newsItemsPerPage) $this->itemsPerPage = $this->themeModule->newsItemsPerPage;
}
}

/**
* @see MultipleLinkPage::countItems()
*/
public function countItems() {
parent::countItems();

if ($this->newsItemList !== null) {
return $this->newsItemList->countObjects();
}
return $this->commentList->countObjects();
}

/**
* @see Page::readData()
*/
public function readData() {
parent::readData();

if ($this->newsItemList !== null) {
// read news items
$this->newsItemList->sqlOffset = ($this->pageNo - 1) * $this->itemsPerPage;
$this->newsItemList->sqlLimit = $this->itemsPerPage;
$this->newsItemList->readObjects();
else {
// read comments
$this->commentList->sqlOffset = ($this->pageNo - 1) * $this->itemsPerPage;
$this->commentList->sqlLimit = $this->itemsPerPage;
$this->commentList->readObjects();
}
}

/**
* @see Page::assignVariables()
*/
public function assignVariables() {
parent::assignVariables();

// init comment add form
if ($this->commentList !== null) {
require_once(MOXEO_DIR.'lib/form/element/CommentAddFormElement.class.php');
$commentAddForm = new CommentAddFormElement($this->newsItem->getCommentableObject(), $this->additionalData['contentItem'], $this->newsItem->getURL());
}

WCF::getTPL()->assign(array(
'contentItem' => $this->contentItem,
'newsItems' => ($this->newsItemList !== null ? $this->newsItemList->getObjects() : array()),
'newsArchive' => $this->newsArchive,
'newsItem' => $this->newsItem,
'newsItemAlias' => $this->newsItemAlias,
'comments' => ($this->commentList !== null ? $this->commentList->getObjects() : array()),
'commentForm' => ($this->commentList !== null ? $commentAddForm->getContent() : '')
));
}
}
?>
13 changes: 11 additions & 2 deletions package.xml
Expand Up @@ -5,8 +5,8 @@
<packagename language="de">Nachrichten-System</packagename>
<packagedescription>Extends Moxeo Open Source CMS by a news system.</packagedescription>
<packagedescription language="de">Erweitert Moxeo Open Source CMS um ein Nachrichten-System.</packagedescription>
<version>1.1.0 Alpha 1</version>
<date>2013-05-24</date>
<version>1.1.0 Alpha 2</version>
<date>2013-05-25</date>
<plugin>com.wcfsolutions.moxeo</plugin>
</packageinformation>

Expand Down Expand Up @@ -42,6 +42,15 @@

<instructions type="update" fromversion="1.0.0 RC 2">
<!-- files -->
<files>files.tar</files>
<templates>templates.tar</templates>
<acptemplates>acptemplates.tar</acptemplates>

<!-- config -->
<thememoduletype>thememoduletype.xml</thememoduletype>

<!-- languages -->
<languages languagecode="de">de.xml</languages>
<languages languagecode="en">en.xml</languages>
</instructions>
</package>
5 changes: 5 additions & 0 deletions templates/news.tpl
@@ -0,0 +1,5 @@
{if $newsItem}
{include file='newsItem'}
{else}
{include file='newsItemList'}
{/if}

0 comments on commit bfdbac6

Please sign in to comment.