| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: image_gallery.admin.inc,v 1.2.2.1 2010/08/03 17:43:00 sun Exp $ 3 4 /** 5 * @file 6 * Contains menu callbacks for image_gallery admin pages. 7 */ 8 9 /** 10 * Menu callback for settings page. 11 */ 12 function image_gallery_admin_settings() { 13 _image_check_settings(); 14 15 // Show various messages if Views module is enabled. 16 if (module_exists('views')) { 17 // Test the status of the view: 18 // It's enabled by default, so either: 19 // - not set: view enabled 20 // - FALSE: view enabled 21 // - TRUE: view disabled 22 // @see views_get_all_views(). 23 $status = variable_get('views_defaults', array()); 24 if (isset($status['image_gallery']) && $status['image_gallery']) { 25 // The view is disabled: tell the user that more interesting things can be done. 26 $form['info']['#value'] = t('Enabling the <a href="!views-link">image_gallery view</a> will give you many more ways to customize your galleries.', array('!views-link' => url('admin/build/views'))); 27 } 28 else { 29 // The view is enabled: explain why there are no settings here and leave. 30 $form['info'] = array( 31 '#type' => 'item', 32 '#title' => t('Image galleries are being made with the Views module'), 33 ); 34 if (module_exists('views_ui')) { 35 $form['info']['#value'] = t('To change the way galleries are displayed, edit the image_gallery view on the <a href="!views-link">Views administration page</a>.', array('!views-link' => url('admin/build/views'))); 36 } 37 else { 38 $form['info']['#value'] = t('To change the way galleries are displayed, enable the <strong>Views UI</strong> module on the <a href="!modules-link">Modules administration page</a>, then override the default image_gallery view.', array('!modules-link' => url('admin/build/modules'))); 39 } 40 return $form; 41 } 42 } 43 44 $form['gallery'] = array( 45 '#type' => 'fieldset', 46 '#title' => t('Gallery settings'), 47 ); 48 $form['gallery']['image_images_per_page'] = array( 49 '#type' => 'textfield', 50 '#title' => t('Images per page'), 51 '#default_value' => variable_get('image_images_per_page', 6), 52 '#size' => 3, 53 '#description' => t('Sets the number of images to be displayed in a gallery page.'), 54 ); 55 $form['gallery']['image_gallery_node_info'] = array( 56 '#type' => 'checkbox', 57 '#title' => t('Display node info'), 58 '#default_value' => variable_get('image_gallery_node_info', 0), 59 '#description' => t("Checking this will display the \"Posted by\" node information on the gallery pages."), 60 ); 61 $form['gallery']['image_gallery_sort_order'] = array( 62 '#type' => 'radios', 63 '#title' => t('Image display sort order'), 64 '#default_value' => variable_get('image_gallery_sort_order', IMAGE_GALLERY_SORT_CREATE_DESC), 65 '#options' => array( 66 IMAGE_GALLERY_SORT_CREATE_DESC => t('Create date, newest first'), 67 IMAGE_GALLERY_SORT_CREATE_ASC => t('Create date, oldest first'), 68 IMAGE_GALLERY_SORT_FILENAME => t('File name'), 69 IMAGE_GALLERY_SORT_TITLE => t('Image title'), 70 ), 71 ); 72 73 return system_settings_form($form); 74 } 75 76 /** 77 * Menu callback for gallery admin. 78 */ 79 function image_gallery_admin() { 80 _image_check_settings(); 81 82 $tree = taxonomy_get_tree(_image_gallery_get_vid()); 83 if ($tree) { 84 $header = array(t('Name'), t('Operations')); 85 foreach ($tree as $term) { 86 $rows[] = array(str_repeat(' -- ', $term->depth) . ' ' . l($term->name, "image/tid/$term->tid"), l(t('edit gallery'), "admin/content/image/edit/$term->tid")); 87 } 88 return theme('table', $header, $rows); 89 } 90 else { 91 return t('No galleries available'); 92 } 93 } 94 95 /** 96 * Menu callback for editing or adding a gallery. 97 */ 98 function image_gallery_admin_edit($tid = NULL) { 99 if ((isset($_POST['op']) && $_POST['op'] == t('Delete')) || isset($_POST['confirm'])) { 100 return drupal_get_form('image_gallery_confirm_delete_form', $tid); 101 } 102 103 if (is_numeric($tid)) { 104 $edit = (array) taxonomy_get_term($tid); 105 } 106 else { 107 $edit = array( 108 'name' => '', 109 'description' => '', 110 'vid' => _image_gallery_get_vid(), 111 'tid' => NULL, 112 'weight' => 0, 113 ); 114 } 115 return drupal_get_form('image_gallery_admin_form', $edit); 116 } 117 118 /** 119 * Form for editing or adding a gallery. 120 */ 121 function image_gallery_admin_form(&$form_state, $edit = array()) { 122 $form['name'] = array( 123 '#type' => 'textfield', 124 '#title' => t('Gallery name'), 125 '#default_value' => $edit['name'], 126 '#size' => 60, 127 '#maxlength' => 64, 128 '#description' => t('The name is used to identify the gallery.'), 129 '#required' => TRUE, 130 ); 131 $form['description'] = array( 132 '#type' => 'textarea', 133 '#title' => t('Description'), 134 '#default_value' => $edit['description'], 135 '#cols' => 60, 136 '#rows' => 5, 137 '#description' => t('The description can be used to provide more information about the image gallery.'), 138 ); 139 $form['parent']['#tree'] = TRUE; 140 $form['parent'][0] = _image_gallery_parent_select($edit['tid'], t('Parent'), 'forum'); 141 $form['weight'] = array( 142 '#type' => 'weight', 143 '#title' => t('Weight'), 144 '#default_value' => $edit['weight'], 145 '#delta' => 10, 146 '#description' => t('When listing galleries, those with with light (small) weights get listed before containers with heavier (larger) weights. Galleries with equal weights are sorted alphabetically.'), 147 ); 148 $form['vid'] = array( 149 '#type' => 'hidden', 150 '#value' => _image_gallery_get_vid(), 151 ); 152 $form['submit'] = array( 153 '#type' => 'submit', 154 '#value' => t('Save'), 155 ); 156 if ($edit['tid']) { 157 $form['delete'] = array( 158 '#type' => 'submit', 159 '#value' => t('Delete'), 160 ); 161 $form['tid'] = array( 162 '#type' => 'hidden', 163 '#value' => $edit['tid'], 164 ); 165 } 166 $form['#submit'][] = 'image_gallery_admin_submit'; 167 $form['#theme'][] = 'image_gallery_admin'; 168 return $form; 169 } 170 171 function _image_gallery_parent_select($tid, $title) { 172 $parents = taxonomy_get_parents($tid); 173 if ($parents) { 174 $parent = array_shift($parents); 175 $parent = $parent->tid; 176 } 177 else { 178 $parent = 0; 179 } 180 181 $children = taxonomy_get_tree(_image_gallery_get_vid(), $tid); 182 183 // A term can't be the child of itself, nor of its children. 184 foreach ($children as $child) { 185 $exclude[] = $child->tid; 186 } 187 $exclude[] = $tid; 188 189 $tree = taxonomy_get_tree(_image_gallery_get_vid()); 190 $options[0] = '<' . t('root') . '>'; 191 if ($tree) { 192 foreach ($tree as $term) { 193 if (!in_array($term->tid, $exclude)) { 194 $options[$term->tid] = str_repeat(' -- ', $term->depth) . ' ' . $term->name; 195 } 196 } 197 } 198 199 return array( 200 '#type' => 'select', 201 '#title' => $title, 202 '#default_value' => $parent, 203 '#options' => $options, 204 '#description' => t('Image galleries may be nested below other galleries.'), 205 '#required' => TRUE, 206 ); 207 } 208 209 /** 210 * Form submit handler. 211 */ 212 function image_gallery_admin_submit($form, &$form_state) { 213 $status = taxonomy_save_term($form_state['values']); 214 switch ($status) { 215 case SAVED_NEW: 216 drupal_set_message(t('Created new gallery %term.', array('%term' => $form_state['values']['name']))); 217 break; 218 219 case SAVED_UPDATED: 220 drupal_set_message(t('The gallery %term has been updated.', array('%term' => $form_state['values']['name']))); 221 break; 222 223 case SAVED_DELETED: 224 drupal_set_message(t('The gallery %term has been deleted.', array('%term' => $form_state['values']['name']))); 225 break; 226 } 227 return 'admin/content/image'; 228 } 229 230 /** 231 * Form for confirmation for deleting a gallery. 232 */ 233 function image_gallery_confirm_delete_form(&$form_state, $tid) { 234 $term = taxonomy_get_term($tid); 235 236 $form['tid'] = array('#type' => 'value', '#value' => $tid); 237 $form['name'] = array('#type' => 'value', '#value' => $term->name); 238 239 return confirm_form($form, t('Are you sure you want to delete the image gallery %name?', array('%name' => $term->name)), 'admin/content/image', t('Deleting an image gallery will delete all sub-galleries. This action cannot be undone.'), t('Delete'), t('Cancel')); 240 } 241 242 /** 243 * Form submit handler. 244 */ 245 function image_gallery_confirm_delete_form_submit($form, &$form_state) { 246 taxonomy_del_term($form_state['values']['tid']); 247 drupal_set_message(t('The image gallery %term and all sub-galleries have been deleted.', array('%term' => $form_state['values']['name']))); 248 $form_state['redirect'] = 'admin/content/image'; 249 } 250
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 |