ad-ajax.php
11 years ago
ad-model.php
11 years ago
ad-select.php
11 years ago
ad.php
11 years ago
ad_ajax_callbacks.php
11 years ago
ad_group.php
11 years ago
ad_placements.php
11 years ago
ad_type_abstract.php
11 years ago
ad_type_content.php
11 years ago
ad_type_plain.php
11 years ago
plugin.php
11 years ago
widget.php
11 years ago
ad-model.php
108 lines
| 1 | <?php |
| 2 | |
| 3 | class Advanced_Ads_Model { |
| 4 | |
| 5 | /** |
| 6 | * |
| 7 | * @var wpdb |
| 8 | */ |
| 9 | protected $db; |
| 10 | |
| 11 | /** |
| 12 | * |
| 13 | * @var array |
| 14 | */ |
| 15 | protected $ad_conditions; |
| 16 | |
| 17 | /** |
| 18 | * |
| 19 | * @var array |
| 20 | */ |
| 21 | protected $ad_placements; |
| 22 | |
| 23 | public function __construct(wpdb $wpdb) |
| 24 | { |
| 25 | $this->db = $wpdb; |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * |
| 30 | * @return array |
| 31 | */ |
| 32 | public function get_ad_conditions() |
| 33 | { |
| 34 | if ( ! isset(self::$ad_conditions) ) { |
| 35 | $this->ad_conditions = include ADVADS_BASE_PATH . 'includes/array_ad_conditions.php'; |
| 36 | } |
| 37 | |
| 38 | return $this->ad_conditions; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Get all blog ids of blogs in the current network that are: |
| 43 | * - not archived |
| 44 | * - not spam |
| 45 | * - not deleted |
| 46 | * |
| 47 | * @since 1.0.0 |
| 48 | * @return array|false The blog ids, false if no matches. |
| 49 | */ |
| 50 | public function get_blog_ids() { |
| 51 | // get an array of blog ids |
| 52 | $sql = "SELECT blog_id FROM $this->db->blogs WHERE archived = '0' AND spam = '0' AND deleted = '0'"; |
| 53 | |
| 54 | return $this->db->get_col( $sql ); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * load all ads based on WP_Query conditions |
| 59 | * |
| 60 | * @since 1.1.0 |
| 61 | * @param arr $args WP_Query arguments that are more specific that default |
| 62 | * @return arr $ads array with post objects |
| 63 | */ |
| 64 | public function get_ads($args = array()){ |
| 65 | // add default WP_Query arguments |
| 66 | $args['post_type'] = Advanced_Ads::POST_TYPE_SLUG; |
| 67 | $args['posts_per_page'] = -1; |
| 68 | if ( empty($args['post_status']) ) { $args['post_status'] = 'publish'; } |
| 69 | $ads = new WP_Query( $args ); |
| 70 | |
| 71 | return $ads->posts; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * load all ad groups |
| 76 | * |
| 77 | * @since 1.1.0 |
| 78 | * @param arr $args array with options |
| 79 | * @return arr $groups array with ad groups |
| 80 | * @link http://codex.wordpress.org/Function_Reference/get_terms |
| 81 | */ |
| 82 | public function get_ad_groups($args = array()){ |
| 83 | $args['hide_empty'] = isset($args['hide_empty']) ? $args['hide_empty'] : false; // display groups without any ads |
| 84 | |
| 85 | return get_terms( Advanced_Ads::AD_GROUP_TAXONOMY, $args ); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * get the array with ad placements |
| 90 | * |
| 91 | * @since 1.1.0 |
| 92 | * @return arr $ad_placements |
| 93 | */ |
| 94 | public function get_ad_placements_array(){ |
| 95 | |
| 96 | if ( ! isset( $this->ad_placements ) ) { |
| 97 | $this->ad_placements = get_option( 'advads-ads-placements', array() ); |
| 98 | |
| 99 | // load default array if not saved yet |
| 100 | if ( ! is_array( $this->ad_placements ) ){ |
| 101 | $this->ad_placements = array(); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | return $this->ad_placements; |
| 106 | } |
| 107 | } |
| 108 |