linea21-modules
[ class tree: linea21-modules ] [ index: linea21-modules ] [ all elements ]

Source for file display.php

Documentation is available at display.php

  1. <?php
  2. /**
  3.  * @package linea21.modules
  4.  * @subpackage comment
  5.  * @author Simon Georget <simon@linea21.com>
  6.  * @version $id SVN
  7.  * @access public
  8.  * @license http://opensource.org/licenses/gpl-3.0.html
  9.  */
  10.  
  11. include_once(themePath('../comment/'.SQL.'.inc.php'));
  12. include_once('../class/class.comment.php');
  13.  
  14. if(!function_exists('getPostCommentAnchor')) {
  15.  
  16.   function getPostCommentAnchor({
  17.  
  18.     $str =     '<a id="anchor-post-comment" href="'.str_replace('&''&amp;'$_SERVER["REQUEST_URI"]).'#add-comment" title="'._t('comment''add').'">'._t('comment''add').'</a>';
  19.     return $str;
  20.   }
  21. }
  22.  
  23. if(!function_exists('getCommentsAnchor')) {
  24.  
  25.   function getCommentsAnchor($a{
  26.     $nb getNbComments($a);
  27.     $str =     '<a id="anchor-comment" href="'.str_replace('&''&amp;'$_SERVER["REQUEST_URI"]).'#comments" title="'._t('comment''go_to').'">'.sprintf(_t('comment''number')'<span id="cc">'.$nb.'</span>').'</a>';
  28.     return $str;
  29.   }
  30. }
  31.  
  32. if(!function_exists('getNbComments')) {
  33.  
  34.   function getNbComments($a{
  35.     $data $GLOBALS['sql_object']->DBSelect(SQL_getCommentsNumber($a));
  36.     return $data[0]['nb'];
  37.   }
  38.  
  39. }
  40.  
  41. if(!function_exists('displayComments')) {
  42.  
  43.   function displayComments($a$moderation false$get_permalink false{
  44.     echo getComments($a$moderation$get_permalink);
  45.   }
  46. }
  47.  
  48. if(!function_exists('getComments')) {
  49.  
  50.   function getComments($a$moderation false$get_permalink false{
  51.  
  52.     $comm new comment;
  53.     $comments $comm->get($a$GLOBALS['sql_object']);
  54.  
  55.     if(count($comments== || $comments == 0{
  56.       return '<p>' _t('comment''nocomment_yet''</p>';
  57.     }
  58.  
  59.     return getMarkup($comments$moderation$get_permalink);
  60.  
  61.   }
  62.  
  63. }
  64.  
  65. if(!function_exists('postCommentAction')) {
  66.  
  67.   function postCommentAction($a{
  68.  
  69.     // comment submit
  70.     if(isset($_POST['cbody'])) {
  71.       $arr array();
  72.  
  73.       isset($_COOKIE['linea21']['login']$arr['user_id'$_COOKIE['linea21']['id'$arr['user_id''';
  74.       $arr['module'$a['module'];
  75.       $arr['module_id'$a['module_id'];
  76.       isset($_POST['cname']$arr['name'$_POST['cname'$arr['name''';
  77.       isset($_POST['cemail']$arr['email'$_POST['cemail'$arr['email''';
  78.       isset($_POST['curl']$arr['url'$_POST['curl'$arr['url''';
  79.       isset($_POST['cbody']$arr['body'$_POST['cbody'$arr['body''';
  80.       isset($_POST['cnotification']$arr['notification''Y' $arr['notification''N';
  81.  
  82.       $comm new comment;
  83.       $passed $comm->checkDataIntegrity($arr);
  84.  
  85.       // errors on input
  86.       if(is_string($passed)) {
  87.         $msg '<p class="error">'$passed .'</p>';
  88.         // everything is OK
  89.       else {
  90.         $r $comm->add($arr$GLOBALS['sql_object']);
  91.         if(!is_numeric($r)) system_error('adding comment on ' $arr['module''/' $arr['module_id']);
  92.         // we send an email to default user for moderation if needed
  93.         emailModerators($arr$r$comm);
  94.         // we notify users if needed
  95.         notifyUsers($arr$r$comm);
  96.         $msg '<b>' _t('comment''successful''</b>';
  97.         (COMMENT_MODERATION == 1$msg .= '<br />'._t('comment''moderation_msg''';
  98.         $msg '<p class="confirm">'$msg .'</p>';
  99.         echo '<script type="text/javascript">
  100.                   $(function() {
  101.                       setTimeout(\'jQuery.smoothScroll({scrollTarget: "#com-'.$r.'"});\', '.SCROLL_DELAY.');
  102.                   });
  103.               </script>';
  104.         footerAddJS('../lib/js/jquery.smooth-scroll.min.js');
  105.       }
  106.  
  107.       echo $msg;
  108.       return true;
  109.     }
  110.  
  111.     return false;
  112.   }
  113. }
  114.  
  115. if(!function_exists('displayCommentForm')) {
  116.  
  117.   function displayCommentForm($a{
  118.  
  119.     // prapare vars fo form
  120.     isset($a['rub']$rub $a['rub'$rub $_REQUEST['rub'];
  121.     isset($a['id']$id $a['id'$id $_REQUEST['id'];
  122.  
  123.  
  124.     $f_name '';
  125.     $f_email '';
  126.     $f_url '';
  127.     $f_body '';
  128.     $f_notification ='';
  129.  
  130.     // comment submit
  131.     if(isset($_POST['cbody'])) {
  132.       $arr array();
  133.  
  134.       isset($_COOKIE['linea21']['login']$arr['user_id'$_COOKIE['linea21']['id'$arr['user_id''';
  135.       $arr['module'$a['module'];
  136.       $arr['module_id'$a['module_id'];
  137.       isset($_POST['cname']$arr['name'$_POST['cname'$arr['name''';
  138.       isset($_POST['cemail']$arr['email'$_POST['cemail'$arr['email''';
  139.       isset($_POST['curl']$arr['url'$_POST['curl'$arr['url''';
  140.       isset($_POST['cbody']$arr['body'$_POST['cbody'$arr['body''';
  141.       isset($_POST['cnotification']$arr['notification''Y' $arr['notification''N';
  142.  
  143.       $comm new comment;
  144.       $passed $comm->checkDataIntegrity($arr);
  145.  
  146.       // errors on input
  147.       if(is_string($passed)) {
  148.         if(isset($_POST['cname'])) $f_name $_POST['cname'];
  149.         if(isset($_POST['cemail'])) $f_email $_POST['cemail'];
  150.         if(isset($_POST['curl'])) $f_url $_POST['curl'];
  151.         if(isset($_POST['cbody'])) $f_body $_POST['cbody'];
  152.         if(isset($_POST['cnotification'])) $f_notification ' checked="checked"';
  153.       }
  154.  
  155.     }
  156.  
  157.  
  158.  
  159.     if(COMMENT_ONLY_REGISTERED == && !isset($_COOKIE['linea21']['login'])) {
  160.       $link HrefMaker(array('rub'=> $GLOBALS['links'][U_L]['user-prefs']['linkvalue']));
  161.       $content '<p class="info">'.sprintf(_t('comment''only_registered')$link).'</p>';
  162.     else {
  163.       $content '<div id="add-comment">
  164.                       <h3>'._t('comment''add').'</h3>
  165.                       <form id="add-comment-form" method="post" action="index.php">
  166.                       <div>';
  167.       if(!isset($_COOKIE['linea21']['login'])) {
  168.         $content .= '<p><label for="cname" class="labelised">'._t('comment''name').' : </label>
  169.                         <input type="text" name="cname" id="cname" class="shorttextfield" value="' $f_name '" /></p>
  170.                       <p><label for="cemail" class="labelised">'._t('comment''email').' : </label>
  171.                       <input type="text" name="cemail" id="cemail" class="shorttextfield" value="' $f_email '" /></p>
  172.                       <p><label for="curl" class="labelised">'._t('comment''website').' ('._t('divers''optional').') : </label>
  173.                       <input type="text" name="curl" id="curl" class="shorttextfield" value="' $f_url '" /></p>';
  174.       else {
  175.         $content .= '<p class="label-leftmargin">'.sprintf(_t('comment''logged-in_post')$_COOKIE['linea21']['login']).'</p>';
  176.       }
  177.       $content .= '<p><label for="cbody" class="labelised">'._t('comment''body').' : </label>
  178.                       <textarea name="cbody" id="cbody" cols="30"  class="shorttextfield" rows="5">' $f_body '</textarea></p>';
  179.       // no ability to subscribe on 'contribute' module
  180.       if(COMMENT_NOTIFICATION == && $a['module']!='contribute'{
  181.         $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>';
  182.       }
  183.       $content .= '<input type="hidden" name="module" id="module" value="'.$a['module'].'" />
  184.                       <input type="hidden" name="rub" id="rub" value="'.$rub.'" />
  185.                       <input type="hidden" name="id" id="id" value="'.$id.'" />';
  186.       if(COMMENT_MODERATION == 1{
  187.         if(!isset($_COOKIE['linea21']['login']|| (isset($_COOKIE['linea21']['login']&& COMMENT_MODERATE_REGISTERED == 1))
  188.         $content .= '<p class="info">'._t('comment''moderation_msg').'</p>';
  189.       }
  190.       $content .= '<input type="submit" class="submitbut" value="'._t('btn','valid').'" />
  191.                   </div>
  192.               </form>
  193.           </div>';
  194.     }
  195.     // for ajax implementation
  196.     footerAddJS('../lib/js/comment_submit.js');
  197.  
  198.     echo $content;
  199.  
  200.   }
  201.  
  202. }
  203.  
  204. if(!function_exists('getMarkup')) {
  205.  
  206.   function getMarkup($comments$moderation false$get_permalink false{
  207.  
  208.     $str '';
  209.     $registered ='';
  210.     $class'odd';
  211.  
  212.     foreach($comments as $c{
  213.       $cdate       $c['comment_date_crea_display'];
  214.       $cdateshort  substr($c['comment_date_crea_display']010);
  215.       $cbody       formatText($c['comment_body']);
  216.  
  217.       (trim($class== 'odd'$class '' $class ' odd';
  218.  
  219.       if(!empty($c['profile_avatar'])) {
  220.         $avatar '../'$c['profile_avatar'];
  221.       else {
  222.         $avatar THEME_PUBLIC_PATH'images/no_avatar.png';
  223.       }
  224.       if($c['comment_status']=='D'{
  225.         $extraclass ' to-moderate';
  226.         if(CURRENT_APP != 'admin'{
  227.           $tomoderate '<p class="moderation">'._t('comment''to_moderate').'</p>';
  228.         else {
  229.           $tomoderate '';
  230.         }
  231.       else {
  232.         $extraclass '';
  233.         $tomoderate '';
  234.       }
  235.       if($c['comment_user_id']!=0{
  236.         if(CURRENT_APP == 'admin'{
  237.           $link 'index.php?rub=user&amp;todo=det&amp;id='.$c['comment_user_id'];
  238.           $data $GLOBALS['sql_object']->DBSelect(SQL_getUserInfo($c['comment_user_id']));
  239.           $cemail ' - <a href="mailto:'.$data[0]['profile_email'].'">'.$data[0]['profile_email'].'</a>';
  240.           $registered ' '._t('comment''registered_user').' ';
  241.         else {
  242.           $link HrefMaker(array('rub' => $GLOBALS['links'][U_L]['user-profile']['linkvalue']'id' => $c['user_id']'name' => $c['user_login']));
  243.           $cemail '';
  244.         }
  245.         $cname '<a href="'$link.'" title="' $GLOBALS['links'][U_L]['user-profile']['desc'].'">'.$c['user_login'].'</a>';
  246.         $cname_raw $c['user_login'];
  247.       else {
  248.         if(CURRENT_APP == 'admin'{
  249.           $cemail ' - <a href="mailto:'.$c['comment_email'].'">'.$c['comment_email'].'</a>';
  250.           $registered '';
  251.         else {
  252.           $cemail '';
  253.         }
  254.         if(!empty($c['comment_url']))
  255.         $cname '<a href="'.$c['comment_url'].'">'.$c['comment_name'].'</a>';
  256.         else {
  257.           $cname $c['comment_name'];
  258.         }
  259.         $cname_raw $c['comment_name'];
  260.       }
  261.  
  262.       $item itemMapping($c['comment_module']);
  263.  
  264.       if($get_permalink == true{
  265.         $permalink '<a href="'.str_replace('&''&amp;'$_SERVER["REQUEST_URI"]).'#com-'.$c['comment_id'].'">#'.$c['comment_id'].'</a>';
  266.       else {
  267.         $permalink '#'.$c['comment_id'];
  268.       }
  269.       if($c['comment_status']== 'E'{
  270.         $marker _t('comment''disapproved');
  271.         $cmarker ' disapprove';
  272.       }
  273.       if($c['comment_status']== 'P'{
  274.         $marker _t('comment''approved');
  275.         $cmarker ' approve';
  276.       }
  277.       if($c['comment_status']== 'D'{
  278.         $marker _t('comment''awaiting');
  279.         $cmarker ' awaiting';
  280.       }
  281.       $str .= '<div class="comment'.$class.$extraclass.'" id="com-'.$c['comment_id'].'">
  282.                   
  283.                 <div class="avatar">
  284.                     <img src="'.$avatar.'" alt="'.$cname_raw.'" />
  285.                 </div>
  286.                 <div class="name">' $cname $registered $cemail.'</div>
  287.                 <div class="date" title="'$cdate .'">'$permalink .' - '$cdateshort .'</div>
  288.                 <div class="body">'formatText($cbody'2HTML'.'</div>'.$tomoderate;
  289.       if($moderation === true || $moderation == 'smart' && $c['comment_status'== 'D') ) {
  290.         $str .= '<div class="comment-actions">
  291.                     <a href="../comment/_ajax_admin.php?todo=approve&amp;id='.$c['comment_id'].'" class="ico_approve" title="'.ucfirst(_t('comment''approve')).'"><span>'.ucfirst(_t('comment''approve')).'</span></a>
  292.                     <a href="../comment/_ajax_admin.php?todo=disapprove&amp;id='.$c['comment_id'].'" class="ico_disapprove" title="'.ucfirst(_t('comment''disapprove')).'"><span>'.ucfirst(_t('comment''disapprove')).'</span></a>
  293.                     <a href="../comment/_ajax_admin.php?todo=del&amp;id='.$c['comment_id'].'" class="ico_delete" title="'.ucfirst(_t('comment''delete')).'"><span>'.ucfirst(_t('comment''delete')).'</span></a>
  294.                     <br style="clear:both" />
  295.                     <div class="action-marker'.$cmarker.'">'.$marker.'</div>
  296.                 </div>
  297.                 ';
  298.       }
  299.       if(CURRENT_APP == 'admin'{
  300.         if($item['link'== 'library'{
  301.           $key 'expandedFolder';
  302.         else {
  303.           $key 'id';
  304.         }
  305.         if($item['link'!= 'contribute'{
  306.           $str .= '<p class="item">'_t('comment''posted_in'.' <a href="../admin/index.php?rub='.$item['link'].'&amp;todo=det&amp;'.$key.'='.$c['comment_module_id'].'" title="'.$c['item_title'].'">'.$c['item_title'].'</a> ('$item['name']')</p>';
  307.         else {
  308.           // no link to item for 'contribute' module
  309.           $str .= '<p class="item">'_t('comment''posted_in'.' '$item['name']'</p>';
  310.         }
  311.       }
  312.       $str .= '</div>';
  313.     }
  314.     return $str;
  315.   }
  316.  
  317. }
  318.  
  319. /**
  320.  * notifyUsers()
  321.  * @param array 
  322.  * @param integer 
  323.  * @param object 
  324.  * @param bool 
  325.  *  $arr : array of needed data
  326.  *  $id : inserted comment id
  327.  *  $o : comment object
  328.  *  $overpass : to overpass tests
  329.  */
  330. if(!function_exists('notifyUsers')) {
  331.   function notifyUsers($arr$id$o$overpass false{
  332.  
  333.     $pass false;
  334.  
  335.     // we prepare values
  336.     $arr['cid'$id;
  337.     $a getValues($arr);
  338.     $data $o->getCommentItem($arr$GLOBALS['sql_object']);
  339.  
  340.     $a['item_title'$data[0]['item_title'];
  341.     $a['action''notify_comment';
  342.  
  343.     if(COMMENT_NOTIFICATION == 1{
  344.  
  345.       // we send it only if new comment is automatically approved
  346.       if(COMMENT_MODERATION == || (COMMENT_MODERATE_REGISTERED == && !empty($arr['user_id']))) {
  347.         $pass true;
  348.       }
  349.  
  350.       if($pass === true || $overpass === true{
  351.         $users_email $o->getSubscribers($arr$GLOBALS['sql_object']);
  352.  
  353.         foreach($users_email as $email{
  354.           // we don't send mail to author
  355.           if($email != $a['author_email']{
  356.             $a['recipient'$email;
  357.  
  358.             include(themePath('../comment/mail_actions.php'));
  359.             include('../mail/template.php');
  360.           }
  361.         }
  362.       }
  363.     }
  364.     // if $overpass we stop there
  365.     if($overpass === truereturn true;
  366.  
  367.     // in any case we send an email to the admin when message is posted
  368.     // if moderation is disabled
  369.     if(COMMENT_MODERATION == || (COMMENT_MODERATE_REGISTERED == && !empty($arr['user_id']))) {
  370.       $a['recipient'SITE_MAIL;
  371.       $a['adminuser'true;
  372.       include(themePath('../comment/mail_actions.php'));
  373.       include('../mail/template.php');
  374.     }
  375.  
  376.   }
  377. }
  378.  
  379. /**
  380.  * emailModerators()
  381.  * @param array 
  382.  * @param integer 
  383.  * @param object 
  384.  *  $arr : array of needed data
  385.  *  $id : inserted comment id
  386.  *  $o : comment object
  387.  */
  388. if(!function_exists('emailModerators')) {
  389.   function emailModerators($arr$id$o{
  390.  
  391.     if(COMMENT_MODERATION == 1{
  392.       // if logged-in user and no moderation on registered user, we exit
  393.       if(!empty($arr['user_id']&& COMMENT_MODERATE_REGISTERED == 0return true;
  394.  
  395.       $arr['cid'$r;
  396.       $a getValues($arr);
  397.  
  398.       if($arr['module'!= 'contribute'{
  399.         $data $o->getCommentItem($arr$GLOBALS['sql_object']);
  400.       else {
  401.         $data[0]['item_title'_t('comment''contribute_item');
  402.       }
  403.  
  404.       $a['item_title'$data[0]['item_title'];
  405.       $a['action''moderate_comment';
  406.       $a['recipient'SITE_MAIL;
  407.       //      print_r($a);
  408.       include(themePath('../comment/mail_actions.php'));
  409.       include('../mail/template.php');
  410.     }
  411.  
  412.   }
  413. }
  414.  
  415. if(!function_exists('getValues')) {
  416.   function getValues($a{
  417.  
  418.     $output array();
  419.  
  420.     if(!empty($a['user_id'])) {
  421.       $data $GLOBALS['sql_object']->DBSelect(SQL_getUserInfo($a['user_id']));
  422.       $output['name'$data[0]['user_login'];
  423.       $output['author_email'$data[0]['profile_email'];
  424.     else {
  425.       $output['name'$a['name'];
  426.       $output['author_email'$a['email'];
  427.     }
  428.     $output['body'$a['body'];
  429.     $output['moderate_link'SITE_ROOT_URL 'admin/index.php?rub=comment&todo=list&module=all&statut=D';
  430.  
  431.     $item itemMapping($a['module']);
  432.     $output['item_type'$item['name'];
  433.     $output['admin_link'SITE_ROOT_URL  'admin/index.php?rub='.$item['link'].'&todo=det&id='$a['module_id'];
  434.     $output['item_link'SITE_ROOT_URL  'public/index.php?rub='.$GLOBALS['links'][U_L][$item['link']]['linkvalue'].'&id='.$a['module_id'];
  435.  
  436.     if($a['module']=='files'{
  437.       $wg explode('/'$a['module_id']);
  438.       if($wg[1== 'shared'{
  439.         $output['item_link'SITE_ROOT_URL  'public/index.php?rub='.$GLOBALS['links'][U_L]['workgroup']['linkvalue'];
  440.       else {
  441.         $output['item_link'SITE_ROOT_URL  'public/index.php?rub='.$GLOBALS['links'][U_L]['workgroup']['linkvalue'].'&id='.$wg[1];
  442.       }
  443.       $output['item_link_comments'$output['item_link'];
  444.       $output['item_link_the_comment'$output['item_link'];
  445.     else {
  446.       $output['item_link'SITE_ROOT_URL  'public/index.php?rub='.$GLOBALS['links'][U_L][$item['link']]['linkvalue'].'&id='.$a['module_id'];
  447.       $output['item_link_comments'$output['item_link'].'#comments';
  448.       if(isset($a['cid'])) $output['item_link_the_comment'$output['item_link'].'#com-'.$a['cid'];
  449.     }
  450.     $output['unsubscribe_link'SITE_ROOT_URL  'public/index.php?rub='.$GLOBALS['links'][U_L]['comment-unsubscribe']['linkvalue'].'&name='.$a['module'].'&id='.$a['module_id'];
  451.     $output['item_link_comments'$output['item_link'].'#comments';
  452.  
  453.     return $output;
  454.   }
  455. }
  456.  
  457. if(!function_exists('getAjaxFunction')) {
  458.   function getAjaxFunction($data ''{
  459.     $str '<script type="text/javascript">
  460.                   $(function() {
  461.                       $(".comment-actions a").click(function() {
  462.                           var url = $(this).attr("href");
  463.  
  464.                         $.ajax({
  465.                             type: "GET",
  466.                           url: url,
  467.                           data: "call=ajax",
  468.                           dataType: "json",
  469.                           success: function(data){
  470.                               if(data.status == 1) {
  471.                                   if(data.page != "comment") {
  472.                                       $(data.el).addClass(data.action).fadeOut("slow");
  473.                                       // we update the comment counter
  474.                                     $("#cc").text( parseInt($("#cc").text()) - 1);
  475.                                   } else {
  476.                                       if(data.action == "del") {
  477.                                           $(data.el).addClass(data.action).fadeOut("slow");
  478.                                       } else {
  479.                                           $(data.el).removeClass("to-moderate");
  480.                                           var col = $(data.el).css("background-color");
  481.                                           
  482.                                           $(data.el + " div.action-marker").removeClass("awaiting approve disapprove").addClass(data.action).empty().text(data.msg);
  483.                                           $(data.el).css("background-color","#F2F2F2").animate({backgroundColor: col}, 1500 );
  484.                                       }
  485.                                   }
  486.                               }
  487.                           }
  488.                         });
  489.                         return false;
  490.                     });
  491.                 
  492.                   });
  493.           </script>';
  494.  
  495.     footerAddJS('../lib/js/jquery.color.js');
  496.  
  497.     return $str;
  498.   }
  499. }
  500.  
  501. if(!function_exists('itemMapping')) {
  502.  
  503.   function itemMapping($module{
  504.  
  505.     $a array();
  506.     $a['name'_t('comment_map'$module);
  507.  
  508.     switch ($module{
  509.       case 'news':
  510.         $a['link''news';
  511.         break;
  512.       case 'project':
  513.         $a['link''project';
  514.         break;
  515.       case 'workgroups':
  516.         $a['link''workshop';
  517.         break;
  518.       case 'indicator':
  519.         $a['link''dashboard';
  520.         break;
  521.       case 'publication':
  522.         $a['link''publication';
  523.         break;
  524.       case 'report':
  525.         $a['link''workshoprep';
  526.         break;
  527.       case 'files':
  528.         $a['link''library';
  529.         break;
  530.       case 'contribute':
  531.         $a['link''contribute';
  532.         break;
  533.       default:
  534.         die($module ' is not a valid option.');
  535.       break;
  536.     }
  537.     return $a;
  538.   }
  539.  
  540. }
  541.  
  542.  
  543. ?>

Documentation generated on Thu, 03 May 2012 15:03:57 +0200 by phpDocumentor 1.4.1