DanielP Skrevet 26. oktober 2003 Del Skrevet 26. oktober 2003 Skal ha bildefremvisning på siden min. Men til nå har jeg ikke funnet noe jeg er fornøyd med. Og håper noen kan hjelpe meg. Kriteriene er: Være raskt, og enkelt. Skal kunne integreres i siden min.(ingen popup side) Og skal ikke åpne ett nytt uavhengig område. Kommer ikke på mer Håper noen kan komme med bra forslag Takker DanielP Lenke til kommentar
mikk- Skrevet 26. oktober 2003 Del Skrevet 26. oktober 2003 (endret) OK, dette er løsningen vi bruker på [url="http://www.klubblan.net/index.php?side=showimages"]Klubblan.net[/url]. Altså: Showimages.htm inkluderes i index.php (som er hovedsiden/"malen") Showimages.htm ser slik ut: [code] <?php ob_start(); // File: $Id: index.php,v 1.11 2003/09/01 // ---------------------------------------------------------------------- // PHP Sanctum Gallery // Copyright (C) 2003 by Duncan O'Neil // http://www.donnchadh.co.uk/ // ---------------------------------------------------------------------- // LICENSE // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License (GPL) // as published by the Free Software Foundation; either version 2 // 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 General Public License for more details. // // To read the license please visit http://www.gnu.org/copyleft/gpl.html // ---------------------------------------------------------------------- // Original Author of this file: Duncan O'Neil // Purpose of this file: To display images and comments // ---------------------------------------------------------------------- // Local Variables $path_to_imgs = "bilder"; //path from this file to the directory holding the images $imgExten = array("bmp","jpg","gif","png","tga"); //add to this as needed $admin_name = "admin"; // change this $admin_pass = "passord"; // change this function default_func() { if (!$currDir) { $currDir = "/"; } //display list of galleries dispGallery($currDir); } function dispGallery($ident) { global $path_to_imgs, $currDir; if (!$currDir) { $currDir = "/"; } dispGalLinks($currDir); echo "<br/><br/>"; //display list of galleries dispGallFunc($currDir); //display list of images $searchDir = $path_to_imgs . $currDir; $galFiles = get_dirFiles($searchDir); if ($galFiles != NULL) { sort ($galFiles); reset ($galFiles); echo "<br/>Bilder i denne kategorien:<br/>"; foreach ($galFiles as $file) { echo "<a class=\"innhold\" href=index.php?side=showimages&action=dispImage&currDir=".rawurlencode($currDir)."&imgDisp=".rawurlencode($file).">$file</a>"; $filename = substr(getcwd() . "/" . $path_to_imgs . $currDir . $file, 0, -3) . "pgc"; if (file_exists($filename)) { echo "*"; } echo "<br/>"; } } } function dispImage() { //display single image global $path_to_imgs, $currDir, $imgDisp; $filename = getcwd() . "/" . $path_to_imgs . $currDir . $imgDisp; if (file_exists($filename)) { echo "<p class='bigtitle' align=center>$imgDisp</p>\n"; dispGalLinks($currDir); echo "<br/><br/>"; dispNextLast(); echo "<p align=center>"; if (is_imageFile($filename)) { if ($_COOKIE["phps_poll_admin"] == "Confirm") { echo "<a class=\"innhold\" href='". $path_to_imgs . $currDir . $imgDisp . "' />Image $imgDisp Linked</a><br/>"; $commentfile = substr($filename, 0, -3) . "pgc"; if (file_exists($commentfile)) { $cfile = substr($imgDisp, 0, -3) . "pgc"; echo "<form action='index.php?side=showimages&action=edit_comment&currDir=".rawurlencode($currDir)."&cfile=".rawurlencode($cfile)."&imgDisp=".rawurlencode($imgDisp)."' method='post'>"; $cfloc = $path_to_imgs . $currDir . $cfile; $fp = fopen($cfloc, "r"); $contents = fread ($fp, filesize ($cfloc)); fclose($fp); $comments = split('<hr>', $contents); $comments = array_filter($comments, "strlen"); foreach($comments as $count => $comment) { echo "<br/><table align='center'><tr><th colspan='2'>Comment ".++$count."</th></tr>"; $comment = eregi_replace("<b>Posted (on|by): </b>",'',$comment); $comment = ereg_replace("(\r\n|\n|\r)", "<br />", $comment); $comment = split('<br />', $comment); $comment = array_filter($comment, "strlen"); $comment_block = ""; foreach($comment as $key => $comment_line) { if ($key == 0) { if (eregi("<a href=\"mailto:(.*)\">(.*)</a>",$comment_line,$regs)) { echo "<tr><td>Name: </td><td><input type='text' value='$regs[2]' name='cmt_name_$count'></td></tr>"; echo "<tr><td>Email: </td><td><input type='text' value='$regs[1]' name='cmt_mail_$count'></td></tr>"; } else { echo "<tr><td>Name: </td><td><input type='text' value='$comment_line' name='cmt_name_$count'></td></tr>"; echo "<tr><td>Email: </td><td><input type='text' value='' name='cmt_mail_$count'></td></tr>"; } } elseif ($key == 1) { echo "<input type='hidden' value='$comment_line' name='cmt_date_$count'>"; } elseif ($key > 1) { $comment_block .= $comment_line . "\r\n"; } } echo "<tr><td valign='top'>Comment: </td><td><textarea cols='20' rows='5' name='cmt_text_$count'>$comment_block</textarea></td></tr>"; echo "<tr><td> </td><td><input type='checkbox' name='delete_$count'>Delete Comment</td></tr>"; echo "</table>"; } echo "<p align='center'><input type='submit' value='Update Comments'></p></form>"; } else { echo "<p align='center'>No comments posted for this image</p>"; } } else { echo "<img src='". $path_to_imgs . $currDir . $imgDisp . "' />"; $commentfile = substr($filename, 0, -3) . "pgc"; $cfile = substr($imgDisp, 0, -3) . "pgc"; echo "<br/><br/><table align='center' width='70%'><tr><td>"; echo "<p align='center' class=\"innhold\"><a class=\"innhold\" href=index.php?side=showimages&action=writeComment&currDir=".rawurlencode($currDir)."&cfile=".rawurlencode($cfile)."&imgDisp=".rawurlencode($imgDisp)."><Legg til kommentar></a></p>"; if (file_exists($commentfile)) { include($commentfile); } else { echo "<p align='center'></p>"; } echo "</tr></td></table>"; } } else { echo "<pre>"; include($filename); echo "</pre>"; } echo "</p>\n"; dispNextLast(); } else { echo "<p>Bildet finnes ikke.</p>"; dispGallery($ident); } } function edit_comment() { global $path_to_imgs, $currDir, $cfile, $imgDisp; foreach ($_POST as $key => $value) { if (substr($key, 0, 4) == "cmt_") { $keys = split('_', $key); ${$keys[1]}[$keys[2]] = $value; } if (substr($key, 0, 7) == "delete_") { $keys = split('_', $key); ${$keys[0]}[$keys[1]] = $value; } } $num_entries = count($name); $cfile_content = ""; //do fopen option w $cfile_ref = fopen ($path_to_imgs . $currDir . $cfile, "w"); for ($i = 1; $i <= $num_entries; $i++) { if ($delete[$i] == "on") { /* do nothing */ } else { //strip invalid chars $text[$i] = bbcode2html($text[$i]); $text[$i] = ereg_replace("(\r\n|\n|\r)", "<br />",$text[$i]); //build content string $cfile_content .= "<b>Posted by: </b>"; if ($mail[$i]) { $cfile_content .= "<a class=\"innhold\" href=\"mailto:".$mail[$i]."\">".$name[$i]."</a>"; } else { $cfile_content .= $name[$i]; } $cfile_content .= "\r\n<b>Posted on: </b>" . $date[$i] . "\r\n\r\n".$text[$i]."\r\n<hr>"; } } //write to file if (!fwrite($cfile_ref, $cfile_content)) { echo "could not write to file"; } //close file fclose($cfile_ref); //redisplay image dispImage(); } function is_imageFile($filename) { global $imgExten; if (in_array(strtolower(substr($filename, -3)), $imgExten)) { return(True); } } function dispGallFunc($currDir) { global $path_to_imgs; $searchDir = $path_to_imgs . $currDir; $galDirs = get_subDirs($searchDir); if ($galDirs != NULL) { sort ($galDirs); reset ($galDirs); echo "<br/>Galleri:<br/>"; foreach ($galDirs as $dir) { $newDir = $currDir . $dir . "/"; echo "<a class=\"innhold\" href=index.php?side=showimages&action=dispGallery&currDir=".rawurlencode($newDir).">$dir</a><br/>"; } echo "<br/>"; } } function dispNextLast() { global $path_to_imgs, $currDir, $imgDisp; //display Next/Last links $searchDir = $path_to_imgs . $currDir; $galFiles = get_dirFiles($searchDir); if (($galFiles != NULL) && (count($galFiles) > 1)) { echo "<table width='70%' align='center' border='0'><tr>\n"; sort ($galFiles); reset ($galFiles); $imgPos = array_search($imgDisp,$galFiles); if ($imgPos != 0) { //display link to Previous echo "<td align='center'><a class=\"innhold\" href=index.php?side=showimages&action=dispImage&currDir=".rawurlencode($currDir)."&imgDisp=".rawurlencode($galFiles[$imgPos-1])."><< Forige</a></td>\n"; } if ($imgPos != count($galFiles) -1) { //display link to Next echo "<td align='center'><a class=\"innhold\" href=index.php?side=showimages&action=dispImage&currDir=".rawurlencode($currDir)."&imgDisp=".rawurlencode($galFiles[$imgPos+1]).">Neste >></a></td>\n"; } echo "</tr></table>\n"; } } function dispGalLinks($currDir) { $arr_dirs = split("/",$currDir); $lowerDir = "/"; echo "<b><a class=\"innhold\" href=index.php?side=showimages>Hovedgalleriet</a></b>"; foreach ($arr_dirs as $dirs) { if ($dirs != "") { $lowerDir .= $dirs."/"; echo " -> <b><a class=\"innhold\" href=index.php?side=showimages&action=dispGallery&currDir=".rawurlencode($lowerDir).">$dirs</a></b>"; } } } function writeComment() { global $path_to_imgs, $currDir, $cfile, $imgDisp; global $pgcName, $pgcEmail, $pgcComment; dispGalLinks($currDir); echo ": " . $imgDisp; //display form to enter details ?> <form action=<? echo "index.php?side=showimages&action=insertComment&currDir=".rawurlencode($currDir)."&cfile=".rawurlencode($cfile)."&imgDisp=".rawurlencode($imgDisp); ?> method=post> <table align="center"> <tr><td align="right" class="innhold">Navn: </td><td width="20"> </td><td align="left"><input class="input-text" type="text" name="pgcName" value="<? echo $pgcName; ?>" /></td></tr> <tr><td align="right" class="innhold">E-post: </td><td width="20"> </td><td align="left"><input class="input-text" type="text" name="pgcEmail" value="<? echo $pgcEmail; ?>" /></td></tr> <tr><td align="right" valign="top" class="innhold">Kommentar: </td><td width="20"> </td><td align="left" valign="top"><textarea class="input-text" rows="8" cols="20" name="pgcComment"><? echo $pgcComment; ?></textarea></td></tr> <tr><td> </td><td width="20"><td align="left"><input class="input-button" type="submit" value="Send Kommentar"></td></tr> </table> </form> <p align="center" class="innhold">Du kan bruke følgende BBkode:</p> <table align="center"> <tr><td align="left" class="innhold">[b] <b>fet</b></td></tr> <tr><td align="left" class="innhold">[i] <i>kursiv</i></td></tr> <tr><td align="left" class="innhold">[u] <u>underlinjet</u></td></tr> <tr><td align="left" class="innhold">[url=<i>adresse</i>]<i>tekst</i>[/url] <a class="innhold">Link</a></td></tr> </table> <? } function insertComment() { global $path_to_imgs, $currDir, $cfile, $imgDisp; global $pgcName, $pgcEmail, $pgcComment; //check passed vars if (!$pgcName || !$pgcComment || !preg_match( "/[[:alnum:]]/ix", $pgcName)) { echo "<b>Missing Required Field(s)</b><br/><br/>"; writeComment(); } else { //do fopen option a $cfile_ref = fopen ($path_to_imgs . $currDir . $cfile, "a"); //strip invalid chars $pgcComment = strip_tags($pgcComment); $pgcComment = bbcode2html($pgcComment); $pgcComment = ereg_replace("(\r\n|\n|\r)", "<br />",$pgcComment); //build content string $cfile_content = ""; if ($pgcEmail) { $cfile_content .= "<font class=\"innhold\"><a class=\"innhold\" href=\"mailto:$pgcEmail\">$pgcName</a> >"; } else { $cfile_content .= "<font class=\"innhold\"><a class=\"innhold\">$pgcName</a> >"; } $cfile_content .= "$pgcComment</font><br><br>"; //write to file if (!fwrite($cfile_ref, $cfile_content)) { echo "could not write to file"; } //close file fclose($cfile_ref); //redisplay image dispImage(); } } //returns an array of sub directories within the specified directory function get_subDirs($dir) { if ($handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { $workingDir = getcwd(); chdir($dir); if (is_dir($file) && !ereg('[.]+',$file)) { $list_of_dirs[] = $file; } chdir($workingDir); } closedir($handle); return $list_of_dirs; } } //returns an array of files within the specified directory, excepting the index.php file function get_dirFiles($dir) { if ($handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { $workingDir = getcwd(); chdir($dir); if (!is_dir($file) && !eregi('index.php?side=showimages',$file) && !eregi('[[:alnum:]].pgc',$file)) { $list_of_dirs[] = $file; } chdir($workingDir); } closedir($handle); return $list_of_dirs; } } //convert bbcode to html function bbcode2html($messagetext) { $messagetext = stripslashes($messagetext); $search = array( '#\[url]([a-z]+?://){1}(.*?)\[/url]#i', '#\[url](.*?)\[/url\]#i', '#\[url=([a-z]+?://){1}(.*?)\](.*?)\[/url]#i', '#\[b](.*?)\[/b\]#i', '#\[i](.*?)\[/i\]#i', '#\[u](.*?)\[/u\]#i', ); $replace = array( '<a href="\1\2">$1$2</a>', '<a href=http://\1\2>\1</a>', '<a href="\1\2">\3</a>', '<b>\1</b>', '<i>\1</i>', '<u>\1</u>', ); $messagetext = preg_replace($search, $replace, $messagetext); return $messagetext; } function login() { echo " <table width='428'> <tr><td valign='top'><h2>Admin Login</h2></td></tr> </table> <form action='index.php?side=showimages&action=verify_admin' method='post'> <table border='0' style='margin-left:40'> <tr> <td>Brukernavn</td><td><input type='text' name='username'></td> </tr> <tr> <td>Passord</td><td><input type='password' name='password'</td> <td align='right'><input type='submit' value='Login'></td> </tr> </table> </form> "; } function verify_admin() { global $admin_name, $admin_pass; if (($_POST['username'] == $admin_name) && ($_POST['password'] == $admin_pass)) { setcookie ("phps_poll_admin", "Confirm"); Header("Location: index.php?side=showimages"); exit(); } else { Header("Location: index.php?side=showimages&action=login"); exit(); } } function logout() { setcookie ("phps_poll_admin", "LoggedOut"); Header("Location: index.php?side=showimages"); exit(); } echo " <table align='center' border='0' width='428' cellpadding='0' cellspacing='0'> <tr> <td width='428' class=\"innhold\"><br />"; if ($_COOKIE["phps_poll_admin"] == "Confirm") { echo "<p align='center'>Logged in as Admin - <a href='index.php?side=showimages&action=logout'>Logout</a></p>"; } if (!$action || !function_exists($action)) { default_func(); } else { $action($ident); } echo " </td></tr></table>"; ?> [/code] Scriptet heter egentlig PHP Sanctum Gallery. Og det gjør det nå og forskjåvidt. Men jeg har moddet det ganske kraftig, blant annet oversatt, gjort om på mye struktur og design ++ Bildene legger du i bilder/. Du kan, og det er meningen at du skal gjøre det, legge bildene i mapper under bilder/. Bildene blir da arrangert i "gallerier" etter navnet på den mappa de ligger i. Husk å CHMODde mappene. Endret 26. oktober 2003 av Mikka Lenke til kommentar
DanielP Skrevet 26. oktober 2003 Forfatter Del Skrevet 26. oktober 2003 Nice Mikka. Takker DanielP Lenke til kommentar
Anbefalte innlegg
Opprett en konto eller logg inn for å kommentere
Du må være et medlem for å kunne skrive en kommentar
Opprett konto
Det er enkelt å melde seg inn for å starte en ny konto!
Start en kontoLogg inn
Har du allerede en konto? Logg inn her.
Logg inn nå