Issues (2407)

administration/model/blog/article.php (16 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 addArticle($data)
0 ignored issues
show
Expected 2 blank lines before function; 0 found
Loading history...
26
    {
27
        $this->db->query("
28
            INSERT INTO article 
29
            SET status = '" . (int)$data['status'] . "', 
30
                noindex = '" . (int)$data['noindex'] . "', 
31
                sort_order = '" . (int)$data['sort_order'] . "', 
32
                date_added = NOW()
33
        ");
34
35
        $article_id = $this->db->getLastId();
36
37
        if (isset($data['image'])) {
38
            $this->db->query("
39
                UPDATE article 
40
                SET image = '" . $this->db->escape($data['image']) . "' 
41
                WHERE article_id = '" . (int)$article_id . "'
42
            ");
43
        }
44
45
        foreach ($data['article_description'] as $language_id => $value) {
46
            $this->db->query("
47
                INSERT INTO article_description 
48
                SET article_id = '" . (int)$article_id . "', 
49
                    language_id = '" . (int)$language_id . "', 
50
                    name = '" . $this->db->escape($value['name']) . "', 
51
                    description = '" . $this->db->escape($value['description']) . "', 
52
                    tag = '" . $this->db->escape($value['tag']) . "', 
53
                    meta_title = '" . $this->db->escape($value['meta_title']) . "', 
54
                    meta_h1 = '" . $this->db->escape($value['meta_h1']) . "', 
55
                    meta_description = '" . $this->db->escape($value['meta_description']) . "'
56
            ");
57
        }
58
59
        if (isset($data['article_image'])) {
60
            foreach ($data['article_image'] as $article_image) {
61
                $this->db->query("
62
                    INSERT INTO article_image 
63
                    SET article_id = '" . (int)$article_id . "', 
64
                        image = '" . $this->db->escape($article_image['image']) . "', 
65
                        sort_order = '" . (int)$article_image['sort_order'] . "'
66
                ");
67
            }
68
        }
69
70
        if (isset($data['article_download'])) {
71
            foreach ($data['article_download'] as $download_id) {
72
                $this->db->query("
73
                    INSERT INTO article_to_download 
74
                    SET article_id = '" . (int)$article_id . "', 
75
                        download_id = '" . (int)$download_id . "'
76
                ");
77
            }
78
        }
79
80
        if (isset($data['article_category'])) {
81
            foreach ($data['article_category'] as $blog_category_id) {
82
                $this->db->query("
83
                    INSERT INTO article_to_blog_category 
84
                    SET article_id = '" . (int)$article_id . "', 
85
                        blog_category_id = '" . (int)$blog_category_id . "'
86
                ");
87
            }
88
        }
89
90
        if (isset($data['main_blog_category_id']) && $data['main_blog_category_id'] > 0) {
91
            $this->db->query("
92
                DELETE 
93
				FROM article_to_blog_category 
94
                WHERE article_id = '" . (int)$article_id . "' 
95
                    AND blog_category_id = '" . (int)$data['main_blog_category_id'] . "'
96
            ");
97
            $this->db->query("
98
                INSERT INTO article_to_blog_category 
99
                SET article_id = '" . (int)$article_id . "', 
100
                    blog_category_id = '" . (int)$data['main_blog_category_id'] . "', 
101
                    main_blog_category = 1
102
            ");
103
        } elseif (isset($data['article_category'][0])) {
104
            $this->db->query("
105
                UPDATE article_to_blog_category 
106
                SET main_blog_category = 1 
107
                WHERE article_id = '" . (int)$article_id . "' 
108
                    AND blog_category_id = '" . (int)$data['article_category'][0] . "'
109
            ");
110
        }
111
112
        if (isset($data['article_related'])) {
113
            foreach ($data['article_related'] as $related_id) {
114
                $this->db->query("
115
                    DELETE 
116
                    FROM article_related 
117
                    WHERE article_id = '" . (int)$article_id . "' 
118
                        AND related_id = '" . (int)$related_id . "'
119
                ");
120
                $this->db->query("
121
                    INSERT INTO article_related 
122
                    SET article_id = '" . (int)$article_id . "', 
123
                        related_id = '" . (int)$related_id . "'
124
                ");
125
                $this->db->query("
126
                    DELETE 
127
				    FROM article_related 
128
                    WHERE article_id = '" . (int)$related_id . "' 
129
                        AND related_id = '" . (int)$article_id . "'
130
                ");
131
                $this->db->query("
132
                    INSERT INTO article_related 
133
                    SET article_id = '" . (int)$related_id . "', 
134
                        related_id = '" . (int)$article_id . "'
135
                ");
136
            }
137
        }
138
139
        if (isset($data['product_related'])) {
140
            foreach ($data['product_related'] as $related_id) {
141
                $this->db->query("
142
                    DELETE 
143
				    FROM article_related_product 
144
                    WHERE article_id = '" . (int)$article_id . "' 
145
                        AND product_id = '" . (int)$related_id . "'
146
                ");
147
                $this->db->query("
148
                    INSERT INTO article_related_product 
149
                    SET article_id = '" . (int)$article_id . "', 
150
                        product_id = '" . (int)$related_id . "'
151
                ");
152
            }
153
        }
154
155
        if (isset($data['article_layout'])) {
156
            foreach ($data['article_layout'] as $layout_id) {
157
                $this->db->query("
158
                    INSERT INTO article_to_layout 
159
                    SET article_id = '" . (int)$article_id . "', 
160
                        layout_id = '" . (int)$layout_id . "'
161
                ");
162
            }
163
        }
164
165
        $this->cache->delete('url_formatter');
166
167
        if (isset($data['keyword']) && !empty($data['keyword'])) {
168
            $this->db->query("
169
                INSERT INTO url_alias 
170
                SET query = 'article_id=" . (int)$article_id . "', 
171
                    keyword = '" . $this->db->escape($data['keyword']) . "'
172
            ");
173
        }
174
175
        $this->cache->delete('article');
176
177
        return $article_id;
178
    }
179
180
    public function editArticle($article_id, $data)
181
    {
182
        $this->db->query("
183
            UPDATE article 
184
            SET status = '" . (int)$data['status'] . "', 
185
                noindex = '" . (int)$data['noindex'] . "', 
186
                sort_order = '" . (int)$data['sort_order'] . "', 
187
                date_modified = NOW() 
188
            WHERE article_id = '" . (int)$article_id . "'
189
        ");
190
191
        if (isset($data['image'])) {
192
            $this->db->query("
193
                UPDATE article 
194
                SET image = '" . $this->db->escape($data['image']) . "' 
195
                WHERE article_id = '" . (int)$article_id . "'
196
            ");
197
        }
198
199
        $this->db->query("
200
            DELETE 
201
            FROM article_description 
202
            WHERE article_id = '" . (int)$article_id . "'
203
        ");
204
205
        foreach ($data['article_description'] as $language_id => $value) {
206
            $this->db->query("
207
                INSERT INTO article_description 
208
                SET article_id = '" . (int)$article_id . "', 
209
                    language_id = '" . (int)$language_id . "', 
210
                    name = '" . $this->db->escape($value['name']) . "', 
211
                    description = '" . $this->db->escape($value['description']) . "', 
212
                    tag = '" . $this->db->escape($value['tag']) . "', 
213
                    meta_title = '" . $this->db->escape($value['meta_title']) . "', 
214
                    meta_h1 = '" . $this->db->escape($value['meta_h1']) . "', 
215
                    meta_description = '" . $this->db->escape($value['meta_description']) . "'
216
            ");
217
        }
218
219
        $this->db->query("
220
            DELETE 
221
            FROM article_image 
222
            WHERE article_id = '" . (int)$article_id . "'
223
        ");
224
225
        if (isset($data['article_image'])) {
226
            foreach ($data['article_image'] as $article_image) {
227
                $this->db->query("
228
                    INSERT INTO article_image 
229
                    SET article_id = '" . (int)$article_id . "', 
230
                        image = '" . $this->db->escape($article_image['image']) . "', 
231
                        sort_order = '" . (int)$article_image['sort_order'] . "'
232
                ");
233
            }
234
        }
235
236
        $this->db->query("
237
            DELETE 
238
            FROM article_to_download 
239
            WHERE article_id = '" . (int)$article_id . "'
240
        ");
241
242
        if (isset($data['article_download'])) {
243
            foreach ($data['article_download'] as $download_id) {
244
                $this->db->query("
245
                    INSERT INTO article_to_download 
246
                    SET article_id = '" . (int)$article_id . "', 
247
                        download_id = '" . (int)$download_id . "'
248
                ");
249
            }
250
        }
251
252
        $this->db->query("
253
            DELETE 
254
            FROM article_to_blog_category 
255
            WHERE article_id = '" . (int)$article_id . "'
256
        ");
257
258
        if (isset($data['article_category'])) {
259
            foreach ($data['article_category'] as $blog_category_id) {
260
                $this->db->query("
261
                    INSERT INTO article_to_blog_category 
262
                    SET article_id = '" . (int)$article_id . "', 
263
                        blog_category_id = '" . (int)$blog_category_id . "'
264
                ");
265
            }
266
        }
267
268
        if (isset($data['main_blog_category_id']) && $data['main_blog_category_id'] > 0) {
269
            $this->db->query("
270
                DELETE 
271
				FROM article_to_blog_category 
272
                WHERE article_id = '" . (int)$article_id . "' 
273
                    AND blog_category_id = '" . (int)$data['main_blog_category_id'] . "'
274
            ");
275
            $this->db->query("
276
                INSERT INTO article_to_blog_category 
277
                SET article_id = '" . (int)$article_id . "', 
278
                    blog_category_id = '" . (int)$data['main_blog_category_id'] . "', 
279
                    main_blog_category = 1
280
            ");
281
        } elseif (isset($data['article_category'][0])) {
282
            $this->db->query("
283
                UPDATE article_to_blog_category 
284
                SET main_blog_category = 1 
285
                WHERE article_id = '" . (int)$article_id . "' 
286
                    AND blog_category_id = '" . (int)$data['article_category'][0] . "'
287
            ");
288
        }
289
290
        $this->db->query("
291
            DELETE 
292
            FROM article_related 
293
            WHERE article_id = '" . (int)$article_id . "'
294
        ");
295
        $this->db->query("
296
            DELETE 
297
            FROM article_related 
298
            WHERE related_id = '" . (int)$article_id . "'
299
        ");
300
301
        if (isset($data['article_related'])) {
302
            foreach ($data['article_related'] as $related_id) {
303
                $this->db->query("
304
                    DELETE 
305
				    FROM article_related 
306
                    WHERE article_id = '" . (int)$article_id . "' 
307
                        AND related_id = '" . (int)$related_id . "'
308
                ");
309
                $this->db->query("
310
                    INSERT INTO article_related 
311
                    SET article_id = '" . (int)$article_id . "', 
312
                        related_id = '" . (int)$related_id . "'
313
                ");
314
                $this->db->query("
315
                    DELETE 
316
				    FROM article_related 
317
                    WHERE article_id = '" . (int)$related_id . "' 
318
                        AND related_id = '" . (int)$article_id . "'
319
                ");
320
                $this->db->query("
321
                    INSERT INTO article_related 
322
                    SET article_id = '" . (int)$related_id . "', 
323
                        related_id = '" . (int)$article_id . "'
324
                ");
325
            }
326
        }
327
328
        $this->db->query("
329
            DELETE 
330
            FROM article_related_product 
331
            WHERE article_id = '" . (int)$article_id . "'
332
        ");
333
334
        if (isset($data['product_related'])) {
335
            foreach ($data['product_related'] as $related_id) {
336
                $this->db->query("
337
                    DELETE 
338
				    FROM article_related_product 
339
                    WHERE article_id = '" . (int)$article_id . "' 
340
                        AND product_id = '" . (int)$related_id . "'
341
                ");
342
                $this->db->query("
343
                    INSERT INTO article_related_product 
344
                    SET article_id = '" . (int)$article_id . "', 
345
                        product_id = '" . (int)$related_id . "'
346
                ");
347
            }
348
        }
349
350
        $this->db->query("
351
            DELETE 
352
            FROM article_to_layout 
353
            WHERE article_id = '" . (int)$article_id . "'
354
        ");
355
356
        if (isset($data['article_layout'])) {
357
            foreach ($data['article_layout'] as $layout_id) {
358
                $this->db->query("
359
                    INSERT INTO article_to_layout 
360
                    SET article_id = '" . (int)$article_id . "', 
361
                        layout_id = '" . (int)$layout_id . "'
362
                ");
363
            }
364
        }
365
366
        $this->db->query("
367
            DELETE 
368
            FROM url_alias 
369
            WHERE query = 'article_id=" . (int)$article_id . "'
370
        ");
371
372
        $this->cache->delete('url_formatter');
373
374
375
        if ($data['keyword']) {
376
            $this->db->query("
377
                INSERT INTO url_alias 
378
                SET query = 'article_id=" . (int)$article_id . "', 
379
                    keyword = '" . $this->db->escape($data['keyword']) . "'
380
            ");
381
        }
382
383
        $this->cache->delete('article');
384
    }
385
386
    public function editArticleStatus($article_id, $status)
387
    {
388
        $this->db->query("
389
            UPDATE article 
390
            SET status = '" . (int)$status . "', 
391
                date_modified = NOW() 
392
            WHERE article_id = '" . (int)$article_id . "'
393
        ");
394
395
        $this->cache->delete('article');
396
397
        return $article_id;
398
    }
399
400
    public function copyArticle($article_id)
401
    {
402
        $query = $this->db->query("
403
            SELECT DISTINCT * 
404
            FROM article p 
405
            LEFT JOIN article_description pd ON (p.article_id = pd.article_id) 
406
            WHERE p.article_id = '" . (int)$article_id . "' 
407
                AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "'
408
        ");
409
410
        if ($query->num_rows) {
411
            $data = $query->row;
412
413
            $data['viewed'] = '0';
414
            $data['keyword'] = '';
415
            $data['status'] = '0';
416
            $data['noindex'] = '0';
417
418
            $data['article_description'] = $this->getArticleDescriptions($article_id);
0 ignored issues
show
The method getArticleDescriptions() does not exist on ModelBlogArticle. Did you maybe mean getArticle()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

418
            /** @scrutinizer ignore-call */ 
419
            $data['article_description'] = $this->getArticleDescriptions($article_id);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
419
            $data['article_image'] = $this->getArticleImages($article_id);
420
            $data['article_related'] = $this->getArticleRelated($article_id);
421
            $data['product_related'] = $this->getProductRelated($article_id);
0 ignored issues
show
The method getProductRelated() does not exist on ModelBlogArticle. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

421
            /** @scrutinizer ignore-call */ 
422
            $data['product_related'] = $this->getProductRelated($article_id);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
422
            $data['article_category'] = $this->getArticleCategories($article_id);
0 ignored issues
show
The method getArticleCategories() does not exist on ModelBlogArticle. Did you maybe mean getArticle()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

422
            /** @scrutinizer ignore-call */ 
423
            $data['article_category'] = $this->getArticleCategories($article_id);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
423
            $data['article_download'] = $this->getArticleDownloads($article_id);
0 ignored issues
show
The method getArticleDownloads() does not exist on ModelBlogArticle. Did you maybe mean getArticle()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

423
            /** @scrutinizer ignore-call */ 
424
            $data['article_download'] = $this->getArticleDownloads($article_id);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
424
            $data['article_layout'] = $this->getArticleLayouts($article_id);
0 ignored issues
show
The method getArticleLayouts() does not exist on ModelBlogArticle. Did you maybe mean getArticle()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

424
            /** @scrutinizer ignore-call */ 
425
            $data['article_layout'] = $this->getArticleLayouts($article_id);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
425
426
            $this->addArticle($data);
0 ignored issues
show
The method addArticle() does not exist on ModelBlogArticle. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

426
            $this->/** @scrutinizer ignore-call */ 
427
                   addArticle($data);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
427
        }
428
    }
429
430
    public function deleteArticle($article_id)
431
    {
432
        $this->db->query("
433
            DELETE 
434
            FROM article 
435
            WHERE article_id = '" . (int)$article_id . "'
436
        ");
437
        $this->db->query("
438
            DELETE 
439
            FROM article_description 
440
            WHERE article_id = '" . (int)$article_id . "'
441
        ");
442
        $this->db->query("
443
            DELETE 
444
            FROM article_image 
445
            WHERE article_id = '" . (int)$article_id . "'
446
        ");
447
        $this->db->query("
448
            DELETE 
449
            FROM article_related 
450
            WHERE article_id = '" . (int)$article_id . "'
451
        ");
452
        $this->db->query("
453
            DELETE 
454
            FROM article_related 
455
            WHERE related_id = '" . (int)$article_id . "'
456
        ");
457
        $this->db->query("
458
            DELETE 
459
            FROM article_related_product 
460
            WHERE article_id = '" . (int)$article_id . "'
461
        ");
462
        $this->db->query("
463
            DELETE 
464
            FROM article_to_blog_category 
465
            WHERE article_id = '" . (int)$article_id . "'
466
        ");
467
        $this->db->query("
468
            DELETE 
469
            FROM article_to_download 
470
            WHERE article_id = '" . (int)$article_id . "'
471
        ");
472
        $this->db->query("
473
            DELETE 
474
            FROM article_to_layout 
475
            WHERE article_id = '" . (int)$article_id . "'
476
        ");
477
        $this->db->query("
478
            DELETE 
479
            FROM review_article 
480
            WHERE article_id = '" . (int)$article_id . "'
481
        ");
482
        $this->db->query("
483
            DELETE 
484
            FROM url_alias 
485
            WHERE query = 'article_id=" . (int)$article_id . "'
486
        ");
487
488
        $this->cache->delete('article');
489
    }
490
491
    public function getArticle($article_id)
492
    {
493
        $query = $this->db->query("
494
            SELECT DISTINCT *, 
495
                (
496
                    SELECT keyword 
497
                    FROM url_alias 
498
                    WHERE query = 'article_id=" . (int)$article_id . "') AS keyword 
499
            FROM article p 
500
            LEFT JOIN article_description pd ON (p.article_id = pd.article_id) 
501
            WHERE p.article_id = '" . (int)$article_id . "' 
502
                AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "'
503
        ");
504
505
        return $query->row;
506
    }
507
508
    public function getArticles($data = array())
509
    {
510
        $sql = "
511
            SELECT * 
512
            FROM article p 
513
            LEFT JOIN article_description pd ON (p.article_id = pd.article_id) 
514
            WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "'
515
        ";
516
517
        if (!empty($data['filter_name'])) {
518
            $sql .= " AND pd.name LIKE '" . $this->db->escape($data['filter_name']) . "%'";
519
        }
520
521
        if (isset($data['filter_status']) && !is_null($data['filter_status'])) {
522
            $sql .= " AND p.status = '" . (int)$data['filter_status'] . "'";
523
        }
524
525
        if (isset($data['filter_noindex']) && !is_null($data['filter_noindex'])) {
526
            $sql .= " AND p.noindex = '" . (int)$data['filter_noindex'] . "'";
527
        }
528
529
        $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...
530
531
        $sort_data = array(
532
            'pd.name',
533
            'p.status',
534
            'p.noindex',
535
            'p.sort_order'
536
        );
537
538
        if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
539
            $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...
540
        } else {
541
            $sql .= " ORDER BY pd.name";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal ORDER BY pd.name 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...
542
        }
543
544
        if (isset($data['order']) && ($data['order'] == 'DESC')) {
545
            $sql .= " DESC";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal 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...
546
        } else {
547
            $sql .= " ASC";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal 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...
548
        }
549
550
        if (isset($data['start']) || isset($data['limit'])) {
551
            if ($data['start'] < 0) {
552
                $data['start'] = 0;
553
            }
554
555
            if ($data['limit'] < 1) {
556
                $data['limit'] = 20;
557
            }
558
559
            $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...
560
        }
561
562
        $query = $this->db->query($sql);
563
564
        return $query->rows;
565
    }
566
567
    public function getArticlesByCategoryId($blog_category_id)
568
    {
569
        $query = $this->db->query("
570
            SELECT * FROM article p 
571
            LEFT JOIN article_description pd ON (p.article_id = pd.article_id) 
572
            LEFT JOIN article_to_blog_category p2c ON (p.article_id = p2c.article_id) 
573
            WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' 
574
                AND p2c.blog_category_id = '" . (int)$blog_category_id . "' 
575
            ORDER BY pd.name ASC
576
        ");
577
578
        return $query->rows;
579
    }
580
581
    public function getArticleDescriptions($article_id)
582
    {
583
        $article_description_data = array();
584
585
        $query = $this->db->query("
586
            SELECT * 
587
            FROM article_description 
588
            WHERE article_id = '" . (int)$article_id . "'
589
        ");
590
591
        foreach ($query->rows as $result) {
592
            $article_description_data[$result['language_id']] = array(
593
                'name'             => $result['name'],
594
                'description'      => $result['description'],
595
                'meta_title'       => $result['meta_title'],
596
                'meta_h1'           => $result['meta_h1'],
597
                'meta_description' => $result['meta_description'],
598
                'tag'              => $result['tag']
599
            );
600
        }
601
602
        return $article_description_data;
603
    }
604
605
    public function getArticleCategories($article_id)
606
    {
607
        $article_category_data = array();
608
609
        $query = $this->db->query("
610
            SELECT * 
611
            FROM article_to_blog_category 
612
            WHERE article_id = '" . (int)$article_id . "'
613
        ");
614
615
        foreach ($query->rows as $result) {
616
            $article_category_data[] = $result['blog_category_id'];
617
        }
618
619
        return $article_category_data;
620
    }
621
622
    public function getArticleMainCategoryId($article_id)
623
    {
624
        $query = $this->db->query("
625
            SELECT blog_category_id 
626
            FROM article_to_blog_category 
627
            WHERE article_id = '" . (int)$article_id . "' 
628
                AND main_blog_category = '1' 
629
            LIMIT 1
630
        ");
631
632
        return ($query->num_rows ? (int)$query->row['blog_category_id'] : 0);
633
    }
634
635
    public function getArticleImages($article_id)
636
    {
637
        $query = $this->db->query("
638
            SELECT * 
639
            FROM article_image 
640
            WHERE article_id = '" . (int)$article_id . "' 
641
            ORDER BY sort_order ASC
642
        ");
643
644
        return $query->rows;
645
    }
646
647
    public function getArticleDownloads($article_id)
648
    {
649
        $article_download_data = array();
650
651
        $query = $this->db->query("
652
            SELECT * 
653
            FROM article_to_download 
654
            WHERE article_id = '" . (int)$article_id . "'
655
        ");
656
657
        foreach ($query->rows as $result) {
658
            $article_download_data[] = $result['download_id'];
659
        }
660
661
        return $article_download_data;
662
    }
663
664
    public function getArticleLayouts($article_id)
665
    {
666
        $article_layout_data = array();
667
668
        $query = $this->db->query("
669
            SELECT * 
670
            FROM article_to_layout 
671
            WHERE article_id = '" . (int)$article_id . "'
672
        ");
673
674
        foreach ($query->rows as $result) {
675
            $article_layout_data = $result['layout_id'];
676
        }
677
678
        return $article_layout_data;
679
    }
680
681
    public function getArticleRelated($article_id)
682
    {
683
        $article_related_data = array();
684
685
        $query = $this->db->query("
686
            SELECT * 
687
            FROM article_related 
688
            WHERE article_id = '" . (int)$article_id . "'
689
        ");
690
691
        foreach ($query->rows as $result) {
692
            $article_related_data[] = $result['related_id'];
693
        }
694
695
        return $article_related_data;
696
    }
697
698
    public function getProductRelated($article_id)
699
    {
700
        $article_related_product = array();
701
702
        $query = $this->db->query("
703
            SELECT * 
704
            FROM article_related_product 
705
            WHERE article_id = '" . (int)$article_id . "'
706
        ");
707
708
        foreach ($query->rows as $result) {
709
            $article_related_product[] = $result['product_id'];
710
        }
711
712
        return $article_related_product;
713
    }
714
715
    public function getTotalArticles($data = array())
716
    {
717
        $sql = "
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal \n SELECT COU...d.article_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...
718
            SELECT COUNT(DISTINCT p.article_id) AS total 
719
            FROM article p 
720
            LEFT JOIN article_description pd ON (p.article_id = pd.article_id)
721
        ";
722
723
        $sql .= " WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "'";
724
725
        if (!empty($data['filter_name'])) {
726
            $sql .= " AND pd.name LIKE '" . $this->db->escape($data['filter_name']) . "%'";
727
        }
728
729
        if (isset($data['filter_status']) && !is_null($data['filter_status'])) {
730
            $sql .= " AND p.status = '" . (int)$data['filter_status'] . "'";
731
        }
732
733
        if (isset($data['filter_noindex']) && $data['filter_noindex'] !== null) {
734
            $sql .= " AND p.noindex = '" . (int)$data['filter_noindex'] . "'";
735
        }
736
737
        $query = $this->db->query($sql);
738
739
        return $query->row['total'];
740
    }
741
742
    public function getTotalArticlesByDownloadId($download_id)
743
    {
744
        $query = $this->db->query("
745
            SELECT COUNT(*) AS total 
746
            FROM article_to_download 
747
            WHERE download_id = '" . (int)$download_id . "'
748
        ");
749
750
        return $query->row['total'];
751
    }
752
753
    public function getTotalArticlesByLayoutId($layout_id)
754
    {
755
        $query = $this->db->query("
756
            SELECT COUNT(*) AS total 
757
            FROM article_to_layout 
758
            WHERE layout_id = '" . (int)$layout_id . "'
759
        ");
760
761
        return $query->row['total'];
762
    }
763
}
764