plugin event trackbacks - fix CREATE table

@garvinhicking please check if this workaround for postgres is ok
This commit is contained in:
Ian 2016-04-14 12:29:55 +02:00
parent e3a07bf4dd
commit 0dda943fd9
15 changed files with 98 additions and 82 deletions

View file

@ -1,15 +1,30 @@
1.16: 1.17:
-----
* use lang API - requires S9y 1.6
* fix some inconsistencies
* fix table "delayed_trackbacks" creation
1.16.1:
-------
* Fixed error when saving an entry, which would loose its category association
1.16:
-----
* Fixed error when saving an entry, which would loose its category association * Fixed error when saving an entry, which would loose its category association
1.15: 1.15:
-----
* Fixed foreach warning in some cases * Fixed foreach warning in some cases
1.14: 1.14:
-----
* Fixed bad SQL table create statement * Fixed bad SQL table create statement
1.13: 1.13:
-----
* Issue SQL statement compatible with pgsql, thanks to ads * Issue SQL statement compatible with pgsql, thanks to ads
1.12: 1.12:
-----
* Added delayed trackbacks, generating those of entries published * Added delayed trackbacks, generating those of entries published
to the future to the future

View file

@ -1,4 +1,4 @@
<?php # <?php
/** /**
* @version * @version
@ -12,3 +12,4 @@
@define('PLUGIN_EVENT_MTRACKBACK_TITLETRACKOWN', 'Изпращане на проследявания към вашия собствен блог ?'); @define('PLUGIN_EVENT_MTRACKBACK_TITLETRACKOWN', 'Изпращане на проследявания към вашия собствен блог ?');
@define('PLUGIN_EVENT_MTRACKBACK_TITLETRACKALL', 'Глобална забрана на проследяванията ?'); @define('PLUGIN_EVENT_MTRACKBACK_TITLETRACKALL', 'Глобална забрана на проследяванията ?');
@define('PLUGIN_EVENT_MTRACKBACK_TITLETRACKSEL', 'Проследявания само за URLs, показани по-долу'); @define('PLUGIN_EVENT_MTRACKBACK_TITLETRACKSEL', 'Проследявания само за URLs, показани по-долу');

View file

@ -18,4 +18,5 @@
// Next lines were translated on 2010/05/02 // Next lines were translated on 2010/05/02
@define('PLUGIN_EVENT_MTRACKBACK_DELAYED_TRACKBACKS_NAME', 'Pozdržené odezvy'); @define('PLUGIN_EVENT_MTRACKBACK_DELAYED_TRACKBACKS_NAME', 'Pozdržené odezvy');
@define('PLUGIN_EVENT_MTRACKBACK_DELAYED_TRACKBACKS_DESC', 'Automaticky vytvářet odezvy článků, které nebyly okamžitě publikovány.'); @define('PLUGIN_EVENT_MTRACKBACK_DELAYED_TRACKBACKS_DESC', 'Automaticky vytvářet odezvy článků, které nebyly okamžitě publikovány.');

View file

@ -18,4 +18,5 @@
// Next lines were translated on 2010/05/02 // Next lines were translated on 2010/05/02
@define('PLUGIN_EVENT_MTRACKBACK_DELAYED_TRACKBACKS_NAME', 'Pozdržené odezvy'); @define('PLUGIN_EVENT_MTRACKBACK_DELAYED_TRACKBACKS_NAME', 'Pozdržené odezvy');
@define('PLUGIN_EVENT_MTRACKBACK_DELAYED_TRACKBACKS_DESC', 'Automaticky vytvářet odezvy článků, které nebyly okamžitě publikovány.'); @define('PLUGIN_EVENT_MTRACKBACK_DELAYED_TRACKBACKS_DESC', 'Automaticky vytvářet odezvy článků, které nebyly okamžitě publikovány.');

View file

@ -1,4 +1,4 @@
<?php # <?php
@define('PLUGIN_EVENT_MTRACKBACK_TITLETITLE', 'Trackbacks kontrollieren'); @define('PLUGIN_EVENT_MTRACKBACK_TITLETITLE', 'Trackbacks kontrollieren');
@define('PLUGIN_EVENT_MTRACKBACK_TITLEDESC', 'Ermöglicht beim Anlegen eines Eintrages zu weiteren URLs Trackbacks zu schicken oder Trackbacks zu deaktivieren'); @define('PLUGIN_EVENT_MTRACKBACK_TITLEDESC', 'Ermöglicht beim Anlegen eines Eintrages zu weiteren URLs Trackbacks zu schicken oder Trackbacks zu deaktivieren');

View file

@ -1,4 +1,4 @@
<?php # <?php
/** /**
* @version * @version
@ -12,4 +12,3 @@
@define('PLUGIN_EVENT_MTRACKBACK_TITLETRACKOWN', '自分のブログにトラックバックを送信しますか?'); @define('PLUGIN_EVENT_MTRACKBACK_TITLETRACKOWN', '自分のブログにトラックバックを送信しますか?');
@define('PLUGIN_EVENT_MTRACKBACK_TITLETRACKALL', '自動的なトラックバックを全体に使うことを無効にしますか?'); @define('PLUGIN_EVENT_MTRACKBACK_TITLETRACKALL', '自動的なトラックバックを全体に使うことを無効にしますか?');
?>

View file

@ -1,4 +1,4 @@
<?php # <?php
/** /**
* @version * @version
@ -12,4 +12,3 @@
@define('PLUGIN_EVENT_MTRACKBACK_TITLETRACKOWN', 'Wysyłać ślady do własnego bloga?'); @define('PLUGIN_EVENT_MTRACKBACK_TITLETRACKOWN', 'Wysyłać ślady do własnego bloga?');
@define('PLUGIN_EVENT_MTRACKBACK_TITLETRACKALL', 'Wyłączyć globalnie obsługę śladów?'); @define('PLUGIN_EVENT_MTRACKBACK_TITLETRACKALL', 'Wyłączyć globalnie obsługę śladów?');
?>

View file

@ -1,4 +1,4 @@
<?php # <?php
/** /**
* @version * @version
@ -12,3 +12,4 @@
@define('PLUGIN_EVENT_MTRACKBACK_TITLETRACKOWN', 'Изпращане на проследявания към вашия собствен блог ?'); @define('PLUGIN_EVENT_MTRACKBACK_TITLETRACKOWN', 'Изпращане на проследявания към вашия собствен блог ?');
@define('PLUGIN_EVENT_MTRACKBACK_TITLETRACKALL', 'Глобална забрана на проследяванията ?'); @define('PLUGIN_EVENT_MTRACKBACK_TITLETRACKALL', 'Глобална забрана на проследяванията ?');
@define('PLUGIN_EVENT_MTRACKBACK_TITLETRACKSEL', 'Проследявания само за URLs, показани по-долу'); @define('PLUGIN_EVENT_MTRACKBACK_TITLETRACKSEL', 'Проследявания само за URLs, показани по-долу');

View file

@ -18,4 +18,5 @@
// Next lines were translated on 2010/05/02 // Next lines were translated on 2010/05/02
@define('PLUGIN_EVENT_MTRACKBACK_DELAYED_TRACKBACKS_NAME', 'Pozdržené odezvy'); @define('PLUGIN_EVENT_MTRACKBACK_DELAYED_TRACKBACKS_NAME', 'Pozdržené odezvy');
@define('PLUGIN_EVENT_MTRACKBACK_DELAYED_TRACKBACKS_DESC', 'Automaticky vytváøet odezvy èlánkù, které nebyly okamžitì publikovány.'); @define('PLUGIN_EVENT_MTRACKBACK_DELAYED_TRACKBACKS_DESC', 'Automaticky vytváøet odezvy èlánkù, které nebyly okamžitì publikovány.');

View file

@ -18,4 +18,5 @@
// Next lines were translated on 2010/05/02 // Next lines were translated on 2010/05/02
@define('PLUGIN_EVENT_MTRACKBACK_DELAYED_TRACKBACKS_NAME', 'Pozdr¾ené odezvy'); @define('PLUGIN_EVENT_MTRACKBACK_DELAYED_TRACKBACKS_NAME', 'Pozdr¾ené odezvy');
@define('PLUGIN_EVENT_MTRACKBACK_DELAYED_TRACKBACKS_DESC', 'Automaticky vytváøet odezvy èlánkù, které nebyly okam¾itì publikovány.'); @define('PLUGIN_EVENT_MTRACKBACK_DELAYED_TRACKBACKS_DESC', 'Automaticky vytváøet odezvy èlánkù, které nebyly okam¾itì publikovány.');

View file

@ -1,4 +1,4 @@
<?php # <?php
@define('PLUGIN_EVENT_MTRACKBACK_TITLETITLE', 'Trackbacks kontrollieren'); @define('PLUGIN_EVENT_MTRACKBACK_TITLETITLE', 'Trackbacks kontrollieren');
@define('PLUGIN_EVENT_MTRACKBACK_TITLEDESC', 'Ermöglicht beim Anlegen eines Eintrages zu weiteren URLs Trackbacks zu schicken oder Trackbacks zu deaktivieren'); @define('PLUGIN_EVENT_MTRACKBACK_TITLEDESC', 'Ermöglicht beim Anlegen eines Eintrages zu weiteren URLs Trackbacks zu schicken oder Trackbacks zu deaktivieren');

View file

@ -1,4 +1,4 @@
<?php # <?php
/** /**
* @version * @version
@ -15,4 +15,3 @@
@define('PLUGIN_EVENT_MTRACKBACK_DELAYED_TRACKBACKS_NAME', 'Delayed Trackbacks'); @define('PLUGIN_EVENT_MTRACKBACK_DELAYED_TRACKBACKS_NAME', 'Delayed Trackbacks');
@define('PLUGIN_EVENT_MTRACKBACK_DELAYED_TRACKBACKS_DESC', 'Automatically create trackbacks of entries which were not released immediately.'); @define('PLUGIN_EVENT_MTRACKBACK_DELAYED_TRACKBACKS_DESC', 'Automatically create trackbacks of entries which were not released immediately.');
?>

View file

@ -1,4 +1,4 @@
<?php # <?php
/** /**
* @version * @version
@ -12,4 +12,3 @@
@define('PLUGIN_EVENT_MTRACKBACK_TITLETRACKOWN', '自分のブログにトラックバックを送信しますか?'); @define('PLUGIN_EVENT_MTRACKBACK_TITLETRACKOWN', '自分のブログにトラックバックを送信しますか?');
@define('PLUGIN_EVENT_MTRACKBACK_TITLETRACKALL', '全体でトラックバックを使うことを無効にしますか?'); @define('PLUGIN_EVENT_MTRACKBACK_TITLETRACKALL', '全体でトラックバックを使うことを無効にしますか?');
?>

View file

@ -1,4 +1,4 @@
<?php # <?php
/** /**
* @version * @version
@ -12,4 +12,3 @@
@define('PLUGIN_EVENT_MTRACKBACK_TITLETRACKOWN', 'Wysy³aæ ¶lady do w³asnego bloga?'); @define('PLUGIN_EVENT_MTRACKBACK_TITLETRACKOWN', 'Wysy³aæ ¶lady do w³asnego bloga?');
@define('PLUGIN_EVENT_MTRACKBACK_TITLETRACKALL', 'Wy³±czyæ globalnie obs³ugê ¶ladów?'); @define('PLUGIN_EVENT_MTRACKBACK_TITLETRACKALL', 'Wy³±czyæ globalnie obs³ugê ¶ladów?');
?>

View file

@ -1,17 +1,10 @@
<?php # <?php
if (IN_serendipity !== true) { if (IN_serendipity !== true) {
die ("Don't hack!"); die ("Don't hack!");
} }
@serendipity_plugin_api::load_language(dirname(__FILE__));
// 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 dirname(__FILE__) . '/lang_en.inc.php';
class serendipity_event_trackback extends serendipity_event class serendipity_event_trackback extends serendipity_event
{ {
@ -26,20 +19,20 @@ class serendipity_event_trackback extends serendipity_event
$propbag->add('description', PLUGIN_EVENT_MTRACKBACK_TITLEDESC); $propbag->add('description', PLUGIN_EVENT_MTRACKBACK_TITLEDESC);
$propbag->add('stackable', false); $propbag->add('stackable', false);
$propbag->add('author', 'Garvin Hicking, Malte Paskuda'); $propbag->add('author', 'Garvin Hicking, Malte Paskuda');
$propbag->add('version', '1.16.1'); $propbag->add('version', '1.17');
$propbag->add('requirements', array( $propbag->add('requirements', array(
'serendipity' => '0.8', 'serendipity' => '1.6',
'smarty' => '2.6.7', 'smarty' => '2.6.7',
'php' => '4.1.0' 'php' => '4.1.0'
)); ));
$propbag->add('event_hooks', array( $propbag->add('event_hooks', array(
'backend_display' => true, 'backend_display' => true,
'backend_trackbacks' => true, 'backend_trackbacks' => true,
'backend_trackback_check' => true, 'backend_trackback_check' => true,
'backend_http_request' => true, 'backend_http_request' => true,
'genpage' => true, 'genpage' => true,
'backend_publish' => true, 'backend_publish' => true,
'backend_save' => true 'backend_save' => true
)); ));
$propbag->add('configuration', array('disable_trackall', 'trackown', 'delayed_trackbacks', 'host', 'port', 'user', 'password')); $propbag->add('configuration', array('disable_trackall', 'trackown', 'delayed_trackbacks', 'host', 'port', 'user', 'password'));
$propbag->add('groups', array('BACKEND_EDITOR')); $propbag->add('groups', array('BACKEND_EDITOR'));
@ -90,25 +83,31 @@ class serendipity_event_trackback extends serendipity_event
$propbag->add('type', 'string'); $propbag->add('type', 'string');
$propbag->add('name', 'Proxy Password'); $propbag->add('name', 'Proxy Password');
$propbag->add('default', ''); $propbag->add('default', '');
break; break;
default:
return false;
} }
return true; return true;
} }
function generate_content(&$title) { function generate_content(&$title)
{
$title = PLUGIN_EVENT_MTRACKBACK_TITLETITLE; $title = PLUGIN_EVENT_MTRACKBACK_TITLETITLE;
} }
function install() { function install()
{
$this->setupDB(); $this->setupDB();
} }
function event_hook($event, &$bag, &$eventData, $addData = null) { function event_hook($event, &$bag, &$eventData, $addData = null)
{
global $serendipity; global $serendipity;
$hooks = &$bag->get('event_hooks'); $hooks = &$bag->get('event_hooks');
if (isset($hooks[$event])) { if (isset($hooks[$event])) {
switch($event) { switch($event) {
case 'backend_http_request': case 'backend_http_request':
// Setup a Proxy? // Setup a Proxy?
@ -119,8 +118,6 @@ class serendipity_event_trackback extends serendipity_event
$eventData['proxy_user'] = $this->get_config('user'); $eventData['proxy_user'] = $this->get_config('user');
$eventData['proxy_pass'] = $this->get_config('password'); $eventData['proxy_pass'] = $this->get_config('password');
} }
return true;
break; break;
case 'backend_trackbacks': case 'backend_trackbacks':
@ -154,8 +151,6 @@ class serendipity_event_trackback extends serendipity_event
} }
} }
} }
return true;
break; break;
case 'backend_trackback_check': case 'backend_trackback_check':
@ -164,8 +159,6 @@ class serendipity_event_trackback extends serendipity_event
$eventData[2] = $addData; $eventData[2] = $addData;
$eventData['skipValidate'] = true; $eventData['skipValidate'] = true;
} }
return true;
break; break;
case 'backend_display': case 'backend_display':
@ -208,7 +201,6 @@ class serendipity_event_trackback extends serendipity_event
<textarea rows="5" cols="50" id="input_additional_trackbacks" name="serendipity[additional_trackbacks]"><?php echo trim(implode("\n", $trackbackURLs)); ?></textarea> <textarea rows="5" cols="50" id="input_additional_trackbacks" name="serendipity[additional_trackbacks]"><?php echo trim(implode("\n", $trackbackURLs)); ?></textarea>
</fieldset> </fieldset>
<?php <?php
return true;
break; break;
case 'backend_save': case 'backend_save':
@ -221,30 +213,30 @@ class serendipity_event_trackback extends serendipity_event
) { ) {
#trackbacks couldn't get generated, so store this entry #trackbacks couldn't get generated, so store this entry
$this->delay($eventData['id'], $eventData['timestamp']); $this->delay($eventData['id'], $eventData['timestamp']);
} }
return true;
break; break;
case 'genpage': case 'genpage':
#don't check on every page #don't check on every page
$try = mt_rand(1, 10); $try = mt_rand(1, 10);
if ($try == 1 && serendipity_db_bool($this->get_config('delayed_trackbacks', true))) { if ($try == 1 && serendipity_db_bool($this->get_config('delayed_trackbacks', true))) {
$this->generateDelayed(); $this->generateDelayed();
} }
return true;
break; break;
default: default:
return false; return false;
break;
} }
return true;
} else { } else {
return false; return false;
} }
} }
#store id of an entry and wanted release-timestamp #store id of an entry and wanted release-timestamp
function delay($id, $timestamp) { function delay($id, $timestamp)
{
global $serendipity; global $serendipity;
$this->upgradeCheck(); $this->upgradeCheck();
$this->removeDelayed($id); $this->removeDelayed($id);
@ -256,10 +248,11 @@ class serendipity_event_trackback extends serendipity_event
} }
#generate trackbacks for entries which now are shown #generate trackbacks for entries which now are shown
function generateDelayed() { function generateDelayed()
{
global $serendipity; global $serendipity;
$this->upgradeCheck(); $this->upgradeCheck();
$sql = "SELECT id, timestamp $sql = "SELECT id, timestamp
FROM FROM
{$serendipity['dbPrefix']}delayed_trackbacks"; {$serendipity['dbPrefix']}delayed_trackbacks";
@ -269,9 +262,9 @@ class serendipity_event_trackback extends serendipity_event
foreach ($entries as $entry) { foreach ($entries as $entry) {
if ($entry['timestamp'] <= serendipity_serverOffsetHour()) { if ($entry['timestamp'] <= serendipity_serverOffsetHour()) {
include_once S9Y_INCLUDE_PATH . 'include/functions_trackbacks.inc.php'; include_once S9Y_INCLUDE_PATH . 'include/functions_trackbacks.inc.php';
$stored_entry = serendipity_fetchEntry('id', $entry['id'], 1, 1); $stored_entry = serendipity_fetchEntry('id', $entry['id'], 1, 1);
if (isset($_SESSION['serendipityRightPublish'])) { if (isset($_SESSION['serendipityRightPublish'])) {
$oldPublighRights = $_SESSION['serendipityRightPublish']; $oldPublighRights = $_SESSION['serendipityRightPublish'];
} else { } else {
@ -285,12 +278,12 @@ class serendipity_event_trackback extends serendipity_event
if (isset($stored_entry['email'])) { if (isset($stored_entry['email'])) {
unset($stored_entry['email']); unset($stored_entry['email']);
} }
# Convert fetched categories to storable categories. # Convert fetched categories to storable categories.
$current_cat = $stored_entry['categories']; $current_cat = $stored_entry['categories'];
$stored_entry['categories'] = array(); $stored_entry['categories'] = array();
foreach($current_cat AS $categoryidx => $category_data) { foreach($current_cat AS $categoryidx => $category_data) {
$stored_entry['categories'][$category_data['categoryid']] = $category_data['categoryid']; $stored_entry['categories'][$category_data['categoryid']] = $category_data['categoryid'];
} }
ob_start(); ob_start();
@ -310,7 +303,8 @@ class serendipity_event_trackback extends serendipity_event
} }
#remove delayed entry from further use #remove delayed entry from further use
function removeDelayed($id) { function removeDelayed($id)
{
global $serendipity; global $serendipity;
$sql = "DELETE FROM $sql = "DELETE FROM
{$serendipity['dbPrefix']}delayed_trackbacks {$serendipity['dbPrefix']}delayed_trackbacks
@ -318,33 +312,39 @@ class serendipity_event_trackback extends serendipity_event
serendipity_db_query($sql); serendipity_db_query($sql);
} }
function setupDB() { function setupDB()
global $serendipity; {
$sql = "CREATE TABLE {$serendipity['dbPrefix']}delayed_trackbacks ( global $serendipity;
id int(11) NOT NULL , if (preg_match('@(postgres|pgsql)@i', $serendipity['dbType'])) {
timestamp int(10) {UNSIGNED}, // postgres < 9.3 IF NOT EXISTS workaround...
PRIMARY KEY (id) $c = serendipity_db_query("SELECT COUNT(*) FROM {$serendipity['dbPrefix']}delayed_trackbacks;");
)"; if ((int)$c >= 0) {
serendipity_db_schema_import ( $sql ); return;
} else {
// Hotfix; better to check for pgsql vs. mysql here, but I didn't have time and needed this fixed for my install $sql = "CREATE TABLE {$serendipity['dbPrefix']}delayed_trackbacks (
$sql = "CREATE TABLE {$serendipity['dbPrefix']}delayed_trackbacks ( id int(11) NOT NULL,
id int(11) NOT NULL , timestamp int(10) {UNSIGNED},
timestamp int(10) {UNSIGNED} PRIMARY KEY (id))";
PRIMARY KEY (id) }
)"; } else {
serendipity_db_schema_import ( $sql ); $sql = "CREATE TABLE IF NOT EXISTS {$serendipity['dbPrefix']}delayed_trackbacks (
id int(11) NOT NULL,
timestamp int(10) {UNSIGNED}
PRIMARY KEY (id))";
}
serendipity_db_schema_import ( $sql ));
} }
function upgradeCheck() { function upgradeCheck()
{
$db_upgrade = serendipity_db_bool($this->get_config('db_upgrade', 2)); $db_upgrade = serendipity_db_bool($this->get_config('db_upgrade', 2));
if ((int)$db_upgrade !== 2) { if ((int)$db_upgrade !== 2) {
$this->setupDB(); $this->setupDB();
$this->set_config('db_upgrade', 2); $this->set_config('db_upgrade', 2);
} }
} }
} }
/* vim: set sts=4 ts=4 expandtab : */ /* vim: set sts=4 ts=4 expandtab : */
?>