<commit_before><?php
if(!defined('ROOT')) exit('Direct Access Is Not Allowed');
//All functions and resources to be used by service system

if(!function_exists("getServiceCMD")) {
	function getServiceCMD() {
		$scmd=$_REQUEST['scmd'];
		return $scmd;
	}

	//Handle Action Method Invocations
	function handleActionMethodCalls($defaultData = []) {
	    if(strlen($_REQUEST['action'])<=0) {
	      printServiceMsg($defaultData);
	      return false;
	    }

	    $rmiMethod = generateActionMethodName($_REQUEST['action']);
	    
	    if($rmiMethod && function_exists($rmiMethod)) {
	      $return = call_user_func($rmiMethod);
	      if($return!==null) {
	        printServiceMsg($return);
	      }
	    } else {
	      printServiceErrorMsg(501,"Method Not Found for ".clean($_REQUEST['action']));
	    }
	}
	  
	//Generates a name for Remote Method Function, returns false if proposedMethodName is null or if rmi method function allready exists
	function generateActionMethodName($proposedMethodName) {
	    if($proposedMethodName==null || strlen($proposedMethodName)<=0) return false;
	    
	    $rmiFunc = str_replace(' ', '-', $proposedMethodName); // Replaces all spaces with hyphens.
	    $rmiFunc = preg_replace('/[^A-Za-z0-9\-_.]/', '', $rmiFunc); // Removes special chars.
	    $rmiFunc =  preg_replace('/-+/', '-', $rmiFunc);
	    $rmiFunc = strtolower($rmiFunc);
	    
	    $rmiFunc = "_service_$rmiFunc";
	    
	    return $rmiFunc;
	}

	function isAjax() {
		if(_server('HTTP_REFERER')) {
			$x=_server('HTTP_X_REQUESTED_WITH');
			
			if(isset($_REQUEST['syshash']) && $_REQUEST['syshash']==getSysHash()) {
				return true;
			} elseif($x) {
				$isAjax = $x AND strtolower($x) === 'xmlhttprequest';
				if($isAjax) {
					return true;
				}
			}
		} elseif(isset($_REQUEST['syshash']) && $_REQUEST['syshash']==getSysHash()) {
			return true;
		}
		return false;
	}

	//All Error Printing Funcs
	function passErrorMsg($msg) {
		if(is_array($msg)) {
			$msg=json_encode($msg);

			echo "<script language='javascript' type='text/javascript'>
				console.error('$msg');
			</script><h3>$msg</h3>";
		} else {
			echo "<script language='javascript' type='text/javascript'>
				if(typeof logiksAlert=='undefined') alert('ERROR : $msg');
				else logiksAlert('ERROR : $msg');
				console.error('$msg');
			</script><h3>$msg</h3>";
		}
	}

	//All Error Printing Funcs
	function passWarnMsg($msg) {
		if(is_array($msg)) {
			$msg=json_encode($msg);

			echo "<script language='javascript' type='text/javascript'>
				console.warn('$msg');
			</script><h3>$msg</h3>";
		} else {
			echo "<script language='javascript' type='text/javascript'>
				if(typeof logiksAlert=='undefined') alert('WARNING : $msg');
				else logiksAlert('WARNING : $msg');
				console.warn('$msg');
			</script><h3>$msg</h3>";
		}
	}

	function printServiceErrorMsg($errCode,$errMsg=null,$errorImg="") {
		if($errCode==null) $errCode=500;
		if(is_numeric($errCode)) {
		  $errorMessage=getErrorTitle($errCode);
	    } else {
	    	$errorMessage="";
	    }
	    if($errMsg==null) {
	    	$errMsg=$errorMessage;
	    }
		if($errorImg!=null && strlen($errorImg)>0) {
			$errorImg=loadMedia($errorImg);
		} else {
			$errorImg=loadMedia("images/errors/msg_default.png");
		}

		$arr=array();
		$arr['ErrorCode']=$errCode;
		$arr['Data']=$errMsg;
		$arr['ErrorDescs']=_replace($errorMessage);
		$arr['ErrorIcon']=$errorImg;

		printServiceData($arr,null,$errCode);
	}

	function printServiceMsg($msgData,$msgCode=200,$msgImage="") {
		// if($msgImage!=null && strlen($msgImage)>0) {
		// 	$msgImage=loadMedia($msgImage);
		// }

		$arr=array();
		$arr['MessageCode']=$msgCode;
		$arr['Data']=$msgData;
		//$arr['MessageIcon']=$msgImage;

		printServiceData($arr,null,$msgCode);
	}

	function printServiceData($arrData,$format=null,$statusCode=200) {
		if($statusCode==null || !is_numeric($statusCode)) $statusCode=200;
		$envelop=getMsgEnvelop();

		if($format==null) {
			if(isset($_GET['format'])) $format=$_GET['format'];
			else $format=$_REQUEST['format'];
		}

		ob_clean();

		if(getConfig("SERVICE_SHOW_REQUEST")) {
			$arrData['Request']['uri']=SiteLocation._server('REQUEST_URI');
			$arrData['Request']['site']=$_REQUEST['site'];
			$arrData['Request']['scmd']=$_REQUEST['scmd'];<commit_msg>Updated serviceMsg<commit_after><?php
if(!defined('ROOT')) exit('Direct Access Is Not Allowed');
//All functions and resources to be used by service system

if(!function_exists("getServiceCMD")) {
	function getServiceCMD() {
		$scmd=$_REQUEST['scmd'];
		return $scmd;
	}

	//Handle Action Method Invocations
	function handleActionMethodCalls($defaultData = []) {
	    if(strlen($_REQUEST['action'])<=0) {
	      printServiceMsg($defaultData);
	      return false;
	    }

	    $rmiMethod = generateActionMethodName($_REQUEST['action']);
	    
	    if($rmiMethod && function_exists($rmiMethod)) {
	      $return = call_user_func($rmiMethod);
	      if($return!==null) {
	        printServiceMsg($return);
	      }
	    } else {
	      printServiceErrorMsg(501,"Method Not Found for ".clean($_REQUEST['action']));
	    }
	}
	  
	//Generates a name for Remote Method Function, returns false if proposedMethodName is null or if rmi method function allready exists
	function generateActionMethodName($proposedMethodName) {
	    if($proposedMethodName==null || strlen($proposedMethodName)<=0) return false;
	    
	    $rmiFunc = str_replace(' ', '-', $proposedMethodName); // Replaces all spaces with hyphens.
	    $rmiFunc = preg_replace('/[^A-Za-z0-9\-_.]/', '', $rmiFunc); // Removes special chars.
	    $rmiFunc =  preg_replace('/-+/', '-', $rmiFunc);
	    $rmiFunc = strtolower($rmiFunc);
	    
	    $rmiFunc = "_service_$rmiFunc";
	    
	    return $rmiFunc;
	}

	function isAjax() {
		if(_server('HTTP_REFERER')) {
			$x=_server('HTTP_X_REQUESTED_WITH');
			
			if(isset($_REQUEST['syshash']) && $_REQUEST['syshash']==getSysHash()) {
				return true;
			} elseif($x) {
				$isAjax = $x AND strtolower($x) === 'xmlhttprequest';
				if($isAjax) {
					return true;
				}
			}
		} elseif(isset($_REQUEST['syshash']) && $_REQUEST['syshash']==getSysHash()) {
			return true;
		}
		return false;
	}

	//All Error Printing Funcs
	function passErrorMsg($msg) {
		if(is_array($msg)) {
			$msg=json_encode($msg);

			echo "<script language='javascript' type='text/javascript'>
				console.error('$msg');
			</script><h3>$msg</h3>";
		} else {
			echo "<script language='javascript' type='text/javascript'>
				if(typeof logiksAlert=='undefined') alert('ERROR : $msg');
				else logiksAlert('ERROR : $msg');
				console.error('$msg');
			</script><h3>$msg</h3>";
		}
	}

	//All Error Printing Funcs
	function passWarnMsg($msg) {
		if(is_array($msg)) {
			$msg=json_encode($msg);

			echo "<script language='javascript' type='text/javascript'>
				console.warn('$msg');
			</script><h3>$msg</h3>";
		} else {
			echo "<script language='javascript' type='text/javascript'>
				if(typeof logiksAlert=='undefined') alert('WARNING : $msg');
				else logiksAlert('WARNING : $msg');
				console.warn('$msg');
			</script><h3>$msg</h3>";
		}
	}

	function printServiceErrorMsg($errCode,$errMsg=null,$errorImg="") {
		if($errCode==null) $errCode=500;
		if(is_numeric($errCode)) {
		  $errorMessage=getErrorTitle($errCode);
	    } else {
	    	$errorMessage="";
	    }
	    if($errMsg==null) {
	    	$errMsg=$errorMessage;
	    }
		if($errorImg!=null && strlen($errorImg)>0) {
			$errorImg=loadMedia($errorImg);
		} else {
			$errorImg=loadMedia("images/errors/msg_default.png");
		}

		$arr=array();
		$arr['ErrorCode']=$errCode;
		$arr['Data']=$errMsg;
		$arr['ErrorDescs']=_replace($errorMessage);
		$arr['ErrorIcon']=$errorImg;

		printServiceData($arr,null,$errCode);
	}

	function printServiceMsg($msgData,$msgCode=200,$msgRootData=[]) {
		// if($msgImage!=null && strlen($msgImage)>0) {
		// 	$msgImage=loadMedia($msgImage);
		// }

		$arr=array();
		$arr['MessageCode']=$msgCode;
		$arr['Data']=$msgData;
		//$arr['MessageIcon']=$msgImage;
		
		if(is_array($msgRootData)) {
			$arr = array_merge($msgRootData, $arr);
		}

		printServiceData($arr,null,$msgCode);
	}

	function printServiceData($arrData,$format=null,$statusCode=200) {
		if($statusCode==null || !is_numeric($statusCode)) $statusCode=200;
		$envelop=getMsgEnvelop();

		if($format==null) {
			if(isset($_GET['format'])) $format=$_GET['format'];
			else $format=$_REQUEST['format'];
		}

		ob_clean();

		if(getConfig("SERVICE_SHOW_REQUEST")) {
			$arrData['Request']['uri']=SiteLocation._server('REQUEST_URI');
			$arrData['Request']['site']=$_REQUEST['site'];
			$arrData['Request']['scmd']=$_REQUEST['scmd'];
{'fraction_non_alphanumeric': 0.19305153445280834, 'fraction_numerical': 0.00671685002895194, 'mean_word_length': 4.421217827997489, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '1727644', 'n_tokens_mistral': 3299, 'n_tokens_neox': 2911, 'n_words': 448}