class_LinkGenerator.inc.php 8.76 KB
<?php
/**
 * @file	LinkGenerator.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/>.
 * 
 */
class LinkGenerator {

	public static function getLabelArrayFromUrl(Account &$param_HostAccount, iStorable &$param_iStorable, array $param_URL) {
		//		D::show($param_URL);
		$var_result = array();

		if(array_key_exists('p', $param_URL)) {
			for($i=count($param_URL['p']); $i>=0; --$i) {
				if(array_key_exists($i, $param_URL['p']) && $param_URL['p'][$i]) {
					$FncVar_BasisClipboardnameArray = CONFIG::transformStringToArray($param_URL['p'][$i], 'category');

					if(class_exists($FncVar_BasisClipboardnameArray[0])) {
						if(is_subclass_of($FncVar_BasisClipboardnameArray[0], 'BasisClipboard')) {
							if(!array_key_exists('BasisClipboard', $var_result)) {
								$var_result['BasisClipboard'] = array();
								$var_result['BasisClipboard']['value'] = $param_URL['p'][$i];
								$var_result['BasisClipboard']['_i'] = $i;
							}
						} else if(is_subclass_of($FncVar_BasisClipboardnameArray[0], 'BasisElement')) {
							if(!array_key_exists('RootElement', $var_result)) {
								$var_result['RootElement'] = array();
								$var_result['RootElement']['value'] = $param_URL['p'][$i];
								$var_result['RootElement']['_i'] = $i;
							}
						}

					} else if($param_URL['p'][$i]=='ID' && $param_URL['p'][$i+1] && $param_URL['p'][$i-1]=='showSingle') {
						$BasisElement =& MultimediaText::loadElement($param_HostAccount, $param_iStorable, $param_Class='*', $param_URL['p'][$i+1], $param_PartOf=null, $param_BasisClipboardArray=null, $param_OnlyWhenLouded=true);

						if(!array_key_exists('showSingle', $var_result)) {
							$var_result['showSingle'] = array();
							if(is_object($BasisElement)) {
								$var_result['showSingle']['Subject'] = $BasisElement->getObjVar('Subject');
								$var_result['showSingle']['class'] = $BasisElement->ThisClassName;
							} else {
								$var_result['showSingle']['Subject'] = 'SingleView('.$param_URL['p'][$i+1].')';
							}

							$var_result['showSingle']['ID'] = $param_URL['p'][$i+1];
							$var_result['showSingle']['_i'] = $i;
						}
					}
				}

			}
		}
		//D::show($var_result)		;
		if(!empty($var_result)) {
			if(!array_key_exists('showSingle', $var_result) && !array_key_exists('BasisClipboard', $var_result) && array_key_exists('RootElement', $var_result) && $var_result['RootElement']['value']) {
				if(is_subclass_of('Profile',$var_result['RootElement']['value'])) {
					$var_HostClass = 'Profile';
				}
				$var_Language1 = Language::getClassLinks($var_HostClass, $var_result['RootElement']['value']);
				return $var_Language1;
				//				@warnung terminiert @f
				//			} else if(!array_key_exists('showSingle', $var_result) && array_key_exists('RootElement', $var_result) && $var_result['RootElement']['_i']+1 == $var_result['BasisClipboard']['_i']) {
			} else if(!array_key_exists('showSingle', $var_result) && array_key_exists('RootElement', $var_result) && $var_result['RootElement']['_i']+1 == $var_result['BasisClipboard']['_i']) {
				if(is_subclass_of('Profile',$var_result['RootElement']['value'])) {
					$var_result['RootElement']['value'] = 'Profile';
				}
				$var_Language1 = Language::getClassLinks($var_result['RootElement']['value'], $var_result['BasisClipboard']['value']);
				return $var_Language1;
				//	@warnung terminiert @f
				//	} else if($var_result['showSingle']['_i'] > $var_result['RootElement']['_i'] && $var_result['showSingle']['_i'] > $var_result['BasisClipboard']['_i']) {
			} else if(array_key_exists('showSingle', $var_result) && $var_result['showSingle']['_i'] > $var_result['RootElement']['_i'] && $var_result['showSingle']['_i'] > $var_result['BasisClipboard']['_i']) {
				return array('label'=>$var_result['showSingle']['Subject']);

				//	@warnung terminiert @f
				// } else if($var_result['showSingle']['_i'] > $var_result['RootElement']['_i'] && $var_result['showSingle']['_i'] < $var_result['BasisClipboard']['_i']) {
			} else if(array_key_exists('showSingle', $var_result) && $var_result['showSingle']['_i'] > $var_result['RootElement']['_i'] && $var_result['showSingle']['_i'] < $var_result['BasisClipboard']['_i']) {
				$var_Language1 = Language::getClassLinks($var_result['showSingle']['class'], $var_result['BasisClipboard']['value']);
				return $var_Language1;

			} else {
				return array('label'=>'?');
			}
		} else {
			return array('label'=>'?');
		}

		//		return $var_result;
	}

	public static function transformBEToLinkString(BasisElement $param_BE, $param_KindOf='showSingle') {

		$var_PartOfDataArray = $param_BE->getPartOfDataArray($param_BE->getObjVar('PartOfID'));

		if(is_array($var_PartOfDataArray) && array_key_exists('WayToRoot', $var_PartOfDataArray) && array_key_exists('string', $var_PartOfDataArray['WayToRoot'])) {
			$var_Link = $var_PartOfDataArray['WayToRoot']['string'];
		} else {
			$var_Link = '';
		}

		$var_Link .= 'p[]='.$param_KindOf.'&p[]=ID&p[]='.$param_BE->getObjVar('ID').'';
		return $var_Link;
	}

	/**
	 * make and return String for BasisElement
	 *
	 * @param int param_BEID
	 */
	//	public static function getBasisElementLinkString($param_BEID, $param_PartOfID, $param_PartOfObjVar) {
	//		if($param_PartOfID) {
	//			if($param_PartOfObjVar) {
	//				$var_Url= 'p[0]=showSingle&p[1]=ID&p[2]='.$param_PartOfID.'&p[3]='.$param_PartOfObjVar.'&p[4]=showSingle&p[5]=ID&p[6]='.$param_BEID;
	//			} else {
	//				$var_Url= 'p[0]=showSingle&p[1]=ID&p[2]='.$param_PartOfID.'&p[3]=LinkList&p[4]=showSingle&p[5]=ID&p[6]='.$param_BEID;
	//			}
	//		} else {
	//			$var_Url= 'p[0]=showSingle&p[1]=ID&p[2]='.$param_BEID.'';
	//		}
	//		return $var_Url;
	//	}

	//	public static function getBasisElementEditLinkString($param_BEID, $param_PartOfID, $param_PartOfObjVar) {
	//		if($param_PartOfID && $param_PartOfObjVar) {
	//			$var_Url= 'p[0]=showSingle&p[1]=ID&p[2]='.$param_PartOfID.'&p[3]='.$param_PartOfObjVar.'&p[4]=edit&p[5]=ID&p[6]='.$param_BEID;
	//			return $var_Url;
	//		} else {
	//			return false;
	//		}
	//
	//	}
	/**
	 * short recursive function, which returns array_keys and array_values as a url
	 *
	 *@param array $param_array the array
	 *@param String $param_return the return string
	 *@return String
	 */

	public static function transformArrayToStringUrl(array $param_array, $param_return = ''){
		if(is_array($param_array)){
			foreach($param_array as $key => $value){
				if(is_array($value))
					return LinkGenerator::transformArrayToStringUrl($value,$param_return.'['.$key.']');
				else
					return $param_return.'['.$key.']'.'='.$value;
			}
		}
	}
	/**
	 * make and return String for Service Link
	 *
	 * @param String param_KindOf Service (like rss2, xml, atom, ...)
	 * @param int param_PartOfID
	 * @param String param_BasisClipboardname=null
	 */
	public static function getServiceLinkString($param_KindOf, $param_PartOfID, array $param_BasisClipboardname=null, array $param_ConditionArray = null, $param_UrlString=null, $param_value) {
		if($param_PartOfID) {

			if($param_UrlString) {
				$var_Url= 'output='.$param_KindOf.'&'.$param_UrlString.'';

			} else if($param_BasisClipboardname) {
				$var_keys = array_keys($param_BasisClipboardname);
				//				$var_Url= 'output='.$param_KindOf.'&p[0]=showSingle&p[1]=ID&p[2]='.$param_PartOfID.'&p[3]='.$param_BasisClipboardname.'';
				$var_Url= 'output='.$param_KindOf.'&p[0]=showSingle&p[1]=ID&p[2]='.$param_PartOfID.'&p[3]='.$var_keys[0].'';

				if(is_array($param_ConditionArray)){
					$var_Url .= ListCondition::tranformConditionToUrl($param_PartOfID,$var_keys[0],$param_ConditionArray);
				}
				else if($param_value == CONSTKindOf::LINK_WITH_C){
					if(array_key_exists('c',$_GET) && array_key_exists($param_PartOfID,$_GET['c']) && array_key_exists($var_keys[0],$_GET['c'][$param_PartOfID])){
						$var_Url.='&c['.$param_PartOfID.']['.$var_keys[0].']';
						$var_Url.=LinkGenerator::transformArrayToStringUrl($_GET['c'][$param_PartOfID][$var_keys[0]]);
					}
				}
			} else  {
				$var_Url= 'output='.$param_KindOf.'&p[0]=showSingle&p[1]=ID&p[2]='.$param_PartOfID.'';
			}

		} else {
			return false;
		}
		return $var_Url;
	}

	//	public static function transformArrayToUrl(array $param_) {
	//	}
}
?>