'admin/build/share', 'title' => t('Share'), 'description' => t('Manage Share popups'), 'callback' => 'share_admin_popups', 'access' => user_access('administer share') ); $items[] = array( 'path' => 'admin/build/share/list', 'title' => t("List"), 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -1, ); $items[] = array( 'path' => 'admin/build/share/add', 'title' => t('Add popup'), 'description' => t('Add a new Share popup.'), 'callback' => 'drupal_get_form', 'callback arguments' => array('share_admin_popups_add'), 'type' => MENU_LOCAL_TASK ); $items[] = array( 'path' => 'admin/build/share/add/share', 'title' => t('Share'), 'callback' => 'drupal_get_form', 'callback arguments' => array('share_admin_popups_share_form'), 'type' => MENU_CALLBACK, 'access' => share_add_share_access() ); $items[] = array( 'path' => 'admin/build/share/add/sharethis', 'title' => t('ShareThis'), 'callback' => 'drupal_get_form', 'callback arguments' => array('share_admin_popups_sharethis_form'), 'type' => MENU_CALLBACK ); } else { if (arg(0) == 'admin' && arg(1) == 'build' && arg(2) == 'share') { $path = drupal_get_path('module', 'share'); require_once("$path/share_admin.inc"); } if (arg(3) == 'share' || arg(3) == 'sharethis') { switch (arg(3)) { case 'share': $title = t('Share'); break; case 'sharethis': $title = t('ShareThis'); break; } $items[] = array( 'path' => 'admin/build/share/'. arg(3) .'/'. arg(4) .'/edit', 'title' => $title, 'callback' => 'drupal_get_form', 'callback arguments' => array('share_admin_popups_'. arg(3) .'_form', arg(4)), 'type' => MENU_CALLBACK ); if (arg(2) == 'share' && is_numeric(arg(4)) && arg(5) == 'delete') { $share = share_popup_load(arg(4), arg(3)); $items[] = array( 'path' => 'admin/build/share/'. arg(3) .'/'. arg(4) .'/delete', 'title' => $title, 'callback' => 'drupal_get_form', 'callback arguments' => array('share_admin_popups_share_delete', $share), 'type' => MENU_CALLBACK ); } } if (is_numeric(arg(3))) { $items[] = array( 'path' => 'admin/build/share/'. arg(3) .'/disable', 'title' => $title, 'callback' => 'share_admin_popups_status', 'callback arguments' => array('disable', arg(3)), 'type' => MENU_CALLBACK ); $items[] = array( 'path' => 'admin/build/share/'. arg(3) .'/enable', 'title' => $title, 'callback' => 'share_admin_popups_status', 'callback arguments' => array('enable', arg(3)), 'type' => MENU_CALLBACK ); } if (is_numeric($arg1 = arg(1))) { $items[] = array( 'path' => '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)) ); } } return $items; } /** * Implementation of hook_link(). */ function share_link($type, $node = NULL, $teaser = FALSE) { $links = array(); if ($popups = share_get_popups('links', $node->type)) { $settings = array(); foreach ($popups as $popup) { $share = share_popup_load($popup->share_id, $popup->type); if (!share_visible($share->view, $teaser)) { continue; } switch ($share->type) { case 'share': if (user_access('use share')) { $links['share_'. $popup->share_id .'_'. $node->nid] = array( 'title' => $share->name, 'href' => 'share/'. $node->nid, 'attributes' => array('id' => 'share-'. $share->share_id .'-'. $node->nid, 'class' => 'share-link') ); $settings[] = array( 'nid' => $node->nid, 'shareID' => $popup->share_id, 'popup' => $share->render($node, 'popup') ); } break; case 'sharethis': if (user_access('use sharethis')) { $links['share_'. $popup->share_id .'_'. $node->nid] = array( 'title' => $share->render($node), 'html' => TRUE ); } break; } } if (!empty($settings)) { drupal_add_js(array('share' => $settings), 'setting'); share_include_js(TRUE); share_include_css(); } } return $links; } function share_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { switch ($op) { case 'view': if ($popups = share_get_popups('nodes', $node->type)) { $settings = array(); foreach ($popups as $popup) { $share = share_popup_load($popup->share_id, $popup->type); if (!share_visible($share->view, $a3)) { continue; } switch ($share->type) { case 'share': if (user_access('use share')) { $links['share_'. $popup->share_id .'_'. $node->nid] = array( 'title' => $share->name, 'href' => 'share/'. $node->nid, 'attributes' => array('id' => 'share-'. $share->share_id .'-'. $node->nid, 'class' => 'share-link') ); $settings[] = array( 'nid' => $node->nid, 'shareID' => $popup->share_id, 'popup' => $share->render($node, 'popup') ); } break; case 'sharethis': if (user_access('use sharethis')) { $node->content['share_'. $popup->share_id .'_'. $node->nid] = array( '#value' => $share->render($node), '#weight' => 10, ); } break; } } if (!empty($settings)) { drupal_add_js(array('share' => $settings), 'setting'); share_include_js(TRUE); share_include_css(); } } break; } } /******************************************************************************* * Callback Functions, Forms, and Tables ******************************************************************************/ /******************************************************************************* * Module and Helper Functions ******************************************************************************/ function share_popup_load($share_id, $type = NULL) { static $shares = array(); if ($shares[$share_id]) { return $shares[$share_id]; } if (!$type) { $type = db_result(db_query("SELECT `type` FROM {share} WHERE `share_id` = %d", $share_id)); } switch ($type) { case 'share': $share = new share_share; $share->load_popup($share_id, 'share'); $share->load_tabs(); $shares[$share_id] = $share; break; case 'sharethis': $share = new share_sharethis; $share->load_popup($share_id, 'sharethis'); $shares[$share_id] = $share; break; } return $shares[$share_id]; } function share_popup_new($type, $args) { $share_id = db_next_id('{share}_share_id'); $node_types = array_filter($args['node_types'], 'share_array_values'); db_query("INSERT INTO {share} (`share_id`, `type`, `label`, `node_types`, `category_terms`, `where`, `view`, `status`) VALUES (%d, '%s', '%s', '%s', '%s', '%s', %d, %d)", $share_id, $args['type'], $args['label'], serialize($node_types), serialize($args['category_terms']), $args['where'], $args['view'], $args['status']); switch ($type) { case 'share': db_query("INSERT INTO {share_share} (`share_id`, `name`, `effects`) VALUES (%d, '%s', %d)", $share_id, $args['link_name'], $args['effects']); foreach (module_implements('share_info') as $module) { db_query("INSERT INTO {share_tabs} (`share_id`, `id`, `title`, `enabled`, `weight`, `module`) VALUES (%d, '%s', '%s', %d, %d, '%s')", $share_id, $args[$module .'_id'], $args[$module .'_title'], $args[$module .'_enabled'], $args[$module .'_weight'], $args[$module .'_module']); $args['share_id'] = $share_id; $func = $module .'_share_tab'; $func('insert', $args); } break; case 'sharethis': $services = empty($args['services_order']) ? $args['services'] : explode(',', $args['services_order']); db_query("INSERT INTO {share_sharethis} (`share_id`, `icon`, `buttonText`, `popup`, `offsettop`, `offsetleft`, `onclick`) VALUES (%d, '%s', '%s', %d, %d, %d, '%s')", $share_id, $args['icon'], $args['button_text'], $args['popup'], $args['top'], $args['left'], $args['onclick']); variable_set('share_sharethis_tabs', $args['tabs']); variable_set('share_sharethis_services', $services); variable_set('share_sharethis_publisher', $args['publisher']); variable_set('share_sharethis_code', $args['code']); break; } return $share_id; } function share_popup_save($type, $args) { $node_types = array_filter($args['node_types'], 'share_array_values'); db_query("UPDATE {share} SET `type` = '%s', `label` = '%s', `node_types` = '%s', `category_terms` = '%s', `where` = '%s', `view` = %d, `status` = %d WHERE `share_id` = '%s'", $args['type'], $args['label'], serialize($node_types), serialize($args['category_terms']), $args['where'], $args['view'], $args['status'], $args['share_id']); switch ($type) { case 'share': db_query("UPDATE {share_share} SET `name` = '%s', `effects` = %d WHERE `share_id` = %d", $args['link_name'], $args['effects'], $args['share_id']); foreach (module_implements('share_info') as $module) { db_query("UPDATE {share_tabs} SET `title` = '%s', `enabled` = %d, `weight` = %d, `module` = '%s' WHERE `share_id` = %d AND `id` = '%s'", $args[$module .'_title'], $args[$module .'_enabled'], $args[$module .'_weight'], $args[$module .'_module'], $args['share_id'], $args[$module .'_id']); if (!db_affected_rows()) { db_query("INSERT INTO {share_tabs} (`share_id`, `id`, `title`, `enabled`, `weight`, `module`) VALUES (%d, '%s', '%s', %d, %d, '%s')", $args['share_id'], $args[$module .'_id'], $args[$module .'_title'], $args[$module .'_enabled'], $args[$module .'_weight'], $args[$module .'_module']); } $func = $module .'_share_tab'; $func('update', $args); } break; case 'sharethis': $services = empty($args['services_order']) ? $args['services'] : explode(',', $args['services_order']); db_query("UPDATE {share_sharethis} SET `icon` = '%s', `buttonText` = '%s', `popup` = %d, `offsettop` = %d, `offsetleft` = %d, `onclick` = '%s' WHERE `share_id` = %d", $args['icon'], $args['button_text'], $args['popup'], $args['top'], $args['left'], $args['onclick'], $args['share_id']); variable_set('share_sharethis_tabs', $args['tabs']); variable_set('share_sharethis_services', $services); variable_set('share_sharethis_publisher', $args['publisher']); variable_set('share_sharethis_code', $args['code']); break; } } function share_popup_delete($share_id, $type = NULL) { if ($type) { switch ($type) { case 'share': db_query("DELETE FROM {share_share} WHERE `share_id` = %d", $share_id); db_query("DELETE FROM {share_tabs} WHERE `share_id` = %d", $share_id); break; case 'sharethis': db_query("DELETE FROM {share_sharethis} WHERE `share_id` = %d", $share_id); break; } } else { db_query("DELETE FROM {share_share} WHERE `share_id` = %d", $share_id); db_query("DELETE FROM {share_tabs} WHERE `share_id` = %d", $share_id); db_query("DELETE FROM {share_sharethis} WHERE `share_id` = %d", $share_id); } db_query("DELETE FROM {share} WHERE `share_id` = %d", $share_id); } function share_add_share_access() { if (!user_access('administer share')) { return FALSE; } $tabs = module_invoke_all('share_info'); if (empty($tabs)) { return FALSE; } return TRUE; } function share_get_popups($where = NULL, $node_type = NULL, $share_type = NULL) { static $share_popups = array(); if (!empty($share_popups)) { if ($where) { if ($node_type) { if ($share_type) { $return = array_merge((array)$share_popups[$where][$node_type][$share_type], $share_popups[$where]['all'][$share_type]); return $return; } $share = array_merge((array)$share_popups[$where][$node_type]['share'], (array)$share_popups[$where]['all']['share']); $sharethis = array_merge((array)$share_popups[$where][$node_type]['sharethis'], (array)$share_popups[$where]['all']['sharethis']); return array_merge($share, $sharethis); } else { return $share_popups[$where]; } } return $share_popups; } $result = db_query("SELECT * FROM {share} WHERE `status` = %d ORDER BY type", TRUE); while ($data = db_fetch_object($result)) { $share = drupal_clone($data); $share->node_types = unserialize($share->node_types); $share->category_terms = unserialize($share->category_terms); if (empty($share->node_types)) { $share_popups[$data->where]['all'][$share->type][] = $share; } else { foreach ($share->node_types as $value) { $share_popups[$data->where][$value][$share->type][] = $share; } } } if ($where) { if ($node_type) { if ($share_type) { $return = array_merge((array)$share_popups[$where][$node_type][$share_type], $share_popups[$where]['all'][$share_type]); return $return; } $share = array_merge((array)$share_popups[$where][$node_type]['share'], (array)$share_popups[$where]['all']['share']); $sharethis = array_merge((array)$share_popups[$where][$node_type]['sharethis'], (array)$share_popups[$where]['all']['sharethis']); return array_merge($share, $sharethis); } else { return $share_popups[$where]; } } return $share_popups; } function share_include_js($link = FALSE) { static $share = FALSE; static $share_link = FALSE; if ($link) { if ($share_link == FALSE) { drupal_add_js(drupal_get_path('module', 'share') .'/js/share_link.js'); $share_link = TRUE; } } if ($share == FALSE) { drupal_add_js(drupal_get_path('module', 'share') .'/js/share.js'); $share = TRUE; } } function share_include_css() { static $share = FALSE; if ($share == FALSE) { drupal_add_css(drupal_get_path('module', 'share') .'/css/share.css'); $share = TRUE; } } function share_visible($view, $teaser) { switch ($view) { case 0: if ($teaser) { return TRUE; } break; case 1: if (!$teaser) { return TRUE; } break; case 2: return TRUE; break; } return FALSE; } function share_array_values($var) { return ($var); } /******************************************************************************* * Theme Functions ******************************************************************************/ function theme_share_popup_tabs($tabs, $nid) { $output = '