diff options
Diffstat (limited to 'buildscripts')
-rw-r--r-- | buildscripts/texbuilder/build.php | 59 | ||||
-rw-r--r-- | buildscripts/texbuilder/create_index.php | 90 | ||||
-rw-r--r-- | buildscripts/texbuilder/prado3_quick_start.tex | 4 |
3 files changed, 152 insertions, 1 deletions
diff --git a/buildscripts/texbuilder/build.php b/buildscripts/texbuilder/build.php index 4e2d8be6..f0556e3f 100644 --- a/buildscripts/texbuilder/build.php +++ b/buildscripts/texbuilder/build.php @@ -10,6 +10,10 @@ $mainTexFile = dirname(__FILE__).'/prado3_quick_start.tex'; //page root location
$base = realpath(dirname(__FILE__).'/../../demos/quickstart/protected/pages/');
+//search index data directory
+$index_dir = realpath(dirname(__FILE__).'/../../demos/quickstart/protected/index/data/');
+
+
//list page into chapters
$pages['Getting Started'] = array(
'GettingStarted/Introduction.page',
@@ -94,6 +98,11 @@ $pages['Advanced Topics'] = array( 'Advanced/Error.page',
'Advanced/Performance.page');
+$pages['Client-side Scripting'] = array(
+ 'Advanced/Scripts.page',
+ 'Advanced/Scripts1.page',
+ 'Advanced/Scripts2.page',
+ 'Advanced/Scripts3.page');
//-------------- END CONFIG ------------------
@@ -273,12 +282,51 @@ function get_section_label($section) return '\hypertarget{'.str_replace('/', '.', $section).'}{}';
}
+
+function set_header_id($content, $count)
+{
+ global $header_count;
+ $header_count = $count*100;
+ $content = preg_replace_callback('/<h1>/', "h1", $content);
+ $content = preg_replace_callback('/<h2>/', "h2", $content);
+ $content = preg_replace_callback('/<h3>/', "h3", $content);
+ return $content;
+}
+
+function h1($matches)
+{
+ global $header_count;
+ return "<h1 id=\"".(++$header_count)."\">";
+}
+
+function h2($matches)
+{
+ global $header_count;
+ return "<h2 id=\"".(++$header_count)."\">";
+}
+
+function h3($matches)
+{
+ global $header_count;
+ return "<h3 id=\"".(++$header_count)."\">";
+}
+
+$header_count = 0;
+
//--------------- BEGIN PROCESSING -------------------
+
+//--------------- Indexer -------------------
+
+require_once('create_index.php');
+$indexer = new quickstart_index($index_dir);
+
// ---------------- Create the Tex files ---------
$count = 1;
+$j = 1;
$current_path = '';
echo "Compiling .page files to Latex files\n\n";
+
foreach($pages as $chapter => $sections)
{
$content = '\chapter{'.$chapter.'}'.get_chapter_label($chapter);
@@ -289,8 +337,16 @@ foreach($pages as $chapter => $sections) echo " Adding $section\n";
$page = $base.'/'.$section;
$current_path = $page;
+
+ //add id to <h1>, <h2>, <3>
+ $content = set_header_id(file_get_contents($page),$j++);
+ file_put_contents($page, $content);
+
$content .= get_section_label($section);
- $content .= parse_html($page,file_get_contents($page));
+ $file_content = file_get_contents($page);
+ $tex = parse_html($page,$file_content);
+ $content .= $tex;
+ $indexer->add($file_content,$section, filemtime($page));
}
//var_dump($content);
@@ -299,6 +355,7 @@ foreach($pages as $chapter => $sections) echo "\n";
}
+$indexer->commit();
if($argc <= 1 && $count > 1)
{
diff --git a/buildscripts/texbuilder/create_index.php b/buildscripts/texbuilder/create_index.php new file mode 100644 index 00000000..b451473d --- /dev/null +++ b/buildscripts/texbuilder/create_index.php @@ -0,0 +1,90 @@ +<?php
+
+// Create quickstart search index
+$zend_path = realpath(dirname(__FILE__).'/../../demos/quickstart/protected/index');
+set_include_path(get_include_path().';'.$zend_path);
+require_once ('Zend/Search/Lucene.php');
+
+
+class quickstart_index
+{
+ private $_index;
+ private $_dir;
+
+ public function __construct($index_file)
+ {
+ $this->_index = new Zend_Search_Lucene($index_file, true);
+ $this->_dir = $index_file;
+ echo "Building search index...\n";
+ }
+
+ public function add($content, $section, $mtime)
+ {
+ foreach($this->split_headings($content) as $headers)
+ {
+ $doc = new Zend_Search_Lucene_Document();
+ $link = "index.php?page=".preg_replace('/\/|\\\/', '.', $section);
+ $link = str_replace('.page', '', $link).'#'.$headers['section'];
+
+ //unsearchable text
+ $doc->addField(Zend_Search_Lucene_Field::UnIndexed('link', $link));
+ $doc->addField(Zend_Search_Lucene_Field::UnIndexed('mtime', $mtime));
+ $doc->addField(Zend_Search_Lucene_Field::UnIndexed('title', $headers['title']));
+ $doc->addField(Zend_Search_Lucene_Field::UnIndexed('text', $headers['content']));
+
+ //searchable text
+ $doc->addField(Zend_Search_Lucene_Field::Keyword('page', strtolower($headers['title'])));
+ $body = strtolower($this->sanitize($headers['content'])).' '.strtolower($headers['title']);
+ $doc->addField(Zend_Search_Lucene_Field::Unstored('contents',$body));
+ $this->_index->addDocument($doc);
+ }
+ }
+
+ function sanitize($input)
+ {
+ return htmlentities(strip_tags( $input ));
+ }
+
+ public function index()
+ {
+ return $this->_index;
+ }
+
+ protected function split_headings($html)
+ {
+ $html = preg_replace('/<\/?com:TContent[^<]*>/', '', $html);
+
+ $html = preg_replace('/<b>([^<]*)<\/b>/', '$1', $html);
+ $html = preg_replace('/<i>([^<]*)<\/i>/', '$1', $html);
+ $html = preg_replace('/<tt>([^<]*)<\/tt>/', '$1', $html);
+
+ $html = preg_replace('/<h1([^>]*)>([^<]*)<\/h1>/', '<hh$1>$2</hh>', $html);
+ $html = preg_replace('/<h2([^>]*)>([^<]*)<\/h2>/', '<hh$1>$2</hh>', $html);
+ $html = preg_replace('/<h3([^>]*)>([^<]*)<\/h3>/', '<hh$1>$2</hh>', $html);
+
+
+ $sections = preg_split('/<hh[^>]*>([^<]+)<\/hh>/', $html,-1);
+ $headers = array();
+ preg_match_all('/<hh([^>]*)>([^<]+)<\/hh>/', $html, $headers);
+ $contents = array();
+ for($i = 1, $t = count($sections); $i < $t; $i++)
+ {
+ $content['title'] = trim($this->sanitize($headers[2][$i-1]));
+ $sec = array();
+ preg_match('/"([^"]*)"/', $headers[1][$i-1], $sec);
+ $content['section'] = str_replace('"', '',$sec[0]);
+ $content['content'] = trim($this->sanitize($sections[$i]));
+ $contents[] = $content;
+ }
+
+ return $contents;
+ }
+
+ public function commit()
+ {
+ $this->_index->commit();
+ $count = $this->_index->count();
+ echo "\nSaving search index ({$count}) to {$this->_dir}\n\n";
+ }
+}
+?>
\ No newline at end of file diff --git a/buildscripts/texbuilder/prado3_quick_start.tex b/buildscripts/texbuilder/prado3_quick_start.tex index a4105685..d55e3462 100644 --- a/buildscripts/texbuilder/prado3_quick_start.tex +++ b/buildscripts/texbuilder/prado3_quick_start.tex @@ -114,5 +114,9 @@ OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \include{ch7}
\include{ch8}
\include{ch9}
+\include{ch10}
+\include{ch11}
+\include{ch12}
+\include{ch13}
\end{document}
|