| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file Enables PicLens feeds and/or PicLens (Lite) on your Drupal website.
|
| 6 |
*
|
| 7 |
* @author Kristof De Jaeger - http://drupal.org/user/107403 - http://realize.be
|
| 8 |
* @version this is the drupal 5.x version
|
| 9 |
*/
|
| 10 |
|
| 11 |
/**
|
| 12 |
* Implementation of hook_perm().
|
| 13 |
*/
|
| 14 |
function piclens_perm() {
|
| 15 |
return array('administer piclens');
|
| 16 |
}
|
| 17 |
|
| 18 |
/**
|
| 19 |
* Implementation of hook_menu().
|
| 20 |
*/
|
| 21 |
function piclens_menu($may_cache) {
|
| 22 |
$items = array();
|
| 23 |
if ($may_cache) {
|
| 24 |
$items[] = array(
|
| 25 |
'path' => 'piclens',
|
| 26 |
'title' => t('PicLens RSS Feed'),
|
| 27 |
'access' => user_access('access content'),
|
| 28 |
'callback' => 'piclens_create_feed',
|
| 29 |
'type' => MENU_CALLBACK,
|
| 30 |
);
|
| 31 |
$items[] = array(
|
| 32 |
'path' => 'admin/settings/piclens',
|
| 33 |
'title' => t('PicLens'),
|
| 34 |
'access' => user_access('administer piclens'),
|
| 35 |
'callback' => 'drupal_get_form',
|
| 36 |
'callback arguments' => 'piclens_admin_settings',
|
| 37 |
'description' => t('Configure Piclens support on your website.'),
|
| 38 |
);
|
| 39 |
$items[] = array(
|
| 40 |
'path' => 'crossdomain.xml',
|
| 41 |
'access' => user_access('access content'),
|
| 42 |
'callback' => 'piclens_crossdomain_xml',
|
| 43 |
'type' => MENU_CALLBACK,
|
| 44 |
);
|
| 45 |
}
|
| 46 |
else {
|
| 47 |
if (module_exists('image_gallery')) {
|
| 48 |
if (arg(0) == 'image' && arg(1) == 'tid' && is_numeric(arg(2))) {
|
| 49 |
piclens_feed_url(url('piclens/imagegallery/'. arg(2), array('absolute' => TRUE)), 'titelken');
|
| 50 |
if (variable_get('piclens_image_gallery_js', 0) == 1) {
|
| 51 |
piclens_lite_javascript();
|
| 52 |
}
|
| 53 |
if (variable_get('piclens_image_gallery_link', 0) == 1) {
|
| 54 |
piclens_lite_link(TRUE);
|
| 55 |
}
|
| 56 |
}
|
| 57 |
}
|
| 58 |
}
|
| 59 |
return $items;
|
| 60 |
}
|
| 61 |
|
| 62 |
/**
|
| 63 |
* Menu callback used by this module to create feeds.
|
| 64 |
*/
|
| 65 |
function piclens_create_feed() {
|
| 66 |
$args = func_get_args();
|
| 67 |
$type = check_plain(array_shift($args));
|
| 68 |
switch ($type) {
|
| 69 |
case 'imagegallery':
|
| 70 |
if ($args[0] != 0) {
|
| 71 |
$items = piclens_image_gallery_images($args[0]);
|
| 72 |
piclens_rss($items);
|
| 73 |
}
|
| 74 |
break;
|
| 75 |
}
|
| 76 |
}
|
| 77 |
|
| 78 |
/**
|
| 79 |
* Menu callback for piclens settings.
|
| 80 |
*/
|
| 81 |
function piclens_admin_settings() {
|
| 82 |
// image gallery support
|
| 83 |
if (module_exists('image_gallery')) {
|
| 84 |
$form['image_gallery'] = array(
|
| 85 |
'#type' => 'fieldset',
|
| 86 |
'#title' => t('Image Gallery'),
|
| 87 |
);
|
| 88 |
$form['image_gallery']['piclens_image_gallery_rss'] = array(
|
| 89 |
'#type' => 'checkbox',
|
| 90 |
'#title' => t('PicLens rss feeds for image galleries.'),
|
| 91 |
'#description' => t('Toggle this checkbox to create PicLens rss feeds when looking at image gallery pages.<br/>The rss feed will automatically list all images from an image gallery.'),
|
| 92 |
'#default_value' => variable_get('piclens_image_gallery_rss', 0),
|
| 93 |
);
|
| 94 |
// get existing labels from image, leaving out default thumbnail.
|
| 95 |
$sizes = image_get_sizes();
|
| 96 |
foreach ($sizes as $key => $val) {
|
| 97 |
if ($key != 'thumbnail') {
|
| 98 |
$options[$key] = $val['label'];
|
| 99 |
}
|
| 100 |
}
|
| 101 |
$form['image_gallery']['piclens_image_gallery_content'] = array(
|
| 102 |
'#title' => t('Image size content'),
|
| 103 |
'#type' => 'select',
|
| 104 |
'#options' => $options,
|
| 105 |
'#default_value' => variable_get('piclens_image_gallery_content', 'preview'),
|
| 106 |
'#description' => t('Choose which image size to use for the content.<br/>Note: the thumbnail will automatically be the standard image thumbnail.'),
|
| 107 |
);
|
| 108 |
if (variable_get('piclens_image_gallery_rss', 0) == 1) {
|
| 109 |
$form['image_gallery']['piclens_image_gallery_js'] = array(
|
| 110 |
'#type' => 'checkbox',
|
| 111 |
'#title' => t('PicLens Lite javascript for image galleries.'),
|
| 112 |
'#description' => t('Toggle this checkbox to add support for PicLens Lite.<br/>This will add javascript to in the content region of your document.'),
|
| 113 |
'#default_value' => variable_get('piclens_image_gallery_js', 0),
|
| 114 |
);
|
| 115 |
$form['image_gallery']['piclens_image_gallery_link'] = array(
|
| 116 |
'#type' => 'checkbox',
|
| 117 |
'#title' => t('PicLens Lite link for image galleries.'),
|
| 118 |
'#description' => t('Toggle this checkbox to add a link as a drupal message to start the PicLens Lite slideshow.<br/>You can also manually add this link in your template, see README.txt for more info.'),
|
| 119 |
'#default_value' => variable_get('piclens_image_gallery_link', 0),
|
| 120 |
);
|
| 121 |
}
|
| 122 |
return system_settings_form($form);
|
| 123 |
}
|
| 124 |
else {
|
| 125 |
$form['no_supported_modules'] = array(
|
| 126 |
'#type' => 'item',
|
| 127 |
'#title' => t('No support'),
|
| 128 |
'#description' => t('No available modules are found for auto support by PicLens. Supported modules for now is image gallery.<br />However, you can use functions to create a rss feed with your own set of images. See README.txt for more info.')
|
| 129 |
);
|
| 130 |
return $form;
|
| 131 |
}
|
| 132 |
}
|
| 133 |
|
| 134 |
/**
|
| 135 |
* Menu callback to output crossdomain.xml
|
| 136 |
*/
|
| 137 |
function piclens_crossdomain_xml() {
|
| 138 |
$output = '<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
|
| 139 |
<cross-domain-policy>
|
| 140 |
<allow-access-from domain="piclens.com" />
|
| 141 |
</cross-domain-policy>';
|
| 142 |
drupal_set_header('Content-Type: text/xml; charset=utf-8');
|
| 143 |
print $output;
|
| 144 |
}
|
| 145 |
|
| 146 |
/**
|
| 147 |
* Helper function addining rss feed to drupal head.
|
| 148 |
*/
|
| 149 |
function piclens_feed_url($feed_url, $title = '') {
|
| 150 |
$title = isset($title) ? ': '. $title .' - ' : ' ';
|
| 151 |
drupal_add_feed($feed_url, variable_get('site_name', 'Drupal') . $title . t('PicLens RSS'));
|
| 152 |
}
|
| 153 |
|
| 154 |
/**
|
| 155 |
* Helper function adding javascript tag for PicLens Lite.
|
| 156 |
* We use drupal_set_content, because using html_head will crash the execution of jquery.
|
| 157 |
*/
|
| 158 |
function piclens_lite_javascript() {
|
| 159 |
$path = drupal_get_path('module', 'piclens');
|
| 160 |
drupal_set_content('content', '<script type="text/javascript" src="http://lite.piclens.com/current/piclens_optimized.js">');
|
| 161 |
}
|
| 162 |
|
| 163 |
/**
|
| 164 |
* Helper function adding javascript link to start PicLens Lite slideshow.
|
| 165 |
*
|
| 166 |
* @param $drupal_set_mesage determin if we use standard
|
| 167 |
* drupal_set_message function to insert the link into $messages
|
| 168 |
* or just return the link
|
| 169 |
*/
|
| 170 |
function piclens_lite_link($drupal_set_message = false) {
|
| 171 |
$html = theme('piclens_lite_html_link');
|
| 172 |
if ($drupal_set_message == TRUE)
|
| 173 |
drupal_set_message($html);
|
| 174 |
else
|
| 175 |
return $html;
|
| 176 |
}
|
| 177 |
|
| 178 |
function theme_piclens_lite_html_link() {
|
| 179 |
$path = drupal_get_path('module', 'piclens');
|
| 180 |
return '<div id="piclenslite"><a href="javascript:PicLensLite.start();">'. t('Start Slideshow') .' <img src="/'. $path .'/PicLensButton.png" alt="PicLens" title="PicLens" width="16" height="12" border="0" align="absmiddle"></a></div>';
|
| 181 |
}
|
| 182 |
|
| 183 |
/**
|
| 184 |
* Function spitting out rss feed formatted for PicLens support.
|
| 185 |
* @param $items structured xml of items, see piclens_format_item().
|
| 186 |
*
|
| 187 |
* @todo check of xmlns atom is needed and doesn't conflict with 3D plugin.
|
| 188 |
* Since I'm only running fedora at home, I haven't been able to test this to
|
| 189 |
* see if it really works.
|
| 190 |
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss" xmlns:atom="http://www.w3.org/2005/Atom">
|
| 191 |
*
|
| 192 |
*/
|
| 193 |
function piclens_rss($items) {
|
| 194 |
$output = '<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
| 195 |
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss">
|
| 196 |
<channel>
|
| 197 |
'. $items .'
|
| 198 |
</channel>
|
| 199 |
</rss>';
|
| 200 |
|
| 201 |
drupal_set_header('Content-Type: application/rss+xml; charset=utf-8');
|
| 202 |
print $output;
|
| 203 |
}
|
| 204 |
|
| 205 |
/**
|
| 206 |
* Format an item to add to PicLens rss feed.
|
| 207 |
*
|
| 208 |
* @param $item array of item properties
|
| 209 |
* properties:
|
| 210 |
* - title : title image or video
|
| 211 |
* - link : direct link to content
|
| 212 |
* - thumbnail : thumbnail url image or video
|
| 213 |
* - content : content url of image or video
|
| 214 |
*
|
| 215 |
* * @return formatted item
|
| 216 |
*/
|
| 217 |
function piclens_format_item($item) {
|
| 218 |
$rssitem = '
|
| 219 |
<item>
|
| 220 |
<title>'. check_plain($item['title']) .'</title>
|
| 221 |
<link>'. $item['link'] .'</link>
|
| 222 |
<media:thumbnail url="'. $item['thumbnail'] .'"/>
|
| 223 |
<media:content url="'. $item['content'] .'"/>
|
| 224 |
</item>
|
| 225 |
';
|
| 226 |
return $rssitem;
|
| 227 |
}
|
| 228 |
|
| 229 |
/**
|
| 230 |
* Helper function to get all images from an image gallery.
|
| 231 |
*/
|
| 232 |
function piclens_image_gallery_images($tid) {
|
| 233 |
// Allow images to be sorted in a useful order.
|
| 234 |
$query = "SELECT n.nid FROM {term_node} t INNER JOIN {node} n ON t.nid = n.nid WHERE n.status = 1 AND n.type = 'image' AND t.tid = %d ";
|
| 235 |
$args = array($tid);
|
| 236 |
switch (variable_get('image_gallery_sort_order', IMAGE_GALLERY_SORT_CREATE_DESC)) {
|
| 237 |
case IMAGE_GALLERY_SORT_CREATE_DESC:
|
| 238 |
$query .= 'ORDER BY n.sticky DESC, n.created DESC';
|
| 239 |
break;
|
| 240 |
|
| 241 |
case IMAGE_GALLERY_SORT_CREATE_ASC:
|
| 242 |
$query .= 'ORDER BY n.sticky DESC, n.created ASC';
|
| 243 |
break;
|
| 244 |
|
| 245 |
case IMAGE_GALLERY_SORT_FILENAME:
|
| 246 |
$query = "SELECT n.nid FROM {term_node} t INNER JOIN {node} n ON t.nid = n.nid
|
| 247 |
INNER JOIN {image} i ON n.nid = i.nid INNER JOIN {files} f ON i.fid = f.fid
|
| 248 |
WHERE n.status = 1 AND n.type = 'image' AND t.tid = %d AND f.filename = '%s'
|
| 249 |
ORDER BY n.sticky DESC, f.filepath";
|
| 250 |
$args[] = IMAGE_ORIGINAL;
|
| 251 |
break;
|
| 252 |
|
| 253 |
case IMAGE_GALLERY_SORT_TITLE:
|
| 254 |
$query .= 'ORDER BY n.sticky DESC, n.title ASC';
|
| 255 |
break;
|
| 256 |
}
|
| 257 |
|
| 258 |
$content = variable_get('piclens_image_gallery_content', 'preview');
|
| 259 |
$result = db_query(db_rewrite_sql($query), $args);
|
| 260 |
while ($row = db_fetch_object($result)) {
|
| 261 |
$node = node_load($row->nid);
|
| 262 |
$item = array(
|
| 263 |
'title' => $node->title,
|
| 264 |
'link' => $GLOBALS['base_url'] .'/'. $node->images[$content],
|
| 265 |
'thumbnail' => $GLOBALS['base_url'] .'/'. $node->images['thumbnail'],
|
| 266 |
'content' => $GLOBALS['base_url'] .'/'. $node->images[$content],
|
| 267 |
);
|
| 268 |
$items .= piclens_format_item($item);
|
| 269 |
}
|
| 270 |
return $items;
|
| 271 |
}
|