/[drupal]/contributions/modules/gallery/gallery_profile/gallery_profile.module
ViewVC logotype

Contents of /contributions/modules/gallery/gallery_profile/gallery_profile.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Fri Nov 23 10:01:39 2007 UTC (2 years ago) by profix898
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--1
Changes since 1.1: +245 -0 lines
File MIME type: text/x-php
- Update HEAD to 5.x-2.0 release version
1 <?php
2 // $Id: gallery_profile.module,v 1.1.2.3 2007/11/14 00:56:46 profix898 Exp $
3
4 /**
5 * gallery_profile.module
6 */
7
8 /**
9 * Implementation of hook_profile_alter().
10 */
11 function gallery_profile_profile_alter(&$account, &$fields) {
12 if (isset($fields['Gallery2'])) {
13 // Set custom title
14 $title = variable_get('gallery_user_profile_title', 'Gallery2');
15 if ($title != 'Gallery2') {
16 $fields[$title] = $fields['Gallery2'];
17 unset($fields['Gallery2']);
18 }
19 $profile = &$fields[$title];
20 // Remove sync status message
21 if (variable_get('gallery_user_profile_hide_sync', 0)) {
22 unset($profile['user_sync']);
23 }
24 // Useralbum link/gallery
25 $gallery_mode = variable_get('gallery_user_profile_gallery', array('link'));
26 if (in_array('gallery', $gallery_mode) && gallery_user_useralbum($account->uid, FALSE)) {
27 $profile['useralbum_gallery'] = array(
28 'title' => in_array('link', $gallery_mode) ?
29 $profile['useralbum_link']['value'] : t('Album: %username', array('%username' => $account->name)),
30 'value' => _gallery_profile_useralbum($account->uid),
31 'class' => 'gallery_profile_useralbum',
32 );
33 unset($profile['useralbum_link']);
34 }
35 else if (!in_array('link', $gallery_mode)) {
36 unset($profile['useralbum_link']);
37 }
38 // Hide section (if no items are available)
39 if (empty($profile)) {
40 unset($fields[$title]);
41 }
42 }
43 }
44
45 /**
46 * Implementation of hook_form_alter().
47 */
48 function gallery_profile_form_alter($form_id, &$form) {
49 if ($form_id == '_gallery_user_settings') {
50 $form['user']['profile']['#collapsed'] = TRUE;
51
52 $form['user']['profile']['gallery_user_profile_title'] = array(
53 '#type' => 'textfield',
54 '#title' => t('Title of Gallery2 profile section'),
55 '#default_value' => variable_get('gallery_user_profile_title', 'Gallery2'),
56 '#size' => 40,
57 '#maxlength' => 255,
58 '#description' => t('Title of the Gallery2 section on profile pages.')
59 );
60
61 $form['user']['profile']['gallery_user_profile_hide_sync'] = array(
62 '#type' => 'checkbox',
63 '#title' => t('Hide sync status message'),
64 '#default_value' => variable_get('gallery_user_profile_hide_sync', 0),
65 '#description' => t('Hide \'Gallery2-Drupal Sync Status\' message in the profile.'),
66 );
67
68 $gallery_mode = variable_get('gallery_user_profile_gallery', array('link'));
69 $form['user']['profile']['gallery_user_profile_gallery'] = array(
70 '#type' => 'checkboxes',
71 '#title' => t('Useralbum mode'),
72 '#default_value' => $gallery_mode,
73 '#options' => array(
74 'link' => t('Show link to useralbum'),
75 'gallery' => t('Show useralbum gallery/images')
76 ),
77 '#description' => t('By default a link to the useralbum is shown. But you may also insert a gallery of
78 random/recent images from the useralbum into the user profile.'),
79 );
80 $form['array_filter'] = array('#type' => 'value');
81 // Useralbum settings
82 if (in_array('gallery', $gallery_mode)) {
83 $form['user']['profile'][] = _gallery_profile_useralbum_settings();
84 }
85 }
86 }
87
88 /**
89 * Function _gallery_profile_useralbum_settings().
90 */
91 function _gallery_profile_useralbum_settings() {
92 require_once(drupal_get_path('module', 'gallery') .'/gallery_block.inc');
93
94 $plugin_status = gallery_plugin_status(array('imageblock', 'imageframe'));
95
96 $form['useralbum'] = array(
97 '#type' => 'fieldset',
98 '#title' => t('Useralbum'),
99 '#collapsible' => TRUE,
100 '#collapsed' => TRUE,
101 '#description' => t('The profile useralbum requires the Gallery2 Image Block plugin (!imageblock_status)
102 and optionally the Gallery2 Image Frame plugin (!imageframe_status).', array(
103 '!imageblock_status' => theme('gallery_plugin_status_message', $plugin_status['imageblock']),
104 '!imageframe_status' => theme('gallery_plugin_status_message', $plugin_status['imageframe'])
105 ))
106 );
107 if ($plugin_status['imageblock'] != GALLERY_PLUGIN_ENABLED) {
108 $form['useralbum']['#description'] .= t(' However the Image Block plugin is unavailable.');
109 return $form;
110 }
111
112 _gallery_block_options($type_map, $param_map);
113 $type_map = array(
114 'randomImage' => t('Random image'),
115 'recentImage' => t('Recent image')
116 );
117
118 $form['useralbum']['gallery_user_profile_useralbum_num_cols'] = array(
119 '#type' => 'select',
120 '#title' => t('Number of columns'),
121 '#default_value' => variable_get('gallery_user_profile_useralbum_num_cols', 2),
122 '#options' => _gallery_range_array(1, 5),
123 '#description' => t('Enter the number of columns in the useralbum.'),
124 );
125
126 $form['useralbum']['gallery_user_profile_useralbum_num_rows'] = array(
127 '#type' => 'select',
128 '#title' => t('Number of rows'),
129 '#default_value' => variable_get('gallery_user_profile_useralbum_num_rows', 2),
130 '#options' => _gallery_range_array(1, 5),
131 '#description' => t('Enter the number of rows in the useralbum.'),
132 );
133
134 $form['useralbum']['gallery_user_profile_useralbum_block_block'] = array(
135 '#type' => 'select',
136 '#title' => 'Image types',
137 '#default_value' => variable_get('gallery_user_profile_useralbum_block_block', 'randomImage'),
138 '#options' => $type_map,
139 '#description' => 'Pick the type of images you would like to see in the useralbum.',
140 );
141
142 $form['useralbum']['gallery_user_profile_useralbum_block_show'] = array(
143 '#type' => 'checkboxes',
144 '#title' => t('Image data'),
145 '#default_value' => variable_get('gallery_user_profile_useralbum_block_show', array()),
146 '#options' => $param_map,
147 '#description' => t('Choose the item metadata you would like to display.'),
148 );
149
150 $form['useralbum']['gallery_user_profile_useralbum_size_method'] = array(
151 '#type' => 'select',
152 '#title' => t('Image size method'),
153 '#default_value' => variable_get('gallery_user_profile_useralbum_size_method', GALLERY_GRID_SIZE_METHOD_DEFAULT),
154 '#options' => array(
155 'maxsize' => t('Max Size'),
156 'exactsize' => t('Exact Size'),
157 ),
158 '#description' => t('\'Max Size\' gives faster image downloading, but the image size
159 may be smaller than the size defined below. <br />\'Exact Size\' may be slower
160 (as a larger image is downloaded and then scaled by the browser) but the image
161 will be guaranteed to be the size defined below. Only supported for G2.2+.'),
162 );
163
164 $form['useralbum']['gallery_user_profile_useralbum_size'] = array(
165 '#type' => 'textfield',
166 '#title' => t('Image size'),
167 '#default_value' => variable_get('gallery_user_profile_useralbum_size', GALLERY_GRID_SIZE_DEFAULT),
168 '#size' => 10,
169 '#maxlength' => 10,
170 '#description' => t('Sets the size (in pixels) of the longest side of the image according
171 to the method defined above.'),
172 );
173
174 $imageframe_desc = ($plugin_status['imageframe'] != GALLERY_PLUGIN_ENABLED) ?
175 t('Requires the Gallery2 Image Frame plugin (!imageframe_status).',
176 array('!imageframe_status' => theme('gallery_plugin_status_message', $plugin_status['imageframe']))) : '';
177
178 $image_frames = gallery_get_image_frames();
179
180 $form['useralbum']['gallery_user_profile_useralbum_album_frame'] = array(
181 '#type' => 'select',
182 '#title' => t('Album frame'),
183 '#default_value' => variable_get('gallery_user_profile_useralbum_album_frame', 'none'),
184 '#options' => $image_frames,
185 '#description' => $imageframe_desc,
186 );
187
188 $form['useralbum']['gallery_user_profile_useralbum_item_frame'] = array(
189 '#type' => 'select',
190 '#title' => t('Item frame'),
191 '#default_value' => variable_get('gallery_user_profile_useralbum_item_frame', 'none'),
192 '#options' => $image_frames,
193 '#description' => $imageframe_desc,
194 );
195
196 $form['useralbum']['gallery_user_profile_useralbum_link_target'] = array(
197 '#type' => 'textfield',
198 '#title' => t('Link target'),
199 '#default_value' => variable_get('gallery_user_profile_useralbum_link_target', ''),
200 '#size' => 20,
201 '#maxlength' => 20,
202 '#description' => t('Enter a link target (e.g. \'_blank\' to open in a new window).'),
203 );
204
205 $form['useralbum']['gallery_user_profile_useralbum_link'] = array(
206 '#type' => 'textfield',
207 '#title' => t('Image Link'),
208 '#default_value' => variable_get('gallery_user_profile_useralbum_link', ''),
209 '#size' => 60,
210 '#maxlength' => 255,
211 '#description' => t('By default the image has a link to the item in the Gallery. This
212 can be overridden here (or leave empty for the default). Use \'none\' for no link, or a URL
213 to link somewhere else instead.'),
214 );
215
216 return $form;
217 }
218
219 /**
220 * Function _gallery_profile_useralbum().
221 */
222 function _gallery_profile_useralbum($uid) {
223 $num_cols = variable_get('gallery_user_profile_useralbum_num_cols', 2);
224 $num_rows = variable_get('gallery_user_profile_useralbum_num_rows', 2);
225 $num_images = $num_cols * $num_rows;
226
227 $param_blocks_array = array_fill(0, $num_images, variable_get('gallery_user_profile_useralbum_block_block', 'randomImage'));
228 $params['blocks'] = is_array($param_blocks_array) ? implode('|', $param_blocks_array) : '';
229 $params['itemId'] = 'user:'. $uid;
230 $param_show_array = variable_get('gallery_user_profile_useralbum_block_show', array());
231 $params['show'] = is_array($param_show_array) ? implode('|', $param_show_array) : '';
232 if (variable_get('gallery_user_profile_useralbum_size_method', GALLERY_GRID_SIZE_METHOD_DEFAULT) == 'maxsize') {
233 $params['maxSize'] = variable_get('gallery_user_profile_useralbum_size', GALLERY_GRID_SIZE_DEFAULT);
234 }
235 else {
236 $params['exactSize'] = variable_get('gallery_user_profile_useralbum_size', GALLERY_GRID_SIZE_DEFAULT);
237 }
238 $params['albumFrame'] = variable_get('gallery_user_profile_useralbum_album_frame', 'none');
239 $params['itemFrame'] = variable_get('gallery_user_profile_useralbum_item_frame', 'none');
240 $params['linkTarget'] = variable_get('gallery_user_profile_useralbum_link_target', '');
241 $params['link'] = variable_get('gallery_user_profile_useralbum_link', '');
242
243 $block = gallery_get_block($params, 'ImageBlock', array('num_cols' => $num_cols));
244 return $block['content'];
245 }

  ViewVC Help
Powered by ViewVC 1.1.2