Issues (2407)

application/model/blog/review.php (4 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 ModelBlogReview 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 addReview($article_id, $data)
0 ignored issues
show
Expected 2 blank lines before function; 0 found
Loading history...
26
    {
27
        $this->db->query("
28
            INSERT INTO review_article 
29
            SET author = '" . $this->db->escape($data['name']) . "', 
30
                customer_id = '" . (int)$this->customer->getId() . "', 
31
                article_id = '" . (int)$article_id . "', 
32
                text = '" . $this->db->escape($data['text']) . "', 
33
                date_added = NOW()
34
        ");
35
36
        $review_id = $this->db->getLastId();
0 ignored issues
show
The assignment to $review_id is dead and can be removed.
Loading history...
37
38
        if ($this->config->get('configblog_review_mail')) {
39
            $this->load->language('blog/mail/review');
40
            $this->load->model('blog/article');
41
            
42
            $article_info = $this->model_blog_article->getArticle($article_id);
43
44
            $subject = sprintf($this->language->get('text_subject'), html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8'));
45
46
            $message  = $this->language->get('text_waiting') . "\n";
47
            $message .= sprintf($this->language->get('text_article'), html_entity_decode($article_info['name'], ENT_QUOTES, 'UTF-8')) . "\n";
48
            $message .= sprintf($this->language->get('text_reviewer'), html_entity_decode($data['name'], ENT_QUOTES, 'UTF-8')) . "\n";
49
            $message .= $this->language->get('text_review') . "\n";
50
            $message .= html_entity_decode($data['text'], ENT_QUOTES, 'UTF-8') . "\n\n";
51
52
            $mail = new \Divine\Engine\Library\Mail();
53
            $mail->protocol = $this->config->get('config_mail_protocol');
54
            $mail->parameter = $this->config->get('config_mail_parameter');
55
            $mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname');
56
            $mail->smtp_username = $this->config->get('config_mail_smtp_username');
57
            $mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8');
58
            $mail->smtp_port = $this->config->get('config_mail_smtp_port');
59
            $mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout');
60
61
            $mail->setTo($this->config->get('config_email'));
62
            $mail->setFrom($this->config->get('config_email'));
63
            $mail->setSender(html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8'));
64
            $mail->setSubject($subject);
65
            $mail->setText($message);
66
            $mail->send();
67
68
            // Send to additional alert emails
69
            $emails = explode(',', $this->config->get('config_alert_email'));
70
71
            foreach ($emails as $email) {
72
                if ($email && preg_match('/^[^\@]+@.*.[a-z]{2,15}$/i', $email)) {
73
                    $mail->setTo($email);
74
                    $mail->send();
75
                }
76
            }
77
        }
78
    }
79
80
    public function getReviewsByArticleId($article_id, $start = 0, $limit = 20)
81
    {
82
        if ($start < 0) {
83
            $start = 0;
84
        }
85
86
        if ($limit < 1) {
87
            $limit = 20;
88
        }
89
90
        $query = $this->db->query(
91
            "
92
            SELECT r.review_article_id, r.author, r.text, p.article_id, pd.name, p.image, r.date_added 
93
            FROM review_article r LEFT JOIN article p ON (r.article_id = p.article_id) 
94
            LEFT JOIN article_description pd ON (p.article_id = pd.article_id) 
95
            WHERE p.article_id = '" . (int)$article_id . "' 
96
                AND p.status = '1' 
97
                AND r.status = '1' 
98
                AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' 
99
            ORDER BY r.date_added DESC 
100
            LIMIT " . (int)$start . "," . (int)$limit
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...
101
        );
102
103
        return $query->rows;
104
    }
105
106
    public function getTotalReviewsByArticleId($article_id)
107
    {
108
        $query = $this->db->query("
109
            SELECT COUNT(*) AS total 
110
            FROM review_article r 
111
            LEFT JOIN article p ON (r.article_id = p.article_id) 
112
            LEFT JOIN article_description pd ON (p.article_id = pd.article_id) 
113
            WHERE p.article_id = '" . (int)$article_id . "' 
114
                AND p.status = '1' 
115
                AND r.status = '1' 
116
                AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "'
117
        ");
118
119
        return $query->row['total'];
120
    }
121
}
122