You are here

function yashare_build in Yandex.Share 7

Generate renderable array.

4 calls to yashare_build()
yashare_block_view in ./yashare.block.inc
Implements hook_block_view().
yashare_node_view in ./yashare.module
Implements hook_node_view().
yashare_render in ./yashare.module
Render Yandex.Share block.
yashare_taxonomy_term_view_alter in ./yashare.module
Implements hook_taxonomy_term_view_alter().

File

./yashare.module, line 195

Code

function yashare_build($id = NULL, $link = NULL, $title = NULL, $description = NULL, $type = NULL) {
  if (!$id) {
    static $counter = NULL;
    if (NULL == $counter) {
      $counter = 0;
    }
    $id = 'auto-' . $counter++;
  }
  $block_id = 'yashare-' . $id;
  $params = array(
    'element' => $block_id,
    'l10n' => yashare_get_language(TRUE),
  );
  if (variable_get('yashare_image', FALSE)) {
    $params['image'] = theme_get_setting('logo');
  }
  if ($link) {
    $params['link'] = url(drupal_get_path_alias($link), array(
      'absolute' => TRUE,
    ));
  }
  if ($title) {
    $params['title'] = check_plain($title . ' | ' . variable_get('site_name', 'Drupal'));
  }
  if ($description) {
    $params['description'] = check_plain($description);
  }
  $params['elementStyle'] = array(
    'text' => check_plain(variable_get('yashare_block_title', '')),
    'type' => $type ? check_plain($type) : variable_get('yashare_type', 'button'),
    'border' => variable_get('yashare_border', FALSE),
    'linkUnderline' => variable_get('yashare_linkunderline', FALSE),
    'linkIcon' => variable_get('yashare_linkicon', FALSE),
    'quickServices' => yashare_get_block_services(),
  );
  $popup_title = variable_get('yashare_popup_title', '');
  $params['popupStyle'] = array(
    'blocks' => $popup_title ? array(
      check_plain($popup_title) => yashare_get_popup_services(),
    ) : yashare_get_popup_services(),
    'copyPasteField' => variable_get('yashare_popup_link', FALSE),
  );
  if (variable_get('yashare_popup_codeforblog', FALSE) && isset($params['title']) && isset($params['link'])) {
    $params['popupStyle']['codeForBlog'] = l($params['title'], $params['link'], array(
      'attributes' => array(
        'title' => $params['title'],
        'target' => '_blank',
      ),
    ));
  }
  if ($vdirection = variable_get('yashare_popup_vdirection', 0)) {
    $params['popupStyle']['vDirection'] = $vdirection;
  }
  $element = array(
    '#type' => 'html_tag',
    '#tag' => 'span',
    '#attributes' => array(
      'id' => $block_id,
    ),
    '#value' => '',
  );
  $element['#attached']['js'] = array(
    '//yandex.st/share/share.js' => array(
      'type' => 'external',
      'scope' => 'footer',
      'weight' => 10,
    ),
    drupal_get_path('module', 'yashare') . '/yashare.js' => array(
      'scope' => 'footer',
      'weight' => 11,
    ),
  );
  $element['#attached']['js'][] = array(
    'data' => array(
      'yashare' => array(
        $block_id => $params,
      ),
    ),
    'type' => 'setting',
  );
  return $element;
}