You are here

sharebar.module in ShareBar 6

Same filename and directory in other branches
  1. 8 sharebar.module
  2. 7.2 sharebar.module
  3. 7 sharebar.module

Various module information.

File

sharebar.module
View source
<?php

/**
 * @file
 * Various module information.
 */
define('SHAREBAR_CREDIT_URL', 'http://www.socialseo.com/drupal-development/sharebar-module.html');

/**
 * Implements hook_perm().
 */
function sharebar_perm() {
  return array(
    'access ShareBar administer',
  );
}

/**
 * Implements hook_menu().
 */
function sharebar_menu() {

  // Administration pages.
  $items['admin/settings/sharebar'] = array(
    'title' => 'ShareBar',
    'description' => 'Configure shareBar',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'sharebar_settings',
    ),
    'access arguments' => array(
      'access ShareBar administer',
    ),
    'file' => 'sharebar.admin.inc',
  );
  $items['admin/settings/sharebar/add'] = array(
    'title' => t('Add new button'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'sharebar_addbutton',
    ),
    'access callback' => 'user_access',
    'access arguments' => array(
      'access ShareBar administer',
    ),
    'type' => MENU_CALLBACK,
    'file' => 'sharebar.admin.inc',
  );
  $items['admin/settings/sharebar/edit'] = array(
    'title' => t('Edit button'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'sharebar_addbutton',
    ),
    'access callback' => 'user_access',
    'access arguments' => array(
      'access ShareBar administer',
    ),
    'type' => MENU_CALLBACK,
    'file' => 'sharebar.admin.inc',
  );
  $items['admin/settings/sharebar/del'] = array(
    'title' => t('Delete button'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'sharebar_button_confirm_delete',
    ),
    'access callback' => 'user_access',
    'access arguments' => array(
      'access ShareBar administer',
    ),
    'type' => MENU_CALLBACK,
    'file' => 'sharebar.admin.inc',
  );
  $items['sharebar/ahah/csscontainer/callback'] = array(
    'page callback' => 'sharebar_ahah_csscontainer_callback',
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
    'file' => 'sharebar.admin.inc',
  );
  return $items;
}

/**
 * Implements hook_theme().
 */
function sharebar_theme() {
  return array(
    'sharebar_buttons_table' => array(
      'file' => 'sharebar.admin.inc',
      'variables' => array(
        'var' => '',
      ),
    ),
  );
}

/**
 * Implements hook_init().
 */
function sharebar_init() {
  if (arg(0) != 'admin') {
    $node = menu_get_object();
    if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == '' && (!empty($node) && variable_get('sharebar_bar_posts_' . $node->type . '_enabled', TRUE)) || !(arg(0) == 'node' && is_numeric(arg(1))) && arg(1) != 'add' && arg(2) != 'edit' && arg(3) != 'edit' && variable_get('sharebar_bar_pages_enabled', TRUE)) {
      drupal_add_css(drupal_get_path('module', 'sharebar') . '/css/sharebar.css');
      if (!variable_get('sharebar_bar_oncontent', TRUE)) {
        if (variable_get('sharebar_bar_horizontal', TRUE)) {
          $hori = 'TRUE';
        }
        else {
          $hori = 'FALSE';
        }
        $width = variable_get('sharebar_bar_width', 1000);
        $swidth = variable_get('sharebar_bar_swidth', 75);
        $position = variable_get('sharebar_bar_position', 'left');
        $leftoffset = variable_get('sharebar_bar_leftoffset', 10);
        $rightoffset = variable_get('sharebar_bar_rightoffset', 10);
        drupal_add_js(drupal_get_path('module', 'sharebar') . '/js/sharebar.js');
        drupal_add_js('jQuery(document).ready(function($) { $(\'.sharebar\').sharebar({horizontal:\'' . $hori . '\',swidth:\'' . $swidth . '\',minwidth:' . $width . ',position:\'' . $position . '\',leftOffset:' . $leftoffset . ',rightOffset:' . $rightoffset . '}); });', 'inline');
      }
    }
  }
}

/**
 * Preprocess variables for region.tpl.php
 */
function sharebar_preprocess_page(&$variables) {
  global $theme;
  if (arg(0) != 'admin') {
    if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == '' && variable_get('sharebar_bar_posts_' . $variables['node']->type . '_enabled', TRUE) || !(arg(0) == 'node' && is_numeric(arg(1))) && arg(1) != 'add' && arg(2) != 'edit' && arg(3) != 'edit' && variable_get('sharebar_bar_pages_enabled', TRUE)) {
      $strh = '';
      $sbg = variable_get('sharebar_bar_background', 'FFFFFF');
      $sborder = variable_get('sharebar_bar_border', 'CCCCCC');
      $credit = variable_get('sharebar_bar_credit', TRUE);
      if (variable_get('sharebar_bar_oncontent', TRUE)) {
        if (variable_get('sharebar_bar_position', 'left') == 'left') {
          $mar = ' margin-right:' . variable_get('sharebar_bar_rightoffset', 10) . 'px;';
        }
        else {
          $mar = ' margin-left:' . variable_get('sharebar_bar_leftoffset', 10) . 'px;';
        }
        $cls = variable_get('sharebar_bar_idcontent', 'sharebarp');
        $sty = 'width: ' . variable_get('sharebar_bar_swidth', 75) . 'px; float: ' . variable_get('sharebar_bar_position', 'left') . ';' . $mar;
      }
      else {
        $cls = variable_get('sharebar_bar_id', 'sharebar');
        drupal_add_js(array(
          'sharebar' => array(
            'cls' => '#' . $cls,
          ),
        ), 'setting');
        $variables['scripts'] = drupal_get_js();
        $sty = '';
      }
      $str = '<ul id="' . $cls . '" style="background:#' . $sbg . ';border-color:#' . $sborder . ';margin-top:' . variable_get('sharebar_bar_toptoffset', 0) . 'px;' . $sty . '">';
      $buttons = unserialize(variable_get('sharebar_buttons', sharebar_buttons_def()));
      if (is_array($buttons) && count($buttons)) {
        usort($buttons, "sharebar_cmp_up");
        foreach ($buttons as $key => $value) {
          if ($value->enabled) {
            $str .= '<li>' . sharebar_bar_filter($value->big_button, drupal_get_title()) . '</li>';
          }
          if ($value->enabled && variable_get('sharebar_bar_horizontal', TRUE) && !variable_get('sharebar_bar_oncontent', TRUE)) {
            $strh .= '<li>' . sharebar_bar_filter($value->small_button, drupal_get_title()) . '</li>';
          }
        }
      }
      if ($credit) {
        $str .= '<li class="credit">' . l(t('Sharebar'), SHAREBAR_CREDIT_URL, array(
          'attributes' => array(
            'target' => '_blank',
          ),
        )) . '</li>';
      }
      $str .= '</ul>';
      if (variable_get('sharebar_bar_horizontal', TRUE)) {
        $str .= '<ul id="sharebarx">' . $strh . '</ul>';
      }
      $variables['content'] = $str . $variables['content'];
    }
  }
}

/**
 * Function to calculate higher weight & move up.
 */
function sharebar_cmp_up($a, $b) {
  return $a->weight > $b->weight;
}

/**
 * Function to calculate lower weight & move down.
 */
function sharebar_cmp_down($a, $b) {
  return $a->weight < $b->weight;
}

/**
 * Replaces dynamic data with their values.
 */
function sharebar_bar_filter($input, $title = '') {
  $name = '';
  if (arg(0) == 'node' && is_numeric(arg(1))) {
    $node = node_load(arg(1));
    if ($node->nid > 0) {
      $title = $node->title;
      $name = $node->name;
    }
  }
  $path = isset($_GET['q']) ? $_GET['q'] : '<front>';
  $currenturl = url($path, array(
    'absolute' => TRUE,
  ));
  $code = array(
    '[title]',
    '[url]',
    '[author]',
    '[twitter]',
  );
  $values = array(
    $title,
    $currenturl,
    $name,
    variable_get('sharebar_bar_twitter_username', 'themesnap'),
  );
  return str_replace($code, $values, $input);
}

/**
 * Does the very standard things that must be done in any normal callback.
 * Used by each ahah callback in this module.
 */
function sharebar_ahah_csscontainer_callback_helper() {
  $form_state = array(
    'storage' => NULL,
    'submitted' => FALSE,
  );
  $form_build_id = $_POST['form_build_id'];
  $form = form_get_cache($form_build_id, $form_state);
  $args = $form['#parameters'];
  $form_id = array_shift($args);
  $form_state['post'] = $form['#post'] = $_POST;

  // Enable the submit/validate handlers to determine whether AHAH-submittted.
  $form_state['ahah_submission'] = TRUE;
  $form['#programmed'] = $form['#redirect'] = FALSE;
  drupal_process_form($form_id, $form, $form_state);
  $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);
  return $form;
}

/**
 * Function to defines default values.
 */
function sharebar_buttons_def() {
  return 'a:10:{s:4:"digg";O:8:"stdClass":6:{s:12:"machine_name";s:4:"digg";s:4:"name";s:4:"digg";s:10:"big_button";s:317:"<script type="text/javascript">(function() { var s = document.createElement(\'SCRIPT\\), s1 = document.getElementsByTagName(\'SCRIPT\')[0]; s.type = \'text/javascript\'; s.async = true; s.src = \'http://widgets.digg.com/buttons.js\'; s1.parentNode.insertBefore(s, s1); })(); </script><a class="DiggThisButton DiggMedium"></a>";s:12:"small_button";s:318:"<script type="text/javascript">(function() { var s = document.createElement(\'SCRIPT\'), s1 = document.getElementsByTagName(\'SCRIPT\')[0]; s.type = \'text/javascript\'; s.async = true; s.src = \'http://widgets.digg.com/buttons.js\'; s1.parentNode.insertBefore(s, s1); })(); </script><a class="DiggThisButton DiggCompact"></a>";s:7:"enabled";i:1;s:6:"weight";s:1:"2";}s:7:"twitter";O:8:"stdClass":6:{s:12:"machine_name";s:7:"twitter";s:4:"name";s:7:"twitter";s:10:"big_button";s:217:"<a href="http://twitter.com/share" class="twitter-share-button" data-url="[url]"data-count="vertical" data-via="[twitter]">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>";s:12:"small_button";s:220:"<a href="http://twitter.com/share" class="twitter-share-button" data-url="[url]" data-count="horizontal" data-via="[twitter]">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>";s:7:"enabled";i:1;s:6:"weight";s:1:"0";}s:8:"facebook";O:8:"stdClass":6:{s:12:"machine_name";s:8:"facebook";s:4:"name";s:8:"facebook";s:10:"big_button";s:447:"<div id="fb-root"></div> <script>(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_US/all.js#xfbml=1"; fjs.parentNode.insertBefore(js, fjs); }(document, \'script\', \'facebook-jssdk\'));</script> <html xmlns:fb="http://ogp.me/ns/fb#"> <fb:like href="[url]" send="true" layout="box_count" width="450" show_faces="true"></fb:like>";s:12:"small_button";s:450:"<div id="fb-root"></div> <script>(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_US/all.js#xfbml=1"; fjs.parentNode.insertBefore(js, fjs); }(document, \'script\', \'facebook-jssdk\'));</script> <html xmlns:fb="http://ogp.me/ns/fb#"> <fb:like href="[url]" send="true" layout="button_count" width="450" show_faces="true"></fb:like>";s:7:"enabled";i:1;s:6:"weight";s:1:"1";}s:6:"reddit";O:8:"stdClass":6:{s:12:"machine_name";s:6:"reddit";s:4:"name";s:6:"reddit";s:10:"big_button";s:89:"<script type="text/javascript" src="http://reddit.com/static/button/button2.js"></script>";s:12:"small_button";s:89:"<script type="text/javascript" src="http://reddit.com/static/button/button1.js"></script>";s:7:"enabled";i:1;s:6:"weight";s:1:"4";}s:5:"dzone";O:8:"stdClass":6:{s:12:"machine_name";s:5:"dzone";s:4:"name";s:5:"dzone";s:10:"big_button";s:94:"<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script>";s:12:"small_button";s:94:"<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script>";s:7:"enabled";i:1;s:6:"weight";s:1:"5";}s:11:"stumbleupon";O:8:"stdClass":6:{s:12:"machine_name";s:11:"stumbleupon";s:4:"name";s:11:"stumbleupon";s:10:"big_button";s:70:"<script src="http://www.stumbleupon.com/hostedbadge.php?s=5"></script>";s:12:"small_button";s:70:"<script src="http://www.stumbleupon.com/hostedbadge.php?s=2"></script>";s:7:"enabled";i:1;s:6:"weight";s:1:"3";}s:11:"designfloat";O:8:"stdClass":6:{s:12:"machine_name";s:11:"designfloat";s:4:"name";s:11:"designfloat";s:10:"big_button";s:150:"<script type="text/javascript">submit_url = \'[url]\';</script><script type="text/javascript" src="http://www.designfloat.com/evb2/button.php"></script>";s:12:"small_button";s:149:"<script type="text/javascript">submit_url = \'[url]\';</script><script type="text/javascript" src="http://www.designfloat.com/evb/button.php"></script>";s:7:"enabled";i:1;s:6:"weight";s:1:"6";}s:5:"email";O:8:"stdClass":6:{s:12:"machine_name";s:5:"email";s:4:"name";s:5:"email";s:10:"big_button";s:71:"<a href="mailto:?subject=[url]" class="sharebar-button email">Email</a>";s:12:"small_button";s:71:"<a href="mailto:?subject=[url]" class="sharebar-button email">Email</a>";s:7:"enabled";i:1;s:6:"weight";s:1:"7";}s:8:"linkedin";O:8:"stdClass":6:{s:12:"machine_name";s:8:"linkedin";s:4:"name";s:8:"linkedin";s:10:"big_button";s:158:"<script src="//platform.linkedin.com/in.js" type="text/javascript">
 lang: en_US</script><script type="IN/Share" data-url="[url]" data-counter="top"></script>";s:12:"small_button";s:160:"<script src="//platform.linkedin.com/in.js" type="text/javascript">
 lang: en_US</script><script type="IN/Share" data-url="[url]" data-counter="right"></script>";s:7:"enabled";i:1;s:6:"weight";s:3:"-50";}s:10:"googleplus";O:8:"stdClass":6:{s:12:"machine_name";s:10:"googleplus";s:4:"name";s:10:"googleplus";s:10:"big_button";s:462:"<!-- Place this tag where you want the +1 button to render. -->
<div class="g-plusone" data-size="tall" data-href="[url]"></div><!-- Place this tag after the last +1 button tag. -->
<script type="text/javascript">(function() {var po = document.createElement(\'script\'); po.type = \'text/javascript\'; po.async = true;po.src = \'https://apis.google.com/js/plusone.js\';var s = document.getElementsByTagName(\'script\')[0]; s.parentNode.insertBefore(po, s);})();</script>";s:12:"small_button";s:443:"<!-- Place this tag where you want the +1 button to render. --><div class="g-plusone" data-href="[url]"></div><!-- Place this tag after the last +1 button tag. --><script type="text/javascript">(function() {var po = document.createElement(\'script\'); po.type = \'text/javascript\'; po.async = true;po.src = \'https://apis.google.com/js/plusone.js\';var s = document.getElementsByTagName(\'script\')[0]; s.parentNode.insertBefore(po, s);})();</script>";s:7:"enabled";i:1;s:6:"weight";s:3:"-50";}}';
}

Functions

Namesort descending Description
sharebar_ahah_csscontainer_callback_helper Does the very standard things that must be done in any normal callback. Used by each ahah callback in this module.
sharebar_bar_filter Replaces dynamic data with their values.
sharebar_buttons_def Function to defines default values.
sharebar_cmp_down Function to calculate lower weight & move down.
sharebar_cmp_up Function to calculate higher weight & move up.
sharebar_init Implements hook_init().
sharebar_menu Implements hook_menu().
sharebar_perm Implements hook_perm().
sharebar_preprocess_page Preprocess variables for region.tpl.php
sharebar_theme Implements hook_theme().

Constants

Namesort descending Description
SHAREBAR_CREDIT_URL @file Various module information.