This repository was archived by the owner on May 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflickrbrowser.module
More file actions
179 lines (150 loc) · 4.95 KB
/
Copy pathflickrbrowser.module
File metadata and controls
179 lines (150 loc) · 4.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?php
/**
* Implements hook_page_build().
*/
function flickrbrowser_page_build(&$page) {
// Add the api key to the Drupal js settings object.
drupal_add_js(array(
'flickrbrowser' => array(
'api_key' => variable_get('flickr_api_key', array()),
),
), array('type' => 'setting', 'scope' => JS_DEFAULT));
$path = drupal_get_path('module', 'flickrbrowser');
drupal_add_css($path . '/flickrbrowser.css');
drupal_add_js($path . '/flickrbrowser.js');
drupal_add_js($path . '/quickpager.jquery.js');
}
/**
* Implements hook_field_widget_info().
*/
function flickrbrowser_field_widget_info() {
return array(
'flickrbrowser' => array(
'label' => 'Flickr Photo with Browser',
'field types' => array('flickrfield'),
'behaviors' => array(
'multiple values' => FIELD_BEHAVIOR_DEFAULT,
'default value' => FIELD_BEHAVIOR_DEFAULT,
),
),
);
}
/**
* Implements hook_element_info().
*/
function flickrbrowser_element_info() {
return array(
'flickrbrowser' => array(
'#input' => TRUE,
'#columns' => array('type', 'id', 'uid'),
'#process' => array('flickrbrowser_form_process_flickrbrowser'),
),
);
}
/**
* Implements hook_field_widget_form().
*/
function flickrbrowser_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
$element = array(
'#type' => $instance['widget']['type'],
'#default_value' => isset($items[$delta]) ? $items[$delta] : '',
);
return $element;
}
/**
* @todo Please document this function.
* @see http://drupal.org/node/1354
*/
function flickrbrowser_form_process_flickrbrowser($element, $form_state, $form = array()) {
// Load the flickr include file
require_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'flickr') . '/flickr.inc';
// Get the nsid, api key and secret
$nsid = variable_get('flickr_default_userid', '');
// Get all photosets for our nsid
$sets = flickr_photoset_get_list($nsid);
// Set initial photoset array element blank for the select list
$photosets = array('' => '');
// Populate the photoset list with returned values from flickr
foreach ($sets as $set) {
$photosets[$set['id']] = t($set['title']['_content']);
}
// If the photo id is not empty grab the image from flickr
if (!empty($element['#value']['id'])) {
$photoinfo = flickr_photo_get_info($element['#value']['id']);
$photo = flickr_img($photoinfo, 's');
}
// If we do indeed have a photo hide the browser, otherwise hide the remove link
if (isset($photo)) {
$hidebrowser = "hide";
$hideremove = "";
}
else {
$photo = "";
$hidebrowser = "";
$hideremove = "hide";
}
// Manually set the element type and hide it
$element['type'] = array(
'#type' => 'hidden',
'#value' => 'photo_id',
'#default_value' => 'photo_id',
);
// Id value, has attributes and prefix/suffix classes for the images
$element['id'] = array(
'#type' => 'hidden',
'#title' => t('Item id'),
'#default_value' => !empty($element['#value']['id']) ? $element['#value']['id'] : '',
'#prefix' => '<div class="photo-selected">' . $photo . '</div>',
'#suffix' => '<div class="photo-remove ' . $hideremove . '"><a class="remove-selected">Remove</a></div>',
'#attributes' => array('class' => array('flickr-id')),
);
// Set the nsid to the sites default and don't allow it to be changed
$element['nsid'] = array(
'#type' => 'hidden',
'#default_value' => !empty($element['#value']['nsid']) ? $element['#value']['nsid'] : variable_get('flickr_default_userid', ''),
'#value' => !empty($element['#value']['nsid']) ? $element['#value']['nsid'] : variable_get('flickr_default_userid', ''),
);
// Photoset list element
$element['photoset'] = array(
'#type' => 'select',
'#default_value' => t(''),
'#title' => t('Select Photoset'),
'#options' => $photosets,
'#attributes' => array('class' => array('photoset-selector')),
'#prefix' => '<div class="flickrbrowser ' . $hidebrowser . '">',
'#suffix' => '<div class="photo-selector"></div></div>',
);
return $element;
}
/**
* Implements hook_theme().
*/
function flickrbrowser_theme() {
$theme = array(
'flickrbrowser' => array(
'variables' => array('element' => NULL),
'template' => 'flickrbrowser'
),
);
return $theme;
}
/**
* Theme for the form element.
*
* The form is already rendered by the child elements by the time it comes back here,
* just group each delta grouping into its own fieldset.
*/
function theme_flickrbrowser($variables) {
//$test = "TESTING";
$element = $variables['element'];
$field = field_info_field($element['#field_name']);
$fieldset = array(
'#value' => $element['#children'],
'#collapsible' => FALSE,
'#collapsed' => FALSE,
'#description' => $element['#description'],
'#attributes' => array('class' => array('flickrbrowser-wrapper')),
);
return theme('fieldset', $fieldset);
//return $test;
}