Skip to content

Commit

Permalink
add gavatar
Browse files Browse the repository at this point in the history
  • Loading branch information
skywalker512 committed Jul 8, 2018
1 parent 5f0c3fd commit 70fe8c5
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 0 deletions.
4 changes: 4 additions & 0 deletions addons/languages/Chinese/definitions.Gravatar.php
@@ -0,0 +1,4 @@
<?php
$definitions["Change your avatar on %s."] = "请到 %s 更改你的头像";
$definitions["Default imageset"] = "默认头像";
$definitions["Default"] = "Default";
37 changes: 37 additions & 0 deletions addons/plugins/Gravatar/.gitignore
@@ -0,0 +1,37 @@
.buildpath
.project
.settings
.htaccess

# Compiled source
*.com
*.class
*.dll
*.exe
*.o
*.so

# Packages
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip

# Logs and databases
*.log
*.sql
*.sqlite

# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
*~
20 changes: 20 additions & 0 deletions addons/plugins/Gravatar/README.md
@@ -0,0 +1,20 @@
# Gravatar Plugin

Allows users to choose to use their Gravatar.

## Installation

[Download](https://github.com/esotalk/Gravatar/archive/master.zip) or clone the Gravatar plugin repo into your esoTalk plugin directory:

cd ESOTALK_DIR/addons/plugins/
git clone git@github.com:esotalk/Gravatar.git Gravatar

Navigate to the the admin/plugins page and activate the Gravatar plugin.

## Translation

Create `definitions.Gravatar.php` in your language pack with the following definitions:

$definitions["Change your avatar on %s."] = "Change your avatar on %s.";
$definitions["Default imageset"] = "Default imageset";
$definitions["Default"] = "Default";
Binary file added addons/plugins/Gravatar/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
91 changes: 91 additions & 0 deletions addons/plugins/Gravatar/plugin.php
@@ -0,0 +1,91 @@
<?php
// Copyright 2013 Toby Zerner, Simon Zerner
// This file is part of esoTalk. Please see the included license file for usage information.

if (!defined("IN_ESOTALK")) exit;

ET::$pluginInfo["Gravatar"] = array(
"name" => "Gravatar",
"description" => "允许用户使用 Gravatar 头像",
"version" => ESOTALK_VERSION,
"author" => "Toby Zerner",
"authorEmail" => "support@esotalk.org",
"authorURL" => "http://esotalk.org",
"license" => "GPLv2",
"dependencies" => array(
"esoTalk" => "1.0.0g4"
)
);

class ETPlugin_Gravatar extends ETPlugin {

function init()
{
// Override the avatar function.

/**
* Return an image tag containing a member's avatar.
*
* @param array $member An array of the member's details. (email is required in this implementation.)
* @param string $avatarFormat The format of the member's avatar (as stored in the database - jpg|gif|png.)
* @param string $className CSS class names to apply to the avatar.
*/
function avatar($member = array(), $className = "")
{
$default = C("plugin.Gravatar.default") ? C("plugin.Gravatar.default") : "mm";

$url = "https://cdn.v2ex.com/gravatar/".md5(strtolower(trim($member["email"])))."?d=".urlencode($default)."&s=64";

return "<img src='$url' alt='' class='avatar $className'/>";
}
}

// Change the avatar field on the settings page.
function handler_settingsController_initGeneral($sender, $form)
{
$form->removeField("avatar", "avatar");
$form->addField("avatar", "avatar", array($this, "fieldAvatar"));
}

function fieldAvatar($form)
{
return sprintf(T("Change your avatar on %s."), "<a href='http://gravatar.com' target='_blank'>Gravatar.com</a>");
}

/**
* Construct and process the settings form for this skin, and return the path to the view that should be
* rendered.
*
* @param ETController $sender The page controller.
* @return string The path to the settings view to render.
*/
public function settings($sender)
{
// Set up the settings form.
$form = ETFactory::make("form");
$form->action = URL("admin/plugins/settings/Gravatar");
$form->setValue("default", C("plugin.Gravatar.default", "mm"));

// If the form was submitted...
if ($form->validPostBack("save")) {

// Construct an array of config options to write.
$config = array();
$config["plugin.Gravatar.default"] = $form->getValue("default");

if (!$form->errorCount()) {

// Write the config file.
ET::writeConfig($config);

$sender->message(T("message.changesSaved"), "success autoDismiss");
$sender->redirect(URL("admin/plugins"));

}
}

$sender->data("gravatarSettingsForm", $form);
return $this->view("settings");
}

}
51 changes: 51 additions & 0 deletions addons/plugins/Gravatar/views/settings.php
@@ -0,0 +1,51 @@
<?php
// Copyright 2011 Toby Zerner, Simon Zerner
// This file is part of esoTalk. Please see the included license file for usage information.

if (!defined("IN_ESOTALK")) exit;

/**
* Displays the settings form for the Gravatar plugin.
*
* @package esoTalk
*/

$form = $data["gravatarSettingsForm"];
?>
<style>
#gravatarDefaults label {
float:left;
width:40%;
margin-bottom:20px;
}
#gravatarDefaults img {
display:block;
}
</style>

<?php echo $form->open(); ?>

<div class='section'>

<ul class='form'>

<li>
<label><?php echo T("Default imageset"); ?></label>
<div class='checkboxGroup' id='gravatarDefaults'>
<label class='radio'><?php echo $form->radio("default", "mm"); ?> <img src='https://cdn.v2ex.com/gravatar/0?d=mm' class='avatar'> <?php echo T("Default"); ?></label>
<label class='radio'><?php echo $form->radio("default", "identicon"); ?> <img src='https://cdn.v2ex.com/gravatar/0?d=identicon' class='avatar'> Identicon</label>
<label class='radio'><?php echo $form->radio("default", "monsterid"); ?> <img src='https://cdn.v2ex.com/gravatar/0?d=monsterid' class='avatar'> MonsterID</label>
<label class='radio'><?php echo $form->radio("default", "wavatar"); ?> <img src='https://cdn.v2ex.com/gravatar/0?d=wavatar' class='avatar'> Wavatar</label>
<label class='radio'><?php echo $form->radio("default", "retro"); ?> <img src='https://cdn.v2ex.com/gravatar/0?d=retro' class='avatar'> Retro</label>
</div>
</li>

</ul>

</div>

<div class='buttons'>
<?php echo $form->saveButton(); ?>
</div>

<?php echo $form->close(); ?>

0 comments on commit 70fe8c5

Please sign in to comment.