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

Document.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003  * ImaComm - a web based photo album software
00004  * Copyright (C) 2003, Mikko Kokkonen
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or (at
00009  * your option) any later version.
00010  * 
00011  * This program is distributed in the hope that it will be useful, but
00012  * WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * General Public License for more details.
00015  * 
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019  */
00029 $_document_prefix = realpath(dirname(__FILE__)."/../");
00030 require_once ($_document_prefix."/version.php");
00031 require_once ($_document_prefix."/classes/Translation.php");
00032 require_once ($_document_prefix."/classes/Album.php");
00033 
00037 define("NAVIGATION_STYLE_IMAGES",  2);
00041 define("NAVIGATION_STYLE_TEXT",    4);
00045 define("NAVIGATION_STYLE_NUMERIC", 8);
00049 define("NAVIGATION_TYPE_WIDE",    16);
00053 define("NAVIGATION_TYPE_TALL",    32);
00054 
00058 define("SIGN_TYPE_WIDE",          2);
00062 define("SIGN_TYPE_TALL",          4);
00063 
00064 class Document
00065 {
00066         // {{{ string title()
00072         function title()
00073         {
00074                 return "ImaComm";
00075         }
00076         // }}}
00077 
00078         // {{{ string version($type = VERSION_TYPE_SHORT)
00087         function version($type = VERSION_TYPE_SHORT)
00088         {
00089                 return versionInfo($type);
00090         }
00091         // }}}
00092 
00093         // {{{ string logo()
00100         function logo()
00101         {
00102                 // Are we under development...
00103                 $devpages = explode(":", "index:viewer");
00104                 $where = basename($_SERVER['PHP_SELF'], ".php");
00105                 if (in_array($where, $devpages))
00106                 {
00107                         $logo = "images/develop.png";
00108                 }
00109                 else
00110                 {
00111                         $logo = "images/logo.png";
00112                 }
00113                 $buf = "<img src=\"".$this->theme()."$logo\" alt=\"ImaComm\" id=\"logo\" />";
00114                 if (in_array($where, $devpages))
00115                 {
00116                         $buf .= "<span id=\"develop\">".translate("Sorry but this part of ImaComm is still under development process.")."</span>";
00117                 }
00118 
00119                 return $buf;
00120         }
00121         // }}}
00122 
00123         // {{{ string theme()
00129         function theme()
00130         {
00131                 return $_SESSION['theme'];
00132         }
00133         // }}}
00134 
00135         // {{{ string header()
00141         function header()
00142         {
00143                 // And what is our page...
00144                 $page = basename($_SERVER['PHP_SELF'], ".php");
00145 
00146                 if ($page == "index")
00147                 {
00148                         // Are we showing albums...
00149                         return "Photo albums";
00150                 }
00151                 if ($page == "viewer")
00152                 {
00153                         return "Photo viewer";
00154                 }
00155         }
00156         // }}}
00157 
00158         // {{{ string subheader()
00159         function subheader()
00160         {
00161                 return "Developer pre-release";
00162         }
00163         // }}}
00164         
00165         // {{{ string about($type)
00177         function about($type = ABOUT_TYPE_VERSION)
00178         {
00179                 $str = $this->version(VERSION_TYPE_LONG);
00180 
00181                 $buf = popupLink($str, "about.php");
00182 
00183                 return $buf;
00184         }
00185         // }}}
00186         
00187         // {{{ string navigation($type)
00201         function navigation($type = null)
00202         {
00203                 global $config, $albumdata;
00204 
00205                 if ($type == null)
00206                 {
00207                         $type = NAVIGATION_STYLE_IMAGES|NAVIGATION_TYPE_WIDE;
00208                 }
00209                 
00210                 // Generate buttons messages...
00211                 if ($type & NAVIGATION_STYLE_IMAGES)
00212                 {
00213                         $back = "<img src=\"".$this->theme()."/images/left.png\" alt=\"".translate("Previous")."\" border=\"0\" />";
00214                         $backi = getimagesize($this->theme()."/images/left.png");
00215                         $up = "<img src=\"".$this->theme()."/images/up.png\" alt=\"".translate("Go up")."\" border=\"0\" />";
00216                         $upi = getimagesize($this->theme()."/images/up.png");
00217                         $next = "<img src=\"".$this->theme()."/images/right.png\" alt=\"".translate("Next")."\" border=\"0\" />";
00218                         $nexti = getimagesize($this->theme()."/images/right.png");
00219                 }
00220                 
00221                 // Resolve our page...
00222                 $page = basename($_SERVER['PHP_SELF'], ".php");
00223 
00224                 // Resolve our album...
00225                 $album = ($_REQUEST['album'] == null) ? "-root-" : $_REQUEST['album'];
00226                 $nesting = $config->getNesting();
00227                 
00228                 $path = explode("/", $album);
00229                 $alb = array_pop($path);
00230                 
00231                 foreach ($path as $p)
00232                 {
00233                         $nesting = $nesting[$p];
00234                 }
00235                 $siblings = array_keys($nesting);
00236                 $path = implode("/", $path);
00237                 
00238                 // Are we on albums page...
00239                 if ($page == "index" && $album != "-root-")
00240                 {
00241                         $place = array_search($alb, $siblings);
00242                         // Back arrow...
00243                         // Do we have any previous albums...
00244                         if ($place > 0)
00245                         {
00246                                 $buf .= genLink($back, "album=$path/".$siblings[$place - 1]);
00247                                 if ($type & NAVIGATION_TYPE_TALL) { $buf .= "<br />"; }
00248                         }
00249                         else
00250                         {
00251                                 $buf .= "<img src=\"".$this->theme()."/images/null.png\" ".$backi[3]." alt=\" \" />";
00252                         }
00253                         
00254                         // Up arrow...
00255                         $buf .= genLink($up, "album=$path");
00256                         if ($type & NAVIGATION_TYPE_TALL) { $buf .= "<br />"; }
00257                         
00258                         // Next...
00259                         if ($place < (count($siblings) - 1))
00260                         {
00261                                 $buf .= genLink($next, "album=$path/".$siblings[$place + 1]);
00262                                 if ($type & NAVIGATION_TYPE_TALL) { $buf .= "<br />"; }
00263                         }
00264 
00265                 }
00266                 if ($page == "viewer")
00267                 {
00268                         $albumdata = get_albumdata($alb);
00269                         $place = $_REQUEST['image'];
00270                         if ($place > 0)
00271                         {
00272                                 $buf .= genLink($back, "album=".$_REQUEST['album'].":image=".($place - 1));
00273                         }
00274                         else
00275                         {
00276                                 $buf .= "<img src=\"".$this->theme()."/images/null.png\" ".$backi[3]." alt=\" \" />";
00277                         }
00278                         $buf .= genLink($up, "album=".$_REQUEST['album'], "index.php");
00279                         if ($place < (count($albumdata->photos) - 1))
00280                         {
00281                                 $buf .= genLink($next, "album=".$_REQUEST['album'].":image=".($place + 1));
00282                         }
00283                         if ($type & NAVIGATION_STYLE_NUMERIC)
00284                         {
00285                                 $buf .= "<br />".translate("Photo {0}/{1}", ($place + 1), count($albumdata->photos));
00286                         }
00287                 }
00288                 return $buf;
00289         }
00290         // }}}
00291 
00292         // {{{ string signinout($type = SIGN_TYPE_WIDE)
00301         function signinout($type = SIGN_TYPE_WIDE)
00302         {
00303                 global $theme, $language, $user, $config;
00304                 
00305                 // Are we logged in?
00306                 if ($_SESSION['logged'] == null && !isset($_REQUEST['signin']) && !isset($_REQUEST['dosignin']))
00307                 {
00308                         // No we aren't.
00309                         $buf .= genLink(translate("Sign in"), "signin");
00310                 }
00311 
00312                 // Sign out?
00313                 if ($_SESSION['logged'] != null)
00314                 {
00315                         $buf .= translate("Signed as {0}", $user->parameter("realname"))."<br />";
00316                         if ($config->option("modify_settings"))
00317                         {
00318                                 $buf .= genLink(translate("Modify settings"), null, "modify.php");
00319                                 if ($type == SIGN_TYPE_WIDE)
00320                                 {
00321                                         $buf .= "&nbsp;-&nbsp;";
00322                                 }
00323                                 else
00324                                 {
00325                                         $buf .= "<br />";
00326                                 }
00327                         }
00328                         if ($user->getClass() == "admin")
00329                         {
00330                                 $buf .= genLink(translate("Manage"), null, "admin.php");
00331                                 if ($type == SIGN_TYPE_WIDE)
00332                                 {
00333                                         $buf .= "&nbsp;-&nbsp;";
00334                                 }
00335                                 else
00336                                 {
00337                                         $buf .= "<br />";
00338                                 }
00339                         }
00340                         $buf .= genLink(translate("Sign out"), "signout");
00341                 }
00342                 
00343                 // Are we asked to sign in?
00344                 if ((isset($_REQUEST['signin']) || isset($_REQUEST['dosignin'])) && $_SESSION['logged'] == null)
00345                 {
00346                         $buf .= formBegin();
00347                         $buf .= "<table id=\"signin\">";
00348                         $buf .= "<tr><td align=\"right\">".translate("Username").":</td><td><input type=\"text\" name=\"username\" size=\"8\" tabstop=\"1\" /></td>";
00349                         if ($type == SIGN_TYPE_WIDE)
00350                         {
00351                                 $buf .= "<td rowspan=\"2\"><input type=\"submit\" name=\"dosignin\" value=\"".translate("Sign in")."\" tabstop=\"3\" id=\"action\" /></td>";
00352                         }
00353                         $buf .= "</tr>\n";
00354                         $buf .= "<tr><td align=\"right\">".translate("Password").":</td><td><input type=\"password\" name=\"password\" size=\"8\" tabstop=\"2\" /></td></tr>";
00355                         if ($type == SIGN_TYPE_TALL)
00356                         {
00357                                 $buf .= "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" name=\"dosignin\" value=\"".translate("Sign in")."\" tabstop=\"3\" id=\"action\" /></td></tr>";
00358                         }
00359                         $buf .= "</table>";
00360                         $buf .= formEnd();
00361                 }
00362                 
00363                 return $buf;
00364         }
00365         // }}}
00366         
00367         // {{{ string failedSignIn()
00375         function failedSignIn()
00376         {
00377                 if (isset($_REQUEST['dosignin']) && $_SESSION['logged'] == null)
00378                 {
00379                         $buf = translate("Failed to sign you in. Please check either your username or your password.");
00380                         $buf .= popupLink(translate("Forgot password?"), "mailpw.php");
00381                 }
00382                 return $buf;
00383         }
00384         // }}}
00385 
00386         // {{{ string albums()
00394         function albums()
00395         {
00396                 global $config, $settings, $themeEngine;
00397 
00398                 // Do we have albums path...
00399                 if ($_REQUEST['album'] == null)
00400                 {
00401                         $albpath = "-root-";
00402                 }
00403                 else
00404                 {
00405                         $albpath = $_REQUEST['album'];
00406                 }
00407 
00408                 $nesting = $config->getNesting();
00409                 // If we have something else than -root-...
00410                 if ($albpath != "-root-")
00411                 {
00412                         $path = explode("/", $albpath);
00413                         $p = $path;
00414                         $curalb = array_pop($p);
00415 
00416                         // Get all sub-albums...
00417                         foreach ($path as $pitem)
00418                         {
00419                                 $nesting = $nesting[$pitem];
00420                         }
00421                         if (is_array($nesting))
00422                         {
00423                                 $albums = array_keys($nesting);
00424                         }
00425                         else
00426                         {
00427                                 $albums = array();
00428                         }
00429                 }
00430                 else
00431                 {
00432                         // We have album and maybe sub-albums and photos...
00433                         // Get all subalbums first...
00434                         $nesting = $config->getNesting();
00435                         if (is_array($nesting[$albpath]))
00436                         {
00437                                 $albums = array_keys($nesting[$albpath]);
00438                         }
00439                         else
00440                         {
00441                                 $albums = array();
00442                         }
00443                         $items = null; // We don't support photos on root level!
00444                         $curalb = "-root-";
00445                 }
00446                 $tpl = $themeEngine->loadTemplate("albums");
00447                 // Start data row...
00448                 $buf .= $tpl['preblock'];
00449                 // And print all items...
00450                 $itemc = 0;
00451                 // Go through all albums first...
00452                 foreach ($albums as $alb)
00453                 {
00454                         if ($itemc == 0)
00455                         {
00456                                 $buf .= $tpl['prerow'];
00457                         }
00458                         // Generate code...
00459                         $album = new Album($config->albums[$alb]['source']);
00460                         $album->loadData();
00461                         list ($since, $count) = explode(":", $album->attribute("visited"));
00462                         $since = date("d.m.Y H:i", $since); // FIXME: Read date format from settings...
00463                         $albc = $nesting[$curalb][$alb];
00464                         if (is_array($albc))
00465                         {
00466                                 $albc = count(array_keys($albc));
00467                         }
00468                         else
00469                         {
00470                                 $albc = 0;
00471                         }
00472                         
00473                         $replace[0] = genLink($album->logo(), "album=$albpath/$alb");
00474                         $replace[1] = genLink($album->attribute("title"), "album=$albpath/$alb");
00475                         $replace[2] = $album->attribute("description");
00476                         $replace[3] = translate("Visited {0} times since {1}", $count, $since);
00477                         $replace[4] = null;
00478                         if ($albc > 0)
00479                         {
00480                                 if ($albc == 1)
00481                                 {
00482                                         $replace[4] = translate("{0} album", $albc);
00483                                 }
00484                                 else
00485                                 {
00486                                         $replace[4] = translate("{0} albums", $albc);
00487                                 }
00488                                 $replace[4] .= translate(" and ");
00489                         }
00490                         if (count($album->photos) > 0)
00491                         {
00492                                 if (count($album->photos) == 1)
00493                                 {
00494                                         $replace[4] .= translate("{0} photo", count($album->photos));
00495                                 }
00496                                 else
00497                                 {
00498                                         $replace[4] .= translate("{0} photos", count($album->photos));
00499                                 }
00500                         }
00501                         else
00502                         {
00503                                 $replace[4] .= translate(" no photos.");
00504                         }
00505 
00506                         $search = array('/\<logo\>/', '/\<title\>/', '/\<description\>/', '/\<visited\>/', '/\<itemscount\>/');
00507                         $buf .= preg_replace($search, $replace, $tpl['item']);
00508                         
00509                         $itemc++;
00510                         if ($itemc >= $tpl['itemsperrow'])
00511                         {
00512                                 $itemc = 0;
00513                                 $buf .= $tpl['postrow'];
00514                         }
00515                 }
00516                 $buf .= $tpl['postblock'];
00517 
00518                 // And then photos...
00519                 $tpl = $themeEngine->loadTemplate("photos");
00520                 
00521                 $album = new Album($config->albums[$curalb]['source']);
00522                 $album->loadData();
00523 
00524                 if (is_array($album->photos))
00525                 {
00526                         $buf .= $tpl['preblock'];
00527                         $itemc = 0;
00528                         foreach ($album->photos as $photo)
00529                         {
00530                                 if ($itemc == 0)
00531                                 {
00532                                         $buf .= $tpl['prerow'];
00533                                 }
00534                                 list($since, $clicks) = explode(":", $album->visited($album->photoID($photo)));
00535                                 $replace[0] = genLink($album->thumbnail($photo), "album=$albpath:image=".$album->photoID($photo), "viewer.php");
00536                                 $replace[1] = $this->caption($photo);
00537                                 if ($clicks == 0)
00538                                 {
00539                                         $replace[2] = "";
00540                                 }
00541                                 elseif ($clicks == 1)
00542                                 {
00543                                         $replace[2] = translate("Viewed {0} time.", $clicks);
00544                                 }
00545                                 else
00546                                 {
00547                                         $replace[2] = translate("Viewed {0} times.", $clicks);
00548                                 }
00549                                 $search = array('/\<thumbnail\>/', '/\<caption\>/', '/\<visited\>/');
00550                                 $buf .= preg_replace($search, $replace, $tpl['item']);
00551                                 $itemc++;
00552         
00553                                 if ($itemc >= $tpl['itemsperrow'])
00554                                 {
00555                                         $itemc = 0;
00556                                         $buf .= $tpl['postrow'];
00557                                 }
00558                         }
00559                         $buf .= $tpl['postblock'];
00560                 }
00561                 
00562                 return $buf;
00563         }
00564         // }}}
00565 
00566         // {{{ string photo()
00567         function photo()
00568         {
00569                 global $config, $albumdata;
00570                 
00571                 $album = array_pop(explode("/", $_REQUEST['album']));
00572                 $albumdata = get_albumdata($album);
00573                 $buf .= $albumdata->photo($_REQUEST['image']);
00574                 return $buf;
00575         }
00576         // }}}
00577 
00578         // {{{ string caption($photo)
00587         function caption($photo = null)
00588         {
00589                 global $config, $albumdata;
00590                 // resolve, if we have photo...
00591                 $album = array_pop(explode("/", $_REQUEST['album']));
00592                 $albumdata = get_albumdata($album);
00593                 if ($photo == null)
00594                 {
00595                         $photo = $_REQUEST['image'];
00596                 }
00597                 elseif (is_string($photo))
00598                 {
00599                         $photo = $albumdata->photoID($photo);
00600                 }
00601                 // We have photo...
00602 
00603                 return $albumdata->caption($photo);
00604         }
00605         // }}}
00606         
00607         // {{{ string comments()
00613         function comments()
00614         {
00615                 global $themeEngine, $albumdata, $config, $user;
00616                 
00617                 // What is our album...
00618                 $album = getAlbum();
00619 
00620                 // Are we on root level?
00621                 if ($album == "-root-")
00622                 {
00623                         return null;
00624                 }
00625                 
00626                 // Load our comments...
00627                 $albumdata = get_albumdata($album);
00628                 
00629                 // Wanna album or photo comment?
00630                 if (basename($_SERVER['PHP_SELF'], ".php") == "index")
00631                 {
00632                         $for = "-album-";
00633                 }
00634                 else
00635                 {
00636                         $for = ($_REQUEST['image'] == "") ? "-album-" : $albumdata->photos[$_REQUEST['image']];
00637                 }
00638 
00639                 $comments_source = $albumdata->attribute("comments");
00640 
00641                 $comments = new Comments($comments_source);
00642                 $comments->loadComments($for);
00643 
00644                 $tpl = $themeEngine->loadTemplate("comments");
00645 
00646                 if (is_array($comments->comments))
00647                 {
00648                         $tags = array("sender", "from", "time", "message", "manage");
00649                         foreach ($tags as $tag)
00650                         {
00651                                 $search[] = "/<$tag>/";
00652                         }
00653                         $buf .= $tpl['preblock'];
00654                         $itemc = 0;
00655                         foreach ($comments->comments as $comment)
00656                         {
00657                                 if ($itemc == 0)
00658                                 {
00659                                         $buf .= $tpl['prerow'];
00660                                 }
00661                                 $replace[0] = $comment['sender'];
00662                                 $replace[1] = $comment['from'];
00663                                 $replace[2] = date($config->option("dateformat"), $comment['time']);
00664                                 $replace[3] = $comment['message'];
00665                                 // And will we display manage-links?
00666                                 if ($comment['sender'] == $user->user || $user->class == "admin")
00667                                 {
00668                                         $img = "<img src=\"".$this->theme()."/images/delete.png\" alt=\"".translate("Delete")."\" />";
00669                                         $replace[4] = genLink($img, "delete");
00670                                 }
00671                                 else
00672                                 {
00673                                         $replace[4] = null;
00674                                 }
00675 
00676                                 $buf .= preg_replace($search, $replace, $tpl['item']);
00677                                 $itemc++;
00678 
00679                                 if ($itemc >= $tpl['itemsperrow'])
00680                                 {
00681                                         $itemc = 0;
00682                                         $buf .= $tpl['postrow'];
00683                                 }
00684                         }
00685                         $buf .= $tpl['postblock'];
00686                 }
00687                 
00688                 return $buf;
00689         }
00690         // }}}
00691 
00692         // {{{ string addCommentBox()
00701         function addCommentBox()
00702         {
00703                 global $config, $albumdata;
00704 
00705                 $album = getAlbum();
00706                 // We do not support comments on root level :-(
00707                 if ($album == "-root-")
00708                 {
00709                         return null;
00710                 }
00711                 
00712                 // Do we have support to add comments?
00713                 $albumdata = get_albumdata($album);
00714                 $comments = new Comments($albumdata->attribute("comments"));
00715                 if (onPage() == "index")
00716                 {
00717                         $for = "-album-";
00718                 }
00719                 else
00720                 {
00721                         $for = ($_REQUEST['image'] == "") ? "-album-" : $albumdata->photos[$_REQUEST['image']];
00722                 }
00723                 if (!$comments->canAdd($for))
00724                 {
00725                         return null;
00726                 }
00727                 
00728                 if (!$config->option('addcomments'))
00729                 {
00730                         return;
00731                 }
00732                 // Add a simple text area...
00733                 $buf .= formBegin();
00734                 $buf .= "<textarea rows=\"5\" cols=\"80\" name=\"newcomment\" id=\"newcomment\"></textarea><br />";
00735                 $buf .= "<input type=\"submit\" name=\"addcomment\" value=\"".translate("Add comment")."\" id=\"addcombtn\" />";
00736                 $buf .= "<span class=\"info_text\">".translate("Type your comment above. HTML codes are not supported unless &lt;b&gt;, &lt;/b&gt;,&lt;i&gt;,&lt;/i&gt;,&lt;u&gt; or &lt;/u&gt;")."</span>";
00737                 $buf .= formEnd();
00738                 return $buf;
00739         }
00740         // }}}
00741 }
00742 ?>

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