PluginProbe
Lasso Lite – Affiliate Link Manager & Product Displays / 113
Lasso Lite – Affiliate Link Manager & Product Displays v113
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 +22 -67 158113 View file →
@@ -8,13 +8,10 @@
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;
13 12 use LassoLite\Classes\Meta_Enum;
14 13 use LassoLite\Models\Model;
15 -
16 -use Lasso\Models\Revert;
17 14 use WP_Query;
18 15
19 16 /**
20 17 * Model
@@ -39,21 +36,8 @@
39 36 */
40 37 public function get_thumbnail_url() {
41 38 $img_src = get_post_meta( $this->get_id(), Meta_Enum::LASSO_LITE_CUSTOM_THUMBNAIL, true );
42 39
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 -
56 40 return ( ! empty( $img_src ) ) ? $img_src : Constant::DEFAULT_THUMBNAIL;
57 41 }
58 42
59 43 /**
@@ -92,47 +76,8 @@
92 76 return $clicks;
93 77 }
94 78
95 79 /**
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 - /**
135 80 * Get list SURL object
136 81 *
137 82 * @param string $keyword Keyword.
138 83 * @param int $page Page name.
@@ -144,16 +89,20 @@
144 89 $offset = 0;
145 90 } else {
146 91 $offset = ( $page * $limit ) - $limit;
147 92 }
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();
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();
156 105 foreach ( $surls as $surl ) {
157 106 $surl->id = $surl->ID;
158 107 $list[] = new self( $surl );
159 108 }
@@ -166,12 +115,18 @@
166 115 * @param string $keyword Keyword.
167 116 * @return integer
168 117 */
169 118 public static function total( $keyword = '' ) {
170 - $sql = self::get_dashboard_query( $keyword );
171 - $total = Model::get_count( $sql );
172 -
173 - return $total;
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;
174 129 }
175 130
176 131 /**
177 132 * Get urls by group