class_XSLPHPFunction.inc.php 7.23 KB
<?php
/**
 * @file	XSLPHPFunction.inc.php
 * @category freeSN
 * @mailto	code [at] netz.coop
 * @version 0.4.200901
 * @link http://netz.coop
 * 
 *  @copyright Copyright by netz.coop e.G. 2015
 *  
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *   This program 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 General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */
/**
 *	In dieser Klasse stehen die PHP Funktionen drinn, die aus dem XSL Script ausgerufen werden
 *
 *	@version 		0.070115 (CD-0.8.3)
 *	@author 		dev [at] mensch [dot] coop
 */
class XSLPHPFunction{


	public static function getLinkAccountManagement(){	return CONSTKindOf::LINK_ACCOUNTMANAGEMENT;}

	/**
	 * nocht nicht geprüfte Funktionen
	 */


	public static function getLastIndex($param_url){
		$var =  strrchr ($param_url, "[");
		$var =  substr ($var, 1, strpos($var,"]")-1);
		if($var==""){
			$var = 0;
		} else {
			$var++;
		}
		return trim($var);
	}
	public static function getURL(){

		return $_SERVER['PHP_SELF'];
	}
	/**
	 *	benötigt in default.xsl	Function_TimeFormular
	 */
	public static function getThisDay($time){
		if($time)	return date('j', $time);
		else		return date('j', time());
	}
	public static function getThisMonth($time, $text='n'){

		if($time){
			if($text=='F' || $text=='M'){
				return Language::getWord(date($text, $time));
			}
			return date($text, $time);
		}
		else		return date($text, time());
	}
	public static function getThisYear($time, $text='Y'){
		if($time)	return date($text, $time);
		else 		return date($text, time());
	}
	public static function getThisHour($time){
		if($time)	return date('G', $time);
		else		return date('G', time());
	}
	public static function getThisMinute($time){
		if($time)	return date('i', $time);
		else		return date('i', time());
	}
	public static function getStampToIcal($time){
		return date('Ymd',$time).'T'.date('Gis',$time);
	}
	public static function getThisDate($param_start, $param_end){
		if($param_start == $param_end or $param_end < $param_start){
			return Language::getWord(date('l', $param_start))." ".date('d.m.y  G:i', $param_start);
		}
		$var_return =  Language::getWord(date('l', $param_start))." ".date('d.m.y  G:i', $param_start)." - ";
		if(date('z',$param_end) > date('z',$param_start) || date('y',$param_end) > date('y',$param_start)){
			$var_return .= Language::getWord(date('l', $param_end))." ".date('d.m.y  G:i', $param_end);
		}
		else{
			$var_return .= date('G:i', $param_end);
		}
		return $var_return;
	}
	public static function getTextForService($text){
		if($text){
			$text = strip_tags($text);
			$kill   = array("\r\n", "\n", "\r");
			$text = str_replace($kill, " ", $text);
		}
		return trim($text);
	}
	public static function getTextForRSS($text){
		if($text){
			$text = strip_tags($text);
			$text = htmlspecialchars($text);
			$text = strip_tags($text);
		}
		return $text;
	}
	/**
	 *	benötigt in default.xsl	loop_FormularOption
	 */
	public static function getStartTagSelectOptionSelected(){return "<option selected>";			}
	public static function getStartTagSelectOption(){		return "<option>";						}
	public static function getEndTagSelectOption(){			return "</option>";						}

	public static function getLinkallFromThisClipboardType() { return CONSTKindOf::LINK_ALLFROMTHISCLIPBOARDTYPE; }

	public static function getLinkShowAll() {			return CONSTKindOf::LINK_SHOWALL;			}
	public static function getLinkShowList() {			return CONSTKindOf::LINK_SHOWLIST;			}
	public static function getLinkMakeNew() {			return CONSTKindOf::LINK_MAKENEW;			}
	public static function getLinkEdit() {				return CONSTKindOf::LINK_EDIT;				}
	public static function getLinkEditSB() {			return CONSTKindOf::LINK_EDITSB;			}
	public static function getLinkShowSingle() {			return CONSTKindOf::LINK_SHOWSINGLE;		}
	public static function getLinkID() {				return CONSTKindOf::LINK_ID;				}


	public static function getLinkShowAllChildren(){	return CONSTKindOf::LINK_SHOWALLCHILDREN;	}
	public static function getLinkShowAllParents(){		return CONSTKindOf::LINK_SHOWALLPARENTS;	}

	public static function getLinkShowLinkList(){		return CONSTKindOf::LINK_SHOWLINKLIST;		}
	public static function getLinkAddToLinkList(){		return CONSTKindOf::LINK_ADDTOLINKLIST;		}
	public static function getLinkRemoveFromLinkList(){	return CONSTKindOf::LINK_REMOVEFROMLINKLIST;}

	public static function getLinkAddElementTo(){		return CONSTKindOf::LINK_ADDELEMENTTO;		}

	public static function getLinkAnswerAspirant() {	return CONSTKindOf::LINK_ANSWERASPIRANT;	}
	public static function getLinkShowWriteMembers() {	return CONSTKindOf::LINK_SHOWWRITEMEMBERS;	}
	public static function getLinkRequestAspirant() {	return CONSTKindOf::LINK_REQUESTASPIRANT;	}


	public static function getLinkError() {				return CONSTKindOf::LINK_ERROR;				}
	public static function getLinkChangePassword() {	return CONSTKindOf::LINK_CHANGEPASSWORD;	}

	//	public static function getLinkListNavigatorStart(){	return CONSTKindOf::LINK_LISTNAVIGATOR_START;}
	//	public static function getLinkListNavigatorLimit(){	return CONSTKindOf::LINK_LISTNAVIGATOR_LIMIT;}
	//	public static function getLinkListNavigatorDirection(){	return CONSTKindOf::LINK_LISTNAVIGATOR_DIRECTION;		}
	//	public static function getLinkListNavigatorUpDirection(){	return CONSTKindOf::LINK_LISTNAVIGATOR_UPDIRECTION;		}
	//	public static function getLinkListNavigatorDownDirection(){	return CONSTKindOf::LINK_LISTNAVIGATOR_DOWNDIRECTION;		}


	public static function getLinkShowAspirant() {	return CONSTKindOf::LINK_SHOWASPIRANT;	}

	public static function checkTags($param_string, $param_index) {

		if(strlen($param_string) > $param_index){
			$param_string = substr($param_string, 0 ,$param_index);



			//offene tags entfernen
			if(strrpos($param_string,'<') > strrpos($param_string,'>')){
				$param_string=substr($param_string,0,strrpos($param_string,'<'));
			}

			//schliessende Tags hinzufügen
			/*preg_match_all("/(<\w+)(?:.){0,}?>/", $param_string, $v1);*/
			preg_match_all("/<[^>]*[^\/]>/", $param_string, $v1);
			preg_match_all("/<\/\w+>/", $param_string, $v2);

			$open = array_map('strtolower', $v1[0]);
			$closed = array_map('strtolower', $v2[0]);

			$string_add = '';

			foreach ($open as $tag)
			{
				/*$end_tag = preg_replace("/<(.*)/", "</$1>", $tag);*/
				//$end_tag = preg_replace("/<([^>^ ]*)/", "</$1>", $tag);
				$end_tag = substr($tag,1);
				if($index = strpos($end_tag," ")){
					$end_tag = '</'.substr($end_tag,0,$index).'>';
				}
				else{
					$end_tag = '</'.substr($end_tag,0,-1).'>';
				}


				if (!in_array($end_tag, $closed)){
					$string_add =$end_tag.$string_add;
				}
				unset($closed[array_search($end_tag, $closed)]);
			}
			$param_string .= "...";
			$param_string .= $string_add;
		}
		//entferne [BasisElement]
		$param_string = preg_replace('/\[BasisElement\s\w*\s\d*\]/i', '', $param_string);
		return $param_string;

	}
}
?>