diff --git a/robocze/ask.php b/robocze/ask.php index 88bfeb7..100eb4e 100644 --- a/robocze/ask.php +++ b/robocze/ask.php @@ -1,14 +1,16 @@ -'; -?> - - -query('SELECT * FROM photos WHERE id=\'$i\'')) +'; +?> + + +query($sql)) { showError('MySQL error'); } @@ -28,24 +30,24 @@ else $row['author'] = ($row['author']=='') ? 'Autor nieznany' : $row['author']; $row['description'] = ($row['description']=='') ? 'Brak opisu' : $row['description']; -} -?> - - - - -query('SELECT COUNT(id) FROM photos WHERE id<'.$id)->fetch_row(); #check if there are some previous photos - $prev=$prev[0]; - if($prev>0) { - $prev=$DB->query('SELECT * FROM photos WHERE id<'.$id.' ORDER BY id DESC LIMIT 1;')->fetch_assoc(); #if yes, get the previous photo's data - echo ''; #and send it - } - $next = $DB->query('SELECT COUNT(id) FROM photos WHERE id>'.$id)->fetch_row(); #check if there are some next photos - $next=$next[0]; - if($next>0) { - $next=$DB->query('SELECT * FROM photos WHERE id>'.$id.' ORDER BY id ASC LIMIT 1;')->fetch_assoc(); #if yes, get the next photo's data - echo ''; #and send it - } -?> - +} +?> + + + + +query('SELECT COUNT(id) FROM photos WHERE id<'.$id)->fetch_row(); #check if there are some previous photos + $prev=$prev[0]; + if($prev>0) { + $prev=$DB->query('SELECT * FROM photos WHERE id<'.$id.' ORDER BY id DESC LIMIT 1;')->fetch_assoc(); #if yes, get the previous photo's data + echo ''; #and send it + } + $next = $DB->query('SELECT COUNT(id) FROM photos WHERE id>'.$id)->fetch_row(); #check if there are some next photos + $next=$next[0]; + if($next>0) { + $next=$DB->query('SELECT * FROM photos WHERE id>'.$id.' ORDER BY id ASC LIMIT 1;')->fetch_assoc(); #if yes, get the next photo's data + echo ''; #and send it + } +?> + diff --git a/robocze/config.php b/robocze/config.php index 73f5325..21cdd8d 100644 --- a/robocze/config.php +++ b/robocze/config.php @@ -1,7 +1,7 @@ - + diff --git a/robocze/display.php b/robocze/display.php index d2d8d77..28427ab 100644 --- a/robocze/display.php +++ b/robocze/display.php @@ -1,33 +1,35 @@ - 0 || - strpos($_SERVER["HTTP_USER_AGENT"], "W3C_Validator")!==false || - strpos($_SERVER["HTTP_USER_AGENT"], "WebKit")!==false; - header('Content-Type: '.($xhtml?'application/xhtml+x':'text/ht').'ml; charset="utf-8"'); #IE doesn't support application/xhtml+xml - workaround - echo ''; -?> - - - - - Podgląd zdjęcia nr <?=$id?> - - - - - -
+ + + + + + Podgląd zdjęcia nr <?=$id?> + + + + + +
query('SELECT * FROM photos WHERE id=\'$i\'')) +$sql = "SELECT * FROM `photos` WHERE id='$id'"; +if (!$result = $DB->query($sql)) { - showError('MySQL error'); + showError('Nie mozna pobrac informacji o zdjeciu!'); } if ($result->num_rows == 0) @@ -45,61 +47,62 @@ else $row['author'] = ($row['author']=='') ? 'Autor nieznany' : $row['author']; $row['description'] = ($row['description']=='') ? 'Brak opisu' : $row['description']; -}?> -
- Zdjęcie -
- Autor:
- Opis: -
-query('SELECT COUNT(id) FROM photos WHERE id<'.$id)->fetch_row(); #check if there are some previous photos -$prev=$prev[0]; -if($prev>0) { -$prev=$DB->query('SELECT * FROM photos WHERE id<'.$id.' ORDER BY id DESC LIMIT 1;')->fetch_assoc(); #if yes, get the previous photo's data -?> - - - -query('SELECT COUNT(id) FROM photos WHERE id>'.$id)->fetch_row(); #check if there are some next photos -$next=$next[0]; -if($next>0) { -$next=$DB->query('SELECT * FROM photos WHERE id>'.$id.' ORDER BY id ASC LIMIT 1;')->fetch_assoc(); #if yes, get the next photo's data -?> - - - - -
- - +} +?> +
+ ZdjÄ_cie +
+ Autor:
+ Opis: +
+query('SELECT COUNT(id) FROM photos WHERE id<'.$id)->fetch_row(); #check if there are some previous photos +$prev=$prev[0]; +if($prev>0) { +$prev=$DB->query('SELECT * FROM photos WHERE id<'.$id.' ORDER BY id DESC LIMIT 1;')->fetch_assoc(); #if yes, get the previous photo's data +?> + + + +query('SELECT COUNT(id) FROM photos WHERE id>'.$id)->fetch_row(); #check if there are some next photos +$next=$next[0]; +if($next>0) { +$next=$DB->query('SELECT * FROM photos WHERE id>'.$id.' ORDER BY id ASC LIMIT 1;')->fetch_assoc(); #if yes, get the next photo's data +?> + + + + +
+ + diff --git a/robocze/functions.php b/robocze/functions.php index d59e50b..b242693 100644 --- a/robocze/functions.php +++ b/robocze/functions.php @@ -1,5 +1,78 @@ - + +* @link http://suczawa.ath.cx/ +**/ + +#wyświetl błąd +function blad($msg) +{ + die(' +

Blad Galerii Zdjec Suczawa 2009!

+ '.$msg.''); +} + +function NaglowekXHTML() +{ + $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 || + strpos($_SERVER["HTTP_USER_AGENT"], "W3C_Validator")!==false || + strpos($_SERVER["HTTP_USER_AGENT"], "WebKit")!==false; + + header('Content-Type: '.($xhtml?'application/xhtml+x':'text/ht').'ml; charset="utf-8"'); #IE doesn't support application/xhtml+xml - workaround + + echo ''; +} + +function GenerujListeStron() +{ + global $cnt; + global $page; + $content = ''; + + if ($page>1) + { + $content .= '«'; + $content .= '  < '; + } + + #wygeneruj strony + for ($i=1;$i<=$cnt;$i++) + { + if ($i==$page) + { + if ($i == $cnt) + { + $content .= ''.$i.''; + } + else + { + $content .= ''.$i.''.' | '; + } + } + else + { + if ($i == $cnt) + { + $content .= ''.$i.' '; + } + else + { + $content .= ''.$i.' | '; + } + } + } + #dodaj linka "+1 strona" oraz do ostatniej + if ($page<$cnt) + { + $content .= '>'; + $content .= '  »'; + } + + #dodaj linka do ostatniej strony + echo $content; +} +?> diff --git a/robocze/gallery.php b/robocze/gallery.php index 1cdabe0..b1e59f0 100644 --- a/robocze/gallery.php +++ b/robocze/gallery.php @@ -1,75 +1,58 @@ - 0 || - strpos($_SERVER["HTTP_USER_AGENT"], "W3C_Validator")!==false || - strpos($_SERVER["HTTP_USER_AGENT"], "WebKit")!==false; - header('Content-Type: '.($xhtml?'application/xhtml+x':'text/ht').'ml; charset="utf-8"'); #IE doesn't support application/xhtml+xml - workaround - echo ''; -?> - - - - - Galeria zdjęć - - - - -
- Logo strony -
-
query('SELECT * FROM photos LIMIT '.(($page-1)*PERPAGE).' , '.PERPAGE)) { - showError('MySQL error'); - } - while($row = $result->fetch_assoc() ){ -?> -
- - Zdjęcie: <?=$row['photo_name']?> - -
- -
-query('SELECT COUNT(id) AS count FROM photos')) { - showError('MySQL error'); +/** +* @package Galeria Suczawa 2009 +* @file gallery.php +* @version $Id$ +**/ + +$page = (isset($_GET['page'])) ? intval($_GET['page']) : 0; + +require_once('./init.php'); #init stuff +NaglowekXHTML(); +?> + + + + + Galeria Zdjęć + + + + +
+ Logo strony +
+
+query($sql)) + { + blad('Nie mozna pobrac zdjec uzytkownikow!'); } - $row = $result->fetch_assoc(); - $count = $row['count']; - $pcount=ceil($result[0]/PERPAGE); -?> -
Strony: - << < | '; - for($i=1; $i<$page; $i++) { - echo ''.$i.' | '; - } - echo $page.' | '; - for($i=$page+1; $i<=$pcount; $i++) { - echo ''.$i.' | '; - } - if($page==$pcount) - echo '> >>'; - else - echo '> >>'; - ?> -
-
- -
- - + while($row = $result->fetch_assoc() ) + { +?> +
+ + Zdj___cie: <?= $row['photo_name']; ?> + +
+ +
+
Strony: + +
+
+ +
+ + diff --git a/robocze/index.php b/robocze/index.php index 914c510..9bb64f6 100644 --- a/robocze/index.php +++ b/robocze/index.php @@ -1,34 +1,31 @@ - 0 || - strpos($_SERVER["HTTP_USER_AGENT"], "W3C_Validator")!==false || - strpos($_SERVER["HTTP_USER_AGENT"], "WebKit")!==false; - header('Content-Type: '.($xhtml?'application/xhtml+x':'text/ht').'ml; charset="utf-8"'); #IE doesn't support application/xhtml+xml - workaround - echo ''; -?> - - - - - Strona główna - - - -
- Logo strony -
- -
- -
- - + + + + + + Strona Główna + + + +
+ Logo strony +
+ +
+ +
+ + diff --git a/robocze/init.php b/robocze/init.php index c9344ed..8c6be3b 100644 --- a/robocze/init.php +++ b/robocze/init.php @@ -1,12 +1,78 @@ -connect_error) { #check if there were any errors connecting - showError('Could not connect do database server ('.$DB->connect_errno.'): '.$DB->connect_error); +if ($DB->connect_error) +{ #check if there were any errors connecting + blad('Could not connect do database server ('.$DB->connect_errno.'): '.$DB->connect_error); +} + +if (!$DB->query("SET NAMES 'utf8'")) #użyj utf-8 +{ + blad('Could not set character to UTF-8'); +} + + +#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)*PERPAGE; + $limit = 'LIMIT '.$value . ', '.PERPAGE; + $page = $_GET['page']; +} +else +{ + $limit = 'LIMIT 0, '.PERPAGE; + $page=1; +} +$cnt = ceil($count / PERPAGE); +if(isset($_GET['page']) && ($_GET['page']>$cnt)) +{ + blad('Podana strona nie istnieje!'); } -if (!$DB->query("SET NAMES 'utf8'")) { #use utf-8 - showError('Could not set character to UTF-8'); -} -?> +// +//koniec generowania stron +// +?> diff --git a/robocze/script.js b/robocze/script.js index 71c77f1..5aa4aa9 100644 --- a/robocze/script.js +++ b/robocze/script.js @@ -1,103 +1,104 @@ -var ajax, previd, nextid; - -function init() { - initAjax(); - if (!document.importNode) { - document.importNode = function(node, allChildren) { - switch (node.nodeType) { - case 1: - var newNode = document.createElement(node.nodeName); - if (allChildren && node.childNodes && node.childNodes.length > 0) { - il=node.childNodes.length; - for (var i = 0; i < il; i++) - newNode.appendChild(document.importNode(node.childNodes[i], allChildren)); - } - return newNode; - break; - default: - return document.createTextNode(node.nodeValue); - break; - } - }; - } - - nextid=(document.getElementById("next_image")!=null)?document.getElementById("next_image").alt:-1; - previd=(document.getElementById("prev_image")!=null)?document.getElementById("prev_image").alt:-1; -} - -function initAjax() { - try { - if (window.XMLHttpRequest) { - ajax = new XMLHttpRequest(); - ajax.overrideMimeType('text/xml'); - } - else if (window.ActiveXObject) - ajax = new ActiveXObject('Microsoft.XMLHTTP'); - else throw 'AJAX Error'; - } - catch (e) { - return false; - } - if (!ajax) { - alert('AJAX Error'); - return false; - } - return true; -} - - -function response() { - if (ajax.readyState != 4 || ajax.status != 200) - return; - - var xml = ajax.responseXML; - document.getElementById("curr_image").parentNode.href=document.getElementById("curr_image").src=xml.getElementsByTagName("current")[0].getAttribute("src"); - document.getElementById("author").firstChild.nodeValue=xml.getElementsByTagName("author")[0].firstChild.nodeValue; - - desc=document.getElementById("description"); - while(desc.hasChildNodes()) desc.removeChild(desc.firstChild); - - children=document.importNode(xml.getElementsByTagName("desc")[0], true).childNodes; - for(i=0; i0) { - document.getElementById("next_image").src=xml.getElementsByTagName("next")[0].getAttribute("thumb"); - nextid=xml.getElementsByTagName("next")[0].getAttribute("id"); - document.getElementById("next_image").alt=nextid; - document.getElementById("next").style.display="block"; - } - else { - document.getElementById("next").style.display="none"; - nextid=-1; - } - - if(xml.getElementsByTagName("prev").length>0) { - document.getElementById("prev_image").src=xml.getElementsByTagName("prev")[0].getAttribute("thumb"); - previd=xml.getElementsByTagName("prev")[0].getAttribute("id"); - document.getElementById("prev_image").alt=previd; - document.getElementById("prev").style.display="block"; - } - else { - document.getElementById("prev").style.display="none"; - previd=-1; - } -} - -function previewImage(el) { - if(el==-1) return 0; - ajax.onreadystatechange = response; - ajax.open('GET', path+ '/ask.php?id=' + el, true); - ajax.send(null); -} - -function prev() { - previewImage(previd); -} - -function next() { - previewImage(nextid); -} +var ajax, previd, nextid; + +function init() { + initAjax(); + if (!document.importNode) { + document.importNode = function(node, allChildren) { + switch (node.nodeType) { + case 1: + var newNode = document.createElement(node.nodeName); + if (allChildren && node.childNodes && node.childNodes.length > 0) { + il=node.childNodes.length; + for (var i = 0; i < il; i++) + newNode.appendChild(document.importNode(node.childNodes[i], allChildren)); + } + return newNode; + break; + default: + return document.createTextNode(node.nodeValue); + break; + } + }; + } + + nextid=(document.getElementById("next_image")!=null)?document.getElementById("next_image").alt:-1; + previd=(document.getElementById("prev_image")!=null)?document.getElementById("prev_image").alt:-1; +} + +function initAjax() { + try { + if (window.XMLHttpRequest) { + ajax = new XMLHttpRequest(); + ajax.overrideMimeType('text/xml'); + } + else if (window.ActiveXObject) + ajax = new ActiveXObject('Microsoft.XMLHTTP'); + else throw 'AJAX Error'; + } + catch (e) { + return false; + } + if (!ajax) { + alert('AJAX Error'); + return false; + } + return true; +} + + +function response() { + if (ajax.readyState != 4 || ajax.status != 200) + return; + + var xml = ajax.responseXML; + document.getElementById("curr_image").parentNode.href=document.getElementById("curr_image").src='images/upload/'+xml.getElementsByTagName("current")[0].getAttribute("src"); + document.title = 'Podgląd zdjęcia nr ' + xml.getElementsByTagName("current")[0].getAttribute("id"); + document.getElementById("author").firstChild.nodeValue=xml.getElementsByTagName("author")[0].firstChild.nodeValue; + + desc=document.getElementById("description"); + while(desc.hasChildNodes()) desc.removeChild(desc.firstChild); + + children=document.importNode(xml.getElementsByTagName("desc")[0], true).childNodes; + for(i=0; i0) { + document.getElementById("next_image").src='images/upload/'+xml.getElementsByTagName("next")[0].getAttribute("thumb"); + nextid=xml.getElementsByTagName("next")[0].getAttribute("id"); + document.getElementById("next_image").alt=nextid; + document.getElementById("next").style.display="block"; + } + else { + document.getElementById("next").style.display="none"; + nextid=-1; + } + + if(xml.getElementsByTagName("prev").length>0) { + document.getElementById("prev_image").src='images/upload/'+xml.getElementsByTagName("prev")[0].getAttribute("thumb"); + previd=xml.getElementsByTagName("prev")[0].getAttribute("id"); + document.getElementById("prev_image").alt=previd; + document.getElementById("prev").style.display="block"; + } + else { + document.getElementById("prev").style.display="none"; + previd=-1; + } +} + +function previewImage(el) { + if(el==-1) return 0; + ajax.onreadystatechange = response; + ajax.open('GET', path+ '/ask.php?id=' + el, true); + ajax.send(null); +} + +function prev() { + previewImage(previd); +} + +function next() { + previewImage(nextid); +}