Changeset 300
- Timestamp:
- 11/12/06 13:13:06 (2 years ago)
- Files:
-
- trunk/build/buildjelix.php (modified) (1 diff)
- trunk/build/manifests/jelix-lib.mn (modified) (2 diffs)
- trunk/build/manifests/testapp.mn (modified) (1 diff)
- trunk/lib/jelix-modules/jelix/templates/atom10.tpl (added)
- trunk/lib/jelix-modules/jelix/templates/rss20.tpl (added)
- trunk/lib/jelix-modules/jelix/templates/rss20items.tpl (deleted)
- trunk/lib/jelix/core/defaultconfig.ini.php (modified) (2 diffs)
- trunk/lib/jelix/core/response/jResponseAtom10.class.php (added)
- trunk/lib/jelix/core/response/jResponseRss20.class.php (modified) (4 diffs)
- trunk/lib/jelix/core/response/jResponseXmlFeed.class.php (added)
- trunk/lib/jelix/tpl/plugins/common/modifier.jdatetime.php (modified) (1 diff)
- trunk/lib/jelix/utils/jDateTime.class.php (modified) (10 diffs)
- trunk/testapp/modules/testapp/controllers/syndication.classic.php (added)
- trunk/testapp/modules/testapp/templates/sommaire.tpl (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/build/buildjelix.php
r297 r300 67 67 if($PHP_VERSION_TARGET == '5.1') $PHP51=1; 68 68 if($PHP_VERSION_TARGET == '5.0') $PHP50=1; 69 }else{ 70 // pas de target d�nie : donc php 5.0 71 $PHP50=1; 69 72 } 70 73 trunk/build/manifests/jelix-lib.mn
r298 r300 55 55 jResponseXml.class.php 56 56 jResponseZip.class.php 57 jResponseXmlFeed.class.php 57 58 jResponseRss20.class.php 59 jResponseAtom10.class.php 58 60 59 61 cd lib/jelix/core/url … … 219 221 404.xul.tpl 220 222 404.html.tpl 221 rss20items.tpl 223 rss20.tpl 224 atom10.tpl 222 225 223 226 cd lib/jelix-modules/jxauth trunk/build/manifests/testapp.mn
r289 r300 32 32 forms.classic.php 33 33 sampleform.classic.php 34 syndication.classic.php 34 35 cd testapp/modules/testapp/templates 35 36 hello.tpl trunk/lib/jelix/core/defaultconfig.ini.php
r286 r300 41 41 zip = jResponseZip 42 42 rss2.0 = jResponseRss20 43 43 atom1.0 = jResponseAtom10 44 44 45 45 [_coreResponses] … … 59 59 zip = jResponseZip 60 60 rss2.0 = jResponseRss20 61 atom1.0 = jResponseAtom10 61 62 62 63 [error_handling] trunk/lib/jelix/core/response/jResponseRss20.class.php
r284 r300 5 5 * @version $Id$ 6 6 * @author Loic Mathaud 7 * @contributor 7 * @author Yannick Le Gu�rt 8 * @contributor Laurent Jouanneau 8 9 * @copyright 2005-2006 Loic Mathaud 10 * @copyright 2006 Yannick Le Gu�rt 11 * @copyright 2006 Laurent Jouanneau 9 12 * @link http://www.jelix.org 10 13 * @licence GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html … … 15 18 */ 16 19 require_once(JELIX_LIB_TPL_PATH.'jTpl.class.php'); 17 require_once(JELIX_LIB_UTILS_PATH.'jRss20Item.class.php'); 20 require_once(JELIX_LIB_RESPONSE_PATH.'jResponseXmlFeed.class.php'); 21 18 22 /** 19 23 * Rss2.0 response 20 24 * @package jelix 21 25 * @subpackage core 26 * @link http://blogs.law.harvard.edu/tech/rss 27 * @link http://www.stervinou.com/projets/rss/ 22 28 */ 23 class jResponseRss20 extends jResponse {29 class jResponseRss20 extends jResponseXMLFeed { 24 30 protected $_type = 'rss2.0'; 25 26 /** 27 * Mandatory title element in <channel> 28 */ 29 public $title = ''; 30 31 /** 32 * Mandatory link element in <channel> 33 */ 34 public $link = ''; 35 36 /** 37 * Mandatory description element in <channel> 38 */ 39 public $description = ''; 40 41 /** 42 * Others optional elements in <channel> 43 */ 44 protected $_optionals = array(); 45 46 protected $_lang; 47 protected $_charset; 48 49 private $_xsl = array(); 50 51 /** 52 * 53 */ 54 public $items = null; 55 56 protected $item_list; 57 58 /** 59 * Template selector 60 * The content of the templates only deals with <item> 61 * @var string 62 */ 63 private $itemsTpl = 'jelix~rss20items'; 64 65 66 function __construct($attributes = array()) { 67 global $gJConfig; 68 $this->_charset = $gJConfig->defaultCharset; 69 $this->_lang = $gJConfig->defaultLocale; 70 $this->items = new jTpl(); 71 parent::__construct($attributes); 72 } 73 31 32 /** 33 * Class constructor 34 * 35 * @param array 36 * @return void 37 */ 38 function __construct ($attributes = array()) { 39 $this->_template = new jTpl(); 40 $this->_mainTpl = 'jelix~rss20'; 41 42 $this->infos = new jRSS20Info (); 43 44 45 parent::__construct ($attributes); 46 $this->infos->language = $this->lang; 47 } 48 74 49 /** 75 50 * Generate the content and send it … … 77 52 * @return boolean true if generation is ok, else false 78 53 */ 79 final public function output (){54 final public function output (){ 80 55 $this->_headSent = false; 81 $this->_httpHeaders['Content-Type']='application/xml;charset='.$this->_charset; 82 83 $this->sendHttpHeaders(); 84 echo '<?xml version="1.0" encoding="'. $this->_charset .'"?>', "\n"; 85 $this->_outputXmlHeader(); 56 57 $this->_httpHeaders['Content-Type'] = 58 'application/xml;charset=' . $this->charset; 59 60 $this->sendHttpHeaders (); 61 $this->_outputXmlHeader (); 62 63 echo '<?xml version="1.0" encoding="'. $this->charset .'"?>', "\n"; 64 86 65 $this->_headSent = true; 87 echo '<rss version="2.0">', "\n"; 88 echo '<channel>', "\n"; 89 echo '<title>'. $this->title .'</title>', "\n"; 90 echo '<link>'. $this->link .'</link>', "\n"; 91 echo '<description>'. $this->description .'</description>', "\n"; 92 echo '<language>'. str_replace('_', '-', strtolower($this->_lang)) .'</language>', "\n"; 93 $this->_outputOptionals(); 94 95 if ($this->itemsTpl != '') { 96 $this->items->assign('items', $this->item_list); 97 $this->items->display($this->itemsTpl); 98 } 99 100 if ($this->hasErrors()) { 101 echo $this->getFormatedErrorMsg(); 102 } 103 echo '</channel>', "\n"; 66 67 // $this->_outputOptionals(); 68 69 $this->_template->assign ('rss', $this->infos); 70 $this->_template->assign ('items', $this->itemList); 71 72 $this->_template->display ($this->_mainTpl); 73 74 if ($this->hasErrors ()) { 75 echo $this->getFormatedErrorMsg (); 76 } 104 77 echo '</rss>'; 105 78 return true; 106 79 } 107 80 108 81 final public function outputErrors() { 109 82 if (!$this->_headSent) { 110 83 if ($this->_sendHttpHeader) { 111 header('Content-Type: text/xml;charset='.$this-> _charset);84 header('Content-Type: text/xml;charset='.$this->charset); 112 85 } 113 echo '<?xml version="1.0" encoding="'. $this-> _charset .'"?>';86 echo '<?xml version="1.0" encoding="'. $this->charset .'"?>'; 114 87 } 115 88 … … 131 104 foreach ($GLOBALS['gJCoord']->errorMessages as $e) { 132 105 // FIXME : Pourquoi utiliser htmlentities() ? 133 $errors .= '<error type="'. $e[0] .'" code="'. $e[1] .'" file="'. $e[3] .'" line="'. $e[4] .'">'.htmlentities($e[2], ENT_NOQUOTES, $this-> _charset). '</error>'. "\n";106 $errors .= '<error type="'. $e[0] .'" code="'. $e[1] .'" file="'. $e[3] .'" line="'. $e[4] .'">'.htmlentities($e[2], ENT_NOQUOTES, $this->charset). '</error>'. "\n"; 134 107 } 135 108 return $errors; 136 109 } 137 138 public function addOptionals($content) { 139 if (is_array($content)) { 140 $this->_optionals = $content; 141 } 142 } 143 144 public function addXSLStyleSheet($src, $params=array ()) { 145 if (!isset($this->_xsl[$src])){ 146 $this->_xsl[$src] = $params; 147 } 148 } 149 150 public function addItem($item) { 151 $this->item_list[] = $item; 152 } 153 154 protected function _outputXmlHeader() { 155 // XSL stylesheet 156 foreach ($this->_xsl as $src => $params) { 157 //the extra params we may found in there. 158 $more = ''; 159 foreach ($params as $param_name => $param_value) { 160 $more .= $param_name.'="'. htmlspecialchars($param_value).'" '; 161 } 162 echo ' <?xml-stylesheet type="text/xsl" href="', $src,'" ', $more,' ?>'; 163 } 164 } 165 166 protected function _outputOptionals() { 167 if (is_array($this->_optionals)) { 168 foreach ($this->_optionals as $name => $value) { 169 echo '<'. $name .'>'. $value .'</'. $name .'>', "\n"; 170 } 171 } 172 } 110 111 /** 112 * create a new item 113 * @param string $title the item title 114 * @param string $link the link 115 * @param string $date the date of the item 116 * @return jXMLFeedItem 117 */ 118 public function createItem($title,$link, $date){ 119 $item = new jRSSItem(); 120 $item->title = $title; 121 $item->id = $item->link = $link; 122 $item->published = $date; 123 return $item; 124 } 125 126 173 127 } 174 128 129 // dates au format RFC822: Sat, 07 Sep 2002 00:00:01 GMT 130 131 /** 132 * meta data of the channel 133 * @package jelix 134 * @subpackage core 135 */ 136 class jRSS20Info extends jXMLFeedInfo{ 137 /** 138 * lang of the channel 139 * @var string 140 */ 141 public $language; 142 /** 143 * email of the content manager 144 * @var string 145 */ 146 public $managingEditor; 147 /** 148 * email of technical responsible 149 * @var string 150 */ 151 public $webMaster; 152 /** 153 * publication date 154 * format: yyyy-mm-dd hh:mm:ss 155 * @var string 156 */ 157 public $published; 158 /** 159 * specification url 160 * example : http://blogs.law.harvard.edu/tech/rss 161 * @var string 162 */ 163 public $docs=''; 164 /** 165 * not implemented 166 * @var string 167 */ 168 public $cloud; // indique un webservice par lequel le client peut s'enregistrer aupr�du serveur 169 // pour �e tenu au courant des modifs 170 //=array('domain'=>'','path'=>'','port'=>'','registerProcedure'=>'', 'protocol'=>''); 171 /** 172 * time to live of the cache, in minutes 173 * @var string 174 */ 175 public $ttl; 176 /** 177 * image title 178 * @var string 179 */ 180 public $imageTitle; 181 /** 182 * web site url corresponding to the image 183 * @var string 184 */ 185 public $imageLink; 186 /** 187 * width of the image 188 * @var string 189 */ 190 public $imageWidth; 191 /** 192 * height of the image 193 * @var string 194 */ 195 public $imageHeight; 196 /** 197 * Description of the image (= title attribute for the img tag) 198 * @var string 199 */ 200 public $imageDescription; 201 202 /** 203 * Pics rate for this channel 204 * @var string 205 */ 206 public $rating; 207 /** 208 * field form for the channel 209 * it is an array('title'=>'','description'=>'','name'=>'','link'=>'') 210 * @var array 211 */ 212 public $textInput; 213 /** 214 * list of hours that agregator should ignore 215 * ex (10, 21) 216 * @var array 217 */ 218 public $skipHours; 219 /** 220 * list of day that agregator should ignore 221 * ex ('monday', 'tuesday') 222 * @var array 223 */ 224 public $skipDays; 225 226 function __construct () 227 { 228 $this->_mandatory = array ( 'title', 'webSiteUrl', 'description'); 229 } 230 } 231 232 /** 233 * content of an item in a syndication channel 234 * @package jelix 235 * @subpackage core 236 */ 237 238 class jRSSItem extends jXMLFeedItem { 239 240 /** 241 * comments url 242 * @var string 243 */ 244 public $comments; 245 /** 246 * media description, attached to the item 247 * the array should contain this keys : 'url', 'size', 'mimetype' 248 * @var array 249 */ 250 public $enclosure; 251 /** 252 * says if the id is a permanent link 253 * @var boolean 254 */ 255 public $idIsPermalink; 256 /** 257 * url of rss channel of the information source 258 * @var string 259 */ 260 public $sourceUrl; 261 /** 262 * Title of the information source 263 * @var string 264 */ 265 public $sourceTitle; 266 } 267 175 268 ?> trunk/lib/jelix/tpl/plugins/common/modifier.jdatetime.php
r227 r300 29 29 'db_time' => jDateTime::BD_TFORMAT, 30 30 'iso8601' => jDateTime::ISO8601_FORMAT, 31 'timestamp' => jDateTime::TIMESTAMP_FORMAT); 31 'timestamp' => jDateTime::TIMESTAMP_FORMAT, 32 'rfc822'=> jDateTime::RFC822_FORMAT); 32 33 33 34 $dt = new jDateTime(); trunk/lib/jelix/utils/jDateTime.class.php
r263 r300 19 19 20 20 21 21 #ifdef PHP50 22 22 if(!function_exists('strptime')){ // existe depuis php 5.1 23 23 /** … … 49 49 } 50 50 } 51 51 #endif 52 52 53 53 /** … … 74 74 const ISO8601_FORMAT=40; 75 75 const TIMESTAMP_FORMAT=50; 76 const RFC822_FORMAT=60; 76 77 77 78 … … 118 119 break; 119 120 case self::ISO8601_FORMAT: 120 $str = sprintf('%04d %02d%02dT%02d:%02d:%02d', $this->year, $this->month, $this->day, $this->hour, $this->minute, $this->second);121 $str = sprintf('%04d-%02d-%02dT%02d:%02d:%02dZ', $this->year, $this->month, $this->day, $this->hour, $this->minute, $this->second); 121 122 break; 122 123 case self::TIMESTAMP_FORMAT: 123 124 $str =(string) mktime ( $this->hour, $this->minute,$this->second , $this->month, $this->day, $this->year ); 125 break; 126 case self::RFC822_FORMAT: 127 $str = date('r', mktime ( $this->hour, $this->minute,$this->second , $this->month, $this->day, $this->year )); 124 128 break; 125 129 } … … 145 149 $this->month = $res['tm_mon']; 146 150 $this->day = $res['tm_mday']; 147 $this->hour = 0;148 $this->minute =0;149 $this->second = 0;150 151 } 151 152 break; … … 166 167 if($res = strptime ( $str, $lf )){ 167 168 $ok=true; 168 $this->year = 0;169 $this->month = 0;170 $this->day = 0;171 169 $this->hour = $res['tm_hour']; 172 170 $this->minute = $res['tm_min']; … … 179 177 $this->month = $match[2]; 180 178 $this->day = $match[3]; 181 $this->hour = 0;182 $this->minute = 0;183 $this->second = 0;184 179 } 185 180 break; … … 196 191 case self::BD_TFORMAT: 197 192 if($ok=preg_match('/^(\d{2}):(\d{2}):(\d{2})$/', $str, $match)){ 198 $this->year = 0;199 $this->month = 0;200 $this->day = 0;201 193 $this->hour = $match[1]; 202 194 $this->minute = $match[2]; … … 205 197 break; 206 198 case self::ISO8601_FORMAT: 207 if($ok=preg_match('/^(\d{4})(\d{2})(\d{2})T(\d{2}):(\d{2}):(\d{2})$/', $str, $match)){ 199 if($ok=preg_match('/^(\d{4})(?:\-(\d{2})(?:\-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{2}))?)?(Z|[+\-]\d{2}:\d{2}))?)?)?$/', $str, $match)){ 200 $c = count($match)-1; 208 201 $this->year = $match[1]; 202 if($c<2) break; 209 203 $this->month = $match[2]; 204 if($c<3) break; 210 205 $this->day = $match[3]; 206 if($c<4) break; 211 207 $this->hour = $match[4]; 212 208 $this->minute = $match[5]; 213 $this->second = $match[6]; 209 if($match[6] != '') $this->second = $match[6]; 210 if($match[8] != 'Z'){ 211 $d = new jDateTime(0,0,0,$match[10],$match[11]); 212 if($match[9] == '+') 213 $this->add($d); 214 else 215 $this->sub($d); 216 } 214 217 } 215 218 break; … … 224 227 $this->second = $t['seconds']; 225 228 break; 229 case self::RFC822_FORMAT: 230 throw new Exception ('jDatetime::setFromString : RFC822_FORMAT not implemented'); 226 231 } 227 232 return $ok; trunk/testapp/modules/testapp/templates/sommaire.tpl
r251 r300 26 26 </ul> 27 27 28 <!-- 28 29 <p>formulaire diff�nci�multiples instances)</p> 29 < !--<ul>30 <ul> 30 31 <li><a href="{jurl 'productform_newform'}">Nouveau produit</a></li> 31 32 <li><a href="{jurl 'productform_show'}">voir le formulaire</a></li> … … 33 34 <li><a href="{jurl 'productform_destroy'}">d�uire le formulaire</a></li> 34 35 </ul>--> 36 37 <h3>Tests syndication</h3> 38 <ul> 39 <li><a href="{jurl 'syndication_rss'}">Rss 2.0</a></li> 40 <li><a href="{jurl 'syndication_atom'}">Atom 1.0</a></li> 41 </ul>
