示例#1
0
        $rating['first_date'] = $row['date'];
    }
    $rating['rates'][$row['rate']][] = array('id' => $row['element_id'], 'date' => $row['date']);
    $image_ids[$row['element_id']] = 1;
    unset($rating);
}
// get image tn urls
$image_urls = array();
if (count($image_ids) > 0) {
    $query = 'SELECT id, name, file, path, representative_ext, level
  FROM ' . IMAGES_TABLE . '
  WHERE id IN (' . implode(',', array_keys($image_ids)) . ')';
    $result = pwg_query($query);
    $params = ImageStdParams::get_by_type(IMG_SQUARE);
    while ($row = pwg_db_fetch_assoc($result)) {
        $image_urls[$row['id']] = array('tn' => DerivativeImage::url($params, $row), 'page' => make_picture_url(array('image_id' => $row['id'], 'image_file' => $row['file'])));
    }
}
//all image averages
$query = 'SELECT element_id,
    AVG(rate) AS avg
  FROM ' . RATE_TABLE . '
  GROUP BY element_id';
$all_img_sum = array();
$result = pwg_query($query);
while ($row = pwg_db_fetch_assoc($result)) {
    $all_img_sum[(int) $row['element_id']] = array('avg' => (double) $row['avg']);
}
$query = 'SELECT id
  FROM ' . IMAGES_TABLE . '
  ORDER by rating_score DESC
示例#2
0
  WHERE id = ' . $_GET['image_id'] . '
;';
$row = pwg_db_fetch_assoc(pwg_query($query));
$storage_category_id = null;
if (!empty($row['storage_category_id'])) {
    $storage_category_id = $row['storage_category_id'];
}
$image_file = $row['file'];
// +-----------------------------------------------------------------------+
// |                             template init                             |
// +-----------------------------------------------------------------------+
$template->set_filenames(array('picture_modify' => 'picture_modify.tpl'));
$admin_url_start = $admin_photo_base_url . '-properties';
$admin_url_start .= isset($_GET['cat_id']) ? '&cat_id=' . $_GET['cat_id'] : '';
$src_image = new SrcImage($row);
$template->assign(array('tag_selection' => $tag_selection, 'U_SYNC' => $admin_url_start . '&sync_metadata=1', 'U_DELETE' => $admin_url_start . '&delete=1&pwg_token=' . get_pwg_token(), 'PATH' => $row['path'], 'TN_SRC' => DerivativeImage::url(IMG_THUMB, $src_image), 'FILE_SRC' => DerivativeImage::url(IMG_LARGE, $src_image), 'NAME' => isset($_POST['name']) ? stripslashes($_POST['name']) : @$row['name'], 'TITLE' => render_element_name($row), 'DIMENSIONS' => @$row['width'] . ' * ' . @$row['height'], 'FILESIZE' => @$row['filesize'] . ' KB', 'REGISTRATION_DATE' => format_date($row['date_available']), 'AUTHOR' => htmlspecialchars(isset($_POST['author']) ? stripslashes($_POST['author']) : @$row['author']), 'DATE_CREATION' => $row['date_creation'], 'DESCRIPTION' => htmlspecialchars(isset($_POST['description']) ? stripslashes($_POST['description']) : @$row['comment']), 'F_ACTION' => get_root_url() . 'admin.php' . get_query_string_diff(array('sync_metadata'))));
$added_by = 'N/A';
$query = '
SELECT ' . $conf['user_fields']['username'] . ' AS username
  FROM ' . USERS_TABLE . '
  WHERE ' . $conf['user_fields']['id'] . ' = ' . $row['added_by'] . '
;';
$result = pwg_query($query);
while ($user_row = pwg_db_fetch_assoc($result)) {
    $row['added_by'] = $user_row['username'];
}
$intro_vars = array('file' => l10n('Original file : %s', $row['file']), 'add_date' => l10n('Posted %s on %s', time_since($row['date_available'], 'year'), format_date($row['date_available'], array('day', 'month', 'year'))), 'added_by' => l10n('Added by %s', $row['added_by']), 'size' => $row['width'] . '×' . $row['height'] . ' pixels, ' . sprintf('%.2f', $row['filesize'] / 1024) . 'MB', 'stats' => l10n('Visited %d times', $row['hit']), 'id' => l10n('Numeric identifier : %d', $row['id']));
if ($conf['rate'] and !empty($row['rating_score'])) {
    $query = '
SELECT
    COUNT(*)
示例#3
0
// info by email to an access granted group of category informations
if (isset($_POST['submitEmail'])) {
    set_make_full_url();
    /* TODO: if $category['representative_picture_id']
       is empty find child representative_picture_id */
    if (!empty($category['representative_picture_id'])) {
        $img = array();
        $query = '
SELECT id, file, path, representative_ext
  FROM ' . IMAGES_TABLE . '
  WHERE id = ' . $category['representative_picture_id'] . '
;';
        $result = pwg_query($query);
        if (pwg_db_num_rows($result) > 0) {
            $element = pwg_db_fetch_assoc($result);
            $img = array('link' => make_picture_url(array('image_id' => $element['id'], 'image_file' => $element['file'], 'category' => $category)), 'src' => DerivativeImage::url(IMG_THUMB, $element));
        }
    }
    $args = array('subject' => l10n('[%s] Visit album %s', $conf['gallery_title'], trigger_change('render_category_name', $category['name'], 'admin_cat_list')));
    $tpl = array('filename' => 'cat_group_info', 'assign' => array('IMG' => $img, 'CAT_NAME' => trigger_change('render_category_name', $category['name'], 'admin_cat_list'), 'LINK' => make_index_url(array('category' => array('id' => $category['id'], 'name' => trigger_change('render_category_name', $category['name'], 'admin_cat_list'), 'permalink' => $category['permalink']))), 'CPL_CONTENT' => empty($_POST['mail_content']) ? '' : stripslashes($_POST['mail_content'])));
    if ('users' == $_POST['who'] and isset($_POST['users']) and count($_POST['users']) > 0) {
        check_input_parameter('users', $_POST, true, PATTERN_ID);
        // TODO code very similar to function pwg_mail_group. We'd better create
        // a function pwg_mail_users that could be called from here and from
        // pwg_mail_group
        // TODO to make checks even better, we should check that theses users
        // have access to this album. No real privacy issue here, even if we
        // send the email to a user without permission.
        $query = '
SELECT
    ui.user_id,
示例#4
0
 /**
  * @param string $type
  * @param array $img
  * @return string
  */
 function derivative_url($type, $img)
 {
     return DerivativeImage::url($type, $img);
 }
示例#5
0
    }
    $query .= '
  ' . $conf['order_by'] . '
  LIMIT ' . $page['nb_images'] . ' OFFSET ' . $page['start'] . '
;';
    $result = pwg_query($query);
    while ($row = pwg_db_fetch_assoc($result)) {
        $element_ids[] = $row['id'];
        $src_image = new SrcImage($row);
        $query = '
SELECT
    id,
    name
  FROM ' . IMAGE_TAG_TABLE . ' AS it
    JOIN ' . TAGS_TABLE . ' AS t ON t.id = it.tag_id
  WHERE image_id = ' . $row['id'] . '
;';
        $tag_selection = get_taglist($query);
        $legend = render_element_name($row);
        if ($legend != get_name_from_file($row['file'])) {
            $legend .= ' (' . $row['file'] . ')';
        }
        $template->append('elements', array_merge($row, array('ID' => $row['id'], 'TN_SRC' => DerivativeImage::url(IMG_THUMB, $src_image), 'FILE_SRC' => DerivativeImage::url(IMG_LARGE, $src_image), 'LEGEND' => $legend, 'U_EDIT' => get_root_url() . 'admin.php?page=photo-' . $row['id'], 'NAME' => htmlspecialchars(@$row['name']), 'AUTHOR' => htmlspecialchars(@$row['author']), 'LEVEL' => !empty($row['level']) ? $row['level'] : '0', 'DESCRIPTION' => htmlspecialchars(@$row['comment']), 'DATE_CREATION' => $row['date_creation'], 'TAGS' => $tag_selection)));
    }
    $template->assign(array('ELEMENT_IDS' => implode(',', $element_ids), 'CACHE_KEYS' => get_admin_client_cache_keys(array('tags'))));
}
trigger_notify('loc_end_element_set_unit');
// +-----------------------------------------------------------------------+
// |                           sending html code                           |
// +-----------------------------------------------------------------------+
$template->assign_var_from_handle('ADMIN_CONTENT', 'batch_manager_unit');
示例#6
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');
        $query .= '
    JOIN ' . IMAGE_CATEGORY_TABLE . ' ON id = image_id';
    }
    $query .= '
  WHERE id IN (' . implode(',', $page['cat_elements_id']) . ')';
    if ($is_category) {
        $query .= '
    AND category_id = ' . $_SESSION['bulk_manager_filter']['category'];
    }
    $query .= '
  ' . $conf['order_by'] . '
  LIMIT ' . $page['nb_images'] . ' OFFSET ' . $page['start'] . '
;';
    $result = pwg_query($query);
    $thumb_params = ImageStdParams::get_by_type(IMG_THUMB);
    // template thumbnail initialization
    while ($row = pwg_db_fetch_assoc($result)) {
        $nb_thumbs_page++;
        $src_image = new SrcImage($row);
        $ttitle = render_element_name($row);
        if ($ttitle != get_name_from_file($row['file'])) {
            $ttitle .= ' (' . $row['file'] . ')';
        }
        $template->append('thumbnails', array_merge($row, array('thumb' => new DerivativeImage($thumb_params, $src_image), 'TITLE' => $ttitle, 'FILE_SRC' => DerivativeImage::url(IMG_LARGE, $src_image), 'U_EDIT' => get_root_url() . 'admin.php?page=photo-' . $row['id'])));
    }
    $template->assign('thumb_params', $thumb_params);
}
$template->assign(array('nb_thumbs_page' => $nb_thumbs_page, 'nb_thumbs_set' => count($page['cat_elements_id']), 'CACHE_KEYS' => get_admin_client_cache_keys(array('tags', 'categories'))));
trigger_notify('loc_end_element_set_global');
//----------------------------------------------------------- sending html code
$template->assign_var_from_handle('ADMIN_CONTENT', 'batch_manager_global');
示例#8
0
// +-----------------------------------------------------------------------+
// info by email to an access granted group of category informations
if (isset($_POST['submitEmail']) and !empty($_POST['group'])) {
    set_make_full_url();
    /* TODO: if $category['representative_picture_id']
       is empty find child representative_picture_id */
    if (!empty($category['representative_picture_id'])) {
        $query = '
SELECT id, file, path, representative_ext
  FROM ' . IMAGES_TABLE . '
  WHERE id = ' . $category['representative_picture_id'] . '
;';
        $result = pwg_query($query);
        if (pwg_db_num_rows($result) > 0) {
            $element = pwg_db_fetch_assoc($result);
            $img_url = '<a href="' . make_picture_url(array('image_id' => $element['id'], 'image_file' => $element['file'], 'category' => $category)) . '" class="thumblnk"><img src="' . DerivativeImage::url(IMG_THUMB, $element) . '"></a>';
        }
    }
    if (!isset($img_url)) {
        $img_url = '';
    }
    pwg_mail_group($_POST['group'], array('subject' => l10n('[%s] Visit album %s', $conf['gallery_title'], trigger_change('render_category_name', $category['name'], 'admin_cat_list'))), array('filename' => 'cat_group_info', 'assign' => array('IMG_URL' => $img_url, 'CAT_NAME' => trigger_change('render_category_name', $category['name'], 'admin_cat_list'), 'LINK' => make_index_url(array('category' => array('id' => $category['id'], 'name' => trigger_change('render_category_name', $category['name'], 'admin_cat_list'), 'permalink' => $category['permalink']))), 'CPL_CONTENT' => empty($_POST['mail_content']) ? '' : stripslashes($_POST['mail_content']))));
    unset_make_full_url();
    $query = '
SELECT
    name
  FROM ' . GROUPS_TABLE . '
  WHERE id = ' . $_POST['group'] . '
;';
    list($group_name) = pwg_db_fetch_row(pwg_query($query));
    $page['infos'][] = l10n('An information email was sent to group "%s"', $group_name);
示例#9
0
/**
 * API method
 * Returns a list of categories
 * @param mixed[] $params
 *    @option int cat_id (optional)
 *    @option bool recursive
 *    @option bool public
 *    @option bool tree_output
 *    @option bool fullname
 */
function ws_categories_getList($params, &$service)
{
    global $user, $conf;
    if (!in_array($params['thumbnail_size'], array_keys(ImageStdParams::get_defined_type_map()))) {
        return new PwgError(WS_ERR_INVALID_PARAM, "Invalid thumbnail_size");
    }
    $where = array('1=1');
    $join_type = 'INNER';
    $join_user = $user['id'];
    if (!$params['recursive']) {
        if ($params['cat_id'] > 0) {
            $where[] = '(
        id_uppercat = ' . (int) $params['cat_id'] . '
        OR id=' . (int) $params['cat_id'] . '
      )';
        } else {
            $where[] = 'id_uppercat IS NULL';
        }
    } else {
        if ($params['cat_id'] > 0) {
            $where[] = 'uppercats ' . DB_REGEX_OPERATOR . ' \'(^|,)' . (int) $params['cat_id'] . '(,|$)\'';
        }
    }
    if ($params['public']) {
        $where[] = 'status = "public"';
        $where[] = 'visible = "true"';
        $join_user = $conf['guest_id'];
    } else {
        if (is_admin()) {
            // in this very specific case, we don't want to hide empty
            // categories. Function calculate_permissions will only return
            // categories that are either locked or private and not permitted
            //
            // calculate_permissions does not consider empty categories as forbidden
            $forbidden_categories = calculate_permissions($user['id'], $user['status']);
            $where[] = 'id NOT IN (' . $forbidden_categories . ')';
            $join_type = 'LEFT';
        }
    }
    $query = '
SELECT
    id, name, comment, permalink,
    uppercats, global_rank, id_uppercat,
    nb_images, count_images AS total_nb_images,
    representative_picture_id, user_representative_picture_id, count_images, count_categories,
    date_last, max_date_last, count_categories AS nb_categories
  FROM ' . CATEGORIES_TABLE . '
    ' . $join_type . ' JOIN ' . USER_CACHE_CATEGORIES_TABLE . '
    ON id=cat_id AND user_id=' . $join_user . '
  WHERE ' . implode("\n    AND ", $where) . '
;';
    $result = pwg_query($query);
    // management of the album thumbnail -- starts here
    $image_ids = array();
    $categories = array();
    $user_representative_updates_for = array();
    // management of the album thumbnail -- stops here
    $cats = array();
    while ($row = pwg_db_fetch_assoc($result)) {
        $row['url'] = make_index_url(array('category' => $row));
        foreach (array('id', 'nb_images', 'total_nb_images', 'nb_categories') as $key) {
            $row[$key] = (int) $row[$key];
        }
        if ($params['fullname']) {
            $row['name'] = strip_tags(get_cat_display_name_cache($row['uppercats'], null));
        } else {
            $row['name'] = strip_tags(trigger_change('render_category_name', $row['name'], 'ws_categories_getList'));
        }
        $row['comment'] = strip_tags(trigger_change('render_category_description', $row['comment'], 'ws_categories_getList'));
        // management of the album thumbnail -- starts here
        //
        // on branch 2.3, the algorithm is duplicated from
        // include/category_cats, but we should use a common code for Piwigo 2.4
        //
        // warning : if the API method is called with $params['public'], the
        // album thumbnail may be not accurate. The thumbnail can be viewed by
        // the connected user, but maybe not by the guest. Changing the
        // filtering method would be too complicated for now. We will simply
        // avoid to persist the user_representative_picture_id in the database
        // if $params['public']
        if (!empty($row['user_representative_picture_id'])) {
            $image_id = $row['user_representative_picture_id'];
        } else {
            if (!empty($row['representative_picture_id'])) {
                // if a representative picture is set, it has priority
                $image_id = $row['representative_picture_id'];
            } else {
                if ($conf['allow_random_representative']) {
                    // searching a random representant among elements in sub-categories
                    $image_id = get_random_image_in_category($row);
                } else {
                    // searching a random representant among representant of sub-categories
                    if ($row['count_categories'] > 0 and $row['count_images'] > 0) {
                        $query = '
SELECT representative_picture_id
  FROM ' . CATEGORIES_TABLE . '
    INNER JOIN ' . USER_CACHE_CATEGORIES_TABLE . '
    ON id=cat_id AND user_id=' . $user['id'] . '
  WHERE uppercats LIKE \'' . $row['uppercats'] . ',%\'
    AND representative_picture_id IS NOT NULL
        ' . get_sql_condition_FandF(array('visible_categories' => 'id'), "\n  AND") . '
  ORDER BY ' . DB_RANDOM_FUNCTION . '()
  LIMIT 1
;';
                        $subresult = pwg_query($query);
                        if (pwg_db_num_rows($subresult) > 0) {
                            list($image_id) = pwg_db_fetch_row($subresult);
                        }
                    }
                }
            }
        }
        if (isset($image_id)) {
            if ($conf['representative_cache_on_subcats'] and $row['user_representative_picture_id'] != $image_id) {
                $user_representative_updates_for[$row['id']] = $image_id;
            }
            $row['representative_picture_id'] = $image_id;
            $image_ids[] = $image_id;
            $categories[] = $row;
        }
        unset($image_id);
        // management of the album thumbnail -- stops here
        $cats[] = $row;
    }
    usort($cats, 'global_rank_compare');
    // management of the album thumbnail -- starts here
    if (count($categories) > 0) {
        $thumbnail_src_of = array();
        $new_image_ids = array();
        $query = '
SELECT id, path, representative_ext, level
  FROM ' . IMAGES_TABLE . '
  WHERE id IN (' . implode(',', $image_ids) . ')
;';
        $result = pwg_query($query);
        while ($row = pwg_db_fetch_assoc($result)) {
            if ($row['level'] <= $user['level']) {
                $thumbnail_src_of[$row['id']] = DerivativeImage::url($params['thumbnail_size'], $row);
            } else {
                // problem: we must not display the thumbnail of a photo which has a
                // higher privacy level than user privacy level
                //
                // * what is the represented category?
                // * find a random photo matching user permissions
                // * register it at user_representative_picture_id
                // * set it as the representative_picture_id for the category
                foreach ($categories as &$category) {
                    if ($row['id'] == $category['representative_picture_id']) {
                        // searching a random representant among elements in sub-categories
                        $image_id = get_random_image_in_category($category);
                        if (isset($image_id) and !in_array($image_id, $image_ids)) {
                            $new_image_ids[] = $image_id;
                        }
                        if ($conf['representative_cache_on_level']) {
                            $user_representative_updates_for[$category['id']] = $image_id;
                        }
                        $category['representative_picture_id'] = $image_id;
                    }
                }
                unset($category);
            }
        }
        if (count($new_image_ids) > 0) {
            $query = '
SELECT id, path, representative_ext
  FROM ' . IMAGES_TABLE . '
  WHERE id IN (' . implode(',', $new_image_ids) . ')
;';
            $result = pwg_query($query);
            while ($row = pwg_db_fetch_assoc($result)) {
                $thumbnail_src_of[$row['id']] = DerivativeImage::url($params['thumbnail_size'], $row);
            }
        }
    }
    // compared to code in include/category_cats, we only persist the new
    // user_representative if we have used $user['id'] and not the guest id,
    // or else the real guest may see thumbnail that he should not
    if (!$params['public'] and count($user_representative_updates_for)) {
        $updates = array();
        foreach ($user_representative_updates_for as $cat_id => $image_id) {
            $updates[] = array('user_id' => $user['id'], 'cat_id' => $cat_id, 'user_representative_picture_id' => $image_id);
        }
        mass_updates(USER_CACHE_CATEGORIES_TABLE, array('primary' => array('user_id', 'cat_id'), 'update' => array('user_representative_picture_id')), $updates);
    }
    foreach ($cats as &$cat) {
        foreach ($categories as $category) {
            if ($category['id'] == $cat['id'] and isset($category['representative_picture_id'])) {
                $cat['tn_url'] = $thumbnail_src_of[$category['representative_picture_id']];
            }
        }
        // we don't want them in the output
        unset($cat['user_representative_picture_id'], $cat['count_images'], $cat['count_categories']);
    }
    unset($cat);
    // management of the album thumbnail -- stops here
    if ($params['tree_output']) {
        return categories_flatlist_to_tree($cats);
    }
    return array('categories' => new PwgNamedArray($cats, 'category', ws_std_get_category_xml_attributes()));
}