EDD_SL_Plugin_Updater.php
7 years ago
ad-ajax.php
8 years ago
ad-debug.php
8 years ago
ad-model.php
8 years ago
ad-select.php
9 years ago
ad.php
7 years ago
ad_ajax_callbacks.php
7 years ago
ad_group.php
7 years ago
ad_placements.php
7 years ago
ad_type_abstract.php
8 years ago
ad_type_content.php
8 years ago
ad_type_dummy.php
8 years ago
ad_type_group.php
8 years ago
ad_type_image.php
7 years ago
ad_type_plain.php
7 years ago
checks.php
7 years ago
compatibility.php
7 years ago
display-conditions.php
7 years ago
filesystem.php
8 years ago
frontend_checks.php
7 years ago
plugin.php
7 years ago
upgrades.php
9 years ago
utils.php
7 years ago
visitor-conditions.php
7 years ago
widget.php
7 years ago
ad_type_plain.php
136 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Advanced Ads Plain Ad Type |
| 4 | * |
| 5 | * @package Advanced_Ads |
| 6 | * @author Thomas Maier <thomas.maier@webgilde.com> |
| 7 | * @license GPL-2.0+ |
| 8 | * @link http://webgilde.com |
| 9 | * @copyright 2014 Thomas Maier, webgilde GmbH |
| 10 | * |
| 11 | * Class containing information about the plain text/code ad type |
| 12 | * |
| 13 | * see ad-type-content.php for a better sample on ad type |
| 14 | * |
| 15 | */ |
| 16 | class Advanced_Ads_Ad_Type_Plain extends Advanced_Ads_Ad_Type_Abstract{ |
| 17 | |
| 18 | /** |
| 19 | * ID - internal type of the ad type |
| 20 | * * |
| 21 | * @since 1.0.0 |
| 22 | */ |
| 23 | public $ID = 'plain'; |
| 24 | |
| 25 | /** |
| 26 | * set basic attributes |
| 27 | * |
| 28 | * @since 1.0.0 |
| 29 | */ |
| 30 | public function __construct() { |
| 31 | $this->title = __( 'Plain Text and Code', 'advanced-ads' ); |
| 32 | $this->description = __( 'Any ad network, Amazon, customized AdSense codes, shortcodes, and code like JavaScript, HTML or PHP.', 'advanced-ads' ); |
| 33 | $this->parameters = array( |
| 34 | 'content' => '' |
| 35 | ); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * output for the ad parameters metabox |
| 40 | * |
| 41 | * this will be loaded using ajax when changing the ad type radio buttons |
| 42 | * echo the output right away here |
| 43 | * name parameters must be in the "advanced_ads" array |
| 44 | * |
| 45 | * @param obj $ad ad object |
| 46 | * @since 1.0.0 |
| 47 | */ |
| 48 | public function render_parameters($ad){ |
| 49 | // load content |
| 50 | $content = (isset($ad->content)) ? $ad->content : ''; |
| 51 | |
| 52 | ?><p class="description"><?php _e( 'Insert plain text or code into this field.', 'advanced-ads' ); ?></p> |
| 53 | <textarea id="advads-ad-content-plain" cols="40" rows="10" name="advanced_ad[content]" onkeyup="Advanced_Ads_Admin.check_ad_source();"><?php echo esc_textarea( $content ); ?></textarea> |
| 54 | <?php include ADVADS_BASE_PATH . 'admin/views/ad-info-after-textarea.php'; ?> |
| 55 | <input type="hidden" name="advanced_ad[output][allow_php]" value="0"/> |
| 56 | <?php $this->render_php_allow($ad); |
| 57 | $this->render_shortcodes_allow( $ad ); |
| 58 | ?><script>jQuery( function() { Advanced_Ads_Admin.check_ad_source(); } );</script><?php |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * render php output field |
| 63 | * |
| 64 | * @param $ad Advanced_Ads_Ad object |
| 65 | */ |
| 66 | public function render_php_allow( $ad ){ |
| 67 | |
| 68 | if( defined( 'ADVANCED_ADS_DISALLOW_PHP' ) ){ |
| 69 | return; |
| 70 | } |
| 71 | |
| 72 | $content = (isset($ad->content)) ? $ad->content : ''; |
| 73 | |
| 74 | // check if php is allowed |
| 75 | if ( isset($ad->output['allow_php']) ){ |
| 76 | $allow_php = absint( $ad->output['allow_php'] ); |
| 77 | } else { |
| 78 | /** |
| 79 | * for compatibility for ads with php added prior to 1.3.18 |
| 80 | * check if there is php code in the content |
| 81 | */ |
| 82 | if ( preg_match( '/\<\?php/', $content ) ){ |
| 83 | $allow_php = 1; |
| 84 | } else { |
| 85 | $allow_php = 0; |
| 86 | } |
| 87 | } |
| 88 | ?> |
| 89 | <label class="label" for="advads-parameters-php"><?php _e( 'Allow PHP', 'advanced-ads' ); ?></label> |
| 90 | <div> |
| 91 | <input id="advads-parameters-php" type="checkbox" name="advanced_ad[output][allow_php]" value="1" <?php checked( 1, $allow_php ); ?> onChange="Advanced_Ads_Admin.check_ad_source();"/><?php _e( 'Execute PHP code (wrapped in <code><?php ?></code>)', 'advanced-ads' ); |
| 92 | ?><div class="advads-error-message" id="advads-parameters-php-warning" style="display:none;"><?php _e( 'No PHP tag detected in your code.', 'advanced-ads' );?> <?php _e( 'Uncheck this checkbox for improved performance.', 'advanced-ads' );?></div></div><hr/><?php |
| 93 | |
| 94 | } |
| 95 | /** |
| 96 | * Render allow shortcodes field. |
| 97 | * |
| 98 | * @param $ad Advanced_Ads_Ad object |
| 99 | */ |
| 100 | public function render_shortcodes_allow( $ad ){ |
| 101 | $allow_shortcodes = ! empty( $ad->output['allow_shortcodes'] ); |
| 102 | ?> |
| 103 | <label class="label" for="advads-parameters-shortcodes"><?php _e( 'Allow shortcodes', 'advanced-ads' ); ?></label> |
| 104 | <div> |
| 105 | <input id="advads-parameters-shortcodes" type="checkbox" name="advanced_ad[output][allow_shortcodes]" value="1" <?php |
| 106 | checked( 1, $allow_shortcodes ); ?> onChange="Advanced_Ads_Admin.check_ad_source();"/><?php _e( 'Execute shortcodes', 'advanced-ads' ); |
| 107 | ?><div class="advads-error-message" id="advads-parameters-shortcodes-warning" style="display:none;"><?php _e( 'No shortcode detected in your code.', 'advanced-ads' );?> <?php _e( 'Uncheck this checkbox for improved performance.', 'advanced-ads' );?></div></div><hr/><?php |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * prepare the ads frontend output |
| 112 | * |
| 113 | * @param obj $ad ad object |
| 114 | * @return str $content ad content prepared for frontend output |
| 115 | * @since 1.0.0 |
| 116 | */ |
| 117 | public function prepare_output($ad){ |
| 118 | |
| 119 | // evaluate the code as php if setting was never saved or is allowed |
| 120 | if ( ! defined( 'ADVANCED_ADS_DISALLOW_PHP' ) && ( ! isset($ad->output['allow_php']) || $ad->output['allow_php'] ) ){ |
| 121 | ob_start(); |
| 122 | eval('?>'.$ad->content); |
| 123 | $content = ob_get_clean(); |
| 124 | } else { |
| 125 | $content = $ad->content; |
| 126 | } |
| 127 | |
| 128 | if ( ! empty( $ad->output['allow_shortcodes'] ) ) { |
| 129 | $content = $this->do_shortcode( $content, $ad ); |
| 130 | } |
| 131 | |
| 132 | return $content; |
| 133 | } |
| 134 | |
| 135 | } |
| 136 |