<commit_before><?php
/**
* Check credential for the url or module-action
* The url should be in the form module/action
* 
* @author: <NAME>
*/
class ComponentCredential{
	
	/**
	* Components status for not having credential
	* either 'disabled' or 'hidden'
	*/
	private static $action = 'hidden';
	
	/**
	* The default hidden behavior can be changed by calling setAction with
	* 'hidden' or 'disabled' just before the refine() call
	*/
	public static function setAction($action){
		self::$action = $action;
	}
	/**
	* Make the component accessible or not accessible
	*/
	public static function filter($array,$module,$action=''){
		if($action == ""){
			if(!self::urlHasCredential($module)) $array[self::$action] = true;
		}else{
			if(!self::actionHasCredential($module,$action)) $array[self::$action] = true;
		}
		return $array;
	}
	/*
	* Check if user has credential for url
	* url should be in module/action format
	*/
	public static function urlHasCredential($url){
		$array = explode("/",$url);
		$array = array_diff($array,array("/",null,""));
		$array = array_values($array);
		$module = isset($array[0])?$array[0]:null;
		$action = isset($array[1])?$array[1]:null;	
		if(strpos($action,"?") !== false){
			$temp = explode("?",$action);
			$action = $temp[0];
		}				
		if(!$module || !$action) return true;		
		return self::actionHasCredential($module,$action);
	}
	
	/**		
	* Direct checking whether user has credential for module,action 
	*/
	public static function actionHasCredential($module,$action){
		$class = $module."Actions";
		require_once(sfConfig::get("sf_root_dir")."/apps/frontend/modules/".$module."/actions/actions.class.php");
		$obj = new $class(sfContext::getInstance(),$module,$action);	
		if(sfContext::getInstance()->getUser()->hasCredential($obj->getCredential())) return true;
		return false;
	}
	
	/**
	* Separator in menu for hidden mode. 
	* Because of hidden menu items, there may be multiple separators together.. just remove them
	*/
	private static function separatorFix($array){
		foreach($array as $key=>$item){
			if(
				isset($item['separator']) 
				&& 
				(
					(!isset($array[$key-1]) || (isset($array[$key-1]) && isset($array[$key-1]['separator'])))
					||
					(!isset($array[$key+1]) || (isset($array[$key+1]) && isset($array[$key+1]['separator'])))
				)
			)
			{
				unset($array[$key]);
			}
		}
		return $array;<commit_msg>Small update to check if file exists<commit_after><?php
/**
* Check credential for the url or module-action
* The url should be in the form module/action
* 
* @author: <NAME>
*/
class ComponentCredential{
	
	/**
	* Components status for not having credential
	* either 'disabled' or 'hidden'
	*/
	private static $action = 'hidden';
	
	/**
	* The default hidden behavior can be changed by calling setAction with
	* 'hidden' or 'disabled' just before the refine() call
	*/
	public static function setAction($action){
		self::$action = $action;
	}
	/**
	* Make the component accessible or not accessible
	*/
	public static function filter($array,$module,$action=''){
		if($action == ""){
			if(!self::urlHasCredential($module)) $array[self::$action] = true;
		}else{
			if(!self::actionHasCredential($module,$action)) $array[self::$action] = true;
		}
		return $array;
	}
	/*
	* Check if user has credential for url
	* url should be in module/action format
	*/
	public static function urlHasCredential($url){
		$array = explode("/",$url);
		$array = array_diff($array,array("/",null,""));
		$array = array_values($array);
		$module = isset($array[0])?$array[0]:null;
		$action = isset($array[1])?$array[1]:null;	
		if(strpos($action,"?") !== false){
			$temp = explode("?",$action);
			$action = $temp[0];
		}				
		if(!$module || !$action) return true;		
		return self::actionHasCredential($module,$action);
	}
	
	/**		
	* Direct checking whether user has credential for module,action 
	*/
	public static function actionHasCredential($module,$action){
		$class = $module."Actions";
		if(file_exists(sfConfig::get("sf_root_dir")."/apps/frontend/modules/".$module."/actions/actions.class.php")){
			require_once(sfConfig::get("sf_root_dir")."/apps/frontend/modules/".$module."/actions/actions.class.php");
			$obj = new $class(sfContext::getInstance(),$module,$action);	
			if(sfContext::getInstance()->getUser()->hasCredential($obj->getCredential())) return true;
		}
		return false;		
	}
	
	/**
	* Separator in menu for hidden mode. 
	* Because of hidden menu items, there may be multiple separators together.. just remove them
	*/
	private static function separatorFix($array){
		foreach($array as $key=>$item){
			if(
				isset($item['separator']) 
				&& 
				(
					(!isset($array[$key-1]) || (isset($array[$key-1]) && isset($array[$key-1]['separator'])))
					||
					(!isset($array[$key+1]) || (isset($array[$key+1]) && isset($array[$key+1]['separator'])))
				)
			)
			{
				unset($array[$key]);
			}
		}
		return $array;
{'fraction_non_alphanumeric': 0.18574338085539716, 'fraction_numerical': 0.004480651731160896, 'mean_word_length': 4.402640264026402, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5087830', 'n_tokens_mistral': 1749, 'n_tokens_neox': 1587, 'n_words': 366}