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 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
<?php
namespace Alpha\View;
use Alpha\Util\Config\ConfigProvider;
use Alpha\Util\Extension\MarkdownFacade;
use Alpha\Util\Security\SecurityUtils;
use Alpha\Util\Service\ServiceFactory;
use Alpha\Model\Person;
use Alpha\View\Widget\TextBox;
use Alpha\View\Widget\Button;
use Alpha\Controller\Front\FrontController;
class ArticleCommentView extends View
{
public function markdownView($fields = array())
{
$config = ConfigProvider::getInstance();
$sessionProvider = $config->get('session.provider.name');
$session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface');
$markdown = new MarkdownFacade($this->record);
$author = new Person();
$id = $this->record->getCreatorId();
$author->load($id->getValue());
$html = '<blockquote class="usercomment">';
$createTS = $this->record->getCreateTS();
$updateTS = $this->record->getUpdateTS();
$html .= '<p>Posted by '.($author->get('URL') == '' ? $author->get('username') : '<a href="'.$author->get('URL').'" target="new window">'.$author->get('username').'</a>').' at '.$createTS->getValue().'.';
$html .= ' '.$author->get('username').' has posted ['.$author->getCommentCount().'] comments on articles since joining.';
$html .= '</p>';
if ($config->get('cms.comments.allowed') && $session->get('currentUser') != null && $session->get('currentUser')->getID() == $author->getID()) {
$html .= $this->editView($fields);
} else {
$html .= $markdown->getContent();
}
if ($createTS->getValue() != $updateTS->getValue()) {
$updator = new Person();
$id = $this->record->getCreatorID();
$updator->load($id->getValue());
$html .= '<p>Updated by '.($updator->get('URL') == '' ? $updator->get('username') : '<a href="'.$updator->get('URL').'" target="new window">'.$updator->get('username').'</a>').' at '.$updateTS->getValue().'.</p>';
}
$html .= '</blockquote>';
return $html;
}
public function createView($fields = array())
{
$config = ConfigProvider::getInstance();
$html = '<h2>Post a new comment:</h2>';
$html .= '<table cols="2" class="create_view">';
$html .= '<form action="'.$fields['formAction'].'" method="POST" accept-charset="UTF-8">';
$textBox = new TextBox($this->record->getPropObject('content'), $this->record->getDataLabel('content'), 'content', '', 10);
$html .= $textBox->render();
$fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('articleID')) : 'articleID');
$html .= '<input type="hidden" name="'.$fieldname.'" value="'.$this->record->get('articleID').'"/>';
$html .= '<tr><td colspan="2">';
$button = new Button('submit', 'Post Comment', 'createCommentBut');
$html .= $button->render();
$html .= '</td></tr>';
$html .= View::renderSecurityFields();
$fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('statusMessage')) : 'statusMessage');
$html .= '<input type="hidden" name="'.$fieldname.'" value="Thank you for your comment!"/>';
$html .= '</form></table>';
$html .= '<p class="warning">Please note that any comment you post may be moderated for spam or offensive material.</p>';
return $html;
}
public function editView($fields = array())
{
$config = ConfigProvider::getInstance();
$sessionProvider = $config->get('session.provider.name');
$session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface');
$html = '<table cols="2" class="edit_view" style="width:100%; margin:0px">';
$html .= '<form action="'.$fields['formAction'].'" method="POST" accept-charset="UTF-8">';
$textBox = new TextBox($this->record->getPropObject('content'), $this->record->getDataLabel('content'), 'content', '', 5, $this->record->getID());
$html .= $textBox->render();
$fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('version_num')) : 'version_num');
$html .= '<input type="hidden" name="'.$fieldname.'" value="'.$this->record->getVersion().'"/>';
$fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('ActiveRecordID')) : 'ActiveRecordID');
$html .= '<input type="hidden" name="'.$fieldname.'" value="'.$this->record->getID().'"/>';
if ($session->get('currentUser')->inGroup('Admin') && strpos($fields['formAction'], '/tk/') !== false) {
$html .= '<tr><td colspan="2">';
$fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('saveBut')) : 'saveBut');
$temp = new Button('submit', 'Save', $fieldname);
$html .= $temp->render();
$html .= ' ';
$js = "$('#dialogDiv').text('Are you sure you wish to delete this item?');
$('#dialogDiv').dialog({
buttons: {
'OK': function(event, ui) {
$('[id=\"".($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('ActiveRecordID')) : 'ActiveRecordID')."\"]').attr('value', '".$this->record->getID()."');
$('#deleteForm').submit();
},
'Cancel': function(event, ui) {
$(this).dialog('close');
}
}
})
$('#dialogDiv').dialog('open');
return false;";
$temp = new Button($js, 'Delete', 'deleteBut');
$html .= $temp->render();
$html .= ' ';
$temp = new Button("document.location = '".FrontController::generateSecureURL('act=Alpha\Controller\ActiveRecordController&ActiveRecordType='.get_class($this->record))."'", 'Back to List', 'cancelBut');
$html .= $temp->render();
$html .= '</td></tr>';
$html .= View::renderSecurityFields();
$fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('_METHOD')) : '_METHOD');
$html .= '<input type="hidden" name="'.$fieldname.'" id="'.$fieldname.'" value="PUT"/>';
$html .= '</form></table>';
} else {
$html .= '</table>';
$html .= '<div align="center">';
$temp = new Button('submit', 'Update Your Comment', 'saveBut'.$this->record->getID());
$html .= $temp->render();
$html .= '</div>';
$html .= View::renderSecurityFields();
$fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('_METHOD')) : '_METHOD');
$html .= '<input type="hidden" name="'.$fieldname.'" id="'.$fieldname.'" value="PUT"/>';
$html .= '</form>';
}
return $html;
}
}