Changeset 1041863
- Timestamp:
- 12/10/2014 11:45:51 AM (11 years ago)
- Location:
- wp-identicon
- Files:
-
- 4 edited
- 1 copied
-
tags/2.0 (copied) (copied from wp-identicon/trunk)
-
tags/2.0/readme.txt (modified) (1 diff)
-
tags/2.0/wp_identicon.php (modified) (15 diffs)
-
trunk/readme.txt (modified) (1 diff)
-
trunk/wp_identicon.php (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-identicon/tags/2.0/readme.txt
r44337 r1041863 2 2 Contributors: scottsm 3 3 Donate link: http://scott.sherrillmix.com/blog/ 4 Tags: comments, avatar, identicon, geometric, shape , gravatar, icon4 Tags: comments, avatar, identicon, geometric, shape, gravatar, icon 5 5 Requires at least: 1.5 6 Tested up to: 2.57 Stable tag: 1.026 Tested up to: 4.0.1 7 Stable tag: 2.0 8 8 9 9 Creates a unique, persistent geometric icons avatar for each commenter based on email address. -
wp-identicon/tags/2.0/wp_identicon.php
r44337 r1041863 2 2 /* 3 3 Plugin Name: WP_Identicon 4 Version: 1.024 Version: 2.0 5 5 Plugin URI: http://scott.sherrillmix.com/blog/blogger/wp_identicon/ 6 Description: This plugin generates persistent specific geometric icons for each user based on the ideas of <a href="http://www.docuverse.com/blog/donpark/2007/01/18/visual-security-9-block-ip-identification">Don Park</a>. 6 Description: This plugin generates persistent specific geometric icons for each user based on the ideas of <a href="http://www.docuverse.com/blog/donpark/2007/01/18/visual-security-9-block-ip-identification">Don Park</a>. Localisation support by Anna Ozeritskaya. 7 7 Author: Scott Sherrill-Mix 8 8 Author URI: http://scott.sherrillmix.com/blog/ … … 12 12 define('WP_IDENTICON_DIR_INTERNAL', dirname(__FILE__).'/identicon/'); 13 13 14 function identicon_textdomain() { 15 load_plugin_textdomain('wp-identicon', 'wp-content/plugins/wp-identicon'); 16 } 17 add_action('init', 'identicon_textdomain'); 14 18 15 19 function identicon_menu() { 16 20 if (function_exists('add_options_page')) { 17 add_options_page( 'Identicon Control Panel', 'Identicon', 1, basename(__FILE__), 'identicon_subpanel');21 add_options_page(__('Identicon Control Panel', 'wp-identicon'), 'Identicon', 1, basename(__FILE__), 'identicon_subpanel'); 18 22 } 19 23 } … … 217 221 imagedestroy($this->im); 218 222 if ($write){ 219 $wrote= imagepng($out,WP_IDENTICON_DIR_INTERNAL.$filename);223 $wrote=@imagepng($out,WP_IDENTICON_DIR_INTERNAL.$filename); 220 224 if(!$wrote) return false; //something went wrong but don't want to mess up blog layout 221 225 }else{ … … 229 233 $filename = "http://www.gravatar.com/avatar.php?gravatar_id=".md5($seed)."&size=$outsize&default=$filename"; 230 234 if ($img){ 231 $filename='<img class="identicon" src="'.$filename.'" alt="'.str_replace('"',"'",$altImgText).' Identicon Icon" height="'.$displaysize.'" width="'.$displaysize.'" />';235 $filename='<img class="identicon" src="'.$filename.'" alt="'.str_replace('"',"'",$altImgText).' Identicon" height="'.$displaysize.'" width="'.$displaysize.'" />'; 232 236 } 233 237 return $filename; … … 274 278 $identicon_options['size']=$identiconsize; 275 279 }else{ 276 echo "<div class='error'><p>Please enter an integer for size. Preferably between 30-200.</p></div>";280 echo '<div class="error"><p>'.__('Please enter an integer for size. Preferably between 30-200.', 'wp-identicon').'</p></div>'; 277 281 } 278 282 if ($identiconsquares > 0){ 279 283 $identicon_options['squares']=$identiconsquares; 280 284 }else{ 281 echo "<div class='error'><p>Please enter an integer for squares. Preferably 3 or greater and probably less than 10.".$identiconsquares.$_POST['identiconsquares']."</p></div>";285 echo '<div class="error"><p>'.__('Please enter an integer for squares. Preferably 3 or greater and probably less than 10.', 'wp-identicon').$identiconsquares.$_POST['identiconsquares'].'</p></div>'; 282 286 } 283 287 foreach(array('backr','backg','backb','forer','foreg','foreb') as $color){//update background color options … … 291 295 $identicon_options[$color]=$colorarray; 292 296 }else{ 293 echo "<div class='error'><p>Please enter a range between two integers for the background color (e.g. 230-255) between 1 and 255. For a single color please enter a single value (e.g. white = 255 for r,g and b).</p></div>";297 echo '<div class="error"><p>'.__('Please enter a range between two integers for the background color (e.g. 230-255) between 1 and 255. For a single color please enter a single value (e.g. white = 255 for r,g and b).', 'wp-identicon').'</p></div>'; 294 298 } 295 299 } … … 302 306 else $identicon_options['grey']=0; 303 307 update_option('identicon', $identicon_options); 304 echo "<div class='updated'><p>Options updated (you may have to clear the identicon cache to see any effect).</p></div>";308 echo '<div class="updated"><p>'.__('Options updated (you may have to clear the identicon cache to see any effect).', 'wp-identicon').'</p></div>'; 305 309 }elseif (isset($_POST['clear'])){ //clear the identicon cache 306 310 $dir=WP_IDENTICON_DIR_INTERNAL; … … 312 316 } 313 317 closedir($dh); 314 echo "<div class='updated'><p>Cache cleared.</p></div>";318 echo '<div class="updated"><p>'.__('Cache cleared.', 'wp-identicon').'</p></div>'; 315 319 } 316 320 } … … 327 331 } 328 332 ?> 329 <div><p><strong>This is the Identicon options page.</strong></p> 330 <p>You currently have <?php echo $identicon_count;?> identicons on your website.</p> 331 </div> 332 <div class='wrap'> 333 <p>Set options here:</p> 333 <div class="wrap"> 334 <h2><?php _e('Identicon Options Page', 'wp-identicon'); ?></h2> 335 336 <p><?php _e('You currently have', 'wp-identicon'); ?> <?php echo $identicon_count;?> <?php _e('identicons on your website', 'wp-identicon'); ?>.</p> 337 338 <h3><?php _e('Set options here:', 'wp-identicon'); ?></h3> 339 340 <div class="wrap"> 334 341 <form method="post" action="options-general.php?page=wp_identicon.php"> 335 342 <ul style="list-style-type: none"> 336 <li><strong> Identicon Size in Pixels</strong> (Default: 35):<br />343 <li><strong><?php _e('Identicon Size in Pixels', 'wp-identicon');?></strong> <?php _e('(Default: 35)', 'wp-identicon');?>:<br /> 337 344 <input type="text" name="identiconsize" value="<?php echo $identicon_options['size'];?>"/></li> 338 <li><strong> Number of Squares</strong> (Default: 4):<br />345 <li><strong><?php _e('Number of Squares', 'wp-identicon');?></strong> <?php _e('(Default: 4)', 'wp-identicon');?>:<br /> 339 346 <input type="text" name="identiconsquares" value="<?php echo $identicon_options['squares'];?>"/></li> 340 347 <?php if(!$identicon_options['grey']){ … … 347 354 $input_detail=array('r'=>'Gray:','g'=>'','b'=>''); 348 355 }?> 349 <li><strong> Background Colors</strong> (enter single value or range. 0,0,0 for transparent. Default: 255,255,255):<br />356 <li><strong><?php _e('Background Colors', 'wp-identicon');?></strong> <?php _e('(enter single value or range. 0,0,0 for transparent. Default: 255,255,255)', 'wp-identicon');?>:<br /> 350 357 <?php echo $input_detail['r'];?><input type="text" name="backr" <?php echo $input_back['r'];?> value="<?php echo implode($identicon_options['backr'],'-');?>"/> 351 358 <?php echo $input_detail['g'];?><input type="<?php echo $gbtype;?>" name="backg" <?php echo $input_back['g'];?> value="<?php echo implode($identicon_options['backg'],'-');?>"/> 352 359 <?php echo $input_detail['b'];?><input type="<?php echo $gbtype;?>" name="backb" <?php echo $input_back['b'];?> value="<?php echo implode($identicon_options['backb'],'-');?>"/></li> 353 <li><strong> Foreground Colors</strong> (enter single value or range. Default: 1-255,1-255,1-255):<br/>360 <li><strong><?php _e('Foreground Colors', 'wp-identicon');?></strong> <?php _e('(enter single value or range. Default: 1-255,1-255,1-255)', 'wp-identicon');?>:<br/> 354 361 <?php echo $input_detail['r'];?><input type="text" name="forer" <?php echo $input_back['r'];?> value="<?php echo implode($identicon_options['forer'],'-');?>"/> 355 362 <?php echo $input_detail['g'];?><input type="<?php echo $gbtype;?>" name="foreg" <?php echo $input_back['g'];?> value="<?php echo implode($identicon_options['foreg'],'-');?>"/> 356 363 <?php echo $input_detail['b'];?><input type="<?php echo $gbtype;?>" name="foreb" <?php echo $input_back['b'];?> value="<?php echo implode($identicon_options['foreb'],'-');?>"/></li> 357 <li><strong> Grayscale</strong> (Good for black and white themes):<input type="checkbox" name="grey" value="1" <?php if ($identicon_options['grey']) echo 'checked="checked"';?> /></li>358 <li><strong> Automatically Add Identicons to Comments</strong> (adds an Identicon beside commenter names or disable it and edit theme file manually) (default: Auto)<br /> <input type="radio" name="autoadd" value="0" <?php if (!$identicon_options['autoadd']) echo 'checked="checked"';?>/> I'll Do It Myself <input type="radio" name="autoadd" value="1" <?php if ($identicon_options['autoadd']==1) echo 'checked="checked"';?>/> Add Identicons For Me <input type="radio" name="autoadd" value="2" <?php if ($identicon_options['autoadd']==2) echo 'checked="checked"';?>/> My Theme Has Builtin WP2.5+ Avatars</li>359 <li><strong> Gravatar Support</strong> (If a commenter has a gravatar use it, otherwise use Identicon) (default: Identicon Only)<br /> <input type="radio" name="gravatar" value="0" <?php if (!$identicon_options['gravatar']) echo 'checked="checked"';?>/> Identicon Only <input type="radio" name="gravatar" value="1" <?php if ($identicon_options['gravatar']) echo 'checked="checked"';?>/> Gravatar + Identicon</li>360 <li><input type="submit" name="submit" value=" Set Options"/></li>364 <li><strong><?php _e('Grayscale', 'wp-identicon');?></strong> <?php _e('(Good for black and white themes)', 'wp-identicon');?>:<input type="checkbox" name="grey" value="1" <?php if ($identicon_options['grey']) echo 'checked="checked"';?> /></li> 365 <li><strong><?php _e('Automatically Add Identicons to Comments', 'wp-identicon');?></strong> <?php _e('(adds an Identicon beside commenter names or disable it and edit theme file manually) (default: Auto)', 'wp-identicon');?><br /> <input type="radio" name="autoadd" value="0" <?php if (!$identicon_options['autoadd']) echo 'checked="checked"';?>/> <?php _e("I'll Do It Myself", 'wp-identicon');?> <input type="radio" name="autoadd" value="1" <?php if ($identicon_options['autoadd']==1) echo 'checked="checked"';?>/> <?php _e('Add Identicons For Me', 'wp-identicon');?> <input type="radio" name="autoadd" value="2" <?php if ($identicon_options['autoadd']==2) echo 'checked="checked"';?>/> <?php _e('My Theme Has Builtin WP2.5+ Avatars', 'wp-identicon');?></li> 366 <li><strong><?php _e('Gravatar Support', 'wp-identicon');?></strong> <?php _e('(If a commenter has a gravatar use it, otherwise use Identicon) (default: Identicon Only)', 'wp-identicon');?><br /> <input type="radio" name="gravatar" value="0" <?php if (!$identicon_options['gravatar']) echo 'checked="checked"';?>/> <?php _e('Identicon Only', 'wp-identicon');?> <input type="radio" name="gravatar" value="1" <?php if ($identicon_options['gravatar']) echo 'checked="checked"';?>/> <?php _e('Gravatar + Identicon', 'wp-identicon');?></li> 367 <li><input type="submit" name="submit" value="<?php _e('Set Options', 'wp-identicon');?>"/></li> 361 368 </ul> 362 369 </form> 363 370 <form method="post" action="options-general.php?page=wp_identicon.php"> 364 <ul style="list-style-type: none"><li> Clear the Identicon Image Cache: <input type="submit" name="clear" value="Clear Cache"/></li></ul>371 <ul style="list-style-type: none"><li><?php _e('Clear the Identicon Image Cache', 'wp-identicon');?>: <input type="submit" name="clear" value="<?php _e('Clear Cache', 'wp-identicon');?>"/></li></ul> 365 372 </form> 366 373 </div> 367 <div class='wrap'><h4>To use Identicon:</h4> <p>Make sure the folder <code>wp-content/plugins/identicon</code> is writable. Identicons should automatically be added beside your commentors names after that. Enjoy.</p> 368 <p>If you use the Recent Comments Widget in your sidebar, this plugin also provides a replacement Recent Comments (with Identicons) Widget to add Identicons to the sidebar comments (just set it in the Widgets Control Panel)</p> 369 <strong>Testing:</strong><br/> 374 <div class='wrap'> 375 <h4><?php _e('To use Identicon', 'wp-identicon');?>:</h4> 376 <p><?php _e('Make sure the folder <code>wp-content/plugins/identicon</code> is writable. Identicons should automatically be added beside your commentors names after that. Enjoy.', 'wp-identicon');?></p> 377 <p><?php _e('If you use the Recent Comments Widget in your sidebar, this plugin also provides a replacement Recent Comments (with Identicons) Widget to add Identicons to the sidebar comments (just set it in the Widgets Control Panel).', 'wp-identicon');?></p> 378 <strong><?php _e('Testing', 'wp-identicon');?>:</strong><br/> 370 379 <?php if (!is_writable(''.WP_IDENTICON_DIR_INTERNAL)){echo "<div class='error'><p>Identicon needs ".WP_IDENTICON_DIR_INTERNAL." to be writable.</p></div>";} 371 380 if (!function_exists("gd_info")){echo "<div class='error'><p>GD Image library not found. Identicon needs this library.</p></div>";}?> 372 <p> A test identicon should be here:<?php $identicon=new identicon; echo $identicon->identicon_build('This is a test','Test');?> and the source URL for this image is <a href="<?php echo $identicon->identicon_build('This is a test','Test',false);?>">here</a>.</p>373 <p> If there is no identicon above or there are any other problems, concerns or suggestions please let me know <a href="http://scott.sherrillmix.com/blog/blogger/wp_identicon">here</a>. Enjoy your identicons.</p></div>374 <div class="wrap"><p> For curiosity's sake, here are the parts the identicons are built from:</p><div class='wrap'>381 <p><?php _e('A test identicon should be here', 'wp-identicon');?>:<?php $identicon=new identicon; echo $identicon->identicon_build('This is a test','Test');?> <?php _e('and the source URL for this image is', 'wp-identicon');?> <a href="<?php echo $identicon->identicon_build('This is a test','Test',false);?>"><?php _e('here', 'wp-identicon');?></a>.</p> 382 <p><?php _e('If there is no identicon above or there are any other problems, concerns or suggestions please let me know <a href="http://scott.sherrillmix.com/blog/blogger/wp_identicon">here</a>. Enjoy your identicons.', 'wp-identicon');?></p></div> 383 <div class="wrap"><p><?php _e("For curiosity's sake, here are the parts the identicons are built from", 'wp-identicon');?>:</p> 375 384 <?php echo $identicon->identicon_display_parts();?> 376 </div> 377 <h4>For advanced users:</h4> <p>Disable the automatic Indenticon placement and put: <br/> <code><?php echo htmlspecialchars('<?php if (function_exists("identicon_build")) {echo identicon_build($comment->comment_author_email,$comment->comment_author); } ?>');?></code><br/> in the comment loop of your theme comment script (probably <code>comments.php</code>). Or if you're more confident and just want the img URL use: 378 <code><?php echo htmlspecialchars('<?php if (function_exists("identicon_build")) {echo identicon_build($comment->comment_author_email,$comment->comment_author,false); } ?>');?></code></p> 379 <p>Please see the <a href="http://scott.sherrillmix.com/blog/blogger/wp_identicon/">plugin page</a> if you need more details.</p></div> 385 386 <h4><?php _e('For advanced users:', 'wp-identicon'); ?></h4> 387 <p><?php _e('Disable the automatic Indenticon placement and put', 'wp-identicon'); ?>: <br/> 388 <code><?php echo htmlspecialchars('<?php if (function_exists("identicon_build")) {echo identicon_build($comment->comment_author_email,$comment->comment_author); } ?>');?></code><br/> 389 <?php _e("in the comment loop of your theme comment script (probably <code>comments.php</code>). Or if you're more confident and just want the img URL use", 'wp-identicon'); ?>: 390 <code><?php echo htmlspecialchars('<?php if (function_exists("identicon_build")) {echo identicon_build($comment->comment_author_email,$comment->comment_author,false); } ?>');?></code></p> 391 392 <p><?php _e('Please see the <a href="http://scott.sherrillmix.com/blog/blogger/wp_identicon/">plugin page</a> if you need more details.', 'wp-identicon'); ?></p> 380 393 381 382 <div><p>The idea for Identicons came from <a href="http://www.docuverse.com/blog/donpark/2007/01/18/visual-security-9-block-ip-identification">Don Park</a>.</p></div> 383 </div> 394 <p><?php _e('The idea for Identicons came from', 'wp-identicon'); ?> <a href="http://www.docuverse.com/blog/donpark/2007/01/18/visual-security-9-block-ip-identification">Don Park</a>.</p> 395 </div> 384 396 <?php 385 397 } … … 387 399 388 400 class identicon_mersenne_twister{ 389 //Copied from wikipedia pseudocode 390 //Don't call over 600 times (without recalling the constructor) 391 // Create a length 624 array to store the state of the generator 392 var $MT; 393 var $i; 394 // Initialise the generator from a seed 395 function identicon_mersenne_twister ($seed=123456) { 396 $this->MT[0] = $seed; 397 $this->i=1; 398 for ($i=1;$i<624;$i++) { // loop over each other element 399 $this->MT[$i] = $this->mysql_math('(1812433253 * ('.$this->MT[$i-1].' ^ ('.$this->MT[$i-1]." >> 30)) + $i) & 0xffffffff"); 400 } 401 $this->generateNumbers(); 402 } 403 404 //(some) PHP integers don't have enough bits for Mersenne Twister so use mysql 405 function mysql_math($equation){ 406 global $wpdb; 407 $query="SELECT ".$equation; 408 $answer=$wpdb->get_var($query); 409 return $answer; 410 } 411 412 // Generate an array of 624 untempered numbers 413 function generateNumbers() { 414 for ($i=0;$i<624;$i++) { 415 $y = $this->mysql_math('('.$this->MT[$i].' & 0x7fffffff) + ('.$this->MT[($i+1)%624].' & 0xfffffffe)'); 416 $even=$this->mysql_math($y.' ^ 0x00000001'); 417 if ($even) { 418 $this->MT[$i] = $this->mysql_math($this->MT[($i + 397) % 624]." ^ ($y >> 1)"); 419 } else { 420 $this->MT[$i] = $this->mysql_math($this->MT[($i + 397) % 624]." ^ ($y >>1) ^ (2567483615)"); // 0x9908b0df 421 } 422 } 423 } 424 425 // Extract a tempered pseudorandom number based on the i-th value 426 // generateNumbers() will have to be called again once the array of 624 numbers is exhausted 427 function extractNumber() { 428 $y = $this->MT[$this->i]; 429 $y = $this->mysql_math("$y ^ ($y >>11) ^ (($y << 7) & 2636928640) ^ (($y << 15) & 4022730752) ^ ($y >>18)"); 430 $this->i++; 431 return $y/0xffffffff; 432 } 433 434 function rand($low,$high){ 435 $pick=floor($low+($high-$low+1)*$this->extractNumber()); 436 return ($pick); 437 } 438 function array_rand($array){ 439 return($this->rand(0,count($array)-1)); 401 //MySQL version doesn't work since they shut down integer overflow switching to: 402 //https://github.com/ruafozy/php-mersenne-twister/blob/master/src/mersenne_twister.php 403 404 function identicon_mersenne_twister($seed=123456) { 405 $this->bits32 = PHP_INT_MAX == 2147483647; 406 $this->define_constants(); 407 $this->init_with_integer($seed); 408 } 409 410 function define_constants() { 411 $this->N = 624; 412 $this->M = 397; 413 $this->MATRIX_A = 0x9908b0df; 414 $this->UPPER_MASK = 0x80000000; 415 $this->LOWER_MASK = 0x7fffffff; 416 417 $this->MASK10=~((~0) << 10); 418 $this->MASK11=~((~0) << 11); 419 $this->MASK12=~((~0) << 12); 420 $this->MASK14=~((~0) << 14); 421 $this->MASK20=~((~0) << 20); 422 $this->MASK21=~((~0) << 21); 423 $this->MASK22=~((~0) << 22); 424 $this->MASK26=~((~0) << 26); 425 $this->MASK27=~((~0) << 27); 426 $this->MASK31=~((~0) << 31); 427 428 $this->TWO_TO_THE_16=pow(2,16); 429 $this->TWO_TO_THE_31=pow(2,31); 430 $this->TWO_TO_THE_32=pow(2,32); 431 432 $this->MASK32 = $this->MASK31 | ($this->MASK31 << 1); 433 } 434 435 function init_with_integer($integer_seed) { 436 $integer_seed = $this->force_32_bit_int($integer_seed); 437 438 $mt = &$this->mt; 439 $mti = &$this->mti; 440 441 $mt = array_fill(0, $this->N, 0); 442 443 $mt[0] = $integer_seed; 444 445 for($mti = 1; $mti < $this->N; $mti++) { 446 $mt[$mti] = $this->add_2($this->mul(1812433253, 447 ($mt[$mti - 1] ^ (($mt[$mti - 1] >> 30) & 3))), $mti); 448 /* 449 mt[mti] = 450 (1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti); 451 */ 452 } 453 } 454 455 /* generates a random number on [0,1)-real-interval */ 456 function real_halfopen() { 457 return 458 $this->signed2unsigned($this->int32()) * (1.0 / 4294967296.0); 459 } 460 function int32() { 461 $mag01 = array(0, $this->MATRIX_A); 462 463 $mt = &$this->mt; 464 $mti = &$this->mti; 465 466 if ($mti >= $this->N) { /* generate N words all at once */ 467 for ($kk=0;$kk<$this->N-$this->M;$kk++) { 468 $y = ($mt[$kk]&$this->UPPER_MASK)|($mt[$kk+1]&$this->LOWER_MASK); 469 $mt[$kk] = $mt[$kk+$this->M] ^ (($y >> 1) & $this->MASK31) ^ $mag01[$y & 1]; 470 } 471 for (;$kk<$this->N-1;$kk++) { 472 $y = ($mt[$kk]&$this->UPPER_MASK)|($mt[$kk+1]&$this->LOWER_MASK); 473 $mt[$kk] = 474 $mt[$kk+($this->M-$this->N)] ^ (($y >> 1) & $this->MASK31) ^ $mag01[$y & 1]; 475 } 476 $y = ($mt[$this->N-1]&$this->UPPER_MASK)|($mt[0]&$this->LOWER_MASK); 477 $mt[$this->N-1] = $mt[$this->M-1] ^ (($y >> 1) & $this->MASK31) ^ $mag01[$y & 1]; 478 479 $mti = 0; 480 } 481 482 $y = $mt[$mti++]; 483 484 /* Tempering */ 485 $y ^= ($y >> 11) & $this->MASK21; 486 $y ^= ($y << 7) & ((0x9d2c << 16) | 0x5680); 487 $y ^= ($y << 15) & (0xefc6 << 16); 488 $y ^= ($y >> 18) & $this->MASK14; 489 490 return $y; 491 } 492 493 function signed2unsigned($signed_integer) { 494 ## assert(is_integer($signed_integer)); 495 ## assert(($signed_integer & ~$this->MASK32) === 0); 496 497 return $signed_integer >= 0? $signed_integer: 498 $this->TWO_TO_THE_32 + $signed_integer; 499 } 500 501 function unsigned2signed($unsigned_integer) { 502 ## assert($unsigned_integer >= 0); 503 ## assert($unsigned_integer < pow(2, 32)); 504 ## assert(floor($unsigned_integer) === floatval($unsigned_integer)); 505 506 return intval($unsigned_integer < $this->TWO_TO_THE_31? $unsigned_integer: 507 $unsigned_integer - $this->TWO_TO_THE_32); 508 } 509 510 function force_32_bit_int($x) { 511 /* 512 it would be un-PHP-like to require is_integer($x), 513 so we have to handle cases like this: 514 515 $x === pow(2, 31) 516 $x === strval(pow(2, 31)) 517 518 we are also opting to do something sensible (rather than dying) 519 if the seed is outside the range of a 32-bit unsigned integer. 520 */ 521 522 if(is_integer($x)) { 523 /* 524 we mask in case we are on a 64-bit machine and at least one 525 bit is set between position 32 and position 63. 526 */ 527 return $x & $this->MASK32; 528 } else { 529 $x = floatval($x); 530 531 $x = $x < 0? ceil($x): floor($x); 532 533 $x = fmod($x, $this->TWO_TO_THE_32); 534 535 if($x < 0) 536 $x += $this->TWO_TO_THE_32; 537 538 return $this->unsigned2signed($x); 539 } 540 } 541 542 /* 543 takes 2 integers, treats them as unsigned 32-bit integers, 544 and adds them. 545 546 it works by splitting each integer into 547 2 "half-integers", then adding the high and low half-integers 548 separately. 549 550 a slight complication is that the sum of the low half-integers 551 may not fit into 16 bits; any "overspill" is added to the sum 552 of the high half-integers. 553 */ 554 function add_2($n1, $n2) { 555 $x = ($n1 & 0xffff) + ($n2 & 0xffff); 556 557 return 558 (((($n1 >> 16) & 0xffff) + 559 (($n2 >> 16) & 0xffff) + 560 ($x >> 16)) << 16) | ($x & 0xffff); 561 } 562 563 function mul($a, $b) { 564 /* 565 a and b, considered as unsigned integers, can be expressed as follows: 566 567 a = 2**16 * a1 + a2, 568 569 b = 2**16 * b1 + b2, 570 571 where 572 573 0 <= a2 < 2**16, 574 0 <= b2 < 2**16. 575 576 given those 2 equations, what this function essentially does is to 577 use the following identity: 578 579 a * b = 2**32 * a1 * b1 + 2**16 * a1 * b2 + 2**16 * b1 * a2 + a2 * b2 580 581 note that the first term, i.e. 2**32 * a1 * b1, is unnecessary here, 582 so we don't compute it. 583 584 we could make the following code clearer by using intermediate 585 variables, but that would probably hurt performance. 586 */ 587 588 return 589 $this->unsigned2signed( 590 fmod( 591 $this->TWO_TO_THE_16 * 592 /* 593 the next line of code calculates a1 * b2, 594 the line after that calculates b1 * a2, 595 and the line after that calculates a2 * b2. 596 */ 597 ((($a >> 16) & 0xffff) * ($b & 0xffff) + 598 (($b >> 16) & 0xffff) * ($a & 0xffff)) + 599 ($a & 0xffff) * ($b & 0xffff), 600 601 $this->TWO_TO_THE_32)); 602 } 603 604 function rand($low,$high){ 605 $pick=floor($low+($high-$low+1)*$this->real_halfopen()); 606 return ($pick); 607 } 608 609 function array_rand($array){ 610 return($this->rand(0,count($array)-1)); 440 611 } 441 612 } … … 510 681 extract($args, EXTR_SKIP); 511 682 $options = get_option('widget_identicon_recent_comments'); 512 $title = empty($options['title']) ? __('Recent Comments' ) : $options['title'];683 $title = empty($options['title']) ? __('Recent Comments', 'wp-identicon') : $options['title']; 513 684 if ( !$number = (int) $options['number'] ) 514 685 $number = 5; … … 536 707 if($comment->comment_type!="pingback"&&$comment->comment_type!="trackback"&&isset($identicon)) 537 708 echo $identicon->identicon_build($comment->comment_author_email,$comment->comment_author,TRUE,'',TRUE,TRUE,$size).' '; 538 echo sprintf(__('%1$s on %2$s' ), get_comment_author_link(), '<a href="'. get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>';709 echo sprintf(__('%1$s on %2$s', 'wp-identicon'), get_comment_author_link(), '<a href="'. get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>'; 539 710 endforeach; endif;?></ul> 540 711 <?php echo $after_widget; ?> … … 564 735 $size = 10; 565 736 ?> 566 <p><label for="identicon_recent-comments-title"><?php _e('Title:' ); ?> <input style="width: 250px;" id="identicon_recent-comments-title" name="identicon_recent-comments-title" type="text" value="<?php echo $title; ?>" /></label></p>567 <p><label for="identicon_recent-comments-number"><?php _e('Number of comments to show:' ); ?> <input style="width: 25px; text-align: center;" id="identicon_recent-comments-number" name="identicon_recent-comments-number" type="text" value="<?php echo $number; ?>" /></label> <?php _e('(at most 15)'); ?></p>568 <p><label for="identicon_size"><?php _e('Size of Widget Identicons (pixels):' ); ?> <input style="width: 25px; text-align: center;" id="identicon_size" name="identicon_size" type="text" value="<?php echo $size; ?>" /></label></p>737 <p><label for="identicon_recent-comments-title"><?php _e('Title:', 'wp-identicon'); ?> <input style="width: 250px;" id="identicon_recent-comments-title" name="identicon_recent-comments-title" type="text" value="<?php echo $title; ?>" /></label></p> 738 <p><label for="identicon_recent-comments-number"><?php _e('Number of comments to show:', 'wp-identicon'); ?> <input style="width: 25px; text-align: center;" id="identicon_recent-comments-number" name="identicon_recent-comments-number" type="text" value="<?php echo $number; ?>" /></label> <?php _e('(at most 15)', 'wp-identicon'); ?></p> 739 <p><label for="identicon_size"><?php _e('Size of Widget Identicons (pixels):', 'wp-identicon'); ?> <input style="width: 25px; text-align: center;" id="identicon_size" name="identicon_size" type="text" value="<?php echo $size; ?>" /></label></p> 569 740 <input type="hidden" id="identicon_recent-comments-submit" name="identicon_recent-comments-submit" value="1" /> 570 741 <?php … … 591 762 } 592 763 764 593 765 add_action('widgets_init', 'identicon_recent_comments_widget_init'); 594 766 ?> -
wp-identicon/trunk/readme.txt
r44337 r1041863 2 2 Contributors: scottsm 3 3 Donate link: http://scott.sherrillmix.com/blog/ 4 Tags: comments, avatar, identicon, geometric, shape , gravatar, icon4 Tags: comments, avatar, identicon, geometric, shape, gravatar, icon 5 5 Requires at least: 1.5 6 Tested up to: 2.57 Stable tag: 1.026 Tested up to: 4.0.1 7 Stable tag: 2.0 8 8 9 9 Creates a unique, persistent geometric icons avatar for each commenter based on email address. -
wp-identicon/trunk/wp_identicon.php
r44337 r1041863 2 2 /* 3 3 Plugin Name: WP_Identicon 4 Version: 1.024 Version: 2.0 5 5 Plugin URI: http://scott.sherrillmix.com/blog/blogger/wp_identicon/ 6 Description: This plugin generates persistent specific geometric icons for each user based on the ideas of <a href="http://www.docuverse.com/blog/donpark/2007/01/18/visual-security-9-block-ip-identification">Don Park</a>. 6 Description: This plugin generates persistent specific geometric icons for each user based on the ideas of <a href="http://www.docuverse.com/blog/donpark/2007/01/18/visual-security-9-block-ip-identification">Don Park</a>. Localisation support by Anna Ozeritskaya. 7 7 Author: Scott Sherrill-Mix 8 8 Author URI: http://scott.sherrillmix.com/blog/ … … 12 12 define('WP_IDENTICON_DIR_INTERNAL', dirname(__FILE__).'/identicon/'); 13 13 14 function identicon_textdomain() { 15 load_plugin_textdomain('wp-identicon', 'wp-content/plugins/wp-identicon'); 16 } 17 add_action('init', 'identicon_textdomain'); 14 18 15 19 function identicon_menu() { 16 20 if (function_exists('add_options_page')) { 17 add_options_page( 'Identicon Control Panel', 'Identicon', 1, basename(__FILE__), 'identicon_subpanel');21 add_options_page(__('Identicon Control Panel', 'wp-identicon'), 'Identicon', 1, basename(__FILE__), 'identicon_subpanel'); 18 22 } 19 23 } … … 217 221 imagedestroy($this->im); 218 222 if ($write){ 219 $wrote= imagepng($out,WP_IDENTICON_DIR_INTERNAL.$filename);223 $wrote=@imagepng($out,WP_IDENTICON_DIR_INTERNAL.$filename); 220 224 if(!$wrote) return false; //something went wrong but don't want to mess up blog layout 221 225 }else{ … … 229 233 $filename = "http://www.gravatar.com/avatar.php?gravatar_id=".md5($seed)."&size=$outsize&default=$filename"; 230 234 if ($img){ 231 $filename='<img class="identicon" src="'.$filename.'" alt="'.str_replace('"',"'",$altImgText).' Identicon Icon" height="'.$displaysize.'" width="'.$displaysize.'" />';235 $filename='<img class="identicon" src="'.$filename.'" alt="'.str_replace('"',"'",$altImgText).' Identicon" height="'.$displaysize.'" width="'.$displaysize.'" />'; 232 236 } 233 237 return $filename; … … 274 278 $identicon_options['size']=$identiconsize; 275 279 }else{ 276 echo "<div class='error'><p>Please enter an integer for size. Preferably between 30-200.</p></div>";280 echo '<div class="error"><p>'.__('Please enter an integer for size. Preferably between 30-200.', 'wp-identicon').'</p></div>'; 277 281 } 278 282 if ($identiconsquares > 0){ 279 283 $identicon_options['squares']=$identiconsquares; 280 284 }else{ 281 echo "<div class='error'><p>Please enter an integer for squares. Preferably 3 or greater and probably less than 10.".$identiconsquares.$_POST['identiconsquares']."</p></div>";285 echo '<div class="error"><p>'.__('Please enter an integer for squares. Preferably 3 or greater and probably less than 10.', 'wp-identicon').$identiconsquares.$_POST['identiconsquares'].'</p></div>'; 282 286 } 283 287 foreach(array('backr','backg','backb','forer','foreg','foreb') as $color){//update background color options … … 291 295 $identicon_options[$color]=$colorarray; 292 296 }else{ 293 echo "<div class='error'><p>Please enter a range between two integers for the background color (e.g. 230-255) between 1 and 255. For a single color please enter a single value (e.g. white = 255 for r,g and b).</p></div>";297 echo '<div class="error"><p>'.__('Please enter a range between two integers for the background color (e.g. 230-255) between 1 and 255. For a single color please enter a single value (e.g. white = 255 for r,g and b).', 'wp-identicon').'</p></div>'; 294 298 } 295 299 } … … 302 306 else $identicon_options['grey']=0; 303 307 update_option('identicon', $identicon_options); 304 echo "<div class='updated'><p>Options updated (you may have to clear the identicon cache to see any effect).</p></div>";308 echo '<div class="updated"><p>'.__('Options updated (you may have to clear the identicon cache to see any effect).', 'wp-identicon').'</p></div>'; 305 309 }elseif (isset($_POST['clear'])){ //clear the identicon cache 306 310 $dir=WP_IDENTICON_DIR_INTERNAL; … … 312 316 } 313 317 closedir($dh); 314 echo "<div class='updated'><p>Cache cleared.</p></div>";318 echo '<div class="updated"><p>'.__('Cache cleared.', 'wp-identicon').'</p></div>'; 315 319 } 316 320 } … … 327 331 } 328 332 ?> 329 <div><p><strong>This is the Identicon options page.</strong></p> 330 <p>You currently have <?php echo $identicon_count;?> identicons on your website.</p> 331 </div> 332 <div class='wrap'> 333 <p>Set options here:</p> 333 <div class="wrap"> 334 <h2><?php _e('Identicon Options Page', 'wp-identicon'); ?></h2> 335 336 <p><?php _e('You currently have', 'wp-identicon'); ?> <?php echo $identicon_count;?> <?php _e('identicons on your website', 'wp-identicon'); ?>.</p> 337 338 <h3><?php _e('Set options here:', 'wp-identicon'); ?></h3> 339 340 <div class="wrap"> 334 341 <form method="post" action="options-general.php?page=wp_identicon.php"> 335 342 <ul style="list-style-type: none"> 336 <li><strong> Identicon Size in Pixels</strong> (Default: 35):<br />343 <li><strong><?php _e('Identicon Size in Pixels', 'wp-identicon');?></strong> <?php _e('(Default: 35)', 'wp-identicon');?>:<br /> 337 344 <input type="text" name="identiconsize" value="<?php echo $identicon_options['size'];?>"/></li> 338 <li><strong> Number of Squares</strong> (Default: 4):<br />345 <li><strong><?php _e('Number of Squares', 'wp-identicon');?></strong> <?php _e('(Default: 4)', 'wp-identicon');?>:<br /> 339 346 <input type="text" name="identiconsquares" value="<?php echo $identicon_options['squares'];?>"/></li> 340 347 <?php if(!$identicon_options['grey']){ … … 347 354 $input_detail=array('r'=>'Gray:','g'=>'','b'=>''); 348 355 }?> 349 <li><strong> Background Colors</strong> (enter single value or range. 0,0,0 for transparent. Default: 255,255,255):<br />356 <li><strong><?php _e('Background Colors', 'wp-identicon');?></strong> <?php _e('(enter single value or range. 0,0,0 for transparent. Default: 255,255,255)', 'wp-identicon');?>:<br /> 350 357 <?php echo $input_detail['r'];?><input type="text" name="backr" <?php echo $input_back['r'];?> value="<?php echo implode($identicon_options['backr'],'-');?>"/> 351 358 <?php echo $input_detail['g'];?><input type="<?php echo $gbtype;?>" name="backg" <?php echo $input_back['g'];?> value="<?php echo implode($identicon_options['backg'],'-');?>"/> 352 359 <?php echo $input_detail['b'];?><input type="<?php echo $gbtype;?>" name="backb" <?php echo $input_back['b'];?> value="<?php echo implode($identicon_options['backb'],'-');?>"/></li> 353 <li><strong> Foreground Colors</strong> (enter single value or range. Default: 1-255,1-255,1-255):<br/>360 <li><strong><?php _e('Foreground Colors', 'wp-identicon');?></strong> <?php _e('(enter single value or range. Default: 1-255,1-255,1-255)', 'wp-identicon');?>:<br/> 354 361 <?php echo $input_detail['r'];?><input type="text" name="forer" <?php echo $input_back['r'];?> value="<?php echo implode($identicon_options['forer'],'-');?>"/> 355 362 <?php echo $input_detail['g'];?><input type="<?php echo $gbtype;?>" name="foreg" <?php echo $input_back['g'];?> value="<?php echo implode($identicon_options['foreg'],'-');?>"/> 356 363 <?php echo $input_detail['b'];?><input type="<?php echo $gbtype;?>" name="foreb" <?php echo $input_back['b'];?> value="<?php echo implode($identicon_options['foreb'],'-');?>"/></li> 357 <li><strong> Grayscale</strong> (Good for black and white themes):<input type="checkbox" name="grey" value="1" <?php if ($identicon_options['grey']) echo 'checked="checked"';?> /></li>358 <li><strong> Automatically Add Identicons to Comments</strong> (adds an Identicon beside commenter names or disable it and edit theme file manually) (default: Auto)<br /> <input type="radio" name="autoadd" value="0" <?php if (!$identicon_options['autoadd']) echo 'checked="checked"';?>/> I'll Do It Myself <input type="radio" name="autoadd" value="1" <?php if ($identicon_options['autoadd']==1) echo 'checked="checked"';?>/> Add Identicons For Me <input type="radio" name="autoadd" value="2" <?php if ($identicon_options['autoadd']==2) echo 'checked="checked"';?>/> My Theme Has Builtin WP2.5+ Avatars</li>359 <li><strong> Gravatar Support</strong> (If a commenter has a gravatar use it, otherwise use Identicon) (default: Identicon Only)<br /> <input type="radio" name="gravatar" value="0" <?php if (!$identicon_options['gravatar']) echo 'checked="checked"';?>/> Identicon Only <input type="radio" name="gravatar" value="1" <?php if ($identicon_options['gravatar']) echo 'checked="checked"';?>/> Gravatar + Identicon</li>360 <li><input type="submit" name="submit" value=" Set Options"/></li>364 <li><strong><?php _e('Grayscale', 'wp-identicon');?></strong> <?php _e('(Good for black and white themes)', 'wp-identicon');?>:<input type="checkbox" name="grey" value="1" <?php if ($identicon_options['grey']) echo 'checked="checked"';?> /></li> 365 <li><strong><?php _e('Automatically Add Identicons to Comments', 'wp-identicon');?></strong> <?php _e('(adds an Identicon beside commenter names or disable it and edit theme file manually) (default: Auto)', 'wp-identicon');?><br /> <input type="radio" name="autoadd" value="0" <?php if (!$identicon_options['autoadd']) echo 'checked="checked"';?>/> <?php _e("I'll Do It Myself", 'wp-identicon');?> <input type="radio" name="autoadd" value="1" <?php if ($identicon_options['autoadd']==1) echo 'checked="checked"';?>/> <?php _e('Add Identicons For Me', 'wp-identicon');?> <input type="radio" name="autoadd" value="2" <?php if ($identicon_options['autoadd']==2) echo 'checked="checked"';?>/> <?php _e('My Theme Has Builtin WP2.5+ Avatars', 'wp-identicon');?></li> 366 <li><strong><?php _e('Gravatar Support', 'wp-identicon');?></strong> <?php _e('(If a commenter has a gravatar use it, otherwise use Identicon) (default: Identicon Only)', 'wp-identicon');?><br /> <input type="radio" name="gravatar" value="0" <?php if (!$identicon_options['gravatar']) echo 'checked="checked"';?>/> <?php _e('Identicon Only', 'wp-identicon');?> <input type="radio" name="gravatar" value="1" <?php if ($identicon_options['gravatar']) echo 'checked="checked"';?>/> <?php _e('Gravatar + Identicon', 'wp-identicon');?></li> 367 <li><input type="submit" name="submit" value="<?php _e('Set Options', 'wp-identicon');?>"/></li> 361 368 </ul> 362 369 </form> 363 370 <form method="post" action="options-general.php?page=wp_identicon.php"> 364 <ul style="list-style-type: none"><li> Clear the Identicon Image Cache: <input type="submit" name="clear" value="Clear Cache"/></li></ul>371 <ul style="list-style-type: none"><li><?php _e('Clear the Identicon Image Cache', 'wp-identicon');?>: <input type="submit" name="clear" value="<?php _e('Clear Cache', 'wp-identicon');?>"/></li></ul> 365 372 </form> 366 373 </div> 367 <div class='wrap'><h4>To use Identicon:</h4> <p>Make sure the folder <code>wp-content/plugins/identicon</code> is writable. Identicons should automatically be added beside your commentors names after that. Enjoy.</p> 368 <p>If you use the Recent Comments Widget in your sidebar, this plugin also provides a replacement Recent Comments (with Identicons) Widget to add Identicons to the sidebar comments (just set it in the Widgets Control Panel)</p> 369 <strong>Testing:</strong><br/> 374 <div class='wrap'> 375 <h4><?php _e('To use Identicon', 'wp-identicon');?>:</h4> 376 <p><?php _e('Make sure the folder <code>wp-content/plugins/identicon</code> is writable. Identicons should automatically be added beside your commentors names after that. Enjoy.', 'wp-identicon');?></p> 377 <p><?php _e('If you use the Recent Comments Widget in your sidebar, this plugin also provides a replacement Recent Comments (with Identicons) Widget to add Identicons to the sidebar comments (just set it in the Widgets Control Panel).', 'wp-identicon');?></p> 378 <strong><?php _e('Testing', 'wp-identicon');?>:</strong><br/> 370 379 <?php if (!is_writable(''.WP_IDENTICON_DIR_INTERNAL)){echo "<div class='error'><p>Identicon needs ".WP_IDENTICON_DIR_INTERNAL." to be writable.</p></div>";} 371 380 if (!function_exists("gd_info")){echo "<div class='error'><p>GD Image library not found. Identicon needs this library.</p></div>";}?> 372 <p> A test identicon should be here:<?php $identicon=new identicon; echo $identicon->identicon_build('This is a test','Test');?> and the source URL for this image is <a href="<?php echo $identicon->identicon_build('This is a test','Test',false);?>">here</a>.</p>373 <p> If there is no identicon above or there are any other problems, concerns or suggestions please let me know <a href="http://scott.sherrillmix.com/blog/blogger/wp_identicon">here</a>. Enjoy your identicons.</p></div>374 <div class="wrap"><p> For curiosity's sake, here are the parts the identicons are built from:</p><div class='wrap'>381 <p><?php _e('A test identicon should be here', 'wp-identicon');?>:<?php $identicon=new identicon; echo $identicon->identicon_build('This is a test','Test');?> <?php _e('and the source URL for this image is', 'wp-identicon');?> <a href="<?php echo $identicon->identicon_build('This is a test','Test',false);?>"><?php _e('here', 'wp-identicon');?></a>.</p> 382 <p><?php _e('If there is no identicon above or there are any other problems, concerns or suggestions please let me know <a href="http://scott.sherrillmix.com/blog/blogger/wp_identicon">here</a>. Enjoy your identicons.', 'wp-identicon');?></p></div> 383 <div class="wrap"><p><?php _e("For curiosity's sake, here are the parts the identicons are built from", 'wp-identicon');?>:</p> 375 384 <?php echo $identicon->identicon_display_parts();?> 376 </div> 377 <h4>For advanced users:</h4> <p>Disable the automatic Indenticon placement and put: <br/> <code><?php echo htmlspecialchars('<?php if (function_exists("identicon_build")) {echo identicon_build($comment->comment_author_email,$comment->comment_author); } ?>');?></code><br/> in the comment loop of your theme comment script (probably <code>comments.php</code>). Or if you're more confident and just want the img URL use: 378 <code><?php echo htmlspecialchars('<?php if (function_exists("identicon_build")) {echo identicon_build($comment->comment_author_email,$comment->comment_author,false); } ?>');?></code></p> 379 <p>Please see the <a href="http://scott.sherrillmix.com/blog/blogger/wp_identicon/">plugin page</a> if you need more details.</p></div> 385 386 <h4><?php _e('For advanced users:', 'wp-identicon'); ?></h4> 387 <p><?php _e('Disable the automatic Indenticon placement and put', 'wp-identicon'); ?>: <br/> 388 <code><?php echo htmlspecialchars('<?php if (function_exists("identicon_build")) {echo identicon_build($comment->comment_author_email,$comment->comment_author); } ?>');?></code><br/> 389 <?php _e("in the comment loop of your theme comment script (probably <code>comments.php</code>). Or if you're more confident and just want the img URL use", 'wp-identicon'); ?>: 390 <code><?php echo htmlspecialchars('<?php if (function_exists("identicon_build")) {echo identicon_build($comment->comment_author_email,$comment->comment_author,false); } ?>');?></code></p> 391 392 <p><?php _e('Please see the <a href="http://scott.sherrillmix.com/blog/blogger/wp_identicon/">plugin page</a> if you need more details.', 'wp-identicon'); ?></p> 380 393 381 382 <div><p>The idea for Identicons came from <a href="http://www.docuverse.com/blog/donpark/2007/01/18/visual-security-9-block-ip-identification">Don Park</a>.</p></div> 383 </div> 394 <p><?php _e('The idea for Identicons came from', 'wp-identicon'); ?> <a href="http://www.docuverse.com/blog/donpark/2007/01/18/visual-security-9-block-ip-identification">Don Park</a>.</p> 395 </div> 384 396 <?php 385 397 } … … 387 399 388 400 class identicon_mersenne_twister{ 389 //Copied from wikipedia pseudocode 390 //Don't call over 600 times (without recalling the constructor) 391 // Create a length 624 array to store the state of the generator 392 var $MT; 393 var $i; 394 // Initialise the generator from a seed 395 function identicon_mersenne_twister ($seed=123456) { 396 $this->MT[0] = $seed; 397 $this->i=1; 398 for ($i=1;$i<624;$i++) { // loop over each other element 399 $this->MT[$i] = $this->mysql_math('(1812433253 * ('.$this->MT[$i-1].' ^ ('.$this->MT[$i-1]." >> 30)) + $i) & 0xffffffff"); 400 } 401 $this->generateNumbers(); 402 } 403 404 //(some) PHP integers don't have enough bits for Mersenne Twister so use mysql 405 function mysql_math($equation){ 406 global $wpdb; 407 $query="SELECT ".$equation; 408 $answer=$wpdb->get_var($query); 409 return $answer; 410 } 411 412 // Generate an array of 624 untempered numbers 413 function generateNumbers() { 414 for ($i=0;$i<624;$i++) { 415 $y = $this->mysql_math('('.$this->MT[$i].' & 0x7fffffff) + ('.$this->MT[($i+1)%624].' & 0xfffffffe)'); 416 $even=$this->mysql_math($y.' ^ 0x00000001'); 417 if ($even) { 418 $this->MT[$i] = $this->mysql_math($this->MT[($i + 397) % 624]." ^ ($y >> 1)"); 419 } else { 420 $this->MT[$i] = $this->mysql_math($this->MT[($i + 397) % 624]." ^ ($y >>1) ^ (2567483615)"); // 0x9908b0df 421 } 422 } 423 } 424 425 // Extract a tempered pseudorandom number based on the i-th value 426 // generateNumbers() will have to be called again once the array of 624 numbers is exhausted 427 function extractNumber() { 428 $y = $this->MT[$this->i]; 429 $y = $this->mysql_math("$y ^ ($y >>11) ^ (($y << 7) & 2636928640) ^ (($y << 15) & 4022730752) ^ ($y >>18)"); 430 $this->i++; 431 return $y/0xffffffff; 432 } 433 434 function rand($low,$high){ 435 $pick=floor($low+($high-$low+1)*$this->extractNumber()); 436 return ($pick); 437 } 438 function array_rand($array){ 439 return($this->rand(0,count($array)-1)); 401 //MySQL version doesn't work since they shut down integer overflow switching to: 402 //https://github.com/ruafozy/php-mersenne-twister/blob/master/src/mersenne_twister.php 403 404 function identicon_mersenne_twister($seed=123456) { 405 $this->bits32 = PHP_INT_MAX == 2147483647; 406 $this->define_constants(); 407 $this->init_with_integer($seed); 408 } 409 410 function define_constants() { 411 $this->N = 624; 412 $this->M = 397; 413 $this->MATRIX_A = 0x9908b0df; 414 $this->UPPER_MASK = 0x80000000; 415 $this->LOWER_MASK = 0x7fffffff; 416 417 $this->MASK10=~((~0) << 10); 418 $this->MASK11=~((~0) << 11); 419 $this->MASK12=~((~0) << 12); 420 $this->MASK14=~((~0) << 14); 421 $this->MASK20=~((~0) << 20); 422 $this->MASK21=~((~0) << 21); 423 $this->MASK22=~((~0) << 22); 424 $this->MASK26=~((~0) << 26); 425 $this->MASK27=~((~0) << 27); 426 $this->MASK31=~((~0) << 31); 427 428 $this->TWO_TO_THE_16=pow(2,16); 429 $this->TWO_TO_THE_31=pow(2,31); 430 $this->TWO_TO_THE_32=pow(2,32); 431 432 $this->MASK32 = $this->MASK31 | ($this->MASK31 << 1); 433 } 434 435 function init_with_integer($integer_seed) { 436 $integer_seed = $this->force_32_bit_int($integer_seed); 437 438 $mt = &$this->mt; 439 $mti = &$this->mti; 440 441 $mt = array_fill(0, $this->N, 0); 442 443 $mt[0] = $integer_seed; 444 445 for($mti = 1; $mti < $this->N; $mti++) { 446 $mt[$mti] = $this->add_2($this->mul(1812433253, 447 ($mt[$mti - 1] ^ (($mt[$mti - 1] >> 30) & 3))), $mti); 448 /* 449 mt[mti] = 450 (1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti); 451 */ 452 } 453 } 454 455 /* generates a random number on [0,1)-real-interval */ 456 function real_halfopen() { 457 return 458 $this->signed2unsigned($this->int32()) * (1.0 / 4294967296.0); 459 } 460 function int32() { 461 $mag01 = array(0, $this->MATRIX_A); 462 463 $mt = &$this->mt; 464 $mti = &$this->mti; 465 466 if ($mti >= $this->N) { /* generate N words all at once */ 467 for ($kk=0;$kk<$this->N-$this->M;$kk++) { 468 $y = ($mt[$kk]&$this->UPPER_MASK)|($mt[$kk+1]&$this->LOWER_MASK); 469 $mt[$kk] = $mt[$kk+$this->M] ^ (($y >> 1) & $this->MASK31) ^ $mag01[$y & 1]; 470 } 471 for (;$kk<$this->N-1;$kk++) { 472 $y = ($mt[$kk]&$this->UPPER_MASK)|($mt[$kk+1]&$this->LOWER_MASK); 473 $mt[$kk] = 474 $mt[$kk+($this->M-$this->N)] ^ (($y >> 1) & $this->MASK31) ^ $mag01[$y & 1]; 475 } 476 $y = ($mt[$this->N-1]&$this->UPPER_MASK)|($mt[0]&$this->LOWER_MASK); 477 $mt[$this->N-1] = $mt[$this->M-1] ^ (($y >> 1) & $this->MASK31) ^ $mag01[$y & 1]; 478 479 $mti = 0; 480 } 481 482 $y = $mt[$mti++]; 483 484 /* Tempering */ 485 $y ^= ($y >> 11) & $this->MASK21; 486 $y ^= ($y << 7) & ((0x9d2c << 16) | 0x5680); 487 $y ^= ($y << 15) & (0xefc6 << 16); 488 $y ^= ($y >> 18) & $this->MASK14; 489 490 return $y; 491 } 492 493 function signed2unsigned($signed_integer) { 494 ## assert(is_integer($signed_integer)); 495 ## assert(($signed_integer & ~$this->MASK32) === 0); 496 497 return $signed_integer >= 0? $signed_integer: 498 $this->TWO_TO_THE_32 + $signed_integer; 499 } 500 501 function unsigned2signed($unsigned_integer) { 502 ## assert($unsigned_integer >= 0); 503 ## assert($unsigned_integer < pow(2, 32)); 504 ## assert(floor($unsigned_integer) === floatval($unsigned_integer)); 505 506 return intval($unsigned_integer < $this->TWO_TO_THE_31? $unsigned_integer: 507 $unsigned_integer - $this->TWO_TO_THE_32); 508 } 509 510 function force_32_bit_int($x) { 511 /* 512 it would be un-PHP-like to require is_integer($x), 513 so we have to handle cases like this: 514 515 $x === pow(2, 31) 516 $x === strval(pow(2, 31)) 517 518 we are also opting to do something sensible (rather than dying) 519 if the seed is outside the range of a 32-bit unsigned integer. 520 */ 521 522 if(is_integer($x)) { 523 /* 524 we mask in case we are on a 64-bit machine and at least one 525 bit is set between position 32 and position 63. 526 */ 527 return $x & $this->MASK32; 528 } else { 529 $x = floatval($x); 530 531 $x = $x < 0? ceil($x): floor($x); 532 533 $x = fmod($x, $this->TWO_TO_THE_32); 534 535 if($x < 0) 536 $x += $this->TWO_TO_THE_32; 537 538 return $this->unsigned2signed($x); 539 } 540 } 541 542 /* 543 takes 2 integers, treats them as unsigned 32-bit integers, 544 and adds them. 545 546 it works by splitting each integer into 547 2 "half-integers", then adding the high and low half-integers 548 separately. 549 550 a slight complication is that the sum of the low half-integers 551 may not fit into 16 bits; any "overspill" is added to the sum 552 of the high half-integers. 553 */ 554 function add_2($n1, $n2) { 555 $x = ($n1 & 0xffff) + ($n2 & 0xffff); 556 557 return 558 (((($n1 >> 16) & 0xffff) + 559 (($n2 >> 16) & 0xffff) + 560 ($x >> 16)) << 16) | ($x & 0xffff); 561 } 562 563 function mul($a, $b) { 564 /* 565 a and b, considered as unsigned integers, can be expressed as follows: 566 567 a = 2**16 * a1 + a2, 568 569 b = 2**16 * b1 + b2, 570 571 where 572 573 0 <= a2 < 2**16, 574 0 <= b2 < 2**16. 575 576 given those 2 equations, what this function essentially does is to 577 use the following identity: 578 579 a * b = 2**32 * a1 * b1 + 2**16 * a1 * b2 + 2**16 * b1 * a2 + a2 * b2 580 581 note that the first term, i.e. 2**32 * a1 * b1, is unnecessary here, 582 so we don't compute it. 583 584 we could make the following code clearer by using intermediate 585 variables, but that would probably hurt performance. 586 */ 587 588 return 589 $this->unsigned2signed( 590 fmod( 591 $this->TWO_TO_THE_16 * 592 /* 593 the next line of code calculates a1 * b2, 594 the line after that calculates b1 * a2, 595 and the line after that calculates a2 * b2. 596 */ 597 ((($a >> 16) & 0xffff) * ($b & 0xffff) + 598 (($b >> 16) & 0xffff) * ($a & 0xffff)) + 599 ($a & 0xffff) * ($b & 0xffff), 600 601 $this->TWO_TO_THE_32)); 602 } 603 604 function rand($low,$high){ 605 $pick=floor($low+($high-$low+1)*$this->real_halfopen()); 606 return ($pick); 607 } 608 609 function array_rand($array){ 610 return($this->rand(0,count($array)-1)); 440 611 } 441 612 } … … 510 681 extract($args, EXTR_SKIP); 511 682 $options = get_option('widget_identicon_recent_comments'); 512 $title = empty($options['title']) ? __('Recent Comments' ) : $options['title'];683 $title = empty($options['title']) ? __('Recent Comments', 'wp-identicon') : $options['title']; 513 684 if ( !$number = (int) $options['number'] ) 514 685 $number = 5; … … 536 707 if($comment->comment_type!="pingback"&&$comment->comment_type!="trackback"&&isset($identicon)) 537 708 echo $identicon->identicon_build($comment->comment_author_email,$comment->comment_author,TRUE,'',TRUE,TRUE,$size).' '; 538 echo sprintf(__('%1$s on %2$s' ), get_comment_author_link(), '<a href="'. get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>';709 echo sprintf(__('%1$s on %2$s', 'wp-identicon'), get_comment_author_link(), '<a href="'. get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>'; 539 710 endforeach; endif;?></ul> 540 711 <?php echo $after_widget; ?> … … 564 735 $size = 10; 565 736 ?> 566 <p><label for="identicon_recent-comments-title"><?php _e('Title:' ); ?> <input style="width: 250px;" id="identicon_recent-comments-title" name="identicon_recent-comments-title" type="text" value="<?php echo $title; ?>" /></label></p>567 <p><label for="identicon_recent-comments-number"><?php _e('Number of comments to show:' ); ?> <input style="width: 25px; text-align: center;" id="identicon_recent-comments-number" name="identicon_recent-comments-number" type="text" value="<?php echo $number; ?>" /></label> <?php _e('(at most 15)'); ?></p>568 <p><label for="identicon_size"><?php _e('Size of Widget Identicons (pixels):' ); ?> <input style="width: 25px; text-align: center;" id="identicon_size" name="identicon_size" type="text" value="<?php echo $size; ?>" /></label></p>737 <p><label for="identicon_recent-comments-title"><?php _e('Title:', 'wp-identicon'); ?> <input style="width: 250px;" id="identicon_recent-comments-title" name="identicon_recent-comments-title" type="text" value="<?php echo $title; ?>" /></label></p> 738 <p><label for="identicon_recent-comments-number"><?php _e('Number of comments to show:', 'wp-identicon'); ?> <input style="width: 25px; text-align: center;" id="identicon_recent-comments-number" name="identicon_recent-comments-number" type="text" value="<?php echo $number; ?>" /></label> <?php _e('(at most 15)', 'wp-identicon'); ?></p> 739 <p><label for="identicon_size"><?php _e('Size of Widget Identicons (pixels):', 'wp-identicon'); ?> <input style="width: 25px; text-align: center;" id="identicon_size" name="identicon_size" type="text" value="<?php echo $size; ?>" /></label></p> 569 740 <input type="hidden" id="identicon_recent-comments-submit" name="identicon_recent-comments-submit" value="1" /> 570 741 <?php … … 591 762 } 592 763 764 593 765 add_action('widgets_init', 'identicon_recent_comments_widget_init'); 594 766 ?>
Note: See TracChangeset
for help on using the changeset viewer.