mirror of
https://github.com/friendica/friendica
synced 2024-11-10 05:42:54 +00:00
Merge pull request #3986 from MrPetovan/task/admin-block-list
Admin remote contact block list
This commit is contained in:
commit
2ca03acb45
30 changed files with 736 additions and 387 deletions
|
@ -1104,7 +1104,8 @@ class dba {
|
|||
*
|
||||
* $data = dba::select($table, $fields, $condition, $params);
|
||||
*/
|
||||
public static function select($table, $fields = array(), $condition = array(), $params = array()) {
|
||||
public static function select($table, array $fields = [], array $condition = [], array $params = [])
|
||||
{
|
||||
if ($table == '') {
|
||||
return false;
|
||||
}
|
||||
|
@ -1115,17 +1116,7 @@ class dba {
|
|||
$select_fields = "*";
|
||||
}
|
||||
|
||||
if (count($condition) > 0) {
|
||||
$array_element = each($condition);
|
||||
$array_key = $array_element['key'];
|
||||
if (is_int($array_key)) {
|
||||
$condition_string = " WHERE ".array_shift($condition);
|
||||
} else {
|
||||
$condition_string = " WHERE `".implode("` = ? AND `", array_keys($condition))."` = ?";
|
||||
}
|
||||
} else {
|
||||
$condition_string = "";
|
||||
}
|
||||
$condition_string = self::buildCondition($condition);
|
||||
|
||||
$param_string = '';
|
||||
$single_row = false;
|
||||
|
@ -1147,6 +1138,11 @@ class dba {
|
|||
$single_row = ($params['limit'] == 1);
|
||||
}
|
||||
|
||||
if (isset($params['limit']) && is_array($params['limit'])) {
|
||||
$param_string .= " LIMIT ".intval($params['limit'][0]).", ".intval($params['limit'][1]);
|
||||
$single_row = ($params['limit'][1] == 1);
|
||||
}
|
||||
|
||||
if (isset($params['only_query']) && $params['only_query']) {
|
||||
$single_row = !$params['only_query'];
|
||||
}
|
||||
|
@ -1164,6 +1160,71 @@ class dba {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Counts the rows from a table satisfying the provided condition
|
||||
*
|
||||
* @param string $table Table name
|
||||
* @param array $condition array of fields for condition
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* Example:
|
||||
* $table = "item";
|
||||
*
|
||||
* $condition = ["uid" => 1, "network" => 'dspr'];
|
||||
* or:
|
||||
* $condition = ["`uid` = ? AND `network` IN (?, ?)", 1, 'dfrn', 'dspr'];
|
||||
*
|
||||
* $count = dba::count($table, $condition);
|
||||
*/
|
||||
public static function count($table, array $condition = [])
|
||||
{
|
||||
if ($table == '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$condition_string = self::buildCondition($condition);
|
||||
|
||||
$sql = "SELECT COUNT(*) AS `count` FROM `".$table."`".$condition_string;
|
||||
|
||||
$row = self::fetch_first($sql, $condition);
|
||||
|
||||
return $row['count'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the SQL condition string built from the provided condition array
|
||||
*
|
||||
* This function operates with two modes.
|
||||
* - Supplied with a filed/value associative array, it builds simple strict
|
||||
* equality conditions linked by AND.
|
||||
* - Supplied with a flat list, the first element is the condition string and
|
||||
* the following arguments are the values to be interpolated
|
||||
*
|
||||
* $condition = ["uid" => 1, "network" => 'dspr'];
|
||||
* or:
|
||||
* $condition = ["`uid` = ? AND `network` IN (?, ?)", 1, 'dfrn', 'dspr'];
|
||||
*
|
||||
* In either case, the provided array is left with the parameters only
|
||||
*
|
||||
* @param array $condition
|
||||
* @return string
|
||||
*/
|
||||
private static function buildCondition(array &$condition = [])
|
||||
{
|
||||
$condition_string = '';
|
||||
if (count($condition) > 0) {
|
||||
$array_element = each($condition);
|
||||
$array_key = $array_element['key'];
|
||||
if (is_int($array_key)) {
|
||||
$condition_string = " WHERE ".array_shift($condition);
|
||||
} else {
|
||||
$condition_string = " WHERE `".implode("` = ? AND `", array_keys($condition))."` = ?";
|
||||
}
|
||||
}
|
||||
|
||||
return $condition_string;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Fills an array with data from a query
|
||||
|
|
|
@ -120,48 +120,90 @@ function load_translation_table($lang) {
|
|||
|
||||
}}
|
||||
|
||||
// translate string if translation exists
|
||||
|
||||
if (! function_exists('t')) {
|
||||
function t($s) {
|
||||
|
||||
/**
|
||||
* @brief Return the localized version of the provided string with optional string interpolation
|
||||
*
|
||||
* This function takes a english string as parameter, and if a localized version
|
||||
* exists for the current language, substitutes it before performing an eventual
|
||||
* string interpolation (sprintf) with additional optional arguments.
|
||||
*
|
||||
* Usages:
|
||||
* - t('This is an example')
|
||||
* - t('URL %s returned no result', $url)
|
||||
* - t('Current version: %s, new version: %s', $current_version, $new_version)
|
||||
*
|
||||
* @param string $s
|
||||
* @return string
|
||||
*/
|
||||
function t($s)
|
||||
{
|
||||
$a = get_app();
|
||||
|
||||
if (x($a->strings,$s)) {
|
||||
if (x($a->strings, $s)) {
|
||||
$t = $a->strings[$s];
|
||||
return is_array($t)?$t[0]:$t;
|
||||
$s = is_array($t) ? $t[0] : $t;
|
||||
}
|
||||
if (func_num_args() > 1) {
|
||||
$args = array_slice(func_get_args(), 1);
|
||||
$s = @vsprintf($s, $args);
|
||||
}
|
||||
return $s;
|
||||
}}
|
||||
|
||||
if (! function_exists('tt')){
|
||||
function tt($singular, $plural, $count){
|
||||
return $s;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the localized version of a singular/plural string with optional string interpolation
|
||||
*
|
||||
* This function takes two english strings as parameters, singular and plural, as
|
||||
* well as a count. If a localized version exists for the current language, they
|
||||
* are used instead. Discrimination between singular and plural is done using the
|
||||
* localized function if any or the default one. Finally, a string interpolation
|
||||
* is performed using the count as parameter.
|
||||
*
|
||||
* Usages:
|
||||
* - tt('Like', 'Likes', $count)
|
||||
* - tt("%s user deleted", "%s users deleted", count($users))
|
||||
*
|
||||
* @global type $lang
|
||||
* @param string $singular
|
||||
* @param string $plural
|
||||
* @param int $count
|
||||
* @return string
|
||||
*/
|
||||
function tt($singular, $plural, $count)
|
||||
{
|
||||
global $lang;
|
||||
$a = get_app();
|
||||
|
||||
if (x($a->strings,$singular)) {
|
||||
if (x($a->strings, $singular)) {
|
||||
$t = $a->strings[$singular];
|
||||
$f = 'string_plural_select_' . str_replace('-','_',$lang);
|
||||
if (! function_exists($f))
|
||||
$f = 'string_plural_select_default';
|
||||
$k = $f($count);
|
||||
return is_array($t)?$t[$k]:$t;
|
||||
if (is_array($t)) {
|
||||
$plural_function = 'string_plural_select_' . str_replace('-', '_', $lang);
|
||||
if (function_exists($plural_function)) {
|
||||
$plural_function = 'string_plural_select_default';
|
||||
}
|
||||
$i = $plural_function($count);
|
||||
$s = $t[$i];
|
||||
} else {
|
||||
$s = $t;
|
||||
}
|
||||
} elseif (string_plural_select_default($count)) {
|
||||
$s = $plural;
|
||||
} else {
|
||||
$s = $singular;
|
||||
}
|
||||
|
||||
if ($count!=1){
|
||||
return $plural;
|
||||
} else {
|
||||
return $singular;
|
||||
}
|
||||
}}
|
||||
$s = @sprintf($s, $count);
|
||||
|
||||
return $s;
|
||||
}
|
||||
|
||||
// provide a fallback which will not collide with
|
||||
// a function defined in any language file
|
||||
|
||||
if (! function_exists('string_plural_select_default')) {
|
||||
function string_plural_select_default($n) {
|
||||
return ($n != 1);
|
||||
}}
|
||||
function string_plural_select_default($n)
|
||||
{
|
||||
return $n != 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
715
mod/admin.php
715
mod/admin.php
File diff suppressed because it is too large
Load diff
|
@ -822,7 +822,33 @@ class Contact extends BaseObject
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief Updates the avatar links in a contact only if needed
|
||||
* @brief Blocks a contact
|
||||
*
|
||||
* @param int $uid
|
||||
* @return bool
|
||||
*/
|
||||
public static function block($uid)
|
||||
{
|
||||
$return = dba::update('contact', ['blocked' => true], ['id' => $uid]);
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Unblocks a contact
|
||||
*
|
||||
* @param int $uid
|
||||
* @return bool
|
||||
*/
|
||||
public static function unblock($uid)
|
||||
{
|
||||
$return = dba::update('contact', ['blocked' => false], ['id' => $uid]);
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Updates the avatar links in a contact only if needed
|
||||
*
|
||||
* @param string $avatar Link to avatar picture
|
||||
* @param int $uid User id of contact owner
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @brief tool to block an account from the node
|
||||
*
|
||||
|
@ -17,49 +16,39 @@
|
|||
* Author: Tobias Diekershoff
|
||||
*
|
||||
* License: AGPLv3 or later, same as Friendica
|
||||
**/
|
||||
|
||||
*/
|
||||
if ($argc != 2 || $argv[1] == "-h" || $argv[1] == "--help" || $argv[1] == "-?") {
|
||||
echo "Usage: ".$argv[0]." [-h|profile_url]\r\n";
|
||||
echo "Usage: " . $argv[0] . " [-h|profile_url]\r\n";
|
||||
echo " -h, -?, --help ... show this help\r\n";
|
||||
echo " profile_url ...... The URL of the profile you want to silence\r\n";
|
||||
echo "\r\n";
|
||||
echo "Example: block bob@example.com\r\n";
|
||||
echo "$> ".$argv[0]." https://example.com/profiles/bob\r\n";
|
||||
echo "$> " . $argv[0] . " https://example.com/profiles/bob\r\n";
|
||||
echo "\r\n";
|
||||
exit(0);
|
||||
}
|
||||
|
||||
use Friendica\Database\DBM;
|
||||
use Friendica\Network\Probe;
|
||||
use Friendica\BaseObject;
|
||||
use Friendica\Object\Contact;
|
||||
|
||||
require_once 'boot.php';
|
||||
require_once 'include/dba.php';
|
||||
require_once 'include/text.php';
|
||||
$a = get_app();
|
||||
require_once '.htconfig.php';
|
||||
|
||||
$a = get_app();;
|
||||
BaseObject::setApp($a);
|
||||
|
||||
require_once '.htconfig.php';
|
||||
dba::connect($db_host, $db_user, $db_pass, $db_data);
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
|
||||
/**
|
||||
* 1. make nurl from last parameter
|
||||
* 2. check DB (contact) if there is a contact with uid=0 and that nurl, get the ID
|
||||
* 3. set the flag hidden=1 for the contact entry with the found ID
|
||||
**/
|
||||
$net = Probe::uri($argv[1]);
|
||||
if (in_array($net['network'], array(NETWORK_PHANTOM, NETWORK_MAIL))) {
|
||||
echo 'This account seems not to exist.';
|
||||
$contact_id = Contact::getIdForURL($argv[1], 0);
|
||||
if (!$contact_id) {
|
||||
echo t('Could not find any contact entry for this URL (%s)', $nurl);
|
||||
echo "\r\n";
|
||||
exit(1);
|
||||
}
|
||||
$nurl = normalise_link($net['url']);
|
||||
$r = dba::select('contact', array('id'), array('nurl' => $nurl, 'uid' => 0), array('limit' => 1));
|
||||
if (DBM::is_result($r)) {
|
||||
dba::update('contact', array('blocked' => true), array('id' => $r['id']));
|
||||
echo "NOTICE: The account should be blocked from the node now\r\n";
|
||||
} else {
|
||||
echo "NOTICE: Could not find any entry for this URL (".$nurl.")\r\n";
|
||||
}
|
||||
|
||||
?>
|
||||
Contact::block($contact_id);
|
||||
echo t('The contact has been blocked from the node');
|
||||
echo "\r\n";
|
||||
exit(0);
|
||||
|
|
63
view/templates/admin/contactblock.tpl
Normal file
63
view/templates/admin/contactblock.tpl
Normal file
|
@ -0,0 +1,63 @@
|
|||
<script>
|
||||
function selectall(cls) {
|
||||
$('.' + cls).prop('checked', true);
|
||||
return false;
|
||||
}
|
||||
function selectnone(cls) {
|
||||
$('.' + cls).prop('checked', false);
|
||||
return false;
|
||||
}
|
||||
</script>
|
||||
<div id="adminpage">
|
||||
<h1>{{$title}} - {{$page}}</h1>
|
||||
<p>{{$description}}</p>
|
||||
<form action="{{$baseurl}}/admin/contactblock" method="post">
|
||||
<input type="hidden" name="form_security_token" value="{{$form_security_token}}">
|
||||
|
||||
<h3>{{$h_contacts}}</h3>
|
||||
{{if $contacts}}
|
||||
<table id="contactblock">
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
{{foreach $th_contacts as $th}}
|
||||
<th>
|
||||
{{$th}}
|
||||
</th>
|
||||
{{/foreach}}
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{foreach $contacts as $contact}}
|
||||
<tr>
|
||||
<td class="checkbox"><input type="checkbox" class="contacts_ckbx" id="id_contact_{{$contact.id}}" name="contacts[]" value="{{$contact.id}}"/></td>
|
||||
<td><img class="icon" src="{{$contact.micro}}" alt="{{$contact.nickname}}" title="{{$contact.nickname}}"></td>
|
||||
<td class="name">{{$contact.name}}</td>
|
||||
<td class="addr">{{$contact.addr}}</td>
|
||||
<td class="addr"><a href="{{$contact.url}}" title="{{$contact.nickname}}" >{{$contact.url}}</a></td>
|
||||
</tr>
|
||||
{{/foreach}}
|
||||
</tbody>
|
||||
</table>
|
||||
<p><a href="#" onclick="return selectall('contacts_ckbx');">{{$select_all}}</a> | <a href="#" onclick="return selectnone('contacts_ckbx');">{{$select_none}}</a></p>
|
||||
{{$paginate}}
|
||||
<div class="submit"><input type="submit" name="page_contactblock_unblock" value="{{$unblock|escape:'html'}}" /></div>
|
||||
{{else}}
|
||||
<p>{{$no_data|escape:'html'}}</p>
|
||||
{{/if}}
|
||||
</form>
|
||||
|
||||
<h3>{{$h_newblock}}</h3>
|
||||
<form action="{{$baseurl}}/admin/contactblock" method="post">
|
||||
<input type="hidden" name="form_security_token" value="{{$form_security_token}}">
|
||||
<table id="contactblock">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>{{include file="field_input.tpl" field=$contacturl}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="submit"><input type="submit" name="page_contactblock_block" value="{{$submit|escape:'html'}}" /></div>
|
||||
</form>
|
||||
</div>
|
31
view/theme/frio/js/mod_admin.js
Normal file
31
view/theme/frio/js/mod_admin.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
/**
|
||||
* @brief Javascript for the admin module
|
||||
*/
|
||||
$(function() {
|
||||
$('body').on('click', '.selectall', function() {
|
||||
selectall($(this).data('selectAll'));
|
||||
});
|
||||
$('body').on('click', '.selectnone', function() {
|
||||
selectnone($(this).data('selectNone'));
|
||||
});
|
||||
|
||||
$('body').on('change', 'input[type=checkbox].select', function() {
|
||||
$this = $(this);
|
||||
if ($this.prop('checked')) {
|
||||
selectall($this.data('selectClass'));
|
||||
$this.attr('title', $this.data('selectNone'));
|
||||
} else {
|
||||
selectnone($this.data('selectClass'));
|
||||
$this.attr('title', $this.data('selectAll'));
|
||||
}
|
||||
});
|
||||
|
||||
function selectall(cls) {
|
||||
$('.' + cls).prop('checked', true);
|
||||
return false;
|
||||
}
|
||||
function selectnone(cls) {
|
||||
$('.' + cls).prop('checked', false);
|
||||
return false;
|
||||
}
|
||||
});
|
60
view/theme/frio/templates/admin/contactblock.tpl
Normal file
60
view/theme/frio/templates/admin/contactblock.tpl
Normal file
|
@ -0,0 +1,60 @@
|
|||
<script type="text/javascript" src="view/theme/frio/js/mod_admin.js"></script>
|
||||
<div id="adminpage">
|
||||
<h1>{{$title}} - {{$page}}</h1>
|
||||
<p>{{$description}}</p>
|
||||
<form action="{{$baseurl}}/admin/contactblock" method="post">
|
||||
<input type="hidden" name="form_security_token" value="{{$form_security_token}}">
|
||||
|
||||
<h3>{{$h_contacts}}</h3>
|
||||
{{if $contacts}}
|
||||
<table id="contactblock" class="table table-condensed table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><input type="checkbox" class="select contacts_ckbx" data-select-class="contacts_ckbx" data-select-all="{{$select_all}}" data-select-none="{{$select_none}}" title="{{$select_all}}"/></th>
|
||||
{{foreach $th_contacts as $th}}
|
||||
<th>
|
||||
{{$th}}
|
||||
</th>
|
||||
{{/foreach}}
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{foreach $contacts as $contact}}
|
||||
<tr>
|
||||
<td><input type="checkbox" class="contacts_ckbx" id="id_contact_{{$contact.id}}" name="contacts[]" value="{{$contact.id}}"/></td>
|
||||
<td><img class="icon" src="{{$contact.micro}}" alt="{{$contact.nickname}}" title="{{$contact.addr}}"></td>
|
||||
<td class="name">{{$contact.name}}</td>
|
||||
<td class="addr" colspan="2"><a href="{{$contact.url}}" title="{{$contact.addr}}" >{{$contact.url}}</a></td>
|
||||
</tr>
|
||||
{{/foreach}}
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td><input type="checkbox" class="select contacts_ckbx" data-select-class="contacts_ckbx" data-select-all="{{$select_all}}" data-select-none="{{$select_none}}" title="{{$select_all}}"/></td>
|
||||
<td colspan="3">
|
||||
{{$total_contacts}}
|
||||
</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
<div class="submit"><button type="submit" class="btn btn-small btn-default" name="page_contactblock_unblock" value="1">{{$unblock|escape:'html'}}</button></div>
|
||||
{{$paginate}}
|
||||
{{else}}
|
||||
<p>{{$no_data|escape:'html'}}</p>
|
||||
{{/if}}
|
||||
</form>
|
||||
|
||||
<h3>{{$h_newblock}}</h3>
|
||||
<form action="{{$baseurl}}/admin/contactblock" method="post">
|
||||
<input type="hidden" name="form_security_token" value="{{$form_security_token}}">
|
||||
<table id="contactblock">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>{{include file="field_input.tpl" field=$contacturl}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="submit"><button type="submit" class="btn btn-primary" name="page_contactblock_block" value="1">{{$submit|escape:'html'}}</button></div>
|
||||
</form>
|
||||
</div>
|
Loading…
Reference in a new issue