Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

comments_gallery.php

Go to the documentation of this file.
00001 <?php
00002 /* $Id: comments_xml.php,v 1.1 2003/10/03 15:28:41 mikko Exp $ */
00003 /*
00004  * ImaComm - a web based photo album software
00005  * Copyright (C) 2003, Mikko Kokkonen
00006  *
00007  * This program is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or (at
00010  * your option) any later version.
00011  * 
00012  * This program is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00020  */
00021 
00034 class Comments_gallery extends Comments
00035 {
00036         var $comments;
00037 
00038         function loadComments($dir, $for)
00039         {
00040                 global $settings;
00041                 
00042                 require_once ($settings->attribute("gallery_location")."/classes/Image.php");
00043                 require_once ($settings->attribute("gallery_location")."/classes/AlbumItem.php");
00044                 require_once ($settings->attribute("gallery_location")."/classes/Comment.php");
00045 
00046                 $albumsrc = $dir."/album.dat";
00047                 $photosrc = $dir."/photos.dat";
00048 
00049                 ob_start();
00050                 readfile($albumsrc);
00051                 $aser = ob_get_contents();
00052                 ob_clean();
00053                 readfile($photosrc);
00054                 $pser = ob_get_contents();
00055                 ob_end_clean();
00056 
00057                 $data = unserialize($aser);
00058                 $photos = unserialize($pser);
00059 
00060                 if ($data->version != 10)
00061                 {
00062                         return;
00063                 }
00064                 // Find correct photo...
00065                 for ($p = 0; $p < count($photos); $p++)
00066                 {
00067                         $name = $photos[$p]->image->name.".".$photos[$p]->image->type;
00068                         $resized = $photos[$p]->image->resizedName.".".$photos[$p]->image->type;
00069                         if ($name == $for || $resized == $for)
00070                         {
00071                                 $comments = $photos[$p]->comments;
00072                                 for ($c = 0; $c < count($comments); $c++)
00073                                 {
00074                                         $data = array(
00075                                                         "sender"  => $comments[$c]->name,
00076                                                         "from"    => $comments[$c]->IPNumber,
00077                                                         "time"    => $comments[$c]->datePosted,
00078                                                         "message" => $comments[$c]->commentText);
00079                                         $this->comments[] = $data;
00080                                 }
00081                         }
00082                 }
00083         }
00084 
00085         function canAdd($dir, $for)
00086         {
00087                 // No support for album level...
00088                 if ($for == "-album-")
00089                 {
00090                         return false;
00091                 }
00092                 // Do we have write support?
00093                 if (!is_writable($dir."/photos.dat"))
00094                 {
00095                         return false;
00096                 }
00097                 return true;
00098         }
00099 
00100         
00101         function addComment($dir, $comdata)
00102         {
00103                 // Loading files...
00104                 global $settings;
00105                 
00106                 require_once ($settings->attribute("gallery_location")."/classes/Image.php");
00107                 require_once ($settings->attribute("gallery_location")."/classes/AlbumItem.php");
00108                 require_once ($settings->attribute("gallery_location")."/classes/Comment.php");
00109 
00110                 $albumsrc = $dir."/album.dat";
00111                 $photosrc = $dir."/photos.dat";
00112 
00113                 ob_start();
00114                 readfile($albumsrc);
00115                 $aser = ob_get_contents();
00116                 ob_clean();
00117                 readfile($photosrc);
00118                 $pser = ob_get_contents();
00119                 ob_end_clean();
00120 
00121                 $data = unserialize($aser);
00122                 $photos = unserialize($pser);
00123 
00124                 if ($data->version != 10)
00125                 {
00126                         return;
00127                 }
00128         
00129                 // Find our photo...
00130                 for ($p = 0; $p < count($photos); $p++)
00131                 {
00132                         $name = $photos[$p]->image->name.".".$photos[$p]->image->type;
00133                         $resized = $photos[$p]->image->resizedName.".".$photos[$p]->image->type;
00134                         if ($comdata['for'] == $name || $comdata['for'] == $resized)
00135                         {
00136                                 // We have photo...
00137                                 $comment = new Comment($comdata['message'], $comdata['from'], $comdata['sender']);
00138                                 // And add a new comment...
00139                                 $photos[$p]->comments[] = $comment;
00140                         }
00141                 }
00142                 // And ready to save...
00143                 $pser = serialize($photos);
00144 //              $aser = serialize($data);
00145                 // And save data back...
00146                 $fp = fopen($photosrc, "w");
00147                 if ($fp)
00148                 {
00149                         fputs($fp, $pser);
00150                         fclose($fp);
00151                 }
00152         }
00153 }
00154 ?>

Generated on Sun Oct 19 11:08:00 2003 for ImaComm by doxygen1.3