[SPIP Zone] [Spip-zone-commit] r16626 - in /_plugins_/_stable_/shoutbox: balise/shoutbox.php formulaires/shoutbox.html js/ js/jquery.labelhide.js plugin.xml

fonctionellement c'est de l'irc sur le web ... !

fil@rezo.net a écrit :

Author: fil@rezo.net
Date: Tue Nov 6 10:34:28 2007
New Revision: 16626

Log:
shoutbox 0.2, avec un nick, un plugin jquery maison (jquery.labelhide) pour l'interface d'edition du nick, un rechargement automatique du fragment, et toutes ces features qui font qu'on en raffole

Added:
    _plugins_/_stable_/shoutbox/js/
    _plugins_/_stable_/shoutbox/js/jquery.labelhide.js
Modified:
    _plugins_/_stable_/shoutbox/balise/shoutbox.php
    _plugins_/_stable_/shoutbox/formulaires/shoutbox.html
    _plugins_/_stable_/shoutbox/plugin.xml

Modified: _plugins_/_stable_/shoutbox/balise/shoutbox.php

--- _plugins_/_stable_/shoutbox/balise/shoutbox.php (original)
+++ _plugins_/_stable_/shoutbox/balise/shoutbox.php Tue Nov 6 10:34:28 2007
@@ -44,7 +44,7 @@
   list($objet, $type, $id, $defaut) = $args;
    // valeur par defaut du formulaire
- if (!isset($defaut)) $defaut = '...';
+ if (!isset($defaut)) $defaut = '';
    // nom de la shoutbox passe en argument #SHOUTBOX{},
   // sinon le contexte d'objet, sinon 'normal'
@@ -71,32 +71,40 @@
// http://doc.spip.org/@balise_SHOUTBOX_dyn
function balise_SHOUTBOX_dyn($defaut, $a) {
- // analyser les donnees
+ // analyser le nick envoye et poser/supprimer le cookie
+ if (_request('valide'.$a)) {
+ $nick = strval(_request('shoutbox_nick_'.$a));
+ if ($nick != strval($_COOKIE['spip_shoutbox_nick'])) {
+ include_spip('inc/cookie');
+ if (strlen($nick))
+ spip_setcookie('spip_shoutbox_nick',
+ $nick,
+ time()+7*24*3600);
+ else
+ spip_setcookie('spip_shoutbox_nick',
+ $_COOKIE['spip_shoutbox_nick'],
+ time()-3600);
+ $_COOKIE['spip_shoutbox_nick'] = $nick;
+ }
+ }
+
+ if (!$nick = htmlspecialchars($_COOKIE['spip_shoutbox_nick']))
+ $nick = $GLOBALS['auteur_session']['nom'];
    // si $_POST correspondant a notre formulaire : stocker un truc
   // dans la base de donnees
   if (_request('valide'.$a)
- AND $val = strval(_request('shoutbox_'.$a))) {
+ AND strlen($val = strval(_request('shoutbox_'.$a)))) {
     // antispam
     if (_request('nobot')) {
       spip_log('spam');
       return '';
     }
- $nom = sinon(htmlspecialchars($_COOKIE['spip_shoutbox_nick']),
- sinon($GLOBALS['auteur_session']['nom'], $GLOBALS['ip']));
-
- /*
- // est-ce une commande ? (API pas terrible, a voir...)
- if (preg_match(',^/(.*?)(\s+(.*))?$,', $val, $r)
- AND function_exists($f = 'shoutbox_command_'.$r[1]))
- $f($val, $r, $nom);
- */
-
     // stocker dans la base de donnees (ici table spip_meta)
     $ou = 'objet,auteur,texte,date';
     $quoi = _q($a) .','
- . _q($nom) .','
+ . _q(sinon($nick, $GLOBALS['ip'])) .','
       . _q($val) .','
       . 'NOW()';
     if (isset($GLOBALS['auteur_session']['id_auteur'])) {
@@ -136,7 +144,8 @@
         'defaut' => $defaut,
         'bouton' => 'ok',
         'nouveau' => isset($id), # si on vient de faire l'insertion
- 'erreur' => $erreur
+ 'erreur' => $erreur,
+ 'nick' => $nick # attention avec l'IP on perdrait le cache d'un visiteur a l'autre
       )
     );
}

Modified: _plugins_/_stable_/shoutbox/formulaires/shoutbox.html

--- _plugins_/_stable_/shoutbox/formulaires/shoutbox.html (original)
+++ _plugins_/_stable_/shoutbox/formulaires/shoutbox.html Tue Nov 6 10:34:28 2007
@@ -41,7 +41,12 @@
[(#REM)
   Bouton
]
-[<p class="spip_bouton"><input type="submit" name="valide#ENV{objet}" value="(#ENV{bouton})" /></p>]
+<p class="spip_bouton">
+<input type="submit" name="valide#ENV{objet}" value="#ENV{bouton}" />
+</p>
+
+<label for="shoutbox_nick_#ENV{objet}" class="labelhide"><:form_pet_votre_nom:></label>
+<input type="text" name="shoutbox_nick_#ENV{objet}" value="[(#ENV{nick})]" class="forml" style="width:50%;" />
</fieldset>
  [(#REM) Antispam "nobot" ]
@@ -51,23 +56,40 @@
</form>
</div>
+
+<script type='text/javascript' src='#CHEMIN{js/jquery.labelhide.js}'></script>
<script type='text/javascript'><!--
-if (window.jQuery) {
- jQuery("#formulaire_shoutbox_[(#ENV{objet})] form")
+if (window.jQuery) (function($){
+ // adresse du fragment ajax
+ var url = 'spip.php?page=shoutbox\x26objet=#ENV{objet}';
+
+ // reload : au debut, toutes les 20s, puis 22, 24... 60s
+ // si on participe on revient a 5s, puis 7, 9... 60s
+ var r = 20;
+ var reload = function() {
+ $("#contenu_shoutbox_#ENV{objet}")
+ .load(url,function(){setTimeout(reload,1000*(r=Math.min(r+2,60)));});
+ }
+ setTimeout(reload, r);
+
+ $("#formulaire_shoutbox_[(#ENV{objet})] form")
   .ajaxForm({
- url: 'spip.php?page=shoutbox\x26objet=#ENV{objet}',
+ url: url,
     target: "#contenu_shoutbox_#ENV{objet}",
     beforeSubmit: function(){
- if (!jQuery("#shoutbox_#ENV{objet}").val().length)
- return false;
- jQuery("#shoutbox_#ENV{objet}").val('');
- jQuery("#contenu_shoutbox_#ENV{objet}")
+ $("#shoutbox_#ENV{objet}").val('');
+ $("#shoutbox_nick_#ENV{objet}").blur();
+ $("#contenu_shoutbox_#ENV{objet}")
       .css('opacity', 0.5);
     },
     success: function(){
- jQuery("#contenu_shoutbox_#ENV{objet}")
+ $("#contenu_shoutbox_#ENV{objet}")
       .css('opacity', 1);
+ r = 5;
     }
   });
-}
+
+ // Masquer le champ de saisie du nick sous son label
+ $('label.labelhide').labelhide();
+})(jQuery);
// --></script>

Added: _plugins_/_stable_/shoutbox/js/jquery.labelhide.js

--- _plugins_/_stable_/shoutbox/js/jquery.labelhide.js (added)
+++ _plugins_/_stable_/shoutbox/js/jquery.labelhide.js Tue Nov 6 10:34:28 2007
@@ -0,0 +1,40 @@
+/*
+ * labelhide for jQuery (c) Fil 2007, licensed GNU/GPL or MIT
+ * cf. http://www.jquery.info/
+ */
+// hide an input and reveal it when clicking on its label
+if (window.jQuery) (function($){
+$.fn.labelhide = function(){
+return this.each(function(){
+ var label = $(this);
+ if (!label.attr('for')) return;
+
+ var input = $("input[name='"+label.attr('for')+"']");
+ if (!input.length) return;
+
+ var default_label = label.html();
+ if (input.val().length) label.html(input.val()+'&nbsp;');
+
+ input
+ .hide()
+ .blur(function(){
+ input
+ .hide();
+ label
+ .html(input.val().length ? input.val()+'&nbsp;' : default_label)
+ .show();
+ });
+
+ label
+ .click(function(){
+ label.hide();
+ input
+ .show()
+ .focus()
+ .select();
+ })
+ .css({cursor:'text'})
+ .add(input)
+ .attr('title', default_label);
+});};
+})(jQuery);

Modified: _plugins_/_stable_/shoutbox/plugin.xml

--- _plugins_/_stable_/shoutbox/plugin.xml (original)
+++ _plugins_/_stable_/shoutbox/plugin.xml Tue Nov 6 10:34:28 2007
@@ -1,7 +1,7 @@
<plugin>
         <nom>Shoutbox</nom>
         <version>
- 0.1
+ 0.2
         </version>
      <auteur>Fil</auteur>

_______________________________________________
Spip-zone-commit@rezo.net - http://listes.rezo.net/mailman/listinfo/spip-zone-commit