From: quix0r Date: Mon, 11 Jul 2011 13:59:45 +0000 (+0000) Subject: Extension ext-surfbar continued, WHERE statement support added: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=5772d38cdfdabb4ccedb6e2152fc0fb20c08417d;p=mailer.git Extension ext-surfbar continued, WHERE statement support added: - Unlocking surfbar URLs is now XML-enabled - Support for one WHERE condition in XML templates added - TODOs.txt updated --- diff --git a/DOCS/TODOs.txt b/DOCS/TODOs.txt index ffe0330d6b..90f60d4c2e 100644 --- a/DOCS/TODOs.txt +++ b/DOCS/TODOs.txt @@ -98,8 +98,7 @@ ./inc/mails/doubler_mails.php:53:// @TODO Can this be rewritten to a filter? ./inc/module-functions.php:267: // @TODO Nothing helped??? ./inc/module-functions.php:308: // @TODO Rewrite this to a filter -./inc/modules/admin/admin-inc.php:1159: // @TODO WHERE is not yet supported -./inc/modules/admin/admin-inc.php:1213: // @TODO If we can rewrite the EL sub-system to support more than one parameter, this call_user_func_array() can be avoided +./inc/modules/admin/admin-inc.php:1227: // @TODO If we can rewrite the EL sub-system to support more than one parameter, this call_user_func_array() can be avoided ./inc/modules/admin/admin-inc.php:171: // @TODO This and the next getCurrentAdminId() call might be moved into the templates? ./inc/modules/admin/admin-inc.php:242: // @TODO This can be rewritten into a filter ./inc/modules/admin/admin-inc.php:274: // @TODO Rewrite this to $content = SQL_FETCHARRAY() diff --git a/inc/callback-functions.php b/inc/callback-functions.php index 59c06e66ec..aad0498b59 100644 --- a/inc/callback-functions.php +++ b/inc/callback-functions.php @@ -628,6 +628,54 @@ function doXmlWhereSelectFromList ($resource, $attributes) { $GLOBALS['__XML_ARGUMENTS']['doXmlCallbackFunction']['where_select_list'] = array(); } +// Handles the XML node 'where-select-from-list-entry' +function doXmlWhereSelectFromListEntry ($resource, $attributes) { + // There are five attributes, by default + if (count($attributes) != 5) { + // Not the right count + debug_report_bug(__FUNCTION__, __LINE__, 'Expected 5 attributes, got ' . count($attributes)); + } elseif (!isset($attributes['TYPE'])) { + // 'TYPE' not found + debug_report_bug(__FUNCTION__, __LINE__, 'Required attribute TYPE not found.'); + } elseif (!isset($attributes['TABLE'])) { + // 'TABLE' not found + debug_report_bug(__FUNCTION__, __LINE__, 'Required attribute TABLE not found.'); + } elseif (!isset($attributes['VALUE'])) { + // 'VALUE' not found + debug_report_bug(__FUNCTION__, __LINE__, 'Required attribute VALUE not found.'); + } elseif (!isset($attributes['CONDITION'])) { + // 'CONDITION' not found + debug_report_bug(__FUNCTION__, __LINE__, 'Required attribute CONDITION not found.'); + } elseif (!isset($attributes['LOOK-FOR'])) { + // 'LOOK-FOR' not found + debug_report_bug(__FUNCTION__, __LINE__, 'Required attribute LOOK-FOR not found.'); + } elseif (!isInvalidXmlType($attributes['TYPE'])) { + // No valid type + debug_report_bug(__FUNCTION__, __LINE__, 'TYPE is not valid, got: ' . $attributes['TYPE']); + } elseif ((trim($attributes['TABLE']) != '') && (!isXmlValueValid($attributes['TYPE'], $attributes['TABLE']))) { + // 'TABLE' not valid/verifyable + debug_report_bug(__FUNCTION__, __LINE__, 'Attribute TABLE does not validate. TABLE=' . $attributes['TABLE']); + } elseif (!isXmlValueValid($attributes['TYPE'], $attributes['VALUE'])) { + // 'VALUE' not valid/verifyable + debug_report_bug(__FUNCTION__, __LINE__, 'Attribute VALUE does not validate. VALUE=' . $attributes['VALUE']); + } elseif (!isXmlValueValid($attributes['TYPE'], $attributes['CONDITION'])) { + // 'CONDITION' not valid/verifyable + debug_report_bug(__FUNCTION__, __LINE__, 'Attribute CONDITION does not validate. CONDITION=' . $attributes['CONDITION']); + } elseif (!isXmlValueValid($attributes['TYPE'], $attributes['LOOK-FOR'])) { + // 'LOOK-FOR' not valid/verifyable + debug_report_bug(__FUNCTION__, __LINE__, 'Attribute LOOK-FOR does not validate. LOOK-FOR=' . $attributes['LOOK-FOR']); + } elseif (!isXmlConditionValid($attributes['CONDITION'])) { + // 'CONDITION' is not known + debug_report_bug(__FUNCTION__, __LINE__, 'Attribute CONDITION is not valid. LOOK-FOR=' . $attributes['CONDITION']); + } elseif (!isset($GLOBALS['__XML_ARGUMENTS']['doXmlCallbackFunction']['data_column_list'])) { + // doXmlCallbackFunction is missing + debug_report_bug(__FUNCTION__, __LINE__, 'Required XML node callback-function/data-column-list not included around this node. Please fix your XML.'); + } + + // Add the entry to the array + addXmlValueToCallbackAttributes('where_select_list', $attributes); +} + // Handles the XML node 'order-by-list' function doXmlOrderByList ($resource, $attributes) { // There should be no attributes @@ -655,15 +703,15 @@ function doXmlOrderByListEntry ($resource, $attributes) { } elseif (!isset($attributes['TYPE'])) { // 'TYPE' not found debug_report_bug(__FUNCTION__, __LINE__, 'Required attribute TYPE not found.'); - } elseif (!isInvalidXmlType($attributes['TYPE'])) { - // No valid type - debug_report_bug(__FUNCTION__, __LINE__, 'TYPE is not valid, got: ' . $attributes['TYPE']); } elseif (!isset($attributes['TABLE'])) { // 'TABLE' not found debug_report_bug(__FUNCTION__, __LINE__, 'Required attribute TABLE not found.'); } elseif (!isset($attributes['VALUE'])) { // 'VALUE' not found debug_report_bug(__FUNCTION__, __LINE__, 'Required attribute VALUE not found.'); + } elseif (!isInvalidXmlType($attributes['TYPE'])) { + // No valid type + debug_report_bug(__FUNCTION__, __LINE__, 'TYPE is not valid, got: ' . $attributes['TYPE']); } elseif (!isXmlValueValid($attributes['TYPE'], $attributes['ORDER'])) { // 'ORDER' not valid/verifyable debug_report_bug(__FUNCTION__, __LINE__, 'Attribute ORDER does not validate. ORDER=' . $attributes['ORDER']); @@ -928,15 +976,15 @@ function addXmlValueToCallbackAttributes ($element, $attributes, $extraKey = '', /* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element=' . $element . ',extraKey=' . $extraKey . ',TYPE=' . $attributes['TYPE'] . ' - ANALYSING...'); if (trim($attributes['NAME']) == '') { // Numerical index - /* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element=' . $element . ',extraKey=' . $extraKey . ',TYPE=' . $attributes['TYPE'].',VALUE[' . gettype($attributes['VALUE']) . ']=' . $attributes['VALUE'] . ' - NUMERICAL!'); + /* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element=' . $element . ',extraKey=' . $extraKey . ',TYPE=' . $attributes['TYPE'] . ',VALUE[' . gettype($attributes['VALUE']) . ']=' . $attributes['VALUE'] . ' - NUMERICAL!'); $GLOBALS['__XML_ARGUMENTS']['doXmlCallbackFunction'][$element][$extraKey][] = $attributes['VALUE']; } elseif (!empty($key)) { // Use from $key - /* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element=' . $element . ',extraKey=' . $extraKey . ',TYPE=' . $attributes['TYPE'].',VALUE[' . gettype($attributes['VALUE']) . ']=' . $attributes['VALUE'] . ' - KEY! (key=' . $attributes[$key] . ')'); + /* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element=' . $element . ',extraKey=' . $extraKey . ',TYPE=' . $attributes['TYPE'] . ',VALUE[' . gettype($attributes['VALUE']) . ']=' . $attributes['VALUE'] . ' - KEY! (key=' . $attributes[$key] . ')'); $GLOBALS['__XML_ARGUMENTS']['doXmlCallbackFunction'][$element][$extraKey][$attributes[$key]] = $attributes['VALUE']; } else { // Use from NAME - /* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element=' . $element . ',extraKey=' . $extraKey . ',TYPE=' . $attributes['TYPE'].',VALUE[' . gettype($attributes['VALUE']) . ']=' . $attributes['VALUE'] . ' - NAME! (NAME=' . $attributes['NAME'] . ')'); + /* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element=' . $element . ',extraKey=' . $extraKey . ',TYPE=' . $attributes['TYPE'] . ',VALUE[' . gettype($attributes['VALUE']) . ']=' . $attributes['VALUE'] . ' - NAME! (NAME=' . $attributes['NAME'] . ')'); $GLOBALS['__XML_ARGUMENTS']['doXmlCallbackFunction'][$element][$extraKey][$attributes['NAME']] = $attributes['VALUE']; } } elseif ((isset($attributes['FUNCTION'])) && (isset($attributes['ALIAS']))) { @@ -953,15 +1001,27 @@ function addXmlValueToCallbackAttributes ($element, $attributes, $extraKey = '', ); // Add the entry - /* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element=' . $element . ',extraKey=' . $extraKey . ',TYPE=' . $attributes['TYPE'].',ALIAS[' . gettype($attributes['ALIAS']) . ']=' . $attributes['ALIAS'] . ',FUNCTION[' . gettype($attributes['FUNCTION']) . ']=' . $attributes['FUNCTION'] . ' - FUNCTION! (VALUE=' . $attributes['VALUE'] . ')'); + /* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element=' . $element . ',extraKey=' . $extraKey . ',TYPE=' . $attributes['TYPE'] . ',ALIAS[' . gettype($attributes['ALIAS']) . ']=' . $attributes['ALIAS'] . ',FUNCTION[' . gettype($attributes['FUNCTION']) . ']=' . $attributes['FUNCTION'] . ' - FUNCTION! (VALUE=' . $attributes['VALUE'] . ')'); + $GLOBALS['__XML_ARGUMENTS']['doXmlCallbackFunction'][$element][] = $array; + } elseif ((isset($attributes['CONDITION'])) && (isset($attributes['LOOK-FOR']))) { + // CONDITION/LOOK-FOR detected + // Init array + $array = array( + 'column' => trim($attributes['VALUE']), + 'table' => trim($attributes['TABLE']), + 'condition' => convertXmlContion(trim($attributes['CONDITION'])), + 'look_for' => trim($attributes['LOOK-FOR']) + ); + + /* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element=' . $element . ',extraKey=' . $extraKey . ',TYPE=' . $attributes['TYPE'] . ',CONDITION[' . gettype($attributes['CONDITION']) . ']=' . $attributes['CONDITION'] . ',LOOK-FOR[' . gettype($attributes['LOOK-FOR']) . ']=' . $attributes['LOOK-FOR'] . ' - CONDITION! (VALUE=' . $attributes['VALUE'] . ')'); $GLOBALS['__XML_ARGUMENTS']['doXmlCallbackFunction'][$element][] = $array; } elseif (isset($attributes['CALLBACK'])) { // CALLBACK/VALUE detected - /* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element=' . $element . ',extraKey=' . $extraKey . ',TYPE=' . $attributes['TYPE'].',CALLBACK[' . gettype($attributes['CALLBACK']) . ']=' . $attributes['CALLBACK'] . ' - CALLBACK! (VALUE=' . $attributes['VALUE'] . ')'); + /* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element=' . $element . ',extraKey=' . $extraKey . ',TYPE=' . $attributes['TYPE'] . ',CALLBACK[' . gettype($attributes['CALLBACK']) . ']=' . $attributes['CALLBACK'] . ' - CALLBACK! (VALUE=' . $attributes['VALUE'] . ')'); $GLOBALS['__XML_ARGUMENTS']['doXmlCallbackFunction'][$element][$attributes['VALUE']] = $attributes['CALLBACK']; } elseif (isset($attributes['ORDER'])) { // ORDER/TABLE detected - /* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element=' . $element . ',extraKey=' . $extraKey . ',TYPE=' . $attributes['TYPE'].',ORDER[' . gettype($attributes['ORDER']) . ']=' . $attributes['ORDER'] . ' - ORDER! (VALUE=' . $attributes['VALUE'] . ')'); + /* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element=' . $element . ',extraKey=' . $extraKey . ',TYPE=' . $attributes['TYPE'] . ',ORDER[' . gettype($attributes['ORDER']) . ']=' . $attributes['ORDER'] . ' - ORDER! (VALUE=' . $attributes['VALUE'] . ')'); $GLOBALS['__XML_ARGUMENTS']['doXmlCallbackFunction'][$element][$attributes['ORDER']][$attributes['TABLE']] = $attributes['VALUE']; } elseif (isset($attributes['COLUMN'])) { // COLUMN/VALUE detected diff --git a/inc/modules/admin/admin-inc.php b/inc/modules/admin/admin-inc.php index 5a23e398d0..d762abd90d 100644 --- a/inc/modules/admin/admin-inc.php +++ b/inc/modules/admin/admin-inc.php @@ -1156,8 +1156,22 @@ function adminListEntries ($tableTemplate, $rowTemplate, $noEntryMessageId, $tab // Do we have entries from whereColumns to add? if (count($whereColumns) > 0) { // Then add these as well - // @TODO WHERE is not yet supported - debug_report_bug(__FUNCTION__, __LINE__, 'Unfinished area, please report your XML to the forums or bug tracker. tableTemplate=' . $tableTemplate . ',rowTemplate=' . $rowTemplate . ',tableName[0]=' . $tableName[0]); + 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'] . "'" . $whereColumns[0]['look_for'] . "'"; + } else { + // More than one entry -> Unsupported + debug_report_bug(__FUNCTION__, __LINE__, 'More than one WHERE statement found. This is currently not supported.'); + } } // END - if // Do we have entries from orderByColumns to add? @@ -1188,7 +1202,7 @@ function adminListEntries ($tableTemplate, $rowTemplate, $noEntryMessageId, $tab } // Do the listing of entries -function doAdminListEntries($SQL, $tableTemplate, $noEntryMessageId, $rowTemplate, $callbackColumns, $extraParameters = array()) { +function doAdminListEntries ($SQL, $tableTemplate, $noEntryMessageId, $rowTemplate, $callbackColumns, $extraParameters = array()) { // Run the SQL query $result = SQL_QUERY($SQL, __FUNCTION__, __LINE__); diff --git a/inc/modules/admin/what-unlock_surfbar_urls.php b/inc/modules/admin/what-unlock_surfbar_urls.php index 5b0d0066e3..6e94af3dc8 100644 --- a/inc/modules/admin/what-unlock_surfbar_urls.php +++ b/inc/modules/admin/what-unlock_surfbar_urls.php @@ -64,40 +64,8 @@ if ((isPostRequestParameterSet('unlock')) && (is_array(postRequestParameter('url } } -// List all URLs -$result = SQL_QUERY("SELECT - `url_id`, - `url_userid`, - `url`, - UNIX_TIMESTAMP(`url_registered`) AS `url_registered` -FROM - `{?_MYSQL_PREFIX?}_surfbar_urls` -WHERE - `url_status`='PENDING' -ORDER BY - `url_id` ASC", __FILE__, __LINE__); - -// Do we have some URLs left? -if (!SQL_HASZERONUMS($result)) { - // List all URLs - $OUT = ''; - while ($content = SQL_FETCHARRAY($result)) { - // "Translate"/add content - $content['url_registered'] = generateDateTime($content['url_registered'], 2); - - // Load row template - $OUT .= loadTemplate('admin_unlock_surfbar_urls_row', true, $content); - } // END - while - - // Load main template - loadTemplate('admin_unlock_surfbar_urls', false, $OUT); -} else { - // No URLs in surfbar - displayMessage('{--ADMIN_SURFBAR_NO_URLS_FOUND--}'); -} - -// Free result -SQL_FREERESULT($result); +// List all pendingURLs +showEntriesByXmlCallback('admin_unlock_surfbar_urls'); // [EOF] ?> diff --git a/inc/xml-functions.php b/inc/xml-functions.php index 8958bdb157..f2de150926 100644 --- a/inc/xml-functions.php +++ b/inc/xml-functions.php @@ -197,6 +197,15 @@ function isInvalidXmlType ($type) { return (in_array($type, array('string', 'array', 'bool', 'int'))); } +// 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 function isXmlValueValid ($type, $value) { // Depends on type, so build a call-back @@ -212,5 +221,25 @@ 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; +} + // [EOF] ?> diff --git a/templates/xml/admin/admin_unlock_surfbar_urls.xml b/templates/xml/admin/admin_unlock_surfbar_urls.xml new file mode 100644 index 0000000000..4fbadeed7d --- /dev/null +++ b/templates/xml/admin/admin_unlock_surfbar_urls.xml @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/templates/xml/admin_list_data_template.xml b/templates/xml/admin_list_data_template.xml index 8fc22d2a10..16f5d58563 100644 --- a/templates/xml/admin_list_data_template.xml +++ b/templates/xml/admin_list_data_template.xml @@ -113,11 +113,11 @@ MA 02110-1301 USA - +