| 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) { |
| 55260521 | 16 | $items[] = array( |
| 17 | 'path' => 'gallery', | |
| 18 | 'title' => t('gallery'), | |
| 19 | 'callback' => 'gallery_page', | |
| c12f5411 | 20 | 'access' => user_access('access gallery'), |
| 55260521 | 21 | 'type' => MENU_NORMAL_ITEM, |
| 22 | ); | |
| c15e9178 | 23 | $items[] = array( |
| 24 | 'path' => 'admin/user/gallery', 'title' => t('gallery'), | |
| 25 | 'callback' => 'gallery_users', | |
| 26 | 'access' => user_access('administer users'), | |
| 55260521 | 27 | 'type' => MENU_LOCAL_TASK, |
| 28 | ); | |
| 04b696f5 | 29 | $items[] = array( |
| 30 | 'path' => 'admin/settings/gallery', | |
| 31 | 'title' => t('gallery'), | |
| 32 | 'description' => t('Settings for embedded Gallery2.'), | |
| 33 | 'callback' => 'drupal_get_form', | |
| 34 | 'callback arguments' => 'gallery_admin_settings', | |
| 35 | 'access' => user_access('administer site configuration'), | |
| 36 | 'type' => MENU_NORMAL_ITEM, | |
| 37 | ); | |
| c15e9178 | 38 | } else { |
| 04b696f5 | 39 | drupal_add_css(drupal_get_path('module', 'gallery') .'/drupal_g2.css', 'module', 'all'); |
| 57ec06e3 | 40 | } |
| 57ec06e3 | 41 | return $items; |
| c15e9178 | 42 | } |
| 43 | ||
| 44 | /** | |
| 45 | * Implementation of hook_help | |
| 46 | */ | |
| 47 | function gallery_help($section) { | |
| 48 | $path = drupal_get_path('module', 'gallery'); | |
| 49 | require_once($path . '/gallery_help.inc'); | |
| 50 | return _gallery_help($section); | |
| 57ec06e3 JW |
51 | } |
| 52 | ||
| 53 | /** | |
| 54 | * Implementation of hook_settings | |
| 55 | */ | |
| 04b696f5 | 56 | function gallery_admin_settings() { |
| c15e9178 | 57 | $path = drupal_get_path('module', 'gallery'); |
| 58 | require_once($path . '/gallery_settings.inc'); | |
| 04b696f5 | 59 | return system_settings_form(_gallery_settings()); |
| 57ec06e3 JW |
60 | } |
| 61 | ||
| 62 | /** | |
| 63 | * Implementation of hook_user | |
| 64 | */ | |
| 1fb40367 | 65 | function gallery_user($op, &$edit, &$user, $category = NULL) { |
| c15e9178 | 66 | $path = drupal_get_path('module', 'gallery'); |
| 67 | require_once($path . '/gallery_user.inc'); | |
| 68 | ||
| 57ec06e3 | 69 | switch ($op) { |
| 744ff82b JW |
70 | case 'login': |
| 71 | /* _gallery_init() will try to create the user, if necessary */ | |
| 72 | list ($success, $ret) = _gallery_init(); | |
| 73 | if (!$success) { | |
| 74 | gallery_error(t('Unable to log in to Gallery'), $ret); | |
| 75 | return; | |
| 76 | } | |
| 77 | break; | |
| c15e9178 | 78 | case 'logout': |
| 79 | if (variable_get('gallery_valid', 0)) { | |
| 80 | $embedPath = variable_get('gallery_dir', './gallery2/') . 'embed.php'; | |
| 81 | require_once($embedPath); | |
| 82 | $ret = GalleryEmbed::logout(); | |
| 83 | break; | |
| 744ff82b | 84 | } |
| c15e9178 | 85 | case 'view': |
| 86 | return gallery_view_user($user); | |
| 87 | case 'insert': | |
| 88 | return gallery_insert_user($edit, $user); | |
| 89 | case 'update': | |
| 90 | return gallery_update_user($edit, $user); | |
| 91 | case 'delete': | |
| 92 | return gallery_delete_user($user); | |
| 93 | } | |
| 94 | } | |
| 744ff82b | 95 | |
| c15e9178 | 96 | /** |
| 97 | * Gallery Users Page - view a set of users | |
| 98 | */ | |
| 99 | function gallery_users() { | |
| 100 | $path = drupal_get_path('module', 'gallery'); | |
| 101 | require_once($path . '/gallery_user.inc'); | |
| 102 | return _gallery_users(); | |
| 103 | } | |
| 744ff82b | 104 | |
| c15e9178 | 105 | /** |
| 106 | * implementation of hook_search | |
| 107 | */ | |
| 108 | function gallery_search($op = 'search', $keys = null) { | |
| 109 | $path = drupal_get_path('module', 'gallery'); | |
| 110 | require_once($path . '/gallery_search.inc'); | |
| 111 | return _gallery_search($op, $keys); | |
| 112 | } | |
| 57ec06e3 | 113 | |
| c15e9178 | 114 | /** |
| 115 | * Implementation of hook_search_item to override how to display the item | |
| 116 | */ | |
| 117 | function gallery_search_page($results) { | |
| 118 | $path = drupal_get_path('module', 'gallery'); | |
| 119 | require_once($path . '/gallery_search.inc'); | |
| 120 | return _gallery_search_page($results); | |
| 121 | } | |
| 57ec06e3 | 122 | |
| c15e9178 | 123 | /** |
| 124 | * Implementation of hook_filter | |
| f88309ad | 125 | */ |
| c15e9178 | 126 | function gallery_filter($op, $delta = 0, $format = -1, $text = '') { |
| 127 | $path = drupal_get_path('module', 'gallery'); | |
| f88309ad | 128 | require_once($path . '/gallery_filter.inc'); |
| 129 | switch ($op) { | |
| 130 | case 'list' : | |
| 131 | return array (0 => t('Gallery2 filter')); | |
| 132 | case 'description' : | |
| 133 | return t('Allow users to easily reference Gallery2 items from nodes.'); | |
| 134 | case 'process' : | |
| c15e9178 | 135 | return gallery_filter_process($text); |
| 136 | case 'no cache': | |
| f88309ad | 137 | return !variable_get('gallery_filter_can_cache', 1); |
| 138 | default : | |
| 139 | return $text; | |
| 140 | } | |
| c15e9178 | 141 | } |
| f88309ad | 142 | |
| c15e9178 | 143 | /** |
| 144 | * Implementation of hook_filter_tips | |
| f88309ad | 145 | */ |
| c15e9178 | 146 | function gallery_filter_tips($delta = 0, $format = -1, $long = false) { |
| 147 | $path = drupal_get_path('module', 'gallery'); | |
| f88309ad | 148 | require_once($path . '/gallery_help.inc'); |
| 149 | if ($long) { | |
| 150 | return gallery_filter_long_tip_translated(); | |
| 151 | } else { | |
| 152 | return gallery_filter_short_tip_translated(); | |
| 153 | } | |
| c15e9178 | 154 | } |
| 744ff82b | 155 | |
| c15e9178 | 156 | /** |
| 157 | * Implementation of hook_perm(). | |
| 158 | */ | |
| 159 | function gallery_perm() { | |
| c12f5411 | 160 | return array('access gallery', 'access standalone g2image'); |
| c15e9178 | 161 | } |
| 162 | ||
| 163 | /** | |
| 164 | * Implementation of hook_elements() - from img_assist | |
| 165 | */ | |
| 166 | function gallery_elements() { | |
| 167 | $type['textarea'] = array('#process' => array('gallery_g2image_textarea' => array())); | |
| 168 | return $type; | |
| 169 | } | |
| 170 | ||
| 171 | /* | |
| 172 | * Add image link underneath textareas | |
| 173 | */ | |
| 174 | function gallery_g2image_textarea($element) { | |
| 175 | $path = drupal_get_path('module', 'gallery'); | |
| 176 | require_once($path . '/gallery_g2image.inc'); | |
| 177 | if (_gallery_g2image_page_match() && !strstr($_GET['q'], 'gallery') && | |
| 178 | (variable_get('gallery_g2image_mode', 'disabled') == 'standalone') && | |
| 179 | (user_access('access standalone g2image'))) { | |
| 180 | gallery_g2image_add_js(); | |
| 181 | $output = theme('gallery_g2image_textarea_link', $element, $link); | |
| 182 | $element['#suffix'] .= $output; | |
| 744ff82b | 183 | } |
| c15e9178 | 184 | return $element; |
| 57ec06e3 JW |
185 | } |
| 186 | ||
| 187 | /** | |
| 188 | * Implementation of hook_block | |
| 189 | * | |
| 57ec06e3 | 190 | */ |
| 744ff82b | 191 | function gallery_block($op = 'list', $delta = 0, $edit = array()) { |
| 55260521 | 192 | $path = drupal_get_path('module', 'gallery'); |
| 193 | require_once($path . '/gallery_block.inc'); | |
| 194 | return _gallery_block($op, $delta, $edit); | |
| 57ec06e3 JW |
195 | } |
| 196 | ||
| 197 | /** | |
| 57ec06e3 JW |
198 | * Main gallery display page |
| 199 | */ | |
| 200 | function gallery_page() { | |
| 9028ba95 | 201 | global $gallery_sidebar; |
| 744ff82b JW |
202 | list ($success, $ret) = _gallery_init(true); |
| 203 | if (!$success) { | |
| 204 | gallery_error(t('Unable to initialize embedded Gallery'), $ret); | |
| c15e9178 | 205 | $err_msg = t('Unable to initialize embedded Gallery. You need to <a href="%link"> |
| 206 | configure your embedded Gallery</a>.', | |
| 207 | array('%link' => url('admin/settings/gallery'))); | |
| 208 | return $err_msg; | |
| 744ff82b | 209 | } |
| 9028ba95 | 210 | // Turn off sidebar |
| c15e9178 | 211 | GalleryCapabilities::set('showSidebarBlocks', false); |
| 744ff82b | 212 | $result = GalleryEmbed::handleRequest(); |
| 57ec06e3 JW |
213 | if (!$result['isDone']) { |
| 214 | list($title, $css, $javascript) = GalleryEmbed::parseHead($result['headHtml']); | |
| a8e806a8 | 215 | if (!empty($javascript)) { |
| c15e9178 | 216 | gallery_set_html_head(implode("\n", $javascript)); |
| a8e806a8 | 217 | } |
| c15e9178 | 218 | gallery_set_html_head(implode("\n", $css)); |
| 7b4b07c4 | 219 | drupal_set_title($title); |
| c15e9178 | 220 | // Add pathbar. See http://gallery.menalto.com/node/33447 |
| 221 | if (isset($result['themeData'])) { | |
| 9028ba95 | 222 | $urlGenerator =& $GLOBALS['gallery']->getUrlGenerator(); |
| 223 | $breadcrumb = array(l(t('Home'), '')); | |
| f88309ad | 224 | // Some themes (eg hybrid) do not set $result['themeData']['parents'] |
| 225 | if ($result['themeData']['parents']) { | |
| 226 | foreach ($result['themeData']['parents'] as $parent) { | |
| 227 | $parent_title = $parent['title']; | |
| 228 | // Simple strip of bbcode (italics) | |
| 229 | $parent_title = str_replace("[i]", "<i>", $parent_title); | |
| 230 | $parent_title = str_replace("[/i]", "</i>", $parent_title); | |
| 231 | // Still does not generate a clean url for /gallery (uses index.php?q=gallery) | |
| 232 | $link = $urlGenerator->generateUrl( | |
| 233 | array('view' => 'core.ShowItem', | |
| 234 | 'itemId' => $parent['id']), | |
| 235 | array('forceFullUrl' => 1)); | |
| 236 | $breadcrumb[] = l($parent_title, $link); | |
| 237 | } | |
| 744ff82b | 238 | } |
| 9028ba95 | 239 | drupal_set_breadcrumb($breadcrumb); |
| 240 | } | |
| 241 | // Store the sidebar info in a global variable for use in the gallery navigation block | |
| 242 | $gallery_sidebar = $result['sidebarBlocksHtml']; | |
| 243 | ||
| c15e9178 | 244 | return $result['bodyHtml']; |
| 57ec06e3 | 245 | } |
| 744ff82b | 246 | } |
| 57ec06e3 | 247 | |
| 57ec06e3 | 248 | ?> |