ocPortal Developer's Guide: Images
» Return to Contents
sources/images.php
Global_functions_images.php
Function summary
|
array
|
_symbol_image_dims (array param)
|
|
string
|
_symbol_thumbnail (array param)
|
|
integer
|
get_max_image_size ()
|
|
tempcode
|
do_image_thumb (URLPATH url, mixed caption, boolean js_tooltip, boolean is_thumbnail_already, integer width, integer height)
|
|
URLPATH
|
ensure_thumbnail (URLPATH full_url, URLPATH thumb_url, ID_TEXT thumb_dir, ID_TEXT table, AUTO_LINK id, ID_TEXT thumb_field_name, ?integer thumb_width)
|
|
boolean
|
check_memory_limit_for (PATH file_path, boolean exit_on_error)
|
|
boolean
|
convert_image (URLPATH from, PATH to, integer width, integer height, integer box_width, boolean exit_on_error, ?string ext2, boolean using_path, boolean only_make_smaller, ?array thumb_options)
|
|
float
|
get_gd_version ()
|
|
boolean
|
is_image (string name)
|
|
boolean
|
is_video (string name, boolean must_be_true_video)
|
|
boolean
|
is_saveable_image (string name)
|
array _symbol_image_dims(array param)
Render an 'IMAGE_WIDTH'/'IMAGE_HEIGHT' symbol.
Parameters…
| Name |
param |
| Description |
Symbol parameters |
| Type |
array |
Returns…
| Description |
A pair: Image dimensions |
| Type |
array |
function _symbol_image_dims($param)
{
if ((get_option('is_on_gd')=='0') || (!function_exists('imagecreatefromstring'))) return array('','');
$value=array('','');
if (isset($param[0]))
{
$base_url=get_custom_base_url();
if ((function_exists('getimagesize')) && (substr($param[0],0,strlen($base_url))==$base_url))
{
$details=@getimagesize(get_custom_file_base().'/'.urldecode(substr($param[0],strlen($base_url)+1)));
if ($details!==false)
{
$value=array(strval($details[0]),strval($details[1]));
}
} else
{
require_code('files');
$source=@imagecreatefromstring(http_download_file($param[0],1024*1024*20/*reasonable limit*/,false));
if ($source!==false)
{
$value=array(strval(imagesx($source)),strval(imagesy($source)));
imagedestroy($source);
}
}
}
return $value;
}
string _symbol_thumbnail(array param)
Render a 'THUMBNAIL' symbol.
Parameters…
| Name |
param |
| Description |
Symbol parameters |
| Type |
array |
Returns…
| Description |
Rendered symbol |
| Type |
string |
function _symbol_thumbnail($param)
{
$value='';
// Usage: {$THUMBNAIL,source,widthxheight,directory,filename,fallback,type,where,option,only_make_smaller}
// source: URL of image to thumbnail
// widthxheight: The desired width and height, separated by a lowercase x. Can be -1 to mean "don't care", but better to use type as "width" or "height"
// directory: Where to save the thumbnail to
// filename: A suggested filename to use (if the default choice causes problems)
// fallback: The URL to an image we can use if the thumbnail fails (eg. the original)
// type: One of "width" (scale until the width matches), "height" (scale until the height matches), "crop" (scale until one dimension's right, cut off the remainder),
// "pad" (scale down until the image fits completely inside the dimensions, then optionally fill the gaps), "pad_horiz_crop_horiz" (fit to height, cropping or
// padding as needed) or "pad_vert_crop_vert" (fit to width, padding or cropping as needed)
// where: If padding or cropping, specifies where to crop or pad. One of "start", "end" or "both"
// option: An extra option if desired. If type is "pad" then this can be a hex colour for the padding
// only_make_smaller: Whether to avoid growing small images to fit (smaller images are better for the Web). One of 0 (false) or 1 (true)
if (($param[0]!=''))
{
if ((get_option('is_on_gd')=='0') || (!function_exists('imagecreatefromstring'))) return $param[0];
$only_make_smaller=isset($param[8])?($param[8]=='1'):false;
$orig_url=$param[0]; // Source for thumbnail generation
if (url_is_local($orig_url)) $orig_url=get_custom_base_url().'/'.$orig_url;
if (!array_key_exists(1,$param)) $param[1]=get_option('thumb_width');
$dimensions=$param[1]; // Generation dimensions.
$exp_dimensions=explode('x',$dimensions);
if (count($exp_dimensions)==1) $exp_dimensions[]='-1';
if (count($exp_dimensions)==2)
{
if ($exp_dimensions[0]=='') $exp_dimensions[0]='-1';
if (isset($param[2]) && $param[2] != '') // Where we are saving to
{
$thumb_save_dir=$param[2];
} else
{
$thumb_save_dir=basename(dirname(rawurldecode($orig_url)));
}
if (strpos($thumb_save_dir,'/')===false) $thumb_save_dir='uploads/'.$thumb_save_dir;
if (!file_exists(get_custom_file_base().'/'.$thumb_save_dir)) $thumb_save_dir='uploads/website_specific';
$filename=rawurldecode(basename((isset($param[3]) && $param[3] != '')?$param[3]:$orig_url)); // We can take a third parameter that hints what filename to save with (useful to avoid filename collisions within the thumbnail filename subspace). Otherwise we based on source's filename
$save_path=get_custom_file_base().'/'.$thumb_save_dir.'/'.$dimensions.'__'.$filename; // Conclusion... We will save to here
$value=get_custom_base_url().'/'.$thumb_save_dir.'/'.rawurlencode($dimensions.'__'.$filename);
// We put a branch in here to preserve the old behaviour when
// called without the last 2 options
if (isset($param[5]) && in_array(trim($param[5]),array('width','height','crop','pad','pad_horiz_crop_horiz','pad_vert_crop_vert')))
{
// This branch does the new behaviour described above
$file_prefix = '/'.$thumb_save_dir.'/thumb__'.$dimensions.'__'.trim($param[5]);
if (isset($param[6])) $file_prefix .= '__'.trim($param[6]);
if (isset($param[7])) $file_prefix .= '__'.trim(str_replace('#','',$param[7]));
$save_path = get_custom_file_base().$file_prefix.'__'.$filename;
$value = get_custom_base_url().$file_prefix.'__'.rawurlencode($filename);
// Only bother calculating the image if we've not already
// made one with these options
if ((!is_file($save_path)) && (!is_file($save_path.'.png')))
{
// Branch based on the type of thumbnail we're making
if (trim($param[5]) == 'width' || trim($param[5]) == 'height')
{
// We just need to scale to the given dimension
$result = convert_image($orig_url,$save_path,(trim($param[5]) == 'width')?$exp_dimensions[0]:-1,(trim($param[5]) == 'height')?$exp_dimensions[1]:-1,-1,false,NULL,false,$only_make_smaller);
}
elseif (trim($param[5]) == 'crop' || trim($param[5]) == 'pad' || trim($param[5]) == 'pad_horiz_crop_horiz' || trim($param[5]) == 'pad_vert_crop_vert')
{
// We need to shrink a bit and crop/pad
require_code('files');
// Find dimensions of the source
$converted_to_path=convert_url_to_path($orig_url);
if (!is_null($converted_to_path))
{
$sizes=@getimagesize($converted_to_path);
if ($sizes===false) return '';
list($source_x,$source_y)=$sizes;
} else
{
$source = @imagecreatefromstring(http_download_file($orig_url,NULL,false));
if ($source===false) return '';
$source_x = imagesx($source);
$source_y = imagesy($source);
imagedestroy($source);
}
// We only need to crop/pad if the aspect ratio
// differs from what we want
$source_aspect = floatval($source_x) / floatval($source_y);
if ($exp_dimensions[1]==0) $exp_dimensions[1]=1;
$destination_aspect = floatval($exp_dimensions[0]) / floatval($exp_dimensions[1]);
// We test the scaled sizes, rather than the ratios
// directly, so that differences too small to affect
// the integer dimensions will be tolerated.
if ($source_aspect > $destination_aspect)
{
// The image is wider than the output.
if ((trim($param[5]) == 'crop') || (trim($param[5]) == 'pad_horiz_crop_horiz'))
{
// Is it too wide, requiring cropping?
$scale = floatval($source_y) / floatval($exp_dimensions[1]);
$modify_image = intval(round(floatval($source_x) / $scale)) != intval($exp_dimensions[0]);
}
else
{
// Is the image too short, requiring padding?
$scale = floatval($source_x) / floatval($exp_dimensions[0]);
$modify_image = intval(round(floatval($source_y) / $scale)) != intval($exp_dimensions[1]);
}
}
elseif ($source_aspect < $destination_aspect)
{
// The image is taller than the output
if ((trim($param[5]) == 'crop') || (trim($param[5]) == 'pad_vert_crop_vert'))
{
// Is it too tall, requiring cropping?
$scale = floatval($source_x) / floatval($exp_dimensions[0]);
$modify_image = intval(round(floatval($source_y) / $scale)) != intval($exp_dimensions[1]);
}
else
{
// Is the image too narrow, requiring padding?
$scale = floatval($source_y) / floatval($exp_dimensions[1]);
$modify_image = intval(round(floatval($source_x) / $scale)) != intval($exp_dimensions[0]);
}
}
else
{
// They're the same, within the tolerances of
// floating point arithmentic. Just scale it.
$modify_image = false;
}
// We have a special case here, since we can "pad" an
// image with nothing, ie. shrink it to fit in the
// output dimensions. This means we don't need to
// modify the image contents either, just scale it.
if ((trim($param[5]) == 'pad' || trim($param[5]) == 'pad_horiz_crop_horiz' || trim($param[5]) == 'pad_vert_crop_vert') && isset($param[5]) && (!isset($param[6]) || trim($param[6]) == ''))
{
$modify_image = false;
}
// Now do the cropping, padding and scaling
if ($modify_image)
{
$result = convert_image($orig_url,$save_path,intval($exp_dimensions[0]),intval($exp_dimensions[1]),-1,false,NULL,false,$only_make_smaller,array('type'=>trim($param[5]),'background'=>(isset($param[7])?trim($param[7]):NULL),'where'=>(isset($param[6])?trim($param[6]):'both'),'scale'=>$scale));
}
else
{
// Just resize
$result = convert_image($orig_url,$save_path,intval($exp_dimensions[0]),intval($exp_dimensions[1]),-1,false,NULL,false,$only_make_smaller);
}
}
// If the convertion failed then give back the fallback,
// or if it's empty then give back the original image
if (!$result) $value=(trim($param[4])=='')? $orig_url : $param[4];
}
if (!is_file($save_path))
$value.='.png'; // was saved as PNG
}
else
{
// This branch does the old behaviour of fitting to width, without the "type" or subsequent parameters.
if (!is_file($save_path))
{
if (!convert_image($orig_url,$save_path,intval($exp_dimensions[0]),intval($exp_dimensions[1]),-1,false,NULL,false,$only_make_smaller))
{ // Ah error, get the closest match we have
$value=isset($param[4])?$param[4]:$orig_url;
}
}
}
}
}
return $value;
}
integer get_max_image_size()
Get the maximum allowed image size, as set in the configuration.
Parameters…
Returns…
| Description |
The maximum image size |
| Type |
integer |
function get_max_image_size()
{
$a=php_return_bytes(ini_get('upload_max_filesize'));
$b=php_return_bytes(ini_get('post_max_size'));
$c=intval(get_option('max_download_size'))*1024;
if (has_specific_permission(get_member(),'exceed_filesize_limit')) $c=0;
$possibilities=array();
if ($a!=0) $possibilities[]=$a;
if ($b!=0) $possibilities[]=$b;
if ($c!=0) $possibilities[]=$c;
return min($possibilities);
}
tempcode do_image_thumb(URLPATH url, mixed caption, boolean js_tooltip, boolean is_thumbnail_already, integer width, integer height)
Get the tempcode for an image thumbnail.
Parameters…
| Name |
url |
| Description |
The URL to the image thumbnail |
| Type |
URLPATH |
| Name |
caption |
| Description |
The caption for the thumbnail (string or Tempcode) |
| Type |
mixed |
| Name |
js_tooltip |
| Description |
Whether to use a JS tooltip. Forcibly set to true if you pass Tempcode |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
is_thumbnail_already |
| Description |
Whether already a thumbnail (if not, function will make one) |
| Default value |
boolean-true |
| Type |
boolean |
| Name |
width |
| Description |
Thumbnail width to use |
| Default value |
90 |
| Type |
integer |
| Name |
height |
| Description |
Thumbnail height to use |
| Default value |
90 |
| Type |
integer |
Returns…
| Description |
The thumbnail |
| Type |
tempcode |
function do_image_thumb($url,$caption,$js_tooltip=false,$is_thumbnail_already=true,$width=90,$height=90)
{
if (is_object($caption))
{
$js_tooltip=true;
}
if(!$is_thumbnail_already)
{
$new_name=strval($width).'_'.strval($height).'_'.url_to_filename($url);
if (!is_saveable_image($new_name)) $new_name.='.png';
$file_thumb=get_custom_file_base().'/uploads/auto_thumbs/'.$new_name;
if (url_is_local($url)) $url=get_custom_base_url().'/'.$url;
if (!file_exists($file_thumb))
convert_image($url,$file_thumb,$width,$height,$width,false);
$url=get_custom_base_url().'/uploads/auto_thumbs/'.rawurlencode($new_name);
}
if (url_is_local($url)) $url=get_custom_base_url().'/'.$url;
if ((!is_object($caption)) && ($caption==''))
{
$caption=do_lang('THUMBNAIL');
$js_tooltip=false;
}
return do_template('IMG_THUMB',array('_GUID'=>'f1c130b7c3b2922fe273596563cb377c','JS_TOOLTIP'=>$js_tooltip,'CAPTION'=>$caption,'URL'=>$url));
}
URLPATH ensure_thumbnail(URLPATH full_url, URLPATH thumb_url, ID_TEXT thumb_dir, ID_TEXT table, AUTO_LINK id, ID_TEXT thumb_field_name, ?integer thumb_width)
Take some image/thumbnail info, and if needed make and caches a thumbnail, and return a thumb url whatever the situation.
Parameters…
| Name |
full_url |
| Description |
The full URL to the image which will-be/is thumbnailed |
| Type |
URLPATH |
| Name |
thumb_url |
| Description |
The URL to the thumbnail (blank: no thumbnail yet) |
| Type |
URLPATH |
| Name |
thumb_dir |
| Description |
The directory, relative to the ocPortal install, where the thumbnails are stored. MINUS "_thumbs" |
| Type |
ID_TEXT |
| Name |
table |
| Description |
The name of the table that is storing what we are doing the thumbnail for |
| Type |
ID_TEXT |
| Name |
id |
| Description |
The ID of the table record that is storing what we are doing the thumbnail for |
| Type |
AUTO_LINK |
| Name |
thumb_field_name |
| Description |
The name of the table field where thumbnails are saved |
| Default value |
thumb_url |
| Type |
ID_TEXT |
| Name |
thumb_width |
| Description |
The thumbnail width to use (NULL: default) |
| Default value |
|
| Type |
?integer |
Returns…
| Description |
The URL to the thumbnail |
| Type |
URLPATH |
function ensure_thumbnail($full_url,$thumb_url,$thumb_dir,$table,$id,$thumb_field_name='thumb_url',$thumb_width=NULL)
{
if (is_null($thumb_width)) $thumb_width=intval(get_option('thumb_width'));
if ((get_option('is_on_gd')=='0') || (!function_exists('imagetypes')) || ($full_url==''))
{
if ((url_is_local($thumb_url)) && ($thumb_url!='')) return get_custom_base_url().'/'.$thumb_url;
return $thumb_url;
}
if ($thumb_url!='')
{
if (url_is_local($thumb_url))
{
$thumb_path=get_custom_file_base().'/'.rawurldecode($thumb_url);
if (!file_exists($thumb_path))
{
$from=str_replace(' ','%20',$full_url);
if (url_is_local($from)) $from=get_custom_base_url().'/'.$from;
if (is_video($from))
{
require_code('galleries2');
create_video_thumb($full_url,$thumb_path);
} else
{
convert_image($from,$thumb_path,intval($thumb_width),-1,-1,false);
}
}
return get_custom_base_url().'/'.$thumb_url;
}
return $thumb_url;
}
$url_parts=explode('/',$full_url);
$i=0;
$_file=$url_parts[count($url_parts)-1];
$dot_pos=strrpos($_file,'.');
$ext=substr($_file,$dot_pos+1);
if (!is_saveable_image($_file)) $ext='png';
$_file=substr($_file,0,$dot_pos);
$thumb_path='';
do
{
$file=rawurldecode($_file).(($i==0)?'':strval($i));
$thumb_path=get_custom_file_base().'/uploads/'.$thumb_dir.'_thumbs/'.$file.'.'.$ext;
$i++;
}
while (file_exists($thumb_path));
$thumb_url='uploads/'.$thumb_dir.'_thumbs/'.rawurlencode($file).'.'.$ext;
if ((substr($table,0,2)=='f_') && (get_forum_type()=='ocf'))
{
$GLOBALS['FORUM_DB']->query_update($table,array($thumb_field_name=>$thumb_url),array('id'=>$id),'',1);
} else
{
$GLOBALS['SITE_DB']->query_update($table,array($thumb_field_name=>$thumb_url),array('id'=>$id),'',1);
}
$from=str_replace(' ','%20',$full_url);
if (url_is_local($from)) $from=get_custom_base_url().'/'.$from;
if (!file_exists($thumb_path))
{
if (is_video($from))
{
require_code('galleries2');
create_video_thumb($full_url,$thumb_path);
} else
{
convert_image($from,$thumb_path,intval($thumb_width),-1,-1,false);
}
}
return get_custom_base_url().'/'.$thumb_url;
}
boolean check_memory_limit_for(PATH file_path, boolean exit_on_error)
Check we can load the given file, given our memory limit.
Parameters…
| Name |
file_path |
| Description |
The file path we are trying to load |
| Type |
PATH |
| Name |
exit_on_error |
| Description |
Whether to exit ocPortal if an error occurs |
| Default value |
boolean-true |
| Type |
boolean |
Returns…
| Description |
Success status |
| Type |
boolean |
function check_memory_limit_for($file_path,$exit_on_error=true)
{
if (function_exists('memory_get_usage'))
{
$ov=ini_get('memory_limit');
$_what_we_will_allow=get_value('real_memory_available_mb');
$what_we_will_allow=is_null($_what_we_will_allow)?NULL:(intval($_what_we_will_allow)*1024*1024);
if ((substr($ov,-1)=='M') || (!is_null($what_we_will_allow)))
{
if (is_null($what_we_will_allow))
{
$total_memory_limit_in_bytes=intval(substr($ov,0,strlen($ov)-1))*1024*1024;
$what_we_will_allow=$total_memory_limit_in_bytes-memory_get_usage()-1024*1024*3; // 3 is for 3MB extra space needed to finish off
}
$details=@getimagesize($file_path);
if ($details!==false) // Check it is not corrupt. If it is corrupt, we will give an error later
{
$magic_factor=3.0; /* factor of inefficency by experimentation */
$channels=4;//array_key_exists('channels',$details)?$details['channels']:3; it will be loaded with 4
$bits_per_channel=8;//array_key_exists('bits',$details)?$details['bits']:8; it will be loaded with 8
$bytes=($details[0]*$details[1])*($bits_per_channel/8)*($channels+1)*$magic_factor;
if ($bytes>floatval($what_we_will_allow))
{
$max_dim=intval(sqrt(floatval($what_we_will_allow)/4.0/$magic_factor/*4 1 byte channels*/));
// Can command line imagemagick save the day?
$imagemagick='/usr/bin/convert';
if (!@file_exists($imagemagick)) $imagemagick='/usr/local/bin/convert';
if (!@file_exists($imagemagick)) $imagemagick='/opt/local/bin/convert';
if (@file_exists($imagemagick))
{
$shrink_command=$imagemagick.' '.@escapeshellarg($file_path);
$shrink_command.=' -resize '.strval(intval(floatval($max_dim)/1.5)).'x'.strval(intval(floatval($max_dim)/1.5));
$shrink_command.=' '.@escapeshellarg($file_path);
$err_cond=-1;
$output_arr=array();
@exec($shrink_command,$output_arr,$err_cond);
if ($err_cond===0) return true;
}
$message=do_lang_tempcode('IMAGE_TOO_LARGE_FOR_THUMB',escape_html(integer_format($max_dim)),escape_html(integer_format($max_dim)));
if (!$exit_on_error)
{
attach_message($message,'warn');
} else
{
warn_exit($message);
}
return false;
}
}
}
}
return true;
}
boolean convert_image(URLPATH from, PATH to, integer width, integer height, integer box_width, boolean exit_on_error, ?string ext2, boolean using_path, boolean only_make_smaller, ?array thumb_options)
Resize an image to the specified size, but retain the aspect ratio.
Parameters…
| Name |
from |
| Description |
The URL to the image to resize |
| Type |
URLPATH |
| Name |
to |
| Description |
The file path (including filename) to where the resized image will be saved |
| Type |
PATH |
| Name |
width |
| Description |
The maximum width we want our new image to be (-1 means "don't factor this in") |
| Type |
integer |
| Name |
height |
| Description |
The maximum height we want our new image to be (-1 means "don't factor this in") |
| Type |
integer |
| Name |
box_width |
| Description |
This is only considered if both $width and $height are -1. If set, it will fit the image to a box of this dimension (suited for resizing both landscape and portraits fairly) |
| Default value |
-1 |
| Type |
integer |
| Name |
exit_on_error |
| Description |
Whether to exit ocPortal if an error occurs |
| Default value |
boolean-true |
| Type |
boolean |
| Name |
ext2 |
| Description |
The file extension to save with (NULL: same as our input file) |
| Default value |
|
| Type |
?string |
| Name |
using_path |
| Description |
Whether $from was in fact a path, not a URL |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
only_make_smaller |
| Description |
Whether to apply a 'never make the image bigger' rule for thumbnail creation (would affect very small images) |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
thumb_options |
| Description |
This optional parameter allows us to specify cropping or padding for the image. See comments in the function. (NULL: no details passed) |
| Default value |
|
| Type |
?array |
Returns…
| Description |
Success |
| Type |
boolean |
function convert_image($from,$to,$width,$height,$box_width=-1,$exit_on_error=true,$ext2=NULL,$using_path=false,$only_make_smaller=false,$thumb_options=NULL)
{
disable_php_memory_limit();
// Load
$ext=get_file_extension($from);
if ($using_path)
{
if (!check_memory_limit_for($from,$exit_on_error)) return false;
$from_file=@file_get_contents($from);
} else
{
$file_path_stub=convert_url_to_path($from);
if (!is_null($file_path_stub))
{
if (!check_memory_limit_for($file_path_stub,$exit_on_error)) return false;
$from_file=@file_get_contents($file_path_stub);
} else
{
$from_file=http_download_file($from,1024*1024*20/*reasonable limit*/,false);
}
}
if ($from_file===false)
{
if ($exit_on_error) fatal_exit(do_lang_tempcode('UPLOAD_PERMISSION_ERROR',escape_html($from)));
require_code('site');
attach_message(do_lang_tempcode('UPLOAD_PERMISSION_ERROR',escape_html($from)),'warn');
return false;
}
$source=@imagecreatefromstring($from_file);
if ((!is_null($thumb_options)) || (!$only_make_smaller))
unset($from_file);
if ($source===false)
{
if ($exit_on_error) warn_exit(do_lang_tempcode('CORRUPT_FILE',escape_html($from)));
require_code('site');
attach_message(do_lang_tempcode('CORRUPT_FILE',escape_html($from)),'warn');
return false;
}
// Derive actual width x height, for the given maximum box (maintain aspect ratio)
// ===============================================================================
$sx=imagesx($source);
$sy=imagesy($source);
$red=NULL;
if (is_null($thumb_options))
{
if ($width==0) $width=1;
if ($height==0) $height=1;
// If we're not sure if this is gonna stretch to fit a width or stretch to fit a height
if (($width==-1) && ($height==-1))
{
if ($sx>$sy)
$width=$box_width;
else
$height=$box_width;
}
if (($width!=-1) && ($height!=-1))
{
if ((floatval($sx)/floatval($width))>(floatval($sy)/floatval($height)))
{
$_width=$width;
$_height=intval($sy*($width/$sx));
} else
{
$_height=$height;
$_width=intval($sx*($height/$sy));
}
}
elseif ($height==-1)
{
$_width=$width;
$_height=intval($width/($sx/$sy));
}
elseif ($width==-1)
{
$_height=$height;
$_width=intval($height/($sy/$sx));
}
if (($_width>$sx) && ($only_make_smaller))
{
$_width=$sx;
$_height=$sy;
// We can just escape, nothing to do
imagedestroy($source);
if (($using_path) && ($from==$to))
return true;
if ($using_path)
{
copy($from,$to);
} else
{
$_to=@fopen($to,'wb') OR intelligent_write_error($to);
fwrite($_to,$from_file);
fclose($_to);
}
fix_permissions($to);
sync_file($to);
return true;
}
if ($_width<1) $_width=1;
if ($_height<1) $_height=1;
// Pad out options for imagecopyresized
// $dst_im,$src_im,$dst_x,$dst_y,$src_x,$src_y,$dst_w,$dst_h,$src_w,$src_h
$dest_x = 0;
$dest_y = 0;
$source_x = 0;
$source_y = 0;
}
else
{
// Thumbnail-specific (for the moment) behaviour. We require the ability
// to crop (ie. window-off a section of the image), and pad (ie. provide a
// background around the image). We keep this separate to the above code
// because that already works well across various aspects of the site.
//
// Format of the array is 'type'=>'crop' or 'type'=>'pad'; 'where'=>'end',
// 'where'=>'start' or 'where'=>'both'. For padding, there is an optional
// 'background'=>'RRGGBBAA' or 'background'=>'RRGGBB' for colored padding
// with or without transparency.
// Grab the dimensions we would get if we didn't crop or scale
$wrong_x = intval(round(floatval($sx) / $thumb_options['scale']));
$wrong_y = intval(round(floatval($sy) / $thumb_options['scale']));
// Handle cropping here
if (($thumb_options['type'] == 'crop') || (($thumb_options['type'] == 'pad_horiz_crop_horiz') && ($wrong_x > $width)) || (($thumb_options['type'] == 'pad_vert_crop_vert') && ($wrong_y > $height)))
{
// See which direction we're cropping in
if (intval(round(floatval($sx) / $thumb_options['scale'])) != $width)
{
$crop_direction = 'x';
}
else
{
$crop_direction = 'y';
}
// We definitely have to crop, since symbols.php only tells us to crop
// if it has to. Thus we know we're going to fill the output image, the
// only question is with what part of the source image?
// Get the amount we'll lose from the source
if ($crop_direction == 'x') $crop_off = intval(($sx - ($width * $thumb_options['scale'])));
elseif ($crop_direction == 'y') $crop_off = intval(($sy - ($height * $thumb_options['scale'])));
// Now we see how much to chop off the start (we don't care about the
// end, as this will be handled by using an appropriate window size)
$displacement = 0;
if (($thumb_options['where'] == 'start') || (($thumb_options['where'] == 'start_if_vertical') && ($crop_direction == 'y')) || (($thumb_options['where'] == 'start_if_horizontal') && ($crop_direction == 'x')))
{
$displacement = 0;
}
elseif (($thumb_options['where'] == 'end') || (($thumb_options['where'] == 'end_if_vertical') && ($crop_direction == 'y')) || (($thumb_options['where'] == 'end_if_horizontal') && ($crop_direction == 'x')))
{
$displacement = intval(floatval($crop_off));
}
else
{
$displacement = intval(floatval($crop_off) / 2.0);
}
// Now we convert this to the right x and y start locations for the
// window
$source_x = ($crop_direction == 'x')? $displacement : 0;
$source_y = ($crop_direction == 'y')? $displacement : 0;
// Now we set the width and height of our window, which will be scaled
// versions of the width and height of the output
$sx = intval(($width * $thumb_options['scale']));
$sy = intval(($height * $thumb_options['scale']));
// We start at the origin of our output
$dest_x = 0;
$dest_y = 0;
// and it is always the full size it can be (or else we'd be cropping
// too much)
$_width = $width;
$_height = $height;
}
elseif ($thumb_options['type'] == 'pad' || (($thumb_options['type'] == 'pad_horiz_crop_horiz') && ($wrong_x < $width)) || (($thumb_options['type'] == 'pad_vert_crop_vert') && ($wrong_y < $height)))
{
// Padding code lives here. We definitely need to pad some excess space
// because otherwise symbols.php would not call us. Thus we need a
// background (can be transparent). Let's see if we've been given one.
if (array_key_exists('background',$thumb_options) && !is_null($thumb_options['background']))
{
if (substr($thumb_options['background'],0,1)=='#') $thumb_options['background']=substr($thumb_options['background'],1);
// We've been given a background, let's find out what it is
if (strlen($thumb_options['background']) == 8)
{
// We've got an alpha channel
$using_alpha = true;
$red_str=substr($thumb_options['background'],0,2);
$green_str=substr($thumb_options['background'],2,2);
$blue_str=substr($thumb_options['background'],4,2);
$alpha_str=substr($thumb_options['background'],6,2);
}
else
{
// We've not got an alpha channel
$using_alpha = false;
$red_str=substr($thumb_options['background'],0,2);
$green_str=substr($thumb_options['background'],2,2);
$blue_str=substr($thumb_options['background'],4,2);
}
$red = intval($red_str,16);
$green = intval($green_str,16);
$blue = intval($blue_str,16);
if ($using_alpha) $alpha = intval($alpha_str,16);
}
else
{
// We've not got a background, so let's find a representative color
// for the image by resampling the whole thing to 1 pixel.
$temp_img = imagecreatetruecolor(1,1); // Make an image to map on to
imagecopyresampled($temp_img,$source,0,0,0,0,1,1,$sx,$sy); // Map the source image on to the 1x1 image
$rgb_index = imagecolorat($temp_img, 0, 0); // Grab the color index of the single pixel
$rgb_array = imagecolorsforindex($temp_img, $rgb_index); // Get the channels for it
$red = $rgb_array['red']; // Grab the red
$green = $rgb_array['green']; // Grab the green
$blue = $rgb_array['blue']; // Grab the blue
// Sort out if we're using alpha
$using_alpha = false;
if (array_key_exists('alpha',$rgb_array)) $using_alpha = true;
if ($using_alpha) $alpha = 255-($rgb_array['alpha']*2+1);
// Destroy the temporary image
imagedestroy($temp_img);
}
// Now we need to work out how much padding we're giving, and where
// The axis
if (intval(round(floatval($sx) / $thumb_options['scale'])) != $width)
{
$pad_axis = 'x';
}
else
{
$pad_axis = 'y';
}
// The amount
if ($pad_axis == 'x') $padding = intval(round(floatval($width) - (floatval($sx) / $thumb_options['scale'])));
else $padding = intval(round(floatval($height) - (floatval($sy) / $thumb_options['scale'])));
// The distribution
if (($thumb_options['where'] == 'start') || (($thumb_options['where'] == 'start_if_vertical') && ($pad_axis == 'y')) || (($thumb_options['where'] == 'start_if_horizontal') && ($pad_axis == 'x')))
{
$pad_amount = 0;
}
else
{
$pad_amount = intval(floatval($padding) / 2.0);
}
// Now set all of the parameters needed for blitting our image
// $sx and $sy are fine, since they cover the whole image
$source_x = 0;
$source_y = 0;
$_width = ($pad_axis == 'x')? intval(round(floatval($sx) / $thumb_options['scale'])) : $width;
$_height = ($pad_axis == 'y')? intval(round(floatval($sy) / $thumb_options['scale'])) : $height;
$dest_x = ($pad_axis == 'x')? $pad_amount : 0;
$dest_y = ($pad_axis == 'y')? $pad_amount : 0;
}
}
// Resample/copy
$gd_version=get_gd_version();
if ($gd_version>=2.0) // If we have GD2
{
// Set the background if we have one
if (!is_null($thumb_options) && !is_null($red))
{
$dest=imagecreatetruecolor($width,$height);
imagealphablending($dest,false);
if ((function_exists('imagecolorallocatealpha')) && ($using_alpha)) $back_col = imagecolorallocatealpha($dest, $red, $green, $blue, 127-intval(floatval($alpha)/2.0));
else $back_col = imagecolorallocate($dest, $red, $green, $blue);
imagefilledrectangle($dest,0,0,$width,$height,$back_col);
if (function_exists('imagesavealpha')) imagesavealpha($dest,true);
} else
{
$dest=imagecreatetruecolor($_width,$_height);
imagealphablending($dest,false);
if (function_exists('imagesavealpha')) imagesavealpha($dest,true);
}
imagecopyresampled($dest,$source,$dest_x,$dest_y,$source_x,$source_y,$_width,$_height,$sx,$sy);
} else
{
// Set the background if we have one
if (!is_null($thumb_options) && !is_null($red))
{
$dest=imagecreate($width,$height);
$back_col = imagecolorallocate($dest, $red, $green, $blue);
imagefill($dest,0,0,$back_col);
} else
{
$dest=imagecreate($_width,$_height);
}
imagecopyresized($dest,$source,$dest_x,$dest_y,$source_x,$source_y,$_width,$_height,$sx,$sy);
}
// Clean up
imagedestroy($source);
// Save
if (is_null($ext2)) $ext2=get_file_extension($to);
// If we've got transparency then we have to save as PNG
if (!is_null($thumb_options) && isset($red) && $using_alpha) $ext2='png';
if ($ext2=='png')
{
if (strtolower(substr($to,-4)) != '.png') $to = $to . '.png';
$test=@imagepng($dest,$to);
if (!$test)
{
if ($exit_on_error) warn_exit(do_lang_tempcode('ERROR_IMAGE_SAVE',@strval($php_errormsg)));
require_code('site');
attach_message(do_lang_tempcode('ERROR_IMAGE_SAVE',@strval($php_errormsg)),'warn');
return false;
}
}
elseif (($ext2=='jpg') || ($ext2=='jpeg'))
{
$jpeg_quality=get_value('jpeg_quality');
if ($jpeg_quality!==NULL)
{
$test=@imagejpeg($dest,$to,intval($jpeg_quality));
} else
{
$test=@imagejpeg($dest,$to);
}
if (!$test)
{
if ($exit_on_error) warn_exit(do_lang_tempcode('ERROR_IMAGE_SAVE',@strval($php_errormsg)));
require_code('site');
attach_message(do_lang_tempcode('ERROR_IMAGE_SAVE',@strval($php_errormsg)),'warn');
return false;
}
}
elseif ((function_exists('imagegif')) && ($ext2=='gif'))
{
$test=@imagegif($dest,$to);
if (!$test)
{
if ($exit_on_error) warn_exit(do_lang_tempcode('ERROR_IMAGE_SAVE',@strval($php_errormsg)));
require_code('site');
attach_message(do_lang_tempcode('ERROR_IMAGE_SAVE',@strval($php_errormsg)),'warn');
return false;
}
} else
{
if ($exit_on_error) warn_exit(do_lang_tempcode('UNKNOWN_FORMAT',escape_html($ext2)));
require_code('site');
attach_message(do_lang_tempcode('UNKNOWN_FORMAT',escape_html($ext2)),'warn');
return false;
}
// Clean up
imagedestroy($dest);
fix_permissions($to);
sync_file($to);
return true;
}
float get_gd_version()
Get the version number of GD on the system. It should only be called if GD is known to be on the system, and in use
Parameters…
Returns…
| Description |
The version of GD installed |
| Type |
float |
function get_gd_version()
{
if (function_exists('gd_info'))
{
$info=gd_info();
$matches=array();
if (preg_match('#(\d(\.|))+#',$info['GD Version'],$matches)!=0)
{
$version=$matches[0];
} else $version=$info['version'];
return floatval($version);
}
ob_start();
phpinfo();
$_info=ob_get_contents();
ob_end_clean();
$a=explode("\n",$_info);
foreach ($a as $line)
{
if (strpos($line,"GD Version")!==false)
{
return floatval(trim(str_replace('GD Version','',strip_tags($line))));
}
}
fatal_exit(do_lang_tempcode('INTERNAL_ERROR'));
return (-1.0); // trick for Zend
}
boolean is_image(string name)
Find whether the image specified is actually an image, based on file extension
Parameters…
| Name |
name |
| Description |
A URL or file path to the image |
| Type |
string |
Returns…
| Description |
Whether the string pointed to a file appeared to be an image |
| Type |
boolean |
function is_image($name)
{
if (substr(basename($name),0,1)=='.') return false; // Temporary file that some OS's make
$ext=get_file_extension($name);
$types=explode(',',get_option('valid_images'));
foreach ($types as $val)
if (strtolower($val)==$ext) return true;
return false;
}
boolean is_video(string name, boolean must_be_true_video)
Find whether the video specified is actually a 'video', based on file extension
Parameters…
| Name |
name |
| Description |
A URL or file path to the video |
| Type |
string |
| Name |
must_be_true_video |
| Description |
Whether it really must be an actual video/audio, not some other kind of rich media which we may render in a video spot |
| Default value |
boolean-false |
| Type |
boolean |
Returns…
| Description |
Whether the string pointed to a file appeared to be a video |
| Type |
boolean |
function is_video($name,$must_be_true_video=false)
{
if ((addon_installed('galleries')) && (!$must_be_true_video))
{
$ve_hooks=find_all_hooks('systems','video_embed');
foreach (array_keys($ve_hooks) as $ve_hook)
{
require_code('hooks/systems/video_embed/'.$ve_hook);
$ve_ob=object_factory('Hook_video_embed_'.$ve_hook);
if (!is_null($ve_ob->get_template_name_and_id($name))) return true;
}
}
$ext=get_file_extension($name);
if (!$must_be_true_video)
{
if ($ext=='swf') return true;
if ($ext=='pdf') return true; // Galleries can render it as a video
}
if (($ext=='rm') || ($ext=='ram')) return true; // These have audio mime types, but may be videos
require_code('mime_types');
$mime_type=get_mime_type($ext);
return ((substr($mime_type,0,6)=='video/') || ((get_option('allow_audio_videos')=='1') && (substr($mime_type,0,6)=='audio/')));
}
boolean is_saveable_image(string name)
Use the image extension to determine if the specified image is of a format (extension) saveable by ocPortal or not.
Parameters…
| Name |
name |
| Description |
A URL or file path to the image |
| Type |
string |
Returns…
| Description |
Whether the string pointed to a file that appeared to be a saveable image |
| Type |
boolean |
function is_saveable_image($name)
{
$ext=get_file_extension($name);
if ((get_option('is_on_gd')=='1') && (function_exists('imagetypes')))
{
$gd=imagetypes();
if (($ext=='gif') && (($gd&IMG_GIF)!=0) && (function_exists('image_gif'))) return true;
if (($ext=='jpg') && (($gd&IMG_JPEG)!=0)) return true;
if (($ext=='jpeg') && (($gd&IMG_JPEG)!=0)) return true;
if (($ext=='png') && (($gd&IMG_PNG)!=0)) return true;
return false;
} else return (($ext=='jpg') || ($ext=='jpeg') || ($ext=='png'));
}
sources/galleries.php
Global_functions_galleries.php
Function summary
|
void
|
init__galleries ()
|
|
tempcode
|
render_image_box (array row, ID_TEXT zone)
|
|
tempcode
|
render_video_box (array row, ID_TEXT zone)
|
|
integer
|
get_default_gallery_max ()
|
|
boolean
|
gallery_has_content (ID_TEXT name)
|
|
?MEMBER
|
get_member_id_from_gallery_name (ID_TEXT gallery_name, ?array row)
|
|
tempcode
|
show_video_details (array myrow)
|
|
tempcode
|
show_gallery_box (array child, ID_TEXT root, boolean show_member_stats_if_appropriate, ID_TEXT zone, boolean quit_if_empty, boolean preview)
|
|
array
|
get_recursive_gallery_details (ID_TEXT name, boolean test_videos, boolean test_images)
|
|
boolean
|
only_download_galleries (ID_TEXT cat)
|
|
boolean
|
only_conventional_galleries (ID_TEXT cat)
|
|
boolean
|
only_member_galleries_of_id (ID_TEXT cat, ?MEMBER member_id, integer child_count)
|
|
tempcode
|
nice_get_gallery_tree (?ID_TEXT it, ?string filter, boolean must_accept_images, boolean must_accept_videos, boolean purity, boolean use_compound_list, ?MEMBER member_id, boolean addable_filter)
|
|
array
|
get_gallery_tree (?ID_TEXT category_id, string tree, ?array gallery_info, boolean do_stats, ?string filter, boolean must_accept_images, boolean must_accept_videos, boolean purity, boolean use_compound_list, ?integer levels, ?MEMBER member_id, boolean addable_filter)
|
|
~integer
|
can_submit_to_gallery (ID_TEXT name)
|
|
tempcode
|
gallery_breadcrumbs (ID_TEXT category_id, ID_TEXT root, boolean no_link_for_me_sir, ID_TEXT zone)
|
|
tempcode
|
nice_get_gallery_content_tree (ID_TEXT table, ?ID_TEXT it, ?AUTO_LINK submitter, boolean use_compound_list, boolean editable_filter)
|
|
array
|
get_gallery_content_tree (ID_TEXT table, ?AUTO_LINK submitter, ?ID_TEXT gallery, ?string tree, ?ID_TEXT title, ?integer levels, boolean use_compound_list, boolean editable_filter)
|
|
tempcode
|
show_gallery_media (URLPATH url, URLPATH thumb_url, integer width, integer height, integer length, ?ID_TEXT orig_filename)
|
|
string
|
get_allowed_video_file_types ()
|
void init__galleries()
Standard code module initialisation function.
Parameters…
(No return value)
function init__galleries()
{
global $GALLERY_ENTRIES_CATS_USED;
$GALLERY_ENTRIES_CATS_USED=NULL;
global $GALLERY_PAIRS;
$GALLERY_PAIRS=NULL;
global $PT_PAIR_CACHE_G;
$PT_PAIR_CACHE_G=array();
}
tempcode render_image_box(array row, ID_TEXT zone)
Render an image box.
Parameters…
| Name |
row |
| Description |
The video row |
| Type |
array |
| Name |
zone |
| Description |
The zone the galleries module is in |
| Default value |
_SEARCH |
| Type |
ID_TEXT |
Returns…
| Description |
The rendered box |
| Type |
tempcode |
function render_image_box($row,$zone='_SEARCH')
{
require_css('galleries');
require_code('images');
$url=build_url(array('page'=>'galleries','type'=>'image','id'=>$row['id']),$zone);
$thumb_url=ensure_thumbnail($row['url'],$row['thumb_url'],'galleries','images',$row['id']);
$description=get_translated_tempcode($row['comments']);
$thumb=do_image_thumb($thumb_url,$description,true);
$tree=gallery_breadcrumbs($row['cat'],'root',false,$zone);
$image_url=$row['url'];
if (url_is_local($image_url)) $image_url=get_custom_base_url().'/'.$image_url;
$title=$GLOBALS['SITE_DB']->query_value_null_ok('galleries','fullname',array('name'=>$row['cat']));
if (is_null($title))
{
$gallery_title=do_lang('UNKNOWN');
} else
{
$gallery_title=get_translated_text($title);
}
return do_template('GALLERY_IMAGE_BOX',array('ADD_DATE_RAW'=>strval($row['add_date']),'ID'=>strval($row['id']),'TITLE'=>get_translated_text($row['title']),'NOTES'=>$row['notes'],'GALLERY_TITLE'=>$gallery_title,'CAT'=>$row['cat'],'VIEWS'=>strval($row['image_views']),'TREE'=>$tree,'URL'=>$url,'IMAGE_URL'=>$image_url,'DESCRIPTION'=>$description,'THUMB'=>$thumb,'THUMB_URL'=>$thumb_url));
}
tempcode render_video_box(array row, ID_TEXT zone)
Render a video box.
Parameters…
| Name |
row |
| Description |
The video row |
| Type |
array |
| Name |
zone |
| Description |
The zone the galleries module is in |
| Default value |
_SEARCH |
| Type |
ID_TEXT |
Returns…
| Description |
The rendered box |
| Type |
tempcode |
function render_video_box($row,$zone='_SEARCH')
{
require_css('galleries');
require_code('images');
$url=build_url(array('page'=>'galleries','type'=>'video','id'=>$row['id']),$zone);
$thumb_url=ensure_thumbnail($row['url'],$row['thumb_url'],'galleries','videos',$row['id']);
$description=get_translated_tempcode($row['comments']);
$thumb=do_image_thumb($thumb_url,$description,true);
$tree=gallery_breadcrumbs($row['cat'],'root',false,$zone);
$video_url=$row['url'];
if (url_is_local($video_url)) $video_url=get_custom_base_url().'/'.$video_url;
$title=$GLOBALS['SITE_DB']->query_value_null_ok('galleries','fullname',array('name'=>$row['cat']));
if (is_null($title))
{
$gallery_title=do_lang('UNKNOWN');
} else
{
$gallery_title=get_translated_text($title);
}
return do_template('GALLERY_VIDEO_BOX',array('ADD_DATE_RAW'=>strval($row['add_date']),'ID'=>strval($row['id']),'TITLE'=>get_translated_text($row['title']),'NOTES'=>$row['notes'],'GALLERY_TITLE'=>$gallery_title,'CAT'=>$row['cat'],'VIEWS'=>strval($row['video_views']),'TREE'=>$tree,'URL'=>$url,'VIDEO_URL'=>$video_url,'DESCRIPTION'=>$description,'THUMB'=>$thumb,'THUMB_URL'=>$thumb_url,'VIDEO_WIDTH'=>strval($row['video_width']),'VIDEO_HEIGHT'=>strval($row['video_height']),'VIDEO_LENGTH'=>strval($row['video_length'])));
}
integer get_default_gallery_max()
Find the default number of images per page in the galleries.
Parameters…
Returns…
| Description |
Images per page |
| Type |
integer |
function get_default_gallery_max()
{
$option=get_option('gallery_selectors');
if ($option=='') return 12;
$selectors=explode(',',$option);
return intval($selectors[0]);
}
boolean gallery_has_content(ID_TEXT name)
Find whether a certain gallery has any content (images, videos, or subgalleries).
Parameters…
| Name |
name |
| Description |
The name of the gallery |
| Type |
ID_TEXT |
Returns…
| Description |
The answer |
| Type |
boolean |
function gallery_has_content($name)
{
$num_galleries=NULL;
global $GALLERY_ENTRIES_CATS_USED;
if (is_null($GALLERY_ENTRIES_CATS_USED))
{
$num_galleries=$GLOBALS['SITE_DB']->query_value('galleries','COUNT(*)');
$GALLERY_ENTRIES_CATS_USED=array();
$images_cats=$GLOBALS['SITE_DB']->query_select('images',array('DISTINCT cat'),($num_galleries<300)?array('validated'=>1):array('validated'=>1,'cat'=>$name));
foreach ($images_cats as $images_cat)
$GALLERY_ENTRIES_CATS_USED[$images_cat['cat']]=1;
$videos_cats=$GLOBALS['SITE_DB']->query_select('videos',array('DISTINCT cat'),($num_galleries<300)?array('validated'=>1):array('validated'=>1,'cat'=>$name));
foreach ($videos_cats as $videos_cat)
$GALLERY_ENTRIES_CATS_USED[$videos_cat['cat']]=1;
}
if (array_key_exists($name,$GALLERY_ENTRIES_CATS_USED))
{
if ($num_galleries>=300) $GALLERY_ENTRIES_CATS_USED=NULL; // It's not right so reset it
return true;
}
if ($num_galleries>=300) $GALLERY_ENTRIES_CATS_USED=NULL; // It's not right so reset it
global $GALLERY_PAIRS;
if (is_null($GALLERY_PAIRS))
{
if (is_null($num_galleries))
$num_galleries=$GLOBALS['SITE_DB']->query_value('galleries','COUNT(*)');
if ($num_galleries<300)
{
$GALLERY_PAIRS=collapse_2d_complexity('name','parent_id',$GLOBALS['SITE_DB']->query_select('galleries',array('name','parent_id')));
} else
{
return !is_null($GLOBALS['SITE_DB']->query_value_null_ok('galleries','name',array('parent_id'=>$name)));
}
}
foreach ($GALLERY_PAIRS as $_parent_id)
{
if ($_parent_id==$name) return true;
}
return false;
}
?MEMBER get_member_id_from_gallery_name(ID_TEXT gallery_name, ?array row)
Find the owner of a gallery.
Parameters…
| Name |
gallery_name |
| Description |
The name of the gallery |
| Type |
ID_TEXT |
| Name |
row |
| Description |
Gallery row (NULL: look it up) |
| Default value |
|
| Type |
?array |
Returns…
| Description |
The owner of the gallery (NULL: not a member owned gallery) |
| Type |
?MEMBER |
function get_member_id_from_gallery_name($gallery_name,$row=NULL)
{
$is_member=(substr($gallery_name,0,7)=='member_');
if (!$is_member)
{
if (is_null($row))
{
$rows=$GLOBALS['SITE_DB']->query_select('galleries',array('g_owner'),array('name'=>$gallery_name));
$row=$rows[0];
}
return $row['g_owner'];
}
return intval(substr($gallery_name,7,strpos($gallery_name,'_',7)-7));
}
tempcode show_video_details(array myrow)
Get preview detailing for a video.
Parameters…
| Name |
myrow |
| Description |
The database row of the video |
| Type |
array |
Returns…
| Description |
The preview |
| Type |
tempcode |
function show_video_details($myrow)
{
return do_template('GALLERY_VIDEO_INFO',array('HEIGHT'=>integer_format($myrow['video_height']),'WIDTH'=>integer_format($myrow['video_width']),'LENGTH'=>strval($myrow['video_length'])));
}
tempcode show_gallery_box(array child, ID_TEXT root, boolean show_member_stats_if_appropriate, ID_TEXT zone, boolean quit_if_empty, boolean preview)
Get preview detailing for a gallery.
Parameters…
| Name |
child |
| Description |
The database row of the gallery |
| Type |
array |
| Name |
root |
| Description |
The virtual root of the gallery |
| Default value |
root |
| Type |
ID_TEXT |
| Name |
show_member_stats_if_appropriate |
| Description |
Whether to show member stats if it is a member owned gallery |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
zone |
| Description |
The zone that the gallery module we are linking to is in |
| Default value |
_SEARCH |
| Type |
ID_TEXT |
| Name |
quit_if_empty |
| Description |
Whether to not show anything if the gallery is empty |
| Default value |
boolean-true |
| Type |
boolean |
| Name |
preview |
| Description |
Whether only to show 'preview' details |
| Default value |
boolean-false |
| Type |
boolean |
Returns…
| Description |
The preview |
| Type |
tempcode |
function show_gallery_box($child,$root='root',$show_member_stats_if_appropriate=false,$zone='_SEARCH',$quit_if_empty=true,$preview=false)
{
$is_member=(substr($child['name'],0,7)=='member_');
if ($is_member)
{
$member_id=get_member_id_from_gallery_name($child['name'],$child);
}
$url=build_url(array('page'=>'galleries','type'=>'misc','root'=>($root=='root')?NULL:$root,'id'=>$child['name']),$zone);
$_title=get_translated_text($child['fullname']);
$pic=$child['rep_image'];
if (($pic=='') && ($is_member)) $pic=$GLOBALS['FORUM_DRIVER']->get_member_avatar_url($member_id);
$add_date=get_timezoned_date($child['add_date'],false);
$comments=get_translated_tempcode($child['description']);
if ($show_member_stats_if_appropriate)
{
if (($is_member) && (get_forum_type()=='ocf'))
{
require_code('ocf_members');
require_code('ocf_members2');
$member_info=ocf_show_member_box($member_id,true);
} else $member_info=new ocp_tempcode();
} else $member_info=new ocp_tempcode();
list($num_children,$num_images,$num_videos)=get_recursive_gallery_details($child['name']);
if (($quit_if_empty) && ($num_images==0) && ($num_videos==0) && ($num_children==0)) return new ocp_tempcode();
$thumb_order='ORDER BY id ASC';
if (get_option('reverse_thumb_order')=='1') $thumb_order='ORDER BY id DESC';
if ($pic=='')
{
$pic=$GLOBALS['SITE_DB']->query_value_null_ok('images','thumb_url',array('cat'=>$child['name'],'validated'=>1),$thumb_order);
if ($pic==='')
{
require_code('images');
$temp=$GLOBALS['SITE_DB']->query_select('images',array('id','url'),array('cat'=>$child['name'],'validated'=>1),$thumb_order,1);
$thumb_url=ensure_thumbnail($temp[0]['url'],'','galleries','images',$temp[0]['id']);
}
}
if (is_null($pic))
{
$pic=$GLOBALS['SITE_DB']->query_value_null_ok('videos','thumb_url',array('cat'=>$child['name'],'validated'=>1),$thumb_order);
}
if (is_null($pic)) $pic='';
if (($pic!='') && (url_is_local($pic))) $pic=get_custom_base_url().'/'.$pic;
if ($pic!='')
{
require_code('images');
$thumb=do_image_thumb($pic,'');
} else $thumb=new ocp_tempcode();
if ($num_children==0)
{
if ($child['accept_videos']==0)
{
$lang=do_lang_tempcode('_SUBGALLERY_BITS_IMAGES',integer_format($num_images),integer_format($num_videos),integer_format($num_images+$num_videos));
}
elseif ($child['accept_images']==0)
{
$lang=do_lang_tempcode('_SUBGALLERY_BITS_VIDEOS',integer_format($num_images),integer_format($num_videos),integer_format($num_images+$num_videos));
} else
{
$lang=do_lang_tempcode('_SUBGALLERY_BITS',integer_format($num_images),integer_format($num_videos),integer_format($num_images+$num_videos));
}
} else
{
if ($child['accept_videos']==0)
{
$lang=do_lang_tempcode('SUBGALLERY_BITS_IMAGES',integer_format($num_children),integer_format($num_images),array(integer_format($num_videos),integer_format($num_images+$num_videos)));
}
elseif ($child['accept_images']==0)
{
$lang=do_lang_tempcode('SUBGALLERY_BITS_VIDEOS',integer_format($num_children),integer_format($num_images),array(integer_format($num_videos),integer_format($num_images+$num_videos)));
} else
{
$lang=do_lang_tempcode('SUBGALLERY_BITS',integer_format($num_children),integer_format($num_images),array(integer_format($num_videos),integer_format($num_images+$num_videos)));
}
}
$tpl=do_template('GALLERY_SUBGALLERY',array('_GUID'=>'0dbec2f11de63b0402471fe5c8b32865','NUM_VIDEOS'=>strval($num_videos),'NUM_IMAGES'=>strval($num_images),'NUM_CHILDREN'=>strval($num_children),'ID'=>$child['name'],'LANG'=>$lang,'ADD_DATE'=>$add_date,'ADD_DATE_RAW'=>strval($child['add_date']),'MEMBER_INFO'=>$member_info,'URL'=>$url,'THUMB'=>$thumb,'PIC'=>$pic,'TITLE'=>$_title,'COMMENTS'=>$comments));
return $tpl;
}
array get_recursive_gallery_details(ID_TEXT name, boolean test_videos, boolean test_images)
Get details of the contents of a gallery.
Parameters…
| Name |
name |
| Description |
The name of the gallery |
| Type |
ID_TEXT |
| Name |
test_videos |
| Description |
Whether to test for videos when making counts (ignore this parameter - used internally) |
| Default value |
boolean-true |
| Type |
boolean |
| Name |
test_images |
| Description |
Whether to test for images when making counts (ignore this parameter - used internally) |
| Default value |
boolean-true |
| Type |
boolean |
Returns…
| Description |
A triplet: (num children, num images, num videos) |
| Type |
array |
function get_recursive_gallery_details($name,$test_videos=true,$test_images=true)
{
static $total_categories=NULL;
if (is_null($total_categories)) $total_categories=$GLOBALS['SITE_DB']->query_value('galleries','COUNT(*)');
$num_images=$test_images?$GLOBALS['SITE_DB']->query_value('images','COUNT(*)',array('cat'=>$name)):0;
$num_videos=$test_videos?$GLOBALS['SITE_DB']->query_value('videos','COUNT(*)',array('cat'=>$name)):0;
if ($total_categories<200) // Make sure not too much, performance issue
{
$children=(strpos($name,'member_')!==false)?array():$GLOBALS['SITE_DB']->query_select('galleries',array('name','accept_images','accept_videos'),array('parent_id'=>$name));
$num_children=0;
foreach ($children as $child)
{
list($_num_children,$_num_images,$_num_videos)=get_recursive_gallery_details($child['name'],$child['accept_videos']==1,$child['accept_images']==1);
$num_images+=$_num_images;
$num_videos+=$_num_videos;
if (get_option('show_empty_galleries')=='1')
{
$num_children+=$_num_children+1;
} else
{
$num_children+=$_num_children+((($_num_images!=0) || ($_num_videos!=0))?1:0);
}
}
return array($num_children,$num_images,$num_videos);
}
$num_children=(strpos($name,'member_')!==false)?0:$GLOBALS['SITE_DB']->query_value('galleries','COUNT(*)',array('parent_id'=>$name));
return array($num_children,$num_images,$num_videos);
}
boolean only_download_galleries(ID_TEXT cat)
See whether a gallery is a download gallery (designed as a filter).
Parameters…
| Name |
cat |
| Description |
The gallery name |
| Type |
ID_TEXT |
Returns…
| Description |
Whether the gallery is a download gallery |
| Type |
boolean |
function only_download_galleries($cat)
{
return (substr($cat,0,9)=='download_');
}
boolean only_conventional_galleries(ID_TEXT cat)
See whether a gallery is NOT a download gallery (designed as a filter).
Parameters…
| Name |
cat |
| Description |
The gallery name |
| Type |
ID_TEXT |
Returns…
| Description |
Whether the gallery is NOT a download gallery |
| Type |
boolean |
function only_conventional_galleries($cat)
{
return (substr($cat,0,9)!='download_');
}
boolean only_member_galleries_of_id(ID_TEXT cat, ?MEMBER member_id, integer child_count)
See whether the GET parameter 'id' is of a gallery that is a member gallery of the given member gallery container, or just a normal gallery.
Parameters…
| Name |
cat |
| Description |
The gallery name |
| Type |
ID_TEXT |
| Name |
member_id |
| Description |
Member we are filtering for (NULL: not needed) |
| Type |
?MEMBER |
| Name |
child_count |
| Description |
The number of children for this gallery |
| Type |
integer |
Returns…
| Description |
The answer |
| Type |
boolean |
function only_member_galleries_of_id($cat,$member_id,$child_count)
{
if (substr($cat,0,7)!='member_') return ($child_count!=0);
return (substr($cat,7,strlen(strval($member_id))+1)==strval($member_id).'_');
}
tempcode nice_get_gallery_tree(?ID_TEXT it, ?string filter, boolean must_accept_images, boolean must_accept_videos, boolean purity, boolean use_compound_list, ?MEMBER member_id, boolean addable_filter)
Gets a gallery selection tree list, extending deeper from the given category_id, showing all sub(sub...)galleries.
Parameters…
| Name |
it |
| Description |
The gallery to select by default (NULL: no specific default) |
| Default value |
|
| Type |
?ID_TEXT |
| Name |
filter |
| Description |
A function name to filter galleries with (NULL: no filter) |
| Default value |
|
| Type |
?string |
| Name |
must_accept_images |
| Description |
Whether displayed galleries must support images |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
must_accept_videos |
| Description |
Whether displayed galleries must support videos |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
purity |
| Description |
Whether to NOT show member galleries that do not exist yet |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
use_compound_list |
| Description |
Whether to get a list of child galleries (not just direct ones, recursively), instead of just IDs |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
member_id |
| Description |
Member we are filtering for (NULL: not needed) |
| Default value |
|
| Type |
?MEMBER |
| Name |
addable_filter |
| Description |
Whether to only show for what may be added to by the current member |
| Default value |
boolean-false |
| Type |
boolean |
Returns…
| Description |
The tree list |
| Type |
tempcode |
function nice_get_gallery_tree($it=NULL,$filter=NULL,$must_accept_images=false,$must_accept_videos=false,$purity=false,$use_compound_list=false,$member_id=NULL,$addable_filter=false)
{
$tree=get_gallery_tree('root','',NULL,false,$filter,$must_accept_images,$must_accept_videos,$purity,$use_compound_list,NULL,$member_id,$addable_filter);
if ($use_compound_list) $tree=$tree[0];
$out=''; // XHTMLXHTML
foreach ($tree as $category)
{
if (($addable_filter) && (!$category['addable'])) continue;
$selected=($category['id']==$it);
$out.='<option value="'.(!$use_compound_list?$category['id']:$category['compound_list']).'"'.($selected?' selected="selected"':'').'>'.escape_html($category['tree']).'</option>';
}
if ($GLOBALS['XSS_DETECT']) ocp_mark_as_escaped($out);
return make_string_tempcode($out);
}
array get_gallery_tree(?ID_TEXT category_id, string tree, ?array gallery_info, boolean do_stats, ?string filter, boolean must_accept_images, boolean must_accept_videos, boolean purity, boolean use_compound_list, ?integer levels, ?MEMBER member_id, boolean addable_filter)
Gets a gallery selection tree list, extending deeper from the given category_id, showing all sub(sub...)galleries.
Parameters…
| Name |
category_id |
| Description |
The gallery we are getting the tree starting from (NULL: root) |
| Default value |
root |
| Type |
?ID_TEXT |
| Name |
tree |
| Description |
The parent tree at this point of the recursion |
| Default value |
|
| Type |
string |
| Name |
gallery_info |
| Description |
The database row for the $category_id gallery (NULL: get it from the DB) |
| Default value |
|
| Type |
?array |
| Name |
do_stats |
| Description |
Whether to include video/image statistics in the returned tree |
| Default value |
boolean-true |
| Type |
boolean |
| Name |
filter |
| Description |
A function name to filter galleries with (NULL: no filter) |
| Default value |
|
| Type |
?string |
| Name |
must_accept_images |
| Description |
Whether displayed galleries must support images |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
must_accept_videos |
| Description |
Whether displayed galleries must support videos |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
purity |
| Description |
Whether to NOT show member galleries that do not exist yet |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
use_compound_list |
| Description |
Whether to get a list of child galleries (not just direct ones, recursively), instead of just IDs |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
levels |
| Description |
The number of recursive levels to search (NULL: all) |
| Default value |
|
| Type |
?integer |
| Name |
member_id |
| Description |
Member we are filtering for (NULL: not needed) |
| Default value |
|
| Type |
?MEMBER |
| Name |
addable_filter |
| Description |
Whether to only show for what may be added to by the current member |
| Default value |
boolean-false |
| Type |
boolean |
Returns…
| Description |
The tree structure, or if $use_compound_list, the tree structure built with pairs containing the compound list in addition to the child branches |
| Type |
array |
function get_gallery_tree($category_id='root',$tree='',$gallery_info=NULL,$do_stats=true,$filter=NULL,$must_accept_images=false,$must_accept_videos=false,$purity=false,$use_compound_list=false,$levels=NULL,$member_id=NULL,$addable_filter=false)
{
if ($levels==-1) return $use_compound_list?array(array(),''):array();
if (is_null($category_id)) $category_id='root';
if (!has_category_access(get_member(),'galleries',$category_id)) return $use_compound_list?array(array(),''):array();
// Put our title onto our tree
if (is_null($gallery_info))
{
$_gallery_info=$GLOBALS['SITE_DB']->query_select('galleries',array('fullname','is_member_synched','accept_images','accept_videos'),array('name'=>$category_id),'',1);
if (!array_key_exists(0,$_gallery_info)) warn_exit(do_lang_tempcode('_MISSING_RESOURCE',escape_html('gallery:'.$category_id)));
$gallery_info=$_gallery_info[0];
}
$title=array_key_exists('text_original',$gallery_info)?$gallery_info['text_original']:get_translated_text($gallery_info['fullname']);
$is_member_synched=$gallery_info['is_member_synched']==1;
$accept_images=$gallery_info['accept_images']==1;
$accept_videos=$gallery_info['accept_videos']==1;
$tree.=$title;
$children=array();
$sub=false;
$query='FROM '.get_table_prefix().'galleries g LEFT JOIN '.get_table_prefix().'translate t ON '.db_string_equal_to('language',user_lang()).' AND g.fullname=t.id WHERE '.db_string_equal_to('parent_id',$category_id);
if (current(current($GLOBALS['SITE_DB']->query('SELECT COUNT(*) '.$query)))>=300)
{
$rows=$GLOBALS['SITE_DB']->query('SELECT text_original,name,fullname,accept_images,accept_videos,is_member_synched,g.fullname '.$query.' ORDER BY add_date',300);
} else
{
$rows=$GLOBALS['SITE_DB']->query('SELECT text_original,name,fullname,accept_images,accept_videos,is_member_synched,g.fullname '.$query.' ORDER BY text_original ASC');
}
if (((is_null($filter)) || (call_user_func_array($filter,array($category_id,$member_id,count($rows))))) && ((!$must_accept_images) || (($accept_images) && (!$is_member_synched))) && ((!$must_accept_videos) || (($accept_videos) && (!$is_member_synched))))
{
// We'll be putting all children in this entire tree into a single list
$children[0]['id']=$category_id;
$children[0]['tree']=$tree;
$children[0]['title']=$title;
$children[0]['accept_images']=$gallery_info['accept_images'];
$children[0]['accept_videos']=$gallery_info['accept_videos'];
$children[0]['is_member_synched']=$gallery_info['is_member_synched'];
if ($addable_filter) $children[0]['addable']=has_submit_permission('mid',get_member(),get_ip_address(),'cms_galleries',array('galleries',$category_id));
if ($do_stats)
{
$good_row_count=0;
foreach ($rows as $row)
{
if (((is_null($filter)) || (call_user_func_array($filter,array($row['name'],$member_id,1)))) && ((!$must_accept_images) || (($row['accept_images']) && ($row['is_member_synched']==0))) && ((!$must_accept_videos) || (($row['accept_videos']) && ($row['is_member_synched']==0))))
$good_row_count++;
}
$children[0]['child_count']=$good_row_count;
if (($good_row_count==0) && (!$purity) && ($gallery_info['is_member_synched'])) $children[0]['child_count']=1; // XHTMLXHTML
$children[0]['video_count']=$GLOBALS['SITE_DB']->query_value('videos','COUNT(*)',array('cat'=>$category_id));
$children[0]['image_count']=$GLOBALS['SITE_DB']->query_value('images','COUNT(*)',array('cat'=>$category_id));
}
$sub=true;
}
$can_submit=mixed();
// Children of this category
$tree.=' > ';
$found_own_gallery=false;
$found_member_galleries=array($GLOBALS['FORUM_DRIVER']->get_guest_id()=>1);
$compound_list=$category_id.',';
foreach ($rows as $child)
{
if ($child['name']=='root') continue;
$can_submit=can_submit_to_gallery($child['name']);
if ($can_submit===false) $can_submit=!$addable_filter;
if (($can_submit!==false) && ($can_submit!==true))
{
$found_own_gallery=true;
$found_member_galleries[$can_submit]=1;
}
if (($can_submit!==false) && (($levels!==0) || ($use_compound_list)))
{
$child_id=$child['name'];
// $child_title=$child['text_original'];
$child_tree=$tree;
$child_children=get_gallery_tree($child_id,$child_tree,$child,$do_stats,$filter,$must_accept_images,$must_accept_videos,$purity,$use_compound_list,is_null($levels)?NULL:($levels-1),$member_id,$addable_filter);
if ($use_compound_list)
{
list($child_children,$_compound_list)=$child_children;
$compound_list.=$_compound_list;
}
if ($levels!==0)
$children=array_merge($children,$child_children);
}
}
if (($sub) && (array_key_exists(0,$children)))
{
$children[0]['compound_list']=$compound_list;
}
$done_for_all=false;
if (($is_member_synched) && (!$purity) && ($levels!==0))
{
if ((has_specific_permission(get_member(),'can_submit_to_others_categories')) && (get_forum_type()=='ocf'))
{
ocf_require_all_forum_stuff();
$members=$GLOBALS['FORUM_DB']->query_select('f_members',array('id','m_username','m_primary_group'),NULL,'ORDER BY m_username',100);
if (count($members)!=100) // Performance tweak. Only do if we don't have too many results
{
$done_for_all=true;
$group_membership=$GLOBALS['FORUM_DB']->query_select('f_group_members',array('gm_group_id','gm_member_id'),array('gm_validated'=>1));
$group_permissions=$GLOBALS['SITE_DB']->query('SELECT group_id,the_page,the_value FROM '.$GLOBALS['SITE_DB']->get_table_prefix().'gsp WHERE '.db_string_equal_to('specific_permission','have_personal_category').' AND ('.db_string_equal_to('the_page','').' OR '.db_string_equal_to('the_page','cms_galleries').')');
$is_super_admin=$GLOBALS['FORUM_DRIVER']->is_super_admin(get_member());
foreach ($members as $_member)
{
$member=$_member['id'];
$username=$_member['m_username'];
$this_category_id='member_'.strval($member).'_'.$category_id;
if ($member==get_member())
{
$has_permission=true;
} else
{
$a=(in_array(array('group_id'=>$member['m_primary_group'],'the_page'=>'','the_value'=>1),$group_permissions));
$b=(in_array(array('group_id'=>$member['m_primary_group'],'the_page'=>'cms_galleries','the_value'=>0),$group_permissions));
$c=(in_array(array('group_id'=>$member['m_primary_group'],'the_page'=>'cms_galleries','the_value'=>1),$group_permissions));
$has_permission=$is_super_admin;
if ((($a) && (!$b)) || ($c))
$has_permission=true;
if (!$has_permission)
{
foreach ($group_membership as $_g)
{
if ($_g['gm_member_id']==$member)
{
$a=(in_array(array('group_id'=>$_g['gm_group_id'],'the_page'=>'','the_value'=>1),$group_permissions));
$b=(in_array(array('group_id'=>$_g['gm_group_id'],'the_page'=>'cms_galleries','the_value'=>0),$group_permissions));
$c=(in_array(array('group_id'=>$_g['gm_group_id'],'the_page'=>'cms_galleries','the_value'=>1),$group_permissions));
if ((($a) && (!$b)) || ($c))
$has_permission=true;
break;
}
}
}
}
if (($has_permission) && (!array_key_exists($member,$found_member_galleries)) && ((is_null($filter)) || (call_user_func_array($filter,array($this_category_id,$member_id,0)))))
{
$own_gallery=array();
$own_gallery['id']=$this_category_id;
$this_title=do_lang('NEW_PERSONAL_GALLERY_OF',$username,$title);
$own_gallery['tree']=$tree.$this_title;
$own_gallery['video_count']=0;
$own_gallery['image_count']=0;
$own_gallery['child_count']=0;
$own_gallery['title']=$this_title;
$own_gallery['accept_images']=$gallery_info['accept_images'];
$own_gallery['accept_videos']=$gallery_info['accept_videos'];
$own_gallery['is_member_synched']=0;
$own_gallery['compound_list']=$compound_list;
$own_gallery['addable']=true;
$children[]=$own_gallery;
if ($member==get_member()) $found_own_gallery=true;
}
}
}
}
if (((!$done_for_all) || (!$found_own_gallery)) && (!array_key_exists(get_member(),$found_member_galleries)) && (!is_guest()) && (!$purity) && (has_specific_permission(get_member(),'have_personal_category')))
{
$this_category_id='member_'.strval(get_member()).'_'.$category_id;
if ((is_null($filter)) || (call_user_func_array($filter,array($this_category_id,$member_id,0))))
{
$own_gallery=array();
$own_gallery['id']=$this_category_id;
$this_title=do_lang('NEW_PERSONAL_GALLERY_OF',$GLOBALS['FORUM_DRIVER']->get_username(get_member()),$title);
$own_gallery['tree']=$tree.$this_title;
$own_gallery['video_count']=0;
$own_gallery['image_count']=0;
$own_gallery['child_count']=0;
$own_gallery['title']=$this_title;
$own_gallery['accept_images']=$gallery_info['accept_images'];
$own_gallery['accept_videos']=$gallery_info['accept_videos'];
$own_gallery['is_member_synched']=0;
$own_gallery['addable']=true;
$own_gallery['compound_list']=$compound_list;
$children[]=$own_gallery;
}
}
}
return $use_compound_list?array($children,$compound_list):$children;
}
~integer can_submit_to_gallery(ID_TEXT name)
See whether the current member can submit to the named member gallery. Note - this function assumes that members have general submit permission, and does not check for gallery read access.
Parameters…
| Name |
name |
| Description |
The gallery name |
| Type |
ID_TEXT |
Returns…
| Description |
The owner of the gallery (false: we aren't allowed to submit to it) (-2: not a member gallery) |
| Type |
~integer |
function can_submit_to_gallery($name)
{
if (substr($name,0,7)!='member_') return (-2);
$parts=explode('_',$name);
if (intval($parts[1])==get_member()) return intval($parts[1]);
if (has_specific_permission(get_member(),'can_submit_to_others_categories')) return intval($parts[1]);
return false;
}
tempcode gallery_breadcrumbs(ID_TEXT category_id, ID_TEXT root, boolean no_link_for_me_sir, ID_TEXT zone)
Get a UI element of a route from a known gallery back to the declared root of the tree.
Parameters…
| Name |
category_id |
| Description |
The gallery name |
| Type |
ID_TEXT |
| Name |
root |
| Description |
The virtual root |
| Default value |
root |
| Type |
ID_TEXT |
| Name |
no_link_for_me_sir |
| Description |
Whether not to put a link at this point in the navigation tree (usually, because the viewer is already at it) |
| Default value |
boolean-true |
| Type |
boolean |
| Name |
zone |
| Description |
The zone that the linked to gallery module is in |
| Default value |
|
| Type |
ID_TEXT |
Returns…
| Description |
The navigation element |
| Type |
tempcode |
function gallery_breadcrumbs($category_id,$root='root',$no_link_for_me_sir=true,$zone='')
{
if ($category_id=='') $category_id='root'; // To fix corrupt data
$url=build_url(array('page'=>'galleries','type'=>'misc','id'=>$category_id,'root'=>($root=='root')?NULL:$root),$zone);
if (($category_id==$root) || ($category_id=='root'))
{
if ($no_link_for_me_sir) return new ocp_tempcode();
$title=get_translated_text($GLOBALS['SITE_DB']->query_value('galleries','fullname',array('name'=>$category_id)));
return hyperlink($url,escape_html($title),false,false,do_lang_tempcode('GO_BACKWARDS_TO',$title),NULL,NULL,'up');
}
global $PT_PAIR_CACHE_G;
if (!array_key_exists($category_id,$PT_PAIR_CACHE_G))
{
$category_rows=$GLOBALS['SITE_DB']->query_select('galleries',array('parent_id','fullname'),array('name'=>$category_id),'',1);
if (!array_key_exists(0,$category_rows)) return new ocp_tempcode();//fatal_exit(do_lang_tempcode('CAT_NOT_FOUND',escape_html($category_id)));
$PT_PAIR_CACHE_G[$category_id]=$category_rows[0];
}
$title=get_translated_text($PT_PAIR_CACHE_G[$category_id]['fullname']);
if (!$no_link_for_me_sir)
{
$tpl_url=do_template('BREADCRUMB_ESCAPED');
$tpl_url->attach(hyperlink($url,escape_html($title),false,false,do_lang_tempcode('GO_BACKWARDS_TO',$title),NULL,NULL,'up'));
} else $tpl_url=new ocp_tempcode();
if ($PT_PAIR_CACHE_G[$category_id]['parent_id']==$category_id) fatal_exit(do_lang_tempcode('RECURSIVE_TREE_CHAIN',escape_html($category_id)));
$below=gallery_breadcrumbs($PT_PAIR_CACHE_G[$category_id]['parent_id'],$root,false,$zone);
$below->attach($tpl_url);
return $below;
}
tempcode nice_get_gallery_content_tree(ID_TEXT table, ?ID_TEXT it, ?AUTO_LINK submitter, boolean use_compound_list, boolean editable_filter)
Get a nice, formatted XHTML list of gallery entries, in gallery tree structure
Parameters…
| Name |
table |
| Description |
The table we are working with |
| Type |
ID_TEXT |
| Values restricted to |
images videos |
| Name |
it |
| Description |
The currently selected entry (NULL: none selected) |
| Default value |
|
| Type |
?ID_TEXT |
| Name |
submitter |
| Description |
Only show images/videos submitted by this member (NULL: no filter) |
| Default value |
|
| Type |
?AUTO_LINK |
| Name |
use_compound_list |
| Description |
Whether to get a list of child galleries (not just direct ones, recursively), instead of just IDs |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
editable_filter |
| Description |
Whether to only show for what may be edited by the current member |
| Default value |
boolean-false |
| Type |
boolean |
Returns…
| Description |
The list of entries |
| Type |
tempcode |
function nice_get_gallery_content_tree($table,$it=NULL,$submitter=NULL,$use_compound_list=false,$editable_filter=false)
{
$tree=get_gallery_content_tree($table,$submitter,NULL,NULL,NULL,NULL,$use_compound_list,$editable_filter);
if ($use_compound_list) $tree=$tree[0];
$out=''; // XHTMLXHTML
foreach ($tree as $gallery)
{
foreach ($gallery['entries'] as $eid=>$etitle)
{
$selected=($eid==$it);
$line=do_template('GALLERY_ENTRY_LIST_LINE',array('_GUID'=>'5a6fac8a768e049f9cc6c2d4ec77eeca','TREE'=>$gallery['tree'],'URL'=>$etitle));
$out.='<option value="'.(!$use_compound_list?strval($eid):$gallery['compound_list']).'"'.($selected?'selected="selected"':'').'>'.$line->evaluate().'</option>';
}
}
if ($GLOBALS['XSS_DETECT']) ocp_mark_as_escaped($out);
return make_string_tempcode($out);
}
array get_gallery_content_tree(ID_TEXT table, ?AUTO_LINK submitter, ?ID_TEXT gallery, ?string tree, ?ID_TEXT title, ?integer levels, boolean use_compound_list, boolean editable_filter)
Get a list of maps containing all the gallery entries, and path information, under the specified gallery - and those beneath it, recursively.
Parameters…
| Name |
table |
| Description |
The table we are working with |
| Type |
ID_TEXT |
| Values restricted to |
images videos |
| Name |
submitter |
| Description |
Only show images/videos submitted by this member (NULL: no filter) |
| Default value |
|
| Type |
?AUTO_LINK |
| Name |
gallery |
| Description |
The gallery being at the root of our recursion (NULL: true root) |
| Default value |
|
| Type |
?ID_TEXT |
| Name |
tree |
| Description |
The tree up to this point in the recursion (NULL: blank, as we are starting the recursion) |
| Default value |
|
| Type |
?string |
| Name |
title |
| Description |
The name of the $gallery we are currently going through (NULL: look it up). This is here for efficiency reasons, as finding children IDs to recurse to also reveals the childs title |
| Default value |
|
| Type |
?ID_TEXT |
| Name |
levels |
| Description |
The number of recursive levels to search (NULL: all) |
| Default value |
|
| Type |
?integer |
| Name |
use_compound_list |
| Description |
Whether to get a list of child galleries (not just direct ones, recursively), instead of just IDs |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
editable_filter |
| Description |
Whether to only show for what may be edited by the current member |
| Default value |
boolean-false |
| Type |
boolean |
Returns…
| Description |
A list of maps for all galleries. Each map entry containins the fields 'id' (gallery ID) and 'tree' (tree path to the category, including the categories own title), and more. Or if $use_compound_list, the tree structure built with pairs containing the compound list in addition to the child branches |
| Type |
array |
function get_gallery_content_tree($table,$submitter=NULL,$gallery=NULL,$tree=NULL,$title=NULL,$levels=NULL,$use_compound_list=false,$editable_filter=false)
{
if (is_null($gallery)) $gallery='root';
if (!has_category_access(get_member(),'galleries',$gallery)) return array();
if (is_null($tree)) $tree='';
// Put our title onto our tree
if (is_null($title)) $title=get_translated_text($GLOBALS['SITE_DB']->query_value('galleries','fullname',array('name'=>$gallery)));
$tree.=$title;
// We'll be putting all children in this entire tree into a single list
$children=array();
$children[0]=array();
$children[0]['id']=$gallery;
$children[0]['title']=$title;
$children[0]['tree']=$tree;
$compound_list=$gallery.',';
// Children of this category
$rows=$GLOBALS['SITE_DB']->query_select('galleries',array('name','fullname'),array('parent_id'=>$gallery),'ORDER BY add_date DESC',300);
$where=array('cat'=>$gallery);
if (!is_null($submitter)) $where['submitter']=$submitter;
$erows=$GLOBALS['SITE_DB']->query_select($table,array('id','url','submitter','title'),$where,'ORDER BY add_date DESC',300);
$children[0]['entries']=array();
foreach ($erows as $row)
{
if (($editable_filter) && (!has_edit_permission('mid',get_member(),$row['submitter'],'cms_galleries',array('galleries',$gallery)))) continue;
$e_title=get_translated_text($row['title']);
if ($e_title=='') $e_title=basename($row['url']);
$children[0]['entries'][$row['id']]=$e_title;
}
$children[0]['child_entry_count']=count($children[0]['entries']);
if ($levels===0) // We throw them away now because they're not on the desired level
{
$children[0]['entries']=array();
}
$children[0]['child_count']=count($rows);
$tree.=' > ';
if ($levels!==0)
{
foreach ($rows as $child)
{
$child_id=$child['name'];
$child_title=get_translated_text($child['fullname']);
$child_tree=$tree;
$child_children=get_gallery_content_tree($table,$submitter,$child_id,$child_tree,$child_title,is_null($levels)?NULL:($levels-1),$use_compound_list,$editable_filter);
if ($use_compound_list)
{
list($child_children,$_compound_list)=$child_children;
$compound_list.=$_compound_list;
}
$children=array_merge($children,$child_children);
}
}
$children[0]['compound_list']=$compound_list;
return $use_compound_list?array($children,$compound_list):$children;
}
tempcode show_gallery_media(URLPATH url, URLPATH thumb_url, integer width, integer height, integer length, ?ID_TEXT orig_filename)
Show a gallery media item (not an image, something more complex)
Parameters…
| Name |
url |
| Description |
URL to media |
| Type |
URLPATH |
| Name |
thumb_url |
| Description |
URL to thumbnail |
| Type |
URLPATH |
| Name |
width |
| Description |
Width |
| Type |
integer |
| Name |
height |
| Description |
Height |
| Type |
integer |
| Name |
length |
| Description |
Length |
| Type |
integer |
| Name |
orig_filename |
| Description |
Original filename of media file (NULL: find from URL) |
| Default value |
|
| Type |
?ID_TEXT |
Returns…
| Description |
Displayed media |
| Type |
tempcode |
function show_gallery_media($url,$thumb_url,$width,$height,$length,$orig_filename=NULL)
{
require_lang('galleries');
if (url_is_local($thumb_url)) $thumb_url=get_custom_base_url().'/'.$thumb_url;
$full_url=url_is_local($url)?(get_custom_base_url().'/'.$url):$url;
$extension=get_file_extension(is_null($orig_filename)?$url:$orig_filename);
require_code('mime_types');
$mime_type=get_mime_type($extension);
if ($extension=='swf')
{
$mime_type='application/x-shockwave-flash';
$tpl='GALLERY_SWF';
} else
{
switch ($mime_type)
{
case 'application/pdf':
$tpl='GALLERY_PDF';
break;
case 'video/quicktime':
$tpl='GALLERY_VIDEO_QT';
break;
case 'audio/x-pn-realaudio':
$tpl='GALLERY_VIDEO_RM';
break;
case 'video/x-flv':
case 'video/mp4':
case 'audio/x-mpeg':
case 'video/webm':
if (addon_installed('jwplayer'))
{
$tpl='GALLERY_VIDEO_FLV';
break;
}
default:
$matches=array();
$ve_hooks=find_all_hooks('systems','video_embed');
foreach (array_keys($ve_hooks) as $ve_hook)
{
require_code('hooks/systems/video_embed/'.$ve_hook);
$ve_ob=object_factory('Hook_video_embed_'.$ve_hook);
$ve_test=$ve_ob->get_template_name_and_id($url);
if (!is_null($ve_test))
{
list($tpl,$full_url)=$ve_test;
break 2;
}
}
$tpl='GALLERY_VIDEO_GENERAL';
}
}
return do_template($tpl,array('THUMB_URL'=>$thumb_url,'URL'=>$full_url,'LENGTH'=>strval($length),'WIDTH'=>strval($width),'HEIGHT'=>strval($height),'MIME_TYPE'=>$mime_type));
}
string get_allowed_video_file_types()
Get a comma-separated list of allowed file types for video upload.
Parameters…
Returns…
| Description |
Allowed file types |
| Type |
string |
function get_allowed_video_file_types()
{
$supported='3gp,asf,avi,flv,m4v,mov,mp4,mpe,mpeg,mpg,ogg,ogv,qt,ra,ram,rm,webm,wmv';
if (get_option('allow_audio_videos')=='1')
{
$supported.=',mid,mp3,wav,wma';
}
$supported.=',pdf';
if (has_specific_permission(get_member(),'use_very_dangerous_comcode'))
{
$supported.=',swf';
}
return $supported;
}
sources/galleries2.php
Global_functions_galleries2.php
Function summary
|
~array
|
get_video_details (PATH file_path, string filename, boolean delay_errors)
|
|
integer
|
read_intel_endian_int (string buffer)
|
|
integer
|
read_network_endian_int (string buffer)
|
|
array
|
_get_wmv_details (resource file)
|
|
?array
|
_get_wmv_details_do_chunk_list (resource file, ?integer chunk_length)
|
|
array
|
_get_avi_details (resource file)
|
|
?array
|
_get_ram_details (resource file)
|
|
?array
|
_get_mov_details (resource file)
|
|
array
|
_get_mov_details_do_atom_list (resource file, ?integer atom_size)
|
|
AUTO_LINK
|
add_image (SHORT_TEXT title, ID_TEXT cat, LONG_TEXT comments, URLPATH url, URLPATH thumb_url, BINARY validated, BINARY allow_rating, BINARY allow_comments, BINARY allow_trackbacks, LONG_TEXT notes, ?MEMBER submitter, ?TIME add_date, ?TIME edit_date, integer views, ?AUTO_LINK id)
|
|
void
|
edit_image (AUTO_LINK id, SHORT_TEXT title, ID_TEXT cat, LONG_TEXT comments, URLPATH url, URLPATH thumb_url, BINARY validated, BINARY allow_rating, BINARY allow_comments, BINARY allow_trackbacks, LONG_TEXT notes, SHORT_TEXT meta_keywords, LONG_TEXT meta_description)
|
|
void
|
delete_image (AUTO_LINK id, boolean delete_full)
|
|
URLPATH
|
create_video_thumb (URLPATH src_url, ?PATH expected_output_path)
|
|
AUTO_LINK
|
add_video (SHORT_TEXT title, ID_TEXT cat, LONG_TEXT comments, URLPATH url, URLPATH thumb_url, BINARY validated, BINARY allow_rating, BINARY allow_comments, BINARY allow_trackbacks, LONG_TEXT notes, integer video_length, integer video_width, integer video_height, ?MEMBER submitter, ?TIME add_date, ?TIME edit_date, integer views, ?AUTO_LINK id)
|
|
void
|
edit_video (AUTO_LINK id, SHORT_TEXT title, ID_TEXT cat, LONG_TEXT comments, URLPATH url, URLPATH thumb_url, BINARY validated, BINARY allow_rating, BINARY allow_comments, BINARY allow_trackbacks, LONG_TEXT notes, integer video_length, integer video_width, integer video_height, SHORT_TEXT meta_keywords, LONG_TEXT meta_description)
|
|
void
|
delete_video (AUTO_LINK id, boolean delete_full)
|
|
void
|
watermark_gallery_image (ID_TEXT gallery, PATH file_path, string filename)
|
|
void
|
_watermark_corner (resource source, URLPATH watermark_url, BINARY x, BINARY y)
|
|
void
|
constrain_gallery_image_to_max_size (PATH file_path, string filename, integer box_width)
|
|
void
|
add_gallery (ID_TEXT name, SHORT_TEXT fullname, LONG_TEXT description, SHORT_TEXT teaser, LONG_TEXT notes, ID_TEXT parent_id, BINARY accept_images, BINARY accept_videos, BINARY is_member_synched, BINARY flow_mode_interface, URLPATH rep_image, URLPATH watermark_top_left, URLPATH watermark_top_right, URLPATH watermark_bottom_left, URLPATH watermark_bottom_right, BINARY allow_rating, BINARY allow_comments, boolean skip_exists_check, ?TIME add_date, ?MEMBER g_owner)
|
|
void
|
edit_gallery (ID_TEXT old_name, ID_TEXT name, SHORT_TEXT fullname, LONG_TEXT description, SHORT_TEXT teaser, LONG_TEXT notes, ?ID_TEXT parent_id, BINARY accept_images, BINARY accept_videos, BINARY is_member_synched, BINARY flow_mode_interface, URLPATH rep_image, URLPATH watermark_top_left, URLPATH watermark_top_right, URLPATH watermark_bottom_left, URLPATH watermark_bottom_right, ?SHORT_TEXT meta_keywords, ?LONG_TEXT meta_description, BINARY allow_rating, BINARY allow_comments, ?MEMBER g_owner)
|
|
void
|
delete_gallery (ID_TEXT name)
|
|
void
|
make_member_gallery_if_needed (ID_TEXT cat)
|
~array get_video_details(PATH file_path, string filename, boolean delay_errors)
Get width,height,length of a video file. Note: unfortunately mpeg is not possible without huge amounts of code.
Parameters…
| Name |
file_path |
| Description |
The path to the video file |
| Type |
PATH |
| Name |
filename |
| Description |
The original filename of the video file (so we can find the file type from the file extension) |
| Type |
string |
| Name |
delay_errors |
| Description |
Whether to skip over errored files instead of dying. We don't currently make use of this as our readers aren't sophisticard enough to properly spot erroneous situations. |
| Default value |
boolean-false |
| Type |
boolean |
Returns…
| Description |
The triplet of width/height/length (possibly containing NULL's for when we can't detect properties) (false: error) |
| Type |
~array |
function get_video_details($file_path,$filename,$delay_errors=false)
{
unset($delay_errors);
$info=NULL;
$extension=get_file_extension($filename);
$file=@fopen($file_path,'rb');
if ($file===false) return false;
switch ($extension)
{
case 'wmv':
$info=_get_wmv_details($file);
break;
case 'asf':
$info=_get_wmv_details($file);
break;
case 'avi':
$info=_get_avi_details($file);
break;
case 'rm':
$info=_get_ram_details($file);
break;
case 'ram':
$info=_get_ram_details($file);
break;
case 'qt':
$info=_get_mov_details($file);
break;
case 'mov':
$info=_get_mov_details($file);
break;
case 'mp4':
$info=_get_mov_details($file);
break;
case 'm4v':
$info=_get_mov_details($file);
break;
default:
if (file_exists(get_file_base().'/sources_custom/getid3/getid3.php'))
{
error_reporting(0);
if (!defined('GETID3_HELPERAPPSDIR')) define('GETID3_HELPERAPPSDIR',get_file_base().'/sources_custom/getid3/helperapps');
require_code('getid3/getid3');
if (class_exists('getID3'))
{
$id3_ob=new getID3();
$_info=$id3_ob->analyze($file_path,$filename);
$info=array(
isset($_info['video']['resolution_x'])?$_info['video']['resolution_x']:NULL,
isset($_info['video']['resolution_y'])?$_info['video']['resolution_y']:NULL,
array_key_exists('playtime_seconds',$_info)?intval($_info['playtime_seconds']):NULL,
);
if (isset($_info['meta']['onMetaData']['width'])) $info[0]=intval($_info['meta']['onMetaData']['width']);
if (isset($_info['meta']['onMetaData']['height'])) $info[1]=intval($_info['meta']['onMetaData']['height']);
require_code('mime_types');
$mime_type=get_mime_type($extension);
if (substr($mime_type,0,6)=='audio/')
{
$info[0]=NULL;
$info[1]=NULL;
}
}
}
break;
}
fclose($file);
if (is_null($info)) return array(NULL,NULL,NULL);
return $info;
}
integer read_intel_endian_int(string buffer)
Read an integer from the given binary chunk. The integer is in intel endian form.
Parameters…
| Name |
buffer |
| Description |
The binary chunk |
| Type |
string |
Returns…
| Description |
The integer |
| Type |
integer |
function read_intel_endian_int($buffer)
{
if (strlen($buffer)==2)
{
return ord($buffer[0])|(ord($buffer[1])<<8);
}
if (strlen($buffer)<4) warn_exit(do_lang_tempcode('CORRUPT_FILE',do_lang('VIDEO'))); // Error
return ord($buffer[0])|(ord($buffer[1])<<8)|(ord($buffer[2])<<16)|(ord($buffer[3])<<24);
}
integer read_network_endian_int(string buffer)
Read an integer from the given binary chunk. The integer is in network endian form.
Parameters…
| Name |
buffer |
| Description |
The binary chunk |
| Type |
string |
Returns…
| Description |
The integer |
| Type |
integer |
function read_network_endian_int($buffer)
{
if (strlen($buffer)==2)
{
return ord($buffer[1])|(ord($buffer[0])<<8);
}
if (strlen($buffer)<4) warn_exit(do_lang_tempcode('CORRUPT_FILE',do_lang('VIDEO'))); // Error
return ord($buffer[3])|(ord($buffer[2])<<8)|(ord($buffer[1])<<16)|(ord($buffer[0])<<24);
}
array _get_wmv_details(resource file)
Get width,height,length of a .wmv video file.
Parameters…
| Name |
file |
| Description |
The file handle |
| Type |
resource |
Returns…
| Description |
The triplet (possibly containing NULL's for when we can't detect properties) |
| Type |
array |
function _get_wmv_details($file)
{
// Read in chunks
list($_,$width,$height,$length)=_get_wmv_details_do_chunk_list($file);
return array($width,$height,$length);
}
?array _get_wmv_details_do_chunk_list(resource file, ?integer chunk_length)
Get chunk-bytes-read,width,height,length of a chunk list of a .wmv video file.
Parameters…
| Name |
file |
| Description |
The file handle |
| Type |
resource |
| Name |
chunk_length |
| Description |
The length of the current chunk list (NULL: covers full file) |
| Default value |
|
| Type |
?integer |
Returns…
| Description |
The quartet (possibly containing NULL's for when we can't detect properties) (NULL: error) |
| Type |
?array |
function _get_wmv_details_do_chunk_list($file,$chunk_length=NULL)
{
$length=NULL;
$width=NULL;
$height=NULL;
$count=0;
while ((!feof($file)) && ((is_null($chunk_length)) || ($count<$chunk_length)) && ((is_null($length)) || (is_null($width)) || (is_null($height))))
{
// Read in chunk info
$a=read_intel_endian_int(fread($file,4));
$b=read_intel_endian_int(fread($file,4));
$c=read_intel_endian_int(fread($file,4));
$d=read_intel_endian_int(fread($file,4));
$sub_chunk_length=read_intel_endian_int(fread($file,4));
$count+=$sub_chunk_length;
if ($sub_chunk_length<=24) return NULL; // Some kind of error that would cause mayhem
fseek($file,4,SEEK_CUR); // Can't read 64 bit
// Header chunk
if (($a==intval(0x75B22630)) && ($b==intval(0x11CF668E)) && ($c==intval(0xAA00D9A6)) && ($d==intval(0x6CCE6200)))
{
fseek($file,6,SEEK_CUR);
$info=_get_wmv_details_do_chunk_list($file,$sub_chunk_length-30);
$sub_chunk_length=24;
if (!is_null($info[1])) $width=$info[1];
if (!is_null($info[2])) $height=$info[2];
if (!is_null($info[3])) $length=$info[3];
}
// Header object
if (($a==intval(0x8CABDCA1)) && ($b==intval(0x11CFA947)) && ($c==intval(0xC000E48E)) && ($d==intval(0x6553200C)))
{
fseek($file,48,SEEK_CUR);
$length=intval(round(read_intel_endian_int(fread($file,4))/10000000));
$sub_chunk_length-=52;
}
// Stream header object
if (($a==intval(0xB7DC0791)) && ($b==intval(0x11CFA9B7)) && ($c==intval(0xC000E68E)) && ($d==intval(0x6553200C)))
{
// Read in chunk info
$a=read_intel_endian_int(fread($file,4));
$b=read_intel_endian_int(fread($file,4));
$c=read_intel_endian_int(fread($file,4));
$d=read_intel_endian_int(fread($file,4));
$sub_chunk_length-=16;
if (($a==intval(0xBC19EFC0)) && ($b==intval(0x11CF5B4D)) && ($c==intval(0x8000FDA8)) && ($d==intval(0x2B445C5F))) // Video chunk
{
fseek($file,38,SEEK_CUR);
$width=read_intel_endian_int(fread($file,4));
$height=read_intel_endian_int(fread($file,4));
$sub_chunk_length-=46;
}
}
fseek($file,$sub_chunk_length-24,SEEK_CUR);
}
return array($count,$width,$height,$length);
}
array _get_avi_details(resource file)
Get width,height,length of a .avi video file.
Parameters…
| Name |
file |
| Description |
The file handle |
| Type |
resource |
Returns…
| Description |
The triplet (possibly containing NULL's for when we can't detect properties) |
| Type |
array |
function _get_avi_details($file)
{
fseek($file,32,SEEK_CUR);
$microseconds_per_frame=read_intel_endian_int(fread($file,4));
fseek($file,12,SEEK_CUR);
$num_frames=read_intel_endian_int(fread($file,4));
$length=intval(round(floatval($num_frames*$microseconds_per_frame)/1000/1000));
fseek($file,12,SEEK_CUR);
$width=read_intel_endian_int(fread($file,4));
$height=read_intel_endian_int(fread($file,4));
return array($width,$height,$length);
}
?array _get_ram_details(resource file)
Get width,height,length of a .rm/.ram video file.
Parameters…
| Name |
file |
| Description |
The file handle |
| Type |
resource |
Returns…
| Description |
The triplet (possibly containing NULL's for when we can't detect properties) (NULL: error) |
| Type |
?array |
function _get_ram_details($file) // + rm
{
$length=NULL;
$width=NULL;
$height=NULL;
// Read in chunks
while ((!feof($file)) && ((is_null($length)) || (is_null($width)) || (is_null($height))))
{
$type=fread($file,4);
$size=read_network_endian_int(fread($file,4));
if ($size<=8) return NULL;
if ($type=='PROP')
{
fseek($file,22,SEEK_CUR);
$length=intval(round(read_network_endian_int(fread($file,4))/1000));
return array($width,$height,$length);
} else fseek($file,$size-8,SEEK_CUR);
}
return array($width,$height,$length);
}
?array _get_mov_details(resource file)
Get width,height,length of a .mov/.qt video file.
Parameters…
| Name |
file |
| Description |
The file handle |
| Type |
resource |
Returns…
| Description |
The triplet (possibly containing NULL's for when we can't detect properties) (NULL: error) |
| Type |
?array |
function _get_mov_details($file)
{
// Read in atoms
$info=_get_mov_details_do_atom_list($file);
if (is_null($info)) return NULL;
list($_,$width,$height,$length)=$info;
return array($width,$height,$length);
}
array _get_mov_details_do_atom_list(resource file, ?integer atom_size)
Get chunk-bytes-read,width,height,length of a atom list of a .mov/.qt video file.
Parameters…
| Name |
file |
| Description |
The file handle |
| Type |
resource |
| Name |
atom_size |
| Description |
The length of the current atom list (NULL: covers full file) |
| Default value |
|
| Type |
?integer |
Returns…
| Description |
The quartet (possibly containing NULL's for when we can't detect properties) |
| Type |
array |
function _get_mov_details_do_atom_list($file,$atom_size=NULL)
{
$length=NULL;
$width=NULL;
$height=NULL;
$count=0;
while ((!feof($file)) && ((is_null($atom_size)) || ($count<$atom_size)) && ((is_null($length)) || (is_null($width)) || (is_null($height))))
{
$next_read=fread($file,4);
if (strlen($next_read)<4) return array($count,$width,$height,$length); // END / problem
$size=read_network_endian_int($next_read);
if ($size<8) // NB: uuid atom can be of size 8 (i.e. empty) on some rare files
{
return array($count,$width,$height,$length); // END / problem
}
$count+=4;
if ($size==0)
{
// $qt_atom=true;
fseek($file,8,SEEK_CUR);
$size=read_network_endian_int(fread($file,4));
$count+=12;
}// else $qt_atom=false;
$type=fread($file,4);
$count+=4;
if ($type=='mvhd')
{
fseek($file,12,SEEK_CUR);
$time_scale=read_network_endian_int(fread($file,4));
$duration=read_network_endian_int(fread($file,4));
$length=intval(round(floatval($duration)/floatval($time_scale)));
fseek($file,80,SEEK_CUR);
$count+=20+80;
}
elseif ($type=='tkhd')
{
fseek($file,76,SEEK_CUR);
$_width=read_network_endian_int(fread($file,2));
fseek($file,2,SEEK_CUR); // fixed point - but we don't want decimal fraction part
$_height=read_network_endian_int(fread($file,2));
fseek($file,2,SEEK_CUR); // fixed point - but we don't want decimal fraction part
$count+=76+8;
if ($_width>0) $width=$_width;
if ($_height>0) $height=$_height;
}
elseif ($type=='moov') // moov contains more atoms, and the one we need for length
{
$info=_get_mov_details_do_atom_list($file,$size-$count);
$count+=$info[0];
if (!is_null($info[1])) $width=$info[1];
if (!is_null($info[2])) $height=$info[2];
if (!is_null($info[3])) $length=$info[3];
}
elseif ($type=='trak') // trak contains more atoms, and the one we need for width and height
{
$info=_get_mov_details_do_atom_list($file,$size-$count);
$count+=$info[0];
if (!is_null($info[1])) $width=$info[1];
if (!is_null($info[2])) $height=$info[2];
if (!is_null($info[3])) $length=$info[3];
} else
{
fseek($file,$size-8,SEEK_CUR);
$count+=$size-8;
}
}
return array($count,$width,$height,$length);
}
AUTO_LINK add_image(SHORT_TEXT title, ID_TEXT cat, LONG_TEXT comments, URLPATH url, URLPATH thumb_url, BINARY validated, BINARY allow_rating, BINARY allow_comments, BINARY allow_trackbacks, LONG_TEXT notes, ?MEMBER submitter, ?TIME add_date, ?TIME edit_date, integer views, ?AUTO_LINK id)
Add an image to a specified gallery.
Parameters…
| Name |
title |
| Description |
Image title |
| Type |
SHORT_TEXT |
| Name |
cat |
| Description |
The gallery name |
| Type |
ID_TEXT |
| Name |
comments |
| Description |
The image comments |
| Type |
LONG_TEXT |
| Name |
url |
| Description |
The URL to the actual image |
| Type |
URLPATH |
| Name |
thumb_url |
| Description |
The URL to the thumbnail of the actual image |
| Type |
URLPATH |
| Name |
validated |
| Description |
Whether the image has been validated for display on the site |
| Type |
BINARY |
| Name |
allow_rating |
| Description |
Whether the image may be rated |
| Type |
BINARY |
| Name |
allow_comments |
| Description |
Whether the image may be commented upon |
| Type |
BINARY |
| Name |
allow_trackbacks |
| Description |
Whether the image may be trackbacked |
| Type |
BINARY |
| Name |
notes |
| Description |
Hidden notes associated with the image |
| Type |
LONG_TEXT |
| Name |
submitter |
| Description |
The submitter (NULL: current member) |
| Default value |
|
| Type |
?MEMBER |
| Name |
add_date |
| Description |
The time of adding (NULL: now) |
| Default value |
|
| Type |
?TIME |
| Name |
edit_date |
| Description |
The time of editing (NULL: never) |
| Default value |
|
| Type |
?TIME |
| Name |
views |
| Description |
The number of views |
| Default value |
0 |
| Type |
integer |
| Name |
id |
| Description |
Force an ID (NULL: don't force an ID) |
| Default value |
|
| Type |
?AUTO_LINK |
Returns…
| Description |
The ID of the new entry |
| Type |
AUTO_LINK |
function add_image($title,$cat,$comments,$url,$thumb_url,$validated,$allow_rating,$allow_comments,$allow_trackbacks,$notes,$submitter=NULL,$add_date=NULL,$edit_date=NULL,$views=0,$id=NULL)
{
if (is_null($submitter)) $submitter=get_member();
if (is_null($add_date)) $add_date=time();
if (!addon_installed('unvalidated')) $validated=1;
$map=array('title'=>insert_lang_comcode($title,2),'edit_date'=>$edit_date,'image_views'=>$views,'add_date'=>$add_date,'allow_rating'=>$allow_rating,'allow_comments'=>$allow_comments,'allow_trackbacks'=>$allow_trackbacks,'notes'=>$notes,'submitter'=>$submitter,'url'=>$url,'thumb_url'=>$thumb_url,'comments'=>insert_lang_comcode($comments,3),'cat'=>$cat,'validated'=>$validated);
if (!is_null($id)) $map['id']=$id;
$id=$GLOBALS['SITE_DB']->query_insert('images',$map,true);
log_it('ADD_IMAGE',strval($id),$title);
require_code('seo2');
seo_meta_set_for_implicit('image',strval($id),array($comments),$comments);
if ($validated==1)
{
require_lang('galleries');
require_code('notifications');
$subject=do_lang('IMAGE_NOTIFICATION_MAIL_SUBJECT',get_site_name(),strip_comcode($title));
$self_url=build_url(array('page'=>'galleries','type'=>'image','id'=>$id),get_module_zone('galleries'),NULL,false,false,true);
$mail=do_lang('IMAGE_NOTIFICATION_MAIL',comcode_escape(get_site_name()),comcode_escape($title),array(comcode_escape($self_url->evaluate())));
dispatch_notification('gallery_entry',$cat,$subject,$mail);
}
decache('side_root_galleries');
decache('main_gallery_embed');
decache('main_download_category');
decache('main_image_fader');
return $id;
}
void edit_image(AUTO_LINK id, SHORT_TEXT title, ID_TEXT cat, LONG_TEXT comments, URLPATH url, URLPATH thumb_url, BINARY validated, BINARY allow_rating, BINARY allow_comments, BINARY allow_trackbacks, LONG_TEXT notes, SHORT_TEXT meta_keywords, LONG_TEXT meta_description)
Edit an image in a specified gallery.
Parameters…
| Name |
id |
| Description |
The ID of the image to edit |
| Type |
AUTO_LINK |
| Name |
title |
| Description |
Image title |
| Type |
SHORT_TEXT |
| Name |
cat |
| Description |
The gallery name |
| Type |
ID_TEXT |
| Name |
comments |
| Description |
The image comments |
| Type |
LONG_TEXT |
| Name |
url |
| Description |
The URL to the actual image |
| Type |
URLPATH |
| Name |
thumb_url |
| Description |
The URL to the thumbnail of the actual image |
| Type |
URLPATH |
| Name |
validated |
| Description |
Whether the image has been validated for display on the site |
| Type |
BINARY |
| Name |
allow_rating |
| Description |
Whether the image may be rated |
| Type |
BINARY |
| Name |
allow_comments |
| Description |
Whether the image may be commented upon |
| Type |
BINARY |
| Name |
allow_trackbacks |
| Description |
Whether the image may be trackbacked |
| Type |
BINARY |
| Name |
notes |
| Description |
Hidden notes associated with the image |
| Type |
LONG_TEXT |
| Name |
meta_keywords |
| Description |
Meta keywords |
| Type |
SHORT_TEXT |
| Name |
meta_description |
| Description |
Meta description |
| Type |
LONG_TEXT |
(No return value)
function edit_image($id,$title,$cat,$comments,$url,$thumb_url,$validated,$allow_rating,$allow_comments,$allow_trackbacks,$notes,$meta_keywords,$meta_description)
{
require_code('urls2');
suggest_new_idmoniker_for('galleries','image',strval($id),$comments);
$_comments=$GLOBALS['SITE_DB']->query_value('images','comments',array('id'=>$id));
$_title=$GLOBALS['SITE_DB']->query_value('images','title',array('id'=>$id));
decache('main_gallery_embed');
require_code('files2');
delete_upload('uploads/galleries','images','url','id',$id,$url);
delete_upload('uploads/galleries_thumbs','images','thumb_url','id',$id,$thumb_url);
if (!addon_installed('unvalidated')) $validated=1;
require_code('submit');
$just_validated=(!content_validated('image',strval($id))) && ($validated==1);
if ($just_validated)
{
send_content_validated_notification('image',strval($id));
}
$GLOBALS['SITE_DB']->query_update('images',array('title'=>lang_remap_comcode($_title,$title),'edit_date'=>time(),'allow_rating'=>$allow_rating,'allow_comments'=>$allow_comments,'allow_trackbacks'=>$allow_trackbacks,'notes'=>$notes,'validated'=>$validated,'cat'=>$cat,'comments'=>lang_remap_comcode($_comments,$comments),'url'=>$url,'thumb_url'=>$thumb_url),array('id'=>$id),'',1);
$self_url=build_url(array('page'=>'galleries','type'=>'image','id'=>$id),get_module_zone('galleries'),NULL,false,false,true);
if ($just_validated)
{
require_lang('galleries');
require_code('notifications');
$subject=do_lang('IMAGE_NOTIFICATION_MAIL_SUBJECT',get_site_name(),strip_comcode($title));
$mail=do_lang('IMAGE_NOTIFICATION_MAIL',comcode_escape(get_site_name()),comcode_escape($title),array(comcode_escape($self_url->evaluate())));
dispatch_notification('gallery_entry',$cat,$subject,$mail);
}
log_it('EDIT_IMAGE',strval($id),$title);
require_code('seo2');
seo_meta_set_for_explicit('image',strval($id),$meta_keywords,$meta_description);
decache('main_download_category');
decache('main_image_fader');
require_lang('galleries');
require_code('feedback');
update_spacer_post($allow_comments!=0,'images',strval($id),$self_url,do_lang('VIEW_IMAGE','','','',get_site_default_lang()),get_value('comment_forum__images'));
}
void delete_image(AUTO_LINK id, boolean delete_full)
Delete a specified image from the database, and delete the file if possible.
Parameters…
| Name |
id |
| Description |
The ID of the image |
| Type |
AUTO_LINK |
| Name |
delete_full |
| Description |
Whether to delete the actual file also |
| Type |
boolean |
(No return value)
function delete_image($id,$delete_full)
{
$rows=$GLOBALS['SITE_DB']->query_select('images',array('title','comments','cat'),array('id'=>$id));
$title=$rows[0]['title'];
$comments=$rows[0]['comments'];
$cat=$rows[0]['cat'];
log_it('DELETE_IMAGE',strval($id),get_translated_text($title));
delete_lang($comments);
delete_lang($title);
// Delete file
if ($delete_full)
{
require_code('files2');
delete_upload('uploads/galleries','images','url','id',$id);
delete_upload('uploads/galleries_thumbs','images','thumb_url','id',$id);
}
// Delete from database
$GLOBALS['SITE_DB']->query_delete('images',array('id'=>$id),'',1);
$GLOBALS['SITE_DB']->query_delete('rating',array('rating_for_type'=>'images','rating_for_id'=>$id));
$GLOBALS['SITE_DB']->query_delete('trackbacks',array('trackback_for_type'=>'images','trackback_for_id'=>$id));
require_code('seo2');
seo_meta_erase_storage('image',strval($id));
decache('side_root_galleries');
decache('main_gallery_embed');
decache('main_image_fader');
}
URLPATH create_video_thumb(URLPATH src_url, ?PATH expected_output_path)
Create a video thumbnail.
Parameters…
| Name |
src_url |
| Description |
Video to get thumbail from (must be local) |
| Type |
URLPATH |
| Name |
expected_output_path |
| Description |
Where to save to (NULL: decide for ourselves) |
| Default value |
|
| Type |
?PATH |
Returns…
| Description |
Thumbnail, only valid if expected_output_path was passed as NULL (blank: could not generate) |
| Type |
URLPATH |
function create_video_thumb($src_url,$expected_output_path=NULL)
{
$ve_hooks=find_all_hooks('systems','video_embed');
foreach (array_keys($ve_hooks) as $ve_hook)
{
require_code('hooks/systems/video_embed/'.$ve_hook);
$ve_ob=object_factory('Hook_video_embed_'.$ve_hook);
$thumbnail=$ve_ob->get_video_thumbnail($src_url);
if (!is_null($thumbnail)) return $thumbnail;
}
if (substr($src_url,0,strlen(get_custom_base_url().'/'))==get_custom_base_url().'/') $src_url=substr($src_url,strlen(get_custom_base_url().'/'));
if (!url_is_local($src_url)) return '';
$src_file=get_custom_file_base().'/'.rawurldecode($src_url);
$src_file=preg_replace('#(\\\|/)#',DIRECTORY_SEPARATOR,$src_file);
if (class_exists('ffmpeg_movie'))
{
$filename='thumb_'.md5(uniqid('')).'1.jpg';
if (is_null($expected_output_path))
$expected_output_path=get_custom_file_base().'/uploads/galleries/'.$filename;
if (file_exists($expected_output_path))
return 'uploads/galleries/'.rawurlencode(basename($expected_output_path));
$movie=@(new ffmpeg_movie($src_file,false));
if ($movie!==false)
{
if ($movie->getFrameCount()==0) return '';
$frame=$movie->getFrame(min($movie->getFrameCount(),25));
$gd_img=$frame->toGDImage();
@imagejpeg($gd_img,$expected_output_path);
if (file_exists($expected_output_path))
{
require_code('images');
if ((get_option('is_on_gd')=='1') && (function_exists('imagecreatefromstring')))
convert_image($expected_output_path,$expected_output_path,-1,-1,intval(get_option('thumb_width')),true,NULL,true);
return 'uploads/galleries/'.rawurlencode(basename($expected_output_path));
}
}
}
$ffmpeg_path=get_option('ffmpeg_path');
if ($ffmpeg_path!='')
{
$filename='thumb_'.md5(uniqid(strval(post_param_integer('thumbnail_auto_position',1)))).'%d.jpg';
$dest_file=get_custom_file_base().'/uploads/galleries/'.$filename;
if (is_null($expected_output_path))
$expected_output_path=str_replace('%d','1',$dest_file);
if ((file_exists($dest_file)) && (is_null(post_param_integer('thumbnail_auto_position',NULL))))
return 'uploads/galleries/'.rawurlencode(basename($expected_output_path));
@unlink($dest_file); // So "if (@filesize($expected_output_path)) break;" will definitely fail if error
$dest_file=preg_replace('#(\\\|/)#',DIRECTORY_SEPARATOR,$dest_file);
$at=display_seconds_period(post_param_integer('thumbnail_auto_position',1));
if (strlen($at)==5) $at='00:'.$at;
$shell_command='"'.$ffmpeg_path.'ffmpeg" -i '.@escapeshellarg($src_file).' -an -ss '.$at.' -r 1 -vframes 1 -y '.@escapeshellarg($dest_file);
$shell_commands=array($shell_command,$shell_command.' -map 0.0:0.0',$shell_command.' -map 0.1:0.0');
foreach ($shell_commands as $shell_command)
{
shell_exec($shell_command);
if (@filesize($expected_output_path)) break;
}
if (file_exists(str_replace('%d','1',$dest_file)))
{
require_code('images');
if ((get_option('is_on_gd')=='1') && (function_exists('imagecreatefromstring')))
{
convert_image(str_replace('%d','1',$dest_file),$expected_output_path,-1,-1,intval(get_option('thumb_width')),true,NULL,true);
} else
{
copy(str_replace('%d','1',$dest_file),$expected_output_path);
fix_permissions($expected_output_path);
sync_file($expected_output_path);
}
return 'uploads/galleries/'.rawurlencode(basename($expected_output_path));
}
}
// get_mime_type
require_code('mime_types');
$file_ext=get_file_extension($src_url);
$input_mime_type=get_mime_type($file_ext);
if (preg_match('#audio\/#i',$input_mime_type)!=0)
{
return find_theme_image('audio_thumb',true);
}
return '';
}
AUTO_LINK add_video(SHORT_TEXT title, ID_TEXT cat, LONG_TEXT comments, URLPATH url, URLPATH thumb_url, BINARY validated, BINARY allow_rating, BINARY allow_comments, BINARY allow_trackbacks, LONG_TEXT notes, integer video_length, integer video_width, integer video_height, ?MEMBER submitter, ?TIME add_date, ?TIME edit_date, integer views, ?AUTO_LINK id)
Add a video to a specified gallery.
Parameters…
| Name |
title |
| Description |
Video title |
| Type |
SHORT_TEXT |
| Name |
cat |
| Description |
The gallery name |
| Type |
ID_TEXT |
| Name |
comments |
| Description |
The video comments |
| Type |
LONG_TEXT |
| Name |
url |
| Description |
The URL to the actual video |
| Type |
URLPATH |
| Name |
thumb_url |
| Description |
The URL to the thumbnail of the actual video |
| Type |
URLPATH |
| Name |
validated |
| Description |
Whether the video has been validated for display on the site |
| Type |
BINARY |
| Name |
allow_rating |
| Description |
Whether the video may be rated |
| Type |
BINARY |
| Name |
allow_comments |
| Description |
Whether the video may be commented upon |
| Type |
BINARY |
| Name |
allow_trackbacks |
| Description |
Whether the video may be trackbacked |
| Type |
BINARY |
| Name |
notes |
| Description |
Hidden notes associated with the video |
| Type |
LONG_TEXT |
| Name |
video_length |
| Description |
The length of the video |
| Type |
integer |
| Name |
video_width |
| Description |
The width of the video |
| Type |
integer |
| Name |
video_height |
| Description |
The height of the video |
| Type |
integer |
| Name |
submitter |
| Description |
The submitter (NULL: current member) |
| Default value |
|
| Type |
?MEMBER |
| Name |
add_date |
| Description |
The time of adding (NULL: now) |
| Default value |
|
| Type |
?TIME |
| Name |
edit_date |
| Description |
The time of editing (NULL: never) |
| Default value |
|
| Type |
?TIME |
| Name |
views |
| Description |
The number of views |
| Default value |
0 |
| Type |
integer |
| Name |
id |
| Description |
Force an ID (NULL: don't force an ID) |
| Default value |
|
| Type |
?AUTO_LINK |
Returns…
| Description |
The ID of the new entry |
| Type |
AUTO_LINK |
function add_video($title,$cat,$comments,$url,$thumb_url,$validated,$allow_rating,$allow_comments,$allow_trackbacks,$notes,$video_length,$video_width,$video_height,$submitter=NULL,$add_date=NULL,$edit_date=NULL,$views=0,$id=NULL)
{
if (is_null($submitter)) $submitter=get_member();
if (is_null($add_date)) $add_date=time();
require_code('transcoding');
$url=transcode_video($url,'videos','url',NULL,'video_width','video_height');
if (!addon_installed('unvalidated')) $validated=1;
$map=array('title'=>insert_lang_comcode($title,2),'edit_date'=>$edit_date,'video_views'=>$views,'add_date'=>time(),'allow_rating'=>$allow_rating,'allow_comments'=>$allow_comments,'allow_trackbacks'=>$allow_trackbacks,'notes'=>$notes,'submitter'=>get_member(),'url'=>$url,'thumb_url'=>$thumb_url,'comments'=>insert_lang_comcode($comments,3),'cat'=>$cat,'validated'=>$validated,'video_length'=>$video_length,'video_width'=>$video_width,'video_height'=>$video_height);
if (!is_null($id)) $map['id']=$id;
$id=$GLOBALS['SITE_DB']->query_insert('videos',$map,true);
log_it('ADD_VIDEO',strval($id),$title);
if ($validated==1)
{
require_lang('galleries');
require_code('notifications');
$subject=do_lang('VIDEO_NOTIFICATION_MAIL_SUBJECT',get_site_name(),strip_comcode($title));
$self_url=build_url(array('page'=>'galleries','type'=>'video','id'=>$id),get_module_zone('galleries'),NULL,false,false,true);
$mail=do_lang('VIDEO_NOTIFICATION_MAIL',comcode_escape(get_site_name()),comcode_escape($title),array(comcode_escape($self_url->evaluate())));
dispatch_notification('gallery_entry',$cat,$subject,$mail);
}
require_code('seo2');
seo_meta_set_for_implicit('video',strval($id),array($comments),$comments);
decache('side_root_galleries');
decache('main_gallery_embed');
return $id;
}
void edit_video(AUTO_LINK id, SHORT_TEXT title, ID_TEXT cat, LONG_TEXT comments, URLPATH url, URLPATH thumb_url, BINARY validated, BINARY allow_rating, BINARY allow_comments, BINARY allow_trackbacks, LONG_TEXT notes, integer video_length, integer video_width, integer video_height, SHORT_TEXT meta_keywords, LONG_TEXT meta_description)
Edit a video in a specified gallery.
Parameters…
| Name |
id |
| Description |
The ID of the entry to edit |
| Type |
AUTO_LINK |
| Name |
title |
| Description |
Video title |
| Type |
SHORT_TEXT |
| Name |
cat |
| Description |
The gallery name |
| Type |
ID_TEXT |
| Name |
comments |
| Description |
The video comments |
| Type |
LONG_TEXT |
| Name |
url |
| Description |
The URL to the actual video |
| Type |
URLPATH |
| Name |
thumb_url |
| Description |
The URL to the thumbnail of the actual video |
| Type |
URLPATH |
| Name |
validated |
| Description |
Whether the video has been validated for display on the site |
| Type |
BINARY |
| Name |
allow_rating |
| Description |
Whether the video may be rated |
| Type |
BINARY |
| Name |
allow_comments |
| Description |
Whether the video may be commented upon |
| Type |
BINARY |
| Name |
allow_trackbacks |
| Description |
Whether the video may be trackbacked |
| Type |
BINARY |
| Name |
notes |
| Description |
Hidden notes associated with the video |
| Type |
LONG_TEXT |
| Name |
video_length |
| Description |
The length of the video |
| Type |
integer |
| Name |
video_width |
| Description |
The width of the video |
| Type |
integer |
| Name |
video_height |
| Description |
The height of the video |
| Type |
integer |
| Name |
meta_keywords |
| Description |
Meta keywords |
| Type |
SHORT_TEXT |
| Name |
meta_description |
| Description |
Meta description |
| Type |
LONG_TEXT |
(No return value)
function edit_video($id,$title,$cat,$comments,$url,$thumb_url,$validated,$allow_rating,$allow_comments,$allow_trackbacks,$notes,$video_length,$video_width,$video_height,$meta_keywords,$meta_description)
{
require_code('urls2');
suggest_new_idmoniker_for('galleries','video',strval($id),$comments);
$_title=$GLOBALS['SITE_DB']->query_value('videos','title',array('id'=>$id));
$_comments=$GLOBALS['SITE_DB']->query_value('videos','comments',array('id'=>$id));
require_code('files2');
delete_upload('uploads/galleries','videos','url','id',$id,$url);
delete_upload('uploads/galleries_thumbs','videos','thumb_url','id',$id,$thumb_url);
require_code('transcoding');
$url=transcode_video($url,'videos','url',NULL,'video_width','video_height');
if (!addon_installed('unvalidated')) $validated=1;
require_code('submit');
$just_validated=(!content_validated('video',strval($id))) && ($validated==1);
if ($just_validated)
{
send_content_validated_notification('video',strval($id));
}
$GLOBALS['SITE_DB']->query_update('videos',array('title'=>lang_remap_comcode($_title,$title),'edit_date'=>time(),'allow_rating'=>$allow_rating,'allow_comments'=>$allow_comments,'allow_trackbacks'=>$allow_trackbacks,'notes'=>$notes,'validated'=>$validated,'cat'=>$cat,'comments'=>lang_remap_comcode($_comments,$comments),'url'=>$url,'thumb_url'=>$thumb_url,'video_length'=>$video_length,'video_width'=>$video_width,'video_height'=>$video_height),array('id'=>$id),'',1);
$self_url=build_url(array('page'=>'galleries','type'=>'video','id'=>$id),get_module_zone('galleries'),NULL,false,false,true);
if ($just_validated)
{
require_lang('galleries');
require_code('notifications');
$subject=do_lang('VIDEO_NOTIFICATION_MAIL_SUBJECT',get_site_name(),strip_comcode($title));
$mail=do_lang('VIDEO_NOTIFICATION_MAIL',comcode_escape(get_site_name()),comcode_escape($title),array(comcode_escape($self_url->evaluate())));
dispatch_notification('gallery_entry',$cat,$subject,$mail);
}
log_it('EDIT_VIDEO',strval($id),$title);
require_code('seo2');
seo_meta_set_for_explicit('video',strval($id),$meta_keywords,$meta_description);
decache('main_gallery_embed');
require_lang('galleries');
require_code('feedback');
update_spacer_post($allow_comments!=0,'videos',strval($id),$self_url,do_lang('VIEW_VIDEO','','','',get_site_default_lang()),get_value('comment_forum__videos'));
}
void delete_video(AUTO_LINK id, boolean delete_full)
Delete a video in a specified gallery.
Parameters…
| Name |
id |
| Description |
The ID of the entry to delete |
| Type |
AUTO_LINK |
| Name |
delete_full |
| Description |
Whether to delete the actual video file from disk as well as the entry |
| Type |
boolean |
(No return value)
function delete_video($id,$delete_full)
{
$rows=$GLOBALS['SITE_DB']->query_select('videos',array('title','comments','cat'),array('id'=>$id));
$title=$rows[0]['title'];
$comments=$rows[0]['comments'];
$cat=$rows[0]['cat'];
log_it('DELETE_VIDEO',strval($id),get_translated_text($title));
delete_lang($title);
delete_lang($comments);
if ($delete_full)
{
require_code('files2');
delete_upload('uploads/galleries','videos','url','id',$id);
delete_upload('uploads/galleries_thumbs','videos','thumb_url','id',$id);
}
// Delete from database
$GLOBALS['SITE_DB']->query_delete('videos',array('id'=>$id),'',1);
$GLOBALS['SITE_DB']->query_delete('rating',array('rating_for_type'=>'videos','rating_for_id'=>$id));
$GLOBALS['SITE_DB']->query_delete('trackbacks',array('trackback_for_type'=>'videos','trackback_for_id'=>$id));
require_code('seo2');
seo_meta_erase_storage('video',strval($id));
decache('side_root_galleries');
decache('main_gallery_embed');
}
void watermark_gallery_image(ID_TEXT gallery, PATH file_path, string filename)
Watermarks an image with the appropriate gallery watermarks.
Parameters…
| Name |
gallery |
| Description |
The name of the gallery for the image |
| Type |
ID_TEXT |
| Name |
file_path |
| Description |
The path to the image file |
| Type |
PATH |
| Name |
filename |
| Description |
The original file name of the image |
| Type |
string |
(No return value)
function watermark_gallery_image($gallery,$file_path,$filename)
{
// We can't watermark an image we can't save
require_code('images');
if (!function_exists('imagecreatefromstring')) return;
if (!is_saveable_image($filename)) return;
// We need to find the most applicable gallery watermarks
$watermark_top_left='';
$watermark_top_right='';
$watermark_bottom_left='';
$watermark_bottom_right='';
do
{
if ($gallery=='') return; // We couldn't find any matermarks
$_gallery=$GLOBALS['SITE_DB']->query_select('galleries',array('parent_id','watermark_top_left','watermark_top_right','watermark_bottom_left','watermark_bottom_right'),array('name'=>$gallery),'',1);
$watermark_top_left=$_gallery[0]['watermark_top_left'];
$watermark_top_right=$_gallery[0]['watermark_top_right'];
$watermark_bottom_left=$_gallery[0]['watermark_bottom_left'];
$watermark_bottom_right=$_gallery[0]['watermark_bottom_right'];
$gallery=$_gallery[0]['parent_id'];
}
while (($watermark_top_left=='') && ($watermark_top_right=='') && ($watermark_bottom_left=='') && ($watermark_bottom_right==''));
// Now we must apply the watermarks
$ext=get_file_extension($filename);
$source=@imagecreatefromstring(file_get_contents($file_path));
if ($source===false) return; // We couldn't load it for some reason
// Apply the watermarks
_watermark_corner($source,$watermark_top_left,0,0);
_watermark_corner($source,$watermark_top_right,1,0);
_watermark_corner($source,$watermark_bottom_left,0,1);
_watermark_corner($source,$watermark_bottom_right,1,1);
// Save
if ($ext=='png') imagepng($source,$file_path);
elseif (($ext=='jpg') || ($ext=='jpeg')) imagejpeg($source,$file_path);
elseif ((function_exists('imagegif')) && ($ext=='gif')) imagegif($source,$file_path);
// Clean up
imagedestroy($source);
}
void _watermark_corner(resource source, URLPATH watermark_url, BINARY x, BINARY y)
Watermark the corner of an image.
Parameters…
| Name |
source |
| Description |
The image resource being watermarked |
| Type |
resource |
| Name |
watermark_url |
| Description |
The (local) URL to the watermark file |
| Type |
URLPATH |
| Name |
x |
| Description |
Whether a right hand side corner is being watermarked |
| Type |
BINARY |
| Name |
y |
| Description |
Whether a bottom edge corner is being watermarked |
| Type |
BINARY |
(No return value)
function _watermark_corner(/*&*/$source,$watermark_url,$x,$y)
{
if ($watermark_url!='')
{
$watermark=@imagecreatefromstring(file_get_contents(rawurldecode($watermark_url)));
if ($watermark!==false)
{
imagecolortransparent($watermark,imagecolorallocate($watermark,255,0,255));
if ($x==1) $x=imagesx($source)-imagesx($watermark);
if ($y==1) $y=imagesy($source)-imagesy($watermark);
imagecopy($source,$watermark,$x,$y,0,0,imagesx($watermark),imagesy($watermark));
imagedestroy($watermark);
}
}
}
void constrain_gallery_image_to_max_size(PATH file_path, string filename, integer box_width)
Make sure the detailed image file is not bigger than the defined box width.
Parameters…
| Name |
file_path |
| Description |
The path to the image file |
| Type |
PATH |
| Name |
filename |
| Description |
The original filename of the image |
| Type |
string |
| Name |
box_width |
| Description |
The box width |
| Type |
integer |
(No return value)
function constrain_gallery_image_to_max_size($file_path,$filename,$box_width)
{
// We can't watermark an image we can't save
require_code('images');
if (!is_saveable_image($filename)) return;
if ((get_option('is_on_gd')=='1') && (function_exists('imagecreatefromstring')))
convert_image($file_path,$file_path,-1,-1,$box_width,false,get_file_extension($filename),true,true);
}
void add_gallery(ID_TEXT name, SHORT_TEXT fullname, LONG_TEXT description, SHORT_TEXT teaser, LONG_TEXT notes, ID_TEXT parent_id, BINARY accept_images, BINARY accept_videos, BINARY is_member_synched, BINARY flow_mode_interface, URLPATH rep_image, URLPATH watermark_top_left, URLPATH watermark_top_right, URLPATH watermark_bottom_left, URLPATH watermark_bottom_right, BINARY allow_rating, BINARY allow_comments, boolean skip_exists_check, ?TIME add_date, ?MEMBER g_owner)
Add a gallery with the specified parameters.
Parameters…
| Name |
name |
| Description |
The gallery codename |
| Type |
ID_TEXT |
| Name |
fullname |
| Description |
The full human-readeable name of the gallery |
| Type |
SHORT_TEXT |
| Name |
description |
| Description |
The description of the gallery |
| Type |
LONG_TEXT |
| Name |
teaser |
| Description |
Teaser text for the gallery |
| Type |
SHORT_TEXT |
| Name |
notes |
| Description |
Hidden notes associated with the gallery |
| Type |
LONG_TEXT |
| Name |
parent_id |
| Description |
The parent gallery (blank: no parent) |
| Type |
ID_TEXT |
| Name |
accept_images |
| Description |
Whether images may be put in this gallery |
| Default value |
1 |
| Type |
BINARY |
| Name |
accept_videos |
| Description |
Whether videos may be put in this gallery |
| Default value |
1 |
| Type |
BINARY |
| Name |
is_member_synched |
| Description |
Whether the gallery serves as a container for automatically created member galleries |
| Default value |
0 |
| Type |
BINARY |
| Name |
flow_mode_interface |
| Description |
Whether the gallery uses the flow mode interface |
| Default value |
0 |
| Type |
BINARY |
| Name |
rep_image |
| Description |
The representative image of the gallery (blank: none) |
| Default value |
|
| Type |
URLPATH |
| Name |
watermark_top_left |
| Description |
Watermark (blank: none) |
| Default value |
|
| Type |
URLPATH |
| Name |
watermark_top_right |
| Description |
Watermark (blank: none) |
| Default value |
|
| Type |
URLPATH |
| Name |
watermark_bottom_left |
| Description |
Watermark (blank: none) |
| Default value |
|
| Type |
URLPATH |
| Name |
watermark_bottom_right |
| Description |
Watermark (blank: none) |
| Default value |
|
| Type |
URLPATH |
| Name |
allow_rating |
| Description |
Whether rating are allowed |
| Default value |
1 |
| Type |
BINARY |
| Name |
allow_comments |
| Description |
Whether comments are allowed |
| Default value |
1 |
| Type |
BINARY |
| Name |
skip_exists_check |
| Description |
Whether to skip the check for whether the gallery exists (useful for importers) |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
add_date |
| Description |
The add time (NULL: now) |
| Default value |
|
| Type |
?TIME |
| Name |
g_owner |
| Description |
The gallery owner (NULL: nobody) |
| Default value |
|
| Type |
?MEMBER |
(No return value)
function add_gallery($name,$fullname,$description,$teaser,$notes,$parent_id,$accept_images=1,$accept_videos=1,$is_member_synched=0,$flow_mode_interface=0,$rep_image='',$watermark_top_left='',$watermark_top_right='',$watermark_bottom_left='',$watermark_bottom_right='',$allow_rating=1,$allow_comments=1,$skip_exists_check=false,$add_date=NULL,$g_owner=NULL)
{
if (is_null($add_date)) $add_date=time();
require_code('type_validation');
if (!is_alphanumeric($name)) warn_exit(do_lang_tempcode('BAD_CODENAME'));
if (!$skip_exists_check)
{
$test=$GLOBALS['SITE_DB']->query_value_null_ok('galleries','name',array('name'=>$name));
if (!is_null($test)) warn_exit(do_lang_tempcode('ALREADY_EXISTS',escape_html($name)));
}
$GLOBALS['SITE_DB']->query_insert('galleries',
array('name'=>$name,'add_date'=>$add_date,'description'=>insert_lang_comcode($description,2),'teaser'=>insert_lang_comcode($teaser,2),'notes'=>$notes,
'fullname'=>insert_lang($fullname,1),
'watermark_top_left'=>$watermark_top_left,'watermark_top_right'=>$watermark_top_right,
'watermark_bottom_left'=>$watermark_bottom_left,'watermark_bottom_right'=>$watermark_bottom_right,
'parent_id'=>$parent_id,'accept_images'=>$accept_images,'rep_image'=>$rep_image,
'accept_videos'=>$accept_videos,'is_member_synched'=>$is_member_synched,'flow_mode_interface'=>$flow_mode_interface,
'allow_rating'=>$allow_rating,'allow_comments'=>$allow_comments,'g_owner'=>$g_owner,
'gallery_views'=>0,
));
log_it('ADD_GALLERY',$name,$fullname);
require_code('seo2');
seo_meta_set_for_implicit('gallery',$name,array($fullname,$description),$description);
if (function_exists('decache'))
{
decache('main_top_galleries');
decache('main_recent_galleries');
decache('main_root_galleries');
decache('side_root_galleries');
}
}
void edit_gallery(ID_TEXT old_name, ID_TEXT name, SHORT_TEXT fullname, LONG_TEXT description, SHORT_TEXT teaser, LONG_TEXT notes, ?ID_TEXT parent_id, BINARY accept_images, BINARY accept_videos, BINARY is_member_synched, BINARY flow_mode_interface, URLPATH rep_image, URLPATH watermark_top_left, URLPATH watermark_top_right, URLPATH watermark_bottom_left, URLPATH watermark_bottom_right, ?SHORT_TEXT meta_keywords, ?LONG_TEXT meta_description, BINARY allow_rating, BINARY allow_comments, ?MEMBER g_owner)
Edit a gallery.
Parameters…
| Name |
old_name |
| Description |
The old gallery codename (in case we are renaming) |
| Type |
ID_TEXT |
| Name |
name |
| Description |
The gallery codename (maybe the same as the old one) |
| Type |
ID_TEXT |
| Name |
fullname |
| Description |
The full human-readeable name of the gallery |
| Type |
SHORT_TEXT |
| Name |
description |
| Description |
The description of the gallery |
| Type |
LONG_TEXT |
| Name |
teaser |
| Description |
Teaser text for the gallery |
| Type |
SHORT_TEXT |
| Name |
notes |
| Description |
Hidden notes associated with the gallery |
| Type |
LONG_TEXT |
| Name |
parent_id |
| Description |
The parent gallery (NULL: no parent) |
| Default value |
|
| Type |
?ID_TEXT |
| Name |
accept_images |
| Description |
Whether images may be put in this gallery |
| Default value |
1 |
| Type |
BINARY |
| Name |
accept_videos |
| Description |
Whether videos may be put in this gallery |
| Default value |
1 |
| Type |
BINARY |
| Name |
is_member_synched |
| Description |
Whether the gallery serves as a container for automatically created member galleries |
| Default value |
0 |
| Type |
BINARY |
| Name |
flow_mode_interface |
| Description |
Whether the gallery uses the flow mode interface |
| Default value |
0 |
| Type |
BINARY |
| Name |
rep_image |
| Description |
The representative image of the gallery (blank: none) |
| Default value |
|
| Type |
URLPATH |
| Name |
watermark_top_left |
| Description |
Watermark (blank: none) |
| Default value |
|
| Type |
URLPATH |
| Name |
watermark_top_right |
| Description |
Watermark (blank: none) |
| Default value |
|
| Type |
URLPATH |
| Name |
watermark_bottom_left |
| Description |
Watermark (blank: none) |
| Default value |
|
| Type |
URLPATH |
| Name |
watermark_bottom_right |
| Description |
Watermark (blank: none) |
| Default value |
|
| Type |
URLPATH |
| Name |
meta_keywords |
| Description |
Meta keywords for this resource (NULL: do not edit) |
| Default value |
|
| Type |
?SHORT_TEXT |
| Name |
meta_description |
| Description |
Meta description for this resource (NULL: do not edit) |
| Default value |
|
| Type |
?LONG_TEXT |
| Name |
allow_rating |
| Description |
Whether rating are allowed |
| Default value |
1 |
| Type |
BINARY |
| Name |
allow_comments |
| Description |
Whether comments are allowed |
| Default value |
1 |
| Type |
BINARY |
| Name |
g_owner |
| Description |
The gallery owner (NULL: nobody) |
| Default value |
|
| Type |
?MEMBER |
(No return value)
function edit_gallery($old_name,$name,$fullname,$description,$teaser,$notes,$parent_id=NULL,$accept_images=1,$accept_videos=1,$is_member_synched=0,$flow_mode_interface=0,$rep_image='',$watermark_top_left='',$watermark_top_right='',$watermark_bottom_left='',$watermark_bottom_right='',$meta_keywords=NULL,$meta_description=NULL,$allow_rating=1,$allow_comments=1,$g_owner=NULL)
{
require_code('urls2');
suggest_new_idmoniker_for('galleries','misc',$name,$fullname);
$under_category_id=$parent_id;
while (($under_category_id!='') && ($under_category_id!=STRING_MAGIC_NULL))
{
if ($name==$under_category_id) warn_exit(do_lang_tempcode('OWN_PARENT_ERROR'));
$under_category_id=$GLOBALS['SITE_DB']->query_value('galleries','parent_id',array('name'=>$under_category_id));
}
if (is_null($parent_id)) $parent_id='';
require_code('seo2');
if ($old_name!=$name)
{
require_code('type_validation');
if (!is_alphanumeric($name)) warn_exit(do_lang_tempcode('BAD_CODENAME'));
$test=$GLOBALS['SITE_DB']->query_value_null_ok('galleries','name',array('name'=>$name));
if (!is_null($test)) warn_exit(do_lang_tempcode('ALREADY_EXISTS',escape_html($name)));
seo_meta_erase_storage('gallery',$old_name);
$GLOBALS['SITE_DB']->query_update('images',array('cat'=>$name),array('cat'=>$old_name));
$GLOBALS['SITE_DB']->query_update('videos',array('cat'=>$name),array('cat'=>$old_name));
$GLOBALS['SITE_DB']->query_update('galleries',array('parent_id'=>$name),array('parent_id'=>$old_name));
$types=$GLOBALS['SITE_DB']->query_select('award_types',array('id'),array('a_content_type'=>'gallery'));
foreach ($types as $type)
{
$GLOBALS['SITE_DB']->query_update('award_archive',array('content_id'=>$name),array('content_id'=>$old_name,'a_type_id'=>$type['id']));
}
}
if (!is_null($meta_keywords)) seo_meta_set_for_explicit('gallery',$name,$meta_keywords,$meta_description);
$myrows=$GLOBALS['SITE_DB']->query_select('galleries',array('fullname','description','teaser'),array('name'=>$old_name),'',1);
if (!array_key_exists(0,$myrows)) warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
$myrow=$myrows[0];
$map=array('name'=>$name,'notes'=>$notes,'fullname'=>lang_remap($myrow['fullname'],$fullname),
'description'=>lang_remap_comcode($myrow['description'],$description),'teaser'=>lang_remap_comcode($myrow['teaser'],$teaser),'parent_id'=>$parent_id,'accept_images'=>$accept_images,
'accept_videos'=>$accept_videos,'is_member_synched'=>$is_member_synched,'flow_mode_interface'=>$flow_mode_interface,
'allow_rating'=>$allow_rating,'allow_comments'=>$allow_comments,'g_owner'=>$g_owner);
require_code('files2');
if (!is_null($rep_image))
{
$map['rep_image']=$rep_image;
delete_upload('uploads/grepimages','galleries','rep_image','name',$old_name,$rep_image);
}
if (!is_null($watermark_top_left))
{
$map['watermark_top_left']=$watermark_top_left;
delete_upload('uploads/watermarks','galleries','watermark_top_left','name',$old_name,$watermark_top_left);
}
if (!is_null($watermark_top_right))
{
$map['watermark_top_right']=$watermark_top_right;
delete_upload('uploads/watermarks','galleries','watermark_top_right','name',$old_name,$watermark_top_right);
}
if (!is_null($watermark_bottom_left))
{
$map['watermark_bottom_left']=$watermark_bottom_left;
delete_upload('uploads/watermarks','galleries','watermark_bottom_left','name',$old_name,$watermark_bottom_left);
}
if (!is_null($watermark_bottom_right))
{
$map['watermark_bottom_right']=$watermark_bottom_right;
delete_upload('uploads/watermarks','galleries','watermark_bottom_right','name',$old_name,$watermark_bottom_right);
}
$GLOBALS['SITE_DB']->query_update('galleries',$map,array('name'=>$old_name),'',1);
log_it('EDIT_GALLERY',$name,$fullname);
$GLOBALS['SITE_DB']->query_update('group_category_access',array('category_name'=>$name),array('module_the_name'=>'galleries','category_name'=>$old_name));
decache('main_top_galleries');
decache('main_recent_galleries');
decache('main_root_galleries');
decache('side_root_galleries');
require_code('feedback');
update_spacer_post($allow_comments!=0,'galleries',$name,build_url(array('page'=>'galleries','type'=>'misc','id'=>$name),get_module_zone('galleries'),NULL,false,false,true),$fullname,get_value('comment_forum__galleries'));
}
void delete_gallery(ID_TEXT name)
Delete a specified gallery.
Parameters…
| Name |
name |
| Description |
The gallery codename |
| Type |
ID_TEXT |
(No return value)
function delete_gallery($name)
{
if ($name=='') warn_exit(do_lang_tempcode('NO_DELETE_ROOT'));
$rows=$GLOBALS['SITE_DB']->query_select('galleries',array('*'),array('name'=>$name),'',1);
if (!array_key_exists(0,$rows)) warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
require_code('files2');
delete_upload('uploads/grepimages','galleries','rep_image','name',$name);
delete_upload('uploads/watermarks','galleries','watermark_top_left','name',$name);
delete_upload('uploads/watermarks','galleries','watermark_top_right','name',$name);
delete_upload('uploads/watermarks','galleries','watermark_bottom_left','name',$name);
delete_upload('uploads/watermarks','galleries','watermark_bottom_right','name',$name);
log_it('DELETE_GALLERY',$name,get_translated_text($rows[0]['fullname']));
delete_lang($rows[0]['fullname']);
delete_lang($rows[0]['description']);
delete_lang($rows[0]['teaser']);
// Images and videos are deleted, because we are deleting the _gallery_, not just a category (nobody is going to be deleting galleries with the expectation of moving the image to a different one in bulk - unlike download categories, for example).
if (function_exists('set_time_limit')) @set_time_limit(0);
do
{
$images=$GLOBALS['SITE_DB']->query_select('images',array('id'),array('cat'=>$name),'',200);
foreach ($images as $image)
{
delete_image($image['id'],false);
}
}
while ($images!=array());
do
{
$videos=$GLOBALS['SITE_DB']->query_select('videos',array('id'),array('cat'=>$name),'',200);
foreach ($videos as $video)
{
delete_video($video['id'],false);
}
}
while ($images!=array());
//... but the subgalleries remain
$GLOBALS['SITE_DB']->query_update('galleries',array('parent_id'=>$rows[0]['parent_id']),array('parent_id'=>$name));
$GLOBALS['SITE_DB']->query_delete('galleries',array('name'=>$name),'',1);
$GLOBALS['SITE_DB']->query_delete('rating',array('rating_for_type'=>'images','rating_for_id'=>$name));
$GLOBALS['SITE_DB']->query_delete('rating',array('rating_for_type'=>'videos','rating_for_id'=>$name));
require_code('seo2');
seo_meta_erase_storage('gallery',$name);
$GLOBALS['SITE_DB']->query_delete('group_category_access',array('module_the_name'=>'galleries','category_name'=>$name));
$GLOBALS['SITE_DB']->query_delete('gsp',array('module_the_name'=>'galleries','category_name'=>$name));
decache('main_top_galleries');
decache('main_recent_galleries');
decache('main_root_galleries');
decache('side_root_galleries');
}
void make_member_gallery_if_needed(ID_TEXT cat)
The UI shows member galleries that do not exist. If it is a member gallery, and it does not exist, it'll need making, before something can be added. This gallery performs the check and makes the gallery if needed.
Parameters…
| Name |
cat |
| Description |
The gallery name |
| Type |
ID_TEXT |
(No return value)
function make_member_gallery_if_needed($cat)
{
// If it is a non-member gallery, it must surely exist, as we have no interface to choose non-existant ones (it's safe enough to assume it hasn't been deleted suddenly)
if (substr($cat,0,7)!='member_') return;
// Test to see if it exists
$test=$GLOBALS['SITE_DB']->query_value_null_ok('galleries','name',array('name'=>$cat));
if (is_null($test))
{
$parts=explode('_',$cat,3);
$member=intval($parts[1]); // Almost certainly going to be same as get_member(), but we might as well be general here
if (!has_specific_permission($member,'have_personal_category','cms_galleries')) return;
// Find about parent (new gallery inherits)
$parent_id=$parts[2];
$_parent_info=$GLOBALS['SITE_DB']->query_select('galleries',array('accept_images','accept_videos','flow_mode_interface','fullname'),array('name'=>$parent_id),'',1);
if (!array_key_exists(0,$_parent_info)) fatal_exit(do_lang_tempcode('INTERNAL_ERROR'));
$parent_info=$_parent_info[0];
$username=$GLOBALS['FORUM_DRIVER']->get_username($member);
if (is_null($username)) warn_exit(do_lang_tempcode('_USER_NO_EXIST',escape_html($username)));
add_gallery($cat,do_lang('PERSONAL_GALLERY_OF',$username,get_translated_text($parent_info['fullname'])),'','','',$parent_id,$parent_info['accept_images'],$parent_info['accept_videos'],0,$parent_info['flow_mode_interface']);
$rows=$GLOBALS['SITE_DB']->query_select('group_category_access',array('group_id'),array('module_the_name'=>'galleries','category_name'=>$parent_id));
foreach ($rows as $row)
{
$GLOBALS['SITE_DB']->query_insert('group_category_access',array('module_the_name'=>'galleries','category_name'=>$cat,'group_id'=>$row['group_id']));
}
}
}
ocPortal prefers PNG files over other image types. This is troubled by a lack of good support in Microsoft Internet Explorer.
PNG files have the added advantage that they can be 'alpha-blended' so that crisp, blended, images may be presented (as opposed to gif files, which have to be hard-blended into the background colour of your website).
Internet Explorer does not this alpha blending directly, which is why PNG image files 'pop' into being blended on page load… a special automated/transparent hack is applied to conduct the blending.
The negative side effects of this hack is the popping effect, the inability to have locally resized PNG images, and the inability to do the thumbnail blur effect used on other image file types. We believe that the blending advantages majorly outweigh these small problems but we hope that Microsoft improve support soon (All other major browsers do not have any issue).
0 reviews: Unrated (average)
There have been no comments yet