Exemplo n.º 1
0
 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);
     }
 }
Exemplo n.º 2
0
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);
    }
}