/[drupal]/contributions/modules/image_pub/image_pub.xp.inc
ViewVC logotype

Contents of /contributions/modules/image_pub/image_pub.xp.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Sat Jan 31 17:51:40 2009 UTC (9 months, 3 weeks ago) by egfrith
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +472 -0 lines
File MIME type: text/x-php
Making sure that .inc files are out of the attic
1 <?php
2 // $Id: image_pub.xp.inc,v 1.1.2.1 2009/01/31 02:00:25 egfrith Exp $
3
4 /*
5 * Windows Web publishing wizard support
6 *
7 * Below is support for the Windows XP Web publishing wizard. It's just a
8 * glorified file picker and MSIE instance in a wizard form factor, but
9 * it gets the job done, and did we mention it comes with every copy of
10 * Windows?
11 *
12 * Microsoft even appears to have some sort of documentation for the
13 * publishing wizard on the MSDN site, although debugging is a major
14 * pain:
15 *
16 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/programmersguide/shell_basics/shell_basics_extending/publishing_wizard/pubwiz.asp
17 *
18 * Our part of the wizard has three steps:
19 * 1. Authenticate.
20 * 2. Select or create album.
21 * 3. Publish. We send a blank page with a magic script to configure
22 * the wizard.
23 *
24 * We send bare HTML and don't use themes. Why not themes?
25 * -> The XP publishing wizard has a microscopic embedded MSIE instance
26 * that we don't want to overflow with content. That is hard to
27 * guarantee using an arbitrary theme.
28 * -> Themes will display distracting links in headers and sidebars. We
29 * don't want the user navigating to one of the distractions.
30 */
31
32 require_once 'image_pub.common.inc';
33
34 /*
35 * Concoct a magic registry file to add this site to the list of
36 * usable destinations for the publishing wizard.
37 */
38 function _image_pub_xp_reghack() {
39 $pub_url = url('publish_xp', array('absolute' => TRUE));
40 $site_name = variable_get('site_name', 'drupal');
41 $site_descr = sprintf(t("Publish Your Photos to %s."), $site_name);
42 if (!strncmp($pub_url, 'https:', 6)) {
43 $site_descr .= ' (Secure)';
44 }
45 else {
46 $site_descr .= ' (Insecure)';
47 }
48 drupal_set_header("Cache-control: private");
49 drupal_set_header("Content-Type: application/octet-stream");
50 drupal_set_header("Content-Disposition: filename=install_registry.reg");
51
52 $lines[] = 'Windows Registry Editor Version 5.00';
53 $lines[] = '';
54 $lines[] = '[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\PublishingWizard\PublishingWizard\Providers\\' . $site_name . ']';
55 $lines[] = '"displayname"="' . $site_name . '"';
56 $lines[] = '"description"="' . $site_descr . '"';
57 $lines[] = '"href"="' . $pub_url . '"';
58 $lines[] = '"icon"="' . _image_pub_base_url() . '/favicon.ico"';
59 $lines[] = '';
60 echo join("\r\n", $lines);
61 exit;
62 }
63
64
65 /*
66 * Implementation of wizard forms and such:
67 * _image_pub_xp_request() (main entry point)
68 * _image_pub_xp_login()
69 * _image_pub_xp_album()
70 * _image_pub_xp_addimage()
71 * _image_pub_xp_page() (HTML form template)
72 * _image_pub_xp_login_form()
73 * _image_pub_xp_album_form()
74 * _image_pub_xp_addimage_script()
75 */
76
77 function _image_pub_xp_request() {
78
79 /*
80 * We require the user to be logged in to publish.
81 * We honor cookies saved from other MSIE sessions, and don't
82 * require the user to log in if they already have a session.
83 */
84
85 global $user;
86 $cmd = $_REQUEST['cmd'];
87 if (!$user->uid) {
88 if (!isset($cmd)) {
89 $cmd = 'login';
90 }
91 }
92
93 switch ($cmd) {
94 case 'login':
95 _image_pub_xp_login($_REQUEST['uname'], $_REQUEST['password']);
96 break;
97 case 'addimage':
98 _image_pub_xp_addimage($_REQUEST['albumid']);
99 default:
100 _image_pub_xp_album($_REQUEST['edit']);
101 break;
102 }
103 }
104
105
106 function _image_pub_xp_login($uname, $pass) {
107 if (empty($uname) && empty($pass)) {
108 _image_pub_xp_login_form();
109 }
110 elseif (!_image_pub_authenticate($uname, $pass)) {
111 drupal_set_message('Login failed. Please try again.', 'error');
112 _image_pub_xp_login_form("Invalid Login", $uname);
113 }
114 else {
115 _image_pub_xp_album_form();
116 }
117 }
118
119
120 function _image_pub_xp_album($edit) {
121 if (!isset($edit)) {
122 _image_pub_xp_album_form();
123 return;
124 }
125
126 $create_new = $edit['create_new'];
127
128 if ($create_new) {
129 $albumid = $edit['create_parentid'];
130 $create_name = $edit['create_name'];
131 $create_descr = $edit['create_descr'];
132
133 $album = _image_pub_album_get($albumid);
134 if (!_image_pub_album_access('update', $album)) {
135 drupal_set_message('Created album permission denied.', 'error');
136 _image_pub_xp_album_form('Create Album Permission Denied', $album);
137 }
138
139 $newalbum = _image_pub_album_add($create_name, $create_descr, $album);
140
141 if (isset($newalbum)) {
142 drupal_set_message('New album '.'<em>'.$newalbum->name.'</em>'.' created.');
143 _image_pub_xp_album_form('Created Album "'.$newalbum->name.'"', $newalbum);
144 }
145 else {
146 drupal_set_message('Error creating album '.'<em>'.$newalbum->name.'</em>.', 'error');
147 _image_pub_xp_album_form('Error Creating Album', $album);
148 }
149 return;
150 }
151
152 // if we got here we are choosing an existing album
153 $albumid = $edit['albumid'];
154 $album = _image_pub_album_get($albumid);
155
156 if (!isset($album)) {
157 drupal_set_mssage('Invalid album specified.', 'error');
158 _image_pub_xp_album_form('Invalid album specified');
159 return;
160 }
161 if (!_image_pub_album_access('create', $album)) {
162 drupal_set_message('Create image permission denied.', 'error');
163 _image_pub_xp_album_form('Create Image Permission Denied', $album);
164 return;
165 }
166 _image_pub_xp_addimage_script($album);
167 }
168
169
170 function _image_pub_xp_addimage($albumid) {
171 $album = _image_pub_album_get($albumid);
172 if (!isset($album)) {
173 _image_pub_xp_album_form('Invalid album specified');
174 return;
175 }
176 if (!_image_pub_album_access('update', $album)) {
177 _image_pub_xp_album_form('Create Image Permission Denied', $album);
178 return;
179 }
180
181 $result = _image_pub_image_add($album, NULL, NULL, 'userfile');
182 }
183
184
185 function _image_pub_xp_page($body, $header, $next, $back = NULL) {
186 global $language;
187 $site_name = variable_get('site_name', 'drupal');
188 ?>
189 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
190 <html xmlns="http://www.w3.org/1999/xhtml" lang="<?php print $language->language; ?>" xml:lang="<?php print $language->language; ?>">
191 <head>
192 </head>
193 <body>
194 <?php echo $body; ?>
195 <script>
196 function OnBack() {
197 <?php if (isset($back)) { ?>
198 window.location.href = "<?php echo $back; ?>";
199 <?php }
200 else { ?>
201 window.external.FinalBack();
202 <?php } ?>
203 window.external.SetWizardButtons(true,true,false);
204 }
205 function OnNext() {
206 <?php echo $next; ?>.submit();
207 }
208 function window.onload() {
209 window.external.SetHeaderText("<?php echo $site_name; ?>", "<?php echo $header; ?>");
210 window.external.SetWizardButtons(true,true,false);
211 }
212 </script>
213 </body>
214 </html>
215 <?php
216 exit;
217 }
218
219
220 function _image_pub_xp_login_form($message = NULL, $uname = NULL) {
221
222 if (!isset($uname)) {
223 $uname = '';
224 }
225
226 // Build a form array
227 $form = array();
228
229 $form['login'] = array(
230 '#type' => 'fieldset',
231 '#tree' => FALSE,
232 );
233
234 $form['login']['uname'] = array(
235 '#type' => 'textfield',
236 '#title' => t('User name'),
237 '#default_value' => check_plain($uname),
238 '#description' => t('Enter your user name.'),
239 );
240
241 $form['login']['password'] = array(
242 '#type' => 'password',
243 '#title' => t('Password'),
244 '#description' => t('Enter your password.'),
245 );
246
247 $form['cmd'] = array(
248 '#type' => 'hidden',
249 '#value' => 'login',
250 );
251
252 $form['lcid'] = array(
253 '#type' => 'hidden',
254 '#value' => check_plain($_REQUEST['lcid']),
255 );
256
257 $form['langid'] = array(
258 '#type' => 'hidden',
259 '#value' => check_plain($_REQUEST['langid']),
260 );
261
262 $form[session_name()] = array(
263 '#type' => 'hidden',
264 '#value' => check_plain(session_id()),
265 );
266
267 // Build the HTML output
268 $body = array();
269
270 // Title
271 $body[] = '<h1>Log in</h1>';
272
273 // Display error message if one is active
274 $body[] = theme('status_messages');
275
276 // Render the form elements to themed HTML
277 $body[] = '<form method="post" id="login">';
278 $body[] = drupal_render(form_builder('login', $form));
279 $body[] = '</form>';
280 $body[] = '';
281
282 // Output the wizard page
283 _image_pub_xp_page(implode("\r\n", $body), 'Upload photos...', 'login');
284
285 }
286
287
288 function _image_pub_xp_album_form($message = NULL, $select_album = NULL) {
289
290 /**
291 * This form is currently not very elegant in how it is build
292 * as it has to over-ride #parents to be compatible with the rest
293 * of the existing code. Field sets are used to present the data
294 * in logical blocks. It may be better in the longer term to make an
295 * additional form page - decide it you want an existing or a new album
296 * and then take the user there, rather than doing it all in one.
297 * Leave as is for now just to check the concept is working
298 */
299
300 // Build a form array
301 $form = array();
302 $form_state = array();
303
304 // create a fieldset to wrap the form in
305 // note #parents must be forced for this set to work with original code
306 $form['existing'] = array(
307 '#type' => 'fieldset',
308 '#tree' => FALSE,
309 );
310
311 // radio button for existing album
312 $form['existing']['create_new'] = array(
313 '#type' => 'radio',
314 '#return_value' => 0,
315 '#title' => t('Use an existing album'),
316 '#attributes' => array('checked' => 'checked'),
317 '#parents' => array('edit', 'create_new'),
318 );
319
320 // for some reason if a new album it doesn't always end up in the select list
321 // I tried using cache_clear_all but that doesn't help
322 // Leave as a bug for now
323
324 // generate the selector by calling _taxonomy_term_select
325 $form['existing']['albumid'] = _taxonomy_term_select('', '', $select_album->tid, _image_pub_get_vid(), '', FALSE, FALSE);
326 $form['existing']['albumid']['#parents'] = array('edit', 'albumid');
327
328 // reset weighting, and delete title from selector
329 unset($form['existing']['albumid']['#weight']);
330 unset($form['existing']['albumid']['#title']);
331 unset($form['existing']['albumid']['#description']);
332
333 // create a container for new album fields
334 // call it edit to avoid having to force #parents
335 $form['edit'] = array(
336 '#type' => 'fieldset',
337 '#tree' => TRUE,
338 );
339
340 // radio button for new album
341 $form['edit']['create_new'] = array(
342 '#type' => 'radio',
343 '#return_value' => 1,
344 '#title' => t('Create a new album'),
345 );
346
347 // get the parent selector by calling _image_gallery_parent_select
348 $form['edit']['create_parentid'] = _image_gallery_parent_select(NULL, 'Within');
349
350 // reset #required option in this instance
351 unset($form['edit']['create_parentid']['#required']);
352
353 $form['edit']['create_name'] = array(
354 '#type' => 'textfield',
355 '#title' => t('Album name'),
356 );
357
358 $form['edit']['create_descr'] = array(
359 '#type' => 'textfield',
360 '#title' => t('Album description'),
361 );
362
363 // Common section - render to all forms
364 $form['cmd'] = array(
365 '#type' => 'hidden',
366 '#value' => 'album',
367 );
368
369 $form['lcid'] = array(
370 '#type' => 'hidden',
371 '#value' => check_plain($_REQUEST['lcid']),
372 );
373
374 $form['langid'] = array(
375 '#type' => 'hidden',
376 '#value' => check_plain($_REQUEST['langid']),
377 );
378
379 $form[session_name()] = array(
380 '#type' => 'hidden',
381 '#value' => check_plain(session_id()),
382 );
383
384 // Build the HTML output
385 $body = array();
386
387 // Title
388 $body[] = '<h2>Select an album</h2>';
389
390 // Display error message if one is active
391 $body[] = theme('status_messages');
392
393 // Render the form elements to themed HTML
394 $body[] = '<form method="post" id="album">';
395 $body[] = drupal_render(form_builder('album', $form, $form_state));
396 $body[] = '</form>';
397 $body[] = '';
398
399 _image_pub_xp_page(implode("\r\n", $body), 'Upload photos...', 'album');
400 }
401
402
403 /*
404 * Concoct a magic ecmascript to configure the XP publishing wizard
405 * to perform the required image submission tasks.
406 */
407 function _image_pub_xp_addimage_script($album) {
408 $albumid = $album->tid;
409 ?>
410 <html>
411 <head>
412 <script>
413 function OnBack() {
414 }
415 function OnNext() {
416 }
417 function window.onload() {
418 window.external.SetWizardButtons(true,true,true);
419 }
420
421 var xml = window.external.Property("TransferManifest");
422 var files = xml.selectNodes("transfermanifest/filelist/file");
423
424 for (i = 0; i < files.length; i++) {
425 var postTag = xml.createNode(1, "post", "");
426 postTag.setAttribute("href", "<?php echo url('publish_xp', array('absolute' => TRUE)); ?>");
427 postTag.setAttribute("name", "userfile");
428
429 var dataTag = xml.createNode(1, "formdata", "");
430 dataTag.setAttribute("name", "albumid");
431 dataTag.text = "<?php echo $albumid; ?>";
432 postTag.appendChild(dataTag);
433
434 dataTag = xml.createNode(1, "formdata", "");
435 dataTag.setAttribute("name", "cmd");
436 dataTag.text = "addimage";
437 postTag.appendChild(dataTag);
438
439 dataTag = xml.createNode(1, "formdata", "");
440 dataTag.setAttribute("name", "<?php echo session_name(); ?>");
441 dataTag.text = "<?php echo session_id(); ?>";
442 postTag.appendChild(dataTag);
443
444 dataTag = xml.createNode(1, "formdata", "");
445 dataTag.setAttribute("name", "userfile_name");
446 dataTag.text = files[i].getAttribute("destination");
447 postTag.appendChild(dataTag);
448
449 dataTag.setAttribute("name", "action");
450 dataTag.text = "SAVE";
451 postTag.appendChild(dataTag);
452
453 files.item(i).appendChild(postTag);
454 }
455
456 var uploadTag = xml.createNode(1, "uploadinfo", "");
457 var htmluiTag = xml.createNode(1, "htmlui", "");
458 htmluiTag.text = "<?php echo url('image/tid/'.$albumid, array('absolute' => TRUE)); ?>";
459 uploadTag.appendChild(htmluiTag);
460
461 xml.documentElement.appendChild(uploadTag);
462
463 window.external.Property("TransferManifest")=xml;
464 window.external.SetWizardButtons(true,true,true);
465 window.external.FinalNext();
466
467 </script>
468 </head>
469 </html>
470 <?php
471 exit;
472 }

  ViewVC Help
Powered by ViewVC 1.1.2