MkFramework
 All Data Structures Functions
plugin_rss.php
1 <?php
2 /*
3 This file is part of Mkframework.
4 
5 Mkframework is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License.
8 
9 Mkframework is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13 
14 You should have received a copy of the GNU Lesser General Public License
15 along with Mkframework. If not, see <http://www.gnu.org/licenses/>.
16 
17 */
23 class plugin_rss{
24 
25  protected $news;
26  protected $header;
27  protected $id=0;
28  protected $sAdresseRss;
29  protected $sUrl;
30  protected $sName='news';
31 
37  public function __construct($sName=null){
38  if($sName!=null){
39  $this->setName($sName);
40  }
41  }
42 
48  public function setName($sName){
49  $this->sName=$sName;
50  }
56  public function setTitre($sTitre){
57  $this->header.='<title>'.htmlentities($sTitre).'</title>';
58  }
64  public function setUrl($sUrl){
65  $this->sUrl=$sUrl;
66  $this->header.='<link>'.htmlentities($sUrl).'</link>';
67  }
73  public function setDesc($sDesc){
74  $this->header.='<description><![CDATA['.$sDesc.']]></description>';
75  }
81  public function setLang($sLang ){
82  $this->header.='<language><![CDATA['.$sLang .']]></language>';
83  }
89  public function setAdresseRss($sAdresseRss){
90  $this->sAdresseRss=$sAdresseRss;
91  }
97  public function addNews($tab){
98 
99  $this->news.='<item>';
100  $this->news.='<title><![CDATA['.$tab['titre'].']]></title>';
101  if(isset($tab['date'])){
102  $this->news.='<pubDate>'.date("r", strtotime($tab['date'])).'</pubDate>';
103  }
104  if(isset($tab['auteur'])){
105  $this->news.='<author><![CDATA['.$tab['auteur'].']]></author>';
106  }
107  $this->news.='<description><![CDATA['.$tab['desc'].']]></description>';
108  $this->news.='<guid>'.$this->sUrl.'#'.$tab['id'].'</guid>';
109  if(isset($tab['link'])){
110  $this->news.='<link>'.$tab['link'].'</link>';
111  }
112 
113  $this->news.='</item>';
114 
115 
116  }
122  public function getContent(){
123 
124  $head='<?xml version="1.0" encoding="ISO-8859-1" ?>'."\n";
125  $head.='<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">';
126  $foot='</rss>';
127  $atom='<atom:link href="'.$this->sAdresseRss.'" rel="self" type="application/rss+xml" />';
128  $sRss=$head.'<channel>'.$atom.$this->header.$this->news.'</channel>'.$foot;
129 
130  $oFile=new _file(_root::getConfigVar('path.data').'xml/'.$this->sName.'.rss');
131  $oFile->setContent($sRss);
132  $oFile->save();
133 
134  return $sRss;
135  }
136 
137 }
static getConfigVar($sCatAndVar, $uDefaut=null)
Definition: class_root.php:654
setDesc($sDesc)
Definition: plugin_rss.php:73
setTitre($sTitre)
Definition: plugin_rss.php:56
setName($sName)
Definition: plugin_rss.php:48
setUrl($sUrl)
Definition: plugin_rss.php:64
__construct($sName=null)
Definition: plugin_rss.php:37
setLang($sLang)
Definition: plugin_rss.php:81
setAdresseRss($sAdresseRss)
Definition: plugin_rss.php:89
addNews($tab)
Definition: plugin_rss.php:97