cleanup index.xx files

master
Jean-Christian Paul Denis 2021-08-28 00:06:46 +02:00
parent d01496f5cf
commit 96fb6c7d23
9 changed files with 958 additions and 1067 deletions

View File

@ -10,7 +10,9 @@
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# -- END LICENSE BLOCK ------------------------------------ # -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')){return;} if (!defined('DC_RC_PATH')) {
return null;
}
# Generic class to play easily with services # Generic class to play easily with services
class kUtRL class kUtRL
@ -20,17 +22,17 @@ class kUtRL
{ {
$list = $core->getBehaviors('kutrlService'); $list = $core->getBehaviors('kutrlService');
if (empty($list)) return array(); if (empty($list)) {
return [];
$service = array(); }
foreach($list as $k => $callback) $service = [];
{ foreach($list as $k => $callback) {
try try {
{
list($service_id,$service_class) = call_user_func($callback); list($service_id,$service_class) = call_user_func($callback);
$services[(string) $service_id] = (string) $service_class; $services[(string) $service_id] = (string) $service_class;
} catch (Exception $e) {
} }
catch (Exception $e) {}
} }
return $services; return $services;
} }
@ -41,8 +43,7 @@ class kUtRL
{ {
global $core; global $core;
try try {
{
if (empty($id)) { if (empty($id)) {
return null; return null;
} }
@ -50,9 +51,9 @@ class kUtRL
if (isset($services[$id])) { if (isset($services[$id])) {
return new $services[$id]($core); return new $services[$id]($core);
} }
} } catch(Exception $e) {
catch(Exception $e) { }
}
return null; return null;
} }
@ -62,18 +63,17 @@ class kUtRL
{ {
global $core; global $core;
try try {
{ if (!in_array($place, ['tpl', 'wiki', 'admin', 'plugin'])) {
if (!in_array($place,array('tpl','wiki','admin','plugin'))) {
return null; return null;
} }
$id = $core->blog->settings->kUtRL->get('kutrl_' . $place .'_service'); $id = $core->blog->settings->kUtRL->get('kutrl_' . $place .'_service');
if (!empty($id)) { if (!empty($id)) {
return self::quickService($id); return self::quickService($id);
} }
} } catch(Exception $e) {
catch(Exception $e) { }
}
return null; return null;
} }
@ -83,8 +83,7 @@ class kUtRL
{ {
global $core; global $core;
try try {
{
$srv = self::quickPlace($place); $srv = self::quickPlace($place);
if (empty($srv)) { if (empty($srv)) {
return $url; return $url;
@ -93,12 +92,10 @@ class kUtRL
if (empty($rs)) { if (empty($rs)) {
return $url; return $url;
} }
return $srv->url_base.$rs->hash; return $srv->url_base.$rs->hash;
} } catch(Exception $e) {
catch(Exception $e) { }
}
return $url; return $url;
} }
} }
?>

View File

@ -12,90 +12,82 @@
# This file manage admin link creation of kUtRL (called from index.php) # This file manage admin link creation of kUtRL (called from index.php)
if (!defined('DC_CONTEXT_ADMIN')){return;} if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
$kut = kutrl::quickPlace('admin'); $kut = kutrl::quickPlace('admin');
# Create a new link # Create a new link
if ($action == 'createlink') { if ($action == 'createlink') {
try {
try if (null === $kut) {
{
if (null === $kut)
throw new Exception('Unknow service'); throw new Exception('Unknow service');
}
$url = trim($core->con->escape($_POST['str'])); $url = trim($core->con->escape($_POST['str']));
$hash = empty($_POST['custom']) ? null : $_POST['custom']; $hash = empty($_POST['custom']) ? null : $_POST['custom'];
if (empty($url)) if (empty($url)) {
throw new Exception(__('There is nothing to shorten.')); throw new Exception(__('There is nothing to shorten.'));
}
if (!$kut->testService()) if (!$kut->testService()) {
throw new Exception(__('Service is not well configured.')); throw new Exception(__('Service is not well configured.'));
}
if (null !== $hash && !$kut->allow_custom_hash) if (null !== $hash && !$kut->allow_custom_hash) {
throw new Exception(__('This service does not allowed custom hash.')); throw new Exception(__('This service does not allowed custom hash.'));
}
if (!$kut->isValidUrl($url)) if (!$kut->isValidUrl($url)) {
throw new Exception(__('This link is not a valid URL.')); throw new Exception(__('This link is not a valid URL.'));
}
if (!$kut->isLongerUrl($url)) if (!$kut->isLongerUrl($url)) {
throw new Exception(__('This link is too short.')); throw new Exception(__('This link is too short.'));
}
if (!$kut->isProtocolUrl($url)) if (!$kut->isProtocolUrl($url)) {
throw new Exception(__('This type of link is not allowed.')); throw new Exception(__('This type of link is not allowed.'));
}
if (!$kut->allow_external_url && !$kut->isBlogUrl($url)) if (!$kut->allow_external_url && !$kut->isBlogUrl($url)) {
throw new Exception(__('Short links are limited to this blog URL.')); throw new Exception(__('Short links are limited to this blog URL.'));
}
if ($kut->isServiceUrl($url)) if ($kut->isServiceUrl($url)) {
throw new Exception(__('This link is already a short link.')); throw new Exception(__('This link is already a short link.'));
}
if (null !== $hash && false !== ($rs = $kut->isKnowHash($hash))) if (null !== $hash && false !== ($rs = $kut->isKnowHash($hash))) {
throw new Exception(__('This custom short url is already taken.')); throw new Exception(__('This custom short url is already taken.'));
}
if (false !== ($rs = $kut->isKnowUrl($url))) if (false !== ($rs = $kut->isKnowUrl($url))) {
{
$url = $rs->url; $url = $rs->url;
$new_url = $kut->url_base .$rs->hash; $new_url = $kut->url_base .$rs->hash;
$msg = $msg =
'<p class="message">' . '<p class="message">' .
sprintf(__('Short link for %s is %s'), sprintf(
__('Short link for %s is %s') ,
'<strong>' . html::escapeHTML($url) .'</strong>', '<strong>' . html::escapeHTML($url) .'</strong>',
'<a href="' . $new_url . '">' . $new_url . '</a>' '<a href="' . $new_url . '">' . $new_url . '</a>'
) . '</p>'; ) . '</p>';
} } else {
else if (false === ($rs = $kut->hash($url, $hash))) {
{ if ($kut->error->flag()) {
if (false === ($rs = $kut->hash($url,$hash)))
{
if ($kut->error->flag())
{
throw new Exception($kut->error->toHTML()); throw new Exception($kut->error->toHTML());
} }
throw new Exception(__('Failed to create short link. This could be caused by a service failure.')); throw new Exception(__('Failed to create short link. This could be caused by a service failure.'));
} } else {
else
{
$url = $rs->url; $url = $rs->url;
$new_url = $kut->url_base . $rs->hash; $new_url = $kut->url_base . $rs->hash;
$msg = $msg =
'<p class="message">' . '<p class="message">' .
sprintf(__('Short link for %s is %s'), sprintf(
__('Short link for %s is %s'),
'<strong>' . html::escapeHTML($url) . '</strong>', '<strong>' . html::escapeHTML($url) . '</strong>',
'<a href="' . $new_url . '">' . $new_url . '</a>' '<a href="' . $new_url . '">' . $new_url . '</a>'
) . '</p>'; ) . '</p>';
# ex: Send new url to messengers # ex: Send new url to messengers
if (!empty($rs)) if (!empty($rs)) {
{
$core->callBehavior('adminAfterKutrlCreate', $core, $rs,__('New short URL')); $core->callBehavior('adminAfterKutrlCreate', $core, $rs,__('New short URL'));
} }
} }
} }
} } catch (Exception $e) {
catch (Exception $e)
{
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
} }
} }
@ -109,12 +101,9 @@ echo '
' &rsaquo; ' . __('New link') . ' &rsaquo; ' . __('New link') .
'</h2>' . $msg; '</h2>' . $msg;
if (null === $kut) if (null === $kut) {
{
echo '<p>' . __('You must set an admin service.') . '</p>'; echo '<p>' . __('You must set an admin service.') . '</p>';
} } else {
else
{
echo ' echo '
<form id="create-link" method="post" action="' . $p_url . '"> <form id="create-link" method="post" action="' . $p_url . '">
@ -122,16 +111,14 @@ else
<p class="classic"><label for="str">' . __('Long link:') . <p class="classic"><label for="str">' . __('Long link:') .
form::field('str', 100, 255, '') . '</label></p>'; form::field('str', 100, 255, '') . '</label></p>';
if ($kut->allow_custom_hash) if ($kut->allow_custom_hash) {
{
echo echo
'<p class="classic"><label for="custom">' . '<p class="classic"><label for="custom">' .
__('Custom short link:') . __('Custom short link:') .
form::field('custom', 50, 32, '') . '</label></p>' . form::field('custom', 50, 32, '') . '</label></p>' .
'<p class="form-note">' . __('Only if you want a custom short link.') . '</p>'; '<p class="form-note">' . __('Only if you want a custom short link.') . '</p>';
if ($s_admin_service == 'local') if ($s_admin_service == 'local') {
{
echo '<p class="form-note">' . echo '<p class="form-note">' .
__('You can use "bob!!" if you want a semi-custom link, it starts with "bob" and "!!" will be replaced by an increment value.') . __('You can use "bob!!" if you want a semi-custom link, it starts with "bob" and "!!" will be replaced by an increment value.') .
'</p>'; '</p>';
@ -142,12 +129,11 @@ else
<div class="clear"> <div class="clear">
<p><input type="submit" name="save" value="' . __('save') . '" />' . <p><input type="submit" name="save" value="' . __('save') . '" />' .
$core->formNonce() . $core->formNonce() .
form::hidden(array('p'),'kUtRL'). form::hidden(['p'], 'kUtRL') .
form::hidden(array('part'),'link'). form::hidden(['part'], 'link') .
form::hidden(array('action'),'createlink').' form::hidden(['action'], 'createlink') . '
</p></div> </p></div>
</form>'; </form>';
} }
dcPage::helpBlock('kUtRL'); dcPage::helpBlock('kUtRL');
echo $footer . '</body></html>'; echo $footer . '</body></html>';
?>

View File

@ -12,17 +12,18 @@
# This file manage links of kUtRL (called from index.php) # This file manage links of kUtRL (called from index.php)
if (!defined('DC_CONTEXT_ADMIN')){return;} if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
# Short links list # Short links list
class kutrlLinkslist extends adminGenericList class kutrlLinkslist extends adminGenericList
{ {
public function display($page, $nb_per_page, $url) public function display($page, $nb_per_page, $url)
{ {
if ($this->rs->isEmpty()) if ($this->rs->isEmpty()) {
echo '<p><strong>' . __('No short link') . '</strong></p>'; echo '<p><strong>' . __('No short link') . '</strong></p>';
} else {
else {
$pager = new pager($page, $this->rs_count, $nb_per_page, 10); $pager = new pager($page, $this->rs_count, $nb_per_page, 10);
$pager->base_url = $url; $pager->base_url = $url;
@ -50,11 +51,11 @@ class kutrlLinkslist extends adminGenericList
echo $this->line($url,$iter); echo $this->line($url,$iter);
if ($this->rs->isEnd()) if ($this->rs->isEnd()) {
break; break;
else } else {
$this->rs->moveNext(); $this->rs->moveNext();
}
$iter++; $iter++;
} }
echo $blocks[1]; echo $blocks[1];
@ -67,8 +68,7 @@ class kutrlLinkslist extends adminGenericList
$type = $this->rs->kut_type; $type = $this->rs->kut_type;
$hash = $this->rs->kut_hash; $hash = $this->rs->kut_hash;
if (null !== ($o = kutrl::quickService($this->rs->kut_type))) if (null !== ($o = kutrl::quickService($this->rs->kut_type))) {
{
$type = '<a href="' . $o->home . '" title="' . $o->name . '">' . $o->name . '</a>'; $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>'; $hash = '<a href="' . $o->url_base . $hash . '" title="' . $o->url_base . $hash . '">' . $hash . '</a>';
} }
@ -76,7 +76,7 @@ class kutrlLinkslist extends adminGenericList
return return
'<tr class="line">' . "\n" . '<tr class="line">' . "\n" .
'<td class="nowrap">' . '<td class="nowrap">' .
form::checkbox(array('entries['.$loop.']'),$this->rs->kut_id,0). form::checkbox(['entries[' . $loop . ']'], $this->rs->kut_id, 0) .
'</td>' . '</td>' .
'<td class="nowrap">' . '<td class="nowrap">' .
$hash . $hash .
@ -106,46 +106,48 @@ $order = !empty($_GET['order']) ? $_GET['order'] : 'desc';
$page = !empty($_GET['page']) ? (integer) $_GET['page'] : 1; $page = !empty($_GET['page']) ? (integer) $_GET['page'] : 1;
$nb_per_page = 30; $nb_per_page = 30;
if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) { if (!empty($_GET['nb']) && (integer) $_GET['nb'] > 0) {
if ($nb_per_page != $_GET['nb']) $show_filters = true; if ($nb_per_page != $_GET['nb']) {
$show_filters = true;
}
$nb_per_page = (integer) $_GET['nb']; $nb_per_page = (integer) $_GET['nb'];
} }
# Combos # Combos
$sortby_combo = array( $sortby_combo = [
__('Date') => 'kut_dt', __('Date') => 'kut_dt',
__('Long link') => 'kut_url', __('Long link') => 'kut_url',
__('Short link') => 'kut_hash' __('Short link') => 'kut_hash'
); ];
$order_combo = array( $order_combo = [
__('Descending') => 'desc', __('Descending') => 'desc',
__('Ascending') => 'asc' __('Ascending') => 'asc'
); ];
$services_combo = array(); $services_combo = [];
foreach(kutrl::getServices($core) as $service_id => $service) foreach(kutrl::getServices($core) as $service_id => $service)
{ {
$o = new $service($core); $o = new $service($core);
$services_combo[__($o->name)] = $o->id; $services_combo[__($o->name)] = $o->id;
} }
$ext_services_combo = array_merge(array(__('Disabled')=>''),$services_combo); $ext_services_combo = array_merge([__('Disabled') => ''], $services_combo);
$lst_services_combo = array_merge(array('-'=>''),$services_combo); $lst_services_combo = array_merge(['-' => ''], $services_combo);
# Params for list # Params for list
$params = array(); $params = [];
$params['limit'] = array((($page-1)*$nb_per_page),$nb_per_page); $params['limit'] = [(($page-1)*$nb_per_page), $nb_per_page];
if ($sortby != '' && in_array($sortby,$sortby_combo)) if ($sortby != '' && in_array($sortby, $sortby_combo)) {
{ if ($urlsrv != '' && in_array($urlsrv, $lst_services_combo)) {
if ($urlsrv != '' && in_array($urlsrv,$lst_services_combo))
$params['kut_type'] = $urlsrv; $params['kut_type'] = $urlsrv;
}
if ($order != '' && in_array($order,$order_combo)) if ($order != '' && in_array($order, $order_combo)) {
$params['order'] = $sortby . ' ' . $order; $params['order'] = $sortby . ' ' . $order;
}
if ($sortby != 'kut_dt' || $order != 'desc' || $urlsrv != '') if ($sortby != 'kut_dt' || $order != 'desc' || $urlsrv != '') {
$show_filters = true; $show_filters = true;
} }
}
$pager_base_url = $pager_base_url =
$p_url . $p_url .
@ -156,41 +158,35 @@ $pager_base_url =
'&amp;nb=' . $nb_per_page . '&amp;nb=' . $nb_per_page .
'&amp;page=%s'; '&amp;page=%s';
# Delete links from list # Delete links from list
if ($action == 'deletelinks') if ($action == 'deletelinks') {
{ try {
try foreach($_POST['entries'] as $k => $id) {
{ $rs = $log->getLogs(['kut_id' => $id]);
foreach($_POST['entries'] as $k => $id) if ($rs->isEmpty()) {
{ continue;
$rs = $log->getLogs(array('kut_id'=>$id)); }
if ($rs->isEmpty()) continue; if (null === ($o = kutrl::quickService($rs->kut_type))) {
continue;
if (null === ($o = kutrl::quickService($rs->kut_type))) continue; }
$o->remove($rs->kut_url); $o->remove($rs->kut_url);
} }
$core->blog->triggerBlog(); $core->blog->triggerBlog();
http::redirect($p_url . '&part=links&urlsrv=' . $urlsrv . '&sortby=' . $sortby . '&order=' . $order . '&nb=' . $nb_per_page . '&page=' . $page . '&msg=' . $action); http::redirect($p_url . '&part=links&urlsrv=' . $urlsrv . '&sortby=' . $sortby . '&order=' . $order . '&nb=' . $nb_per_page . '&page=' . $page . '&msg=' . $action);
} } catch (Exception $e) {
catch (Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
} }
} }
# Get links and pager # Get links and pager
try try {
{
$list_all = $log->getLogs($params); $list_all = $log->getLogs($params);
$list_counter = $log->getLogs($params, true)->f(0); $list_counter = $log->getLogs($params, true)->f(0);
$list_current = new kutrlLinksList($core, $list_all, $list_counter, $pager_base_url); $list_current = new kutrlLinksList($core, $list_all, $list_counter, $pager_base_url);
} } catch (Exception $e) {
catch (Exception $e)
{
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
} }
if (!$show_filters) { if (!$show_filters) {
$header .= dcPage::jsLoad('js/filter-controls.js'); $header .= dcPage::jsLoad('js/filter-controls.js');
} }
@ -232,8 +228,8 @@ echo '
<label class="classic">' . form::field('nb', 3, 3, $nb_per_page) . ' ' . __('Entries per page') . ' <label class="classic">' . form::field('nb', 3, 3, $nb_per_page) . ' ' . __('Entries per page') . '
</label> </label>
<input type="submit" value="' . __('filter') . '" />' . <input type="submit" value="' . __('filter') . '" />' .
form::hidden(array('p'),'kUtRL'). form::hidden(['p'], 'kUtRL') .
form::hidden(array('part'),'links').' form::hidden(['part'], 'links') . '
</p> </p>
</div> </div>
</div> </div>
@ -249,14 +245,14 @@ echo '
<p class="col checkboxes-helpers"></p> <p class="col checkboxes-helpers"></p>
<p class="col right"> <p class="col right">
<input type="submit" value="' . __('Delete selected short links') . '" />' . <input type="submit" value="' . __('Delete selected short links') . '" />' .
form::hidden(array('action'),'deletelinks'). form::hidden(['action'], 'deletelinks') .
form::hidden(array('urlsrv'),$urlsrv). form::hidden(['urlsrv'], $urlsrv) .
form::hidden(array('sortby'),$sortby). form::hidden(['sortby'], $sortby) .
form::hidden(array('order'),$order). form::hidden(['order'], $order) .
form::hidden(array('page'),$page). form::hidden(['page'], $page) .
form::hidden(array('nb'),$nb_per_page). form::hidden(['nb'], $nb_per_page) .
form::hidden(array('p'),'kUtRL'). form::hidden(['p'], 'kUtRL') .
form::hidden(array('part'),'links'). form::hidden(['part'], 'links') .
$core->formNonce() . ' $core->formNonce() . '
</p> </p>
</div> </div>

View File

@ -12,23 +12,20 @@
# This file manage services of kUtRL (called from index.php) # This file manage services of kUtRL (called from index.php)
if (!defined('DC_CONTEXT_ADMIN')){return;} if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
# Save services settings # Save services settings
if ($action == 'saveservice') if ($action == 'saveservice') {
{ try {
try foreach(kutrl::getServices($core) as $service_id => $service) {
{
foreach(kutrl::getServices($core) as $service_id => $service)
{
$o = new $service($core); $o = new $service($core);
$o->saveSettings(); $o->saveSettings();
} }
$core->blog->triggerBlog(); $core->blog->triggerBlog();
http::redirect($p_url . '&part=service&section=' . $section . '&msg=' . $action); http::redirect($p_url . '&part=service&section=' . $section . '&msg=' . $action);
} } catch (Exception $e) {
catch (Exception $e)
{
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
} }
} }
@ -49,14 +46,12 @@ dcPage::jsVar('jcToolsBox.prototype.section',$section).
'</h2>' . $msg . ' '</h2>' . $msg . '
<form id="service-form" method="post" action="' . $p_url . '">'; <form id="service-form" method="post" action="' . $p_url . '">';
foreach(kutrl::getServices($core) as $service_id => $service) foreach(kutrl::getServices($core) as $service_id => $service) {
{
$o = new $service($core); $o = new $service($core);
echo '<fieldset id="setting-' . $service_id . '"><legend>' . $o->name . '</legend>'; echo '<fieldset id="setting-' . $service_id . '"><legend>' . $o->name . '</legend>';
if (!empty($msg)) if (!empty($msg)) {
{
echo '<p><em>' . ( echo '<p><em>' . (
$o->testService() ? $o->testService() ?
$img_green . ' ' . sprintf(__('%s API is well configured and runing.'), $o->name) : $img_green . ' ' . sprintf(__('%s API is well configured and runing.'), $o->name) :
@ -66,12 +61,9 @@ foreach(kutrl::getServices($core) as $service_id => $service)
echo $o->error->toHTML(); echo $o->error->toHTML();
//} //}
} }
if (!empty($o->home)) {
if (!empty($o->home))
{
echo '<p><a title="' . __('homepage') . '" href="' . $o->home . '">' . sprintf(__('Learn more about %s.'), $o->name) . '</a></p>'; echo '<p><a title="' . __('homepage') . '" href="' . $o->home . '">' . sprintf(__('Learn more about %s.'), $o->name) . '</a></p>';
} }
$o->settingsForm(); $o->settingsForm();
echo '</fieldset>'; echo '</fieldset>';
@ -81,12 +73,11 @@ echo '
<div class="clear"> <div class="clear">
<p><input type="submit" name="save" value="' . __('save') . '" />' . <p><input type="submit" name="save" value="' . __('save') . '" />' .
$core->formNonce() . $core->formNonce() .
form::hidden(array('p'),'kUtRL'). form::hidden(['p'], 'kUtRL') .
form::hidden(array('part'),'service'). form::hidden(['part'], 'service') .
form::hidden(array('action'),'saveservice'). form::hidden(['action'], 'saveservice') .
form::hidden(array('section'),$section).' form::hidden(['section'], $section) . '
</p></div> </p></div>
</form>'; </form>';
dcPage::helpBlock('kUtRL'); dcPage::helpBlock('kUtRL');
echo $footer . '</body></html>'; echo $footer . '</body></html>';
?>

View File

@ -12,7 +12,9 @@
# This file manage settings of kUtRL (called from index.php) # This file manage settings of kUtRL (called from index.php)
if (!defined('DC_CONTEXT_ADMIN')){return;} if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
$s_active = (boolean) $s->kutrl_active; $s_active = (boolean) $s->kutrl_active;
$s_plugin_service = (string) $s->kutrl_plugin_service; $s_plugin_service = (string) $s->kutrl_plugin_service;
@ -24,8 +26,7 @@ $s_tpl_passive = (boolean) $s->kutrl_tpl_passive;
$s_tpl_active = (boolean) $s->kutrl_tpl_active; $s_tpl_active = (boolean) $s->kutrl_tpl_active;
$s_admin_entry_default = (string) $s->kutrl_admin_entry_default; $s_admin_entry_default = (string) $s->kutrl_admin_entry_default;
if ($default_part == 'setting' && $action == 'savesetting') if ($default_part == 'setting' && $action == 'savesetting') {
{
try { try {
$s_active = !empty($_POST['s_active']); $s_active = !empty($_POST['s_active']);
$s_admin_service = $_POST['s_admin_service']; $s_admin_service = $_POST['s_admin_service'];
@ -50,20 +51,18 @@ if ($default_part == 'setting' && $action == 'savesetting')
$core->blog->triggerBlog(); $core->blog->triggerBlog();
http::redirect($p_url . '&part=setting&msg=' . $action . '&section=' . $section); http::redirect($p_url . '&part=setting&msg=' . $action . '&section=' . $section);
} } catch (Exception $e) {
catch (Exception $e) {
$core->error->add($e->getMessage()); $core->error->add($e->getMessage());
} }
} }
$services_combo = array(); $services_combo = [];
foreach(kutrl::getServices($core) as $service_id => $service) foreach(kutrl::getServices($core) as $service_id => $service) {
{
$o = new $service($core); $o = new $service($core);
$services_combo[__($o->name)] = $o->id; $services_combo[__($o->name)] = $o->id;
} }
$ext_services_combo = array_merge(array(__('Disabled')=>''),$services_combo); $ext_services_combo = array_merge([__('Disabled')=>''], $services_combo);
$lst_services_combo = array_merge(array('-'=>''),$services_combo); $lst_services_combo = array_merge(['-'=>''], $services_combo);
echo ' echo '
<html> <html>
@ -83,26 +82,26 @@ dcPage::jsVar('jcToolsBox.prototype.section',$section).
<fieldset id="setting-plugin"><legend>' . __('Plugin activation') . '</legend> <fieldset id="setting-plugin"><legend>' . __('Plugin activation') . '</legend>
<p><label class="classic">' . <p><label class="classic">' .
form::checkbox(array('s_active'),'1',$s_active). form::checkbox(['s_active'], '1', $s_active) .
__('Enable plugin') . '</label></p> __('Enable plugin') . '</label></p>
</fieldset> </fieldset>
<fieldset id="setting-option"><legend>' . __('General rules') . '</legend> <fieldset id="setting-option"><legend>' . __('General rules') . '</legend>
<p><label class="classic">' . <p><label class="classic">' .
form::checkbox(array('s_allow_external_url'),'1',$s_allow_external_url). form::checkbox(['s_allow_external_url'], '1', $s_allow_external_url) .
__('Allow short link for external URL') . '</label></p> __('Allow short link for external URL') . '</label></p>
<p class="form-note">' . __('Not only link started with this blog URL could be shortened.') . '</p> <p class="form-note">' . __('Not only link started with this blog URL could be shortened.') . '</p>
<p><label class="classic">' . <p><label class="classic">' .
form::checkbox(array('s_tpl_passive'),'1',$s_tpl_passive). form::checkbox(['s_tpl_passive'], '1', $s_tpl_passive) .
__('Passive mode') . '</label></p> __('Passive mode') . '</label></p>
<p class="form-note">' . __('If this extension is disabled and the passive mode is enabled, "kutrl" tags (like EntryKurl) will display long urls instead of nothing on templates.') . '</p> <p class="form-note">' . __('If this extension is disabled and the passive mode is enabled, "kutrl" tags (like EntryKurl) will display long urls instead of nothing on templates.') . '</p>
<p><label class="classic">' . <p><label class="classic">' .
form::checkbox(array('s_tpl_active'),'1',$s_tpl_active). form::checkbox(['s_tpl_active'], '1', $s_tpl_active) .
__('Active mode') . '</label></p> __('Active mode') . '</label></p>
<p class="form-note">' . __('If the active mode is enabled, all know default template tags (like EntryURL) will display short urls instead of long ones on templates.') . '<br />' . <p class="form-note">' . __('If the active mode is enabled, all know default template tags (like EntryURL) will display short urls instead of long ones on templates.') . '<br />' .
__('You can disable URL shortening for a specific template tag by adding attribute disable_kutrl="1" to it . ') . '</p> __('You can disable URL shortening for a specific template tag by adding attribute disable_kutrl="1" to it . ') . '</p>
<p><label class="classic">' . <p><label class="classic">' .
form::checkbox(array('s_admin_entry_default'),'1',$s_admin_entry_default). form::checkbox(['s_admin_entry_default'], '1', $s_admin_entry_default) .
__('Create short link for new entries') . '</label></p> __('Create short link for new entries') . '</label></p>
<p class="form-note">' . __('This can be changed on page of creation/edition of an entry.') . '</p> <p class="form-note">' . __('This can be changed on page of creation/edition of an entry.') . '</p>
</fieldset> </fieldset>
@ -115,7 +114,7 @@ if (!empty($msg)) {
} }
} }
echo '&nbsp;' . __('Administration:') . '<br />' . echo '&nbsp;' . __('Administration:') . '<br />' .
form::combo(array('s_admin_service'),$services_combo,$s_admin_service).' form::combo(['s_admin_service'], $services_combo, $s_admin_service) . '
</label></p> </label></p>
<p class="form-note">' . __('Service to use in this admin page and on edit page of an entry.') . '</p> <p class="form-note">' . __('Service to use in this admin page and on edit page of an entry.') . '</p>
<p><label>'; <p><label>';
@ -125,7 +124,7 @@ if (!empty($msg)) {
} }
} }
echo '&nbsp;' . __('Extensions:') . '<br />' . echo '&nbsp;' . __('Extensions:') . '<br />' .
form::combo(array('s_plugin_service'),$services_combo,$s_plugin_service).' form::combo(['s_plugin_service'], $services_combo, $s_plugin_service) . '
</label></p> </label></p>
<p class="form-note">' . __('Service to use on third part plugins.') . '</p> <p class="form-note">' . __('Service to use on third part plugins.') . '</p>
<p><label>'; <p><label>';
@ -135,7 +134,7 @@ if (!empty($msg)) {
} }
} }
echo '&nbsp;' . __('Templates:') . '<br />' . echo '&nbsp;' . __('Templates:') . '<br />' .
form::combo(array('s_tpl_service'),$ext_services_combo,$s_tpl_service).' form::combo(['s_tpl_service'], $ext_services_combo, $s_tpl_service) . '
</label></p> </label></p>
<p class="form-note">' . __('Shorten links automatically when using template value like "EntryKutrl".') . '</p> <p class="form-note">' . __('Shorten links automatically when using template value like "EntryKutrl".') . '</p>
<p><label>'; <p><label>';
@ -145,7 +144,7 @@ if (!empty($msg)) {
} }
} }
echo '&nbsp;' . __('Contents:') . '<br />' . echo '&nbsp;' . __('Contents:') . '<br />' .
form::combo(array('s_wiki_service'),$ext_services_combo,$s_wiki_service).' form::combo(['s_wiki_service'], $ext_services_combo, $s_wiki_service) . '
</label></p> </label></p>
<p class="form-note">' . __('Shorten links automatically found in contents using wiki synthax.') . '</p> <p class="form-note">' . __('Shorten links automatically found in contents using wiki synthax.') . '</p>
</fieldset> </fieldset>
@ -153,12 +152,11 @@ form::combo(array('s_wiki_service'),$ext_services_combo,$s_wiki_service).'
<div class="clear"> <div class="clear">
<p><input type="submit" name="save" value="' . __('save') . '" />' . <p><input type="submit" name="save" value="' . __('save') . '" />' .
$core->formNonce() . $core->formNonce() .
form::hidden(array('p'),'kUtRL'). form::hidden(['p'], 'kUtRL') .
form::hidden(array('part'),'setting'). form::hidden(['part'], 'setting') .
form::hidden(array('action'),'savesetting'). form::hidden(['action'], 'savesetting') .
form::hidden(array('section'),$section).' form::hidden(['section'], $section) . '
</p></div> </p></div>
</form>'; </form>';
dcPage::helpBlock('kUtRL'); dcPage::helpBlock('kUtRL');
echo $footer . '</body></html>'; echo $footer . '</body></html>';
?>

View File

@ -12,7 +12,9 @@
# This file is used with plugin activityReport # This file is used with plugin activityReport
if (!defined('DC_RC_PATH')){return;} if (!defined('DC_RC_PATH')) {
return null;
}
$core->activityReport->addGroup('kutrl', __('Plugin kUtRL')); $core->activityReport->addGroup('kutrl', __('Plugin kUtRL'));
@ -23,16 +25,15 @@ $core->activityReport->addAction(
__('Short link creation'), __('Short link creation'),
__('New short link of type "%s" and hash "%s" was created.'), __('New short link of type "%s" and hash "%s" was created.'),
'kutrlAfterCreateShortUrl', 'kutrlAfterCreateShortUrl',
array('kutrlActivityReportBehaviors','kutrlCreate') ['kutrlActivityReportBehaviors', 'kutrlCreate']
); );
class kutrlActivityReportBehaviors class kutrlActivityReportBehaviors
{ {
public static function kutrlCreate($rs) public static function kutrlCreate($rs)
{ {
$logs = array($rs->type,$rs->hash); $logs = [$rs->type,$rs->hash];
$GLOBALS['core']->activityReport->addLog('kutrl', 'create', $logs); $GLOBALS['core']->activityReport->addLog('kutrl', 'create', $logs);
} }
} }
?>

View File

@ -52,17 +52,15 @@ class kutrlLog
$cur->insert(); $cur->insert();
$this->con->unlock(); $this->con->unlock();
return array( return [
'id' => $cur->kut_id, 'id' => $cur->kut_id,
'url' => $url, 'url' => $url,
'hash' => $hash, 'hash' => $hash,
'type' => $type, 'type' => $type,
'service' => $service, 'service' => $service,
'counter '=> 0 'counter '=> 0
); ];
} } catch (Exception $e) {
catch (Exception $e)
{
$this->con->unlock(); $this->con->unlock();
throw $e; throw $e;
} }
@ -80,17 +78,16 @@ class kutrlLog
"WHERE blog_id = '" . $this->blog . "' " . "WHERE blog_id = '" . $this->blog . "' " .
"AND kut_service = '" . $this->con->escape($service) . "' "; "AND kut_service = '" . $this->con->escape($service) . "' ";
if (null !== $url) if (null !== $url) {
$req .= "AND kut_url = '" . $this->con->escape($url) . "' "; $req .= "AND kut_url = '" . $this->con->escape($url) . "' ";
}
if (null !== $hash) if (null !== $hash) {
$req .= "AND kut_hash = '" . $this->con->escape($hash) . "' "; $req .= "AND kut_hash = '" . $this->con->escape($hash) . "' ";
}
if (null !== $type) { if (null !== $type) {
if (is_array($type)) { if (is_array($type)) {
$req .= "AND kut_type '" . $this->con->in($type) ."' "; $req .= "AND kut_type '" . $this->con->in($type) ."' ";
} } else {
else {
$req .= "AND kut_type = '" . $this->con->escape($type) . "' "; $req .= "AND kut_type = '" . $this->con->escape($type) . "' ";
} }
} }
@ -110,8 +107,7 @@ class kutrlLog
$cur = $this->con->openCursor($this->table); $cur = $this->con->openCursor($this->table);
$this->con->writeLock($this->table); $this->con->writeLock($this->table);
try try {
{
$cur->kut_url = ''; $cur->kut_url = '';
$cur->kut_dt = date('Y-m-d H:i:s'); $cur->kut_dt = date('Y-m-d H:i:s');
$cur->kut_counter = 0; $cur->kut_counter = 0;
@ -123,9 +119,7 @@ class kutrlLog
$this->con->unlock(); $this->con->unlock();
return true; return true;
} } catch (Exception $e) {
catch (Exception $e)
{
$this->con->unlock(); $this->con->unlock();
throw $e; throw $e;
} }
@ -156,20 +150,13 @@ class kutrlLog
$counter = $rs->isEmpty() ? 0 : $rs->kut_counter; $counter = $rs->isEmpty() ? 0 : $rs->kut_counter;
if ('get' == $do) if ('get' == $do) {
{
return $counter; return $counter;
} } elseif ('up' == $do) {
elseif ('up' == $do)
{
$counter += 1; $counter += 1;
} } elseif ('reset' == $do) {
elseif ('reset' == $do)
{
$counter = 0; $counter = 0;
} } else {
else
{
return 0; return 0;
} }
@ -188,127 +175,83 @@ class kutrlLog
public function getLogs($p, $count_only = false) public function getLogs($p, $count_only = false)
{ {
if ($count_only) if ($count_only) {
{
$r = 'SELECT count(S.kut_id) '; $r = 'SELECT count(S.kut_id) ';
} } else {
else
{
$content_req = ''; $content_req = '';
if (!empty($p['columns']) && is_array($p['columns'])) if (!empty($p['columns']) && is_array($p['columns'])) {
{
$content_req .= implode(', ', $p['columns']) . ', '; $content_req .= implode(', ', $p['columns']) . ', ';
} }
$r = $r =
'SELECT S.kut_id, S.kut_type, S.kut_hash, S.kut_url, ' . 'SELECT S.kut_id, S.kut_type, S.kut_hash, S.kut_url, ' .
$content_req . 'S.kut_dt '; $content_req . 'S.kut_dt ';
} }
$r .= 'FROM ' . $this->table . ' S '; $r .= 'FROM ' . $this->table . ' S ';
if (!empty($p['from'])) {
if (!empty($p['from']))
{
$r .= $p['from'] . ' '; $r .= $p['from'] . ' ';
} }
$r .= "WHERE S.blog_id = '" . $this->blog . "' "; $r .= "WHERE S.blog_id = '" . $this->blog . "' ";
if (isset($p['kut_service'])) {
if (isset($p['kut_service']))
{
$r .= "AND kut_service='" . $this->con->escape($p['kut_service']) . "' "; $r .= "AND kut_service='" . $this->con->escape($p['kut_service']) . "' ";
} } else {
else
{
$r .= "AND kut_service='kutrl' "; $r .= "AND kut_service='kutrl' ";
} }
if (isset($p['kut_type'])) {
if (isset($p['kut_type']))
{
if (is_array($p['kut_type']) && !empty($p['kut_type'])) if (is_array($p['kut_type']) && !empty($p['kut_type']))
{ {
$r .= 'AND kut_type ' . $this->con->in($p['kut_type']); $r .= 'AND kut_type ' . $this->con->in($p['kut_type']);
} } elseif ($p['kut_type'] != '') {
elseif ($p['kut_type'] != '')
{
$r .= "AND kut_type = '" . $this->con->escape($p['kut_type']) . "' "; $r .= "AND kut_type = '" . $this->con->escape($p['kut_type']) . "' ";
} }
} }
if (isset($p['kut_id'])) {
if (isset($p['kut_id'])) if (is_array($p['kut_id']) && !empty($p['kut_id'])) {
{
if (is_array($p['kut_id']) && !empty($p['kut_id']))
{
$r .= 'AND kut_id ' . $this->con->in($p['kut_id']); $r .= 'AND kut_id ' . $this->con->in($p['kut_id']);
} } elseif ($p['kut_id'] != '') {
elseif ($p['kut_id'] != '')
{
$r .= "AND kut_id = '" . $this->con->escape($p['kut_id']) . "' "; $r .= "AND kut_id = '" . $this->con->escape($p['kut_id']) . "' ";
} }
} }
if (isset($p['kut_hash'])) {
if (isset($p['kut_hash'])) if (is_array($p['kut_hash']) && !empty($p['kut_hash'])) {
{
if (is_array($p['kut_hash']) && !empty($p['kut_hash']))
{
$r .= 'AND kut_hash ' . $this->con->in($p['kut_hash']); $r .= 'AND kut_hash ' . $this->con->in($p['kut_hash']);
} } elseif ($p['kut_hash'] != '') {
elseif ($p['kut_hash'] != '')
{
$r .= "AND kut_hash = '" . $this->con->escape($p['kut_hash']) . "' "; $r .= "AND kut_hash = '" . $this->con->escape($p['kut_hash']) . "' ";
} }
} }
if (isset($p['kut_url'])) {
if (isset($p['kut_url'])) if (is_array($p['kut_url']) && !empty($p['kut_url'])) {
{
if (is_array($p['kut_url']) && !empty($p['kut_url']))
{
$r .= 'AND kut_url ' . $this->con->in($p['kut_url']); $r .= 'AND kut_url ' . $this->con->in($p['kut_url']);
} } elseif ($p['kut_url'] != '') {
elseif ($p['kut_url'] != '')
{
$r .= "AND kut_url = '" . $this->con->escape($p['kut_url']) . "' "; $r .= "AND kut_url = '" . $this->con->escape($p['kut_url']) . "' ";
} }
} }
if (!empty($p['kut_year'])) {
if (!empty($p['kut_year']))
{
$r .= $r .=
'AND ' . $this->con->dateFormat('kut_dt', '%Y') . ' = ' . 'AND ' . $this->con->dateFormat('kut_dt', '%Y') . ' = ' .
"'" . sprintf('%04d', $p['kut_year']) . "' "; "'" . sprintf('%04d', $p['kut_year']) . "' ";
} }
if (!empty($p['kut_month'])) {
if (!empty($p['kut_month']))
{
$r .= $r .=
'AND ' . $this->con->dateFormat('kut_dt', '%m') . ' = ' . 'AND ' . $this->con->dateFormat('kut_dt', '%m') . ' = ' .
"'" . sprintf('%02d', $p['kut_month']) . "' "; "'" . sprintf('%02d', $p['kut_month']) . "' ";
} }
if (!empty($p['kut_day'])) {
if (!empty($p['kut_day']))
{
$r .= $r .=
'AND ' . $this->con->dateFormat('kut_dt', '%d') . ' = ' . 'AND ' . $this->con->dateFormat('kut_dt', '%d') . ' = ' .
"'" . sprintf('%02d', $p['kut_day']) . "' "; "'" . sprintf('%02d', $p['kut_day']) . "' ";
} }
if (!empty($p['sql'])) {
if (!empty($p['sql']))
{
$r .= $p['sql'] . ' '; $r .= $p['sql'] . ' ';
} }
if (!$count_only) {
if (!$count_only)
{
$r .= empty($p['order']) ? $r .= empty($p['order']) ?
'ORDER BY kut_dt DESC ' : 'ORDER BY kut_dt DESC ' :
'ORDER BY ' . $this->con->escape($p['order']) . ' '; 'ORDER BY ' . $this->con->escape($p['order']) . ' ';
} }
if (!$count_only && !empty($p['limit'])) {
if (!$count_only && !empty($p['limit']))
{
$r .= $this->con->limit($p['limit']); $r .= $this->con->limit($p['limit']);
} }
return $this->con->select($r); return $this->con->select($r);
} }
} }
?>

View File

@ -37,20 +37,20 @@ class kutrlService
true : $allow_external_url; true : $allow_external_url;
$this->config = array_merge( $this->config = array_merge(
array( [
'id' => 'undefined', 'id' => 'undefined',
'name' => 'undefined', 'name' => 'undefined',
'home' => '', 'home' => '',
'allow_external_url' => true, 'allow_external_url' => true,
'allow_custom_hash' => false, 'allow_custom_hash' => false,
'allow_protocols' => array('http://'), 'allow_protocols' => ['http://'],
'url_test' => 'http://dotclear.jcdenis.com/go/kUtRL', 'url_test' => 'http://dotclear.jcdenis.com/go/kUtRL',
'url_api' => '', 'url_api' => '',
'url_base' => '', 'url_base' => '',
'url_min_len' => 0 'url_min_len' => 0
), ],
$this->config $this->config
); );
} }
@ -109,11 +109,13 @@ class kutrlService
# Test if an url protocol (eg: http://) is allowed # Test if an url protocol (eg: http://) is allowed
public function isProtocolUrl($url) public function isProtocolUrl($url)
{ {
foreach($this->allow_protocols as $protocol) foreach($this->allow_protocols as $protocol) {
{ if (empty($protocol)) {
if (empty($protocol)) continue; continue;
}
if (strpos($url,$protocol) === 0) return true; if (strpos($url,$protocol) === 0) {
return true;
}
} }
return false; return false;
} }
@ -143,45 +145,35 @@ class kutrlService
public function hash($url, $hash = null) public function hash($url, $hash = null)
{ {
$url = trim($this->core->con->escape($url)); $url = trim($this->core->con->escape($url));
if ('undefined' === $this->id) if ('undefined' === $this->id) {
{
return false; return false;
} }
if ($hash && !$this->allow_custom_hash) if ($hash && !$this->allow_custom_hash) {
{
return false; return false;
} }
if ($this->isServiceUrl($url)) if ($this->isServiceUrl($url)) {
{
return false; return false;
} }
if (!$this->isLongerUrl($url)) if (!$this->isLongerUrl($url)) {
{
return false; return false;
} }
if (!$this->allow_external_url && $this->isBlogUrl($url)) if (!$this->allow_external_url && $this->isBlogUrl($url)) {
{
return false; return false;
} }
if ($hash && false !== ($rs = $this->isKnowHash($hash))) if ($hash && false !== ($rs = $this->isKnowHash($hash))) {
{
return false; return false;
} }
if (false === ($rs = $this->isKnowUrl($url))) if (false === ($rs = $this->isKnowUrl($url))) {
{ if (false === ($rs = $this->createHash($url, $hash))) {
if (false === ($rs = $this->createHash($url,$hash)))
{
return false; return false;
} }
$this->log->insert($rs->url, $rs->hash, $rs->type, 'kutrl'); $this->log->insert($rs->url, $rs->hash, $rs->type, 'kutrl');
$this->core->blog->triggerBlog(); $this->core->blog->triggerBlog();
# --BEHAVIOR-- kutrlAfterCreateShortUrl # --BEHAVIOR-- kutrlAfterCreateShortUrl
$this->core->callBehavior('kutrlAfterCreateShortUrl', $rs); $this->core->callBehavior('kutrlAfterCreateShortUrl', $rs);
} }
return $rs; return $rs;
} }
@ -195,8 +187,9 @@ class kutrlService
# Remove an url from list of know urls # Remove an url from list of know urls
public function remove($url) public function remove($url)
{ {
if (!($rs = $this->isKnowUrl($url))) return false; if (!($rs = $this->isKnowUrl($url))) {
echo 'la'; return false;
}
$this->deleteUrl($url); $this->deleteUrl($url);
$this->log->delete($rs->id); $this->log->delete($rs->id);
return true; return true;
@ -215,40 +208,29 @@ class kutrlService
} }
# Post request # Post request
public static function post($server,$data,$verbose=true,$get=false,$headers=array()) public static function post($server, $data, $verbose = true, $get = false, $headers = [])
{ {
$url = (string) $server; $url = (string) $server;
$client = netHttp::initClient($url, $url); $client = netHttp::initClient($url, $url);
$client->setUserAgent('kUtRL - http://kutrl.fr'); $client->setUserAgent('kUtRL - http://kutrl.fr');
$client->setPersistReferers(false); $client->setPersistReferers(false);
if (is_array($headers) && !empty($headers)) if (is_array($headers) && !empty($headers)) {
{ foreach($headers as $header) {
foreach($headers as $header)
{
$client->setMoreHeader($header); $client->setMoreHeader($header);
} }
} }
if ($get) {
if ($get)
{
$client->get($url, $data); $client->get($url, $data);
} } else {
else
{
$client->post($url, $data); $client->post($url, $data);
} }
if (!$verbose && $client->getStatus() != 200) {
if (!$verbose && $client->getStatus() != 200)
{
return false; return false;
} }
if ($verbose) {
if ($verbose)
{
return $client->getContent(); return $client->getContent();
} }
return true; return true;
} }
} }
?>

View File

@ -12,7 +12,9 @@
# This file contents class to shorten url pass through wiki # This file contents class to shorten url pass through wiki
if (!defined('DC_RC_PATH')){return;} if (!defined('DC_RC_PATH')) {
return null;
}
class kutrlWiki class kutrlWiki
{ {
@ -24,15 +26,16 @@ class kutrlWiki
# Do nothing on comment preview and post preview # Do nothing on comment preview and post preview
if (!empty($_POST['preview']) if (!empty($_POST['preview'])
|| !empty($GLOBALS['_ctx']) && $GLOBALS['_ctx']->preview || !empty($GLOBALS['_ctx']) && $GLOBALS['_ctx']->preview
|| !$s->kutrl_active) return; || !$s->kutrl_active) {
return null;
if (null === ($kut = kutrl::quickPlace('wiki'))) return; }
if (null === ($kut = kutrl::quickPlace('wiki'))) {
foreach($kut->allow_protocols as $protocol) return null;
{ }
foreach($kut->allow_protocols as $protocol) {
$wiki2xhtml->registerFunction( $wiki2xhtml->registerFunction(
'url:' . $protocol, 'url:' . $protocol,
array('kutrlWiki','transform') ['kutrlWiki', 'transform']
); );
} }
} }
@ -42,39 +45,33 @@ class kutrlWiki
global $core; global $core;
$s = $core->blog->settings->kUtRL; $s = $core->blog->settings->kUtRL;
if (!$s->kutrl_active) return; if (!$s->kutrl_active) {
return null;
if (null === ($kut = kutrl::quickPlace('wiki'))) return array(); }
if (null === ($kut = kutrl::quickPlace('wiki'))) {
return [];
}
# Test if long url exists # Test if long url exists
$is_new = false; $is_new = false;
$rs = $kut->isKnowUrl($url); $rs = $kut->isKnowUrl($url);
if (!$rs) if (!$rs) {
{
$is_new = true; $is_new = true;
$rs = $kut->hash($url); $rs = $kut->hash($url);
} }
if (!$rs) {
if (!$rs) return [];
{ } else {
return array(); $res = [];
}
else
{
$res = array();
$testurl = strlen($rs->url) > 35 ? substr($rs->url, 0, 35) . '...' : $rs->url; $testurl = strlen($rs->url) > 35 ? substr($rs->url, 0, 35) . '...' : $rs->url;
$res['url'] = $kut->url_base . $rs->hash; $res['url'] = $kut->url_base . $rs->hash;
$res['title'] = sprintf(__('%s (Shorten with %s)'), $rs->url, __($kut->name)); $res['title'] = sprintf(__('%s (Shorten with %s)'), $rs->url, __($kut->name));
if ($testurl == $content) $res['content'] = $res['url']; if ($testurl == $content) $res['content'] = $res['url'];
# ex: Send new url to messengers # ex: Send new url to messengers
if (!empty($rs)) if (!empty($rs)) {
{
$core->callBehavior('wikiAfterKutrlCreate', $core, $rs, __('New short URL')); $core->callBehavior('wikiAfterKutrlCreate', $core, $rs, __('New short URL'));
} }
return $res; return $res;
} }
} }
} }
?>