Mar 19
Monday, March 19th, 2007
This is modified code that I found from the Internet the orginal code that may not work on some server that php has 32bit operation problem and I already tested on my server.
PHP:
-
<?php
-
define('GOOGLE_MAGIC', 0xE6359A60
);
-
-
//unsigned shift right
-
function zeroFill($a, $b)
-
{
-
-
if ($z & $a)
-
{
-
$a = ($a>>1);
-
$a &= (~$z);
-
$a |= 0x40000000;
-
$a = ($a>>($b-1));
-
}
-
else
-
{
-
$a = ($a>>$b);
-
}
-
return $a;
-
}
-
-
function toInt32(& $x){
-
-
$y = (int)$x;
-
if($y==-$z&&$x<-$z){
-
$y = (int)((-1)*$x);
-
$y = (-1)*$y;
-
}
-
$x = $y;
-
}
-
-
function mix($a,$b,$c) {
-
$a -= $b; $a -= $c; toInt32($a); $a = (int)($a ^ (zeroFill($c,13)));
-
$b -= $c; $b -= $a; toInt32($b); $b = (int)($b ^ ($a<<8));
-
$c -= $a; $c -= $b; toInt32($c); $c = (int)($c ^ (zeroFill($b,13)));
-
$a -= $b; $a -= $c; toInt32($a); $a = (int)($a ^ (zeroFill($c,12)));
-
$b -= $c; $b -= $a; toInt32($b); $b = (int)($b ^ ($a<<16));
-
$c -= $a; $c -= $b; toInt32($c); $c = (int)($c ^ (zeroFill($b,5)));
-
$a -= $b; $a -= $c; toInt32($a); $a = (int)($a ^ (zeroFill($c,3)));
-
$b -= $c; $b -= $a; toInt32($b); $b = (int)($b ^ ($a<<10));
-
$c -= $a; $c -= $b; toInt32($c); $c = (int)($c ^ (zeroFill($b,15)));
-
-
}
-
-
function GoogleCH($url, $length=null, $init=GOOGLE_MAGIC) {
-
-
-
}
-
$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 = mix($a,$b,$c);
-
$a = $mix[0]; $b = $mix[1]; $c = $mix[2];
-
$k += 12;
-
$len -= 12;
-
}
-
-
$c += $length;
-
switch($len) /* all the case statements fall through */
-
{
-
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 = mix($a,$b,$c);
-
/*-------------------------------------------- report the result */
-
return $mix[2];
-
}
-
-
//converts a string into an array of integers containing the numeric value of the char
-
function strord($string) {
-
for($i=0;$i<strlen($string);$i++) {
-
$result[$i] =
ord($string{$i});
-
}
-
return $result;
-
}
-
-
-
// converts an array of 32 bit integers into an array with 8 bit values. Equivalent to (BYTE *)arr32
-
-
function c32to8bit($arr32) {
-
for($i=0;$i<count($arr32);$i++) {
-
for ($bitOrder=$i*4;$bitOrder<=$i*4+3;$bitOrder++) {
-
$arr8[$bitOrder]=$arr32[$i]&255;
-
$arr32[$i]=zeroFill($arr32[$i], 8);
-
}
-
}
-
return $arr8;
-
}
-
-
-
function get_page_rank($url){
-
-
$reqgr = "info:".$url;
-
-
$gch = "6".GoogleCH(strord($reqgr));
-
$fsock =
fsockopen('toolbarqueries.google.com',
80,
$errno,
$errstr);
-
if ( !$fsock ){
-
echo 'Can not connect to server';
-
return -1;
-
}
-
$base_get = "/search?client=navclient-auto&ch=".$gch."&ie=UTF-8&oe=UTF-8&features=Rank:FVN&q=".$reqgre;
-
fputs($fsock,
"GET $base_get HTTP/1.1\r\n");
-
-
fputs($fsock,
"User-Agent: Mozilla/4.0 (compatible; GoogleToolbar 2.0.114-big; Windows XP 5.1)\r\n");
-
fputs($fsock,
"Connection: close\r\n\r\n");
-
-
$res['content'] .=
fread($fsock,
1024);
-
}
-
-
if(preg_match('/Rank_.*?:.*?:(\d+)/i',
$res['content'],
$m)){
-
return $m[1];
-
}else{
-
return -1;
-
}
-
}
-
-
echo get_page_rank
("www.google.com");
-
-
?>
Posted in Internet, Programming, PHP | No Comments »
Feb 22
Thursday, February 22nd, 2007
PHP developer Stefan Esser has said he will go ahead with plans to disclose dozens of security flaws in PHP in March, hitting back at criticism that the “Month of PHP bugs” project is nothing more than dangerous, self-serving publicity. The problem isn’t irresponsible disclosure, but the sluggishness of the PHP team in fixing serious problems, Esser contended. He has first-hand experience with the PHP security process having created both the Hardened-PHP Project and the PHP Security Response Team, which he left acrimoniously in December.
Original post by Forum of Incident Response and Security Teams - Daily Security News
Posted in PHP, News | No Comments »
Feb 21
Wednesday, February 21st, 2007
“Stefan Esser is the founder of both the Hardened-PHP Project and the PHP Security Response Team (which he recently left). During an interview with SecurityFocus he announced the upcoming Month of PHP bugs initiative in March.”
Original post by Forum of Incident Response and Security Teams - Daily Security News
Posted in PHP, News | No Comments »
Feb 19
Monday, February 19th, 2007
I uses Ultimate Tag Warrior version 3.14159265 (February 4th, 2007) with WordPress 2.1, it work great but there have some problem or bug that when you try to open /tag it will show 404 errors. I check and try to make the page /tag or /tag/ show all tags with function of Ultimate Tag Warrior. Here is small changed.
PHP:
-
function ultimate_tag_templates() {
-
if ($_GET["archive"] == "tag") {
-
include(TEMPLATEPATH . '/tag_all.php');
-
-
} else if (get_query_var("tag") != "") {
-
ultimate_get_posts();
-
-
if (is_feed()) {
-
-
return;
-
}
-
-
if ( $_GET["feed"] == '') {
-
include(TEMPLATEPATH . '/tag.php');
-
-
}
-
} else {
-
// include(TEMPLATEPATH . '/index.php');
-
}
-
}
-
}
This function will process when you query for tag but you will see if you request with empty value of tag it won’t process anything and let Wordpress process this and finally it give 404 errors
I just made some changes to handle when user query with empty tag or open at /tag or /tag/
PHP:
-
function ultimate_tag_templates() {
-
if ($_GET["archive"] == "tag") {
-
include(TEMPLATEPATH . '/tag_all.php');
-
-
} else if (get_query_var("tag") != "") {
-
ultimate_get_posts();
-
-
if (is_feed()) {
-
-
return;
-
}
-
-
if ( $_GET["feed"] == '') {
-
include(TEMPLATEPATH . '/tag.php');
-
-
}
-
} else {
-
// include(TEMPLATEPATH . '/index.php');
-
} else {
-
if ( (eregi('^/tag$',
$_SERVER['REQUEST_URI']) ) ||
-
(eregi("^/tag/$",
$_SERVER['REQUEST_URI'])) ) {
-
include(TEMPLATEPATH . '/tags.php');
-
-
}
-
}
-
}
You may need to have file tags.php in your theme directory
Here is example of tags.php
PHP:
-
<?php get_header(); ?>
-
-
<div class="primary">
-
-
<?php UTW_ShowWeightedTagSetAlphabetical("coloredsizedtagcloud","",0) ?>
-
-
</div>
-
-
<?php get_sidebar(); ?>
-
-
<?php get_footer(); ?>
You also can change function or parameters to display tag in the page as you want. Please see all detail here UltimateTagWarrior help
Posted in PHP | 1 Comment »
Feb 16
Friday, February 16th, 2007
Today I try to change category name from anti-virus to virus but using old permalink /%category%/%postname%.html and i found later that there have 404 errors. I try to looking around on search engine but could not find any mod_rewrite to fix this problem. Finally I look into source code of Wordpress 2.1 and change the code below:-
/wp-includes/category.php
Search for line 168
function get_category_by_path($category_path, $full_match = true, $output = OBJECT) {
Add this code after global $wpdb;
$category_path = str_replace('old-category', 'new-category', $category_path);
For above I changed my /wp-includes/category.php to
......
function get_category_by_path($category_path, $full_match = true, $output = OBJECT) {
global $wpdb;
$category_path = str_replace('anti-virus', 'virus', $category_path);
......
Posted in PHP | No Comments »