add user pref on table filters and cols, fix js
This commit is contained in:
parent
a6fdf10759
commit
98c61a0c6e
6 changed files with 168 additions and 89 deletions
|
@ -2,6 +2,10 @@ xxx.xx.xx
|
||||||
- Never fix breaking comments or complexe public url
|
- Never fix breaking comments or complexe public url
|
||||||
- [ ] Add public page of the list of know urls and in/visible status
|
- [ ] Add public page of the list of know urls and in/visible status
|
||||||
- [ ] Add passworded links
|
- [ ] Add passworded links
|
||||||
|
- fix permissions
|
||||||
|
- fix js load
|
||||||
|
- add user pref on table cols
|
||||||
|
- add user pref on filters (dc 2.20)
|
||||||
|
|
||||||
2021.09.16
|
2021.09.16
|
||||||
- remove deprecated external service
|
- remove deprecated external service
|
||||||
|
|
40
_admin.php
40
_admin.php
|
@ -25,11 +25,14 @@ $_menu['Plugins']->addItem(
|
||||||
$core->adminurl->get('admin.plugin.kUtRL'),
|
$core->adminurl->get('admin.plugin.kUtRL'),
|
||||||
dcPage::getPF('kUtRL/icon.png'),
|
dcPage::getPF('kUtRL/icon.png'),
|
||||||
preg_match('/' . preg_quote($core->adminurl->get('admin.plugin.kUtRL')) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
|
preg_match('/' . preg_quote($core->adminurl->get('admin.plugin.kUtRL')) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
|
||||||
$core->auth->check('admin', $core->blog->id));
|
$core->auth->check('admin', $core->blog->id)
|
||||||
|
);
|
||||||
|
|
||||||
# Admin behaviors
|
# Admin behaviors
|
||||||
if ($core->blog->settings->kUtRL->kutrl_active) {
|
if ($core->blog->settings->kUtRL->kutrl_active) {
|
||||||
$core->addBehavior('adminDashboardFavorites', ['adminKutrl', 'antispamDashboardFavorites']);
|
$core->addBehavior('adminDashboardFavorites', ['adminKutrl', 'antispamDashboardFavorites']);
|
||||||
|
$core->addBehavior('adminColumnsLists', ['adminKutrl', 'adminColumnsLists']);
|
||||||
|
$core->addBehavior('adminSortsLists', ['adminKutrl', 'adminSortsLists']);
|
||||||
$core->addBehavior('adminPostHeaders', ['adminKutrl', 'adminPostHeaders']);
|
$core->addBehavior('adminPostHeaders', ['adminKutrl', 'adminPostHeaders']);
|
||||||
$core->addBehavior('adminPostFormItems', ['adminKutrl', 'adminPostFormItems']);
|
$core->addBehavior('adminPostFormItems', ['adminKutrl', 'adminPostFormItems']);
|
||||||
$core->addBehavior('adminAfterPostUpdate', ['adminKutrl', 'adminAfterPostUpdate']); // update existing short url
|
$core->addBehavior('adminAfterPostUpdate', ['adminKutrl', 'adminAfterPostUpdate']); // update existing short url
|
||||||
|
@ -49,6 +52,16 @@ $core->addBehavior('importFull', ['backupKutrl', 'importFull']);
|
||||||
# Admin behaviors class
|
# Admin behaviors class
|
||||||
class adminKutrl
|
class adminKutrl
|
||||||
{
|
{
|
||||||
|
public static function sortbyCombo()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
__('Date') => 'kut_dt',
|
||||||
|
__('Short URL') => 'kut_hash',
|
||||||
|
__('Long URL') => 'kut_url',
|
||||||
|
__('Service') => 'kut_service'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
public static function antispamDashboardFavorites(dcCore $core, $favs)
|
public static function antispamDashboardFavorites(dcCore $core, $favs)
|
||||||
{
|
{
|
||||||
$favs->register(
|
$favs->register(
|
||||||
|
@ -63,9 +76,32 @@ class adminKutrl
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function adminColumnsLists(dcCore $core, $cols)
|
||||||
|
{
|
||||||
|
$cols['kUtRL'] = [
|
||||||
|
__('URL shortener'),
|
||||||
|
[
|
||||||
|
'kut_hash' => [true, __('Hash')],
|
||||||
|
'kut_dt' => [true, __('Date')],
|
||||||
|
'kut_service' => [true, __('Service')]
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function adminSortsLists(dcCore $core, $sorts)
|
||||||
|
{
|
||||||
|
$sorts['kUtRL'] = [
|
||||||
|
__('URL shortener'),
|
||||||
|
self::sortbyCombo(),
|
||||||
|
'kut_dt',
|
||||||
|
'desc',
|
||||||
|
[__('Links per page'), 30]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
public static function adminPostHeaders()
|
public static function adminPostHeaders()
|
||||||
{
|
{
|
||||||
return dcPage::jsLoad('index.php?pf=kUtRL/js/admin.js');
|
return dcPage::jsLoad(dcPage::getPF('kUtRL/js/posts.js'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function adminPostFormItems($main_items, $sidebar_items, $post)
|
public static function adminPostFormItems($main_items, $sidebar_items, $post)
|
||||||
|
|
|
@ -28,6 +28,20 @@ class kutrlLinkslist
|
||||||
$this->html_next = __('next »');
|
$this->html_next = __('next »');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function userColumns($type, $cols)
|
||||||
|
{
|
||||||
|
$cols_user = @$this->core->auth->user_prefs->interface->cols;
|
||||||
|
if (is_array($cols_user) || $cols_user instanceof ArrayObject) {
|
||||||
|
if (isset($cols_user[$type])) {
|
||||||
|
foreach ($cols_user[$type] as $cn => $cd) {
|
||||||
|
if (!$cd && isset($cols[$cn])) {
|
||||||
|
unset($cols[$cn]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function display($page, $nb_per_page, $enclose_block, $filter = false)
|
public function display($page, $nb_per_page, $enclose_block, $filter = false)
|
||||||
{
|
{
|
||||||
if ($this->rs->isEmpty()) {
|
if ($this->rs->isEmpty()) {
|
||||||
|
@ -38,30 +52,53 @@ class kutrlLinkslist
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$pager = new dcPager($page, $this->rs_count, $nb_per_page, 10);
|
$pager = new dcPager($page, $this->rs_count, $nb_per_page, 10);
|
||||||
$entries = [];
|
$links = [];
|
||||||
if (isset($_REQUEST['entries'])) {
|
if (isset($_REQUEST['entries'])) {
|
||||||
foreach ($_REQUEST['entries'] as $v) {
|
foreach ($_REQUEST['entries'] as $v) {
|
||||||
$entries[(integer) $v] = true;
|
$links[(integer) $v] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$blocks = explode('%s', sprintf($enclose_block,
|
$cols = [
|
||||||
'<div class="table-outer"><table>' .
|
'kut_url' => '<th colspan="2" class="first">' . __('Link') . '</th>',
|
||||||
($filter ?
|
'kut_hash' => '<th scope="col">' . __('Hash') . '</th>',
|
||||||
'<caption>' . sprintf(__('List of %s links matching the filter.'), $this->rs_count) . '</caption>' :
|
'kut_dt' => '<th scope="col">' . __('Date') . '</th>',
|
||||||
'<caption>' . sprintf(__('List of links (%s)'), $this->rs_count) . '</caption>'
|
'kut_service' => '<th scope="col">' . __('Service') . '</th>'
|
||||||
) .
|
];
|
||||||
'<tr>' .
|
$cols = new ArrayObject($cols);
|
||||||
'<th colspan="2" class="first">' . __('Hash') . '</th>' .
|
$this->userColumns('kUtRL', $cols);
|
||||||
'<th scope="col">' . __('Link') . '</th>' .
|
|
||||||
'<th scope="col">' . __('Date') . '</th>' .
|
$html_block =
|
||||||
'<th scope="col">' . __('Service') . '</th>' .
|
'<div class="table-outer">' .
|
||||||
'</tr>%s</table>%s</div>'
|
'<table>' .
|
||||||
));
|
'<caption>' . ($filter ?
|
||||||
|
sprintf(__('List of %s links matching the filter.'), $this->rs_count) :
|
||||||
|
sprintf(__('List of links (%s)'), $this->rs_count)
|
||||||
|
). '</caption>' .
|
||||||
|
'<thead>' .
|
||||||
|
'<tr>' . implode(iterator_to_array($cols)) . '</tr>' .
|
||||||
|
'</thead>' .
|
||||||
|
'<tbody>%s</tbody>' .
|
||||||
|
'</table>' .
|
||||||
|
'%s</div>';
|
||||||
|
|
||||||
|
if ($enclose_block) {
|
||||||
|
$html_block = sprintf($enclose_block, $html_block);
|
||||||
|
}
|
||||||
|
$blocks = explode('%s', $html_block);
|
||||||
|
|
||||||
echo $pager->getLinks() . $blocks[0];
|
echo $pager->getLinks() . $blocks[0];
|
||||||
|
|
||||||
while ($this->rs->fetch()) {
|
while ($this->rs->fetch()) {
|
||||||
|
echo $this->linkLine(isset($links[$this->rs->kut_id]));
|
||||||
|
}
|
||||||
|
|
||||||
|
echo $blocks[1] . $blocks[2] . $pager->getLinks();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function linkLine($checked)
|
||||||
|
{
|
||||||
$type = $this->rs->kut_type;
|
$type = $this->rs->kut_type;
|
||||||
$hash = $this->rs->kut_hash;
|
$hash = $this->rs->kut_hash;
|
||||||
|
|
||||||
|
@ -70,27 +107,27 @@ class kutrlLinkslist
|
||||||
$hash = '<a href="' . $o->url_base . $hash . '" title="' . $o->url_base . $hash . '">' . $hash . '</a>';
|
$hash = '<a href="' . $o->url_base . $hash . '" title="' . $o->url_base . $hash . '">' . $hash . '</a>';
|
||||||
}
|
}
|
||||||
|
|
||||||
echo
|
$cols = [
|
||||||
'<tr class="line">' .
|
'check' => '<td class="nowrap">' .
|
||||||
'<td class="nowrap">' .
|
|
||||||
form::checkbox(['entries[]'], $this->rs->kut_id, ['checked' => isset($entries[$this->rs->kut_id])]) .
|
form::checkbox(['entries[]'], $this->rs->kut_id, ['checked' => isset($entries[$this->rs->kut_id])]) .
|
||||||
'</td>' .
|
'</td>',
|
||||||
'<td class="nowrap">' .
|
'kut_url' => '<td class="maximal" scope="row">' .
|
||||||
$hash .
|
|
||||||
'</td>' .
|
|
||||||
'<td class="maximal" scope="row">' .
|
|
||||||
'<a href="' . $this->rs->kut_url . '">' . $this->rs->kut_url . '</a>' .
|
'<a href="' . $this->rs->kut_url . '">' . $this->rs->kut_url . '</a>' .
|
||||||
'</td>' .
|
'</td>',
|
||||||
'<td class="nowrap count">' .
|
'kut_hash' => '<td class="nowrap">' .
|
||||||
|
$hash .
|
||||||
|
'</td>',
|
||||||
|
'kut_dt' => '<td class="nowrap count">' .
|
||||||
dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->kut_dt, $this->core->auth->getInfo('user_tz')) .
|
dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->kut_dt, $this->core->auth->getInfo('user_tz')) .
|
||||||
'</td>' .
|
'</td>',
|
||||||
'<td class="nowrap">' .
|
'kut_service' => '<td class="nowrap">' .
|
||||||
$type .
|
$type .
|
||||||
'</td>' .
|
'</td>'
|
||||||
'</tr>';
|
];
|
||||||
}
|
|
||||||
|
|
||||||
echo $blocks[1].$blocks[2].$pager->getLinks();
|
$cols = new ArrayObject($cols);
|
||||||
}
|
$this->userColumns('kUtRL', $cols);
|
||||||
|
|
||||||
|
return '<tr class="line">' . implode(iterator_to_array($cols)) . '</tr>' . "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
65
index.php
65
index.php
|
@ -190,20 +190,15 @@ if ($part == 'link') {
|
||||||
if ($part == 'links') {
|
if ($part == 'links') {
|
||||||
$log = new kutrlLog($core);
|
$log = new kutrlLog($core);
|
||||||
|
|
||||||
$sortby_combo = [
|
$sortby_combo = adminKutrl::sortbyCombo();
|
||||||
__('Date') => 'kut_dt',
|
$order_combo = [__('Descending') => 'desc', __('Ascending') => 'asc'];
|
||||||
__('Long link') => 'kut_url',
|
|
||||||
__('Short link') => 'kut_hash'
|
|
||||||
];
|
|
||||||
$order_combo = [
|
|
||||||
__('Descending') => 'desc',
|
|
||||||
__('Ascending') => 'asc'
|
|
||||||
];
|
|
||||||
|
|
||||||
$core->auth->user_prefs->addWorkspace('interface');
|
$core->auth->user_prefs->addWorkspace('interface');
|
||||||
$default_sortby = 'kut_dt';
|
$sorts_user = @$core->auth->user_prefs->interface->sorts;
|
||||||
$default_order = $core->auth->user_prefs->interface->posts_order ?: 'desc';
|
$default_sortby = $sorts_user['kUtRL'][0] ?? 'kut_dt';
|
||||||
$nb_per_page = $core->auth->user_prefs->interface->nb_posts_per_page ?: 30;
|
$default_order = $sorts_user['kUtRL'][1] ?? 'desc';
|
||||||
|
$nb_per_page = !empty($sorts_user['kUtRL'][2]) ? $sorts_user['kUtRL'][2] : 30;
|
||||||
|
|
||||||
$sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : $default_sortby;
|
$sortby = !empty($_GET['sortby']) ? $_GET['sortby'] : $default_sortby;
|
||||||
$order = !empty($_GET['order']) ? $_GET['order'] : $default_order;
|
$order = !empty($_GET['order']) ? $_GET['order'] : $default_order;
|
||||||
$urlsrv = !empty($_GET['urlsrv']) ? $_GET['urlsrv'] : '';
|
$urlsrv = !empty($_GET['urlsrv']) ? $_GET['urlsrv'] : '';
|
||||||
|
@ -277,16 +272,9 @@ echo
|
||||||
|
|
||||||
if ($part == 'links') {
|
if ($part == 'links') {
|
||||||
echo
|
echo
|
||||||
'<script type="text/javascript">' . "\n" .
|
dcPage::jsVars(['dotclear.filter_reset_url' => $core->adminurl->get('admin.plugin.kUtRL', ['part' => 'links'])]) .
|
||||||
"//<![CDATA[\n" .
|
dcPage::jsFilterControl($show_filters) .
|
||||||
dcPage::jsVar(
|
dcPage::jsLoad(dcPage::getPF('kUtRL/js/admin.js'));
|
||||||
'dotclear.filter_reset_url',
|
|
||||||
html::escapeJS($p_url . '&part=links')
|
|
||||||
) . "\n" .
|
|
||||||
"\$(function(){\$('.checkboxes-helpers').each(function(){dotclear.checkboxesHelpers(this);});});\n" .
|
|
||||||
"//]]>\n" .
|
|
||||||
"</script>\n" .
|
|
||||||
dcPage::jsFilterControl($show_filters);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
echo
|
echo
|
||||||
|
@ -498,7 +486,7 @@ if ($part == 'links') {
|
||||||
dcPage::notices();
|
dcPage::notices();
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
<form action="' . $p_url . '&part=links" method="get" id="filters-form">
|
<form action="' . $p_url . '" method="get" id="filters-form">
|
||||||
<h3 class="out-of-screen-if-js">' . __('Show filters and display options') . '</h3>
|
<h3 class="out-of-screen-if-js">' . __('Show filters and display options') . '</h3>
|
||||||
<div class="table">
|
<div class="table">
|
||||||
<div class="cell">
|
<div class="cell">
|
||||||
|
@ -518,8 +506,9 @@ if ($part == 'links') {
|
||||||
__('entries per page') . '</label></p>' .
|
__('entries per page') . '</label></p>' .
|
||||||
|
|
||||||
form::hidden('part', 'links') .
|
form::hidden('part', 'links') .
|
||||||
form::hidden('p', 'kUtRL') . '
|
form::hidden('p', 'kUtRL') .
|
||||||
|
form::hidden('filters-options-id', 'kUtRL') .
|
||||||
|
'<p class="hidden-if-no-js"><a href="#" id="filter-options-save">' . __('Save current options') . '</a></p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -530,21 +519,27 @@ if ($part == 'links') {
|
||||||
$list_current->display(
|
$list_current->display(
|
||||||
$page,
|
$page,
|
||||||
$nb_per_page,
|
$nb_per_page,
|
||||||
'<form action="' . $p_url . '&part=links" method="post" id="form-actions">
|
'<form action="' . $p_url . '&part=links" method="post" id="form-entries">
|
||||||
|
|
||||||
%s
|
%s
|
||||||
|
|
||||||
<div class="two-cols">
|
<div class="two-cols">
|
||||||
<p class="col checkboxes-helpers"></p>
|
<div class="col left">
|
||||||
|
<p class="checkboxes-helpers"></p>
|
||||||
|
</div>
|
||||||
<p class="col right">
|
<p class="col right">
|
||||||
<input type="submit" value="' . __('Delete selected short links') . '" />' .
|
<input id="do-action" type="submit" value="' . __('Delete selected short links') . '" /></p>' .
|
||||||
form::hidden(['deletelinks'], 1) .
|
$core->adminurl->getHiddenFormFields(
|
||||||
form::hidden(['urlsrv'], $urlsrv) .
|
'admin.plugin.kUtRL',[
|
||||||
form::hidden(['sortby'], $sortby) .
|
'deletelinks' => 1,
|
||||||
form::hidden(['order'], $order) .
|
'urlsrv' => $urlsrv,
|
||||||
form::hidden(['page'], $page) .
|
'sortby' => $sortby,
|
||||||
form::hidden(['nb'], $nb_per_page) .
|
'order' => $order,
|
||||||
form::hidden(['part'], 'links') .
|
'page' => $page,
|
||||||
|
'nb' => $nb_per_page,
|
||||||
|
'part' => 'links'
|
||||||
|
]
|
||||||
|
) .
|
||||||
$core->formNonce() . '
|
$core->formNonce() . '
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
10
js/admin.js
10
js/admin.js
|
@ -1,7 +1,7 @@
|
||||||
$(function(){
|
$(function(){
|
||||||
/* toogle admin form sidebar */
|
$('#form-entries .checkboxes-helpers').each(function () {
|
||||||
$('#kUtRL h5').toggleWithLegend(
|
dotclear.checkboxesHelpers(this, undefined, '#form-entries td input[type=checkbox]', '#form-entries #do-action');
|
||||||
$('#kUtRL').children().not('h5'),
|
});
|
||||||
{cookie:'dcx_kUtRL_admin_form_sidebar',legend_click:true}
|
$('#form-entries td input[type=checkbox]').enableShiftClick();
|
||||||
);
|
dotclear.condSubmit('#form-entries td input[type=checkbox]', '#form-entries #do-action');
|
||||||
});
|
});
|
7
js/posts.js
Normal file
7
js/posts.js
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
$(function(){
|
||||||
|
/* toogle admin form sidebar */
|
||||||
|
$('#kUtRL h5').toggleWithLegend(
|
||||||
|
$('#kUtRL').children().not('h5'),
|
||||||
|
{cookie:'dcx_kUtRL_admin_form_sidebar',legend_click:true}
|
||||||
|
);
|
||||||
|
});
|
Loading…
Reference in a new issue