PluginProbe
Lasso Lite – Affiliate Link Manager & Product Displays / 158
Lasso Lite – Affiliate Link Manager & Product Displays v158
158 157 155 156 154 153 152 151 150 149 148 trunk 0.9.9 104 105 106 107 108 109 110 111 112 113 114 115 All 57 releases
← All changes | classes/class-surl.php +67 -22 114158 View file →
@@ -8,10 +8,13 @@
8 8 namespace LassoLite\Classes;
9 9
10 10 use LassoLite\Admin\Constant;
11 11 use LassoLite\Classes\Amazon_Api;
12 +use LassoLite\Classes\Helper;
12 13 use LassoLite\Classes\Meta_Enum;
13 14 use LassoLite\Models\Model;
15 +
16 +use Lasso\Models\Revert;
14 17 use WP_Query;
15 18
16 19 /**
17 20 * Model
@@ -36,8 +39,21 @@
36 39 */
37 40 public function get_thumbnail_url() {
38 41 $img_src = get_post_meta( $this->get_id(), Meta_Enum::LASSO_LITE_CUSTOM_THUMBNAIL, true );
39 42
43 + $public_url = $this->get_public_url();
44 + $is_amazon_page = Amazon_Api::is_amazon_url( $public_url );
45 + if ( $is_amazon_page && ( Constant::DEFAULT_THUMBNAIL === $img_src || ! $img_src ) ) {
46 + $product_id = Amazon_Api::get_product_id_by_url( $public_url );
47 + if ( $product_id ) {
48 + $lasso_amazon_api = new Amazon_Api();
49 + $product = $lasso_amazon_api->get_amazon_product_from_db( $product_id );
50 + if ( $product ) {
51 + $img_src = $product['default_image'];
52 + }
53 + }
54 + }
55 +
40 56 return ( ! empty( $img_src ) ) ? $img_src : Constant::DEFAULT_THUMBNAIL;
41 57 }
42 58
43 59 /**
@@ -76,8 +92,47 @@
76 92 return $clicks;
77 93 }
78 94
79 95 /**
96 + * Get dashboard SQL query
97 + *
98 + * @param string $keyword Keyword.
99 + */
100 + private static function get_dashboard_query( $keyword ) {
101 + $keyword = '%' . Model::esc_like( $keyword ) . '%';
102 + $where = '';
103 +
104 + if ( Helper::is_lasso_pro_installed() && class_exists( 'Lasso\Models\Revert' ) ) {
105 + $revert = new Revert();
106 + $where = '
107 + AND ID NOT IN (
108 + SELECT r.post_data
109 + FROM ' . $revert->get_table_name() . ' AS r
110 + INNER JOIN ' . Model::get_wp_table_name( 'posts' ) . ' AS p
111 + ON p.ID = r.post_data
112 + WHERE r.plugin = "' . SIMPLE_URLS_SLUG . '"
113 + AND p.post_type = "' . Constant::LASSO_PRO_POST_TYPE . '"
114 + )
115 + ';
116 + }
117 +
118 + $sql = '
119 + SELECT *
120 + FROM
121 + ' . Model::get_wp_table_name( 'posts' ) . '
122 + WHERE
123 + post_type = %s
124 + AND post_status = %s
125 + AND post_title LIKE %s
126 + ' . $where . '
127 + ORDER BY post_modified DESC
128 + ';
129 + $sql = Model::prepare( $sql, SIMPLE_URLS_SLUG, 'publish', $keyword );
130 +
131 + return $sql;
132 + }
133 +
134 + /**
80 135 * Get list SURL object
81 136 *
82 137 * @param string $keyword Keyword.
83 138 * @param int $page Page name.
@@ -89,20 +144,16 @@
89 144 $offset = 0;
90 145 } else {
91 146 $offset = ( $page * $limit ) - $limit;
92 147 }
93 - $surls = get_posts(
94 - array(
95 - 'posts_per_page' => $limit,
96 - 'offset' => $offset,
97 - 'post_type' => SIMPLE_URLS_SLUG,
98 - 'post_status' => 'publish',
99 - 's' => $keyword,
100 - 'orderby' => 'post_modified',
101 - 'order' => 'DESC',
102 - )
103 - );
104 - $list = array();
148 +
149 + $sql = self::get_dashboard_query( $keyword );
150 + $sql = $sql . ' LIMIT %d OFFSET %d';
151 + $sql = Model::prepare( $sql, $limit, $offset );
152 +
153 + $surls = Model::get_results( $sql );
154 +
155 + $list = array();
105 156 foreach ( $surls as $surl ) {
106 157 $surl->id = $surl->ID;
107 158 $list[] = new self( $surl );
108 159 }
@@ -115,18 +166,12 @@
115 166 * @param string $keyword Keyword.
116 167 * @return integer
117 168 */
118 169 public static function total( $keyword = '' ) {
119 - if ( empty( $keyword ) ) {
120 - return (int) wp_count_posts( SIMPLE_URLS_SLUG )->publish;
121 - }
122 - $args = array(
123 - 'post_status' => 'publish',
124 - 'post_type' => SIMPLE_URLS_SLUG,
125 - 's' => $keyword,
126 - );
127 - $the_query = new WP_Query( $args );
128 - return $the_query->post_count;
170 + $sql = self::get_dashboard_query( $keyword );
171 + $total = Model::get_count( $sql );
172 +
173 + return $total;
129 174 }
130 175
131 176 /**
132 177 * Get urls by group