/* Sending a page as set of offline HTML pages packed in ZIP archive */
/* Grzegorz Kraszewski, 09-Apr-2013 */
require('zipstream-0.2.2-min.php');
/*------------------------------------------*/
/* Get current fonts settings from cookies. */
/*------------------------------------------*/
$f1 = $_COOKIE['basefont'];
$f2 = $_COOKIE['codefont'];
$bs = $_COOKIE['basesize'];
$ms = $_COOKIE['margin'];
if (strlen($f1) > 128) $f1 = FALSE;
if (strlen($f2) > 128) $f2 = FALSE;
if (!preg_match('/[\w\x20\-\_]+/', $f1)) $f1 = FALSE;
if (!preg_match('/[\w\x20\-\_]+/', $f2)) $f2 = FALSE;
$bs = (float)$bs;
$ms = (float)$ms;
if (($bs < 3) || ($bs > 200)) $bs = FALSE;
if (($ms < 0) || ($ms > 10)) $ms = FALSE;
/*------------------------------------------------------------------------------------*/
/* Parsing function. Takes array of lines, returns generated HTML as a single string. */
/*------------------------------------------------------------------------------------*/
function parse_wiki($lines, $toc)
{
global $f1, $f2, $bs, $ms;
$res = '
';
$html_from_tbl = array('<', '>', '\\\\');
$html_to_tbl = array('<', '>', '
');
$line = 0;
$code = 0;
$tbl = 0;
$ul = 0;
$ol = 0;
foreach ($lines as $c)
{
if ($line == 0)
{
$title = preg_replace('/^=(.*)=$/U', '$1', $c);
$res .= '' . $title . '';
if (!$toc) $res .= '';
$line = 1;
}
$c = str_replace($html_from_tbl, $html_to_tbl, $c);
/* ====== special underlined header for autodocs ====== */
$c = preg_replace('/___(\S.+\S)___/U', '$1
', $c);
/* ====== headers ====== */
$c = preg_replace('/====(\S.+\S)====/U', '$1
', $c);
$c = preg_replace('/===(\S.+\S)===/U', '$1
', $c);
$c = preg_replace('/==(\S.+\S)==/U', '$1
', $c);
$c = preg_replace('/=(\S.+\S)=/U', '$1
', $c);
/* ====== special underlined header used for autodocs ====== */
$c = preg_replace('/==_(\S.+\S)_==/U', '$1
', $c);
/* ====== '''bold''', ''italic'', ^^superscript^^, ,,subscript,, ====== */
$c = preg_replace('/\x27\x27\x27(.*)\x27\x27\x27/U', '$1', $c);
$c = preg_replace('/\x27\x27(.*)\x27\x27/U', '$1', $c);
$c = preg_replace('/\^\^([\w]+)\^\^/U', '$1', $c);
$c = preg_replace('/\,\,([\w]+)\,\,/U', '$1', $c);
/* ====== paragraphs ====== */
if ($c[0] == "\t") $c = "\n" . substr($c, 1) . "
\n"; // plain, starting with tab
if ($c[0] == '_' && $c[1] == '_') $c = "\n" . substr($c, 2) . "
\n"; // note, starting with "__"
if ($c[0] == '^' && $c[1] == '^') $c = "\n" . substr($c, 2) . "
\n"; // important, starting with "^^"
/* ====== code ====== */
if ($c[0] == ' ')
{
if ($code == 0)
{
$res .= "\n";
$code = 1;
}
$c = str_replace(' ', ' ', substr($c, 1)) . '
';
}
else
{
if ($code == 1) $res .= "
\n";
$code = 0;
}
/* ====== tables ====== */
if ($c[0] == '|')
{
if ($tbl == 0)
{
$res .= '';
$tbl = 1;
}
$cells = trim($c, '|');
$cells = explode('|', $cells);
$res .= '';
foreach ($cells as $cell)
{
$colspan = strspn($cell, '#');
$cell = ltrim($cell, '#');
$cadjust = strspn($cell, '^');
$cell = ltrim($cell, '^');
$radjust = strspn($cell, '$');
$cell = ltrim($cell, '$');
$class = '';
if ($radjust > 0) $class = ' class="r"';
if ($cadjust > 0) $class = ' class="c"';
if ($colspan > 0) $colspan = " colspan=\"$colspan\"";
else $colspan = '';
$res .= "$cell | ";
}
$res .= '
';
}
else
{
if ($tbl == 1) $res .= '
';
$tbl = 0;
}
/* ====== images [[img |