* @version $Id$ * @license http://opensource.org/licenses/agpl-v3.html */ /** * img.pew.cc Image Hosting * Copyright (C) 2009-2010 Daniel Triendl * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ require_once('lib/init.php'); require_once('lib/class.browse.php'); if (isset($_GET['tag'])) { // Calculate page offset $page = (isset($_GET['p']) && is_numeric($_GET['p'])) ? (int)$_GET['p'] : 1; $offset = ($page - 1) * $pagelimit; $tags_in = urldecode($_GET['tag']); $browse = new browse($pdo); $images = $browse->getImagesByTags($tags_in, $offset, $pagelimit); $tag_text = ucwords(str_ireplace(',', ', ', stripslashes_safe($_GET['tag']))); $img_text = ''; // Generate HTML output foreach ($images as $image) { $img_text .= '
' . htmlentities($image->original_name, ENT_QUOTES, 'UTF-8') . '
' . "\n"; $img_text .= 'Show
' . "\n"; } $pages = '

'; if ($page > 1 && ceil($browse->resultCount()/$pagelimit) > 1) { $pages .= '| < · '; $pages .= '< < · '; } for ($i = 1; $i <= ceil($browse->resultCount()/$pagelimit); $i++) { if ($i != $page) $pages .= '' . $i . ''; else $pages .= $i; $pages .= ' · '; } if ($page < ceil($browse->resultCount()/$pagelimit)) { $pages .= '> > · '; $pages .= '> | · '; } $pages = substr($pages, 0, -10) . '

'; //Get tags for images $tags = $browse->getTagListTags($tags_in); if (count($tags) > 0) { $tags_text = '
'; } else { $tags_text = ''; } outputHTML('

' . htmlentities(one_wordwrap($tag_text, 5, '­'), ENT_QUOTES, 'UTF-8', false) . '

' . $img_text . '
' . $pages . $tags_text, array('title' => 'Tag: ' . htmlentities($tag_text, ENT_QUOTES, 'UTF-8'), 'lightbox' => true)); } elseif(isset($_GET['user'])) { // Calculate page offset $page = (isset($_GET['p']) && is_numeric($_GET['p'])) ? (int)$_GET['p'] : 1; $offset = ($page - 1) * $pagelimit; $browse = new browse($pdo); $images = $browse->getImagesByUser($_GET['user'], $offset, $pagelimit); $img_text = ''; // Generate HTML output foreach ($images as $image) { $img_text .= '
' . htmlentities($image->original_name, ENT_QUOTES, 'UTF-8') . '
' . "\n"; $img_text .= 'Show
' . "\n"; } // Generate page count $pages = '

'; for ($i = 1; $i <= ceil($browse->resultCount()/$pagelimit); $i++) { if ($i != $page) $pages .= '' . $i . ''; else $pages .= $i; $pages .= ' · '; } $pages = substr($pages, 0, -10) . '

'; outputHTML('

' . htmlentities(one_wordwrap(urldecode(stripslashes_safe($_GET['user'])), 5, '­'), ENT_QUOTES, 'UTF-8', false) . '

' . $img_text . '
' . $pages, array('title' => 'Tag: ' . htmlentities(stripslashes_safe($_GET['user']), ENT_QUOTES, 'UTF-8'), 'lightbox' => true)); } elseif(isset($_GET['ip']) && isset($_GET['time'])) { $browse = new browse($pdo); $images = $browse->getImagesByIpTime($_GET['ip'], $_GET['time']); $img_text = ''; // Generate HTML output foreach ($images as $image) { $img_text .= '
' . htmlentities($image->original_name, ENT_QUOTES, 'UTF-8') . '
' . "\n"; $img_text .= 'Show
' . "\n"; } outputHTML('

' . htmlentities(one_wordwrap(urldecode($_GET['ip'] . ' - ' . $_GET['time']), 5, '­'), ENT_QUOTES, 'UTF-8', false) . '

' . $img_text . '
', array('title' => 'Upload: ' . htmlentities($_GET['ip'] . ' - ' . $_GET['time'], ENT_QUOTES, 'UTF-8'), 'lightbox' => true)); } elseif(isset($_GET['upload'])) { $browse = new browse($pdo); $images = $browse->getImagesByUploadID($_GET['upload']); if (count($images) == 0) { errorMsg('No images found, upload failed.'); } $img_text = ''; // Generate HTML output foreach ($images as $image) { $img_text .= '
' . htmlentities($image->original_name, ENT_QUOTES, 'UTF-8') . '
' . "\n"; $img_text .= 'Show
' . "\n"; } outputHTML('

' . htmlentities(one_wordwrap(urldecode($_GET['upload']), 5, '­'), ENT_QUOTES, 'UTF-8', false) . '

' . $img_text . '
', array('title' => 'Upload: ' . htmlentities($_GET['upload'], ENT_QUOTES, 'UTF-8'), 'lightbox' => true)); } else { // Get tags from db $browse = new browse($pdo); $tag_list = $browse->getTagList((isset($_GET['tags']) && $_GET['tags'] == 'all') ? -1 : 100); $tags = array(); $texts = array(); foreach ($tag_list as $tag) { $tags[$tag->tag] = $tag->count; $texts[$tag->tag] = htmlentities($tag->text, ENT_QUOTES, 'UTF-8'); } // $tags is the array ksort($tags); // largest and smallest array values $max_qty = (count($tags) > 0) ? max(array_values($tags)) : 0; $min_qty = (count($tags) > 0) ? min(array_values($tags)) : 0; // loop through the tag array and generate HTML output $cloud = ''; foreach ($tags as $tag => $count) { // Logarythmic tag list $div = log($max_qty) - log($min_qty); if ($div == 0) $div = 1; $weight = (log($count)-log($min_qty)) / $div; $size = $min_size + round(($max_size - $min_size) * $weight); $cloud .= '' . $texts[$tag] . ' '; } outputHTML('

' . $cloud . '


Show all tags

', array('title' => 'Tags')); } ?>