View source
<?php
if (module_exists('block')) {
module_load_include('inc', 'addthis', 'includes/addthis.block');
}
module_load_include('inc', 'addthis', 'includes/addthis.field');
function addthis_hook_info() {
$hooks['addthis_display_markup'] = array(
'group' => 'addthis',
);
return $hooks;
}
function addthis_help($path, $arg) {
switch ($path) {
case 'admin/help#addthis':
$output = '<h3>' . t('About') . '</h3>';
$output .= '<p>';
$output .= t('The AddThis module defines AddThis field type for the Field module. A AddThis field may contain a button, toolbox, sharecount or customized sharing tool using <a href="http://addthis.com/">AddThis.com</a>.');
$output .= '</p>';
return $output;
}
}
function addthis_filter_format_update($format) {
field_cache_clear();
}
function addthis_filter_format_disable($format) {
field_cache_clear();
}
function addthis_menu() {
$menu_items['admin/config/user-interface/addthis'] = array(
'title' => 'AddThis',
'description' => 'Configure AddThis settings.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'addthis_admin_settings_form',
),
'access arguments' => array(
AddThis::PERMISSION_ADMINISTER_ADDTHIS,
),
'type' => MENU_NORMAL_ITEM,
'file' => AddThis::ADMIN_INCLUDE_FILE,
'weight' => 0,
);
$menu_items['admin/config/user-interface/addthis/basic'] = array(
'title' => 'Basic settings',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$menu_items['admin/config/user-interface/addthis/advanced'] = array(
'title' => 'Advanced settings',
'type' => MENU_LOCAL_TASK,
'page callback' => 'drupal_get_form',
'page arguments' => array(
'addthis_admin_settings_advanced_form',
),
'access arguments' => array(
AddThis::PERMISSION_ADMINISTER_ADDTHIS,
),
'file' => AddThis::ADMIN_INCLUDE_FILE,
'weight' => 10,
);
return $menu_items;
}
function addthis_permission() {
return array(
AddThis::PERMISSION_ADMINISTER_ADDTHIS => array(
'title' => t('Administer AddThis'),
'description' => t('Perform maintenance tasks for AddThis.'),
),
AddThis::PERMISSION_ADMINISTER_ADVANCED_ADDTHIS => array(
'title' => t('Administer advanced AddThis'),
'description' => t('Perform advanced maintenance tasks for AddThis.'),
),
);
}
function addthis_form_field_ui_field_edit_form_alter(&$form, &$form_state, $form_id) {
if ($form['#field']['type'] == AddThis::FIELD_TYPE && $form['#field']['type'] == AddThis::MODULE_NAME) {
$form['field']['#access'] = FALSE;
$form['instance']['required']['#access'] = FALSE;
$form['instance']['description']['#access'] = FALSE;
$form['instance']['default_value_widget']['#access'] = FALSE;
}
}
function addthis_rdf_namespaces() {
if (AddThis::getInstance()
->isFacebookLikeCountSupportEnabled()) {
return array(
'fb' => 'http://www.facebook.com/2008/fbml',
);
}
return array();
}
function addthis_theme($existing, $type, $theme, $path) {
return array(
'addthis_wrapper' => array(
'render element' => 'addthis_wrapper',
),
'addthis_element' => array(
'render element' => 'addthis_element',
),
'addthis' => array(
'render element' => 'addthis',
),
);
}
function addthis_page_build(&$page) {
$addthis_js_path = drupal_get_path('module', 'addthis') . '/addthis.js';
$page['content']['#attached']['js'][$addthis_js_path] = array(
'type' => 'file',
'scope' => 'footer',
);
if (!path_is_admin(current_path()) && AddThis::getInstance()
->getWidgetJsInclude() == AddThis::WIDGET_JS_INCLUDE_PAGE) {
$manager = AddThisScriptManager::getInstance();
$manager
->attachJsToElement($page['content']);
}
}
function template_preprocess_addthis(&$variables) {
if (isset($variables[0]) && count($variables) == 3) {
$variables['#display'] = $variables[0];
unset($variables[0]);
}
}
function theme_addthis($variables) {
$markup = AddThis::getInstance()
->getDisplayMarkup($variables['#display']);
return render($markup);
}
function theme_addthis_wrapper($variables) {
$element = $variables['addthis_wrapper'];
$output = '<' . $element['#tag'] . drupal_attributes($element['#attributes']) . '>';
$children = element_children($element);
if (count($children) > 0) {
foreach ($children as $child) {
$output .= render($element[$child]);
}
}
$output .= '</' . $element['#tag'] . ">\n";
return $output;
}
function theme_addthis_element($variables) {
$element = $variables['addthis_element'];
if (!isset($element['#value'])) {
return '<' . $element['#tag'] . drupal_attributes($element['#attributes']) . " />\n";
}
$output = '<' . $element['#tag'] . drupal_attributes($element['#attributes']) . '>';
if (isset($element['#value_prefix'])) {
$output .= $element['#value_prefix'];
}
$output .= $element['#value'];
if (isset($element['#value_suffix'])) {
$output .= $element['#value_suffix'];
}
$output .= '</' . $element['#tag'] . ">\n";
return $output;
}
function _addthis_settings_form($form = array(), &$form_state = array(), $display_type = NULL, $display_settings = array()) {
if (empty($display_settings) || !is_array($display_settings)) {
$display_settings = array();
}
$no_js = FALSE;
$display_type = isset($display_type) ? $display_type : 'addthis_disabled';
if (isset($form_state['values']['addthis_settings']['type'])) {
$display_type = $form_state['values']['addthis_settings']['type'];
}
$form['#type'] = 'container';
$form['#attributes'] = array();
$form['#id'] = 'addthis_settings';
$formatter_options = AddThis::getInstance()
->getDisplayTypes();
$form['type'] = array(
'#type' => 'select',
'#title' => t('Formatter for @title', array(
'@title' => 'AddThis block',
)),
'#title_display' => 'invisible',
'#options' => $formatter_options,
'#default_value' => $display_type,
'#parents' => array(
'addthis_settings',
'type',
),
'#attributes' => array(
'class' => array(
'addthis-display-type',
),
),
'#ajax' => array(
'callback' => '_addthis_settings_form_submit_callback',
'wrapper' => 'addthis_settings',
'name' => 'switch_display',
'event' => 'change',
),
);
if ($no_js) {
$form['choose'] = array(
'#type' => 'submit',
'#name' => 'Switch display',
'#value' => 'Switch display',
'#op' => 'switch_display',
'#id' => 'switch-display',
'#submit' => array(
'_addthis_settings_form_submit',
),
);
}
$formatter_type = $display_type;
$settings = $display_settings;
$formatter_settings = field_info_formatter_settings($formatter_type);
$settings += $formatter_settings;
$field = array();
$instance = array();
$view_mode = 'block';
$instance['display'][$view_mode]['type'] = $formatter_type;
$formatter = field_info_formatter_types($formatter_type);
$instance['display'][$view_mode]['module'] = $formatter['module'];
$instance['display'][$view_mode]['settings'] = $settings;
$settings_form = array();
$function = $formatter['module'] . '_field_formatter_settings_form';
if (function_exists($function)) {
$settings_form = $function($field, $instance, $view_mode, $form, $form_state);
$settings_form['#tree'] = TRUE;
$settings_form['#parents'] = array(
'addthis_settings',
'settings',
);
}
$form['settings'] = $settings_form;
return $form;
}
function _addthis_settings_form_submit($form, &$form_state) {
$form_state['rebuild'] = TRUE;
}
function _addthis_settings_form_submit_callback($form, &$form_state) {
$form_state['rebuild'] = TRUE;
return $form['addthis_settings']['form'];
}