<?php
defined('WikyBlog') or die("Not an entry point...");

class specialContent{
	
	/* static */
	function get($title, $variables=array() ){
		global $wbAdminUser,$dbInfo,$wbTables;
		
		$title = 'Template:'.$title;
		
		$query = 'SELECT `content`, '.$dbInfo['page']['dbTable'].'.`file_id` FROM '.$dbInfo['page']['dbTable'];
		$query .= ' INNER JOIN '.$wbTables['all_files'];
		$query .= ' USING(`file_id`) ';
		$query .= ' WHERE `owner` = "'.$wbAdminUser.'" ';
		$query .= ' AND `title` = "'.wbDB::escape($title).'" ';
		$query .= ' LIMIT 1 OFFSET 0';
		$result = wbDB::runQuery($query);
		$num = mysql_num_rows($result);
		if( $num !== 1){
			return false;
		}
		global $wbParser;
		
		$row = mysql_fetch_assoc($result);
		initiateParser($variables);
		return $wbParser->justParse($row['content'],'',$row['file_id']);
	}
	
	/* static */
	function fromStatus(){
		global $page,$langA;

		switch($page->status){
			case 'Suspended':
				//$GLOBALS['pageOwner']['username'] = $GLOBALS['wbAdminUser']; //this will then cause the session functions to save wbAdminUser data with the wrong info
				specialContent::toPageArea('suspended');
			break;
			
			case 'registered':
				specialContent::toPageArea('registered');
			break;
			
			case 'LostPage':
				includeFile('special/content/LostPage.php');
			break;
			
			case 'Pending':
				specialContent::toPageArea('Pending');
			break;
			
			case 'restricted':
				specialContent::toPageArea('Restricted');
			break;
			
			default:
				$text = specialContent::get($page->status);
				if( !$text  ){
					includeFile('special/content/LostPage.php');
					break;
				}
				if( isset($langA[$page->status]) ){
					$title = $langA[$page->status];
				}else{
					$title = $page->status;
				}
				$page->contentA[$title] = $text;
			break;
			
		}
	}
	
	/* static */
	function toPageArea($title){
		global $page,$langA;
		wbLang::getFile('ADMIN');
		
		$dTitle = wbLang::text($title);
		$page->displayTitle = $dTitle;
		
		$content = specialContent::get($title);
		if( $content === false){
			$page->contentA[$dTitle] = wbLang::text($title);
			return;
		}
		$page->contentA[$dTitle] = $content;
	}
	
	/* static */
	function message($title){
		$content = specialContent::get($title);
		if( $content === false){
			return false;
		}
		message($content);
		return true;
	}
}