Пример #1
0
function process_GThumb($tpl_vars, $pictures)
{
    global $template, $conf;
    $template->set_filename('index_thumbnails', realpath(GTHUMB_PATH . 'template/gthumb.tpl'));
    $template->assign('GThumb', $conf['GThumb']);
    $template->assign('GThumb_derivative_params', ImageStdParams::get_custom(9999, $conf['GThumb']['height']));
    if ($conf['GThumb']['big_thumb'] and !empty($tpl_vars[0])) {
        $derivative_params = ImageStdParams::get_custom(9999, 2 * $conf['GThumb']['height'] + $conf['GThumb']['margin']);
        $template->assign('GThumb_big', new DerivativeImage($derivative_params, $tpl_vars[0]['src_image']));
    }
    return $tpl_vars;
}
 function init($height)
 {
     $this->candidates = array();
     foreach (ImageStdParams::get_defined_type_map() as $params) {
         if ($params->max_height() < $height || $params->sizing->max_crop) {
             continue;
         }
         if ($params->max_height() > 3 * $height) {
             break;
         }
         $this->candidates[] = $params;
     }
     $this->default = ImageStdParams::get_custom($height * 3, $height, 1, 0, $height);
     $this->height = $height;
 }
Пример #3
0
   $query_model = 'SELECT *
 FROM ' . IMAGES_TABLE . '
 WHERE id < start_id
 ORDER BY id DESC
 LIMIT ' . $qlimit;
   $urls = array();
   do {
       $result = pwg_query(str_replace('start_id', $start_id, $query_model));
       $is_last = pwg_db_num_rows($result) < $qlimit;
       while ($row = pwg_db_fetch_assoc($result)) {
           $start_id = $row['id'];
           $src_image = new SrcImage($row);
           if ($src_image->is_mimetype()) {
               continue;
           }
           $derivative = new DerivativeImage(ImageStdParams::get_custom(9999, $conf['GThumb']['height']), $src_image);
           if (@filemtime($derivative->get_path()) === false) {
               $urls[] = $derivative->get_url() . $uid;
           }
           if (count($urls) >= $max_urls && !$is_last) {
               break;
           }
       }
       if ($is_last) {
           $start_id = 0;
       }
   } while (count($urls) < $max_urls && $start_id);
   $ret = array();
   if ($start_id) {
       $ret['next_page'] = $start_id;
   }
Пример #4
0
 /**
  * The "define_derivative" function allows to define derivative from tpl file.
  * It assigns a DerivativeParams object to _name_ template variable.
  *
  * @param array $params
  *    - name (required)
  *    - type (optional)
  *    - width (required if type is empty)
  *    - height (required if type is empty)
  *    - crop (optional, used if type is empty)
  *    - min_height (optional, used with crop)
  *    - min_height (optional, used with crop)
  * @param Smarty $smarty
  */
 function func_define_derivative($params, $smarty)
 {
     !empty($params['name']) or fatal_error('define_derivative missing name');
     if (isset($params['type'])) {
         $derivative = ImageStdParams::get_by_type($params['type']);
         $smarty->assign($params['name'], $derivative);
         return;
     }
     !empty($params['width']) or fatal_error('define_derivative missing width');
     !empty($params['height']) or fatal_error('define_derivative missing height');
     $w = intval($params['width']);
     $h = intval($params['height']);
     $crop = 0;
     $minw = null;
     $minh = null;
     if (isset($params['crop'])) {
         if (is_bool($params['crop'])) {
             $crop = $params['crop'] ? 1 : 0;
         } else {
             $crop = round($params['crop'] / 100, 2);
         }
         if ($crop) {
             $minw = empty($params['min_width']) ? $w : intval($params['min_width']);
             $minw <= $w or fatal_error('define_derivative invalid min_width');
             $minh = empty($params['min_height']) ? $h : intval($params['min_height']);
             $minh <= $h or fatal_error('define_derivative invalid min_height');
         }
     }
     $smarty->assign($params['name'], ImageStdParams::get_custom($w, $h, $crop, $minw, $minh));
 }
Пример #5
0
function Fotorama_end_picture()
{
    global $template, $conf, $user, $page;
    if (Fotorama_is_replace_picture()) {
        $url_up = duplicate_index_url(array('start' => floor($page['current_rank'] / $page['nb_image_page']) * $page['nb_image_page']), array('start'));
        //slideshow end
        $template->assign(array('U_SLIDESHOW_STOP' => $url_up));
        $template->assign('replace_picture', true);
    }
    if (!$page['slideshow']) {
        return;
    }
    load_language('plugin.lang', FOTORAMA_PATH);
    $split_limit = 400;
    if ('mobile' == get_device()) {
        $split_limit /= 2;
    }
    $view_offset = null;
    if (count($page['items']) >= 1.2 * $split_limit) {
        $first = $split_limit * 0.2;
        $last = $split_limit - $first;
        $first = $page['current_rank'] - $first;
        if ($first < 0) {
            $first += count($page['items']);
        }
        $last = $page['current_rank'] + $last;
        if ($last >= count($page['items'])) {
            $last -= count($page['items']);
        }
        if ($first < $last) {
            $selection = array_slice($page['items'], $first, $last - $first);
            $view_borders = array(0, count($selection) - 1);
            $view_offset = array('from' => 0, 'offset' => $first);
        } else {
            $selection = array_slice($page['items'], 0, $last);
            $view_borders = array(count($selection), count($selection) - 1);
            $view_offset = array('from' => count($selection), 'offset' => $first - count($selection));
            $selection = array_merge($selection, array_slice($page['items'], $first));
        }
    } else {
        $selection = $page['items'];
        $view_borders = null;
    }
    $query = '
  SELECT *
    FROM ' . IMAGES_TABLE . '
    WHERE id IN (' . implode(',', $selection) . ')
    ORDER BY FIELD(id, ' . implode(',', $selection) . ')
  ;';
    $result = pwg_query($query);
    $current = $template->get_template_vars('current');
    if (isset($current['selected_derivative'])) {
        $type = $current['selected_derivative']->get_type();
    }
    $defined = ImageStdParams::get_defined_type_map();
    if (!isset($type) or !isset($defined[$type])) {
        $type = pwg_get_session_var('picture_deriv', $conf['derivative_default_size']);
    }
    $skip = -1;
    $big_type = $type;
    $next_type = $type;
    foreach (ImageStdParams::get_defined_type_map() as $def_type => $params) {
        if ($def_type == $type) {
            $skip = 2;
        }
        if ($skip >= 0) {
            $big_type = $def_type;
        }
        if ($skip >= 1 and $conf['Fotorama']['resize']) {
            $next_type = $def_type;
        }
        if ($skip == 0) {
            break;
        }
        $skip = $skip - 1;
    }
    $type = $next_type;
    // +1 size for inpage slideshow
    if ($conf['Fotorama']['only_fullscreen']) {
        $type = $big_type;
    }
    $type_params = ImageStdParams::get_by_type($type);
    $big_type_params = ImageStdParams::get_by_type($big_type);
    if ($conf['Fotorama']['nav'] == 'thumbs' or $conf['Fotorama']['fullscreen_nav'] == 'thumbs') {
        $has_thumbs = true;
    } else {
        $has_thumbs = false;
    }
    if ($has_thumbs) {
        if ($conf['Fotorama']['square_thumb']) {
            $thumb_params = ImageStdParams::get_custom($conf['Fotorama']['thumbheight'], $conf['Fotorama']['thumbheight'], 1, $conf['Fotorama']['thumbheight'], $conf['Fotorama']['thumbheight']);
        } else {
            $thumb_params = ImageStdParams::get_custom(9999, $conf['Fotorama']['thumbheight']);
        }
    }
    $picture = array();
    while ($row = pwg_db_fetch_assoc($result)) {
        $row['src_image'] = new SrcImage($row);
        $row['derivative'] = new DerivativeImage($type_params, $row['src_image']);
        $row['derivative_big'] = new DerivativeImage($big_type_params, $row['src_image']);
        if ($has_thumbs) {
            $row['derivative_thumb'] = new DerivativeImage($thumb_params, $row['src_image']);
        }
        $row['url'] = duplicate_picture_url(array('image_id' => $row['id'], 'image_file' => $row['file']), array('start'));
        $row['TITLE'] = render_element_name($row);
        $picture[] = $row;
    }
    $picture = trigger_change('fotorama_items', $picture, $selection);
    $template->assign(array('TOTAL_ITEMS' => count($page['items']), 'view_borders' => $view_borders, 'view_offset' => $view_offset, 'current_rank' => array_search($page['image_id'], $selection)));
    $template->assign('item_height', ImageStdParams::get_by_type($type)->max_height());
    $template->assign('items', $picture);
    $template->assign(array('Fotorama' => $conf['Fotorama']));
    $template->assign('Fotorama_has_thumbs', $has_thumbs);
    if (is_file('./themes/' . $user['theme'] . '/template/fotorama.tpl')) {
        $template->set_filenames(array('slideshow' => realpath('./themes/' . $user['theme'] . '/template/fotorama.tpl')));
    } else {
        $template->set_filenames(array('slideshow' => realpath(FOTORAMA_PATH . 'template/fotorama.tpl')));
    }
    $template->assign('FOTORAMA_CONTENT_PATH', realpath(FOTORAMA_PATH . 'template/fotorama-content.tpl'));
}
Пример #6
0
 $qlimit = min(5000, ceil(max($image_count / 500, $max_urls)));
 $query_model = 'SELECT * FROM ' . IMAGES_TABLE . ' WHERE id < start_id ORDER BY id DESC LIMIT ' . $qlimit;
 $urls = array();
 do {
     $result = pwg_query(str_replace('start_id', $start_id, $query_model));
     $is_last = pwg_db_num_rows($result) < $qlimit;
     while ($row = pwg_db_fetch_assoc($result)) {
         $start_id = $row['id'];
         $src_image = new SrcImage($row);
         if ($src_image->is_mimetype()) {
             continue;
         }
         if ($params['method'] == "slide" || $params['method'] == "square") {
             $derivative = new DerivativeImage(ImageStdParams::get_custom($params['height'], 9999), $src_image);
         } else {
             $derivative = new DerivativeImage(ImageStdParams::get_custom(9999, $params['height']), $src_image);
         }
         if (@filemtime($derivative->get_path()) === false) {
             $urls[] = $derivative->get_url() . $uid;
         }
         if (count($urls) >= $max_urls && !$is_last) {
             break;
         }
     }
     if ($is_last) {
         $start_id = 0;
     }
 } while (count($urls) < $max_urls && $start_id);
 $ret = array();
 if ($start_id) {
     $ret['next_page'] = $start_id;
Пример #7
0
function modus_index_category_thumbnails($items)
{
    global $page, $template, $conf;
    if ('categories' != $page['section'] || !($wh = @$conf['modus_theme']['album_thumb_size'])) {
        return $items;
    }
    $template->assign('album_thumb_size', $wh);
    $def_params = ImageStdParams::get_custom($wh, $wh, 1, $wh, $wh);
    foreach (ImageStdParams::get_defined_type_map() as $params) {
        if ($params->max_height() == $wh) {
            $alt_params = $params;
        }
    }
    foreach ($items as &$item) {
        $src_image = $item['representative']['src_image'];
        $src_size = $src_image->get_size();
        $deriv = null;
        if (isset($alt_params) && $src_size[0] >= $src_size[1]) {
            $dsize = $alt_params->compute_final_size($src_size);
            if ($dsize[0] >= $wh && $dsize[1] >= $wh) {
                $deriv = new DerivativeImage($alt_params, $src_image);
                $rect = new ImageRect($dsize);
                $rect->crop_h($dsize[0] - $wh, $item['representative']['coi']);
                $rect->crop_v($dsize[1] - $wh, $item['representative']['coi']);
                $l = -$rect->l;
                $t = -$rect->t;
            }
        }
        if (!isset($deriv)) {
            $deriv = new DerivativeImage($def_params, $src_image);
            $dsize = $deriv->get_size();
            $l = intval($wh - $dsize[0]) / 2;
            $t = intval($wh - $dsize[1]) / 2;
        }
        $item['modus_deriv'] = $deriv;
        if (!empty($item['icon_ts'])) {
            $item['icon_ts']['TITLE'] = time_since($item['max_date_last'], 'month');
        }
        $styles = array();
        if ($l < -1 || $l > 1) {
            $styles[] = 'left:' . 100 * $l / $wh . '%';
        }
        if ($t < -1 || $t > 1) {
            $styles[] = 'top:' . $t . 'px';
        }
        if (count($styles)) {
            $styles = ' style=' . implode(';', $styles);
        } else {
            $styles = '';
        }
        $item['MODUS_STYLE'] = $styles;
    }
    return $items;
}
Пример #8
0
function GDThumb_process_category($tpl_vars)
{
    global $template, $conf;
    $confTemp = $conf['gdThumb'];
    $confTemp['GDTHUMB_ROOT'] = 'plugins/' . GDTHUMB_ID;
    $confTemp['big_thumb_noinpw'] = isset($confTemp['big_thumb_noinpw']) ? 1 : 0;
    $template->set_filename('index_category_thumbnails', dirname(__FILE__) . '/template/gdthumb_cat.tpl');
    $template->assign('GDThumb', $confTemp);
    if ($confTemp['method'] == "slide" || $confTemp['method'] == "square") {
        $template->assign('GDThumb_derivative_params', ImageStdParams::get_custom($confTemp['height'], 9999));
    } else {
        $template->assign('GDThumb_derivative_params', ImageStdParams::get_custom(9999, $confTemp['height']));
    }
    if ($confTemp['big_thumb'] and !empty($tpl_vars[0])) {
        $id = $tpl_vars[0]["representative_picture_id"];
        if ($id && ($rep = $tpl_vars[0]["representative"])) {
            if ($confTemp['method'] == "slide" || $confTemp['method'] == "square") {
                $derivative_params = ImageStdParams::get_custom(2 * $confTemp['height'] + $confTemp['margin'], 9999);
            } else {
                $derivative_params = ImageStdParams::get_custom(9999, 2 * $confTemp['height'] + $confTemp['margin']);
            }
            $template->assign('GDThumb_big', new DerivativeImage($derivative_params, $rep['src_image']));
        }
    }
    return $tpl_vars;
}