'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() { $types = array(t("--NONE--"), 'share_this' => t("Share this")); if (module_exists('service_links')) { $types["service_links"] = t("Service links"); } $form['share_type'] = array( '#type' => 'select', '#title' => t("Share Type"), '#description' => t("Select the type of Share links."), '#default_value' => variable_get('share_type', 0), '#options' => $types ); // Share This $form['share_this_settings'] = array( '#type' => 'fieldset', '#title' => t('Share This Settings'), '#description' => t('These settings only take affect if Share This is the Share type selected above. Share This requires javascript to be enabled.'), '#collapsible' => TRUE, '#collapsed' => TRUE ); $form['share_this_settings']['where_to_share_share_this'] = array( // Where to Share '#type' => 'fieldset', '#title' => t('Where to Share'), '#description' => t('Set the node types and categories you want to display links for.'), '#collapsible' => TRUE ); $form['share_this_settings']['where_to_share_share_this']['share_share_this_node_types'] = array( '#type' => 'checkboxes', '#title' => t('Node types'), '#default_value' => variable_get('share_share_this_node_types', array()), '#options' => node_get_types('names') ); if (module_exists('taxonomy')) { $terms = taxonomy_form_all(); if (!empty($terms)) { $form['share_this_settings']['where_to_share_share_this']['share_share_this_category_types'] = array( '#type' => 'select', '#multiple' => TRUE, '#title' => t('Categories'), '#default_value' => variable_get('share_share_this_category_types', array()), '#options' => taxonomy_form_all() ); } } $form['share_this_settings']['where_to_share_share_this']['share_share_this_where'] = array( '#type' => 'select', '#title' => t('Where'), '#default_value' => variable_get('share_share_this_where', 0), '#options' => array(t('Links'), t('Nodes')) ); $share_code = ''; $form['share_this_settings']['share_share_this_code'] = array( '#type' => 'textarea', '#title' => t('Share This Code'), '#description' => t('Javascript code provided by Share This. You can generate your own code !here.', array('!here' => l(t('here'), 'http://sharethis.com/publisher?type=stapi'))), '#default_value' => variable_get('share_share_this_code', $share_code) ); // Service Links $form['service_links_settings'] = array( '#type' => 'fieldset', '#title' => t('Service Links Settings'), '#description' => t('These settings only take affect if Service Links is the Share type selected above, and Share is enabled on the !service_links page.', array('!service_links' => l(t('Service Links settings'), 'admin/settings/servicelinks'))), '#collapsible' => TRUE, '#collapsed' => TRUE ); $form['service_links_settings']['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) ); $form['service_links_settings']['share_link_codes'] = array( // Link Codes '#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': switch (variable_get('share_type', 0)) { case "share_this": if (variable_get('share_share_this_where', 0) == '1') { static $share = 0; if (_share_share_this_show($node->type, $node->nid) && user_access('use share this')) { if ($share == '0') { $share++; drupal_set_html_head(variable_get('share_share_this_code', 0)); } $node->content['share_share_this'] = array( '#value' => "", '#weight' => 10 ); } } break; case "service_links": 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; } break; } } /** * Implementation of hook_link(). */ function share_link($type, $node = NULL, $teaser = FALSE) { switch (variable_get('share_type', 0)) { case "share_this": if (variable_get('share_share_this_where', 0) == '0') { static $share = 0; if (_share_share_this_show($node->type, $node->nid) && user_access('use share this')) { if ($share == '0') { $share++; drupal_set_html_head(variable_get('share_share_this_code', 0)); } $links['share_share_this'] = array( 'title' => "", 'html' => TRUE, 'attributes' => array('id' => 'share_'.$node->nid) ); return $links; } } break; case "service_links": 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; } } break; } } /** * 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' => '
'.share_render($node).'
', '#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 '
'.share_render($node, FALSE, TRUE).'
'; } } 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.= '
'; } $output.= l(t('Share'), base_path().'share/'.$node->nid, array('class' => 'share_link', 'onclick' => 'return false;')); $output.= ''; 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 = '
  • '.l(t('Link Codes'), '', array('onclick' => 'return false;')).'
  • '; } $forward = NULL; $form_type = variable_get('forward_form_type', 'link'); if (module_exists('forward') && user_access('access forward') && ($form_type = 'share_form' || variable_get('share_forward', 0))) { $forward = '
  • '.l(t('E-Mail'), '', array('onclick' => 'return false;')).'
  • '; } if (variable_get('share_forward', 0)) { $close = NULL; if (variable_get('share_block_collapsible', 1)) { $close = ''.t('Close').''; } return $close. ''; } } function _share_get_content($links, $nid) { $output = '
    '; $output.= ''; $output.= '
    '; $form_type = variable_get('forward_form_type', 'link'); if (module_exists('forward') && user_access('access forward') && ($form_type == 'share_form' || variable_get('share_forward', 0))) { $output.= ''; } $link_codes = variable_get('share_link_codes', array('direct' => 0, 'html' => 0, 'forum' => 0)); $count = array_count_values($link_codes); if ($count[0] < 3 || !isset($count[0])) { drupal_add_js(drupal_get_path('module', 'share').'/js/link_codes.js'); $output.= ''; } $output.= '
    '; return $output; } function _share_get_link_codes($op, $nid) { $node = node_load($nid); switch ($op) { case "direct": return ''; case "html": return ''; case "forum": return ''; } } function share_form($nid = null) { global $base_url, $user; $form = array(); if ($nid != '') { $emailtype = 'email'; $form['node'] = array('#type' => 'value', '#value' => node_load((int)$nid)); } else { $emailtype = 'postcard'; } $form['yemail'] = array( '#type' => 'textfield', '#title' => t('Your Email'), '#default_value' => $user->mail, '#size' => 30, '#maxlength' => 256, '#description' => null, '#attributes' => null, '#required' => true, ); $form['yname'] = array( '#type' => 'textfield', '#title' => t('Your Name'), '#default_value' => $user->name, '#size' => 30, '#maxlength' => 256, '#description' => null, '#attributes' => null, '#required' => true, ); $form['recipients'] = array( '#type' => 'textfield', '#title' => t('Send To'), '#default_value' => str_replace(', ', "\n", $recipients), '#size' => 30, '#description' => t('Enter one address or multiple addresses separated with commas.'), '#attributes' => null, '#required' => true, ); $form['message'] = array( '#type' => 'hidden', '#value' => ' ', ); $form['nid'] = array( '#type' => 'hidden', '#value' => $nid, ); $form['forward_footer'] = array( '#type' => 'hidden', '#value' => variable_get('forward_footer', ''), ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Send'), ); $form['#validate'] = array( 'forward_form_validate' => array() ); $form['#submit'] = array( 'forward_form_submit' => array() ); return $form; } function share_forms() { # get the form id $args = func_get_args(); $form_id = $args[0][0]; # Ensure we map a callback for our form and not something else $forms = array(); if (strpos($form_id, "share_form") === 0) { # Let the forms API know where to get the form data corresponding # to this form id. $forms[$form_id] = array('callback' => 'share_form'); } return $forms; } function share_page($nid) { $node = node_load($nid); $data->description = t("From this page you can share %title to a social bookmarking site or email a link to the page.", array('%title' => $node->title)); if (variable_get('service_links_in_share_node', 2) > 0 || 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')) { $data->social['title'] = t("Social Web"); $data->social['links'] = service_links_render($node, TRUE); if (function_exists('forward_form')) { $data->forward['title'] = t("E-mail"); $data->forward['form'] = drupal_get_form('forward_form', $nid); } $data->node = node_view($node); return theme('share_page',$data); } } drupal_not_found(); } function theme_share_page($data) { $links = ''; $output = $data->description; $output .= ""; if ($data->forward['title']) { $output .= ""; } $output .= ""; $output .= ""; if ($data->forward['form']) { $output .= ""; } $output .= ""; $colspan = $data->forward?" colspan='2'":NULL; $output .= "".$data->node."
    ".$data->social['title']."".$data->forward['title']."
    ".$links."".$data->forward['form']."
    "; return $output; } function theme_share_css($block = FALSE) { if (!$block) { drupal_add_css(drupal_get_path('module', 'share'). '/share.css', 'theme', 'screen'); } else { drupal_add_css(drupal_get_path('module', 'share'). '/share_block.css', 'theme', 'screen'); } } /** * Check if the service links should be displayed for the node type/category. */ function _share_share_this_show($type, $nid) { $links_show = FALSE; $node_type = in_array($type, variable_get('share_share_this_node_types', array()), TRUE); if (module_exists('taxonomy')) { $terms = taxonomy_node_get_terms($nid); foreach ($terms as $term) { $category_type = in_array($term->tid, variable_get('share_share_this_category_types', array()), FALSE); } } if ($node_type || $category_type) { $links_show = TRUE; } return $links_show; }