From: Ummon Date: Thu, 23 Apr 2020 16:43:19 +0000 (+0200) Subject: Merge branch 'master' of gburri.org:euphorik X-Git-Url: https://git.euphorik.ch/?p=euphorik.git;a=commitdiff_plain;h=808fb60f6c10dfcaccee94c6a49f768de84dc2ef;hp=a43e9c0197a98e1ae68e7a50eece6b22d55467d5 Merge branch 'master' of gburri.org:euphorik --- diff --git a/.gitignore b/.gitignore index 5b3f348..7c8641d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ *.iws *.beam -var/ \ No newline at end of file +var/ +/BD +/data \ No newline at end of file diff --git a/doc/server_architecture.svg b/doc/server_architecture.svg index 8a00377..c6002b4 100644 --- a/doc/server_architecture.svg +++ b/doc/server_architecture.svg @@ -532,7 +532,7 @@ y="359.74429" x="77.082535" id="tspan2541" - sodipodi:role="line">formater + sodipodi:role="line">formatter - + diff --git a/js/chat/commandes.js b/js/chat/commandes.js index 871e22b..cbf522d 100644 --- a/js/chat/commandes.js +++ b/js/chat/commandes.js @@ -27,20 +27,20 @@ * /nick * Modifie le nick courant */ -euphorik.Commandes = function(client, pageMinichat, util, formater) { +euphorik.Commandes = function(client, pageMinichat, util, formatter) { var thisCommandes = this; this.client = client; this.pageMinichat = pageMinichat; this.util = util; - this.formater = formater; + this.formatter = formatter; // construction du texte d'aide (liste des commandes) de manière statique this.texteAide = "

Commandes

    "; objectEach( euphorik.Commandes.liste, function(name, commande) { - thisCommandes.texteAide += "
  • " + thisCommandes.formater.completeProcessing(commande.usage) + " : " + thisCommandes.formater.completeProcessing(commande.description) + "
  • "; + thisCommandes.texteAide += "
  • " + thisCommandes.formatter.completeProcessing(commande.usage) + " : " + thisCommandes.formatter.completeProcessing(commande.description) + "
  • "; } ); this.texteAide += "
"; diff --git a/js/chat/conversation.js b/js/chat/conversation.js index 8c11752..4deb11c 100644 --- a/js/chat/conversation.js +++ b/js/chat/conversation.js @@ -35,7 +35,7 @@ euphorik.Conversation = function(conversations, num) { this.id = Math.floor(Math.random() * 1000000).toString(36); this.util = this.conversations.util; - this.formater = this.conversations.formater; + this.formatter = this.conversations.formatter; this.client = this.conversations.client; this.idDernierMessageAffiche = 0; @@ -107,7 +107,7 @@ euphorik.Conversation.prototype.getMessageReduit = function() { * @racine un message représentant la racine de la conversation, vaut undefined pour la conversation générale */ euphorik.Conversation.prototype.setRacine = function(racineElement) { - this.racine = new euphorik.Message(this.client, this.formater, racineElement); + this.racine = new euphorik.Message(this.client, this.formatter, racineElement); }; /** diff --git a/js/chat/conversations.js b/js/chat/conversations.js index ea7e742..05da80e 100644 --- a/js/chat/conversations.js +++ b/js/chat/conversations.js @@ -21,9 +21,9 @@ /** * Représente l'ensemble des conversations affichés. */ -euphorik.Conversations = function(client, formater, util, communication, fragment) { +euphorik.Conversations = function(client, formatter, util, communication, fragment) { this.client = client; - this.formater = formater; + this.formatter = formatter; this.util = util; this.fragment = fragment; @@ -247,7 +247,7 @@ euphorik.Conversations.prototype.ajouterMessage = function(element, numConversat var message = new euphorik.Message( this.client, - this.formater, + this.formatter, element ); diff --git a/js/chat/message.js b/js/chat/message.js index b3e5f12..e7439c9 100644 --- a/js/chat/message.js +++ b/js/chat/message.js @@ -25,9 +25,9 @@ euphorik.Reponse = function(id, nick, login) { /** * Représente un message. */ -euphorik.Message = function(client, formater, element) { +euphorik.Message = function(client, formatter, element) { this.client = client; - this.formater = formater; + this.formatter = formatter; this.id = element.id; this.auteurId = element.user_id; @@ -118,9 +118,9 @@ euphorik.Message.prototype.XHTML = function(messagePair, pre) { // construit l'identifiant de la personne var identifiant = - this.client.nickFormat === "nick" || this.login === "" ? this.formater.completeProcessing(this.nick) : - (this.client.nickFormat === "login" ? this.formater.completeProcessing(this.login) : - this.formater.completeProcessing(this.nick) + "(" + this.formater.completeProcessing(this.login) +")" ); + this.client.nickFormat === "nick" || this.login === "" ? this.formatter.completeProcessing(this.nick) : + (this.client.nickFormat === "login" ? this.formatter.completeProcessing(this.login) : + this.formatter.completeProcessing(this.nick) + "(" + this.formatter.completeProcessing(this.login) +")" ); var XHTMLrepondA = ""; var debut = true; @@ -128,7 +128,7 @@ euphorik.Message.prototype.XHTML = function(messagePair, pre) { if (!debut) { XHTMLrepondA += ", "; } - XHTMLrepondA += thisMessage.formater.completeProcessing(rep.nick); + XHTMLrepondA += thisMessage.formatter.completeProcessing(rep.nick); debut = false; }); if (XHTMLrepondA) { @@ -148,6 +148,6 @@ euphorik.Message.prototype.XHTML = function(messagePair, pre) { "" + "" + XHTMLrepondA + - "" + this.formater.completeProcessing(this.contenu, this.nick) + "" + + "" + this.formatter.completeProcessing(this.contenu, this.nick) + "" + ""; }; diff --git a/js/euphorik.js b/js/euphorik.js index 3f45e2d..893a32a 100755 --- a/js/euphorik.js +++ b/js/euphorik.js @@ -25,8 +25,8 @@ var euphorik = {}; $(document).ready( function() { var fragment = new Fragment(); - var formater = new euphorik.Formater(); - var util = new euphorik.Util(formater); + var formatter = new euphorik.Formatter(); + var util = new euphorik.Util(formatter); var communication = new euphorik.Communication( function(data) { util.messageDialog(data.error_message); }, function() { util.showWaitBar(); }, @@ -59,16 +59,16 @@ $(document).ready( $("#menu .register").click(function(){ pages.displayPage("register"); }); $("#menu .about").click(function(){ pages.displayPage("about"); }); - // TODO: simplification : such link[1] should be created and automatically open the right page without + // TODO : simplification : such link[1] should be created and automatically open the right page without // explicitly add a page. // [1] : Terms of use $("#footer .termsOfUse").click(function(){ pages.displayPage("terms_of_use"); }); - pages.addPage(new euphorik.PageMinichat(client, formater, util, communication), true); - pages.addPage(new euphorik.PageAdmin(client, formater, util, communication)); - pages.addPage(new euphorik.PageProfile(client, formater, util)); - pages.addPage(new euphorik.PageRegister(client, formater, util)); - pages.addPage(new euphorik.PageAbout(client, formater, util, communication)); + pages.addPage(new euphorik.PageMinichat(client, formatter, util, communication), true); + pages.addPage(new euphorik.PageAdmin(client, formatter, util, communication)); + pages.addPage(new euphorik.PageProfile(client, formatter, util)); + pages.addPage(new euphorik.PageRegister(client, formatter, util)); + pages.addPage(new euphorik.PageAbout(client, formatter, util, communication)); pages.addPage("terms_of_use"); pages.displayPage(); // display the default page diff --git a/js/formater.js b/js/formater.js deleted file mode 100644 index a4fbc23..0000000 --- a/js/formater.js +++ /dev/null @@ -1,183 +0,0 @@ -// coding: utf-8 -// Copyright 2008 Grégory Burri -// -// This file is part of Euphorik. -// -// Euphorik is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Euphorik is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Euphorik. If not, see . - -/*jslint laxbreak:true */ - -/** - * An object for text formatting like Wiki syntax or smiles substitution. - * TODO : improve the performance of the smiles substitution - */ -euphorik.Formater = function() { - this.smiles = euphorik.conf.smiles; - this.protocols = "http|https|ed2k"; - - this.regexUrl = new RegExp("(?:(?:" + this.protocols + ")://|www\\.)[^ ]*", "gi"); - this.regexImg = new RegExp("^.*?\\.(gif|jpg|png|jpeg|bmp|tiff)$", "i"); - this.regexDomain = new RegExp("^(?:(?:" + this.protocols + ")://)(.*?)(?:$|/).*$", "i"); - this.regexTestIfProtocolExists = new RegExp("^(?:" + this.protocols + ")://.*$", "i"); - this.regexProtocolName = new RegExp("^(.*?)://"); -}; - -/** - * Formats a nick given by the user. - * Trim and remove "{..}". - * @param nick the given nick - * @return the cleaned nick - */ -euphorik.Formater.prototype.formatNick = function(nick) { - return nick.replace(/\{|\}/g, "").trim(); -}; - -euphorik.Formater.prototype.getSmilesHTML = function() { - var XHTML = ""; - objectEach(this.smiles, function(name) { - XHTML += "\"""; - }); - return XHTML; -}; - -/** - * Complete fomratting process applied to a text. - * - Remove HTML markups - * - Substitutes wiki syntax with HTML - * - Replaces URL with 'a' tag - * - Replaces smiles with HTML - * - Replaces the link to a conversation with HTML - * @m the raw message - * @nick optional, attaches the nick and the message to each images like " : " - */ -euphorik.Formater.prototype.completeProcessing = function(m, nick) { - return this.processConversationLinks(this.processSmiles(this.traiterURL(this.traiterWikiSyntaxe(this.remplacerBalisesHTML(m)), nick))); -}; - -/** - * Processes all conversation links. - * The user can click on a conversation link to open it. - * A link is a number in between brackets like that : "{5F}" where '5F' is the id of the root message. - * This link will be turn in '{5F}' which can be clicked to open the '5F' conversation. - */ -euphorik.Formater.prototype.processConversationLinks = function(m) { - return m.replace( - /\{\w+\}/g, - function(lien) { - return "" + lien + ""; - } - ); -}; - -/** - * Substitute the smiles (':)', ':P', etc.) with HTML. - * FIXME : This function is very heavy, to optimize ! - * Average : 234ms - */ -euphorik.Formater.prototype.processSmiles = function(m) { - objectEach(this.smiles, function(name, smiles) { - for (var i = 0; i < smiles.length; i++) { - m = m.replace(smiles[i], "\"""); - } - }); - return m; -}; - -euphorik.Formater.prototype.remplacerBalisesHTML = function(m) { - return m.replace(//g, ">").replace(/"/g, """); -}; - -euphorik.Formater.prototype.traiterURL = function(m, nick) { - var thisFormater = this; - var traitementUrl = function(url) { - // si ya pas de protocole on rajoute "http://" - if (!thisFormater.regexTestIfProtocolExists.test(url)) { - url = "http://" + url; - } - var extension = thisFormater.getShort(url); - return "[" + extension[0] + "]"; - }; - return m.replace(this.regexUrl, traitementUrl); -}; - -/** - * Formatage en utilisant un sous-ensemble des règles de Textile : http://en.wikipedia.org/wiki/Textile_(markup_language). - * par exemple _italic_ devient italic. - */ -euphorik.Formater.prototype.traiterWikiSyntaxe = function(m) { - return m.replace( - /(?:^| )_(.*?)_(?:$| )/g, - function(texte, c1, c2, c3) { - return '' + c1 + c2 + c3 + ''; - } - ).replace( - /(?:^| )\*(.*?)\*(?:$| )/g, - function(texte, c1, c2, c3) { - return '' + c1 + c2 + c3 + ''; - } - ); -}; - -/** - * Renvoie une version courte de l'url. - * par exemple : http://en.wikipedia.org/wiki/Yakov_Smirnoff devient en.wikipedia.org - */ -euphorik.Formater.prototype.getShort = function(url) { - var estUneImage = false; - var versionShort = null; - var rechercheImg = this.regexImg.exec(url); - - if (rechercheImg) { - versionShort = rechercheImg[1].toLowerCase(); - if (versionShort === "jpeg") { - versionShort = "jpg"; // jpeg -> jpg - } - estUneImage = true; - } else { - var rechercheDomaine = this.regexDomain.exec(url); - if (rechercheDomaine && rechercheDomaine.length >= 2) { - versionShort = rechercheDomaine[1]; - } else { - var protocolName = this.regexProtocolName.exec(url); - if (protocolName && protocolName.length >= 2) { - versionShort = protocolName[1]; - } - } - } - - return [versionShort ? versionShort : "url", estUneImage]; - }; - -euphorik.Formater.prototype.supprimerSmiles = function(m) { - objectEach(this.smiles, function(name, smiles) { - for (var i = 0; i < smiles.length; i++) { - m = m.replace(smiles[i], ""); - } - }); - return m; -}; - -/** - * Traite les nick et messages à être affiché dans le titre d'une image visualisé avec lightbox. - * Supprime les smiles pour pas qu'ils puissent être remplacés par la fonction 'processSmiles'. - * TODO : trouver un moyen pour que les smiles puissent être conservés - */ -euphorik.Formater.prototype.traiterPourFenetreLightBox = function(M, urlCourante) { - var thisFormater = this; - var traitementUrl = function(url) { - return "[" + thisFormater.getShort(url)[0] + (urlCourante === url ? "*" : "") + "]"; - }; - - return this.remplacerBalisesHTML(this.supprimerSmiles(M)).replace(this.regexUrl, traitementUrl); -}; diff --git a/js/formatter.js b/js/formatter.js new file mode 100644 index 0000000..b1227f0 --- /dev/null +++ b/js/formatter.js @@ -0,0 +1,183 @@ +// coding: utf-8 +// Copyright 2008 Grégory Burri +// +// This file is part of Euphorik. +// +// Euphorik is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Euphorik is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Euphorik. If not, see . + +/*jslint laxbreak:true */ + +/** + * An object for text formatting like Wiki syntax or smiles substitution. + * TODO : improve the performance of the smiles substitution + */ +euphorik.Formatter = function() { + this.smiles = euphorik.conf.smiles; + this.protocols = "http|https|ed2k"; + + this.regexUrl = new RegExp("(?:(?:" + this.protocols + ")://|www\\.)[^ ]*", "gi"); + this.regexImg = new RegExp("^.*?\\.(gif|jpg|png|jpeg|bmp|tiff)$", "i"); + this.regexDomain = new RegExp("^(?:(?:" + this.protocols + ")://)(.*?)(?:$|/).*$", "i"); + this.regexTestIfProtocolExists = new RegExp("^(?:" + this.protocols + ")://.*$", "i"); + this.regexProtocolName = new RegExp("^(.*?)://"); +}; + +/** + * Formats a nick given by the user. + * Trim and remove "{..}". + * @param nick the given nick + * @return the cleaned nick + */ +euphorik.Formatter.prototype.formatNick = function(nick) { + return nick.replace(/\{|\}/g, "").trim(); +}; + +euphorik.Formatter.prototype.getSmilesHTML = function() { + var XHTML = ""; + objectEach(this.smiles, function(name) { + XHTML += "\"""; + }); + return XHTML; +}; + +/** + * Complete formatting process applied to a text. + * - Remove HTML markups + * - Substitutes wiki syntax with HTML + * - Replaces URL with 'a' tag + * - Replaces smiles with HTML + * - Replaces the link to a conversation with HTML + * @m the raw message + * @nick optional, attaches the nick and the message to each images like " : " + */ +euphorik.Formatter.prototype.completeProcessing = function(m, nick) { + return this.processConversationLinks(this.processSmiles(this.traiterURL(this.traiterWikiSyntaxe(this.remplacerBalisesHTML(m)), nick))); +}; + +/** + * Processes all conversation links. + * The user can click on a conversation link to open it. + * A link is a number in between brackets like that : "{5F}" where '5F' is the id of the root message. + * This link will be turn in '{5F}' which can be clicked to open the '5F' conversation. + */ +euphorik.Formatter.prototype.processConversationLinks = function(m) { + return m.replace( + /\{\w+\}/g, + function(lien) { + return "" + lien + ""; + } + ); +}; + +/** + * Substitute the smiles (':)', ':P', etc.) with HTML. + * FIXME : This function is very heavy, to optimize ! + * Average : 234ms + */ +euphorik.Formatter.prototype.processSmiles = function(m) { + objectEach(this.smiles, function(name, smiles) { + for (var i = 0; i < smiles.length; i++) { + m = m.replace(smiles[i], "\"""); + } + }); + return m; +}; + +euphorik.Formatter.prototype.remplacerBalisesHTML = function(m) { + return m.replace(//g, ">").replace(/"/g, """); +}; + +euphorik.Formatter.prototype.traiterURL = function(m, nick) { + var thisFormatter = this; + var traitementUrl = function(url) { + // si ya pas de protocole on rajoute "http://" + if (!thisFormatter.regexTestIfProtocolExists.test(url)) { + url = "http://" + url; + } + var extension = thisFormatter.getShort(url); + return "[" + extension[0] + "]"; + }; + return m.replace(this.regexUrl, traitementUrl); +}; + +/** + * Formatage en utilisant un sous-ensemble des règles de Textile : http://en.wikipedia.org/wiki/Textile_(markup_language). + * par exemple _italic_ devient italic. + */ +euphorik.Formatter.prototype.traiterWikiSyntaxe = function(m) { + return m.replace( + /(?:^| )_(.*?)_(?:$| )/g, + function(texte, c1, c2, c3) { + return '' + c1 + c2 + c3 + ''; + } + ).replace( + /(?:^| )\*(.*?)\*(?:$| )/g, + function(texte, c1, c2, c3) { + return '' + c1 + c2 + c3 + ''; + } + ); +}; + +/** + * Renvoie une version courte de l'url. + * par exemple : http://en.wikipedia.org/wiki/Yakov_Smirnoff devient en.wikipedia.org + */ +euphorik.Formatter.prototype.getShort = function(url) { + var estUneImage = false; + var versionShort = null; + var rechercheImg = this.regexImg.exec(url); + + if (rechercheImg) { + versionShort = rechercheImg[1].toLowerCase(); + if (versionShort === "jpeg") { + versionShort = "jpg"; // jpeg -> jpg + } + estUneImage = true; + } else { + var rechercheDomaine = this.regexDomain.exec(url); + if (rechercheDomaine && rechercheDomaine.length >= 2) { + versionShort = rechercheDomaine[1]; + } else { + var protocolName = this.regexProtocolName.exec(url); + if (protocolName && protocolName.length >= 2) { + versionShort = protocolName[1]; + } + } + } + + return [versionShort ? versionShort : "url", estUneImage]; + }; + +euphorik.Formatter.prototype.supprimerSmiles = function(m) { + objectEach(this.smiles, function(name, smiles) { + for (var i = 0; i < smiles.length; i++) { + m = m.replace(smiles[i], ""); + } + }); + return m; +}; + +/** + * Traite les nick et messages à être affiché dans le titre d'une image visualisé avec lightbox. + * Supprime les smiles pour pas qu'ils puissent être remplacés par la fonction 'processSmiles'. + * TODO : trouver un moyen pour que les smiles puissent être conservés + */ +euphorik.Formatter.prototype.traiterPourFenetreLightBox = function(M, urlCourante) { + var thisFormatter = this; + var traitementUrl = function(url) { + return "[" + thisFormatter.getShort(url)[0] + (urlCourante === url ? "*" : "") + "]"; + }; + + return this.remplacerBalisesHTML(this.supprimerSmiles(M)).replace(this.regexUrl, traitementUrl); +}; diff --git a/js/pageAbout.js b/js/pageAbout.js index 9a72139..e5da1cb 100644 --- a/js/pageAbout.js +++ b/js/pageAbout.js @@ -16,12 +16,12 @@ // You should have received a copy of the GNU General Public License // along with Euphorik. If not, see . -euphorik.PageAbout = function(client, formater, util, communication) { +euphorik.PageAbout = function(client, formatter, util, communication) { this.name = "about"; this.client = client; - this.formater = formater; - this.util = util; + this.formatter = formatter; + this.util = util; this.communication = communication; }; diff --git a/js/pageAdmin.js b/js/pageAdmin.js index fe464b8..6b1819d 100644 --- a/js/pageAdmin.js +++ b/js/pageAdmin.js @@ -21,11 +21,11 @@ /*jslint laxbreak:true */ -euphorik.PageAdmin = function(client, formater, util, communication) { +euphorik.PageAdmin = function(client, formatter, util, communication) { this.name = "admin"; this.client = client; - this.formater = formater; + this.formatter = formatter; this.util = util; this.communication = communication; @@ -87,8 +87,8 @@ euphorik.PageAdmin.prototype.majIPs = function() { '|'; ip.users.each(function(j, user) { XHTML += (j > 0 ? ", " : "") + - '' + thisPageAdmin.formater.completeProcessing(user.nick) + '' + - (user.login === "" ? "" : ''); + '' + thisPageAdmin.formatter.completeProcessing(user.nick) + '' + + (user.login === "" ? "" : ''); }); XHTML += 'débannir'; }); diff --git a/js/pageMinichat.js b/js/pageMinichat.js index 13f3375..4068222 100755 --- a/js/pageMinichat.js +++ b/js/pageMinichat.js @@ -18,14 +18,14 @@ /*jslint laxbreak:true */ -euphorik.PageMinichat = function(client, formater, util, communication) { +euphorik.PageMinichat = function(client, formatter, util, communication) { this.name = "minichat"; this.client = client; - this.formater = formater; + this.formatter = formatter; this.util = util; this.communication = communication; - this.commandes = new euphorik.Commandes(this.client, this, this.util, this.formater); + this.commandes = new euphorik.Commandes(this.client, this, this.util, this.formatter); // permet d'éviter d'envoyer plusieurs messages simultanément en pressant // rapidement sur "enter" par exemple @@ -65,7 +65,7 @@ euphorik.PageMinichat.prototype.charger = function() { $("#posterMessage input.nick").val(this.client.nick); // cet appel ne doit pas être fait avant l'appel à 'charger' - this.conversations = new euphorik.Conversations(this.client, this.formater, this.util, this.communication, this.fragment); + this.conversations = new euphorik.Conversations(this.client, this.formatter, this.util, this.communication, this.fragment); this.chargerConversationsFragment(); @@ -118,12 +118,12 @@ euphorik.PageMinichat.prototype.charger = function() { // $("body").append('
'); // affichage des smiles - $("#smiles").append(this.formater.getSmilesHTML()).children().each( + $("#smiles").append(this.formatter.getSmilesHTML()).children().each( function(i) { var opacityBase = $(this).css("opacity"); $(this).click( function() { - thisPage.util.replaceSelection($("form#posterMessage input.message")[0], thisPage.formater.smiles[$(this).attr("class")][0].source.replace(/\\/g, "")); + thisPage.util.replaceSelection($("form#posterMessage input.message")[0], thisPage.formatter.smiles[$(this).attr("class")][0].source.replace(/\\/g, "")); } ).hover( function() { $(this).animate({opacity: 1}, 200); }, @@ -227,7 +227,7 @@ euphorik.PageMinichat.prototype.envoyerMessage = function(message) { var nick = $("form#posterMessage input.nick").val(); // (un nick vide est autorisé) - nick = this.formater.formatNick(nick); + nick = this.formatter.formatNick(nick); if (nick === euphorik.conf.defaultNick) { this.util.messageDialog("Choose a nickname"); diff --git a/js/pageProfile.js b/js/pageProfile.js index c5ea5df..1a474d7 100755 --- a/js/pageProfile.js +++ b/js/pageProfile.js @@ -16,11 +16,11 @@ // You should have received a copy of the GNU General Public License // along with Euphorik. If not, see . -euphorik.PageProfile = function(client, formater, util) { +euphorik.PageProfile = function(client, formatter, util) { this.name = "profile"; this.client = client; - this.formater = formater; + this.formatter = formatter; this.util = util; }; @@ -64,7 +64,7 @@ euphorik.PageProfile.prototype.chargerProfile = function() { $("form#profile button").click( function() { - thisPage.client.nick = thisPage.formater.formatNick($("form#profile input.nick").val()); + thisPage.client.nick = thisPage.formatter.formatNick($("form#profile input.nick").val()); thisPage.client.email = $("form#profile input.email").val(); thisPage.client.chatOrder = $("form#profile select#chatOrder option:selected").attr("value"); thisPage.client.nickFormat = $("form#profile select#affichagePseudo option:selected").attr("value"); diff --git a/js/pageRegister.js b/js/pageRegister.js index 09d3631..56be885 100755 --- a/js/pageRegister.js +++ b/js/pageRegister.js @@ -16,11 +16,11 @@ // You should have received a copy of the GNU General Public License // along with Euphorik. If not, see . -euphorik.PageRegister = function(client, formater, util) { +euphorik.PageRegister = function(client, formatter, util) { this.name = "register"; this.client = client; - this.formater = formater; + this.formatter = formatter; this.util = util; }; diff --git a/js/util.js b/js/util.js index 5feacb5..39f89b0 100644 --- a/js/util.js +++ b/js/util.js @@ -23,16 +23,16 @@ * - Print a message box to display some information for the user. * - Set a tooltip for a HTML element. * - Some text manipulation for input area. - * @formater An object for string format + * @formatter An object for string format */ -euphorik.Util = function (formater) { +euphorik.Util = function (formatter) { $("#info .close").click(function() { $("#info").slideUp(50); }); $("body").append('
').append('

'); - this.formater = formater; + this.formatter = formatter; this.bulleActive = true; }; @@ -43,7 +43,7 @@ euphorik.Util.messageType = {informatif: 0, question: 1, erreur: 2}; * @message [String] The message. * @type [euphorik.Util.messageType] The message type like 'information' or 'error'. Default is messageType.informatif. * @buttons An object where the properties are the labels and the values are functions which will be executed when a button is clicked. - * @format [bool] The message should be formated. (see 'formater.js') + * @format [bool] The message should be formated. (see 'formatter.js') * @time The time while the message is displayed. -1 for infinity. */ euphorik.Util.prototype.messageDialog = function(message, type, buttons, format, time) { @@ -59,7 +59,7 @@ euphorik.Util.prototype.messageDialog = function(message, type, buttons, format, var close = function() { $("#info").slideUp(100); }; close(); - $("#info .message").html(!thisUtil.formater || !format ? message : thisUtil.formater.completeProcessing(message)); + $("#info .message").html(!thisUtil.formatter || !format ? message : thisUtil.formatter.completeProcessing(message)); switch(type) { case euphorik.Util.messageType.informatif : $("#info #icone").attr("class", "information"); break; diff --git a/modules/erl/euphorik_bd.erl b/modules/erl/euphorik_bd.erl index aabf365..6b10f4b 100755 --- a/modules/erl/euphorik_bd.erl +++ b/modules/erl/euphorik_bd.erl @@ -19,10 +19,10 @@ % Ce module permet de gérer les données persistantes lié au site d'euphorik.ch. % Il permet d'ajouter des message, de demande les messages sur une page donnée, etc.. % Ce module utilise une base mnesia. -% @author G.Burri -module(euphorik_bd). +-author("Greg Burri "). -export([ % texte : get_texte/1, diff --git a/modules/erl/euphorik_bd_admin.erl b/modules/erl/euphorik_bd_admin.erl index a57f6fe..84fe459 100644 --- a/modules/erl/euphorik_bd_admin.erl +++ b/modules/erl/euphorik_bd_admin.erl @@ -21,7 +21,7 @@ % @author G.Burri -module(euphorik_bd_admin). - +-author("Greg Burri "). -export([ version_bd/0, create/0, diff --git a/modules/erl/euphorik_common.erl b/modules/erl/euphorik_common.erl index 9b740b9..f9e3f68 100644 --- a/modules/erl/euphorik_common.erl +++ b/modules/erl/euphorik_common.erl @@ -17,10 +17,10 @@ % along with Euphorik. If not, see . % % Module with some useful stuffs. -% @author G.Burri -module(euphorik_common). +-author("Greg Burri "). -export([ ceiling/1, delta_date_ms/2, diff --git a/modules/erl/euphorik_daemon.erl b/modules/erl/euphorik_daemon.erl index b802bbe..190458e 100755 --- a/modules/erl/euphorik_daemon.erl +++ b/modules/erl/euphorik_daemon.erl @@ -18,11 +18,10 @@ % % Module tournant en background s'occupant periodiquement de certaines tâches : % - rechargement des modules lors d'une mise en production -% Date : 05.11.2007 -% @author G.Burri -module(euphorik_daemon). +-author("Greg Burri "). -export([start/1, reload_euphorik/0, loop/0]). -include("../include/euphorik_defines.hrl"). @@ -35,7 +34,7 @@ start(_A) -> loop() -> receive - switch -> % permet de substituer le code du process par un nouveau code, voir reload_euphorik + switch -> % To reload a new code, see 'reload_euphorik/0'. euphorik_daemon:loop() end. diff --git a/modules/erl/euphorik_minichat_conversation.erl b/modules/erl/euphorik_minichat_conversation.erl index 156eaac..2d546f1 100755 --- a/modules/erl/euphorik_minichat_conversation.erl +++ b/modules/erl/euphorik_minichat_conversation.erl @@ -19,7 +19,6 @@ % Ce module permet la gestion des conversations du minichat d'euphorik. % Un message (enfant) peut répondre à des messages (ses parents). % Un message (parent) peut avoir plusieurs réponses (enfants) -% @author G.Burri % % Les conversation se compose d'une liste de tuple comprenant la conversation, du premier message de la conversation, % et d'un booleen indiquant s'il y a encore des messages @@ -34,6 +33,7 @@ -module(euphorik_minichat_conversation). +-author("Greg Burri "). -export([ conversations/4 ]). @@ -190,7 +190,7 @@ conversation(R, N, D, P) -> % @spec conversation([integer()], [integer()], [integer()]) -> {[int()], [int()]} conversation(Conv, [M | Reste], X) -> Est_deja_traite = any(fun(E) -> E =:= M end, Conv), - if Est_deja_traite -> + if Est_deja_traite -> conversation(Conv, Reste, X); true -> Enfants = euphorik_bd:enfants_id(M), diff --git a/modules/erl/euphorik_protocole.erl b/modules/erl/euphorik_protocole.erl index bf40484..ef37ace 100755 --- a/modules/erl/euphorik_protocole.erl +++ b/modules/erl/euphorik_protocole.erl @@ -18,10 +18,10 @@ % % Ce module gére les différents messages envoyés par le client (javascript) via AJAX. % Les messages donnés ainsi que les réponses sont au format JSON. -% @author G.Burri -module(euphorik_protocole). +-author("Greg Burri "). -export([ register/2, login/2, @@ -39,7 +39,7 @@ % Une utilisateur s'enregistre avec un tuple {Login, Password}. -register([{login, Login}, {password, Password}, {profile, Profile_json}], IP) -> +register([{"login", Login}, {"password", Password}, {"profile", Profile_json}], IP) -> Can_register = euphorik_bd:can_register(IP), if Can_register -> case euphorik_bd:user_by_login(Login) of @@ -54,7 +54,7 @@ register([{login, Login}, {password, Password}, {profile, Profile_json}], IP) -> erreur_register_flood() end; % Enregistrement sans {Login, Password} -register([{profile, Profile_json}], IP) -> +register([{"profile", Profile_json}], IP) -> Can_register = euphorik_bd:can_register(IP), if Can_register -> Profile = profile_from_json(Profile_json), @@ -70,7 +70,7 @@ erreur_register_flood() -> % Un utilisateur se logge (avec un couple {login, mot de passe}) -login([{login, Login}, {password, Password}], IP) -> +login([{"login", Login}, {"password", Password}], IP) -> case euphorik_bd:user_by_login_password(Login, Password) of {ok, User} -> loginUser(User, IP); @@ -79,7 +79,7 @@ login([{login, Login}, {password, Password}], IP) -> erreur(30) end; % Un utilisateur se logge (avec un cookie) -login([{cookie, Cookie}], IP) -> +login([{"cookie", Cookie}], IP) -> case euphorik_bd:user_by_cookie(Cookie) of {ok, User} -> loginUser(User, IP); @@ -106,10 +106,10 @@ generer_cookie() -> % Modification du profile. profile( [ - {cookie, Cookie}, - {login, Login}, - {password, Password}, - {profile, Profile_json} + {"cookie", Cookie}, + {"login", Login}, + {"password", Password}, + {"profile", Profile_json} ] ) -> case profile_from_json(Profile_json) of @@ -130,21 +130,21 @@ profile( profile_from_json( {struct, [ - {nick, Pseudo}, - {email, Email}, - {css, Css}, - {chat_order, Chat_order_str}, - {nick_format, Nick_format_str}, - {view_times, View_times}, - {view_tooltips, View_tooltips}, - {conversations, {array, Conversations_json}}, - {ostentatious_master, Ostentatious_master_str} + {"nick", Pseudo}, + {"email", Email}, + {"css", Css}, + {"chat_order", Chat_order_str}, + {"nick_format", Nick_format_str}, + {"view_times", View_times}, + {"view_tooltips", View_tooltips}, + {"conversations", {array, Conversations_json}}, + {"ostentatious_master", Ostentatious_master_str} ] } ) -> % décomposition de la strucure JSON Conversations = lists:foldr( - fun({struct, [{root, Racine}, {minimized, Reduit}]}, A) -> + fun({struct, [{"root", Racine}, {"minimized", Reduit}]}, A) -> % virage des messages qui n'existent pas Message_exite = euphorik_bd:message_existe(Racine), if Message_exite -> @@ -190,16 +190,16 @@ profile_from_json( % Attend un événement pour la page "Chat" % last_message id et cookie sont facultatifs -wait_event([{page, "chat"} | Data]) -> +wait_event([{"page", "chat"} | Data]) -> % traitement des inputs - Cookie = case lists:keysearch(cookie, 1, Data) of {value, {_, C}} -> C; _ -> inconnu end, - Last_message_id = case lists:keysearch(last_message_id, 1, Data) of {value, {_, Id}} -> Id; _ -> 0 end, - {value, {_, Message_count}} = lists:keysearch(message_count, 1, Data), - Main_page = case lists:keysearch(main_page, 1, Data) of {value, {_, P}} -> P; _ -> 1 end, - {value, {_, {array, Conversations_json}}} = lists:keysearch(conversations, 1, Data), + Cookie = case lists:keysearch("cookie", 1, Data) of {value, {_, C}} -> C; _ -> inconnu end, + Last_message_id = case lists:keysearch("last_message_id", 1, Data) of {value, {_, Id}} -> Id; _ -> 0 end, + {value, {_, Message_count}} = lists:keysearch("message_count", 1, Data), + Main_page = case lists:keysearch("main_page", 1, Data) of {value, {_, P}} -> P; _ -> 1 end, + {value, {_, {array, Conversations_json}}} = lists:keysearch("conversations", 1, Data), Racines_conversations = lists:map( - fun({struct, [{root, Racine}, {page, Page} | Reste]}) -> - Last_mess_conv = case Reste of [{last_message_id, L}] -> L; _ -> 0 end, + fun({struct, [{"root", Racine}, {"page", Page} | Reste]}) -> + Last_mess_conv = case Reste of [{"last_message_id", L}] -> L; _ -> 0 end, {Racine, Page, Last_mess_conv} end, Conversations_json @@ -217,12 +217,12 @@ wait_event([{page, "chat"} | Data]) -> R end; % Attend un événement pour la page "Admin" -wait_event([{page, "admin"}]) -> +wait_event([{"page", "admin"}]) -> case wait_event_page_admin() of banned_ips_refresh -> {struct, [ - {reply, "banned_ips_refresh"} + {"reply", "banned_ips_refresh"} ] }; _ -> @@ -242,13 +242,13 @@ wait_event_page_chat(User, Racines_conversations, Message_count, Last_message_id Conversations -> % Accrochez-vous ca va siouxer ;). {struct, [ - {reply, "new_messages"}, - {conversations, {array, + {"reply", "new_messages"}, + {"conversations", {array, lists:map( fun({Racine, {Conv, Plus}}) -> {struct, [ - {last_page, not Plus}, - {first, % le premier message de la conversation + {"last_page", not Plus}, + {"first", % le premier message de la conversation if Racine =:= undefined orelse Conv =:= [] -> null; true -> @@ -333,10 +333,10 @@ wait_event_page_admin() -> % Answer_to est une liste d'id (int) put_message( [ - {cookie, Cookie}, - {nick, Nick}, - {content, Content}, - {answer_to, {array, Answer_to}} + {"cookie", Cookie}, + {"nick", Nick}, + {"content", Content}, + {"answer_to", {array, Answer_to}} ] ) -> case euphorik_bd:user_by_cookie(Cookie) of @@ -366,10 +366,10 @@ put_message( % bannissement d'un utilisateur (son ip est bannie) ban( [ - {cookie, Cookie}, - {duration, Duration}, - {user_id, User_id}, - {reason, Reason} + {"cookie", Cookie}, + {"duration", Duration}, + {"user_id", User_id}, + {"reason", Reason} ]) -> % controle que l'utilisateur est un admin case euphorik_bd:user_by_cookie(Cookie) of @@ -402,9 +402,9 @@ ban( % slapage d'un user (avertissement) slap( [ - {cookie, Cookie}, - {user_id, User_id}, - {reason, Reason} + {"cookie", Cookie}, + {"user_id", User_id}, + {"reason", Reason} ]) -> % controle que l'utilisateur est un admin case euphorik_bd:user_by_cookie(Cookie) of @@ -439,8 +439,8 @@ slap( unban_ip( [ - {cookie, Cookie}, - {ip, IP} + {"cookie", Cookie}, + {"ip", IP} ] ) -> case euphorik_bd:user_by_cookie(Cookie) of @@ -454,7 +454,7 @@ unban_ip( list_banned_ips( [ - {cookie, Cookie} + {"cookie", Cookie} ] ) -> case euphorik_bd:user_by_cookie(Cookie) of @@ -462,19 +462,19 @@ list_banned_ips( { struct, [ - {reply, "list_banned_ips"}, - {list, {array, lists:map( + {"reply", "list_banned_ips"}, + {"list", {array, lists:map( fun({IP, T, Users}) -> {struct, [ - {ip, euphorik_common:serialize_ip(IP)}, - {remaining_time, format_minutes(T)}, - {users, {array, lists:map( + {"ip", euphorik_common:serialize_ip(IP)}, + {"remaining_time", format_minutes(T)}, + {"users", {array, lists:map( fun({Pseudo, Login}) -> {struct, [ - {nick, Pseudo}, - {login, Login} + {"nick", Pseudo}, + {"login", Login} ] } end, @@ -504,9 +504,9 @@ erreur(Num) -> erreur_json(Num, Mess) -> { struct, [ - {reply, "error"}, - {no, Num}, - {error_message, Mess} + {"reply", "error"}, + {"no", Num}, + {"error_message", Mess} ] }. @@ -549,34 +549,34 @@ format_date(Date) -> json_reponse_ok() -> - {struct, [{reply, "ok"}]}. + {struct, [{"reply", "ok"}]}. json_reponse_login_ok(#user{profile = Profile} = User) -> { struct, [ - {reply, "login"}, - {status, if (User#user.password =/= []) and (User#user.login =/= []) -> "auth_registered"; true -> "auth_not_registered" end}, - {cookie, User#user.cookie}, - {id, User#user.id}, - {login, User#user.login}, - {ek_master, User#user.ek_master}, - {profile, {struct, + {"reply", "login"}, + {"status", if (User#user.password =/= []) and (User#user.login =/= []) -> "auth_registered"; true -> "auth_not_registered" end}, + {"cookie", User#user.cookie}, + {"id", User#user.id}, + {"login", User#user.login}, + {"ek_master", User#user.ek_master}, + {"profile", {struct, [ - {nick, Profile#profile.pseudo}, - {email, Profile#profile.email}, - {css, Profile#profile.css}, - {chat_order, atom_to_list(Profile#profile.chat_order)}, - {nick_format, atom_to_list(Profile#profile.nick_format)}, - {view_times, Profile#profile.view_times}, - {view_tooltips, Profile#profile.view_tooltips}, - {conversations, {array, lists:map( + {"nick", Profile#profile.pseudo}, + {"email", Profile#profile.email}, + {"css", Profile#profile.css}, + {"chat_order", atom_to_list(Profile#profile.chat_order)}, + {"nick_format", atom_to_list(Profile#profile.nick_format)}, + {"view_times", Profile#profile.view_times}, + {"view_tooltips", Profile#profile.view_tooltips}, + {"conversations", {array, lists:map( fun({Racine, Reduit}) -> - {struct, [{root, Racine}, {minimized, Reduit}]} + {struct, [{"root", Racine}, {"minimized", Reduit}]} end, Profile#profile.conversations )}}, - {ostentatious_master, atom_to_list(Profile#profile.ostentatious_master)} + {"ostentatious_master", atom_to_list(Profile#profile.ostentatious_master)} ] }} ] @@ -592,25 +592,25 @@ json_message(Mess, Repond_a, User) -> Est_une_reponse_a_user = User =/= inconnu andalso euphorik_bd:est_une_reponse_a_user(User#user.id, Mess#minichat.id), {ok, #user{profile = Profile_mess} = User_mess } = euphorik_bd:user_by_id(Mess#minichat.auteur_id), {struct, [ - {id, Mess#minichat.id}, - {user_id, User_mess#user.id}, - {date, case Mess#minichat.date of undefined -> "?"; _ -> format_date(Mess#minichat.date) end}, - {system, Mess#minichat.auteur_id =:= 0}, - {owner, Est_proprietaire}, - {answered, A_repondu_a_message}, - {is_a_reply, Est_une_reponse_a_user}, - {nick, Mess#minichat.pseudo}, - {login, User_mess#user.login}, - {content, Mess#minichat.contenu}, - {root, Mess#minichat.racine_id}, - {answer_to, {array, lists:map( + {"id", Mess#minichat.id}, + {"user_id", User_mess#user.id}, + {"date", case Mess#minichat.date of undefined -> "?"; _ -> format_date(Mess#minichat.date) end}, + {"system", Mess#minichat.auteur_id =:= 0}, + {"owner", Est_proprietaire}, + {"answered", A_repondu_a_message}, + {"is_a_reply", Est_une_reponse_a_user}, + {"nick", Mess#minichat.pseudo}, + {"login", User_mess#user.login}, + {"content", Mess#minichat.contenu}, + {"root", Mess#minichat.racine_id}, + {"answer_to", {array, lists:map( fun(Id_mess) -> {ok, M} = euphorik_bd:message_by_id(Id_mess), {ok, User_reponse} = euphorik_bd:user_by_mess(M#minichat.id), - {struct, [{id, M#minichat.id}, {nick, M#minichat.pseudo}, {login, User_reponse#user.login}]} + {struct, [{"id", M#minichat.id}, {"nick", M#minichat.pseudo}, {"login", User_reponse#user.login}]} end, Repond_a )}}, - {ek_master, User_mess#user.ek_master}, - {ostentatious_master, atom_to_list(Profile_mess#profile.ostentatious_master)} + {"ek_master", User_mess#user.ek_master}, + {"ostentatious_master", atom_to_list(Profile_mess#profile.ostentatious_master)} ]}. diff --git a/modules/erl/euphorik_requests.erl b/modules/erl/euphorik_requests.erl index 8ee67a5..49cbe02 100755 --- a/modules/erl/euphorik_requests.erl +++ b/modules/erl/euphorik_requests.erl @@ -19,10 +19,10 @@ % This module responds to JSON requests via 'AJAX'. % It's defined as an Yaws 'appmods' with the url '/request'. % For instance in debug mode 'http://localhost:8090/request' will call the out/1 function. -% @author G.Burri -module(euphorik_requests). +-author("Greg Burri "). -export([out/1]). -include_lib("yaws_api.hrl"). -include("../include/euphorik_defines.hrl"). @@ -36,8 +36,10 @@ out(A) -> end, % active: to receive {tcp_closed, _} when the socket is closing. % keepalive: avoid firewalls to cut the connection. + inet:setopts(A#arg.clisock, [{active, true}, {keepalive, true}]), {value, {_, Contenu}} = lists:keysearch("action", 1, yaws_api:parse_post(A)), + Ret = traiter_message(Contenu, IP), {content, "application/json", Ret}. @@ -45,8 +47,9 @@ out(A) -> % Décode le message JSON. traiter_message(Contenu, IP) -> % extrait l'entête obligatoire des messages JSON - {ok, {struct, [{header, {struct, [{action, Action}, {version, Version_client}]}} | Reste]}} = json:decode_string(Contenu), - json:encode( + {ok, {struct, [{"header", {struct, [{"action", Action}, {"version", Version_client}]}} | Reste]}} = json2:decode_string(Contenu), + + json2:encode( if Version_client =:= ?VERSION_PROTOCOLE -> traiter_action(Action, Reste, IP); true -> diff --git a/modules/erl/euphorik_test.erl b/modules/erl/euphorik_test.erl index 9c4fdd4..a166465 100644 --- a/modules/erl/euphorik_test.erl +++ b/modules/erl/euphorik_test.erl @@ -45,7 +45,7 @@ start(N, M) -> timer:sleep(100), spawn( fun() -> - {A1, A2, A3} = now(), + {A1, A2, A3} = erlang:timestamp(), random:seed(A1, A2, A3), loop(Id, M) end diff --git a/tools/yaws.conf b/tools/yaws.conf index 6c0994d..820f310 100644 --- a/tools/yaws.conf +++ b/tools/yaws.conf @@ -1,4 +1,4 @@ -# Configuration pour euphorik.ch en mode de développement. +# Configuration pour euphorik.ch en mode de d�veloppement. logdir = /tmp @@ -15,6 +15,7 @@ include_dir = ../modules/include allowed_scripts = yaws appmods = start_mod = euphorik_daemon + auth_log = true # dir_listings = true @@ -27,7 +28,7 @@ trace = false cache_refresh_secs = 0 -# it is possible to have yaws start additional +# it is possible to have yaws start additional # application specific code at startup # runmod = my_app @@ -48,17 +49,16 @@ log_wrap_size = 1000000 log_resolve_hostname = false -# fail completely or not if yaws fails +# fail completely or not if yaws fails # to bind a listen socket fail_on_bind_err = true # If HTTP auth is used, it is possible to have a specific # auth log. -auth_log = true -# When we're running multiple yaws systems on the same +# When we're running multiple yaws systems on the same # host, we need to give each yaws system an individual # name. Yaws will write a number of runtime files under # /tmp/yaws/${id} @@ -75,12 +75,3 @@ auth_log = true # This is often nice in testing environments but not # acceptable in real live hosting scenarios pick_first_virthost_on_nomatch = true - -# All unices are broken since it's not possible to bind to -# a privileged port (< 1024) unless uid==0 -# There is a contrib in jungerl which makes it possible by means -# of an external setuid root programm called fdsrv to listen to -# to privileged port. -# If we use this feature, it requires fdsrv to be properly installed. -# Doesn't yet work with SSL. -use_fdsrv = false