Exemple #1
0
/**
 * API method
 * Returns a list of missing derivatives (not generated yet)
 * @param mixed[] $params
 *    @option string types (optional)
 *    @option int[] ids
 *    @option int max_urls
 *    @option int prev_page (optional)
 */
function ws_getMissingDerivatives($params, &$service)
{
    global $conf;
    if (empty($params['types'])) {
        $types = array_keys(ImageStdParams::get_defined_type_map());
    } else {
        $types = array_intersect(array_keys(ImageStdParams::get_defined_type_map()), $params['types']);
        if (count($types) == 0) {
            return new PwgError(WS_ERR_INVALID_PARAM, "Invalid types");
        }
    }
    $max_urls = $params['max_urls'];
    $query = 'SELECT MAX(id)+1, COUNT(*) FROM ' . IMAGES_TABLE . ';';
    list($max_id, $image_count) = pwg_db_fetch_row(pwg_query($query));
    if (0 == $image_count) {
        return array();
    }
    $start_id = $params['prev_page'];
    if ($start_id <= 0) {
        $start_id = $max_id;
    }
    $uid = '&b=' . time();
    $conf['question_mark_in_urls'] = $conf['php_extension_in_urls'] = true;
    $conf['derivative_url_style'] = 2;
    //script
    $qlimit = min(5000, ceil(max($image_count / 500, $max_urls / count($types))));
    $where_clauses = ws_std_image_sql_filter($params, '');
    $where_clauses[] = 'id<start_id';
    if (!empty($params['ids'])) {
        $where_clauses[] = 'id IN (' . implode(',', $params['ids']) . ')';
    }
    $query_model = '
SELECT id, path, representative_ext, width, height, rotation
  FROM ' . IMAGES_TABLE . '
  WHERE ' . implode(' AND ', $where_clauses) . '
  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;
            }
            foreach ($types as $type) {
                $derivative = new DerivativeImage($type, $src_image);
                if ($type != $derivative->get_type()) {
                    continue;
                }
                if (@filemtime($derivative->get_path()) === false) {
                    $urls[] = $derivative->get_url() . $uid;
                }
            }
            if (count($urls) >= $max_urls and !$is_last) {
                break;
            }
        }
        if ($is_last) {
            $start_id = 0;
        }
    } while (count($urls) < $max_urls and $start_id);
    $ret = array();
    if ($start_id) {
        $ret['next_page'] = $start_id;
    }
    $ret['urls'] = $urls;
    return $ret;
}
Exemple #2
0
 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;
   }
   $ret['urls'] = $urls;
   echo json_encode($ret);
Exemple #3
0
;';
$result = pwg_query($query);
if (pwg_db_num_rows($result) > 0) {
    // template thumbnail initialization
    $current_rank = 1;
    $derivativeParams = ImageStdParams::get_by_type(IMG_SQUARE);
    while ($row = pwg_db_fetch_assoc($result)) {
        $derivative = new DerivativeImage($derivativeParams, new SrcImage($row));
        if (!empty($row['name'])) {
            $thumbnail_name = $row['name'];
        } else {
            $file_wo_ext = get_filename_wo_extension($row['file']);
            $thumbnail_name = str_replace('_', ' ', $file_wo_ext);
        }
        $current_rank++;
        $template->append('thumbnails', array('ID' => $row['id'], 'NAME' => $thumbnail_name, 'TN_SRC' => $derivative->get_url(), 'RANK' => $current_rank * 10, 'SIZE' => $derivative->get_size()));
    }
}
// image order management
$sort_fields = array('' => '', 'file ASC' => l10n('File name, A &rarr; Z'), 'file DESC' => l10n('File name, Z &rarr; A'), 'name ASC' => l10n('Photo title, A &rarr; Z'), 'name DESC' => l10n('Photo title, Z &rarr; A'), 'date_creation DESC' => l10n('Date created, new &rarr; old'), 'date_creation ASC' => l10n('Date created, old &rarr; new'), 'date_available DESC' => l10n('Date posted, new &rarr; old'), 'date_available ASC' => l10n('Date posted, old &rarr; new'), 'rating_score DESC' => l10n('Rating score, high &rarr; low'), 'rating_score ASC' => l10n('Rating score, low &rarr; high'), 'hit DESC' => l10n('Visits, high &rarr; low'), 'hit ASC' => l10n('Visits, low &rarr; high'), 'id ASC' => l10n('Numeric identifier, 1 &rarr; 9'), 'id DESC' => l10n('Numeric identifier, 9 &rarr; 1'), 'rank ASC' => l10n('Manual sort order'));
$template->assign('image_order_options', $sort_fields);
$image_order = explode(',', $category['image_order']);
for ($i = 0; $i < 3; $i++) {
    if (isset($image_order[$i])) {
        $template->append('image_order', $image_order[$i]);
    } else {
        $template->append('image_order', '');
    }
}
$template->assign('image_order_choice', $image_order_choice);
// +-----------------------------------------------------------------------+
Exemple #4
0
$query = 'SELECT * FROM ' . IMAGES_TABLE . ' WHERE id=' . $_GET['image_id'];
$row = pwg_db_fetch_assoc(pwg_query($query));
if (isset($_POST['submit'])) {
    foreach (ImageStdParams::get_defined_type_map() as $params) {
        if ($params->sizing->max_crop != 0) {
            delete_element_derivatives($row, $params->type);
        }
    }
    delete_element_derivatives($row, IMG_CUSTOM);
    $uid = '&b=' . time();
    $conf['question_mark_in_urls'] = $conf['php_extension_in_urls'] = true;
    if ($conf['derivative_url_style'] == 1) {
        $conf['derivative_url_style'] = 0;
        //auto
    }
} else {
    $uid = '';
}
$tpl_var = array('TITLE' => render_element_name($row), 'ALT' => $row['file'], 'U_IMG' => DerivativeImage::url(IMG_LARGE, $row));
if (!empty($row['coi'])) {
    $tpl_var['coi'] = array('l' => char_to_fraction($row['coi'][0]), 't' => char_to_fraction($row['coi'][1]), 'r' => char_to_fraction($row['coi'][2]), 'b' => char_to_fraction($row['coi'][3]));
}
foreach (ImageStdParams::get_defined_type_map() as $params) {
    if ($params->sizing->max_crop != 0) {
        $derivative = new DerivativeImage($params, new SrcImage($row));
        $template->append('cropped_derivatives', array('U_IMG' => $derivative->get_url() . $uid, 'HTM_SIZE' => $derivative->get_size_htm()));
    }
}
$template->assign($tpl_var);
$template->set_filename('picture_coi', 'picture_coi.tpl');
$template->assign_var_from_handle('ADMIN_CONTENT', 'picture_coi');
Exemple #5
0
function modus_thumbs($x, $smarty)
{
    global $template, $page, $conf;
    $default_params = $smarty->getTemplateVars('derivative_params');
    $row_height = $default_params->max_height();
    $device = get_device();
    $container_margin = 5;
    if ('mobile' == $device) {
        $horizontal_margin = floor(0.01 * $row_height);
        $container_margin = 0;
    } elseif ('tablet' == $device) {
        $horizontal_margin = floor(0.015 * $row_height);
    } else {
        $horizontal_margin = floor(0.02 * $row_height);
    }
    $vertical_margin = $horizontal_margin + 1;
    $candidates = array($default_params);
    foreach (ImageStdParams::get_defined_type_map() as $params) {
        if ($params->max_height() > $row_height && $params->sizing->max_crop == $default_params->sizing->max_crop) {
            $candidates[] = $params;
            if (count($candidates) == 3) {
                break;
            }
        }
    }
    $do_over = 'desktop' == $device;
    $new_icon = " <span class=albSymbol title=\"" . l10n('posted on %s') . "\">" . MODUS_STR_RECENT . '</span>';
    foreach ($smarty->getTemplateVars('thumbnails') as $item) {
        $src_image = $item['src_image'];
        $new = !empty($item['icon_ts']) ? sprintf($new_icon, format_date($item['date_available'])) : '';
        $idx = 0;
        do {
            $cparams = $candidates[$idx];
            $c = new DerivativeImage($cparams, $src_image);
            $csize = $c->get_size();
            $idx++;
        } while ($csize[1] < $row_height - 2 && $idx < count($candidates));
        $a_style = '';
        if ($csize[1] < $row_height) {
            $a_style = ' style="top:' . floor(($row_height - $csize[1]) / 2) . 'px"';
        } elseif ($csize[1] > $row_height) {
            $csize = $c->get_scaled_size(9999, $row_height);
        }
        if ($do_over) {
            ?>
<li style=width:<?php 
            echo $csize[0];
            ?>
px;height:<?php 
            echo $row_height;
            ?>
px><a href="<?php 
            echo $item['URL'];
            ?>
"<?php 
            echo $a_style;
            ?>
><img src="<?php 
            echo $c->get_url();
            ?>
" width=<?php 
            echo $csize[0];
            ?>
 height=<?php 
            echo $csize[1];
            ?>
 alt="<?php 
            echo $item['TN_ALT'];
            ?>
"></a><div class=overDesc><?php 
            echo $item['NAME'];
            echo $new;
            ?>
</div></li>
<?php 
        } else {
            ?>
<li style=width:<?php 
            echo $csize[0];
            ?>
px;height:<?php 
            echo $row_height;
            ?>
px><a href="<?php 
            echo $item['URL'];
            ?>
"<?php 
            echo $a_style;
            ?>
><img src="<?php 
            echo $c->get_url();
            ?>
" width=<?php 
            echo $csize[0];
            ?>
 height=<?php 
            echo $csize[1];
            ?>
 alt="<?php 
            echo $item['TN_ALT'];
            ?>
"></a></li>
<?php 
        }
    }
    $template->block_html_style(null, '#thumbnails{text-align:justify;overflow:hidden;margin-left:' . ($container_margin - $horizontal_margin) . 'px;margin-right:' . $container_margin . 'px}
#thumbnails>li{float:left;overflow:hidden;position:relative;margin-bottom:' . $vertical_margin . 'px;margin-left:' . $horizontal_margin . 'px}#thumbnails>li>a{position:absolute;border:0}');
    $template->block_footer_script(null, 'rvgtProcessor=new RVGThumbs({hMargin:' . $horizontal_margin . ',rowHeight:' . $row_height . '});');
    $my_base_name = basename(dirname(__FILE__));
    // not async to avoid visible flickering reflow
    $template->scriptLoader->add('modus.arange', 1, array('jquery'), 'themes/' . $my_base_name . "/js/thumb.arrange.min.js", 0);
}
function pshare_section_init()
{
    global $tokens, $page, $conf, $user, $template;
    if ($tokens[0] == 'pshare') {
        $page['section'] = 'pshare';
        $page['title'] = l10n('Shared Picture');
        if (!isset($tokens[1])) {
            die("missing key");
        }
        if (!preg_match(PSHARE_KEY_PATTERN, $tokens[1])) {
            die("invalid key");
        }
        $page['pshare_key'] = $tokens[1];
        $query = '
SELECT
    *,
    NOW() AS dbnow
  FROM ' . PSHARE_KEYS_TABLE . '
  WHERE uuid = \'' . $page['pshare_key'] . '\'
;';
        $shares = query2array($query);
        if (count($shares) == 0) {
            die('unknown key');
        }
        $share = $shares[0];
        pshare_log($share['pshare_key_id'], 'visit');
        // is the key still valid?
        if (strtotime($share['expire_on']) < strtotime($share['dbnow'])) {
            die('expired key');
        }
        // if the user is permitted for this photo, let's redirect to
        // picture.php (with full details and actions)
        if (!is_a_guest() and pshare_is_photo_visible($share['image_id'])) {
            // find the first reachable category linked to the photo
            $query = '
SELECT category_id
  FROM ' . IMAGE_CATEGORY_TABLE . '
  WHERE image_id = ' . $share['image_id'] . '
;';
            $authorizeds = array_diff(array_from_query($query, 'category_id'), explode(',', calculate_permissions($user['id'], $user['status'])));
            foreach ($authorizeds as $category_id) {
                $url = make_picture_url(array('image_id' => $share['image_id'], 'category' => get_cat_info($category_id)));
                if (function_exists('Fotorama_is_replace_picture') and Fotorama_is_replace_picture()) {
                    $url .= '&slidestop';
                }
                redirect($url);
            }
            redirect(make_picture_url(array('image_id' => $share['image_id'])));
        }
        $query = '
SELECT *
  FROM ' . IMAGES_TABLE . '
  WHERE id = ' . $share['image_id'] . '
;';
        $rows = query2array($query);
        $image = $rows[0];
        $src_image = new SrcImage($image);
        if (isset($tokens[2]) && 'download' == $tokens[2]) {
            $format_id = null;
            if (isset($tokens[3]) && preg_match('/^f(\\d+)$/', $tokens[3], $matches)) {
                $format_id = $matches[1];
                $query = '
SELECT
    *
  FROM ' . IMAGE_FORMAT_TABLE . '
  WHERE format_id = ' . $format_id . '
    AND image_id = ' . $image['id'] . '
;';
                $formats = query2array($query);
                if (count($formats) == 0) {
                    do_error(400, 'Invalid request - format');
                }
                $format = $formats[0];
                $file = original_to_format(get_element_path($image), $format['ext']);
                $image['file'] = get_filename_wo_extension($image['file']) . '.' . $format['ext'];
            } else {
                $file = $image['path'];
            }
            $gmt_mtime = gmdate('D, d M Y H:i:s', filemtime($file)) . ' GMT';
            $http_headers = array('Content-Length: ' . @filesize($file), 'Last-Modified: ' . $gmt_mtime, 'Content-Type: ' . mime_content_type($file), 'Content-Disposition: attachment; filename="' . $image['file'] . '";', 'Content-Transfer-Encoding: binary');
            foreach ($http_headers as $header) {
                header($header);
            }
            readfile($file);
            pshare_log($share['pshare_key_id'], 'download', $format_id);
            exit;
        }
        $template->set_filename('shared_picture', realpath(PSHARE_PATH . 'template/shared_picture.tpl'));
        $derivative = new DerivativeImage(ImageStdParams::get_by_type(IMG_MEDIUM), $src_image);
        $derivative_size = $derivative->get_size();
        // a random string to avoid browser cache
        $rand = '&amp;download=' . substr(md5(time()), 0, 6);
        $template->assign(array('SRC' => $derivative->get_url(), 'IMG_WIDTH' => $derivative_size[0], 'IMG_HEIGHT' => $derivative_size[1], 'DOWNLOAD_URL' => duplicate_index_url() . '/' . $page['pshare_key'] . '/download' . $rand));
        // formats
        if (defined('IMAGE_FORMAT_TABLE')) {
            $query = '
SELECT *
  FROM ' . IMAGE_FORMAT_TABLE . '
  WHERE image_id = ' . $share['image_id'] . '
;';
            $formats = query2array($query);
            if (!empty($formats)) {
                foreach ($formats as &$format) {
                    $format['download_url'] = duplicate_index_url() . '/' . $page['pshare_key'] . '/download';
                    $format['download_url'] .= '/f' . $format['format_id'] . $rand;
                    $format['filesize'] = sprintf('%.1fMB', $format['filesize'] / 1024);
                }
            }
            $template->assign('formats', $formats);
        }
        $template->parse('shared_picture');
        $template->p();
        exit;
    }
}