<?php
// xrs - Keep It Simple And Stupid XML Powered Publication System
// Copyright (C) 2002-2003 Ales Hakl <ales at hakl dot net>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
include "../etc/conf.php";
function startElement($parser, $name, $attribs) {
global $DocMeta,$IsTitle,$IsDesc,$IsAuthor,$IsContact;
if ($name=='document'){
if (isset($attribs['lang'])) $DocMeta['lang']=$attribs['lang'];
if (isset($attribs['author'])) $DocMeta['aid']=$attribs['author'];
}
if ($name=='title') $IsTitle=true;
if ($name=='desc') $IsDesc=true;
if ($name=='author') $IsAuthor=true;
}
function endElement($parser, $name) {
global $DocMeta,$IsTitle,$IsDesc,$IsAuthor,$IsContact;
if ($name=='title') $IsTitle=false;
if ($name=='desc') $IsDesc=false;
if ($name=='author') $IsAuthor=false;
}
function characterData($parser, $data) {
global $DocMeta,$IsTitle,$IsDesc,$IsAuthor,$IsContact;
if ($IsTitle) $DocMeta['title'].=$data;
if ($IsDesc) $DocMeta['desc'].=$data;
if ($IsAuthor) $DocMeta['author'].=$data;
}
function new_xml_parser($file) {
$xml_parser = xml_parser_create('utf-8');
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0);
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
if (!($fp = @fopen($file, "r"))) {
return false;
}
if (!is_array($parser_file)) {
settype($parser_file, "array");
}
return array($xml_parser, $fp);
}
function ReadDocMetaInfo($file){
global $DocMeta;
$DocMeta=array();
if (!(list($xml_parser, $fp) = new_xml_parser($file))) {
die("could not open XML input");
}
while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d\n",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);
return $DocMeta;
}
function PutItem($Item,$fp){
fputs($fp,'<news lang="'.$Item['lang'].'" author="'.$Item['author'].'" date="'.$Item['date'].'"><![CDATA['.$Item['content'].']]></news>'."\n");
}
function PN_startElement($parser, $name, $attribs) {
global $NItem,$IsItem;
if ($name=='news'){
$NItem=array();
$IsItem=true;
if (isset($attribs['lang'])) $NItem['lang']=$attribs['lang'];
if (isset($attribs['author'])) $NItem['author']=$attribs['author'];
if (isset($attribs['date'])) $NItem['date']=$attribs['date'];
}
}
function PN_endElement($parser, $name) {
global $News,$NItem,$IsItem,$NewsOut;
if ($name=='news'){
$IsItem=false;
$News[]=$NItem;
PutItem($NItem,$NewsOut);
}
}
function PN_characterData($parser, $data) {
global $NItem,$IsItem;
if ($IsItem) $NItem['content'].=$data;
}
function PN_PIHandler($parser, $target, $data){
global $News,$NewsAdd,$NewsOut,$NewsAddFlag;
if ($target=='xrs') {
if ($data=='grow before'){
if ($NewsAddFlag){
$News[]=$NewsAdd;
PutItem($NewsAdd,$NewsOut);
}
FputS($NewsOut,'<?xrs grow before?>'."\n");
}
if ($data=='grow after'){
FputS($NewsOut,'<?xrs grow after?>'."\n");
if ($NewsAddFlag){
$News[]=$NewsAdd;
PutItem($NewsAdd,$NewsOut);
}
}
}
}
function PN_new_xml_parser($file) {
$xml_parser = xml_parser_create('utf-8');
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0);
xml_set_element_handler($xml_parser, "PN_startElement", "PN_endElement");
xml_set_character_data_handler($xml_parser, "PN_characterData");
xml_set_processing_instruction_handler($xml_parser, "PN_PIHandler");
if (!($fp = @fopen($file, "r"))) {
return false;
}
if (!is_array($parser_file)) {
settype($parser_file, "array");
}
return array($xml_parser, $fp);
}
function ProcessNews($file,$AddFlag,$AddItem){
global $News,$NewsAdd,$NewsOut,$NewsAddFlag;
$News=array();
$NewsAdd=$AddItem;
$NewsAddFlag=$AddFlag;
if (!(list($xml_parser, $fp) = PN_new_xml_parser($file))) {
die("could not open XML input");
}
$NewsOut=fopen($file.'.wrk',"w");
FPutS($NewsOut,"<?xml version=\"1.0\" ?>\n<newscollection>\n");
while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d\n",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);
fclose($fp);
FPutS($NewsOut,"</newscollection>\n");
fclose($NewsOut);
Copy($file.'.wrk',$file);
return $News;
}
function PL_PutItem($Item,$fp){
fputs($fp,'<link lang="'.$Item['lang'].'" author="'.$Item['author'].'" date="'.$Item['date'].'" href="'.$Item['href'].'"><![CDATA['.$Item['content'].']]></link>'."\n");
}
function PL_startElement($parser, $name, $attribs) {
global $LItem,$IsItem;
if ($name=='link'){
$LItem=array();
$IsItem=true;
if (isset($attribs['lang'])) $LItem['lang']=$attribs['lang'];
if (isset($attribs['author'])) $LItem['author']=$attribs['author'];
if (isset($attribs['date'])) $LItem['date']=$attribs['date'];
if (isset($attribs['href'])) $LItem['href']=$attribs['href'];
}
}
function PL_endElement($parser, $name) {
global $Links,$LItem,$IsItem,$LinksOut;
if ($name=='link'){
$IsItem=false;
$Links[]=$LItem;
PL_PutItem($LItem,$LinksOut);
}
}
function PL_characterData($parser, $data) {
global $LItem,$IsItem;
if ($IsItem) $LItem['content'].=$data;
}
function PL_PIHandler($parser, $target, $data){
global $Links,$LinksAdd,$LinksOut,$LinksAddFlag;
if ($target=='xrs') {
if ($data=='grow before'){
if (($LinksAddFlag)){
$Links[]=$LinksAdd;
PL_PutItem($LinksAdd,$LinksOut);
}
FputS($LinksOut,'<?xrs grow before?>'."\n");
}
if ($data=='grow after'){
FputS($LinksOut,'<?xrs grow after?>'."\n");
if (isset($LinksAddFlag)){
$Links[]=$LinksAdd;
PL_PutItem($LinksAdd,$LinksOut);
}
}
}
}
function PL_new_xml_parser($file) {
$xml_parser = xml_parser_create('utf-8');
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0);
xml_set_element_handler($xml_parser, "PL_startElement", "PL_endElement");
xml_set_character_data_handler($xml_parser, "PL_characterData");
xml_set_processing_instruction_handler($xml_parser, "PL_PIHandler");
if (!($fp = @fopen($file, "r"))) {
return false;
}
if (!is_array($parser_file)) {
settype($parser_file, "array");
}
return array($xml_parser, $fp);
}
function ProcessLinks($file,$AddFlag,$AddItem){
global $Links,$LinksAdd,$LinksOut,$LinksAddFlag;
$Links=array();
$LinksAdd=$AddItem;
$LinksAddFlag=$AddFlag;
if (!(list($xml_parser, $fp) = PL_new_xml_parser($file))) {
die("could not open XML input");
}
$LinksOut=fopen($file.'.wrk',"w");
FPutS($LinksOut,"<?xml version=\"1.0\" ?>\n<linkscollection>\n");
while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d\n",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);
fclose($fp);
FPutS($LinksOut,"</linkscollection>\n");
fclose($LinksOut);
Copy($file.'.wrk',$file);
return $Links;
}
function gen_news($news){
global $ListLimit;
$fp['en']=fopen('../gen/snews.en.xrs','w');
$fp['cs']=fopen('../gen/snews.cs.xrs','w');
for($i=0;($i<Count($news))&&($i<$ListLimit);$i++) FPuts($fp[$news[$i]['lang']],'<li class="snews_item"><span class="snews_date">'.Date("d-m-Y H:i:s",$news[$i]['date']).'</span><span class="snews_content">'.$news[$i]['content'].'</span> <span class="snews_author">[<a href="/info.php?team#'.$news[$i]['author'].'">'.$news[$i]['author'].'</a>]</span></li>');
fclose($fp['en']);
fclose($fp['cs']);
$fp['en']=fopen('../gen/news.en.xrs','w');
$fp['cs']=fopen('../gen/news.cs.xrs','w');
for($i=0;$i<Count($news);$i++) FPuts($fp[$news[$i]['lang']],'<li class="news_item"><span class="news_date">'.Date("d-m-Y H:i:s",$news[$i]['date']).'</span><span class="news_content">'.$news[$i]['content'].'</span><span class="news_author">[<a href="/info.php?team#'.$news[$i]['author'].'">'.$news[$i]['author'].'</a>]</span></li>');
fclose($fp['en']);
fclose($fp['cs']);
}
function gen_links($links){
global $ListLimit;
$fp['en']=fopen('../gen/slinks.en.xrs','w');
$fp['cs']=fopen('../gen/slinks.cs.xrs','w');
for($i=0;($i<Count($links))&&($i<$ListLimit);$i++) FPuts($fp[$links[$i]['lang']],'<li class="slink_item"><span class="slink_date">'.Date("d-m-Y H:i:s",$links[$i]['date']).'</span><a href="'.$links[$i]['href'].'"><span class="slink_content">'.$links[$i]['content'].'</span></a> <span class="slink_author">[<a href="/info.php?team#'.$links[$i]['author'].'">'.$links[$i]['author'].'</a>]</span></li>');
fclose($fp['en']);
fclose($fp['cs']);
$fp['en']=fopen('../gen/links.en.xrs','w');
$fp['cs']=fopen('../gen/links.cs.xrs','w');
for($i=0;$i<Count($links);$i++) FPuts($fp[$links[$i]['lang']],'<li class="link_item"><span class="link_date">'.Date("d-m-Y H:i:s",$links[$i]['date']).'</span><a href="'.$links[$i]['href'].'"><span class="link_content">'.$links[$i]['content'].'</span></a><span class="link_author">[<a href="/info.php?team#'.$links[$i]['author'].'">'.$links[$i]['author'].'</a>]</span></li>');
fclose($fp['en']);
fclose($fp['cs']);
}
function IndexDocs($dir){
function getdirlisting($dir) {
$listing = array();
$dh = opendir($dir);
while ($file = readdir($dh)) {
array_push($listing, $file);
}
closedir($dh);
sort($listing);
return $listing;
}
$fp['en']=fopen('../gen/docs.en.xrs','w');
$fp['cs']=fopen('../gen/docs.cs.xrs','w');
$i=0;
foreach (getdirlisting($dir) as $file){
if (!is_dir($dir.$file)) continue;
if ($file=='..') continue;
if ($file=='.') continue;
$doc=ReadDocMetaInfo($dir.$file.'/metainfo.xml');
echo '<input type="checkbox" name="main['.$i.']" value="'.$file.'" />'.$file.' '.$doc['title']."<br />\n";
$i++;
FputS($fp[$doc['lang']],'<tr class="doc_row">');
FputS($fp[$doc['lang']],'<td class="doc_title"><a href="doc/'.$file.'/">'.$doc['title'].'</td>');
FputS($fp[$doc['lang']],'<td class="doc_desc">'.$doc['desc'].'</td>');
if (isset($doc['aid'])){
FputS($fp[$doc['lang']],'<td class="doc_author"><a href="/info.php?team#'.$doc['aid'].'">'.$doc['author'].'</td>');
}else {
FputS($fp[$doc['lang']],'<td class="doc_author">'.$doc['author'].'</td>');
}
FputS($fp[$doc['lang']],'<td class="doc_date">'.Date("d-m-Y H:i:s",filemtime($dir.$file)).'</td>');
FputS($fp[$doc['lang']],'</tr>');
}
fclose($fp['en']);
fclose($fp['cs']);
}
?>