00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 $_functions_prefix = realpath(dirname(__FILE__));
00022 require_once "$_functions_prefix/../platform.php";
00023
00024
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
00041 if ($type != "album")
00042 {
00043 $var = "{$type}_source";
00044 $src = $settings->attribute($var);
00045 }
00046
00047
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
00074 function theme( $theme )
00075 {
00076
00077 $themedir = "../themes";
00078
00079 if (file_exists("$themedir/$theme/cfgindex.php"))
00080 {
00081
00082 session_register("theme");
00083 $_SESSION['theme'] = "$themedir/$theme/";
00084 }
00085 else
00086 {
00087
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
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
00110 function showPage($objs = null)
00111 {
00112 global $document;
00113
00114
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
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
00134 require_once "$theme/$tpl";
00135 }
00136
00137
00138
00144 function jsBegin()
00145 {
00146 return "<script type=\"text/javascript\">\n<!--\n";
00147 }
00148
00149
00150
00159 function jsReplace($id, $innerHTML)
00160 {
00161 $buf .= "document.getElementById('$id').innerHTML = '$innerHTML';\n";
00162 return $buf;
00163 }
00164
00165
00166
00172 function jsEnd()
00173 {
00174 return "\n// -->\n</script>\n";
00175 }
00176
00177
00178
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
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
00222 function noMethod($obj, $met)
00223 {
00224 return deverror("Object ".get_class($obj)." doesn't have method ".$met."!");
00225 }
00226
00227
00228
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
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 ?>