« Back to zenphoto.org

ZenphotoPlugins: zenshow.php

File zenshow.php, 13.3 kB (added by aitf311, 10 months ago)

Zenshow 1.4.1 ready for Zenphoto 1.1+

Line 
1 <?php
2 /*
3 Plugin Name: ZenShow
4 Plugin URI: http://www.ruicruz.com/zenshow/
5 Description: Displays a thumbnail from ZenPhoto. Updated for ZenPhoto 1.1.2 by Thinkdreams, as well as bug fixes by Samuel Goldstein.
6 Version: 1.4.1
7 Author: Rui Cruz
8 Author URI: http://www.ruicruz.com
9 */
10
11
12 /**
13  * Wordpress plugin to handle insertion of Zenphoto Photos into wordpress blocks
14  *
15  * @author Rui Cruz, http://www.ruicruz.com
16  * @copyright Rui Cruz
17  * @version 1.4.1
18  */
19 class RMCZS {
20
21
22     /**
23      * ZenPhoto Database name (to support diferent a database from WordPress
24      *
25      * @var string
26      */
27     var $zen_db;
28     
29     /**
30      * Database username
31      *
32      * @var string
33      */
34     var $zen_user;
35     
36     /**
37      * Database Password
38      *
39      * @var string
40      */
41     var $zen_pw;
42     
43     /**
44      * ZenPhoto Host
45      *
46      * @var string
47      */
48     var $host;
49
50     /**
51      * Database Tables prefix (if any)
52      *
53      * @var string
54      */
55     var $zen_prefix = '';
56     
57     /**
58      * Height of the ZenPhoto thumbnail
59      *
60      * @var int
61      */   
62     var $zen_tb_height = 85;
63     
64     /**
65      * Width of the ZenPhoto thumbnail
66      *
67      * @var int
68      */
69     var $zen_tb_width = 85;
70     
71     
72     /**
73      * ZenPhoto URL
74      *
75      * @var string
76      */
77     var $zen_url;
78
79     
80 //////////////////////////////////////////
81 //
82 //        OBJECT METHODS
83 //
84 //////////////////////////////////////////
85
86     /**
87      * Constructor, adds the admin page and retrieves the configuration options
88      *
89      * @return RMCZS
90      */
91     function RMCZS() {
92
93         add_action('admin_menu', array(&$this,'ShowAdmin'));         
94         
95         $this->get_zenconf();
96         
97     }
98     
99         
100 //////////////////////////////////////////
101 //
102 //        METHODS TO DISPLAY THE PICTURES
103 //
104 //////////////////////////////////////////
105
106     /**
107      * Shows last photo (selected by bigger ID)
108      *
109      * @param string $date
110      */
111     function showPhoto($date = null) {
112                 
113         global $ZenDB, $RMCZS;
114
115         if ( $RMCZS->connect() ) {
116             
117             if ( !is_null($date) && (ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $date)) ) {
118                 
119                 $SQL_date = ' AND album.date < ' . $date;
120                 
121             } else {
122                 
123                 $SQL_date = null;
124                 
125             }
126
127             $SQL_query = 'SELECT images.filename AS filename, images.`desc` AS file_desc, album.folder AS folder, images.title AS title FROM ' . $RMCZS->zen_prefix . 'images AS images INNER JOIN ' . $RMCZS->zen_prefix . 'albums AS album ON album.id = images.albumid WHERE images.show = 1 ' . $SQL_date . ' ORDER BY images.id DESC LIMIT 1';
128     
129             if ($Photo = $ZenDB->get_row($SQL_query))
130             
131                 echo '<a href="' . $RMCZS->zen_url .'index.php?album='. $Photo->folder . '&amp;image=' . $Photo->filename . '" id="rpc_photo" title="' . $Photo->file_desc . '" />'
132                 . '<img height="' . $RMCZS->zen_tb_height . '" width="' . $RMCZS->zen_tb_width . '" src="' . $RMCZS->zen_url . 'zp-core/i.php?a='. $Photo->folder . '&i=' . $Photo->filename . '&s=thumb" alt="' . $Photo->title . '">'
133                 . '</a>';
134                     
135             $RMCZS->disconnect();   
136         
137         } else {
138             
139             trigger_error('Unable to display Photo');
140             
141         }
142     }
143
144     
145     /**
146      * Shows X Random photos
147      *
148      * @param int $num_photos
149      * @param string $date
150      */
151     function randomPhotos($num_photos = 4, $date = null) {
152                 
153         global $ZenDB, $RMCZS;
154
155         if ( $RMCZS->connect() ) {
156             
157             if ( !is_null($date) && (ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $date)) ) {
158                 
159                 $SQL_date = ' AND album.date < ' . $date;
160                 
161             } else {
162                 
163                 $SQL_date = null;
164                 
165             }           
166
167             $SQL_query = 'SELECT images.filename AS filename, images.`desc` AS file_desc, album.folder AS folder, images.title AS title FROM ' . $RMCZS->zen_prefix . 'images AS images INNER JOIN ' . $RMCZS->zen_prefix . 'albums AS album ON album.id = images.albumid WHERE images.show = 1 ' . $SQL_date . ' ORDER BY RAND() LIMIT ' . $num_photos;
168     
169             if ($Photos = $ZenDB->get_results($SQL_query))
170             
171                 foreach ($Photos as $Photo) {
172                 
173                     echo '<a href="' . $RMCZS->zen_url .'index.php?album='.
174                     $Photo->folder . '&amp;image=' . $Photo->filename .
175                     '" title="' . $Photo->title . '" class="rpc_photo">'
176                     . '<img class="random" src="' . $RMCZS->zen_url .
177                     'zp-core/i.php?a='. $Photo->folder . '&i=' .
178                     $Photo->filename . '&s='.$RMCZS->zen_tb_width.'&cw='.
179                     $RMCZS->zen_tb_width.'&ch='.$RMCZS->zen_tb_height.
180                     '" alt="' . $Photo->title . '" />'
181                     . '</a>';
182                 
183                 }           
184                     
185             $RMCZS->disconnect();   
186         
187         } else {
188             
189             trigger_error('Unable to display');
190             
191         }
192     }
193
194     
195     /**
196      * Shows X Random photos
197      *
198      * @param int $num_album
199      * @param int $num_photos
200      */
201     function showAlbum($num_album, $num_photos = 4) {
202                 
203         global $ZenDB, $RMCZS;
204
205         if ( $RMCZS->connect() ) {       
206
207             $SQL_query = 'SELECT images.filename AS filename, images.`desc` AS file_desc, album.folder AS folder, images.title AS title, album.title AS ab_title, album.place AS ab_place, album.date AS ab_date FROM ' . $RMCZS->zen_prefix . 'images AS images INNER JOIN ' . $RMCZS->zen_prefix . 'albums AS album ON album.id = images.albumid WHERE images.show = 1 AND album.id = ' . $num_album . ' ORDER BY RAND() LIMIT ' . $num_photos;
208     
209             if ($Photos = $ZenDB->get_results($SQL_query)) {
210                 
211                 echo '<div class="rmc_album">';           
212             
213                 foreach ($Photos as $Photo) {
214                 
215                     echo '<a href="' . $RMCZS->zen_url .'index.php?album='. $Photo->folder . '&amp;image=' . $Photo->filename . '" title="' . $Photo->title . '" class="rpc_photo">'
216                     . '<img height="' . $RMCZS->zen_tb_height . '" width="' . $RMCZS->zen_tb_width . '" src="' . $RMCZS->zen_url . 'zp-core/i.php?a='. $Photo->folder . '&i=' . $Photo->filename . '&s=thumb" alt="' . $Photo->title . '" />'
217                     . '</a>';
218                 
219                 }
220                 
221                 echo '<div class="title"><a href="' . $RMCZS->zen_url . 'index.php?album=' . $Photo->folder . '">' . $Photo->ab_title . '</a></div>'
222                 . '<div class="place">' . $Photo->ab_place . '</div>'
223                 . '<div class="date">' . $Photo->ab_date . '</div>';
224                 
225                 echo '</div>';
226                 
227             }
228                     
229             $RMCZS->disconnect();   
230         
231         } else {
232             
233             trigger_error('Unable to display');
234             
235         }
236     }
237     
238     
239 //////////////////////////////////////////
240 //
241 //        ADMINISTRATION METHODS
242 //
243 //////////////////////////////////////////
244
245
246     function AdminOptions() {   
247         
248         if (isset($_POST['info_update'])) {
249         
250             update_option("RMCZS_db", $_POST['txt_zendb']);
251             update_option("RMCZS_username", $_POST['txt_zenusername']);
252             update_option("RMCZS_password", $_POST['txt_zenpassword']);
253             update_option("RMCZS_host", $_POST['txt_zenhost']);
254             
255             update_option('RMCZS_tb_width', $_POST['txt_zen_tb_width']);
256             update_option('RMCZS_tb_height', $_POST['txt_zen_tb_height']);
257             
258             
259             update_option("RMCZS_prefix", $_POST['txt_zenprefix']);
260             update_option("RMCZS_url", $_POST['txt_zenurl']);
261             
262             echo '<div class="updated"><p><strong>';
263             _e('ZenShow options Updated.', 'Localization name');
264             echo '</strong></p></div>';
265
266         }
267         
268         $this->get_zenconf();
269
270         ?>
271         <div class="wrap">
272           <form method="post">
273             <h2>Zen Show</h2>
274            
275                 <div align="right"><?php $this->get_ZenUrl(); ?></div>
276                
277                  <fieldset name="database" title="Database configuration" class="options">
278              
279                      <legend>ZenPhoto Database Options</legend>
280                
281                    
282                     <table width="100%" border="0" align="center">
283                       <tr>
284                         <th width="200" align="right"><?php _e('Database', 'Localization name') ?></th>
285                         <td><input name="txt_zendb" type="text" value="<?php echo $this->zen_db; ?>" size="40" /></td>
286                       </tr>
287                       <tr>
288                         <th width="200" align="right"><?php _e('Username', 'Localization name') ?></th>
289                         <td><input name="txt_zenusername" type="text" value="<?php echo $this->zen_user; ?>" size="40" /></td>
290                       </tr>
291                       <tr>
292                         <th width="200" align="right"><?php _e('Password', 'Localization name') ?></th>
293                         <td><input name="txt_zenpassword" type="password" value="<?php echo $this->zen_pw; ?>" size="40" /></td>
294                       </tr>
295                       <tr>
296                         <th width="200" align="right"><?php _e('Host', 'Localization name') ?></th>
297                         <td><input name="txt_zenhost" type="text" value="<?php echo $this->zen_host; ?>" size="40" /></td>
298                       </tr>
299                       <tr>
300                         <th align="right"><?php _e('Tables Prefix', 'Localization name') ?></th>
301                         <td><input name="txt_zenprefix" type="text" value="<?php echo $this->zen_prefix; ?>" size="40" />
302                         Usually &quot;zp_&quot; </td>
303                       </tr>
304                     </table>
305                    
306                    
307                 </fieldset>
308                  <br />
309              
310                  <fieldset name="thumbnail" title="Thumbnail configuration" class="options">
311                  
312                      <legend>ZenPhoto Thumbnail Options</legend>                   
313                    
314                     <table width="100%" border="0" align="center">
315                       <tr>
316                         <th width="200" align="right"><?php _e('Height', 'Localization name') ?></th>
317                         <td><input name="txt_zen_tb_height" type="text" value="<?php echo $this->zen_tb_height; ?>" size="4" maxlenght="4" /></td>
318                         <td rowspan="2">Check ZenPhoto config.php and insert the values accordingly </td>
319                       </tr>
320                       <tr>
321                         <th width="200" align="right"><?php _e('Width', 'Localization name') ?></th>
322                         <td><input name="txt_zen_tb_width" type="text" value="<?php echo $this->zen_tb_width; ?>" size="4" maxlength="4" /></td>
323                       </tr>
324                     </table>
325                    
326                    
327                 </fieldset>
328                  <br />
329
330                      
331              <fieldset name="folder" title="Database configuration" class="options">
332                
333                <legend>Url Options</legend>
334                 <table width="100%" border="0" align="center">
335                   <tr>
336                     <th width="200" align="right"><?php _e('Zen Photo URL', 'Localization name') ?></th>
337                     <td><input name="txt_zenurl" type="text" value="<?php echo $this->zen_url; ?>" size="40" />
338                     <strong>Always</strong> use ending trailing slash ex: zenphoto/</td>
339                   </tr>
340                 </table>
341                 <br />
342              </fieldset>
343            
344             <div class="submit">
345                   <input type="submit" name="info_update" value="<?php _e('Update options', 'Localization name'); ?>" />
346             </div>
347           </form>
348           <p>There's (actually no longer) more information about configuring this plugin on <a href="http://www.ruicruz.com/zenshow/" target="_blank">http://www.ruicruz.com/zenshow/</a><br />
349             <a href="http://zenphoto.org/changelog.html" target="_blank">ZenPhoto.org changelog</a><br />Hacked to SeL standards by SjG</p>
350         </div>
351          <?php
352     
353     }
354
355
356     /**
357      * Adds the option page to WordPress administration,
358      * only users with level 9 can use
359      *
360      * @return void
361      */
362     function ShowAdmin() {
363         
364         if (function_exists('add_options_page')) {
365             
366             add_options_page('RMCZENSHOW', 'RMC:Zen Show', 9, __FILE__, array(&$this,'AdminOptions'));
367             
368         }
369         
370      }
371
372     
373 //////////////////////////////////////////
374 //
375 //        MISC
376 //
377 //////////////////////////////////////////   
378     
379
380     
381     /**
382      * Gets the configuration from Wordpress database
383      *
384      * @return void
385      */
386     function get_zenconf() {
387     
388         $tmp = get_option('RMCZS_db');
389         $this->zen_db = ($tmp !== false?$tmp:'zenphoto_database');
390         $tmp = get_option('RMCZS_username');
391         $this->zen_user = ($tmp !== false?$tmp:'zenphoto_user');
392         $tmp = get_option('RMCZS_password');
393         $this->zen_pw = ($tmp !== false?$tmp:'zenphoto_password');;
394         $tmp = get_option('RMCZS_prefix');
395         $this->zen_prefix = ($tmp !== false?$tmp:'zp_');
396         $tmp =get_option('RMCZS_host');
397         $this->zen_host = ($tmp !== false?$tmp:'localhost');
398         $tmp =get_option('RMCZS_url');
399         $this->zen_url = ($tmp !== false?$tmp:'/zenphoto/');
400         $tmp =get_option('RMCZS_tb_width');
401         $this->zen_tb_width = ($tmp !== false?$tmp:'100');
402         $tmp =get_option('RMCZS_tb_height');
403         $this->zen_tb_height = ($tmp !== false?$tmp:'100');
404
405     }
406
407     /**
408      * Shows the link to ZenPhoto Administration
409      *
410      */
411     function get_ZenUrl() {
412         
413         if (!empty($this->zen_url))
414
415             echo '<a href="'.$this->zen_url.'zp-core/admin.php" target="_blank">ZenPhoto Admin</a>';
416             
417     }
418     
419     
420     /**
421      * Connects to ZenPhoto database
422      *
423      * @return bool
424      */
425     function connect() {
426
427         global $ZenDB;
428         
429         $this->get_zenconf();
430         
431                     
432         //    OUTPUT
433         // header('Content-Type: text/html; charset=ISO-8859-1');
434         
435         
436         if (empty($this->zen_db)) {
437             
438             echo 'You don\'t have <a href="http://www.zenphoto.org" taget="_blank">ZenPhoto</a> configured/installed.';
439             
440             return false;
441             
442         } else {
443             
444             $ZenDB = new wpdb($this->zen_user, $this->zen_pw, $this->zen_db, $this->zen_host);
445             
446             return true;
447                 
448         }
449             
450         
451     }
452     
453     /**
454      * Kills of some variables
455      *
456      * @return void
457      */
458     function disconnect() {
459         
460         $ZenDB = NULL;
461         
462     }
463     
464
465
466
467
468 }
469
470
471
472 $RMCZS = new RMCZS();
473
474
475 ?>