You are here

function share42_block in Share42 - social sharing buttons 6

Implements hook_block().

File

./share42.module, line 34
Main file for the Share42 module.

Code

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,
    );
  }
}