You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

blogs_last_post.php 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. require('CURL.php');
  3. class Blogs_last_post extends CURL{
  4. private $_result;
  5. /*private $listeImages = array(
  6. 0 => 0, // penelope
  7. 1 => 12, //explosm
  8. 2 => 0, // margaux
  9. );
  10. private $nomImages = array(
  11. 0 => 'PenelopeBagieu',
  12. 1 => 'CyanideAndHapiness',
  13. 2 => 'MargauxMotin',
  14. );
  15. public $link = array(
  16. 0 => 'http://www.penelope-jolicoeur.com/',
  17. 1 => 'http://www.explosm.net/comics/',
  18. 2 => 'http://margauxmotin.typepad.fr/',
  19. );*/
  20. private $link = array();
  21. function getResult()
  22. {
  23. return $this->_result;
  24. }
  25. public function getLinks(){
  26. if($linksXML = @simplexml_load_file('../db/blog_links.xml')){
  27. foreach($linksXML->link as $individualLink){
  28. $this->link[] = array('name'=>$individualLink->name, 'url'=>$individualLink->url, 'number'=>$individualLink->number);
  29. }
  30. return $this->link;
  31. }
  32. else
  33. return [];
  34. }
  35. function getTitles()
  36. {
  37. $xhtml = "";
  38. try{
  39. foreach($this->exec() as $result)
  40. {
  41. $xhtml .= $this->getTitle($result);
  42. $xhtml .= '<br/>';
  43. }
  44. }catch(Exception $e)
  45. {
  46. $xhtml .= $this->error();
  47. }
  48. return $xhtml;
  49. }
  50. function getTitle($result = null, $url = null)
  51. {
  52. if(isset($result))
  53. {
  54. preg_match( "/<h3 class=\"entry-header\">(.*)<\/h3>/i", $result, $match );
  55. if(isset($match[1]))
  56. return utf8_decode(strip_tags($match[1]));
  57. else{
  58. preg_match( "/<title>(.*)<\/title>/i", $result, $title );
  59. if(isset($title[1]))
  60. return $title[1];
  61. else
  62. return 'Erreur : pas de titre de blog trouv�.';
  63. }
  64. }
  65. //TODO en fonction de l'url et non du resultat du cURL
  66. }
  67. function getPost()
  68. {
  69. }
  70. function createThumbnail($result, $title = 0)
  71. {
  72. if(isset($result))
  73. {
  74. preg_match_all( "#<img[^>]+src=['|\"](.*?)['|\"][^>]*>#i", $result, $match );
  75. /*$ret = file_put_contents('match.txt', var_export($match,true), FILE_APPEND);
  76. if ($ret === false)
  77. {
  78. echo 'erreur';
  79. }*/
  80. $number = $this->link[$title]['number'];
  81. $title = $this->link[$title]['name'];
  82. if(isset($match[1][(int)$number]))
  83. {
  84. $source = @imagecreatefromjpeg($match[1][(int)$number]);
  85. if($source == false)
  86. $source = @imagecreatefrompng($match[1][(int)$number]);
  87. $wSource = @imagesx($source);
  88. $hSource = @imagesy($source);
  89. $destination = imagecreatetruecolor(50, 50);
  90. @imagecopyresampled($destination, $source, 0, 0, 0, 0, 50, 50, $wSource, $hSource);
  91. @imagepng($destination, 'images/blogs/'.$title.'.png');
  92. return 'images/blogs/'.$title.'.png';
  93. }
  94. }
  95. }
  96. function getImages($notFromGetImage = false)
  97. {
  98. if($notFromGetImage){
  99. //TODO stuff
  100. }else{
  101. $xhtml = "";
  102. $i = 0;
  103. try{
  104. foreach($this->exec() as $result)
  105. {
  106. $xhtml .= '<img src="'.$this->createThumbnail($result, $i).'" />';
  107. $xhtml .= '<br/>';
  108. $i++;
  109. }
  110. }catch(Exception $e)
  111. {
  112. $xhtml .= $this->error();
  113. }
  114. return $xhtml;
  115. }
  116. }
  117. function getAllImagesToChoose($result,$notFromGetImage = false)
  118. {
  119. if($notFromGetImage){
  120. //TODO stuff
  121. }else{
  122. preg_match_all( "#<img[^>]+src=['|\"](.*?)['|\"][^>]*>#i", $result, $match );
  123. $nbImages = count($match[1]);
  124. $xhtml = 'Liste d\'images : <br/>';
  125. for($i = 0; $i<$nbImages; $i++){
  126. $xhtml .= '<img src="'.$match[1][$i].'" id="n-'.$i.'" class="choose"/><br/>';
  127. }
  128. return $xhtml;
  129. }
  130. }
  131. function getEverything()
  132. {
  133. $temps_debut = microtime(true);
  134. $xhtml = "";
  135. $i = 0;
  136. try{
  137. foreach($this->exec() as $result)
  138. {
  139. $xhtml .= '<a href="'.$this->link[$i]['url'].'" target="_blank" class="blogLinks"><img src="'.$this->createThumbnail($result, $i).'" />&nbsp;&nbsp;'.utf8_encode($this->getTitle($result))."</a>";
  140. $xhtml .= '<br/>';
  141. $i++;
  142. }
  143. }catch(Exception $e)
  144. {
  145. $xhtml .= $this->error();
  146. }
  147. $temps_fin = microtime(true);
  148. $xhtml .= 'Temps d\'execution : '.round($temps_fin - $temps_debut, 4).'s';
  149. return $xhtml;
  150. }
  151. }