Feed.class.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. class Feed extends SQLiteEntity{
  3. protected $id,$name,$url,$unread=0,$events=array(),$description,$website,$folder;
  4. protected $TABLE_NAME = 'feed';
  5. protected $CLASS_NAME = 'Feed';
  6. protected $object_fields =
  7. array(
  8. 'id'=>'key',
  9. 'name'=>'string',
  10. 'description'=>'longstring',
  11. 'website'=>'longstring',
  12. 'url'=>'longstring',
  13. 'unread'=>'integer',
  14. 'folder'=>'integer'
  15. );
  16. function __construct($name=null,$url=null){
  17. $this->name = $name;
  18. $this->url = $url;
  19. parent::__construct();
  20. }
  21. function getInfos(){
  22. $xml = @simplexml_load_file($this->url);
  23. if($xml!=false){
  24. $this->name = array_shift ($xml->xpath('channel/title'));
  25. $this->description = array_shift ($xml->xpath('channel/description'));
  26. $this->website = array_shift ($xml->xpath('channel/link'));
  27. }
  28. }
  29. function parse(){
  30. $xml = @simplexml_load_file($this->url,"SimpleXMLElement",LIBXML_NOCDATA);
  31. if($xml!=false){
  32. $this->name = array_shift ($xml->xpath('channel/title'));
  33. $this->description = array_shift ($xml->xpath('channel/description'));
  34. $this->website = array_shift ($xml->xpath('channel/link'));
  35. $eventManager = new Event();
  36. foreach($xml->xpath('//item') as $item){
  37. $alreadyParsed = $eventManager->load(array('guid'=>$item->guid));
  38. if(!$alreadyParsed){
  39. $event = new Event($item->guid,$item->title);
  40. $namespaces = $item->getNameSpaces(true);
  41. if(isset($namespaces['dc'])){
  42. $dc = $item->children($namespaces['dc']);
  43. $event->setCreator($dc->creator);
  44. $event->setPubdate($dc->date);
  45. if($event->getPubdate()=='')
  46. $event->setPubdate($dc->pubDate);
  47. }
  48. if(trim($event->getPubdate()==''))
  49. $event->setPubdate($item->pubDate);
  50. if(trim($event->getPubdate()==''))
  51. $event->setPubdate($item->date);
  52. if(trim($event->getCreator()==''))
  53. $event->setCreator($item->creator);
  54. $event->setContent($item->children($namespaces['content']));
  55. $event->setLink($item->link);
  56. $event->setCategory($item->category);
  57. $event->setDescription(utf8_decode($item->description));
  58. $event->setFeed($this->id);
  59. $event->setUnread(1);
  60. $event->save();
  61. }
  62. }
  63. }else{
  64. $this->name = 'Flux invalide';
  65. $this->description = 'Impossible de se connecter au flux demand&eacute, peut &ecirc;tre est il en maintenance?';
  66. }
  67. }
  68. function getDescription(){
  69. return stripslashes($this->description);
  70. }
  71. function setDescription($description){
  72. $this->description = $description;
  73. }
  74. function getWebSite(){
  75. return $this->website;
  76. }
  77. function setWebSite($website){
  78. $this->website = $website;
  79. }
  80. function getId(){
  81. return $this->id;
  82. }
  83. function getUrl(){
  84. return $this->url;
  85. }
  86. function setUrl($url){
  87. $this->url = $url;
  88. }
  89. function getName(){
  90. return (isset($this->name)?$this->name:$this->url);
  91. }
  92. function setName($name){
  93. $this->name = $name;
  94. }
  95. function getUnread(){
  96. return $this->unread;
  97. }
  98. function getEvents($start=0,$limit=10000,$order){
  99. $eventManager = new Event();
  100. $events = $eventManager->loadAll(array('feed'=>$this->getId()),$order,$start.','.$limit);
  101. return $events;
  102. }
  103. function countUnreadEvents(){
  104. $result = 0;
  105. $eventManager = new Event();
  106. $result = $eventManager->rowCount(array('feed'=>$this->getId(),'unread'=>'1'));
  107. return $result;
  108. }
  109. function getFolder(){
  110. return $this->folder;
  111. }
  112. function setFolder($folder){
  113. $this->folder = $folder;
  114. }
  115. }
  116. ?>