Commits

moumar committed 0a63a9c Draft

first version

  • Participants
  • Parent commits 75bf893

Comments (0)

Files changed (9)

-pour modifier les categories, ajouter une correspondance dans la variable $MMR_RATING_CATEGORIES.
+pour modifier les categories, ajouter une correspondance dans la variable $MEF_RATING_CATEGORIES.
 Pour la première valeur, il ne faut utiliser que les caractères a à z, 0 à 9, _ ou -. Cette première
 valeur ne doit jamais changer une fois qu'elle a été fixée.
 
 L'ordre peut être changé.
 
 pour afficher tous les critères sur la page d'un article: 
-<?php mmr_show() ?>
+<?php mef_show() ?>
 
 pour afficher un critère particulier sur la page d'un article: 
-<?php mmr_show("hebergement") ?>
+<?php mef_show("hebergement") ?>
 
 
 pour afficher les top 10 les meilleurs articles dans toutes les categories:
-<?php mmr_top(10) ?>
+<?php mef_top(10) ?>
 
 pour afficher le top 10 des meilleurs articles tous critères confondus:
-<?php mmr_top_overall(10) ?>
+<?php mef_top_overall(10) ?>
 
 pour effacer toutes les notes dans tous les articles:
-<?php mmr_clear_all() ?>
+<?php mef_clear_all() ?>
+<?php
+
+$MEF_RATING_DESCRIPTIONS = array(
+    "Nul",
+    "A la limite",
+    "Assez bien",
+    "Très bien",
+    "Excellent!"
+);
+
+$MEF_FORM_DESCRIPTION = array(
+  "annee_visite"        => array("nom" => "Année de visite", 
+                                 "type" => "select",
+                                 "valeurs" => range("1950", date('Y'))),
+  "temps_sur_place"     => array("nom" => "Temps sur place",
+                                 "type" => "checkbox",
+                                 "valeurs" => array("moins d'une semaine", "moins de 2 semaines", "moins de 1 mois")),
+  "age"                 => array("nom" => "Votre âge",
+                                 "type" => "select",
+                                 "valeurs" => array_map(function($age) { return $age." ans"; }, range(7, 100))),
+  "sexe"                => array('nom' => "Votre sexe",
+                                 "type" => "checkbox",
+                                 "valeurs" => array("homme", "femme")),
+  "type_voyage"         => array("nom" => "Type de voyage",
+                                 "type" => "select",
+                                 "valeurs" => array("Routard", "Famille", "Groupe", "indépendant", "Voyage organisé", "Hotel-club", "Expat")),
+  "villes_visitees"     => array("nom" => "Régions ou villes notables visitées",
+                                 "type" => "textarea"),
+  "ce_qui_a_plu"        => array("nom" => "Ce qui vous a plu dans ce pays",
+                                 "type" => "textarea",
+                                 "limite" => 500),
+  "ce_qui_a_deplu"      => array("nom"  => "Ce qui vous a déplu dans ce pays",
+                                 "type" => "textarea",
+                                 "limite" => 500),
+  "budget"              => array("nom" => "Budget",
+                                 "type" => "select",
+                                 "valeurs" => array('moins de 500 €', 'moins de 1000 €')),
+  #"Communication"                       => array(),
+  "hebergement"         => array("nom" => 'Hébergement', "type" => "note"),
+  "gastronomie"         => array("nom" => 'Gastronomie', "type" => "note"),
+  "accueil"             => array("nom" => 'Accueil & hospitalité', "type" => "note"),
+  "meteo"               => array("nom" => 'Météo', "type" => "note"),
+  "night-life"          => array("nom" => 'Bars/boîtes/night life', "type" => "note"),
+  "paysages"            => array("nom" => 'Paysages', "type" => "note"),
+  "culture"             => array("nom" => 'Culture/Monuments/musées', "type" => "note"),
+  "activites"           => array("nom" => 'Activités/loisirs/sport', "type" => "note"),
+  "shopping"            => array("nom" => 'Shopping', "type" => "note"),
+  "sante"               => array("nom" => 'Hygiène/Santé', "type" => "note"),
+  "securite"            => array("nom" => 'Sécurité', "type" => "note"),
+  "gay"                 => array("nom" => 'Gay-Friendly', "type" => "note"),
+  "photo"               => array("nom" => 'Intérêt photographique', "type" => "note"),
+  "deplacements"        => array("nom" => 'Déplacements intérieurs', "type" => "note"),
+  "commentaire_supp"    => array("nom" => "Commentaire supplémentaire",
+                                 "type" => "textarea",
+                                 "taille" => 500,
+                                 "facultatif" => true),
+  "bons_plans"          => array("nom" => "Bons plans",
+                                 "type" => "textarea",
+                                 "taille" => 500),
+  "recommander_ami"     => array("nom" => "Recommanderiez vous cette destination à un ami",
+                                 "type" => "checkbox",
+                                 "valeurs" => array("oui", "non")),
+  "pseudo"              => array("nom" => "Votre pseudo",
+                                 "type" => "text")
+  #(Eventuellement :)
+  #Langues:
+  #Racisme:
+);
+?>

File jquery.validate.min.js

+/*! jQuery Validation Plugin - v1.11.0 - 2/4/2013
+* https://github.com/jzaefferer/jquery-validation
+* Copyright (c) 2013 Jörn Zaefferer; Licensed MIT */
+(function(e){e.extend(e.fn,{validate:function(t){if(!this.length){t&&t.debug&&window.console&&console.warn("Nothing selected, can't validate, returning nothing.");return}var n=e.data(this[0],"validator");return n?n:(this.attr("novalidate","novalidate"),n=new e.validator(t,this[0]),e.data(this[0],"validator",n),n.settings.onsubmit&&(this.validateDelegate(":submit","click",function(t){n.settings.submitHandler&&(n.submitButton=t.target),e(t.target).hasClass("cancel")&&(n.cancelSubmit=!0)}),this.submit(function(t){function r(){var r;return n.settings.submitHandler?(n.submitButton&&(r=e("<input type='hidden'/>").attr("name",n.submitButton.name).val(n.submitButton.value).appendTo(n.currentForm)),n.settings.submitHandler.call(n,n.currentForm,t),n.submitButton&&r.remove(),!1):!0}return n.settings.debug&&t.preventDefault(),n.cancelSubmit?(n.cancelSubmit=!1,r()):n.form()?n.pendingRequest?(n.formSubmitted=!0,!1):r():(n.focusInvalid(),!1)})),n)},valid:function(){if(e(this[0]).is("form"))return this.validate().form();var t=!0,n=e(this[0].form).validate();return this.each(function(){t&=n.element(this)}),t},removeAttrs:function(t){var n={},r=this;return e.each(t.split(/\s/),function(e,t){n[t]=r.attr(t),r.removeAttr(t)}),n},rules:function(t,n){var r=this[0];if(t){var i=e.data(r.form,"validator").settings,s=i.rules,o=e.validator.staticRules(r);switch(t){case"add":e.extend(o,e.validator.normalizeRule(n)),s[r.name]=o,n.messages&&(i.messages[r.name]=e.extend(i.messages[r.name],n.messages));break;case"remove":if(!n)return delete s[r.name],o;var u={};return e.each(n.split(/\s/),function(e,t){u[t]=o[t],delete o[t]}),u}}var a=e.validator.normalizeRules(e.extend({},e.validator.classRules(r),e.validator.attributeRules(r),e.validator.dataRules(r),e.validator.staticRules(r)),r);if(a.required){var f=a.required;delete a.required,a=e.extend({required:f},a)}return a}}),e.extend(e.expr[":"],{blank:function(t){return!e.trim(""+t.value)},filled:function(t){return!!e.trim(""+t.value)},unchecked:function(e){return!e.checked}}),e.validator=function(t,n){this.settings=e.extend(!0,{},e.validator.defaults,t),this.currentForm=n,this.init()},e.validator.format=function(t,n){return arguments.length===1?function(){var n=e.makeArray(arguments);return n.unshift(t),e.validator.format.apply(this,n)}:(arguments.length>2&&n.constructor!==Array&&(n=e.makeArray(arguments).slice(1)),n.constructor!==Array&&(n=[n]),e.each(n,function(e,n){t=t.replace(new RegExp("\\{"+e+"\\}","g"),function(){return n})}),t)},e.extend(e.validator,{defaults:{messages:{},groups:{},rules:{},errorClass:"error",validClass:"valid",errorElement:"label",focusInvalid:!0,errorContainer:e([]),errorLabelContainer:e([]),onsubmit:!0,ignore:":hidden",ignoreTitle:!1,onfocusin:function(e,t){this.lastActive=e,this.settings.focusCleanup&&!this.blockFocusCleanup&&(this.settings.unhighlight&&this.settings.unhighlight.call(this,e,this.settings.errorClass,this.settings.validClass),this.addWrapper(this.errorsFor(e)).hide())},onfocusout:function(e,t){!this.checkable(e)&&(e.name in this.submitted||!this.optional(e))&&this.element(e)},onkeyup:function(e,t){if(t.which===9&&this.elementValue(e)==="")return;(e.name in this.submitted||e===this.lastElement)&&this.element(e)},onclick:function(e,t){e.name in this.submitted?this.element(e):e.parentNode.name in this.submitted&&this.element(e.parentNode)},highlight:function(t,n,r){t.type==="radio"?this.findByName(t.name).addClass(n).removeClass(r):e(t).addClass(n).removeClass(r)},unhighlight:function(t,n,r){t.type==="radio"?this.findByName(t.name).removeClass(n).addClass(r):e(t).removeClass(n).addClass(r)}},setDefaults:function(t){e.extend(e.validator.defaults,t)},messages:{required:"This field is required.",remote:"Please fix this field.",email:"Please enter a valid email address.",url:"Please enter a valid URL.",date:"Please enter a valid date.",dateISO:"Please enter a valid date (ISO).",number:"Please enter a valid number.",digits:"Please enter only digits.",creditcard:"Please enter a valid credit card number.",equalTo:"Please enter the same value again.",maxlength:e.validator.format("Please enter no more than {0} characters."),minlength:e.validator.format("Please enter at least {0} characters."),rangelength:e.validator.format("Please enter a value between {0} and {1} characters long."),range:e.validator.format("Please enter a value between {0} and {1}."),max:e.validator.format("Please enter a value less than or equal to {0}."),min:e.validator.format("Please enter a value greater than or equal to {0}.")},autoCreateRanges:!1,prototype:{init:function(){function r(t){var n=e.data(this[0].form,"validator"),r="on"+t.type.replace(/^validate/,"");n.settings[r]&&n.settings[r].call(n,this[0],t)}this.labelContainer=e(this.settings.errorLabelContainer),this.errorContext=this.labelContainer.length&&this.labelContainer||e(this.currentForm),this.containers=e(this.settings.errorContainer).add(this.settings.errorLabelContainer),this.submitted={},this.valueCache={},this.pendingRequest=0,this.pending={},this.invalid={},this.reset();var t=this.groups={};e.each(this.settings.groups,function(n,r){typeof r=="string"&&(r=r.split(/\s/)),e.each(r,function(e,r){t[r]=n})});var n=this.settings.rules;e.each(n,function(t,r){n[t]=e.validator.normalizeRule(r)}),e(this.currentForm).validateDelegate(":text, [type='password'], [type='file'], select, textarea, [type='number'], [type='search'] ,[type='tel'], [type='url'], [type='email'], [type='datetime'], [type='date'], [type='month'], [type='week'], [type='time'], [type='datetime-local'], [type='range'], [type='color'] ","focusin focusout keyup",r).validateDelegate("[type='radio'], [type='checkbox'], select, option","click",r),this.settings.invalidHandler&&e(this.currentForm).bind("invalid-form.validate",this.settings.invalidHandler)},form:function(){return this.checkForm(),e.extend(this.submitted,this.errorMap),this.invalid=e.extend({},this.errorMap),this.valid()||e(this.currentForm).triggerHandler("invalid-form",[this]),this.showErrors(),this.valid()},checkForm:function(){this.prepareForm();for(var e=0,t=this.currentElements=this.elements();t[e];e++)this.check(t[e]);return this.valid()},element:function(t){t=this.validationTargetFor(this.clean(t)),this.lastElement=t,this.prepareElement(t),this.currentElements=e(t);var n=this.check(t)!==!1;return n?delete this.invalid[t.name]:this.invalid[t.name]=!0,this.numberOfInvalids()||(this.toHide=this.toHide.add(this.containers)),this.showErrors(),n},showErrors:function(t){if(t){e.extend(this.errorMap,t),this.errorList=[];for(var n in t)this.errorList.push({message:t[n],element:this.findByName(n)[0]});this.successList=e.grep(this.successList,function(e){return!(e.name in t)})}this.settings.showErrors?this.settings.showErrors.call(this,this.errorMap,this.errorList):this.defaultShowErrors()},resetForm:function(){e.fn.resetForm&&e(this.currentForm).resetForm(),this.submitted={},this.lastElement=null,this.prepareForm(),this.hideErrors(),this.elements().removeClass(this.settings.errorClass).removeData("previousValue")},numberOfInvalids:function(){return this.objectLength(this.invalid)},objectLength:function(e){var t=0;for(var n in e)t++;return t},hideErrors:function(){this.addWrapper(this.toHide).hide()},valid:function(){return this.size()===0},size:function(){return this.errorList.length},focusInvalid:function(){if(this.settings.focusInvalid)try{e(this.findLastActive()||this.errorList.length&&this.errorList[0].element||[]).filter(":visible").focus().trigger("focusin")}catch(t){}},findLastActive:function(){var t=this.lastActive;return t&&e.grep(this.errorList,function(e){return e.element.name===t.name}).length===1&&t},elements:function(){var t=this,n={};return e(this.currentForm).find("input, select, textarea").not(":submit, :reset, :image, [disabled]").not(this.settings.ignore).filter(function(){return!this.name&&t.settings.debug&&window.console&&console.error("%o has no name assigned",this),this.name in n||!t.objectLength(e(this).rules())?!1:(n[this.name]=!0,!0)})},clean:function(t){return e(t)[0]},errors:function(){var t=this.settings.errorClass.replace(" ",".");return e(this.settings.errorElement+"."+t,this.errorContext)},reset:function(){this.successList=[],this.errorList=[],this.errorMap={},this.toShow=e([]),this.toHide=e([]),this.currentElements=e([])},prepareForm:function(){this.reset(),this.toHide=this.errors().add(this.containers)},prepareElement:function(e){this.reset(),this.toHide=this.errorsFor(e)},elementValue:function(t){var n=e(t).attr("type"),r=e(t).val();return n==="radio"||n==="checkbox"?e("input[name='"+e(t).attr("name")+"']:checked").val():typeof r=="string"?r.replace(/\r/g,""):r},check:function(t){t=this.validationTargetFor(this.clean(t));var n=e(t).rules(),r=!1,i=this.elementValue(t),s;for(var o in n){var u={method:o,parameters:n[o]};try{s=e.validator.methods[o].call(this,i,t,u.parameters);if(s==="dependency-mismatch"){r=!0;continue}r=!1;if(s==="pending"){this.toHide=this.toHide.not(this.errorsFor(t));return}if(!s)return this.formatAndAdd(t,u),!1}catch(a){throw this.settings.debug&&window.console&&console.log("Exception occured when checking element "+t.id+", check the '"+u.method+"' method.",a),a}}if(r)return;return this.objectLength(n)&&this.successList.push(t),!0},customDataMessage:function(t,n){return e(t).data("msg-"+n.toLowerCase())||t.attributes&&e(t).attr("data-msg-"+n.toLowerCase())},customMessage:function(e,t){var n=this.settings.messages[e];return n&&(n.constructor===String?n:n[t])},findDefined:function(){for(var e=0;e<arguments.length;e++)if(arguments[e]!==undefined)return arguments[e];return undefined},defaultMessage:function(t,n){return this.findDefined(this.customMessage(t.name,n),this.customDataMessage(t,n),!this.settings.ignoreTitle&&t.title||undefined,e.validator.messages[n],"<strong>Warning: No message defined for "+t.name+"</strong>")},formatAndAdd:function(t,n){var r=this.defaultMessage(t,n.method),i=/\$?\{(\d+)\}/g;typeof r=="function"?r=r.call(this,n.parameters,t):i.test(r)&&(r=e.validator.format(r.replace(i,"{$1}"),n.parameters)),this.errorList.push({message:r,element:t}),this.errorMap[t.name]=r,this.submitted[t.name]=r},addWrapper:function(e){return this.settings.wrapper&&(e=e.add(e.parent(this.settings.wrapper))),e},defaultShowErrors:function(){var e,t;for(e=0;this.errorList[e];e++){var n=this.errorList[e];this.settings.highlight&&this.settings.highlight.call(this,n.element,this.settings.errorClass,this.settings.validClass),this.showLabel(n.element,n.message)}this.errorList.length&&(this.toShow=this.toShow.add(this.containers));if(this.settings.success)for(e=0;this.successList[e];e++)this.showLabel(this.successList[e]);if(this.settings.unhighlight)for(e=0,t=this.validElements();t[e];e++)this.settings.unhighlight.call(this,t[e],this.settings.errorClass,this.settings.validClass);this.toHide=this.toHide.not(this.toShow),this.hideErrors(),this.addWrapper(this.toShow).show()},validElements:function(){return this.currentElements.not(this.invalidElements())},invalidElements:function(){return e(this.errorList).map(function(){return this.element})},showLabel:function(t,n){var r=this.errorsFor(t);r.length?(r.removeClass(this.settings.validClass).addClass(this.settings.errorClass),r.html(n)):(r=e("<"+this.settings.errorElement+">").attr("for",this.idOrName(t)).addClass(this.settings.errorClass).html(n||""),this.settings.wrapper&&(r=r.hide().show().wrap("<"+this.settings.wrapper+"/>").parent()),this.labelContainer.append(r).length||(this.settings.errorPlacement?this.settings.errorPlacement(r,e(t)):r.insertAfter(t))),!n&&this.settings.success&&(r.text(""),typeof this.settings.success=="string"?r.addClass(this.settings.success):this.settings.success(r,t)),this.toShow=this.toShow.add(r)},errorsFor:function(t){var n=this.idOrName(t);return this.errors().filter(function(){return e(this).attr("for")===n})},idOrName:function(e){return this.groups[e.name]||(this.checkable(e)?e.name:e.id||e.name)},validationTargetFor:function(e){return this.checkable(e)&&(e=this.findByName(e.name).not(this.settings.ignore)[0]),e},checkable:function(e){return/radio|checkbox/i.test(e.type)},findByName:function(t){return e(this.currentForm).find("[name='"+t+"']")},getLength:function(t,n){switch(n.nodeName.toLowerCase()){case"select":return e("option:selected",n).length;case"input":if(this.checkable(n))return this.findByName(n.name).filter(":checked").length}return t.length},depend:function(e,t){return this.dependTypes[typeof e]?this.dependTypes[typeof e](e,t):!0},dependTypes:{"boolean":function(e,t){return e},string:function(t,n){return!!e(t,n.form).length},"function":function(e,t){return e(t)}},optional:function(t){var n=this.elementValue(t);return!e.validator.methods.required.call(this,n,t)&&"dependency-mismatch"},startRequest:function(e){this.pending[e.name]||(this.pendingRequest++,this.pending[e.name]=!0)},stopRequest:function(t,n){this.pendingRequest--,this.pendingRequest<0&&(this.pendingRequest=0),delete this.pending[t.name],n&&this.pendingRequest===0&&this.formSubmitted&&this.form()?(e(this.currentForm).submit(),this.formSubmitted=!1):!n&&this.pendingRequest===0&&this.formSubmitted&&(e(this.currentForm).triggerHandler("invalid-form",[this]),this.formSubmitted=!1)},previousValue:function(t){return e.data(t,"previousValue")||e.data(t,"previousValue",{old:null,valid:!0,message:this.defaultMessage(t,"remote")})}},classRuleSettings:{required:{required:!0},email:{email:!0},url:{url:!0},date:{date:!0},dateISO:{dateISO:!0},number:{number:!0},digits:{digits:!0},creditcard:{creditcard:!0}},addClassRules:function(t,n){t.constructor===String?this.classRuleSettings[t]=n:e.extend(this.classRuleSettings,t)},classRules:function(t){var n={},r=e(t).attr("class");return r&&e.each(r.split(" "),function(){this in e.validator.classRuleSettings&&e.extend(n,e.validator.classRuleSettings[this])}),n},attributeRules:function(t){var n={},r=e(t);for(var i in e.validator.methods){var s;i==="required"?(s=r.get(0).getAttribute(i),s===""&&(s=!0),s=!!s):s=r.attr(i),s?n[i]=s:r[0].getAttribute("type")===i&&(n[i]=!0)}return n.maxlength&&/-1|2147483647|524288/.test(n.maxlength)&&delete n.maxlength,n},dataRules:function(t){var n,r,i={},s=e(t);for(n in e.validator.methods)r=s.data("rule-"+n.toLowerCase()),r!==undefined&&(i[n]=r);return i},staticRules:function(t){var n={},r=e.data(t.form,"validator");return r.settings.rules&&(n=e.validator.normalizeRule(r.settings.rules[t.name])||{}),n},normalizeRules:function(t,n){return e.each(t,function(r,i){if(i===!1){delete t[r];return}if(i.param||i.depends){var s=!0;switch(typeof i.depends){case"string":s=!!e(i.depends,n.form).length;break;case"function":s=i.depends.call(n,n)}s?t[r]=i.param!==undefined?i.param:!0:delete t[r]}}),e.each(t,function(r,i){t[r]=e.isFunction(i)?i(n):i}),e.each(["minlength","maxlength"],function(){t[this]&&(t[this]=Number(t[this]))}),e.each(["rangelength"],function(){var n;t[this]&&(e.isArray(t[this])?t[this]=[Number(t[this][0]),Number(t[this][1])]:typeof t[this]=="string"&&(n=t[this].split(/[\s,]+/),t[this]=[Number(n[0]),Number(n[1])]))}),e.validator.autoCreateRanges&&(t.min&&t.max&&(t.range=[t.min,t.max],delete t.min,delete t.max),t.minlength&&t.maxlength&&(t.rangelength=[t.minlength,t.maxlength],delete t.minlength,delete t.maxlength)),t},normalizeRule:function(t){if(typeof t=="string"){var n={};e.each(t.split(/\s/),function(){n[this]=!0}),t=n}return t},addMethod:function(t,n,r){e.validator.methods[t]=n,e.validator.messages[t]=r!==undefined?r:e.validator.messages[t],n.length<3&&e.validator.addClassRules(t,e.validator.normalizeRule(t))},methods:{required:function(t,n,r){if(!this.depend(r,n))return"dependency-mismatch";if(n.nodeName.toLowerCase()==="select"){var i=e(n).val();return i&&i.length>0}return this.checkable(n)?this.getLength(t,n)>0:e.trim(t).length>0},remote:function(t,n,r){if(this.optional(n))return"dependency-mismatch";var i=this.previousValue(n);this.settings.messages[n.name]||(this.settings.messages[n.name]={}),i.originalMessage=this.settings.messages[n.name].remote,this.settings.messages[n.name].remote=i.message,r=typeof r=="string"&&{url:r}||r;if(i.old===t)return i.valid;i.old=t;var s=this;this.startRequest(n);var o={};return o[n.name]=t,e.ajax(e.extend(!0,{url:r,mode:"abort",port:"validate"+n.name,dataType:"json",data:o,success:function(r){s.settings.messages[n.name].remote=i.originalMessage;var o=r===!0||r==="true";if(o){var u=s.formSubmitted;s.prepareElement(n),s.formSubmitted=u,s.successList.push(n),delete s.invalid[n.name],s.showErrors()}else{var a={},f=r||s.defaultMessage(n,"remote");a[n.name]=i.message=e.isFunction(f)?f(t):f,s.invalid[n.name]=!0,s.showErrors(a)}i.valid=o,s.stopRequest(n,o)}},r)),"pending"},minlength:function(t,n,r){var i=e.isArray(t)?t.length:this.getLength(e.trim(t),n);return this.optional(n)||i>=r},maxlength:function(t,n,r){var i=e.isArray(t)?t.length:this.getLength(e.trim(t),n);return this.optional(n)||i<=r},rangelength:function(t,n,r){var i=e.isArray(t)?t.length:this.getLength(e.trim(t),n);return this.optional(n)||i>=r[0]&&i<=r[1]},min:function(e,t,n){return this.optional(t)||e>=n},max:function(e,t,n){return this.optional(t)||e<=n},range:function(e,t,n){return this.optional(t)||e>=n[0]&&e<=n[1]},email:function(e,t){return this.optional(t)||/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i.test(e)},url:function(e,t){return this.optional(t)||/^(https?|s?ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(e)},date:function(e,t){return this.optional(t)||!/Invalid|NaN/.test((new Date(e)).toString())},dateISO:function(e,t){return this.optional(t)||/^\d{4}[\/\-]\d{1,2}[\/\-]\d{1,2}$/.test(e)},number:function(e,t){return this.optional(t)||/^-?(?:\d+|\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/.test(e)},digits:function(e,t){return this.optional(t)||/^\d+$/.test(e)},creditcard:function(e,t){if(this.optional(t))return"dependency-mismatch";if(/[^0-9 \-]+/.test(e))return!1;var n=0,r=0,i=!1;e=e.replace(/\D/g,"");for(var s=e.length-1;s>=0;s--){var o=e.charAt(s);r=parseInt(o,10),i&&(r*=2)>9&&(r-=9),n+=r,i=!i}return n%10===0},equalTo:function(t,n,r){var i=e(r);return this.settings.onfocusout&&i.unbind(".validate-equalTo").bind("blur.validate-equalTo",function(){e(n).valid()}),t===i.val()}}}),e.format=e.validator.format})(jQuery),function(e){var t={};if(e.ajaxPrefilter)e.ajaxPrefilter(function(e,n,r){var i=e.port;e.mode==="abort"&&(t[i]&&t[i].abort(),t[i]=r)});else{var n=e.ajax;e.ajax=function(r){var i=("mode"in r?r:e.ajaxSettings).mode,s=("port"in r?r:e.ajaxSettings).port;return i==="abort"?(t[s]&&t[s].abort(),t[s]=n.apply(this,arguments)):n.apply(this,arguments)}}}(jQuery),function(e){e.extend(e.fn,{validateDelegate:function(t,n,r){return this.bind(n,function(n){var i=e(n.target);if(i.is(t))return r.apply(i,arguments)})}})}(jQuery);

File moumar_eval_form.css

+.mef-rating.editable > img {
+  cursor: pointer;
+}
+
+.mef-rating .title {
+  float :left;
+  width: 14em;
+}
+
+form.mef table td {
+  padding: 1em 0;
+}
+
+form.mef label.error { 
+  color: red; padding-left: .5em; vertical-align: top; }

File moumar_eval_form.js

+jQuery(function($) {
+  function restore_image_src() {
+    var img = $(this);
+    img.attr("src", img.data("original_src"));
+    var text = img.parent(".mef-rating").find(".text");
+    var note = img.data("note");
+    text.text(note != null ? rating_descriptions[note] : "");
+  }
+  
+  function image_url(what) {
+    return "wp-content/plugins/moumar_eval_form/images/rating_" + what + ".gif";
+  }
+
+  $(".mef-rating.editable")
+    .each(function() {
+      var note = $(this).find("input[type=hidden]").val() - 1;
+      if (note >= 0) {
+        $(this).find("img").each(function(i) {
+          $(this)
+            .data("original_src", image_url(i <= note ? "on" : "off"))
+            .data("note", note)
+          restore_image_src.call(this);
+        });
+      }
+    });
+
+  $(".mef-rating.editable > img")
+    .hover(function() {
+      var img = $(this);
+      var mef_rating = img.parent(".mef-rating");
+      var imgs = img.siblings("img").andSelf();
+      var note = imgs.index(img);
+
+      imgs.attr("src", function(index) {
+        return image_url( note >= index ? "over" : "off");
+      });
+
+      mef_rating
+        .find(".text")
+        .text(rating_descriptions[note]);
+
+    }, restore_image_src)
+    .click(function() {
+      var img = $(this);
+      var mef_rating = img.parent(".mef-rating");
+      var text = mef_rating.find(".text");
+      var imgs = img.siblings("img").andSelf();
+      var clicked_note = imgs.index(img);
+      img.siblings("input[type=hidden]").val(clicked_note + 1);
+      img.siblings("label.error").hide();
+
+      imgs.attr("src", function(index) {
+        return image_url( clicked_note >= index ? "on" : "off");
+      });
+
+      imgs.each(function() {
+        $(this)
+          .data("note", clicked_note)
+          .data("original_src", $(this).attr("src"));
+      });
+    });
+
+  $(".mef-rating.editable").mouseout(function() {
+    $(this).find("> img").each(restore_image_src);
+  });
+  
+  function textarea_limite() {
+    var v = $(this).val();
+    var limit = $(this).data("limite");
+    if (v.length > limit) {
+      $(this).val(v.substr(0, limit));
+    }
+  }
+
+  $(".mef textarea")
+    .filter(function() {
+      return $(this).data("limite") > 0;
+    })
+    .keyup(textarea_limite)
+    .change(textarea_limite);
+
+  $.extend($.validator.messages, {
+    required: "Ce champ est obligatoire."
+  });
+
+  $("form.mef").validate({ignore: ""});
+});

File moumar_eval_form.php

+<?php
+/*
+Plugin Name: Moumar Eval Form
+Plugin URI: https://bibucket.org/moumar/wordpress_eval_form
+Description: Eval Form
+Author: moumar
+Version: 0.1
+Author URI: http://moumar.net/
+*/
+
+require dirname(__FILE__) . "/config.php";
+
+$MEF_RATING_CATEGORIES = array();
+
+foreach($MEF_FORM_DESCRIPTION as $key => $item_description) {
+  if($item_description["type"] == "note") {
+    $MEF_RATING_CATEGORIES[$key] = $item_description["nom"];
+  }
+}
+
+$mef_meta_key = "moumar_eval_form";
+
+if (__FILE__ == realpath($_SERVER["SCRIPT_FILENAME"])) {
+  $base_path = str_replace("/wp-content/plugins/moumar_eval_form", "", dirname(__FILE__));
+  
+  require($base_path . '/wp-load.php');
+
+  if (is_numeric($_POST["pays_name"])) {
+    $all_pays = mef__get_all_pays();
+    $fiche_pays = get_page_by_title($all_pays[$_POST["pays_name"]], "array", "post");
+  } else {
+    $fiche_pays = get_page_by_title($_POST["pays_name"], "array", "post");
+  }
+
+  if (!$fiche_pays) {
+    echo "pays inconnu";
+    exit();
+  }
+  
+  $fiches_pays_category_id = get_category_by_slug("pays")->term_id;
+  $continent_category_ids = array_map(
+    function($c) { return $c->term_id; },
+    get_categories(array("parent" => $fiches_pays_category_id))
+  );
+  $post_category_ids = wp_get_post_categories($fiche_pays->ID);
+  list($continent_category_id) = array_values( array_intersect($continent_category_ids, $post_category_ids) );
+  if (!$continent_category_id) {
+    echo "pays invalide (continent)";
+    exit();
+  }
+
+  $ratings = array();
+  $page_content = "";
+
+  foreach($MEF_FORM_DESCRIPTION as $key => $item_description) {
+    if ($_POST[$key] == null) {
+      if (!$item_description["facultatif"]) {
+        echo "le paramètre '" . htmlspecialchars($item_description["nom"]) . "' est manquant";
+        exit();
+      } else {
+        continue;
+      }
+    }
+
+    $page_content .= "<h3>";
+    $page_content .= htmlspecialchars($item_description["nom"]) . ": " ;
+    $page_content .= "</h3>";
+
+    switch($item_description["type"]) {
+      case "select":
+      case "checkbox":
+        $i = $_POST[$key];
+        $page_content .= htmlspecialchars($item_description["valeurs"][$i]);
+        break;
+      case "textarea":
+      case "text":
+        $page_content .= "<p>";
+        $page_content .= htmlspecialchars($_POST[$key]);
+        $page_content .= "</p>";
+        break;
+      case "note":
+        $v = $_POST[$key];
+        $ratings[$key] = $v;
+        $page_content .= mef__generate_html_for_rating($v);
+        break;
+    }
+  }
+  $post = array(
+    'comment_status' => 'closed',
+    //  'post_category' => '' #FIXME Evaluations pays //post_category no longer exists, try wp_set_post_terms() for setting a post's categories
+    'post_content' => $page_content,
+    'post_status' => 'pending',
+    'post_title' => "evaluation de " . $_POST["pseudo"] . " de " . $fiche_pays->post_title,
+    'post_type' => "post"
+  );
+
+  $post_id = wp_insert_post( $post );
+  if ( $post_id > 0) {
+    $ratings["pays_name"] = $fiche_pays->post_title;
+    $ratings["pays_id"] = $fiche_pays->ID;
+    add_post_meta($post_id, $mef_meta_key, $ratings, true);
+    $category_ids = array();
+    #$category_ids[] = get_term_by("name", $fiche_pays->post_title, "category")->term_id;
+    $category_ids[] = get_cat_ID("Evaluations Pays");
+    $continent = get_term_by("id", $continent_category_id, "category");
+    $category_ids[] = $continent->term_id;
+    $category_ids[] = get_term_by("name", "Evaluations " . $continent->name, "category")->term_id;
+    wp_set_post_categories( $post_id, $category_ids);
+    echo "votre avis a été enregistré, il va être validé.";
+  } else {
+    echo "erreur à l'enregistrement du post";
+  }
+
+  exit();
+}
+
+function mef_top_overall($limit = 10) {
+  global $mef_meta_key, $MEF_RATING_CATEGORIES;
+  $overall_ratings = array();
+
+  $cat_id = get_term_by("name", "Evaluations Pays", "category")->term_id;
+  $posts = get_posts(array("category" => $cat_id, "post_status" => "publish", "numberposts" => -1));
+  foreach($posts as $post) {
+    $count = 0;
+    $total = 0;
+    $ratings_for_this_country = get_post_meta($post->ID, $mef_meta_key, true);
+    foreach($ratings_for_this_country as $category => $note) {
+      if ($MEF_RATING_CATEGORIES[$category] and $note > 0) {
+        $count += 1;
+        $total += $note;
+      }
+    }
+    $overall_ratings[$ratings_for_this_country["pays_id"]] = ($count > 0) ? $total / $count : 0;
+  }
+
+  mef__internal_show_ratings($overall_ratings, $limit, "global");
+}
+
+function mef_top($rating_category, $limit = 10) {
+  global $mef_meta_key, $MEF_RATING_CATEGORIES;
+
+  if (is_numeric($rating_category)) {
+    $limit = $rating_category;
+    foreach($MEF_RATING_CATEGORIES as $key => $value) {
+      mef_top($key, $limit);
+    }
+  } else {
+    if (!$MEF_RATING_CATEGORIES[$rating_category]) {
+      echo "<big> la catégorie " . htmlspecialchars($rating_category) . " n'existe pas!</big>";
+      return;
+    }
+
+    $cat_id = get_cat_ID("Evaluations Pays");
+
+    $custom_posts = get_posts(array("category" => $cat_id, "numberposts" => -1, "post_status" => "publish"));
+    $ratings = array();
+    foreach($custom_posts as $post) {
+      $ratings_for_this_eval = get_post_meta($post->ID, $mef_meta_key, true);
+      if ($ratings_for_this_eval and $v = $ratings_for_this_eval[$rating_category]) {
+        $count += 1;
+        $ratings[$ratings_for_this_eval["pays_id"]] += $v;
+      }
+    }
+    mef__internal_show_ratings($ratings, $limit, $MEF_RATING_CATEGORIES[$rating_category]);
+  }
+}
+
+function mef_form($pays_name = null) {
+  global $MEF_FORM_DESCRIPTION;
+
+  $post_url = plugins_url(basename(__FILE__), __FILE__);
+
+  echo "<form class=\"mef\" method=\"POST\" action=\"$post_url\">";
+  echo "<table>";
+  if ($pays_name) {
+    echo "<input type=\"hidden\" name=\"pays_name\" value=\"$pays_name\" />" ;
+  } else {
+    $MEF_FORM_DESCRIPTION = 
+      array_merge(array("pays_name" => 
+                           array("nom" => "Pays", 
+                                          "type" => "select",
+                                          "valeurs" => mef__get_all_pays()))
+                  , $MEF_FORM_DESCRIPTION );
+  }
+
+  foreach($MEF_FORM_DESCRIPTION as $key => $item_description) {
+    echo "<tr>";
+    echo "<td><label for=\"$key\">" . htmlspecialchars($item_description["nom"]) . ": ";
+
+    if ($item_description["facultatif"] != 1) 
+      echo "*";
+
+    echo "</label></td>";
+    echo "<td>";
+    #$data_str = 'data-facultatif="' . $item_description["facultatif"] . '" data-limite="'.$item_description["limite"].'"';
+    $class = $item_description["facultatif"] != 1 ? "required" : "";
+    switch($item_description["type"]) {
+      case "select":
+        echo "<select class=\"select $class\" name=\"$key\">";
+        echo "<option value=\"\">-</option>";
+        $items = $item_description["valeurs"];
+        for($i = 0; $i < count($items); $i++) {
+          echo "<option value=\"$i\">" . htmlspecialchars($items[$i]) . "</option>";
+        }
+        echo "</select>";
+        break;
+      case "checkbox":
+        $items = $item_description["valeurs"];
+        for($i = 0; $i < count($items); $i++) {
+          echo "<input class=\"$class\" type=\"radio\" name=\"$key\" value=\"$i\" />" . htmlspecialchars($items[$i]);
+        }
+        echo "<label for=\"$key\" class=\"error\" style=\"display:none\">Ce champ est obligatoire</label>";
+        break;
+      case "textarea":
+        $l = htmlspecialchars($item_description["limite"]);
+        echo "<textarea class=\"$class\" name=\"$key\" rows=\"5\" cols=\"20\" data-limite=\"$l\"></textarea>";
+        if ($l > 0) {
+          echo "<small>(limite $l caractères)</small>";
+        }
+        break;
+      case "text":
+        echo "<input class=\"$class\" type=\"text\" name=\"$key\" size=\"40\" />";
+        break;
+      case "note":
+        echo
+          "<div class=\"mef-rating editable\">" .
+          mef__generate_html_for_rating(0) .
+          '<span class="text"></span>' .
+          "<input class=\"$class\" type=\"hidden\" name=\"$key\" value=\"\" />" .
+          '</div>';
+        break;
+    }
+    echo "</td>";
+    echo "</tr>";
+  }
+  echo "<tr><td></td><td>";
+  echo "<input type=\"submit\" value=\"Envoyer le questionnaire\" />";
+  echo "</td>";
+  echo "</tr></table></form>";
+}
+
+function mef__get_all_pays() {
+  $cat_id = get_cat_ID("Fiches Pays");
+  $posts = get_posts(array("category" => $cat_id, "numberposts" => -1));
+  $pays = array();
+  foreach($posts as $post) {
+    $pays[] = $post->post_title;
+  }
+  sort($pays);
+  return $pays;
+}
+
+function mef__generate_html_for_rating($note) {
+  $image_path = plugin_dir_url(__FILE__ ) . 'images';
+  $out = "";
+  for($i = 0; $i < 5; $i++) {
+    if ((int)$note > $i)
+      $base = "rating_on";
+    else if ($note > $i and fmod($note, 1) > 0.1)
+      $base = "rating_half";
+    else
+      $base = "rating_off";
+    $src = "$image_path/$base.gif";
+    $out .= "<img src=\"$src\" data-index=\"$i\" data-original_src=\"$src\" />";
+  }
+  return $out;
+}
+
+function mef__internal_show_ratings($ratings, $limit, $title) {
+  arsort($ratings);
+  $ratings = array_slice($ratings, 0, $limit, true);
+
+  echo "<div class=\"mef-rating top\"><h3>Top " . htmlspecialchars($limit). " " . htmlspecialchars($title) . "</h3>";
+  echo "<ol>";
+  foreach ($ratings as $pays_id => $note) {
+    if ($note == 0)
+      continue;
+    
+    echo "<li>";
+    $permalink = get_permalink($pays_id);
+    $pays_name = get_the_title($pays_id);
+    
+    echo mef__generate_html_for_rating(round($note, 1));
+    echo "<a href=\"$permalink\" title=\"$pays_name\">$pays_name</a>";
+    echo "</li>";
+  }
+  echo "</ol>";
+  echo "</div>";
+}
+
+function mef_init() {
+  global $mef_meta_key, $MEF_RATING_DESCRIPTIONS;
+  wp_enqueue_script( 'jquery' );
+  wp_enqueue_script( 'jquery.validate', plugins_url('moumar_eval_form/jquery.validate.min.js') );
+  wp_enqueue_script( $mef_meta_key, plugins_url('moumar_eval_form/moumar_eval_form.js') );
+  wp_localize_script( $mef_meta_key, 'rating_descriptions', $MEF_RATING_DESCRIPTIONS);
+  wp_enqueue_style( $mef_meta_key, plugins_url('moumar_eval_form/moumar_eval_form.css') );
+}
+
+add_action('init', 'mef_init');
+?>

File moumar_multi_rating.css

-.mmr-rating.editable > img {
-  cursor: pointer;
-}
-
-.mmr-rating .title {
-  float :left;
-  width: 14em;
-}

File moumar_multi_rating.js

-jQuery(function($) {
-  var rating_names = [
-    "Nul",
-    "A la limite",
-    "Assez bien",
-    "Très bien",
-    "Excellent!"
-  ];
-
-  function restore_image_src() {
-    var img = $(this);
-    var text = img.parent(".mmr-rating").find(".text");
-    img.attr("src", img.data("original_src"));
-    if (!text.data("sticky")) {
-      text.text("");
-    }
-  }
-
-  $(".mmr-rating.editable > img")
-    .hover(function() {
-      var img = $(this);
-      var mmr_rating = img.parent(".mmr-rating");
-      var imgs = img.siblings("img").andSelf();
-      var i = imgs.index(img);
-      imgs
-        .each(function(index) {
-          var img = $(this);
-          var bn = img.attr("src").replace(/_\w+\.gif/, '');
-          var suffix = "off";
-          if (i >= index) {
-            suffix = "over";
-          }
-          img.attr("src", bn + "_" + suffix + ".gif");
-        });
-
-      mmr_rating
-        .find(".text")
-        .text(rating_names[i])
-        .data("sticky", false);
-    }, restore_image_src)
-    .click(function() {
-      var img = $(this);
-      var mmr_rating = img.parent(".mmr-rating");
-      var text = mmr_rating.find(".text");
-      var imgs = img.siblings("img").andSelf();
-      var i = imgs.index(img);
-
-      text.text("envoi...")
-          .data("sticky", true);
-      imgs.each(function() {
-        var img = $(this);
-        img.data("original_src", img.attr("src"));
-      });
-      $.post(mmr_rating.data("post_url"), {
-        post_id: mmr_rating.data("post_id"),
-        rating_category: mmr_rating.data("rating_category"),
-        rating: i+1
-      }).complete(function(e) {
-        text.text(e.responseText);
-      });
-    });
-
-  $(".mmr-rating.editable").mouseout(function() {
-    $(this).find("> img").each(restore_image_src);
-  });
-});

File moumar_multi_rating.php

-<?php
-/*
-Plugin Name: Moumar Multi Rating
-Plugin URI: https://github.com/moumar/multi_rating
-Description: Multi rating
-Author: moumar
-Version: 0.1
-Author URI: http://moumar.net/
-*/
-
-$MMR_RATING_CATEGORIES = array(
-  'hebergement'         => 'Hébergement',
-  'gastronomie'         => 'Gastronomie',
-  'accueil'             => 'Accueil & hospitalité',
-  'meteo'               => 'Météo',
-  'night-life'          => 'Bars/boîtes/night life',
-  'paysages'            => 'Paysages',
-  'culture'             => 'Culture/Monuments/musées',
-  'activites'           => 'Activités/loisirs/sport',
-  'shopping'            => 'Shopping',
-  'sante'               => 'Hygiène/Santé',
-  'securite'            => 'Sécurité',
-  'gay'                 => 'Gay-Friendly',
-  'photo'               => 'Intérêt photographique',
-  'deplacements'        => 'Déplacements intérieurs'
-);
-
-if (__FILE__ == realpath($_SERVER["SCRIPT_FILENAME"])) {
-  $base_path = str_replace("/wp-content/plugins/moumar_multi_rating", "", dirname(__FILE__));
-  session_start();
-  
-  require($base_path . '/wp-load.php');
-
-  $post_id = $_POST["post_id"];
-  $rating_category = $_POST["rating_category"];
-  $rating = $_POST["rating"];
-  $session_key = "moumar-multi-rating-$post_id-$rating_category";
-
-  $previous_rating = $_SESSION[$session_key] ;
-  //echo "rating: '$rating', previous '$previous_rating'";
-
-  if ($previous_rating) {
-    //mmr_rate_post($post_id, $rating_category, -1 * $previous_rating) ;
-    echo "vous avez déjà voté!";
-  } else {
-    mmr_rate_post($post_id, $rating_category, $rating);
-    $_SESSION[$session_key] = $_POST["rating"];
-    echo "Merci pour votre vote.";
-  }
-
-  exit();
-}
-
-function mmr_rate_post($post_id, $rating_category, $rating) {
-  $ratings_for_country = get_post_meta($post_id, "moumar_multi_rating", true);
-  
-  if (!$ratings_for_country) {
-    $ratings_for_country = array();
-  }
-
-  if (!$ratings_for_country[$rating_category]) {
-    $ratings_for_country[$rating_category] = array("count" => 0, "total" => 0);
-  }
-
-  $ratings_for_country[$rating_category]["count"] += ($rating < 0 ? -1 : 1);
-  $ratings_for_country[$rating_category]["total"] += $rating;
-  //echo( "count: " . $ratings_for_country[$rating_category]["count"] . " total : " . $ratings_for_country[$rating_category]["total"]);
-
-  add_post_meta($post_id, "moumar_multi_rating", $ratings_for_country, true) or update_post_meta($post_id, "moumar_multi_rating", $ratings_for_country);
-}
-
-function mmr_pluralize($root, $count) {
-  $s = "$count $root";
-  if ($count != 1) {
-    $s .= "s";
-  }
-  return $s;
-}
-
-function mmr_show($rating_category = null) {
-  global $post, $MMR_RATING_CATEGORIES;
-  if ($rating_category) {
-    $category_full_name = $MMR_RATING_CATEGORIES[$rating_category];
-    if (!$category_full_name) {
-      echo "<big> la catégorie " . htmlspecialchars($rating_category) . " n'existe pas!</big>";
-      return;
-    }
-
-    $ratings_for_country = get_post_meta($post->ID, 'moumar_multi_rating', true);
-    $count = 0;
-    $total = 0;
-
-    if ($ratings_for_country[$rating_category]) {
-      $count = $ratings_for_country[$rating_category]["count"] or 0;
-      $total = $ratings_for_country[$rating_category]["total"] or 0;
-    }
-    if ($total > 0)
-      $note = round($total/$count, 1);
-    else
-      $note = 0;
-
-    mmr_show_rating($note, htmlspecialchars($category_full_name), ", " . mmr_pluralize("vote", $count), array("post_id" => $post->ID, "rating_category" => $rating_category), true);
-  } else {
-    foreach($MMR_RATING_CATEGORIES as $key => $value) {
-      mmr_show($key);
-    }
-  }
-}
-
-function mmr_show_rating($note, $title, $suffix, $datas, $is_editable) {
-  $editable_class = $is_editable ? "editable" : "";
-  $post_url = plugins_url(basename(__FILE__), __FILE__);
-  $data_string = "data-post_url=\"" . $post_url . "\"";
-  foreach($datas as $k => $v) {
-    $data_string .= " data-$k=\"$v\" ";
-  }
-
-  echo "<div class=\"mmr-rating $editable_class\" $data_string >";
-  echo "<span class=\"title\">" . $title ."</span>";
-  $image_path = plugin_dir_url(__FILE__ ) . 'images';
-  for($i = 0; $i < 5; $i++) {
-    if ((int)$note > $i)
-      $base = "rating_on";
-    else if ($note > $i and fmod($note, 1) > 0.1)
-      $base = "rating_half";
-    else
-      $base = "rating_off";
-    $src = "$image_path/$base.gif";
-
-    echo "<img src=\"$src\" data-index=\"$i\" data-original_src=\"$src\" />";
-  }
-  echo mmr_pluralize("étoile", $note) . $suffix;
-  echo ' <span class="text"></span>';
-  echo '</div>';
-}
-
-function mmr_clear_all() {
-  foreach(get_posts() as $post) {
-    setup_postdata($post);
-    delete_post_meta($post->ID, "moumar_multi_rating"); 
-  }
-}
-
-function mmr_top_overall($limit = 10) {
-  $ratings = array();
-
-  foreach(get_posts() as $post) {
-    setup_postdata($post);
-    $count = 0;
-    $total = 0;
-    $ratings_for_country = get_post_meta($post->ID, "moumar_multi_rating", true);
-    if (!$ratings_for_country)
-      continue;
-    foreach($ratings_for_country as $rating) {
-      $count += $rating["count"];
-      $total += $rating["total"];
-    }
-    $ratings[$post->ID] = 0;
-    if ($count > 0) {
-      $ratings[$post->ID] = $total / $count;
-    }
-  }
-  
-  mmr_internal_show_ratings($ratings, $limit, "global");
-}
-
-function mmr_top($rating_category, $limit = 10) {
-  global $MMR_RATING_CATEGORIES;
-
-  if (is_numeric($rating_category)) {
-    $limit = $rating_category;
-    foreach($MMR_RATING_CATEGORIES as $key => $value) {
-      mmr_top($key, $limit);
-    }
-  } else {
-    if (!$MMR_RATING_CATEGORIES[$rating_category]) {
-      echo "<big> la catégorie " . htmlspecialchars($rating_category) . " n'existe pas!</big>";
-      return;
-    }
-    #$args = array('category' => -9); // exclude category 9
-    #$custom_posts = get_posts($args);
-    $custom_posts = get_posts();
-    $ratings = array();
-    foreach($custom_posts as $post) {
-      setup_postdata($post);
-      $ratings_for_country = get_post_meta($post->ID, "moumar_multi_rating", true);
-      if ($ratings_for_country and $ratings_for_country[$rating_category]) {
-        $count = $ratings_for_country[$rating_category]["count"];
-        if ($count) 
-          $ratings[$post->ID] = $ratings_for_country[$rating_category]["total"] / $count;
-      }
-    }
-    mmr_internal_show_ratings($ratings, $limit, $MMR_RATING_CATEGORIES[$rating_category]);
-  }
-}
-
-function mmr_internal_show_ratings($ratings, $limit, $title) {
-  arsort($ratings);
-  $ratings = array_slice($ratings, 0, $limit);
-  //print_r($ratings);
-
-  echo "<div class=\"mmr-rating-top\"><h3>Top " . htmlspecialchars($limit). " " . htmlspecialchars($title) . "</h3>";
-  echo "<ol>";
-  foreach ($ratings as $post_id => $note) {
-    if ($note == 0)
-      continue;
-    echo "<li>";
-    $permalink = htmlspecialchars(get_permalink($post_id));
-    $title = htmlspecialchars(get_the_title($post_id));
-    $html = "<a href=\"$permalink\" title=\"$title\">$title</a>";
-    
-    mmr_show_rating(round($note, 1), $html, "", array(), false);
-    echo "</li>";
-  }
-  echo "</ol>";
-  echo "</div>";
-}
-
-function mmr_init() {
-  wp_enqueue_script( 'jquery' );
-  wp_enqueue_script( 'moumar_multi_rating', plugins_url('moumar_multi_rating/moumar_multi_rating.js') );
-  wp_enqueue_style( 'moumar_multi_rating', plugins_url('moumar_multi_rating/moumar_multi_rating.css') );
-}
-
-add_action('init', 'mmr_init');
-?>