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

common.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  */
00020 
00021 $_functions_prefix = realpath(dirname(__FILE__));
00022 require_once "$_functions_prefix/../platform.php";
00023 
00024 // {{{ array(source, module) generateModule($type)
00030 function generateModule($type, $src = null)
00031 {
00032         global $settings, $_functions_prefix;
00033 
00034         if (strtolower(get_class($settings)) != "settings")
00035         {
00036                 $ret = array(null, null);
00037         }
00038         else
00039         {
00040                 // If albums...
00041                 if ($type != "album")
00042                 {
00043                         $var = "{$type}_source";
00044                         $src = $settings->attribute($var);
00045                 }
00046                 // Resolve module..
00047                 // Are we supporting scheme...
00048                 preg_match("/^(.*?:\/\/)?(.*)/", $src, $match);
00049                 $scheme = substr($match[1], 0, -3);
00050                 $path = $match[2];
00051                 $pi = pathinfo($path);
00052                 $ext = strtolower($pi['extension']);
00053                 if (file_exists("$_functions_prefix/modules/{$type}_".strtolower("$scheme.php")))
00054                 {
00055                         $src = substr($src, strlen($scheme) + 3);
00056                         $out = array($src, "{$type}_".strtolower($scheme));
00057                 }
00058                 elseif (file_exists("$_functions_prefix/modules/{$type}_$ext.php"))
00059                 {
00060                         $out = array($src, "{$type}_$ext");
00061                 }
00062         }
00063         return $out;
00064 }
00065 // }}}
00066 
00067 // {{{ theme(string $theme)
00074 function theme( $theme )
00075 {
00076         // FIXME: Hard-coded theme dir? Use same theme-folder than ImaComm (i.e. same themes)
00077         $themedir = "../themes";
00078         // Do we have $theme?
00079         if (file_exists("$themedir/$theme/cfgindex.php"))
00080         {
00081                 // Using sessions...
00082                 session_register("theme");
00083                 $_SESSION['theme'] = "$themedir/$theme/";
00084         }
00085         else
00086         {
00087                 // Find 1st theme and use it...
00088                 $dir = dir($themedir);
00089                 while (false !== ($entry = $dir->read()))
00090                 {
00091                         if (file_exists($dir.path."/".$entry."/cfgindex.php"))
00092                         {
00093                                 session_register("theme");
00094                                 $_SESSION['theme'] = $dir.path."/".$entry."/";
00095                         }
00096                 }
00097                 // We don't have any themes installed!
00098                 die("<h1 style=\"color: #f00;\">Sorry :-(</h1><p>You haven't installed any themes. Before you can configure ImaComm, you need to install at least one theme.</p>\n<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>");
00099         }
00100 }
00101 // }}}
00102 
00103 // {{{ showPage()
00110 function showPage($objs = null)
00111 {
00112         global $document;
00113 
00114         // Load theme...
00115         $theme = $_SESSION['theme'];
00116         if (!isset($theme))
00117         {
00118                 print deverror("Session variable <b>theme</b> must be set before calling showPage()! Call theme(\"theme\") first!", true);
00119         }
00120         // Try to resolve our page...
00121         $page = basename($_SERVER['PHP_SELF'], ".php");
00122         $dirs = explode("/", dirname($_SERVER['PHP_SELF']));
00123         $dir = array_pop($dirs);
00124         if ($dir == "setup")
00125         {
00126                 $tpl = "cfg$page.php";
00127         }
00128         else
00129         {
00130                 $tpl = "$page.php";
00131         }
00132 
00133         // Load template...
00134         require_once "$theme/$tpl"; // Simple and nice, isn't it?
00135 }
00136 // }}}
00137 
00138 // {{{ string jsBegin()
00144 function jsBegin()
00145 {
00146         return "<script type=\"text/javascript\">\n<!--\n";
00147 }
00148 // }}}
00149 
00150 // {{{ string jsReplace($id, $innerHTML)
00159 function jsReplace($id, $innerHTML)
00160 {
00161         $buf .= "document.getElementById('$id').innerHTML = '$innerHTML';\n";
00162         return $buf;
00163 }
00164 // }}}
00165 
00166 // {{{ string jsEnd()
00172 function jsEnd()
00173 {
00174         return "\n// -->\n</script>\n";
00175 }
00176 // }}}
00177 
00178 // {{{ string status($msg)
00186 function status($msg = null)
00187 {
00188         $buf .= jsBegin();
00189         $buf .= jsReplace("statusmessage", $msg);
00190         $buf .= jsEnd();
00191         print $buf; flush();
00192 }
00193 // }}}
00194 
00195 // {{{ deverror($msg, $serious = false)
00201 function deverror($msg, $serious = false)
00202 {
00203         $msg = "<b>[Developer error]</b>: $msg<br />If you are not a developer, you just found a bug. Please report it with SourceForge Bugzilla! FIXME: Add address!";
00204         if ($serious)
00205         {
00206                 die($msg);
00207         }
00208         else
00209         {
00210                 return "$msg<br />";
00211         }
00212 }
00213 // }}}
00214 
00215 // {{{ noMethod($obj, $met)
00222 function noMethod($obj, $met)
00223 {
00224         return deverror("Object ".get_class($obj)." doesn't have method ".$met."!");
00225 }
00226 // }}}
00227 
00228 // {{{ string dprint($var)
00235 function dprint($var)
00236 {
00237         $buf = "<pre>";
00238         ob_start();
00239         print_r($var);
00240         $buf .= ob_get_contents();
00241         ob_end_clean();
00242         $buf .= "</pre>";
00243 
00244         return $buf;
00245 }
00246 // }}}
00247 
00248 // {{{ sring vprint($var)
00249 function vdprint($var)
00250 {
00251         ob_start();
00252         print"<pre>";var_dump($var);print"</pre>\n";
00253         $buf = ob_get_contents();
00254         ob_end_clean();
00255         return $buf;
00256 }
00257 ?>

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