* @version $id SVN * @access public * @license http://opensource.org/licenses/gpl-3.0.html */ include_once(themePath('../comment/'.SQL.'.inc.php')); include_once('../class/class.comment.php'); if(!function_exists('getPostCommentAnchor')) { function getPostCommentAnchor() { $str = ''._t('comment', 'add').''; return $str; } } if(!function_exists('getCommentsAnchor')) { function getCommentsAnchor($a) { $nb = getNbComments($a); $str = ''.sprintf(_t('comment', 'number'), ''.$nb.'').''; return $str; } } if(!function_exists('getNbComments')) { function getNbComments($a) { $data = $GLOBALS['sql_object']->DBSelect(SQL_getCommentsNumber($a)); return $data[0]['nb']; } } if(!function_exists('displayComments')) { function displayComments($a, $moderation = false, $get_permalink = false) { echo getComments($a, $moderation, $get_permalink); } } if(!function_exists('getComments')) { function getComments($a, $moderation = false, $get_permalink = false) { $comm = new comment; $comments = $comm->get($a, $GLOBALS['sql_object']); if(count($comments) == 0 || $comments == 0) { return '

' . _t('comment', 'nocomment_yet') . '

'; } return getMarkup($comments, $moderation, $get_permalink); } } if(!function_exists('postCommentAction')) { function postCommentAction($a) { // comment submit if(isset($_POST['cbody'])) { $arr = array(); 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'; $comm = new comment; $passed = $comm->checkDataIntegrity($arr); // errors on input if(is_string($passed)) { $msg = '

'. $passed .'

'; // everything is OK } else { $r = $comm->add($arr, $GLOBALS['sql_object']); if(!is_numeric($r)) system_error('adding comment on ' . $arr['module'] . '/' . $arr['module_id']); // we send an email to default user for moderation if needed emailModerators($arr, $r, $comm); // we notify users if needed notifyUsers($arr, $r, $comm); $msg = '' . _t('comment', 'successful') . ''; (COMMENT_MODERATION == 1) ? $msg .= '
'._t('comment', 'moderation_msg') : ''; $msg = '

'. $msg .'

'; echo ''; footerAddJS('../lib/js/jquery.smooth-scroll.min.js'); } echo $msg; return true; } return false; } } if(!function_exists('displayCommentForm')) { function displayCommentForm($a) { // prapare vars fo form isset($a['rub']) ? $rub = $a['rub'] : $rub = $_REQUEST['rub']; isset($a['id']) ? $id = $a['id'] : $id = $_REQUEST['id']; $f_name = ''; $f_email = ''; $f_url = ''; $f_body = ''; $f_notification =''; // comment submit if(isset($_POST['cbody'])) { $arr = array(); 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'; $comm = new comment; $passed = $comm->checkDataIntegrity($arr); // errors on input if(is_string($passed)) { 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 = '

'.sprintf(_t('comment', 'only_registered'), $link).'

'; } else { $content = '

'._t('comment', 'add').'

'; if(!isset($_COOKIE['linea21']['login'])) { $content .= '

'; } else { $content .= '

'.sprintf(_t('comment', 'logged-in_post'), $_COOKIE['linea21']['login']).'

'; } $content .= '

'; // no ability to subscribe on 'contribute' module if(COMMENT_NOTIFICATION == 1 && $a['module']!='contribute') { $content .= '

'; } $content .= ' '; if(COMMENT_MODERATION == 1) { if(!isset($_COOKIE['linea21']['login']) || (isset($_COOKIE['linea21']['login']) && COMMENT_MODERATE_REGISTERED == 1)) $content .= '

'._t('comment', 'moderation_msg').'

'; } $content .= '
'; } // for ajax implementation footerAddJS('../lib/js/comment_submit.js'); echo $content; } } if(!function_exists('getMarkup')) { function getMarkup($comments, $moderation = false, $get_permalink = false) { $str = ''; $registered =''; $class= 'odd'; foreach($comments as $c) { $cdate = $c['comment_date_crea_display']; $cdateshort = substr($c['comment_date_crea_display'], 0, 10); $cbody = formatText($c['comment_body']); (trim($class) == 'odd') ? $class = '' : $class = ' odd'; if(!empty($c['profile_avatar'])) { $avatar = '../'. $c['profile_avatar']; } else { $avatar = THEME_PUBLIC_PATH. 'images/no_avatar.png'; } if($c['comment_status']=='D') { $extraclass = ' to-moderate'; if(CURRENT_APP != 'admin') { $tomoderate = '

'._t('comment', 'to_moderate').'

'; } else { $tomoderate = ''; } } else { $extraclass = ''; $tomoderate = ''; } if($c['comment_user_id']!=0) { if(CURRENT_APP == 'admin') { $link = 'index.php?rub=user&todo=det&id='.$c['comment_user_id']; $data = $GLOBALS['sql_object']->DBSelect(SQL_getUserInfo($c['comment_user_id'])); $cemail = ' - '.$data[0]['profile_email'].''; $registered = ' '._t('comment', 'registered_user').' '; } else { $link = HrefMaker(array('rub' => $GLOBALS['links'][U_L]['user-profile']['linkvalue'], 'id' => $c['user_id'], 'name' => $c['user_login'])); $cemail = ''; } $cname = ''.$c['user_login'].''; $cname_raw = $c['user_login']; } else { if(CURRENT_APP == 'admin') { $cemail = ' - '.$c['comment_email'].''; $registered = ''; } else { $cemail = ''; } if(!empty($c['comment_url'])) $cname = ''.$c['comment_name'].''; else { $cname = $c['comment_name']; } $cname_raw = $c['comment_name']; } $item = itemMapping($c['comment_module']); if($get_permalink == true) { $permalink = '#'.$c['comment_id'].''; } else { $permalink = '#'.$c['comment_id']; } if($c['comment_status']== 'E') { $marker = _t('comment', 'disapproved'); $cmarker = ' disapprove'; } if($c['comment_status']== 'P') { $marker = _t('comment', 'approved'); $cmarker = ' approve'; } if($c['comment_status']== 'D') { $marker = _t('comment', 'awaiting'); $cmarker = ' awaiting'; } $str .= '
'.$cname_raw.'
' . $cname . $registered . $cemail.'
'. $permalink .' - '. $cdateshort .'
'. formatText($cbody, '2HTML') .'
'.$tomoderate; if($moderation === true || ( $moderation == 'smart' && $c['comment_status'] == 'D') ) { $str .= '
'.ucfirst(_t('comment', 'approve')).' '.ucfirst(_t('comment', 'disapprove')).' '.ucfirst(_t('comment', 'delete')).'
'.$marker.'
'; } if(CURRENT_APP == 'admin') { if($item['link'] == 'library') { $key = 'expandedFolder'; } else { $key = 'id'; } if($item['link'] != 'contribute') { $str .= '

'. _t('comment', 'posted_in') .' '.$c['item_title'].' ('. $item['name']. ')

'; } else { // no link to item for 'contribute' module $str .= '

'. _t('comment', 'posted_in') .' '. $item['name']. '

'; } } $str .= '
'; } return $str; } } /** * notifyUsers() * @param array * @param integer * @param object * @param bool * $arr : array of needed data * $id : inserted comment id * $o : comment object * $overpass : to overpass tests */ if(!function_exists('notifyUsers')) { function notifyUsers($arr, $id, $o, $overpass = false) { $pass = false; // we prepare values $arr['cid'] = $id; $a = getValues($arr); $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']))) { $pass = true; } 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; $a['adminuser'] = true; include(themePath('../comment/mail_actions.php')); include('../mail/template.php'); } } } /** * emailModerators() * @param array * @param integer * @param object * $arr : array of needed data * $id : inserted comment id * $o : comment object */ if(!function_exists('emailModerators')) { function emailModerators($arr, $id, $o) { 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; $arr['cid'] = $r; $a = getValues($arr); if($arr['module'] != 'contribute') { $data = $o->getCommentItem($arr, $GLOBALS['sql_object']); } else { $data[0]['item_title'] = _t('comment', 'contribute_item'); } $a['item_title'] = $data[0]['item_title']; $a['action'] = 'moderate_comment'; $a['recipient'] = SITE_MAIL; // print_r($a); include(themePath('../comment/mail_actions.php')); include('../mail/template.php'); } } } if(!function_exists('getValues')) { function getValues($a) { $output = array(); if(!empty($a['user_id'])) { $data = $GLOBALS['sql_object']->DBSelect(SQL_getUserInfo($a['user_id'])); $output['name'] = $data[0]['user_login']; $output['author_email'] = $data[0]['profile_email']; } else { $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'; $item = itemMapping($a['module']); $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']); if($wg[1] == 'shared') { $output['item_link'] = SITE_ROOT_URL . 'public/index.php?rub='.$GLOBALS['links'][U_L]['workgroup']['linkvalue']; } else { $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']; } else { $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'; return $output; } } if(!function_exists('getAjaxFunction')) { function getAjaxFunction($data = '') { $str = ''; footerAddJS('../lib/js/jquery.color.js'); return $str; } } if(!function_exists('itemMapping')) { function itemMapping($module) { $a = array(); $a['name'] = _t('comment_map', $module); switch ($module) { case 'news': $a['link'] = 'news'; break; case 'project': $a['link'] = 'project'; break; case 'workgroups': $a['link'] = 'workshop'; break; case 'indicator': $a['link'] = 'dashboard'; break; case 'publication': $a['link'] = 'publication'; break; case 'report': $a['link'] = 'workshoprep'; break; case 'files': $a['link'] = 'library'; break; case 'contribute': $a['link'] = 'contribute'; break; default: die($module . ' is not a valid option.'); break; } return $a; } } ?>