« Back to zenphoto.org

ZenphotoPlugins: xp_publish.php

File xp_publish.php, 13.9 kB (added by trisweb, 1 year ago)

Windows XP Publishing Wizard, newest version

Line 
1 <?php
2
3 /**
4   * XP Publishing wizard for ZenPhoto 0.3
5   * Copyright (C) 2006 Niels Leenheer
6   *
7   * Inspired by the XP Publishing wizard from
8   * Gallery and Coppermine
9   * - Copyright (C) 2003-2006 Coppermine Dev Team
10   * - Copyright Gregory Demar
11   *
12   * This program is free software; you can redistribute it and/or
13   * modify it under the terms of the GNU General Public License
14   * as published by the Free Software Foundation; either version 2
15   * of the License, or (at your option) any later version.
16   *
17   */
18  
19  
20 require_once("zen/template-functions.php");
21
22 $cmd = empty($_GET['cmd']) ? '' : $_GET['cmd'];
23 $xp = new xpPublish();
24
25 if ($cmd == 'publish') {
26     $xp->logout();
27     $xp->handleCmd('login');
28     exit;
29 }
30
31 $xp->authorize();
32
33 if (!zp_loggedin() && $cmd && $cmd != 'regedit') $cmd = 'login';
34 if (isset($_POST['user'])) $cmd = 'process_login';
35
36 $xp->handleCmd($cmd);
37
38
39
40
41 class xpPublish {
42
43     /* Wizard buttons */
44     var $buttonsEnableBack = false;
45     var $buttonsEnableNext = false;
46     var $buttonsLastServerSidePage = false;
47
48     /* Default actions */
49     var $onBack = 'window.external.FinalBack();';
50     var $onNext = 'window.external.FinalNext();';
51     var $onCancel = '';
52
53     function xpPublish() {
54     }
55     
56     function handleCmd($cmd) {
57         switch ($cmd) {
58             case 'regedit':
59                 $this->send_reg_file();
60                 break;
61             case 'login':
62                 $this->form_login();
63                 break;
64             case 'process_login':
65                 $this->process_login();
66                 break;
67             case 'album':
68                 $this->form_album();
69                 break;
70             case 'finish':
71                 $this->form_finish();
72                 break;
73             case 'upload':
74                 $this->form_upload();
75                 break;
76             default:
77                 $this->explaination();
78                 break;
79         }
80     }
81     
82     function explaination() {
83 ?>
84 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
85 <html>
86 <head>
87     <title>zenphoto xp publishing wizard</title>
88     <link rel="stylesheet" href="zen/admin.css" type="text/css" />
89     <script type="text/javascript" src="zen/admin.js"></script>
90 </head>
91 <body>   
92 <p><img src="zen/images/zen-logo.gif" title="Zen Photo" /></p>
93   <div id="loginform">
94     <p><strong>To use the XP Publishing Wizard you first need to register it with Windows.</strong></p>
95     <p>Download the file below and open it.<br />This will add the ZenPhoto XP Publishing Wizard to your copy of Windows XP.</p>
96     <p><a href='<?php echo basename(__FILE__); ?>?cmd=regedit'>Download zenphoto.reg</a></p>
97   </div>     
98 </body>
99 </html>
100 <?php
101     }
102     
103     function show_debug($cmd = '') {
104         $this->header();
105
106         echo "<p>Command: " . $cmd . "</p>";
107         echo "<p>Logged in: " . zp_loggedin() . "</p>";
108
109         $this->buttonsLastServerSidePage = true;
110         $this->footer();
111     }
112     
113     function form_upload() {
114         if ($_FILES['userpicture']['tmp_name'] != '' &&
115             $_FILES['userpicture']['tmp_name'] == 0) {
116             
117             $folder = strip($_GET['folder']);
118             $uploaddir = SERVERPATH . '/albums/' . $folder;
119             $tmp_name = $_FILES['userpicture']['tmp_name'];
120             $name = $_FILES['userpicture']['name'];
121
122             if (is_image($name)) {
123                 $uploadfile = $uploaddir . '/' . $name;
124                 move_uploaded_file($tmp_name, $uploadfile);
125                 @chmod($uploadfile, 0777);
126             }
127         }
128     }
129     
130     function form_finish() {
131         if ($_POST['albumselect'] == '' && empty($_POST['folder']))
132             return $this->form_publish('Please enter the name of the new album');
133         
134         if ($_POST['albumselect'] == '' && $_POST['folder'] != '') {
135             $folder = strip($_POST['folder']);
136       $uploaddir = SERVERPATH . '/albums/' . $folder;
137         
138             if (!is_dir($uploaddir)) {
139         mkdir ($uploaddir, 0777);
140       }
141             
142             @chmod($uploaddir,0777);
143
144             $gallery = new Gallery();
145       $album = new Album($gallery, $folder);
146       $title = strip($_POST['albumtitle']);
147
148       if (!empty($title)) {
149         $album->setTitle($title);
150       }
151         } else {
152             $folder = strip($_POST['albumselect']);
153         }
154         
155         $this->header();
156
157         echo '<h2>Just a moment...</h2>';
158
159         $this->buttonsEnableBack = true;
160         $this->buttonsEnableNext = true;
161         $this->buttonsLastServerSidePage = true;
162         $this->footer('startUpload("' . utf8::encode_javascript($folder) . '"); ');
163     }
164     
165     function form_album($message = '') {
166         $gallery = new Gallery();
167
168         $this->header();
169
170         echo '<script language="javascript" type="text/javascript">';
171         echo "\n\n";
172     echo 'var albumArray = new Array ( ';
173
174     $first = true;
175     $albums = $gallery->getAlbums();
176     foreach ($albums as $folder) {
177       echo ($first ? "" : ", ") . "'" . addslashes($folder) . "'";
178         $first = false;
179     }
180         
181         echo ');';
182         echo "\n\n";
183         echo '</script>';
184
185
186         echo '<h2>Select the album you want to use</h2>';
187         if ($message != '') echo "<p>" . htmlspecialchars($message) . "</p>";
188     
189         echo '<form method="post" id="select" action="' . FULLWEBPATH . '/' . basename(__FILE__) . '?cmd=finish">';
190         echo '<input type="hidden" name="folder" value="" />';
191
192         echo '<div id="albumselect">';
193         echo '<select id="" name="albumselect" onChange="albumSwitch(this)">';
194         echo '<option value="" selected="true">A new album...</option>';
195         
196         $albums = $gallery->getAlbums();
197         foreach ($albums as $folder) {
198       $album = new Album($gallery, $folder);
199             echo '<option value="' . $folder . '">'. $album->getTitle() . '</option>';
200         }
201         
202         echo '</select>';
203         echo '<fieldset id="albumtext"><legend>Create a new album</legend><div>';
204         echo '<label>Title:';
205         echo '<input id="albumtitle" size="22" type="text" name="albumtitle" value="" onKeyUp="updateFolder(this, \'folderdisplay\', \'autogen\');" />';
206         echo '</label>';
207         echo '<label>Folder:';
208         echo '<input id="folderdisplay" size="18" type="text" name="folderdisplay" disabled="true" onKeyUp="validateFolder(this);"/>';
209         echo '<label>';
210         echo '<input type="checkbox" name="autogenfolder" id="autogen" checked="true" onClick="toggleAutogen(\'folderdisplay\', \'albumtitle\', this);" />';
211         echo 'Auto-generate';
212         echo '</label>';
213         echo '</label>';
214         echo '<div id="foldererror" style="display: none;">That name is already in use</div>';
215         echo '</div></fieldset></div>';
216         echo '</form>';
217
218         $this->buttonsEnableBack = true;
219         $this->buttonsEnableNext = true;
220         $this->onNext = 'select.folder.value = select.folderdisplay.value; select.submit();';
221         $this->footer();
222     }
223     
224     function form_login($message = '') {
225         $this->header();
226
227         echo '<h2>Enter your username and password</h2>';
228         if ($message != '') echo "<p>" . htmlspecialchars($message) . "</p>";
229         
230         echo '<form method="post" id="login" action="' . FULLWEBPATH . '/' . basename(__FILE__) . '?cmd=album">';
231         echo '<label>Username:';
232         echo '<input type="text" id="user" name="user" value="" maxlength="25" />';
233         echo '</label>';
234         echo '<label>Password:';
235         echo '<input type="password" id="pass" name="pass" value="" maxlength="25" />';
236         echo '</label>';
237         echo '</form>';
238         
239         $this->buttonsEnableBack = true;
240         $this->buttonsEnableNext = true;
241         $this->onNext = 'login.submit();';
242         $this->footer();
243     }
244     
245     function process_login() {
246         global $_zp_loggedin;
247         
248         if (isset($_POST['user']) && isset($_POST['pass'])) {
249             $user = $_POST['user'];
250             $pass = $_POST['pass'];
251
252             if ($user == zp_conf("adminuser") && $pass == zp_conf("adminpass")) {
253                 setcookie("zenphoto_wizard", md5($user.$pass));
254                 $_zp_loggedin = true;
255             } else {
256                 setcookie("zenphoto_wizard", "");
257             }
258         }       
259         
260         if ($_zp_loggedin) {
261             $this->form_album();
262         } else {
263             $this->form_login('The username or password you entered are not correct');
264         }
265     }
266     
267     function logout() {
268         setcookie("zenphoto_wizard", "");
269     }
270     
271     function authorize() {
272         global $_zp_loggedin;
273
274         if (isset($_COOKIE['zenphoto_wizard'])) {
275               $saved_auth = $_COOKIE['zenphoto_wizard'];
276               $check_auth = md5(zp_conf("adminuser").zp_conf("adminpass"));
277               if ($saved_auth == $check_auth) {
278                 $_zp_loggedin = true;
279               } else {
280                 setcookie("zenphoto_wizard", "");
281               }
282         }
283     }
284     
285     function header() {
286         echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">';
287         echo '<html dir="ltr">';
288         echo '<head>';
289         echo '<title>' . htmlspecialchars(zp_conf('gallery_title')) . '</title>';
290         echo '<meta http-equiv="Content-Type" content="text/html; charset=' . zp_conf('charset') . '" />';
291         echo '<style type="text/css">';
292 ?>
293
294     body {
295         background: threedface url(<?php echo FULLWEBPATH; ?>/zen/images/zen-logo.gif) right bottom no-repeat;
296     }
297    
298     body, td, select, input {
299         font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif;
300         font-size: 8pt;
301     }
302    
303     h2 {
304         font-size: 9pt;
305     }
306    
307     fieldset {
308         padding: 12pt 12pt 0;
309     }
310    
311     fieldset div {
312         padding: 12pt 0 0;
313     }
314    
315     label {
316         display: block;
317         position: relative;
318         height: 24pt;       
319     }
320     label input#user,
321     label input#pass,
322     label input#albumtitle,
323     label input#folderdisplay {
324         position: absolute;
325         left: 15%;
326         width: 60%;
327         top: -4pt;
328         padding: 2pt;
329         height: 17pt;
330     }
331     label input#folderdisplay {
332         width: 30%;
333     }
334    
335     label label {
336         position: absolute;
337         width: 30%;
338         left: 47%;
339         top: -2pt;
340         display: inline;
341     }
342     label label input {
343         margin: 0 2pt 0 0;
344     }
345     #foldererror {
346         font-weight: bold;
347         color: red;
348         margin: -4pt 0 0 0;
349         padding: 0 0 12pt 15%;
350     }
351
352 <?php       
353         echo '</style>';
354         echo '</head>';
355         echo '<body>';
356     }
357     
358     function footer($javascript = '') {
359         echo '<div id="content"></div>';
360         echo '<script language="javascript" type="text/javascript">';
361
362         ?>
363
364     function contains(arr, key) {
365         for (i=0; i<arr.length; i++) {
366             if (arr[i].toLowerCase() == key.toLowerCase()) {
367                 return true;
368             }
369         }
370         return false;
371     }
372
373     function albumSwitch(sel) {
374         var selected = sel.options[sel.selectedIndex];
375         var albumtext = document.getElementById("albumtext");
376         var albumbox = document.getElementById("folderdisplay");
377         var titlebox = document.getElementById("albumtitle");
378         var checkbox = document.getElementById("autogen");
379        
380         if (selected.value == "") {
381             albumtext.style.display = "block";
382             albumbox.value = "";
383             titlebox.value = "";
384             document.getElementById("foldererror").style.display = "none";
385             checkbox.checked = true;
386             toggleAutogen("folderdisplay", "albumtitle", checkbox);
387         } else {
388             albumtext.style.display = "none";
389             albumbox.value = selected.value;
390             titlebox.value = selected.text;
391         }
392     }
393
394     function updateFolder(nameObj, folderID, checkboxID) {
395         var autogen = document.getElementById(checkboxID).checked;
396         var folder = document.getElementById(folderID);
397         var name = nameObj.value;
398         var fname = "";
399         var fnamesuffix = "";
400         var count = 1;
401         if (autogen && name != "") {
402             fname = name;
403             fname = fname.toLowerCase();
404             fname = fname.replace(/[\!@#$\%\^&*()\~`\'\"]/gi, "");
405             fname = fname.replace(/[^a-zA-Z0-9]/gi, "-");
406             fname = fname.replace(/--*/gi, "-");
407             while (contains(albumArray, fname+fnamesuffix)) {
408                 fnamesuffix = "-"+count;
409                 count++;
410             }
411         }
412         folder.value = fname+fnamesuffix;
413     }
414
415     function validateFolder(folderObj) {
416         var errorDiv = document.getElementById("foldererror");
417         if (albumArray && contains(albumArray, folderObj.value)) {
418             errorDiv.style.display = "block";
419         } else {
420             errorDiv.style.display = "none";
421         }
422     }
423
424     function toggleAutogen(fieldID, nameID, checkbox) {
425         var field = document.getElementById(fieldID);
426         var name = document.getElementById(nameID);
427         if (checkbox.checked) {
428             window.folderbackup = field.value;
429             field.disabled = true;
430             updateFolder(name, fieldID, checkbox.id);
431         } else {
432             if (window.folderbackup && window.folderbackup != "")
433                 field.value = window.folderbackup;
434             field.disabled = false;
435         }
436     }
437
438
439        
440     function startUpload(folder) {
441         var xml = window.external.Property('TransferManifest');
442         var files = xml.selectNodes('transfermanifest/filelist/file');
443
444         for (i = 0; i < files.length; i++) {
445             var postTag = xml.createNode(1, 'post', '');
446             postTag.setAttribute('href', '<?php echo FULLWEBPATH . '/' . basename(__FILE__) . '?cmd=upload'; ?>&folder=' + folder);
447             postTag.setAttribute('name', 'userpicture');
448
449             var dataTag = xml.createNode(1, 'formdata', '');
450             dataTag.setAttribute('name', 'MAX_FILE_SIZE');
451             dataTag.text = '10000000';
452             postTag.appendChild(dataTag);
453
454             files.item(i).appendChild(postTag);
455         }
456
457         var uploadTag = xml.createNode(1, 'uploadinfo', '');
458         uploadTag.setAttribute('friendlyname', '<?php echo utf8::encode_javascript(zp_conf('gallery_title')); ?>');
459         var htmluiTag = xml.createNode(1, 'htmlui', '');
460         htmluiTag.text = '<?php echo utf8::encode_javascript(FULLWEBPATH); ?>';
461         uploadTag.appendChild(htmluiTag);
462
463         xml.documentElement.appendChild(uploadTag);
464
465         window.external.Property('TransferManifest')=xml;
466         window.external.SetWizardButtons(true,true,true);
467         content.innerHtml=xml;
468         window.external.FinalNext();
469     }
470
471     function OnBack() {
472         <?php echo $this->onBack; ?>
473     }
474
475     function OnNext() {
476         <?php echo $this->onNext; ?>
477     }
478
479     function OnCancel() {
480         <?php echo $this->onCancel; ?>
481     }
482
483     function window.onload() {
484         window.external.SetHeaderText('<?php echo utf8::encode_javascript(zp_conf('gallery_title')); ?>','<?php echo utf8::encode_javascript(FULLWEBPATH); ?>');
485         window.external.SetWizardButtons(<?php echo $this->buttonsEnableBack ? 'true' : 'false'; ?>,<?php echo $this->buttonsEnableNext ? 'true' : 'false'; ?>,<?php echo $this->buttonsLastServerSidePage ? 'true' : 'false'; ?>);
486     }
487    
488     <?php echo $javascript; ?>
489    
490         <?php
491         
492         echo '</script></body></html>';
493     }
494     
495     function send_reg_file() {
496
497         $time_stamp = time();
498
499         header("Content-Type: application/octet-stream");
500         header("Content-Disposition: attachment; filename=zenphoto_".$time_stamp.".reg");
501
502         $lines[] = 'Windows Registry Editor Version 5.00';
503         $lines[] = '[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\PublishingWizard\PublishingWizard\Providers\\'. zp_conf('gallery_title') .']';
504         $lines[] = '"displayname"="' . zp_conf('gallery_title') . '"';
505         $lines[] = '"description"="' . FULLWEBPATH . '"';
506         $lines[] = '"href"="' . FULLWEBPATH . '/' . basename(__FILE__) . '?cmd=publish"';
507         $lines[] = '"icon"="' . "http://" . $_SERVER['HTTP_HOST'] . '/favicon.ico"';
508         
509         print join("\r\n", $lines);
510         print "\r\n";
511         exit;   
512     }
513 }
514
515
516 ?>