cleanup index.xx files
This commit is contained in:
parent
d01496f5cf
commit
96fb6c7d23
@ -10,95 +10,92 @@
|
|||||||
# 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
|
||||||
{
|
{
|
||||||
# Load services list from behavior
|
# Load services list from behavior
|
||||||
public static function getServices($core)
|
public static function getServices($core)
|
||||||
{
|
{
|
||||||
$list = $core->getBehaviors('kutrlService');
|
$list = $core->getBehaviors('kutrlService');
|
||||||
|
|
||||||
if (empty($list)) return array();
|
if (empty($list)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
$service = [];
|
||||||
|
foreach($list as $k => $callback) {
|
||||||
|
try {
|
||||||
|
list($service_id,$service_class) = call_user_func($callback);
|
||||||
|
$services[(string) $service_id] = (string) $service_class;
|
||||||
|
} catch (Exception $e) {
|
||||||
|
|
||||||
$service = array();
|
}
|
||||||
foreach($list as $k => $callback)
|
}
|
||||||
{
|
return $services;
|
||||||
try
|
}
|
||||||
{
|
|
||||||
list($service_id,$service_class) = call_user_func($callback);
|
|
||||||
$services[(string) $service_id] = (string) $service_class;
|
|
||||||
}
|
|
||||||
catch (Exception $e) {}
|
|
||||||
}
|
|
||||||
return $services;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Silently try to load a service according to its id
|
# Silently try to load a service according to its id
|
||||||
# Return null on error else service on success
|
# Return null on error else service on success
|
||||||
public static function quickService($id='')
|
public static function quickService($id = '')
|
||||||
{
|
{
|
||||||
global $core;
|
global $core;
|
||||||
|
|
||||||
try
|
try {
|
||||||
{
|
if (empty($id)) {
|
||||||
if (empty($id)) {
|
return null;
|
||||||
return null;
|
}
|
||||||
}
|
$services = self::getServices($core);
|
||||||
$services = self::getServices($core);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
# Silently try to load a service according to its place
|
# Silently try to load a service according to its place
|
||||||
# Return null on error else service on success
|
# Return null on error else service on success
|
||||||
public static function quickPlace($place='plugin')
|
public static function quickPlace($place = 'plugin')
|
||||||
{
|
{
|
||||||
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;
|
||||||
|
}
|
||||||
|
|
||||||
# Silently try to reduce url (using 'plugin' place)
|
# Silently try to reduce url (using 'plugin' place)
|
||||||
# return long url on error else short url on success
|
# return long url on error else short url on success
|
||||||
public static function quickReduce($url,$custom=null,$place='plugin')
|
public static function quickReduce($url, $custom = null, $place = 'plugin')
|
||||||
{
|
{
|
||||||
global $core;
|
global $core;
|
||||||
|
|
||||||
try
|
try {
|
||||||
{
|
$srv = self::quickPlace($place);
|
||||||
$srv = self::quickPlace($place);
|
if (empty($srv)) {
|
||||||
if (empty($srv)) {
|
return $url;
|
||||||
return $url;
|
}
|
||||||
}
|
$rs = $srv->hash($url,$custom);
|
||||||
$rs = $srv->hash($url,$custom);
|
if (empty($rs)) {
|
||||||
if (empty($rs)) {
|
return $url;
|
||||||
return $url;
|
}
|
||||||
}
|
return $srv->url_base.$rs->hash;
|
||||||
|
} catch(Exception $e) {
|
||||||
|
|
||||||
return $srv->url_base.$rs->hash;
|
}
|
||||||
}
|
return $url;
|
||||||
catch(Exception $e) { }
|
}
|
||||||
|
|
||||||
return $url;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
?>
|
|
@ -12,142 +12,128 @@
|
|||||||
|
|
||||||
# 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 {
|
||||||
|
if (null === $kut) {
|
||||||
|
throw new Exception('Unknow service');
|
||||||
|
}
|
||||||
|
$url = trim($core->con->escape($_POST['str']));
|
||||||
|
$hash = empty($_POST['custom']) ? null : $_POST['custom'];
|
||||||
|
|
||||||
try
|
if (empty($url)) {
|
||||||
{
|
throw new Exception(__('There is nothing to shorten.'));
|
||||||
if (null === $kut)
|
}
|
||||||
throw new Exception('Unknow service');
|
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;
|
||||||
|
$msg =
|
||||||
|
'<p class="message">' .
|
||||||
|
sprintf(
|
||||||
|
__('Short link for %s is %s') ,
|
||||||
|
'<strong>' . html::escapeHTML($url) .'</strong>',
|
||||||
|
'<a href="' . $new_url . '">' . $new_url . '</a>'
|
||||||
|
) . '</p>';
|
||||||
|
} 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;
|
||||||
|
$msg =
|
||||||
|
'<p class="message">' .
|
||||||
|
sprintf(
|
||||||
|
__('Short link for %s is %s'),
|
||||||
|
'<strong>' . html::escapeHTML($url) . '</strong>',
|
||||||
|
'<a href="' . $new_url . '">' . $new_url . '</a>'
|
||||||
|
) . '</p>';
|
||||||
|
|
||||||
$url = trim($core->con->escape($_POST['str']));
|
# ex: Send new url to messengers
|
||||||
$hash = empty($_POST['custom']) ? null : $_POST['custom'];
|
if (!empty($rs)) {
|
||||||
|
$core->callBehavior('adminAfterKutrlCreate', $core, $rs,__('New short URL'));
|
||||||
if (empty($url))
|
}
|
||||||
throw new Exception(__('There is nothing to shorten.'));
|
}
|
||||||
|
}
|
||||||
if (!$kut->testService())
|
} catch (Exception $e) {
|
||||||
throw new Exception(__('Service is not well configured.'));
|
$core->error->add($e->getMessage());
|
||||||
|
}
|
||||||
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;
|
|
||||||
$msg =
|
|
||||||
'<p class="message">'.
|
|
||||||
sprintf(__('Short link for %s is %s'),
|
|
||||||
'<strong>'.html::escapeHTML($url).'</strong>',
|
|
||||||
'<a href="'.$new_url.'">'.$new_url.'</a>'
|
|
||||||
).'</p>';
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
$msg =
|
|
||||||
'<p class="message">'.
|
|
||||||
sprintf(__('Short link for %s is %s'),
|
|
||||||
'<strong>'.html::escapeHTML($url).'</strong>',
|
|
||||||
'<a href="'.$new_url.'">'.$new_url.'</a>'
|
|
||||||
).'</p>';
|
|
||||||
|
|
||||||
# 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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
<html>
|
<html>
|
||||||
<head><title>kUtRL, '.__('Links shortener').'</title>'.$header.'</head>
|
<head><title>kUtRL, ' . __('Links shortener') . '</title>' . $header . '</head>
|
||||||
<body>
|
<body>
|
||||||
<h2>kUtRL'.
|
<h2>kUtRL' .
|
||||||
' › <a href="'.$p_url.'&part=links">'.__('Links').'</a>'.
|
' › <a href="' . $p_url . '&part=links">' . __('Links') . '</a>' .
|
||||||
' › '.__('New link').
|
' › ' . __('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 {
|
||||||
}
|
echo '
|
||||||
else
|
<form id="create-link" method="post" action="' . $p_url . '">
|
||||||
{
|
|
||||||
echo '
|
|
||||||
<form id="create-link" method="post" action="'.$p_url.'">
|
|
||||||
|
|
||||||
<h3>'.sprintf(__('Shorten link using service "%s"'),$kut->name).'</h3>
|
<h3>' . sprintf(__('Shorten link using service "%s"'), $kut->name) . '</h3>
|
||||||
<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>';
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
echo '
|
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'),'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>';
|
||||||
?>
|
|
@ -12,86 +12,86 @@
|
|||||||
|
|
||||||
# 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 {
|
||||||
|
$pager = new pager($page, $this->rs_count, $nb_per_page, 10);
|
||||||
|
|
||||||
else {
|
$pager->base_url = $url;
|
||||||
$pager = new pager($page,$this->rs_count,$nb_per_page,10);
|
|
||||||
|
|
||||||
$pager->base_url = $url;
|
$html_block =
|
||||||
|
'<table class="clear">' .
|
||||||
|
'<thead>' .
|
||||||
|
'<tr>' .
|
||||||
|
'<th class="nowrap" colspan="2">' . __('Hash') . '</th>' .
|
||||||
|
'<th class="maximal">' . __('Link') . '</th>' .
|
||||||
|
'<th class="nowrap">' . __('Date') . '</th>' .
|
||||||
|
'<th class="nowrap">' . __('Service') . '</th>' .
|
||||||
|
'</tr>' .
|
||||||
|
'</thead>' .
|
||||||
|
'<tbody>%s</tbody>' .
|
||||||
|
'</table>';
|
||||||
|
|
||||||
$html_block =
|
echo '<p>' . __('Page(s)') . ' : ' . $pager->getLinks() . '</p>';
|
||||||
'<table class="clear">'.
|
$blocks = explode('%s', $html_block);
|
||||||
'<thead>'.
|
echo $blocks[0];
|
||||||
'<tr>'.
|
|
||||||
'<th class="nowrap" colspan="2">'.__('Hash').'</th>'.
|
|
||||||
'<th class="maximal">'.__('Link').'</th>'.
|
|
||||||
'<th class="nowrap">'.__('Date').'</th>'.
|
|
||||||
'<th class="nowrap">'.__('Service').'</th>'.
|
|
||||||
'</tr>'.
|
|
||||||
'</thead>'.
|
|
||||||
'<tbody>%s</tbody>'.
|
|
||||||
'</table>';
|
|
||||||
|
|
||||||
echo '<p>'.__('Page(s)').' : '.$pager->getLinks().'</p>';
|
$this->rs->index(((integer)$page - 1) * $nb_per_page);
|
||||||
$blocks = explode('%s',$html_block);
|
$iter = 0;
|
||||||
echo $blocks[0];
|
while ($iter < $nb_per_page) {
|
||||||
|
|
||||||
$this->rs->index(((integer)$page - 1) * $nb_per_page);
|
echo $this->line($url,$iter);
|
||||||
$iter = 0;
|
|
||||||
while ($iter < $nb_per_page) {
|
|
||||||
|
|
||||||
echo $this->line($url,$iter);
|
if ($this->rs->isEnd()) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
$this->rs->moveNext();
|
||||||
|
}
|
||||||
|
$iter++;
|
||||||
|
}
|
||||||
|
echo $blocks[1];
|
||||||
|
echo '<p>' . __('Page(s)') . ' : ' . $pager->getLinks() . '</p>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->rs->isEnd())
|
private function line($url, $loop)
|
||||||
break;
|
{
|
||||||
else
|
$type = $this->rs->kut_type;
|
||||||
$this->rs->moveNext();
|
$hash = $this->rs->kut_hash;
|
||||||
|
|
||||||
$iter++;
|
if (null !== ($o = kutrl::quickService($this->rs->kut_type))) {
|
||||||
}
|
$type = '<a href="' . $o->home . '" title="' . $o->name . '">' . $o->name . '</a>';
|
||||||
echo $blocks[1];
|
$hash = '<a href="' . $o->url_base . $hash . '" title="' . $o->url_base . $hash . '">' . $hash . '</a>';
|
||||||
echo '<p>'.__('Page(s)').' : '.$pager->getLinks().'</p>';
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function line($url,$loop)
|
return
|
||||||
{
|
'<tr class="line">' . "\n" .
|
||||||
$type = $this->rs->kut_type;
|
'<td class="nowrap">' .
|
||||||
$hash = $this->rs->kut_hash;
|
form::checkbox(['entries[' . $loop . ']'], $this->rs->kut_id, 0) .
|
||||||
|
'</td>' .
|
||||||
if (null !== ($o = kutrl::quickService($this->rs->kut_type)))
|
'<td class="nowrap">' .
|
||||||
{
|
$hash .
|
||||||
$type = '<a href="'.$o->home.'" title="'.$o->name.'">'.$o->name.'</a>';
|
"</td>\n" .
|
||||||
$hash = '<a href="'.$o->url_base.$hash.'" title="'.$o->url_base.$hash.'">'.$hash.'</a>';
|
'<td class="maximal">' .
|
||||||
}
|
'<a href="' . $this->rs->kut_url . '">' . $this->rs->kut_url . '</a>' .
|
||||||
|
"</td>\n" .
|
||||||
return
|
'<td class="nowrap">' .
|
||||||
'<tr class="line">'."\n".
|
dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->kut_dt, $this->core->auth->getInfo('user_tz')) .
|
||||||
'<td class="nowrap">'.
|
"</td>\n" .
|
||||||
form::checkbox(array('entries['.$loop.']'),$this->rs->kut_id,0).
|
'<td class="nowrap">' .
|
||||||
'</td>'.
|
$type .
|
||||||
'<td class="nowrap">'.
|
"</td>\n" .
|
||||||
$hash.
|
'</tr>' . "\n";
|
||||||
"</td>\n".
|
}
|
||||||
'<td class="maximal">'.
|
|
||||||
'<a href="'.$this->rs->kut_url.'">'.$this->rs->kut_url.'</a>'.
|
|
||||||
"</td>\n".
|
|
||||||
'<td class="nowrap">'.
|
|
||||||
dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->kut_dt,$this->core->auth->getInfo('user_tz')).
|
|
||||||
"</td>\n".
|
|
||||||
'<td class="nowrap">'.
|
|
||||||
$type.
|
|
||||||
"</td>\n".
|
|
||||||
'</tr>'."\n";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Logs class
|
# Logs class
|
||||||
@ -106,162 +106,158 @@ $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']) {
|
||||||
$nb_per_page = (integer) $_GET['nb'];
|
$show_filters = true;
|
||||||
|
}
|
||||||
|
$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 .
|
||||||
'&tab=list'.
|
'&tab=list' .
|
||||||
'&urlsrv='.$urlsrv.
|
'&urlsrv=' . $urlsrv .
|
||||||
'&sortby='.$sortby.
|
'&sortby=' . $sortby .
|
||||||
'&order='.$order.
|
'&order=' . $order .
|
||||||
'&nb='.$nb_per_page.
|
'&nb=' . $nb_per_page .
|
||||||
'&page=%s';
|
'&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;
|
||||||
|
}
|
||||||
|
$o->remove($rs->kut_url);
|
||||||
|
}
|
||||||
|
|
||||||
if (null === ($o = kutrl::quickService($rs->kut_type))) continue;
|
$core->blog->triggerBlog();
|
||||||
$o->remove($rs->kut_url);
|
http::redirect($p_url . '&part=links&urlsrv=' . $urlsrv . '&sortby=' . $sortby . '&order=' . $order . '&nb=' . $nb_per_page . '&page=' . $page . '&msg=' . $action);
|
||||||
}
|
} catch (Exception $e) {
|
||||||
|
$core->error->add($e->getMessage());
|
||||||
$core->blog->triggerBlog();
|
}
|
||||||
http::redirect($p_url.'&part=links&urlsrv='.$urlsrv.'&sortby='.$sortby.'&order='.$order.'&nb='.$nb_per_page.'&page='.$page.'&msg='.$action);
|
|
||||||
}
|
|
||||||
catch (Exception $e) {
|
|
||||||
$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) {
|
||||||
|
$core->error->add($e->getMessage());
|
||||||
}
|
}
|
||||||
catch (Exception $e)
|
|
||||||
{
|
|
||||||
$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');
|
||||||
}
|
}
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
<html>
|
<html>
|
||||||
<head><title>kUtRL, '.__('Links shortener').'</title>'.
|
<head><title>kUtRL, ' . __('Links shortener') . '</title>' .
|
||||||
"\n<script type=\"text/javascript\"> \n".
|
"\n<script type=\"text/javascript\"> \n" .
|
||||||
"$(function(){ $('.checkboxes-helpers').each(function(){dotclear.checkboxesHelpers(this);}); }); \n".
|
"$(function(){ $('.checkboxes-helpers').each(function(){dotclear.checkboxesHelpers(this);}); }); \n" .
|
||||||
"</script>\n".
|
"</script>\n" .
|
||||||
$header.'</head>
|
$header . '</head>
|
||||||
<body>
|
<body>
|
||||||
<h2>kUtRL'.
|
<h2>kUtRL' .
|
||||||
' › '.__('Links').
|
' › ' . __('Links') .
|
||||||
' - <a class="button" href="'.$p_url.'&part=link">'.__('New link').'</a>'.
|
' - <a class="button" href="' . $p_url . '&part=link">' . __('New link') . '</a>' .
|
||||||
'</h2>'.$msg;
|
'</h2>' . $msg;
|
||||||
|
|
||||||
if (!$show_filters) {
|
if (!$show_filters) {
|
||||||
echo '<p><a id="filter-control" class="form-control" href="#">'.
|
echo '<p><a id="filter-control" class="form-control" href="#">' .
|
||||||
__('Filters').'</a></p>';
|
__('Filters') . '</a></p>';
|
||||||
}
|
}
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
<form action="'.$p_url.'&part=links" method="get" id="filters-form">
|
<form action="' . $p_url . '&part=links" method="get" id="filters-form">
|
||||||
<fieldset><legend>'.__('Filters').'</legend>
|
<fieldset><legend>' . __('Filters') . '</legend>
|
||||||
<div class="three-cols">
|
<div class="three-cols">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<label>'.__('Service:').form::combo('urlsrv',$lst_services_combo,$urlsrv).'
|
<label>' . __('Service:') . form::combo('urlsrv', $lst_services_combo, $urlsrv) . '
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<label>'.__('Order by:').form::combo('sortby',$sortby_combo,$sortby).'
|
<label>' . __('Order by:') . form::combo('sortby', $sortby_combo, $sortby) . '
|
||||||
</label>
|
</label>
|
||||||
<label>'.__('Sort:').form::combo('order',$order_combo,$order).'
|
<label>' . __('Sort:') . form::combo('order', $order_combo, $order) . '
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<p>
|
<p>
|
||||||
<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>
|
||||||
<br class="clear" />
|
<br class="clear" />
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</form>
|
</form>
|
||||||
<form action="'.$p_url.'&part=links" method="post" id="form-actions">';
|
<form action="' . $p_url . '&part=links" method="post" id="form-actions">';
|
||||||
|
|
||||||
$list_current->display($page,$nb_per_page,$pager_base_url);
|
$list_current->display($page, $nb_per_page, $pager_base_url);
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
<div class="two-cols">
|
<div class="two-cols">
|
||||||
<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>
|
||||||
</form>';
|
</form>';
|
||||||
|
|
||||||
dcPage::helpBlock('kUtRL');
|
dcPage::helpBlock('kUtRL');
|
||||||
echo $footer.'</body></html>';
|
echo $footer . '</body></html>';
|
||||||
?>
|
?>
|
@ -12,66 +12,58 @@
|
|||||||
|
|
||||||
# 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§ion='.$section.'&msg='.$action);
|
http::redirect($p_url . '&part=service§ion=' . $section . '&msg=' . $action);
|
||||||
}
|
} catch (Exception $e) {
|
||||||
catch (Exception $e)
|
|
||||||
{
|
|
||||||
$core->error->add($e->getMessage());
|
$core->error->add($e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
<html>
|
<html>
|
||||||
<head><title>kUtRL, '.__('Links shortener').'</title>'.$header.
|
<head><title>kUtRL, ' . __('Links shortener') . '</title>' . $header .
|
||||||
dcPage::jsLoad('index.php?pf=kUtRL/js/service.js').
|
dcPage::jsLoad('index.php?pf=kUtRL/js/service.js') .
|
||||||
"<script type=\"text/javascript\">\n//<![CDATA[\n".
|
"<script type=\"text/javascript\">\n//<![CDATA[\n" .
|
||||||
dcPage::jsVar('jcToolsBox.prototype.section',$section).
|
dcPage::jsVar('jcToolsBox.prototype.section', $section) .
|
||||||
"\n//]]>\n</script>\n".
|
"\n//]]>\n</script>\n" .
|
||||||
'</head>
|
'</head>
|
||||||
<body>
|
<body>
|
||||||
<h2>kUtRL'.
|
<h2>kUtRL' .
|
||||||
' › <a href="'.$p_url.'&part=links">'.__('Links').'</a>'.
|
' › <a href="' . $p_url . '&part=links">' . __('Links') . '</a>' .
|
||||||
' › '.__('Services').
|
' › ' . __('Services') .
|
||||||
' - <a class="button" href="'.$p_url.'&part=link">'.__('New link').'</a>'.
|
' - <a class="button" href="' . $p_url . '&part=link">' . __('New link') . '</a>' .
|
||||||
'</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) :
|
||||||
$img_red.' '.sprintf(__('Failed to test %s API.'),$o->name)
|
$img_red . ' ' . sprintf(__('Failed to test %s API.'), $o->name)
|
||||||
).'</em></p>';
|
) . '</em></p>';
|
||||||
//if ($o->error->flag()) {
|
//if ($o->error->flag()) {
|
||||||
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>';
|
||||||
@ -79,14 +71,13 @@ foreach(kutrl::getServices($core) as $service_id => $service)
|
|||||||
|
|
||||||
echo '
|
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>';
|
||||||
?>
|
|
@ -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'];
|
||||||
@ -37,128 +38,125 @@ if ($default_part == 'setting' && $action == 'savesetting')
|
|||||||
$s_tpl_active = !empty($_POST['s_tpl_active']);
|
$s_tpl_active = !empty($_POST['s_tpl_active']);
|
||||||
$s_admin_entry_default = !empty($_POST['s_admin_entry_default']);
|
$s_admin_entry_default = !empty($_POST['s_admin_entry_default']);
|
||||||
|
|
||||||
$s->put('kutrl_active',$s_active);
|
$s->put('kutrl_active', $s_active);
|
||||||
$s->put('kutrl_plugin_service',$s_plugin_service);
|
$s->put('kutrl_plugin_service', $s_plugin_service);
|
||||||
$s->put('kutrl_admin_service',$s_admin_service);
|
$s->put('kutrl_admin_service', $s_admin_service);
|
||||||
$s->put('kutrl_tpl_service',$s_tpl_service);
|
$s->put('kutrl_tpl_service', $s_tpl_service);
|
||||||
$s->put('kutrl_wiki_service',$s_wiki_service);
|
$s->put('kutrl_wiki_service', $s_wiki_service);
|
||||||
$s->put('kutrl_allow_external_url',$s_allow_external_url);
|
$s->put('kutrl_allow_external_url', $s_allow_external_url);
|
||||||
$s->put('kutrl_tpl_passive',$s_tpl_passive);
|
$s->put('kutrl_tpl_passive', $s_tpl_passive);
|
||||||
$s->put('kutrl_tpl_active',$s_tpl_active);
|
$s->put('kutrl_tpl_active', $s_tpl_active);
|
||||||
$s->put('kutrl_admin_entry_default',$s_admin_entry_default);
|
$s->put('kutrl_admin_entry_default', $s_admin_entry_default);
|
||||||
|
|
||||||
$core->blog->triggerBlog();
|
$core->blog->triggerBlog();
|
||||||
|
|
||||||
http::redirect($p_url.'&part=setting&msg='.$action.'§ion='.$section);
|
http::redirect($p_url . '&part=setting&msg=' . $action . '§ion=' . $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>
|
||||||
<head><title>kUtRL, '.__('Links shortener').'</title>'.$header.
|
<head><title>kUtRL, ' . __('Links shortener') . '</title>' . $header .
|
||||||
dcPage::jsLoad('index.php?pf=kUtRL/js/setting.js').
|
dcPage::jsLoad('index.php?pf=kUtRL/js/setting.js') .
|
||||||
"<script type=\"text/javascript\">\n//<![CDATA[\n".
|
"<script type=\"text/javascript\">\n//<![CDATA[\n" .
|
||||||
dcPage::jsVar('jcToolsBox.prototype.section',$section).
|
dcPage::jsVar('jcToolsBox.prototype.section', $section) .
|
||||||
"\n//]]>\n</script>\n".
|
"\n//]]>\n</script>\n" .
|
||||||
'</head>
|
'</head>
|
||||||
<body>
|
<body>
|
||||||
<h2>kUtRL'.
|
<h2>kUtRL' .
|
||||||
' › <a href="'.$p_url.'&part=links">'.__('Links').'</a>'.
|
' › <a href="' . $p_url . '&part=links">' . __('Links') . '</a>' .
|
||||||
' › '.__('Settings').
|
' › ' . __('Settings') .
|
||||||
' - <a class="button" href="'.$p_url.'&part=link">'.__('New link').'</a>'.
|
' - <a class="button" href="' . $p_url . '&part=link">' . __('New link') . '</a>' .
|
||||||
'</h2>'.$msg.'
|
'</h2>' . $msg . '
|
||||||
<form id="setting-form" method="post" action="'.$p_url.'">
|
<form id="setting-form" method="post" action="' . $p_url . '">
|
||||||
|
|
||||||
<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>
|
||||||
|
|
||||||
<fieldset id="setting-service"><legend>'. __('Default services').'</legend>
|
<fieldset id="setting-service"><legend>' . __('Default services') . '</legend>
|
||||||
<p><label>';
|
<p><label>';
|
||||||
if (!empty($msg)) {
|
if (!empty($msg)) {
|
||||||
if (null !== ($o = kutrl::quickPlace($s_admin_service))) {
|
if (null !== ($o = kutrl::quickPlace($s_admin_service))) {
|
||||||
echo $o->testService() ? $img_green : $img_red;
|
echo $o->testService() ? $img_green : $img_red;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
echo ' '.__('Administration:').'<br />'.
|
echo ' ' . __('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>';
|
||||||
if (!empty($msg)) {
|
if (!empty($msg)) {
|
||||||
if (null !== ($o = kutrl::quickPlace($s_plugin_service))) {
|
if (null !== ($o = kutrl::quickPlace($s_plugin_service))) {
|
||||||
echo $o->testService() ? $img_green : $img_red;
|
echo $o->testService() ? $img_green : $img_red;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
echo ' '.__('Extensions:').'<br />'.
|
echo ' ' . __('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>';
|
||||||
if (!empty($msg)) {
|
if (!empty($msg)) {
|
||||||
if (null !== ($o = kutrl::quickPlace($s_tpl_service))) {
|
if (null !== ($o = kutrl::quickPlace($s_tpl_service))) {
|
||||||
echo $o->testService() ? $img_green : $img_red;
|
echo $o->testService() ? $img_green : $img_red;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
echo ' '.__('Templates:').'<br />'.
|
echo ' ' . __('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>';
|
||||||
if (!empty($msg)) {
|
if (!empty($msg)) {
|
||||||
if (null !== ($o = kutrl::quickPlace($s_wiki_service))) {
|
if (null !== ($o = kutrl::quickPlace($s_wiki_service))) {
|
||||||
echo $o->testService() ? $img_green : $img_red;
|
echo $o->testService() ? $img_green : $img_red;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
echo ' '.__('Contents:').'<br />'.
|
echo ' ' . __('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>
|
||||||
|
|
||||||
<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>';
|
||||||
?>
|
|
@ -12,27 +12,28 @@
|
|||||||
|
|
||||||
# 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'));
|
||||||
|
|
||||||
# from BEHAVIOR kutrlAfterCreateShortUrl in kUtRL/inc/lib.kutrl.srv.php
|
# from BEHAVIOR kutrlAfterCreateShortUrl in kUtRL/inc/lib.kutrl.srv.php
|
||||||
$core->activityReport->addAction(
|
$core->activityReport->addAction(
|
||||||
'kutrl',
|
'kutrl',
|
||||||
'create',
|
'create',
|
||||||
__('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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
|
@ -14,301 +14,244 @@
|
|||||||
|
|
||||||
class kutrlLog
|
class kutrlLog
|
||||||
{
|
{
|
||||||
public $core;
|
public $core;
|
||||||
public $table;
|
public $table;
|
||||||
public $blog;
|
public $blog;
|
||||||
public $con;
|
public $con;
|
||||||
|
|
||||||
public function __construct($core)
|
public function __construct($core)
|
||||||
{
|
{
|
||||||
$this->core = $core;
|
$this->core = $core;
|
||||||
$this->table = $core->prefix.'kutrl';
|
$this->table = $core->prefix . 'kutrl';
|
||||||
$this->blog = $core->con->escape($core->blog->id);
|
$this->blog = $core->con->escape($core->blog->id);
|
||||||
$this->con = $core->con;
|
$this->con = $core->con;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function nextId()
|
public function nextId()
|
||||||
{
|
{
|
||||||
return $this->con->select(
|
return $this->con->select(
|
||||||
'SELECT MAX(kut_id) FROM '.$this->table
|
'SELECT MAX(kut_id) FROM ' . $this->table
|
||||||
)->f(0) + 1;
|
)->f(0) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function insert($url,$hash,$type,$service='kutrl')
|
public function insert($url, $hash, $type, $service = 'kutrl')
|
||||||
{
|
{
|
||||||
$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_id = $this->nextId();
|
$cur->kut_id = $this->nextId();
|
||||||
$cur->blog_id = $this->blog;
|
$cur->blog_id = $this->blog;
|
||||||
$cur->kut_url = (string) $url;
|
$cur->kut_url = (string) $url;
|
||||||
$cur->kut_hash = (string) $hash;
|
$cur->kut_hash = (string) $hash;
|
||||||
$cur->kut_type = (string) $type;
|
$cur->kut_type = (string) $type;
|
||||||
$cur->kut_service = (string) $service;
|
$cur->kut_service = (string) $service;
|
||||||
$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;
|
||||||
|
|
||||||
$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();
|
||||||
{
|
throw $e;
|
||||||
$this->con->unlock();
|
}
|
||||||
throw $e;
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function select($url=null,$hash=null,$type=null,$service='kutrl')
|
public function select($url = null, $hash = null, $type =null, $service = 'kutrl')
|
||||||
{
|
{
|
||||||
//$this->con->writeLock($this->table);
|
//$this->con->writeLock($this->table);
|
||||||
|
|
||||||
$req =
|
$req =
|
||||||
'SELECT kut_id as id, kut_hash as hash, kut_url as url, '.
|
'SELECT kut_id as id, kut_hash as hash, kut_url as url, ' .
|
||||||
'kut_type as type, kut_service as service, kut_counter as counter '.
|
'kut_type as type, kut_service as service, kut_counter as counter ' .
|
||||||
'FROM '.$this->table.' '.
|
'FROM ' . $this->table . ' ' .
|
||||||
"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) {
|
||||||
|
$req .= "AND kut_hash = '" . $this->con->escape($hash) . "' ";
|
||||||
|
}
|
||||||
|
if (null !== $type) {
|
||||||
|
if (is_array($type)) {
|
||||||
|
$req .= "AND kut_type '" . $this->con->in($type) ."' ";
|
||||||
|
} else {
|
||||||
|
$req .= "AND kut_type = '" . $this->con->escape($type) . "' ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (null !== $hash)
|
$req .= 'ORDER BY kut_dt DESC ' . $this->con->limit(1);
|
||||||
$req .= "AND kut_hash = '".$this->con->escape($hash)."' ";
|
|
||||||
|
|
||||||
if (null !== $type) {
|
$rs = $this->con->select($req);
|
||||||
if (is_array($type)) {
|
//$this->con->unlock();
|
||||||
$req .= "AND kut_type '".$this->con->in($type)."' ";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$req .= "AND kut_type = '".$this->con->escape($type)."' ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$req .= 'ORDER BY kut_dt DESC '.$this->con->limit(1);
|
return $rs->isEmpty() ? false : $rs;
|
||||||
|
}
|
||||||
|
|
||||||
$rs = $this->con->select($req);
|
public function clear($id)
|
||||||
//$this->con->unlock();
|
{
|
||||||
|
$id = (integer) $id;
|
||||||
|
|
||||||
return $rs->isEmpty() ? false : $rs;
|
$cur = $this->con->openCursor($this->table);
|
||||||
}
|
$this->con->writeLock($this->table);
|
||||||
|
|
||||||
public function clear($id)
|
try {
|
||||||
{
|
$cur->kut_url = '';
|
||||||
$id = (integer) $id;
|
$cur->kut_dt = date('Y-m-d H:i:s');
|
||||||
|
$cur->kut_counter = 0;
|
||||||
|
|
||||||
$cur = $this->con->openCursor($this->table);
|
$cur->update(
|
||||||
$this->con->writeLock($this->table);
|
"WHERE blog_id='" . $this->blog . "' " .
|
||||||
|
"AND kut_id='" . $id . "' "
|
||||||
|
);
|
||||||
|
$this->con->unlock();
|
||||||
|
|
||||||
try
|
return true;
|
||||||
{
|
} catch (Exception $e) {
|
||||||
$cur->kut_url = '';
|
$this->con->unlock();
|
||||||
$cur->kut_dt = date('Y-m-d H:i:s');
|
throw $e;
|
||||||
$cur->kut_counter = 0;
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$cur->update(
|
public function delete($id)
|
||||||
"WHERE blog_id='".$this->blog."' ".
|
{
|
||||||
"AND kut_id='".$id."' "
|
$id = (integer) $id;
|
||||||
);
|
|
||||||
$this->con->unlock();
|
|
||||||
|
|
||||||
return true;
|
return $this->con->execute(
|
||||||
}
|
'DELETE FROM ' . $this->table . ' ' .
|
||||||
catch (Exception $e)
|
"WHERE blog_id='" . $this->blog . "' " .
|
||||||
{
|
"AND kut_id='" . $id . "' "
|
||||||
$this->con->unlock();
|
);
|
||||||
throw $e;
|
}
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function delete($id)
|
public function counter($id, $do = 'get')
|
||||||
{
|
{
|
||||||
$id = (integer) $id;
|
$id = (integer) $id;
|
||||||
|
|
||||||
return $this->con->execute(
|
$rs = $this->con->select(
|
||||||
'DELETE FROM '.$this->table.' '.
|
'SELECT kut_counter ' .
|
||||||
"WHERE blog_id='".$this->blog."' ".
|
'FROM ' . $this->table . ' ' .
|
||||||
"AND kut_id='".$id."' "
|
"WHERE blog_id='" . $this->blog . "' " .
|
||||||
);
|
"AND kut_id='" . $id . "' "
|
||||||
}
|
);
|
||||||
|
|
||||||
public function counter($id,$do='get')
|
$counter = $rs->isEmpty() ? 0 : $rs->kut_counter;
|
||||||
{
|
|
||||||
$id = (integer) $id;
|
|
||||||
|
|
||||||
$rs = $this->con->select(
|
if ('get' == $do) {
|
||||||
'SELECT kut_counter '.
|
return $counter;
|
||||||
'FROM '.$this->table.' '.
|
} elseif ('up' == $do) {
|
||||||
"WHERE blog_id='".$this->blog."' ".
|
$counter += 1;
|
||||||
"AND kut_id='".$id."' "
|
} elseif ('reset' == $do) {
|
||||||
);
|
$counter = 0;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
$counter = $rs->isEmpty() ? 0 : $rs->kut_counter;
|
$cur = $this->con->openCursor($this->table);
|
||||||
|
$this->con->writeLock($this->table);
|
||||||
|
|
||||||
if ('get' == $do)
|
$cur->kut_counter = (integer) $counter;
|
||||||
{
|
$cur->update(
|
||||||
return $counter;
|
"WHERE blog_id='" . $this->blog . "' " .
|
||||||
}
|
"AND kut_id='" . $id . "'"
|
||||||
elseif ('up' == $do)
|
);
|
||||||
{
|
$this->con->unlock();
|
||||||
$counter += 1;
|
|
||||||
}
|
|
||||||
elseif ('reset' == $do)
|
|
||||||
{
|
|
||||||
$counter = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$cur = $this->con->openCursor($this->table);
|
return $counter;
|
||||||
$this->con->writeLock($this->table);
|
}
|
||||||
|
|
||||||
$cur->kut_counter = (integer) $counter;
|
public function getLogs($p, $count_only = false)
|
||||||
$cur->update(
|
{
|
||||||
"WHERE blog_id='".$this->blog."' ".
|
if ($count_only) {
|
||||||
"AND kut_id='".$id."'"
|
$r = 'SELECT count(S.kut_id) ';
|
||||||
);
|
} else {
|
||||||
$this->con->unlock();
|
$content_req = '';
|
||||||
|
|
||||||
return $counter;
|
if (!empty($p['columns']) && is_array($p['columns'])) {
|
||||||
}
|
$content_req .= implode(', ', $p['columns']) . ', ';
|
||||||
|
}
|
||||||
public function getLogs($p,$count_only=false)
|
$r =
|
||||||
{
|
'SELECT S.kut_id, S.kut_type, S.kut_hash, S.kut_url, ' .
|
||||||
if ($count_only)
|
$content_req . 'S.kut_dt ';
|
||||||
{
|
}
|
||||||
$r = 'SELECT count(S.kut_id) ';
|
$r .= 'FROM ' . $this->table . ' S ';
|
||||||
}
|
if (!empty($p['from'])) {
|
||||||
else
|
$r .= $p['from'] . ' ';
|
||||||
{
|
}
|
||||||
$content_req = '';
|
$r .= "WHERE S.blog_id = '" . $this->blog . "' ";
|
||||||
|
if (isset($p['kut_service'])) {
|
||||||
if (!empty($p['columns']) && is_array($p['columns']))
|
$r .= "AND kut_service='" . $this->con->escape($p['kut_service']) . "' ";
|
||||||
{
|
} else {
|
||||||
$content_req .= implode(', ',$p['columns']).', ';
|
$r .= "AND kut_service='kutrl' ";
|
||||||
}
|
}
|
||||||
$r =
|
if (isset($p['kut_type'])) {
|
||||||
'SELECT S.kut_id, S.kut_type, S.kut_hash, S.kut_url, '.
|
if (is_array($p['kut_type']) && !empty($p['kut_type']))
|
||||||
$content_req.'S.kut_dt ';
|
{
|
||||||
}
|
$r .= 'AND kut_type ' . $this->con->in($p['kut_type']);
|
||||||
|
} elseif ($p['kut_type'] != '') {
|
||||||
$r .= 'FROM '.$this->table.' S ';
|
$r .= "AND kut_type = '" . $this->con->escape($p['kut_type']) . "' ";
|
||||||
|
}
|
||||||
if (!empty($p['from']))
|
}
|
||||||
{
|
if (isset($p['kut_id'])) {
|
||||||
$r .= $p['from'].' ';
|
if (is_array($p['kut_id']) && !empty($p['kut_id'])) {
|
||||||
}
|
$r .= 'AND kut_id ' . $this->con->in($p['kut_id']);
|
||||||
$r .= "WHERE S.blog_id = '".$this->blog."' ";
|
} elseif ($p['kut_id'] != '') {
|
||||||
|
$r .= "AND kut_id = '" . $this->con->escape($p['kut_id']) . "' ";
|
||||||
if (isset($p['kut_service']))
|
}
|
||||||
{
|
}
|
||||||
$r .= "AND kut_service='".$this->con->escape($p['kut_service'])."' ";
|
if (isset($p['kut_hash'])) {
|
||||||
}
|
if (is_array($p['kut_hash']) && !empty($p['kut_hash'])) {
|
||||||
else
|
$r .= 'AND kut_hash ' . $this->con->in($p['kut_hash']);
|
||||||
{
|
} elseif ($p['kut_hash'] != '') {
|
||||||
$r .= "AND kut_service='kutrl' ";
|
$r .= "AND kut_hash = '" . $this->con->escape($p['kut_hash']) . "' ";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (isset($p['kut_type']))
|
if (isset($p['kut_url'])) {
|
||||||
{
|
if (is_array($p['kut_url']) && !empty($p['kut_url'])) {
|
||||||
if (is_array($p['kut_type']) && !empty($p['kut_type']))
|
$r .= 'AND kut_url ' . $this->con->in($p['kut_url']);
|
||||||
{
|
} elseif ($p['kut_url'] != '') {
|
||||||
$r .= 'AND kut_type '.$this->con->in($p['kut_type']);
|
$r .= "AND kut_url = '" . $this->con->escape($p['kut_url']) . "' ";
|
||||||
}
|
}
|
||||||
elseif ($p['kut_type'] != '')
|
}
|
||||||
{
|
if (!empty($p['kut_year'])) {
|
||||||
$r .= "AND kut_type = '".$this->con->escape($p['kut_type'])."' ";
|
$r .=
|
||||||
}
|
'AND ' . $this->con->dateFormat('kut_dt', '%Y') . ' = ' .
|
||||||
}
|
"'" . sprintf('%04d', $p['kut_year']) . "' ";
|
||||||
|
}
|
||||||
if (isset($p['kut_id']))
|
if (!empty($p['kut_month'])) {
|
||||||
{
|
$r .=
|
||||||
if (is_array($p['kut_id']) && !empty($p['kut_id']))
|
'AND ' . $this->con->dateFormat('kut_dt', '%m') . ' = ' .
|
||||||
{
|
"'" . sprintf('%02d', $p['kut_month']) . "' ";
|
||||||
$r .= 'AND kut_id '.$this->con->in($p['kut_id']);
|
}
|
||||||
}
|
if (!empty($p['kut_day'])) {
|
||||||
elseif ($p['kut_id'] != '')
|
$r .=
|
||||||
{
|
'AND ' . $this->con->dateFormat('kut_dt', '%d') . ' = ' .
|
||||||
$r .= "AND kut_id = '".$this->con->escape($p['kut_id'])."' ";
|
"'" . sprintf('%02d', $p['kut_day']) . "' ";
|
||||||
}
|
}
|
||||||
}
|
if (!empty($p['sql'])) {
|
||||||
|
$r .= $p['sql'] . ' ';
|
||||||
if (isset($p['kut_hash']))
|
}
|
||||||
{
|
if (!$count_only) {
|
||||||
if (is_array($p['kut_hash']) && !empty($p['kut_hash']))
|
$r .= empty($p['order']) ?
|
||||||
{
|
'ORDER BY kut_dt DESC ' :
|
||||||
$r .= 'AND kut_hash '.$this->con->in($p['kut_hash']);
|
'ORDER BY ' . $this->con->escape($p['order']) . ' ';
|
||||||
}
|
}
|
||||||
elseif ($p['kut_hash'] != '')
|
if (!$count_only && !empty($p['limit'])) {
|
||||||
{
|
$r .= $this->con->limit($p['limit']);
|
||||||
$r .= "AND kut_hash = '".$this->con->escape($p['kut_hash'])."' ";
|
}
|
||||||
}
|
return $this->con->select($r);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($p['kut_url']))
|
|
||||||
{
|
|
||||||
if (is_array($p['kut_url']) && !empty($p['kut_url']))
|
|
||||||
{
|
|
||||||
$r .= 'AND kut_url '.$this->con->in($p['kut_url']);
|
|
||||||
}
|
|
||||||
elseif ($p['kut_url'] != '')
|
|
||||||
{
|
|
||||||
$r .= "AND kut_url = '".$this->con->escape($p['kut_url'])."' ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($p['kut_year']))
|
|
||||||
{
|
|
||||||
$r .=
|
|
||||||
'AND '.$this->con->dateFormat('kut_dt','%Y').' = '.
|
|
||||||
"'".sprintf('%04d',$p['kut_year'])."' ";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($p['kut_month']))
|
|
||||||
{
|
|
||||||
$r .=
|
|
||||||
'AND '.$this->con->dateFormat('kut_dt','%m').' = '.
|
|
||||||
"'".sprintf('%02d',$p['kut_month'])."' ";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($p['kut_day']))
|
|
||||||
{
|
|
||||||
$r .=
|
|
||||||
'AND '.$this->con->dateFormat('kut_dt','%d').' = '.
|
|
||||||
"'".sprintf('%02d',$p['kut_day'])."' ";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($p['sql']))
|
|
||||||
{
|
|
||||||
$r .= $p['sql'].' ';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$count_only)
|
|
||||||
{
|
|
||||||
$r .= empty($p['order']) ?
|
|
||||||
'ORDER BY kut_dt DESC ' :
|
|
||||||
'ORDER BY '.$this->con->escape($p['order']).' ';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$count_only && !empty($p['limit']))
|
|
||||||
{
|
|
||||||
$r .= $this->con->limit($p['limit']);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->con->select($r);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
?>
|
|
@ -14,241 +14,223 @@
|
|||||||
# A service class must extends this one
|
# A service class must extends this one
|
||||||
class kutrlService
|
class kutrlService
|
||||||
{
|
{
|
||||||
public $core;
|
public $core;
|
||||||
public $error;
|
public $error;
|
||||||
public $settings;
|
public $settings;
|
||||||
public $log;
|
public $log;
|
||||||
|
|
||||||
protected $config = array();
|
protected $config = array();
|
||||||
|
|
||||||
public function __construct($core)
|
public function __construct($core)
|
||||||
{
|
{
|
||||||
$this->core = $core;
|
$this->core = $core;
|
||||||
$this->settings = $core->blog->settings->kUtRL;
|
$this->settings = $core->blog->settings->kUtRL;
|
||||||
$this->log = new kutrlLog($core);
|
$this->log = new kutrlLog($core);
|
||||||
$this->error = new dcError();
|
$this->error = new dcError();
|
||||||
$this->error->setHTMLFormat('%s',"%s\n");
|
$this->error->setHTMLFormat('%s', "%s\n");
|
||||||
|
|
||||||
$this->init();
|
$this->init();
|
||||||
|
|
||||||
// Force setting
|
// Force setting
|
||||||
$allow_external_url = $this->settings->kutrl_allow_external_url;
|
$allow_external_url = $this->settings->kutrl_allow_external_url;
|
||||||
$this->config['$allow_external_url'] = null === $allow_external_url ?
|
$this->config['$allow_external_url'] = null === $allow_external_url ?
|
||||||
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
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
# Magic get for config values
|
# Magic get for config values
|
||||||
public function __get($k)
|
public function __get($k)
|
||||||
{
|
{
|
||||||
return isset($this->config[$k]) ? $this->config[$k] : null;
|
return isset($this->config[$k]) ? $this->config[$k] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Additionnal actions on child start
|
# Additionnal actions on child start
|
||||||
protected function init()
|
protected function init()
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
# Save settings from admin page
|
# Save settings from admin page
|
||||||
public function saveSettings()
|
public function saveSettings()
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Settings form for admin page
|
# Settings form for admin page
|
||||||
public function settingsForm()
|
public function settingsForm()
|
||||||
{
|
{
|
||||||
echo
|
echo
|
||||||
'<p class="form-note">'.
|
'<p class="form-note">' .
|
||||||
__('There is nothing to configure for this service.').
|
__('There is nothing to configure for this service.') .
|
||||||
'</p>';
|
'</p>';
|
||||||
}
|
}
|
||||||
|
|
||||||
# Test if service is well configured
|
# Test if service is well configured
|
||||||
public function testService()
|
public function testService()
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Test if an url is valid
|
# Test if an url is valid
|
||||||
public function isValidUrl($url)
|
public function isValidUrl($url)
|
||||||
{
|
{
|
||||||
return (boolean) filter_var($url,FILTER_VALIDATE_URL);
|
return (boolean) filter_var($url, FILTER_VALIDATE_URL);
|
||||||
}
|
}
|
||||||
|
|
||||||
# Test if an url contents know prefix
|
# Test if an url contents know prefix
|
||||||
public function isServiceUrl($url)
|
public function isServiceUrl($url)
|
||||||
{
|
{
|
||||||
return strpos($url,$this->url_base) === 0;
|
return strpos($url, $this->url_base) === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Test if an url is long enoutgh
|
# Test if an url is long enoutgh
|
||||||
public function isLongerUrl($url)
|
public function isLongerUrl($url)
|
||||||
{
|
{
|
||||||
return ((integer) $this->url_min_len >= $url);
|
return ((integer) $this->url_min_len >= $url);
|
||||||
}
|
}
|
||||||
|
|
||||||
# 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (strpos($url,$protocol) === 0) return true;
|
# Test if an url is from current blog
|
||||||
}
|
public function isBlogUrl($url)
|
||||||
return false;
|
{
|
||||||
}
|
$base = $this->core->blog->url;
|
||||||
|
$url = substr($url, 0, strlen($base));
|
||||||
|
|
||||||
# Test if an url is from current blog
|
return $url == $base;
|
||||||
public function isBlogUrl($url)
|
}
|
||||||
{
|
|
||||||
$base = $this->core->blog->url;
|
|
||||||
$url = substr($url,0,strlen($base));
|
|
||||||
|
|
||||||
return $url == $base;
|
# Test if an url is know
|
||||||
}
|
public function isKnowUrl($url)
|
||||||
|
{
|
||||||
|
return $this->log->select($url, null, $this->id, 'kutrl');
|
||||||
|
}
|
||||||
|
|
||||||
# Test if an url is know
|
# Test if an custom short url is know
|
||||||
public function isKnowUrl($url)
|
public function isKnowHash($hash)
|
||||||
{
|
{
|
||||||
return $this->log->select($url,null,$this->id,'kutrl');
|
return $this->log->select(null, $hash, $this->id, 'kutrl');
|
||||||
}
|
}
|
||||||
|
|
||||||
# Test if an custom short url is know
|
# Create hash from url
|
||||||
public function isKnowHash($hash)
|
public function hash($url, $hash = null)
|
||||||
{
|
{
|
||||||
return $this->log->select(null,$hash,$this->id,'kutrl');
|
$url = trim($this->core->con->escape($url));
|
||||||
}
|
if ('undefined' === $this->id) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ($hash && !$this->allow_custom_hash) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ($this->isServiceUrl($url)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!$this->isLongerUrl($url)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!$this->allow_external_url && $this->isBlogUrl($url)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ($hash && false !== ($rs = $this->isKnowHash($hash))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (false === ($rs = $this->isKnowUrl($url))) {
|
||||||
|
if (false === ($rs = $this->createHash($url, $hash))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
# Create hash from url
|
$this->log->insert($rs->url, $rs->hash, $rs->type, 'kutrl');
|
||||||
public function hash($url,$hash=null)
|
$this->core->blog->triggerBlog();
|
||||||
{
|
|
||||||
$url = trim($this->core->con->escape($url));
|
|
||||||
if ('undefined' === $this->id)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if ($hash && !$this->allow_custom_hash)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if ($this->isServiceUrl($url))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!$this->isLongerUrl($url))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!$this->allow_external_url && $this->isBlogUrl($url))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if ($hash && false !== ($rs = $this->isKnowHash($hash)))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (false === ($rs = $this->isKnowUrl($url)))
|
|
||||||
{
|
|
||||||
if (false === ($rs = $this->createHash($url,$hash)))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->log->insert($rs->url,$rs->hash,$rs->type,'kutrl');
|
# --BEHAVIOR-- kutrlAfterCreateShortUrl
|
||||||
$this->core->blog->triggerBlog();
|
$this->core->callBehavior('kutrlAfterCreateShortUrl', $rs);
|
||||||
|
|
||||||
|
}
|
||||||
|
return $rs;
|
||||||
|
}
|
||||||
|
|
||||||
# --BEHAVIOR-- kutrlAfterCreateShortUrl
|
# Create a hash for a given url (and its custom hash)
|
||||||
$this->core->callBehavior('kutrlAfterCreateShortUrl',$rs);
|
public function createHash($url, $hash = null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Remove an url from list of know urls
|
||||||
|
public function remove($url)
|
||||||
|
{
|
||||||
|
if (!($rs = $this->isKnowUrl($url))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$this->deleteUrl($url);
|
||||||
|
$this->log->delete($rs->id);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
# Delete url on service (second argument really delete urls)
|
||||||
return $rs;
|
public function deleteUrl($url, $delete = false)
|
||||||
}
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
# Create a hash for a given url (and its custom hash)
|
# Retrieve long url from hash
|
||||||
public function createHash($url,$hash=null)
|
public function getUrl($hash)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Remove an url from list of know urls
|
# Post request
|
||||||
public function remove($url)
|
public static function post($server, $data, $verbose = true, $get = false, $headers = [])
|
||||||
{
|
{
|
||||||
if (!($rs = $this->isKnowUrl($url))) return false;
|
$url = (string) $server;
|
||||||
echo 'la';
|
$client = netHttp::initClient($url, $url);
|
||||||
$this->deleteUrl($url);
|
$client->setUserAgent('kUtRL - http://kutrl.fr');
|
||||||
$this->log->delete($rs->id);
|
$client->setPersistReferers(false);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Delete url on service (second argument really delete urls)
|
if (is_array($headers) && !empty($headers)) {
|
||||||
public function deleteUrl($url,$delete=false)
|
foreach($headers as $header) {
|
||||||
{
|
$client->setMoreHeader($header);
|
||||||
return null;
|
}
|
||||||
}
|
}
|
||||||
|
if ($get) {
|
||||||
# Retrieve long url from hash
|
$client->get($url, $data);
|
||||||
public function getUrl($hash)
|
} else {
|
||||||
{
|
$client->post($url, $data);
|
||||||
return false;
|
}
|
||||||
}
|
if (!$verbose && $client->getStatus() != 200) {
|
||||||
|
return false;
|
||||||
# Post request
|
}
|
||||||
public static function post($server,$data,$verbose=true,$get=false,$headers=array())
|
if ($verbose) {
|
||||||
{
|
return $client->getContent();
|
||||||
$url = (string) $server;
|
}
|
||||||
$client = netHttp::initClient($url,$url);
|
return true;
|
||||||
$client->setUserAgent('kUtRL - http://kutrl.fr');
|
}
|
||||||
$client->setPersistReferers(false);
|
|
||||||
|
|
||||||
if (is_array($headers) && !empty($headers))
|
|
||||||
{
|
|
||||||
foreach($headers as $header)
|
|
||||||
{
|
|
||||||
$client->setMoreHeader($header);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($get)
|
|
||||||
{
|
|
||||||
$client->get($url,$data);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$client->post($url,$data);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$verbose && $client->getStatus() != 200)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($verbose)
|
|
||||||
{
|
|
||||||
return $client->getContent();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
?>
|
|
@ -12,69 +12,66 @@
|
|||||||
|
|
||||||
# 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
|
||||||
{
|
{
|
||||||
public static function coreInitWiki($wiki2xhtml)
|
public static function coreInitWiki($wiki2xhtml)
|
||||||
{
|
{
|
||||||
global $core;
|
global $core;
|
||||||
$s = $core->blog->settings->kUtRL;
|
$s = $core->blog->settings->kUtRL;
|
||||||
|
|
||||||
# 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 null;
|
||||||
|
}
|
||||||
|
foreach($kut->allow_protocols as $protocol) {
|
||||||
|
$wiki2xhtml->registerFunction(
|
||||||
|
'url:' . $protocol,
|
||||||
|
['kutrlWiki', 'transform']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (null === ($kut = kutrl::quickPlace('wiki'))) return;
|
public static function transform($url, $content)
|
||||||
|
{
|
||||||
|
global $core;
|
||||||
|
$s = $core->blog->settings->kUtRL;
|
||||||
|
|
||||||
foreach($kut->allow_protocols as $protocol)
|
if (!$s->kutrl_active) {
|
||||||
{
|
return null;
|
||||||
$wiki2xhtml->registerFunction(
|
}
|
||||||
'url:'.$protocol,
|
if (null === ($kut = kutrl::quickPlace('wiki'))) {
|
||||||
array('kutrlWiki','transform')
|
return [];
|
||||||
);
|
}
|
||||||
}
|
# Test if long url exists
|
||||||
}
|
$is_new = false;
|
||||||
|
$rs = $kut->isKnowUrl($url);
|
||||||
|
if (!$rs) {
|
||||||
|
$is_new = true;
|
||||||
|
$rs = $kut->hash($url);
|
||||||
|
}
|
||||||
|
if (!$rs) {
|
||||||
|
return [];
|
||||||
|
} else {
|
||||||
|
$res = [];
|
||||||
|
$testurl = strlen($rs->url) > 35 ? substr($rs->url, 0, 35) . '...' : $rs->url;
|
||||||
|
$res['url'] = $kut->url_base . $rs->hash;
|
||||||
|
$res['title'] = sprintf(__('%s (Shorten with %s)'), $rs->url, __($kut->name));
|
||||||
|
if ($testurl == $content) $res['content'] = $res['url'];
|
||||||
|
|
||||||
public static function transform($url,$content)
|
# ex: Send new url to messengers
|
||||||
{
|
if (!empty($rs)) {
|
||||||
global $core;
|
$core->callBehavior('wikiAfterKutrlCreate', $core, $rs, __('New short URL'));
|
||||||
$s = $core->blog->settings->kUtRL;
|
}
|
||||||
|
return $res;
|
||||||
if (!$s->kutrl_active) return;
|
}
|
||||||
|
}
|
||||||
if (null === ($kut = kutrl::quickPlace('wiki'))) return array();
|
|
||||||
|
|
||||||
# Test if long url exists
|
|
||||||
$is_new = false;
|
|
||||||
$rs = $kut->isKnowUrl($url);
|
|
||||||
if (!$rs)
|
|
||||||
{
|
|
||||||
$is_new = true;
|
|
||||||
$rs = $kut->hash($url);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$rs)
|
|
||||||
{
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$res = array();
|
|
||||||
$testurl = strlen($rs->url) > 35 ? substr($rs->url,0,35).'...' : $rs->url;
|
|
||||||
$res['url'] = $kut->url_base.$rs->hash;
|
|
||||||
$res['title'] = sprintf(__('%s (Shorten with %s)'),$rs->url,__($kut->name));
|
|
||||||
if ($testurl == $content) $res['content'] = $res['url'];
|
|
||||||
|
|
||||||
# ex: Send new url to messengers
|
|
||||||
if (!empty($rs))
|
|
||||||
{
|
|
||||||
$core->callBehavior('wikiAfterKutrlCreate',$core,$rs,__('New short URL'));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $res;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
?>
|
|
Loading…
Reference in New Issue
Block a user