X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fxml-functions.php;h=d09e8e11fae32792dc250b08d242ef77ec27cd19;hb=96979cf66a4fc49fda5842e59f475af377821cf9;hp=04550bc6da6afa1f1901b1efb6bbd93ff1cdc5b4;hpb=24dfb73f1de360ec03e9ad3a277e9cd78f3b61fc;p=mailer.git diff --git a/inc/xml-functions.php b/inc/xml-functions.php index 04550bc6da..d09e8e11fa 100644 --- a/inc/xml-functions.php +++ b/inc/xml-functions.php @@ -17,7 +17,7 @@ * -------------------------------------------------------------------- * * Copyright (c) 2003 - 2009 by Roland Haeder * * Copyright (c) 2009 - 2011 by Mailer Developer Team * - * For more information visit: http://www.mxchange.org * + * For more information visit: http://mxchange.org * * * * 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 * @@ -63,6 +63,13 @@ function showEntriesByXmlCallback ($template) { // Read it $templateContent = readFromFile($FQFN); + // Init main arrays + $GLOBALS['__XML_CALLBACKS'] = array( + 'callbacks' => array(), + 'functions' => array() + ); + $GLOBALS['__XML_ARGUMENTS'] = array(); + // Handle it over to the parser parseXmlData($templateContent); @@ -117,6 +124,15 @@ function doCallXmlCallbackFunction () { if ((isset($GLOBALS['__XML_CALLBACKS']['functions'][$callback])) && (isset($GLOBALS['__XML_ARGUMENTS'][$callback]))) { // Run all function callbacks foreach ($GLOBALS['__XML_CALLBACKS']['functions'][$callback] as $function) { + // Trim all function names + $function = trim($function); + + // If the function is empty, simply skip to the (maybe) next one + if (empty($function)) { + // Skip this + continue; + } // END - if + // Now construct the call-back function's name with 'Execute' at the end $callbackName = $callback . 'Execute'; @@ -135,9 +151,9 @@ function doCallXmlCallbackFunction () { } // END - foreach } -// ---------------------------------------------------------------------------- +//----------------------------------------------------------------------------- // Call-back functions for XML parser -// ---------------------------------------------------------------------------- +//----------------------------------------------------------------------------- // Starts an element function startXmlElement ($resource, $element, $attributes) { @@ -169,7 +185,9 @@ function xmlCharacterHandler ($resource, $characters) { // Nothing to handle return; } // END - if - die('characters[]='.strlen($characters)); + + // @TODO Handle characters + die(__FUNCTION__ . ':characters[]='.strlen($characters)); } // Checks if given type is valid, makes all lower-case @@ -178,7 +196,16 @@ function isInvalidXmlType ($type) { $type = strtolower(trim($type)); // Is it found? - return (in_array($type, array('string', 'array', 'bool'))); + return (in_array($type, array('string', 'array', 'bool', 'int', 'callback'))); +} + +// Checks if given condition is valid +function isXmlConditionValid ($condition) { + // Trim and make lower-case + $condition = trim(strtolower($condition)); + + // Is it valid? + return (in_array($condition, array('equals'))); } // Checks if given value is valid/verifyable @@ -196,5 +223,82 @@ function isXmlValueValid ($type, $value) { return call_user_func_array($callbackFunction, array($value)); } +// Converts given condition into a symbol +function convertXmlContion ($condition) { + // Default is an invalid one + $return = '???'; + + // Detect the condition again + switch ($condition) { + case 'EQUALS': // Equals + $return = '='; + break; + + default: // Unknown condition + debug_report_bug(__FUNCTION__, __LINE__, 'Condition ' . $condition . ' is unknown/unsupported.'); + break; + } // END - switch + + // Return it + return $return; +} + +// "Getter" for sql part back from given array +function getSqlPartFromXmlArray ($columns) { + // Init SQL + $SQL = ''; + + // Walk through all entries + foreach ($columns as $columnArray) { + // Init SQL part + $sqlPart = ''; + + // Do we have a table/alias + if (!empty($columnArray['table'])) { + // Pre-add it + $sqlPart .= $columnArray['table'] . '.'; + } // END - if + + // Add column + $sqlPart .= '`' . $columnArray['column'] . '`'; + + // Is a function and alias set? + if ((!empty($columnArray['function'])) && (!empty($columnArray['alias']))) { + // Add both + $sqlPart = $columnArray['function'] . '(' . $sqlPart . ') AS `' . $columnArray['alias'] . '`'; + } // END - if + + // Add finished SQL part to the query + $SQL .= $sqlPart . ','; + } // END - foreach + + // Return it without last commata + return substr($SQL, 0, -1); +} + +// Searches in given XML array for value and returns the parent index +function searchXmlArray ($value, $columns, $childKey) { + // Default is not found + $return = false; + + // Walk through whole array + foreach ($columns as $key => $columnArray) { + // Make sure the element is there + assert(isset($columnArray[$childKey])); + + // Now is it what we are looking for? + if ($columnArray[$childKey] == $value) { + // Remember this match + $return = $key; + + // And abort any further searches + break; + } // END - foreach + } // END - foreach + + // Return key/false + return $return; +} + // [EOF] ?>