Forum core source dump (as of July 31)


* Main forum functionality.
* Class calls and rendering functionality is incorportaed into this file.
* @author Eksith Rodrigo
* @version 0.1
* @license MIT License

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

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

//Begin closed check

		Core Code
	// Begin session
	// 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
	// User has asked to login

	// After getting a redirect page request
		$req = $core->decrypt($_GET['redir']);
			header("Location: "+ $req)
			header("Location: "+ $presets['site_url']);
	// 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
		// We're on a topic
		$mdata['replies_list'] = $database->getReplies($mdata['topic_id'], 0, 5);
		// We're on a forum
		$mdata['forum_list'] = $database->getForums($mdata['forum_id']);
		$mdata['topics_list'] = $database->getTopics($mdata['forum_id'], 0, 5);
		// We're on the homepage
		$mdata['forum_list'] = $database->getForums(0);
		$mdata['topics_list'] = $database->getTopics(1, 0, 5, true);
		$mdata['replies_list'] = $database->getReplies(1, 0, 5);
		// We're on a plugin specific page
		// TODO Plugin render functionality
		// 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
		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;
			header('Content-Type: text/html; charset=UTF-8');
	// End of execution cleanup


	Forum is closed

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


echo $html;
} // End closed check

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: Logo

You are commenting using your 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