exts = array('jpg', 'png', 'gif', 'jpeg'); // This should be added from Admin Area. may be some people also want to allow BMPs; $this->embed_types = array("html", "forum", "email", "direct"); $this->set_default_tagger_configs(); } /** * Setting up Photos Section */ function init_photos() { global $Cbucket; $this->init_actions(); $this->init_collections(); $this->photos_admin_menu(); $this->setting_other_things(); $this->set_photo_max_size(); $this->thumb_dimensions = array( 't' => array( 'width' => config('photo_thumb_width'), 'height' => config('photo_thumb_height'), 'crop' => (config('photo_crop') == 0 ? -1 : 4 ), 'watermark' => false, 'shrapit' => true ), 'm' => array( 'width' => config('photo_med_width'), 'height' => config('photo_med_height'), 'crop' => (config('photo_crop') == 0 ? -1 : 4 ), 'watermark' => false, 'shrapit' => false ), 'l' => array( 'width' => config('photo_lar_width'), 'height' => 0, 'crop' => -1, 'watermark' => config('watermark_photo'), 'shrapit' => false ), 'o' => array( 'width' => 0, 'height' => 0, 'crop' => -1, 'watermark' => config('watermark_photo'), 'shrapit' => false ) ); /* Following is a sample for custom thumbs. We will have a config called 'custom_thumbs'. * This will be a json_encoded multi-dimensional associative array. It's will be following * $custom_thumbs = [type:'video|user|collection|photo|group'] => array( * [unique_code] => array( * [name] => 'Thumb', * [unique_code] => 'thumb', * [abbr] => 't', * [width] => '120', * [height] => '90', * [crop] => true|false * [keep_aspect_ratio] => true|false * ) * ) */ if ( $Cbucket->configs['custom_thumbs_dimensions'] || $Cbucket->configs['custom_thumbs_dimensions'] == '' ) { } } /** * Initiating Actions for Photos */ function init_actions() { $this->action = new cbactions(); $this->action->init(); // Setting up reporting excuses $this->action->type = 'p'; $this->action->name = 'photo'; $this->action->obj_class = 'cbphoto'; $this->action->check_func = 'photo_exists'; $this->action->type_tbl = "photos"; $this->action->type_id_field = 'photo_id'; } /** * Setting Email Settings */ function set_share_email( $data ) { $this->share_email_vars = array( '{photo_title}' => $data['photo_title'], '{photo_description}' => $data['photo_description'], '{photo_link}' => $this->collection->collection_links( $data, 'view_item' ), '{photo_thumb}' => $this->get_image_file( $data['photo_id'], 'm' ) ); $this->action->share_template_name = 'photo_share_template'; $this->action->val_array = $this->share_email_vars; } /** * Initiating Collections for Photos */ function init_collections() { $this->collection = new Collections; $this->collection->objType = "p"; $this->collection->objClass = "cbphoto"; $this->collection->objTable = "photos"; $this->collection->objName = "Photo"; $this->collection->objFunction = "photo_exists"; $this->collection->objFieldID = "photo_id"; $this->photo_register_function( 'delete_collection_photos' ); } /** * Create Admin Area menu for photos */ function photos_admin_menu() { global $Cbucket,$cbcollection,$userquery; $am = $Cbucket->AdminMenu; $per = $userquery->get_user_level(userid()); $menu = array( 'title' => lang('Photos Manager'), 'icon' => 'icon-picture', 'id' => 'photos-manager', 'access' => 'photos_moderation', ); $sub_menu = array( 'photos-manager' => array( array('title' => lang('Photo Manager'), 'link' => 'photo_manager.php'), array('title' => lang('Flagged Photos'), 'link' => 'flagged_photos.php'), array('title' => lang('Orphan Photos'), 'link' => 'orphan_photos.php'), array('title' => lang('Photo Settings'), 'link' => 'photo_settings.php'), array('title' => lang('Watermark Settings'), 'link' => 'photo_settings.php?mode=watermark_settings'), array('title' => lang('Recreate Thumbs'), 'link' => 'recreate_thumbs.php?mode=mass') ) ); add_admin_menu($menu); add_admin_sub_menus($sub_menu); } /** * Setting other things */ function setting_other_things() { global $userquery, $Cbucket; // Search type if ( isSectionEnabled( 'photos' ) ) $Cbucket->search_types['photos'] = "cbphoto"; // My account links $accountLinks = array(); $accountLinks = array( lang( 'manage_photos' ) => "manage_photos.php", lang( 'manage_favorite_photos' ) => "manage_photos.php?mode=favorite", lang( 'manage_my_album' ) => "manage_photos.php?mode=my_album", ); if ( isSectionEnabled( 'photos' ) ) $userquery->user_account[lang( 'Photos' )] = $accountLinks; //Setting Cbucket links $Cbucket->links['photos'] = array('photos.php', 'photos/'); $Cbucket->links['manage_photos'] = array('manage_photos.php', 'manage_photos.php'); $Cbucket->links['edit_photo'] = array('edit_photo.php?photo=', 'edit_photo.php?photo='); $Cbucket->links['photo_upload'] = array('photo_upload.php', 'photo_upload'); $Cbucket->links['manage_favorite_photos'] = array('manage_photos.php?mode=favorite', 'manage_photos.php?mode=favorite'); $Cbucket->links['manage_orphan_photos'] = array('manage_photos.php?mode=orphan', 'manage_photos.php?mode=orphan'); $Cbucket->links['user_photos'] = array('user_photos.php?mode=uploaded&user=', 'user_photos.php?mode=uploaded&user='); $Cbucket->links['user_fav_photos'] = array('user_photos.php?mode=favorite&user=', 'user_photos.php?mode=favorite&user='); // Setting Home Tab } /** * Initiatting Search */ function init_search() { $this->search = new cbsearch; $this->search->db_tbl = "photos"; $this->search->use_match_method = TRUE; $this->search->columns = array( array("field" => "photo_title", "type" => "LIKE", "var" => "%{KEY}%"), array("field" => "photo_tags", "type" => "LIKE", "var" => "%{KEY}%", "op" => "OR") ); $this->search->match_fields = array("photo_title", "photo_tags"); $this->search->cat_tbl = $this->cat_tbl; $this->search->display_template = LAYOUT . '/blocks/photo.html'; $this->search->template_var = 'photo'; $this->search->has_user_id = true; $this->search->results_per_page = config( 'photo_search_result' ); $this->search->search_type['photos'] = array('title' => lang( 'photos' )); $this->search->add_cond( tbl( 'photos.collection_id' ) . " <> 0" ); $sorting = array( 'date_added' => lang( "date_added" ), 'views' => lang( "views" ), 'total_comments' => lang( "comments" ), 'rating' => lang( "rating" ), 'total_favorites' => lang( "favorites" ) ); $this->search->sorting = array( 'date_added' => " date_added DESC", 'views' => " views DESC", 'rating' => " rating DESC, rated_by DESC", 'total_comments' => " total_comments DESC ", 'total_favorites' => " total_favorites DESC" ); $array = $_GET; $uploaded = $array['datemargin']; $sort = $array['sort']; $forms = array( 'query' => array( 'title' => lang( 'keywords' ), 'type' => 'textfield', 'name' => 'query', 'id' => 'query', 'value' => cleanForm( $array['query'] ) ), 'date_margin' => array( 'title' => lang( 'uploaded' ), 'type' => 'dropdown', 'name' => 'datemargin', 'id' => 'datemargin', 'value' => $this->search->date_margins(), 'checked' => $uploaded, ), 'sort' => array( 'title' => lang( 'sort_by' ), 'type' => 'dropdown', 'name' => 'sort', 'value' => $sorting, 'checked' => $sort ) ); $this->search->search_type['photos']['fields'] = $forms; } /** * Set File Max Size */ function set_photo_max_size() { global $Cbucket; $adminSize = $Cbucket->configs['max_photo_size']; if ( !$adminSize ) $this->max_file_size = 2 * 1024 * 1024; else $this->max_file_size = $adminSize * 1024 * 1024; } /** * Check if photo exists or not */ function photo_exists( $id ) { global $db; if ( is_numeric( $id ) ) $result = $db->select( tbl( $this->p_tbl ), "photo_id", " photo_id = '$id'" ); else $result = $db->select( tbl( $this->p_tbl ), "photo_id", " photo_key = '$id'" ); if ( $result ) return true; else return false; } /** * Register function */ function photo_register_function( $func ) { global $cbcollection; $cbcollection->collection_delete_functions[] = 'delete_collection_photos'; } /** * Get Photo */ function get_photo( $pid, $join = false ) { global $db; if ( $join == true ) { list( $join, $alias ) = join_collection_table(); } if ( is_numeric( $pid ) ) $result = $db->select( tbl( $this->p_tbl ).$join, "*".$alias, " photo_id = '$pid'" ); else $result = $db->select( tbl( $this->p_tbl ).$join, "*".$alias, " photo_key = '$pid'" ); //echo $db->db_query; if ( $db->num_rows > 0 ) return $result[0]; else return false; } /** * Get Photos */ function get_photos( $p ) { global $db; $tables = "photos,users"; $order = $p['order']; $limit = $p['limit']; $cond = ""; if ( !has_access( 'admin_access', TRUE ) ) { $cond = " " . tbl( 'photos.broadcast' ) . " = 'public' AND " . tbl( 'photos.active' ) . " = 'yes'"; } else { if ( $p['active'] ) $cond .= " " . tbl( 'photos.active' ) . " = '" . $p['active'] . "'"; if ( $p['broadcast'] ) { if ( $cond != "" ) $cond .= " AND "; $cond .= " " . tbl( 'photos.broadcast' ) . " = '" . $p['broadcast'] . "'"; } } if ( $p['pid'] ) { if ( $cond != "" ) $cond .= " AND "; $cond .= $this->constructMultipleQuery( array("ids" => $p['pid'], "sign" => "=", "operator" => "OR") ); } if ( $p['key'] ) { if ( $cond != "" ) $cond .= " AND "; $cond .= " " . tbl( 'photos.photo_key' ) . " = '" . $p['key'] . "'"; } if ( $p['filename'] ) { if ( $cond != "" ) $cond .= " AND "; $cond .= " " . tbl( 'photos.filename' ) . " = '" . $p['filename'] . "'"; } if ( $p['extension'] ) { foreach ( $this->exts as $ext ) { if ( in_array( $ext, $this->exts ) ) { if ( $cond != "" ) $cond .= " AND "; $cond .= " " . tbl( 'photos.ext' ) . " = '" . $p['extension'] . "'"; } } } if ( $p['date_span'] ) { if ( $cond != "" ) $cond .= " AND "; $cond .= " " . cbsearch::date_margin( "date_added", $p['date_span'] ); } if ( $p['featured'] ) { if ( $cond != "" ) $cond .= " AND "; $cond .= " " . tbl( 'photos.featured' ) . " = '" . $p['featured'] . "'"; } if ( $p['user'] ) { if ( $cond != "" ) $cond .= " AND "; $cond .= $this->constructMultipleQuery( array("ids" => $p['user'], "sign" => "=", "operator" => "AND", "column" => "userid") ); } if ( $p['exclude'] ) { if ( $cond != "" ) $cond .= " AND "; $cond .= $this->constructMultipleQuery( array("ids" => $p['exclude'], "sign" => "<>") ); } $title_tag = ''; if ( $p['title'] ) { $title_tag = " " . tbl( 'photos.photo_title' ) . " LIKE '%" . $p['title'] . "%'"; } if ( $p['tags'] ) { $tags = explode( ",", $p['tags'] ); if ( count( $tags ) > 0 ) { if ( $title_tag != '' ) $title_tag .= " OR "; $total = count( $tags ); $loop = 1; foreach ( $tags as $tag ) { $title_tag .= " " . tbl( 'photos.photo_tags' ) . " LIKE '%$tag%'"; if ( $loop < $total ) $title_tag .= " OR "; $loop++; } } else { if ( $title_tag != '' ) $title_tag .= " OR "; $title_tag .= " " . tbl( 'photos.photo_tags' ) . " LIKE '%" . $p['tags'] . "%'"; } } if ( $title_tag != "" ) { if ( $cond != '' ) $cond .= " AND "; $cond .= " ($title_tag) "; } if ( $p['ex_user'] ) { if ( $cond != "" ) $cond .= " AND "; $cond .= $this->constructMultipleQuery( array("ids" => $p['ex_user'], "sign" => "<>", "operator" => "AND", "column" => "userid") ); } if ( $p['extra_cond'] ) { if ( $cond != "" ) $cond .= " AND "; $cond .= $p['extra_cond']; } if ( $p['get_orphans'] ) $p['collection'] = "\0"; if ( $p['collection'] ) { if ( $cond != "" ) $cond .= " AND "; $cond .= $this->constructMultipleQuery( array("ids" => $p['collection'], "sign" => "=", "operator" => "OR", "column" => "collection_id") ); } else { if ( $cond != "" ) $cond .= " AND "; $cond .= " " . tbl( 'photos.collection_id' ) . " <> '0'"; } if ( !$p['count_only'] && !$p['show_related'] ) { if ( $cond != "" ) $cond .= " AND "; $result = $db->select( tbl( $tables ), tbl( "photos.*,users.userid,users.username" ), $cond . tbl( "photos.userid" ) . " = " . tbl( "users.userid" ), $limit, $order ); //echo $db->db_query; } if ( $p['show_related'] ) { $cond = "MATCH(" . tbl( 'photos.photo_title,photos.photo_tags' ) . ")"; $cond .= " AGAINST ('" . cbsearch::set_the_key( $p['title'] ) . "' IN BOOLEAN MODE)"; if ( $p['exclude'] ) { if ( $cond != "" ) $cond .= " AND "; $cond .= $this->constructMultipleQuery( array("ids" => $p['exclude'], "sign" => "<>") ); } if ( $p['collection'] ) { if ( $cond != "" ) $cond .= " AND "; $cond .= $this->constructMultipleQuery( array("ids" => $p['collection'], "sign" => "<>", "column" => "collection_id") ); } if ( $p['extra_cond'] ) { if ( $cond != "" ) $cond .= " AND "; $cond .= $p['extra_cond']; } $result = $db->select( tbl( $tables ), tbl( "photos.*,users.userid,users.username" ), $cond . " AND " . tbl( 'photos.collection_id' ) . " <> '0' AND " . tbl( "photos.userid" ) . " = " . tbl( "users.userid" ), $limit, $order ); //echo $db->db_query; // We found nothing from TITLE of Photos, let's try TAGS if ( $db->num_rows == 0 ) { $tags = cbsearch::set_the_key( $p['tags'] ); $tags = str_replace( '+', '', $tags ); $cond = "MATCH(" . tbl( 'photos.photo_title,photos.photo_tags' ) . ")"; $cond .= " AGAINST ('" . $tags . "' IN BOOLEAN MODE)"; if ( $p['exclude'] ) { if ( $cond != "" ) $cond .= " AND "; $cond .= $this->constructMultipleQuery( array("ids" => $p['exclude'], "sign" => "<>") ); } if ( $p['collection'] ) { if ( $cond != "" ) $cond .= " AND "; $cond .= $this->constructMultipleQuery( array("ids" => $p['collection'], "sign" => "<>", "column" => "collection_id") ); } if ( $p['extra_cond'] ) { if ( $cond != "" ) $cond .= " AND "; $cond .= $p['extra_cond']; } $result = $db->select( tbl( $tables ), tbl( "photos.*,users.userid,users.username" ), $cond . " AND " . tbl( 'photos.collection_id' ) . " <> '0' AND " . tbl( "photos.userid" ) . " = " . tbl( "users.userid" ), $limit, $order ); //echo $db->db_query; } } if ( $p['count_only'] ) { if ( $p['extra_cond'] ) { if ( $cond != "" ) $cond .= " AND "; $cond .= $p['extra_cond']; } $result = $db->count( tbl( "photos" ), "photo_id", $cond ); } if ( $p['assign'] ) assign( $p['assign'], $result ); else return $result; } /** * Used to construct Multi Query * Only IDs will be excepted */ function constructMultipleQuery( $params ) { $cond = ""; $IDs = $params['ids']; if ( is_array( $IDs ) ) $IDs = $IDs; else $IDs = explode( ",", $IDs ); $count = 0; $cond .= "( "; foreach ( $IDs as $id ) { $id = str_replace( " ", "", $id ); if ( is_numeric( $id ) || $params['column'] == 'collection_id' ) { if ( $count > 0 ) $cond .= " " . ($params['operator'] ? $params['operator'] : 'AND') . " "; $cond .= "" . tbl( 'photos.' . ($params['column'] ? $params['column'] : 'photo_id') ) . " " . ($params['sign'] ? $params['sign'] : '=') . " '" . $id . "'"; $count++; } } $cond .= " )"; return $cond; } /** * Used to construct Exclude Query function exclude_query($array) { $cond = ''; if(!is_array($array)) $ids = explode(',',$array); else $ids = $array; $count = 0; $cond .= "( "; foreach($ids as $id) { $count++; if($count > 1) $cond .= " AND "; $cond .= " ".tbl('photos.photo_id')." <> '".$id."'"; } $cond .= " )"; return $cond; } */ /** * Used to generate photo key * Replica of video_keygen function */ function photo_key() { global $db; $char_list = "ABDGHKMNORSUXWY"; $char_list .= "123456789"; while ( 1 ) { $photo_key = ''; srand( (double) microtime() * 1000000 ); for ( $i = 0; $i < 12; $i++ ) { $photo_key .= substr( $char_list, (rand() % (strlen( $char_list )) ), 1 ); } if ( !$this->pkey_exists( $photo_key ) ) break; } return $photo_key; } /** * Used to check if key exists */ function pkey_exists( $key ) { global $db; $db->select( tbl( "photos" ), "photo_key", " photo_key = '$key'" ); if ( $db->num_rows > 0 ) return true; else return false; } /** * Used to delete photo */ function delete_photo( $id, $oprhan = FALSE ) { global $db; if ( $this->photo_exists( $id ) ) { $photo = $this->get_photo( $id ); $del_photo_funcs = cb_get_functions( 'delete_photo' ); if ( is_array( $del_photo_funcs ) ) { foreach ( $del_photo_funcs as $func ) { if ( function_exists( $func['func'] ) ) { $func['func']( $photo ); } } } if ( $orphan == FALSE )//removing from collection $this->collection->remove_item( $photo['photo_id'], $photo['collection_id'] ); //now removing photo files $this->delete_photo_files( $photo ); //finally removing from Database $this->delete_from_db( $photo ); //Decrementing User Photos $db->update( tbl( "users" ), array("total_photos"), array("|f|total_photos-1"), " userid='" . $photo['userid'] . "'" ); //Removing Photo Comments $db->delete( tbl( "comments" ), array("type", "type_id"), array("p", $photo['photo_id']) ); //Removing Photo From Favortes $db->delete( tbl( "favorites" ), array("type", "id"), array("p", $photo['photo_id']) ); } else e( lang( "photo_not_exists" ) ); } /** * Used to delete photo files */ function delete_photo_files( $id ) { if ( !is_array( $id ) ) $photo = $this->get_photo( $id ); else $photo = $id; $pid = $photo['photo_id']; $files = $this->get_image_file( $pid, 't', TRUE, NULL, FALSE, TRUE ); if ( !empty( $files ) ) { foreach ( $files as $file ) { $file_dir = PHOTOS_DIR . "/" . $file; if ( file_exists( $file_dir ) ) unlink( $file_dir ); } e( sprintf( lang( "success_delete_file" ), $photo['photo_title'] ), "m" ); } } /** * Used to delete photo from database */ function delete_from_db( $id ) { global $db; if ( is_array( $id ) ) $delete_id = $id['photo_id']; else $delete_id = $id; $db->execute( "DELETE FROM " . tbl( 'photos' ) . " WHERE photo_id = $delete_id" ); e( lang( "photo_success_deleted" ), "m" ); } /** * Used to get photo owner */ function get_photo_owner( $id ) { return $this->get_photo_field( $id, 'userid' ); } /** * Used to get photo any field */ function get_photo_field( $id, $field ) { global $db; if ( !$field ) return false; else { if ( !is_numeric( $id ) ) $result = $db->select( tbl( $this->p_tbl ), $field, ' photo_key = ' . $id . '' ); else $result = $db->select( tbl( $this->p_tbl ), $field, ' photo_id = ' . $id . '' ); if ( $result ) return $result[0][$field]; else return false; } } /** * Used filter array */ function remove_empty_indexes( $array ) { $newArr = array(); if ( is_array( $array ) ) { foreach ( $array as $key => $arr ) { if ( is_array( $arr ) ) { foreach ( $arr as $a ) { if ( !empty( $a ) ) { $newArr[$key][] = $a; } } } } return $newArr; } else { echo "No Array Provided"; } } /** * Used to crop the image * Image will be crop to dead-center */ function crop_image( $input, $output, $ext, $width, $height ) { $info = getimagesize( $input ); $Swidth = $info[0]; $Sheight = $info[1]; $canvas = imagecreatetruecolor( $width, $height ); $left_padding = $Swidth / 2 - $width / 2; $top_padding = $Sheight / 2 - $height / 2; switch ( $ext ) { case "jpeg": case "jpg": case "JPG": case "JPEG": { $image = imagecreatefromjpeg( $input ); imagecopy( $canvas, $image, 0, 0, $left_padding, $top_padding, $width, $height ); imagejpeg( $canvas, $output, 90 ); } break; case "png": case "PNG": { $image = imagecreatefrompng( $input ); imagecopy( $canvas, $image, 0, 0, $left_padding, $top_padding, $width, $height ); imagepng( $canvas, $output, 9 ); } break; case "gif": case "GIF": { $image = imagecreatefromgif( $input ); imagecopy( $canvas, $image, 0, 0, $left_padding, $top_padding, $width, $height ); imagejpeg( $canvas, $output, 90 ); } break; default: { return false; } break; } imagedestroy( $canvas ); } /** * Used to resize and watermark image * */ function generate_photos( $array ) { global $db; $path = PHOTOS_DIR . "/"; if ( !is_array( $array ) ) $p = $this->get_photo( $array ); else $p = $array; $filename = $p['filename']; $extension = $p['ext']; /* Updating resizes code. From static, we'll load code, dimensions, watermark and sharpit from thumb_dimensions array */ $dimensions = $this->thumb_dimensions; $img = new CB_Resizer( $path.$filename.".".$extension ); foreach ( $dimensions as $code => $dim ) { $img->target = $path.$filename."_".$code.".".$extension; // Set cropping $img->crop = $dim['crop']; $img->_resize( $dim['width'], $dim['height'] ); // Check if we want to sharp this thumb if ( $dim['sharpit'] == true ) { $img->_sharpit(); } // Check if we want to apply watermark if ( $dim['watermark'] == true ) { // Set placement $img->watermark_placement = $this->position; $watermark_file = $this->watermark_file(); // Replacing URL to DIR. $watermark = str_replace( BASEURL, BASEDIR, $watermark_file ); $img->watermark( $watermark ); } // Lets save it $img->save(); } // $this->createThumb( $path . $filename . "." . $extension, $path . $filename . "_o." . $extension, $extension ); // $this->createThumb( $path . $filename . "." . $extension, $path . $filename . "_t." . $extension, $extension, $this->thumb_width, $this->thumb_height ); // $this->createThumb( $path . $filename . "." . $extension, $path . $filename . "_m." . $extension, $extension, $this->mid_width, $this->mid_height ); // $this->createThumb( $path . $filename . "." . $extension, $path . $filename . "_l." . $extension, $extension, $this->lar_width ); // // $should_watermark = config( 'watermark_photo' ); // // if ( !empty( $should_watermark ) && $should_watermark == 1 ) { // $this->watermark_image( $path . $filename . "_l." . $extension, $path . $filename . "_l." . $extension ); // $this->watermark_image( $path . $filename . "_o." . $extension, $path . $filename . "_o." . $extension ); // } /* GETTING DETAILS OF IMAGES AND STORING THEM IN DB */ $this->update_image_details( $p ); } /** * This function is used to get photo files and extract * dimensions and file size of each file, put them in array * then encode in json and finally update photo details column */ function update_image_details( $photo ) { global $db, $json; if ( is_array( $photo ) && !empty( $photo['photo_id'] ) ) $p = $photo; else $p = $this->get_photo( $photo ); if ( !empty( $photo ) ) { $images = $this->get_image_file( $p, NULL, TRUE, NULL, FALSE ); if ( $images ) { foreach ( $images as $image ) { $imageFile = PHOTOS_DIR . "/" . $image; if ( file_exists( $imageFile ) ) { $imageDetails = getimagesize( $imageFile ); $imageSize = filesize( $imageFile ); $data[$this->get_image_type( $image )] = array( "width" => $imageDetails[0], "height" => $imageDetails[1], "attribute" => mysql_clean( $imageDetails[3] ), "size" => array( "bytes" => round( $imageSize ), "kilobytes" => round( $imageSize / 1024 ), "megabytes" => round( $imageSize / 1024 / 1024, 2 ) ) ); } } if ( is_array( $data ) && !empty( $data ) ) { if ( phpversion() < "5.2.0" ) $encodedData = stripslashes( $json->json_encode( $data ) ); else $encodedData = stripslashes( json_encode( $data ) ); $db->update( tbl( 'photos' ), array("photo_details"), array("|no_mc|$encodedData"), " photo_id = '" . $p['photo_id'] . "' " ); } } } } /** * Creating resized photo */ function createThumb( $from, $to, $ext, $d_width = NULL, $d_height = NULL, $force_copy = false ) { $file = $from; $info = getimagesize( $file ); $org_width = $info[0]; $org_height = $info[1]; if ( $org_width > $d_width && !empty( $d_width ) ) { $ratio = $org_width / $d_width; // We will resize it according to Width $width = $org_width / $ratio; $height = $org_height / $ratio; $image_r = imagecreatetruecolor( $width, $height ); if ( !empty( $d_height ) && $height > $d_height && $this->cropping == 1 ) { $crop_image = TRUE; } switch ( $ext ) { case "jpeg": case "jpg": case "JPG": case "JPEG": { $image = imagecreatefromjpeg( $file ); imagecopyresampled( $image_r, $image, 0, 0, 0, 0, $width, $height, $org_width, $org_height ); imagejpeg( $image_r, $to, 90 ); if ( !empty( $crop_image ) ) $this->crop_image( $to, $to, $ext, $width, $d_height ); } break; case "png": case "PNG": { $image = imagecreatefrompng( $file ); imagecopyresampled( $image_r, $image, 0, 0, 0, 0, $width, $height, $org_width, $org_height ); imagepng( $image_r, $to, 9 ); if ( !empty( $crop_image ) ) $this->crop_image( $to, $to, $ext, $width, $d_height ); } break; case "gif": case "GIF": { $image = imagecreatefromgif( $file ); imagecopyresampled( $image_r, $image, 0, 0, 0, 0, $width, $height, $org_width, $org_height ); imagegif( $image_r, $to, 90 ); if ( !empty( $crop_image ) ) $this->crop_image( $to, $to, $ext, $width, $d_height ); } break; } imagedestroy( $image_r ); } else { if ( !file_exists( $to ) || $force_copy === true ) copy( $from, $to ); } } /** * Used to get watermark file */ function watermark_file() { if ( file_exists( BASEDIR . "/images/photo_watermark.png" ) ) return BASEURL . "/images/photo_watermark.png"; else return false; } /** * Used to set watermark position */ function position_watermark( $file, $watermark ) { if ( empty( $this->position ) ) $info = array('left', 'top'); else $info = explode( ":", $this->position ); $x = $info[0]; $y = $info[1]; list($w, $h) = getimagesize( $file ); list($ww, $wh) = getimagesize( $watermark ); $padding = $this->padding; switch ( $x ) { case "center": { $finalxPadding = $w / 2 - $ww / 2; } break; case "left": default: { $finalxPadding = $padding; } break; case "right": { $finalxPadding = $w - $ww - $padding; } break; } switch ( $y ) { case "top": default: { $finalyPadding = $padding; } break; case "center": { $finalyPadding = $h / 2 - $wh / 2; } break; case "bottom": { $finalyPadding = $h - $wh - $padding; } break; } $values = array($finalxPadding, $finalyPadding); return $values; } /** * Used to watermark image */ function watermark_image( $input, $output ) { $watermark_file = $this->watermark_file(); if ( !$watermark_file ) return false; else { list($Swidth, $Sheight, $Stype) = getimagesize( $input ); $wImage = imagecreatefrompng( $watermark_file ); $ww = imagesx( $wImage ); $wh = imagesy( $wImage ); $paddings = $this->position_watermark( $input, $watermark_file ); switch ( $Stype ) { case 1: //GIF { $sImage = imagecreatefromgif( $input ); imagecopy( $sImage, $wImage, $paddings[0], $paddings[1], 0, 0, $ww, $wh ); imagejpeg( $sImage, $output, 90 ); } break; case 2: //JPEG { $sImage = imagecreatefromjpeg( $input ); imagecopy( $sImage, $wImage, $paddings[0], $paddings[1], 0, 0, $ww, $wh ); imagejpeg( $sImage, $output, 90 ); } break; case 3: //PNG { $sImage = imagecreatefrompng( $input ); imagecopy( $sImage, $wImage, $paddings[0], $paddings[1], 0, 0, $ww, $wh ); imagepng( $sImage, $output, 9 ); } break; } } } /** * Load Upload Form */ function loadUploadForm( $params ) { $p = $params; $should_include = $p['includeHeader'] ? $p['includeHeader'] : TRUE; $output = '