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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
<?php
/**
* @version $Revision: 1.8 $
* @package liberty
* @subpackage plugins_data
*/
// +----------------------------------------------------------------------+
// | Copyright (c) 2004, bitweaver.org
// +----------------------------------------------------------------------+
// | All Rights Reserved. See copyright.txt for details and a complete list of authors.
// | Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details
// |
// | For comments, please use phpdocu.sourceforge.net documentation standards!!!
// | -> see http://phpdocu.sourceforge.net/
// +----------------------------------------------------------------------+
// | Authors: drewslater <andrew@andrewslater.com>
// +----------------------------------------------------------------------+
// $Id: data.attachment.php,v 1.8 2006/12/09 10:39:58 squareing Exp $
/**
* definitions
*/
global $gBitSystem;
define( 'PLUGIN_GUID_DATAATTACHMENT', 'dataattachment' );
global $gLibertySystem;
$pluginParams = array (
'tag' => 'ATTACHMENT',
'auto_activate' => TRUE,
'requires_pair' => FALSE,
'load_function' => 'data_attachment',
'title' => 'Attachment',
'help_page' => 'DataPluginAttachment',
'description' => tra("Display attachment in content"),
'help_function' => 'data_attachment_help',
'syntax' => '{ATTACHMENT id= size= align= }',
'path' => LIBERTY_PKG_PATH.'plugins/data.attachment.php',
'security' => 'registered',
'plugin_type' => DATA_PLUGIN
);
$gLibertySystem->registerPlugin( PLUGIN_GUID_DATAATTACHMENT, $pluginParams );
$gLibertySystem->registerDataTag( $pluginParams['tag'], PLUGIN_GUID_DATAATTACHMENT );
function data_attachment_help() {
$help =
'<table class="data help">'
.'<tr>'
.'<th>' . tra( "Key" ) . '</th>'
.'<th>' . tra( "Type" ) . '</th>'
.'<th>' . tra( "Comments" ) . '</th>'
.'</tr>'
.'<tr class="odd">'
.'<td>id</td>'
.'<td>' . tra( "numeric") . '<br />' . tra("(required)") . '</td>'
.'<td>' . tra( "Id number of Attachment to display inline.") . '</td>'
.'</tr>'
.'<tr class="even">'
.'<td>size</td>'
.'<td>' . tra( "key-words") . '<br />' . tra("(optional)") . '</td>'
.'<td>' . tra( "If the Attachment is an image, you can specify the size of the thumbnail displayed. Possible values are:") . ' <strong>avatar, small, medium, large, original</strong> '
. tra( "(Default = " ) . '<strong>medium</strong>)</td>'
.'</tr>'
.'<tr class="odd">'
.'<td>link</td>'
.'<td>' . tra( "string") . '<br />' . tra("(optional)") . '</td>'
.'<td>' . tra( "Allows you to specify a relative or absolute URL the image will link to if clicked. If set to false, no link is inserted.")
. tra("(Default = ") . '<strong>'.tra( 'link to source image' ).'</strong>)</td>'
.'</tr>'
.'<tr class="even">'
.'<td>'.tra( "styling" ).'</td>'
.'<td>'.tra( "string").'<br />'.tra("(optional)").'</td>'
.'<td>'.tra( "Multiple styling options available: padding, margin, background, border, text-align, color, font, font-size, font-weight, font-family, align. Please view CSS guidelines on what values these settings take.").'</td>'
.'</tr>'
.'</table>'
. tra("Example: ") . "{ATTACHMENT id='13' size='small' text-align='center' link='http://www.google.com'}";
return $help;
}
function data_attachment($data, $params) { // NOTE: The original plugin had several parameters that have been dropped
// at a minimum, return blank string (not empty) so we still replace the tag
$ret = ' ';
if( empty( $params['id'] ) ) {
// The Manditory Parameter is missing. we are not gonna trow an error, and just return empty since
// many sites use the old style required second "closing" empty tag
return $ret;
}
$liba = new LibertyAttachable();
if( !$att = $liba->getAttachment( $params['id'] ) ) {
$ret = tra( "The attachment id given is not valid." );
return $ret;
}
// insert source url if we need the original file
if( !empty( $params['size'] ) && $params['size'] == 'original' ) {
$thumburl = $att['source_url'];
} else {
$thumburl = ( !empty( $params['size'] ) && !empty( $att['thumbnail_url'][$params['size']] ) ? $att['thumbnail_url'][$params['size']] : $att['thumbnail_url']['medium'] );
}
$attstring = array();
$attstring['div_style'] = '';
foreach( $params as $key => $value ) {
if( !empty( $value ) ) {
switch( $key ) {
// rename a couple of parameters
case 'background-color':
$key = 'background';
case 'description':
$key = 'desc';
case 'class':
$class = $value;
break;
case 'float':
case 'padding':
case 'margin':
case 'background':
case 'border':
case 'text-align':
case 'color':
case 'font':
case 'font-size':
case 'font-weight':
case 'font-family':
$attstring['div_style'] .= $key.':'.$value.';';
break;
case 'align':
if( $value == 'center' || $value == 'middle' ) {
$attstring['div_style'] .= 'text-align:center;';
} else {
$attstring['div_style'] .= 'float:'.$value.';';
}
break;
default:
$attstring[$key] = $value;
break;
}
}
}
// check if we have a valid thumbnail
if( !empty( $thumburl ) ) {
// set up image first
$ret = '<img'.
' alt="'. ( !empty( $attstring['desc'] ) ? $attstring['desc'] : tra( 'Image' ) ).'"'.
' title="'.( !empty( $attstring['desc'] ) ? $attstring['desc'] : tra( 'Image' ) ).'"'.
' src="' .$thumburl.'"'.
' />';
// use specified link as href. insert default link to source only when source not already displayed
if( !empty( $params['link'] ) && $params['link'] == 'false' ) {
} elseif( !empty( $params['link'] ) ) {
$ret = '<a href="'.trim( $attstring['link'] ).'">'.$ret.'</a>';
} elseif( empty( $params['size'] ) || $params['size'] != 'original' ) {
$ret = '<a href="'.trim( $att['source_url'] ).'">'.$ret.'</a>';
}
// finally, wrap the image with a div
if( !empty( $attstring['div_style'] ) || !empty( $class ) || !empty( $attstring['desc'] ) ) {
$ret = '<div class="'.( !empty( $class ) ? $class : "att-plugin" ).'" style="'.$attstring['div_style'].'">'.$ret.'<br />'.( !empty( $attstring['desc'] ) ? $attstring['desc'] : '' ).'</div>';
}
} else {
$ret = tra( "The attachment id given is not valid." );
}
return $ret;
}
?>
|