PageRenderTime 54ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/bots/chan8/cron.php

https://github.com/NeoRazorX/feedstorm
PHP | 83 lines | 58 code | 7 blank | 18 comment | 9 complexity | ba64e819d35614520eee55d334648054 MD5 | raw file
Possible License(s): LGPL-3.0
  1. <?php
  2. /*
  3. * This file is part of FeedStorm
  4. * Copyright (C) 2014 Carlos Garcia Gomez neorazorx@gmail.com
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as
  8. * published by the Free Software Foundation, either version 3 of the
  9. * License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. require_once 'model/story_preview.php';
  20. function chan8(&$story)
  21. {
  22. $story_preview = new story_preview();
  23. $last_stories = array_merge($story->last_stories( mt_rand(10,100) ), $story->random_stories( mt_rand(10,100) ));
  24. foreach($last_stories as $sto)
  25. {
  26. echo '.';
  27. $story_preview->load($sto->link, $sto->description_uncut());
  28. if( !$story_preview->type AND mb_strlen($sto->description) < 500 )
  29. {
  30. $html = $story_preview->curl_download($sto->link);
  31. $urls = array();
  32. if( preg_match_all('@<meta property="og:image" content="([^"]+)@', $html, $urls) )
  33. {
  34. foreach($urls[1] as $url)
  35. {
  36. $story_preview->load($url);
  37. if($story_preview->type)
  38. {
  39. $sto->description .= ' '.$story_preview->link;
  40. $sto->save();
  41. echo '(img)';
  42. break;
  43. }
  44. }
  45. }
  46. if( !$story_preview->type AND mb_strlen($sto->description) < 200 AND count($sto->topics) == 0 )
  47. {
  48. /// buscamos vĂ­deos de youtube
  49. $urls = array();
  50. if( preg_match_all('@((https?://)?([-\w]+\.[-\w\.]+)+\w(:\d+)?(/([-\w/_\.]*(\?\S+)?)?)*)@', $html, $urls) )
  51. {
  52. foreach($urls[0] as $url)
  53. {
  54. foreach( array('youtube', 'youtu.be', 'vimeo') as $domain )
  55. {
  56. if( strpos($url, $domain) !== FALSE )
  57. {
  58. $story_preview->load($url);
  59. if( in_array($story_preview->type, array('youtube', 'vimeo')) )
  60. {
  61. $sto->description .= ' '.$story_preview->link;
  62. $sto->save();
  63. echo '('.$domain.')';
  64. break;
  65. }
  66. }
  67. }
  68. if($story_preview->type)
  69. break;
  70. }
  71. }
  72. }
  73. }
  74. }
  75. }
  76. chan8($story);