juicerio.module in Juicer - Social Media Feed Aggregator 7
Same filename and directory in other branches
Module file for the Juicer Integration module.
File
juicerio.moduleView source
<?php
/**
* @file
* Module file for the Juicer Integration module.
*/
/**
* Implements hook_permission();
*/
function juicerio_permission() {
return array(
'administer juicer' => array(
'title' => t('Administer Juicer'),
'description' => t('Administer Juicer IO social media feed.'),
),
);
}
/**
* Implements hook_menu();
*/
function juicerio_menu() {
$items['admin/config/services/juicerio'] = array(
'title' => 'Juicer settings',
'description' => 'Juicer IO social media feed settings.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'juicerio_settings_form',
),
'access arguments' => array(
'administer juicer',
),
'file' => 'juicerio.admin.inc',
);
return $items;
}
/**
* Implements hook_theme().
*/
function juicerio_theme($existing, $type, $theme, $path) {
return array(
'juicerio_feed' => array(
'variables' => array(
'feed_id' => NULL,
'post_num' => NULL,
'infinite_pages' => NULL,
'gutter_amt' => NULL,
'column_num' => NULL,
'filters' => NULL,
),
),
);
}
function theme_juicerio_feed($variables) {
if ($variables['feed_id'] != NULL) {
// Add in the Juicer IO Javascript and CSS files
$js_embed = variable_get('juicerio_js_embed', '//assets.juicer.io/embed-no-jquery.js');
drupal_add_js($js_embed, array(
'type' => 'external',
));
drupal_add_css('//assets.juicer.io/embed.css', 'external');
// Prepare all the attributes.
$attributes = 'data-feed-id="' . $variables['feed_id'] . '"';
if ($variables['post_num'] != NULL) {
$attributes .= ' data-per="' . $variables['post_num'] . '"';
}
if ($variables['infinite_pages'] != NULL) {
$attributes .= ' data-pages="' . $variables['infinite_pages'] . '"';
}
if ($variables['gutter_amt'] != NULL) {
$attributes .= ' data-gutter="' . $variables['gutter_amt'] . '"';
}
if ($variables['column_num'] != NULL) {
$attributes .= ' data-columns="' . $variables['column_num'] . '"';
}
if ($variables['filters'] != NULL) {
$attributes .= ' data-filter="' . $variables['filters'] . '"';
}
// Assemble the output.
$output = '<ul class="juicer-feed" ' . $attributes . '></ul>';
}
else {
$output = t('Please !configure to see a social media feed.', array(
'!configure' => l(t('provide a Juicer account name'), 'admin/config/services/juicerio'),
));
}
return $output;
}
/**
* Implements hook_block_info().
*/
function juicerio_block_info() {
$count = variable_get('juicerio_blocks', 1);
for ($delta = 1; $delta <= $count; $delta++) {
$info = t('Juicer Embed Feed');
if ($delta > 1) {
$info .= ' ' . $delta;
}
$blocks['juicerio_' . $delta] = array(
'info' => $info,
'cache' => DRUPAL_NO_CACHE,
);
}
return $blocks;
}
/**
* Implements hook_block_view().
*/
function juicerio_block_view($delta = 1) {
$block = array();
$feed_id = variable_get('juicerio_feed_id');
$count = variable_get('juicerio_blocks', 1);
$infinite = variable_get($delta . '_infinite_pages');
$infinite_pages = $infinite === 0 ? NULL : $infinite;
$variables = array(
'feed_id' => $feed_id,
'post_num' => variable_get($delta . '_post_number'),
'infinite_pages' => $infinite_pages,
'gutter_amt' => variable_get($delta . '_gutter_amt'),
'column_num' => variable_get($delta . '_column_number'),
'filters' => variable_get($delta . '_filter'),
);
$block['subject'] = NULL;
$block['content'] = theme('juicerio_feed', $variables);
return $block;
}
/**
* Implements hook_block_configure().
*/
function juicerio_block_configure($delta = 1) {
$form = array();
$form['juicero'] = array(
'#type' => 'fieldset',
'#title' => t('Juicer feed settings'),
'#collapsible' => TRUE,
);
// Number of posts
$form['juicero'][$delta . '_post_number'] = array(
'#type' => 'select',
'#title' => t('Number of posts'),
'#default_value' => variable_get($delta . '_post_number', NULL),
'#options' => drupal_map_assoc(array(
1,
2,
3,
5,
10,
15,
20,
25,
50,
75,
100,
250,
500,
1000,
)),
'#description' => t('Set the total number of posts shown. Defaults to 100.'),
);
// Infinite scrolling pages
$form['juicero'][$delta . '_infinite_pages'] = array(
'#type' => 'select',
'#title' => t('Number of scrolling pages'),
'#default_value' => variable_get($delta . '_infinite_pages', 0),
'#options' => drupal_map_assoc(array(
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
15,
20,
25,
50,
100,
)),
'#description' => t('Set to 0 your feed will scroll infinitely: more and more posts will keep being added to the feed until all your posts are visible.<br />
If set to 1, only the first page of results will be visible. If set to 2, the feed will scroll just once.'),
);
// Space between posts
$form['juicero'][$delta . '_gutter_amt'] = array(
'#type' => 'textfield',
'#title' => t('Column gutter size'),
'#field_suffix' => t('pixels'),
'#size' => 5,
'#default_value' => variable_get($delta . '_gutter_amt', NULL),
'#description' => t('The column gutter is the horrizontal space between columns of posts. Defaults to 20 pixels.'),
);
// Change number of columns
$form['juicero'][$delta . '_column_number'] = array(
'#type' => 'select',
'#title' => t('Number of columns'),
'#default_value' => variable_get($delta . '_column_number', NULL),
'#options' => drupal_map_assoc(array(
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
)),
'#description' => t("Columns are not allowed to be less than 200px (as it doesn't look good). If the number of columns set here is not respected, increase the size of the containing element."),
);
// Filter the posts based on social account
$form['juicero'][$delta . '_filter'] = array(
'#type' => 'textfield',
'#title' => t('Filter the posts based on social account'),
'#default_value' => variable_get($delta . '_filter', NULL),
'#description' => t('To filter your posts, enter either the capitalized name of the source, or the account name of source source.<br />
Example: If you have an Instagram source of #tbt, enter either <em>tbt</em> or <em>Instagram</em> to only show posts from that source.<br />
Note: If you have multiple Instagram srouces entering <em>Instagram<em> will show posts from all of them.'),
);
return $form;
}
/**
* Implements hook_block_save().
*/
function juicerio_block_save($delta = 1, $edit = array()) {
variable_set($delta . '_post_number', $edit[$delta . '_post_number']);
variable_set($delta . '_infinite_pages', $edit[$delta . '_infinite_pages']);
variable_set($delta . '_gutter_amt', $edit[$delta . '_gutter_amt']);
variable_set($delta . '_column_number', $edit[$delta . '_column_number']);
variable_set($delta . '_filter', $edit[$delta . '_filter']);
}
Functions
Name | Description |
---|---|
juicerio_block_configure | Implements hook_block_configure(). |
juicerio_block_info | Implements hook_block_info(). |
juicerio_block_save | Implements hook_block_save(). |
juicerio_block_view | Implements hook_block_view(). |
juicerio_menu | Implements hook_menu(); |
juicerio_permission | Implements hook_permission(); |
juicerio_theme | Implements hook_theme(). |
theme_juicerio_feed |