| Commit | Line | Data |
|---|---|---|
| 57ec06e3 | 1 | <?php |
| 7b4b07c4 | 2 | // $Id$ |
| c15e9178 | 3 | // For Drupal 4.7 with Gallery 2.1 |
| 57ec06e3 | 4 | |
| c15e9178 | 5 | $path = drupal_get_path('module', 'gallery'); |
| 6 | require_once($path . '/gallery_base.inc'); | |
| 57ec06e3 JW |
7 | |
| 8 | /** | |
| 9 | * Implementation of hook_menu | |
| 10 | */ | |
| 11 | function gallery_menu($may_cache) { | |
| c15e9178 | 12 | global $user; |
| 57ec06e3 | 13 | $items = array(); |
| c15e9178 | 14 | $view_access = (user_access('access user profiles') || ($user->uid == arg(1))); |
| 57ec06e3 | 15 | if ($may_cache) { |
| 744ff82b | 16 | $items[] = array('path' => 'gallery', |
| 34347387 | 17 | 'title' => t('gallery'), |
| 57ec06e3 JW |
18 | 'callback' => 'gallery_page', |
| 19 | 'access' => user_access('access content'), | |
| 34347387 | 20 | 'type' => MENU_NORMAL_ITEM); |
| c15e9178 | 21 | $items[] = array( |
| 22 | 'path' => 'admin/user/gallery', 'title' => t('gallery'), | |
| 23 | 'callback' => 'gallery_users', | |
| 24 | 'access' => user_access('administer users'), | |
| 25 | 'type' => MENU_LOCAL_TASK); | |
| 26 | } else { | |
| 27 | // Add head info here so that it is included once only per page (almost) | |
| 28 | gallery_set_html_head(gallery_css_include()); | |
| 57ec06e3 | 29 | } |
| 57ec06e3 | 30 | return $items; |
| c15e9178 | 31 | } |
| 32 | ||
| 33 | /** | |
| 34 | * Implementation of hook_help | |
| 35 | */ | |
| 36 | function gallery_help($section) { | |
| 37 | $path = drupal_get_path('module', 'gallery'); | |
| 38 | require_once($path . '/gallery_help.inc'); | |
| 39 | return _gallery_help($section); | |
| 57ec06e3 JW |
40 | } |
| 41 | ||
| 42 | /** | |
| 43 | * Implementation of hook_settings | |
| 44 | */ | |
| 45 | function gallery_settings() { | |
| c15e9178 | 46 | $path = drupal_get_path('module', 'gallery'); |
| 47 | require_once($path . '/gallery_settings.inc'); | |
| 48 | return _gallery_settings(); | |
| 57ec06e3 JW |
49 | } |
| 50 | ||
| 51 | /** | |
| 52 | * Implementation of hook_user | |
| 53 | */ | |
| 1fb40367 | 54 | function gallery_user($op, &$edit, &$user, $category = NULL) { |
| c15e9178 | 55 | $path = drupal_get_path('module', 'gallery'); |
| 56 | require_once($path . '/gallery_user.inc'); | |
| 57 | ||
| 57ec06e3 | 58 | switch ($op) { |
| 744ff82b JW |
59 | case 'login': |
| 60 | /* _gallery_init() will try to create the user, if necessary */ | |
| 61 | list ($success, $ret) = _gallery_init(); | |
| 62 | if (!$success) { | |
| 63 | gallery_error(t('Unable to log in to Gallery'), $ret); | |
| 64 | return; | |
| 65 | } | |
| 66 | break; | |
| c15e9178 | 67 | case 'logout': |
| 68 | if (variable_get('gallery_valid', 0)) { | |
| 69 | $embedPath = variable_get('gallery_dir', './gallery2/') . 'embed.php'; | |
| 70 | require_once($embedPath); | |
| 71 | $ret = GalleryEmbed::logout(); | |
| 72 | break; | |
| 744ff82b | 73 | } |
| c15e9178 | 74 | case 'view': |
| 75 | return gallery_view_user($user); | |
| 76 | case 'insert': | |
| 77 | return gallery_insert_user($edit, $user); | |
| 78 | case 'update': | |
| 79 | return gallery_update_user($edit, $user); | |
| 80 | case 'delete': | |
| 81 | return gallery_delete_user($user); | |
| 82 | } | |
| 83 | } | |
| 744ff82b | 84 | |
| c15e9178 | 85 | /** |
| 86 | * Gallery Users Page - view a set of users | |
| 87 | */ | |
| 88 | function gallery_users() { | |
| 89 | $path = drupal_get_path('module', 'gallery'); | |
| 90 | require_once($path . '/gallery_user.inc'); | |
| 91 | return _gallery_users(); | |
| 92 | } | |
| 744ff82b | 93 | |
| c15e9178 | 94 | /** |
| 95 | * implementation of hook_search | |
| 96 | */ | |
| 97 | function gallery_search($op = 'search', $keys = null) { | |
| 98 | $path = drupal_get_path('module', 'gallery'); | |
| 99 | require_once($path . '/gallery_search.inc'); | |
| 100 | return _gallery_search($op, $keys); | |
| 101 | } | |
| 57ec06e3 | 102 | |
| c15e9178 | 103 | /** |
| 104 | * Implementation of hook_search_item to override how to display the item | |
| 105 | */ | |
| 106 | function gallery_search_page($results) { | |
| 107 | $path = drupal_get_path('module', 'gallery'); | |
| 108 | require_once($path . '/gallery_search.inc'); | |
| 109 | return _gallery_search_page($results); | |
| 110 | } | |
| 57ec06e3 | 111 | |
| c15e9178 | 112 | /** |
| 113 | * Implementation of hook_filter | |
| 114 | */\r | |
| 115 | function gallery_filter($op, $delta = 0, $format = -1, $text = '') { | |
| 116 | $path = drupal_get_path('module', 'gallery'); | |
| 117 | require_once($path . '/gallery_filter.inc');\r | |
| 118 | switch ($op) {\r | |
| 119 | case 'list' :\r | |
| 120 | return array (0 => t('Gallery2 filter'));\r | |
| 121 | case 'description' :\r | |
| 122 | return t('Allow users to easily reference Gallery2 items from nodes.');\r | |
| 123 | case 'process' :\r | |
| 124 | return gallery_filter_process($text); | |
| 125 | case 'no cache': | |
| 126 | return !variable_get('gallery_filter_can_cache', 1);\r | |
| 127 | default :\r | |
| 128 | return $text;\r | |
| 129 | }\r | |
| 130 | } | |
| 131 | \r | |
| 132 | /** | |
| 133 | * Implementation of hook_filter_tips | |
| 134 | */\r | |
| 135 | function gallery_filter_tips($delta = 0, $format = -1, $long = false) { | |
| 136 | $path = drupal_get_path('module', 'gallery'); | |
| 137 | require_once($path . '/gallery_help.inc');\r | |
| 138 | if ($long) {\r | |
| 139 | return gallery_filter_long_tip_translated();\r | |
| 140 | } else {\r | |
| 141 | return gallery_filter_short_tip_translated();\r | |
| 142 | }\r | |
| 143 | } | |
| 744ff82b | 144 | |
| c15e9178 | 145 | /** |
| 146 | * Implementation of hook_perm(). | |
| 147 | */ | |
| 148 | function gallery_perm() { | |
| 149 | return array('access standalone g2image'); | |
| 150 | } | |
| 151 | ||
| 152 | /** | |
| 153 | * Implementation of hook_elements() - from img_assist | |
| 154 | */ | |
| 155 | function gallery_elements() { | |
| 156 | $type['textarea'] = array('#process' => array('gallery_g2image_textarea' => array())); | |
| 157 | return $type; | |
| 158 | } | |
| 159 | ||
| 160 | /* | |
| 161 | * Add image link underneath textareas | |
| 162 | */ | |
| 163 | function gallery_g2image_textarea($element) { | |
| 164 | $path = drupal_get_path('module', 'gallery'); | |
| 165 | require_once($path . '/gallery_g2image.inc'); | |
| 166 | if (_gallery_g2image_page_match() && !strstr($_GET['q'], 'gallery') && | |
| 167 | (variable_get('gallery_g2image_mode', 'disabled') == 'standalone') && | |
| 168 | (user_access('access standalone g2image'))) { | |
| 169 | gallery_g2image_add_js(); | |
| 170 | $output = theme('gallery_g2image_textarea_link', $element, $link); | |
| 171 | $element['#suffix'] .= $output; | |
| 744ff82b | 172 | } |
| c15e9178 | 173 | return $element; |
| 57ec06e3 JW |
174 | } |
| 175 | ||
| 176 | /** | |
| 177 | * Implementation of hook_block | |
| 178 | * | |
| 179 | * - gallery navigation block (recommended) | |
| 180 | * - gallery imageblock (random, most viewed, etc) | |
| 181 | */ | |
| 744ff82b | 182 | function gallery_block($op = 'list', $delta = 0, $edit = array()) { |
| c15e9178 | 183 | // Modified typeMap to use current Gallery2 naming |
| 184 | $typeMap = array('none' => t('None'), | |
| 185 | 'randomImage' => t('Random Image'), | |
| 186 | 'recentImage' => t('Newest Image'), | |
| 187 | 'viewedImage' => t('Most Viewed Image'), | |
| 188 | 'randomAlbum' => t('Random Album'), | |
| 189 | 'recentAlbum' => t('Newest Album'), | |
| 190 | 'viewedAlbum' => t('Most Viewed Album'), | |
| 191 | 'dailyImage' => t('Picture of the Day'), | |
| 192 | 'weeklyImage' => t('Picture of the Week'), | |
| 193 | 'monthlyImage' => t('Picture of the Month'), | |
| 194 | 'dailyAlbum' => t('Album of the Day'), | |
| 195 | 'weeklyAlbum' => t('Album of the Week'), | |
| 196 | 'monthlyAlbum' => t('Album of the Month')); | |
| 744ff82b JW |
197 | |
| 198 | switch ($op) { | |
| c15e9178 | 199 | case 'list': |
| 200 | $blocks[0]['info'] = t('Gallery Block'); | |
| 201 | $blocks[1]['info'] = t('Gallery Navigation'); | |
| 202 | return $blocks; | |
| 744ff82b | 203 | |
| c15e9178 | 204 | case 'view': |
| 205 | list ($success, $ret) = _gallery_init(true); | |
| 206 | if (!$success) { | |
| 207 | $err_msg = t('Unable to initialize embedded Gallery. You need to <a href="%link"> | |
| 208 | configure your embedded Gallery</a>.', | |
| 209 | array('%link' => url('admin/settings/gallery'))); | |
| 210 | gallery_error($err_msg, $ret); | |
| 211 | return; | |
| 212 | } | |
| 213 | switch ($delta) { | |
| 214 | // 0 = Image Block | |
| 215 | case 0: | |
| 216 | // Allow for multiple image types | |
| 217 | $param_blocks_array = variable_get('gallery_block_block', array('randomImage')); | |
| 218 | $params['blocks'] = is_array($param_blocks_array) ? implode('|', $param_blocks_array) : ""; | |
| 219 | $param_show_array = variable_get('gallery_block_show', array()); | |
| 220 | $params['show'] = is_array($param_show_array) ? implode('|', $param_show_array) : ""; | |
| 221 | $params['maxSize'] = variable_get('gallery_maxsize', 160); | |
| 222 | // Add frames and link target using g2_filter code from MichelleC | |
| 223 | $params['albumFrame'] = variable_get('gallery_album_frame', 'none');; | |
| 224 | $params['itemFrame'] = variable_get('gallery_item_frame', 'none');; | |
| 225 | $params['linkTarget'] = variable_get('gallery_link_target', '');; | |
| 226 | ||
| 227 | $block = array(); | |
| 228 | list($ret, $content, $head) = GalleryEmbed::getImageBlock($params); | |
| 229 | if ($ret) { | |
| 230 | gallery_error(t('Unable to get Gallery image block'), $ret); | |
| 231 | return; | |
| 232 | } else { | |
| 233 | if ($content) { | |
| 234 | // If more than one image type selected then default the subject to 'Gallery' | |
| 235 | // Also fixes typo in v1.9 -- block => blocks | |
| 236 | if (count(variable_get('gallery_block_block', 'randomImage')) > 1) { | |
| 237 | $block['subject'] = t('Gallery'); | |
| 238 | } else { | |
| 239 | $block['subject'] = $typeMap[$params['blocks']]; | |
| 240 | } | |
| 241 | // TODO: This should not be hardcoded, but included in the CSS. | |
| 242 | $block['content'] = '<center>' . $content . '</center>'; | |
| 9e95ee77 | 243 | } |
| 9e95ee77 JW |
244 | } |
| 245 | if ($head) { | |
| c15e9178 | 246 | gallery_set_html_head($head); |
| 9fe08b6a | 247 | } |
| c15e9178 | 248 | break; |
| 249 | // 1 = Navigation Block | |
| 250 | case 1: | |
| 251 | if (arg(0) == 'gallery') { | |
| 252 | GalleryCapabilities::set('showSidebarBlocks', false); | |
| 253 | $result = GalleryEmbed::handleRequest(); | |
| 254 | if (isset($result['sidebarBlocksHtml']) && !empty($result['sidebarBlocksHtml'])) { | |
| 255 | $block['subject'] = t('Gallery Navigation'); | |
| 256 | $block['content'] = '<div id="gsSidebar" class="gcBorder1">' . join('', $result['sidebarBlocksHtml']) . '</div>'; | |
| 9fe08b6a JW |
257 | } |
| 258 | } | |
| c15e9178 | 259 | break; |
| 9fe08b6a | 260 | } |
| c15e9178 | 261 | $ret = GalleryEmbed::done(); |
| 262 | if ($ret) { | |
| 263 | gallery_error(t('Unable to complete Gallery request'), $ret); | |
| 264 | return; | |
| 265 | } | |
| 266 | return $block; | |
| 57ec06e3 JW |
267 | } |
| 268 | } | |
| 269 | ||
| 270 | /** | |
| 57ec06e3 JW |
271 | * Main gallery display page |
| 272 | */ | |
| 273 | function gallery_page() { | |
| 744ff82b JW |
274 | list ($success, $ret) = _gallery_init(true); |
| 275 | if (!$success) { | |
| 276 | gallery_error(t('Unable to initialize embedded Gallery'), $ret); | |
| c15e9178 | 277 | $err_msg = t('Unable to initialize embedded Gallery. You need to <a href="%link"> |
| 278 | configure your embedded Gallery</a>.', | |
| 279 | array('%link' => url('admin/settings/gallery'))); | |
| 280 | return $err_msg; | |
| 744ff82b | 281 | } |
| c15e9178 | 282 | /* Pass any excess path info to G2 - NEEDED??? */ |
| 283 | // $path = substr($_GET['q'], 7 /* length of 'gallery/' */); | |
| 284 | /* if (!empty($path)) { | |
| 744ff82b | 285 | $_GET[GALLERY_FORM_VARIABLE_PREFIX . 'path'] = $path; |
| c15e9178 | 286 | }*/ |
| 287 | // Turn off sidebar and pathbar | |
| 288 | GalleryCapabilities::set('showSidebarBlocks', false); | |
| 744ff82b | 289 | $result = GalleryEmbed::handleRequest(); |
| 57ec06e3 JW |
290 | if (!$result['isDone']) { |
| 291 | list($title, $css, $javascript) = GalleryEmbed::parseHead($result['headHtml']); | |
| a8e806a8 | 292 | if (!empty($javascript)) { |
| c15e9178 | 293 | gallery_set_html_head(implode("\n", $javascript)); |
| a8e806a8 | 294 | } |
| c15e9178 | 295 | gallery_set_html_head(implode("\n", $css)); |
| 296 | // Add Gallery head. FIX - this will be included twice on a gallery page. Has to be | |
| 297 | // included here as it is after the G2 .css files and so can override them. | |
| 298 | gallery_set_html_head(gallery_css_include(), false); | |
| 7b4b07c4 | 299 | drupal_set_title($title); |
| c15e9178 | 300 | // Add pathbar. See http://gallery.menalto.com/node/33447 |
| 301 | if (isset($result['themeData'])) { | |
| 302 | $urlGenerator =& $GLOBALS['gallery']->getUrlGenerator(); | |
| 303 | $breadcrumb = array(l(t('Home'), '')); | |
| 304 | foreach ($result['themeData']['parents'] as $parent) { | |
| 305 | $parent_title = $parent['title']; | |
| 306 | // Simple strip of bbcode (italics) | |
| 307 | $parent_title = str_replace("[i]", "<i>", $parent_title); | |
| 308 | $parent_title = str_replace("[/i]", "</i>", $parent_title); | |
| 309 | $breadcrumb[] = '<a href="'.$urlGenerator->generateUrl( | |
| 310 | array('itemId' => $parent['id'])) .'">'.$parent_title."</a>"; | |
| 311 | } | |
| 312 | drupal_set_breadcrumb($breadcrumb); | |
| 744ff82b | 313 | } |
| c15e9178 | 314 | return $result['bodyHtml']; |
| 57ec06e3 | 315 | } |
| 744ff82b | 316 | } |
| 57ec06e3 | 317 | |
| 57ec06e3 | 318 | ?> |