function make_new_avatar($array = null)
{
    global $cbphoto, $userquery, $photo, $db, $cbcollection;
    if (is_null($array)) {
        $array = $_POST;
    }
    /* include resizer class */
    include_once 'includes/classes/resizer.class.php';
    $date_dir = get_photo_date_folder($photo);
    /* get original photo */
    $p = get_original_photo($photo);
    /* define source and decode photo details */
    $source = PHOTOS_DIR . '/' . $date_dir . '/' . $p;
    $pd = json_decode($photo['photo_details'], true);
    /* coordinates */
    $x = mysql_clean($array['start_x']);
    $x2 = mysql_clean($array['end_x']);
    $y = mysql_clean($array['start_y']);
    $y2 = mysql_clean($array['end_y']);
    if (!is_numeric($x) || !is_numeric($x2) || !is_numeric($y) || !is_numeric($y2)) {
        e('Unable to crop. Coordinates were unrealiable.');
    } else {
        /*
         * We will be using the original photo to crop the avatar.
         * First we'll covert the posted pixels to percentage
         * Second get pixels from original photo using percentage
         * Using newly computed pixels crop from original photo
         * Save it in avatar collection, make it source and start making avatars
         */
        $xx = $x / $pd['l']['width'] * 100;
        // compute percentage
        $xx2 = $x2 / $pd['l']['width'] * 100;
        // compute percentage
        $newX = $xx * $pd['o']['width'] / 100;
        // compute pixels
        $newX2 = $xx2 * $pd['o']['width'] / 100;
        // compute pixels
        $yy = $y / $pd['l']['height'] * 100;
        // compute percentage
        $yy2 = $y2 / $pd['l']['height'] * 100;
        // compute percentage
        $newY = $yy * $pd['o']['height'] / 100;
        // compute pixels
        $newY2 = $yy2 * $pd['o']['height'] / 100;
        // compute pixels
        /* set source */
        $r = new CB_Resizer($source);
        $filename = cb_filename();
        $photopath = PHOTOS_DIR . '/' . createDataFolders(PHOTOS_DIR);
        $avatar_dir = USER_THUMBS_DIR . '/';
        $uid = $userquery->udetails['userid'];
        $ext = $photo['ext'];
        $cid = cb_create_user_avatar_collection($userquery->udetails);
        /* Save the cropped as original source of photo. */
        $new_photo = $r->target = $photopath . '/' . $filename . "." . $photo['ext'];
        $r->_crop($newX, $newY, $newX2, $newY2);
        $r->save();
        $fields = array('photo_title' => 'Avatar', 'photo_description' => ' ', 'photo_tags' => ' ', 'filename' => $filename, 'userid' => $uid, 'ext' => $photo['ext'], 'is_avatar' => true, 'collection_id' => $cid);
        /* Inserting photo in user's avatar collection */
        $photo_id = $cbphoto->insert_photo($fields);
        $avatar = $uid . '_' . $filename . '.' . $ext;
        $avatarpath = $avatar_dir . $avatar;
        /* Make $new_photo the source */
        $r->source = $r->target;
        /* Big Thumb */
        $r->target = $avatarpath;
        $r->_resize(AVATAR_SIZE, AVATAR_SIZE);
        $r->save();
        /* Small Thumb */
        $r->target = USER_THUMBS_DIR . '/' . $uid . '_' . $filename . '-small.' . $photo['ext'];
        $r->_resize(AVATAR_SMALL_SIZE, AVATAR_SMALL_SIZE);
        $r->save();
        /* Update user avatar field */
        $db->update(tbl('users'), array('avatar'), array($avatar), " userid = '" . $uid . "' ");
        /* Update cover photo of collection */
        $cbcollection->set_cover_photo($photo_id, $cid);
        /* go back to photo */
        redirect_to($cbphoto->photo_links($photo, 'view_photo'));
        /* go to user profile */
        //redirect_to( $userquery->profile_link(userid()) );
    }
}
Exemple #2
0
 /**
  * Ready photo for downloading
  */
 function ready_photo_file($pid)
 {
     $photo = $this->get_photo($pid);
     if (empty($photo)) {
         e(lang("photo_not_exist"));
     } else {
         if (!$this->collection->is_viewable($photo['collection_id'])) {
             return false;
         } else {
             $filename = $this->get_image_file($photo['photo_id'], 'o', FALSE, FALSE, FALSE);
             $returnArray = array("file_dir" => PHOTOS_DIR . "/" . get_photo_date_folder($photo) . "/" . $filename, "file_url" => PHOTOS_URL . "/" . get_photo_date_folder($photo) . "/" . $filename, "filename" => $filename, "details" => $photo);
             return $returnArray;
         }
     }
 }
Exemple #3
0
 /**
  * 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);
 }
/**
 * Updated version of getting photo file. In this function
 * we dont use glob() function to first get all thumbs and
 * then extract one thumb, instead now we only construct
 * the url of given code/size, checks if file_exists, if yes return
 * thumb else return default thumb.
 */
function get_image_file($params)
{
    global $cbphoto, $Cbucket;
    $details = $params['details'];
    $output = $params['output'];
    $sizes = $params['size'] ? $params['size'] : ($params['code'] ? $params['code'] : 't');
    if (empty($details)) {
        return $cbphoto->default_thumb($size, $output);
    } else {
        // Make sure photo exists
        if (!is_array($details)) {
            $photo = $cbphoto->get_photo($details, true);
        } else {
            $photo = $details;
        }
        if (empty($photo['photo_id']) or empty($photo['photo_key'])) {
            return $cbphoto->default_thumb($size, $output);
        } else {
            if (empty($photo['filename']) or empty($photo['ext'])) {
                return $cbphoto->default_thumb($size, $output);
            } else {
                $params['photo'] = $photo;
                // Call custom functions
                if (count($Cbucket->custom_get_photo_funcs) > 0) {
                    foreach ($Cbucket->custom_get_photo_funcs as $funcs) {
                        if (function_exists($funcs)) {
                            $func_returned = $funcs($params);
                            if ($func_returned) {
                                return $func_returned;
                            }
                        }
                    }
                }
                if ($details['is_mature'] == 'yes' && !userid()) {
                    return get_mature_thumb($details, $size, $output);
                }
                $dir = PHOTOS_DIR;
                $file_directory = get_photo_date_folder($photo);
                $with_path = $params['with_path'] = $params['with_path'] === false ? false : true;
                if ($file_directory) {
                    $file_directory .= '/';
                }
                $path = $dir . '/' . $file_directory;
                $file_name = $photo['filename'] . '%s.' . $photo['ext'];
                $sizes = explode(",", $sizes);
                if ($sizes[0] == 'all' and count($sizes) == 1) {
                    $sizes = get_photo_dimensions(true);
                    $sizes = array_keys($sizes);
                }
                $sizes = array_map("trim", $sizes);
                if (phpversion < '5.2.0') {
                    global $json;
                    $js = $json;
                }
                if (!empty($js)) {
                    $image_details = $js->json_decode($photo['photo_details'], true);
                } else {
                    $image_details = json_decode($photo['photo_details'], true);
                }
                foreach ($sizes as $size) {
                    $filename = sprintf($file_name, "_" . $size);
                    $full_path = $path . $filename;
                    if (file_exists($full_path)) {
                        if ($with_path) {
                            $thumbs[] = PHOTOS_URL . '/' . $file_directory . $filename;
                        } else {
                            $thumbs[] = $filename;
                        }
                    }
                }
                if ($params['with_orig'] === true) {
                    if ($with_path) {
                        $thumbs[] = PHOTOS_URL . '/' . $file_directory . sprintf($file_name, "");
                    } else {
                        $thumbs[] = sprintf($file_name, "");
                    }
                }
                //pr ( $thumbs, true );
                if (!$thumbs or count($thumbs) <= 0) {
                    $thumbs = _recheck_photo_code($params);
                    if (!$thumbs or !is_array($thumbs)) {
                        return $cbphoto->default_thumb($size, $output);
                    }
                }
                if (empty($params['output']) or $params['output'] == 'non_html') {
                    if ($params['assign']) {
                        assign($params['assign'], $thumbs);
                    } else {
                        if ($params['multi']) {
                            return $thumbs;
                        } else {
                            return $thumbs[0];
                        }
                    }
                } else {
                    $attrs = array();
                    $src = $thumbs[0];
                    $size = $cbphoto->get_image_type($src);
                    if (!file_exists(str_replace(PHOTOS_URL, PHOTOS_DIR, $src))) {
                        $src = $cbphoto->default_thumb($size);
                    }
                    if (empty($image_details) or !isset($image_details[$size])) {
                        $dem = getimagesize(str_replace(PHOTOS_URL, PHOTOS_DIR, $src));
                        $width = $dem[0];
                        $height = $dem[1];
                        /* UPDATEING IMAGE DETAILS */
                        $cbphoto->update_image_details($photo);
                    } else {
                        $width = $image_details[$size]['width'];
                        $height = $image_details[$size]['height'];
                    }
                    if ($params['width'] and is_numeric($params['width']) and ($params['height'] and is_numeric($height))) {
                        $width = $params['width'];
                        $height = $params['height'];
                    } else {
                        if ($params['width'] and is_numeric($params['width'])) {
                            $height = round($params['width'] / $width * $height);
                            $width = $params['width'];
                        } else {
                            if ($params['height'] and is_numeric($height)) {
                                $width = round($params['height'] * $width / $height);
                                $height = $p['height'];
                            }
                        }
                    }
                    $attrs['width'] = $width;
                    $attrs['height'] = $height;
                    if ($params['id']) {
                        $id = mysql_clean($params['id']) . "_" . $photo['photo_id'];
                    } else {
                        $id = "photo_" . $photo['photo_id'];
                    }
                    $attrs['id'] = $id;
                    if ($params['class']) {
                        $attrs['class'] = mysql_clean($params['class']);
                    }
                    if ($params['align']) {
                        $attrs['align'] = mysql_clean($params['align']);
                    }
                    $title = $params['title'] ? $params['title'] : $photo['photo_title'];
                    $attrs['title'] = mysql_clean($title);
                    $alt = $params['alt'] ? TITLE . ' - ' . $params['alt'] : TITLE . ' - ' . $photo['photo_title'];
                    $attrs['alt'] = mysql_clean($alt);
                    if (add_tagging_attribute($photo)) {
                        $attrs['cb-tagger-photo'] = 'yes';
                    }
                    $anchor_p = array("place" => 'photo_thumb', "data" => $photo);
                    $params['extra'] = ANCHOR($anchor_p);
                    if ($params['style']) {
                        $attrs['style'] = $params['style'];
                    }
                    if ($params['extra']) {
                        $attrs['extra'] = $params['extra'];
                    }
                    $image = cb_output_img_tag($src, $attrs);
                    if ($params['assign']) {
                        assign($params['assign'], $image);
                    } else {
                        return $image;
                    }
                }
            }
        }
    }
}
 function get_server_img($params)
 {
     global $__resize_thumbs;
     if (!$__resize_thumbs) {
         return;
     }
     $w = DEFAULT_WIDTH;
     $h = DEFAULT_HEIGHT;
     global $baseurl;
     $timthumb_path = CB_SERVER_THUMB_URL . '/timthumb.php?src=';
     //var_dump($params);
     $details = $params['details'];
     $output = $params['output'];
     $size = $params['size'];
     $default = array('t', 'm', 'l', 'o');
     $thumbs = array();
     if (!$details) {
         //var_dump("get default 1");
         return get_photo_default_thumb($size, $output);
     }
     if (!is_array($details)) {
         $photo = $cbphoto->get_photo($details, true);
     } else {
         $photo = $details;
     }
     if (empty($photo['photo_id']) or empty($photo['photo_key'])) {
         return get_photo_default_thumb($size, $output);
     }
     if (empty($photo['filename']) or empty($photo['ext'])) {
         return get_photo_default_thumb($size, $output);
     }
     $params['photo'] = $photo;
     $path = PHOTOS_DIR;
     $directory = get_photo_date_folder($photo);
     $with_path = $params['with_path'] = $params['with_path'] === false ? false : true;
     $with_original = $params['with_orig'];
     $size = (!in_array($size, $default) or !$size) ? 't' : $size;
     if ($size == 'l') {
         $w = 320;
         $h = 250;
     } else {
         if ($size == 'm') {
             $w = 160;
             $h = 90;
         } else {
             if ($size == 't') {
                 $w = 120;
                 $h = 60;
             }
         }
     }
     list($width, $height) = explode('x', $params['size']);
     if (isset($width) && is_numeric($width) && isset($height) && is_numeric($height)) {
         $w = $width;
         $h = $height;
     }
     $tim_postfix = '&type=photos&h=' . $h . '&w=' . $w . '&zc=1';
     if ($directory) {
         $directory .= '/';
     }
     $path .= '/' . $directory;
     $filename = $photo['filename'] . '%s.' . $photo['ext'];
     $files = glob($path . sprintf($filename, '*'));
     global $cbphoto;
     if (!empty($files)) {
         foreach ($files as $file) {
             $thumb_name = explode("/", $file);
             $thumb_name = end($thumb_name);
             $thumb_type = $cbphoto->get_image_type($thumb_name);
             if ($with_original) {
                 //$thumbs[] = ( ( $with_path ) ? PHOTOS_URL.'/' : '' ) . $directory . $thumb_name;
                 $thumbs[] = $timthumb_path . $thumb_name . '&directory=photos/' . $directory . $tim_postfix;
             } else {
                 if (!empty($thumb_type)) {
                     //$thumbs[] = ( ( $with_path ) ? PHOTOS_URL.'/' : '' ) . $directory . $thumb_name;
                     $thumbs[] = $timthumb_path . $thumb_name . '&directory=photos/' . $directory . $tim_postfix;
                 }
             }
         }
         if (empty($output) or $output == 'non_html') {
             if ($params['assign'] and $params['multi']) {
                 assign($params['assign'], $thumbs);
             } else {
                 if ($params['multi']) {
                     return $thumbs;
                 } else {
                     $search_name = sprintf($filename, "_" . $size);
                     $return_thumb = array_find($search_name, $thumbs);
                     if (empty($return_thumb)) {
                         return get_photo_default_thumb($size, $output);
                     } else {
                         if ($params['assign']) {
                             assign($params['assign'], $return_thumb);
                         } else {
                             return $return_thumb;
                         }
                     }
                 }
             }
         }
         if ($output == 'html') {
             $search_name = sprintf($filename, "_" . $size);
             $src = array_find($search_name, $thumbs);
             $src = empty($src) ? get_photo_default_thumb($size) : $src;
             $attrs = array('src' => $src);
             if (phpversion < '5.2.0') {
                 global $json;
             }
             if ($json) {
                 $image_details = $json->json_decode($photo['photo_details'], true);
             } else {
                 $image_details = json_decode($photo['photo_details'], true);
             }
             if (empty($image_details) or empty($image_details[$size])) {
                 $dem = getimagesize(str_replace(PHOTOS_URL, PHOTOS_DIR, $src));
                 $width = $dem[0];
                 $height = $dem[1];
                 /* UPDATEING IMAGE DETAILS */
                 $cbphoto->update_image_details($photo);
             } else {
                 $width = $image_details[$size]['width'];
                 $height = $image_details[$size]['height'];
             }
             if ($params['width'] and is_numeric($params['width']) and ($params['height'] and is_numeric($height))) {
                 $width = $params['width'];
                 $height = $params['height'];
             } else {
                 if ($params['width'] and is_numeric($params['width'])) {
                     $height = round($params['width'] / $width * $height);
                     $width = $params['width'];
                 } else {
                     if ($params['height'] and is_numeric($height)) {
                         $width = round($params['height'] * $width / $height);
                         $height = $params['height'];
                     }
                 }
             }
             //$attrs[ 'width' ] = $width;
             //$attrs[ 'height' ] = $height;
             $attrs['id'] = ($params['id'] ? $params['id'] . '_' : 'photo_') . $photo['photo_id'];
             if ($params['class']) {
                 $attrs['class'] = mysql_clean($params['class']);
             }
             if ($params['align']) {
                 $attrs['align'] = mysql_clean($params['align']);
             }
             $attrs['title'] = $photo['photo_title'];
             if (isset($params['title']) and $params['title'] == '') {
                 unset($attrs['title']);
             }
             $attrs['alt'] = TITLE . ' - ' . $photo['photo_title'];
             $anchor_p = array("place" => 'photo_thumb', "data" => $photo);
             $params['extra'] = ANCHOR($anchor_p);
             if ($params['style']) {
                 $attrs['style'] = $params['style'];
             }
             if ($params['extra']) {
                 $attrs['extra'] = $params['extra'];
             }
             $image = cb_create_html_tag('img', true, $attrs);
             if ($params['assign']) {
                 assign($params['assign'], $image);
             } else {
                 return $image;
             }
         }
     } else {
         return get_photo_default_thumb($size, $output);
     }
 }
function get_image_file($params)
{
    global $cbphoto, $Cbucket;
    //var_dump($params);
    $details = $params['details'];
    $output = $params['output'];
    $size = $params['size'];
    $default = array('t', 'm', 'l', 'o');
    $thumbs = array();
    if (!$details) {
        //var_dump("get default 1");
        return get_photo_default_thumb($size, $output);
    }
    if (!is_array($details)) {
        $photo = $cbphoto->get_photo($details, true);
    } else {
        $photo = $details;
    }
    if (empty($photo['photo_id']) or empty($photo['photo_key'])) {
        //var_dump("get default 2");
        return get_photo_default_thumb($size, $output);
    }
    if (empty($photo['filename']) or empty($photo['ext'])) {
        //var_dump("get default 3");
        return get_photo_default_thumb($size, $output);
    }
    $params['photo'] = $photo;
    if (count($Cbucket->custom_get_photo_funcs) > 0) {
        $functions = $Cbucket->custom_get_photo_funcs;
        foreach ($functions as $func) {
            if (function_exists($func)) {
                $func_data = $func($params);
                if ($func_data) {
                    return $func_data;
                }
            }
        }
    }
    $path = PHOTOS_DIR;
    $directory = get_photo_date_folder($photo);
    $with_path = $params['with_path'] = $params['with_path'] === false ? false : true;
    $with_original = $params['with_orig'];
    $size = (!in_array($size, $default) or !$size) ? 't' : $size;
    if ($directory) {
        $directory .= '/';
    }
    $path .= '/' . $directory;
    $filename = $photo['filename'] . '%s.' . $photo['ext'];
    $files = glob($path . sprintf($filename, '*'));
    if (!empty($files)) {
        foreach ($files as $file) {
            $splitted = explode("/", $file);
            $thumb_name = end($splitted);
            $thumb_type = $cbphoto->get_image_type($thumb_name);
            if ($with_original) {
                $thumbs[] = ($with_path ? PHOTOS_URL . '/' : '') . $directory . $thumb_name;
            } else {
                if (!empty($thumb_type)) {
                    $thumbs[] = ($with_path ? PHOTOS_URL . '/' : '') . $directory . $thumb_name;
                }
            }
        }
        if (empty($output) or $output == 'non_html') {
            if ($params['assign'] and $params['multi']) {
                assign($params['assign'], $thumbs);
            } else {
                if ($params['multi']) {
                    return $thumbs;
                } else {
                    $search_name = sprintf($filename, "_" . $size);
                    $return_thumb = array_find($search_name, $thumbs);
                    if (empty($return_thumb)) {
                        return get_photo_default_thumb($size, $output);
                    } else {
                        if ($params['assign']) {
                            assign($params['assign'], $return_thumb);
                        } else {
                            return $return_thumb;
                        }
                    }
                }
            }
        }
        if ($output == 'html') {
            $search_name = sprintf($filename, "_" . $size);
            $src = array_find($search_name, $thumbs);
            $src = empty($src) ? get_photo_default_thumb($size) : $src;
            $attrs = array('src' => $src);
            if (phpversion < '5.2.0') {
                global $json;
            }
            if ($json) {
                $image_details = $json->json_decode($photo['photo_details'], true);
            } else {
                $image_details = json_decode($photo['photo_details'], true);
            }
            if (empty($image_details) or empty($image_details[$size])) {
                $dem = getimagesize(str_replace(PHOTOS_URL, PHOTOS_DIR, $src));
                $width = $dem[0];
                $height = $dem[1];
                /* UPDATEING IMAGE DETAILS */
                $cbphoto->update_image_details($photo);
            } else {
                $width = $image_details[$size]['width'];
                $height = $image_details[$size]['height'];
            }
            if ($params['width'] and is_numeric($params['width']) and ($params['height'] and is_numeric($height))) {
                $width = $params['width'];
                $height = $params['height'];
            } else {
                if ($params['width'] and is_numeric($params['width'])) {
                    $height = round($params['width'] / $width * $height);
                    $width = $params['width'];
                } else {
                    if ($params['height'] and is_numeric($height)) {
                        $width = round($params['height'] * $width / $height);
                        $height = $params['height'];
                    }
                }
            }
            //$attrs[ 'width' ] = $width;
            //$attrs[ 'height' ] = $height;
            $attrs['id'] = ($params['id'] ? $params['id'] . '_' : 'photo_') . $photo['photo_id'];
            if ($params['class']) {
                $attrs['class'] = mysql_clean($params['class']);
            }
            if ($params['align']) {
                $attrs['align'] = mysql_clean($params['align']);
            }
            $attrs['title'] = $photo['photo_title'];
            if (isset($params['title']) and $params['title'] == '') {
                unset($attrs['title']);
            }
            $attrs['alt'] = TITLE . ' - ' . $photo['photo_title'];
            $anchor_p = array("place" => 'photo_thumb', "data" => $photo);
            $params['extra'] = ANCHOR($anchor_p);
            if ($params['style']) {
                $attrs['style'] = $params['style'];
            }
            if ($params['extra']) {
                $attrs['extra'] = $params['extra'];
            }
            $image = cb_create_html_tag('img', true, $attrs);
            if ($params['assign']) {
                assign($params['assign'], $image);
            } else {
                return $image;
            }
        }
    } else {
        return get_photo_default_thumb($size, $output);
    }
}