00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
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
00088 if ($for == "-album-")
00089 {
00090 return false;
00091 }
00092
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
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
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
00137 $comment = new Comment($comdata['message'], $comdata['from'], $comdata['sender']);
00138
00139 $photos[$p]->comments[] = $comment;
00140 }
00141 }
00142
00143 $pser = serialize($photos);
00144
00145
00146 $fp = fopen($photosrc, "w");
00147 if ($fp)
00148 {
00149 fputs($fp, $pser);
00150 fclose($fp);
00151 }
00152 }
00153 }
00154 ?>