Changeset 2229158
- Timestamp:
- 01/17/2020 01:35:28 PM (6 years ago)
- Location:
- addefend-easy-integration
- Files:
-
- 3 edited
- 4 copied
-
tags/1.8 (copied) (copied from addefend-easy-integration/trunk)
-
tags/1.8/Components/script_integration.php (copied) (copied from addefend-easy-integration/trunk/Components/script_integration.php) (4 diffs)
-
tags/1.8/addefend-easy-integration.php (copied) (copied from addefend-easy-integration/trunk/addefend-easy-integration.php) (1 diff)
-
tags/1.8/readme.txt (copied) (copied from addefend-easy-integration/trunk/readme.txt) (2 diffs)
-
trunk/Components/script_integration.php (modified) (4 diffs)
-
trunk/addefend-easy-integration.php (modified) (1 diff)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
addefend-easy-integration/tags/1.8/Components/script_integration.php
r2227678 r2229158 2 2 3 3 global $wpdb; 4 define( 'ADDEFEND_TABLE_NAME', $wpdb->prefix . "addefend" ); 5 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); 4 define('ADDEFEND_TABLE_NAME', $wpdb->prefix . "addefend"); 5 define('ADDEFEND_SCRIPT_UPDATE_FREQUENCY_IN_SEC', 5*60); 6 require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); 6 7 7 8 // create the addefend table … … 13 14 id mediumint(9) NOT NULL, 14 15 script longtext NOT NULL, 16 timestamp int NOT NULL, 15 17 PRIMARY KEY (id) 16 18 ) $charset_collate;"; 17 dbDelta( $sql);19 dbDelta($sql); 18 20 } 19 21 20 // add custom cron schedules 21 add_filter( 'cron_schedules', 'addefend_add_script_update_frequency'); 22 function addefend_add_script_update_frequency($schedules ) { 23 if(!isset($schedules['everyfiveminutes'])) { 24 $schedules['everyfiveminutes'] = array( 25 'interval' => 300, 26 'display' => __('Every Five Minutes') 27 ); 28 } 29 if(!isset($schedules['every10seconds'])) { 30 // this is for testing 31 $schedules['every10seconds'] = array( 32 'interval' => 10, 33 'display' => __('Every ten Seconds') 34 ); 35 } 36 return $schedules; 37 } 38 // activate the scheduling when the plugin is activated 39 register_activation_hook(ADDEFEND_PLUGIN_PHP_FILE, 'addefend_activate_scheduling'); 40 function addefend_activate_scheduling() { 41 if ( !wp_next_scheduled( 'out_of_date_script' ) ) { 42 wp_schedule_event( time(), 'everyfiveminutes', 'out_of_date_script'); 43 } 44 } 45 46 // the new script is being stored in a dedicated table in the wordpress database 47 add_action('out_of_date_script', 'download_addefend_script'); 22 register_activation_hook(ADDEFEND_PLUGIN_PHP_FILE, 'download_addefend_script'); 48 23 function download_addefend_script() { 49 addefend_log('ADDEFEND -- TRACE : download_addefend_script() !');50 $script_URL = get_option( 'addefend_script_URL');24 // the new script is being stored in a dedicated table in the wordpress database 25 $script_URL = get_option('addefend_script_URL'); 51 26 // API call 52 27 $response = wp_remote_get($script_URL); 53 28 // handling the response 54 if (is_wp_error( $response) || wp_remote_retrieve_response_code($response) == 404){29 if (is_wp_error($response) || wp_remote_retrieve_response_code($response) == 404){ 55 30 if ( is_wp_error( $response ) ) { 56 31 $error_string = $response->get_error_message(); … … 68 43 array( 69 44 'id' => '1', 70 'script' => $new_script 45 'script' => $new_script, 46 'timestamp' => time() 71 47 ) 72 48 ); … … 83 59 function inject_addefend_script(){ 84 60 global $wpdb; 85 $addefend_script = $wpdb->get_var("SELECT script FROM ".ADDEFEND_TABLE_NAME." WHERE (id = '1')"); 86 if(!$addefend_script){ 61 extract($wpdb->get_row("SELECT script AS addefend_script, timestamp AS addefend_script_timestamp FROM ".ADDEFEND_TABLE_NAME." WHERE (id = '1')", "ARRAY_A")); 62 if($addefend_script && $addefend_script_timestamp){ 63 $addefend_script_age = time() - $addefend_script_timestamp; 64 echo '<script type="text/javascript">' . $addefend_script . '</script>'; 65 addefend_log('ADDEFEND -- TRACE : A ' . $addefend_script_age . ' seconds old script was injected in the footer'); 66 if ($addefend_script_age < ADDEFEND_SCRIPT_UPDATE_FREQUENCY_IN_SEC) { 67 $nextScriptUpdateDate = $addefend_script_timestamp + ADDEFEND_SCRIPT_UPDATE_FREQUENCY_IN_SEC; 68 addefend_log('ADDEFEND -- TRACE : the next script update is scheduled for ' . date('l jS \of F Y h:i:s A (e)', $nextScriptUpdateDate)); 69 } else { 70 download_addefend_script(); 71 } 72 } else { 87 73 addefend_log('ADDEFEND -- ERROR : Failed to retrieve the script from the database'); 88 }else{ 89 echo '<script type="text/javascript">'.$addefend_script.'</script>'; 90 addefend_log('ADDEFEND -- TRACE : Script injected in the footer'); 91 } 92 $nextScriptUpdateDate = wp_next_scheduled( 'out_of_date_script' ); 93 if ( $nextScriptUpdateDate ) { 94 addefend_log('ADDEFEND -- TRACE : the next script update is scheduled for ' . date('l jS \of F Y h:i:s A', $nextScriptUpdateDate)); 95 } else { 96 addefend_log('ADDEFEND -- ERROR : Script Update schedule does not exist, trying to re-create it...'); 97 $existingSchedules = wp_get_schedules(); 98 if (wp_schedule_event( time(), 'everyfiveminutes', 'out_of_date_script')) { 99 addefend_log('ADDEFEND -- TRACE : successfully rescheduled the Script Update for every five minutes'); 100 } else if (wp_schedule_event( time(), 'hourly', 'out_of_date_script')) { 101 addefend_log('ADDEFEND -- TRACE : successfully rescheduled the Script Update for every one hour'); 102 } else { 103 addefend_log('ADDEFEND -- ERROR : failed to reschedule the Script Update - time() = ' . time() . ' | existingSchedules = (' . implode(", ", array_keys($existingSchedules)) . ')'); 104 } 74 download_addefend_script(); 105 75 } 106 76 } 107 77 108 // desactivate the scheduling and clear the cache when the plugin is deactivated 109 register_deactivation_hook(ADDEFEND_PLUGIN_PHP_FILE, 'addefend_deactivate_scheduling'); 110 function addefend_deactivate_scheduling() { 111 wp_clear_scheduled_hook('out_of_date_script'); 78 // clean up the database from all addefend content 79 register_deactivation_hook(ADDEFEND_PLUGIN_PHP_FILE, 'addefend_cleanup'); 80 function addefend_cleanup() { 112 81 global $wpdb; 113 $wpdb->delete( ADDEFEND_TABLE_NAME, array( 'id' => '1' ));82 $wpdb->delete(ADDEFEND_TABLE_NAME, array('id' => '1')); 114 83 } -
addefend-easy-integration/tags/1.8/addefend-easy-integration.php
r2227663 r2229158 4 4 Plugin URI: https://wordpress.org/plugins/addefend-easy-integration/ 5 5 Description: The AdDefend Easy Intregration plug-in supports publishers in integrating the AdDefend anti-adblock solution. 6 Version: 1. 76 Version: 1.8 7 7 Author: AdDefend GmbH 8 8 Author URI: http://www.addefend.com/ -
addefend-easy-integration/tags/1.8/readme.txt
r2227663 r2229158 4 4 Requires at least: 4.2 5 5 Tested up to: 5.3.2 6 Stable tag: 1. 76 Stable tag: 1.8 7 7 License: GPLv3 8 8 License URI: https://www.gnu.org/licenses/gpl.html … … 52 52 == Changelog == 53 53 54 = 1.8 = 55 * improvements to the script update method 56 54 57 = 1.7 = 55 58 * improve the automatic Cron job recovery -
addefend-easy-integration/trunk/Components/script_integration.php
r2227678 r2229158 2 2 3 3 global $wpdb; 4 define( 'ADDEFEND_TABLE_NAME', $wpdb->prefix . "addefend" ); 5 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); 4 define('ADDEFEND_TABLE_NAME', $wpdb->prefix . "addefend"); 5 define('ADDEFEND_SCRIPT_UPDATE_FREQUENCY_IN_SEC', 5*60); 6 require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); 6 7 7 8 // create the addefend table … … 13 14 id mediumint(9) NOT NULL, 14 15 script longtext NOT NULL, 16 timestamp int NOT NULL, 15 17 PRIMARY KEY (id) 16 18 ) $charset_collate;"; 17 dbDelta( $sql);19 dbDelta($sql); 18 20 } 19 21 20 // add custom cron schedules 21 add_filter( 'cron_schedules', 'addefend_add_script_update_frequency'); 22 function addefend_add_script_update_frequency($schedules ) { 23 if(!isset($schedules['everyfiveminutes'])) { 24 $schedules['everyfiveminutes'] = array( 25 'interval' => 300, 26 'display' => __('Every Five Minutes') 27 ); 28 } 29 if(!isset($schedules['every10seconds'])) { 30 // this is for testing 31 $schedules['every10seconds'] = array( 32 'interval' => 10, 33 'display' => __('Every ten Seconds') 34 ); 35 } 36 return $schedules; 37 } 38 // activate the scheduling when the plugin is activated 39 register_activation_hook(ADDEFEND_PLUGIN_PHP_FILE, 'addefend_activate_scheduling'); 40 function addefend_activate_scheduling() { 41 if ( !wp_next_scheduled( 'out_of_date_script' ) ) { 42 wp_schedule_event( time(), 'everyfiveminutes', 'out_of_date_script'); 43 } 44 } 45 46 // the new script is being stored in a dedicated table in the wordpress database 47 add_action('out_of_date_script', 'download_addefend_script'); 22 register_activation_hook(ADDEFEND_PLUGIN_PHP_FILE, 'download_addefend_script'); 48 23 function download_addefend_script() { 49 addefend_log('ADDEFEND -- TRACE : download_addefend_script() !');50 $script_URL = get_option( 'addefend_script_URL');24 // the new script is being stored in a dedicated table in the wordpress database 25 $script_URL = get_option('addefend_script_URL'); 51 26 // API call 52 27 $response = wp_remote_get($script_URL); 53 28 // handling the response 54 if (is_wp_error( $response) || wp_remote_retrieve_response_code($response) == 404){29 if (is_wp_error($response) || wp_remote_retrieve_response_code($response) == 404){ 55 30 if ( is_wp_error( $response ) ) { 56 31 $error_string = $response->get_error_message(); … … 68 43 array( 69 44 'id' => '1', 70 'script' => $new_script 45 'script' => $new_script, 46 'timestamp' => time() 71 47 ) 72 48 ); … … 83 59 function inject_addefend_script(){ 84 60 global $wpdb; 85 $addefend_script = $wpdb->get_var("SELECT script FROM ".ADDEFEND_TABLE_NAME." WHERE (id = '1')"); 86 if(!$addefend_script){ 61 extract($wpdb->get_row("SELECT script AS addefend_script, timestamp AS addefend_script_timestamp FROM ".ADDEFEND_TABLE_NAME." WHERE (id = '1')", "ARRAY_A")); 62 if($addefend_script && $addefend_script_timestamp){ 63 $addefend_script_age = time() - $addefend_script_timestamp; 64 echo '<script type="text/javascript">' . $addefend_script . '</script>'; 65 addefend_log('ADDEFEND -- TRACE : A ' . $addefend_script_age . ' seconds old script was injected in the footer'); 66 if ($addefend_script_age < ADDEFEND_SCRIPT_UPDATE_FREQUENCY_IN_SEC) { 67 $nextScriptUpdateDate = $addefend_script_timestamp + ADDEFEND_SCRIPT_UPDATE_FREQUENCY_IN_SEC; 68 addefend_log('ADDEFEND -- TRACE : the next script update is scheduled for ' . date('l jS \of F Y h:i:s A (e)', $nextScriptUpdateDate)); 69 } else { 70 download_addefend_script(); 71 } 72 } else { 87 73 addefend_log('ADDEFEND -- ERROR : Failed to retrieve the script from the database'); 88 }else{ 89 echo '<script type="text/javascript">'.$addefend_script.'</script>'; 90 addefend_log('ADDEFEND -- TRACE : Script injected in the footer'); 91 } 92 $nextScriptUpdateDate = wp_next_scheduled( 'out_of_date_script' ); 93 if ( $nextScriptUpdateDate ) { 94 addefend_log('ADDEFEND -- TRACE : the next script update is scheduled for ' . date('l jS \of F Y h:i:s A', $nextScriptUpdateDate)); 95 } else { 96 addefend_log('ADDEFEND -- ERROR : Script Update schedule does not exist, trying to re-create it...'); 97 $existingSchedules = wp_get_schedules(); 98 if (wp_schedule_event( time(), 'everyfiveminutes', 'out_of_date_script')) { 99 addefend_log('ADDEFEND -- TRACE : successfully rescheduled the Script Update for every five minutes'); 100 } else if (wp_schedule_event( time(), 'hourly', 'out_of_date_script')) { 101 addefend_log('ADDEFEND -- TRACE : successfully rescheduled the Script Update for every one hour'); 102 } else { 103 addefend_log('ADDEFEND -- ERROR : failed to reschedule the Script Update - time() = ' . time() . ' | existingSchedules = (' . implode(", ", array_keys($existingSchedules)) . ')'); 104 } 74 download_addefend_script(); 105 75 } 106 76 } 107 77 108 // desactivate the scheduling and clear the cache when the plugin is deactivated 109 register_deactivation_hook(ADDEFEND_PLUGIN_PHP_FILE, 'addefend_deactivate_scheduling'); 110 function addefend_deactivate_scheduling() { 111 wp_clear_scheduled_hook('out_of_date_script'); 78 // clean up the database from all addefend content 79 register_deactivation_hook(ADDEFEND_PLUGIN_PHP_FILE, 'addefend_cleanup'); 80 function addefend_cleanup() { 112 81 global $wpdb; 113 $wpdb->delete( ADDEFEND_TABLE_NAME, array( 'id' => '1' ));82 $wpdb->delete(ADDEFEND_TABLE_NAME, array('id' => '1')); 114 83 } -
addefend-easy-integration/trunk/addefend-easy-integration.php
r2227663 r2229158 4 4 Plugin URI: https://wordpress.org/plugins/addefend-easy-integration/ 5 5 Description: The AdDefend Easy Intregration plug-in supports publishers in integrating the AdDefend anti-adblock solution. 6 Version: 1. 76 Version: 1.8 7 7 Author: AdDefend GmbH 8 8 Author URI: http://www.addefend.com/ -
addefend-easy-integration/trunk/readme.txt
r2227663 r2229158 4 4 Requires at least: 4.2 5 5 Tested up to: 5.3.2 6 Stable tag: 1. 76 Stable tag: 1.8 7 7 License: GPLv3 8 8 License URI: https://www.gnu.org/licenses/gpl.html … … 52 52 == Changelog == 53 53 54 = 1.8 = 55 * improvements to the script update method 56 54 57 = 1.7 = 55 58 * improve the automatic Cron job recovery
Note: See TracChangeset
for help on using the changeset viewer.