function handleNzbAction($messageIds, array $currentSession, $action, Services_Providers_FullSpot $svcProvSpot, Services_Providers_Nzb $svcProvNzb) { if (!is_array($messageIds)) { $messageIds = array($messageIds); } # if # Make sure the user has the appropriate permissions $currentSession['security']->fatalPermCheck(SpotSecurity::spotsec_retrieve_nzb, ''); if ($action != 'display') { $currentSession['security']->fatalPermCheck(SpotSecurity::spotsec_download_integration, $action); } # if /* * Get all the full spots for all of the specified NZB files */ $nzbList = array(); $fullSpot = array(); foreach ($messageIds as $thisMsgId) { $fullSpot = $svcProvSpot->fetchFullSpot($thisMsgId, $currentSession['user']['userid']); if (!empty($fullSpot['nzb'])) { $nzbList[] = array('spot' => $fullSpot, 'nzb' => $svcProvNzb->fetchNzb($fullSpot)); } # if } # foreach /* * send nzblist to NzbHandler plugin */ $nzbHandlerFactory = new Services_NzbHandler_Factory(); $nzbHandler = $nzbHandlerFactory->build($this->_settings, $action, $currentSession['user']['prefs']['nzbhandling']); $nzbHandler->processNzb($fullSpot, $nzbList); /* * and mark the spot as downloaded */ if ($currentSession['user']['prefs']['keep_downloadlist']) { if ($currentSession['security']->allowed(SpotSecurity::spotsec_keep_own_downloadlist, '')) { $spotStateListDao = $this->_daoFactory->getSpotStateListDao(); foreach ($messageIds as $thisMsgId) { $spotStateListDao->addToDownloadList($thisMsgId, $currentSession['user']['userid']); } # foreach } # if } # if # and send notifications $spotsNotifications = new SpotNotifications($this->_daoFactory, $this->_settings, $currentSession); $spotsNotifications->sendNzbHandled($action, $fullSpot); }
function __construct(Services_Settings_Container $settings, $currentSession, Dao_Factory $daoFactory, $params) { $this->_settings = $settings; $this->_currentSession = $currentSession; $this->_daoFactory = $daoFactory; $this->_spotSec = $currentSession['security']; $this->_params = $params; # We initialiseren hier een NzbHandler object om te voorkomen # dat we voor iedere spot een nieuw object initialiseren, een property # zou mooier zijn, maar daar is PHP dan weer te traag voor $nzbHandlerFactory = new Services_NzbHandler_Factory(); if (isset($currentSession['user']['prefs']['nzbhandling'])) { $this->_nzbHandler = $nzbHandlerFactory->build($settings, $currentSession['user']['prefs']['nzbhandling']['action'], $currentSession['user']['prefs']['nzbhandling']); } # if }
function render() { # Make sure the user has the appropriate permissions $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_use_sabapi, ''); $apikey = $this->_currentSession['user']['apikey']; if ($this->_tplHelper->apiToHash($apikey) != $this->_params['nzbhandlerapikey']) { error_log('API Key Incorrect'); echo 'API Key Incorrect'; return; } # if $nzbHandlerFactory = new Services_NzbHandler_Factory(); $this->_nzbHandler = $nzbHandlerFactory->build($this->_settings, $this->_currentSession['user']['prefs']['nzbhandling']['action'], $this->_currentSession['user']['prefs']['nzbhandling']); if ($this->_nzbHandler->hasApiSupport() !== false) { $action = strtolower($this->_params['action']); switch ($action) { # actions on the entire queue case 'getstatus': $result = $this->_nzbHandler->getStatus(); break; case 'pausequeue': $result = $this->_nzbHandler->pauseQueue(); break; case 'resumequeue': $result = $this->_nzbHandler->resumeQueue(); break; case 'setspeedlimit': $result = $this->_nzbHandler->setSpeedLimit($this->_params['limit']); break; # actions on a specific download # actions on a specific download case 'movedown': $result = $this->_nzbHandler->moveDown($this->_params['id']); break; case 'moveup': $result = $this->_nzbHandler->moveUp($this->_params['id']); break; case 'movetop': $result = $this->_nzbHandler->moveTop($this->_params['id']); break; case 'movebottom': $result = $this->_nzbHandler->moveBottom($this->_params['id']); break; case 'setcategory': $result = $this->_nzbHandler->setCategory($this->_params['id'], $this->_params['category']); break; case 'setpriority': $result = $this->_nzbHandler->setPriority($this->_params['id'], $this->_params['priority']); break; case 'setpassword': $result = $this->_nzbHandler->setPassword($this->_params['id'], $this->_params['password']); break; case 'delete': $result = $this->_nzbHandler->delete($this->_params['id']); break; case 'rename': $result = $this->_nzbHandler->rename($this->_params['id'], $this->_params['name']); break; case 'pause': $result = $this->_nzbHandler->pause($this->_params['id']); break; case 'resume': $result = $this->_nzbHandler->resume($this->_params['id']); break; # non download related actions # non download related actions case 'getcategories': $result = $this->_nzbHandler->getBuiltinCategories(); break; case 'getversion': $tmp = $this->_nzbHandler->getVersion(); if ($tmp === false) { $result = false; } else { $result['version'] = $tmp; } break; default: # default action $result = false; } } else { error_log('The configured NZB handler has no api support'); echo 'The configured NZB handler has no api support'; return; } # do not cache the nzbhandlerapi's output $this->sendExpireHeaders(true); $this->sendContentTypeHeader('json'); if ($result === true || $result === false) { $tmp['result'] = $result; $result = $tmp; } $result = json_encode($result); echo $result; }