CMS  Version 3.9
CommentView Class Reference

Public Member Functions

 CommentView ($obj, $xrefClass, $component, $title="")
 
 buildCommentList ($obj)
 
 formatComment ($comment)
 
 drawButtons ($comment)
 
 writeScript ()
 
 drawView ()
 
 drawForm ()
 
 buildCommentForm ()
 
 addXrefRecord ($form)
 
 save ()
 
 getMatchingPK ($xref, $obj)
 

Static Public Member Functions

static addCommentPanel ($qs=null)
 
static fromGET ()
 
static onSaveNewComment ($form)
 Called by comment_form handler to save xref and send email for new comments. More...
 

Public Attributes

 $obj
 
 $list
 
 $form
 
 $xrefClass
 
 $component
 
 $title
 
 $usernameFormat = "{User.first_name} {User.last_name}"
 

Detailed Description

Definition at line 56 of file comment_view.inc.

Member Function Documentation

◆ addCommentPanel()

static CommentView::addCommentPanel (   $qs = null)
static

Definition at line 89 of file comment_view.inc.

90  {
91  if (!$qs)
92  {
93  $qs = getCleanQueryString();
94  }
95  $panel = new Panel("comment_panel", "/action/comment/comment_panel?$qs");
96  $panel->draw();
97  }
Panel provides a reloadable panel tied to an action handler.
Definition: panel.inc:51
$panel

◆ addXrefRecord()

CommentView::addXrefRecord (   $form)

Definition at line 280 of file comment_view.inc.

281  {
282  $xref = new $this->xrefClass;
283  $xref->set($this->obj->primary_key, $this->obj->get($this->obj->primary_key));
284  $xref->set($form->data->primary_key, $form->data->get($form->data->primary_key));
285  $xref->save();
286  }

◆ buildCommentForm()

CommentView::buildCommentForm ( )

Definition at line 234 of file comment_view.inc.

235  {
236  trace("Building Comment Form", 3);
237 
238  global $user;
239 
240  $key_name = $this->obj->getPrimaryKey();
241  $key_value = $this->obj->get($key_name);
242 
243  $comment = new Comment();
244  if(Settings::getValue("comment", "publish_automatically"))
245  {
246  $comment->published = true;
247  }
248  $form = new AutoForm($comment, "POST", "/action/comment/comment_form?comment_id=&xref_class={$this->xrefClass}&key_name=$key_name&key_value=$key_value&xref_component={$this->component}", "Comment_form");
249  $form->ajaxSubmit("function(result) {new Comment().commentFormResult(result);}", "function() {document.id('{$form->id}_error').set('text','Failed to communicate with server'); }");
250 
251  $form->required("description");
252  $form->alias("title", "Subject", "author", "Your Name");
253  $form->alias("description", "Comment");
254  $form->hide(user_id, published);
255  $form->onSaveComplete = array($this, addXrefRecord);
256 
257  if ($user)
258  {
259  $comment->user_id = $user->get($user->primary_key);
260  $form->hide("author");
261  }
262  else
263  {
264  $comment->user_id = 0;
265  $form->required("author");
266  }
267 
268  $captchaMode = Settings::getValue("comment", "use_captcha");
269  if ($captchaMode == "Always" || ($captchaMode == "Anonymous Only" && !$user))
270  {
271  $captchaMgr = new CaptchaManager();
272  $captchaMgr->addCaptchaToForm($form);
273  }
274 
275  if (!Settings::getValue("comment", "show_subject_field")) $form->hide("title");
276 
277  return $form;
278  }
Provides a central management class for event handlers and common functionality for the captcha compo...
addXrefRecord($form)
static getValue($component, $name)
Retrieve the value of the specified Setting.
Definition: settings.inc:104
global $user
$captchaMode
$comment
$key_value
$key_name
$image published
$feedback user_id
Definition: save.inc:14

◆ buildCommentList()

CommentView::buildCommentList (   $obj)

Definition at line 110 of file comment_view.inc.

111  {
112  trace("Building Comment List", 3);
113 
114  if(checkRole("admin"))
115  {
116  $comments = $obj->Comments("ORDER BY date_posted DESC");
117  }
118  else
119  {
120  $comments = $obj->Comments("Where published=1 ORDER BY date_posted DESC");
121  }
122  $list = new PagedList($comments, "comment_list", array($this, formatComment));
123  $list->CSSclass = "Standard";
124  $list->styles = "clear: both";
125  $list->paginate = false;
126 
127  return $list;
128  }
formatComment($comment)

◆ CommentView()

CommentView::CommentView (   $obj,
  $xrefClass,
  $component,
  $title = "" 
)
Parameters
obj$objany DataItem class that can link to Comment
String$xrefClassDataItem xref class that links obj to Comment
String$component
String$title

Definition at line 73 of file comment_view.inc.

74  {
75  $this->obj = $obj;
76  $this->xrefClass = $xrefClass;
77  $this->component = $component;
78  $this->title = ($title) ? $title : "Comments";
79  $this->list = $this->buildCommentList($obj);
80  $this->form = $this->buildCommentForm();
81 
82  if (Settings::getValue("comment", "username_format") == "Username")
83  {
84  $mgr = new UserManager();
85  $this->usernameFormat = "{User.".$mgr->getUsernameField()."}";
86  }
87  }
$bookmark title
buildCommentList($obj)
Provides the interface to the user model for the application.

◆ drawButtons()

CommentView::drawButtons (   $comment)

Definition at line 162 of file comment_view.inc.

163  {
164  $edit = "<div class='button_row'>\n";
165 
166  if($comment->isEditable())
167  {
168  $edit .= "<a href='#' class='button' onclick=\"new Comment().showCommentDialog({comment_id}, '{$this->xrefClass}', '{$this->component}'); return false\"> Edit </a>&nbsp;&nbsp;";
169  }
170  if(checkRole("admin") && !Settings::getValue("comment","publish_automatically"))
171  {
172  if($comment->published)
173  {
174  $edit .= "<a href='#' class='button' onclick=\"new Comment().commentPublish({comment_id}); return false;\"> Un-Publish </a>\n";
175  }
176  else
177  {
178  $edit .= "<a href='#' class='button' onclick=\"new Comment().commentPublish({comment_id}); return false;\"> Publish </a>\n";
179  }
180  }
181  $edit .= "<div style='clear:both'></div></div>\n";
182 
183  return $edit;
184  }
$edit

◆ drawForm()

CommentView::drawForm ( )

Definition at line 222 of file comment_view.inc.

223  {
224  global $user;
225 
226  if ($user || Settings::getValue("comment", "allow_anonymous_commenting"))
227  {
228 
229  $this->form->drawForm();
230 
231  }
232  }

◆ drawView()

CommentView::drawView ( )

Definition at line 200 of file comment_view.inc.

201  {
202  global $user;
203 
204  if (Settings::getValue("comment", "enable_item_rating"))
205  {
207  }
208 
209  echo "<h3>{$this->title}</h3>\n";
210  $preambleIdentifier = $user ? Settings::getValue("comment", "logged_in_preamble_text") : Settings::getValue("comment", "anonymous_preamble_text");
211 
212  $text = TextLookup::getText($preambleIdentifier);
213 
214  echo $text;
215 
216  if(count($this->list->items) > 0)
217  {
218  $this->list->drawList();
219  }
220  }
static drawRatingWidget($obj=null)
The Settings class provides components with a common API for specifying application settings and conf...
Definition: settings.inc:49
static getText($code, $obj=null, $blank=false)
Retrieves text for display on a page, given the code.
Definition: text_lookup.inc:85

◆ formatComment()

CommentView::formatComment (   $comment)

Definition at line 131 of file comment_view.inc.

132  {
133  $author = ($comment->user_id) ? $comment->format($this->usernameFormat) : $comment->author;
134 
135  if($comment->published)
136  {
137  $out = "<div id='comment{$comment->comment_id}' class='message'>\n";
138  }
139  else
140  {
141  $out = "<a name='comment{$comment->comment_id}'></a><div id='comment{$comment->comment_id}' class='message_unpublished'>\n";
142  }
143  $out .=" <div class='title'>";
144 
145  if ($comment->title)
146  {
147  $out .= "<strong>{$comment->title}</strong><br/>";
148  }
149 
150  $out .= "<span class='small'>Posted by $author at {$comment->date_posted}</span>\n </div>\n <div class='message_content'>";
151 
152  if($comment->isEditable() || (checkRole("admin") && !Settings::getValue("comment","publish_automatically")))
153  {
154  $edit .= $this->drawButtons($comment);
155  }
156 
157  $out .= $comment->format("{description:stripHTML}$edit");
158  $out .= "</div></div></a>";
159  return $out;
160  }
$out
Definition: page.inc:66
drawButtons($comment)

◆ fromGET()

static CommentView::fromGET ( )
static

Definition at line 99 of file comment_view.inc.

100  {
101  $adapter = CommentManager::getAdapter();
102 
103  if ($adapter)
104  {
105  $parent = $adapter->createParent();
106  return new CommentView($parent, $adapter->xrefClass, $adapter->component);
107  }
108  }
$parent
Definition: templates.inc:42
CommentView($obj, $xrefClass, $component, $title="")

◆ getMatchingPK()

CommentView::getMatchingPK (   $xref,
  $obj 
)

Definition at line 350 of file comment_view.inc.

351  {
352  $pks = $obj->getPrimaryKeyList();
353  foreach($pks as $pk)
354  {
355  if ($xref->hasField($pk)) return $pk;
356  }
357 
358  throw new DataItemException("No matching foreign key in xref table");
359  }

◆ onSaveNewComment()

static CommentView::onSaveNewComment (   $form)
static

Called by comment_form handler to save xref and send email for new comments.

AutoForm's obj can by any obj that links to Comment (e.g, Article)

Parameters
obj$formAutoForm

Definition at line 315 of file comment_view.inc.

316  {
317  $xref_class = $form->data->get("xref_class");
318  $xref = new $xref_class;
319 
320  $obj = $form->data;
321 
322  // The primary key name of the parent obj (e.g., Article)
323  $key_name = $obj->get("key_name");
324  $key_value = $obj->get("key_value");
325 
326  $xref->set($key_name, $key_value);
327  $xref->set("comment_id", $obj->get("comment_id"));
328 
329  if (method_exists($xref, verifyEnabled))
330  {
331  if (!$xref->verifyEnabled($key_value))
332  {
333  Fakoli::end("No SPAM for you today, Mister!");
334  }
335  }
336 
337  // Wait until after verified, if applicable, to save
338  $xref->save();
339 
340  $confirmation_message = "Thank you for your comment.";
341  if(!Settings::getValue("comment", "publish_automatically"))
342  {
343  sendEmailUsingEmailManager($xref, 'new_comment');
344  $confimation_message = "Thank you. Your comment has been submitted to the moderator.";
345  }
346 
347  $form->data->set("confirmation_message", $confirmation_message);
348  }
static end($message="")
Use this method to terminate execution of a script instead of using the php keywords exit() or die().
Definition: core.inc:1149
$xref_class
sendEmailUsingEmailManager($sendingItem, $name, $onSendComplete="")

◆ save()

CommentView::save ( )

Definition at line 288 of file comment_view.inc.

289  {
290  $form = $this->form;
291 
292  if($form->save())
293  {
294  $xref = new $this->xrefClass;
295 
296  $obj = $this->obj;
297  $pk = $this->getMatchingPK($xref, $obj);
298 
299  $xref->set($pk, $obj->get($pk));
300  $xref->set("comment_id", $form->data->get("comment_id"));
301  $xref->save();
302  return true;
303  }
304  }
getMatchingPK($xref, $obj)

◆ writeScript()

CommentView::writeScript ( )

Definition at line 186 of file comment_view.inc.

187  {
188  global $user;
189 
190  $script .= $this->list->writeScript();
191 
192  if ($user || Settings::getValue("comment", "allow_anonymous_commenting"))
193  {
194  $script .= $this->form->writeScript();
195  }
196 
197  return $script;
198  }

Member Data Documentation

◆ $component

CommentView::$component

Definition at line 62 of file comment_view.inc.

◆ $form

CommentView::$form

Definition at line 60 of file comment_view.inc.

◆ $list

CommentView::$list

Definition at line 59 of file comment_view.inc.

◆ $obj

CommentView::$obj

Definition at line 58 of file comment_view.inc.

◆ $title

CommentView::$title

Definition at line 63 of file comment_view.inc.

◆ $usernameFormat

CommentView::$usernameFormat = "{User.first_name} {User.last_name}"

Definition at line 64 of file comment_view.inc.

◆ $xrefClass

CommentView::$xrefClass

Definition at line 61 of file comment_view.inc.


The documentation for this class was generated from the following file: