Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added news theme module type (combines list and view)
- Loading branch information
Sebastian Öttl
committed
May 25, 2013
1 parent
4ca88b8
commit bfdbac6
Showing
9 changed files
with
329 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
files/lib/data/theme/module/type/NewsThemeModuleType.class.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; | ||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() : '') | ||
)); | ||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{if $newsItem} | ||
{include file='newsItem'} | ||
{else} | ||
{include file='newsItemList'} | ||
{/if} |
Oops, something went wrong.