Re: [TChat] Module de Tchat Communautaire

Merci pour ces remontées,


Essayer de remplacer le fichier tchatche.php dans modules/tchatche/tchatche.php par


Code PHP (php) :
Pour copier le contenu exact du code,
Veuillez citer le message
  1.  
  2. <?php
  3.  
  4. class tpl{
  5.  
  6.     function tchatche_main(){
  7.     
  8.     global $K_user,$K_mod,$K_theme;
  9.         
  10.         $main = null;
  11.         $main .= '<script type="text/javascript">'."\n";
  12.         
  13.         $main .= '
  14.         
  15.         function ajax()
  16.         {
  17.             var http_request=null;
  18.             
  19.             if (window.XMLHttpRequest) { 
  20.                 http_request = new XMLHttpRequest();
  21.             }
  22.             else if (window.ActiveXObject) 
  23.             {
  24.                 http_request = new ActiveXObject("Microsoft.XMLHTTP");
  25.             }
  26.             //on définit l\'appel de la fonction au retour serveur
  27.             http_request.onreadystatechange = function() { alert_ajax(http_request); };
  28.             
  29.             //on appelle le fichier reponse.txt
  30.             http_request.open("GET", "modules/tchatche/comments.php?cmd=show", true);
  31.             http_request.send(null);
  32.         }
  33.  
  34.         function alert_ajax(http_request)
  35.         {
  36.             if (http_request.readyState == 4)
  37.                     {
  38.                         if (http_request.status == 200)
  39.                         {
  40.                             document.getElementById(\'c_cont\').innerHTML=http_request.responseText;
  41.                             
  42.                         }
  43.                         else
  44.                         {
  45.                             alert(\'There was a problem with the request.\');
  46.                         }
  47.                     }
  48.         }
  49.         
  50.         
  51.         setInterval(\'ajax()\', 3000);
  52.         window.onload = ajax();
  53.         '."\n";
  54.         $main .= '</script>'."\n";
  55.                     
  56.         $main .= '<div id="c_cont"></div>'."\n";            
  57.         $main .= '<div id="u_online"></div>'."\n";
  58.         $main .= '<div class="clearer"></div>'."\n";        
  59.                 
  60.         echo $main;
  61.  
  62.         
  63.  
  64.     }//FIN FUNCTION tchatche_MAIN
  65.     
  66.     function tchatche_publish()
  67.     {
  68.     global $K_user,$K_mod,$K_theme;
  69.     
  70.         $main = null;        
  71.         
  72.         $main .= '<script type="text/javascript">'."\n";
  73.         $main .= '        
  74.         function submitComment(text,id)
  75.         { 
  76.         
  77.             if(text == \'\')
  78.             {
  79.         
  80.                 alert("Vous n\'avez pas rempli le champ input");
  81.                 return false;
  82.             }
  83.             else
  84.             {
  85.                 var xhr; 
  86.                 try {  xhr = new ActiveXObject(\'Msxml2.XMLHTTP\');   }
  87.                 catch (e) 
  88.                 {
  89.                     try {   xhr = new ActiveXObject(\'Microsoft.XMLHTTP\'); }
  90.                     catch (e2) 
  91.                     {
  92.                        try {  xhr = new XMLHttpRequest();  }
  93.                        catch (e3) {  xhr = false;   }
  94.                      }
  95.                 }
  96.              
  97.                 xhr.onreadystatechange  = function() 
  98.                 { 
  99.                    if(xhr.readyState  == 4)
  100.                    {
  101.                     if(xhr.status  == 200) 
  102.                     {                    
  103.                     document.getElementById(\'reponse\').innerHTML = \'<img class="tchatche-submit-success" src="'.(file_exists('modules/'.$K_mod.'/theme/ok.png') ? 'modules/'.$K_mod.'/theme/ok.png' : 'themes/'.$K_theme.'/images/ok.png' ).'" alt="" />\';
  104.                         document.getElementById(\'text\').value = \'\';
  105.                     }
  106.                     else 
  107.                     {
  108.                         document.getElementById(\'reponse\').innerHTML = \'<h5 class="tchatche-submit-error">Une erreur est intervenue dans la publication de votre commentaire</h5>\';
  109.                     }
  110.                     }
  111.                 };
  112.                 
  113.                 if(text == \'delete\')
  114.                 {
  115.                 
  116.                 xhr.open( \'POST\', "modules/'.$K_mod.'/comments.php?cmd=remove",  true); 
  117.                 xhr.setRequestHeader(\'Content-Type\', \'application/x-www-form-urlencoded\');
  118.                 
  119.                 xhr.send(\'id=\'+id);
  120.                 
  121.                 }
  122.                 
  123.                 if(text != \'delete\' && text != \'abus\')
  124.                 {
  125.  
  126.                 xhr.open( \'POST\', "modules/'.$K_mod.'/comments.php?cmd=add",  true); 
  127.                 xhr.setRequestHeader(\'Content-Type\', \'application/x-www-form-urlencoded\');                
  128.                 xhr.send(\'text=\'+text,\'\');
  129.  
  130.                 }
  131.                 
  132.                 if(text == \'abus\')
  133.                 {
  134.  
  135.                 xhr.open( \'POST\', "modules/'.$K_mod.'/comments.php?cmd=abus",  true); 
  136.                 xhr.setRequestHeader(\'Content-Type\', \'application/x-www-form-urlencoded\');
  137.                 
  138.                 xhr.send(\'id=\'+id);
  139.  
  140.                 }
  141.                 
  142.                 
  143.             }    
  144.         }
  145.  
  146.         '."\n";
  147.         $main .= '</script>'."\n";
  148.         
  149.         $main .= '<div class="tchatche-comments-box">'."\n";
  150.         
  151.         $main .= '<form action="index.php">'."\n";
  152.         $main .= '<img class="tchatche-user-infos" src="'.$K_user->avatar.'"  alt="" />'."\n";
  153.         $main .= '<input type="text" name="text" id="text" />'."\n";
  154.         $main .= '<input type="button" value="Tchater" title="Valider avec la touche entrée" onclick="submitComment(escape(document.getElementById(\'text\').value));" /><span id="reponse"></span>'."\n";
  155.         $main .= '</form>'."\n";
  156.         $main .= '<p class="clearer"></p>'."\n";
  157.         $main .= '</div>'."\n";
  158.                 
  159.         echo $main;
  160.     
  161.     }
  162.     
  163.     function tchatche_comment($data)
  164.     {
  165.     global $K_user,$K_mod,$K_theme;
  166.     
  167.  
  168.         $main  = '<div class="tchatche-comments">'."\n";
  169.         $main .=  '<img src="'.$data->u_avatar.'" alt="" class="tchatche-comments-avatar" title="'.$data->userName.'"/>'."\n";
  170.         $main .= '<div class="tchatche-comments-text"><span class="tchatche-comments-date">'.date('H:i:s',$data->time).' :</span> '. bbcode($data->text,1, 0, 0, 0, 0, 0).'</div>'."\n";
  171.         $main .= '<img src="'.(file_exists('modules/tchatche/theme/abus.png') ? 'modules/tchatche/theme/abus.png' : 'themes/'.$K_theme.'/images/abus.png' ).'" alt="" class="tchatche-abus-img" onclick="submitComment(\'abus\',\''.$data->id.'\');" title="Signaler un abus" />'."\n";
  172.         if(get_grade() >= GRD_MODOF)
  173.         {
  174.         $main .= '<img src="'.(file_exists('modules/tchatche/theme/delete.png') ? 'modules/tchatche/theme/delete.png' : 'themes/'.$K_theme.'/images/delete.png' ).'" alt="" class="tchatche-delete-img" onclick="submitComment(\'delete\',\''.$data->id.'\');" title="Supprimer"/>'."\n";
  175.         }
  176.         $main .=  '<div class="clearer"></div>'."\n";
  177.         $main .=  '</div>'."\n";
  178.         
  179.         echo $main;
  180.     
  181.     }
  182.     
  183.     function tchatche_comment_ADM($data)
  184.     {
  185.     global $K_user,$K_mod,$K_theme;
  186.     
  187.  
  188.         $main  = '<div class="tchatche-comments">'."\n";
  189.         $main .=  '<img src="'.$data->u_avatar.'" alt="" class="tchatche-comments-avatar" title="'.$data->userName.'"/>'."\n";
  190.         $main .= '<div class="tchatche-comments-text"><span class="tchatche-comments-date">'.date('H:i:s',$data->time).' :</span> '. bbcode($data->text,1, 0, 0, 0, 0, 0).'</div>'."\n";
  191.         $main .= '<a href="index.php?mod='.$K_mod.'&amp;ac=gestion&amp;cmd=valid&amp;id='.$data->id.'"><img src="'.(file_exists('modules/tchatche/theme/check.png') ? 'modules/tchatche/theme/check.png' : 'themes/'.$K_theme.'/images/check.png' ).'" alt="" class="tchatche-check-img" /></a>'."\n";
  192.         if(get_grade() >= GRD_MODOF)
  193.         {
  194.         $main .= '<a href="index.php?mod='.$K_mod.'&amp;ac=gestion&amp;cmd=remove&amp;id='.$data->id.'"><img src="'.(file_exists('modules/tchatche/theme/delete.png') ? 'modules/tchatche/theme/delete.png' : 'themes/'.$K_theme.'/images/delete.png' ).'" alt="" class="tchatche-delete-img" /></a>'."\n";
  195.         }
  196.         $main .=  '<div class="clearer"></div>'."\n";
  197.         $main .=  '</div>'."\n";
  198.         
  199.         echo $main;
  200.     
  201.     }
  202.     
  203.     function tchatche_onlineh()
  204.     {
  205.     
  206.     $main = null;
  207.     
  208.     $main .= '<h5 class="tchatche-user-online">Membres connect&eacute;s (sur 60 secondes)</h5>'."\n";
  209.     $main .= "\n".'<ul class="tchatche-online-list">'."\n";
  210.     
  211.     echo $main;
  212.     
  213.     }
  214.     
  215.     function tchatche_online($data)
  216.     {
  217.     global $K_user,$K_mod,$K_theme;
  218.     
  219.     $main = null;
  220.     $main .= '<script type="text/javascript">'."\n";
  221.     $main .= 'function online()
  222.         {
  223.             var user_online=null;
  224.             
  225.             if (window.XMLHttpRequest) { 
  226.                 user_online = new XMLHttpRequest();
  227.             }
  228.             else if (window.ActiveXObject) 
  229.             {
  230.                 user_online = new ActiveXObject("Microsoft.XMLHTTP");
  231.             }
  232.             //on définit l\'appel de la fonction au retour serveur
  233.             user_online.onreadystatechange = function() { alert_online(user_online); };
  234.             
  235.             //on appelle le fichier reponse.txt
  236.             user_online.open("GET", "modules/tchatche/online.php", true);
  237.             user_online.send(null);
  238.         }
  239.  
  240.         function alert_online(user_online)
  241.         {
  242.             if (user_online.readyState == 4)
  243.                     {
  244.                         if (user_online.status == 200)
  245.                         {
  246.                             document.getElementById(\'u_online\').innerHTML=user_online.responseText;
  247.                             
  248.                         }
  249.                         else
  250.                         {
  251.                             alert(\'There was a problem with the request.\');
  252.                         }
  253.                     }
  254.         }
  255.         
  256.         
  257.         setInterval(\'online()\', 60000);
  258.         window.onload = online();
  259.         '."\n";
  260.         $main .= '</script>'."\n";
  261.         
  262.         if(!empty($data))
  263.         {
  264.         $main .= '<li><img src="'.(file_exists('modules/tchatche/theme/user.png') ? 'modules/tchatche/theme/user.png' : 'themes/'.$K_theme.'/images/user.png' ).'" alt="" /> <a href="'.url_rw('index.php?mod=espace_membre&amp;ac=profil&amp;id='.$data->user,array($data->userName)).'" title="Dernière connexion : '.date('H:i:s',$data->last_time).'">'.$data->userName.'</a></li>'."\n";
  265.         }
  266.         
  267.         echo $main;    
  268.     }
  269.     
  270.     function tchatche_onlinef()
  271.     {
  272.     
  273.     $main = null;
  274.     $main .= '</ul>'."\n";
  275.     
  276.     echo $main;
  277.     
  278.     }
  279.  
  280. } // FIN CLASS
  281.  
  282. ?>
  283.  


Sujet écrit par Gothicae le mardi 10 janvier 2012 à 08:58

[ Imprimer ] - [ Fermer la fenêtre ]