// size in pixels if ($picture['current']['src_image']->is_original() and isset($picture['current']['width'])) { $infos['INFO_DIMENSIONS'] = $picture['current']['width'] . '*' . $picture['current']['height']; } // filesize if (!empty($picture['current']['filesize'])) { $infos['INFO_FILESIZE'] = l10n('%d Kb', $picture['current']['filesize']); } // number of visits $infos['INFO_VISITS'] = $picture['current']['hit']; // file $infos['INFO_FILE'] = $picture['current']['file']; $template->assign($infos); $template->assign('display_info', unserialize($conf['picture_informations'])); // related tags $tags = get_common_tags(array($page['image_id']), -1); if (count($tags)) { foreach ($tags as $tag) { $template->append('related_tags', array_merge($tag, array('URL' => make_index_url(array('tags' => array($tag))), 'U_TAG_IMAGE' => duplicate_picture_url(array('section' => 'tags', 'tags' => array($tag)))))); } } // related categories if (count($related_categories) == 1 and isset($page['category']) and $related_categories[0]['id'] == $page['category']['id']) { // no need to go to db, we have all the info $template->append('related_categories', get_cat_display_name($page['category']['upper_names'])); } else { // use only 1 sql query to get names for all related categories $ids = array(); foreach ($related_categories as $category) { // add all uppercats to $ids $ids = array_merge($ids, explode(',', $category['uppercats']));
$query = ' SELECT DISTINCT(category_id) AS id FROM ' . IMAGE_CATEGORY_TABLE . ' AS ic JOIN ' . IMAGES_TABLE . ' AS i ON i.id = ic.image_id WHERE ic.image_id IN (' . implode(',', $page['cat_elements_id']) . ') AND ( ic.category_id != i.storage_category_id OR i.storage_category_id IS NULL ) ;'; $template->assign('associated_categories', query2array($query, 'id', 'id')); } if (count($page['cat_elements_id']) > 0) { // remove tags $template->assign('associated_tags', get_common_tags($page['cat_elements_id'], -1)); } // creation date $template->assign('DATE_CREATION', empty($_POST['date_creation']) ? date('Y-m-d') . ' 00:00:00' : $_POST['date_creation']); // image level options $template->assign(array('level_options' => get_privacy_level_options(), 'level_options_selected' => 0)); // metadata include_once PHPWG_ROOT_PATH . 'admin/site_reader_local.php'; $site_reader = new LocalSiteReader('./'); $used_metadata = implode(', ', $site_reader->get_metadata_attributes()); $template->assign(array('used_metadata' => $used_metadata)); //derivatives $del_deriv_map = array(); foreach (ImageStdParams::get_defined_type_map() as $params) { $del_deriv_map[$params->type] = l10n($params->type); }
/** * Setups each block the main menubar. */ function initialize_menu() { global $page, $conf, $user, $template, $filter; $menu = new BlockManager("menubar"); $menu->load_registered_blocks(); $menu->prepare_display(); if (@$page['section'] == 'search' and isset($page['qsearch_details'])) { $template->assign('QUERY_SEARCH', htmlspecialchars($page['qsearch_details']['q'])); } //--------------------------------------------------------------- external links if ($block = $menu->get_block('mbLinks') and !empty($conf['links'])) { $block->data = array(); foreach ($conf['links'] as $url => $url_data) { if (!is_array($url_data)) { $url_data = array('label' => $url_data); } if (!isset($url_data['eval_visible']) or eval($url_data['eval_visible'])) { $tpl_var = array('URL' => $url, 'LABEL' => $url_data['label']); if (!isset($url_data['new_window']) or $url_data['new_window']) { $tpl_var['new_window'] = array('NAME' => isset($url_data['nw_name']) ? $url_data['nw_name'] : '', 'FEATURES' => isset($url_data['nw_features']) ? $url_data['nw_features'] : ''); } $block->data[] = $tpl_var; } } if (!empty($block->data)) { $block->template = 'menubar_links.tpl'; } } //-------------------------------------------------------------- categories $block = $menu->get_block('mbCategories'); //------------------------------------------------------------------------ filter if ($conf['menubar_filter_icon'] and !empty($conf['filter_pages']) and get_filter_page_value('used')) { if ($filter['enabled']) { $template->assign('U_STOP_FILTER', add_url_params(make_index_url(array()), array('filter' => 'stop'))); } else { $template->assign('U_START_FILTER', add_url_params(make_index_url(array()), array('filter' => 'start-recent-' . $user['recent_period']))); } } if ($block != null) { $block->data = array('NB_PICTURE' => $user['nb_total_images'], 'MENU_CATEGORIES' => get_categories_menu(), 'U_CATEGORIES' => make_index_url(array('section' => 'categories'))); $block->template = 'menubar_categories.tpl'; } //------------------------------------------------------------------------ tags $block = $menu->get_block('mbTags'); if ($block != null and !empty($page['items']) and 'picture' != script_basename()) { if ('tags' == @$page['section']) { $tags = get_common_tags($page['items'], $conf['menubar_tag_cloud_items_number'], $page['tag_ids']); $tags = add_level_to_tags($tags); foreach ($tags as $tag) { $block->data[] = array_merge($tag, array('U_ADD' => make_index_url(array('tags' => array_merge($page['tags'], array($tag)))), 'URL' => make_index_url(array('tags' => array($tag))))); } } else { $selection = array_slice($page['items'], $page['start'], $page['nb_image_page']); $tags = add_level_to_tags(get_common_tags($selection, $conf['content_tag_cloud_items_number'])); foreach ($tags as $tag) { $block->data[] = array_merge($tag, array('URL' => make_index_url(array('tags' => array($tag))))); } } if (!empty($block->data)) { $block->template = 'menubar_tags.tpl'; } } //----------------------------------------------------------- special categories if (($block = $menu->get_block('mbSpecials')) != null) { if (!is_a_guest()) { // favorites $block->data['favorites'] = array('URL' => make_index_url(array('section' => 'favorites')), 'TITLE' => l10n('display your favorites photos'), 'NAME' => l10n('Your favorites')); } $block->data['most_visited'] = array('URL' => make_index_url(array('section' => 'most_visited')), 'TITLE' => l10n('display most visited photos'), 'NAME' => l10n('Most visited')); if ($conf['rate']) { $block->data['best_rated'] = array('URL' => make_index_url(array('section' => 'best_rated')), 'TITLE' => l10n('display best rated photos'), 'NAME' => l10n('Best rated')); } $block->data['recent_pics'] = array('URL' => make_index_url(array('section' => 'recent_pics')), 'TITLE' => l10n('display most recent photos'), 'NAME' => l10n('Recent photos')); $block->data['recent_cats'] = array('URL' => make_index_url(array('section' => 'recent_cats')), 'TITLE' => l10n('display recently updated albums'), 'NAME' => l10n('Recent albums')); $block->data['random'] = array('URL' => get_root_url() . 'random.php', 'TITLE' => l10n('display a set of random photos'), 'NAME' => l10n('Random photos'), 'REL' => 'rel="nofollow"'); $block->data['calendar'] = array('URL' => make_index_url(array('chronology_field' => $conf['calendar_datefield'] == 'date_available' ? 'posted' : 'created', 'chronology_style' => 'monthly', 'chronology_view' => 'calendar')), 'TITLE' => l10n('display each day with photos, month per month'), 'NAME' => l10n('Calendar'), 'REL' => 'rel="nofollow"'); $block->template = 'menubar_specials.tpl'; } //---------------------------------------------------------------------- summary if (($block = $menu->get_block('mbMenu')) != null) { // quick search block will be displayed only if data['qsearch'] is set // to "yes" $block->data['qsearch'] = true; // tags link $block->data['tags'] = array('TITLE' => l10n('display available tags'), 'NAME' => l10n('Tags'), 'URL' => get_root_url() . 'tags.php', 'COUNTER' => get_nb_available_tags()); // search link $block->data['search'] = array('TITLE' => l10n('search'), 'NAME' => l10n('Search'), 'URL' => get_root_url() . 'search.php', 'REL' => 'rel="search"'); if ($conf['activate_comments']) { // comments link $block->data['comments'] = array('TITLE' => l10n('display last user comments'), 'NAME' => l10n('Comments'), 'URL' => get_root_url() . 'comments.php', 'COUNTER' => get_nb_available_comments()); } // about link $block->data['about'] = array('TITLE' => l10n('About Piwigo'), 'NAME' => l10n('About'), 'URL' => get_root_url() . 'about.php'); // notification $block->data['rss'] = array('TITLE' => l10n('RSS feed'), 'NAME' => l10n('Notification'), 'URL' => get_root_url() . 'notification.php', 'REL' => 'rel="nofollow"'); $block->template = 'menubar_menu.tpl'; } //--------------------------------------------------------------- identification if (is_a_guest()) { $template->assign(array('U_LOGIN' => get_root_url() . 'identification.php', 'U_LOST_PASSWORD' => get_root_url() . 'password.php', 'AUTHORIZE_REMEMBERING' => $conf['authorize_remembering'])); if ($conf['allow_user_registration']) { $template->assign('U_REGISTER', get_root_url() . 'register.php'); } } else { $template->assign('USERNAME', stripslashes($user['username'])); if (is_autorize_status(ACCESS_CLASSIC)) { $template->assign('U_PROFILE', get_root_url() . 'profile.php'); } // the logout link has no meaning with Apache authentication : it is not // possible to logout with this kind of authentication. if (!$conf['apache_authentication']) { $template->assign('U_LOGOUT', get_root_url() . '?act=logout'); } if (is_admin()) { $template->assign('U_ADMIN', get_root_url() . 'admin.php'); } } if (($block = $menu->get_block('mbIdentification')) != null) { $block->template = 'menubar_identification.tpl'; } $menu->apply('MENUBAR', 'menubar.tpl'); }
/** * API method * Returns detailed information for an element * @param mixed[] $params * @option int image_id * @option int comments_page * @option int comments_per_page */ function ws_images_getInfo($params, $service) { global $user, $conf; $query = ' SELECT * FROM ' . IMAGES_TABLE . ' WHERE id=' . $params['image_id'] . get_sql_condition_FandF(array('visible_images' => 'id'), ' AND') . ' LIMIT 1 ;'; $result = pwg_query($query); if (pwg_db_num_rows($result) == 0) { return new PwgError(404, 'image_id not found'); } $image_row = pwg_db_fetch_assoc($result); $image_row = array_merge($image_row, ws_std_get_urls($image_row)); //-------------------------------------------------------- related categories $query = ' SELECT id, name, permalink, uppercats, global_rank, commentable FROM ' . IMAGE_CATEGORY_TABLE . ' INNER JOIN ' . CATEGORIES_TABLE . ' ON category_id = id WHERE image_id = ' . $image_row['id'] . get_sql_condition_FandF(array('forbidden_categories' => 'category_id'), ' AND') . ' ;'; $result = pwg_query($query); $is_commentable = false; $related_categories = array(); while ($row = pwg_db_fetch_assoc($result)) { if ($row['commentable'] == 'true') { $is_commentable = true; } unset($row['commentable']); $row['url'] = make_index_url(array('category' => $row)); $row['page_url'] = make_picture_url(array('image_id' => $image_row['id'], 'image_file' => $image_row['file'], 'category' => $row)); $row['id'] = (int) $row['id']; $related_categories[] = $row; } usort($related_categories, 'global_rank_compare'); if (empty($related_categories)) { return new PwgError(401, 'Access denied'); } //-------------------------------------------------------------- related tags $related_tags = get_common_tags(array($image_row['id']), -1); foreach ($related_tags as $i => $tag) { $tag['url'] = make_index_url(array('tags' => array($tag))); $tag['page_url'] = make_picture_url(array('image_id' => $image_row['id'], 'image_file' => $image_row['file'], 'tags' => array($tag))); unset($tag['counter']); $tag['id'] = (int) $tag['id']; $related_tags[$i] = $tag; } //------------------------------------------------------------- related rates $rating = array('score' => $image_row['rating_score'], 'count' => 0, 'average' => null); if (isset($rating['score'])) { $query = ' SELECT COUNT(rate) AS count, ROUND(AVG(rate),2) AS average FROM ' . RATE_TABLE . ' WHERE element_id = ' . $image_row['id'] . ' ;'; $row = pwg_db_fetch_assoc(pwg_query($query)); $rating['score'] = (double) $rating['score']; $rating['average'] = (double) $row['average']; $rating['count'] = (int) $row['count']; } //---------------------------------------------------------- related comments $related_comments = array(); $where_comments = 'image_id = ' . $image_row['id']; if (!is_admin()) { $where_comments .= ' AND validated="true"'; } $query = ' SELECT COUNT(id) AS nb_comments FROM ' . COMMENTS_TABLE . ' WHERE ' . $where_comments . ' ;'; list($nb_comments) = query2array($query, null, 'nb_comments'); $nb_comments = (int) $nb_comments; if ($nb_comments > 0 and $params['comments_per_page'] > 0) { $query = ' SELECT id, date, author, content FROM ' . COMMENTS_TABLE . ' WHERE ' . $where_comments . ' ORDER BY date LIMIT ' . (int) $params['comments_per_page'] . ' OFFSET ' . (int) ($params['comments_per_page'] * $params['comments_page']) . ' ;'; $result = pwg_query($query); while ($row = pwg_db_fetch_assoc($result)) { $row['id'] = (int) $row['id']; $related_comments[] = $row; } } $comment_post_data = null; if ($is_commentable and (!is_a_guest() or is_a_guest() and $conf['comments_forall'])) { $comment_post_data['author'] = stripslashes($user['username']); $comment_post_data['key'] = get_ephemeral_key(2, $params['image_id']); } $ret = $image_row; foreach (array('id', 'width', 'height', 'hit', 'filesize') as $k) { if (isset($ret[$k])) { $ret[$k] = (int) $ret[$k]; } } foreach (array('path', 'storage_category_id') as $k) { unset($ret[$k]); } $ret['rates'] = array(WS_XML_ATTRIBUTES => $rating); $ret['categories'] = new PwgNamedArray($related_categories, 'category', array('id', 'url', 'page_url')); $ret['tags'] = new PwgNamedArray($related_tags, 'tag', ws_std_get_tag_xml_attributes()); if (isset($comment_post_data)) { $ret['comment_post'] = array(WS_XML_ATTRIBUTES => $comment_post_data); } $ret['comments_paging'] = new PwgNamedStruct(array('page' => $params['comments_page'], 'per_page' => $params['comments_per_page'], 'count' => count($related_comments), 'total_count' => $nb_comments)); $ret['comments'] = new PwgNamedArray($related_comments, 'comment', array('id', 'date')); if ($service->_responseFormat != 'rest') { return $ret; // for backward compatibility only } else { return array('image' => new PwgNamedStruct($ret, null, array('name', 'comment'))); } }