Commit 66931b44 authored by Mindiell's avatar Mindiell

First commit

parents
.share-links-container {
margin: 30px 0 10px;
}
li.share-links {
width:100%;
}
div.share-links a {
background-image:url(/sites/all/themes/lqdn314/images/sprites_zen.png);
background-repeat:no-repeat;
width:16px;
height:16px;
margin:3px;
overflow:hidden;
display:block;
float:left;
text-indent:-1000px;
}
.share-links a.share-identica {background-position: 0 -36px }
.share-links a.share-lqdn {background-position: 0 -68px }
.share-links a.share-yooook {background-position: 0 -84px }
.share-links a.share-flattr {background-position: 0 -100px }
.share-links a.share-twitter {background-position: 0 -116px }
.share-links a.share-facebook {background-position: 0 -132px }
.share-links a.share-delicious {background-position: 0 -148px }
.share-links a.share-digg {background-position: 0 -164px }
.share-links a.share-myspace {background-position: 0 -180px }
; $Id$
name = "Share links"
description = Provides links to social sites
core = 6.x
package = "La Quadrature"
<?php
/*
* http://drupal.org/project/flattr
*/
function _lqdn_share_links_flattr_taxonomy_terms_to_text($taxonomy)
{
$terms = '';
$items = array();
foreach ($taxonomy as $tid => $term) {
$items[] = check_plain($term->name);
}
$terms = implode(',', $items);
return $terms;
}
/*
* http://drupal.org/project/flattr
*/
function _lqdn_share_links_flattr($node)
{
//drupal_add_css(drupal_get_path('module', 'flattr') . '/flattr.css');
$output = '<div class="flattr-box">';
$output .= '<script type="text/javascript">' . "\n";
$output .= " var flattr_btn = 'compact';" . "\n";
$output .= " var flattr_uid = '" . check_plain(variable_get('flattr_uid', 'laquadrature')) . "';" . "\n";
if ($node->title) {
$output .= " var flattr_tle = '" . check_plain($node->title) . "';" . "\n";
}
if ($node->teaser) {
$teaser = preg_replace("/\r|\n/s", "", $node->teaser);
}
if (empty($teaser)) {
$teaser = preg_replace("/\r|\n/s", "", node_teaser($node->body, NULL, 50));
}
if (empty($teaser)) {
$teaser = t('No description');
}
/*
* strip_tags() est utilisé pour enlevé toutes les balises html de la description.
* sans ça, noscript met des alertes XSS sur certaines pages (à cause, probablement de caractères mal échapés)
*/
$output .= " var flattr_dsc = '" . trim(check_plain(strip_tags($teaser))) . "';" . "\n";
if (is_array($node->taxonomy)) {
$output .= " var flattr_tag = '" . _lqdn_share_links_flattr_taxonomy_terms_to_text($node->taxonomy) . "';" . "\n";
}
$output .= " var flattr_cat = 'text';" . "\n";
$output .= " var flattr_url = '" . url('node/' . $node->nid, array('absolute' => TRUE)) . "';" . "\n";
// https://api.flattr.com/odapi/languages/human
$lang = ($node->language == 'fr') ? 'fr_FR' : 'en_GB';
$output .= " var flattr_lng = '". $lang ."';\n";
$output .= "</script>" . "\n";
$output .= '<script src="https://api.flattr.com/button/load.js" type="text/javascript"></script>' . "\n";
$output .= '</div>';
return $output;
}
function _lqdn_share_links_menu() {
return '<ul class="links social-links">
<li><a class="icon contact" href="' . url('newsletter') . '" title="' . t('Newsletter') . '">' . t('Newsletter') . '</a></li>
<li>'.l(t('RSS News'), 'rss.xml', array('attributes'=> array('class'=>'icon rss', 'title'=>t('RSS feeds')))).'</li>
<!--<li><a class="icon identica" href="https://identi.ca/laquadrature" title="' . t('Identi.ca') . '">Identi.ca</a></li>-->
<li><a class="icon twitter" href="https://twitter.com/laquadrature" title="' . t('Twitter') . '">Twitter</a></li>
</ul>';
}
function _lqdn_share_links($node) {
drupal_add_css(drupal_get_path('module', 'lqdn_share_links') .'/lqdn_share_links.css');
static $social = array (
array ('name' => 'Twitter', 'url' => 'http://twitter.com/timeline/home?status=%status$s', 'icon' => 'twitter'),
//array ('name' => 'Identi.ca', 'url' => 'http://identi.ca/index.php?action=newnotice&status_textarea=', 'icon' => 'identica'),
//array ('name' => 'identi.ca', 'url' => 'http://identi.ca/notice/new?status_textarea=%status$s', 'icon' => 'identica'),
//array ('name' => 'Google buzz', 'url' => 'http://www.google.com/buzz/post?url=%url$s&amp;message=%title$s', 'icon' => 'google-buzz'),
//array ('name' => 'Google bookmarks', 'url' => 'http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=%url$s&amp;title=%title$s', 'icon' => 'googlebookmark'),
array ('name' => 'Facebook', 'url' => 'http://www.facebook.com/share.php?src=bm&amp;u=%url$s&amp;v=3', 'icon' => 'facebook'),
array ('name' => 'Delicious', 'url' => 'http://del.icio.us/post?url=%url$s&amp;title=%title$s', 'icon' => 'delicious'),
array ('name' => 'Digg', 'url' => 'http://digg.com/submit?phrase=2&amp;url=%url$s&amp;title=%title$s', 'icon' => 'digg'),
array ('name' => 'MySpace', 'url' => 'http://www.myspace.com/Modules/PostTo/Pages/?u=%url$s&amp;t=%title$s', 'icon' => 'myspace'),
//array ('name' => 'Technorati', 'url' => 'http://technorati.com/faves?add=%url$s', 'icon' => 'technorati'),
//array ('name' => 'Live', 'url' => 'https://favorites.live.com/quickadd.aspx?marklet=1&amp;add=%url$s&amp;title=%title$s', 'icon' => 'live'),
);
static $support = array (
array ('name' => 'La Quadrature du Net', 'url' => 'https://soutien.laquadrature.net/', 'icon' => 'lqdn'),
//array ('name' => 'yooook', 'url' => 'https://yooook.net/site/direct_donation/10.00/laquadrature/', 'icon' => 'yooook'),
//array ('name' => 'flattr', 'url' => 'http://flattr.com/thing/18725/', 'icon' => 'flattr'),
);
global $base_root;
global $base_path;
$output = '';
//$imgpath = $base_path . path_to_theme() . '/img/icons/16x16/';
$imgpath = $base_path . drupal_get_path('theme', 'lqdn') . '/img/icons/16x16/';
$url = $base_root . url('node/'.$node->nid);
$tiny_url = variable_get('base_root_tiny_url', $base_root) . '/node/'. $node->nid; /* URL Rewrite /!\ */
variable_set('base_root_tiny_url', 'http://lqdn.fr');
$params = array (
'url' => urlencode($url),
'tiny_url' => urlencode($tiny_url),
'title' => urlencode($node->title),
'status' => urlencode($node->title . ' : ' . $tiny_url),
);
$output .= '<div class="share-links" style="float:left; width:49%">'. t('Share this:') .'<br />';
foreach ($social as $s) {
$output .= ' <a href="'. sprintfn($s['url'], $params) .'" class="share-'. $s['icon'].'">'. $s['name'] . '</a>';
}
$output .= '</div><div class="share-links" style="margin-left:50%; width:49%">'. t('Support next publications:') .'<br />';
foreach ($support as $s) {
$output .= ' <a href="'. sprintfn($s['url'], $params) .'" class="share-'. $s['icon'].'">'. $s['name'] . '</a>';
}
$output .= _lqdn_share_links_flattr($node);
$output .= '</div>';//<div style="padding:0;margin:0;clear:both;height:0;">&nbsp;</div>';
return '<div class="share-links-container">' . $output . '</div>';
}
/* Exemple d'utilisation
function tribune_preprocess_node(&$variables) {
$node = $variables['node'];
$variables['special_page'] = in_array ($node->type, array ('page', 'project_issue', 'license'));
if ($variables['page'] && !$variables['special_page']) {
$variables['share'] = _tribune_share_links($node);
}
}
*/
/**
* Implementation of hook_nodeapi().
*/
function lqdn_share_links_nodeapi(&$node, $op, $teaser, $page) {
if ($op == 'view' && $page) {
$node->content['share_links'] = array(
'#value' => _lqdn_share_links($node),
'#weight' => 10,
);
}
}
/**
* Implementation of hook_link().
*/
function lqdn_share_links_link($type, $node = NULL, $teaser = FALSE) {
$links = array();
if ($type == 'node' && $teaser) {
//$links[] = _lqdn_share_links($node);
}
return $links;
}
/**
* Implementation of hook_block().
*/
function lqdn_share_links_block($op = 'list', $delta = 0, $edit = array()) {
if ($op == 'list') {
$blocks[0]['info'] = t('Liens vers les machins de lqdn');
return $blocks;
}
else if ($op == 'view') {
if ($delta == 0) {
$block = array(
'subject' => '',
'content' => _lqdn_share_links_menu(),
);
}
return $block;
}
}
/**
* version of sprintf for cases where named arguments are desired (php syntax)
*
* with sprintf: sprintf('second: %2$s ; first: %1$s', '1st', '2nd');
*
* with sprintfn: sprintfn('second: %second$s ; first: %first$s', array(
* 'first' => '1st',
* 'second'=> '2nd'
* ));
*
* @param string $format sprintf format string, with any number of named arguments
* @param array $args array of [ 'arg_name' => 'arg value', ... ] replacements to be made
* @return string|false result of sprintf call, or bool false on error
*/
function sprintfn ($format, array $args = array()) {
// map of argument names to their corresponding sprintf numeric argument value
$arg_nums = array_slice(array_flip(array_keys(array(0 => 0) + $args)), 1);
// find the next named argument. each search starts at the end of the previous replacement.
for ($pos = 0; preg_match('/(?<=%)([a-zA-Z_]\w*)(?=\$)/', $format, $match, PREG_OFFSET_CAPTURE, $pos);) {
$arg_pos = $match[0][1];
$arg_len = strlen($match[0][0]);
$arg_key = $match[1][0];
// programmer did not supply a value for the named argument found in the format string
if (! array_key_exists($arg_key, $arg_nums)) {
user_error("sprintfn(): Missing argument '${arg_key}'", E_USER_WARNING);
return false;
}
// replace the named argument with the corresponding numeric one
$format = substr_replace($format, $replace = $arg_nums[$arg_key], $arg_pos, $arg_len);
$pos = $arg_pos + strlen($replace); // skip to end of replacement for next iteration
}
return vsprintf($format, array_values($args));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment