replace array_{add,remove} with array_diff
This commit is contained in:
parent
deb26ff7d3
commit
43ea7fb70c
@ -3,35 +3,6 @@
|
|||||||
* Things which should be in the core API *
|
* Things which should be in the core API *
|
||||||
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove an item from an array
|
|
||||||
*/
|
|
||||||
function array_remove(array $array, $to_remove): array
|
|
||||||
{
|
|
||||||
$array = array_unique($array);
|
|
||||||
$a2 = [];
|
|
||||||
foreach ($array as $existing) {
|
|
||||||
if ($existing != $to_remove) {
|
|
||||||
$a2[] = $existing;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $a2;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds an item to an array.
|
|
||||||
*
|
|
||||||
* Also removes duplicate values from the array.
|
|
||||||
*/
|
|
||||||
function array_add(array $array, $element): array
|
|
||||||
{
|
|
||||||
// Could we just use array_push() ?
|
|
||||||
// http://www.php.net/manual/en/function.array-push.php
|
|
||||||
$array[] = $element;
|
|
||||||
$array = array_unique($array);
|
|
||||||
return $array;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the unique elements of an array, case insensitively
|
* Return the unique elements of an array, case insensitively
|
||||||
*/
|
*/
|
||||||
|
@ -277,8 +277,7 @@ class TagListTheme extends Themelet
|
|||||||
if (!in_array($tag, $tags) && !in_array("-$tag", $tags)) {
|
if (!in_array($tag, $tags) && !in_array("-$tag", $tags)) {
|
||||||
return "";
|
return "";
|
||||||
} else {
|
} else {
|
||||||
$tags = array_remove($tags, $tag);
|
$tags = array_diff($tags, [$tag, "-$tag"]);
|
||||||
$tags = array_remove($tags, "-$tag");
|
|
||||||
return "<a href='".$this->tag_link(join(' ', $tags))."' title='Remove' rel='nofollow'>R</a>";
|
return "<a href='".$this->tag_link(join(' ', $tags))."' title='Remove' rel='nofollow'>R</a>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -288,8 +287,7 @@ class TagListTheme extends Themelet
|
|||||||
if (in_array($tag, $tags)) {
|
if (in_array($tag, $tags)) {
|
||||||
return "";
|
return "";
|
||||||
} else {
|
} else {
|
||||||
$tags = array_remove($tags, "-$tag");
|
$tags = array_diff($tags, ["-$tag"]) + [$tag];
|
||||||
$tags = array_add($tags, $tag);
|
|
||||||
return "<a href='".$this->tag_link(join(' ', $tags))."' title='Add' rel='nofollow'>A</a>";
|
return "<a href='".$this->tag_link(join(' ', $tags))."' title='Add' rel='nofollow'>A</a>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -299,8 +297,7 @@ class TagListTheme extends Themelet
|
|||||||
if (in_array("-$tag", $tags)) {
|
if (in_array("-$tag", $tags)) {
|
||||||
return "";
|
return "";
|
||||||
} else {
|
} else {
|
||||||
$tags = array_remove($tags, $tag);
|
$tags = array_diff($tags, [$tag]) + ["-$tag"];
|
||||||
$tags = array_add($tags, "-$tag");
|
|
||||||
return "<a href='".$this->tag_link(join(' ', $tags))."' title='Subtract' rel='nofollow'>S</a>";
|
return "<a href='".$this->tag_link(join(' ', $tags))."' title='Subtract' rel='nofollow'>S</a>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user