Changeset 1556450
- Timestamp:
- 12/16/2016 10:56:18 PM (8 years ago)
- Location:
- speed-bumps
- Files:
-
- 16 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
speed-bumps/tags/0.2.0/Gruntfile.js
r1204895 r1556450 45 45 phpcs: { 46 46 application: { 47 src: ['inc/**/*.php', 'tests/**/*.php']47 src: 48 48 }, 49 49 options: { 50 bin: 'vendor/bin/phpcs',51 standard: 'WordPress-VIP'50 bin: , 51 standard: 52 52 } 53 53 } -
speed-bumps/tags/0.2.0/README.md
r1204895 r1556450 1 1 # Speed Bumps # 2 **Contributors:** fusioneng , goldenapples, noppanit2 **Contributors:** fusioneng, goldenapples, noppanit 3 3 **Tags:** content, advertising, recirculation 4 **Requires at least:** 3.0.15 **Stable tag:** 0. 1.06 **Tested up to:** 4. 34 **Requires at least:** 5 **Stable tag:** 0..0 6 **Tested up to:** 4. 7 7 **License:** GPLv2 or later 8 8 **License URI:** http://www.gnu.org/licenses/gpl-2.0.html … … 114 114 ## Changelog ## 115 115 116 ### 0.1.0 (July 22, 2015) ### 116 ### 0.2.0 (December 15, 2016) ### 117 118 * Compatability: Remove direct $wp_filter access for WP 4.7 compatability. 119 * Compatability: Fix issues throwing warnings in PHP7. 120 * Feature: Add "last ditch fallback" option for speed bump registration. 121 * Feature: Add filter around speed bump insertion content. 122 * Performance: Unregister speed bumps when global constraints prevent them being inserted. 123 * Performance: Unregister speed bumps after inserting them the maximum number of times. 124 * Performance: Allow speed bump constraint filters to short-circuit other filters at an insertion point, or to skip all remaining insertion points in a document. 125 126 ### 0.1.0 (July 23, 2015) ### 117 127 118 128 * Initial release. 119 * [Full release notes](http://fus .in/1MidK1N)129 * [Full release notes](http://fus) -
speed-bumps/tags/0.2.0/inc/constraints/content/class-injection.php
r1204895 r1556450 4 4 use Speed_Bumps\Utils\Comparison; 5 5 use Speed_Bumps\Utils\Text; 6 6 7 7 8 /** … … 37 38 38 39 if ( count( $this_speed_bump_insertions ) >= $args['maximum_inserts'] ) { 39 $can_insert = false;40 $can_insert = ; 40 41 } 41 42 -
speed-bumps/tags/0.2.0/inc/constraints/elements/class-shortcode.php
r1204895 r1556450 2 2 namespace Speed_Bumps\Constraints\Elements; 3 3 4 class Shortcode extends Constraint_Abstract {4 class Shortcode extends Constraint_Abstract{ 5 5 public function paragraph_not_contains_element( $paragraph ) { 6 6 if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $paragraph, $matches, PREG_SET_ORDER ) ) { -
speed-bumps/tags/0.2.0/inc/constraints/text/class-minimum-text.php
r1204895 r1556450 2 2 namespace Speed_Bumps\Constraints\Text; 3 3 4 4 5 use Speed_Bumps\Utils\Text; 5 use Speed_Bumps \Utils\Comparison;6 use Speed_Bumps; 6 7 7 8 /** … … 40 41 if ( isset( $args['minimum_content_length'][ $unit ] ) && 41 42 Comparison::content_less_than( $unit, $args['minimum_content_length'][ $unit ], $content ) ) { 42 $can_insert = false;43 $can_insert = ; 43 44 } 44 45 } … … 47 48 if ( intval( $args['minimum_content_length'] ) ) { 48 49 if ( Comparison::content_less_than( 'characters', intval( $args['minimum_content_length'] ), $content ) ) { 49 $can_insert = false;50 $can_insert = ; 50 51 } 51 52 } 53 54 55 56 57 52 58 53 59 return $can_insert; -
speed-bumps/tags/0.2.0/languages/speed-bumps.pot
r1204895 r1556450 1 # Copyright (C) 201 5Fusion Engineering1 # Copyright (C) 201 Fusion Engineering 2 2 # This file is distributed under the same license as the Speed-bumps package. 3 3 msgid "" 4 4 msgstr "" 5 "Project-Id-Version: Speed-bumps 0. 1.0\n"6 "Report-Msgid-Bugs-To: http ://wordpress.org/support/plugin/speed-bumps\n"7 "POT-Creation-Date: 201 5-07-22 18:59:50+00:00\n"5 "Project-Id-Version: Speed-bumps 0..0\n" 6 "Report-Msgid-Bugs-To: http://wordpress.org/support/plugin/speed-bumps\n" 7 "POT-Creation-Date: 201+00:00\n" 8 8 "MIME-Version: 1.0\n" 9 9 "Content-Type: text/plain; charset=utf-8\n" 10 10 "Content-Transfer-Encoding: 8bit\n" 11 "PO-Revision-Date: 201 5-MO-DA HO:MI+ZONE\n"11 "PO-Revision-Date: 201-MO-DA HO:MI+ZONE\n" 12 12 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" 13 13 "Language-Team: LANGUAGE <LL@li.org>\n" 14 "X-Generator: grunt-wp-i18n 0.5. 2\n"14 "X-Generator: grunt-wp-i18n 0.5.\n" 15 15 "X-Poedit-KeywordsList: " 16 16 "__;_e;_x:1,2c;_ex:1,2c;_n:1,2;_nx:1,2,4c;_n_noop:1,2;_nx_noop:1,2,3c;esc_" -
speed-bumps/tags/0.2.0/readme.txt
r1204895 r1556450 3 3 Tags: content, advertising, recirculation 4 4 Requires at least: 4.2 5 Stable tag: 0. 1.06 Tested up to: 4. 35 Stable tag: 0..0 6 Tested up to: 4. 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 114 114 == Changelog == 115 115 116 117 118 119 120 121 122 123 124 125 116 126 = 0.1.0 (July 23, 2015) = 117 127 -
speed-bumps/tags/0.2.0/speed-bumps.php
r1204895 r1556450 2 2 /* 3 3 Plugin Name: Speed-bumps 4 Version: 0. 1.04 Version: 0..0 5 5 Description: A Plugin to insert a piece of content intelligently. 6 6 Author: Fusion Engineering … … 66 66 * - and the file containing the class itself will be named `class-{classname}.php` 67 67 */ 68 function spl_autoload( $class) {68 function spl_autoload() { 69 69 70 70 // project-specific namespace … … 88 88 if ( file_exists( $file ) ) { 89 89 //Require the file 90 require( $file);90 require(); 91 91 } 92 92 } … … 109 109 */ 110 110 public function insert_speed_bumps( $the_content ) { 111 112 111 113 $output = array(); 112 114 $already_inserted = array(); … … 126 128 foreach ( $this->get_speed_bumps() as $id => $args ) { 127 129 128 if ( apply_filters( 'speed_bumps_'. $id . '_constraints', true, $context, $args, $already_inserted ) ) { 130 $speed_bump_filter = sprintf( self::$filter_id, $id ); 131 132 /** 133 * Filter whether a speed bump can be inserted at a given location 134 * 135 * This filter is dynamically named "speed_bump_{id}_constraints", and is the main logic of 136 * this plugin. Returning false from this filter means that the speed bump will not be 137 * inserted. 138 * 139 * @param bool $can_insert Whether the speed bump can be inserted here 140 * @param array $args Speed bump rules 141 * @param array $context Current insertion point context 142 * @param array $already_inserted Other speed bumps which have been inserted 143 */ 144 if ( apply_filters( $speed_bump_filter, true, $context, $args, $already_inserted ) ) { 129 145 130 146 $content_to_be_inserted = call_user_func( $args['string_to_inject'], $context, $already_inserted ); 131 147 132 $output[] = $content_to_be_inserted; 148 /** 149 * Filter the output of a speed bump. 150 * 151 * @param string $content_to_be_inserted Output of speed bump 152 * @param array $args Speed bump rules 153 * @param array $context Current insertion point context 154 * @param array $already_inserted Other speed bumps which have been inserted 155 */ 156 $output[] = apply_filters( 'speed_bumps_content_inserted', $content_to_be_inserted, $args, $context, $already_inserted ); 157 158 $already_inserted[] = array( 159 'index' => $index, 160 'speed_bump_id' => $id, 161 'inserted_content' => $content_to_be_inserted, 162 ); 163 } 164 165 /** 166 * Fires after all constraints on a speed bump are completed for an insertion point 167 * 168 * @param string $speed_bump_filter The speed bump's filter name 169 * @param array $context Current insertion point context 170 */ 171 do_action( 'speed_bumps_constraints_completed', $speed_bump_filter ); 172 173 } // @codingStandardsIgnoreLine End foreach() loop through filters at insertion point 174 175 } // @codingStandardsIgnoreLine End foreach() loop through paragraphs. 176 177 // Apply "last ditch" insertion rules for any speed bumps that implement them 178 $context['last_ditch'] = true; 179 180 foreach ( $this->get_speed_bumps() as $id => $args ) { 181 182 if ( ! empty( $args['last_ditch_fallback'] ) ) { 183 184 if ( is_callable( $args['last_ditch_fallback'] ) ) { 185 $can_insert = call_user_func( $args['last_ditch_fallback'], $context, $already_inserted ); 186 } else { 187 $inserted = array_filter( $already_inserted, function( $insert ) use ( $id ) { return $insert['speed_bump_id'] === $id; } ); 188 $can_insert = ( count( $inserted ) < $args['minimum_inserts'] ); 189 } 190 191 if ( $can_insert ) { 192 $content_to_be_inserted = call_user_func( $args['string_to_inject'], $context, $already_inserted ); 193 194 $output[] = apply_filters( 'speed_bumps_content_inserted', $content_to_be_inserted, $args, $context, $already_inserted ); 195 133 196 $already_inserted[] = array( 134 197 'index' => $index, … … 140 203 } 141 204 205 142 206 return implode( PHP_EOL . PHP_EOL, $output ); 143 207 } … … 163 227 // Maximum number of times this can be inserted in a post 164 228 'maximum_inserts' => 1, 229 230 231 232 233 234 235 165 236 166 237 // Rules which govern the content as a whole … … 232 303 } 233 304 305 306 307 308 309 310 311 312 313 314 315 234 316 public function get_speed_bump( $id ) { 235 317 return self::$speed_bumps[ $id ]; … … 245 327 foreach ( $this->get_speed_bumps() as $id => $args ) { 246 328 $this->clear_speed_bump( $id ); 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 247 452 } 248 453 } -
speed-bumps/trunk/Gruntfile.js
r1204895 r1556450 45 45 phpcs: { 46 46 application: { 47 src: ['inc/**/*.php', 'tests/**/*.php']47 src: 48 48 }, 49 49 options: { 50 bin: 'vendor/bin/phpcs',51 standard: 'WordPress-VIP'50 bin: , 51 standard: 52 52 } 53 53 } -
speed-bumps/trunk/README.md
r1204895 r1556450 1 1 # Speed Bumps # 2 **Contributors:** fusioneng , goldenapples, noppanit2 **Contributors:** fusioneng, goldenapples, noppanit 3 3 **Tags:** content, advertising, recirculation 4 **Requires at least:** 3.0.15 **Stable tag:** 0. 1.06 **Tested up to:** 4. 34 **Requires at least:** 5 **Stable tag:** 0..0 6 **Tested up to:** 4. 7 7 **License:** GPLv2 or later 8 8 **License URI:** http://www.gnu.org/licenses/gpl-2.0.html … … 114 114 ## Changelog ## 115 115 116 ### 0.1.0 (July 22, 2015) ### 116 ### 0.2.0 (December 15, 2016) ### 117 118 * Compatability: Remove direct $wp_filter access for WP 4.7 compatability. 119 * Compatability: Fix issues throwing warnings in PHP7. 120 * Feature: Add "last ditch fallback" option for speed bump registration. 121 * Feature: Add filter around speed bump insertion content. 122 * Performance: Unregister speed bumps when global constraints prevent them being inserted. 123 * Performance: Unregister speed bumps after inserting them the maximum number of times. 124 * Performance: Allow speed bump constraint filters to short-circuit other filters at an insertion point, or to skip all remaining insertion points in a document. 125 126 ### 0.1.0 (July 23, 2015) ### 117 127 118 128 * Initial release. 119 * [Full release notes](http://fus .in/1MidK1N)129 * [Full release notes](http://fus) -
speed-bumps/trunk/inc/constraints/content/class-injection.php
r1204895 r1556450 4 4 use Speed_Bumps\Utils\Comparison; 5 5 use Speed_Bumps\Utils\Text; 6 6 7 7 8 /** … … 37 38 38 39 if ( count( $this_speed_bump_insertions ) >= $args['maximum_inserts'] ) { 39 $can_insert = false;40 $can_insert = ; 40 41 } 41 42 -
speed-bumps/trunk/inc/constraints/elements/class-shortcode.php
r1204895 r1556450 2 2 namespace Speed_Bumps\Constraints\Elements; 3 3 4 class Shortcode extends Constraint_Abstract {4 class Shortcode extends Constraint_Abstract{ 5 5 public function paragraph_not_contains_element( $paragraph ) { 6 6 if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $paragraph, $matches, PREG_SET_ORDER ) ) { -
speed-bumps/trunk/inc/constraints/text/class-minimum-text.php
r1204895 r1556450 2 2 namespace Speed_Bumps\Constraints\Text; 3 3 4 4 5 use Speed_Bumps\Utils\Text; 5 use Speed_Bumps \Utils\Comparison;6 use Speed_Bumps; 6 7 7 8 /** … … 40 41 if ( isset( $args['minimum_content_length'][ $unit ] ) && 41 42 Comparison::content_less_than( $unit, $args['minimum_content_length'][ $unit ], $content ) ) { 42 $can_insert = false;43 $can_insert = ; 43 44 } 44 45 } … … 47 48 if ( intval( $args['minimum_content_length'] ) ) { 48 49 if ( Comparison::content_less_than( 'characters', intval( $args['minimum_content_length'] ), $content ) ) { 49 $can_insert = false;50 $can_insert = ; 50 51 } 51 52 } 53 54 55 56 57 52 58 53 59 return $can_insert; -
speed-bumps/trunk/languages/speed-bumps.pot
r1204895 r1556450 1 # Copyright (C) 201 5Fusion Engineering1 # Copyright (C) 201 Fusion Engineering 2 2 # This file is distributed under the same license as the Speed-bumps package. 3 3 msgid "" 4 4 msgstr "" 5 "Project-Id-Version: Speed-bumps 0. 1.0\n"6 "Report-Msgid-Bugs-To: http ://wordpress.org/support/plugin/speed-bumps\n"7 "POT-Creation-Date: 201 5-07-22 18:59:50+00:00\n"5 "Project-Id-Version: Speed-bumps 0..0\n" 6 "Report-Msgid-Bugs-To: http://wordpress.org/support/plugin/speed-bumps\n" 7 "POT-Creation-Date: 201+00:00\n" 8 8 "MIME-Version: 1.0\n" 9 9 "Content-Type: text/plain; charset=utf-8\n" 10 10 "Content-Transfer-Encoding: 8bit\n" 11 "PO-Revision-Date: 201 5-MO-DA HO:MI+ZONE\n"11 "PO-Revision-Date: 201-MO-DA HO:MI+ZONE\n" 12 12 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" 13 13 "Language-Team: LANGUAGE <LL@li.org>\n" 14 "X-Generator: grunt-wp-i18n 0.5. 2\n"14 "X-Generator: grunt-wp-i18n 0.5.\n" 15 15 "X-Poedit-KeywordsList: " 16 16 "__;_e;_x:1,2c;_ex:1,2c;_n:1,2;_nx:1,2,4c;_n_noop:1,2;_nx_noop:1,2,3c;esc_" -
speed-bumps/trunk/readme.txt
r1204895 r1556450 3 3 Tags: content, advertising, recirculation 4 4 Requires at least: 4.2 5 Stable tag: 0. 1.06 Tested up to: 4. 35 Stable tag: 0..0 6 Tested up to: 4. 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 114 114 == Changelog == 115 115 116 117 118 119 120 121 122 123 124 125 116 126 = 0.1.0 (July 23, 2015) = 117 127 -
speed-bumps/trunk/speed-bumps.php
r1204895 r1556450 2 2 /* 3 3 Plugin Name: Speed-bumps 4 Version: 0. 1.04 Version: 0..0 5 5 Description: A Plugin to insert a piece of content intelligently. 6 6 Author: Fusion Engineering … … 66 66 * - and the file containing the class itself will be named `class-{classname}.php` 67 67 */ 68 function spl_autoload( $class) {68 function spl_autoload() { 69 69 70 70 // project-specific namespace … … 88 88 if ( file_exists( $file ) ) { 89 89 //Require the file 90 require( $file);90 require(); 91 91 } 92 92 } … … 109 109 */ 110 110 public function insert_speed_bumps( $the_content ) { 111 112 111 113 $output = array(); 112 114 $already_inserted = array(); … … 126 128 foreach ( $this->get_speed_bumps() as $id => $args ) { 127 129 128 if ( apply_filters( 'speed_bumps_'. $id . '_constraints', true, $context, $args, $already_inserted ) ) { 130 $speed_bump_filter = sprintf( self::$filter_id, $id ); 131 132 /** 133 * Filter whether a speed bump can be inserted at a given location 134 * 135 * This filter is dynamically named "speed_bump_{id}_constraints", and is the main logic of 136 * this plugin. Returning false from this filter means that the speed bump will not be 137 * inserted. 138 * 139 * @param bool $can_insert Whether the speed bump can be inserted here 140 * @param array $args Speed bump rules 141 * @param array $context Current insertion point context 142 * @param array $already_inserted Other speed bumps which have been inserted 143 */ 144 if ( apply_filters( $speed_bump_filter, true, $context, $args, $already_inserted ) ) { 129 145 130 146 $content_to_be_inserted = call_user_func( $args['string_to_inject'], $context, $already_inserted ); 131 147 132 $output[] = $content_to_be_inserted; 148 /** 149 * Filter the output of a speed bump. 150 * 151 * @param string $content_to_be_inserted Output of speed bump 152 * @param array $args Speed bump rules 153 * @param array $context Current insertion point context 154 * @param array $already_inserted Other speed bumps which have been inserted 155 */ 156 $output[] = apply_filters( 'speed_bumps_content_inserted', $content_to_be_inserted, $args, $context, $already_inserted ); 157 158 $already_inserted[] = array( 159 'index' => $index, 160 'speed_bump_id' => $id, 161 'inserted_content' => $content_to_be_inserted, 162 ); 163 } 164 165 /** 166 * Fires after all constraints on a speed bump are completed for an insertion point 167 * 168 * @param string $speed_bump_filter The speed bump's filter name 169 * @param array $context Current insertion point context 170 */ 171 do_action( 'speed_bumps_constraints_completed', $speed_bump_filter ); 172 173 } // @codingStandardsIgnoreLine End foreach() loop through filters at insertion point 174 175 } // @codingStandardsIgnoreLine End foreach() loop through paragraphs. 176 177 // Apply "last ditch" insertion rules for any speed bumps that implement them 178 $context['last_ditch'] = true; 179 180 foreach ( $this->get_speed_bumps() as $id => $args ) { 181 182 if ( ! empty( $args['last_ditch_fallback'] ) ) { 183 184 if ( is_callable( $args['last_ditch_fallback'] ) ) { 185 $can_insert = call_user_func( $args['last_ditch_fallback'], $context, $already_inserted ); 186 } else { 187 $inserted = array_filter( $already_inserted, function( $insert ) use ( $id ) { return $insert['speed_bump_id'] === $id; } ); 188 $can_insert = ( count( $inserted ) < $args['minimum_inserts'] ); 189 } 190 191 if ( $can_insert ) { 192 $content_to_be_inserted = call_user_func( $args['string_to_inject'], $context, $already_inserted ); 193 194 $output[] = apply_filters( 'speed_bumps_content_inserted', $content_to_be_inserted, $args, $context, $already_inserted ); 195 133 196 $already_inserted[] = array( 134 197 'index' => $index, … … 140 203 } 141 204 205 142 206 return implode( PHP_EOL . PHP_EOL, $output ); 143 207 } … … 163 227 // Maximum number of times this can be inserted in a post 164 228 'maximum_inserts' => 1, 229 230 231 232 233 234 235 165 236 166 237 // Rules which govern the content as a whole … … 232 303 } 233 304 305 306 307 308 309 310 311 312 313 314 315 234 316 public function get_speed_bump( $id ) { 235 317 return self::$speed_bumps[ $id ]; … … 245 327 foreach ( $this->get_speed_bumps() as $id => $args ) { 246 328 $this->clear_speed_bump( $id ); 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 247 452 } 248 453 }
Note: See TracChangeset
for help on using the changeset viewer.