← All posts

The SeoTools Service and Calculating PR and TIC with PHP

seo.adw0rd.ru

I’ve added a bit more code and decided to put my SeoTools service out there for everyone to see. To be honest, I don’t know whether it’s worth developing further; I’d like to build a report-generating service for companies that provide SEO services.

The Idea!

For example, a user visits the service and enters a domain and some potential keywords (if they have any), after which the service checks the domain’s metrics and its rankings for those keywords, and suggests other keywords that are better suited to the domain. Morphological dictionaries could also be integrated to suggest similar words, and so on.

After that, it would generate charts and graphs and calculate approximate growth, and so on. In other words, make forecasts!

The Service

At the moment, the service queries information sequentially, so it may seem rather sluggish. It would be easy enough to rewrite it to make parallel requests, but is that really necessary right now…?

Calculating PR

As promised, here’s a class for determining PR:



< ?php

class googlePageRank {

    public static function get($url)
    {
        define("GOOGLE_MAGIC", 0xE6359A60);

        $url = 'info:'.$url;
        $ch = self::GoogleCH(self::strord($url));
        $file = "http://www.google.com/search?client=navclient-auto&ch=6$ch&features=Rank&q=$url";
        $data = seoTools::curlGetContent($file);

        return trim($data);
    }

    public static function GoogleCH($url, $length=null, $init=GOOGLE_MAGIC)
    {
        if (is_null($length)) {
            $length = sizeof($url);
        }
        $a = $b = 0x9E3779B9;
        $c = $init;
        $k = 0;
        $len = $length;
        while($len >= 12) {
            $a += ($url[$k + 0] + ($url[$k + 1] < < 8) + ($url[$k + 2] << 16) + ($url[$k + 3] << 24));
            $b += ($url[$k + 4] + ($url[$k + 5] << 8) + ($url[$k + 6] << 16) + ($url[$k + 7] << 24));
            $c += ($url[$k + 8] + ($url[$k + 9] << 8) + ($url[$k + 10] << 16) + ($url[$k + 11] << 24));
            $mix = self::mix($a, $b, $c);
            $a = $mix[0]; $b = $mix[1]; $c = $mix[2];
            $k += 12;
            $len -= 12;
        }
        $c += $length;
        switch($len) {
            case 11: $c += ($url[$k + 10] << 24);
            case 10: $c += ($url[$k + 9] << 16);
            case 9 : $c += ($url[$k + 8] << 8);
            /* the first byte of c is reserved for the length */
            case 8 : $b += ($url[$k + 7] << 24);
            case 7 : $b += ($url[$k + 6] << 16);
            case 6 : $b+=($url[$k+5]<<8);
            case 5 : $b+=($url[$k+4]);
            case 4 : $a+=($url[$k+3]<<24);
            case 3 : $a+=($url[$k+2]<<16);
            case 2 : $a+=($url[$k+1]<<8);
            case 1 : $a+=($url[$k+0]);
            /* case 0: nothing left to add */
        }
        $mix = self::mix($a,$b,$c);
        return $mix[2];
    }

    public static function zeroFill($a, $b)
    {
        $z = hexdec(80000000);
        if ($z & $a) {
            $a = ($a>>1);
            $a &= (~$z);
            $a |= 0x40000000;
            $a = ($a>>($b-1));
        } else {
            $a = ($a>>$b);
        }
        return $a;
    }

    public static function mix($a,$b,$c) {
        $a -= $b; $a -= $c; $a ^= (self::zeroFill($c,13));
        $b -= $c; $b -= $a; $b ^= ($a<<8);
        $c -= $a; $c -= $b; $c ^= (self::zeroFill($b,13));
        $a -= $b; $a -= $c; $a ^= (self::zeroFill($c,12));
        $b -= $c; $b -= $a; $b ^= ($a<<16);
        $c -= $a; $c -= $b; $c ^= (self::zeroFill($b,5));
        $a -= $b; $a -= $c; $a ^= (self::zeroFill($c,3));
        $b -= $c; $b -= $a; $b ^= ($a<<10);
        $c -= $a; $c -= $b; $c ^= (self::zeroFill($b,15));

        return array($a,$b,$c);
    }

    public static function strord($string) {
        for($i=0;$i<strlen($string);$i++) {
            $result[$i] = ord($string{$i});
        }
        return $result;
    }
}
?>

Usage example,



require_once "googlePageRank.php";

function getPR ($url) {

    preg_match(
        '|Rank_(\d*):(\d*):(\d*)|i',
        googlePageRank::get($url),
        $PR
    );

    return $PR[3];
}

echo getPR(URL);

Where URL is the domain you want to check.

Calculating TIC

Now let’s calculate Yandex TIC. To do that, we’ll enter URL (your domain).



function getTCY ($url) {

    preg_match(
        '|<tcy\s+rang=["\']?(\d*)["\']?\s+value=["\']?(\d*)["\']?\s?/>|i',
        file_get_contents('http://bar-navig.yandex.ru/u?ver=2&url='.urlencode($url).'&show=1'),
        $TCY
    );

    return $TCY[2];
}

echo getTCY(URL);

Well, that’s it. Any questions? Feel free to ask in the comments!
My response to A Quick Note on How to Find PR and CY

Comments are closed. Read the original discussion in Russian →