Skip to content

Commit 4a09391

Browse files
committed
Add other user profiles to user view page
1 parent 697c138 commit 4a09391

File tree

4 files changed

+140
-17
lines changed

4 files changed

+140
-17
lines changed

src/controllers/User/View.php

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,38 @@ protected function getUserInfo(UserViewModel &$model) {
6060

6161
// Try to get their user profile
6262
try {
63-
$model->user_profile = new UserProfile($this->user_id);
64-
$model->biography = $model->user_profile->getBiography();
65-
$model->github = $model->user_profile->getGitHubUsername();
66-
$model->facebook = $model->user_profile->getFacebookUsername();
67-
$model->twitter = $model->user_profile->getTwitterUsername();
68-
$model->instagram = $model->user_profile->getInstagramUsername();
69-
$model->skype = $model->user_profile->getSkypeUsername();
70-
$model->website = $model->user_profile->getWebsite();
63+
64+
$model->user_profile = new UserProfile($this->user_id);
65+
66+
$model->biography = $model->user_profile->getBiography();
67+
68+
$model->facebook = $model->user_profile->getFacebookUsername();
69+
$model->facebook_uri = $model->user_profile->getFacebookURI();
70+
71+
$model->github = $model->user_profile->getGitHubUsername();
72+
$model->github_uri = $model->user_profile->getGitHubURI();
73+
74+
$model->instagram = $model->user_profile->getInstagramUsername();
75+
$model->instagram_uri = $model->user_profile->getInstagramURI();
76+
77+
$model->phone = $model->user_profile->getPhone();
78+
$model->phone_uri = $model->user_profile->getPhoneURI();
79+
80+
$model->reddit = $model->user_profile->getRedditUsername();
81+
$model->reddit_uri = $model->user_profile->getRedditURI();
82+
83+
$model->skype = $model->user_profile->getSkypeUsername();
84+
$model->skype_uri = $model->user_profile->getSkypeURI();
85+
86+
$model->steam_id = $model->user_profile->getSteamId();
87+
$model->steam_uri = $model->user_profile->getSteamURI();
88+
89+
$model->twitter = $model->user_profile->getTwitterUsername();
90+
$model->twitter_uri = $model->user_profile->getTwitterURI();
91+
92+
$model->website = $model->user_profile->getWebsite();
93+
$model->website_uri = $model->user_profile->getWebsiteURI();
94+
7195
} catch (UserProfileNotFoundException $e) {
7296
// Not a problem
7397
}

src/libraries/UserProfile.php

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ class UserProfile {
2121
protected $id;
2222
protected $instagram_username;
2323
protected $phone;
24+
protected $reddit_username;
2425
protected $skype_username;
26+
protected $steam_id;
2527
protected $twitter_username;
2628
protected $website;
2729

@@ -33,7 +35,9 @@ public function __construct($data) {
3335
$this->id = (int) $data;
3436
$this->instagram_username = null;
3537
$this->phone = null;
38+
$this->reddit_username = null;
3639
$this->skype_username = null;
40+
$this->steam_id = null;
3741
$this->twitter_username = null;
3842
$this->website = null;
3943
$this->refresh();
@@ -45,7 +49,9 @@ public function __construct($data) {
4549
$this->id = $data->id;
4650
$this->instagram_username = $data->instagram_username;
4751
$this->phone = $data->phone;
52+
$this->reddit_username = $data->reddit_username;
4853
$this->skype_username = $data->skype_username;
54+
$this->steam_id = $data->steam_id;
4955
$this->twitter_username = $data->twitter_username;
5056
$this->website = $data->website;
5157
} else {
@@ -57,10 +63,18 @@ public function getBiography() {
5763
return $this->biography;
5864
}
5965

66+
public function getFacebookURI() {
67+
return "https://www.facebook.com/" . $this->getFacebookUsername();
68+
}
69+
6070
public function getFacebookUsername() {
6171
return $this->facebook_username;
6272
}
6373

74+
public function getGitHubURI() {
75+
return "https://github.com/" . $this->getGitHubUsername();
76+
}
77+
6478
public function getGitHubUsername() {
6579
return $this->github_username;
6680
}
@@ -69,6 +83,10 @@ public function getId() {
6983
return $this->id;
7084
}
7185

86+
public function getInstagramURI() {
87+
return "https://instagram.com/" . $this->getInstagramUsername();
88+
}
89+
7290
public function getInstagramUsername() {
7391
return $this->instagram_username;
7492
}
@@ -77,20 +95,66 @@ public function getPhone() {
7795
return $this->phone;
7896
}
7997

98+
public function getPhoneURI() {
99+
return "tel://" . $this->getPhone();
100+
}
101+
102+
public function getRedditURI() {
103+
return "https://www.reddit.com/user/" . $this->getRedditUsername();
104+
}
105+
106+
public function getRedditUsername() {
107+
return $this->reddit_username;
108+
}
109+
110+
public function getSkypeURI() {
111+
return "skype:" . $this->getSkypeUsername() . "?chat";
112+
}
113+
80114
public function getSkypeUsername() {
81115
return $this->skype_username;
82116
}
83117

118+
public function getSteamId() {
119+
return $this->steam_id;
120+
}
121+
122+
public function getSteamURI() {
123+
return "https://steamcommunity.com/profiles/" . $this->getSteamId();
124+
}
125+
126+
public function getTwitterURI() {
127+
return "https://twitter.com/" . $this->getTwitterUsername();
128+
}
129+
84130
public function getTwitterUsername() {
85131
return $this->twitter_username;
86132
}
87133

88134
public function getWebsite() {
89-
return $this->website;
135+
$value = strtolower($this->website);
136+
if (substr($value, 0, 7) == "http://") {
137+
return substr($value, 7);
138+
} else if (substr($value, 0, 8) == "https://") {
139+
return substr($value, 8);
140+
} else {
141+
return "http://" . $value;
142+
}
143+
}
144+
145+
public function getWebsiteURI() {
146+
$value = strtolower($this->website);
147+
if (substr($value, 0, 7) == "http://"
148+
|| substr($value, 0, 8) == "https://") {
149+
return $value;
150+
} else {
151+
return "http://" . $value;
152+
}
90153
}
91154

92155
protected static function normalize(StdClass &$data) {
93-
$data->user_id = (int) $data->user_id;
156+
$data->user_id = (int) $data->user_id;
157+
$data->steam_id = (int) $data->steam_id;
94158

95159
if (!is_null($data->biography))
96160
$data->biography = (string) $data->biography;
@@ -107,6 +171,9 @@ protected static function normalize(StdClass &$data) {
107171
if (!is_null($data->phone))
108172
$data->phone = (string) $data->phone;
109173

174+
if (!is_null($data->reddit_username))
175+
$data->reddit_username = (string) $data->reddit_username;
176+
110177
if (!is_null($data->skype_username))
111178
$data->skype_username = (string) $data->skype_username;
112179

@@ -129,7 +196,9 @@ public function refresh() {
129196
$this->github_username = $cache_val->github_username;
130197
$this->instagram_username = $cache_val->instagram_username;
131198
$this->phone = $cache_val->phone;
199+
$this->reddit_username = $cache_val->reddit_username;
132200
$this->skype_username = $cache_val->skype_username;
201+
$this->steam_id = $cache_val->steam_id;
133202
$this->twitter_username = $cache_val->twitter_username;
134203
$this->website = $cache_val->website;
135204
return true;
@@ -143,11 +212,13 @@ public function refresh() {
143212
`biography`,
144213
`facebook_username`,
145214
`github_username`,
146-
`user_id`,
147215
`instagram_username`,
148216
`phone`,
217+
`reddit_username`,
149218
`skype_username`,
219+
`steam_id`,
150220
`twitter_username`,
221+
`user_id`,
151222
`website`
152223
FROM `user_profiles`
153224
WHERE `user_id` = :id
@@ -167,7 +238,9 @@ public function refresh() {
167238
$this->github_username = $row->github_username;
168239
$this->instagram_username = $row->instagram_username;
169240
$this->phone = $row->phone;
241+
$this->reddit_username = $row->reddit_username;
170242
$this->skype_username = $row->skype_username;
243+
$this->steam_id = $row->steam_id;
171244
$this->twitter_username = $row->twitter_username;
172245
$this->website = $row->website;
173246
Common::$cache->set($cache_key, serialize($row), 300);

src/models/User/View.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,49 +10,69 @@ class View extends Model {
1010
public $contributions;
1111
public $documents;
1212
public $facebook;
13+
public $facebook_uri;
1314
public $github;
15+
public $github_uri;
1416
public $instagram;
17+
public $instagram_uri;
1518
public $news_posts;
1619
public $packets;
1720
public $profiledata;
21+
public $reddit;
22+
public $reddit_uri;
1823
public $servers;
1924
public $skype;
25+
public $skype_uri;
26+
public $steam_id;
27+
public $steam_uri;
2028
public $sum_documents;
2129
public $sum_news_posts;
2230
public $sum_packets;
2331
public $sum_servers;
2432
public $twitter;
33+
public $twitter_uri;
2534
public $user;
2635
public $user_est;
2736
public $user_id;
2837
public $user_profile;
2938
public $user_session;
3039
public $website;
40+
public $website_uri;
3141

3242
public function __construct() {
3343
parent::__construct();
3444
$this->biography = null;
3545
$this->contributions = null;
3646
$this->documents = null;
3747
$this->facebook = null;
48+
$this->facebook_uri = null;
3849
$this->github = null;
50+
$this->github_uri = null;
3951
$this->instagram = null;
52+
$this->instagram_uri = null;
4053
$this->news_posts = null;
4154
$this->packets = null;
4255
$this->profiledata = null;
56+
$this->reddit = null;
57+
$this->reddit_uri = null;
4358
$this->servers = null;
4459
$this->skype = null;
60+
$this->skype_uri = null;
61+
$this->steam_id = null;
62+
$this->steam_uri = null;
4563
$this->sum_documents = null;
4664
$this->sum_news_posts = null;
4765
$this->sum_packets = null;
4866
$this->sum_servers = null;
4967
$this->twitter = null;
68+
$this->twitter_uri = null;
5069
$this->user = null;
5170
$this->user_est = null;
5271
$this->user_id = null;
5372
$this->user_profile = null;
5473
$this->user_session = null;
5574
$this->website = null;
75+
$this->website_uri = null;
5676
}
5777

5878
}

src/templates/User/View.phtml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,28 @@ require("./header.inc.phtml");
4343
<?php if ($this->getContext()->profiledata) { ?>
4444
<table class="profiledata"><tbody>
4545
<?php if ($this->getContext()->github) { ?>
46-
<tr><th class="right">GitHub:</th><td class="left"><a href="https://github.com/<?php echo rawurlencode($this->getContext()->github) ?>"><?php echo htmlspecialchars($this->getContext()->github, ENT_HTML5, "UTF-8"); ?></a></td></tr>
46+
<tr><th class="right">GitHub:</th><td class="left"><a href="<?php echo $this->getContext()->github_uri; ?>"><?php echo htmlspecialchars($this->getContext()->github, ENT_HTML5, "UTF-8"); ?></a></td></tr>
47+
<?php } ?>
48+
<?php if ($this->getContext()->reddit) { ?>
49+
<tr><th class="right">Reddit:</th><td class="left"><a href="<?php echo $this->getContext()->reddit_uri; ?>"><?php echo htmlspecialchars($this->getContext()->reddit, ENT_HTML5, "UTF-8"); ?></a></td></tr>
50+
<?php } ?>
51+
<?php if ($this->getContext()->steam_id) { ?>
52+
<tr><th class="right">Steam:</th><td class="left"><a href="<?php echo $this->getContext()->steam_uri; ?>"><?php echo htmlspecialchars($this->getContext()->steam_id, ENT_HTML5, "UTF-8"); ?></a></td></tr>
4753
<?php } ?>
4854
<?php if ($this->getContext()->facebook) { ?>
49-
<tr><th class="right">Facebook:</th><td class="left"><a href="https://www.facebook.com/<?php echo rawurlencode($this->getContext()->facebook); ?>"><?php echo htmlspecialchars($this->getContext()->facebook, ENT_HTML5, "UTF-8"); ?></a></td></tr>
55+
<tr><th class="right">Facebook:</th><td class="left"><a href="<?php echo $this->getContext()->facebook_uri; ?>"><?php echo htmlspecialchars($this->getContext()->facebook, ENT_HTML5, "UTF-8"); ?></a></td></tr>
5056
<?php } ?>
5157
<?php if ($this->getContext()->twitter) { ?>
52-
<tr><th class="right">Twitter:</th><td class="left"><a href="https://twitter.com/<?php echo rawurlencode($this->getContext()->twitter); ?>"><?php echo htmlspecialchars($this->getContext()->twitter, ENT_HTML5, "UTF-8"); ?></a></td></tr>
58+
<tr><th class="right">Twitter:</th><td class="left"><a href="<?php echo $this->getContext()->twitter_uri; ?>"><?php echo htmlspecialchars($this->getContext()->twitter, ENT_HTML5, "UTF-8"); ?></a></td></tr>
5359
<?php } ?>
5460
<?php if ($this->getContext()->instagram) { ?>
55-
<tr><th class="right">Instagram:</th><td class="left"><a href="https://instagram.com/<?php echo rawurlencode($this->getContext()->instagram); ?>"><?php echo htmlspecialchars($this->getContext()->instagram, ENT_HTML5, "UTF-8"); ?></a></td></tr>
61+
<tr><th class="right">Instagram:</th><td class="left"><a href="<?php echo $this->getContext()->instagram_uri; ?>"><?php echo htmlspecialchars($this->getContext()->instagram, ENT_HTML5, "UTF-8"); ?></a></td></tr>
5662
<?php } ?>
5763
<?php if ($this->getContext()->skype) { ?>
58-
<tr><th class="right">Skype:</th><td class="left"><a href="skype:<?php echo rawurlencode($this->getContext()->skype); ?>?call"><?php echo htmlspecialchars($this->getContext()->skype, ENT_HTML5, "UTF-8"); ?></a></td></tr>
64+
<tr><th class="right">Skype:</th><td class="left"><a href="skype:<?php echo $this->getContext()->skype_uri; ?>"><?php echo htmlspecialchars($this->getContext()->skype, ENT_HTML5, "UTF-8"); ?></a></td></tr>
5965
<?php } ?>
6066
<?php if ($this->getContext()->website) { ?>
61-
<tr><th class="right">Website:</th><td class="left"><a href="<?php echo $this->getContext()->website; ?>"><?php echo htmlspecialchars($this->getContext()->website, ENT_HTML5, "UTF-8"); ?></a></td></tr>
67+
<tr><th class="right">Website:</th><td class="left"><a href="<?php echo $this->getContext()->website_uri; ?>"><?php echo htmlspecialchars($this->getContext()->website, ENT_HTML5, "UTF-8"); ?></a></td></tr>
6268
<?php } ?>
6369
</tbody></table>
6470
<?php } ?>

0 commit comments

Comments
 (0)