/**
* Salted, hashed passwords are stored in the DB.
*/
-function common_munge_password($password, $id, Profile $profile=null)
+function common_munge_password($password, Profile $profile=null)
{
$hashed = null;
}
if ($user instanceof User && !empty($password)) {
- if (0 == strcmp(common_munge_password($password, $user->id),
- $user->password)) {
+ if (0 == strcmp(common_munge_password($password, $user->getProfile()), $user->password)) {
//internal checking passed
$authenticatedUser = $user;
}
* @param Notice $notice in-progress or complete Notice object for context
* @return string partially-rendered HTML
*/
-function common_linkify_mentions($text, $notice)
+function common_linkify_mentions($text, Notice $notice)
{
$mentions = common_find_mentions($text, $notice);
return $text;
}
-function common_linkify_mention($mention)
+function common_linkify_mention(array $mention)
{
$output = null;
*/
function common_find_mentions($text, Notice $notice)
{
- try {
- $sender = Profile::getKV('id', $notice->profile_id);
- } catch (NoProfileException $e) {
- return array();
- }
+ // The getProfile call throws NoProfileException on failure
+ $sender = $notice->getProfile();
$mentions = array();
// Is it a reply?
- if ($notice instanceof Notice) {
- try {
- $origNotice = $notice->getParent();
- $origAuthor = $origNotice->getProfile();
+ try {
+ $origNotice = $notice->getParent();
+ $origAuthor = $origNotice->getProfile();
- $ids = $origNotice->getReplies();
+ $ids = $origNotice->getReplies();
- foreach ($ids as $id) {
- $repliedTo = Profile::getKV('id', $id);
- if ($repliedTo instanceof Profile) {
- $origMentions[$repliedTo->nickname] = $repliedTo;
- }
+ foreach ($ids as $id) {
+ try {
+ $repliedTo = Profile::getByID($id);
+ $origMentions[$repliedTo->getNickname()] = $repliedTo;
+ } catch (NoResultException $e) {
+ // continue foreach
}
- } catch (NoProfileException $e) {
- common_log(LOG_WARNING, sprintf('Notice %d author profile id %d does not exist', $origNotice->id, $origNotice->profile_id));
- } catch (ServerException $e) {
- // Probably just no parent. Should get a specific NoParentException
- } catch (Exception $e) {
- common_log(LOG_WARNING, __METHOD__ . ' got exception ' . get_class($e) . ' : ' . $e->getMessage());
}
+ } catch (NoParentNoticeException $e) {
+ // It wasn't a reply to anything, so we can't harvest nickname-relations.
}
$matches = common_find_mentions_raw($text);
function common_path($relative, $ssl=false, $addSession=true)
{
- $pathpart = (common_config('site', 'path')) ? common_config('site', 'path')."/" : '';
+ $pathpart = (!empty(common_config('site', 'path'))) ? common_config('site', 'path') . '/' : '';
if (($ssl && (common_config('site', 'ssl') === 'sometimes'))
|| GNUsocial::isHTTPS()
$text = html_entity_decode(strip_tags($html), ENT_QUOTES, 'UTF-8');
return $trim ? trim($text) : $text;
}
+
+function html_sprintf()
+{
+ $args = func_get_args();
+ for ($i=1; $i<count($args); $i++) {
+ $args[$i] = htmlspecialchars($args[$i]);
+ }
+ return call_user_func_array('sprintf', $args);
+}