Quellcode durchsuchen

Ajout controller Rss pour export au format RSS (très très basique) #34 + ajout lib text pour gérer le bbcode

Marien Fressinaud vor 13 Jahren
Ursprung
Commit
bf24aa601f
4 geänderte Dateien mit 155 neuen und 0 gelöschten Zeilen
  1. 1 0
      app/App_FrontController.php
  2. 35 0
      app/controllers/rssController.php
  3. 31 0
      app/views/rss/public.phtml
  4. 88 0
      lib/lib_text.php

+ 1 - 0
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 () {

+ 35 - 0
app/controllers/rssController.php

@@ -0,0 +1,35 @@
+<?php
+  
+class rssController extends ActionController {
+	public function firstAction() {
+		header('Content-Type: text/xml');
+		header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
+		header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
+		header('Pragma: public');
+
+		$this->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() {
+	}
+}

+ 31 - 0
app/views/rss/public.phtml

@@ -0,0 +1,31 @@
+<?php echo '<?xml version="1.0" encoding="UTF-8" ?>'; ?>
+<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
+	<channel>
+		<title><?php echo View::title(); ?></title>
+		<link><?php echo Url::display(); ?></link>
+		<description>Flux public de <?php echo View::title(); ?></description>
+		<language>fr</language>
+		<pubDate><?php echo date('D, d M Y H:i:s O'); ?></pubDate>
+		<lastBuildDate><?php echo gmdate('D, d M Y H:i:s'); ?> GMT</lastBuildDate>
+		<atom:link href="<?php echo Url::display(array('a' => 'rss')); ?>" rel="self" type="application/rss+xml" />
+<?php
+$items = $this->itemPaginator->items ();
+foreach ($items as $item) {
+?>
+		<item>
+			<title><?php echo htmlspecialchars(html_entity_decode($item->title ())); ?></title>
+			<link><?php echo $item->link (); ?></link>
+			<?php $author = $item->author (); ?>
+			<?php if ($author != '') { ?>
+			<dc:creator><?php echo $author; ?></dc:creator>
+			<?php } ?>
+			<description><![CDATA[<?php
+	echo html_entity_decode($item->notes (false, false));
+?>]]></description>
+			<pubDate><?php echo date('D, d M Y H:i:s O', $item->date (true)); ?></pubDate>
+			<guid><?php echo $item->guid (); ?></guid>
+		</item>
+<?php } ?>		
+
+	</channel>
+</rss>

+ 88 - 0
lib/lib_text.php

@@ -0,0 +1,88 @@
+<?php
+
+function bbDecode($string) {
+
+	$find = array(
+		"'\[b\](.*?)\[/b\]'is",
+		"'\[u\](.*?)\[/u\]'is",
+		"'\[i\](.*?)\[/i\]'is",
+		"'\[s\](.*?)\[/s\]'is",
+		"'\[code\](.*?)\[/code\]'is",
+		"'\[quote\](.*?)\[/quote\]'is",
+		"'\[quote=(.*?)\](.*?)\[/quote\]'is",
+		"'\[span=(.*?)\](.*?)\[/span\]'i",
+		"'\[div=(.*?)\](.*?)\[/div\]'is",
+		"'\[h\](.*?)\[/h\]'i",
+		"'\[url\](.*?)\[/url\]'i",
+		"'\[url=(.*?)\](.*?)\[/url\]'i",
+		"'\[video\](.*?)\[/video\]'i",
+		"'\[video width=(.*?) height=(.*?)\](.*?)\[/video\]'i",
+		"'\[img\](.*?)\[/img\]'i",
+		"'\[img title=(.*?) rel=(.*?)\](.*?)\[/img\]'i",
+		"'\[img title=(.*?)\](.*?)\[/img\]'i",
+	);
+
+	$replace = array(
+		"<strong>\\1</strong>",
+		"<u>\\1</u>",
+		"<i>\\1</i>",
+		"<del>\\1</del>",
+		"<pre>\\1</pre>",
+		"<q>\\1</q>",
+		"<q><span class=\"cite\">\\1 a écrit</span><br />\\2</q>",
+		"<span class=\"\\1\">\\2</span>",
+		"<div class=\"\\1\">\\2</div>",
+		"<b>\\1</b><br />",
+		"<a href=\"\\1\">\\1</a>",
+		"<a href=\"\\1\">\\2</a>",
+		"<object width=\"480\" height=\"387\" class=\"center\"><param name=\"movie\" value=\"\\1\"></param><embed src=\"\\1\" type=\"application/x-shockwave-flash\" width=\"480\" height=\"387\"></embed></object>",
+		"<object width=\"\\1\" height=\"\\2\" class=\"center\"><param name=\"movie\" value=\"\\3\"></param><embed src=\"\\3\" type=\"application/x-shockwave-flash\" width=\"\\1\" height=\"\\2\"></embed></object>",
+		"<a href=\"\\1\" rel=\"prettyPhoto\"><img src=\"\\1\" alt=\"\" /></a>",
+		"<img class=\"illustration\" src=\"\\3\" alt=\"\\1\" />",
+		"<img src=\"\\2\" alt=\"\\1\" />",
+	);
+
+	$string = makeLinks(preg_replace ($find, $replace, $string));
+	$string = nl2brPlus ($string);
+
+	return $string;
+}
+
+// do nl2br except when in a <pre> tag
+function nl2brPlus($string) {
+	$string = str_replace("\n", "<br />", $string);
+	if(preg_match_all('/\<pre\>(.*?)\<\/pre\>/', $string, $match)){
+		foreach($match as $a){
+			foreach($a as $b){
+				$string = str_replace('<pre>'.$b.'</pre>', "<pre>".str_replace("<br />", "", $b)."</pre>", $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 ' <a href="'.$uri.'">'.$link.'</a>';
+	} else {
+		return $uri;
+	}
+}
+
+// parse la description pour ajouter les liens sur les tags
+function parse_tags ($desc) {
+	$desc_parse = preg_replace ('/#([\w\dÀÇÈÉÊËÎÏÔÙÚÛÜàáâçèéêëîïóùúûü]+)/i', '<a class="linktag" href="?addtag=\\1">\\1</a>', $desc);
+
+	return $desc_parse;
+}