-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathBlogcomment.php
More file actions
executable file
·170 lines (155 loc) · 7.02 KB
/
Blogcomment.php
File metadata and controls
executable file
·170 lines (155 loc) · 7.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
/**
* 2007-2015 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2015 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class Blogcomment extends ObjectModel
{
public $id_smart_blog_comment;
public $id_parent;
public $id_customer;
public $id_post;
public $name;
public $email;
public $website;
public $content;
public $active = 1;
public $created;
public static $definition = array(
'table' => 'smart_blog_comment',
'primary' => 'id_smart_blog_comment',
'multilang' => false,
'fields' => array(
'id_parent' => array('type' => self::TYPE_INT, 'validate' => 'isunsignedInt'),
'id_customer' => array('type' => self::TYPE_INT, 'validate' => 'isunsignedInt'),
'id_post' => array('type' => self::TYPE_INT, 'validate' => 'isunsignedInt'),
'name' => array('type' => self::TYPE_STRING, 'validate' => 'isString'),
'email' => array('type' => self::TYPE_STRING, 'validate' => 'isString'),
'website' => array('type' => self::TYPE_STRING, 'validate' => 'isString'),
'content' => array('type' => self::TYPE_HTML, 'validate' => 'isString'),
'active' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
'created' => array('type' => self::TYPE_DATE, 'validate' => 'isString'),
),
);
public $comment_child_loop = 0;
public $comment_child_loop_depth = 2;
public function __construct($id = null, $id_shop = null)
{
Shop::addTableAssociation('smart_blog_comment', array('type' => 'shop'));
parent::__construct($id, $id_shop);
}
public function addComment($id_post, $comment, $value, $id_parent)
{
if ($id_parent == '' && $id_parent == null) {
$id_parent = 0;
}
$sql = 'INSERT INTO ' . _DB_PREFIX_ . 'smart_blog_comment(id_post,name,email,content,website,id_parent, active) VALUES (' . (int) $id_post . ', \'' . $comment['name'] . '\', \'' . $comment['mail'] . '\', \'' . $comment['comment'] . '\', \'' . $comment['website'] . '\', ' . (int) $id_parent . ', ' . $value . ')';
if (!Db::getInstance()->execute($sql))
return false;
}
public function getChildComment($id_parent)
{
$child_comments = NULL;
$sql = 'SELECT * FROM ' . _DB_PREFIX_ . 'smart_blog_comment
WHERE active=1 AND id_parent=' . (int) $id_parent;
if (!$child_comments = DB::getInstance()->executeS($sql))
return false;
$j = 0;
if (isset($child_comments) && (count($child_comments) > 0)) {
foreach ($child_comments as $key => $ch_comment) {
$child_comments[$key]['content'] = str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),"<br/>",$ch_comment['content']);
if ($this->comment_child_loop <= $this->comment_child_loop_depth) {
$coments_2 = $this->getChildComment($ch_comment['id_smart_blog_comment']);
if ($coments_2){
if (count($coments_2) > 0)
$child_comments[$j]['child_comments'] = $coments_2;
}
}
$j++;
$this->comment_child_loop++;
}
}
return $child_comments;
}
public function getComment($id_post)
{
$sql = 'SELECT * FROM ' . _DB_PREFIX_ . 'smart_blog_comment
WHERE active=1 AND id_parent=0 AND id_post=' . (int) $id_post;
if (!$comments = DB::getInstance()->executeS($sql))
return false;
$i = 0;
foreach ($comments as $key => $comment) {
$comments[$key]['content'] = str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),"<br/>",$comment['content']);
$coments = $this->getChildComment($comment['id_smart_blog_comment']);
if ($coments){
if (count($coments) > 0)
$comments[$i]['child_comments'] = $coments;
}
$i++;
$this->comment_child_loop++;
}
return $comments;
}
public static function getLatestComments($id_lang = null)
{
$result = array();
if ($id_lang == null) {
$id_lang = (int) Context::getContext()->language->id;
}
if (Configuration::get('smartshowhomecomments') != '' && Configuration::get('smartshowhomecomments') != null) {
$limit = Configuration::get('smartshowhomecomments');
} else {
$limit = 5;
}
$sql = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('SELECT * FROM ' . _DB_PREFIX_ . 'smart_blog_comment bc INNER JOIN
' . _DB_PREFIX_ . 'smart_blog_post_shop bps ON bc.id_post=bps.id_smart_blog_post and bps.id_shop = ' . (int) Context::getContext()->shop->id . '
WHERE bc.active= 1 ORDER BY bc.id_smart_blog_comment DESC limit 0, ' . $limit);
$i = 0;
foreach ($sql as $post) {
$result[$i]['id_smart_blog_comment'] = $post['id_smart_blog_comment'];
$result[$i]['id_parent'] = $post['id_parent'];
$result[$i]['id_customer'] = $post['id_customer'];
$result[$i]['id_post'] = $post['id_post'];
$result[$i]['name'] = $post['name'];
$result[$i]['email'] = $post['email'];
$result[$i]['website'] = $post['website'];
$result[$i]['active'] = $post['active'];
$result[$i]['created'] = $post['created'];
$result[$i]['content'] = str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),"<br/>",$post['content']);
$SmartBlogPost = new SmartBlogPost();
$result[$i]['link_rewrite'] = $SmartBlogPost->GetPostSlugById($post['id_post']);
$result[$i]['slug'] = $SmartBlogPost->GetPostSlugById($post['id_post']);
$i++;
}
return $result;
}
public static function getToltalComment($id)
{
$sql = 'SELECT id_post FROM ' . _DB_PREFIX_ . 'smart_blog_comment
WHERE id_post=' . (int) $id . '
AND active=1';
if (!$posts = Db::getInstance()->executeS($sql))
return false;
return count($posts);
}
}