summaryrefslogtreecommitdiff
path: root/liberty_plugins/data.component.php
blob: 31f40e3a20d51afe0369e0dd90696b388a04b577 (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\StockComponent;
use Bitweaver\BitBase;
use Bitweaver\KernelTools;

define( 'PLUGIN_GUID_DATACOMPONENT', 'datacomponent' );

global $gLibertySystem;

$pluginParams = [
	'tag'           => 'component',
	'title'         => 'Stock Component',
	'description'   => KernelTools::tra( "Display a link to a component in other content." ),
	'help_page'     => 'DataPluginComponent',

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

	'booticon'       => '{biticon ipackage="icons" iname="emblem-favorite" iexplain="Component"}',
	'taginsert'     => '{component id= nolink=}',

	'help_function' => 'data_component_help',
	'load_function' => 'data_component',
];
$gLibertySystem->registerPlugin( PLUGIN_GUID_DATACOMPONENT, $pluginParams );
$gLibertySystem->registerDataTag( $pluginParams['tag'], PLUGIN_GUID_DATACOMPONENT );

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

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

	return $ret;
}

function data_component_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( "Component id number of the component 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 component title without a hyperlink." ) . '</td>'
			.'</tr>'
		.'</table>'
		. KernelTools::tra( "Example: ") . "{component id='13'}";
	return $help;
}