-
Notifications
You must be signed in to change notification settings - Fork 39
/
hel_image.php
277 lines (247 loc) · 7.96 KB
/
hel_image.php
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<?php
/**
* @package loki_1
* @subpackage hel
*/
/**
* Include reason libraries
*/
include_once( 'reason_header.php' );
header('Content-Type: application/vnd.mozilla.xul+xml');
echo <<<FINIS
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
FINIS;
?>
<!DOCTYPE window [
<?php include_once("hel_entities.ent"); ?>
]>
<window
id="xul_window"
title="Insert Image or Link to Image"
asdfdebug="true"
asdforient="horizontal"
xmlns:hel="http://www.carleton.edu/hel"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload="do_onload()">
<groupbox orient="vertical" flex="1">
<caption label="Link URI"/>
<tabbox id="link_tabs">
<tabs>
<tab label="Insert Image"/>
<tab label="Insert Link to Images"/>
</tabs>
<tabpanels>
<tabpanel id="images_button_tab" orient="vertical">
<groupbox orient="vertical">
<caption label="Click on an image to insert it"/>
<vbox style="overflow: scroll; height: 250px;" id="image_buttons_container">
<?php
$site_id = isset( $_REQUEST[ 'site_id' ] ) ? $_REQUEST[ 'site_id' ] : 0;
settype($site_id, 'integer');
print_image_buttons($site_id);
?>
</vbox>
</groupbox>
<hbox>
<button id="cancel-button" label='Cancel' oncommand="do_oncancel()" />
</hbox>
</tabpanel>
<tabpanel id="images_link_tab" orient="vertical">
<groupbox orient="vertical">
<caption label="Select an image to link to"/>
<menulist id="image_links" flex="0">
<menupopup>
<?php
$site_id = isset( $_REQUEST[ 'site_id' ] ) ? $_REQUEST[ 'site_id' ] : 0;
settype($site_id, 'integer');
print_image_links($site_id);
?>
</menupopup>
</menulist>
</groupbox>
<groupbox orient="vertical">
<caption label="Link Information"/>
<checkbox id="new_window" label="Open in new browser window"/>
<hbox>
<label control="title" value="Link title:"/>
<textbox id="title" flex="1" style="min-width: 15em;"/>
</hbox>
</groupbox>
<hbox>
<spacer flex="1"/>
<button id="submit_button" label="OK" default="true" oncommand="do_onsubmit(this);"/>
<button id="cancel_button" label="Cancel" oncommand="do_oncancel();"/>
<spacer flex="1"/>
</hbox>
<groupbox orient="horizontal" style="border-left: 0px; border-right: 0px; border-bottom: 0px;">
<spacer flex="1"/>
<button id="unlink_button" label="Remove Link" oncommand="do_unlink();"/>
<spacer flex="1"/>
</groupbox>
<spacer flex="10"/>
</tabpanel>
</tabpanels>
</tabbox>
</groupbox>
<spacer flex="100" />
<script type="text/javascript">
<![CDATA[
try {
var editor_obj = opener.<?php echo htmlspecialchars($_REQUEST['editor_obj'],ENT_QUOTES,'UTF-8'); ?>;
} catch(e) {}
function do_onload()
{
document.getElementById('image_buttons_container').firstChild.focus();
try {
document.getElementById('title').value = editor_obj.temp_modal_args.link_title;
document.getElementById('new_window').checked = editor_obj.temp_modal_args.link_new_window;
var image_links = document.getElementById('image_links').firstChild.childNodes;
for (var i = 0; i < image_links.length; i++) {
if ( image_links.item(i).value == editor_obj.temp_modal_args.link_url ) {
document.getElementById('image_links').selectedIndex = i;
document.getElementById('link_tabs').selectedIndex = 1;
}
}
} catch(e) {}
}
function do_onsubmit(image_button)
{
if ( document.getElementById('link_tabs').selectedIndex == 0 )
{
editor_obj.insert_image( image_button.getAttribute('hel:src'),
image_button.getAttribute('hel:height'),
image_button.getAttribute('hel:width'),
image_button.getAttribute('hel:alt') );
}
else
{
var selected_url;
selected_url = document.getElementById('image_links').selectedItem.value;
selected_onclick = document.getElementById('image_links').selectedItem.getAttribute('hel:onclick');
editor_obj.insert_link( selected_url,
document.getElementById('new_window').checked,
document.getElementById('title').value,
selected_onclick );
}
window.close();
}
function do_oncancel()
{
window.close();
}
function do_unlink()
{
editor_obj.insert_link('', false, '', '');
window.close();
}
]]>
</script>
</window>
<?php
// Adapted from /usr/local/webapps/www-dev/admin/scripts/image_list.php , which is used by Loki
function print_image_buttons( $site_id )
{
if( $site_id != 0 )
{
reason_include_once( 'classes/entity_selector.php' );
$es = new entity_selector( $site_id );
$es->add_type( id_of( 'image' ) );
$es->set_order('entity.last_modified DESC');
$images = $es->run_one();
foreach ( $images as $image )
{
// get filenames for the thumbnail and full size
$tn_name = $image->id().'_tn.'.$image->get_value('image_type');
$image_name = $image->id().'.'.$image->get_value('image_type');
// sometimes images aren't in the filesystem. hence, the error supressing @
// this gets image size. [0] contains width, [1] contains height.
// OK, the error suppression does not work. Instead I am wrapping the getimagesize function in a file existence check
if(file_exists( PHOTOSTOCK.$tn_name ))
{
$tn_info = @getimagesize( PHOTOSTOCK.$tn_name );
}
else
{
$tn_info = false;
}
if(file_exists( PHOTOSTOCK.$image_name ))
{
$image_info = @getimagesize( PHOTOSTOCK.$image_name );
}
else
{
$image_info = false;
}
$button_string = <<<FINIS
<button onclick="do_onsubmit(this);" hel:src="%s" hel:width="%s" hel:height="%s" hel:alt="%s"
style="overflow: hidden; width: %spx" orient="vertical">
<image src="%s"/>
<description style="text-align:center;">
<html:span style="font-weight:bold">Alternate text:</html:span> %s
</description>
<description style="text-align:center">
<html:span style="font-weight:bold">Width:</html:span> %s
</description>
<description style="text-align:center">
<html:span style="font-weight:bold">Height:</html:span> %s
</description>
</button>
FINIS;
// I suppose there could be a thumbnail with no image. This code takes care of all possibilities
if( $tn_info )
{
printf( $button_string,
'https://'.$_SERVER["SERVER_NAME"].WEB_PHOTOSTOCK.$tn_name,
$tn_info[0],
$tn_info[1],
htmlspecialchars($image->get_value('description')),
$tn_info[0],
'https://'.$_SERVER["SERVER_NAME"].WEB_PHOTOSTOCK.$tn_name,
htmlspecialchars($image->get_value('description')),
$tn_info[0],
$tn_info[1] );
}
if ( $image_info )
{
printf( $button_string,
'https://'.$_SERVER["SERVER_NAME"].WEB_PHOTOSTOCK.$image_name,
$image_info[0],
$image_info[1],
htmlspecialchars($image->get_value('description')),
$image_info[0],
'https://'.$_SERVER["SERVER_NAME"].WEB_PHOTOSTOCK.$image_name,
htmlspecialchars($image->get_value('description')),
$image_info[0],
$image_info[1] );
}
}
}
}
function print_image_links( $site_id )
{
if( $site_id != 0 )
{
reason_include_once( 'classes/entity_selector.php' );
$es = new entity_selector( $site_id );
$es->add_type( id_of( 'image' ) );
$es->set_order('entity.last_modified DESC');
$images = $es->run_one();
$site = new entity( $site_id );
foreach( $images AS $image )
{
$url = WEB_PHOTOSTOCK . $image->id() . '.' . $image->get_value('image_type');
$name = htmlspecialchars($image->get_value('name'));
$size = $image->get_value('size');
if ( !empty($size) )
$name .= ' (' . $size . 'kb)';
$window_width = $image->get_value('width') < 340 ? 340 : 40 + $image->get_value('width');
$window_height = 170 + $image->get_value('height');
$onclick_url = WEB_PHOTOSTOCK . "image.php3?id=" . $image->id();
$onclick = "window.open('" . $onclick_url . "', 'PopupImage', 'menubar,scrollbars,resizable,width=" . $window_width . ",height=" . $window_height . "'); return false;";
echo '<menuitem value="'.$url.'" label="'.$name.'" hel:onclick="'.$onclick.'"/>'."\n";
}
}
}
?>