コード例 #1
0
 /**
  * Add an ad unit to the body of a post
  *
  * @access public
  * @param array $atts
  * @param string $content
  * @param string $tag
  * @return string
  */
 public function do_ad_unit($atts, $content, $tag)
 {
     // Ensure the shortcode is valid
     if (empty($atts['unit'])) {
         return;
     }
     // Attempt to display the specified ad unit.
     // This will just do nothing if the unit is invalid
     // or doesn't exist in the current ad layer.
     return Ad_Layers_Ad_Server::instance()->get_ad_unit($atts['unit']);
 }
コード例 #2
0
 public function setUp()
 {
     parent::setUp();
     $this->ad_server_parent = Ad_Layers_Ad_Server::instance();
     $this->ad_server_settings = array('ad_server' => 'Ad_Layers_DFP', 'account_id' => '6355419', 'path_templates' => array(array('path_template' => '/#account_id#/#ad_unit#/front', 'page_type' => 'default')), 'breakpoints' => array(), 'ad_units' => array(array('code' => 'sidebar', 'sizes' => array(array('width' => 300, 'height' => 250, 'default_size' => 'default'), array('width' => 300, 'height' => 600)))));
     update_option($this->ad_server_parent->option_name, $this->ad_server_settings);
     // Add an ad layer
     $this->ad_layer = $this->factory->post->create(array('post_type' => 'ad-layer'));
     add_post_meta($this->ad_layer, 'ad_layer_ad_units', array(array('ad_unit' => 'sidebar')));
     // add_post_meta( $this->ad_layer, 'ad_layer_page_types', array() );
     Ad_Layers::instance()->setup();
     $this->ad_server_parent->setup();
     $this->ad_server = $this->ad_server_parent->get_ad_server();
 }
コード例 #3
0
 /**
  * Add an ad unit to the body of a post
  *
  * @access public
  * @param array $atts
  * @param string $content
  * @param string $tag
  * @return string
  */
 public function do_ad_unit($atts, $content, $tag)
 {
     // Ensure the shortcode is valid
     if (empty($atts['unit'])) {
         return;
     }
     // Attempt to display the specified ad unit.
     // This will just do nothing if the unit is invalid
     // or doesn't exist in the current ad layer.
     // Since the WP shortcode pattern is running and trying to replace
     // our shortcode, we need to return the ad and what to replace there,
     // so we set the echo value to false for get_ad_unit.
     return Ad_Layers_Ad_Server::instance()->get_ad_unit($atts['unit'], false);
 }
コード例 #4
0
 /**
  * Adds the meta boxes required to manage an ad layer.
  *
  * @param string|array $post_types
  * @param string $context
  * @param string $priority
  */
 public function add_meta_boxes()
 {
     if (!class_exists('Fieldmanager_Field')) {
         return;
     }
     // Add ad units
     $ad_unit_args = array('name' => 'ad_layer_ad_units', 'limit' => 0, 'extra_elements' => 0, 'one_label_per_item' => false, 'sortable' => true, 'label' => __('Select one or more ad units.', 'ad-layers'), 'add_more_label' => __('Add an ad unit', 'ad-layers'), 'children' => array('ad_unit' => new Fieldmanager_Select(array('label' => __('Ad Unit', 'ad-layers'), 'options' => Ad_Layers_Ad_Server::instance()->get_ad_units())), 'do_not_render' => new Fieldmanager_Checkbox(__('Do not render the ad on load', 'ad-layers'))));
     $targeting_args = Ad_Layers_Ad_Server::instance()->get_custom_targeting_args('custom_targeting');
     if (!empty($targeting_args)) {
         $ad_unit_args['children']['custom_targeting'] = new Fieldmanager_Group(apply_filters('ad_layers_custom_targeting_ad_unit_args', $targeting_args));
     }
     $fm_ad_units = new Fieldmanager_Group(apply_filters('ad_layers_ad_units_field_args', $ad_unit_args));
     $fm_ad_units->add_meta_box(__('Ad Units', 'ad-layers'), $this->post_type, 'normal', 'high');
     // Add page types
     $fm_page_types = new Fieldmanager_Select(apply_filters('ad_layers_page_types_field_args', array('name' => 'ad_layer_page_types', 'limit' => 0, 'extra_elements' => 0, 'one_label_per_item' => false, 'label' => __('Select one or more page types to be targeted with this ad layer.', 'ad-layers'), 'add_more_label' => __('Add a page type', 'ad-layers'), 'options' => Ad_Layers::instance()->get_page_types())));
     $fm_page_types->add_meta_box(__('Page Types', 'ad-layers'), $this->post_type, 'normal', 'high');
     // Add taxonomies
     $fm_taxonomies = new Fieldmanager_Select(apply_filters('ad_layers_taxonomies_field_args', array('name' => 'ad_layer_taxonomies', 'limit' => 0, 'extra_elements' => 0, 'one_label_per_item' => false, 'label' => __('Select one or more optional taxonomies for targeting. Posts with any term in these taxonomies will get the ad layer.', 'ad-layers'), 'add_more_label' => __('Add a taxonomy', 'ad-layers'), 'options' => Ad_Layers::instance()->get_taxonomies())));
     $fm_taxonomies->add_meta_box(__('Taxonomies', 'ad-layers'), $this->post_type, 'normal', 'high');
     // Add post types
     $fm_post_types = new Fieldmanager_Select(apply_filters('ad_layers_post_types_field_args', array('name' => 'ad_layer_post_types', 'limit' => 0, 'extra_elements' => 0, 'one_label_per_item' => false, 'label' => __('Select one or more optional post types for targeting. Any post of this type will get the ad layer.', 'ad-layers'), 'add_more_label' => __('Add a post type', 'ad-layers'), 'options' => Ad_Layers::instance()->get_post_types())));
     $fm_post_types->add_meta_box(__('Post Types', 'ad-layers'), $this->post_type, 'normal', 'high');
     // Custom targeting variables
     $targeting_args = Ad_Layers_Ad_Server::instance()->get_custom_targeting_args();
     if (!empty($targeting_args)) {
         $fm_custom = new Fieldmanager_Group(apply_filters('ad_layers_custom_targeting_field_args', $targeting_args));
         $fm_custom->add_meta_box(__('Page Level Custom Targeting', 'ad-layers'), $this->post_type, 'normal', 'low');
     }
 }
コード例 #5
0
         * Gets the args used to define a custom targeting field.
         *
         * @access public
         * @param string $name
         * @return array
         */
        public function get_custom_targeting_args($name = 'ad_layer_custom_targeting')
        {
            if (!class_exists('Fieldmanager_Field')) {
                return array();
            }
            return apply_filters('ad_layers_custom_targeting_args', array('name' => $name, 'collapsible' => true, 'collapsed' => false, 'limit' => 0, 'extra_elements' => 0, 'add_more_label' => __('Add custom targeting', 'ad-layers'), 'label_macro' => array(__('%s', 'ad-layers'), 'title'), 'children' => array('custom_variable' => new Fieldmanager_Select(array('label' => __('Custom Variable', 'ad-layers'), 'options' => Ad_Layers::instance()->get_custom_variables())), 'source' => new Fieldmanager_Select(array('label' => __('Source', 'ad-layers'), 'options' => $this->get_custom_targeting_sources())), 'values' => new Fieldmanager_Textfield(array('add_more_label' => __('Add value', 'ad-layers'), 'one_label_per_item' => false, 'limit' => 0, 'extra_elements' => 0, 'display_if' => array('src' => 'source', 'value' => 'other'))))));
        }
        /**
         * Gets all available custom targeting sources.
         *
         * @access private
         * @return array
         */
        private function get_custom_targeting_sources()
        {
            $options = array();
            // Add all taxonomies available to ad layers
            $options = array_merge($options, Ad_Layers::instance()->get_taxonomies());
            // Add additional options
            $options = array_merge($options, array('post_type' => __('Post Type', 'ad-layers'), 'author' => __('Author', 'ad-layers'), 'other' => __('Other', 'ad-layers')));
            return apply_filters('ad_layers_custom_targeting_sources', $options);
        }
    }
    Ad_Layers_Ad_Server::instance();
}
コード例 #6
0
 /**
  * Creates a select field to select the ad unit.
  *
  * @access protected
  * @param string $selected_value The currently selected value
  * @return string HTML for the field
  */
 protected function ad_unit_select_field_html($selected_value)
 {
     // Get all ad units in the system.
     // If none exist, display a message.
     // This will also prevent the widget from being saved due to the validation rules in update().
     $no_units = '<p>' . esc_html__('No ad units are currently available.', 'ad-layers') . '</p>';
     $ad_units = Ad_Layers_Ad_Server::instance()->get_ad_units();
     // Build the option list.
     $options = '';
     foreach ($ad_units as $ad_unit) {
         $options .= sprintf('<option value="%s" %s>%s</option>', esc_attr($ad_unit), selected($selected_value, $ad_unit, false), esc_html($ad_unit));
     }
     // Return the complete element.
     return sprintf('<select name="%s" id="%s">%s</select>', $this->get_field_name('ad_unit'), $this->get_field_id('ad_unit'), $options);
 }