// +-----------------------------------------------------------------------+ $categories = array(); $query = ' SELECT id, name, permalink, dir, rank, status FROM ' . CATEGORIES_TABLE; if (!isset($_GET['parent_id'])) { $query .= ' WHERE id_uppercat IS NULL'; } else { $query .= ' WHERE id_uppercat = ' . $_GET['parent_id']; } $query .= ' ORDER BY rank ASC ;'; $categories = hash_from_query($query, 'id'); // get the categories containing images directly $categories_with_images = array(); if (count($categories)) { $query = ' SELECT category_id, COUNT(*) AS nb_photos FROM ' . IMAGE_CATEGORY_TABLE . ' GROUP BY category_id ;'; // WHERE category_id IN ('.implode(',', array_keys($categories)).') $nb_photos_in = query2array($query, 'category_id', 'nb_photos'); $query = ' SELECT id,
/** * Returns an array associating element id (images.id) with its complete * path in the filesystem * * @param int $category_id * @param int $site_id * @param boolean $recursive * @param boolean $only_new * @return array */ function get_filelist($category_id = '', $site_id = 1, $recursive = false, $only_new = false) { // filling $cat_ids : all categories required $cat_ids = array(); $query = ' SELECT id FROM ' . CATEGORIES_TABLE . ' WHERE site_id = ' . $site_id . ' AND dir IS NOT NULL'; if (is_numeric($category_id)) { if ($recursive) { $query .= ' AND uppercats ' . DB_REGEX_OPERATOR . ' \'(^|,)' . $category_id . '(,|$)\' '; } else { $query .= ' AND id = ' . $category_id . ' '; } } $query .= ' ;'; $result = pwg_query($query); while ($row = pwg_db_fetch_assoc($result)) { $cat_ids[] = $row['id']; } if (count($cat_ids) == 0) { return array(); } $query = ' SELECT id, path, representative_ext FROM ' . IMAGES_TABLE . ' WHERE storage_category_id IN (' . implode(',', $cat_ids) . ')'; if ($only_new) { $query .= ' AND date_metadata_update IS NULL '; } $query .= ' ;'; return hash_from_query($query, 'id'); }
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'])); } $ids = array_unique($ids); $query = ' SELECT id, name, permalink FROM ' . CATEGORIES_TABLE . ' WHERE id IN (' . implode(',', $ids) . ')'; $cat_map = hash_from_query($query, 'id'); foreach ($related_categories as $category) { $cats = array(); foreach (explode(',', $category['uppercats']) as $id) { $cats[] = $cat_map[$id]; } $template->append('related_categories', get_cat_display_name($cats)); } } // maybe someone wants a special display (call it before page_header so that // they can add stylesheets) $element_content = trigger_change('render_element_content', '', $picture['current']); $template->assign('ELEMENT_CONTENT', $element_content); if (isset($picture['next']) and $picture['next']['src_image']->is_original() and $template->get_template_vars('U_PREFETCH') == null and strpos(@$_SERVER['HTTP_USER_AGENT'], 'Chrome/') === false) { $template->assign('U_PREFETCH', $picture['next']['derivatives'][pwg_get_session_var('picture_deriv', $conf['derivative_default_size'])]->get_url()); }
switch ($_GET['action']) { case 'delete': delete_site($page['site']); $page['infos'][] = $galleries_url . ' ' . l10n('deleted'); break; } } $template->assign(array('F_ACTION' => get_root_url() . 'admin.php' . get_query_string_diff(array('action', 'site', 'pwg_token')), 'PWG_TOKEN' => get_pwg_token())); $query = ' SELECT c.site_id, COUNT(DISTINCT c.id) AS nb_categories, COUNT(i.id) AS nb_images FROM ' . CATEGORIES_TABLE . ' AS c LEFT JOIN ' . IMAGES_TABLE . ' AS i ON c.id=i.storage_category_id WHERE c.site_id IS NOT NULL GROUP BY c.site_id ;'; $sites_detail = hash_from_query($query, 'site_id'); $query = ' SELECT * FROM ' . SITES_TABLE . ' ;'; $result = pwg_query($query); while ($row = pwg_db_fetch_assoc($result)) { $is_remote = url_is_remote($row['galleries_url']); $base_url = PHPWG_ROOT_PATH . 'admin.php'; $base_url .= '?page=site_manager'; $base_url .= '&site=' . $row['id']; $base_url .= '&pwg_token=' . get_pwg_token(); $base_url .= '&action='; $update_url = PHPWG_ROOT_PATH . 'admin.php'; $update_url .= '?page=site_update'; $update_url .= '&site=' . $row['id'];
</head> <body> <h2>GuestBook import</h2> <?php $show_form = true; if (isset($_POST['image_id'])) { if (!preg_match('#^[0-9]+$#', $_POST['image_id'])) { echo '<h3>Incorrect image Id</h3><br>'; } else { $query = ' SELECT * FROM ' . COMMENTS_TABLE . ' WHERE image_id = ' . $_POST['image_id'] . ' ;'; $comms = hash_from_query($query, 'id'); if (!count($comms)) { echo '<h3>No comments for this picture</h3><br>'; } else { mass_inserts(GUESTBOOK_TABLE, array('date', 'author', 'author_id', 'anonymous_id', 'email', 'website', 'content', 'rate', 'validated', 'validation_date'), $comms); echo '<h3>' . count($comms) . ' comments imported into the Guestbook</h3><br>'; $show_form = false; } } } if ($show_form) { ?> Just enter the ID of your old guestbook picture (the ID can be found a the picture edition page, near the thumbnail) and click the <b>import</b> button. <form action="" method="post"> <label>Image ID : <input type="text" size="5" name="image_id"></label><br> <input type="submit" value="import">
// | This program is distributed in the hope that it will be useful, but | // | WITHOUT ANY WARRANTY; without even the implied warranty of | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | // | General Public License for more details. | // | | // | You should have received a copy of the GNU General Public License | // | along with this program; if not, write to the Free Software | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | // | USA. | // +-----------------------------------------------------------------------+ defined('PHPWG_ROOT_PATH') or die('Hacking attempt!'); $upgrade_description = 'add ASC keyword to categories image_order field'; $query = ' SELECT id, image_order FROM ' . CATEGORIES_TABLE . ' WHERE image_order != "" ;'; $cats = hash_from_query($query, 'id'); foreach ($cats as $id => &$data) { $image_order = explode(',', $data['image_order']); foreach ($image_order as &$order) { if (strpos($order, ' ASC') === false && strpos($order, ' DESC') === false) { $order .= ' ASC'; } } unset($order); $data['image_order'] = implode(',', $image_order); } unset($data); mass_updates(CATEGORIES_TABLE, array('primary' => array('id'), 'update' => array('image_order')), $cats); echo "\n" . $upgrade_description . "\n";
function osm_get_items($page) { // Limit search by category, by tag, by smartalbum $LIMIT_SEARCH = ""; $INNER_JOIN = ""; if (isset($page['section'])) { if ($page['section'] === 'categories' and isset($page['category']) and isset($page['category']['id'])) { $LIMIT_SEARCH = "FIND_IN_SET(" . $page['category']['id'] . ", c.uppercats) AND "; $INNER_JOIN = "INNER JOIN " . CATEGORIES_TABLE . " AS c ON ic.category_id = c.id"; } if ($page['section'] === 'tags' and isset($page['tags']) and isset($page['tags'][0]['id'])) { $items = get_image_ids_for_tags(array($page['tags'][0]['id'])); if (!empty($items)) { $LIMIT_SEARCH = "ic.image_id IN (" . implode(',', $items) . ") AND "; } } if ($page['section'] === 'tags' and isset($page['category']) and isset($page['category']['id'])) { $LIMIT_SEARCH = "FIND_IN_SET(" . $page['category']['id'] . ", c.uppercats) AND "; $INNER_JOIN = "INNER JOIN " . CATEGORIES_TABLE . " AS c ON ic.category_id = c.id"; } } $forbidden = get_sql_condition_FandF(array('forbidden_categories' => 'ic.category_id', 'visible_categories' => 'ic.category_id', 'visible_images' => 'i.id'), "\n AND"); /* We have lat and lng coordonate for virtual album */ if (isset($_GET['min_lat']) and isset($_GET['max_lat']) and isset($_GET['min_lng']) and isset($_GET['max_lng'])) { $LIMIT_SEARCH = ""; $INNER_JOIN = ""; /* Delete all previous album */ $query = "SELECT `id` FROM " . CATEGORIES_TABLE . " WHERE `name` = 'Locations' AND `comment` LIKE '%OSM plugin%';"; $ids = array_from_query($query, 'id'); /* Unlink items for the previous album */ delete_categories($ids, $photo_deletion_mode = 'no_delete'); /* Create an album */ $options = array('comment' => 'Generated by OSM plugin'); $osm_album = create_virtual_category('Locations', NULL, $options); /* Create a sub album */ $options = array('comment' => "OSM virtual album\nlat:" . $_GET['min_lat'] . " " . $_GET['max_lat'] . "\nlng:" . $_GET['min_lng'] . " " . $_GET['max_lng']); $osm_sub_album = create_virtual_category("OSM" . $_GET['min_lat'] . "", $osm_album['id'], $options); /* Get all items inside the lat and lng */ $query = "SELECT `id`, `latitude`, `longitude` \n FROM " . IMAGES_TABLE . " AS i\n INNER JOIN " . IMAGE_CATEGORY_TABLE . " AS ic ON id = ic.image_id\n WHERE " . $LIMIT_SEARCH . " `latitude` IS NOT NULL AND `longitude` IS NOT NULL \n AND `latitude` > " . $_GET['min_lat'] . " AND `latitude` < " . $_GET['max_lat'] . "\n AND `longitude` > " . $_GET['min_lng'] . " AND `longitude` < " . $_GET['max_lng'] . "\n " . $forbidden . ";"; $items = hash_from_query($query, 'id'); /* Add items to the new sub album */ foreach ($items as $item) { $query = "INSERT INTO " . IMAGE_CATEGORY_TABLE . " ( `image_id` ,`category_id` ,`rank` ) VALUES ( '" . $item['id'] . "', '" . $osm_sub_album['id'] . "', NULL );"; pwg_query($query); } /* Redirect to the new album */ header('Location: ' . get_absolute_root_url() . 'index.php?/category/' . $osm_sub_album['id']); exit; } // Fetch data with latitude and longitude //$query="SELECT `latitude`, `longitude`, `name`, `path` FROM ".IMAGES_TABLE." WHERE `latitude` IS NOT NULL AND `longitude` IS NOT NULL;"; // SUBSTRING_INDEX(TRIM(LEADING '.' FROM `path`), '.', 1) full path without filename extension // SUBSTRING_INDEX(TRIM(LEADING '.' FROM `path`), '.', -1) full path with only filename extension if (isset($page['image_id'])) { $LIMIT_SEARCH .= 'i.id = ' . $page['image_id'] . ' AND '; } $query = "SELECT i.latitude, i.longitude,\n IFNULL(i.name, '') AS `name`,\n IF(i.representative_ext IS NULL,\n CONCAT(SUBSTRING_INDEX(TRIM(LEADING '.' FROM i.path), '.', 1 ), '-sq.', SUBSTRING_INDEX(TRIM(LEADING '.' FROM i.path), '.', -1 )),\n TRIM(LEADING '.' FROM\n REPLACE(i.path, TRIM(TRAILING '.' FROM SUBSTRING_INDEX(i.path, '/', -1 )),\n CONCAT('pwg_representative/',\n CONCAT(\n TRIM(TRAILING '.' FROM SUBSTRING_INDEX( SUBSTRING_INDEX(i.path, '/', -1 ) , '.', 1 )),\n CONCAT('-sq.', i.representative_ext)\n )\n )\n )\n )\n ) AS `pathurl`,\n TRIM(TRAILING '/' FROM CONCAT( i.id, '/category/', IFNULL(i.storage_category_id, '') ) ) AS `imgurl`,\n IFNULL(i.comment, '') AS `comment`,\n IFNULL(i.author, '') AS `author`,\n i.width\n FROM " . IMAGES_TABLE . " AS i\n INNER JOIN (" . IMAGE_CATEGORY_TABLE . " AS ic " . $INNER_JOIN . ") ON i.id = ic.image_id\n WHERE " . $LIMIT_SEARCH . " i.latitude IS NOT NULL AND i.longitude IS NOT NULL " . $forbidden . " GROUP BY i.id;"; //echo $query; $php_data = array_from_query($query); //print_r($php_data); $js_data = array(); foreach ($php_data as $array) { // MySQL did all the job //print_r($array); $js_data[] = array((double) $array['latitude'], (double) $array['longitude'], $array['name'], get_absolute_root_url() . "i.php?" . $array['pathurl'], get_absolute_root_url() . "picture.php?/" . $array['imgurl'], $array['comment'], $array['author'], (int) $array['width']); } /* START Debug generate dummy data $js_data = array(); $str = 'abcdef'; $minLat = -90.00; $maxLat = 90.00; $minLon = -180.00; $maxLon = 180.00; for ($i = 1; $i <= 5000; $i++) { $js_data[] = array( (double)$minLat + (double)((float)rand()/(float)getrandmax() * (($maxLat - $minLat) + 1)), (double)$minLon + (double)((float)rand()/(float)getrandmax() * (($maxLon - $minLon) + 1)), str_shuffle($str), "http://placehold.it/120x120", "http://placehold.it/200x200", "Comment", "Author", (int)120 ); } END Debug generate dummy data */ return $js_data; }
define('SQL_EXIF', "`latitude` IS NOT NULL AND `longitude` is NOT NULL"); if ($sync_options['cat_id'] != 0) { $query = ' SELECT id FROM ' . CATEGORIES_TABLE . ' WHERE '; if ($sync_options['subcats_included']) { $query .= 'uppercats REGEXP \'(^|,)' . $sync_options['cat_id'] . '(,|$)\''; } else { $query .= 'id=' . $sync_options['cat_id']; } $cat_ids = array_from_query($query, 'id'); $query = 'SELECT `id`, `name`, `latitude`, `longitude` FROM ' . IMAGES_TABLE . ' INNER JOIN ' . IMAGE_CATEGORY_TABLE . ' ON id=image_id WHERE ' . SQL_EXIF . ' AND category_id IN (' . implode(',', $cat_ids) . ') GROUP BY id'; } else { $query = 'SELECT `id`, `name`, `latitude`, `longitude` FROM ' . IMAGES_TABLE . ' WHERE ' . SQL_EXIF; } $images = hash_from_query($query, 'id'); $datas = array(); $errors = array(); $warnings = array(); $infos = array(); foreach ($images as $image) { // Fech reverse location from API // https://nominatim.openstreetmap.org/reverse?format=xml&lat=51.082333&lon=10.366229&zoom=12 // https://open.mapquestapi.com/nominatim/v1/reverse.php?format=xml&lat=48.858366666667&lon=2.2942166666667&zoom=12 // http://wiki.openstreetmap.org/wiki/Nominatim //$osm_url = "https://nominatim.openstreetmap.org/reverse?format=json&addressdetails=1&zoom=12&lat=". $image['latitude'] ."&lon=". $image['longitude']; $osm_url = "https://open.mapquestapi.com/nominatim/v1/reverse.php?format=json&addressdetails=1&zoom=12&lat=" . $image['latitude'] . "&lon=" . $image['longitude']; //print $osm_url ."<br/>"; // Ensure we do have PHP curl install // Or should fallback to fopen if (function_exists('curl_init')) {