add user pref on table filters and cols, fix js
This commit is contained in:
parent
a6fdf10759
commit
98c61a0c6e
@ -2,6 +2,10 @@ xxx.xx.xx
|
||||
- Never fix breaking comments or complexe public url
|
||||
- [ ] Add public page of the list of know urls and in/visible status
|
||||
- [ ] 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
|
||||
- remove deprecated external service
|
||||
|
48
_admin.php
48
_admin.php
@ -25,11 +25,14 @@ $_menu['Plugins']->addItem(
|
||||
$core->adminurl->get('admin.plugin.kUtRL'),
|
||||
dcPage::getPF('kUtRL/icon.png'),
|
||||
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
|
||||
if ($core->blog->settings->kUtRL->kutrl_active) {
|
||||
$core->addBehavior('adminDashboardFavorites', ['adminKutrl', 'antispamDashboardFavorites']);
|
||||
$core->addBehavior('adminColumnsLists', ['adminKutrl', 'adminColumnsLists']);
|
||||
$core->addBehavior('adminSortsLists', ['adminKutrl', 'adminSortsLists']);
|
||||
$core->addBehavior('adminPostHeaders', ['adminKutrl', 'adminPostHeaders']);
|
||||
$core->addBehavior('adminPostFormItems', ['adminKutrl', 'adminPostFormItems']);
|
||||
$core->addBehavior('adminAfterPostUpdate', ['adminKutrl', 'adminAfterPostUpdate']); // update existing short url
|
||||
@ -49,23 +52,56 @@ $core->addBehavior('importFull', ['backupKutrl', 'importFull']);
|
||||
# Admin behaviors class
|
||||
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)
|
||||
{
|
||||
$favs->register(
|
||||
'kUtRL',
|
||||
[
|
||||
'title' => __('Links shortener'),
|
||||
'url' => $core->adminurl->get('admin.plugin.kUtRL'),
|
||||
'small-icon' => dcPage::getPF('kUtRL/icon.png'),
|
||||
'large-icon' => dcPage::getPF('kUtRL/icon-b.png'),
|
||||
'title' => __('Links shortener'),
|
||||
'url' => $core->adminurl->get('admin.plugin.kUtRL'),
|
||||
'small-icon' => dcPage::getPF('kUtRL/icon.png'),
|
||||
'large-icon' => dcPage::getPF('kUtRL/icon-b.png'),
|
||||
'permissions' => 'admin'
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
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)
|
||||
|
@ -28,6 +28,20 @@ class kutrlLinkslist
|
||||
$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)
|
||||
{
|
||||
if ($this->rs->isEmpty()) {
|
||||
@ -38,59 +52,82 @@ class kutrlLinkslist
|
||||
}
|
||||
} else {
|
||||
$pager = new dcPager($page, $this->rs_count, $nb_per_page, 10);
|
||||
$entries = [];
|
||||
$links = [];
|
||||
if (isset($_REQUEST['entries'])) {
|
||||
foreach ($_REQUEST['entries'] as $v) {
|
||||
$entries[(integer) $v] = true;
|
||||
$links[(integer) $v] = true;
|
||||
}
|
||||
}
|
||||
|
||||
$blocks = explode('%s', sprintf($enclose_block,
|
||||
'<div class="table-outer"><table>' .
|
||||
($filter ?
|
||||
'<caption>' . sprintf(__('List of %s links matching the filter.'), $this->rs_count) . '</caption>' :
|
||||
'<caption>' . sprintf(__('List of links (%s)'), $this->rs_count) . '</caption>'
|
||||
) .
|
||||
'<tr>' .
|
||||
'<th colspan="2" class="first">' . __('Hash') . '</th>' .
|
||||
'<th scope="col">' . __('Link') . '</th>' .
|
||||
'<th scope="col">' . __('Date') . '</th>' .
|
||||
'<th scope="col">' . __('Service') . '</th>' .
|
||||
'</tr>%s</table>%s</div>'
|
||||
));
|
||||
$cols = [
|
||||
'kut_url' => '<th colspan="2" class="first">' . __('Link') . '</th>',
|
||||
'kut_hash' => '<th scope="col">' . __('Hash') . '</th>',
|
||||
'kut_dt' => '<th scope="col">' . __('Date') . '</th>',
|
||||
'kut_service' => '<th scope="col">' . __('Service') . '</th>'
|
||||
];
|
||||
$cols = new ArrayObject($cols);
|
||||
$this->userColumns('kUtRL', $cols);
|
||||
|
||||
echo $pager->getLinks().$blocks[0];
|
||||
$html_block =
|
||||
'<div class="table-outer">' .
|
||||
'<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];
|
||||
|
||||
while ($this->rs->fetch()) {
|
||||
$type = $this->rs->kut_type;
|
||||
$hash = $this->rs->kut_hash;
|
||||
|
||||
if (null !== ($o = kutrl::quickService($type))) {
|
||||
$type = '<a href="' . $o->home . '" title="' . $o->name . '">' . $o->name . '</a>';
|
||||
$hash = '<a href="' . $o->url_base . $hash . '" title="' . $o->url_base . $hash . '">' . $hash . '</a>';
|
||||
}
|
||||
|
||||
echo
|
||||
'<tr class="line">' .
|
||||
'<td class="nowrap">' .
|
||||
form::checkbox(['entries[]'], $this->rs->kut_id, ['checked' => isset($entries[$this->rs->kut_id])]) .
|
||||
'</td>' .
|
||||
'<td class="nowrap">' .
|
||||
$hash .
|
||||
'</td>' .
|
||||
'<td class="maximal" scope="row">' .
|
||||
'<a href="' . $this->rs->kut_url . '">' . $this->rs->kut_url . '</a>' .
|
||||
'</td>' .
|
||||
'<td class="nowrap count">' .
|
||||
dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->kut_dt, $this->core->auth->getInfo('user_tz')) .
|
||||
'</td>' .
|
||||
'<td class="nowrap">' .
|
||||
$type .
|
||||
'</td>' .
|
||||
'</tr>';
|
||||
echo $this->linkLine(isset($links[$this->rs->kut_id]));
|
||||
}
|
||||
|
||||
echo $blocks[1].$blocks[2].$pager->getLinks();
|
||||
echo $blocks[1] . $blocks[2] . $pager->getLinks();
|
||||
}
|
||||
}
|
||||
|
||||
private function linkLine($checked)
|
||||
{
|
||||
$type = $this->rs->kut_type;
|
||||
$hash = $this->rs->kut_hash;
|
||||
|
||||
if (null !== ($o = kutrl::quickService($type))) {
|
||||
$type = '<a href="' . $o->home . '" title="' . $o->name . '">' . $o->name . '</a>';
|
||||
$hash = '<a href="' . $o->url_base . $hash . '" title="' . $o->url_base . $hash . '">' . $hash . '</a>';
|
||||
}
|
||||
|
||||
$cols = [
|
||||
'check' => '<td class="nowrap">' .
|
||||
form::checkbox(['entries[]'], $this->rs->kut_id, ['checked' => isset($entries[$this->rs->kut_id])]) .
|
||||
'</td>',
|
||||
'kut_url' => '<td class="maximal" scope="row">' .
|
||||
'<a href="' . $this->rs->kut_url . '">' . $this->rs->kut_url . '</a>' .
|
||||
'</td>',
|
||||
'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')) .
|
||||
'</td>',
|
||||
'kut_service' => '<td class="nowrap">' .
|
||||
$type .
|
||||
'</td>'
|
||||
];
|
||||
|
||||
$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') {
|
||||
$log = new kutrlLog($core);
|
||||
|
||||
$sortby_combo = [
|
||||
__('Date') => 'kut_dt',
|
||||
__('Long link') => 'kut_url',
|
||||
__('Short link') => 'kut_hash'
|
||||
];
|
||||
$order_combo = [
|
||||
__('Descending') => 'desc',
|
||||
__('Ascending') => 'asc'
|
||||
];
|
||||
$sortby_combo = adminKutrl::sortbyCombo();
|
||||
$order_combo = [__('Descending') => 'desc', __('Ascending') => 'asc'];
|
||||
|
||||
$core->auth->user_prefs->addWorkspace('interface');
|
||||
$default_sortby = 'kut_dt';
|
||||
$default_order = $core->auth->user_prefs->interface->posts_order ?: 'desc';
|
||||
$nb_per_page = $core->auth->user_prefs->interface->nb_posts_per_page ?: 30;
|
||||
$sorts_user = @$core->auth->user_prefs->interface->sorts;
|
||||
$default_sortby = $sorts_user['kUtRL'][0] ?? 'kut_dt';
|
||||
$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;
|
||||
$order = !empty($_GET['order']) ? $_GET['order'] : $default_order;
|
||||
$urlsrv = !empty($_GET['urlsrv']) ? $_GET['urlsrv'] : '';
|
||||
@ -277,16 +272,9 @@ echo
|
||||
|
||||
if ($part == 'links') {
|
||||
echo
|
||||
'<script type="text/javascript">' . "\n" .
|
||||
"//<![CDATA[\n" .
|
||||
dcPage::jsVar(
|
||||
'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);
|
||||
dcPage::jsVars(['dotclear.filter_reset_url' => $core->adminurl->get('admin.plugin.kUtRL', ['part' => 'links'])]) .
|
||||
dcPage::jsFilterControl($show_filters) .
|
||||
dcPage::jsLoad(dcPage::getPF('kUtRL/js/admin.js'));
|
||||
}
|
||||
|
||||
echo
|
||||
@ -498,7 +486,7 @@ if ($part == 'links') {
|
||||
dcPage::notices();
|
||||
|
||||
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>
|
||||
<div class="table">
|
||||
<div class="cell">
|
||||
@ -518,8 +506,9 @@ if ($part == 'links') {
|
||||
__('entries per page') . '</label></p>' .
|
||||
|
||||
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>
|
||||
|
||||
@ -530,21 +519,27 @@ if ($part == 'links') {
|
||||
$list_current->display(
|
||||
$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
|
||||
|
||||
<div class="two-cols">
|
||||
<p class="col checkboxes-helpers"></p>
|
||||
<div class="col left">
|
||||
<p class="checkboxes-helpers"></p>
|
||||
</div>
|
||||
<p class="col right">
|
||||
<input type="submit" value="' . __('Delete selected short links') . '" />' .
|
||||
form::hidden(['deletelinks'], 1) .
|
||||
form::hidden(['urlsrv'], $urlsrv) .
|
||||
form::hidden(['sortby'], $sortby) .
|
||||
form::hidden(['order'], $order) .
|
||||
form::hidden(['page'], $page) .
|
||||
form::hidden(['nb'], $nb_per_page) .
|
||||
form::hidden(['part'], 'links') .
|
||||
<input id="do-action" type="submit" value="' . __('Delete selected short links') . '" /></p>' .
|
||||
$core->adminurl->getHiddenFormFields(
|
||||
'admin.plugin.kUtRL',[
|
||||
'deletelinks' => 1,
|
||||
'urlsrv' => $urlsrv,
|
||||
'sortby' => $sortby,
|
||||
'order' => $order,
|
||||
'page' => $page,
|
||||
'nb' => $nb_per_page,
|
||||
'part' => 'links'
|
||||
]
|
||||
) .
|
||||
$core->formNonce() . '
|
||||
</p>
|
||||
</div>
|
||||
|
10
js/admin.js
10
js/admin.js
@ -1,7 +1,7 @@
|
||||
$(function(){
|
||||
/* toogle admin form sidebar */
|
||||
$('#kUtRL h5').toggleWithLegend(
|
||||
$('#kUtRL').children().not('h5'),
|
||||
{cookie:'dcx_kUtRL_admin_form_sidebar',legend_click:true}
|
||||
);
|
||||
$('#form-entries .checkboxes-helpers').each(function () {
|
||||
dotclear.checkboxesHelpers(this, undefined, '#form-entries td input[type=checkbox]', '#form-entries #do-action');
|
||||
});
|
||||
$('#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 New Issue
Block a user