diff --git a/~dev_rating/application/bootstrap.php b/~dev_rating/application/bootstrap.php index 19dcd3ba3b2a32acce0ebaa93f81e6c78fdc5b63..86da4ae135544e383630380eb012f3ac1d11ad21 100644 --- a/~dev_rating/application/bootstrap.php +++ b/~dev_rating/application/bootstrap.php @@ -275,6 +275,13 @@ Route::set('admin:common', 'admin(/<controller>(/<action>(/<param1>(:<param2>))) 'action' => 'index' ]); +Route::set('support:image', 'support/image(/<action>)/<id>')//, ['id' => '[0-9]+']) + ->defaults([ + 'directory' => 'Support', + 'controller' => 'Image', + 'action' => 'view' + ]); + // --------------- Java session provider -------------- Route::set('javaSessionProvider', 'java_authentication') ->defaults([ diff --git a/~dev_rating/application/classes/Controller/Environment/Admin.php b/~dev_rating/application/classes/Controller/Environment/Admin.php index 627ae08c957d9a6e0269e65700e84562f8eac83e..82da3feb628440c50a83fd06ada2780ebf833c4d 100644 --- a/~dev_rating/application/classes/Controller/Environment/Admin.php +++ b/~dev_rating/application/classes/Controller/Environment/Admin.php @@ -10,4 +10,4 @@ class Controller_Environment_Admin extends Controller_Environment_User $this->user->checkAccess(User::RIGHTS_ADMIN); } -} \ No newline at end of file +} diff --git a/~dev_rating/application/classes/Controller/Support/Image.php b/~dev_rating/application/classes/Controller/Support/Image.php new file mode 100644 index 0000000000000000000000000000000000000000..bd474046378670132773761947cd467ddeb1a7ac --- /dev/null +++ b/~dev_rating/application/classes/Controller/Support/Image.php @@ -0,0 +1,39 @@ +<?php defined('SYSPATH') or die('No direct script access.'); + +class Controller_Support_Image extends Controller_Environment_Admin +{ + public function before() { + parent::before(); + } + + public function after() { + + } + + public function action_view() { + $filename = DOCROOT . SupportImageSaver::directoryToSave . + $this->request->param('id') . SupportImageSaver::imageExtension; + $this->responseImage($filename); + } + + public function action_preview() { + $filename = DOCROOT . SupportImageSaver::directoryToSave . + SupportImageSaver::thumbPref . $this->request->param('id') . SupportImageSaver::imageExtension; + $this->responseImage($filename); + } + + private function responseImage($filename) { + + if (!file_exists($filename) OR !is_file($filename)) { + throw new HTTP_Exception_404('Picture not found'); + } + + $image = file_get_contents($filename); + + $info = getimagesize($filename); + $mime = $info['mime']; + $this->response->headers('Content-Type', $mime) + ->body($image); + } + +} diff --git a/~dev_rating/application/classes/SupportImageSaver.php b/~dev_rating/application/classes/SupportImageSaver.php index 52dd534890369ca87bccf6d9970d96eeac7711f6..3fa925fb93ff52e728f450bace3e675b5d73fe9a 100644 --- a/~dev_rating/application/classes/SupportImageSaver.php +++ b/~dev_rating/application/classes/SupportImageSaver.php @@ -3,11 +3,14 @@ class SupportImageSaver { const savingStatusOk = true; + const directoryToSave = 'support/img/'; + const imageExtension = '.jpg'; + const thumbPref = 'thumb_'; private $_rootDir = DOCROOT; - private $_subDir = 'support/img/'; - private $_fileExt = '.jpg'; - private $_thumbSuf = 'thumb_'; + private $_subDir = self::directoryToSave; + private $_fileExt = self::imageExtension; + private $_thumbPref = self::thumbPref; private $_srcFilePath = null; private $_targetFilePath = null; @@ -23,7 +26,7 @@ class SupportImageSaver $this->_srcFilePath = $srcFilePath; $this->_targetFilePath = $dir . $file; - $this->_targetPreviewPath = $dir . $this->_thumbSuf . $file; + $this->_targetPreviewPath = $dir . $this->_thumbPref . $file; } public function saveImage() {