summaryrefslogtreecommitdiff
path: root/liberty_plugins/data.wikigraph.php
blob: 2aae36d805c0709671900e51cc932700596ea805 (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
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
/**
 * @version  $Revision: 1.6 $
 * @package  liberty
 * @subpackage plugins_data
 */
/**
 * definitions
 */
namespace Bitweaver\Liberty;

use Bitweaver\KernelTools;
global $gBitSystem, $gLibertySystem;

// only include this plugin if wiki is active and we have GraphViz
if( @include_once 'Image/GraphViz.php' ) {

define( 'PLUGIN_GUID_DATAWIKIGRAPH', 'datawikigraph' );
$pluginParams = [
	'tag'           => 'wikigraph',
	'auto_activate' => false,
	'requires_pair' => true,
	'load_function' => 'data_wikigraph',
	'title'         => 'WikiGraph',
	'help_page'     => 'DataPluginWikiGraph',
	'description'   => KernelTools::tra( "Inserts a graph for visual navigation. The graph shows the page and every page that can be reached from that page. It requies the Image_GraphViz pear plugin and graphviz to be installed: <strong>pear install Image_GraphViz</strong>" ),
	'help_function' => 'data_wikigraph_help',
	'syntax'        => "{wikigraph level= title= }".KernelTools::tra( "Wiki page name" )."{/wikigraph}",
	'plugin_type'   => DATA_PLUGIN
];
$gLibertySystem->registerPlugin( PLUGIN_GUID_DATAWIKIGRAPH, $pluginParams );
$gLibertySystem->registerDataTag( $pluginParams['tag'], PLUGIN_GUID_DATAWIKIGRAPH );

function data_wikigraph_help() {
	$help =
		'<table class="data help">'
			.'<tr>'
				.'<th>'.KernelTools::tra( "Key" ).'</th>'
				.'<th>'.KernelTools::tra( "Type" ).'</th>'
				.'<th>'.KernelTools::tra( "Comments" ).'</th>'
			.'</tr>'
			.'<tr class="odd">'
				.'<td>level</td>'
				.'<td>'.KernelTools::tra( "numeric").'<br />'.KernelTools::tra( "(optional)" ).'</td>'
				.'<td>'.KernelTools::tra( "The number of levels that will be followed from the starting page." ).' '.KernelTools::tra( "Default").': 0</td>'
			.'</tr>'
			.'<tr class="even">'
				.'<td>title</td>'
				.'<td>'.KernelTools::tra( "string").'<br />'.KernelTools::tra( "(optional)" ).'</td>'
				.'<td>'.KernelTools::tra( "Title of the graph.").' '.KernelTools::tra( "Default ").': Wiki-Graph</td>'
			.'</tr>'
			.'<tr class="odd">'
				.'<td>nodesep</td>'
				.'<td>'.KernelTools::tra( "numeric").'<br />'.KernelTools::tra( "(optional)" ).'</td>'
				.'<td>'.KernelTools::tra( "Distance between nodes in inches.").' '.KernelTools::tra( "Default").': 1.2</td>'
			.'</tr>'
			.'<tr class="even">'
				.'<td>rankdir</td>'
				.'<td>'.KernelTools::tra( "string").'<br />'.KernelTools::tra( "(optional)" ).'</td>'
				.'<td>'.KernelTools::tra( "Direction of graph layout - can be Left to Right (LR), Right to Left (RL), Top to Bottom (TB), Bottom to Top (BT).").' '.KernelTools::tra( "Default").': TB</td>'
			.'</tr>'
			.'<tr class="odd">'
				.'<td>bgcolor</td>'
				.'<td>'.KernelTools::tra( "html colour").'<br />'.KernelTools::tra( "(optional)" ).'</td>'
				.'<td>'.KernelTools::tra( "Background colour of the graph.").' '.KernelTools::tra( "Default").': KernelTools::transparent</td>'
			.'</tr>'
			.'</table>'
		.KernelTools::tra( "Example: " )."{wikigraph level=1}Welcome{/wikigraph}";
	return $help;
}

function data_wikigraph( $pData, $pParams ) {
	global $gContent, $gBitThemes;
	$ret = " ";

	// check to see if we have pear available.
//	if( $error = pear_check( "Image/GraphViz.php" )) {
//		return $error;
//	}

	if( !empty( $gContent ) && is_object( $gContent )) {
		$querystring = "";

		$title = !empty( $pParams['title'] ) ? $pParams['title'] : 'Wiki-Graph';
		unset( $pParams['title'] );

		foreach( $pParams as $param => $value ) {
			$querystring .= "&amp;{$param}={$value}";
		}

		if( empty( $pData ) ) {
			$pData = ( is_object( $gContent ) || !empty( $gContent->mPageName )) ? $gContent->mPageName : null;
		}

		if( !empty( $pData ) ) {
			$params = array(
				'graph' => $gBitThemes->getGraphvizGraphAttributes( $pParams ),
				'node'  => $gBitThemes->getGraphvizNodeAttributes( $pParams ),
				'edge'  => $gBitThemes->getGraphvizEdgeAttributes( $pParams ),
			);

			$mapname = md5( microtime() );
			$mapdata = $gContent->linkStructureMap( $pData, isset( $pParams['level'] ) ? $pParams['level'] : 0, $params );

			$ret = "
				<div style='text-align:center'>
				<img src=\"".WIKI_PKG_URL."wiki_graph.php?page=".urlencode( $pData )."{$querystring}\" alt='{$title}' usemap='#$mapname' />
				<map name='$mapname'>$mapdata</map>
				</div>";
			$ret = preg_replace( "/\n|\r/", '', $ret );
		}
	}
	return $ret;
}

} // graphviz check