| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @defgroup drigg_external Drigg External : Provides an External Vote Button for Drigg.
|
| 6 |
*
|
| 7 |
* It uses Drigg's configuration to determine which vote button to display. It finds content
|
| 8 |
* in Drigg's database based on the originating URL picked up either from the HTTP referer
|
| 9 |
* or from the url HTTP attribute.
|
| 10 |
* It depends on two templates that you can customize to your wishes : one for when a button
|
| 11 |
* gets displayed (because the originating URL is already in Drigg), one for adding the content
|
| 12 |
* to drigg (because the originating URL is not already in Drigg)
|
| 13 |
*/
|
| 14 |
|
| 15 |
/**
|
| 16 |
* @file
|
| 17 |
* Handles incoming requests to render a vote or add button, coming from the javascript
|
| 18 |
*
|
| 19 |
* @ingroup drigg_external
|
| 20 |
*/
|
| 21 |
|
| 22 |
/**
|
| 23 |
* Display help and module information
|
| 24 |
* @param path which path of the site we're displaying help
|
| 25 |
* @param arg array that holds the current path as would be returned from arg() function
|
| 26 |
* @return help text for the path
|
| 27 |
*/
|
| 28 |
function drigg_external_help($path, $arg) {
|
| 29 |
$output = '';
|
| 30 |
switch ($path) {
|
| 31 |
case "admin/help#drigg_external":
|
| 32 |
$output = '<p>'. t("Offers an external vote button for a drigg site") .'</p>';
|
| 33 |
break;
|
| 34 |
}
|
| 35 |
return $output;
|
| 36 |
} // function onthisdate_help
|
| 37 |
|
| 38 |
/**
|
| 39 |
* Implementation of hook_menu().
|
| 40 |
*
|
| 41 |
*/
|
| 42 |
function drigg_external_menu() {
|
| 43 |
|
| 44 |
$items = array();
|
| 45 |
|
| 46 |
$items['drigg_external/display_button'] = array(
|
| 47 |
'title' => t('Drigg External - Show external vote button'),
|
| 48 |
'page callback' => 'drigg_external_display_button',
|
| 49 |
'access callback' => TRUE,
|
| 50 |
'type' => MENU_CALLBACK,
|
| 51 |
);
|
| 52 |
|
| 53 |
return $items;
|
| 54 |
}
|
| 55 |
|
| 56 |
/**
|
| 57 |
* Implementation of hook_theme().
|
| 58 |
*
|
| 59 |
*/
|
| 60 |
function drigg_external_theme() {
|
| 61 |
return array(
|
| 62 |
//the external vote button itself is themed so that module users can add extra
|
| 63 |
//stuff around the vote button itself (think branding...)
|
| 64 |
|
| 65 |
//the template that will contain the vote button
|
| 66 |
'drigg_external_button_vote' => array(
|
| 67 |
'arguments' => array('node' => NULL, 'widget_html' => NULL),
|
| 68 |
'template' => 'drigg-external-button-vote',
|
| 69 |
),
|
| 70 |
|
| 71 |
//the template to display the "add this" message with a link to the correct URL
|
| 72 |
'drigg_external_button_add' => array(
|
| 73 |
'arguments' => array('link' => NULL),
|
| 74 |
'template' => 'drigg-external-button-add',
|
| 75 |
),
|
| 76 |
);
|
| 77 |
}
|
| 78 |
|
| 79 |
|
| 80 |
/**
|
| 81 |
* Valid permissions for this module
|
| 82 |
* @return array An array of valid permissions for the onthisdate module
|
| 83 |
*/
|
| 84 |
function drigg_external_perm() {
|
| 85 |
return array('access drigg_external');
|
| 86 |
} // function onthisdate_perm()
|
| 87 |
|
| 88 |
|
| 89 |
function _drigg_external_get_url() {
|
| 90 |
//This runs as a callback therefore it goes through the full Drupal bootstrap which looks like a waste of time
|
| 91 |
//I tried doing it as a simple PHP script using drupal_bootstrap but I ended up having to include
|
| 92 |
//helper & common scripts from core & drigg and, especially, load the variables from the database so
|
| 93 |
//I deemed it not worth the trouble
|
| 94 |
|
| 95 |
// get the REFERER URL in case the user did not provide the permalink in javascript
|
| 96 |
// this is used for wordpress-type sites where javascript cannot be included : we will just
|
| 97 |
// serve up an image that links to here or something to that amount
|
| 98 |
if (isset($_SERVER['HTTP_REFERER'])) {
|
| 99 |
$url = check_url($_SERVER['HTTP_REFERER']);
|
| 100 |
}
|
| 101 |
|
| 102 |
// get the URL provided in javascript if it's there. It overrides the referer
|
| 103 |
if (isset($_GET['url'])) {
|
| 104 |
//$get_url = iconv("UTF-8", "UTF-8//IGNORE", $_GET['url'] );
|
| 105 |
$get_url = $_GET['url'];
|
| 106 |
if ($get_url) {
|
| 107 |
$url = check_url($get_url);
|
| 108 |
}
|
| 109 |
}
|
| 110 |
|
| 111 |
// this should never happen
|
| 112 |
if (!isset($url)) {
|
| 113 |
return FALSE;
|
| 114 |
}
|
| 115 |
|
| 116 |
return $url;
|
| 117 |
}
|
| 118 |
|
| 119 |
function _drigg_external_get_node($url) {
|
| 120 |
if (!module_exists("drigg")) {
|
| 121 |
die("Drigg isn't installed!");
|
| 122 |
}
|
| 123 |
|
| 124 |
//get the drigg node from the url
|
| 125 |
$node = drigg_url_exists($url, 0, TRUE);
|
| 126 |
|
| 127 |
return $node;
|
| 128 |
}
|
| 129 |
|
| 130 |
function drigg_external_display_button() {
|
| 131 |
//separate functions for upcoming Wordpress-compatible EVB
|
| 132 |
$url = _drigg_external_get_url();
|
| 133 |
if (!$url) {
|
| 134 |
//make this pretty one day
|
| 135 |
die("No url to display button for. Did you set the javacript 'url_site' variable ?");
|
| 136 |
}
|
| 137 |
|
| 138 |
$node = _drigg_external_get_node($url);
|
| 139 |
|
| 140 |
if ($node) {
|
| 141 |
//drigg allows you to use any kind of widget
|
| 142 |
//the PHP located in the variable below tells us which function to call (and the parameters)
|
| 143 |
$widget_display_php = variable_get('drigg_voting_forms_voted_on','return extra_voting_forms_show_form($node, "n", 3);');
|
| 144 |
|
| 145 |
//currently, eval doesn't work so use the default drigg vote button than 90% of people use
|
| 146 |
$widget_code=eval($widget_display_php);
|
| 147 |
if ($widget_code == FALSE) {
|
| 148 |
die("Widget error cannot eval following PHP : $widget_display_php");
|
| 149 |
}
|
| 150 |
|
| 151 |
drupal_add_css();
|
| 152 |
drupal_add_js();
|
| 153 |
|
| 154 |
print theme('drigg_external_button_vote', $node, $widget_code);
|
| 155 |
}
|
| 156 |
else {
|
| 157 |
//create the link to drigg node creation
|
| 158 |
//l function is broken because it doubly encodes, see http://drupal.org/node/178615
|
| 159 |
$link="<a target='_blank' href='/node/add/drigg/?url=".rawurlencode($url)."'>".t("Add it !")."</a>";
|
| 160 |
|
| 161 |
print theme('drigg_external_button_add', $link);
|
| 162 |
}
|
| 163 |
|
| 164 |
//that's all folks : prevent drupal from display a page
|
| 165 |
module_invoke_all('exit');
|
| 166 |
exit;
|
| 167 |
}
|