/** * Find a key in the given array return exploded position, false if key isn't found * * @version 1 * @author Rick de Man <*****@*****.**> * * @param array $Array * The array to look in for * @param string $Key * The Key to find in the provided array * @param string $Glue * The 'glue' for key location string * @param string $Result * Do not Use, will be over ruled * @return false if not found, string as location of the key */ function arraykeylocate($Array, $Key, $Glue = ',', $Result = '') { // Overrule the Result only when function depth is 1 if (GetFunctionDepth(2) == 1) { // Reset Result value $Result = ''; } // Check if array has been given if (is_array($Array)) { // Loop through the array, Find the Key foreach ($Array as $K => $V) { // Check if the current Key is which we are looking for if ($K == $Key) { // Check if result is empty if ($Result == '') { // Return the Current KeyName return $K; } else { // Return the result + KeyName return $Result . $Glue . $K; } } } // Loop through the array, go deeper in the array foreach ($Array as $K => $V) { // Only allow Arrays if (is_array($V)) { // Check for Results for each level we can $Result2 = ArrayKeyLocate($Array[$K], $Key, $Glue, $Result == '' ? $K : $Result . ',' . $K); // If the String ends with the Search Key Start returning value(s) if (EndsWith($Glue . $Key, $Result2) !== false) { // Return The position return $Result2; } } } } // Return the result return $Result == '' ? false : $Result; }
/** * HTML Menu Builder * * @version 1 * @author Rick de Man <*****@*****.**> * * @param string $S * The offset of the line, spaces and or tabs * @param array $Menu * The Multidimension Menu Array * @param string $Single * The Single HTML code * @param unknown $Multi * The Multi HTML code * @param boolean $UniteLink * Add link to parents link * @return string */ private function HTML_MenuBuild($S, $Menu, $Single, $Multi, $UniteLink = true) { // Create the Result variable $Result = ''; // Load function depth with a maxof 2 $FunctionDepth = GetFunctionDepth(2); // Loop throug each Menu items foreach ($Menu as $Index => $Item) { // Starting variables $Find = array(); $HasSub = false; $Replace = array(); $ResultTemp = ''; $SubMenu = array(); // Check if 'Item' has children foreach ($Item as $K => $V) { // Check if variable is an array if (is_array($V)) { // Detected array $HasSub = true; // Add Submenus $SubMenu[] = $V; } else { if ($K == 'data') { if ($V != '') { $Data = json_decode($V, true); } else { $Data = array(); } } else { // Add find string $Find[] = strtolower("{Menu:{$K}}"); // Add replace string $Replace[] = $V; } } } // Place offset for each line, Select Single or Multi Menu foreach (explode(EOLDB, $FunctionDepth == 1 ? $Single : $Multi) as $Line) { // Create result Elemnt $ResultTemp .= $S . $Line . EOL; } // if Unitelink is string and not the Main Parent Menu if (is_string($UniteLink) && $FunctionDepth != 1) { // Add the Parent link as starting URL $ResultTemp = str_replace('{menu:link}', $UniteLink . '{menu:link}', $ResultTemp); $this->Pages[$Item['ID']] = $UniteLink . $Item['link']; } else { $this->Pages[$Item['ID']] = $Item['link']; } if (isset($Data['insertAfter'])) { $ResultTemp .= $S . $Data['insertAfter'] . EOL; } // Replace Menu Tags $ResultTemp = str_replace($Find, $Replace, $ResultTemp); if (isset($Data['preg_replace'])) { $ResultTemp = preg_replace($Data['preg_replace']['find'], $Data['preg_replace']['replace'], $ResultTemp); } // Menu holds does not contain Children if ($HasSub == false) { // Remove '{sub/}' $ResultTemp = preg_replace('/([\\s]*){sub\\/}/im', '', $ResultTemp); // Remove '{haschildren}....{/haschildren}' $ResultTemp = preg_replace('/{haschildren}([\\s\\S]*?){\\/haschildren}/im', '', $ResultTemp); } // Menu contains Children if ($HasSub !== false) { // strip {haschildren} & {/haschildren}, keep string inbetween $ResultTemp = preg_replace('/{haschildren}([\\s\\S]*?){\\/haschildren}/im', "\$1", $ResultTemp); } // if a sub menu is allowed if (preg_match('/^([\\s]*){sub\\/}/im', $ResultTemp, $Match)) { // Check if UniteLink is not FALSE if ($UniteLink !== false) { // Check for Boolean || First level if (is_bool($UniteLink) || $FunctionDepth == 1) { // Starting URL $UniteLink = $Item['link'] . '/'; } else { // Append URL $UniteLink .= $Item['link'] . '/'; } } // Check if second Menu Code is not empty if ($Multi !== '') { // Create children $ResultTemp = preg_replace('/^([\\s]*){sub\\/}/im', $this->HTML_MenuBuild($Match[1], $SubMenu, $Single, $Multi, $UniteLink), $ResultTemp); } } // Add the Menu to the result $Result .= $ResultTemp; } // Delete Whitelines $Result = str_replace(EOL . EOL, EOL, $Result); // Return processed HTML string return $Result; }