Forum core source dump (as of July 31)

lib/main.php

/**
* Main forum functionality.
* Class calls and rendering functionality is incorportaed into this file.
*
* @author Eksith Rodrigo
* @version 0.1
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/


// Initiate presets array
$presets = array();

// Get the preset configuration
require_once($rt . 'config.php');


//Begin closed check
if(!$presets['site_closed'])
{

	/******************************************************************************
		Core Code
	*******************************************************************************/
	
	// Begin session
	session_start();
	
	// Global error storage
	$errors = '';
	
	
	// If not being redirected after login or logout, initiate modules.
	// The Render module is required for the forums to function)
	$modules = Modules::getInstance($presets, $database, array("Render", "Wysiwyg"));
	
	// Initiate core (also initiates $database variable)
	$core = Core::getInstance($presets, $database, $modules);
	
	
	// User has asked to logout
	if($core->checkLogout())
	{
		$core->logout();
	}
	
	// User has asked to login
	if($core->checkLogin())
	{
		$core->login();
	}

	/*
	// After getting a redirect page request
	if(isset($_GET['redir']))
	{	
		$req = $core->decrypt($_GET['redir']);
		
		if($core->verifyURL($req))
		{
			header("Location: "+ $req)
			exit;
		}
		else
		{
			header("Location: "+ $presets['site_url']);
			exit;
		}
		}
	*/
	
	
	// Get status and location data
	$core->getUserData($userID, $username, $privileges, $lastID, $exc);
	
	
	// Store status and Forum data for modules and templates
	$mdata = array();
	
	// Load the presets into this array
	$mdata['presets'] = $presets;
	
	// This is for the </title><title> tag and must not contain any HTML tags.
	$mdata['presets']['site_ptitle'] = $core->getDefaultText($presets['site_title'], '');
	
	// Check user status. No userID = anonymous.
	$mdata['is_anonymous'] = (empty($userID))? true : false;
	
	// Posting status
	$mdata['is_newTopic'] = $core->postingNewTopic();
	$mdata['is_newReply'] = $core->postingNewReply();
	
	// Browsing status
	$mdata['is_index'] = $core->browsingIndex();
	$mdata['is_forum'] = $core->browsingForum();
	$mdata['is_topic'] = $core->browsingTopic();
	$mdata['is_section'] = $core->browsingSection();
	
	// Posting data
	$mdata['post_title'] = $core->postTitle();
	$mdata['post_author'] = $core->postAuthor();
	$mdata['post_email'] = $core->postEmail();
	$mdata['post_content'] = $core->postContent();
	
	// Form data
	$mdata['form_name'] = ($mdata['is_newTopic'])? "topicform" : "replyform";
	
	$mdata['forum_id'] = $core->postForumID();
	$mdata['topic_id'] = $core->postTopicID();
	$mdata['parent_id'] = $core->postParentID();
	
	$mdata['page'] = $core->currentPage();
	
	$mdata['site'] = array();
	$mdata['language'] = array();
	$mdata['navigation'] = array();
	
	// This page is requested in AJAX mode (Not used at this time)
	$mdata['is_ajaxmode'] = (isset($_GET['ajax']))? true : false;
	
	$mdata['replies_list'] = array();
	$mdata['forum_list'] = array();
	$mdata['replies_list'] = array();
	
	
	/******************************************************************************
		Page building
	******************************************************************************/
	
	if($mdata['is_topic'])
	{
		// We're on a topic
		
		$database->Open();
		
		$mdata['replies_list'] = $database->getReplies($mdata['topic_id'], 0, 5);
		
		$database->Close();
	}
	elseif($mdata['is_forum'])
	{
		// We're on a forum
		
		$database->Open();
		
		$mdata['forum_list'] = $database->getForums($mdata['forum_id']);
		$mdata['topics_list'] = $database->getTopics($mdata['forum_id'], 0, 5);
		
		$database->Close();
	}
	elseif($mdata['is_index'])
	{
		// We're on the homepage
		
		$database->Open();
		
		$mdata['forum_list'] = $database->getForums(0);
		$mdata['topics_list'] = $database->getTopics(1, 0, 5, true);
		$mdata['replies_list'] = $database->getReplies(1, 0, 5);
		
		$database->Close();
	}
	elseif($mdata['is_section'])
	{
		// We're on a plugin specific page
		// TODO Plugin render functionality
	}
	else
	{
		// Something strange is going on. Do nothing...
	}
	
	
	
	/******************************************************************************
		Template specific methods.
		Variable based functions to be called within templates.
	******************************************************************************/
	
	/**
	* Calls module functions for a specific region on the template and gets the combined output from all modules
	*
	* @param string $region Template region to be rendered;
	*/
	$render = create_function('$region', 'global $modules, $mdata; return $modules->__trigger($region, $mdata);');
	
	/**
	* Clean method for removing old region data within loops in templates
	*
	* @param string $region Template region to be cleaned;
	*/
	$clean = create_function('$region', 'global $modules; $modules->__clean($region);');
	
	
	// Template building
	
	if($mdata['is_index'])
		include_once($presets['site_root'] . 'templates/'. $presets['site_theme'] . '/main.php');




	/******************************************************************************
		Core functions
	******************************************************************************/
	
	// Cleanup and error display. 
	function shutdown()
	{
		global $errors, $render, $clean;
		
		// Empty the dynamic function variables
		$render = null;
		$clean = null;
		
		if(!empty($errors))
		{
			header('Content-Type: text/html; charset=UTF-8');
			echo($errors);
		}
	}
	
	// End of execution cleanup
	register_shutdown_function('shutdown');

}
else
{

/******************************************************************************
	Forum is closed
******************************************************************************/

// Create closed page
$html =< <<HTML
<html>
<head>
	<title>{$presets['site_title']}</title>
	<style type="text/css">
		body { font:normal 81% "Segoe UI", "Myriad", "Trebutchet MS", sans-serif; }
	</style>
</head>
<body>
	{$presets['site_closed_message']}
</body>

HTML;

echo $html;
} // End closed check
Advertisement

6 thoughts on “Forum core source dump (as of July 31)

  1. Pingback: I have developer ADHD « This page intentionally left ugly

  2. This was a very interesting read for me!
    Although I have a question,
    I am a beginning php programmer, currently developing drupal modules on my internship, but looking to develop some sort of forum script/cms/framework/… . I’m not planning on actually making it public, it’s just a personal project to teach myself some things. So, my question…, I saw in your main.php you do:
    Core::getInstance and Modules::getInstance, is it the same as doing:
    $core = new Core();
    $core->getInstance(…); ? and did you have to define ‘Core’ somewhere or does php automatically recognise it as a class and searches for it (with the autoload function you wrote)?
    thanks in advance!

    You can contact me on my email if you want

    • Hi Jelle

      Yes, the basic idea is to let the autoload function load the class dynamically so you wouldn’t need to declare it elsewhere.

      Technically $core = new Core(); wouldn’t work in this case becuse the __construct function in that class is set to private.

      So you would always have to use the getInstance method when you want to create a new instance unless you’re calling new Core() inside the Core class itself.

  3. Pingback: (Snippet) Blocking IPs from a list file with PHP « This page intentionally left ugly

  4. Pingback: PHP Plugin/Module system | This page intentionally left ugly

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s