Last active
December 16, 2015 10:18
-
-
Save luniki/5418732 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* | |
**/ | |
class UserRoute implements APIRoute | |
{ | |
/** | |
* | |
**/ | |
public function describeRoutes() | |
{ | |
return array( | |
'/user(/:user_id)' => _('Nutzerdaten'), | |
// ... | |
); | |
} | |
// ... | |
public function routes(&$router) | |
{ | |
// | |
$router->get('/user(/:user_id)', function ($user_id) use ($router) | |
{ | |
$user_id = $user_id ?: $GLOBALS['user']->id; | |
$user = User::find($user_id); | |
if (!$user) { | |
$router->halt(404, sprintf('User %s not found', $user_id)); | |
return; | |
} | |
$visibilities = get_local_visibility_by_id($user_id, 'homepage'); | |
if (is_array(json_decode($visibilities, true))) { | |
$visibilities = json_decode($visibilities, true); | |
} else { | |
$visibilities = array(); | |
} | |
$get_field = function ($field, $visibility) use ($user_id, $user, $visibilities) { | |
if (!$user[$field] | |
|| !is_element_visible_for_user($GLOBALS['user']->id, $user_id, $visibilities[$visibility])) | |
{ | |
return ''; | |
} | |
return $user[$field]; | |
}; | |
$avatar = function ($size) use ($user_id, $visibilities) { | |
static $avatar; | |
if (!$avatar) { | |
$avatar_id = is_element_visible_for_user($GLOBALS['user']->id, $user_id, $visibilities['picture']) | |
? $user_id : 'nobody'; | |
$avatar = Avatar::getAvatar($avatar_id); | |
} | |
return $avatar->getURL($size); | |
}; | |
$user = array( | |
'user_id' => $user_id, | |
'username' => $user['username'], | |
'perms' => $user['perms'], | |
'title_pre' => $user['title_front'], | |
'forename' => $user['Vorname'], | |
'lastname' => $user['Nachname'], | |
'title_post' => $user['title_rear'], | |
'email' => get_visible_email($user_id), | |
'avatar_small' => $avatar(Avatar::SMALL), | |
'avatar_medium' => $avatar(Avatar::MEDIUM), | |
'avatar_normal' => $avatar(Avatar::NORMAL), | |
'phone' => $get_field('privatnr', 'private_phone'), | |
'homepage' => $get_field('Home', 'homepage'), | |
'privadr' => strip_tags($get_field('privadr', 'privadr')), | |
); | |
$query = "SELECT value | |
FROM user_config | |
WHERE field = ? AND user_id = ?"; | |
$statement = DBManager::get()->prepare($query); | |
$statement->execute(array('SKYPE_NAME', $user_id)); | |
$user['skype'] = $statement->fetchColumn() ?: ''; | |
$statement->closeCursor(); | |
if ($user['skype']) { | |
$statement->execute(array('SKYPE_ONLINE_STATUS', $user_id)); | |
$user['skype_show'] = (bool)$statement->fetchColumn(); | |
} else { | |
$user['skype_show'] = false; | |
} | |
$router->render(compact('user')); | |
}); | |
// ... | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* | |
**/ | |
class UserRoute implements APIRoute | |
{ | |
public function describeRoutes() | |
{ | |
// ??? | |
} | |
// ... | |
/** | |
* @GET "/user(/:user_id)" | |
*/ | |
public function getUser($user_id) | |
{ | |
$user_id = $user_id ?: $GLOBALS['user']->id; | |
$user = User::find($user_id); | |
if (!$user) { | |
throw new APIException(404, sprintf('User %s not found', $user_id)); | |
} | |
return $user; | |
} | |
} | |
class User { | |
static function find($id) { | |
// ... | |
} | |
function toJSON() | |
{ | |
return array( | |
'user_id' => $user_id, | |
'username' => $user['username'], | |
'perms' => $user['perms'], | |
'title_pre' => $user['title_front'], | |
'forename' => $user['Vorname'], | |
'lastname' => $user['Nachname'], | |
'title_post' => $user['title_rear'], | |
'email' => get_visible_email($user_id), | |
'avatar_small' => $avatar(Avatar::SMALL), | |
'avatar_medium' => $avatar(Avatar::MEDIUM), | |
'avatar_normal' => $avatar(Avatar::NORMAL), | |
'phone' => $get_field('privatnr', 'private_phone'), | |
'homepage' => $get_field('Home', 'homepage'), | |
'privadr' => strip_tags($get_field('privadr', 'privadr')), | |
); | |
} | |
function toXML() | |
{ | |
return ???; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment