share42.module in Share42 - social sharing buttons 6
Same filename and directory in other branches
Main file for the Share42 module.
File
share42.moduleView source
<?php
/**
* @file
* Main file for the Share42 module.
*/
/**
* Implements hook_help().
*/
function share42_help($path, $arg) {
switch ($path) {
case 'admin/help#share42':
$output = '';
$output .= '<h3>' . t('Introduction') . '</h3>';
$output .= '<p>' . t('Integration of social sharing buttons script from http://share42.com.') . '</p>';
$output .= '<h3>' . t('Installation') . '</h3>';
$output .= '<p>' . t('Configure required services at <a href="!site">http://share42.com</a> and then download and unpack into "sites/all/libraries/share42" folder.', array(
'!site' => 'http://share42.com',
)) . '</p>';
return $output;
}
}
/**
* Implements hook_init().
*/
function share42_init() {
drupal_add_js(_share42_library_path() . '/share42.js', 'module', 'footer');
drupal_add_css(drupal_get_path('module', 'share42') . '/css/share42.css');
}
/**
* Implements hook_block().
*/
function share42_block($op = 'list', $delta = 0, $edit = array()) {
if ($op == 'list') {
$blocks['share42'] = array(
'info' => t('Share42 - social sharing buttons block'),
'cache' => BLOCK_CACHE_GLOBAL,
);
return $blocks;
}
elseif ($op == 'configure' && $delta == 'share42') {
$form = array();
$form['share42_top1'] = array(
'#title' => t('Offset without scroll'),
'#description' => t('Distance from the top of the page to the "sticky" panel (in pixels).'),
'#default_value' => variable_get('share42_top1', 200),
);
$form['share42_top2'] = array(
'#title' => t('Offset with scroll'),
'#description' => t('Distance from the top of the visible area of the page to the floating panel (in pixels).'),
'#default_value' => variable_get('share42_top2', 50),
);
$form['share42_margin'] = array(
'#title' => t('Horizontal margin'),
'#description' => t('Horizontal displacement of the panel. If you want to move it to the left, for example, by 70 pixels, set the value to "-70", but if you want to move it to the right, for example, by 50 pixels, set this value to "50".'),
'#default_value' => variable_get('share42_margin', -70),
);
foreach ($form as $key => $value) {
$form[$key]['#type'] = 'textfield';
$form[$key]['#size'] = 3;
$form[$key]['#maxlength'] = 4;
$form[$key]['#element_validate'] = array(
'share42_validate_number',
);
}
return $form;
}
elseif ($op == 'save' && $delta == 'share42') {
variable_set('share42_top1', $edit['share42_top1']);
variable_set('share42_top2', $edit['share42_top2']);
variable_set('share42_margin', $edit['share42_margin']);
}
elseif ($op == 'view' && $delta == 'share42') {
$output = '<div class="share42init"' . ' data-url="' . url(isset($_GET['q']) ? $_GET['q'] : '<front>', array(
'absolute' => TRUE,
)) . '" data-title="' . drupal_get_title() . '" data-path="' . base_path() . _share42_library_path() . '/' . '" data-top1="' . variable_get('share42_top1', 200) . '" data-top2="' . variable_get('share42_top2', 50) . '" data-margin="' . variable_get('share42_margin', -70) . '"></div>';
return array(
'subject' => '',
'content' => $output,
);
}
}
function share42_validate_number($element, &$form_state) {
$value = $element['#value'];
if ($value != '' && !is_numeric($value)) {
form_error($element, t('%name must be a number.', array(
'%name' => $element['#title'],
)));
}
}
/**
* Returns the path to the Share42 library.
*/
function _share42_library_path() {
static $library_path;
if (is_null($library_path)) {
$library_path = variable_get('share42_library_path', module_exists('libraries') ? libraries_get_path('share42') : 'sites/all/libraries/share42');
if (!file_exists($library_path . '/share42.js')) {
watchdog('share42', 'Share42 library is missing.', array(), WATCHDOG_ERROR);
$library_path = FALSE;
}
}
return $library_path;
}
/**
* Returns version of the Share42 library.
*/
function _share42_library_version() {
static $version;
if (is_null($version) && ($library_path = _share42_library_path())) {
$pattern = '/share42.com \\| ([0-9\\.]+)/';
$share42_js = file_get_contents($library_path . '/share42.js', NULL, NULL, 0, 32);
if (preg_match($pattern, $share42_js, $matches)) {
$version = $matches[1];
}
else {
$version = 'Unknown';
}
}
return $version;
}
Functions
Name![]() |
Description |
---|---|
share42_block | Implements hook_block(). |
share42_help | Implements hook_help(). |
share42_init | Implements hook_init(). |
share42_validate_number | |
_share42_library_path | Returns the path to the Share42 library. |
_share42_library_version | Returns version of the Share42 library. |