//////////////////////////////////////////////////
// Calliope version 0.2.1
//////////////////////////////////////////////////
// If a story_id has not been passed, redirect user to cats page
if (!$_GET['story_id']) {
Header("Location: cats.php");
}
// Prepare page
require ("pagestart.php");
// Get values
// $story_path = get_config_value('fic_path');
$story_path = "fics/";
$fic_separator = get_config_value('fic_separator');
$template->assign("FIC_SEPARATOR", $fic_separator);
$chapter_separator = get_config_value('chapter_separator');
$date_format = get_config_value('date_format');
// Parse query values
$story_id = $_GET['story_id'];
if ($_GET['chapter']) {
$chapter_num = $_GET['chapter'];
} else {
$chapter_num = "01";
}
// Get chapter info
$query_chapter = "SELECT id, CONCAT_WS('$chapter_separator', chapter_num, chapter_title) AS chapter_title, chapter_num, summary, notes, DATE_FORMAT(date, '$date_format') AS date FROM $chapters_table WHERE story_id = '$story_id' AND chapter_num = '$chapter_num'";
$chapter_result = mysql_query($query_chapter) or exit("query_chapter error: ".mysql_error());
$chapter_info = mysql_fetch_assoc($chapter_result);
// Get story info
$query = "SELECT cat_id, user_id, fic_title, author, pairing, characters, genre, rating, warnings, spoilers, challenge, complete FROM $stories_table WHERE id = '$story_id'";
$story_query = mysql_query($query) or exit("query story error: ".mysql_error());
$story = mysql_fetch_array($story_query);
// Get number of chapters
$query_num = mysql_query("SELECT COUNT(chapter_num) as num_chapters FROM $chapters_table WHERE story_id = '$story_id'") or exit("query_num error: ".mysql_error());
$num_result = mysql_fetch_assoc($query_num);
$num_rows = $num_result['num_chapters'];
//Fic Header & mail subject
$template->assign("FIC_TITLE", stripslashes($story['fic_title']));
$page_title = " ".$page_title_separator." ".stripslashes($story['fic_title']);
$subject = $story['fic_title'];
// Check if is a one-shot or a chapter of a longer story
if ($num_rows > 1) {
$chapter_title = stripslashes($chapter_info['chapter_title']);
$template->assign_if("chapter", "1");
$template->assign_if("chapter_2", "1"); // Gaia's web hack
$template->assign("CHAPTER", $chapter_title);
$template->assign("CAT_ID", $story['cat_id']);
$template->assign("STORY_ID", $story_id);
// Add chapter title to page title
$page_title .= " ".$page_title_separator." ".$chapter_title;
// Add chapter title to mail subject
$subject .= " - ".$chapter_title;
// Chapter navigation
$nav_separator = get_config_value('nav_separator');
$i = 1;
$query_chapters = mysql_query("SELECT chapter_num FROM $chapters_table WHERE story_id = '$story_id'") or exit("query_num error: ".mysql_error());
while ($chapter_list = mysql_fetch_array($query_chapters)) {
$chapters_nav_index .= "".$chapter_list['chapter_num']."";
if ($i < $num_rows) {
$chapters_nav_index .= " $nav_separator ";
}
$i++;
}
if ($chapter_info['chapter_num'] > 01) {
$previous = $chapter_info['chapter_num'] - 1;
$previous = str_pad($previous, 2, "0", STR_PAD_LEFT);
$chapters_nav_prev = "".$lang['previous']."";
}
if ($chapter_info['chapter_num'] < $num_rows) {
$next = $chapter_info['chapter_num'] + 1;
$next = str_pad($next, 2, "0", STR_PAD_LEFT);
$chapters_nav_next = "".$lang['next']."";
}
if (!is_null($chapters_nav_prev) AND is_null($chapters_nav_next)) {
$chapters_nav = "$chapters_nav_prev $chapters_nav_index";
} elseif (is_null($chapters_nav_prev) AND !is_null($chapters_nav_next)) {
$chapters_nav = "$chapters_nav_index $chapters_nav_next";
} else {
$chapters_nav = "$chapters_nav_prev $chapters_nav_index $chapters_nav_next";
}
$template->assign("CHAPTERS_NAV", $chapters_nav);
$template->assign("CHAPTER_NUM", $chapter_info['chapter_num']);
$template->assign_if("chapter_num", "1");
} else {
$template->assign_if("nochapter", "1");
}
// Author
$template->assign("BY", $lang['by']);
$template->assign("USER_ID", $story['user_id']);
$template->assign("AUTHOR", $story['author']);
// Prepare mail subject
$subject = urlencode(stripslashes($subject));
$template->assign("SUBJECT", $subject);
// Fic Subheader
// General story information
// Categories
$cats = format_story_info($story['cat_id'], "cats.php?cat_id=", "&action=cat", "cats");
$template->assign("CATEGORY", $cats);
// Pairing?
if (!empty($story['pairing'])) {
// Hack para solucionar errores del sistema anterior
$pairing_list = format_story_info($story['pairing'], "search.php?action=search&field=pairing&value=", "&type=like", "pairings");
$template->assign("PAIRING", $pairing_list);
$template->assign_if("pairing", "1");
}
// Characters?
if (!empty($story['characters'])) {
$characters = format_story_info($story['characters'], "search.php?action=search&field=characters&value=", "&type=like", "char");
$template->assign("CHARACTERS", $characters);
$template->assign_if("characters", "1");
}
// Genres
if (!empty($story['genre'])) {
$genres = get_option_names("genre", $story['genre'], "link");
$template->assign("GENRES", $genres);
$template->assign_if("genres", "1");
}
// Ratings
$ratings = get_option_names("rating", $story['rating'], 'link');
$template->assign("RATING", $ratings);
// Warnings
if (!empty($story['warnings'])) {
$warnings = get_option_names("warnings", $story['warnings'], 'link');
$template->assign("WARNINGS", $warnings);
$template->assign_if("warning", "1");
}
// Spoilers - Do not display if user only entered "No" or "None"
if (!empty($story['spoilers']) AND !preg_match("/[nN]o(ne)?$/", $story['spoilers'])) {
$template->assign("SPOILERS", $story['spoilers']);
$template->assign_if("spoilers", "1");
}
// Is a response to a challenge from the challenges page?
if ($story['challenge'] != "00000") {
$challenge_id = $story['challenge'];
$query_challenge = "SELECT title FROM $challenges_table WHERE id = '$challenge_id'";
$challenge_query = mysql_query($query_challenge) or die("challenge_query error: ".mysql_error());
$challenge = mysql_fetch_array($challenge_query);
$template->assign_if("challenge", "1");
$template->assign("CHALLENGE", rtrim(ltrim($story['challenge'], '0'), '.'));
$template->assign("CHALLENGE_LABEL", stripslashes($lang['challenge_answer']));
$template->assign("CHALLENGE_TEXT", stripslashes($lang['challenge']));
$template->assign("CHALLENGE_TITLE", $challenge['title']);
}
// Status
if ($story['complete'] == "Yes") {
$template->assign("STATUS", $lang['story_completed']);
$template->assign_if("complete", "1");
} else {
$template->assign("STATUS", $lang['story_not_completed']);
}
// Chapter-specific information
// Date
$template->assign("DATE", $chapter_info['date']);
// Fic summary
if (!empty($chapter_info['summary'])) {
$summary_text = format_text($chapter_info['summary']);
$template->assign("SUMMARY", $summary_text);
$template->assign("SUMMARY_LABEL", $lang['summary']);
$template->assign_if("summary", "1");
}
// Story notes
if (!empty($chapter_info['notes'])) {
$notes = format_text($chapter_info['notes']);
$template->assign_if("notes", "1");
$template->assign("AUTHOR_NOTES", $notes);
$template->assign("AUTHOR_NOTES_LABEL", stripslashes($lang['notes']));
}
// Get fic text
$story_file = $story_path.$chapter_info['id'].".txt";
$story_text = file_get_contents ($story_file);
$template->assign("FIC", $story_text);
// Process template
$template->assign("PRINT_LABEL", $lang['print']);
$template->assign("PRINT_ID", $story_id);
$template->assign("PAGE_TITLE", $page_title);
$template->pparse("layout/fic.tmpl");
// Close database connection
endconnect ();
echo $totaltime;
?>