<commit_before><?php
/**
 * ownCloud
 *
 * @author <NAME>
 * @author <NAME>
 * @copyright 2012 <NAME> <EMAIL>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

/**
 * Collection of useful functions
 */
class OC_Helper {
	private static $mimetypes=array();
	private static $tmpFiles=array();

	/**
	 * @brief Creates an url using a defined route
	 * @param $route
	 * @param array $parameters
	 * @return
	 * @internal param array $args with param=>value, will be appended to the returned url
	 * @returns the url
	 *
	 * Returns a url to the given app and file.
	 */
	public static function linkToRoute( $route, $parameters = array() ) {
		$urlLinkTo = OC::getRouter()->generate($route, $parameters);
		return $urlLinkTo;
	}

	/**
	 * @brief Creates an url
	 * @param string $app app
	 * @param string $file file
	 * @param array $args array with param=>value, will be appended to the returned url
	 * 	The value of $args will be urlencoded
	 * @return string the url
	 *
	 * Returns a url to the given app and file.
	 */
	public static function linkTo( $app, $file, $args = array() ) {
		if( $app != '' ) {
			$app_path = OC_App::getAppPath($app);
			// Check if the app is in the app folder
			if( $app_path && file_exists( $app_path.'/'.$file )) {
				if(substr($file, -3) == 'php' || substr($file, -3) == 'css') {
					$urlLinkTo =  OC::$WEBROOT . '/index.php/apps/' . $app;
					$urlLinkTo .= ($file!='index.php') ? '/' . $file : '';
				}else{
					$urlLinkTo =  OC_App::getAppWebPath($app) . '/' . $file;
				}
			}
			else{
				$urlLinkTo =  OC::$WEBROOT . '/' . $app . '/' . $file;
			}
		}
		else{
			if( file_exists( OC::$SERVERROOT . '/core/'. $file )) {
				$urlLinkTo =  OC::$WEBROOT . '/core/'.$file;
			}
			else{
				$urlLinkTo =  OC::$WEBROOT . '/'.$file;
			}
		}

		if (!empty($args)) {
			$urlLinkTo .= '?';
			foreach($args as $k => $v) {
				$urlLinkTo .= '&'.$k.'='.urlencode($v);
			}
		}<commit_msg>Simplify the code and remove a first  unnecessary (and non conform) '&' character when there are pending arguments<commit_after><?php
/**
 * ownCloud
 *
 * @author <NAME>
 * @author <NAME>
 * @copyright 2012 <NAME> <EMAIL>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
 *
 * You should have received a copy of the GNU Affero General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

/**
 * Collection of useful functions
 */
class OC_Helper {
	private static $mimetypes=array();
	private static $tmpFiles=array();

	/**
	 * @brief Creates an url using a defined route
	 * @param $route
	 * @param array $parameters
	 * @return
	 * @internal param array $args with param=>value, will be appended to the returned url
	 * @returns the url
	 *
	 * Returns a url to the given app and file.
	 */
	public static function linkToRoute( $route, $parameters = array() ) {
		$urlLinkTo = OC::getRouter()->generate($route, $parameters);
		return $urlLinkTo;
	}

	/**
	 * @brief Creates an url
	 * @param string $app app
	 * @param string $file file
	 * @param array $args array with param=>value, will be appended to the returned url
	 * 	The value of $args will be urlencoded
	 * @return string the url
	 *
	 * Returns a url to the given app and file.
	 */
	public static function linkTo( $app, $file, $args = array() ) {
		if( $app != '' ) {
			$app_path = OC_App::getAppPath($app);
			// Check if the app is in the app folder
			if( $app_path && file_exists( $app_path.'/'.$file )) {
				if(substr($file, -3) == 'php' || substr($file, -3) == 'css') {
					$urlLinkTo =  OC::$WEBROOT . '/index.php/apps/' . $app;
					$urlLinkTo .= ($file!='index.php') ? '/' . $file : '';
				}else{
					$urlLinkTo =  OC_App::getAppWebPath($app) . '/' . $file;
				}
			}
			else{
				$urlLinkTo =  OC::$WEBROOT . '/' . $app . '/' . $file;
			}
		}
		else{
			if( file_exists( OC::$SERVERROOT . '/core/'. $file )) {
				$urlLinkTo =  OC::$WEBROOT . '/core/'.$file;
			}
			else{
				$urlLinkTo =  OC::$WEBROOT . '/'.$file;
			}
		}

		if ($args && $query = http_build_query($args, '', '&')) {
			$urlLinkTo .= '?'.$query;
		}
{'fraction_non_alphanumeric': 0.14751552795031056, 'fraction_numerical': 0.002717391304347826, 'mean_word_length': 3.05748031496063, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3896116', 'n_tokens_mistral': 1842, 'n_tokens_neox': 1657, 'n_words': 587}