// is this a redirect from a call with a target url to be added ?
			if ( isset($_SESSION['shorty-referrer']) )
			{
				// this takes care of handling the url on the client side
				OCP\Util::addScript ( 'shorty', 'add' );
				// add url taked from the session vars to anything contained in the query string
				$_SERVER['QUERY_STRING'] = implode('&',array_merge(array('url'=>$_SESSION['shorty-referrer']),explode('&',$_SERVER['QUERY_STRING'])));
			}
			else
			{
				// simple desktop initialization, no special actions contained
				OCP\Util::addScript ( 'shorty', 'list' );
			}
			$tmpl = new OCP\Template( 'shorty', 'tmpl_index', 'user' );
			// any additional actions registered via hooks that should be offered ?
			$tmpl->assign ( 'shorty-actions', OC_Shorty_Hooks::requestActions() );
			// the (remote) base url of the qrcode generator
			$tmpl->assign ( 'qrcode-ref', sprintf('%s?service=%s&id=',  OCP\Util::linkToAbsolute('', 'public.php'), 'shorty_qrcode') );
			// available status options (required for select filter in toolbox)
			$shorty_status['']=sprintf('- %s -',OC_Shorty_L10n::t('all'));
			foreach ( OC_Shorty_Type::$STATUS as $status )
				$shorty_status[$status] = OC_Shorty_L10n::t($status);
			$tmpl->assign ( 'shorty-status', $shorty_status );
			$tmpl->assign ( 'default-status', OCP\Config::getUserValue(OCP\User::getUser(),'shorty','default-status','private') );
			// any referrer we want to hand over to the browser ?
			if ( array_key_exists('shorty-referrer',$_SESSION) )
				$tmpl->assign ( 'shorty-referrer', $_SESSION['shorty-referrer'] );
			// is sending sms enabled in the personal preferences ?
			$tmpl->assign ( 'sms-control', OCP\Config::getUserValue(OCP\User::getUser(),'shorty','sms-control','disabled') );
			// clean up session var so that a browser reload does not trigger the same action again
			\OC::$session->remove('shorty-referrer');
{
	$p_id      = OC_Shorty_Type::req_argument ( 'id',     OC_Shorty_Type::ID,     FALSE );
	$p_query   = OC_Shorty_Type::req_argument ( 'query',  OC_Shorty_Type::STRING, FALSE );
	$p_format  = OC_Shorty_Type::req_argument ( 'format', OC_Shorty_Type::STRING, FALSE );
	$p_sort    = OC_Shorty_Type::req_argument ( 'sort',   OC_Shorty_Type::STRING, 'ka' );
	$param = array (
		':user'   => OCP\User::getUser ( ),
		':id'     => $p_id,
		':sort'   => OC_Shorty_Type::$SORTING[$p_sort],
		':format' => $p_format,
		':sort'   => $p_sort,
		':query'  => $p_query,
	);

	$match = NULL;
	$candidates = OC_Shorty_Hooks::requestQueries();
	foreach ($candidates['list'] as $candidate)
		if ($candidate['id']==$p_query)
			$match = $candidate;
	if ( ! $match )
		throw new OC_Shorty_Exception ( "Request for unknown query '%1'.", array($p_query) );

	// run query
	$query = OCP\DB::prepare ( $match['query'] );
	$result = $query->execute(array_intersect($param,$match['param']));
	$reply = $result->fetchAll();

	// swallow any accidential output generated by php notices and stuff to preserve a clean JSON reply structure
	OC_Shorty_Tools::ob_control ( FALSE );

	// output payload
					elseif ( ! OCP\User::checkPassword($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) )
					{
						// second, authenticated attempt, request repeated authentication
						header('WWW-Authenticate: Basic realm="Retry OwnCloud relay authorization"');
						header('HTTP/1.0 401 Unauthorized');
						// important: flush, so that auth headers are not swallowed by OC
						flush(); ob_flush();
						// log denied access attempt
						OC_Shorty_Hooks::registerClick ( $result[0], $request, 'failed' );
						// fallback: refuse forwarding => 403: Forbidden
						throw new OC_Shorty_HttpException ( 403 );
					}
				}
				break;

				case 'public':
				// no access restriction, so all fine!
		} // switch status

		// finish this script to record the click, even if the client detaches right after the redirect
		ignore_user_abort ( TRUE );
		// register click
		OC_Shorty_Hooks::registerClick ( $result[0], $request, 'granted' );
		// forward to target, regardless of who sends the request
		header("HTTP/1.0 301 Moved Permanently");
		// http forwarding header
		header ( sprintf('Location: %s', $target) );
	} // if id
} catch ( OC_Shorty_Exception $e ) { header($e->getMessage()); }
?>
 * The dialog will be included in the general framework of the system settings page
 * @access public
 * @author Christian Reiner
 */

// session checks
OCP\User::checkLoggedIn  ( );
OCP\User::checkAdminUser ( );
OCP\App::checkAppEnabled ( 'shorty' );

$RUNTIME_NOSETUPFS = true;

OCP\Util::addStyle  ( 'shorty',   'settings' );

OCP\Util::addScript ( '3rdparty', 'chosen/chosen.jquery.min' );
OCP\Util::addScript ( 'shorty',   'shorty' );
OCP\Util::addScript ( 'shorty',   'util' );
OCP\Util::addScript ( 'shorty',   'settings' );
if ( OCP\Util::DEBUG==OCP\Config::getAppValue( "loglevel", OCP\Util::WARN ) )
	OCP\Util::addScript ( 'shorty',  'debug' );

// fetch template
$tmpl = new OCP\Template ( 'shorty', 'tmpl_settings' );
// inflate template
$tmpl->assign ( 'shorty-plugins',      OC_Shorty_Hooks::requestDetails() );
$tmpl->assign ( 'backend-default',     OCP\Config::getAppValue('shorty','backend-default','none') );
$tmpl->assign ( 'backend-static-base', OCP\Config::getAppValue('shorty','backend-static-base','') );
// render template
return $tmpl->fetchPage ( );
?>