Issues (2407)

application/model/blog/article.php (28 issues)

1
<?php
2
3
/* 	Divine CMS - Open source CMS for widespread use.
4
    Copyright (c) 2019 Mykola Burakov ([email protected])
5
6
    See SOURCE.txt for other and additional information.
7
8
    This file is part of Divine CMS.
9
10
    This program is free software: you can redistribute it and/or modify
11
    it under the terms of the GNU General Public License as published by
12
    the Free Software Foundation, either version 3 of the License, or
13
    (at your option) any later version.
14
15
    This program is distributed in the hope that it will be useful,
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
    GNU General Public License for more details.
19
20
    You should have received a copy of the GNU General Public License
21
    along with this program. If not, see <http://www.gnu.org/licenses/>. */
22
23
class ModelBlogArticle extends \Divine\Engine\Core\Model
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
24
{
25
    public function updateViewed($article_id)
0 ignored issues
show
Expected 2 blank lines before function; 0 found
Loading history...
26
    {
27
        $this->db->query("
28
            UPDATE article SET viewed = (viewed + 1) 
29
            WHERE article_id = '" . (int)$article_id . "'
30
        ");
31
    }
32
33
    public function getArticle($article_id)
34
    {
35
        if ($this->customer->isLogged()) {
36
            $customer_group_id = $this->customer->getGroupId();
0 ignored issues
show
The assignment to $customer_group_id is dead and can be removed.
Loading history...
37
        } else {
38
            $customer_group_id = $this->config->get('config_customer_group_id');
39
        }
40
41
        $query = $this->db->query("
42
            SELECT DISTINCT *, pd.name AS name, p.image, (SELECT COUNT(*) AS total 
43
                FROM review_article r2 
44
                WHERE r2.article_id = p.article_id 
45
                AND r2.status = '1' 
46
                GROUP BY r2.article_id) AS reviews, p.sort_order 
47
            FROM article p 
48
            LEFT JOIN article_description pd ON (p.article_id = pd.article_id) 
49
            WHERE p.article_id = '" . (int)$article_id . "' 
50
                AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' 
51
                AND p.status = '1'
52
        ");
53
54
        if ($query->num_rows) {
55
            return array(
56
                'meta_title'       => $query->row['meta_title'],
57
                'noindex'          => $query->row['noindex'],
58
                'meta_h1'          => $query->row['meta_h1'],
59
                'article_id'       => $query->row['article_id'],
60
                'name'             => $query->row['name'],
61
                'description'      => $query->row['description'],
62
                'meta_description' => $query->row['meta_description'],
63
                'image'            => $query->row['image'],
64
                'reviews'          => $query->row['reviews'],
65
                'sort_order'       => $query->row['sort_order'],
66
                'article_review'   => $query->row['article_review'],
67
                'status'           => $query->row['status'],
68
                'gstatus'           => $query->row['gstatus'],
69
                'date_added'       => $query->row['date_added'],
70
                'date_modified'    => $query->row['date_modified'],
71
                'viewed'           => $query->row['viewed']
72
            );
73
        } else {
74
            return false;
75
        }
76
    }
77
78
    public function getArticles($data = array())
79
    {
80
        if ($this->customer->isLogged()) {
81
            $customer_group_id = $this->customer->getGroupId();
82
        } else {
83
            $customer_group_id = $this->config->get('config_customer_group_id');
84
        }
85
86
        $cache = md5(http_build_query($data));
87
88
        $article_data = $this->cache->get('article.' . (int)$this->config->get('config_language_id') . '.0.' . (int)$customer_group_id . '.' . $cache);
89
90
        if (!$article_data) {
91
            $sql = "
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal \n SELECT...icle_id) \n does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
92
                SELECT p.article_id 
93
                FROM article p 
94
                LEFT JOIN article_description pd ON (p.article_id = pd.article_id) 
95
            ";
96
97
            if (!empty($data['filter_category_id'])) {
98
                $sql .= " 
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal \n L...e_id)\n does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
99
                    LEFT JOIN article_to_blog_category p2c ON (p.article_id = p2c.article_id)
100
                ";
101
            }
102
103
            $sql .= " 
104
                WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' 
105
                    AND p.status = '1'
106
            ";
107
108
            if (!empty($data['filter_name']) || !empty($data['filter_tag'])) {
109
                $sql .= " AND (";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal AND ( does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
110
111
                if (!empty($data['filter_name'])) {
112
                    if (!empty($data['filter_description'])) {
113
                        $sql .= "LCASE(pd.name) LIKE '%" . $this->db->escape(\voku\helper\UTF8::strtolower($data['filter_name'])) . "%' OR MATCH(pd.description) AGAINST('" . $this->db->escape(\voku\helper\UTF8::strtolower($data['filter_name'])) . "')";
114
                    } else {
115
                        $sql .= "LCASE(pd.name) LIKE '%" . $this->db->escape(\voku\helper\UTF8::strtolower($data['filter_name'])) . "%'";
116
                    }
117
                }
118
119
                if (!empty($data['filter_name']) && !empty($data['filter_tag'])) {
120
                    $sql .= " OR ";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal OR does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
121
                }
122
123
                if (!empty($data['filter_tag'])) {
124
                    $sql .= "MATCH(pd.tag) AGAINST('" . $this->db->escape(\voku\helper\UTF8::strtolower($data['filter_tag'])) . "')";
125
                }
126
127
                $sql .= ")";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal ) does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
128
129
                if (!empty($data['filter_name'])) {
130
                    $sql .= " OR LCASE(p.model) = '" . $this->db->escape(\voku\helper\UTF8::strtolower($data['filter_name'])) . "'";
131
                }
132
133
                if (!empty($data['filter_name'])) {
134
                    $sql .= " OR LCASE(p.sku) = '" . $this->db->escape(\voku\helper\UTF8::strtolower($data['filter_name'])) . "'";
135
                }
136
137
                if (!empty($data['filter_name'])) {
138
                    $sql .= " OR LCASE(p.upc) = '" . $this->db->escape(\voku\helper\UTF8::strtolower($data['filter_name'])) . "'";
139
                }
140
141
                if (!empty($data['filter_name'])) {
142
                    $sql .= " OR LCASE(p.ean) = '" . $this->db->escape(\voku\helper\UTF8::strtolower($data['filter_name'])) . "'";
143
                }
144
145
                if (!empty($data['filter_name'])) {
146
                    $sql .= " OR LCASE(p.jan) = '" . $this->db->escape(\voku\helper\UTF8::strtolower($data['filter_name'])) . "'";
147
                }
148
149
                if (!empty($data['filter_name'])) {
150
                    $sql .= " OR LCASE(p.isbn) = '" . $this->db->escape(\voku\helper\UTF8::strtolower($data['filter_name'])) . "'";
151
                }
152
153
                if (!empty($data['filter_name'])) {
154
                    $sql .= " OR LCASE(p.mpn) = '" . $this->db->escape(\voku\helper\UTF8::strtolower($data['filter_name'])) . "'";
155
                }
156
            }
157
158
            if (!empty($data['filter_category_id'])) {
159
                if (!empty($data['filter_sub_category'])) {
160
                    $implode_data = array();
161
162
                    $implode_data[] = (int)$data['filter_category_id'];
163
164
                    $this->load->model('blog/category');
165
166
                    $categories = $this->model_blog_category->getCategoriesByParentId($data['filter_category_id']);
167
168
                    foreach ($categories as $blog_category_id) {
169
                        $implode_data[] = (int)$blog_category_id;
170
                    }
171
172
                    $sql .= " AND p2c.blog_category_id IN (" . implode(', ', $implode_data) . ")";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal AND p2c.blog_category_id IN ( does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal ) does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
173
                } else {
174
                    $sql .= " AND p2c.blog_category_id = '" . (int)$data['filter_category_id'] . "'";
175
                }
176
            }
177
178
            $sql .= " GROUP BY p.article_id";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal GROUP BY p.article_id does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
179
180
            $sort_data = array(
181
                'pd.name',
182
                'p.viewed',
183
                'p.sort_order',
184
                'p.date_added'
185
            );
186
187
            if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
188
                if ($data['sort'] == 'pd.name' || $data['sort'] == 'p.model' || $data['sort'] == 'p.date_added') {
189
                    $sql .= " ORDER BY LCASE(" . $data['sort'] . ")";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal ORDER BY LCASE( does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal ) does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
190
                } else {
191
                    $sql .= " ORDER BY " . $data['sort'];
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal ORDER BY does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
192
                }
193
            } else {
194
                $sql .= " ORDER BY p.sort_order";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal ORDER BY p.sort_order does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
195
            }
196
197
            if (isset($data['order']) && ($data['order'] == 'DESC')) {
198
                $sql .= " DESC, LCASE(pd.name) DESC";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal DESC, LCASE(pd.name) DESC does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
199
            } else {
200
                $sql .= " ASC, LCASE(pd.name) ASC";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal ASC, LCASE(pd.name) ASC does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
201
            }
202
203
            if (isset($data['start']) || isset($data['limit'])) {
204
                if ($data['start'] < 0) {
205
                    $data['start'] = 0;
206
                }
207
208
                if ($data['limit'] < 1) {
209
                    $data['limit'] = 20;
210
                }
211
212
                $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal LIMIT does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal , does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
213
            }
214
215
            $article_data = array();
216
217
            $query = $this->db->query($sql);
218
219
            foreach ($query->rows as $result) {
220
                $article_data[$result['article_id']] = $this->getArticle($result['article_id']);
221
            }
222
223
            //$this->cache->set(
224
            //     'article.' . (int)$this->config->get('config_language_id') . '.0.' . (int)$customer_group_id . '.' . $cache,
225
            //     $article_data
226
            // );
227
        }
228
229
        return $article_data;
230
    }
231
232
    public function getLatestArticles($limit)
233
    {
234
        if ($this->customer->isLogged()) {
235
            $customer_group_id = $this->customer->getGroupId();
236
        } else {
237
            $customer_group_id = $this->config->get('config_customer_group_id');
238
        }
239
240
        $article_data = $this->cache->get('article.latest.' . (int)$this->config->get('config_language_id') . '.0.' . $customer_group_id . '.' . (int)$limit);
241
242
        if (!$article_data) {
243
            $query = $this->db->query(
244
                "
245
                SELECT p.article_id 
246
                FROM article p 
247
                WHERE p.status = '1'
248
                ORDER BY p.date_added DESC 
249
                LIMIT " . (int)$limit
250
            );
251
252
            foreach ($query->rows as $result) {
253
                $article_data[$result['article_id']] = $this->getArticle($result['article_id']);
254
            }
255
256
            $this->cache->set(
257
                'article.latest.' . (int)$this->config->get('config_language_id') . '.0.' . $customer_group_id . '.' . (int)$limit,
258
                $article_data
259
            );
260
        }
261
262
        return $article_data;
263
    }
264
265
    public function getPopularArticles($limit)
266
    {
267
        $article_data = array();
268
269
        $query = $this->db->query(
270
            "
271
            SELECT p.article_id 
272
            FROM article p 
273
            WHERE p.status = '1'
274
            ORDER BY p.viewed DESC, p.date_added DESC 
275
            LIMIT " . (int)$limit
276
        );
277
278
        foreach ($query->rows as $result) {
279
            $article_data[$result['article_id']] = $this->getArticle($result['article_id']);
280
        }
281
282
        return $article_data;
283
    }
284
285
    public function getArticleImages($article_id)
286
    {
287
        $query = $this->db->query("
288
            SELECT * 
289
            FROM article_image 
290
            WHERE article_id = '" . (int)$article_id . "' 
291
            ORDER BY sort_order ASC
292
        ");
293
294
        return $query->rows;
295
    }
296
297
    public function getArticleRelated($article_id)
298
    {
299
        $article_data = array();
300
301
        $query = $this->db->query("
302
            SELECT * FROM article_related pr 
303
            LEFT JOIN article p ON (pr.related_id = p.article_id) 
304
            WHERE pr.article_id = '" . (int)$article_id . "' 
305
                AND p.status = '1'
306
        ");
307
308
        foreach ($query->rows as $result) {
309
            $article_data[$result['related_id']] = $this->getArticle($result['related_id']);
310
        }
311
312
        return $article_data;
313
    }
314
315
    public function getArticleRelatedByProduct($data)
316
    {
317
        $article_data = array();
318
319
        $this->load->model('blog/article');
320
321
        $sql = "
322
            SELECT * 
323
            FROM product_related_article np 
324
            LEFT JOIN article p ON (np.article_id = p.article_id) 
325
            WHERE np.product_id = '" . (int)$data['product_id'] . "' 
326
                AND p.status = '1'
327
            LIMIT " . $data['limit'];
328
329
        $query = $this->db->query($sql);
330
331
        foreach ($query->rows as $result) {
332
            $article_data[$result['article_id']] = $this->model_blog_article->getArticle($result['article_id']);
333
        }
334
335
        return $article_data;
336
    }
337
338
    //category manuf
339
    public function getArticleRelatedByCategory($data)
340
    {
341
        $article_data = array();
342
343
        $query = $this->db->query(
344
            "
345
            SELECT * 
346
            FROM article_related_wb pr 
347
            LEFT JOIN article p ON (pr.article_id = p.article_id) 
348
            WHERE pr.category_id = '" . (int)$data['category_id'] . "' 
349
                AND p.status = '1'
350
            LIMIT " . (int)$data['limit']
351
        );
352
353
        foreach ($query->rows as $result) {
354
            $article_data[$result['article_id']] = $this->getArticle($result['article_id']);
355
        }
356
357
        return $article_data;
358
    }
359
360
    public function getArticleRelatedByManufacturer($data)
361
    {
362
        $article_data = array();
363
364
        $query = $this->db->query(
365
            "
366
            SELECT * 
367
            FROM article_related_mn pr 
368
            LEFT JOIN article p ON (pr.article_id = p.article_id) 
369
            WHERE pr.manufacturer_id = '" . (int)$data['manufacturer_id'] . "' 
370
                AND p.status = '1'
371
            LIMIT " . (int)$data['limit']
372
        );
373
374
        foreach ($query->rows as $result) {
375
            $article_data[$result['article_id']] = $this->getArticle($result['article_id']);
376
        }
377
378
379
380
        return $article_data;
381
    }
382
    //category manuf
383
384
    public function getArticleRelatedProduct($article_id)
385
    {
386
        $product_data = array();
387
        $this->load->model('catalog/product');
388
        $query = $this->db->query("
389
            SELECT * FROM article_related_product np 
390
            LEFT JOIN product p ON (np.product_id = p.product_id) 
391
            WHERE np.article_id = '" . (int)$article_id . "' 
392
                AND p.status = '1'
393
        ");
394
395
        foreach ($query->rows as $result) {
396
            $product_data[$result['product_id']] = $this->model_catalog_product->getProduct($result['product_id']);
397
        }
398
399
        return $product_data;
400
    }
401
402
    public function getArticleLayoutId($article_id)
403
    {
404
        $query = $this->db->query("
405
            SELECT * 
406
            FROM article_to_layout 
407
            WHERE article_id = '" . (int)$article_id . "'
408
        ");
409
410
        if ($query->num_rows) {
411
            return $query->row['layout_id'];
412
        } else {
413
            return  $this->config->get('config_layout_article');
414
        }
415
    }
416
417
    public function getCategories($article_id)
418
    {
419
        $query = $this->db->query("
420
            SELECT * 
421
            FROM article_to_blog_category 
422
            WHERE article_id = '" . (int)$article_id . "'
423
        ");
424
425
        return $query->rows;
426
    }
427
428
    public function getDownloads($article_id)
429
    {
430
        $query = $this->db->query("
431
            SELECT * 
432
            FROM article_to_download pd 
433
            LEFT JOIN download d ON(pd.download_id=d.download_id) 
434
            LEFT JOIN download_description dd ON(pd.download_id=dd.download_id) 
435
            WHERE article_id = '" . (int)$article_id . "' 
436
                AND dd.language_id = '" . (int)$this->config->get('config_language_id') . "'
437
        ");
438
439
        return $query->rows;
440
    }
441
442
    public function getDownload($article_id, $download_id)
443
    {
444
        $download = "";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
445
        if ($download_id != 0) {
446
            $download = " AND d.download_id=" . (int)$download_id;
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal AND d.download_id= does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
447
        }
448
        $query = $this->db->query("
449
            SELECT * 
450
            FROM article_to_download pd 
451
            LEFT JOIN download d ON(pd.download_id=d.download_id) 
452
            LEFT JOIN download_description dd ON(pd.download_id=dd.download_id) 
453
            WHERE article_id = '" . (int)$article_id . "' " . $download . " 
454
                AND dd.language_id = '" . (int)$this->config->get('config_language_id') . "'
455
        ");
456
457
        return $query->row;
458
    }
459
460
    public function getTotalArticles($data = array())
461
    {
462
        if ($this->customer->isLogged()) {
463
            $customer_group_id = $this->customer->getGroupId();
464
        } else {
465
            $customer_group_id = $this->config->get('config_customer_group_id');
466
        }
467
468
        $cache = md5(http_build_query($data));
469
470
        $article_data = $this->cache->get('article.total.' . (int)$this->config->get('config_language_id') . '.0.' . (int)$customer_group_id . '.' . $cache);
471
472
        if (!$article_data) {
473
            $sql = "
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal \n SELECT...icle_id) \n does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
474
                SELECT COUNT(DISTINCT p.article_id) AS total 
475
                FROM article p 
476
                LEFT JOIN article_description pd ON (p.article_id = pd.article_id) 
477
            ";
478
479
            if (!empty($data['filter_blog_category_id'])) {
480
                $sql .= " 
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal \n L...e_id)\n does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
481
                    LEFT JOIN article_to_blog_category p2c ON (p.article_id = p2c.article_id)
482
                ";
483
            }
484
485
            $sql .= " 
486
                WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' 
487
                AND p.status = '1'
488
            ";
489
490
            if (!empty($data['filter_name']) || !empty($data['filter_tag'])) {
491
                $sql .= " AND (";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal AND ( does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
492
493
                if (!empty($data['filter_name'])) {
494
                    if (!empty($data['filter_description'])) {
495
                        $sql .= "
496
                            LCASE(pd.name) LIKE '%" . $this->db->escape(\voku\helper\UTF8::strtolower($data['filter_name'])) . "%' 
497
                            OR MATCH(pd.description) 
498
                            AGAINST('" . $this->db->escape(\voku\helper\UTF8::strtolower($data['filter_name'])) . "')
499
                        ";
500
                    } else {
501
                        $sql .= "
502
                            LCASE(pd.name) LIKE '%" . $this->db->escape(\voku\helper\UTF8::strtolower($data['filter_name'])) . "%'
503
                        ";
504
                    }
505
                }
506
507
                if (!empty($data['filter_name']) && !empty($data['filter_tag'])) {
508
                    $sql .= " OR ";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal OR does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
509
                }
510
511
                if (!empty($data['filter_tag'])) {
512
                    $sql .= "MATCH(pd.tag) AGAINST('" . $this->db->escape(\voku\helper\UTF8::strtolower($data['filter_tag'])) . "')";
513
                }
514
515
                $sql .= ")";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal ) does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
516
517
                if (!empty($data['filter_name'])) {
518
                    $sql .= " OR LCASE(p.model) = '" . $this->db->escape(\voku\helper\UTF8::strtolower($data['filter_name'])) . "'";
519
                }
520
521
                if (!empty($data['filter_name'])) {
522
                    $sql .= " OR LCASE(p.sku) = '" . $this->db->escape(\voku\helper\UTF8::strtolower($data['filter_name'])) . "'";
523
                }
524
525
                if (!empty($data['filter_name'])) {
526
                    $sql .= " OR LCASE(p.upc) = '" . $this->db->escape(\voku\helper\UTF8::strtolower($data['filter_name'])) . "'";
527
                }
528
529
                if (!empty($data['filter_name'])) {
530
                    $sql .= " OR LCASE(p.ean) = '" . $this->db->escape(\voku\helper\UTF8::strtolower($data['filter_name'])) . "'";
531
                }
532
533
                if (!empty($data['filter_name'])) {
534
                    $sql .= " OR LCASE(p.jan) = '" . $this->db->escape(\voku\helper\UTF8::strtolower($data['filter_name'])) . "'";
535
                }
536
537
                if (!empty($data['filter_name'])) {
538
                    $sql .= " OR LCASE(p.isbn) = '" . $this->db->escape(\voku\helper\UTF8::strtolower($data['filter_name'])) . "'";
539
                }
540
541
                if (!empty($data['filter_name'])) {
542
                    $sql .= " OR LCASE(p.mpn) = '" . $this->db->escape(\voku\helper\UTF8::strtolower($data['filter_name'])) . "'";
543
                }
544
            }
545
546
            if (!empty($data['filter_blog_category_id'])) {
547
                if (!empty($data['filter_sub_blog_category'])) {
548
                    $implode_data = array();
549
550
                    $implode_data[] = (int)$data['filter_blog_category_id'];
551
552
                    $this->load->model('blog/category');
553
554
                    $categories = $this->model_blog_category->getCategoriesByParentId($data['filter_category_id']);
555
556
                    foreach ($categories as $blog_category_id) {
557
                        $implode_data[] = (int)$blog_category_id;
558
                    }
559
560
                    $sql .= " AND p2c.blog_category_id IN (" . implode(', ', $implode_data) . ")";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal AND p2c.blog_category_id IN ( does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal ) does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
561
                } else {
562
                    $sql .= " AND p2c.blog_category_id = '" . (int)$data['filter_blog_category_id'] . "'";
563
                }
564
            }
565
566
            $query = $this->db->query($sql);
567
568
            $article_data = $query->row['total'];
569
570
            $this->cache->set(
571
                'article.total.' . (int)$this->config->get('config_language_id') . '.0.' . (int)$customer_group_id . '.' . $cache,
572
                $article_data
573
            );
574
        }
575
576
        return $article_data;
577
    }
578
}
579