| 1 |
<?php
|
| 2 |
/**
|
| 3 |
* $Id: scooperceci.module,v 1.6 2008/04/23 01:35:49 narno Exp $
|
| 4 |
* Sccoper Ceci : a Drupal module that adds a "Sccoper Ceci" button to your nodes.
|
| 5 |
* (The code of this module is partially based on Digg This module by Ramiro Gómez)
|
| 6 |
* @author Arnaud 'Narno' Ligny <arnaud.ligny@narno.com>
|
| 7 |
* @copyright Narno.com
|
| 8 |
*/
|
| 9 |
|
| 10 |
/**
|
| 11 |
* Implementation of hook_perm().
|
| 12 |
*/
|
| 13 |
function scooperceci_perm() {
|
| 14 |
return array('use scooperceci');
|
| 15 |
}
|
| 16 |
|
| 17 |
/**
|
| 18 |
* Implementation of hook_menu().
|
| 19 |
*/
|
| 20 |
function scooperceci_menu($may_cache) {
|
| 21 |
$items = array();
|
| 22 |
$items[] = array(
|
| 23 |
'path' => 'admin/settings/scooperceci',
|
| 24 |
'title' => t('Scooper Ceci'),
|
| 25 |
'description' => t('Enable the node types and set the properties for the Scooper Ceci button.'),
|
| 26 |
'callback' => 'drupal_get_form',
|
| 27 |
'callback arguments' => array('scooperceci_admin_settings'),
|
| 28 |
'access' => user_access('administer site configuration'),
|
| 29 |
'type' => MENU_NORMAL_ITEM
|
| 30 |
);
|
| 31 |
return $items;
|
| 32 |
}
|
| 33 |
|
| 34 |
/**
|
| 35 |
* admin settings for the scooperceci module
|
| 36 |
*/
|
| 37 |
function scooperceci_admin_settings() {
|
| 38 |
$form = array();
|
| 39 |
$form['scooperceci'] = array(
|
| 40 |
'#type' => 'fieldset',
|
| 41 |
'#title' => t('Settings')
|
| 42 |
);
|
| 43 |
$form['scooperceci']['scooperceci_button_type'] = array(
|
| 44 |
'#type' => 'radios',
|
| 45 |
'#title' => t('Button types'),
|
| 46 |
'#default_value' => variable_get('scooperceci_button_type', 'small'),
|
| 47 |
'#options' => array('large' => '<img src="http://statik.scoopeo.com/images/large.png" />', 'small' => '<img src="http://statik.scoopeo.com/images/small.png" />', 'oneline' => '<img src="http://statik.scoopeo.com/images/oneline.png" />', 'dark' => '<img src="http://statik.scoopeo.com/images/dark.png" />', 'mini' => '<img src="http://statik.scoopeo.com/images/mini.png" />'),
|
| 48 |
'#description' => t('Specifies the button type (also named <em>clicker type</em>)')
|
| 49 |
);
|
| 50 |
$form['scooperceci']['scooperceci_button_weight'] = array(
|
| 51 |
'#type' => 'select',
|
| 52 |
'#title' => t('Weight'),
|
| 53 |
'#default_value' => variable_get('scooperceci_button_weight', 0),
|
| 54 |
'#options' => drupal_map_assoc(range(-20,20)),
|
| 55 |
'#description' => t('Specifies the position of the <em>Scooper Ceci</em> button (a low weight will display the button above the content and a high weight, below the content)')
|
| 56 |
);
|
| 57 |
$form['scooperceci']['scooperceci_node_types'] = array(
|
| 58 |
'#type' => 'checkboxes',
|
| 59 |
'#title' => t('Node types'),
|
| 60 |
'#default_value' => variable_get('scooperceci_node_types', array()),
|
| 61 |
'#options' => node_get_types('names'),
|
| 62 |
'#description' => t('Activate the node types in where the <em>Scooper Ceci</em> button shall be displayed')
|
| 63 |
);
|
| 64 |
$form['scooperceci']['scooperceci_where'] = array(
|
| 65 |
'#type' => 'select',
|
| 66 |
'#title' => t('Where to display'),
|
| 67 |
'#default_value' => variable_get('scooperceci_where', 0),
|
| 68 |
'#options' => array(t('Nodes'), t('Links'))
|
| 69 |
);
|
| 70 |
$form['scooperceci']['scooperceci_in_node'] = array(
|
| 71 |
'#type' => 'select',
|
| 72 |
'#title' => t('When to display in nodes'),
|
| 73 |
'#default_value' => variable_get('scooperceci_in_node', 0),
|
| 74 |
'#options' => array(0 => t('Disabled'), 1 => t('Teaser view'), 2 => t('Full page view'), 3 => t('Teaser and full page view')),
|
| 75 |
'#description' => t('When to display the <em>Scooper Ceci</em> button in the node')
|
| 76 |
);
|
| 77 |
if (variable_get('scooperceci_where', 0) == 1) {
|
| 78 |
$form['scooperceci']['scooperceci_in_node']['#disabled'] = TRUE;
|
| 79 |
}
|
| 80 |
return system_settings_form($form);
|
| 81 |
}
|
| 82 |
|
| 83 |
/**
|
| 84 |
* Implementation of hook_nodeapi().
|
| 85 |
*/
|
| 86 |
function scooperceci_nodeapi(&$node, $op, $teaser, $page) {
|
| 87 |
if ($op == 'view' && user_access('use scooperceci') && variable_get('scooperceci_where', 0) == 0) {
|
| 88 |
// node types ?
|
| 89 |
if(in_array($node->type, variable_get('scooperceci_node_types', array()), TRUE)) {
|
| 90 |
// when in node ?
|
| 91 |
switch (variable_get('scooperceci_in_node', 0)) {
|
| 92 |
case 1:
|
| 93 |
if ($teaser) {
|
| 94 |
$node->content['scooperceci_button'] = array(
|
| 95 |
'#value' => theme('scooperceci_button', $node),
|
| 96 |
'#weight' => variable_get('scooperceci_button_weight', 0)
|
| 97 |
);
|
| 98 |
}
|
| 99 |
break;
|
| 100 |
case 2:
|
| 101 |
if ($page) {
|
| 102 |
$node->content['scooperceci_button'] = array(
|
| 103 |
'#value' => theme('scooperceci_button', $node),
|
| 104 |
'#weight' => variable_get('scooperceci_button_weight', 0)
|
| 105 |
);
|
| 106 |
}
|
| 107 |
break;
|
| 108 |
case 3:
|
| 109 |
if ($teaser) {
|
| 110 |
$node->content['scooperceci_button'] = array(
|
| 111 |
'#value' => theme('scooperceci_button', $node),
|
| 112 |
'#weight' => variable_get('scooperceci_button_weight', 0)
|
| 113 |
);
|
| 114 |
} elseif ($page) {
|
| 115 |
$node->content['scooperceci_button'] = array(
|
| 116 |
'#value' => theme('scooperceci_button', $node),
|
| 117 |
'#weight' => variable_get('scooperceci_button_weight', 0)
|
| 118 |
);
|
| 119 |
}
|
| 120 |
break;
|
| 121 |
}
|
| 122 |
}
|
| 123 |
}
|
| 124 |
}
|
| 125 |
|
| 126 |
/**
|
| 127 |
* Implementation of hook_link().
|
| 128 |
*/
|
| 129 |
function scooperceci_link($type, $node = NULL, $teaser = FALSE) {
|
| 130 |
$links = array();
|
| 131 |
if (user_access('use scooperceci') && variable_get('scooperceci_where', 0) == 1) {
|
| 132 |
// node types ?
|
| 133 |
if(in_array($node->type, variable_get('scooperceci_node_types', array()), TRUE)) {
|
| 134 |
$links['scooperceci_link'] = array(
|
| 135 |
'title' => theme('scooperceci_button', $node, FALSE),
|
| 136 |
'html' => TRUE
|
| 137 |
);
|
| 138 |
}
|
| 139 |
}
|
| 140 |
return $links;
|
| 141 |
}
|
| 142 |
|
| 143 |
/**
|
| 144 |
* theme function for button display
|
| 145 |
*/
|
| 146 |
function theme_scooperceci_button($node, $indiv = TRUE) {
|
| 147 |
// add css file
|
| 148 |
$module_path = drupal_get_path('module', 'scooperceci');
|
| 149 |
drupal_add_css($module_path . '/scooperceci.css');
|
| 150 |
// absolute url of the current node
|
| 151 |
$url = url('node/'. $node->nid, NULL, NULL, TRUE);
|
| 152 |
// add node title
|
| 153 |
//$url .= '&title=' . urlencode($node->title);
|
| 154 |
// button type
|
| 155 |
$button_type = variable_get('scooperceci_button_type', 'small');
|
| 156 |
// js content
|
| 157 |
$scoopeo_js =<<<EOF
|
| 158 |
<script type="text/javascript">
|
| 159 |
scoopeo_url = '$url';
|
| 160 |
</script>
|
| 161 |
<script type="text/javascript" src="http://scoopeo.com/clicker/insert/$button_type"></script>
|
| 162 |
EOF;
|
| 163 |
if ($indiv) {
|
| 164 |
$return = '<div class="scoopeo">'. $scoopeo_js .'</div>';
|
| 165 |
} else {
|
| 166 |
$return = $scoopeo_js;
|
| 167 |
}
|
| 168 |
return $return;
|
| 169 |
}
|
| 170 |
?>
|