<commit_before><?php
namespace Dframe;
use Dframe\Config;

//http://download.hernas.pl/

class Router extends Core
{

    public $aRouting;
    private $aRoutingParse;
    private $sURI;
    private $parsingArray;

	public function __construct(){

		$aURI = explode('/', $_SERVER['SCRIPT_NAME']);
		
		array_pop($aURI);
		$this->sURI = implode('/', $aURI).'/';

        $routerConfig = Config::load('router');
		$this->aRouting = $routerConfig->get();
		$this->aRoutingParse = $routerConfig->get();

	}
    
    // string||array (folder,)controller/action 
    public function isActive($url) {
        if(is_array($url)) {
            foreach($url as $oneurl) {
                if(strpos($oneurl, '/'))
                    list($task, $action) = explode('/', $oneurl);
                else
                    $task = $oneurl;
                    
                if(!empty($action)) {
                    if($task == $this->aRouting['task'] && $action == $this->aRouting['action'])
                        return true;
                } else {
                    if($task == $this->aRouting['task'])
                        return true;
                }
            }
            return false;
        } else {
            if(strpos($url, '/'))
                list($task, $action) = explode('/', $url);
            else
                $task = $url;
                
            if(!empty($action))
                return ($task == $this->aRouting['task']) && ($action == $this->aRouting['action']);

            return ($task == $this->aRouting['task']);
        }
    }
    
	public function makeUrl($sUrl = null)
	{
		$aParamsHook = explode('#', $sUrl);
		$aParams = explode('?', $aParamsHook[0]);
		$aParams_ = explode('/', $aParams[0]);
		$sAction = $aParams_[0];
		if (isset($aParams_[1])) 
			$sModel = $aParams_[1];
		else
			$sModel = null;

		if (isset($aParams[1])) 
			parse_str($aParams[1], $aParams);
		else 
			$aParams = array();
		
		if(MOD_REWRITE){

            $sExpressionUrl = $sAction.'/'.$sModel;
            if(!empty($aParams)) {
                $sExpressionUrl .= '?';
                foreach($aParams AS $k => $v)
                {
                    $test[] = $k.'='.$v;
                }
                $sExpressionUrl .= implode('&', $test);
            }
		} else {
			$sExpressionUrl = 'index.php?task='.$sAction.'&action='.$sModel;
			foreach($aParams AS $k => $v){
				$sExpressionUrl .= '&'.$k.'='.$v;
			}

		}
		$sUrl = 'http://' . $_SERVER['HTTP_HOST'] . $this->sURI;
		$sUrl .= $sExpressionUrl;
		
		return $sUrl;
	}
	private function parseParams($sRouting, $aParams){
		$sReturn = null;
		foreach($aParams AS $key => $value)
		{
			$sReturn .= str_replace(array('[name]', '[value]'), array($key, $value), $sRouting);
		}
		return $sReturn;
	}

	public function parseGets(){
		$routerConfig = Config::load('router');
		
		if(MOD_REWRITE){

			$sRequest = preg_replace('!'.$this->sURI.'(.*)$!i',  '$1', $_SERVER['REQUEST_URI']);
			if(substr($sRequest, -1)!='/'){
				$sRequest .= '/';
			}

			$sGets = $this->parseUrl($sRequest);
			parse_str($sGets, $aGets);
			$_GET['task'] = !empty($aGets['task'])?$aGets['task']:$routerConfig->get('NAME_CONTROLLER');;	
			unset($aGets['task']);
			$_GET['action'] = !empty($aGets['action'])?$aGets['action']:$routerConfig->get('NAME_MODEL');;
			unset($aGets['action']);
			$_GET = array_merge($_GET, $aGets);

		}else{

			$sRequest = preg_replace('!'.$this->sURI.'(.*)$!i',  '$1', $_SERVER['REQUEST_URI']);
			if(substr($sRequest, 0, 1)=='?'){
				$sRequest = substr($sRequest, 1);
			}

			$sGets = $sRequest;

            $sGets = str_replace("index.php?", "", $sGets);
            parse_str($sGets, $output);

			$_GET['task'] = !empty($output['task'])?$output['task']:$routerConfig->get('NAME_CONTROLLER');;	
			$_GET['action'] = !empty($output['action'])?$output['action']:$routerConfig->get('NAME_MODEL');;
			
		}
	}

	private function parseUrl($sRequest){   
		$sVars = null;
		foreach($this->aRoutingParse AS $k => $v){
			
			preg_match_all('!\[(.+?)\]!ie', $v[0], $aExpression_);
			$sExpression = preg_replace('!\[(.+?)\]!ie', '$this->transformParam(\'$1\', \''.$k.'\')', $v[0]);
			if(preg_match_all('!'.$sExpression.'!i', $sRequest, $aExpression__))
			{
				foreach($aExpression__ AS $k_ => $v_)
				{
					foreach($v_ AS $kkk => $vvv)
					{
						if(!isset($aExpression_[1][$k_-1]))
						{<commit_msg>Tworzenie domylnego tasku i akcji<commit_after><?php
namespace Dframe;
use Dframe\Config;

//http://download.hernas.pl/

class Router extends Core
{

    public $aRouting;
    private $aRoutingParse;
    private $sURI;
    private $parsingArray;

	public function __construct($bootstrap){

		$aURI = explode('/', $_SERVER['SCRIPT_NAME']);
		
		array_pop($aURI);
		$this->sURI = implode('/', $aURI).'/';

        $routerConfig = Config::load('router');
		$this->aRouting = $routerConfig->get();
		$this->aRoutingParse = $routerConfig->get();

	}
    
    // string||array (folder,)controller/action 
    public function isActive($url) {
        if(is_array($url)) {
            foreach($url as $oneurl) {
                if(strpos($oneurl, '/'))
                    list($task, $action) = explode('/', $oneurl);
                else
                    $task = $oneurl;
                    
                if(!empty($action)) {
                    if($task == $this->aRouting['NAME_CONTROLLER'] && $action == $this->aRouting['NAME_MODEL'])
                        return true;
                } else {
                    if($task == $this->aRouting['NAME_CONTROLLER'])
                        return true;
                }
            }
            return false;
        } else {
            if(strpos($url, '/'))
                list($task, $action) = explode('/', $url);
            else
                $task = $url;
                
            if(!empty($action))
                return ($task == $this->aRouting['NAME_CONTROLLER']) && ($action == $this->aRouting['NAME_MODEL']);

            return ($task == $this->aRouting['NAME_CONTROLLER']);
        }
    }
    
	public function makeUrl($sUrl = null)
	{
		$aParamsHook = explode('#', $sUrl);
		$aParams = explode('?', $aParamsHook[0]);
		$aParams_ = explode('/', $aParams[0]);
		$sAction = $aParams_[0];
		if (isset($aParams_[1])) 
			$sModel = $aParams_[1];
		else
			$sModel = null;

		if (isset($aParams[1])) 
			parse_str($aParams[1], $aParams);
		else 
			$aParams = array();
		
		if(MOD_REWRITE){

            $sExpressionUrl = $sAction.'/'.$sModel;
            if(!empty($aParams)) {
                $sExpressionUrl .= '?';
                foreach($aParams AS $k => $v)
                {
                    $test[] = $k.'='.$v;
                }
                $sExpressionUrl .= implode('&', $test);
            }
		} else {
			$sExpressionUrl = 'index.php?task='.$sAction.'&action='.$sModel;
			foreach($aParams AS $k => $v){
				$sExpressionUrl .= '&'.$k.'='.$v;
			}

		}
		$sUrl = 'http://' . $_SERVER['HTTP_HOST'] . $this->sURI;
		$sUrl .= $sExpressionUrl;
		
		return $sUrl;
	}
	private function parseParams($sRouting, $aParams){
		$sReturn = null;
		foreach($aParams AS $key => $value)
		{
			$sReturn .= str_replace(array('[name]', '[value]'), array($key, $value), $sRouting);
		}
		return $sReturn;
	}

	public function parseGets(){
		$routerConfig = Config::load('router');
		
		if(MOD_REWRITE){

			$sRequest = preg_replace('!'.$this->sURI.'(.*)$!i',  '$1', $_SERVER['REQUEST_URI']);
			if(substr($sRequest, -1)!='/'){
				$sRequest .= '/';
			}

			$sGets = $this->parseUrl($sRequest);
			parse_str($sGets, $aGets);
			$_GET['NAME_CONTROLLER'] = !empty($aGets['NAME_CONTROLLER'])?$aGets['NAME_CONTROLLER']:$routerConfig->get('NAME_CONTROLLER');;	
			unset($aGets['NAME_CONTROLLER']);
			$_GET['NAME_MODEL'] = !empty($aGets['NAME_MODEL'])?$aGets['NAME_MODEL']:$routerConfig->get('NAME_MODEL');;
			unset($aGets['NAME_MODEL']);
			$_GET = array_merge($_GET, $aGets);

		}else{

			$sRequest = preg_replace('!'.$this->sURI.'(.*)$!i',  '$1', $_SERVER['REQUEST_URI']);
			if(substr($sRequest, 0, 1)=='?'){
				$sRequest = substr($sRequest, 1);
			}

			$sGets = $sRequest;

            $sGets = str_replace("index.php?", "", $sGets);
            parse_str($sGets, $output);

			$_GET['NAME_CONTROLLER'] = !empty($output['NAME_CONTROLLER'])?$output['NAME_CONTROLLER']:$routerConfig->get('NAME_CONTROLLER');;	
			$_GET['NAME_MODEL'] = !empty($output['NAME_MODEL'])?$output['NAME_MODEL']:$routerConfig->get('NAME_MODEL');;
			
		}
	}

	private function parseUrl($sRequest){   
		$sVars = null;
		foreach($this->aRoutingParse AS $k => $v){
			
			preg_match_all('!\[(.+?)\]!ie', $v[0], $aExpression_);
			$sExpression = preg_replace('!\[(.+?)\]!ie', '$this->transformParam(\'$1\', \''.$k.'\')', $v[0]);
			if(preg_match_all('!'.$sExpression.'!i', $sRequest, $aExpression__))
			{
				foreach($aExpression__ AS $k_ => $v_)
				{
					foreach($v_ AS $kkk => $vvv)
					{
						if(!isset($aExpression_[1][$k_-1]))
						{
{'fraction_non_alphanumeric': 0.2140873236307077, 'fraction_numerical': 0.003999555604932785, 'mean_word_length': 2.5122902848224737, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1723256', 'n_tokens_mistral': 3456, 'n_tokens_neox': 3116, 'n_words': 480}