Beispiel #1
0
// Sanity checks
OCP\JSON::callCheck ( );
OCP\JSON::checkLoggedIn ( );
OCP\JSON::checkAppEnabled ( 'shorty' );

try
{
	$p_id      = OC_Shorty_Tools::shorty_id ( );
	$p_status  = OC_Shorty_Type::req_argument ( 'status',  OC_Shorty_Type::STATUS, FALSE );
	$p_title   = OC_Shorty_Type::req_argument ( 'title',   OC_Shorty_Type::STRING, FALSE );
	$p_target  = OC_Shorty_Type::req_argument ( 'target',  OC_Shorty_Type::URL,    TRUE  );
	$p_until   = OC_Shorty_Type::req_argument ( 'until',   OC_Shorty_Type::DATE,   FALSE );
	$p_notes   = OC_Shorty_Type::req_argument ( 'notes',   OC_Shorty_Type::STRING, FALSE );
	$p_favicon = OC_Shorty_Type::req_argument ( 'favicon', OC_Shorty_Type::URL,    FALSE );
	// register shorty at backend
	$p_source = OC_Shorty_Backend::registerUrl ( $p_id );
	// fallback title: choose hostname if no title is specified
	$p_title = $p_title ? trim($p_title) : parse_url($p_target,PHP_URL_HOST);
	// insert new shorty into our database
	$param = array
	(
		':user'    => OCP\User::getUser(),
		':id'      => $p_id,
		':status'  => $p_status  ?        $p_status          : '',
		':title'   => $p_title   ? substr($p_title,  0,1024) : '',
		':favicon' => $p_favicon ? substr($p_favicon,0,1024) : '',
		':source'  => $p_source  ?        $p_source          : '',
		':target'  => $p_target  ? substr($p_target, 0,4096) : '',
		':notes'   => $p_notes   ? substr($p_notes,  0,4096) : '',
		':until'   => $p_until   ?        $p_until           : null,
	);
	/**
	* @method OC_Shorty_Backend::registerUrl
	* @brief Wrapper function around the specific backend routines
	* @param string id: Internal shorty id used to reference a shorty upon usage.
	* @return string: The shortened url as generated by a specific backend.
	* @throws OC_Shorty_Exception taking over the explaining of the failure from the specific backend
	* @access public
	* @author Christian Reiner
	*/
	static function registerUrl ( $id )
	{
		try
		{
			// construct the $relay, the url to be called to reach THIS service (ownclouds shorty plugin)
			$relay = OC_Shorty_Tools::relayUrl ( $id );
			// call backend specific work horse
			switch ( $type=OCP\Config::getUserValue(OCP\User::getUser(),'shorty','backend-type',
			                                        OCP\Config::getAppValue('shorty','backend-default','none')) )
			{
				default:
					return OC_Shorty_Backend::registerUrl_default ( $id, $relay );

				case 'static':
					return OC_Shorty_Backend::registerUrl_static  ( $id, $relay );

				case 'bitly':
					return OC_Shorty_Backend::registerUrl_bitly   ( $id, $relay );

				case 'cligs':
					return OC_Shorty_Backend::registerUrl_cligs   ( $id, $relay );

				case 'google':
					return OC_Shorty_Backend::registerUrl_google  ( $id, $relay );

				case 'isgd':
					return OC_Shorty_Backend::registerUrl_isgd    ( $id, $relay );

				case 'tinyurl':
					return OC_Shorty_Backend::registerUrl_tinyurl ( $id, $relay );

				case 'tinycc':
					return OC_Shorty_Backend::registerUrl_tinycc  ( $id, $relay );
			} // switch
		} // try
		catch (OC_Shorty_Exception $e)
		{
			throw $e;
		} // catch
		catch (Exception $e)
		{
			throw new OC_Shorty_Exception ( "Failed to register url '%s' at '%s' backend.", array($relay,$type) );
		} // catch
	} // OC_Shorty_Backend::registerUrl