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

/plugins/icefilms/library/X/VlcShares/Plugins/IceFilms.php

http://vlc-shares.googlecode.com/
PHP | 793 lines | 466 code | 201 blank | 126 comment | 90 complexity | 891f3cfa6ee3d088b5ec5271cd4b7084 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * Add IceFilms site as a video source
  4. * @author ximarx
  5. *
  6. */
  7. class X_VlcShares_Plugins_IceFilms extends X_VlcShares_Plugins_Abstract implements X_VlcShares_Plugins_ResolverInterface {
  8. const VERSION = '0.2.1';
  9. const VERSION_CLEAN = '0.2.1';
  10. const SORT_MOVIES = 'mov';
  11. const SORT_TVSHOWS = 'tvs';
  12. const SORT_OTHER = 'oth';
  13. const SORT_MUSIC = 'mus';
  14. const SORT_STANDUP = 'sdu';
  15. const TYPE_MEGAVIDEO = 'mv';
  16. const TYPE_MEGAUPLOAD = 'mu';
  17. public function __construct() {
  18. $this->setPriority('gen_beforeInit')
  19. ->setPriority('getCollectionsItems')
  20. ->setPriority('preRegisterVlcArgs')
  21. ->setPriority('getShareItems')
  22. ->setPriority('preGetModeItems')
  23. ->setPriority('getIndexManageLinks')
  24. ->setPriority('getIndexMessages')
  25. ;
  26. }
  27. /**
  28. * Inizialize translator for this plugin
  29. * @param Zend_Controller_Action $controller
  30. */
  31. function gen_beforeInit(Zend_Controller_Action $controller) {
  32. $this->helpers()->language()->addTranslation(__CLASS__);
  33. }
  34. /**
  35. * Add the main link for icefilms
  36. * @param Zend_Controller_Action $controller
  37. */
  38. public function getCollectionsItems(Zend_Controller_Action $controller) {
  39. X_Debug::i("Plugin triggered");
  40. $link = new X_Page_Item_PItem($this->getId(), X_Env::_('p_icefilms_collectionindex'));
  41. $link->setIcon('/images/icefilms/logo.png')
  42. ->setDescription(X_Env::_('p_icefilms_collectionindex_desc'))
  43. ->setType(X_Page_Item_PItem::TYPE_CONTAINER)
  44. ->setLink(
  45. array(
  46. 'controller' => 'browse',
  47. 'action' => 'share',
  48. 'p' => $this->getId(),
  49. ), 'default', true
  50. );
  51. return new X_Page_ItemList_PItem(array($link));
  52. }
  53. /**
  54. * Get category/video list
  55. * @param unknown_type $provider
  56. * @param unknown_type $location
  57. * @param Zend_Controller_Action $controller
  58. */
  59. public function getShareItems($provider, $location, Zend_Controller_Action $controller) {
  60. if ( $provider != $this->getId() ) return;
  61. X_Debug::i('Plugin triggered');
  62. X_VlcShares_Plugins::broker()->unregisterPluginClass('X_VlcShares_Plugins_SortItems');
  63. $items = new X_Page_ItemList_PItem();
  64. X_Debug::i("Requested location: $location");
  65. // location format:
  66. // sortType/subType/page/thread/linkType:linkId
  67. $split = $location != '' ? @explode('/', $location, 6) : array();
  68. @list($sortType, $subType, $page, $series, $thread, $linkTypeId) = $split;
  69. X_Debug::i("Exploded location: ".var_export($split, true));
  70. switch ( count($split) ) {
  71. case 6:
  72. // we shouldn't be here!
  73. case 5:
  74. $this->_fetchVideos($items, $sortType, $subType, $page, $series, $thread);
  75. break;
  76. case 4:
  77. $this->_fetchEpisodes($items, $sortType, $subType, $page, $series);
  78. break;
  79. case 2:
  80. $page = 1;
  81. case 3:
  82. $this->_fetchThreads($items, $sortType, $subType, $page);
  83. break;
  84. case 1:
  85. $this->_fetchClassification($items, $sortType);
  86. break;
  87. case 0:
  88. default:
  89. $this->disableCache();
  90. $this->_fetchSortType($items);
  91. }
  92. return $items;
  93. }
  94. /**
  95. * This hook can be used to add low priority args in vlc stack
  96. *
  97. * @param X_Vlc $vlc vlc wrapper object
  98. * @param string $provider id of the plugin that should handle request
  99. * @param string $location to stream
  100. * @param Zend_Controller_Action $controller the controller who handle the request
  101. */
  102. public function preRegisterVlcArgs(X_Vlc $vlc, $provider, $location, Zend_Controller_Action $controller) {
  103. // this plugin inject params only if this is the provider
  104. if ( $provider != $this->getId() ) return;
  105. // i need to register source as first, because subtitles plugin use source
  106. // for create subfile
  107. X_Debug::i('Plugin triggered');
  108. $location = $this->resolveLocation($location);
  109. if ( $location !== null ) {
  110. // TODO adapt to newer api when ready
  111. $vlc->registerArg('source', "\"$location\"");
  112. } else {
  113. X_Debug::e("No source o_O");
  114. }
  115. }
  116. /**
  117. * Add button -watch megavideo stream directly-
  118. *
  119. * @param string $provider
  120. * @param string $location
  121. * @param Zend_Controller_Action $controller
  122. */
  123. public function preGetModeItems($provider, $location, Zend_Controller_Action $controller) {
  124. if ( $provider != $this->getId()) return;
  125. X_Debug::i("Plugin triggered");
  126. $url = $this->resolveLocation($location);
  127. if ( $url ) {
  128. $link = new X_Page_Item_PItem('core-directwatch', X_Env::_('p_icefilms_watchdirectly'));
  129. $link->setIcon('/images/icons/play.png')
  130. ->setType(X_Page_Item_PItem::TYPE_PLAYABLE)
  131. ->setLink($url);
  132. return new X_Page_ItemList_PItem(array($link));
  133. } else {
  134. // if there is no link, i have to remove start-vlc button
  135. // and replace it with a Warning button
  136. X_Debug::i('Setting priority to filterModeItems');
  137. $this->setPriority('filterModeItems', 99);
  138. $link = new X_Page_Item_PItem('megavideo-warning', X_Env::_('p_icefilms_invalidlink'));
  139. $link->setIcon('/images/msg_error.png')
  140. ->setType(X_Page_Item_PItem::TYPE_ELEMENT)
  141. ->setLink(array (
  142. 'controller' => 'browse',
  143. 'action' => 'share',
  144. 'p' => $this->getId(),
  145. 'l' => X_Env::encode($this->getParentLocation($location)),
  146. ), 'default', true);
  147. return new X_Page_ItemList_PItem(array($link));
  148. }
  149. }
  150. /**
  151. * Remove vlc-play button if location is invalid
  152. * @param X_Page_Item_PItem $item,
  153. * @param string $provider
  154. * @param Zend_Controller_Action $controller
  155. */
  156. public function filterModeItems(X_Page_Item_PItem $item, $provider,Zend_Controller_Action $controller) {
  157. if ( $item->getKey() == 'core-play') {
  158. X_Debug::i('plugin triggered');
  159. X_Debug::w('core-play flagged as invalid because the link is invalid');
  160. return false;
  161. }
  162. }
  163. private $cachedLocation = array();
  164. /**
  165. * @see X_VlcShares_Plugins_ResolverInterface::resolveLocation
  166. * @param string $location
  167. * @return string real address of a resource
  168. */
  169. function resolveLocation($location = null) {
  170. if ( $location == '' || $location == null ) return false;
  171. if ( array_key_exists($location, $this->cachedLocation) ) {
  172. return $this->cachedLocation[$location];
  173. }
  174. X_Debug::i("Requested location: $location");
  175. $split = $location != '' ? @explode('/', $location, 6) : array();
  176. @list($sortType, $subType, $page, $serie, $thread, $linkTypeId) = $split;
  177. //@list($videoType, $videoId) = @explode(':', $linkTypeId, 2);
  178. //@list($videoId, $secret) = @explode(':', $linkTypeId, 2);
  179. $videoType = 'unk';
  180. $videoId = $linkTypeId;
  181. //@list($letter, $thread, $href) = explode('/', $location, 3);
  182. X_Debug::i("SortType: $sortType, SubType: $subType, Page: $page, Serie: $serie, Thread: $thread, VType: $videoType, VID: $videoId");
  183. if ( $videoType == null || $videoId == null ) {
  184. $this->cachedLocation[$location] = false;
  185. return false;
  186. }
  187. // need to get the real id for the video
  188. $realLink = $this->_getRealId($videoId, $thread);
  189. $return = false;
  190. /* @var $hosterHelper X_VlcShares_Plugins_Helper_Hoster */
  191. $hosterHelper = $this->helpers('hoster');
  192. try {
  193. $return = $hosterHelper->findHoster($realLink)->getPlayable($realLink, false);
  194. } catch ( Exception $e ) {
  195. X_Debug::e("Hoster exception: {$e->getMessage()}");
  196. }
  197. $this->cachedLocation[$location] = $return;
  198. return $return;
  199. }
  200. /**
  201. * Support for parent location
  202. * @see X_VlcShares_Plugins_ResolverInterface::getParentLocation
  203. * @param $location
  204. */
  205. function getParentLocation($location = null) {
  206. if ( $location == '' || $location == null ) return false;
  207. //X_Debug::i($location);
  208. $exploded = explode('/', $location);
  209. if ( count($exploded) == 5 && $exploded[0] != self::SORT_TVSHOWS ) {
  210. // i have to add an extra pop
  211. // if series == null
  212. array_pop($exploded);
  213. }
  214. //X_Debug::i(var_export($exploded, true));
  215. // sort/sub/page/serie/thread/video
  216. if ( count($exploded) == 3 ) {
  217. // i have to add an extra pop
  218. // to jump from threads to sub page
  219. array_pop($exploded);
  220. }
  221. if ( count($exploded) == 2 && ( $exploded[0] == self::SORT_OTHER || $exploded[0] == self::SORT_STANDUP || $exploded[0] == self::SORT_MUSIC ) ) {
  222. // i have to add an extra pop
  223. // if series == null
  224. array_pop($exploded);
  225. }
  226. array_pop($exploded);
  227. //X_Debug::i(var_export($exploded, true));
  228. if ( count($exploded) >= 1 ) {
  229. return implode('/', $exploded);
  230. } else {
  231. return null;
  232. }
  233. }
  234. /**
  235. * Add the link for -manage-megavideo-
  236. * @param Zend_Controller_Action $this
  237. * @return X_Page_ItemList_ManageLink
  238. */
  239. public function getIndexManageLinks(Zend_Controller_Action $controller) {
  240. $link = new X_Page_Item_ManageLink($this->getId(), X_Env::_('p_icefilms_mlink'));
  241. $link->setTitle(X_Env::_('p_icefilms_managetitle'))
  242. ->setIcon('/images/icefilms/logo.png')
  243. ->setLink(array(
  244. 'controller' => 'config',
  245. 'action' => 'index',
  246. 'key' => 'icefilms'
  247. ), 'default', true);
  248. return new X_Page_ItemList_ManageLink(array($link));
  249. }
  250. /**
  251. * Show an error message if megavideo plugin version < 0.2.1
  252. * @param Zend_Controller_Action $this
  253. * @return X_Page_ItemList_Message
  254. */
  255. public function getIndexMessages(Zend_Controller_Action $controller) {
  256. try {
  257. $megauploadHelper = $this->helpers('megaupload');
  258. } catch (Exception $e) {
  259. X_Debug::i('Plugin triggered');
  260. $m = new X_Page_Item_Message($this->getId(), X_Env::_('p_icefilms_dashboardwarning'));
  261. $m->setType(X_Page_Item_Message::TYPE_ERROR);
  262. return new X_Page_ItemList_Message(array($m));
  263. }
  264. }
  265. private function _fetchClassification(X_Page_ItemList_PItem $items, $sortType) {
  266. $cType = array();
  267. $lets = strtoupper('1,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z');
  268. $cType = explode(',', $lets);
  269. foreach ( $cType as $type ) {
  270. $item = new X_Page_Item_PItem($this->getId()."-$sortType-$type", ($type == '1' ? '#' : $type));
  271. $item->setIcon('/images/icons/folder_32.png')
  272. ->setType(X_Page_Item_PItem::TYPE_CONTAINER)
  273. ->setCustom(__CLASS__.':location', "$sortType/$type")
  274. ->setDescription(APPLICATION_ENV == 'development' ? "$sortType/$type" : null)
  275. ->setLink(array(
  276. 'l' => X_Env::encode("$sortType/$type")
  277. ), 'default', false);
  278. $items->append($item);
  279. }
  280. }
  281. private function _fetchSortType(X_Page_ItemList_PItem $items) {
  282. $sorts = array(
  283. self::SORT_MOVIES => X_Env::_('p_icefilms_sort_movies'),
  284. self::SORT_TVSHOWS => X_Env::_('p_icefilms_sort_tvshows'),
  285. self::SORT_OTHER."/1" => X_Env::_('p_icefilms_sort_other'),
  286. self::SORT_STANDUP."/1" => X_Env::_('p_icefilms_sort_standup'),
  287. self::SORT_MUSIC."/1" => X_Env::_('p_icefilms_sort_music'),
  288. );
  289. foreach ( $sorts as $sortL => $sortLabel ) {
  290. $item = new X_Page_Item_PItem($this->getId()."-sort-$sortL", $sortLabel);
  291. $item->setIcon('/images/icons/folder_32.png')
  292. ->setType(X_Page_Item_PItem::TYPE_CONTAINER)
  293. ->setCustom(__CLASS__.':location', "$sortL")
  294. ->setDescription(APPLICATION_ENV == 'development' ? "$sortL" : null)
  295. ->setLink(array(
  296. 'l' => X_Env::encode("$sortL")
  297. ), 'default', false);
  298. $items->append($item);
  299. }
  300. }
  301. private function _fetchThreads(X_Page_ItemList_PItem $items, $sortType, $subType, $page = 1) {
  302. X_Debug::i("Fetching threads for $sortType/$subType/$page");
  303. switch ( $sortType ) {
  304. case self::SORT_MOVIES:
  305. // subType = letter
  306. $url = $this->config('index.movies.url', "http://www.icefilms.info/movies/a-z/" ).$subType;
  307. $pattern = '/<a href=\/ip\.php\?v\=([^\&]+)\&>([^\<]+)<\/a>/';
  308. break;
  309. case self::SORT_TVSHOWS:
  310. // subType = letter
  311. $url = $this->config('index.tvshows.url', "http://www.icefilms.info/tv/a-z/" ).$subType;
  312. $pattern = '/<a href=\/tv\/series\/([^\>]+)>([^\<]+)<\/a>([^\<]+)<br>/';
  313. break;
  314. case self::SORT_OTHER:
  315. // subType = letter
  316. $url = $this->config('index.other.url', "http://www.icefilms.info/other/a-z/" ).$subType;
  317. $pattern = '/<a href=\/ip\.php\?v\=([^\&]+)\&>([^\<]+)<\/a>/';
  318. break;
  319. case self::SORT_MUSIC:
  320. // subType = letter
  321. $url = $this->config('index.music.url', "http://www.icefilms.info/music/a-z/" ).$subType;
  322. $pattern = '/<a href=\/ip\.php\?v\=([^\&]+)\&>([^\<]+)<\/a>/';
  323. break;
  324. case self::SORT_STANDUP:
  325. // subType = letter
  326. $url = $this->config('index.standup.url', "http://www.icefilms.info/standup/a-z/" ).$subType;
  327. $pattern = '/<a href=\/ip\.php\?v\=([^\&]+)\&>([^\<]+)<\/a>/';
  328. break;
  329. }
  330. /*
  331. if ( $page > 1 ) {
  332. // adding page param
  333. $url .= "&page=$page";
  334. }
  335. */
  336. // cache validity for the request = 15 minutes
  337. $htmlString = $this->_loadPage($url, 15);
  338. $matches = array();
  339. if ( preg_match_all($pattern, $htmlString, $matches, PREG_SET_ORDER) ) {
  340. X_Debug::i("Threads found: ".count($matches));
  341. //X_Debug::i("Threads: ".var_export($matches, true));
  342. // check for next page before match overwrite
  343. $hasNext = $this->helpers()->paginator()->hasNext($matches, $page);
  344. $pageCount = $this->helpers()->paginator()->getPages($matches);
  345. if ( $this->helpers()->paginator()->hasPrevious($matches, $page) ) {
  346. $item = new X_Page_Item_PItem('previous-page', X_Env::_('previouspage', $page - 1, $pageCount ));
  347. $tmpPage = $page - 1;
  348. $item//->setIcon('/images/icons/folder_32.png')
  349. ->setType(X_Page_Item_PItem::TYPE_CONTAINER)
  350. ->setCustom(__CLASS__.':location', "$sortType/$subType/$tmpPage")
  351. ->setLink(array(
  352. 'l' => X_Env::encode("$sortType/$subType/$tmpPage")
  353. ), 'default', false);
  354. if ( APPLICATION_ENV == 'development' ) {
  355. $item->setDescription("$sortType/$subType/$tmpPage");
  356. }
  357. $items->append($item);
  358. }
  359. // reduce the matches for this items only
  360. $matches = $this->helpers()->paginator()->getPage($matches, $page);
  361. foreach ($matches as $thread) {
  362. if ( $sortType == self::SORT_TVSHOWS ) {
  363. @list(, $threadId, $label, $episodes) = $thread;
  364. $threadId = str_replace('/', ':', $threadId);
  365. $label .= " [$episodes]";
  366. } else {
  367. @list(, $threadId, $label) = $thread;
  368. $threadId = "null/$threadId";
  369. }
  370. $item = new X_Page_Item_PItem($this->getId()."-$sortType-$subType-$threadId", $label);
  371. $item->setIcon('/images/icons/folder_32.png')
  372. ->setType(X_Page_Item_PItem::TYPE_CONTAINER)
  373. ->setCustom(__CLASS__.':location', "$sortType/$subType/$page/$threadId")
  374. ->setLink(array(
  375. 'l' => X_Env::encode("$sortType/$subType/$page/$threadId")
  376. ), 'default', false);
  377. if ( APPLICATION_ENV == 'development' ) {
  378. $item->setDescription("$sortType/$subType/$page/$threadId");
  379. }
  380. $items->append($item);
  381. }
  382. if ( $hasNext ) {
  383. $item = new X_Page_Item_PItem('next-page', X_Env::_('nextpage', $page + 1, $pageCount));
  384. $tmpPage = $page + 1;
  385. $item//->setIcon('/images/icons/folder_32.png')
  386. ->setType(X_Page_Item_PItem::TYPE_CONTAINER)
  387. ->setCustom(__CLASS__.':location', "$sortType/$subType/$tmpPage")
  388. ->setLink(array(
  389. 'l' => X_Env::encode("$sortType/$subType/$tmpPage")
  390. ), 'default', false);
  391. if ( APPLICATION_ENV == 'development' ) {
  392. $item->setDescription("$sortType/$subType/$tmpPage");
  393. }
  394. $items->append($item);
  395. }
  396. } else {
  397. X_Debug::e("Regex failed {{$pattern}}");
  398. }
  399. }
  400. private function _fetchEpisodes(X_Page_ItemList_PItem $items, $sortType, $subType, $page = 1, $serie) {
  401. X_Debug::i("Fetching episodes for $sortType/$subType/$page/$serie");
  402. $url = $this->config('index.episodes.url', "http://www.icefilms.info/tv/series/" ).str_replace(':','/', $serie);
  403. $pattern = '/<a href=\/ip\.php\?v\=([^\&]+)&>([^\<]+)<\/a>/';
  404. $htmlString = $this->_loadPage($url);
  405. $matches = array();
  406. if ( preg_match_all($pattern, $htmlString, $matches, PREG_SET_ORDER) ) {
  407. X_Debug::i("Threads found: ".count($matches));
  408. foreach ($matches as $thread) {
  409. @list(, $epId, $label) = $thread;
  410. //$threadId .= '/0';
  411. $item = new X_Page_Item_PItem($this->getId()."-$sortType-$subType-$serie-$epId", $label);
  412. $item->setIcon('/images/icons/folder_32.png')
  413. ->setType(X_Page_Item_PItem::TYPE_CONTAINER)
  414. ->setCustom(__CLASS__.':location', "$sortType/$subType/$page/$serie/$epId")
  415. ->setLink(array(
  416. 'l' => X_Env::encode("$sortType/$subType/$page/$serie/$epId")
  417. ), 'default', false);
  418. if ( APPLICATION_ENV == 'development' ) {
  419. $item->setDescription("$sortType/$subType/$page/$serie/$epId");
  420. }
  421. $items->append($item);
  422. }
  423. } else {
  424. X_Debug::e("Regex failed {{$pattern}}");
  425. }
  426. }
  427. private function _fetchVideos(X_Page_ItemList_PItem $items, $sortType, $subType, $page, $serie, $thread) {
  428. X_Debug::i("Fetching videos for $sortType/$subType/$page/$serie/$thread");
  429. $url = $this->config('index.video.url', 'http://www.icefilms.info/membersonly/components/com_iceplayer/video.php?vid=').$thread;
  430. $htmlString = $this->_loadPage($url);
  431. //$htmlString = str_replace(array("\n", "\r", "\t", chr(0xC2), chr(0xA0), chr(157)), '', $htmlString);
  432. X_Debug::i($htmlString);
  433. $catPattern = '/(*ANY)<div class\=ripdiv><b>([^\<]+)<\/b>/';
  434. //$urlPattern = '/url\=http\:\/\/www.megaupload.com\/\?d\=([^\&]+)&([^\>]+)>([^\<]+)</';
  435. $urlPattern = '/onclick\=\\\'go\(([0-9]+)\)\\\'\>([^\<]+)</';
  436. $matches = array();
  437. $links = array();
  438. if ( preg_match_all($catPattern, $htmlString, $matches, PREG_OFFSET_CAPTURE) ) {
  439. for ($i = 0; $i < count($matches[0]); $i++ ) {
  440. //$links[$matches[1][$i][0]] = array();
  441. $catLabel = $matches[1][$i][0];
  442. if ( array_key_exists($i+1, $matches[0]) ) {
  443. if ( !preg_match_all($urlPattern, substr($htmlString, $matches[0][$i][1], $matches[0][$i+1][1] - $matches[0][$i][1] ), $lMatches, PREG_SET_ORDER) ) {
  444. X_Debug::e("Pattern failure: {$urlPattern}");
  445. continue;
  446. }
  447. } else {
  448. if ( !preg_match_all($urlPattern, substr($htmlString, $matches[0][$i][1]), $lMatches, PREG_SET_ORDER) ) {
  449. X_Debug::e("Pattern failure: {$urlPattern}");
  450. continue;
  451. }
  452. }
  453. //X_Debug::i(var_export($lMatches, true));
  454. foreach ($lMatches as $lm) {
  455. //@list(, $muId, , $label) = $lm;
  456. @list(, $muId, $label) = $lm;
  457. // $muId now is a videoId of Icefilms
  458. $label = "$label ($catLabel)";
  459. //$videoId = self::TYPE_MEGAUPLOAD.":$muId";
  460. $videoId = $muId;
  461. $item = new X_Page_Item_PItem($this->getId()."-megaupload", "$label");
  462. $item->setIcon('/images/icons/file_32.png')
  463. ->setType(X_Page_Item_PItem::TYPE_ELEMENT)
  464. ->setCustom(__CLASS__.':location', "$sortType/$subType/$page/$serie/$thread/$videoId")
  465. ->setLink(array(
  466. 'action' => 'mode',
  467. 'l' => X_Env::encode("$sortType/$subType/$page/$serie/$thread/$videoId")
  468. ), 'default', false);
  469. if ( APPLICATION_ENV == 'development' ) {
  470. $item->setDescription("$sortType/$subType/$page/$serie/$thread/$videoId");
  471. }
  472. $items->append($item);
  473. }
  474. }
  475. } else {
  476. X_Debug::i("Pattern failure {$catPattern} or no video found");
  477. }
  478. }
  479. /**
  480. * Load an $uri performing an http request (or from cache if possible/allowed)
  481. */
  482. private function _loadPage($uri, $validityCache = 0) {
  483. $cachePlugin = false;
  484. if ( $validityCache > 0 ) {
  485. if ( X_VlcShares_Plugins::broker()->isRegistered('cache') ) {
  486. /* @var $cachePlugin X_VlcShares_Plugins_Cache */
  487. $cachePlugin = X_VlcShares_Plugins::broker()->getPlugins('cache');
  488. try {
  489. X_Debug::i("Retrieving cache entry for {{$uri}}");
  490. return $cachePlugin->retrieveItem($uri);
  491. } catch (Exception $e) {
  492. X_Debug::i("No valid cache entry for $uri");
  493. }
  494. }
  495. }
  496. X_Debug::i("Loading page $uri");
  497. $http = new Zend_Http_Client($uri, array(
  498. 'maxredirects' => $this->config('request.maxredirects', 10),
  499. 'timeout' => $this->config('request.timeout', 25)
  500. //'keepalive' => true
  501. ));
  502. $http->setHeaders(array(
  503. $this->config('hide.useragent', false) ? 'User-Agent: vlc-shares/'.X_VlcShares::VERSION .' icefilms/'.self::VERSION_CLEAN : 'User-Agent: Mozilla/5.0 (X11; Linux i686; rv:2.0.1) Gecko/20101019 Firefox/4.0.1',
  504. //'Content-Type: application/x-www-form-urlencoded'
  505. ));
  506. $response = $http->request();
  507. $htmlString = $response->getBody();
  508. if ( $validityCache > 0 && $cachePlugin ) {
  509. X_Debug::i("Caching page {{$uri}} with validity {{$validityCache}}");
  510. $cachePlugin->storeItem($uri, $htmlString, (int) $validityCache);
  511. }
  512. return $htmlString;
  513. }
  514. private function _getRealId($fakeId, $t) {
  515. try {
  516. /* @var $cacheHelper X_VlcShares_Plugins_Helper_Cache */
  517. $cacheHelper = X_VlcShares_Plugins::helpers()->helper('cache');
  518. $response = $cacheHelper->retrieveItem("icefilms::$t,$fakeId");
  519. X_Debug::i("Valid cache entry found: $response");
  520. return $response;
  521. } catch (Exception $e) {
  522. // no cache plugin or no entry in cache, it's the same
  523. X_Debug::i("Cache disabled or no valid entry found");
  524. }
  525. // hover check
  526. $m = rand(100, 300) * -1;
  527. // time check
  528. $s = rand(5, 50);
  529. $http = new Zend_Http_Client("http://www.icefilms.info/membersonly/components/com_iceplayer/video.php?h=374&w=631&vid=$t&img=", array (
  530. 'maxredirects' => $this->config('request.maxredirects', 10),
  531. 'timeout' => $this->config('request.timeout', 25)
  532. ));
  533. // first request, set the cookies
  534. $htmlString = $http->setCookieJar(true)->request()->getBody();
  535. //$captchaPattern = '/name\=captcha value\=([^\>]+)/';
  536. //$secretPattern = '/name\=secret value\=([^\>]+)/';
  537. $secretPattern = '/f\.lastChild\.value=\"([^\']+)\",a/';
  538. //$iqsPattern = '/name\=iqs value\=([^\>]+)/';
  539. $sec = array();
  540. if ( preg_match($secretPattern, $htmlString, $sec) ) {
  541. if ( count($sec) ) {
  542. $sec = $sec[1];
  543. } else {
  544. X_Debug::w("Secret string not found");
  545. $sec = '';
  546. }
  547. } else {
  548. X_Debug::e("Secret pattern failed {{$secretPattern}}");
  549. $sec = '';
  550. }
  551. $http->setUri('http://www.icefilms.info/membersonly/components/com_iceplayer/video.phpAjaxResp.php');
  552. $http->setHeaders(array(
  553. 'User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.215 Safari/535.1',
  554. 'Content-type:application/x-www-form-urlencoded',
  555. 'Origin: http://www.icefilms.info',
  556. "Referer: http://www.icefilms.info/membersonly/components/com_iceplayer/video.php?h=374&w=631&vid=$t&img="
  557. ));
  558. $http->setMethod(Zend_Http_Client::POST)
  559. ->setParameterPost('id', $fakeId)
  560. ->setParameterPost('s', $s)
  561. ->setParameterPost('iqs', '')
  562. ->setParameterPost('url', '')
  563. ->setParameterPost('m', $m)
  564. ->setParameterPost('cap', '')
  565. ->setParameterPost('sec', $sec)
  566. ->setParameterPost('t', $t);
  567. //X_Debug::i("Cookies: ".$http->getCookieJar()->getAllCookies(Zend_Http_CookieJar::COOKIE_STRING_CONCAT));
  568. $response = $http->request()->getBody();
  569. //X_Debug::i("Request: ".$http->getLastRequest());
  570. //X_Debug::i("Response: ".$http->getLastResponse()->getBody());
  571. X_Debug::i("Raw: $response");
  572. $response = trim(urldecode(substr($response, strlen('/membersonly/components/com_iceplayer/GMorBMlet.php?url='))), '&');
  573. X_Debug::i("Filtered: $response");
  574. try {
  575. /* @var $cacheHelper X_VlcShares_Plugins_Helper_Cache */
  576. $cacheHelper = X_VlcShares_Plugins::helpers()->helper('cache');
  577. $cacheHelper->storeItem("icefilms::$t,$fakeId", $response, 15); // store for the next 15 min
  578. X_Debug::i("Value stored in cache for 15 min: {key = icefilms::$t,$fakeId, value = $response}");
  579. } catch (Exception $e) {
  580. // no cache plugin, next time i have to repeat the request
  581. }
  582. return $response;
  583. }
  584. private function disableCache() {
  585. if ( X_VlcShares_Plugins::broker()->isRegistered('cache') ) {
  586. $cache = X_VlcShares_Plugins::broker()->getPlugins('cache');
  587. if ( method_exists($cache, 'setDoNotCache') ) {
  588. $cache->setDoNotCache();
  589. }
  590. }
  591. }
  592. }