1: <?php
2:
3: namespace Alpha\View;
4:
5: use Alpha\Util\Config\ConfigProvider;
6: use Alpha\Util\Extension\MarkdownFacade;
7: use Alpha\Util\Security\SecurityUtils;
8: use Alpha\Util\Http\Session\SessionProviderFactory;
9: use Alpha\Model\Person;
10: use Alpha\View\Widget\TextBox;
11: use Alpha\View\Widget\Button;
12: use Alpha\Controller\Front\FrontController;
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: class ArticleCommentView extends View
57: {
58: 59: 60: 61: 62: 63: 64: 65: 66:
67: public function markdownView($fields = array())
68: {
69: $config = ConfigProvider::getInstance();
70: $sessionProvider = $config->get('session.provider.name');
71: $session = SessionProviderFactory::getInstance($sessionProvider);
72:
73: $markdown = new MarkdownFacade($this->BO);
74: $author = new Person();
75: $id = $this->BO->getCreatorID();
76: $author->load($id->getValue());
77:
78: $html = '<blockquote class="usercomment">';
79:
80: $createTS = $this->BO->getCreateTS();
81: $updateTS = $this->BO->getUpdateTS();
82:
83: $html .= '<p>Posted by '.($author->get('URL') == '' ? $author->get('displayname') : '<a href="'.$author->get('URL').'" target="new window">'.$author->get('displayname').'</a>').' at '.$createTS->getValue().'.';
84: $html .= ' '.$author->get('displayname').' has posted ['.$author->getCommentCount().'] comments on articles since joining.';
85: $html .= '</p>';
86: if ($config->get('cms.comments.allowed') && $session->get('currentUser') != null && $session->get('currentUser')->getID() == $author->getID()) {
87: $html .= $this->editView($fields);
88: } else {
89: $html .= $markdown->getContent();
90: }
91:
92: if ($createTS->getValue() != $updateTS->getValue()) {
93: $updator = new Person();
94: $id = $this->BO->getCreatorID();
95: $updator->load($id->getValue());
96: $html .= '<p>Updated by '.($updator->get('URL') == '' ? $updator->get('displayname') : '<a href="'.$updator->get('URL').'" target="new window">'.$updator->get('displayname').'</a>').' at '.$updateTS->getValue().'.</p>';
97: }
98: $html .= '</blockquote>';
99:
100: return $html;
101: }
102:
103: 104: 105: 106: 107: 108: 109: 110: 111:
112: public function createView($fields = array())
113: {
114: $config = ConfigProvider::getInstance();
115:
116: $html = '<h2>Post a new comment:</h2>';
117:
118: $html .= '<table cols="2" class="create_view">';
119: $html .= '<form action="'.$fields['formAction'].'" method="POST" accept-charset="UTF-8">';
120:
121: $textBox = new TextBox($this->BO->getPropObject('content'), $this->BO->getDataLabel('content'), 'content', '', 10);
122: $html .= $textBox->render();
123:
124: $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('articleOID')) : 'articleOID');
125: $html .= '<input type="hidden" name="'.$fieldname.'" value="'.$this->BO->get('articleOID').'"/>';
126: $html .= '<tr><td colspan="2">';
127:
128: $button = new Button('submit', 'Post Comment', 'createCommentBut');
129: $html .= $button->render();
130:
131: $html .= '</td></tr>';
132:
133: $html .= View::renderSecurityFields();
134:
135: $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('statusMessage')) : 'statusMessage');
136: $html .= '<input type="hidden" name="'.$fieldname.'" value="Thank you for your comment!"/>';
137:
138: $html .= '</form></table>';
139: $html .= '<p class="warning">Please note that any comment you post may be moderated for spam or offensive material.</p>';
140:
141: return $html;
142: }
143:
144: 145: 146: 147: 148: 149: 150: 151: 152:
153: public function editView($fields = array())
154: {
155: $config = ConfigProvider::getInstance();
156: $sessionProvider = $config->get('session.provider.name');
157: $session = SessionProviderFactory::getInstance($sessionProvider);
158:
159: $html = '<table cols="2" class="edit_view" style="width:100%; margin:0px">';
160: $html .= '<form action="'.$fields['formAction'].'" method="POST" accept-charset="UTF-8">';
161:
162: $textBox = new TextBox($this->BO->getPropObject('content'), $this->BO->getDataLabel('content'), 'content', '', 5, $this->BO->getID());
163: $html .= $textBox->render();
164:
165: $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('version_num')) : 'version_num');
166: $html .= '<input type="hidden" name="'.$fieldname.'" value="'.$this->BO->getVersion().'"/>';
167: $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('ActiveRecordOID')) : 'ActiveRecordOID');
168: $html .= '<input type="hidden" name="'.$fieldname.'" value="'.$this->BO->getID().'"/>';
169:
170:
171: if ($session->get('currentUser')->inGroup('Admin') && strpos($fields['formAction'], '/tk/') !== false) {
172: $html .= '<tr><td colspan="2">';
173:
174: $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('saveBut')) : 'saveBut');
175: $temp = new Button('submit', 'Save', $fieldname);
176: $html .= $temp->render();
177: $html .= ' ';
178: $js = "$('#dialogDiv').text('Are you sure you wish to delete this item?');
179: $('#dialogDiv').dialog({
180: buttons: {
181: 'OK': function(event, ui) {
182: $('[id=\"".($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('ActiveRecordOID')) : 'ActiveRecordOID')."\"]').attr('value', '".$this->BO->getOID()."');
183: $('#deleteForm').submit();
184: },
185: 'Cancel': function(event, ui) {
186: $(this).dialog('close');
187: }
188: }
189: })
190: $('#dialogDiv').dialog('open');
191: return false;";
192: $temp = new Button($js, 'Delete', 'deleteBut');
193: $html .= $temp->render();
194: $html .= ' ';
195: $temp = new Button("document.location = '".FrontController::generateSecureURL('act=Alpha\Controller\ActiveRecordController&ActiveRecordType='.get_class($this->BO))."'", 'Back to List', 'cancelBut');
196: $html .= $temp->render();
197: $html .= '</td></tr>';
198:
199: $html .= View::renderSecurityFields();
200:
201: $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('_METHOD')) : '_METHOD');
202: $html .= '<input type="hidden" name="'.$fieldname.'" id="'.$fieldname.'" value="PUT"/>';
203:
204: $html .= '</form></table>';
205: } else {
206: $html .= '</table>';
207:
208: $html .= '<div align="center">';
209: $temp = new Button('submit', 'Update Your Comment', 'saveBut'.$this->BO->getID());
210: $html .= $temp->render();
211: $html .= '</div>';
212:
213: $html .= View::renderSecurityFields();
214:
215: $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('_METHOD')) : '_METHOD');
216: $html .= '<input type="hidden" name="'.$fieldname.'" id="'.$fieldname.'" value="PUT"/>';
217:
218: $html .= '</form>';
219: }
220:
221: return $html;
222: }
223: }
224: