Modernise some function calls etc, to newer GNU social standards

This commit is contained in:
Mikael Nordfeldth 2017-04-25 21:03:43 +02:00
parent 5f24fc0986
commit c71600c144

View File

@ -111,52 +111,16 @@ class BlacklistPlugin extends Plugin
} }
} }
/**
* Hook registration to prevent blacklisted homepages or nicknames
*
* Throws an exception if there's a blacklisted homepage or nickname.
*
* @param Action $action Action being called (usually register)
*
* @return boolean hook value
*/
function onStartRegisterUser(&$user, &$profile)
{
$homepage = strtolower($profile->homepage);
if (!empty($homepage)) {
if (!$this->_checkUrl($homepage)) {
// TRANS: Validation failure for URL. %s is the URL.
$msg = sprintf(_m("You may not register with homepage \"%s\"."),
$homepage);
throw new ClientException($msg);
}
}
$nickname = strtolower($profile->nickname);
if (!empty($nickname)) {
if (!$this->_checkNickname($nickname)) {
// TRANS: Validation failure for nickname. %s is the nickname.
$msg = sprintf(_m("You may not register with nickname \"%s\"."),
$nickname);
throw new ClientException($msg);
}
}
return true;
}
/** /**
* Hook profile update to prevent blacklisted homepages or nicknames * Hook profile update to prevent blacklisted homepages or nicknames
* *
* Throws an exception if there's a blacklisted homepage or nickname. * Throws an exception if there's a blacklisted homepage or nickname.
* *
* @param Action $action Action being called (usually register) * @param ManagedAction $action Action being called (usually register)
* *
* @return boolean hook value * @return boolean hook value
*/ */
function onStartProfileSaveForm($action) function onStartProfileSaveForm(ManagedAction $action)
{ {
$homepage = strtolower($action->trimmed('homepage')); $homepage = strtolower($action->trimmed('homepage'));
@ -192,7 +156,7 @@ class BlacklistPlugin extends Plugin
* *
* @return boolean hook value * @return boolean hook value
*/ */
function onStartNoticeSave(&$notice) public function onStartNoticeSave(&$notice)
{ {
common_replace_urls_callback($notice->content, common_replace_urls_callback($notice->content,
array($this, 'checkNoticeUrl')); array($this, 'checkNoticeUrl'));
@ -328,7 +292,7 @@ class BlacklistPlugin extends Plugin
* *
* @return boolean hook value * @return boolean hook value
*/ */
function onEndAdminPanelNav($nav) function onEndAdminPanelNav(Menu $nav)
{ {
if (AdminPanelAction::canAdmin('blacklist')) { if (AdminPanelAction::canAdmin('blacklist')) {
@ -346,75 +310,76 @@ class BlacklistPlugin extends Plugin
return true; return true;
} }
function onEndDeleteUserForm($action, $user) function onEndDeleteUserForm(HTMLOutputter $out, User $user)
{ {
$cur = common_current_user(); $scoped = $out->getScoped();
if (empty($cur) || !$cur->hasRight(Right::CONFIGURESITE)) { if ($scoped === null || !$scoped->hasRight(Right::CONFIGURESITE)) {
return; return true;
} }
$profile = $user->getProfile();
if (empty($profile)) { try {
return; $profile = $user->getProfile();
} catch (UserNoProfileException $e) {
return true;
} }
$action->elementStart('ul', 'form_data'); $out->elementStart('ul', 'form_data');
$action->elementStart('li'); $out->elementStart('li');
$this->checkboxAndText($action, $this->checkboxAndText($out,
'blacklistnickname', 'blacklistnickname',
// TRANS: Checkbox label in the blacklist user form. // TRANS: Checkbox label in the blacklist user form.
_m('Add this nickname pattern to blacklist'), _m('Add this nickname pattern to blacklist'),
'blacklistnicknamepattern', 'blacklistnicknamepattern',
$this->patternizeNickname($user->nickname)); $this->patternizeNickname($profile->getNickname()));
$action->elementEnd('li'); $out->elementEnd('li');
if (!empty($profile->homepage)) { if (!empty($profile->getHomepage())) {
$action->elementStart('li'); $out->elementStart('li');
$this->checkboxAndText($action, $this->checkboxAndText($out,
'blacklisthomepage', 'blacklisthomepage',
// TRANS: Checkbox label in the blacklist user form. // TRANS: Checkbox label in the blacklist user form.
_m('Add this homepage pattern to blacklist'), _m('Add this homepage pattern to blacklist'),
'blacklisthomepagepattern', 'blacklisthomepagepattern',
$this->patternizeHomepage($profile->homepage)); $this->patternizeHomepage($profile->getHomepage()));
$action->elementEnd('li'); $out->elementEnd('li');
} }
$action->elementEnd('ul'); $out->elementEnd('ul');
} }
function onEndDeleteUser($action, $user) function onEndDeleteUser(HTMLOutputter $out, User $user)
{ {
if ($action->boolean('blacklisthomepage')) { if ($out->boolean('blacklisthomepage')) {
$pattern = $action->trimmed('blacklisthomepagepattern'); $pattern = $out->trimmed('blacklisthomepagepattern');
Homepage_blacklist::ensurePattern($pattern); Homepage_blacklist::ensurePattern($pattern);
} }
if ($action->boolean('blacklistnickname')) { if ($out->boolean('blacklistnickname')) {
$pattern = $action->trimmed('blacklistnicknamepattern'); $pattern = $out->trimmed('blacklistnicknamepattern');
Nickname_blacklist::ensurePattern($pattern); Nickname_blacklist::ensurePattern($pattern);
} }
return true; return true;
} }
function checkboxAndText($action, $checkID, $label, $textID, $value) function checkboxAndText(HTMLOutputter $out, $checkID, $label, $textID, $value)
{ {
$action->element('input', array('name' => $checkID, $out->element('input', array('name' => $checkID,
'type' => 'checkbox', 'type' => 'checkbox',
'class' => 'checkbox', 'class' => 'checkbox',
'id' => $checkID)); 'id' => $checkID));
$action->text(' '); $out->text(' ');
$action->element('label', array('class' => 'checkbox', $out->element('label', array('class' => 'checkbox',
'for' => $checkID), 'for' => $checkID),
$label); $label);
$action->text(' '); $out->text(' ');
$action->element('input', array('name' => $textID, $out->element('input', array('name' => $textID,
'type' => 'text', 'type' => 'text',
'id' => $textID, 'id' => $textID,
'value' => $value)); 'value' => $value));