first commit
This commit is contained in:
7
plugins/image_text/hooks/all.php
Normal file
7
plugins/image_text/hooks/all.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
function HookImage_textAllInitialise()
|
||||
{
|
||||
global $image_text_fieldvars;
|
||||
config_register_core_fieldvars("Image text plugin",$image_text_fieldvars);
|
||||
}
|
126
plugins/image_text/hooks/collection_download.php
Executable file
126
plugins/image_text/hooks/collection_download.php
Executable file
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
use Montala\ResourceSpace\CommandPlaceholderArg;
|
||||
function HookImage_textCollection_downloadReplaceuseoriginal()
|
||||
{
|
||||
global $usergroup, $image_text_override_groups, $lang;
|
||||
# Return if not configured for this resource type or user does not have the option to download without overlay
|
||||
if (!in_array($usergroup, $image_text_override_groups)){return false;}
|
||||
|
||||
?><div class="Question">
|
||||
<label for="no_overlay"><?php echo escape($lang['image_text_download_clear']); ?></label><input type=checkbox id="nooverlay" name="nooverlay" value="true" >
|
||||
<div class="clearerleft"> </div></div>
|
||||
<?php
|
||||
return false;
|
||||
}
|
||||
|
||||
function HookImage_textCollection_downloadModifydownloadfile($resource)
|
||||
{
|
||||
global $p, $newpath, $userref, $usergroup, $pextension,
|
||||
$image_text_restypes, $image_text_override_groups, $image_text_filetypes,
|
||||
$usesize, $use_watermark, $alternative, $tmpfile, $filename,
|
||||
$image_text_height_proportion, $image_text_max_height, $image_text_min_height,
|
||||
$image_text_font, $image_text_position,$image_text_banner_position, $imagemagick_path;
|
||||
|
||||
# Return if not configured for this resource type or if user has requested no overlay and is permitted this
|
||||
if (
|
||||
!in_array($resource['resource_type'], $image_text_restypes)
|
||||
|| !in_array(strtoupper($resource['file_extension']), $image_text_filetypes)
|
||||
|| (getval("nooverlay","") != "" && in_array($usergroup, $image_text_override_groups))
|
||||
|| $use_watermark
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
# Get text from field
|
||||
global $image_text_field_select, $image_text_default_text;
|
||||
$overlaytext=get_data_by_field($resource["ref"], $image_text_field_select);
|
||||
if ($overlaytext=="") {
|
||||
if ($image_text_default_text != "") {
|
||||
$overlaytext=$image_text_default_text;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
# If this is not a temporary file having metadata written see if we already have a suitable size with the correct text
|
||||
$image_text_saved_file=get_resource_path($resource["ref"],true,$usesize . "_image_text_" . md5($overlaytext . $image_text_height_proportion . $image_text_max_height . $image_text_min_height . $image_text_font . $image_text_position . $image_text_banner_position) . "_" ,false,$pextension,-1,1);
|
||||
|
||||
if ($p!=$tmpfile && $p!=$newpath && file_exists($image_text_saved_file)) {
|
||||
$p=$image_text_saved_file;
|
||||
return true;
|
||||
}
|
||||
|
||||
# Locate imagemagick.
|
||||
$identify_fullpath = get_utility_path("im-identify");
|
||||
if (!$identify_fullpath) {
|
||||
debug("Could not find ImageMagick 'identify' utility at location '{$imagemagick_path}'.");
|
||||
return false;
|
||||
}
|
||||
|
||||
# Get image's dimensions.
|
||||
$identcommand = $identify_fullpath . ' -format %wx%h [FILE]';
|
||||
$cmdparams = ["[FILE]" => new CommandPlaceholderArg($p, 'is_valid_rs_path')];
|
||||
$identoutput =run_command($identcommand, false, $cmdparams);
|
||||
|
||||
preg_match('/^([0-9]+)x([0-9]+)$/ims',$identoutput,$smatches);
|
||||
if ((@list(,$width,$height) = $smatches)===false) { return false; }
|
||||
|
||||
$olheight=floor($height * $image_text_height_proportion);
|
||||
if($olheight<$image_text_min_height && intval($image_text_min_height)!=0){$olheight=$image_text_min_height;}
|
||||
if($olheight>$image_text_max_height && intval($image_text_max_height)!=0){$olheight=$image_text_max_height;}
|
||||
|
||||
# Locate imagemagick.
|
||||
$convert_fullpath = get_utility_path("im-convert");
|
||||
if (!$convert_fullpath) {
|
||||
exit("Could not find ImageMagick 'convert' utility at location '$imagemagick_path'");
|
||||
}
|
||||
|
||||
$tmpolfile= get_temp_dir() . "/" . $resource["ref"] . "_image_text_" . $userref . "." . $pextension;
|
||||
|
||||
$createolcommand = $convert_fullpath . ' -background [BACKCOLOUR] -fill white -gravity [POSITION] -font [FONT] -size [WIDTHxHEIGHT] caption:[CAPTION] [TMPOLFILE]';
|
||||
$cmdparams = [
|
||||
"[BACKCOLOUR]" => "#000",
|
||||
"[FILE]" => new CommandPlaceholderArg($p, 'is_valid_rs_path'),
|
||||
"[POSITION]" => new CommandPlaceholderArg($image_text_position,fn($val): bool => in_array($val, ["east","west","center"])),
|
||||
"[FONT]" => $image_text_font,
|
||||
"[WIDTHxHEIGHT]" => (int) $width . "x" . (int) $olheight,
|
||||
"[CAPTION]" => new CommandPlaceholderArg($overlaytext, 'is_string'),
|
||||
"[TMPOLFILE]" => new CommandPlaceholderArg($tmpolfile, 'is_valid_rs_path'),
|
||||
];
|
||||
run_command($createolcommand, false, $cmdparams);
|
||||
|
||||
$newdlfile = get_temp_dir() . "/" . $resource["ref"] . "_image_text_result_" . $userref . "." . $pextension;
|
||||
|
||||
if ($image_text_banner_position == "bottom") {
|
||||
$convertcommand = $convert_fullpath . " [FILE] [TMPOLFILE] -append [NEWDLFILE]";
|
||||
} else {
|
||||
$convertcommand = $convert_fullpath . " [TMPOLFILE] [FILE] -append [NEWDLFILE]";
|
||||
}
|
||||
$cmdparams = [
|
||||
"[FILE]" => new CommandPlaceholderArg($p, 'is_valid_rs_path'),
|
||||
"[TMPOLFILE]" => new CommandPlaceholderArg($tmpolfile, 'is_valid_rs_path'),
|
||||
"[NEWDLFILE]" => new CommandPlaceholderArg($newdlfile, 'is_valid_rs_path'),
|
||||
];
|
||||
run_command($convertcommand, false, $cmdparams);
|
||||
|
||||
if ($p!=$tmpfile) {
|
||||
# If this is not a temporary file having metadata written then copy it to the filestore for future use
|
||||
copy($newdlfile, $image_text_saved_file);
|
||||
}
|
||||
|
||||
if ($p == $tmpfile || $p == $newpath) {
|
||||
# Replace file in temporary directory with modified file
|
||||
unlink($p);
|
||||
rename($newdlfile,$p);
|
||||
} else {
|
||||
# File is in original location, just retarget $p
|
||||
$p=$newdlfile;
|
||||
}
|
||||
|
||||
if (file_exists($tmpolfile)) {
|
||||
unlink($tmpolfile);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
101
plugins/image_text/hooks/download.php
Executable file
101
plugins/image_text/hooks/download.php
Executable file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
use Montala\ResourceSpace\CommandPlaceholderArg;
|
||||
|
||||
function HookImage_textDownloadModifydownloadfile()
|
||||
{
|
||||
global $ref, $path, $tmpfile, $usergroup, $ext, $resource_data,
|
||||
$image_text_restypes, $image_text_override_groups, $image_text_filetypes,
|
||||
$size, $page, $use_watermark, $alternative, $image_text_height_proportion,
|
||||
$image_text_max_height, $image_text_min_height, $image_text_font, $image_text_position,
|
||||
$image_text_banner_position, $imagemagick_path;
|
||||
|
||||
if (getval('noattach', '')) {
|
||||
return;
|
||||
}
|
||||
|
||||
# Return if not configured for this resource type or if user has requested no overlay and is permitted this
|
||||
if(!is_array($resource_data)
|
||||
||
|
||||
!in_array($resource_data['resource_type'], $image_text_restypes)
|
||||
||
|
||||
!in_array(strtoupper($ext), $image_text_filetypes)
|
||||
||
|
||||
(getval("nooverlay","")!="" && in_array($usergroup, $image_text_override_groups))
|
||||
||
|
||||
$use_watermark)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
# Get text from field
|
||||
global $image_text_field_select, $image_text_default_text;
|
||||
$overlaydata = get_data_by_field($ref, $image_text_field_select);
|
||||
$overlaytext = mb_convert_encoding($overlaydata, mb_detect_encoding($overlaydata),"UTF-8");
|
||||
if($overlaytext=="")
|
||||
{
|
||||
if($image_text_default_text!="")
|
||||
{$overlaytext=$image_text_default_text;}
|
||||
else
|
||||
{return false;}
|
||||
}
|
||||
|
||||
# If this is not a temporary file having metadata written see if we already have a suitable size with the correct text
|
||||
$image_text_saved_file = get_resource_path($ref,true,$size . "_image_text_" . md5($overlaytext . $image_text_height_proportion . $image_text_max_height . $image_text_min_height . $image_text_font . $image_text_position . $image_text_banner_position) . "_" ,false,$ext,-1,$page,$use_watermark,'',$alternative);
|
||||
|
||||
if ($path != $tmpfile && file_exists($image_text_saved_file)) {
|
||||
$path = $image_text_saved_file;
|
||||
return true;
|
||||
}
|
||||
if ((list($width,$height) = try_getimagesize($path))===false) {
|
||||
return false;
|
||||
}
|
||||
$olheight=floor($height * $image_text_height_proportion);
|
||||
if ($olheight<$image_text_min_height && intval($image_text_min_height)!=0){$olheight=$image_text_min_height;}
|
||||
if ($olheight>$image_text_max_height && intval($image_text_max_height)!=0){$olheight=$image_text_max_height;}
|
||||
|
||||
# Locate imagemagick.
|
||||
$convert_fullpath = get_utility_path("im-convert");
|
||||
if (!$convert_fullpath) {
|
||||
exit("Could not find ImageMagick 'convert' utility at location '$imagemagick_path'");
|
||||
}
|
||||
|
||||
$tmpolfile= get_temp_dir() . "/" . $ref . "_image_text_" . uniqid() . "." . $ext;
|
||||
$createolcommand = $convert_fullpath . " -background '#000' -fill white -gravity %%POSITION%% -font %%FONT%% -size %%WIDTHHEIGHT%% caption:%%CAPTION%% %%TMPOLFILE%%";
|
||||
$createolparams = [
|
||||
"%%POSITION%%" => new CommandPlaceholderArg($image_text_position,fn($val): bool => in_array($val, ["east","west","center"])),
|
||||
"%%FONT%%" => new CommandPlaceholderArg($image_text_font, fn($val): bool => preg_match('/^[a-zA-Z0-9\#\s\-]*$/', $val) === 1),
|
||||
"%%WIDTHHEIGHT%%" => (int) $width . "x" . (int) $olheight,
|
||||
"%%CAPTION%%" => new CommandPlaceholderArg($overlaytext, 'is_string'),
|
||||
"%%TMPOLFILE%%" => $tmpolfile,
|
||||
];
|
||||
|
||||
run_command($createolcommand, false, $createolparams);
|
||||
|
||||
$newdlfile = get_temp_dir() . "/" . $ref . "_image_text_result_" . uniqid() . "." . $ext;
|
||||
if($image_text_banner_position == "bottom") {
|
||||
$convertcommand = $convert_fullpath . " %%PATH%% %%TMPOLFILE%% -append %%NEWDLFILE%%";
|
||||
} else {
|
||||
$convertcommand = $convert_fullpath . " %%TMPOLFILE%% %%PATH%% -append %%NEWDLFILE%%";
|
||||
}
|
||||
|
||||
$convertparams = [
|
||||
"%%PATH%%" => new CommandPlaceholderArg($path, 'is_valid_rs_path'),
|
||||
"%%TMPOLFILE%%" => new CommandPlaceholderArg($tmpolfile, 'is_safe_basename'),
|
||||
"%%NEWDLFILE%%" => new CommandPlaceholderArg($newdlfile, 'is_safe_basename'),
|
||||
];
|
||||
run_command($convertcommand, false, $convertparams);
|
||||
|
||||
$oldpath = $path;
|
||||
if ($path != $tmpfile) {
|
||||
// If this is not a temporary file having metadata written then move it to the filestore for future use
|
||||
rename($newdlfile, $image_text_saved_file);
|
||||
$path = $image_text_saved_file;
|
||||
} else {
|
||||
$path = $newdlfile;
|
||||
}
|
||||
try_unlink($tmpolfile);
|
||||
if (strpos(get_temp_dir(), $oldpath) === 0) {
|
||||
try_unlink($oldpath);
|
||||
}
|
||||
return true;
|
||||
}
|
9
plugins/image_text/hooks/download_progress.php
Executable file
9
plugins/image_text/hooks/download_progress.php
Executable file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
function HookImage_textDownload_progressAddtodownloadquerystring()
|
||||
{
|
||||
if(getval("nooverlay","")!="")
|
||||
{return "&nooverlay=true";}
|
||||
return false;
|
||||
}
|
||||
|
9
plugins/image_text/hooks/download_usage.php
Executable file
9
plugins/image_text/hooks/download_usage.php
Executable file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
function HookImage_textDownload_usageAddtodownloadquerystring()
|
||||
{
|
||||
if(getval("nooverlay","")!="")
|
||||
{return "?nooverlay=true";}
|
||||
return "";
|
||||
}
|
||||
|
17
plugins/image_text/hooks/preview.php
Executable file
17
plugins/image_text/hooks/preview.php
Executable file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
function HookImage_textPreviewPreviewimage()
|
||||
{
|
||||
global $ext, $resource, $image_text_restypes, $baseurl, $ref, $url, $use_watermark, $k, $alternative, $image_text_filetypes,$page;
|
||||
|
||||
# Return if not configured for this resource type, no image or using watermark
|
||||
if(!in_array($resource['resource_type'], $image_text_restypes) || (int) $resource["has_image"] === RESOURCE_PREVIEWS_NONE || !in_array(strtoupper($ext), $image_text_filetypes) || $use_watermark){return false;}
|
||||
|
||||
$path=get_resource_path($ref,true,"scr",false,$ext,-1,$page,"","",$alternative);
|
||||
|
||||
if (!file_exists($path)){$size="pre";} else { $size="scr";}
|
||||
|
||||
$url=$baseurl."/pages/download.php" . "?ref=" . urlencode($ref) . "&size=" . urlencode($size) . "&ext=" . urlencode($ext) . "&k=" . urlencode($k) . "&alternative=" . urlencode($alternative) ."&noattach=true";
|
||||
|
||||
return false;
|
||||
}
|
||||
|
10
plugins/image_text/hooks/terms.php
Executable file
10
plugins/image_text/hooks/terms.php
Executable file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
function HookImage_textTermsBeforeredirectchangeurl()
|
||||
{
|
||||
global $url;
|
||||
if(getval("nooverlay","")!="")
|
||||
{return $url . "&nooverlay=true";}
|
||||
return false;
|
||||
}
|
||||
|
37
plugins/image_text/hooks/view.php
Executable file
37
plugins/image_text/hooks/view.php
Executable file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
function HookImage_textViewDownloadbuttonreplace()
|
||||
{
|
||||
global $lang,$baseurl_short,$ext,$resource,$image_text_restypes,$baseurl,$ref,$altfiles,$n,$usergroup,$image_text_override_groups,$image_text_filetypes;
|
||||
global $order_by,$k,$search,$offset,$archive,$sort, $size_info_array;
|
||||
$size_info = $size_info_array;
|
||||
# Return if not configured for this resource type or user does not have the option to download without overlay
|
||||
if(!in_array($resource['resource_type'], $image_text_restypes) || !in_array($usergroup, $image_text_override_groups)){return false;}
|
||||
|
||||
if (isset($altfiles[$n]["file_extension"]) && in_array(strtoupper($altfiles[$n]["file_extension"]), $image_text_filetypes) )
|
||||
{
|
||||
?>
|
||||
|
||||
<a id="downloadlink" style="margin-bottom:5px" href="<?php echo $baseurl ?>/pages/terms.php?ref=<?php echo urlencode($ref)?>&search=<?php
|
||||
echo urlencode($search) ?>&k=<?php echo urlencode($k)?>&url=<?php
|
||||
echo urlencode("pages/download_progress.php?ref=" . $ref . "&ext=" . $altfiles[$n]["file_extension"] . "&k=" . $k . "&search=" . urlencode($search)
|
||||
. "&offset=" . $offset . "&alternative=" . $altfiles[$n]["ref"] . "&archive=" . $archive . "&sort=".$sort."&order_by="
|
||||
. urlencode($order_by)."&nooverlay=true")?>" onClick="return CentralSpaceLoad(this,true);"><?php echo escape($lang["image_text_download_clear"]); ?></a><?php
|
||||
}
|
||||
|
||||
elseif (in_array(strtoupper($resource["file_extension"]), $image_text_filetypes))
|
||||
{
|
||||
if(isset($size_info["extension"])){$dlext=$size_info["extension"];}else{$dlext=$resource["file_extension"];}
|
||||
|
||||
?><a id="downloadlink" style="margin-bottom:5px" href="<?php echo $baseurl ?>/pages/terms.php?ref=<?php echo urlencode($ref)?>&search=<?php
|
||||
echo urlencode($search) ?>&k=<?php echo urlencode($k)?>&url=<?php
|
||||
echo urlencode("pages/download_progress.php?ref=" . $ref . "&size=" . $size_info["id"]
|
||||
. "&ext=" . $dlext . "&k=" . $k . "&search=" . urlencode($search)
|
||||
. "&offset=" . $offset . "&archive=" . $archive . "&sort=".$sort."&order_by="
|
||||
. urlencode($order_by) ."&nooverlay=true")?>" onClick="return CentralSpaceLoad(this,true);"><?php echo escape($lang["image_text_download_clear"]); ?></a><?php
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user