summaryrefslogtreecommitdiff
path: root/liberty_plugins/data.assembly.php
blob: 641ae7e2f792b1f6ec4b06bcc31cd22f0508dbf1 (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
<?php
/**
 * @version  $Revision$
 * $Header$
 * @package  liberty
 * @subpackage plugins_storage
 */

namespace Bitweaver\Liberty;

use Bitweaver\Stock\StockAssembly;
use Bitweaver\BitBase;
use Bitweaver\KernelTools;

define( 'PLUGIN_GUID_DATAASSEMBLY', 'dataassembly' );

global $gLibertySystem;

$pluginParams = [
	'tag'           => 'assembly',
	'title'         => 'Stock Assembly',
	'description'   => KernelTools::tra( "Display a link to a stock assembly in other content." ),
	'help_page'     => 'DataPluginAssembly',

	'auto_activate' => false,
	'requires_pair' => false,
	'syntax'        => '{assembly id= }',
	'plugin_type'   => DATA_PLUGIN,

	'booticon'       => '{biticon ipackage="icons" iname="view-list-text" iexplain="Assembly"}',
	'taginsert'     => '{assembly id= nolink=}',

	'help_function' => 'data_assembly_help',
	'load_function' => 'data_assembly',
];
$gLibertySystem->registerPlugin( PLUGIN_GUID_DATAASSEMBLY, $pluginParams );
$gLibertySystem->registerDataTag( $pluginParams['tag'], PLUGIN_GUID_DATAASSEMBLY );

function data_assembly( $pData, $pParams ) {
	global $gBitSystem;
	$ret = ' ';

	if( BitBase::verifyId( $pParams['id'] ) && $gBitSystem->isPackageActive( 'stock' ) ) {
		$assembly = new StockAssembly( null, $pParams['id'] );
		if( $assembly->load() ) {
			$title = htmlspecialchars( $assembly->getTitle() );
			if( !empty( $pParams['nolink'] ) ) {
				$ret = $title;
			} else {
				$url = htmlspecialchars( $assembly->getDisplayUrl() );
				$ret = '<a href="'.$url.'">'.$title.'</a>';
			}
		} else {
			$ret = KernelTools::tra( "Unknown Assembly" );
		}
	} else {
		$ret = KernelTools::tra( "Unknown Assembly" );
	}

	return $ret;
}

function data_assembly_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>id</td>'
				.'<td>' . KernelTools::tra( "numeric") . '<br />' . KernelTools::tra("(required)") . '</td>'
				.'<td>' . KernelTools::tra( "Assembly id number of the assembly to link to." ) . '</td>'
			.'</tr>'
			.'<tr class="even">'
				.'<td>nolink</td>'
				.'<td>' . KernelTools::tra( "key-words") . '<br />' . KernelTools::tra("(optional)") . '</td>'
				.'<td>' . KernelTools::tra( "Display the assembly title without a hyperlink." ) . '</td>'
			.'</tr>'
		.'</table>'
		. KernelTools::tra( "Example: ") . "{assembly id='5'}";
	return $help;
}