consistent plugin usage - gravatar
this and followup commits touches: use load_languiage API class method parenthesis "\n{\n <code>\n}\n", case break switches, consistent boolean usage, append css to eventData and other cleanups
This commit is contained in:
parent
34cefef45f
commit
adfb3bc537
@ -2,7 +2,7 @@
|
||||
|
||||
function build_monster($filename, $seed='',$size=''){
|
||||
// init random seed
|
||||
if($seed) srand( hexdec(substr(md5($seed),0,6)) );
|
||||
if ($seed) srand( hexdec(substr(md5($seed),0,6)) );
|
||||
|
||||
// throw the dice for body parts
|
||||
$parts = array(
|
||||
@ -31,17 +31,17 @@ function build_monster($filename, $seed='',$size=''){
|
||||
imagedestroy($im);
|
||||
|
||||
// color the body
|
||||
if($part == 'body'){
|
||||
if ($part == 'body') {
|
||||
$color = imagecolorallocate($monster, rand(20,235), rand(20,235), rand(20,235));
|
||||
imagefill($monster,60,60,$color);
|
||||
}
|
||||
}
|
||||
|
||||
// restore random seed
|
||||
if($seed) srand();
|
||||
if ($seed) srand();
|
||||
|
||||
// resize if needed, then output
|
||||
if($size && $size < 400){
|
||||
if ($size && $size < 400) {
|
||||
$out = @imagecreatetruecolor($size,$size);
|
||||
if (!$out) return false; // Problems creating image!
|
||||
imagecopyresampled($out,$monster,0,0,0,0,$size,$size,120,120);
|
||||
@ -49,10 +49,12 @@ function build_monster($filename, $seed='',$size=''){
|
||||
imagedestroy($out);
|
||||
imagedestroy($monster);
|
||||
return true;
|
||||
}else{
|
||||
} else {
|
||||
//header ("Content-type: image/png");
|
||||
imagepng($monster,$filename);
|
||||
imagedestroy($monster);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -1,20 +1,14 @@
|
||||
<?php #
|
||||
|
||||
<?php
|
||||
|
||||
if (IN_serendipity !== true) {
|
||||
die ("Don't hack!");
|
||||
}
|
||||
|
||||
// Probe for a language include with constants. Still include defines later on, if some constants were missing
|
||||
$probelang = dirname(__FILE__) . '/' . $serendipity['charset'] . 'lang_' . $serendipity['lang'] . '.inc.php';
|
||||
if (file_exists($probelang)) {
|
||||
include $probelang;
|
||||
}
|
||||
|
||||
include dirname(__FILE__) . '/lang_en.inc.php';
|
||||
// Load possible language files.
|
||||
@serendipity_plugin_api::load_language(dirname(__FILE__));
|
||||
|
||||
// Actual version of this plugin
|
||||
@define('PLUGIN_EVENT_GRAVATAR_VERSION', '1.59'); // NOTE: This plugin is also in the central repository. Commit changes to the core, too :)
|
||||
@define('PLUGIN_EVENT_GRAVATAR_VERSION', '1.60'); // NOTE: This plugin is also in the central repository. Commit changes to the core, too :)
|
||||
|
||||
// Defines the maximum available method slots in the configuration.
|
||||
@define('PLUGIN_EVENT_GRAVATAR_METHOD_MAX', 6);
|
||||
@ -43,25 +37,24 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
$propbag->add('stackable', false);
|
||||
$propbag->add('author', 'Garvin Hicking, Grischa Brockhaus');
|
||||
$propbag->add('requirements', array(
|
||||
'serendipity' => '0.7',
|
||||
'serendipity' => '1.6',
|
||||
'smarty' => '2.6.7',
|
||||
'php' => '4.1.0'
|
||||
));
|
||||
$propbag->add('version', PLUGIN_EVENT_GRAVATAR_VERSION);
|
||||
$propbag->add('groups', array('IMAGES'));
|
||||
$propbag->add('event_hooks', array(
|
||||
$propbag->add('groups', array('IMAGES'));
|
||||
$propbag->add('event_hooks', array(
|
||||
'frontend_display' => true,
|
||||
'frontend_comment' => true,
|
||||
'external_plugin' => true,
|
||||
'css' => true,
|
||||
));
|
||||
$configuration = array('longdescription','seperator');
|
||||
$config_methods = array();
|
||||
$configuration = array('longdescription', 'separator');
|
||||
$config_methods = array();
|
||||
for ($idx=1; $idx<=PLUGIN_EVENT_GRAVATAR_METHOD_MAX; $idx++) {
|
||||
$config_methods[] = "method_$idx";
|
||||
}
|
||||
|
||||
|
||||
$propbag->add('configuration',
|
||||
array_merge($configuration, $config_methods,
|
||||
array('defaultavatar', 'recent_entries', 'infoline',
|
||||
@ -71,7 +64,6 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function introspect_config_item($name, &$propbag)
|
||||
{
|
||||
global $serendipity;
|
||||
@ -111,6 +103,7 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
);
|
||||
|
||||
switch($name) {
|
||||
|
||||
case 'smartyimage':
|
||||
$propbag->add('type', 'boolean');
|
||||
$propbag->add('name', PLUGIN_EVENT_GRAVATAR_USE_SMARTY);
|
||||
@ -136,13 +129,16 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
$propbag->add('type', 'content');
|
||||
$propbag->add('default', PLUGIN_EVENT_GRAVATAR_EXTLING_WARNING);
|
||||
break;
|
||||
|
||||
case 'longdescription':
|
||||
$propbag->add('type', 'content');
|
||||
$propbag->add('default', PLUGIN_EVENT_GRAVATAR_LONG_DESCRIPTION);
|
||||
break;
|
||||
case 'seperator':
|
||||
$propbag->add('type', 'seperator');
|
||||
|
||||
case 'separator':
|
||||
$propbag->add('type', 'separator');
|
||||
break;
|
||||
|
||||
case 'gravatar_fallback':
|
||||
$propbag->add('type', 'select');
|
||||
$propbag->add('name', PLUGIN_EVENT_GRAVATAR_FALLBACK);
|
||||
@ -150,6 +146,7 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
$propbag->add('select_values', $gravatar_fallbacks);
|
||||
$propbag->add('default', 'none');
|
||||
break;
|
||||
|
||||
case 'gravatar_fallback_use_always':
|
||||
$propbag->add('type', 'boolean');
|
||||
$propbag->add('name', PLUGIN_EVENT_GRAVATAR_FALLBACK_ALLWAYS);
|
||||
@ -158,11 +155,7 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
break;
|
||||
|
||||
case 'defaultavatar':
|
||||
if (version_compare('1.2',$serendipity['version'])==1) {// 1 if 1.2 higher than actual version number
|
||||
$propbag->add('type', 'string');
|
||||
} else {
|
||||
$propbag->add('type', 'media');
|
||||
}
|
||||
$propbag->add('type', 'string');
|
||||
$propbag->add('name', PLUGIN_EVENT_GRAVATAR_DEFAULTAVATAR);
|
||||
$propbag->add('description', PLUGIN_EVENT_GRAVATAR_DEFAULTAVATAR_DESC);
|
||||
$propbag->add('default', '');
|
||||
@ -193,7 +186,7 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
$propbag->add('type', 'radio');
|
||||
$propbag->add('name', PLUGIN_EVENT_GRAVATAR_RATING);
|
||||
$propbag->add('description', PLUGIN_EVENT_GRAVATAR_RATING_DESC);
|
||||
$propbag->add('radio', array(
|
||||
$propbag->add('radio', array(
|
||||
'value' => array('-', 'G', 'PG', 'R', 'X'),
|
||||
'desc' => array(PLUGIN_EVENT_GRAVATAR_RATING_NO,PLUGIN_EVENT_GRAVATAR_RATING_G, PLUGIN_EVENT_GRAVATAR_RATING_PG, PLUGIN_EVENT_GRAVATAR_RATING_R, PLUGIN_EVENT_GRAVATAR_RATING_X)
|
||||
));
|
||||
@ -222,19 +215,22 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
$propbag->add('default', false);
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function generate_content(&$title) {
|
||||
function generate_content(&$title)
|
||||
{
|
||||
$title = PLUGIN_EVENT_GRAVATAR_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Will be called while saving settings
|
||||
*/
|
||||
function cleanup() {
|
||||
function cleanup()
|
||||
{
|
||||
// *Always* clean up the cache after changing configuration, else
|
||||
// the configuration change will first be seen after cache time is run out.
|
||||
$this->log("-------");
|
||||
@ -305,8 +301,6 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
|
||||
// Print out image html for the user avatar into the frontend_display
|
||||
@ -316,35 +310,39 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
}
|
||||
|
||||
$this->printAvatarHtml($eventData, $addData);
|
||||
|
||||
return true;
|
||||
break;
|
||||
|
||||
case 'css':
|
||||
// avatar css has to be emitted no matter of smarty enabled: the sidebar needs it.
|
||||
//$useSmarty = serendipity_db_bool($this->get_config('smartyimage', false));
|
||||
//if (!$useSmarty && !(strpos($eventData, '.avatar_left') || strpos($eventData, '.avatar_rigth'))) {
|
||||
if (!(strpos($eventData, '.avatar_left') || strpos($eventData, '.avatar_rigth'))) {
|
||||
?>
|
||||
// CSS class does NOT exist by user customized template styles, include default
|
||||
if (false === (strpos($eventData, '.avatar_left') || strpos($eventData, '.avatar_rigth'))) {
|
||||
$eventData .= '
|
||||
|
||||
/* serendipity_event_gravatar start */
|
||||
|
||||
.avatar_left {
|
||||
float:left;
|
||||
margin-left:0px;
|
||||
margin-right:10px;
|
||||
float:left;
|
||||
margin-left:0px;
|
||||
margin-right:10px;
|
||||
}
|
||||
.avatar_right {
|
||||
float:right;
|
||||
margin-right:0px;
|
||||
margin-left:10px;
|
||||
float:right;
|
||||
margin-right:0px;
|
||||
margin-left:10px;
|
||||
}
|
||||
<?php
|
||||
|
||||
/* serendipity_event_gravatar end */
|
||||
|
||||
';
|
||||
|
||||
}
|
||||
return true;
|
||||
break;
|
||||
break;
|
||||
|
||||
// Adds information about the actual supported avatar types below the comment input
|
||||
case 'frontend_comment':
|
||||
|
||||
// Suppress infoline about configured avatar types if configured like that:
|
||||
if (!serendipity_db_bool($this->get_config('infoline', true))){
|
||||
if (!serendipity_db_bool($this->get_config('infoline', 'true'))){
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -378,7 +376,7 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
$supported_methods .= (empty($supported_methods) ? '' : ', ') . '<a href="http://www.splitbrain.org/go/monsterid">Monster ID</a>';
|
||||
break;
|
||||
case 'identicon':
|
||||
$supported_methods .= (empty($supported_methods) ? '' : ', ') . '<a href="http://scott.sherrillmix.com/blog/blogger/wp_identicon/">Identicon/Ycon</a>';
|
||||
$supported_methods .= (empty($supported_methods) ? '' : ', ') . '<a href="http://scott.sherrillmix.com/blog/blogger/wp_identicon/">Identicon/Ycon</a>';
|
||||
break;
|
||||
case 'wavatars':
|
||||
$supported_methods .= (empty($supported_methods) ? '' : ', ') . '<a href="http://www.shamusyoung.com/twentysidedtale/?p=1462">Wavatars</a>';
|
||||
@ -386,12 +384,13 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
}
|
||||
}
|
||||
echo '<div class="serendipity_commentDirection serendipity_comment_gravatar">' . sprintf(PLUGIN_EVENT_GRAVATAR_SUPPORTED, $supported_methods) . '</div>';
|
||||
return true;
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@ -401,16 +400,16 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
* Returns HTML displaying the user avatar. This is done without any call to external servers.
|
||||
* If a cached avatar is found, the image will have it as SRC, else the SRC will be filled with
|
||||
* an external_plugin call, that will try to fetch a fresh avatar later.
|
||||
*
|
||||
*/
|
||||
function printAvatarHtml(&$eventData, &$addData){
|
||||
function printAvatarHtml(&$eventData, &$addData)
|
||||
{
|
||||
global $serendipity;
|
||||
|
||||
$useSmarty = serendipity_db_bool($this->get_config('smartyimage', false));
|
||||
$useSmarty = serendipity_db_bool($this->get_config('smartyimage', 'false'));
|
||||
|
||||
// comments sidebar plugin doesn't support smarty, so switch it off, if detected
|
||||
if ($addData['from'] == 'serendipity_plugin_comments:generate_content') {
|
||||
if (!serendipity_db_bool($this->get_config('recent_entries', true))) {
|
||||
if (!serendipity_db_bool($this->get_config('recent_entries', 'true'))) {
|
||||
return false;
|
||||
}
|
||||
$useSmarty = false;
|
||||
@ -428,12 +427,12 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
|
||||
$url = '';
|
||||
if (!empty($eventData['url'])) {
|
||||
$url = $eventData['url'];
|
||||
$url = $eventData['url'];
|
||||
}
|
||||
|
||||
if (!empty($eventData['url'])) { // Strip Query paras
|
||||
$urlparts = explode('?', $eventData['url']);
|
||||
$url = $urlparts[0];
|
||||
if (!empty($eventData['url'])) { // Strip Query params
|
||||
$urlparts = explode('?', $eventData['url']);
|
||||
$url = $urlparts[0];
|
||||
}
|
||||
$title = '';
|
||||
$author = 'unknown';
|
||||
@ -443,10 +442,10 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
}
|
||||
|
||||
if (isset($eventData['email']) && !empty($eventData['email'])) {
|
||||
$email_md5 = md5(strtolower($eventData['email']));
|
||||
$email_md5 = md5(strtolower($eventData['email']));
|
||||
}
|
||||
else {
|
||||
$email_md5 = '';
|
||||
$email_md5 = '';
|
||||
}
|
||||
if ($this->cache_seconds > 0) {
|
||||
$cache_file = $this->getCacheFilePath($eventData);
|
||||
@ -488,7 +487,8 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
* Generates a CSS class for the avatar depending where it is displayed.
|
||||
* Defaults to comment_avatar in comments and is unique for plugins.
|
||||
*/
|
||||
function generateAvatarCssClass($addData){
|
||||
function generateAvatarCssClass($addData)
|
||||
{
|
||||
if (empty($addData)) {
|
||||
return "avatar";
|
||||
}
|
||||
@ -501,7 +501,8 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
/**
|
||||
* Tests wether the default avatar is supported
|
||||
*/
|
||||
function supportDefaultAvatar(){
|
||||
function supportDefaultAvatar()
|
||||
{
|
||||
|
||||
// Check if a default avatar is defined
|
||||
$default = $this->getDefaultImageConfiguration();
|
||||
@ -530,7 +531,8 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
* Will try to fetch a fresh avatar image by user configuration. If retreiving was successfull,
|
||||
* the image will cached and displayed as binary image response.
|
||||
*/
|
||||
function fetchAvatar(&$eventData) {
|
||||
function fetchAvatar(&$eventData)
|
||||
{
|
||||
global $serendipity;
|
||||
|
||||
$methodnr = 1;
|
||||
@ -616,7 +618,8 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
*
|
||||
* @return boolean true, if Avatar was found and added to the comment buffer
|
||||
*/
|
||||
function fetchGravatar(&$eventData){
|
||||
function fetchGravatar(&$eventData)
|
||||
{
|
||||
global $serendipity;
|
||||
|
||||
$this->log("Gravatar: url=" . $eventData['url'] . " email_md5=" . $eventData['email_md5'] . " author=" .$eventData['author']) ;
|
||||
@ -625,28 +628,28 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
return false;
|
||||
}
|
||||
if (empty($eventData['email_md5'])) {
|
||||
if (!serendipity_db_bool($this->get_config('gravatar_fallback_use_always', false)) || (empty($eventData['url']) && empty($eventData['author']))) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
if (empty($eventData['url'])) $email_md5 = md5($eventData['author']);
|
||||
else $email_md5 = md5($eventData['url']);
|
||||
}
|
||||
if (!serendipity_db_bool($this->get_config('gravatar_fallback_use_always', 'false')) || (empty($eventData['url']) && empty($eventData['author']))) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
if (empty($eventData['url'])) $email_md5 = md5($eventData['author']);
|
||||
else $email_md5 = md5($eventData['url']);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$email_md5 = $eventData['email_md5'];
|
||||
$email_md5 = $eventData['email_md5'];
|
||||
}
|
||||
$default = $this->getDefaultImageConfiguration();
|
||||
|
||||
$gravatar_fallback = $this->get_config("gravatar_fallback");
|
||||
$fallback = "";
|
||||
if ($gravatar_fallback != 'none') {
|
||||
$fallback = '&d=' . $gravatar_fallback;
|
||||
$fallback = '&d=' . $gravatar_fallback;
|
||||
}
|
||||
else {
|
||||
//$defaultavatar = urlencode((empty($default['defaultavatar'])? $serendipity['baseURL'] . 'dummy.gif': 'http://' . $_SERVER['SERVER_NAME'] . $default['defaultavatar']));
|
||||
$defaultavatar = urlencode($serendipity['serendipityHTTPPath'] . 'dummy456.gif123'); // Add a not existing image to produce an error we can check
|
||||
$fallback = '&d=' . $defaultavatar;
|
||||
//$defaultavatar = urlencode((empty($default['defaultavatar'])? $serendipity['baseURL'] . 'dummy.gif': 'http://' . $_SERVER['SERVER_NAME'] . $default['defaultavatar']));
|
||||
$defaultavatar = urlencode($serendipity['serendipityHTTPPath'] . 'dummy456.gif123'); // Add a not existing image to produce an error we can check
|
||||
$fallback = '&d=' . $defaultavatar;
|
||||
}
|
||||
|
||||
$urltpl = 'http://www.gravatar.com/avatar.php?'
|
||||
@ -660,6 +663,7 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
|
||||
$success = $this->saveAndResponseAvatar($eventData, $urltpl, 1);
|
||||
$this->avatarConfiguration['gravatar_found'] = $success;
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
@ -672,7 +676,8 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
*
|
||||
* @return boolean true, if Avatar was found and added to the comment buffer
|
||||
*/
|
||||
function fetchMyBlogLog(&$eventData){
|
||||
function fetchMyBlogLog(&$eventData)
|
||||
{
|
||||
require_once S9Y_PEAR_PATH . 'HTTP/Request.php';
|
||||
global $serendipity;
|
||||
|
||||
@ -700,7 +705,6 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
return $check;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tries to add a favatar or pavatar (depending on the given mode) to the comment.
|
||||
*
|
||||
@ -710,7 +714,8 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
*
|
||||
* @return boolean true, if Avatar was found and added to the comment buffer
|
||||
*/
|
||||
function fetchPFavatar(&$eventData, $mode="F"){
|
||||
function fetchPFavatar(&$eventData, $mode="F")
|
||||
{
|
||||
require_once S9Y_PEAR_PATH . 'HTTP/Request.php';
|
||||
global $serendipity;
|
||||
|
||||
@ -753,7 +758,6 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
serendipity_request_start();
|
||||
}
|
||||
|
||||
|
||||
// Evaluate URL of P/Favatar
|
||||
$req = new HTTP_Request($url, array('allowRedirects' => true, 'maxRedirects' => 3));
|
||||
$favicon = false;
|
||||
@ -763,20 +767,16 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
// nothing to do,
|
||||
$favicon = false;
|
||||
$this->log($mode . " - Error fetching $url: " . $req->getResponseCode());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$pavatarHeaderIcon = $req->getResponseHeader("X-Pavatar");
|
||||
$fContent = $req->getResponseBody();
|
||||
if ($mode=='P' && !empty($pavatarHeaderIcon)){
|
||||
$faviconURL = $pavatarHeaderIcon;
|
||||
$this->log("Found x-pavatar in head: $faviconURL");
|
||||
}
|
||||
else if (!$islocalhost &&
|
||||
($mode=='P' && preg_match('/<link[^>]+rel="pavatar"[^>]+?href="([^"]+?)"/si', $fContent, $matches)) ||
|
||||
($mode=='F' && preg_match('/<link[^>]+rel="(?:shortcut )?icon"[^>]+?href="([^"]+?)"/si', $fContent, $matches))
|
||||
)
|
||||
else if (!$islocalhost && ($mode=='P' && preg_match('/<link[^>]+rel="pavatar"[^>]+?href="([^"]+?)"/si', $fContent, $matches)) ||
|
||||
($mode=='F' && preg_match('/<link[^>]+rel="(?:shortcut )?icon"[^>]+?href="([^"]+?)"/si', $fContent, $matches)))
|
||||
{
|
||||
|
||||
// Attempt to grab an avatar link from their webpage url
|
||||
$linkUrl = (function_exists('serendipity_entity_decode') ? serendipity_entity_decode($matches[1]) : html_entity_decode($matches[1], ENT_COMPAT, LANG_CHARSET));
|
||||
if (substr($linkUrl, 0, 1) == '/') {
|
||||
@ -792,8 +792,7 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
}
|
||||
|
||||
$this->log($mode . " - Found link rel to url $faviconURL");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// If unsuccessful, attempt to "guess" the favicon location
|
||||
$urlParts = parse_url($url);
|
||||
$faviconURL = $urlParts['scheme'] . '://' . $urlParts['host'] . ($mode=='F'?'/favicon.ico':'/pavatar.png');
|
||||
@ -801,7 +800,6 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
}
|
||||
|
||||
// Split image URL and check if image is available using a fast and timed out socket:
|
||||
|
||||
$url_parts = @parse_url($faviconURL);
|
||||
if (!is_array($url_parts)) {
|
||||
$url_parts = array();
|
||||
@ -853,10 +851,10 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function fetchTwitter(&$eventData) {
|
||||
function fetchTwitter(&$eventData)
|
||||
{
|
||||
require_once S9Y_PEAR_PATH . 'HTTP/Request.php';
|
||||
|
||||
// Was lastrun successfull?
|
||||
@ -927,7 +925,8 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
|
||||
}
|
||||
|
||||
function fetchIdentica(&$eventData) {
|
||||
function fetchIdentica(&$eventData)
|
||||
{
|
||||
require_once S9Y_PEAR_PATH . 'HTTP/Request.php';
|
||||
|
||||
// Was lastrun successfull?
|
||||
@ -977,7 +976,8 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
*
|
||||
* @return boolean true, if Avatar was found and added to the comment buffer
|
||||
*/
|
||||
function fetchMonster(&$eventData){
|
||||
function fetchMonster(&$eventData)
|
||||
{
|
||||
require_once dirname(__FILE__) . '/monsterid/monsterid.php';
|
||||
|
||||
$seed = md5($eventData['author']) . $eventData['email_md5'] . md5($eventData['url']);
|
||||
@ -1007,7 +1007,8 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
*
|
||||
* @return boolean true, if Avatar was found and added to the comment buffer
|
||||
*/
|
||||
function fetchWavatar(&$eventData){
|
||||
function fetchWavatar(&$eventData)
|
||||
{
|
||||
require_once dirname(__FILE__) . '/wavatars/wavatars.php';
|
||||
|
||||
$seed = md5($eventData['author']) . $eventData['email_md5'] . md5($eventData['url']);
|
||||
@ -1039,7 +1040,8 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
*
|
||||
* @return boolean true, if Avatar was found and added to the comment buffer
|
||||
*/
|
||||
function fetchYcon(&$eventData){
|
||||
function fetchYcon(&$eventData)
|
||||
{
|
||||
require_once dirname(__FILE__) . '/ycon/ycon.image.php';
|
||||
|
||||
$seed = md5($eventData['author']) . $eventData['email_md5'] . md5($eventData['url']);
|
||||
@ -1069,7 +1071,8 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
*
|
||||
* @return boolean true, if Avatar was found and added to the comment buffer
|
||||
*/
|
||||
function fetchDefault(){
|
||||
function fetchDefault()
|
||||
{
|
||||
global $serendipity;
|
||||
|
||||
$default = $this->getDefaultImageConfiguration();
|
||||
@ -1091,11 +1094,11 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Caches an avatar and streams it back to the browser.
|
||||
*/
|
||||
function saveAndResponseAvatar($eventData, $url, $allow_redirection = 3){
|
||||
function saveAndResponseAvatar($eventData, $url, $allow_redirection = 3)
|
||||
{
|
||||
require_once S9Y_PEAR_PATH . 'HTTP/Request.php';
|
||||
global $serendipity;
|
||||
$fContent = null;
|
||||
@ -1156,7 +1159,8 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
return true;
|
||||
}
|
||||
|
||||
function saveAndResponseMyBlogAvatar($eventData, $url) {
|
||||
function saveAndResponseMyBlogAvatar($eventData, $url)
|
||||
{
|
||||
global $serendipity;
|
||||
|
||||
$request_pars['allowRedirects'] = false;
|
||||
@ -1280,7 +1284,8 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
* @param string fContent content to be cached
|
||||
* @param request req optional the request that produced this content (for logging)
|
||||
*/
|
||||
function cacheAvatar($eventData, $fContent, $req=null){
|
||||
function cacheAvatar($eventData, $fContent, $req=null)
|
||||
{
|
||||
|
||||
$cache_file = $this->getCacheFilePath($eventData);
|
||||
$this->log("cacheAvatar: " . $cache_file);
|
||||
@ -1308,12 +1313,11 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
return $cache_file;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Return binary response for an image
|
||||
*/
|
||||
function show($filename) {
|
||||
function show($filename)
|
||||
{
|
||||
$this->log("show: $filename");
|
||||
if (!file_exists($filename)) {
|
||||
header('X-Avatar: No-Image');
|
||||
@ -1372,8 +1376,8 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
* @param string title the title for that image
|
||||
* @return string the html code representing the Avatar
|
||||
*/
|
||||
function generateImageHtml($url, $title = null, $align = 'right', $addAlignClass = true, $cssClass = "comment_avatar"){
|
||||
|
||||
function generateImageHtml($url, $title = null, $align = 'right', $addAlignClass = true, $cssClass = "comment_avatar")
|
||||
{
|
||||
$default = $this->getDefaultImageConfiguration();
|
||||
|
||||
if (empty($title)){
|
||||
@ -1386,7 +1390,7 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
if ($addAlignClass && ($align == 'right' || $align == 'left'))
|
||||
$cssAlign = "avatar_$align";
|
||||
$alt = '*';
|
||||
if (serendipity_db_bool($this->get_config('autoralt', false))) {
|
||||
if (serendipity_db_bool($this->get_config('autoralt', 'false'))) {
|
||||
$alt = $title;
|
||||
}
|
||||
return '<img src="' . $url . '" alt="' . $alt . '" title="' . $title . '" class="' . $cssClass . ($addAlignClass? " $cssAlign":"") . '" height="' . $default['size'] . '" width="' . $default['size'] . '"/>';
|
||||
@ -1395,14 +1399,16 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
/**
|
||||
* Just generates comments into the comment block. Used for debugging only!
|
||||
*/
|
||||
function generateComment(&$eventData, $comment){
|
||||
function generateComment(&$eventData, $comment)
|
||||
{
|
||||
$eventData['comment'] = "-- $comment --<br>\n" . $eventData['comment'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the avatar cache directory
|
||||
*/
|
||||
function getCacheDirectory(){
|
||||
function getCacheDirectory()
|
||||
{
|
||||
global $serendipity;
|
||||
if ($this->cache_dir === null) {
|
||||
$this->cache_dir = $serendipity['serendipityPath'] . PATH_SMARTY_COMPILE . '/serendipity_event_avatar';
|
||||
@ -1415,7 +1421,8 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
* If no relevant user data was found, null is returned.
|
||||
*
|
||||
*/
|
||||
function getCacheFilePath($eventData){
|
||||
function getCacheFilePath($eventData)
|
||||
{
|
||||
global $serendipity;
|
||||
|
||||
$cache_filename = $this->getCacheFileName($eventData);
|
||||
@ -1430,7 +1437,8 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
* If no relevant user data was found, null is returned.
|
||||
*
|
||||
*/
|
||||
function getCacheFileUrl($eventData){
|
||||
function getCacheFileUrl($eventData)
|
||||
{
|
||||
global $serendipity;
|
||||
|
||||
$cache_filename = $this->getCacheFileName($eventData);
|
||||
@ -1443,12 +1451,14 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
/**
|
||||
* Returns a URL encoded and signed variable.
|
||||
*/
|
||||
function urlencode($url) {
|
||||
function urlencode($url)
|
||||
{
|
||||
$hash = md5($this->instance_id . $url);
|
||||
return $hash . str_replace ('_', '%5F', urlencode($url));
|
||||
}
|
||||
|
||||
function urldecode($url) {
|
||||
function urldecode($url)
|
||||
{
|
||||
$hash = substr($url, 0, 32);
|
||||
$real_url = urldecode(substr($url, 32));
|
||||
|
||||
@ -1466,7 +1476,8 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
* If no relevant user data was found, null is returned.
|
||||
*
|
||||
*/
|
||||
function getCacheFileName($eventData){
|
||||
function getCacheFileName($eventData)
|
||||
{
|
||||
global $serendipity;
|
||||
|
||||
if (!isset($eventData['email']) && !isset($eventData['email_md5']) && !isset($eventData['url'])) {
|
||||
@ -1489,7 +1500,8 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
/**
|
||||
* Builds an array of default image configuration
|
||||
*/
|
||||
function getDefaultImageConfiguration() {
|
||||
function getDefaultImageConfiguration()
|
||||
{
|
||||
global $serendipity;
|
||||
|
||||
if ($this->defaultImageConfigurationdefault === null) {
|
||||
@ -1502,7 +1514,8 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
return $this->defaultImageConfigurationdefault;
|
||||
}
|
||||
|
||||
function getPermaPluginPath() {
|
||||
function getPermaPluginPath()
|
||||
{
|
||||
global $serendipity;
|
||||
|
||||
// Get configured plugin path:
|
||||
@ -1515,12 +1528,14 @@ class serendipity_event_gravatar extends serendipity_event
|
||||
|
||||
}
|
||||
|
||||
function log($message){
|
||||
function log($message)
|
||||
{
|
||||
if (!PLUGIN_EVENT_GRAVATAR_DEBUG) return;
|
||||
$fp = fopen($this->getCacheDirectory() . '.log','a');
|
||||
fwrite($fp, $message . "\n");
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* vim: set sts=4 ts=4 expandtab : */
|
||||
|
@ -99,9 +99,9 @@ Builds the avatar.
|
||||
|
||||
function wavatar_build ($filename, $seed, $size)
|
||||
{
|
||||
if (!function_exists (imagecreatetruecolor)) {
|
||||
return false;
|
||||
}
|
||||
if (!function_exists (imagecreatetruecolor)) {
|
||||
return false;
|
||||
}
|
||||
$face = 1 + (hexdec (substr ($seed, 1, 2)) % (WAVATAR_FACES));
|
||||
$bg_color = (hexdec (substr ($seed, 3, 2)) % 240);
|
||||
$fade = 1 + (hexdec (substr ($seed, 5, 2)) % (WAVATAR_BACKGROUNDS));
|
||||
|
@ -2,13 +2,13 @@
|
||||
require_once 'ycon.php';
|
||||
|
||||
function build_ycon($filename, $seed='',$size=''){
|
||||
$hash = md5($seed);
|
||||
$image = ycon($hash, $size, 255, 255, 255);
|
||||
imagetruecolortopalette($image, false, 64);
|
||||
// header('Content-type: image/png');
|
||||
imagepng($image,$filename);
|
||||
imagedestroy($image);
|
||||
return true;
|
||||
$hash = md5($seed);
|
||||
$image = ycon($hash, $size, 255, 255, 255);
|
||||
imagetruecolortopalette($image, false, 64);
|
||||
// header('Content-type: image/png');
|
||||
imagepng($image,$filename);
|
||||
imagedestroy($image);
|
||||
return true;
|
||||
}
|
||||
|
||||
?>
|
@ -282,4 +282,5 @@ function draw_glpyh(&$image, $x, $y, $full, $fg_color, $bg_color, $shape, $rotat
|
||||
// draw the bastard
|
||||
imagefilledpolygon($image, $points, count($points) / 2, $drawing_color);
|
||||
}
|
||||
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user