| 1 | <?php
|
|---|
| 2 | /**
|
|---|
| 3 | * Avatar class. Plugins that provide avatars should hook into this.
|
|---|
| 4 | *
|
|---|
| 5 | * PHP version 5
|
|---|
| 6 | *
|
|---|
| 7 | * LICENSE: Hotaru CMS is free software: you can redistribute it and/or
|
|---|
| 8 | * modify it under the terms of the GNU General Public License as
|
|---|
| 9 | * published by the Free Software Foundation, either version 3 of
|
|---|
| 10 | * the License, or (at your option) any later version.
|
|---|
| 11 | *
|
|---|
| 12 | * Hotaru CMS is distributed in the hope that it will be useful, but WITHOUT
|
|---|
| 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|---|
| 14 | * FITNESS FOR A PARTICULAR PURPOSE.
|
|---|
| 15 | *
|
|---|
| 16 | * You should have received a copy of the GNU General Public License along
|
|---|
| 17 | * with Hotaru CMS. If not, see http://www.gnu.org/licenses/.
|
|---|
| 18 | *
|
|---|
| 19 | * @category Content Management System
|
|---|
| 20 | * @package HotaruCMS
|
|---|
| 21 | * @author Nick Ramsay <admin@hotarucms.org>
|
|---|
| 22 | * @copyright Copyright (c) 2009, Hotaru CMS
|
|---|
| 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
|
|---|
| 24 | * @link http://www.hotarucms.org/
|
|---|
| 25 | *
|
|---|
| 26 | * USAGE:
|
|---|
| 27 | * $avatar = new Avatar($h, $user_id, $size, $rating);
|
|---|
| 28 | * $avatar->getAvatar($h); // returns the avatar for custom display... OR...
|
|---|
| 29 | * $avatar->linkAvatar($h); // displays the avatar linked to the user's profile
|
|---|
| 30 | * $avatar->wrapAvatar($h); // displays the avatar linked and wrapped in a div
|
|---|
| 31 | *
|
|---|
| 32 | * Shortcuts:
|
|---|
| 33 | * $h->setAvatar($user_id, $size, $rating);
|
|---|
| 34 | * $h->getAvatar(); $h->linkAvatar(); $h->wrapAvatar();
|
|---|
| 35 | *
|
|---|
| 36 | */
|
|---|
| 37 | class Avatar
|
|---|
| 38 | {
|
|---|
| 39 | public $user_id = 0;
|
|---|
| 40 | public $user_name = '';
|
|---|
| 41 | public $user_email = '';
|
|---|
| 42 | public $size = 32;
|
|---|
| 43 | public $rating = 'g'; // "global" used by Gravatar
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 | /**
|
|---|
| 47 | * constructor
|
|---|
| 48 | *
|
|---|
| 49 | * @param $h Hotaru object
|
|---|
| 50 | * @param $user_id
|
|---|
| 51 | * @param $size avatar size in pixels
|
|---|
| 52 | * @param $rating avatar rating (g, pg, r or x in Gravatar)
|
|---|
| 53 | */
|
|---|
| 54 | public function __construct($h, $user_id = 0, $size = 32, $rating = 'g')
|
|---|
| 55 | {
|
|---|
| 56 | if (!$user_id) { return false; }
|
|---|
| 57 |
|
|---|
| 58 | $this->user_id = $user_id;
|
|---|
| 59 |
|
|---|
| 60 | $user = new UserBase();
|
|---|
| 61 | $user->getUserBasic($h, $this->user_id);
|
|---|
| 62 | $this->user_email = $user->email;
|
|---|
| 63 | $this->user_name = $user->name;
|
|---|
| 64 |
|
|---|
| 65 | $this->size = $size;
|
|---|
| 66 | $this->rating = $rating;
|
|---|
| 67 |
|
|---|
| 68 | $this->setVars($h);
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 | /**
|
|---|
| 73 | * Add Avatar properties to a vars array for plugins to use
|
|---|
| 74 | */
|
|---|
| 75 | public function setVars($h)
|
|---|
| 76 | {
|
|---|
| 77 | $vars = array(
|
|---|
| 78 | 'user_id'=>$this->user_id,
|
|---|
| 79 | 'user_name'=>$this->user_name,
|
|---|
| 80 | 'user_email'=>$this->user_email,
|
|---|
| 81 | 'size'=>$this->size,
|
|---|
| 82 | 'rating'=>$this->rating
|
|---|
| 83 | );
|
|---|
| 84 |
|
|---|
| 85 | $h->pluginHook('avatar_set_avatar', '', $vars);
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 | /**
|
|---|
| 90 | * get the plain avatar with no surrounding HTML div
|
|---|
| 91 | *
|
|---|
| 92 | * @return return the avatar
|
|---|
| 93 | */
|
|---|
| 94 | public function getAvatar($h)
|
|---|
| 95 | {
|
|---|
| 96 | if (!$this->user_id) { return false; }
|
|---|
| 97 |
|
|---|
| 98 | $result = $h->pluginHook('avatar_get_avatar');
|
|---|
| 99 | if ($result) {
|
|---|
| 100 | foreach ($result as $key => $value) {
|
|---|
| 101 | $avatar = $value;
|
|---|
| 102 | }
|
|---|
| 103 | return $avatar; // returns the last avatar sent to this hook
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | return false;
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 | /**
|
|---|
| 111 | * option to display the avatar linked to ther user's profile
|
|---|
| 112 | */
|
|---|
| 113 | public function linkAvatar($h)
|
|---|
| 114 | {
|
|---|
| 115 | if (!$this->user_id) { return false; }
|
|---|
| 116 |
|
|---|
| 117 | $output = "<a href='" . $h->url(array('user' => $this->user_name)) . "' title='" . $this->user_name . "'>\n";
|
|---|
| 118 | $result = $h->pluginHook('avatar_get_avatar');
|
|---|
| 119 | if ($result) {
|
|---|
| 120 | foreach ($result as $key => $value) {
|
|---|
| 121 | $avatar = $value;
|
|---|
| 122 | }
|
|---|
| 123 | $output .= $avatar; // uses the last avatar sent to this hook
|
|---|
| 124 | }
|
|---|
| 125 | $output .= "</a>\n";
|
|---|
| 126 | return $output;
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 | /**
|
|---|
| 131 | * option to display the profile-linked avatar wrapped in a div
|
|---|
| 132 | */
|
|---|
| 133 | public function wrapAvatar($h)
|
|---|
| 134 | {
|
|---|
| 135 | if (!$this->user_id) { return false; }
|
|---|
| 136 |
|
|---|
| 137 | $output = "<div class='avatar_wrapper'>";
|
|---|
| 138 | $output .= "<a href='" . $h->url(array('user' => $this->user_name)) . "' title='" . $this->user_name . "'>\n";
|
|---|
| 139 | $result = $h->pluginHook('avatar_get_avatar');
|
|---|
| 140 | if ($result) {
|
|---|
| 141 | foreach ($result as $key => $value) {
|
|---|
| 142 | $avatar = $value;
|
|---|
| 143 | }
|
|---|
| 144 | $output .= $avatar; // uses the last avatar sent to this hook
|
|---|
| 145 | }
|
|---|
| 146 | $output .= "</a>\n";
|
|---|
| 147 | $output .= "</div>\n";
|
|---|
| 148 | return $output;
|
|---|
| 149 | }
|
|---|
| 150 | }
|
|---|
| 151 | ?>
|
|---|