From 95122983287d1f16924c666ba018482c453e17aa Mon Sep 17 00:00:00 2001 From: Marcos de Oliveira Date: Tue, 6 Apr 2021 11:20:40 -0300 Subject: [PATCH] Add username column to links table * Create `array_insert` function This was needed because array_splice does not work on associative arrays. * Add hook functions to insert username column and cells * Add javascript to increment number of columns in HTML --- authMgrPlus/plugin.php | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/authMgrPlus/plugin.php b/authMgrPlus/plugin.php index ddcff1e..c049b35 100644 --- a/authMgrPlus/plugin.php +++ b/authMgrPlus/plugin.php @@ -624,4 +624,48 @@ function amp_is_valid_user() { return $valid; } + +yourls_add_action( 'html_footer', 'amp_format_table_javascript' ); + +function amp_format_table_javascript() { + echo << +if($("body").hasClass("index")) { + document.querySelector("#main_table tfoot th").colSpan = 7; + document.querySelector("#nourl_found td").colSpan = 7; +} + + +JS; +} + +function array_insert($array, $position, $insert_array) { + $first_array = array_splice($array, 0, $position); + $array = array_merge($first_array, $insert_array, $array); + + return $array; +} + +yourls_add_filter('table_head_cells', 'amp_username_table_head'); +function amp_username_table_head( $cells ) { + $user_head = array( 'username' => 'Username' ); + $cells = array_insert($cells, 5, $user_head); + return $cells; +} + +yourls_add_filter('table_add_row_cell_array', 'amp_add_user_row'); +function amp_add_user_row( $cells, $keyword ) { + $username = amp_keyword_owner($keyword); + $user_cell = array( + 'username' => array( + 'template' => '%username%', + 'username' => $username, + ) + ); + $cells = array_insert($cells, 5, $user_cell); + + return $cells; +} + ?>