uptolike.module in Uptolike share buttons 7
Main file for Uptolike module.
File
uptolike.moduleView source
<?php
/**
* @file
* Main file for Uptolike module.
*/
define('UPTOLIKE_HOST', 'https://uptolike.com/api/');
define('UPTOLIKE_PARTNER', 'cms');
define('UPTOLIKE_SUPPORT_EMAIL', 'uptolikeshare@gmail.com');
/**
* Implements hook_help().
*/
function uptolike_help($path, $arg) {
switch ($path) {
// Main module help for the Uptolike module.
case 'admin/help#uptolike':
$output = '<h2>' . t('Uptolike is a customizable social media buttons') . '</h2>';
$output .= '<p>' . t("The buttons of social networks can be installed anywhere on the page, set the color, shape, size, and special effects. Don't forget to experiment: the buttons of social networks – one of the conversion elements on your website: achieve the most successful of their location and appearance.") . '</p>';
return $output;
// Help preset list in the Uptolike module.
case 'admin/config/system/uptolike':
return '<p>' . t('This page contains all the available presets for Uptolike module. You can add new, edit existing, and to export/import the preset.') . '</p>';
}
}
/**
* Implements hook_permission().
*/
function uptolike_permission() {
return array(
'administer uptolike' => array(
'title' => t('Administer Uptolike'),
'description' => t('Perform administration tasks for Uptolike module.'),
),
);
}
/**
* Implements hook_menu().
*/
function uptolike_menu() {
$items = array();
$items['admin/config/system/uptolike/statistics'] = array(
'title' => 'Statistics',
'description' => 'Statistics of using Uptolike share buttons.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'uptolike_admin_statistic_form',
),
'access arguments' => array(
'administer uptolike',
),
'type' => MENU_LOCAL_TASK,
'file' => 'uptolike.admin.inc',
'weight' => -1,
);
$items['admin/config/system/uptolike/settings'] = array(
'title' => 'Settings',
'description' => 'Configure Uptolike share buttons.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'uptolike_admin_settings_form',
),
'access arguments' => array(
'administer uptolike',
),
'type' => MENU_LOCAL_TASK,
'file' => 'uptolike.admin.inc',
);
return $items;
}
/**
* Implements hook_ctools_plugin_api().
*
* Tell CTools that we support the default_uptolike_presets API.
*/
function uptolike_ctools_plugin_api($owner, $api) {
if ($owner == 'uptolike' && $api == 'default_uptolike_presets') {
return array(
'version' => 1,
);
}
}
/**
* Implements hook_default_uptolike_preset().
*
* Provide a couple of default presets.
*/
function uptolike_default_uptolike_preset() {
$export = array();
$uptolike = new stdClass();
$uptolike->api_version = 1;
$uptolike->name = 'default_preset';
$uptolike->admin_title = 'Default preset';
$uptolike->code = 'data-mobile-view="true" data-share-size="30" data-like-text-enable="false" data-background-alpha="0.0" data-mode="share" data-background-color="#ffffff" data-share-shape="round-rectangle" data-share-counter-size="12" data-icon-color="#ffffff" data-mobile-sn-ids="fb.vk.tw.wh.ok.gp." data-text-color="#000000" data-buttons-color="#FFFFFF" data-counter-background-color="#ffffff" data-pid="' . uptolike_project_id() . '" data-share-counter-type="common" data-orientation="horizontal" data-following-enable="false" data-sn-ids="fb.vk.tw.ok.gp." data-preview-mobile="false" data-selection-enable="true" data-exclude-show-more="false" data-share-style="1" data-counter-background-alpha="1.0" data-top-button="false"';
$uptolike->json = '{"orientation":1,"size":2,"form":2,"counterType":2,"style":1,"following":0,"useSelectionModule":true,"share_ids":["fb","vk","tw","ok","gp"],"mobileIds":["fb","vk","tw","wh","ok","gp"],"follow_ids":{"fb":"ваш_id"},"hoverEffect":0,"shareColor":"#ffffff","likeColor":"#ffffff","shareColor2":"#000000","shareColor3":"#FFFFFF","shareColor4":"#ffffff","shareColor5":"#ffffff","shareAlpha":"0","shareAlpha4":"1","likeAlpha":"0","shareCountTextSize":12,"mobileView":true,"likeVariant":0,"type":1,"showShareCounter":true,"shareVariant":0}';
$export['default_preset'] = $uptolike;
return $export;
}
/**
* Implements hook_ctools_plugin_directory().
*/
function uptolike_ctools_plugin_directory($module, $type) {
// Load the export_ui plugin.
if ($type == 'export_ui') {
return 'plugins/export_ui';
}
}
/**
* List of Uptolike ctools presets.
*
* @return array
* An associative array containing machine readable and human names of
* presets.
*/
function uptolike_preset_list() {
ctools_include('export');
$objects = ctools_export_load_object('uptolike_preset');
$list = array();
foreach ($objects as $object) {
// Do not show disabled presets.
if (!isset($object->disabled) || isset($object->disabled) && !$object->disabled) {
$list[$object->name] = $object->admin_title;
}
}
asort($list);
return $list;
}
/**
* Load enabled "uptolike_preset" object.
*
* @param array $arg
* An array of arguments whose actual use is defined by the "conditions"
* argument. See ctools_export_load_object() fo details.
*
* @return array|bool|mixed
* Loaded ctools object or FALSE if object is disabled.
*/
function _uptolike_ctools_export_load_enabled_object(array $arg) {
ctools_include('export');
$object = ctools_export_load_object('uptolike_preset', 'conditions', $arg);
$object = reset($object);
if (!isset($object->disabled) || isset($object->disabled) && !$object->disabled) {
return $object;
}
return FALSE;
}
/**
* Implements hook_block_info().
*/
function uptolike_block_info() {
$blocks = array();
// Get current number of blocks.
$number = variable_get('uptolike_number_of_blocks', 1);
// Generate assigned amount of blocks.
for ($i = 1; $i <= $number; $i++) {
$blocks['uptolike' . $i] = array(
'info' => t('Uptolike share buttons block @number', array(
'@number' => $i,
)),
'cache' => 'DRUPAL_CACHE_PER_PAGE',
);
}
return $blocks;
}
/**
* Implements hook_block_configure().
*/
function uptolike_block_configure($delta = '') {
// Get current number of blocks.
$number = variable_get('uptolike_number_of_blocks', 1);
$form = array();
for ($i = 1; $i <= $number; $i++) {
if ($delta == 'uptolike' . $i) {
$form['preset'] = array(
'#type' => 'select',
'#title' => t('Uptolike preset'),
'#description' => t('Select Uptolike share buttons preset. !manage_presets', array(
'!manage_presets' => l(t('Manage presets.'), '/admin/config/system/uptolike'),
)),
'#options' => uptolike_preset_list(),
'#default_value' => variable_get('uptolike_block_preset_' . $i, 'default_preset'),
'#empty_option' => t('- Select preset -'),
);
}
}
return $form;
}
/**
* Implements hook_block_save().
*/
function uptolike_block_save($delta = '', $edit = array()) {
// Get current number of blocks.
$number = variable_get('uptolike_number_of_blocks', 1);
for ($i = 1; $i <= $number; $i++) {
if ($delta == 'uptolike' . $i) {
variable_set('uptolike_block_preset_' . $i, $edit['preset']);
}
}
}
/**
* Implements hook_block_view().
*/
function uptolike_block_view($delta = '') {
$block = array();
// Get current number of blocks.
$number = variable_get('uptolike_number_of_blocks', 1);
for ($i = 1; $i <= $number; $i++) {
if ($delta == 'uptolike' . $i) {
$block_preset = variable_get('uptolike_block_preset_' . $i, 'default_preset');
$object = _uptolike_ctools_export_load_enabled_object(array(
'name' => $block_preset,
));
if (!empty($object)) {
// Prepare data for theme function.
$variables = array();
global $base_url;
$variables['url'] = $base_url . request_uri();
$variables['language'] = variable_get('uptolike_language', uptolike_default_language());
$variables['data'] = filter_xss($object->code);
$block['subject'] = t('Uptolike share buttons block @number', array(
'@number' => $i,
));
$block['content'] = array(
'#markup' => theme('uptolike_code', $variables),
'#attached' => array(
'js' => array(
array(
'data' => theme('uptolike_javascript'),
'scope' => 'footer',
'type' => 'inline',
),
),
),
);
}
}
}
return $block;
}
/**
* Implements hook_entity_view().
*/
function uptolike_entity_view($entity, $type, $view_mode, $langcode) {
if (isset($entity->type)) {
$extra_fields = field_extra_fields_get_display($type, $entity->type, $view_mode);
if (isset($extra_fields['uptolike']) && $extra_fields['uptolike']['visible'] && !empty($extra_fields['uptolike']['settings'])) {
$preset = $extra_fields['uptolike']['settings']['preset'];
$object = _uptolike_ctools_export_load_enabled_object(array(
'name' => $preset,
));
if (!empty($object)) {
// Prepare data for theme function.
$variables = array();
$url = entity_uri($type, $entity);
if (!empty($url['path'])) {
$url['options']['absolute'] = TRUE;
$variables['url'] = url($url['path'], $url['options']);
}
$variables['language'] = variable_get('uptolike_language', uptolike_default_language());
$variables['data'] = filter_xss($object->code);
$entity->content['uptolike'] = array(
'#markup' => theme('uptolike_code', $variables),
'#attached' => array(
'js' => array(
array(
'data' => theme('uptolike_javascript'),
'scope' => 'footer',
'type' => 'inline',
),
),
),
);
}
}
}
}
/**
* Implements hook_field_extra_fields().
*/
function uptolike_field_extra_fields($get_defaults = FALSE) {
$uptolike = array(
'label' => t('Uptolike'),
'description' => t('Uptolike share buttons'),
'weight' => 50,
'settings' => array(
'preset' => 'default_preset',
),
);
if ($get_defaults) {
return array(
'extra_fields' => array(
'display' => array(
'uptolike' => $uptolike,
),
),
);
}
$extra = array();
$uptolike_entities = variable_get('uptolike_entities', array(
'node',
));
$uptolike_entities = array_filter($uptolike_entities);
foreach (entity_get_info() as $entity_type => $entity) {
// Add extra field only for selected entities.
if (in_array($entity_type, $uptolike_entities)) {
foreach (array_keys($entity['bundles']) as $bundle) {
$extra[$entity_type][$bundle]['display']['uptolike'] = $uptolike;
$field_bundle_setting = field_bundle_settings($entity_type, $bundle);
$view_modes = $field_bundle_setting['view_modes'];
$view_modes = array_keys($view_modes);
// Hide Uptolike extra field by default.
if (empty($field_bundle_setting['extra_fields']['display']['uptolike'])) {
$settings = array(
'visible' => FALSE,
'weight' => $uptolike['weight'],
);
foreach ($view_modes as $view_mode) {
$field_bundle_setting['extra_fields']['display']['uptolike'][$view_mode] = $settings;
}
field_bundle_settings($entity_type, $bundle, $field_bundle_setting);
}
}
}
}
return $extra;
}
/**
* Implements hook_form_FORM_ID_alter() for field_ui_display_overview_form().
*/
function uptolike_form_field_ui_display_overview_form_alter(&$form, &$form_state, $form_id) {
$uptolike_entities = variable_get('uptolike_entities', array(
'node',
));
$uptolike_entities = array_filter($uptolike_entities);
// Add settings only for selected entities.
if (in_array($form['#entity_type'], $uptolike_entities)) {
$base_button = array(
'#submit' => array(
'field_ui_display_overview_multistep_submit',
),
'#ajax' => array(
'callback' => 'field_ui_display_overview_multistep_js',
'wrapper' => 'field-display-overview-wrapper',
'effect' => 'fade',
),
'#field_name' => 'uptolike',
);
$summary = isset($form_state['formatter_settings']['uptolike']) ? $form_state['formatter_settings']['uptolike'] : NULL;
if ($form_state['formatter_settings_edit'] == 'uptolike') {
$form['fields']['uptolike']['#region_callback'] = 'field_ui_display_overview_row_region';
$form['fields']['uptolike']['format']['settings_edit_form'] = array(
'#type' => 'container',
'#attributes' => array(
'class' => array(
'field-formatter-settings-edit-form',
),
),
'#parents' => array(
'fields',
'uptolike',
'settings_edit_form',
),
'label' => array(
'#markup' => t('Format settings:') . ' <span class="formatter-name">' . t('Uptolike') . '</span>',
),
'settings' => _uptolike_field_formatter_settings_form($form, $summary),
'actions' => array(
'#type' => 'actions',
'save_settings' => $base_button + array(
'#type' => 'submit',
'#name' => 'uptolike_formatter_settings_update',
'#value' => t('Update'),
'#op' => 'update',
),
'cancel_settings' => $base_button + array(
'#type' => 'submit',
'#name' => 'uptolike_formatter_settings_cancel',
'#value' => t('Cancel'),
'#op' => 'cancel',
// Do not check errors for the 'Cancel' button, but make sure we
// get the value of the 'formatter type' select.
'#limit_validation_errors' => array(
array(
'fields',
'uptolike',
'type',
),
),
),
),
);
$form['fields']['uptolike']['#attributes']['class'][] = 'field-formatter-settings-editing';
}
elseif (isset($form['#entity_type'])) {
$form['fields']['uptolike']['#region_callback'] = 'field_ui_display_overview_row_region';
$form['fields']['uptolike']['settings_summary'] = array(
'#markup' => '<div class="field-formatter-summary">' . _uptolike_field_formatter_settings_summary($form, $summary) . '</div>',
'#cell_attributes' => array(
'class' => array(
'field-formatter-summary-cell',
),
),
);
$form['fields']['uptolike']['settings_edit'] = $base_button + array(
'#type' => 'image_button',
'#name' => 'uptolike_formatter_settings_edit',
'#src' => 'misc/configure.png',
'#attributes' => array(
'class' => array(
'field-formatter-settings-edit',
),
'alt' => t('Edit'),
),
'#op' => 'edit',
// Do not check errors for the 'Edit' button, but make sure we get
// the value of the 'formatter type' select.
'#limit_validation_errors' => array(
array(
'fields',
'uptolike',
'type',
),
),
'#prefix' => '<div class="field-formatter-settings-edit-wrapper">',
'#suffix' => '</div>',
);
}
if (!isset($form_state['formatter_settings']['uptolike']) || isset($form_state['formatter_settings']['uptolike']) && empty($form_state['formatter_settings']['uptolike'])) {
$bundle_settings = field_bundle_settings($form['#entity_type'], $form['#bundle']);
if (isset($bundle_settings['extra_fields']['display']['uptolike'][$form['#view_mode']]['settings'])) {
$form_state['formatter_settings']['uptolike'] = $bundle_settings['extra_fields']['display']['uptolike'][$form['#view_mode']]['settings'];
}
else {
$display_defaults = uptolike_field_extra_fields(TRUE);
$form_state['formatter_settings']['uptolike'] = $display_defaults['extra_fields']['display']['uptolike']['settings'];
}
}
$form['#submit'][] = '_uptolike_display_overview_form_submit';
}
}
/**
* Pseudo hook_field_formatter_settings_form().
*/
function _uptolike_field_formatter_settings_form($build, $summary = NULL) {
$display_stored = field_bundle_settings($build['#entity_type'], $build['#bundle']);
$display_defaults = uptolike_field_extra_fields(TRUE);
if (!empty($summary)) {
$settings = $summary;
}
elseif (isset($display_stored['extra_fields']['display']['uptolike'][$build['#view_mode']])) {
$settings = $display_stored['extra_fields']['display']['uptolike'][$build['#view_mode']]['settings'];
}
else {
$settings = $display_defaults['extra_fields']['display']['uptolike']['settings'];
}
$form['preset'] = array(
'#default_value' => $settings['preset'],
'#type' => 'select',
'#title' => t('Uptolike preset'),
'#description' => t('Select Uptolike share buttons preset. !manage_presets', array(
'!manage_presets' => l(t('Manage presets.'), '/admin/config/system/uptolike'),
)),
'#options' => uptolike_preset_list(),
'#empty_option' => t('- Select preset -'),
);
return $form;
}
/**
* Pseudo hook_field_formatter_settings_summary().
*/
function _uptolike_field_formatter_settings_summary($build, $summary = NULL) {
$display_stored = field_bundle_settings($build['#entity_type'], $build['#bundle']);
$display_defaults = uptolike_field_extra_fields(TRUE);
if (!empty($summary)) {
$settings = $summary;
}
elseif (isset($display_stored['extra_fields']['display']['uptolike'][$build['#view_mode']]['settings'])) {
$settings = $display_stored['extra_fields']['display']['uptolike'][$build['#view_mode']]['settings'];
}
else {
$settings = $display_defaults['extra_fields']['display']['uptolike']['settings'];
}
if (isset($settings['preset'])) {
ctools_include('export');
$preset = ctools_export_load_object('uptolike_preset', 'conditions', array(
'name' => $settings['preset'],
));
if (!empty($preset)) {
$preset = reset($preset);
$summary = t('Uptolike preset to use: @preset', array(
'@preset' => $preset->admin_title,
));
}
else {
$summary = t('Uptolike preset to use: none');
}
}
return $summary;
}
/**
* Uptolike submit handler for field_ui_display_overview_form.
*/
function _uptolike_display_overview_form_submit($form, &$form_state) {
// Get current bundle settings.
$bundle_settings = field_bundle_settings($form['#entity_type'], $form['#bundle']);
$bundle_settings['extra_fields']['display']['uptolike'][$form['#view_mode']]['settings'] = $form_state['formatter_settings']['uptolike'];
// Save updated bundle settings.
field_bundle_settings($form['#entity_type'], $form['#bundle'], $bundle_settings);
}
/**
* Implements hook_js_alter().
*/
function uptolike_js_alter(&$javascript) {
// Display Uptolike main javascript code only once.
foreach ($javascript as $k => $js) {
if ($js['type'] == 'inline' && strpos($js['data'], 'uptolike') !== FALSE) {
// Save to use later.
$uptolike = $js;
// Remove all Uptolike javascripts.
unset($javascript[$k]);
}
}
if (!empty($uptolike)) {
// Add code only once.
$javascript[] = $uptolike;
}
}
/**
* Implements hook_filter_info().
*/
function uptolike_filter_info() {
$filters = array();
$filters['uptolike'] = array(
'title' => t('Uptolike share buttons'),
'description' => t('Every instance of the special <code>[uptolike]</code> or <code>[uptolike:preset]</code> tag will be replaced with Uptolike share buttons.'),
'settings callback' => '_uptolike_filter_settings',
'process callback' => '_uptolike_filter_process',
'tips callback' => '_uptolike_filter_tips',
);
return $filters;
}
/**
* Settings callback for Uptolike filter.
*/
function _uptolike_filter_settings($form, $form_state, $filter, $format, $defaults) {
$settings['uptolike'] = array(
'#type' => 'select',
'#title' => t('Uptolike default preset'),
'#description' => t('Select default Uptolike share buttons preset which will be used by <code>[uptolike]</code> tag. !manage_presets', array(
'!manage_presets' => l(t('Manage presets.'), '/admin/config/system/uptolike'),
)),
'#options' => uptolike_preset_list(),
'#default_value' => isset($filter->settings['uptolike']) ? $filter->settings['uptolike'] : $defaults['uptolike'],
'#empty_option' => t('- Select preset -'),
);
return $settings;
}
/**
* Uptolike filter process callback.
*/
function _uptolike_filter_process($text, $filter) {
if (preg_match_all('#\\[uptolike\\]#isU', $text, $matches_code)) {
$object = _uptolike_ctools_export_load_enabled_object(array(
'name' => $filter->settings['uptolike'],
));
if (!empty($object)) {
// Prepare data for theme function.
$variables = array();
global $base_url;
$variables['url'] = $base_url . request_uri();
$variables['language'] = variable_get('uptolike_language', uptolike_default_language());
$variables['data'] = filter_xss($object->code);
$text = str_replace('[uptolike]', theme('uptolike_code', $variables), $text);
}
else {
$text = str_replace('[uptolike]', '<!-- UPTOLIKE - INVALID DEFAULT PRESET -->', $text);
}
}
if (preg_match_all('#\\[uptolike\\:(.+)\\]#isU', $text, $matches_code)) {
foreach ($matches_code[0] as $ci => $code) {
$preset = $matches_code[1][$ci];
$object = _uptolike_ctools_export_load_enabled_object(array(
'name' => $preset,
));
if (!empty($object)) {
// Prepare data for theme function.
$variables = array();
global $base_url;
$variables['url'] = $base_url . request_uri();
$variables['language'] = variable_get('uptolike_language', uptolike_default_language());
$variables['data'] = filter_xss($object->code);
$text = str_replace($code, theme('uptolike_code', $variables), $text);
}
elseif (strpos($text, 'PRESET: ' . $code) === FALSE) {
$text = str_replace($code, '<!-- UPTOLIKE - INVALID PRESET: ' . check_plain($code) . ' -->', $text);
}
}
}
return $text;
}
/**
* Filter tips callback for uptolike filter.
*/
function _uptolike_filter_tips($filter, $format, $long = FALSE) {
return t('<code>[uptolike]</code> and <code>[uptolike:preset]</code> will be replaced with Uptolike share buttons.');
}
/**
* Implements hook_page_alter().
*/
function uptolike_page_alter(&$page) {
$every_page = variable_get('uptolike_every_page', 0);
if ($every_page) {
$page['page_bottom']['uptolike']['#attached']['js'] = array(
array(
'data' => theme('uptolike_javascript'),
'scope' => 'footer',
'type' => 'inline',
),
);
}
}
/**
* Share buttons language.
*
* @return string
* Default site language or 'en' if language is not supported.
*/
function uptolike_default_language() {
// Supported languages.
$languages = array(
'en',
'ru',
'ua',
'de',
'es',
'it',
'lt',
'pl',
);
global $language;
$default_language = in_array($language->language, $languages);
return $default_language ? $language->language : 'en';
}
/**
* Build project identifier.
*
* @return string
* Site url without "www", "." and "-".
*/
function uptolike_project_id() {
global $base_url;
// Remove http:// and https:// from site url.
$url = preg_replace('#http(s)?:\\/\\/#', '', $base_url);
// Remove www from begging.
$url = preg_replace('#^www\\.#', '', $url);
// Remove "." and "-".
$url = preg_replace('#[.-]#', '', $url);
return UPTOLIKE_PARTNER . $url;
}
/**
* Registration on Uptolike service.
*
* @param string $email
* Email address for registration.
*
* @return string
* Text information about status of registration.
*/
function uptolike_user_registration($email) {
$output = t('An error has occurred.');
$url = UPTOLIKE_HOST . 'getCryptKeyWithUserReg.json?';
$query = array(
'email' => $email,
'partner' => UPTOLIKE_PARTNER,
'projectId' => uptolike_project_id(),
'url' => check_plain($_SERVER['HTTP_HOST']),
);
$request = drupal_http_request($url . drupal_http_build_query($query));
if ($request->code == 200) {
$data = drupal_json_decode($request->data);
if ($data['statusCode'] == 'MAIL_SENDED') {
$output = t('Secret key has been sent to %email.', array(
'%email' => $email,
));
}
if ($data['statusCode'] == 'ALREADY_EXISTS') {
$output = t('Error code 015. Contact support %email with this error code.', array(
'%email' => UPTOLIKE_SUPPORT_EMAIL,
));
}
}
return $output;
}
/**
* Build crypt key for url.
*
* @return null|string
* The secret key to be added to the url or null if no data.
*/
function uptolike_cryptkey() {
$email = variable_get('uptolike_email', NULL);
$key = variable_get('uptolike_key', NULL);
$project_id = uptolike_project_id();
$output = NULL;
if (!empty($email) && !empty($key)) {
// Email address should not be url encoded.
$string = 'mail=' . $email . '&partner=' . UPTOLIKE_PARTNER . '&projectId=' . $project_id;
$output = md5($string . $key);
}
return $output;
}
/**
* Build constructor iframe.
*/
function uptolike_constructor() {
$url = UPTOLIKE_HOST . 'constructor.html';
$cryptkey = uptolike_cryptkey();
if (!empty($cryptkey)) {
$query = array(
'mail' => variable_get('uptolike_email', NULL),
'partner' => UPTOLIKE_PARTNER,
'projectId' => uptolike_project_id(),
'signature' => $cryptkey,
);
$url .= '?' . drupal_http_build_query($query);
}
$variables = array();
$variables['url'] = $url;
$variables['class'] = 'uptolike-constructor';
return theme('uptolike_iframe', $variables);
}
/**
* Build statistic iframe.
*
* @param bool $class
* CSS class for iframe.
*
* @return string
* Theme for uptolike statistic iframe.
*/
function uptolike_statistic($class = FALSE) {
$query = array(
'mail' => variable_get('uptolike_email', NULL),
'partner' => UPTOLIKE_PARTNER,
'projectId' => uptolike_project_id(),
'signature' => uptolike_cryptkey(),
);
$url = UPTOLIKE_HOST . 'statistics.html?' . drupal_http_build_query($query);
$variables = array();
$variables['url'] = $url;
$variables['class'] = $class ? $class : 'uptolike-statistic';
return theme('uptolike_iframe', $variables);
}
/**
* Return HTML for Uptolike iframe.
*
* @param array $variables
* An associative array containing:
* - url: url of embed iframe.
* - class: css class of embed iframe.
*
* @ingroup themeable
*/
function theme_uptolike_iframe(array $variables) {
$url = $variables['url'];
if (!empty($url)) {
$class = $variables['class'];
$output = '<iframe id="uptolike"';
if (!empty($class)) {
$output .= ' class="' . $class . '"';
}
$output .= ' src="' . $url . '"></iframe>';
}
else {
$output = '';
}
return $output;
}
/**
* Return main javascript code for Uptolike share buttons.
*
* @ingroup themeable
*/
function theme_uptolike_javascript() {
$script = "(function(w,doc) {";
$script .= "if (!w.__utlWdgt ) {";
$script .= "w.__utlWdgt = true;";
$script .= "var d = doc, s = d.createElement('script'), g = 'getElementsByTagName';";
$script .= "s.type = 'text/javascript'; s.charset='UTF-8'; s.async = true;";
$script .= "s.src = ('https:' == w.location.protocol ? 'https' : 'http') + '://w.uptolike.com/widgets/v1/uptolike.js';";
$script .= "var h=d[g]('body')[0];";
$script .= "h.appendChild(s);";
$script .= "}})(window,document);";
return $script;
}
/**
* Implements hook_theme().
*/
function uptolike_theme() {
return array(
'uptolike_iframe' => array(
'variables' => array(
'url' => NULL,
'class' => NULL,
),
),
'uptolike_javascript' => array(),
'uptolike_code' => array(
'variables' => array(
'url' => NULL,
'language' => NULL,
'data' => NULL,
),
'template' => 'uptolike',
),
);
}
Functions
Constants
Name![]() |
Description |
---|---|
UPTOLIKE_HOST | @file Main file for Uptolike module. |
UPTOLIKE_PARTNER | |
UPTOLIKE_SUPPORT_EMAIL |