コード例 #1
0
OCP\JSON::checkAppEnabled ( 'shorty' );

try
{
	$data = array();
	switch ( $_SERVER['REQUEST_METHOD'] )
	{
		case 'POST':
			// detect provided preferences
			$data = array();
			foreach (array_keys($_POST) as $key)
			{
				if ( isset(OC_Shorty_Type::$PREFERENCE[$key]) ) // ignore unknown preference keys
				{
					$type = OC_Shorty_Type::$PREFERENCE[$key];
					$data[$key] = OC_Shorty_Type::req_argument ( $key, $type, FALSE );
				}
			}
			// store settings
			foreach ( $data as $key=>$val )
				OCP\Config::setUserValue( OCP\User::getUser(), 'shorty', $key, $val );
			// swallow any accidential output generated by php notices and stuff to preserve a clean JSON reply structure
			OC_Shorty_Tools::ob_control ( FALSE );
			OCP\Util::writeLog( 'shorty', sprintf("Preference '%s' saved",implode(',',array_keys($data))), OCP\Util::DEBUG );
			OCP\JSON::success (
				array (
					'data'    => $data,
					'level'   => 'debug',
 					'message' => OC_Shorty_L10n::t("Preference '%s' saved",implode(',',array_keys($data)))
				)
			);
コード例 #2
0
			break;

		case 'id':
		case 'shorty':
			// this looks like the request refers to a Shortys ID, lets see if we know that one
			$id     = OC_Shorty_Type::req_argument($key,OC_Shorty_Type::ID,FALSE);
			$param  = array ( ':id' => OC_Shorty_Type::normalize($id,OC_Shorty_Type::ID) );
			$query  = OCP\DB::prepare ( OC_Shorty_Query::URL_BY_ID );
			break 2; // skip switch AND foreach, we have all details we need...
		case 'url':
		case 'uri':
		case 'ref':
		case 'source':
		case 'target':
			// this looks like the request refers to a full url, lets see if we know that one as a Shortys source
			$source = OC_Shorty_Type::req_argument($key,OC_Shorty_Type::URL,FALSE);
			$param  = array ( ':source' => OC_Shorty_Type::normalize($source,OC_Shorty_Type::URL) );
			$query  = OCP\DB::prepare ( OC_Shorty_Query::URL_BY_SOURCE );
			break 2; // skip switch AND foreach, we have all details we need...
	} // switch
} // foreach

// generate qrcode for the specified id/url, IF it exists and has not expired in the database
try
{
	if ( $query )
	{
		$result = $query->execute($param)->FetchAll();
		if ( FALSE===$result )
			throw new OC_Shorty_HttpException ( 500 );
		elseif ( ! is_array($result) )
コード例 #3
0
ファイル: meta.php プロジェクト: ArcherSys/ArcherSysOSCloud7
 * @return json: success/error state indicator
 * @return array: Associative array of meta data aspects
 * @author Christian Reiner
 */

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

//no apps or filesystem
$RUNTIME_NOSETUPFS = true;

// Sanity checks
OCP\JSON::callCheck ( );
OCP\JSON::checkLoggedIn ( );
OCP\JSON::checkAppEnabled ( 'shorty' );

try
{
	$target  = OC_Shorty_Type::req_argument ( 'target', OC_Shorty_Type::URL, TRUE );
	$meta    = OC_Shorty_Meta::fetchMetaData(htmlspecialchars_decode($target));

	// swallow any accidential output generated by php notices and stuff to preserve a clean JSON reply structure
	OC_Shorty_Tools::ob_control ( FALSE );
	OCP\Util::writeLog( 'shorty', sprintf("Target meta data retrieved for url '%s'.",$target), OCP\Util::DEBUG );
	OCP\JSON::success ( array (
		'data'    => $meta,
		'level'   => 'info',
		'message' => OC_Shorty_L10n::t("Target url '%s' is valid", $meta['target']) ) );
} catch ( Exception $e ) { OC_Shorty_Exception::JSONerror($e); }
?>
コード例 #4
0
// swallow any accidential output generated by php notices and stuff to preserve a clean JSON reply structure
OC_Shorty_Tools::ob_control ( TRUE );

//no apps or filesystem
$RUNTIME_NOSETUPFS = true;

// Sanity checks
OCP\JSON::callCheck ( );
OCP\JSON::checkLoggedIn ( );
OCP\JSON::checkAppEnabled ( 'shorty' );

try
{
	$p_id     = OC_Shorty_Type::req_argument ( 'id',     OC_Shorty_Type::ID,     TRUE );
	$p_status = OC_Shorty_Type::req_argument ( 'status', OC_Shorty_Type::STATUS, FALSE );
	$param = array
	(
		'user'   => OCP\User::getUser ( ),
		'id'     => $p_id,
		'status' => $p_status,
	);
	$query = OCP\DB::prepare ( OC_Shorty_Query::URL_STATUS );
	$query->execute ( $param );

	// swallow any accidential output generated by php notices and stuff to preserve a clean JSON reply structure
	OC_Shorty_Tools::ob_control ( FALSE );
	OCP\Util::writeLog( 'shorty', sprintf("Status change for shorty with id '%s' saved",$p_id), OCP\Util::INFO );
	OCP\JSON::success ( array (
		'data'    => array('id'=>$p_id),
		'level'   => 'info',
コード例 #5
0
ファイル: edit.php プロジェクト: ArcherSys/ArcherSysOSCloud7
$RUNTIME_NOSETUPFS = true;

// Sanity checks
OCP\JSON::callCheck ( );
OCP\JSON::checkLoggedIn ( );
OCP\JSON::checkAppEnabled ( 'shorty' );

try
{
	$p_id      = OC_Shorty_Type::req_argument ( 'id',      OC_Shorty_Type::ID,     TRUE );
	$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,    FALSE );
	$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 );
	$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) : '',
		':target'  => $p_target  ? substr($p_target, 0,4096) : '',
		':notes'   => $p_notes   ? substr($p_notes,  0,4096) : '',
		':until'   => $p_until   ?        $p_until           : null,
	);
	$query = OCP\DB::prepare ( OC_Shorty_Query::URL_UPDATE );
	$query->execute ( $param );

	// read new entry for feedback
コード例 #6
0
ファイル: del.php プロジェクト: ArcherSys/ArcherSysOSCloud7
 */

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

//no apps or filesystem
$RUNTIME_NOSETUPFS = true;

// Sanity checks
OCP\JSON::callCheck ( );
OCP\JSON::checkLoggedIn ( );
OCP\JSON::checkAppEnabled ( 'shorty' );

try
{
	$p_id  = OC_Shorty_Type::req_argument ( 'id', OC_Shorty_Type::ID, TRUE );
	$param = array
	(
		'user' => OCP\User::getUser(),
		'id'   => $p_id,
	);
	$query = OCP\DB::prepare ( OC_Shorty_Query::URL_DELETE );
	$query->execute($param);

	// swallow any accidential output generated by php notices and stuff to preserve a clean JSON reply structure
	OC_Shorty_Tools::ob_control ( FALSE );
	OCP\Util::writeLog( 'shorty', sprintf("Deleted Shorty with id '%s'",$p_id), OCP\Util::INFO );
	OCP\JSON::success ( array (
		'data'    => array('id'=>$p_id),
		'level'   => 'info',
		'message' => OC_Shorty_L10n::t("Shorty with id '%s' deleted",$p_id) ) );
コード例 #7
0
ファイル: relay.php プロジェクト: ArcherSys/ArcherSysOSCloud7
// - a (target) url to be added as a new shorty
// - none of the two, so just a plain list of existing shortys
foreach ($_GET as $key=>$val) // in case there are unexpected, additional arguments like a timestamp added by some stupid proxy
{
	switch ($key)
	{
		default:
			// unrecognized key, we ignore it
			break;

		case 'id':
		case 'shorty':
		case 'ref':
		case 'entry':
			// a recognized argument key indicating an id to be looked up
			$arg = OC_Shorty_Type::req_argument($key,OC_Shorty_Type::ID,FALSE);
			break 2; // skip switch AND foreach
	} // switch
} // foreach

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

// now construct the target url and relay to it (if applicable)
try
{
	// has an id been specified at all ?
	if ( NULL==$arg )
	{
		// nothing to forward to => 400: Bad Request
		throw new OC_Shorty_HttpException ( 400 );
コード例 #8
0
ファイル: query.php プロジェクト: ArcherSys/ArcherSysOSCloud7
 */

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

// Session checks
OCP\App::checkAppEnabled ( 'shorty' );

$RUNTIME_NOSETUPFS = true;

try
{
	$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 )
コード例 #9
0
ファイル: click.php プロジェクト: ArcherSys/ArcherSysOSCloud7
// swallow any accidential output generated by php notices and stuff to preserve a clean JSON reply structure
OC_Shorty_Tools::ob_control ( TRUE );

//no apps or filesystem
$RUNTIME_NOSETUPFS = true;

// Sanity checks
OCP\JSON::callCheck ( );
OCP\JSON::checkLoggedIn ( );
OCP\JSON::checkAppEnabled ( 'shorty' );

try
{
	if (isset($_GET['id']))
	{
		$p_id  = OC_Shorty_Type::req_argument ( $_GET['id'], OC_Shorty_Type::ID, TRUE );
		$param = array (
			':id'   => $p_id,
			':time' => 'NOW()',
		);

		// record the click
		$query = OCP\DB::prepare ( OC_Shorty_Query::URL_CLICK );
		$query->execute ( $param );

		// allow further processing by registered hooks
		$details = array ( );
		// for this we need two things: details about the Shorty AND about the request
		$query = OCP\DB::prepare ( OC_Shorty_Query::URL_VERIFY );
		$entries = $query->execute($param)->FetchAll();
		if (  (1==count($entries))