Location: PHPKode > projects > JaxBlog > JaxBlog/app/user/user_story/main.php
<?php

require_once('../../../config.php');
require_once(FOLDER_RELATIVE_COMMON . 'builder-user.php');
require_once(FOLDER_RELATIVE_COMMON . 'html.php');

function getStories($page_id, $story_id) {
	
	$html = "\n";
	
	if (isset($story_id) && $story_id > 0) {
		// Get requested story.
		$sql = 'SELECT ' . databaseGetDate('stamp') . ' AS stamp, s.title AS title, s.content AS content FROM Stories s WHERE s.id = ?';
		$row = databaseGetRow($sql, array($story_id));
		$html .= buildStoryFromDBRow($row, '');
		
	} else {
		$row = getPageInfo($page_id);
		$max = $row['visible_stories'];
		$counter = 0;
		
		// See if user has permission to view the story.
		$require_login = $row['require_login'] == 'Y';
		if ($require_login && (!$_SESSION['username'])) {
			header('location:../user_story/user_error.php?errorcode=1002');
			exit;
		}
		
		// Get stories for the requested page, limited by the max for the page.
		$sql = 'SELECT ' . databaseGetDate('stamp') . ' AS stamp, s.title AS title, s.content AS content FROM PageToStory ps, Stories s WHERE ps.page_id = ? and s.id = ps.story_id ORDER BY s.stamp DESC ';
		$rows = databaseGetRows($sql, array($page_id));
		foreach ($rows as $row) {
			if (++$counter > $max) break;
			$html .= buildStoryFromDBRow($row, '');
		}
	}
	
	if ((!isset($page_id)) || $page_id != 1) {
		$html .= "\n\t\t\t" . '<div class="archive"><a class="archive" href="user_stories_list.php">archived stories</a></div>' . "\n";
	}
	
	return $html;
}

function getBreadcrumb($page_id) {
	if (!isset($page_id)) return;
	if (FLAG_BREADCRUMB != 'Y') return;

	$row = getPageInfo($page_id);
	$parent_id = $row['parent_id'];
	$title = removeBreak($row['title'], false);
	$html = '';
	
	// If the parent exists, create breadcrumb trail.
	if ($parent_id > 0) {
		$sql = 'SELECT id, title, parent_id FROM Pages WHERE id = ?';
		$id = $parent_id;
		$continue = true;
		$html .= $title . "\n";
		
		while ($continue) {
			$row = databaseGetRow($sql, array($id));
			if ($row) {
				$id = $row['parent_id'];
				$title = removeBreak($row['title'], false);
				$link = '<a class="breadcrumb_link" href="main.php?page_id=' . $row['id'] . '">' . $title . '</a>';
				$html = "$link &gt; $html";
			} else {
				$continue = false;
			}
		}
		$html = '<div class="breadcrumb">' . $html . '</div>';
	}
	return $html;
}

$page_id  = (isset($_GET['page_id'])) ? $_GET['page_id'] : null;
$story_id = (isset($_GET['story_id'])) ? $_GET['story_id'] : null;
$page_id  = (!isset($page_id)) && (!isset($story_id)) ? 1 : $page_id;

$header     = '';
$onload     = '';
$content    = getStories($page_id, $story_id);
$breadcrumb = getBreadcrumb($page_id);

$page = buildUserPage($page_id, $story_id, $header, $onload, $content, $breadcrumb);

echo $page;

?>
Return current item: JaxBlog