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