'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_tab_names'] = array( '#type' => 'fieldset', '#title' => t("Tab Names"), '#description' => t("Set names for the tabs provided in the Share popup."), '#collapsible' => TRUE, '#collapsed' => FALSE ); $form['share_tab_names']['share_tab_social'] = array( '#type' => 'textfield', '#title' => t("Service Links Tab"), '#default_value' => variable_get('share_tab_social', t("Social Web")), '#required' => FALSE ); $form['share_tab_names']['share_tab_email'] = array( '#type' => 'textfield', '#title' => t("E-mail Tab"), '#default_value' => variable_get('share_tab_email', t("E-mail")), '#required' => FALSE ); $form['share_name'] = array( '#type' => 'textfield', '#title' => t("Share Link Name"), '#description' => t("Enter the name you would like to give your share link."), '#default_value' => variable_get('share_name', 'Share') ); $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()), '#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) { 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': $share = array( 'collapsible' => variable_get('share_block_collapsible', 1), 'collapsed' => variable_get('share_block_collapsed', 0) ); drupal_add_js(array('share' => $share), 'setting'); 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'), '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())); 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 = l(t('Close'), '', array('class' => 'share_close', 'onclick' => 'return false;')); } 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()); $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'); } }