mirror of
https://github.com/Mibew/design.git
synced 2025-01-23 02:20:34 +03:00
Split libs/common.php into separate files
This commit is contained in:
parent
17b4327dfb
commit
29d7f891da
@ -17,14 +17,23 @@
|
||||
|
||||
session_start();
|
||||
|
||||
require_once(dirname(__FILE__) . '/converter.php');
|
||||
require_once(dirname(__FILE__) . '/config.php');
|
||||
require_once(dirname(__FILE__) . '/plugins.php');
|
||||
require_once(dirname(__FILE__) . '/classes/database.php');
|
||||
require_once(dirname(__FILE__) . '/classes/settings.php');
|
||||
|
||||
$version = '1.6.5';
|
||||
$jsver = "165";
|
||||
// Include common libs
|
||||
require_once(dirname(__FILE__) . '/common/constants.php');
|
||||
require_once(dirname(__FILE__) . '/common/csrf.php');
|
||||
require_once(dirname(__FILE__) . '/common/datetime.php');
|
||||
require_once(dirname(__FILE__) . '/common/forms.php');
|
||||
require_once(dirname(__FILE__) . '/common/verification.php');
|
||||
require_once(dirname(__FILE__) . '/common/locale.php');
|
||||
require_once(dirname(__FILE__) . '/common/misc.php');
|
||||
require_once(dirname(__FILE__) . '/common/request.php');
|
||||
require_once(dirname(__FILE__) . '/common/response.php');
|
||||
require_once(dirname(__FILE__) . '/common/string.php');
|
||||
|
||||
|
||||
// Initialize the database
|
||||
Database::initialize(
|
||||
@ -38,602 +47,10 @@ Database::initialize(
|
||||
$dbencoding
|
||||
);
|
||||
|
||||
function myiconv($in_enc, $out_enc, $string)
|
||||
{
|
||||
global $_utf8win1251, $_win1251utf8;
|
||||
if ($in_enc == $out_enc) {
|
||||
return $string;
|
||||
}
|
||||
if (function_exists('iconv')) {
|
||||
$converted = @iconv($in_enc, $out_enc, $string);
|
||||
if ($converted !== FALSE) {
|
||||
return $converted;
|
||||
}
|
||||
}
|
||||
if ($in_enc == "cp1251" && $out_enc == "utf-8")
|
||||
return strtr($string, $_win1251utf8);
|
||||
if ($in_enc == "utf-8" && $out_enc == "cp1251")
|
||||
return strtr($string, $_utf8win1251);
|
||||
|
||||
return $string; // do not know how to convert
|
||||
}
|
||||
|
||||
function verifyparam($name, $regexp, $default = null)
|
||||
{
|
||||
if (isset($_GET[$name])) {
|
||||
$val = $_GET[$name];
|
||||
if (preg_match($regexp, $val))
|
||||
return $val;
|
||||
|
||||
} else if (isset($_POST[$name])) {
|
||||
$val = $_POST[$name];
|
||||
if (preg_match($regexp, $val))
|
||||
return $val;
|
||||
|
||||
} else {
|
||||
if (isset($default))
|
||||
return $default;
|
||||
}
|
||||
echo "<html><head></head><body>Wrong parameter used or absent: " . $name . "</body></html>";
|
||||
exit;
|
||||
}
|
||||
|
||||
function debugexit_print($var)
|
||||
{
|
||||
echo "<html><body><pre>";
|
||||
print_r($var);
|
||||
echo "</pre></body></html>";
|
||||
exit;
|
||||
}
|
||||
|
||||
$locale_pattern = "/^[\w-]{2,5}$/";
|
||||
|
||||
function locale_exists($locale)
|
||||
{
|
||||
return file_exists(dirname(__FILE__) . "/../locales/$locale/properties");
|
||||
}
|
||||
|
||||
function get_available_locales()
|
||||
{
|
||||
global $locale_pattern;
|
||||
$list = array();
|
||||
$folder = dirname(__FILE__) . "/../locales";
|
||||
if ($handle = opendir($folder)) {
|
||||
while (false !== ($file = readdir($handle))) {
|
||||
if (preg_match($locale_pattern, $file) && $file != 'names' && is_dir("$folder/$file")) {
|
||||
$list[] = $file;
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
sort($list);
|
||||
return $list;
|
||||
}
|
||||
|
||||
function get_user_locale()
|
||||
{
|
||||
global $default_locale;
|
||||
|
||||
if (isset($_COOKIE['webim_locale'])) {
|
||||
$requested_lang = $_COOKIE['webim_locale'];
|
||||
if (locale_exists($requested_lang))
|
||||
return $requested_lang;
|
||||
}
|
||||
|
||||
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
|
||||
$requested_langs = explode(",", $_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
||||
foreach ($requested_langs as $requested_lang) {
|
||||
if (strlen($requested_lang) > 2)
|
||||
$requested_lang = substr($requested_lang, 0, 2);
|
||||
|
||||
if (locale_exists($requested_lang))
|
||||
return $requested_lang;
|
||||
}
|
||||
}
|
||||
|
||||
if (locale_exists($default_locale))
|
||||
return $default_locale;
|
||||
|
||||
return 'en';
|
||||
}
|
||||
|
||||
function get_locale()
|
||||
{
|
||||
global $webimroot, $locale_pattern;
|
||||
|
||||
$locale = verifyparam("locale", $locale_pattern, "");
|
||||
|
||||
if ($locale && locale_exists($locale)) {
|
||||
$_SESSION['locale'] = $locale;
|
||||
setcookie('webim_locale', $locale, time() + 60 * 60 * 24 * 1000, "$webimroot/");
|
||||
} else if (isset($_SESSION['locale'])) {
|
||||
$locale = $_SESSION['locale'];
|
||||
}
|
||||
|
||||
if (!$locale || !locale_exists($locale))
|
||||
$locale = get_user_locale();
|
||||
return $locale;
|
||||
}
|
||||
|
||||
$current_locale = get_locale();
|
||||
$messages = array();
|
||||
$output_encoding = array();
|
||||
|
||||
if (function_exists("date_default_timezone_set")) {
|
||||
// TODO try to get timezone from config.php/session etc.
|
||||
// autodetect timezone
|
||||
@date_default_timezone_set(function_exists("date_default_timezone_get") ? @date_default_timezone_get() : "GMT");
|
||||
}
|
||||
|
||||
function get_locale_links($href)
|
||||
{
|
||||
global $current_locale;
|
||||
$localeLinks = array();
|
||||
$allLocales = get_available_locales();
|
||||
if (count($allLocales) < 2) {
|
||||
return null;
|
||||
}
|
||||
foreach ($allLocales as $k) {
|
||||
$localeLinks[$k] = getlocal_($k, "names");
|
||||
}
|
||||
return $localeLinks;
|
||||
}
|
||||
|
||||
function load_messages($locale)
|
||||
{
|
||||
global $messages, $webim_encoding, $output_encoding;
|
||||
$hash = array();
|
||||
$current_encoding = $webim_encoding;
|
||||
$fp = fopen(dirname(__FILE__) . "/../locales/$locale/properties", "r");
|
||||
while (!feof($fp)) {
|
||||
$line = fgets($fp, 4096);
|
||||
$keyval = preg_split("/=/", $line, 2);
|
||||
if (isset($keyval[1])) {
|
||||
if ($keyval[0] == 'encoding') {
|
||||
$current_encoding = trim($keyval[1]);
|
||||
} else if ($keyval[0] == 'output_encoding') {
|
||||
$output_encoding[$locale] = trim($keyval[1]);
|
||||
} else if ($current_encoding == $webim_encoding) {
|
||||
$hash[$keyval[0]] = str_replace("\\n", "\n", trim($keyval[1]));
|
||||
} else {
|
||||
$hash[$keyval[0]] = myiconv($current_encoding, $webim_encoding, str_replace("\\n", "\n", trim($keyval[1])));
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose($fp);
|
||||
$messages[$locale] = $hash;
|
||||
}
|
||||
|
||||
function getoutputenc()
|
||||
{
|
||||
global $current_locale, $output_encoding, $webim_encoding, $messages;
|
||||
if (!isset($messages[$current_locale]))
|
||||
load_messages($current_locale);
|
||||
return isset($output_encoding[$current_locale]) ? $output_encoding[$current_locale] : $webim_encoding;
|
||||
}
|
||||
|
||||
function getstring_($text, $locale)
|
||||
{
|
||||
global $messages;
|
||||
if (!isset($messages[$locale]))
|
||||
load_messages($locale);
|
||||
|
||||
$localized = $messages[$locale];
|
||||
if (isset($localized[$text]))
|
||||
return $localized[$text];
|
||||
if ($locale != 'en') {
|
||||
return getstring_($text, 'en');
|
||||
}
|
||||
|
||||
return "!" . $text;
|
||||
}
|
||||
|
||||
function getstring($text)
|
||||
{
|
||||
global $current_locale;
|
||||
return getstring_($text, $current_locale);
|
||||
}
|
||||
|
||||
function getlocal($text)
|
||||
{
|
||||
global $current_locale, $webim_encoding;
|
||||
return myiconv($webim_encoding, getoutputenc(), getstring_($text, $current_locale));
|
||||
}
|
||||
|
||||
function getlocal_($text, $locale)
|
||||
{
|
||||
global $webim_encoding;
|
||||
return myiconv($webim_encoding, getoutputenc(), getstring_($text, $locale));
|
||||
}
|
||||
|
||||
function topage($text)
|
||||
{
|
||||
global $webim_encoding;
|
||||
return myiconv($webim_encoding, getoutputenc(), $text);
|
||||
}
|
||||
|
||||
function getstring2_($text, $params, $locale)
|
||||
{
|
||||
$string = getstring_($text, $locale);
|
||||
for ($i = 0; $i < count($params); $i++) {
|
||||
$string = str_replace("{" . $i . "}", $params[$i], $string);
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
function getstring2($text, $params)
|
||||
{
|
||||
global $current_locale;
|
||||
return getstring2_($text, $params, $current_locale);
|
||||
}
|
||||
|
||||
function getlocal2($text, $params)
|
||||
{
|
||||
global $current_locale, $webim_encoding;
|
||||
$string = myiconv($webim_encoding, getoutputenc(), getstring_($text, $current_locale));
|
||||
for ($i = 0; $i < count($params); $i++) {
|
||||
$string = str_replace("{" . $i . "}", $params[$i], $string);
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
/* prepares for Javascript string */
|
||||
function getlocalforJS($text, $params)
|
||||
{
|
||||
global $current_locale, $webim_encoding;
|
||||
$string = myiconv($webim_encoding, getoutputenc(), getstring_($text, $current_locale));
|
||||
$string = str_replace("\"", "\\\"", str_replace("\n", "\\n", $string));
|
||||
for ($i = 0; $i < count($params); $i++) {
|
||||
$string = str_replace("{" . $i . "}", $params[$i], $string);
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
/* ajax server actions use utf-8 */
|
||||
function getrawparam($name)
|
||||
{
|
||||
global $webim_encoding;
|
||||
if (isset($_POST[$name])) {
|
||||
$value = myiconv("utf-8", $webim_encoding, $_POST[$name]);
|
||||
if (get_magic_quotes_gpc()) {
|
||||
$value = stripslashes($value);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
die("no " . $name . " parameter");
|
||||
}
|
||||
|
||||
/* form processors use current Output encoding */
|
||||
function getparam($name)
|
||||
{
|
||||
global $webim_encoding;
|
||||
if (isset($_POST[$name])) {
|
||||
$value = myiconv(getoutputenc(), $webim_encoding, $_POST[$name]);
|
||||
if (get_magic_quotes_gpc()) {
|
||||
$value = stripslashes($value);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
die("no " . $name . " parameter");
|
||||
}
|
||||
|
||||
function unicode_urldecode($url)
|
||||
{
|
||||
preg_match_all('/%u([[:alnum:]]{4})/', $url, $a);
|
||||
|
||||
foreach ($a[1] as $uniord) {
|
||||
$dec = hexdec($uniord);
|
||||
$utf = '';
|
||||
|
||||
if ($dec < 128) {
|
||||
$utf = chr($dec);
|
||||
} else if ($dec < 2048) {
|
||||
$utf = chr(192 + (($dec - ($dec % 64)) / 64));
|
||||
$utf .= chr(128 + ($dec % 64));
|
||||
} else {
|
||||
$utf = chr(224 + (($dec - ($dec % 4096)) / 4096));
|
||||
$utf .= chr(128 + ((($dec % 4096) - ($dec % 64)) / 64));
|
||||
$utf .= chr(128 + ($dec % 64));
|
||||
}
|
||||
$url = str_replace('%u' . $uniord, $utf, $url);
|
||||
}
|
||||
return urldecode($url);
|
||||
}
|
||||
|
||||
function getgetparam($name, $default = '')
|
||||
{
|
||||
global $webim_encoding;
|
||||
if (!isset($_GET[$name]) || !$_GET[$name]) {
|
||||
return $default;
|
||||
}
|
||||
$value = myiconv("utf-8", $webim_encoding, unicode_urldecode($_GET[$name]));
|
||||
if (get_magic_quotes_gpc()) {
|
||||
$value = stripslashes($value);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
function cutstring($string, $length = 75, $ellipsis = '')
|
||||
{
|
||||
$result = '';
|
||||
if (strlen($string) > $length) {
|
||||
$splitstring = explode("[__cut__]", wordwrap($string, $length, "[__cut__]", true));
|
||||
$result = $splitstring[0] . $ellipsis;
|
||||
}else{
|
||||
$result = $string;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
function start_xml_output()
|
||||
{
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Pragma: no-cache");
|
||||
header("Content-type: text/xml; charset=utf-8");
|
||||
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
|
||||
}
|
||||
|
||||
function start_html_output()
|
||||
{
|
||||
$charset = getstring("output_charset");
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Pragma: no-cache");
|
||||
header("Content-type: text/html" . (isset($charset) ? "; charset=" . $charset : ""));
|
||||
}
|
||||
|
||||
function start_js_output(){
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Pragma: no-cache");
|
||||
header("Content-type: application/javascript; charset=utf-8");
|
||||
header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
|
||||
}
|
||||
|
||||
function escape_with_cdata($text)
|
||||
{
|
||||
return "<![CDATA[" . str_replace("]]>", "]]>]]><![CDATA[", $text) . "]]>";
|
||||
}
|
||||
|
||||
function form_value($key)
|
||||
{
|
||||
global $page;
|
||||
if (isset($page) && isset($page["form$key"]))
|
||||
return htmlspecialchars($page["form$key"]);
|
||||
return "";
|
||||
}
|
||||
|
||||
function form_value_cb($key)
|
||||
{
|
||||
global $page;
|
||||
if (isset($page) && isset($page["form$key"]))
|
||||
return $page["form$key"] === true;
|
||||
return false;
|
||||
}
|
||||
|
||||
function form_value_mb($key, $id)
|
||||
{
|
||||
global $page;
|
||||
if (isset($page) && isset($page["form$key"]) && is_array($page["form$key"])) {
|
||||
return in_array($id, $page["form$key"]);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function no_field($key)
|
||||
{
|
||||
return getlocal2("errors.required", array(getlocal($key)));
|
||||
}
|
||||
|
||||
function failed_uploading_file($filename, $key)
|
||||
{
|
||||
return getlocal2("errors.failed.uploading.file",
|
||||
array($filename, getlocal($key)));
|
||||
}
|
||||
|
||||
function wrong_field($key)
|
||||
{
|
||||
return getlocal2("errors.wrong_field", array(getlocal($key)));
|
||||
}
|
||||
|
||||
function get_popup($href, $jshref, $message, $title, $wndName, $options)
|
||||
{
|
||||
if (!$jshref) {
|
||||
$jshref = "'$href'";
|
||||
}
|
||||
return "<a href=\"$href\" target=\"_blank\" " . ($title ? "title=\"$title\" " : "") . "onclick=\"if(navigator.userAgent.toLowerCase().indexOf('opera') != -1 && window.event.preventDefault) window.event.preventDefault();this.newWindow = window.open($jshref, '$wndName', '$options');this.newWindow.focus();this.newWindow.opener=window;return false;\">$message</a>";
|
||||
}
|
||||
|
||||
function get_image($href, $width, $height)
|
||||
{
|
||||
if ($width != 0 && $height != 0)
|
||||
return "<img src=\"$href\" border=\"0\" width=\"$width\" height=\"$height\" alt=\"\"/>";
|
||||
return "<img src=\"$href\" border=\"0\" alt=\"\"/>";
|
||||
}
|
||||
|
||||
function get_gifimage_size($filename)
|
||||
{
|
||||
if (function_exists('gd_info')) {
|
||||
$info = gd_info();
|
||||
if (isset($info['GIF Read Support']) && $info['GIF Read Support']) {
|
||||
$img = @imagecreatefromgif($filename);
|
||||
if ($img) {
|
||||
$height = imagesy($img);
|
||||
$width = imagesx($img);
|
||||
imagedestroy($img);
|
||||
return array($width, $height);
|
||||
}
|
||||
}
|
||||
}
|
||||
return array(0, 0);
|
||||
}
|
||||
|
||||
function add_params($servlet, $params)
|
||||
{
|
||||
$infix = '?';
|
||||
if (strstr($servlet, $infix) !== FALSE)
|
||||
$infix = '&';
|
||||
foreach ($params as $k => $v) {
|
||||
$servlet .= $infix . $k . "=" . $v;
|
||||
$infix = '&';
|
||||
}
|
||||
return $servlet;
|
||||
}
|
||||
|
||||
function div($a, $b)
|
||||
{
|
||||
return ($a - ($a % $b)) / $b;
|
||||
}
|
||||
|
||||
function date_diff_to_text($seconds)
|
||||
{
|
||||
$minutes = div($seconds, 60);
|
||||
$seconds = $seconds % 60;
|
||||
if ($minutes < 60) {
|
||||
return sprintf("%02d:%02d", $minutes, $seconds);
|
||||
} else {
|
||||
$hours = div($minutes, 60);
|
||||
$minutes = $minutes % 60;
|
||||
return sprintf("%02d:%02d:%02d", $hours, $minutes, $seconds);
|
||||
}
|
||||
}
|
||||
|
||||
function is_valid_email($email)
|
||||
{
|
||||
return preg_match("/^[^@]+@[^\.]+(\.[^\.]+)*$/", $email);
|
||||
}
|
||||
|
||||
function get_app_location($showhost, $issecure)
|
||||
{
|
||||
global $webimroot;
|
||||
if ($showhost) {
|
||||
return ($issecure ? "https://" : "http://") . $_SERVER['HTTP_HOST'] . $webimroot;
|
||||
} else {
|
||||
return $webimroot;
|
||||
}
|
||||
}
|
||||
|
||||
function is_secure_request()
|
||||
{
|
||||
return
|
||||
isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443'
|
||||
|| isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on"
|
||||
|| isset($_SERVER["HTTP_HTTPS"]) && $_SERVER["HTTP_HTTPS"] == "on";
|
||||
}
|
||||
|
||||
function get_month_selection($fromtime, $totime)
|
||||
{
|
||||
$start = getdate($fromtime);
|
||||
$month = $start['mon'];
|
||||
$year = $start['year'];
|
||||
$result = array();
|
||||
do {
|
||||
$current = mktime(0, 0, 0, $month, 1, $year);
|
||||
$result[date("m.y", $current)] = strftime("%B, %Y", $current);
|
||||
$month++;
|
||||
if ($month > 12) {
|
||||
$month = 1;
|
||||
$year++;
|
||||
}
|
||||
} while ($current < $totime);
|
||||
return $result;
|
||||
}
|
||||
|
||||
function get_form_date($day, $month)
|
||||
{
|
||||
if (preg_match('/^(\d{2}).(\d{2})$/', $month, $matches)) {
|
||||
return mktime(0, 0, 0, $matches[1], $day, $matches[2]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
function set_form_date($utime, $prefix)
|
||||
{
|
||||
global $page;
|
||||
$page["form${prefix}day"] = date("d", $utime);
|
||||
$page["form${prefix}month"] = date("m.y", $utime);
|
||||
}
|
||||
|
||||
function date_to_text($unixtime)
|
||||
{
|
||||
if ($unixtime < 60 * 60 * 24 * 30)
|
||||
return getlocal("time.never");
|
||||
|
||||
$then = getdate($unixtime);
|
||||
$now = getdate();
|
||||
|
||||
if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) {
|
||||
$date_format = getlocal("time.today.at");
|
||||
} else if (($then['yday'] + 1) == $now['yday'] && $then['year'] == $now['year']) {
|
||||
$date_format = getlocal("time.yesterday.at");
|
||||
} else {
|
||||
$date_format = getlocal("time.dateformat");
|
||||
}
|
||||
|
||||
return strftime($date_format . " " . getlocal("time.timeformat"), $unixtime);
|
||||
}
|
||||
|
||||
$dbversion = '1.6.3';
|
||||
$featuresversion = '1.6.4';
|
||||
|
||||
function getchatstyle()
|
||||
{
|
||||
$chatstyle = verifyparam("style", "/^\w+$/", "");
|
||||
if ($chatstyle) {
|
||||
return $chatstyle;
|
||||
}
|
||||
return Settings::get('chatstyle');
|
||||
}
|
||||
|
||||
function jspath()
|
||||
{
|
||||
global $jsver;
|
||||
return "js/$jsver";
|
||||
}
|
||||
|
||||
/* authorization token check for CSRF attack */
|
||||
function csrfchecktoken()
|
||||
{
|
||||
setcsrftoken();
|
||||
|
||||
// check the turing code for post requests and del requests
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
//if token match
|
||||
if (!isset($_POST['csrf_token']) || ($_POST['csrf_token'] != $_SESSION['csrf_token'])) {
|
||||
|
||||
die("CSRF failure");
|
||||
}
|
||||
} else if (isset($_GET['act'])) {
|
||||
if (($_GET['act'] == 'del' || $_GET['act'] == 'delete') && $_GET['csrf_token'] != $_SESSION['csrf_token']) {
|
||||
|
||||
die("CSRF failure");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* print csrf token as a hidden field*/
|
||||
function print_csrf_token_input()
|
||||
{
|
||||
setcsrftoken();
|
||||
|
||||
echo "<input name='csrf_token' type='hidden' value='" . $_SESSION['csrf_token'] . "' />\n";
|
||||
}
|
||||
|
||||
/* print csrf token in url format */
|
||||
function print_csrf_token_in_url()
|
||||
{
|
||||
setcsrftoken();
|
||||
|
||||
echo "&csrf_token=" . $_SESSION['csrf_token'];
|
||||
}
|
||||
|
||||
/* set csrf token */
|
||||
function setcsrftoken()
|
||||
{
|
||||
if (!isset($_SESSION['csrf_token'])) {
|
||||
$_SESSION['csrf_token'] = sha1(rand(10000000, 99999999));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
39
src/messenger/webim/libs/common/constants.php
Normal file
39
src/messenger/webim/libs/common/constants.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright 2005-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Current version of Mibew Messenger
|
||||
*/
|
||||
$version = '1.6.5';
|
||||
|
||||
/**
|
||||
* Current version of Mibew Messenger's JavaScript
|
||||
*/
|
||||
$jsver = "164";
|
||||
|
||||
/**
|
||||
* Current version of database structure
|
||||
*/
|
||||
$dbversion = '1.6.3';
|
||||
|
||||
/**
|
||||
* Current version of implemented features
|
||||
*/
|
||||
$featuresversion = '1.6.4';
|
||||
|
||||
|
||||
?>
|
62
src/messenger/webim/libs/common/csrf.php
Normal file
62
src/messenger/webim/libs/common/csrf.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright 2005-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/* authorization token check for CSRF attack */
|
||||
function csrfchecktoken()
|
||||
{
|
||||
setcsrftoken();
|
||||
|
||||
// check the turing code for post requests and del requests
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
//if token match
|
||||
if (!isset($_POST['csrf_token']) || ($_POST['csrf_token'] != $_SESSION['csrf_token'])) {
|
||||
|
||||
die("CSRF failure");
|
||||
}
|
||||
} else if (isset($_GET['act'])) {
|
||||
if (($_GET['act'] == 'del' || $_GET['act'] == 'delete') && $_GET['csrf_token'] != $_SESSION['csrf_token']) {
|
||||
|
||||
die("CSRF failure");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* print csrf token as a hidden field*/
|
||||
function print_csrf_token_input()
|
||||
{
|
||||
setcsrftoken();
|
||||
|
||||
echo "<input name='csrf_token' type='hidden' value='" . $_SESSION['csrf_token'] . "' />";
|
||||
}
|
||||
|
||||
/* print csrf token in url format */
|
||||
function print_csrf_token_in_url()
|
||||
{
|
||||
setcsrftoken();
|
||||
|
||||
echo "&csrf_token=" . $_SESSION['csrf_token'];
|
||||
}
|
||||
|
||||
/* set csrf token */
|
||||
function setcsrftoken()
|
||||
{
|
||||
if (!isset($_SESSION['csrf_token'])) {
|
||||
$_SESSION['csrf_token'] = sha1(rand(10000000, 99999999));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
85
src/messenger/webim/libs/common/datetime.php
Normal file
85
src/messenger/webim/libs/common/datetime.php
Normal file
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright 2005-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
require_once(dirname(__FILE__) . '/locale.php');
|
||||
|
||||
function date_diff_to_text($seconds)
|
||||
{
|
||||
$minutes = div($seconds, 60);
|
||||
$seconds = $seconds % 60;
|
||||
if ($minutes < 60) {
|
||||
return sprintf("%02d:%02d", $minutes, $seconds);
|
||||
} else {
|
||||
$hours = div($minutes, 60);
|
||||
$minutes = $minutes % 60;
|
||||
return sprintf("%02d:%02d:%02d", $hours, $minutes, $seconds);
|
||||
}
|
||||
}
|
||||
|
||||
function get_month_selection($fromtime, $totime)
|
||||
{
|
||||
$start = getdate($fromtime);
|
||||
$month = $start['mon'];
|
||||
$year = $start['year'];
|
||||
$result = array();
|
||||
do {
|
||||
$current = mktime(0, 0, 0, $month, 1, $year);
|
||||
$result[date("m.y", $current)] = strftime("%B, %Y", $current);
|
||||
$month++;
|
||||
if ($month > 12) {
|
||||
$month = 1;
|
||||
$year++;
|
||||
}
|
||||
} while ($current < $totime);
|
||||
return $result;
|
||||
}
|
||||
|
||||
function get_form_date($day, $month)
|
||||
{
|
||||
if (preg_match('/^(\d{2}).(\d{2})$/', $month, $matches)) {
|
||||
return mktime(0, 0, 0, $matches[1], $day, $matches[2]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
function set_form_date($utime, $prefix)
|
||||
{
|
||||
global $page;
|
||||
$page["form${prefix}day"] = date("d", $utime);
|
||||
$page["form${prefix}month"] = date("m.y", $utime);
|
||||
}
|
||||
|
||||
function date_to_text($unixtime)
|
||||
{
|
||||
if ($unixtime < 60 * 60 * 24 * 30)
|
||||
return getlocal("time.never");
|
||||
|
||||
$then = getdate($unixtime);
|
||||
$now = getdate();
|
||||
|
||||
if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) {
|
||||
$date_format = getlocal("time.today.at");
|
||||
} else if (($then['yday'] + 1) == $now['yday'] && $then['year'] == $now['year']) {
|
||||
$date_format = getlocal("time.yesterday.at");
|
||||
} else {
|
||||
$date_format = getlocal("time.dateformat");
|
||||
}
|
||||
|
||||
return strftime($date_format . " " . getlocal("time.timeformat"), $unixtime);
|
||||
}
|
||||
|
||||
?>
|
43
src/messenger/webim/libs/common/forms.php
Normal file
43
src/messenger/webim/libs/common/forms.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright 2005-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
function form_value($key)
|
||||
{
|
||||
global $page;
|
||||
if (isset($page) && isset($page["form$key"]))
|
||||
return htmlspecialchars($page["form$key"]);
|
||||
return "";
|
||||
}
|
||||
|
||||
function form_value_cb($key)
|
||||
{
|
||||
global $page;
|
||||
if (isset($page) && isset($page["form$key"]))
|
||||
return $page["form$key"] === true;
|
||||
return false;
|
||||
}
|
||||
|
||||
function form_value_mb($key, $id)
|
||||
{
|
||||
global $page;
|
||||
if (isset($page) && isset($page["form$key"]) && is_array($page["form$key"])) {
|
||||
return in_array($id, $page["form$key"]);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
?>
|
231
src/messenger/webim/libs/common/locale.php
Normal file
231
src/messenger/webim/libs/common/locale.php
Normal file
@ -0,0 +1,231 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright 2005-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
require_once(dirname(__FILE__) . '/converter.php');
|
||||
require_once(dirname(__FILE__) . '/verification.php');
|
||||
|
||||
function myiconv($in_enc, $out_enc, $string)
|
||||
{
|
||||
global $_utf8win1251, $_win1251utf8;
|
||||
if ($in_enc == $out_enc) {
|
||||
return $string;
|
||||
}
|
||||
if (function_exists('iconv')) {
|
||||
$converted = @iconv($in_enc, $out_enc, $string);
|
||||
if ($converted !== FALSE) {
|
||||
return $converted;
|
||||
}
|
||||
}
|
||||
if ($in_enc == "cp1251" && $out_enc == "utf-8")
|
||||
return strtr($string, $_win1251utf8);
|
||||
if ($in_enc == "utf-8" && $out_enc == "cp1251")
|
||||
return strtr($string, $_utf8win1251);
|
||||
|
||||
return $string; // do not know how to convert
|
||||
}
|
||||
|
||||
function locale_exists($locale)
|
||||
{
|
||||
return file_exists(dirname(__FILE__) . "/../../locales/$locale/properties");
|
||||
}
|
||||
|
||||
function get_available_locales()
|
||||
{
|
||||
global $locale_pattern;
|
||||
$list = array();
|
||||
$folder = dirname(__FILE__) . "/../../locales";
|
||||
if ($handle = opendir($folder)) {
|
||||
while (false !== ($file = readdir($handle))) {
|
||||
if (preg_match($locale_pattern, $file) && $file != 'names' && is_dir("$folder/$file")) {
|
||||
$list[] = $file;
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
sort($list);
|
||||
return $list;
|
||||
}
|
||||
|
||||
function get_user_locale()
|
||||
{
|
||||
global $default_locale;
|
||||
|
||||
if (isset($_COOKIE['webim_locale'])) {
|
||||
$requested_lang = $_COOKIE['webim_locale'];
|
||||
if (locale_exists($requested_lang))
|
||||
return $requested_lang;
|
||||
}
|
||||
|
||||
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
|
||||
$requested_langs = explode(",", $_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
||||
foreach ($requested_langs as $requested_lang) {
|
||||
if (strlen($requested_lang) > 2)
|
||||
$requested_lang = substr($requested_lang, 0, 2);
|
||||
|
||||
if (locale_exists($requested_lang))
|
||||
return $requested_lang;
|
||||
}
|
||||
}
|
||||
|
||||
if (locale_exists($default_locale))
|
||||
return $default_locale;
|
||||
|
||||
return 'en';
|
||||
}
|
||||
|
||||
function get_locale()
|
||||
{
|
||||
global $webimroot, $locale_pattern;
|
||||
|
||||
$locale = verifyparam("locale", $locale_pattern, "");
|
||||
|
||||
if ($locale && locale_exists($locale)) {
|
||||
$_SESSION['locale'] = $locale;
|
||||
setcookie('webim_locale', $locale, time() + 60 * 60 * 24 * 1000, "$webimroot/");
|
||||
} else if (isset($_SESSION['locale'])) {
|
||||
$locale = $_SESSION['locale'];
|
||||
}
|
||||
|
||||
if (!$locale || !locale_exists($locale))
|
||||
$locale = get_user_locale();
|
||||
return $locale;
|
||||
}
|
||||
|
||||
function get_locale_links($href)
|
||||
{
|
||||
global $current_locale;
|
||||
$localeLinks = array();
|
||||
$allLocales = get_available_locales();
|
||||
if (count($allLocales) < 2) {
|
||||
return null;
|
||||
}
|
||||
foreach ($allLocales as $k) {
|
||||
$localeLinks[$k] = getlocal_($k, "names");
|
||||
}
|
||||
return $localeLinks;
|
||||
}
|
||||
|
||||
function load_messages($locale)
|
||||
{
|
||||
global $messages, $webim_encoding, $output_encoding;
|
||||
$hash = array();
|
||||
$current_encoding = $webim_encoding;
|
||||
$fp = fopen(dirname(__FILE__) . "/../../locales/$locale/properties", "r");
|
||||
while (!feof($fp)) {
|
||||
$line = fgets($fp, 4096);
|
||||
$keyval = preg_split("/=/", $line, 2);
|
||||
if (isset($keyval[1])) {
|
||||
if ($keyval[0] == 'encoding') {
|
||||
$current_encoding = trim($keyval[1]);
|
||||
} else if ($keyval[0] == 'output_encoding') {
|
||||
$output_encoding[$locale] = trim($keyval[1]);
|
||||
} else if ($current_encoding == $webim_encoding) {
|
||||
$hash[$keyval[0]] = str_replace("\\n", "\n", trim($keyval[1]));
|
||||
} else {
|
||||
$hash[$keyval[0]] = myiconv($current_encoding, $webim_encoding, str_replace("\\n", "\n", trim($keyval[1])));
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose($fp);
|
||||
$messages[$locale] = $hash;
|
||||
}
|
||||
|
||||
function getoutputenc()
|
||||
{
|
||||
global $current_locale, $output_encoding, $webim_encoding, $messages;
|
||||
if (!isset($messages[$current_locale]))
|
||||
load_messages($current_locale);
|
||||
return isset($output_encoding[$current_locale]) ? $output_encoding[$current_locale] : $webim_encoding;
|
||||
}
|
||||
|
||||
function getstring_($text, $locale)
|
||||
{
|
||||
global $messages;
|
||||
if (!isset($messages[$locale]))
|
||||
load_messages($locale);
|
||||
|
||||
$localized = $messages[$locale];
|
||||
if (isset($localized[$text]))
|
||||
return $localized[$text];
|
||||
if ($locale != 'en') {
|
||||
return getstring_($text, 'en');
|
||||
}
|
||||
|
||||
return "!" . $text;
|
||||
}
|
||||
|
||||
function getstring($text)
|
||||
{
|
||||
global $current_locale;
|
||||
return getstring_($text, $current_locale);
|
||||
}
|
||||
|
||||
function getlocal($text)
|
||||
{
|
||||
global $current_locale, $webim_encoding;
|
||||
return myiconv($webim_encoding, getoutputenc(), getstring_($text, $current_locale));
|
||||
}
|
||||
|
||||
function getlocal_($text, $locale)
|
||||
{
|
||||
global $webim_encoding;
|
||||
return myiconv($webim_encoding, getoutputenc(), getstring_($text, $locale));
|
||||
}
|
||||
|
||||
function getstring2_($text, $params, $locale)
|
||||
{
|
||||
$string = getstring_($text, $locale);
|
||||
for ($i = 0; $i < count($params); $i++) {
|
||||
$string = str_replace("{" . $i . "}", $params[$i], $string);
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
function getstring2($text, $params)
|
||||
{
|
||||
global $current_locale;
|
||||
return getstring2_($text, $params, $current_locale);
|
||||
}
|
||||
|
||||
function getlocal2($text, $params)
|
||||
{
|
||||
global $current_locale, $webim_encoding;
|
||||
$string = myiconv($webim_encoding, getoutputenc(), getstring_($text, $current_locale));
|
||||
for ($i = 0; $i < count($params); $i++) {
|
||||
$string = str_replace("{" . $i . "}", $params[$i], $string);
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
/* prepares for Javascript string */
|
||||
function getlocalforJS($text, $params)
|
||||
{
|
||||
global $current_locale, $webim_encoding;
|
||||
$string = myiconv($webim_encoding, getoutputenc(), getstring_($text, $current_locale));
|
||||
$string = str_replace("\"", "\\\"", str_replace("\n", "\\n", $string));
|
||||
for ($i = 0; $i < count($params); $i++) {
|
||||
$string = str_replace("{" . $i . "}", $params[$i], $string);
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
$locale_pattern = "/^[\w-]{2,5}$/";
|
||||
$current_locale = get_locale();
|
||||
$messages = array();
|
||||
$output_encoding = array();
|
||||
|
||||
?>
|
59
src/messenger/webim/libs/common/misc.php
Normal file
59
src/messenger/webim/libs/common/misc.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright 2005-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
require_once(dirname(__FILE__) . '/constants.php');
|
||||
|
||||
function debugexit_print($var)
|
||||
{
|
||||
echo "<html><body><pre>";
|
||||
print_r($var);
|
||||
echo "</pre></body></html>";
|
||||
exit;
|
||||
}
|
||||
|
||||
function get_gifimage_size($filename)
|
||||
{
|
||||
if (function_exists('gd_info')) {
|
||||
$info = gd_info();
|
||||
if (isset($info['GIF Read Support']) && $info['GIF Read Support']) {
|
||||
$img = @imagecreatefromgif($filename);
|
||||
if ($img) {
|
||||
$height = imagesy($img);
|
||||
$width = imagesx($img);
|
||||
imagedestroy($img);
|
||||
return array($width, $height);
|
||||
}
|
||||
}
|
||||
}
|
||||
return array(0, 0);
|
||||
}
|
||||
|
||||
|
||||
function jspath()
|
||||
{
|
||||
global $jsver;
|
||||
return "js/$jsver";
|
||||
}
|
||||
|
||||
function div($a, $b)
|
||||
{
|
||||
return ($a - ($a % $b)) / $b;
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
88
src/messenger/webim/libs/common/request.php
Normal file
88
src/messenger/webim/libs/common/request.php
Normal file
@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright 2005-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
require_once(dirname(__FILE__) . '/locale.php');
|
||||
|
||||
/* ajax server actions use utf-8 */
|
||||
function getrawparam($name)
|
||||
{
|
||||
global $webim_encoding;
|
||||
if (isset($_POST[$name])) {
|
||||
$value = myiconv("utf-8", $webim_encoding, $_POST[$name]);
|
||||
if (get_magic_quotes_gpc()) {
|
||||
$value = stripslashes($value);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
die("no " . $name . " parameter");
|
||||
}
|
||||
|
||||
/* form processors use current Output encoding */
|
||||
function getparam($name)
|
||||
{
|
||||
global $webim_encoding;
|
||||
if (isset($_POST[$name])) {
|
||||
$value = myiconv(getoutputenc(), $webim_encoding, $_POST[$name]);
|
||||
if (get_magic_quotes_gpc()) {
|
||||
$value = stripslashes($value);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
die("no " . $name . " parameter");
|
||||
}
|
||||
|
||||
function getgetparam($name, $default = '')
|
||||
{
|
||||
global $webim_encoding;
|
||||
if (!isset($_GET[$name]) || !$_GET[$name]) {
|
||||
return $default;
|
||||
}
|
||||
$value = myiconv("utf-8", $webim_encoding, unicode_urldecode($_GET[$name]));
|
||||
if (get_magic_quotes_gpc()) {
|
||||
$value = stripslashes($value);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
function get_app_location($showhost, $issecure)
|
||||
{
|
||||
global $webimroot;
|
||||
if ($showhost) {
|
||||
return ($issecure ? "https://" : "http://") . $_SERVER['HTTP_HOST'] . $webimroot;
|
||||
} else {
|
||||
return $webimroot;
|
||||
}
|
||||
}
|
||||
|
||||
function is_secure_request()
|
||||
{
|
||||
return
|
||||
isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443'
|
||||
|| isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on"
|
||||
|| isset($_SERVER["HTTP_HTTPS"]) && $_SERVER["HTTP_HTTPS"] == "on";
|
||||
}
|
||||
|
||||
function getchatstyle()
|
||||
{
|
||||
$chatstyle = verifyparam("style", "/^\w+$/", "");
|
||||
if ($chatstyle) {
|
||||
return $chatstyle;
|
||||
}
|
||||
return Settings::get('chatstyle');
|
||||
}
|
||||
|
||||
?>
|
95
src/messenger/webim/libs/common/response.php
Normal file
95
src/messenger/webim/libs/common/response.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright 2005-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
require_once(dirname(__FILE__) . '/locale.php');
|
||||
|
||||
function get_popup($href, $jshref, $message, $title, $wndName, $options)
|
||||
{
|
||||
if (!$jshref) {
|
||||
$jshref = "'$href'";
|
||||
}
|
||||
return "<a href=\"$href\" target=\"_blank\" " . ($title ? "title=\"$title\" " : "") . "onclick=\"if(navigator.userAgent.toLowerCase().indexOf('opera') != -1 && window.event.preventDefault) window.event.preventDefault();this.newWindow = window.open($jshref, '$wndName', '$options');this.newWindow.focus();this.newWindow.opener=window;return false;\">$message</a>";
|
||||
}
|
||||
|
||||
function get_image($href, $width, $height)
|
||||
{
|
||||
if ($width != 0 && $height != 0)
|
||||
return "<img src=\"$href\" border=\"0\" width=\"$width\" height=\"$height\" alt=\"\"/>";
|
||||
return "<img src=\"$href\" border=\"0\" alt=\"\"/>";
|
||||
}
|
||||
|
||||
function start_xml_output()
|
||||
{
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Pragma: no-cache");
|
||||
header("Content-type: text/xml; charset=utf-8");
|
||||
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
|
||||
}
|
||||
|
||||
function start_html_output()
|
||||
{
|
||||
$charset = getstring("output_charset");
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Pragma: no-cache");
|
||||
header("Content-type: text/html" . (isset($charset) ? "; charset=" . $charset : ""));
|
||||
}
|
||||
|
||||
function start_js_output(){
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Pragma: no-cache");
|
||||
header("Content-type: application/javascript; charset=utf-8");
|
||||
header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
|
||||
}
|
||||
|
||||
function topage($text)
|
||||
{
|
||||
global $webim_encoding;
|
||||
return myiconv($webim_encoding, getoutputenc(), $text);
|
||||
}
|
||||
|
||||
function no_field($key)
|
||||
{
|
||||
return getlocal2("errors.required", array(getlocal($key)));
|
||||
}
|
||||
|
||||
function failed_uploading_file($filename, $key)
|
||||
{
|
||||
return getlocal2("errors.failed.uploading.file",
|
||||
array($filename, getlocal($key)));
|
||||
}
|
||||
|
||||
function wrong_field($key)
|
||||
{
|
||||
return getlocal2("errors.wrong_field", array(getlocal($key)));
|
||||
}
|
||||
|
||||
function add_params($servlet, $params)
|
||||
{
|
||||
$infix = '?';
|
||||
if (strstr($servlet, $infix) !== FALSE)
|
||||
$infix = '&';
|
||||
foreach ($params as $k => $v) {
|
||||
$servlet .= $infix . $k . "=" . $v;
|
||||
$infix = '&';
|
||||
}
|
||||
return $servlet;
|
||||
}
|
||||
|
||||
?>
|
58
src/messenger/webim/libs/common/string.php
Normal file
58
src/messenger/webim/libs/common/string.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright 2005-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
function unicode_urldecode($url)
|
||||
{
|
||||
preg_match_all('/%u([[:alnum:]]{4})/', $url, $a);
|
||||
|
||||
foreach ($a[1] as $uniord) {
|
||||
$dec = hexdec($uniord);
|
||||
$utf = '';
|
||||
|
||||
if ($dec < 128) {
|
||||
$utf = chr($dec);
|
||||
} else if ($dec < 2048) {
|
||||
$utf = chr(192 + (($dec - ($dec % 64)) / 64));
|
||||
$utf .= chr(128 + ($dec % 64));
|
||||
} else {
|
||||
$utf = chr(224 + (($dec - ($dec % 4096)) / 4096));
|
||||
$utf .= chr(128 + ((($dec % 4096) - ($dec % 64)) / 64));
|
||||
$utf .= chr(128 + ($dec % 64));
|
||||
}
|
||||
$url = str_replace('%u' . $uniord, $utf, $url);
|
||||
}
|
||||
return urldecode($url);
|
||||
}
|
||||
|
||||
function cutstring($string, $length = 75, $ellipsis = '')
|
||||
{
|
||||
$result = '';
|
||||
if (strlen($string) > $length) {
|
||||
$splitstring = explode("[__cut__]", wordwrap($string, $length, "[__cut__]", true));
|
||||
$result = $splitstring[0] . $ellipsis;
|
||||
}else{
|
||||
$result = $string;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
function escape_with_cdata($text)
|
||||
{
|
||||
return "<![CDATA[" . str_replace("]]>", "]]>]]><![CDATA[", $text) . "]]>";
|
||||
}
|
||||
|
||||
?>
|
43
src/messenger/webim/libs/common/verification.php
Normal file
43
src/messenger/webim/libs/common/verification.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright 2005-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
function verifyparam($name, $regexp, $default = null)
|
||||
{
|
||||
if (isset($_GET[$name])) {
|
||||
$val = $_GET[$name];
|
||||
if (preg_match($regexp, $val))
|
||||
return $val;
|
||||
|
||||
} else if (isset($_POST[$name])) {
|
||||
$val = $_POST[$name];
|
||||
if (preg_match($regexp, $val))
|
||||
return $val;
|
||||
|
||||
} else {
|
||||
if (isset($default))
|
||||
return $default;
|
||||
}
|
||||
echo "<html><head></head><body>Wrong parameter used or absent: " . $name . "</body></html>";
|
||||
exit;
|
||||
}
|
||||
|
||||
function is_valid_email($email)
|
||||
{
|
||||
return preg_match("/^[^@]+@[^\.]+(\.[^\.]+)*$/", $email);
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in New Issue
Block a user