diff --git a/lang/master/tpl/design.mtt b/lang/master/tpl/design.mtt index 7c66a01..10ec6a8 100644 --- a/lang/master/tpl/design.mtt +++ b/lang/master/tpl/design.mtt @@ -199,7 +199,7 @@ - version ::VERSION:: + version cagettepei-::VERSION::
diff --git a/package.json b/package.json index 8b568c2..c165d44 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "CagettePei", + "name": "cagette-pei", "description": "le logiciel libre du circuit court", "license": "AGPL-3.0", "dependencies": { diff --git a/src/App.hx b/src/App.hx index 8ebbb8a..9334091 100755 --- a/src/App.hx +++ b/src/App.hx @@ -16,7 +16,8 @@ class App extends sugoi.BaseApp { */ // public static var VERSION = ([0,9,2] : Version).withPre("july"); // public static var VERSION = ([0,9,2] : Version).withPre(MyMacros.getGitShortSHA(), MyMacros.getGitCommitDate()); - public static var VERSION = "cagette-péi " + MyMacros.getGitCommitDate(); + // public static var VERSION = "cagette-péi " + MyMacros.getGitCommitDate(); + public static var VERSION = "cagette-pei"; // empty yet, cf.BaseApp.loadConfig public function new() { super(); diff --git a/src/sugoi/BaseApp.hx b/src/sugoi/BaseApp.hx index 6ea6d57..573d989 100644 --- a/src/sugoi/BaseApp.hx +++ b/src/sugoi/BaseApp.hx @@ -1,121 +1,132 @@ package sugoi; + import sugoi.i18n.TemplateTranslator; import sugoi.Web; class BaseApp { + public var cnx:sys.db.Connection; + public var template:templo.Loader; + public var maintain:Bool; + public var session:sugoi.db.Session; + public var view:View; + public var user:db.User; + public var params:Map; + public var cookieName:String; + public var cookieDomain:String; + public var uri:String; - public var cnx : sys.db.Connection; - public var template : templo.Loader; - public var maintain : Bool; - public var session : sugoi.db.Session; - public var view : View; - public var user : db.User; - public var params : Map; - public var cookieName : String; - public var cookieDomain : String; - public var uri : String; - - public static var config: Config; - //public static var classPathes = sugoi.tools.Macros.getClassPathes(); + public static var config:Config; + + // public static var classPathes = sugoi.tools.Macros.getClassPathes(); public function new() { - if (config == null) { loadConfig(); } - + cookieName = "sid"; cookieDomain = "." + App.config.HOST; - + #if plugins - if( false ) sugoi.plugin.PlugIn.copyTpl(); + if (false) + sugoi.plugin.PlugIn.copyTpl(); #end - + // This macro generates translated templates for each langage #if i18n_generation - if( false ) TemplateTranslator.parse("lang/master"); + if (false) + TemplateTranslator.parse("lang/master"); #end } - + public function loadConfig() { - App.config = BaseApp.config = new sugoi.Config(); + App.config = BaseApp.config = new sugoi.Config(); + + var PATH = Web.getCwd() + "../"; + var json = haxe.Json.parse(sys.io.File.getContent(PATH + "package.json")); + App.VERSION = json.version; + + App.log('configuration has been reloaded, VERSION=${App.VERSION}'); } - public function loadTemplate( t : String ) { + public function loadTemplate(t:String) { templo.Loader.OPTIMIZED = App.config.DEBUG == false; templo.Loader.BASE_DIR = App.config.TPL; templo.Loader.TMP_DIR = App.config.TPL_TMP; - if ( t == null ) return null; + if (t == null) + return null; #if neko - return new templo.Loader(t, App.config.getBool("cachetpl")); + return new templo.Loader(t, App.config.getBool("cachetpl")); #else - return new templo.Loader(t); + return new templo.Loader(t); #end } - public function setTemplate( t : String ) { + public function setTemplate(t:String) { template = t == null ? null : loadTemplate(t); } - public function initLang( lang : String ) { - - if (lang == null || lang == "") lang = config.LANG; - - //Define template path + public function initLang(lang:String) { + if (lang == null || lang == "") + lang = config.LANG; + + // Define template path var path; - if (!App.config.DEBUG){ + if (!App.config.DEBUG) { path = Web.getCwd() + "../lang/" + lang + "/"; - }else{ + } else { path = Web.getCwd() + "../lang/master/"; } App.config.TPL = path + "tpl/"; App.config.TPL_TMP = path + "tmp/"; - - //init system locale - if ( !Sys.setTimeLocale("en_US.UTF-8") ) { + + // init system locale + if (!Sys.setTimeLocale("en_US.UTF-8")) { Sys.setTimeLocale("en"); } - - //init gettext translator + + // init gettext translator sugoi.i18n.Locale.init(lang); - + return true; } function saveAndClose() { - - if( cnx == null ) return; - if( session.sid != null ) + if (cnx == null) + return; + if (session.sid != null) session.update(); - + cnx.commit(); cnx.close(); untyped cnx.close = function() {} untyped cnx.request = function(s) return null; } - function executeTemplate( ?save ) { + function executeTemplate(?save) { view.init(); var result = template.execute(view); - if ( save ) saveAndClose(); + if (save) + saveAndClose(); #if php - //strange bug with templo in PHP - if (result.substr(0, 4) == "null") result = result.substr(4); + // strange bug with templo in PHP + if (result.substr(0, 4) == "null") + result = result.substr(4); #end Sys.print(result); } - function onMeta( m : String, args : Array ) { - switch( m ) { - case "tpl": - setTemplate(args[0]); - case "logged": - if ( user == null ) - throw sugoi.ControllerAction.RedirectAction("/?__redirect="+Web.getURI()); - case "admin": - if( user == null || !user.isAdmin() ) - throw sugoi.ControllerAction.RedirectAction("/"); - default: + function onMeta(m:String, args:Array) { + switch (m) { + case "tpl": + setTemplate(args[0]); + case "logged": + if (user == null) + throw sugoi.ControllerAction.RedirectAction("/?__redirect=" + Web.getURI()); + case "admin": + if (user == null || !user.isAdmin()) + throw sugoi.ControllerAction.RedirectAction("/"); + default: } } @@ -124,111 +135,109 @@ class BaseApp { */ function detectLang() { var l = Web.getClientHeader("Accept-Language"); - if( l != null ) - for( l in l.split(",") ) { + if (l != null) + for (l in l.split(",")) { l = l.split(";")[0]; l = l.split("-")[0]; l = StringTools.trim(l); - for( a in App.config.LANGS ) - if( a == l ) + for (a in App.config.LANGS) + if (a == l) return a; } - + return App.config.LANG; } - - + /** * Setup current app language */ function setupLang() { - - //this app is monolingual and doesn't manage i18n - if (App.config.LANG == "master") return; - - //lang is taken from user object or from HTTP headers - if ( session.lang == null || !Lambda.has(App.config.LANGS, session.lang) ){ + // this app is monolingual and doesn't manage i18n + if (App.config.LANG == "master") + return; + + // lang is taken from user object or from HTTP headers + if (session.lang == null || !Lambda.has(App.config.LANGS, session.lang)) { session.lang = (user == null) ? detectLang() : user.lang; } - - //override if param is given + + // override if param is given var lang = params.get("lang"); - if ( lang != null && Lambda.has(App.config.LANGS, lang) ){ + if (lang != null && Lambda.has(App.config.LANGS, lang)) { session.lang = lang; - } - - //init lang + + // init lang initLang(session.lang); } - + /** * Get current application langage (2 letters lowercase) */ - public function getLang(){ + public function getLang() { return (session != null && session.lang != null && session.lang != "") ? session.lang : App.config.LANG; } public function rollback() { - if( cnx != null ) cnx.rollback(); + if (cnx != null) + cnx.rollback(); sys.db.Manager.cleanup(); - if( user != null && session != null ) + if (user != null && session != null) user = session.user; // does not reset session } - public function setCookie( oldCookie : String ){ - if( session != null && session.sid != null && session.sid != oldCookie ) { - Web.setHeader("Set-Cookie", cookieName+"=" + session.sid + "; path=/;"); + public function setCookie(oldCookie:String) { + if (session != null && session.sid != null && session.sid != oldCookie) { + Web.setHeader("Set-Cookie", cookieName + "=" + session.sid + "; path=/;"); } } function mainLoop() { params = Web.getParams(); - - //Get session + + // Get session var sids = []; var cookieSid = Web.getCookies().get(cookieName); - if( params.exists("sid") ) sids.push(params.get("sid")); - if( cookieSid != null ) sids.push(cookieSid); + if (params.exists("sid")) + sids.push(params.get("sid")); + if (cookieSid != null) + sids.push(cookieSid); session = sugoi.db.Session.init(sids); - - //Check for maintenance + + // Check for maintenance maintain = sugoi.db.Variable.getInt("maintain") != 0; user = session.user; - - //setup langage + + // setup langage setupLang(); - - - if( maintain && ((user != null && user.isAdmin()) ) ) + + if (maintain && ((user != null && user.isAdmin()))) maintain = false; - + setCookie(cookieSid); - - if( maintain ) { + + if (maintain) { setTemplate("maintain.mtt"); executeTemplate(); return; } - - //dispatching + + // dispatching try { - uri = Web.getURI(); - if ( StringTools.endsWith(uri, "/index.n") ) uri = uri.substr(0, -8); - - //"before dispatch" callback + if (StringTools.endsWith(uri, "/index.n")) + uri = uri.substr(0, -8); + + // "before dispatch" callback beforeDispatch(); - + var d = new haxe.web.Dispatch(uri, params); d.onMeta = onMeta; d.dispatch(new controller.Main()); - - } catch ( e : haxe.web.Dispatch.DispatchError ) { - - //dispatch / routing error - if ( App.config.DEBUG ) { + } catch (e:haxe.web.Dispatch.DispatchError) { + // dispatch / routing error + if (App.config.DEBUG) { #if neko neko.Lib.rethrow(e); #else @@ -238,48 +247,48 @@ class BaseApp { cnx.rollback(); Web.redirect("/"); return; - - } catch ( e : sugoi.ControllerAction) { - - switch( e ) { - case RedirectAction(url): - Web.redirect(url); - template = null; - case ErrorAction(url, text), OkAction(url,text): - if( text == null ) { - text = url; - url = Web.getURI(); - } - Web.redirect(url); - var error = switch(e) { case ErrorAction(_): true; default: false; }; - if( error ) rollback(); - if ( error ) { - session.addMessage(text,true); - }else { - session.addMessage(text); - } - template = null; + } catch (e:sugoi.ControllerAction) { + switch (e) { + case RedirectAction(url): + Web.redirect(url); + template = null; + case ErrorAction(url, text), OkAction(url, text): + if (text == null) { + text = url; + url = Web.getURI(); + } + Web.redirect(url); + var error = switch (e) { + case ErrorAction(_): true; + default: false; + }; + if (error) + rollback(); + if (error) { + session.addMessage(text, true); + } else { + session.addMessage(text); + } + template = null; } } - - //Render template - if ( template == null ) { + + // Render template + if (template == null) { saveAndClose(); - } else { + } else { executeTemplate(true); // will saveAndClose } } - + /** * Override this function if you want * to insert some actions */ - public function beforeDispatch() { - - } + public function beforeDispatch() {} - public function logError( e : Dynamic, ?stack : String ) { - var stack = if( stack != null ) stack else haxe.CallStack.toString(haxe.CallStack.exceptionStack()); + public function logError(e:Dynamic, ?stack:String) { + var stack = if (stack != null) stack else haxe.CallStack.toString(haxe.CallStack.exceptionStack()); var message = new StringBuf(); message.add(Std.string(e)); message.add("\n"); @@ -288,43 +297,42 @@ class BaseApp { var e = new sugoi.db.Error(); e.url = Web.getURI(); e.ip = Web.getClientIP(); - e.user = if( user != null ) user else null; + e.user = if (user != null) user else null; e.date = Date.now(); e.userAgent = Web.getClientHeader("User-Agent"); e.error = message.toString(); e.insert(); } - function errorHandler( e:Dynamic ) { + function errorHandler(e:Dynamic) { try { var stack = haxe.CallStack.toString(haxe.CallStack.exceptionStack()); // ROLLBACK and LOG - if ( cnx != null ) { + if (cnx != null) { cnx.rollback(); - logError(e,stack); + logError(e, stack); } - - //log also in a file, in case we don't have a valid connexion to DB - Web.logMessage(e+"\n" + stack); - + + // log also in a file, in case we don't have a valid connexion to DB + Web.logMessage(e + "\n" + stack); + maintain = true; view = new View(); view.message = Std.string(e); - if ( App.config.DEBUG || (user != null && user.isAdmin()) ) { + if (App.config.DEBUG || (user != null && user.isAdmin())) { view.stack = stack; } - + setTemplate("error.mtt"); executeTemplate(false); - - } catch( e : Dynamic ) { + } catch (e:Dynamic) { Sys.print("
");
-			Sys.println("Error : "+try Std.string(e) catch( e : Dynamic ) "???");
+			Sys.println("Error : " + try Std.string(e) catch (e:Dynamic) "???");
 			Sys.println(haxe.CallStack.toString(haxe.CallStack.exceptionStack()));
 			try {
-				if( cnx != null )
-					sugoi.db.Error.manager.get(0,false);
-			} catch( e : Dynamic ) {
+				if (cnx != null)
+					sugoi.db.Error.manager.get(0, false);
+			} catch (e:Dynamic) {
 				Sys.println("Initializing Database...");
 				sys.db.Admin.initializeDatabase();
 				Sys.println("Done");
@@ -339,7 +347,7 @@ class BaseApp {
 	 */
 	function init() {
 		maintain = App.config.getBool("maintain");
-		if( maintain ) {
+		if (maintain) {
 			view = new View();
 			setTemplate("maintain.mtt");
 			executeTemplate(false);
@@ -348,23 +356,23 @@ class BaseApp {
 		try {
 			var dbstr = App.config.get("database");
 			var dbreg = ~/([^:]+):\/\/([^:]+):([^@]*?)@([^:]+)(:[0-9]+)?\/(.*?)$/;
-			if( !dbreg.match(dbstr) )
+			if (!dbreg.match(dbstr))
 				throw "Configuration requires a valid database attribute, format is : mysql://user:password@host:port/dbname";
 			var port = dbreg.matched(5);
 			var dbparams = {
-				user:dbreg.matched(2),
-				pass:dbreg.matched(3),
-				host:dbreg.matched(4),
-				port:port == null ? 3306 : Std.parseInt(port.substr(1)),
-				database:dbreg.matched(6),
-				socket:null
+				user: dbreg.matched(2),
+				pass: dbreg.matched(3),
+				host: dbreg.matched(4),
+				port: port == null ? 3306 : Std.parseInt(port.substr(1)),
+				database: dbreg.matched(6),
+				socket: null
 			};
 			cnx = sys.db.Mysql.connect(dbparams);
-		} catch( e : Dynamic ) {
+		} catch (e:Dynamic) {
 			errorHandler(e);
 			return false;
 		}
-		if( App.config.SQL_LOG )
+		if (App.config.SQL_LOG)
 			cnx = new sugoi.tools.DebugConnection(cnx);
 		return true;
 	}
@@ -372,7 +380,7 @@ class BaseApp {
 	function cloneApp() {
 		// ensure that we have no variable initialized in app loop
 		var app = new App();
-		var bapp : BaseApp = app;
+		var bapp:BaseApp = app;
 		bapp.cnx = cnx;
 		bapp.view = new View();
 		App.current = app;
@@ -380,13 +388,15 @@ class BaseApp {
 	}
 
 	function run() {
-
 		// Will close the connection
-		sys.db.Transaction.main(cnx, cloneApp, function(e) { var b : BaseApp = App.current; b.errorHandler(e); });
+		sys.db.Transaction.main(cnx, cloneApp, function(e) {
+			var b:BaseApp = App.current;
+			b.errorHandler(e);
+		});
 		App.current = null;
 	}
 
-	function sendHeaders(){
+	function sendHeaders() {
 		Web.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
 		Web.setHeader("Pragma", "no-cache");
 		Web.setHeader("Expires", "-1");
@@ -396,28 +406,28 @@ class BaseApp {
 	}
 
 	static function main() {
-		
 		/**
 		 * this macro will parse the code and generate the allTexts.pot file
 		 * which will be used as a template for translation files (*.po and *.mo)
 		 */
 		#if i18n_parsing
-		if( false ) sugoi.i18n.GetText.parse(["src", "lang/master","js","common"], "www/lang/allTexts.pot");
+		if (false)
+			sugoi.i18n.GetText.parse(["src", "lang/master", "js", "common"], "www/lang/allTexts.pot");
 		#end
-		
+
 		App.current = new App();
-		var a : BaseApp = App.current;
-		
+		var a:BaseApp = App.current;
+
 		a.sendHeaders();
 
-		if( !a.init() ) {
+		if (!a.init()) {
 			a = null;
 			return;
 		}
 		a.run();
 		a = null;
 		#if neko
-		if ( App.config.getInt("cache", 0) == 1 ) {			
+		if (App.config.getInt("cache", 0) == 1) {
 			neko.Web.cacheModule(App.main);
 		}
 		#end
diff --git a/src/sugoi/mail/Mail.hx b/src/sugoi/mail/Mail.hx
index 862fbb9..1d9787f 100644
--- a/src/sugoi/mail/Mail.hx
+++ b/src/sugoi/mail/Mail.hx
@@ -32,8 +32,8 @@ class Mail implements IMail {
 	public function setSender(email, ?name, ?userId) {
 		if (!isValid(email))
 			throw "invalid sender email : \"" + email + "\"";
-
-		sender = {name: name, email: email, userId: userId};
+		var finalName = (name != null) ? thx.text.Diactrics.clean(name) : null;
+		sender = {name: finalName, email: email, userId: userId};
 		return this;
 	}
 
diff --git a/www/lang/texts_fr.po b/www/lang/texts_fr.po
index 6f14500..80bf3c3 100644
--- a/www/lang/texts_fr.po
+++ b/www/lang/texts_fr.po
@@ -1538,7 +1538,7 @@ msgid ""
 "Group and user 'admin' created. Your email is 'admin@cagette.net' and your "
 "password is 'admin'"
 msgstr ""
-"Groupe et utilisateur 'admin' créé. Votre email est 'admin@cagette.net' et "
+"Groupe et utilisateur 'admin' créé. Votre email est 'admin@cagettepei.re' et "
 "votre mot de passe est 'admin'"
 
 #: src/controller/Install.hx:4677
@@ -4551,7 +4551,7 @@ msgstr "Extrait non exhaustif des produits proposés :"
 
 #: lang/master/tpl/group/view.mtt:5027
 msgid "http://www.cagette.net"
-msgstr "http://www.cagette.net"
+msgstr "https://git.artcode.re/cagetters/cagettepei"
 
 #: lang/master/tpl/group/view.mtt:5060
 msgid "Cagette.net, the free software of food direct-selling"
@@ -4618,7 +4618,7 @@ msgid ""
 "Cagette.net is made by "
 msgstr ""
-"CagettePéi est une fourche du logiciel Cagette.net réalisé par "
 
 #: lang/master/tpl/validate/user.mtt:2124