Quanta RefreshDoc script

From KDE UserBase Wiki
Revision as of 07:58, 6 July 2010 by Nerkn (talk | contribs)

Please copy code from source view, also omit the bottom line.

#!/usr/bin/php
<?php
$doc = array();
$doc2 = array();
// ####F-ref-seitem
$doc[] = array('name' => 'Function reference pages', 'link' => );
// ####### treeee
$cXmlReader = new XMLReader();
$cXmlReader->open($argv[1].'/index.html');
while($cXmlReader->read())
{
if($cXmlReader->name == a && $cXmlReader->readInnerXML() != "")
{
if($cXmlReader->depth == 5)
$doc[] = array('link' => $cXmlReader->getAttribute("href"), 'name' => $cXmlReader->readInnerXML());
if($cXmlReader->depth == 7)
$doc[count($doc)-1][] = array('link' => $cXmlReader->getAttribute("href"), 'name' => $cXmlReader->readInnerXML());
}
}
// ####### treeee 2
$cXmlReader = new XMLReader();
$cXmlReader->open($argv[1].'/funcref.html');
while($cXmlReader->read())
{
if($cXmlReader->name == a && $cXmlReader->depth != 4 && $cXmlReader->depth != 8 && $cXmlReader->readInnerXML() != "")
{
if($cXmlReader->depth == 5)
$doc2[] = array('link' => $cXmlReader->getAttribute("href"), 'name' => $cXmlReader->readInnerXML());
if($cXmlReader->depth == 7)
$doc2[count($doc2)-1][] = array('link' => $cXmlReader->getAttribute("href"), 'name' => $cXmlReader->readInnerXML());
}
}
// ######### ;F-Ref-Liste 
$dir = opendir($argv[1]);
while($file = readdir($dir))
{
if(substr($file, 0, 4) == 'ref.')
{
$filec = file_get_contents($argv[1].'/'.$file);
$i = strpos($filec, '<title>');
$j = strpos($filec, '</title>');
$name = substr($filec, $i + 7, $j-$i-7);
$doc[0][] = array('link' => $file, 'name' => $name);
}
}
closedir ($dir);
// ################# CONTEXT
$cXmlReader = new XMLReader();
$cXmlReader->open($argv[1].'/indexes.html');
$context = array();
while($cXmlReader->read())
{
if($cXmlReader->name == a && $cXmlReader->readInnerXML() != "" && $cXmlReader->depth == 6)
{
if(substr($cXmlReader->readInnerXML(), -2) == "()")
$name = substr($cXmlReader->readInnerXML(), 0, -2);
else
$name = $cXmlReader->readInnerXML();
$context[] = array('link' => $cXmlReader->getAttribute("href"), 'name' => $name);
}
}
// ############## write tree into file
function w($text, $nl=0)
{
global $file;
$text = utf8_decode($text);
fwrite($file, $text.(($nl)?"\n":));
}
$file = fopen($argv[1].'.docrc', 'w');
w('[Tree]
Doc dir='.$argv[1].'
Top Element='.$argv[1].' documentation
');
w($argv[1].' documentation=');
$c=;
foreach($doc as $line)
{
w($c.((count($line) > 2)?'#':).$line['name']);
$c=',';
}
w("\n");
function wrec($array)
{
w("\n");
foreach($array as $line)
{
if(count($line) == 2)
w($line['name'].'='.$line['link'], 1);
else if(count($line) > 2)
{
w($line['name'].'=');
$c = ;
foreach($line as $key=>$subline)
{
if(!is_numeric($key)) continue;
w($c.((count($subline) > 2)?'#':).$subline['name']);
$c=',';
}
w("\n");
wrec($line);
}
}
w("\n");
}
wrec($doc);
// ############## write context into file
w('[Context]',1);
w('ContextList=');
$c = ;
foreach($context as $line)
{
w($c.$line['name']);
$c = ',';
}
w("\n",1);
foreach($context as $key=>$line)
{
if(!is_numeric($key)) continue;
w($line['name'].'='.$line['link'],1);
}
fclose($file);
// ############## write tree 2 into second file
$file = fopen($argv[1].'_fref.docrc', 'w');
w('[Tree]
Doc dir='.$argv[1].'
Top Element='.$argv[1].'_fref documentation
');
w($argv[1].'_fref documentation=');
$c=;
foreach($doc2 as $line)
{
w($c.((count($line) > 2)?'#':).$line['name']);
$c=',';
}
w("\n");
wrec($doc2);
fclose($file);
?>