LegifranceJOBridge.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. class LegifranceJOBridge extends BridgeAbstract{
  3. const MAINTAINER = 'Pierre Mazière';
  4. const NAME = 'Journal Officiel de la République Française';
  5. const URI = 'https://www.legifrance.gouv.fr/affichJO.do';
  6. const DESCRIPTION = 'Returns the laws and decrees officially registered daily in France';
  7. const PARAMETERS=array();
  8. private $author;
  9. private $timestamp;
  10. private $uri;
  11. private function extractItem($section,$subsection=null,$origin=null){
  12. $item=array();
  13. $item['author']=$this->author;
  14. $item['timestamp']=$this->timestamp;
  15. $item['uri']=$this->uri.'#'.count($this->items);
  16. $item['title']=$section->plaintext;
  17. if(!is_null($origin)){
  18. $item['title']='[ '.$item['title'].' / '.$subsection->plaintext.' ] '.$origin->plaintext;
  19. $data=$origin;
  20. }elseif(!is_null($subsection)){
  21. $item['title']='[ '.$item['title'].' ] '.$subsection->plaintext;
  22. $data=$subsection;
  23. }else{
  24. $data=$section;
  25. }
  26. $item['content']='';
  27. foreach($data->nextSibling()->find('a') as $content){
  28. $text=$content->plaintext;
  29. $href=$content->nextSibling()->getAttribute('resource');
  30. $item['content'].='<p><a href="'.$href.'">'.$text.'</a></p>';
  31. }
  32. return $item;
  33. }
  34. public function collectData(){
  35. $html=getSimpleHTMLDOM(self::URI)
  36. or $this->returnServer('Unable to download '.self::URI);
  37. $this->author=trim($html->find('h2.title',0)->plaintext);
  38. $uri=$html->find('h2.titleELI',0)->plaintext;
  39. $this->uri=trim(substr($uri,strpos($uri,'https')));
  40. $this->timestamp=strtotime(substr($this->uri,strpos($this->uri,'eli/jo/')+strlen('eli/jo/')));
  41. foreach($html->find('h3') as $section){
  42. $subsections=$section->nextSibling()->find('h4');
  43. foreach($subsections as $subsection){
  44. $origins=$subsection->nextSibling()->find('h5');
  45. foreach($origins as $origin){
  46. $this->items[]=$this->extractItem($section,$subsection,$origin);
  47. }
  48. if(!empty($origins)){
  49. continue;
  50. }
  51. $this->items[]=$this->extractItem($section,$subsection);
  52. }
  53. if(!empty($subsections)){
  54. continue;
  55. }
  56. $this->items[]=$this->extractItem($section);
  57. }
  58. }
  59. }