PageRenderTime 55ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/plugins/gogocinema/library/X/VlcShares/Plugins/GoGoCinema.php

http://vlc-shares.googlecode.com/
PHP | 765 lines | 453 code | 180 blank | 132 comment | 82 complexity | 0633d477e81389d0048683fab7f31a93 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. require_once 'X/VlcShares/Plugins/Abstract.php';
  3. require_once 'Zend/Dom/Query.php';
  4. /**
  5. * Add GoGoCinema site as a video source
  6. * @author ximarx
  7. *
  8. */
  9. class X_VlcShares_Plugins_GoGoCinema extends X_VlcShares_Plugins_Abstract implements X_VlcShares_Plugins_ResolverInterface {
  10. const VERSION = '0.2';
  11. const VERSION_CLEAN = '0.2';
  12. const SORT_ALPHA = 'a';
  13. const SORT_YEAR = 'y';
  14. const SORT_TYPE = 't';
  15. const SORT_SEARCH = 's';
  16. const TYPE_MEGAVIDEO = 'm';
  17. const TYPE_YOUTUBE = 'y';
  18. public function __construct() {
  19. $this->setPriority('gen_beforeInit')
  20. ->setPriority('getCollectionsItems')
  21. ->setPriority('preRegisterVlcArgs')
  22. ->setPriority('getShareItems')
  23. ->setPriority('preGetModeItems')
  24. ->setPriority('getIndexManageLinks')
  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 jigoku
  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_gogocinema_collectionindex'));
  41. $link->setIcon('/images/gogocinema/logo.png')
  42. ->setDescription(X_Env::_('p_gogocinema_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. //$baseUrl = $this->config('base.url', 'http://www.gogocinema.net/mediacenter/index.php?page=ajax_show_folder&id=');
  64. $items = new X_Page_ItemList_PItem();
  65. X_Debug::i("Requested location: $location");
  66. // location format:
  67. // sortType/subType/page/thread/linkType:linkId
  68. $split = $location != '' ? @explode('/', $location, 5) : array();
  69. @list($sortType, $subType, $page, $thread, $linkTypeId) = $split;
  70. X_Debug::i("Exploded location: ".var_export($split, true));
  71. // special case: if sortType = search the subType param can be in
  72. // gogocinema:search
  73. if ( $sortType == self::SORT_SEARCH && is_null($subType) ) {
  74. $this->disableCache();
  75. $searchValue = $controller->getRequest()->getParam("{$this->getId()}:search", null);
  76. if ( $searchValue == null ) {
  77. // go back in index
  78. $split = array();
  79. } else {
  80. $subType = $searchValue;
  81. $split[1] = $searchValue; // in this way sort search doesn't go in classification
  82. }
  83. }
  84. switch ( count($split) ) {
  85. case 5:
  86. // we shouldn't be here!
  87. case 4:
  88. $this->_fetchVideos($items, $sortType, $subType, $page, $thread);
  89. break;
  90. case 2:
  91. $page = 1;
  92. case 3:
  93. $this->_fetchThreads($items, $sortType, $subType, $page);
  94. break;
  95. case 1:
  96. $this->_fetchClassification($items, $sortType);
  97. break;
  98. case 0:
  99. default:
  100. $this->disableCache();
  101. $this->_fetchSortType($items);
  102. }
  103. return $items;
  104. }
  105. /**
  106. * This hook can be used to add low priority args in vlc stack
  107. *
  108. * @param X_Vlc $vlc vlc wrapper object
  109. * @param string $provider id of the plugin that should handle request
  110. * @param string $location to stream
  111. * @param Zend_Controller_Action $controller the controller who handle the request
  112. */
  113. public function preRegisterVlcArgs(X_Vlc $vlc, $provider, $location, Zend_Controller_Action $controller) {
  114. // this plugin inject params only if this is the provider
  115. if ( $provider != $this->getId() ) return;
  116. // i need to register source as first, because subtitles plugin use source
  117. // for create subfile
  118. X_Debug::i('Plugin triggered');
  119. $location = $this->resolveLocation($location);
  120. if ( $location !== null ) {
  121. // TODO adapt to newer api when ready
  122. $vlc->registerArg('source', "\"$location\"");
  123. } else {
  124. X_Debug::e("No source o_O");
  125. }
  126. }
  127. /**
  128. * Add button -watch megavideo stream directly-
  129. *
  130. * @param string $provider
  131. * @param string $location
  132. * @param Zend_Controller_Action $controller
  133. */
  134. public function preGetModeItems($provider, $location, Zend_Controller_Action $controller) {
  135. if ( $provider != $this->getId()) return;
  136. X_Debug::i("Plugin triggered");
  137. $url = $this->resolveLocation($location);
  138. if ( $url ) {
  139. $link = new X_Page_Item_PItem('core-directwatch', X_Env::_('p_gogocinema_watchdirectly'));
  140. $link->setIcon('/images/icons/play.png')
  141. ->setType(X_Page_Item_PItem::TYPE_PLAYABLE)
  142. ->setLink($url);
  143. return new X_Page_ItemList_PItem(array($link));
  144. } else {
  145. // if there is no link, i have to remove start-vlc button
  146. // and replace it with a Warning button
  147. X_Debug::i('Setting priority to filterModeItems');
  148. $this->setPriority('filterModeItems', 99);
  149. $link = new X_Page_Item_PItem('megavideo-warning', X_Env::_('p_gogocinema_invalidlink'));
  150. $link->setIcon('/images/msg_error.png')
  151. ->setType(X_Page_Item_PItem::TYPE_ELEMENT)
  152. ->setLink(array (
  153. 'controller' => 'browse',
  154. 'action' => 'share',
  155. 'p' => $this->getId(),
  156. 'l' => X_Env::encode($this->getParentLocation($location)),
  157. ), 'default', true);
  158. return new X_Page_ItemList_PItem(array($link));
  159. }
  160. }
  161. /**
  162. * Remove vlc-play button if location is invalid
  163. * @param X_Page_Item_PItem $item,
  164. * @param string $provider
  165. * @param Zend_Controller_Action $controller
  166. */
  167. public function filterModeItems(X_Page_Item_PItem $item, $provider,Zend_Controller_Action $controller) {
  168. if ( $item->getKey() == 'core-play') {
  169. X_Debug::i('plugin triggered');
  170. X_Debug::w('core-play flagged as invalid because the link is invalid');
  171. return false;
  172. }
  173. }
  174. private $cachedLocation = array();
  175. /**
  176. * @see X_VlcShares_Plugins_ResolverInterface::resolveLocation
  177. * @param string $location
  178. * @return string real address of a resource
  179. */
  180. function resolveLocation($location = null) {
  181. if ( $location == '' || $location == null ) return false;
  182. if ( array_key_exists($location, $this->cachedLocation) ) {
  183. return $this->cachedLocation[$location];
  184. }
  185. X_Debug::i("Requested location: $location");
  186. $split = $location != '' ? @explode('/', $location, 5) : array();
  187. @list($sortType, $subType, $page, $thread, $linkTypeId) = $split;
  188. @list($videoType, $videoId) = @explode(':', $linkTypeId, 2);
  189. //@list($letter, $thread, $href) = explode('/', $location, 3);
  190. X_Debug::i("SortType: $sortType, SubType: $subType, Page: $page, Thread: $thread, VType: $videoType, VID: $videoId");
  191. if ( $videoType == null || $videoId == null ) {
  192. $this->cachedLocation[$location] = false;
  193. return false;
  194. }
  195. $return = false;
  196. switch ($videoType) {
  197. case self::TYPE_MEGAVIDEO:
  198. try {
  199. /* @var $megavideoHelper X_VlcShares_Plugins_Helper_Megavideo */
  200. $megavideoHelper = $this->helpers('megavideo');
  201. // fetch megavideo ?d= links
  202. @list($mvType, $mvId) = @explode('=', $videoId);
  203. if ( $mvType == 'd') {
  204. // convert megaupload->megavideo id in megavideo id
  205. $http = new Zend_Http_Client("http://www.megavideo.com/?d=$mvId");
  206. $response = $http->request();
  207. $body = $response->getBody();
  208. $matches = array();
  209. if ( preg_match('/flashvars\.v \= \"([^\"]*)\";/', $body, $matches) ) {
  210. $videoId = $matches[1];
  211. } else {
  212. // conversion failed
  213. break;
  214. }
  215. } elseif ($mvType == 'v' ) {
  216. $videoId = $mvId;
  217. }
  218. X_Debug::i("Megavideo ID: $videoId");
  219. if ( $megavideoHelper->setLocation($videoId)->getServer() ) {
  220. $return = $megavideoHelper->getUrl();
  221. }
  222. } catch (Exception $e) {
  223. X_Debug::e("Megavideo helper isn't installed or enabled: {$e->getMessage()}");
  224. }
  225. break;
  226. case self::TYPE_YOUTUBE:
  227. try {
  228. /* @var $youtubeHelper X_VlcShares_Plugins_Helper_Youtube */
  229. $youtubeHelper = $this->helpers('youtube');
  230. /* @var $youtubePlugin X_VlcShares_Plugins_Youtube */
  231. $youtubePlugin = X_VlcShares_Plugins::broker()->getPlugins('youtube');
  232. X_Debug::i("Youtube ID: $videoId");
  233. // THIS CODE HAVE TO BE MOVED IN YOUTUBE HELPER
  234. // FIXME
  235. $formats = $youtubeHelper->getFormatsNOAPI($videoId/*->getVideoId()*/);
  236. $returned = null;
  237. $qualityPriority = explode('|', $youtubePlugin->config('quality.priority', '5|34|18|35'));
  238. foreach ($qualityPriority as $quality) {
  239. if ( array_key_exists($quality, $formats)) {
  240. $returned = $formats[$quality];
  241. X_Debug::i('Video format selected: '.$quality);
  242. break;
  243. }
  244. }
  245. if ( $returned === null ) {
  246. // for valid video id but video with restrictions
  247. // alternatives formats can't be fetched by youtube page.
  248. // i have to fallback to standard api url
  249. $apiVideo = $youtubeHelper->getVideo($videoId);
  250. foreach ($apiVideo->mediaGroup->content as $content) {
  251. if ($content->type === "video/3gpp") {
  252. $returned = $content->url;
  253. X_Debug::w('Content restricted video, fallback to api url:'.$returned);
  254. break;
  255. }
  256. }
  257. if ( $returned === null ) {
  258. $returned = false;
  259. }
  260. }
  261. $return = $returned;
  262. } catch (Exception $e) {
  263. X_Debug::e("Youtube helper isn't installed or enabled: {$e->getMessage()}");
  264. }
  265. break;
  266. default:
  267. X_Debug::i("Using new hoster api");
  268. try {
  269. $hoster = $this->helpers()->hoster()->getHoster($videoType);
  270. $return = $hoster->getPlayable($videoId);
  271. } catch (Exception $e) {
  272. X_Debug::e("Hoster api hasn't a valid handler for {{$videoType}:{$videoId}}: {$e->getMessage()}");
  273. $return = false;
  274. }
  275. }
  276. $this->cachedLocation[$location] = $return;
  277. return $return;
  278. }
  279. /**
  280. * Support for parent location
  281. * @see X_VlcShares_Plugins_ResolverInterface::getParentLocation
  282. * @param $location
  283. */
  284. function getParentLocation($location = null) {
  285. if ( $location == '' || $location == null ) return false;
  286. //X_Debug::i($location);
  287. $exploded = explode('/', $location);
  288. //X_Debug::i(var_export($exploded, true));
  289. // sort/sub/page/thread/video
  290. if ( count($exploded) == 3 ) {
  291. // i have to add an extra pop
  292. // to jump from threads to sub page
  293. array_pop($exploded);
  294. }
  295. array_pop($exploded);
  296. //X_Debug::i(var_export($exploded, true));
  297. if ( count($exploded) >= 1 ) {
  298. return implode('/', $exploded);
  299. } else {
  300. return null;
  301. }
  302. }
  303. /**
  304. * Add the link for -manage-megavideo-
  305. * @param Zend_Controller_Action $this
  306. * @return X_Page_ItemList_ManageLink
  307. */
  308. public function getIndexManageLinks(Zend_Controller_Action $controller) {
  309. $link = new X_Page_Item_ManageLink($this->getId(), X_Env::_('p_gogocinema_mlink'));
  310. $link->setTitle(X_Env::_('p_gogocinema_managetitle'))
  311. ->setIcon('/images/gogocinema/logo.png')
  312. ->setLink(array(
  313. 'controller' => 'config',
  314. 'action' => 'index',
  315. 'key' => 'gogocinema'
  316. ), 'default', true);
  317. return new X_Page_ItemList_ManageLink(array($link));
  318. }
  319. private function _fetchClassification(X_Page_ItemList_PItem $items, $sortType) {
  320. $cType = array();
  321. switch ( $sortType ) {
  322. case self::SORT_TYPE:
  323. $url = $this->config('index.url', 'http://www.gogocinema.com/index.php');
  324. $pattern = '/<a href=\"disp_genre\.php\?genre\=([^\"]+)\"\>/';
  325. break;
  326. case self::SORT_YEAR:
  327. $url = $this->config('index.url', 'http://www.gogocinema.com/index.php');
  328. $pattern = '/<a style\=\"color\:\#993300\;\" href=\"disp_year\.php\?year\=([^\"]+)\"\>/';
  329. break;
  330. case self::SORT_ALPHA:
  331. $url = null;
  332. $lets = strtoupper('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');
  333. $cType = explode(',', $lets);
  334. break;
  335. }
  336. if ( $url !== null ) {
  337. // fetch items
  338. $page = $this->_loadPage($url);
  339. if ( preg_match_all($pattern, $page, $cType) !== false ) {
  340. $cType = @$cType[1];
  341. X_Debug::i("Classification items for $sortType found: ".var_export($cType, true));
  342. } else {
  343. X_Debug::e("Regex failed for pattern {{$pattern}}");
  344. }
  345. }
  346. foreach ( $cType as $type ) {
  347. $item = new X_Page_Item_PItem($this->getId()."-$sortType-$type", $type);
  348. $item->setIcon('/images/icons/folder_32.png')
  349. ->setType(X_Page_Item_PItem::TYPE_CONTAINER)
  350. ->setCustom(__CLASS__.':location', "$sortType/$type")
  351. ->setDescription(APPLICATION_ENV == 'development' ? "$sortType/$type" : null)
  352. ->setLink(array(
  353. 'l' => X_Env::encode("$sortType/$type")
  354. ), 'default', false);
  355. $items->append($item);
  356. }
  357. }
  358. private function _fetchSortType(X_Page_ItemList_PItem $items) {
  359. $sorts = array(
  360. self::SORT_ALPHA => X_Env::_('p_gogocinema_sort_alpha'),
  361. self::SORT_TYPE => X_Env::_('p_gogocinema_sort_type'),
  362. self::SORT_YEAR => X_Env::_('p_gogocinema_sort_year'),
  363. );
  364. foreach ( $sorts as $sortL => $sortLabel ) {
  365. $item = new X_Page_Item_PItem($this->getId()."-sort-$sortL", $sortLabel);
  366. $item->setIcon('/images/icons/folder_32.png')
  367. ->setType(X_Page_Item_PItem::TYPE_CONTAINER)
  368. ->setCustom(__CLASS__.':location', "$sortL")
  369. ->setDescription(APPLICATION_ENV == 'development' ? "$sortL" : null)
  370. ->setLink(array(
  371. 'l' => X_Env::encode("$sortL")
  372. ), 'default', false);
  373. $items->append($item);
  374. }
  375. if ( $this->helpers()->devices()->isWiimc() ) {
  376. $item = new X_Page_Item_PItem($this->getId()."-sort-".self::SORT_SEARCH, X_Env::_('p_gogocinema_sort_search'));
  377. $item->setIcon('/images/gogocinema/search.png')
  378. ->setType(X_Page_Item_PItem::TYPE_REQUEST)
  379. ->setCustom(__CLASS__.':location', self::SORT_SEARCH)
  380. ->setDescription(APPLICATION_ENV == 'development' ? self::SORT_SEARCH : null)
  381. ->setLink(array(
  382. 'l' => X_Env::encode(self::SORT_SEARCH),
  383. // search key have to be the last one or wiimc will append the string to something to unknown
  384. "{$this->getId()}:search" => ''
  385. ), 'default', false);
  386. $items->append($item);
  387. }
  388. }
  389. private function _fetchThreads(X_Page_ItemList_PItem $items, $sortType, $subType, $page = 1) {
  390. X_Debug::i("Fetching threads for $sortType/$subType/$page");
  391. switch ( $sortType ) {
  392. case self::SORT_ALPHA:
  393. // subType = letter
  394. $url = $this->config('index.alpha.url', "http://www.gogocinema.com/disp_abcd.php?letter=" ).$subType;
  395. break;
  396. case self::SORT_YEAR:
  397. // subType = year
  398. $url = $this->config('index.year.url', "http://www.gogocinema.com/disp_year.php?year=" ).$subType;
  399. break;
  400. case self::SORT_TYPE:
  401. // subType = year
  402. $url = $this->config('index.type.url', "http://www.gogocinema.com/disp_genre.php?genre=" ).$subType;
  403. break;
  404. case self::SORT_SEARCH:
  405. // subType = year
  406. $url = $this->config('index.search.url', "http://www.gogocinema.com/disp_search.php?search=" ).urlencode($subType);
  407. break;
  408. }
  409. if ( $page > 1 ) {
  410. // adding page param
  411. $url .= "&page=$page";
  412. }
  413. $htmlString = $this->_loadPage($url);
  414. $pattern = '/<a href\=\"movie\.php\?movie_id\=([^\"]+)\" style\=\"color\:\#E95C24\;\"><img src\=\"([^\"]+)\" width\=\"68\" height\=\"100\" alt\=\"Watch ([^\"]+) Online\"/';
  415. $patternNext = '/<span class\=\"disabled\"\>Next\<\/span\>/';
  416. $patternPrevious = '/<span class\=\"disabled\"\>Previous\<\/span\>/';
  417. $patternPagination = '/<div class\=\"pagination\"\>/';
  418. $matches = array();
  419. if ( preg_match_all($pattern, $htmlString, $matches, PREG_SET_ORDER) ) {
  420. X_Debug::i("Threads found: ".count($matches));
  421. $paginationEnabled = (preg_match($patternPagination, $htmlString) ? true : false);
  422. if ( $paginationEnabled && !preg_match($patternPrevious, $htmlString, $submatch) ) {
  423. //X_Debug::i("Previous page allowed: ".var_export($submatch, true));
  424. $ppage = $page > 2 ? "/".($page - 1) : '';
  425. $item = new X_Page_Item_PItem($this->getId()."-previouspage", X_Env::_('p_gogocinema_previouspage', ($page - 1)) );
  426. $item//->setIcon('/images/icons/folder_32.png')
  427. //->setThumbnail($thumbnail)
  428. ->setType(X_Page_Item_PItem::TYPE_CONTAINER)
  429. ->setCustom(__CLASS__.':location', "$sortType/$subType$ppage")
  430. ->setLink(array(
  431. // if needed / is already in $ppage
  432. 'l' => X_Env::encode("$sortType/$subType$ppage")
  433. ), 'default', false);
  434. if ( APPLICATION_ENV == 'development' ) {
  435. $item->setDescription("$sortType/$subType$ppage");
  436. }
  437. $items->append($item);
  438. }
  439. foreach ($matches as $thread) {
  440. @list(, $threadId, $thumbnail, $label) = $thread;
  441. $item = new X_Page_Item_PItem($this->getId()."-$sortType-$subType-$threadId", $label);
  442. $item->setIcon('/images/icons/folder_32.png')
  443. ->setThumbnail($thumbnail)
  444. ->setType(X_Page_Item_PItem::TYPE_CONTAINER)
  445. ->setCustom(__CLASS__.':location', "$sortType/$subType/$page/$threadId")
  446. ->setLink(array(
  447. 'l' => X_Env::encode("$sortType/$subType/$page/$threadId")
  448. ), 'default', false);
  449. if ( APPLICATION_ENV == 'development' ) {
  450. $item->setDescription("$sortType/$subType/$page/$threadId");
  451. }
  452. $items->append($item);
  453. }
  454. if ( $paginationEnabled && !preg_match($patternNext, $htmlString, $submatch) ) {
  455. //X_Debug::i("Next page allowed: ".var_export($submatch, true));
  456. $item = new X_Page_Item_PItem($this->getId()."-nextpage", X_Env::_('p_gogocinema_nextpage', ($page + 1)) );
  457. $item//->setIcon('/images/icons/folder_32.png')
  458. //->setThumbnail($thumbnail)
  459. ->setType(X_Page_Item_PItem::TYPE_CONTAINER)
  460. ->setCustom(__CLASS__.':location', "$sortType/$subType/".($page + 1))
  461. ->setLink(array(
  462. 'l' => X_Env::encode("$sortType/$subType/".($page + 1))
  463. ), 'default', false);
  464. if ( APPLICATION_ENV == 'development' ) {
  465. $item->setDescription("$sortType/$subType/".($page + 1));
  466. }
  467. $items->append($item);
  468. }
  469. } else {
  470. X_Debug::e("Regex failed {{$pattern}}");
  471. }
  472. }
  473. private function _fetchVideos(X_Page_ItemList_PItem $items, $sortType, $subType, $page, $thread) {
  474. X_Debug::i("Fetching videos for $sortType/$subType/$page/$thread");
  475. $url = $this->config('index.video.url', 'http://www.gogocinema.com/movie.php?movie_id=').$thread;
  476. $htmlString = $this->_loadPage($url);
  477. $htmlString = str_replace(array("\n", "\r", "\t", chr(0xC2), chr(0xA0), chr(157)), '', $htmlString);
  478. //X_Debug::i($htmlString);
  479. //$megavideoPattern = '/href\=\"http:\/\/megavideo\.com\/\?([^\"]+)\" /';
  480. //$megavideoPattern = '/<tr bgcolor\=\"#043F6E\"><td>\# ([^\"]+)\<\/td><\/tr><tr><td align\=\"center\"><a style\=\"color\:\#FFFFFF\;\" href\=\"http:\/\/megavideo\.com\/\?([^\"]+)\" target\=\"\_blank\">/';
  481. //$youtubePattern = '/<tr bgcolor\=\"#043F6E\"><td>\# ([^\"]+)\<\/td><\/tr><tr><td align\=\"center\"><a style\=\"color\:\#FFFFFF\;\" href\=\"http\:\/\/youtube\.com\/watch\?v\=([^\"]+)\" target\=\"\_blank\">/';
  482. $globalPattern = '/<tr bgcolor\=\"#043F6E\"><td>\# (?P<label>[^\"]+)\<\/td><\/tr><tr><td align\=\"center\"><a style\=\"color\:\#FFFFFF\;\" href\=\"(?P<link>[^\"]+)\" target\=\"\_blank\">/';
  483. $movietitlePattern = '/<td class\=\"movietitle\" colspan \= \"3\"><a href\=\"movie\.php\?movie_id=([^\"]+)\" style=\"color\:\#E95C24\;\">([^\"]+)<\/a>/';
  484. $matches = array();
  485. if ( preg_match($movietitlePattern, $htmlString, $matches) ) {
  486. $movieTitle = "{$matches[2]}: ";
  487. } else {
  488. $movieTitle = '';
  489. }
  490. $matches = array();
  491. if ( preg_match_all($globalPattern, $htmlString, $matches, PREG_SET_ORDER ) ) {
  492. X_Debug::i("Megavideo videos found: ".count($matches));
  493. X_Debug::i(var_export($matches, true));
  494. foreach ($matches as $video) {
  495. //@list(,$label, $videoId) = $video;
  496. $label = $video['label'];
  497. $link = $video['link'];
  498. try {
  499. $hoster = $this->helpers()->hoster()->findHoster($link);
  500. $label = strip_tags($label). " [".ucfirst($hoster->getId())."]";
  501. //$videoId = self::TYPE_MEGAVIDEO.":$videoId";
  502. $videoId = "{$hoster->getId()}:{$hoster->getResourceId($link)}";
  503. $item = new X_Page_Item_PItem($this->getId()."-{$hoster->getId()}", "$movieTitle$label");
  504. $item->setIcon('/images/icons/file_32.png')
  505. ->setType(X_Page_Item_PItem::TYPE_ELEMENT)
  506. ->setCustom(__CLASS__.':location', "$sortType/$subType/$page/$thread/$videoId")
  507. ->setLink(array(
  508. 'action' => 'mode',
  509. 'l' => X_Env::encode("$sortType/$subType/$page/$thread/$videoId")
  510. ), 'default', false);
  511. if ( APPLICATION_ENV == 'development' ) {
  512. $item->setDescription("$sortType/$subType/$page/$thread/$videoId");
  513. }
  514. $items->append($item);
  515. } catch (Exception $e) {
  516. // no valid hoster for this link
  517. }
  518. }
  519. } else {
  520. X_Debug::i("Megavideo videos NOT found: ".var_export($matches, true));
  521. X_Debug::i("No megavideo links found");
  522. }
  523. /*
  524. $matches = array();
  525. if ( preg_match_all($youtubePattern, $htmlString, $matches, PREG_SET_ORDER) ) {
  526. X_Debug::i("Youtube videos found: ".count($matches));
  527. foreach ($matches as $video) {
  528. @list(,$label,$videoId) = $video;
  529. $label = strip_tags($label);
  530. $videoId = self::TYPE_YOUTUBE.":$videoId";
  531. $item = new X_Page_Item_PItem($this->getId()."-youtube", "$movieTitle$label");
  532. $item->setIcon('/images/icons/file_32.png')
  533. ->setType(X_Page_Item_PItem::TYPE_ELEMENT)
  534. ->setCustom(__CLASS__.':location', "$sortType/$subType/$page/$thread/$videoId")
  535. ->setLink(array(
  536. 'action' => 'mode',
  537. 'l' => X_Env::encode("$sortType/$subType/$page/$thread/$videoId")
  538. ), 'default', false);
  539. if ( APPLICATION_ENV == 'development' ) {
  540. $item->setDescription("$sortType/$subType/$page/$thread/$videoId");
  541. }
  542. $items->append($item);
  543. }
  544. }
  545. */
  546. }
  547. private function _loadPage($uri) {
  548. X_Debug::i("Loading page $uri");
  549. $http = new Zend_Http_Client($uri, array(
  550. 'maxredirects' => $this->config('request.maxredirects', 10),
  551. 'timeout' => $this->config('request.timeout', 25)
  552. //'keepalive' => true
  553. ));
  554. $http->setHeaders(array(
  555. $this->config('hide.useragent', false) ? 'User-Agent: vlc-shares/'.X_VlcShares::VERSION .' gogocinema/'.self::VERSION_CLEAN : 'User-Agent: Mozilla/5.0 (X11; Linux i686; rv:2.0.1) Gecko/20101019 Firefox/4.0.1',
  556. //'Content-Type: application/x-www-form-urlencoded'
  557. ));
  558. $response = $http->request();
  559. $htmlString = $response->getBody();
  560. return $htmlString;
  561. }
  562. private function disableCache() {
  563. if ( X_VlcShares_Plugins::broker()->isRegistered('cache') ) {
  564. $cache = X_VlcShares_Plugins::broker()->getPlugins('cache');
  565. if ( method_exists($cache, 'setDoNotCache') ) {
  566. $cache->setDoNotCache();
  567. }
  568. }
  569. }
  570. }