| 1 | <?php |
|---|
| 2 | // wcf imports |
|---|
| 3 | require_once(WCF_DIR.'lib/data/user/User.class.php'); |
|---|
| 4 | require_once(WCF_DIR.'lib/data/user/option/UserOptionOutput.class.php'); |
|---|
| 5 | require_once(WCF_DIR.'lib/data/user/option/UserOptionOutputContactInformation.class.php'); |
|---|
| 6 | |
|---|
| 7 | /** |
|---|
| 8 | * |
|---|
| 9 | * @author Torben Brodt |
|---|
| 10 | * @copyright 2011 easy-coding.de |
|---|
| 11 | * @license GNU General Public License <http://opensource.org/licenses/gpl-3.0.html> |
|---|
| 12 | * @package de.easy-coding.wcf.plus |
|---|
| 13 | */ |
|---|
| 14 | class UserOptionOutputPlus implements UserOptionOutput, UserOptionOutputContactInformation { |
|---|
| 15 | protected $type = 'googleplus'; |
|---|
| 16 | |
|---|
| 17 | // UserOptionOutput implementation |
|---|
| 18 | |
|---|
| 19 | /** |
|---|
| 20 | * @see UserOptionOutput::getShortOutput() |
|---|
| 21 | */ |
|---|
| 22 | public function getShortOutput(User $user, $optionData, $value) { |
|---|
| 23 | return $this->getImage($user, $value, 'S'); |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | /** |
|---|
| 27 | * @see UserOptionOutput::getMediumOutput() |
|---|
| 28 | */ |
|---|
| 29 | public function getMediumOutput(User $user, $optionData, $value) { |
|---|
| 30 | return $this->getImage($user, $value); |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | /** |
|---|
| 34 | * @see UserOptionOutput::getOutput() |
|---|
| 35 | */ |
|---|
| 36 | public function getOutput(User $user, $optionData, $value) { |
|---|
| 37 | if (empty($value) || $value == 'http://') return ''; |
|---|
| 38 | |
|---|
| 39 | $value = self::getURL($value); |
|---|
| 40 | $value = StringUtil::encodeHTML($value); |
|---|
| 41 | return '<a href="'.$value.'">'.$value.'</a>'; |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | // UserOptionOutputContactInformation implementation |
|---|
| 45 | /** |
|---|
| 46 | * @see UserOptionOutputContactInformation::getOutput() |
|---|
| 47 | */ |
|---|
| 48 | public function getOutputData(User $user, $optionData, $value) { |
|---|
| 49 | if (empty($value) || $value == 'http://') return null; |
|---|
| 50 | |
|---|
| 51 | $value = self::getURL($value); |
|---|
| 52 | $value = StringUtil::encodeHTML($value); |
|---|
| 53 | |
|---|
| 54 | return array( |
|---|
| 55 | 'icon' => StyleManager::getStyle()->getIconPath($this->type.'M.png'), |
|---|
| 56 | 'title' => WCF::getLanguage()->get('wcf.user.option.'.$optionData['optionName']), |
|---|
| 57 | 'value' => $value, |
|---|
| 58 | 'url' => $value |
|---|
| 59 | ); |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | /** |
|---|
| 63 | * Generates an image button. |
|---|
| 64 | * |
|---|
| 65 | * @see UserOptionOutput::getShortOutput() |
|---|
| 66 | */ |
|---|
| 67 | protected function getImage(User $user, $value, $imageSize = 'M') { |
|---|
| 68 | if (empty($value) || $value == 'http://') return ''; |
|---|
| 69 | |
|---|
| 70 | $value = self::getURL($value); |
|---|
| 71 | $title = WCF::getLanguage()->get('wcf.user.profile.plus.title', array('$username' => StringUtil::encodeHTML($user->username))); |
|---|
| 72 | return '<a href="'.StringUtil::encodeHTML($value).'"><img src="'.StyleManager::getStyle()->getIconPath($this->type.$imageSize.'.png').'" alt="" title="'.$title.'" /></a>'; |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | /** |
|---|
| 76 | * @return integer |
|---|
| 77 | */ |
|---|
| 78 | public static function getID($url) { |
|---|
| 79 | if (is_numeric($url)) { |
|---|
| 80 | return $url; |
|---|
| 81 | } else if (preg_match('/^https?:\/\/plus\.google\.com\/([0-9]+)/', $url, $res)) { |
|---|
| 82 | return $res[1]; |
|---|
| 83 | } |
|---|
| 84 | return 0; |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | /** |
|---|
| 88 | * Formats the URL. |
|---|
| 89 | * |
|---|
| 90 | * @param string $url |
|---|
| 91 | * @return string |
|---|
| 92 | */ |
|---|
| 93 | private static function getURL($url) { |
|---|
| 94 | $id = self::getID($url); |
|---|
| 95 | return 'https://plus.google.com/'.$id; |
|---|
| 96 | } |
|---|
| 97 | } |
|---|
| 98 | ?> |
|---|