'share', 'title' => t("Share"), 'description' => t("Share this page"), 'callback' => 'share_page', 'callback arguments' => array($arg1), 'type' => MENU_CALLBACK, 'access' => node_access('view', node_load($arg1)) ); } } else { $items[] = array( 'path' => 'admin/settings/share', 'title' => t('Share'), 'callback' => 'drupal_get_form', 'callback arguments' => array('share_settings'), 'access' => user_access('administer share') ); } return $items; } function share_settings() { $form['share_effects'] = array( '#type' => 'checkbox', '#title' => t("Effects"), '#description' => t("Add animation to the opening and closing of the Share popup."), '#default_value' => variable_get('share_effects', 0) ); // Link Codes $form['share_link_codes'] = array( '#type' => 'checkboxes', '#title' => t("Link Codes"), '#description' => t("Provide generated link code(s) that points to the node."), '#default_value' => variable_get('share_link_codes', array('direct' => 0, 'html' => 0, 'forum' => 0)), '#options' => array('direct' => t("Direct Url"), 'html' => t("HTML Code"), 'forum' => t("Forum Code")) ); return system_settings_form($form); } /** * Implementation of hook_form_alter(). */ function share_form_alter($form_id, &$form) { if ($form_id == 'service_links_admin_settings') { drupal_add_js(drupal_get_path('module', 'share').'/js/settings.js'); $form['how_to_show_the_links']['service_links_in_node']['#default_value'] = variable_get('service_links_in_node', 0); $form['how_to_show_the_links']['share'] = array( '#type' => 'fieldset', '#title' => t("Share"), '#description' => t("If Share is used, only one way of showing service links is allowed."), '#collapsible' => TRUE, '#collapsed' => FALSE, '#weight' => -1 ); $form['how_to_show_the_links']['share']['service_links_in_share_node'] = array( '#type' => 'select', '#title' => t('Share service links in nodes'), '#default_value' => variable_get('service_links_in_share_node', 2), '#options' => array(0 => t('Disabled'), 1 => t('Teaser view'), 2 => t('Full-page view'), 3 => t('Teasers and full-page view')), '#description' => t('When to display the services after the node text.') ); $form['how_to_show_the_links']['share']['service_links_in_share_links'] = array( '#type' => 'select', '#title' => t('Share service links in links'), '#default_value' => variable_get('service_links_in_share_links', 0), '#options' => array(0 => t('Disabled'), 1 => t('Teaser view'), 2 => t('Full-page view'), 3 => t('Teasers and full-page view')), '#description' => t('When to display the services after the node text.') ); $form['how_to_show_the_links']['share_message'] = array( '#type' => 'item', '#value' => '
' ); $form['how_to_show_the_links']['service_links_style']['#weight'] = 1; $form['#validate']['share_service_links_validate'] = array(); } if ($form_id == 'forward_admin_settings') { $form['forward_options']['forward_form_type']['#options']['share_link'] = 'Link in Share'; $form['forward_options']['forward_form_type']['#options']['share_form'] = 'Form in Share'; $form['share']['share_forward'] = array( '#type' => 'checkbox', '#title' => t("Share Forward Form"), '#description' => t("Always show Forward form as a tab in the Share popup."), '#default_value' => variable_get('share_forward', 0) ); $form['buttons']['#weight'] = 2; } } function share_service_links_validate($form_id, $form_values) { if ($form_values['service_links_in_share_node'] > 0) { if ($form_values['service_links_in_links'] > 0) { form_set_error('service_links_in_links', "'Share service links in node' cannot be enabled if 'Service links in links' is also enabled."); } if ($form_values['service_links_in_node'] > 0) { form_set_error('service_links_in_node', "'Share service links in node' cannot be enabled if 'Service links in node' is also enabled."); } if ($form_values['service_links_in_share_links'] > 0) { form_set_error('service_links_in_share_links', "'Share service links in node' cannot be enabled if 'Share service links in links' is also enabled."); } } if ($form_values['service_links_in_share_links'] > 0) { if ($form_values['service_links_in_links'] > 0) { form_set_error('service_links_in_links', "'Share service links in links' cannot be enabled if 'Service links in links' is also enabled."); } if ($form_values['service_links_in_node'] > 0) { form_set_error('service_links_in_node', "'Share service links in links' cannot be enabled if 'Service links in node' is also enabled."); } if ($form_values['service_links_in_share_node'] > 0) { form_set_error('service_links_in_share_node', "'Share service links in links' cannot be enabled if 'Share service links in node' is also enabled."); } } } /** * Implementation of hook_nodeapi(). */ function share_nodeapi(&$node, $op, $teaser, $page) { switch ($op) { case 'view': if (variable_get('service_links_in_share_node', 2) > 0) { $links_show = _service_links_show($node->type, $node->nid); if ($links_show && user_access('use service links')) { $share_view = variable_get('service_links_in_share_node', 2); switch ($share_view) { case "1": if ($teaser) { $node = share_display('node', $node); } break; case "2": if ($page) { $node = share_display('node', $node); } break; case "3": if ($teaser) { $node = share_display('node', $node); } if ($page) { $node = share_display('node', $node); } break; } } } break; } } /** * Implementation of hook_link(). */ function share_link($type, $node = NULL, $teaser = FALSE) { if (variable_get('service_links_in_share_links', 0) > 0) { $links_show = _service_links_show($node->type, $node->nid); if ($links_show && user_access('use service links')) { $links = array(); $share_view = variable_get('service_links_in_share_links', 0); switch ($share_view) { case "1": if ($teaser) { $links['share_group_'.$node->nid.' share'] = share_display('link', $node); } break; case "2": if (!$teaser) { $links['share_group_'.$node->nid.' share'] = share_display('link', $node); } break; case "3": $links['share_group_'.$node->nid.' share'] = share_display('link', $node); break; } return $links; } } } /** * Implementation of hook_block(). */ function share_block($op = 'list', $delta = 0, $edit = array()) { switch ($op) { case 'list': $blocks[0]['info'] = t('Share'); return $blocks; case 'configure': switch ($delta) { case 0: $form['share_block_collapsible'] = array( '#type' => 'checkbox', '#title' => t('Share Block Collapsible'), '#description' => t('Whether the Share block is collapsible.'), '#default_value' => variable_get('share_block_collapsible', 1) ); $form['share_block_collapsed'] = array( '#type' => 'checkbox', '#title' => t('Share Block Collapsed'), '#description' => t('Whether the Share block is initially collapsed or not.'), '#default_value' => variable_get('share_block_collapsed', 0) ); } return $form; case 'save': switch ($delta) { case 0: variable_set('share_block_collapsible', $edit['share_block_collapsible']); variable_set('share_block_collapsed', $edit['share_block_collapsed']); } return; case 'view': default: switch ($delta) { case 0: if (user_access('use service links')) { if (arg(0) == 'node' && is_numeric(arg(1)) && !arg(2)) { theme('share_css', TRUE); $node = node_load(arg(1)); $links_show = _service_links_show($node->type, $node->nid); if ($links_show) { $block['content'] = $content = share_display('block', $node); } } } break; } return $block; } } function share_display($type,$node) { static $share = NULL; if ($share == NULL) { $share = array( 'collapsible' => variable_get('share_block_collapsible', 1), 'collapsed' => variable_get('share_block_collapsed', 0) ); drupal_add_js(array('share' => $share), 'setting'); } switch ($type) { case 'node': $node->content['service_links'] = array( '#value' => ' ', '#weight' => 10 ); return $node; case 'link': $link = array( 'title' => share_render($node, TRUE), 'html' => TRUE, 'attributes' => array('id' => 'share_'.$node->nid) ); return $link; case 'block': return ' '; } } function share_render($node, $is_link = FALSE, $is_block = FALSE) { $service_links = service_links_render($node, FALSE); $links = ''; foreach ($service_links as $service) { if (!is_array($service)) { $links.= $service; } } $output = ''; if (!empty($links)) { theme('share_css'); if (variable_get('share_effects', 0)) { drupal_add_js(drupal_get_path('module', 'share').'/js/share_effects.js'); } else { drupal_add_js(drupal_get_path('module', 'share').'/js/share.js'); } $nid = $node->nid; if ($is_block) { $nid = 'block'; } if (!$is_link) { $output.= ' '; } } return $output; } function _share_get_tabs() { $codes = NULL; $count = array_count_values(variable_get('share_link_codes', array('direct' => 0, 'html' => 0, 'forum' => 0))); if ($count[0] < 3 || !isset($count[0])) { $codes = '".$data->social['title']." | "; if ($data->forward['title']) { $output .= "".$data->forward['title']." | "; } $output .= "
---|---|
".$links." | "; if ($data->forward['form']) { $output .= "".$data->forward['form']." | "; } $output .= "
".$data->node." |