Exemplo n.º 1
0
 /**
  * save a new placement
  *
  * @since 1.1.0
  * @param array $new_placement
  * @return mixed true if saved; error message if not
  */
 public static function save_new_placement($new_placement)
 {
     // load placements // -TODO use model
     $placements = Advanced_Ads::get_ad_placements_array();
     // create slug
     $new_placement['slug'] = sanitize_title($new_placement['name']);
     // check if slug already exists or is empty
     if ($new_placement['slug'] === '' || isset($placements[$new_placement['slug']])) {
         return false;
     }
     // make sure only allowed types are being saved
     $placement_types = Advanced_Ads_Placements::get_placement_types();
     $new_placement['type'] = isset($placement_types[$new_placement['type']]) ? $new_placement['type'] : 'default';
     // escape name
     $new_placement['name'] = esc_attr($new_placement['name']);
     // add new place to all placements
     $placements[$new_placement['slug']] = array('type' => $new_placement['type'], 'name' => $new_placement['name']);
     // save array
     update_option('advads-ads-placements', $placements);
     return true;
 }
 /**
  * Render the placements page
  *
  * @since    1.1.0
  */
 public function display_placements_page()
 {
     $placement_types = Advanced_Ads_Placements::get_placement_types();
     $placements = Advanced_Ads::get_ad_placements_array();
     // -TODO use model
     $items = Advanced_Ads_Placements::items_for_select();
     // load ads and groups for select field
     // display view
     include ADVADS_BASE_PATH . 'admin/views/placements.php';
 }
Exemplo n.º 3
0
 public function get_ad_by_placement($args)
 {
     if (isset($args['override'])) {
         return $args['override'];
     }
     if (!isset($args['id']) || $args['id'] == '') {
         return;
     }
     // check conditions
     if (!Advanced_Ads_Placements::can_display($args['id'])) {
         return;
     }
     // get placement content
     $id = $args['id'];
     return Advanced_Ads_Placements::output($id, $args);
 }
 /**
  * injected ad into content (before and after)
  * displays ALL ads
  *
  * @since 1.1.0
  * @param str $content post content
  */
 public function inject_content($content = '')
 {
     // run only within the loop on single pages of public post types
     $public_post_types = get_post_types(array('public' => true, 'publicly_queryable' => true), 'names', 'or');
     // check if admin allows injection in all places
     $options = $this->plugin->options();
     if (!isset($options['content-injection-everywhere'])) {
         // check if this is a singular page within the loop
         if (!is_singular($public_post_types) || !in_the_loop()) {
             return $content;
         }
     }
     $placements = get_option('advads-ads-placements', array());
     if (!apply_filters('advanced-ads-can-inject-into-content', true, $content, $placements)) {
         return $content;
     }
     foreach ($placements as $_placement_id => $_placement) {
         if (empty($_placement['item']) || !isset($_placement['type'])) {
             continue;
         }
         $_options = isset($_placement['options']) ? $_placement['options'] : array();
         switch ($_placement['type']) {
             case 'post_top':
                 // TODO broken: does not serve placement but serves ad directly
                 $content = Advanced_Ads_Select::get_instance()->get_ad_by_method($_placement_id, Advanced_Ads_Select::PLACEMENT, $_options) . $content;
                 break;
             case 'post_bottom':
                 $content .= Advanced_Ads_Select::get_instance()->get_ad_by_method($_placement_id, Advanced_Ads_Select::PLACEMENT, $_options);
                 break;
             case 'post_content':
                 $content = Advanced_Ads_Placements::inject_in_content($_placement_id, $_options, $content);
                 break;
         }
     }
     return $content;
 }
Exemplo n.º 5
0
</option>
                                            <?php 
                }
                ?>
                                        </select>

                                        <input type="number" name="advads[placements][<?php 
                echo $_placement_slug;
                ?>
][options][index]" value="<?php 
                echo isset($_placement['options']['index']) ? $_placement['options']['index'] : 1;
                ?>
"/>.

                                        <?php 
                $tags = Advanced_Ads_Placements::tags_for_content_injection();
                ?>
                                        <select name="advads[placements][<?php 
                echo $_placement_slug;
                ?>
][options][tag]">
                                            <?php 
                foreach ($tags as $_tag_key => $_tag) {
                    ?>
                                            <option value="<?php 
                    echo $_tag_key;
                    ?>
" <?php 
                    if (isset($_placement['options']['tag'])) {
                        selected($_placement['options']['tag'], $_tag_key);
                    }