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

functions.php

Go to the documentation of this file.
00001 <?php
00002 /* $Id: functions.php,v 1.5 2003/10/03 15:27:31 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 
00030 // Global -> add these variables always everywhere!
00031 $add = array("album", "image");
00032 
00033 $_functions_prefix = realpath(dirname(__FILE__));
00034 // {{{ theme(string $theme)
00041 function theme( $theme )
00042 {
00043         $themedir = "themes";
00044         // Do we have $theme?
00045         if (file_exists("$themedir/$theme/cfgindex.php"))
00046         {
00047                 // Using sessions...
00048                 session_register("theme");
00049                 $_SESSION['theme'] = "$themedir/$theme/";
00050                 return true;
00051         }
00052         else
00053         {
00054                 // Find 1st theme and use it...
00055                 $dir = dir($themedir);
00056                 while (false !== ($entry = $dir->read()))
00057                 {
00058                         if (file_exists($dir.path."/".$entry."/cfgindex.php"))
00059                         {
00060                                 session_register("theme");
00061                                 $_SESSION['theme'] = $dir.path."/".$entry."/";
00062                                 return true;
00063                         }
00064                 }
00065                 // We don't have any themes installed!
00066                 $msg = "<h1 style=\"color: #f00;\">Sorry :-(</h1>";
00067                 $msg .= "<p>You haven't installed any themes. Before you can configure ImaComm, you need to install at least one theme.</p>";
00068                 $msg .= "<p>If you just extract ImaComm from package then you did have a mispackged version. Please download a ImaComm always from its homepage, <a href=\"http://imacomm.sourceforge.net\">http://imacomm.sourceforge.net</a>.<br />If you did downloaded this package from there, please send a bug report <a href=\"FIXME: LINK HERE\">FIXME: LINK HERE</a></p>";
00069                 $msg .= "<p><font size=\"-1\">Technical information: You tried to load theme $theme</font></p>";
00070                 die($msg);
00071         }
00072         return false;
00073 }
00074 // }}}
00075 
00076 // {{{ string getAlbum()
00083 function getAlbum()
00084 {
00085         $album_path = explode("/", $_REQUEST['album']);
00086         $album = array_pop($album_path);
00087         if ($album == "")
00088         {
00089                 $album = "-root-";
00090         }
00091 
00092         return $album;
00093 }
00094 // }}}
00095 
00096 // {{{ string onPage()
00103 function onPage()
00104 {
00105         return basename($_SERVER['PHP_SELF'], ".php");
00106 }
00107 // }}}
00108 
00109 // {{{ showPage()
00116 function showPage()
00117 {
00118         global $document;
00119 
00120         // Load theme...
00121         $theme = $_SESSION['theme'];
00122         if (!isset($theme))
00123         {
00124                 print deverror("Session variable <b>theme</b> must be set before calling showPage()! Call theme(\"theme\") first!", true);
00125         }
00126         // Try to resolve our page...
00127         $page = basename($_SERVER['PHP_SELF'], ".php");
00128         $dirs = explode("/", dirname($_SERVER['PHP_SELF']));
00129         $dir = array_pop($dirs);
00130         if ($dir == "setup")
00131         {
00132                 $tpl = "cfg$page.php";
00133         }
00134         else
00135         {
00136                 $tpl = "$page.php";
00137         }
00138 
00139         // Load template...
00140         if (!file_exists("$theme/$tpl"))
00141         {
00142                 print deverror("Theme $theme is not installed correctly. File $tpl is missing from theme folder!", true);
00143         }
00144         require_once "$theme/$tpl"; // Simplae and nice, isn't it?
00145 }
00146 // }}}
00147 
00148 // {{{ deverror($msg, $serious = false)
00157 function deverror($msg, $serious = false)
00158 {
00159         $msg = "<b>[Developer error]</b>: (".__FILE__.":".__LINE__.") $msg<br />If you are not a developer, you just found a bug. Please report it with SourceForge Bugzilla! FIXME: Add address!";
00160         if ($serious)
00161         {
00162                 die($msg);
00163         }
00164         else
00165         {
00166                 return "$msg<br />";
00167         }
00168 }
00169 // }}}
00170 
00171 // {{{ string genLink($title = null, $vars = null, $href = null)
00182 function genLink($title = null, $vars = null, $href = null)
00183 {
00184         global $add;
00185         $vars = explode(":", $vars);
00186         $href = ($href == null) ? $_SERVER['PHP_SELF'] : $href;
00187         
00188         $reqvar = $_REQUEST;
00189         // Split vars from values...
00190         foreach ($vars as $var)
00191         {
00192                 if (strstr($var, '=') !== false)
00193                 {
00194                         list ($var, $value) = explode("=", $var);
00195                         $reqvar[$var] = $value;
00196                 }
00197                 $variables[] = $var;
00198         }
00199         $vars = array_merge($add, $variables);
00200         $vars = array_unique($vars);
00201         
00202         $buf = "<a href=\"$href?";
00203         foreach ($vars as $var)
00204         {
00205                 $buf .= "$var=".$reqvar[$var]."&";
00206         }
00207         $buf .= "\">$title</a>\n";
00208 
00209         return $buf;
00210 }
00211 // }}}
00212 
00213 // {{{ string formBegin($href = null, $method = "post")
00222 function formBegin($href = null, $method = "post")
00223 {
00224         global $add;
00225         $href = ($href == null) ? $_SERVER['PHP_SELF'] : $href;
00226 
00227         $buf = "<form method=\"$method\" action=\"$href\">";
00228         foreach ($add as $var)
00229         {
00230                 $buf .= "<input type=\"hidden\" name=\"$var\" value=\"".$_REQUEST[$var]."\" />\n";
00231         }
00232 
00233         return $buf;
00234 }
00235 // }}}
00236 
00237 // {{{ string formEnd()
00243 function formEnd()
00244 {
00245         $buf = "</form>";
00246 
00247         return $buf;
00248 }
00249 // }}}
00250 
00251 // {{{ string popupLink($title, $href)
00260 function popupLink($title, $href)
00261 {
00262         $buf = "<a href=\"$href\">$title</a>";
00263 
00264         return $buf;
00265 }
00266 // }}}
00267 
00268 // {{{ mixed parseValue($value, $type)
00278 function parseValue($value, $type)
00279 {
00280         global $_functions_prefix;
00281         // Accept boolean values
00282         $boolval = array(
00283                         "true"  => true,
00284                         "yes"   => true,
00285                         "1"     => true,
00286                         "false" => false,
00287                         "no"    => false,
00288                         "0"     => false);
00289 
00290         if ($type == "boolean")
00291         {
00292                 return $boolval[$value];
00293         }
00294         if ($type == "string")
00295         {
00296                 return $value;
00297         }
00298         if ($type == "integer")
00299         {
00300                 settype($value, "integer");
00301                 return $value;
00302         }
00303         if ($type == "theme")
00304         {
00305                 if (is_dir("$_functions_prefix/themes/$value"))
00306                 {
00307                         return "$value";
00308                 }
00309         }
00310         // FIXME: More types?
00311 }
00312 // }}}
00313 
00314 // {{{ string dprint($var)
00321 function dprint($var)
00322 {
00323         $buf = "<pre>";
00324         ob_start();
00325         print_r($var);
00326         $buf .= ob_get_contents();
00327         ob_end_clean();
00328         $buf .= "</pre>";
00329 
00330         return $buf;
00331 }
00332 // }}}
00333 ?>

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