author | Dan Fuhry <dan@enanocms.org> |
Sat, 21 Aug 2010 23:51:10 -0400 | |
changeset 44 | 17cfc3da0dcc |
parent 42 | 7c6e2e97aa08 |
permissions | -rw-r--r-- |
5 | 1 |
<?php |
2 |
||
3 |
/* |
|
4 |
* Snapr |
|
5 |
* Version 0.1 beta 1 |
|
6 |
* Copyright (C) 2007 Dan Fuhry |
|
7 |
* |
|
8 |
* This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License |
|
9 |
* as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied |
|
12 |
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. |
|
13 |
*/ |
|
14 |
||
15 |
// |
|
16 |
// "Random Image" sidebar block |
|
17 |
// |
|
18 |
||
19 |
function gal_sidebar_block() |
|
20 |
{ |
|
42
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
21 |
global $db, $session, $paths, $template, $plugins; // Common objects |
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
22 |
|
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
23 |
$q = $db->sql_query('SELECT img_id,img_title FROM '.table_prefix.'gallery WHERE is_folder=0;'); |
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
24 |
if ( !$q ) |
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
25 |
$db->_die(); |
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
26 |
|
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
27 |
$images = array(); |
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
28 |
while ( $row = $db->fetchrow() ) |
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
29 |
{ |
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
30 |
$id = intval($row['img_id']); |
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
31 |
$images[$id] = $row['img_title']; |
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
32 |
} |
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
33 |
|
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
34 |
// Loop through all gallery images until we find one we can read (typically on the first try, but you never know...) |
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
35 |
$my_image = false; |
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
36 |
while ( count($images) > 0 ) |
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
37 |
{ |
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
38 |
$rand = array_rand($images); |
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
39 |
$image = $images[$rand]; |
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
40 |
$acl = $session->fetch_page_acl(strval($rand), 'Gallery'); |
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
41 |
if ( is_object($acl) && $acl->get_permissions('read') ) |
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
42 |
{ |
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
43 |
$my_image = $image; |
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
44 |
break; |
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
45 |
} |
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
46 |
unset($images[$rand]); |
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
47 |
} |
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
48 |
if ( $my_image ) |
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
49 |
{ |
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
50 |
// Generate sidebar HTML |
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
51 |
$image_link = '<div style="padding: 5px; text-align: center;"> |
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
52 |
<a href="' . makeUrlNS('Gallery', $rand) . '"> |
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
53 |
<img alt="<thumbnail>" src="' . makeUrlNS('Special', 'GalleryFetcher/thumb/' . $rand) . '" style="border-width: 0; display: block; margin: 0 auto 5px auto;" /> |
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
54 |
<span style="color: black;">' . htmlspecialchars($my_image) . '</span> |
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
55 |
</a> |
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
56 |
</div>'; |
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
57 |
} |
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
58 |
else |
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
59 |
{ |
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
60 |
$image_link = 'No images in the gallery.'; |
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
61 |
} |
7c6e2e97aa08
Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents:
13
diff
changeset
|
62 |
$template->sidebar_widget('Random image', $image_link); |
5 | 63 |
} |
64 |
||
65 |
$plugins->attachHook('compile_template', 'gal_sidebar_block();'); |
|
66 |
||
67 |
?> |