Update domframework to be gettext package compliant

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1661 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2014-08-06 13:16:43 +00:00
parent ab7f76d0bb
commit b8a3e1aa23
13 changed files with 223 additions and 111 deletions

View File

@@ -50,17 +50,22 @@ class auth
$res .= "<div class='container'>\n"; $res .= "<div class='container'>\n";
$res .= " <form class='form-signin' role='form' method='post' "; $res .= " <form class='form-signin' role='form' method='post' ";
$res .= "action='#'>\n"; $res .= "action='#'>\n";
$res .= " <h2 class='form-signin-heading'>"._("Please sign in"); $res .= " <h2 class='form-signin-heading'>".dgettext("domframework",
"Please sign in");
$res .= "</h2>\n"; $res .= "</h2>\n";
$res .= " <input type='text' class='form-control' name='email' "; $res .= " <input type='text' class='form-control' name='email' ";
$res .= "placeholder='"._("Email address")."' required autofocus/>\n"; $res .= "placeholder='".dgettext("domframework",
"Email address")."' required autofocus/>\n";
$res .= " <input type='password' class='form-control' name='password' "; $res .= " <input type='password' class='form-control' name='password' ";
$res .= "placeholder='"._("Password")."' required/>\n"; $res .= "placeholder='".dgettext("domframework",
"Password")."' required/>\n";
$res .= " <label class='checkbox'>"; $res .= " <label class='checkbox'>";
$res .= "<input type='checkbox' name='remember-me'/>"._("Remember me"); $res .= "<input type='checkbox' name='remember-me'/>".dgettext("domframework",
"Remember me");
$res .= "</label>\n"; $res .= "</label>\n";
$res .= " <button class='btn btn-lg btn-primary btn-block' "; $res .= " <button class='btn btn-lg btn-primary btn-block' ";
$res .= "type='submit'>"._("Sign in")."</button>\n"; $res .= "type='submit'>".dgettext("domframework",
"Sign in")."</button>\n";
if ($message !== "") if ($message !== "")
$res .= "<div class='alert alert-danger'>$message</div>"; $res .= "<div class='alert alert-danger'>$message</div>";
$res .= " </form>\n"; $res .= " </form>\n";
@@ -73,7 +78,8 @@ class auth
/** Establish the connection to authentication server */ /** Establish the connection to authentication server */
public function connect () public function connect ()
{ {
throw new Exception (_("No connect to authentication available"), 405); throw new Exception (dgettext("domframework",
"No connect to authentication available"), 405);
} }
/** Check if the email and password are correct /** Check if the email and password are correct
@@ -83,13 +89,15 @@ class auth
@param string $password Password to authenticate */ @param string $password Password to authenticate */
public function authentication ($email, $password) public function authentication ($email, $password)
{ {
throw new exception (_("No authentication available"), 405); throw new exception (dgettext("domframework",
"No authentication available"), 405);
} }
/** Return all the parameters recorded for the authenticate user */ /** Return all the parameters recorded for the authenticate user */
public function getdetails () public function getdetails ()
{ {
throw new exception (_("No getdetails available"), 405); throw new exception (dgettext("domframework",
"No getdetails available"), 405);
} }
/** Method to change the password /** Method to change the password
@@ -98,13 +106,15 @@ class auth
@param string $newpassword The new password to be recorded */ @param string $newpassword The new password to be recorded */
public function changepassword ($oldpassword, $newpassword) public function changepassword ($oldpassword, $newpassword)
{ {
throw new exception (_("No password change available"), 405); throw new exception (dgettext("domframework",
"No password change available"), 405);
} }
/** List all the users available in the database /** List all the users available in the database
Return firstname, lastname, mail, with mail is an array */ Return firstname, lastname, mail, with mail is an array */
public function listusers () public function listusers ()
{ {
throw new exception (_("No List User available"), 405); throw new exception (dgettext("domframework",
"No List User available"), 405);
} }
} }

View File

@@ -101,7 +101,8 @@ class authldap extends auth
@param string $newpassword The new password to be recorded */ @param string $newpassword The new password to be recorded */
public function changepassword ($oldpassword, $newpassword) public function changepassword ($oldpassword, $newpassword)
{ {
throw new Exception (_("The password can't be change for LDAP users"), 405); throw new Exception (dgettext("domframework",
"The password can't be change for LDAP users"), 405);
} }
/** List all the users available in the database /** List all the users available in the database

View File

@@ -44,7 +44,8 @@ class authorizationdb extends authorization
public function initialize () public function initialize ()
{ {
if ($this->db === null) if ($this->db === null)
throw new Exception (_("Database to authorize is not connected"), 500); throw new Exception (dgettext("domframework",
"Database to authorize is not connected"), 500);
$tables = $this->db->listTables (); $tables = $this->db->listTables ();
if (!in_array ($this->db->tableprefix.$this->db->table, $tables)) if (!in_array ($this->db->tableprefix.$this->db->table, $tables))
{ {
@@ -62,14 +63,17 @@ class authorizationdb extends authorization
public function validate ($object) public function validate ($object)
{ {
if ($this->db === null) if ($this->db === null)
throw new Exception (_("Database to authorize is not connected"), 500); throw new Exception (dgettext("domframework",
"Database to authorize is not connected"), 500);
if (substr ($object, -1) === "/") if (substr ($object, -1) === "/")
$object = substr ($object, 0, -1); $object = substr ($object, 0, -1);
if (substr ($object, 0, 1) !== "/") if (substr ($object, 0, 1) !== "/")
throw new Exception (_("Object don't start by slash"), 406); throw new Exception (dgettext("domframework",
"Object don't start by slash"), 406);
$object = preg_replace ("#//+#", "/", $object); $object = preg_replace ("#//+#", "/", $object);
if ($this->authiduser === "") if ($this->authiduser === "")
throw new Exception (_("Not authenticated"), 401); throw new Exception (dgettext("domframework",
"Not authenticated"), 401);
try try
{ {
$this->treecheckExecute ($object); $this->treecheckExecute ($object);
@@ -83,7 +87,9 @@ class authorizationdb extends authorization
// exists // exists
$search = $this->db->read (array (array ("object", $object))); $search = $this->db->read (array (array ("object", $object)));
if (count ($search) === 0) if (count ($search) === 0)
throw new Exception (sprintf (_("Object %s doesn't exists"), $object), throw new Exception (sprintf (dgettext("domframework",
"Object %s doesn't exists"),
$object),
404); 404);
$search = reset ($search); $search = reset ($search);
$ownerid = intval ($search["ownerid"]); $ownerid = intval ($search["ownerid"]);
@@ -134,20 +140,25 @@ class authorizationdb extends authorization
public function add ($object, $ownerid, $groupid, $modbits) public function add ($object, $ownerid, $groupid, $modbits)
{ {
if ($this->db === null) if ($this->db === null)
throw new Exception (_("Database to authorize is not connected"), 500); throw new Exception (dgettext("domframework",
"Database to authorize is not connected"), 500);
// The modbits are stored in octal to be more readable // The modbits are stored in octal to be more readable
$modbits = decoct ($modbits); $modbits = decoct ($modbits);
if (substr ($object, -1) === "/") if (substr ($object, -1) === "/")
$object = substr ($object, 0, -1); $object = substr ($object, 0, -1);
if (substr ($object, 0, 1) !== "/") if (substr ($object, 0, 1) !== "/")
throw new Exception (_("Object don't start by slash"), 406); throw new Exception (dgettext("domframework",
"Object don't start by slash"), 406);
$object = preg_replace ("#//+#", "/", $object); $object = preg_replace ("#//+#", "/", $object);
if ($this->authiduser === "") if ($this->authiduser === "")
throw new Exception (_("Not authenticated"), 401); throw new Exception (dgettext("domframework",
"Not authenticated"), 401);
if ($this->authiduser !== 0 && $this->authiduser !== $ownerid) if ($this->authiduser !== 0 && $this->authiduser !== $ownerid)
throw new Exception (_("Can't create object not owned by myself"), 406); throw new Exception (dgettext("domframework",
"Can't create object not owned by myself"), 406);
if ($this->authiduser !== 0 && !in_array ($groupid, $this->authgroups)) if ($this->authiduser !== 0 && !in_array ($groupid, $this->authgroups))
throw new Exception (_("Can't create object with not owned group"), 406); throw new Exception (dgettext("domframework",
"Can't create object with not owned group"), 406);
try try
{ {
$this->treecheckExecute ($object); $this->treecheckExecute ($object);
@@ -161,7 +172,8 @@ class authorizationdb extends authorization
// exists // exists
$search = $this->db->read (array (array ("object", $object))); $search = $this->db->read (array (array ("object", $object)));
if (count ($search)) if (count ($search))
throw new Exception (sprintf (_("Object %s already defined"), $object), throw new Exception (sprintf (dgettext("domframework",
"Object %s already defined"), $object),
400); 400);
// All the folder structure is accessible. Check if we can add the file in // All the folder structure is accessible. Check if we can add the file in
@@ -197,16 +209,20 @@ class authorizationdb extends authorization
public function drop ($object) public function drop ($object)
{ {
if ($this->db === null) if ($this->db === null)
throw new Exception (_("Database to authorize is not connected"), 500); throw new Exception (dgettext("domframework",
"Database to authorize is not connected"), 500);
if (substr ($object, -1) === "/") if (substr ($object, -1) === "/")
$object = substr ($object, 0, -1); $object = substr ($object, 0, -1);
if (substr ($object, 0, 1) !== "/") if (substr ($object, 0, 1) !== "/")
throw new Exception (_("Object don't start by slash"), 406); throw new Exception (dgettext("domframework",
"Object don't start by slash"), 406);
$object = preg_replace ("#//+#", "/", $object); $object = preg_replace ("#//+#", "/", $object);
if ($this->authiduser === "") if ($this->authiduser === "")
throw new Exception (_("Not authenticated"), 401); throw new Exception (dgettext("domframework",
"Not authenticated"), 401);
if ($object === "/") if ($object === "/")
throw new Exception (_("The root can not be removed"), 406); throw new Exception (dgettext("domframework",
"The root can not be removed"), 406);
try try
{ {
$this->treecheckExecute ($object); $this->treecheckExecute ($object);
@@ -220,8 +236,9 @@ class authorizationdb extends authorization
// exists // exists
$search = $this->db->read (array (array ("object", $object))); $search = $this->db->read (array (array ("object", $object)));
if (count ($search) === 0) if (count ($search) === 0)
throw new Exception (sprintf (_("Object %s doesn't exists"), $object), throw new Exception (sprintf (dgettext("domframework",
400); "Object %s doesn't exists"),
$object), 400);
// All the folder structure is accessible. Check if we can remove the file // All the folder structure is accessible. Check if we can remove the file
// in the last folder (Write modbit). Root can always write. // in the last folder (Write modbit). Root can always write.
@@ -229,9 +246,11 @@ class authorizationdb extends authorization
{ {
$rc = $this->db->delete ($object); $rc = $this->db->delete ($object);
if ($rc > 1) if ($rc > 1)
throw new Exception (_("Removing more than one object"), 406); throw new Exception (dgettext("domframework",
"Removing more than one object"), 406);
if ($rc == 0) if ($rc == 0)
throw new Exception (_("No object removed"), 406); throw new Exception (dgettext("domframework",
"No object removed"), 406);
$rc = $this->db->delete ("$object$this->separator%"); $rc = $this->db->delete ("$object$this->separator%");
return TRUE; return TRUE;
} }
@@ -247,9 +266,11 @@ class authorizationdb extends authorization
$rc = $this->db->delete ($object); $rc = $this->db->delete ($object);
if ($rc > 1) if ($rc > 1)
throw new Exception (_("Removing more than one object"), 406); throw new Exception (dgettext("domframework",
"Removing more than one object"), 406);
if ($rc == 0) if ($rc == 0)
throw new Exception (_("No object removed"), 406); throw new Exception (dgettext("domframework",
"No object removed"), 406);
$rc = $this->db->delete ("$object$this->separator%"); $rc = $this->db->delete ("$object$this->separator%");
return TRUE; return TRUE;
} }
@@ -262,16 +283,20 @@ class authorizationdb extends authorization
public function chown ($object, $ownerid) public function chown ($object, $ownerid)
{ {
if ($this->db === null) if ($this->db === null)
throw new Exception (_("Database to authorize is not connected"), 500); throw new Exception (dgettext("domframework",
"Database to authorize is not connected"), 500);
if (substr ($object, -1) === "/") if (substr ($object, -1) === "/")
$object = substr ($object, 0, -1); $object = substr ($object, 0, -1);
if (substr ($object, 0, 1) !== "/") if (substr ($object, 0, 1) !== "/")
throw new Exception (_("Object don't start by slash"), 406); throw new Exception (dgettext("domframework",
"Object don't start by slash"), 406);
$object = preg_replace ("#//+#", "/", $object); $object = preg_replace ("#//+#", "/", $object);
if ($this->authiduser === "") if ($this->authiduser === "")
throw new Exception (_("Not authenticated"), 401); throw new Exception (dgettext("domframework",
"Not authenticated"), 401);
if ($this->authiduser !== 0) if ($this->authiduser !== 0)
throw new Exception (_("The chown is reserved to root user"), 405); throw new Exception (dgettext("domframework",
"The chown is reserved to root user"), 405);
try try
{ {
$this->treecheckExecute ($object); $this->treecheckExecute ($object);
@@ -285,7 +310,8 @@ class authorizationdb extends authorization
// exists // exists
$search = $this->db->read (array (array ("object", $object))); $search = $this->db->read (array (array ("object", $object)));
if (count ($search) === 0) if (count ($search) === 0)
throw new Exception (sprintf (_("Object %s doesn't exists"), $object), throw new Exception (sprintf (dgettext("domframework",
"Object %s doesn't exists"), $object),
400); 400);
$search = reset ($search); $search = reset ($search);
$this->db->update ($object, array ("ownerid"=>$ownerid)); $this->db->update ($object, array ("ownerid"=>$ownerid));
@@ -300,18 +326,23 @@ class authorizationdb extends authorization
public function chgrp ($object, $groupid) public function chgrp ($object, $groupid)
{ {
if ($this->db === null) if ($this->db === null)
throw new Exception (_("Database to authorize is not connected"), 500); throw new Exception (dgettext("domframework",
"Database to authorize is not connected"), 500);
if (substr ($object, -1) === "/") if (substr ($object, -1) === "/")
$object = substr ($object, 0, -1); $object = substr ($object, 0, -1);
if (substr ($object, 0, 1) !== "/") if (substr ($object, 0, 1) !== "/")
throw new Exception (_("Object don't start by slash"), 406); throw new Exception (dgettext("domframework",
"Object don't start by slash"), 406);
$object = preg_replace ("#//+#", "/", $object); $object = preg_replace ("#//+#", "/", $object);
if ($this->authiduser === "") if ($this->authiduser === "")
throw new Exception (_("Not authenticated"), 401); throw new Exception (dgettext("domframework",
"Not authenticated"), 401);
if ($this->authiduser !== 0 && !in_array ($groupid, $this->authgroups)) if ($this->authiduser !== 0 && !in_array ($groupid, $this->authgroups))
throw new Exception (_("The user must be in the wanted group"), 405); throw new Exception (dgettext("domframework",
"The user must be in the wanted group"), 405);
if (!in_array ("WRITE", $this->validate ($object))) if (!in_array ("WRITE", $this->validate ($object)))
throw new Exception (sprintf (_("%s is write protected"), $object), 405); throw new Exception (sprintf (dgettext("domframework",
"%s is write protected"), $object), 405);
try try
{ {
$this->treecheckExecute ($object); $this->treecheckExecute ($object);
@@ -325,7 +356,8 @@ class authorizationdb extends authorization
// exists // exists
$search = $this->db->read (array (array ("object", $object))); $search = $this->db->read (array (array ("object", $object)));
if (count ($search) === 0) if (count ($search) === 0)
throw new Exception (sprintf (_("Object %s doesn't exists"), $object), throw new Exception (sprintf (dgettext("domframework",
"Object %s doesn't exists"), $object),
400); 400);
$search = reset ($search); $search = reset ($search);
$this->db->update ($object, array ("groupid"=>$groupid)); $this->db->update ($object, array ("groupid"=>$groupid));
@@ -340,16 +372,20 @@ class authorizationdb extends authorization
public function chmod ($object, $mod) public function chmod ($object, $mod)
{ {
if ($this->db === null) if ($this->db === null)
throw new Exception (_("Database to authorize is not connected"), 500); throw new Exception (dgettext("domframework",
"Database to authorize is not connected"), 500);
if (substr ($object, -1) === "/") if (substr ($object, -1) === "/")
$object = substr ($object, 0, -1); $object = substr ($object, 0, -1);
if (substr ($object, 0, 1) !== "/") if (substr ($object, 0, 1) !== "/")
throw new Exception (_("Object don't start by slash"), 406); throw new Exception (dgettext("domframework",
"Object don't start by slash"), 406);
$object = preg_replace ("#//+#", "/", $object); $object = preg_replace ("#//+#", "/", $object);
if ($this->authiduser === "") if ($this->authiduser === "")
throw new Exception (_("Not authenticated"), 401); throw new Exception (dgettext("domframework",
"Not authenticated"), 401);
if (!in_array ("WRITE", $this->validate ($object))) if (!in_array ("WRITE", $this->validate ($object)))
throw new Exception (sprintf (_("%s is write protected"), $object), 405); throw new Exception (sprintf (dgettext("domframework",
"%s is write protected"), $object), 405);
try try
{ {
$this->treecheckExecute ($object); $this->treecheckExecute ($object);
@@ -363,7 +399,8 @@ class authorizationdb extends authorization
// exists // exists
$search = $this->db->read (array (array ("object", $object))); $search = $this->db->read (array (array ("object", $object)));
if (count ($search) === 0) if (count ($search) === 0)
throw new Exception (sprintf (_("Object %s doesn't exists"), $object), throw new Exception (sprintf (dgettext("domframework",
"Object %s doesn't exists"), $object),
400); 400);
$search = reset ($search); $search = reset ($search);
// TODO : Don't update if the user is not the owner of the file // TODO : Don't update if the user is not the owner of the file
@@ -378,14 +415,17 @@ class authorizationdb extends authorization
public function lsmod ($object) public function lsmod ($object)
{ {
if ($this->db === null) if ($this->db === null)
throw new Exception (_("Database to authorize is not connected"), 500); throw new Exception (dgettext("domframework",
"Database to authorize is not connected"), 500);
if (substr ($object, -1) === "/") if (substr ($object, -1) === "/")
$object = substr ($object, 0, -1); $object = substr ($object, 0, -1);
if (substr ($object, 0, 1) !== "/") if (substr ($object, 0, 1) !== "/")
throw new Exception (_("Object don't start by slash"), 406); throw new Exception (dgettext("domframework",
"Object don't start by slash"), 406);
$object = preg_replace ("#//+#", "/", $object); $object = preg_replace ("#//+#", "/", $object);
if ($this->authiduser === "") if ($this->authiduser === "")
throw new Exception (_("Not authenticated"), 401); throw new Exception (dgettext("domframework",
"Not authenticated"), 401);
try try
{ {
$this->treecheckExecute ($object); $this->treecheckExecute ($object);
@@ -399,7 +439,8 @@ class authorizationdb extends authorization
// exists // exists
$search = $this->db->read (array (array ("object", $object))); $search = $this->db->read (array (array ("object", $object)));
if (count ($search) === 0) if (count ($search) === 0)
throw new Exception (sprintf (_("Object %s doesn't exists"), $object), throw new Exception (sprintf (dgettext("domframework",
"Object %s doesn't exists"), $object),
400); 400);
$search = reset ($search); $search = reset ($search);
return octdec ($search["modbits"]); return octdec ($search["modbits"]);
@@ -412,14 +453,17 @@ class authorizationdb extends authorization
public function lsown ($object) public function lsown ($object)
{ {
if ($this->db === null) if ($this->db === null)
throw new Exception (_("Database to authorize is not connected"), 500); throw new Exception (dgettext("domframework",
"Database to authorize is not connected"), 500);
if (substr ($object, -1) === "/") if (substr ($object, -1) === "/")
$object = substr ($object, 0, -1); $object = substr ($object, 0, -1);
if (substr ($object, 0, 1) !== "/") if (substr ($object, 0, 1) !== "/")
throw new Exception (_("Object don't start by slash"), 406); throw new Exception (dgettext("domframework",
"Object don't start by slash"), 406);
$object = preg_replace ("#//+#", "/", $object); $object = preg_replace ("#//+#", "/", $object);
if ($this->authiduser === "") if ($this->authiduser === "")
throw new Exception (_("Not authenticated"), 401); throw new Exception (dgettext("domframework",
"Not authenticated"), 401);
try try
{ {
$this->treecheckExecute ($object); $this->treecheckExecute ($object);
@@ -433,7 +477,8 @@ class authorizationdb extends authorization
// exists // exists
$search = $this->db->read (array (array ("object", $object))); $search = $this->db->read (array (array ("object", $object)));
if (count ($search) === 0) if (count ($search) === 0)
throw new Exception (sprintf (_("Object %s doesn't exists"), $object), throw new Exception (sprintf (dgettext("domframework",
"Object %s doesn't exists"), $object),
400); 400);
$search = reset ($search); $search = reset ($search);
return intval ($search["ownerid"]); return intval ($search["ownerid"]);
@@ -446,14 +491,17 @@ class authorizationdb extends authorization
public function lsgrp ($object) public function lsgrp ($object)
{ {
if ($this->db === null) if ($this->db === null)
throw new Exception (_("Database to authorize is not connected"), 500); throw new Exception (dgettext("domframework",
"Database to authorize is not connected"), 500);
if (substr ($object, -1) === "/") if (substr ($object, -1) === "/")
$object = substr ($object, 0, -1); $object = substr ($object, 0, -1);
if (substr ($object, 0, 1) !== "/") if (substr ($object, 0, 1) !== "/")
throw new Exception (_("Object don't start by slash"), 406); throw new Exception (dgettext("domframework",
"Object don't start by slash"), 406);
$object = preg_replace ("#//+#", "/", $object); $object = preg_replace ("#//+#", "/", $object);
if ($this->authiduser === "") if ($this->authiduser === "")
throw new Exception (_("Not authenticated"), 401); throw new Exception (dgettext("domframework",
"Not authenticated"), 401);
try try
{ {
$this->treecheckExecute ($object); $this->treecheckExecute ($object);
@@ -467,7 +515,8 @@ class authorizationdb extends authorization
// exists // exists
$search = $this->db->read (array (array ("object", $object))); $search = $this->db->read (array (array ("object", $object)));
if (count ($search) === 0) if (count ($search) === 0)
throw new Exception (sprintf (_("Object %s doesn't exists"), $object), throw new Exception (sprintf (dgettext("domframework",
"Object %s doesn't exists"), $object),
404); 404);
$search = reset ($search); $search = reset ($search);
return intval ($search["groupid"]); return intval ($search["groupid"]);
@@ -482,7 +531,8 @@ class authorizationdb extends authorization
private function treecheckExecute ($object) private function treecheckExecute ($object)
{ {
if ($this->db === null) if ($this->db === null)
throw new Exception (_("Database to authorize is not connected"), 500); throw new Exception (dgettext("domframework",
"Database to authorize is not connected"), 500);
// Search all the parents in an array // Search all the parents in an array
$parents = array (); $parents = array ();
$par = $object; $par = $object;
@@ -518,7 +568,8 @@ class authorizationdb extends authorization
} }
} }
if (!$found) if (!$found)
throw new Exception (sprintf (_("The path %s is not found in database"), throw new Exception (sprintf (dgettext("domframework",
"The path %s is not found in database"),
$p), 404); $p), 404);
else else
{ {
@@ -542,7 +593,8 @@ class authorizationdb extends authorization
if (($parentModbits & 0001) === 1) if (($parentModbits & 0001) === 1)
continue; continue;
throw new Exception (sprintf (_("No execute rights on %s"), $p), 405); throw new Exception (sprintf (dgettext("domframework",
"No execute rights on %s"), $p), 405);
} }
} }
return TRUE; return TRUE;
@@ -572,6 +624,7 @@ class authorizationdb extends authorization
if (($parentModbits & 0002) === 2) if (($parentModbits & 0002) === 2)
return TRUE; return TRUE;
throw new Exception (sprintf (_("No write rights on %s"), $parent), 405); throw new Exception (sprintf (dgettext("domframework",
"No write rights on %s"), $parent), 405);
} }
} }

View File

@@ -29,7 +29,8 @@ class authparams
/** Get informations from a HTTP authentication */ /** Get informations from a HTTP authentication */
public function http() public function http()
{ {
$realm = _("Restricted access"); $realm = dgettext("domframework",
"Restricted access");
if (!isset($_SERVER['PHP_AUTH_USER'])) if (!isset($_SERVER['PHP_AUTH_USER']))
{ {
header("WWW-Authenticate: Basic realm=\"$realm\""); header("WWW-Authenticate: Basic realm=\"$realm\"");

View File

@@ -48,7 +48,8 @@ class authsession extends auth
@param string $newpassword The new password to be recorded */ @param string $newpassword The new password to be recorded */
public function changepassword ($oldpassword, $newpassword) public function changepassword ($oldpassword, $newpassword)
{ {
throw new Exception (_("The password can't be change for SESSION users"), throw new Exception (dgettext("domframework",
"The password can't be change for SESSION users"),
405); 405);
} }
} }

View File

@@ -41,14 +41,16 @@ class authsympa extends auth
public function __construct () public function __construct ()
{ {
if (! class_exists ("SoapClient")) if (! class_exists ("SoapClient"))
throw new Exception (_("No SOAP PHP library available"), 500); throw new Exception (dgettext("domframework",
"No SOAP PHP library available"), 500);
} }
/** Connect to the Sympa server */ /** Connect to the Sympa server */
public function connect () public function connect ()
{ {
if ($this->wsdl === null) if ($this->wsdl === null)
throw new Exception (_("No WSDL provided to Sympa auth"), 401); throw new Exception (dgettext("domframework",
"No WSDL provided to Sympa auth"), 401);
$this->client = new SoapClient($this->wsdl); $this->client = new SoapClient($this->wsdl);
} }
@@ -58,13 +60,15 @@ class authsympa extends auth
public function authentication ($email, $password) public function authentication ($email, $password)
{ {
if ($this->client === null) if ($this->client === null)
throw new Exception (_("The SOAP connection is not opened"), 401); throw new Exception (dgettext("domframework",
"The SOAP connection is not opened"), 401);
if ($this->list === null) if ($this->list === null)
throw new Exception (_("The list to check is not defined"), 401); throw new Exception (dgettext("domframework",
"The list to check is not defined"), 401);
$this->authkey = $this->client->login ($email, $password); $this->authkey = $this->client->login ($email, $password);
if ($this->authkey === null) if ($this->authkey === null)
throw new Exception ( throw new Exception (dgettext("domframework",
_("Can't connect with provided email/password to sympa"), "Can't connect with provided email/password to sympa"),
401); 401);
$this->email = $email; $this->email = $email;
$rc = $this->client->authenticateAndRun ($email, $this->authkey, $rc = $this->client->authenticateAndRun ($email, $this->authkey,
@@ -77,7 +81,8 @@ class authsympa extends auth
/** Return all the parameters recorded for the authenticate user */ /** Return all the parameters recorded for the authenticate user */
public function getdetails () public function getdetails ()
{ {
throw new Exception (_("The details can't be provided by Sympa"), 404); throw new Exception (dgettext("domframework",
"The details can't be provided by Sympa"), 404);
} }
/** Method to change the password /** Method to change the password
@@ -86,7 +91,8 @@ class authsympa extends auth
@param string $newpassword The new password to be recorded */ @param string $newpassword The new password to be recorded */
public function changepassword ($oldpassword, $newpassword) public function changepassword ($oldpassword, $newpassword)
{ {
throw new Exception (_("The password can't be change for SYMPA users"), throw new Exception (dgettext("domframework",
"The password can't be change for SYMPA users"),
405); 405);
} }
} }

View File

@@ -69,25 +69,30 @@ class cachefile
public function cachedir () public function cachedir ()
{ {
if (! isset ($this->directory) || $this->directory === "") if (! isset ($this->directory) || $this->directory === "")
throw new Exception (_("No cache directory defined"), 500); throw new Exception (dgettext("domframework",
"No cache directory defined"), 500);
if (! file_exists ($this->directory)) if (! file_exists ($this->directory))
{ {
// Need to create the cache dir // Need to create the cache dir
$parent = realpath (dirname ($this->directory)); $parent = realpath (dirname ($this->directory));
if (! is_writeable (dirname ($this->directory))) if (! is_writeable (dirname ($this->directory)))
throw new Exception (sprintf (_( throw new Exception (sprintf (dgettext("domframework",
"Directory %s is not writable : can not create cache directory"), "Directory %s is not writable : can not create cache directory"),
$parent), 500); $parent), 500);
if (!mkdir ($this->directory)) if (!mkdir ($this->directory))
throw new Exception (sprintf (_("Can not create cache directory %s"), throw new Exception (sprintf (dgettext("domframework",
"Can not create cache directory %s"),
$this->directory), 500); $this->directory), 500);
chmod ($this->directory, 0777); chmod ($this->directory, 0777);
} }
if (! is_writable ($this->directory)) if (! is_writable ($this->directory))
throw new Exception (sprintf (_("Cache directory %s is not writable"), throw new Exception (sprintf (dgettext("domframework",
"Cache directory %s is not writable"),
$this->directory), 500); $this->directory), 500);
if (! is_readable ($this->directory)) if (! is_readable ($this->directory))
throw new Exception (sprintf (_("Cache directory %s is not readable"), throw new Exception (sprintf (dgettext("domframework",
"Cache directory %s is not readable"),
$this->directory), 500); $this->directory), 500);
if (!file_exists ($this->directory."/.htaccess")) if (!file_exists ($this->directory."/.htaccess"))
file_put_contents ($this->directory."/.htaccess", "deny from all\n"); file_put_contents ($this->directory."/.htaccess", "deny from all\n");
@@ -105,7 +110,8 @@ class cachefile
if ($this->nocache !== false) if ($this->nocache !== false)
return false; return false;
if ($data === false) if ($data === false)
throw new Exception (_("Can not store FALSE in cache"), 500); throw new Exception (dgettext("domframework",
"Can not store FALSE in cache"), 500);
try try
{ {
$this->cachedir (); $this->cachedir ();
@@ -148,10 +154,12 @@ class cachefile
if (!file_exists ($fileCache)) if (!file_exists ($fileCache))
return false; return false;
if (!is_readable ($fileCache)) if (!is_readable ($fileCache))
throw new Exception (sprintf (_("File cache %s is not readable"), throw new Exception (sprintf (dgettext("domframework",
"File cache %s is not readable"),
$fileCache), 500); $fileCache), 500);
if (!is_writable ($fileCache)) if (!is_writable ($fileCache))
throw new Exception (sprintf (_("File cache %s is not writable"), throw new Exception (sprintf (dgettext("domframework",
"File cache %s is not writable"),
$fileCache), 500); $fileCache), 500);
// Lock : waiting the reconstruction of the cache by another process // Lock : waiting the reconstruction of the cache by another process
// Waiting 10s maximum to re-create the cache file // Waiting 10s maximum to re-create the cache file

View File

@@ -27,7 +27,8 @@ class cacheoutput
{ {
$res = @include ("domframework/cache$method.php"); $res = @include ("domframework/cache$method.php");
if ($res === false) if ($res === false)
throw new Exception (sprintf (_("Unkwnown cache method : "), $method), throw new Exception (sprintf (dgettext("domframework",
"Unkwnown cache method : "), $method),
500); 500);
$this->id = $id; $this->id = $id;
$this->ttl = $ttl; $this->ttl = $ttl;

View File

@@ -46,13 +46,13 @@ class config
if (@file_put_contents ($this->confFile, if (@file_put_contents ($this->confFile,
"<?php\r\n\$conf = array ();\r\n") "<?php\r\n\$conf = array ();\r\n")
=== FALSE) === FALSE)
throw new Exception (sprintf ( throw new Exception (sprintf (dgettext("domframework",
_("No configuration file '%s' available and it can't be created"), "No configuration file '%s' available and it can't be created"),
$this->confFile)); $this->confFile));
} }
elseif (! is_readable ($this->confFile)) elseif (! is_readable ($this->confFile))
throw new Exception (sprintf ( throw new Exception (sprintf ( dgettext("domframework",
_("The configuration file '%s' is not readable"), "The configuration file '%s' is not readable"),
$this->confFile)); $this->confFile));
$conf = array (); $conf = array ();
$rc = include ($this->confFile); $rc = include ($this->confFile);
@@ -83,16 +83,18 @@ class config
} }
elseif (! is_readable ($this->confFile)) elseif (! is_readable ($this->confFile))
throw new Exception (sprintf ( throw new Exception (sprintf (
_("The configuration file '%s' is not readable"), dgettext("domframework",
"The configuration file '%s' is not readable"),
$this->confFile)); $this->confFile));
if (!is_writeable ($this->confFile)) if (!is_writeable ($this->confFile))
throw new Exception (sprintf ( throw new Exception (sprintf (dgettext("domframework",
"Configuration file '%s' is write protected", "Configuration file '%s' is write protected"),
$this->confFile)); $this->confFile));
$conf = array (); $conf = array ();
$rc = include ($this->confFile); $rc = include ($this->confFile);
if ($rc !== 1) if ($rc !== 1)
throw new Exception ("Error in configuration file"); throw new Exception (dgettext("domframework",
"Error in configuration file"), 500);
$newconf = array_merge ($this->default, $conf, array ($param=>$value)); $newconf = array_merge ($this->default, $conf, array ($param=>$value));
$txt = "<?php\r\n"; $txt = "<?php\r\n";
$txt .= "\$conf = array(\r\n"; $txt .= "\$conf = array(\r\n";
@@ -100,7 +102,8 @@ class config
$txt .= ");\r\n"; $txt .= ");\r\n";
if (@file_put_contents ($this->confFile, $txt, LOCK_EX) === FALSE) if (@file_put_contents ($this->confFile, $txt, LOCK_EX) === FALSE)
throw new Exception (sprintf ("Can't save configuration file '%s'", throw new Exception (sprintf (dgettext("domframework",
"Can't save configuration file '%s'"),
$this->confFile)); $this->confFile));
return TRUE; return TRUE;
} }
@@ -135,7 +138,8 @@ class config
$phpcode .= "),\r\n"; $phpcode .= "),\r\n";
} }
else else
throw new Exception ("Config : missing type ".gettype ($val)); throw new Exception (dgettext("domframework",
"Config : missing type ").gettype ($val), 500);
} }
return $phpcode; return $phpcode;

View File

@@ -64,7 +64,7 @@ class dblayer extends PDO
public function databasename () public function databasename ()
{ {
if ($this->db === null) if ($this->db === null)
throw new Exception (_("Database not connected")); throw new Exception (dgettext("domframework", "Database not connected"));
$vals = explode (";", substr (strstr ($this->dsn, ":"), 1)); $vals = explode (";", substr (strstr ($this->dsn, ":"), 1));
$dsnExplode = array (); $dsnExplode = array ();
foreach ($vals as $val) foreach ($vals as $val)
@@ -81,7 +81,7 @@ class dblayer extends PDO
public function listTables () public function listTables ()
{ {
if ($this->db === null) if ($this->db === null)
throw new Exception (_("Database not connected")); throw new Exception (dgettext("domframework", "Database not connected"));
switch ($this->db->getAttribute(PDO::ATTR_DRIVER_NAME)) switch ($this->db->getAttribute(PDO::ATTR_DRIVER_NAME))
{ {
case "sqlite": case "sqlite":
@@ -113,7 +113,8 @@ class dblayer extends PDO
$res[] = $d["tablename"]; $res[] = $d["tablename"];
break; break;
default: default:
throw new Exception (_("Unknown database driver in listTables")); throw new Exception (dgettext("domframework",
"Unknown database driver in listTables"));
} }
return $res; return $res;
} }

View File

@@ -324,6 +324,19 @@ You can remove the objects with :
You can see if the user can access to the object with READ, WRITE, EXECUTE : You can see if the user can access to the object with READ, WRITE, EXECUTE :
$auth->validate ("/module/<object>") $auth->validate ("/module/<object>")
12. Internationalization
------------------------
The domframework can be use to internationalize your software. You can create a
structure like _locale/en_US.UTF8/LC_MESSAGES/{package}.mo_ and just call :
// Selection of the language
$language = new language ();
$language->activeLanguage ("package", "package-Langugage");
Change the name "package" by your soft name, and use the same name in the
_LC_MESSAGES_ directory.
The _LC_MESSAGES_ directory must be writeable : a cache of the .mo file is
created if it is possible to inform Apache of the evolutions of your software.
XX. CLI usage XX. CLI usage
------------- -------------
The DomFramework is designed to be used in console line too. The DomFramework is designed to be used in console line too.

View File

@@ -15,15 +15,19 @@ class model_file
{ {
$this->dataPath = realpath ($this->dataPath); $this->dataPath = realpath ($this->dataPath);
if ($this->dataPath === FALSE) if ($this->dataPath === FALSE)
throw new Exception (_("Folder data not available"), 500); throw new Exception (dgettext("domframework",
"Folder data not available"), 500);
$fileArticle = $this->dataPath."/".$articleid; $fileArticle = $this->dataPath."/".$articleid;
if (! file_exists ($fileArticle)) if (! file_exists ($fileArticle))
throw new Exception (_("Article not found"), 404); throw new Exception (dgettext("domframework",
"Article not found"), 404);
$fileArticle = realpath ($fileArticle); $fileArticle = realpath ($fileArticle);
if (substr ($fileArticle, 0, strlen ($this->dataPath)) !== $this->dataPath) if (substr ($fileArticle, 0, strlen ($this->dataPath)) !== $this->dataPath)
throw new Exception (_("Asked article not in data path"), 404); throw new Exception (dgettext("domframework",
"Asked article not in data path"), 404);
if ($fileArticle === FALSE) if ($fileArticle === FALSE)
throw new Exception (_("Article not found"), 404); throw new Exception (dgettext("domframework",
"Article not found"), 404);
return unserialize (file_get_contents ($fileArticle)); return unserialize (file_get_contents ($fileArticle));
} }
@@ -33,15 +37,19 @@ class model_file
{ {
$this->dataPath = realpath ($this->dataPath); $this->dataPath = realpath ($this->dataPath);
if ($this->dataPath === FALSE) if ($this->dataPath === FALSE)
throw new Exception (_("Folder data not available"), 500); throw new Exception (dgettext("domframework",
"Folder data not available"), 500);
$fileArticle = $this->dataPath."/".$articleid; $fileArticle = $this->dataPath."/".$articleid;
if (! file_exists ($fileArticle)) if (! file_exists ($fileArticle))
throw new Exception (_("Article not found"), 404); throw new Exception (dgettext("domframework",
"Article not found"), 404);
$fileArticle = realpath ($fileArticle); $fileArticle = realpath ($fileArticle);
if (substr ($fileArticle, 0, strlen ($this->dataPath)) !== $this->dataPath) if (substr ($fileArticle, 0, strlen ($this->dataPath)) !== $this->dataPath)
throw new Exception (_("Asked article not in data path"), 404); throw new Exception (dgettext("domframework",
"Asked article not in data path"), 404);
if ($fileArticle === FALSE) if ($fileArticle === FALSE)
throw new Exception (_("Article not found"), 404); throw new Exception (dgettext("domframework",
"Article not found"), 404);
return file_put_contents ($fileArticle, serialize ($data)); return file_put_contents ($fileArticle, serialize ($data));
} }
@@ -50,7 +58,8 @@ class model_file
{ {
$list = glob ($this->dataPath."/*"); $list = glob ($this->dataPath."/*");
if ($list === FALSE || empty ($list)) if ($list === FALSE || empty ($list))
throw new Exception (_("No article found"), 404); throw new Exception (dgettext("domframework",
"No article found"), 404);
foreach ($list as $key=>$val) foreach ($list as $key=>$val)
$list[$key] = basename ($val); $list[$key] = basename ($val);
return $list; return $list;

View File

@@ -83,7 +83,8 @@ class form
} }
else else
{ {
throw new Exception (_("Unknown FORM method (GET or POST allowed)")); throw new Exception (dgettext("domframework",
"Unknown FORM method (GET or POST allowed)"));
} }
if (count ($values) !== 0) if (count ($values) !== 0)
@@ -414,7 +415,7 @@ die ("FORM/VERIFY : UNUSED and dirty\n");
} }
else else
{ {
$res .= _("No value provided"); $res .= dgettext("domframework", "No value provided");
} }
$res .= " </div>\n"; // End controls $res .= " </div>\n"; // End controls
@@ -576,12 +577,15 @@ class csrf
if ($this->csrf === FALSE ) if ($this->csrf === FALSE )
return TRUE; return TRUE;
if (! isset ($_SESSION["domframework"]["form"]["csrf"])) if (! isset ($_SESSION["domframework"]["form"]["csrf"]))
throw new Exception (_("No previous CSRF token : abort")); throw new Exception (dgettext("domframework",
"No previous CSRF token : abort"));
if ($_SESSION["domframework"]["form"]["csrf"] !== $tokenFromUser) if ($_SESSION["domframework"]["form"]["csrf"] !== $tokenFromUser)
throw new Exception (_("Invalid CSRF token provided")); throw new Exception (dgettext("domframework",
"Invalid CSRF token provided"));
if (($_SESSION["domframework"]["form"]["csrfStart"] + $this->csrfTimeout) < if (($_SESSION["domframework"]["form"]["csrfStart"] + $this->csrfTimeout) <
microtime (TRUE)) microtime (TRUE))
throw new Exception (_("Obsolete CSRF token provided")); throw new Exception (dgettext("domframework",
"Obsolete CSRF token provided"));
return TRUE; return TRUE;
} }