View source
<?php
define('FB_INSTANT_ARTICLES_AD_TYPE_NONE', 'none');
define('FB_INSTANT_ARTICLES_AD_TYPE_FBAN', 'fban');
define('FB_INSTANT_ARTICLES_AD_TYPE_SOURCE_URL', 'source_url');
define('FB_INSTANT_ARTICLES_AD_TYPE_EMBED_CODE', 'embed_code');
function fb_instant_articles_get_ad_types() {
return array(
FB_INSTANT_ARTICLES_AD_TYPE_NONE => t('None'),
FB_INSTANT_ARTICLES_AD_TYPE_FBAN => t('Facebook Audience Network'),
FB_INSTANT_ARTICLES_AD_TYPE_SOURCE_URL => t('Source URL'),
FB_INSTANT_ARTICLES_AD_TYPE_EMBED_CODE => t('Embed Code'),
);
}
function fb_instant_articles_menu() {
$items['admin/config/services/fb-instant-articles'] = array(
'title' => 'Facebook Instant Articles',
'description' => 'Settings related to Facebook Instant Articles.',
'page callback' => 'system_admin_menu_block_page',
'access arguments' => array(
'access administration pages',
),
'file' => 'system.admin.inc',
'file path' => drupal_get_path('module', 'system'),
);
$items['admin/config/services/fb-instant-articles/settings'] = array(
'title' => 'Facebook Instant Articles Base settings',
'description' => 'Base settings for Facebook Instant Articles.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'fb_instant_articles_settings',
),
'access arguments' => array(
'administer fb_instant_articles',
),
'file' => 'includes/admin.inc',
'weight' => -10,
);
return $items;
}
function fb_instant_articles_permission() {
$permissions = array();
$permissions['administer fb_instant_articles'] = array(
'title' => t('Administer Facebook Instant Articles'),
);
return $permissions;
}
function fb_instant_articles_help($path, $arg) {
switch ($path) {
case 'admin/help#fb_instant_articles':
$filepath = dirname(__FILE__) . '/README.md';
if (file_exists($filepath)) {
$string = file_get_contents($filepath);
if ($processed = fb_instant_articles_help_markdown($string)) {
return $processed;
}
return '<pre>' . $string . '</pre>';
}
break;
case 'admin/config/services/fb-instant-articles':
case 'admin/config/services/fb-instant-articles/settings':
$page_id = variable_get('fb_instant_articles_page_id', '');
$output = '';
$output .= '<h2>' . t('Setup') . '</h2>';
$output .= '<p>' . t('Once you\'ve activated this Drupal module, set up your Instant Articles and submit them to Facebook for a one-time review. The review is required before you can begin publishing. Follow these steps to get started:') . '</p>';
$output .= '<ol>';
$output .= ' <li>' . t('<a href="@sign_up_url" target="_blank">Sign up</a> for Instant Articles, if you haven\'t already, and enabled the same Facebook Page you have selected.', array(
'@sign_up_url' => 'https://www.facebook.com/instant_articles/signup',
)) . '</li>';
$output .= ' <li>' . t('Claim the URL you will use to publish articles.</b> Right now, we think the URL for this page is: %url. ', array(
'%url' => $_SERVER['HTTP_HOST'],
));
if ($page_id != '') {
$claim_url = 'https://www.facebook.com/' . $page_id . '/settings/?tab=instant_articles#URL';
$output .= t('<a href="@claim_url" target="_blank">Claim your URL here.</a>', array(
'@claim_url' => $claim_url,
));
}
$output .= '</li>';
$output .= ' <li>' . t('Install the Pages Manager App to preview your articles and styles on <a href="@ios_url" target="_blank">iOS</a> or <a href="@android_url" target="_blank">Android</a>.', array(
'@ios_url' => 'http://itunes.apple.com/app/facebook-pages-manager/id514643583?ls=1&mt=8&ign-mscache=1',
'@android_url' => 'https://play.google.com/store/apps/details?id=com.facebook.pages.app',
)) . '</li>';
$output .= ' <li>' . t('Create a style template for your articles using the <a href="@style_url" target="_blank">Style Editor</a>. Be sure to provide the name of the template you want to use in the Module Configuration settings below.', array(
'@style_url' => 'https://developers.facebook.com/docs/instant-articles/guides/design#style',
)) . '</li>';
$output .= ' <li>' . t('[Optional] Enable Audience Network, if you choose. Learn more about <a href="@audience_url" target="_blank">Audience Network</a> for Instant Articles and <a href="@sign_up_url" target="_blank">sign up here</a>.', array(
'@audience_url' => 'https://fbinstantarticles.files.wordpress.com/2016/03/audience-network_wp_instant-articles-2-2-web_self-serve.pdf',
'@sign_up_url' => '',
)) . '</li>';
$output .= ' <li>' . t('[Optional] Set up your ads and analytics, including Audience Network, in the Configuration area, below.') . '</li>';
if ($page_id != '') {
$article_review_url = 'https://www.facebook.com/' . $page_id . '/settings/?tab=instant_articles#Setup-Step2';
$output .= ' <li>' . t('<a href="@article_review_url" target="_blank">Submit your articles</a> for review.', array(
'@article_review_url' => $article_review_url,
)) . '</li>';
}
else {
$output .= ' <li>' . t('Submit your articles for review.') . '</li>';
}
$output .= '</ol>';
$output .= '<p>' . t('Other Resources:') . '</p>';
$output .= '<ol>';
$output .= ' <li>' . t('Read the <a href="@docs_url" target="_blank">documentation</a> to answer additional questions you might have about Instant Articles.', array(
'@docs_url' => 'https://developers.facebook.com/docs/instant-articles',
)) . '</li>';
$output .= ' <li>' . t('Check out the <a href="@blog_url" target="_blank">Instant Articles blog</a> and sign up to receive notifications of important updates.', array(
'@blog_url' => 'https://developers.facebook.com/ia/blog/',
)) . '</li>';
if ($page_id != '') {
$tools_url = 'https://www.facebook.com/' . $page_id . '/settings/?tab=instant_articles';
$roles_url = 'https://www.facebook.com/' . $page_id . '/settings/?tab=admin_roles';
$output .= ' <li>' . t('To give other members of your team access to the <a href="@tools_url" target="_blank">Instant Articles tools</a>, assign them <a href="@roles_url" target="_blank">page roles here</a>.', array(
'@tools_url' => $tools_url,
'@roles_url' => $roles_url,
)) . '</li>';
}
else {
$output .= ' <li>' . t('To give other members of your team access to the Instant Articles tools, assign them page roles.') . '</li>';
}
$output .= '</ol>';
return $output;
break;
}
}
function fb_instant_articles_help_markdown($string) {
if (module_exists('markdown')) {
$filters = module_invoke('markdown', 'filter_info');
$info = $filters['filter_markdown'];
if (function_exists($info['process callback'])) {
return $info['process callback']($string, NULL);
}
return FALSE;
}
}
function fb_instant_articles_html_head_alter(&$head_elements) {
if (drupal_is_front_page() && ($page_id = variable_get('fb_instant_articles_page_id', NULL))) {
$head_elements['fb_instant_articles_page'] = array(
'#type' => 'html_tag',
'#tag' => 'meta',
'#attributes' => array(
'property' => 'fb:pages',
'content' => $page_id,
),
);
}
}
function fb_instant_articles_init() {
$enable_transformer_logging = variable_get('fb_instant_articles_enable_logging');
$appender = array(
'class' => $enable_transformer_logging ? '\\Drupal\\fb_instant_articles\\DrupalLoggerAppender' : 'LoggerAppenderNull',
'layout' => array(
'class' => 'LoggerLayoutSimple',
),
);
$configuration = array(
'rootLogger' => array(
'appenders' => array(
'facebook-instantarticles-transformer',
'facebook-instantarticles-client',
),
),
'appenders' => array(
'facebook-instantarticles-transformer' => $appender,
'facebook-instantarticles-client' => $appender,
),
);
\Logger::configure($configuration);
}