mirror of
https://github.com/Mibew/mibew.git
synced 2025-03-03 18:38:31 +03:00
Create controller for button image
This commit is contained in:
parent
8db2b94203
commit
35605b5af3
@ -1,74 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* Copyright 2005-2014 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Import namespaces and classes of the core
|
|
||||||
use Mibew\Settings;
|
|
||||||
use Mibew\Thread;
|
|
||||||
|
|
||||||
// Initialize libraries
|
|
||||||
require_once(dirname(__FILE__) . '/libs/init.php');
|
|
||||||
|
|
||||||
$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['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 = 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);
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* Copyright 2005-2014 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
require_once(dirname(__FILE__) . '/b.php');
|
|
109
src/mibew/libs/classes/Mibew/Controller/ButtonController.php
Normal file
109
src/mibew/libs/classes/Mibew/Controller/ButtonController.php
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Copyright 2005-2014 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Mibew\Controller;
|
||||||
|
|
||||||
|
use Mibew\Settings;
|
||||||
|
use Mibew\Thread;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents button-related actions
|
||||||
|
*/
|
||||||
|
class ButtonController extends AbstractController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Generate content for "/b" route.
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @return string Rendered page content
|
||||||
|
*/
|
||||||
|
public function indexAction(Request $request)
|
||||||
|
{
|
||||||
|
$referer = $request->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;
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,7 @@
|
|||||||
|
button:
|
||||||
|
path: /b
|
||||||
|
defaults: { _controller: Mibew\Controller\ButtonController::indexAction }
|
||||||
|
|
||||||
license:
|
license:
|
||||||
path: /license
|
path: /license
|
||||||
defaults: { _controller: Mibew\Controller\LicenseController::indexAction }
|
defaults: { _controller: Mibew\Controller\LicenseController::indexAction }
|
||||||
|
@ -70,7 +70,7 @@ if (!$lang || !in_array($lang, $image_locales)) {
|
|||||||
$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);
|
$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) {
|
if ($group_id) {
|
||||||
$image_href .= "&group=$group_id";
|
$image_href .= "&group=$group_id";
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user