Location: PHPKode > projects > Cynus > cynus/display.php
<?php
/**
 * @file display.php -- Controls how to display parts of Cynus publicly
 * @Id $Id: display.php,v 1.10 2004/07/30 13:08:21 jason Exp $
 *
 * Cynus - a web-based content manager
 * Copyright (C) 2003 Brett and Jason Profitt
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */

/**********************************
**********CONFIGURATION******
**********************************/

/*Cynus needs to know the location of the main cynus install.
If you haven't moved this file, then you shouldn't need to do
anything here. But, if you decide to put this somewhere else, then
you will have to set this variable.
If you do not know what this is, look in the online configuration
tool and click on "base" to edit. Then, look for the cynus_base_dir
variable. This value should be the same as it. This will be an 
absolute path to the directory, not one relative to the web directory.
Unlike all of the other variables in cynus, THIS NEEDS A TRAILING SLASH
*/
$base_dir='';

/********************************
*************DONE*************
********************************/

require_once("{$base_dir}config.php");
require_once("{$base_dir}display_func.php");
#require_once("$base_dir/load_cynus.php");

/********************
IF YOU EDIT CYNUS'S LOAD_CYNUS.PHP FUNCTION, EDIT THIS TOO!!1
*********************/
define("DEBUG_LEVEL", 0);
require_once ("{$base_dir}debug.php");
require_once("{$base_dir}main_func.php");

#connect to the mysql server
$sql_con=@mysql_connect("$config[sql_server]", "$config[sql_user]", "$config[sql_pass]") or
	cynus_error("Could not connect to MySQL server, exitting.");
#select the right database
@mysql_select_db("$config[sql_db]", $sql_con) or 
	cynus_error("Could not select the MySQL database, exitting.");

#Load the config table
$query="SELECT * from `$config[sql_prefix]config`";
$result=mysql_query($query);
while($each_variable = mysql_fetch_assoc($result)) {
	$var_name=$each_variable['name'];
	if($each_variable['section']!='base' && $each_variable['section'] != 'view_only') {
		$section=$each_variable['section'];
		$mod_conf[$section][$var_name]=$each_variable['value'];
	}
	else{
		$config[$var_name] = $each_variable['value'];
	}
}
$time=time();
$config['this_month']=date('n', $time);
$config['this_day']=date('j', $time);
$config['this_year']=date('Y', $time);
$config['month_array']=	array(1 => 'January',2 => 'February',3 => 'March',4 => 'April',
				5 => 'May',6 => 'June',7 => 'July',8 => 'August',
				9 => 'September',10 => 'October',11 => 'November',12 => 'December');




#So, now we can go ahead and require the right files for just the base. other 
#modules can include files they need when they're called. this should help
#speed up the parsing

#for login functions
require_once($base_dir . 'login_func.php');
#for the menu functions
require_once($base_dir . 'menu_func.php');
#for the messages functions
require_once($base_dir . 'messages_func.php');
#signal functions
require_once($base_dir . 'signal_func.php');
#for startup function goodness
require_once($base_dir . 'startup_func.php');

$user_config=check_login();
/********************
YOU'RE DONE
*********************/


#ok, now we have all of our standard function in case
#the display function that is called used them.

#we have a couple of things we can do. if they don't pick a module, we'll just
#print out all of the pages by module. otherwise, we'll give them what they ask
if($_GET['module'] != '') {
	#first step, check if the module exists
	$query="SELECT `id` from `$config[sql_prefix]modules` WHERE `name`='$_GET[module]'";
	$module_id=mysql_request($query);
	if($module_id['id']=='') {
		$error=1;
	}
	$query="SELECT * from `$config[sql_prefix]display` WHERE `module`='$module_id[id]' AND `active`='1'";
	$result=mysql_query($query);
	
	if(mysql_num_rows($result) < 1) {	
		$error=1;
	}
	if($error == 1) {
		$content .= <<<___eofh
There was an error while trying to complete your request. The most likely cause is that
you followed a link that was copied incorrectly. You can try browsing through 
<a href="display.php">available pages</a> to see if you can find what you are looking for.
___eofh;
	}
	else{
		$page=mysql_fetch_assoc($result);
		$content .= display_something($page);
	}
}
else{
	$content .= display_pages();
}

if($each_page['template']==0) {
	$where="`default`='1'";
}
else{
	$where="`id`='$each_page[id]'";
}

#do they want a template at all (from the url)?
if($_GET['t'] != -1) {
	#now what we need to do is format the page after getting the template
	if(($config['page_template']=='' || $config['page_template']==0) && $_GET['t'] == '') {
		#if they didn't define one, or they want 0, they need the default
		//$query="SELECT * from `$config[sql_prefix]templates` WHERE `default`='1'";
		//$template_info=mysql_request($query);
		$template=get_template();
	}
	else{
		$tid=set_default($config['page_template'], $_GET['t']);
		$template=get_template($tid);
	}
	
	//$template=implode("", file("$base_dir/templates/$template_info[file]"));
	if($template != '') {
		$page=eregi_replace("</head>", "$config[head_extra]\n</head>", $template);
		$page=ereg_replace("%%TITLE%%", "$config[page_title]", $page);
		$page=ereg_replace("%%CONTENT%%", "$content", $page);
		print $page;
		$did_page=1;
	}
}
#no template!
if($did_page != 1){
	print <<<___eofh
<html>
<head>
<title>$config[page_title]</title>
$config[head_extra]
</head>
<body>
$content
</body>
</html>
___eofh;
	
}


/*
This passes off control to the registered display controller
*/
function display_something(&$page) {
	global $config, $mod_conf, $user_config;
	
	#we need to get the module stuff again (don't worry, it's cached by now)
	$module_info=module_convert_id($page['module']);
	
	#let's require the stuff we need
	$includes=split("\|", $page['includes']);
	foreach($includes as $file) {
		require_once("$config[cynus_base_dir]/modules/$module_info[location]/$file");
	}
	
	#now let's call the function
	$command="\$content .= $page[display_function]();";
	eval("$command");
	return $content;
}

function display_pages() {
	global $config;
	$query="SELECT * from `$config[sql_prefix]display` WHERE `active`='1'";
	$result=mysql_query($query);
	while($each_page=mysql_fetch_assoc($result)) {
		#now we need to get this so we can do that and have fun fun fun!
		$module_info=module_convert_id($each_page['module']);
		if($each_page['extra_url'] != '') {$extra="&$each_page[extra_url]";}
		else{$extra='';}
		if($each_page['module'] != 0) {$module="module=$module_info[name]";}
		else{$module='';}
		$module_name=$module_info['name'];
		$displays[$module_name] = "<a href=\"display.php?$module$extra\">$module_info[friendly_name]</a><br />\n";
	}
	ksort($displays);
	foreach($displays as $page) {
		$content .= $page;
	}
	
	return $content;
}

?>
Return current item: Cynus