Ejemplo n.º 1
0
 /**
  * manipulate output of ad widget
  *
  * @since 1.6.8.2
  * @param arr $params widget and sidebar params
  */
 public function manipulate_widget_output($params = array())
 {
     if ($params[0]['widget_name'] === 'Advanced Ads') {
         $options = $this->plugin->options();
         // hide id by default (when options are empty) or when option is enabled
         if ($options === array() || isset($options['remove-widget-id']) && $options['remove-widget-id']) {
             $pattern = '#\\s(id)=("|\')[^"^\']+("|\')#';
             $params[0]['before_widget'] = preg_replace($pattern, '', $params[0]['before_widget']);
         }
     }
     return $params;
 }
Ejemplo n.º 2
0
 /**
  * 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());
     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;
 }