Comparing revisions for FileexportAction

  • [16468] 2007-04-22 09:24:41 by DomBonj (unregistered user) [v0.99: reduced memory usage; added 'e' and 'r' options; support for Footnote action; coding standard]
  • [19356] 2008-01-28 00:15:25 by DomBonj (unregistered user) [Modified links pointing to docs server]
Additions:
- Wikka 1.1.6.2
- Save the first code block below as ##action/fileexport.php##
%%(php)<?php
# @version 0.95
# @input Parameters = [type=('html'|'xml')] [sort=('tag'|'type'|'title')] [opts=['e']['o']['p']['r']] [cats='Category1','Category2'..]
if (!defined('FE_ERROR_USAGE')) define ('FE_ERROR_USAGE', "fileexport [type=\"html|xml\"] [opts=\"[e][o][p][r]\"] [sort=\"tag|time|title\"] [cats=\"<i>category list</i>\"]");
return ("<em class='error'>$msg</em><br />");
$output = "";
if ( (isset($vars['opts']) && (!preg_match("/^[eopr]{1,4}$/i", $vars['opts'])))
|| (isset($vars['type']) && (!preg_match("/^(html|xml)$/i", $vars['type'])))
$query = "&type=". $type;
$query .= "&own=". (preg_match("/[o]/i", $vars['opts']) ? 'n' : 'y');
$query .= "&sys=". (preg_match("/[p]/i", $vars['opts']) ? 'y' : 'n');
$query .= "&cats=";
%%(php)<?php
# @version 0.99
if (!defined('FE_TABLE_OF_CONTENTS')) define ('FE_TABLE_OF_CONTENTS', "Table of contents");
if (!defined('FE_ERROR_REQUEST_STRING')) define ('FE_ERROR_REQUEST_STRING', "Illegal request string, unable to export");
if (!defined('FE_ERROR_ARCHIVE_BUILD')) define ('FE_ERROR_ARCHIVE_BUILD', "Error building the archive file, unable to export");
return ("<em class='error'>$msg</em><br />");
function FEpage_data (&$this, $tag, &$page_content)
// page footer from FootnoteAction
function FEhtml (&$this, &$pages, &$key_order, $embed_css, $css_path, $remove_links, $save_tag, $save_page)
{
$root_url = $_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'];
$header = "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>\n".
"<html><head><meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' />\n";
if ($fcss = fopen($css_path, 'r'))
{
if (!($stylesheet = file_get_contents($css_path)))
{
$stylesheet = '';
}
else
{
$stylesheet = "<style type='text/css'>$stylesheet\n</style>";
}
}
else
{
$stylesheet = '';
}
$header .= ($embed_css ? $stylesheet : '') .'<title>'. $this->GetConfigValue('wakka_name') ."</title></head><body>\n";
$toc = '';
$file_name = $this->GetConfigValue('wakka_name') .'_'. date('Ymd');
foreach ($pages as $tag => $mypage)
{
// prepare mapping table for translation of intra-wiki links
$pat[] = '/'. preg_quote('http://'.$root_url, '/') .'\?wakka='. $tag .'([^\w\.\/]?)/';
$rep[] = '#'. $mypage['i'] .'$1';
}
$save_includes = $this->config['includes'];
foreach ($key_order as $tag => $val)
{
$pagedata = array();
FEpage_data($this, $tag, $pagedata);
$toc .= "<li><a href='#{$pages[$tag]['i']}'>". $pages[$tag]['title'] ."</a></li>\n";
// preserve intra-wiki links
$pagedata['body'] = "<a name='". $pages[$tag]['i'] ."'></a>". preg_replace($pat, $rep, $pagedata['body']);
// relabel footnotes from FootnoteAction
$pagedata['body'] = preg_replace("/href=\'\#(\d+)\#fn(\d+)/", "href='#fn$1_$2", $pagedata['body']);
$pagedata['body'] = preg_replace("/id=\'fn(\d+)/", "id='fn". $pages[$tag]['i']. "_$1", $pagedata['body']);
$pagedata['body'] = preg_replace("/href=\'\#(\d+)\#fnback(\d+)/", "href='#fnback$1_$2", $pagedata['body']);
$pagedata['body'] = preg_replace("/id=\'fnback(\d+)/", "id='fnback". $pages[$tag]['i']. "_$1", $pagedata['body']);
// if requested, remove external links including tail
if ($remove_links)
{
$pagedata['body'] = preg_replace("/<\s*a[^>]+href=([\'\"])[^#][^>]*?\>(.*?)<\/a>/", "$2", $pagedata['body']);
$pagedata['body'] = preg_replace('/'.preg_quote($this->GetConfigValue('external_link_tail'),'/').'/', '', $pagedata['body']);
}
$output .= $pagedata['body'] ."<hr />\n";
}
$output = $header ."<div class='page'><h2>". FE_TABLE_OF_CONTENTS. '</h2><ul>'. $toc .'</ul><hr />'. $output;
// restore original values
$this->tag = $save_tag;
$this->page = $save_page;
$this->config['includes'] = $save_includes;
header('Content-Disposition: attachment; filename='. $file_name .'html');
header('Content-Type: text/html; charset=ISO-8859-1');
header('Expires: 0');
header('Pragma: no-cache');
print $output;
echo '</div></body></html>';
exit();
function FExml (&$this, &$pages, &$key_order, $remove_links, $save_tag, $save_page)
{
$file_name = $this->GetConfigValue('wakka_name') .'_'. date('Ymd');
$output = '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?><wikka>';
$save_includes = $this->config['includes'];
foreach ($key_order as $tag => $val)
{
$mytab = $pages[$tag];
$output .= '<page tag="'. $tag .'" lastchange="'. strftime('%Y-%m-%dT%H:%M:%S', strtotime($mytab['lastchange'])) .'"><owner>'. $mytab['owner'] .'</owner>';
foreach (explode (' ', $mytab['cats']) as $mycat)
{
if ($mycat)
{
$output .= '<category>'. $mycat. '</category>';
}
}
$output .= '<title>'. utf8_encode(htmlspecialchars($mytab['title'], ENT_COMPAT, 'UTF-8')) .'</title>\n';
$pagedata = array();
FEpage_data($this, $tag, $pagedata);
$output .= '<raw_content>'. utf8_encode(htmlspecialchars($pagedata['raw'], ENT_COMPAT)) .".</raw_content>\n";
// if requested, remove external links including tail
if ($remove_links)
{
$pagedata['body'] = preg_replace("/<\s*a[^>]+href=([\'\"])[^#][^>]*?\>(.*?)<\/a>/", "$2", $pagedata['body']);
$pagedata['body'] = preg_replace('/'.preg_quote($this->GetConfigValue('external_link_tail'),'/').'/', '', $pagedata['body']);
}
$output .= '<rendered_content>'.utf8_encode(htmlspecialchars($pagedata['body'], ENT_COMPAT, 'UTF-8')).".</rendered_content>";
$output .= "</page>\n";
}
$output .= '</wikka>';
// restore original values
$this->tag = $save_tag;
$this->page = $save_page;
$this->config['includes'] = $save_includes;
header('Content-Disposition: attachment; filename='. $file_name .'xml');
header('Content-Type: text/xml; charset=UTF-8');
header('Expires: 0');
header('Pragma: no-cache');
print $output;
exit();
if ((isset($_GET['own']) && !(preg_match("/^[YN]$/i", $_GET['own'])))
|| (isset($_GET['emb']) && (!preg_match("/^[YN]$/i", $_GET['emb'])))
|| (isset($_GET['sys']) && (!preg_match("/^[YN]$/i", $_GET['sys'])))
|| (isset($_GET['type']) && (!preg_match("/^(html|xml)$/i", $_GET['type'])))
$css_path = 'css/'. $this->GetConfigValue('stylesheet');
if ('y' == strtolower($_GET['own']))
$query .= " AND (owner = '".$this->GetUserName()."')";
if ('y' != strtolower($_GET['sys']))
$query .= " AND (owner <> '(Public)')";
$query .= " AND (body REGEXP 'Category[A-Z0-9ÄÖÜ][A-Za-z0-9ÄÖÜßäöü]*[[:>:]]')";
// this page is to be exported: pretend your are this page
$pages[$row['tag']]['title'] = $this->PageTitle();
if (!isset($_GET['type']) || $_GET['type'] == 'html')
FEhtml ($this, $pages, $key_order, $embed_css, $css_path, $remove_links, $save_tag, $save_page);
FExml ($this, $pages, $key_order, $remove_links, $save_tag, $save_page);
$xml .= '<?xml-stylesheet href="' . $this->GetConfigValue("base_url") .'/css/xml.css" type="text/css"?' .">\n";
Deletions:
- Wikka 1.1.6.2 & 1.1.6.3
- Save the first code block below as ##actions/fileexport.php##
%%(php)<?php
# @version 0.97
# @input Parameters = [type=('html'|'rawhtml'|'xml')] [sort=('tag'|'type'|'time')] [scope=('PageTag'|'m'|'o'|'p')] [opts=['e']['r']] [cats='Category1','Category2'..]
if (!defined('FE_ERROR_USAGE')) define ('FE_ERROR_USAGE', "fileexport [type=\"html|rawhtml|xml\"] [scope=\"PageTag|m|o|p\"] [opts=\"[e][r]\"] [sort=\"tag|time|title\"] [cats=\"<i>category list</i>\"]");
if (!defined('FE_ERROR_MISSING_PAGE')) define ('FE_ERROR_MISSING_PAGE', 'Can not export: page \'%s\' does not exist');
return ('<em class="error">'. $msg .'</em><br />');
$output = '';
if ( (isset($vars['opts']) && (!preg_match("/^[er]{1,4}$/i", $vars['opts'])))
|| (isset($vars['scope']) && (!preg_match("/^([oO]|[pP]|[mM]|[A-ZÄÖÜ]+[a-zßäöü]+[A-Z0-9ÄÖÜ][A-Za-z0-9ÄÖÜßäöü]*)$/", $vars['scope'])))
|| (isset($vars['type']) && (!preg_match("/^(html|rawhtml|xml)$/i", $vars['type'])))
else if ( isset($vars['scope']) && preg_match("/^[A-ZÄÖÜ]+[a-zßäöü]+[A-Z0-9ÄÖÜ][A-Za-z0-9ÄÖÜßäöü]*$/", $vars['scope']) && !$this->ExistsPage($vars['scope']) )
$output .= FEerror(sprintf(FE_ERROR_MISSING_PAGE, $vars['scope']));
$query = '&type='. $type;
$query .= '&scope='. (isset($vars['scope']) ? $vars['scope'] : 'm');
$query .= '&cats=';
%%(php)<?php
# @version 1.04
if (!defined('FE_TABLE_OF_CONTENTS')) define ('FE_TABLE_OF_CONTENTS', 'Table of contents');
if (!defined('FE_ERROR_REQUEST_STRING')) define ('FE_ERROR_REQUEST_STRING', 'Illegal request string, unable to export');
if (!defined('FE_ERROR_ARCHIVE_BUILD')) define ('FE_ERROR_ARCHIVE_BUILD', 'Error building the archive file, unable to export');
function FEerror($msg)
return ('<em class="error">'. $msg .'</em><br />');
function FEpage_data(&$this, $tag, &$page_content)
// add page footer from FootnoteAction
function FEhtml(&$this, &$pages, &$key_order, $embed_css, $css_path, $remove_links, $save_tag, $save_page, $raw=false)
$root_url = $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'];
$header = "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>\n".
"<html><head><meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' />\n";
if ($fcss = fopen($css_path, 'r'))
if (!($stylesheet = file_get_contents($css_path)))
$stylesheet = '';
else
$stylesheet = "<style type='text/css'>$stylesheet\n</style>";
$stylesheet = '';
$header .= ($embed_css ? $stylesheet : '') .'<title>'. $this->GetConfigValue('wakka_name') ."</title></head><body>\n";
$toc = '';
$file_name = $this->GetConfigValue('wakka_name') .'_'. date('Ymd');
foreach ($pages as $tag => $mypage)
{ // prepare mapping table for translation of intra-wiki links
$pat[] = '/'. preg_quote('http://'.$root_url, '/') .'\?wakka='. $tag .'([^\w^Ä^Ö^Ü^ß^ä^ö^ü])/';
$rep[] = '#'. $mypage['i'] .'$1';
$save_includes = $this->config['includes'];
foreach ($key_order as $tag => $val)
$pagedata = array();
FEpage_data($this, $tag, $pagedata);
$toc .= '<li><a href="#'. $pages[$tag]['i'] .'">'. $pages[$tag]['title'] ."</a></li>\n";
if (!$raw)
{ // preserve intra-wiki links
$pagedata['body'] = '<a name="'. $pages[$tag]['i'] .'"></a>'. preg_replace($pat, $rep, $pagedata['body']);
else
{ // remove all intra-wiki links for raw HTML
$pat = '/<\s*a[^>]+href=([\'\"])'. preg_quote('http://'.$root_url, '/') .'\?wakka=.+?[^>].*?\>(.*?)<\/a>/';
$pagedata['body'] = preg_replace($pat, "$2", $pagedata['body']);
// relabel footnotes from FootnoteAction
$pagedata['body'] = preg_replace("/href=\'\#(\d+)\#fn(\d+)/", "href='#fn$1_$2", $pagedata['body']);
$pagedata['body'] = preg_replace("/id=\'fn(\d+)/", "id='fn". $pages[$tag]['i']. "_$1", $pagedata['body']);
$pagedata['body'] = preg_replace("/href=\'\#(\d+)\#fnback(\d+)/", "href='#fnback$1_$2", $pagedata['body']);
$pagedata['body'] = preg_replace("/id=\'fnback(\d+)/", "id='fnback". $pages[$tag]['i']. "_$1", $pagedata['body']);
// if requested, remove external links including tail
if ($remove_links)
{
$pagedata['body'] = preg_replace("/<\s*a[^>]+href=([\'\"])[^#][^>]*?\>(.*?)<\/a>/", "$2", $pagedata['body']);
$pagedata['body'] = preg_replace('/'.preg_quote($this->GetConfigValue('external_link_tail'),'/').'/', '', $pagedata['body']);
else if ($raw)
{ // remove links tail
$pagedata['body'] = preg_replace('/'.preg_quote($this->GetConfigValue('external_link_tail'),'/').'/', '', $pagedata['body']);
$output .= $pagedata['body'] ."<hr />\n";
if (!$raw)
$output = $header .'<div class="page"><h2>'. FE_TABLE_OF_CONTENTS. '</h2><ul>'. $toc .'</ul><hr />'. $output . '</div></body></html>';
else
{ // remove last ruler from raw HTML
$output = preg_replace('/\<hr \/\>$/', '', $output);
// restore original values
$this->tag = $save_tag;
$this->page = $save_page;
$this->config['includes'] = $save_includes;
header('Content-Disposition: attachment; filename='. $file_name .'.html');
header('Content-Type: text/html; charset=ISO-8859-1');
header('Expires: 0');
header('Pragma: no-cache');
print $output;
exit();
function FExml(&$this, &$pages, &$key_order, $remove_links, $save_tag, $save_page)
$file_name = $this->GetConfigValue('wakka_name') .'_'. date('Ymd');
$output = '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?><wikka>';
$save_includes = $this->config['includes'];
foreach ($key_order as $tag => $val)
$mytab = $pages[$tag];
$output .= '<page tag="'. $tag .'" lastchange="'. strftime('%Y-%m-%dT%H:%M:%S', strtotime($mytab['lastchange'])) .'"><owner>'. $mytab['owner'] .'</owner>';
foreach (explode (' ', $mytab['cats']) as $mycat)
if ($mycat)
$output .= '<category>'. $mycat. '</category>';
$output .= '<title>'. utf8_encode(htmlspecialchars($mytab['title'], ENT_COMPAT, 'UTF-8')) ."</title>\n";
$pagedata = array();
FEpage_data($this, $tag, $pagedata);
$output .= '<raw_content>'. utf8_encode(htmlspecialchars($pagedata['raw'], ENT_COMPAT)) .".</raw_content>\n";
if ($remove_links)
{ // if requested, remove external links including tail
$pagedata['body'] = preg_replace("/<\s*a[^>]+href=([\'\"])[^#][^>]*?\>(.*?)<\/a>/", "$2", $pagedata['body']);
$pagedata['body'] = preg_replace('/'.preg_quote($this->GetConfigValue('external_link_tail'),'/').'/', '', $pagedata['body']);
$output .= '<rendered_content>'. utf8_encode(htmlspecialchars($pagedata['body'], ENT_COMPAT, 'UTF-8')) .'</rendered_content>';
if (preg_match_all('/\{\{structdata(.+?)\}\}/', $pagedata['raw'], $matches))
{ // extract structured data items and add them to XML
foreach ($matches[1] as $mym)
$structdatatype = '';
$params = array();
if (preg_match('/type=\"(.*?)\"[ \t]*.*?data=\"(.*?)\"/', $mym, $matches2))
{
$structdatatype = $matches2[1];
preg_match_all('/(\w+?)\=\'(.*?)\'/', $matches2[2], $matches3);
}
else if (preg_match('/data=\"(.*?)\"[ \t]*.*?type=\"(.*?)\"/', $mym, $matches2))
{
$structdatatype = $matches2[2];
preg_match_all('/(\w+?)\=\'(.*?)\'/', $matches2[1], $matches3);
}
for ($i=0; $i < count($matches3[1]); $i++)
{
$params[strtolower($matches3[1][$i])] = $matches3[2][$i];
}
if ($structdatatype)
{
$output .= '<structdataitem type="'. $structdatatype. '">';
foreach ($params as $myparam => $myval)
{
$output .= '<'. $myparam .'>'. utf8_encode(htmlspecialchars($myval, ENT_COMPAT)) .'</'. $myparam .'>';
}
$output .= "</structdataitem>\n";
}
$output .= "</page>\n";
$output .= '</wikka>';
// restore original values
$this->tag = $save_tag;
$this->page = $save_page;
$this->config['includes'] = $save_includes;
header('Content-Disposition: attachment; filename='. $file_name .'.xml');
header('Content-Type: text/xml; charset=UTF-8');
header('Expires: 0');
header('Pragma: no-cache');
print $output;
exit();
}
if ((isset($_GET['emb']) && (!preg_match("/^[YN]$/i", $_GET['emb'])))
|| (isset($_GET['scope']) && (!preg_match("/^([oO]|[pP]|[mM]|[A-ZÄÖÜ]+[a-zßäöü]+[A-Z0-9ÄÖÜ][A-Za-z0-9ÄÖÜßäöü]*)$/", $_GET['scope'])))
|| (isset($_GET['type']) && (!preg_match("/^(html|rawhtml|xml)$/i", $_GET['type'])))
$css_path = 'css' .DIRECTORY_SEPARATOR. $this->GetConfigValue('stylesheet');
if ('m' == strtolower($_GET['scope']))
$query .= ' AND (owner = \''. $this->GetUserName() .'\')';
else if ('o' == strtolower($_GET['scope']))
$query .= ' AND (owner <> \'(Public)\')';
else if ('p' == strtolower($_GET['scope']))
{ // placeholder
$query .= '';
else
{ // a single page is exported
$query .= ' AND (tag = \''. $_GET['scope'] .'\')';
$query .= ' AND (body REGEXP \'Category[A-Z0-9ÄÖÜ][A-Za-z0-9ÄÖÜßäöü]*[[:>:]]\')';
{ // this page is to be exported: pretend your are this page
$pages[$row['tag']]['title'] = trim($this->PageTitle());
if (!isset($_GET['type']) || ($_GET['type'] == 'html') || ($_GET['type'] == 'rawhtml'))
$raw_html = ($_GET['type'] == 'rawhtml');
FEhtml($this, $pages, $key_order, $embed_css, $css_path, $remove_links, $save_tag, $save_page, $raw_html);
FExml($this, $pages, $key_order, $remove_links, $save_tag, $save_page);
$xml .= '<?xml-stylesheet href="' . $this->GetConfigValue('base_url') .'/css/xml.css" type="text/css"?' .">\n";
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki