Guest_Book - Version 1.0.0

Version Notes

The Guest Book Magento extension is a powerful and simultaneously simple way to build relationships with your website visitors.

Download this release

Release Info

Developer Magento Core Team
Extension Guest_Book
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

Files changed (45) hide show
  1. app/code/community/Magpleasure/Guestbook/Block/Adminhtml/Message.php +31 -0
  2. app/code/community/Magpleasure/Guestbook/Block/Adminhtml/Message/Edit.php +57 -0
  3. app/code/community/Magpleasure/Guestbook/Block/Adminhtml/Message/Edit/Form.php +34 -0
  4. app/code/community/Magpleasure/Guestbook/Block/Adminhtml/Message/Edit/Tab/General.php +132 -0
  5. app/code/community/Magpleasure/Guestbook/Block/Adminhtml/Message/Edit/Tabs.php +34 -0
  6. app/code/community/Magpleasure/Guestbook/Block/Adminhtml/Message/Grid.php +244 -0
  7. app/code/community/Magpleasure/Guestbook/Block/Adminhtml/Widget/Grid/Column/Renderer/Comment.php +37 -0
  8. app/code/community/Magpleasure/Guestbook/Block/Adminhtml/Widget/Grid/Column/Renderer/Customer.php +41 -0
  9. app/code/community/Magpleasure/Guestbook/Block/Comments.php +159 -0
  10. app/code/community/Magpleasure/Guestbook/Block/Comments/Abstract.php +41 -0
  11. app/code/community/Magpleasure/Guestbook/Block/Comments/Form.php +115 -0
  12. app/code/community/Magpleasure/Guestbook/Block/Comments/Message.php +136 -0
  13. app/code/community/Magpleasure/Guestbook/Block/Menu/Item.php +47 -0
  14. app/code/community/Magpleasure/Guestbook/Helper/Comment/Render.php +45 -0
  15. app/code/community/Magpleasure/Guestbook/Helper/Comment/Secure.php +105 -0
  16. app/code/community/Magpleasure/Guestbook/Helper/Data.php +110 -0
  17. app/code/community/Magpleasure/Guestbook/Model/Message.php +93 -0
  18. app/code/community/Magpleasure/Guestbook/Model/Mysql4/Message.php +27 -0
  19. app/code/community/Magpleasure/Guestbook/Model/Mysql4/Message/Collection.php +107 -0
  20. app/code/community/Magpleasure/Guestbook/controllers/Adminhtml/MessageController.php +278 -0
  21. app/code/community/Magpleasure/Guestbook/controllers/IndexController.php +161 -0
  22. app/code/community/Magpleasure/Guestbook/etc/adminhtml.xml +77 -0
  23. app/code/community/Magpleasure/Guestbook/etc/config.xml +182 -0
  24. app/code/community/Magpleasure/Guestbook/etc/system.xml +91 -0
  25. app/code/community/Magpleasure/Guestbook/sql/guestbook_setup/mysql4-install-1.0.php +45 -0
  26. app/design/adminhtml/default/default/layout/guestbook.xml +20 -0
  27. app/design/frontend/default/default/layout/guestbook.xml +36 -0
  28. app/design/frontend/default/default/template/guestbook/comments.phtml +59 -0
  29. app/design/frontend/default/default/template/guestbook/comments/form.phtml +110 -0
  30. app/design/frontend/default/default/template/guestbook/comments/message.phtml +43 -0
  31. app/design/frontend/default/default/template/guestbook/comments/pager.phtml +37 -0
  32. app/etc/modules/Magpleasure_Guestbook.xml +9 -0
  33. app/locale/en_US/Magpleasure_Guestbook.csv +65 -0
  34. app/locale/ru_RU/Magpleasure_Guestbook.csv +65 -0
  35. js/guestbook/comments.js +146 -0
  36. package.xml +18 -0
  37. skin/frontend/default/default/guestbook/css/styles.css +277 -0
  38. skin/frontend/default/default/guestbook/images/ajax-loader.gif +0 -0
  39. skin/frontend/default/default/guestbook/images/backgrounds-sprite.png +0 -0
  40. skin/frontend/default/default/guestbook/images/button-fill.gif +0 -0
  41. skin/frontend/default/default/guestbook/images/category-mark.png +0 -0
  42. skin/frontend/default/default/guestbook/images/commentpoint.png +0 -0
  43. skin/frontend/default/default/guestbook/images/icon-next.png +0 -0
  44. skin/frontend/default/default/guestbook/images/icon-prev.png +0 -0
  45. skin/frontend/default/default/guestbook/images/services-sprite.png +0 -0
app/code/community/Magpleasure/Guestbook/Block/Adminhtml/Message.php ADDED
@@ -0,0 +1,31 @@
1
+ <?php
2
+ /**
3
+ * MagPleasure Co.
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the EULA
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://www.magpleasure.com/LICENSE.txt
11
+ *
12
+ * @category Magpleasure
13
+ * @package Magpleasure_Guestbook
14
+ * @copyright Copyright (c) 2012 Magpleasure Co. (http://www.magpleasure.com)
15
+ * @license http://www.magpleasure.com/LICENSE.txt
16
+ */
17
+
18
+ class Magpleasure_Guestbook_Block_Adminhtml_Message extends Mage_Adminhtml_Block_Widget_Grid_Container
19
+ {
20
+
21
+ public function __construct()
22
+ {
23
+
24
+ $this->_controller = "adminhtml_message";
25
+ $this->_blockGroup = "guestbook";
26
+ $this->_headerText = Mage::helper("guestbook")->__("Comments");
27
+ parent::__construct();
28
+ $this->_removeButton('add');
29
+ }
30
+
31
+ }
app/code/community/Magpleasure/Guestbook/Block/Adminhtml/Message/Edit.php ADDED
@@ -0,0 +1,57 @@
1
+ <?php
2
+ /**
3
+ * MagPleasure Co.
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the EULA
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://www.magpleasure.com/LICENSE.txt
11
+ *
12
+ * @category Magpleasure
13
+ * @package Magpleasure_Guestbook
14
+ * @copyright Copyright (c) 2012 Magpleasure Co. (http://www.magpleasure.com)
15
+ * @license http://www.magpleasure.com/LICENSE.txt
16
+ */
17
+
18
+ class Magpleasure_Guestbook_Block_Adminhtml_Message_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
19
+ {
20
+
21
+ protected function _helper()
22
+ {
23
+ return Mage::helper('guestbook');
24
+ }
25
+
26
+ public function __construct()
27
+ {
28
+ parent::__construct();
29
+
30
+ $this->_objectId = 'id';
31
+ $this->_blockGroup = 'guestbook';
32
+ $this->_controller = 'adminhtml_message';
33
+
34
+ $this->_updateButton('save', 'label', $this->_helper()->__('Save Comment'));
35
+ $this->_updateButton('delete', 'label', $this->_helper()->__('Delete Comment'));
36
+
37
+ $this->_addButton('saveandcontinue', array(
38
+ 'label' => Mage::helper('adminhtml')->__('Save And Continue Edit'),
39
+ 'onclick' => 'saveAndContinueEdit()',
40
+ 'class' => 'save',
41
+ ), -100);
42
+
43
+ $this->_formScripts[] = "
44
+ function saveAndContinueEdit(){
45
+ editForm.submit($('edit_form').action+'back/edit/');
46
+ }
47
+ ";
48
+ }
49
+
50
+ public function getHeaderText()
51
+ {
52
+ if (Mage::registry('current_comment') && Mage::registry('current_comment')->getId()) {
53
+ return $this->_helper()->__("Edit Comment of '%s'", $this->escapeHtml(Mage::registry('current_comment')->getName()));
54
+ }
55
+ return false;
56
+ }
57
+ }
app/code/community/Magpleasure/Guestbook/Block/Adminhtml/Message/Edit/Form.php ADDED
@@ -0,0 +1,34 @@
1
+ <?php
2
+ /**
3
+ * MagPleasure Co.
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the EULA
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://www.magpleasure.com/LICENSE.txt
11
+ *
12
+ * @category Magpleasure
13
+ * @package Magpleasure_Guestbook
14
+ * @copyright Copyright (c) 2012 Magpleasure Co. (http://www.magpleasure.com)
15
+ * @license http://www.magpleasure.com/LICENSE.txt
16
+ */
17
+
18
+ class Magpleasure_Guestbook_Block_Adminhtml_Message_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
19
+ {
20
+ protected function _prepareForm()
21
+ {
22
+ $form = new Varien_Data_Form(array(
23
+ 'id' => 'edit_form',
24
+ 'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
25
+ 'method' => 'post',
26
+ 'enctype' => 'multipart/form-data'
27
+ )
28
+ );
29
+
30
+ $form->setUseContainer(true);
31
+ $this->setForm($form);
32
+ return parent::_prepareForm();
33
+ }
34
+ }
app/code/community/Magpleasure/Guestbook/Block/Adminhtml/Message/Edit/Tab/General.php ADDED
@@ -0,0 +1,132 @@
1
+ <?php
2
+ /**
3
+ * MagPleasure Co.
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the EULA
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://www.magpleasure.com/LICENSE.txt
11
+ *
12
+ * @category Magpleasure
13
+ * @package Magpleasure_Guestbook
14
+ * @copyright Copyright (c) 2012 Magpleasure Co. (http://www.magpleasure.com)
15
+ * @license http://www.magpleasure.com/LICENSE.txt
16
+ */
17
+
18
+ class Magpleasure_Guestbook_Block_Adminhtml_Message_Edit_Tab_General extends Mage_Adminhtml_Block_Widget_Form
19
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
20
+ {
21
+
22
+ protected function _helper()
23
+ {
24
+ return Mage::helper('guestbook');
25
+ }
26
+
27
+ protected function _prepareForm()
28
+ {
29
+ $form = new Varien_Data_Form();
30
+ $this->setForm($form);
31
+ $fieldset = $form->addFieldset('guestbook_form', array('legend' => $this->_helper()->__('General')));
32
+
33
+ $fieldset->addField('name', 'text', array(
34
+ 'label' => $this->_helper()->__('Name'),
35
+ 'class' => 'required-entry',
36
+ 'required' => true,
37
+ 'name' => 'name',
38
+ ));
39
+
40
+ $fieldset->addField('email', 'text', array(
41
+ 'label' => $this->_helper()->__('Email'),
42
+ 'class' => 'required-entry',
43
+ 'required' => true,
44
+ 'name' => 'email',
45
+ ));
46
+
47
+ $values = Mage::registry('current_comment')->getData();
48
+ if (!isset($values['reply_to'])){
49
+ $fieldset->addField('subject', 'text', array(
50
+ 'label' => $this->_helper()->__('Subject'),
51
+ 'required' => true,
52
+ 'class' => 'required-entry',
53
+ 'name' => 'subject',
54
+ ));
55
+ }
56
+
57
+ $fieldset->addField('message', 'textarea', array(
58
+ 'label' => $this->_helper()->__('Comment'),
59
+ 'class' => 'required-entry',
60
+ 'required' => true,
61
+ 'name' => 'message',
62
+ ));
63
+
64
+ $comment = Mage::getSingleton('guestbook/message');
65
+
66
+ $fieldset->addField('status', 'select',
67
+ array(
68
+ 'name' => 'status',
69
+ 'label' => $this->_helper()->__('Status'),
70
+ 'values' => $comment->toOptionArray(),
71
+ ));
72
+
73
+ if (!Mage::app()->isSingleStoreMode()){
74
+ $fieldset->addField('store_id', 'select',
75
+ array(
76
+ 'label' => $this->_helper()->__('Posted from'),
77
+ 'required' => true,
78
+ 'name' => 'store_id',
79
+ 'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm()
80
+ ));
81
+ }
82
+
83
+ if (Mage::getSingleton('adminhtml/session')->getPostData()) {
84
+ $form->setValues(Mage::getSingleton('adminhtml/session')->getPostData());
85
+ Mage::getSingleton('adminhtml/session')->getPostData(null);
86
+ } elseif (Mage::registry('current_comment')) {
87
+ $form->setValues(Mage::registry('current_comment')->getData());
88
+ }
89
+
90
+ return parent::_prepareForm();
91
+ }
92
+
93
+ /**
94
+ * Return Tab label
95
+ *
96
+ * @return string
97
+ */
98
+ public function getTabLabel()
99
+ {
100
+ return $this->_helper()->__("General");
101
+ }
102
+
103
+ /**
104
+ * Return Tab title
105
+ *
106
+ * @return string
107
+ */
108
+ public function getTabTitle()
109
+ {
110
+ return $this->_helper()->__("General");
111
+ }
112
+
113
+ /**
114
+ * Can show tab in tabs
115
+ *
116
+ * @return boolean
117
+ */
118
+ public function canShowTab()
119
+ {
120
+ return true;
121
+ }
122
+
123
+ /**
124
+ * Tab is hidden
125
+ *
126
+ * @return boolean
127
+ */
128
+ public function isHidden()
129
+ {
130
+ return false;
131
+ }
132
+ }
app/code/community/Magpleasure/Guestbook/Block/Adminhtml/Message/Edit/Tabs.php ADDED
@@ -0,0 +1,34 @@
1
+ <?php
2
+ /**
3
+ * MagPleasure Co.
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the EULA
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://www.magpleasure.com/LICENSE.txt
11
+ *
12
+ * @category Magpleasure
13
+ * @package Magpleasure_Guestbook
14
+ * @copyright Copyright (c) 2012 Magpleasure Co. (http://www.magpleasure.com)
15
+ * @license http://www.magpleasure.com/LICENSE.txt
16
+ */
17
+
18
+ class Magpleasure_Guestbook_Block_Adminhtml_Message_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
19
+ {
20
+
21
+ protected function _helper()
22
+ {
23
+ return Mage::helper('guestbook');
24
+ }
25
+
26
+ public function __construct()
27
+ {
28
+ parent::__construct();
29
+ $this->setId('guestbook_comments');
30
+ $this->setDestElementId('edit_form');
31
+ $this->setTitle($this->_helper()->__('Comment Information'));
32
+ }
33
+
34
+ }
app/code/community/Magpleasure/Guestbook/Block/Adminhtml/Message/Grid.php ADDED
@@ -0,0 +1,244 @@
1
+ <?php
2
+ /**
3
+ * MagPleasure Co.
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the EULA
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://www.magpleasure.com/LICENSE.txt
11
+ *
12
+ * @category Magpleasure
13
+ * @package Magpleasure_Guestbook
14
+ * @copyright Copyright (c) 2012 Magpleasure Co. (http://www.magpleasure.com)
15
+ * @license http://www.magpleasure.com/LICENSE.txt
16
+ */
17
+
18
+ class Magpleasure_Guestbook_Block_Adminhtml_Message_Grid extends Mage_Adminhtml_Block_Widget_Grid
19
+ {
20
+
21
+ /**
22
+ * Helper
23
+ * @return Magpleasure_Guestbook_Helper_Data
24
+ */
25
+ protected function _helper()
26
+ {
27
+ return Mage::helper('guestbook');
28
+ }
29
+
30
+
31
+ public function __construct()
32
+ {
33
+ parent::__construct();
34
+ $this->setId("guestbookGrid");
35
+ $this->setDefaultSort("message_id");
36
+ $this->setDefaultDir("DESC");
37
+ $this->setUseAjax(true);
38
+ $this->setSaveParametersInSession(true);
39
+ }
40
+
41
+ protected function _prepareCollection()
42
+ {
43
+ $collection = Mage::getModel("guestbook/message")->getCollection();
44
+ $collection->addReplyTo();
45
+ $this->setCollection($collection);
46
+ return parent::_prepareCollection();
47
+ }
48
+
49
+ protected function _prepareColumns()
50
+ {
51
+ $this->addColumn('message_id', array(
52
+ 'header' => $this->_helper()->__('ID'),
53
+ 'align' => 'right',
54
+ 'width' => '50px',
55
+ 'index' => 'message_id',
56
+ ));
57
+
58
+ $this->addColumn('reply_to_text', array(
59
+ 'header' => $this->_helper()->__('Reply To'),
60
+ 'align' => 'left',
61
+ 'width' => '200px',
62
+ 'index' => 'reply_to_text',
63
+ 'renderer' => 'Magpleasure_Guestbook_Block_Adminhtml_Widget_Grid_Column_Renderer_Comment',
64
+ 'filter_condition_callback' => array($this, '_filterReplyToCondition'),
65
+ ));
66
+
67
+ $this->addColumn('message', array(
68
+ 'header' => $this->_helper()->__('Comment'),
69
+ 'align' => 'left',
70
+ 'width' => '200px',
71
+ 'renderer' => 'Magpleasure_Guestbook_Block_Adminhtml_Widget_Grid_Column_Renderer_Comment',
72
+ 'index' => 'message',
73
+ 'filter_condition_callback' => array($this, '_filterMessageCondition'),
74
+ ));
75
+
76
+ $this->addColumn('name', array(
77
+ 'header' => $this->_helper()->__('Name'),
78
+ 'align' => 'left',
79
+ 'index' => 'name',
80
+ ));
81
+
82
+ $this->addColumn('email', array(
83
+ 'header' => $this->_helper()->__('Email'),
84
+ 'align' => 'left',
85
+ 'index' => 'email',
86
+ ));
87
+
88
+ $this->addColumn('customer_id', array(
89
+ 'header' => $this->_helper()->__('Customer'),
90
+ 'align' => 'left',
91
+ 'index' => 'customer_id',
92
+ 'filter' => false,
93
+ 'renderer' => 'Magpleasure_Guestbook_Block_Adminhtml_Widget_Grid_Column_Renderer_Customer',
94
+ ));
95
+
96
+ $this->addColumn('status', array(
97
+ 'header' => $this->_helper()->__('Status'),
98
+ 'align' => 'left',
99
+ 'width' => '80px',
100
+ 'index' => 'status',
101
+ 'type' => 'options',
102
+ 'options' => Mage::getModel('guestbook/message')->getOptionsArray(),
103
+ 'filter_condition_callback' => array($this, '_filterStatus'),
104
+ ));
105
+
106
+ if(!Mage::app()->isSingleStoreMode()){
107
+ $this->addColumn('store_id', array(
108
+ 'header' => $this->__('Store View'),
109
+ 'index' => 'store_id',
110
+ 'sortable' => true,
111
+ 'width' => '120px',
112
+ 'type' => 'store',
113
+ 'store_view' => true,
114
+ 'renderer' => 'Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Store',
115
+ ));
116
+ }
117
+
118
+ $this->addColumn('created_at', array(
119
+ 'header' => $this->_helper()->__('Created At'),
120
+ 'index' => 'created_at',
121
+ 'type' => 'datetime',
122
+ 'width' => '140px',
123
+ ));
124
+
125
+ $this->addColumn('updated_at', array(
126
+ 'header' => $this->_helper()->__('Updated At'),
127
+ 'index' => 'updated_at',
128
+ 'type' => 'datetime',
129
+ 'width' => '140px',
130
+ ));
131
+
132
+ $this->addColumn('action',
133
+ array(
134
+ 'header' => $this->_helper()->__('Action'),
135
+ 'width' => '100',
136
+ 'type' => 'action',
137
+ 'getter' => 'getId',
138
+ 'actions' => array(
139
+ array(
140
+ 'caption' => $this->_helper()->__('View'),
141
+ 'url' => array('base' => '*/*/view'),
142
+ 'field' => 'id'
143
+ ),
144
+ array(
145
+ 'caption' => $this->_helper()->__('Approve'),
146
+ 'url' => array('base' => '*/*/approve'),
147
+ 'field' => 'id'
148
+ ),
149
+ array(
150
+ 'caption' => $this->_helper()->__('Reject'),
151
+ 'url' => array('base' => '*/*/reject'),
152
+ 'field' => 'id'
153
+ ),
154
+ ),
155
+ 'filter' => false,
156
+ 'sortable' => false,
157
+ 'index' => 'stores',
158
+ 'is_system' => true,
159
+ ));
160
+
161
+ return parent::_prepareColumns();
162
+ }
163
+
164
+ protected function _prepareMassaction()
165
+ {
166
+ $this->setMassactionIdField('message_id');
167
+ $this->getMassactionBlock()->setFormFieldName('comments');
168
+
169
+ $statuses = Mage::getModel('guestbook/message')->toOptionArray();
170
+
171
+ array_unshift($statuses, array('label' => '', 'value' => ''));
172
+ $this->getMassactionBlock()->addItem('status', array(
173
+ 'label' => $this->_helper()->__('Change status'),
174
+ 'url' => $this->getUrl('*/*/massStatus', array('_current' => true)),
175
+ 'additional' => array(
176
+ 'visibility' => array(
177
+ 'name' => 'status',
178
+ 'type' => 'select',
179
+ 'class' => 'required-entry',
180
+ 'label' => $this->_helper()->__('Status'),
181
+ 'values' => $statuses
182
+ )
183
+ )
184
+ ));
185
+
186
+ $this->getMassactionBlock()->addItem('delete', array(
187
+ 'label' => $this->_helper()->__('Delete'),
188
+ 'url' => $this->getUrl('*/*/massDelete'),
189
+ 'confirm' => $this->_helper()->__('Are you sure?')
190
+ ));
191
+ return $this;
192
+ }
193
+
194
+ public function getRowUrl($row)
195
+ {
196
+ return $this->getUrl('*/*/edit', array('id' => $row->getId()));
197
+ }
198
+
199
+ public function getGridUrl()
200
+ {
201
+ return $this->getUrl('*/*/grid');
202
+ }
203
+
204
+ protected function _filterReplyToCondition($collection, $column)
205
+ {
206
+ if (!$value = $column->getFilter()->getValue()) {
207
+ return;
208
+ }
209
+ $this->getCollection()->addReplyToTextFilter($value);
210
+ }
211
+
212
+ protected function _filterMessageCondition($collection, $column)
213
+ {
214
+ if (!$value = $column->getFilter()->getValue()) {
215
+ return;
216
+ }
217
+ $this->getCollection()->addMessageTextFilter($value);
218
+ }
219
+
220
+ protected function _filterStatus($collection, $column)
221
+ {
222
+ if (!$value = $column->getFilter()->getValue()) {
223
+ return;
224
+ }
225
+ $this->getCollection()->addStatusFilter($value);
226
+ }
227
+
228
+ protected function _addColumnFilterToCollection($column)
229
+ {
230
+ if ($this->getCollection()) {
231
+ $field = ( $column->getFilterIndex() ) ? $column->getFilterIndex() : $column->getIndex();
232
+ if ($column->getFilterConditionCallback()) {
233
+ call_user_func($column->getFilterConditionCallback(), $this->getCollection(), $column);
234
+ } else {
235
+ $cond = $column->getFilter()->getCondition();
236
+ if ($field && isset($cond)) {
237
+ $this->getCollection()->addFieldToFilter("main_table.".$field , $cond);
238
+ }
239
+ }
240
+ }
241
+ return $this;
242
+ }
243
+
244
+ }
app/code/community/Magpleasure/Guestbook/Block/Adminhtml/Widget/Grid/Column/Renderer/Comment.php ADDED
@@ -0,0 +1,37 @@
1
+ <?php
2
+ /**
3
+ * MagPleasure Co.
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the EULA
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://www.magpleasure.com/LICENSE.txt
11
+ *
12
+ * @category Magpleasure
13
+ * @package Magpleasure_Guestbook
14
+ * @copyright Copyright (c) 2012 Magpleasure Co. (http://www.magpleasure.com)
15
+ * @license http://www.magpleasure.com/LICENSE.txt
16
+ */
17
+
18
+
19
+ class Magpleasure_Guestbook_Block_Adminhtml_Widget_Grid_Column_Renderer_Comment extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
20
+ {
21
+ /**
22
+ * Renders grid column
23
+ *
24
+ * @param Varien_Object $row
25
+ * @return string
26
+ */
27
+ public function render(Varien_Object $row)
28
+ {
29
+ $content = $this->_getValue($row);
30
+ if ($content){
31
+ /** @var Magpleasure_Guestbook_Helper_Data $helper */
32
+ $helper = Mage::helper('guestbook');
33
+ return $helper->_render()->render($content, 200);
34
+ }
35
+ return parent::render($row);
36
+ }
37
+ }
app/code/community/Magpleasure/Guestbook/Block/Adminhtml/Widget/Grid/Column/Renderer/Customer.php ADDED
@@ -0,0 +1,41 @@
1
+ <?php
2
+ /**
3
+ * MagPleasure Co.
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the EULA
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://www.magpleasure.com/LICENSE.txt
11
+ *
12
+ * @category Magpleasure
13
+ * @package Magpleasure_Guestbook
14
+ * @copyright Copyright (c) 2012 Magpleasure Co. (http://www.magpleasure.com)
15
+ * @license http://www.magpleasure.com/LICENSE.txt
16
+ */
17
+
18
+
19
+ class Magpleasure_Guestbook_Block_Adminhtml_Widget_Grid_Column_Renderer_Customer extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
20
+ {
21
+ /**
22
+ * Renders grid column
23
+ *
24
+ * @param Varien_Object $row
25
+ * @return string
26
+ */
27
+ public function render(Varien_Object $row)
28
+ {
29
+ $customerId = $this->_getValue($row);
30
+ if ($customerId) {
31
+ $html = "";
32
+ /** @var Mage_Customer_Model_Customer $customer */
33
+ $customer = Mage::getModel('customer/customer')->load($customerId);
34
+ $name = $customer->getName();
35
+ $url = $this->getUrl('adminhtml/customer/edit', array('id'=>$customerId));
36
+ $html .= "<a href=\"{$url}\" target=\"_blank\">{$name}</a>";
37
+ return $html;
38
+ }
39
+ return parent::render($row);
40
+ }
41
+ }
app/code/community/Magpleasure/Guestbook/Block/Comments.php ADDED
@@ -0,0 +1,159 @@
1
+ <?php
2
+ /**
3
+ * MagPleasure Co.
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the EULA
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://www.magpleasure.com/LICENSE.txt
11
+ *
12
+ * @category Magpleasure
13
+ * @package Magpleasure_Guestbook
14
+ * @copyright Copyright (c) 2012 Magpleasure Co. (http://www.magpleasure.com)
15
+ * @license http://www.magpleasure.com/LICENSE.txt
16
+ */
17
+
18
+ class Magpleasure_Guestbook_Block_Comments extends Mage_Core_Block_Template
19
+ {
20
+ protected $_collection;
21
+
22
+ protected function _construct()
23
+ {
24
+ parent::_construct();
25
+ $this->setTemplate("guestbook/comments.phtml");
26
+ }
27
+
28
+ protected function _prepareLayout()
29
+ {
30
+ parent::_prepareLayout();
31
+ $head = $this->getLayout()->getBlock("head");
32
+ if ($head){
33
+ $head->setTitle($this->_helper()->getMenuLabel());
34
+ }
35
+
36
+ $breadcrumbs = $this->getLayout()->getBlock("breadcrumbs");
37
+ if ($breadcrumbs){
38
+
39
+ $breadcrumbs->addCrumb("home", array(
40
+ "label" => $this->__("Home"),
41
+ "title" => $this->__("Home"),
42
+ "link" => Mage::getBaseUrl('web')
43
+ ));
44
+
45
+ $breadcrumbs->addCrumb("guestbook", array(
46
+ "label" => $this->_helper()->getMenuLabel(),
47
+ "title" => $this->_helper()->getMenuLabel()
48
+ ));
49
+ }
50
+ }
51
+
52
+ /**
53
+ * Customer Session
54
+ *
55
+ * @return Mage_Customer_Model_Session
56
+ */
57
+ public function getCustomerSession()
58
+ {
59
+ return Mage::getSingleton('customer/session');
60
+ }
61
+
62
+ /**
63
+ * Helper
64
+ *
65
+ * @return Magpleasure_Guestbook_Helper_Data
66
+ */
67
+ public function _helper()
68
+ {
69
+ return Mage::helper('guestbook');
70
+ }
71
+
72
+ /**
73
+ * Core
74
+ *
75
+ * @return Mage_Core_Helper_Data
76
+ */
77
+ public function _core()
78
+ {
79
+ return Mage::helper('core');
80
+ }
81
+
82
+ public function getHeader()
83
+ {
84
+ return $this->_helper()->getMenuLabel();
85
+ }
86
+
87
+ protected function _beforeToHtml()
88
+ {
89
+ $this->getToolbar()
90
+ ->setPageVarName('p')
91
+ ->setLimit($this->_helper()->getCommentsPerPage())
92
+ ->setTemplate('guestbook/comments/pager.phtml')
93
+ ->setCollection($this->getCollection())
94
+ ;
95
+ parent::_beforeToHtml();
96
+ }
97
+
98
+ public function getCollection()
99
+ {
100
+ if (!$this->_collection){
101
+ /** @var Magpleasure_Guestbook_Model_Mysql4_Message_Collection $comments */
102
+ $comments = Mage::getModel('guestbook/message')->getCollection();
103
+
104
+ if (!Mage::app()->isSingleStoreMode()){
105
+ $comments->addStoreFilter(Mage::app()->getStore()->getId());
106
+ }
107
+
108
+ $comments
109
+ ->addActiveFilter($this->_helper()->getCommentsAutoapprove() ? null : $this->getCustomerSession()->getSessionId() )
110
+ ;
111
+
112
+ $comments
113
+ ->setDateOrder()
114
+ ->setNotReplies()
115
+ ;
116
+
117
+ $this->_collection = $comments;
118
+ }
119
+ return $this->_collection;
120
+ }
121
+
122
+ public function getMessageHtml(Magpleasure_Guestbook_Model_Message $message)
123
+ {
124
+ $messageBlock = $this->getLayout()->createBlock('guestbook/comments_message');
125
+ if ($messageBlock){
126
+ $messageBlock->setMessage($message);
127
+ return $messageBlock->toHtml();
128
+ }
129
+ return false;
130
+ }
131
+
132
+ public function getFormUrl()
133
+ {
134
+ return $this->getUrl('guestbook/index/form', array(
135
+ 'reply_to'=>'{{reply_to}}',
136
+ ));
137
+ }
138
+
139
+ public function getPostUrl()
140
+ {
141
+ return $this->getUrl('guestbook/index/postForm', array(
142
+ 'reply_to'=>'{{reply_to}}',
143
+ ));
144
+ }
145
+
146
+ /**
147
+ * @return Mage_Page_Block_Html_Pager
148
+ */
149
+ public function getToolbar()
150
+ {
151
+ return $this->getLayout()->getBlock('guestbook_list_toolbar');
152
+ }
153
+
154
+ public function getToolbarHtml()
155
+ {
156
+ return $this->getToolbar()->toHtml();
157
+ }
158
+
159
+ }
app/code/community/Magpleasure/Guestbook/Block/Comments/Abstract.php ADDED
@@ -0,0 +1,41 @@
1
+ <?php
2
+ /**
3
+ * MagPleasure Co.
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the EULA
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://www.magpleasure.com/LICENSE.txt
11
+ *
12
+ * @category Magpleasure
13
+ * @package Magpleasure_Guestbook
14
+ * @copyright Copyright (c) 2012 Magpleasure Co. (http://www.magpleasure.com)
15
+ * @license http://www.magpleasure.com/LICENSE.txt
16
+ */
17
+
18
+ class Magpleasure_Guestbook_Block_Comments_Abstract extends Mage_Core_Block_Template
19
+ {
20
+
21
+ /**
22
+ * Helper
23
+ *
24
+ * @return Magpleasure_Guestbook_Helper_Data
25
+ */
26
+ public function _helper()
27
+ {
28
+ return Mage::helper('guestbook');
29
+ }
30
+
31
+ /**
32
+ * Customer Session
33
+ *
34
+ * @return Mage_Customer_Model_Session
35
+ */
36
+ public function getCustomerSession()
37
+ {
38
+ return Mage::getSingleton('customer/session');
39
+ }
40
+
41
+ }
app/code/community/Magpleasure/Guestbook/Block/Comments/Form.php ADDED
@@ -0,0 +1,115 @@
1
+ <?php
2
+ /**
3
+ * MagPleasure Co.
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the EULA
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://www.magpleasure.com/LICENSE.txt
11
+ *
12
+ * @category Magpleasure
13
+ * @package Magpleasure_Guestbook
14
+ * @copyright Copyright (c) 2012 Magpleasure Co. (http://www.magpleasure.com)
15
+ * @license http://www.magpleasure.com/LICENSE.txt
16
+ */
17
+
18
+
19
+ class Magpleasure_Guestbook_Block_Comments_Form extends Magpleasure_Guestbook_Block_Comments_Abstract
20
+ {
21
+ protected $_collection;
22
+
23
+ protected $_replyTo;
24
+ protected $_formData = array();
25
+
26
+ protected function _construct()
27
+ {
28
+ parent::_construct();
29
+ $this->setTemplate("guestbook/comments/form.phtml");
30
+ }
31
+
32
+ public function setReplyTo($value)
33
+ {
34
+ $this->_replyTo = $value;
35
+ }
36
+
37
+ public function canPostComments()
38
+ {
39
+ return $this->_helper()->getCommentsAllowGuests();
40
+ }
41
+
42
+ /**
43
+ * Comment
44
+ *
45
+ * @return Magpleasure_Blog_Model_Comment
46
+ */
47
+ public function getReplyTo()
48
+ {
49
+ return $this->_replyTo ? $this->_replyTo->getId() : 0;
50
+ }
51
+
52
+ public function isReply()
53
+ {
54
+ return !!$this->getReplyTo();
55
+ }
56
+
57
+ public function canPost()
58
+ {
59
+ return $this->_helper()->getCommentsAllowGuests() || $this->isLoggedId();
60
+ }
61
+
62
+ public function setFormData(array $data)
63
+ {
64
+ $this->_formData = $data;
65
+ }
66
+
67
+ public function getFormData()
68
+ {
69
+ return new Varien_Object($this->_formData);
70
+ }
71
+
72
+ public function getRegisterUrl()
73
+ {
74
+ return $this->getUrl('customer/account/create');
75
+ }
76
+
77
+ public function getLoginUrl()
78
+ {
79
+ return $this->getUrl('customer/account/login');
80
+ }
81
+
82
+ public function isLoggedId()
83
+ {
84
+ return $this->getCustomerSession()->isLoggedIn();
85
+ }
86
+
87
+ public function getCustomerId()
88
+ {
89
+ return $this->getCustomerSession()->getCustomerId();
90
+ }
91
+
92
+ public function getCustomerName()
93
+ {
94
+ return $this->isLoggedId() ? $this->getCustomerSession()->getCustomer()->getName() : '';
95
+ }
96
+
97
+ public function getCustomerEmail()
98
+ {
99
+ return $this->getCustomerSession()->getCustomer()->getEmail();
100
+ }
101
+
102
+ public function getSessionId()
103
+ {
104
+ return $this->getCustomerSession()->getSessionId();
105
+ }
106
+
107
+ public function getMessageBlockHtml()
108
+ {
109
+ $block = $this->getMessagesBlock();
110
+ if ($block){
111
+ $block->setMessages($this->getCustomerSession()->getMessages(true));
112
+ }
113
+ return $block->toHtml();
114
+ }
115
+ }
app/code/community/Magpleasure/Guestbook/Block/Comments/Message.php ADDED
@@ -0,0 +1,136 @@
1
+ <?php
2
+ /**
3
+ * MagPleasure Co.
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the EULA
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://www.magpleasure.com/LICENSE.txt
11
+ *
12
+ * @category Magpleasure
13
+ * @package Magpleasure_Guestbook
14
+ * @copyright Copyright (c) 2012 Magpleasure Co. (http://www.magpleasure.com)
15
+ * @license http://www.magpleasure.com/LICENSE.txt
16
+ */
17
+
18
+
19
+ class Magpleasure_Guestbook_Block_Comments_Message extends Magpleasure_Guestbook_Block_Comments_Abstract
20
+ {
21
+ protected $_collection;
22
+
23
+ protected function _construct()
24
+ {
25
+ parent::_construct();
26
+ $this->setTemplate("guestbook/comments/message.phtml");
27
+ }
28
+
29
+ /**
30
+ * Comment
31
+ *
32
+ * @return Magpleasure_Blog_Model_Comment
33
+ */
34
+ public function getMessage()
35
+ {
36
+ return $this->getData('message');
37
+ }
38
+
39
+ public function getContent()
40
+ {
41
+ return $this->_helper()->_render()->render($this->getMessage()->getMessage());
42
+ }
43
+
44
+ public function getMessageId()
45
+ {
46
+ return $this->getMessage()->getId();
47
+ }
48
+
49
+ public function getAuthor()
50
+ {
51
+ return $this->getMessage()->getName();
52
+ }
53
+
54
+ public function getDate()
55
+ {
56
+ return $this->_helper()->renderDate($this->getMessage()->getCreatedAt());
57
+ }
58
+
59
+ public function getTime()
60
+ {
61
+ return $this->_helper()->renderTime($this->getMessage()->getCreatedAt());
62
+ }
63
+
64
+ public function getRepliesCollection()
65
+ {
66
+ if (!$this->_collection){
67
+ /** @var Magpleasure_Guestbook_Model_Mysql4_Message_Collection $messages */
68
+ $messages = Mage::getModel('guestbook/message')->getCollection();
69
+
70
+ if (!Mage::app()->isSingleStoreMode()){
71
+ $messages->addStoreFilter(Mage::app()->getStore()->getId());
72
+ }
73
+
74
+ $messages
75
+ ->addActiveFilter($this->_helper()->getCommentsAutoapprove() ? null : $this->getCustomerSession()->getSessionId() )
76
+ ;
77
+
78
+ $messages
79
+ ->setDateOrder()
80
+ ->setReplyToFilter($this->getMessage()->getId())
81
+ ;
82
+
83
+ $this->_collection = $messages;
84
+ }
85
+ return $this->_collection;
86
+ }
87
+
88
+ /**
89
+ * Replies Html
90
+ *
91
+ * @return string
92
+ */
93
+ public function getRepliesHtml()
94
+ {
95
+ $html = "";
96
+ foreach ($this->getRepliesCollection() as $message){
97
+ $messageBlock = $this->getLayout()->createBlock('guestbook/comments_message');
98
+ if ($messageBlock){
99
+ $messageBlock->setMessage($message);
100
+ $html .= $messageBlock->toHtml();
101
+ }
102
+ }
103
+ return $html;
104
+ }
105
+
106
+ public function isReply()
107
+ {
108
+ if ($this->getIsAjax()){
109
+ return false;
110
+ }
111
+ if ($this->getMessage()->getReplyTo()){
112
+ $flag = 'guestbook_reply_'.$this->getMessage()->getReplyTo();
113
+ if (!Mage::registry($flag)){
114
+ Mage::register($flag, true);
115
+ return true;
116
+ }
117
+ }
118
+ return false;
119
+ }
120
+
121
+ public function getCountCode()
122
+ {
123
+ return $this->getCommentsCount() ? $this->__("%s comments", $this->getCommentsCount()) : $this->__("No comments");
124
+ }
125
+
126
+ public function getNeedApproveMessage()
127
+ {
128
+ return ($this->getMessage()->getStatus() == Magpleasure_Guestbook_Model_Message::STATUS_PENDING);
129
+ }
130
+
131
+ public function getSubject()
132
+ {
133
+ return $this->getMessage()->getSubject();
134
+ }
135
+
136
+ }
app/code/community/Magpleasure/Guestbook/Block/Menu/Item.php ADDED
@@ -0,0 +1,47 @@
1
+ <?php
2
+ /**
3
+ * MagPleasure Co.
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the EULA
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://www.magpleasure.com/LICENSE.txt
11
+ *
12
+ * @category Magpleasure
13
+ * @package Magpleasure_Guestbook
14
+ * @copyright Copyright (c) 2012 Magpleasure Co. (http://www.magpleasure.com)
15
+ * @license http://www.magpleasure.com/LICENSE.txt
16
+ */
17
+ class Magpleasure_Guestbook_Block_Menu_Item extends Mage_Core_Block_Abstract
18
+ {
19
+ /**
20
+ * Helper
21
+ * @return Magpleasure_Guestbook_Helper_Data
22
+ */
23
+ protected function _helper()
24
+ {
25
+ return Mage::helper('guestbook');
26
+ }
27
+
28
+ public function addGuestbookLink()
29
+ {
30
+ /** @var Mage_Page_Block_Template_Links $parentBlock */
31
+ $parentBlock = $this->getParentBlock();
32
+ if ($parentBlock && $this->_helper()->getMenuEnabled()) {
33
+ $parentBlock->addLink(
34
+ $this->_helper()->getMenuLabel(),
35
+ $this->getUrl('guestbook'),
36
+ $this->_helper()->getMenuLabel(),
37
+ false,
38
+ array(),
39
+ $this->_helper()->getMenuPosition(),
40
+ 'class="mp-guestbook"',
41
+ 'class="top-link-guestbook"'
42
+ );
43
+ }
44
+ return $this;
45
+ }
46
+
47
+ }
app/code/community/Magpleasure/Guestbook/Helper/Comment/Render.php ADDED
@@ -0,0 +1,45 @@
1
+ <?php
2
+ /**
3
+ * MagPleasure Co.
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the EULA
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://www.magpleasure.com/LICENSE.txt
11
+ *
12
+ * @category Magpleasure
13
+ * @package Magpleasure_Guestbook
14
+ * @copyright Copyright (c) 2012 Magpleasure Co. (http://www.magpleasure.com)
15
+ * @license http://www.magpleasure.com/LICENSE.txt
16
+ */
17
+
18
+ class Magpleasure_Guestbook_Helper_Comment_Render extends Mage_Core_Helper_Data
19
+ {
20
+
21
+ public function render($content, $limit = false)
22
+ {
23
+ if ($limit){
24
+ if (strlen($content) > $limit){
25
+ $content = substr($content, 0, $limit);
26
+ if (strpos($content, " ") !== false){
27
+ $cuts = explode(" ", $content);
28
+ if (count($cuts) && count($cuts) > 1){
29
+ unset($cuts[count($cuts) - 1]);
30
+ $content = implode(" ", $cuts)."...";
31
+ }
32
+ }
33
+ }
34
+ }
35
+
36
+ preg_match_all('#\bhttps?://[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/))#', $content, $match);
37
+ foreach ($match[0] as $url){
38
+ $content = str_replace($url, "<a href=\"{$url}\" target=\"_blank\">{$url}</a>", $content);
39
+ }
40
+ return nl2br($content);
41
+ }
42
+
43
+
44
+
45
+ }
app/code/community/Magpleasure/Guestbook/Helper/Comment/Secure.php ADDED
@@ -0,0 +1,105 @@
1
+ <?php
2
+ /**
3
+ * MagPleasure Co.
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the EULA
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://www.magpleasure.com/LICENSE.txt
11
+ *
12
+ * @category Magpleasure
13
+ * @package Magpleasure_Guestbook
14
+ * @copyright Copyright (c) 2012 Magpleasure Co. (http://www.magpleasure.com)
15
+ * @license http://www.magpleasure.com/LICENSE.txt
16
+ */
17
+
18
+ class Magpleasure_Guestbook_Helper_Comment_Secure extends Mage_Core_Helper_Data
19
+ {
20
+ const SESSSION_KEY = 'guestbook_customer_keys';
21
+
22
+ /**
23
+ * Helper
24
+ *
25
+ * @return Magpleasure_Guestbook_Helper_Data
26
+ */
27
+ public function _helper()
28
+ {
29
+ return Mage::helper('guestbook');
30
+ }
31
+
32
+ /**
33
+ * Customer Session
34
+ *
35
+ * @return Mage_Customer_Model_Session
36
+ */
37
+ public function getCustomerSession()
38
+ {
39
+ return Mage::getSingleton('customer/session');
40
+ }
41
+
42
+ protected function _getMd5Hash()
43
+ {
44
+ return md5(time() + rand(1, 1000));
45
+ }
46
+
47
+ protected function _save($key, $values)
48
+ {
49
+ $session = $this->getCustomerSession();
50
+ $keys = $session->getData(self::SESSSION_KEY);
51
+ if (!$keys || !is_array($keys)){
52
+ $keys = array();
53
+ }
54
+ $keys[$key] = $values;
55
+ $session->setData(self::SESSSION_KEY, $keys);
56
+ }
57
+
58
+ protected function _load($key)
59
+ {
60
+ $session = $this->getCustomerSession();
61
+ $keys = $session->getData(self::SESSSION_KEY);
62
+ if ($keys && is_array($keys)){
63
+ if (isset($keys[$key])){
64
+ $result = $keys[$key];
65
+ unset($keys[$key]);
66
+ return $result;
67
+ }
68
+ }
69
+ return false;
70
+ }
71
+
72
+ public function getSecureCode($replyTo)
73
+ {
74
+ $key = $this->_getMd5Hash();
75
+ $data = array(
76
+ 'reply_to' => $replyTo,
77
+ );
78
+ $data = serialize($data);
79
+ $this->_save($key, $data);
80
+ return $key;
81
+ }
82
+
83
+ public function validate($secure, $replyTo)
84
+ {
85
+ if (!$this->_helper()->getCommentsAllowGuests() && !$this->getCustomerSession()->isLoggedIn()){
86
+ return false;
87
+ }
88
+ $data = $this->_load($secure);
89
+ if ($data){
90
+ try {
91
+ $data = unserialize($data);
92
+ if (is_array($data)){
93
+ if (isset($data['reply_to'])){
94
+ return ($data['reply_to'] == $replyTo);
95
+ }
96
+ }
97
+ } catch (Exception $e){
98
+ return false;
99
+ }
100
+ }
101
+ return false;
102
+ }
103
+
104
+
105
+ }
app/code/community/Magpleasure/Guestbook/Helper/Data.php ADDED
@@ -0,0 +1,110 @@
1
+ <?php
2
+ /**
3
+ * MagPleasure Co.
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the EULA
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://www.magpleasure.com/LICENSE.txt
11
+ *
12
+ * @category Magpleasure
13
+ * @package Magpleasure_Guestbook
14
+ * @copyright Copyright (c) 2012 Magpleasure Co. (http://www.magpleasure.com)
15
+ * @license http://www.magpleasure.com/LICENSE.txt
16
+ */
17
+
18
+ class Magpleasure_Guestbook_Helper_Data extends Mage_Core_Helper_Abstract
19
+ {
20
+ /**
21
+ * Auto Approving
22
+ *
23
+ * @return mixed
24
+ */
25
+ public function getCommentsAutoapprove()
26
+ {
27
+ return Mage::getStoreConfig('guestbook/messages/autoapprove');
28
+ }
29
+
30
+ public function getCommentsPerPage()
31
+ {
32
+ return Mage::getStoreConfig('guestbook/messages/record_per_page');
33
+ }
34
+
35
+ public function getCommentsAllowGuests()
36
+ {
37
+ return Mage::getStoreConfig('guestbook/messages/allow_guests');
38
+ }
39
+
40
+ public function getMenuEnabled()
41
+ {
42
+ return Mage::getStoreConfig('guestbook/menu/enabled');
43
+ }
44
+
45
+ public function getMenuPosition()
46
+ {
47
+ return Mage::getStoreConfig('guestbook/menu/position');
48
+ }
49
+
50
+ public function getMenuLabel()
51
+ {
52
+ return Mage::getStoreConfig('guestbook/menu/label');
53
+ }
54
+
55
+ /**
56
+ * Render
57
+ *
58
+ * @return Magpleasure_Guestbook_Helper_Comment_Render
59
+ */
60
+ public function _render()
61
+ {
62
+ return Mage::helper("guestbook/comment_render");
63
+ }
64
+
65
+ /**
66
+ * Comment Secure
67
+ *
68
+ * @return Magpleasure_Guestbook_Helper_Comment_Secure
69
+ */
70
+ public function _secure()
71
+ {
72
+ return Mage::helper("guestbook/comment_secure");
73
+ }
74
+
75
+ protected function _getTimezone()
76
+ {
77
+ return Mage::getStoreConfig('general/locale/timezone');
78
+ }
79
+
80
+ public function renderTime($datetime)
81
+ {
82
+ $date = new Zend_Date($datetime, Zend_Date::ISO_8601, Mage::app()->getLocale()->getLocaleCode());
83
+ $date->setTimezone($this->_getTimezone());
84
+ return $date->toString(Zend_Date::TIME_SHORT);
85
+ }
86
+
87
+ public function renderDate($datetime)
88
+ {
89
+ $date = new Zend_Date($datetime, Zend_Date::ISO_8601, Mage::app()->getLocale()->getLocaleCode());
90
+ $date->setTimezone($this->_getTimezone());
91
+ return $date->toString(Zend_Date::DATE_LONG);
92
+ }
93
+
94
+ /**
95
+ * Wrapper for standart strip_tags() function with extra functionality for html entities
96
+ *
97
+ * @param string $data
98
+ * @param string $allowableTags
99
+ * @param bool $escape
100
+ * @return string
101
+ */
102
+ public function stripTags($data, $allowableTags = null, $escape = false)
103
+ {
104
+ $result = strip_tags($data, $allowableTags);
105
+ return $escape ? $this->escapeHtml($result, $allowableTags) : $result;
106
+ }
107
+
108
+
109
+ }
110
+
app/code/community/Magpleasure/Guestbook/Model/Message.php ADDED
@@ -0,0 +1,93 @@
1
+ <?php
2
+
3
+ class Magpleasure_Guestbook_Model_Message extends Mage_Core_Model_Abstract
4
+ {
5
+ const STATUS_PENDING = 1;
6
+ const STATUS_APPROVED = 2;
7
+ const STATUS_REJECTED = 3;
8
+
9
+ /**
10
+ * Helper
11
+ * @return Magpleasure_Guestbook_Helper_Data
12
+ */
13
+ protected function _helper()
14
+ {
15
+ return Mage::helper('guestbook');
16
+ }
17
+
18
+ protected function _construct()
19
+ {
20
+ $this->_init("guestbook/message");
21
+
22
+ }
23
+
24
+ public function getOptionsArray()
25
+ {
26
+ return array(
27
+ self::STATUS_PENDING => $this->_helper()->__("Pending"),
28
+ self::STATUS_APPROVED => $this->_helper()->__("Approved"),
29
+ self::STATUS_REJECTED => $this->_helper()->__("Rejected"),
30
+ );
31
+ }
32
+
33
+ public function toOptionArray()
34
+ {
35
+ $result = array();
36
+ foreach ($this->getOptionsArray() as $value=>$label){
37
+ $result[] = array('value'=>$value, 'label'=>$label);
38
+ }
39
+ return $result;
40
+ }
41
+
42
+
43
+ public function approve()
44
+ {
45
+ $this
46
+ ->setSessionId(null)
47
+ ->setStatus(self::STATUS_APPROVED)
48
+ ->save();
49
+ return $this;
50
+ }
51
+
52
+ public function reject()
53
+ {
54
+ $this
55
+ ->setSessionId(null)
56
+ ->setStatus(self::STATUS_REJECTED)
57
+ ->save();
58
+ return $this;
59
+ }
60
+
61
+
62
+ protected function _prepareComment($message)
63
+ {
64
+ $message = html_entity_decode($message);
65
+ return strip_tags($message);
66
+ }
67
+
68
+ public function comment(array $data)
69
+ {
70
+ $this->addData($data);
71
+ $this->setStoreId(Mage::app()->getStore()->getId());
72
+ if ($this->_helper()->getCommentsAutoapprove()){
73
+ $this->setStatus(self::STATUS_APPROVED);
74
+ $this->setSessionId(null);
75
+ } else {
76
+ $this->setStatus(self::STATUS_PENDING);
77
+ }
78
+ $this->setMessage( $this->_prepareComment($data['message']) );
79
+ $this->save();
80
+ return $this;
81
+ }
82
+
83
+ public function reply(array $data)
84
+ {
85
+ /** @var Magpleasure_Guestbook_Model_Message $message */
86
+ $message = Mage::getModel('guestbook/message');
87
+ $message->setReplyTo($this->getId());
88
+ $message->comment($data);
89
+ return $message;
90
+ }
91
+
92
+ }
93
+
app/code/community/Magpleasure/Guestbook/Model/Mysql4/Message.php ADDED
@@ -0,0 +1,27 @@
1
+ <?php
2
+ class Magpleasure_Guestbook_Model_Mysql4_Message extends Mage_Core_Model_Mysql4_Abstract
3
+ {
4
+ /**
5
+ * Zend_Date date format for Mysql requests
6
+ */
7
+ const MYSQL_ZEND_DATE_FORMAT = 'yyyy-MM-dd HH:mm:ss';
8
+
9
+
10
+ protected function _construct()
11
+ {
12
+ $this->_init("guestbook/message", "message_id");
13
+ }
14
+
15
+ protected function _beforeSave(Mage_Core_Model_Abstract $object)
16
+ {
17
+ parent::_beforeSave($object);
18
+ $now = new Zend_Date();
19
+ $now = $now->toString(self::MYSQL_ZEND_DATE_FORMAT);
20
+ if (!$object->getId()){
21
+ $object->setCreatedAt($now);
22
+ }
23
+ $object->setUpdatedAt($now);
24
+ }
25
+
26
+ }
27
+
app/code/community/Magpleasure/Guestbook/Model/Mysql4/Message/Collection.php ADDED
@@ -0,0 +1,107 @@
1
+ <?php
2
+ /**
3
+ * MagPleasure Co.
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the EULA
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://www.magpleasure.com/LICENSE.txt
11
+ *
12
+ * @category Magpleasure
13
+ * @package Magpleasure_Guestbook
14
+ * @copyright Copyright (c) 2012 Magpleasure Co. (http://www.magpleasure.com)
15
+ * @license http://www.magpleasure.com/LICENSE.txt
16
+ */
17
+
18
+ class Magpleasure_Guestbook_Model_Mysql4_Message_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
19
+ {
20
+
21
+ public function _construct()
22
+ {
23
+ $this->_init("guestbook/message");
24
+ }
25
+
26
+ public function addStoreFilter($storeId)
27
+ {
28
+ $this->getSelect()
29
+ ->where("main_table.store_id = ?", $storeId)
30
+ ;
31
+ return $this;
32
+ }
33
+
34
+ public function addActiveFilter($ownerSessionId = null)
35
+ {
36
+ if ($ownerSessionId){
37
+ $activeStatus = Magpleasure_Guestbook_Model_Message::STATUS_APPROVED;
38
+ $pendingStatus = Magpleasure_Guestbook_Model_Message::STATUS_PENDING;
39
+ $this->getSelect()
40
+ ->where(new Zend_Db_Expr("(main_table.status = '{$activeStatus}') OR ((main_table.status = '{$pendingStatus}') AND (main_table.session_id = '$ownerSessionId'))"))
41
+ ;
42
+
43
+
44
+ } else {
45
+ $this->addFieldToFilter('main_table.status', Magpleasure_Guestbook_Model_Message::STATUS_APPROVED);
46
+ }
47
+ return $this;
48
+ }
49
+
50
+ public function addReplyTo()
51
+ {
52
+ $this->getSelect()
53
+ ->joinLeft(array('replied'=>$this->getMainTable()), "replied.message_id = main_table.reply_to", array('reply_to_text'=>'replied.message'))
54
+ ;
55
+ return $this;
56
+ }
57
+
58
+
59
+ public function addReplyToTextFilter($filter)
60
+ {
61
+ $this->getSelect()
62
+ ->where("replied.message LIKE ('%{$filter}%')")
63
+ ;
64
+ return $this;
65
+ }
66
+
67
+
68
+ public function addMessageTextFilter($filter)
69
+ {
70
+ $this->getSelect()
71
+ ->where("main_table.message LIKE ('%{$filter}%')")
72
+ ;
73
+ return $this;
74
+ }
75
+
76
+ public function setDateOrder($dir = 'ASC')
77
+ {
78
+ $this->getSelect()
79
+ ->order("main_table.created_at {$dir}");
80
+ return $this;
81
+ }
82
+
83
+ public function setNotReplies()
84
+ {
85
+ $this->getSelect()
86
+ ->where("main_table.reply_to IS NULL")
87
+ ;
88
+ return $this;
89
+ }
90
+
91
+ public function setReplyToFilter($commentId)
92
+ {
93
+ $this->getSelect()
94
+ ->where("main_table.reply_to = ?", $commentId)
95
+ ;
96
+ return $this;
97
+ }
98
+
99
+ public function addStatusFilter($ststusId)
100
+ {
101
+ $this->getSelect()
102
+ ->where("main_table.status = ?", $ststusId)
103
+ ;
104
+ return $this;
105
+ }
106
+ }
107
+
app/code/community/Magpleasure/Guestbook/controllers/Adminhtml/MessageController.php ADDED
@@ -0,0 +1,278 @@
1
+ <?php
2
+ /**
3
+ * MagPleasure Co.
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the EULA
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://www.magpleasure.com/LICENSE.txt
11
+ *
12
+ * @category Magpleasure
13
+ * @package Magpleasure_Guestbook
14
+ * @copyright Copyright (c) 2012 Magpleasure Co. (http://www.magpleasure.com)
15
+ * @license http://www.magpleasure.com/LICENSE.txt
16
+ */
17
+
18
+ class Magpleasure_Guestbook_Adminhtml_MessageController extends Mage_Adminhtml_Controller_Action
19
+ {
20
+ /**
21
+ * Helper
22
+ * @return Magpleasure_Guestbook_Helper_Data
23
+ */
24
+ protected function _helper()
25
+ {
26
+ return Mage::helper('guestbook');
27
+ }
28
+
29
+ protected function _initAction()
30
+ {
31
+ $this->loadLayout()
32
+ ->_setActiveMenu('catalog/guestbook')
33
+ ->_addBreadcrumb($this->_helper()->__('Guestbook'), $this->_helper()->__('Guestbook'));
34
+ return $this;
35
+ }
36
+
37
+
38
+ public function indexAction()
39
+ {
40
+ $this->_initAction()
41
+ ->renderLayout();
42
+ }
43
+
44
+
45
+ public function editAction()
46
+ {
47
+ $id = $this->getRequest()->getParam('id');
48
+ $comment = Mage::getModel('guestbook/message');
49
+ if ($id){
50
+ $comment->load($id);
51
+ }
52
+
53
+ $this->loadLayout();
54
+ $this->_setActiveMenu('catalog/guestbook/comment');
55
+
56
+ if ($comment->getId()){
57
+
58
+ Mage::register('current_comment', $comment);
59
+ $data = Mage::getSingleton('adminhtml/session')->getPostData(true);
60
+ if (!empty($data)) {
61
+ $comment->setData($data);
62
+ }
63
+
64
+ $this->_addBreadcrumb($this->_helper()->__('Guest Book'), $this->_helper()->__('Guest Book'));
65
+ $this->_addBreadcrumb($this->_helper()->__('Comment'), $this->_helper()->__('Comment'));
66
+
67
+ } else {
68
+ $this->_getSession()->addError($this->_helper()->__('Comment is not exists.'));
69
+ $this->_redirect('*/*/index');
70
+ }
71
+
72
+ $this->renderLayout();
73
+ }
74
+
75
+
76
+ public function saveAction()
77
+ {
78
+ $requestPost = $this->getRequest()->getPost();
79
+ $comment = Mage::getModel('guestbook/message');
80
+ if ($id = $this->getRequest()->getParam('id')){
81
+ $comment->load($id);
82
+ }
83
+
84
+ try {
85
+ $comment->addData($requestPost);
86
+ $comment->save();
87
+ $this->_getSession()->addSuccess($this->_helper()->__("Comment was successfully saved."));
88
+
89
+ if ($this->getRequest()->getParam('back')){
90
+ $this->_redirect('*/*/edit', array('id'=> $this->getRequest()->getParam('id') ? $this->getRequest()->getParam('id') : $comment->getId() ));
91
+ } else {
92
+ $this->_redirect('*/*/index');
93
+ }
94
+
95
+ } catch (Exception $e) {
96
+ Mage::getSingleton('adminhtml/session')->setPostData($requestPost);
97
+ $this->_getSession()->addError($this->_helper()->__("Error while saving the comment (%s).", $e->getMessage()));
98
+ $this->_redirectReferer();
99
+ }
100
+
101
+ }
102
+
103
+ /**
104
+ * Delete comment
105
+ * @param int|string $id
106
+ * @return boolean
107
+ */
108
+ protected function _delete($id)
109
+ {
110
+ $comment = Mage::getModel('guestbook/message')->load($id);
111
+ if ($comment->getId()){
112
+ try{
113
+ $comment->delete();
114
+ return true;
115
+ } catch(Exception $e) {
116
+ return false;
117
+ }
118
+ }
119
+ return false;
120
+ }
121
+
122
+ /**
123
+ * Approve comment
124
+ * @param int|string $id
125
+ * @return boolean
126
+ */
127
+ protected function _approve($id)
128
+ {
129
+ $comment = Mage::getModel('guestbook/message')->load($id);
130
+ if ($comment->getId()){
131
+ try{
132
+ $comment->approve();
133
+ return true;
134
+ } catch(Exception $e) {
135
+ return false;
136
+ }
137
+ }
138
+ return false;
139
+ }
140
+
141
+ /**
142
+ * Reject comment
143
+ * @param int|string $id
144
+ * @return boolean
145
+ */
146
+ protected function _reject($id)
147
+ {
148
+ $comment = Mage::getModel('guestbook/message')->load($id);
149
+ if ($comment->getId()){
150
+ try{
151
+ $comment->reject();
152
+ return true;
153
+ } catch(Exception $e) {
154
+ return false;
155
+ }
156
+ }
157
+ return false;
158
+ }
159
+
160
+ protected function _updateStatus($id, $status)
161
+ {
162
+ if ($id){
163
+ try {
164
+ $comment = Mage::getModel('guestbook/message')->load($id);
165
+ $comment->setStatus($status);
166
+ $comment->save();
167
+ return true;
168
+ } catch (Exception $e){
169
+ return false;
170
+ }
171
+ }
172
+ }
173
+
174
+ public function massStatusAction()
175
+ {
176
+ $comments = $this->getRequest()->getPost('comments');
177
+ $status = $this->getRequest()->getPost('status');
178
+ if ($comments){
179
+ $success = 0;
180
+ $error = 0;
181
+ foreach ($comments as $commentId){
182
+ if ($this->_updateStatus($commentId, $status)){
183
+ $success++;
184
+ } else {
185
+ $error++;
186
+ }
187
+ }
188
+ if ($success){
189
+ $this->_getSession()->addSuccess($this->_helper()->__("%s comments successfully updated.", $success));
190
+ }
191
+ if ($error){
192
+ $this->_getSession()->addError($this->_helper()->__("%s comments was not updated.", $error));
193
+ }
194
+ }
195
+ $this->_redirectReferer();
196
+ }
197
+
198
+ public function massDeleteAction()
199
+ {
200
+ $comments = $this->getRequest()->getPost('comments');
201
+ if ($comments){
202
+ $success = 0;
203
+ $error = 0;
204
+ foreach ($comments as $commentId){
205
+ if ($this->_delete($commentId)){
206
+ $success++;
207
+ } else {
208
+ $error++;
209
+ }
210
+ }
211
+ if ($success){
212
+ $this->_getSession()->addSuccess($this->_helper()->__("%s comments successfully deleted.", $success));
213
+ }
214
+ if ($error){
215
+ $this->_getSession()->addError($this->_helper()->__("%s comments was not deleted.", $error));
216
+ }
217
+ }
218
+ $this->_redirectReferer();
219
+ }
220
+
221
+ public function approveAction()
222
+ {
223
+ $id = $this->getRequest()->getParam('id');
224
+ if ($id){
225
+ try {
226
+ $this->_approve($id);
227
+ $this->_getSession()->addSuccess($this->_helper()->__("Comment was successfully approved."));
228
+ } catch (Exception $e){
229
+ $this->_getSession()->addError($this->_helper()->__("Comment was not approved (%s).", $e->getMessage()));
230
+ $this->_redirectReferer();
231
+ return;
232
+ }
233
+ }
234
+ $this->_redirect('*/*/index');
235
+ }
236
+
237
+ public function rejectAction()
238
+ {
239
+ $id = $this->getRequest()->getParam('id');
240
+ if ($id){
241
+ try {
242
+ $this->_reject($id);
243
+ $this->_getSession()->addSuccess($this->_helper()->__("Comment was successfully rejected."));
244
+ } catch (Exception $e){
245
+ $this->_getSession()->addError($this->_helper()->__("Comment was not rejected (%s).", $e->getMessage()));
246
+ $this->_redirectReferer();
247
+ return;
248
+ }
249
+ }
250
+ $this->_redirect('*/*/index');
251
+ }
252
+
253
+ public function deleteAction()
254
+ {
255
+ $id = $this->getRequest()->getParam('id');
256
+ if ($id){
257
+ try {
258
+ $this->_delete($id);
259
+ $this->_getSession()->addSuccess($this->_helper()->__("Comment was successfully deleted."));
260
+ } catch (Exception $e){
261
+ $this->_getSession()->addError($this->_helper()->__("Comment was not deleted (%s).", $e->getMessage()));
262
+ $this->_redirectReferer();
263
+ return;
264
+ }
265
+ }
266
+ $this->_redirect('*/*/index');
267
+ }
268
+
269
+
270
+ public function gridAction()
271
+ {
272
+ $grid = $this->getLayout()->createBlock('guestbook/adminhtml_message_grid');
273
+ if ($grid){
274
+ $this->getResponse()->setBody($grid->toHtml());
275
+ }
276
+ }
277
+
278
+ }
app/code/community/Magpleasure/Guestbook/controllers/IndexController.php ADDED
@@ -0,0 +1,161 @@