public function init()
 {
     parent::init();
     if (!X_VlcShares_Plugins::broker()->isRegistered('veoh')) {
         throw new Exception(X_Env::_('err_pluginnotregistered') . ": veoh");
     }
 }
 /**
  * Get category/video list
  * @param unknown_type $provider
  * @param unknown_type $location
  * @param Zend_Controller_Action $controller
  */
 public function getShareItems($provider, $location, Zend_Controller_Action $controller)
 {
     if ($provider != $this->getId()) {
         return;
     }
     X_Debug::i('Plugin triggered');
     X_VlcShares_Plugins::broker()->unregisterPluginClass('X_VlcShares_Plugins_SortItems');
     $baseUrl = $this->config('base.url', 'http://www.opfitalia.net/mediacenter/index.php?page=ajax_show_folder&id=');
     $items = new X_Page_ItemList_PItem();
     try {
         if ($location != '') {
             @(list($path, $type, $link) = explode('/', $location));
             $lStack = explode(':', $path);
             $last = count($lStack) > 0 ? $lStack[count($lStack) - 1] : 0;
             $decoded = $this->_loadPage($baseUrl . $last);
             $this->_fillPlaylist($items, $decoded, $lStack);
         } else {
             // show the index
             $indexCategory = $this->config('index.category', 0);
             $decoded = $this->_loadPage($baseUrl . $indexCategory);
             $this->_fillPlaylist($items, $decoded, array());
         }
     } catch (Exception $e) {
         // auth problems
         $item = new X_Page_Item_PItem('opf-autherror', X_Env::_('p_opfitalia_br_error') . ": {$e->getMessage()}");
         $item->setIcon('/images/msg_error.png')->setType(X_Page_Item_PItem::TYPE_ELEMENT)->setDescription($e->getMessage())->setLink(array('controller' => 'index', 'action' => 'collections'), 'default', true);
         $items->append($item);
     }
     return $items;
 }
 public function startEngine(X_Threads_Thread $thread)
 {
     // assume all parameters are ready
     $thread->log("Spawning RTMPDump (rtmpdump-weebtv | vlc)...");
     $source = $this->getParam('source');
     // set the path
     if (X_Env::isWindows()) {
         X_RtmpDumpWeebTv::getInstance()->setPath(APPLICATION_PATH . '/../bin/rtmpdump-weebtv-win/rtmpdump-weebtv.exe');
     } else {
         X_RtmpDumpWeebTv::getInstance()->setPath(APPLICATION_PATH . '/../bin/rtmpdump-weebtv-linux/rtmpdump-weebtv');
     }
     $weebPlugin = X_VlcShares_Plugins::broker()->getPlugins('weebtv');
     if ($weebPlugin instanceof X_VlcShares_Plugins_WeebTv && X_VlcShares_Plugins::helpers()->streamer()->isRegistered('vlc')) {
         // try to get reference to vlc-streamer
         /* @var $vlcStreamer X_Streamer_Engine_Vlc */
         $vlcStreamer = X_VlcShares_Plugins::helpers()->streamer()->get('vlc');
         // get the channel id
         $source = substr($source, strlen('rtmpdump-weebtv://'));
         // make the plugin to parse params from server and build a rtmpdump-weebtv uri
         $source = $weebPlugin->getLinkParams($source);
         // always live
         $command = (string) X_RtmpDumpWeebTv::getInstance()->parseUri($source);
         $vlcStreamer->getVlcWrapper()->setPipe($command);
         $vlcStreamer->setSource('-');
         $vlcStreamer->setParam('profile', "#std{access=http{mime=video/x-flv},mux=ffmpeg{mux=flv},dst=0.0.0.0:{$weebPlugin->getStreamingPort()}/stream}");
         // redirect std error to null
         // and force quite
         //X_Env::execute("$command -q 2> /dev/null", X_Env::EXECUTE_OUT_NONE, X_Env::EXECUTE_PS_WAIT);
         //X_Env::execute($command, X_Env::EXECUTE_OUT_NONE, X_Env::EXECUTE_PS_WAIT);
         $vlcStreamer->getVlcWrapper()->spawn();
         $thread->log("RTMPDump execution finished");
     } else {
         $thread->log("RTMPDump-weebtv cannot be started without weebtv plugin and vlc streamer");
     }
 }
 /**
  * Get category/video list
  * @param unknown_type $provider
  * @param unknown_type $location
  * @param Zend_Controller_Action $controller
  */
 public function getShareItems($provider, $location, Zend_Controller_Action $controller)
 {
     if ($provider != $this->getId()) {
         return;
     }
     X_Debug::i('Plugin triggered');
     X_VlcShares_Plugins::broker()->unregisterPluginClass('X_VlcShares_Plugins_SortItems');
     //$baseUrl = $this->config('base.url', 'http://www.jigoku.net/mediacenter/index.php?page=ajax_show_folder&id=');
     $items = new X_Page_ItemList_PItem();
     X_Debug::i("Requested location: {$location}");
     $split = $location != '' ? @explode('/', $location, 4) : array();
     @(list($letter, $thread, $video) = $split);
     X_Debug::i("Exploded location: " . var_export($split, true));
     switch (count($split)) {
         // i should not be here, so i fallback to video case
         case 3:
             // show the list of video in the page
         // show the list of video in the page
         case 2:
             $this->_fetchVideos($items, $letter, $thread);
             break;
             // fetch the list of anime in group
         // fetch the list of anime in group
         case 1:
             $this->_fetchThreads($items, $letter);
             break;
             // fetch the list of groups
         // fetch the list of groups
         default:
             $this->_fetchClassification($items);
     }
     return $items;
 }
 /**
  * Get device features
  * 
  * @return Application_Model_Device
  */
 public function getDevice()
 {
     if ($this->device == null) {
         $this->device = false;
         $devices = Application_Model_DevicesMapper::i()->fetchAll();
         /* @var Application_Model_Device $device */
         foreach ($devices as $device) {
             // if exact do an == comparison
             if ($device->isExact() && $device->getPattern() == $_SERVER['HTTP_USER_AGENT'] || !$device->isExact() && preg_match($device->getPattern(), $_SERVER['HTTP_USER_AGENT']) > 0) {
                 // valid $device found;
                 $this->device = $device;
                 break;
             }
         }
         if ($this->device == false) {
             // load things from default
             $this->device = new Application_Model_Device();
             if (X_VlcShares_Plugins::broker()->isRegistered('wiimc')) {
                 $this->device->setGuiClass($this->options->get('gui', 'X_VlcShares_Plugins_WiimcPlxRenderer'));
             } else {
                 $this->device->setGuiClass($this->options->get('gui', 'X_VlcShares_Plugins_WebkitRenderer'));
             }
             $this->device->setIdProfile($this->options->get('profile', 1))->setLabel("Unknown device");
         }
     }
     return $this->device;
 }
 function proxyAction()
 {
     // time to get params from get
     /* @var $request Zend_Controller_Request_Http */
     $request = $this->getRequest();
     if (!$this->plugin->config('proxy.enabled', true) && !X_VlcShares_Plugins::helpers()->devices()->isWiimc()) {
         throw new Exception(X_Env::_('p_animeftw_err_proxydisabled'));
     }
     // this action is so special.... no layout or viewRenderer
     $this->_helper->viewRenderer->setNoRender();
     $this->_helper->layout->disableLayout();
     $videoUrl = $request->getParam('v', false);
     // video file url
     $refererUrl = $request->getParam('r', false);
     // referer page needed
     if ($videoUrl === false || $refererUrl === false) {
         // invalid request
         throw new Exception(X_Env::_('p_animeftw_err_invalidrequest'));
         return;
     }
     $videoUrl = X_Env::decode($videoUrl);
     $refererUrl = X_Env::decode($refererUrl);
     // if user abort request (vlc/wii stop playing, this process ends
     ignore_user_abort(false);
     // close and clean the output buffer, everything will be read and send to device
     ob_end_clean();
     //$userAgent = $this->plugin->config('hide.useragent', true) ? 'User-Agent: vlc-shares/'.X_VlcShares::VERSION : 'User-Agent: Mozilla/5.0 (X11; Linux i686; rv:2.0.1) Gecko/20101019 Firefox/4.0.1';
     $userAgent = 'User-Agent: vlc-shares/' . X_VlcShares::VERSION . ' animeftw/' . X_VlcShares_Plugins_AnimeFTW::VERSION;
     $opts = array('http' => array('header' => array("Referer: {$refererUrl}", "User-Agent: {$userAgent}")));
     $context = stream_context_create($opts);
     // readfile open a file and send it directly to output buffer
     readfile($videoUrl, false, $context);
 }
 /**
  * Return a list of page items for the current $location
  * if the $provider is this
  */
 public function getShareItems($provider, $location, Zend_Controller_Action $controller)
 {
     // this plugin add items only if it is the provider
     if ($provider != $this->getId()) {
         return;
     }
     X_Debug::i("Plugin triggered");
     // disabling cache plugin
     try {
         $cachePlugin = X_VlcShares_Plugins::broker()->getPlugins('cache');
         if (method_exists($cachePlugin, 'setDoNotCache')) {
             $cachePlugin->setDoNotCache();
         }
     } catch (Exception $e) {
         // cache plugin not registered, no problem
     }
     $urlHelper = $controller->getHelper('url');
     $items = new X_Page_ItemList_PItem();
     if ($location != '') {
         list($shareId, $path) = explode(':', $location, 2);
         $share = new Application_Model_FilesystemShare();
         Application_Model_FilesystemSharesMapper::i()->find($shareId, $share);
         // TODO prevent ../
         $browsePath = realpath($share->getPath() . $path);
         if (file_exists($browsePath)) {
             $dir = new DirectoryIterator($browsePath);
             foreach ($dir as $entry) {
                 if ($entry->isDot()) {
                     continue;
                 }
                 if ($entry->isDir()) {
                     $item = new X_Page_Item_PItem($this->getId() . '-' . $entry->getFilename() . '/', "{$entry->getFilename()}/");
                     $item->setIcon('/images/icons/folder_32.png')->setType(X_Page_Item_PItem::TYPE_CONTAINER)->setCustom(__CLASS__ . ':location', "{$share->getId()}:{$path}{$entry->getFilename()}/")->setLink(array('l' => X_Env::encode("{$share->getId()}:{$path}{$entry->getFilename()}/")), 'default', false);
                     $items->append($item);
                 } else {
                     if ($entry->isFile()) {
                         $item = new X_Page_Item_PItem($this->getId() . '-' . $entry->getFilename(), "{$entry->getFilename()}");
                         $item->setIcon('/images/icons/file_32.png')->setType(X_Page_Item_PItem::TYPE_ELEMENT)->setCustom(__CLASS__ . ':location', "{$share->getId()}:{$path}{$entry->getFilename()}")->setLink(array('action' => 'mode', 'l' => X_Env::encode("{$share->getId()}:{$path}{$entry->getFilename()}")), 'default', false);
                         $items->append($item);
                     } else {
                         // scarta i symlink
                         continue;
                     }
                 }
             }
         }
     } else {
         // if location is not specified,
         // show collections
         $shares = Application_Model_FilesystemSharesMapper::i()->fetchAll();
         foreach ($shares as $share) {
             /* @var $share Application_Model_FilesystemShare */
             $item = new X_Page_Item_PItem($this->getId() . '-' . $share->getLabel(), $share->getLabel());
             $item->setIcon('/images/icons/folder_32.png')->setDescription(APPLICATION_ENV == 'development' ? $share->getPath() : null)->setType(X_Page_Item_PItem::TYPE_CONTAINER)->setCustom(__CLASS__ . ':location', "{$share->getId()}:/")->setLink(array('l' => X_Env::encode("{$share->getId()}:/")), 'default', false);
             $items->append($item);
         }
     }
     return $items;
 }
 public function getSelectionItems($provider, $location, $pid, Zend_Controller_Action $controller)
 {
     // we want to expose items only if pid is this plugin
     if ($this->getId() != $pid) {
         return;
     }
     // check for resolvable $location
     // this plugin is useless if i haven't an access
     // to the real location (url for stream or path for file)
     $provider = X_VlcShares_Plugins::broker()->getPlugins($provider);
     if (!$provider instanceof X_VlcShares_Plugins_ResolverInterface) {
         return;
     }
     $providerClass = get_class($provider);
     X_Debug::i('Plugin triggered');
     $urlHelper = $controller->getHelper('url');
     // i try to mark current selected sub based on $this->getId() param
     // in $currentSub i get the name of the current profile
     $currentSub = $controller->getRequest()->getParam($this->getId(), false);
     if ($currentSub !== false) {
         $currentSub = X_Env::decode($currentSub);
     }
     $return = new X_Page_ItemList_PItem();
     $item = new X_Page_Item_PItem($this->getId() . '-none', X_Env::_('p_audioswitcher_selection_none'));
     $item->setType(X_Page_Item_PItem::TYPE_ELEMENT)->setLink(array('action' => 'mode', $this->getId() => null, 'pid' => null), 'default', false)->setHighlight($currentSub === false);
     $return->append($item);
     // i do the check for this on top
     // location param come in a plugin encoded way
     $location = $provider->resolveLocation($location);
     // check if infile support is enabled
     // by default infile.enabled is true
     if ($this->config('infile.enabled', true)) {
         // check for infile tracks
         $infileTracks = $this->helpers()->stream()->setLocation($location)->getAudiosInfo();
         //X_Debug::i(var_export($infileSubs, true));
         foreach ($infileTracks as $streamId => $track) {
             X_Debug::i("Valid infile-sub: [{$streamId}] {$track['language']} ({$track['format']})");
             $item = new X_Page_Item_PItem($this->getId() . '-stream-' . $streamId, X_Env::_("p_audioswitcher_subtype_" . self::STREAM) . " {$streamId} {$track['language']} {$track['format']}");
             $item->setType(X_Page_Item_PItem::TYPE_ELEMENT)->setCustom(__CLASS__ . ':sub', self::STREAM . ":{$streamId}")->setLink(array('action' => 'mode', 'pid' => null, $this->getId() => X_Env::encode(self::STREAM . ":{$streamId}")), 'default', false)->setHighlight($currentSub == self::STREAM . ":{$streamId}");
             $return->append($item);
         }
     }
     // for file system source i will search for subs in filename notation
     // by default file.enabled is true
     if ($this->config('file.enabled', true) && is_a($provider, 'X_VlcShares_Plugins_FileSystem')) {
         $dirname = pathinfo($location, PATHINFO_DIRNAME);
         $filename = pathinfo($location, PATHINFO_FILENAME);
         $extTracks = $this->getFSTracks($dirname, $filename);
         foreach ($extTracks as $streamId => $track) {
             X_Debug::i("Valid extfile-sub: {$track['language']} ({$track['format']})");
             $item = new X_Page_Item_PItem($this->getId() . '-file-' . $streamId, X_Env::_("p_audioswitcher_subtype_" . self::FILE) . " {$track['language']} ({$track['format']})");
             $item->setType(X_Page_Item_PItem::TYPE_ELEMENT)->setCustom(__CLASS__ . ':sub', self::FILE . ":{$streamId}")->setLink(array('action' => 'mode', 'pid' => null, $this->getId() => X_Env::encode(self::FILE . ":{$streamId}")), 'default', false)->setHighlight($currentSub == self::FILE . ":{$streamId}");
             $return->append($item);
         }
     }
     // general profiles are in the bottom of array
     return $return;
 }
 public function preDispatch()
 {
     X_Debug::i("Required action: [" . $this->getRequest()->getControllerName() . '/' . $this->getRequest()->getActionName() . ']');
     parent::preDispatch();
     // call plugins trigger
     // TODO check if plugin broker should be called before parent::preDispatch
     X_VlcShares_Plugins::broker()->gen_beforePageBuild($this);
     //$this->_helper->url->url()
 }
 public function init()
 {
     parent::init();
     if (!X_VlcShares_Plugins::broker()->isRegistered('upnprenderer')) {
         throw new Exception(X_Env::_('err_pluginnotregistered') . ": upnprenderer");
     } else {
         $this->plugin = X_VlcShares_Plugins::broker()->getPlugins('upnprenderer');
     }
 }
 function preDispatch()
 {
     // uses the device helper for wiimc recognition
     if (X_VlcShares_Plugins::helpers()->devices()->isWiimc()) {
         // wiimc 1.0.9 e inferiori nn accetta redirect
         //$this->_forward('collections', 'index');
         $this->getRequest()->setControllerName('index')->setActionName('collections')->setDispatched(false);
     } else {
         $this->_helper->redirector('index', 'index');
     }
 }
 public function init()
 {
     parent::init();
     if (!X_VlcShares_Plugins::broker()->isRegistered('bookmarks')) {
         throw new Exception(X_Env::_('err_pluginnotregistered') . ": bookmarks");
     } else {
         $this->pluginLibrary = X_VlcShares_Plugins::broker()->getPlugins('bookmarks');
     }
     if (X_VlcShares_Plugins::broker()->isRegistered('bookmarklets')) {
         $this->pluginBookmarklets = X_VlcShares_Plugins::broker()->getPlugins('bookmarklets');
     }
 }
 function init()
 {
     // call parent init, always
     parent::init();
     if (!X_VlcShares_Plugins::broker()->isRegistered('spainradio')) {
         /*
         $this->_helper->flashMessenger(X_Env::_('err_pluginnotregistered') . ": youtube");
         $this->_helper->redirector('index', 'manage');
         */
         throw new Exception(X_Env::_('err_pluginnotregistered') . ": spainradio");
     } else {
         $this->plugin = X_VlcShares_Plugins::broker()->getPlugins('spainradio');
     }
 }
Example #14
0
 /**
  * Get category/video list
  * @param unknown_type $provider
  * @param unknown_type $location
  * @param Zend_Controller_Action $controller
  */
 public function getShareItems($provider, $location, Zend_Controller_Action $controller)
 {
     // this plugin add items only if it is the provider
     if ($provider != $this->getId()) {
         return;
     }
     X_Debug::i("Plugin triggered");
     // try to disable SortItems plugin, so link are listed as in html page
     X_VlcShares_Plugins::broker()->unregisterPluginClass('X_VlcShares_Plugins_SortItems');
     $urlHelper = $controller->getHelper('url');
     $items = new X_Page_ItemList_PItem();
     if ($location != '' && array_key_exists((int) $location, $this->seasons)) {
         // episodes list
         $url = $this->seasons[(int) $location];
         $html = $this->_loadPage($url);
         $dom = new Zend_Dom_Query($html);
         $results = $dom->queryXpath('//div[@id="randomVideos"]//div[@class="randomTab"]//a[@class="previewDescriptionTitle"]');
         $resultsImages = $dom->queryXpath('//div[@id="randomVideos"]//div[@class="randomTab"]//img[1]/attribute::src');
         for ($i = 0; $i < $results->count(); $i++, $results->next()) {
             $node = $results->current();
             $href = $node->getAttribute('href');
             $label = $node->nodeValue;
             $id = explode('id=', $href, 2);
             $id = @$id[1];
             $thumb = null;
             try {
                 if ($resultsImages->valid()) {
                     $thumb = $resultsImages->current()->nodeValue;
                     $resultsImages->next();
                 }
             } catch (Exception $e) {
                 $thumb = null;
             }
             $item = new X_Page_Item_PItem($this->getId() . '-' . $label, $label);
             $item->setIcon('/images/icons/file_32.png')->setType(X_Page_Item_PItem::TYPE_ELEMENT)->setCustom(__CLASS__ . ':location', $id)->setLink(array('action' => 'mode', 'l' => X_Env::encode($id)), 'default', false);
             if ($thumb !== null) {
                 $item->setThumbnail($thumb);
             }
             $items->append($item);
         }
     } else {
         foreach ($this->seasons as $key => $seasons) {
             $item = new X_Page_Item_PItem($this->getId() . '-' . $key, X_Env::_('p_allsp_season_n') . ": {$key}");
             $item->setIcon('/images/icons/folder_32.png')->setType(X_Page_Item_PItem::TYPE_CONTAINER)->setCustom(__CLASS__ . ':location', $key)->setLink(array('action' => 'share', 'l' => X_Env::encode($key)), 'default', false);
             $items->append($item);
         }
     }
     return $items;
 }
 /**
  * get an array with standard information about the playable
  * @param string $url the hoster page or resource ID
  * @param boolean $isId
  * @return array format:
  * 		array(
  * 			'title' => TITLE
  * 			'description' => DESCRIPTION
  * 			'length' => LENGTH
  * 			...
  * 		)
  */
 function getPlayableInfos($url, $isId = true)
 {
     if (!$isId) {
         $url = $this->getResourceId($url);
     }
     // $url is an id now for sure
     /* @var $megavideoHelper X_VlcShares_Plugins_Helper_Megavideo */
     $megavideoHelper = X_VlcShares_Plugins::helpers()->helper('megavideo');
     if ($megavideoHelper->setLocation($url)->getServer() == '') {
         throw new Exception("Invalid video", self::E_ID_INVALID);
     }
     // use cached values
     $infos = array('title' => $megavideoHelper->getTitle(), 'description' => $megavideoHelper->getDescription(), 'length' => $megavideoHelper->getDuration());
     return $infos;
 }
 public function gen_afterPageBuild(X_Page_ItemList_PItem $items, Zend_Controller_Action $controller)
 {
     /*
     if ( !$this->_forceRendering ) { 
     	// even if forced.enabled, don't build the page if the device is wiimc
     	if ( $this->helpers()->devices()->isWiimc() || ( !((bool) $this->config('forced.enabled', false)) && !$this->helpers()->devices()->isAndroid() )) return;
     }
     */
     if (!$this->isDefaultRenderer()) {
         return;
     }
     X_Debug::i("Plugin triggered");
     $request = $controller->getRequest();
     $urlHelper = $controller->getHelper('url');
     /* @var $view Zend_Controller_Action_Helper_ViewRenderer */
     $view = $controller->getHelper('viewRenderer');
     /* @var $layout Zend_Layout_Controller_Action_Helper_Layout */
     $layout = $controller->getHelper('layout');
     $view->setViewSuffix('mobile.phtml');
     $layout->getLayoutInstance()->setLayout('mobile', true);
     if ($request instanceof Zend_Controller_Request_Http) {
         if ($request->isXmlHttpRequest()) {
             $layout->getLayoutInstance()->disableLayout();
         }
     }
     try {
         $providerObj = X_VlcShares_Plugins::broker()->getPlugins($request->getParam('p', ''));
         $view->view->providerName = strtolower($providerObj->getId());
         if ($providerObj instanceof X_VlcShares_Plugins_ResolverDisplayableInterface) {
             // location in request obj are X_Env::encoded
             $view->view->location = $providerObj->resolveLocation(X_Env::decode($request->getParam('l', '')));
         }
         if ($providerObj instanceof X_VlcShares_Plugins_ResolverInterface) {
             // location in request obj are X_Env::encoded
             $view->view->locationRaw = $providerObj->resolveLocation(X_Env::decode($request->getParam('l', '')));
             $view->view->parentLocation = $providerObj->getParentLocation(X_Env::decode($request->getParam('l', '')));
         }
     } catch (Exception $e) {
         //die('No provider');
         X_Debug::i('No provider O_o');
     }
     // set some vars for view
     $view->view->provider = $request->getParam('p', '');
     $view->view->items = $items;
     $view->view->actionName = $request->getActionName();
     $view->view->controllerName = $request->getControllerName();
     $view->view->coverflowEnabled = $this->config('coverflow.enabled', true);
 }
Example #17
0
 public function run($params = array(), X_Threads_Thread $thread)
 {
     $this->thread = $thread;
     $streamerId = X_Env::isset_or($params['streamerId'], false);
     $streamerClass = X_Env::isset_or($params['streamerClass'], false);
     $params = X_Env::isset_or($params['params'], array());
     if (!$streamerId) {
         $thread->log("Sorry dude, no streamerId submitted. Can't do anything");
         return X_Threads_Thread::RETURN_INVALID_PARAMS;
     }
     /* @var $streamer X_Streamer_Engine_Vlc */
     $streamer = X_VlcShares_Plugins::helpers()->streamer()->get($streamerId);
     $streamer->setParams($params);
     $streamer->startEngine($thread);
     return self::RETURN_NORMAL;
 }
 /**
  * Get category/video list
  * @param unknown_type $provider
  * @param unknown_type $location
  * @param Zend_Controller_Action $controller
  */
 public function getShareItems($provider, $location, Zend_Controller_Action $controller)
 {
     // this plugin add items only if it is the provider
     if ($provider != $this->getId()) {
         return;
     }
     X_Debug::i("Plugin triggered");
     $urlHelper = $controller->getHelper('url');
     $items = new X_Page_ItemList_PItem();
     if ($location != '') {
         // try to disable SortItems plugin, so link are listed as in html page
         X_VlcShares_Plugins::broker()->unregisterPluginClass('X_VlcShares_Plugins_SortItems');
         $pageIndex = rtrim($this->config('base.url', 'http://www.animeland.it/'), '/') . "/{$location}";
         $htmlString = $this->_loadPage($pageIndex);
         $dom = new Zend_Dom_Query($htmlString);
         $results = $dom->queryXpath('//a[@href!="menu_streaming.html"]');
         for ($i = 0; $i < $results->count(); $i++, $results->next()) {
             $node = $results->current();
             $href = $node->getAttribute('href');
             $label = $node->nodeValue;
             $item = new X_Page_Item_PItem($this->getId() . '-' . $label, $label);
             $item->setIcon('/images/icons/file_32.png')->setType(X_Page_Item_PItem::TYPE_ELEMENT)->setCustom(__CLASS__ . ':location', $href)->setLink(array('action' => 'mode', 'l' => X_Env::encode($href)), 'default', false);
             $items->append($item);
         }
     } else {
         $pageIndex = rtrim($this->config('base.url', 'http://www.animeland.it/'), '/') . "/" . $this->config('index.page', 'menu_streaming.html');
         $htmlString = $this->_loadPage($pageIndex);
         $dom = new Zend_Dom_Query($htmlString);
         $results = $dom->queryXpath('//a[@href!="menu_streaming.html"]');
         for ($i = 0; $i < $results->count(); $i++, $results->next()) {
             $node = $results->current();
             $href = $node->getAttribute('href');
             $label = $node->nodeValue;
             $target = $node->getAttribute('target');
             if ($target == '_blank') {
                 $item = new X_Page_Item_PItem($this->getId() . '-' . $label, $label);
                 $item->setIcon('/images/icons/file_32.png')->setType(X_Page_Item_PItem::TYPE_ELEMENT)->setCustom(__CLASS__ . ':location', $href)->setLink(array('action' => 'mode', 'l' => X_Env::encode($href)), 'default', false);
                 $items->append($item);
             } else {
                 $item = new X_Page_Item_PItem($this->getId() . '-' . $label, $label);
                 $item->setIcon('/images/icons/folder_32.png')->setType(X_Page_Item_PItem::TYPE_CONTAINER)->setCustom(__CLASS__ . ':location', $href)->setLink(array('action' => 'share', 'l' => X_Env::encode($href)), 'default', false);
                 $items->append($item);
             }
         }
     }
     return $items;
 }
 /**
  * Sorts items:
  * 		if provider is FileSystem uses a folder/file sort
  * 		else alphabetical one
  * @param array &$items array of X_Page_Item_PItem
  * @param string $provider id of the plugin the handle the request
  * @param Zend_Controller_Action $controller
  */
 public function orderShareItems(&$items, $provider, Zend_Controller_Action $controller)
 {
     X_Debug::i('Plugin triggered');
     try {
         $plugin = X_VlcShares_Plugins::broker()->getPlugins($provider);
         // TODO check for problem if i always use sortFolderBased
         if (true || is_a($plugin, 'X_VlcShares_Plugins_FileSystem')) {
             X_Debug::i('Sort sortFolderBased');
             usort($items, array(__CLASS__, 'sortFolderBased'));
         } else {
             X_Debug::i('Sort generic');
             usort($items, array(__CLASS__, 'sortAlphabetically'));
         }
     } catch (Exception $e) {
         X_Debug::w("Problem while sorting: {$e->getMessage()}");
     }
 }
 /**
  * Get category/video list
  * @param string $provider
  * @param string $location
  * @param Zend_Controller_Action $controller
  * @return X_Page_ItemList_PItem
  */
 public function getShareItems($provider, $location, Zend_Controller_Action $controller)
 {
     // this plugin add items only if it is the provider
     if ($provider != $this->getId()) {
         return;
     }
     X_Debug::i("Plugin triggered");
     // disabling cache plugin
     try {
         $cachePlugin = X_VlcShares_Plugins::broker()->getPlugins('cache');
         if (method_exists($cachePlugin, 'setDoNotCache')) {
             $cachePlugin->setDoNotCache();
         }
     } catch (Exception $e) {
         // cache plugin not registered, no problem
     }
     $urlHelper = $controller->getHelper('url');
     X_VlcShares_Plugins::broker()->unregisterPluginClass('X_VlcShares_Plugins_SortItems');
     $items = new X_Page_ItemList_PItem();
     // location format:
     // $catPage/X_Env::encode($category)/$itemPage/$item
     $locParts = $location != '' ? explode('/', $location, 4) : array();
     @(list($catPage, $category, $itemPage, $item) = $locParts);
     $locCount = count($locParts);
     // category is double encoded so we need an extra decode
     $category = X_Env::decode($category);
     switch ($locCount) {
         case 2:
             $itemPage = 1;
         case 4:
             // we shouldn't be here, $locCount = 4 means that we have a
             // selected video in location. We should be in browse/mode
         // we shouldn't be here, $locCount = 4 means that we have a
         // selected video in location. We should be in browse/mode
         case 3:
             $this->fetchVideos($items, $catPage, $category, $itemPage);
             break;
         default:
         case 0:
             $catPage = 1;
         case 1:
             $this->fetchCategories($items, $catPage);
             break;
     }
     return $items;
 }
 public function gen_beforePageBuild(Zend_Controller_Action $controller)
 {
     X_Debug::i("Tuning options");
     try {
         /* @var $cacheHelper X_VlcShares_Plugins_Helper_Cache  */
         $cacheHelper = $this->helpers()->helper('cache');
         $lastdevices = false;
         try {
             $lastdevices = $cacheHelper->retrieveItem('devices::lastdevices');
         } catch (Exception $e) {
             /* key missing */
         }
         if ($lastdevices) {
             $lastdevices = @unserialize($lastdevices);
         }
         if (!is_array($lastdevices)) {
             $lastdevices = array();
         }
         foreach ($lastdevices as $key => $time) {
             if ($time < time()) {
                 unset($lastdevices[$key]);
             }
         }
         if (!array_key_exists($_SERVER['HTTP_USER_AGENT'], $lastdevices)) {
             $lastdevices[$_SERVER['HTTP_USER_AGENT']] = time() + 15 * 60;
         }
         // clear the cache entry every 60 min if untouched
         $cacheHelper->storeItem('devices::lastdevices', serialize($lastdevices), 60);
     } catch (Exception $e) {
         X_Debug::i("User agent cannot be added to the cache");
     }
     $guiClass = $this->helpers()->devices()->getDefaultDeviceGuiClass();
     X_Debug::i("Device configs: {{label: {$this->helpers()->devices()->getDeviceLabel()}, guiClass: {$guiClass}}");
     foreach (X_VlcShares_Plugins::broker()->getPlugins() as $pluginKey => $pluginObj) {
         if ($pluginObj instanceof X_VlcShares_Plugins_RendererInterface) {
             if ($guiClass == get_class($pluginObj)) {
                 /* @var $pluginObj X_VlcShares_Plugins_RendererInterface */
                 $pluginObj->setDefaultRenderer(true);
             }
         }
     }
     // disable this trigger, prevent double initialization
     $this->setPriority('gen_beforePageBuild', -1);
 }
 function proxyAction()
 {
     // time to get params from get
     /* @var $request Zend_Controller_Request_Http */
     $request = $this->getRequest();
     // this action is so special.... no layout or viewRenderer
     $this->_helper->viewRenderer->setNoRender();
     $this->_helper->layout->disableLayout();
     $videoUrl = $request->getParam('v', false);
     // video file url
     //$refererUrl = $request->getParam('r', false); // referer page needed
     if ($videoUrl === false) {
         // invalid request
         throw new Exception(X_Env::_('p_direttarai_err_invalidrequest'));
     }
     $videoUrl = X_Env::decode($videoUrl);
     //$refererUrl = X_Env::decode($refererUrl);
     if (!defined("X_VlcShares_Plugins_DirettaRai::C_{$videoUrl}")) {
         throw new Exception(X_Env::_('p_direttarai_err_invalidchannel'));
     }
     $videoUrl = constant("X_VlcShares_Plugins_DirettaRai::C_{$videoUrl}");
     //$userAgent = $this->plugin->config('hide.useragent', true) ? 'User-Agent: vlc-shares/'.X_VlcShares::VERSION.' direttarai/'.X_VlcShares_Plugins_DirettaRai::VERSION : 'User-Agent: Mozilla/5.0 (X11; Linux i686; rv:2.0.1) Gecko/20101019 Firefox/4.0.1';
     //$userAgent = 'User-Agent: vlc-shares/'.X_VlcShares::VERSION.' direttarai/'.X_VlcShares_Plugins_DirettaRai::VERSION;
     $opts = array('http' => array('header' => array('viaurl: www.rai.tv')));
     $context = stream_context_create($opts);
     // redirect support in wiimc exists only from 1.1.0
     if (!X_VlcShares_Plugins::helpers()->devices()->isWiimc() && $this->plugin->config('direct.enabled', true)) {
         $match = array();
         $xml = file_get_contents($videoUrl, false, $context);
         if (preg_match('/<REF HREF=\\"([^\\"]*)\\"\\/>/', $xml, $match)) {
             $this->_helper->redirector->gotoUrlAndExit($match[1]);
         } else {
             throw new Exception(X_Env::_('p_direttarai_err_invalidchannel'));
         }
     } else {
         // if user abort request (vlc/wii stop playing, this process ends)
         ignore_user_abort(false);
         // close and clean the output buffer, everything will be read and send to device
         ob_end_clean();
         // readfile open a file and send it directly to output buffer
         readfile($videoUrl, false, $context);
     }
 }
 /**
  * (non-PHPdoc)
  * @see X_PageParser_Parser::parse()
  */
 public function parse($string)
 {
     switch ($this->mode) {
         case self::MODE_TITLES:
             return $this->parseTitles($string);
         case self::MODE_EPISODES:
             return $this->parseEpisodes($string);
         case self::MODE_LINKS:
             return $this->parseLinks($string);
         case self::MODE_NEXTPAGE:
             return $this->parseNextPage($string);
         default:
             throw new Exception("Invalid mode: {" . $this->mode . "}");
     }
     // dead code
     // first, find the thumb url:
     $match = array();
     $thumb = false;
     preg_match(self::PATTERN_THUMBNAIL, $string, $match);
     // avoid relative thumbnails
     if (count($match) > 0 && X_Env::startWith($match['image'], 'http://')) {
         $thumb = $match['image'];
         X_Debug::i("Thumbnail found: {$thumb}");
     }
     /* @var $hosterHelper X_VlcShares_Plugins_Helper_Hoster */
     $hosterHelper = X_VlcShares_Plugins::helpers()->hoster();
     $subparser = X_PageParser_Parser_HosterLinks::factory($hosterHelper, X_PageParser_Parser_Preg::factory(self::PATTERN_LINKS, X_PageParser_Parser_Preg::PREG_MATCH_ALL, PREG_SET_ORDER));
     $links = $subparser->parse($string);
     X_Debug::i("Valid hosters link found: " . count($links));
     // clean results and reformat them
     $cleanedLinks = array();
     foreach ($links as $link) {
         $cLink = array();
         $cLink['hosterId'] = $link['hoster']->getId();
         $cLink['videoId'] = $link['hoster']->getResourceId($link['url']);
         $cLink['label'] = strip_tags($link['label']);
         $cLink['link'] = "{$cLink['hosterId']}:{$cLink['videoId']}";
         $cLink['thumbnail'] = $thumb;
         $cleanedLinks[] = $cLink;
     }
     return $cleanedLinks;
 }
 public function init()
 {
     parent::init();
     if (!X_VlcShares_Plugins::broker()->isRegistered('megavideo')) {
         /*
         $this->_helper->flashMessenger(X_Env::_('err_pluginnotregistered') . ": youtube");
         $this->_helper->redirector('index', 'manage');
         */
         throw new Exception(X_Env::_('err_pluginnotregistered') . ": megavideo");
     } else {
         $this->plugin = X_VlcShares_Plugins::broker()->getPlugins('megavideo');
     }
     $action = $this->getRequest()->getActionName();
     if ($action == 'premium') {
         // disabling outbuffering
         // and response return
         $this->getFrontController()->setParam('disableOutputBuffering', true);
         $this->getFrontController()->returnResponse(false);
     }
 }
 /**
  * This hook can be used check vlc status just before
  * spawn is called
  * 
  * @param X_Vlc $vlc vlc wrapper object
  * @param string $provider id of the plugin that should handle request
  * @param string $location to stream
  * @param Zend_Controller_Action $controller the controller who handle the request
  */
 public function preSpawnVlc(X_Vlc $vlc, $provider, $location, Zend_Controller_Action $controller)
 {
     // TODO port to newer api when ready
     // when newer X_Vlc's api will be ready
     // i will need change this to
     // $source = $vlc->getSource();
     // and double quote removal will be automatic
     $source = $vlc->getArg('source');
     $provider = X_VlcShares_Plugins::broker()->getPlugins($provider);
     //if ( X_Env::isWindows() && !X_Env::startWith($source, 'http://') && !X_Env::startWith($source, 'https://') ) {
     if (X_Env::isWindows() && is_a($provider, 'X_VlcShares_Plugins_FileSystem')) {
         // with newer api this will be useless
         $source = realpath(trim($source, '"'));
         // when newer X_Vlc's api will be ready
         // i will need change this to
         // $vlc->setSource($source);
         // and double quotation will be automatic
         $vlc->registerArg('source', "\"{$source}\"");
     }
 }
 public function collectionsAction()
 {
     $pageItems = new X_Page_ItemList_PItem();
     // links on top
     $pageItems->merge(X_VlcShares_Plugins::broker()->preGetCollectionsItems($this));
     // normal links
     $pageItems->merge(X_VlcShares_Plugins::broker()->getCollectionsItems($this));
     // bottom links
     $pageItems->merge(X_VlcShares_Plugins::broker()->postGetCollectionsItems($this));
     // filter out items (parental-control / hidden file / system dir)
     foreach ($pageItems->getItems() as $key => $item) {
         $results = X_VlcShares_Plugins::broker()->filterCollectionsItems($item, $this);
         if ($results != null && in_array(false, $results)) {
             //unset($pageItems[$key]);
             $pageItems->remove($item);
         }
     }
     // trigger for page creation
     X_VlcShares_Plugins::broker()->gen_afterPageBuild($pageItems, $this);
 }
 /**
  * Get category/video list
  * @param unknown_type $provider
  * @param unknown_type $location
  * @param Zend_Controller_Action $controller
  * @return X_Page_ItemList_PItem
  */
 public function getShareItems($provider, $location, Zend_Controller_Action $controller)
 {
     // this plugin add items only if it is the provider
     if ($provider != $this->getId()) {
         return;
     }
     X_Debug::i("Plugin triggered");
     // disabling cache plugin
     try {
         $cachePlugin = X_VlcShares_Plugins::broker()->getPlugins('cache');
         if (method_exists($cachePlugin, 'setDoNotCache')) {
             $cachePlugin->setDoNotCache();
         }
     } catch (Exception $e) {
         // cache plugin not registered, no problem
     }
     $urlHelper = $controller->getHelper('url');
     $items = new X_Page_ItemList_PItem();
     if ($location != '') {
         //list($shareType, $linkId) = explode(':', $location, 2);
         // $location is the categoryName
         $videos = Application_Model_MegavideoMapper::i()->fetchByCategory($location);
         foreach ($videos as $video) {
             /* @var $video Application_Model_Megavideo */
             $item = new X_Page_Item_PItem($this->getId() . '-' . $video->getId(), $video->getLabel());
             $item->setIcon('/images/icons/file_32.png')->setType(X_Page_Item_PItem::TYPE_ELEMENT)->setCustom(__CLASS__ . ':location', $video->getId())->setLink(array('action' => 'mode', 'l' => X_Env::encode($video->getId())), 'default', false);
             $items->append($item);
         }
     } else {
         // if location is not specified,
         // show collections
         $categories = Application_Model_MegavideoMapper::i()->fetchCategories();
         foreach ($categories as $share) {
             /* @var $share Application_Model_FilesystemShare */
             $item = new X_Page_Item_PItem($this->getId() . '-' . $share['category'], "{$share['category']} ({$share['links']})");
             $item->setIcon('/images/icons/folder_32.png')->setType(X_Page_Item_PItem::TYPE_CONTAINER)->setCustom(__CLASS__ . ':location', $share['category'])->setLink(array('l' => X_Env::encode($share['category'])), 'default', false);
             $items->append($item);
         }
     }
     return $items;
 }
 /**
  * Get category/video list
  * @param unknown_type $provider
  * @param unknown_type $location
  * @param Zend_Controller_Action $controller
  */
 public function getShareItems($provider, $location, Zend_Controller_Action $controller)
 {
     if ($provider != $this->getId()) {
         return;
     }
     X_Debug::i('Plugin triggered');
     X_VlcShares_Plugins::broker()->unregisterPluginClass('X_VlcShares_Plugins_SortItems');
     if (X_VlcShares_Plugins::broker()->isRegistered('cache')) {
         $cachePlugin = X_VlcShares_Plugins::broker()->getPlugins('cache');
         if (method_exists($cachePlugin, 'setDoNotCache')) {
             $cachePlugin->setDoNotCache();
         }
     }
     $items = new X_Page_ItemList_PItem();
     foreach ($this->channels as $name => $url) {
         $item = new X_Page_Item_PItem($this->getId() . "-{$url}", $name);
         $item->setIcon('/images/icons/file_32.png')->setType(X_Page_Item_PItem::TYPE_CONTAINER)->setCustom(__CLASS__ . ':location', $url)->setLink(array('l' => X_Env::encode($url), 'action' => 'mode'), 'default', false);
         $items->append($item);
     }
     return $items;
 }
 public function startEngine(X_Threads_Thread $thread)
 {
     // assume all parameters are ready
     $thread->log("Spawning RTMPDump (rtmpdump | vlc)...");
     $source = $this->getParam('source');
     if (X_VlcShares_Plugins::helpers()->streamer()->isRegistered('vlc')) {
         $command = (string) X_RtmpDump::getInstance()->parseUri($source);
         $streamPort = X_VlcShares_Plugins::helpers()->rtmpdump()->getStreamPort();
         // try to get reference to vlc-streamer
         /* @var $vlcStreamer X_Streamer_Engine_Vlc */
         $vlcStreamer = X_VlcShares_Plugins::helpers()->streamer()->get('vlc');
         $vlcStreamer->getVlcWrapper()->setPipe($command);
         $vlcStreamer->setSource('-');
         $vlcStreamer->setParam('profile', "#std{access=http{mime=video/x-flv},mux=ffmpeg{mux=flv},dst=0.0.0.0:{$streamPort}/}");
         //X_Env::execute($command, X_Env::EXECUTE_OUT_NONE, X_Env::EXECUTE_PS_WAIT);
         $vlcStreamer->getVlcWrapper()->spawn();
         //$this->vlc->spawn();
         $thread->log("RTMPDump execution finished");
     } else {
         $thread->log("RTMPDump cannot be started without vlc streamer");
     }
 }
 /**
  * Get category/video list
  * @param unknown_type $provider
  * @param unknown_type $location
  * @param Zend_Controller_Action $controller
  */
 public function getShareItems($provider, $location, Zend_Controller_Action $controller)
 {
     // this plugin add items only if it is the provider
     if ($provider != $this->getId()) {
         return;
     }
     X_Debug::i("Plugin triggered");
     $urlHelper = $controller->getHelper('url');
     $items = new X_Page_ItemList_PItem();
     //try to disable SortItems plugin, so link are listed as in html page
     X_VlcShares_Plugins::broker()->unregisterPluginClass('X_VlcShares_Plugins_SortItems');
     X_Debug::i("Requested location: {$location}");
     $split = $location != '' ? @explode('/', $location, 4) : array();
     X_Debug::i("Exploded location: " . var_export($split, true));
     switch (count($split)) {
         // i should not be here, so i fallback to video case
         case 4:
             // show the list of video in the page
             // here authentication is required if it's possibile
         // show the list of video in the page
         // here authentication is required if it's possibile
         case 3:
             $this->_fetchVideos($items, $split[0], $split[1], $split[2]);
             break;
             // show the list of thread in category by letter
         // show the list of thread in category by letter
         case 2:
             $this->_fetchThreads($items, $split[0], $split[1]);
             break;
             // show the list of A-B-C.... if an area is selected
         // show the list of A-B-C.... if an area is selected
         case 1:
             $this->_fetchClassification($items, $split[0]);
             break;
         default:
             $this->_fetchLists($items);
     }
     return $items;
 }