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

@@ -44,7 +44,8 @@ class authorizationdb extends authorization
public function initialize ()
{
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 ();
if (!in_array ($this->db->tableprefix.$this->db->table, $tables))
{
@@ -62,14 +63,17 @@ class authorizationdb extends authorization
public function validate ($object)
{
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) === "/")
$object = 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);
if ($this->authiduser === "")
throw new Exception (_("Not authenticated"), 401);
throw new Exception (dgettext("domframework",
"Not authenticated"), 401);
try
{
$this->treecheckExecute ($object);
@@ -83,7 +87,9 @@ class authorizationdb extends authorization
// exists
$search = $this->db->read (array (array ("object", $object)));
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);
$search = reset ($search);
$ownerid = intval ($search["ownerid"]);
@@ -134,20 +140,25 @@ class authorizationdb extends authorization
public function add ($object, $ownerid, $groupid, $modbits)
{
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
$modbits = decoct ($modbits);
if (substr ($object, -1) === "/")
$object = 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);
if ($this->authiduser === "")
throw new Exception (_("Not authenticated"), 401);
throw new Exception (dgettext("domframework",
"Not authenticated"), 401);
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))
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
{
$this->treecheckExecute ($object);
@@ -161,7 +172,8 @@ class authorizationdb extends authorization
// exists
$search = $this->db->read (array (array ("object", $object)));
if (count ($search))
throw new Exception (sprintf (_("Object %s already defined"), $object),
throw new Exception (sprintf (dgettext("domframework",
"Object %s already defined"), $object),
400);
// 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)
{
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) === "/")
$object = 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);
if ($this->authiduser === "")
throw new Exception (_("Not authenticated"), 401);
throw new Exception (dgettext("domframework",
"Not authenticated"), 401);
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
{
$this->treecheckExecute ($object);
@@ -220,8 +236,9 @@ class authorizationdb extends authorization
// exists
$search = $this->db->read (array (array ("object", $object)));
if (count ($search) === 0)
throw new Exception (sprintf (_("Object %s doesn't exists"), $object),
400);
throw new Exception (sprintf (dgettext("domframework",
"Object %s doesn't exists"),
$object), 400);
// All the folder structure is accessible. Check if we can remove the file
// in the last folder (Write modbit). Root can always write.
@@ -229,9 +246,11 @@ class authorizationdb extends authorization
{
$rc = $this->db->delete ($object);
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)
throw new Exception (_("No object removed"), 406);
throw new Exception (dgettext("domframework",
"No object removed"), 406);
$rc = $this->db->delete ("$object$this->separator%");
return TRUE;
}
@@ -247,9 +266,11 @@ class authorizationdb extends authorization
$rc = $this->db->delete ($object);
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)
throw new Exception (_("No object removed"), 406);
throw new Exception (dgettext("domframework",
"No object removed"), 406);
$rc = $this->db->delete ("$object$this->separator%");
return TRUE;
}
@@ -262,16 +283,20 @@ class authorizationdb extends authorization
public function chown ($object, $ownerid)
{
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) === "/")
$object = 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);
if ($this->authiduser === "")
throw new Exception (_("Not authenticated"), 401);
throw new Exception (dgettext("domframework",
"Not authenticated"), 401);
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
{
$this->treecheckExecute ($object);
@@ -285,7 +310,8 @@ class authorizationdb extends authorization
// exists
$search = $this->db->read (array (array ("object", $object)));
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);
$search = reset ($search);
$this->db->update ($object, array ("ownerid"=>$ownerid));
@@ -300,18 +326,23 @@ class authorizationdb extends authorization
public function chgrp ($object, $groupid)
{
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) === "/")
$object = 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);
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))
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)))
throw new Exception (sprintf (_("%s is write protected"), $object), 405);
throw new Exception (sprintf (dgettext("domframework",
"%s is write protected"), $object), 405);
try
{
$this->treecheckExecute ($object);
@@ -325,7 +356,8 @@ class authorizationdb extends authorization
// exists
$search = $this->db->read (array (array ("object", $object)));
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);
$search = reset ($search);
$this->db->update ($object, array ("groupid"=>$groupid));
@@ -340,16 +372,20 @@ class authorizationdb extends authorization
public function chmod ($object, $mod)
{
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) === "/")
$object = 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);
if ($this->authiduser === "")
throw new Exception (_("Not authenticated"), 401);
throw new Exception (dgettext("domframework",
"Not authenticated"), 401);
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
{
$this->treecheckExecute ($object);
@@ -363,7 +399,8 @@ class authorizationdb extends authorization
// exists
$search = $this->db->read (array (array ("object", $object)));
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);
$search = reset ($search);
// 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)
{
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) === "/")
$object = 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);
if ($this->authiduser === "")
throw new Exception (_("Not authenticated"), 401);
throw new Exception (dgettext("domframework",
"Not authenticated"), 401);
try
{
$this->treecheckExecute ($object);
@@ -399,7 +439,8 @@ class authorizationdb extends authorization
// exists
$search = $this->db->read (array (array ("object", $object)));
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);
$search = reset ($search);
return octdec ($search["modbits"]);
@@ -412,14 +453,17 @@ class authorizationdb extends authorization
public function lsown ($object)
{
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) === "/")
$object = 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);
if ($this->authiduser === "")
throw new Exception (_("Not authenticated"), 401);
throw new Exception (dgettext("domframework",
"Not authenticated"), 401);
try
{
$this->treecheckExecute ($object);
@@ -433,7 +477,8 @@ class authorizationdb extends authorization
// exists
$search = $this->db->read (array (array ("object", $object)));
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);
$search = reset ($search);
return intval ($search["ownerid"]);
@@ -446,14 +491,17 @@ class authorizationdb extends authorization
public function lsgrp ($object)
{
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) === "/")
$object = 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);
if ($this->authiduser === "")
throw new Exception (_("Not authenticated"), 401);
throw new Exception (dgettext("domframework",
"Not authenticated"), 401);
try
{
$this->treecheckExecute ($object);
@@ -467,7 +515,8 @@ class authorizationdb extends authorization
// exists
$search = $this->db->read (array (array ("object", $object)));
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);
$search = reset ($search);
return intval ($search["groupid"]);
@@ -482,7 +531,8 @@ class authorizationdb extends authorization
private function treecheckExecute ($object)
{
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
$parents = array ();
$par = $object;
@@ -518,7 +568,8 @@ class authorizationdb extends authorization
}
}
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);
else
{
@@ -542,7 +593,8 @@ class authorizationdb extends authorization
if (($parentModbits & 0001) === 1)
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;
@@ -572,6 +624,7 @@ class authorizationdb extends authorization
if (($parentModbits & 0002) === 2)
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);
}
}