auth->makePermissions([ dcAuth::PERMISSION_ADMIN, ])); $header = ''; $part = $_REQUEST['part'] ?? 'links'; $action = $_POST['action'] ?? ''; # link creation if ($part == 'link') { $kut = kUtRL::quickPlace('admin'); if (!empty($_POST['save'])) { try { if (null === $kut) { throw new Exception('Unknow service'); } $url = trim(dcCore::app()->con->escape($_POST['str'])); $hash = empty($_POST['custom']) ? null : $_POST['custom']; if (empty($url)) { throw new Exception(__('There is nothing to shorten.')); } if (!$kut->testService()) { throw new Exception(__('Service is not well configured.')); } if (null !== $hash && !$kut->allow_custom_hash) { throw new Exception(__('This service does not allowed custom hash.')); } if (!$kut->isValidUrl($url)) { throw new Exception(__('This link is not a valid URL.')); } if (!$kut->isLongerUrl($url)) { throw new Exception(__('This link is too short.')); } if (!$kut->isProtocolUrl($url)) { throw new Exception(__('This type of link is not allowed.')); } if (!$kut->allow_external_url && !$kut->isBlogUrl($url)) { throw new Exception(__('Short links are limited to this blog URL.')); } if ($kut->isServiceUrl($url)) { throw new Exception(__('This link is already a short link.')); } if (null !== $hash && false !== ($rs = $kut->isKnowHash($hash))) { throw new Exception(__('This custom short url is already taken.')); } if (false !== ($rs = $kut->isKnowUrl($url))) { $url = $rs->url; $new_url = $kut->url_base . $rs->hash; dcAdminNotices::addSuccessNotice(sprintf( __('Short link for %s is %s'), '' . html::escapeHTML($url) . '', '' . $new_url . '' )); } else { if (false === ($rs = $kut->hash($url, $hash))) { if ($kut->error->flag()) { throw new Exception($kut->error->toHTML()); } throw new Exception(__('Failed to create short link. This could be caused by a service failure.')); } else { $url = $rs->url; $new_url = $kut->url_base . $rs->hash; dcAdminNotices::addSuccessNotice(sprintf( __('Short link for %s is %s'), '' . html::escapeHTML($url) . '', '' . $new_url . '' )); # ex: Send new url to messengers if (!empty($rs)) { dcCore::app()->callBehavior('adminAfterKutrlCreate', $rs, __('New short URL')); } } } } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); } } # links } else { $services_combo = []; foreach (kUtRL::getServices() as $service_id => $service) { $o = new $service(); $services_combo[__($o->name)] = $o->id; } $ext_services_combo = array_merge([__('Disabled') => ''], $services_combo); $lst_services_combo = array_merge(['-' => ''], $services_combo); $log = new kutrlLog(); $kUtRL_filter = new adminGenericFilterV2('kUtRL'); $kUtRL_filter->add('part', 'links'); $kUtRL_filter->add(dcAdminFilters::getPageFilter()); $kUtRL_filter->add(dcAdminFilters::getSelectFilter( 'urlsrv', __('Service:'), $lst_services_combo, 'kut_type' )); $params = $kUtRL_filter->params(); try { $list_all = $log->getLogs($params); $list_counter = $log->getLogs($params, true)->f(0); $list_current = new kutrlLinkslist($list_all, $list_counter); } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); } $header = $kUtRL_filter->js(dcCore::app()->adminurl->get('admin.plugin.kUtRL', ['part' => 'links'])) . dcPage::jsLoad(dcPage::getPF('kUtRL/js/admin.js')); if (!empty($_POST['deletelinks'])) { try { foreach ($_POST['entries'] as $id) { $rs = $log->getLogs(['kut_id' => $id]); if ($rs->isEmpty()) { continue; } if (null === ($o = kUtRL::quickService($rs->kut_type))) { continue; } $o->remove($rs->kut_url); } dcCore::app()->blog->triggerBlog(); dcAdminNotices::addSuccessNotice( __('Links successfully deleted') ); dcCore::app()->adminurl->redirect('admin.plugin.kUtRL', $kUtRL_filter->values()); } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); } } } # display header echo 'kUtRL, ' . __('Links shortener') . '' . $header . ''; # display link creation if ($part == 'link') { echo dcPage::breadcrumb([ __('Plugins') => '', __('Links shortener') => dcCore::app()->adminurl->get('admin.plugin.kUtRL'), __('New link') => '', ]) . dcPage::notices(); if (null === $kut) { echo '

' . __('You must set an admin service.') . '

'; } else { echo '

' . sprintf(__('Shorten link using service "%s"'), $kut->name) . '

'; } } else { echo dcPage::breadcrumb([ __('Plugins') => '', __('Links shortener') => '', ]) . dcPage::notices() . '

' . __('New Link') . '

'; $kUtRL_filter->display('admin.plugin.kUtRL', form::hidden('p', 'kUtRL') . form::hidden('part', 'links')); $list_current->display( $kUtRL_filter->value('page'), $kUtRL_filter->nb, '
%s

' . dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.kUtRL', array_merge(['deletelinks' => 1], $kUtRL_filter->values(true))) . dcCore::app()->formNonce() . '

', $kUtRL_filter->show() ); } # display footer dcPage::helpBlock('kUtRL'); echo '';