Changeset 300

Show
Ignore:
Timestamp:
11/12/06 13:13:06 (2 years ago)
Author:
laurentj
Message:

- jDatetime : fix bug sur ISO8601
- jDatetime : prise en charge du format rfc 822
- Syndication jresponse : intégration du patch de torgan ticket #15 + des améliorations par moi-meme : meilleure factorisation sur les classes abstraites, corrections sur les templates pour que le contenu atom et rss soit valide

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/build/buildjelix.php

    r297 r300  
    6767    if($PHP_VERSION_TARGET == '5.1') $PHP51=1; 
    6868    if($PHP_VERSION_TARGET == '5.0') $PHP50=1; 
     69}else{ 
     70    // pas de target d�nie : donc php 5.0 
     71    $PHP50=1; 
    6972} 
    7073 
  • trunk/build/manifests/jelix-lib.mn

    r298 r300  
    5555  jResponseXml.class.php 
    5656  jResponseZip.class.php 
     57  jResponseXmlFeed.class.php 
    5758  jResponseRss20.class.php 
     59  jResponseAtom10.class.php 
    5860 
    5961cd lib/jelix/core/url 
     
    219221  404.xul.tpl 
    220222  404.html.tpl 
    221   rss20items.tpl 
     223  rss20.tpl 
     224  atom10.tpl 
    222225 
    223226cd lib/jelix-modules/jxauth 
  • trunk/build/manifests/testapp.mn

    r289 r300  
    3232  forms.classic.php 
    3333  sampleform.classic.php 
     34  syndication.classic.php 
    3435cd testapp/modules/testapp/templates 
    3536  hello.tpl 
  • trunk/lib/jelix/core/defaultconfig.ini.php

    r286 r300  
    4141zip = jResponseZip 
    4242rss2.0 = jResponseRss20 
    43  
     43atom1.0 = jResponseAtom10 
    4444 
    4545[_coreResponses] 
     
    5959zip = jResponseZip 
    6060rss2.0 = jResponseRss20 
     61atom1.0 = jResponseAtom10 
    6162 
    6263[error_handling] 
  • trunk/lib/jelix/core/response/jResponseRss20.class.php

    r284 r300  
    55* @version     $Id$ 
    66* @author      Loic Mathaud 
    7 * @contributor 
     7* @author      Yannick Le Gu�rt 
     8* @contributor Laurent Jouanneau 
    89* @copyright   2005-2006 Loic Mathaud 
     10* @copyright   2006 Yannick Le Gu�rt 
     11* @copyright   2006 Laurent Jouanneau 
    912* @link        http://www.jelix.org 
    1013* @licence     GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html 
     
    1518*/ 
    1619require_once(JELIX_LIB_TPL_PATH.'jTpl.class.php'); 
    17 require_once(JELIX_LIB_UTILS_PATH.'jRss20Item.class.php'); 
     20require_once(JELIX_LIB_RESPONSE_PATH.'jResponseXmlFeed.class.php'); 
     21 
    1822/** 
    1923* Rss2.0 response 
    2024* @package  jelix 
    2125* @subpackage core 
     26* @link http://blogs.law.harvard.edu/tech/rss 
     27* @link http://www.stervinou.com/projets/rss/ 
    2228*/ 
    23 class jResponseRss20 extends jResponse
     29class jResponseRss20 extends jResponseXMLFeed
    2430    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 
    7449    /** 
    7550     * Generate the content and send it 
     
    7752     * @return boolean true if generation is ok, else false 
    7853     */ 
    79     final public function output()
     54    final public function output ()
    8055        $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 
    8665        $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        } 
    10477        echo '</rss>'; 
    10578        return true; 
    10679    } 
    107      
     80 
    10881    final public function outputErrors() { 
    10982        if (!$this->_headSent) { 
    11083             if ($this->_sendHttpHeader) { 
    111                 header('Content-Type: text/xml;charset='.$this->_charset); 
     84                header('Content-Type: text/xml;charset='.$this->charset); 
    11285             } 
    113              echo '<?xml version="1.0" encoding="'. $this->_charset .'"?>'; 
     86             echo '<?xml version="1.0" encoding="'. $this->charset .'"?>'; 
    11487        } 
    11588 
     
    131104        foreach ($GLOBALS['gJCoord']->errorMessages  as $e) { 
    132105            // 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"; 
    134107        } 
    135108        return $errors; 
    136109    } 
    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 
    173127} 
    174128 
     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 */ 
     136class 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 
     238class 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 
    175268?> 
  • trunk/lib/jelix/tpl/plugins/common/modifier.jdatetime.php

    r227 r300  
    2929        'db_time' => jDateTime::BD_TFORMAT, 
    3030        'iso8601' => jDateTime::ISO8601_FORMAT, 
    31         'timestamp' => jDateTime::TIMESTAMP_FORMAT); 
     31        'timestamp' => jDateTime::TIMESTAMP_FORMAT, 
     32        'rfc822'=> jDateTime::RFC822_FORMAT); 
    3233 
    3334    $dt = new jDateTime(); 
  • trunk/lib/jelix/utils/jDateTime.class.php

    r263 r300  
    1919 
    2020 
    21  
     21#ifdef PHP50 
    2222if(!function_exists('strptime')){ // existe depuis php 5.1 
    2323    /** 
     
    4949    } 
    5050} 
    51  
     51#endif 
    5252 
    5353/** 
     
    7474    const ISO8601_FORMAT=40; 
    7575    const TIMESTAMP_FORMAT=50; 
     76    const RFC822_FORMAT=60; 
    7677 
    7778 
     
    118119               break; 
    119120           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); 
    121122               break; 
    122123           case self::TIMESTAMP_FORMAT: 
    123124               $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 )); 
    124128               break; 
    125129        } 
     
    145149                   $this->month = $res['tm_mon']; 
    146150                   $this->day = $res['tm_mday']; 
    147                    $this->hour = 0; 
    148                    $this->minute =0; 
    149                    $this->second = 0; 
    150151               } 
    151152               break; 
     
    166167               if($res = strptime ( $str, $lf )){ 
    167168                   $ok=true; 
    168                    $this->year = 0; 
    169                    $this->month = 0; 
    170                    $this->day = 0; 
    171169                   $this->hour = $res['tm_hour']; 
    172170                   $this->minute = $res['tm_min']; 
     
    179177                    $this->month = $match[2]; 
    180178                    $this->day = $match[3]; 
    181                     $this->hour = 0; 
    182                     $this->minute = 0; 
    183                     $this->second = 0; 
    184179               } 
    185180               break; 
     
    196191           case self::BD_TFORMAT: 
    197192               if($ok=preg_match('/^(\d{2}):(\d{2}):(\d{2})$/', $str, $match)){ 
    198                     $this->year = 0; 
    199                     $this->month = 0; 
    200                     $this->day = 0; 
    201193                    $this->hour = $match[1]; 
    202194                    $this->minute = $match[2]; 
     
    205197               break; 
    206198           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; 
    208201                    $this->year = $match[1]; 
     202                    if($c<2) break; 
    209203                    $this->month = $match[2]; 
     204                    if($c<3) break; 
    210205                    $this->day = $match[3]; 
     206                    if($c<4) break; 
    211207                    $this->hour = $match[4]; 
    212208                    $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                    } 
    214217               } 
    215218               break; 
     
    224227               $this->second = $t['seconds']; 
    225228               break; 
     229           case self::RFC822_FORMAT: 
     230               throw new Exception ('jDatetime::setFromString : RFC822_FORMAT not implemented'); 
    226231        } 
    227232        return $ok; 
  • trunk/testapp/modules/testapp/templates/sommaire.tpl

    r251 r300  
    2626</ul> 
    2727 
     28<!-- 
    2829<p>formulaire diff�nci�multiples instances)</p> 
    29 <!--<ul> 
     30<ul> 
    3031   <li><a href="{jurl 'productform_newform'}">Nouveau produit</a></li> 
    3132   <li><a href="{jurl 'productform_show'}">voir le formulaire</a></li> 
     
    3334   <li><a href="{jurl 'productform_destroy'}">d�uire le formulaire</a></li> 
    3435</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> 
Download in other formats: Unified Diff Zip Archive