| 1 |
<?php
|
| 2 |
// $Id: websnapr.module,v 1.1.2.2 2008/01/19 06:34:03 Gurpartap Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Display an overlay bubble on mouse hover, showing a hyperlink target
|
| 7 |
* thumbnail, using the WebSnapr service.
|
| 8 |
*/
|
| 9 |
|
| 10 |
/**
|
| 11 |
* Implementation of hook_help().
|
| 12 |
*/
|
| 13 |
function websnapr_help($page, $arg) {
|
| 14 |
$output = '';
|
| 15 |
switch ($page) {
|
| 16 |
case 'admin/help#websnapr':
|
| 17 |
$output .= '<p>' . t('The WebSnapr Preview Bubble module is a simple, unobtrusive script used to display an overlay bubble showing a hyperlink target thumbnail using WebSnapr. It is a snap to setup and works on all modern browsers. Check the demo at: <a href="http://www.websnapr.com/previewbubble/">http://www.websnapr.com/previewbubble/</a>');
|
| 18 |
$output .= '<p>' . t('WebSnapr - Preview Bubble Javascript by Juan Xavier Larrea') . '</p>';
|
| 19 |
break;
|
| 20 |
case 'admin/settings/websnapr':
|
| 21 |
$output .= '<p>' . t('Bubbles are always enabled for hyperlinks having class <em>previewlink</em>, irrespective of any configuration below.<br /><a href="!url" />Configure permissions</a> for user roles to view WebSnapr Preview Bubbles.', array('!url' => url('admin/user/permissions', array('fragment' => 'module-websnapr')))) . '</p>';
|
| 22 |
}
|
| 23 |
|
| 24 |
return $output;
|
| 25 |
}
|
| 26 |
|
| 27 |
/**
|
| 28 |
* Implementation of hook_init().
|
| 29 |
*/
|
| 30 |
function websnapr_init() {
|
| 31 |
if (user_access('view websnapr preview bubble')) {
|
| 32 |
// Load the JS for WebSnapr
|
| 33 |
websnapr_load_script();
|
| 34 |
}
|
| 35 |
}
|
| 36 |
|
| 37 |
/**
|
| 38 |
* Implementation of hook_menu().
|
| 39 |
*/
|
| 40 |
function websnapr_menu() {
|
| 41 |
$items = array();
|
| 42 |
|
| 43 |
$items['admin/settings/websnapr'] = array(
|
| 44 |
'title' => 'WebSnapr Preview Bubble',
|
| 45 |
'description' => 'Toggle site-wide usage of WebSnapr Preview Bubbles.',
|
| 46 |
'page callback' => 'drupal_get_form',
|
| 47 |
'page arguments' => array('websnapr_settings'),
|
| 48 |
'access callback' => 'user_access',
|
| 49 |
'access arguments' => array('administer site configuration'),
|
| 50 |
'type' => MENU_NORMAL_ITEM,
|
| 51 |
);
|
| 52 |
|
| 53 |
return $items;
|
| 54 |
}
|
| 55 |
|
| 56 |
/**
|
| 57 |
* Implementation of hook_perm().
|
| 58 |
*/
|
| 59 |
function websnapr_perm() {
|
| 60 |
return array('view websnapr preview bubble');
|
| 61 |
}
|
| 62 |
|
| 63 |
/**
|
| 64 |
* Menu callback; Return a form for WebSnapr module settings.
|
| 65 |
*/
|
| 66 |
function websnapr_settings() {
|
| 67 |
$form = array();
|
| 68 |
|
| 69 |
$form['websnapr'] = array(
|
| 70 |
'#type' => 'fieldset',
|
| 71 |
'#title' => t('Basic settings'),
|
| 72 |
);
|
| 73 |
$form['websnapr']['websnapr_developer_key'] = array(
|
| 74 |
'#type' => 'textfield',
|
| 75 |
'#title' => t('WebSnapr Developer Key'),
|
| 76 |
'#default_value' => variable_get('websnapr_developer_key', NULL),
|
| 77 |
'#size' => 50,
|
| 78 |
'#maxlength' => 250,
|
| 79 |
'#required' => TRUE,
|
| 80 |
'#description' => t("No key? !link - It's free and there is no catch!", array('!link' => l(t('Get yours here'), 'http://www.websnapr.com/'))),
|
| 81 |
);
|
| 82 |
$form['websnapr']['websnapr_preview_selector'] = array(
|
| 83 |
'#type' => 'textfield',
|
| 84 |
'#title' => t('CSS Selector'),
|
| 85 |
'#default_value' => variable_get('websnapr_preview_selector', 'div.node a'),
|
| 86 |
'#size' => 50,
|
| 87 |
'#maxlength' => 250,
|
| 88 |
'#description' => t('Enter <a href="http://www.w3.org/TR/css3-selectors/" title="Click to learn more about CSS Selectors"/>CSS Selectors</a> for HTML hyperlink tags, as implemented in jQuery, to enable WebSnapr Preview Bubble for. Separate multiple by comma.<br />For example:<br />
|
| 89 |
<ul>
|
| 90 |
<li>External links: <strong>a[@href^=http://]:not([@href*=!url])</strong></li>
|
| 91 |
<li>Links with class <em>websnapr</em>: <strong>a.websnapr</strong></li>
|
| 92 |
<li>Links only within nodes: <strong>div.node a</strong></li>
|
| 93 |
<li>All links on site web pages: <strong>a</strong></li>
|
| 94 |
</ul>!test', array('!test' => '[' . l(t('Hover to test the drupal.org snap.'), 'http://drupal.org/', array('attributes' => array('class' => 'previewlink'))) . ']', '!url' => $_SERVER['HTTP_HOST'])),
|
| 95 |
);
|
| 96 |
|
| 97 |
return system_settings_form($form);
|
| 98 |
}
|
| 99 |
|
| 100 |
/**
|
| 101 |
* Load required JS and settings for WebSnapr Bubble Previews.
|
| 102 |
*/
|
| 103 |
function websnapr_load_script() {
|
| 104 |
static $loaded;
|
| 105 |
|
| 106 |
if (!$loaded) {
|
| 107 |
$path = drupal_get_path('module', 'websnapr');
|
| 108 |
|
| 109 |
// Add the JS settings.
|
| 110 |
$settings = array(
|
| 111 |
'websnapr' => array(
|
| 112 |
'previewBubbleSelector' => variable_get('websnapr_preview_selector', 'div.node a'),
|
| 113 |
'previewBubbleBG' => (base_path() . $path . '/images/bg.png'),
|
| 114 |
'developerKey' => variable_get('websnapr_developer_key', NULL),
|
| 115 |
),
|
| 116 |
);
|
| 117 |
drupal_add_js($settings, 'setting');
|
| 118 |
|
| 119 |
// Add the WebSnapr service JS.
|
| 120 |
drupal_add_js($path . '/js/websnapr.js');
|
| 121 |
$loaded = TRUE;
|
| 122 |
}
|
| 123 |
return;
|
| 124 |
}
|