Plugin Directory

Changeset 3185764


Ignore:
Timestamp:
11/11/2024 01:48:34 PM (17 months ago)
Author:
r2b2io
Message:

1.1.2

Location:
r2b2-monetization
Files:
370 added
5 edited

Legend:

Unmodified
Added
Removed
  • r2b2-monetization/trunk/constants.php

    r3181596 r3185764  
    44} // Exit if accessed directly
    55
    6 define( "R2B2_PLUGIN_VERSION", '1.1.1' );
     6define( "R2B2_PLUGIN_VERSION", '1.1.2' );
    77
    88define( "R2B2_OPTIONS", 'r2b2-settings' );
  • r2b2-monetization/trunk/index.php

    r3181596 r3185764  
    33 * Plugin Name:       R2B2 Monetization
    44 * Description:       Maximize your profits today with programmatic advertising.
    5  * Version:           1.1.1
     5 * Version:           1.1.2
    66 * Requires at least: 5.2
    77 * Requires PHP:      7.2
     
    3333    wp_enqueue_style( 'r2b2-styles', plugins_url( '/css/r2b2-styles.css', __FILE__ ), false, R2B2_PLUGIN_VERSION );
    3434    $placements = r2b2_get_placement_data();
     35    if ( empty( $placements ) ) {
     36        return;
     37    }
    3538
    3639    $deviceIsMobile = wp_is_mobile();
    3740
    3841    foreach ( $placements as $placement ) {
    39         if ( ! $placement[ R2B2_PL_DATA_DELIVERY ] ) {
     42        if ( empty( $placement ) || ! $placement[ R2B2_PL_DATA_DELIVERY ] ) {
    4043            continue;
    4144        }
     
    5962function r2b2_insert_into_posts( $content ) {
    6063    if ( ! empty( $content ) ) {
    61         $placements         = r2b2_get_placement_data();
     64        $placements = r2b2_get_placement_data();
     65        if ( empty( $placements ) ) {
     66            return $content;
     67        }
    6268        $placementsToInsert = [];
    6369
     
    6571
    6672        foreach ( $placements as $placement ) {
    67             if ( ! $placement[ R2B2_PL_DATA_DELIVERY ] ) {
     73            if ( empty( $placement ) || ! $placement[ R2B2_PL_DATA_DELIVERY ] ) {
    6874                continue;
    6975            }
  • r2b2-monetization/trunk/migrations.php

    r3181596 r3185764  
    2323        r2b2_migrate_to_110();
    2424    }
     25    if ( version_compare( $installed_version, '1.1.2', '<' ) ) {
     26        r2b2_migrate_to_112();
     27    }
    2528
    2629    update_option( 'r2b2_plugin_version', R2B2_PLUGIN_VERSION );
    2730}
    2831
    29 
     32/**
     33 * Migrate from separate lists to one list with JSON encoded data.
     34 * @return void
     35 */
    3036function r2b2_migrate_to_110() {
    3137    $options        = get_option( R2B2_OPTIONS );
     
    4046
    4147    for ( $i = 0; $i < count( $placements ); $i ++ ) {
    42         $placement            = preg_replace( '/[\x00-\x1F\x80-\xFF]/', '', $placements[ $i ] );
    43         $dgpm                 = explode( '/', strtolower( $placement ) );
    44         $placementsData[ $i ] = wp_json_encode( [
    45             R2B2_PL_DATA_DGPM            => [
    46                 'd' => $dgpm[0],
    47                 'g' => $dgpm[1],
    48                 'p' => $dgpm[2],
    49                 'm' => r2b2_is_placement_mobile( $placement ),
    50             ],
    51             R2B2_PL_DATA_DELIVERY        => in_array( $placement, $placementsDelivery ),
    52             R2B2_PL_DATA_PARAGRAPH_INDEX => null,
    53             R2B2_PL_DATA_TABLE_INDEX     => null,
    54             R2B2_PL_DATA_DEMO            => in_array( $placement, $placementsDemo ),
    55         ] );
     48        try {
     49            $placement = preg_replace( '/[\x00-\x1F\x80-\xFF]/', '', $placements[ $i ] );
     50            if ( empty( $placement ) ) {
     51                continue;
     52            }
     53            $dgpm                 = explode( '/', strtolower( $placement ) );
     54            $placementsData[ $i ] = wp_json_encode( [
     55                R2B2_PL_DATA_DGPM            => [
     56                    'd' => $dgpm[0],
     57                    'g' => $dgpm[1],
     58                    'p' => $dgpm[2],
     59                    'm' => r2b2_is_placement_mobile( $placement ),
     60                ],
     61                R2B2_PL_DATA_DELIVERY        => in_array( $placement, $placementsDelivery ),
     62                R2B2_PL_DATA_PARAGRAPH_INDEX => null,
     63                R2B2_PL_DATA_TABLE_INDEX     => null,
     64                R2B2_PL_DATA_DEMO            => in_array( $placement, $placementsDemo ),
     65            ] );
     66        } catch ( Exception $e ) {
     67        }
    5668    }
    5769
     
    6375    update_option( R2B2_OPTIONS, $options );
    6476}
     77
     78/**
     79 * Remove the empty placement that was generated in last migration.
     80 * @cite a:1:{s:23:"r2b2_settings_list_data";s:123:"{"dgpm":{"d":"","g":null,"p":null,"m":false},"delivery_enabled":true,"paragraph_index":null,"table_index":null,"demo":true}";}
     81 * @return void
     82 */
     83function r2b2_migrate_to_112() {
     84    $options    = get_option( R2B2_OPTIONS );
     85    $listData   = $options[ R2B2_OPTION_PLACEMENT_LIST_DATA ] ?? '';
     86    $placements = explode( "\n", $listData ) ?? [];
     87
     88    $placementsDataOut = [];
     89
     90    for ( $i = 0; $i < count( $placements ); $i ++ ) {
     91        try {
     92            $placement = preg_replace( '/[\x00-\x1F\x80-\xFF]/', '', $placements[ $i ] );
     93            if ( empty( $placement ) ) {
     94                continue;
     95            }
     96            $placementOrig = json_decode( $placement, true );
     97            if ( empty( $placementOrig ) || empty( $placementOrig[ R2B2_PL_DATA_DGPM ] ) || empty( $placementOrig[ R2B2_PL_DATA_DELIVERY ] ) ) {
     98                continue;
     99            }
     100            if ( empty( $placementOrig[ R2B2_PL_DATA_DGPM ]['d'] ) || empty( $placementOrig[ R2B2_PL_DATA_DGPM ]['g'] ) || empty( $placementOrig[ R2B2_PL_DATA_DGPM ]['p'] ) ) {
     101                continue;
     102            }
     103            $placementsDataOut[] = wp_json_encode( [
     104                R2B2_PL_DATA_DGPM            => [
     105                    'd' => $placementOrig[ R2B2_PL_DATA_DGPM ]['d'],
     106                    'g' => $placementOrig[ R2B2_PL_DATA_DGPM ]['g'],
     107                    'p' => $placementOrig[ R2B2_PL_DATA_DGPM ]['p'],
     108                    'm' => $placementOrig[ R2B2_PL_DATA_DGPM ]['m'] ?? false,
     109                ],
     110                R2B2_PL_DATA_DELIVERY        => $placementOrig[ R2B2_PL_DATA_DELIVERY ],
     111                R2B2_PL_DATA_PARAGRAPH_INDEX => $placementOrig[ R2B2_PL_DATA_PARAGRAPH_INDEX ] ?? null,
     112                R2B2_PL_DATA_TABLE_INDEX     => $placementOrig[ R2B2_PL_DATA_TABLE_INDEX ] ?? null,
     113                R2B2_PL_DATA_DEMO            => $placementOrig[ R2B2_PL_DATA_DEMO ] ?? false,
     114            ] );
     115        } catch ( Exception $e ) {
     116        }
     117    }
     118
     119    $options[ R2B2_OPTION_PLACEMENT_LIST_DATA ] = join( "\n", $placementsDataOut );
     120
     121    update_option( R2B2_OPTIONS, $options );
     122}
  • r2b2-monetization/trunk/r2b2-options.js

    r3181596 r3185764  
    2323
    2424        displayPlacementTable();
     25
     26        window.addEventListener('keydown', function (ev) {
     27            if (ev.code === "Escape") {
     28                closePopup();
     29            }
     30        });
    2531
    2632        win.r2b2 = {
     
    206212            updatePlacementData(dgpm, {paragraph_index: cInputParagraph.value});
    207213            closePopup();
    208             if (callbackAfterSave && typeof callbackAfterSave === "function"){
     214            if (callbackAfterSave && typeof callbackAfterSave === "function") {
    209215                callbackAfterSave();
    210216            }
     
    271277    function createCheckboxListenerDelivery(dgpm) {
    272278        return function () {
    273             if (isPlacementWithContainer(dgpm)){
     279            if (isPlacementWithContainer(dgpm)) {
    274280                const pl = getPlacementDataSingle(dgpm);
    275                 if (!pl.paragraph_index && this.checked){
     281                if (!pl.paragraph_index && this.checked) {
    276282                    displayPopupEditPlacement(dgpm, function () {
    277283                        updatePlacementData(dgpm, {delivery_enabled: true})
     
    299305            const srcUrl = match[2];
    300306            const urlParts = srcUrl.match(regexUrl);
     307            const isMobile = !['desktop', 'classic', '0', ''].includes(urlParts[5]);
    301308            const dgpm = {
    302309                d: urlParts[2],
    303310                g: urlParts[3],
    304311                p: urlParts[4],
    305                 m: !['desktop', 'classic', '0'].includes(urlParts[5]),
     312                m: isMobile,
    306313            };
    307             addPlacementData(createPlacementObj(dgpm, !isPlacementWithContainer(dgpm)));
     314            if (!getPlacementDataSingle(dgpm)) {
     315                addPlacementData(createPlacementObj(dgpm, !isPlacementWithContainer(dgpm)));
     316            }
    308317        }
    309318        closePopup();
     
    323332                if (placementData.trim() === '') continue;
    324333                const data = JSON.parse(placementData);
     334                if (!data.dgpm || !data.dgpm.d || !data.dgpm.g || !data.dgpm.p) continue;
    325335                placementsData.push(createPlacementObj(data.dgpm, data.delivery_enabled, data.demo, data.paragraph_index));
    326336            }
     
    332342        if (!isElement(cInputListData)) throw new Error('List is not an Element');
    333343        const value = cInputListData.value;
    334         let placementsData = [];
    335344        if (value !== '') {
    336345            const placementsDataRaw = value.split('\n');
     
    343352            }
    344353        }
    345         return placementsData;
     354        return false;
    346355    }
    347356
  • r2b2-monetization/trunk/readme.txt

    r3181596 r3185764  
    55Tested up to: 6.4.3
    66Requires PHP: 7.2
    7 Stable tag: 1.1.1
     7Stable tag: 1.1.2
    88License: GPL-3.0-only
    99
Note: See TracChangeset for help on using the changeset viewer.