function flickr_block_configure in Flickr 7
Implements hook_block_configure().
File
- block/
flickr_block.module, line 62 - The Flickr block module
Code
function flickr_block_configure($delta = '') {
// Remove the large and original sizes.
$size_options = array();
foreach (flickr_photo_sizes() as $size => $info) {
$size_options[$size] = $info['label'] . ' - ' . $info['description'];
}
unset($size_options['k']);
unset($size_options['o']);
// Define all of the form element variables and retrieve existing values.
$settings = variable_get('flickr_block_' . $delta, array(
'user_id' => '',
'group_id' => '',
'photoset_id' => '',
'show_n' => variable_get('flickr_photos_per_page', 6),
'size' => variable_get('flickr_default_size_album', 's'),
'tag' => '',
'sort' => 'unsorted',
'filter' => '',
'media' => 'photos',
'vocab' => '',
'geo' => '',
'date' => '',
'extend' => variable_get('flickr_extend', 1),
'tag_mode' => 'context',
'min_title' => variable_get('flickr_title_suppress_on_small', '100'),
'min_metadata' => variable_get('flickr_metadata_suppress_on_small', '150'),
));
if (!isset($settings['show_n'])) {
$settings['show_n'] = variable_get('flickr_photos_per_page', 6);
}
if (!isset($settings['size'])) {
$settings['size'] = variable_get('flickr_default_size_album', 's');
}
if (!isset($settings['tag'])) {
$settings['tag'] = '';
}
if (!isset($settings['group_id'])) {
$settings['group_id'] = '';
}
if (!isset($settings['photoset_id'])) {
$settings['photoset_id'] = '';
}
if (!isset($settings['sort'])) {
$settings['sort'] = 'unsorted';
}
if (!isset($settings['filter'])) {
$settings['filter'] = '';
}
if (!isset($settings['media'])) {
$settings['media'] = 'photos';
}
if (!isset($settings['vocab'])) {
$settings['vocab'] = '';
}
if (!isset($settings['geo'])) {
$settings['geo'] = '';
}
if (!isset($settings['date'])) {
$settings['date'] = '';
}
if (!isset($settings['extend'])) {
$settings['extend'] = variable_get('flickr_extend', 1);
}
if (!isset($settings['tag_mode'])) {
$settings['tag_mode'] = 'context';
}
if (!isset($settings['min_title'])) {
$settings['min_title'] = variable_get('flickr_title_suppress_on_small', '100');
}
if (!isset($settings['min_metadata'])) {
$settings['min_metadata'] = variable_get('flickr_metadata_suppress_on_small', '150');
}
// Define all elements of the block parameters form.
$form = array();
$default_userid = variable_get('flickr_default_userid', '');
$user_id = array_key_exists('user_id', $settings) ? $settings['user_id'] : '';
$default = $user_id;
if (isset($settings['user_id'])) {
if (!empty($default) && $settings['user_id'] != 'public') {
$info = flickr_people_getinfo($default);
$default = $info['username']['_content'];
}
else {
$default = $settings['user_id'];
}
}
// Require a user id if the site-wide default user has not been set.
if (empty($default_userid)) {
$form["flickr_block_{$delta}_user_id"] = array(
'#type' => 'textfield',
'#title' => t('Flickr User ID'),
'#default_value' => $default,
'#required' => TRUE,
'#description' => t("A Flickr user ID (number@number, alias, username or email). Note that the sites's default Flickr user ID has not been set."),
'#element_validate' => array(
'flickr_userid_block_validate',
),
);
}
else {
$info = flickr_people_getinfo(variable_get('flickr_default_userid', ''));
$form["flickr_block_{$delta}_user_id"] = array(
'#type' => 'textfield',
'#title' => t('Flickr User ID'),
'#default_value' => $default,
'#description' => t("A Flickr user ID (number@number, alias, username or email). If this is left blank, the sites's default user will be used. The current default Flickr user is") . " '<em>" . $info['username']['_content'] . "</em>'.",
'#element_validate' => array(
'flickr_userid_block_validate',
),
);
}
$idgettr = l(t('Find your Flickr group ID.'), 'http://idgettr.com/', array(
'attributes' => array(
'title' => t('Use the URL of your group to find the Flickr ID.'),
'target' => '_blank',
),
));
$form["flickr_block_{$delta}_group_id"] = array(
'#type' => 'textfield',
'#title' => t('Flickr group ID'),
'#default_value' => $settings['group_id'],
'#required' => TRUE,
'#description' => t("A numerical ID (number@number) or group path alias. !find_id", array(
'!find_id' => $idgettr,
)),
);
$form["flickr_block_{$delta}_photoset"] = array(
'#type' => 'textfield',
'#title' => t('Flickr photoset ID'),
'#default_value' => $settings['photoset_id'],
'#description' => t("A numerical ID of a Flickr photoset."),
'#required' => TRUE,
);
$form['display_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Display'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['display_settings']["flickr_block_{$delta}_show_n"] = array(
'#type' => 'textfield',
'#title' => t('Show <em>n</em> photos'),
'#required' => TRUE,
'#default_value' => $settings['show_n'],
'#description' => t("The block will display this many photos. Gets ignored for slideshows."),
'#element_validate' => array(
'flickr_shown_block_validate',
),
'#size' => 2,
'#maxlength' => 2,
);
$form['display_settings']["flickr_block_{$delta}_size"] = array(
'#type' => 'select',
'#options' => $size_options,
'#title' => t('Size of photos'),
'#default_value' => $settings['size'],
'#description' => t("Select the size of photos you'd like to display in the block."),
);
// Override default settings to force or suppress the display of the caption
// title and metadata.
$attribution = l(t('proper attribution'), 'https://www.flickr.com/services/developer/attributions/', array(
'attributes' => array(
'title' => t('Flickr: The Flickr Developer Guide - Attributions'),
'target' => '_blank',
),
));
$form['display_settings']["flickr_block_{$delta}_min_title"] = array(
'#type' => 'textfield',
'#title' => t('Minimum image width to display a title caption'),
'#required' => TRUE,
'#default_value' => $settings['min_title'],
'#description' => t("Small images have liitle space for a title caption. Replace it with the text 'Flickr' that links to the photo page on Flickr to comply with their <a href='https://www.flickr.com/guidelines.gne' title='Flickr Community Guidelines' target='_blank'>Guidelines</a>.<br />Set it to '0 px' to always include or '999 px' to always exclude. To give !attribution this should be included (space allowing). After saving the configuration <a href='?q=admin/config/development/performance'>clear the cache</a>.", array(
'!attribution' => $attribution,
)),
'#element_validate' => array(
'flickr_title_block_validate',
),
'#field_suffix' => t('px'),
'#size' => 3,
'#maxlength' => 3,
);
$form['display_settings']["flickr_block_{$delta}_min_metadata"] = array(
'#type' => 'textfield',
'#title' => t('Minimum image width to display date, location, photographer and optionally license info under the caption'),
'#required' => TRUE,
'#default_value' => $settings['min_metadata'],
'#description' => t("Suppress extra info on small images. Set it to '0 px' to always include or '999 px' to always exclude. To give !attribution this should be included (space allowing). After saving the configuration <a href='?q=admin/config/development/performance'>clear the cache</a>.", array(
'!attribution' => $attribution,
)),
'#element_validate' => array(
'flickr_metadata_block_validate',
),
'#field_suffix' => t('px'),
'#size' => 3,
'#maxlength' => 3,
);
$form['filter_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Filter / Sort order'),
'#description' => t("The filters/sort order below get ignored for slideshows (always newest first)."),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['filter_settings']["flickr_block_{$delta}_sort"] = array(
'#type' => 'select',
'#options' => array(
'unsorted' => t('Unsorted, as delivered by the Flickr API (fastest response)'),
'random' => t('Random (slower response after cache clear)'),
'date-taken-desc' => t('Latest taken (newest first)'),
'date-posted-desc' => t('Latest posted (newest first)'),
'id' => t('Descending on photo ID (an alternative newest first)'),
'views' => t('Number of photo views on Flickr (popularity, slower response after cache clear)'),
),
'#title' => t('Sort order'),
'#default_value' => $settings['sort'],
'#description' => t("Gets ignored for slideshows (always newest first)."),
);
$form['filter_settings']["flickr_block_{$delta}_filter"] = array(
'#type' => 'select',
'#options' => array(
'' => t('Nothing'),
'interestingness-desc' => t("Interestingness (Flickr's own algorithm)"),
'relevance' => t('Relevancy (most useful for public photos filtered on tags)'),
),
'#title' => t('Interestingness / relevancy'),
'#default_value' => $settings['filter'],
);
$form['filter_settings']["flickr_block_{$delta}_media"] = array(
'#type' => 'select',
'#options' => array(
'all' => t('all'),
'photos' => t('photos'),
'videos' => t('videos'),
),
'#title' => t('Media type'),
'#default_value' => $settings['media'],
);
if (function_exists('taxonomy_get_vocabularies')) {
// Get a list of existing vocabularies.
$vocabulary = taxonomy_get_vocabularies();
$checklist_vocab_array = array(
'0' => '<none>',
);
foreach ($vocabulary as $item) {
$key = $item->vid;
$value = $item->name;
$checklist_vocab_array[$key] = $value;
}
$form['filter_settings']["flickr_block_{$delta}_vocab"] = array(
'#type' => 'select',
'#title' => t('Flickr tags as node taxonomy terms (choose a vocabulary to use)'),
'#position' => 'left',
'#options' => $checklist_vocab_array,
'#default_value' => $settings['vocab'],
'#description' => t("Limit the Flickr images to those that have a Flickr tag identical to the terms found for the node on the page the block is displayed on of a specific vocabulary. Case insensitive, matches any tag, for photosets even partial. Multiple tags for groups will only query the last 500 photos on Flickr (slowest API request). For user blocks the Flickr account of the node author will be queried. Remember that Flickr removes spaces from multi word tags (e.g. 'beach trip' becomes 'beachtrip'). Use taxonomy terms without spaces in the vocabulary dedicated to Flickr.<br />For your content type, adjust the <em>Help text</em> of the used taxonomy field accordingly (e.g. at <em>admin/structure/types/manage/article/fields/field_tags</em>). The recommended widget type is <em>Autocomplete term widget (tagging)</em> with an <em>unlimited number of values</em>. If not already in use, the default existing vocabulary <em>Tags</em> can be used which is already configured right by default. Set <em>Tags</em> as a <em>Term reference</em> field on your content type and it works out-of-the-box.<br />If not on a node page, all photos will be displayed. To avoid this set the visibility settings below to <em>Only the listed pages</em> specified as <em>node/*</em>.<br />Note that if you add this <em>term reference</em> field to user profiles at <em>admin/config/people/accounts/fields</em> it will filter additionally on it for user blocks. E.g. a user can set individually that from their account only photos tagged <em>'website'</em> should be used to embed, indepedent from other used tags. Does apply only on user blocks, except for favorites."),
);
if ($delta < 7 || $delta == 10 || $delta == 11) {
$form['filter_settings']["flickr_block_{$delta}_extend"] = array(
'#type' => 'checkbox',
'#title' => t("Extend to search for matching terms also in the Flickr photo title and description besides Flickr tags. This limits the tag mode below to 'any' (OR)."),
'#default_value' => $settings['extend'],
'#description' => t("Shows more results if true."),
);
}
else {
$form['filter_settings']["flickr_block_{$delta}_extend"] = array(
'#type' => 'checkbox',
'#title' => t("Extend to search for matching terms also in the Flickr photo title (not the description) besides Flickr tags."),
'#default_value' => $settings['extend'],
'#description' => t("Shows more results if true."),
);
}
// Limit the tag mode to 'OR' for extended searches.
if ($settings['extend']) {
$form['filter_settings']["flickr_block_{$delta}_tag_mode"] = array(
'#type' => 'radios',
'#title' => t("Tag mode"),
'#options' => array(
'any' => t("Any (OR)"),
'all' => '<span class="grayed-out">' . t("All (AND)") . '</span>',
'context' => '<span class="grayed-out">' . t("All (AND) for public searches, any (OR) if a Flickr user ID is known.") . '</span>',
),
'#default_value' => 'any',
'#description' => t("Forced to 'any' (OR) for extended searches. Unselect the checkbox above ('Extend') and save if you want to use this option."),
);
// Disable specific options.
// See https://www.drupal.org/node/342316#comment-4732130.
$form['filter_settings']["flickr_block_{$delta}_tag_mode"]['all'] = array(
'#disabled' => TRUE,
);
$form['filter_settings']["flickr_block_{$delta}_tag_mode"]['context'] = array(
'#disabled' => TRUE,
);
}
else {
$form['filter_settings']["flickr_block_{$delta}_tag_mode"] = array(
'#type' => 'radios',
'#title' => t("Tag mode"),
'#options' => array(
'any' => t("Any (OR)"),
'all' => t("All (AND)"),
'context' => t("All (AND) for public searches, any (OR) if a Flickr user ID is known."),
),
'#default_value' => $settings['tag_mode'],
'#description' => t("Either 'any' for an OR operator between tags, 'all' for an AND operator or depending on the context."),
);
}
}
if (module_exists('geofield') || module_exists('location_node')) {
// Get a list of existing geofields.
$fields = field_read_fields(array(
'type' => 'geofield',
));
$checklist_fields_array = array(
'0' => '<none>',
);
if (module_exists('location_node')) {
$checklist_fields_array = array(
'0' => '<none>',
'1' => 'Location module',
);
}
foreach ($fields as $item) {
$key = $item['field_name'];
$value = $item['field_name'];
$checklist_fields_array[$key] = $value;
}
$form['filter_settings']["flickr_block_{$delta}_geo"] = array(
'#type' => 'select',
'#title' => t('Location or geofield (choose a field machine name to use)'),
'#position' => 'left',
'#options' => $checklist_fields_array,
'#default_value' => $settings['geo'],
'#description' => t("Limit the Flickr images to those that have a geo location near to the geofield found for the node on the page the block is displayed on.<br />If not on a node page, all photos will be displayed. To avoid this set the visibility settings below to <em>Only the listed pages</em> specified as <em>node/*</em>."),
);
}
if (module_exists('date')) {
// Get a list of existing date ields.
$fields = field_read_fields(array(
'type' => 'datetime',
));
$checklist_fields_array = array(
'0' => '<none>',
);
foreach ($fields as $item) {
$key = $item['field_name'];
$value = $item['field_name'];
$checklist_fields_array[$key] = $value;
}
$form['filter_settings']["flickr_block_{$delta}_date"] = array(
'#type' => 'select',
'#title' => t('Date field (choose a field machine name to use)'),
'#position' => 'left',
'#options' => $checklist_fields_array,
'#default_value' => $settings['date'],
'#description' => t("Limit the Flickr images to those that are taken on or between the dates attached to the node on the page the block is displayed on.<br />If not on a node page, all photos will be displayed. To avoid this set the visibility settings below to <em>Only the listed pages</em> specified as <em>node/*</em>."),
);
}
// A note for dynamic user blocks.
$form["flickr_block_note"] = array(
'#markup' => t("<h3>NOTE</h3><strong>The block visibility setting for 'user' (node author) blocks are not only restricted in the block configuration but also by the Flickr Block module.</strong> The block only gets displayed on user and node pages. Below you can change the block settings to exclude 'user/*' pages or show them only on 'node/*' pages or the other way around. Fine-grain even more by selecting a content type, for example blog posts."),
'#weight' => 10,
);
// Build the block form - use unset to hide unwanted form elements.
switch ($delta) {
// User recent Flickr photosets.
case 1:
unset($form["flickr_block_{$delta}_user_id"]);
unset($form["flickr_block_{$delta}_group_id"]);
unset($form["flickr_block_{$delta}_photoset"]);
unset($form['filter_settings']["flickr_block_{$delta}_sort"]);
unset($form['filter_settings']["flickr_block_{$delta}_filter"]);
if (module_exists('taxonomy')) {
unset($form['filter_settings']["flickr_block_{$delta}_vocab"]);
unset($form['filter_settings']["flickr_block_{$delta}_extend"]);
unset($form['filter_settings']["flickr_block_{$delta}_tag_mode"]);
}
if (module_exists('geofield') || module_exists('location_node')) {
unset($form['filter_settings']["flickr_block_{$delta}_geo"]);
}
if (module_exists('date')) {
unset($form['filter_settings']["flickr_block_{$delta}_date"]);
}
if (module_exists('date')) {
unset($form['filter_settings']["flickr_block_{$delta}_date"]);
}
// Photoset, not photos.
$form["flickr_block_{$delta}_show_n"]['#title'] = t('Show the last <em>n</em> photosets');
$form["flickr_block_{$delta}_show_n"]['#description'] = t("The block will show this many of the user's photosets.");
break;
// User Flickr photos.
case 0:
case 2:
unset($form["flickr_block_{$delta}_user_id"]);
unset($form["flickr_block_{$delta}_group_id"]);
unset($form["flickr_block_{$delta}_photoset"]);
break;
// User favorite Flickr photos.
case 13:
case 14:
// User gallery Flickr photos.
case 15:
case 16:
unset($form["flickr_block_{$delta}_user_id"]);
unset($form["flickr_block_{$delta}_group_id"]);
unset($form["flickr_block_{$delta}_photoset"]);
unset($form['filter_settings']["flickr_block_{$delta}_filter"]);
if (module_exists('taxonomy')) {
unset($form['filter_settings']["flickr_block_{$delta}_tag_mode"]);
}
if (module_exists('geofield') || module_exists('location_node')) {
unset($form['filter_settings']["flickr_block_{$delta}_geo"]);
}
if (module_exists('date')) {
unset($form['filter_settings']["flickr_block_{$delta}_date"]);
}
break;
// Photos from a Flickr user.
case 3:
case 5:
unset($form["flickr_block_{$delta}_group_id"]);
unset($form["flickr_block_{$delta}_photoset"]);
unset($form['flickr_block_note']);
if (empty($default_userid)) {
$form["flickr_block_{$delta}_user_id"]['#description'] = t("A Flickr user ID (number@number, alias, username or email). Leave empty or use the keyword <em>public</em> to grab CC licensed Public photos.");
}
else {
$config = l(t('Flickr settings'), 'admin/config/media/flickr/', array(
'attributes' => array(
'title' => t('Go to Flickr configuration page'),
),
));
$form["flickr_block_{$delta}_user_id"]['#description'] = t("A Flickr user ID (number@number, alias, username or email). If empty, the sites's current default user !username will be used. Use the keyword <em>public</em> to grab CC licensed public photos.", array(
'!username' => '<em>' . $info['username']['_content'] . '</em>',
));
}
$form["flickr_block_{$delta}_user_id"]['#required'] = FALSE;
break;
// Favorite public photos from a Flickr user.
case 9:
case 12:
unset($form["flickr_block_{$delta}_group_id"]);
unset($form["flickr_block_{$delta}_photoset"]);
unset($form['flickr_block_note']);
unset($form['filter_settings']["flickr_block_{$delta}_filter"]);
if (module_exists('taxonomy')) {
unset($form['filter_settings']["flickr_block_{$delta}_tag_mode"]);
}
if (module_exists('geofield') || module_exists('location_node')) {
unset($form['filter_settings']["flickr_block_{$delta}_geo"]);
}
if (module_exists('date')) {
unset($form['filter_settings']["flickr_block_{$delta}_date"]);
}
break;
// Recent photosets from a Flickr user.
case 4:
unset($form["flickr_block_{$delta}_group_id"]);
unset($form["flickr_block_{$delta}_photoset"]);
unset($form['flickr_block_note']);
unset($form['filter_settings']["flickr_block_{$delta}_sort"]);
unset($form['filter_settings']["flickr_block_{$delta}_filter"]);
if (module_exists('taxonomy')) {
unset($form['filter_settings']["flickr_block_{$delta}_vocab"]);
unset($form['filter_settings']["flickr_block_{$delta}_extend"]);
unset($form['filter_settings']["flickr_block_{$delta}_tag_mode"]);
}
if (module_exists('geofield') || module_exists('location_node')) {
unset($form['filter_settings']["flickr_block_{$delta}_geo"]);
}
if (module_exists('date')) {
unset($form['filter_settings']["flickr_block_{$delta}_date"]);
}
// Photosets, not photos.
$form["flickr_block_{$delta}_show_n"]['#title'] = t('Show the last <em>n</em> photosets');
$form["flickr_block_{$delta}_show_n"]['#description'] = t("The block will show this many of the user's photosets.");
break;
// Photos from a Flickr group.
case 6:
case 10:
unset($form["flickr_block_{$delta}_user_id"]);
unset($form["flickr_block_{$delta}_photoset"]);
unset($form['flickr_block_note']);
$form['filter_settings']["flickr_block_{$delta}_sort"]['#options'] = array(
'unsorted' => t('Recent unsorted, as delivered by the Flickr API (fastest response)'),
'random' => t('Random (slower response after cache clear)'),
'date-taken-desc' => t('Latest taken (newest first)'),
'date-posted-desc' => t('Latest posted (newest first)'),
'added' => t('Latest added to group (newest first)'),
'id' => t('Descending on photo ID (an alternative newest first)'),
'views' => t('Number of photo views on Flickr (popularity, slower response after cache clear)'),
);
break;
// Photos from a Flickr photoset.
case 7:
case 8:
unset($form["flickr_block_{$delta}_user_id"]);
unset($form["flickr_block_{$delta}_group_id"]);
unset($form['flickr_block_note']);
unset($form['filter_settings']["flickr_block_{$delta}_filter"]);
if (module_exists('taxonomy')) {
unset($form['filter_settings']["flickr_block_{$delta}_tag_mode"]);
}
if (module_exists('geofield') || module_exists('location_node')) {
unset($form['filter_settings']["flickr_block_{$delta}_geo"]);
}
if (module_exists('date')) {
unset($form['filter_settings']["flickr_block_{$delta}_date"]);
}
break;
// Photos with a specific tag from a Flickr user.
case 11:
unset($form["flickr_block_{$delta}_group_id"]);
unset($form["flickr_block_{$delta}_photoset"]);
unset($form['flickr_block_note']);
if (module_exists('taxonomy')) {
unset($form['filter_settings']["flickr_block_{$delta}_vocab"]);
}
if (module_exists('geofield') || module_exists('location_node')) {
unset($form['filter_settings']["flickr_block_{$delta}_geo"]);
}
if (module_exists('date')) {
unset($form['filter_settings']["flickr_block_{$delta}_date"]);
}
if (empty($default_userid)) {
$form["flickr_block_{$delta}_user_id"]['#description'] = t("A Flickr user ID (number@number, alias, username or email). Leave empty or use the keyword <em>public</em> to grab CC licensed Public photos.");
}
else {
$config = l(t('Flickr settings'), 'admin/config/media/flickr/', array(
'attributes' => array(
'title' => t('Go to Flickr configuration page'),
),
));
$form["flickr_block_{$delta}_user_id"]['#description'] = t("A Flickr user ID (number@number, alias, username or email). If empty, the sites's current default user !username will be used. Use the keyword <em>public</em> to grab CC licensed public photos.", array(
'!username' => '<em>' . $info['username']['_content'] . '</em>',
));
}
$form["flickr_block_{$delta}_user_id"]['#required'] = FALSE;
$form["flickr_block_{$delta}_tag"] = array(
'#type' => 'textfield',
'#title' => t('Show photos having this tag'),
'#default_value' => $settings['tag'],
'#description' => t("Comma seperated tags for which you want media to display. Case insensitive. Matches any tag for a specific user or all tags for public photos. You can exclude results that match a term by prepending it with a - character.<br />Remember that Flickr removes spaces from multi word tags (e.g. 'beach trip' becomes 'beachtrip')."),
'#required' => TRUE,
);
break;
}
return $form;
}