X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Futil.php;h=99a0a1db30fee5c9fd73f38ced66699445e7e57b;hb=15a9c869794ea3948086afa5310696e1250d9a26;hp=81160d052c49ac431655557c2d3b34b064f03bb9;hpb=1f5f5474f175a8248b362f8be4ff23bb5e971305;p=quix0rs-gnu-social.git diff --git a/lib/util.php b/lib/util.php index 81160d052c..99a0a1db30 100644 --- a/lib/util.php +++ b/lib/util.php @@ -58,18 +58,17 @@ function common_init_language() // (say, ga_ES for Galego/Galician) it seems to take it. common_init_locale("en_US"); + // Note that this setlocale() call may "fail" but this is harmless; + // gettext will still select the right language. $language = common_language(); $locale_set = common_init_locale($language); + setlocale(LC_CTYPE, 'C'); // So we do not have to make people install the gettext locales $path = common_config('site','locale_path'); bindtextdomain("statusnet", $path); bind_textdomain_codeset("statusnet", "UTF-8"); textdomain("statusnet"); - - if(!$locale_set) { - common_log(LOG_INFO, 'Language requested:' . $language . ' - locale could not be set. Perhaps that system locale is not installed.', __FILE__); - } } function common_timezone() @@ -196,10 +195,15 @@ function common_set_user($user) } if ($user) { - common_ensure_session(); - $_SESSION['userid'] = $user->id; - $_cur = $user; - return $_cur; + if (Event::handle('StartSetUser', array(&$user))) { + if($user){ + common_ensure_session(); + $_SESSION['userid'] = $user->id; + $_cur = $user; + Event::handle('EndSetUser', array($user)); + return $_cur; + } + } } return false; } @@ -350,8 +354,11 @@ function common_current_user() common_ensure_session(); $id = isset($_SESSION['userid']) ? $_SESSION['userid'] : false; if ($id) { - $_cur = User::staticGet($id); - return $_cur; + $user = User::staticGet($id); + if ($user) { + $_cur = $user; + return $_cur; + } } } @@ -1043,8 +1050,27 @@ function common_log_line($priority, $msg) return date('Y-m-d H:i:s') . ' ' . $syslog_priorities[$priority] . ': ' . $msg . "\n"; } +function common_request_id() +{ + $pid = getmypid(); + if (php_sapi_name() == 'cli') { + return $pid; + } else { + static $req_id = null; + if (!isset($req_id)) { + $req_id = substr(md5(mt_rand()), 0, 8); + } + if (isset($_SERVER['REQUEST_URI'])) { + $url = $_SERVER['REQUEST_URI']; + } + $method = $_SERVER['REQUEST_METHOD']; + return "$pid.$req_id $method $url"; + } +} + function common_log($priority, $msg, $filename=null) { + $msg = '[' . common_request_id() . '] ' . $msg; $logfile = common_config('site', 'logfile'); if ($logfile) { $log = fopen($logfile, "a"); @@ -1420,25 +1446,18 @@ function common_shorten_url($long_url) if (empty($user)) { // common current user does not find a user when called from the XMPP daemon // therefore we'll set one here fix, so that XMPP given URLs may be shortened - $svc = 'ur1.ca'; + $shortenerName = 'ur1.ca'; } else { - $svc = $user->urlshorteningservice; - } - global $_shorteners; - if (!isset($_shorteners[$svc])) { - //the user selected service doesn't exist, so default to ur1.ca - $svc = 'ur1.ca'; + $shortenerName = $user->urlshorteningservice; } - if (!isset($_shorteners[$svc])) { - // no shortener plugins installed. - return $long_url; - } - - $reflectionObj = new ReflectionClass($_shorteners[$svc]['callInfo'][0]); - $short_url_service = $reflectionObj->newInstanceArgs($_shorteners[$svc]['callInfo'][1]); - $short_url = $short_url_service->shorten($long_url); - return $short_url; + if(Event::handle('StartShortenUrl', array($long_url,$shortenerName,&$shortenedUrl))){ + //URL wasn't shortened, so return the long url + return $long_url; + }else{ + //URL was shortened, so return the result + return $shortenedUrl; + } } function common_client_ip()