PageRenderTime 87ms CodeModel.GetById 25ms RepoModel.GetById 2ms app.codeStats 0ms

/plugins/Gravatar/plugin.php

https://github.com/Ramir1/esoTalk
PHP | 96 lines | 54 code | 20 blank | 22 comment | 6 complexity | 13f1aa91cb37e0b2f7fc1254a5c18867 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. // Copyright 2013 Toby Zerner, Simon Zerner
  3. // This file is part of esoTalk. Please see the included license file for usage information.
  4. if (!defined("IN_ESOTALK")) exit;
  5. ET::$pluginInfo["Gravatar"] = array(
  6. "name" => "Gravatar",
  7. "description" => "Allows users to choose to use their Gravatar.",
  8. "version" => ESOTALK_VERSION,
  9. "author" => "Toby Zerner",
  10. "authorEmail" => "support@esotalk.org",
  11. "authorURL" => "http://esotalk.org",
  12. "license" => "GPLv2"
  13. );
  14. class ETPlugin_Gravatar extends ETPlugin {
  15. function init()
  16. {
  17. // Override the avatar function.
  18. /**
  19. * Return an image tag containing a member's avatar.
  20. *
  21. * @param array $member An array of the member's details. (email is required in this implementation.)
  22. * @param string $avatarFormat The format of the member's avatar (as stored in the database - jpg|gif|png.)
  23. * @param string $className CSS class names to apply to the avatar.
  24. */
  25. function avatar($member = array(), $className = "")
  26. {
  27. $esoTalkDefault = getResource("skins/base/avatar.png", true);
  28. if (empty($member["email"])) $url = $esoTalkDefault;
  29. else {
  30. $default = C("plugin.Gravatar.default");
  31. if (!$default or empty($member)) $default = $esoTalkDefault;
  32. $protocol = C("esoTalk.https") ? "https" : "http";
  33. $url = "$protocol://www.gravatar.com/avatar/".md5(strtolower(trim($member["email"])))."?d=".urlencode($default)."&s=64";
  34. }
  35. return "<img src='$url' alt='' class='avatar $className'/>";
  36. }
  37. }
  38. // Change the avatar field on the settings page.
  39. function handler_settingsController_initGeneral($sender, $form)
  40. {
  41. $form->removeField("avatar", "avatar");
  42. $form->addField("avatar", "avatar", array($this, "fieldAvatar"));
  43. }
  44. function fieldAvatar($form)
  45. {
  46. return T("Change your avatar on <a href='http://gravatar.com' target='_blank'>Gravatar.com</a>.");
  47. }
  48. /**
  49. * Construct and process the settings form for this skin, and return the path to the view that should be
  50. * rendered.
  51. *
  52. * @param ETController $sender The page controller.
  53. * @return string The path to the settings view to render.
  54. */
  55. public function settings($sender)
  56. {
  57. // Set up the settings form.
  58. $form = ETFactory::make("form");
  59. $form->action = URL("admin/plugins");
  60. $form->setValue("default", C("plugin.Gravatar.default"));
  61. // If the form was submitted...
  62. if ($form->validPostBack("save")) {
  63. // Construct an array of config options to write.
  64. $config = array();
  65. $config["plugin.Gravatar.default"] = $form->getValue("default");
  66. if (!$form->errorCount()) {
  67. // Write the config file.
  68. ET::writeConfig($config);
  69. $sender->message(T("message.changesSaved"), "success");
  70. $sender->redirect(URL("admin/plugins"));
  71. }
  72. }
  73. $sender->data("gravatarSettingsForm", $form);
  74. return $this->getView("settings");
  75. }
  76. }