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
|
<?php
/**
* @version $Revision$
* $Header$
* @package liberty
* @subpackage plugins_storage
*/
/**
* required setup
*/
namespace Bitweaver\Liberty;
use Bitweaver\Fisheye\FisheyeImage;
use Bitweaver\BitBase;
use Bitweaver\KernelTools;
/**
* definitions
*/
define( 'PLUGIN_GUID_DATAIMAGE', 'dataimage' );
global $gLibertySystem;
$pluginParams = [
'tag' => 'image',
'title' => 'Fisheye Image',
'description' => KernelTools::tra( "Display an image in other content. This plugin only works with files that have been uploaded using fisheye." ),
'help_page' => 'DataPluginImage',
'auto_activate' => false,
'requires_pair' => false,
'syntax' => '{image id= }',
'plugin_type' => DATA_PLUGIN,
// display icon in quicktags bar
'booticon' => '{booticon iname="icon-picture" iexplain="Image"}',
'taginsert' => '{image id= size= nolink=}',
// functions
'help_function' => 'data_image_help',
'load_function' => 'data_image',
];
$gLibertySystem->registerPlugin( PLUGIN_GUID_DATAIMAGE, $pluginParams );
$gLibertySystem->registerDataTag( $pluginParams['tag'], PLUGIN_GUID_DATAIMAGE );
function data_image( $pData, $pParams ) {
global $gBitSystem, $gBitSmarty;
$ret = ' ';
$imgStyle = '';
$wrapper = \Bitweaver\Liberty\liberty_plugins_wrapper_style( $pParams );
$description = !isset( $wrapper['description'] ) ? $wrapper['description'] : null;
foreach( $pParams as $key => $value ) {
if( !empty( $value ) ) {
switch( $key ) {
// rename a couple of parameters
case 'width':
case 'height':
if( preg_match( "/^\d+(em|px|%|pt)$/", trim( $value ) ) ) {
$imgStyle .= $key.':'.$value.';';
} elseif( preg_match( "/^\d+$/", $value ) ) {
$imgStyle .= $key.':'.$value.'px;';
}
// remove values from the hash that they don't get used in the div as well
$pParams[$key] = null;
break;
}
}
}
$wrapper = \Bitweaver\Liberty\liberty_plugins_wrapper_style( $pParams );
if( !empty( $pParams['src'] ) ) {
$thumbUrl = $pParams['src'];
} elseif( BitBase::verifyId( $pParams['id'] ) && $gBitSystem->isPackageActive( 'fisheye' )) {
$item = new FisheyeImage( $pParams['id'], null );
if( $item->load() ) {
// insert source url if we need the original file
if( !empty( $pParams['size'] ) && $pParams['size'] == 'original' ) {
$thumbUrl = $item->getDownloadUrl();
} elseif( $item->mInfo['thumbnail_url'] ) {
$thumbUrl = !empty( $pParams['size'] ) && !empty( $item->mInfo['thumbnail_url'][$pParams['size']] ) ? $item->mInfo['thumbnail_url'][$pParams['size']] : $item->mInfo['thumbnail_url']['medium'];
}
if( empty( $description ) ) {
$description = !isset( $wrapper['description'] ) ? $wrapper['description'] : $item->getField( 'title', KernelTools::tra( 'Image' ) );
}
}
}
// check if we have a valid thumbnail
if( !empty( $thumbUrl )) {
// set up image first
$ret = '<img'.
' alt="'. $description.'"'.
' title="'.$description.'"'.
' src="' .$thumbUrl.'"'.
' style="'.$imgStyle.'"'.
' />';
if( !empty( $pParams['nolink'] ) ) {
} elseif( !empty( $wrapper['link'] ) ) {
// if this image is linking to something, wrap the image with the <a>
$ret = '<a href="'.trim( $wrapper['link'] ).'">'.$ret.'</a>';
} elseif ( empty( $pParams['size'] ) || $pParams['size'] != 'original' ) {
if ( $gBitSystem->isFeatureActive( 'site_fancy_zoom' ) and !empty( $item->mInfo['source_url'] ) ) {
$ret = '<a href="'.trim( str_replace(' ', '%20', $item->mInfo['source_url'] ) ).'">'.$ret.'</a>';
} else if ( $item->getDownloadUrl() ) {
$ret = '<a href="'.trim( $item->getDownloadUrl() ).'">'.$ret.'</a>';
} else if ( !empty( $item->mInfo['media_url'] ) ) {
$ret = '<a href="'.trim( $item->mInfo['media_url'] ).'">'.$ret.'</a>';
}
}
if( !empty( $wrapper['style'] ) || !empty( $class ) || !empty( $wrapper['description'] ) ) {
$ret = '<'.$wrapper['wrapper'].' class="'.( !empty( $wrapper['class'] ) ? $wrapper['class'] : "img-plugin" ).'" style="'.$wrapper['style'].'">'.$ret.( !empty( $wrapper['description'] ) ? '<br />'.$wrapper['description'] : '' ).'</'.$wrapper['wrapper'].'>';
}
} else {
$ret = KernelTools::tra( "Unknown Image" );
}
return $ret;
}
function data_image_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( "Image id number of Image to display inline.") . KernelTools::tra( "You can use either content_id or id." ).'</td>'
.'</tr>'
.'<tr class="even">'
.'<td>size</td>'
.'<td>' . KernelTools::tra( "key-words") . '<br />' . KernelTools::tra("(optional)") . '</td>'
.'<td>' . KernelTools::tra( "If the File is an image, you can specify the size of the thumbnail displayed. Possible values are:") . ' <strong>avatar, small, medium, large, original</strong> '
. KernelTools::tra( "(Default = " ) . '<strong>medium</strong>)</td>'
.'</tr>'
.'<tr class="odd">'
.'<td>nolink</td>'
.'<td>' . KernelTools::tra( "key-words") . '<br />' . KernelTools::tra("(optional)") . '</td>'
.'<td>' . KernelTools::tra( "Remove hotlink from element. Used to display fixed copies of an image item.") . '</td>'
.'</tr>'
.'</table>'
. KernelTools::tra( "Example: ") . "{image id='13' size='small'}";
return $help;
}
|