00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00030
00031 $add = array("album", "image");
00032
00033 $_functions_prefix = realpath(dirname(__FILE__));
00034
00041 function theme( $theme )
00042 {
00043 $themedir = "themes";
00044
00045 if (file_exists("$themedir/$theme/cfgindex.php"))
00046 {
00047
00048 session_register("theme");
00049 $_SESSION['theme'] = "$themedir/$theme/";
00050 return true;
00051 }
00052 else
00053 {
00054
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
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
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
00103 function onPage()
00104 {
00105 return basename($_SERVER['PHP_SELF'], ".php");
00106 }
00107
00108
00109
00116 function showPage()
00117 {
00118 global $document;
00119
00120
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
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
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";
00145 }
00146
00147
00148
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
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
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
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
00243 function formEnd()
00244 {
00245 $buf = "</form>";
00246
00247 return $buf;
00248 }
00249
00250
00251
00260 function popupLink($title, $href)
00261 {
00262 $buf = "<a href=\"$href\">$title</a>";
00263
00264 return $buf;
00265 }
00266
00267
00268
00278 function parseValue($value, $type)
00279 {
00280 global $_functions_prefix;
00281
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
00311 }
00312
00313
00314
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 ?>