From f8b522a1aa3451838f39d95f84e21f48eb71f8b8 Mon Sep 17 00:00:00 2001 From: CaMer0n Date: Thu, 12 Jul 2012 10:15:12 +0000 Subject: [PATCH] Watermark now applies site-wide when activated. --- e107_admin/image.php | 46 +++++++++++++++++++ e107_admin/prefs.php | 6 +++ .../thumb_plugins/gd_watermarkttf.inc.php | 12 ++--- e107_plugins/gallery/e_shortcode.php | 31 ------------- e107_plugins/gallery/includes/admin.php | 36 --------------- thumb.php | 45 ++++++++++++------ 6 files changed, 90 insertions(+), 86 deletions(-) diff --git a/e107_admin/image.php b/e107_admin/image.php index 279bac38d..504d94fb9 100644 --- a/e107_admin/image.php +++ b/e107_admin/image.php @@ -371,6 +371,13 @@ class media_admin_ui extends e_admin_ui 'im_width' => array('title'=> "Avatar Width", 'type'=>'text', 'data'=>'int', 'writeParms'=>'help=Avatar images will be constrained to these dimensions (in pixels)'), //TODO LAN 'im_height' => array('title'=> "Avatar Height", 'type'=>'text', 'data'=>'int', 'writeParms'=>'help=Avatar images will be constrained to these dimensions (in pixels)'), 'resize_dimensions' => array('title'=> "Resize Dimensions", 'type'=>'method', 'data'=>'str'), + + 'watermark_activate' => array('title'=> 'Watermark Activation', 'type' => 'text', 'data' => 'str', 'help'=>'All images with a width or height greater than this value will be given a watermark during resizing.'), // 'validate' => 'regex', 'rule' => '#^[\d]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore')), + 'watermark_text' => array('title'=> 'Watermark Text', 'type' => 'text', 'data' => 'str', 'help'=>'Optional Watermark Text'), // 'validate' => 'regex', 'rule' => '#^[\d]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore')), + 'watermark_font' => array('title'=> 'Watermark Font', 'type' => 'dropdown', 'data' => 'str', 'help'=>'Optional Watermark Font. Upload more .ttf fonts to the /fonts folder in your theme directory.'), // 'validate' => 'regex', 'rule' => '#^[\d]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore')), + 'watermark_size' => array('title'=> 'Watermark Size', 'type' => 'text', 'data' => 'int', 'help'=>'Optional Watermark Font'), // 'validate' => 'regex', 'rule' => '#^[\d]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore')), + 'watermark_pos' => array('title'=> 'Watermark Position', 'type' => 'dropdown', 'data' => 'str', 'help'=>'Watermark Position'), // 'validate' => 'regex', 'rule' => '#^[\d]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore')), + 'watermark_opacity' => array('title'=> 'Watermark Opacity', 'type' => 'text', 'data' => 'int', 'help'=>'Enter a number between 1 and 100'), // 'validate' => 'regex', 'rule' => '#^[\d]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore')), ); @@ -455,6 +462,45 @@ class media_admin_ui extends e_admin_ui $this->cats[$cat] = $row['media_cat_title']; } asort($this->cats); + + $pref = e107::getPref(); + $tp = e107::getParser(); + $fl = e107::getFile(); + $path = e_THEME.$pref['sitetheme']."/fonts/"; + + $fDir = $fl->get_files(e_THEME.$pref['sitetheme']."/fonts/",".ttf",'',2); + $fonts = array(0=>'None'); + foreach($fDir as $f) + { + $id = $tp->createConstants($f['path'].$f['fname'],'rel'); + $fonts[$id] = $f['fname']; + } + + + $this->prefs['watermark_font']['writeParms'] = $fonts; + $this->prefs['watermark_font']['readParms'] = $fonts; + + $wm_pos = array( + 'BR' => "Bottom Right", + 'BL' => "Bottom Left", + 'TR' => "Top Right", + 'TL' => "Top Left", + 'C' => "Center", + 'R' => "Right", + 'L' => "Left", + 'T' => "Top", + 'B' => "Bottom", + '*' => "Tile" + ); + + $this->prefs['watermark_pos']['writeParms'] = $wm_pos; + $this->prefs['watermark_pos']['readParms'] = $wm_pos; + + //FIXME TODO - clear thumbnail cache when prefs are saved/updated. + // e107::getCache()->clearAll('image'); + + + if(varset($_POST['batch_import_selected'])) diff --git a/e107_admin/prefs.php b/e107_admin/prefs.php index 0e50ab852..9f75a56ab 100644 --- a/e107_admin/prefs.php +++ b/e107_admin/prefs.php @@ -280,6 +280,12 @@ $text .= "
".$tp->parseTemplate("{IMAGESELECTOR={$parm //TODO make the preview update when image-picker is used. $text .= "
".$tp->parseTemplate("{IMAGESELECTOR={$parms}&scaction=preview}")."
"; +$sLogo = siteinfo_shortcodes::sc_logo(); + +echo $sLogo; +// $frm->imagepicker('sitelogo',$pref['sitelogo'],'_common') + + $text .= " diff --git a/e107_handlers/phpthumb/thumb_plugins/gd_watermarkttf.inc.php b/e107_handlers/phpthumb/thumb_plugins/gd_watermarkttf.inc.php index abe077ebc..1dd66dffc 100644 --- a/e107_handlers/phpthumb/thumb_plugins/gd_watermarkttf.inc.php +++ b/e107_handlers/phpthumb/thumb_plugins/gd_watermarkttf.inc.php @@ -68,12 +68,12 @@ class GdWatermarkTTF // public function WatermarkText($text, $size=12, $alignment='BR', $hex_color='000000', $ttffont='', $opacity=100, $margin=5, $angle=0, $bg_color=false, $bg_opacity=0, $fillextend='', &$that) public function WatermarkText($parms, &$that) { - $text = $parms[0]; - $size = $parms[1]; - $alignment = $parms[2]; - $hex_color = $parms[3]; - $ttffont = $parms[4]; - $opacity = (isset($parms[5])) ? $parms[5] : 100; + $text = $parms['text']; + $size = $parms['size']; + $alignment = $parms['pos']; + $hex_color = $parms['color']; + $ttffont = $parms['font']; + $opacity = (isset($parms['opacity'])) ? $parms['opacity'] : 100; $margin = 30; // (isset($parms[6])) ? $parms[6] : 25; $angle = 0; // $parms['angle']; $bg_color = false; diff --git a/e107_plugins/gallery/e_shortcode.php b/e107_plugins/gallery/e_shortcode.php index 57799b91d..65f0bbf36 100644 --- a/e107_plugins/gallery/e_shortcode.php +++ b/e107_plugins/gallery/e_shortcode.php @@ -42,37 +42,6 @@ class gallery_shortcodes extends e_shortcode $pop_h = vartrue(e107::getPlugPref('gallery','pop_h'),768); $attFull = 'w='.$pop_w.'&h='.$pop_h; - $wm_text = vartrue(e107::getPlugPref('gallery','watermark_text')); - $wm_font = vartrue(e107::getPlugPref('gallery','watermark_font')); - $wm_size = vartrue(e107::getPlugPref('gallery','watermark_size'),20); - $wm_pos = vartrue(e107::getPlugPref('gallery','watermark_pos'),"BR"); - $wm_color = vartrue(e107::getPlugPref('gallery','watermark_color'),"fff"); - $wm_opacity = vartrue(e107::getPlugPref('gallery','watermark_opacity'),"70"); - $wm_padding = vartrue(e107::getPlugPref('gallery','watermark_padding'),"5"); - - /* - "wmt" (WaterMarkText) - [ex: &fltr[]=wmt||||||||] - where: - is the text to use as a watermark, - is the font size (1-5 for built-in font, or point - size for TrueType fonts), - is the alignment (one of BR, BL, TR, TL, C, R, L, - T, B, * where B=bottom, T=top, L=left, R=right, - C=centre, *=tile), - is the hex color of the text - is the filename of the TTF file (optional, if - omitted a built-in font will be used) - is opacity from 0 to 100, - is the edge (and inter-tile) margin in percent - is the angle - */ - - if($wm_text) - { - $attFull .= "&wm=".$wm_text."|".$wm_size."|".$wm_pos."|".$wm_color."|".$wm_font."|".$wm_opacity."|".$wm_padding; - } - // echo "

".$attFull; $text = "
"; diff --git a/e107_plugins/gallery/includes/admin.php b/e107_plugins/gallery/includes/admin.php index 347c685bd..5e695b82d 100644 --- a/e107_plugins/gallery/includes/admin.php +++ b/e107_plugins/gallery/includes/admin.php @@ -129,11 +129,6 @@ class gallery_cat_admin_ui extends e_admin_ui 'popup_w' => array('title'=> 'Image Max. Width', 'type' => 'text', 'data' => 'int', 'help'=>'Images will be auto-resized if greater than the width given here'), // 'validate' => 'regex', 'rule' => '#^[\d]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore')), 'popup_h' => array('title'=> 'Image Max. Height', 'type' => 'text', 'data' => 'int', 'help'=>'Images will be auto-resized if greater than the height given here'), // 'validate' => 'regex', 'rule' => '#^[\d]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore')), - 'watermark_text' => array('title'=> 'Watermark Text', 'type' => 'text', 'data' => 'str', 'help'=>'Optional Watermark Text'), // 'validate' => 'regex', 'rule' => '#^[\d]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore')), - 'watermark_font' => array('title'=> 'Watermark Font', 'type' => 'dropdown', 'data' => 'str', 'help'=>'Optional Watermark Font. Upload more .ttf fonts to the /fonts folder in your theme directory.'), // 'validate' => 'regex', 'rule' => '#^[\d]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore')), - 'watermark_size' => array('title'=> 'Watermark Size', 'type' => 'text', 'data' => 'int', 'help'=>'Optional Watermark Font'), // 'validate' => 'regex', 'rule' => '#^[\d]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore')), - 'watermark_pos' => array('title'=> 'Watermark Position', 'type' => 'dropdown', 'data' => 'str', 'help'=>'Watermark Position'), // 'validate' => 'regex', 'rule' => '#^[\d]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore')), - 'watermark_opacity' => array('title'=> 'Watermark Opacity', 'type' => 'text', 'data' => 'int', 'help'=>'Enter a number between 1 and 100'), // 'validate' => 'regex', 'rule' => '#^[\d]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore')), 'slideshow_category' => array('title'=> 'Slideshow category', 'type' => 'dropdown', 'data' => 'str', 'help'=>'Images from this category will be used in the sliding menu.'), // 'validate' => 'regex', 'rule' => '#^[\d]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore')), // 'slideshow_thumb_w' => array('title'=> 'Thumbnail Width', 'type' => 'number', 'data' => 'integer', 'help'=>'Width in px'), // 'validate' => 'regex', 'rule' => '#^[\d]+$#i', 'help' => 'allowed characters are a-zA-Z and underscore')), @@ -163,38 +158,7 @@ class gallery_cat_admin_ui extends e_admin_ui // 'zoom' => 'zoom' ); - $pref = e107::getPref(); - $tp = e107::getParser(); - $fl = e107::getFile(); - $path = e_THEME.$pref['sitetheme']."/fonts/"; - - $fDir = $fl->get_files(e_THEME.$pref['sitetheme']."/fonts/",".ttf",'',2); - $fonts = array(0=>'None'); - foreach($fDir as $f) - { - $id = $tp->createConstants($f['path'].$f['fname'],'rel'); - $fonts[$id] = $f['fname']; - } - - $this->prefs['watermark_font']['writeParms'] = $fonts; - $this->prefs['watermark_font']['readParms'] = $fonts; - - $wm_pos = array( - 'BR' => "Bottom Right", - 'BL' => "Bottom Left", - 'TR' => "Top Right", - 'TL' => "Top Left", - 'C' => "Center", - 'R' => "Right", - 'L' => "Left", - 'T' => "Top", - 'B' => "Bottom", - '*' => "Tile" - ); - - $this->prefs['watermark_pos']['writeParms'] = $wm_pos; - $this->prefs['watermark_pos']['readParms'] = $wm_pos; $this->prefs['slideshow_effect']['writeParms'] = $effects; $this->prefs['slideshow_effect']['readParms'] = $effects; diff --git a/thumb.php b/thumb.php index ffaee9385..a40498605 100644 --- a/thumb.php +++ b/thumb.php @@ -32,6 +32,8 @@ define('e107_INIT', true); $thumbpage = new e_thumbpage(); + + if(!$thumbpage->checkSrc()) { die(' Access denied!'); @@ -59,6 +61,11 @@ class e_thumbpage * @var string source path modified/sanitized */ protected $_src_path = null; + + + /** Stores watermark prefs + */ + protected $_watermark = array(); /** * Constructor - init paths @@ -116,7 +123,20 @@ class e_thumbpage // basic Admin area detection - required for proper path parsing define('ADMIN', strpos(e_SELF, ($e107->getFolder('admin')) !== false || strpos(e_PAGE, 'admin') !== false)); + $e107->set_urls(false); + + $pref = $e107->getPref(); //TODO optimize/benchmark + $this->_watermark = array( + 'activate' => vartrue($pref['watermark_activate'], false), + 'text' => vartrue($pref['watermark_text']), + 'size' => vartrue($pref['watermark_size'], 20), + 'pos' => vartrue($pref['watermark_pos'],"BR"), + 'color' => vartrue($pref['watermark_color'],'fff'), + 'font' => vartrue($pref['watermark_font']), + 'opacity' => vartrue($pref['watermark_opacity'], 20) + ); + // parse request $this->parseRequest(); } @@ -229,21 +249,20 @@ class e_thumbpage { $thumb->adaptiveResize((integer) vartrue($this->_request['aw'], 0), (integer) vartrue($this->_request['ah'], 0)); } - - //TODO Move to $_SESSION and activate based on width/height ie. watermark all images larger than.... - // ie. prevent user tampering with URLs. - if(isset($this->_request['wm'])) + + // Watermark Option - See admin->MediaManager->prefs for details. + + if($this->_watermark['activate'] < $options['w'] + || $this->_watermark['activate'] < $options['aw'] + || $this->_watermark['activate'] < $options['h'] + || $this->_watermark['activate'] < $options['ah'] + ) { $tp = e107::getParser(); + $this->_watermark['font'] = $tp->createConstants($this->_watermark['font'], 'mix'); + $this->_watermark['font'] = realpath($tp->replaceConstants($this->_watermark['font'],'rel')); - $tmp = explode("|",$this->_request['wm']); - - $tmp[4] = $tp->createConstants($tmp[4], 'mix'); - $tmp[4] = realpath($tp->replaceConstants($tmp[4],'rel')); - - $thumb->WatermarkText($tmp); - // $alignment='BR', $hex_color='000000', $ttffont='', $opacity=100, $margin=5, $angle=0, $bg_color=false, $bg_opacity=0, $fillextend='' - + $thumb->WatermarkText($this->_watermark); } @@ -261,7 +280,7 @@ class e_thumbpage $ret['h'] = isset($this->_request['h']) ? intval($this->_request['h']) : $ret['w']; $ret['aw'] = isset($this->_request['aw']) ? intval($this->_request['aw']) : false; $ret['ah'] = isset($this->_request['ah']) ? intval($this->_request['ah']) : $ret['aw']; - $ret['wm'] = isset($this->_request['wm']) ? intval($this->_request['wm']) : $ret['wm']; + // $ret['wm'] = isset($this->_request['wm']) ? intval($this->_request['wm']) : $ret['wm']; return $ret; }