1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-01 20:30:39 +02:00

IN PROGRESS - task EONE-10: System thumbnails

- media manager now uses thumb.php
- form handler uses thumb.php (UI) when type is image and parameter thumb is passed 
- minor issues fixed
- thumbUrl() method added (Parser, for now)
This commit is contained in:
secretr
2010-03-09 16:05:41 +00:00
parent b1b33d1870
commit 2a0529f631
7 changed files with 367 additions and 296 deletions

View File

@@ -8,10 +8,8 @@
*
* Cache Administration Area
*
* $Source: /cvs_backup/e107_0.8/e107_admin/cache.php,v $
* $Revision$
* $Date$
* $Author$
* $URL$
* $Id$
*
*/
require_once("../class2.php");

View File

@@ -8,10 +8,8 @@
*
* Image Administration Area
*
* $Source: /cvs_backup/e107_0.8/e107_admin/image.php,v $
* $Revision$
* $Date$
* $Author$
* $URL$
* $Id$
*
*/
require_once("../class2.php");
@@ -39,7 +37,7 @@ $e_sub_cat = 'image';
require_once(e_HANDLER."userclass_class.php");
require_once(e_HANDLER."message_handler.php");
// $frm = new e_form(); //new form handler
$emessage = &eMessage::getInstance();
$emessage = eMessage::getInstance();
class media_admin extends e_admin_dispatcher
{
@@ -131,7 +129,7 @@ class faq_cat_ui extends e_admin_ui
}
class faq_cat_form_ui extends e_admin_form_ui
/*class faq_cat_form_ui extends e_admin_form_ui
{
public function faq_info_parent($curVal,$mode)
{
@@ -154,7 +152,7 @@ class faq_cat_form_ui extends e_admin_form_ui
break;
}
}
}
}*/
@@ -236,7 +234,7 @@ class media_admin_ui extends e_admin_ui
protected $fields = array(
'checkboxes' => array('title'=> '', 'type' => null, 'data'=> null, 'width' =>'5%', 'forced'=> TRUE, 'thclass'=>'center', 'class'=>'center'),
'media_id' => array('title'=> LAN_ID, 'type' => 'number', 'data'=> 'int', 'width' =>'5%', 'forced'=> TRUE, 'nolist'=>TRUE),
'media_url' => array('title'=> 'Preview', 'type' => 'image', 'data'=> 'str', 'thclass' => 'center', 'class'=>'center', 'readParms'=>'thumb=100', 'width' => 'auto','readonly'=>TRUE),
'media_url' => array('title'=> 'Preview', 'type' => 'image', 'data'=> 'str', 'thclass' => 'center', 'class'=>'center', 'readParms'=>'thumb=60&thumb_urlraw=0&thumb_aw=60', 'width' => '110px','readonly'=>TRUE),
// 'media_preview' => array('title'=> "Preview", 'type' => 'image', 'data'=> null, 'width' => '10%'),
'media_upload' => array('title'=> "Upload File", 'type' => 'upload', 'data'=> false, 'readParm' => 'hidden', 'width' => '10%', 'nolist' => true),

View File

@@ -14,8 +14,9 @@
/**
* @package e107
* @subpackage shortcodes|admin|user|e107_handler|bbcodes
* @subpackage e107_handler
* @version $Id$
* @author secretr
*
* Simple, quick and efective way of testing performance of parts of your code
* Example:
@@ -28,7 +29,7 @@
* // Do something, e.g. loop 1000000 times
*
* // stop timer and check your e_LOG folder
* $bench->end()->$bench->('myevent');
* $bench->end()->logResult('myevent');
* //OR print out the result (don't forget to stop the timer if used without the above line!
* $bench->printResult();
* </code>

View File

@@ -1612,6 +1612,28 @@ class e_parse
return $text;
}
public function thumbUrl($url, $options = array(), $raw = false, $full = false)
{
if(!is_array($options))
{
parse_str($options, $options);
}
if($raw) $url = $this->createConstants($url, 'mix');
$thurl = ($full ? SITEURL : e_HTTP).'thumb.php?src='.$url.'&amp;';
if(vartrue($options['aw']))
{
$thurl .= 'aw='.intval($options['aw']).'&amp;ah='.(vartrue($options['ah']) ? intval($options['ah']) : intval($options['aw']));
}
else
{
if(!vartrue($options['w'])) $options['w'] = 100;
$thurl .= 'aw='.intval($options['w']).'&amp;ah='.(vartrue($options['h']) ? intval($options['h']) : intval($options['w']));
}
return $thurl;
}
/**
* Replace e107 path constants
@@ -1687,7 +1709,6 @@ class e_parse
"{e_THEME}",
//,"{e_DOWNLOAD}"
"{e_HANDLER}",
//FIXME need another name
"{e_MEDIA}"
);

View File

@@ -1225,12 +1225,33 @@ class e_form
case 'image': //TODO - thumb, js tooltip...
if($value)
{
if(vartrue($parms['thumb']))
{
$src = $tp->replaceConstants(vartrue($parms['pre']).$value, 'abs');
$thumb = $parms['thumb'];
$thparms = array();
if(is_numeric($thumb) && '1' != $thumb)
{
$thparms['w'] = intval($thumb);
}
elseif(vartrue($parms['thumb_aw']))
{
$thparms['aw'] = intval($parms['thumb_aw']);
}
$thsrc = $tp->thumbUrl(vartrue($parms['pre']).$value, $thparms, varset($parms['thumb_urlraw']));
$alt = $src;
$ttl = '<img src="'.$thsrc.'" alt="'.$alt.'" class="e-thumb" />';
$value = '<a href="'.$src.'" class="e-image-preview" title="'.$alt.'" rel="external">'.$ttl.'</a>';
}
else
{
$src = $tp->replaceConstants(vartrue($parms['pre']).$value, 'abs');
$alt = $src; //basename($value);
$ttl = vartrue($parms['thumb']) ? '<img src="'.$src.'" alt="'.$alt.'" style="width: '.(is_numeric($parms['thumb']) ? $parms['thumb'] : 80).'px" />' : vartrue($parms['title'], 'LAN_PREVIEW');
$ttl = vartrue($parms['title'], 'LAN_PREVIEW');
$value = '<a href="'.$src.'" class="e-image-preview" title="'.$alt.'" rel="external">'.defset($ttl, $ttl).'</a>';
}
}
break;
case 'datestamp':

View File

@@ -8,10 +8,8 @@
*
* Release Plugin Administration UI
*
* $Source: /cvsroot/e107/e107_0.8/e107_plugins/release/includes/admin.php,v $
* $Revision$
* $Date$
* $Author$
* $URL$
* $Id$
*/
//require_once(e_HANDLER.'admin_handler.php'); - autoloaded - see class2.php __autoload()
@@ -217,7 +215,9 @@ class plugin_release_admin_ui extends e_admin_ui
* [optional] 'size' => [optional] - medium, small, large - default is medium,
* [optional] 'counter' => 0 number of max characters - has only visual effect, doesn't truncate the value (default - false)
*
* - image -> read: [optional] 'title' => 'SOME_LAN' (default - LAN_PREVIEW), [optional] 'pre' => '{e_PLUGIN}myplug/images/'
* - image -> read: [optional] 'title' => 'SOME_LAN' (default - LAN_PREVIEW), [optional] 'pre' => '{e_PLUGIN}myplug/images/',
* 'thumb' => 1 (true) or number width in pixels, 'thumb_urlraw' => 1|0 if true, it's a 'raw' url (no sc path constants),
* 'thumb_aw' => if 'thumb' is 1|true, this is used for Adaptive thumb width
* -> write: (array) [optional] 'label' => '', [optional] '__options' => array(...) see e_form::imagepicker() for allowed options
*
* - icon -> read: [optional] 'class' => 'S16', [optional] 'pre' => '{e_PLUGIN}myplug/images/'

View File

@@ -15,13 +15,21 @@
/**
* @package e107
* @subpackage core
* @author secretr
* @version $Id$
*
* @todo cache management - max age, max size, image cache manager (?), cron (?)
*
* On-the-fly thumbnail generator
*/
define('e107_INIT', true);
//error_reporting(E_ALL);
//require_once './e107_handlers/benchmark.php';
//$bench = new e_benchmark();
//$bench->start();
$thumbpage = new e_thumbpage();
if(!$thumbpage->checkSrc())
@@ -30,17 +38,28 @@ if(!$thumbpage->checkSrc())
}
$thumbpage->sendImage();
/**
* Handle on-the-fly created thumbnails
*
* @author secretr
*
*/
// Check your e_LOG folder
//$bench->end()->logResult('thumb.php', $_GET['src'].' - no cache');
exit;
class e_thumbpage
{
/**
* Page request
* @var array
*/
protected $_request = array();
/**
* @var string image source path (e107 path shortcode)
*/
protected $_src = null;
/**
* @var string source path modified/sanitized
*/
protected $_src_path = null;
/**
* Constructor - init paths
* @todo FIX e107 (new folder structure), simplify all this, e.g. e107::getInstance()->initMinimal($path_to_e107_config);
@@ -80,7 +99,14 @@ class e_thumbpage
'CORE_DIRECTORY'
);
$sql_info = array(); //compact('mySQLserver', 'mySQLuser', 'mySQLpassword', 'mySQLdefaultdb', 'mySQLprefix', 'mySQLcharset');
e107::getInstance()->initCore($e107_paths, $self, $sql_info, varset($e107_CONFIG, array()));
//e107::getInstance()->initCore($e107_paths, $self, $sql_info, varset($e107_CONFIG, array()));
$e107 = e107::getInstance();
$e107->setDirs($e107_paths, varset($e107_CONFIG, array()));
$e107->set_constants();
$e107->set_paths();
$e107->file_path = $e107->fix_windows_paths($self)."/";
$e107->set_base_path();
$e107->set_urls();
unset($tmp, $self);
// parse request
@@ -89,8 +115,9 @@ class e_thumbpage
function parseRequest()
{
parse_str(str_replace('&amp;', '&', e_QUERY), $request);
$this->_request = $request;
//parse_str(str_replace('&amp;', '&', e_QUERY), $this->_request);
parse_str($_SERVER['QUERY_STRING'], $this->_request);
return $this;
}
function checkSrc()
@@ -119,7 +146,8 @@ class e_thumbpage
return false;
}
$path = $tp->replaceConstants($this->_src);
// should be safe enough
$path = $tp->replaceConstants(str_replace('..', '', $this->_src));
if(is_file($path) && is_readable($path))
{
@@ -131,6 +159,7 @@ class e_thumbpage
function sendImage()
{
//global $bench;
if(!$this->_src_path)
{
return $this;
@@ -139,7 +168,7 @@ class e_thumbpage
$thumbnfo = pathinfo($this->_src_path);
$options = $this->getRequestOptions();
$cache_str = md5(serialize($options).md5_file($this->_src_path));
$cache_str = md5(serialize($options).$this->_src_path);
$fname = strtolower('Thumb_'.$thumbnfo['filename'].'_'.$cache_str.'.'.$thumbnfo['extension']).'.cache.bin';
if(is_file(e_CACHE_IMAGE.$fname) && is_readable(e_CACHE_IMAGE.$fname))
@@ -152,6 +181,7 @@ class e_thumbpage
if (@$_SERVER['HTTP_IF_MODIFIED_SINCE'] && ($thumbnfo['lmodified'] <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) && (isset($_SERVER['HTTP_IF_NONE_MATCH']) && trim($_SERVER['HTTP_IF_NONE_MATCH']) == $thumbnfo['md5s']))
{
header('HTTP/1.1 304 Not Modified');
//$bench->end()->logResult('thumb.php', $_GET['src'].' - 304 not modified');
exit;
}
@@ -159,6 +189,7 @@ class e_thumbpage
$this->sendHeaders($thumbnfo);
@readfile(e_CACHE_IMAGE.$fname);
//$bench->end()->logResult('thumb.php', $_GET['src'].' - retrieve cache');
exit;
}
@@ -189,7 +220,6 @@ class e_thumbpage
// show thumb
$thumb->show();
exit;
}
function getRequestOptions()
@@ -243,3 +273,5 @@ class e_thumbpage
return null;
}
}
?>