[eluser]Pascal Kriete[/eluser]
So today I finally got sick of having 10 billion tabs and windows open on my 13 inch screen when I'm coding. So I looked around for a printable userguide, and there are quite a few Versions and what not, but they're usually not for 1.6, and it's mostly pdfs - I needed something flexible, since the SVN code gets updated frequently. So with all due respect, I made my own.
It uses my local copy of the SVN user guide to dynamically generate one big html page with proper page breaks for printing. I also added a function to rewrite the table of contents links to just scroll to the proper anchor (web 1.0 - hell, yeah).
My hosting is having issues, so I'll just post the code:
Controller:Code:
class Test extends Controller {
function Test()
{
parent::Controller();
}
function index()
{
echo "test controller";
}
function userguide()
{
/* Things we'll need */
$main_dir = "/Applications/MAMP/htdocs/user_guide/"; //user_guide root WITH trailing slash
/* These are sent out in the order listed */
$individual_files = array('index.html', 'toc.html', 'license.html', 'installation/index.html');
$directories = array('', 'general/', 'libraries/', 'helpers/');
/* Make css inline */
$header['css'] = file_get_contents($main_dir.'userguide.css');
$this->load->view('userguide/header', $header);
$mainpage = $main_dir.'index.html';
/* Go through folders and get contents */
foreach($directories as $folder) {
$this_dir = $main_dir.$folder;
$current_dir = opendir($this_dir);
$files_in_dir = array();
//Individual files come from the root folder
if ($folder == '')
$files_in_dir = $individual_files;
else
while($file = readdir($current_dir)) {
$files_in_dir[] = $file;
}
foreach($files_in_dir as $file) {
if (!is_dir($file)) {
$file_path = $this_dir.$file;
//Turn the non-junk into a view variable
if ($file == 'toc.html')
$data['contents'] = $this->_change_toc($file_path);
else
$data['contents'] = $this->_extract_contents($file_path);
$data['anchor'] = $folder.$file;
$this->load->view('userguide/content', $data);
}
}
closedir($current_dir);
}
$this->load->view('userguide/footer');
}
function _change_toc($path)
{
$contents = $this->_extract_contents($path);
/* Change links */
$contents = str_replace('./', '#', $contents);
return $contents;
}
function _extract_contents($file_path)
{
/* Things we need */
$start = '<div id="content">';
$end = '<!-- END CONTENT -->';
/* Get that first file */
$file_content = file_get_contents($file_path);
/* Remove the junk */
$start_pos = strpos($file_content, $start);
$end_pos = strpos($file_content, $end);
$pos_diff = $end_pos - $start_pos;
/* Give back the non-junk */
$contents = substr($file_content, $start_pos, $pos_diff);
return $contents;
}
}
Views:
Header:
Code:
<?php //SVN Userguide changes frequently -- keep the cache clean
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>CodeIgniter User Guide</title>
<style type="text/css" media="screen,print">
<!--
<?=$css?>
#content {
page-break-after: always;
}
#masthead {
margin-top: 20px;
}
-->
</style>
<style type="text/css" media="screen">
<!--
#content {
margin-bottom: 100px;
padding-bottom: 100px;
border-bottom: 3px solid black;
}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv='expires' content='-1' />
<meta http-equiv= 'pragma' content='no-cache' />
<meta name='robots' content='all' />
<meta name='author' content='ExpressionEngine Dev Team' />
<meta name='description' content='CodeIgniter User Guide' />
</head>
<body>
<div id="masthead">
<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
<tr>
<td><h1>CodeIgniter User Guide Version 1.6.0</h1></td>
</tr>
</table>
</div>
<br clear="all" />
<div class="center"><img src="http://dev.ellislab.com/svn/CodeIgniter/trunk/user_guide/images/ci_logo_flame.jpg" width="150" height="164" border="0" alt="CodeIgniter" /></div>
<!-- START CONTENT -->
Content:
Code:
<a name="<?=$anchor;?>"></a>
<?=$contents?>
Footer:
Code:
<!-- END CONTENT -->
<div id="footer">
<p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2008 · <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
</div>
</body>
</html>