mirror of
https://github.com/Mibew/mibew.git
synced 2025-02-01 05:44:41 +03:00
Apply new codding style
This commit is contained in:
parent
41f1e0a3bc
commit
42ff39f4d9
@ -20,55 +20,58 @@ use Mibew\Settings;
|
||||
use Mibew\Thread;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(dirname(__FILE__).'/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/chat.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/groups.php');
|
||||
require_once(dirname(__FILE__) . '/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/chat.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/groups.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/track.php');
|
||||
|
||||
$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : "";
|
||||
if($referer && isset($_SESSION['threadid'])) {
|
||||
$thread = Thread::load($_SESSION['threadid']);
|
||||
if ($referer && isset($_SESSION['threadid'])) {
|
||||
$thread = Thread::load($_SESSION['threadid']);
|
||||
if ($thread && $thread->state != Thread::STATE_CLOSED) {
|
||||
$msg = getstring2_("chat.client.visited.page", array($referer), $thread->locale);
|
||||
$thread->postMessage(Thread::KIND_FOR_AGENT, $msg);
|
||||
$msg = getstring2_(
|
||||
"chat.client.visited.page",
|
||||
array($referer),
|
||||
$thread->locale
|
||||
);
|
||||
$thread->postMessage(Thread::KIND_FOR_AGENT, $msg);
|
||||
}
|
||||
}
|
||||
|
||||
$image = verifyparam(isset($_GET['image']) ? "image" : "i", "/^\w+$/", "mibew");
|
||||
$lang = verifyparam(isset($_GET['language']) ? "language" : "lang", "/^[\w-]{2,5}$/", "");
|
||||
if(!$lang || !locale_exists($lang)) {
|
||||
$lang = CURRENT_LOCALE;
|
||||
$image = verify_param(isset($_GET['image']) ? "image" : "i", "/^\w+$/", "mibew");
|
||||
$lang = verify_param(isset($_GET['language']) ? "language" : "lang", "/^[\w-]{2,5}$/", "");
|
||||
if (!$lang || !locale_exists($lang)) {
|
||||
$lang = CURRENT_LOCALE;
|
||||
}
|
||||
|
||||
$groupid = verifyparam( "group", "/^\d{1,8}$/", "");
|
||||
if($groupid) {
|
||||
if(Settings::get('enablegroups') == '1') {
|
||||
$group = group_by_id($groupid);
|
||||
if(!$group) {
|
||||
$groupid = "";
|
||||
}
|
||||
} else {
|
||||
$groupid = "";
|
||||
}
|
||||
$group_id = verify_param("group", "/^\d{1,8}$/", "");
|
||||
if ($group_id) {
|
||||
if (Settings::get('enablegroups') == '1') {
|
||||
$group = group_by_id($group_id);
|
||||
if (!$group) {
|
||||
$group_id = "";
|
||||
}
|
||||
} else {
|
||||
$group_id = "";
|
||||
}
|
||||
}
|
||||
|
||||
$image_postfix = has_online_operators($groupid) ? "on" : "off";
|
||||
$filename = "locales/${lang}/button/${image}_${image_postfix}.gif";
|
||||
$image_postfix = has_online_operators($group_id) ? "on" : "off";
|
||||
$file_name = "locales/${lang}/button/${image}_${image_postfix}.gif";
|
||||
|
||||
$fp = fopen($filename, 'rb') or die("no image");
|
||||
$fp = fopen($file_name, 'rb') or die("no image");
|
||||
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: image/gif");
|
||||
header("Content-Length: ".filesize($filename));
|
||||
if(function_exists('fpassthru')){
|
||||
@fpassthru($fp);
|
||||
header("Content-Length: " . filesize($file_name));
|
||||
if (function_exists('fpassthru')) {
|
||||
@fpassthru($fp);
|
||||
} else {
|
||||
while( (!feof($fp)) && (connection_status()==0)){
|
||||
print(fread($fp, 1024*8));
|
||||
flush();
|
||||
}
|
||||
fclose($fp);
|
||||
while ((!feof($fp)) && (connection_status() == 0)) {
|
||||
print(fread($fp, 1024 * 8));
|
||||
flush();
|
||||
}
|
||||
fclose($fp);
|
||||
}
|
||||
exit;
|
||||
?>
|
@ -15,6 +15,4 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
require_once(dirname(__FILE__).'/b.php');
|
||||
exit;
|
||||
?>
|
||||
require_once(dirname(__FILE__) . '/b.php');
|
||||
|
@ -15,12 +15,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
require_once(dirname(__FILE__).'/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/captcha.php');
|
||||
require_once(dirname(__FILE__) . '/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/captcha.php');
|
||||
|
||||
$captchaCode = gen_captcha();
|
||||
$_SESSION["mibew_captcha"] = $captchaCode;
|
||||
draw_captcha($captchaCode);
|
||||
|
||||
exit;
|
||||
?>
|
||||
$captcha_code = gen_captcha();
|
||||
$_SESSION["mibew_captcha"] = $captcha_code;
|
||||
draw_captcha($captcha_code);
|
||||
|
@ -21,24 +21,24 @@ use Mibew\Thread;
|
||||
use Mibew\Style\ChatStyle;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(dirname(__FILE__).'/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/chat.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/groups.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/captcha.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/invitation.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/track.php');
|
||||
require_once(dirname(__FILE__) . '/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/chat.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/groups.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/captcha.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/invitation.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/track.php');
|
||||
|
||||
if(Settings::get('enablessl') == "1" && Settings::get('forcessl') == "1") {
|
||||
if(!is_secure_request()) {
|
||||
$requested = $_SERVER['PHP_SELF'];
|
||||
if($_SERVER['REQUEST_METHOD'] == 'GET' && $_SERVER['QUERY_STRING']) {
|
||||
header("Location: ".get_app_location(true,true)."/client.php?".$_SERVER['QUERY_STRING']);
|
||||
} else {
|
||||
die("only https connections are handled");
|
||||
}
|
||||
exit;
|
||||
}
|
||||
if (Settings::get('enablessl') == "1" && Settings::get('forcessl') == "1") {
|
||||
if (!is_secure_request()) {
|
||||
$requested = $_SERVER['PHP_SELF'];
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'GET' && $_SERVER['QUERY_STRING']) {
|
||||
header("Location: " . get_app_location(true, true) . "/client.php?" . $_SERVER['QUERY_STRING']);
|
||||
} else {
|
||||
die("only https connections are handled");
|
||||
}
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize chat style which is currently used in system
|
||||
@ -46,155 +46,164 @@ $chat_style = new ChatStyle(ChatStyle::currentStyle());
|
||||
|
||||
// Do not support old browsers at all
|
||||
if (get_remote_level($_SERVER['HTTP_USER_AGENT']) == 'old') {
|
||||
// Create page array
|
||||
$page = array_merge_recursive(
|
||||
setup_logo()
|
||||
);
|
||||
$chat_style->render('nochat', $page);
|
||||
exit;
|
||||
// Create page array
|
||||
$page = array_merge_recursive(
|
||||
setup_logo()
|
||||
);
|
||||
$chat_style->render('nochat', $page);
|
||||
exit;
|
||||
}
|
||||
|
||||
$action = verifyparam("act", "/^(invitation|mailthread)$/", "default");
|
||||
$action = verify_param("act", "/^(invitation|mailthread)$/", "default");
|
||||
|
||||
if ($action == 'invitation' && Settings::get('enabletracking')) {
|
||||
// Check if user invited to chat
|
||||
$invitation_state = invitation_state($_SESSION['visitorid']);
|
||||
// Check if user invited to chat
|
||||
$invitation_state = invitation_state($_SESSION['visitorid']);
|
||||
|
||||
if ($invitation_state['invited'] && $invitation_state['threadid']) {
|
||||
$thread = Thread::load($invitation_state['threadid']);
|
||||
if ($invitation_state['invited'] && $invitation_state['threadid']) {
|
||||
$thread = Thread::load($invitation_state['threadid']);
|
||||
|
||||
// Prepare page
|
||||
$page = setup_invitation_view($thread);
|
||||
// Prepare page
|
||||
$page = setup_invitation_view($thread);
|
||||
|
||||
// Build js application options
|
||||
$page['invitationOptions'] = json_encode($page['invitation']);
|
||||
// Expand page
|
||||
$chat_style->render('chat', $page);
|
||||
exit;
|
||||
}
|
||||
// Build js application options
|
||||
$page['invitationOptions'] = json_encode($page['invitation']);
|
||||
// Expand page
|
||||
$chat_style->render('chat', $page);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
if( !isset($_GET['token']) || !isset($_GET['thread']) ) {
|
||||
if (!isset($_GET['token']) || !isset($_GET['thread'])) {
|
||||
|
||||
$thread = NULL;
|
||||
if( isset($_SESSION['threadid']) ) {
|
||||
$thread = Thread::reopen($_SESSION['threadid']);
|
||||
}
|
||||
$thread = null;
|
||||
if (isset($_SESSION['threadid'])) {
|
||||
$thread = Thread::reopen($_SESSION['threadid']);
|
||||
}
|
||||
|
||||
if( !$thread ) {
|
||||
if (!$thread) {
|
||||
|
||||
// Load group info
|
||||
$groupid = "";
|
||||
$groupname = "";
|
||||
$group = NULL;
|
||||
if(Settings::get('enablegroups') == '1') {
|
||||
$groupid = verifyparam( "group", "/^\d{1,8}$/", "");
|
||||
if($groupid) {
|
||||
$group = group_by_id($groupid);
|
||||
if(!$group) {
|
||||
$groupid = "";
|
||||
} else {
|
||||
$groupname = get_group_name($group);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Load group info
|
||||
$group_id = "";
|
||||
$group_name = "";
|
||||
$group = null;
|
||||
if (Settings::get('enablegroups') == '1') {
|
||||
$group_id = verify_param("group", "/^\d{1,8}$/", "");
|
||||
if ($group_id) {
|
||||
$group = group_by_id($group_id);
|
||||
if (!$group) {
|
||||
$group_id = "";
|
||||
} else {
|
||||
$group_name = get_group_name($group);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get operator code
|
||||
$operator_code = empty($_GET['operator_code'])
|
||||
? ''
|
||||
: $_GET['operator_code'];
|
||||
if (! preg_match("/^[A-z0-9_]+$/", $operator_code)) {
|
||||
$operator_code = false;
|
||||
}
|
||||
// Get operator code
|
||||
$operator_code = empty($_GET['operator_code']) ? '' : $_GET['operator_code'];
|
||||
if (!preg_match("/^[A-z0-9_]+$/", $operator_code)) {
|
||||
$operator_code = false;
|
||||
}
|
||||
|
||||
// Get visitor info
|
||||
$visitor = visitor_from_request();
|
||||
$info = getgetparam('info');
|
||||
$email = getgetparam('email');
|
||||
// Get visitor info
|
||||
$visitor = visitor_from_request();
|
||||
$info = get_get_param('info');
|
||||
$email = get_get_param('email');
|
||||
|
||||
// Get referrer
|
||||
$referrer = isset($_GET['url'])
|
||||
? $_GET['url']
|
||||
: (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : "");
|
||||
// Get referrer
|
||||
$referrer = isset($_GET['url'])
|
||||
? $_GET['url']
|
||||
: (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : "");
|
||||
|
||||
if(isset($_GET['referrer']) && $_GET['referrer']) {
|
||||
$referrer .= "\n".$_GET['referrer'];
|
||||
}
|
||||
if (isset($_GET['referrer']) && $_GET['referrer']) {
|
||||
$referrer .= "\n" . $_GET['referrer'];
|
||||
}
|
||||
|
||||
// Check if there are online operators
|
||||
if(!has_online_operators($groupid)) {
|
||||
// Display leave message page
|
||||
$page = array_merge_recursive(
|
||||
setup_logo($group),
|
||||
setup_leavemessage(
|
||||
$visitor['name'],
|
||||
$email,
|
||||
$groupid,
|
||||
$info,
|
||||
$referrer
|
||||
)
|
||||
);
|
||||
$page['leaveMessageOptions'] = json_encode($page['leaveMessage']);
|
||||
$chat_style->render('chat', $page);
|
||||
exit;
|
||||
}
|
||||
// Check if there are online operators
|
||||
if (!has_online_operators($group_id)) {
|
||||
// Display leave message page
|
||||
$page = array_merge_recursive(
|
||||
setup_logo($group),
|
||||
setup_leavemessage(
|
||||
$visitor['name'],
|
||||
$email,
|
||||
$group_id,
|
||||
$info,
|
||||
$referrer
|
||||
)
|
||||
);
|
||||
$page['leaveMessageOptions'] = json_encode($page['leaveMessage']);
|
||||
$chat_style->render('chat', $page);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Get invitation info
|
||||
if (Settings::get('enabletracking')) {
|
||||
$invitation_state = invitation_state($_SESSION['visitorid']);
|
||||
$visitor_is_invited = $invitation_state['invited'];
|
||||
} else {
|
||||
$visitor_is_invited = false;
|
||||
}
|
||||
// Get invitation info
|
||||
if (Settings::get('enabletracking')) {
|
||||
$invitation_state = invitation_state($_SESSION['visitorid']);
|
||||
$visitor_is_invited = $invitation_state['invited'];
|
||||
} else {
|
||||
$visitor_is_invited = false;
|
||||
}
|
||||
|
||||
// Get operator info
|
||||
$requested_operator = false;
|
||||
if ($operator_code) {
|
||||
$requested_operator = operator_by_code($operator_code);
|
||||
}
|
||||
// Get operator info
|
||||
$requested_operator = false;
|
||||
if ($operator_code) {
|
||||
$requested_operator = operator_by_code($operator_code);
|
||||
}
|
||||
|
||||
// Check if survey should be displayed
|
||||
if(Settings::get('enablepresurvey') == '1'
|
||||
&& !$visitor_is_invited
|
||||
&& !$requested_operator
|
||||
) {
|
||||
// Display prechat survey
|
||||
$page = array_merge_recursive(
|
||||
setup_logo($group),
|
||||
setup_survey($visitor['name'], $email, $groupid, $info, $referrer)
|
||||
);
|
||||
$page['surveyOptions'] = json_encode($page['survey']);
|
||||
$chat_style->render('chat', $page);
|
||||
exit;
|
||||
}
|
||||
// Check if survey should be displayed
|
||||
if (Settings::get('enablepresurvey') == '1' && !$visitor_is_invited && !$requested_operator) {
|
||||
// Display prechat survey
|
||||
$page = array_merge_recursive(
|
||||
setup_logo($group),
|
||||
setup_survey(
|
||||
$visitor['name'],
|
||||
$email,
|
||||
$group_id,
|
||||
$info,
|
||||
$referrer
|
||||
)
|
||||
);
|
||||
$page['surveyOptions'] = json_encode($page['survey']);
|
||||
$chat_style->render('chat', $page);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Start chat thread
|
||||
$thread = chat_start_for_user($groupid, $requested_operator, $visitor['id'], $visitor['name'], $referrer, $info);
|
||||
}
|
||||
$threadid = $thread->id;
|
||||
$token = $thread->lastToken;
|
||||
$chatstyle = verifyparam( "style", "/^\w+$/", "");
|
||||
header("Location: " . MIBEW_WEB_ROOT . "/client.php?thread=" . intval($threadid) . "&token=" . urlencode($token) . ($chatstyle ? "&style=" . urlencode($chatstyle) : ""));
|
||||
exit;
|
||||
// Start chat thread
|
||||
$thread = chat_start_for_user(
|
||||
$group_id,
|
||||
$requested_operator,
|
||||
$visitor['id'],
|
||||
$visitor['name'],
|
||||
$referrer,
|
||||
$info
|
||||
);
|
||||
}
|
||||
$thread_id = $thread->id;
|
||||
$token = $thread->lastToken;
|
||||
$chat_style_name = verify_param("style", "/^\w+$/", "");
|
||||
$redirect_to = MIBEW_WEB_ROOT . "/client.php?thread=" . intval($thread_id)
|
||||
. "&token=" . urlencode($token)
|
||||
. ($chat_style_name ? "&style=" . urlencode($chat_style_name) : "");
|
||||
header("Location: " . $redirect_to);
|
||||
exit;
|
||||
}
|
||||
|
||||
$token = verifyparam( "token", "/^\d{1,8}$/");
|
||||
$threadid = verifyparam( "thread", "/^\d{1,8}$/");
|
||||
$token = verify_param("token", "/^\d{1,8}$/");
|
||||
$thread_id = verify_param("thread", "/^\d{1,8}$/");
|
||||
|
||||
$thread = Thread::load($threadid, $token);
|
||||
if (! $thread) {
|
||||
die("wrong thread");
|
||||
$thread = Thread::load($thread_id, $token);
|
||||
if (!$thread) {
|
||||
die("wrong thread");
|
||||
}
|
||||
|
||||
$page = setup_chatview_for_user($thread);
|
||||
|
||||
if($action == "mailthread") {
|
||||
$chat_style->render('mail', $page);
|
||||
if ($action == "mailthread") {
|
||||
$chat_style->render('mail', $page);
|
||||
} else {
|
||||
// Build js application options
|
||||
$page['chatOptions'] = json_encode($page['chat']);
|
||||
// Expand page
|
||||
$chat_style->render('chat', $page);
|
||||
// Build js application options
|
||||
$page['chatOptions'] = json_encode($page['chat']);
|
||||
// Expand page
|
||||
$chat_style->render('chat', $page);
|
||||
}
|
||||
|
||||
?>
|
@ -20,16 +20,17 @@ use Mibew\EventDispatcher;
|
||||
use Mibew\Settings;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(dirname(__FILE__).'/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/track.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/statistics.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/cron.php');
|
||||
require_once(dirname(__FILE__) . '/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/track.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/chat.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/statistics.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/cron.php');
|
||||
|
||||
$cron_key = empty($_GET['cron_key']) ? '' : $_GET['cron_key'];
|
||||
|
||||
// Check cron security key
|
||||
if ($cron_key != Settings::get('cron_key')) {
|
||||
die();
|
||||
die();
|
||||
}
|
||||
|
||||
// Determine use or not quiet mode
|
||||
@ -50,9 +51,7 @@ $dispatcher->triggerEvent('cronRun');
|
||||
Settings::set('_last_cron_run', time());
|
||||
Settings::update();
|
||||
|
||||
if (! $quiet) {
|
||||
// TODO: May be localize it
|
||||
echo('All cron jobs done.');
|
||||
if (!$quiet) {
|
||||
// TODO: May be localize it
|
||||
echo('All cron jobs done.');
|
||||
}
|
||||
|
||||
?>
|
@ -16,6 +16,3 @@
|
||||
*/
|
||||
|
||||
header("Location: operator/index.php");
|
||||
exit;
|
||||
|
||||
?>
|
@ -36,6 +36,8 @@ define('MIBEW_WEB_ROOT', $mibewroot);
|
||||
|
||||
// Include common functions
|
||||
require_once(MIBEW_FS_ROOT.'/libs/common/constants.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/common/verification.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/common/converter.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/common/locale.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/common/misc.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/common/response.php');
|
||||
@ -48,7 +50,7 @@ function runsql($query, $link)
|
||||
return $res;
|
||||
}
|
||||
|
||||
$act = verifyparam("act", "/^(silentcreateall|createdb|ct|dt|addcolumns)$/");
|
||||
$act = verify_param("act", "/^(silentcreateall|createdb|ct|dt|addcolumns)$/");
|
||||
|
||||
$link = @mysql_connect($mysqlhost, $mysqllogin, $mysqlpass)
|
||||
or show_install_err('Could not connect: ' . mysql_error());
|
||||
|
@ -48,6 +48,8 @@ define('MIBEW_WEB_ROOT', $base_url);
|
||||
|
||||
// Include common functions
|
||||
require_once(MIBEW_FS_ROOT.'/libs/common/constants.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/common/verification.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/common/converter.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/common/locale.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/common/misc.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/common/response.php');
|
||||
@ -307,7 +309,7 @@ function add_canned_messages($link){
|
||||
foreach (get_available_locales() as $locale) {
|
||||
if (! in_array($locale, $existlocales)) {
|
||||
foreach (explode("\n", getstring_('chat.predefined_answers', $locale)) as $answer) {
|
||||
$result[] = array('locale' => $locale, 'vctitle' => cutstring($answer, 97, '...'), 'vcvalue' => $answer);
|
||||
$result[] = array('locale' => $locale, 'vctitle' => cut_string($answer, 97, '...'), 'vcvalue' => $answer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,56 +18,56 @@
|
||||
// Import namespaces and classes of the core
|
||||
use Mibew\Database;
|
||||
|
||||
function load_canned_messages($locale, $groupid)
|
||||
function load_canned_messages($locale, $group_id)
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$values = array(':locale' => $locale);
|
||||
if ($groupid) {
|
||||
$values[':groupid'] = $groupid;
|
||||
}
|
||||
return $db->query(
|
||||
"select id, vctitle, vcvalue from {chatresponses} " .
|
||||
"where locale = :locale AND (" .
|
||||
($groupid ? "groupid = :groupid" : "groupid is NULL OR groupid = 0") .
|
||||
") order by vcvalue",
|
||||
$values,
|
||||
array('return_rows' => Database::RETURN_ALL_ROWS)
|
||||
);
|
||||
$db = Database::getInstance();
|
||||
$values = array(':locale' => $locale);
|
||||
if ($group_id) {
|
||||
$values[':groupid'] = $group_id;
|
||||
}
|
||||
|
||||
return $db->query(
|
||||
("SELECT id, vctitle, vcvalue FROM {chatresponses} "
|
||||
. "WHERE locale = :locale AND ("
|
||||
. ($group_id ? "groupid = :groupid" : "groupid is NULL OR groupid = 0")
|
||||
. ") ORDER BY vcvalue"),
|
||||
$values,
|
||||
array('return_rows' => Database::RETURN_ALL_ROWS)
|
||||
);
|
||||
}
|
||||
|
||||
function load_canned_message($key)
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$result = $db->query(
|
||||
"select vctitle, vcvalue from {chatresponses} where id = ?",
|
||||
array($key),
|
||||
array('return_rows' => Database::RETURN_ONE_ROW)
|
||||
);
|
||||
return $result ? $result : null;
|
||||
$db = Database::getInstance();
|
||||
$result = $db->query(
|
||||
"SELECT vctitle, vcvalue FROM {chatresponses} WHERE id = ?",
|
||||
array($key),
|
||||
array('return_rows' => Database::RETURN_ONE_ROW)
|
||||
);
|
||||
|
||||
return $result ? $result : null;
|
||||
}
|
||||
|
||||
function save_canned_message($key, $title, $message)
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$db->query(
|
||||
"update {chatresponses} set vcvalue = ?, vctitle = ? where id = ?",
|
||||
array($message, $title, $key)
|
||||
);
|
||||
$db = Database::getInstance();
|
||||
$db->query(
|
||||
"UPDATE {chatresponses} SET vcvalue = ?, vctitle = ? WHERE id = ?",
|
||||
array($message, $title, $key)
|
||||
);
|
||||
}
|
||||
|
||||
function add_canned_message($locale, $groupid, $title, $message)
|
||||
function add_canned_message($locale, $group_id, $title, $message)
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$db->query(
|
||||
"insert into {chatresponses} (locale,groupid,vctitle,vcvalue) " .
|
||||
"values (?, ?, ?, ?)",
|
||||
array(
|
||||
$locale,
|
||||
($groupid ? $groupid : "null"),
|
||||
$title,
|
||||
$message
|
||||
)
|
||||
);
|
||||
$db = Database::getInstance();
|
||||
$db->query(
|
||||
("INSERT INTO {chatresponses} (locale,groupid,vctitle,vcvalue) "
|
||||
. "VALUES (?, ?, ?, ?)"),
|
||||
array(
|
||||
$locale,
|
||||
($group_id ? $group_id : "null"),
|
||||
$title,
|
||||
$message,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
?>
|
@ -17,59 +17,57 @@
|
||||
|
||||
function can_show_captcha()
|
||||
{
|
||||
return extension_loaded("gd");
|
||||
return extension_loaded("gd");
|
||||
}
|
||||
|
||||
function gen_captcha()
|
||||
{
|
||||
$symbols = 'abcdefghijkmnpqrstuvwxyz123456789';
|
||||
$string = '';
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$string .= substr($symbols, mt_rand(0, strlen($symbols)), 1);
|
||||
}
|
||||
return $string;
|
||||
$symbols = 'abcdefghijkmnpqrstuvwxyz123456789';
|
||||
$string = '';
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$string .= substr($symbols, mt_rand(0, strlen($symbols)), 1);
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
function draw_captcha($security_code)
|
||||
{
|
||||
//Set the image width and height
|
||||
$width = 100;
|
||||
$height = 25;
|
||||
|
||||
//Set the image width and height
|
||||
$width = 100;
|
||||
$height = 25;
|
||||
//Create the image resource
|
||||
$image = ImageCreate($width, $height);
|
||||
if (function_exists('imageantialias')) {
|
||||
imageantialias($image, true);
|
||||
}
|
||||
|
||||
//Create the image resource
|
||||
$image = ImageCreate($width, $height);
|
||||
if (function_exists('imageantialias')) {
|
||||
imageantialias($image, true);
|
||||
}
|
||||
//We are making three colors, white, black and gray
|
||||
$white = ImageColorAllocate($image, 255, 255, 255);
|
||||
$black = ImageColorAllocate($image, 15, 50, 15);
|
||||
$grey = ImageColorAllocate($image, 204, 204, 204);
|
||||
$ellipsec = ImageColorAllocate($image, 0, 100, 60);
|
||||
|
||||
//We are making three colors, white, black and gray
|
||||
$white = ImageColorAllocate($image, 255, 255, 255);
|
||||
$black = ImageColorAllocate($image, 15, 50, 15);
|
||||
$grey = ImageColorAllocate($image, 204, 204, 204);
|
||||
$ellipsec = ImageColorAllocate($image, 0, 100, 60);
|
||||
//Make the background black
|
||||
ImageFill($image, 0, 0, $black);
|
||||
imagefilledellipse($image, 56, 15, 30, 17, $ellipsec);
|
||||
|
||||
//Make the background black
|
||||
ImageFill($image, 0, 0, $black);
|
||||
imagefilledellipse($image, 56, 15, 30, 17, $ellipsec);
|
||||
//Add randomly generated string in white to the image
|
||||
ImageString($image, 5, 30, 4, $security_code, $white);
|
||||
|
||||
//Add randomly generated string in white to the image
|
||||
ImageString($image, 5, 30, 4, $security_code, $white);
|
||||
|
||||
//Throw in some lines to make it a little bit harder for any bots to break
|
||||
ImageRectangle($image, 0, 0, $width - 1, $height - 1, $grey);
|
||||
imageline($image, 0, $height / 2 + 3, $width, $height / 2 + 5, $grey);
|
||||
imageline($image, $width / 2 - 14, 0, $width / 2 + 7, $height, $grey);
|
||||
//Throw in some lines to make it a little bit harder for any bots to break
|
||||
ImageRectangle($image, 0, 0, $width - 1, $height - 1, $grey);
|
||||
imageline($image, 0, $height / 2 + 3, $width, $height / 2 + 5, $grey);
|
||||
imageline($image, $width / 2 - 14, 0, $width / 2 + 7, $height, $grey);
|
||||
|
||||
|
||||
//Tell the browser what kind of file is come in
|
||||
header("Content-Type: image/jpeg");
|
||||
//Tell the browser what kind of file is come in
|
||||
header("Content-Type: image/jpeg");
|
||||
|
||||
//Output the newly created image in jpeg format
|
||||
ImageJpeg($image);
|
||||
//Output the newly created image in jpeg format
|
||||
ImageJpeg($image);
|
||||
|
||||
//Free up resources
|
||||
ImageDestroy($image);
|
||||
//Free up resources
|
||||
ImageDestroy($image);
|
||||
}
|
||||
|
||||
?>
|
File diff suppressed because it is too large
Load Diff
@ -22,307 +22,319 @@ namespace Mibew\API;
|
||||
*
|
||||
* @todo May be use regular methods instead of static one
|
||||
*/
|
||||
class API {
|
||||
class API
|
||||
{
|
||||
/**
|
||||
* Version of the MIBEW API protocol implemented by the class
|
||||
*/
|
||||
const PROTOCOL_VERSION = '1.0';
|
||||
|
||||
/**
|
||||
* Version of the MIBEW API protocol implemented by the class
|
||||
*/
|
||||
const PROTOCOL_VERSION = '1.0';
|
||||
/**
|
||||
* Array of \Mibew\API\API objects
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $interactions = array();
|
||||
|
||||
/**
|
||||
* Array of \Mibew\API\API objects
|
||||
* @var array
|
||||
*/
|
||||
protected static $interactions = array();
|
||||
/**
|
||||
* An object that encapsulates type of the interaction
|
||||
*
|
||||
* @var \Mibew\API\Interaction
|
||||
*/
|
||||
protected $interaction = null;
|
||||
|
||||
/**
|
||||
* An object that encapsulates type of the interaction
|
||||
*
|
||||
* @var \Mibew\API\Interaction
|
||||
*/
|
||||
protected $interaction = NULL;
|
||||
/**
|
||||
* Returns \Mibew\API\API object
|
||||
*
|
||||
* @param string $class_name A name of the interaction type class
|
||||
* @return MibeAPI object
|
||||
* @throws \Mibew\API\APIException
|
||||
*/
|
||||
public static function getAPI($class_name)
|
||||
{
|
||||
if (!class_exists($class_name)) {
|
||||
throw new APIException(
|
||||
"Wrong interaction type",
|
||||
APIException::WRONG_INTERACTION_TYPE
|
||||
);
|
||||
}
|
||||
if (empty(self::$interactions[$class_name])) {
|
||||
self::$interactions[$class_name] = new self(new $class_name());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns \Mibew\API\API object
|
||||
*
|
||||
* @param string $class_name A name of the interaction type class
|
||||
* @return MibeAPI object
|
||||
* @throws \Mibew\API\APIException
|
||||
*/
|
||||
public static function getAPI($class_name) {
|
||||
if (! class_exists($class_name)) {
|
||||
throw new APIException(
|
||||
"Wrong interaction type",
|
||||
APIException::WRONG_INTERACTION_TYPE
|
||||
);
|
||||
}
|
||||
if (empty(self::$interactions[$class_name])) {
|
||||
self::$interactions[$class_name] = new self(new $class_name());
|
||||
}
|
||||
return self::$interactions[$class_name];
|
||||
}
|
||||
return self::$interactions[$class_name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param \Mibew\API\Interaction $interaction Interaction type object
|
||||
*/
|
||||
protected function __construct(Interaction\Interaction $interaction) {
|
||||
$this->interaction = $interaction;
|
||||
}
|
||||
/**
|
||||
* Validate package
|
||||
*
|
||||
* @param array $package Package array. See Mibew API for details.
|
||||
* @param array $trusted_signatures Array of trusted signatures.
|
||||
* @throws \Mibew\API\APIException
|
||||
*/
|
||||
public function checkPackage($package, $trusted_signatures)
|
||||
{
|
||||
// Check signature
|
||||
if (!isset($package['signature'])) {
|
||||
throw new APIException(
|
||||
"Package signature is empty",
|
||||
APIException::EMPTY_SIGNATURE
|
||||
);
|
||||
}
|
||||
if (!in_array($package['signature'], $trusted_signatures)) {
|
||||
throw new APIException(
|
||||
"Package signed with untrusted signature",
|
||||
APIException::UNTRUSTED_SIGNATURE
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate package
|
||||
*
|
||||
* @param array $package Package array. See Mibew API for details.
|
||||
* @param array $trusted_signatures Array of trusted signatures.
|
||||
* @throws \Mibew\API\APIException
|
||||
*/
|
||||
public function checkPackage($package, $trusted_signatures) {
|
||||
// Check signature
|
||||
if (! isset($package['signature'])) {
|
||||
throw new APIException(
|
||||
"Package signature is empty",
|
||||
APIException::EMPTY_SIGNATURE
|
||||
);
|
||||
}
|
||||
if (! in_array($package['signature'], $trusted_signatures)) {
|
||||
throw new APIException(
|
||||
"Package signed with untrusted signature",
|
||||
APIException::UNTRUSTED_SIGNATURE
|
||||
);
|
||||
}
|
||||
// Check protocol
|
||||
if (empty($package['proto'])) {
|
||||
throw new APIException(
|
||||
"Package protocol is empty",
|
||||
APIException::EMPTY_PROTOCOL
|
||||
);
|
||||
}
|
||||
if ($package['proto'] != self::PROTOCOL_VERSION) {
|
||||
throw new APIException(
|
||||
"Wrong package protocol version '{$package['proto']}'",
|
||||
APIException::WRONG_PROTOCOL_VERSION
|
||||
);
|
||||
}
|
||||
|
||||
// Check protocol
|
||||
if (empty($package['proto'])) {
|
||||
throw new APIException(
|
||||
"Package protocol is empty",
|
||||
APIException::EMPTY_PROTOCOL
|
||||
);
|
||||
}
|
||||
if ($package['proto'] != self::PROTOCOL_VERSION) {
|
||||
throw new APIException(
|
||||
"Wrong package protocol version '{$package['proto']}'",
|
||||
APIException::WRONG_PROTOCOL_VERSION
|
||||
);
|
||||
}
|
||||
// Check async flag
|
||||
if (!isset($package['async'])) {
|
||||
throw new APIException(
|
||||
"'async' flag is missed",
|
||||
APIException::ASYNC_FLAG_MISSED
|
||||
);
|
||||
}
|
||||
if (!is_bool($package['async'])) {
|
||||
throw new APIException(
|
||||
"Wrong 'async' flag value",
|
||||
APIException::WRONG_ASYNC_FLAG_VALUE
|
||||
);
|
||||
}
|
||||
|
||||
// Check async flag
|
||||
if (! isset($package['async'])) {
|
||||
throw new APIException(
|
||||
"'async' flag is missed",
|
||||
APIException::ASYNC_FLAG_MISSED
|
||||
);
|
||||
}
|
||||
if (! is_bool($package['async'])) {
|
||||
throw new APIException(
|
||||
"Wrong 'async' flag value",
|
||||
APIException::WRONG_ASYNC_FLAG_VALUE
|
||||
);
|
||||
}
|
||||
// Package must have at least one request
|
||||
if (empty($package['requests'])) {
|
||||
throw new APIException(
|
||||
"Empty requests set",
|
||||
APIException::EMPTY_REQUESTS
|
||||
);
|
||||
}
|
||||
// Check requests in package
|
||||
foreach ($package['requests'] as $request) {
|
||||
$this->checkRequest($request);
|
||||
}
|
||||
}
|
||||
|
||||
// Package must have at least one request
|
||||
if (empty($package['requests'])) {
|
||||
throw new APIException(
|
||||
"Empty requests set",
|
||||
APIException::EMPTY_REQUESTS
|
||||
);
|
||||
}
|
||||
// Check requests in package
|
||||
foreach ($package['requests'] as $request) {
|
||||
$this->checkRequest($request);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Validate request
|
||||
*
|
||||
* @param array $request Request array. See Mibew API for details.
|
||||
* @throws \Mibew\API\APIException
|
||||
*/
|
||||
public function checkRequest($request)
|
||||
{
|
||||
// Check token
|
||||
if (empty($request['token'])) {
|
||||
throw new APIException(
|
||||
"Empty request token",
|
||||
APIException::EMPTY_TOKEN
|
||||
);
|
||||
}
|
||||
// Request must have at least one function
|
||||
if (empty($request['functions'])) {
|
||||
throw new APIException(
|
||||
"Empty functions set",
|
||||
APIException::EMPTY_FUNCTIONS
|
||||
);
|
||||
}
|
||||
// Check functions in request
|
||||
foreach ($request['functions'] as $function) {
|
||||
$this->checkFunction($function);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate request
|
||||
*
|
||||
* @param array $request Request array. See Mibew API for details.
|
||||
* @throws \Mibew\API\APIException
|
||||
*/
|
||||
public function checkRequest($request) {
|
||||
// Check token
|
||||
if (empty($request['token'])) {
|
||||
throw new APIException(
|
||||
"Empty request token",
|
||||
APIException::EMPTY_TOKEN
|
||||
);
|
||||
}
|
||||
// Request must have at least one function
|
||||
if (empty($request['functions'])) {
|
||||
throw new APIException(
|
||||
"Empty functions set",
|
||||
APIException::EMPTY_FUNCTIONS
|
||||
);
|
||||
}
|
||||
// Check functions in request
|
||||
foreach ($request['functions'] as $function) {
|
||||
$this->checkFunction($function);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Validate function
|
||||
*
|
||||
* @param array $function Function array. See Mibew API for details.
|
||||
* @param boolean $filter_reserved_functions Determine if function name must
|
||||
* not be in reserved list
|
||||
* @throws \Mibew\API\APIException
|
||||
*/
|
||||
public function checkFunction($function, $filter_reserved_functions = false)
|
||||
{
|
||||
// Check function name
|
||||
if (empty($function['function'])) {
|
||||
throw new APIException(
|
||||
'Cannot call for function with empty name',
|
||||
APIException::EMPTY_FUNCTION_NAME
|
||||
);
|
||||
}
|
||||
if ($filter_reserved_functions) {
|
||||
if (in_array($function['function'], $this->interaction->reservedFunctionNames)) {
|
||||
throw new APIException(
|
||||
"'{$function['function']}' is reserved function name",
|
||||
APIException::FUNCTION_NAME_RESERVED
|
||||
);
|
||||
}
|
||||
}
|
||||
// Check function's arguments
|
||||
if (empty($function['arguments'])) {
|
||||
throw new APIException(
|
||||
"There are no arguments in '{$function['function']}' function",
|
||||
APIException::EMPTY_ARGUMENTS
|
||||
);
|
||||
}
|
||||
if (!is_array($function['arguments'])) {
|
||||
throw new APIException(
|
||||
"Arguments must be an array",
|
||||
APIException::WRONG_ARGUMENTS_TYPE
|
||||
);
|
||||
}
|
||||
$unset_arguments = array_diff(
|
||||
$this->interaction->getObligatoryArguments($function['function']),
|
||||
array_keys($function['arguments'])
|
||||
);
|
||||
if (!empty($unset_arguments)) {
|
||||
throw new APIException(
|
||||
"Arguments '" . implode("', '", $unset_arguments) . "' must be set",
|
||||
APIException::OBLIGATORY_ARGUMENTS_MISSED
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate function
|
||||
*
|
||||
* @param array $function Function array. See Mibew API for details.
|
||||
* @param boolean $filter_reserved_functions Determine if function name must not be in
|
||||
* reserved list
|
||||
* @throws \Mibew\API\APIException
|
||||
*/
|
||||
public function checkFunction($function, $filter_reserved_functions = false) {
|
||||
// Check function name
|
||||
if (empty($function['function'])) {
|
||||
throw new APIException(
|
||||
'Cannot call for function with empty name',
|
||||
APIException::EMPTY_FUNCTION_NAME
|
||||
);
|
||||
}
|
||||
if ($filter_reserved_functions) {
|
||||
if (in_array(
|
||||
$function['function'],
|
||||
$this->interaction->reservedFunctionNames
|
||||
)) {
|
||||
throw new APIException(
|
||||
"'{$function['function']}' is reserved function name",
|
||||
APIException::FUNCTION_NAME_RESERVED
|
||||
);
|
||||
}
|
||||
}
|
||||
// Check function's arguments
|
||||
if (empty($function['arguments'])) {
|
||||
throw new APIException(
|
||||
"There are no arguments in '{$function['function']}' function",
|
||||
APIException::EMPTY_ARGUMENTS
|
||||
);
|
||||
}
|
||||
if (! is_array($function['arguments'])) {
|
||||
throw new APIException(
|
||||
"Arguments must be an array",
|
||||
APIException::WRONG_ARGUMENTS_TYPE
|
||||
);
|
||||
}
|
||||
$unset_arguments = array_diff(
|
||||
$this->interaction->getObligatoryArguments($function['function']),
|
||||
array_keys($function['arguments'])
|
||||
);
|
||||
if (! empty($unset_arguments)) {
|
||||
throw new APIException(
|
||||
"Arguments '" . implode("', '", $unset_arguments) . "' must be set",
|
||||
APIException::OBLIGATORY_ARGUMENTS_MISSED
|
||||
);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Encodes package
|
||||
*
|
||||
* @param array $requests Requests array. See Mibew API for details.
|
||||
* @param string $signature Sender signature.
|
||||
* @param boolean $async true for asynchronous request and false for
|
||||
* synchronous request
|
||||
* @return string Ready for transfer encoded package
|
||||
*/
|
||||
public function encodePackage($requests, $signature, $async)
|
||||
{
|
||||
$package = array();
|
||||
$package['signature'] = $signature;
|
||||
$package['proto'] = self::PROTOCOL_VERSION;
|
||||
$package['async'] = $async;
|
||||
$package['requests'] = $requests;
|
||||
|
||||
/**
|
||||
* Encodes package
|
||||
*
|
||||
* @param array $requests Requests array. See Mibew API for details.
|
||||
* @param string $signature Sender signature.
|
||||
* @param boolean $async true for asynchronous request and false for synchronous request
|
||||
* @return string Ready for transfer encoded package
|
||||
*/
|
||||
public function encodePackage($requests, $signature, $async) {
|
||||
$package = array();
|
||||
$package['signature'] = $signature;
|
||||
$package['proto'] = self::PROTOCOL_VERSION;
|
||||
$package['async'] = $async;
|
||||
$package['requests'] = $requests;
|
||||
return urlencode(json_encode($package));
|
||||
}
|
||||
return urlencode(json_encode($package));
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes package and validate package structure
|
||||
*
|
||||
* @param string $package Encoded package
|
||||
* @param array $trusted_signatures List of trusted signatures
|
||||
* @return array Decoded package array. See Mibew API for details.
|
||||
* @throws \Mibew\API\APIException
|
||||
*/
|
||||
public function decodePackage($package, $trusted_signatures) {
|
||||
// Try to decode package
|
||||
$decoded_package = urldecode($package);
|
||||
$decoded_package = json_decode($decoded_package, true);
|
||||
/**
|
||||
* Decodes package and validate package structure
|
||||
*
|
||||
* @param string $package Encoded package
|
||||
* @param array $trusted_signatures List of trusted signatures
|
||||
* @return array Decoded package array. See Mibew API for details.
|
||||
* @throws \Mibew\API\APIException
|
||||
*/
|
||||
public function decodePackage($package, $trusted_signatures)
|
||||
{
|
||||
// Try to decode package
|
||||
$decoded_package = urldecode($package);
|
||||
$decoded_package = json_decode($decoded_package, true);
|
||||
|
||||
// Check package
|
||||
$json_error_code = json_last_error();
|
||||
if ($json_error_code != JSON_ERROR_NONE) {
|
||||
// Not valid JSON
|
||||
throw new APIException(
|
||||
"Package have invalid json structure. " .
|
||||
"JSON error code is '" . $json_error_code . "'",
|
||||
APIException::NOT_VALID_JSON
|
||||
);
|
||||
}
|
||||
$this->checkPackage($decoded_package, $trusted_signatures);
|
||||
// Check package
|
||||
$json_error_code = json_last_error();
|
||||
if ($json_error_code != JSON_ERROR_NONE) {
|
||||
// Not valid JSON
|
||||
throw new APIException(
|
||||
"Package have invalid json structure. JSON error code is '" . $json_error_code . "'",
|
||||
APIException::NOT_VALID_JSON
|
||||
);
|
||||
}
|
||||
$this->checkPackage($decoded_package, $trusted_signatures);
|
||||
|
||||
return $decoded_package;
|
||||
}
|
||||
return $decoded_package;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds result package
|
||||
*
|
||||
* @param string $token Token of the result package
|
||||
* @param array $result_arguments Arguments of result function
|
||||
* @return array Result package
|
||||
*/
|
||||
public function buildResult($token, $result_arguments) {
|
||||
$arguments = $result_arguments + $this->interaction->getObligatoryArgumentsDefaults('result');
|
||||
$package = array(
|
||||
'token' => $token,
|
||||
'functions' => array(
|
||||
array(
|
||||
'function' => 'result',
|
||||
'arguments' => $arguments
|
||||
)
|
||||
)
|
||||
);
|
||||
return $package;
|
||||
}
|
||||
/**
|
||||
* Builds result package
|
||||
*
|
||||
* @param string $token Token of the result package
|
||||
* @param array $result_arguments Arguments of result function
|
||||
* @return array Result package
|
||||
*/
|
||||
public function buildResult($token, $result_arguments)
|
||||
{
|
||||
$arguments = $result_arguments + $this->interaction->getObligatoryArgumentsDefaults('result');
|
||||
$package = array(
|
||||
'token' => $token,
|
||||
'functions' => array(
|
||||
array(
|
||||
'function' => 'result',
|
||||
'arguments' => $arguments,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Search 'result' function in $function_list. If request contains more than one result
|
||||
* functions throws an \Mibew\API\APIException
|
||||
*
|
||||
* @param array $functions_list Array of functions. See Mibew API specification
|
||||
* for function structure details
|
||||
* @param mixed $existance Control existance of the 'result' function in request.
|
||||
* Use boolean true if 'result' function must exists in request, boolean false if must not
|
||||
* and null if it doesn't matter.
|
||||
* @return mixed Function array if 'result' function found and NULL otherwise
|
||||
* @throws \Mibew\API\APIException
|
||||
*/
|
||||
public function getResultFunction ($functions_list, $existence = null) {
|
||||
$result_function = null;
|
||||
// Try to find 'result' function
|
||||
foreach ($functions_list as $function) {
|
||||
if ($function['function'] == 'result') {
|
||||
if (! is_null($result_function)) {
|
||||
// Another 'result' function found
|
||||
throw new APIException(
|
||||
"Function 'result' already exists in request",
|
||||
APIException::RESULT_FUNCTION_ALREADY_EXISTS
|
||||
);
|
||||
}
|
||||
// First 'result' function found
|
||||
$result_function = $function;
|
||||
}
|
||||
}
|
||||
if ($existence === true && is_null($result_function)) {
|
||||
// 'result' function must present in request
|
||||
throw new APIException(
|
||||
"There is no 'result' function in request",
|
||||
APIException::NO_RESULT_FUNCTION
|
||||
);
|
||||
}
|
||||
if ($existence === false && !is_null($result_function)) {
|
||||
// 'result' function must not present in request
|
||||
throw new APIException(
|
||||
"There is 'result' function in request",
|
||||
APIException::RESULT_FUNCTION_EXISTS
|
||||
);
|
||||
}
|
||||
return $result_function;
|
||||
}
|
||||
return $package;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search 'result' function in $function_list.
|
||||
*
|
||||
* If request contains more than one result the functions throws
|
||||
* an \Mibew\API\APIException.
|
||||
*
|
||||
* @param array $functions_list Array of functions. See Mibew API
|
||||
* specification for function structure details.
|
||||
* @param mixed $existance Control existance of the 'result' function in
|
||||
* request. Use boolean true if 'result' function must exists in request,
|
||||
* boolean false if must not and null if it doesn't matter.
|
||||
* @return mixed Function array if 'result' function found and NULL
|
||||
* otherwise
|
||||
* @throws \Mibew\API\APIException
|
||||
*/
|
||||
public function getResultFunction($functions_list, $existence = null)
|
||||
{
|
||||
$result_function = null;
|
||||
// Try to find 'result' function
|
||||
foreach ($functions_list as $function) {
|
||||
if ($function['function'] == 'result') {
|
||||
if (!is_null($result_function)) {
|
||||
// Another 'result' function found
|
||||
throw new APIException(
|
||||
"Function 'result' already exists in request",
|
||||
APIException::RESULT_FUNCTION_ALREADY_EXISTS
|
||||
);
|
||||
}
|
||||
// First 'result' function found
|
||||
$result_function = $function;
|
||||
}
|
||||
}
|
||||
if ($existence === true && is_null($result_function)) {
|
||||
// 'result' function must present in request
|
||||
throw new APIException(
|
||||
"There is no 'result' function in request",
|
||||
APIException::NO_RESULT_FUNCTION
|
||||
);
|
||||
}
|
||||
if ($existence === false && !is_null($result_function)) {
|
||||
// 'result' function must not present in request
|
||||
throw new APIException(
|
||||
"There is 'result' function in request",
|
||||
APIException::RESULT_FUNCTION_EXISTS
|
||||
);
|
||||
}
|
||||
|
||||
return $result_function;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param \Mibew\API\Interaction $interaction Interaction type object
|
||||
*/
|
||||
protected function __construct(Interaction\Interaction $interaction)
|
||||
{
|
||||
$this->interaction = $interaction;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -20,99 +20,98 @@ namespace Mibew\API;
|
||||
/**
|
||||
* Mibew API Exception class.
|
||||
*/
|
||||
class APIException extends \Exception {
|
||||
/**
|
||||
* Async flag is missed.
|
||||
*/
|
||||
const ASYNC_FLAG_MISSED = 1;
|
||||
/**
|
||||
* There are no arguments in function
|
||||
*/
|
||||
const EMPTY_ARGUMENTS = 2;
|
||||
/**
|
||||
* Cannot call for function with empty name
|
||||
*/
|
||||
const EMPTY_FUNCTION_NAME = 3;
|
||||
/**
|
||||
* Functions set is empty
|
||||
*/
|
||||
const EMPTY_FUNCTIONS = 4;
|
||||
/**
|
||||
* Package protocol is empty
|
||||
*/
|
||||
const EMPTY_PROTOCOL = 5;
|
||||
/**
|
||||
* Requests set is empty
|
||||
*/
|
||||
const EMPTY_REQUESTS = 6;
|
||||
/**
|
||||
* Package signature is empty
|
||||
*/
|
||||
const EMPTY_SIGNATURE = 7;
|
||||
/**
|
||||
* Request token is empty
|
||||
*/
|
||||
const EMPTY_TOKEN = 8;
|
||||
/**
|
||||
* Wrong reference. Reference variable is empty
|
||||
*/
|
||||
const EMPTY_VARIABLE_IN_REFERENCE = 9;
|
||||
/**
|
||||
* This function name is reserved
|
||||
*/
|
||||
const FUNCTION_NAME_RESERVED = 10;
|
||||
/**
|
||||
* There is no result function
|
||||
*/
|
||||
const NO_RESULT_FUNCTION = 11;
|
||||
/**
|
||||
* Package have not valid JSON structure
|
||||
*/
|
||||
const NOT_VALID_JSON = 12;
|
||||
/**
|
||||
* Some of the function's obligatory arguments are missed
|
||||
*/
|
||||
const OBLIGATORY_ARGUMENTS_MISSED = 13;
|
||||
/**
|
||||
* Request contains more than one result functions
|
||||
*/
|
||||
const RESULT_FUNCTION_ALREADY_EXISTS = 14;
|
||||
/**
|
||||
* There is 'result' function in request
|
||||
*/
|
||||
const RESULT_FUNCTION_EXISTS = 15;
|
||||
/**
|
||||
* Package signed with untrusted signature
|
||||
*/
|
||||
const UNTRUSTED_SIGNATURE = 16;
|
||||
/**
|
||||
* Wrong reference. Variable is undefined in functions results
|
||||
*/
|
||||
const VARIABLE_IS_UNDEFINED_IN_REFERENCE = 17;
|
||||
/**
|
||||
* Variable is undefined in function's results
|
||||
*/
|
||||
const VARIABLE_IS_UNDEFINED_IN_RESULT = 18;
|
||||
/**
|
||||
* Arguments must be an array
|
||||
*/
|
||||
const WRONG_ARGUMENTS_TYPE = 19;
|
||||
/**
|
||||
* Async flag value is wrong
|
||||
*/
|
||||
const WRONG_ASYNC_FLAG_VALUE = 20;
|
||||
/**
|
||||
* Wrong reference. Function with this number does not call yet
|
||||
*/
|
||||
const WRONG_FUNCTION_NUM_IN_REFERENCE = 21;
|
||||
/**
|
||||
* Wrong interaction type
|
||||
*/
|
||||
const WRONG_INTERACTION_TYPE = 22;
|
||||
/**
|
||||
* Wrong package protocol version
|
||||
*/
|
||||
const WRONG_PROTOCOL_VERSION = 23;
|
||||
class APIException extends \Exception
|
||||
{
|
||||
/**
|
||||
* Async flag is missed.
|
||||
*/
|
||||
const ASYNC_FLAG_MISSED = 1;
|
||||
/**
|
||||
* There are no arguments in function
|
||||
*/
|
||||
const EMPTY_ARGUMENTS = 2;
|
||||
/**
|
||||
* Cannot call for function with empty name
|
||||
*/
|
||||
const EMPTY_FUNCTION_NAME = 3;
|
||||
/**
|
||||
* Functions set is empty
|
||||
*/
|
||||
const EMPTY_FUNCTIONS = 4;
|
||||
/**
|
||||
* Package protocol is empty
|
||||
*/
|
||||
const EMPTY_PROTOCOL = 5;
|
||||
/**
|
||||
* Requests set is empty
|
||||
*/
|
||||
const EMPTY_REQUESTS = 6;
|
||||
/**
|
||||
* Package signature is empty
|
||||
*/
|
||||
const EMPTY_SIGNATURE = 7;
|
||||
/**
|
||||
* Request token is empty
|
||||
*/
|
||||
const EMPTY_TOKEN = 8;
|
||||
/**
|
||||
* Wrong reference. Reference variable is empty
|
||||
*/
|
||||
const EMPTY_VARIABLE_IN_REFERENCE = 9;
|
||||
/**
|
||||
* This function name is reserved
|
||||
*/
|
||||
const FUNCTION_NAME_RESERVED = 10;
|
||||
/**
|
||||
* There is no result function
|
||||
*/
|
||||
const NO_RESULT_FUNCTION = 11;
|
||||
/**
|
||||
* Package have not valid JSON structure
|
||||
*/
|
||||
const NOT_VALID_JSON = 12;
|
||||
/**
|
||||
* Some of the function's obligatory arguments are missed
|
||||
*/
|
||||
const OBLIGATORY_ARGUMENTS_MISSED = 13;
|
||||
/**
|
||||
* Request contains more than one result functions
|
||||
*/
|
||||
const RESULT_FUNCTION_ALREADY_EXISTS = 14;
|
||||
/**
|
||||
* There is 'result' function in request
|
||||
*/
|
||||
const RESULT_FUNCTION_EXISTS = 15;
|
||||
/**
|
||||
* Package signed with untrusted signature
|
||||
*/
|
||||
const UNTRUSTED_SIGNATURE = 16;
|
||||
/**
|
||||
* Wrong reference. Variable is undefined in functions results
|
||||
*/
|
||||
const VARIABLE_IS_UNDEFINED_IN_REFERENCE = 17;
|
||||
/**
|
||||
* Variable is undefined in function's results
|
||||
*/
|
||||
const VARIABLE_IS_UNDEFINED_IN_RESULT = 18;
|
||||
/**
|
||||
* Arguments must be an array
|
||||
*/
|
||||
const WRONG_ARGUMENTS_TYPE = 19;
|
||||
/**
|
||||
* Async flag value is wrong
|
||||
*/
|
||||
const WRONG_ASYNC_FLAG_VALUE = 20;
|
||||
/**
|
||||
* Wrong reference. Function with this number does not call yet
|
||||
*/
|
||||
const WRONG_FUNCTION_NUM_IN_REFERENCE = 21;
|
||||
/**
|
||||
* Wrong interaction type
|
||||
*/
|
||||
const WRONG_INTERACTION_TYPE = 22;
|
||||
/**
|
||||
* Wrong package protocol version
|
||||
*/
|
||||
const WRONG_PROTOCOL_VERSION = 23;
|
||||
}
|
||||
|
||||
?>
|
@ -20,113 +20,137 @@ namespace Mibew\API;
|
||||
/**
|
||||
* Implements functions execution context
|
||||
*/
|
||||
class ExecutionContext {
|
||||
/**
|
||||
* Values which returns after execution of all functions in request
|
||||
* @var array
|
||||
*/
|
||||
protected $return = array();
|
||||
class ExecutionContext
|
||||
{
|
||||
/**
|
||||
* Values which returns after execution of all functions in request
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $return = array();
|
||||
|
||||
/**
|
||||
* Results of execution of all function in request
|
||||
* @var array
|
||||
*/
|
||||
protected $functions_results = array();
|
||||
/**
|
||||
* Results of execution of all function in request
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $functionsResults = array();
|
||||
|
||||
/**
|
||||
* Returns requets results
|
||||
*
|
||||
* @return array Request results
|
||||
* @see \Mibew\API\ExecutionContext::$return
|
||||
*/
|
||||
public function getResults () {
|
||||
return $this->return;
|
||||
}
|
||||
/**
|
||||
* Returns requets results
|
||||
*
|
||||
* @return array Request results
|
||||
* @see \Mibew\API\ExecutionContext::$return
|
||||
*/
|
||||
public function getResults()
|
||||
{
|
||||
return $this->return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build arguments list by replace all references by values of execution context
|
||||
*
|
||||
* @param array $function Function array. See MibewAPI for details.
|
||||
* @return array Arguments list
|
||||
* @throws \Mibew\API\APIException
|
||||
*/
|
||||
public function getArgumentsList ($function) {
|
||||
$arguments = $function['arguments'];
|
||||
$references = $function['arguments']['references'];
|
||||
foreach ($references as $variable => $func_num) {
|
||||
// Check target function in context
|
||||
if (! isset($this->functions_results[$func_num - 1])) {
|
||||
// Wrong function num
|
||||
throw new APIException(
|
||||
"Wrong reference in '{$function['function']}' function. " .
|
||||
"Function #{$func_num} does not call yet.",
|
||||
APIException::WRONG_FUNCTION_NUM_IN_REFERENCE
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Build arguments list by replace all references by values of execution
|
||||
* context.
|
||||
*
|
||||
* @param array $function Function array. See MibewAPI for details.
|
||||
* @return array Arguments list
|
||||
* @throws \Mibew\API\APIException
|
||||
*/
|
||||
public function getArgumentsList($function)
|
||||
{
|
||||
$arguments = $function['arguments'];
|
||||
$references = $function['arguments']['references'];
|
||||
foreach ($references as $variable => $func_num) {
|
||||
// Check target function in context
|
||||
if (!isset($this->functionsResults[$func_num - 1])) {
|
||||
// Wrong function num
|
||||
$message = "Wrong reference in '%s' function. "
|
||||
. "Function #%s does not call yet.";
|
||||
throw new APIException(
|
||||
sprintf(
|
||||
$message,
|
||||
$function['function'],
|
||||
$func_num
|
||||
),
|
||||
APIException::WRONG_FUNCTION_NUM_IN_REFERENCE
|
||||
);
|
||||
}
|
||||
|
||||
// Check reference
|
||||
if (empty($arguments[$variable])) {
|
||||
// Empty argument that should contains reference
|
||||
throw new APIException(
|
||||
"Wrong reference in '{$function['function']}' function. " .
|
||||
"Empty {$variable} argument.",
|
||||
APIException::EMPTY_VARIABLE_IN_REFERENCE
|
||||
);
|
||||
}
|
||||
$reference_to = $arguments[$variable];
|
||||
// Check reference
|
||||
if (empty($arguments[$variable])) {
|
||||
// Empty argument that should contains reference
|
||||
throw new APIException(
|
||||
sprintf(
|
||||
"Wrong reference in '%s' function. Empty %s argument.",
|
||||
$function['function'],
|
||||
$variable
|
||||
),
|
||||
APIException::EMPTY_VARIABLE_IN_REFERENCE
|
||||
);
|
||||
}
|
||||
$reference_to = $arguments[$variable];
|
||||
|
||||
// Check target value
|
||||
if (! isset($this->functions_results[$func_num - 1][$reference_to])) {
|
||||
// Undefined target value
|
||||
throw new APIException(
|
||||
"Wrong reference in '{$function['function']}' function. " .
|
||||
"There is no '{$reference_to}' argument in #{$func_num} " .
|
||||
"function results",
|
||||
APIException::VARIABLE_IS_UNDEFINED_IN_REFERENCE
|
||||
);
|
||||
}
|
||||
// Check target value
|
||||
if (!isset($this->functionsResults[$func_num - 1][$reference_to])) {
|
||||
// Undefined target value
|
||||
$message = "Wrong reference in '%s' function. "
|
||||
. "There is no '%s' argument in #%s function results";
|
||||
throw new APIException(
|
||||
sprintf(
|
||||
$message,
|
||||
$function['function'],
|
||||
$reference_to,
|
||||
$func_num
|
||||
),
|
||||
APIException::VARIABLE_IS_UNDEFINED_IN_REFERENCE
|
||||
);
|
||||
}
|
||||
|
||||
// Replace reference by target value
|
||||
$arguments[$variable] = $this->functions_results[$func_num - 1][$reference_to];
|
||||
}
|
||||
return $arguments;
|
||||
}
|
||||
// Replace reference by target value
|
||||
$arguments[$variable] = $this->functionsResults[$func_num - 1][$reference_to];
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores functions results in execution context and add values to request result
|
||||
*
|
||||
* @param array $function Function array. See MibewAPI for details.
|
||||
* @param array $results Associative array of the function results.
|
||||
* @throws \Mibew\API\APIException
|
||||
*/
|
||||
public function storeFunctionResults ($function, $results) {
|
||||
// Check if function return correct results
|
||||
if (empty($results['errorCode'])) {
|
||||
// Add value to request results
|
||||
foreach ($function['arguments']['return'] as $name => $alias) {
|
||||
if (! isset($results[$name])) {
|
||||
// Value that defined in 'return' argument is undefined
|
||||
throw new APIException(
|
||||
"Variable with name '{$name}' is undefined in the " .
|
||||
"results of the '{$function['function']}' function",
|
||||
APIException::VARIABLE_IS_UNDEFINED_IN_RESULT
|
||||
);
|
||||
}
|
||||
$this->return[$alias] = $results[$name];
|
||||
}
|
||||
} else {
|
||||
// Something went wrong during function execution
|
||||
// Store error code and error message
|
||||
$this->return['errorCode'] = $results['errorCode'];
|
||||
$this->return['errorMessage'] = empty($results['errorMessage'])
|
||||
? ''
|
||||
: $results['errorMessage'];
|
||||
}
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
// Store function results in execution context
|
||||
$this->functions_results[] = $results;
|
||||
}
|
||||
/**
|
||||
* Stores functions results in execution context and add values to request
|
||||
* result.
|
||||
*
|
||||
* @param array $function Function array. See MibewAPI for details.
|
||||
* @param array $results Associative array of the function results.
|
||||
* @throws \Mibew\API\APIException
|
||||
*/
|
||||
public function storeFunctionResults($function, $results)
|
||||
{
|
||||
// Check if function return correct results
|
||||
if (empty($results['errorCode'])) {
|
||||
// Add value to request results
|
||||
foreach ($function['arguments']['return'] as $name => $alias) {
|
||||
if (!isset($results[$name])) {
|
||||
// Value that defined in 'return' argument is undefined
|
||||
$message = "Variable with name '%s' is undefined "
|
||||
. "in the results of the '%s' function";
|
||||
throw new APIException(
|
||||
sprintf(
|
||||
$message,
|
||||
$name,
|
||||
$function['function']
|
||||
),
|
||||
APIException::VARIABLE_IS_UNDEFINED_IN_RESULT
|
||||
);
|
||||
}
|
||||
$this->return[$alias] = $results[$name];
|
||||
}
|
||||
} else {
|
||||
// Something went wrong during function execution
|
||||
// Store error code and error message
|
||||
$this->return['errorCode'] = $results['errorCode'];
|
||||
$this->return['errorMessage'] = empty($results['errorMessage'])
|
||||
? ''
|
||||
: $results['errorMessage'];
|
||||
}
|
||||
|
||||
// Store function results in execution context
|
||||
$this->functionsResults[] = $results;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -20,32 +20,31 @@ namespace Mibew\API\Interaction;
|
||||
/**
|
||||
* Implements Mibew Core - Mibew Chat Window interaction
|
||||
*/
|
||||
class ChatInteraction extends Interaction {
|
||||
/**
|
||||
* Defines obligatory arguments and default values for them
|
||||
* @var array
|
||||
* @see \Mibew\API\Interaction\Interaction::$obligatoryArgumnents
|
||||
*/
|
||||
protected $obligatoryArguments = array(
|
||||
'*' => array(
|
||||
'threadId' => null,
|
||||
'token' => null,
|
||||
'references' => array(),
|
||||
'return' => array()
|
||||
),
|
||||
'result' => array(
|
||||
'errorCode' => 0
|
||||
)
|
||||
);
|
||||
class ChatInteraction extends Interaction
|
||||
{
|
||||
/**
|
||||
* Reserved function's names
|
||||
* @var array
|
||||
* @see \Mibew\API\Interaction\Interaction::$reservedFunctionNames
|
||||
*/
|
||||
public $reservedFunctionNames = array(
|
||||
'result',
|
||||
);
|
||||
|
||||
/**
|
||||
* Reserved function's names
|
||||
* @var array
|
||||
* @see \Mibew\API\Interaction\Interaction::$reservedFunctionNames
|
||||
*/
|
||||
public $reservedFunctionNames = array(
|
||||
'result'
|
||||
);
|
||||
/**
|
||||
* Defines obligatory arguments and default values for them
|
||||
* @var array
|
||||
* @see \Mibew\API\Interaction\Interaction::$obligatoryArgumnents
|
||||
*/
|
||||
protected $obligatoryArguments = array(
|
||||
'*' => array(
|
||||
'threadId' => null,
|
||||
'token' => null,
|
||||
'references' => array(),
|
||||
'return' => array(),
|
||||
),
|
||||
'result' => array(
|
||||
'errorCode' => 0,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
?>
|
@ -20,80 +20,94 @@ namespace Mibew\API\Interaction;
|
||||
/**
|
||||
* Encapsulates interaction type
|
||||
*/
|
||||
abstract class Interaction {
|
||||
/**
|
||||
* Defines obligatory arguments and default values for them
|
||||
*
|
||||
* @var array Keys of the array are function names ('*' for all functions). Values are arrays of obligatory
|
||||
* arguments with key for name of an argument and value for default value.
|
||||
*
|
||||
* For example:
|
||||
* <code>
|
||||
* protected $obligatoryArguments = array(
|
||||
* '*' => array( // Obligatory arguments for all functions are
|
||||
* 'return' => array(), // 'return' with array() by default and
|
||||
* 'references' => array() // 'references' with array() by default
|
||||
* ),
|
||||
* 'result' => array( // There is an additional argument for the result function
|
||||
* 'errorCode' => 0 // This is 'error_code' with 0 by default
|
||||
* )
|
||||
* );
|
||||
* </code>
|
||||
*/
|
||||
protected $obligatoryArguments = array();
|
||||
abstract class Interaction
|
||||
{
|
||||
/**
|
||||
* Reserved function's names
|
||||
*
|
||||
* Defines reserved(system) function's names described in the Mibew API.
|
||||
* @var array
|
||||
*/
|
||||
public $reservedFunctionNames = array();
|
||||
|
||||
/**
|
||||
* Reserved function's names
|
||||
*
|
||||
* Defines reserved(system) function's names described in the Mibew API.
|
||||
* @var array
|
||||
*/
|
||||
public $reservedFunctionNames = array();
|
||||
/**
|
||||
* Defines obligatory arguments and default values for them
|
||||
*
|
||||
* @var array Keys of the array are function names ('*' for all functions).
|
||||
* Values are arrays of obligatory arguments with key for name of an
|
||||
* argument and value for default value.
|
||||
*
|
||||
* For example:
|
||||
* <code>
|
||||
* protected $obligatoryArguments = array(
|
||||
* '*' => array(
|
||||
* // Obligatory arguments for all functions are:
|
||||
* 'return' => array(), // 'return' with array() by default and
|
||||
* 'references' => array() // 'references' with array() by default
|
||||
* ),
|
||||
*
|
||||
* 'result' => array(
|
||||
* // There is an additional argument for the result function
|
||||
* 'errorCode' => 0 // This is 'error_code' with 0 by default
|
||||
* )
|
||||
* );
|
||||
* </code>
|
||||
*/
|
||||
protected $obligatoryArguments = array();
|
||||
|
||||
/**
|
||||
* Returns obligatory arguments for the $function_name function
|
||||
*
|
||||
* @param string $function_name Function name
|
||||
* @return array An array of obligatory arguments
|
||||
*/
|
||||
public function getObligatoryArguments($function_name) {
|
||||
$obligatory_arguments = array();
|
||||
// Add obligatory for all functions arguments
|
||||
if (! empty($this->obligatoryArguments['*'])) {
|
||||
$obligatory_arguments = array_merge(
|
||||
$obligatory_arguments,
|
||||
array_keys($this->obligatoryArguments['*'])
|
||||
);
|
||||
}
|
||||
// Add obligatory arguments for given function
|
||||
if (! empty($this->obligatoryArguments[$function_name])) {
|
||||
$obligatory_arguments = array_merge(
|
||||
$obligatory_arguments,
|
||||
array_keys($this->obligatoryArguments[$function_name])
|
||||
);
|
||||
}
|
||||
return array_unique($obligatory_arguments);
|
||||
}
|
||||
/**
|
||||
* Returns obligatory arguments for the $function_name function
|
||||
*
|
||||
* @param string $function_name Function name
|
||||
* @return array An array of obligatory arguments
|
||||
*/
|
||||
public function getObligatoryArguments($function_name)
|
||||
{
|
||||
$obligatory_arguments = array();
|
||||
// Add obligatory for all functions arguments
|
||||
if (!empty($this->obligatoryArguments['*'])) {
|
||||
$obligatory_arguments = array_merge(
|
||||
$obligatory_arguments,
|
||||
array_keys($this->obligatoryArguments['*'])
|
||||
);
|
||||
}
|
||||
// Add obligatory arguments for given function
|
||||
if (!empty($this->obligatoryArguments[$function_name])) {
|
||||
$obligatory_arguments = array_merge(
|
||||
$obligatory_arguments,
|
||||
array_keys($this->obligatoryArguments[$function_name])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns default values of obligatory arguments for the $function_name function
|
||||
*
|
||||
* @param string $function_name Function name
|
||||
* @return array Associative array with keys are obligatory arguments and values are default
|
||||
* values of them
|
||||
*/
|
||||
public function getObligatoryArgumentsDefaults($function_name) {
|
||||
$obligatory_arguments = array();
|
||||
// Add obligatory for all functions arguments
|
||||
if (! empty($this->obligatoryArguments['*'])) {
|
||||
$obligatory_arguments = array_merge($obligatory_arguments, $this->obligatoryArguments['*']);
|
||||
}
|
||||
// Add obligatory arguments for given function
|
||||
if (! empty($this->obligatoryArguments[$function_name])) {
|
||||
$obligatory_arguments = array_merge($obligatory_arguments, $this->obligatoryArguments[$function_name]);
|
||||
}
|
||||
return $obligatory_arguments;
|
||||
}
|
||||
return array_unique($obligatory_arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns default values of obligatory arguments for the $function_name
|
||||
* function
|
||||
*
|
||||
* @param string $function_name Function name
|
||||
* @return array Associative array with keys are obligatory arguments and
|
||||
* values are default values of them
|
||||
*/
|
||||
public function getObligatoryArgumentsDefaults($function_name)
|
||||
{
|
||||
$obligatory_arguments = array();
|
||||
// Add obligatory for all functions arguments
|
||||
if (!empty($this->obligatoryArguments['*'])) {
|
||||
$obligatory_arguments = array_merge(
|
||||
$obligatory_arguments,
|
||||
$this->obligatoryArguments['*']
|
||||
);
|
||||
}
|
||||
// Add obligatory arguments for given function
|
||||
if (!empty($this->obligatoryArguments[$function_name])) {
|
||||
$obligatory_arguments = array_merge(
|
||||
$obligatory_arguments,
|
||||
$this->obligatoryArguments[$function_name]
|
||||
);
|
||||
}
|
||||
|
||||
return $obligatory_arguments;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -20,31 +20,30 @@ namespace Mibew\API\Interaction;
|
||||
/**
|
||||
* Implements Mibew Core - Mibew invitation waiting window interaction
|
||||
*/
|
||||
class InviteInteraction extends Interaction {
|
||||
/**
|
||||
* Defines obligatory arguments and default values for them
|
||||
* @var array
|
||||
* @see \Mibew\API\Interaction\Interaction::$obligatoryArgumnents
|
||||
*/
|
||||
protected $obligatoryArguments = array(
|
||||
'*' => array(
|
||||
'references' => array(),
|
||||
'return' => array(),
|
||||
'visitorId' => null
|
||||
),
|
||||
'result' => array(
|
||||
'errorCode' => 0
|
||||
)
|
||||
);
|
||||
class InviteInteraction extends Interaction
|
||||
{
|
||||
/**
|
||||
* Reserved function's names
|
||||
* @var array
|
||||
* @see \Mibew\API\Interaction\Interaction::$reservedFunctionNames
|
||||
*/
|
||||
public $reservedFunctionNames = array(
|
||||
'result',
|
||||
);
|
||||
|
||||
/**
|
||||
* Reserved function's names
|
||||
* @var array
|
||||
* @see \Mibew\API\Interaction\Interaction::$reservedFunctionNames
|
||||
*/
|
||||
public $reservedFunctionNames = array(
|
||||
'result'
|
||||
);
|
||||
/**
|
||||
* Defines obligatory arguments and default values for them
|
||||
* @var array
|
||||
* @see \Mibew\API\Interaction\Interaction::$obligatoryArgumnents
|
||||
*/
|
||||
protected $obligatoryArguments = array(
|
||||
'*' => array(
|
||||
'references' => array(),
|
||||
'return' => array(),
|
||||
'visitorId' => null,
|
||||
),
|
||||
'result' => array(
|
||||
'errorCode' => 0,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
?>
|
@ -20,34 +20,33 @@ namespace Mibew\API\Interaction;
|
||||
/**
|
||||
* Implements Mibew Core - Mibew Users list interaction
|
||||
*/
|
||||
class UsersInteraction extends Interaction {
|
||||
/**
|
||||
* Defines obligatory arguments and default values for them
|
||||
* @var array
|
||||
* @see \Mibew\API\Interaction\Interaction::$obligatoryArgumnents
|
||||
*/
|
||||
protected $obligatoryArguments = array(
|
||||
'*' => array(
|
||||
'agentId' => null,
|
||||
'references' => array(),
|
||||
'return' => array()
|
||||
),
|
||||
'updateThreads' => array(
|
||||
'revision' => 0
|
||||
),
|
||||
'result' => array(
|
||||
'errorCode' => 0
|
||||
)
|
||||
);
|
||||
class UsersInteraction extends Interaction
|
||||
{
|
||||
/**
|
||||
* Reserved function's names
|
||||
* @var array
|
||||
* @see \Mibew\API\Interaction\Interaction::$reservedFunctionNames
|
||||
*/
|
||||
public $reservedFunctionNames = array(
|
||||
'result',
|
||||
);
|
||||
|
||||
/**
|
||||
* Reserved function's names
|
||||
* @var array
|
||||
* @see \Mibew\API\Interaction\Interaction::$reservedFunctionNames
|
||||
*/
|
||||
public $reservedFunctionNames = array(
|
||||
'result'
|
||||
);
|
||||
/**
|
||||
* Defines obligatory arguments and default values for them
|
||||
* @var array
|
||||
* @see \Mibew\API\Interaction\Interaction::$obligatoryArgumnents
|
||||
*/
|
||||
protected $obligatoryArguments = array(
|
||||
'*' => array(
|
||||
'agentId' => null,
|
||||
'references' => array(),
|
||||
'return' => array(),
|
||||
),
|
||||
'updateThreads' => array(
|
||||
'revision' => 0,
|
||||
),
|
||||
'result' => array(
|
||||
'errorCode' => 0,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
?>
|
@ -21,380 +21,406 @@ namespace Mibew;
|
||||
* Encapsulates work with database. Implenets singleton pattern to provide only
|
||||
* one instance.
|
||||
*/
|
||||
Class Database{
|
||||
class Database
|
||||
{
|
||||
const FETCH_ASSOC = 1;
|
||||
const FETCH_NUM = 2;
|
||||
const FETCH_BOTH = 4;
|
||||
const RETURN_ONE_ROW = 8;
|
||||
const RETURN_ALL_ROWS = 16;
|
||||
|
||||
const FETCH_ASSOC = 1;
|
||||
const FETCH_NUM = 2;
|
||||
const FETCH_BOTH = 4;
|
||||
const RETURN_ONE_ROW = 8;
|
||||
const RETURN_ALL_ROWS = 16;
|
||||
/**
|
||||
* An instance of Database class
|
||||
* @var Database
|
||||
*/
|
||||
protected static $instance = null;
|
||||
|
||||
/**
|
||||
* An instance of Database class
|
||||
* @var Database
|
||||
*/
|
||||
protected static $instance = NULL;
|
||||
/**
|
||||
* PDO object
|
||||
* @var \PDO
|
||||
*/
|
||||
protected $dbh = null;
|
||||
|
||||
/**
|
||||
* PDO object
|
||||
* @var \PDO
|
||||
*/
|
||||
protected $dbh = NULL;
|
||||
/**
|
||||
* Database host
|
||||
* @var string
|
||||
*/
|
||||
protected $dbHost = '';
|
||||
|
||||
/**
|
||||
* Database host
|
||||
* @var string
|
||||
*/
|
||||
protected $dbHost = '';
|
||||
/**
|
||||
* Database user's login
|
||||
* @var string
|
||||
*/
|
||||
protected $dbLogin = '';
|
||||
|
||||
/**
|
||||
* Database user's login
|
||||
* @var string
|
||||
*/
|
||||
protected $dbLogin = '';
|
||||
/**
|
||||
* Database user's password
|
||||
* @var string
|
||||
*/
|
||||
protected $dbPass = '';
|
||||
|
||||
/**
|
||||
* Database user's password
|
||||
* @var string
|
||||
*/
|
||||
protected $dbPass = '';
|
||||
/**
|
||||
* Database name
|
||||
* @var string
|
||||
*/
|
||||
protected $dbName = '';
|
||||
|
||||
/**
|
||||
* Database name
|
||||
* @var string
|
||||
*/
|
||||
protected $dbName = '';
|
||||
/**
|
||||
* Tables prefix
|
||||
* @var string
|
||||
*/
|
||||
protected $tablesPrefix = '';
|
||||
|
||||
/**
|
||||
* Tables prefix
|
||||
* @var string
|
||||
*/
|
||||
protected $tablesPrefix = '';
|
||||
/**
|
||||
* Database connection encoding. Is used only if
|
||||
* Database::$forceCharsetInConnection is set to true.
|
||||
* @var string
|
||||
*
|
||||
* @see Database::$forceCharsetInConnection
|
||||
*/
|
||||
protected $dbEncoding = 'utf8';
|
||||
|
||||
/**
|
||||
* Database connection encoding. Use only if Database::$forceCharsetInConnection set to true
|
||||
* @var string
|
||||
*
|
||||
* @see Database::$forceCharsetInConnection
|
||||
*/
|
||||
protected $dbEncoding = 'utf8';
|
||||
/**
|
||||
* Determine if connection must be forced to charset, specified in
|
||||
* Database::$dbEncoding
|
||||
* @var boolean
|
||||
*
|
||||
* @see Database::$dbEncoding
|
||||
*/
|
||||
protected $forceCharsetInConnection = true;
|
||||
|
||||
/**
|
||||
* Determine if connection must be forced to charset, specified in
|
||||
* Database::$dbEncoding
|
||||
* @var boolean
|
||||
*
|
||||
* @see Database::$dbEncoding
|
||||
*/
|
||||
protected $forceCharsetInConnection = true;
|
||||
/**
|
||||
* Determine if connection to the database must be persistent
|
||||
* @var type
|
||||
*/
|
||||
protected $usePersistentConnection = false;
|
||||
|
||||
/**
|
||||
* Determine if connection to the database must be persistent
|
||||
* @var type
|
||||
*/
|
||||
protected $usePersistentConnection = false;
|
||||
/**
|
||||
* Array of prepared SQL statements
|
||||
* @var array
|
||||
*/
|
||||
protected $preparedStatements = array();
|
||||
|
||||
/**
|
||||
* Array of prepared SQL statements
|
||||
* @var array
|
||||
*/
|
||||
protected $preparedStatements = array();
|
||||
/**
|
||||
* Id of the last query
|
||||
* @var type
|
||||
*/
|
||||
protected $lastQuery = null;
|
||||
|
||||
/**
|
||||
* Id of the last query
|
||||
* @var type
|
||||
*/
|
||||
protected $lastQuery = NULL;
|
||||
/**
|
||||
* Controls if exception must be processed into class or thrown
|
||||
* @var boolean
|
||||
*/
|
||||
protected $throwExceptions = false;
|
||||
|
||||
/**
|
||||
* Controls if exception must be processed into class or thrown
|
||||
* @var boolean
|
||||
*/
|
||||
protected $throwExceptions = false;
|
||||
/**
|
||||
* Get instance of Database class.
|
||||
*
|
||||
* If no instance exists, creates new instance.
|
||||
* Use Database::initialize() before try to get an instance. If database
|
||||
* was not initilize coorectly triggers an error with E_USER_ERROR level.
|
||||
*
|
||||
* @return Database
|
||||
* @see Database::initialize()
|
||||
*/
|
||||
public static function getInstance()
|
||||
{
|
||||
if (is_null(self::$instance)) {
|
||||
trigger_error('Database was not initialized correctly', E_USER_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get instance of Database class.
|
||||
*
|
||||
* If no instance exists, creates new instance.
|
||||
* Use Database::initialize() before try to get an instance. If database was not initilize coorectly triggers an
|
||||
* error with E_USER_ERROR level.
|
||||
*
|
||||
* @return Database
|
||||
* @see Database::initialize()
|
||||
*/
|
||||
public static function getInstance(){
|
||||
if (is_null(self::$instance)) {
|
||||
trigger_error('Database was not initialized correctly', E_USER_ERROR);
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy internal database object
|
||||
*/
|
||||
public static function destroy(){
|
||||
if (! is_null(self::$instance)) {
|
||||
self::$instance->__destruct();
|
||||
self::$instance = NULL;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Destroy internal database object
|
||||
*/
|
||||
public static function destroy()
|
||||
{
|
||||
if (!is_null(self::$instance)) {
|
||||
self::$instance->__destruct();
|
||||
self::$instance = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize database.
|
||||
*
|
||||
* Set internal database and connectionproperties. Create Database object. Create PDO object and store it in the
|
||||
* Database object.
|
||||
*
|
||||
* @param string $host Database host.
|
||||
* @param string $user Database user name.
|
||||
* @param string $pass Database for user with $name password.
|
||||
* @param boolean $use_pconn Control use persistent connection to the database or not.
|
||||
* @param string $db Database name.
|
||||
* @param string $prefix Database tables prefix
|
||||
* @param boolean $force_charset Control force charset in conection or not.
|
||||
* @param string $encoding Contains connection encoding. Using only if $force_charset = true.
|
||||
*/
|
||||
public static function initialize($host, $user, $pass, $use_pconn, $db, $prefix, $force_charset = false, $encoding = 'utf8') {
|
||||
// Check PDO
|
||||
if (! extension_loaded('PDO')) {
|
||||
throw new \Exception('PDO extension is not loaded');
|
||||
}
|
||||
/**
|
||||
* Initialize database.
|
||||
*
|
||||
* Set internal database and connectionproperties. Create Database object.
|
||||
* Create PDO object and store it in the Database object.
|
||||
*
|
||||
* @param string $host Database host.
|
||||
* @param string $user Database user name.
|
||||
* @param string $pass Database for user with $name password.
|
||||
* @param boolean $use_pconn Control use persistent connection to the
|
||||
* database or not.
|
||||
* @param string $db Database name.
|
||||
* @param string $prefix Database tables prefix
|
||||
* @param boolean $force_charset Control force charset in conection or not.
|
||||
* @param string $encoding Contains connection encoding. Is used only if
|
||||
* $force_charset is equals to TRUE.
|
||||
*/
|
||||
public static function initialize(
|
||||
$host,
|
||||
$user,
|
||||
$pass,
|
||||
$use_pconn,
|
||||
$db,
|
||||
$prefix,
|
||||
$force_charset = false,
|
||||
$encoding = 'utf8'
|
||||
) {
|
||||
// Check PDO
|
||||
if (!extension_loaded('PDO')) {
|
||||
throw new \Exception('PDO extension is not loaded');
|
||||
}
|
||||
|
||||
if (! extension_loaded('pdo_mysql')) {
|
||||
throw new \Exception('pdo_mysql extension is not loaded');
|
||||
}
|
||||
if (!extension_loaded('pdo_mysql')) {
|
||||
throw new \Exception('pdo_mysql extension is not loaded');
|
||||
}
|
||||
|
||||
// Check if initialization
|
||||
if (! is_null(self::$instance)) {
|
||||
throw new \Exception('Database already initialized');
|
||||
}
|
||||
// Check if initialization
|
||||
if (!is_null(self::$instance)) {
|
||||
throw new \Exception('Database already initialized');
|
||||
}
|
||||
|
||||
// Create database instance
|
||||
$instance = new Database();
|
||||
// Create database instance
|
||||
$instance = new Database();
|
||||
|
||||
// Set database and connection properties
|
||||
$instance->dbHost = $host;
|
||||
$instance->dbLogin = $user;
|
||||
$instance->dbPass = $pass;
|
||||
$instance->dbName = $db;
|
||||
$instance->dbEncoding = $encoding;
|
||||
$instance->tablesPrefix = preg_replace('/[^A-Za-z0-9_$]/', '', $prefix);
|
||||
$instance->forceCharsetInConnection = $force_charset;
|
||||
$instance->usePersistentConnection = $use_pconn;
|
||||
// Set database and connection properties
|
||||
$instance->dbHost = $host;
|
||||
$instance->dbLogin = $user;
|
||||
$instance->dbPass = $pass;
|
||||
$instance->dbName = $db;
|
||||
$instance->dbEncoding = $encoding;
|
||||
$instance->tablesPrefix = preg_replace('/[^A-Za-z0-9_$]/', '', $prefix);
|
||||
$instance->forceCharsetInConnection = $force_charset;
|
||||
$instance->usePersistentConnection = $use_pconn;
|
||||
|
||||
// Create PDO object
|
||||
$instance->dbh = new \PDO(
|
||||
"mysql:host={$instance->dbHost};dbname={$instance->dbName}",
|
||||
$instance->dbLogin,
|
||||
$instance->dbPass,
|
||||
array(\PDO::ATTR_PERSISTENT => $instance->usePersistentConnection)
|
||||
);
|
||||
// Create PDO object
|
||||
$instance->dbh = new \PDO(
|
||||
"mysql:host={$instance->dbHost};dbname={$instance->dbName}",
|
||||
$instance->dbLogin,
|
||||
$instance->dbPass,
|
||||
array(\PDO::ATTR_PERSISTENT => $instance->usePersistentConnection)
|
||||
);
|
||||
|
||||
if ($instance->forceCharsetInConnection) {
|
||||
$instance->dbh->exec("SET NAMES ".$instance->dbh->quote($instance->dbEncoding));
|
||||
}
|
||||
if ($instance->forceCharsetInConnection) {
|
||||
$instance->dbh->exec("SET NAMES " . $instance->dbh->quote($instance->dbEncoding));
|
||||
}
|
||||
|
||||
// Store instance
|
||||
self::$instance = $instance;
|
||||
}
|
||||
// Store instance
|
||||
self::$instance = $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forbid clone objects
|
||||
*/
|
||||
private final function __clone() {}
|
||||
/**
|
||||
* Set if exceptions must be process into the class or thrown and return
|
||||
* previous value.
|
||||
*
|
||||
* If called without arguments just return previous value without changing
|
||||
* anything.
|
||||
*
|
||||
* @param boolean $value Value that should be set. This argument is optional
|
||||
* @return bool Previous value
|
||||
*/
|
||||
public function throwExeptions()
|
||||
{
|
||||
$last_value = $this->throwExceptions;
|
||||
if (func_num_args() > 0) {
|
||||
$this->throwExceptions = func_get_arg(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forbid external object creation
|
||||
*/
|
||||
protected function __construct() {}
|
||||
return $last_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles errors
|
||||
* @param \Exception $e
|
||||
*/
|
||||
protected function handleError(\Exception $e){
|
||||
if ($this->throwExceptions) {
|
||||
throw $e;
|
||||
}
|
||||
die($e->getMessage());
|
||||
}
|
||||
/**
|
||||
* Database class destructor.
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
foreach ($this->preparedStatements as $key => $statement) {
|
||||
$this->preparedStatements[$key] = null;
|
||||
}
|
||||
$this->dbh = null;
|
||||
self::$instance = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if exceptions must be process into the class or thrown and return
|
||||
* previous value.
|
||||
*
|
||||
* If called without arguments just return previous value without changing
|
||||
* anything.
|
||||
*
|
||||
* @param boolean $value Value that should be set. This argument is optional
|
||||
* @return bool Previous value
|
||||
*/
|
||||
public function throwExeptions(){
|
||||
$last_value = $this->throwExceptions;
|
||||
if (func_num_args() > 0) {
|
||||
$this->throwExceptions = func_get_arg(0);
|
||||
}
|
||||
return $last_value;
|
||||
}
|
||||
/**
|
||||
* Executes SQL query.
|
||||
*
|
||||
* In SQL query can be used PDO style placeholders:
|
||||
* unnamed placeholders (question marks '?') and named placeholders (like
|
||||
* ':name'). If unnamed placeholders are used, $values array must have
|
||||
* numeric indexes. If named placeholders are used, $values param must be an
|
||||
* associative array with keys corresponding to the placeholders names
|
||||
*
|
||||
* Table prefix automatically substitute if table name puts in curly braces
|
||||
*
|
||||
* @param string $query SQL query
|
||||
* @param array $values Values, that must be substitute instead of
|
||||
* placeholders in SQL query.
|
||||
* @param array $params Array of query parameters. It can contains values
|
||||
* with following keys:
|
||||
* - 'return_rows' control if rows must be returned and how many rows must
|
||||
* be returnd. The value can be Database::RETURN_ONE_ROW for olny one
|
||||
* row or Database::RETURN_ALL_ROWS for all rows. If this key not
|
||||
* specified, the function will not return any rows.
|
||||
* - 'fetch_type' control indexes in resulting rows. The value can be
|
||||
* Database::FETCH_ASSOC for associative array, Database::FETCH_NUM for
|
||||
* array with numeric indexes and Database::FETCH_BOTH for both indexes.
|
||||
* Default value is Database::FETCH_ASSOC.
|
||||
* @return mixed If 'return_rows' key of the $params array is specified,
|
||||
* returns one or several rows (depending on $params['return_rows'] value)
|
||||
* or boolean false on fail.
|
||||
* If 'return_rows' key of the $params array is not specified, returns
|
||||
* boolean true on success or false on fail.
|
||||
*
|
||||
* @see Database::RETURN_ONE_ROW
|
||||
* @see Database::RETURN_ALL_ROWS
|
||||
* @see Database::FETCH_ASSOC
|
||||
* @see Database::FETCH_NUM
|
||||
* @see Database::FETCH_BOTH
|
||||
*/
|
||||
public function query($query, $values = null, $params = array())
|
||||
{
|
||||
try {
|
||||
$query = preg_replace("/\{(\w+)\}/", $this->tablesPrefix . "$1", $query);
|
||||
|
||||
/**
|
||||
* Database class destructor.
|
||||
*/
|
||||
public function __destruct(){
|
||||
foreach($this->preparedStatements as $key => $statement) {
|
||||
$this->preparedStatements[$key] = NULL;
|
||||
}
|
||||
$this->dbh = NULL;
|
||||
self::$instance = NULL;
|
||||
}
|
||||
$query_key = md5($query);
|
||||
if (!array_key_exists($query_key, $this->preparedStatements)) {
|
||||
$this->preparedStatements[$query_key] = $this->dbh->prepare($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes SQL query.
|
||||
* In SQL query can be used PDO style placeholders:
|
||||
* unnamed placeholders (question marks '?') and named placeholders (like
|
||||
* ':name').
|
||||
* If unnamed placeholders are used, $values array must have numeric indexes.
|
||||
* If named placeholders are used, $values param must be an associative array
|
||||
* with keys corresponding to the placeholders names
|
||||
*
|
||||
* Table prefix automatically substitute if table name puts in curly braces
|
||||
*
|
||||
* @param string $query SQL query
|
||||
* @param array $values Values, that must be substitute instead of
|
||||
* placeholders in SQL query.
|
||||
* @param array $params Array of query parameters. It can contains values with
|
||||
* following keys:
|
||||
* - 'return_rows' control if rows must be returned and how many rows must
|
||||
* be returnd. The value can be Database::RETURN_ONE_ROW for olny one row
|
||||
* or Database::RETURN_ALL_ROWS for all rows. If this key not specified,
|
||||
* the function will not return any rows.
|
||||
* - 'fetch_type' control indexes in resulting rows. The value can be
|
||||
* Database::FETCH_ASSOC for associative array, Database::FETCH_NUM for
|
||||
* array with numeric indexes and Database::FETCH_BOTH for both indexes.
|
||||
* Default value is Database::FETCH_ASSOC.
|
||||
* @return mixed If 'return_rows' key of the $params array is specified,
|
||||
* returns one or several rows (depending on $params['return_rows'] value) or
|
||||
* boolean false on fail.
|
||||
* If 'return_rows' key of the $params array is not specified, returns
|
||||
* boolean true on success or false on fail.
|
||||
*
|
||||
* @see Database::RETURN_ONE_ROW
|
||||
* @see Database::RETURN_ALL_ROWS
|
||||
* @see Database::FETCH_ASSOC
|
||||
* @see Database::FETCH_NUM
|
||||
* @see Database::FETCH_BOTH
|
||||
*/
|
||||
public function query($query, $values = NULL, $params = array()){
|
||||
try{
|
||||
$query = preg_replace("/\{(\w+)\}/", $this->tablesPrefix."$1", $query);
|
||||
$this->lastQuery = $query_key;
|
||||
|
||||
$query_key = md5($query);
|
||||
if (! array_key_exists($query_key, $this->preparedStatements)) {
|
||||
$this->preparedStatements[$query_key] = $this->dbh->prepare($query);
|
||||
}
|
||||
// Execute query
|
||||
$this->preparedStatements[$query_key]->execute($values);
|
||||
|
||||
$this->lastQuery = $query_key;
|
||||
// Check if error occurs
|
||||
if ($this->preparedStatements[$query_key]->errorCode() !== '00000') {
|
||||
$errorInfo = $this->preparedStatements[$query_key]->errorInfo();
|
||||
throw new \Exception(' Query failed: ' . $errorInfo[2]);
|
||||
}
|
||||
|
||||
// Execute query
|
||||
$this->preparedStatements[$query_key]->execute($values);
|
||||
// No need to return rows
|
||||
if (!array_key_exists('return_rows', $params)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if error occurs
|
||||
if ($this->preparedStatements[$query_key]->errorCode() !== '00000') {
|
||||
$errorInfo = $this->preparedStatements[$query_key]->errorInfo();
|
||||
throw new \Exception(' Query failed: ' . $errorInfo[2]);
|
||||
}
|
||||
// Some rows must be returned
|
||||
// Get indexes type
|
||||
if (!array_key_exists('fetch_type', $params)) {
|
||||
$params['fetch_type'] = Database::FETCH_ASSOC;
|
||||
}
|
||||
switch ($params['fetch_type']) {
|
||||
case Database::FETCH_NUM:
|
||||
$fetch_type = \PDO::FETCH_NUM;
|
||||
break;
|
||||
case Database::FETCH_ASSOC:
|
||||
$fetch_type = \PDO::FETCH_ASSOC;
|
||||
break;
|
||||
case Database::FETCH_BOTH:
|
||||
$fetch_type = \PDO::FETCH_BOTH;
|
||||
break;
|
||||
default:
|
||||
throw new \Exception("Unknown 'fetch_type' value!");
|
||||
}
|
||||
|
||||
// No need to return rows
|
||||
if (! array_key_exists('return_rows', $params)) {
|
||||
return true;
|
||||
}
|
||||
// Get results
|
||||
$rows = array();
|
||||
if ($params['return_rows'] == Database::RETURN_ONE_ROW) {
|
||||
$rows = $this->preparedStatements[$query_key]->fetch($fetch_type);
|
||||
} elseif ($params['return_rows'] == Database::RETURN_ALL_ROWS) {
|
||||
$rows = $this->preparedStatements[$query_key]->fetchAll($fetch_type);
|
||||
} else {
|
||||
throw new \Exception("Unknown 'return_rows' value!");
|
||||
}
|
||||
$this->preparedStatements[$query_key]->closeCursor();
|
||||
|
||||
// Some rows must be returned
|
||||
return $rows;
|
||||
} catch (\Exception $e) {
|
||||
$this->handleError($e);
|
||||
}
|
||||
}
|
||||
|
||||
// Get indexes type
|
||||
if (! array_key_exists('fetch_type', $params)) {
|
||||
$params['fetch_type'] = Database::FETCH_ASSOC;
|
||||
}
|
||||
switch($params['fetch_type']){
|
||||
case Database::FETCH_NUM:
|
||||
$fetch_type = \PDO::FETCH_NUM;
|
||||
break;
|
||||
case Database::FETCH_ASSOC:
|
||||
$fetch_type = \PDO::FETCH_ASSOC;
|
||||
break;
|
||||
case Database::FETCH_BOTH:
|
||||
$fetch_type = \PDO::FETCH_BOTH;
|
||||
break;
|
||||
default:
|
||||
throw new \Exception("Unknown 'fetch_type' value!");
|
||||
}
|
||||
/**
|
||||
* Returns value of PDOStatement::$errorInfo property for last query.
|
||||
*
|
||||
* @return string Error info array
|
||||
* @see \PDOStatement::$erorrInfo
|
||||
*/
|
||||
public function errorInfo()
|
||||
{
|
||||
if (is_null($this->lastQuery)) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
$error_info = $this->preparedStatements[$this->lastQuery]->errorInfo();
|
||||
} catch (\Exception $e) {
|
||||
$this->handleError($e);
|
||||
}
|
||||
|
||||
// Get results
|
||||
$rows = array();
|
||||
if ($params['return_rows'] == Database::RETURN_ONE_ROW) {
|
||||
$rows = $this->preparedStatements[$query_key]->fetch($fetch_type);
|
||||
} elseif ($params['return_rows'] == Database::RETURN_ALL_ROWS) {
|
||||
$rows = $this->preparedStatements[$query_key]->fetchAll($fetch_type);
|
||||
} else {
|
||||
throw new \Exception("Unknown 'return_rows' value!");
|
||||
}
|
||||
$this->preparedStatements[$query_key]->closeCursor();
|
||||
return $error_info;
|
||||
}
|
||||
|
||||
return $rows;
|
||||
} catch(\Exception $e) {
|
||||
$this->handleError($e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Returns the ID of the last inserted row
|
||||
*
|
||||
* @return int The ID
|
||||
*/
|
||||
public function insertedId()
|
||||
{
|
||||
try {
|
||||
$last_inserted_id = $this->dbh->lastInsertId();
|
||||
} catch (\Exception $e) {
|
||||
$this->handleError($e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns value of PDOStatement::$errorInfo property for last query
|
||||
* @return string Error info array
|
||||
*
|
||||
* @see \PDOStatement::$erorrInfo
|
||||
*/
|
||||
public function errorInfo(){
|
||||
if (is_null($this->lastQuery)) {
|
||||
return false;
|
||||
}
|
||||
try{
|
||||
$errorInfo = $this->preparedStatements[$this->lastQuery]->errorInfo();
|
||||
} catch (\Exception $e) {
|
||||
$this->handleError($e);
|
||||
}
|
||||
return $errorInfo;
|
||||
}
|
||||
return $last_inserted_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ID of the last inserted row
|
||||
*
|
||||
* @return int The ID
|
||||
*/
|
||||
public function insertedId(){
|
||||
try{
|
||||
$lastInsertedId = $this->dbh->lastInsertId();
|
||||
} catch(\Exception $e) {
|
||||
$this->handleError($e);
|
||||
}
|
||||
return $lastInsertedId;
|
||||
}
|
||||
/**
|
||||
* Get count of affected rows in the last query
|
||||
*
|
||||
* @return int Affected rows count
|
||||
*/
|
||||
public function affectedRows()
|
||||
{
|
||||
if (is_null($this->lastQuery)) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
$affected_rows = $this->preparedStatements[$this->lastQuery]->rowCount();
|
||||
} catch (\Exception $e) {
|
||||
$this->handleError($e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get count of affected rows in the last query
|
||||
*
|
||||
* @return int Affected rows count
|
||||
*/
|
||||
public function affectedRows(){
|
||||
if (is_null($this->lastQuery)) {
|
||||
return false;
|
||||
}
|
||||
try{
|
||||
$affected_rows = $this->preparedStatements[$this->lastQuery]->rowCount();
|
||||
} catch(\Exception $e) {
|
||||
$this->handleError($e);
|
||||
}
|
||||
return $affected_rows;
|
||||
}
|
||||
return $affected_rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forbid external object creation
|
||||
*/
|
||||
protected function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles errors
|
||||
* @param \Exception $e
|
||||
*/
|
||||
protected function handleError(\Exception $e)
|
||||
{
|
||||
if ($this->throwExceptions) {
|
||||
throw $e;
|
||||
}
|
||||
die($e->getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Forbid clone objects
|
||||
*/
|
||||
final private function __clone()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -21,128 +21,140 @@ namespace Mibew;
|
||||
* Provide event-related functionality.
|
||||
* Implements singleton pattern.
|
||||
*/
|
||||
Class EventDispatcher {
|
||||
class EventDispatcher
|
||||
{
|
||||
/**
|
||||
* An instance of EventDispatcher class.
|
||||
*
|
||||
* @var EventDispatcher
|
||||
*/
|
||||
protected static $instance = null;
|
||||
|
||||
/**
|
||||
* An instance of EventDispatcher class.
|
||||
* @var EventDispatcher
|
||||
*/
|
||||
protected static $instance = null;
|
||||
/**
|
||||
* Events and listeners array.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $events = array();
|
||||
|
||||
/**
|
||||
* Events and listeners array.
|
||||
* @var array
|
||||
*/
|
||||
protected $events = array();
|
||||
/**
|
||||
* Increments any time when plugin adds. Is used for determine plugins order
|
||||
* for plugins with equal priority.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $offset = 0;
|
||||
|
||||
/**
|
||||
* Increments any time when plugin adds. Use for determine plugins order for plugins with
|
||||
* equal priority.
|
||||
* @var int
|
||||
*/
|
||||
protected $offset = 0;
|
||||
/**
|
||||
* Returns an instance of EventDispatcher class.
|
||||
*
|
||||
* @return EventDispatcher
|
||||
*/
|
||||
public static function getInstance()
|
||||
{
|
||||
if (self::$instance === null) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of EventDispatcher class.
|
||||
*
|
||||
* @return EventDispatcher
|
||||
*/
|
||||
public static function getInstance(){
|
||||
if (self::$instance === null) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make constructor unavailable for client code
|
||||
*/
|
||||
protected function __constructor() {}
|
||||
/**
|
||||
* Attaches listener function to event.
|
||||
*
|
||||
* All event listeners must receive one argument of array type by reference.
|
||||
*
|
||||
* @param string $event_name Event's name
|
||||
* @param \Mibew\Plugin $plugin Plugin object, that handles the event
|
||||
* @param string $listener Plugins method, that handles the event
|
||||
* @param int $priority Priority of listener. If $priority = null, the
|
||||
* plugin weight will use instead.
|
||||
* @return boolean true on success or false on failure.
|
||||
*
|
||||
* @see \Mibew\Plugin::getWeight()
|
||||
*/
|
||||
public function attachListener($event_name, Plugin $plugin, $listener, $priority = null)
|
||||
{
|
||||
// Check method is callable
|
||||
if (!is_callable(array($plugin, $listener))) {
|
||||
trigger_error("Method '{$listener}' is not callable!", E_USER_WARNING);
|
||||
|
||||
/**
|
||||
* Attaches listener function to event.
|
||||
*
|
||||
* All event listeners must receive one argument of array type by reference.
|
||||
*
|
||||
* @param string $event_name Event's name
|
||||
* @param \Mibew\Plugin $plugin Plugin object, that handles the event
|
||||
* @param string $listener Plugins method, that handles the event
|
||||
* @param int $priority Priority of listener. If $priority = null, the plugin weight will
|
||||
* use instead.
|
||||
* @return boolean true on success or false on failure.
|
||||
*
|
||||
* @see \Mibew\Plugin::getWeight()
|
||||
*/
|
||||
public function attachListener($event_name, Plugin $plugin, $listener, $priority = null){
|
||||
// Check method is callable
|
||||
if (! is_callable(array($plugin, $listener))) {
|
||||
trigger_error("Method '{$listener}' is not callable!", E_USER_WARNING);
|
||||
return false;
|
||||
}
|
||||
// Create empty array for event listener if it not exists
|
||||
if (! array_key_exists($event_name, $this->events)) {
|
||||
$this->events[$event_name] = array();
|
||||
}
|
||||
// Check priority
|
||||
if (is_null($priority)) {
|
||||
$priority = $plugin->getWeight();
|
||||
}
|
||||
// Attach listener
|
||||
$this->events[$event_name][$priority . "_" . $this->offset] = array(
|
||||
'plugin' => $plugin,
|
||||
'listener' => $listener
|
||||
);
|
||||
$this->offset++;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// Create empty array for event listener if it not exists
|
||||
if (!array_key_exists($event_name, $this->events)) {
|
||||
$this->events[$event_name] = array();
|
||||
}
|
||||
// Check priority
|
||||
if (is_null($priority)) {
|
||||
$priority = $plugin->getWeight();
|
||||
}
|
||||
// Attach listener
|
||||
$this->events[$event_name][$priority . "_" . $this->offset] = array(
|
||||
'plugin' => $plugin,
|
||||
'listener' => $listener,
|
||||
);
|
||||
$this->offset++;
|
||||
|
||||
/**
|
||||
* Detach listener function from event
|
||||
*
|
||||
* @param string $event_name Event's name
|
||||
* @param \Mibew\Plugin $plugin Plugin object, that handles the event
|
||||
* @param string $listener Plugins method, that handles the event
|
||||
* @return boolean true on success or false on failure.
|
||||
*/
|
||||
public function detachListener($event_name, Plugin $plugin, $listener){
|
||||
// Check event exists
|
||||
if (! array_key_exists($event_name, $this->events)) {
|
||||
return false;
|
||||
}
|
||||
// Search event and $plugin->$listener
|
||||
foreach ($this->events[$event_name] as $index => $event) {
|
||||
if ($event['plugin'] === $plugin && $event['listener'] == $listener) {
|
||||
// Detach listener
|
||||
unset($this->events[$event_name][$index]);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggers the event
|
||||
*
|
||||
* @param string $event_name Event's name
|
||||
* @param array &$arguments Arguments passed to listener
|
||||
* @return boolean true on success or false on failure
|
||||
*/
|
||||
public function triggerEvent($event_name, &$arguments = array()){
|
||||
// Check event listeners exists
|
||||
if (! array_key_exists($event_name, $this->events)) {
|
||||
return true;
|
||||
}
|
||||
// Sorting listeners by priority
|
||||
uksort($this->events[$event_name], 'strnatcmp');
|
||||
// Invoke listeners
|
||||
foreach ($this->events[$event_name] as $event) {
|
||||
$plugin = $event['plugin'];
|
||||
$listener = $event['listener'];
|
||||
$plugin->$listener($arguments);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Detach listener function from event
|
||||
*
|
||||
* @param string $event_name Event's name
|
||||
* @param \Mibew\Plugin $plugin Plugin object, that handles the event
|
||||
* @param string $listener Plugins method, that handles the event
|
||||
* @return boolean true on success or false on failure.
|
||||
*/
|
||||
public function detachListener($event_name, Plugin $plugin, $listener)
|
||||
{
|
||||
// Check event exists
|
||||
if (!array_key_exists($event_name, $this->events)) {
|
||||
return false;
|
||||
}
|
||||
// Search event and $plugin->$listener
|
||||
foreach ($this->events[$event_name] as $index => $event) {
|
||||
if ($event['plugin'] === $plugin && $event['listener'] == $listener) {
|
||||
// Detach listener
|
||||
unset($this->events[$event_name][$index]);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggers the event
|
||||
*
|
||||
* @param string $event_name Event's name
|
||||
* @param array &$arguments Arguments passed to listener
|
||||
* @return boolean true on success or false on failure
|
||||
*/
|
||||
public function triggerEvent($event_name, &$arguments = array())
|
||||
{
|
||||
// Check event listeners exists
|
||||
if (!array_key_exists($event_name, $this->events)) {
|
||||
return true;
|
||||
}
|
||||
// Sorting listeners by priority
|
||||
uksort($this->events[$event_name], 'strnatcmp');
|
||||
// Invoke listeners
|
||||
foreach ($this->events[$event_name] as $event) {
|
||||
$plugin = $event['plugin'];
|
||||
$listener = $event['listener'];
|
||||
$plugin->$listener($arguments);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make constructor unavailable for client code
|
||||
*/
|
||||
protected function __constructor()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -20,52 +20,51 @@ namespace Mibew;
|
||||
/**
|
||||
* Base plugin class
|
||||
*/
|
||||
abstract Class Plugin {
|
||||
abstract class Plugin
|
||||
{
|
||||
/**
|
||||
* Constructor must set this value to true after successful initialization
|
||||
* failures
|
||||
* @var boolean
|
||||
*/
|
||||
public $initialized = false;
|
||||
|
||||
/**
|
||||
* Constructor must set this value to true after successful initialization
|
||||
* failures
|
||||
* @var boolean
|
||||
*/
|
||||
public $initialized = false;
|
||||
/**
|
||||
* An array of plugin configuration
|
||||
* @var array
|
||||
*/
|
||||
protected $config = array();
|
||||
|
||||
/**
|
||||
* An array of plugin configuration
|
||||
* @var array
|
||||
*/
|
||||
protected $config = array();
|
||||
/**
|
||||
* Returns plugin weight. Weight is used for determine loading order and as
|
||||
* default listner priority.
|
||||
*
|
||||
* @return int Plugin weight
|
||||
*/
|
||||
abstract public function getWeight();
|
||||
|
||||
/**
|
||||
* Returns plugin weight. Weight is used for determine loading order and as default
|
||||
* listner priority.
|
||||
*
|
||||
* @return int Plugin weight
|
||||
*/
|
||||
abstract public function getWeight();
|
||||
/**
|
||||
* Register listeners
|
||||
*
|
||||
* Event listener take one argument by reference. For example:
|
||||
* <code>
|
||||
* public function testListener(&$arguments) {
|
||||
* $arguments['result'] = 'Test string';
|
||||
* }
|
||||
* </code>
|
||||
*/
|
||||
abstract public function registerListeners();
|
||||
|
||||
/**
|
||||
* Register listeners
|
||||
*
|
||||
* Event listener take one argument by reference. For example:
|
||||
* <code>
|
||||
* public function testListener(&$arguments) {
|
||||
* $arguments['result'] = 'Test string';
|
||||
* }
|
||||
* </code>
|
||||
*/
|
||||
abstract public function registerListeners();
|
||||
|
||||
/**
|
||||
* Returns list of plugin's dependences.
|
||||
*
|
||||
* Each element of dependenses list is a string with a plugin name.
|
||||
* If plugin have no dependenses do not override this method.
|
||||
*
|
||||
* @return array List of plugin's dependences.
|
||||
*/
|
||||
public static function getDependences() {
|
||||
return array();
|
||||
}
|
||||
/**
|
||||
* Returns list of plugin's dependences.
|
||||
*
|
||||
* Each element of dependenses list is a string with a plugin name.
|
||||
* If plugin have no dependenses do not override this method.
|
||||
*
|
||||
* @return array List of plugin's dependences.
|
||||
*/
|
||||
public static function getDependences()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -20,143 +20,142 @@ namespace Mibew;
|
||||
/**
|
||||
* Manage plugins
|
||||
*/
|
||||
Class PluginManager {
|
||||
class PluginManager
|
||||
{
|
||||
/**
|
||||
* Contains all loaded plugins
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $loadedPlugins = array();
|
||||
|
||||
/**
|
||||
* Contains all loaded plugins
|
||||
* @var array
|
||||
*/
|
||||
protected static $loaded_plugins = array();
|
||||
/**
|
||||
* Returns plugin object
|
||||
*
|
||||
* @param string $plugin_name
|
||||
* @return \Mibew\Plugin
|
||||
*/
|
||||
public static function getPlugin($plugin_name)
|
||||
{
|
||||
if (empty(self::$loadedPlugins[$plugin_name])) {
|
||||
trigger_error(
|
||||
"Plugin '{$plugin_name}' does not initialized!",
|
||||
E_USER_WARNING
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns plugin object
|
||||
*
|
||||
* @param string $plugin_name
|
||||
* @return \Mibew\Plugin
|
||||
*/
|
||||
public static function getPlugin($plugin_name) {
|
||||
if (empty(self::$loaded_plugins[$plugin_name])) {
|
||||
trigger_error(
|
||||
"Plugin '{$plugin_name}' does not initialized!",
|
||||
E_USER_WARNING
|
||||
);
|
||||
}
|
||||
return self::$loaded_plugins[$plugin_name];
|
||||
}
|
||||
return self::$loadedPlugins[$plugin_name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns associative array of loaded plugins.
|
||||
*
|
||||
* Key represents plugin's name and value contains Plugin object
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getAllPlugins() {
|
||||
return self::$loaded_plugins;
|
||||
}
|
||||
/**
|
||||
* Returns associative array of loaded plugins.
|
||||
*
|
||||
* Key represents plugin's name and value contains Plugin object
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getAllPlugins()
|
||||
{
|
||||
return self::$loadedPlugins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads plugins.
|
||||
*
|
||||
* The method checks dependences and plugin avaiulability before loading and
|
||||
* invokes Plugin::registerListeners() after loading.
|
||||
*
|
||||
* @param array $plugins_list List of plugins' names and configurations.
|
||||
* For example:
|
||||
* <code>
|
||||
* $plugins_list = array();
|
||||
* $plugins_list[] = array(
|
||||
* 'name' => 'plugin_name', // Obligatory value
|
||||
* 'config' => array( // Pass to plugin constructor
|
||||
* 'weight' => 100,
|
||||
* 'some_configurable_value' => 'value'
|
||||
* )
|
||||
* )
|
||||
* </code>
|
||||
*
|
||||
* @see Plugin::registerListeners()
|
||||
*/
|
||||
public static function loadPlugins($plugins_list){
|
||||
// Add include path
|
||||
$include_path = get_include_path();
|
||||
$include_path .= empty($include_path) ? '' : PATH_SEPARATOR ;
|
||||
set_include_path($include_path . realpath(MIBEW_FS_ROOT . "/plugins/"));
|
||||
/**
|
||||
* Loads plugins.
|
||||
*
|
||||
* The method checks dependences and plugin avaiulability before loading and
|
||||
* invokes Plugin::registerListeners() after loading.
|
||||
*
|
||||
* @param array $plugins_list List of plugins' names and configurations.
|
||||
* For example:
|
||||
* <code>
|
||||
* $plugins_list = array();
|
||||
* $plugins_list[] = array(
|
||||
* 'name' => 'plugin_name', // Obligatory value
|
||||
* 'config' => array( // Pass to plugin constructor
|
||||
* 'weight' => 100,
|
||||
* 'some_configurable_value' => 'value'
|
||||
* )
|
||||
* )
|
||||
* </code>
|
||||
*
|
||||
* @see Plugin::registerListeners()
|
||||
*/
|
||||
public static function loadPlugins($plugins_list)
|
||||
{
|
||||
// Add include path
|
||||
$include_path = get_include_path();
|
||||
$include_path .= empty($include_path) ? '' : PATH_SEPARATOR;
|
||||
set_include_path($include_path . realpath(MIBEW_FS_ROOT . "/plugins/"));
|
||||
|
||||
// Load plugins
|
||||
$loading_queue = array();
|
||||
$offset = 0;
|
||||
foreach ($plugins_list as $plugin) {
|
||||
if (empty($plugin['name'])) {
|
||||
trigger_error("Plugin name undefined!", E_USER_WARNING);
|
||||
continue;
|
||||
}
|
||||
$plugin_name = $plugin['name'];
|
||||
$plugin_config = isset($plugin['config']) ? $plugin['config'] : array();
|
||||
// Load plugins
|
||||
$loading_queue = array();
|
||||
$offset = 0;
|
||||
foreach ($plugins_list as $plugin) {
|
||||
if (empty($plugin['name'])) {
|
||||
trigger_error("Plugin name undefined!", E_USER_WARNING);
|
||||
continue;
|
||||
}
|
||||
$plugin_name = $plugin['name'];
|
||||
$plugin_config = isset($plugin['config']) ? $plugin['config'] : array();
|
||||
|
||||
// Build name of the plugin class
|
||||
$plugin_name_parts = explode('_', $plugin_name);
|
||||
$plugin_name_parts = array_map('ucfirst', $plugin_name_parts);
|
||||
$plugin_classname = '\\Mibew\\Plugin\\' . implode('', $plugin_name_parts);
|
||||
// Build name of the plugin class
|
||||
$plugin_name_parts = explode('_', $plugin_name);
|
||||
$plugin_name_parts = array_map('ucfirst', $plugin_name_parts);
|
||||
$plugin_classname = '\\Mibew\\Plugin\\' . implode('', $plugin_name_parts);
|
||||
|
||||
// Try to load plugin file
|
||||
if (! (include_once $plugin_name."/".$plugin_name."_plugin.php")) {
|
||||
trigger_error("Cannot load plugin file!", E_USER_ERROR);
|
||||
}
|
||||
// Check plugin class name
|
||||
if (! class_exists($plugin_classname)) {
|
||||
trigger_error(
|
||||
"Plugin class '{$plugin_classname}' is undefined!",
|
||||
E_USER_WARNING
|
||||
);
|
||||
continue;
|
||||
}
|
||||
// Check if plugin extends abstract 'Plugin' class
|
||||
if ('Mibew\\Plugin' != get_parent_class($plugin_classname)) {
|
||||
trigger_error(
|
||||
"Plugin class '{$plugin_classname}' does not extend " .
|
||||
"abstract '\\Mibew\\Plugin' class!",
|
||||
E_USER_WARNING
|
||||
);
|
||||
continue;
|
||||
}
|
||||
// Try to load plugin file
|
||||
if (!(include_once $plugin_name . "/" . $plugin_name . "_plugin.php")) {
|
||||
trigger_error("Cannot load plugin file!", E_USER_ERROR);
|
||||
}
|
||||
// Check plugin class name
|
||||
if (!class_exists($plugin_classname)) {
|
||||
trigger_error(
|
||||
"Plugin class '{$plugin_classname}' is undefined!",
|
||||
E_USER_WARNING
|
||||
);
|
||||
continue;
|
||||
}
|
||||
// Check if plugin extends abstract 'Plugin' class
|
||||
if ('Mibew\\Plugin' != get_parent_class($plugin_classname)) {
|
||||
$error_essage = "Plugin class '{$plugin_classname}' does not "
|
||||
. "extend abstract '\\Mibew\\Plugin' class!";
|
||||
trigger_error($error_essage, E_USER_WARNING);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check plugin dependences
|
||||
$plugin_dependences = call_user_func(array(
|
||||
$plugin_classname,
|
||||
'getDependences'
|
||||
));
|
||||
foreach ($plugin_dependences as $dependence) {
|
||||
if (empty(self::$loaded_plugins[$dependence])) {
|
||||
trigger_error(
|
||||
"Plugin '{$dependence}' was not loaded yet, but " .
|
||||
"exists in '{$plugin_name}' dependences list!",
|
||||
E_USER_WARNING
|
||||
);
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
// Check plugin dependences
|
||||
$plugin_dependences = call_user_func(array(
|
||||
$plugin_classname,
|
||||
'getDependences',
|
||||
));
|
||||
foreach ($plugin_dependences as $dependence) {
|
||||
if (empty(self::$loadedPlugins[$dependence])) {
|
||||
$error_essage = "Plugin '{$dependence}' was not loaded "
|
||||
. "yet, but exists in '{$plugin_name}' dependences list!";
|
||||
trigger_error($error_essage, E_USER_WARNING);
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
|
||||
// Add plugin to loading queue
|
||||
$plugin_instance = new $plugin_classname($plugin_config);
|
||||
if ($plugin_instance->initialized) {
|
||||
// Store plugin instance
|
||||
self::$loaded_plugins[$plugin_name] = $plugin_instance;
|
||||
$loading_queue[$plugin_instance->getWeight() . "_" . $offset] = $plugin_instance;
|
||||
$offset++;
|
||||
} else {
|
||||
trigger_error(
|
||||
"Plugin '{$plugin_name}' was not initialized correctly!",
|
||||
E_USER_WARNING
|
||||
);
|
||||
}
|
||||
}
|
||||
// Sort queue in order to plugins' weights
|
||||
uksort($loading_queue, 'strnatcmp');
|
||||
// Add events and listeners
|
||||
foreach ($loading_queue as $plugin) {
|
||||
$plugin->registerListeners();
|
||||
}
|
||||
}
|
||||
// Add plugin to loading queue
|
||||
$plugin_instance = new $plugin_classname($plugin_config);
|
||||
if ($plugin_instance->initialized) {
|
||||
// Store plugin instance
|
||||
self::$loadedPlugins[$plugin_name] = $plugin_instance;
|
||||
$loading_queue[$plugin_instance->getWeight() . "_" . $offset] = $plugin_instance;
|
||||
$offset++;
|
||||
} else {
|
||||
trigger_error(
|
||||
"Plugin '{$plugin_name}' was not initialized correctly!",
|
||||
E_USER_WARNING
|
||||
);
|
||||
}
|
||||
}
|
||||
// Sort queue in order to plugins' weights
|
||||
uksort($loading_queue, 'strnatcmp');
|
||||
// Add events and listeners
|
||||
foreach ($loading_queue as $plugin) {
|
||||
$plugin->registerListeners();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -24,81 +24,84 @@ use Mibew\Database;
|
||||
* Base class for all request processors that interact with JavaScript
|
||||
* applications at the client side.
|
||||
*/
|
||||
abstract class ClientSideProcessor extends Processor {
|
||||
abstract class ClientSideProcessor extends Processor
|
||||
{
|
||||
|
||||
/**
|
||||
* Call function at client side
|
||||
*
|
||||
* @param array $functions Array of functions to call. See Mibew API for
|
||||
* details.
|
||||
* @param array|null $callback callback array for synchronous requests.
|
||||
* @return mixed request result or boolean false on failure.
|
||||
*/
|
||||
public function call($functions, $callback = null) {
|
||||
return parent::call($functions, true, $callback);
|
||||
}
|
||||
/**
|
||||
* Call function at client side
|
||||
*
|
||||
* @param array $functions Array of functions to call. See Mibew API for
|
||||
* details.
|
||||
* @param array|null $callback callback array for synchronous requests.
|
||||
* @return mixed request result or boolean false on failure.
|
||||
*/
|
||||
public function call($functions, $callback = null)
|
||||
{
|
||||
return parent::call($functions, true, $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends asynchronous responses
|
||||
*
|
||||
* @param array $responses An array of the 'Request' arrays. See Mibew API
|
||||
* for details
|
||||
*/
|
||||
protected function sendAsyncResponses($responses) {
|
||||
header("Content-type: text/plain; charset=UTF-8");
|
||||
echo($this->mibewAPI->encodePackage(
|
||||
$responses,
|
||||
$this->config['signature'],
|
||||
true
|
||||
));
|
||||
}
|
||||
/**
|
||||
* Sends asynchronous responses
|
||||
*
|
||||
* @param array $responses An array of the 'Request' arrays. See Mibew API
|
||||
* for details
|
||||
*/
|
||||
protected function sendAsyncResponses($responses)
|
||||
{
|
||||
header("Content-type: text/plain; charset=UTF-8");
|
||||
echo($this->mibewAPI->encodePackage(
|
||||
$responses,
|
||||
$this->config['signature'],
|
||||
true
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add request to client side to the buffer. Use database as storage.
|
||||
* Override this method if you want to use another storage and/or save logic.
|
||||
*
|
||||
* @param String $key Request key. Use to load request from buffer.
|
||||
* @param $request Request array.
|
||||
*/
|
||||
protected function addRequestToBuffer($key, $request) {
|
||||
// Save request to database
|
||||
$db = Database::getInstance();
|
||||
$db->query(
|
||||
"INSERT INTO {requestbuffer} (request, requestkey) VALUES (:request, :key)",
|
||||
array(':request' => serialize($request), ':key' => md5($key))
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Add request to client side to the buffer. Use database as storage.
|
||||
* Override this method if you want to use another storage and/or save logic.
|
||||
*
|
||||
* @param String $key Request key. Use to load request from buffer.
|
||||
* @param $request Request array.
|
||||
*/
|
||||
protected function addRequestToBuffer($key, $request)
|
||||
{
|
||||
// Save request to database
|
||||
$db = Database::getInstance();
|
||||
$db->query(
|
||||
"INSERT INTO {requestbuffer} (request, requestkey) VALUES (:request, :key)",
|
||||
array(':request' => serialize($request), ':key' => md5($key))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load stored requests to the client side
|
||||
*
|
||||
* @param String $key Request key
|
||||
* @return array Array of requests with given key
|
||||
*/
|
||||
protected function getRequestsFromBuffer($key) {
|
||||
$db = Database::getInstance();
|
||||
/**
|
||||
* Load stored requests to the client side
|
||||
*
|
||||
* @param String $key Request key
|
||||
* @return array Array of requests with given key
|
||||
*/
|
||||
protected function getRequestsFromBuffer($key)
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
|
||||
$key = md5($key);
|
||||
$key = md5($key);
|
||||
|
||||
// Get requests from database
|
||||
$requests = $db->query(
|
||||
"SELECT request FROM {requestbuffer} WHERE requestkey = :key",
|
||||
array(':key' => $key),
|
||||
array('return_rows' => Database::RETURN_ALL_ROWS)
|
||||
);
|
||||
// Remove got requests from database
|
||||
$db->query(
|
||||
"DELETE FROM {requestbuffer} WHERE requestkey = :key",
|
||||
array(':key' => $key)
|
||||
);
|
||||
// Unserialize requests
|
||||
$result = array();
|
||||
foreach($requests as $request_info) {
|
||||
$result[] = unserialize($request_info['request']);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
// Get requests from database
|
||||
$requests = $db->query(
|
||||
"SELECT request FROM {requestbuffer} WHERE requestkey = :key",
|
||||
array(':key' => $key),
|
||||
array('return_rows' => Database::RETURN_ALL_ROWS)
|
||||
);
|
||||
// Remove got requests from database
|
||||
$db->query(
|
||||
"DELETE FROM {requestbuffer} WHERE requestkey = :key",
|
||||
array(':key' => $key)
|
||||
);
|
||||
// Unserialize requests
|
||||
$result = array();
|
||||
foreach ($requests as $request_info) {
|
||||
$result[] = unserialize($request_info['request']);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -20,11 +20,10 @@ namespace Mibew\RequestProcessor\Exception;
|
||||
/**
|
||||
* Class for {@link \Mibew\RequestProcessor\InviteRequestProcessor} exceptions
|
||||
*/
|
||||
class InviteProcessorException extends ProcessorException {
|
||||
/**
|
||||
* Operator is not logged in
|
||||
*/
|
||||
const ERROR_AGENT_NOT_LOGGED_IN = 1;
|
||||
class InviteProcessorException extends ProcessorException
|
||||
{
|
||||
/**
|
||||
* Operator is not logged in
|
||||
*/
|
||||
const ERROR_AGENT_NOT_LOGGED_IN = 1;
|
||||
}
|
||||
|
||||
?>
|
@ -20,11 +20,10 @@ namespace Mibew\RequestProcessor\Exception;
|
||||
/**
|
||||
* Class for {@link \Mibew\RequestProcessor\Processor} exceptions.
|
||||
*/
|
||||
class ProcessorException extends \Exception {
|
||||
/**
|
||||
* Wrong function arguments
|
||||
*/
|
||||
const WRONG_ARGUMENTS = 1;
|
||||
class ProcessorException extends \Exception
|
||||
{
|
||||
/**
|
||||
* Wrong function arguments
|
||||
*/
|
||||
const WRONG_ARGUMENTS = 1;
|
||||
}
|
||||
|
||||
?>
|
@ -20,51 +20,50 @@ namespace Mibew\RequestProcessor\Exception;
|
||||
/**
|
||||
* Class for {@link \Mibew\RequestProcessor\ThreadProcessor} exceptions.
|
||||
*/
|
||||
class ThreadProcessorException extends ProcessorException {
|
||||
/**
|
||||
* 'recipient' argument is not set
|
||||
*/
|
||||
const EMPTY_RECIPIENT = 1;
|
||||
/**
|
||||
* Operator is not logged in
|
||||
*/
|
||||
const ERROR_AGENT_NOT_LOGGED_IN = 2;
|
||||
/**
|
||||
* Wrong arguments set for an API function
|
||||
*/
|
||||
const ERROR_WRONG_ARGUMENTS = 3;
|
||||
/**
|
||||
* Thread cannot be loaded
|
||||
*/
|
||||
const ERROR_WRONG_THREAD = 4;
|
||||
/**
|
||||
* Message cannot be send
|
||||
*/
|
||||
const ERROR_CANNOT_SEND = 5;
|
||||
/**
|
||||
* User rename forbidden by system configurations
|
||||
*/
|
||||
const ERROR_FORBIDDEN_RENAME = 6;
|
||||
/**
|
||||
* Various recipient in different functions in one package
|
||||
*/
|
||||
const VARIOUS_RECIPIENT = 7;
|
||||
/**
|
||||
* Various thread ids or thread tokens in different functions in one package
|
||||
*/
|
||||
const VARIOUS_THREAD_ID = 8;
|
||||
/**
|
||||
* Wrong recipient value
|
||||
*/
|
||||
const WRONG_RECIPIENT_VALUE = 9;
|
||||
/**
|
||||
* Wrong captcha value
|
||||
*/
|
||||
const ERROR_WRONG_CAPTCHA = 10;
|
||||
/**
|
||||
* Wrong email address
|
||||
*/
|
||||
const ERROR_WRONG_EMAIL = 11;
|
||||
class ThreadProcessorException extends ProcessorException
|
||||
{
|
||||
/**
|
||||
* 'recipient' argument is not set
|
||||
*/
|
||||
const EMPTY_RECIPIENT = 1;
|
||||
/**
|
||||
* Operator is not logged in
|
||||
*/
|
||||
const ERROR_AGENT_NOT_LOGGED_IN = 2;
|
||||
/**
|
||||
* Wrong arguments set for an API function
|
||||
*/
|
||||
const ERROR_WRONG_ARGUMENTS = 3;
|
||||
/**
|
||||
* Thread cannot be loaded
|
||||
*/
|
||||
const ERROR_WRONG_THREAD = 4;
|
||||
/**
|
||||
* Message cannot be send
|
||||
*/
|
||||
const ERROR_CANNOT_SEND = 5;
|
||||
/**
|
||||
* User rename forbidden by system configurations
|
||||
*/
|
||||
const ERROR_FORBIDDEN_RENAME = 6;
|
||||
/**
|
||||
* Various recipient in different functions in one package
|
||||
*/
|
||||
const VARIOUS_RECIPIENT = 7;
|
||||
/**
|
||||
* Various thread ids or thread tokens in different functions in one package
|
||||
*/
|
||||
const VARIOUS_THREAD_ID = 8;
|
||||
/**
|
||||
* Wrong recipient value
|
||||
*/
|
||||
const WRONG_RECIPIENT_VALUE = 9;
|
||||
/**
|
||||
* Wrong captcha value
|
||||
*/
|
||||
const ERROR_WRONG_CAPTCHA = 10;
|
||||
/**
|
||||
* Wrong email address
|
||||
*/
|
||||
const ERROR_WRONG_EMAIL = 11;
|
||||
}
|
||||
|
||||
?>
|
@ -20,19 +20,18 @@ namespace Mibew\RequestProcessor\Exception;
|
||||
/**
|
||||
* Class for {@link \Mibew\RequestProcessor\UsersProcessor} exceptions
|
||||
*/
|
||||
class UsersProcessorException extends ProcessorException {
|
||||
/**
|
||||
* Operator is not logged in
|
||||
*/
|
||||
const ERROR_AGENT_NOT_LOGGED_IN = 1;
|
||||
/**
|
||||
* Wrong agent id
|
||||
*/
|
||||
const ERROR_WRONG_AGENT_ID = 2;
|
||||
/**
|
||||
* Various agent ids in different functions in one package
|
||||
*/
|
||||
const VARIOUS_AGENT_ID = 3;
|
||||
class UsersProcessorException extends ProcessorException
|
||||
{
|
||||
/**
|
||||
* Operator is not logged in
|
||||
*/
|
||||
const ERROR_AGENT_NOT_LOGGED_IN = 1;
|
||||
/**
|
||||
* Wrong agent id
|
||||
*/
|
||||
const ERROR_WRONG_AGENT_ID = 2;
|
||||
/**
|
||||
* Various agent ids in different functions in one package
|
||||
*/
|
||||
const VARIOUS_AGENT_ID = 3;
|
||||
}
|
||||
|
||||
?>
|
@ -33,94 +33,106 @@ use Mibew\RequestProcessor\Exception\InviteProcessorException;
|
||||
*
|
||||
* Implements Singleton pattern
|
||||
*/
|
||||
class InviteProcessor extends ClientSideProcessor {
|
||||
class InviteProcessor extends ClientSideProcessor
|
||||
{
|
||||
/**
|
||||
* An instance of the InviteProcessor class
|
||||
*
|
||||
* @var \Mibew\RequestProcessor\InviteProcessor
|
||||
*/
|
||||
protected static $instance = null;
|
||||
|
||||
/**
|
||||
* An instance of the InviteProcessor class
|
||||
* @var \Mibew\RequestProcessor\InviteProcessor
|
||||
*/
|
||||
protected static $instance = null;
|
||||
/**
|
||||
* Return an instance of the InviteProcessor class.
|
||||
*
|
||||
* @return \Mibew\RequestProcessor\InviteProcessor
|
||||
*/
|
||||
public static function getInstance()
|
||||
{
|
||||
if (is_null(self::$instance)) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an instance of the InviteProcessor class.
|
||||
* @return \Mibew\RequestProcessor\InviteProcessor
|
||||
*/
|
||||
public static function getInstance() {
|
||||
if (is_null(self::$instance)) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Do not use directly __construct method! Use
|
||||
* \Mibew\RequestProcessor\InviteProcessor::getInstance() instead!
|
||||
* @todo Think about why the method is not protected
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct(array(
|
||||
'signature' => '',
|
||||
'trusted_signatures' => array(''),
|
||||
'event_prefix' => 'invite'
|
||||
));
|
||||
}
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Do not use directly __construct method! Use
|
||||
* \Mibew\RequestProcessor\InviteProcessor::getInstance() instead!
|
||||
*
|
||||
* @todo Think about why the method is not protected
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(array(
|
||||
'signature' => '',
|
||||
'trusted_signatures' => array(''),
|
||||
'event_prefix' => 'invite'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns an instance of the \Mibew\API\API class.
|
||||
*
|
||||
* @return \Mibew\API\API
|
||||
*/
|
||||
protected function getMibewAPIInstance() {
|
||||
return MibewAPI::getAPI('\\Mibew\\API\\Interaction\\InviteInteraction');
|
||||
}
|
||||
/**
|
||||
* Creates and returns an instance of the \Mibew\API\API class.
|
||||
*
|
||||
* @return \Mibew\API\API
|
||||
*/
|
||||
protected function getMibewAPIInstance()
|
||||
{
|
||||
return MibewAPI::getAPI('\\Mibew\\API\\Interaction\\InviteInteraction');
|
||||
}
|
||||
|
||||
/**
|
||||
* Stub for sendAsyncRequest method.
|
||||
*
|
||||
* Actually request not send to client side. This method is ONLY STUB.
|
||||
* @return boolean Always true
|
||||
*/
|
||||
protected function sendAsyncRequest() {
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Stub for sendAsyncRequest method.
|
||||
*
|
||||
* Actually request not send to client side. This method is ONLY STUB.
|
||||
*
|
||||
* @return boolean Always true
|
||||
*/
|
||||
protected function sendAsyncRequest()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stub for call method.
|
||||
*
|
||||
* Actually nothing can be called at client side. This method is ONLY STUB.
|
||||
* @return boolean Always false.
|
||||
*/
|
||||
public function call() {
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Stub for call method.
|
||||
*
|
||||
* Actually nothing can be called at client side. This method is ONLY STUB.
|
||||
*
|
||||
* @return boolean Always false.
|
||||
*/
|
||||
public function call()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns visitor invitation state. API function
|
||||
*
|
||||
* @param array $args Associative array of arguments. It must contains
|
||||
* following keys:
|
||||
* - 'visitorId': Id of the invited visitor
|
||||
* @return array Array of results. It contains following keys:
|
||||
* - 'invited': boolean, indicates if visitor is invited
|
||||
* - 'threadId': thread id related to visitor or false if there is no thread
|
||||
*/
|
||||
protected function apiInvitationState($args) {
|
||||
$operator = get_logged_in();
|
||||
if (!$operator) {
|
||||
throw new InviteProcessorException(
|
||||
"Operator not logged in!",
|
||||
InviteProcessorException::ERROR_AGENT_NOT_LOGGED_IN
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Returns visitor invitation state. API function
|
||||
*
|
||||
* @param array $args Associative array of arguments. It must contains
|
||||
* following keys:
|
||||
* - 'visitorId': Id of the invited visitor
|
||||
* @return array Array of results. It contains following keys:
|
||||
* - 'invited': boolean, indicates if visitor is invited
|
||||
* - 'threadId': thread id related to visitor or false if there is no
|
||||
* thread
|
||||
*/
|
||||
protected function apiInvitationState($args)
|
||||
{
|
||||
$operator = get_logged_in();
|
||||
if (!$operator) {
|
||||
throw new InviteProcessorException(
|
||||
"Operator not logged in!",
|
||||
InviteProcessorException::ERROR_AGENT_NOT_LOGGED_IN
|
||||
);
|
||||
}
|
||||
|
||||
$invitation = invitation_state($args['visitorId']);
|
||||
return array(
|
||||
'invited' => (bool)$invitation['invited'],
|
||||
'threadId' => ($invitation['threadid'] ? $invitation['threadid'] : false)
|
||||
);
|
||||
}
|
||||
$invitation = invitation_state($args['visitorId']);
|
||||
|
||||
return array(
|
||||
'invited' => (bool) $invitation['invited'],
|
||||
'threadId' => ($invitation['threadid'] ? $invitation['threadid'] : false),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -81,452 +81,488 @@ use Mibew\RequestProcessor\Exception\ProcessorException;
|
||||
* Example of the event handler:
|
||||
* <code>
|
||||
* public function callHandler(&$function) {
|
||||
* if ($function['function'] == 'microtime') {
|
||||
* $as_float = empty($function['arguments']['as_float'])
|
||||
* ? false
|
||||
* : $function['arguments']['as_float'];
|
||||
* $function['results']['time'] = microtime($as_float);
|
||||
* }
|
||||
* if ($function['function'] == 'microtime') {
|
||||
* $as_float = empty($function['arguments']['as_float'])
|
||||
* ? false
|
||||
* : $function['arguments']['as_float'];
|
||||
* $function['results']['time'] = microtime($as_float);
|
||||
* }
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
* @see \Mibew\RequestProcessor\Processor::__construct()
|
||||
*/
|
||||
abstract class Processor {
|
||||
abstract class Processor
|
||||
{
|
||||
/**
|
||||
* Instance of the MibewAPI class
|
||||
*
|
||||
* @var \Mibew\API\API
|
||||
*/
|
||||
protected $mibewAPI = null;
|
||||
|
||||
/**
|
||||
* Instance of the MibewAPI class
|
||||
* @var \Mibew\API\API
|
||||
*/
|
||||
protected $mibewAPI = null;
|
||||
/**
|
||||
* Prefix that uses for all events triggered by the class.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $eventPrefix = '';
|
||||
|
||||
/**
|
||||
* Prefix that uses for all events triggered by the class.
|
||||
* @var string
|
||||
*/
|
||||
protected $eventPrefix = '';
|
||||
/**
|
||||
* Array of the responses packages
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $responses = array();
|
||||
|
||||
/**
|
||||
* Array of the responses packages
|
||||
* @var array
|
||||
*/
|
||||
protected $responses = array();
|
||||
/**
|
||||
* Array of configurations
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $config = array();
|
||||
|
||||
/**
|
||||
* Array of configurations
|
||||
* @var array
|
||||
*/
|
||||
protected $config = array();
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param type $config Configuration data.
|
||||
* It must contains following keys:
|
||||
* - 'signature': Use for verification sender
|
||||
* - 'trusted_signatures': array of trusted signatures. Uses for identify
|
||||
* another side of interaction.
|
||||
* And may contains following (if not default values will be used)
|
||||
* - 'event_prefix': prefix that uses for all events triggered by the
|
||||
* class. The default value is the class name with first character in
|
||||
* lower case
|
||||
*/
|
||||
public function __construct($config)
|
||||
{
|
||||
// Check signature
|
||||
if (!isset($config['signature'])) {
|
||||
trigger_error("Signature is not specified", E_USER_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param type $config Configuration data.
|
||||
* It must contains following keys:
|
||||
* - 'signature': Use for verification sender
|
||||
* - 'trusted_signatures': array of trusted signatures. Uses for identify another
|
||||
* side of interaction.
|
||||
* And may contains following (if not default values will be used)
|
||||
* - 'event_prefix': prefix that uses for all events triggered by the
|
||||
* class. The default value is the class name with first character in
|
||||
* lower case
|
||||
*/
|
||||
public function __construct($config) {
|
||||
// Check signature
|
||||
if (! isset($config['signature'])) {
|
||||
trigger_error("Signature is not specified", E_USER_ERROR);
|
||||
}
|
||||
// Check trusted signatures
|
||||
if (!isset($config['trusted_signatures'])) {
|
||||
trigger_error("Trusted signatures is not specified", E_USER_ERROR);
|
||||
}
|
||||
|
||||
// Check trusted signatures
|
||||
if (! isset($config['trusted_signatures'])) {
|
||||
trigger_error("Trusted signatures is not specified", E_USER_ERROR);
|
||||
}
|
||||
// Get an instance of the MibewAPI class
|
||||
$this->mibewAPI = $this->getMibewAPIInstance();
|
||||
|
||||
// Get an instance of the MibewAPI class
|
||||
$this->mibewAPI = $this->getMibewAPIInstance();
|
||||
// Get class name and prefix for events and etc.
|
||||
$class_name_parts = explode('\\', get_class($this));
|
||||
$class_name = array_pop($class_name_parts);
|
||||
$this->eventPrefix = empty($config['event_prefix'])
|
||||
? strtolower(substr($class_name, 0, 1)) . substr($class_name, 1)
|
||||
: $config['event_prefix'];
|
||||
|
||||
// Get class name and prefix for events and etc.
|
||||
$class_name_parts = explode('\\', get_class($this));
|
||||
$class_name = array_pop($class_name_parts);
|
||||
$this->eventPrefix = empty($config['event_prefix'])
|
||||
? strtolower(substr($class_name, 0, 1)) . substr($class_name, 1)
|
||||
: $config['event_prefix'];
|
||||
// Store config
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
// Store config
|
||||
$this->config = $config;
|
||||
}
|
||||
/**
|
||||
* Proccess received packages
|
||||
*
|
||||
* On any error function returns only boolean false. To handle error add
|
||||
* listener to the "<eventPrefix>RequestError" event.
|
||||
*
|
||||
* @param string $package Encoded package
|
||||
* @return boolean true if request processed succussfully or false on
|
||||
* failure
|
||||
*/
|
||||
public function receiveRequest($package)
|
||||
{
|
||||
$dispatcher = EventDispatcher::getInstance();
|
||||
// Try to handle request
|
||||
try {
|
||||
// Decode package
|
||||
$request_package = $this->mibewAPI->decodePackage(
|
||||
$package,
|
||||
$this->config['trusted_signatures']
|
||||
);
|
||||
|
||||
/**
|
||||
* Proccess received packages
|
||||
*
|
||||
* On any error function returns only boolean false. To handle error add listener to the
|
||||
* "<eventPrefix>RequestError" event.
|
||||
*
|
||||
* @param string $package Encoded package
|
||||
* @return boolean true if request processed succussfully or false on failure
|
||||
*/
|
||||
public function receiveRequest($package){
|
||||
$dispatcher = EventDispatcher::getInstance();
|
||||
// Try to handle request
|
||||
try {
|
||||
// Decode package
|
||||
$request_package = $this->mibewAPI->decodePackage(
|
||||
$package,
|
||||
$this->config['trusted_signatures']
|
||||
);
|
||||
// Trigger request received event
|
||||
$vars = array('package' => $request_package);
|
||||
$dispatcher->triggerEvent(
|
||||
$this->eventPrefix . 'RequestReceived',
|
||||
$vars
|
||||
);
|
||||
$package = $vars['package'];
|
||||
|
||||
// Trigger request received event
|
||||
$vars = array('package' => $request_package);
|
||||
$dispatcher->triggerEvent(
|
||||
$this->eventPrefix . 'RequestReceived',
|
||||
$vars
|
||||
);
|
||||
$package = $vars['package'];
|
||||
// Process requests in package
|
||||
// Clear responses
|
||||
$this->responses = array();
|
||||
foreach ($package['requests'] as $request) {
|
||||
if ($package['async']) {
|
||||
// Asynchronous request
|
||||
// Try to load callback function for this token
|
||||
$callback = $this->loadCallback($request['token']);
|
||||
|
||||
// Process requests in package
|
||||
// Clear responses
|
||||
$this->responses = array();
|
||||
foreach ($package['requests'] as $request) {
|
||||
if ($package['async']) {
|
||||
// Asynchronous request
|
||||
// Try to load callback function for this token
|
||||
$callback = $this->loadCallback($request['token']);
|
||||
if (!is_null($callback)) {
|
||||
// There is callback function. Try to get result arguments
|
||||
$arguments = $this->processRequest($request, true);
|
||||
$function = $callback['function'];
|
||||
$arguments += empty($callback['arguments'])
|
||||
? array()
|
||||
: $callback['arguments'];
|
||||
call_user_func_array($function, array($arguments));
|
||||
continue;
|
||||
} else {
|
||||
// Try to get result function
|
||||
$result_function = $this->mibewAPI->getResultFunction($request['functions']);
|
||||
|
||||
if (! is_null($callback)) {
|
||||
// There is callback function. Try to get result arguments
|
||||
$arguments = $this->processRequest($request, true);
|
||||
$function = $callback['function'];
|
||||
$arguments += empty($callback['arguments'])
|
||||
? array()
|
||||
: $callback['arguments'];
|
||||
call_user_func_array($function, array($arguments));
|
||||
continue;
|
||||
} else {
|
||||
// Try to get result function
|
||||
$result_function = $this->mibewAPI->getResultFunction($request['functions']);
|
||||
if (!is_null($result_function)) {
|
||||
// There is result function but no callback
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! is_null($result_function)) {
|
||||
// There is result function but no callback
|
||||
continue;
|
||||
}
|
||||
// There is no result function
|
||||
// Process request
|
||||
$arguments = $this->processRequest($request, false);
|
||||
// Send response
|
||||
$this->responses[] = $this->mibewAPI->buildResult(
|
||||
$request['token'],
|
||||
$arguments
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// Synchronous request
|
||||
// Process request
|
||||
$arguments = $this->processRequest($request, false);
|
||||
// Send response
|
||||
$this->responses[] = $this->mibewAPI->buildResult(
|
||||
$request['token'],
|
||||
$arguments
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// There is no result function
|
||||
// Process request
|
||||
$arguments = $this->processRequest($request, false);
|
||||
// Send response
|
||||
$this->responses[] = $this->mibewAPI->buildResult(
|
||||
$request['token'],
|
||||
$arguments
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// Synchronous request
|
||||
// Process request
|
||||
$arguments = $this->processRequest($request, false);
|
||||
// Send response
|
||||
$this->responses[] = $this->mibewAPI->buildResult(
|
||||
$request['token'],
|
||||
$arguments
|
||||
);
|
||||
}
|
||||
}
|
||||
if (count($this->responses) != 0) {
|
||||
// Send responses
|
||||
if ($request_package['async']) {
|
||||
$this->sendAsyncResponses($this->responses);
|
||||
} else {
|
||||
$this->sendSyncResponses($this->responses);
|
||||
}
|
||||
}
|
||||
|
||||
if (count($this->responses) != 0) {
|
||||
// Send responses
|
||||
if ($request_package['async']) {
|
||||
$this->sendAsyncResponses($this->responses);
|
||||
} else {
|
||||
$this->sendSyncResponses($this->responses);
|
||||
}
|
||||
}
|
||||
// Output response
|
||||
} catch (\Exception $e) {
|
||||
// Something went wrong. Trigger error event
|
||||
$vars = array('exception' => $e);
|
||||
$dispatcher->triggerEvent($this->eventPrefix . 'RequestError', $vars);
|
||||
|
||||
// Output response
|
||||
} catch (\Exception $e) {
|
||||
// Something went wrong. Trigger error event
|
||||
$vars = array('exception' => $e);
|
||||
$dispatcher->triggerEvent($this->eventPrefix . 'RequestError', $vars);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call functions at the other side
|
||||
*
|
||||
* On any error function returns only boolean false. To handle error add listener to the
|
||||
* "<eventPrefix>CallError" event.
|
||||
*
|
||||
* @param array $functions Array of functions. See Mibew API for details.
|
||||
* @param boolean $async True for asynchronous requests and false for synchronous request
|
||||
* @param mixed $callback callback array or null for synchronous requests.
|
||||
* @return mixed request result or boolean false on failure.
|
||||
*/
|
||||
public function call($functions, $async, $callback = null) {
|
||||
// Get an instance of the \Mibew\EventDispatcher class
|
||||
$dispatcher = EventDispatcher::getInstance();
|
||||
// Try to call function at Other side
|
||||
try {
|
||||
// Check functions to call
|
||||
if (! is_array($functions)) {
|
||||
throw new ProcessorException(
|
||||
'#1 argument must be an array!',
|
||||
ProcessorException::WRONG_ARGUMENTS
|
||||
);
|
||||
}
|
||||
foreach ($functions as $function) {
|
||||
$this->mibewAPI->checkFunction($function, true);
|
||||
$this->checkFunction($function);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Create request
|
||||
// TODO: evaluate a possibility of using more secure method of the generation of token
|
||||
$token = md5(microtime() . rand());
|
||||
$request = array(
|
||||
'token' => $token,
|
||||
'functions' => $functions
|
||||
);
|
||||
/**
|
||||
* Call functions at the other side
|
||||
*
|
||||
* On any error function returns only boolean false. To handle error add
|
||||
* listener to the "<eventPrefix>CallError" event.
|
||||
*
|
||||
* @param array $functions Array of functions. See Mibew API for details.
|
||||
* @param boolean $async True for asynchronous requests and false for
|
||||
* synchronous request
|
||||
* @param mixed $callback callback array or null for synchronous requests.
|
||||
* @return mixed request result or boolean false on failure.
|
||||
*/
|
||||
public function call($functions, $async, $callback = null)
|
||||
{
|
||||
// Get an instance of the \Mibew\EventDispatcher class
|
||||
$dispatcher = EventDispatcher::getInstance();
|
||||
// Try to call function at Other side
|
||||
try {
|
||||
// Check functions to call
|
||||
if (!is_array($functions)) {
|
||||
throw new ProcessorException(
|
||||
'#1 argument must be an array!',
|
||||
ProcessorException::WRONG_ARGUMENTS
|
||||
);
|
||||
}
|
||||
foreach ($functions as $function) {
|
||||
$this->mibewAPI->checkFunction($function, true);
|
||||
$this->checkFunction($function);
|
||||
}
|
||||
|
||||
if ($async) {
|
||||
// Store callback
|
||||
if (! is_null($callback)) {
|
||||
$this->saveCallback($token, $callback);
|
||||
}
|
||||
// Create request
|
||||
// TODO: evaluate a possibility of using more secure method of the
|
||||
// generation of token
|
||||
$token = md5(microtime() . rand());
|
||||
$request = array(
|
||||
'token' => $token,
|
||||
'functions' => $functions
|
||||
);
|
||||
|
||||
// Send asynchronous request
|
||||
$this->sendAsyncRequest($request);
|
||||
return true;
|
||||
}
|
||||
if ($async) {
|
||||
// Store callback
|
||||
if (!is_null($callback)) {
|
||||
$this->saveCallback($token, $callback);
|
||||
}
|
||||
|
||||
// Send synchronous request
|
||||
$response_package = $this->sendSyncRequest($request);
|
||||
// Send asynchronous request
|
||||
$this->sendAsyncRequest($request);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Trigger response received event
|
||||
$vars = array('package' => $response_package);
|
||||
$dispatcher->triggerEvent($this->eventPrefix . 'ResponseReceived', $vars);
|
||||
// Send synchronous request
|
||||
$response_package = $this->sendSyncRequest($request);
|
||||
|
||||
// Process requests in response
|
||||
$result = null;
|
||||
foreach ($response_package['requests'] as $request) {
|
||||
// Use only response with token equals to request token. Ignore other packages.
|
||||
// TODO: May be not ignore other packages
|
||||
if ($request['token'] == $token) {
|
||||
$result = $this->processRequest($request, true);
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// Trigger error event
|
||||
$vars = array('exception' => $e);
|
||||
$dispatcher->triggerEvent($this->eventPrefix . "CallError", $vars);
|
||||
return false;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
// Trigger response received event
|
||||
$vars = array('package' => $response_package);
|
||||
$dispatcher->triggerEvent($this->eventPrefix . 'ResponseReceived', $vars);
|
||||
|
||||
/**
|
||||
* Process request
|
||||
*
|
||||
* @param array $request 'Requests' array. See Mibew API for details.
|
||||
* @param mixed $result_function Control existance of the 'result' function in request.
|
||||
* Use boolean true if 'result' function must exists in request, boolean false if must not
|
||||
* and null if it doesn't matter.
|
||||
* @return array Array of requests results.
|
||||
*/
|
||||
protected function processRequest($request, $result_function = null) {
|
||||
$context = new \Mibew\API\ExecutionContext();
|
||||
// Process requests in response
|
||||
$result = null;
|
||||
foreach ($response_package['requests'] as $request) {
|
||||
// Use only response with token equals to request token. Ignore other packages.
|
||||
// TODO: May be not ignore other packages
|
||||
if ($request['token'] == $token) {
|
||||
$result = $this->processRequest($request, true);
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// Trigger error event
|
||||
$vars = array('exception' => $e);
|
||||
$dispatcher->triggerEvent($this->eventPrefix . "CallError", $vars);
|
||||
|
||||
// Get result functions
|
||||
$result_function = $this->mibewAPI->getResultFunction(
|
||||
$request['functions'],
|
||||
$result_function
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Request contains not only result function
|
||||
if (! is_null($result_function) && count($request['functions']) > 1) {
|
||||
trigger_error(
|
||||
'Request contains not only result function',
|
||||
E_USER_WARNING
|
||||
);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
if (is_null($result_function)) {
|
||||
// Execute functions
|
||||
foreach ($request['functions'] as $function) {
|
||||
if (! $this->processFunction($function, $context)) {
|
||||
// Stop if errorCode is set and not equals to 0
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $context->getResults();
|
||||
} else {
|
||||
// Return result
|
||||
return $result_function['arguments'];
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Process request
|
||||
*
|
||||
* @param array $request 'Requests' array. See Mibew API for details.
|
||||
* @param mixed $result_function Control existance of the 'result' function
|
||||
* in request. Use boolean true if 'result' function must exists in
|
||||
* request, boolean false if must not and null if it doesn't matter.
|
||||
* @return array Array of requests results.
|
||||
*/
|
||||
protected function processRequest($request, $result_function = null)
|
||||
{
|
||||
$context = new \Mibew\API\ExecutionContext();
|
||||
|
||||
/**
|
||||
* Process function
|
||||
*
|
||||
* @param array $function 'Function' array. See Mibew API for details
|
||||
* @param \Mibew\API\ExecutionContext &$context Execution context
|
||||
* @return boolean lase if function returns errorCode and errorCode differs from 0.
|
||||
*/
|
||||
protected function processFunction($function, \Mibew\API\ExecutionContext &$context) {
|
||||
// Get function arguments with replaced references
|
||||
$arguments = $context->getArgumentsList($function);
|
||||
// Get result functions
|
||||
$result_function = $this->mibewAPI->getResultFunction(
|
||||
$request['functions'],
|
||||
$result_function
|
||||
);
|
||||
|
||||
$call_vars = array(
|
||||
'function' => $function['function'],
|
||||
'arguments' => $arguments,
|
||||
'results' => array()
|
||||
);
|
||||
// Request contains not only result function
|
||||
if (!is_null($result_function) && count($request['functions']) > 1) {
|
||||
trigger_error(
|
||||
'Request contains not only result function',
|
||||
E_USER_WARNING
|
||||
);
|
||||
}
|
||||
|
||||
// Call processor function
|
||||
$this->processorCall($call_vars);
|
||||
if (is_null($result_function)) {
|
||||
// Execute functions
|
||||
foreach ($request['functions'] as $function) {
|
||||
if (!$this->processFunction($function, $context)) {
|
||||
// Stop if errorCode is set and not equals to 0
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Trigger FunctionCall event
|
||||
$dispatcher = EventDispatcher::getInstance();
|
||||
$dispatcher->triggerEvent($this->eventPrefix . 'FunctionCall', $call_vars);
|
||||
return $context->getResults();
|
||||
} else {
|
||||
// Return result
|
||||
return $result_function['arguments'];
|
||||
}
|
||||
}
|
||||
|
||||
// Get results
|
||||
$results = $call_vars['results'];
|
||||
/**
|
||||
* Process function
|
||||
*
|
||||
* @param array $function 'Function' array. See Mibew API for details
|
||||
* @param \Mibew\API\ExecutionContext &$context Execution context
|
||||
* @return boolean lase if function returns errorCode and errorCode differs
|
||||
* from 0.
|
||||
*/
|
||||
protected function processFunction($function, \Mibew\API\ExecutionContext &$context)
|
||||
{
|
||||
// Get function arguments with replaced references
|
||||
$arguments = $context->getArgumentsList($function);
|
||||
|
||||
// Add function results to execution context
|
||||
$context->storeFunctionResults($function, $results);
|
||||
$call_vars = array(
|
||||
'function' => $function['function'],
|
||||
'arguments' => $arguments,
|
||||
'results' => array(),
|
||||
);
|
||||
|
||||
// Check errorCode
|
||||
return empty($results['errorCode']);
|
||||
}
|
||||
// Call processor function
|
||||
$this->processorCall($call_vars);
|
||||
|
||||
/**
|
||||
* Stores callback function
|
||||
*
|
||||
* Callback is an associative array with following keys
|
||||
* - 'function': function name to call
|
||||
* - 'arguments': additional arguments, that passed to the callback function
|
||||
*
|
||||
* @param string $token Request token
|
||||
* @param array $callback Callback function array
|
||||
* @todo Create some unit tests
|
||||
*/
|
||||
protected function saveCallback($token, $callback) {
|
||||
$db = Database::getInstance();
|
||||
$db->query(
|
||||
"INSERT INTO {requestcallback} ( ".
|
||||
"token, function, arguments ".
|
||||
") VALUES ( " .
|
||||
":token, :function, :arguments" .
|
||||
")",
|
||||
array(
|
||||
':token' => $token,
|
||||
':function' => $callback['function'],
|
||||
':arguments' => serialize($callback['arguments'])
|
||||
)
|
||||
);
|
||||
}
|
||||
// Trigger FunctionCall event
|
||||
$dispatcher = EventDispatcher::getInstance();
|
||||
$dispatcher->triggerEvent($this->eventPrefix . 'FunctionCall', $call_vars);
|
||||
|
||||
/**
|
||||
* Loads callback function
|
||||
*
|
||||
* Callback is an associative array with following keys
|
||||
* - 'function': function name to call
|
||||
* - 'arguments': additional arguments, that passed to the callback function
|
||||
*
|
||||
* @param string $token Token of the request related to callback function
|
||||
* @return mixed callback function array or null if callback function not exists
|
||||
* @todo Create some unit tests
|
||||
*/
|
||||
protected function loadCallback($token) {
|
||||
$db = Database::getInstance();
|
||||
$callback = $db->query(
|
||||
"SELECT * FROM {requestcallback} WHERE token = :token",
|
||||
array(':token' => $token),
|
||||
array('return_rows' => Database::RETURN_ONE_ROW)
|
||||
);
|
||||
if (! $callback) {
|
||||
return null;
|
||||
}
|
||||
return array(
|
||||
'function' => $callback['function'],
|
||||
'arguments' => unserialize($callback['arguments'])
|
||||
);
|
||||
}
|
||||
// Get results
|
||||
$results = $call_vars['results'];
|
||||
|
||||
/**
|
||||
* Dispatcher of the functions, provided by the RequestProcessor (or inherited) classes as an external API.
|
||||
*
|
||||
* All API methods names starts with 'api' prefix.
|
||||
* It calls before '<eventPrefix>FunctionCall' event triggers.
|
||||
*
|
||||
* @param array &$func Function array equals to array, passed to the '<eventPrefix>FunctionCall' event.
|
||||
* @todo Create some unit tests
|
||||
*/
|
||||
protected function processorCall(&$func) {
|
||||
$method_name = 'api' . ucfirst($func['function']);
|
||||
if (is_callable(array($this, $method_name))) {
|
||||
try {
|
||||
$func['results'] = $this->$method_name($func['arguments']);
|
||||
} catch(ProcessorException $e) {
|
||||
$func['results'] = array(
|
||||
'errorCode' => $e->getCode(),
|
||||
'errorMessage' => $e->getMessage()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Add function results to execution context
|
||||
$context->storeFunctionResults($function, $results);
|
||||
|
||||
/**
|
||||
* Sends synchronous request
|
||||
*
|
||||
* @param array $request The 'request' array. See Mibew API for details
|
||||
* @return mixed response array or boolean false on failure
|
||||
*/
|
||||
protected function sendSyncRequest($request) {
|
||||
trigger_error('Method sendSyncRequest does not implement!', E_USER_WARNING);
|
||||
}
|
||||
// Check errorCode
|
||||
return empty($results['errorCode']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends asynchronous request
|
||||
*
|
||||
* @param array $request The 'request' array. See Mibew API for details
|
||||
* @return boolean true on success or false on failure
|
||||
*/
|
||||
protected function sendAsyncRequest($request) {
|
||||
trigger_error('Method sendAsyncRequest does not implement!', E_USER_WARNING);
|
||||
}
|
||||
/**
|
||||
* Stores callback function
|
||||
*
|
||||
* Callback is an associative array with following keys
|
||||
* - 'function': function name to call.
|
||||
* - 'arguments': additional arguments, that passed to the callback
|
||||
* function.
|
||||
*
|
||||
* @param string $token Request token
|
||||
* @param array $callback Callback function array
|
||||
* @todo Create some unit tests
|
||||
*/
|
||||
protected function saveCallback($token, $callback)
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
|
||||
/**
|
||||
* Sends synchronous responses
|
||||
*
|
||||
* @param array $responses An array of the 'Request' arrays. See Mibew API for details
|
||||
*/
|
||||
protected function sendSyncResponses($responses) {
|
||||
trigger_error('Method sendSyncResponses does not implement!', E_USER_WARNING);
|
||||
}
|
||||
$query = "INSERT INTO {requestcallback} ( "
|
||||
. "token, function, arguments "
|
||||
. ") VALUES ( "
|
||||
. ":token, :function, :arguments"
|
||||
. ")";
|
||||
|
||||
/**
|
||||
* Sends asynchronous responses
|
||||
*
|
||||
* @param array $responses An array of the 'Request' arrays. See Mibew API for details
|
||||
*/
|
||||
protected function sendAsyncResponses($responses) {
|
||||
trigger_error('Method sendAsyncResponses does not implement!', E_USER_WARNING);
|
||||
}
|
||||
$db->query(
|
||||
$query,
|
||||
array(
|
||||
':token' => $token,
|
||||
':function' => $callback['function'],
|
||||
':arguments' => serialize($callback['arguments']),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Additional validation for functions that called via call method
|
||||
*
|
||||
* If something wrong function should throw an Exception.
|
||||
*
|
||||
* @param Array $function A Function array
|
||||
*/
|
||||
protected function checkFunction($function) {}
|
||||
/**
|
||||
* Loads callback function
|
||||
*
|
||||
* Callback is an associative array with following keys
|
||||
* - 'function': function name to call.
|
||||
* - 'arguments': additional arguments, that passed to the callback
|
||||
* function.
|
||||
*
|
||||
* @param string $token Token of the request related to callback function
|
||||
* @return mixed callback function array or null if callback function not
|
||||
* exists
|
||||
* @todo Create some unit tests
|
||||
*/
|
||||
protected function loadCallback($token)
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$callback = $db->query(
|
||||
"SELECT * FROM {requestcallback} WHERE token = :token",
|
||||
array(':token' => $token),
|
||||
array('return_rows' => Database::RETURN_ONE_ROW)
|
||||
);
|
||||
if (!$callback) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns an instance of the \Mibew\API\API class.
|
||||
*
|
||||
* @return \Mibew\API\API
|
||||
*/
|
||||
protected abstract function getMibewAPIInstance();
|
||||
return array(
|
||||
'function' => $callback['function'],
|
||||
'arguments' => unserialize($callback['arguments']),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatcher of the functions, provided by the RequestProcessor
|
||||
* (or inherited) classes as an external API.
|
||||
*
|
||||
* All API methods names starts with 'api' prefix.
|
||||
* It calls before '<eventPrefix>FunctionCall' event triggers.
|
||||
*
|
||||
* @param array &$func Function array equals to array, passed to the
|
||||
* '<eventPrefix>FunctionCall' event.
|
||||
* @todo Create some unit tests
|
||||
*/
|
||||
protected function processorCall(&$func)
|
||||
{
|
||||
$method_name = 'api' . ucfirst($func['function']);
|
||||
if (is_callable(array($this, $method_name))) {
|
||||
try {
|
||||
$func['results'] = $this->$method_name($func['arguments']);
|
||||
} catch (ProcessorException $e) {
|
||||
$func['results'] = array(
|
||||
'errorCode' => $e->getCode(),
|
||||
'errorMessage' => $e->getMessage(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends synchronous request
|
||||
*
|
||||
* @param array $request The 'request' array. See Mibew API for details
|
||||
* @return mixed response array or boolean false on failure
|
||||
*/
|
||||
protected function sendSyncRequest($request)
|
||||
{
|
||||
trigger_error('Method sendSyncRequest does not implement!', E_USER_WARNING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends asynchronous request
|
||||
*
|
||||
* @param array $request The 'request' array. See Mibew API for details
|
||||
* @return boolean true on success or false on failure
|
||||
*/
|
||||
protected function sendAsyncRequest($request)
|
||||
{
|
||||
trigger_error('Method sendAsyncRequest does not implement!', E_USER_WARNING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends synchronous responses
|
||||
*
|
||||
* @param array $responses An array of the 'Request' arrays. See Mibew API
|
||||
* for details
|
||||
*/
|
||||
protected function sendSyncResponses($responses)
|
||||
{
|
||||
trigger_error('Method sendSyncResponses does not implement!', E_USER_WARNING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends asynchronous responses
|
||||
*
|
||||
* @param array $responses An array of the 'Request' arrays. See Mibew API
|
||||
* for details
|
||||
*/
|
||||
protected function sendAsyncResponses($responses)
|
||||
{
|
||||
trigger_error('Method sendAsyncResponses does not implement!', E_USER_WARNING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Additional validation for functions that called via call method
|
||||
*
|
||||
* If something wrong function should throw an Exception.
|
||||
*
|
||||
* @param Array $function A Function array
|
||||
*/
|
||||
protected function checkFunction($function)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns an instance of the \Mibew\API\API class.
|
||||
*
|
||||
* @return \Mibew\API\API
|
||||
*/
|
||||
abstract protected function getMibewAPIInstance();
|
||||
}
|
||||
|
||||
?>
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -20,161 +20,165 @@ namespace Mibew;
|
||||
/**
|
||||
* Encapsulates work with system settings.
|
||||
*/
|
||||
Class Settings {
|
||||
class Settings
|
||||
{
|
||||
/**
|
||||
* An instance of Settings class
|
||||
*
|
||||
* @var Settings
|
||||
*/
|
||||
protected static $instance = null;
|
||||
|
||||
/**
|
||||
* An instance of Settings class
|
||||
* @var Settings
|
||||
*/
|
||||
protected static $instance = null;
|
||||
/**
|
||||
* Array of settings
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $settings = array();
|
||||
|
||||
/**
|
||||
* Array of settings
|
||||
* @var array
|
||||
*/
|
||||
protected $settings = array();
|
||||
/**
|
||||
* Array of settings stored in database
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $settingsInDb = array();
|
||||
|
||||
/**
|
||||
* Array of settings stored in database
|
||||
* @var array
|
||||
*/
|
||||
protected $settingsInDb = array();
|
||||
/**
|
||||
* Returns an instance of Settings class
|
||||
*
|
||||
* @return Settings
|
||||
*/
|
||||
protected static function getInstance()
|
||||
{
|
||||
if (self::$instance === null) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of Settings class
|
||||
* @return Settings
|
||||
*/
|
||||
protected static function getInstance(){
|
||||
if (self::$instance === null) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings class constructor. Set default values and load setting from database.
|
||||
*/
|
||||
protected function __construct() {
|
||||
// Set default values
|
||||
$this->settings = array(
|
||||
'dbversion' => 0,
|
||||
'featuresversion' => 0,
|
||||
'title' => 'Your Company',
|
||||
'hosturl' => 'http://mibew.org',
|
||||
'logo' => '',
|
||||
'usernamepattern' => '{name}',
|
||||
'chat_style' => 'default',
|
||||
'invitation_style' => 'default',
|
||||
'page_style' => 'default',
|
||||
'chattitle' => 'Live Support',
|
||||
'geolink' => 'http://api.hostip.info/get_html.php?ip={ip}',
|
||||
'geolinkparams' => 'width=440,height=100,toolbar=0,scrollbars=0,location=0,status=1,menubar=0,resizable=1',
|
||||
'max_uploaded_file_size' => 100000,
|
||||
'max_connections_from_one_host' => 10,
|
||||
'thread_lifetime' => 600,
|
||||
/**
|
||||
* Settings class constructor. Set default values and load setting from
|
||||
* database.
|
||||
*/
|
||||
protected function __construct()
|
||||
{
|
||||
// Set default values
|
||||
$this->settings = array(
|
||||
'dbversion' => 0,
|
||||
'featuresversion' => 0,
|
||||
'title' => 'Your Company',
|
||||
'hosturl' => 'http://mibew.org',
|
||||
'logo' => '',
|
||||
'usernamepattern' => '{name}',
|
||||
'chat_style' => 'default',
|
||||
'invitation_style' => 'default',
|
||||
'page_style' => 'default',
|
||||
'chattitle' => 'Live Support',
|
||||
'geolink' => 'http://api.hostip.info/get_html.php?ip={ip}',
|
||||
'geolinkparams' => 'width=440,height=100,toolbar=0,scrollbars=0,location=0,status=1,menubar=0,resizable=1',
|
||||
'max_uploaded_file_size' => 100000,
|
||||
'max_connections_from_one_host' => 10,
|
||||
'thread_lifetime' => 600,
|
||||
'email' => '', /* inbox for left messages */
|
||||
'left_messages_locale' => HOME_LOCALE,
|
||||
'sendmessagekey' => 'center',
|
||||
'enableban' => '0',
|
||||
'enablessl' => '0',
|
||||
'forcessl' => '0',
|
||||
'usercanchangename' => '1',
|
||||
'enablegroups' => '0',
|
||||
'enablegroupsisolation' => '0',
|
||||
'enablestatistics' => '1',
|
||||
'enabletracking' => '0',
|
||||
'enablepresurvey' => '1',
|
||||
'surveyaskmail' => '0',
|
||||
'surveyaskgroup' => '1',
|
||||
'surveyaskmessage' => '0',
|
||||
'enablepopupnotification' => '0',
|
||||
'showonlineoperators' => '0',
|
||||
'enablecaptcha' => '0',
|
||||
'online_timeout' => 30, /* Timeout (in seconds) when online operator becomes offline */
|
||||
'updatefrequency_operator' => 2,
|
||||
'updatefrequency_chat' => 2,
|
||||
'statistics_aggregation_interval' => 24 * 60 * 60,
|
||||
'updatefrequency_tracking' => 10,
|
||||
'visitors_limit' => 20, /* Number of visitors to look over */
|
||||
'invitation_lifetime' => 60, /* Lifetime for invitation to chat */
|
||||
'tracking_lifetime' => 600, /* Time to store tracked old visitors' data */
|
||||
'cron_key' => DEFAULT_CRON_KEY,
|
||||
// System values are listed below. They cannot be changed via
|
||||
// administrative interface. Start names for these values from
|
||||
// underscore sign(_).
|
||||
// Unix timestamp when cron job ran last time.
|
||||
'_last_cron_run' => 0,
|
||||
);
|
||||
|
||||
'email' => '', /* inbox for left messages */
|
||||
'left_messages_locale' => HOME_LOCALE,
|
||||
'sendmessagekey' => 'center',
|
||||
// Load values from database
|
||||
$db = Database::getInstance();
|
||||
$rows = $db->query(
|
||||
"SELECT vckey, vcvalue FROM {chatconfig}",
|
||||
null,
|
||||
array('return_rows' => Database::RETURN_ALL_ROWS)
|
||||
);
|
||||
|
||||
'enableban' => '0',
|
||||
'enablessl' => '0',
|
||||
'forcessl' => '0',
|
||||
'usercanchangename' => '1',
|
||||
'enablegroups' => '0',
|
||||
'enablegroupsisolation' => '0',
|
||||
'enablestatistics' => '1',
|
||||
'enabletracking' => '0',
|
||||
'enablepresurvey' => '1',
|
||||
'surveyaskmail' => '0',
|
||||
'surveyaskgroup' => '1',
|
||||
'surveyaskmessage' => '0',
|
||||
'enablepopupnotification' => '0',
|
||||
'showonlineoperators' => '0',
|
||||
'enablecaptcha' => '0',
|
||||
foreach ($rows as $row) {
|
||||
$name = $row['vckey'];
|
||||
$this->settings[$name] = $row['vcvalue'];
|
||||
$this->settingsInDb[$name] = true;
|
||||
}
|
||||
}
|
||||
|
||||
'online_timeout' => 30, /* Timeout (in seconds) when online operator becomes offline */
|
||||
'updatefrequency_operator' => 2,
|
||||
'updatefrequency_chat' => 2,
|
||||
/**
|
||||
* Get setting value.
|
||||
*
|
||||
* @param string $name Variable's name
|
||||
* @return mixed
|
||||
*/
|
||||
public static function get($name)
|
||||
{
|
||||
$instance = self::getInstance();
|
||||
|
||||
'statistics_aggregation_interval' => 24*60*60,
|
||||
return $instance->settings[$name];
|
||||
}
|
||||
|
||||
'updatefrequency_tracking' => 10,
|
||||
'visitors_limit' => 20, /* Number of visitors to look over */
|
||||
'invitation_lifetime' => 60, /* Lifetime for invitation to chat */
|
||||
'tracking_lifetime' => 600, /* Time to store tracked old visitors' data */
|
||||
/**
|
||||
* Set setting value.
|
||||
*
|
||||
* @param string $name Variables's name
|
||||
* @param mixed $value Variable's value
|
||||
*/
|
||||
public static function set($name, $value)
|
||||
{
|
||||
$instance = self::getInstance();
|
||||
$instance->settings[$name] = $value;
|
||||
}
|
||||
|
||||
'cron_key' => DEFAULT_CRON_KEY,
|
||||
/**
|
||||
* Updates settings in database.
|
||||
*/
|
||||
public static function update()
|
||||
{
|
||||
$instance = self::getInstance();
|
||||
$db = Database::getInstance();
|
||||
foreach ($instance->settings as $key => $value) {
|
||||
if (!isset($instance->settingsInDb[$key])) {
|
||||
$db->query(
|
||||
"INSERT INTO {chatconfig} (vckey) VALUES (?)",
|
||||
array($key)
|
||||
);
|
||||
}
|
||||
$db->query(
|
||||
"UPDATE {chatconfig} SET vcvalue=? WHERE vckey=?",
|
||||
array($value, $key)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// System values are listed below. They cannot be changed via
|
||||
// administrative interface. Start names for these values from
|
||||
// underscore sign(_).
|
||||
|
||||
// Unix timestamp when cron job ran last time.
|
||||
'_last_cron_run' => 0
|
||||
);
|
||||
|
||||
// Load values from database
|
||||
$db = Database::getInstance();
|
||||
$rows = $db->query(
|
||||
"select vckey,vcvalue from {chatconfig}",
|
||||
NULL,
|
||||
array('return_rows' => Database::RETURN_ALL_ROWS)
|
||||
);
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$name = $row['vckey'];
|
||||
$this->settings[$name] = $row['vcvalue'];
|
||||
$this->settingsInDb[$name] = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get setting value.
|
||||
*
|
||||
* @param string $name Variable's name
|
||||
* @return mixed
|
||||
*/
|
||||
public static function get($name) {
|
||||
$instance = self::getInstance();
|
||||
return $instance->settings[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set setting value.
|
||||
*
|
||||
* @param string $name Variables's name
|
||||
* @param mixed $value Variable's value
|
||||
*/
|
||||
public static function set($name, $value) {
|
||||
$instance = self::getInstance();
|
||||
$instance->settings[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates settings in database.
|
||||
*/
|
||||
public static function update() {
|
||||
$instance = self::getInstance();
|
||||
$db = Database::getInstance();
|
||||
foreach ($instance->settings as $key => $value) {
|
||||
if (!isset($instance->settingsInDb[$key])) {
|
||||
$db->query(
|
||||
"insert into {chatconfig} (vckey) values (?)",
|
||||
array($key)
|
||||
);
|
||||
}
|
||||
$db->query(
|
||||
"update {chatconfig} set vcvalue=? where vckey=?",
|
||||
array($value, $key)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of destructor
|
||||
*/
|
||||
public function __destruct() {}
|
||||
/**
|
||||
* Implementation of destructor
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -24,146 +24,152 @@ use Mibew\TemplateEngine\ChatTemplateEngine;
|
||||
/**
|
||||
* Represents a chat style
|
||||
*/
|
||||
class ChatStyle extends Style implements StyleInterface {
|
||||
class ChatStyle extends Style implements StyleInterface
|
||||
{
|
||||
/**
|
||||
* Template engine for chat templates.
|
||||
*
|
||||
* @var \Mibew\TemplateEngine\ChatTemplateEngine
|
||||
*/
|
||||
protected $templateEngine;
|
||||
|
||||
/**
|
||||
* Template engine for chat templates.
|
||||
* @var \Mibew\TemplateEngine\ChatTemplateEngine
|
||||
*/
|
||||
protected $templateEngine;
|
||||
/**
|
||||
* Object constructor
|
||||
*
|
||||
* @param string $style_name Name of the style
|
||||
*/
|
||||
public function __construct($style_name)
|
||||
{
|
||||
parent::__construct($style_name);
|
||||
|
||||
/**
|
||||
* Object constructor
|
||||
*
|
||||
* @param string $style_name Name of the style
|
||||
*/
|
||||
public function __construct($style_name) {
|
||||
parent::__construct($style_name);
|
||||
$this->templateEngine = new ChatTemplateEngine(
|
||||
$this->filesPath(),
|
||||
$this->name()
|
||||
);
|
||||
}
|
||||
|
||||
$this->templateEngine = new ChatTemplateEngine(
|
||||
$this->filesPath(),
|
||||
$this->name()
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Builds base path for style files. This path is relative Mibew root and
|
||||
* does not contain neither leading nor trailing slash.
|
||||
*
|
||||
* @return string Base path for style files
|
||||
*/
|
||||
public function filesPath()
|
||||
{
|
||||
return 'styles/dialogs/' . $this->name();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders template file to HTML and send it to the output
|
||||
*
|
||||
* @param string $template_name Name of the template file with neither path
|
||||
* nor extension.
|
||||
* @param array $data Associative array of values that should be used for
|
||||
* substitutions in a template.
|
||||
*/
|
||||
public function render($template_name, $data = array())
|
||||
{
|
||||
start_html_output();
|
||||
echo($this->templateEngine->render($template_name, $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds base path for style files. This path is relative Mibew root and
|
||||
* does not contain neither leading nor trailing slash.
|
||||
*
|
||||
* @return string Base path for style files
|
||||
*/
|
||||
public function filesPath() {
|
||||
return 'styles/dialogs/' . $this->name();
|
||||
}
|
||||
/**
|
||||
* Returns name of the style which shoud be used for the current request.
|
||||
*
|
||||
* Result of the method can depends on user role, requested page or any
|
||||
* other criteria.
|
||||
*
|
||||
* @return string Name of a style
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public static function currentStyle()
|
||||
{
|
||||
// Ceck if request contains chat style
|
||||
$style_name = verify_param("style", "/^\w+$/", "");
|
||||
if (!$style_name) {
|
||||
// Use the default style
|
||||
$style_name = self::defaultStyle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders template file to HTML and send it to the output
|
||||
*
|
||||
* @param string $template_name Name of the template file with neither path
|
||||
* nor extension.
|
||||
* @param array $data Associative array of values that should be used for
|
||||
* substitutions in a template.
|
||||
*/
|
||||
public function render($template_name, $data = array()) {
|
||||
start_html_output();
|
||||
echo($this->templateEngine->render($template_name, $data));
|
||||
}
|
||||
// Get all style list and make sure that in has at least one style.
|
||||
$available_styles = self::availableStyles();
|
||||
if (empty($available_styles)) {
|
||||
throw new \RuntimeException('There are no dialog styles in the system');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns name of the style which shoud be used for the current request.
|
||||
*
|
||||
* Result of the method can depends on user role, requested page or any
|
||||
* other criteria.
|
||||
*
|
||||
* @return string Name of a style
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public static function currentStyle() {
|
||||
// Ceck if request contains chat style
|
||||
$style_name = verifyparam("style", "/^\w+$/", "");
|
||||
if (!$style_name) {
|
||||
// Use the default style
|
||||
$style_name = self::defaultStyle();
|
||||
}
|
||||
// Check if selected style exists. If it does not exist try to fall back
|
||||
// to "default". Finally, if there is no appropriate style in the system
|
||||
// throw an exception.
|
||||
if (in_array($style_name, $available_styles)) {
|
||||
return $style_name;
|
||||
} elseif (in_array('default', $available_styles)) {
|
||||
return 'default';
|
||||
} else {
|
||||
throw new \RuntimeException('There is no appropriate dialog style in the system');
|
||||
}
|
||||
}
|
||||
|
||||
// Get all style list and make sure that in has at least one style.
|
||||
$available_styles = self::availableStyles();
|
||||
if (empty($available_styles)) {
|
||||
throw new \RuntimeException('There are no dialog styles in the system');
|
||||
}
|
||||
/**
|
||||
* Returns name of the style which is used in the system by default.
|
||||
*
|
||||
* @return string Name of a style
|
||||
*/
|
||||
public static function defaultStyle()
|
||||
{
|
||||
// Load value from system settings
|
||||
return Settings::get('chat_style');
|
||||
}
|
||||
|
||||
// Check if selected style exists. If it does not exist try to fall back
|
||||
// to "default". Finally, if there is no appropriate style in the system
|
||||
// throw an exception.
|
||||
if (in_array($style_name, $available_styles)) {
|
||||
return $style_name;
|
||||
} elseif (in_array('default', $available_styles)) {
|
||||
return 'default';
|
||||
} else {
|
||||
throw new \RuntimeException('There is no appropriate dialog style in the system');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Sets style which is used in the system by default
|
||||
*
|
||||
* @param string $style_name Name of a style
|
||||
*/
|
||||
public static function setDefaultStyle($style_name)
|
||||
{
|
||||
Settings::set('chat_style', $style_name);
|
||||
Settings::update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns name of the style which is used in the system by default.
|
||||
*
|
||||
* @return string Name of a style
|
||||
*/
|
||||
public static function defaultStyle() {
|
||||
// Load value from system settings
|
||||
return Settings::get('chat_style');
|
||||
}
|
||||
/**
|
||||
* Returns an array which contains names of available styles.
|
||||
*
|
||||
* @param array List of styles names
|
||||
*/
|
||||
public static function availableStyles()
|
||||
{
|
||||
$styles_root = MIBEW_FS_ROOT . '/styles/dialogs';
|
||||
|
||||
/**
|
||||
* Sets style which is used in the system by default
|
||||
*
|
||||
* @param string $style_name Name of a style
|
||||
*/
|
||||
public static function setDefaultStyle($style_name) {
|
||||
Settings::set('chat_style', $style_name);
|
||||
Settings::update();
|
||||
}
|
||||
return self::getStyleList($styles_root);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array which contains names of available styles.
|
||||
*
|
||||
* @param array List of styles names
|
||||
*/
|
||||
public static function availableStyles() {
|
||||
$styles_root = MIBEW_FS_ROOT . '/styles/dialogs';
|
||||
|
||||
return self::getStyleList($styles_root);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns array of default configurations for concrete style object. This
|
||||
* method uses "Template method" design pattern.
|
||||
*
|
||||
* @return array Default configurations of the style
|
||||
*/
|
||||
protected function defaultConfigurations() {
|
||||
return array(
|
||||
'history' => array(
|
||||
'window_params' => ''
|
||||
),
|
||||
'users' => array(
|
||||
'thread_tag' => 'div',
|
||||
'visitor_tag' => 'div'
|
||||
),
|
||||
'tracked' => array(
|
||||
'user_window_params' => '',
|
||||
'visitor_window_params' => ''
|
||||
),
|
||||
'invitation' => array(
|
||||
'window_params' => ''
|
||||
),
|
||||
'ban' => array(
|
||||
'window_params' => ''
|
||||
),
|
||||
'screenshots' => array()
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Returns array of default configurations for concrete style object. This
|
||||
* method uses "Template method" design pattern.
|
||||
*
|
||||
* @return array Default configurations of the style
|
||||
*/
|
||||
protected function defaultConfigurations()
|
||||
{
|
||||
return array(
|
||||
'history' => array(
|
||||
'window_params' => '',
|
||||
),
|
||||
'users' => array(
|
||||
'thread_tag' => 'div',
|
||||
'visitor_tag' => 'div',
|
||||
),
|
||||
'tracked' => array(
|
||||
'user_window_params' => '',
|
||||
'visitor_window_params' => '',
|
||||
),
|
||||
'invitation' => array(
|
||||
'window_params' => '',
|
||||
),
|
||||
'ban' => array(
|
||||
'window_params' => '',
|
||||
),
|
||||
'screenshots' => array(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -23,89 +23,96 @@ use Mibew\Settings;
|
||||
/**
|
||||
* Represents a style for invitations
|
||||
*/
|
||||
class InvitationStyle extends Style implements StyleInterface {
|
||||
/**
|
||||
* Builds base path for style files. This path is relative Mibew root and
|
||||
* does not contain neither leading nor trailing slash.
|
||||
*
|
||||
* @return string Base path for style files
|
||||
*/
|
||||
public function filesPath() {
|
||||
return 'styles/invitations/' . $this->name();
|
||||
}
|
||||
class InvitationStyle extends Style implements StyleInterface
|
||||
{
|
||||
/**
|
||||
* Builds base path for style files. This path is relative Mibew root and
|
||||
* does not contain neither leading nor trailing slash.
|
||||
*
|
||||
* @return string Base path for style files
|
||||
*/
|
||||
public function filesPath()
|
||||
{
|
||||
return 'styles/invitations/' . $this->name();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads configurations of the style.
|
||||
*
|
||||
* @return array Style configurations
|
||||
*/
|
||||
public function configurations() {
|
||||
return array();
|
||||
}
|
||||
/**
|
||||
* Loads configurations of the style.
|
||||
*
|
||||
* @return array Style configurations
|
||||
*/
|
||||
public function configurations()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stub for StyleInterface::render method.
|
||||
*
|
||||
* The method does not contain actual code because inviation styles are not
|
||||
* renderable now.
|
||||
*/
|
||||
public function render($template_name, $data = array()) {
|
||||
return FALSE;
|
||||
}
|
||||
/**
|
||||
* Stub for StyleInterface::render method.
|
||||
*
|
||||
* The method does not contain actual code because inviation styles are not
|
||||
* renderable now.
|
||||
*/
|
||||
public function render($template_name, $data = array())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns name of the style which shoud be used for the current request.
|
||||
*
|
||||
* Result of the method can depends on user role, requested page or any
|
||||
* other criteria.
|
||||
*
|
||||
* @return string Name of a style
|
||||
*/
|
||||
public static function currentStyle() {
|
||||
// Just use the default style
|
||||
return self::defaultStyle();
|
||||
}
|
||||
/**
|
||||
* Returns name of the style which shoud be used for the current request.
|
||||
*
|
||||
* Result of the method can depends on user role, requested page or any
|
||||
* other criteria.
|
||||
*
|
||||
* @return string Name of a style
|
||||
*/
|
||||
public static function currentStyle()
|
||||
{
|
||||
// Just use the default style
|
||||
return self::defaultStyle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns name of the style which is used in the system by default.
|
||||
*
|
||||
* @return string Name of a style
|
||||
*/
|
||||
public static function defaultStyle() {
|
||||
// Load value from system settings
|
||||
return Settings::get('invitation_style');
|
||||
}
|
||||
/**
|
||||
* Returns name of the style which is used in the system by default.
|
||||
*
|
||||
* @return string Name of a style
|
||||
*/
|
||||
public static function defaultStyle()
|
||||
{
|
||||
// Load value from system settings
|
||||
return Settings::get('invitation_style');
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets style which is used in the system by default
|
||||
*
|
||||
* @param string $style_name Name of a style
|
||||
*/
|
||||
public static function setDefaultStyle($style_name) {
|
||||
Settings::set('invitation_style', $style_name);
|
||||
Settings::update();
|
||||
}
|
||||
/**
|
||||
* Sets style which is used in the system by default
|
||||
*
|
||||
* @param string $style_name Name of a style
|
||||
*/
|
||||
public static function setDefaultStyle($style_name)
|
||||
{
|
||||
Settings::set('invitation_style', $style_name);
|
||||
Settings::update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array which contains names of available styles.
|
||||
*
|
||||
* @param array List of styles names
|
||||
*/
|
||||
public static function availableStyles() {
|
||||
$styles_root = MIBEW_FS_ROOT . '/styles/invitations';
|
||||
/**
|
||||
* Returns an array which contains names of available styles.
|
||||
*
|
||||
* @param array List of styles names
|
||||
*/
|
||||
public static function availableStyles()
|
||||
{
|
||||
$styles_root = MIBEW_FS_ROOT . '/styles/invitations';
|
||||
|
||||
return self::getStyleList($styles_root);
|
||||
}
|
||||
return self::getStyleList($styles_root);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns array of default configurations for concrete style object. This
|
||||
* method uses "Template method" design pattern.
|
||||
*
|
||||
* @return array Default configurations of the style
|
||||
*/
|
||||
protected function defaultConfigurations() {
|
||||
return array();
|
||||
}
|
||||
/**
|
||||
* Returns array of default configurations for concrete style object. This
|
||||
* method uses "Template method" design pattern.
|
||||
*
|
||||
* @return array Default configurations of the style
|
||||
*/
|
||||
protected function defaultConfigurations()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -23,106 +23,112 @@ use Mibew\Settings;
|
||||
/**
|
||||
* Represents a style for operator pages
|
||||
*/
|
||||
class PageStyle extends Style implements StyleInterface {
|
||||
/**
|
||||
* Builds base path for style files. This path is relative Mibew root and
|
||||
* does not contain neither leading nor trailing slash.
|
||||
*
|
||||
* @return string Base path for style files
|
||||
*/
|
||||
public function filesPath() {
|
||||
return 'styles/pages/' . $this->name();
|
||||
}
|
||||
class PageStyle extends Style implements StyleInterface
|
||||
{
|
||||
/**
|
||||
* Builds base path for style files. This path is relative Mibew root and
|
||||
* does not contain neither leading nor trailing slash.
|
||||
*
|
||||
* @return string Base path for style files
|
||||
*/
|
||||
public function filesPath()
|
||||
{
|
||||
return 'styles/pages/' . $this->name();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders template file to HTML and send it to the output
|
||||
*
|
||||
* @param string $template_name Name of the template file with neither path
|
||||
* nor extension.
|
||||
* @param array $data Associative array of values that should be used for
|
||||
* substitutions in a template.
|
||||
*/
|
||||
public function render($template_name, $data = array()) {
|
||||
// Add template root value to page variables
|
||||
$page['stylepath'] = MIBEW_WEB_ROOT . '/' . $this->filesPath();
|
||||
/**
|
||||
* Renders template file to HTML and send it to the output
|
||||
*
|
||||
* @param string $template_name Name of the template file with neither path
|
||||
* nor extension.
|
||||
* @param array $data Associative array of values that should be used for
|
||||
* substitutions in a template.
|
||||
*/
|
||||
public function render($template_name, $data = array())
|
||||
{
|
||||
// Add template root value to page variables
|
||||
$page['stylepath'] = MIBEW_WEB_ROOT . '/' . $this->filesPath();
|
||||
|
||||
// Prepare to output html
|
||||
start_html_output();
|
||||
// Prepare to output html
|
||||
start_html_output();
|
||||
|
||||
// Build full view name. Remove '\' and '/' characters form the
|
||||
// specified view name
|
||||
$full_view_name = MIBEW_FS_ROOT . '/' . $this->filesPath() . '/views/' .
|
||||
str_replace("/\\", '', $template_name) . '.php';
|
||||
// Build full view name. Remove '\' and '/' characters form the
|
||||
// specified view name
|
||||
$full_view_name = MIBEW_FS_ROOT . '/' . $this->filesPath() . '/views/'
|
||||
. str_replace("/\\", '', $template_name) . '.php';
|
||||
|
||||
// $page variable is used in included views files, so we need to create
|
||||
// it as an alias of $data argument.
|
||||
$page = $data;
|
||||
// $page variable is used in included views files, so we need to create
|
||||
// it as an alias of $data argument.
|
||||
$page = $data;
|
||||
|
||||
// Load and execute the view
|
||||
require($full_view_name);
|
||||
}
|
||||
// Load and execute the view
|
||||
require($full_view_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns name of the style which shoud be used for the current request.
|
||||
*
|
||||
* Result of the method can depends on user role, requested page or any
|
||||
* other criteria.
|
||||
*
|
||||
* @return string Name of a style
|
||||
*/
|
||||
public static function currentStyle() {
|
||||
// Just use the default style
|
||||
return self::defaultStyle();
|
||||
}
|
||||
/**
|
||||
* Returns name of the style which shoud be used for the current request.
|
||||
*
|
||||
* Result of the method can depends on user role, requested page or any
|
||||
* other criteria.
|
||||
*
|
||||
* @return string Name of a style
|
||||
*/
|
||||
public static function currentStyle()
|
||||
{
|
||||
// Just use the default style
|
||||
return self::defaultStyle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns name of the style which is used in the system by default.
|
||||
*
|
||||
* @return string Name of a style
|
||||
*/
|
||||
public static function defaultStyle() {
|
||||
// Load value from system settings
|
||||
return Settings::get('page_style');
|
||||
}
|
||||
/**
|
||||
* Returns name of the style which is used in the system by default.
|
||||
*
|
||||
* @return string Name of a style
|
||||
*/
|
||||
public static function defaultStyle()
|
||||
{
|
||||
// Load value from system settings
|
||||
return Settings::get('page_style');
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets style which is used in the system by default
|
||||
*
|
||||
* @param string $style_name Name of a style
|
||||
*/
|
||||
public static function setDefaultStyle($style_name) {
|
||||
Settings::set('page_style', $style_name);
|
||||
Settings::update();
|
||||
}
|
||||
/**
|
||||
* Sets style which is used in the system by default
|
||||
*
|
||||
* @param string $style_name Name of a style
|
||||
*/
|
||||
public static function setDefaultStyle($style_name)
|
||||
{
|
||||
Settings::set('page_style', $style_name);
|
||||
Settings::update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array which contains names of available styles.
|
||||
*
|
||||
* @param array List of styles names
|
||||
*/
|
||||
public static function availableStyles() {
|
||||
$styles_root = MIBEW_FS_ROOT . '/styles/pages';
|
||||
/**
|
||||
* Returns an array which contains names of available styles.
|
||||
*
|
||||
* @param array List of styles names
|
||||
*/
|
||||
public static function availableStyles()
|
||||
{
|
||||
$styles_root = MIBEW_FS_ROOT . '/styles/pages';
|
||||
|
||||
return self::getStyleList($styles_root);
|
||||
}
|
||||
return self::getStyleList($styles_root);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns array of default configurations for concrete style object. This
|
||||
* method uses "Template method" design pattern.
|
||||
*
|
||||
* @return array Default configurations of the style
|
||||
*/
|
||||
protected function defaultConfigurations() {
|
||||
return array(
|
||||
'chat' => array(
|
||||
'window_params' => ''
|
||||
),
|
||||
'mail' => array(
|
||||
'window_params' => ''
|
||||
),
|
||||
'screenshots' => array()
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Returns array of default configurations for concrete style object. This
|
||||
* method uses "Template method" design pattern.
|
||||
*
|
||||
* @return array Default configurations of the style
|
||||
*/
|
||||
protected function defaultConfigurations()
|
||||
{
|
||||
return array(
|
||||
'chat' => array(
|
||||
'window_params' => ''
|
||||
),
|
||||
'mail' => array(
|
||||
'window_params' => ''
|
||||
),
|
||||
'screenshots' => array(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -20,117 +20,123 @@ namespace Mibew\Style;
|
||||
/**
|
||||
* Base class for styles
|
||||
*/
|
||||
abstract class Style {
|
||||
/**
|
||||
* Styles configuration array or NULL by default
|
||||
* @var array|NULL
|
||||
*/
|
||||
protected $cachedConfigurations = NULL;
|
||||
abstract class Style
|
||||
{
|
||||
/**
|
||||
* Styles configuration array or NULL by default
|
||||
*
|
||||
* @var array|NULL
|
||||
*/
|
||||
protected $cachedConfigurations = null;
|
||||
|
||||
/**
|
||||
* This value is used to store name of a style
|
||||
* @var string
|
||||
*/
|
||||
protected $styleName;
|
||||
/**
|
||||
* This value is used to store name of a style
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $styleName;
|
||||
|
||||
/**
|
||||
* Contains cached results of the \Mibew\Style\StyleInterface::getStyleList
|
||||
* method. The lists are keyed by the $root_dir argument of the method.
|
||||
* @var array
|
||||
* @see \Mibew\Style\StyleInterface::getStyleList
|
||||
*/
|
||||
protected static $cachedStyleLists = array();
|
||||
/**
|
||||
* Contains cached results of the \Mibew\Style\StyleInterface::getStyleList
|
||||
* method. The lists are keyed by the $root_dir argument of the method.
|
||||
*
|
||||
* @var array
|
||||
* @see \Mibew\Style\StyleInterface::getStyleList
|
||||
*/
|
||||
protected static $cachedStyleLists = array();
|
||||
|
||||
/**
|
||||
* Object constructor
|
||||
*
|
||||
* @param string $style_name Name of the style
|
||||
*/
|
||||
public function __construct($style_name) {
|
||||
$this->styleName = $style_name;
|
||||
}
|
||||
/**
|
||||
* Object constructor
|
||||
*
|
||||
* @param string $style_name Name of the style
|
||||
*/
|
||||
public function __construct($style_name)
|
||||
{
|
||||
$this->styleName = $style_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns name of the style related with the object
|
||||
*
|
||||
* @return string Name of the style
|
||||
*/
|
||||
public function name() {
|
||||
return $this->styleName;
|
||||
}
|
||||
/**
|
||||
* Returns name of the style related with the object
|
||||
*
|
||||
* @return string Name of the style
|
||||
*/
|
||||
public function name()
|
||||
{
|
||||
return $this->styleName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads configurations of the style. The results is cached in the class
|
||||
* instance.
|
||||
*
|
||||
* @return array Style configurations
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function configurations() {
|
||||
$config_file = MIBEW_FS_ROOT . '/' . $this->filesPath() . '/config.ini';
|
||||
/**
|
||||
* Loads configurations of the style. The results is cached in the class
|
||||
* instance.
|
||||
*
|
||||
* @return array Style configurations
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function configurations()
|
||||
{
|
||||
$config_file = MIBEW_FS_ROOT . '/' . $this->filesPath() . '/config.ini';
|
||||
|
||||
// Check if configurations already loaded. Do not do the job twice.
|
||||
if (is_null($this->cachedConfigurations)) {
|
||||
// Set empty value for configuration array
|
||||
$this->cachedConfigurations = array();
|
||||
// Check if configurations already loaded. Do not do the job twice.
|
||||
if (is_null($this->cachedConfigurations)) {
|
||||
// Set empty value for configuration array
|
||||
$this->cachedConfigurations = array();
|
||||
|
||||
// Try to read configuration file
|
||||
if (!is_readable($config_file)) {
|
||||
throw new \RuntimeException('Cannot read configuration file');
|
||||
}
|
||||
// Try to read configuration file
|
||||
if (!is_readable($config_file)) {
|
||||
throw new \RuntimeException('Cannot read configuration file');
|
||||
}
|
||||
|
||||
// Load configurations from file, merge it with default configs and
|
||||
// cache the result.
|
||||
$loaded_config = parse_ini_file($config_file, true);
|
||||
$default_config = $this->defaultConfigurations();
|
||||
$this->cachedConfigurations = $loaded_config + $default_config;
|
||||
}
|
||||
// Load configurations from file, merge it with default configs and
|
||||
// cache the result.
|
||||
$loaded_config = parse_ini_file($config_file, true);
|
||||
$default_config = $this->defaultConfigurations();
|
||||
$this->cachedConfigurations = $loaded_config + $default_config;
|
||||
}
|
||||
|
||||
return $this->cachedConfigurations;
|
||||
}
|
||||
return $this->cachedConfigurations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets names of styles which are located in the $root_dir.
|
||||
*
|
||||
* @param string $root_dir Root styles directory
|
||||
* @return array List of styles' names
|
||||
*/
|
||||
protected static function getStyleList($root_dir) {
|
||||
// Check if styles list is already stored in the cache
|
||||
if (!isset(self::$cachedStyleLists[$root_dir])) {
|
||||
// Build list of styles for the specified root directory.
|
||||
$style_list = array();
|
||||
if ($handle = opendir($root_dir)) {
|
||||
while (false !== ($file = readdir($handle))) {
|
||||
if (preg_match("/^\w+$/", $file) && is_dir("$root_dir/$file")) {
|
||||
$style_list[$file] = $file;
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
/**
|
||||
* Builds base path for style files. This path is relative Mibew root and
|
||||
* does not contain neither leading nor trailing slash.
|
||||
*
|
||||
* @return string Base path for style files
|
||||
*/
|
||||
abstract public function filesPath();
|
||||
|
||||
// Cache the list
|
||||
self::$cachedStyleLists[$root_dir] = $style_list;
|
||||
}
|
||||
/**
|
||||
* Gets names of styles which are located in the $root_dir.
|
||||
*
|
||||
* @param string $root_dir Root styles directory
|
||||
* @return array List of styles' names
|
||||
*/
|
||||
protected static function getStyleList($root_dir)
|
||||
{
|
||||
// Check if styles list is already stored in the cache
|
||||
if (!isset(self::$cachedStyleLists[$root_dir])) {
|
||||
// Build list of styles for the specified root directory.
|
||||
$style_list = array();
|
||||
if ($handle = opendir($root_dir)) {
|
||||
while (false !== ($file = readdir($handle))) {
|
||||
if (preg_match("/^\w+$/", $file) && is_dir("$root_dir/$file")) {
|
||||
$style_list[$file] = $file;
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
|
||||
return self::$cachedStyleLists[$root_dir];
|
||||
}
|
||||
// Cache the list
|
||||
self::$cachedStyleLists[$root_dir] = $style_list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds base path for style files. This path is relative Mibew root and
|
||||
* does not contain neither leading nor trailing slash.
|
||||
*
|
||||
* @return string Base path for style files
|
||||
*/
|
||||
public abstract function filesPath();
|
||||
return self::$cachedStyleLists[$root_dir];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns array of default configurations for concrete style object. This
|
||||
* method uses "Template method" design pattern.
|
||||
*
|
||||
* @return array Default configurations of the style
|
||||
*/
|
||||
protected abstract function defaultConfigurations();
|
||||
/**
|
||||
* Returns array of default configurations for concrete style object. This
|
||||
* method uses "Template method" design pattern.
|
||||
*
|
||||
* @return array Default configurations of the style
|
||||
*/
|
||||
abstract protected function defaultConfigurations();
|
||||
}
|
||||
|
||||
?>
|
@ -20,69 +20,69 @@ namespace Mibew\Style;
|
||||
/**
|
||||
* Determine interface for specific style class.
|
||||
*/
|
||||
interface StyleInterface {
|
||||
/**
|
||||
* Returns name of the style which shoud be used for the current request.
|
||||
*
|
||||
* Result of the method can depends on user role, requested page or any
|
||||
* other criteria.
|
||||
*
|
||||
* @return string Name of a style
|
||||
*/
|
||||
public static function currentStyle();
|
||||
interface StyleInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns name of the style which is used in the system by default.
|
||||
*
|
||||
* @return string Name of a style
|
||||
*/
|
||||
public static function defaultStyle();
|
||||
/**
|
||||
* Returns name of the style which shoud be used for the current request.
|
||||
*
|
||||
* Result of the method can depends on user role, requested page or any
|
||||
* other criteria.
|
||||
*
|
||||
* @return string Name of a style
|
||||
*/
|
||||
public static function currentStyle();
|
||||
|
||||
/**
|
||||
* Sets style which is used in the system by default
|
||||
*
|
||||
* @param string $style_name Name of a style
|
||||
*/
|
||||
public static function setDefaultStyle($style_name);
|
||||
/**
|
||||
* Returns name of the style which is used in the system by default.
|
||||
*
|
||||
* @return string Name of a style
|
||||
*/
|
||||
public static function defaultStyle();
|
||||
|
||||
/**
|
||||
* Returns an array which contains names of available styles.
|
||||
*
|
||||
* @param array List of styles names
|
||||
*/
|
||||
public static function availableStyles();
|
||||
/**
|
||||
* Sets style which is used in the system by default
|
||||
*
|
||||
* @param string $style_name Name of a style
|
||||
*/
|
||||
public static function setDefaultStyle($style_name);
|
||||
|
||||
/**
|
||||
* Builds base path for style files. This URL is relative Mibew root and
|
||||
* does not contain neither leading nor trailing slash.
|
||||
*
|
||||
* @return string Base path for style files
|
||||
*/
|
||||
public function filesPath();
|
||||
/**
|
||||
* Returns an array which contains names of available styles.
|
||||
*
|
||||
* @param array List of styles names
|
||||
*/
|
||||
public static function availableStyles();
|
||||
|
||||
/**
|
||||
* Loads and returns configurations of the style.
|
||||
*
|
||||
* @param array $name Style's configuration params
|
||||
*/
|
||||
public function configurations();
|
||||
/**
|
||||
* Builds base path for style files. This URL is relative Mibew root and
|
||||
* does not contain neither leading nor trailing slash.
|
||||
*
|
||||
* @return string Base path for style files
|
||||
*/
|
||||
public function filesPath();
|
||||
|
||||
/**
|
||||
* Returns name of the style related with the object
|
||||
*
|
||||
* @return string Name of the style
|
||||
*/
|
||||
public function name();
|
||||
/**
|
||||
* Loads and returns configurations of the style.
|
||||
*
|
||||
* @param array $name Style's configuration params
|
||||
*/
|
||||
public function configurations();
|
||||
|
||||
/**
|
||||
* Renders template file to HTML and send it to the output
|
||||
*
|
||||
* @param string $template_name Name of the template file with neither path
|
||||
* nor extension.
|
||||
* @param array $data Associative array of values that should be used for
|
||||
* substitutions in a template.
|
||||
*/
|
||||
public function render($template_name, $data = array());
|
||||
/**
|
||||
* Returns name of the style related with the object
|
||||
*
|
||||
* @return string Name of the style
|
||||
*/
|
||||
public function name();
|
||||
|
||||
/**
|
||||
* Renders template file to HTML and send it to the output
|
||||
*
|
||||
* @param string $template_name Name of the template file with neither path
|
||||
* nor extension.
|
||||
* @param array $data Associative array of values that should be used for
|
||||
* substitutions in a template.
|
||||
*/
|
||||
public function render($template_name, $data = array());
|
||||
}
|
||||
|
||||
?>
|
@ -20,235 +20,243 @@ namespace Mibew\TemplateEngine;
|
||||
/**
|
||||
* Simple template engine for chat templates
|
||||
*/
|
||||
class ChatTemplateEngine {
|
||||
class ChatTemplateEngine
|
||||
{
|
||||
/**
|
||||
* Regular expression for conditional blocks in templates
|
||||
*/
|
||||
const IF_REGEXP = "/\\\${(if|ifnot):([\w\.]+)}(.*?)(\\\${else:\\2}.*?)?\\\${endif:\\2}/s";
|
||||
/**
|
||||
* Path to teplates relative to MIBEW_FS_ROOT.
|
||||
* @var string
|
||||
*/
|
||||
protected $stylePath;
|
||||
|
||||
/**
|
||||
* Regular expression for conditional blocks in templates
|
||||
*/
|
||||
const IF_REGEXP = "/\\\${(if|ifnot):([\w\.]+)}(.*?)(\\\${else:\\2}.*?)?\\\${endif:\\2}/s";
|
||||
/**
|
||||
* Machine name of the templates style.
|
||||
* @var string
|
||||
*/
|
||||
protected $styleName;
|
||||
|
||||
/**
|
||||
* Path to teplates relative to MIBEW_FS_ROOT.
|
||||
* @var string
|
||||
*/
|
||||
protected $stylePath;
|
||||
/**
|
||||
* Data for the currently rendering template. Unfortunately there is no
|
||||
* another place to store these data for used chat templates logic.
|
||||
* @var array
|
||||
*/
|
||||
protected $templateData;
|
||||
|
||||
/**
|
||||
* Machine name of the templates style.
|
||||
* @var string
|
||||
*/
|
||||
protected $styleName;
|
||||
/**
|
||||
* Flatten data for the currently rendering template.
|
||||
* @var array
|
||||
*/
|
||||
protected $flattenTemplateData;
|
||||
|
||||
/**
|
||||
* Data for the currently rendering template. Unfortunately there is no
|
||||
* another place to store these data for used chat templates logic.
|
||||
* @var array
|
||||
*/
|
||||
protected $templateData;
|
||||
/**
|
||||
* Constructs an instance of the template engine.
|
||||
*
|
||||
* @param string $style_path Path to the style relative to MIBEW_FS_ROOT.
|
||||
* @param string $style_name Machine name of the templates style.
|
||||
*/
|
||||
public function __construct($style_path, $style_name)
|
||||
{
|
||||
$this->stylePath = $style_path;
|
||||
$this->styleName = $style_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flatten data for the currently rendering template.
|
||||
* @var array
|
||||
*/
|
||||
protected $flattenTemplateData;
|
||||
/**
|
||||
* Renders template and returns HTML for it.
|
||||
*
|
||||
* @param string $template_name Name of a template with neither path nor
|
||||
* extension.
|
||||
* @param array $data Data for substitutions.
|
||||
* @return string Rendered HTML markup.
|
||||
*/
|
||||
public function render($template_name, $data)
|
||||
{
|
||||
$this->flattenTemplateData = array_flatten_recursive($data);
|
||||
$this->templateData = $data;
|
||||
$contents = $this->getTemplateFileContent($template_name);
|
||||
|
||||
/**
|
||||
* Constructs an instance of the template engine.
|
||||
*
|
||||
* @param string $style_path Path to the style relative to MIBEW_FS_ROOT.
|
||||
* @param string $style_name Machine name of the templates style.
|
||||
*/
|
||||
public function __construct($style_path, $style_name) {
|
||||
$this->stylePath = $style_path;
|
||||
$this->styleName = $style_name;
|
||||
}
|
||||
return $this->expandText($contents);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders template and returns HTML for it.
|
||||
*
|
||||
* @param string $template_name Name of a template with neither path nor
|
||||
* extension.
|
||||
* @param array $data Data for substitutions.
|
||||
* @return string Rendered HTML markup.
|
||||
*/
|
||||
public function render($template_name, $data) {
|
||||
$this->flattenTemplateData = array_flatten_recursive($data);
|
||||
$this->templateData = $data;
|
||||
$contents = $this->getTemplateFileContent($template_name);
|
||||
return $this->expandText($contents);
|
||||
}
|
||||
/**
|
||||
* Check if condition form conditional construction is true.
|
||||
*
|
||||
* @param string $condition Condition name. Can be any element name of the
|
||||
* template data array.
|
||||
*/
|
||||
public function checkCondition($condition)
|
||||
{
|
||||
if ($condition == 'errors') {
|
||||
return !empty($this->templateData['errors'])
|
||||
&& is_array($this->templateData['errors']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if condition form conditional construction is true.
|
||||
*
|
||||
* @param string $condition Condition name. Can be any element name of the
|
||||
* template data array.
|
||||
*/
|
||||
public function checkCondition($condition) {
|
||||
if ($condition == 'errors') {
|
||||
return !empty($this->templateData['errors'])
|
||||
&& is_array($this->templateData['errors']);
|
||||
}
|
||||
return !empty($this->flattenTemplateData[$condition]);
|
||||
}
|
||||
return !empty($this->flattenTemplateData[$condition]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process conditional construction. This function is a callback for
|
||||
* "preg_replace_callback" function.
|
||||
*
|
||||
* @param array $matches matches passed from "preg_replace_callback"
|
||||
* function.
|
||||
* @return string One of conditional blocks depending of conditional value.
|
||||
*/
|
||||
public function expandCondition($matches) {
|
||||
$value = $this->checkCondition($matches[2]) ^ ($matches[1] != 'if');
|
||||
/**
|
||||
* Process conditional construction. This function is a callback for
|
||||
* "preg_replace_callback" function.
|
||||
*
|
||||
* @param array $matches matches passed from "preg_replace_callback"
|
||||
* function.
|
||||
* @return string One of conditional blocks depending of conditional value.
|
||||
*/
|
||||
public function expandCondition($matches)
|
||||
{
|
||||
$value = $this->checkCondition($matches[2]) ^ ($matches[1] != 'if');
|
||||
|
||||
if ($value) {
|
||||
return preg_replace_callback(
|
||||
self::IF_REGEXP,
|
||||
array($this, "expandCondition"),
|
||||
$matches[3]
|
||||
);
|
||||
} else if (isset($matches[4])) {
|
||||
return preg_replace_callback(
|
||||
self::IF_REGEXP,
|
||||
array($this, "expandCondition"),
|
||||
substr($matches[4], strpos($matches[4], "}") + 1)
|
||||
);
|
||||
}
|
||||
if ($value) {
|
||||
return preg_replace_callback(
|
||||
self::IF_REGEXP,
|
||||
array($this, "expandCondition"),
|
||||
$matches[3]
|
||||
);
|
||||
} elseif (isset($matches[4])) {
|
||||
return preg_replace_callback(
|
||||
self::IF_REGEXP,
|
||||
array($this, "expandCondition"),
|
||||
substr($matches[4], strpos($matches[4], "}") + 1)
|
||||
);
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace variables in template with its values. This function is a
|
||||
* callback for "preg_replace_callback" function.
|
||||
*
|
||||
* @param array $matches matches passed from "preg_replace_callback"
|
||||
* function.
|
||||
* @return string Value of the variable or empty string if the value was not
|
||||
* passed in with template data.
|
||||
*/
|
||||
public function expandVar($matches) {
|
||||
$prefix = $matches[1];
|
||||
$var = $matches[2];
|
||||
/**
|
||||
* Replace variables in template with its values. This function is a
|
||||
* callback for "preg_replace_callback" function.
|
||||
*
|
||||
* @param array $matches matches passed from "preg_replace_callback"
|
||||
* function.
|
||||
* @return string Value of the variable or empty string if the value was not
|
||||
* passed in with template data.
|
||||
*/
|
||||
public function expandVar($matches)
|
||||
{
|
||||
$prefix = $matches[1];
|
||||
$var = $matches[2];
|
||||
|
||||
if (!$prefix) {
|
||||
if ($var == 'mibewroot') {
|
||||
return MIBEW_WEB_ROOT;
|
||||
} elseif ($var == 'tplroot') {
|
||||
return MIBEW_WEB_ROOT . "/" . $this->stylePath;
|
||||
} elseif ($var == 'styleid') {
|
||||
return $this->styleName;
|
||||
} elseif ($var == 'pagination') {
|
||||
return generate_pagination(
|
||||
MIBEW_WEB_ROOT . '/' . $this->stylePath,
|
||||
$this->templateData['pagination']
|
||||
);
|
||||
} elseif ($var == 'errors' || $var == 'harderrors') {
|
||||
if (
|
||||
!empty($this->templateData['errors'])
|
||||
&& is_array($this->templateData['errors'])
|
||||
) {
|
||||
$result = getlocal("$var.header");
|
||||
foreach ($this->templateData['errors'] as $e) {
|
||||
$result .= getlocal("errors.prefix")
|
||||
. $e
|
||||
. getlocal("errors.suffix");
|
||||
}
|
||||
$result .= getlocal("errors.footer");
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
if (!$prefix) {
|
||||
if ($var == 'mibewroot') {
|
||||
return MIBEW_WEB_ROOT;
|
||||
} elseif ($var == 'tplroot') {
|
||||
return MIBEW_WEB_ROOT . "/" . $this->stylePath;
|
||||
} elseif ($var == 'styleid') {
|
||||
return $this->styleName;
|
||||
} elseif ($var == 'pagination') {
|
||||
return generate_pagination(
|
||||
MIBEW_WEB_ROOT . '/' . $this->stylePath,
|
||||
$this->templateData['pagination']
|
||||
);
|
||||
} elseif ($var == 'errors' || $var == 'harderrors') {
|
||||
$errors_data_exists = !empty($this->templateData['errors'])
|
||||
&& is_array($this->templateData['errors']);
|
||||
if ($errors_data_exists) {
|
||||
$result = getlocal("$var.header");
|
||||
foreach ($this->templateData['errors'] as $e) {
|
||||
$result .= getlocal("errors.prefix")
|
||||
. $e
|
||||
. getlocal("errors.suffix");
|
||||
}
|
||||
$result .= getlocal("errors.footer");
|
||||
|
||||
} elseif ($prefix == 'msg:' || $prefix == 'msgjs:' || $prefix == 'url:') {
|
||||
$message = '';
|
||||
if (strpos($var, ",") !== false) {
|
||||
$pos = strpos($var, ",");
|
||||
$param = substr($var, $pos + 1);
|
||||
$var = substr($var, 0, $pos);
|
||||
$message = getlocal2($var, array($this->flattenTemplateData[$param]));
|
||||
} else {
|
||||
$message = getlocal($var);
|
||||
}
|
||||
if ($prefix == 'msgjs:') {
|
||||
return json_encode($message);
|
||||
}
|
||||
return $message;
|
||||
} else if ($prefix == 'form:') {
|
||||
return form_value($this->templateData, $var);
|
||||
} else if ($prefix == 'page:' || $prefix == 'pagejs:') {
|
||||
$message = isset($this->flattenTemplateData[$var])
|
||||
? $this->flattenTemplateData[$var]
|
||||
: "";
|
||||
return ($prefix == 'pagejs:') ? json_encode($message) : $message;
|
||||
} else if ($prefix == 'if:' || $prefix == 'else:' || $prefix == 'endif:' || $prefix == 'ifnot:') {
|
||||
return "<!-- wrong $prefix:$var -->";
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
} elseif ($prefix == 'msg:' || $prefix == 'msgjs:' || $prefix == 'url:') {
|
||||
$message = '';
|
||||
if (strpos($var, ",") !== false) {
|
||||
$pos = strpos($var, ",");
|
||||
$param = substr($var, $pos + 1);
|
||||
$var = substr($var, 0, $pos);
|
||||
$message = getlocal2($var, array($this->flattenTemplateData[$param]));
|
||||
} else {
|
||||
$message = getlocal($var);
|
||||
}
|
||||
if ($prefix == 'msgjs:') {
|
||||
return json_encode($message);
|
||||
}
|
||||
return $message;
|
||||
} elseif ($prefix == 'form:') {
|
||||
return form_value($this->templateData, $var);
|
||||
} elseif ($prefix == 'page:' || $prefix == 'pagejs:') {
|
||||
$message = isset($this->flattenTemplateData[$var])
|
||||
? $this->flattenTemplateData[$var]
|
||||
: "";
|
||||
|
||||
return "";
|
||||
}
|
||||
return ($prefix == 'pagejs:') ? json_encode($message) : $message;
|
||||
} elseif ($prefix == 'if:' || $prefix == 'else:' || $prefix == 'endif:' || $prefix == 'ifnot:') {
|
||||
return "<!-- wrong $prefix:$var -->";
|
||||
}
|
||||
|
||||
/**
|
||||
* Process "include" control structure. This function is a callback for
|
||||
* "preg_replace_callback" function.
|
||||
*
|
||||
* @param array $matches matches passed from "preg_replace_callback"
|
||||
* function.
|
||||
* @return string Contents of including file
|
||||
*/
|
||||
public function expandInclude($matches) {
|
||||
$template_name = $matches[1];
|
||||
return $this->getTemplateFileContent($template_name);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts all control structures to markup.
|
||||
*
|
||||
* @param string $text Source text
|
||||
* @return string Markup with no control structures
|
||||
*/
|
||||
public function expandText($text) {
|
||||
$text = preg_replace_callback(
|
||||
"/\\\${include:([\w\.]+)}/",
|
||||
array($this, "expandInclude"),
|
||||
$text
|
||||
);
|
||||
/**
|
||||
* Process "include" control structure. This function is a callback for
|
||||
* "preg_replace_callback" function.
|
||||
*
|
||||
* @param array $matches matches passed from "preg_replace_callback"
|
||||
* function.
|
||||
* @return string Contents of including file
|
||||
*/
|
||||
public function expandInclude($matches)
|
||||
{
|
||||
$template_name = $matches[1];
|
||||
|
||||
$text = preg_replace_callback(
|
||||
self::IF_REGEXP,
|
||||
array($this, "expandCondition"),
|
||||
$text
|
||||
);
|
||||
return $this->getTemplateFileContent($template_name);
|
||||
}
|
||||
|
||||
return preg_replace_callback(
|
||||
"/\\\${(\w+:)?([\w\.,]+)}/",
|
||||
array($this, "expandVar"),
|
||||
$text
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Converts all control structures to markup.
|
||||
*
|
||||
* @param string $text Source text
|
||||
* @return string Markup with no control structures
|
||||
*/
|
||||
public function expandText($text)
|
||||
{
|
||||
$text = preg_replace_callback(
|
||||
"/\\\${include:([\w\.]+)}/",
|
||||
array($this, "expandInclude"),
|
||||
$text
|
||||
);
|
||||
|
||||
/**
|
||||
* Loads content of a template file.
|
||||
*
|
||||
* @param string $template_name Name of a template file to load.
|
||||
* @return string Template file's content.
|
||||
*
|
||||
* @throws \RuntimeException If there is no such template file or the file
|
||||
* is not readable.
|
||||
*/
|
||||
protected function getTemplateFileContent($template_name) {
|
||||
$full_file_path = MIBEW_FS_ROOT . '/' . $this->stylePath .
|
||||
'/templates/' . $template_name . '.tpl';
|
||||
$text = preg_replace_callback(
|
||||
self::IF_REGEXP,
|
||||
array($this, "expandCondition"),
|
||||
$text
|
||||
);
|
||||
|
||||
if (!is_readable($full_file_path)) {
|
||||
throw new \RuntimeException(
|
||||
'Cannot load template file: "' . $full_file_path . '"'
|
||||
);
|
||||
}
|
||||
return preg_replace_callback(
|
||||
"/\\\${(\w+:)?([\w\.,]+)}/",
|
||||
array($this, "expandVar"),
|
||||
$text
|
||||
);
|
||||
}
|
||||
|
||||
return file_get_contents($full_file_path);
|
||||
}
|
||||
/**
|
||||
* Loads content of a template file.
|
||||
*
|
||||
* @param string $template_name Name of a template file to load.
|
||||
* @return string Template file's content.
|
||||
*
|
||||
* @throws \RuntimeException If there is no such template file or the file
|
||||
* is not readable.
|
||||
*/
|
||||
protected function getTemplateFileContent($template_name)
|
||||
{
|
||||
$full_file_path = MIBEW_FS_ROOT . '/' . $this->stylePath
|
||||
. '/templates/' . $template_name . '.tpl';
|
||||
|
||||
if (!is_readable($full_file_path)) {
|
||||
throw new \RuntimeException(
|
||||
'Cannot load template file: "' . $full_file_path . '"'
|
||||
);
|
||||
}
|
||||
|
||||
return file_get_contents($full_file_path);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
File diff suppressed because it is too large
Load Diff
@ -17,23 +17,23 @@
|
||||
|
||||
/**
|
||||
* Autoloader for classes which implements PSR-0 standard.
|
||||
*
|
||||
* @param string $class_name Fully qualified name of the class
|
||||
*/
|
||||
function class_autoload($class_name) {
|
||||
$base_dir = MIBEW_FS_ROOT . DIRECTORY_SEPARATOR . 'libs' .
|
||||
DIRECTORY_SEPARATOR . 'classes';
|
||||
function class_autoload($class_name)
|
||||
{
|
||||
$base_dir = MIBEW_FS_ROOT . DIRECTORY_SEPARATOR . 'libs' .
|
||||
DIRECTORY_SEPARATOR . 'classes';
|
||||
|
||||
$class_name = ltrim($class_name, '\\');
|
||||
$file_name = '';
|
||||
$file_name = '';
|
||||
$namespace = '';
|
||||
if ($last_ns_pos = strrpos($class_name, '\\')) {
|
||||
$namespace = substr($class_name, 0, $last_ns_pos);
|
||||
$class_name = substr($class_name, $last_ns_pos + 1);
|
||||
$file_name = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
|
||||
$file_name = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
|
||||
}
|
||||
$file_name .= str_replace('_', DIRECTORY_SEPARATOR, $class_name) . '.php';
|
||||
|
||||
require $base_dir . DIRECTORY_SEPARATOR . $file_name;
|
||||
}
|
||||
|
||||
?>
|
@ -20,13 +20,13 @@
|
||||
*
|
||||
* @param string $file Path to Configuration file
|
||||
* @return boolean|array Array of configurations or boolean false if file can
|
||||
* not be read.
|
||||
* not be read.
|
||||
*/
|
||||
function read_config_file($file) {
|
||||
if (! is_readable($file)) {
|
||||
return false;
|
||||
}
|
||||
return parse_ini_file($file, true);
|
||||
}
|
||||
function read_config_file($file)
|
||||
{
|
||||
if (!is_readable($file)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
?>
|
||||
return parse_ini_file($file, true);
|
||||
}
|
||||
|
@ -34,15 +34,15 @@ define('FEATURES_VERSION', '2.0');
|
||||
* Prefix for session variables.
|
||||
* Provide an ability to instal several mibew instances on one server.
|
||||
*/
|
||||
define('SESSION_PREFIX', md5($mysqlhost.'##'.$mysqldb.'##'.$mysqlprefix) . '_');
|
||||
define('SESSION_PREFIX', md5($mysqlhost . '##' . $mysqldb . '##' . $mysqlprefix) . '_');
|
||||
|
||||
/**
|
||||
* Default value for cron security key.
|
||||
* Another value can be set at operator/settings.php page.
|
||||
*/
|
||||
define('DEFAULT_CRON_KEY', md5(
|
||||
$mysqlhost . '##' . $mysqldb . '##' . $mysqllogin. '##' .
|
||||
$mysqlpass . '##' . $mysqlprefix . '##'
|
||||
$mysqlhost . '##' . $mysqldb . '##' . $mysqllogin . '##'
|
||||
. $mysqlpass . '##' . $mysqlprefix . '##'
|
||||
));
|
||||
|
||||
/**
|
||||
@ -54,5 +54,3 @@ define('VISITOR_COOKIE_NAME', 'MIBEW_VisitorID');
|
||||
* Internal system encoding
|
||||
*/
|
||||
define('MIBEW_ENCODING', $mibew_encoding);
|
||||
|
||||
?>
|
@ -16,36 +16,34 @@
|
||||
*/
|
||||
|
||||
$_utf8win1251 = array(
|
||||
"\xD0\x90" => "\xC0", "\xD0\x91" => "\xC1", "\xD0\x92" => "\xC2", "\xD0\x93" => "\xC3", "\xD0\x94" => "\xC4",
|
||||
"\xD0\x95" => "\xC5", "\xD0\x81" => "\xA8", "\xD0\x96" => "\xC6", "\xD0\x97" => "\xC7", "\xD0\x98" => "\xC8",
|
||||
"\xD0\x99" => "\xC9", "\xD0\x9A" => "\xCA", "\xD0\x9B" => "\xCB", "\xD0\x9C" => "\xCC", "\xD0\x9D" => "\xCD",
|
||||
"\xD0\x9E" => "\xCE", "\xD0\x9F" => "\xCF", "\xD0\xA0" => "\xD0", "\xD0\xA1" => "\xD1", "\xD0\xA2" => "\xD2",
|
||||
"\xD0\xA3" => "\xD3", "\xD0\xA4" => "\xD4", "\xD0\xA5" => "\xD5", "\xD0\xA6" => "\xD6", "\xD0\xA7" => "\xD7",
|
||||
"\xD0\xA8" => "\xD8", "\xD0\xA9" => "\xD9", "\xD0\xAA" => "\xDA", "\xD0\xAB" => "\xDB", "\xD0\xAC" => "\xDC",
|
||||
"\xD0\xAD" => "\xDD", "\xD0\xAE" => "\xDE", "\xD0\xAF" => "\xDF", "\xD0\x87" => "\xAF", "\xD0\x86" => "\xB2",
|
||||
"\xD0\x84" => "\xAA", "\xD0\x8E" => "\xA1", "\xD0\xB0" => "\xE0", "\xD0\xB1" => "\xE1", "\xD0\xB2" => "\xE2",
|
||||
"\xD0\xB3" => "\xE3", "\xD0\xB4" => "\xE4", "\xD0\xB5" => "\xE5", "\xD1\x91" => "\xB8", "\xD0\xB6" => "\xE6",
|
||||
"\xD0\xB7" => "\xE7", "\xD0\xB8" => "\xE8", "\xD0\xB9" => "\xE9", "\xD0\xBA" => "\xEA", "\xD0\xBB" => "\xEB",
|
||||
"\xD0\xBC" => "\xEC", "\xD0\xBD" => "\xED", "\xD0\xBE" => "\xEE", "\xD0\xBF" => "\xEF", "\xD1\x80" => "\xF0",
|
||||
"\xD1\x81" => "\xF1", "\xD1\x82" => "\xF2", "\xD1\x83" => "\xF3", "\xD1\x84" => "\xF4", "\xD1\x85" => "\xF5",
|
||||
"\xD1\x86" => "\xF6", "\xD1\x87" => "\xF7", "\xD1\x88" => "\xF8", "\xD1\x89" => "\xF9", "\xD1\x8A" => "\xFA",
|
||||
"\xD1\x8B" => "\xFB", "\xD1\x8C" => "\xFC", "\xD1\x8D" => "\xFD", "\xD1\x8E" => "\xFE", "\xD1\x8F" => "\xFF",
|
||||
"\xD1\x96" => "\xB3", "\xD1\x97" => "\xBF", "\xD1\x94" => "\xBA", "\xD1\x9E" => "\xA2");
|
||||
"\xD0\x90" => "\xC0", "\xD0\x91" => "\xC1", "\xD0\x92" => "\xC2", "\xD0\x93" => "\xC3", "\xD0\x94" => "\xC4",
|
||||
"\xD0\x95" => "\xC5", "\xD0\x81" => "\xA8", "\xD0\x96" => "\xC6", "\xD0\x97" => "\xC7", "\xD0\x98" => "\xC8",
|
||||
"\xD0\x99" => "\xC9", "\xD0\x9A" => "\xCA", "\xD0\x9B" => "\xCB", "\xD0\x9C" => "\xCC", "\xD0\x9D" => "\xCD",
|
||||
"\xD0\x9E" => "\xCE", "\xD0\x9F" => "\xCF", "\xD0\xA0" => "\xD0", "\xD0\xA1" => "\xD1", "\xD0\xA2" => "\xD2",
|
||||
"\xD0\xA3" => "\xD3", "\xD0\xA4" => "\xD4", "\xD0\xA5" => "\xD5", "\xD0\xA6" => "\xD6", "\xD0\xA7" => "\xD7",
|
||||
"\xD0\xA8" => "\xD8", "\xD0\xA9" => "\xD9", "\xD0\xAA" => "\xDA", "\xD0\xAB" => "\xDB", "\xD0\xAC" => "\xDC",
|
||||
"\xD0\xAD" => "\xDD", "\xD0\xAE" => "\xDE", "\xD0\xAF" => "\xDF", "\xD0\x87" => "\xAF", "\xD0\x86" => "\xB2",
|
||||
"\xD0\x84" => "\xAA", "\xD0\x8E" => "\xA1", "\xD0\xB0" => "\xE0", "\xD0\xB1" => "\xE1", "\xD0\xB2" => "\xE2",
|
||||
"\xD0\xB3" => "\xE3", "\xD0\xB4" => "\xE4", "\xD0\xB5" => "\xE5", "\xD1\x91" => "\xB8", "\xD0\xB6" => "\xE6",
|
||||
"\xD0\xB7" => "\xE7", "\xD0\xB8" => "\xE8", "\xD0\xB9" => "\xE9", "\xD0\xBA" => "\xEA", "\xD0\xBB" => "\xEB",
|
||||
"\xD0\xBC" => "\xEC", "\xD0\xBD" => "\xED", "\xD0\xBE" => "\xEE", "\xD0\xBF" => "\xEF", "\xD1\x80" => "\xF0",
|
||||
"\xD1\x81" => "\xF1", "\xD1\x82" => "\xF2", "\xD1\x83" => "\xF3", "\xD1\x84" => "\xF4", "\xD1\x85" => "\xF5",
|
||||
"\xD1\x86" => "\xF6", "\xD1\x87" => "\xF7", "\xD1\x88" => "\xF8", "\xD1\x89" => "\xF9", "\xD1\x8A" => "\xFA",
|
||||
"\xD1\x8B" => "\xFB", "\xD1\x8C" => "\xFC", "\xD1\x8D" => "\xFD", "\xD1\x8E" => "\xFE", "\xD1\x8F" => "\xFF",
|
||||
"\xD1\x96" => "\xB3", "\xD1\x97" => "\xBF", "\xD1\x94" => "\xBA", "\xD1\x9E" => "\xA2");
|
||||
$_win1251utf8 = array(
|
||||
"\xC0" => "\xD0\x90", "\xC1" => "\xD0\x91", "\xC2" => "\xD0\x92", "\xC3" => "\xD0\x93", "\xC4" => "\xD0\x94",
|
||||
"\xC5" => "\xD0\x95", "\xA8" => "\xD0\x81", "\xC6" => "\xD0\x96", "\xC7" => "\xD0\x97", "\xC8" => "\xD0\x98",
|
||||
"\xC9" => "\xD0\x99", "\xCA" => "\xD0\x9A", "\xCB" => "\xD0\x9B", "\xCC" => "\xD0\x9C", "\xCD" => "\xD0\x9D",
|
||||
"\xCE" => "\xD0\x9E", "\xCF" => "\xD0\x9F", "\xD0" => "\xD0\xA0", "\xD1" => "\xD0\xA1", "\xD2" => "\xD0\xA2",
|
||||
"\xD3" => "\xD0\xA3", "\xD4" => "\xD0\xA4", "\xD5" => "\xD0\xA5", "\xD6" => "\xD0\xA6", "\xD7" => "\xD0\xA7",
|
||||
"\xD8" => "\xD0\xA8", "\xD9" => "\xD0\xA9", "\xDA" => "\xD0\xAA", "\xDB" => "\xD0\xAB", "\xDC" => "\xD0\xAC",
|
||||
"\xDD" => "\xD0\xAD", "\xDE" => "\xD0\xAE", "\xDF" => "\xD0\xAF", "\xAF" => "\xD0\x87", "\xB2" => "\xD0\x86",
|
||||
"\xAA" => "\xD0\x84", "\xA1" => "\xD0\x8E", "\xE0" => "\xD0\xB0", "\xE1" => "\xD0\xB1", "\xE2" => "\xD0\xB2",
|
||||
"\xE3" => "\xD0\xB3", "\xE4" => "\xD0\xB4", "\xE5" => "\xD0\xB5", "\xB8" => "\xD1\x91", "\xE6" => "\xD0\xB6",
|
||||
"\xE7" => "\xD0\xB7", "\xE8" => "\xD0\xB8", "\xE9" => "\xD0\xB9", "\xEA" => "\xD0\xBA", "\xEB" => "\xD0\xBB",
|
||||
"\xEC" => "\xD0\xBC", "\xED" => "\xD0\xBD", "\xEE" => "\xD0\xBE", "\xEF" => "\xD0\xBF", "\xF0" => "\xD1\x80",
|
||||
"\xF1" => "\xD1\x81", "\xF2" => "\xD1\x82", "\xF3" => "\xD1\x83", "\xF4" => "\xD1\x84", "\xF5" => "\xD1\x85",
|
||||
"\xF6" => "\xD1\x86", "\xF7" => "\xD1\x87", "\xF8" => "\xD1\x88", "\xF9" => "\xD1\x89", "\xFA" => "\xD1\x8A",
|
||||
"\xFB" => "\xD1\x8B", "\xFC" => "\xD1\x8C", "\xFD" => "\xD1\x8D", "\xFE" => "\xD1\x8E", "\xFF" => "\xD1\x8F",
|
||||
"\xB3" => "\xD1\x96", "\xBF" => "\xD1\x97", "\xBA" => "\xD1\x94", "\xA2" => "\xD1\x9E");
|
||||
|
||||
?>
|
||||
"\xC0" => "\xD0\x90", "\xC1" => "\xD0\x91", "\xC2" => "\xD0\x92", "\xC3" => "\xD0\x93", "\xC4" => "\xD0\x94",
|
||||
"\xC5" => "\xD0\x95", "\xA8" => "\xD0\x81", "\xC6" => "\xD0\x96", "\xC7" => "\xD0\x97", "\xC8" => "\xD0\x98",
|
||||
"\xC9" => "\xD0\x99", "\xCA" => "\xD0\x9A", "\xCB" => "\xD0\x9B", "\xCC" => "\xD0\x9C", "\xCD" => "\xD0\x9D",
|
||||
"\xCE" => "\xD0\x9E", "\xCF" => "\xD0\x9F", "\xD0" => "\xD0\xA0", "\xD1" => "\xD0\xA1", "\xD2" => "\xD0\xA2",
|
||||
"\xD3" => "\xD0\xA3", "\xD4" => "\xD0\xA4", "\xD5" => "\xD0\xA5", "\xD6" => "\xD0\xA6", "\xD7" => "\xD0\xA7",
|
||||
"\xD8" => "\xD0\xA8", "\xD9" => "\xD0\xA9", "\xDA" => "\xD0\xAA", "\xDB" => "\xD0\xAB", "\xDC" => "\xD0\xAC",
|
||||
"\xDD" => "\xD0\xAD", "\xDE" => "\xD0\xAE", "\xDF" => "\xD0\xAF", "\xAF" => "\xD0\x87", "\xB2" => "\xD0\x86",
|
||||
"\xAA" => "\xD0\x84", "\xA1" => "\xD0\x8E", "\xE0" => "\xD0\xB0", "\xE1" => "\xD0\xB1", "\xE2" => "\xD0\xB2",
|
||||
"\xE3" => "\xD0\xB3", "\xE4" => "\xD0\xB4", "\xE5" => "\xD0\xB5", "\xB8" => "\xD1\x91", "\xE6" => "\xD0\xB6",
|
||||
"\xE7" => "\xD0\xB7", "\xE8" => "\xD0\xB8", "\xE9" => "\xD0\xB9", "\xEA" => "\xD0\xBA", "\xEB" => "\xD0\xBB",
|
||||
"\xEC" => "\xD0\xBC", "\xED" => "\xD0\xBD", "\xEE" => "\xD0\xBE", "\xEF" => "\xD0\xBF", "\xF0" => "\xD1\x80",
|
||||
"\xF1" => "\xD1\x81", "\xF2" => "\xD1\x82", "\xF3" => "\xD1\x83", "\xF4" => "\xD1\x84", "\xF5" => "\xD1\x85",
|
||||
"\xF6" => "\xD1\x86", "\xF7" => "\xD1\x87", "\xF8" => "\xD1\x88", "\xF9" => "\xD1\x89", "\xFA" => "\xD1\x8A",
|
||||
"\xFB" => "\xD1\x8B", "\xFC" => "\xD1\x8C", "\xFD" => "\xD1\x8D", "\xFE" => "\xD1\x8E", "\xFF" => "\xD1\x8F",
|
||||
"\xB3" => "\xD1\x96", "\xBF" => "\xD1\x97", "\xBA" => "\xD1\x94", "\xA2" => "\xD1\x9E");
|
||||
|
@ -16,47 +16,45 @@
|
||||
*/
|
||||
|
||||
/* authorization token check for CSRF attack */
|
||||
function csrfchecktoken()
|
||||
function csrf_check_token()
|
||||
{
|
||||
setcsrftoken();
|
||||
set_csrf_token();
|
||||
|
||||
// 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");
|
||||
}
|
||||
}
|
||||
// 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");
|
||||
}
|
||||
} elseif (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*/
|
||||
/* print csrf token as a hidden field */
|
||||
function print_csrf_token_input()
|
||||
{
|
||||
setcsrftoken();
|
||||
set_csrf_token();
|
||||
|
||||
echo "<input name='csrf_token' type='hidden' value='" . $_SESSION['csrf_token'] . "' />";
|
||||
echo "<input name='csrf_token' type='hidden' value='" . $_SESSION['csrf_token'] . "' />";
|
||||
}
|
||||
|
||||
/* print csrf token in url format */
|
||||
function print_csrf_token_in_url()
|
||||
{
|
||||
setcsrftoken();
|
||||
set_csrf_token();
|
||||
|
||||
echo "&csrf_token=" . $_SESSION['csrf_token'];
|
||||
echo "&csrf_token=" . $_SESSION['csrf_token'];
|
||||
}
|
||||
|
||||
/* set csrf token */
|
||||
function setcsrftoken()
|
||||
function set_csrf_token()
|
||||
{
|
||||
if (!isset($_SESSION['csrf_token'])) {
|
||||
$_SESSION['csrf_token'] = sha1(session_id() . (function_exists('openssl_random_pseudo_bytes') ? openssl_random_pseudo_bytes(32) : (time() + microtime()) . mt_rand(0, 99999999)));
|
||||
}
|
||||
if (!isset($_SESSION['csrf_token'])) {
|
||||
$_SESSION['csrf_token'] = sha1(session_id() . (function_exists('openssl_random_pseudo_bytes')
|
||||
? openssl_random_pseudo_bytes(32)
|
||||
: (time() + microtime()) . mt_rand(0, 99999999)));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -15,71 +15,72 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
require_once(MIBEW_FS_ROOT.'/libs/common/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);
|
||||
}
|
||||
$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)
|
||||
function get_month_selection($from_time, $to_time)
|
||||
{
|
||||
$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;
|
||||
$start = getdate($from_time);
|
||||
$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 < $to_time);
|
||||
|
||||
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;
|
||||
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) {
|
||||
return array(
|
||||
"form${prefix}day" => date("d", $utime),
|
||||
"form${prefix}month" => date("m.y", $utime)
|
||||
);
|
||||
function set_form_date($utime, $prefix)
|
||||
{
|
||||
return array(
|
||||
"form${prefix}day" => date("d", $utime),
|
||||
"form${prefix}month" => date("m.y", $utime),
|
||||
);
|
||||
}
|
||||
|
||||
function date_to_text($unixtime)
|
||||
{
|
||||
if ($unixtime < 60 * 60 * 24 * 30)
|
||||
return getlocal("time.never");
|
||||
if ($unixtime < 60 * 60 * 24 * 30) {
|
||||
return getlocal("time.never");
|
||||
}
|
||||
|
||||
$then = getdate($unixtime);
|
||||
$now = getdate();
|
||||
$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");
|
||||
}
|
||||
if ($then['yday'] == $now['yday'] && $then['year'] == $now['year']) {
|
||||
$date_format = getlocal("time.today.at");
|
||||
} elseif (($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);
|
||||
return strftime($date_format . " " . getlocal("time.timeformat"), $unixtime);
|
||||
}
|
||||
|
||||
?>
|
@ -19,47 +19,52 @@
|
||||
* Returns properly prepared value of a form variable.
|
||||
*
|
||||
* @param array $page The page array. All form variables are prefixed with
|
||||
* "form" string.
|
||||
* "form" string.
|
||||
* @param string $name Form variable name.
|
||||
* @return string Value of a form variable.
|
||||
*/
|
||||
function form_value($page, $name) {
|
||||
if (!empty($page) && isset($page["form$name"]))
|
||||
return htmlspecialchars($page["form$name"]);
|
||||
return "";
|
||||
function form_value($page, $name)
|
||||
{
|
||||
if (!empty($page) && isset($page["form$name"])) {
|
||||
return htmlspecialchars($page["form$name"]);
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a form variable is true.
|
||||
*
|
||||
* @param array $page The page array. All form variables are prefixed with
|
||||
* "form" string.
|
||||
* "form" string.
|
||||
* @param string $name Form variable name.
|
||||
* @return boolean Returns TRUE only if specified form variable is set, has boolean type
|
||||
* and equals to TRUE. In all other cases returns FALSE.
|
||||
* @return boolean Returns TRUE only if specified form variable is set, has
|
||||
* boolean type and equals to TRUE. In all other cases returns FALSE.
|
||||
*/
|
||||
function form_value_cb($page, $name) {
|
||||
if (!empty($page) && isset($page["form$name"]))
|
||||
return $page["form$name"] === true;
|
||||
return false;
|
||||
}
|
||||
function form_value_cb($page, $name)
|
||||
{
|
||||
if (!empty($page) && isset($page["form$name"])) {
|
||||
return $page["form$name"] === true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if form variable is array and has element with specified key.
|
||||
*
|
||||
* @param array $page The page array. All form variables are prefixed with
|
||||
* "form" string.
|
||||
* "form" string.
|
||||
* @param string $name Form variable name.
|
||||
* @param string $key Key of the element to check.
|
||||
* @return boolean Returns TRUE only if specified form variable is set, is an
|
||||
* array has element with the specified key. In all other cases returns FALSE.
|
||||
* array has element with the specified key. In all other cases returns FALSE.
|
||||
*/
|
||||
function form_value_mb($page, $name, $key) {
|
||||
if (!empty($page) && isset($page["form$name"]) && is_array($page["form$name"])) {
|
||||
return in_array($key, $page["form$name"]);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function form_value_mb($page, $name, $key)
|
||||
{
|
||||
if (!empty($page) && isset($page["form$name"]) && is_array($page["form$name"])) {
|
||||
return in_array($key, $page["form$name"]);
|
||||
}
|
||||
|
||||
?>
|
||||
return false;
|
||||
}
|
||||
|
@ -18,10 +18,6 @@
|
||||
// Import namespaces and classes of the core
|
||||
use Mibew\PluginManager;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(MIBEW_FS_ROOT.'/libs/common/converter.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/common/verification.php');
|
||||
|
||||
/**
|
||||
* Name for the cookie to store locale code in use
|
||||
*/
|
||||
@ -33,13 +29,19 @@ define('LOCALE_COOKIE_NAME', 'mibew_locale');
|
||||
* Verified value of the $default_locale configuration parameter (see
|
||||
* "libs/default_config.php" for details)
|
||||
*/
|
||||
define('DEFAULT_LOCALE', locale_pattern_check($default_locale) && locale_exists($default_locale) ? $default_locale : 'en');
|
||||
define(
|
||||
'DEFAULT_LOCALE',
|
||||
locale_pattern_check($default_locale) && locale_exists($default_locale) ? $default_locale : 'en'
|
||||
);
|
||||
|
||||
/**
|
||||
* Verified value of the $home_locale configuration parameter (see
|
||||
* "libs/default_config.php" for details)
|
||||
*/
|
||||
define('HOME_LOCALE', locale_pattern_check($home_locale) && locale_exists($home_locale) ? $home_locale : 'en');
|
||||
define(
|
||||
'HOME_LOCALE',
|
||||
locale_pattern_check($home_locale) && locale_exists($home_locale) ? $home_locale : 'en'
|
||||
);
|
||||
|
||||
/**
|
||||
* Code of the current system locale
|
||||
@ -48,105 +50,123 @@ define('CURRENT_LOCALE', get_locale());
|
||||
|
||||
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);
|
||||
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
|
||||
return $string; // do not know how to convert
|
||||
}
|
||||
|
||||
function locale_exists($locale)
|
||||
{
|
||||
return file_exists(MIBEW_FS_ROOT."/locales/$locale/properties");
|
||||
return file_exists(MIBEW_FS_ROOT . "/locales/$locale/properties");
|
||||
}
|
||||
|
||||
function locale_pattern_check($locale)
|
||||
{
|
||||
$locale_pattern = "/^[\w-]{2,5}$/";
|
||||
return preg_match($locale_pattern, $locale) && $locale != 'names';
|
||||
$locale_pattern = "/^[\w-]{2,5}$/";
|
||||
|
||||
return preg_match($locale_pattern, $locale) && $locale != 'names';
|
||||
}
|
||||
|
||||
function get_available_locales()
|
||||
{
|
||||
$list = array();
|
||||
$folder = MIBEW_FS_ROOT.'/locales';
|
||||
if ($handle = opendir($folder)) {
|
||||
while (false !== ($file = readdir($handle))) {
|
||||
if (locale_pattern_check($file) && is_dir("$folder/$file")) {
|
||||
$list[] = $file;
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
sort($list);
|
||||
return $list;
|
||||
$list = array();
|
||||
$folder = MIBEW_FS_ROOT . '/locales';
|
||||
if ($handle = opendir($folder)) {
|
||||
while (false !== ($file = readdir($handle))) {
|
||||
if (locale_pattern_check($file) && is_dir("$folder/$file")) {
|
||||
$list[] = $file;
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
sort($list);
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
function get_user_locale()
|
||||
{
|
||||
if (isset($_COOKIE[LOCALE_COOKIE_NAME])) {
|
||||
$requested_lang = $_COOKIE[LOCALE_COOKIE_NAME];
|
||||
if (locale_pattern_check($requested_lang) && locale_exists($requested_lang))
|
||||
return $requested_lang;
|
||||
}
|
||||
if (isset($_COOKIE[LOCALE_COOKIE_NAME])) {
|
||||
$requested_lang = $_COOKIE[LOCALE_COOKIE_NAME];
|
||||
if (locale_pattern_check($requested_lang) && 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 (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_pattern_check($requested_lang) && locale_exists($requested_lang))
|
||||
return $requested_lang;
|
||||
}
|
||||
}
|
||||
if (locale_pattern_check($requested_lang) && locale_exists($requested_lang)) {
|
||||
return $requested_lang;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (locale_pattern_check(DEFAULT_LOCALE) && locale_exists(DEFAULT_LOCALE))
|
||||
return DEFAULT_LOCALE;
|
||||
if (locale_pattern_check(DEFAULT_LOCALE) && locale_exists(DEFAULT_LOCALE)) {
|
||||
return DEFAULT_LOCALE;
|
||||
}
|
||||
|
||||
return 'en';
|
||||
return 'en';
|
||||
}
|
||||
|
||||
function get_locale()
|
||||
{
|
||||
$locale = verifyparam("locale", "/./", "");
|
||||
$locale = verify_param("locale", "/./", "");
|
||||
|
||||
if ($locale && locale_pattern_check($locale) && locale_exists($locale)) {
|
||||
$_SESSION['locale'] = $locale;
|
||||
}
|
||||
else if (isset($_SESSION['locale']) && locale_pattern_check($_SESSION['locale']) && locale_exists($_SESSION['locale'])) {
|
||||
$locale = $_SESSION['locale'];
|
||||
}
|
||||
else {
|
||||
$locale = get_user_locale();
|
||||
}
|
||||
// Check if locale code passed in as a param is valid
|
||||
$locale_param_valid = $locale
|
||||
&& locale_pattern_check($locale)
|
||||
&& locale_exists($locale);
|
||||
|
||||
setcookie(LOCALE_COOKIE_NAME, $locale, time() + 60 * 60 * 24 * 1000, MIBEW_WEB_ROOT . "/");
|
||||
return $locale;
|
||||
// Check if locale code stored in session data is valid
|
||||
$session_locale_valid = isset($_SESSION['locale'])
|
||||
&& locale_pattern_check($_SESSION['locale'])
|
||||
&& locale_exists($_SESSION['locale']);
|
||||
|
||||
if ($locale_param_valid) {
|
||||
$_SESSION['locale'] = $locale;
|
||||
} elseif ($session_locale_valid) {
|
||||
$locale = $_SESSION['locale'];
|
||||
} else {
|
||||
$locale = get_user_locale();
|
||||
}
|
||||
|
||||
setcookie(LOCALE_COOKIE_NAME, $locale, time() + 60 * 60 * 24 * 1000, MIBEW_WEB_ROOT . "/");
|
||||
|
||||
return $locale;
|
||||
}
|
||||
|
||||
function get_locale_links($href)
|
||||
{
|
||||
$localeLinks = array();
|
||||
$allLocales = get_available_locales();
|
||||
if (count($allLocales) < 2) {
|
||||
return null;
|
||||
}
|
||||
foreach ($allLocales as $k) {
|
||||
$localeLinks[$k] = getlocal_($k, "names");
|
||||
}
|
||||
return $localeLinks;
|
||||
$locale_links = array();
|
||||
$all_locales = get_available_locales();
|
||||
if (count($all_locales) < 2) {
|
||||
return null;
|
||||
}
|
||||
foreach ($all_locales as $k) {
|
||||
$locale_links[$k] = getlocal_($k, "names");
|
||||
}
|
||||
|
||||
return $locale_links;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -157,38 +177,39 @@ function get_locale_links($href)
|
||||
*
|
||||
* @param string $locale Name of a locale whose messages should be loaded.
|
||||
*/
|
||||
function load_messages($locale) {
|
||||
global $messages, $output_encoding;
|
||||
function load_messages($locale)
|
||||
{
|
||||
global $messages, $output_encoding;
|
||||
|
||||
// Load core localization
|
||||
$locale_file = MIBEW_FS_ROOT . "/locales/{$locale}/properties";
|
||||
$locale_data = read_locale_file($locale_file);
|
||||
// Load core localization
|
||||
$locale_file = MIBEW_FS_ROOT . "/locales/{$locale}/properties";
|
||||
$locale_data = read_locale_file($locale_file);
|
||||
|
||||
if (! is_null($locale_data['output_encoding'])) {
|
||||
$output_encoding[$locale] = $locale_data['output_encoding'];
|
||||
}
|
||||
if (!is_null($locale_data['output_encoding'])) {
|
||||
$output_encoding[$locale] = $locale_data['output_encoding'];
|
||||
}
|
||||
|
||||
$messages[$locale] = $locale_data['messages'];
|
||||
$messages[$locale] = $locale_data['messages'];
|
||||
|
||||
// Plugins are unavailable on system installation
|
||||
if (!installation_in_progress()) {
|
||||
// Load active plugins localization
|
||||
$plugins_list = array_keys(PluginManager::getAllPlugins());
|
||||
// Plugins are unavailable on system installation
|
||||
if (!installation_in_progress()) {
|
||||
// Load active plugins localization
|
||||
$plugins_list = array_keys(PluginManager::getAllPlugins());
|
||||
|
||||
foreach($plugins_list as $plugin_name) {
|
||||
$locale_file = MIBEW_FS_ROOT .
|
||||
"/plugins/{$plugin_name}/locales/{$locale}/properties";
|
||||
if (is_readable($locale_file)) {
|
||||
$locale_data = read_locale_file($locale_file);
|
||||
// array_merge used to provide an ability for plugins to override
|
||||
// localized strings
|
||||
$messages[$locale] = array_merge(
|
||||
$messages[$locale],
|
||||
$locale_data['messages']
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($plugins_list as $plugin_name) {
|
||||
$locale_file = MIBEW_FS_ROOT .
|
||||
"/plugins/{$plugin_name}/locales/{$locale}/properties";
|
||||
if (is_readable($locale_file)) {
|
||||
$locale_data = read_locale_file($locale_file);
|
||||
// array_merge used to provide an ability for plugins to override
|
||||
// localized strings
|
||||
$messages[$locale] = array_merge(
|
||||
$messages[$locale],
|
||||
$locale_data['messages']
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -210,188 +231,216 @@ function load_messages($locale) {
|
||||
* All localized strings have internal Mibew encoding(see $mibew_encoding
|
||||
* value in libs/config.php).
|
||||
*/
|
||||
function read_locale_file($path) {
|
||||
// Set default values
|
||||
$current_encoding = MIBEW_ENCODING;
|
||||
$output_encoding = null;
|
||||
$messages = array();
|
||||
function read_locale_file($path)
|
||||
{
|
||||
// Set default values
|
||||
$current_encoding = MIBEW_ENCODING;
|
||||
$output_encoding = null;
|
||||
$messages = array();
|
||||
|
||||
$fp = fopen($path, "r");
|
||||
if ($fp === FALSE) {
|
||||
die("unable to read locale file $path");
|
||||
}
|
||||
while (!feof($fp)) {
|
||||
$line = fgets($fp, 4096);
|
||||
// Try to get key and value from locale file line
|
||||
$line_parts = preg_split("/=/", $line, 2);
|
||||
if (count($line_parts) == 2) {
|
||||
$key = $line_parts[0];
|
||||
$value = $line_parts[1];
|
||||
// Check if key is service field and treat it as
|
||||
// localized string otherwise
|
||||
if ($key == 'encoding') {
|
||||
$current_encoding = trim($value);
|
||||
} else if ($key == 'output_encoding') {
|
||||
$output_encoding = trim($value);
|
||||
} else if ($current_encoding == MIBEW_ENCODING) {
|
||||
$messages[$key] = str_replace("\\n", "\n", trim($value));
|
||||
} else {
|
||||
$messages[$key] = myiconv(
|
||||
$current_encoding,
|
||||
MIBEW_ENCODING,
|
||||
str_replace("\\n", "\n", trim($value))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose($fp);
|
||||
$fp = fopen($path, "r");
|
||||
if ($fp === false) {
|
||||
die("unable to read locale file $path");
|
||||
}
|
||||
while (!feof($fp)) {
|
||||
$line = fgets($fp, 4096);
|
||||
// Try to get key and value from locale file line
|
||||
$line_parts = preg_split("/=/", $line, 2);
|
||||
if (count($line_parts) == 2) {
|
||||
$key = $line_parts[0];
|
||||
$value = $line_parts[1];
|
||||
// Check if key is service field and treat it as
|
||||
// localized string otherwise
|
||||
if ($key == 'encoding') {
|
||||
$current_encoding = trim($value);
|
||||
} elseif ($key == 'output_encoding') {
|
||||
$output_encoding = trim($value);
|
||||
} elseif ($current_encoding == MIBEW_ENCODING) {
|
||||
$messages[$key] = str_replace("\\n", "\n", trim($value));
|
||||
} else {
|
||||
$messages[$key] = myiconv(
|
||||
$current_encoding,
|
||||
MIBEW_ENCODING,
|
||||
str_replace("\\n", "\n", trim($value))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose($fp);
|
||||
|
||||
return array(
|
||||
'encoding' => $current_encoding,
|
||||
'output_encoding' => $output_encoding,
|
||||
'messages' => $messages
|
||||
);
|
||||
return array(
|
||||
'encoding' => $current_encoding,
|
||||
'output_encoding' => $output_encoding,
|
||||
'messages' => $messages
|
||||
);
|
||||
}
|
||||
|
||||
function getoutputenc()
|
||||
{
|
||||
global $output_encoding, $messages;
|
||||
if (!isset($messages[CURRENT_LOCALE]))
|
||||
load_messages(CURRENT_LOCALE);
|
||||
return isset($output_encoding[CURRENT_LOCALE]) ? $output_encoding[CURRENT_LOCALE] : MIBEW_ENCODING;
|
||||
global $output_encoding, $messages;
|
||||
if (!isset($messages[CURRENT_LOCALE])) {
|
||||
load_messages(CURRENT_LOCALE);
|
||||
}
|
||||
|
||||
return isset($output_encoding[CURRENT_LOCALE])
|
||||
? $output_encoding[CURRENT_LOCALE]
|
||||
: MIBEW_ENCODING;
|
||||
}
|
||||
|
||||
function getstring_($text, $locale)
|
||||
{
|
||||
global $messages;
|
||||
if (!isset($messages[$locale]))
|
||||
load_messages($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');
|
||||
}
|
||||
$localized = $messages[$locale];
|
||||
if (isset($localized[$text])) {
|
||||
return $localized[$text];
|
||||
}
|
||||
if ($locale != 'en') {
|
||||
return getstring_($text, 'en');
|
||||
}
|
||||
|
||||
return "!" . $text;
|
||||
return "!" . $text;
|
||||
}
|
||||
|
||||
function getstring($text)
|
||||
{
|
||||
return getstring_($text, CURRENT_LOCALE);
|
||||
return getstring_($text, CURRENT_LOCALE);
|
||||
}
|
||||
|
||||
function getlocal($text)
|
||||
{
|
||||
return myiconv(MIBEW_ENCODING, getoutputenc(), getstring_($text, CURRENT_LOCALE));
|
||||
return myiconv(MIBEW_ENCODING, getoutputenc(), getstring_($text, CURRENT_LOCALE));
|
||||
}
|
||||
|
||||
function getlocal_($text, $locale)
|
||||
{
|
||||
return myiconv(MIBEW_ENCODING, getoutputenc(), getstring_($text, $locale));
|
||||
return myiconv(MIBEW_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;
|
||||
$string = getstring_($text, $locale);
|
||||
for ($i = 0; $i < count($params); $i++) {
|
||||
$string = str_replace("{" . $i . "}", $params[$i], $string);
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
function getstring2($text, $params)
|
||||
{
|
||||
return getstring2_($text, $params, CURRENT_LOCALE);
|
||||
return getstring2_($text, $params, CURRENT_LOCALE);
|
||||
}
|
||||
|
||||
function getlocal2($text, $params)
|
||||
{
|
||||
$string = myiconv(MIBEW_ENCODING, getoutputenc(), getstring_($text, CURRENT_LOCALE));
|
||||
for ($i = 0; $i < count($params); $i++) {
|
||||
$string = str_replace("{" . $i . "}", $params[$i], $string);
|
||||
}
|
||||
return $string;
|
||||
$string = myiconv(MIBEW_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)
|
||||
function get_local_for_js($text, $params)
|
||||
{
|
||||
$string = myiconv(MIBEW_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;
|
||||
$string = myiconv(MIBEW_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;
|
||||
}
|
||||
|
||||
function locale_load_idlist($name)
|
||||
function locale_load_id_list($name)
|
||||
{
|
||||
$result = array();
|
||||
$fp = @fopen(MIBEW_FS_ROOT."/locales/names/$name", "r");
|
||||
if ($fp !== FALSE) {
|
||||
while (!feof($fp)) {
|
||||
$line = trim(fgets($fp, 4096));
|
||||
if ($line && preg_match("/^[\w_\.]+$/", $line)) {
|
||||
$result[] = $line;
|
||||
}
|
||||
}
|
||||
fclose($fp);
|
||||
}
|
||||
return $result;
|
||||
$result = array();
|
||||
$fp = @fopen(MIBEW_FS_ROOT . "/locales/names/$name", "r");
|
||||
if ($fp !== false) {
|
||||
while (!feof($fp)) {
|
||||
$line = trim(fgets($fp, 4096));
|
||||
if ($line && preg_match("/^[\w_\.]+$/", $line)) {
|
||||
$result[] = $line;
|
||||
}
|
||||
}
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function save_message($locale, $key, $value)
|
||||
{
|
||||
$result = "";
|
||||
$added = false;
|
||||
$current_encoding = MIBEW_ENCODING;
|
||||
$fp = fopen(MIBEW_FS_ROOT."/locales/$locale/properties", "r");
|
||||
if ($fp === FALSE) {
|
||||
die("unable to open properties for locale $locale");
|
||||
}
|
||||
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 (!$added && $keyval[0] == $key) {
|
||||
$line = "$key=" . myiconv(MIBEW_ENCODING, $current_encoding, str_replace("\r", "", str_replace("\n", "\\n", trim($value)))) . "\n";
|
||||
$added = true;
|
||||
}
|
||||
}
|
||||
$result .= $line;
|
||||
}
|
||||
fclose($fp);
|
||||
if (!$added) {
|
||||
$result .= "$key=" . myiconv(MIBEW_ENCODING, $current_encoding, str_replace("\r", "", str_replace("\n", "\\n", trim($value)))) . "\n";
|
||||
}
|
||||
$fp = @fopen(MIBEW_FS_ROOT."/locales/$locale/properties", "w");
|
||||
if ($fp !== FALSE) {
|
||||
fwrite($fp, $result);
|
||||
fclose($fp);
|
||||
} else {
|
||||
die("cannot write /locales/$locale/properties, please check file permissions on your server");
|
||||
}
|
||||
$fp = @fopen(MIBEW_FS_ROOT."/locales/$locale/properties.log", "a");
|
||||
if ($fp !== FALSE) {
|
||||
$extAddr = $_SERVER['REMOTE_ADDR'];
|
||||
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) &&
|
||||
$_SERVER['HTTP_X_FORWARDED_FOR'] != $_SERVER['REMOTE_ADDR']) {
|
||||
$extAddr = $_SERVER['REMOTE_ADDR'] . ' (' . $_SERVER['HTTP_X_FORWARDED_FOR'] . ')';
|
||||
}
|
||||
$userbrowser = $_SERVER['HTTP_USER_AGENT'];
|
||||
$remoteHost = isset($_SERVER['REMOTE_HOST']) ? $_SERVER['REMOTE_HOST'] : $extAddr;
|
||||
$result = "";
|
||||
$added = false;
|
||||
$current_encoding = MIBEW_ENCODING;
|
||||
$fp = fopen(MIBEW_FS_ROOT . "/locales/$locale/properties", "r");
|
||||
if ($fp === false) {
|
||||
die("unable to open properties for locale $locale");
|
||||
}
|
||||
while (!feof($fp)) {
|
||||
$line = fgets($fp, 4096);
|
||||
$key_val = preg_split("/=/", $line, 2);
|
||||
if (isset($key_val[1])) {
|
||||
if ($key_val[0] == 'encoding') {
|
||||
$current_encoding = trim($key_val[1]);
|
||||
} elseif (!$added && $key_val[0] == $key) {
|
||||
$line = "$key="
|
||||
. myiconv(
|
||||
MIBEW_ENCODING,
|
||||
$current_encoding,
|
||||
str_replace("\r", "", str_replace("\n", "\\n", trim($value)))
|
||||
) . "\n";
|
||||
$added = true;
|
||||
}
|
||||
}
|
||||
$result .= $line;
|
||||
}
|
||||
fclose($fp);
|
||||
if (!$added) {
|
||||
$result .= "$key="
|
||||
. myiconv(
|
||||
MIBEW_ENCODING,
|
||||
$current_encoding,
|
||||
str_replace("\r", "", str_replace("\n", "\\n", trim($value)))
|
||||
) . "\n";
|
||||
}
|
||||
$fp = @fopen(MIBEW_FS_ROOT . "/locales/$locale/properties", "w");
|
||||
if ($fp !== false) {
|
||||
fwrite($fp, $result);
|
||||
fclose($fp);
|
||||
} else {
|
||||
die("cannot write /locales/$locale/properties, please check file permissions on your server");
|
||||
}
|
||||
$fp = @fopen(MIBEW_FS_ROOT . "/locales/$locale/properties.log", "a");
|
||||
if ($fp !== false) {
|
||||
$ext_addr = $_SERVER['REMOTE_ADDR'];
|
||||
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) &&
|
||||
$_SERVER['HTTP_X_FORWARDED_FOR'] != $_SERVER['REMOTE_ADDR']) {
|
||||
$ext_addr = $_SERVER['REMOTE_ADDR'] . ' (' . $_SERVER['HTTP_X_FORWARDED_FOR'] . ')';
|
||||
}
|
||||
$user_browser = $_SERVER['HTTP_USER_AGENT'];
|
||||
$remote_host = isset($_SERVER['REMOTE_HOST']) ? $_SERVER['REMOTE_HOST'] : $ext_addr;
|
||||
|
||||
fwrite($fp, "# " . date(DATE_RFC822) . " by $remoteHost using $userbrowser\n");
|
||||
fwrite($fp, "$key=" . myiconv(MIBEW_ENCODING, $current_encoding, str_replace("\r", "", str_replace("\n", "\\n", trim($value)))) . "\n");
|
||||
fclose($fp);
|
||||
}
|
||||
fwrite($fp, "# " . date(DATE_RFC822) . " by $remote_host using $user_browser\n");
|
||||
fwrite(
|
||||
$fp,
|
||||
("$key="
|
||||
. myiconv(
|
||||
MIBEW_ENCODING,
|
||||
$current_encoding,
|
||||
str_replace("\r", "", str_replace("\n", "\\n", trim($value)))
|
||||
)
|
||||
. "\n")
|
||||
);
|
||||
fclose($fp);
|
||||
}
|
||||
}
|
||||
|
||||
$messages = array();
|
||||
$output_encoding = array();
|
||||
|
||||
?>
|
@ -15,42 +15,41 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
require_once(MIBEW_FS_ROOT.'/libs/common/constants.php');
|
||||
|
||||
function debugexit_print($var)
|
||||
{
|
||||
echo "<html><body><pre>";
|
||||
print_r($var);
|
||||
echo "</pre></body></html>";
|
||||
exit;
|
||||
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);
|
||||
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()
|
||||
function js_path()
|
||||
{
|
||||
return "js/compiled";
|
||||
return "js/compiled";
|
||||
}
|
||||
|
||||
function div($a, $b)
|
||||
{
|
||||
return ($a - ($a % $b)) / $b;
|
||||
return ($a - ($a % $b)) / $b;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -88,21 +87,23 @@ function div($a, $b)
|
||||
* @param array $arr Array to flatten
|
||||
* @return array
|
||||
*/
|
||||
function array_flatten_recursive($arr) {
|
||||
$result = array();
|
||||
foreach($arr as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
// Flatten nested arrays
|
||||
$value = array_flatten_recursive($value);
|
||||
foreach($value as $inner_key => $inner_value) {
|
||||
$result[$key.".".$inner_key] = $inner_value;
|
||||
}
|
||||
} else {
|
||||
// Leave scalar values 'as is'
|
||||
$result[$key] = $value;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
function array_flatten_recursive($arr)
|
||||
{
|
||||
$result = array();
|
||||
foreach ($arr as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
// Flatten nested arrays
|
||||
$value = array_flatten_recursive($value);
|
||||
foreach ($value as $inner_key => $inner_value) {
|
||||
$result[$key . "." . $inner_key] = $inner_value;
|
||||
}
|
||||
} else {
|
||||
// Leave scalar values 'as is'
|
||||
$result[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -110,12 +111,11 @@ function array_flatten_recursive($arr) {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function installation_in_progress() {
|
||||
if (!defined('INSTALLATION_IN_PROGRESS')) {
|
||||
return FALSE;
|
||||
}
|
||||
function installation_in_progress()
|
||||
{
|
||||
if (!defined('INSTALLATION_IN_PROGRESS')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return INSTALLATION_IN_PROGRESS;
|
||||
return INSTALLATION_IN_PROGRESS;
|
||||
}
|
||||
|
||||
?>
|
@ -18,62 +18,61 @@
|
||||
// Import namespaces and classes of the core
|
||||
use Mibew\Settings;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(MIBEW_FS_ROOT.'/libs/common/locale.php');
|
||||
|
||||
/* ajax server actions use utf-8 */
|
||||
function getrawparam($name)
|
||||
function get_raw_param($name)
|
||||
{
|
||||
if (isset($_POST[$name])) {
|
||||
$value = myiconv("utf-8", MIBEW_ENCODING, $_POST[$name]);
|
||||
if (get_magic_quotes_gpc()) {
|
||||
$value = stripslashes($value);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
die("no " . $name . " parameter");
|
||||
}
|
||||
if (isset($_POST[$name])) {
|
||||
$value = myiconv("utf-8", MIBEW_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)
|
||||
|
||||
function get_param($name)
|
||||
{
|
||||
if (isset($_POST[$name])) {
|
||||
$value = myiconv(getoutputenc(), MIBEW_ENCODING, $_POST[$name]);
|
||||
if (get_magic_quotes_gpc()) {
|
||||
$value = stripslashes($value);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
die("no " . $name . " parameter");
|
||||
if (isset($_POST[$name])) {
|
||||
$value = myiconv(getoutputenc(), MIBEW_ENCODING, $_POST[$name]);
|
||||
if (get_magic_quotes_gpc()) {
|
||||
$value = stripslashes($value);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
die("no " . $name . " parameter");
|
||||
}
|
||||
|
||||
function getgetparam($name, $default = '')
|
||||
function get_get_param($name, $default = '')
|
||||
{
|
||||
if (!isset($_GET[$name]) || !$_GET[$name]) {
|
||||
return $default;
|
||||
}
|
||||
$value = myiconv("utf-8", MIBEW_ENCODING, unicode_urldecode($_GET[$name]));
|
||||
if (get_magic_quotes_gpc()) {
|
||||
$value = stripslashes($value);
|
||||
}
|
||||
return $value;
|
||||
if (!isset($_GET[$name]) || !$_GET[$name]) {
|
||||
return $default;
|
||||
}
|
||||
$value = myiconv("utf-8", MIBEW_ENCODING, unicode_urldecode($_GET[$name]));
|
||||
if (get_magic_quotes_gpc()) {
|
||||
$value = stripslashes($value);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
function get_app_location($showhost, $issecure)
|
||||
function get_app_location($show_host, $is_secure)
|
||||
{
|
||||
if ($showhost) {
|
||||
return ($issecure ? "https://" : "http://") . $_SERVER['HTTP_HOST'] . MIBEW_WEB_ROOT;
|
||||
} else {
|
||||
return MIBEW_WEB_ROOT;
|
||||
}
|
||||
if ($show_host) {
|
||||
return ($is_secure ? "https://" : "http://") . $_SERVER['HTTP_HOST'] . MIBEW_WEB_ROOT;
|
||||
} else {
|
||||
return MIBEW_WEB_ROOT;
|
||||
}
|
||||
}
|
||||
|
||||
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";
|
||||
return (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443')
|
||||
|| (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on")
|
||||
|| (isset($_SERVER["HTTP_HTTPS"]) && $_SERVER["HTTP_HTTPS"] == "on");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -81,8 +80,7 @@ function is_secure_request()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function get_page_style() {
|
||||
return Settings::get('page_style');
|
||||
function get_page_style()
|
||||
{
|
||||
return Settings::get('page_style');
|
||||
}
|
||||
|
||||
?>
|
@ -15,57 +15,61 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
// Import namespaces and classes of the core
|
||||
use Mibew\EventDispatcher;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(MIBEW_FS_ROOT.'/libs/common/locale.php');
|
||||
|
||||
function get_popup($href, $jshref, $message, $title, $wndName, $options)
|
||||
function get_popup($href, $js_href, $message, $title, $wnd_name, $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>";
|
||||
if (!$js_href) {
|
||||
$js_href = "'$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($js_href, '$wnd_name', '$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=\"\"/>";
|
||||
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\"?>";
|
||||
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 : ""));
|
||||
$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)
|
||||
function start_js_output()
|
||||
{
|
||||
return myiconv(MIBEW_ENCODING, getoutputenc(), $text);
|
||||
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 to_page($text)
|
||||
{
|
||||
return myiconv(MIBEW_ENCODING, getoutputenc(), $text);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -81,24 +85,25 @@ function topage($text)
|
||||
* @param string $page_name CSS files load to this page
|
||||
* @return string HTML block of 'link' tags
|
||||
*/
|
||||
function get_additional_css($page_name) {
|
||||
// Prepare event arguments array
|
||||
$args = array(
|
||||
'page' => $page_name,
|
||||
'css' => array()
|
||||
);
|
||||
function get_additional_css($page_name)
|
||||
{
|
||||
// Prepare event arguments array
|
||||
$args = array(
|
||||
'page' => $page_name,
|
||||
'css' => array(),
|
||||
);
|
||||
|
||||
// Trigger event
|
||||
$dispatcher = EventDispatcher::getInstance();
|
||||
$dispatcher->triggerEvent('pageAddCSS', $args);
|
||||
// Trigger event
|
||||
$dispatcher = EventDispatcher::getInstance();
|
||||
$dispatcher->triggerEvent('pageAddCSS', $args);
|
||||
|
||||
// Build resulting css list
|
||||
$result = array();
|
||||
foreach($args['css'] as $css) {
|
||||
$result[] = '<link rel="stylesheet" type="text/css" href="'.$css.'">';
|
||||
}
|
||||
// Build resulting css list
|
||||
$result = array();
|
||||
foreach ($args['css'] as $css) {
|
||||
$result[] = '<link rel="stylesheet" type="text/css" href="' . $css . '">';
|
||||
}
|
||||
|
||||
return implode("\n", $result);
|
||||
return implode("\n", $result);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -114,24 +119,25 @@ function get_additional_css($page_name) {
|
||||
* @param string $page_name JavaScript files load to this page
|
||||
* @return string HTML block of 'script' tags
|
||||
*/
|
||||
function get_additional_js($page_name) {
|
||||
// Prepare event arguments array
|
||||
$args = array(
|
||||
'page' => $page_name,
|
||||
'js' => array()
|
||||
);
|
||||
function get_additional_js($page_name)
|
||||
{
|
||||
// Prepare event arguments array
|
||||
$args = array(
|
||||
'page' => $page_name,
|
||||
'js' => array()
|
||||
);
|
||||
|
||||
// Trigger event
|
||||
$dispatcher = EventDispatcher::getInstance();
|
||||
$dispatcher->triggerEvent('pageAddJS', $args);
|
||||
// Trigger event
|
||||
$dispatcher = EventDispatcher::getInstance();
|
||||
$dispatcher->triggerEvent('pageAddJS', $args);
|
||||
|
||||
// Build resulting css list
|
||||
$result = array();
|
||||
foreach($args['js'] as $js) {
|
||||
$result[] = '<script type="text/javascript" src="'.$js.'"></script>';
|
||||
}
|
||||
// Build resulting css list
|
||||
$result = array();
|
||||
foreach ($args['js'] as $js) {
|
||||
$result[] = '<script type="text/javascript" src="' . $js . '"></script>';
|
||||
}
|
||||
|
||||
return implode("\n", $result);
|
||||
return implode("\n", $result);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -145,25 +151,25 @@ function get_additional_js($page_name) {
|
||||
* @param string $page_name Localized strings add to this page
|
||||
* @return string JSON encoded localized strings
|
||||
*/
|
||||
function get_additional_localized_strings($page_name) {
|
||||
// Prepare event arguments array
|
||||
$args = array(
|
||||
'page' => $page_name,
|
||||
'localized_strings' => array()
|
||||
);
|
||||
function get_additional_localized_strings($page_name)
|
||||
{
|
||||
// Prepare event arguments array
|
||||
$args = array(
|
||||
'page' => $page_name,
|
||||
'localized_strings' => array(),
|
||||
);
|
||||
|
||||
// Trigger event
|
||||
$dispatcher = EventDispatcher::getInstance();
|
||||
$dispatcher->triggerEvent('pageAddLocalizedStrings', $args);
|
||||
// Trigger event
|
||||
$dispatcher = EventDispatcher::getInstance();
|
||||
$dispatcher->triggerEvent('pageAddLocalizedStrings', $args);
|
||||
|
||||
// Build result
|
||||
$result = array();
|
||||
if (! empty($args['localized_strings'])
|
||||
&& is_array($args['localized_strings'])) {
|
||||
$result = $args['localized_strings'];
|
||||
}
|
||||
// Build result
|
||||
$result = array();
|
||||
if (!empty($args['localized_strings']) && is_array($args['localized_strings'])) {
|
||||
$result = $args['localized_strings'];
|
||||
}
|
||||
|
||||
return json_encode($result);
|
||||
return json_encode($result);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -179,19 +185,20 @@ function get_additional_localized_strings($page_name) {
|
||||
* @param string $page_name Plugins initialize at this page
|
||||
* @return string JavaScript options block
|
||||
*/
|
||||
function get_js_plugin_options($page_name) {
|
||||
// Prepare event arguments array
|
||||
$args = array(
|
||||
'page' => $page_name,
|
||||
'plugins' => array()
|
||||
);
|
||||
function get_js_plugin_options($page_name)
|
||||
{
|
||||
// Prepare event arguments array
|
||||
$args = array(
|
||||
'page' => $page_name,
|
||||
'plugins' => array()
|
||||
);
|
||||
|
||||
// Trigger event
|
||||
$dispatcher = EventDispatcher::getInstance();
|
||||
$dispatcher->triggerEvent('pageAddJSPluginOptions', $args);
|
||||
// Trigger event
|
||||
$dispatcher = EventDispatcher::getInstance();
|
||||
$dispatcher->triggerEvent('pageAddJSPluginOptions', $args);
|
||||
|
||||
// Return encoded options
|
||||
return json_encode($args['plugins']);
|
||||
// Return encoded options
|
||||
return json_encode($args['plugins']);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -199,74 +206,76 @@ function get_js_plugin_options($page_name) {
|
||||
*
|
||||
* @param string $page_name Plugins initialize at this page
|
||||
* @return array Associative array of plugins data. It contains following keys:
|
||||
* - 'additional_css': contains results of the 'get_additional_css function
|
||||
* - 'additional_js': contains results of the 'get_additional_js' function
|
||||
* - 'additional_localized_strings': contains results of the
|
||||
* 'get_additional_localized_strings' function
|
||||
* - 'js_plugin_options': contains results of the 'get_js_plugin_options'
|
||||
* function
|
||||
* - 'additional_css': contains results of the 'get_additional_css function
|
||||
* - 'additional_js': contains results of the 'get_additional_js' function
|
||||
* - 'additional_localized_strings': contains results of the
|
||||
* 'get_additional_localized_strings' function
|
||||
* - 'js_plugin_options': contains results of the 'get_js_plugin_options'
|
||||
* function
|
||||
*/
|
||||
function get_plugins_data($page_name) {
|
||||
return array(
|
||||
'additional_css' => get_additional_css($page_name),
|
||||
'additional_js' => get_additional_js($page_name),
|
||||
'additional_localized_strings' => get_additional_localized_strings($page_name),
|
||||
'js_plugin_options' => get_js_plugin_options($page_name)
|
||||
);
|
||||
function get_plugins_data($page_name)
|
||||
{
|
||||
return array(
|
||||
'additional_css' => get_additional_css($page_name),
|
||||
'additional_js' => get_additional_js($page_name),
|
||||
'additional_localized_strings' => get_additional_localized_strings($page_name),
|
||||
'js_plugin_options' => get_js_plugin_options($page_name)
|
||||
);
|
||||
}
|
||||
|
||||
function no_field($key)
|
||||
{
|
||||
return getlocal2("errors.required", array(getlocal($key)));
|
||||
return getlocal2("errors.required", array(getlocal($key)));
|
||||
}
|
||||
|
||||
function failed_uploading_file($filename, $key)
|
||||
{
|
||||
return getlocal2("errors.failed.uploading.file",
|
||||
array($filename, getlocal($key)));
|
||||
return getlocal2("errors.failed.uploading.file", array($filename, getlocal($key)));
|
||||
}
|
||||
|
||||
function wrong_field($key)
|
||||
{
|
||||
return getlocal2("errors.wrong_field", array(getlocal($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;
|
||||
$infix = '?';
|
||||
if (strstr($servlet, $infix) !== false) {
|
||||
$infix = '&';
|
||||
}
|
||||
foreach ($params as $k => $v) {
|
||||
$servlet .= $infix . $k . "=" . $v;
|
||||
$infix = '&';
|
||||
}
|
||||
|
||||
return $servlet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds JSONP response to the Mibew widget
|
||||
*
|
||||
* @param array $response Response data. It can contain following items:
|
||||
* - 'load': associative array, specify files which must be loaded. Array keys
|
||||
* are file aliases and values are URLs. One can use file alias to specify
|
||||
* dependences (described below).
|
||||
* - 'handlers': array, handlers which must be called (described below).
|
||||
* - 'dependences': array, specify dependences between handlers and loaded
|
||||
* files. Array keys are handlers names and values are arrays of file aliases
|
||||
* from load item. Handler function will call only after all specified files
|
||||
* loaded.
|
||||
* - 'data': associative array, arbitrary structure which will be passed to all
|
||||
* functions, specified in 'handlers' item.
|
||||
* - 'load': associative array, specify files which must be loaded. Array keys
|
||||
* are file aliases and values are URLs. One can use file alias to specify
|
||||
* dependences (described below).
|
||||
* - 'handlers': array, handlers which must be called (described below).
|
||||
* - 'dependences': array, specify dependences between handlers and loaded
|
||||
* files. Array keys are handlers names and values are arrays of file aliases
|
||||
* from load item. Handler function will call only after all specified files
|
||||
* loaded.
|
||||
* - 'data': associative array, arbitrary structure which will be passed to all
|
||||
* functions, specified in 'handlers' item.
|
||||
* @return string JSONP response that ready to send to the widget
|
||||
*/
|
||||
function build_widget_response($response) {
|
||||
$result = $response + array(
|
||||
'load' => array(),
|
||||
'handlers' => array(),
|
||||
'dependences' => array(),
|
||||
'data' => array()
|
||||
);
|
||||
return "Mibew.Objects.widget.onResponse(" . json_encode($result) . ");";
|
||||
}
|
||||
function build_widget_response($response)
|
||||
{
|
||||
$result = $response + array(
|
||||
'load' => array(),
|
||||
'handlers' => array(),
|
||||
'dependences' => array(),
|
||||
'data' => array(),
|
||||
);
|
||||
|
||||
?>
|
||||
return "Mibew.Objects.widget.onResponse(" . json_encode($result) . ");";
|
||||
}
|
||||
|
@ -17,42 +17,40 @@
|
||||
|
||||
function unicode_urldecode($url)
|
||||
{
|
||||
preg_match_all('/%u([[:alnum:]]{4})/', $url, $a);
|
||||
preg_match_all('/%u([[:alnum:]]{4})/', $url, $a);
|
||||
|
||||
foreach ($a[1] as $uniord) {
|
||||
$dec = hexdec($uniord);
|
||||
$utf = '';
|
||||
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);
|
||||
if ($dec < 128) {
|
||||
$utf = chr($dec);
|
||||
} elseif ($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 = '')
|
||||
function cut_string($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;
|
||||
$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) . "]]>";
|
||||
return "<![CDATA[" . str_replace("]]>", "]]>]]><![CDATA[", $text) . "]]>";
|
||||
}
|
||||
|
||||
?>
|
@ -15,29 +15,28 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
function verifyparam($name, $regexp, $default = null)
|
||||
function verify_param($name, $reg_exp, $default = null)
|
||||
{
|
||||
if (isset($_GET[$name]) && is_scalar($_GET[$name])) {
|
||||
$val = $_GET[$name];
|
||||
if (preg_match($regexp, $val))
|
||||
return $val;
|
||||
|
||||
} else if (isset($_POST[$name]) && is_scalar($_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;
|
||||
if (isset($_GET[$name]) && is_scalar($_GET[$name])) {
|
||||
$val = $_GET[$name];
|
||||
if (preg_match($reg_exp, $val)) {
|
||||
return $val;
|
||||
}
|
||||
} elseif (isset($_POST[$name]) && is_scalar($_POST[$name])) {
|
||||
$val = $_POST[$name];
|
||||
if (preg_match($reg_exp, $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);
|
||||
return preg_match("/^[^@]+@[^\.]+(\.[^\.]+)*$/", $email);
|
||||
}
|
||||
|
||||
?>
|
@ -21,12 +21,10 @@
|
||||
* @param string $cron_key Cron security key
|
||||
* @return string Cron URI
|
||||
*/
|
||||
function cron_get_uri($cron_key) {
|
||||
$path = get_app_location(true, is_secure_request()) . '/cron.php';
|
||||
$path .= empty($cron_key)
|
||||
? ''
|
||||
: '?cron_key='.$cron_key;
|
||||
return $path;
|
||||
}
|
||||
function cron_get_uri($cron_key)
|
||||
{
|
||||
$path = get_app_location(true, is_secure_request()) . '/cron.php';
|
||||
$path .= empty($cron_key) ? '' : '?cron_key=' . $cron_key;
|
||||
|
||||
?>
|
||||
return $path;
|
||||
}
|
||||
|
@ -62,14 +62,13 @@ $default_locale = "en"; /* if user does not provide known lang */
|
||||
* Plugins
|
||||
*/
|
||||
$plugins_list = array();
|
||||
|
||||
/* Exapmle of plugins configuration
|
||||
$plugins_list[] = array(
|
||||
'name' => 'plugin_name',
|
||||
'config' => array(
|
||||
'weight' => 100,
|
||||
'some_configurable_value' => 'value'
|
||||
)
|
||||
'name' => 'plugin_name',
|
||||
'config' => array(
|
||||
'weight' => 100,
|
||||
'some_configurable_value' => 'value'
|
||||
)
|
||||
)
|
||||
*/
|
||||
|
||||
?>
|
@ -19,121 +19,143 @@
|
||||
use Mibew\Settings;
|
||||
use Mibew\Style\InvitationStyle;
|
||||
|
||||
function generate_button($title, $locale, $style, $invitation_style_name, $group, $inner, $showhost, $forcesecure, $modsecurity, $operator_code)
|
||||
{
|
||||
$app_location = get_app_location($showhost, $forcesecure);
|
||||
$link = $app_location . "/client.php";
|
||||
if ($locale)
|
||||
$link = append_query($link, "locale=$locale");
|
||||
if ($style)
|
||||
$link = append_query($link, "style=$style");
|
||||
if ($group)
|
||||
$link = append_query($link, "group=$group");
|
||||
function generate_button(
|
||||
$title,
|
||||
$locale,
|
||||
$style,
|
||||
$invitation_style_name,
|
||||
$group,
|
||||
$inner,
|
||||
$show_host,
|
||||
$force_secure,
|
||||
$mod_security,
|
||||
$operator_code
|
||||
) {
|
||||
$app_location = get_app_location($show_host, $force_secure);
|
||||
$link = $app_location . "/client.php";
|
||||
if ($locale) {
|
||||
$link = append_query($link, "locale=$locale");
|
||||
}
|
||||
if ($style) {
|
||||
$link = append_query($link, "style=$style");
|
||||
}
|
||||
if ($group) {
|
||||
$link = append_query($link, "group=$group");
|
||||
}
|
||||
|
||||
$modsecfix = $modsecurity ? ".replace('http://','').replace('https://','')" : "";
|
||||
$jslink = append_query("'" . $link, "url='+escape(document.location.href$modsecfix)+'&referrer='+escape(document.referrer$modsecfix)");
|
||||
$popup_options = "toolbar=0,scrollbars=0,location=0,status=1,menubar=0,width=640,height=480,resizable=1";
|
||||
$modsecfix = $mod_security ? ".replace('http://','').replace('https://','')" : "";
|
||||
$js_link = append_query(
|
||||
"'" . $link,
|
||||
"url='+escape(document.location.href$modsecfix)+'&referrer='+escape(document.referrer$modsecfix)"
|
||||
);
|
||||
$popup_options = "toolbar=0,scrollbars=0,location=0,status=1,menubar=0,width=640,height=480,resizable=1";
|
||||
|
||||
// Generate operator code field
|
||||
if ($operator_code) {
|
||||
$form_on_submit = "if(navigator.userAgent.toLowerCase().indexOf('opera') != -1 " .
|
||||
"&& window.event.preventDefault) window.event.preventDefault();" .
|
||||
"this.newWindow = window.open({$jslink} + '&operator_code=' + document.getElementById('mibewOperatorCodeField').value, 'mibew', '{$popup_options}');" .
|
||||
"this.newWindow.focus();this.newWindow.opener=window;return false;";
|
||||
$temp = '<form action="" onsubmit="' . $form_on_submit . '" id="mibewOperatorCodeForm">' .
|
||||
'<input type="text" id="mibewOperatorCodeField" />' .
|
||||
'</form>';
|
||||
return "<!-- mibew operator code field -->" . $temp . "<!-- / mibew operator code field -->";
|
||||
}
|
||||
// Generate operator code field
|
||||
if ($operator_code) {
|
||||
$form_on_submit = "if(navigator.userAgent.toLowerCase().indexOf('opera') != -1 "
|
||||
. "&& window.event.preventDefault) window.event.preventDefault();"
|
||||
. "this.newWindow = window.open({$js_link} + '&operator_code=' "
|
||||
. "+ document.getElementById('mibewOperatorCodeField').value, 'mibew', '{$popup_options}');"
|
||||
. "this.newWindow.focus();this.newWindow.opener=window;return false;";
|
||||
$temp = '<form action="" onsubmit="' . $form_on_submit . '" id="mibewOperatorCodeForm">'
|
||||
. '<input type="text" id="mibewOperatorCodeField" />'
|
||||
. '</form>';
|
||||
return "<!-- mibew operator code field -->" . $temp . "<!-- / mibew operator code field -->";
|
||||
}
|
||||
|
||||
// Generate button
|
||||
$temp = get_popup($link, "$jslink",
|
||||
$inner, $title, "mibew", $popup_options);
|
||||
if (Settings::get('enabletracking')) {
|
||||
$widget_data = array();
|
||||
// Generate button
|
||||
$temp = get_popup($link, "$js_link", $inner, $title, "mibew", $popup_options);
|
||||
if (Settings::get('enabletracking')) {
|
||||
$widget_data = array();
|
||||
|
||||
// Get actual invitation style instance
|
||||
if (!$invitation_style_name) {
|
||||
$invitation_style_name = InvitationStyle::currentStyle();
|
||||
}
|
||||
$invitation_style = new InvitationStyle($invitation_style_name);
|
||||
// Get actual invitation style instance
|
||||
if (!$invitation_style_name) {
|
||||
$invitation_style_name = InvitationStyle::currentStyle();
|
||||
}
|
||||
$invitation_style = new InvitationStyle($invitation_style_name);
|
||||
|
||||
// URL of file with additional CSS rules for invitation popup
|
||||
$widget_data['inviteStyle'] = $app_location . '/' .
|
||||
$invitation_style->filesPath() .
|
||||
'/invite.css';
|
||||
// URL of file with additional CSS rules for invitation popup
|
||||
$widget_data['inviteStyle'] = $app_location . '/' .
|
||||
$invitation_style->filesPath() .
|
||||
'/invite.css';
|
||||
|
||||
// Time between requests to the server in milliseconds
|
||||
$widget_data['requestTimeout'] = Settings::get('updatefrequency_tracking')
|
||||
* 1000;
|
||||
// Time between requests to the server in milliseconds
|
||||
$widget_data['requestTimeout'] = Settings::get('updatefrequency_tracking') * 1000;
|
||||
|
||||
// URL for requests
|
||||
$widget_data['requestURL'] = $app_location . '/widget.php';
|
||||
// URL for requests
|
||||
$widget_data['requestURL'] = $app_location . '/widget.php';
|
||||
|
||||
// Locale for invitation
|
||||
$widget_data['locale'] = $locale;
|
||||
// Locale for invitation
|
||||
$widget_data['locale'] = $locale;
|
||||
|
||||
// Name of the cookie to track user. Use if third-party cookie blocked
|
||||
$widget_data['visitorCookieName'] = VISITOR_COOKIE_NAME;
|
||||
// Name of the cookie to track user. Use if third-party cookie blocked
|
||||
$widget_data['visitorCookieName'] = VISITOR_COOKIE_NAME;
|
||||
|
||||
// Build additional button code
|
||||
$temp = preg_replace('/^(<a )/', '\1id="mibewAgentButton" ', $temp) .
|
||||
'<div id="mibewinvitation"></div>' .
|
||||
'<script type="text/javascript" src="' .
|
||||
$app_location . '/js/compiled/widget.js' .
|
||||
'"></script>' .
|
||||
'<script type="text/javascript">' .
|
||||
'Mibew.Widget.init('.json_encode($widget_data).')' .
|
||||
'</script>';
|
||||
}
|
||||
return "<!-- mibew button -->" . $temp . "<!-- / mibew button -->";
|
||||
// Build additional button code
|
||||
$temp = preg_replace('/^(<a )/', '\1id="mibewAgentButton" ', $temp)
|
||||
. '<div id="mibewinvitation"></div>'
|
||||
. '<script type="text/javascript" src="'
|
||||
. $app_location . '/js/compiled/widget.js'
|
||||
. '"></script>'
|
||||
. '<script type="text/javascript">'
|
||||
. 'Mibew.Widget.init(' . json_encode($widget_data) . ')'
|
||||
. '</script>';
|
||||
}
|
||||
|
||||
return "<!-- mibew button -->" . $temp . "<!-- / mibew button -->";
|
||||
}
|
||||
|
||||
function verifyparam_groupid($paramid, &$errors) {
|
||||
$groupid = "";
|
||||
$groupid = verifyparam($paramid, "/^\d{0,8}$/", "");
|
||||
if ($groupid) {
|
||||
$group = group_by_id($groupid);
|
||||
if (!$group) {
|
||||
$errors[] = getlocal("page.group.no_such");
|
||||
$groupid = "";
|
||||
}
|
||||
}
|
||||
return $groupid;
|
||||
function verifyparam_groupid($param_id, &$errors)
|
||||
{
|
||||
$group_id = verify_param($param_id, "/^\d{0,8}$/", "");
|
||||
if ($group_id) {
|
||||
$group = group_by_id($group_id);
|
||||
if (!$group) {
|
||||
$errors[] = getlocal("page.group.no_such");
|
||||
$group_id = "";
|
||||
}
|
||||
}
|
||||
|
||||
return $group_id;
|
||||
}
|
||||
|
||||
function get_groups_list()
|
||||
{
|
||||
$result = array();
|
||||
$allgroups = get_all_groups();
|
||||
$result[] = array('groupid' => '', 'vclocalname' => getlocal("page.gen_button.default_group"), 'level' => 0);
|
||||
foreach ($allgroups as $g) {
|
||||
$result[] = $g;
|
||||
}
|
||||
return $result;
|
||||
$result = array();
|
||||
$all_groups = get_all_groups();
|
||||
$result[] = array(
|
||||
'groupid' => '',
|
||||
'vclocalname' => getlocal("page.gen_button.default_group"),
|
||||
'level' => 0,
|
||||
);
|
||||
foreach ($all_groups as $g) {
|
||||
$result[] = $g;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function get_image_locales_map($localesdir)
|
||||
function get_image_locales_map($locales_dir)
|
||||
{
|
||||
$imageLocales = array();
|
||||
$allLocales = get_available_locales();
|
||||
foreach ($allLocales as $curr) {
|
||||
$imagesDir = "$localesdir/$curr/button";
|
||||
if ($handle = @opendir($imagesDir)) {
|
||||
while (false !== ($file = readdir($handle))) {
|
||||
if (preg_match("/^(\w+)_on.gif$/", $file, $matches)
|
||||
&& is_file("$imagesDir/" . $matches[1] . "_off.gif")) {
|
||||
$image = $matches[1];
|
||||
if (!isset($imageLocales[$image])) {
|
||||
$imageLocales[$image] = array();
|
||||
}
|
||||
$imageLocales[$image][] = $curr;
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
}
|
||||
return $imageLocales;
|
||||
}
|
||||
$image_locales = array();
|
||||
$all_locales = get_available_locales();
|
||||
foreach ($all_locales as $curr) {
|
||||
$images_dir = "$locales_dir/$curr/button";
|
||||
if ($handle = @opendir($images_dir)) {
|
||||
while (false !== ($file = readdir($handle))) {
|
||||
$both_files_exist = preg_match("/^(\w+)_on.gif$/", $file, $matches)
|
||||
&& is_file("$images_dir/" . $matches[1] . "_off.gif");
|
||||
if ($both_files_exist) {
|
||||
$image = $matches[1];
|
||||
if (!isset($image_locales[$image])) {
|
||||
$image_locales[$image] = array();
|
||||
}
|
||||
$image_locales[$image][] = $curr;
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
return $image_locales;
|
||||
}
|
||||
|
@ -21,32 +21,35 @@ use Mibew\Settings;
|
||||
|
||||
function group_by_id($id)
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$group = $db->query(
|
||||
"select * from {chatgroup} where groupid = ?",
|
||||
array($id),
|
||||
array('return_rows' => Database::RETURN_ONE_ROW)
|
||||
);
|
||||
return $group;
|
||||
$db = Database::getInstance();
|
||||
$group = $db->query(
|
||||
"SELECT * FROM {chatgroup} WHERE groupid = ?",
|
||||
array($id),
|
||||
array('return_rows' => Database::RETURN_ONE_ROW)
|
||||
);
|
||||
|
||||
return $group;
|
||||
}
|
||||
|
||||
function group_by_name($name)
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$group = $db->query(
|
||||
"select * from {chatgroup} where vclocalname = ?",
|
||||
array($name),
|
||||
array('return_rows' => Database::RETURN_ONE_ROW)
|
||||
);
|
||||
return $group;
|
||||
$db = Database::getInstance();
|
||||
$group = $db->query(
|
||||
"SELECT * FROM {chatgroup} WHERE vclocalname = ?",
|
||||
array($name),
|
||||
array('return_rows' => Database::RETURN_ONE_ROW)
|
||||
);
|
||||
|
||||
return $group;
|
||||
}
|
||||
|
||||
function get_group_name($group)
|
||||
{
|
||||
if (HOME_LOCALE == CURRENT_LOCALE || !isset($group['vccommonname']) || !$group['vccommonname'])
|
||||
return $group['vclocalname'];
|
||||
else
|
||||
return $group['vccommonname'];
|
||||
if (HOME_LOCALE == CURRENT_LOCALE || !isset($group['vccommonname']) || !$group['vccommonname']) {
|
||||
return $group['vclocalname'];
|
||||
} else {
|
||||
return $group['vccommonname'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -57,97 +60,114 @@ function get_group_name($group)
|
||||
* @param int $active Number of the active tab. The count starts from 0.
|
||||
* @return array Tabs list
|
||||
*/
|
||||
function setup_group_settings_tabs($gid, $active) {
|
||||
$tabs = array();
|
||||
function setup_group_settings_tabs($gid, $active)
|
||||
{
|
||||
$tabs = array();
|
||||
|
||||
if ($gid) {
|
||||
$tabs = array(
|
||||
getlocal("page_group.tab.main") => $active != 0 ? (MIBEW_WEB_ROOT . "/operator/group.php?gid=$gid") : "",
|
||||
getlocal("page_group.tab.members") => $active != 1 ? (MIBEW_WEB_ROOT . "/operator/groupmembers.php?gid=$gid") : "",
|
||||
);
|
||||
}
|
||||
if ($gid) {
|
||||
$tabs = array(
|
||||
getlocal("page_group.tab.main") => ($active != 0
|
||||
? (MIBEW_WEB_ROOT . "/operator/group.php?gid=$gid")
|
||||
: ""),
|
||||
getlocal("page_group.tab.members") => ($active != 1
|
||||
? (MIBEW_WEB_ROOT . "/operator/groupmembers.php?gid=$gid")
|
||||
: ""),
|
||||
);
|
||||
}
|
||||
|
||||
return $tabs;
|
||||
return $tabs;
|
||||
}
|
||||
|
||||
function get_operator_groupslist($operatorid)
|
||||
function get_operator_groups_list($operator_id)
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
if (Settings::get('enablegroups') == '1') {
|
||||
$groupids = array(0);
|
||||
$allgroups = $db->query(
|
||||
"select groupid from {chatgroupoperator} where operatorid = ? order by groupid",
|
||||
array($operatorid),
|
||||
array('return_rows' => Database::RETURN_ALL_ROWS)
|
||||
);
|
||||
foreach ($allgroups as $g) {
|
||||
$groupids[] = $g['groupid'];
|
||||
}
|
||||
return implode(",", $groupids);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
$db = Database::getInstance();
|
||||
if (Settings::get('enablegroups') == '1') {
|
||||
$group_ids = array(0);
|
||||
$all_groups = $db->query(
|
||||
"SELECT groupid FROM {chatgroupoperator} WHERE operatorid = ? ORDER BY groupid",
|
||||
array($operator_id),
|
||||
array('return_rows' => Database::RETURN_ALL_ROWS)
|
||||
);
|
||||
foreach ($all_groups as $g) {
|
||||
$group_ids[] = $g['groupid'];
|
||||
}
|
||||
|
||||
return implode(",", $group_ids);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
function get_available_parent_groups($skipgroup)
|
||||
function get_available_parent_groups($skip_group)
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$groupslist = $db->query(
|
||||
"select {chatgroup}.groupid as groupid, parent, vclocalname " .
|
||||
"from {chatgroup} order by vclocalname",
|
||||
NULL,
|
||||
array('return_rows' => Database::RETURN_ALL_ROWS)
|
||||
);
|
||||
$result = array(array('groupid' => '', 'level' => '', 'vclocalname' => getlocal("form.field.groupparent.root")));
|
||||
$result = array();
|
||||
|
||||
if ($skipgroup) {
|
||||
$skipgroup = (array)$skipgroup;
|
||||
} else {
|
||||
$skipgroup = array();
|
||||
}
|
||||
$result[] = array(
|
||||
'groupid' => '',
|
||||
'level' => '',
|
||||
'vclocalname' => getlocal("form.field.groupparent.root"),
|
||||
);
|
||||
|
||||
$result = array_merge($result, get_sorted_child_groups_($groupslist, $skipgroup, 0) );
|
||||
return $result;
|
||||
$db = Database::getInstance();
|
||||
$groups_list = $db->query(
|
||||
("SELECT {chatgroup}.groupid AS groupid, parent, vclocalname "
|
||||
. "FROM {chatgroup} ORDER BY vclocalname"),
|
||||
null,
|
||||
array('return_rows' => Database::RETURN_ALL_ROWS)
|
||||
);
|
||||
|
||||
if ($skip_group) {
|
||||
$skip_group = (array) $skip_group;
|
||||
} else {
|
||||
$skip_group = array();
|
||||
}
|
||||
|
||||
$result = array_merge($result, get_sorted_child_groups_($groups_list, $skip_group, 0));
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function group_has_children($groupid)
|
||||
function group_has_children($group_id)
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$children = $db->query(
|
||||
"select COUNT(*) as count from {chatgroup} where parent = ?",
|
||||
array($groupid),
|
||||
array('return_rows' => Database::RETURN_ONE_ROW)
|
||||
);
|
||||
return ($children['count'] > 0);
|
||||
$db = Database::getInstance();
|
||||
$children = $db->query(
|
||||
"SELECT COUNT(*) AS count FROM {chatgroup} WHERE parent = ?",
|
||||
array($group_id),
|
||||
array('return_rows' => Database::RETURN_ONE_ROW)
|
||||
);
|
||||
|
||||
return ($children['count'] > 0);
|
||||
}
|
||||
|
||||
function get_top_level_group($group)
|
||||
{
|
||||
return is_null($group['parent'])?$group:group_by_id($group['parent']);
|
||||
return is_null($group['parent']) ? $group : group_by_id($group['parent']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to load email for specified group or for its parent.
|
||||
*
|
||||
* @param int $group_id Group id
|
||||
* @return string|boolean Email address or false if there is no email
|
||||
*/
|
||||
function get_group_email($group_id) {
|
||||
// Try to get group email
|
||||
$group = group_by_id($group_id);
|
||||
if ($group && !empty($group['vcemail'])) {
|
||||
return $group['vcemail'];
|
||||
}
|
||||
function get_group_email($group_id)
|
||||
{
|
||||
// Try to get group email
|
||||
$group = group_by_id($group_id);
|
||||
if ($group && !empty($group['vcemail'])) {
|
||||
return $group['vcemail'];
|
||||
}
|
||||
|
||||
// Try to get parent group email
|
||||
if (! is_null($group['parent'])) {
|
||||
$group = group_by_id($group['parent']);
|
||||
if ($group && !empty($group['vcemail'])) {
|
||||
return $group['vcemail'];
|
||||
}
|
||||
}
|
||||
// Try to get parent group email
|
||||
if (!is_null($group['parent'])) {
|
||||
$group = group_by_id($group['parent']);
|
||||
if ($group && !empty($group['vcemail'])) {
|
||||
return $group['vcemail'];
|
||||
}
|
||||
}
|
||||
|
||||
// There is no email
|
||||
return false;
|
||||
// There is no email
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -156,9 +176,10 @@ function get_group_email($group_id) {
|
||||
* @param array $group Associative group array. Should contain 'ilastseen' key.
|
||||
* @return bool
|
||||
*/
|
||||
function group_is_online($group) {
|
||||
return ($group['ilastseen'] !== NULL
|
||||
&& $group['ilastseen'] < Settings::get('online_timeout'));
|
||||
function group_is_online($group)
|
||||
{
|
||||
return $group['ilastseen'] !== null
|
||||
&& $group['ilastseen'] < Settings::get('online_timeout');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -168,9 +189,10 @@ function group_is_online($group) {
|
||||
* key.
|
||||
* @return bool
|
||||
*/
|
||||
function group_is_away($group) {
|
||||
return $group['ilastseenaway'] !== NULL
|
||||
&& $group['ilastseenaway'] < Settings::get('online_timeout');
|
||||
function group_is_away($group)
|
||||
{
|
||||
return $group['ilastseenaway'] !== null
|
||||
&& $group['ilastseenaway'] < Settings::get('online_timeout');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -181,137 +203,173 @@ function group_is_away($group) {
|
||||
* - 'vclocaldescription': string, contain local description of the group.
|
||||
* @return string Group description
|
||||
*/
|
||||
function get_group_description($group) {
|
||||
if (HOME_LOCALE == CURRENT_LOCALE
|
||||
|| !isset($group['vccommondescription'])
|
||||
|| !$group['vccommondescription']) {
|
||||
return $group['vclocaldescription'];
|
||||
} else {
|
||||
return $group['vccommondescription'];
|
||||
}
|
||||
function get_group_description($group)
|
||||
{
|
||||
$use_local_description = HOME_LOCALE == CURRENT_LOCALE
|
||||
|| !isset($group['vccommondescription'])
|
||||
|| !$group['vccommondescription'];
|
||||
|
||||
if ($use_local_description) {
|
||||
return $group['vclocaldescription'];
|
||||
} else {
|
||||
return $group['vccommondescription'];
|
||||
}
|
||||
}
|
||||
|
||||
function check_group_params($group, $extra_params = NULL)
|
||||
function check_group_params($group, $extra_params = null)
|
||||
{
|
||||
$obligatory_params = array(
|
||||
'name',
|
||||
'description',
|
||||
'commonname',
|
||||
'commondescription',
|
||||
'email',
|
||||
'weight',
|
||||
'parent',
|
||||
'chattitle',
|
||||
'hosturl',
|
||||
'logo');
|
||||
$params = is_null($extra_params)?$obligatory_params:array_merge($obligatory_params,$extra_params);
|
||||
if(count(array_diff($params, array_keys($group))) != 0){
|
||||
die('Wrong parameters set!');
|
||||
}
|
||||
$obligatory_params = array(
|
||||
'name',
|
||||
'description',
|
||||
'commonname',
|
||||
'commondescription',
|
||||
'email',
|
||||
'weight',
|
||||
'parent',
|
||||
'chattitle',
|
||||
'hosturl',
|
||||
'logo',
|
||||
);
|
||||
|
||||
$params = is_null($extra_params)
|
||||
? $obligatory_params
|
||||
: array_merge($obligatory_params, $extra_params);
|
||||
|
||||
if (count(array_diff($params, array_keys($group))) != 0) {
|
||||
die('Wrong parameters set!');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates group
|
||||
*
|
||||
* @param array $group Operators' group.
|
||||
* The $group array must contains following keys:
|
||||
* name, description, commonname, commondescription,
|
||||
* email, weight, parent, title, chattitle, hosturl, logo
|
||||
* @param array $group Operators' group. The $group array must contains the
|
||||
* following keys:
|
||||
* - name,
|
||||
* - description,
|
||||
* - commonname,
|
||||
* - commondescription,
|
||||
* - email,
|
||||
* - weight,
|
||||
* - parent,
|
||||
* - title,
|
||||
* - chattitle,
|
||||
* - hosturl,
|
||||
* - logo
|
||||
* @return array Created group
|
||||
*/
|
||||
function create_group($group)
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
check_group_params($group);
|
||||
$db->query(
|
||||
"insert into {chatgroup} (parent, vclocalname,vclocaldescription,vccommonname, " .
|
||||
"vccommondescription,vcemail,vctitle,vcchattitle,vchosturl,vclogo,iweight) " .
|
||||
"values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
array(
|
||||
($group['parent'] ? (int)$group['parent'] : NULL),
|
||||
$group['name'],
|
||||
$group['description'],
|
||||
$group['commonname'],
|
||||
$group['commondescription'],
|
||||
$group['email'],
|
||||
$group['title'],
|
||||
$group['chattitle'],
|
||||
$group['hosturl'],
|
||||
$group['logo'],
|
||||
$group['weight']
|
||||
)
|
||||
);
|
||||
$id = $db->insertedId();
|
||||
check_group_params($group);
|
||||
|
||||
$newdep = $db->query(
|
||||
"select * from {chatgroup} where groupid = ?",
|
||||
array($id),
|
||||
array('return_rows' => Database::RETURN_ONE_ROW)
|
||||
);
|
||||
return $newdep;
|
||||
$db = Database::getInstance();
|
||||
$db->query(
|
||||
("INSERT INTO {chatgroup} ("
|
||||
. "parent, vclocalname, vclocaldescription, vccommonname, "
|
||||
. "vccommondescription, vcemail, vctitle, vcchattitle, vchosturl, "
|
||||
. "vclogo, iweight"
|
||||
. ") values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"),
|
||||
array(
|
||||
($group['parent'] ? (int) $group['parent'] : null),
|
||||
$group['name'],
|
||||
$group['description'],
|
||||
$group['commonname'],
|
||||
$group['commondescription'],
|
||||
$group['email'],
|
||||
$group['title'],
|
||||
$group['chattitle'],
|
||||
$group['hosturl'],
|
||||
$group['logo'],
|
||||
$group['weight'],
|
||||
)
|
||||
);
|
||||
$id = $db->insertedId();
|
||||
|
||||
$new_group = $db->query(
|
||||
"SELECT * FROM {chatgroup} WHERE groupid = ?",
|
||||
array($id),
|
||||
array('return_rows' => Database::RETURN_ONE_ROW)
|
||||
);
|
||||
|
||||
return $new_group;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates group info
|
||||
*
|
||||
* @param array $group Operators' group.
|
||||
* The $group array must contains following keys:
|
||||
* id, name, description, commonname, commondescription,
|
||||
* email, weight, parent, title, chattitle, hosturl, logo
|
||||
* @param array $group Operators' group. The $group array must contains the
|
||||
* following keys:
|
||||
* - id,
|
||||
* - name,
|
||||
* - description,
|
||||
* - commonname,
|
||||
* - commondescription,
|
||||
* - email,
|
||||
* - weight,
|
||||
* - parent,
|
||||
* - title,
|
||||
* - chattitle,
|
||||
* - hosturl,
|
||||
* - logo
|
||||
*/
|
||||
function update_group($group)
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
check_group_params($group, array('id'));
|
||||
$db->query(
|
||||
"update {chatgroup} set parent = ?, vclocalname = ?, vclocaldescription = ?, " .
|
||||
"vccommonname = ?, vccommondescription = ?, vcemail = ?, vctitle = ?, " .
|
||||
"vcchattitle = ?, vchosturl = ?, vclogo = ?, iweight = ? where groupid = ?",
|
||||
array(
|
||||
($group['parent'] ? (int)$group['parent'] : NULL),
|
||||
$group['name'],
|
||||
$group['description'],
|
||||
$group['commonname'],
|
||||
$group['commondescription'],
|
||||
$group['email'],
|
||||
$group['title'],
|
||||
$group['chattitle'],
|
||||
$group['hosturl'],
|
||||
$group['logo'],
|
||||
$group['weight'],
|
||||
$group['id']
|
||||
)
|
||||
);
|
||||
check_group_params($group, array('id'));
|
||||
|
||||
if ($group['parent']) {
|
||||
$db->query(
|
||||
"update {chatgroup} set parent = NULL where parent = ?",
|
||||
array($group['id'])
|
||||
);
|
||||
}
|
||||
$db = Database::getInstance();
|
||||
$db->query(
|
||||
("UPDATE {chatgroup} SET "
|
||||
. "parent = ?, vclocalname = ?, vclocaldescription = ?, "
|
||||
. "vccommonname = ?, vccommondescription = ?, "
|
||||
. "vcemail = ?, vctitle = ?, vcchattitle = ?, "
|
||||
. "vchosturl = ?, vclogo = ?, iweight = ? "
|
||||
. "where groupid = ?"),
|
||||
array(
|
||||
($group['parent'] ? (int) $group['parent'] : null),
|
||||
$group['name'],
|
||||
$group['description'],
|
||||
$group['commonname'],
|
||||
$group['commondescription'],
|
||||
$group['email'],
|
||||
$group['title'],
|
||||
$group['chattitle'],
|
||||
$group['hosturl'],
|
||||
$group['logo'],
|
||||
$group['weight'],
|
||||
$group['id']
|
||||
)
|
||||
);
|
||||
|
||||
if ($group['parent']) {
|
||||
$db->query(
|
||||
"UPDATE {chatgroup} SET parent = NULL WHERE parent = ?",
|
||||
array($group['id'])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function get_group_members($groupid)
|
||||
function get_group_members($group_id)
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
return $db->query(
|
||||
"select operatorid from {chatgroupoperator} where groupid = ?",
|
||||
array($groupid),
|
||||
array('return_rows' => Database::RETURN_ALL_ROWS)
|
||||
);
|
||||
$db = Database::getInstance();
|
||||
return $db->query(
|
||||
"SELECT operatorid FROM {chatgroupoperator} WHERE groupid = ?",
|
||||
array($group_id),
|
||||
array('return_rows' => Database::RETURN_ALL_ROWS)
|
||||
);
|
||||
}
|
||||
|
||||
function update_group_members($groupid, $newvalue)
|
||||
function update_group_members($group_id, $new_value)
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$db->query("delete from {chatgroupoperator} where groupid = ?", array($groupid));
|
||||
$db = Database::getInstance();
|
||||
$db->query(
|
||||
"DELETE FROM {chatgroupoperator} WHERE groupid = ?",
|
||||
array($group_id)
|
||||
);
|
||||
|
||||
foreach ($newvalue as $opid) {
|
||||
$db->query(
|
||||
"insert into {chatgroupoperator} (groupid, operatorid) values (?, ?)",
|
||||
array($groupid,$opid)
|
||||
);
|
||||
}
|
||||
foreach ($new_value as $operator_id) {
|
||||
$db->query(
|
||||
"INSERT INTO {chatgroupoperator} (groupid, operatorid) VALUES (?, ?)",
|
||||
array($group_id, $operator_id)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -24,10 +24,16 @@ define('MIBEW_FS_ROOT', dirname(dirname(__FILE__)));
|
||||
@ini_set('open_basedir', MIBEW_FS_ROOT);
|
||||
|
||||
// Include configuration file
|
||||
require_once(MIBEW_FS_ROOT.'/libs/config.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/config.php');
|
||||
|
||||
// Sanitize path to application and remove extra slashes
|
||||
$mibewroot = join("/", array_map("urlencode", preg_split('/\//', preg_replace('/\/+$/', '', preg_replace('/\/{2,}/', '/', '/' . $mibewroot)))));
|
||||
$mibewroot = join(
|
||||
"/",
|
||||
array_map(
|
||||
"urlencode",
|
||||
preg_split('/\//', preg_replace('/\/+$/', '', preg_replace('/\/{2,}/', '/', '/' . $mibewroot)))
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Base URL of the Mibew installation
|
||||
@ -35,28 +41,29 @@ $mibewroot = join("/", array_map("urlencode", preg_split('/\//', preg_replace('/
|
||||
define('MIBEW_WEB_ROOT', $mibewroot);
|
||||
|
||||
// Include system constants file
|
||||
require_once(MIBEW_FS_ROOT.'/libs/common/constants.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/common/constants.php');
|
||||
|
||||
// Initialize classes autoloading
|
||||
require_once(MIBEW_FS_ROOT.'/libs/common/autoload.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/common/autoload.php');
|
||||
spl_autoload_register('class_autoload');
|
||||
|
||||
// Include common libs
|
||||
require_once(MIBEW_FS_ROOT.'/libs/common/configurations.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/common/csrf.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/common/datetime.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/common/forms.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/common/verification.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/common/locale.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/common/misc.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/common/request.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/common/response.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/common/string.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/common/configurations.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/common/verification.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/common/converter.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/common/locale.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/common/csrf.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/common/datetime.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/common/forms.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/common/misc.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/common/request.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/common/response.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/common/string.php');
|
||||
|
||||
// Make session cookie more secure
|
||||
@ini_set('session.cookie_httponly', TRUE);
|
||||
@ini_set('session.cookie_httponly', true);
|
||||
if (is_secure_request()) {
|
||||
@ini_set('session.cookie_secure', TRUE);
|
||||
@ini_set('session.cookie_secure', true);
|
||||
}
|
||||
@ini_set('session.cookie_path', MIBEW_WEB_ROOT . "/");
|
||||
@ini_set('session.name', 'MibewSessionID');
|
||||
@ -66,25 +73,23 @@ session_start();
|
||||
|
||||
// Initialize the database
|
||||
\Mibew\Database::initialize(
|
||||
$mysqlhost,
|
||||
$mysqllogin,
|
||||
$mysqlpass,
|
||||
$use_persistent_connection,
|
||||
$mysqldb,
|
||||
$mysqlprefix,
|
||||
$force_charset_in_connection,
|
||||
$dbencoding
|
||||
$mysqlhost,
|
||||
$mysqllogin,
|
||||
$mysqlpass,
|
||||
$use_persistent_connection,
|
||||
$mysqldb,
|
||||
$mysqlprefix,
|
||||
$force_charset_in_connection,
|
||||
$dbencoding
|
||||
);
|
||||
|
||||
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");
|
||||
// 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");
|
||||
}
|
||||
|
||||
if (! empty($plugins_list)) {
|
||||
// Variable $plugins_config defined in libs/config.php
|
||||
\Mibew\PluginManager::loadPlugins($plugins_list);
|
||||
if (!empty($plugins_list)) {
|
||||
// Variable $plugins_config defined in libs/config.php
|
||||
\Mibew\PluginManager::loadPlugins($plugins_list);
|
||||
}
|
||||
|
||||
?>
|
@ -29,27 +29,29 @@ use Mibew\Thread;
|
||||
* - 'threadid': int, ID of the thread, related with visitor or boolean false
|
||||
* if visitor with specfied ID does not exist.
|
||||
*/
|
||||
function invitation_state($visitor_id) {
|
||||
$db = Database::getInstance();
|
||||
$db_result = $db->query(
|
||||
"SELECT t.threadid, t.invitationstate, t.istate " .
|
||||
"FROM {chatsitevisitor} v, {chatthread} t " .
|
||||
"WHERE visitorid = ? " .
|
||||
"AND t.threadid = v.threadid",
|
||||
array($visitor_id),
|
||||
array('return_rows' => Database::RETURN_ONE_ROW)
|
||||
);
|
||||
function invitation_state($visitor_id)
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$db_result = $db->query(
|
||||
("SELECT t.threadid, t.invitationstate, t.istate "
|
||||
. "FROM {chatsitevisitor} v, {chatthread} t "
|
||||
. "WHERE visitorid = ? "
|
||||
. "AND t.threadid = v.threadid"),
|
||||
array($visitor_id),
|
||||
array('return_rows' => Database::RETURN_ONE_ROW)
|
||||
);
|
||||
|
||||
$ret = array();
|
||||
if (!$db_result) {
|
||||
$ret['invited'] = false;
|
||||
$ret['threadid'] = false;
|
||||
} else {
|
||||
$ret['invited'] = ($db_result['istate'] == Thread::STATE_INVITED)
|
||||
&& ($db_result['invitationstate'] == Thread::INVITATION_WAIT);
|
||||
$ret['threadid'] = $db_result['threadid'];
|
||||
}
|
||||
return $ret;
|
||||
$ret = array();
|
||||
if (!$db_result) {
|
||||
$ret['invited'] = false;
|
||||
$ret['threadid'] = false;
|
||||
} else {
|
||||
$ret['invited'] = ($db_result['istate'] == Thread::STATE_INVITED)
|
||||
&& ($db_result['invitationstate'] == Thread::INVITATION_WAIT);
|
||||
$ret['threadid'] = $db_result['threadid'];
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -58,79 +60,80 @@ function invitation_state($visitor_id) {
|
||||
* @param int $visitor_id ID of the visitor, who must be invited.
|
||||
* @param array $operator Info for operator who invite the visitor
|
||||
* @return Thread|boolean Thread object related with invitation or boolean
|
||||
* false on failure
|
||||
* false on failure
|
||||
*/
|
||||
function invitation_invite($visitor_id, $operator) {
|
||||
// Check if visitor already invited
|
||||
$invitation_state = invitation_state($visitor_id);
|
||||
if ($invitation_state['invited']) {
|
||||
return false;
|
||||
}
|
||||
function invitation_invite($visitor_id, $operator)
|
||||
{
|
||||
// Check if visitor already invited
|
||||
$invitation_state = invitation_state($visitor_id);
|
||||
if ($invitation_state['invited']) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get visitor info
|
||||
$visitor = track_get_visitor_by_id($visitor_id);
|
||||
// Get visitor info
|
||||
$visitor = track_get_visitor_by_id($visitor_id);
|
||||
|
||||
// Get last page visited by the visitor
|
||||
$visitor_path = track_get_path($visitor);
|
||||
ksort($visitor_path);
|
||||
$last_visited_page = array_pop($visitor_path);
|
||||
// Get last page visited by the visitor
|
||||
$visitor_path = track_get_path($visitor);
|
||||
ksort($visitor_path);
|
||||
$last_visited_page = array_pop($visitor_path);
|
||||
|
||||
// Get visitor details
|
||||
$visitor_details = track_retrieve_details($visitor);
|
||||
// Get visitor details
|
||||
$visitor_details = track_retrieve_details($visitor);
|
||||
|
||||
// Get some operator's info
|
||||
$operator_name = get_operator_name($operator);
|
||||
// Get some operator's info
|
||||
$operator_name = get_operator_name($operator);
|
||||
|
||||
// Create thread for invitation
|
||||
$thread = Thread::create();
|
||||
if (! $thread) {
|
||||
// Something went wrong
|
||||
return false;
|
||||
}
|
||||
// Populate thread and save it
|
||||
$thread->agentId = $operator['operatorid'];
|
||||
$thread->agentName = $operator_name;
|
||||
$thread->userName = $visitor['username'];
|
||||
$thread->remote = $visitor_details['remote_host'];
|
||||
$thread->referer = $last_visited_page;
|
||||
// User's locale is unknown, set operator locale to the thread
|
||||
$thread->locale = CURRENT_LOCALE;
|
||||
$thread->userId = $visitor['userid'];
|
||||
$thread->userAgent = $visitor_details['user_agent'];
|
||||
$thread->state = Thread::STATE_INVITED;
|
||||
$thread->invitationState = Thread::INVITATION_WAIT;
|
||||
$thread->save();
|
||||
// Create thread for invitation
|
||||
$thread = Thread::create();
|
||||
if (!$thread) {
|
||||
// Something went wrong
|
||||
return false;
|
||||
}
|
||||
// Populate thread and save it
|
||||
$thread->agentId = $operator['operatorid'];
|
||||
$thread->agentName = $operator_name;
|
||||
$thread->userName = $visitor['username'];
|
||||
$thread->remote = $visitor_details['remote_host'];
|
||||
$thread->referer = $last_visited_page;
|
||||
// User's locale is unknown, set operator locale to the thread
|
||||
$thread->locale = CURRENT_LOCALE;
|
||||
$thread->userId = $visitor['userid'];
|
||||
$thread->userAgent = $visitor_details['user_agent'];
|
||||
$thread->state = Thread::STATE_INVITED;
|
||||
$thread->invitationState = Thread::INVITATION_WAIT;
|
||||
$thread->save();
|
||||
|
||||
$db = Database::getInstance();
|
||||
$db->query(
|
||||
"UPDATE {chatsitevisitor} set " .
|
||||
"invitations = invitations + 1, " .
|
||||
"threadid = :thread_id " .
|
||||
"WHERE visitorid = :visitor_id",
|
||||
array(
|
||||
':thread_id' => $thread->id,
|
||||
':visitor_id' => $visitor_id
|
||||
)
|
||||
);
|
||||
$db = Database::getInstance();
|
||||
$db->query(
|
||||
("UPDATE {chatsitevisitor} set "
|
||||
. "invitations = invitations + 1, "
|
||||
. "threadid = :thread_id "
|
||||
. "WHERE visitorid = :visitor_id"),
|
||||
array(
|
||||
':thread_id' => $thread->id,
|
||||
':visitor_id' => $visitor_id,
|
||||
)
|
||||
);
|
||||
|
||||
// Send some messages
|
||||
$thread->postMessage(
|
||||
Thread::KIND_FOR_AGENT,
|
||||
getlocal2(
|
||||
'chat.visitor.invitation.sent',
|
||||
array($operator_name, $last_visited_page)
|
||||
)
|
||||
);
|
||||
$thread->postMessage(
|
||||
Thread::KIND_AGENT,
|
||||
getlocal("invitation.message"),
|
||||
array(
|
||||
'name' => $operator_name,
|
||||
'operator_id' => $operator['operatorid']
|
||||
)
|
||||
);
|
||||
// Send some messages
|
||||
$thread->postMessage(
|
||||
Thread::KIND_FOR_AGENT,
|
||||
getlocal2(
|
||||
'chat.visitor.invitation.sent',
|
||||
array($operator_name, $last_visited_page)
|
||||
)
|
||||
);
|
||||
$thread->postMessage(
|
||||
Thread::KIND_AGENT,
|
||||
getlocal("invitation.message"),
|
||||
array(
|
||||
'name' => $operator_name,
|
||||
'operator_id' => $operator['operatorid'],
|
||||
)
|
||||
);
|
||||
|
||||
return $thread;
|
||||
return $thread;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -139,47 +142,48 @@ function invitation_invite($visitor_id, $operator) {
|
||||
* @param int $visitor_id ID of the visitor who accept invitation
|
||||
* @return Thread|boolean Thread object or boolean false on failure
|
||||
*/
|
||||
function invitation_accept($visitor_id) {
|
||||
// Check if visitor was invited
|
||||
$invitation_state = invitation_state($visitor_id);
|
||||
if (! $invitation_state['invited']) {
|
||||
// Visitor was not invited
|
||||
return false;
|
||||
}
|
||||
function invitation_accept($visitor_id)
|
||||
{
|
||||
// Check if visitor was invited
|
||||
$invitation_state = invitation_state($visitor_id);
|
||||
if (!$invitation_state['invited']) {
|
||||
// Visitor was not invited
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get thread related with the visitor
|
||||
$db = Database::getInstance();
|
||||
$result = $db->query(
|
||||
"SELECT threadid FROM {chatsitevisitor} WHERE visitorid = :visitor_id",
|
||||
array(':visitor_id' => $visitor_id),
|
||||
array('return_rows' => Database::RETURN_ONE_ROW)
|
||||
);
|
||||
// Get thread related with the visitor
|
||||
$db = Database::getInstance();
|
||||
$result = $db->query(
|
||||
"SELECT threadid FROM {chatsitevisitor} WHERE visitorid = :visitor_id",
|
||||
array(':visitor_id' => $visitor_id),
|
||||
array('return_rows' => Database::RETURN_ONE_ROW)
|
||||
);
|
||||
|
||||
if (empty($result['threadid'])) {
|
||||
// Something went wrong. There is no thread related with the visitor.
|
||||
return false;
|
||||
}
|
||||
if (empty($result['threadid'])) {
|
||||
// Something went wrong. There is no thread related with the visitor.
|
||||
return false;
|
||||
}
|
||||
|
||||
$thread = Thread::load($result['threadid']);
|
||||
if (! $thread) {
|
||||
// Something went wrong. Cannot load thread.
|
||||
return false;
|
||||
}
|
||||
$thread = Thread::load($result['threadid']);
|
||||
if (!$thread) {
|
||||
// Something went wrong. Cannot load thread.
|
||||
return false;
|
||||
}
|
||||
|
||||
// Update thread info
|
||||
$thread->state = Thread::STATE_LOADING;
|
||||
$thread->invitationState = Thread::INVITATION_ACCEPTED;
|
||||
$thread->chatStarted = time();
|
||||
$thread->save();
|
||||
// Update thread info
|
||||
$thread->state = Thread::STATE_LOADING;
|
||||
$thread->invitationState = Thread::INVITATION_ACCEPTED;
|
||||
$thread->chatStarted = time();
|
||||
$thread->save();
|
||||
|
||||
// Update visitor info
|
||||
$db->query(
|
||||
"UPDATE {chatsitevisitor} SET chats = chats + 1 " .
|
||||
"WHERE visitorid = :visitor_id",
|
||||
array(':visitor_id' => $visitor_id)
|
||||
);
|
||||
// Update visitor info
|
||||
$db->query(
|
||||
("UPDATE {chatsitevisitor} SET chats = chats + 1 "
|
||||
. "WHERE visitorid = :visitor_id"),
|
||||
array(':visitor_id' => $visitor_id)
|
||||
);
|
||||
|
||||
return $thread;
|
||||
return $thread;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -187,87 +191,89 @@ function invitation_accept($visitor_id) {
|
||||
*
|
||||
* @param int $visitor_id ID of the visitor
|
||||
*/
|
||||
function invitation_reject($visitor_id) {
|
||||
$visitor = track_get_visitor_by_id($visitor_id);
|
||||
function invitation_reject($visitor_id)
|
||||
{
|
||||
$visitor = track_get_visitor_by_id($visitor_id);
|
||||
|
||||
// Send message to operator
|
||||
$thread = Thread::load($visitor['threadid']);
|
||||
if ($thread) {
|
||||
$thread->postMessage(
|
||||
Thread::KIND_FOR_AGENT,
|
||||
getlocal('chat.visitor.invitation.rejected')
|
||||
);
|
||||
}
|
||||
// Send message to operator
|
||||
$thread = Thread::load($visitor['threadid']);
|
||||
if ($thread) {
|
||||
$thread->postMessage(
|
||||
Thread::KIND_FOR_AGENT,
|
||||
getlocal('chat.visitor.invitation.rejected')
|
||||
);
|
||||
}
|
||||
|
||||
$db = Database::getInstance();
|
||||
$db->query(
|
||||
"UPDATE {chatsitevisitor} v, {chatthread} t SET " .
|
||||
"v.threadid = NULL, " .
|
||||
"t.invitationstate = :invitation_rejected, " .
|
||||
"t.istate = :state_closed, " .
|
||||
"t.dtmclosed = :now " .
|
||||
"WHERE t.threadid = v.threadid " .
|
||||
"AND visitorid = :visitor_id",
|
||||
array(
|
||||
':invitation_rejected' => Thread::INVITATION_REJECTED,
|
||||
':state_closed' => Thread::STATE_CLOSED,
|
||||
':visitor_id' => $visitor_id,
|
||||
':now' => time()
|
||||
)
|
||||
);
|
||||
$db = Database::getInstance();
|
||||
$db->query(
|
||||
("UPDATE {chatsitevisitor} v, {chatthread} t SET "
|
||||
. "v.threadid = NULL, "
|
||||
. "t.invitationstate = :invitation_rejected, "
|
||||
. "t.istate = :state_closed, "
|
||||
. "t.dtmclosed = :now "
|
||||
. "WHERE t.threadid = v.threadid "
|
||||
. "AND visitorid = :visitor_id"),
|
||||
array(
|
||||
':invitation_rejected' => Thread::INVITATION_REJECTED,
|
||||
':state_closed' => Thread::STATE_CLOSED,
|
||||
':visitor_id' => $visitor_id,
|
||||
':now' => time(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Close old invitations
|
||||
*/
|
||||
function invitation_close_old() {
|
||||
$db = Database::getInstance();
|
||||
function invitation_close_old()
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
|
||||
// Get all threads to close
|
||||
$threads = $db->query(
|
||||
"SELECT * FROM {chatthread} " .
|
||||
"WHERE istate = :state_invited " .
|
||||
"AND invitationstate = :invitation_wait " .
|
||||
"AND (:now - dtmcreated) > :lifetime",
|
||||
array(
|
||||
':invitation_wait' => Thread::INVITATION_WAIT,
|
||||
':state_invited' => Thread::STATE_INVITED,
|
||||
':lifetime' => Settings::get('invitation_lifetime'),
|
||||
':now' => time()
|
||||
),
|
||||
array('return_rows' => Database::RETURN_ALL_ROWS)
|
||||
);
|
||||
// Get all threads to close
|
||||
$threads = $db->query(
|
||||
("SELECT * FROM {chatthread} "
|
||||
. "WHERE istate = :state_invited "
|
||||
. "AND invitationstate = :invitation_wait "
|
||||
. "AND (:now - dtmcreated) > :lifetime"),
|
||||
array(
|
||||
':invitation_wait' => Thread::INVITATION_WAIT,
|
||||
':state_invited' => Thread::STATE_INVITED,
|
||||
':lifetime' => Settings::get('invitation_lifetime'),
|
||||
':now' => time(),
|
||||
),
|
||||
array('return_rows' => Database::RETURN_ALL_ROWS)
|
||||
);
|
||||
|
||||
// Remove old invitations
|
||||
$db->query(
|
||||
"UPDATE {chatsitevisitor} v, {chatthread} t SET " .
|
||||
"t.invitationstate = :invitation_ignored, " .
|
||||
"t.istate = :state_closed, " .
|
||||
"t.dtmclosed = :now, " .
|
||||
"v.threadid = NULL " .
|
||||
"WHERE t.istate = :state_invited " .
|
||||
"AND t.invitationstate = :invitation_wait " .
|
||||
"AND (:now - t.dtmcreated) > :lifetime",
|
||||
array(
|
||||
':invitation_ignored' => Thread::INVITATION_IGNORED,
|
||||
':invitation_wait' => Thread::INVITATION_WAIT,
|
||||
':state_closed' => Thread::STATE_CLOSED,
|
||||
':state_invited' => Thread::STATE_INVITED,
|
||||
':lifetime' => Settings::get('invitation_lifetime'),
|
||||
':now' => time()
|
||||
)
|
||||
);
|
||||
// Remove old invitations
|
||||
$db->query(
|
||||
("UPDATE {chatsitevisitor} v, {chatthread} t SET "
|
||||
. "t.invitationstate = :invitation_ignored, "
|
||||
. "t.istate = :state_closed, "
|
||||
. "t.dtmclosed = :now, "
|
||||
. "v.threadid = NULL "
|
||||
. "WHERE t.istate = :state_invited "
|
||||
. "AND t.invitationstate = :invitation_wait "
|
||||
. "AND (:now - t.dtmcreated) > :lifetime"),
|
||||
array(
|
||||
':invitation_ignored' => Thread::INVITATION_IGNORED,
|
||||
':invitation_wait' => Thread::INVITATION_WAIT,
|
||||
':state_closed' => Thread::STATE_CLOSED,
|
||||
':state_invited' => Thread::STATE_INVITED,
|
||||
':lifetime' => Settings::get('invitation_lifetime'),
|
||||
':now' => time(),
|
||||
)
|
||||
);
|
||||
|
||||
// Iterate over all threads and send messages to operator about close by
|
||||
// timeout
|
||||
foreach($threads as $thread_info) {
|
||||
$thread = Thread::createFromDbInfo($thread_info);
|
||||
$thread->postMessage(
|
||||
Thread::KIND_FOR_AGENT,
|
||||
getstring_('chat.visitor.invitation.ignored', $thread->locale)
|
||||
);
|
||||
unset($thread);
|
||||
}
|
||||
// Iterate over all threads and send messages to operator about close by
|
||||
// timeout
|
||||
foreach ($threads as $thread_info) {
|
||||
$thread = Thread::createFromDbInfo($thread_info);
|
||||
$thread->postMessage(
|
||||
Thread::KIND_FOR_AGENT,
|
||||
getstring_('chat.visitor.invitation.ignored', $thread->locale)
|
||||
);
|
||||
unset($thread);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -276,32 +282,31 @@ function invitation_close_old() {
|
||||
* @param Thread $thread Thread object related with invitation
|
||||
* @return array Array of invitation data
|
||||
*/
|
||||
function setup_invitation_view(Thread $thread) {
|
||||
$data = prepare_chat_app_data();
|
||||
function setup_invitation_view(Thread $thread)
|
||||
{
|
||||
$data = prepare_chat_app_data();
|
||||
|
||||
// Set refresh frequency
|
||||
$data['frequency'] = Settings::get('updatefrequency_chat');
|
||||
// Set refresh frequency
|
||||
$data['frequency'] = Settings::get('updatefrequency_chat');
|
||||
|
||||
// Load JavaScript plugins and JavaScripts, CSS files required by them
|
||||
$data = array_merge_recursive($data, get_plugins_data('client_chat_window'));
|
||||
// Load JavaScript plugins and JavaScripts, CSS files required by them
|
||||
$data = array_merge_recursive($data, get_plugins_data('client_chat_window'));
|
||||
|
||||
// Create some empty arrays
|
||||
$data['invitation'] = array();
|
||||
// Create some empty arrays
|
||||
$data['invitation'] = array();
|
||||
|
||||
$data['invitation']['thread'] = array(
|
||||
'id' => $thread->id,
|
||||
'token' => $thread->lastToken
|
||||
);
|
||||
$data['invitation']['thread'] = array(
|
||||
'id' => $thread->id,
|
||||
'token' => $thread->lastToken,
|
||||
);
|
||||
|
||||
$data['invitation']['user'] = array(
|
||||
'name' => htmlspecialchars(topage($thread->userName)),
|
||||
'canChangeName' => false,
|
||||
'isAgent' => false
|
||||
);
|
||||
$data['invitation']['user'] = array(
|
||||
'name' => htmlspecialchars(to_page($thread->userName)),
|
||||
'canChangeName' => false,
|
||||
'isAgent' => false,
|
||||
);
|
||||
|
||||
$data['startFrom'] = 'invitation';
|
||||
$data['startFrom'] = 'invitation';
|
||||
|
||||
return $data;
|
||||
return $data;
|
||||
}
|
||||
|
||||
?>
|
@ -15,25 +15,29 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
function mibew_mail($toaddr, $reply_to, $subject, $body)
|
||||
function mibew_mail($to_addr, $reply_to, $subject, $body)
|
||||
{
|
||||
global $mibew_mailbox, $mail_encoding;
|
||||
global $mibew_mailbox, $mail_encoding;
|
||||
|
||||
$headers = "From: $mibew_mailbox\r\n"
|
||||
. "Reply-To: " . myiconv(MIBEW_ENCODING, $mail_encoding, $reply_to) . "\r\n"
|
||||
. "Content-Type: text/plain; charset=$mail_encoding\r\n"
|
||||
. 'X-Mailer: PHP/' . phpversion();
|
||||
$headers = "From: $mibew_mailbox\r\n"
|
||||
. "Reply-To: " . myiconv(MIBEW_ENCODING, $mail_encoding, $reply_to) . "\r\n"
|
||||
. "Content-Type: text/plain; charset=$mail_encoding\r\n"
|
||||
. 'X-Mailer: PHP/' . phpversion();
|
||||
|
||||
$real_subject = "=?" . $mail_encoding . "?B?" . base64_encode(myiconv(MIBEW_ENCODING, $mail_encoding, $subject)) . "?=";
|
||||
$real_subject = "=?" . $mail_encoding . "?B?"
|
||||
. base64_encode(myiconv(MIBEW_ENCODING, $mail_encoding, $subject)) . "?=";
|
||||
|
||||
$body = preg_replace("/\n/", "\r\n", $body);
|
||||
$body = preg_replace("/\n/", "\r\n", $body);
|
||||
|
||||
$old_from = ini_get('sendmail_from');
|
||||
@ini_set('sendmail_from', $mibew_mailbox);
|
||||
@mail($toaddr, $real_subject, wordwrap(myiconv(MIBEW_ENCODING, $mail_encoding, $body), 70), $headers);
|
||||
if (isset($old_from)) {
|
||||
@ini_set('sendmail_from', $old_from);
|
||||
}
|
||||
$old_from = ini_get('sendmail_from');
|
||||
@ini_set('sendmail_from', $mibew_mailbox);
|
||||
@mail(
|
||||
$to_addr,
|
||||
$real_subject,
|
||||
wordwrap(myiconv(MIBEW_ENCODING, $mail_encoding, $body), 70),
|
||||
$headers
|
||||
);
|
||||
if (isset($old_from)) {
|
||||
@ini_set('sendmail_from', $old_from);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
File diff suppressed because it is too large
Load Diff
@ -15,7 +15,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Builds list of operator settings tabs. The keys of the resulting array are
|
||||
* tabs titles and the values are tabs URLs.
|
||||
@ -24,19 +23,26 @@
|
||||
* @param int $active Number of the active tab. The count starts from 0.
|
||||
* @return array Tabs list
|
||||
*/
|
||||
function setup_operator_settings_tabs($operator_id, $active) {
|
||||
$tabs = array();
|
||||
function setup_operator_settings_tabs($operator_id, $active)
|
||||
{
|
||||
$tabs = array();
|
||||
|
||||
if ($operator_id) {
|
||||
$tabs = array(
|
||||
getlocal("page_agent.tab.main") => $active != 0 ? (MIBEW_WEB_ROOT . "/operator/operator.php?op=" . $operator_id) : "",
|
||||
getlocal("page_agent.tab.avatar") => $active != 1 ? (MIBEW_WEB_ROOT . "/operator/avatar.php?op=" . $operator_id) : "",
|
||||
getlocal("page_agent.tab.groups") => $active != 2 ? (MIBEW_WEB_ROOT . "/operator/opgroups.php?op=" . $operator_id) : "",
|
||||
getlocal("page_agent.tab.permissions") => $active != 3 ? (MIBEW_WEB_ROOT . "/operator/permissions.php?op=" . $operator_id) : ""
|
||||
);
|
||||
}
|
||||
if ($operator_id) {
|
||||
$tabs = array(
|
||||
getlocal("page_agent.tab.main") => ($active != 0
|
||||
? (MIBEW_WEB_ROOT . "/operator/operator.php?op=" . $operator_id)
|
||||
: ""),
|
||||
getlocal("page_agent.tab.avatar") => ($active != 1
|
||||
? (MIBEW_WEB_ROOT . "/operator/avatar.php?op=" . $operator_id)
|
||||
: ""),
|
||||
getlocal("page_agent.tab.groups") => ($active != 2
|
||||
? (MIBEW_WEB_ROOT . "/operator/opgroups.php?op=" . $operator_id)
|
||||
: ""),
|
||||
getlocal("page_agent.tab.permissions") => ($active != 3
|
||||
? (MIBEW_WEB_ROOT . "/operator/permissions.php?op=" . $operator_id)
|
||||
: ""),
|
||||
);
|
||||
}
|
||||
|
||||
return $tabs;
|
||||
return $tabs;
|
||||
}
|
||||
|
||||
?>
|
@ -32,11 +32,13 @@ define('PAGINATION_LINKS_ON_PAGE', 5);
|
||||
* @param string $title Link title
|
||||
* @return string HTML markup
|
||||
*/
|
||||
function generate_pagination_link($page, $title) {
|
||||
$lnk = $_SERVER['REQUEST_URI'];
|
||||
$href = preg_replace("/\?page=\d+\&/", "?", preg_replace("/\&page=\d+/", "", $lnk));
|
||||
$href .= strstr($href, "?") ? "&page=$page" : "?page=$page";
|
||||
return "<a href=\"" . htmlspecialchars($href) . "\" class=\"pagelink\">$title</a>";
|
||||
function generate_pagination_link($page, $title)
|
||||
{
|
||||
$lnk = $_SERVER['REQUEST_URI'];
|
||||
$href = preg_replace("/\?page=\d+\&/", "?", preg_replace("/\&page=\d+/", "", $lnk));
|
||||
$href .= strstr($href, "?") ? "&page=$page" : "?page=$page";
|
||||
|
||||
return "<a href=\"" . htmlspecialchars($href) . "\" class=\"pagelink\">$title</a>";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -47,8 +49,9 @@ function generate_pagination_link($page, $title) {
|
||||
* @param string $alt Value of an 'alt' atribute of the image tag.
|
||||
* @return string HTML markup
|
||||
*/
|
||||
function generate_pagination_image($style_path, $id, $alt) {
|
||||
return "<img src=\"" . $style_path . "/images/$id.gif\" border=\"0\" alt=\"" . htmlspecialchars($alt) . "\"/>";
|
||||
function generate_pagination_image($style_path, $id, $alt)
|
||||
{
|
||||
return "<img src=\"" . $style_path . "/images/$id.gif\" border=\"0\" alt=\"" . htmlspecialchars($alt) . "\"/>";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -65,37 +68,38 @@ function generate_pagination_image($style_path, $id, $alt) {
|
||||
* - start: int, index of item to start from.
|
||||
* - end: int, index of item to end at.
|
||||
*/
|
||||
function pagination_info($items_count, $default_items_per_page = 15) {
|
||||
if ($items_count) {
|
||||
$items_per_page = verifyparam("items", "/^\d{1,3}$/", $default_items_per_page);
|
||||
if ($items_per_page < 2) {
|
||||
$items_per_page = 2;
|
||||
}
|
||||
function pagination_info($items_count, $default_items_per_page = 15)
|
||||
{
|
||||
if ($items_count) {
|
||||
$items_per_page = verify_param("items", "/^\d{1,3}$/", $default_items_per_page);
|
||||
if ($items_per_page < 2) {
|
||||
$items_per_page = 2;
|
||||
}
|
||||
|
||||
$total_pages = div($items_count + $items_per_page - 1, $items_per_page);
|
||||
$curr_page = verifyparam("page", "/^\d{1,6}$/", 1);
|
||||
$total_pages = div($items_count + $items_per_page - 1, $items_per_page);
|
||||
$curr_page = verify_param("page", "/^\d{1,6}$/", 1);
|
||||
|
||||
if ($curr_page < 1) {
|
||||
$curr_page = 1;
|
||||
}
|
||||
if ($curr_page > $total_pages) {
|
||||
$curr_page = $total_pages;
|
||||
}
|
||||
if ($curr_page < 1) {
|
||||
$curr_page = 1;
|
||||
}
|
||||
if ($curr_page > $total_pages) {
|
||||
$curr_page = $total_pages;
|
||||
}
|
||||
|
||||
$start_index = ($curr_page - 1) * $items_per_page;
|
||||
$end_index = min($start_index + $items_per_page, $items_count);
|
||||
$start_index = ($curr_page - 1) * $items_per_page;
|
||||
$end_index = min($start_index + $items_per_page, $items_count);
|
||||
|
||||
return array(
|
||||
"page" => $curr_page,
|
||||
"items" => $items_per_page,
|
||||
"total" => $total_pages,
|
||||
"count" => $items_count,
|
||||
"start" => $start_index,
|
||||
"end" => $end_index,
|
||||
);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return array(
|
||||
"page" => $curr_page,
|
||||
"items" => $items_per_page,
|
||||
"total" => $total_pages,
|
||||
"count" => $items_count,
|
||||
"start" => $start_index,
|
||||
"end" => $end_index,
|
||||
);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -108,26 +112,28 @@ function pagination_info($items_count, $default_items_per_page = 15) {
|
||||
* pagination_info function for details.
|
||||
* - items: slice of items to display.
|
||||
*/
|
||||
function setup_pagination($items, $default_items_per_page = 15) {
|
||||
if (count($items) > 0) {
|
||||
$info = pagination_info(count($items), $default_items_per_page);
|
||||
if ($info) {
|
||||
$items_slice = array_slice(
|
||||
$items,
|
||||
$info['start'],
|
||||
$info['end'] - $info['start']
|
||||
);
|
||||
return array(
|
||||
'info' => $info,
|
||||
'items' => $items_slice,
|
||||
);
|
||||
}
|
||||
}
|
||||
function setup_pagination($items, $default_items_per_page = 15)
|
||||
{
|
||||
if (count($items) > 0) {
|
||||
$info = pagination_info(count($items), $default_items_per_page);
|
||||
if ($info) {
|
||||
$items_slice = array_slice(
|
||||
$items,
|
||||
$info['start'],
|
||||
$info['end'] - $info['start']
|
||||
);
|
||||
|
||||
return array(
|
||||
'info' => false,
|
||||
'items' => false,
|
||||
);
|
||||
return array(
|
||||
'info' => $info,
|
||||
'items' => $items_slice,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
'info' => false,
|
||||
'items' => false,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -140,64 +146,66 @@ function setup_pagination($items, $default_items_per_page = 15) {
|
||||
* page.
|
||||
* @return string HTML markup
|
||||
*/
|
||||
function generate_pagination($style_path, $pagination, $bottom = true) {
|
||||
$result = getlocal2(
|
||||
"tag.pagination.info",
|
||||
array(
|
||||
$pagination['page'],
|
||||
$pagination['total'],
|
||||
$pagination['start'] + 1,
|
||||
$pagination['end'],
|
||||
$pagination['count']
|
||||
)
|
||||
) . "<br/>";
|
||||
function generate_pagination($style_path, $pagination, $bottom = true)
|
||||
{
|
||||
$result = getlocal2(
|
||||
"tag.pagination.info",
|
||||
array(
|
||||
$pagination['page'],
|
||||
$pagination['total'],
|
||||
$pagination['start'] + 1,
|
||||
$pagination['end'],
|
||||
$pagination['count'],
|
||||
)
|
||||
) . "<br/>";
|
||||
|
||||
if ($pagination['total'] > 1) {
|
||||
if (!$bottom) {
|
||||
$result = "";
|
||||
} else {
|
||||
$result .= "<br/>";
|
||||
}
|
||||
$result .= "<div class='pagination'>";
|
||||
$curr_page = $pagination['page'];
|
||||
if ($pagination['total'] > 1) {
|
||||
if (!$bottom) {
|
||||
$result = "";
|
||||
} else {
|
||||
$result .= "<br/>";
|
||||
}
|
||||
$result .= "<div class='pagination'>";
|
||||
$curr_page = $pagination['page'];
|
||||
|
||||
$minPage = max($curr_page - PAGINATION_LINKS_ON_PAGE, 1);
|
||||
$maxPage = min($curr_page + PAGINATION_LINKS_ON_PAGE, $pagination['total']);
|
||||
$min_page = max($curr_page - PAGINATION_LINKS_ON_PAGE, 1);
|
||||
$max_page = min($curr_page + PAGINATION_LINKS_ON_PAGE, $pagination['total']);
|
||||
|
||||
if ($curr_page > 1) {
|
||||
$result .= generate_pagination_link(
|
||||
$curr_page - 1,
|
||||
generate_pagination_image(
|
||||
$style_path,
|
||||
"prevpage",
|
||||
getlocal("tag.pagination.previous")
|
||||
)
|
||||
) . PAGINATION_SPACING;
|
||||
}
|
||||
if ($curr_page > 1) {
|
||||
$result .= generate_pagination_link(
|
||||
$curr_page - 1,
|
||||
generate_pagination_image(
|
||||
$style_path,
|
||||
"prevpage",
|
||||
getlocal("tag.pagination.previous")
|
||||
)
|
||||
) . PAGINATION_SPACING;
|
||||
}
|
||||
|
||||
for ($i = $minPage; $i <= $maxPage; $i++) {
|
||||
$title = abs($curr_page - $i) >= PAGINATION_LINKS_ON_PAGE && $i != 1 ? "..." : $i;
|
||||
if ($i != $curr_page)
|
||||
$result .= generate_pagination_link($i, $title);
|
||||
else
|
||||
$result .= "<span class=\"pagecurrent\">$title</span>";
|
||||
if ($i < $maxPage)
|
||||
$result .= PAGINATION_SPACING;
|
||||
}
|
||||
for ($i = $min_page; $i <= $max_page; $i++) {
|
||||
$title = (abs($curr_page - $i) >= PAGINATION_LINKS_ON_PAGE && $i != 1) ? "..." : $i;
|
||||
if ($i != $curr_page) {
|
||||
$result .= generate_pagination_link($i, $title);
|
||||
} else {
|
||||
$result .= "<span class=\"pagecurrent\">$title</span>";
|
||||
}
|
||||
if ($i < $max_page) {
|
||||
$result .= PAGINATION_SPACING;
|
||||
}
|
||||
}
|
||||
|
||||
if ($curr_page < $pagination['total']) {
|
||||
$result .= PAGINATION_SPACING . generate_pagination_link(
|
||||
$curr_page + 1,
|
||||
generate_pagination_image(
|
||||
$style_path,
|
||||
"nextpage",
|
||||
getlocal("tag.pagination.next")
|
||||
)
|
||||
);
|
||||
}
|
||||
$result .= "</div>";
|
||||
}
|
||||
return $result;
|
||||
if ($curr_page < $pagination['total']) {
|
||||
$result .= PAGINATION_SPACING . generate_pagination_link(
|
||||
$curr_page + 1,
|
||||
generate_pagination_image(
|
||||
$style_path,
|
||||
"nextpage",
|
||||
getlocal("tag.pagination.next")
|
||||
)
|
||||
);
|
||||
}
|
||||
$result .= "</div>";
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
?>
|
@ -25,20 +25,31 @@ use Mibew\Settings;
|
||||
* @param int $active Number of the active tab. The count starts from 0.
|
||||
* @return array Tabs list
|
||||
*/
|
||||
function setup_settings_tabs($active) {
|
||||
$tabs = array(
|
||||
getlocal("page_settings.tab.main") => $active != 0 ? (MIBEW_WEB_ROOT . "/operator/settings.php") : "",
|
||||
getlocal("page_settings.tab.features") => $active != 1 ? (MIBEW_WEB_ROOT . "/operator/features.php") : "",
|
||||
getlocal("page_settings.tab.performance") => $active != 2 ? (MIBEW_WEB_ROOT . "/operator/performance.php") : "",
|
||||
getlocal("page_settings.tab.page_themes") => $active != 3 ? (MIBEW_WEB_ROOT . "/operator/page_themes.php") : "",
|
||||
getlocal("page_settings.tab.themes") => $active != 4 ? (MIBEW_WEB_ROOT . "/operator/themes.php") : "",
|
||||
);
|
||||
function setup_settings_tabs($active)
|
||||
{
|
||||
$tabs = array(
|
||||
getlocal("page_settings.tab.main") => ($active != 0
|
||||
? (MIBEW_WEB_ROOT . "/operator/settings.php")
|
||||
: ""),
|
||||
getlocal("page_settings.tab.features") => ($active != 1
|
||||
? (MIBEW_WEB_ROOT . "/operator/features.php")
|
||||
: ""),
|
||||
getlocal("page_settings.tab.performance") => ($active != 2
|
||||
? (MIBEW_WEB_ROOT . "/operator/performance.php")
|
||||
: ""),
|
||||
getlocal("page_settings.tab.page_themes") => ($active != 3
|
||||
? (MIBEW_WEB_ROOT . "/operator/page_themes.php")
|
||||
: ""),
|
||||
getlocal("page_settings.tab.themes") => ($active != 4
|
||||
? (MIBEW_WEB_ROOT . "/operator/themes.php")
|
||||
: ""),
|
||||
);
|
||||
|
||||
if (Settings::get('enabletracking')) {
|
||||
$tabs[getlocal("page_settings.tab.invitationthemes")] = ($active != 5 ? (MIBEW_WEB_ROOT . "/operator/invitationthemes.php") : "");
|
||||
}
|
||||
if (Settings::get('enabletracking')) {
|
||||
$tabs[getlocal("page_settings.tab.invitationthemes")] = ($active != 5
|
||||
? (MIBEW_WEB_ROOT . "/operator/invitationthemes.php")
|
||||
: "");
|
||||
}
|
||||
|
||||
return $tabs;
|
||||
return $tabs;
|
||||
}
|
||||
|
||||
?>
|
File diff suppressed because it is too large
Load Diff
@ -20,75 +20,78 @@ use Mibew\Database;
|
||||
use Mibew\Settings;
|
||||
use Mibew\Thread;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(MIBEW_FS_ROOT.'/libs/chat.php');
|
||||
|
||||
function track_visitor($visitorid, $entry, $referer)
|
||||
function track_visitor($visitor_id, $entry, $referer)
|
||||
{
|
||||
$visitor = track_get_visitor_by_id($visitorid);
|
||||
$visitor = track_get_visitor_by_id($visitor_id);
|
||||
|
||||
if (FALSE === $visitor) {
|
||||
$visitor = track_visitor_start($entry, $referer);
|
||||
return $visitor;
|
||||
} else {
|
||||
$db = Database::getInstance();
|
||||
$db->query(
|
||||
"update {chatsitevisitor} set lasttime = :now " .
|
||||
"where visitorid = :visitorid",
|
||||
array(
|
||||
':visitorid' => $visitor['visitorid'],
|
||||
':now' => time()
|
||||
)
|
||||
);
|
||||
track_visit_page($visitor['visitorid'], $referer);
|
||||
return $visitor['visitorid'];
|
||||
}
|
||||
if (false === $visitor) {
|
||||
$visitor = track_visitor_start($entry, $referer);
|
||||
|
||||
return $visitor;
|
||||
} else {
|
||||
$db = Database::getInstance();
|
||||
$db->query(
|
||||
"UPDATE {chatsitevisitor} SET lasttime = :now WHERE visitorid = :visitorid",
|
||||
array(
|
||||
':visitorid' => $visitor['visitorid'],
|
||||
':now' => time(),
|
||||
)
|
||||
);
|
||||
track_visit_page($visitor['visitorid'], $referer);
|
||||
|
||||
return $visitor['visitorid'];
|
||||
}
|
||||
}
|
||||
|
||||
function track_visitor_start($entry, $referer)
|
||||
{
|
||||
$visitor = visitor_from_request();
|
||||
$visitor = visitor_from_request();
|
||||
|
||||
$db = Database::getInstance();
|
||||
$db->query(
|
||||
"insert into {chatsitevisitor} (userid,username,firsttime,lasttime,entry,details) ".
|
||||
"values (:userid, :username, :now, :now, :entry, :details)",
|
||||
array(
|
||||
':userid' => $visitor['id'],
|
||||
':username' => $visitor['name'],
|
||||
':now' => time(),
|
||||
':entry' => $entry,
|
||||
':details' => track_build_details()
|
||||
)
|
||||
);
|
||||
$db = Database::getInstance();
|
||||
$db->query(
|
||||
("INSERT INTO {chatsitevisitor} ( "
|
||||
. "userid, username, firsttime, lasttime, entry,details "
|
||||
. ") VALUES ( "
|
||||
. ":userid, :username, :now, :now, :entry, :details "
|
||||
. ")"),
|
||||
array(
|
||||
':userid' => $visitor['id'],
|
||||
':username' => $visitor['name'],
|
||||
':now' => time(),
|
||||
':entry' => $entry,
|
||||
':details' => track_build_details(),
|
||||
)
|
||||
);
|
||||
|
||||
$id = $db->insertedId();
|
||||
$id = $db->insertedId();
|
||||
|
||||
if ($id) {
|
||||
track_visit_page($id, $referer);
|
||||
}
|
||||
if ($id) {
|
||||
track_visit_page($id, $referer);
|
||||
}
|
||||
|
||||
return $id ? $id : 0;
|
||||
return $id ? $id : 0;
|
||||
}
|
||||
|
||||
function track_get_visitor_by_id($visitorid)
|
||||
function track_get_visitor_by_id($visitor_id)
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
return $db->query(
|
||||
"select * from {chatsitevisitor} where visitorid = ?",
|
||||
array($visitorid),
|
||||
array('return_rows' => Database::RETURN_ONE_ROW)
|
||||
);
|
||||
$db = Database::getInstance();
|
||||
|
||||
return $db->query(
|
||||
"SELECT * FROM {chatsitevisitor} WHERE visitorid = ?",
|
||||
array($visitor_id),
|
||||
array('return_rows' => Database::RETURN_ONE_ROW)
|
||||
);
|
||||
}
|
||||
|
||||
function track_get_visitor_by_threadid($threadid)
|
||||
function track_get_visitor_by_thread_id($thread_id)
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
return $db->query(
|
||||
"select * from {chatsitevisitor} where threadid = ?",
|
||||
array($threadid),
|
||||
array('return_rows' => Database::RETURN_ONE_ROW)
|
||||
);
|
||||
$db = Database::getInstance();
|
||||
|
||||
return $db->query(
|
||||
"SELECT * FROM {chatsitevisitor} WHERE threadid = ?",
|
||||
array($thread_id),
|
||||
array('return_rows' => Database::RETURN_ONE_ROW)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -97,66 +100,73 @@ function track_get_visitor_by_threadid($threadid)
|
||||
* @param string $user_id User id
|
||||
* @return boolean|array Visitor array or boolean false if visitor not exists
|
||||
*/
|
||||
function track_get_visitor_by_user_id($user_id) {
|
||||
$db = Database::getInstance();
|
||||
return $db->query(
|
||||
"select * from {chatsitevisitor} where userid = ?",
|
||||
array($user_id),
|
||||
array('return_rows' => Database::RETURN_ONE_ROW)
|
||||
);
|
||||
function track_get_visitor_by_user_id($user_id)
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
|
||||
return $db->query(
|
||||
"SELECT * FROM {chatsitevisitor} WHERE userid = ?",
|
||||
array($user_id),
|
||||
array('return_rows' => Database::RETURN_ONE_ROW)
|
||||
);
|
||||
}
|
||||
|
||||
function track_visit_page($visitorid, $page)
|
||||
function track_visit_page($visitor_id, $page)
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$db = Database::getInstance();
|
||||
|
||||
if (empty($page)) {
|
||||
return;
|
||||
}
|
||||
$lastpage = $db->query(
|
||||
"select address from {visitedpage} where visitorid = ? " .
|
||||
"order by visittime desc limit 1",
|
||||
array($visitorid),
|
||||
array('return_rows' => Database::RETURN_ONE_ROW)
|
||||
);
|
||||
if ( $lastpage['address'] != $page ) {
|
||||
$db->query(
|
||||
"insert into {visitedpage} (visitorid, address, visittime) " .
|
||||
"values (:visitorid, :page, :now)",
|
||||
array(
|
||||
':visitorid' => $visitorid,
|
||||
':page' => $page,
|
||||
':now' => time()
|
||||
)
|
||||
);
|
||||
}
|
||||
if (empty($page)) {
|
||||
return;
|
||||
}
|
||||
$last_page = $db->query(
|
||||
("SELECT address "
|
||||
. "FROM {visitedpage} "
|
||||
. "WHERE visitorid = ? "
|
||||
. "ORDER BY visittime DESC "
|
||||
. "LIMIT 1"),
|
||||
array($visitor_id),
|
||||
array('return_rows' => Database::RETURN_ONE_ROW)
|
||||
);
|
||||
if ($last_page['address'] != $page) {
|
||||
$db->query(
|
||||
("INSERT INTO {visitedpage} ("
|
||||
. "visitorid, address, visittime "
|
||||
. ") VALUES ( "
|
||||
. ":visitorid, :page, :now "
|
||||
.")"),
|
||||
array(
|
||||
':visitorid' => $visitor_id,
|
||||
':page' => $page,
|
||||
':now' => time(),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function track_get_path($visitor)
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$query_result = $db->query(
|
||||
"select address, visittime from {visitedpage} " .
|
||||
"where visitorid = ?",
|
||||
array($visitor['visitorid']),
|
||||
array('return_rows' => Database::RETURN_ALL_ROWS)
|
||||
);
|
||||
$result = array();
|
||||
foreach ($query_result as $page) {
|
||||
$result[$page['visittime']] = $page['address'];
|
||||
}
|
||||
return $result;
|
||||
$db = Database::getInstance();
|
||||
$query_result = $db->query(
|
||||
"SELECT address, visittime FROM {visitedpage} WHERE visitorid = ?",
|
||||
array($visitor['visitorid']),
|
||||
array('return_rows' => Database::RETURN_ALL_ROWS)
|
||||
);
|
||||
$result = array();
|
||||
foreach ($query_result as $page) {
|
||||
$result[$page['visittime']] = $page['address'];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function track_build_details()
|
||||
{
|
||||
$result = array(
|
||||
'user_agent' => $_SERVER['HTTP_USER_AGENT'],
|
||||
'remote_host' => get_remote_host()
|
||||
'user_agent' => $_SERVER['HTTP_USER_AGENT'],
|
||||
'remote_host' => get_remote_host(),
|
||||
);
|
||||
|
||||
return serialize($result);
|
||||
|
||||
}
|
||||
|
||||
function track_retrieve_details($visitor)
|
||||
@ -167,64 +177,68 @@ function track_retrieve_details($visitor)
|
||||
/**
|
||||
* Remove old visitors
|
||||
*/
|
||||
function track_remove_old_visitors() {
|
||||
$db = Database::getInstance();
|
||||
function track_remove_old_visitors()
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
|
||||
// Remove associations of visitors with closed threads
|
||||
$db->query(
|
||||
"UPDATE {chatsitevisitor} SET threadid = NULL " .
|
||||
"WHERE threadid IS NOT NULL AND " .
|
||||
" (SELECT count(*) FROM {chatthread} " .
|
||||
"WHERE threadid = {chatsitevisitor}.threadid" .
|
||||
" AND istate <> " . Thread::STATE_CLOSED . " " .
|
||||
" AND istate <> " . Thread::STATE_LEFT . ") = 0"
|
||||
);
|
||||
// Remove associations of visitors with closed threads
|
||||
$db->query(
|
||||
"UPDATE {chatsitevisitor} SET threadid = NULL "
|
||||
. "WHERE threadid IS NOT NULL AND "
|
||||
. "(SELECT count(*) FROM {chatthread} "
|
||||
. "WHERE threadid = {chatsitevisitor}.threadid "
|
||||
. "AND istate <> " . Thread::STATE_CLOSED . " "
|
||||
. "AND istate <> " . Thread::STATE_LEFT . ") = 0 "
|
||||
);
|
||||
|
||||
// Remove old visitors
|
||||
$db->query(
|
||||
"DELETE FROM {chatsitevisitor} " .
|
||||
"WHERE (:now - lasttime) > :lifetime ".
|
||||
"AND threadid IS NULL",
|
||||
array(
|
||||
':lifetime' => Settings::get('tracking_lifetime'),
|
||||
':now' => time()
|
||||
)
|
||||
);
|
||||
// Remove old visitors
|
||||
$db->query(
|
||||
("DELETE FROM {chatsitevisitor} "
|
||||
. "WHERE (:now - lasttime) > :lifetime "
|
||||
. "AND threadid IS NULL"),
|
||||
array(
|
||||
':lifetime' => Settings::get('tracking_lifetime'),
|
||||
':now' => time(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove old tracks
|
||||
*/
|
||||
function track_remove_old_tracks() {
|
||||
$db = Database::getInstance();
|
||||
function track_remove_old_tracks()
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
|
||||
// Remove old visitors' tracks
|
||||
$db->query(
|
||||
"DELETE FROM {visitedpage} " .
|
||||
"WHERE (:now - visittime) > :lifetime " .
|
||||
// Remove only tracks that are included in statistics
|
||||
"AND calculated = 1 " .
|
||||
"AND visitorid NOT IN (SELECT visitorid FROM {chatsitevisitor}) ",
|
||||
array(
|
||||
':lifetime' => Settings::get('tracking_lifetime'),
|
||||
':now' => time()
|
||||
)
|
||||
);
|
||||
// Remove old visitors' tracks
|
||||
$db->query(
|
||||
("DELETE FROM {visitedpage} "
|
||||
. "WHERE (:now - visittime) > :lifetime "
|
||||
// Remove only tracks that are included in statistics
|
||||
. "AND calculated = 1 "
|
||||
. "AND visitorid NOT IN (SELECT visitorid FROM {chatsitevisitor}) "),
|
||||
array(
|
||||
':lifetime' => Settings::get('tracking_lifetime'),
|
||||
':now' => time(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return user id by visitor id.
|
||||
*
|
||||
* @param int $visitorid Id of the visitor
|
||||
* @param int $visitor_id Id of the visitor
|
||||
* @return string|boolean user id or boolean false if there is no visitor with
|
||||
* specified visitor id
|
||||
*/
|
||||
function track_get_user_id($visitorid) {
|
||||
$visitor = track_get_visitor_by_id($visitorid);
|
||||
if (! $visitor) {
|
||||
return false;
|
||||
}
|
||||
return $visitor['userid'];
|
||||
function track_get_user_id($visitor_id)
|
||||
{
|
||||
$visitor = track_get_visitor_by_id($visitor_id);
|
||||
if (!$visitor) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $visitor['userid'];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -234,17 +248,16 @@ function track_get_user_id($visitorid) {
|
||||
* visitor.
|
||||
* @param Thread $thread Chat thread object
|
||||
*/
|
||||
function track_visitor_bind_thread($user_id, $thread) {
|
||||
$db = Database::getInstance();
|
||||
$db->query(
|
||||
'UPDATE {chatsitevisitor} ' .
|
||||
'SET threadid = :thread_id ' .
|
||||
'WHERE userid = :user_id',
|
||||
array(
|
||||
':thread_id' => $thread->id,
|
||||
':user_id' => $user_id
|
||||
)
|
||||
);
|
||||
function track_visitor_bind_thread($user_id, $thread)
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$db->query(
|
||||
('UPDATE {chatsitevisitor} '
|
||||
. 'SET threadid = :thread_id '
|
||||
. 'WHERE userid = :user_id'),
|
||||
array(
|
||||
':thread_id' => $thread->id,
|
||||
':user_id' => $user_id,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
?>
|
@ -18,50 +18,50 @@
|
||||
// Import namespaces and classes of the core
|
||||
use Mibew\Settings;
|
||||
|
||||
function get_useragent_version($userAgent)
|
||||
function get_user_agent_version($user_agent)
|
||||
{
|
||||
$known_agents = get_known_user_agents();
|
||||
if (is_array($known_agents)) {
|
||||
$userAgent = strtolower($userAgent);
|
||||
foreach ($known_agents as $agent) {
|
||||
if (strstr($userAgent, $agent)) {
|
||||
if (preg_match("/" . $agent . "[\\s\/]?(\\d+(\\.\\d+(\\.\\d+(\\.\\d+)?)?)?)/", $userAgent, $matches)) {
|
||||
$ver = $matches[1];
|
||||
if ($agent == 'safari') {
|
||||
if (preg_match("/version\/(\\d+(\\.\\d+(\\.\\d+)?)?)/", $userAgent, $matches)) {
|
||||
$ver = $matches[1];
|
||||
} else {
|
||||
$ver = "1 or 2 (build " . $ver . ")";
|
||||
}
|
||||
if (preg_match("/mobile\/(\\d+(\\.\\d+(\\.\\d+)?)?)/", $userAgent, $matches)) {
|
||||
$userAgent = "iPhone " . $matches[1] . " ($agent $ver)";
|
||||
break;
|
||||
}
|
||||
}
|
||||
$known_agents = get_known_user_agents();
|
||||
if (is_array($known_agents)) {
|
||||
$user_agent = strtolower($user_agent);
|
||||
foreach ($known_agents as $agent) {
|
||||
if (strstr($user_agent, $agent)) {
|
||||
if (preg_match("/" . $agent . "[\\s\/]?(\\d+(\\.\\d+(\\.\\d+(\\.\\d+)?)?)?)/", $user_agent, $matches)) {
|
||||
$ver = $matches[1];
|
||||
if ($agent == 'safari') {
|
||||
if (preg_match("/version\/(\\d+(\\.\\d+(\\.\\d+)?)?)/", $user_agent, $matches)) {
|
||||
$ver = $matches[1];
|
||||
} else {
|
||||
$ver = "1 or 2 (build " . $ver . ")";
|
||||
}
|
||||
if (preg_match("/mobile\/(\\d+(\\.\\d+(\\.\\d+)?)?)/", $user_agent, $matches)) {
|
||||
$user_agent = "iPhone " . $matches[1] . " ($agent $ver)";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$userAgent = ucfirst($agent) . " " . $ver;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $userAgent;
|
||||
$user_agent = ucfirst($agent) . " " . $ver;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $user_agent;
|
||||
}
|
||||
|
||||
function get_user_addr($addr)
|
||||
{
|
||||
if (Settings::get('geolink') && preg_match("/(\\d+\\.\\d+\\.\\d+\\.\\d+)/", $addr, $matches)) {
|
||||
$userip = $matches[1];
|
||||
return get_popup(
|
||||
str_replace("{ip}", $userip, Settings::get('geolink')),
|
||||
'',
|
||||
htmlspecialchars($addr),
|
||||
"GeoLocation",
|
||||
"ip$userip",
|
||||
Settings::get('geolinkparams')
|
||||
);
|
||||
}
|
||||
return htmlspecialchars($addr);
|
||||
}
|
||||
if (Settings::get('geolink') && preg_match("/(\\d+\\.\\d+\\.\\d+\\.\\d+)/", $addr, $matches)) {
|
||||
$user_ip = $matches[1];
|
||||
return get_popup(
|
||||
str_replace("{ip}", $user_ip, Settings::get('geolink')),
|
||||
'',
|
||||
htmlspecialchars($addr),
|
||||
"GeoLocation",
|
||||
"ip$user_ip",
|
||||
Settings::get('geolinkparams')
|
||||
);
|
||||
}
|
||||
|
||||
?>
|
||||
return htmlspecialchars($addr);
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
use Mibew\Style\PageStyle;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(dirname(__FILE__).'/libs/init.php');
|
||||
require_once(dirname(__FILE__) . '/libs/init.php');
|
||||
|
||||
$page = array();
|
||||
$page['title'] = getlocal("license.title");
|
||||
@ -28,5 +28,3 @@ $page['fixedwrap'] = true;
|
||||
|
||||
$page_style = new PageStyle(PageStyle::currentStyle());
|
||||
$page_style->render('license', $page);
|
||||
|
||||
?>
|
@ -21,68 +21,68 @@ use Mibew\Thread;
|
||||
use Mibew\Style\ChatStyle;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(dirname(__FILE__).'/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/chat.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/groups.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/notify.php');
|
||||
require_once(dirname(__FILE__) . '/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/chat.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/groups.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/notify.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/track.php');
|
||||
|
||||
$page = array(
|
||||
'errors' =>array()
|
||||
'errors' => array(),
|
||||
);
|
||||
|
||||
$token = verifyparam( "token", "/^\d{1,8}$/");
|
||||
$threadid = verifyparam( "thread", "/^\d{1,8}$/");
|
||||
$token = verify_param("token", "/^\d{1,8}$/");
|
||||
$thread_id = verify_param("thread", "/^\d{1,8}$/");
|
||||
|
||||
$thread = Thread::load($threadid, $token);
|
||||
if (! $thread) {
|
||||
die("wrong thread");
|
||||
$thread = Thread::load($thread_id, $token);
|
||||
if (!$thread) {
|
||||
die("wrong thread");
|
||||
}
|
||||
|
||||
// Initialize chat style which is currently used in system
|
||||
$chat_style = new ChatStyle(ChatStyle::currentStyle());
|
||||
|
||||
$email = getparam('email');
|
||||
$email = get_param('email');
|
||||
$page['email'] = $email;
|
||||
$group = is_null($thread->groupId)?NULL:group_by_id($thread->groupId);
|
||||
if( !$email ) {
|
||||
$page['errors'][] = no_field("form.field.email");
|
||||
} else if( !is_valid_email($email)) {
|
||||
$page['errors'][] = wrong_field("form.field.email");
|
||||
$group = is_null($thread->groupId) ? null : group_by_id($thread->groupId);
|
||||
if (!$email) {
|
||||
$page['errors'][] = no_field("form.field.email");
|
||||
} elseif (!is_valid_email($email)) {
|
||||
$page['errors'][] = wrong_field("form.field.email");
|
||||
}
|
||||
|
||||
if( count($page['errors']) > 0 ) {
|
||||
$page['formemail'] = $email;
|
||||
$page['chat.thread.id'] = $thread->id;
|
||||
$page['chat.thread.token'] = $thread->lastToken;
|
||||
$page['level'] = "";
|
||||
$page = array_merge_recursive(
|
||||
$page,
|
||||
setup_logo($group)
|
||||
);
|
||||
$chat_style->render('mail', $page);
|
||||
exit;
|
||||
if (count($page['errors']) > 0) {
|
||||
$page['formemail'] = $email;
|
||||
$page['chat.thread.id'] = $thread->id;
|
||||
$page['chat.thread.token'] = $thread->lastToken;
|
||||
$page['level'] = "";
|
||||
$page = array_merge_recursive(
|
||||
$page,
|
||||
setup_logo($group)
|
||||
);
|
||||
$chat_style->render('mail', $page);
|
||||
exit;
|
||||
}
|
||||
|
||||
$history = "";
|
||||
$last_id = -1;
|
||||
$messages = $thread->getMessages(true, $last_id);
|
||||
foreach ($messages as $msg) {
|
||||
$history .= message_to_text($msg);
|
||||
$history .= message_to_text($msg);
|
||||
}
|
||||
|
||||
$subject = getstring("mail.user.history.subject");
|
||||
$body = getstring2(
|
||||
"mail.user.history.body",
|
||||
array($thread->userName, $history, Settings::get('title'), Settings::get('hosturl'))
|
||||
"mail.user.history.body",
|
||||
array($thread->userName,
|
||||
$history,
|
||||
Settings::get('title'),
|
||||
Settings::get('hosturl')
|
||||
)
|
||||
);
|
||||
|
||||
mibew_mail($email, $mibew_mailbox, $subject, $body);
|
||||
|
||||
$page = array_merge_recursive(
|
||||
$page,
|
||||
setup_logo($group)
|
||||
);
|
||||
$page = array_merge_recursive($page, setup_logo($group));
|
||||
|
||||
$chat_style->render('mailsent', $page);
|
||||
exit;
|
||||
?>
|
@ -22,30 +22,31 @@ use Mibew\Style\ChatStyle;
|
||||
use Mibew\Style\PageStyle;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(dirname(dirname(__FILE__)).'/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/canned.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/chat.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/groups.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/pagination.php');
|
||||
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/canned.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/chat.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/groups.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/pagination.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/track.php');
|
||||
|
||||
$operator = check_login();
|
||||
|
||||
if (Settings::get('enablessl') == "1" && Settings::get('forcessl') == "1") {
|
||||
if (!is_secure_request()) {
|
||||
$requested = $_SERVER['PHP_SELF'];
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'GET' && $_SERVER['QUERY_STRING']) {
|
||||
header("Location: " . get_app_location(true, true) . "/operator/agent.php?" . $_SERVER['QUERY_STRING']);
|
||||
} else {
|
||||
die("only https connections are handled");
|
||||
}
|
||||
exit;
|
||||
}
|
||||
if (!is_secure_request()) {
|
||||
$requested = $_SERVER['PHP_SELF'];
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'GET' && $_SERVER['QUERY_STRING']) {
|
||||
header("Location: " . get_app_location(true, true) . "/operator/agent.php?" . $_SERVER['QUERY_STRING']);
|
||||
} else {
|
||||
die("only https connections are handled");
|
||||
}
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$threadid = verifyparam("thread", "/^\d{1,8}$/");
|
||||
$thread_id = verify_param("thread", "/^\d{1,8}$/");
|
||||
$page = array(
|
||||
'errors' => array()
|
||||
'errors' => array(),
|
||||
);
|
||||
|
||||
// Initialize chat style which is currently used in system
|
||||
@ -55,92 +56,92 @@ $page_style = new PageStyle(PageStyle::currentStyle());
|
||||
|
||||
if (!isset($_GET['token'])) {
|
||||
|
||||
$remote_level = get_remote_level($_SERVER['HTTP_USER_AGENT']);
|
||||
if ($remote_level != "ajaxed") {
|
||||
$page['errors'][] = getlocal("thread.error.old_browser");
|
||||
$chat_style->render('error', $page);
|
||||
exit;
|
||||
}
|
||||
$remote_level = get_remote_level($_SERVER['HTTP_USER_AGENT']);
|
||||
if ($remote_level != "ajaxed") {
|
||||
$page['errors'][] = getlocal("thread.error.old_browser");
|
||||
$chat_style->render('error', $page);
|
||||
exit;
|
||||
}
|
||||
|
||||
$thread = Thread::load($threadid);
|
||||
if (!$thread || !isset($thread->lastToken)) {
|
||||
$page['errors'][] = getlocal("thread.error.wrong_thread");
|
||||
$chat_style->render('error', $page);
|
||||
exit;
|
||||
}
|
||||
$thread = Thread::load($thread_id);
|
||||
if (!$thread || !isset($thread->lastToken)) {
|
||||
$page['errors'][] = getlocal("thread.error.wrong_thread");
|
||||
$chat_style->render('error', $page);
|
||||
exit;
|
||||
}
|
||||
|
||||
$viewonly = verifyparam("viewonly", "/^true$/", false);
|
||||
$view_only = verify_param("viewonly", "/^true$/", false);
|
||||
|
||||
$forcetake = verifyparam("force", "/^true$/", false);
|
||||
if (!$viewonly && $thread->state == Thread::STATE_CHATTING && $operator['operatorid'] != $thread->agentId) {
|
||||
$force_take = verify_param("force", "/^true$/", false);
|
||||
if (!$view_only && $thread->state == Thread::STATE_CHATTING && $operator['operatorid'] != $thread->agentId) {
|
||||
|
||||
if (!is_capable(CAN_TAKEOVER, $operator)) {
|
||||
$page['errors'][] = getlocal("thread.error.cannot_take_over");
|
||||
$chat_style->render('error', $page);
|
||||
exit;
|
||||
}
|
||||
if (!is_capable(CAN_TAKEOVER, $operator)) {
|
||||
$page['errors'][] = getlocal("thread.error.cannot_take_over");
|
||||
$chat_style->render('error', $page);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($forcetake == false) {
|
||||
$page = array(
|
||||
'user' => topage($thread->userName),
|
||||
'agent' => topage($thread->agentName),
|
||||
'link' => $_SERVER['PHP_SELF'] . "?thread=$threadid&force=true",
|
||||
'title' => getlocal("confirm.take.head"),
|
||||
);
|
||||
$page_style->render('confirm', $page);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
if ($force_take == false) {
|
||||
$page = array(
|
||||
'user' => to_page($thread->userName),
|
||||
'agent' => to_page($thread->agentName),
|
||||
'link' => $_SERVER['PHP_SELF'] . "?thread=$thread_id&force=true",
|
||||
'title' => getlocal("confirm.take.head"),
|
||||
);
|
||||
$page_style->render('confirm', $page);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$viewonly) {
|
||||
if(! $thread->take($operator)){
|
||||
$page['errors'][] = getlocal("thread.error.cannot_take");
|
||||
$chat_style->render('error', $page);
|
||||
exit;
|
||||
}
|
||||
} else if (!is_capable(CAN_VIEWTHREADS, $operator)) {
|
||||
$page['errors'][] = getlocal("thread.error.cannot_view");
|
||||
$chat_style->render('error', $page);
|
||||
exit;
|
||||
}
|
||||
if (!$view_only) {
|
||||
if (!$thread->take($operator)) {
|
||||
$page['errors'][] = getlocal("thread.error.cannot_take");
|
||||
$chat_style->render('error', $page);
|
||||
exit;
|
||||
}
|
||||
} elseif (!is_capable(CAN_VIEWTHREADS, $operator)) {
|
||||
$page['errors'][] = getlocal("thread.error.cannot_view");
|
||||
$chat_style->render('error', $page);
|
||||
exit;
|
||||
}
|
||||
|
||||
$token = $thread->lastToken;
|
||||
header("Location: " . MIBEW_WEB_ROOT . "/operator/agent.php?thread=" . intval($threadid) . "&token=" . urlencode($token));
|
||||
exit;
|
||||
$token = $thread->lastToken;
|
||||
$redirect_to = MIBEW_WEB_ROOT . "/operator/agent.php?thread="
|
||||
. intval($thread_id) . "&token=" . urlencode($token);
|
||||
header("Location: " . $redirect_to);
|
||||
exit;
|
||||
}
|
||||
|
||||
$token = verifyparam("token", "/^\d{1,8}$/");
|
||||
$token = verify_param("token", "/^\d{1,8}$/");
|
||||
|
||||
$thread = Thread::load($threadid, $token);
|
||||
$thread = Thread::load($thread_id, $token);
|
||||
if (!$thread) {
|
||||
die("wrong thread");
|
||||
die("wrong thread");
|
||||
}
|
||||
|
||||
if ($thread->agentId != $operator['operatorid'] && !is_capable(CAN_VIEWTHREADS, $operator)) {
|
||||
$page['errors'][] = "Cannot view threads";
|
||||
$chat_style->render('error', $page);
|
||||
exit;
|
||||
$page['errors'][] = "Cannot view threads";
|
||||
$chat_style->render('error', $page);
|
||||
exit;
|
||||
}
|
||||
|
||||
$page = array_merge_recursive(
|
||||
$page,
|
||||
setup_chatview_for_operator($thread, $operator)
|
||||
$page,
|
||||
setup_chatview_for_operator($thread, $operator)
|
||||
);
|
||||
|
||||
start_html_output();
|
||||
|
||||
$pparam = verifyparam("act", "/^(redirect)$/", "default");
|
||||
$pparam = verify_param("act", "/^(redirect)$/", "default");
|
||||
if ($pparam == "redirect") {
|
||||
$page = array_merge_recursive(
|
||||
$page,
|
||||
setup_redirect_links($threadid, $operator, $token)
|
||||
);
|
||||
$chat_style->render('redirect', $page);
|
||||
$page = array_merge_recursive(
|
||||
$page,
|
||||
setup_redirect_links($thread_id, $operator, $token)
|
||||
);
|
||||
$chat_style->render('redirect', $page);
|
||||
} else {
|
||||
// Build js application options
|
||||
$page['chatOptions'] = json_encode($page['chat']);
|
||||
// Render the page
|
||||
$chat_style->render('chat', $page);
|
||||
// Build js application options
|
||||
$page['chatOptions'] = json_encode($page['chat']);
|
||||
// Render the page
|
||||
$chat_style->render('chat', $page);
|
||||
}
|
||||
|
||||
?>
|
@ -20,97 +20,89 @@ use Mibew\Settings;
|
||||
use Mibew\Style\PageStyle;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(dirname(dirname(__FILE__)).'/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/operator_settings.php');
|
||||
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/operator_settings.php');
|
||||
|
||||
$operator = check_login();
|
||||
csrfchecktoken();
|
||||
csrf_check_token();
|
||||
|
||||
$opId = verifyparam("op", "/^\d{1,9}$/");
|
||||
$op_id = verify_param("op", "/^\d{1,9}$/");
|
||||
$page = array(
|
||||
'opid' => $opId,
|
||||
'avatar' => '',
|
||||
'errors' => array(),
|
||||
'opid' => $op_id,
|
||||
'avatar' => '',
|
||||
'errors' => array(),
|
||||
);
|
||||
|
||||
$canmodify = ($opId == $operator['operatorid'] && is_capable(CAN_MODIFYPROFILE, $operator))
|
||||
|| is_capable(CAN_ADMINISTRATE, $operator);
|
||||
$can_modify = ($op_id == $operator['operatorid'] && is_capable(CAN_MODIFYPROFILE, $operator))
|
||||
|| is_capable(CAN_ADMINISTRATE, $operator);
|
||||
|
||||
$op = operator_by_id($opId);
|
||||
$op = operator_by_id($op_id);
|
||||
|
||||
if (!$op) {
|
||||
$page['errors'][] = getlocal("no_such_operator");
|
||||
$page['errors'][] = getlocal("no_such_operator");
|
||||
} elseif (isset($_POST['op'])) {
|
||||
$avatar = $op['vcavatar'];
|
||||
|
||||
} else if (isset($_POST['op'])) {
|
||||
$avatar = $op['vcavatar'];
|
||||
if (!$can_modify) {
|
||||
$page['errors'][] = getlocal('page_agent.cannot_modify');
|
||||
} elseif (isset($_FILES['avatarFile']) && $_FILES['avatarFile']['name']) {
|
||||
$valid_types = array("gif", "jpg", "png", "tif", "jpeg");
|
||||
|
||||
if (!$canmodify) {
|
||||
$page['errors'][] = getlocal('page_agent.cannot_modify');
|
||||
$orig_filename = $_FILES['avatarFile']['name'];
|
||||
$tmp_file_name = $_FILES['avatarFile']['tmp_name'];
|
||||
|
||||
} else if (isset($_FILES['avatarFile']) && $_FILES['avatarFile']['name']) {
|
||||
$valid_types = array("gif", "jpg", "png", "tif", "jpeg");
|
||||
$ext = preg_replace('/\//', '', strtolower(substr($orig_filename, 1 + strrpos($orig_filename, "."))));
|
||||
$new_file_name = intval($op_id) . ".$ext";
|
||||
|
||||
$orig_filename = $_FILES['avatarFile']['name'];
|
||||
$tmp_file_name = $_FILES['avatarFile']['tmp_name'];
|
||||
$file_size = $_FILES['avatarFile']['size'];
|
||||
if ($file_size == 0 || $file_size > Settings::get('max_uploaded_file_size')) {
|
||||
$page['errors'][] = failed_uploading_file($orig_filename, "errors.file.size.exceeded");
|
||||
} elseif (!in_array($ext, $valid_types)) {
|
||||
$page['errors'][] = failed_uploading_file($orig_filename, "errors.invalid.file.type");
|
||||
} else {
|
||||
$avatar_local_dir = MIBEW_FS_ROOT . '/files/avatar/';
|
||||
$full_file_path = $avatar_local_dir . $new_file_name;
|
||||
if (file_exists($full_file_path)) {
|
||||
unlink($full_file_path);
|
||||
}
|
||||
if (!@move_uploaded_file($_FILES['avatarFile']['tmp_name'], $full_file_path)) {
|
||||
$page['errors'][] = failed_uploading_file($orig_filename, "errors.file.move.error");
|
||||
} else {
|
||||
$avatar = MIBEW_WEB_ROOT . "/files/avatar/$new_file_name";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$page['errors'][] = "No file selected";
|
||||
}
|
||||
|
||||
$ext = preg_replace('/\//', '', strtolower(substr($orig_filename, 1 + strrpos($orig_filename, "."))));
|
||||
$new_file_name = intval($opId). ".$ext";
|
||||
|
||||
$file_size = $_FILES['avatarFile']['size'];
|
||||
if ($file_size == 0 || $file_size > Settings::get('max_uploaded_file_size')) {
|
||||
$page['errors'][] = failed_uploading_file($orig_filename, "errors.file.size.exceeded");
|
||||
} elseif (!in_array($ext, $valid_types)) {
|
||||
$page['errors'][] = failed_uploading_file($orig_filename, "errors.invalid.file.type");
|
||||
} else {
|
||||
$avatar_local_dir = MIBEW_FS_ROOT.'/files/avatar/';
|
||||
$full_file_path = $avatar_local_dir . $new_file_name;
|
||||
if (file_exists($full_file_path)) {
|
||||
unlink($full_file_path);
|
||||
}
|
||||
if (!@move_uploaded_file($_FILES['avatarFile']['tmp_name'], $full_file_path)) {
|
||||
$page['errors'][] = failed_uploading_file($orig_filename, "errors.file.move.error");
|
||||
} else {
|
||||
$avatar = MIBEW_WEB_ROOT . "/files/avatar/$new_file_name";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$page['errors'][] = "No file selected";
|
||||
}
|
||||
|
||||
if (count($page['errors']) == 0) {
|
||||
update_operator_avatar($op['operatorid'], $avatar);
|
||||
|
||||
if ($opId && $avatar && $_SESSION[SESSION_PREFIX."operator"] && $operator['operatorid'] == $opId) {
|
||||
$_SESSION[SESSION_PREFIX."operator"]['vcavatar'] = $avatar;
|
||||
}
|
||||
header("Location: " . MIBEW_WEB_ROOT . "/operator/avatar.php?op=" . intval($opId));
|
||||
exit;
|
||||
} else {
|
||||
$page['avatar'] = topage($op['vcavatar']);
|
||||
}
|
||||
if (count($page['errors']) == 0) {
|
||||
update_operator_avatar($op['operatorid'], $avatar);
|
||||
|
||||
if ($op_id && $avatar && $_SESSION[SESSION_PREFIX . "operator"] && $operator['operatorid'] == $op_id) {
|
||||
$_SESSION[SESSION_PREFIX . "operator"]['vcavatar'] = $avatar;
|
||||
}
|
||||
header("Location: " . MIBEW_WEB_ROOT . "/operator/avatar.php?op=" . intval($op_id));
|
||||
exit;
|
||||
} else {
|
||||
$page['avatar'] = to_page($op['vcavatar']);
|
||||
}
|
||||
} else {
|
||||
if (isset($_GET['delete']) && $_GET['delete'] == "true" && $canmodify) {
|
||||
update_operator_avatar($op['operatorid'], '');
|
||||
header("Location: " . MIBEW_WEB_ROOT . "/operator/avatar.php?op=" . intval($opId));
|
||||
exit;
|
||||
}
|
||||
$page['avatar'] = topage($op['vcavatar']);
|
||||
if (isset($_GET['delete']) && $_GET['delete'] == "true" && $can_modify) {
|
||||
update_operator_avatar($op['operatorid'], '');
|
||||
header("Location: " . MIBEW_WEB_ROOT . "/operator/avatar.php?op=" . intval($op_id));
|
||||
exit;
|
||||
}
|
||||
$page['avatar'] = to_page($op['vcavatar']);
|
||||
}
|
||||
|
||||
$page['currentop'] = $op ? topage(get_operator_name($op)) . " (" . $op['vclogin'] . ")" : getlocal("not_found");
|
||||
$page['canmodify'] = $canmodify ? "1" : "";
|
||||
$page['currentop'] = $op ? to_page(get_operator_name($op)) . " (" . $op['vclogin'] . ")" : getlocal("not_found");
|
||||
$page['canmodify'] = $can_modify ? "1" : "";
|
||||
$page['title'] = getlocal("page_avatar.title");
|
||||
$page['menuid'] = ($operator['operatorid'] == $opId) ? "profile" : "operators";
|
||||
$page['menuid'] = ($operator['operatorid'] == $op_id) ? "profile" : "operators";
|
||||
|
||||
$page = array_merge(
|
||||
$page,
|
||||
prepare_menu($operator)
|
||||
);
|
||||
$page['tabs'] = setup_operator_settings_tabs($opId, 1);
|
||||
$page = array_merge($page, prepare_menu($operator));
|
||||
$page['tabs'] = setup_operator_settings_tabs($op_id, 1);
|
||||
|
||||
$page_style = new PageStyle(PageStyle::currentStyle());
|
||||
$page_style->render('avatar', $page);
|
||||
|
||||
?>
|
@ -21,13 +21,14 @@ use Mibew\Thread;
|
||||
use Mibew\Style\PageStyle;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(dirname(dirname(__FILE__)).'/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/chat.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/pagination.php');
|
||||
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/chat.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/pagination.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/track.php');
|
||||
|
||||
$operator = check_login();
|
||||
csrfchecktoken();
|
||||
csrf_check_token();
|
||||
$page = array('banId' => '');
|
||||
$page['saved'] = false;
|
||||
$page['thread'] = '';
|
||||
@ -35,109 +36,103 @@ $page['threadid'] = '';
|
||||
$page['errors'] = array();
|
||||
|
||||
if (isset($_POST['address'])) {
|
||||
$banId = verifyparam("banId", "/^(\d{1,9})?$/", "");
|
||||
$address = getparam("address");
|
||||
$days = getparam("days");
|
||||
$comment = getparam('comment');
|
||||
$threadid = isset($_POST['threadid']) ? getparam('threadid') : "";
|
||||
$ban_id = verify_param("banId", "/^(\d{1,9})?$/", "");
|
||||
$address = get_param("address");
|
||||
$days = get_param("days");
|
||||
$comment = get_param('comment');
|
||||
$thread_id = isset($_POST['threadid']) ? get_param('threadid') : "";
|
||||
|
||||
if (!$address) {
|
||||
$page['errors'][] = no_field("form.field.address");
|
||||
}
|
||||
if (!$address) {
|
||||
$page['errors'][] = no_field("form.field.address");
|
||||
}
|
||||
|
||||
if (!preg_match("/^\d+$/", $days)) {
|
||||
$page['errors'][] = wrong_field("form.field.ban_days");
|
||||
}
|
||||
if (!preg_match("/^\d+$/", $days)) {
|
||||
$page['errors'][] = wrong_field("form.field.ban_days");
|
||||
}
|
||||
|
||||
if (!$comment) {
|
||||
$page['errors'][] = no_field("form.field.ban_comment");
|
||||
}
|
||||
if (!$comment) {
|
||||
$page['errors'][] = no_field("form.field.ban_comment");
|
||||
}
|
||||
|
||||
$existing_ban = ban_for_addr($address);
|
||||
$existing_ban = ban_for_addr($address);
|
||||
|
||||
if ((!$banId && $existing_ban) ||
|
||||
($banId && $existing_ban && $banId != $existing_ban['banid'])) {
|
||||
$page['errors'][] = getlocal2("ban.error.duplicate", array($address, $existing_ban['banid']));
|
||||
}
|
||||
if ((!$ban_id && $existing_ban) ||
|
||||
($ban_id && $existing_ban && $ban_id != $existing_ban['banid'])) {
|
||||
$page['errors'][] = getlocal2("ban.error.duplicate", array($address, $existing_ban['banid']));
|
||||
}
|
||||
|
||||
if (count($page['errors']) == 0) {
|
||||
$db = Database::getInstance();
|
||||
$now = time();
|
||||
$till_time = $now + $days * 24 * 60 * 60;
|
||||
if (!$banId) {
|
||||
$db->query(
|
||||
"insert into {chatban} (dtmcreated,dtmtill,address,comment) " .
|
||||
"values (:now,:till,:address,:comment)",
|
||||
array(
|
||||
':now' => $now,
|
||||
':till' => $till_time,
|
||||
':address' => $address,
|
||||
':comment' => $comment
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$db->query(
|
||||
"update {chatban} set dtmtill = :till,address = :address, " .
|
||||
"comment = :comment where banid = :banid",
|
||||
array(
|
||||
':till' => $till_time,
|
||||
':address' => $address,
|
||||
':comment' => $comment,
|
||||
':banid' => $banId
|
||||
)
|
||||
);
|
||||
}
|
||||
if (count($page['errors']) == 0) {
|
||||
$db = Database::getInstance();
|
||||
$now = time();
|
||||
$till_time = $now + $days * 24 * 60 * 60;
|
||||
if (!$ban_id) {
|
||||
$db->query(
|
||||
("INSERT INTO {chatban} (dtmcreated, dtmtill, address, comment) "
|
||||
. "VALUES (:now,:till,:address,:comment)"),
|
||||
array(
|
||||
':now' => $now,
|
||||
':till' => $till_time,
|
||||
':address' => $address,
|
||||
':comment' => $comment,
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$db->query(
|
||||
("UPDATE {chatban} SET dtmtill = :till, address = :address, "
|
||||
. "comment = :comment WHERE banid = :banid"),
|
||||
array(
|
||||
':till' => $till_time,
|
||||
':address' => $address,
|
||||
':comment' => $comment,
|
||||
':banid' => $ban_id,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$page['saved'] = true;
|
||||
$page['address'] = $address;
|
||||
$page['saved'] = true;
|
||||
$page['address'] = $address;
|
||||
} else {
|
||||
$page['banId'] = to_page($ban_id);
|
||||
$page['formaddress'] = to_page($address);
|
||||
$page['formdays'] = to_page($days);
|
||||
$page['formcomment'] = to_page($comment);
|
||||
$page['threadid'] = $thread_id;
|
||||
}
|
||||
} elseif (isset($_GET['id'])) {
|
||||
$ban_id = verify_param('id', "/^\d{1,9}$/");
|
||||
$db = Database::getInstance();
|
||||
$ban = $db->query(
|
||||
("SELECT banid, (dtmtill - :now) AS days, address, comment "
|
||||
. "FROM {chatban} WHERE banid = :banid"),
|
||||
array(
|
||||
':banid' => $ban_id,
|
||||
':now' => time(),
|
||||
),
|
||||
array('return_rows' => Database::RETURN_ONE_ROW)
|
||||
);
|
||||
|
||||
} else {
|
||||
$page['banId'] = topage($banId);
|
||||
$page['formaddress'] = topage($address);
|
||||
$page['formdays'] = topage($days);
|
||||
$page['formcomment'] = topage($comment);
|
||||
$page['threadid'] = $threadid;
|
||||
}
|
||||
} else if (isset($_GET['id'])) {
|
||||
$banId = verifyparam('id', "/^\d{1,9}$/");
|
||||
$db = Database::getInstance();
|
||||
$ban = $db->query(
|
||||
"select banid,(dtmtill - :now)" .
|
||||
" as days,address,comment from {chatban} where banid = :banid",
|
||||
array(
|
||||
':banid' => $banId,
|
||||
':now' => time()
|
||||
),
|
||||
array('return_rows' => Database::RETURN_ONE_ROW)
|
||||
);
|
||||
|
||||
if ($ban) {
|
||||
$page['banId'] = topage($ban['banid']);
|
||||
$page['formaddress'] = topage($ban['address']);
|
||||
$page['formdays'] = topage(round($ban['days'] / 86400));
|
||||
$page['formcomment'] = topage($ban['comment']);
|
||||
} else {
|
||||
$page['errors'][] = "Wrong id";
|
||||
}
|
||||
} else if (isset($_GET['thread'])) {
|
||||
$threadid = verifyparam('thread', "/^\d{1,9}$/");
|
||||
$thread = Thread::load($threadid);
|
||||
if ($thread) {
|
||||
$page['thread'] = topage($thread->userName);
|
||||
$page['threadid'] = $threadid;
|
||||
$page['formaddress'] = topage($thread->remote);
|
||||
$page['formdays'] = 15;
|
||||
}
|
||||
if ($ban) {
|
||||
$page['banId'] = to_page($ban['banid']);
|
||||
$page['formaddress'] = to_page($ban['address']);
|
||||
$page['formdays'] = to_page(round($ban['days'] / 86400));
|
||||
$page['formcomment'] = to_page($ban['comment']);
|
||||
} else {
|
||||
$page['errors'][] = "Wrong id";
|
||||
}
|
||||
} elseif (isset($_GET['thread'])) {
|
||||
$thread_id = verify_param('thread', "/^\d{1,9}$/");
|
||||
$thread = Thread::load($thread_id);
|
||||
if ($thread) {
|
||||
$page['thread'] = to_page($thread->userName);
|
||||
$page['threadid'] = $thread_id;
|
||||
$page['formaddress'] = to_page($thread->remote);
|
||||
$page['formdays'] = 15;
|
||||
}
|
||||
}
|
||||
|
||||
$page['title'] = getlocal("page_ban.title");
|
||||
|
||||
$page = array_merge(
|
||||
$page,
|
||||
prepare_menu($operator, false)
|
||||
);
|
||||
$page = array_merge($page, prepare_menu($operator, false));
|
||||
|
||||
$page_style = new PageStyle(PageStyle::currentStyle());
|
||||
$page_style->render('ban', $page);
|
||||
|
||||
?>
|
@ -20,16 +20,17 @@ use Mibew\Database;
|
||||
use Mibew\Style\PageStyle;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(dirname(dirname(__FILE__)).'/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/chat.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/pagination.php');
|
||||
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/chat.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/pagination.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/track.php');
|
||||
|
||||
$operator = check_login();
|
||||
csrfchecktoken();
|
||||
csrf_check_token();
|
||||
|
||||
$page = array(
|
||||
'errors' => array(),
|
||||
'errors' => array(),
|
||||
);
|
||||
|
||||
setlocale(LC_TIME, getstring("time.locale"));
|
||||
@ -37,38 +38,33 @@ setlocale(LC_TIME, getstring("time.locale"));
|
||||
$db = Database::getInstance();
|
||||
|
||||
if (isset($_GET['act']) && $_GET['act'] == 'del') {
|
||||
$banId = isset($_GET['id']) ? $_GET['id'] : "";
|
||||
$ban_id = isset($_GET['id']) ? $_GET['id'] : "";
|
||||
|
||||
if (!preg_match("/^\d+$/", $banId)) {
|
||||
$page['errors'][] = "Cannot delete: wrong argument";
|
||||
}
|
||||
if (!preg_match("/^\d+$/", $ban_id)) {
|
||||
$page['errors'][] = "Cannot delete: wrong argument";
|
||||
}
|
||||
|
||||
if (count($page['errors']) == 0) {
|
||||
$db->query("delete from {chatban} where banid = ?", array($banId));
|
||||
header("Location: " . MIBEW_WEB_ROOT . "/operator/blocked.php");
|
||||
exit;
|
||||
}
|
||||
if (count($page['errors']) == 0) {
|
||||
$db->query("DELETE FROM {chatban} WHERE banid = ?", array($ban_id));
|
||||
header("Location: " . MIBEW_WEB_ROOT . "/operator/blocked.php");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$blockedList = $db->query(
|
||||
"select banid, dtmtill as till,address,comment from {chatban}",
|
||||
NULL,
|
||||
array('return_rows' => Database::RETURN_ALL_ROWS)
|
||||
$blocked_list = $db->query(
|
||||
"SELECT banid, dtmtill AS till,address,comment FROM {chatban}",
|
||||
null,
|
||||
array('return_rows' => Database::RETURN_ALL_ROWS)
|
||||
);
|
||||
|
||||
$page['title'] = getlocal("page_bans.title");
|
||||
$page['menuid'] = "blocked";
|
||||
|
||||
$pagination = setup_pagination($blockedList);
|
||||
$pagination = setup_pagination($blocked_list);
|
||||
$page['pagination'] = $pagination['info'];
|
||||
$page['pagination.items'] = $pagination['items'];
|
||||
|
||||
$page = array_merge(
|
||||
$page,
|
||||
prepare_menu($operator)
|
||||
);
|
||||
$page = array_merge($page, prepare_menu($operator));
|
||||
|
||||
$page_style = new PageStyle(PageStyle::currentStyle());
|
||||
$page_style->render('blocked_visitors', $page);
|
||||
|
||||
?>
|
@ -20,19 +20,19 @@ use Mibew\Database;
|
||||
use Mibew\Style\PageStyle;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(dirname(dirname(__FILE__)).'/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/canned.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/settings.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/groups.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/pagination.php');
|
||||
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/canned.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/settings.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/groups.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/pagination.php');
|
||||
|
||||
$operator = check_login();
|
||||
force_password($operator);
|
||||
csrfchecktoken();
|
||||
csrf_check_token();
|
||||
|
||||
$page = array(
|
||||
'errors' => array(),
|
||||
'errors' => array(),
|
||||
);
|
||||
|
||||
# locales
|
||||
@ -40,58 +40,59 @@ $page = array(
|
||||
$all_locales = get_available_locales();
|
||||
$locales_with_label = array();
|
||||
foreach ($all_locales as $id) {
|
||||
$locales_with_label[] = array('id' => $id, 'name' => getlocal_($id, "names"));
|
||||
$locales_with_label[] = array('id' => $id, 'name' => getlocal_($id, "names"));
|
||||
}
|
||||
$page['locales'] = $locales_with_label;
|
||||
|
||||
$lang = verifyparam("lang", "/^[\w-]{2,5}$/", "");
|
||||
$lang = verify_param("lang", "/^[\w-]{2,5}$/", "");
|
||||
if (!$lang || !in_array($lang, $all_locales)) {
|
||||
$lang = in_array(CURRENT_LOCALE, $all_locales) ? CURRENT_LOCALE : $all_locales[0];
|
||||
$lang = in_array(CURRENT_LOCALE, $all_locales) ? CURRENT_LOCALE : $all_locales[0];
|
||||
}
|
||||
|
||||
# groups
|
||||
|
||||
$groupid = "";
|
||||
$groupid = verifyparam("group", "/^\d{0,8}$/", "");
|
||||
if ($groupid) {
|
||||
$group = group_by_id($groupid);
|
||||
if (!$group) {
|
||||
$page['errors'][] = getlocal("page.group.no_such");
|
||||
$groupid = "";
|
||||
}
|
||||
$group_id = verify_param("group", "/^\d{0,8}$/", "");
|
||||
if ($group_id) {
|
||||
$group = group_by_id($group_id);
|
||||
if (!$group) {
|
||||
$page['errors'][] = getlocal("page.group.no_such");
|
||||
$group_id = "";
|
||||
}
|
||||
}
|
||||
|
||||
$allgroups = in_isolation($operator)?get_all_groups_for_operator($operator):get_all_groups();
|
||||
$all_groups = in_isolation($operator) ? get_all_groups_for_operator($operator) : get_all_groups();
|
||||
$page['groups'] = array();
|
||||
$page['groups'][] = array(
|
||||
'groupid' => '',
|
||||
'vclocalname' => getlocal("page.gen_button.default_group"),
|
||||
'level' => 0
|
||||
'groupid' => '',
|
||||
'vclocalname' => getlocal("page.gen_button.default_group"),
|
||||
'level' => 0,
|
||||
);
|
||||
foreach ($allgroups as $g) {
|
||||
$page['groups'][] = $g;
|
||||
foreach ($all_groups as $g) {
|
||||
$page['groups'][] = $g;
|
||||
}
|
||||
|
||||
# delete
|
||||
|
||||
if (isset($_GET['act']) && $_GET['act'] == 'delete') {
|
||||
$key = isset($_GET['key']) ? $_GET['key'] : "";
|
||||
$key = isset($_GET['key']) ? $_GET['key'] : "";
|
||||
|
||||
if (!preg_match("/^\d+$/", $key)) {
|
||||
$page['errors'][] = "Wrong key";
|
||||
}
|
||||
if (!preg_match("/^\d+$/", $key)) {
|
||||
$page['errors'][] = "Wrong key";
|
||||
}
|
||||
|
||||
if (count($page['errors']) == 0) {
|
||||
$db = Database::getInstance();
|
||||
$db->query("delete from {chatresponses} where id = ?", array($key));
|
||||
header("Location: " . MIBEW_WEB_ROOT . "/operator/canned.php?lang=" . urlencode($lang) . "&group=" . intval($groupid));
|
||||
exit;
|
||||
}
|
||||
if (count($page['errors']) == 0) {
|
||||
$db = Database::getInstance();
|
||||
$db->query("DELETE FROM {chatresponses} WHERE id = ?", array($key));
|
||||
$redirect_to = MIBEW_WEB_ROOT . "/operator/canned.php?lang="
|
||||
. urlencode($lang) . "&group=" . intval($group_id);
|
||||
header("Location: " . $redirect_to);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
// Get messages and setup pagination
|
||||
|
||||
$messages = load_canned_messages($lang, $groupid);
|
||||
$messages = load_canned_messages($lang, $group_id);
|
||||
$pagination = setup_pagination($messages);
|
||||
$page['pagination'] = $pagination['info'];
|
||||
$page['pagination.items'] = $pagination['items'];
|
||||
@ -99,16 +100,11 @@ $page['pagination.items'] = $pagination['items'];
|
||||
# form values
|
||||
|
||||
$page['formlang'] = $lang;
|
||||
$page['formgroup'] = $groupid;
|
||||
$page['formgroup'] = $group_id;
|
||||
$page['title'] = getlocal("canned.title");
|
||||
$page['menuid'] = "canned";
|
||||
|
||||
$page = array_merge(
|
||||
$page,
|
||||
prepare_menu($operator)
|
||||
);
|
||||
$page = array_merge($page, prepare_menu($operator));
|
||||
|
||||
$page_style = new PageStyle(PageStyle::currentStyle());
|
||||
$page_style->render('canned', $page);
|
||||
|
||||
?>
|
@ -19,77 +19,69 @@
|
||||
use Mibew\Style\PageStyle;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(dirname(dirname(__FILE__)).'/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/canned.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/pagination.php');
|
||||
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/canned.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/pagination.php');
|
||||
|
||||
$operator = check_login();
|
||||
csrfchecktoken();
|
||||
csrf_check_token();
|
||||
|
||||
$stringid = verifyparam("key", "/^\d{0,9}$/", "");
|
||||
$string_id = verify_param("key", "/^\d{0,9}$/", "");
|
||||
|
||||
$page = array(
|
||||
'errors' => array(),
|
||||
'errors' => array(),
|
||||
);
|
||||
|
||||
$page_style = new PageStyle(PageStyle::currentStyle());
|
||||
|
||||
if ($stringid) {
|
||||
$canned_message = load_canned_message($stringid);
|
||||
if (!$canned_message) {
|
||||
$page['errors'][] = getlocal("cannededit.no_such");
|
||||
$stringid = "";
|
||||
}else{
|
||||
$title = $canned_message['vctitle'];
|
||||
$message = $canned_message['vcvalue'];
|
||||
}
|
||||
if ($string_id) {
|
||||
$canned_message = load_canned_message($string_id);
|
||||
if (!$canned_message) {
|
||||
$page['errors'][] = getlocal("cannededit.no_such");
|
||||
$string_id = "";
|
||||
} else {
|
||||
$title = $canned_message['vctitle'];
|
||||
$message = $canned_message['vcvalue'];
|
||||
}
|
||||
} else {
|
||||
$message = '';
|
||||
$title = '';
|
||||
$page['locale'] = verifyparam("lang", "/^[\w-]{2,5}$/", "");
|
||||
$page['groupid'] = "";
|
||||
$page['groupid'] = verifyparam("group", "/^\d{0,8}$/");
|
||||
$message = '';
|
||||
$title = '';
|
||||
$page['locale'] = verify_param("lang", "/^[\w-]{2,5}$/", "");
|
||||
$page['groupid'] = "";
|
||||
$page['groupid'] = verify_param("group", "/^\d{0,8}$/");
|
||||
}
|
||||
|
||||
if (isset($_POST['message']) && isset($_POST['title'])) {
|
||||
$title = getparam('title');
|
||||
if (!$title) {
|
||||
$page['errors'][] = no_field("form.field.title");
|
||||
}
|
||||
$title = get_param('title');
|
||||
if (!$title) {
|
||||
$page['errors'][] = no_field("form.field.title");
|
||||
}
|
||||
|
||||
$message = getparam('message');
|
||||
if (!$message) {
|
||||
$page['errors'][] = no_field("form.field.message");
|
||||
}
|
||||
$message = get_param('message');
|
||||
if (!$message) {
|
||||
$page['errors'][] = no_field("form.field.message");
|
||||
}
|
||||
|
||||
if (count($page['errors']) == 0) {
|
||||
if ($stringid) {
|
||||
save_canned_message($stringid, $title, $message);
|
||||
} else {
|
||||
add_canned_message($page['locale'], $page['groupid'], $title, $message);
|
||||
}
|
||||
$page['saved'] = true;
|
||||
$page = array_merge(
|
||||
$page,
|
||||
prepare_menu($operator, false)
|
||||
);
|
||||
$page_style->render('cannededit', $page);
|
||||
exit;
|
||||
}
|
||||
if (count($page['errors']) == 0) {
|
||||
if ($string_id) {
|
||||
save_canned_message($string_id, $title, $message);
|
||||
} else {
|
||||
add_canned_message($page['locale'], $page['groupid'], $title, $message);
|
||||
}
|
||||
$page['saved'] = true;
|
||||
$page = array_merge($page, prepare_menu($operator, false));
|
||||
$page_style->render('cannededit', $page);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$page['saved'] = false;
|
||||
$page['key'] = $stringid;
|
||||
$page['formtitle'] = topage($title);
|
||||
$page['formmessage'] = topage($message);
|
||||
$page['title'] = empty($stringid) ? getlocal("cannednew.title") : getlocal("cannededit.title");
|
||||
$page['key'] = $string_id;
|
||||
$page['formtitle'] = to_page($title);
|
||||
$page['formmessage'] = to_page($message);
|
||||
$page['title'] = empty($string_id) ? getlocal("cannednew.title") : getlocal("cannededit.title");
|
||||
|
||||
$page = array_merge(
|
||||
$page,
|
||||
prepare_menu($operator, false)
|
||||
);
|
||||
$page = array_merge($page, prepare_menu($operator, false));
|
||||
|
||||
$page_style->render('cannededit', $page);
|
||||
|
||||
?>
|
@ -20,66 +20,70 @@ use Mibew\Settings;
|
||||
use Mibew\Style\PageStyle;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(dirname(dirname(__FILE__)).'/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/settings.php');
|
||||
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/settings.php');
|
||||
|
||||
$operator = check_login();
|
||||
csrfchecktoken();
|
||||
csrf_check_token();
|
||||
|
||||
$page = array(
|
||||
'agentId' => '',
|
||||
'errors' => array(),
|
||||
'agentId' => '',
|
||||
'errors' => array(),
|
||||
);
|
||||
|
||||
$options = array(
|
||||
'enableban', 'usercanchangename',
|
||||
'enablegroups', 'enablegroupsisolation',
|
||||
'enablestatistics', 'enabletracking',
|
||||
'enablessl', 'forcessl',
|
||||
'enablepresurvey', 'surveyaskmail', 'surveyaskgroup', 'surveyaskmessage',
|
||||
'enablepopupnotification', 'showonlineoperators',
|
||||
'enablecaptcha');
|
||||
'enableban',
|
||||
'usercanchangename',
|
||||
'enablegroups',
|
||||
'enablegroupsisolation',
|
||||
'enablestatistics',
|
||||
'enabletracking',
|
||||
'enablessl',
|
||||
'forcessl',
|
||||
'enablepresurvey',
|
||||
'surveyaskmail',
|
||||
'surveyaskgroup',
|
||||
'surveyaskmessage',
|
||||
'enablepopupnotification',
|
||||
'showonlineoperators',
|
||||
'enablecaptcha',
|
||||
);
|
||||
|
||||
if (Settings::get('featuresversion') != FEATURES_VERSION) {
|
||||
Settings::set('featuresversion', FEATURES_VERSION);
|
||||
Settings::update();
|
||||
Settings::set('featuresversion', FEATURES_VERSION);
|
||||
Settings::update();
|
||||
}
|
||||
$params = array();
|
||||
foreach ($options as $opt) {
|
||||
$params[$opt] = Settings::get($opt);
|
||||
$params[$opt] = Settings::get($opt);
|
||||
}
|
||||
|
||||
if (isset($_POST['sent'])) {
|
||||
if (is_capable(CAN_ADMINISTRATE, $operator)) {
|
||||
foreach ($options as $opt) {
|
||||
Settings::set($opt,(verifyparam($opt, "/^on$/", "") == "on" ? "1" : "0"));
|
||||
}
|
||||
Settings::update();
|
||||
header("Location: " . MIBEW_WEB_ROOT . "/operator/features.php?stored");
|
||||
exit;
|
||||
} else {
|
||||
$page['errors'][] = "Not an administrator";
|
||||
}
|
||||
if (is_capable(CAN_ADMINISTRATE, $operator)) {
|
||||
foreach ($options as $opt) {
|
||||
Settings::set($opt, (verify_param($opt, "/^on$/", "") == "on" ? "1" : "0"));
|
||||
}
|
||||
Settings::update();
|
||||
header("Location: " . MIBEW_WEB_ROOT . "/operator/features.php?stored");
|
||||
exit;
|
||||
} else {
|
||||
$page['errors'][] = "Not an administrator";
|
||||
}
|
||||
}
|
||||
|
||||
$page['canmodify'] = is_capable(CAN_ADMINISTRATE, $operator);
|
||||
$page['stored'] = isset($_GET['stored']);
|
||||
foreach ($options as $opt) {
|
||||
$page["form$opt"] = $params[$opt] == "1";
|
||||
$page["form$opt"] = $params[$opt] == "1";
|
||||
}
|
||||
|
||||
$page['title'] = getlocal("settings.title");
|
||||
$page['menuid'] = "settings";
|
||||
|
||||
$page = array_merge(
|
||||
$page,
|
||||
prepare_menu($operator)
|
||||
);
|
||||
$page = array_merge($page, prepare_menu($operator));
|
||||
|
||||
$page['tabs'] = setup_settings_tabs(1);
|
||||
|
||||
$page_style = new PageStyle(PageStyle::currentStyle());
|
||||
$page_style->render('features', $page);
|
||||
|
||||
?>
|
@ -22,82 +22,94 @@ use Mibew\Style\InvitationStyle;
|
||||
use Mibew\Style\PageStyle;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(dirname(dirname(__FILE__)).'/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/groups.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/getcode.php');
|
||||
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/groups.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/getcode.php');
|
||||
|
||||
$operator = check_login();
|
||||
force_password($operator);
|
||||
|
||||
$page = array(
|
||||
'errors' => array(),
|
||||
'errors' => array(),
|
||||
);
|
||||
|
||||
$imageLocales = get_image_locales_map(MIBEW_FS_ROOT.'/locales');
|
||||
$image = verifyparam(isset($_GET['image']) ? "image" : "i", "/^\w+$/", "mibew");
|
||||
if (!isset($imageLocales[$image])) {
|
||||
$page['errors'][] = "Unknown image: $image";
|
||||
$avail = array_keys($imageLocales);
|
||||
$image = $avail[0];
|
||||
$image_locales_map = get_image_locales_map(MIBEW_FS_ROOT . '/locales');
|
||||
$image = verify_param(isset($_GET['image']) ? "image" : "i", "/^\w+$/", "mibew");
|
||||
if (!isset($image_locales_map[$image])) {
|
||||
$page['errors'][] = "Unknown image: $image";
|
||||
$avail = array_keys($image_locales_map);
|
||||
$image = $avail[0];
|
||||
}
|
||||
$image_locales = $imageLocales[$image];
|
||||
$image_locales = $image_locales_map[$image];
|
||||
|
||||
$stylelist = ChatStyle::availableStyles();
|
||||
$stylelist[""] = getlocal("page.preview.style_default");
|
||||
$style = verifyparam("style", "/^\w*$/", "");
|
||||
if ($style && !in_array($style, $stylelist)) {
|
||||
$style = "";
|
||||
$style_list = ChatStyle::availableStyles();
|
||||
$style_list[""] = getlocal("page.preview.style_default");
|
||||
$style = verify_param("style", "/^\w*$/", "");
|
||||
if ($style && !in_array($style, $style_list)) {
|
||||
$style = "";
|
||||
}
|
||||
|
||||
$invitationstylelist = InvitationStyle::availableStyles();
|
||||
$invitationstylelist[""] = getlocal("page.preview.style_default");
|
||||
$invitationstyle = verifyparam("invitationstyle", "/^\w*$/", "");
|
||||
if ($invitationstyle && !in_array($invitationstyle, $invitationstylelist)) {
|
||||
$invitationstyle = "";
|
||||
$invitation_style_list = InvitationStyle::availableStyles();
|
||||
$invitation_style_list[""] = getlocal("page.preview.style_default");
|
||||
$invitation_style = verify_param("invitationstyle", "/^\w*$/", "");
|
||||
if ($invitation_style && !in_array($invitation_style, $invitation_style_list)) {
|
||||
$invitation_style = "";
|
||||
}
|
||||
|
||||
$groupid = verifyparam_groupid("group", $page['errors']);
|
||||
$showhost = verifyparam("hostname", "/^on$/", "") == "on";
|
||||
$forcesecure = verifyparam("secure", "/^on$/", "") == "on";
|
||||
$modsecurity = verifyparam("modsecurity", "/^on$/", "") == "on";
|
||||
$group_id = verifyparam_groupid("group", $page['errors']);
|
||||
$show_host = verify_param("hostname", "/^on$/", "") == "on";
|
||||
$force_secure = verify_param("secure", "/^on$/", "") == "on";
|
||||
$mod_security = verify_param("modsecurity", "/^on$/", "") == "on";
|
||||
|
||||
$code_type = verifyparam("codetype", "/^(button|operator_code)$/", "button");
|
||||
$code_type = verify_param("codetype", "/^(button|operator_code)$/", "button");
|
||||
$operator_code = ($code_type == "operator_code");
|
||||
|
||||
$lang = verifyparam("lang", "/^[\w-]{2,5}$/", "");
|
||||
if (!$lang || !in_array($lang, $image_locales))
|
||||
$lang = in_array(CURRENT_LOCALE, $image_locales) ? CURRENT_LOCALE : $image_locales[0];
|
||||
$lang = verify_param("lang", "/^[\w-]{2,5}$/", "");
|
||||
if (!$lang || !in_array($lang, $image_locales)) {
|
||||
$lang = in_array(CURRENT_LOCALE, $image_locales) ? CURRENT_LOCALE : $image_locales[0];
|
||||
}
|
||||
|
||||
$file = MIBEW_FS_ROOT.'/locales/${lang}/button/${image}_on.gif';
|
||||
$file = MIBEW_FS_ROOT . '/locales/${lang}/button/${image}_on.gif';
|
||||
$size = get_gifimage_size($file);
|
||||
|
||||
$imagehref = get_app_location($showhost, $forcesecure) . "/b.php?i=$image&lang=$lang";
|
||||
if ($groupid) {
|
||||
$imagehref .= "&group=$groupid";
|
||||
$image_href = get_app_location($show_host, $force_secure) . "/b.php?i=$image&lang=$lang";
|
||||
if ($group_id) {
|
||||
$image_href .= "&group=$group_id";
|
||||
}
|
||||
$message = get_image($imagehref, $size[0], $size[1]);
|
||||
$message = get_image($image_href, $size[0], $size[1]);
|
||||
|
||||
$page['buttonCode'] = generate_button("", $lang, $style, $invitationstyle, $groupid, $message, $showhost, $forcesecure, $modsecurity, $operator_code);
|
||||
$page['availableImages'] = array_keys($imageLocales);
|
||||
$page['buttonCode'] = generate_button(
|
||||
"",
|
||||
$lang,
|
||||
$style,
|
||||
$invitation_style,
|
||||
$group_id,
|
||||
$message,
|
||||
$show_host,
|
||||
$force_secure,
|
||||
$mod_security,
|
||||
$operator_code
|
||||
);
|
||||
$page['availableImages'] = array_keys($image_locales_map);
|
||||
$page['availableLocales'] = $image_locales;
|
||||
$page['availableChatStyles'] = $stylelist;
|
||||
$page['availableInvitationStyles'] = $invitationstylelist;
|
||||
$page['availableChatStyles'] = $style_list;
|
||||
$page['availableInvitationStyles'] = $invitation_style_list;
|
||||
$page['groups'] = get_groups_list();
|
||||
|
||||
$page['availableCodeTypes'] = array(
|
||||
'button' => getlocal('page.gen_button.button'),
|
||||
'operator_code' => getlocal('page.gen_button.operator_code')
|
||||
'button' => getlocal('page.gen_button.button'),
|
||||
'operator_code' => getlocal('page.gen_button.operator_code')
|
||||
);
|
||||
|
||||
$page['formgroup'] = $groupid;
|
||||
$page['formgroup'] = $group_id;
|
||||
$page['formstyle'] = $style;
|
||||
$page['forminvitationstyle'] = $invitationstyle;
|
||||
$page['forminvitationstyle'] = $invitation_style;
|
||||
$page['formimage'] = $image;
|
||||
$page['formlang'] = $lang;
|
||||
$page['formhostname'] = $showhost;
|
||||
$page['formsecure'] = $forcesecure;
|
||||
$page['formmodsecurity'] = $modsecurity;
|
||||
$page['formhostname'] = $show_host;
|
||||
$page['formsecure'] = $force_secure;
|
||||
$page['formmodsecurity'] = $mod_security;
|
||||
$page['formcodetype'] = $code_type;
|
||||
|
||||
$page['enabletracking'] = Settings::get('enabletracking');
|
||||
@ -106,12 +118,7 @@ $page['operator_code'] = $operator_code;
|
||||
$page['title'] = getlocal("page.gen_button.title");
|
||||
$page['menuid'] = "getcode";
|
||||
|
||||
$page = array_merge(
|
||||
$page,
|
||||
prepare_menu($operator)
|
||||
);
|
||||
$page = array_merge($page, prepare_menu($operator));
|
||||
|
||||
$page_style = new PageStyle(PageStyle::currentStyle());
|
||||
$page_style->render('gen_button', $page);
|
||||
|
||||
?>
|
@ -19,138 +19,142 @@
|
||||
use Mibew\Style\PageStyle;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(dirname(dirname(__FILE__)).'/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/groups.php');
|
||||
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/groups.php');
|
||||
|
||||
$operator = check_login();
|
||||
csrfchecktoken();
|
||||
csrf_check_token();
|
||||
|
||||
$page = array(
|
||||
'grid' => '',
|
||||
'errors' => array(),
|
||||
'grid' => '',
|
||||
'errors' => array(),
|
||||
);
|
||||
|
||||
$groupid = '';
|
||||
$group_id = '';
|
||||
|
||||
if (isset($_POST['name'])) {
|
||||
$groupid = verifyparam("gid", "/^(\d{1,9})?$/", "");
|
||||
$name = getparam('name');
|
||||
$description = getparam('description');
|
||||
$commonname = getparam('commonname');
|
||||
$commondescription = getparam('commondescription');
|
||||
$email = getparam('email');
|
||||
$weight = getparam('weight');
|
||||
$parentgroup = verifyparam("parentgroup", "/^(\d{1,9})?$/", "");
|
||||
$title = getparam('title');
|
||||
$chattitle = getparam('chattitle');
|
||||
$hosturl = getparam('hosturl');
|
||||
$logo = getparam('logo');
|
||||
$group_id = verify_param("gid", "/^(\d{1,9})?$/", "");
|
||||
$name = get_param('name');
|
||||
$description = get_param('description');
|
||||
$common_name = get_param('commonname');
|
||||
$common_description = get_param('commondescription');
|
||||
$email = get_param('email');
|
||||
$weight = get_param('weight');
|
||||
$parent_group = verify_param("parentgroup", "/^(\d{1,9})?$/", "");
|
||||
$title = get_param('title');
|
||||
$chat_title = get_param('chattitle');
|
||||
$host_url = get_param('hosturl');
|
||||
$logo = get_param('logo');
|
||||
|
||||
if (!$name)
|
||||
$page['errors'][] = no_field("form.field.groupname");
|
||||
if (!$name) {
|
||||
$page['errors'][] = no_field("form.field.groupname");
|
||||
}
|
||||
|
||||
if ($email != '' && !is_valid_email($email))
|
||||
$page['errors'][] = wrong_field("form.field.mail");
|
||||
if ($email != '' && !is_valid_email($email)) {
|
||||
$page['errors'][] = wrong_field("form.field.mail");
|
||||
}
|
||||
|
||||
if (! preg_match("/^(\d{1,9})?$/", $weight))
|
||||
$page['errors'][] = wrong_field("form.field.groupweight");
|
||||
if (!preg_match("/^(\d{1,9})?$/", $weight)) {
|
||||
$page['errors'][] = wrong_field("form.field.groupweight");
|
||||
}
|
||||
|
||||
if ($weight == '')
|
||||
$weight = 0;
|
||||
if ($weight == '') {
|
||||
$weight = 0;
|
||||
}
|
||||
|
||||
if (! $parentgroup)
|
||||
$parentgroup = NULL;
|
||||
if (!$parent_group) {
|
||||
$parent_group = null;
|
||||
}
|
||||
|
||||
$existing_group = group_by_name($name);
|
||||
if ((!$groupid && $existing_group) ||
|
||||
($groupid && $existing_group && $groupid != $existing_group['groupid']))
|
||||
$page['errors'][] = getlocal("page.group.duplicate_name");
|
||||
$existing_group = group_by_name($name);
|
||||
$duplicate_name = (!$group_id && $existing_group)
|
||||
|| ($group_id
|
||||
&& $existing_group
|
||||
&& $group_id != $existing_group['groupid']);
|
||||
|
||||
if (count($page['errors']) == 0) {
|
||||
if (!$groupid) {
|
||||
$newdep = create_group(array(
|
||||
'name' => $name,
|
||||
'description' => $description,
|
||||
'commonname' => $commonname,
|
||||
'commondescription' => $commondescription,
|
||||
'email' => $email,
|
||||
'weight' => $weight,
|
||||
'parent' => $parentgroup,
|
||||
'title' => $title,
|
||||
'chattitle' => $chattitle,
|
||||
'hosturl' => $hosturl,
|
||||
'logo' => $logo));
|
||||
header("Location: " . MIBEW_WEB_ROOT . "/operator/groupmembers.php?gid=" . intval($newdep['groupid']));
|
||||
exit;
|
||||
} else {
|
||||
update_group(array(
|
||||
'id' => $groupid,
|
||||
'name' => $name,
|
||||
'description' => $description,
|
||||
'commonname' => $commonname,
|
||||
'commondescription' => $commondescription,
|
||||
'email' => $email,
|
||||
'weight' => $weight,
|
||||
'parent' => $parentgroup,
|
||||
'title' => $title,
|
||||
'chattitle' => $chattitle,
|
||||
'hosturl' => $hosturl,
|
||||
'logo' => $logo));
|
||||
header("Location: " . MIBEW_WEB_ROOT . "/operator/group.php?gid=" . intval($groupid) . "&stored");
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
$page['formname'] = topage($name);
|
||||
$page['formdescription'] = topage($description);
|
||||
$page['formcommonname'] = topage($commonname);
|
||||
$page['formcommondescription'] = topage($commondescription);
|
||||
$page['formemail'] = topage($email);
|
||||
$page['formweight'] = topage($weight);
|
||||
$page['formparentgroup'] = topage($parentgroup);
|
||||
$page['grid'] = topage($groupid);
|
||||
$page['formtitle'] = topage($title);
|
||||
$page['formchattitle'] = topage($chattitle);
|
||||
$page['formhosturl'] = topage($hosturl);
|
||||
$page['formlogo'] = topage($logo);
|
||||
}
|
||||
if ($duplicate_name) {
|
||||
$page['errors'][] = getlocal("page.group.duplicate_name");
|
||||
}
|
||||
|
||||
} else if (isset($_GET['gid'])) {
|
||||
$groupid = verifyparam('gid', "/^\d{1,9}$/");
|
||||
$group = group_by_id($groupid);
|
||||
if (count($page['errors']) == 0) {
|
||||
if (!$group_id) {
|
||||
$new_dep = create_group(array(
|
||||
'name' => $name,
|
||||
'description' => $description,
|
||||
'commonname' => $common_name,
|
||||
'commondescription' => $common_description,
|
||||
'email' => $email,
|
||||
'weight' => $weight,
|
||||
'parent' => $parent_group,
|
||||
'title' => $title,
|
||||
'chattitle' => $chat_title,
|
||||
'hosturl' => $host_url,
|
||||
'logo' => $logo));
|
||||
header("Location: " . MIBEW_WEB_ROOT . "/operator/groupmembers.php?gid=" . intval($new_dep['groupid']));
|
||||
exit;
|
||||
} else {
|
||||
update_group(array(
|
||||
'id' => $group_id,
|
||||
'name' => $name,
|
||||
'description' => $description,
|
||||
'commonname' => $common_name,
|
||||
'commondescription' => $common_description,
|
||||
'email' => $email,
|
||||
'weight' => $weight,
|
||||
'parent' => $parent_group,
|
||||
'title' => $title,
|
||||
'chattitle' => $chat_title,
|
||||
'hosturl' => $host_url,
|
||||
'logo' => $logo));
|
||||
header("Location: " . MIBEW_WEB_ROOT . "/operator/group.php?gid=" . intval($group_id) . "&stored");
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
$page['formname'] = to_page($name);
|
||||
$page['formdescription'] = to_page($description);
|
||||
$page['formcommonname'] = to_page($common_name);
|
||||
$page['formcommondescription'] = to_page($common_description);
|
||||
$page['formemail'] = to_page($email);
|
||||
$page['formweight'] = to_page($weight);
|
||||
$page['formparentgroup'] = to_page($parent_group);
|
||||
$page['grid'] = to_page($group_id);
|
||||
$page['formtitle'] = to_page($title);
|
||||
$page['formchattitle'] = to_page($chat_title);
|
||||
$page['formhosturl'] = to_page($host_url);
|
||||
$page['formlogo'] = to_page($logo);
|
||||
}
|
||||
} elseif (isset($_GET['gid'])) {
|
||||
$group_id = verify_param('gid', "/^\d{1,9}$/");
|
||||
$group = group_by_id($group_id);
|
||||
|
||||
if (!$group) {
|
||||
$page['errors'][] = getlocal("page.group.no_such");
|
||||
$page['grid'] = topage($groupid);
|
||||
} else {
|
||||
$page['formname'] = topage($group['vclocalname']);
|
||||
$page['formdescription'] = topage($group['vclocaldescription']);
|
||||
$page['formcommonname'] = topage($group['vccommonname']);
|
||||
$page['formcommondescription'] = topage($group['vccommondescription']);
|
||||
$page['formemail'] = topage($group['vcemail']);
|
||||
$page['formweight'] = topage($group['iweight']);
|
||||
$page['formparentgroup'] = topage($group['parent']);
|
||||
$page['grid'] = topage($group['groupid']);
|
||||
$page['formtitle'] = topage($group['vctitle']);
|
||||
$page['formchattitle'] = topage($group['vcchattitle']);
|
||||
$page['formhosturl'] = topage($group['vchosturl']);
|
||||
$page['formlogo'] = topage($group['vclogo']);
|
||||
}
|
||||
if (!$group) {
|
||||
$page['errors'][] = getlocal("page.group.no_such");
|
||||
$page['grid'] = to_page($group_id);
|
||||
} else {
|
||||
$page['formname'] = to_page($group['vclocalname']);
|
||||
$page['formdescription'] = to_page($group['vclocaldescription']);
|
||||
$page['formcommonname'] = to_page($group['vccommonname']);
|
||||
$page['formcommondescription'] = to_page($group['vccommondescription']);
|
||||
$page['formemail'] = to_page($group['vcemail']);
|
||||
$page['formweight'] = to_page($group['iweight']);
|
||||
$page['formparentgroup'] = to_page($group['parent']);
|
||||
$page['grid'] = to_page($group['groupid']);
|
||||
$page['formtitle'] = to_page($group['vctitle']);
|
||||
$page['formchattitle'] = to_page($group['vcchattitle']);
|
||||
$page['formhosturl'] = to_page($group['vchosturl']);
|
||||
$page['formlogo'] = to_page($group['vclogo']);
|
||||
}
|
||||
}
|
||||
|
||||
$page['stored'] = isset($_GET['stored']);
|
||||
$page['availableParentGroups'] = get_available_parent_groups($groupid);
|
||||
$page['availableParentGroups'] = get_available_parent_groups($group_id);
|
||||
$page['title'] = getlocal("page.group.title");
|
||||
$page['menuid'] = "groups";
|
||||
|
||||
$page = array_merge(
|
||||
$page,
|
||||
prepare_menu($operator)
|
||||
);
|
||||
$page = array_merge($page, prepare_menu($operator));
|
||||
|
||||
$page['tabs'] = setup_group_settings_tabs($groupid, 0);
|
||||
$page['tabs'] = setup_group_settings_tabs($group_id, 0);
|
||||
|
||||
$page_style = new PageStyle(PageStyle::currentStyle());
|
||||
$page_style->render('group', $page);
|
||||
|
||||
?>
|
@ -19,56 +19,50 @@
|
||||
use Mibew\Style\PageStyle;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(dirname(dirname(__FILE__)).'/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/groups.php');
|
||||
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/groups.php');
|
||||
|
||||
$operator = check_login();
|
||||
csrfchecktoken();
|
||||
csrf_check_token();
|
||||
|
||||
$groupid = verifyparam("gid", "/^\d{1,9}$/");
|
||||
$page = array('groupid' => $groupid);
|
||||
$group_id = verify_param("gid", "/^\d{1,9}$/");
|
||||
$page = array('groupid' => $group_id);
|
||||
$page['operators'] = get_operators_list(array());
|
||||
$page['errors'] = array();
|
||||
|
||||
$group = group_by_id($groupid);
|
||||
$group = group_by_id($group_id);
|
||||
|
||||
if (!$group) {
|
||||
$page['errors'][] = getlocal("page.group.no_such");
|
||||
$page['errors'][] = getlocal("page.group.no_such");
|
||||
} elseif (isset($_POST['gid'])) {
|
||||
|
||||
} else if (isset($_POST['gid'])) {
|
||||
$new_members = array();
|
||||
foreach ($page['operators'] as $op) {
|
||||
if (verify_param("op" . $op['operatorid'], "/^on$/", "") == "on") {
|
||||
$new_members[] = $op['operatorid'];
|
||||
}
|
||||
}
|
||||
|
||||
$new_members = array();
|
||||
foreach ($page['operators'] as $op) {
|
||||
if (verifyparam("op" . $op['operatorid'], "/^on$/", "") == "on") {
|
||||
$new_members[] = $op['operatorid'];
|
||||
}
|
||||
}
|
||||
|
||||
update_group_members($groupid, $new_members);
|
||||
header("Location: " . MIBEW_WEB_ROOT . "/operator/groupmembers.php?gid=" . intval($groupid) . "&stored");
|
||||
exit;
|
||||
update_group_members($group_id, $new_members);
|
||||
header("Location: " . MIBEW_WEB_ROOT . "/operator/groupmembers.php?gid=" . intval($group_id) . "&stored");
|
||||
exit;
|
||||
}
|
||||
|
||||
$page['formop'] = array();
|
||||
$page['currentgroup'] = $group ? topage(htmlspecialchars($group['vclocalname'])) : "";
|
||||
$page['currentgroup'] = $group ? to_page(htmlspecialchars($group['vclocalname'])) : "";
|
||||
|
||||
foreach (get_group_members($groupid) as $rel) {
|
||||
$page['formop'][] = $rel['operatorid'];
|
||||
foreach (get_group_members($group_id) as $rel) {
|
||||
$page['formop'][] = $rel['operatorid'];
|
||||
}
|
||||
|
||||
$page['stored'] = isset($_GET['stored']);
|
||||
$page['title'] = getlocal("page.groupmembers.title");
|
||||
$page['menuid'] = "groups";
|
||||
|
||||
$page = array_merge(
|
||||
$page,
|
||||
prepare_menu($operator)
|
||||
);
|
||||
$page = array_merge($page, prepare_menu($operator));
|
||||
|
||||
$page['tabs'] = setup_group_settings_tabs($groupid, 1);
|
||||
$page['tabs'] = setup_group_settings_tabs($group_id, 1);
|
||||
|
||||
$page_style = new PageStyle(PageStyle::currentStyle());
|
||||
$page_style->render('groupmembers', $page);
|
||||
|
||||
?>
|
@ -20,61 +20,56 @@ use Mibew\Database;
|
||||
use Mibew\Style\PageStyle;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(dirname(dirname(__FILE__)).'/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/groups.php');
|
||||
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/groups.php');
|
||||
|
||||
$operator = check_login();
|
||||
csrfchecktoken();
|
||||
csrf_check_token();
|
||||
|
||||
if (isset($_GET['act']) && $_GET['act'] == 'del') {
|
||||
|
||||
$groupid = isset($_GET['gid']) ? $_GET['gid'] : "";
|
||||
$group_id = isset($_GET['gid']) ? $_GET['gid'] : "";
|
||||
|
||||
if (!preg_match("/^\d+$/", $groupid)) {
|
||||
$page['errors'][] = getlocal("page.groups.error.cannot_delete");
|
||||
}
|
||||
if (!preg_match("/^\d+$/", $group_id)) {
|
||||
$page['errors'][] = getlocal("page.groups.error.cannot_delete");
|
||||
}
|
||||
|
||||
if (!is_capable(CAN_ADMINISTRATE, $operator)) {
|
||||
$page['errors'][] = getlocal("page.groups.error.forbidden_remove");
|
||||
}
|
||||
if (!is_capable(CAN_ADMINISTRATE, $operator)) {
|
||||
$page['errors'][] = getlocal("page.groups.error.forbidden_remove");
|
||||
}
|
||||
|
||||
if (count($page['errors']) == 0) {
|
||||
$db = Database::getInstance();
|
||||
$db->query("delete from {chatgroup} where groupid = ?", array($groupid));
|
||||
$db->query("delete from {chatgroupoperator} where groupid = ?", array($groupid));
|
||||
$db->query("update {chatthread} set groupid = 0 where groupid = ?",array($groupid));
|
||||
header("Location: " . MIBEW_WEB_ROOT . "/operator/groups.php");
|
||||
exit;
|
||||
}
|
||||
if (count($page['errors']) == 0) {
|
||||
$db = Database::getInstance();
|
||||
$db->query("delete from {chatgroup} where groupid = ?", array($group_id));
|
||||
$db->query("delete from {chatgroupoperator} where groupid = ?", array($group_id));
|
||||
$db->query("update {chatthread} set groupid = 0 where groupid = ?", array($group_id));
|
||||
header("Location: " . MIBEW_WEB_ROOT . "/operator/groups.php");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$page = array();
|
||||
$sort['by'] = verifyparam("sortby", "/^(name|lastseen|weight)$/", "name");
|
||||
$sort['desc'] = (verifyparam("sortdirection", "/^(desc|asc)$/", "desc") == "desc");
|
||||
$sort['by'] = verify_param("sortby", "/^(name|lastseen|weight)$/", "name");
|
||||
$sort['desc'] = (verify_param("sortdirection", "/^(desc|asc)$/", "desc") == "desc");
|
||||
$page['groups'] = get_sorted_groups($sort);
|
||||
$page['formsortby'] = $sort['by'];
|
||||
$page['formsortdirection'] = $sort['desc']?'desc':'asc';
|
||||
$page['formsortdirection'] = $sort['desc'] ? 'desc' : 'asc';
|
||||
$page['canmodify'] = is_capable(CAN_ADMINISTRATE, $operator);
|
||||
$page['availableOrders'] = array(
|
||||
array('id' => 'name', 'name' => getlocal('form.field.groupname')),
|
||||
array('id' => 'lastseen', 'name' => getlocal('page_agents.status')),
|
||||
array('id' => 'weight', 'name' => getlocal('page.groups.weight'))
|
||||
array('id' => 'name', 'name' => getlocal('form.field.groupname')),
|
||||
array('id' => 'lastseen', 'name' => getlocal('page_agents.status')),
|
||||
array('id' => 'weight', 'name' => getlocal('page.groups.weight')),
|
||||
);
|
||||
$page['availableDirections'] = array(
|
||||
array('id' => 'desc', 'name' => getlocal('page.groups.sortdirection.desc')),
|
||||
array('id' => 'asc', 'name' => getlocal('page.groups.sortdirection.asc')),
|
||||
array('id' => 'desc', 'name' => getlocal('page.groups.sortdirection.desc')),
|
||||
array('id' => 'asc', 'name' => getlocal('page.groups.sortdirection.asc')),
|
||||
);
|
||||
|
||||
$page['title'] = getlocal("page.groups.title");
|
||||
$page['menuid'] = "groups";
|
||||
|
||||
$page = array_merge(
|
||||
$page,
|
||||
prepare_menu($operator)
|
||||
);
|
||||
$page = array_merge($page, prepare_menu($operator));
|
||||
|
||||
$page_style = new PageStyle(PageStyle::currentStyle());
|
||||
$page_style->render('groups', $page);
|
||||
|
||||
?>
|
@ -21,12 +21,13 @@ use Mibew\Thread;
|
||||
use Mibew\Style\PageStyle;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(dirname(dirname(__FILE__)).'/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/chat.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/userinfo.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/pagination.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/cron.php');
|
||||
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/chat.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/userinfo.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/pagination.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/cron.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/track.php');
|
||||
|
||||
$operator = check_login();
|
||||
force_password($operator);
|
||||
@ -36,109 +37,107 @@ setlocale(LC_TIME, getstring("time.locale"));
|
||||
$page = array();
|
||||
$query = isset($_GET['q']) ? myiconv(getoutputenc(), MIBEW_ENCODING, $_GET['q']) : false;
|
||||
|
||||
$searchType = verifyparam('type', '/^(all|message|operator|visitor)$/', 'all');
|
||||
$searchInSystemMessages = (verifyparam('insystemmessages', '/^on$/', 'off') == 'on') || !$query;
|
||||
$search_type = verify_param('type', '/^(all|message|operator|visitor)$/', 'all');
|
||||
$search_in_system_messages = (verify_param('insystemmessages', '/^on$/', 'off') == 'on') || !$query;
|
||||
|
||||
if ($query !== false) {
|
||||
$db = Database::getInstance();
|
||||
$groups = $db->query(
|
||||
"select {chatgroup}.groupid as groupid, vclocalname " .
|
||||
"from {chatgroup} order by vclocalname",
|
||||
NULL,
|
||||
array('return_rows' => Database::RETURN_ALL_ROWS)
|
||||
);
|
||||
$db = Database::getInstance();
|
||||
$groups = $db->query(
|
||||
("SELECT {chatgroup}.groupid AS groupid, vclocalname " .
|
||||
"FROM {chatgroup} " .
|
||||
"ORDER BY vclocalname"),
|
||||
null,
|
||||
array('return_rows' => Database::RETURN_ALL_ROWS)
|
||||
);
|
||||
|
||||
$groupName = array();
|
||||
foreach ($groups as $group) {
|
||||
$groupName[$group['groupid']] = $group['vclocalname'];
|
||||
}
|
||||
$page['groupName'] = $groupName;
|
||||
$group_name = array();
|
||||
foreach ($groups as $group) {
|
||||
$group_name[$group['groupid']] = $group['vclocalname'];
|
||||
}
|
||||
$page['groupName'] = $group_name;
|
||||
|
||||
$values = array(
|
||||
':query' => "%{$query}%",
|
||||
':invitation_accepted' => Thread::INVITATION_ACCEPTED,
|
||||
':invitation_not_invited' => Thread::INVITATION_NOT_INVITED
|
||||
);
|
||||
$values = array(
|
||||
':query' => "%{$query}%",
|
||||
':invitation_accepted' => Thread::INVITATION_ACCEPTED,
|
||||
':invitation_not_invited' => Thread::INVITATION_NOT_INVITED,
|
||||
);
|
||||
|
||||
$searchConditions = array();
|
||||
if ($searchType == 'message' || $searchType == 'all') {
|
||||
$searchConditions[] = "({chatmessage}.tmessage LIKE :query" .
|
||||
($searchInSystemMessages?'':" AND ({chatmessage}.ikind = :kind_user OR {chatmessage}.ikind = :kind_agent)") .
|
||||
")";
|
||||
if (! $searchInSystemMessages) {
|
||||
$values[':kind_user'] = Thread::KIND_USER;
|
||||
$values[':kind_agent'] = Thread::KIND_AGENT;
|
||||
}
|
||||
}
|
||||
if ($searchType == 'operator' || $searchType == 'all') {
|
||||
$searchConditions[] = "({chatthread}.agentName LIKE :query)";
|
||||
}
|
||||
if ($searchType == 'visitor' || $searchType == 'all') {
|
||||
$searchConditions[] = "({chatthread}.userName LIKE :query)";
|
||||
$searchConditions[] = "({chatthread}.remote LIKE :query)";
|
||||
}
|
||||
$search_conditions = array();
|
||||
if ($search_type == 'message' || $search_type == 'all') {
|
||||
$search_conditions[] = "({chatmessage}.tmessage LIKE :query"
|
||||
. ($search_in_system_messages
|
||||
? ''
|
||||
: " AND ({chatmessage}.ikind = :kind_user OR {chatmessage}.ikind = :kind_agent)")
|
||||
. ")";
|
||||
if (!$search_in_system_messages) {
|
||||
$values[':kind_user'] = Thread::KIND_USER;
|
||||
$values[':kind_agent'] = Thread::KIND_AGENT;
|
||||
}
|
||||
}
|
||||
if ($search_type == 'operator' || $search_type == 'all') {
|
||||
$search_conditions[] = "({chatthread}.agentName LIKE :query)";
|
||||
}
|
||||
if ($search_type == 'visitor' || $search_type == 'all') {
|
||||
$search_conditions[] = "({chatthread}.userName LIKE :query)";
|
||||
$search_conditions[] = "({chatthread}.remote LIKE :query)";
|
||||
}
|
||||
|
||||
// Load threads
|
||||
list($threads_count) = $db->query(
|
||||
"SELECT COUNT(DISTINCT {chatthread}.dtmcreated) " .
|
||||
"FROM {chatthread}, {chatmessage} " .
|
||||
"WHERE {chatmessage}.threadid = {chatthread}.threadid " .
|
||||
"AND ({chatthread}.invitationstate = :invitation_accepted " .
|
||||
"OR {chatthread}.invitationstate = :invitation_not_invited) " .
|
||||
"AND (" . implode(' OR ', $searchConditions) . ")",
|
||||
$values,
|
||||
array(
|
||||
'return_rows' => Database::RETURN_ONE_ROW,
|
||||
'fetch_type' => Database::FETCH_NUM
|
||||
)
|
||||
);
|
||||
// Load threads
|
||||
list($threads_count) = $db->query(
|
||||
("SELECT COUNT(DISTINCT {chatthread}.dtmcreated) "
|
||||
. "FROM {chatthread}, {chatmessage} "
|
||||
. "WHERE {chatmessage}.threadid = {chatthread}.threadid "
|
||||
. "AND ({chatthread}.invitationstate = :invitation_accepted "
|
||||
. "OR {chatthread}.invitationstate = :invitation_not_invited) "
|
||||
. "AND (" . implode(' OR ', $search_conditions) . ")"),
|
||||
$values,
|
||||
array(
|
||||
'return_rows' => Database::RETURN_ONE_ROW,
|
||||
'fetch_type' => Database::FETCH_NUM,
|
||||
)
|
||||
);
|
||||
|
||||
$pagination_info = pagination_info($threads_count);
|
||||
$pagination_info = pagination_info($threads_count);
|
||||
|
||||
if ($threads_count && $pagination_info) {
|
||||
$page['pagination'] = $pagination_info;
|
||||
if ($threads_count && $pagination_info) {
|
||||
$page['pagination'] = $pagination_info;
|
||||
|
||||
$limit_start = intval($pagination_info['start']);
|
||||
$limit_end = intval($pagination_info['end'] - $pagination_info['start']);
|
||||
$limit_start = intval($pagination_info['start']);
|
||||
$limit_end = intval($pagination_info['end'] - $pagination_info['start']);
|
||||
|
||||
$threads_list = $db->query(
|
||||
"SELECT DISTINCT {chatthread}.* " .
|
||||
"FROM {chatthread}, {chatmessage} " .
|
||||
"WHERE {chatmessage}.threadid = {chatthread}.threadid " .
|
||||
"AND ({chatthread}.invitationstate = :invitation_accepted " .
|
||||
"OR {chatthread}.invitationstate = :invitation_not_invited) " .
|
||||
"AND (" . implode(' OR ', $searchConditions) . ") " .
|
||||
"ORDER BY {chatthread}.dtmcreated DESC " .
|
||||
"LIMIT " . $limit_start . ", " .$limit_end,
|
||||
$values,
|
||||
array('return_rows' => Database::RETURN_ALL_ROWS)
|
||||
);
|
||||
$threads_list = $db->query(
|
||||
("SELECT DISTINCT {chatthread}.* "
|
||||
. "FROM {chatthread}, {chatmessage} "
|
||||
. "WHERE {chatmessage}.threadid = {chatthread}.threadid "
|
||||
. "AND ({chatthread}.invitationstate = :invitation_accepted "
|
||||
. "OR {chatthread}.invitationstate = :invitation_not_invited) "
|
||||
. "AND (" . implode(' OR ', $search_conditions) . ") "
|
||||
. "ORDER BY {chatthread}.dtmcreated DESC "
|
||||
. "LIMIT " . $limit_start . ", " . $limit_end),
|
||||
$values,
|
||||
array('return_rows' => Database::RETURN_ALL_ROWS)
|
||||
);
|
||||
|
||||
foreach ($threads_list as $item) {
|
||||
$page['pagination.items'][] = Thread::createFromDbInfo($item);
|
||||
}
|
||||
} else {
|
||||
$page['pagination'] = false;
|
||||
$page['pagination.items'] = false;
|
||||
}
|
||||
foreach ($threads_list as $item) {
|
||||
$page['pagination.items'][] = Thread::createFromDbInfo($item);
|
||||
}
|
||||
} else {
|
||||
$page['pagination'] = false;
|
||||
$page['pagination.items'] = false;
|
||||
}
|
||||
|
||||
$page['formq'] = topage($query);
|
||||
$page['formq'] = to_page($query);
|
||||
} else {
|
||||
$page['pagination'] = false;
|
||||
$page['pagination.items'] = false;
|
||||
$page['pagination'] = false;
|
||||
$page['pagination.items'] = false;
|
||||
}
|
||||
|
||||
$page['formtype'] = $searchType;
|
||||
$page['forminsystemmessages'] = $searchInSystemMessages;
|
||||
$page['formtype'] = $search_type;
|
||||
$page['forminsystemmessages'] = $search_in_system_messages;
|
||||
$page['title'] = getlocal("page_analysis.search.title");
|
||||
$page['menuid'] = "history";
|
||||
|
||||
$page = array_merge(
|
||||
$page,
|
||||
prepare_menu($operator)
|
||||
);
|
||||
$page = array_merge($page, prepare_menu($operator));
|
||||
|
||||
$page_style = new PageStyle(PageStyle::currentStyle());
|
||||
$page_style->render('thread_search', $page);
|
||||
|
||||
?>
|
@ -20,34 +20,29 @@ use Mibew\Settings;
|
||||
use Mibew\Style\PageStyle;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(dirname(dirname(__FILE__)).'/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/operator.php');
|
||||
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/operator.php');
|
||||
|
||||
$operator = check_login();
|
||||
force_password($operator);
|
||||
|
||||
$isonline = is_operator_online($operator['operatorid']);
|
||||
$is_online = is_operator_online($operator['operatorid']);
|
||||
|
||||
$page = array(
|
||||
'version' => MIBEW_VERSION,
|
||||
'localeLinks' => get_locale_links(MIBEW_WEB_ROOT . "/operator/index.php"),
|
||||
'needUpdate' => Settings::get('dbversion') != DB_VERSION,
|
||||
'needChangePassword' => check_password_hash($operator['vclogin'], '', $operator['vcpassword']),
|
||||
'profilePage' => MIBEW_WEB_ROOT . "/operator/operator.php?op=".$operator['operatorid'],
|
||||
'updateWizard' => MIBEW_WEB_ROOT . "/install/",
|
||||
'newFeatures' => Settings::get('featuresversion') != FEATURES_VERSION,
|
||||
'featuresPage' => MIBEW_WEB_ROOT . "/operator/features.php",
|
||||
'isOnline' => $isonline,
|
||||
'title' => getlocal("topMenu.admin"),
|
||||
'menuid' => "main",
|
||||
'version' => MIBEW_VERSION,
|
||||
'localeLinks' => get_locale_links(MIBEW_WEB_ROOT . "/operator/index.php"),
|
||||
'needUpdate' => Settings::get('dbversion') != DB_VERSION,
|
||||
'needChangePassword' => check_password_hash($operator['vclogin'], '', $operator['vcpassword']),
|
||||
'profilePage' => MIBEW_WEB_ROOT . "/operator/operator.php?op=" . $operator['operatorid'],
|
||||
'updateWizard' => MIBEW_WEB_ROOT . "/install/",
|
||||
'newFeatures' => Settings::get('featuresversion') != FEATURES_VERSION,
|
||||
'featuresPage' => MIBEW_WEB_ROOT . "/operator/features.php",
|
||||
'isOnline' => $is_online,
|
||||
'title' => getlocal("topMenu.admin"),
|
||||
'menuid' => "main",
|
||||
);
|
||||
|
||||
$page = array_merge(
|
||||
$page,
|
||||
prepare_menu($operator)
|
||||
);
|
||||
$page = array_merge($page, prepare_menu($operator));
|
||||
|
||||
$page_style = new PageStyle(PageStyle::currentStyle());
|
||||
$page_style->render('menu', $page);
|
||||
|
||||
?>
|
@ -15,11 +15,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
require_once(dirname(dirname(__FILE__)).'/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/invitation.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/operator.php');
|
||||
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/invitation.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/operator.php');
|
||||
|
||||
$processor = \Mibew\RequestProcessor\InviteProcessor::getInstance();
|
||||
$processor->receiveRequest($_POST['data']);
|
||||
|
||||
?>
|
@ -20,36 +20,33 @@ use Mibew\Style\InvitationStyle;
|
||||
use Mibew\Style\PageStyle;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(dirname(dirname(__FILE__)).'/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/pagination.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/groups.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/settings.php');
|
||||
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/pagination.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/groups.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/settings.php');
|
||||
|
||||
$operator = check_login();
|
||||
|
||||
$stylelist = InvitationStyle::availableStyles();
|
||||
$style_list = InvitationStyle::availableStyles();
|
||||
|
||||
$preview = verifyparam("preview", "/^\w+$/", "default");
|
||||
if (!in_array($preview, $stylelist)) {
|
||||
$preview = $stylelist[0];
|
||||
$preview = verify_param("preview", "/^\w+$/", "default");
|
||||
if (!in_array($preview, $style_list)) {
|
||||
$preview = $style_list[0];
|
||||
}
|
||||
|
||||
$page['formpreview'] = $preview;
|
||||
$page['preview'] = $preview;
|
||||
$page['availablePreviews'] = $stylelist;
|
||||
$page['operatorName'] = (empty($operator['vclocalname'])?$operator['vccommonname']:$operator['vclocalname']);
|
||||
$page['availablePreviews'] = $style_list;
|
||||
$page['operatorName'] = (empty($operator['vclocalname'])
|
||||
? $operator['vccommonname']
|
||||
: $operator['vclocalname']);
|
||||
$page['title'] = getlocal("page.preview.title");
|
||||
$page['menuid'] = "settings";
|
||||
|
||||
$page = array_merge(
|
||||
$page,
|
||||
prepare_menu($operator)
|
||||
);
|
||||
$page = array_merge($page, prepare_menu($operator));
|
||||
|
||||
$page['tabs'] = setup_settings_tabs(5);
|
||||
|
||||
$page_style = new PageStyle(PageStyle::currentStyle());
|
||||
$page_style->render('invitation_themes', $page);
|
||||
|
||||
?>
|
@ -15,24 +15,23 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
require_once(dirname(dirname(__FILE__)).'/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/invitation.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/track.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/operator.php');
|
||||
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/invitation.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/chat.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/track.php');
|
||||
|
||||
$operator = check_login();
|
||||
|
||||
$visitorid = verifyparam("visitor", "/^\d{1,8}$/");
|
||||
$visitor_id = verify_param("visitor", "/^\d{1,8}$/");
|
||||
|
||||
$thread = invitation_invite($visitorid, $operator);
|
||||
$thread = invitation_invite($visitor_id, $operator);
|
||||
if (!$thread) {
|
||||
die("Invitation failed!");
|
||||
}
|
||||
|
||||
// Open chat window for operator
|
||||
$redirect_to = MIBEW_WEB_ROOT .
|
||||
'/operator/agent.php?thread=' . intval($thread->id) .
|
||||
'&token=' . urlencode($thread->lastToken);
|
||||
$redirect_to = MIBEW_WEB_ROOT
|
||||
. '/operator/agent.php?thread=' . intval($thread->id)
|
||||
. '&token=' . urlencode($thread->lastToken);
|
||||
header('Location: ' . $redirect_to);
|
||||
|
||||
?>
|
@ -19,44 +19,47 @@
|
||||
use Mibew\Style\PageStyle;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(dirname(dirname(__FILE__)).'/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/operator.php');
|
||||
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/operator.php');
|
||||
|
||||
$page = array(
|
||||
'formisRemember' => true,
|
||||
'version' => MIBEW_VERSION,
|
||||
'errors' => array(),
|
||||
'formisRemember' => true,
|
||||
'version' => MIBEW_VERSION,
|
||||
'errors' => array(),
|
||||
);
|
||||
|
||||
if (isset($_POST['login']) && isset($_POST['password'])) {
|
||||
$login = getparam('login');
|
||||
$password = getparam('password');
|
||||
$remember = isset($_POST['isRemember']) && $_POST['isRemember'] == "on";
|
||||
$login = get_param('login');
|
||||
$password = get_param('password');
|
||||
$remember = isset($_POST['isRemember']) && $_POST['isRemember'] == "on";
|
||||
|
||||
$operator = operator_by_login($login);
|
||||
if ($operator && isset($operator['vcpassword']) && check_password_hash($operator['vclogin'], $password, $operator['vcpassword']) && !operator_is_disabled($operator)) {
|
||||
$operator = operator_by_login($login);
|
||||
$operator_can_login = $operator
|
||||
&& isset($operator['vcpassword'])
|
||||
&& check_password_hash($operator['vclogin'], $password, $operator['vcpassword'])
|
||||
&& !operator_is_disabled($operator);
|
||||
|
||||
$target = $password == ''
|
||||
? MIBEW_WEB_ROOT . "/operator/operator.php?op=" . intval($operator['operatorid'])
|
||||
: (isset($_SESSION['backpath'])
|
||||
? $_SESSION['backpath']
|
||||
: MIBEW_WEB_ROOT . "/operator/index.php");
|
||||
if ($operator_can_login) {
|
||||
$target = $password == ''
|
||||
? MIBEW_WEB_ROOT . "/operator/operator.php?op=" . intval($operator['operatorid'])
|
||||
: (isset($_SESSION['backpath']) ? $_SESSION['backpath'] : MIBEW_WEB_ROOT . "/operator/index.php");
|
||||
|
||||
login_operator($operator, $remember, is_secure_request());
|
||||
header("Location: $target");
|
||||
exit;
|
||||
} else {
|
||||
if (operator_is_disabled($operator)) {
|
||||
$page['errors'][] = getlocal('page_login.operator.disabled');
|
||||
} else {
|
||||
$page['errors'][] = getlocal("page_login.error");
|
||||
}
|
||||
$page['formlogin'] = $login;
|
||||
}
|
||||
} else if(isset($_GET['login'])) {
|
||||
$login = getgetparam('login');
|
||||
if (preg_match("/^(\w{1,15})$/", $login))
|
||||
$page['formlogin'] = $login;
|
||||
login_operator($operator, $remember, is_secure_request());
|
||||
header("Location: $target");
|
||||
exit;
|
||||
} else {
|
||||
if (operator_is_disabled($operator)) {
|
||||
$page['errors'][] = getlocal('page_login.operator.disabled');
|
||||
} else {
|
||||
$page['errors'][] = getlocal("page_login.error");
|
||||
}
|
||||
$page['formlogin'] = $login;
|
||||
}
|
||||
} elseif (isset($_GET['login'])) {
|
||||
$login = get_get_param('login');
|
||||
if (preg_match("/^(\w{1,15})$/", $login)) {
|
||||
$page['formlogin'] = $login;
|
||||
}
|
||||
}
|
||||
|
||||
$page['localeLinks'] = get_locale_links(MIBEW_WEB_ROOT . "/operator/login.php");
|
||||
@ -67,5 +70,3 @@ $page['fixedwrap'] = true;
|
||||
|
||||
$page_style = new PageStyle(PageStyle::currentStyle());
|
||||
$page_style->render('login', $page);
|
||||
|
||||
?>
|
@ -15,11 +15,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
require_once(dirname(dirname(__FILE__)).'/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/operator.php');
|
||||
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/operator.php');
|
||||
|
||||
logout_operator();
|
||||
|
||||
header("Location: " . MIBEW_WEB_ROOT . "/operator/login.php");
|
||||
exit;
|
||||
?>
|
@ -19,155 +19,158 @@
|
||||
use Mibew\Style\PageStyle;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(dirname(dirname(__FILE__)).'/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/operator_settings.php');
|
||||
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/operator_settings.php');
|
||||
|
||||
$operator = check_login();
|
||||
csrfchecktoken();
|
||||
csrf_check_token();
|
||||
|
||||
$page = array(
|
||||
'opid' => '',
|
||||
'errors' => array(),
|
||||
'opid' => '',
|
||||
'errors' => array(),
|
||||
);
|
||||
|
||||
$opId = '';
|
||||
$op_id = '';
|
||||
|
||||
if ((isset($_POST['login']) || !is_capable(CAN_ADMINISTRATE, $operator)) && isset($_POST['password'])) {
|
||||
$opId = verifyparam("opid", "/^(\d{1,9})?$/", "");
|
||||
if (is_capable(CAN_ADMINISTRATE, $operator)) {
|
||||
$login = getparam('login');
|
||||
} else {
|
||||
$login = $operator['vclogin'];
|
||||
}
|
||||
$email = getparam('email');
|
||||
$password = getparam('password');
|
||||
$passwordConfirm = getparam('passwordConfirm');
|
||||
$localname = getparam('name');
|
||||
$commonname = getparam('commonname');
|
||||
$code = getparam('code');
|
||||
$op_id = verify_param("opid", "/^(\d{1,9})?$/", "");
|
||||
if (is_capable(CAN_ADMINISTRATE, $operator)) {
|
||||
$login = get_param('login');
|
||||
} else {
|
||||
$login = $operator['vclogin'];
|
||||
}
|
||||
$email = get_param('email');
|
||||
$password = get_param('password');
|
||||
$password_confirm = get_param('passwordConfirm');
|
||||
$local_name = get_param('name');
|
||||
$common_name = get_param('commonname');
|
||||
$code = get_param('code');
|
||||
|
||||
if (!$localname)
|
||||
$page['errors'][] = no_field("form.field.agent_name");
|
||||
if (!$local_name) {
|
||||
$page['errors'][] = no_field("form.field.agent_name");
|
||||
}
|
||||
|
||||
if (!$commonname)
|
||||
$page['errors'][] = no_field("form.field.agent_commonname");
|
||||
if (!$common_name) {
|
||||
$page['errors'][] = no_field("form.field.agent_commonname");
|
||||
}
|
||||
|
||||
if (!$login) {
|
||||
$page['errors'][] = no_field("form.field.login");
|
||||
} else if (!preg_match("/^[\w_\.]+$/", $login)) {
|
||||
$page['errors'][] = getlocal("page_agent.error.wrong_login");
|
||||
}
|
||||
if (!$login) {
|
||||
$page['errors'][] = no_field("form.field.login");
|
||||
} elseif (!preg_match("/^[\w_\.]+$/", $login)) {
|
||||
$page['errors'][] = getlocal("page_agent.error.wrong_login");
|
||||
}
|
||||
|
||||
if ($email == '' || !is_valid_email($email)) {
|
||||
$page['errors'][] = wrong_field("form.field.mail");
|
||||
}
|
||||
if ($email == '' || !is_valid_email($email)) {
|
||||
$page['errors'][] = wrong_field("form.field.mail");
|
||||
}
|
||||
|
||||
if ($code != '' && (! preg_match("/^[A-z0-9_]+$/", $code))) {
|
||||
$page['errors'][] = getlocal("page_agent.error.wrong_agent_code");
|
||||
}
|
||||
if ($code != '' && (!preg_match("/^[A-z0-9_]+$/", $code))) {
|
||||
$page['errors'][] = getlocal("page_agent.error.wrong_agent_code");
|
||||
}
|
||||
|
||||
if (!$opId && !$password)
|
||||
$page['errors'][] = no_field("form.field.password");
|
||||
if (!$op_id && !$password) {
|
||||
$page['errors'][] = no_field("form.field.password");
|
||||
}
|
||||
|
||||
if ($password != $passwordConfirm)
|
||||
$page['errors'][] = getlocal("my_settings.error.password_match");
|
||||
if ($password != $password_confirm) {
|
||||
$page['errors'][] = getlocal("my_settings.error.password_match");
|
||||
}
|
||||
|
||||
$existing_operator = operator_by_login($login);
|
||||
if ((!$opId && $existing_operator) ||
|
||||
($opId && $existing_operator && $opId != $existing_operator['operatorid']))
|
||||
$page['errors'][] = getlocal("page_agent.error.duplicate_login");
|
||||
$existing_operator = operator_by_login($login);
|
||||
$duplicate_login = (!$op_id && $existing_operator)
|
||||
|| ($op_id
|
||||
&& $existing_operator
|
||||
&& $op_id != $existing_operator['operatorid']);
|
||||
if ($duplicate_login) {
|
||||
$page['errors'][] = getlocal("page_agent.error.duplicate_login");
|
||||
}
|
||||
|
||||
// Check if operator with specified email already exists in the database
|
||||
$existing_operator = operator_by_email($email);
|
||||
if (
|
||||
// Create operator with email already in database
|
||||
(!$opId && $existing_operator) ||
|
||||
// Update operator email to existing one
|
||||
($opId && $existing_operator && $opId != $existing_operator['operatorid'])
|
||||
) {
|
||||
$page['errors'][] = getlocal("page_agent.error.duplicate_email");
|
||||
}
|
||||
// Check if operator with specified email already exists in the database
|
||||
$existing_operator = operator_by_email($email);
|
||||
$duplicate_email =
|
||||
// Create operator with email already in database
|
||||
(!$op_id && $existing_operator)
|
||||
// Update operator email to existing one
|
||||
|| ($op_id
|
||||
&& $existing_operator
|
||||
&& $op_id != $existing_operator['operatorid']);
|
||||
if ($duplicate_email) {
|
||||
$page['errors'][] = getlocal("page_agent.error.duplicate_email");
|
||||
}
|
||||
|
||||
$canmodify = ($opId == $operator['operatorid'] && is_capable(CAN_MODIFYPROFILE, $operator))
|
||||
|| is_capable(CAN_ADMINISTRATE, $operator);
|
||||
if (!$canmodify) {
|
||||
$page['errors'][] = getlocal('page_agent.cannot_modify');
|
||||
}
|
||||
$can_modify = ($op_id == $operator['operatorid'] && is_capable(CAN_MODIFYPROFILE, $operator))
|
||||
|| is_capable(CAN_ADMINISTRATE, $operator);
|
||||
if (!$can_modify) {
|
||||
$page['errors'][] = getlocal('page_agent.cannot_modify');
|
||||
}
|
||||
|
||||
if (count($page['errors']) == 0) {
|
||||
if (!$opId) {
|
||||
$newop = create_operator($login, $email, $password, $localname, $commonname, "", $code);
|
||||
header("Location: " . MIBEW_WEB_ROOT . "/operator/avatar.php?op=" . intval($newop['operatorid']));
|
||||
exit;
|
||||
} else {
|
||||
update_operator($opId, $login, $email, $password, $localname, $commonname, $code);
|
||||
// update the session password
|
||||
if (!empty($password) && $opId == $operator['operatorid']) {
|
||||
$toDashboard = check_password_hash($login, '', $operator['vcpassword']) && $password != '';
|
||||
$_SESSION[SESSION_PREFIX."operator"]['vcpassword'] = calculate_password_hash($login, $password);
|
||||
if($toDashboard) {
|
||||
header("Location: " . MIBEW_WEB_ROOT . "/operator/index.php");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
header("Location: " . MIBEW_WEB_ROOT . "/operator/operator.php?op=" . intval($opId) . "&stored");
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
$page['formlogin'] = topage($login);
|
||||
$page['formname'] = topage($localname);
|
||||
$page['formemail'] = topage($email);
|
||||
$page['formcommonname'] = topage($commonname);
|
||||
$page['formcode'] = topage($code);
|
||||
$page['opid'] = topage($opId);
|
||||
}
|
||||
if (count($page['errors']) == 0) {
|
||||
if (!$op_id) {
|
||||
$new_operator = create_operator($login, $email, $password, $local_name, $common_name, "", $code);
|
||||
header("Location: " . MIBEW_WEB_ROOT . "/operator/avatar.php?op=" . intval($new_operator['operatorid']));
|
||||
exit;
|
||||
} else {
|
||||
update_operator($op_id, $login, $email, $password, $local_name, $common_name, $code);
|
||||
// update the session password
|
||||
if (!empty($password) && $op_id == $operator['operatorid']) {
|
||||
$to_dashboard = check_password_hash($login, '', $operator['vcpassword']) && $password != '';
|
||||
$_SESSION[SESSION_PREFIX . "operator"]['vcpassword'] = calculate_password_hash($login, $password);
|
||||
if ($to_dashboard) {
|
||||
header("Location: " . MIBEW_WEB_ROOT . "/operator/index.php");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
header("Location: " . MIBEW_WEB_ROOT . "/operator/operator.php?op=" . intval($op_id) . "&stored");
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
$page['formlogin'] = to_page($login);
|
||||
$page['formname'] = to_page($local_name);
|
||||
$page['formemail'] = to_page($email);
|
||||
$page['formcommonname'] = to_page($common_name);
|
||||
$page['formcode'] = to_page($code);
|
||||
$page['opid'] = to_page($op_id);
|
||||
}
|
||||
} elseif (isset($_GET['op'])) {
|
||||
$op_id = verify_param('op', "/^\d{1,9}$/");
|
||||
$op = operator_by_id($op_id);
|
||||
|
||||
} else if (isset($_GET['op'])) {
|
||||
$opId = verifyparam('op', "/^\d{1,9}$/");
|
||||
$op = operator_by_id($opId);
|
||||
if (!$op) {
|
||||
$page['errors'][] = getlocal("no_such_operator");
|
||||
$page['opid'] = to_page($op_id);
|
||||
} else {
|
||||
//show an error if the admin password hasn't been set yet.
|
||||
if (check_password_hash($operator['vclogin'], '', $operator['vcpassword']) && !isset($_GET['stored'])) {
|
||||
$page['errors'][] = getlocal("my_settings.error.no_password");
|
||||
}
|
||||
|
||||
if (!$op) {
|
||||
$page['errors'][] = getlocal("no_such_operator");
|
||||
$page['opid'] = topage($opId);
|
||||
} else {
|
||||
//show an error if the admin password hasn't been set yet.
|
||||
if (check_password_hash($operator['vclogin'], '', $operator['vcpassword']) && !isset($_GET['stored']))
|
||||
{
|
||||
$page['errors'][] = getlocal("my_settings.error.no_password");
|
||||
}
|
||||
|
||||
$page['formlogin'] = topage($op['vclogin']);
|
||||
$page['formname'] = topage($op['vclocalename']);
|
||||
$page['formemail'] = topage($op['vcemail']);
|
||||
$page['formcommonname'] = topage($op['vccommonname']);
|
||||
$page['formcode'] = topage($op['code']);
|
||||
$page['opid'] = topage($op['operatorid']);
|
||||
}
|
||||
$page['formlogin'] = to_page($op['vclogin']);
|
||||
$page['formname'] = to_page($op['vclocalename']);
|
||||
$page['formemail'] = to_page($op['vcemail']);
|
||||
$page['formcommonname'] = to_page($op['vccommonname']);
|
||||
$page['formcode'] = to_page($op['code']);
|
||||
$page['opid'] = to_page($op['operatorid']);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$opId && !is_capable(CAN_ADMINISTRATE, $operator)) {
|
||||
$page['errors'][] = getlocal("page_agent.error.forbidden_create");
|
||||
if (!$op_id && !is_capable(CAN_ADMINISTRATE, $operator)) {
|
||||
$page['errors'][] = getlocal("page_agent.error.forbidden_create");
|
||||
}
|
||||
|
||||
$canmodify = ($opId == $operator['operatorid'] && is_capable(CAN_MODIFYPROFILE, $operator))
|
||||
|| is_capable(CAN_ADMINISTRATE, $operator);
|
||||
$can_modify = ($op_id == $operator['operatorid'] && is_capable(CAN_MODIFYPROFILE, $operator))
|
||||
|| is_capable(CAN_ADMINISTRATE, $operator);
|
||||
|
||||
$page['stored'] = isset($_GET['stored']);
|
||||
$page['canmodify'] = $canmodify ? "1" : "";
|
||||
$page['canmodify'] = $can_modify ? "1" : "";
|
||||
$page['canchangelogin'] = is_capable(CAN_ADMINISTRATE, $operator);
|
||||
$page['needChangePassword'] = check_password_hash($operator['vclogin'], '', $operator['vcpassword']);
|
||||
$page['title'] = getlocal("page_agent.title");
|
||||
$page['menuid'] = ($opId == $operator['operatorid']) ? "profile" : "operators";
|
||||
$page['menuid'] = ($op_id == $operator['operatorid']) ? "profile" : "operators";
|
||||
|
||||
$page = array_merge(
|
||||
$page,
|
||||
prepare_menu($operator)
|
||||
);
|
||||
$page = array_merge($page, prepare_menu($operator));
|
||||
|
||||
$page['tabs'] = setup_operator_settings_tabs($opId, 0);
|
||||
$page['tabs'] = setup_operator_settings_tabs($op_id, 0);
|
||||
|
||||
$page_style = new PageStyle(PageStyle::currentStyle());
|
||||
$page_style->render('agent', $page);
|
||||
|
||||
?>
|
@ -20,99 +20,101 @@ use Mibew\Database;
|
||||
use Mibew\Style\PageStyle;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(dirname(dirname(__FILE__)).'/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/operator.php');
|
||||
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/operator.php');
|
||||
|
||||
$operator = check_login();
|
||||
force_password($operator);
|
||||
csrfchecktoken();
|
||||
csrf_check_token();
|
||||
|
||||
$page = array(
|
||||
'errors' => array(),
|
||||
'errors' => array(),
|
||||
);
|
||||
|
||||
if (isset($_GET['act'])) {
|
||||
|
||||
$operatorid = isset($_GET['id']) ? $_GET['id'] : "";
|
||||
if (!preg_match("/^\d+$/", $operatorid)) {
|
||||
$page['errors'][] = getlocal("no_such_operator");
|
||||
}
|
||||
$operator_id = isset($_GET['id']) ? $_GET['id'] : "";
|
||||
if (!preg_match("/^\d+$/", $operator_id)) {
|
||||
$page['errors'][] = getlocal("no_such_operator");
|
||||
}
|
||||
|
||||
if ($_GET['act'] == 'del') {
|
||||
if (!is_capable(CAN_ADMINISTRATE, $operator)) {
|
||||
$page['errors'][] = getlocal("page_agents.error.forbidden_remove");
|
||||
}
|
||||
if ($_GET['act'] == 'del') {
|
||||
if (!is_capable(CAN_ADMINISTRATE, $operator)) {
|
||||
$page['errors'][] = getlocal("page_agents.error.forbidden_remove");
|
||||
}
|
||||
|
||||
if ($operatorid == $operator['operatorid']) {
|
||||
$page['errors'][] = getlocal("page_agents.error.cannot_remove_self");
|
||||
}
|
||||
if ($operator_id == $operator['operatorid']) {
|
||||
$page['errors'][] = getlocal("page_agents.error.cannot_remove_self");
|
||||
}
|
||||
|
||||
if (count($page['errors']) == 0) {
|
||||
$op = operator_by_id($operatorid);
|
||||
if (!$op) {
|
||||
$page['errors'][] = getlocal("no_such_operator");
|
||||
} else if ($op['vclogin'] == 'admin') {
|
||||
$page['errors'][] = getlocal("page_agents.error.cannot_remove_admin");
|
||||
}
|
||||
}
|
||||
if (count($page['errors']) == 0) {
|
||||
$op = operator_by_id($operator_id);
|
||||
if (!$op) {
|
||||
$page['errors'][] = getlocal("no_such_operator");
|
||||
} elseif ($op['vclogin'] == 'admin') {
|
||||
$page['errors'][] = getlocal("page_agents.error.cannot_remove_admin");
|
||||
}
|
||||
}
|
||||
|
||||
if (count($page['errors']) == 0) {
|
||||
delete_operator($operatorid);
|
||||
header("Location: " . MIBEW_WEB_ROOT . "/operator/operators.php");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
if ($_GET['act'] == 'disable' || $_GET['act'] == 'enable') {
|
||||
$act_disable = ($_GET['act'] == 'disable');
|
||||
if (!is_capable(CAN_ADMINISTRATE, $operator)) {
|
||||
$page['errors'][] = $act_disable?getlocal('page_agents.disable.not.allowed'):getlocal('page_agents.enable.not.allowed');
|
||||
}
|
||||
if (count($page['errors']) == 0) {
|
||||
delete_operator($operator_id);
|
||||
header("Location: " . MIBEW_WEB_ROOT . "/operator/operators.php");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
if ($_GET['act'] == 'disable' || $_GET['act'] == 'enable') {
|
||||
$act_disable = ($_GET['act'] == 'disable');
|
||||
if (!is_capable(CAN_ADMINISTRATE, $operator)) {
|
||||
$page['errors'][] = $act_disable
|
||||
? getlocal('page_agents.disable.not.allowed')
|
||||
: getlocal('page_agents.enable.not.allowed');
|
||||
}
|
||||
|
||||
if ($operatorid == $operator['operatorid'] && $act_disable) {
|
||||
$page['errors'][] = getlocal('page_agents.cannot.disable.self');
|
||||
}
|
||||
if ($operator_id == $operator['operatorid'] && $act_disable) {
|
||||
$page['errors'][] = getlocal('page_agents.cannot.disable.self');
|
||||
}
|
||||
|
||||
if (count($page['errors']) == 0) {
|
||||
$op = operator_by_id($operatorid);
|
||||
if (!$op) {
|
||||
$page['errors'][] = getlocal("no_such_operator");
|
||||
} else if ($op['vclogin'] == 'admin' && $act_disable) {
|
||||
$page['errors'][] = getlocal('page_agents.cannot.disable.admin');
|
||||
}
|
||||
}
|
||||
if (count($page['errors']) == 0) {
|
||||
$op = operator_by_id($operator_id);
|
||||
if (!$op) {
|
||||
$page['errors'][] = getlocal("no_such_operator");
|
||||
} elseif ($op['vclogin'] == 'admin' && $act_disable) {
|
||||
$page['errors'][] = getlocal('page_agents.cannot.disable.admin');
|
||||
}
|
||||
}
|
||||
|
||||
if (count($page['errors']) == 0) {
|
||||
$db = Database::getInstance();
|
||||
$db->query(
|
||||
"update {chatoperator} set idisabled = ? where operatorid = ?",
|
||||
array(($act_disable ? '1' : '0'), $operatorid)
|
||||
);
|
||||
if (count($page['errors']) == 0) {
|
||||
$db = Database::getInstance();
|
||||
$db->query(
|
||||
"update {chatoperator} set idisabled = ? where operatorid = ?",
|
||||
array(($act_disable ? '1' : '0'), $operator_id)
|
||||
);
|
||||
|
||||
header("Location: " . MIBEW_WEB_ROOT . "/operator/operators.php");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
header("Location: " . MIBEW_WEB_ROOT . "/operator/operators.php");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sort['by'] = verifyparam("sortby", "/^(login|commonname|localename|lastseen)$/", "login");
|
||||
$sort['desc'] = (verifyparam("sortdirection", "/^(desc|asc)$/", "desc") == "desc");
|
||||
$sort['by'] = verify_param("sortby", "/^(login|commonname|localename|lastseen)$/", "login");
|
||||
$sort['desc'] = (verify_param("sortdirection", "/^(desc|asc)$/", "desc") == "desc");
|
||||
$page['formsortby'] = $sort['by'];
|
||||
$page['formsortdirection'] = $sort['desc']?'desc':'asc';
|
||||
$page['formsortdirection'] = $sort['desc'] ? 'desc' : 'asc';
|
||||
$list_options['sort'] = $sort;
|
||||
if (in_isolation($operator)) {
|
||||
$list_options['isolated_operator_id'] = $operator['operatorid'];
|
||||
$list_options['isolated_operator_id'] = $operator['operatorid'];
|
||||
}
|
||||
$page['allowedAgents'] = get_operators_list($list_options);
|
||||
$page['canmodify'] = is_capable(CAN_ADMINISTRATE, $operator);
|
||||
$page['availableOrders'] = array(
|
||||
array('id' => 'login', 'name' => getlocal('page_agents.login')),
|
||||
array('id' => 'localename', 'name' => getlocal('page_agents.agent_name')),
|
||||
array('id' => 'commonname', 'name' => getlocal('page_agents.commonname')),
|
||||
array('id' => 'lastseen', 'name' => getlocal('page_agents.status'))
|
||||
array('id' => 'login', 'name' => getlocal('page_agents.login')),
|
||||
array('id' => 'localename', 'name' => getlocal('page_agents.agent_name')),
|
||||
array('id' => 'commonname', 'name' => getlocal('page_agents.commonname')),
|
||||
array('id' => 'lastseen', 'name' => getlocal('page_agents.status')),
|
||||
);
|
||||
$page['availableDirections'] = array(
|
||||
array('id' => 'desc', 'name' => getlocal('page_agents.sortdirection.desc')),
|
||||
array('id' => 'asc', 'name' => getlocal('page_agents.sortdirection.asc')),
|
||||
array('id' => 'desc', 'name' => getlocal('page_agents.sortdirection.desc')),
|
||||
array('id' => 'asc', 'name' => getlocal('page_agents.sortdirection.asc')),
|
||||
);
|
||||
|
||||
$page['title'] = getlocal("page_agents.title");
|
||||
@ -120,12 +122,7 @@ $page['menuid'] = "operators";
|
||||
|
||||
setlocale(LC_TIME, getstring("time.locale"));
|
||||
|
||||
$page = array_merge(
|
||||
$page,
|
||||
prepare_menu($operator)
|
||||
);
|
||||
$page = array_merge($page, prepare_menu($operator));
|
||||
|
||||
$page_style = new PageStyle(PageStyle::currentStyle());
|
||||
$page_style->render('agents', $page);
|
||||
|
||||
?>
|
@ -19,69 +19,67 @@
|
||||
use Mibew\Style\PageStyle;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(dirname(dirname(__FILE__)).'/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/operator_settings.php');
|
||||
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/operator_settings.php');
|
||||
|
||||
$operator = check_login();
|
||||
csrfchecktoken();
|
||||
csrf_check_token();
|
||||
|
||||
$operator_in_isolation = in_isolation($operator);
|
||||
|
||||
$opId = verifyparam("op", "/^\d{1,9}$/");
|
||||
$page = array('opid' => $opId);
|
||||
$page['groups'] = $operator_in_isolation?get_all_groups_for_operator($operator):get_all_groups();
|
||||
$op_id = verify_param("op", "/^\d{1,9}$/");
|
||||
$page = array('opid' => $op_id);
|
||||
$page['groups'] = $operator_in_isolation
|
||||
? get_all_groups_for_operator($operator)
|
||||
: get_all_groups();
|
||||
$page['errors'] = array();
|
||||
|
||||
$canmodify = is_capable(CAN_ADMINISTRATE, $operator);
|
||||
$can_modify = is_capable(CAN_ADMINISTRATE, $operator);
|
||||
|
||||
$op = operator_by_id($opId);
|
||||
$op = operator_by_id($op_id);
|
||||
|
||||
if (!$op) {
|
||||
$page['errors'][] = getlocal("no_such_operator");
|
||||
$page['errors'][] = getlocal("no_such_operator");
|
||||
} elseif (isset($_POST['op'])) {
|
||||
|
||||
} else if (isset($_POST['op'])) {
|
||||
if (!$can_modify) {
|
||||
$page['errors'][] = getlocal('page_agent.cannot_modify');
|
||||
}
|
||||
|
||||
if (!$canmodify) {
|
||||
$page['errors'][] = getlocal('page_agent.cannot_modify');
|
||||
}
|
||||
if (count($page['errors']) == 0) {
|
||||
$new_groups = array();
|
||||
foreach ($page['groups'] as $group) {
|
||||
if (verify_param("group" . $group['groupid'], "/^on$/", "") == "on") {
|
||||
$new_groups[] = $group['groupid'];
|
||||
}
|
||||
}
|
||||
|
||||
if (count($page['errors']) == 0) {
|
||||
$new_groups = array();
|
||||
foreach ($page['groups'] as $group) {
|
||||
if (verifyparam("group" . $group['groupid'], "/^on$/", "") == "on") {
|
||||
$new_groups[] = $group['groupid'];
|
||||
}
|
||||
}
|
||||
|
||||
update_operator_groups($op['operatorid'], $new_groups);
|
||||
header("Location: " . MIBEW_WEB_ROOT . "/operator/opgroups.php?op=" . intval($opId) . "&stored");
|
||||
exit;
|
||||
}
|
||||
update_operator_groups($op['operatorid'], $new_groups);
|
||||
header("Location: " . MIBEW_WEB_ROOT . "/operator/opgroups.php?op=" . intval($op_id) . "&stored");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$page['formgroup'] = array();
|
||||
$page['currentop'] = $op ? topage(get_operator_name($op)) . " (" . $op['vclogin'] . ")" : getlocal("not_found");
|
||||
$page['canmodify'] = $canmodify ? "1" : "";
|
||||
$page['currentop'] = $op
|
||||
? to_page(get_operator_name($op)) . " (" . $op['vclogin'] . ")"
|
||||
: getlocal("not_found");
|
||||
$page['canmodify'] = $can_modify ? "1" : "";
|
||||
|
||||
if ($op) {
|
||||
foreach (get_operator_groupids($opId) as $rel) {
|
||||
$page['formgroup'][] = $rel['groupid'];
|
||||
}
|
||||
foreach (get_operator_group_ids($op_id) as $rel) {
|
||||
$page['formgroup'][] = $rel['groupid'];
|
||||
}
|
||||
}
|
||||
|
||||
$page['stored'] = isset($_GET['stored']);
|
||||
$page['title'] = getlocal("operator.groups.title");
|
||||
$page['menuid'] = ($page['operatorid'] == $opId) ? "profile" : "operators";
|
||||
$page['menuid'] = ($page['operatorid'] == $op_id) ? "profile" : "operators";
|
||||
|
||||
$page = array_merge(
|
||||
$page,
|
||||
prepare_menu($operator)
|
||||
);
|
||||
$page = array_merge($page, prepare_menu($operator));
|
||||
|
||||
$page['tabs'] = setup_operator_settings_tabs($opId, 2);
|
||||
$page['tabs'] = setup_operator_settings_tabs($op_id, 2);
|
||||
|
||||
$page_style = new PageStyle(PageStyle::currentStyle());
|
||||
$page_style->render('operator_groups', $page);
|
||||
|
||||
?>
|
@ -19,47 +19,42 @@
|
||||
use Mibew\Style\PageStyle;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(dirname(dirname(__FILE__)).'/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/settings.php');
|
||||
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/settings.php');
|
||||
|
||||
$operator = check_login();
|
||||
|
||||
$stylelist = PageStyle::availableStyles();
|
||||
$style_list = PageStyle::availableStyles();
|
||||
|
||||
$preview = verifyparam("preview", "/^\w+$/", "default");
|
||||
if (!in_array($preview, $stylelist)) {
|
||||
$style_names = array_keys($stylelist);
|
||||
$preview = $stylelist[$style_names[0]];
|
||||
$preview = verify_param("preview", "/^\w+$/", "default");
|
||||
if (!in_array($preview, $style_list)) {
|
||||
$style_names = array_keys($style_list);
|
||||
$preview = $style_list[$style_names[0]];
|
||||
}
|
||||
|
||||
$preview_style = new PageStyle($preview);
|
||||
$style_config = $preview_style->configurations();
|
||||
|
||||
$screenshots = array();
|
||||
foreach($style_config['screenshots'] as $name => $desc) {
|
||||
$screenshots[] = array(
|
||||
'name' => $name,
|
||||
'file' => MIBEW_WEB_ROOT . '/' . $preview_style->filesPath()
|
||||
. '/screenshots/' . $name . '.png',
|
||||
'description' => $desc
|
||||
);
|
||||
foreach ($style_config['screenshots'] as $name => $desc) {
|
||||
$screenshots[] = array(
|
||||
'name' => $name,
|
||||
'file' => (MIBEW_WEB_ROOT . '/' . $preview_style->filesPath()
|
||||
. '/screenshots/' . $name . '.png'),
|
||||
'description' => $desc,
|
||||
);
|
||||
}
|
||||
|
||||
$page['formpreview'] = $preview;
|
||||
$page['availablePreviews'] = $stylelist;
|
||||
$page['availablePreviews'] = $style_list;
|
||||
$page['screenshotsList'] = $screenshots;
|
||||
$page['title'] = getlocal("page.preview.title");
|
||||
$page['menuid'] = "settings";
|
||||
|
||||
$page = array_merge(
|
||||
$page,
|
||||
prepare_menu($operator)
|
||||
);
|
||||
$page = array_merge($page, prepare_menu($operator));
|
||||
|
||||
$page['tabs'] = setup_settings_tabs(3);
|
||||
|
||||
$page_style = new PageStyle(PageStyle::currentStyle());
|
||||
$page_style->render('page_themes', $page);
|
||||
|
||||
?>
|
@ -20,92 +20,98 @@ use Mibew\Settings;
|
||||
use Mibew\Style\PageStyle;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(dirname(dirname(__FILE__)).'/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/settings.php');
|
||||
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/settings.php');
|
||||
|
||||
$operator = check_login();
|
||||
csrfchecktoken();
|
||||
csrf_check_token();
|
||||
|
||||
$page = array(
|
||||
'agentId' => '',
|
||||
'errors' => array(),
|
||||
'agentId' => '',
|
||||
'errors' => array(),
|
||||
);
|
||||
|
||||
$options = array(
|
||||
'online_timeout', 'updatefrequency_operator', 'updatefrequency_chat',
|
||||
'max_connections_from_one_host',
|
||||
'updatefrequency_tracking', 'visitors_limit', 'invitation_lifetime',
|
||||
'tracking_lifetime', 'thread_lifetime', 'statistics_aggregation_interval');
|
||||
'online_timeout',
|
||||
'updatefrequency_operator',
|
||||
'updatefrequency_chat',
|
||||
'max_connections_from_one_host',
|
||||
'updatefrequency_tracking',
|
||||
'visitors_limit',
|
||||
'invitation_lifetime',
|
||||
'tracking_lifetime',
|
||||
'thread_lifetime',
|
||||
'statistics_aggregation_interval',
|
||||
);
|
||||
|
||||
$params = array();
|
||||
foreach ($options as $opt) {
|
||||
$params[$opt] = Settings::get($opt);
|
||||
$params[$opt] = Settings::get($opt);
|
||||
}
|
||||
|
||||
if (isset($_POST['onlinetimeout'])) {
|
||||
$params['online_timeout'] = getparam('onlinetimeout');
|
||||
if (!is_numeric($params['online_timeout'])) {
|
||||
$page['errors'][] = wrong_field("settings.onlinetimeout");
|
||||
}
|
||||
$params['online_timeout'] = get_param('onlinetimeout');
|
||||
if (!is_numeric($params['online_timeout'])) {
|
||||
$page['errors'][] = wrong_field("settings.onlinetimeout");
|
||||
}
|
||||
|
||||
$params['updatefrequency_operator'] = getparam('frequencyoperator');
|
||||
if (!is_numeric($params['updatefrequency_operator'])) {
|
||||
$page['errors'][] = wrong_field("settings.frequencyoperator");
|
||||
}
|
||||
$params['updatefrequency_operator'] = get_param('frequencyoperator');
|
||||
if (!is_numeric($params['updatefrequency_operator'])) {
|
||||
$page['errors'][] = wrong_field("settings.frequencyoperator");
|
||||
}
|
||||
|
||||
$params['updatefrequency_chat'] = getparam('frequencychat');
|
||||
if (!is_numeric($params['updatefrequency_chat'])) {
|
||||
$page['errors'][] = wrong_field("settings.frequencychat");
|
||||
}
|
||||
$params['updatefrequency_chat'] = get_param('frequencychat');
|
||||
if (!is_numeric($params['updatefrequency_chat'])) {
|
||||
$page['errors'][] = wrong_field("settings.frequencychat");
|
||||
}
|
||||
|
||||
$params['max_connections_from_one_host'] = getparam('onehostconnections');
|
||||
if (!is_numeric($params['max_connections_from_one_host'])) {
|
||||
$page['errors'][] = getlocal("settings.wrong.onehostconnections");
|
||||
}
|
||||
$params['max_connections_from_one_host'] = get_param('onehostconnections');
|
||||
if (!is_numeric($params['max_connections_from_one_host'])) {
|
||||
$page['errors'][] = getlocal("settings.wrong.onehostconnections");
|
||||
}
|
||||
|
||||
$params['thread_lifetime'] = getparam('threadlifetime');
|
||||
if (!is_numeric($params['thread_lifetime'])) {
|
||||
$page['errors'][] = getlocal("settings.wrong.threadlifetime");
|
||||
}
|
||||
$params['thread_lifetime'] = get_param('threadlifetime');
|
||||
if (!is_numeric($params['thread_lifetime'])) {
|
||||
$page['errors'][] = getlocal("settings.wrong.threadlifetime");
|
||||
}
|
||||
|
||||
$params['statistics_aggregation_interval'] = getparam('statistics_aggregation_interval');
|
||||
if (!is_numeric($params['statistics_aggregation_interval'])) {
|
||||
$page['errors'][] = wrong_field("settings.statistics_aggregation_interval");
|
||||
}
|
||||
$params['statistics_aggregation_interval'] = get_param('statistics_aggregation_interval');
|
||||
if (!is_numeric($params['statistics_aggregation_interval'])) {
|
||||
$page['errors'][] = wrong_field("settings.statistics_aggregation_interval");
|
||||
}
|
||||
|
||||
if (Settings::get('enabletracking')) {
|
||||
if (Settings::get('enabletracking')) {
|
||||
|
||||
$params['updatefrequency_tracking'] = getparam('frequencytracking');
|
||||
if (!is_numeric($params['updatefrequency_tracking'])) {
|
||||
$page['errors'][] = wrong_field("settings.frequencytracking");
|
||||
}
|
||||
$params['updatefrequency_tracking'] = get_param('frequencytracking');
|
||||
if (!is_numeric($params['updatefrequency_tracking'])) {
|
||||
$page['errors'][] = wrong_field("settings.frequencytracking");
|
||||
}
|
||||
|
||||
$params['visitors_limit'] = getparam('visitorslimit');
|
||||
if (!is_numeric($params['visitors_limit'])) {
|
||||
$page['errors'][] = wrong_field("settings.visitorslimit");
|
||||
}
|
||||
$params['visitors_limit'] = get_param('visitorslimit');
|
||||
if (!is_numeric($params['visitors_limit'])) {
|
||||
$page['errors'][] = wrong_field("settings.visitorslimit");
|
||||
}
|
||||
|
||||
$params['invitation_lifetime'] = getparam('invitationlifetime');
|
||||
if (!is_numeric($params['invitation_lifetime'])) {
|
||||
$page['errors'][] = wrong_field("settings.invitationlifetime");
|
||||
}
|
||||
$params['invitation_lifetime'] = get_param('invitationlifetime');
|
||||
if (!is_numeric($params['invitation_lifetime'])) {
|
||||
$page['errors'][] = wrong_field("settings.invitationlifetime");
|
||||
}
|
||||
|
||||
$params['tracking_lifetime'] = getparam('trackinglifetime');
|
||||
if (!is_numeric($params['tracking_lifetime'])) {
|
||||
$page['errors'][] = wrong_field("settings.trackinglifetime");
|
||||
}
|
||||
$params['tracking_lifetime'] = get_param('trackinglifetime');
|
||||
if (!is_numeric($params['tracking_lifetime'])) {
|
||||
$page['errors'][] = wrong_field("settings.trackinglifetime");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (count($page['errors']) == 0) {
|
||||
foreach ($options as $opt) {
|
||||
Settings::set($opt,$params[$opt]);
|
||||
}
|
||||
Settings::update();
|
||||
header("Location: " . MIBEW_WEB_ROOT . "/operator/performance.php?stored");
|
||||
exit;
|
||||
}
|
||||
if (count($page['errors']) == 0) {
|
||||
foreach ($options as $opt) {
|
||||
Settings::set($opt, $params[$opt]);
|
||||
}
|
||||
Settings::update();
|
||||
header("Location: " . MIBEW_WEB_ROOT . "/operator/performance.php?stored");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$page['formonlinetimeout'] = $params['online_timeout'];
|
||||
@ -117,11 +123,10 @@ $page['formstatistics_aggregation_interval'] = $params['statistics_aggregation_i
|
||||
|
||||
if (Settings::get('enabletracking')) {
|
||||
|
||||
$page['formfrequencytracking'] = $params['updatefrequency_tracking'];
|
||||
$page['formvisitorslimit'] = $params['visitors_limit'];
|
||||
$page['forminvitationlifetime'] = $params['invitation_lifetime'];
|
||||
$page['formtrackinglifetime'] = $params['tracking_lifetime'];
|
||||
|
||||
$page['formfrequencytracking'] = $params['updatefrequency_tracking'];
|
||||
$page['formvisitorslimit'] = $params['visitors_limit'];
|
||||
$page['forminvitationlifetime'] = $params['invitation_lifetime'];
|
||||
$page['formtrackinglifetime'] = $params['tracking_lifetime'];
|
||||
}
|
||||
|
||||
$page['enabletracking'] = Settings::get('enabletracking');
|
||||
@ -130,14 +135,9 @@ $page['stored'] = isset($_GET['stored']);
|
||||
$page['title'] = getlocal("settings.title");
|
||||
$page['menuid'] = "settings";
|
||||
|
||||
$page = array_merge(
|
||||
$page,
|
||||
prepare_menu($operator)
|
||||
);
|
||||
$page = array_merge($page, prepare_menu($operator));
|
||||
|
||||
$page['tabs'] = setup_settings_tabs(2);
|
||||
|
||||
$page_style = new PageStyle(PageStyle::currentStyle());
|
||||
$page_style->render('performance', $page);
|
||||
|
||||
?>
|
@ -19,77 +19,70 @@
|
||||
use Mibew\Style\PageStyle;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(dirname(dirname(__FILE__)).'/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/operator_settings.php');
|
||||
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/operator_settings.php');
|
||||
|
||||
$operator = check_login();
|
||||
csrfchecktoken();
|
||||
csrf_check_token();
|
||||
|
||||
$opId = verifyparam("op", "/^\d{1,9}$/");
|
||||
$op_id = verify_param("op", "/^\d{1,9}$/");
|
||||
$page = array(
|
||||
'opid' => $opId,
|
||||
'canmodify' => is_capable(CAN_ADMINISTRATE, $operator) ? "1" : "",
|
||||
'errors' => array(),
|
||||
'opid' => $op_id,
|
||||
'canmodify' => is_capable(CAN_ADMINISTRATE, $operator) ? "1" : "",
|
||||
'errors' => array(),
|
||||
);
|
||||
|
||||
$op = operator_by_id($opId);
|
||||
$op = operator_by_id($op_id);
|
||||
|
||||
if (!$op) {
|
||||
$page['errors'][] = getlocal("no_such_operator");
|
||||
$page['errors'][] = getlocal("no_such_operator");
|
||||
} elseif (isset($_POST['op'])) {
|
||||
|
||||
} else if (isset($_POST['op'])) {
|
||||
if (!is_capable(CAN_ADMINISTRATE, $operator)) {
|
||||
$page['errors'][] = getlocal('page_agent.cannot_modify');
|
||||
}
|
||||
|
||||
if (!is_capable(CAN_ADMINISTRATE, $operator)) {
|
||||
$page['errors'][] = getlocal('page_agent.cannot_modify');
|
||||
}
|
||||
$new_permissions = isset($op['iperm']) ? $op['iperm'] : 0;
|
||||
|
||||
$new_permissions = isset($op['iperm']) ? $op['iperm'] : 0;
|
||||
foreach (permission_ids() as $perm => $id) {
|
||||
if (verify_param("permissions$id", "/^on$/", "") == "on") {
|
||||
$new_permissions |= (1 << $perm);
|
||||
} else {
|
||||
$new_permissions &= ~(1 << $perm);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (permission_ids() as $perm => $id) {
|
||||
if (verifyparam("permissions$id", "/^on$/", "") == "on") {
|
||||
$new_permissions |= (1 << $perm);
|
||||
} else {
|
||||
$new_permissions &= ~(1 << $perm);
|
||||
}
|
||||
}
|
||||
|
||||
if (count($page['errors']) == 0) {
|
||||
update_operator_permissions($op['operatorid'], $new_permissions);
|
||||
|
||||
if ($opId && $_SESSION[SESSION_PREFIX."operator"] && $operator['operatorid'] == $opId) {
|
||||
$_SESSION[SESSION_PREFIX."operator"]['iperm'] = $new_permissions;
|
||||
}
|
||||
header("Location: " . MIBEW_WEB_ROOT . "/operator/permissions.php?op=" . intval($opId) . "&stored");
|
||||
exit;
|
||||
}
|
||||
if (count($page['errors']) == 0) {
|
||||
update_operator_permissions($op['operatorid'], $new_permissions);
|
||||
|
||||
if ($op_id && $_SESSION[SESSION_PREFIX . "operator"] && $operator['operatorid'] == $op_id) {
|
||||
$_SESSION[SESSION_PREFIX . "operator"]['iperm'] = $new_permissions;
|
||||
}
|
||||
header("Location: " . MIBEW_WEB_ROOT . "/operator/permissions.php?op=" . intval($op_id) . "&stored");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$page['permissionsList'] = get_permission_list();
|
||||
$page['formpermissions'] = array("");
|
||||
$page['currentop'] = $op ? topage(get_operator_name($op)) . " (" . $op['vclogin'] . ")" : getlocal("not_found");
|
||||
$page['currentop'] = $op ? to_page(get_operator_name($op)) . " (" . $op['vclogin'] . ")" : getlocal("not_found");
|
||||
|
||||
if ($op) {
|
||||
foreach (permission_ids() as $perm => $id) {
|
||||
if (is_capable($perm, $op)) {
|
||||
$page['formpermissions'][] = $id;
|
||||
}
|
||||
}
|
||||
foreach (permission_ids() as $perm => $id) {
|
||||
if (is_capable($perm, $op)) {
|
||||
$page['formpermissions'][] = $id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$page['stored'] = isset($_GET['stored']);
|
||||
$page['title'] = getlocal("permissions.title");
|
||||
$page['menuid'] = ($operator['operatorid'] == $opId) ? "profile" : "operators";
|
||||
$page['menuid'] = ($operator['operatorid'] == $op_id) ? "profile" : "operators";
|
||||
|
||||
$page = array_merge(
|
||||
$page,
|
||||
prepare_menu($operator)
|
||||
);
|
||||
$page = array_merge($page, prepare_menu($operator));
|
||||
|
||||
$page['tabs'] = setup_operator_settings_tabs($opId, 3);
|
||||
$page['tabs'] = setup_operator_settings_tabs($op_id, 3);
|
||||
|
||||
$page_style = new PageStyle(PageStyle::currentStyle());
|
||||
$page_style->render('permissions', $page);
|
||||
|
||||
?>
|
@ -21,108 +21,110 @@ use Mibew\Thread;
|
||||
use Mibew\Style\ChatStyle;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(dirname(dirname(__FILE__)).'/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/chat.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/groups.php');
|
||||
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/chat.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/groups.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/track.php');
|
||||
|
||||
$operator = check_login();
|
||||
|
||||
$threadid = verifyparam("thread", "/^\d{1,8}$/");
|
||||
$token = verifyparam("token", "/^\d{1,8}$/");
|
||||
$thread_id = verify_param("thread", "/^\d{1,8}$/");
|
||||
$token = verify_param("token", "/^\d{1,8}$/");
|
||||
|
||||
$thread = Thread::load($threadid, $token);
|
||||
if (! $thread) {
|
||||
die("wrong thread");
|
||||
$thread = Thread::load($thread_id, $token);
|
||||
if (!$thread) {
|
||||
die("wrong thread");
|
||||
}
|
||||
|
||||
$page = array(
|
||||
'errors' => array(),
|
||||
'errors' => array(),
|
||||
);
|
||||
|
||||
// Initialize chat style which is currently used in system
|
||||
$chat_style = new ChatStyle(ChatStyle::currentStyle());
|
||||
|
||||
if (isset($_GET['nextGroup'])) {
|
||||
$nextid = verifyparam("nextGroup", "/^\d{1,8}$/");
|
||||
$nextGroup = group_by_id($nextid);
|
||||
$next_id = verify_param("nextGroup", "/^\d{1,8}$/");
|
||||
$next_group = group_by_id($next_id);
|
||||
|
||||
if ($nextGroup) {
|
||||
$page['message'] = getlocal2("chat.redirected.group.content", array(topage(get_group_name($nextGroup))));
|
||||
if ($thread->state == Thread::STATE_CHATTING) {
|
||||
$thread->state = Thread::STATE_WAITING;
|
||||
$thread->nextAgent = 0;
|
||||
$thread->groupId = $nextid;
|
||||
$thread->agentId = 0;
|
||||
$thread->agentName = '';
|
||||
$thread->save();
|
||||
|
||||
$thread->postMessage(
|
||||
Thread::KIND_EVENTS,
|
||||
getstring2_(
|
||||
"chat.status.operator.redirect",
|
||||
array(get_operator_name($operator)),
|
||||
$thread->locale
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$page['errors'][] = getlocal("chat.redirect.cannot");
|
||||
}
|
||||
} else {
|
||||
$page['errors'][] = "Unknown group";
|
||||
}
|
||||
if ($next_group) {
|
||||
$page['message'] = getlocal2(
|
||||
"chat.redirected.group.content",
|
||||
array(to_page(get_group_name($next_group)))
|
||||
);
|
||||
if ($thread->state == Thread::STATE_CHATTING) {
|
||||
$thread->state = Thread::STATE_WAITING;
|
||||
$thread->nextAgent = 0;
|
||||
$thread->groupId = $next_id;
|
||||
$thread->agentId = 0;
|
||||
$thread->agentName = '';
|
||||
$thread->save();
|
||||
|
||||
$thread->postMessage(
|
||||
Thread::KIND_EVENTS,
|
||||
getstring2_(
|
||||
"chat.status.operator.redirect",
|
||||
array(get_operator_name($operator)),
|
||||
$thread->locale
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$page['errors'][] = getlocal("chat.redirect.cannot");
|
||||
}
|
||||
} else {
|
||||
$page['errors'][] = "Unknown group";
|
||||
}
|
||||
} else {
|
||||
$nextid = verifyparam("nextAgent", "/^\d{1,8}$/");
|
||||
$nextOperator = operator_by_id($nextid);
|
||||
$next_id = verify_param("nextAgent", "/^\d{1,8}$/");
|
||||
$next_operator = operator_by_id($next_id);
|
||||
|
||||
if ($nextOperator) {
|
||||
$page['message'] = getlocal2("chat.redirected.content", array(topage(get_operator_name($nextOperator))));
|
||||
if ($thread->state == Thread::STATE_CHATTING) {
|
||||
$thread->state = Thread::STATE_WAITING;
|
||||
$thread->nextAgent = $nextid;
|
||||
$thread->agentId = 0;
|
||||
if ($thread->groupId != 0) {
|
||||
$db = Database::getInstance();
|
||||
list($groups_count) = $db->query(
|
||||
"select count(*) AS count from {chatgroupoperator} " .
|
||||
"where operatorid = ? and groupid = ?",
|
||||
array($nextid, $thread->groupId),
|
||||
array(
|
||||
'return_rows' => Database::RETURN_ONE_ROW,
|
||||
'fetch_type' => Database::FETCH_NUM
|
||||
)
|
||||
);
|
||||
if ($groups_count === 0) {
|
||||
$thread->groupId = 0;
|
||||
}
|
||||
}
|
||||
$thread->save();
|
||||
$thread->postMessage(
|
||||
Thread::KIND_EVENTS,
|
||||
getstring2_(
|
||||
"chat.status.operator.redirect",
|
||||
array(get_operator_name($operator)),
|
||||
$thread->locale
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$page['errors'][] = getlocal("chat.redirect.cannot");
|
||||
}
|
||||
} else {
|
||||
$page['errors'][] = "Unknown operator";
|
||||
}
|
||||
if ($next_operator) {
|
||||
$page['message'] = getlocal2(
|
||||
"chat.redirected.content",
|
||||
array(to_page(get_operator_name($next_operator)))
|
||||
);
|
||||
if ($thread->state == Thread::STATE_CHATTING) {
|
||||
$thread->state = Thread::STATE_WAITING;
|
||||
$thread->nextAgent = $next_id;
|
||||
$thread->agentId = 0;
|
||||
if ($thread->groupId != 0) {
|
||||
$db = Database::getInstance();
|
||||
list($groups_count) = $db->query(
|
||||
("SELECT count(*) AS count "
|
||||
. "FROM {chatgroupoperator} "
|
||||
. "WHERE operatorid = ? AND groupid = ?"),
|
||||
array($next_id, $thread->groupId),
|
||||
array(
|
||||
'return_rows' => Database::RETURN_ONE_ROW,
|
||||
'fetch_type' => Database::FETCH_NUM,
|
||||
)
|
||||
);
|
||||
if ($groups_count === 0) {
|
||||
$thread->groupId = 0;
|
||||
}
|
||||
}
|
||||
$thread->save();
|
||||
$thread->postMessage(
|
||||
Thread::KIND_EVENTS,
|
||||
getstring2_(
|
||||
"chat.status.operator.redirect",
|
||||
array(get_operator_name($operator)),
|
||||
$thread->locale
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$page['errors'][] = getlocal("chat.redirect.cannot");
|
||||
}
|
||||
} else {
|
||||
$page['errors'][] = "Unknown operator";
|
||||
}
|
||||
}
|
||||
|
||||
$page = array_merge_recursive(
|
||||
$page,
|
||||
setup_logo()
|
||||
);
|
||||
$page = array_merge_recursive($page, setup_logo());
|
||||
|
||||
if (count($page['errors']) > 0) {
|
||||
$chat_style->render('error', $page);
|
||||
$chat_style->render('error', $page);
|
||||
} else {
|
||||
$chat_style->render('redirected', $page);
|
||||
$chat_style->render('redirected', $page);
|
||||
}
|
||||
|
||||
?>
|
@ -20,65 +20,69 @@ use Mibew\Database;
|
||||
use Mibew\Style\PageStyle;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(dirname(dirname(__FILE__)).'/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/settings.php');
|
||||
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/settings.php');
|
||||
|
||||
$page = array(
|
||||
'version' => MIBEW_VERSION,
|
||||
'showform' => true,
|
||||
'title' => getlocal("resetpwd.title"),
|
||||
'headertitle' => getlocal("app.title"),
|
||||
'show_small_login' => true,
|
||||
'fixedwrap' => true,
|
||||
'errors' => array(),
|
||||
'version' => MIBEW_VERSION,
|
||||
'showform' => true,
|
||||
'title' => getlocal("resetpwd.title"),
|
||||
'headertitle' => getlocal("app.title"),
|
||||
'show_small_login' => true,
|
||||
'fixedwrap' => true,
|
||||
'errors' => array(),
|
||||
);
|
||||
|
||||
$page_style = new PageStyle(PageStyle::currentStyle());
|
||||
|
||||
$opId = verifyparam("id", "/^\d{1,9}$/");
|
||||
$token = verifyparam("token", "/^[\dabcdef]+$/");
|
||||
$op_id = verify_param("id", "/^\d{1,9}$/");
|
||||
$token = verify_param("token", "/^[\dabcdef]+$/");
|
||||
|
||||
$operator = operator_by_id($opId);
|
||||
$operator = operator_by_id($op_id);
|
||||
|
||||
if (!$operator) {
|
||||
$page['errors'][] = "No such operator";
|
||||
$page['showform'] = false;
|
||||
} else if ($token != $operator['vcrestoretoken']) {
|
||||
$page['errors'][] = "Wrong token";
|
||||
$page['showform'] = false;
|
||||
$page['errors'][] = "No such operator";
|
||||
$page['showform'] = false;
|
||||
} elseif ($token != $operator['vcrestoretoken']) {
|
||||
$page['errors'][] = "Wrong token";
|
||||
$page['showform'] = false;
|
||||
}
|
||||
|
||||
if (count($page['errors']) == 0 && isset($_POST['password'])) {
|
||||
$password = getparam('password');
|
||||
$passwordConfirm = getparam('passwordConfirm');
|
||||
$password = get_param('password');
|
||||
$password_confirm = get_param('passwordConfirm');
|
||||
|
||||
if (!$password)
|
||||
$page['errors'][] = no_field("form.field.password");
|
||||
if (!$password) {
|
||||
$page['errors'][] = no_field("form.field.password");
|
||||
}
|
||||
|
||||
if ($password != $passwordConfirm)
|
||||
$page['errors'][] = getlocal("my_settings.error.password_match");
|
||||
if ($password != $password_confirm) {
|
||||
$page['errors'][] = getlocal("my_settings.error.password_match");
|
||||
}
|
||||
|
||||
if (count($page['errors']) == 0) {
|
||||
$page['isdone'] = true;
|
||||
if (count($page['errors']) == 0) {
|
||||
$page['isdone'] = true;
|
||||
|
||||
$db = Database::getInstance();
|
||||
$db->query(
|
||||
"update {chatoperator} set vcpassword = ?, vcrestoretoken = '' " .
|
||||
"where operatorid = ?",
|
||||
array(calculate_password_hash($operator['vclogin'], $password), $opId)
|
||||
);
|
||||
$db = Database::getInstance();
|
||||
$db->query(
|
||||
("UPDATE {chatoperator} "
|
||||
. "SET vcpassword = ?, vcrestoretoken = '' "
|
||||
. "WHERE operatorid = ?"),
|
||||
array(
|
||||
calculate_password_hash($operator['vclogin'], $password),
|
||||
$op_id,
|
||||
)
|
||||
);
|
||||
|
||||
$page['loginname'] = $operator['vclogin'];
|
||||
$page_style->render('resetpwd', $page);
|
||||
exit;
|
||||
}
|
||||
$page['loginname'] = $operator['vclogin'];
|
||||
$page_style->render('resetpwd', $page);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$page['id'] = $opId;
|
||||
$page['id'] = $op_id;
|
||||
$page['token'] = $token;
|
||||
$page['isdone'] = false;
|
||||
|
||||
$page_style->render('resetpwd', $page);
|
||||
|
||||
?>
|
@ -20,65 +20,77 @@ use Mibew\Database;
|
||||
use Mibew\Style\PageStyle;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(dirname(dirname(__FILE__)).'/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/settings.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/notify.php');
|
||||
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/settings.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/notify.php');
|
||||
|
||||
$page = array(
|
||||
'version' => MIBEW_VERSION,
|
||||
'title' => getlocal("restore.title"),
|
||||
'headertitle' => getlocal("app.title"),
|
||||
'show_small_login' => true,
|
||||
'fixedwrap' => true,
|
||||
'errors' => array(),
|
||||
'version' => MIBEW_VERSION,
|
||||
'title' => getlocal("restore.title"),
|
||||
'headertitle' => getlocal("app.title"),
|
||||
'show_small_login' => true,
|
||||
'fixedwrap' => true,
|
||||
'errors' => array(),
|
||||
);
|
||||
|
||||
$loginoremail = "";
|
||||
$login_or_email = "";
|
||||
|
||||
$page_style = new PageStyle(PageStyle::currentStyle());
|
||||
|
||||
if (isset($_POST['loginoremail'])) {
|
||||
$loginoremail = getparam("loginoremail");
|
||||
$login_or_email = get_param("loginoremail");
|
||||
|
||||
$torestore = is_valid_email($loginoremail) ? operator_by_email($loginoremail) : operator_by_login($loginoremail);
|
||||
if (!$torestore) {
|
||||
$page['errors'][] = getlocal("no_such_operator");
|
||||
}
|
||||
$to_restore = is_valid_email($login_or_email)
|
||||
? operator_by_email($login_or_email)
|
||||
: operator_by_login($login_or_email);
|
||||
if (!$to_restore) {
|
||||
$page['errors'][] = getlocal("no_such_operator");
|
||||
}
|
||||
|
||||
$email = $torestore['vcemail'];
|
||||
if (count($page['errors']) == 0 && !is_valid_email($email)) {
|
||||
$page['errors'][] = "Operator hasn't set his e-mail";
|
||||
}
|
||||
$email = $to_restore['vcemail'];
|
||||
if (count($page['errors']) == 0 && !is_valid_email($email)) {
|
||||
$page['errors'][] = "Operator hasn't set his e-mail";
|
||||
}
|
||||
|
||||
if (count($page['errors']) == 0) {
|
||||
$token = sha1($torestore['vclogin'] . (function_exists('openssl_random_pseudo_bytes') ? openssl_random_pseudo_bytes(32) : (time() + microtime()) . mt_rand(0, 99999999)));
|
||||
if (count($page['errors']) == 0) {
|
||||
$token = sha1($to_restore['vclogin'] . (function_exists('openssl_random_pseudo_bytes')
|
||||
? openssl_random_pseudo_bytes(32)
|
||||
: (time() + microtime()) . mt_rand(0, 99999999)));
|
||||
|
||||
$db = Database::getInstance();
|
||||
$db->query(
|
||||
"update {chatoperator} set dtmrestore = :now, " .
|
||||
"vcrestoretoken = :token where operatorid = :operatorid",
|
||||
array(
|
||||
':now' => time(),
|
||||
':token' => $token,
|
||||
':operatorid' => $torestore['operatorid']
|
||||
)
|
||||
);
|
||||
$db = Database::getInstance();
|
||||
$db->query(
|
||||
("UPDATE {chatoperator} "
|
||||
. "SET dtmrestore = :now, vcrestoretoken = :token "
|
||||
. "WHERE operatorid = :operatorid"),
|
||||
array(
|
||||
':now' => time(),
|
||||
':token' => $token,
|
||||
':operatorid' => $to_restore['operatorid'],
|
||||
)
|
||||
);
|
||||
|
||||
$href = get_app_location(true, false) . "/operator/resetpwd.php?id=" . $torestore['operatorid'] . "&token=$token";
|
||||
mibew_mail($email, $email, getstring("restore.mailsubj"), getstring2("restore.mailtext", array(get_operator_name($torestore), $href)));
|
||||
$href = get_app_location(true, false) . "/operator/resetpwd.php?id="
|
||||
. $to_restore['operatorid'] . "&token=$token";
|
||||
mibew_mail(
|
||||
$email,
|
||||
$email,
|
||||
getstring("restore.mailsubj"),
|
||||
getstring2(
|
||||
"restore.mailtext",
|
||||
array(get_operator_name($to_restore), $href)
|
||||
)
|
||||
);
|
||||
|
||||
$page['isdone'] = true;
|
||||
$page_style->render('restore', $page);
|
||||
exit;
|
||||
}
|
||||
$page['isdone'] = true;
|
||||
$page_style->render('restore', $page);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$page['formloginoremail'] = topage($loginoremail);
|
||||
$page['formloginoremail'] = to_page($login_or_email);
|
||||
|
||||
$page['localeLinks'] = get_locale_links(MIBEW_WEB_ROOT . "/operator/restore.php");
|
||||
$page['isdone'] = false;
|
||||
|
||||
$page_style->render('restore', $page);
|
||||
|
||||
?>
|
@ -22,129 +22,139 @@ use Mibew\Style\InvitationStyle;
|
||||
use Mibew\Style\PageStyle;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(dirname(dirname(__FILE__)).'/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/settings.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/cron.php');
|
||||
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/settings.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/cron.php');
|
||||
|
||||
$operator = check_login();
|
||||
force_password($operator);
|
||||
csrfchecktoken();
|
||||
csrf_check_token();
|
||||
|
||||
$page = array(
|
||||
'agentId' => '',
|
||||
'errors' => array(),
|
||||
'agentId' => '',
|
||||
'errors' => array(),
|
||||
);
|
||||
|
||||
// Load system configs
|
||||
$options = array(
|
||||
'email',
|
||||
'title',
|
||||
'logo',
|
||||
'hosturl',
|
||||
'usernamepattern',
|
||||
'chattitle',
|
||||
'geolink',
|
||||
'geolinkparams',
|
||||
'sendmessagekey',
|
||||
'cron_key'
|
||||
'email',
|
||||
'title',
|
||||
'logo',
|
||||
'hosturl',
|
||||
'usernamepattern',
|
||||
'chattitle',
|
||||
'geolink',
|
||||
'geolinkparams',
|
||||
'sendmessagekey',
|
||||
'cron_key',
|
||||
);
|
||||
|
||||
$params = array();
|
||||
foreach ($options as $opt) {
|
||||
$params[$opt] = Settings::get($opt);
|
||||
$params[$opt] = Settings::get($opt);
|
||||
}
|
||||
|
||||
// Load styles configs
|
||||
$styles_params = array(
|
||||
'chat_style' => ChatStyle::defaultStyle(),
|
||||
'page_style' => PageStyle::defaultStyle(),
|
||||
'chat_style' => ChatStyle::defaultStyle(),
|
||||
'page_style' => PageStyle::defaultStyle(),
|
||||
);
|
||||
|
||||
$chat_style_list = ChatStyle::availableStyles();
|
||||
$page_style_list = PageStyle::availableStyles();
|
||||
|
||||
if (Settings::get('enabletracking')) {
|
||||
$styles_params['invitation_style'] = InvitationStyle::defaultStyle();
|
||||
$invitation_style_list = InvitationStyle::availableStyles();
|
||||
$styles_params['invitation_style'] = InvitationStyle::defaultStyle();
|
||||
$invitation_style_list = InvitationStyle::availableStyles();
|
||||
}
|
||||
|
||||
if (isset($_POST['email']) && isset($_POST['title']) && isset($_POST['logo'])) {
|
||||
$params['email'] = getparam('email');
|
||||
$params['title'] = getparam('title');
|
||||
$params['logo'] = getparam('logo');
|
||||
$params['hosturl'] = getparam('hosturl');
|
||||
$params['usernamepattern'] = getparam('usernamepattern');
|
||||
$params['chattitle'] = getparam('chattitle');
|
||||
$params['geolink'] = getparam('geolink');
|
||||
$params['geolinkparams'] = getparam('geolinkparams');
|
||||
$params['sendmessagekey'] = verifyparam('sendmessagekey', "/^c?enter$/");
|
||||
$params['cron_key'] = getparam('cronkey');
|
||||
$params['email'] = get_param('email');
|
||||
$params['title'] = get_param('title');
|
||||
$params['logo'] = get_param('logo');
|
||||
$params['hosturl'] = get_param('hosturl');
|
||||
$params['usernamepattern'] = get_param('usernamepattern');
|
||||
$params['chattitle'] = get_param('chattitle');
|
||||
$params['geolink'] = get_param('geolink');
|
||||
$params['geolinkparams'] = get_param('geolinkparams');
|
||||
$params['sendmessagekey'] = verify_param('sendmessagekey', "/^c?enter$/");
|
||||
$params['cron_key'] = get_param('cronkey');
|
||||
|
||||
$styles_params['chat_style'] = verifyparam("chat_style", "/^\w+$/", $styles_params['chat_style']);
|
||||
if (!in_array($styles_params['chat_style'], $chat_style_list)) {
|
||||
$styles_params['chat_style'] = $chat_style_list[0];
|
||||
}
|
||||
$styles_params['chat_style'] = verify_param("chat_style", "/^\w+$/", $styles_params['chat_style']);
|
||||
if (!in_array($styles_params['chat_style'], $chat_style_list)) {
|
||||
$styles_params['chat_style'] = $chat_style_list[0];
|
||||
}
|
||||
|
||||
$styles_params['page_style'] = verifyparam("page_style", "/^\w+$/", $styles_params['page_style']);
|
||||
if (!in_array($styles_params['page_style'], $page_style_list)) {
|
||||
$styles_params['page_style'] = $page_style_list[0];
|
||||
}
|
||||
$styles_params['page_style'] = verify_param("page_style", "/^\w+$/", $styles_params['page_style']);
|
||||
if (!in_array($styles_params['page_style'], $page_style_list)) {
|
||||
$styles_params['page_style'] = $page_style_list[0];
|
||||
}
|
||||
|
||||
if (Settings::get('enabletracking')) {
|
||||
$styles_params['invitation_style'] = verifyparam("invitation_style", "/^\w+$/", $styles_params['invitation_style']);
|
||||
if (!in_array($styles_params['invitation_style'], $invitation_style_list)) {
|
||||
$styles_params['invitation_style'] = $invitation_style_list[0];
|
||||
}
|
||||
}
|
||||
if (Settings::get('enabletracking')) {
|
||||
$styles_params['invitation_style'] = verify_param(
|
||||
"invitation_style",
|
||||
"/^\w+$/",
|
||||
$styles_params['invitation_style']
|
||||
);
|
||||
if (!in_array($styles_params['invitation_style'], $invitation_style_list)) {
|
||||
$styles_params['invitation_style'] = $invitation_style_list[0];
|
||||
}
|
||||
}
|
||||
|
||||
if ($params['email'] && !is_valid_email($params['email'])) {
|
||||
$page['errors'][] = getlocal("settings.wrong.email");
|
||||
}
|
||||
if ($params['email'] && !is_valid_email($params['email'])) {
|
||||
$page['errors'][] = getlocal("settings.wrong.email");
|
||||
}
|
||||
|
||||
if ($params['geolinkparams']) {
|
||||
foreach (preg_split("/,/", $params['geolinkparams']) as $oneparam) {
|
||||
if (!preg_match("/^\s*(toolbar|scrollbars|location|status|menubar|width|height|resizable)=\d{1,4}$/", $oneparam)) {
|
||||
$page['errors'][] = "Wrong link parameter: \"$oneparam\", should be one of 'toolbar, scrollbars, location, status, menubar, width, height or resizable'";
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($params['geolinkparams']) {
|
||||
foreach (preg_split("/,/", $params['geolinkparams']) as $one_param) {
|
||||
$wrong_param = !preg_match(
|
||||
"/^\s*(toolbar|scrollbars|location|status|menubar|width|height|resizable)=\d{1,4}$/",
|
||||
$one_param
|
||||
);
|
||||
if ($wrong_param) {
|
||||
$page['errors'][] = "Wrong link parameter: \"$one_param\", "
|
||||
. "should be one of 'toolbar, scrollbars, location, "
|
||||
. "status, menubar, width, height or resizable'";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (preg_match("/^[0-9A-z]*$/", $params['cron_key']) == 0) {
|
||||
$page['errors'][] = getlocal("settings.wrong.cronkey");
|
||||
}
|
||||
if (preg_match("/^[0-9A-z]*$/", $params['cron_key']) == 0) {
|
||||
$page['errors'][] = getlocal("settings.wrong.cronkey");
|
||||
}
|
||||
|
||||
if (count($page['errors']) == 0) {
|
||||
// Update system settings
|
||||
foreach ($options as $opt) {
|
||||
Settings::set($opt,$params[$opt]);
|
||||
}
|
||||
Settings::update();
|
||||
if (count($page['errors']) == 0) {
|
||||
// Update system settings
|
||||
foreach ($options as $opt) {
|
||||
Settings::set($opt, $params[$opt]);
|
||||
}
|
||||
Settings::update();
|
||||
|
||||
// Update styles params
|
||||
ChatStyle::setDefaultStyle($styles_params['chat_style']);
|
||||
PageStyle::setDefaultStyle($styles_params['page_style']);
|
||||
if (Settings::get('enabletracking')) {
|
||||
InvitationStyle::setDefaultStyle($styles_params['invitation_style']);
|
||||
}
|
||||
// Update styles params
|
||||
ChatStyle::setDefaultStyle($styles_params['chat_style']);
|
||||
PageStyle::setDefaultStyle($styles_params['page_style']);
|
||||
if (Settings::get('enabletracking')) {
|
||||
InvitationStyle::setDefaultStyle($styles_params['invitation_style']);
|
||||
}
|
||||
|
||||
// Redirect the user
|
||||
header("Location: " . MIBEW_WEB_ROOT . "/operator/settings.php?stored");
|
||||
exit;
|
||||
}
|
||||
// Redirect the user
|
||||
header("Location: " . MIBEW_WEB_ROOT . "/operator/settings.php?stored");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$page['formemail'] = topage($params['email']);
|
||||
$page['formtitle'] = topage($params['title']);
|
||||
$page['formlogo'] = topage($params['logo']);
|
||||
$page['formhosturl'] = topage($params['hosturl']);
|
||||
$page['formgeolink'] = topage($params['geolink']);
|
||||
$page['formgeolinkparams'] = topage($params['geolinkparams']);
|
||||
$page['formusernamepattern'] = topage($params['usernamepattern']);
|
||||
$page['formemail'] = to_page($params['email']);
|
||||
$page['formtitle'] = to_page($params['title']);
|
||||
$page['formlogo'] = to_page($params['logo']);
|
||||
$page['formhosturl'] = to_page($params['hosturl']);
|
||||
$page['formgeolink'] = to_page($params['geolink']);
|
||||
$page['formgeolinkparams'] = to_page($params['geolinkparams']);
|
||||
$page['formusernamepattern'] = to_page($params['usernamepattern']);
|
||||
$page['formpagestyle'] = $styles_params['page_style'];
|
||||
$page['availablePageStyles'] = $page_style_list;
|
||||
$page['formchatstyle'] = $styles_params['chat_style'];
|
||||
$page['formchattitle'] = topage($params['chattitle']);
|
||||
$page['formchattitle'] = to_page($params['chattitle']);
|
||||
$page['formsendmessagekey'] = $params['sendmessagekey'];
|
||||
$page['availableChatStyles'] = $chat_style_list;
|
||||
$page['stored'] = isset($_GET['stored']);
|
||||
@ -157,18 +167,13 @@ $page['title'] = getlocal("settings.title");
|
||||
$page['menuid'] = "settings";
|
||||
|
||||
if (Settings::get('enabletracking')) {
|
||||
$page['forminvitationstyle'] = $styles_params['invitation_style'];
|
||||
$page['availableInvitationStyles'] = $invitation_style_list;
|
||||
$page['forminvitationstyle'] = $styles_params['invitation_style'];
|
||||
$page['availableInvitationStyles'] = $invitation_style_list;
|
||||
}
|
||||
|
||||
$page = array_merge(
|
||||
$page,
|
||||
prepare_menu($operator)
|
||||
);
|
||||
$page = array_merge($page, prepare_menu($operator));
|
||||
|
||||
$page['tabs'] = setup_settings_tabs(0);
|
||||
|
||||
$page_style = new PageStyle(PageStyle::currentStyle());
|
||||
$page_style->render('settings', $page);
|
||||
|
||||
?>
|
@ -21,11 +21,12 @@ use Mibew\Settings;
|
||||
use Mibew\Style\PageStyle;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(dirname(dirname(__FILE__)).'/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/chat.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/statistics.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/cron.php');
|
||||
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/chat.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/statistics.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/cron.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/track.php');
|
||||
|
||||
$operator = check_login();
|
||||
force_password($operator);
|
||||
@ -33,164 +34,158 @@ force_password($operator);
|
||||
setlocale(LC_TIME, getstring("time.locale"));
|
||||
|
||||
$page = array();
|
||||
$page['operator'] = topage(get_operator_name($operator));
|
||||
$page['operator'] = to_page(get_operator_name($operator));
|
||||
$page['availableDays'] = range(1, 31);
|
||||
$page['availableMonth'] = get_month_selection(time() - 400 * 24 * 60 * 60, time() + 50 * 24 * 60 * 60);
|
||||
$page['showresults'] = false;
|
||||
$statisticstype = verifyparam("type", "/^(bydate|byagent|bypage)$/", "bydate");
|
||||
$page['type'] = $statisticstype;
|
||||
$page['showbydate'] = ($statisticstype == 'bydate');
|
||||
$page['showbyagent'] = ($statisticstype == 'byagent');
|
||||
$page['showbypage'] = ($statisticstype == 'bypage');
|
||||
$statistics_type = verify_param("type", "/^(bydate|byagent|bypage)$/", "bydate");
|
||||
$page['type'] = $statistics_type;
|
||||
$page['showbydate'] = ($statistics_type == 'bydate');
|
||||
$page['showbyagent'] = ($statistics_type == 'byagent');
|
||||
$page['showbypage'] = ($statistics_type == 'bypage');
|
||||
|
||||
$page['cron_path'] = cron_get_uri(Settings::get('cron_key'));
|
||||
$page['last_cron_run'] = Settings::get('_last_cron_run');
|
||||
|
||||
$page['show_invitations_info'] = (bool)Settings::get('enabletracking');
|
||||
$page['show_invitations_info'] = (bool) Settings::get('enabletracking');
|
||||
|
||||
$page['errors'] = array();
|
||||
|
||||
if (isset($_GET['startday'])) {
|
||||
$startday = verifyparam("startday", "/^\d+$/");
|
||||
$startmonth = verifyparam("startmonth", "/^\d{2}.\d{2}$/");
|
||||
$endday = verifyparam("endday", "/^\d+$/");
|
||||
$endmonth = verifyparam("endmonth", "/^\d{2}.\d{2}$/");
|
||||
$start = get_form_date($startday, $startmonth);
|
||||
$end = get_form_date($endday, $endmonth) + 24 * 60 * 60;
|
||||
|
||||
$start_day = verify_param("startday", "/^\d+$/");
|
||||
$start_month = verify_param("startmonth", "/^\d{2}.\d{2}$/");
|
||||
$end_day = verify_param("endday", "/^\d+$/");
|
||||
$end_month = verify_param("endmonth", "/^\d{2}.\d{2}$/");
|
||||
$start = get_form_date($start_day, $start_month);
|
||||
$end = get_form_date($end_day, $end_month) + 24 * 60 * 60;
|
||||
} else {
|
||||
$curr = getdate(time());
|
||||
if ($curr['mday'] < 7) {
|
||||
// previous month
|
||||
if ($curr['mon'] == 1) {
|
||||
$month = 12;
|
||||
$year = $curr['year'] - 1;
|
||||
} else {
|
||||
$month = $curr['mon'] - 1;
|
||||
$year = $curr['year'];
|
||||
}
|
||||
$start = mktime(0, 0, 0, $month, 1, $year);
|
||||
$end = mktime(0, 0, 0, $month, date("t", $start), $year) + 24 * 60 * 60;
|
||||
} else {
|
||||
$start = mktime(0, 0, 0, $curr['mon'], 1, $curr['year']);
|
||||
$end = time() + 24 * 60 * 60;
|
||||
}
|
||||
$curr = getdate(time());
|
||||
if ($curr['mday'] < 7) {
|
||||
// previous month
|
||||
if ($curr['mon'] == 1) {
|
||||
$month = 12;
|
||||
$year = $curr['year'] - 1;
|
||||
} else {
|
||||
$month = $curr['mon'] - 1;
|
||||
$year = $curr['year'];
|
||||
}
|
||||
$start = mktime(0, 0, 0, $month, 1, $year);
|
||||
$end = mktime(0, 0, 0, $month, date("t", $start), $year) + 24 * 60 * 60;
|
||||
} else {
|
||||
$start = mktime(0, 0, 0, $curr['mon'], 1, $curr['year']);
|
||||
$end = time() + 24 * 60 * 60;
|
||||
}
|
||||
}
|
||||
$page = array_merge(
|
||||
$page,
|
||||
set_form_date($start, "start"),
|
||||
set_form_date($end - 24 * 60 * 60, "end")
|
||||
$page,
|
||||
set_form_date($start, "start"),
|
||||
set_form_date($end - 24 * 60 * 60, "end")
|
||||
);
|
||||
|
||||
if ($start > $end) {
|
||||
$page['errors'][] = getlocal("statistics.wrong.dates");
|
||||
$page['errors'][] = getlocal("statistics.wrong.dates");
|
||||
}
|
||||
|
||||
$activetab = 0;
|
||||
$active_tab = 0;
|
||||
$db = Database::getInstance();
|
||||
if ($statisticstype == 'bydate') {
|
||||
$page['reportByDate'] = $db->query(
|
||||
"SELECT DATE(FROM_UNIXTIME(date)) AS date, " .
|
||||
"threads, " .
|
||||
"missedthreads, " .
|
||||
"sentinvitations, " .
|
||||
"acceptedinvitations, " .
|
||||
"rejectedinvitations, " .
|
||||
"ignoredinvitations, " .
|
||||
"operatormessages AS agents, " .
|
||||
"usermessages AS users, " .
|
||||
"averagewaitingtime AS avgwaitingtime, " .
|
||||
"averagechattime AS avgchattime " .
|
||||
"FROM {chatthreadstatistics} s " .
|
||||
"WHERE s.date >= :start " .
|
||||
"AND s.date < :end " .
|
||||
"GROUP BY DATE(FROM_UNIXTIME(date)) " .
|
||||
"ORDER BY s.date DESC",
|
||||
array(
|
||||
':start' => $start,
|
||||
':end' => $end
|
||||
),
|
||||
array('return_rows' => Database::RETURN_ALL_ROWS)
|
||||
);
|
||||
if ($statistics_type == 'bydate') {
|
||||
$page['reportByDate'] = $db->query(
|
||||
("SELECT DATE(FROM_UNIXTIME(date)) AS date, "
|
||||
. "threads, "
|
||||
. "missedthreads, "
|
||||
. "sentinvitations, "
|
||||
. "acceptedinvitations, "
|
||||
. "rejectedinvitations, "
|
||||
. "ignoredinvitations, "
|
||||
. "operatormessages AS agents, "
|
||||
. "usermessages AS users, "
|
||||
. "averagewaitingtime AS avgwaitingtime, "
|
||||
. "averagechattime AS avgchattime "
|
||||
. "FROM {chatthreadstatistics} s "
|
||||
. "WHERE s.date >= :start "
|
||||
. "AND s.date < :end "
|
||||
. "GROUP BY DATE(FROM_UNIXTIME(date)) "
|
||||
. "ORDER BY s.date DESC"),
|
||||
array(
|
||||
':start' => $start,
|
||||
':end' => $end,
|
||||
),
|
||||
array('return_rows' => Database::RETURN_ALL_ROWS)
|
||||
);
|
||||
|
||||
$page['reportByDateTotal'] = $db->query(
|
||||
"SELECT DATE(FROM_UNIXTIME(date)) AS date, " .
|
||||
"SUM(threads) AS threads, " .
|
||||
"SUM(missedthreads) AS missedthreads, " .
|
||||
"SUM(sentinvitations) AS sentinvitations, " .
|
||||
"SUM(acceptedinvitations) AS acceptedinvitations, " .
|
||||
"SUM(rejectedinvitations) AS rejectedinvitations, " .
|
||||
"SUM(ignoredinvitations) AS ignoredinvitations, " .
|
||||
"SUM(operatormessages) AS agents, " .
|
||||
"SUM(usermessages) AS users, " .
|
||||
"ROUND(SUM(averagewaitingtime * s.threads) / SUM(s.threads),1) AS avgwaitingtime, " .
|
||||
"ROUND(SUM(averagechattime * s.threads) / SUM(s.threads),1) AS avgchattime " .
|
||||
"FROM {chatthreadstatistics} s " .
|
||||
"WHERE s.date >= :start " .
|
||||
"AND s.date < :end",
|
||||
array(
|
||||
':start' => $start,
|
||||
':end' => $end
|
||||
),
|
||||
array('return_rows' => Database::RETURN_ONE_ROW)
|
||||
);
|
||||
$page['reportByDateTotal'] = $db->query(
|
||||
("SELECT DATE(FROM_UNIXTIME(date)) AS date, "
|
||||
. "SUM(threads) AS threads, "
|
||||
. "SUM(missedthreads) AS missedthreads, "
|
||||
. "SUM(sentinvitations) AS sentinvitations, "
|
||||
. "SUM(acceptedinvitations) AS acceptedinvitations, "
|
||||
. "SUM(rejectedinvitations) AS rejectedinvitations, "
|
||||
. "SUM(ignoredinvitations) AS ignoredinvitations, "
|
||||
. "SUM(operatormessages) AS agents, "
|
||||
. "SUM(usermessages) AS users, "
|
||||
. "ROUND(SUM(averagewaitingtime * s.threads) / SUM(s.threads),1) AS avgwaitingtime, "
|
||||
. "ROUND(SUM(averagechattime * s.threads) / SUM(s.threads),1) AS avgchattime "
|
||||
. "FROM {chatthreadstatistics} s "
|
||||
. "WHERE s.date >= :start "
|
||||
. "AND s.date < :end"),
|
||||
array(
|
||||
':start' => $start,
|
||||
':end' => $end,
|
||||
),
|
||||
array('return_rows' => Database::RETURN_ONE_ROW)
|
||||
);
|
||||
|
||||
$activetab = 0;
|
||||
} elseif($statisticstype == 'byagent') {
|
||||
$page['reportByAgent'] = $db->query(
|
||||
"SELECT o.vclocalename AS name, " .
|
||||
"SUM(s.threads) AS threads, " .
|
||||
"SUM(s.messages) AS msgs, " .
|
||||
"ROUND( " .
|
||||
"SUM(s.averagelength * s.messages) / SUM(s.messages), " .
|
||||
"1) AS avglen, " .
|
||||
"SUM(sentinvitations) AS sentinvitations, " .
|
||||
"SUM(acceptedinvitations) AS acceptedinvitations, " .
|
||||
"SUM(rejectedinvitations) AS rejectedinvitations, " .
|
||||
"SUM(ignoredinvitations) AS ignoredinvitations " .
|
||||
"FROM {chatoperatorstatistics} s, {chatoperator} o " .
|
||||
"WHERE s.operatorid = o.operatorid " .
|
||||
"AND s.date >= :start " .
|
||||
"AND s.date < :end " .
|
||||
"GROUP BY s.operatorid",
|
||||
array(
|
||||
':start' => $start,
|
||||
':end' => $end
|
||||
),
|
||||
array('return_rows' => Database::RETURN_ALL_ROWS)
|
||||
);
|
||||
$activetab = 1;
|
||||
} elseif($statisticstype == 'bypage') {
|
||||
$page['reportByPage'] = $db->query(
|
||||
"SELECT SUM(visits) as visittimes, " .
|
||||
"address, " .
|
||||
"SUM(chats) as chattimes, " .
|
||||
"SUM(sentinvitations) AS sentinvitations, " .
|
||||
"SUM(acceptedinvitations) AS acceptedinvitations, " .
|
||||
"SUM(rejectedinvitations) AS rejectedinvitations, " .
|
||||
"SUM(ignoredinvitations) AS ignoredinvitations " .
|
||||
"FROM {visitedpagestatistics} " .
|
||||
"WHERE date >= :start " .
|
||||
"AND date < :end " .
|
||||
"GROUP BY address",
|
||||
array(':start' => $start, ':end' => $end),
|
||||
array('return_rows' => Database::RETURN_ALL_ROWS)
|
||||
);
|
||||
$activetab = 2;
|
||||
$active_tab = 0;
|
||||
} elseif ($statistics_type == 'byagent') {
|
||||
$page['reportByAgent'] = $db->query(
|
||||
("SELECT o.vclocalename AS name, "
|
||||
. "SUM(s.threads) AS threads, "
|
||||
. "SUM(s.messages) AS msgs, "
|
||||
. "ROUND( "
|
||||
. "SUM(s.averagelength * s.messages) / SUM(s.messages), "
|
||||
. "1) AS avglen, "
|
||||
. "SUM(sentinvitations) AS sentinvitations, "
|
||||
. "SUM(acceptedinvitations) AS acceptedinvitations, "
|
||||
. "SUM(rejectedinvitations) AS rejectedinvitations, "
|
||||
. "SUM(ignoredinvitations) AS ignoredinvitations "
|
||||
. "FROM {chatoperatorstatistics} s, {chatoperator} o "
|
||||
. "WHERE s.operatorid = o.operatorid "
|
||||
. "AND s.date >= :start "
|
||||
. "AND s.date < :end "
|
||||
. "GROUP BY s.operatorid"),
|
||||
array(
|
||||
':start' => $start,
|
||||
':end' => $end,
|
||||
),
|
||||
array('return_rows' => Database::RETURN_ALL_ROWS)
|
||||
);
|
||||
$active_tab = 1;
|
||||
} elseif ($statistics_type == 'bypage') {
|
||||
$page['reportByPage'] = $db->query(
|
||||
("SELECT SUM(visits) as visittimes, "
|
||||
. "address, "
|
||||
. "SUM(chats) as chattimes, "
|
||||
. "SUM(sentinvitations) AS sentinvitations, "
|
||||
. "SUM(acceptedinvitations) AS acceptedinvitations, "
|
||||
. "SUM(rejectedinvitations) AS rejectedinvitations, "
|
||||
. "SUM(ignoredinvitations) AS ignoredinvitations "
|
||||
. "FROM {visitedpagestatistics} "
|
||||
. "WHERE date >= :start "
|
||||
. "AND date < :end "
|
||||
. "GROUP BY address"),
|
||||
array(':start' => $start, ':end' => $end),
|
||||
array('return_rows' => Database::RETURN_ALL_ROWS)
|
||||
);
|
||||
$active_tab = 2;
|
||||
}
|
||||
$page['showresults'] = count($page['errors']) == 0;
|
||||
|
||||
$page['title'] = getlocal("statistics.title");
|
||||
$page['menuid'] = "statistics";
|
||||
|
||||
$page = array_merge(
|
||||
$page,
|
||||
prepare_menu($operator)
|
||||
);
|
||||
$page = array_merge($page, prepare_menu($operator));
|
||||
|
||||
$page['tabs'] = setup_statistics_tabs($activetab);
|
||||
$page['tabs'] = setup_statistics_tabs($active_tab);
|
||||
|
||||
$page_style = new PageStyle(PageStyle::currentStyle());
|
||||
$page_style->render('statistics', $page);
|
||||
|
||||
?>
|
@ -20,21 +20,22 @@ use Mibew\Style\ChatStyle;
|
||||
use Mibew\Style\PageStyle;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(dirname(dirname(__FILE__)).'/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/chat.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/pagination.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/groups.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/settings.php');
|
||||
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/chat.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/pagination.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/groups.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/settings.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/track.php');
|
||||
|
||||
$operator = check_login();
|
||||
|
||||
$stylelist = ChatStyle::availableStyles();
|
||||
$style_list = ChatStyle::availableStyles();
|
||||
|
||||
$preview = verifyparam("preview", "/^\w+$/", "default");
|
||||
if (!in_array($preview, $stylelist)) {
|
||||
$style_names = array_keys($stylelist);
|
||||
$preview = $stylelist[$style_names[0]];
|
||||
$preview = verify_param("preview", "/^\w+$/", "default");
|
||||
if (!in_array($preview, $style_list)) {
|
||||
$style_names = array_keys($style_list);
|
||||
$preview = $style_list[$style_names[0]];
|
||||
}
|
||||
|
||||
$chat_style = new ChatStyle($preview);
|
||||
@ -42,29 +43,24 @@ $chat_style = new ChatStyle($preview);
|
||||
$style_config = $chat_style->configurations();
|
||||
|
||||
$screenshots = array();
|
||||
foreach($style_config['screenshots'] as $name => $desc) {
|
||||
$screenshots[] = array(
|
||||
'name' => $name,
|
||||
'file' => MIBEW_WEB_ROOT . '/' . $chat_style->filesPath()
|
||||
. '/screenshots/' . $name . '.png',
|
||||
'description' => $desc
|
||||
);
|
||||
foreach ($style_config['screenshots'] as $name => $desc) {
|
||||
$screenshots[] = array(
|
||||
'name' => $name,
|
||||
'file' => (MIBEW_WEB_ROOT . '/' . $chat_style->filesPath()
|
||||
. '/screenshots/' . $name . '.png'),
|
||||
'description' => $desc
|
||||
);
|
||||
}
|
||||
|
||||
$page['formpreview'] = $preview;
|
||||
$page['availablePreviews'] = $stylelist;
|
||||
$page['availablePreviews'] = $style_list;
|
||||
$page['screenshotsList'] = $screenshots;
|
||||
$page['title'] = getlocal("page.preview.title");
|
||||
$page['menuid'] = "settings";
|
||||
|
||||
$page = array_merge(
|
||||
$page,
|
||||
prepare_menu($operator)
|
||||
);
|
||||
$page = array_merge($page, prepare_menu($operator));
|
||||
|
||||
$page['tabs'] = setup_settings_tabs(4);
|
||||
|
||||
$page_style = new PageStyle(PageStyle::currentStyle());
|
||||
$page_style->render('themes', $page);
|
||||
|
||||
?>
|
@ -20,11 +20,12 @@ use Mibew\Thread;
|
||||
use Mibew\Style\PageStyle;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(dirname(dirname(__FILE__)).'/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/chat.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/groups.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/userinfo.php');
|
||||
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/chat.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/groups.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/userinfo.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/track.php');
|
||||
|
||||
$operator = check_login();
|
||||
|
||||
@ -33,31 +34,26 @@ $page = array();
|
||||
setlocale(LC_TIME, getstring("time.locale"));
|
||||
|
||||
if (isset($_GET['threadid'])) {
|
||||
// Load thread info
|
||||
$threadid = verifyparam("threadid", "/^(\d{1,9})?$/", "");
|
||||
$thread = Thread::load($threadid);
|
||||
$group = group_by_id($thread->groupId);
|
||||
// Load thread info
|
||||
$thread_id = verify_param("threadid", "/^(\d{1,9})?$/", "");
|
||||
$thread = Thread::load($thread_id);
|
||||
$group = group_by_id($thread->groupId);
|
||||
|
||||
$thread_info = array(
|
||||
'thread' => $thread,
|
||||
'groupName' => get_group_name($group),
|
||||
);
|
||||
$page['thread_info'] = $thread_info;
|
||||
$thread_info = array(
|
||||
'thread' => $thread,
|
||||
'groupName' => get_group_name($group),
|
||||
);
|
||||
$page['thread_info'] = $thread_info;
|
||||
|
||||
// Build messages list
|
||||
$lastid = -1;
|
||||
$messages = $thread_info['thread']->getMessages(false, $lastid);
|
||||
$page['threadMessages'] = json_encode($messages);
|
||||
// Build messages list
|
||||
$last_id = -1;
|
||||
$messages = $thread_info['thread']->getMessages(false, $last_id);
|
||||
$page['threadMessages'] = json_encode($messages);
|
||||
}
|
||||
|
||||
$page['title'] = getlocal("thread.chat_log");
|
||||
|
||||
$page = array_merge(
|
||||
$page,
|
||||
prepare_menu($operator, false)
|
||||
);
|
||||
$page = array_merge($page, prepare_menu($operator, false));
|
||||
|
||||
$page_style = new PageStyle(PageStyle::currentStyle());
|
||||
$page_style->render('thread_log', $page);
|
||||
|
||||
?>
|
@ -20,10 +20,10 @@ use Mibew\Settings;
|
||||
use Mibew\Style\PageStyle;
|
||||
|
||||
// Initialize libraries
|
||||
require_once(dirname(dirname(__FILE__)).'/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/chat.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT.'/libs/track.php');
|
||||
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/chat.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/operator.php');
|
||||
require_once(MIBEW_FS_ROOT . '/libs/track.php');
|
||||
|
||||
$operator = check_login();
|
||||
|
||||
@ -34,22 +34,20 @@ if (Settings::get('enabletracking') == "0") {
|
||||
}
|
||||
|
||||
if (isset($_GET['thread'])) {
|
||||
$threadid = verifyparam("thread", "/^\d{1,8}$/");
|
||||
}
|
||||
else {
|
||||
$visitorid = verifyparam("visitor", "/^\d{1,8}$/");
|
||||
$thread_id = verify_param("thread", "/^\d{1,8}$/");
|
||||
} else {
|
||||
$visitor_id = verify_param("visitor", "/^\d{1,8}$/");
|
||||
}
|
||||
|
||||
if (isset($threadid)) {
|
||||
$visitor = track_get_visitor_by_threadid($threadid);
|
||||
if (isset($thread_id)) {
|
||||
$visitor = track_get_visitor_by_thread_id($thread_id);
|
||||
if (!$visitor) {
|
||||
die("Wrong thread!");
|
||||
die("Wrong thread!");
|
||||
}
|
||||
}
|
||||
else {
|
||||
$visitor = track_get_visitor_by_id($visitorid);
|
||||
} else {
|
||||
$visitor = track_get_visitor_by_id($visitor_id);
|
||||
if (!$visitor) {
|
||||
die("Wrong visitor!");
|
||||
die("Wrong visitor!");
|
||||
}
|
||||
}
|
||||
$path = track_get_path($visitor);
|
||||
@ -58,13 +56,13 @@ $page['entry'] = htmlspecialchars($visitor['entry']);
|
||||
$page['history'] = array();
|
||||
ksort($path);
|
||||
foreach ($path as $k => $v) {
|
||||
$page['history'][] = array( 'date' => date_to_text($k),
|
||||
'link' => htmlspecialchars($v) );
|
||||
$page['history'][] = array(
|
||||
'date' => date_to_text($k),
|
||||
'link' => htmlspecialchars($v),
|
||||
);
|
||||
}
|
||||
|
||||
$page['title'] = getlocal("tracked.path");
|
||||
|
||||
$page_style = new PageStyle(PageStyle::currentStyle());
|
||||
$page_style->render('tracked', $page);
|
||||
|
||||
?>
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user