Location: PHPKode > projects > 11in1 > 11in1/topic.php
<?php

/**************************************************************************
 *                                                                        *
 *                                                                        *
 *           Script: 11in1                                                *
 *          Version: 1.0.1                                                *
 *      Description: an open source content managment system (CMS)        *
 *               By: Eyad Fallatah of Emuci Inc.                          *
 *             File: topic.php                                            *
 *          Website: http://www.11in1.org                                 *
 *            Email: hide@address.com                                       *
 *                                                                        *
 *                                                                        *
 **************************************************************************
 *                                                                        *
 *                                                                        *
 *   This script is freeware and you can use it however you like at       *
 *   your own risk. If you are interested in contributing to the          *
 *   development of this script, please visit our website.                *
 *                                                                        *
 *                                                                        *
 *************************************************************************/

// protect the included files by defining a permission
DEFINE('PERMISSION_TO_INCLUDE', TRUE);


// include the needed files 
require(dirname(__FILE__) . "/includes/global.php");
require "includes/captcha/captcha.php";

$id = $_GET['id'];

$_SESSION['captcha3'] = captcha();
$captcha = $_SESSION['captcha3']['image_src'];


// Get database information
$info = $Database->getInfo();	
	
// connect to db
$conn = mysql_connect($info[0], $info[1], $info[2]);
$db = mysql_select_db($info[3], $conn);
	
$id = mysql_real_escape_string($id);

$result = mysql_query("SELECT * FROM 11in1_topics WHERE id = '$id'");	
$dbRow = mysql_fetch_row($result);

$thisID = $dbRow[0];
$thisSecID = $dbRow[1];
$thisTitle = $dbRow[2];
$thisDate = $Functions->FormatDate($dbRow[3], $settings_lang, $settings_dateFormat);
$thisContent = $dbRow[4];
$thisMainTemp = 'uploads/pictures/'.$dbRow[6];
$thisAttachment = $dbRow[8];


$result = mysql_query("SELECT title FROM 11in1_sections WHERE id = '$thisSecID'");	
$dbRow = mysql_fetch_row($result);
$thisSecName = $dbRow[0];



//show attachment if any
if($thisAttachment)
{
	$thisAttachment = "<li><a href='do.php?action=download&id=$thisID'>$thisAttachment</a></li>";
}


// has this user read this topic before?
$visitedTopics = $_SESSION['visited'];
if(is_array($visitedTopics))
{
	 $found = false;
	 
	 for($i = 0; $i < count($visitedTopics); $i++)
	 {
	 	if($visitedTopics[$i] == $thisID)
	 	{
	 		$found = true;
	 		break;
	 	}
	 }
	 
	 // if user hasn't read this topic before, increment counter
	 if(!$found)
	 {
	 	mysql_query("UPDATE 11in1_topics SET allviewers = (allviewers + 1) WHERE id = '$thisID'");
	 	$visitedTopics[] = $thisID;
	 	$_SESSION['visited'] = $visitedTopics;
	 }	
}




// get comments if allowed
if($settings_allow_comments)
{
	
	// which commenting system to use?
	// if type equal to 1, show comments from Facebook
	if($settings_commentsType)
	{
		
		$facebook_settings_encoding = $lang_iso;
		$facebook_settings_width = $settings_facebookWidth;
		$facebook_settings_postsPerLoad = $settings_comments_per_load;
		$facebook_settings_pathToThisPage =  "http://" . $_SERVER['HTTP_HOST']  . $_SERVER['REQUEST_URI'];
		
		$thisComments = 
		"	<div id=\"fb-root\"></div>
			<script src=\"http://connect.facebook.net/$facebook_settings_encoding/all.js#appId=APP_ID&amp;xfbml=1\"></script>
			<fb:comments href=\"$facebook_settings_pathToThisPage\" num_posts=\"$facebook_settings_postsPerLoad\" width=\"$facebook_settings_width\"></fb:comments>
		";
	}	 
	// else, show comments from local database	
	else
	{
		// total number of comments associated with this topic
		$result = mysql_query("SELECT id FROM 11in1_comments WHERE topicID = '$id'", $conn);
		$total = mysql_num_rows($result);
				
		
		// get list of countries
		$sql ="SELECT * FROM 11in1_countries ORDER BY name ASC";	
		$result = mysql_query($sql);						
		while($row=mysql_fetch_array($result))
		{
			$thisName = $row['name'];
			$thisID = $row['id'];
			
			if($thisID == $settings_location)
			$selected = "selected";
			else
			$selected = "";
			
			$thisOptions .= "<option value=\"$thisID\" $selected>$thisName</option>";
		}		

				
		$list = $Loader->getComments($settings_comments_per_load, $settings_comments_per_load, $id);
		
		
		// prepare inner template
$static_value = array ($list, $navBar, $lang_frontend_name, $lang_frontend_title, $lang_frontend_comment, $lang_frontend_location, $thisOptions, $lang_frontend_submit, $captcha, $lang_frontend_contactFormCaptcha, $id, $settings_comments_per_load, $total, $lang_frontend_loadMore, $lang_frontend_commentsTitle);
$static_name  = array ("{LIST}", "{PAGINATION}", "{NAME}", "{TITLE}", "{COMMENT}", "{LOCATION}", "{OPTIONS}", "{SUBMIT}", "{CAPTCHA}", "{LEGEND_CAPTCHA}", "{ID}", "{LIMIT}", "{TOTAL}", "{LOAD_MORE}", "{COMMENTS}");
		$template = $Engine->loadTemplate ("templates/$settings_template/comments.html");
		$thisComments = $Engine->replaceStatic($static_name, $static_value, $template);			
	}
}




// topic does not extsit, show home page
if(empty($thisID))
{
	echo "<script>window.location='index.php';</script>";
	header("Location: index.php");
}


// prepare the page name
$pageName = $thisTitle;



// show the main page if any
if((file_exists($thisMainTemp))&&(is_file($thisMainTemp)))
$thisMain = "<img src='$thisMainTemp' class='topicImage'>";


// get the content of the page
$static_value = array ($thisTitle, $thisContent, $thisSecName, $thisDate, $lang_frontend_postedIn, $lang_frontend_onDate, $thisMain, $thisComments, $thisAttachment);
$static_name  = array ("{TITLE}", "{CONTENT}", "{SEC_NAME}", "{DATE}", "{POSTED_IN}", "{ON_DATE}", "{IMG}", "{COMMENTS}", "{ATTACHMENT}");
$pageContent = $Engine->loadTemplate("templates/$settings_template/topic.html");
$pageContent = $Engine->replaceStatic($static_name, $static_value, $pageContent);



// load template
$common_static_value[] = $pageContent;
$common_static_value[] = $pageName;
$common_static_name[] = "{DISPLAY_AREA}";
$common_static_name[] = "{PAGE_NAME}";
$template = $Engine->loadTemplate("templates/$settings_template/layout.html");
$template = $Engine->replaceStatic($common_static_name, $common_static_value, $template);		

	
echo $template;

?>
Return current item: 11in1