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"); $basic_fields = array( 'photo_id', 'photo_key', 'userid', 'photo_title', 'photo_description', 'photo_tags', 'collection_id', 'photo_details', 'date_added', 'filename', 'ext', 'active', 'broadcast', 'file_directory' ); $cb_columns->object( 'photos' )->register_columns( $basic_fields ); } /** * @return array */ function get_basic_fields() { return $this->basic_fields; } function set_basic_fields( $fields = array() ) { return $this->basic_fields = $fields; } function basic_fields_setup() { # Set basic video fields $basic_fields = array( 'photo_id', 'photo_key', 'userid', 'photo_title', 'photo_description', 'photo_tags', 'collection_id', 'photo_details', 'date_added', 'filename', 'ext', 'active', 'broadcast', 'file_directory' ); return $this->set_basic_fields( $basic_fields ); } function get_extra_fields() { return $this->extra_fields; } function set_extra_fields( $fields = array() ) { return $this->extra_fields = $fields; } function get_photo_fields( $extra_fields = array() ) { $fields = $this->get_basic_fields(); $extra = $this->get_extra_fields(); if ( empty( $fields ) ) { $fields = $this->basic_fields_setup(); } if ( !empty( $extra ) ) { $fields = array_merge( $fields, $extra ); } if ( !empty( $extra_fields ) ) { if ( is_array( $extra_fields ) ) { $fields = array_merge( $fields, $extra_fields ); } else { $fields[] = $extra_fields; } } # Do make array unqiue, otherwise we might get duplicate # fields $fields = array_unique( $fields ); return $fields; } function get_fields( $extra_fields = array() ) { return $this->get_photo_fields(); } function add_field( $field ) { $extra_fields = $this->get_extra_fields(); if ( is_array( $field ) ) { $extra_fields = array_merge( $extra_fields, $field ); } else { $extra_fields[] = $field; } return $this->set_extra_fields( $extra_fields ); } function add_photo_field( $field ) { return $this->add_field( $field ); } /** * Setting up Photos Section */ function init_photos() { $this->init_actions(); $this->init_collections(); $this->photos_admin_menu(); $this->setting_other_things(); $this->set_photo_max_size(); } /** * 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()); if($per['photos_moderation'] == "yes") $am['Photos'] = array( 'Photo Manager' => 'photo_manager.php', 'Flagged Photos' => 'flagged_photos.php', 'Orphan Photos' => 'orphan_photos.php', 'Photo Settings' => 'photo_settings.php', 'Watermark Settings' => 'photo_settings.php?mode=watermark_settings', 'Recreate Thumbs' => 'recreate_thumbs.php?mode=mass' ); $Cbucket->AdminMenu = $am; } /** * Setting other things Edited on 12 march 2014 for photo links */ function setting_other_things() { global $userquery,$Cbucket; // Search type if(isSectionEnabled('photos')) $Cbucket->search_types['photos'] = "cbphoto"; //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='); // My account links $accountLinks = array(); $accountLinks = array( lang('manage_photos') => cblink(array('name'=>'manage_photos')), lang('manage_favorite_photos') => cblink(array('name'=>'manage_photos','extra_params'=>'mode=favorite')), lang('manage_my_album') => cblink(array('name'=>'manage_photos','extra_params'=>'mode=my_album')), ); if(isSectionEnabled('photos')) $userquery->user_account[lang('Photos')] = $accountLinks; // 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 ) { global $db; $select_field = is_numeric( $pid ) ? 'photo_id' : 'photo_key'; $fields = array( 'photos' => array( '*' ), 'users' => get_user_fields(), 'collections' => array( 'collection_name', 'type', 'category', 'views as collection_views', 'date_added as collection_added' ) ); $string = tbl_fields( $fields ); $query = "SELECT $string FROM ".table( 'photos' ); $query .= " LEFT JOIN ".table( 'collections' )." ON photos.collection_id = collections.collection_id"; $query .= " LEFT JOIN ".table( 'users' )." ON collections.collection_id = users.userid"; $query .= " WHERE photos.$select_field = '$pid' "; if(is_numeric($pid)) $result = $db->select(tbl($this->p_tbl),"*"," photo_id = '$pid'"); else $result = $db->select(tbl($this->p_tbl),"*"," photo_key = '$pid'"); if($db->num_rows > 0) return $result[0]; else return false; } /** * Get Photos */ function get_photos($p) { global $db, $cb_columns; $tables = "photos,users"; $order = $p['order']; $limit = $p['limit']; $cond = ""; if(!has_access('admin_access',TRUE)) { $cond = " ".('photos.broadcast')." = 'public' AND ".('photos.active')." = 'yes'"; } else { if($p['active']) $cond .= " ".('photos.active')." = '".$p['active']."'"; if($p['broadcast']) { if($cond != "") $cond .= " AND "; $cond .= " ".('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 .= " ".('photos.photo_key')." = '".$p['key']."'"; } if($p['filename']) { if($cond != "") $cond .= " AND "; $cond .= " ".('photos.filename')." = '".$p['filename']."'"; } if($p['extension']) { foreach($this->exts as $ext) { if(in_array($ext,$this->exts)) { if($cond != "") $cond .= " AND "; $cond .= " ".('photos.ext')." = '".$p['extension']."'"; } } } if($p['date_span']) { if($cond != "") $cond .= " AND "; $cond .= " ".cbsearch::date_margin("photos.date_added",$p['date_span']); } if($p['featured']) { if($cond != "") $cond .= " AND "; $cond .= " ".('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 .= " ".('photos.photo_tags')." LIKE '%$tag%'"; if($loop<$total) $title_tag .= " OR "; $loop++; } } else { if($title_tag != '') $title_tag .= " OR "; $title_tag .= " ".('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'] = (string)"0"; } if($p['collection'] || $p['get_orphans']) { if($cond != "") $cond .= " AND "; $cond .= $this->constructMultipleQuery(array("ids"=>$p['collection'],"sign"=>"=","operator"=>"OR","column"=>"collection_id")); } else { if($cond != "") $cond .= " AND "; $cond .= " ".('photos.collection_id')." <> '0'"; } $fields = array( 'photos' => get_photo_fields(), 'users' => get_user_fields(), 'collections' => array( 'collection_name', 'type', 'category', 'views as collection_views', 'date_added as collection_added' ) ); $string = tbl_fields( $fields ); $main_query = "SELECT $string FROM ".table( 'photos' ); $main_query .= " LEFT JOIN ".table( 'collections' )." ON photos.collection_id = collections.collection_id"; $main_query .= " LEFT JOIN ".table( 'users' )." ON collections.userid = users.userid"; $order = $order ? " ORDER BY ".$order : false; $limit = $limit ? " LIMIT ".$limit : false; if(!$p['count_only'] && !$p['show_related']) { $query = $main_query; if ( $cond ) { $query .= " WHERE ".$cond; } $query .= $order; $query .= $limit; $result = select( $query ); } if($p['show_related']) { $query = $main_query; $cond = "MATCH(".('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']; } $where = " WHERE ".$cond." AND photos.collection_id <> 0"; $query .= $where; $query .= $order; $query .= $limit; $result = select( $query ); // We found nothing from TITLE of Photos, let's try TAGS if($db->num_rows == 0) { $query = $main_query; $tags = cbsearch::set_the_key($p['tags']); $tags = str_replace('+','',$tags); $cond = "MATCH(".('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']; } $where = " WHERE ".$cond." AND photos.collection_id <> 0"; $query .= $where; $query .= $order; $query .= $limit; $result = select( $query ); } } if($p['count_only']) { if($p['extra_cond']) { if($cond != "") $cond .= " AND "; $cond .= $p['extra_cond']; } $result = $db->count(table("photos"),"photo_id",$cond); } #pr( $query, true ); 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 .= "".('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 = get_image_file( array( 'details' => $photo, 'size' => 't', 'multi' => true, 'with_orig' => true, 'with_path' => false ) ); #$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; $path .= get_photo_date_folder( $p ).'/'; $filename = $p['filename']; $extension = $p['ext']; $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 = get_image_file( array( 'details' => $photo, 'size' => 't', 'multi' => true, 'with_path' => 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) if(!is_dir($from)){ 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; $output = ''; $should_include = $p['includeHeader'] ? $p['includeHeader'] : true; if( file_exists( LAYOUT."/blocks/upload_head.html" ) and $should_include == true ) { $output .= Fetch( "blocks/upload_head.html" ); } $output .= Fetch( "blocks/upload/photo_upload.html" ); return $output; $should_include = $p['includeHeader'] ? $p['includeHeader'] : TRUE; $output = '