get_photos($param);
}
//Simple Width Fetcher
function getWidth($file)
{
$sizes = getimagesize($file);
if($sizes)
return $sizes[0];
}
//Simple Height Fetcher
function getHeight($file)
{
$sizes = getimagesize($file);
if($sizes)
return $sizes[1];
}
//Load Photo Upload Form
function loadPhotoUploadForm($params)
{
global $cbphoto;
return $cbphoto->loadUploadForm($params);
}
//Photo File Fetcher
function get_photo($params)
{
global $cbphoto;
return $cbphoto->getFileSmarty($params);
}
//Photo Upload BUtton
function upload_photo_button($params)
{
global $cbphoto;
return $cbphoto->upload_photo_button($params);
}
//Photo Embed Cides
function photo_embed_codes($params)
{
global $cbphoto;
return $cbphoto->photo_embed_codes($params);
}
//Create download button
function photo_download_button($params)
{
global $cbphoto;
return $cbphoto->download_button($params);
}
function load_photo_controls ( $args ) {
global $cbphoto;
if ( !empty($args['photo'])) {
$controls = explode(',',$args['controls']);
$controls = array_map('trim', $controls);
foreach ($controls as $control) {
$control_args = null;
// Parameters for this controls
$control_args = $args[$control];
$method_to_call = 'load_'.$control;
if ( method_exists($cbphoto, $method_to_call) ) {
$cbphoto->$method_to_call( $args['photo'], $control_args); // Call the method
}
}
}
}
function get_original_photo( $photo ) {
global $cbphoto;
if ( !is_array($photo) ) {
$ph = $cbphoto->get_photo($photo);
} else {
$ph = $photo;
}
if ( is_array($ph) ) {
$files = $cbphoto->get_image_file( $ph, 'o', true, null, false, true);
$orig = $ph['filename'].'.'.$ph['ext'];
$file = array_find( $orig, $files );
return $file;
}
}
function insert_photo_colors( $photo ) {
global $db, $cbphoto;
if ( !is_array($photo) ) {
$ph = $cbphoto->get_photo( $photo );
} else {
$ph = $photo;
}
if ( is_array($ph) && isset($ph['photo_id']) ) {
if ( $id = $db->select( tbl('photosmeta'),'pmeta_id'," photo_id = '".$ph['photo_id']."' AND meta_name = 'colors' " ) ) {
return $id;
}
$dir = PHOTOS_DIR.'/'.get_photo_date_folder( $ph).'/';
$file = get_original_photo( $ph );
$path = $dir.$file;
if ( file_exists($path) ) {
$img = new CB_Resizer( $path );
$colors = $img->color_palette();
$img->_destroy(); // Free memory
if ( $colors ) {
$jcolors = json_encode( $colors );
$insert_id = $db->insert( tbl('photosmeta'), array('photo_id','meta_name','meta_value'), array($ph['photo_id'],'colors','|no_mc|'.$jcolors) );
if ( $insert_id ) {
return $insert_id;
}
}
}
}
}
function insert_exif_data( $photo ) {
global $db, $cbphoto;
if ( !is_array($photo) ) {
$ph = $cbphoto->get_photo( $photo );
} else {
$ph = $photo;
}
if ( is_array($ph) && isset($ph['photo_id']) ) {
$dir = PHOTOS_DIR.'/'.get_photo_date_folder( $ph).'/';
if ( strtolower($ph['ext']) != 'jpg' ) {
/* return if photo is not jpg */
return;
}
$file = get_original_photo( $ph );
$path = $dir.$file;
if ( file_exists($path) ) {
/* File exists. read the exif data. Thanks to CopperMine, Love you */
$data = read_exif_data_raw( $path, 0);
if ( isset($data['SubIFD']) ) {
$exif_to_include = array('IFD0','SubIFD','IFD1','InteroperabilityIFD');
foreach( $exif_to_include as $eti ) {
if ( isset( $data[$eti]) ) {
$exif[$eti] = $data[$eti];
}
}
/* Removing unknown tags from exif data */
foreach ( $exif as $parent => $tags ) {
foreach ( $tags as $tag => $value ) {
if ( $tag == 'MakerNote' ) {
if ( is_array( $value ) ) {
foreach( $value as $mtag => $mvalue ) {
if ( strpos($mtag,'unknown') !== false ) {
unset( $exif[$parent][$tag][$mtag] );
} else {
$exif[$parent][$tag][$mtag] = trim( $mvalue );
}
}
}
}
if ( is_array( $value )) {
continue;
}
if ( strpos($tag,'unknown') !== false ) {
unset( $exif[$parent][$tag] );
} else {
$exif[$parent][$tag] = trim( $value );
}
}
}
$jexif = json_encode($exif);
$jexif = preg_replace('/\\\(u000)(.){1}/','', $jexif);
/* add new meta of exif_data for current photo */
$insert_id = $db->insert( tbl('photosmeta'), array('photo_id','meta_name','meta_value'), array($ph['photo_id'],'exif_data',"|no_mc|$jexif") );
if ( $insert_id ) {
/* update photo has_exif to yes, so we know that this photo has exif data */
$db->update( tbl($cbphoto->p_tbl), array('exif_data'), array('yes'), " photo_id = '".$ph['photo_id']."' " );
return $insert_id;
}
}
}
}
}
function ready_exif_data ( $exif, $photo = null ) {
if ( empty( $exif ) || !is_array($exif) ) {
return false;
}
$formatted['dates']['taken'] = $exif['IFD0']['DateTime'] ? $exif['IFD0']['DateTime'] : null;
$formatted['dates']['uploaded'] = ( $photo ? $photo['date_added'] : null );
$formatted['base']['camera'] = ( $exif['IFD0']['Model'] ? $exif['IFD0']['Model'] : null );
$formatted['base']['exposure'] = ( $exif['SubIFD']['ExposureTime'] ? $exif['SubIFD']['ExposureTime'] : null );
$formatted['base']['aperture'] = ( $exif['SubIFD']['ApertureValue'] ? $exif['SubIFD']['ApertureValue'] : null );
$formatted['base']['focal length'] = ( $exif['SubIFD']['FocalLength'] ? $exif['SubIFD']['FocalLength'] : null );
$all = array();
$merge = array('IFD0','SubIFD');
foreach( $merge as $tag ) {
if ( isset($exif[$tag]) ) {
$all = array_merge($all, $exif[$tag]);
}
}
if ( isset( $exif['SubIFD']['MakerNote']) ) {
$all = array_merge( $all, $exif['SubIFD']['MakerNote'] );
unset( $all['MakerNote'] );
}
/* Remove Base indexes and DateTime */
unset( $all['DateTime'] );
unset( $all['Model'] );
unset( $all['ExposureTime'] );
unset( $all['ApertureValue'] );
unset( $all['FocalLength'] );
$formatted['rest'] = $all;
return $formatted;
}
function format_exif_camelCase( $str ) {
if ( !$str ) {
return false;
}
$re = '/(?<=[a-z])(?=[A-Z])/';
$str = preg_split( $re, $str );
return implode(' ', $str );
}
function cb_output_img_tag( $src, $attrs = null ) {
if ( empty( $src ) ) {
return false;
}
$start = "";
$attributes = ' src = "'.$src.'"';
if ( is_array( $attrs) ) {
/* We'll just loop through and add attrs in image */
foreach ( $attrs as $attr => $value ) {
if ( strtolower($attr) != 'extra' ) {
$attributes .= ' '.$attr.' = "'.$value.'" ';
} else {
$attributes .= $value;
}
}
}
// THIS IS MERGINGGGGGG
return $start.$attributes.$close;
}
/**
* Add a new thumb dimension in thumb_dimensions array.
*
* @global OBJECT $cbphoto
* @param STRING $code
* @param INT $width
* @param INT $height
* @param INT $crop
* @param BOOL $watermark
* @param BOOL $sharpit
* @return array
*/
function add_custom_photo_size( $code, $width = 0, $height = 0, $crop = 4, $watermark = false, $sharpit = false ) {
global $cbphoto;
$sizes = $cbphoto->thumb_dimensions;
$code = strtolower( $code );
if ( $code == 't' || $code == 'm' || $code == 'l' || $code == 'o' || preg_match('/[^\w]/', $code, $matches ) ) {
return false;
}
if ( !is_numeric( $width ) || !is_numeric( $height ) ) {
return false;
}
$sizes [ $code ] = array(
'width' => abs( $width ),
'height' => abs( $height ),
'crop' => $crop,
'watermark' => $watermark,
'sharpit' => $sharpit
);
return $cbphoto->thumb_dimensions = $sizes;
}
function get_all_custom_size_photos( $id ) {
global $cbphoto;
if ( !is_array( $id ) ) {
$photo = $cbphoto->get_photo( $id );
} else {
$photo = $id;
}
/* I'm unable to select only custom size photos using glob, so we'll
* get all photos loop through exclude clipbucket sizes and save only
* custom ones
*/
$files = $cbphoto->get_image_file( $photo, null, true, null, false );
$cbsize = $cbphoto->thumb_dimensions;
if ( $files ) {
foreach ( $files as $file ) {
$code = $cbphoto->get_image_type ( $file );
if ( !isset( $cbsize[ $code ]) ) {
$custom_files[] = $file;
}
}
if ( is_array( $custom_files ) ) {
return $custom_files;
} else {
return false;
}
}
}
function get_photo_dimensions() {
global $cbphoto;
return $cbphoto->thumb_dimensions;
}
function clean_custom_photo_size( $id ) {
global $cbphoto;
$photos = get_all_custom_size_photos( $id );
// Apply photo_dimension filters so get all custom sizes
apply_filters( null, 'photo_dimensions' );
$dimensions = get_photo_dimensions();
if ( $photos ) {
foreach ( $photos as $photo ) {
$code = $cbphoto->get_image_type( $photo );
/*
* The following custom code does not exist in thumb_dimensions array
*/
if ( !isset( $dimensions[ $code ] ) ) {
// I'm still thinking what to do with these extra photos
$path = PHOTOS_DIR.'/'.$photo;
$month = 2678400; // month period
$lastacc = fileatime( $path );
if ( ( $lastacc ) && time() - $lastacc > $month ) {
// it's been over a month since this file was accessed, remove it
unlink( $photo );
}
}
}
}
}
function get_photometa( $id, $name ) {
global $db;
if ( empty( $id ) || empty( $name ) ) {
return false;
}
$result = $db->select( tbl('photosmeta'), '*', " photo_id = '".$id."' AND meta_name = '".strtolower($name)."' " );
if ( $result ) {
return $result[0];
} else {
return false;
}
}
function get_photo_meta_value( $id, $name ) {
$meta = get_photometa($id, $name);
if ( $meta ) {
return $meta['meta_value'];
} else {
return false;
}
}
/**
* It returns an array for photo action link.
* This should be used with photo_action_links
* filter.
*
* @param string $text
* @param string $href
* @param string $target
* @return mix
*/
function add_photo_action_link( $text, $href, $icon = null, $target = null, $tags = null ) {
if ( !$text && !$href ) {
return false;
}
if ( strlen( trim( $href ) ) == 1 && $href == '#' ) {
$skip_href_check = true;
}
if ( !preg_match('/(http:\/\/|https:\/\/)/', $href, $matches ) && !$skip_href_check ) {
return false;
}
return array( 'href' => $href, 'text' => $text,'icon' => $icon, 'target' => $target, 'tags' => ( !is_null($tags) && is_array($tags) ) ? $tags : null );
}
function cbphoto_pm_action_link_filter( $links ) {
if ( userid() ) {
$links[] = add_photo_action_link( lang('Send in private message'), '#' , 'envelope', null, array('id' => 'private_message_photo', 'data-toggle' => 'modal', 'data-target' => '#private_message_photo_form') );
}
global $photo, $cbphoto;
if ( ( $photo['exif_data'] == 'yes' && $photo['view_exif'] == 'yes' ) || ( $photo['userid'] == userid() && $photo['exif_data'] == 'yes' ) ) {
$links[] = add_photo_action_link( lang('EXIF Data'), $cbphoto->photo_links( $photo, 'exif_data' ), 'camera' );
}
/* Later we uncomment this, BAM something new to give >:D */
//$links[] = add_photo_action_link( lang('View Colors'),'#','tasks', null, array('onclick' => 'show_colors(event)', 'data-photo-id' => $photo['photo_id']) );
return $links;
}
function register_photo_private_message_field( $photo ) {
global $cbpm;
$field = array(
'attach_photo' => array(
'name' => 'attach_photo',
'id' => 'attach_photo',
'value' => $photo['photo_key'],
'type' => 'hidden'
)
);
$cbpm->add_custom_field( $field );
}
function attach_photo_pm_handlers() {
global $cbpm;
$cbpm->pm_attachments[] = 'attach_photo';
$cbpm->pm_attachments_parse[] = 'parse_photo_attachment';
}
function attach_photo( $array ) {
global $cbphoto;
if ( $cbphoto->photo_exists( $array['attach_photo'] ) ) {
return '{p:'.$array['attach_photo'].'}';
}
}
function parse_photo_attachment( $att ) {
global $cbphoto;
preg_match('/{p:(.*)}/',$att,$matches);
$key = $matches[1];
if ( !empty( $key ) ) {
$photo = $cbphoto->get_photo( $key, true );
if ( $photo ) {
assign( 'photo',$photo );
assign( 'type','photo' );
Template( STYLES_DIR.'/global/blocks/pm/attachments.html', false );
}
}
}
/**
* This is registered at cb_head ANCHOR. This loads photo actions links.
* You can use photo_action_links filter to new links and
* photo_action_configs to provide custom configurations.
*
* Right now it has only to configurations.
* menu_wrapper =>