Permalink
Browse files

Media module supporting removed

  • Loading branch information...
1 parent 0ac3a82 commit 2b61129677e4254f081f6b27532ce0198ca9d94e @alexeyco alexeyco committed Mar 16, 2012
@@ -35,21 +35,20 @@ public function before()
parent::before();
$this->template
- ->set('js', Media::instance('js'))
- ->set('css', Media::instance('css'))
->set('global_config', array())
->set('title', '')
->set('content', '');
/**
* Load config
*/
- $this->_config = Arr::merge(Kohana::$config->load('media')->as_array(),
- Kohana::$config->load('wysiwyg.default'));
+ $this->_config = Kohana::$config
+ ->load('filebrowser')
+ ->as_array();
- $this->_directory = $this->_config['media_directory']
+ $this->_directory = $this->_config['public_directory']
.DIRECTORY_SEPARATOR
- .Kohana::$config->load('filebrowser.uploads_directory')
+ .$this->_config['uploads_directory']
.DIRECTORY_SEPARATOR;
$this->_path = str_replace('/', DIRECTORY_SEPARATOR, $this->request->param('path'));
@@ -102,7 +101,7 @@ public function action_flash()
protected function _filebrowser()
{
- $filter = Kohana::$config->load('filebrowser.filters.'.$this->request->action());
+ $filter = $this->_config['filters'][$this->request->action()];
$path = $this->_directory.$this->_path;
if ($this->request->is_ajax())
@@ -146,7 +145,7 @@ public function action_upload()
if ($_FILES)
{
// Check if file already exists
- if(is_file(APPPATH.$this->_directory.$this->_path.$_FILES['Filedata']['name']))
+ if(is_file(DOCROOT.$this->_directory.$this->_path.$_FILES['Filedata']['name']))
{
return $this->response->json(array(
'error' => __('FIle :file already exists in :path', array(
@@ -157,7 +156,7 @@ public function action_upload()
try
{
- Upload::save($_FILES['Filedata'], $_FILES['Filedata']['name'], APPPATH.$this->_directory.$this->_path);
+ Upload::save($_FILES['Filedata'], $_FILES['Filedata']['name'], DOCROOT.$this->_directory.$this->_path);
}
catch(Kohana_Exception $e)
{
@@ -180,8 +179,8 @@ public function action_move()
if (isset($_POST['to']))
{
- $from = APPPATH.$this->_directory.$this->_path;
- $to = APPPATH.$this->_directory.$_POST['to'].DIRECTORY_SEPARATOR.pathinfo($this->_path, PATHINFO_BASENAME);
+ $from = DOCROOT.$this->_directory.$this->_path;
+ $to = DOCROOT.$this->_directory.$_POST['to'].DIRECTORY_SEPARATOR.pathinfo($this->_path, PATHINFO_BASENAME);
try
{
@@ -205,7 +204,7 @@ public function action_download()
{
$this->auto_render = FALSE;
- $file = APPPATH.$this->_directory.$this->_path;
+ $file = DOCROOT.$this->_directory.$this->_path;
if ( ! file_exists($file) OR ! is_file($file))
{
@@ -231,15 +230,15 @@ public function action_rename()
{
$this->auto_render = FALSE;
- $path = rtrim(APPPATH.$this->_directory
+ $path = rtrim(DOCROOT.$this->_directory
.pathinfo($this->_path, PATHINFO_DIRNAME), '.')
.DIRECTORY_SEPARATOR;
$extension = pathinfo($this->_path, PATHINFO_EXTENSION);
$_POST = Arr::extract($_POST, array('filename'));
- $current_fname = APPPATH.$this->_directory.$this->_path;
+ $current_fname = DOCROOT.$this->_directory.$this->_path;
$new_fname = $path.DIRECTORY_SEPARATOR.$_POST['filename']
.( ! empty($extension) ? '.'.$extension : '');
@@ -293,7 +292,7 @@ public function action_rotate_left()
public function action_crop()
{
- $file = APPPATH.$this->_directory.$this->_path;
+ $file = DOCROOT.$this->_directory.$this->_path;
if ( ! is_file($file) OR ! $dimentions = Filebrowser::is_image($file))
throw new HTTP_Exception_404;
@@ -312,7 +311,7 @@ public function action_crop()
'offset_y'
));
- $path = rtrim(APPPATH.$this->_directory
+ $path = rtrim(DOCROOT.$this->_directory
.pathinfo($this->_path, PATHINFO_DIRNAME), '.')
.DIRECTORY_SEPARATOR;
@@ -409,12 +408,12 @@ public function action_add()
{
$this->auto_render = FALSE;
- $directory = APPPATH.$this->_directory.$this->_path;
+ $directory = DOCROOT.$this->_directory.$this->_path;
if ( ! is_dir($directory))
return $this->response->status(404);
- $path = rtrim(APPPATH.$this->_directory
+ $path = rtrim(DOCROOT.$this->_directory
.pathinfo($this->_path, PATHINFO_DIRNAME), '.')
.DIRECTORY_SEPARATOR;
@@ -461,7 +460,7 @@ protected function _rotate($degrees)
{
$this->auto_render = FALSE;
- $file = APPPATH.$this->_directory.$this->_path;
+ $file = DOCROOT.$this->_directory.$this->_path;
if ( ! is_file($file) OR ! Filebrowser::is_image($file))
{
@@ -491,7 +490,7 @@ public function action_delete()
{
try
{
- unlink(APPPATH.$this->_directory.$this->_path);
+ unlink(DOCROOT.$this->_directory.$this->_path);
}
catch(Exception $e)
{
@@ -517,9 +516,9 @@ public function action_thumb()
{
$this->auto_render = FALSE;
- $config = Kohana::$config->load('filebrowser.thumbs');
+ $config = $this->_config['thumbs'];
- $image = APPPATH.$this->_directory.$this->_path;
+ $image = DOCROOT.$this->_directory.$this->_path;
if ( ! is_file($image) OR ! ($dimentions = Filebrowser::is_image($image)))
{
@@ -592,7 +591,7 @@ public function after()
$this->template->global_config = array
(
- 'root' => $this->_config['media_directory'].'/'.Kohana::$config->load('filebrowser.uploads_directory'),
+ 'root' => $this->_config['public_directory'].'/'.$this->_config['uploads_directory'],
'dirs_url' => $route->uri(array('action' => 'dirs')),
'files_url' => $route->uri(array('action' => $this->request->action())),
'move_url' => $route->uri(array('action' => 'move')),
@@ -1,77 +1,65 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
-class Kohana_Controller_WYSIWYG extends Controller_Media {
+class Kohana_Controller_WYSIWYG extends Controller {
/**
- * WYSIWYG configuration array
+ * Filebrowser configuration array
*
* @var array
*/
- protected $_wysiwyg_config = array();
+ protected $_config = array();
+
+ public function before()
+ {
+ parent::before();
+
+ $this->_config = Kohana::$config
+ ->load('filebrowser')
+ ->as_array();
+ }
/**
- * WYSIWYG filebrowser configuration array
+ * Requested filename
*
- * @var array
+ * @var string
*/
- protected $_filebrowser_config = array();
+ protected $_file;
/**
- * Environment name
+ * Requested file extension
*
* @var string
*/
- protected $_environment;
+ protected $_ext;
- public function before()
+ public function action_media()
{
- parent::before();
+ $file = $this->request->param('file');
- $this->_wysiwyg_config = Kohana::$config->load('wysiwyg')
- ->as_array();
-
- $this->_filebrowser_config = Kohana::$config->load('filebrowser')
- ->as_array();
+ // Get the file info
+ $this->_ext = pathinfo($file, PATHINFO_EXTENSION);
+ $this->_file = str_replace('.'.$this->_ext, '', $file);
- // Be cause minimized WYSIWYG editor does not work...
- // I don't know why... I add this problem in my TODO
- // Alexey Popov :)
- $this->_config['filters'] = array
- (
- 'css' => $this->_config['filters']['css']
- );
+ // Find requested file
+ $file = Kohana::find_file('media', $this->_file, $this->_ext);
- $file = pathinfo($this->_file, PATHINFO_FILENAME);
-
- if ($file == 'init')
+ if ($file)
{
- $ext = pathinfo($this->_file, PATHINFO_EXTENSION);
-
- if (in_array($ext, array('js', 'css')))
- {
- $this->_environment = $file;
-
- $this->request->action($ext);
- }
+ // Check if the browser sent an "if-none-match: <etag>" header, and tell if the file hasn't changed
+ $this->response->check_cache(sha1($this->request->uri()).filemtime($file), $this->request);
+
+ // Set the proper headers to allow caching
+ // and send the file content as the response
+ $this->response
+ ->body(file_get_contents($file))
+ ->headers('content-type', File::mime_by_ext($this->_ext))
+ ->headers('last-modified', date('r', filemtime($file)));
+ }
+ else
+ {
+ // Return a 404 status
+ $this->response->status(404);
}
- }
-
- public function action_plain()
- {
- $this->_source(array($this->_check_path($this->_file)));
- }
-
- public function action_js()
- {
- $files = array
- (
- Kohana::find_file('media/wysiwyg', 'init', 'js')
- );
-
- $optional_content = 'var wysiwyg_config = '.json_encode($this->_wysiwyg_config).'; ';
- $optional_content .= 'var filebrowser_config = '.json_encode($this->_filebrowser_config).';';
-
- $source = $this->_source($files, $optional_content);
}
} // End Kohana_Controller_WYSIWYG
@@ -46,7 +46,7 @@ public static function list_all($directory)
*/
protected static function _list($directory, $dirs, $files, array $filter = NULL)
{
- $directory = APPPATH.$directory;
+ $directory = DOCROOT.$directory;
$return = array();
@@ -78,8 +78,8 @@ protected static function _list($directory, $dirs, $files, array $filter = NULL)
if ($dimensions = self::is_image($filename))
{
- $dir = APPPATH
- .Kohana::$config->load('media.media_directory')
+ $dir = DOCROOT
+ .Kohana::$config->load('filebrowser.public_directory')
.DIRECTORY_SEPARATOR
.Kohana::$config->load('filebrowser.uploads_directory')
.DIRECTORY_SEPARATOR;
@@ -91,7 +91,7 @@ protected static function _list($directory, $dirs, $files, array $filter = NULL)
));
$return[$fileinfo->getFilename()] = Arr::merge($return[$fileinfo->getFilename()], array(
- 'thumb' => $thumb.'?'.Media::compress($fileinfo->getMTime()),
+ 'thumb' => $thumb.'?'.$fileinfo->getMTime(),
'width' => $dimensions[0],
'height' => $dimensions[1]
));
View
@@ -4,18 +4,22 @@
return array
(
- 'uploads_directory' => 'uploads',
- 'thumbs' => array
+ 'public_directory' => 'media',
+ 'uploads_directory' => 'uploads',
+
+ 'thumbs' => array
(
'width' => 100,
'height' => 75
),
+
'filters' => array
(
'images' => array('allowed' => array('jpg', 'jpeg', 'png', 'bmp', 'gif')),
'flash' => array('allowed' => array('swf')),
'browse' => array('disallowed' => array('htaccess', 'php'))
),
+
'filebrowserBrowseUrl' => $filebrowser->uri(array('action' => 'browse')),
'filebrowserImageBrowseUrl' => $filebrowser->uri(array('action' => 'images')),
'filebrowserFlashBrowseUrl' => $filebrowser->uri(array('action' => 'flash')),
View
@@ -1,15 +0,0 @@
-<?php defined('SYSPATH') or die('No direct access allowed.');
-
-return array
-(
- 'default' => array
- (
- 'selector' => '.rte',
-
- 'config' => array
- (
- 'skin' => 'kama',
- 'filebrowser' => TRUE
- ),
- )
-);
View
@@ -1,15 +1,16 @@
<?php defined('SYSPATH') or die('No direct script access.');
-$public_directory = Kohana::$config->load('media')->media_directory;
-
-Route::set('media/wysiwyg', $public_directory.'/wysiwyg/<file>(?<mtime>)', array('file' => '.+', 'mtime' => '%d'))
- ->defaults(array(
- 'controller' => 'wysiwyg',
- 'action' => 'plain'
- ));
-
Route::set('wysiwyg/filebrowser', 'wysiwyg/filebrowser/<action>(/<path>)', array('action' => '(add|browse|crop|delete|dirs|download|flash|images|move|rename|resize|rotate_left|rotate_right|thumb|upload)', 'path' => '.*'))
->defaults(array(
'controller' => 'filebrowser',
'action' => 'browse'
));
+
+$public_directory = Kohana::$config
+ ->load('filebrowser.public_directory');
+
+Route::set('media/wysiwyg', $public_directory.'/wysiwyg/<file>', array('file' => '.*'))
+ ->defaults(array(
+ 'controller' => 'wysiwyg',
+ 'action' => 'media'
+ ));
Oops, something went wrong.

0 comments on commit 2b61129

Please sign in to comment.