|
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 |
|
|
|
|
|
|
24
|
|
|
{ |
|
25
|
|
|
public function addReview($article_id, $data) |
|
|
|
|
|
|
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(); |
|
|
|
|
|
|
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 |
|
|
|
|
|
|
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
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.