Modulo de redes sociales con diseño personalizado para compartir contenido y contadores en Joomla 3
<?xml version="1.0" encoding="utf-8"?>
<extension type="module" version="3.1.0" client="site" method="upgrade">
<name>Modulo de Redes Sociales</name>
<author>David Salazar Renzzo</author>
<version>1.0.0</version>
<creationDate>20/05/2015</creationDate>
<description>Modulo para redes sociales y compartir contenido.</description>
<files>
<filename>mod_rrss.xml</filename>
<filename module="mod_rrss">mod_rrss.php</filename>
<filename>index.html</filename>
<filename>helper.php</filename>
<filename>tmpl/default.php</filename>
<filename>tmpl/index.html</filename>
</files>
<config>
</config>
</extension>
<?php
/**
* @package Module RRSS Incentivos Tributarios
* @subpackage mod_rrss
* @author David Salazar http://www.startapp.pe
* @copyright Copyright (C) 2002 - 2015 StartApp, Inc. All rights reserved.
* @license GNU/GPL license: http://www.gnu.org/copyleft/gpl.html
*/
defined( '_JEXEC' ) or die( 'Restricted access' );
// Agregamos los ficheros helpers que necesitemos para el funcionamiento del módulo
require_once( dirname(__FILE__).'/helper.php' );
// La función getHola() se encuentra en el fichero helper, su resultado será almacenado en la variable $hola
$hola = modRRSSHelper::getHola( $params );
//Obtener la url absoluta actual en Joomla 3 par compartirla por rrss
$uri = JFactory::getURI();
$absolute_url = $uri->toString();
// Damos entrada a la plantilla
require( JModuleHelper::getLayoutPath( 'mod_rrss' ) );
?>
<?php
/**
* @package Module RRSS Incentivos Tributarios
* @subpackage mod_rrss
* @author David Salazar http://www.startapp.pe
* @copyright Copyright (C) 2002 - 2015 StartApp, Inc. All rights reserved.
* @license GNU/GPL license: http://www.gnu.org/copyleft/gpl.html
*/
class modRRSSHelper{
function getHola( $params ){
return "Hola";
}
function get_likes($url) {
$json_string = file_get_contents('https://api.facebook.com/method/links.getStats?urls=' . $url . '&format=json');
$json = json_decode($json_string, true);
if(isset($json[0]['total_count'])){
return intval( $json[0]['total_count'] );
} else { return 0;}
}
function get_tweets($url) {
$json_string = file_get_contents('http://urls.api.twitter.com/1/urls/count.json?url=' . $url);
$json = json_decode($json_string, true);
if(isset($json['count'])){
return intval( $json['count'] );
} else {return 0;}
}
function get_plusones($url) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://clients6.google.com/rpc");
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, '[{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"' . $url . '","source":"widget","userId":"@viewer","groupId":"@self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}]');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
$curl_results = curl_exec ($curl);
curl_close ($curl);
$json = json_decode($curl_results, true);
if(isset($json[0]['result']['metadata']['globalCounts']['count'])){
return intval( $json[0]['result']['metadata']['globalCounts']['count'] );
} else {return 0;}
}
function get_stumble($url) {
$json_string= file_get_contents('http://www.stumbleupon.com/services/1.01/badge.getinfo?url='.$url);
$json = json_decode($json_string, true);
if (isset($json['result']['views'])) {
return intval($json['result']['views']);
} else {return 0;}
}
}
if(isset($_GET["thisurl"])){
$thisUrl =$_GET["thisurl"];
$firstpart= substr("$thisUrl", 0, 20);
// Change http://medialoot.com to your own domain!
if ($firstpart == 'http://startapp.pe/incentivos') {
$data = "{";
$data .= '"facebook": '. json_encode(get_likes($thisUrl)) . ", ";
$data .= '"twitter": ' . json_encode(get_tweets($thisUrl)) . ", ";
$data .= '"gplus": ' . json_encode(get_plusones($thisUrl)) . ", ";
$data .= '"stumble": ' . json_encode(get_stumble($thisUrl)) . "}";
} else {
//throw error
$data = 'ERROR - Está intentando usar este script fuera del dominio permitido';
}
} else {
$data = 'Sin resultados que mostrar.';
}
header('Content-Type: application/json');
echo $data;
?>
<style type="text/css">
a.post-share {
display: block;
width: 94px;
height: 46px;
float: left;
margin: 10px 0px 0px 0px;
background: #3e599a url(sidebar-share.png) no-repeat 0 0;
text-decoration:none;
width: 197px;
text-indent: 50px;
font: 15px/46px "Helvetica Neue", Arial, Helvetica, Geneva, sans-serif;
color: #ffffff;
}
a.post-share:hover {
opacity: 0.8;
text-decoration: none;
cursor: pointer;
}
a.post-share span {
width: 20px;
height: 16px;
padding: 15px;
display: block;
float:right;
background-color: #4665af;
color: #ffffff;
vertical-align: middle;
font: 16px "Helvetica Neue", Arial, Helvetica, Geneva, sans-serif;
text-align: center;
text-indent: 0;
}
a.post-share.facebook {
background: #3e599a url(sidebar-share.png) no-repeat 0 1px;
margin-right: 10px;
}
a.post-share.facebook span {
background-color: #4665af;
}
a.post-share.twitter {
background: #4b8cbe url(sidebar-share.png) no-repeat -0px -111px;
margin-right: 10px;
}
a.post-share.twitter span {
background-color: #529fda;
}
a.post-share.gplus {
background: #b8382e url(sidebar-share.png) no-repeat -0px -50px;
margin-right: 10px;
}
a.post-share.gplus span {
background-color: #d24238;
}
a.post-share.stumble {
background: #e15131 url(sidebar-share.png) no-repeat -0px -165px;
}
a.post-share.stumble span {
background-color: #fd5d3b;
}
</style>
<?php
echo "Ruta absolua: ".$absolute_url;
?>
<a class="post-share facebook" href="http://www.facebook.com/plugins/like.php?href=http://medialoot.com/blog/&width&layout=standard&action=like&show_faces=true&share=true&height=80&appId=#################" onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=100,width=200');return false;">Facebook<span></span>
</a>
<a class="post-share twitter" href="https://twitter.com/share?url=http://medialoot.com/blog/&text=Text for Twitter Here&via=medialoot" onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;">Twitter<span></span>
</a>
<a class="post-share gplus" href="https://plus.google.com/share?url=http://medialoot.com/blog/" onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;">Google Plus<span></span>
</a>
<a class="post-share stumble" href="http://www.stumbleupon.com/submit?url=http://medialoot.com/blog/" onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=800');return false;">Stumbleupon<span></span>
</a>