| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: gallery_g2image_settings.inc,v 1.1.2.3 2009/01/10 11:20:02 profix898 Exp $ 3 4 require_once(drupal_get_path('module', 'gallery') .'/gallery_settings.inc'); 5 6 /** 7 * gallery_g2image.module : gallery_g2image_settings.inc 8 * Settings functions 9 */ 10 11 /** 12 * Function _gallery_g2image_settings(). 13 */ 14 function _gallery_g2image_settings() { 15 $plugin_status = gallery_plugin_status(array('imageblock')); 16 $plugin_status['g2image'] = _gallery_g2image_path() ? GALLERY_PLUGIN_ENABLED : GALLERY_PLUGIN_MISSING; 17 18 $desc = t('G2Image requires the Gallery2 Image Block plugin (!imageblock_status) and 19 the G2Image application (!g2image_status) to be installed.', 20 array( 21 '!imageblock_status' => theme('gallery_plugin_status_message', $plugin_status['imageblock']), 22 '!g2image_status' => theme('gallery_plugin_status_message', $plugin_status['g2image']) 23 ) 24 ); 25 if ($plugin_status['imageblock'] != GALLERY_PLUGIN_ENABLED) { 26 $g2_uri = variable_get('gallery_embed_uri', '?q=gallery'); 27 $g2_plugins_page = (variable_get('gallery_valid', 0)) ? 28 t('<a href= "@g2_plugins">Gallery2 Plugins</a>', 29 array('@g2_plugins' => $g2_uri .'&g2_view=core.SiteAdmin&g2_subView=core.AdminModules')) 30 : t('Gallery2 Site Admin -> Plugins'); 31 $desc .= t('<br />However, the Image Block plugin is unavailable. To use G2Image please go to 32 the !g2_plugins page and install/activate the Image Block plugin.', array( 33 '!g2_plugins' => $g2_plugins_page)); 34 } 35 if ($plugin_status['g2image'] != GALLERY_PLUGIN_ENABLED) { 36 $desc .= t('<br />However, the G2Image application is unavailable. Please <a href="@g2image_url">download 37 G2Image</a> and install it as outlined in README.TXT.', array( 38 '@g2image_url' => 'http://g2image.steffensenfamily.com/index.php?title=Download')); 39 } 40 41 $form['g2image'] = array( 42 '#type' => 'fieldset', 43 '#title' => t('Gallery Image Assist (G2Image) settings'), 44 '#collapsible' => FALSE, 45 '#collapsed' => FALSE, 46 '#description' => $desc, 47 ); 48 49 if ($plugin_status['imageblock'] == GALLERY_PLUGIN_ENABLED && $plugin_status['g2image'] == GALLERY_PLUGIN_ENABLED) { 50 $form['g2image']['gallery_g2image_mode'] = array( 51 '#type' => 'select', 52 '#title' => t('Mode'), 53 '#default_value' => variable_get('gallery_g2image_mode', 'disabled'), 54 '#options' => array( 55 'disabled' => t('Disabled'), 56 'standalone' => t('Standalone'), 57 'tinymce' => t('TinyMCE'), 58 ), 59 '#description' => t('Determines the mode of operation. For anything other than \'Disabled\' the G2Image 60 application has to be installed. See the README.txt instructions. In \'Standalone\' 61 mode a button will be visible under textfields to launch the g2image window. In 62 \'TinyMCE\' mode the g2image button can be used in the TinyMCE toolbar. Note that the 63 TinyMCE version will NOT work wih Safari - use the standalone version instead.'), 64 ); 65 66 $visibility = variable_get('gallery_g2image_visibility', 1); 67 $form['g2image']['gallery_g2image_visibility'] = array( 68 '#type' => 'radios', 69 '#title' => t('Show G2Image link on specific pages (Standalone mode)'), 70 '#default_value' => $visibility, 71 '#options' => array( 72 t('Show on every page except the listed pages.'), 73 t('Show on only the listed pages.') 74 ) 75 ); 76 if ($visibility) { 77 $form['g2image']['gallery_g2image_visibility_pages'] = array( 78 '#type' => 'textarea', 79 '#title' => t('Pages (Standalone mode only)'), 80 '#default_value' => variable_get('gallery_g2image_visibility_pages', "node/add/*\ncomment/*"), 81 '#description' => t('Enter one page per line as Drupal paths. The \'*\' character is a wildcard. Example paths are 82 \'%blog\' for the blog page and %blog-wildcard for every personal blog. %front is the front page.', 83 array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>')) 84 ); 85 } 86 87 $form['g2image']['gallery_g2image_sortby'] = array( 88 '#type' => 'select', 89 '#title' => t('Default Sort Order'), 90 '#default_value' => variable_get('gallery_g2image_sortby', 'title_asc'), 91 '#options' => array( 92 'title_asc' => t('Gallery2 Title (A-z)'), 93 'title_desc' => t('Gallery2 Title (z-A)'), 94 'name_asc' => t('Filename (A-z)'), 95 'name_desc' => t('Filename (z-A)'), 96 'mtime_desc' => t('Last Modification (newest first)'), 97 'mtime_asc' => t('Last Modification (oldest first)'), 98 ), 99 '#description' => t('Determines the default sorting order.'), 100 ); 101 102 $form['g2image']['gallery_g2image_images_per_page'] = array( 103 '#type' => 'select', 104 '#title' => t('Default Number of images per page'), 105 '#default_value' => variable_get('gallery_g2image_images_per_page', 20), 106 '#options' => _gallery_range_array(10, 60, 10), 107 '#description' => t('Choose the default number of images per page.'), 108 ); 109 110 $form['g2image']['gallery_g2image_display_filenames'] = array( 111 '#type' => 'select', 112 '#title' => t('Default Display Options'), 113 '#default_value' => variable_get('gallery_g2image_display_filenames', 'thumbnails'), 114 '#options' => array( 115 'thumbnails' => t('Thumbnails only'), 116 'filenames' => t('Thumbnails with title and filename'), 117 ), 118 '#description' => t('Choose the default display option for images.'), 119 ); 120 121 $form['g2image']['gallery_g2image_default_action'] = array( 122 '#type' => 'select', 123 '#title' => t('Default Action'), 124 '#default_value' => variable_get('gallery_g2image_default_action', 'drupal_g2_filter'), 125 '#options' => array( 126 'drupal_g2_filter' => t('Gallery Filter ID'), 127 'thumbnail_image' => t('Thumbnail with link to image'), 128 'thumbnail_album' => t('Thumbnail with link to parent album'), 129 'thumbnail_custom_url' => t('Thumbnail with link to custom URL'), 130 'thumbnail_only' => t('Thumbnail only'), 131 'link_image' => t('Text link to image'), 132 'link_parent' => t('Text link to parent album'), 133 ), 134 '#description' => t('Choose the default method of inserting the image info.'), 135 ); 136 137 $form['g2image']['gallery_g2image_custom_url'] = array( 138 '#type' => 'textfield', 139 '#title' => t('Default custom url'), 140 '#default_value' => variable_get('gallery_g2image_custom_url', 'http://'), 141 '#size' => 50, 142 '#maxlength' => 50, 143 '#description' => t('The default custom url. Used with \'Thumbnail with link to custom URL\' action setting'), 144 ); 145 146 $css_options = array( 147 'none' => t('None'), 148 'g2image_normal' => t('Normal'), 149 'g2image_float_left' => t('Float Left'), 150 'g2image_float_right' => t('Float Right'), 151 'g2image_centered' => t('Centered'), 152 ); 153 154 // Merge in custom class options 155 $gallery_g2image_custom_class = array_filter(variable_get('gallery_g2image_custom_class', array())); 156 $css_options = array_merge($css_options, drupal_map_assoc($gallery_g2image_custom_class)); 157 158 $form['g2image']['gallery_g2image_default_alignment'] = array( 159 '#type' => 'select', 160 '#title' => t('Default Alignment'), 161 '#default_value' => variable_get('gallery_g2image_default_alignment', 'none'), 162 '#options' => $css_options, 163 '#description' => t('Choose the default alignment of images.'), 164 ); 165 166 $form['g2image']['gallery_g2image_custom_class'] = array('#tree' => TRUE); 167 for ($i=1; $i<=4; $i++) { 168 $form['g2image']['gallery_g2image_custom_class'][$i] = array( 169 '#type' => 'textfield', 170 '#title' => t('Custom Class @index', array('@index' => $i)), 171 '#default_value' => isset($gallery_g2image_custom_class[$i]) ? $gallery_g2image_custom_class[$i] : '', 172 '#size' => 20, 173 '#maxlength' => 50, 174 ); 175 } 176 $form['g2image']['gallery_g2image_custom_class'][$i-1]['#description'] = t('Additional css classes to be available 177 for selection (must be defined in .css file).'); 178 179 $form['g2image']['gallery_g2image_class_mode'] = array( 180 '#type' => 'select', 181 '#title' => t('Alignment Class Insertion Point'), 182 '#default_value' => variable_get('gallery_g2image_class_mode', 'img'), 183 '#options' => array( 184 'img' => t('<img class=...>'), 185 'div' => t('<div class=...><img ...>'), 186 ), 187 '#description' => t('Determines where the alignment class will be inserted. If you choose \'<div 188 class=...><img ...>\', you will have to manually delete any <div> tags 189 manually after deleting images from the TinyMCE window.'), 190 ); 191 } 192 193 $form['#validate'] = array('_gallery_g2image_settings_validate'); 194 return system_settings_form($form); 195 } 196 197 /** 198 * Function _gallery_g2image_settings_validate(). 199 * (saves the G2Image config file) 200 */ 201 function _gallery_g2image_settings_validate($form, &$form_state) { 202 switch ($form_state['values']['gallery_g2image_mode']) { 203 case 'tinymce': 204 $mode = t('TinyMCE'); 205 if (module_exists('tinymce')) { 206 $path = drupal_get_path('module', 'tinymce'); 207 } else if (module_exists('wysiwyg')) { 208 $path = drupal_get_path('module', 'wysiwyg'); 209 } 210 $path .= '/tinymce/jscripts/tiny_mce/plugins/g2image'; 211 break; 212 case 'standalone': 213 $mode = t('Standalone'); 214 $path = drupal_get_path('module', 'gallery_g2image'); 215 $path .= '/g2image'; 216 break; 217 default: 218 return; 219 } 220 221 // Note that file_check_directory uses &$path and will strip the trailing '/' 222 $filename = $path .'/config.php'; 223 if (is_writable($filename) == FALSE && !file_check_directory($path)) { 224 form_set_error('', t('G2Image does not seem to be installed for @mode mode in the required directory (@dir), or the 225 directory is not writable. Please see the INSTALL.txt for instructions.', 226 array('@mode' => $mode, '@dir' => '<drupal_path>/'. $path))); 227 return; 228 } 229 230 $cr = "\n"; 231 $g2ic_gallery2_path = str_replace('\\', '/', variable_get('gallery_dir', './gallery2/')); 232 $g2ic_use_full_path = (substr($g2ic_gallery2_path, 0, 1) == '/' || substr($g2ic_gallery2_path, $_SERVER['DOCUMENT_ROOT']) !== FALSE) ? 'TRUE' : 'FALSE'; 233 $form_state['values']['gallery_g2image_custom_url'] = check_url($form_state['values']['gallery_g2image_custom_url']); 234 $g2ic_display_filenames = ($form_state['values']['gallery_g2image_display_filenames'] == 'filenames') ? 'TRUE' : 'FALSE'; 235 $g2ic_custom_class = array(); 236 foreach ($form_state['values']['gallery_g2image_custom_class'] as $key => $value) { 237 $g2ic_custom_class[$key] = ($value) ? $value : 'not_used'; 238 } 239 240 $content = '<?php'. $cr; 241 $content .= '/*'. $cr; 242 $content .= ' Gallery 2 Image Chooser'. $cr; 243 $content .= ' Version 3.0 - updated 16 SEP 2007'. $cr; 244 $content .= ' Documentation: http://g2image.steffensenfamily.com/'. $cr; 245 $content .= $cr; 246 $content .= ' Author: Kirk Steffensen with inspiration, code snippets,'. $cr; 247 $content .= ' and assistance as listed in CREDITS.HTML'. $cr; 248 $content .= $cr; 249 $content .= ' Released under the GPL version 2.'. $cr; 250 $content .= ' A copy of the license is in the root folder of this plugin.'. $cr; 251 $content .= $cr; 252 $content .= ' See README.HTML for installation info.'. $cr; 253 $content .= ' See CHANGELOG.HTML for a history of changes.'. $cr; 254 $content .= '*/'. $cr; 255 $content .= $cr; 256 $content .= '// Automatically generated by gallery.module (admin/settings/gallery/g2image).'. $cr; 257 $content .= '// DO NOT EDIT'. $cr; 258 $content .= $cr; 259 260 $content .= '$g2ic_embedded_mode = TRUE;'. $cr; 261 $content .= '$g2ic_gallery2_path = \''. $g2ic_gallery2_path .'\';'. $cr; 262 $content .= '$g2ic_use_full_path = '. $g2ic_use_full_path .';'. $cr; 263 $content .= '$g2ic_gallery2_uri = \''. variable_get('gallery_uri', '/gallery2/') .'\';'. $cr; 264 $content .= '$g2ic_embed_uri = \''. variable_get('gallery_embed_uri', '?q=gallery') .'\';'. $cr; 265 266 $content .= '$g2ic_drupal_g2_filter = TRUE;'. $cr; 267 $content .= '$g2ic_drupal_g2_filter_prefix = \''. variable_get('gallery_filter_prefix', 'G2') .'\';'. $cr; 268 269 $content .= '$g2ic_language = \'en\';'. $cr; 270 $content .= '$g2ic_images_per_page = '. $form_state['values']['gallery_g2image_images_per_page'] .';'. $cr; 271 $content .= '$g2ic_display_filenames = '. $g2ic_display_filenames .';'. $cr; 272 273 $content .= '$g2ic_default_alignment = \''. $form_state['values']['gallery_g2image_default_alignment'] .'\';'. $cr; 274 $content .= '$g2ic_custom_class_1 = \''. $g2ic_custom_class[1] .'\';'. $cr; 275 $content .= '$g2ic_custom_class_2 = \''. $g2ic_custom_class[2] .'\';'. $cr; 276 $content .= '$g2ic_custom_class_3 = \''. $g2ic_custom_class[3] .'\';'. $cr; 277 $content .= '$g2ic_custom_class_4 = \''. $g2ic_custom_class[4] .'\';'. $cr; 278 $content .= '$g2ic_class_mode = \''. $form_state['values']['gallery_g2image_class_mode'] .'\';'. $cr; 279 280 $content .= '$g2ic_default_action = \''. $form_state['values']['gallery_g2image_default_action'] .'\';'. $cr; 281 $content .= '$g2ic_sortby = \''. $form_state['values']['gallery_g2image_sortby'] .'\';'. $cr; 282 $content .= '$g2ic_custom_url = \''. $form_state['values']['gallery_g2image_custom_url'] .'\';'. $cr; 283 $content .= $cr; 284 $content .= '?>'. $cr; 285 286 $filename = $path .'/config.php'; 287 if (is_writable($filename) == FALSE) { 288 form_set_error('', t('Could not write to G2Image config file. Please check the permissions for @filename.', 289 array('@filename' => $filename))); 290 return; 291 } 292 $handle = fopen($filename, "w"); 293 if (fwrite($handle, $content) === FALSE) { 294 form_set_error('', t('Could not write to G2Image config file. Please check the permissions for @filename.', 295 array('@filename' => $filename))); 296 return; 297 } 298 else { 299 drupal_set_message(t('G2Image configuration file successfully created.')); 300 } 301 fclose($handle); 302 } 303 304 /** 305 * Function _gallery_g2image_path(). 306 */ 307 function _gallery_g2image_path($path = NULL) { 308 if (!isset($path)) { 309 // Standalone G2Image folder 310 $path = drupal_get_path('module', 'gallery_g2image') .'/g2image'; 311 if (!file_exists($path .'/config.php') && !file_check_directory($path)) { 312 $path = NULL; 313 // TinyMCE folder for G2Image plugin 314 if (module_exists('tinymce')) { 315 $path = drupal_get_path('module', 'tinymce'); 316 $path .= '/tinymce/jscripts/tiny_mce/plugins/g2image'; 317 if (!file_exists($path .'/config.php') && !file_check_directory($path)) { 318 $path = NULL; 319 } 320 } else if (module_exists('wysiwyg')) { 321 // WYSIWYG folder for G2Image plugin 322 $path = drupal_get_path('module', 'wysiwyg'); 323 $path .= '/tinymce/jscripts/tiny_mce/plugins/g2image'; 324 if (!file_exists($path .'/config.php') && !file_check_directory($path)) { 325 $path = NULL; 326 } 327 } 328 } 329 } 330 331 // Store location of G2Image 332 variable_set('gallery_g2image_path', isset($path) ? $path : FALSE); 333 334 return $path; 335 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |