From 35605b5af3e2ca3bd64a6b125d8d76cf85211260 Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Thu, 8 May 2014 11:53:25 +0000 Subject: [PATCH] Create controller for button image --- src/mibew/b.php | 74 ------------ src/mibew/button.php | 18 --- .../Mibew/Controller/ButtonController.php | 109 ++++++++++++++++++ src/mibew/libs/routing.yml | 4 + src/mibew/operator/getcode.php | 2 +- 5 files changed, 114 insertions(+), 93 deletions(-) delete mode 100644 src/mibew/b.php delete mode 100644 src/mibew/button.php create mode 100644 src/mibew/libs/classes/Mibew/Controller/ButtonController.php diff --git a/src/mibew/b.php b/src/mibew/b.php deleted file mode 100644 index da2d5e6b..00000000 --- a/src/mibew/b.php +++ /dev/null @@ -1,74 +0,0 @@ -state != Thread::STATE_CLOSED) { - $msg = getstring2_( - "chat.client.visited.page", - array($referer), - $thread->locale, - true - ); - $thread->postMessage(Thread::KIND_FOR_AGENT, $msg); - } -} - -$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; -} - -$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($group_id) ? "on" : "off"; -$file_name = "locales/${lang}/button/${image}_${image_postfix}.gif"; - -$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($file_name)); -if (function_exists('fpassthru')) { - @fpassthru($fp); -} else { - while ((!feof($fp)) && (connection_status() == 0)) { - print(fread($fp, 1024 * 8)); - flush(); - } - fclose($fp); -} diff --git a/src/mibew/button.php b/src/mibew/button.php deleted file mode 100644 index afd17368..00000000 --- a/src/mibew/button.php +++ /dev/null @@ -1,18 +0,0 @@ -server->get('HTTP_REFERER', ''); + + 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, + true + ); + $thread->postMessage(Thread::KIND_FOR_AGENT, $msg); + } + } + + $image = $request->query->get('i', ''); + if (!preg_match("/^\w+$/", $image)) { + $image = 'mibew'; + } + + $lang = $request->query->get('lang', ''); + if (!preg_match("/^[\w-]{2,5}$/", $lang)) { + $lang = ''; + } + if (!$lang || !locale_exists($lang)) { + $lang = CURRENT_LOCALE; + } + + $group_id = $request->query->get('group', ''); + if (!preg_match("/^\d{1,8}$/", $group_id)) { + $group_id = false; + } + if ($group_id) { + if (Settings::get('enablegroups') == '1') { + $group = group_by_id($group_id); + if (!$group) { + $group_id = false; + } + } else { + $group_id = false; + } + } + + // Get image file content + $image_postfix = has_online_operators($group_id) ? "on" : "off"; + $file_name = "locales/${lang}/button/${image}_${image_postfix}.gif"; + + $fh = fopen($file_name, 'rb'); + if ($fh) { + // Create response with image in body + $file_size = filesize($file_name); + $content = fread($fh, $file_size); + fclose($fh); + $response = new Response($content, 200); + + // Set correct content info + $response->headers->set('Content-Type' ,'image/gif'); + $response->headers->set('Content-Length', $file_size); + } else { + $response = new Response('Not found', 404); + } + + // Disable caching + $response->headers->addCacheControlDirective('no-cache', true); + $response->headers->addCacheControlDirective('no-store', true); + $response->headers->addCacheControlDirective('must-revalidate', true); + $response->setExpires(new \DateTime('yesterday noon')); + $response->headers->set('Pragma', 'no-cache'); + + return $response; + } +} diff --git a/src/mibew/libs/routing.yml b/src/mibew/libs/routing.yml index 7d98d308..266f3095 100644 --- a/src/mibew/libs/routing.yml +++ b/src/mibew/libs/routing.yml @@ -1,3 +1,7 @@ +button: + path: /b + defaults: { _controller: Mibew\Controller\ButtonController::indexAction } + license: path: /license defaults: { _controller: Mibew\Controller\LicenseController::indexAction } diff --git a/src/mibew/operator/getcode.php b/src/mibew/operator/getcode.php index c16b1444..3aafc1e3 100644 --- a/src/mibew/operator/getcode.php +++ b/src/mibew/operator/getcode.php @@ -70,7 +70,7 @@ if (!$lang || !in_array($lang, $image_locales)) { $file = MIBEW_FS_ROOT . '/locales/${lang}/button/${image}_on.gif'; $size = get_gifimage_size($file); -$image_href = get_app_location($show_host, $force_secure) . "/b.php?i=$image&lang=$lang"; +$image_href = get_app_location($show_host, $force_secure) . "/b?i=$image&lang=$lang"; if ($group_id) { $image_href .= "&group=$group_id"; }