1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-31 20:00:37 +02:00

Watermark now applies site-wide when activated.

This commit is contained in:
CaMer0n
2012-07-12 10:15:12 +00:00
parent 90d3ecadcc
commit f8b522a1aa
6 changed files with 90 additions and 86 deletions

View File

@@ -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']))

View File

@@ -280,6 +280,12 @@ $text .= "<div class='field-section'>".$tp->parseTemplate("{IMAGESELECTOR={$parm
//TODO make the preview update when image-picker is used.
$text .= "<div class='field-spacer'>".$tp->parseTemplate("{IMAGESELECTOR={$parms}&scaction=preview}")."</div>";
$sLogo = siteinfo_shortcodes::sc_logo();
echo $sLogo;
// $frm->imagepicker('sitelogo',$pref['sitelogo'],'_common')
$text .= "
</td>
</tr>

View File

@@ -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;

View File

@@ -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|<t>|<s>|<a>|<c>|<f>|<o>|<m>|<n>]
where:
<t> is the text to use as a watermark,
<s> is the font size (1-5 for built-in font, or point
size for TrueType fonts),
<a> 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),
<c> is the hex color of the text
<f> is the filename of the TTF file (optional, if
omitted a built-in font will be used)
<o> is opacity from 0 to 100,
<m> is the edge (and inter-tile) margin in percent
<n> is the angle
*/
if($wm_text)
{
$attFull .= "&wm=".$wm_text."|".$wm_size."|".$wm_pos."|".$wm_color."|".$wm_font."|".$wm_opacity."|".$wm_padding;
}
// echo "<br /><br />".$attFull;
$text = "<a class='".$class."' title='".$tp->toAttribute($this->var['media_caption'])."' href='".$tp->thumbUrl($this->var['media_url'], $attFull)."' rel='{$rel}' >";

View File

@@ -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;

View File

@@ -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;
}