コード例 #1
0
ファイル: tools.php プロジェクト: ArcherSys/ArcherSysOSCloud7
	/**
	* @method OC_Shorty_Tools::ob_control
	* @param bool on: Wether to activate or deactivate the buffer
	* @return NULL|string: NULL when starting buffering, buffered content when stopping buffering
	* @access public
	* @author Christian Reiner
	*/
	static function ob_control ( $on=TRUE )
	{
		$output = NULL;				@ob_implicit_flush ( FALSE );
				@ob_start ( );
				self::$ob_active = TRUE;

		if ( self::$ob_usage )
		{
			// attempt to use outpout buffering
			if ( $on )
			{
				// start buffering if possible and not yet started before
				if (   function_exists('ob_start')       // output buffers installed at all ?
					&& ! self::$ob_active  )  // don't stack buffers (create buffer only, if not yet started)
				{
					@ob_implicit_flush ( FALSE );
					@ob_start ( );
					self::$ob_active = TRUE;
				}
			} // if $on==TRUE
			else
			{
				// end buffering _if_ it has been started before
				if ( self::$ob_active )
				{
					$output = @ob_get_contents ( );
					@ob_end_clean ( );
					self::$ob_active = FALSE;
				}
			} // if $on==FALSE
		} // if ob_usage
		return $output;
	} // function ob_control
コード例 #2
0
	/**
	* @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
コード例 #3
0
ファイル: list.php プロジェクト: ArcherSys/ArcherSysOSCloud7
	$param = array (
		':user'   => OCP\User::getUser ( ),
		':sort'   => $p_sort,
// 		':offset' => $p_offset,
// 		':limit'  => PAGE_SIZE,
	);
	$query = OCP\DB::prepare ( OC_Shorty_Query::URL_LIST );
	$result = $query->execute($param);
	$reply = $result->fetchAll();
	foreach (array_keys($reply) as $key) {
		if (isset($reply[$key]['id']))
		{
			// enhance all entries with the relay url
			$reply[$key]['relay']=OC_Shorty_Tools::relayUrl ( $reply[$key]['id'] );
			// make sure there is _any_ favicon contained, otherwise layout in MS-IE browser is broken...
			if (empty($reply[$key]['favicon']))
				$reply[$key]['favicon'] = OCP\Util::imagePath('shorty', 'blank.png');
		}
	} // foreach

	// 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("Constructed list of defined shortys holding %s entries.",sizeof($reply)), OCP\Util::DEBUG );
	OCP\JSON::success ( array (
		'data'    => $reply,
		'level'   => 'debug',
		'count'   => sizeof($reply),
		'message' => OC_Shorty_L10n::t("Number of entries: %s", count($reply)) ) );
} catch ( Exception $e ) { OC_Shorty_Exception::JSONerror($e); }
?>
コード例 #4
0
ファイル: type.php プロジェクト: ArcherSys/ArcherSysOSCloud7
	/**
	* @method OC_Shorty_Type::normalize
	* @brief Cleanup and formal normalization of a given value   according to its type
	* Normalizes a given value according to its claimed type.
	* This typically means trimming of string values, but somet  imes also more specific actions.
	* @param mixed value: Value to be normalized
	* @param OC_Shorty_Type::type type: Supposed type of the va  lue
	* @param bool strict: Flag indicating if the normalization   should be done in a strict way
	* @return mixed: The normalized value
	* @throws error Indicating a parameter violation
	* @access public
	* @author Christian Reiner
	*/
	static function normalize ( $value, $type, $strict=FALSE )
	{
		if (NULL===(self::validate($value,$type,$strict)))
		{
			if ( ! $strict)
				return NULL;
			else
				throw new OC_Shorty_Exception ( "invalid value '%1\$s' for type '%2\$s'", array($value,$type) );
		} // if
		switch ( $type )
		{
			case self::ID:
				return trim ( $value );

			case self::STATUS:
				return trim ( $value );

			case self::SORTKEY:
				return trim ( $value );

			case self::SORTVAL:
				return trim ( $value );

			case self::JSON:
				return trim ( $value );

			case self::STRING:
				return trim ( $value );

			case self::URL:
				return trim ( $value );

			case self::PATH:
				return trim ( $value );

			case self::INTEGER:
				return sprintf ( '%d', $value );

			case self::FLOAT:
				return sprintf ( '%f', $value );

			case self::TIMESTAMP:
				return trim ( $value );

			case self::DATE:
				return date ( 'Y-m-d', self::validate($value,OC_Shorty_Type::DATE) );

			case self::BOOLEAN:
				return OC_Shorty_Tools::toBoolean(trim($value)) ? TRUE : FALSE;

		} // switch $type
		throw new OC_Shorty_Exception ( "unknown request argument type '%s'", array($type) );
	} // function normalize
コード例 #5
0
ファイル: meta.php プロジェクト: ArcherSys/ArcherSysOSCloud7
	static function enrichMetaDataCurl ( $url, &$meta )
	{
		// to fetch meta data we rely on curl being installed
		if ( ! function_exists('curl_init') )
			return;
		// try to retrieve the meta data
		$handle = curl_init ( );
		curl_setopt ( $handle, CURLOPT_URL, OC_Shorty_Tools::idnToASCII($url) );
		curl_setopt ( $handle, CURLOPT_RETURNTRANSFER, 1 );
		curl_setopt ( $handle, CURLOPT_FOLLOWLOCATION, TRUE );
		curl_setopt ( $handle, CURLOPT_MAXREDIRS, 10 );
		if ( FALSE!==($page=curl_exec($handle)) )
		{
			// try to extract title from page
			preg_match ( "/<head[^>]*>.*<title>(.*)<\/title>.*<\/head>/si", $page, $match );
// 			$meta['title']    = isset($match[1]) ? htmlspecialchars_decode ( trim($match[1]) ) : '';
			$meta['title']    = isset($match[1]) ? html_entity_decode ( trim($match[1]),  ENT_COMPAT, 'UTF-8' ) : '';
			$meta['staticon'] = self::selectIcon ( 'state', TRUE );
			// final url after a possible redirection
			$meta['final']       = curl_getinfo ( $handle, CURLINFO_EFFECTIVE_URL );
			// try to extract favicon from page
			preg_match ( '/<[^>]*link[^>]*(rel=["\']icon["\']|rel=["\']shortcut icon["\']) .*href=["\']([^>]*)["\'].*>/iU', $page, $match );
			if (1<sizeof($match))
			{
				// the specified uri might be an url, an absolute or a relative path
				// we have to turn it into an url to be able to display it out of context
				$favicon = htmlspecialchars_decode ( $match[2] );
				// test for an url
				if (parse_url($favicon,PHP_URL_SCHEME))
				{
					$meta['favicon'] = $favicon;
				}
				// test for an absolute path
				elseif ( 0===strpos(parse_url($favicon,PHP_URL_PATH),'/') )
				{
					$url_token = parse_url($meta['final']);
					$meta['favicon'] = sprintf( '%s://%s/%s', $url_token['scheme'], $url_token['host'], $favicon );
				}
				// so it appears to be a relative path
				else
				{
					$url_token = parse_url($meta['final']);
					$meta['favicon'] = sprintf( '%s://%s%s%s', $url_token['scheme'], $url_token['host'], dirname($url_token['path']), $favicon );
				}
			}
			$meta['mimetype']    = preg_replace ( '/^([^;]+);.*/i', '$1', curl_getinfo($handle,CURLINFO_CONTENT_TYPE) );
			$meta['mimicon']     = self::selectIcon ( 'mimetype', $meta['mimetype'] );
			$meta['code']        = curl_getinfo ( $handle, CURLINFO_HTTP_CODE );
			$meta['status']      = OC_Shorty_L10n::t ( self::selectCode('status',$meta['code']) );
			$meta['explanation'] = OC_Shorty_L10n::t ( self::selectCode('explanation',$meta['code']) );
		} // if
		curl_close ( $handle );
		// that's it !
	} // function enrichMetaDataCurl
コード例 #6
0
	/**
	* @method OC_Shorty_Exception::JSONerror
	* @brief Calls OCP\JSON::error with a pretty formated version of an exception
	* @param exception: An exception object holding information
	* @return json: OCP\JSON::error
	* @access public
	* @author Christian Reiner
	*/
	static function JSONerror ( $e )
	{
		$title = OC_Shorty_L10n::t("Exception");
		switch ( get_class($e) )
		{
			case 'OC_Shorty_Exception':
				$message = $e->getTranslation();
				break;

			case 'PDOException':
				$message = sprintf ( OC_Shorty_L10n::t( "%s\nMessage(code): %s (%s)\nFile(line): %s (%s)\nInfo: %%s",
														OC_Shorty_L10n::t("Exception (%s)", get_class($e)),
														htmlspecialchars($e->getMessage()),
														htmlspecialchars($e->getCode()),
														htmlspecialchars($e->getFile()),
														htmlspecialchars($e->getLine()) ),
									(method_exists($e,'errorInfo') ? trim($e->errorInfo()) : '-/-') );
				break;

			default:
				if ( is_a($e,'Exception') )
					$message = OC_Shorty_L10n::t("Unexpected type of exception caught:%s\n%s", get_class($e), $e->getMessage());
				else $message = OC_Shorty_L10n::t("Unexpected thrown object of type caught:\n%s", get_class($e));
		} // switch
		// swallow any accidential output generated by php notices and stuff to preserve a clean JSON reply structure
		$output = trim ( OC_Shorty_Tools::ob_control(FALSE) );
		if ( $output )
		{
			$message = "! Swallowing accidential output from ajax routines ! \n"
						."Please fix this ! Here is the first line: \n"
						.substr ( $output, 0, strpos($output,"\n") );
			OCP\Util::writeLog( 'shorty', $message, OCP\Util::WARN );
		} // output
		// return a clean JSON error
		return OCP\JSON::error ( array ('title'   => $title,
										'level'   => 'error',
										'message' => sprintf("%s:\n%s", $title, $message) ) );
	} // function error
コード例 #7
0
	/**
	* @method import
	* @brief Imports all data from a given resource into this apps storage areas
	* @author Christian Reiner
	*/
	function import ( )
	{
		OCP\Util::writeLog ( 'shorty','Starting data migration import for Shorty', OCP\Util::INFO );
		switch( $this->appinfo->version )
		{
			default:
				$query  = $this->content->prepare( "SELECT * FROM shorty WHERE user LIKE ?" );
				$result = $query->execute( array( $this->olduid ) );
				if (is_array(is_array($result)))
				{
					while( $row = $result->fetchRow() )
					{
						$param = array (
							'id'       => $row['id'],
							'status'   => $row['status'],
							'title'    => $row['title'],
							'favicon'  => $row['favicon'],
							'source'   => $row['source'],
							'target'   => $row['target'],
							'user'     => $row['user'],
							'until'    => $row['until'],
							'created'  => $row['created'],
							'accessed' => $row['accessed'],
							'clicks'   => $row['clicks'],
							'notes'    => $row['notes'],
						);
						// import each shorty one by one, no special treatment required, since no autoincrement id is used
						$query = OCP\DB::prepare( sprintf ( "INSERT INTO *PREFIX*shorty(%s) VALUES (%s)",
															implode(',',array_keys($param)),
															implode(',',array_fill(0,count($param),'?')) ) );
						$query->execute( $param );
					} // while
				} // if
				break;
		} // switch
		// check for success by counting the generated entries
		$count = OC_Shorty_Tools::countShortys();
		if(   (is_array($result) && is_array($count))
		&& (count($result)==$count['sum_shortys']) )
			return true;
		else return false;
	} // function import