public function gen_afterPageBuild(X_Page_ItemList_PItem $list, Zend_Controller_Action $controller)
 {
     if (!$this->isDefaultRenderer()) {
         return;
     }
     X_Debug::i("Plugin triggered");
     $request = $controller->getRequest();
     $responseType = 'u:BrowseResponse';
     $num = count($list->getItems());
     if ($this->request['browseflag'] == 'BrowseMetadata') {
         $parentID = $this->_getParent($controller->getRequest());
         $item = new X_Page_Item_PItem('fake-item', "Container");
         $item->setLink(array_merge(array('controller' => $controller->getRequest()->getControllerName(), 'action' => $controller->getRequest()->getActionName()), $controller->getRequest()->getParams()));
         $item->setDescription("Fake description");
         $didl = X_Upnp::createMetaDIDL($item, $parentID, $num, $controller->getRequest()->getControllerName(), $controller->getRequest()->getActionName(), $controller->getRequest()->getParam('p', 'null'));
     } elseif ($this->request['browseflag'] == 'BrowseDirectChildren') {
         $parentID = $this->request['objectid'];
         $didl = X_Upnp::createDIDL($list->getItems(), $parentID, $num, $controller->getRequest()->getControllerName(), $controller->getRequest()->getActionName(), $controller->getRequest()->getParam('p', 'null'));
     }
     $xmlDIDL = $didl->saveXML();
     X_Debug::i("DIDL response: {$xmlDIDL}");
     // Build SOAP-XML reply from DIDL-XML and send it to upnp device
     $domSOAP = X_Upnp::createSOAPEnvelope($xmlDIDL, $num, $num, $responseType, $parentID);
     $soapXML = $domSOAP->saveXML();
     // turn off viewRenderer and Layout, add Content-Type and set response body
     $this->_render($soapXML, $controller);
 }
 /**
  * Redirect to controls if vlc is running
  * @param Zend_Controller_Action $controller
  */
 public function gen_beforePageBuild(Zend_Controller_Action $controller)
 {
     /*
     $vlc = X_Vlc::getLastInstance();
     
     if ( $vlc === null ) {
     	X_Debug::i("No vlc instance");
     	return;
     }
     */
     $controllerName = $controller->getRequest()->getControllerName();
     $actionName = $controller->getRequest()->getActionName();
     $query = "{$controllerName}/{$actionName}";
     X_Debug::i("Plugin triggered for: {$query}");
     //$isRunning = $vlc->isRunning();
     $isRunning = X_Streamer::i()->isStreaming();
     if (array_search($query, $this->redirectCond_To) !== false && $isRunning) {
         $controller->getRequest()->setControllerName('controls')->setActionName('control')->setDispatched(false);
         X_Debug::i("Redirect to controls/control");
     } elseif (array_search($query, $this->redirectCond_Away) !== false && !$isRunning) {
         X_Debug::i("Redirect to index/collections");
         $controller->getRequest()->setControllerName('index')->setActionName('collections')->setDispatched(false);
     } else {
         X_Debug::i("No redirection: vlc is running? " . ($isRunning ? 'Yes' : 'No'));
     }
 }
 function removeAction()
 {
     $id = $this->getRequest()->getParam('id', false);
     $csrf = $this->getRequest()->getParam('csrf', false);
     if (!$id) {
         throw new Exception("Thread id missing");
     }
     $hash = new Zend_Form_Element_Hash('csrf', array('salt' => __CLASS__));
     if (!$hash->isValid($csrf)) {
         throw new Exception("Invalid token");
     }
     $hash->initCsrfToken();
     $thread = X_Threads_Manager::instance()->getMonitor()->getThread($id);
     // special case for streamer
     if ($thread->getId() == X_Streamer::THREAD_ID) {
         X_Debug::i('Special stop');
         X_Streamer::i()->stop();
     } else {
         X_Threads_Manager::instance()->halt($thread);
     }
     // wait 5 seconds
     sleep(5);
     X_Threads_Manager::instance()->getMessenger()->clearQueue($thread);
     X_Threads_Manager::instance()->getMonitor()->removeThread($thread, true);
     $this->_helper->flashMessenger(array('type' => 'success', 'text' => X_Env::_('threads_done')));
     $this->_helper->redirector('index', 'tmanager');
 }
 /**
  * Add the go to stream link (only if engine is rtmpdump)
  * 
  * @param X_Streamer_Engine $engine selected streamer engine
  * @param string $uri
  * @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
  * @return X_Page_ItemList_PItem 
  */
 public function getStreamItems(X_Streamer_Engine $engine, $uri, $provider, $location, Zend_Controller_Action $controller)
 {
     // ignore the call if streamer is not rtmpdump
     if (!$engine instanceof X_Streamer_Engine_RtmpDump) {
         return;
     }
     X_Debug::i('Plugin triggered');
     $return = new X_Page_ItemList_PItem();
     $outputLink = "http://{%SERVER_NAME%}:{$this->helpers()->rtmpdump()->getStreamPort()}/";
     $outputLink = str_replace(array('{%SERVER_IP%}', '{%SERVER_NAME%}'), array($_SERVER['SERVER_ADDR'], strstr($_SERVER['HTTP_HOST'], ':') ? strstr($_SERVER['HTTP_HOST'], ':') : $_SERVER['HTTP_HOST']), $outputLink);
     $item = new X_Page_Item_PItem($this->getId(), X_Env::_('p_outputs_gotostream'));
     $item->setType(X_Page_Item_PItem::TYPE_PLAYABLE)->setIcon('/images/icons/play.png')->setLink($outputLink);
     $return->append($item);
     /*
     
     		$item = new X_Page_Item_PItem('controls-stop', X_Env::_('p_controls_stop'));
     		$item->setType(X_Page_Item_PItem::TYPE_ELEMENT)
     			->setIcon('/images/icons/stop.png')
     			->setLink(array(
     				'controller'		=>	'controls',
     				'action'	=>	'execute',
     				'a'			=>	'stop',
     				'pid'		=>	$this->getId(),
     			), 'default', false);
     		$return->append($item);
     */
     return $return;
 }
 /**
  * Show an error if ffmpeg isn't enabled
  */
 function getIndexMessages(Zend_Controller_Action $controller)
 {
     X_Debug::i('Plugin triggered');
     $m = new X_Page_Item_Message($this->getId(), X_Env::_('p_fsthumbs_dashboardffmpegerror'));
     $m->setType(X_Page_Item_Message::TYPE_ERROR);
     return new X_Page_ItemList_Message(array($m));
 }
示例#6
0
 function gen_beforePageBuild(Zend_Controller_Action $controller)
 {
     $moduleName = $controller->getRequest()->getModuleName();
     $controllerName = $controller->getRequest()->getControllerName();
     $actionName = $controller->getRequest()->getActionName();
     $providerName = $controller->getRequest()->getParam('p', false);
     // check permission class
     if ($controllerName == 'browse' && $actionName == 'share') {
         // check provider too only if controller == browse
         $resourceKey = "{$moduleName}/{$controllerName}/{$actionName}" . ($providerName !== false ? "/{$providerName}" : '');
     } else {
         $resourceKey = "{$moduleName}/{$controllerName}/{$actionName}";
     }
     // TODO:
     // replace this with an ACL call:
     //  if ( !$acl->canUse($resource, $currentStatus) )
     if (array_search("{$moduleName}/{$controllerName}/{$actionName}", $this->_whiteList) === false) {
         if (!$this->isLoggedIn()) {
             X_Debug::i("Login required and user not logged in");
             if ($this->helpers()->devices()->isVlc()) {
                 X_Debug::i("Look like it's this vlc: {$_SERVER['REMOTE_ADDR']}");
                 if (gethostbyname($_SERVER['REMOTE_ADDR']) == '::1' || gethostbyname($_SERVER['REMOTE_ADDR']) == '127.0.0.1') {
                     X_Debug::i("Skipping auth, it should be the local vlc");
                     return;
                 }
             } elseif ($this->helpers()->devices()->isWiimc() && $this->helpers()->devices()->isWiimcBeforeVersion('1.1.6')) {
                 // wiimc <= 1.1.5 send 2 different user-agent string
                 // for browsing mode and video mode
                 // so i have care about this
                 // TODO remove this when 1.1.5 an older will be deprecated
                 // anyway i take care only of vanilla wiimc based on ios58. custom version
                 // not supported
                 $useragent = "{$_SERVER['HTTP_USER_AGENT']} (IOS58)";
                 // try to add " (ISO58)" to the useragent and check again
                 if (Application_Model_AuthSessionsMapper::i()->fetchByIpUserAgent($_SERVER['REMOTE_ADDR'], $useragent)) {
                     X_Debug::i("Workaround for WIIMC user-agent-incongruence");
                     return;
                 }
             } elseif ($this->helpers()->acl()->canUseAnonymously($resourceKey)) {
                 X_Debug::i("Resource can be used anonymously");
                 return;
             }
             X_Debug::w("Auth required, redirecting to login");
             $controller->getRequest()->setControllerName("auth")->setActionName('index')->setDispatched(false);
         } elseif ($this->config('acl.enabled', false)) {
             X_Debug::i("ACL enabled, checking resource {{$resourceKey}}");
             $username = $this->getCurrentUser(true);
             if (!$this->helpers()->acl()->canUse($username, $resourceKey)) {
                 X_Debug::w("Forbidden, can't access resource");
                 $controller->getRequest()->setControllerName("auth")->setActionName('forbidden')->setDispatched(false);
             } else {
                 X_Debug::i("Access granted");
             }
         } else {
             X_Debug::i("ACL disabled");
         }
     } else {
         X_Debug::i("Whitelisted resource");
     }
 }
 public function saveAction()
 {
     /* @var $request Zend_Controller_Request_Http */
     $request = $this->getRequest();
     $configs = Application_Model_ConfigsMapper::i()->fetchAll();
     if ($request->isPost()) {
         $form = $this->_initConfigsForm($configs, $request->getPost());
         if (!$form->isErrors()) {
             $post = $request->getPost();
             $isError = false;
             foreach ($configs as $config) {
                 /* @var $config Application_Model_Config */
                 if ($config->getSection() == 'plugins') {
                     continue;
                 }
                 // plugins config will not be handled here
                 $postStoreName = $config->getSection() . "_" . str_replace('.', '_', $config->getKey());
                 // ISSUE-15: https://code.google.com/p/vlc-shares/issues/detail?id=15
                 // This is a workaround it: remove slashes if magic_quotes is enabled
                 // FIXME remove this workaround in vlc-shares 0.6+
                 $postValue = $request->getPost($postStoreName);
                 if (get_magic_quotes_gpc()) {
                     //$postValue = str_replace(array('\\\\' , '=\\"'), array('\\', '="'), $postValue );
                     $postValue = stripslashes($postValue);
                 }
                 if (array_key_exists($postStoreName, $post) && $config->getValue() != $postValue) {
                     // new value
                     try {
                         $config->setValue($postValue);
                         Application_Model_ConfigsMapper::i()->save($config);
                         if (stripos($config->getKey(), 'password') != false) {
                             X_Debug::i("New config: {$config->getSection()}.{$config->getKey()} = ***********");
                         } else {
                             X_Debug::i("New config: {$config->getSection()}.{$config->getKey()} = {$config->getValue()}");
                         }
                     } catch (Exception $e) {
                         $isError = true;
                         $this->_helper->flashMessenger(X_Env::_('configs_save_err_db') . ": {$e->getMessage()}");
                     }
                 }
             }
             if (!$isError) {
                 $this->_helper->flashMessenger(X_Env::_('configs_save_done'));
             }
             if ($form->getValue('isapply') == '1') {
                 $this->_helper->redirector('index', 'configs');
             } else {
                 $this->_helper->redirector('index', 'manage');
             }
         } else {
             $this->_forward('index');
         }
     } else {
         $this->_helper->flashMessenger(X_Env::_('configs_save_nodata'));
         $this->_helper->redirector('index', 'configs');
     }
 }
示例#8
0
 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 gen_afterPageBuild(X_Page_ItemList_PItem $items, Zend_Controller_Action $controller)
 {
     if (count($items->getItems()) == 0) {
         X_Debug::i("Plugin triggered");
         $item = new X_Page_Item_PItem('emptylists', X_Env::_('p_emptylists_moveaway'));
         $item->setType(X_Page_Item_PItem::TYPE_ELEMENT)->setLink(X_Env::completeUrl($controller->getHelper('url')->url()));
         $items->append($item);
     }
 }
 /**
  * Redirect to controls if vlc is running
  * @param Zend_Controller_Action $controller
  */
 public function gen_beforePageBuild(Zend_Controller_Action $controller)
 {
     X_Debug::i("Plugin triggered: redirect to installer");
     $controllerName = $controller->getRequest()->getControllerName();
     if ($controllerName != 'installer' && $controllerName != 'error') {
         //die($controllerName);
         $controller->getRequest()->setControllerName('installer')->setActionName('index')->setDispatched(false);
     }
 }
示例#11
0
 public function getPage($uri)
 {
     // http hold all info about the last request and last response object as well as all options
     if ($this->last_request_uri != $uri) {
         $this->last_request_uri = $uri;
         X_Debug::i("Fetching: {$uri}");
         $this->getHttpClient()->setUri($uri)->request();
         //X_Debug::i("Request: \n".$this->getHttpClient()->getLastRequest());
     }
     return $this->getHttpClient()->getLastResponse()->getBody();
 }
 public function gen_afterPageBuild(X_Page_ItemList_PItem $items, Zend_Controller_Action $controller)
 {
     if ($this->helpers()->devices()->isWiimc() && $this->helpers()->devices()->isWiimcBeforeVersion('1.0.9')) {
         if (count($items->getItems()) === 1) {
             X_Debug::i("Plugin triggered");
             $item = new X_Page_Item_PItem('workaroundwiimcplaylistitemsbug', '-- Workaround for bug in Wiimc <= 1.0.9 --');
             $item->setType(X_Page_Item_PItem::TYPE_ELEMENT)->setLink(X_Env::completeUrl($controller->getHelper('url')->url()));
             $items->append($item);
         }
     }
 }
 public function indexAction()
 {
     // uses the device helper for wiimc recognition
     // maybe i will add a trigger here
     if (X_VlcShares_Plugins::helpers()->devices()->isWiimc()) {
         // wiimc 1.0.9 e inferiori nn accetta redirect
         X_Debug::i("Forwarding...");
         $this->_forward('collections', 'index');
     } else {
         $this->_helper->redirector('index', 'manage');
     }
 }
示例#14
0
 /**
  * Get things found by the $parser
  * @see X_PageParser_Parser
  * @return mixed
  */
 public function getParsed(X_PageParser_Parser $parser = null)
 {
     if (!is_null($parser)) {
         X_Debug::i("Temp pattern");
         $loaded = $this->getLoader()->getPage($this->uri);
         return $parser->parse($loaded);
     } elseif ($this->parsed === null) {
         $loaded = $this->getLoader()->getPage($this->uri);
         $this->parsed = $this->getParser()->parse($loaded);
     }
     return $this->parsed;
 }
 protected function processProperties($properties = array())
 {
     if (!is_array($properties)) {
         X_Debug::e("Properties is not an array");
         return;
     }
     foreach ($properties as $key => $value) {
         $properties_ignored = true;
         // prot-type is valid
         if (isset(self::$validProperties[$key])) {
             // check value
             $validValues = self::$validProperties[$key];
             @(list($typeValidValues, $validValues) = @explode(':', $validValues, 2));
             // typeValidValues = boolean / regex / set / ...
             switch ($typeValidValues) {
                 case 'boolean':
                     $checkValues = array('true', 'false', '0', '1');
                     if (array_search($value, $checkValues)) {
                         // cast to type
                         $value = (bool) $value;
                         $properties_ignored = false;
                     } else {
                         $properties_ignored = "invalid property value {{$value}}, not boolean";
                     }
                     break;
                 case 'set':
                     $checkValues = explode('|', $validValues);
                     if (array_search($value, $checkValues)) {
                         $properties_ignored = false;
                     } else {
                         $properties_ignored = "invalid property value {{$value}}, not in valid set";
                     }
                     break;
                 case 'regex':
                     if (preg_match($validValues, $value)) {
                         $properties_ignored = false;
                     } else {
                         $properties_ignored = "invalid property value {{$value}}, format not valid";
                     }
                     break;
             }
         } else {
             $properties_ignored = "invalid property";
         }
         if ($properties_ignored !== false) {
             X_Debug::w("Property {{$key}} of acl-resource {{$this->getKey()}} ignored: " . $properties_ignored !== true ? $properties_ignored : 'unknown reason');
         } else {
             X_Debug::i("Valid property for acl-resource {{$this->getKey()}}: {$key} => {{$value}}");
             $this->properties[$key] = $value;
         }
     }
 }
 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);
 }
 /**
  * (non-PHPdoc)
  * @see X_PageParser_Parser::parse()
  */
 public function parse($string)
 {
     $matches = array();
     $links = array();
     preg_match_all(self::PATTERN, $string, $matches, PREG_SET_ORDER);
     X_Debug::i(sprintf("Links found: %s", count($matches)));
     // process links
     foreach ($matches as $match) {
         $link = array();
         $link['label'] = $match['LABEL'];
         $link['hoster'] = X_VlcShares_Plugins_Helper_Hoster_Own3dLive::ID;
         $link['id'] = $match['ID'];
         $links[] = $link;
     }
     return $links;
 }
 /**
  * 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()}");
     }
 }
示例#19
0
 /**
  * get a playable resource url
  * from an $url (or a resource id if $isId = true)
  * @param string $url the hoster page or resource ID
  * @param boolean $isId
  * @return string a playable url
  */
 function getPlayable($url, $isId = true)
 {
     if (!$isId) {
         $url = $this->getResourceId($url);
     }
     // $url is an id now for sure
     /* @var $youtubeHelper X_VlcShares_Plugins_Helper_Youtube */
     $youtubeHelper = X_VlcShares_Plugins::helpers()->helper('youtube');
     /* @var $youtubePlugin X_VlcShares_Plugins_Youtube */
     $youtubePlugin = X_VlcShares_Plugins::broker()->getPlugins('youtube');
     X_Debug::i("Youtube ID: {$url}");
     // THIS CODE HAVE TO BE MOVED IN YOUTUBE HELPER
     // FIXME
     $formats = $youtubeHelper->getFormatsNOAPI($url);
     $returned = null;
     $qualityPriority = explode('|', $youtubePlugin->config('quality.priority', '5|34|18|35'));
     foreach ($qualityPriority as $quality) {
         if (array_key_exists($quality, $formats)) {
             $returned = $formats[$quality];
             X_Debug::i('Video format selected: ' . $quality);
             break;
         }
     }
     if ($returned === null) {
         // for valid video id but video with restrictions
         // alternatives formats can't be fetched by youtube page.
         // i have to fallback to standard api url
         $apiVideo = $youtubeHelper->getVideo($url);
         foreach ($apiVideo->mediaGroup->content as $content) {
             if ($content->type === "video/3gpp") {
                 $returned = $content->url;
                 X_Debug::w('Content restricted video, fallback to api url:' . $returned);
                 break;
             }
         }
         if ($returned === null) {
             $returned = false;
         }
     }
     if ($returned !== false && $returned !== null) {
         // valid return
         return $returned;
     }
     throw new Exception("Invalid video", self::E_ID_INVALID);
 }
 /**
  * Retrieve statistic from plugins
  * @param Zend_Controller_Action $this
  * @return X_Page_ItemList_Message
  */
 public function getIndexMessages(Zend_Controller_Action $controller)
 {
     $version = X_VlcShares::VERSION;
     X_Debug::i('Plugin triggered');
     $showError = false;
     $type = 'warning';
     if (strpos($version, 'alpha') !== false || strpos($version, 'beta') !== false || strpos($version, 'dev') !== false || strpos($version, 'unstable') !== false) {
         $showError = true;
     } elseif (strpos($version, 'rc') !== false || strpos($version, 'release_candidate') !== false) {
         $showError = true;
         $type = 'info';
     }
     if ($showError) {
         $m = new X_Page_Item_Message($this->getId(), X_Env::_('p_widgetdevalert_warningmessage'));
         $m->setType($type);
         return new X_Page_ItemList_Message(array($m));
     }
 }
示例#21
0
 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);
 }
示例#22
0
 private function parseVideos($string)
 {
     $matches = array();
     $links = array();
     preg_match_all(self::PATTERN_VIDEOS, $string, $matches, PREG_SET_ORDER);
     X_Debug::i(sprintf("Links found: %s", count($matches)));
     // process links
     foreach ($matches as $match) {
         $label = $match['label'];
         $id = $match['id'];
         $thumbnail = $match['thumbnail'];
         $link = array();
         $link['label'] = $label;
         $link['thumbnail'] = $thumbnail;
         $link['id'] = $id;
         $links[] = $link;
     }
     return $links;
 }
 public function gen_afterPageBuild(X_Page_ItemList_PItem $items, Zend_Controller_Action $controller)
 {
     if (!$this->isDefaultRenderer()) {
         // to be used, this
         return;
     }
     X_Debug::i("Plugin triggered");
     $request = $controller->getRequest();
     $urlHelper = $controller->getHelper('url');
     if ($request instanceof Zend_Controller_Request_Http) {
         if ($request->isXmlHttpRequest() || $request->getParam('webkit:json', false)) {
             $this->dispatchRequest($request, $items, $controller);
         } else {
             $this->showMainPage($request, $controller);
         }
     } else {
         X_Debug::f("Request isn't HTTP");
     }
 }
 /**
  * Return true if $item is an hidden file or system file (check configs)
  * @param X_Page_Item_PItem $item
  * @param string $provider
  * @param Zend_Controller_Action $controller
  * @return boolean|null true or null if file is ok, false otherwise (will be filtered out)
  */
 public function filterShareItems(X_Page_Item_PItem $item, $provider, Zend_Controller_Action $controller)
 {
     try {
         $plugin = X_VlcShares_Plugins::broker()->getPlugins($provider);
         if (is_a($plugin, 'X_VlcShares_Plugins_FileSystem') && $plugin instanceof X_VlcShares_Plugins_ResolverInterface) {
             // i use instanceof ResolverInterface
             // so i have code suggestions
             // X_VlcShares_Plugins_FileSystem register a custom param in item
             // for location lookup
             $location = $plugin->resolveLocation($item->getCustom('X_VlcShares_Plugins_FileSystem:location'));
             // i must check for $location !== false as a fallback for no custom param case
             if ($location !== false && file_exists($location)) {
                 // i have a location to check for hidden files:
                 if ($this->_checkEntry($location) === false) {
                     X_Debug::i("Plugin triggered, item filtered: {$location}");
                     return false;
                 }
             }
             //X_Debug::i('Plugin triggered');
         }
     } catch (Exception $e) {
         X_Debug::w("Problem while filtering: {$e->getMessage()}");
     }
 }
 function scategoryAction()
 {
     /* @var $request Zend_Controller_Request_Http */
     $request = $this->getRequest();
     if (!$request->isPost()) {
         $this->_helper->flashMessenger(array('text' => X_Env::_('p_youtube_save_invalidrequest'), 'type' => 'error'));
         $this->_helper->redirector('index', 'youtube');
     }
     try {
         $form = new Application_Form_YoutubeCategory();
     } catch (Exception $e) {
         $this->_helper->flashMessenger(array('text' => X_Env::_('p_youtube_save_formerror') . ": {$e->getMessage()}", 'type' => 'error'));
         $this->_helper->redirector('index', 'youtube');
     }
     $post = $request->getPost();
     X_Debug::i("Post = '" . var_export($post, true) . "'");
     $valid = $form->isValid($post);
     $thumbselectValue = $form->getValue('thumbselect');
     X_Debug::i("Valid = '{$valid}'");
     X_Debug::i("Thumbselect = '{$thumbselectValue}'");
     //X_Debug::i("Error messages = '" . var_export($form->getErrorMessages(), true) . "'");
     //X_Debug::i("Errors = '" . var_export($form->getErrors(), true) . "'");
     if ($thumbselectValue == 'upload') {
         // if thumbselectvalue == '', i have to read the file content
         // as required
         $form->thumbnail->setRequired(true);
         // i need to check it again if thumbnail upload is required
         $valid = $form->isValid($post);
         X_Debug::i("Valid = '{$valid}'");
     }
     if ($valid != true) {
         $this->_helper->flashMessenger(array('text' => X_Env::_('p_youtube_save_invaliddata'), 'type' => 'error'));
         //$this->_helper->flashMessenger(array('text' => '<pre>'.var_export($form, true).'</pre>', 'type' => 'error'));
         foreach ($form->getErrorMessages() as $error) {
             $this->_helper->flashMessenger(array('text' => $error, 'type' => 'error'));
         }
         $this->_helper->redirector('index', 'youtube');
     }
     if ($thumbselectValue == 'upload' && $form->thumbnail->isUploaded()) {
         try {
             $form->thumbnail->receive();
         } catch (Exception $e) {
             $this->_helper->flashMessenger(array('text' => X_Env::_('p_youtube_save_err_receivedata'), 'type' => 'error'));
             $this->_helper->redirector('index', 'youtube');
         }
         $thumbselectValue = '/images/youtube/uploads/' . pathinfo($form->thumbnail->getFileName(), PATHINFO_BASENAME);
     } else {
         $thumbselectValue = '/images/youtube/uploads/' . $thumbselectValue;
     }
     try {
         $category = new Application_Model_YoutubeCategory();
         $categoryId = $form->getValue('id');
         if ($categoryId) {
             Application_Model_YoutubeCategoriesMapper::i()->find($categoryId, $category);
         }
         $category->setLabel($form->getValue('label'))->setThumbnail($thumbselectValue);
         Application_Model_YoutubeCategoriesMapper::i()->save($category);
         $this->_helper->flashMessenger(array('text' => X_Env::_('p_youtube_save_completed_category'), 'type' => 'info'));
         $this->_helper->redirector('index', 'youtube');
     } catch (Exception $e) {
         $this->_helper->flashMessenger(array('text' => X_Env::_('p_youtube_save_err_dberror') . ": {$e->getMessage()}", 'type' => 'error'));
         $this->_helper->redirector('index', 'youtube');
     }
 }
示例#26
0
 public static function init($options, $helpersOptions = array())
 {
     // plugins are registered in plugin broker
     self::$_pluginBroker = new X_VlcShares_Plugins_Broker();
     if (!$options instanceof Zend_Config) {
         if (!is_array($options)) {
             $options = array();
         }
         $options = new Zend_Config($options);
     }
     if (!$helpersOptions instanceof Zend_Config) {
         if (!is_array($helpersOptions)) {
             $helpersOptions = array();
         }
         $helpersOptions = new Zend_Config($helpersOptions);
     }
     $plugins = Application_Model_PluginsMapper::i()->fetchAll();
     //foreach ($options as $o_k => $o_v ) {
     // 	$pValue = $o_v->toArray();
     //	$pKey = $o_k;
     foreach ($plugins as $plugin) {
         /* @var $plugin Application_Model_Plugin */
         if (!$plugin->isEnabled() && $plugin->getType() != Application_Model_Plugin::SYSTEM) {
             continue;
         }
         $pKey = $plugin->getKey();
         try {
             if ($options->{$pKey}) {
                 $pValue = $options->{$pKey}->toArray();
             } else {
                 // no configs
                 $pValue = array();
             }
         } catch (Exception $e) {
             // no configs
             $pValue = array();
         }
         $pValue['class'] = $plugin->getClass();
         if ($plugin->getFile() != null) {
             $pValue['path'] = APPLICATION_PATH . "/../library/" . $plugin->getFile();
         }
         $className = $pValue['class'];
         $path = @$pValue['path'];
         // se class non e' settato, il plugin nn e' valido
         if (!$className) {
             continue;
         }
         if ($path && substr($path, -4) == '.php' && file_exists($path)) {
             require_once $path;
         }
         if (class_exists($className) && is_subclass_of($className, 'X_VlcShares_Plugins_Abstract')) {
             $pValue['id'] = $pKey;
             // si auto referenzia
             //new $className(new Zend_Config($pValue));
             // plugins system from
             //	event-based -> function-based
             $plugin = new $className();
             //X_Debug::i($pKey . ":\n".var_export($pValue, true));
             $plugin->setConfigs(new Zend_Config($pValue));
             self::$_pluginBroker->registerPlugin($pKey, $plugin, true);
         }
     }
     self::$_helperBroker = new X_VlcShares_Plugins_Helper_Broker($helpersOptions);
     X_Debug::i("Plugin system enabled");
     $pluginlist = implode(', ', array_keys(self::$_pluginBroker->getPlugins()));
     X_Debug::i("Plugins registered: {$pluginlist}");
     $helperlist = implode(', ', array_keys(self::$_helperBroker->getHelpers()));
     X_Debug::i("Helpers registered: {$helperlist}");
     self::$_pluginBroker->gen_afterPluginsInitialized(self::$_pluginBroker);
 }
示例#27
0
 private function _send($command)
 {
     $commandFull = str_replace('{%command%}', "?{$command}", $this->http_command);
     X_Debug::i(__METHOD__ . ": sending message {{$command}}: {{$commandFull}}");
     $ctx = stream_context_create(array('http' => array('timeout' => $this->http_timeout)));
     //$return = X_Env::execute($command, $outtype, X_Env::EXECUTE_PS_WAIT);
     $return = @file_get_contents($commandFull, false, $ctx);
     return $return;
 }
 /**
  *	Add button -watch megavideo stream directly-
  * 
  * @param string $provider
  * @param string $location
  * @param Zend_Controller_Action $controller
  */
 public function preGetModeItems($provider, $location, Zend_Controller_Action $controller)
 {
     if ($provider != $this->getId()) {
         return;
     }
     X_Debug::i("Plugin triggered");
     $url = $this->resolveLocation($location);
     if ($url) {
         $link = new X_Page_Item_PItem('core-directwatch', X_Env::_('p_animeland_watchdirectly'));
         $link->setIcon('/images/icons/play.png')->setType(X_Page_Item_PItem::TYPE_PLAYABLE)->setLink($url);
         return new X_Page_ItemList_PItem(array($link));
     }
 }
示例#29
0
 /**
  * Add the button BackToStream in controls page
  * 
  * @param X_Streamer_Engine $engine 
  * @param Zend_Controller_Action $controller the controller who handle the request
  * @return array
  */
 public function preGetControlItems(X_Streamer_Engine $engine, Zend_Controller_Action $controller)
 {
     // ignore if the streamer is not vlc
     if (!$engine instanceof X_Streamer_Engine_Vlc) {
         return;
     }
     X_Debug::i('Plugin triggered');
     $profileId = $controller->getRequest()->getParam($this->getId(), false);
     $urlHelper = $controller->getHelper('url');
     $outputLink = false;
     // i store the default link, so if i don't find the proper output
     // i will have a valid link for -go-to-stream- button
     //$output->setLink($this->config('default.link', "http://{$_SERVER['SERVER_ADDR']}:8081"));
     if ($profileId !== false) {
         $profile = new Application_Model_Profile();
         Application_Model_ProfilesMapper::i()->find($profileId, $profile);
         $outputLink = $profile->getLink();
     } else {
         // if store session is enabled, i try to get last output
         // method from store
         // else i fallback to best selection
         try {
             if ($this->config('store.session', true)) {
                 /* @var $cache X_VlcShares_Plugins_Helper_Cache */
                 $cache = $this->helpers()->helper('cache');
                 $outputLink = $cache->retrieveItem('profile::lastvlclink');
             }
         } catch (Exception $e) {
             // cache expired or cache disabled;
             X_Debug::i("Stored session not used");
         }
         if (!$outputLink) {
             X_Debug::i("Outputlink not found. Using best for this device");
             $profile = $this->getBest();
             $outputLink = $profile->getLink();
         }
     }
     $outputLink = self::prepareOutputLink($outputLink);
     $outputLink = str_replace(array('{%SERVER_IP%}', '{%SERVER_NAME%}'), array($_SERVER['SERVER_ADDR'], $_SERVER['HTTP_HOST']), $outputLink);
     $item = new X_Page_Item_PItem($this->getId(), X_Env::_('p_profiles_backstream'));
     $item->setType(X_Page_Item_PItem::TYPE_PLAYABLE)->setIcon('/images/icons/play.png')->setLink($outputLink);
     return new X_Page_ItemList_PItem(array($item));
 }
 public function streamAction()
 {
     $request = $this->getRequest();
     X_VlcShares_Plugins::broker()->gen_preProviderSelection($this);
     $provider = $request->getParam('p', false);
     if ($provider === false || !X_VlcShares_Plugins::broker()->isRegistered($provider)) {
         throw new Exception("Invalid provider");
     }
     $location = X_Env::decode($request->getParam('l', ''));
     $providerObj = X_VlcShares_Plugins::broker()->getPlugins($provider);
     // if provider is a resolver, i can use new streamer api
     if (X_VlcShares_Plugins::helpers()->streamer()->isEnabled() && $providerObj instanceof X_VlcShares_Plugins_ResolverInterface) {
         $url = $providerObj->resolveLocation($location);
         X_Debug::i("Resolved location: {{$url}}");
         // check if url is valid (resolver give null or false on error)
         if (!$url) {
             X_Debug::e("Invalid location: {$location}");
             throw new Exception("Stream location is invalid: {$url}");
         }
         $engine = X_VlcShares_Plugins::helpers()->streamer()->find($url);
         X_Debug::i("Streamer engine found: {{$engine->getId()}}");
         // automatically set the url as source param in the engine
         $engine->setSource($url);
         // NEW APIS
         // each arg is stored as in a LIFO stack. If i put top priority as first,
         // low priority args could override it. So i use an inverse priority insertion
         // register low priority args
         X_VlcShares_Plugins::broker()->preRegisterStreamerArgs($engine, $url, $provider, $location, $this);
         // register normal priority args
         X_VlcShares_Plugins::broker()->registerStreamerArgs($engine, $url, $provider, $location, $this);
         // register top priority args
         X_VlcShares_Plugins::broker()->postRegisterStreamerArgs($engine, $url, $provider, $location, $this);
         X_VlcShares_Plugins::broker()->preStartStreamer($engine, $url, $provider, $location, $this);
         $results = X_VlcShares_Plugins::broker()->canStartStreamer($engine, $url, $provider, $location, $this);
         $started = false;
         if (is_null($results) || !in_array(false, $results)) {
             X_Debug::i("Starting streamer {{$engine->getId()}}: {$engine}");
             $started = true;
             X_Streamer::i()->start($engine);
         } else {
             $pluginId = array_search(false, $results, true);
             X_Debug::f("Plugin {{$pluginId}} prevented streamer from starting...");
             //throw new Exception("Plugin {{$pluginId}} prevented streamer from starting");
         }
         X_VlcShares_Plugins::broker()->postStartStreamer($started, $engine, $url, $provider, $location, $this);
     } else {
         // otherwise i'm forced to fallback to old api
         //{{{ THIS CODE BLOCK WILL IS DEPRECATED AND WILL BE REMOVED IN 0.5.6 or 0.6
         //TODO remove in 0.5.6 or 0.6
         // each arg is stored as in a LIFO stack. If i put top priority as first,
         // low priority args could override it. So i use an inverse priority insertion
         // register low priority args
         X_VlcShares_Plugins::broker()->preRegisterVlcArgs($this->vlc, $provider, $location, $this);
         // register normal priority args
         X_VlcShares_Plugins::broker()->registerVlcArgs($this->vlc, $provider, $location, $this);
         // register top priority args
         X_VlcShares_Plugins::broker()->postRegisterVlcArgs($this->vlc, $provider, $location, $this);
         X_VlcShares_Plugins::broker()->preSpawnVlc($this->vlc, $provider, $location, $this);
         $this->vlc->spawn();
         X_VlcShares_Plugins::broker()->postSpawnVlc($this->vlc, $provider, $location, $this);
         try {
             $engine = X_VlcShares_Plugins::helpers()->streamer()->get('vlc');
         } catch (Exception $e) {
             X_Debug::w('No vlc streamer available');
             $engine = new X_Streamer_Engine_Vlc($this->vlc);
         }
         $url = $this->vlc->getArg('source');
         //}}}
     }
     $pageItems = new X_Page_ItemList_PItem();
     // i can't add here the go to play button
     // because i don't know the output type
     // i need to leave this to the plugins, too
     // i hope that an output manager plugin
     // will be always enabled
     // top links
     $pageItems->merge(X_VlcShares_Plugins::broker()->preGetStreamItems($engine, $url, $provider, $location, $this));
     // normal links
     $pageItems->merge(X_VlcShares_Plugins::broker()->getStreamItems($engine, $url, $provider, $location, $this));
     // bottom links
     $pageItems->merge(X_VlcShares_Plugins::broker()->postGetStreamItems($engine, $url, $provider, $location, $this));
     // trigger for page creation
     X_VlcShares_Plugins::broker()->gen_afterPageBuild($pageItems, $this);
 }