'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' => ' ', '#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." |