summaryrefslogtreecommitdiff
path: root/plugins/format.pearwiki_general.php.off
blob: 0e13964c7bfebbf81b86c83db1351a485173ea66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php

namespace Bitweaver\Liberty;

/**
 * @version  $Revision$
 * @package  liberty
 * @subpackage plugins_format
 */

/**
 * definitions
 */
global $gLibertySystem;
if( @include_once 'PEAR/Registry.php' ) {
	if( @include_once 'Text/Wiki.php' ) {

$genPluginParams = array (
	'store_function' => 'pearwiki_general_save_data',
	'verify_function' => 'pearwiki_general_verify_data',
	'plugin_type' => FORMAT_PLUGIN,
	'linebreak' => "\r\n"
);

$reg = new \PEAR_Registry();

foreach( $reg->listPackages() as $package ) {
	if( preg_match( '!^text_wiki!', $package )) {
		// get package information
		$inf = $reg->packageInfo( $package );

		// package information is all over the place. this should clean it up a bit
		if( !empty( $inf['name'] )) {
			$package = $inf['name'];
		} elseif( !empty( $inf['name'] )) {
			$package = $inf['package'];
		} else {
			continue;
		}

		// fetch parser name
		$p = substr( $package, strlen( "text_wiki" ));
		if( empty( $p )) {
			$parser = "Text_Wiki";
			$parser_class = "Default";
		} else {
			$parser = substr( $p,1 );
			$parser_class = $parser;
		}

		$f = create_function('&$pParseHash, &$pCommonObject','return pearwiki_general_parse_data("'.$parser_class.'",$pParseHash, $pCommonObject);');
		$guid = "pearwiki_$parser";
		if (strlen($guid)>16) {
			$guid = "pw_$parser";
		}
		if (strlen($guid)>16) {
			$guid = substr($guid,0,16);
		}
		$insPluginParams =  [
			'load_function' => $f,
			'edit_field' => "<input type=\"radio\" name=\"format_guid\" value=\"$guid\"",
			'description' => "Pear Wiki Parser for $parser Syntax.",
			'edit_label' => "$parser Syntax, parsed by Pear::Text_Wiki$p",
			'help_page' => "{$parser}Syntax",
			'auto_activate' => false,
		];
		$gLibertySystem->registerPlugin( $guid, array_merge($genPluginParams,$insPluginParams) );

	}
}

	}
}

function pearwiki_general_save_data( &$pParamHash ) {
}

function pearwiki_general_verify_data( &$pParamHash ) {
	$pParamHash['content_store']['data'] = $pParamHash['edit'];
	return null;
}

function pearwiki_general_parse_data( $parser_fmt, &$pParseHash, &$pCommonObject ) {
	global $gBitSystem;

	if (!defined('PAGE_SEP')) {
		define('PAGE_SEP', 'PAGE MARKER HERE*&^%$#^$%*PAGEMARKERHERE');
	}
	$parser = \Text_Wiki::singleton($parser_fmt);
	if (\PEAR::isError($parser)) {
		$gBitSystem->fatalError( "There was an unknown error while constructing the PEAR parser." );
	}
	global $gBitSystem;
	if ($gBitSystem->isPackageActive('wiki')) {
		$parser->setRenderConf('xhtml', 'wikilink', 'exists_callback', [ &$pCommonObject, 'pageExists' ] );
		$parser->setRenderConf('xhtml', 'wikilink', 'view_url', [ TIKI_PKG_URL.'index.php?page=' ] );
		$parser->setRenderConf('xhtml', 'wikilink', 'new_url', [ TIKI_PKG_URL.'edit.php?page=' ] );
	}
	$parser->setRenderConf('xhtml', 'table', 'css_table', [ 'wikitable' ] );
	$xhtml = $parser->transform( $pParseHash['data'], 'Xhtml' );

	return $xhtml;
}