예제 #1
0
	function validateUserPreferences($prefs) {
		$errorList = array();
		
		# Definieer een aantal arrays met valid settings
		$validDateFormats = array('human', '%a, %d-%b-%Y (%H:%M)', '%d-%m-%Y (%H:%M)');
		$validTemplates = array('we1rdo');
		
		# Controleer de per page setting
		$prefs['perpage'] = (int) $prefs['perpage'];
		if (($prefs['perpage'] < 2) || ($prefs['perpage'] > 250)) {
			$errorList[] = array('validateuser_invalidpreference', array('perpage'));
		} # if
		
		# Controleer basis settings
		if (in_array($prefs['date_formatting'], $validDateFormats) === false) {
			$errorList[] = array('validateuser_invalidpreference', array('date_formatting')); 
		} # if
		
		if (in_array($prefs['template'], $validTemplates) === false) { 	
			$errorList[] = array('validateuser_invalidpreference', array('template'));
		} # if
		
		# als er een sabnzbd host opgegeven is, moet die geldig zijn
		if ( ($prefs['nzbhandling']['action'] == 'client-sabnzbd') || ($prefs['nzbhandling']['action'] == 'push-sabnzbd') ) {
			$tmpHost = parse_url($prefs['nzbhandling']['sabnzbd']['url']);
			
			if ( ($tmpHost === false) | (!isset($tmpHost['scheme'])) || (($tmpHost['scheme'] != 'http') && ($tmpHost['scheme'] != 'https')) ) {
				$errorList[] = array('validateuser_invalidpreference', array('sabnzbd url'));
			} # if
			
			# SABnzbd URL moet altijd eindigen met een slash
			if(substr($prefs['nzbhandling']['sabnzbd']['url'], -1) !== '/') {
				$prefs['nzbhandling']['sabnzbd']['url'] .= '/';
			} # if
		} # if

		# converteer overige settings naar boolean zodat we gewoon al weten wat er uitkomt
		$prefs['count_newspots'] = (isset($prefs['count_newspots'])) ? true : false;
		$prefs['keep_seenlist'] = (isset($prefs['keep_seenlist'])) ? true : false;
		$prefs['auto_markasread'] = (isset($prefs['auto_markasread'])) ? true : false;
		$prefs['keep_downloadlist'] = (isset($prefs['keep_downloadlist'])) ? true : false;
		$prefs['keep_watchlist'] = (isset($prefs['keep_watchlist'])) ? true : false;
		$prefs['show_filesize'] = (isset($prefs['show_filesize'])) ? true : false;
		$prefs['show_multinzb'] = (isset($prefs['show_multinzb'])) ? true : false;
		
		$notifProviders = Notifications_Factory::getFutureServices();
		foreach ($notifProviders as $notifProvider) {
			$prefs['notifications'][$notifProvider]['enabled'] = (isset($prefs['notifications'][$notifProvider]['enabled'])) ? true : false;
			$prefs['notifications'][$notifProvider]['events']['nzb_handled'] = (isset($prefs['notifications'][$notifProvider]['events']['nzb_handled'])) ? true : false;
			$prefs['notifications'][$notifProvider]['events']['retriever_finished'] = (isset($prefs['notifications'][$notifProvider]['events']['retriever_finished'])) ? true : false;
			$prefs['notifications'][$notifProvider]['events']['user_added'] = (isset($prefs['notifications'][$notifProvider]['events']['user_added'])) ? true : false;
		}

		# We willen geen megabytes aan custom CSS opslaan, dus controleer dat dit niet te groot is
		if (strlen($prefs['customcss'] > 1024 * 10)) { 
			$errorList[] = array('validateuser_invalidpreference', array('customcss'));
		} # if		
		
		# als men runcommand of save wil, moet er een local_dir opgegeven worden
		if (($prefs['nzbhandling']['action'] == 'save') || ($prefs['nzbhandling']['action'] == 'runcommand')) {
			if (empty($prefs['nzbhandling']['local_dir'])) {
				$errorList[] = array('validateuser_invalidpreference', array('local_dir'));
			} # if
		} # if

		# als men Growl wil gebruiken, moet er een host opgegeven worden
		if ($prefs['notifications']['growl']['enabled']) {
			if (empty($prefs['notifications']['growl']['host'])) {
				$errorList[] = array('validateuser_invalidpreference', array('growl host'));
			} # if
		} # if

		# als men Notifo wil gebruiken, moet er een username & apikey opgegeven worden
		if ($prefs['notifications']['notifo']['enabled']) {
			if (empty($prefs['notifications']['notifo']['username'])) {
				$errorList[] = array('validateuser_invalidpreference', array('notifo username'));
			} # if
			if (empty($prefs['notifications']['notifo']['api'])) {
				$errorList[] = array('validateuser_invalidpreference', array('notifo api'));
			} # if
		} # if

		# als men Prowl wil gebruiken, moet er een apikey opgegeven worden
		if ($prefs['notifications']['prowl']['enabled']) {
			if (empty($prefs['notifications']['prowl']['apikey'])) {
				$errorList[] = array('validateuser_invalidpreference', array('prowl apikey'));
			} # if
		} # if

		return array($errorList, $prefs);
	} # validateUserPreferences
예제 #2
0
	function updateUserPreferences() {
		$userList = $this->_db->listUsers("", 0, 9999999);

		# loop through every user and fix it 
		foreach($userList['list'] as $user) {
			# Omdat we vanuit listUsers() niet alle velden meekrijgen
			# vragen we opnieuw het user record op
			$user = $this->_db->getUser($user['userid']);

			# set the users' preferences
			$this->setSettingIfNot($user['prefs'], 'perpage', 25);
			$this->setSettingIfNot($user['prefs'], 'date_formatting', 'human');
			$this->setSettingIfNot($user['prefs'], 'template', 'we1rdo');
			$this->setSettingIfNot($user['prefs'], 'count_newspots', true);
			$this->setSettingIfNot($user['prefs'], 'keep_seenlist', true);
			$this->setSettingIfNot($user['prefs'], 'auto_markasread', true);
			$this->setSettingIfNot($user['prefs'], 'keep_downloadlist', true);
			$this->setSettingIfNot($user['prefs'], 'keep_watchlist', true);
			$this->setSettingIfNot($user['prefs'], 'nzb_search_engine', 'nzbindex');
			$this->setSettingIfNot($user['prefs'], 'show_filesize', true);
			$this->setSettingIfNot($user['prefs'], 'show_multinzb', true);
			$this->setSettingIfNot($user['prefs'], 'customcss', '');

			$this->setSettingIfNot($user['prefs']['nzbhandling'], 'action', 'disable');
			$this->setSettingIfNot($user['prefs']['nzbhandling'], 'local_dir', '/tmp');
			$this->setSettingIfNot($user['prefs']['nzbhandling'], 'prepare_action', 'merge');
			$this->setSettingIfNot($user['prefs']['nzbhandling'], 'command', '');
			$this->setSettingIfNot($user['prefs']['nzbhandling']['sabnzbd'], 'url', '');
			$this->setSettingIfNot($user['prefs']['nzbhandling']['sabnzbd'], 'apikey', '');
			$this->setSettingIfNot($user['prefs']['nzbhandling']['nzbget'], 'host', '');
			$this->setSettingIfNot($user['prefs']['nzbhandling']['nzbget'], 'port', '');
			$this->setSettingIfNot($user['prefs']['nzbhandling']['nzbget'], 'username', '');
			$this->setSettingIfNot($user['prefs']['nzbhandling']['nzbget'], 'password', '');
			$this->setSettingIfNot($user['prefs']['nzbhandling']['nzbget'], 'timeout', 15);

			$this->setSettingIfNot($user['prefs']['notifications']['growl'], 'host', '');
			$this->setSettingIfNot($user['prefs']['notifications']['growl'], 'password', '');
			$this->setSettingIfNot($user['prefs']['notifications']['notifo'], 'username', '');
			$this->setSettingIfNot($user['prefs']['notifications']['notifo'], 'api', '');
			$this->setSettingIfNot($user['prefs']['notifications']['prowl'], 'apikey', '');
			$notifProviders = Notifications_Factory::getFutureServices();
			foreach ($notifProviders as $notifProvider) {
				$this->setSettingIfNot($user['prefs']['notifications'][$notifProvider], 'enabled', false);
				$this->setSettingIfNot($user['prefs']['notifications'][$notifProvider]['events'], 'nzb_handled', false);
				$this->setSettingIfNot($user['prefs']['notifications'][$notifProvider]['events'], 'retriever_finished', false);
				$this->setSettingIfNot($user['prefs']['notifications'][$notifProvider]['events'], 'user_added', false);		
			} // foreach

			# oude settings verwijderen
			$this->unsetSetting($user['prefs'], 'search_url');

			# update the user record in the database			
			$this->_db->setUser($user);
		} # foreach
	} # update()