From: Roland Häder Date: Sun, 21 Oct 2012 10:26:16 +0000 (+0000) Subject: Rewrote view/click.php to filter chains to allow other extensions (e.g. ext-forced... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=ed91696103e27286d50d5dcd9e6b6a6184dd3f16;p=mailer.git Rewrote view/click.php to filter chains to allow other extensions (e.g. ext-forced) to register own handlers --- diff --git a/click.php b/click.php index 2647b5f7fa..c3659428ea 100644 --- a/click.php +++ b/click.php @@ -51,22 +51,13 @@ require('inc/config-global.php'); // Set content type, this is required for search engines setContentType('text/html'); -// Check required parameters -if ((isGetRequestElementSet('user')) && (isGetRequestElementSet('banner'))) { - // Update clicks counter... - SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_refbanner` SET `clicks`=`clicks`+1 WHERE `id`=%s LIMIT 1", array(bigintval(getRequestElement('banner'))), __FILE__, __LINE__); - - // A line has been updated? - if ((!SQL_HASZEROAFFECTED()) && (isGetRequestElementSet('user'))) { - // Redirect to the user's referral link - redirectToUrl('ref.php?refid=' . bigintval(getRequestElement('user'))); - } // END - if -} // END - if +// Run filter chain +runFilterChain('handle_click_php'); // Load index page redirectToUrl('modules.php?module=index'); -// Shutdown +// Shutdown (if reached) doShutdown(); // [EOF] diff --git a/inc/extensions/ext-forced.php b/inc/extensions/ext-forced.php index b517e04259..9cfb71227e 100644 --- a/inc/extensions/ext-forced.php +++ b/inc/extensions/ext-forced.php @@ -144,6 +144,8 @@ INDEX (`forced_stats_userid`)", registerFilter(__FILE__, __LINE__, 'member_earning_table_data', 'FORCED_POPUP_TABLE_DATA', FALSE, TRUE, isExtensionDryRun()); registerFilter(__FILE__, __LINE__, 'post_change_forced_campaign_status', 'FORCED_CHANGE_CAMPAIGN_STATUS', FALSE, TRUE, isExtensionDryRun()); registerFilter(__FILE__, __LINE__, 'pre_change_forced_campaign_status', 'FORCED_CHANGE_CAMPAIGN_VALIDATE_DATA', FALSE, TRUE, isExtensionDryRun()); + registerFilter(__FILE__, __LINE__, 'handle_click_php', 'HANDLE_FORCED_AD_CLICK', FALSE, TRUE, isExtensionDryRun()); + registerFilter(__FILE__, __LINE__, 'handle_view_php', 'HANDLE_FORCED_AD_VIEW', FALSE, TRUE, isExtensionDryRun()); break; case 'remove': // Do stuff when removing extension @@ -168,6 +170,8 @@ INDEX (`forced_stats_userid`)", unregisterFilter(__FILE__, __LINE__, 'member_earning_table_data', 'FORCED_POPUP_TABLE_DATA', TRUE, isExtensionDryRun()); unregisterFilter(__FILE__, __LINE__, 'post_change_forced_campaign_status', 'FORCED_CHANGE_CAMPAIGN_STATUS', TRUE, isExtensionDryRun()); unregisterFilter(__FILE__, __LINE__, 'pre_change_forced_campaign_status', 'FORCED_CHANGE_CAMPAIGN_VALIDATE_DATA', TRUE, isExtensionDryRun()); + unregisterFilter(__FILE__, __LINE__, 'handle_click_php', 'HANDLE_FORCED_AD_CLICK', TRUE, isExtensionDryRun()); + unregisterFilter(__FILE__, __LINE__, 'handle_view_php', 'HANDLE_FORCED_AD_VIEW', TRUE, isExtensionDryRun()); break; case 'activate': // Do stuff when admin activates this extension diff --git a/inc/filter-functions.php b/inc/filter-functions.php index 946d0a5ef5..accd0c9475 100644 --- a/inc/filter-functions.php +++ b/inc/filter-functions.php @@ -198,6 +198,10 @@ ORDER BY // Build mails registerFilter(__FUNCTION__, __LINE__, 'send_build_mail', 'SEND_BUILD_MAIL'); + + // Handle referral banner click/view + registerFilter(__FUNCTION__, __LINE__, 'handle_click_php', 'HANDLE_REFERRER_BANNER_CLICK'); + registerFilter(__FUNCTION__, __LINE__, 'handle_view_php', 'HANDLE_REFERRER_BANNER_VIEW'); } // "Registers" a new filter function diff --git a/inc/filter/forced_filter.php b/inc/filter/forced_filter.php index d3843ca622..212ff2063f 100644 --- a/inc/filter/forced_filter.php +++ b/inc/filter/forced_filter.php @@ -119,5 +119,27 @@ function FILTER_FORCED_CHANGE_CAMPAIGN_VALIDATE_DATA ($filterData) { return $filterData; } +// Filter for handling click on forced ad +function FILTER_HANDLE_FORCED_AD_CLICK ($filterData) { + // Are all required parameters set? + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!'); + die(__FUNCTION__.': CALLED!'); + + // Return filter data + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!'); + return $filterData; +} + +// Filter for handling viewing forced banner +function FILTER_HANDLE_FORCED_AD_VIEW ($filterData) { + // Are all required parameters set? + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called!'); + die(__FUNCTION__.': CALLED!'); + + // Return filter data + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Done!'); + return $filterData; +} + // [EOF] ?> diff --git a/inc/filters.php b/inc/filters.php index 99152510cf..ccdd4176c7 100644 --- a/inc/filters.php +++ b/inc/filters.php @@ -1247,5 +1247,59 @@ function FILTER_SEND_BUILD_MAIL ($filterData) { return $filterData; } +// Handles click on referral banner +function FILTER_HANDLE_REFERRER_BANNER_CLICK ($filterData) { + // Check required parameters + if ((isGetRequestElementSet('user')) && (isGetRequestElementSet('banner'))) { + // Update clicks counter... + SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_refbanner` SET `clicks`=`clicks`+1 WHERE `id`=%s LIMIT 1", + array(bigintval(getRequestElement('banner'))), __FUNCTION__, __LINE__); + + // A line has been updated? + if ((!SQL_HASZEROAFFECTED()) && (isGetRequestElementSet('user'))) { + // Redirect to the user's referral link + redirectToUrl('ref.php?refid=' . bigintval(getRequestElement('user'))); + } // END - if + } // END - if + + // Return filter data + return $filterData; +} + +// Filter for handling viewing of a referral banner +function FILTER_HANDLE_REFERRER_BANNER_VIEW ($filterData) { + // Are all required parameters set + if ((isGetRequestElementSet('user')) && (isGetRequestElementSet('banner'))) { + // For later things... ;-) + $result = SQL_QUERY_ESC("SELECT `url` FROM `{?_MYSQL_PREFIX?}_refbanner` WHERE `id`=%s LIMIT 1", + array(bigintval(getRequestElement('banner'))), __FUNCTION__, __LINE__); + + // Is there the banner? + if (SQL_NUMROWS($result) == 1) { + // Load the URL + $data = SQL_FETCHARRAY($result); + + // Update counter + SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_refbanner` SET `counter`=`counter`+1 WHERE `id`=%s LIMIT 1", + array(bigintval(getRequestElement('banner'))), __FUNCTION__, __LINE__); + + // Set header and ... + setContentType('image/' . substr($data['url'], -3, 3)); + + // Redirect + redirectToUrl($data['url'], FALSE); + } else { + // @TODO No banner found, output some default banner + logDebugMessage(__FUNCTION__, __LINE__, 'Banner ' . bigintval(getRequestElement('banner')) . ' not dound.'); + } + + // Free memory + SQL_FREERESULT($result); + } else { + // Do nothing for now + redirectToUrl('modules.php?module=index'); + } +} + // [EOF] ?> diff --git a/inc/xml-functions.php b/inc/xml-functions.php index 6c5e5812a4..0d487f4e5b 100644 --- a/inc/xml-functions.php +++ b/inc/xml-functions.php @@ -40,8 +40,26 @@ if (!defined('__SECURITY')) { die(); } // END - if +// Init XML system +function initXml () { + // All conditions + $GLOBALS['__XML_CONDITIONS'] = array( + // Equals not + 'NOT-EQUALS' => ' != ', + // Is not + 'IS-NOT' => ' IS NOT ', + // Is + 'IS' => ' IS ', + // Equals + 'EQUALS' => ' = ', + ); +} + // Calls back a function based on given XML template data function showEntriesByXmlCallback ($template, $content = array(), $compileCode = TRUE) { + // Init XML system as sch calls will be only used once per run + initXml(); + // Generate FQFN for with special path $FQFN = sprintf("%stemplates/xml/%s%s.xml", getPath(), @@ -257,22 +275,13 @@ function isXmlValueValid ($type, $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 - reportBug(__FUNCTION__, __LINE__, 'Condition ' . $condition . ' is unknown/unsupported.'); - break; - } // END - switch + if (!isset($GLOBALS['__XML_CONDITIONS'][$condition])) { + reportBug(__FUNCTION__, __LINE__, 'Condition ' . $condition . ' is unknown/unsupported.'); + } // END - if // Return it - return $return; + return $GLOBALS['__XML_CONDITIONS'][$condition]; } // "Getter" for sql part back from given array diff --git a/view.php b/view.php index afbdbff05c..512dea7019 100644 --- a/view.php +++ b/view.php @@ -48,36 +48,8 @@ $GLOBALS['__output_mode'] = -1; // Load the required file(s) require('inc/config-global.php'); -if ((isGetRequestElementSet('user')) && (isGetRequestElementSet('banner'))) { - // For later things... ;-) - $result = SQL_QUERY_ESC("SELECT `url` FROM `{?_MYSQL_PREFIX?}_refbanner` WHERE `id`=%s LIMIT 1", - array(bigintval(getRequestElement('banner'))), __FILE__, __LINE__); - - // Is there the banner? - if (SQL_NUMROWS($result) == 1) { - // Load the URL - $data = SQL_FETCHARRAY($result); - - // Update counter - SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_refbanner` SET `counter`=`counter`+1 WHERE `id`=%s LIMIT 1", - array(bigintval(getRequestElement('banner'))), __FILE__, __LINE__); - - // Set header and ... - setContentType('image/' . substr($data['url'], -3, 3)); - - // Redirect - redirectToUrl($data['url'], FALSE); - } else { - // @TODO No banner found, output some default banner - logDebugMessage(__FILE__, __LINE__, 'Banner ' . bigintval(getRequestElement('banner')) . ' not dound.'); - } - - // Free memory - SQL_FREERESULT($result); -} else { - // Do nothing for now - redirectToUrl('modules.php?module=index'); -} +// Run filter chain +runFilterChain('handle_view_php'); // Shutdown doShutdown();