'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_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) ); return system_settings_form($form); } /** * Implementation of hook_form_alter(). */ function share_form_alter($form_id, &$form) { if ($form_id == 'service_links_admin_settings') { $form['share'] = array( '#type' => 'fieldset', '#title' => t("Share"), '#description' => t("Extra features settings."), '#weight' => 1, '#collapsible' => TRUE, '#collapsed' => TRUE ); $form['share']['share_service_links'] = array( '#type' => 'checkbox', '#title' => t("Group Service Links"), '#description' => t("This will provide just one general link that opens a javascript window holding all the service links. If the viewer does not have javascript enabled, this settings makes no effect."), '#default_value' => variable_get('share_service_links', 0), '#required' => FALSE ); $form['#validate']['share_service_links_validate'] = array(); $form['buttons']['#weight'] = 2; } if ($form_id == 'forward_admin_settings') { $form['share'] = array( '#type' => 'fieldset', '#title' => t("Share"), '#description' => t("Extra features settings."), '#weight' => 1, '#collapsible' => TRUE, '#collapsed' => TRUE ); $form['share']['share_forward'] = array( '#type' => 'checkbox', '#title' => t("Group With Service Links"), '#description' => t("This will provide the forward link inside the Share link provided by Share module. If the form type selected above is link, it will be displayed in the same list as the Service Links. If the form type is share_form, it will be displayed in a tab."), '#default_value' => variable_get('share_forward', 0) ); $form['share']['share_forward_form'] = array( '#type' => 'checkbox', '#title' => t("Show Forward Form"), '#description' => t("Show Forward form as a tab in Share popup if form type is set to 'link'."), '#default_value' => variable_get('share_forward_form', 0) ); $form['buttons']['#weight'] = 2; $form['forward_options']['forward_show_teasers']['#description'] .= ". If Forward is set to 'Group with Service Links' then this does not take affect, change on Service Links settings page to display in teasers."; $form['forward_options']['forward_form_type']['#options']['share'] = 'share_form'; } } function share_service_links_validate($form_id, $form) { if ($form['share_service_links'] == 1) { if ($form['service_links_in_node'] != 0 && $form['service_links_in_links'] != 0) { form_set_error('service_links_in_links',"Share works correctly only if Service Links is displayed in either links or nodes, but not both. Please disabled one."); form_set_error('service_links_in_node'," "); } /*if ($form['service_links_in_links'] == 1 || $form['service_links_in_links'] == 3) { form_set_error('service_links_in_links',"Teasers do not work at this time with Share module. Please either turn off 'Group Service Links' or change 'Service links in nodes' to 'Disabled' or 'Full-page view'."); } if ($form['service_links_in_node'] == 1 || $form['service_links_in_node'] == 3) { form_set_error('service_links_in_node',"Teasers do not work at this time with Share module. Please either turn off 'Group Service Links' or change 'Service links in nodes' to 'Disabled' or 'Full-page view'."); }*/ } } /** * Implementation of hook_nodeapi(). */ function share_nodeapi(&$node, $op, $teaser, $page) { if (variable_get('share_service_links', 0) == 1) { $links_show = _service_links_show($node->type, $node->nid); if ($links_show && user_access('use service links')) { $node_links = variable_get('service_links_in_node', 0); switch ($op) { case 'view': switch ($node_links) { case "1": if ($teaser) { $node = share_link_display('node',$node); } break; case "2": if ($page) { $node = share_link_display('node',$node); } break; case "3": if ($teaser) { $node = share_link_display('node',$node); } if ($page) { $node = share_link_display('node',$node); } break; } break; } } } } /** * Implementation of hook_link(). */ function share_link($type, $node = NULL, $teaser = FALSE) { $links = array(); if (variable_get('share_service_links', 0) == 1) { $links_show = _service_links_show($node->type, $node->nid); if ($links_show && user_access('use service links')) { $link_links = variable_get('service_links_in_links', 0); switch ($link_links) { case "1": if ($teaser) { $links['share'.$node->nid.'_group share'] = share_link_display('link',$node); } break; case "2": if (!$teaser) { $links['share'.$node->nid.'_group share'] = share_link_display('link',$node); } break; case "3": $links['share'.$node->nid.'_group share'] = share_link_display('link',$node); break; } return $links; } } } /** * Implementation of hook_link_alter(). */ function share_link_alter(&$node, &$links) { if (variable_get('share_service_links', 0) == 1) { $links_show = _service_links_show($node->type, $node->nid); if ($links_show && user_access('use service links')) { $links_links = variable_get('service_links_in_links', 0); if ($links_links != 0) { $forward_form = share_forward_formtype($node->nid); if ($forward_form != '') { $menu = ""; } else { $menu = NULL; } $share_links = ''; if ($share_links != '') { drupal_add_js("$('li.share".$node->nid."_group').append(".drupal_to_js($share_links).');', 'inline', 'footer'); } } } } } function share_link_display($type,$node) { switch ($type) { case 'node': drupal_add_js(drupal_get_path('module', 'share').'/share.js'); drupal_add_js(array('share' => array('effects' => variable_get('share_effects', 0))), 'setting'); theme('share_css'); $forward_form = share_forward_formtype($node->nid); if ($forward_form != '') { $menu = ""; } else { $menu = NULL; } $node->content['service_links']['#value'] = preg_replace('/
[a-zA-Z\/ :]*<\/div>/','',$node->content['service_links']['#value']); $node->content['service_links']['#value'] = "
"; return $node; break; case 'link': drupal_add_js(drupal_get_path('module', 'share').'/share.js'); drupal_add_js(array('share' => array('effects' => variable_get('share_effects', 0))), 'setting'); theme('share_css'); return array( 'title' => t("Share"), 'href' => "share/".$node->nid, 'attributes' => array( 'title' => t("Share this page"), 'onclick' => 'return false;', 'id' => 'share'.$node->nid ), 'html' => 1 ); break; } } function share_forward_formtype($nid, $block = FALSE) { if (variable_get('forward_form_type', 'link') == 'share' || (variable_get('forward_form_type', 'link') == 'link' && variable_get('share_forward_form', 0) == 1)) { if ($block) { return drupal_get_form('share_form_block', $nid); } else { return drupal_get_form('share_form'.$nid, $nid); } } else { 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' => 24, '#maxlength' => 256, '#description' => null, '#attributes' => null, '#required' => true, ); $form['yname'] = array( '#type' => 'textfield', '#title' => t('Your Name'), '#default_value' => $user->name, '#size' => 24, '#maxlength' => 256, '#description' => null, '#attributes' => null, '#required' => true, ); $form['recipients'] = array( '#type' => 'textfield', '#title' => t('Send To'), '#default_value' => str_replace(', ', "\n", $recipients), '#size' => 24, '#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() ); $form['#attributes']['style'] = 'display: none;'; 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('share_service_links', 0) == 1) { $links_show = _service_links_show($node->type, $node->nid); if ($links_show && user_access('use service links')) { $node_links = variable_get('service_links_in_node', 0); $link_links = variable_get('service_links_in_links', 0); if ($node_links != 0 || $link_links != 0) { $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); } 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() { drupal_add_css(drupal_get_path('module', 'share'). '/share.css', 'theme', 'screen'); } /** * 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': if ($delta == 0) { $form['share_block_collapsed'] = array( '#type' => 'checkbox', '#title' => t('Collapsed'), '#description' => t('If the block should be collapsed initially.'), '#default_value' => variable_get('share_block_collapsed',1) ); $form['share_block_link'] = array( '#type' => 'textfield', '#title' => t('Link Name'), '#description' => t('Name the title for the block.'), '#default_value' => variable_get('share_block_link',t('Share')) ); } return $form; case 'save': if ($delta == 0) { variable_set('share_block_collapsed',$edit['share_block_collapsed']); variable_set('share_block_link',$edit['share_block_link']); } return; case 'view': default: switch ($delta) { case '0': if (arg(0) == 'node' && is_numeric(arg(1))) { $node = node_load(arg(1)); } if (variable_get('share_service_links', 0) == 1) { $links_show = _service_links_show($node->type, $node->nid); if ($links_show && user_access('use service links')) { $node_links = variable_get('service_links_in_node', 0); $link_links = variable_get('service_links_in_links', 0); if ($node_links != 0 || $link_links != 0) { $links = ''; drupal_add_js(drupal_get_path('module', 'share').'/share_block.js'); drupal_add_js(array('share' => array('block' => 1)), 'setting'); $link = "".variable_get('share_block_link',t('Share')).""; if (variable_get('share_block_collapsed', 1) == 1) { $show = " style='display: none;'"; } else { $show = NULL; } $output = "
". "
".$forward_form = share_forward_formtype($node->nid, TRUE)."
"; $block['subject'] = $link; $block['content'] = $output; } } } } return $block; } }