- Poprawiono interpretowanie pierwszego i ostatniego zdjęcia

- Zmieniono stronnicowanie
- Dodano buttony oraz przykładowe zdjęcia do testów skryptu
- Prowadzono 2 nowe pliki: functions.php - z funkcjami oraz config.php - konfiguracją
- Wprowadzono mniej ważne poprawki

git-svn-id: https://svn.pioder.pl/sg-svn@7 3ed2631f-fe0d-47e0-9194-a46bc0f18ee8
This commit is contained in:
pioder
2009-06-16 11:52:07 +00:00
parent 239589a41d
commit 04fdaa4ab6
31 changed files with 623 additions and 329 deletions

View File

@@ -1,10 +1,42 @@
<?php <?php
$i=intval($_GET['name'])+1; /**
require('init.php'); * @package Galeria Suczawa 2009
$result = mysql_query('SELECT * FROM photos WHERE id='.$i); * @file ask.php
$row = mysql_fetch_assoc($result); * @version $Id$
* @author chp1994 <chp1994@gmail.com>
* @link http://suczawa.ath.cx/
**/
if(!row) die('Error'); $i=intval($_GET['name']);
require('./init.php');
if ($i == 0)
{
blad('Zdjecie nie istnieje!');
}
$sql = "SELECT * FROM `photos` WHERE `id`='$i'";
if (!$result = $DB->query($sql))
{
blad('Nie mozna pobrac informacji o zdjeciu!');
}
#sprawdź, czy zdjęcie istnieje
$cnt = $result->num_rows;
if ($result->num_rows == 0)
{
$row = array(
'author' => '--',
'description' => 'Zdjęcie usunięte',
'photo_name' => 'no_image.png',
'id' => $i
);
}
else
{
$row = $result->fetch_assoc();
$row['author'] = ($row['author']=='') ? 'Autor nieznany' : $row['author'];
$row['description'] = ($row['description']=='') ? 'Brak opisu' : $row['description'];
}
header('Content-Type: text/xml'); header('Content-Type: text/xml');
echo '<?xml version="1.0" encoding="utf-8"?>'; echo '<?xml version="1.0" encoding="utf-8"?>';
@@ -14,7 +46,7 @@ echo '<?xml version="1.0" encoding="utf-8"?>';
<name><?=$row['id']?>: <?=basename($row['photo_name'])?></name> <name><?=$row['id']?>: <?=basename($row['photo_name'])?></name>
<desc xmlns="http://www.w3.org/1999/xhtml"><p><?=$row['description']?></p></desc> <desc xmlns="http://www.w3.org/1999/xhtml"><p><?=$row['description']?></p></desc>
<src><?=$row['photo_name']?></src> <src><?=$row['photo_name']?></src>
<author><?=$row['author']?></author> <author><?= $row['author']; ?></author>
<?if($i==$count){?><last /><? } ?> <?if($i==$lastid){?><last /><? } ?>
<?if($i==0){?><first /><? } ?> <?if($i==$firstid){?><first /><? } ?>
</data> </data>

17
robocze/config.php Normal file
View File

@@ -0,0 +1,17 @@
<?
/**
* @package Galeria Suczawa 2009
* @file config.php
* @version $Id$
* @author PioDer <pioder@wp.pl>
* @link http://suczawa.ath.cx/
**/
define('DB_HOST','localhost');
define('DB_USER','root');
define('DB_PASS','');
define('DB_NAME','galeria');
//liczba zdjęć na stronę
$per_page=3;
?>

64
robocze/dump.txt Normal file
View File

@@ -0,0 +1,64 @@
-- phpMyAdmin SQL Dump
-- version 3.1.3.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Czas wygenerowania: 16 Cze 2009, 12:36
-- Wersja serwera: 5.1.33
-- Wersja PHP: 5.2.9
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
--
-- Baza danych: `galeria`
--
-- --------------------------------------------------------
--
-- Struktura tabeli dla `admins`
--
CREATE TABLE IF NOT EXISTS `admins` (
`id` smallint(1) NOT NULL,
`nick` varchar(20) NOT NULL,
`password` varchar(200) NOT NULL,
`email` varchar(20) NOT NULL,
`IP` varchar(14) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
--
-- Zrzut danych tabeli `admins`
--
-- --------------------------------------------------------
--
-- Struktura tabeli dla `photos`
--
CREATE TABLE IF NOT EXISTS `photos` (
`id` smallint(4) NOT NULL,
`thumb_name` varchar(20) NOT NULL,
`photo_name` varchar(20) NOT NULL,
`author` varchar(30) NOT NULL,
`description` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
--
-- Zrzut danych tabeli `photos`
--
INSERT INTO `photos` (`id`, `thumb_name`, `photo_name`, `author`, `description`) VALUES
(1, 'DSC_0026_m.png', 'DSC_0026.png', '', 'Pod zamkiem - grupowo'),
(2, 'DSC_0132_m.png', 'DSC_0132.png', '', 'Pod szko³¹'),
(3, 'DSC_0169_m.png', 'DSC_0169.png', '', 'Widoki na Monastyr'),
(4, 'DSC_0294_m.png', 'DSC_0294.png', '', 'Bukowina Po³udniowa'),
(5, 'DSC_0378_m.png', 'DSC_0378.png', '', 'Pani Monika :)'),
(6, 'DSC_0080_m.png', 'DSC_0080.png', '', 'Nasz Geniusz podczas rozdawania nagród ;)'),
(7, 'DSC_0672_m.png', 'DSC_0672.png', '', 'W¹wóz...'),
(8, 'DSCF0372_m.png', 'DSCF0372.png', '', 'Œwi¹tynia w Monastyrze'),
(9, 'DSCF0452_m.png', 'DSCF0452.png', '', 'Kolejna fotka z w¹wozu.');

67
robocze/functions.php Normal file
View File

@@ -0,0 +1,67 @@
<?
/**
* @package Galeria Suczawa 2009
* @file functions.php
* @version $Id$
* @author PioDer <pioder@wp.pl>
* @link http://suczawa.ath.cx/
**/
#wyświetl błąd
function blad($msg)
{
die('
<h1>Blad Galerii Zdjec Suczawa 2009!</h1>
<span style="color: red; font-weight: bold; font-size: 12pt">'.$msg.'</span>');
}
function GenerujListeStron()
{
global $cnt;
global $page;
$content = '';
if ($page>1)
{
$content .= '<a href="?page=1" title="Pierwsza strona">&lt;&lt;</a>';
$content .= '&nbsp;&nbsp;<a href="?page='.($page-1).'" title="Poprzednia strona">&lt;</a> ';
}
#wygeneruj strony
for ($i=1;$i<=$cnt;$i++)
{
if ($i==$page)
{
if ($i == $cnt)
{
$content .= '<span style="text-decoration: underline">'.$i.'</span>';
}
else
{
$content .= '<span style="text-decoration: underline">'.$i.'</span>'.' | ';
}
}
else
{
if ($i == $cnt)
{
$content .= '<a href="?page='.$i.'">'.$i.'</a> ';
}
else
{
$content .= '<a href="?page='.$i.'">'.$i.'</a> | ';
}
}
}
#dodaj linka "+1 strona" oraz do ostatniej
if ($page<$cnt)
{
$content .= '<a href="?page='.($page+1).'" title="Następna strona">&gt;</a>';
$content .= '&nbsp;&nbsp;<a href="?page='.$cnt.'" title="Ostatnia strona">&gt;&gt;</a>';
}
#dodaj linka do ostatniej strony
echo $content;
}
?>

View File

@@ -1,29 +1,53 @@
<?php <?php
/**
* @package Galeria Suczawa 2009
* @file gallery.php
* @version $Id$
* @author chp1994 <chp1994@gmail.com>
* @link http://suczawa.ath.cx/
**/
$page= (isset($_GET['page'])) ? intval($_GET['page']) : 0; $page= (isset($_GET['page'])) ? intval($_GET['page']) : 0;
$xhtml = preg_match('/application\/xhtml\+xml(?![+a-z])(;q=(0\.\d{1,3}|[01]))?/i', $xhtml = preg_match('/application\/xhtml\+xml(?![+a-z])(;q=(0\.\d{1,3}|[01]))?/i',
$_SERVER['HTTP_ACCEPT'], $xhtml) && (isset($xhtml[2])?$xhtml[2]:1) > 0 || $_SERVER['HTTP_ACCEPT'], $xhtml) && (isset($xhtml[2])?$xhtml[2]:1) > 0 ||
strpos($_SERVER["HTTP_USER_AGENT"], "W3C_Validator")!==false || strpos($_SERVER["HTTP_USER_AGENT"], "W3C_Validator")!==false ||
strpos($_SERVER["HTTP_USER_AGENT"], "WebKit")!==false; strpos($_SERVER["HTTP_USER_AGENT"], "WebKit")!==false;
header('Content-Type: '.($xhtml ? 'application/xhtml+x' : 'text/ht').'ml; charset="utf-8"'); header('Content-Type: '.($xhtml ? 'application/xhtml+x' : 'text/ht').'ml; charset="utf-8"');
require('init.php');
echo '<?xml version="1.0" encoding="utf-8"?>' require('./init.php');
echo '<?xml version="1.0" encoding="utf-8"?>';
?> ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl">
<head> <head>
<title>Galeria</title> <title>Galeria Suczawa 2009</title>
<link type="text/css" href="style.css" rel="stylesheet" /> <link type="text/css" href="style.css" rel="stylesheet" />
<script type="text/javascript" src="script.js"></script> <script type="text/javascript">
<!--
sciezka = 'http://' + '<?= $_SERVER['HTTP_HOST']; ?>' + '/sg/robocze/';
//-->
</script>
<script type="text/javascript" src="script.js"><!-- AJAX Library by chp1994(c) //--></script>
</head> </head>
<body onload="javascipt:init()"> <body onload="javascipt:init()">
<div id="page"> <div id="page">
<div id="images_outer"> <div id="images_outer">
<table id="images"><tr> <table id="images"><tr>
<?php <?php
$result = mysql_query('SELECT * FROM photos LIMIT '.($page*$per_page).', '.$per_page); //$sql = "SELECT * FROM `photos` LIMIT ".($page*$per_page).", $per_page";
for($i=$page*$per_page; $row = mysql_fetch_assoc($result); $i++) { $sql = "SELECT * FROM `photos` $limit";
echo '<td class="image_outer" onclick="javascript:previewImage('.$i.')"><img alt="'.$row['photo_name'].'" src="'.$row['thumb_name'].'" class="image" /></td>'; if (!$result = $DB->query($sql))
{
blad('Nie mozna pobrac zdjec uzytkownikow!');
}
for($i=$page*$per_page; $row = $result->fetch_assoc(); $i++)
{
echo '<td class="image_outer" onclick="javascript:previewImage('.($row['id']).')"><img alt="'.$row['photo_name'].'" src="images/upload/'.$row['thumb_name'].'" class="image" /></td>';
if($i%3==2 && $i!=$count-1) echo '</tr><tr>'; if($i%3==2 && $i!=$count-1) echo '</tr><tr>';
} }
@@ -38,16 +62,7 @@ echo '<?xml version="1.0" encoding="utf-8"?>'
<div id="pages_outer"> <div id="pages_outer">
<div id="pages">Strony: <div id="pages">Strony:
<?php <?php
$pcount = ceil($count/$per_page)-1; GenerujListeStron();
for($i=0; $i<$page; $i++) {
echo '<a href="?page='.$i.'">'.($i+1).'</a> | ';
}
if($page!=$pcount) echo ($page+1).' | ';
else echo ($page+1);
for($i=$page+1; $i<$pcount; $i++) {
echo '<a href="?page='.$i.'">'.($i+1).'</a> | ';
}
if($page!=$pcount) echo '<a href="?page='.($pcount).'">'.($pcount+1).'</a>';
?> ?>
</div> </div>
</div> </div>
@@ -56,9 +71,9 @@ echo '<?xml version="1.0" encoding="utf-8"?>'
<div id="disp_inner"> <div id="disp_inner">
<div><h3 id="disp_name"> </h3></div> <div><h3 id="disp_name"> </h3></div>
<div id="disp_top"> <div id="disp_top">
<img id="disp_prev" src="img/prev.png" onclick="javascript:prev()" alt="Poprzedni"></img> <img id="disp_prev" src="images/prev.png" onclick="javascript:prev()" alt="Poprzedni"></img>
<a id="disp_a" href=""><img id="disp_img" src="" alt="Zdjęcie" /></a> <a id="disp_a" href=""><img id="disp_img" src="" alt="Zdjecie" /></a>
<img id="disp_next" src="img/next.png" onclick="javascript:next()" alt="Następny"></img> <img id="disp_next" src="images/next.png" onclick="javascript:next()" alt="Nastepny"></img>
</div> </div>
<div id="disp_info"></div> <div id="disp_info"></div>
<div><b>Autor:</b> <a id="disp_author"> </a></div> <div><b>Autor:</b> <a id="disp_author"> </a></div>

BIN
robocze/images/next.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 781 B

BIN
robocze/images/next_i.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
robocze/images/prev.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 788 B

BIN
robocze/images/prev_i.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 440 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 451 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 424 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 343 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 402 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 347 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 390 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 336 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 359 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

View File

@@ -1,10 +1,105 @@
<? <?
mysql_pconnect('HOST', 'USER', 'PASS'); /**
mysql_select_db('DB'); * @package Galeria Suczawa 2009
mysql_query("SET NAMES 'utf8'"); * @file init.php
* @version $Id$
* @author chp1994 <chp1994@gmail.com>
* @link http://suczawa.ath.cx/
**/
$per_page=6; #dołącz plik konfiguracyjny oraz funkcje
require('./config.php');
require('./functions.php');
$result = mysql_query('SELECT COUNT(id) FROM photos'); #sprawdź, czy jest wyłączone register globals oraz magic quotes?
$count= mysql_result($result, 0); if (ini_get('register_globals') == 1)
{
ini_set('register_globals', '0');
if (ini_get('register_globals') == 1)
{
blad('Could not disable register_globals.');
}
}
if (get_magic_quotes_gpc())
{
blad('Prosze wylaczyc magic_quotes_gpc w php.ini!');
}
#połącz z bazą danych
$DB = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
#sprawdź pomyślność połączenia
if ($DB->connect_error)
{
blad('Could not connect do database server ('.$DB->connect_errno.')'.$DB->connect_error);
}
if (!$DB->query("SET NAMES 'utf8'"))
{
blad('Could not set character to UTF-8');
}
#pobierz id pierwszego zdjęcia
$sql = "SELECT `id` FROM `photos` ORDER BY `id` LIMIT 1";
if (!$result = $DB->query($sql))
{
blad('Nie mozna odczytac id pierwszego zdjecia!');
}
$row = $result->fetch_assoc();
$firstid = $row['id'];
$result->free; //zwolnij pamięć
unset($row);
#pobierz id ostatniego zdjęcia
$sql = "SELECT `id` FROM `photos` ORDER BY `id` DESC LIMIT 1";
if (!$result = $DB->query($sql))
{
blad('Nie mozna odczytac id ostatniego zdjecia!');
}
$row = $result->fetch_assoc();
$lastid = $row['id'];
$result->free; //zwolnij pamięć
unset($row);
#pobierz liczbę zdjęć w galerii
$sql = "SELECT COUNT(`id`) AS `count` FROM `photos`";
if (!$result = $DB->query($sql))
{
blad('Nie mozna odczytac liczby zdjec!');
}
$row = $result->fetch_assoc();
$count = $row['count'];
$result->free; //zwolnij pamięć
//
//wygeneruj strone
//
if (isset($_GET['page'])&&($_GET['page']!=1))
{
if (!is_numeric($_GET['page']))
{
die('Hacking attempt');
}
$value = ($_GET['page']-1)*$per_page;
$limit = 'LIMIT '.$value . ', '.$per_page;
$page = $_GET['page'];
}
else
{
$limit = 'LIMIT 0, '.$per_page;
$page=1;
}
$cnt = ceil($count / $per_page);
if(isset($_GET['page']) && ($_GET['page']>$cnt))
{
blad('Podana strona nie istnieje!');
}
//
//koniec generowania stron
//
?> ?>

View File

@@ -79,17 +79,17 @@ function response() {
for(i=0; i<children.length; i++) { for(i=0; i<children.length; i++) {
disp_info.appendChild(children[i]); disp_info.appendChild(children[i]);
} }
disp_img.src=xml.getElementsByTagName("src")[0].firstChild.nodeValue; disp_img.src= 'images/upload/' + xml.getElementsByTagName("src")[0].firstChild.nodeValue;
disp_a.href=xml.getElementsByTagName("src")[0].firstChild.nodeValue; disp_a.href= 'images/upload/' + xml.getElementsByTagName("src")[0].firstChild.nodeValue;
disp_name.firstChild.nodeValue=xml.getElementsByTagName("name")[0].firstChild.nodeValue; disp_name.firstChild.nodeValue=xml.getElementsByTagName("name")[0].firstChild.nodeValue;
disp_author.firstChild.nodeValue=xml.getElementsByTagName("author")[0].firstChild.nodeValue; disp_author.firstChild.nodeValue=xml.getElementsByTagName("author")[0].firstChild.nodeValue;
if(xml.getElementsByTagName("last").length) { if(xml.getElementsByTagName("last").length) {
document.getElementById("disp_next").src="img/next_i.png"; document.getElementById("disp_next").src="images/next_i.png";
last=true; last=true;
} }
if(xml.getElementsByTagName("first").length) { if(xml.getElementsByTagName("first").length) {
document.getElementById("disp_prev").src="img/prev_i.png"; document.getElementById("disp_prev").src="images/prev_i.png";
first=true; first=true;
} }
disp.style.display="block"; disp.style.display="block";
@@ -99,13 +99,12 @@ function previewImage(el) {
curr=el; curr=el;
last=false; last=false;
first=false first=false
document.getElementById("disp_next").src="img/next.png"; document.getElementById("disp_next").src="images/next.png";
document.getElementById("disp_prev").src="img/prev.png"; document.getElementById("disp_prev").src="images/prev.png";
ajax.onreadystatechange = response; ajax.onreadystatechange = response;
ajax.open('GET', 'http://www.amharc.yoyo.pl/ask.php?name=' + el, true); ajax.open('GET', sciezka + 'ask.php?name=' + el, true);
ajax.send(null); ajax.send(null);
} }
function prev() { function prev() {
if(!first) previewImage(curr-1); if(!first) previewImage(curr-1);
} }

View File

@@ -2,6 +2,12 @@ body {
background-color: black; background-color: black;
text-align: center; text-align: center;
} }
a {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
#page { #page {
margin: auto; margin: auto;
width: 700px; width: 700px;
@@ -102,4 +108,3 @@ body {
#pages a, #pages a:link, #pages a:hover, #pages a:visited { #pages a, #pages a:link, #pages a:hover, #pages a:visited {
color: white; color: white;
} }