Changeset 1069497
- Timestamp:
- 01/16/2015 04:08:24 PM (11 years ago)
- Location:
- wp-advertize-it
- Files:
-
- 1 added
- 14 edited
- 14 copied
-
tags/0.9.4 (added)
-
tags/0.9.4/ace (copied) (copied from wp-advertize-it/trunk/ace)
-
tags/0.9.4/bootstrap.php (copied) (copied from wp-advertize-it/trunk/bootstrap.php) (1 diff)
-
tags/0.9.4/classes (copied) (copied from wp-advertize-it/trunk/classes)
-
tags/0.9.4/classes/wp-advertize-it.php (modified) (8 diffs)
-
tags/0.9.4/classes/wpai-settings.php (modified) (7 diffs)
-
tags/0.9.4/classes/wpai-widget.php (modified) (1 diff)
-
tags/0.9.4/css (copied) (copied from wp-advertize-it/trunk/css)
-
tags/0.9.4/css/admin.css (modified) (2 diffs)
-
tags/0.9.4/images (copied) (copied from wp-advertize-it/trunk/images)
-
tags/0.9.4/includes (copied) (copied from wp-advertize-it/trunk/includes)
-
tags/0.9.4/javascript (copied) (copied from wp-advertize-it/trunk/javascript)
-
tags/0.9.4/readme.txt (copied) (copied from wp-advertize-it/trunk/readme.txt) (4 diffs)
-
tags/0.9.4/screenshot-1.png (copied) (copied from wp-advertize-it/trunk/screenshot-1.png)
-
tags/0.9.4/screenshot-2.png (copied) (copied from wp-advertize-it/trunk/screenshot-2.png)
-
tags/0.9.4/screenshot-3.png (copied) (copied from wp-advertize-it/trunk/screenshot-3.png)
-
tags/0.9.4/screenshot-4.png (copied) (copied from wp-advertize-it/trunk/screenshot-4.png)
-
tags/0.9.4/screenshot-5.png (copied) (copied from wp-advertize-it/trunk/screenshot-5.png)
-
tags/0.9.4/views (copied) (copied from wp-advertize-it/trunk/views)
-
tags/0.9.4/views/wpai-settings/page-settings-fields.php (modified) (18 diffs)
-
tags/0.9.4/views/wpai-settings/page-settings-section-headers.php (modified) (1 diff)
-
trunk/bootstrap.php (modified) (1 diff)
-
trunk/classes/wp-advertize-it.php (modified) (8 diffs)
-
trunk/classes/wpai-settings.php (modified) (7 diffs)
-
trunk/classes/wpai-widget.php (modified) (1 diff)
-
trunk/css/admin.css (modified) (2 diffs)
-
trunk/readme.txt (modified) (4 diffs)
-
trunk/views/wpai-settings/page-settings-fields.php (modified) (18 diffs)
-
trunk/views/wpai-settings/page-settings-section-headers.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
wp-advertize-it/tags/0.9.4/bootstrap.php
r1069307 r1069497 4 4 Plugin URI: https://wordpress.org/plugins/wp-advertize-it/ 5 5 Description: A plugin to place adsense blocks on your site 6 Version: 0.9. 36 Version: 0.9.4 7 7 Author: Henri Benoit 8 8 Author URI: http://benohead.com -
wp-advertize-it/tags/0.9.4/classes/wp-advertize-it.php
r1051600 r1069497 24 24 * Plugin version 25 25 */ 26 const VERSION = '0.9. 3';26 const VERSION = '0.9.4'; 27 27 /** 28 28 * Prefix used to identify things related to this plugin … … 343 343 $ad_block = ""; 344 344 $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']; 347 347 } 348 348 return $ad_block; … … 367 367 <?php foreach ($blocks as $i => $block) : ?> 368 368 <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> 370 370 <?php endforeach; ?> 371 371 </select> … … 613 613 } 614 614 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 615 623 /** 616 624 * Adds the ad blocks to be displayed in the provided contents … … 654 662 $after_first_post_paragraph_block = $this->modules['WPAI_Settings']->settings['placements']['after-first-post-paragraph']; 655 663 $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']; 656 666 657 667 if (!is_feed() && strpos($content, '<!--NoHomePageAds-->') !== false) { … … 675 685 $before_last_post_paragraph_block = ""; 676 686 $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 = ""; 677 691 } 678 692 if (!is_feed() && strpos($content, '<!--NoAfterFirstParagraphAds-->') !== false) { … … 749 763 } 750 764 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() 751 802 && $after_first_post_paragraph_block != "" 752 803 && intval($options['min-char-count']) <= $char_count … … 921 972 foreach ( $blocks as $number => $code ) { 922 973 if ( strpos( $content, '<!--NoAdBlock' . ( $number + 1 ) . '-->' ) !== false ) { 923 $blocks[ $number ] = "";974 $blocks[ $number ]['text'] = ""; 924 975 } 925 976 } -
wp-advertize-it/tags/0.9.4/classes/wpai-settings.php
r1045033 r1069497 109 109 public function upgrade($db_version = 0) 110 110 { 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', '<' ) ) 113 113 { 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 } 117 126 } 118 127 … … 160 169 "before-last-post-paragraph" => "", 161 170 "before-last-page-paragraph" => "", 171 "before-last-post-sentence" => "", 172 "before-last-page-sentence" => "", 162 173 "after-first-post-paragraph" => "", 163 174 "after-first-page-paragraph" => "", … … 322 333 323 334 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']); 325 336 } 326 337 … … 335 346 $this->add_settings_field_placements('wpai_middle-of-post', 'Middle of post'); 336 347 $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'); 337 349 $this->add_settings_field_placements('wpai_post-below-content', 'Posts below content'); 338 350 $this->add_settings_field_placements('wpai_post-below-comments', 'Posts below comments'); … … 341 353 $this->add_settings_field_placements('wpai_middle-of-page', 'Middle of page'); 342 354 $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'); 343 356 $this->add_settings_field_placements('wpai_page-below-content', 'Pages below content'); 344 357 $this->add_settings_field_placements('wpai_page-below-comments', 'Pages below comments'); … … 403 416 public static function get_ad_block($blocks, $id) 404 417 { 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']; 407 420 } 408 421 return ""; … … 488 501 $this->setting_empty_string_if_not_set($new_settings, 'placements', 'before-last-post-paragraph'); 489 502 $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'); 490 505 $this->setting_empty_string_if_not_set($new_settings, 'placements', 'after-first-post-paragraph'); 491 506 $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 68 68 <?php 69 69 foreach ($settings['blocks'] as $i => $block) : 70 $label = 'Ad Block ' . ($i + 1);70 $label = $block['name']; 71 71 $selected = ''; 72 72 if ($selected_block == $i) -
wp-advertize-it/tags/0.9.4/css/admin.css
r1006845 r1069497 22 22 23 23 .settings_page_wpai_settings .ace_editor { 24 margin-bottom: 1.7em;25 24 min-height: 150px; 26 25 } … … 28 27 margin-top: 0; 29 28 } 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 5 5 Requires at least: 3.0.1 6 6 Tested up to: 4.1 7 Stable tag: 0.9. 37 Stable tag: 0.9.4 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 28 28 * Middle of post 29 29 * Before last post paragraph 30 * Before last post sentence 30 31 * Posts below content 31 32 * Posts below comments … … 34 35 * Middle of page 35 36 * Before last page paragraph 37 * Before last page sentence 36 38 * Pages below content 37 39 * Pages below comments 38 40 * Below footer 41 42 Note 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. 39 43 40 44 A widget is also available to display in a sidebar. … … 109 113 == Changelog == 110 114 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 111 120 = 0.9.3 = 112 121 -
wp-advertize-it/tags/0.9.4/views/wpai-settings/page-settings-fields.php
r1051600 r1069497 10 10 <div id="<?php esc_attr_e($field['label_for']); ?>_div"></div> 11 11 <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']); ?>"> 14 17 <input type="checkbox" 15 18 id="checkbox_<?php esc_attr_e('wpai_settings[blocks][' . substr($field['label_for'], strlen('wpai_block-')) . ']'); ?>" … … 29 32 <?php 30 33 foreach ($settings['blocks'] as $i => $block) : 31 $label = 'Ad Block ' . ($i + 1);34 $label = $block['name']; 32 35 $selected = ''; 33 36 if (intval($settings['placements']['homepage-below-title']) === $i) … … 48 51 <?php 49 52 foreach ($settings['blocks'] as $i => $block) : 50 $label = 'Ad Block ' . ($i + 1);53 $label = $block['name']; 51 54 $selected = ''; 52 55 if (intval($settings['placements']['post-below-title']) === $i) … … 68 71 <?php 69 72 foreach ($settings['blocks'] as $i => $block) : 70 $label = 'Ad Block ' . ($i + 1);73 $label = $block['name']; 71 74 $selected = ''; 72 75 if (intval($settings['placements']['post-below-content']) === $i) … … 88 91 <?php 89 92 foreach ($settings['blocks'] as $i => $block) : 90 $label = 'Ad Block ' . ($i + 1);93 $label = $block['name']; 91 94 $selected = ''; 92 95 if (intval($settings['placements']['post-below-comments']) === $i) … … 108 111 <?php 109 112 foreach ($settings['blocks'] as $i => $block) : 110 $label = 'Ad Block ' . ($i + 1);113 $label = $block['name']; 111 114 $selected = ''; 112 115 if (intval($settings['placements']['page-below-title']) === $i) … … 128 131 <?php 129 132 foreach ($settings['blocks'] as $i => $block) : 130 $label = 'Ad Block ' . ($i + 1);133 $label = $block['name']; 131 134 $selected = ''; 132 135 if (intval($settings['placements']['page-below-content']) === $i) … … 148 151 <?php 149 152 foreach ($settings['blocks'] as $i => $block) : 150 $label = 'Ad Block ' . ($i + 1);153 $label = $block['name']; 151 154 $selected = ''; 152 155 if (intval($settings['placements']['page-below-comments']) === $i) … … 168 171 <?php 169 172 foreach ($settings['blocks'] as $i => $block) : 170 $label = 'Ad Block ' . ($i + 1);173 $label = $block['name']; 171 174 $selected = ''; 172 175 if (intval($settings['placements']['all-below-footer']) === $i) … … 188 191 <?php 189 192 foreach ($settings['blocks'] as $i => $block) : 190 $label = 'Ad Block ' . ($i + 1);193 $label = $block['name']; 191 194 $selected = ''; 192 195 if (intval($settings['placements']['middle-of-post']) === $i) … … 208 211 <?php 209 212 foreach ($settings['blocks'] as $i => $block) : 210 $label = 'Ad Block ' . ($i + 1);213 $label = $block['name']; 211 214 $selected = ''; 212 215 if (intval($settings['placements']['middle-of-page']) === $i) … … 228 231 <?php 229 232 foreach ($settings['blocks'] as $i => $block) : 230 $label = 'Ad Block ' . ($i + 1);233 $label = $block['name']; 231 234 $selected = ''; 232 235 if (intval($settings['placements']['before-last-post-paragraph']) === $i) … … 248 251 <?php 249 252 foreach ($settings['blocks'] as $i => $block) : 250 $label = 'Ad Block ' . ($i + 1);253 $label = $block['name']; 251 254 $selected = ''; 252 255 if (intval($settings['placements']['before-last-page-paragraph']) === $i) … … 258 261 $selected = ''; 259 262 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 268 elseif ('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 288 elseif ('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) 260 303 $selected = 'selected="selected"'; 261 304 echo '<option style="padding-right: 10px;" value="' . esc_attr($i) . '" ' . $selected . '>' . $label . '</option>'; … … 268 311 <?php 269 312 foreach ($settings['blocks'] as $i => $block) : 270 $label = 'Ad Block ' . ($i + 1);313 $label = $block['name']; 271 314 $selected = ''; 272 315 if (intval($settings['placements']['after-first-post-paragraph']) === $i) … … 288 331 <?php 289 332 foreach ($settings['blocks'] as $i => $block) : 290 $label = 'Ad Block ' . ($i + 1);333 $label = $block['name']; 291 334 $selected = ''; 292 335 if (intval($settings['placements']['after-first-page-paragraph']) === $i) … … 308 351 <?php 309 352 foreach ($settings['blocks'] as $i => $block) : 310 $label = 'Ad Block ' . ($i + 1);353 $label = $block['name']; 311 354 $selected = ''; 312 355 if (intval($settings['placements']['between-posts']) === $i) … … 328 371 <?php 329 372 foreach ($settings['blocks'] as $i => $block) : 330 $label = 'Ad Block ' . ($i + 1);373 $label = $block['name']; 331 374 $selected = ''; 332 375 if (intval($settings['placements']['above-everything']) === $i) -
wp-advertize-it/tags/0.9.4/views/wpai-settings/page-settings-section-headers.php
r1045033 r1069497 29 29 } 30 30 }); 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>'); 32 44 jQuery('.delete-checkbox').each(function () { 33 45 jQuery(this).closest('tr').children('th').first().prepend(jQuery(this)); -
wp-advertize-it/trunk/bootstrap.php
r1051600 r1069497 4 4 Plugin URI: https://wordpress.org/plugins/wp-advertize-it/ 5 5 Description: A plugin to place adsense blocks on your site 6 Version: 0.9. 36 Version: 0.9.4 7 7 Author: Henri Benoit 8 8 Author URI: http://benohead.com -
wp-advertize-it/trunk/classes/wp-advertize-it.php
r1051600 r1069497 24 24 * Plugin version 25 25 */ 26 const VERSION = '0.9. 3';26 const VERSION = '0.9.4'; 27 27 /** 28 28 * Prefix used to identify things related to this plugin … … 343 343 $ad_block = ""; 344 344 $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']; 347 347 } 348 348 return $ad_block; … … 367 367 <?php foreach ($blocks as $i => $block) : ?> 368 368 <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> 370 370 <?php endforeach; ?> 371 371 </select> … … 613 613 } 614 614 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 615 623 /** 616 624 * Adds the ad blocks to be displayed in the provided contents … … 654 662 $after_first_post_paragraph_block = $this->modules['WPAI_Settings']->settings['placements']['after-first-post-paragraph']; 655 663 $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']; 656 666 657 667 if (!is_feed() && strpos($content, '<!--NoHomePageAds-->') !== false) { … … 675 685 $before_last_post_paragraph_block = ""; 676 686 $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 = ""; 677 691 } 678 692 if (!is_feed() && strpos($content, '<!--NoAfterFirstParagraphAds-->') !== false) { … … 749 763 } 750 764 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() 751 802 && $after_first_post_paragraph_block != "" 752 803 && intval($options['min-char-count']) <= $char_count … … 921 972 foreach ( $blocks as $number => $code ) { 922 973 if ( strpos( $content, '<!--NoAdBlock' . ( $number + 1 ) . '-->' ) !== false ) { 923 $blocks[ $number ] = "";974 $blocks[ $number ]['text'] = ""; 924 975 } 925 976 } -
wp-advertize-it/trunk/classes/wpai-settings.php
r1045033 r1069497 109 109 public function upgrade($db_version = 0) 110 110 { 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', '<' ) ) 113 113 { 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 } 117 126 } 118 127 … … 160 169 "before-last-post-paragraph" => "", 161 170 "before-last-page-paragraph" => "", 171 "before-last-post-sentence" => "", 172 "before-last-page-sentence" => "", 162 173 "after-first-post-paragraph" => "", 163 174 "after-first-page-paragraph" => "", … … 322 333 323 334 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']); 325 336 } 326 337 … … 335 346 $this->add_settings_field_placements('wpai_middle-of-post', 'Middle of post'); 336 347 $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'); 337 349 $this->add_settings_field_placements('wpai_post-below-content', 'Posts below content'); 338 350 $this->add_settings_field_placements('wpai_post-below-comments', 'Posts below comments'); … … 341 353 $this->add_settings_field_placements('wpai_middle-of-page', 'Middle of page'); 342 354 $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'); 343 356 $this->add_settings_field_placements('wpai_page-below-content', 'Pages below content'); 344 357 $this->add_settings_field_placements('wpai_page-below-comments', 'Pages below comments'); … … 403 416 public static function get_ad_block($blocks, $id) 404 417 { 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']; 407 420 } 408 421 return ""; … … 488 501 $this->setting_empty_string_if_not_set($new_settings, 'placements', 'before-last-post-paragraph'); 489 502 $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'); 490 505 $this->setting_empty_string_if_not_set($new_settings, 'placements', 'after-first-post-paragraph'); 491 506 $this->setting_empty_string_if_not_set($new_settings, 'placements', 'after-first-page-paragraph'); -
wp-advertize-it/trunk/classes/wpai-widget.php
r932299 r1069497 68 68 <?php 69 69 foreach ($settings['blocks'] as $i => $block) : 70 $label = 'Ad Block ' . ($i + 1);70 $label = $block['name']; 71 71 $selected = ''; 72 72 if ($selected_block == $i) -
wp-advertize-it/trunk/css/admin.css
r1006845 r1069497 22 22 23 23 .settings_page_wpai_settings .ace_editor { 24 margin-bottom: 1.7em;25 24 min-height: 150px; 26 25 } … … 28 27 margin-top: 0; 29 28 } 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 5 5 Requires at least: 3.0.1 6 6 Tested up to: 4.1 7 Stable tag: 0.9. 37 Stable tag: 0.9.4 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 28 28 * Middle of post 29 29 * Before last post paragraph 30 * Before last post sentence 30 31 * Posts below content 31 32 * Posts below comments … … 34 35 * Middle of page 35 36 * Before last page paragraph 37 * Before last page sentence 36 38 * Pages below content 37 39 * Pages below comments 38 40 * Below footer 41 42 Note 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. 39 43 40 44 A widget is also available to display in a sidebar. … … 109 113 == Changelog == 110 114 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 111 120 = 0.9.3 = 112 121 -
wp-advertize-it/trunk/views/wpai-settings/page-settings-fields.php
r1051600 r1069497 10 10 <div id="<?php esc_attr_e($field['label_for']); ?>_div"></div> 11 11 <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']); ?>"> 14 17 <input type="checkbox" 15 18 id="checkbox_<?php esc_attr_e('wpai_settings[blocks][' . substr($field['label_for'], strlen('wpai_block-')) . ']'); ?>" … … 29 32 <?php 30 33 foreach ($settings['blocks'] as $i => $block) : 31 $label = 'Ad Block ' . ($i + 1);34 $label = $block['name']; 32 35 $selected = ''; 33 36 if (intval($settings['placements']['homepage-below-title']) === $i) … … 48 51 <?php 49 52 foreach ($settings['blocks'] as $i => $block) : 50 $label = 'Ad Block ' . ($i + 1);53 $label = $block['name']; 51 54 $selected = ''; 52 55 if (intval($settings['placements']['post-below-title']) === $i) … … 68 71 <?php 69 72 foreach ($settings['blocks'] as $i => $block) : 70 $label = 'Ad Block ' . ($i + 1);73 $label = $block['name']; 71 74 $selected = ''; 72 75 if (intval($settings['placements']['post-below-content']) === $i) … … 88 91 <?php 89 92 foreach ($settings['blocks'] as $i => $block) : 90 $label = 'Ad Block ' . ($i + 1);93 $label = $block['name']; 91 94 $selected = ''; 92 95 if (intval($settings['placements']['post-below-comments']) === $i) … … 108 111 <?php 109 112 foreach ($settings['blocks'] as $i => $block) : 110 $label = 'Ad Block ' . ($i + 1);113 $label = $block['name']; 111 114 $selected = ''; 112 115 if (intval($settings['placements']['page-below-title']) === $i) … … 128 131 <?php 129 132 foreach ($settings['blocks'] as $i => $block) : 130 $label = 'Ad Block ' . ($i + 1);133 $label = $block['name']; 131 134 $selected = ''; 132 135 if (intval($settings['placements']['page-below-content']) === $i) … … 148 151 <?php 149 152 foreach ($settings['blocks'] as $i => $block) : 150 $label = 'Ad Block ' . ($i + 1);153 $label = $block['name']; 151 154 $selected = ''; 152 155 if (intval($settings['placements']['page-below-comments']) === $i) … … 168 171 <?php 169 172 foreach ($settings['blocks'] as $i => $block) : 170 $label = 'Ad Block ' . ($i + 1);173 $label = $block['name']; 171 174 $selected = ''; 172 175 if (intval($settings['placements']['all-below-footer']) === $i) … … 188 191 <?php 189 192 foreach ($settings['blocks'] as $i => $block) : 190 $label = 'Ad Block ' . ($i + 1);193 $label = $block['name']; 191 194 $selected = ''; 192 195 if (intval($settings['placements']['middle-of-post']) === $i) … … 208 211 <?php 209 212 foreach ($settings['blocks'] as $i => $block) : 210 $label = 'Ad Block ' . ($i + 1);213 $label = $block['name']; 211 214 $selected = ''; 212 215 if (intval($settings['placements']['middle-of-page']) === $i) … … 228 231 <?php 229 232 foreach ($settings['blocks'] as $i => $block) : 230 $label = 'Ad Block ' . ($i + 1);233 $label = $block['name']; 231 234 $selected = ''; 232 235 if (intval($settings['placements']['before-last-post-paragraph']) === $i) … … 248 251 <?php 249 252 foreach ($settings['blocks'] as $i => $block) : 250 $label = 'Ad Block ' . ($i + 1);253 $label = $block['name']; 251 254 $selected = ''; 252 255 if (intval($settings['placements']['before-last-page-paragraph']) === $i) … … 258 261 $selected = ''; 259 262 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 268 elseif ('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 288 elseif ('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) 260 303 $selected = 'selected="selected"'; 261 304 echo '<option style="padding-right: 10px;" value="' . esc_attr($i) . '" ' . $selected . '>' . $label . '</option>'; … … 268 311 <?php 269 312 foreach ($settings['blocks'] as $i => $block) : 270 $label = 'Ad Block ' . ($i + 1);313 $label = $block['name']; 271 314 $selected = ''; 272 315 if (intval($settings['placements']['after-first-post-paragraph']) === $i) … … 288 331 <?php 289 332 foreach ($settings['blocks'] as $i => $block) : 290 $label = 'Ad Block ' . ($i + 1);333 $label = $block['name']; 291 334 $selected = ''; 292 335 if (intval($settings['placements']['after-first-page-paragraph']) === $i) … … 308 351 <?php 309 352 foreach ($settings['blocks'] as $i => $block) : 310 $label = 'Ad Block ' . ($i + 1);353 $label = $block['name']; 311 354 $selected = ''; 312 355 if (intval($settings['placements']['between-posts']) === $i) … … 328 371 <?php 329 372 foreach ($settings['blocks'] as $i => $block) : 330 $label = 'Ad Block ' . ($i + 1);373 $label = $block['name']; 331 374 $selected = ''; 332 375 if (intval($settings['placements']['above-everything']) === $i) -
wp-advertize-it/trunk/views/wpai-settings/page-settings-section-headers.php
r1045033 r1069497 29 29 } 30 30 }); 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>'); 32 44 jQuery('.delete-checkbox').each(function () { 33 45 jQuery(this).closest('tr').children('th').first().prepend(jQuery(this));
Note: See TracChangeset
for help on using the changeset viewer.