| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: gallery_profile.module,v 1.2.2.3 2008/06/09 22:18:54 profix898 Exp $ 3 4 /** 5 * gallery_profile.module 6 */ 7 8 /** 9 * Implementation of hook_perm(). 10 */ 11 function gallery_profile_perm() { 12 return array('access gallery profile'); 13 } 14 15 /** 16 * Implementation of hook_menu(). 17 */ 18 function gallery_profile_menu() { 19 $items = array(); 20 if (variable_get('gallery_valid', 0)) { 21 $items['admin/user/gallery/settings/general'] = array( 22 'title' => 'General', 23 'type' => MENU_DEFAULT_LOCAL_TASK, 24 'weight' => 0 25 ); 26 $items['admin/user/gallery/settings/profile'] = array( 27 'title' => 'User Profile', 28 'access callback' => 'gallery_admin_access', 29 'access arguments' => array(array('administer users', 'administer gallery settings')), 30 'page callback' => 'drupal_get_form', 31 'page arguments' => array('_gallery_profile_settings'), 32 'type' => MENU_LOCAL_TASK, 33 'weight' => 1 34 ); 35 } 36 37 return $items; 38 } 39 40 /** 41 * Implementation of hook_profile_alter(). 42 */ 43 function gallery_profile_profile_alter(&$account) { 44 if (isset($account->content['gallery2']) && user_access('access gallery profile')) { 45 $profile = &$account->content['gallery2']; 46 // Set custom title 47 $profile['#title'] = variable_get('gallery_user_profile_title', 'Gallery2'); 48 // Remove sync status message 49 if (variable_get('gallery_user_profile_hide_sync', 0)) { 50 unset($profile['user_sync']); 51 } 52 // Useralbum link/gallery 53 $profile_type = variable_get('gallery_user_profile_gallery', array('link')); 54 if (in_array('gallery', $profile_type) && gallery_user_useralbum($account->uid, FALSE)) { 55 $profile['useralbum_gallery'] = array( 56 '#type' => 'user_profile_item', 57 '#title' => in_array('link', $profile_type) ? 58 $profile['useralbum_link']['#value'] : t('Album: %username', array('%username' => $account->name)), 59 '#value' => _gallery_profile_useralbum($account->uid), 60 '#attributes' => array('class' => 'gallery_profile_useralbum') 61 ); 62 unset($profile['useralbum_link']); 63 } 64 else if (!in_array('link', $profile_type)) { 65 unset($profile['useralbum_link']); 66 } 67 // Hide section (if no items are available) 68 if (count($profile) < 3) { 69 unset($fields['gallery2']); 70 } 71 } 72 } 73 74 /** 75 * Implementation of hook_form_alter(). 76 */ 77 function gallery_profile_form_alter(&$form, $form_state, $form_id) { 78 if ($form_id == '_gallery_user_settings') { 79 unset($form['user']['gallery_user_profile_hide']); 80 $form['user']['sync']['#collapsible'] = FALSE; 81 } 82 } 83 84 /** 85 * Function _gallery_profile_settings(). 86 */ 87 function _gallery_profile_settings() { 88 require_once(drupal_get_path('module', 'gallery') .'/gallery_block.inc'); 89 require_once(drupal_get_path('module', 'gallery') .'/gallery_block_admin.inc'); 90 91 $form['profile'] = array( 92 '#type' => 'fieldset', 93 '#title' => t('User Profile'), 94 '#collapsible' => FALSE, 95 '#collapsed' => FALSE 96 ); 97 98 $form['profile']['gallery_user_profile_hide'] = array( 99 '#type' => 'checkbox', 100 '#title' => t('Hide Gallery2 section in profiles'), 101 '#default_value' => variable_get('gallery_user_profile_hide', 0), 102 '#description' => t('Hide the Gallery2 section (i.e. Gallery2-Drupal Sync Status) on the user profile pages.'), 103 ); 104 105 $form['profile']['gallery_user_profile_title'] = array( 106 '#type' => 'textfield', 107 '#title' => t('Title of Gallery2 profile section'), 108 '#default_value' => variable_get('gallery_user_profile_title', 'Gallery2'), 109 '#size' => 40, 110 '#maxlength' => 255, 111 '#description' => t('Title of the Gallery2 section on profile pages.') 112 ); 113 114 $form['profile']['gallery_user_profile_hide_sync'] = array( 115 '#type' => 'checkbox', 116 '#title' => t('Hide sync status message'), 117 '#default_value' => variable_get('gallery_user_profile_hide_sync', 0), 118 '#description' => t('Hide \'Gallery2-Drupal Sync Status\' message in the profile.'), 119 ); 120 121 $profile_type = variable_get('gallery_user_profile_gallery', array('link')); 122 $form['profile']['gallery_user_profile_gallery'] = array( 123 '#type' => 'checkboxes', 124 '#title' => t('Profile gallery mode'), 125 '#default_value' => $profile_type, 126 '#options' => array( 127 'link' => t('Show link to useralbum'), 128 'gallery' => t('Show (useralbum) gallery/images') 129 ), 130 '#description' => t('By default a link to the useralbum is shown. But you may also insert a gallery of 131 random/recent images from the useralbum into the user profile.'), 132 ); 133 134 // Useralbum settings 135 if (in_array('gallery', $profile_type)) { 136 $form['profile']['useralbum'] = array( 137 '#type' => 'fieldset', 138 '#title' => t('Useralbum settings'), 139 '#collapsible' => TRUE, 140 '#collapsed' => TRUE 141 ); 142 $element = 'gallery_user_profile_useralbum'; 143 $form['profile']['useralbum'] += _gallery_block_admin_imageblock($element, t('profile useralbum')); 144 $form['#submit'][] = '_gallery_block_admin_imageblock_submit'; 145 } 146 147 $form = system_settings_form($form); 148 return $form; 149 } 150 151 /** 152 * Function _gallery_profile_useralbum(). 153 */ 154 function _gallery_profile_useralbum($uid) { 155 $num_cols = variable_get('gallery_user_profile_useralbum_num_cols', 2); 156 $num_rows = variable_get('gallery_user_profile_useralbum_num_rows', 2); 157 $num_images = $num_cols * $num_rows; 158 159 $param_blocks_array = array_filter(variable_get('gallery_user_profile_useralbum_block_block', array('randomImage'))); 160 // Ensure $param_blocks_array contains $num_images elements (auto-append if necessary) 161 $count = count($param_blocks_array); 162 if (($num = $num_images - $count) > 0) { 163 $param_blocks_array += array_fill($count, $num, end($param_blocks_array)); 164 } 165 $params['blocks'] = implode('|', $param_blocks_array); 166 $item_id = trim(variable_get('gallery_user_profile_useralbum_item_id', '')); 167 $params['itemId'] = empty($item_id) ? ('user:'. $uid) : $item_id; 168 $param_show_array = variable_get('gallery_user_profile_useralbum_block_show', array()); 169 $params['show'] = empty($param_show_array) ? 'none' : implode('|', $param_show_array); 170 if (variable_get('gallery_user_profile_useralbum_size_method', GALLERY_GRID_SIZE_METHOD_DEFAULT) == 'maxsize') { 171 $params['maxSize'] = variable_get('gallery_user_profile_useralbum_size', GALLERY_GRID_SIZE_DEFAULT); 172 } 173 else { 174 $params['exactSize'] = variable_get('gallery_user_profile_useralbum_size', GALLERY_GRID_SIZE_DEFAULT); 175 } 176 $params['albumFrame'] = variable_get('gallery_user_profile_useralbum_album_frame', 'none'); 177 $params['itemFrame'] = variable_get('gallery_user_profile_useralbum_item_frame', 'none'); 178 $params['linkTarget'] = variable_get('gallery_user_profile_useralbum_link_target', ''); 179 $params['link'] = variable_get('gallery_user_profile_useralbum_link', ''); 180 181 $block = gallery_get_block($params, 'ImageBlock', array('num_cols' => $num_cols)); 182 return isset($block['content']) ? $block['content'] : ''; 183 }
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 |