Source for file display.php
Documentation is available at display.php
* @package linea21.modules
* @author Simon Georget <simon@linea21.com>
* @license http://opensource.org/licenses/gpl-3.0.html
include_once(themePath('../comment/'. SQL. '.inc.php'));
include_once('../class/class.comment.php');
$str = '<a id="anchor-post-comment" href="'. str_replace('&', '&', $_SERVER["REQUEST_URI"]). '#add-comment" title="'. _t('comment', 'add'). '">'. _t('comment', 'add'). '</a>';
$str = '<a id="anchor-comment" href="'. str_replace('&', '&', $_SERVER["REQUEST_URI"]). '#comments" title="'. _t('comment', 'go_to'). '">'. sprintf(_t('comment', 'number'), '<span id="cc">'. $nb. '</span>'). '</a>';
function displayComments($a, $moderation = false, $get_permalink = false) {
function getComments($a, $moderation = false, $get_permalink = false) {
$comments = $comm->get($a, $GLOBALS['sql_object']);
if(count($comments) == 0 || $comments == 0) {
return '<p>' . _t('comment', 'nocomment_yet') . '</p>';
return getMarkup($comments, $moderation, $get_permalink);
if(isset ($_POST['cbody'])) {
isset ($_COOKIE['linea21']['login']) ? $arr['user_id'] = $_COOKIE['linea21']['id'] : $arr['user_id'] = '';
$arr['module'] = $a['module'];
$arr['module_id'] = $a['module_id'];
isset ($_POST['cname']) ? $arr['name'] = $_POST['cname'] : $arr['name'] = '';
isset ($_POST['cemail']) ? $arr['email'] = $_POST['cemail'] : $arr['email'] = '';
isset ($_POST['curl']) ? $arr['url'] = $_POST['curl'] : $arr['url'] = '';
isset ($_POST['cbody']) ? $arr['body'] = $_POST['cbody'] : $arr['body'] = '';
isset ($_POST['cnotification']) ? $arr['notification'] = 'Y' : $arr['notification'] = 'N';
$passed = $comm->checkDataIntegrity($arr);
$msg = '<p class="error">'. $passed . '</p>';
$r = $comm->add($arr, $GLOBALS['sql_object']);
// we send an email to default user for moderation if needed
// we notify users if needed
$msg = '<b>' . _t('comment', 'successful') . '</b>';
(COMMENT_MODERATION == 1) ? $msg .= '<br />'. _t('comment', 'moderation_msg') : '';
$msg = '<p class="confirm">'. $msg . '</p>';
echo '<script type="text/javascript">
setTimeout(\'jQuery.smoothScroll({scrollTarget: "#com-'. $r. '"});\', '. SCROLL_DELAY. ');
isset ($a['rub']) ? $rub = $a['rub'] : $rub = $_REQUEST['rub'];
isset ($a['id']) ? $id = $a['id'] : $id = $_REQUEST['id'];
if(isset ($_POST['cbody'])) {
isset ($_COOKIE['linea21']['login']) ? $arr['user_id'] = $_COOKIE['linea21']['id'] : $arr['user_id'] = '';
$arr['module'] = $a['module'];
$arr['module_id'] = $a['module_id'];
isset ($_POST['cname']) ? $arr['name'] = $_POST['cname'] : $arr['name'] = '';
isset ($_POST['cemail']) ? $arr['email'] = $_POST['cemail'] : $arr['email'] = '';
isset ($_POST['curl']) ? $arr['url'] = $_POST['curl'] : $arr['url'] = '';
isset ($_POST['cbody']) ? $arr['body'] = $_POST['cbody'] : $arr['body'] = '';
isset ($_POST['cnotification']) ? $arr['notification'] = 'Y' : $arr['notification'] = 'N';
$passed = $comm->checkDataIntegrity($arr);
if(isset ($_POST['cname'])) $f_name = $_POST['cname'];
if(isset ($_POST['cemail'])) $f_email = $_POST['cemail'];
if(isset ($_POST['curl'])) $f_url = $_POST['curl'];
if(isset ($_POST['cbody'])) $f_body = $_POST['cbody'];
if(isset ($_POST['cnotification'])) $f_notification = ' checked="checked"';
if(COMMENT_ONLY_REGISTERED == 1 && !isset ($_COOKIE['linea21']['login'])) {
$link = HrefMaker(array('rub'=> $GLOBALS['links'][U_L]['user-prefs']['linkvalue']));
$content = '<p class="info">'. sprintf(_t('comment', 'only_registered'), $link). '</p>';
$content = '<div id="add-comment">
<h3>'. _t('comment', 'add'). '</h3>
<form id="add-comment-form" method="post" action="index.php">
if(!isset ($_COOKIE['linea21']['login'])) {
$content .= '<p><label for="cname" class="labelised">'. _t('comment', 'name'). ' : </label>
<input type="text" name="cname" id="cname" class="shorttextfield" value="' . $f_name . '" /></p>
<p><label for="cemail" class="labelised">'. _t('comment', 'email'). ' : </label>
<input type="text" name="cemail" id="cemail" class="shorttextfield" value="' . $f_email . '" /></p>
<p><label for="curl" class="labelised">'. _t('comment', 'website'). ' ('. _t('divers', 'optional'). ') : </label>
<input type="text" name="curl" id="curl" class="shorttextfield" value="' . $f_url . '" /></p>';
$content .= '<p class="label-leftmargin">'. sprintf(_t('comment', 'logged-in_post'), $_COOKIE['linea21']['login']). '</p>';
$content .= '<p><label for="cbody" class="labelised">'. _t('comment', 'body'). ' : </label>
<textarea name="cbody" id="cbody" cols="30" class="shorttextfield" rows="5">' . $f_body . '</textarea></p>';
// no ability to subscribe on 'contribute' module
if(COMMENT_NOTIFICATION == 1 && $a['module']!= 'contribute') {
$content .= '<p class="label-leftmargin"><input type="checkbox" name="cnotification" id="cnotification" value="1"'. $f_notification. ' /><label for="cnotification" class="labelised autowidth">' . _t('comment', 'email_notification') . '</label></p>';
$content .= '<input type="hidden" name="module" id="module" value="'. $a['module']. '" />
<input type="hidden" name="rub" id="rub" value="'. $rub. '" />
<input type="hidden" name="id" id="id" value="'. $id. '" />';
if(COMMENT_MODERATION == 1) {
if(!isset ($_COOKIE['linea21']['login']) || (isset ($_COOKIE['linea21']['login']) && COMMENT_MODERATE_REGISTERED == 1))
$content .= '<p class="info">'. _t('comment', 'moderation_msg'). '</p>';
$content .= '<input type="submit" class="submitbut" value="'. _t('btn','valid'). '" />
// for ajax implementation
function getMarkup($comments, $moderation = false, $get_permalink = false) {
foreach($comments as $c) {
$cdate = $c['comment_date_crea_display'];
$cdateshort = substr($c['comment_date_crea_display'], 0, 10);
(trim($class) == 'odd') ? $class = '' : $class = ' odd';
if(!empty($c['profile_avatar'])) {
$avatar = '../'. $c['profile_avatar'];
if($c['comment_status']== 'D') {
$extraclass = ' to-moderate';
$tomoderate = '<p class="moderation">'. _t('comment', 'to_moderate'). '</p>';
if($c['comment_user_id']!= 0) {
$link = 'index.php?rub=user&todo=det&id='. $c['comment_user_id'];
$data = $GLOBALS['sql_object']->DBSelect(SQL_getUserInfo($c['comment_user_id']));
$cemail = ' - <a href="mailto:'. $data[0]['profile_email']. '">'. $data[0]['profile_email']. '</a>';
$registered = ' '. _t('comment', 'registered_user'). ' ';
$link = HrefMaker(array('rub' => $GLOBALS['links'][U_L]['user-profile']['linkvalue'], 'id' => $c['user_id'], 'name' => $c['user_login']));
$cname = '<a href="'. $link. '" title="' . $GLOBALS['links'][U_L]['user-profile']['desc']. '">'. $c['user_login']. '</a>';
$cname_raw = $c['user_login'];
$cemail = ' - <a href="mailto:'. $c['comment_email']. '">'. $c['comment_email']. '</a>';
if(!empty($c['comment_url']))
$cname = '<a href="'. $c['comment_url']. '">'. $c['comment_name']. '</a>';
$cname = $c['comment_name'];
$cname_raw = $c['comment_name'];
if($get_permalink == true) {
$permalink = '<a href="'. str_replace('&', '&', $_SERVER["REQUEST_URI"]). '#com-'. $c['comment_id']. '">#'. $c['comment_id']. '</a>';
$permalink = '#'. $c['comment_id'];
if($c['comment_status']== 'E') {
$marker = _t('comment', 'disapproved');
$cmarker = ' disapprove';
if($c['comment_status']== 'P') {
$marker = _t('comment', 'approved');
if($c['comment_status']== 'D') {
$marker = _t('comment', 'awaiting');
$str .= '<div class="comment'. $class. $extraclass. '" id="com-'. $c['comment_id']. '">
<img src="'. $avatar. '" alt="'. $cname_raw. '" />
<div class="name">' . $cname . $registered . $cemail. '</div>
<div class="date" title="'. $cdate . '">'. $permalink . ' - '. $cdateshort . '</div>
<div class="body">'. formatText($cbody, '2HTML') . '</div>'. $tomoderate;
if($moderation === true || ( $moderation == 'smart' && $c['comment_status'] == 'D') ) {
$str .= '<div class="comment-actions">
<a href="../comment/_ajax_admin.php?todo=approve&id='. $c['comment_id']. '" class="ico_approve" title="'. ucfirst(_t('comment', 'approve')). '"><span>'. ucfirst(_t('comment', 'approve')). '</span></a>
<a href="../comment/_ajax_admin.php?todo=disapprove&id='. $c['comment_id']. '" class="ico_disapprove" title="'. ucfirst(_t('comment', 'disapprove')). '"><span>'. ucfirst(_t('comment', 'disapprove')). '</span></a>
<a href="../comment/_ajax_admin.php?todo=del&id='. $c['comment_id']. '" class="ico_delete" title="'. ucfirst(_t('comment', 'delete')). '"><span>'. ucfirst(_t('comment', 'delete')). '</span></a>
<br style="clear:both" />
<div class="action-marker'. $cmarker. '">'. $marker. '</div>
if($item['link'] == 'library') {
if($item['link'] != 'contribute') {
$str .= '<p class="item">'. _t('comment', 'posted_in') . ' <a href="../admin/index.php?rub='. $item['link']. '&todo=det&'. $key. '='. $c['comment_module_id']. '" title="'. $c['item_title']. '">'. $c['item_title']. '</a> ('. $item['name']. ')</p>';
// no link to item for 'contribute' module
$str .= '<p class="item">'. _t('comment', 'posted_in') . ' '. $item['name']. '</p>';
* $arr : array of needed data
* $id : inserted comment id
* $overpass : to overpass tests
function notifyUsers($arr, $id, $o, $overpass = false) {
$data = $o->getCommentItem($arr, $GLOBALS['sql_object']);
$a['item_title'] = $data[0]['item_title'];
$a['action'] = 'notify_comment';
if(COMMENT_NOTIFICATION == 1) {
// we send it only if new comment is automatically approved
if(COMMENT_MODERATION == 0 || (COMMENT_MODERATE_REGISTERED == 0 && !empty($arr['user_id']))) {
if($pass === true || $overpass === true) {
$users_email = $o->getSubscribers($arr, $GLOBALS['sql_object']);
foreach($users_email as $email) {
// we don't send mail to author
if($email != $a['author_email']) {
$a['recipient'] = $email;
include(themePath('../comment/mail_actions.php'));
include('../mail/template.php');
// if $overpass we stop there
if($overpass === true) return true;
// in any case we send an email to the admin when message is posted
// if moderation is disabled
if(COMMENT_MODERATION == 0 || (COMMENT_MODERATE_REGISTERED == 0 && !empty($arr['user_id']))) {
$a['recipient'] = SITE_MAIL;
include(themePath('../comment/mail_actions.php'));
include('../mail/template.php');
* $arr : array of needed data
* $id : inserted comment id
if(COMMENT_MODERATION == 1) {
// if logged-in user and no moderation on registered user, we exit
if(!empty($arr['user_id']) && COMMENT_MODERATE_REGISTERED == 0) return true;
if($arr['module'] != 'contribute') {
$data = $o->getCommentItem($arr, $GLOBALS['sql_object']);
$data[0]['item_title'] = _t('comment', 'contribute_item');
$a['item_title'] = $data[0]['item_title'];
$a['action'] = 'moderate_comment';
$a['recipient'] = SITE_MAIL;
include(themePath('../comment/mail_actions.php'));
include('../mail/template.php');
if(!empty($a['user_id'])) {
$output['name'] = $data[0]['user_login'];
$output['author_email'] = $data[0]['profile_email'];
$output['name'] = $a['name'];
$output['author_email'] = $a['email'];
$output['body'] = $a['body'];
$output['moderate_link'] = SITE_ROOT_URL . 'admin/index.php?rub=comment&todo=list&module=all&statut=D';
$output['item_type'] = $item['name'];
$output['admin_link'] = SITE_ROOT_URL . 'admin/index.php?rub='. $item['link']. '&todo=det&id='. $a['module_id'];
$output['item_link'] = SITE_ROOT_URL . 'public/index.php?rub='. $GLOBALS['links'][U_L][$item['link']]['linkvalue']. '&id='. $a['module_id'];
if($a['module']== 'files') {
$wg = explode('/', $a['module_id']);
$output['item_link'] = SITE_ROOT_URL . 'public/index.php?rub='. $GLOBALS['links'][U_L]['workgroup']['linkvalue'];
$output['item_link'] = SITE_ROOT_URL . 'public/index.php?rub='. $GLOBALS['links'][U_L]['workgroup']['linkvalue']. '&id='. $wg[1];
$output['item_link_comments'] = $output['item_link'];
$output['item_link_the_comment'] = $output['item_link'];
$output['item_link'] = SITE_ROOT_URL . 'public/index.php?rub='. $GLOBALS['links'][U_L][$item['link']]['linkvalue']. '&id='. $a['module_id'];
$output['item_link_comments'] = $output['item_link']. '#comments';
if(isset ($a['cid'])) $output['item_link_the_comment'] = $output['item_link']. '#com-'. $a['cid'];
$output['unsubscribe_link'] = SITE_ROOT_URL . 'public/index.php?rub='. $GLOBALS['links'][U_L]['comment-unsubscribe']['linkvalue']. '&name='. $a['module']. '&id='. $a['module_id'];
$output['item_link_comments'] = $output['item_link']. '#comments';
$str = '<script type="text/javascript">
$(".comment-actions a").click(function() {
var url = $(this).attr("href");
if(data.page != "comment") {
$(data.el).addClass(data.action).fadeOut("slow");
// we update the comment counter
$("#cc").text( parseInt($("#cc").text()) - 1);
if(data.action == "del") {
$(data.el).addClass(data.action).fadeOut("slow");
$(data.el).removeClass("to-moderate");
var col = $(data.el).css("background-color");
$(data.el + " div.action-marker").removeClass("awaiting approve disapprove").addClass(data.action).empty().text(data.msg);
$(data.el).css("background-color","#F2F2F2").animate({backgroundColor: col}, 1500 );
$a['name'] = _t('comment_map', $module);
$a['link'] = 'dashboard';
$a['link'] = 'publication';
$a['link'] = 'workshoprep';
$a['link'] = 'contribute';
die($module . ' is not a valid option.');
|