Adapt plugins for new dashboard widget style
- Add new class .dashboard_widget to apply necessary styles - Remove obsolete plugin JS to cycle odd/even classes Note: I have no idea why the diff for linktrimmer is huge. Might have been encoded utf-8 before? Now it's iso-8859-1. References s9y/Serendipity#297
This commit is contained in:
parent
c97fa0ab47
commit
81f20690af
|
@ -27,7 +27,7 @@ class serendipity_event_adminnotes extends serendipity_event {
|
|||
'php' => '4.1.0'
|
||||
));
|
||||
|
||||
$propbag->add('version', '0.12');
|
||||
$propbag->add('version', '0.13');
|
||||
$propbag->add('author', 'Garvin Hicking, Matthias Mees');
|
||||
$propbag->add('stackable', false);
|
||||
$propbag->add('configuration', array('feedback', 'limit', 'html', 'markup', 'cutoff'));
|
||||
|
@ -470,11 +470,6 @@ function fulltext_toggle(id) {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
$(document).ready(function () {
|
||||
var count_quicknote_cycle = $('#dashboard > section.quick_list').length;
|
||||
var quicknote_cycled = (count_quicknote_cycle % 2) ? 'odd' : 'even';
|
||||
$('#dashboard_quicknotes').addClass(quicknote_cycled);
|
||||
});
|
||||
/* serendipity_event_adminnotes (quicknotes) end */
|
||||
|
||||
<?php
|
||||
|
@ -528,7 +523,7 @@ function fulltext_toggle(id) {
|
|||
if (is_array($notes)) {
|
||||
?>
|
||||
|
||||
<section id="dashboard_quicknotes" class="equal_heights quick_list">
|
||||
<section id="dashboard_quicknotes" class="equal_heights quick_list dashboard_widget">
|
||||
<h3><?php echo PLUGIN_ADMINNOTES_TITLE ?></h3>
|
||||
<ol class="plainList">
|
||||
<?php
|
||||
|
|
|
@ -1,113 +1,108 @@
|
|||
{if $linktrimmer_external}
|
||||
<!doctype html>
|
||||
<!--[if IE 8]> <html class="no-js lt-ie9" lang="{$lang}"> <![endif]-->
|
||||
<!--[if gt IE 8]><!--> <html class="no-js" lang="{$lang}"> <!--<![endif]-->
|
||||
<head>
|
||||
<meta charset="{$CONST.LANG_CHARSET}">
|
||||
<title>{$CONST.PLUGIN_EVENT_AMAZONCHOOSER_MEDIA_BUTTON}</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" href="{$serendipityBaseURL}serendipity.css.php?serendipity[css_mode]=serendipity_admin.css">
|
||||
<!--[if lte IE 8]>
|
||||
<link rel="stylesheet" href="{serendipity_getFile file='admin/oldie.css'}">
|
||||
<![endif]-->
|
||||
<script src="{serendipity_getFile file='admin/js/modernizr-2.8.1.min.js'}"></script>
|
||||
|
||||
<style>{* popup only classes *}
|
||||
.serendipity_linktrimmer_page .linktrimmer {
|
||||
display: block;
|
||||
margin: 1em auto auto;
|
||||
}
|
||||
#main_linktrimmer {
|
||||
border: 1px solid #BBB;
|
||||
background: none repeat scroll 0% 0% #EEE;
|
||||
padding: 0.75em;
|
||||
margin: 0px 0px 1em;
|
||||
}
|
||||
#main_linktrimmer legend {
|
||||
border: 1px solid #72878A;
|
||||
background: none repeat scroll 0% 0% #DDD;
|
||||
padding: 2px 5px;
|
||||
}
|
||||
#linktrimmer_url.input_textbox { width: inherit; }
|
||||
</style>
|
||||
</head>
|
||||
<body id="serendipity_admin_page" class="serendipity_linktrimmer_page">
|
||||
<main id="workspace" class="clearfix">
|
||||
<div id="content" class="clearfix">
|
||||
{/if}
|
||||
|
||||
{if $linktrimmer_external}
|
||||
<div class="linktrimmer">
|
||||
{else}
|
||||
<section id="dashboard_linktrimmer" class="equal_heights quick_list">
|
||||
<h3>{$CONST.PLUGIN_LINKTRIMMER_NAME}</h3>
|
||||
{/if}
|
||||
<form action="" method="post">
|
||||
<input type="hidden" name="txtarea" value="{$linktrimmer_txtarea|escape:'url'}">
|
||||
<fieldset id="main_linktrimmer" class="">
|
||||
{if $linktrimmer_external}
|
||||
<legend>{$CONST.PLUGIN_LINKTRIMMER_NAME}</legend>
|
||||
{/if}
|
||||
|
||||
{if $linktrimmer_error}
|
||||
<span class="msg_error"><span class="icon-attention-circled"></span> {$CONST.PLUGIN_LINKTRIMMER_ERROR}</span>
|
||||
{/if}
|
||||
|
||||
<div class="form_field">
|
||||
<label for="linktrimmer_url">{$CONST.PLUGIN_LINKTRIMMER_ENTER}</label>
|
||||
<input id="linktrimmer_url" class="input_textbox" type="text" value="" name="linktrimmer_url" placeholder="http://www.s9y.org">
|
||||
{if $linktrimmer_external === false}
|
||||
</div>
|
||||
|
||||
<div class="form_field">
|
||||
{/if}
|
||||
<label for="linktrimmer_hash">{$CONST.PLUGIN_LINKTRIMMER_HASH}</label>
|
||||
<input id="linktrimmer_hash" class="input_textbox" type="text" value="" name="linktrimmer_hash" size="14">
|
||||
|
||||
<input type="submit" name="submit" value="{$CONST.GO}" class="input_button">
|
||||
</div>
|
||||
|
||||
{if $linktrimmer_url != '' && $linktrimmer_external}
|
||||
<script>
|
||||
{if !$linktrimmer_ispopup}
|
||||
window.parent.parent.serendipity.serendipity_imageSelector_addToBody('<a href="{$linktrimmer_url|escape}" title="{$linktrimmer_origurl|escape}">{$linktrimmer_origurl|escape}</a>', '{$linktrimmer_txtarea|escape}');
|
||||
window.parent.parent.$.magnificPopup.close();
|
||||
{else}
|
||||
self.opener.serendipity_imageSelector_addToBody('<a href="{$linktrimmer_url|escape}" title="{$linktrimmer_origurl|escape}">{$linktrimmer_origurl|escape}</a>', '{$linktrimmer_txtarea|escape}');
|
||||
self.close();
|
||||
{/if}
|
||||
</script>
|
||||
{elseif $linktrimmer_url != ''}
|
||||
<div class="form_field">
|
||||
<label for="linktrimmer_result">{$CONST.PLUGIN_LINKTRIMMER_RESULT}</label>
|
||||
<input id="linktrimmer_result" class="input_textbox" type="text" value="{$linktrimmer_url|escape}" name="linktrimmer_result">
|
||||
<script>
|
||||
document.getElementById('linktrimmer_result').select();
|
||||
document.getElementById('linktrimmer_result').focus();
|
||||
</script>
|
||||
</div>
|
||||
{else}
|
||||
<script>
|
||||
document.getElementById('linktrimmer_url').select();
|
||||
document.getElementById('linktrimmer_url').focus();
|
||||
</script>
|
||||
{/if}
|
||||
</fieldset>
|
||||
</form>
|
||||
{if $linktrimmer_external}
|
||||
</div>
|
||||
{else}
|
||||
</section>
|
||||
<script>
|
||||
var count = $('#dashboard > section.quick_list').length;
|
||||
var cycot = (count % 2) ? 'odd' : 'even';
|
||||
$('#dashboard_linktrimmer').addClass(cycot);
|
||||
</script>
|
||||
{/if}
|
||||
|
||||
{if $linktrimmer_external}
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
{/if}
|
||||
{if $linktrimmer_external}
|
||||
<!doctype html>
|
||||
<!--[if IE 8]> <html class="no-js lt-ie9" lang="{$lang}"> <![endif]-->
|
||||
<!--[if gt IE 8]><!--> <html class="no-js" lang="{$lang}"> <!--<![endif]-->
|
||||
<head>
|
||||
<meta charset="{$CONST.LANG_CHARSET}">
|
||||
<title>{$CONST.PLUGIN_EVENT_AMAZONCHOOSER_MEDIA_BUTTON}</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" href="{$serendipityBaseURL}serendipity.css.php?serendipity[css_mode]=serendipity_admin.css">
|
||||
<!--[if lte IE 8]>
|
||||
<link rel="stylesheet" href="{serendipity_getFile file='admin/oldie.css'}">
|
||||
<![endif]-->
|
||||
<script src="{serendipity_getFile file='admin/js/modernizr-2.8.3.min.js'}"></script>
|
||||
|
||||
<style>{* popup only classes *}
|
||||
.serendipity_linktrimmer_page .linktrimmer {
|
||||
display: block;
|
||||
margin: 1em auto auto;
|
||||
}
|
||||
#main_linktrimmer {
|
||||
border: 1px solid #BBB;
|
||||
background: none repeat scroll 0% 0% #EEE;
|
||||
padding: 0.75em;
|
||||
margin: 0px 0px 1em;
|
||||
}
|
||||
#main_linktrimmer legend {
|
||||
border: 1px solid #72878A;
|
||||
background: none repeat scroll 0% 0% #DDD;
|
||||
padding: 2px 5px;
|
||||
}
|
||||
#linktrimmer_url.input_textbox { width: inherit; }
|
||||
</style>
|
||||
</head>
|
||||
<body id="serendipity_admin_page" class="serendipity_linktrimmer_page">
|
||||
<main id="workspace" class="clearfix">
|
||||
<div id="content" class="clearfix">
|
||||
{/if}
|
||||
|
||||
{if $linktrimmer_external}
|
||||
<div class="linktrimmer">
|
||||
{else}
|
||||
<section id="dashboard_linktrimmer" class="equal_heights quick_list dashboard_widget">
|
||||
<h3>{$CONST.PLUGIN_LINKTRIMMER_NAME}</h3>
|
||||
{/if}
|
||||
<form action="" method="post">
|
||||
<input type="hidden" name="txtarea" value="{$linktrimmer_txtarea|escape:'url'}">
|
||||
<fieldset id="main_linktrimmer" class="">
|
||||
{if $linktrimmer_external}
|
||||
<legend>{$CONST.PLUGIN_LINKTRIMMER_NAME}</legend>
|
||||
{/if}
|
||||
|
||||
{if $linktrimmer_error}
|
||||
<span class="msg_error"><span class="icon-attention-circled"></span> {$CONST.PLUGIN_LINKTRIMMER_ERROR}</span>
|
||||
{/if}
|
||||
|
||||
<div class="form_field">
|
||||
<label for="linktrimmer_url">{$CONST.PLUGIN_LINKTRIMMER_ENTER}</label>
|
||||
<input id="linktrimmer_url" class="input_textbox" type="text" value="" name="linktrimmer_url" placeholder="http://www.s9y.org">
|
||||
{if $linktrimmer_external === false}
|
||||
</div>
|
||||
|
||||
<div class="form_field">
|
||||
{/if}
|
||||
<label for="linktrimmer_hash">{$CONST.PLUGIN_LINKTRIMMER_HASH}</label>
|
||||
<input id="linktrimmer_hash" class="input_textbox" type="text" value="" name="linktrimmer_hash" size="14">
|
||||
|
||||
<input type="submit" name="submit" value="{$CONST.GO}" class="input_button">
|
||||
</div>
|
||||
|
||||
{if $linktrimmer_url != '' && $linktrimmer_external}
|
||||
<script>
|
||||
{if !$linktrimmer_ispopup}
|
||||
window.parent.parent.serendipity.serendipity_imageSelector_addToBody('<a href="{$linktrimmer_url|escape}" title="{$linktrimmer_origurl|escape}">{$linktrimmer_origurl|escape}</a>', '{$linktrimmer_txtarea|escape}');
|
||||
window.parent.parent.$.magnificPopup.close();
|
||||
{else}
|
||||
self.opener.serendipity_imageSelector_addToBody('<a href="{$linktrimmer_url|escape}" title="{$linktrimmer_origurl|escape}">{$linktrimmer_origurl|escape}</a>', '{$linktrimmer_txtarea|escape}');
|
||||
self.close();
|
||||
{/if}
|
||||
</script>
|
||||
{elseif $linktrimmer_url != ''}
|
||||
<div class="form_field">
|
||||
<label for="linktrimmer_result">{$CONST.PLUGIN_LINKTRIMMER_RESULT}</label>
|
||||
<input id="linktrimmer_result" class="input_textbox" type="text" value="{$linktrimmer_url|escape}" name="linktrimmer_result">
|
||||
<script>
|
||||
document.getElementById('linktrimmer_result').select();
|
||||
document.getElementById('linktrimmer_result').focus();
|
||||
</script>
|
||||
</div>
|
||||
{else}
|
||||
<script>
|
||||
document.getElementById('linktrimmer_url').select();
|
||||
document.getElementById('linktrimmer_url').focus();
|
||||
</script>
|
||||
{/if}
|
||||
</fieldset>
|
||||
</form>
|
||||
{if $linktrimmer_external}
|
||||
</div>
|
||||
{else}
|
||||
</section>
|
||||
{/if}
|
||||
|
||||
{if $linktrimmer_external}
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
{/if}
|
||||
|
|
|
@ -1,378 +1,378 @@
|
|||
<?php #
|
||||
|
||||
if (IN_serendipity !== true) {
|
||||
die ("Don't hack!");
|
||||
}
|
||||
|
||||
// Probe for a language include with constants. Still include defines later on, if some constants were missing
|
||||
$probelang = dirname(__FILE__) . '/' . $serendipity['charset'] . 'lang_' . $serendipity['lang'] . '.inc.php';
|
||||
if (file_exists($probelang)) {
|
||||
include $probelang;
|
||||
}
|
||||
|
||||
include_once dirname(__FILE__) . '/lang_en.inc.php';
|
||||
|
||||
class serendipity_event_linktrimmer extends serendipity_event {
|
||||
var $debug;
|
||||
|
||||
function introspect(&$propbag) {
|
||||
global $serendipity;
|
||||
|
||||
$propbag->add('name', PLUGIN_LINKTRIMMER_NAME);
|
||||
$propbag->add('description', PLUGIN_LINKTRIMMER_DESC);
|
||||
$propbag->add('requirements', array(
|
||||
'serendipity' => '1.3',
|
||||
'smarty' => '2.6.7',
|
||||
'php' => '4.1.0'
|
||||
));
|
||||
|
||||
$propbag->add('version', '1.6.2');
|
||||
$propbag->add('author', 'Garvin Hicking, Ian');
|
||||
$propbag->add('stackable', false);
|
||||
$propbag->add('configuration', array('prefix', 'frontpage', 'domain'));
|
||||
$propbag->add('event_hooks', array(
|
||||
'backend_frontpage_display' => true,
|
||||
'css_backend' => true,
|
||||
'frontend_configure' => true,
|
||||
'backend_dashboard' => true,
|
||||
'backend_entry_toolbar_extended' => true,
|
||||
'backend_entry_toolbar_body' => true,
|
||||
'backend_wysiwyg' => true,
|
||||
'external_plugin' => true,
|
||||
|
||||
)
|
||||
);
|
||||
#$this->dependencies = array('serendipity_event_jquery' => 'keep');
|
||||
$propbag->add('groups', array('BACKEND_FEATURES'));
|
||||
}
|
||||
|
||||
function introspect_config_item($name, &$propbag) {
|
||||
global $serendipity;
|
||||
|
||||
switch($name) {
|
||||
case 'prefix':
|
||||
$propbag->add('type', 'string');
|
||||
$propbag->add('name', PLUGIN_LINKTRIMMER_LINKPREFIX);
|
||||
$propbag->add('description', PLUGIN_LINKTRIMMER_LINKPREFIX_DESC);
|
||||
$propbag->add('default', 'l');
|
||||
break;
|
||||
|
||||
case 'frontpage':
|
||||
$propbag->add('type', 'boolean');
|
||||
$propbag->add('name', PLUGIN_LINKTRIMMER_FRONTPAGE_OPTION);
|
||||
$propbag->add('description', '');
|
||||
$propbag->add('default', 'true');
|
||||
break;
|
||||
|
||||
case 'domain':
|
||||
$propbag->add('type', 'string');
|
||||
$propbag->add('name', PLUGIN_LINKTRIMMER_DOMAIN);
|
||||
$propbag->add('description', PLUGIN_LINKTRIMMER_DOMAIN_DESC);
|
||||
$propbag->add('default', $serendipity['baseURL']);
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function setupDB() {
|
||||
global $serendipity;
|
||||
|
||||
if (serendipity_db_bool($this->get_config('db_built_1', false))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (preg_match('@mysql@i', $serendipity['dbType'])) {
|
||||
$sql = "CREATE TABLE {$serendipity['dbPrefix']}linktrimmer (
|
||||
id {AUTOINCREMENT} {PRIMARY},
|
||||
hash varchar(32) collate latin1_general_cs,
|
||||
url text
|
||||
);";
|
||||
} else {
|
||||
$sql = "CREATE TABLE {$serendipity['dbPrefix']}linktrimmer (
|
||||
id {AUTOINCREMENT} {PRIMARY},
|
||||
hash varchar(32),
|
||||
url text
|
||||
);";
|
||||
}
|
||||
|
||||
serendipity_db_schema_import($sql);
|
||||
|
||||
$sql = "CREATE INDEX linkidx ON {$serendipity['dbPrefix']}linktrimmer (hash)";
|
||||
serendipity_db_schema_import($sql);
|
||||
|
||||
$this->set_config('db_built_1', 'true');
|
||||
}
|
||||
|
||||
function generate_content(&$title) {
|
||||
$title = PLUGIN_LINKTRIMMER_NAME;
|
||||
}
|
||||
|
||||
static function base62($var) {
|
||||
static $base_characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
||||
|
||||
$stack = array();
|
||||
while (bccomp($var, 0) != 0) {
|
||||
$remainder = bcmod($var, 62);
|
||||
$var = bcdiv(bcsub($var, $remainder), 62);
|
||||
|
||||
array_push($stack, $base_characters[$remainder]);
|
||||
}
|
||||
|
||||
return implode('', array_reverse($stack));
|
||||
}
|
||||
|
||||
static function lookup($url, $custom_hash = '', $pref = '') {
|
||||
global $serendipity;
|
||||
|
||||
$custom_hash = trim($custom_hash);
|
||||
$url = trim($url);
|
||||
|
||||
if (!preg_match('@https?://@i', $url)) {
|
||||
$url = 'http://' . $url;
|
||||
}
|
||||
|
||||
$res = serendipity_db_query("SELECT hash FROM {$serendipity['dbPrefix']}linktrimmer WHERE url = '" . serendipity_db_escape_string($url) . "' LIMIT 1", true, 'assoc');
|
||||
if (!is_array($res) || empty($res['hash'])) {
|
||||
|
||||
if (!empty($custom_hash)) {
|
||||
$res = serendipity_db_query("SELECT hash FROM {$serendipity['dbPrefix']}linktrimmer WHERE hash = '" . serendipity_db_escape_string($custom_hash) . "' LIMIT 1", true, 'assoc');
|
||||
if (is_array($res) && !empty($res['hash'])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$hash = serendipity_event_linktrimmer::create($url, $custom_hash);
|
||||
if (empty($hash)) {
|
||||
return false;
|
||||
} else {
|
||||
return $pref . $hash;
|
||||
}
|
||||
}
|
||||
|
||||
return $pref . $res['hash'];
|
||||
}
|
||||
|
||||
static function create($url, $hash = '') {
|
||||
global $serendipity;
|
||||
|
||||
serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}linktrimmer (url) VALUES ('" . serendipity_db_escape_string($url) . "')");
|
||||
$id = serendipity_db_insert_id();
|
||||
|
||||
if (empty($id)) return false;
|
||||
|
||||
if (empty($hash)) {
|
||||
$hash = serendipity_event_linktrimmer::base62($id);
|
||||
}
|
||||
|
||||
serendipity_db_query("UPDATE {$serendipity['dbPrefix']}linktrimmer
|
||||
SET hash = '" . $hash . "'
|
||||
WHERE id = " . (int)$id);
|
||||
|
||||
return $hash;
|
||||
}
|
||||
|
||||
function show($external = false) {
|
||||
global $serendipity;
|
||||
|
||||
if (IN_serendipity !== true) {
|
||||
die ("Don't hack!");
|
||||
}
|
||||
|
||||
if (!is_object($serendipity['smarty'])) {
|
||||
serendipity_smarty_init();
|
||||
}
|
||||
|
||||
$this->setupDB();
|
||||
|
||||
$pref = $this->get_config('domain') . $this->get_config('prefix') . '/';
|
||||
if ($this->get_config('domain') == $serendipity['baseURL']) {
|
||||
$pref = $this->get_config('domain') . $this->get_config('prefix') . '/';
|
||||
} else {
|
||||
$pref = $this->get_config('domain');
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['submit']) && !empty($_REQUEST['linktrimmer_url'])) {
|
||||
$url = $this->lookup($_REQUEST['linktrimmer_url'], $_REQUEST['linktrimmer_hash'], $pref);
|
||||
if ($url == false) {
|
||||
$error = PLUGIN_LINKTRIMMER_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
$serendipity['smarty']->assign(array(
|
||||
'linktrimmer_ispopup' => $serendipity['enablePopup'],
|
||||
'linktrimmer_error' => $error,
|
||||
'linktrimmer_url' => $url,
|
||||
'linktrimmer_origurl' => $_REQUEST['linktrimmer_url'],
|
||||
'linktrimmer_external' => $external,
|
||||
'linktrimmer_txtarea' => $_REQUEST['txtarea']
|
||||
));
|
||||
|
||||
if ($serendipity['version'][0] > '1') {
|
||||
echo $this->parseTemplate('plugin_linktrimmer.tpl');
|
||||
} else {
|
||||
echo $this->parseTemplate('plugin_linktrimmer_old.tpl');
|
||||
}
|
||||
}
|
||||
|
||||
function generate_button ($txtarea) {
|
||||
global $serendipity;
|
||||
if (!isset($txtarea)) {
|
||||
$txtarea = 'body';
|
||||
}
|
||||
$link = ($serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '') . 'plugin/linktrimmer' . ($serendipity['rewrite'] != 'none' ? '?' : '&') . 'txtarea=' . $txtarea;
|
||||
if ($serendipity['version'][0] > '1') {
|
||||
?>
|
||||
<input type="button" class="input_button" name="insLinktrimmer" value="<?php echo PLUGIN_LINKTRIMMER_NAME; ?>" style="" onclick="serendipity.openPopup('<?php echo $link; ?>', 'linktrimmerSel', 'width=800,height=600,toolbar=no,scrollbars=1,scrollbars,resize=1,resizable=1');">
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<input type="button" class="serendipityPrettyButton input_button" name="insLinktrimmer" value="<?php echo PLUGIN_LINKTRIMMER_NAME; ?>" style="" onclick="window.open('<?php echo $link; ?>', 'linktrimmerSel', 'width=800,height=600,toolbar=no,scrollbars=1,scrollbars,resize=1,resizable=1');" />
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
function event_hook($event, &$bag, &$eventData, $addData = null) {
|
||||
global $serendipity;
|
||||
static $has_jquery = null;
|
||||
|
||||
$hooks = &$bag->get('event_hooks');
|
||||
|
||||
if (isset($hooks[$event])) {
|
||||
if ($has_jquery === null) {
|
||||
$has_jquery = class_exists('serendipity_event_jquery');
|
||||
if ($serendipity['capabilities']['jquery']) {
|
||||
$has_jquery = true;
|
||||
}
|
||||
}
|
||||
|
||||
switch($event) {
|
||||
case 'backend_entry_toolbar_extended':
|
||||
if (isset($eventData['backend_entry_toolbar_extended:textarea'])) {
|
||||
$txtarea = $serendipity['version'][0] < '2' ? $eventData['backend_entry_toolbar_extended:textarea'] : $eventData['backend_entry_toolbar_extended:nugget'];
|
||||
} else {
|
||||
$txtarea = 'extended';
|
||||
}
|
||||
if (!$serendipity['wysiwyg']) {
|
||||
$this->generate_button($txtarea);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'backend_entry_toolbar_body':
|
||||
if (isset($eventData['backend_entry_toolbar_body:textarea'])) {
|
||||
$txtarea = $serendipity['version'][0] < '2' ? $eventData['backend_entry_toolbar_body:textarea'] : $eventData['backend_entry_toolbar_body:nugget'];
|
||||
} else {
|
||||
$txtarea = 'body';
|
||||
}
|
||||
if (!$serendipity['wysiwyg']) {
|
||||
$this->generate_button($txtarea);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'backend_wysiwyg':
|
||||
$link = $serendipity['serendipityHTTPPath'] . ($serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '') . 'plugin/linktrimmer' . ($serendipity['rewrite'] != 'none' ? '?' : '&') . 'txtarea=' . ($serendipity['version'][0] > '1' ? 'linktrimmer'.$eventData['item'] : $eventData['jsname']);
|
||||
$open = $serendipity['version'][0] > '1' ? 'serendipity.openPopup' : 'window.open';
|
||||
$eventData['buttons'][] = array(
|
||||
'id' => 'linktrimmer' . ($serendipity['version'][0] > '1' ? $eventData['item'] : $eventData['jsname']),
|
||||
'name' => PLUGIN_LINKTRIMMER_NAME,
|
||||
'javascript' => 'function() { '.$open.'(\'' . $link . '\', \'LinkTrimmer\', \'width=800,height=600,toolbar=no,scrollbars=1,scrollbars,resize=1,resizable=1\') }',
|
||||
'img_url' => $serendipity['serendipityHTTPPath'] . ($serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '') . 'plugin/plugin_linktrimmer.gif',
|
||||
'img_path' => 'serendipity_event_linktrimmer/serendipity_event_linktrimmer.gif',
|
||||
'toolbar' => 'other'
|
||||
);//'img_path' deprecated, used by ckeditor plugin <= 4.1.0
|
||||
return true;
|
||||
break;
|
||||
|
||||
case 'frontend_configure':
|
||||
if (preg_match('@' . $serendipity['serendipityHTTPPath'] . '/?(' . $serendipity['indexFile'] . ')?\??' . $this->get_config('prefix') . '/?(.+)$@imsU', $_SERVER['REQUEST_URI'], $m)) {
|
||||
$hash = preg_replace('@[^a-z0-9]@imsU', '', $m[2]);
|
||||
$res = serendipity_db_query("SELECT url
|
||||
FROM {$serendipity['dbPrefix']}linktrimmer
|
||||
WHERE hash = '" . serendipity_db_escape_string($hash) . "'
|
||||
LIMIT 1", true, 'assoc');
|
||||
if (is_array($res) && !empty($res['url'])) {
|
||||
$url = str_replace(array("\n", "\r", "\0"), array('', '', ''), $res['url']);
|
||||
header('HTTP/1.0 301 Moved Permanently');
|
||||
header('Location: ' . $url);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'backend_dashboard':
|
||||
if (serendipity_db_bool($this->get_config('frontpage', true)) ) $this->show();
|
||||
break;
|
||||
|
||||
case 'backend_frontpage_display':
|
||||
if (serendipity_db_bool($this->get_config('frontpage', true) && $serendipity['version'][0] <= '1') ) $this->show();
|
||||
break;
|
||||
|
||||
case 'external_plugin':
|
||||
if ($_SESSION['serendipityAuthedUser'] !== true) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$uri_parts = explode('?', str_replace('&', '&', $eventData));
|
||||
$parts = explode('&', $uri_parts[0]);
|
||||
|
||||
$uri_part = $parts[0];
|
||||
$parts = array_pop($parts);
|
||||
|
||||
if (count($parts) > 1) {
|
||||
foreach($parts as $key => $value) {
|
||||
$val = explode('=', $value);
|
||||
$_REQUEST[$val[0]] = $val[1];
|
||||
}
|
||||
} else {
|
||||
$val = explode('=', $parts[0]);
|
||||
$_REQUEST[$val[0]] = $val[1];
|
||||
}
|
||||
|
||||
if (!isset($_REQUEST['txtarea'])) {
|
||||
$parts = explode('&', $uri_parts[1]);
|
||||
if (count($parts) > 1) {
|
||||
foreach($parts as $key => $value) {
|
||||
$val = explode('=', $value);
|
||||
$_REQUEST[$val[0]] = $val[1];
|
||||
}
|
||||
} else {
|
||||
$val = explode('=', $parts[0]);
|
||||
$_REQUEST[$val[0]] = $val[1];
|
||||
}
|
||||
}
|
||||
|
||||
switch($uri_part) {
|
||||
case 'plugin_linktrimmer.gif':
|
||||
header('Content-Type: image/gif');
|
||||
echo file_get_contents(dirname(__FILE__) . '/serendipity_event_linktrimmer.gif');
|
||||
break;
|
||||
|
||||
case 'linktrimmer':
|
||||
$this->show(true);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'css_backend':
|
||||
if (!strpos($eventData, '.linktrimmer')) {
|
||||
// class exists in CSS, so a user has customized it and we don't need default
|
||||
echo file_get_contents(dirname(__FILE__) . '/linktrimmer.css');
|
||||
if ($serendipity['version'][0] < '2') echo '#linktrimmer_url.input_textbox { width: inherit; }';
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/* vim: set sts=4 ts=4 expandtab : */
|
||||
<?php #
|
||||
|
||||
if (IN_serendipity !== true) {
|
||||
die ("Don't hack!");
|
||||
}
|
||||
|
||||
// Probe for a language include with constants. Still include defines later on, if some constants were missing
|
||||
$probelang = dirname(__FILE__) . '/' . $serendipity['charset'] . 'lang_' . $serendipity['lang'] . '.inc.php';
|
||||
if (file_exists($probelang)) {
|
||||
include $probelang;
|
||||
}
|
||||
|
||||
include_once dirname(__FILE__) . '/lang_en.inc.php';
|
||||
|
||||
class serendipity_event_linktrimmer extends serendipity_event {
|
||||
var $debug;
|
||||
|
||||
function introspect(&$propbag) {
|
||||
global $serendipity;
|
||||
|
||||
$propbag->add('name', PLUGIN_LINKTRIMMER_NAME);
|
||||
$propbag->add('description', PLUGIN_LINKTRIMMER_DESC);
|
||||
$propbag->add('requirements', array(
|
||||
'serendipity' => '1.3',
|
||||
'smarty' => '2.6.7',
|
||||
'php' => '4.1.0'
|
||||
));
|
||||
|
||||
$propbag->add('version', '1.6.3');
|
||||
$propbag->add('author', 'Garvin Hicking, Ian');
|
||||
$propbag->add('stackable', false);
|
||||
$propbag->add('configuration', array('prefix', 'frontpage', 'domain'));
|
||||
$propbag->add('event_hooks', array(
|
||||
'backend_frontpage_display' => true,
|
||||
'css_backend' => true,
|
||||
'frontend_configure' => true,
|
||||
'backend_dashboard' => true,
|
||||
'backend_entry_toolbar_extended' => true,
|
||||
'backend_entry_toolbar_body' => true,
|
||||
'backend_wysiwyg' => true,
|
||||
'external_plugin' => true,
|
||||
|
||||
)
|
||||
);
|
||||
#$this->dependencies = array('serendipity_event_jquery' => 'keep');
|
||||
$propbag->add('groups', array('BACKEND_FEATURES'));
|
||||
}
|
||||
|
||||
function introspect_config_item($name, &$propbag) {
|
||||
global $serendipity;
|
||||
|
||||
switch($name) {
|
||||
case 'prefix':
|
||||
$propbag->add('type', 'string');
|
||||
$propbag->add('name', PLUGIN_LINKTRIMMER_LINKPREFIX);
|
||||
$propbag->add('description', PLUGIN_LINKTRIMMER_LINKPREFIX_DESC);
|
||||
$propbag->add('default', 'l');
|
||||
break;
|
||||
|
||||
case 'frontpage':
|
||||
$propbag->add('type', 'boolean');
|
||||
$propbag->add('name', PLUGIN_LINKTRIMMER_FRONTPAGE_OPTION);
|
||||
$propbag->add('description', '');
|
||||
$propbag->add('default', 'true');
|
||||
break;
|
||||
|
||||
case 'domain':
|
||||
$propbag->add('type', 'string');
|
||||
$propbag->add('name', PLUGIN_LINKTRIMMER_DOMAIN);
|
||||
$propbag->add('description', PLUGIN_LINKTRIMMER_DOMAIN_DESC);
|
||||
$propbag->add('default', $serendipity['baseURL']);
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function setupDB() {
|
||||
global $serendipity;
|
||||
|
||||
if (serendipity_db_bool($this->get_config('db_built_1', false))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (preg_match('@mysql@i', $serendipity['dbType'])) {
|
||||
$sql = "CREATE TABLE {$serendipity['dbPrefix']}linktrimmer (
|
||||
id {AUTOINCREMENT} {PRIMARY},
|
||||
hash varchar(32) collate latin1_general_cs,
|
||||
url text
|
||||
);";
|
||||
} else {
|
||||
$sql = "CREATE TABLE {$serendipity['dbPrefix']}linktrimmer (
|
||||
id {AUTOINCREMENT} {PRIMARY},
|
||||
hash varchar(32),
|
||||
url text
|
||||
);";
|
||||
}
|
||||
|
||||
serendipity_db_schema_import($sql);
|
||||
|
||||
$sql = "CREATE INDEX linkidx ON {$serendipity['dbPrefix']}linktrimmer (hash)";
|
||||
serendipity_db_schema_import($sql);
|
||||
|
||||
$this->set_config('db_built_1', 'true');
|
||||
}
|
||||
|
||||
function generate_content(&$title) {
|
||||
$title = PLUGIN_LINKTRIMMER_NAME;
|
||||
}
|
||||
|
||||
static function base62($var) {
|
||||
static $base_characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
||||
|
||||
$stack = array();
|
||||
while (bccomp($var, 0) != 0) {
|
||||
$remainder = bcmod($var, 62);
|
||||
$var = bcdiv(bcsub($var, $remainder), 62);
|
||||
|
||||
array_push($stack, $base_characters[$remainder]);
|
||||
}
|
||||
|
||||
return implode('', array_reverse($stack));
|
||||
}
|
||||
|
||||
static function lookup($url, $custom_hash = '', $pref = '') {
|
||||
global $serendipity;
|
||||
|
||||
$custom_hash = trim($custom_hash);
|
||||
$url = trim($url);
|
||||
|
||||
if (!preg_match('@https?://@i', $url)) {
|
||||
$url = 'http://' . $url;
|
||||
}
|
||||
|
||||
$res = serendipity_db_query("SELECT hash FROM {$serendipity['dbPrefix']}linktrimmer WHERE url = '" . serendipity_db_escape_string($url) . "' LIMIT 1", true, 'assoc');
|
||||
if (!is_array($res) || empty($res['hash'])) {
|
||||
|
||||
if (!empty($custom_hash)) {
|
||||
$res = serendipity_db_query("SELECT hash FROM {$serendipity['dbPrefix']}linktrimmer WHERE hash = '" . serendipity_db_escape_string($custom_hash) . "' LIMIT 1", true, 'assoc');
|
||||
if (is_array($res) && !empty($res['hash'])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$hash = serendipity_event_linktrimmer::create($url, $custom_hash);
|
||||
if (empty($hash)) {
|
||||
return false;
|
||||
} else {
|
||||
return $pref . $hash;
|
||||
}
|
||||
}
|
||||
|
||||
return $pref . $res['hash'];
|
||||
}
|
||||
|
||||
static function create($url, $hash = '') {
|
||||
global $serendipity;
|
||||
|
||||
serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}linktrimmer (url) VALUES ('" . serendipity_db_escape_string($url) . "')");
|
||||
$id = serendipity_db_insert_id();
|
||||
|
||||
if (empty($id)) return false;
|
||||
|
||||
if (empty($hash)) {
|
||||
$hash = serendipity_event_linktrimmer::base62($id);
|
||||
}
|
||||
|
||||
serendipity_db_query("UPDATE {$serendipity['dbPrefix']}linktrimmer
|
||||
SET hash = '" . $hash . "'
|
||||
WHERE id = " . (int)$id);
|
||||
|
||||
return $hash;
|
||||
}
|
||||
|
||||
function show($external = false) {
|
||||
global $serendipity;
|
||||
|
||||
if (IN_serendipity !== true) {
|
||||
die ("Don't hack!");
|
||||
}
|
||||
|
||||
if (!is_object($serendipity['smarty'])) {
|
||||
serendipity_smarty_init();
|
||||
}
|
||||
|
||||
$this->setupDB();
|
||||
|
||||
$pref = $this->get_config('domain') . $this->get_config('prefix') . '/';
|
||||
if ($this->get_config('domain') == $serendipity['baseURL']) {
|
||||
$pref = $this->get_config('domain') . $this->get_config('prefix') . '/';
|
||||
} else {
|
||||
$pref = $this->get_config('domain');
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['submit']) && !empty($_REQUEST['linktrimmer_url'])) {
|
||||
$url = $this->lookup($_REQUEST['linktrimmer_url'], $_REQUEST['linktrimmer_hash'], $pref);
|
||||
if ($url == false) {
|
||||
$error = PLUGIN_LINKTRIMMER_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
$serendipity['smarty']->assign(array(
|
||||
'linktrimmer_ispopup' => $serendipity['enablePopup'],
|
||||
'linktrimmer_error' => $error,
|
||||
'linktrimmer_url' => $url,
|
||||
'linktrimmer_origurl' => $_REQUEST['linktrimmer_url'],
|
||||
'linktrimmer_external' => $external,
|
||||
'linktrimmer_txtarea' => $_REQUEST['txtarea']
|
||||
));
|
||||
|
||||
if ($serendipity['version'][0] > '1') {
|
||||
echo $this->parseTemplate('plugin_linktrimmer.tpl');
|
||||
} else {
|
||||
echo $this->parseTemplate('plugin_linktrimmer_old.tpl');
|
||||
}
|
||||
}
|
||||
|
||||
function generate_button ($txtarea) {
|
||||
global $serendipity;
|
||||
if (!isset($txtarea)) {
|
||||
$txtarea = 'body';
|
||||
}
|
||||
$link = ($serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '') . 'plugin/linktrimmer' . ($serendipity['rewrite'] != 'none' ? '?' : '&') . 'txtarea=' . $txtarea;
|
||||
if ($serendipity['version'][0] > '1') {
|
||||
?>
|
||||
<input type="button" class="input_button" name="insLinktrimmer" value="<?php echo PLUGIN_LINKTRIMMER_NAME; ?>" style="" onclick="serendipity.openPopup('<?php echo $link; ?>', 'linktrimmerSel', 'width=800,height=600,toolbar=no,scrollbars=1,scrollbars,resize=1,resizable=1');">
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<input type="button" class="serendipityPrettyButton input_button" name="insLinktrimmer" value="<?php echo PLUGIN_LINKTRIMMER_NAME; ?>" style="" onclick="window.open('<?php echo $link; ?>', 'linktrimmerSel', 'width=800,height=600,toolbar=no,scrollbars=1,scrollbars,resize=1,resizable=1');" />
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
function event_hook($event, &$bag, &$eventData, $addData = null) {
|
||||
global $serendipity;
|
||||
static $has_jquery = null;
|
||||
|
||||
$hooks = &$bag->get('event_hooks');
|
||||
|
||||
if (isset($hooks[$event])) {
|
||||
if ($has_jquery === null) {
|
||||
$has_jquery = class_exists('serendipity_event_jquery');
|
||||
if ($serendipity['capabilities']['jquery']) {
|
||||
$has_jquery = true;
|
||||
}
|
||||
}
|
||||
|
||||
switch($event) {
|
||||
case 'backend_entry_toolbar_extended':
|
||||
if (isset($eventData['backend_entry_toolbar_extended:textarea'])) {
|
||||
$txtarea = $serendipity['version'][0] < '2' ? $eventData['backend_entry_toolbar_extended:textarea'] : $eventData['backend_entry_toolbar_extended:nugget'];
|
||||
} else {
|
||||
$txtarea = 'extended';
|
||||
}
|
||||
if (!$serendipity['wysiwyg']) {
|
||||
$this->generate_button($txtarea);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'backend_entry_toolbar_body':
|
||||
if (isset($eventData['backend_entry_toolbar_body:textarea'])) {
|
||||
$txtarea = $serendipity['version'][0] < '2' ? $eventData['backend_entry_toolbar_body:textarea'] : $eventData['backend_entry_toolbar_body:nugget'];
|
||||
} else {
|
||||
$txtarea = 'body';
|
||||
}
|
||||
if (!$serendipity['wysiwyg']) {
|
||||
$this->generate_button($txtarea);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'backend_wysiwyg':
|
||||
$link = $serendipity['serendipityHTTPPath'] . ($serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '') . 'plugin/linktrimmer' . ($serendipity['rewrite'] != 'none' ? '?' : '&') . 'txtarea=' . ($serendipity['version'][0] > '1' ? 'linktrimmer'.$eventData['item'] : $eventData['jsname']);
|
||||
$open = $serendipity['version'][0] > '1' ? 'serendipity.openPopup' : 'window.open';
|
||||
$eventData['buttons'][] = array(
|
||||
'id' => 'linktrimmer' . ($serendipity['version'][0] > '1' ? $eventData['item'] : $eventData['jsname']),
|
||||
'name' => PLUGIN_LINKTRIMMER_NAME,
|
||||
'javascript' => 'function() { '.$open.'(\'' . $link . '\', \'LinkTrimmer\', \'width=800,height=600,toolbar=no,scrollbars=1,scrollbars,resize=1,resizable=1\') }',
|
||||
'img_url' => $serendipity['serendipityHTTPPath'] . ($serendipity['rewrite'] == 'none' ? $serendipity['indexFile'] . '?/' : '') . 'plugin/plugin_linktrimmer.gif',
|
||||
'img_path' => 'serendipity_event_linktrimmer/serendipity_event_linktrimmer.gif',
|
||||
'toolbar' => 'other'
|
||||
);//'img_path' deprecated, used by ckeditor plugin <= 4.1.0
|
||||
return true;
|
||||
break;
|
||||
|
||||
case 'frontend_configure':
|
||||
if (preg_match('@' . $serendipity['serendipityHTTPPath'] . '/?(' . $serendipity['indexFile'] . ')?\??' . $this->get_config('prefix') . '/?(.+)$@imsU', $_SERVER['REQUEST_URI'], $m)) {
|
||||
$hash = preg_replace('@[^a-z0-9]@imsU', '', $m[2]);
|
||||
$res = serendipity_db_query("SELECT url
|
||||
FROM {$serendipity['dbPrefix']}linktrimmer
|
||||
WHERE hash = '" . serendipity_db_escape_string($hash) . "'
|
||||
LIMIT 1", true, 'assoc');
|
||||
if (is_array($res) && !empty($res['url'])) {
|
||||
$url = str_replace(array("\n", "\r", "\0"), array('', '', ''), $res['url']);
|
||||
header('HTTP/1.0 301 Moved Permanently');
|
||||
header('Location: ' . $url);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'backend_dashboard':
|
||||
if (serendipity_db_bool($this->get_config('frontpage', true)) ) $this->show();
|
||||
break;
|
||||
|
||||
case 'backend_frontpage_display':
|
||||
if (serendipity_db_bool($this->get_config('frontpage', true) && $serendipity['version'][0] <= '1') ) $this->show();
|
||||
break;
|
||||
|
||||
case 'external_plugin':
|
||||
if ($_SESSION['serendipityAuthedUser'] !== true) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$uri_parts = explode('?', str_replace('&', '&', $eventData));
|
||||
$parts = explode('&', $uri_parts[0]);
|
||||
|
||||
$uri_part = $parts[0];
|
||||
$parts = array_pop($parts);
|
||||
|
||||
if (count($parts) > 1) {
|
||||
foreach($parts as $key => $value) {
|
||||
$val = explode('=', $value);
|
||||
$_REQUEST[$val[0]] = $val[1];
|
||||
}
|
||||
} else {
|
||||
$val = explode('=', $parts[0]);
|
||||
$_REQUEST[$val[0]] = $val[1];
|
||||
}
|
||||
|
||||
if (!isset($_REQUEST['txtarea'])) {
|
||||
$parts = explode('&', $uri_parts[1]);
|
||||
if (count($parts) > 1) {
|
||||
foreach($parts as $key => $value) {
|
||||
$val = explode('=', $value);
|
||||
$_REQUEST[$val[0]] = $val[1];
|
||||
}
|
||||
} else {
|
||||
$val = explode('=', $parts[0]);
|
||||
$_REQUEST[$val[0]] = $val[1];
|
||||
}
|
||||
}
|
||||
|
||||
switch($uri_part) {
|
||||
case 'plugin_linktrimmer.gif':
|
||||
header('Content-Type: image/gif');
|
||||
echo file_get_contents(dirname(__FILE__) . '/serendipity_event_linktrimmer.gif');
|
||||
break;
|
||||
|
||||
case 'linktrimmer':
|
||||
$this->show(true);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'css_backend':
|
||||
if (!strpos($eventData, '.linktrimmer')) {
|
||||
// class exists in CSS, so a user has customized it and we don't need default
|
||||
echo file_get_contents(dirname(__FILE__) . '/linktrimmer.css');
|
||||
if ($serendipity['version'][0] < '2') echo '#linktrimmer_url.input_textbox { width: inherit; }';
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/* vim: set sts=4 ts=4 expandtab : */
|
||||
|
|
Loading…
Reference in a new issue