Location: PHPKode > projects > Content*Builder > contentbuilder/main.php
<?php
global $debug_time_start;
$debug_time_start = microtime();

/**
 * cb_log()
 * Loggt bestimmte Ereignisse zur späteren Auswertung. Die Codes sind 
 * abhängig von der Interpretation.....
 * 
 * @param string $aktion Code der Aktion die geloggt werden soll
 **/
function cb_log($aktion) {
	$cbUserID = $GLOBALS[cbUserID];
	if(!empty($aktion)) {
		$zeit	= date("Y-m-d H:i:s");
		$IP		= $REMOTE_ADDR;
		$hostaddress = $_SERVER['REMOTE_ADDR'];
		if (!$hostaddress) { 
			$hostaddress = $_SERVER['REMOTE_HOST'];
		}
		$hostaddress = @GetHostByAddr($hostaddress);
		mysql_query("INSERT INTO ".TABLE."_stats VALUES ('$cbUserID','$aktion','$zeit','$IP  $hostaddress')");
	}
}

if(@session_start()) {
	
	/*
	#begin: PHP 4.2.0 compatible update
	*/
	extract($HTTP_GET_VARS);
	extract($HTTP_POST_VARS);
	extract($HTTP_SESSION_VARS);
	extract($_GET);
	extract($_POST);
	extract($_SESSION);
	/*
	#end
	*/

	if($logout == 1) {
		session_destroy();
		header("Location: index.php");
	}
	
	/* 
	* Show Menu Update #1 
	* Dieser Code Block übernimmt das ein- und ausblenden des 
	* Seitenmenus. Das Ergebnis wird in $cbMenu gespeichert. Es 
	* kann also von den Plugins noch verändert werden.
	*/
	if($_GET[cbMenuStage] != "") { $cbMenuStage = $_GET[cbMenuStage]; } else { $cbMenuStage = $_SESSION[cbMenuStage]; }
	if($cbMenuStage == "hidden") {
		$cbMenuNegativeStage = "visible";
		$cbMenu = false;
	} else {
		$cbMenuNegativeStage = "hidden";
		$cbMenuStage = "visible";
		$cbMenu = true;
	}
	$_SESSION["cbMenuStage"] = $cbMenuStage;
	/* end */
	
	require_once("root.inc");
	require_once($cbDirInclude."db.php");
	include_once($cbDirInclude."config.ini");
	include_once($cbDirInclude."languages.inc.php");
	include_once($cbDirLib."smarty/Smarty.class.php" );
	include_once($cbDirLib."CB_error.class.php" );
	include_once($cbDirLib."CB_media.class.php" );
	include_once($cbDirLib."CB_option.class.php" );
	include_once($cbDirLib."CB_perm.class.php" );
	require_once($cbDirLib."CB_plugin.class.php");
	
	/*
	* Initialisieren des Optionen Objekts für System Optionen
	*/
	$cbOption = new CBOption();
	$cbOption->setModule("system");
	$cbOption->getOptionList();
	
	/*
	* User Objekt anlegen. Anschließend Abfrage, ob User 
	* authentisiert ist
	*/
	$cbUser = new CBPerm();
	if(!$cbUser->isAuthenticated()) {
		session_destroy();
		header("Location: index.php");
		exit();
	}
	
	/*
	* Abfrage der wichtigsten Informationen des aktuellen Users
	*/
	$cbUserID    = $cbUser->getUserID();
	$cbUserGroup = $cbUser->getUserGroup();
	$cbPerms     = $cbUser->getPattern();
	
	/*
	* Initialisieren des Optionen Objekts für den aktuellen 
	* User und seine Optionen.
	*/
	$usrOption = new CBOption($cbUserID);
	$usrOption->setModule("user");
	$usrOption->getOptionList();
	
	/* 
	* Setzen eines Standard Skin Directory's falls die Option nicht 
	* gesetzt ist
	*/
	if(!$cbOption->getSingleOption("skinDir")) {
		$templateDir = "templates/default/";
	} else {
		$templateDir = $cbOption->getSingleOption("skinDir");
	}
	
	$cbDirGfx = $templateDir."images/gfx/";
	
	/* global gültige Konstante mit dem Pfad zum Skin anlegen */
	define("CB_TEMPLATE_DIR", $templateDir);
	/* patTemplate Objekt ableiten und Template Verzeichnis setzen */
	$tpl = new Smarty;
	$tpl->template_dir = CB_TEMPLATE_DIR;
	$tpl->compile_dir  = CB_TEMPLATE_DIR."compiled/";
	$tpl->config_dir   = CB_TEMPLATE_DIR."config/";

	/*
	* Ableiten des Plugin Objekts zum verwalten der Plugins 
	*/
	$cbPlugins  = new CB_plugin();
	
	/* 
	* Sprach Präfix abfragen (momentan de oder en)
	*/
	$lang_pf = $cbOption->getSingleOption("lang");
	$tpl->assign("LANGUAGE_PREFIX", $lang_pf);
	
	/*
	* Einbinden der Sprachdateien für Gruppen und Plugins
	*/
	$lang_path = $cbDirInclude."/language/";
	require_once($cbDirInclude."/language/".$lang_pf."/plugin.lang.php");
	require_once($cbDirInclude."/language/".$lang_pf."/group.lang.php");
	
	/*
	* Durchlaufen der Plugin Verzeichnisse und Einbinden der plugin.config
	*/
	$pluginsDir	    = dir($cbDirPlugin);
	while($pluginsDirEntry = $pluginsDir->read()) {
		if(is_dir($cbDirPlugin."/".$pluginsDirEntry) && ($pluginsDirEntry != ".") && ($pluginsDirEntry != "..")) {
			if(file_exists($cbDirPlugin."/".$pluginsDirEntry."/plugin.config")) {
				include($cbDirPlugin."/".$pluginsDirEntry."/plugin.config");
			}
		}
	}
	
	/* 
	* Normale Plugins abrufen
	*/
	$generalPlugins = $cbPlugins->getPluginsByType("general");
	if($generalPlugins != false) {
		foreach($generalPlugins as $v) {
			if($v->getValue("visibility") != "hidden") {
				/* 
				* Wenn Name im Language Array abgelegt ist, nimm diesen, 
				* ansonsten den, den das Plugin angegeben hat
				*/
				if($lang_plugin_plugin[$v->getValue("ident")] != "") {
					$thisPluginName = $lang_plugin_plugin[$v->getValue("ident")];
				} else {
					$thisPluginName = $v->getValue("name");
				}
				
				/*
				* Plugin Icon Leiste generieren
				*/
				if($v->getValue("position") == "headbar") {
					$menuHeadbarNames[]  = $thisPluginName;
					$menuHeadbarIdents[] = $v->getValue("ident");
					$menuHeadbarIcons[]  = $v->getValue("icon");
					
				}
				
				/* 
				* seitliches Zusatzmenu basteln
				*/
				if($v->getValue("position") == "menu") {
					if($v->getValue("group") != $lastGroup) {
						$thisGroup = $v->getValue("group");
						$htmlMenu .= "<b>".$lang_plugin_group[$thisGroup]."</b><br>";
					}
					$htmlMenu .= '<img src="'.$cbDirGfx.'moarrow.gif" width="8" align="middle" height="11"><a href="'.$PHP_SELF.'?load='.$v->getValue("ident").'">'.$thisPluginName.'</a><br>';
					$lastGroup = $v->getValue("group");
				}
			}
			if($v->getValue("ident") == $load) {
				$actualPlugin = $v;
			}
		}
	}
	
	if(is_object($actualPlugin)) {
		/*
		* compatibility to old system 
		*/
		$config['templates'] = $actualPlugin->getValue("templates");
		$config['urlIdent']  = $actualPlugin->getValue("ident");
		
		$mainDir = dirname(__FILE__);
		$pluginLocation = str_replace($mainDir."/", "", $actualPlugin->getValue("directory"));
		$pluginLocation = str_replace($mainDir."\\", "", $pluginLocation);
		$actualPlugin->setValue("directory", $pluginLocation);
		
		$pluginInclude  = $actualPlugin->getValue("directory")."/".$actualPlugin->getValue("file");
	} else {
		$pluginLocation = $cbDirPlugin.'/system_includes';
		if(empty($credits)) {
			$pluginInclude = $cbDirPlugin.'/system_includes/welcome.inc.php';
		} else {
			$pluginInclude = $cbDirPlugin.'/system_includes/credits.inc.php';
		}
	}

	### Starting the template output ###
	$t_basedir = CB_TEMPLATE_DIR;
	$t_images  = CB_TEMPLATE_DIR."images/";

	$tpl->assign("GFX",          $cbDirGfx);
	$tpl->assign("IMAGEDIR",     $t_images);
	$tpl->assign("TEMPLATE_DIR", $t_basedir);
	$tpl->assign("PHP_SELF",     $PHP_SELF);
	$tpl->assign("MENU_NEGATIVE_STAGE",   $cbMenuNegativeStage);
	$tpl->assign("MENU_STAGE",   $cbMenuStage);
	$tpl->assign("URLIDENT",     $load);
	$tpl->assign("SID",          $SID);
	
	/*
	* Permanent Feature
	*/
	$permanentWhitelistString = $usrOption->getSingleOption("permanentWhitelist");
	$permanentWhitelist = explode("|^|", $permanentWhitelistString);
		
	$permanentPlugins = $cbPlugins->getPluginsByType("permanent");
	if($permanentPlugins != false) {
		$permanentContent = array();
		foreach($permanentPlugins as $actualPermanentPlugin) {
			/* 
			* Nur die Permanents anzeigen, die in der Whitelist stehen
			*/
			if(in_array($actualPermanentPlugin->getValue("ident"), $permanentWhitelist)) {
				if(is_file($actualPermanentPlugin->getValue("directory").$actualPermanentPlugin->getValue("file"))) {
					ob_start();
						include($actualPermanentPlugin->getValue("directory").$actualPermanentPlugin->getValue("file"));
						$_tempPermContent = ob_get_contents();
					ob_end_clean();
					$permanentContent[] = $_tempPermContent;
				}
			}
		}
	}
	
	if(is_array($permanentContent) && count($permanentContent) > 0) {
		$tpl->assign("pluginPermanentsSet", "1");
		$tpl->assign("pluginPermanentsContent",
			array ( "CONTENT" => $permanentContent )
		);
	}
	
	$tpl->assign( "cb_head_menu",
		array ( "MODULE_NAME" => $menuHeadbarNames,
				"ICON"        => $menuHeadbarIcons,
				"URLIDENT"    => $menuHeadbarIdents
		)
	);

	$tpl->assign( "cb_html_menu", $htmlMenu );

	/*
	* Hauptplugin einbinden
	*/
	ob_start();
		$tpl->assign("SUB", $sub);
		$tpl->assign("PLUGINLOCATION", $pluginLocation);
		
		include($pluginInclude);
		$cbModuleContent = ob_get_contents();
	ob_end_clean();
		
	$tpl->assign("CB_MODULE_CONTENT", $cbModuleContent);
	
	global $debug_time_start;
	$debug_time_end = microtime();
	$start = explode(" ", $debug_time_start);
	$end = explode(" ", $debug_time_end);
	$elapsed = ($end[0] - $start[0]) + ($end[1] - $start[1]);
	$mtime=number_format( $elapsed, 3, ".", ",");

	$tpl->assign("cb_data", 
		array ( "VERSION"   => $version,
				"MICROTIME"	=> $mtime
		)
	);
	$tpl->display( "contentbuilder.template" );
} else { 
	header("Location: index.php");
}
?>
Return current item: Content*Builder