From bf24aa601f96d184f9635fa72377d7521b324b4f Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Wed, 20 Mar 2013 22:56:17 +0100 Subject: Ajout controller Rss pour export au format RSS (très très basique) #34 + ajout lib text pour gérer le bbcode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/App_FrontController.php | 1 + app/controllers/rssController.php | 35 ++++++++++++++++ app/views/rss/public.phtml | 31 ++++++++++++++ lib/lib_text.php | 88 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 155 insertions(+) create mode 100755 app/controllers/rssController.php create mode 100755 app/views/rss/public.phtml create mode 100644 lib/lib_text.php diff --git a/app/App_FrontController.php b/app/App_FrontController.php index 55bcfc167..0ff7bf182 100644 --- a/app/App_FrontController.php +++ b/app/App_FrontController.php @@ -20,6 +20,7 @@ class App_FrontController extends FrontController { require (LIB_PATH . '/lib_phpQuery.php'); require (LIB_PATH . '/lib_rss.php'); require (LIB_PATH . '/lib_simplepie.php'); + require (LIB_PATH . '/lib_text.php'); } private function loadModels () { diff --git a/app/controllers/rssController.php b/app/controllers/rssController.php new file mode 100755 index 000000000..1f66f4517 --- /dev/null +++ b/app/controllers/rssController.php @@ -0,0 +1,35 @@ +view->_useLayout (false); + } + + public function publicAction () { + $entryDAO = new EntryDAO (); + $entryDAO->_nbItemsPerPage (-1); + + $items = $entryDAO->listPublic ('low_to_high'); + + try { + $page = Request::param('page', 1); + $nb = Request::param('nb', 15); + $this->view->itemPaginator = new Paginator($items); + $this->view->itemPaginator->_nbItemsPerPage($nb); + $this->view->itemPaginator->_currentPage($page); + } catch(CurrentPagePaginationException $e) { + Error::error( + 404, + array('error' => array('La page que vous cherchez n\'existe pas')) + ); + } + } + + public function getNbNotReadAction() { + } +} diff --git a/app/views/rss/public.phtml b/app/views/rss/public.phtml new file mode 100755 index 000000000..04a035699 --- /dev/null +++ b/app/views/rss/public.phtml @@ -0,0 +1,31 @@ +'; ?> + + + <?php echo View::title(); ?> + + Flux public de + fr + + GMT + +itemPaginator->items (); +foreach ($items as $item) { +?> + + <?php echo htmlspecialchars(html_entity_decode($item->title ())); ?> + link (); ?> + author (); ?> + + + + notes (false, false)); +?>]]> + date (true)); ?> + guid (); ?> + + + + + diff --git a/lib/lib_text.php b/lib/lib_text.php new file mode 100644 index 000000000..6e8f7b2bf --- /dev/null +++ b/lib/lib_text.php @@ -0,0 +1,88 @@ +\\1", + "\\1", + "\\1", + "\\1", + "
\\1
", + "\\1", + "\\1 a écrit
\\2
", + "\\2", + "
\\2
", + "\\1
", + "\\1", + "\\2", + "", + "", + "\"\"", + "\"\\1\"", + "\"\\1\"", + ); + + $string = makeLinks(preg_replace ($find, $replace, $string)); + $string = nl2brPlus ($string); + + return $string; +} + +// do nl2br except when in a
 tag
+function nl2brPlus($string) {
+	$string = str_replace("\n", "
", $string); + if(preg_match_all('/\(.*?)\<\/pre\>/', $string, $match)){ + foreach($match as $a){ + foreach($a as $b){ + $string = str_replace('
'.$b.'
', "
".str_replace("
", "", $b)."
", $string); + } + } + } + return $string; +} + +# Transform URL and e-mails into links +function makeLinks($string) { + $string = preg_replace_callback('/\s(http|https|ftp):(\/\/){0,1}([^\"\s]*)/i','splitUri',$string); + return $string; +} + +# Split links, require for makeLinks +function splitUri($matches) { + $uri = $matches[1].':'.$matches[2].$matches[3]; + $t = parse_url($uri); + $link = $matches[3]; + + if (!empty($t['scheme'])) { + return ' '.$link.''; + } else { + return $uri; + } +} + +// parse la description pour ajouter les liens sur les tags +function parse_tags ($desc) { + $desc_parse = preg_replace ('/#([\w\dÀÇÈÉÊËÎÏÔÙÚÛÜàáâçèéêëîïóùúûü]+)/i', '\\1', $desc); + + return $desc_parse; +} -- cgit v1.2.3