Permalink
Browse files

blogging

  • Loading branch information...
1 parent 315870a commit 4f2ac51a36c0ccce49e604a4d4e5d60eb9236580 @dicabrio committed Feb 3, 2011
@@ -55,5 +55,6 @@
'inhoud_2-file-dimensions-too-big' => 'Het te uploaden bestand is te groot',
'inhoud_2-uploaded-file-too-big' => 'Het te uploaden bestand is te groot',
'pagename-empty' => 'Pagina-url mag niet leeg zijn',
+ 'title-nothing-set' => 'Pagina-titel mag niet leeg zijn',
);
@@ -23,4 +23,29 @@ public static function findAll() {
}
+ public static function findActive($numberIncrement=10, $numberStart=0) {
+
+ $numberIncrement = intval($numberIncrement);
+ if ($numberIncrement == 0) {
+ $numberIncrement = 10;
+ }
+
+ $now = date('Y-m-d H:i:s');
+ $crit = new Criteria("type=:type
+ AND active = :active
+ AND publishtime < :time
+ AND (expiretime = '0000-00-00 00:00:00' OR expiretime > :time)", array('type' => 'blog', 'active' => 1, 'time' => $now));
+
+ return parent::findAll('Page', parent::ALL, $crit, 'created DESC', intval($numberStart).','.$numberIncrement);
+ }
+
+ public function countAllActive() {
+
+ $now = date('Y-m-d H:i:s');
+ return (int)parent::countBySql("SELECT COUNT(1) FROM `page` WHERE type=:type
+ AND active = :active
+ AND publishtime < :time
+ AND (expiretime = '0000-00-00 00:00:00' OR expiretime > :time)", array('type' => 'blog', 'active' => 1, 'time' => $now));
+ }
+
}
@@ -25,15 +25,11 @@ class BlogarchiveCmsModule implements CmsModuleController {
/**
*
- * @var TextArea
+ * @var Input
*/
- private $textArea;
+ private $amountElement;
- /**
- *
- * @var Bool
- */
- private $htmlEditor;
+ private $amount;
/**
* construct the text line module
@@ -50,13 +46,42 @@ public function __construct(PageModule $oMod, Form $form) {
// load the data
$this->load();
+ $this->defineForm();
}
/**
* Load the data for this module
*/
private function load() {
+ $this->oTextContent = PageText::getByPageModule($this->oPageModule);
+ $values = explode(',', $this->oTextContent->getContent());
+
+ if (!isset($values[1])) {
+ $this->amount = 10;
+ $this->templateFile = $this->templateFile = new TemplateFile();
+ } else {
+ $this->amount = $values[0];
+ $this->templateFile = $this->templateFile = new TemplateFile($values[1]);
+ }
+
+ $module = current(Module::getForTemplates('blog'));
+ $this->options = TemplateFile::findByModule($module);
+ }
+
+ private function defineForm() {
+
+ $this->amountElement = new Input('text', $this->oPageModule->getIdentifier().'_amount', $this->amount);
+
+ $this->selectElement = new Select($this->oPageModule->getIdentifier());
+ $this->selectElement->setValue($this->templateFile->getID());
+ $this->selectElement->addOption(0, Lang::get('general.choose'));
+
+ foreach ($this->options as $templateOption) {
+ $this->selectElement->addOption($templateOption->getID(), $templateOption->getTitle());
+ }
+ $this->form->addFormElement($this->amountElement->getName(), $this->amountElement);
+ $this->form->addFormElement($this->selectElement->getName(), $this->selectElement);
}
/**
@@ -67,6 +92,7 @@ private function load() {
public function addFormMapping(FormMapper $mapper) {
$this->mapper = $mapper;
+ $this->mapper->addFormElementToDomainEntityMapping($this->selectElement->getName(), "TemplateFile");
}
@@ -76,7 +102,11 @@ public function addFormMapping(FormMapper $mapper) {
*/
public function getEditor() {
- return '';
+ $view = new View(Conf::get('general.dir.templates').'/blog/blogcmsmodule.php');
+ $view->assign('form', $this->form);
+ $view->assign('identifier', $this->oPageModule->getIdentifier());
+
+ return $view;
}
@@ -87,7 +117,13 @@ public function getEditor() {
*/
public function handleData() {
- // empty
+ $sModIdentifier = $this->oPageModule->getIdentifier();
+ $templateFile = $this->mapper->getModel($sModIdentifier);
+ $amount = $this->mapper->getModel($sModIdentifier.'_amount');
+
+ $this->oTextContent->setContent($amount.','.$templateFile->getID());
+ $this->oTextContent->setPageModule($this->oPageModule);
+ $this->oTextContent->save();
}
@@ -0,0 +1,110 @@
+<?php
+
+class BlogarchivePageModule implements PageModuleController {
+
+ /**
+ * @var PageModule
+ */
+ private $pageModule;
+ /**
+ * @var Page
+ */
+ private $page;
+ /**
+ * @var Request
+ */
+ private $request;
+ /**
+ * @var PageModuleController
+ */
+ private $imageUploadModule;
+ /**
+ * @var PageModuleController
+ */
+ private $textBlockModule;
+
+ /**
+ *
+ * @param PageModule $module
+ * @param Page $oPage
+ * @param Request $request
+ * @return void
+ */
+ public function __construct(PageModule $module, Page $page, Request $request) {
+
+ $this->pageModule = $module;
+ $this->page = $page;
+ $this->request = $request;
+ }
+
+ private function buildBlogArray(Page $blog) {
+
+ $pageModule = $blog->getModule('subject');
+ $pageTextSubject = PageText::getByPageModule($pageModule);
+
+ $pageModule = $blog->getModule('summary');
+ $pageTextSummary = PageText::getByPageModule($pageModule);
+
+ return array('subject' => $pageTextSubject->getContent(), 'name' => $blog->getName(), 'summary' => $pageTextSummary->getContent());
+
+ }
+
+ /**
+ * get contents for this module as a string or an object that has a __toString method implemented
+ *
+ * @return string
+ */
+ public function getContents() {
+
+ $oTextContent = PageText::getByPageModule($this->pageModule);
+ $formshizzle = explode(',', $oTextContent->getContent());
+
+ $amountToStart = 0;
+ $amountPerPage = intval($formshizzle[0]);
+ $page = intval($this->request->get('page'));
+
+ if ($page > 1) {
+ $amountToStart = ($page * $amountPerPage) - $amountPerPage;
+ } else {
+ $page = 1;
+ }
+
+ $activeBlogs = Blog::findActive($amountPerPage, $amountToStart);
+ $amountOfActiveBlogs = Blog::countAllActive();
+
+ $blogArticlesForTemplate = array();
+ foreach ($activeBlogs as $blog) {
+ $blogArticlesForTemplate[] = $this->buildBlogArray($blog);
+ }
+
+ try {
+
+ $tplFile = new TemplateFile($formshizzle[1]);
+ $view = new View(Conf::get('upload.dir.templates').'/'.$tplFile->getFilename());
+ $view->assign('wwwurl', Conf::get('general.url.www'));
+ $view->assign('articles', $blogArticlesForTemplate);
+// $view->assign('pages', ceil($amountOfActiveBlogs / $amountPerPage));
+// $view->assign('page', $page);
+
+ return $view;
+ } catch (Exception $e) {
+
+ $str = '<ul id="blogrecent">';
+ foreach ($activeBlogs as $blog) {
+ $str .= '<li><a href="'.$blog->getName().'">'.$blog->getTitle().'</a></li>';
+ }
+ $str .= '</ul>';
+
+ return $str;
+ }
+ }
+
+ /**
+ * @return string
+ */
+ public function getIdentifier() {
+
+ return '';
+ }
+
+}
@@ -26,7 +26,11 @@ public function addScript($sScript) {
if (!is_string($sScript)) {
throw new CmsException('It is not allowed to add a script url of another type then string. Type is: '.getType($sScript));
}
- $this->aScripts[] = $sScript;
+
+ if (!in_array($sScript, $this->aScripts)) {
+ $this->aScripts[] = $sScript;
+ }
+
}
/**
@@ -36,8 +40,11 @@ public function addStyle($sLink) {
if (!is_string($sLink)) {
throw new CmsException('It is not allowed to add a style url of another type then string. Type is: '.getType($sLink));
}
+
+ if (!in_array($sLink, $this->aStyles)) {
+ $this->aStyles[] = $sLink;
+ }
- $this->aStyles[] = $sLink;
}
/**
@@ -210,8 +210,6 @@ public function savepage($keepediting = false) {
$this->_redirect('page/folder/'.$folder->getID());
-// $this->_redirect('page/folder/'.$folder->getID());
-
} catch (PageRecordException $e) {
$data->rollBack();
@@ -8,7 +8,7 @@ protected function defineFormElementToDomainEntityMapping() {
$this->addFormElementToDomainEntityMapping('template_id', 'TemplateFile');
$this->addFormElementToDomainEntityMapping('publishtime', 'Date');
$this->addFormElementToDomainEntityMapping('expiretime', 'Date');
- $this->addFormElementToDomainEntityMapping('title', 'TextLine');
+ $this->addFormElementToDomainEntityMapping('title', 'RequiredTextLine');
$this->addFormElementToDomainEntityMapping('redirect', 'TextLine');
}
}
@@ -7,12 +7,11 @@ class HtmltextblockPageModule extends TextblockPageModule {
*
* @return string
*/
-// public function getContents() {
-// if ($this->oTextContent === null) {
-// return '';
-// }
-//
-// return nl2br($this->oTextContent->getContent());
-// }
+ public function getContents() {
+
+ $this->isHTMLContent();
+ return parent::getContents();
+
+ }
}
@@ -21,8 +21,25 @@ public function cleanUpHTML() {
// check if it has paragraph wrapt around it
$text = trim($this->getValue());
- if (!preg_match('/^<p(.+)\/p>$/', $text)) {
- $this->setValue('<p>'.$text.'</p>');
- }
+ $text = strip_tags($text, '<p><a><img><br><strong><em><ul><li><ol>');
+
+ $emptyParagraphPattern = "/<p\b[^>]*>(\S+)?<\/p>(<br \/>)?/";
+ $text = preg_replace($emptyParagraphPattern, '', $text);
+
+ $stripper = new StripAttributes();
+ $stripper->allow = array('id', 'class');
+ $stripper->exceptions = array('img' => array('src', 'alt', 'title', 'width', 'height'), 'a' => array('href', 'title'));
+ $text = $stripper->strip($text);
+
+ $this->setValue($text);
+
}
}
+
+function removeGarbageTags($matches) {
+ return '<p>'.$matches[1].'</p>';
+}
+
+function removeGarbageBreaks($matches) {
+ return '';
+}
@@ -109,7 +109,7 @@ public function handleData() {
$sModIdentifier = $this->oPageModule->getIdentifier();
$text = $this->mapper->getModel($sModIdentifier);
- if ($this->htmlEditor) {
+ if ($this->htmlEditor === true) {
$text->cleanUpHTML();
}
@@ -19,6 +19,12 @@ class TextblockPageModule implements PageModuleController {
/**
*
+ * @var boolean
+ */
+ private $isHtmlContent = false;
+
+ /**
+ *
* @param PageModule $oMod
* @param Page $oPage
* @param Request $request
@@ -46,6 +52,10 @@ public function getContents() {
return '';
}
+ if ($this->isHtmlContent) {
+ return $this->oTextContent->getContent();
+ }
+
return nl2br($this->oTextContent->getContent());
}
@@ -57,4 +67,10 @@ public function getIdentifier() {
return $this->oPageModule->getIdentifier();
}
+
+ protected function isHTMLContent() {
+
+ $this->isHtmlContent = true;
+
+ }
}
Oops, something went wrong.

0 comments on commit 4f2ac51

Please sign in to comment.