예제 #1
0
 /**
  * Show entry.
  *
  */
 public function showAction()
 {
     $this->enableLayout();
     $key = $this->_getParam('key');
     $entry = $this->_blog->getEntry($key);
     // @todo pimcore Staticroute::assemble() generates double slash on end
     $url = rtrim($this->view->url(), '/') . '/';
     if (!$entry) {
         throw new Zend_Controller_Action_Exception("Blog entry for key '{$key}' not found", 404);
     }
     if ($this->_commenting && $this->_request->isPost()) {
         $result = $this->_commenting->saveComment($this->_request->getPost(), $entry);
         if ($result) {
             $this->_messenger->addMessage($this->_translate->_('blog_comment_added'));
             return $this->_redirect($url);
         }
     }
     $this->view->entry = $entry;
     if ($this->_commenting) {
         $this->view->comments = $this->_commenting->getComments($entry, $this->_getParam('page', 1), $this->_getParam('perpage', 10));
         $form = $this->_commenting->getForm();
         $form->setAction($url);
         $this->view->commentForm = $form;
     }
     $this->view->headTitle($entry->getTitle());
 }
 /**
  * Overwrite the default comments form so we can tweak a bit
  *
  * @see docs/en/Extending
  */
 public function CommentsForm()
 {
     if (Commenting::has_commenting($this->ownerBaseClass) && Commenting::get_config_value($this->ownerBaseClass, 'include_js')) {
         Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
         Requirements::javascript(THIRDPARTY_DIR . '/jquery-validate/lib/jquery.form.js');
         Requirements::javascript(THIRDPARTY_DIR . '/jquery-validate/jquery.validate.pack.js');
         Requirements::javascript('comments/javascript/CommentsInterface.js');
     }
     $interface = new SSViewer('DiscussionsCommentsInterface');
     $enabled = !$this->attachedToSiteTree() || $this->owner->ProvideComments ? true : false;
     // do not include the comments on pages which don't have id's such as security pages
     if ($this->owner->ID < 0) {
         return false;
     }
     $controller = new CommentingController();
     $controller->setOwnerRecord($this);
     $controller->setBaseClass($this->ClassName);
     $controller->setOwnerController(Controller::curr());
     $moderatedSubmitted = Session::get('CommentsModerated');
     Session::clear('CommentsModerated');
     // Tweak the comments form a bit, so it is more user friendly
     if ($enabled) {
         $form = $controller->CommentsForm();
         $form->Fields()->removeByName("Comment");
         $comment_field = TextareaField::create("Comment", "")->setCustomValidationMessage(_t('CommentInterface.COMMENT_MESSAGE_REQUIRED', 'Please enter your comment'))->setAttribute('data-message-required', _t('CommentInterface.COMMENT_MESSAGE_REQUIRED', 'Please enter your comment'));
         if ($form->Fields()->dataFieldByName("NameView")) {
             $form->Fields()->insertBefore($comment_field, "NameView");
         } else {
             $form->Fields()->insertBefore($comment_field, "Name");
         }
     } else {
         $form = false;
     }
     // a little bit all over the show but to ensure a slightly easier upgrade for users
     // return back the same variables as previously done in comments
     return $interface->process(new ArrayData(array('CommentHolderID' => Commenting::get_config_value($this->ClassName, 'comments_holder_id'), 'PostingRequiresPermission' => Commenting::get_config_value($this->ClassName, 'required_permission'), 'CanPost' => Commenting::can_member_post($this->ClassName), 'RssLink' => "CommentingController/rss", 'RssLinkPage' => "CommentingController/rss/" . $this->ClassName . '/' . $this->ID, 'CommentsEnabled' => $enabled, 'Parent' => $this, 'AddCommentForm' => $form, 'ModeratedSubmitted' => $moderatedSubmitted, 'Comments' => $this->getComments())));
 }
예제 #3
0
파일: index.php 프로젝트: nikosv/openeclass
 $rating_content = '';
 if ($sharing_allowed) {
     $sharing_content = ($sharing_enabled) ? print_sharing_links($urlServer."modules/blog/index.php?$url_params&amp;action=showPost&amp;pId=".$post->getId(), $post->getTitle()) : '';
 }            
 if ($ratings_enabled) {
     $rating = new Rating('up_down', 'blogpost', $post->getId());
     if ($blog_type == 'course_blog') {
         $rating_content = $rating->put($is_editor, $uid, $course_id);
     } elseif ($blog_type == 'perso_blog') {
         //in this case send user_id as third argument instead of course_id which is 0
         //since we only need this info for identifying user's blog
         $rating_content = $rating->put(NULL, $uid, $user_id);
     }
 }
 if ($comments_enabled && ($post->getCommenting() == 1)) {
     $comm = new Commenting('blogpost', $post->getId());
     $comment_content = "<a class='btn btn-primary btn-xs pull-right' href='$_SERVER[SCRIPT_NAME]?$url_params&amp;action=showPost&amp;pId=".$post->getId()."#comments_title'>$langComments (".$comm->getCommentsNum().")</a>";
 } else {
     $comment_content = "<div class=\"blog_post_empty_space\"></div>";
 }            
 $tool_content .= "<div class='panel panel-action-btn-default'>
                     <div class='panel-heading'>
                         <div class='pull-right'>
                             ". action_button(array(
                                 array(
                                     'title' => $langEditChange,
                                     'url' => "$_SERVER[SCRIPT_NAME]?$url_params&amp;action=editPost&amp;pId=".$post->getId(),
                                     'icon' => 'fa-edit',
                                     'show' => $allow_to_edit
                                 ),
                                 array(
예제 #4
0
 $posts = $blog->getBlogPostsDB($page, $posts_per_page);
 /***blog posts area***/
 $tool_content .= "<div class='row'>";
 $tool_content .= "<div class='col-sm-9'>";
 foreach ($posts as $post) {
     $sharing_content = '';
     $rating_content = '';
     if ($sharing_allowed) {
         $sharing_content = $sharing_enabled ? print_sharing_links($urlServer . "modules/blog/index.php?course={$course_code}&amp;action=showPost&amp;pId=" . $post->getId(), $post->getTitle()) : '';
     }
     if ($ratings_enabled) {
         $rating = new Rating('up_down', 'blogpost', $post->getId());
         $rating_content = $rating->put($is_editor, $uid, $course_id);
     }
     if ($comments_enabled) {
         $comm = new Commenting('blogpost', $post->getId());
         $comment_content = "<a class='btn btn-primary btn-xs pull-right' href='{$_SERVER['SCRIPT_NAME']}?course={$course_code}&amp;action=showPost&amp;pId=" . $post->getId() . "#comments_title'>{$langComments} (" . $comm->getCommentsNum() . ")</a>";
     } else {
         $comment_content = "<div class=\"blog_post_empty_space\"></div>";
     }
     $tool_content .= "<div class='panel panel-action-btn-default'>\r\n                                <div class='panel-heading'>\r\n                                    <div class='pull-right'>\r\n                                        " . action_button(array(array('title' => $langModify, 'url' => "{$_SERVER['SCRIPT_NAME']}?course={$course_code}&amp;action=editPost&amp;pId=" . $post->getId(), 'icon' => 'fa-edit', 'show' => $post->permEdit($is_editor, $stud_allow_create, $uid)), array('title' => $langDelete, 'url' => "{$_SERVER['SCRIPT_NAME']}?course={$course_code}&amp;action=delPost&amp;pId=" . $post->getId(), 'icon' => 'fa-times', 'class' => 'delete', 'confirm' => $langSureToDelBlogPost, 'show' => $post->permEdit($is_editor, $stud_allow_create, $uid)))) . "\r\n                                    </div>\r\n                                    <h3 class='panel-title'>\r\n                                        <a href='{$_SERVER['SCRIPT_NAME']}?course={$course_code}&amp;action=showPost&amp;pId=" . $post->getId() . "'>" . q($post->getTitle()) . "</a>\r\n                                    </h3>                                    \r\n                                </div>\r\n                                <div class='panel-body'>\r\n                                    <div class='label label-success'>" . nice_format($post->getTime(), true) . "</div><small>" . $langBlogPostUser . display_user($post->getAuthor(), false, false) . "</small><br><br>" . standard_text_escape(ellipsize_html($post->getContent(), $num_chars_teaser_break, "<strong>&nbsp;...<a href='{$_SERVER['SCRIPT_NAME']}?course={$course_code}&amp;action=showPost&amp;pId=" . $post->getId() . "'> <span class='smaller'>[{$langMore}]</span></a></strong>")) . "\r\n                                    {$comment_content}\r\n                                </div>\r\n                                <div class='panel-footer'>\r\n                                    <div class='row'>\r\n                                        <div class='col-sm-6'>{$rating_content}</div>\r\n                                        <div class='col-sm-6 text-right'>{$sharing_content}</div>\r\n                                    </div>                                    \r\n                                </div>\r\n                             </div>";
 }
 //display navigation links
 $tool_content .= $blog->navLinksHTML($page, $posts_per_page);
 $tool_content .= "</div>";
 /***end of blog posts area***/
 /***sidebar area***/
 $tool_content .= "<div class='col-sm-3'>";
 $tool_content .= $blog->popularBlogPostsHTML($num_popular);
 $tool_content .= $blog->chronologicalTreeHTML(date('n', strtotime($posts[0]->getTime())), date('Y', strtotime($posts[0]->getTime())));
 $tool_content .= "</div></div>";
 function trigger()
 {
     $result = new XMLElement("post-comment");
     $comment = array();
     $comment['author_name'] = $_POST['name'];
     $comment['author_url'] = $_POST['website'];
     $comment['author_email'] = $_POST['email'];
     $comment['body'] = $_POST['comment'];
     $comment['entry_handle'] = $_POST['entry-handle'];
     $comment['section'] = $_POST['section'];
     $comment = array_map("stripslashes", $comment);
     ## Create the cookie elements
     $cookie = new XMLElement("cookie");
     $cookie->addChild(new XMLElement("name", General::sanitize($comment['author_name'])));
     $cookie->addChild(new XMLElement("email", General::sanitize($comment['author_email'])));
     $cookie->addChild(new XMLElement("url", General::validateURL($comment['author_url'])));
     $cookie->addChild(new XMLElement("comment", General::sanitize($comment['body'])));
     $result->addChild($cookie);
     $canProceed = true;
     if ($comment['author_name'] == "" || $comment['author_email'] == "" || $comment['body'] == "") {
         $xMissing = new XMLElement("missing");
         if ($comment['author_name'] == "") {
             $missing = new XMLElement("input");
             $missing->setAttribute("name", "name");
             $xMissing->addChild($missing);
         }
         if ($comment['author_email'] == "") {
             $missing = new XMLElement("input");
             $missing->setAttribute("name", "email");
             $xMissing->addChild($missing);
         }
         if ($comment['body'] == "") {
             $missing = new XMLElement("input");
             $missing->setAttribute("name", "comment");
             $xMissing->addChild($missing);
         }
         $result->addChild($xMissing);
         $canProceed = false;
     }
     if ($comment['author_email'] != "" && !ereg('^[a-zA-Z0-9_\\.\\-]+@[a-zA-Z0-9\\-]+\\.[a-zA-Z0-9\\-\\.]+$', $comment['author_email'])) {
         $invalid = new XMLElement("invalid");
         $xInvalid = new XMLElement("input");
         $xInvalid->setAttribute("name", "email");
         $invalid->addChild($xInvalid);
         $result->addChild($invalid);
         $canProceed = false;
     }
     if (!$canProceed) {
         $result->setAttribute("sent", "false");
     } else {
         require_once TOOLKIT . "/class.commenting.php";
         $oCommenting = new Commenting(array("parent" => $this->_parent));
         ## By default 'body', 'author_name' and 'author_ip' are required, but we
         ## want an email ('author_email') address as well.
         $oCommenting->setRequiredField('author_email');
         #if(is_array($oCommenting->_notices) && !empty($oCommenting->_notices)){
         if (!$oCommenting->insertComment($comment)) {
             $result->addChild(new XMLElement("notice", $oCommenting->_notices[0]));
             $result->setAttribute("sent", "false");
         } else {
             $result->setAttribute("sent", "true");
             $result->addChild(new XMLElement("notice", "Comment saved successfully"));
         }
         if ($oCommenting->isLastCommentSpam) {
             $result->setAttribute("spam", "true");
         }
         $prefix = $this->_parent->getConfigVar('cookie_prefix', 'symphony');
         if ($_POST['remember'] == 'on') {
             setcookie($prefix . 'comment-remember[name]', $comment['author_name'], time() + TWO_WEEKS, $this->_parent->getCookieDomain());
             setcookie($prefix . 'comment-remember[url]', $comment['author_url'], time() + TWO_WEEKS, $this->_parent->getCookieDomain());
             setcookie($prefix . 'comment-remember[email]', $comment['author_email'], time() + TWO_WEEKS, $this->_parent->getCookieDomain());
         } else {
             setcookie($prefix . 'comment-remember', ' ', time() - TWO_WEEKS, $this->_parent->getCookieDomain());
         }
     }
     return $result;
 }
예제 #6
0
 /**
  * Delete blog post
  * @return boolean true on success, false on failure
  */
 public function delete() {
     $sql = 'DELETE FROM `blog_post` WHERE `id` = ?d';
     $numrows = Database::get()->query($sql, $this->id)->affectedRows;
     if ($numrows == 1) {
         Commenting::deleteComments('blogpost', $this->id);
         Rating::deleteRatings('blogpost', $this->id);
         return true;
     } else {
         return false;
     }
 }
예제 #7
0
require_once 'class.commenting.php';


if ($_POST['rtype'] == 'blogpost') {
    $setting_id = SETTING_BLOG_COMMENT_ENABLE;
} elseif ($_POST['rtype'] == 'course') {
    $setting_id = SETTING_COURSE_COMMENT_ENABLE;
}

if (setting_get($setting_id, $course_id) == 1) {
    //response array
    //[0] -> status, [1] -> message, other positions -> other data 
    $response = array();
    
    if ($_POST['action'] == 'new') {
        if (Commenting::permCreate($is_editor, $uid, $course_id)) {
            $comment = new Comment();
            if ($comment->create($_POST['commentText'], $uid, $_POST['rtype'], intval($_POST['rid']))) {
                $post_actions = '<div class="pull-right">';
                $post_actions .= '<a href="javascript:void(0)" onclick="xmlhttpPost(\''.$urlServer.'modules/comments/comments.php?course='.$course_code.'\', \'editLoad\', '.$_POST['rid'].', \''.$_POST['rtype'].'\', \'\', '.$comment->getId().')">';
                $post_actions .= icon('fa-edit', $langModify).'</a> ';
                $post_actions .= '<a href="javascript:void(0)" onclick="xmlhttpPost(\''.$urlServer.'modules/comments/comments.php?course='.$course_code.'\', \'delete\', '.$_POST['rid'].', \''.$_POST['rtype'].'\', \''.$langCommentsDelConfirm.'\', '.$comment->getId().')">';
                $post_actions .= icon('fa-times', $langDelete).'</a>';
                $post_actions .='</div>';   
                
                $response[0] = 'OK';
                $response[1] = "<div class='alert alert-success'>".$langCommentsSaveSuccess."</div>";
                $response[2] = $comment->getId();
                $response[3] = "
         <div class='row margin-bottom-thin margin-top-thin comment' id='comment-".$comment->getId()."'>
                    <div class='col-xs-12'>
예제 #8
0
 /**
  * Returns the permalink for this {@link Comment}. Inserted into
  * the ID tag of the comment
  *
  * @return string
  */
 public function Permalink()
 {
     $prefix = Commenting::get_config_value($this->BaseClass, 'comment_permalink_prefix');
     return $prefix . $this->ID;
 }
예제 #9
0
    $description = standard_text_escape($course_info->description);
    $main_content .= "<div id='descr_content'>$description</div>";
} else {
    $main_content .= "<p class='not_visible'> - $langThisCourseDescriptionIsEmpty - </p>";
}
if (!empty($keywords)) {
    $main_content .= "<p id='keywords'><b>$langCourseKeywords</b> $keywords</p>";
}
$main_content .= "</div>";

if (!empty($addon)) {
    $main_content .= "<div class='course_info'><h1>$langCourseAddon</h1><p>$addon</p></div>";
}
if (setting_get(SETTING_COURSE_COMMENT_ENABLE, $course_id) == 1) {
    commenting_add_js();
    $comm = new Commenting('course', $course_id);
    $main_content .= $comm->put($course_code, $is_editor, $uid);
}
if (setting_get(SETTING_COURSE_RATING_ENABLE, $course_id) == 1) {
    $rating = new Rating('fivestar', 'course', $course_id);
    $rating_content = $rating->put($is_editor, $uid, $course_id);
}
if (is_sharing_allowed($course_id)) {
    if (setting_get(SETTING_COURSE_SHARING_ENABLE, $course_id) == 1) {
        $social_content = print_sharing_links($urlServer."courses/$course_code", $currentCourseName);
    }
}
$panel_footer = "";
if(isset($rating_content) || isset($social_content)) {
    $panel_footer .= "                
                <div class='panel-footer'>
예제 #10
0
    /**
     * Injects all commenting module code in other subsystems
     * @param courseCode the course code
     * @param $isEditor
     * @param $uid the user id
     * @return string
     */
    public function put($courseCode, $isEditor, $uid, $always_open = false) {
        global $langComments, $langBlogPostUser, $langSubmit, $themeimg, $langModify, $langDelete,
        $langCommentsDelConfirm, $langCommentsSaveConfirm, $urlServer, $head_content;
        
        //$head_content .= '<link rel="stylesheet" type="text/css" href="'.$urlServer.'modules/comments/style.css">';
        
        $commentsNum = $this->getCommentsNum();

        if (!$always_open) {
            $comments_title = "<button type='button' class='btn btn-primary' data-toggle='modal' data-target='#commentArea-$this->rid'>$langComments (<span id='commentsNum-$this->rid'>$commentsNum</span>)</button>";
            $out = "$comments_title
                    <div class='modal fade' id='commentArea-$this->rid' role='dialog'>
                      <div class='modal-dialog modal-lg'>
                        <div class='modal-content' style='padding:1%'>
                          <div class='modal-header'>
                            <button type='button' class='close' data-dismiss='modal'>&times;</button>
                              <h4 class='modal-title'>$langComments</h4>
                          </div>
                          <div class='modal-body' id='comments-$this->rid'>";
        } else {
            $comments_title = "<h3 id='comments_title'>$langComments (<span id='commentsNum-$this->rid'>$commentsNum</span>)</h3><br>";
            $out = "<div class='commenting'>
                        $comments_title
                    <div class='commentArea' id='commentArea-$this->rid'>
                    <div id='comments-$this->rid'>";
        }
        
        if ($commentsNum != 0) {
            //retrieve comments
            $comments = $this->getCommentsDB();
            foreach ($comments as $comment) {
                if (is_null($courseCode)) { //for the case of personal blog posts comments
                    if (isset($_SESSION['uid']) && ($isEditor || ($comment->getAuthor() == $uid))) { //$isEditor corresponds to blog editor
                        $post_actions = '<div class="pull-right">';
                        $post_actions .= '<a href="javascript:void(0)" onclick="xmlhttpPost(\''.$urlServer.'modules/comments/comments_perso_blog.php\', \'editLoad\', '.$this->rid.', \''.$this->rtype.'\', \'\', '.$comment->getId().')">';
                        $post_actions .= icon('fa-edit', $langModify).'</a> ';
                        $post_actions .= '<a href="javascript:void(0)" onclick="xmlhttpPost(\''.$urlServer.'modules/comments/comments_perso_blog.php\', \'delete\', '.$this->rid.', \''.$this->rtype.'\', \''.$langCommentsDelConfirm.'\', '.$comment->getId().')">';
                        $post_actions .= icon('fa-times', $langDelete).'</a>';
                        $post_actions .='</div>';
                    } else {
                        $post_actions = '';
                    }
                } else {
                    if ($comment->permEdit($isEditor, $uid)) {
                        $post_actions = '<div class="pull-right">';
                        $post_actions .= '<a href="javascript:void(0)" onclick="xmlhttpPost(\''.$urlServer.'modules/comments/comments.php?course='.$courseCode.'\', \'editLoad\', '.$this->rid.', \''.$this->rtype.'\', \'\', '.$comment->getId().')">';
                        $post_actions .= icon('fa-edit', $langModify).'</a> ';
                        $post_actions .= '<a href="javascript:void(0)" onclick="xmlhttpPost(\''.$urlServer.'modules/comments/comments.php?course='.$courseCode.'\', \'delete\', '.$this->rid.', \''.$this->rtype.'\', \''.$langCommentsDelConfirm.'\', '.$comment->getId().')">';
                        $post_actions .= icon('fa-times', $langDelete).'</a>';
                
                        if (abuse_report_show_flag('comment', $comment->getId(), course_code_to_id($courseCode), $isEditor)) {
                            $post_actions .= abuse_report_icon_flag ('comment', $comment->getId(), course_code_to_id($courseCode)); 
                        }
                
                        $post_actions .='</div>';
                    } else {
                        if (abuse_report_show_flag('comment', $comment->getId(), course_code_to_id($courseCode), $isEditor)) {
                            $post_actions = '<div class="pull-right">'.abuse_report_icon_flag ('comment', $comment->getId(), course_code_to_id($courseCode)).'</div>';
                        } else {
                            $post_actions = '';
                        }
                    }
                }           
                $out .= "<div class='row margin-bottom-thin margin-top-thin comment' id='comment-".$comment->getId()."'>
                          <div class='col-xs-12'>
                           <div class='media'>
                            <a class='media-left' href='#'>
                            ". profile_image($comment->getAuthor(), IMAGESIZE_SMALL) ."
                            </a>
                            <div class='media-body bubble'>
                             <div class='label label-success media-heading'>".nice_format($comment->getTime(), true).'</div>'.
                              "<small>".$langBlogPostUser.display_user($comment->getAuthor(), false, false)."</small>".
                               $post_actions
                               ."<div class='margin-top-thin' id='comment_content-".$comment->getId()."'>". q($comment->getContent()) ."</div>
                               </div>
                            </div>
                          </div>
                         </div>";              
            }
        }
        $out .= "</div>";
        
        if (is_null($courseCode)) { //for the case of personal blog posts comments
            if (isset($_SESSION['uid'])) {
                $out .= '<form action="" onsubmit="xmlhttpPost(\''.$urlServer.'modules/comments/comments_perso_blog.php\', \'new\','.$this->rid.', \''.$this->rtype.'\', \''.$langCommentsSaveConfirm.'\'); return false;">';
                $out .= '<textarea class="form-control" name="textarea" id="textarea-'.$this->rid.'" rows="5"></textarea><br/>';
                $out .= '<input class="btn btn-primary" name="send_button" type="submit" value="'.$langSubmit.'" />';
                $out .= '</form>';
            } 
        } else {
            if (Commenting::permCreate($isEditor, $uid, course_code_to_id($courseCode))) {
                $out .= '<form action="" onsubmit="xmlhttpPost(\''.$urlServer.'modules/comments/comments.php?course='.$courseCode.'\', \'new\','.$this->rid.', \''.$this->rtype.'\', \''.$langCommentsSaveConfirm.'\'); return false;">';
                $out .= '<textarea class="form-control" name="textarea" id="textarea-'.$this->rid.'" rows="5"></textarea><br/>';
                $out .= '<input class="btn btn-primary" name="send_button" type="submit" value="'.$langSubmit.'" />';
                $out .= '</form>';
            }
        }
        
        if (!$always_open) {
            $out .= '<div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                     </div>';
            $out .= '</div>';
        }
        
        $out .= '</div>';
        $out .= '</div>';
        
        return $out;
    }
예제 #11
0
<?php

/**
 * Comments Default Configuration
 *
 * To enable comments on your own {@link DataObject}'s you need to 
 * call Commenting::add_comments($object_name, $settings);
 *
 * Where $object_name is the name of the subclass of DataObject you want
 * to add the comments to and $settings is a map of configuration options
 * and values
 *
 * Example: mysite/_config.php
 *
 * <code>
 *	// uses the default values
 *	Commenting::add('SiteTree');
 * 
 *	// set configuration
 *	Commenting::add('SiteTree', array(
 *		'require_login' => true
 *	));
 * </code>
 */
Commenting::add('SiteTree');
예제 #12
0
 /**
  * Injects all commenting module code in other subsystems
  * @param courseCode the course code
  * @param $isEditor
  * @param $uid the user id
  * @return string
  */
 public function put($courseCode, $isEditor, $uid, $always_open = false)
 {
     global $langComments, $langBlogPostUser, $langSubmit, $themeimg, $langModify, $langDelete, $langCommentsDelConfirm, $langCommentsSaveConfirm, $urlServer, $head_content;
     //$head_content .= '<link rel="stylesheet" type="text/css" href="'.$urlServer.'modules/comments/style.css">';
     $commentsNum = $this->getCommentsNum();
     if (!$always_open) {
         $comments_title = "<a id='comments_title' href='javascript:void(0)' onclick='showComments(\"{$this->rid}\")'>{$langComments} (<span id='commentsNum-{$this->rid}'>{$commentsNum}</span>)</a><br>";
         $comments_display = "style='display:none'";
     } else {
         $comments_title = "<h3 id='comments_title'>{$langComments} (<span id='commentsNum-{$this->rid}'>{$commentsNum}</span>)</h3><br>";
         $comments_display = "";
     }
     //the array is declared in commenting.js
     $out = "<script type='text/javascript'>showCommentArea[{$this->rid}] = false;</script>\r\n                <div class='commenting'>\r\n                    {$comments_title}\r\n                <div class='commentArea' id='commentArea-{$this->rid}' {$comments_display}>\r\n                <div id='comments-{$this->rid}'>";
     if ($commentsNum != 0) {
         //retrieve comments
         $comments = $this->getCommentsDB();
         foreach ($comments as $comment) {
             if ($comment->permEdit($isEditor, $uid)) {
                 $post_actions = '<div class="pull-right">';
                 $post_actions .= '<a href="javascript:void(0)" onclick="xmlhttpPost(\'' . $urlServer . 'modules/comments/comments.php?course=' . $courseCode . '\', \'editLoad\', ' . $this->rid . ', \'' . $this->rtype . '\', \'\', ' . $comment->getId() . ')">';
                 $post_actions .= icon('fa-edit', $langModify) . '</a> ';
                 $post_actions .= '<a href="javascript:void(0)" onclick="xmlhttpPost(\'' . $urlServer . 'modules/comments/comments.php?course=' . $courseCode . '\', \'delete\', ' . $this->rid . ', \'' . $this->rtype . '\', \'' . $langCommentsDelConfirm . '\', ' . $comment->getId() . ')">';
                 $post_actions .= icon('fa-times', $langDelete) . '</a>';
                 $post_actions .= '</div>';
             } else {
                 $post_actions = '';
             }
             $out .= "<div class='row margin-bottom-thin margin-top-thin comment' id='comment-" . $comment->getId() . "'>\r\n            <div class='col-xs-12'>\r\n                <div class='media'>\r\n                    <a class='media-left' href='#'>\r\n                        " . profile_image($comment->getAuthor(), IMAGESIZE_SMALL) . "\r\n                    </a>\r\n                    <div class='media-body bubble'>\r\n                        <div class='label label-success media-heading'>" . nice_format($comment->getTime(), true) . '</div>' . "<small>" . $langBlogPostUser . display_user($comment->getAuthor(), false, false) . "</small>" . $post_actions . "<div class='margin-top-thin' id='comment_content-" . $comment->getId() . "'>" . q($comment->getContent()) . "</div>\r\n                    </div>\r\n                </div>\r\n            </div>\r\n        </div>";
         }
     }
     $out .= "</div>";
     if (Commenting::permCreate($isEditor, $uid, course_code_to_id($courseCode))) {
         $out .= '<form action="" onsubmit="xmlhttpPost(\'' . $urlServer . 'modules/comments/comments.php?course=' . $courseCode . '\', \'new\',' . $this->rid . ', \'' . $this->rtype . '\', \'' . $langCommentsSaveConfirm . '\'); return false;">';
         $out .= '<textarea class="form-control" name="textarea" id="textarea-' . $this->rid . '" rows="5"></textarea><br/>';
         $out .= '<input class="btn btn-primary" name="send_button" type="submit" value="' . $langSubmit . '" />';
         $out .= '</form>';
     }
     $out .= '</div>';
     $out .= '</div>';
     return $out;
 }
 /**
  * Comments interface for the front end. Includes the CommentAddForm and the composition
  * of the comments display. 
  * 
  * To customize the html see templates/CommentInterface.ss or extend this function with
  * your own extension.
  *
  * @todo Cleanup the passing of all this configuration based functionality
  *
  * @see docs/en/Extending
  */
 public function CommentsForm()
 {
     $interface = new SSViewer('CommentsInterface');
     // detect whether we comments are enabled. By default if $CommentsForm is included
     // on a {@link DataObject} then it is enabled, however {@link SiteTree} objects can
     // trigger comments on / off via ProvideComments
     $enabled = !$this->attachedToSiteTree() || $this->owner->ProvideComments ? true : false;
     // do not include the comments on pages which don't have id's such as security pages
     if ($this->owner->ID < 0) {
         return false;
     }
     $controller = new CommentingController();
     $controller->setOwnerRecord($this->owner);
     $controller->setBaseClass($this->ownerBaseClass);
     $controller->setOwnerController(Controller::curr());
     $form = $enabled ? $controller->CommentsForm() : false;
     // a little bit all over the show but to ensure a slightly easier upgrade for users
     // return back the same variables as previously done in comments
     return $interface->process(new ArrayData(array('CommentHolderID' => Commenting::get_config_value($this->ownerBaseClass, 'comments_holder_id'), 'PostingRequiresPermission' => Commenting::get_config_value($this->ownerBaseClass, 'required_permission'), 'CanPost' => Commenting::can_member_post($this->ownerBaseClass), 'RssLink' => "CommentingController/rss", 'RssLinkPage' => "CommentingController/rss/" . $this->ownerBaseClass . '/' . $this->owner->ID, 'CommentsEnabled' => $enabled, 'AddCommentForm' => $form, 'Comments' => $this->Comments())));
 }
예제 #14
0
 public function testDefaultTemplateRendersHtmlWithAllowHtml()
 {
     if (!class_exists('HTMLPurifier')) {
         $this->markTestSkipped('HTMLPurifier class not found');
     }
     $origAllowed = Commenting::get_config_value('CommentableItem', 'html_allowed');
     $item = new CommentableItem();
     $item->write();
     // Without HTML allowed
     $comment = new Comment();
     $comment->Comment = '<p>my comment</p>';
     $comment->ParentID = $item->ID;
     $comment->BaseClass = 'CommentableItem';
     $comment->write();
     $html = $item->customise(array('CommentsEnabled' => true))->renderWith('CommentsInterface');
     $this->assertContains('&lt;p&gt;my comment&lt;/p&gt;', $html);
     Commenting::set_config_value('CommentableItem', 'html_allowed', true);
     $html = $item->customise(array('CommentsEnabled' => true))->renderWith('CommentsInterface');
     $this->assertContains('<p>my comment</p>', $html);
     Commenting::set_config_value('CommentableItem', 'html_allowed', $origAllowed);
 }
<?php

if (ClassInfo::exists('Commenting')) {
    // Add commenting to discussions
    Commenting::add('Discussion', array("require_login" => true, "required_permission" => "DISCUSSIONS_REPLY", "order_comments_by" => "\"Created\" ASC"));
    Object::add_extension("Member", "DiscussionsMember");
    Object::add_extension("Group", "DiscussionsGroup");
    Object::add_extension("Comment", "DiscussionsComment");
    if (class_exists('Users_Account_Controller')) {
        Users_Account_Controller::add_extension('DiscussionsUsersController');
    }
}
 /**
  * Process which creates a {@link Comment} once a user submits a comment from this form.
  *
  * @param array $data 
  * @param Form $form
  */
 public function doPostComment($data, $form)
 {
     $class = isset($data['BaseClass']) ? $data['BaseClass'] : $this->getBaseClass();
     // if no class then we cannot work out what controller or model they
     // are on so throw an error
     if (!$class) {
         user_error("No OwnerClass set on CommentingController.", E_USER_ERROR);
     }
     // cache users data
     Cookie::set("CommentsForm_UserData", Convert::raw2json($data));
     Cookie::set("CommentsForm_Comment", $data['Comment']);
     // extend hook to allow extensions. Also see onAfterPostComment
     $this->extend('onBeforePostComment', $form);
     // If commenting can only be done by logged in users, make sure the user is logged in
     $member = Member::currentUser();
     if (Commenting::can_member_post($class) && $member) {
         $form->Fields()->push(new HiddenField("AuthorID", "Author ID", $member->ID));
     }
     if (!Commenting::can_member_post($class)) {
         echo _t('CommentingController.PERMISSIONFAILURE', "You're not able to post comments to this page. Please ensure you are logged in and have an appropriate permission level.");
         return;
     }
     // is moderation turned on
     $moderated = Commenting::get_config_value($class, 'require_moderation');
     $comment = new Comment();
     $form->saveInto($comment);
     $comment->Moderated = $moderated ? false : true;
     $comment->write();
     // clear the users comment since it passed validation
     Cookie::set('CommentsForm_Comment', false);
     if (Director::is_ajax()) {
         if (!$comment->Moderated) {
             echo $comment->renderWith('CommentInterface_pendingcomment');
         } else {
             echo $comment->renderWith('CommentInterface_singlecomment');
         }
         return true;
     }
     if ($comment->NeedsModeration) {
         $this->sessionMessage($moderationMsg, 'good');
     }
     // build up the return link. Ideally redirect to
     $holder = Commenting::get_config_value($comment->BaseClass, 'comments_holder_id');
     $hash = $comment->NeedsModeration ? $holder : $comment->Permalink();
     $url = isset($data['ReturnURL']) ? $data['ReturnURL'] : false;
     return $url ? $this->redirect($url . '#' . $hash) : $this->redirectBack();
 }