Medidor PageRank en tu sitio Web


Antes utilizaba MiPageRank.com pero parece que murio, asi que me puse a hacer mi propio medidor de PageRank, y como me quedo bonito (modesto yo) lo puse para que cualquiera lo pueda usar...

En c0wa.com/pagerank hay que poner la direccion del sitio, elegir el estilo y copiar el codigo HTML, simple.

Cambiar target en links externos

Este script permite al usuario seleccionar si quiere que los links externos se abran en una nueva ventana o no, cambiando el target de forma dinamica con Javascript.
// uso tb_toggle(target), ej: tb_toggle('_blank');
function tb_toggle(x) {
var links = document.getElementsByTagName('a');
loc = location.href.split(/\//)
for (i = 0; i < links.length; i++) {
link = links[i].href.split(/\//)
if (loc[2] != link[2]) {
links[i].target = x;
}
}
}

Un ejemplo con un checkbox seria:
<input type="checkbox" onclick="if (this.checked) tb_toggle('_blank'); else tb_toggle('')" /> Abrir links externos en una nueva ventana
Ver demo

Clase PHP para calcular PageRank

Buscando algun metodo para calcular el PageRank no encontre demasiada informacion... Lo mas interesante fue una clase escrita por Patxi Echarte de EsLoMas.com, pero del año 2006 y ya no funciona por unos cambios en Google... Me tome la libertad de modificar dos lineas para que funcione, pero los creditos son para el...
<?php
/**
* Google PageRank number for a URL
*
* LICENCE
* ========
* copyright (c) 2000 Patxi Echarte [patxi@eslomas.com]
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2.1 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details at
* http://www.gnu.org/copyleft/lgpl.html
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @package GooglePageRank
* @version $Id: GooglePageRank.class.php,v 1.0 2006/10/04 $
* @author Patxi Echarte <patxi@eslomas.com>
*/
class GooglePageRank {

var $_GOOGLE_MAGIC = 0xE6359A60;

var $_url = '';

var $_checksum = '';

/**
* Constructor
*
* @access public
*/
function GooglePageRank($url)
{
$this->_url = $url;
}

function _strToNum($Str, $Check, $Magic)
{
$Int32Unit = 4294967296; // 2^32

$length = strlen($Str);
for ($i = 0; $i < $length; $i++) {
$Check *= $Magic;
//If the float is beyond the boundaries of integer (usually +/- 2.15e+9 = 2^31),
// the result of converting to integer is undefined
// refer to http://www.php.net/manual/en/language.types.integer.php
//if (is_float($Check)) {
if ($Check >= $Int32Unit) {
$Check = ($Check - $Int32Unit * (int) ($Check / $Int32Unit));
// - 2^31
$Check = ($Check < -2147483647) ? ($Check + $Int32Unit) : $Check;
}
$Check += ord($Str{$i});
}
return $Check;
}

function _hashURL($String)
{
$Check1 = $this->_strToNum($String, 0x1505, 0x21);
$Check2 = $this->_strToNum($String, 0, 0x1003F);

$Check1 >>= 2;
$Check1 = (($Check1 >> 4) & 0x3FFFFC0 ) | ($Check1 & 0x3F);
$Check1 = (($Check1 >> 4) & 0x3FFC00 ) | ($Check1 & 0x3FF);
$Check1 = (($Check1 >> 4) & 0x3C000 ) | ($Check1 & 0x3FFF);

$T1 = (((($Check1 & 0x3C0) << 4) | ($Check1 & 0x3C)) <<2 ) | ($Check2 & 0xF0F );
$T2 = (((($Check1 & 0xFFFFC000) << 4) | ($Check1 & 0x3C00)) << 0xA) | ($Check2 & 0xF0F0000 );

return ($T1 | $T2);
}

function checksum()
{
if($this->_checksum != '') return $this->_checksum;

$Hashnum = $this->_hashURL($this->_url);

$CheckByte = 0;
$Flag = 0;

$HashStr = sprintf('%u', $Hashnum) ;
$length = strlen($HashStr);

for ($i = $length - 1; $i >= 0; $i --) {
$Re = $HashStr{$i};
if (1 == ($Flag % 2)) {
$Re += $Re;
$Re = (int)($Re / 10) + ($Re % 10);
}
$CheckByte += $Re;
$Flag ++;
}

$CheckByte %= 10;
if (0 !== $CheckByte) {
$CheckByte = 10 - $CheckByte;
if (1 === ($Flag%2) ) {
if (1 === ($CheckByte % 2)) {
$CheckByte += 9;
}
$CheckByte >>= 1;
}
}

$this->_checksum = '7'.$CheckByte.$HashStr;
return $this->_checksum;
}

/**
* obtiene la url donde obtener la información del pagerank
* @access public
*/
function pageRankUrl()
{
return 'http://toolbarqueries.google.com/search?client=navclient-auto&ch='
.$this->checksum().'&q=info:'.$this->_url.'&features=Rank&num=100&filter=0';
}

/**
* devuelve el pagerank para la url indicada o -1 si error
* @access public
*/
function getPageRank()
{
$fh = @fopen($this->pageRankUrl(), "r");
if($fh)
{
$contenido = '';
while (!feof($fh)) {
$contenido .= fread($fh, 8192);
}
fclose($fh);

list(,,$pr) = split(":", $contenido);
if ($pr >= 0 and $pr <= 10) return $pr;
}
return -1;
}

}
?>

Para utilizarlo seria algo asi:
<?
include('gpr.class.php');
$gpr = new GooglePageRank($url);
$gpr->getPageRank();
?>

Aviso al clickear en un enlace externo

Este script avisara que estamos dejando la pagina y si pregunta si deseamos continuar al hacer click en cualquier enlace externo, al igual que hace Hotmail con los vinculos dentro de un correo.
message = 'Este enlace hace referencia a un sitio Web externo. ¿Desea continuar?'; // edita esta linea para cambiar el mensaje

window.onload = function() {
var links = document.getElementsByTagName('a');
loc = location.href.split(/\//)
for (i = 0; i < links.length; i++) {
link = links[i].href.split(/\//)
if (loc[2] != link[2]) {
links[i].onclick = function() {
if (!confirm(message)) return false;
}
}
}
}

Ver demo

AJAX, primeros pasos

AJAX es una tecnica para desarrollar sitios Web interactivos. Permite realizar cambios y acciones en las paginas sin necesidad de recargarlas. Esto aumenta la interactividad y la usabilidad de las aplicaciones.

Con la siguiente funcion se pueden hacer llamados a otros sitios y mostrar el resultado en el div deseado:
// doajax('accion', 'output', 'imagen de carga')
// ej: doajax('vote.php?id=5', 'result5', 'loading.gif')

IE = document.all?true:false

if (IE) {
http = new ActiveXObject('Microsoft.XMLHTTP');
}
else {
http = new XMLHttpRequest();
}

function doajax(action, output, loading) {
document.getElementById(output).innerHTML = '';
http.onreadystatechange = function() {
if(http.readyState == 4) {
document.getElementById(output).innerHTML = http.responseText;
}
}
http.open("GET", action, true);
http.send(null);
}

Ver demo

Y de regalo, un sitio para crear imagenes de 'cargando' al mejor estilo web 2.0: ajaxload

Drag de objetos muy simple con Javascript (arrastrando cosas)

Como no encontre ningun script para hacer drag de objetos sencillo hice uno propio. Su uso es muy simple, solo hay que agregar onmousedown="start_drag()" a casi cualquier item de la pagina (y position: absolute en el css)

Script
// ejemplo: <input type="button" value="hello world" onmousedown="start_drag()" style="position: absolute" />

IE = document.all?true:false

function drag_start(x) {
drag_object = x;
drag_object.focus();
}

document.onmousedown = function (e) {
if (!e) var e = window.event;
if (typeof drag_object != 'undefined') {
if (IE) {
xoffset = e.x-drag_object.offsetLeft;
yoffset = e.y-drag_object.offsetTop;
}
else {
xoffset = e.layerX;
yoffset = e.layerY;
}
return false;
}
}

document.onselectstart = function () {
if (typeof drag_object != 'undefined') {
return false;
}
}

document.onmousemove = function (e) {
if (!e) var e = window.event;
if (typeof drag_object != 'undefined') {
drag_object.style.left = e.clientX - xoffset + 'px';
drag_object.style.top = e.clientY - yoffset + 'px';
}
}

document.onmouseup = function () {
delete drag_object;
}

Ver demo

Descarga videos YouTube

A continuación un pequeño sketch de un código que nos permite extraer la URL del video.

<?
if (!ereg("^http://[a-zA-Z]*\.youtube\.com", $_GET['file']))
die("Ooops!");

$t = file($_GET['file']);

$k = array_values(preg_grep("/var fullscreenUrl/", $t));
ereg("\?(.*)\'", $k[0], $s);
$r = $s[1];
echo '<a href="http://www.youtube.com/get_video?'.$r.'">Get video!</a>';
?>