$size = intval($_REQUEST['s']); if ($size < DW_IDENTICON_MIN_SIZE || $size > DW_IDENTICON_MAX_SIZE) { $size = 80; } //gravatar redirect $gravatar = strtolower($_REQUEST['gr']); $gravatar = $gravatar == 'true' || ($gravatar = 1); //get static $avatarList = glob(WP_IDENTICON_ROOT_PATH . DIRECTORY_SEPARATOR . DW_IDENTICON_STATIC_DIR . DIRECTORY_SEPARATOR . $seed . '.*', GLOB_NOSORT); $avatar = $avatarList[0]; if (!$avatar) { //generate avatar include 'wp_identicon.php'; $idc = new identicon(); //function identicon_build($seed='',$altImgText='',$img=true,$outsize='',$write=true,$random=true,$displaysize='',$gravataron=true) $avatar = $idc->identicon_build($seed, '', false, $size, true, true, $size, $gravatar); } //output image $filename = basename($avatar); $file_extension = strtolower(substr(strrchr($filename, "."), 1)); $contentType = 'application/octet-stream'; switch ($file_extension) { case "gif": $contentType = "image/gif"; break; case "png": $contentType = "image/png"; break; case "jpeg": case "jpg": $contentType = "image/jpeg";
function do_identicon($formatter = null, $params) { //create identicon for later use static $identicon = null; if (!$identicon) { $identicon = new identicon(); } if (!empty($params['seed'])) { $seed = $params['seed']; } else { $seed = md5($_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT']); } $img = true; $outsize = ''; $random = true; $displaysize = ''; return $identicon->identicon_build($seed, $img, $outsize, $random, $displaysize); }
function identicon_subpanel() { echo "<div class='wrap'>"; if (isset($_POST['submit'])) { //update the identicon size option $identicon_options = identicon_get_options(); $identiconsize = intval($_POST['identiconsize']); $identiconsquares = intval($_POST['identiconsquares']); if ($identiconsize > 0 & $identiconsize < 400) { $identicon_options['size'] = $identiconsize; } else { echo '<div class="error"><p>' . __('Please enter an integer for size. Preferably between 30-200.', 'wp-identicon') . '</p></div>'; } if ($identiconsquares > 0) { $identicon_options['squares'] = $identiconsquares; } else { 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>'; } foreach (array('backr', 'backg', 'backb', 'forer', 'foreg', 'foreb') as $color) { //update background color options $colorarray = explode('-', $_POST[$color]); if (count($colorarray) == 1) { $colorarray[1] = $colorarray[0]; } $colorarray[0] = intval($colorarray[0]); $colorarray[1] = intval($colorarray[1]); if ($colorarray[0] >= 0 & $colorarray[0] < 256 & $colorarray[1] >= 0 & $colorarray[1] < 256) { $identicon_options[$color] = $colorarray; } else { 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>'; } } if ($_POST['autoadd'] == 0) { $identicon_options['autoadd'] = 0; } elseif ($_POST['autoadd'] == 1) { $identicon_options['autoadd'] = 1; } elseif ($_POST['autoadd'] == 2) { $identicon_options['autoadd'] = 2; } if ($_POST['gravatar'] == 0) { $identicon_options['gravatar'] = 0; } elseif ($_POST['gravatar'] == 1) { $identicon_options['gravatar'] = 1; } if ($_POST['grey'] == 1) { $identicon_options['grey'] = 1; } else { $identicon_options['grey'] = 0; } update_option('identicon', $identicon_options); echo '<div class="updated"><p>' . __('Options updated (you may have to clear the identicon cache to see any effect).', 'wp-identicon') . '</p></div>'; } elseif (isset($_POST['clear'])) { //clear the identicon cache $dir = WP_IDENTICON_DIR_INTERNAL; if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if (is_file($dir . $file) and preg_match('/^.*\\.png$/', $file)) { unlink($dir . $file); } } closedir($dh); echo '<div class="updated"><p>' . __('Cache cleared.', 'wp-identicon') . '</p></div>'; } } $identicon_options = identicon_get_options(); //count file $identicon_count = 0; $dir = WP_IDENTICON_DIR_INTERNAL; if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if (is_file($dir . $file) and preg_match('/^[a-f0-9]*\\.png$/', $file)) { $identicon_count++; } } } ?> <div class="wrap"> <h2><?php _e('Identicon Options.', 'wp-identicon'); ?> </h2> <p><?php _e('You currently have', 'wp-identicon'); ?> <?php echo $identicon_count; ?> <?php _e('identicons on your website', 'wp-identicon'); ?> .</p> <p><?php _e('Set options here:', 'wp-identicon'); ?> </p> <form method="post" action="options-general.php?page=wp-identicon.php"> <ul style="list-style-type: none"> <li><strong><?php _e('Identicon Size (in pixels)', 'wp-identicon'); ?> </strong>:<br /> <input type="text" name="identiconsize" size="5" value="<?php echo $identicon_options['size']; ?> "/> <small><?php _e('(Default: 35)', 'wp-identicon'); ?> </small></li> <li><strong><?php _e('Number of Squares', 'wp-identicon'); ?> </strong>:<br /> <input type="text" name="identiconsquares" size="5" value="<?php echo $identicon_options['squares']; ?> "/> <small><?php _e('(Default: 4)', 'wp-identicon'); ?> </small><br/><br/></li> <?php if (!$identicon_options['grey']) { $gbtype = "text"; $input_back = array('r' => 'style="background:#fee;"', 'g' => 'style="background:#efe;"', 'b' => 'style="background:#eef;"'); $input_detail = array('r' => 'R:', 'g' => 'G:', 'b' => 'B:'); } else { $gbtype = "hidden"; $input_back = array('r' => '', 'g' => '', 'b' => ''); $input_detail = array('r' => 'Gray:', 'g' => '', 'b' => ''); } ?> <li><strong><?php _e('Background Colors', 'wp-identicon'); ?> </strong>:<br /> <small><?php _e('(enter single value or range. 0,0,0 for transparent. Default: 255,255,255)', 'wp-identicon'); ?> </small><br/> <?php echo $input_detail['r']; ?> <input type="text" name="backr" size="10" <?php echo $input_back['r']; ?> value="<?php echo implode($identicon_options['backr'], '-'); ?> "/> <?php echo $input_detail['g']; ?> <input type="<?php echo $gbtype; ?> " name="backg" size="10" <?php echo $input_back['g']; ?> value="<?php echo implode($identicon_options['backg'], '-'); ?> "/> <?php echo $input_detail['b']; ?> <input type="<?php echo $gbtype; ?> " name="backb" size="10" <?php echo $input_back['b']; ?> value="<?php echo implode($identicon_options['backb'], '-'); ?> "/><br/><br/></li> <li><strong><?php _e('Foreground Colors', 'wp-identicon'); ?> :</strong><br/> <small><?php _e('(enter single value or range. Default: 1-255,1-255,1-255)', 'wp-identicon'); ?> </small><br/> <?php echo $input_detail['r']; ?> <input type="text" name="forer" size="10" <?php echo $input_back['r']; ?> value="<?php echo implode($identicon_options['forer'], '-'); ?> "/> <?php echo $input_detail['g']; ?> <input type="<?php echo $gbtype; ?> " name="foreg" size="10" <?php echo $input_back['g']; ?> value="<?php echo implode($identicon_options['foreg'], '-'); ?> "/> <?php echo $input_detail['b']; ?> <input type="<?php echo $gbtype; ?> " name="foreb" size="10" <?php echo $input_back['b']; ?> value="<?php echo implode($identicon_options['foreb'], '-'); ?> "/><br/><br/></li> <li><strong><?php _e('Grayscale', 'wp-identicon'); ?> :</strong> <input type="checkbox" name="grey" value="1" <?php if ($identicon_options['grey']) { echo 'checked="checked"'; } ?> /> <small><?php _e('(Good for black and white themes)', 'wp-identicon'); ?> </small><br/><br/></li> <li><strong><?php _e('Automatically Add Identicons to Comments', 'wp-identicon'); ?> </strong><br/> <small><?php _e('(adds an Identicon beside commenter names or disable it and edit theme file manually). Default: Auto)', 'wp-identicon'); ?> </small><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 WordPress 2.5+ Avatars', 'wp-identicon'); ?> </li> <li><strong><?php _e('Gravatar Support', 'wp-identicon'); ?> :</strong><br /> <small><?php _e('(If a commenter has a gravatar use it, otherwise use Identicon. Default: Identicon Only)', 'wp-identicon'); ?> </small><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> <li><input type="submit" name="submit" value="<?php _e('Set Options', 'wp-identicon'); ?> "/></li> </ul> </form> <h4><?php _e('Clear the Identicon Image Cache', 'wp-identicon'); ?> :</h4> <form method="post" action="options-general.php?page=wp-identicon.php"> <input type="submit" name="clear" value="<?php _e('Clear Cache', 'wp-identicon'); ?> "/></form> <h4><?php _e('To use Identicon', 'wp-identicon'); ?> :</h4> <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> <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> <strong><?php _e('Testing:', 'wp-identicon'); ?> </strong><br/> <?php if (!is_writable('' . WP_IDENTICON_DIR_INTERNAL)) { echo '<div class="error"><p>' . __('Identicon needs ', 'wp-identicon') . WP_IDENTICON_DIR_INTERNAL . __(' to be writable.', 'wp-identicon') . '</p></div>'; } if (!function_exists("gd_info")) { echo '<div class="error"><p>' . __('GD Image library not found. Identicon needs this library.', 'wp-identicon') . '</p></div>'; } ?> <p><?php _e('A test identicon should be here', 'wp-identicon'); ?> :<br/><br/><?php $identicon = new identicon(); echo $identicon->identicon_build('This is a test', 'Test'); ?> <br/><br/><?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> <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> <p><?php _e("For curiosity's sake, here are the parts the identicons are built from", 'wp-identicon'); ?> :</p> <?php echo $identicon->identicon_display_parts(); ?> <h4><?php _e('For advanced users:', 'wp-identicon'); ?> </h4> <p><?php _e('Disable the automatic Indenticon placement and put', 'wp-identicon'); ?> : <br/> <code><?php echo htmlspecialchars('<?php if (function_exists("identicon_build")) {echo identicon_build($comment->comment_author_email,$comment->comment_author); } ?>'); ?> </code><br/> <?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'); ?> : <code><?php echo htmlspecialchars('<?php if (function_exists("identicon_build")) {echo identicon_build($comment->comment_author_email,$comment->comment_author,false); } ?>'); ?> </code></p> <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> <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> </div> <?php }