You are here

function sharebar_preprocess_page in ShareBar 6

Same name and namespace in other branches
  1. 8 sharebar.module \sharebar_preprocess_page()

Preprocess variables for region.tpl.php

File

./sharebar.module, line 112
Various module information.

Code

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'];
    }
  }
}