Example #1
0
 /**
  * Used to return default thumb
  */
 function default_thumb($size = NULL, $output = NULL)
 {
     if ($size != "_t" && $size != "_m") {
         $size = "_m";
     }
     if (file_exists(TEMPLATEDIR . "/images/thumbs/no-photo" . $size . ".png")) {
         $path = TEMPLATEURL . "/images/thumbs/no-photo" . $size . ".png";
     } else {
         $path = PHOTOS_URL . "/no-photo" . $size . ".png";
     }
     if (!empty($output) && $output == "html") {
         return cb_output_img_tag($path);
     } else {
         return $path;
     }
 }
Example #2
0
function get_mature_thumb($object, $size = null, $output = null)
{
    /* Calling custom function */
    $funcs = cb_get_functions('mature_thumb');
    if (is_array($funcs)) {
        foreach ($funcs as $func) {
            if (function_exists($func['func'])) {
                $thumb = $func['func']($object, $size, $output);
                if ($thumb) {
                    return $thumb;
                }
            }
        }
    }
    if ($size == 'big') {
        $size = '-big';
    } else {
        $size = null;
    }
    $name = "unsafe" . $size . ".png";
    $path = BASEURL . '/images/' . $name;
    $attrs['class'] = 'cb-mature-thumb';
    if ($output) {
        return cb_output_img_tag($path, $attrs);
    } else {
        return $path;
    }
}
Example #3
0
/**
 * 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;
                    }
                }
            }
        }
    }
}