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

namespace Bitweaver\Liberty;

use Bitweaver\KernelTools;

/**
 * assigned_modules
 *
 * @author     xing
 * @version    $Revision$
 * @package    liberty
 * @subpackage plugins_data
 * @copyright  Copyright (c) 2004, bitweaver.org
 */

/**
 * Setup Code
 */
define( 'PLUGIN_GUID_DATAPRE', 'datapre' );
global $gLibertySystem;
$pluginParams = [
	'tag'           => 'PRE',
	'auto_activate' => false,
	'requires_pair' => true,
	'load_function' => '\data_pre',
	'title'         => 'Pre',
	'help_page'     => 'DataPluginPre',
	'description'   => KernelTools::tra( "This plugin allows you to easily create a preformatted text block with a number of optional CSS parameters." ),
	'help_function' => '\data_pre_help',
	'syntax'        => "{pre border='3px solid blue'}",
	'plugin_type'   => DATA_PLUGIN,
];
$gLibertySystem->registerPlugin( PLUGIN_GUID_DATAPRE, $pluginParams );
$gLibertySystem->registerDataTag( $pluginParams['tag'], PLUGIN_GUID_DATAPRE );

function data_pre_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>' . KernelTools::tra( "CSS rules" ) . '</td>'
				.'<td>' . KernelTools::tra( "string") . '<br />' . KernelTools::tra( "(optional)" ) . '</td>'
				.'<td>' . KernelTools::tra( "This can be any CSS style rule. e.g.: ") . "border='3px solid blue'" .'</td>'
			.'</tr>'
			.'<tr class="even">'
				.'<td>preset</td>'
				.'<td>' . KernelTools::tra( "string") . '<br />' . KernelTools::tra( "(optional)" ) . '</td>'
				.'<td>' . KernelTools::tra( "There are a few presets, which you can use to style with. Presets include: dark, orange, red, blue, centered.") .'</td>'
			.'</tr>'
		.'</table>'
		. KernelTools::tra( "Example: " ) . "{pre preset=centered border='3px solid blue'}";
	return $help;
}

function data_pre( $pData, $pParams, $pCommonObject, $pParseHash ) {
	$style = '';
	foreach( $pParams as $key => $value ) {
		if( !empty( $value ) ) {
			switch( $key ) {
				case 'preset':
					if( $value == 'dark' ) {
						$style .= 'background:#333;color:#ccc;border:2px solid #000;padding:0.5em 1em;margin:0.5em;';
					} elseif( $value == "orange" ) {
						$style .= 'background:#f60;color:#fff;border:2px solid #900;padding:0.5em 1em;margin:0.5em;';
					} elseif( $value == "red" ) {
						$style .= 'background:#eee;color:#900;border:2px solid #900;padding:0.5em 1em;margin:0.5em;';
					} elseif( $value == "blue" ) {
						$style .= 'background:#def;color:#009;border:2px solid #acf;padding:0.5em 1em;margin:0.5em;';
					} elseif( $value == "centered" ) {
						$style .= 'background:#eee;color:#333;border:2px solid #ddd;padding:0.5em 1em;margin:0.5em auto;width:50%;text-align:center;';
					}
					break;
				case 'style':
					$style .= $value;
					break;
				case 'class':
					$class = $value;
					break;
				default:
					$style .= $key.':'.$value.';';
				break;
			}
		}
	}
	$parseHash['content_id'] = $pParseHash['content_id'];
	$parseHash['user_id'] = $pParseHash['user_id'];
	$parseHash['no_cache'] = true;
	$parseHash['data'] = $pData;
	$ret = '<pre '.( !empty( $class ) ? 'class="'.$class.'" ' : '' ).'style="'.$style.'">'.LibertyContent::parseDataHash( $parseHash, $pCommonObject ).'</pre>';
	return $ret;
}