X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fxml-functions.php;h=9506a93e815489250b42c03d77a53444f54caa2d;hb=77669502ccc2779d32a842f6d523fb68169fadda;hp=f62de6a6e8d1d59adaee34c4a6709b880d0424e4;hpb=f97544ccd404280919e2d08a9e4a19e61167277f;p=mailer.git diff --git a/inc/xml-functions.php b/inc/xml-functions.php index f62de6a6e8..9506a93e81 100644 --- a/inc/xml-functions.php +++ b/inc/xml-functions.php @@ -79,15 +79,15 @@ function doGenericXmlTemplateCallback ($template, $content = array(), $compileCo // Is it again readable? if (isFileReadable($FQFN)) { // Is there cache? - if ((!isDebuggingTemplateCache()) && (isTemplateCached('xml', $template))) { + if ((!isDebugTemplateCacheEnabled()) && (isTemplateCached('xml', $template))) { // Evaluate the cache - eval(readTemplateCache('xml', $template)); + $templateContent = readTemplateCache('xml', $template, $content); } else { // Read it $templateContent = readFromFile($FQFN); // Prepare it for finaly eval() command - $GLOBALS['template_eval']['xml'][$template] = '$templateContent = decodeEntities("' . compileRawCode(escapeJavaScriptQuotes($templateContent), FALSE, TRUE, TRUE, $compileCode) . '");'; + $GLOBALS['template_eval']['xml'][$template] = '$templateContent = decodeEntities("' . compileRawCode(escapeJavaScriptQuotes($templateContent), TRUE, $compileCode) . '");'; // Eval the code, this does insert any array elements from $content eval($GLOBALS['template_eval']['xml'][$template]); @@ -100,6 +100,7 @@ function doGenericXmlTemplateCallback ($template, $content = array(), $compileCo ); $GLOBALS['__XML_ARGUMENTS'] = array(); $GLOBALS['__COLUMN_INDEX'] = array(); + $GLOBALS['__XML_CONTENT'] = $content; // Handle it over to the parser parseXmlData($templateContent); @@ -108,7 +109,7 @@ function doGenericXmlTemplateCallback ($template, $content = array(), $compileCo addXmlSpecialElements($template); // Call the call-back function - doCallXmlCallbackFunction(); + doCallXmlCallbackFunction($content); } else { // Template not found displayMessage('{%message,XML_TEMPLATE_404=' . $template . '%}'); @@ -135,7 +136,7 @@ function parseXmlData ($content) { // Is there recode? if (!function_exists('recode')) { // No fallback ATM - reportBug('PHP extension recode is missing. Please install it.'); + reportBug(__FUNCTION__, __LINE__, 'PHP extension recode is missing. Please install it.'); } // END - if // Convert HTML entities to UTF-8 @@ -188,11 +189,11 @@ function doCallXmlCallbackFunction () { // Is it there? if (!function_exists($callbackName)) { // No, then please add it - reportBug(__FUNCTION__, __LINE__, 'callback=' . $callback . ',function=' . $function . 'arguments()=' . count($GLOBALS['__XML_ARGUMENTS'][$callback]) . ' - execute call-back does not exist.'); + reportBug(__FUNCTION__, __LINE__, 'callback=' . $callback . ',function=' . $function . ',arguments()=' . count($GLOBALS['__XML_ARGUMENTS'][$callback]) . ',content()=' . count($GLOBALS['__XML_CONTENT']) . ' - execute call-back does not exist.'); } // END - if // Call it - call_user_func_array($callbackName, array($function, $GLOBALS['__XML_ARGUMENTS'][$callback], $GLOBALS['__COLUMN_INDEX'][$callback])); + call_user_func_array($callbackName, array($function, $GLOBALS['__XML_ARGUMENTS'][$callback], $GLOBALS['__COLUMN_INDEX'][$callback], $GLOBALS['__XML_CONTENT'])); } // END - foreach } else { // Not found @@ -231,13 +232,13 @@ function xmlCharacterHandler ($resource, $characters) { $characters = trim($characters); // Are there some to handle? - if (strlen($characters) == 0) { + if (empty($characters)) { // Nothing to handle return; } // END - if // @TODO Handle characters - die(__FUNCTION__ . ':characters[]='.strlen($characters)); + die(__FUNCTION__ . ':characters[' . gettype($characters) . ']=' . strlen($characters)); } // Checks if given type is valid, makes all lower-case @@ -255,7 +256,7 @@ function isXmlConditionValid ($condition) { $condition = trim(strtolower($condition)); // Is it valid? - return (in_array($condition, array('equals'))); + return (in_array($condition, array('equals', 'and'))); } // Checks if given value is valid/verifyable @@ -284,20 +285,38 @@ function convertXmlContion ($condition) { return $GLOBALS['__XML_CONDITIONS'][$condition]; } +// "Getter" for FROM statement from given columns +function getSqlXmlFromTable ($tableName) { + // Init SQL + $sql = ' FROM `{?_MYSQL_PREFIX?}_' . $tableName[0]['value'] . '`'; + + // Is alias set? + if (!empty($tableName[0]['alias'])) { + // Also add it + $sql .= ' AS `' . $tableName[0]['alias'] . '`'; + } // END - if + + // Return SQL + return $sql; +} + // "Getter" for sql part back from given array function getSqlPartFromXmlArray ($columns) { // Init SQL - $SQL = ''; + $sql = ''; // Walk through all entries foreach ($columns as $columnArray) { + // Must be an array + assert(is_array($columnArray)); + // Init SQL part $sqlPart = ''; // Is there a table/alias if (!empty($columnArray['table'])) { // Pre-add it - $sqlPart .= $columnArray['table'] . '.'; + $sqlPart .= '`' . $columnArray['table'] . '`.'; } // END - if // Add column @@ -310,11 +329,130 @@ function getSqlPartFromXmlArray ($columns) { } // END - if // Add finished SQL part to the query - $SQL .= $sqlPart . ','; + $sql .= $sqlPart . ','; } // END - foreach // Return it without last commata - return substr($SQL, 0, -1); + return substr($sql, 0, -1); +} + +// "Getter" for JOIN statement +function getSqlXmlJoinedTable ($tableJoinType, $tableJoinName, $joinOnLeftTable, $joinOnCondition, $joinOnRightTable) { + // Are all set? + assert((count($tableJoinType) > 0) && (count($tableJoinName) > 0) && (count($joinOnLeftTable) > 0) && (count($joinOnCondition) > 0) && (count($joinOnRightTable) > 0)); + + // Init SQL + $sql = ''; + + // "Walk" through all JOINs + foreach ($tableJoinType as $key => $joinType) { + // 1) Add JOIN type and table name with alias + $sql .= ' ' . $joinType . ' `{?_MYSQL_PREFIX?}_' . $tableJoinName[$key]['name'] . '`'; + + // Alias set? + if (!empty($tableJoinName[$key]['alias'])) { + // Add it + $sql .= ' AS `' . $tableJoinName[$key]['alias'] . '`'; + } // END - if + + // 2) Add left part + condition + right part with aliases + // 2/1) ON + left part + $sql .= ' ON `' . $joinOnLeftTable[$key]['name'] . '`.`' . $joinOnLeftTable[$key]['column'] . '`'; + // 2/2) Condition + $sql .= $joinOnCondition[$key]; + // 2/3) right part + $sql .= '`' . $joinOnRightTable[$key]['name'] . '`.`' . $joinOnRightTable[$key]['column'] . '`'; + } // END - foreach + + // Return SQL + return $sql; +} + +// "Getter" for WHERE statement from given columns and conditions arrays +function getSqlXmlWhereConditions ($whereColumns, $conditions) { + // Init SQL + $sql = ''; + + // Are there some conditions? + if (count($whereColumns) > 0) { + // Then add these as well + if (count($whereColumns) == 1) { + // One entry found + $sql .= ' WHERE '; + + // Table/alias included? + if (!empty($whereColumns[0]['table'])) { + // Add it as well + $sql .= $whereColumns[0]['table'] . '.'; + } // END - if + + // Add the rest + $sql .= '`' . $whereColumns[0]['column'] . '`' . $whereColumns[0]['condition'] . chr(39) . $whereColumns[0]['look_for'] . chr(39); + } elseif ((count($whereColumns > 1)) && (count($conditions) > 0)) { + // More than one "WHERE" + condition found + foreach ($whereColumns as $idx => $columnArray) { + // Default is WHERE + $condition = ' WHERE '; + + // Is the condition element there? + if (isset($conditions[$columnArray['column']])) { + // Assume the condition + $condition .= ' ' . $conditions[$columnArray['column']] . ' '; + } // END - if + + // Add to SQL query + die($sql.'/'.$condition); + $sql .= $condition; + + // Table/alias included? + if (!empty($whereColumns[$idx]['table'])) { + // Add it as well + $sql .= $whereColumns[$idx]['table'] . '.'; + } // END - if + + // Add the rest + $sql .= '`' . $whereColumns[$idx]['column'] . '`' . $whereColumns[$idx]['condition'] . chr(39) . convertDollarDataToGetElement($whereColumns[$idx]['look_for']) . chr(39); + } // END - foreach + } else { + // Did not set $conditions + reportBug(__FUNCTION__, __LINE__, 'Supplied more than "whereColumns" entries but no conditions! Please fix your XML template.'); + } + } // END - if + + // Return SQL + return $sql; +} + +// "Getter" for ORDER BY statement from given columns +function getSqlXmlOrderBy ($orderByColumns) { + // Init SQL + $sql = ''; + + // Are there entries from orderByColumns to add? + if (count($orderByColumns) > 0) { + // Add them as well + $sql .= ' ORDER BY '; + foreach ($orderByColumns as $orderByColumn => $array) { + // Get keys (table/alias) and values (sorting itself) + $table = trim(implode('', array_keys($array))); + $sorting = trim(implode('', array_values($array))); + + // table/alias can be omitted + if (!empty($table)) { + // table/alias is given + $sql .= '`' . $table . '`.'; + } // END - if + + // Add order-by column + $sql .= '`' . $orderByColumn . '` ' . $sorting . ','; + } // END - foreach + + // Remove last column + $sql = substr($sql, 0, -1); + } // END - if + + // Return SQL + return $sql; } // Searches in given XML array for value and returns the parent index @@ -328,7 +466,8 @@ function searchXmlArray ($value, $columns, $childKey) { assert(isset($columnArray[$childKey])); // Now is it what we are looking for? - if ($columnArray[$childKey] == $value) { + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'value=' . $value . ',key=' . $key . ',childKey=' . $childKey . ',columnArray=' . $columnArray[$childKey]); + if ($columnArray[$childKey] === $value) { // Remember this match $return = $key;