16 include_once (
"Lib.Prefix.php");
22 if (!function_exists(
'pgettext')) {
23 function pgettext($context, $msgid)
25 $contextString =
"{$context}\004{$msgid}";
26 $translation = _($contextString);
27 if ($translation === $contextString)
return $msgid;
28 else return $translation;
31 function npgettext($context, $msgid, $msgid_plural, $num)
33 $contextString =
"{$context}\004{$msgid}";
34 $contextStringp =
"{$context}\004{$msgid_plural}";
35 $translation = ngettext($contextString, $contextStringp, $num);
36 if ($translation === $contextString) {
38 }
else if ($translation === $contextStringp) {
58 return npgettext($context,
$message, $message_plural, abs($num));
60 return ngettext(
$message, $message_plural, abs($num));
80 if (isset($action->parent)) $action->parent->AddLogMsg($msg, $cut);
89 if (isset($action->parent)) $action->parent->log->deprecated(
"Deprecated : " . $msg);
98 if (isset($action->parent)) $action->parent->addWarningMsg($msg);
108 $s = mb_strtoupper(mb_substr(
$s, 0, 1,
'UTF-8') ,
'UTF-8') . mb_substr(
$s, 1, mb_strlen(
$s) ,
'UTF-8');
115 return preg_replace(
"/(^\s+)|(\s+$)/us",
"", $string);
123 $im = intval(ini_get(
"max_execution_time"));
124 if ($im > 0 && $im < $limit && $limit >= 0) ini_set(
"max_execution_time", $limit);
125 if ($limit <= 0) ini_set(
"max_execution_time", 0);
137 if (!
$user->isAffected()) {
140 $mailAddr =
$user->getMail();
141 if (
$full && $mailAddr !==
'') {
143 $pren =
'"' . trim(str_replace(
'"',
'-', ucwords(strtolower(
$user->getDisplayName(
$user->id))))) .
'" <';
145 return $pren . $mailAddr . $postn;
153 if (isset($tmp) && !empty($tmp)) {
156 $tmp =
getParam(
'CORE_TMPDIR', $def);
165 if (substr($tmp, 0, 1) !=
'/') {
173 $tmp = $tmp .
'/dcp';
196 if ($action)
return $action->getParam($name, $def);
211 require_once (
'WHAT/Class.ApplicationParameterManager.php');
213 static $params = null;
218 if (empty($params)) {
221 $err =
simpleQuery(
"",
"select name, val from paramv where (type = 'G') or (type='A' and appid = (select id from application where name ='CORE'));", $tparams,
false,
false,
false);
223 foreach ($tparams as $p) {
224 $params[$p[
'name']] = $p[
'val'];
228 if (array_key_exists($name, $params) ==
false) {
229 error_log(sprintf(
"parameter %s not found use %s instead", $name, $def));
232 return ($params[$name] === null) ? $def : $params[$name];
243 if ($action)
return $action->read($name, $def);
254 return $action->user;
260 if (strstr($layfile,
'..')) {
263 if (!strstr($layfile,
'.')) $layfile.=
".xml";
264 $socStyle = Getparam(
"CORE_SOCSTYLE");
265 $style = Getparam(
"STYLE");
267 if ($socStyle !=
"") {
268 $file = $root .
"/STYLE/$socStyle/Layout/$layfile";
269 if (file_exists(
$file)) {
273 $file = $root .
"/STYLE/$socStyle/Layout/" . strtolower($layfile);
274 if (file_exists(
$file)) {
277 } elseif ($style !=
"") {
278 $file = $root .
"/STYLE/$style/Layout/$layfile";
279 if (file_exists(
$file)) {
283 $file = $root .
"/STYLE/$style/Layout/" . strtolower($layfile);
284 if (file_exists(
$file)) {
289 $file = $root .
"/$app/Layout/$layfile";
290 if (file_exists(
$file)) {
294 $file = $root .
"/$app/Layout/" . strtolower($layfile);
295 if (file_exists(
$file)) {
304 list($a_micro, $a_int) = explode(
' ',
$a);
305 list($b_micro, $b_int) = explode(
' ', $b);
306 if ($a_int > $b_int) {
307 return ($a_int - $b_int) + ($a_micro - $b_micro);
308 } elseif ($a_int == $b_int) {
309 if ($a_micro > $b_micro) {
310 return ($a_int - $b_int) + ($a_micro - $b_micro);
311 } elseif ($a_micro < $b_micro) {
312 return ($b_int - $a_int) + ($b_micro - $a_micro);
317 return ($b_int - $a_int) + ($b_micro - $a_micro);
327 $td = @debug_backtrace(
false);
328 if (!is_array($td))
return array();
329 $t = array_slice($td,
$slice);
330 foreach ($t as $k =>
$s) {
331 unset($t[$k][
"args"]);
347 foreach ($st as $k => $t) {
348 $errors[] = sprintf(
'%d) %s:%s %s::%s()', $k, isset($t[
"file"]) ? $t[
"file"] :
'closure', isset($t[
"line"]) ? $t[
"line"] : 0, isset($t[
"class"]) ? $t[
"class"] :
'', $t[
"function"]);
351 error_log(implode(
"\n", $errors));
357 if (!isset($CORE_DBID) || !($CORE_DBID[
$dbaccess])) {
358 $CORE_DBID[
$dbaccess] = pg_connect($dbaccess);
359 if (!$CORE_DBID[$dbaccess]) {
361 header(
'HTTP/1.0 503 DB connection unavalaible');
362 throw new \Dcp\Db\Exception(
'DB0101', $dbaccess);
388 error_log(
"Deprecated call to getDbEnv() : not necessary");
398 $freedomctx = getenv(
"freedom_context");
399 if ($freedomctx ==
false || $freedomctx ==
"") {
407 static $pg_service = null;
409 if ($pg_service)
return $pg_service;
413 error_log(
"Undefined pgservice_core in dbaccess.php");
443 if (!isset($$varName))
return null;
448 static $pg_service = null;
450 if ($pg_service)
return $pg_service;
452 if ($pgservice_freedom ==
"") {
453 error_log(
"Undefined pgservice_freedom in dbaccess.php");
456 $pg_service = $pgservice_freedom;
462 error_log(
"Deprecated call to getDbName(dbaccess) : use getServiceName(dbaccess)");
468 if (preg_match(
"/service='?([a-zA-Z0-9_.-]+)/",
$dbaccess, $reg)) {
487 static $sqlStrict = null;
494 if ($SQLDEBUG) $sqlt1 = microtime();
497 if (pg_numrows(
$r) > 0) {
498 if ($singlecolumn) $result = pg_fetch_all_columns(
$r, 0);
499 else $result = pg_fetch_all(
$r);
500 if ($singleresult) $result = $result[0];
502 if ($singleresult && $singlecolumn) {
509 $TSQLDELAY[] = array(
511 "s" => str_replace(array(
529 if ($useStrict !==
false) {
530 if ($sqlStrict === null) $sqlStrict = (
getParam(
"CORE_SQLSTRICT") !=
"no");
531 if ($useStrict ===
true || $sqlStrict) {
532 throw new \Dcp\Db\Exception(
$err);
594 function getWshCmd($nice =
false, $userid = 0, $sudo =
false)
597 if ($nice)
$wsh.=
"nice -n +10 ";
598 if ($sudo)
$wsh.=
"sudo ";
600 $userid = intval($userid);
601 if ($userid > 0)
$wsh.=
"--userid=$userid ";
611 if ($action)
return $action->user->id;
623 $foutname = uniqid(
getTmpDir() .
"/bgexec");
624 $fout = fopen($foutname,
"w+");
625 fwrite($fout,
"#!/bin/bash\n");
626 foreach ($tcmd as $v) {
627 fwrite($fout,
"$v\n");
630 chmod($foutname, 0700);
632 exec(
"exec nohup $foutname > /dev/null 2>&1 &", $result,
$err);
639 wbar(
'-',
'-', $text);
642 function wbar($reste, $total, $text =
"",
$fbar =
false)
644 static $preste, $ptotal;
647 if ($reste ===
'-') $reste = $preste;
648 else $preste = $reste;
649 if ($total ===
'-') $total = $ptotal;
650 else $ptotal = $total;
651 if (file_exists(
"$fbar.lck")) {
657 $ffbar = fopen(
$fbar, $wmode);
658 fputs($ffbar,
"$reste/$total/$text\n");
665 include_once (
"Class.QueryDb.php");
667 $q->AddQuery(
"name='WVERSION'");
668 $l =
$q->Query(0, 0,
"TABLE");
670 foreach ($l as $k => $v) {
671 $nv+= intval(str_replace(
'.',
'', $v[
"val"]));
696 if (
$to ==
"")
return '';
698 if ($forcelink ==
"mailto") {
699 $target = $forcelink;
701 $target = strtolower(GetParam(
"CORE_MAIL_LINK",
"optimal"));
702 if ($target ==
"optimal") {
706 $prot = (
$_SERVER[
"HTTPS"] ==
"on" ?
"https" :
"http");
711 if (is_array($anchorattr)) {
712 foreach ($anchorattr as $k => $v) $attrcode.=
' ' . $k .
'="' . $v .
'"';
720 $link.=
'href="mailto:' .
$to .
'"';
722 $link.= (
$cc !=
"" ?
'&cc=' .
$cc :
'');
723 $link.= (
$bcc !=
"" ?
'&bcc=' .
$bcc :
'');
732 $link =
'<span ' . $classcode .
'>' . $acontent .
'</span>';
750 if (is_array($string))
return seems_utf8(implode(
'', $string));
761 return preg_match(
'!!u', $Str);
770 include_once (
'Class.User.php');
771 include_once (
'Class.Session.php');
780 $action->Set(
"",
$core);
782 $lang = $action->Getparam(
"CORE_LANG");
789 include_once (
'Class.User.php');
790 include_once (
'Class.Session.php');
794 $action->user->setLoginName(
$login);
804 if ($charspace ==
"") {
805 $charspace =
"[:alnum:]";
808 $charspace = preg_replace_callback(
'/(\[:[a-z]+:)(\d+)(\])/',
function ($matches)
810 return str_repeat($matches[1] . $matches[3], $matches[2]);
814 $charspace = preg_replace(array(
816 "/\[:extrastrong:\]/",
823 "[:lower:][:upper:][:digit:]",
824 "[:extra:],;:=+*/(){}[]&@#!?\"'<>",
826 "abcdefghijklmnopqrstuvwxyz",
827 "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
833 for ($i = 0; $i < $length; $i++) {
834 $passwd.= substr($charspace, rand(0, strlen($charspace) - 1) , 1);
855 if (empty($core_lang)) {
856 $core_lang =
getParam(
"CORE_LANG",
"fr_FR");
858 $lng = substr($core_lang, 0, 2);
859 if (preg_match(
'#^[a-z0-9_\.-]+$#i', $core_lang) && file_exists(
"locale/" . $lng .
"/lang.php")) {
860 include (
"locale/" . $lng .
"/lang.php");
862 include (
"locale/fr/lang.php");
864 if (!isset(
$lang) || !isset(
$lang[$core_lang]) || !is_array(
$lang[$core_lang])) {
867 return $lang[$core_lang];
872 static $locales = null;
874 if ($locales === null) {
876 include (
'CORE/lang.php');
894 $action->parent->param->SetVolatile(
"CORE_LANG",
$lang);
895 $action->parent->setVolatileParam(
"CORE_LANG",
$lang);
898 if (setlocale(LC_MESSAGES,
$lang) ===
false) {
901 setlocale(LC_CTYPE,
$lang);
902 setlocale(LC_MONETARY,
$lang);
903 setlocale(LC_TIME,
$lang);
906 $numberFile = sprintf(
"%s/locale/.gettextnumber",
DEFAULT_PUBDIR);
908 if (is_file($numberFile)) {
909 $number = trim(@file_get_contents($numberFile));
916 $enumAttr = new \NormalAttribute(
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
$a,
"",
"",
"");
917 $enumAttr->resetEnum();
919 $td =
"main-catalog$number";
921 putenv(
"LANG=" .
$lang);
924 bind_textdomain_codeset($td,
'utf-8');
926 mb_internal_encoding(
'UTF-8');
929 mb_internal_encoding(
'UTF-8');
logDebugStack($slice=1, $msg="")
getDbAccessValue($varName)
getMailAddr($userid, $full=false)
print< H1 > Check Database< i > $dbaccess</i ></H1 > $a
static _catchDeprecatedGlobalParameter($parameterName)
Exception class use exceptionCode to identifiy correctly exception.
static getAuthParam($provider="")
if(!function_exists('pgettext')) ___($message, $context="")
getAuthParam($freedomctx="", $provider="")
static getError($code, $args=null)
getLocaleConfig($core_lang= '')
n___($message, $message_plural, $num, $context="")
getAuthProvider($freedomctx="")
static getAuthProviderList()
wbar($reste, $total, $text="", $fbar=false)
getLayoutFile($app, $layfile)
getAuthTypeParams($freedomctx="")
getWshCmd($nice=false, $userid=0, $sudo=false)
getParam($name, $def="")
must be in core or global type
getAuthType($freedomctx="")
mkpasswd($length=8, $charspace="")
WhatInitialisation($session=null)
static getAuthTypeParams()
deprecatedFunction($msg= '')
getSessionValue($name, $def="")
getServiceName($dbaccess)
setMaxExecutionTimeTo($limit)
setMailtoAnchor($to, $acontent="", $subject="", $cc="", $bcc="", $from="", $anchorattr=array(), $forcelink="")
if(($docid!==0)&&(!is_numeric($docid))) $query
simpleQuery($dbaccess, $query, &$result=array(), $singlecolumn=false, $singleresult=false, $useStrict=null)
bgexec($tcmd, &$result, &$err)
if($file) if($subject==""&&$file) if($subject=="") $err
getAuthProviderList($freedomctx="")
getCoreParam($name, $def="")
must be in core or global type