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:
30
auth.php
30
auth.php
@@ -50,17 +50,22 @@ class auth
|
||||
$res .= "<div class='container'>\n";
|
||||
$res .= " <form class='form-signin' role='form' method='post' ";
|
||||
$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 .= " <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 .= "placeholder='"._("Password")."' required/>\n";
|
||||
$res .= "placeholder='".dgettext("domframework",
|
||||
"Password")."' required/>\n";
|
||||
$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 .= " <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 !== "")
|
||||
$res .= "<div class='alert alert-danger'>$message</div>";
|
||||
$res .= " </form>\n";
|
||||
@@ -73,7 +78,8 @@ class auth
|
||||
/** Establish the connection to authentication server */
|
||||
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
|
||||
@@ -83,13 +89,15 @@ class auth
|
||||
@param string $password Password to authenticate */
|
||||
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 */
|
||||
public function getdetails ()
|
||||
{
|
||||
throw new exception (_("No getdetails available"), 405);
|
||||
throw new exception (dgettext("domframework",
|
||||
"No getdetails available"), 405);
|
||||
}
|
||||
|
||||
/** Method to change the password
|
||||
@@ -98,13 +106,15 @@ class auth
|
||||
@param string $newpassword The new password to be recorded */
|
||||
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
|
||||
Return firstname, lastname, mail, with mail is an array */
|
||||
public function listusers ()
|
||||
{
|
||||
throw new exception (_("No List User available"), 405);
|
||||
throw new exception (dgettext("domframework",
|
||||
"No List User available"), 405);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +101,8 @@ class authldap extends auth
|
||||
@param string $newpassword The new password to be recorded */
|
||||
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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,8 @@ class authparams
|
||||
/** Get informations from a HTTP authentication */
|
||||
public function http()
|
||||
{
|
||||
$realm = _("Restricted access");
|
||||
$realm = dgettext("domframework",
|
||||
"Restricted access");
|
||||
if (!isset($_SERVER['PHP_AUTH_USER']))
|
||||
{
|
||||
header("WWW-Authenticate: Basic realm=\"$realm\"");
|
||||
|
||||
@@ -48,7 +48,8 @@ class authsession extends auth
|
||||
@param string $newpassword The new password to be recorded */
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,14 +41,16 @@ class authsympa extends auth
|
||||
public function __construct ()
|
||||
{
|
||||
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 */
|
||||
public function connect ()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -58,13 +60,15 @@ class authsympa extends auth
|
||||
public function authentication ($email, $password)
|
||||
{
|
||||
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)
|
||||
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);
|
||||
if ($this->authkey === null)
|
||||
throw new Exception (
|
||||
_("Can't connect with provided email/password to sympa"),
|
||||
throw new Exception (dgettext("domframework",
|
||||
"Can't connect with provided email/password to sympa"),
|
||||
401);
|
||||
$this->email = $email;
|
||||
$rc = $this->client->authenticateAndRun ($email, $this->authkey,
|
||||
@@ -77,7 +81,8 @@ class authsympa extends auth
|
||||
/** Return all the parameters recorded for the authenticate user */
|
||||
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
|
||||
@@ -86,7 +91,8 @@ class authsympa extends auth
|
||||
@param string $newpassword The new password to be recorded */
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,25 +69,30 @@ class cachefile
|
||||
public function cachedir ()
|
||||
{
|
||||
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))
|
||||
{
|
||||
// Need to create the cache dir
|
||||
$parent = realpath (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"),
|
||||
$parent), 500);
|
||||
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);
|
||||
chmod ($this->directory, 0777);
|
||||
}
|
||||
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);
|
||||
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);
|
||||
if (!file_exists ($this->directory."/.htaccess"))
|
||||
file_put_contents ($this->directory."/.htaccess", "deny from all\n");
|
||||
@@ -105,7 +110,8 @@ class cachefile
|
||||
if ($this->nocache !== false)
|
||||
return 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
|
||||
{
|
||||
$this->cachedir ();
|
||||
@@ -148,10 +154,12 @@ class cachefile
|
||||
if (!file_exists ($fileCache))
|
||||
return false;
|
||||
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);
|
||||
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);
|
||||
// Lock : waiting the reconstruction of the cache by another process
|
||||
// Waiting 10s maximum to re-create the cache file
|
||||
|
||||
@@ -27,7 +27,8 @@ class cacheoutput
|
||||
{
|
||||
$res = @include ("domframework/cache$method.php");
|
||||
if ($res === false)
|
||||
throw new Exception (sprintf (_("Unkwnown cache method : "), $method),
|
||||
throw new Exception (sprintf (dgettext("domframework",
|
||||
"Unkwnown cache method : "), $method),
|
||||
500);
|
||||
$this->id = $id;
|
||||
$this->ttl = $ttl;
|
||||
|
||||
24
config.php
24
config.php
@@ -46,13 +46,13 @@ class config
|
||||
if (@file_put_contents ($this->confFile,
|
||||
"<?php\r\n\$conf = array ();\r\n")
|
||||
=== FALSE)
|
||||
throw new Exception (sprintf (
|
||||
_("No configuration file '%s' available and it can't be created"),
|
||||
throw new Exception (sprintf (dgettext("domframework",
|
||||
"No configuration file '%s' available and it can't be created"),
|
||||
$this->confFile));
|
||||
}
|
||||
elseif (! is_readable ($this->confFile))
|
||||
throw new Exception (sprintf (
|
||||
_("The configuration file '%s' is not readable"),
|
||||
throw new Exception (sprintf ( dgettext("domframework",
|
||||
"The configuration file '%s' is not readable"),
|
||||
$this->confFile));
|
||||
$conf = array ();
|
||||
$rc = include ($this->confFile);
|
||||
@@ -83,16 +83,18 @@ class config
|
||||
}
|
||||
elseif (! is_readable ($this->confFile))
|
||||
throw new Exception (sprintf (
|
||||
_("The configuration file '%s' is not readable"),
|
||||
dgettext("domframework",
|
||||
"The configuration file '%s' is not readable"),
|
||||
$this->confFile));
|
||||
if (!is_writeable ($this->confFile))
|
||||
throw new Exception (sprintf (
|
||||
"Configuration file '%s' is write protected",
|
||||
throw new Exception (sprintf (dgettext("domframework",
|
||||
"Configuration file '%s' is write protected"),
|
||||
$this->confFile));
|
||||
$conf = array ();
|
||||
$rc = include ($this->confFile);
|
||||
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));
|
||||
$txt = "<?php\r\n";
|
||||
$txt .= "\$conf = array(\r\n";
|
||||
@@ -100,7 +102,8 @@ class config
|
||||
$txt .= ");\r\n";
|
||||
|
||||
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));
|
||||
return TRUE;
|
||||
}
|
||||
@@ -135,7 +138,8 @@ class config
|
||||
$phpcode .= "),\r\n";
|
||||
}
|
||||
else
|
||||
throw new Exception ("Config : missing type ".gettype ($val));
|
||||
throw new Exception (dgettext("domframework",
|
||||
"Config : missing type ").gettype ($val), 500);
|
||||
}
|
||||
|
||||
return $phpcode;
|
||||
|
||||
@@ -64,7 +64,7 @@ class dblayer extends PDO
|
||||
public function databasename ()
|
||||
{
|
||||
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));
|
||||
$dsnExplode = array ();
|
||||
foreach ($vals as $val)
|
||||
@@ -81,7 +81,7 @@ class dblayer extends PDO
|
||||
public function listTables ()
|
||||
{
|
||||
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))
|
||||
{
|
||||
case "sqlite":
|
||||
@@ -113,7 +113,8 @@ class dblayer extends PDO
|
||||
$res[] = $d["tablename"];
|
||||
break;
|
||||
default:
|
||||
throw new Exception (_("Unknown database driver in listTables"));
|
||||
throw new Exception (dgettext("domframework",
|
||||
"Unknown database driver in listTables"));
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
13
docs/USAGE
13
docs/USAGE
@@ -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 :
|
||||
$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
|
||||
-------------
|
||||
The DomFramework is designed to be used in console line too.
|
||||
|
||||
@@ -15,15 +15,19 @@ class model_file
|
||||
{
|
||||
$this->dataPath = realpath ($this->dataPath);
|
||||
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;
|
||||
if (! file_exists ($fileArticle))
|
||||
throw new Exception (_("Article not found"), 404);
|
||||
throw new Exception (dgettext("domframework",
|
||||
"Article not found"), 404);
|
||||
$fileArticle = realpath ($fileArticle);
|
||||
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)
|
||||
throw new Exception (_("Article not found"), 404);
|
||||
throw new Exception (dgettext("domframework",
|
||||
"Article not found"), 404);
|
||||
return unserialize (file_get_contents ($fileArticle));
|
||||
}
|
||||
|
||||
@@ -33,15 +37,19 @@ class model_file
|
||||
{
|
||||
$this->dataPath = realpath ($this->dataPath);
|
||||
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;
|
||||
if (! file_exists ($fileArticle))
|
||||
throw new Exception (_("Article not found"), 404);
|
||||
throw new Exception (dgettext("domframework",
|
||||
"Article not found"), 404);
|
||||
$fileArticle = realpath ($fileArticle);
|
||||
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)
|
||||
throw new Exception (_("Article not found"), 404);
|
||||
throw new Exception (dgettext("domframework",
|
||||
"Article not found"), 404);
|
||||
return file_put_contents ($fileArticle, serialize ($data));
|
||||
}
|
||||
|
||||
@@ -50,7 +58,8 @@ class model_file
|
||||
{
|
||||
$list = glob ($this->dataPath."/*");
|
||||
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)
|
||||
$list[$key] = basename ($val);
|
||||
return $list;
|
||||
|
||||
14
form.php
14
form.php
@@ -83,7 +83,8 @@ class form
|
||||
}
|
||||
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)
|
||||
@@ -414,7 +415,7 @@ die ("FORM/VERIFY : UNUSED and dirty\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
$res .= _("No value provided");
|
||||
$res .= dgettext("domframework", "No value provided");
|
||||
}
|
||||
|
||||
$res .= " </div>\n"; // End controls
|
||||
@@ -576,12 +577,15 @@ class csrf
|
||||
if ($this->csrf === FALSE )
|
||||
return TRUE;
|
||||
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)
|
||||
throw new Exception (_("Invalid CSRF token provided"));
|
||||
throw new Exception (dgettext("domframework",
|
||||
"Invalid CSRF token provided"));
|
||||
if (($_SESSION["domframework"]["form"]["csrfStart"] + $this->csrfTimeout) <
|
||||
microtime (TRUE))
|
||||
throw new Exception (_("Obsolete CSRF token provided"));
|
||||
throw new Exception (dgettext("domframework",
|
||||
"Obsolete CSRF token provided"));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user