Plugin Directory

Changeset 2229158


Ignore:
Timestamp:
01/17/2020 01:35:28 PM (6 years ago)
Author:
melkarim
Message:

new release

Location:
addefend-easy-integration
Files:
3 edited
4 copied

Legend:

Unmodified
Added
Removed
  • addefend-easy-integration/tags/1.8/Components/script_integration.php

    r2227678 r2229158  
    22
    33global $wpdb;
    4 define( 'ADDEFEND_TABLE_NAME', $wpdb->prefix . "addefend" );
    5 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
     4define('ADDEFEND_TABLE_NAME', $wpdb->prefix . "addefend");
     5define('ADDEFEND_SCRIPT_UPDATE_FREQUENCY_IN_SEC', 5*60);
     6require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
    67
    78// create the addefend table
     
    1314      id mediumint(9) NOT NULL,
    1415      script longtext NOT NULL,
     16      timestamp int NOT NULL,
    1517      PRIMARY KEY  (id)
    1618    ) $charset_collate;";
    17     dbDelta( $sql );
     19    dbDelta($sql);
    1820}
    1921
    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');
     22register_activation_hook(ADDEFEND_PLUGIN_PHP_FILE, 'download_addefend_script');
    4823function 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');
    5126    // API call
    5227    $response = wp_remote_get($script_URL);
    5328    // 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){
    5530        if ( is_wp_error( $response ) ) {
    5631            $error_string = $response->get_error_message();
     
    6843            array(
    6944                'id' => '1',
    70                 'script' => $new_script
     45                'script' => $new_script,
     46                'timestamp' => time()
    7147            )
    7248        );
     
    8359function inject_addefend_script(){
    8460    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 {
    8773        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();
    10575    }
    10676}
    10777
    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
     79register_deactivation_hook(ADDEFEND_PLUGIN_PHP_FILE, 'addefend_cleanup');
     80function addefend_cleanup() {
    11281    global $wpdb;
    113     $wpdb->delete( ADDEFEND_TABLE_NAME, array( 'id' => '1' ) );
     82    $wpdb->delete(ADDEFEND_TABLE_NAME, array('id' => '1'));
    11483}
  • addefend-easy-integration/tags/1.8/addefend-easy-integration.php

    r2227663 r2229158  
    44Plugin URI: https://wordpress.org/plugins/addefend-easy-integration/
    55Description: The AdDefend Easy Intregration plug-in supports publishers in integrating the AdDefend anti-adblock solution.
    6 Version: 1.7
     6Version: 1.8
    77Author: AdDefend GmbH
    88Author URI: http://www.addefend.com/
  • addefend-easy-integration/tags/1.8/readme.txt

    r2227663 r2229158  
    44Requires at least: 4.2
    55Tested up to: 5.3.2
    6 Stable tag: 1.7
     6Stable tag: 1.8
    77License: GPLv3
    88License URI: https://www.gnu.org/licenses/gpl.html
     
    5252== Changelog ==
    5353
     54= 1.8 =
     55* improvements to the script update method
     56
    5457= 1.7 =
    5558* improve the automatic Cron job recovery
  • addefend-easy-integration/trunk/Components/script_integration.php

    r2227678 r2229158  
    22
    33global $wpdb;
    4 define( 'ADDEFEND_TABLE_NAME', $wpdb->prefix . "addefend" );
    5 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
     4define('ADDEFEND_TABLE_NAME', $wpdb->prefix . "addefend");
     5define('ADDEFEND_SCRIPT_UPDATE_FREQUENCY_IN_SEC', 5*60);
     6require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
    67
    78// create the addefend table
     
    1314      id mediumint(9) NOT NULL,
    1415      script longtext NOT NULL,
     16      timestamp int NOT NULL,
    1517      PRIMARY KEY  (id)
    1618    ) $charset_collate;";
    17     dbDelta( $sql );
     19    dbDelta($sql);
    1820}
    1921
    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');
     22register_activation_hook(ADDEFEND_PLUGIN_PHP_FILE, 'download_addefend_script');
    4823function 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');
    5126    // API call
    5227    $response = wp_remote_get($script_URL);
    5328    // 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){
    5530        if ( is_wp_error( $response ) ) {
    5631            $error_string = $response->get_error_message();
     
    6843            array(
    6944                'id' => '1',
    70                 'script' => $new_script
     45                'script' => $new_script,
     46                'timestamp' => time()
    7147            )
    7248        );
     
    8359function inject_addefend_script(){
    8460    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 {
    8773        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();
    10575    }
    10676}
    10777
    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
     79register_deactivation_hook(ADDEFEND_PLUGIN_PHP_FILE, 'addefend_cleanup');
     80function addefend_cleanup() {
    11281    global $wpdb;
    113     $wpdb->delete( ADDEFEND_TABLE_NAME, array( 'id' => '1' ) );
     82    $wpdb->delete(ADDEFEND_TABLE_NAME, array('id' => '1'));
    11483}
  • addefend-easy-integration/trunk/addefend-easy-integration.php

    r2227663 r2229158  
    44Plugin URI: https://wordpress.org/plugins/addefend-easy-integration/
    55Description: The AdDefend Easy Intregration plug-in supports publishers in integrating the AdDefend anti-adblock solution.
    6 Version: 1.7
     6Version: 1.8
    77Author: AdDefend GmbH
    88Author URI: http://www.addefend.com/
  • addefend-easy-integration/trunk/readme.txt

    r2227663 r2229158  
    44Requires at least: 4.2
    55Tested up to: 5.3.2
    6 Stable tag: 1.7
     6Stable tag: 1.8
    77License: GPLv3
    88License URI: https://www.gnu.org/licenses/gpl.html
     
    5252== Changelog ==
    5353
     54= 1.8 =
     55* improvements to the script update method
     56
    5457= 1.7 =
    5558* improve the automatic Cron job recovery
Note: See TracChangeset for help on using the changeset viewer.