public function parse($string) { $parsed = array(); switch ($this->function) { case self::PREG_MATCH: if (@preg_match($this->pattern, $string, $parsed, $this->flags) === false) { X_Debug::w("Invalid pattern (" . preg_last_error() . "): {$this->pattern}"); $parsed = array(); } break; case self::PREG_MATCH_ALL: if (@preg_match_all($this->pattern, $string, $parsed, $this->flags) === false) { X_Debug::w("Invalid pattern (" . preg_last_error() . "): {$this->pattern}"); $parsed = array(); } break; case self::PREG_SPLIT: $parsed = @preg_split($this->pattern, $string, null, $this->flags); if ($parsed === false) { X_Debug::w("Invalid pattern (" . preg_last_error() . "): {$this->pattern}"); $parsed = array(); } break; default: X_Debug::e("Invalid function code provided: {$this->function}"); } return $parsed; }
/** * 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 spawn($threadId) { $http = new Zend_Http_Client($this->url, array('timeout' => 3, 'keepalive' => false)); $i = 20; do { if ($i-- < 0) { throw new Exception("To many hash generation failed"); } $salt = rand(1, 1000); $key = time(); $privKey = rand(100000, 999999); $hash = md5("{$salt}{$privKey}{$key}"); } while (!$this->storeRequestKey($hash, $privKey)); $http->setParameterPost('hash', $hash)->setParameterPost('key', $key)->setParameterPost('salt', $salt)->setParameterPost('thread', $threadId); try { $body = $http->request(Zend_Http_Client::POST)->getBody(); $response = @Zend_Json::decode($body); if ($response) { return @$response['success']; } } catch (Exception $e) { // timeout // don't know, assume true X_Debug::w("Request timeout"); return true; } }
/** * 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; }
public function errorAction() { $errors = $this->_getParam('error_handler'); switch ($errors->type) { case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE: case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER: case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION: // 404 error -- controller or action not found $this->getResponse()->setHttpResponseCode(404); $this->view->message = 'Page not found'; break; default: // application error $this->getResponse()->setHttpResponseCode(500); $this->view->message = 'Application error'; break; } /* // Log exception, if logger available if ($log = $this->getLog()) { $log->crit($this->view->message, $errors->exception); } */ X_Debug::f($this->view->message . ": " . $errors->exception->getMessage()); X_Debug::f($errors->exception->getTraceAsString()); // conditionally display exceptions //if ($this->getInvokeArg('displayExceptions') == true ) { $this->view->exception = $errors->exception; //} $this->view->request = $errors->request; }
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'); }
/** * 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)); }
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 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); } }
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); } } }
/** * Init debug system * @param string $logPath path for debug log * @param int $logLevel level of debug is allowed from */ public static function init($logPath, $logLevel = self::LVL_FATAL) { if (!is_null(self::$logFile)) { fclose(self::$logFile); } self::$logFile = fopen($logPath, 'ab'); self::$logPath = $logPath; self::$logLevel = $logLevel; self::forcedInfo("------------------------------------------------------"); self::forcedInfo("Debug log enabled, level: {$logLevel}"); }
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 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'); } }
/** * 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 __construct(X_Vlc $vlcInstance = null) { if (is_null($vlcInstance)) { $vlcInstance = X_Vlc::getLastInstance(); // OMG OMG no } if (is_null($vlcInstance)) { // check again X_Debug::e("Streamer engine VLC without a vlc instance available"); throw new Exception("No X_Vlc instance available"); } $this->vlc = $vlcInstance; }
public function parse($string) { $parsed = array(); if ($this->namespace) { $parsed = simplexml_load_string($string, "SimpleXMLElement", 0, $this->namespace); } else { $parsed = simplexml_load_string($string); } if ($parsed === false) { X_Debug::e("simplexml_load_string return error: invalid string"); $parsed = array(); } return $parsed; }
/** * get the resource ID for the hoster * from an $url * @param string $url the hoster page * @return string the resource id */ function getResourceId($url) { $matches = array(); if (preg_match(self::PATTERN, $url, $matches)) { if ($matches['ID'] != '') { return $matches['ID']; } X_Debug::e("No id found in {{$url}}", self::E_ID_NOTFOUND); throw new Exception("No id found in {{$url}}"); } else { X_Debug::e("Regex failed"); throw new Exception("Regex failed", self::E_URL_INVALID); } }
/** * Retrieve news from plugins * @param Zend_Controller_Action $this * @return X_Page_ItemList_News */ public function getIndexNews(Zend_Controller_Action $controller) { try { $view = $controller->getHelper('viewRenderer'); $view->view->headScript()->appendFile('http://www.google.com/jsapi'); $view->view->headScript()->appendFile($view->view->baseUrl("/js/widgetdevnews/script.js")); $view->view->headLink()->appendStylesheet($view->view->baseUrl('/css/widgetdevnews/style.css')); $text = (include dirname(__FILE__) . '/WidgetDevNews.commits.phtml'); $item = new X_Page_Item_News($this->getId(), ''); $item->setTab(X_Env::_('p_widgetdevnews_commits_tab'))->setContent($text); return new X_Page_ItemList_News(array($item)); } catch (Exception $e) { X_Debug::e('No view O_o'); } }
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()}"); } }
/** * 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)); } }
public function addTranslation($key) { $moduleName = $key . '.' . $this->lang; // i have to check $moduleName to be sure that the file is inside the languages/ directory if (file_exists(realpath(APPLICATION_PATH . "/../languages/{$moduleName}"))) { $translate = new Zend_Translate('ini', realpath(APPLICATION_PATH . "/../languages/{$moduleName}")); } elseif ($this->lang != 'en_GB.ini' && file_exists(realpath(APPLICATION_PATH . "/../languages/{$key}.en_GB.ini"))) { // fallback to english translation X_Debug::w("Language file not found: {$moduleName}. Falling back to english translation"); $translate = new Zend_Translate('ini', realpath(APPLICATION_PATH . "/../languages/{$key}.en_GB.ini")); } else { X_Debug::w("Language file not found: {$moduleName}"); return false; } // time to append translator to the global instance X_Env::initTranslator($translate); return true; }
/** * (non-PHPdoc) * @see X_PageParser_Parser::parse() */ public function parse($string) { $matches = array(); if (!preg_match(self::PATTERN_MAIN, $string, $matches)) { X_Debug::e('Main pattern failed'); return array(); } $string = $matches['main']; $string = str_replace(array('\\n', '\\u003c', '\\u003e'), array('', '<', '>'), $string); $string = stripslashes($string); //X_Debug::i("Decoded string: {$string}"); $matches = array(); if (!preg_match_all(self::PATTERN_ITEMS, $string, $matches, PREG_SET_ORDER)) { X_Debug::e('Items pattern failed: {' . preg_last_error() . '}'); return array(); } return $matches; }
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); }
protected function dispatchRequest(Zend_Controller_Request_Http $request, X_Page_ItemList_PItem $items, Zend_Controller_Action $controller) { /* @var $view Zend_Controller_Action_Helper_ViewRenderer */ $view = $controller->getHelper('viewRenderer'); /* @var $layout Zend_Layout_Controller_Action_Helper_Layout */ $layout = $controller->getHelper('layout'); try { $view->setNoRender(true); $layout->disableLayout(); } catch (Exception $e) { X_Debug::e("Layout or View not enabled: " . $e->getMessage()); } $result = array(); $actionName = $request->getActionName(); $controllerName = $request->getControllerName(); $result['controller'] = $controllerName; $result['action'] = $actionName; $result['success'] = true; $result['items'] = array(); /* @var $urlHelper Zend_Controller_Action_Helper_Url */ $urlHelper = $controller->getHelper('url'); $skipMethod = array('getCustom', 'getLinkParam', 'getLinkAction', 'getLinkController'); foreach ($items->getItems() as $itemId => $item) { /* @var $item X_Page_Item_PItem */ $aItem = array(); $methods = get_class_methods(get_class($item)); foreach ($methods as $method) { if (array_search($method, $skipMethod) !== false) { continue; } if ($method == "getIcon") { $aItem['icon'] = $request->getBaseUrl() . $item->getIcon(); } elseif (X_Env::startWith($method, 'get')) { $aItem[lcfirst(substr($method, 3))] = $item->{$method}(); } elseif (X_Env::startWith($method, 'is')) { $aItem[lcfirst(substr($method, 2))] = $item->{$method}(); } } $result['items'][] = $aItem; } /* @var $jsonHelper Zend_Controller_Action_Helper_Json */ $jsonHelper = $controller->getHelper('Json'); $jsonHelper->direct($result, true, false); }