summaryrefslogtreecommitdiff
path: root/plugins/data.include.php
blob: 5d6e13da068b539ee3b688d3a3044b6c5c72e471 (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
<?php

namespace Bitweaver\Liberty;

use Bitweaver\KernelTools;
use Bitweaver\Wiki\BitPage;

/**
 * @version  $Revision$
 * @package  liberty
 * @subpackage plugins_data
 */
// +----------------------------------------------------------------------+
// | Copyright (c) 2004, bitweaver.org
// +----------------------------------------------------------------------+
// | All Rights Reserved. See below for details and a complete list of authors.
// | Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details
// |
// | For comments, please use phpdocu.sourceforge.net documentation standards!!!
// | -> see http://phpdocu.sourceforge.net/
// +----------------------------------------------------------------------+
// | Author (TikiWiki): Marc Laporte <marclaporte@users.sourceforge.net>
// | Reworked for Bitweaver (& Undoubtedly Screwed-Up)
// | by: StarRider <starrrider@users.sourceforge.net>
// +----------------------------------------------------------------------+
// $Id$

/**
 * definitions
 */
define( 'PLUGIN_GUID_DATAINCLUDE', 'datainclude' );
global $gLibertySystem;
$pluginParams = [
	'tag' => 'INCLUDE',
	'auto_activate' => true,
	'requires_pair' => false,
	'load_function' => '\data_include',
	'title' => 'Include',
	'help_page' => 'DataPluginInclude',
	'description' => KernelTools::tra("This plugin is used to include the contents of one Wiki page in another Wiki page."),
	'help_function' => '\data_include_help',
	'syntax' => "{INCLUDE content_id= }",
	'plugin_type' => DATA_PLUGIN,
];
$gLibertySystem->registerPlugin( PLUGIN_GUID_DATAINCLUDE, $pluginParams );
$gLibertySystem->registerDataTag( $pluginParams['tag'], PLUGIN_GUID_DATAINCLUDE );

// Help Function
function data_include_help() {
	$help = '
		<table class="plugin help">
			<tr>
				<th>'.KernelTools::tra( 'key' ).'</th>
				<th>'.KernelTools::tra( 'type' ).'</th>
				<th>'.KernelTools::tra( 'comments' ).'</th>
			</tr>
			<tr class="odd">
				<td>page_name</td>
				<td>'.KernelTools::tra( 'string (optional)' ).'</td>
				<td>'.KernelTools::tra( 'To include any wiki page you can use it\'s page name (this has to be a unique name. if it\'s not unique, use the page_id instead) (this method is deprecated).' ).'</td>
			</tr>
			<tr class="even">
				<td>page_id</td>
				<td>'.KernelTools::tra( 'numeric (optional)' ).'</td>
				<td>'.KernelTools::tra( 'To include any wiki page you can use it\'s page_id number.' ).'</td>
			</tr>
			<tr class="odd">
				<td>content_id</td>
				<td>'.KernelTools::tra( 'numeric (optional)' ).'</td>
				<td>'.KernelTools::tra( 'To include any content from bitweaver insert the appropriate numeric content id. This can include blog posts, images, wiki texts...<br />
					Avaliable content can be viewed <a href="'.LIBERTY_PKG_URL.'list_content.php">here</a>' ).'</td>
			</tr>
		</table>
		Example: {INCLUDE page_name=Welcome}
		Example: {INCLUDE page_id=15}
		Example: {INCLUDE content_id=15}';
	return $help;
}

function data_include($data, $params) {
	$ret = "<p>Please enter a valid 'page_name', 'page_id' or 'content_id' to include in this page.</p>";
	// load page by page_id
	if( isset( $params['page_id'] ) && is_numeric( $params['page_id'] ) ) {
		global $gLibertySystem;
		$typeClass = $gLibertySystem->getContentClassName( 'bitpage' );
		$wp = new BitPage( $params['page_id'] );
		if( $wp->load() ) {
			$ret = $wp->getParsedData();
		}
	// load page by content_id
	} elseif( isset( $params['content_id'] ) && is_numeric( $params['content_id'] ) ) {
		if( $obj = LibertyBase::getLibertyObject( $params['content_id'] ) ) {
			$ret = $obj->getParsedData();
		}
	// load page by page_name
	} elseif( isset( $params['page_name'] ) ) {
		$ret = "page_name isn't working yet, please use page_id or content_id";
	}

	// if $ret is empty, we need to make sure there is at least a space that we get rid of the {}
	if( empty( $ret )) {
		$ret = ' ';
	}

	return $ret;
}