Plugin Directory

Changeset 1069497


Ignore:
Timestamp:
01/16/2015 04:08:24 PM (11 years ago)
Author:
benohead
Message:

tagging version 0.9.4

Location:
wp-advertize-it
Files:
1 added
14 edited
14 copied

Legend:

Unmodified
Added
Removed
  • wp-advertize-it/tags/0.9.4/bootstrap.php

    r1069307 r1069497  
    44Plugin URI:  https://wordpress.org/plugins/wp-advertize-it/
    55Description: A plugin to place adsense blocks on your site
    6 Version:     0.9.3
     6Version:     0.9.4
    77Author:      Henri Benoit
    88Author URI:  http://benohead.com
  • wp-advertize-it/tags/0.9.4/classes/wp-advertize-it.php

    r1051600 r1069497  
    2424         * Plugin version
    2525         */
    26         const VERSION = '0.9.3';
     26        const VERSION = '0.9.4';
    2727        /**
    2828         * Prefix used to identify things related to this plugin
     
    343343            $ad_block = "";
    344344            $blocks = $this->modules['WPAI_Settings']->settings['blocks'];
    345             if (isset($blocks[intval($block) - 1])) {
    346                 $ad_block = $blocks[intval($block) - 1];
     345            if (isset($blocks[intval($block) - 1]) && isset($blocks[intval($block) - 1]['text'])) {
     346                $ad_block = $blocks[intval($block) - 1]['text'];
    347347            }
    348348            return $ad_block;
     
    367367                    <?php foreach ($blocks as $i => $block) : ?>
    368368                        <option style="padding-right: 10px;"
    369                                 value="<?php echo esc_attr(($i + 1)); ?>"><?php echo 'Ad Block ' . ($i + 1); ?></option>
     369                                value="<?php echo esc_attr(($i + 1)); ?>"><?php echo $block['name']; ?></option>
    370370                    <?php endforeach; ?>
    371371                </select>
     
    613613        }
    614614
     615        public function endsWith($haystack, $needle) {
     616            return $needle === "" || strpos($haystack, $needle, strlen($haystack) - strlen($needle)) !== FALSE;
     617        }
     618
     619        public function endsWithDot($haystack) {
     620            return $this->endsWith($haystack, ".");
     621        }
     622
    615623        /**
    616624         * Adds the ad blocks to be displayed in the provided contents
     
    654662            $after_first_post_paragraph_block = $this->modules['WPAI_Settings']->settings['placements']['after-first-post-paragraph'];
    655663            $after_first_page_paragraph_block = $this->modules['WPAI_Settings']->settings['placements']['after-first-page-paragraph'];
     664            $before_last_post_sentence_block = $this->modules['WPAI_Settings']->settings['placements']['before-last-post-sentence'];
     665            $before_last_page_sentence_block = $this->modules['WPAI_Settings']->settings['placements']['before-last-page-sentence'];
    656666
    657667            if (!is_feed() && strpos($content, '<!--NoHomePageAds-->') !== false) {
     
    675685                $before_last_post_paragraph_block = "";
    676686                $before_last_page_paragraph_block = "";
     687            }
     688            if (!is_feed() && strpos($content, '<!--NoBeforeLastSentenceAds-->') !== false) {
     689                $before_last_post_sentence_block = "";
     690                $before_last_page_sentence_block = "";
    677691            }
    678692            if (!is_feed() && strpos($content, '<!--NoAfterFirstParagraphAds-->') !== false) {
     
    749763            }
    750764            if (is_single()
     765                && $before_last_post_sentence_block != ""
     766                && intval($options['min-char-count']) <= $char_count
     767                && intval($options['min-word-count']) <= $word_count
     768                && intval($options['min-sentence-count']) <= $paragraph_count
     769            ) {
     770                $before_last_post_sentence = WPAI_Settings::get_ad_block($blocks, $before_last_post_sentence_block);
     771
     772                $last = strrpos($content, '.');
     773                if ($last !== false) {
     774                    if ($this->endsWithDot(rtrim(strip_tags( $content)))) {
     775                        $index = strrpos($content, '.', $last - strlen($content) - 1) + 1;
     776                    }
     777                    else {
     778                        $index = $last+1;
     779                    }
     780                    $content = substr_replace($content, $before_last_post_sentence, $index, 0);
     781                }
     782            } else if (is_page()
     783                && $before_last_page_sentence_block != ""
     784                && intval($options['min-char-count']) <= $char_count
     785                && intval($options['min-word-count']) <= $word_count
     786                && intval($options['min-sentence-count']) <= $paragraph_count
     787            ) {
     788                $before_last_page_sentence = WPAI_Settings::get_ad_block($blocks, $before_last_page_sentence_block);
     789
     790                $last = strrpos($content, '.');
     791                if ($last !== false) {
     792                    if ($this->endsWithDot(rtrim(strip_tags( $content)))) {
     793                        $index = strrpos($content, '.', $last - strlen($content) - 1) + 1;
     794                    }
     795                    else {
     796                        $index = $last+1;
     797                    }
     798                    $content = substr_replace($content, $before_last_page_sentence, $index, 0);
     799                }
     800            }
     801            if (is_single()
    751802                && $after_first_post_paragraph_block != ""
    752803                && intval($options['min-char-count']) <= $char_count
     
    921972            foreach ( $blocks as $number => $code ) {
    922973                if ( strpos( $content, '<!--NoAdBlock' . ( $number + 1 ) . '-->' ) !== false ) {
    923                     $blocks[ $number ] = "";
     974                    $blocks[ $number ]['text'] = "";
    924975                }
    925976            }
  • wp-advertize-it/tags/0.9.4/classes/wpai-settings.php

    r1045033 r1069497  
    109109        public function upgrade($db_version = 0)
    110110        {
    111             /*
    112             if( version_compare( $db_version, 'x.y.z', '<' ) )
     111            error_log('db_version='.$db_version);
     112            if( version_compare( $db_version, '0.9.4', '<' ) )
    113113            {
    114                 // Do stuff
    115             }
    116             */
     114                error_log("options=".print_r($this->settings, true));
     115                if (isset($this->settings['blocks'])) {
     116                    $blocks = $this->settings['blocks'];
     117                    foreach ($blocks as $i => $block) {
     118                        $block_name = 'Ad Block ' . ($i + 1);
     119                        $this->settings['blocks'][$i]=array();
     120                        $this->settings['blocks'][$i]['name']=$block_name;
     121                        $this->settings['blocks'][$i]['text']=$block;
     122                    }
     123                }
     124                error_log("options=".print_r($this->settings, true));
     125            }
    117126        }
    118127
     
    160169                "before-last-post-paragraph" => "",
    161170                "before-last-page-paragraph" => "",
     171                "before-last-post-sentence" => "",
     172                "before-last-page-sentence" => "",
    162173                "after-first-post-paragraph" => "",
    163174                "after-first-page-paragraph" => "",
     
    322333
    323334            foreach ($blocks as $i => $block) {
    324                 $this->add_settings_field_blocks('wpai_block-' . ($i + 1), 'Ad Block ' . ($i + 1));
     335                $this->add_settings_field_blocks('wpai_block-' . ($i + 1), $block['name']);
    325336            }
    326337
     
    335346            $this->add_settings_field_placements('wpai_middle-of-post', 'Middle of post');
    336347            $this->add_settings_field_placements('wpai_before-last-post-paragraph', 'Before last post paragraph');
     348            $this->add_settings_field_placements('wpai_before-last-post-sentence', 'Before last post sentence');
    337349            $this->add_settings_field_placements('wpai_post-below-content', 'Posts below content');
    338350            $this->add_settings_field_placements('wpai_post-below-comments', 'Posts below comments');
     
    341353            $this->add_settings_field_placements('wpai_middle-of-page', 'Middle of page');
    342354            $this->add_settings_field_placements('wpai_before-last-page-paragraph', 'Before last page paragraph');
     355            $this->add_settings_field_placements('wpai_before-last-page-sentence', 'Before last page sentence');
    343356            $this->add_settings_field_placements('wpai_page-below-content', 'Pages below content');
    344357            $this->add_settings_field_placements('wpai_page-below-comments', 'Pages below comments');
     
    403416        public static function get_ad_block($blocks, $id)
    404417        {
    405             if (isset($blocks[intval($id)])) {
    406                 return $blocks[intval($id)];
     418            if (isset($blocks[intval($id)]) && isset($blocks[intval($id)]['text'])) {
     419                return $blocks[intval($id)]['text'];
    407420            }
    408421            return "";
     
    488501            $this->setting_empty_string_if_not_set($new_settings, 'placements', 'before-last-post-paragraph');
    489502            $this->setting_empty_string_if_not_set($new_settings, 'placements', 'before-last-page-paragraph');
     503            $this->setting_empty_string_if_not_set($new_settings, 'placements', 'before-last-post-sentence');
     504            $this->setting_empty_string_if_not_set($new_settings, 'placements', 'before-last-page-sentence');
    490505            $this->setting_empty_string_if_not_set($new_settings, 'placements', 'after-first-post-paragraph');
    491506            $this->setting_empty_string_if_not_set($new_settings, 'placements', 'after-first-page-paragraph');
  • wp-advertize-it/tags/0.9.4/classes/wpai-widget.php

    r932299 r1069497  
    6868                <?php
    6969                foreach ($settings['blocks'] as $i => $block) :
    70                     $label = 'Ad Block ' . ($i + 1);
     70                    $label = $block['name'];
    7171                    $selected = '';
    7272                    if ($selected_block == $i)
  • wp-advertize-it/tags/0.9.4/css/admin.css

    r1006845 r1069497  
    2222
    2323.settings_page_wpai_settings .ace_editor {
    24     margin-bottom: 1.7em;
    2524    min-height: 150px;
    2625}
     
    2827    margin-top: 0;
    2928}
     29
     30.settings_page_wpai_settings #before-blocks + table.form-table > tbody > tr {
     31    border-bottom: 1.7em solid transparent;
     32}
  • wp-advertize-it/tags/0.9.4/readme.txt

    r1069307 r1069497  
    55Requires at least: 3.0.1
    66Tested up to: 4.1
    7 Stable tag: 0.9.3
     7Stable tag: 0.9.4
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    2828* Middle of post   
    2929* Before last post paragraph   
     30* Before last post sentence
    3031* Posts below content   
    3132* Posts below comments 
     
    3435* Middle of page   
    3536* Before last page paragraph   
     37* Before last page sentence
    3638* Pages below content   
    3739* Pages below comments 
    3840* Below footer 
     41
     42Note that sentences might not be identified correctly if there are dots within sentences e.g. "it is a country with 80.6 million inhabitants." - this would be identified as two sentences instead of one. Instead of this placement you may want to use the "before last post/page paragraph" placement and make sure the last sentence is on its own paragraph.
    3943
    4044A widget is also available to display in a sidebar.
     
    109113== Changelog ==
    110114
     115= 0.9.4 =
     116
     117* Ad blocks can be renamed in the text field below the editor. Renaming occurs only when the settings are saved.
     118* Added placement option for before last sentence. Sentences might not be identified correctly if there are dots within sentences e.g. "it is a country with 80.6 million inhabitants." - this would be identified as two sentences instead of one. Instead of this placement you may want to use the "before last paragraph" placement and make sure the last sentence is on its own paragraph.
     119
    111120= 0.9.3 =
    112121
  • wp-advertize-it/tags/0.9.4/views/wpai-settings/page-settings-fields.php

    r1051600 r1069497  
    1010    <div id="<?php esc_attr_e($field['label_for']); ?>_div"></div>
    1111    <textarea style="width: 95%;" wrap="soft" rows="5" id="<?php esc_attr_e($field['label_for']); ?>"
    12               name="<?php esc_attr_e('wpai_settings[blocks][' . (intval(substr($field['label_for'], strlen('wpai_block-'))) - 1) . ']'); ?>"
    13               class="regular-text"><?php esc_attr_e($settings['blocks'][intval(substr($field['label_for'], strlen('wpai_block-'))) - 1]); ?></textarea>
     12              name="<?php esc_attr_e('wpai_settings[blocks][' . (intval(substr($field['label_for'], strlen('wpai_block-'))) - 1) . '][text]'); ?>"
     13              class="regular-text"><?php esc_attr_e($settings['blocks'][intval(substr($field['label_for'], strlen('wpai_block-'))) - 1]['text']); ?></textarea>
     14    <input type="text"
     15           name="<?php esc_attr_e('wpai_settings[blocks][' . (intval(substr($field['label_for'], strlen('wpai_block-'))) - 1) . '][name]'); ?>"
     16           value="<?php esc_attr_e($settings['blocks'][intval(substr($field['label_for'], strlen('wpai_block-'))) - 1]['name']); ?>">
    1417    <input type="checkbox"
    1518           id="checkbox_<?php esc_attr_e('wpai_settings[blocks][' . substr($field['label_for'], strlen('wpai_block-')) . ']'); ?>"
     
    2932        <?php
    3033        foreach ($settings['blocks'] as $i => $block) :
    31             $label = 'Ad Block ' . ($i + 1);
     34            $label = $block['name'];
    3235            $selected = '';
    3336            if (intval($settings['placements']['homepage-below-title']) === $i)
     
    4851        <?php
    4952        foreach ($settings['blocks'] as $i => $block) :
    50             $label = 'Ad Block ' . ($i + 1);
     53            $label = $block['name'];
    5154            $selected = '';
    5255            if (intval($settings['placements']['post-below-title']) === $i)
     
    6871        <?php
    6972        foreach ($settings['blocks'] as $i => $block) :
    70             $label = 'Ad Block ' . ($i + 1);
     73            $label = $block['name'];
    7174            $selected = '';
    7275            if (intval($settings['placements']['post-below-content']) === $i)
     
    8891        <?php
    8992        foreach ($settings['blocks'] as $i => $block) :
    90             $label = 'Ad Block ' . ($i + 1);
     93            $label = $block['name'];
    9194            $selected = '';
    9295            if (intval($settings['placements']['post-below-comments']) === $i)
     
    108111        <?php
    109112        foreach ($settings['blocks'] as $i => $block) :
    110             $label = 'Ad Block ' . ($i + 1);
     113            $label = $block['name'];
    111114            $selected = '';
    112115            if (intval($settings['placements']['page-below-title']) === $i)
     
    128131        <?php
    129132        foreach ($settings['blocks'] as $i => $block) :
    130             $label = 'Ad Block ' . ($i + 1);
     133            $label = $block['name'];
    131134            $selected = '';
    132135            if (intval($settings['placements']['page-below-content']) === $i)
     
    148151        <?php
    149152        foreach ($settings['blocks'] as $i => $block) :
    150             $label = 'Ad Block ' . ($i + 1);
     153            $label = $block['name'];
    151154            $selected = '';
    152155            if (intval($settings['placements']['page-below-comments']) === $i)
     
    168171        <?php
    169172        foreach ($settings['blocks'] as $i => $block) :
    170             $label = 'Ad Block ' . ($i + 1);
     173            $label = $block['name'];
    171174            $selected = '';
    172175            if (intval($settings['placements']['all-below-footer']) === $i)
     
    188191        <?php
    189192        foreach ($settings['blocks'] as $i => $block) :
    190             $label = 'Ad Block ' . ($i + 1);
     193            $label = $block['name'];
    191194            $selected = '';
    192195            if (intval($settings['placements']['middle-of-post']) === $i)
     
    208211        <?php
    209212        foreach ($settings['blocks'] as $i => $block) :
    210             $label = 'Ad Block ' . ($i + 1);
     213            $label = $block['name'];
    211214            $selected = '';
    212215            if (intval($settings['placements']['middle-of-page']) === $i)
     
    228231        <?php
    229232        foreach ($settings['blocks'] as $i => $block) :
    230             $label = 'Ad Block ' . ($i + 1);
     233            $label = $block['name'];
    231234            $selected = '';
    232235            if (intval($settings['placements']['before-last-post-paragraph']) === $i)
     
    248251        <?php
    249252        foreach ($settings['blocks'] as $i => $block) :
    250             $label = 'Ad Block ' . ($i + 1);
     253            $label = $block['name'];
    251254            $selected = '';
    252255            if (intval($settings['placements']['before-last-page-paragraph']) === $i)
     
    258261        $selected = '';
    259262        if ($settings['placements']['before-last-page-paragraph'] === $i)
     263            $selected = 'selected="selected"';
     264        echo '<option style="padding-right: 10px;" value="' . esc_attr($i) . '" ' . $selected . '>' . $label . '</option>';
     265        ?>
     266    </select>
     267<?php
     268elseif ('wpai_before-last-post-sentence' == $field['label_for']) : ?>
     269    <select class="placement-block-select" id="wpai_settings[placements][before-last-post-sentence]"
     270            name="wpai_settings[placements][before-last-post-sentence]">
     271        <?php
     272        foreach ($settings['blocks'] as $i => $block) :
     273            $label = $block['name'];
     274            $selected = '';
     275            if (intval($settings['placements']['before-last-post-sentence']) === $i)
     276                $selected = 'selected="selected"';
     277            echo '<option data-block-id="wpai_block-' . esc_attr($i + 1) . '" style="padding-right: 10px;" value="' . esc_attr($i) . '" ' . $selected . '>' . $label . '</option>';
     278        endforeach;
     279        $i = "";
     280        $label = 'None';
     281        $selected = '';
     282        if ($settings['placements']['before-last-post-sentence'] === $i)
     283            $selected = 'selected="selected"';
     284        echo '<option style="padding-right: 10px;" value="' . esc_attr($i) . '" ' . $selected . '>' . $label . '</option>';
     285        ?>
     286    </select>
     287<?php
     288elseif ('wpai_before-last-page-sentence' == $field['label_for']) : ?>
     289    <select class="placement-block-select" id="wpai_settings[placements][before-last-page-sentence]"
     290            name="wpai_settings[placements][before-last-page-sentence]">
     291        <?php
     292        foreach ($settings['blocks'] as $i => $block) :
     293            $label = $block['name'];
     294            $selected = '';
     295            if (intval($settings['placements']['before-last-page-sentence']) === $i)
     296                $selected = 'selected="selected"';
     297            echo '<option data-block-id="wpai_block-' . esc_attr($i + 1) . '" style="padding-right: 10px;" value="' . esc_attr($i) . '" ' . $selected . '>' . $label . '</option>';
     298        endforeach;
     299        $i = "";
     300        $label = 'None';
     301        $selected = '';
     302        if ($settings['placements']['before-last-page-sentence'] === $i)
    260303            $selected = 'selected="selected"';
    261304        echo '<option style="padding-right: 10px;" value="' . esc_attr($i) . '" ' . $selected . '>' . $label . '</option>';
     
    268311        <?php
    269312        foreach ($settings['blocks'] as $i => $block) :
    270             $label = 'Ad Block ' . ($i + 1);
     313            $label = $block['name'];
    271314            $selected = '';
    272315            if (intval($settings['placements']['after-first-post-paragraph']) === $i)
     
    288331        <?php
    289332        foreach ($settings['blocks'] as $i => $block) :
    290             $label = 'Ad Block ' . ($i + 1);
     333            $label = $block['name'];
    291334            $selected = '';
    292335            if (intval($settings['placements']['after-first-page-paragraph']) === $i)
     
    308351        <?php
    309352        foreach ($settings['blocks'] as $i => $block) :
    310             $label = 'Ad Block ' . ($i + 1);
     353            $label = $block['name'];
    311354            $selected = '';
    312355            if (intval($settings['placements']['between-posts']) === $i)
     
    328371        <?php
    329372        foreach ($settings['blocks'] as $i => $block) :
    330             $label = 'Ad Block ' . ($i + 1);
     373            $label = $block['name'];
    331374            $selected = '';
    332375            if (intval($settings['placements']['above-everything']) === $i)
  • wp-advertize-it/tags/0.9.4/views/wpai-settings/page-settings-section-headers.php

    r1045033 r1069497  
    2929                }
    3030            });
    31             jQuery('#before-blocks + table.form-table tbody').append('<tr><th scope="row"><label for="wpai_block-' + (lastIndex + 1) + '">Ad Block ' + (lastIndex + 1) + '</label></div></th><td><button onclick="previewBlock(\'wpai_block-' + (lastIndex + 1) + '\');return false;" class="button-secondary" id="preview-block-<wpai_block-' + (lastIndex + 1) + '">Preview</button><div id="wpai_block-' + (lastIndex + 1) + '_div"></div><textarea style="width: 95%;" wrap="soft" rows="5" value="" class="regular-text" id="wpai_block-' + (lastIndex + 1) + '" name="wpai_settings[blocks][' + lastIndex + ']"></textarea><input type="checkbox" id="checkbox_wpai_settings[blocks][' + lastIndex + ']" data-ad-block="wpai_block-' + (lastIndex + 1) + '" class="delete-checkbox"></td></tr>');
     31            jQuery('#before-blocks + table.form-table tbody').append(
     32                '<tr>'
     33                    +'<th scope="row">'
     34                        +'<label for="wpai_block-' + (lastIndex + 1) + '">Ad Block ' + (lastIndex + 1) + '</label>'
     35                    +'</th>'
     36                    +'<td>'
     37                        +'<button onclick="previewBlock(\'wpai_block-' + (lastIndex + 1) + '\');return false;" class="button-secondary" id="preview-block-<wpai_block-' + (lastIndex + 1) + '">Preview</button>'
     38                        +'<div id="wpai_block-' + (lastIndex + 1) + '_div"></div>'
     39                        +'<textarea style="width: 95%;" wrap="soft" rows="5" value="" class="regular-text" id="wpai_block-' + (lastIndex + 1) + '" name="wpai_settings[blocks][' + lastIndex + '][text]"></textarea>'
     40                        +'<input type="text" name="wpai_settings[blocks][' + lastIndex + '][name]" value="Ad Block ' + (lastIndex + 1) + '">'
     41                        +'<input type="checkbox" id="checkbox_wpai_settings[blocks][' + lastIndex + ']" data-ad-block="wpai_block-' + (lastIndex + 1) + '" class="delete-checkbox">'
     42                    +'</td>'
     43                +'</tr>');
    3244            jQuery('.delete-checkbox').each(function () {
    3345                jQuery(this).closest('tr').children('th').first().prepend(jQuery(this));
  • wp-advertize-it/trunk/bootstrap.php

    r1051600 r1069497  
    44Plugin URI:  https://wordpress.org/plugins/wp-advertize-it/
    55Description: A plugin to place adsense blocks on your site
    6 Version:     0.9.3
     6Version:     0.9.4
    77Author:      Henri Benoit
    88Author URI:  http://benohead.com
  • wp-advertize-it/trunk/classes/wp-advertize-it.php

    r1051600 r1069497  
    2424         * Plugin version
    2525         */
    26         const VERSION = '0.9.3';
     26        const VERSION = '0.9.4';
    2727        /**
    2828         * Prefix used to identify things related to this plugin
     
    343343            $ad_block = "";
    344344            $blocks = $this->modules['WPAI_Settings']->settings['blocks'];
    345             if (isset($blocks[intval($block) - 1])) {
    346                 $ad_block = $blocks[intval($block) - 1];
     345            if (isset($blocks[intval($block) - 1]) && isset($blocks[intval($block) - 1]['text'])) {
     346                $ad_block = $blocks[intval($block) - 1]['text'];
    347347            }
    348348            return $ad_block;
     
    367367                    <?php foreach ($blocks as $i => $block) : ?>
    368368                        <option style="padding-right: 10px;"
    369                                 value="<?php echo esc_attr(($i + 1)); ?>"><?php echo 'Ad Block ' . ($i + 1); ?></option>
     369                                value="<?php echo esc_attr(($i + 1)); ?>"><?php echo $block['name']; ?></option>
    370370                    <?php endforeach; ?>
    371371                </select>
     
    613613        }
    614614
     615        public function endsWith($haystack, $needle) {
     616            return $needle === "" || strpos($haystack, $needle, strlen($haystack) - strlen($needle)) !== FALSE;
     617        }
     618
     619        public function endsWithDot($haystack) {
     620            return $this->endsWith($haystack, ".");
     621        }
     622
    615623        /**
    616624         * Adds the ad blocks to be displayed in the provided contents
     
    654662            $after_first_post_paragraph_block = $this->modules['WPAI_Settings']->settings['placements']['after-first-post-paragraph'];
    655663            $after_first_page_paragraph_block = $this->modules['WPAI_Settings']->settings['placements']['after-first-page-paragraph'];
     664            $before_last_post_sentence_block = $this->modules['WPAI_Settings']->settings['placements']['before-last-post-sentence'];
     665            $before_last_page_sentence_block = $this->modules['WPAI_Settings']->settings['placements']['before-last-page-sentence'];
    656666
    657667            if (!is_feed() && strpos($content, '<!--NoHomePageAds-->') !== false) {
     
    675685                $before_last_post_paragraph_block = "";
    676686                $before_last_page_paragraph_block = "";
     687            }
     688            if (!is_feed() && strpos($content, '<!--NoBeforeLastSentenceAds-->') !== false) {
     689                $before_last_post_sentence_block = "";
     690                $before_last_page_sentence_block = "";
    677691            }
    678692            if (!is_feed() && strpos($content, '<!--NoAfterFirstParagraphAds-->') !== false) {
     
    749763            }
    750764            if (is_single()
     765                && $before_last_post_sentence_block != ""
     766                && intval($options['min-char-count']) <= $char_count
     767                && intval($options['min-word-count']) <= $word_count
     768                && intval($options['min-sentence-count']) <= $paragraph_count
     769            ) {
     770                $before_last_post_sentence = WPAI_Settings::get_ad_block($blocks, $before_last_post_sentence_block);
     771
     772                $last = strrpos($content, '.');
     773                if ($last !== false) {
     774                    if ($this->endsWithDot(rtrim(strip_tags( $content)))) {
     775                        $index = strrpos($content, '.', $last - strlen($content) - 1) + 1;
     776                    }
     777                    else {
     778                        $index = $last+1;
     779                    }
     780                    $content = substr_replace($content, $before_last_post_sentence, $index, 0);
     781                }
     782            } else if (is_page()
     783                && $before_last_page_sentence_block != ""
     784                && intval($options['min-char-count']) <= $char_count
     785                && intval($options['min-word-count']) <= $word_count
     786                && intval($options['min-sentence-count']) <= $paragraph_count
     787            ) {
     788                $before_last_page_sentence = WPAI_Settings::get_ad_block($blocks, $before_last_page_sentence_block);
     789
     790                $last = strrpos($content, '.');
     791                if ($last !== false) {
     792                    if ($this->endsWithDot(rtrim(strip_tags( $content)))) {
     793                        $index = strrpos($content, '.', $last - strlen($content) - 1) + 1;
     794                    }
     795                    else {
     796                        $index = $last+1;
     797                    }
     798                    $content = substr_replace($content, $before_last_page_sentence, $index, 0);
     799                }
     800            }
     801            if (is_single()
    751802                && $after_first_post_paragraph_block != ""
    752803                && intval($options['min-char-count']) <= $char_count
     
    921972            foreach ( $blocks as $number => $code ) {
    922973                if ( strpos( $content, '<!--NoAdBlock' . ( $number + 1 ) . '-->' ) !== false ) {
    923                     $blocks[ $number ] = "";
     974                    $blocks[ $number ]['text'] = "";
    924975                }
    925976            }
  • wp-advertize-it/trunk/classes/wpai-settings.php

    r1045033 r1069497  
    109109        public function upgrade($db_version = 0)
    110110        {
    111             /*
    112             if( version_compare( $db_version, 'x.y.z', '<' ) )
     111            error_log('db_version='.$db_version);
     112            if( version_compare( $db_version, '0.9.4', '<' ) )
    113113            {
    114                 // Do stuff
    115             }
    116             */
     114                error_log("options=".print_r($this->settings, true));
     115                if (isset($this->settings['blocks'])) {
     116                    $blocks = $this->settings['blocks'];
     117                    foreach ($blocks as $i => $block) {
     118                        $block_name = 'Ad Block ' . ($i + 1);
     119                        $this->settings['blocks'][$i]=array();
     120                        $this->settings['blocks'][$i]['name']=$block_name;
     121                        $this->settings['blocks'][$i]['text']=$block;
     122                    }
     123                }
     124                error_log("options=".print_r($this->settings, true));
     125            }
    117126        }
    118127
     
    160169                "before-last-post-paragraph" => "",
    161170                "before-last-page-paragraph" => "",
     171                "before-last-post-sentence" => "",
     172                "before-last-page-sentence" => "",
    162173                "after-first-post-paragraph" => "",
    163174                "after-first-page-paragraph" => "",
     
    322333
    323334            foreach ($blocks as $i => $block) {
    324                 $this->add_settings_field_blocks('wpai_block-' . ($i + 1), 'Ad Block ' . ($i + 1));
     335                $this->add_settings_field_blocks('wpai_block-' . ($i + 1), $block['name']);
    325336            }
    326337
     
    335346            $this->add_settings_field_placements('wpai_middle-of-post', 'Middle of post');
    336347            $this->add_settings_field_placements('wpai_before-last-post-paragraph', 'Before last post paragraph');
     348            $this->add_settings_field_placements('wpai_before-last-post-sentence', 'Before last post sentence');
    337349            $this->add_settings_field_placements('wpai_post-below-content', 'Posts below content');
    338350            $this->add_settings_field_placements('wpai_post-below-comments', 'Posts below comments');
     
    341353            $this->add_settings_field_placements('wpai_middle-of-page', 'Middle of page');
    342354            $this->add_settings_field_placements('wpai_before-last-page-paragraph', 'Before last page paragraph');
     355            $this->add_settings_field_placements('wpai_before-last-page-sentence', 'Before last page sentence');
    343356            $this->add_settings_field_placements('wpai_page-below-content', 'Pages below content');
    344357            $this->add_settings_field_placements('wpai_page-below-comments', 'Pages below comments');
     
    403416        public static function get_ad_block($blocks, $id)
    404417        {
    405             if (isset($blocks[intval($id)])) {
    406                 return $blocks[intval($id)];
     418            if (isset($blocks[intval($id)]) && isset($blocks[intval($id)]['text'])) {
     419                return $blocks[intval($id)]['text'];
    407420            }
    408421            return "";
     
    488501            $this->setting_empty_string_if_not_set($new_settings, 'placements', 'before-last-post-paragraph');
    489502            $this->setting_empty_string_if_not_set($new_settings, 'placements', 'before-last-page-paragraph');
     503            $this->setting_empty_string_if_not_set($new_settings, 'placements', 'before-last-post-sentence');
     504            $this->setting_empty_string_if_not_set($new_settings, 'placements', 'before-last-page-sentence');
    490505            $this->setting_empty_string_if_not_set($new_settings, 'placements', 'after-first-post-paragraph');
    491506            $this->setting_empty_string_if_not_set($new_settings, 'placements', 'after-first-page-paragraph');
  • wp-advertize-it/trunk/classes/wpai-widget.php

    r932299 r1069497  
    6868                <?php
    6969                foreach ($settings['blocks'] as $i => $block) :
    70                     $label = 'Ad Block ' . ($i + 1);
     70                    $label = $block['name'];
    7171                    $selected = '';
    7272                    if ($selected_block == $i)
  • wp-advertize-it/trunk/css/admin.css

    r1006845 r1069497  
    2222
    2323.settings_page_wpai_settings .ace_editor {
    24     margin-bottom: 1.7em;
    2524    min-height: 150px;
    2625}
     
    2827    margin-top: 0;
    2928}
     29
     30.settings_page_wpai_settings #before-blocks + table.form-table > tbody > tr {
     31    border-bottom: 1.7em solid transparent;
     32}
  • wp-advertize-it/trunk/readme.txt

    r1051600 r1069497  
    55Requires at least: 3.0.1
    66Tested up to: 4.1
    7 Stable tag: 0.9.3
     7Stable tag: 0.9.4
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    2828* Middle of post   
    2929* Before last post paragraph   
     30* Before last post sentence
    3031* Posts below content   
    3132* Posts below comments 
     
    3435* Middle of page   
    3536* Before last page paragraph   
     37* Before last page sentence
    3638* Pages below content   
    3739* Pages below comments 
    3840* Below footer 
     41
     42Note that sentences might not be identified correctly if there are dots within sentences e.g. "it is a country with 80.6 million inhabitants." - this would be identified as two sentences instead of one. Instead of this placement you may want to use the "before last post/page paragraph" placement and make sure the last sentence is on its own paragraph.
    3943
    4044A widget is also available to display in a sidebar.
     
    109113== Changelog ==
    110114
     115= 0.9.4 =
     116
     117* Ad blocks can be renamed in the text field below the editor. Renaming occurs only when the settings are saved.
     118* Added placement option for before last sentence. Sentences might not be identified correctly if there are dots within sentences e.g. "it is a country with 80.6 million inhabitants." - this would be identified as two sentences instead of one. Instead of this placement you may want to use the "before last paragraph" placement and make sure the last sentence is on its own paragraph.
     119
    111120= 0.9.3 =
    112121
  • wp-advertize-it/trunk/views/wpai-settings/page-settings-fields.php

    r1051600 r1069497  
    1010    <div id="<?php esc_attr_e($field['label_for']); ?>_div"></div>
    1111    <textarea style="width: 95%;" wrap="soft" rows="5" id="<?php esc_attr_e($field['label_for']); ?>"
    12               name="<?php esc_attr_e('wpai_settings[blocks][' . (intval(substr($field['label_for'], strlen('wpai_block-'))) - 1) . ']'); ?>"
    13               class="regular-text"><?php esc_attr_e($settings['blocks'][intval(substr($field['label_for'], strlen('wpai_block-'))) - 1]); ?></textarea>
     12              name="<?php esc_attr_e('wpai_settings[blocks][' . (intval(substr($field['label_for'], strlen('wpai_block-'))) - 1) . '][text]'); ?>"
     13              class="regular-text"><?php esc_attr_e($settings['blocks'][intval(substr($field['label_for'], strlen('wpai_block-'))) - 1]['text']); ?></textarea>
     14    <input type="text"
     15           name="<?php esc_attr_e('wpai_settings[blocks][' . (intval(substr($field['label_for'], strlen('wpai_block-'))) - 1) . '][name]'); ?>"
     16           value="<?php esc_attr_e($settings['blocks'][intval(substr($field['label_for'], strlen('wpai_block-'))) - 1]['name']); ?>">
    1417    <input type="checkbox"
    1518           id="checkbox_<?php esc_attr_e('wpai_settings[blocks][' . substr($field['label_for'], strlen('wpai_block-')) . ']'); ?>"
     
    2932        <?php
    3033        foreach ($settings['blocks'] as $i => $block) :
    31             $label = 'Ad Block ' . ($i + 1);
     34            $label = $block['name'];
    3235            $selected = '';
    3336            if (intval($settings['placements']['homepage-below-title']) === $i)
     
    4851        <?php
    4952        foreach ($settings['blocks'] as $i => $block) :
    50             $label = 'Ad Block ' . ($i + 1);
     53            $label = $block['name'];
    5154            $selected = '';
    5255            if (intval($settings['placements']['post-below-title']) === $i)
     
    6871        <?php
    6972        foreach ($settings['blocks'] as $i => $block) :
    70             $label = 'Ad Block ' . ($i + 1);
     73            $label = $block['name'];
    7174            $selected = '';
    7275            if (intval($settings['placements']['post-below-content']) === $i)
     
    8891        <?php
    8992        foreach ($settings['blocks'] as $i => $block) :
    90             $label = 'Ad Block ' . ($i + 1);
     93            $label = $block['name'];
    9194            $selected = '';
    9295            if (intval($settings['placements']['post-below-comments']) === $i)
     
    108111        <?php
    109112        foreach ($settings['blocks'] as $i => $block) :
    110             $label = 'Ad Block ' . ($i + 1);
     113            $label = $block['name'];
    111114            $selected = '';
    112115            if (intval($settings['placements']['page-below-title']) === $i)
     
    128131        <?php
    129132        foreach ($settings['blocks'] as $i => $block) :
    130             $label = 'Ad Block ' . ($i + 1);
     133            $label = $block['name'];
    131134            $selected = '';
    132135            if (intval($settings['placements']['page-below-content']) === $i)
     
    148151        <?php
    149152        foreach ($settings['blocks'] as $i => $block) :
    150             $label = 'Ad Block ' . ($i + 1);
     153            $label = $block['name'];
    151154            $selected = '';
    152155            if (intval($settings['placements']['page-below-comments']) === $i)
     
    168171        <?php
    169172        foreach ($settings['blocks'] as $i => $block) :
    170             $label = 'Ad Block ' . ($i + 1);
     173            $label = $block['name'];
    171174            $selected = '';
    172175            if (intval($settings['placements']['all-below-footer']) === $i)
     
    188191        <?php
    189192        foreach ($settings['blocks'] as $i => $block) :
    190             $label = 'Ad Block ' . ($i + 1);
     193            $label = $block['name'];
    191194            $selected = '';
    192195            if (intval($settings['placements']['middle-of-post']) === $i)
     
    208211        <?php
    209212        foreach ($settings['blocks'] as $i => $block) :
    210             $label = 'Ad Block ' . ($i + 1);
     213            $label = $block['name'];
    211214            $selected = '';
    212215            if (intval($settings['placements']['middle-of-page']) === $i)
     
    228231        <?php
    229232        foreach ($settings['blocks'] as $i => $block) :
    230             $label = 'Ad Block ' . ($i + 1);
     233            $label = $block['name'];
    231234            $selected = '';
    232235            if (intval($settings['placements']['before-last-post-paragraph']) === $i)
     
    248251        <?php
    249252        foreach ($settings['blocks'] as $i => $block) :
    250             $label = 'Ad Block ' . ($i + 1);
     253            $label = $block['name'];
    251254            $selected = '';
    252255            if (intval($settings['placements']['before-last-page-paragraph']) === $i)
     
    258261        $selected = '';
    259262        if ($settings['placements']['before-last-page-paragraph'] === $i)
     263            $selected = 'selected="selected"';
     264        echo '<option style="padding-right: 10px;" value="' . esc_attr($i) . '" ' . $selected . '>' . $label . '</option>';
     265        ?>
     266    </select>
     267<?php
     268elseif ('wpai_before-last-post-sentence' == $field['label_for']) : ?>
     269    <select class="placement-block-select" id="wpai_settings[placements][before-last-post-sentence]"
     270            name="wpai_settings[placements][before-last-post-sentence]">
     271        <?php
     272        foreach ($settings['blocks'] as $i => $block) :
     273            $label = $block['name'];
     274            $selected = '';
     275            if (intval($settings['placements']['before-last-post-sentence']) === $i)
     276                $selected = 'selected="selected"';
     277            echo '<option data-block-id="wpai_block-' . esc_attr($i + 1) . '" style="padding-right: 10px;" value="' . esc_attr($i) . '" ' . $selected . '>' . $label . '</option>';
     278        endforeach;
     279        $i = "";
     280        $label = 'None';
     281        $selected = '';
     282        if ($settings['placements']['before-last-post-sentence'] === $i)
     283            $selected = 'selected="selected"';
     284        echo '<option style="padding-right: 10px;" value="' . esc_attr($i) . '" ' . $selected . '>' . $label . '</option>';
     285        ?>
     286    </select>
     287<?php
     288elseif ('wpai_before-last-page-sentence' == $field['label_for']) : ?>
     289    <select class="placement-block-select" id="wpai_settings[placements][before-last-page-sentence]"
     290            name="wpai_settings[placements][before-last-page-sentence]">
     291        <?php
     292        foreach ($settings['blocks'] as $i => $block) :
     293            $label = $block['name'];
     294            $selected = '';
     295            if (intval($settings['placements']['before-last-page-sentence']) === $i)
     296                $selected = 'selected="selected"';
     297            echo '<option data-block-id="wpai_block-' . esc_attr($i + 1) . '" style="padding-right: 10px;" value="' . esc_attr($i) . '" ' . $selected . '>' . $label . '</option>';
     298        endforeach;
     299        $i = "";
     300        $label = 'None';
     301        $selected = '';
     302        if ($settings['placements']['before-last-page-sentence'] === $i)
    260303            $selected = 'selected="selected"';
    261304        echo '<option style="padding-right: 10px;" value="' . esc_attr($i) . '" ' . $selected . '>' . $label . '</option>';
     
    268311        <?php
    269312        foreach ($settings['blocks'] as $i => $block) :
    270             $label = 'Ad Block ' . ($i + 1);
     313            $label = $block['name'];
    271314            $selected = '';
    272315            if (intval($settings['placements']['after-first-post-paragraph']) === $i)
     
    288331        <?php
    289332        foreach ($settings['blocks'] as $i => $block) :
    290             $label = 'Ad Block ' . ($i + 1);
     333            $label = $block['name'];
    291334            $selected = '';
    292335            if (intval($settings['placements']['after-first-page-paragraph']) === $i)
     
    308351        <?php
    309352        foreach ($settings['blocks'] as $i => $block) :
    310             $label = 'Ad Block ' . ($i + 1);
     353            $label = $block['name'];
    311354            $selected = '';
    312355            if (intval($settings['placements']['between-posts']) === $i)
     
    328371        <?php
    329372        foreach ($settings['blocks'] as $i => $block) :
    330             $label = 'Ad Block ' . ($i + 1);
     373            $label = $block['name'];
    331374            $selected = '';
    332375            if (intval($settings['placements']['above-everything']) === $i)
  • wp-advertize-it/trunk/views/wpai-settings/page-settings-section-headers.php

    r1045033 r1069497  
    2929                }
    3030            });
    31             jQuery('#before-blocks + table.form-table tbody').append('<tr><th scope="row"><label for="wpai_block-' + (lastIndex + 1) + '">Ad Block ' + (lastIndex + 1) + '</label></div></th><td><button onclick="previewBlock(\'wpai_block-' + (lastIndex + 1) + '\');return false;" class="button-secondary" id="preview-block-<wpai_block-' + (lastIndex + 1) + '">Preview</button><div id="wpai_block-' + (lastIndex + 1) + '_div"></div><textarea style="width: 95%;" wrap="soft" rows="5" value="" class="regular-text" id="wpai_block-' + (lastIndex + 1) + '" name="wpai_settings[blocks][' + lastIndex + ']"></textarea><input type="checkbox" id="checkbox_wpai_settings[blocks][' + lastIndex + ']" data-ad-block="wpai_block-' + (lastIndex + 1) + '" class="delete-checkbox"></td></tr>');
     31            jQuery('#before-blocks + table.form-table tbody').append(
     32                '<tr>'
     33                    +'<th scope="row">'
     34                        +'<label for="wpai_block-' + (lastIndex + 1) + '">Ad Block ' + (lastIndex + 1) + '</label>'
     35                    +'</th>'
     36                    +'<td>'
     37                        +'<button onclick="previewBlock(\'wpai_block-' + (lastIndex + 1) + '\');return false;" class="button-secondary" id="preview-block-<wpai_block-' + (lastIndex + 1) + '">Preview</button>'
     38                        +'<div id="wpai_block-' + (lastIndex + 1) + '_div"></div>'
     39                        +'<textarea style="width: 95%;" wrap="soft" rows="5" value="" class="regular-text" id="wpai_block-' + (lastIndex + 1) + '" name="wpai_settings[blocks][' + lastIndex + '][text]"></textarea>'
     40                        +'<input type="text" name="wpai_settings[blocks][' + lastIndex + '][name]" value="Ad Block ' + (lastIndex + 1) + '">'
     41                        +'<input type="checkbox" id="checkbox_wpai_settings[blocks][' + lastIndex + ']" data-ad-block="wpai_block-' + (lastIndex + 1) + '" class="delete-checkbox">'
     42                    +'</td>'
     43                +'</tr>');
    3244            jQuery('.delete-checkbox').each(function () {
    3345                jQuery(this).closest('tr').children('th').first().prepend(jQuery(this));
Note: See TracChangeset for help on using the changeset viewer.