protected function processForm(sfWebRequest $request, sfForm $form) { $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName())); if ($form->isValid()) { $isNew = $form->getObject()->isNew(); $notice = $isNew ? 'Your reply was saved successfully.' : 'The item was updated successfully.'; $sf_nested_comment = $form->save(); $this->dispatcher->notify(new sfEvent($this, 'admin.save_object', array('object' => $sf_nested_comment))); $email_pref = sfNestedCommentConfig::isMailEnabled(); $enable_mail_alert = $email_pref === true || $email_pref == 'moderated'; if ($isNew && $enable_mail_alert && $sf_nested_comment->isReply()) { $userComment = $sf_nested_comment->getsfNestedCommentRelatedBySfCommentId(); $params = $this->prepareMailParameter($sf_nested_comment, $userComment); sfNestedCommentTools::sendEmail($this->getMailer(), $params); } $this->getUser()->setFlash('notice', $notice); $this->redirect('@sf_nested_comment'); } else { $this->getUser()->setFlash('error', 'The item has not been saved due to some errors.', false); } }
public function executeRecentComments() { $this->comments = sfNestedCommentQuery::create() ->recent() ->approved() ->limit(sfNestedCommentConfig::getMaxRecentCommet()) ->find(); }
function url_for_commentable_object($commentableObject, $absolute = false) { $callable = sfNestedCommentConfig::getUrlCommentableCallable(); if ($callable) { return url_for(call_user_func($callable, $commentableObject), $absolute); } return false; }
public function executeAddComment(sfWebRequest $request) { $this->commentForm = new sfNestedCommentFrontForm(null, $this->getUser()); $bindValues = $request->getParameter($this->commentForm->getName()); if (sfNestedCommentConfig::isRecaptchaEnabled()) { $captcha = array( 'recaptcha_challenge_field' => $request->getParameter('recaptcha_challenge_field'), 'recaptcha_response_field' => $request->getParameter('recaptcha_response_field'), ); $bindValues = array_merge($bindValues, array('captcha' => $captcha)); } $this->commentForm->bind($bindValues); if ($this->commentForm->isValid()) { $comment = $this->commentForm->save(); $this->getUser()->setFlash('add_comment', $comment->getIsModerated() ? 'moderated' : 'normal'); $this->dispatcher->notify(new sfEvent($this, 'sf_nested_comment.add', array('object' => $comment))); $email_pref = sfNestedCommentConfig::isMailEnabled(); if($email_pref == true || ($email_pref == 'moderated' && $comment->getIsModerated())) { $params = $this->prepareMailParameter($comment); sfNestedCommentTools::sendEmail($this->getMailer(), $params); } if($request->isXmlHttpRequest()) { $this->setLayout(false); sfConfig::set('sf_web_debug', false); $commentableObject = $comment->getCommentableObject(); $comments = sfNestedCommentTools::getComments($commentableObject, $request); return $this->renderPartial('sfNestedComment/comments', array('object' => $commentableObject, 'comments' => $comments, 'commentForm' => sfNestedCommentTools::createCommentForm($commentableObject))); } else { return $this->redirect($request->getReferer()); } } else { if($request->isXmlHttpRequest()) { $this->getResponse()->setStatusCode(404); $this->setLayout(false); sfConfig::set('sf_web_debug', false); return $this->renderPartial('sfNestedComment/add_comment', array('commentForm' => $this->commentForm)); } else { return 'Error'; } } }
protected function doUpdateObject($values) { parent::doUpdateObject($values); $commentable = sfNestedCommentableModelQuery::create()->model($this->getValues())->findOneOrCreate(); $commentable->setCommentableId($this->getValue('commentable_id')); $commentable->setCommentableModel($this->getValue('commentable_model')); $automoderation = sfNestedCommentConfig::getMailAutomoderation(); if($automoderation === true || (($automoderation == 'first_post') && !sfNestedCommentQuery::create()->isAuthorApproved($this->getObject()->getAuthorName(), $this->getObject()->getAuthorEmail()))) { $this->getObject()->setIsModerated(true); } $this->getObject()->setsfNestedCommentableModel($commentable); }
public function initialize() { if ($this->configuration instanceof sfApplicationConfiguration) { if (sfNestedCommentConfig::isRoutesRegister()) { if (in_array('sfNestedComment', sfConfig::get('sf_enabled_modules', array()))) { $this->dispatcher->connect('routing.load_configuration', array('sfNestedCommentRouting', 'listenToRoutingLoadConfigurationEvent')); } if (in_array('sfNestedCommentAdmin', sfConfig::get('sf_enabled_modules', array()))) { $this->dispatcher->connect('routing.load_configuration', array('sfNestedCommentRouting', 'addRouteForNestedCommentAdmin')); } } sfOutputEscaper::markClassAsSafe('sfNestedCommentsRenderer'); if (sfNestedCommentConfig::isUsePluginPurifier()) { self::registerHTMLPurifier(); } } }
public function sortByCreatedAt() { return $this->orderByCreatedAt(sfNestedCommentConfig::getSortType()); }
<?php use_helper('I18N') ?> <?php if (method_exists($object instanceof sfOutputEscaper ? $object->getRawValue() : $object, 'allowComments')): ?> <?php $enable_comment = sfNestedCommentConfig::isCommentEnabled() && $object->allowComments() ?> <?php else: ?> <?php $enable_comment = sfNestedCommentConfig::isCommentEnabled() ?> <?php endif; ?> <?php if(0 < $nb_comments = $object->getNbApprovedComments()): ?> <h3 id="comments-title"><?php echo format_number_choice('[1]One comment so far|(1,+Inf]%1% comments so far', array('%1%' => $nb_comments), $nb_comments) ?></h3> <?php endif; ?> <div id="sfNestedComment_comment_list"> <?php include_partial('sfNestedComment/comment_list', array('comments' => $comments)) ?> </div> <?php if(!$enable_comment): ?> <div class="comment-closed"><?php echo __('Comments are closed.') ?></div> <?php elseif($sf_user->getFlash('add_comment') == 'moderated'): ?> <div class="comment-moderated"><?php echo __('Your comment has been submitted and is awaiting moderation') ?></div> <?php endif; ?> <?php if($enable_comment): ?> <?php include_partial('sfNestedComment/add_comment', array('commentForm' => $commentForm)) ?> <?php endif; ?>
<?php use_stylesheet('/sfNestedCommentPlugin/css/commentPreview.css', 'last') ?> <?php use_stylesheet('/sfNestedCommentPlugin/css/jquery.textarearesizer.css', 'last') ?> <?php use_javascript('/sfNestedCommentPlugin/js/commentPreview.js', 'last') ?> <?php use_javascript('/sfNestedCommentPlugin/js/jquery.textarearesizer.compressed.js', 'last') ?> <?php endif; ?> <div id="respond"> <h3 id="replay-title"><?php echo __('Leave a reply') ?> <small><a href="#respond" id="cancel-comment-reply-link">Cancel Reply</a></small></h3> <form action="<?php echo url_for('@sf_nested_commend_add') ?>" name='add_comment' class='add_comment' id='sfNestedComment_add_comment_form' method="post"> <?php echo $commentForm ?> <div class="form-submit"> <input type="submit" value="<?php echo (__('Submit comment')) ?>" id="sumbit-comment" /> <?php if($use_ajax): ?> <input type="button" value="Preview" id="preview-comment-button" /> <span id="add-comment-loader" style="display:none;"><?php echo image_tag('/sfNestedCommentPlugin/images/loading.gif') ?></span> <?php endif; ?> </div> </form> <?php if($use_ajax): ?> <div class="lp-block" id="live-preview-display"> <div id="lp-comment"></div> </div> <?php endif; ?> </div> <?php if($use_ajax): ?> <?php use_javascript('/sfNestedCommentPlugin/js/commentForm.js') ?> <script type="text/javascript"> setupAjaxCommentForm(<?php echo sfNestedCommentConfig::isNestedEnabled() ?>); </script> <?php endif; ?>
public function getLink() { $callable = sfNestedCommentConfig::getUrlCommentableCallable(); if ($callable) { $commentableUrl = call_user_func($callable, $this->getCommentableObject()); return $commentableUrl .= '#comment-'.$this->getId(); } return ''; }
<?php $use_ajax = sfNestedCommentConfig::isAjaxEnabled() ?> <?php $enable_nested = sfNestedCommentConfig::isNestedEnabled() ?> <?php if (sfNestedCommentConfig::isNestedEnabled()): ?> <?php use_helper('sfNestedCommentPagination') ?> <?php $url = $use_ajax ? '@sf_nested_comment_commenting' : $sf_request->getPathInfoPrefix().$sf_request->getPathInfo() ?> <?php echo comment_pagination($comments, $url, $sf_request->getParameterHolder(), 'Earlier Comments', 'Older Comments') ?> <?php $comments = $comments->getResults() ?> <?php endif; ?> <?php $renderer = sfNestedCommentTools::createCommentsRenderer($comments, $enable_nested) ?> <?php echo $renderer->render() ?>
<?php if (sfNestedCommentConfig::isUsePluginStylesheet()): ?> <?php use_stylesheet('/sfNestedCommentPlugin/css/sfNestedComment.css') ?> <?php endif; ?> <?php use_javascript('/sfNestedCommentPlugin/js/sfNestedComment.reply.js') ?> <?php $use_ajax = sfNestedCommentConfig::isAjaxEnabled() ?> <?php $enable_nested = sfNestedCommentConfig::isNestedEnabled() ?> <?php if($use_ajax): ?> <?php if($enable_nested): ?> <?php use_javascript('/sfNestedCommentPlugin/js/jCollapsible.js') ?> <?php endif; ?> <?php endif; ?> <div id="comments"> <div id="sfNestedComments"> <?php include_partial('sfNestedComment/comments', array('object' => $object, 'comments' => $comments, 'commentForm' => $commentForm)) ?> </div> </div> <?php if($use_ajax): ?> <?php use_javascript('/sfNestedCommentPlugin/js/listComments.js') ?> <?php if ($object instanceof sfOutputEscaper): ?> <?php $model = get_class($object->getRawValue()) ?> <?php else: ?> <?php $model = get_class($object) ?> <?php endif; ?> <script type="text/javascript"> setupAjaxListComments('<?php echo $model ?>', '<?php echo $object->getPrimaryKey() ?>', <?php echo sfNestedCommentConfig::isNestedEnabled() ?>); </script> <?php endif; ?>
<?php use_helper('sfNestedComment', 'I18N') ?> <?php $use_gravatar = sfNestedCommentConfig::isGravatarEnabled() ?> <?php if ($use_gravatar): ?> <?php use_helper('Gravatar') ?> <?php endif; ?> <?php $cls = 'recentcommentsavatar' ?> <table class="<?php echo $cls ?>" cellspacing="0" cellpadding="0" border="0"> <tbody> <?php $i = 1 ?> <?php foreach($comments as $comment): ?> <?php $commentableObject = $comment->getCommentableObject() ?> <?php $suffix = $i == 1 ? 'top' : 'end' ?> <tr> <?php if ($use_gravatar): ?> <td class="<?php echo $cls.$suffix ?>" style="height: 32px; width: 32px" title="<?php echo $comment->getAuthorName() ?>"> <?php if ($comment->getAuthorUrl()): ?> <a rel="nofollow" href="<?php echo $comment->getAuthorUrl() ?>"> <?php echo gravatar_image_tag($comment->getAuthorEmail(), null, 32) ?> </a> <?php else: ?> <?php echo gravatar_image_tag($comment->getAuthorEmail(), null, 32) ?> <?php endif; ?> </td> <?php endif; ?> <td class="recentcommentstext<?php echo $suffix?>"> <?php if ($comment->getAuthorUrl()): ?> <a rel="nofollow" href="<?php echo $comment->getAuthorUrl() ?>"><?php echo $comment->getAuthorName() ?></a> <?php else: ?> <?php echo $comment->getAuthorName() ?> <?php endif; ?> <?php echo __('on') ?>
<?php use_helper('Date') ?> <div id="comment-<?php echo $comment->getId() ?>"> <div class="comment-author"> <?php if (sfNestedCommentConfig::isGravatarEnabled()): ?> <?php use_helper('Gravatar') ?> <?php echo gravatar_image_tag($comment->getAuthorEmail(), null, 40) ?> <?php endif; ?> <cite class="fn"><?php echo $comment->getAuthorUrl() ? link_to($comment->getAuthorName(), $comment->getAuthorUrl()) : $comment->getAuthorName() ?></cite> <span class="says"><?php echo __('says') ?>:</span> </div> <div class="comment-meta"> <?php echo format_date(strtotime($comment->getCreatedAt()), 'D') ?> at <?php echo format_datetime(strtotime($comment->getCreatedAt()), 't') ?> </div> <div class="comment-body"> <?php echo $comment->getContent(ESC_RAW) ?> </div> <div class="reply"><a href="#respond" onclick="return addComment.moveForm('comment-<?php echo $comment->getId() ?>', '<?php echo $comment->getId() ?>', 'respond', '<?php echo $comment->getsfNestedCommentableModel()->getCommentableId() ?>')">Reply</a></div> </div>
public function spooledMessages() { return $this ->filterBySuccess(false) ->filterByAttempts(sfNestedCommentConfig::getMaxAttempts(), Criteria::LESS_EQUAL); }
public static function ellipsis($text, $append='…') { $text = strip_tags($text); $max = sfNestedCommentConfig::getMaxRecentTitleLength(); if (strlen($text) <= $max) return $text; $out = substr($text,0,$max); if (strpos($text,' ') === FALSE) return $out.$append; return preg_replace('/\w+$/','',$out).$append; }