6 * Embed a JavaScript widget into content and as a block.
8 * Module implements a javascript widget that can be either used
9 * as an embed item via an input filter, or shown as a block.
13 * Implementation of hook_perm().
15 function snufkin_1_perm() {
16 return array('administer snufkin_1', 'access snufkin_1'); // Not there you little naughty girl!
20 * Implementation of hook_menu().
22 function snufkin_1_menu() {
25 $items['admin/settings/snufkin_1'] = array(
26 'title' => 'Embed widget',
27 'description' => 'Configure the embeddable widget code',
28 'page callback' => 'drupal_get_form',
29 'page arguments' => array('snufkin_1_settings_form'),
30 'access arguments' => array('administer snufkin_1'),
31 'file' => 'snufkin_1.admin.inc',
34 $items['snufkin_1'] = array(
35 'title' => 'Magic widget',
36 'description' => 'Display the magic widget on a page.',
37 'page callback' => 'snufkin_1_widget_page',
38 'access arguments' => array('access snufkin_1'),
44 function snufkin_1_widget_page() {
45 return _snufkin_1_default();
49 * Implementation of hook_block().
51 function snufkin_1_block($op = 'list', $delta = 0, $edit = array()) {
55 $blocks['widget']['info'] = t('Widget');
59 if ($delta == 'widget') {
60 $block['subject'] = t('Widget'); // Do we really need a title? I think NOT!
61 $block['content'] = _snufkin_1_default();
68 * Implementation of hook_filter_tips().
70 function snufkin_1_filter_tips($delta, $format, $long = FALSE) {
71 // This module only implements one input filter, so delta is not used.
73 return t('To embed the delicious.com widget write [widget]. It will insert a <script>...</script> code that pulls the network badge from delicious.com.');
76 return t('You may embed the delicious.com widget by using the [widget] tag.');
81 * Implementation of hook_filter().
83 function snufkin_1_filter($op, $delta = 0, $format = -1, $text = '', $cache_id = 0) {
86 return array(0 => t('Embed widget'));
89 return t('Embed JavaScript that displays a delicious.com widget.');
92 return preg_replace('/\[widget\]/', _snufkin_1_default(), $text);
100 * Default value for the widget code.
102 * Url is assembled so later on it can be customized more easily.
104 function _snufkin_1_default() {
105 $url = 'http://feeds.delicious.com/v2/js/networkbadge/';
106 $username = check_plain(variable_get('snufkin_1_name', 'tanarurkerem'));
108 'icon' => 's', 'name' => TRUE, 'itemcount' => TRUE, 'nwcount' => TRUE, 'fancount' => TRUE,
110 $src = url($url . $username, array('query' => $options, 'external' => TRUE));
111 return '<script type="text/javascript" src="' . $src . '"></script>';