View source
<?php
define('SOCIALFEED_INSTAGRAM_GRAPH_URL', 'https://graph.instagram.com/me/media?fields=id,media_type,media_url,username,timestamp,permalink');
function socialfeed_help($path, $arg) {
switch ($path) {
case 'admin/help#socialfeed':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Social Feed module allows you to fetch the feeds directly from Facebook, Twitter & Instagram by simply enabling and configuring its blocks.') . '</p>';
$output .= '<h4>' . t('Instagram') . '</h4>';
$output .= '<p>' . t('To be able to use and search after hashimages on Instagram, you need a Client ID. This simple guide will step by step tell you have to get one.') . '</p>';
$output .= '<strong>' . t('Note: You need to have a Instagram account to be able to get a Client ID.') . '</strong>';
$output .= '<p>' . t('Follow these simple steps to get your own key.') . '</p>';
$output .= '<ol><li>' . t("Login if you aren't.") . '</li><li>' . t('Go to the <a href="@instagram" target="@blank">Instagram Developer Page</a>.', [
'@instagram' => 'https://www.instagram.com/developer/',
'@blank' => '_blank',
]) . '</li><li>' . t('Click on "Register your application".') . '</li><li>' . t("If you don't already have an application registered, you'll now see a form to register a new one. If you instead see a list of 'clients', click the 'Register new client' at the top right.") . '</li><li>' . t('Set application name to your websites name') . '</li><li>' . t('Type in a description, something like "Registering to get a client ID to use in the Social Feed - Drupal Module"') . '</li><li>' . t('Add the url of your site in the two last fields.') . '</li><li>' . t('Add the contact email') . '</li><li>' . t('Hit register.') . '</li><li>' . t('Click "Manage clients" in the top menu and you\'ll now see you new client in the list and a client id, client secret and more.') . '</li>';
return $output;
}
}
function socialfeed_menu() {
$items = [];
$items['admin/config/services/socialfeed'] = [
'title' => 'Social Feed Settings',
'description' => 'Configure to fit clients needs',
'page callback' => 'drupal_get_form',
'page arguments' => [
'socialfeed_facebook_settings',
],
'access arguments' => [
'administer modules',
],
'file' => 'socialfeed.admin.inc',
'type' => MENU_NORMAL_ITEM,
];
$items['admin/config/services/socialfeed/facebook'] = [
'title' => 'Facebook',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => 0,
];
$items['admin/config/services/socialfeed/twitter'] = [
'title' => 'Twitter',
'description' => 'Configure to fit clients needs',
'page arguments' => [
'socialfeed_twitter_settings',
],
'access arguments' => [
'administer modules',
],
'file' => 'socialfeed.admin.inc',
'type' => MENU_LOCAL_TASK,
'weight' => 1,
];
$items['admin/config/services/socialfeed/instagram'] = [
'title' => 'Instagram',
'description' => 'Configure to fit clients needs',
'page arguments' => [
'socialfeed_instagram_settings',
],
'access arguments' => [
'administer modules',
],
'file' => 'socialfeed.admin.inc',
'type' => MENU_LOCAL_TASK,
'weight' => 2,
];
return $items;
}
function socialfeed_theme($existing, $type, $theme, $path) {
return [
'socialfeed_facebook' => [
'variables' => [
'facebook' => NULL,
],
'template' => 'facebook',
'path' => drupal_get_path('module', 'socialfeed') . '/templates',
],
'socialfeed_twitter' => [
'variables' => [
'twitter' => NULL,
],
'template' => 'twitter',
'path' => drupal_get_path('module', 'socialfeed') . '/templates',
],
'socialfeed_instagram' => [
'variables' => [
'instagram' => NULL,
],
'template' => 'instagram',
'path' => drupal_get_path('module', 'socialfeed') . '/templates',
],
];
}
function socialfeed_block_info() {
$blocks = [];
$blocks['facebook_latest_feed'] = [
'info' => t('Social Feed Facebook'),
'cache' => DRUPAL_CACHE_CUSTOM,
];
$blocks['twitter_latest_feed'] = [
'info' => t('Social Feed Twitter'),
'cache' => DRUPAL_CACHE_CUSTOM,
];
$blocks['instagram_latest_feed'] = [
'info' => t('Social Feed Instagram'),
'cache' => DRUPAL_CACHE_CUSTOM,
];
return $blocks;
}
function socialfeed_block_view($delta = '') {
$block = [];
switch ($delta) {
case 'facebook_latest_feed':
module_load_include('inc', 'socialfeed', 'socialfeed.block');
$block['subject'] = '';
$block['content'] = socialfeed_posts_render('facebook');
break;
case 'twitter_latest_feed':
module_load_include('inc', 'socialfeed', 'socialfeed.block');
$block['subject'] = '';
$block['content'] = socialfeed_posts_render('twitter');
break;
case 'instagram_latest_feed':
module_load_include('inc', 'socialfeed', 'socialfeed.block');
$block['subject'] = '';
$block['content'] = socialfeed_posts_render('instagram');
break;
}
return $block;
}