summaryrefslogtreecommitdiff
path: root/plugins/data.quote.php
blob: a05d4e205ad5d846aa4fa37ae9c5bb0962e7781e (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php

namespace Bitweaver\Liberty;

use Bitweaver\KernelTools;
use Bitweaver\Boards\BitBoardPost;
use Bitweaver\Users\RoleUser;

/**
 * @version  $Revision$
 * @package  liberty
 * @subpackage plugins_data
 */
// +----------------------------------------------------------------------+
// | Copyright (c) 2005, 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): Gustavo Muslera <gmuslera@users.sourceforge.net>
// | Reworked for Bitweaver (& Undoubtedly Screwed-Up)
// | by: wjames5
// | Reworked from: data.articles.php from wikiplugin_articles.php
// +----------------------------------------------------------------------+
// $Id$

/**
 * definitions
 */
global $gBitSystem, $gBitSmarty;
define( 'PLUGIN_GUID_DATAQUOTE', 'dataquote' );
global $gLibertySystem;
$pluginParams = [
	'tag'           => 'quote',
	'auto_activate' => false,
	'requires_pair' => true,
	'load_function' => '\data_quote',
	'help_function' => '\data_quote_help',
	'title'         => 'Quote',
	'help_page'     => 'DataPluginQuote',
	'description'   => KernelTools::tra( "This plugin allows content to be attributed to other authors and visually indicated." ),
	'syntax'        => "{quote format_guid= user= comment_id= }.. content ..{/quote}",
	'plugin_type'   => DATA_PLUGIN,
];
$gLibertySystem->registerPlugin( PLUGIN_GUID_DATAQUOTE, $pluginParams );
$gLibertySystem->registerDataTag( $pluginParams['tag'], PLUGIN_GUID_DATAQUOTE );

// Help Routine
function data_quote_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=\"even\">
				<td>comment_id</td>
				<td>" . KernelTools::tra( "comment_id") . '<br />' . KernelTools::tra("(optional)") . "</td>
				<td>" . KernelTools::tra( "specify the comment_id of the comment being quoted") . "</td>
			</tr>
			<tr class=\"odd\">
				<td>user</td>
				<td>" . KernelTools::tra( "user") . '<br />' . KernelTools::tra("(optional)") . "</td>
				<td>" . KernelTools::tra( "specify the user whose comemnt is being quoted") . "</td>
			</tr>
			<tr class=\"even\">
				<td>format_guid</td>
				<td>" . KernelTools::tra( "string") . '<br />' . KernelTools::tra("(required)") . "</td>
				<td>" . KernelTools::tra( "Specify what renderer should be used to render the contents") . "</td>
			</tr>
		</table>".
	KernelTools::tra("Example: ") . '{quote format_guid="tikiwiki" comment_id="7" user="user"} ... {/quote}<br />';
	return $help;
}

// Executable Routine
function data_quote( $pData, $pParams ) {
	global $gLibertySystem, $gBitSmarty, $gBitSystem;

	if( empty( $pParams['format_guid'] )) {
		// default should be set - if not, we'll use tikiwiki - can't use PLUGIN_GUID_TIKIWIKI since it might not be defined.
		$pParams['format_guid'] = $gBitSystem->getConfig( 'default_format', 'tikiwiki' );
	}

	$rendererHash = [];
	$rendererHash['content_id'] = 0;
	$rendererHash['format_guid'] = $pParams['format_guid'];
	$rendererHash['data'] = trim( $pData );
	$formatGuid = $rendererHash['format_guid'];
	$ret = "";

	if( $func = $gLibertySystem->getPluginFunction( $formatGuid, 'load_function' ) ) {
//		$ret = $func( $rendererHash, $this );
	}

	$quote = [];
	$user = empty( $pParams['user'] ) ? null : $pParams['user'];

	if( !empty( $pParams['comment_id'] )) {

		$c = $gBitSystem->getActivePackage() == 'boards'
			? new BitBoardPost( preg_replace( '/[^0-9]/', '', $pParams['comment_id'] ) )
			: new LibertyComment( preg_replace( '/[^0-9]/', '', $pParams['comment_id'] ) );

		if( empty( $c->mInfo['title'] )) {
			$c->mInfo['title'] = "#".$c->mCommentId;
		}

		$quote['cite_url'] = $c->getDisplayUrl();
		$quote['title'] = $c->mInfo['title'];
		$quote['created'] = $c->mInfo['created'];

		if( empty( $user )) {
			$user = $c->mInfo['login'];
		}
	}

	$quote['login'] = $user;

	if( !empty( $user )) {
		$u = new RoleUser();
		$u->load( true, $user );

		$quote['user_url'] = $u->getDisplayUrl();
		$quote['user_display_name'] = $u->mInfo['display_name'];
	}

	$quote['ret'] = $ret;

	$gBitSmarty->assign( "quote", $quote );
	$repl = $gBitSmarty->fetch( "bitpackage:liberty/plugins/data_quote.tpl" );

	return $repl;
}