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; dcPage::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; dcPage::addSuccessNotice(sprintf( __('Short link for %s is %s'), '' . html::escapeHTML($url) . '', '' . $new_url . '' )); # ex: Send new url to messengers if (!empty($rs)) { $core->callBehavior('adminAfterKutrlCreate', $core, $rs,__('New short URL')); } } } } catch (Exception $e) { $core->error->add($e->getMessage()); } } # links } else { $services_combo = []; foreach(kutrl::getServices($core) as $service_id => $service) { $o = new $service($core); $services_combo[__($o->name)] = $o->id; } $ext_services_combo = array_merge([__('Disabled')=>''], $services_combo); $lst_services_combo = array_merge(['-'=>''], $services_combo); $log = new kutrlLog($core); $kUtRL_filter = new adminGenericFilter($core, '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($core, $list_all, $list_counter); } catch (Exception $e) { $core->error->add($e->getMessage()); } $header = $kUtRL_filter->js($core->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); } $core->blog->triggerBlog(); dcPage::addSuccessNotice( __('Links successfully deleted') ); $core->adminurl->redirect('admin.plugin.kUtRL', $kUtRL_filter->values()); } catch (Exception $e) { $core->error->add($e->getMessage()); } } } # display header echo 'kUtRL, ' . __('Links shortener') . '' . $header . ''; # display link creation if ($part == 'link') { echo dcPage::breadcrumb([ __('Plugins') => '', __('Links shortener') => $core->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

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

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