-
Notifications
You must be signed in to change notification settings - Fork 3
/
sam-pro-zone.php
79 lines (69 loc) · 2.11 KB
/
sam-pro-zone.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/**
* Created by PhpStorm.
* Author: minimus
* Date: 29.06.2015
* Time: 10:06
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'SamProZone' ) ) {
class SamProZone {
private $zid;
private $crawler;
private $args;
private $clauses;
private $settings;
private $ajax;
private $force;
private $tags;
public $ad;
public $img = null;
public $link = null;
public $width = 0;
public $height = 0;
public function __construct( $id, $args, $useTags, $crawler = false, $clauses = null, $ajax = false, $force = false ) {
global $SAM_PRO_Query;
$this->zid = $id;
$this->crawler = $crawler;
$this->args = $args;
$this->tags = $useTags;
$this->clauses = ( is_null( $clauses ) ) ? $SAM_PRO_Query : $clauses;
$this->ajax = $ajax;
$this->force = $force;
$this->ad = self::buildZone();
}
private function buildZone() {
global $wpdb;
$zTable = $wpdb->prefix . 'sampro_zones';
$zrTable = $wpdb->prefix . 'sampro_zones_rules';
$single = $this->clauses['single'];
$where = ( ( $single ) ? ' AND szr.single = 1 ' : ' AND szr.single = 0 ' ) . $this->clauses['zone'];
$pid = ( $single ) ? 'sz.single_id' : 'sz.arc_id';
/*$sql = "(SELECT szr.pid FROM {$zrTable} szr WHERE szr.zid = %d {$where} ORDER BY szr.priority)
UNION
(SELECT {$pid} FROM {$zTable} sz WHERE sz.zid = %d)
LIMIT 1;";*/
$sql = "SELECT uzr.pid FROM
((SELECT szr.pid, szr.priority FROM {$zrTable} szr
WHERE szr.zid = %d {$where})
UNION
(SELECT {$pid} AS pid, 10000 AS priority FROM {$zTable} sz WHERE sz.zid = %d)
ORDER BY priority) uzr LIMIT 1;";
$result = $wpdb->get_var( $wpdb->prepare( $sql, $this->zid, $this->zid ) );
if ( ! is_null( $result ) ) {
include_once( apply_filters( 'sam_pro_place_module', 'sam-pro-place.php' ) );
$ad = new SamProPlace( (int) $result, $this->args, $this->tags, $this->crawler, $this->clauses, $this->ajax, $this->force );
$out = $ad->ad;
$this->link = $ad->link;
$this->img = $ad->img;
$this->width = $ad->width;
$this->height = $ad->height;
} else {
$out = '';
}
return $out;
}
}
}