From 0bced8b29fff587f2b8da5c271089ec4a7727c0b Mon Sep 17 00:00:00 2001 From: Thomas Hochstein Date: Mon, 5 Aug 2019 18:27:42 +0200 Subject: [PATCH] vgwort: Some fixes. (#97) * Change type of UNIQUE columns to VARCHAR. MySQL can't work with UNIQUE constraints on BLOB or TEXT columns: "MySQL Error 1170 (42000): BLOB/TEXT Column Used in Key Specification Without a Key Length". Public and private counter identifiers have a fixed length of 32, so use VARCHAR(32) instead. Signed-off-by: Thomas Hochstein * Requires at least s9y 2.2.1-alpha1. That's the first release containing "info_more", see s9y/Serendipty#511 Signed-off-by: Thomas Hochstein * Fix typo. MySQL comparisions use "=", not "==". Signed-off-by: Thomas Hochstein * Internationalisation. Signed-off-by: Thomas Hochstein * Fix typo. String concatenation is done using ".=", not "+=". Signed-off-by: Thomas Hochstein * Bump version, add ChangeLog. Signed-off-by: Thomas Hochstein * Drop "unofficial" from name. Signed-off-by: Thomas Hochstein --- serendipity_event_vgwort/ChangeLog | 13 +++++++ .../UTF-8/lang_de.inc.php | 9 +++-- .../UTF-8/lang_en.inc.php | 7 +++- .../serendipity_event_vgwort.php | 34 +++++++++---------- serendipity_event_vgwort/vgwortMenu.tpl | 4 +-- 5 files changed, 45 insertions(+), 22 deletions(-) create mode 100644 serendipity_event_vgwort/ChangeLog diff --git a/serendipity_event_vgwort/ChangeLog b/serendipity_event_vgwort/ChangeLog new file mode 100644 index 00000000..328ccde9 --- /dev/null +++ b/serendipity_event_vgwort/ChangeLog @@ -0,0 +1,13 @@ +Version 0.4: +============ +Changes by Thomas Hochstein +- Require s9y 2.2.1-alpha1 or higher due to backend template changes + missing in older versions. +- Change table columns counter_public and counter_private to + VARCHAR(32) as MySQL doesn't accept UNIQUE constraints on TEXT + or BLOB columns. +- Fix MySQL comparison (use "=" instead of "=="); otherwise, no + counter codes will ever be found. +- Fix concatenation of body and extended, fixing wrong length + calculations for all entries with an extended entry. +- Internationalisation. diff --git a/serendipity_event_vgwort/UTF-8/lang_de.inc.php b/serendipity_event_vgwort/UTF-8/lang_de.inc.php index 0acdb216..fcc27a98 100644 --- a/serendipity_event_vgwort/UTF-8/lang_de.inc.php +++ b/serendipity_event_vgwort/UTF-8/lang_de.inc.php @@ -1,4 +1,9 @@ add('description', PLUGIN_EVENT_VGWORT_DESC); $propbag->add('stackable', false); $propbag->add('author', 'Malte Paskuda'); - $propbag->add('version', '0.3.2'); + $propbag->add('version', '0.4'); $propbag->add('requirements', array( - 'serendipity' => '2.1' + 'serendipity' => '2.2.1' )); $propbag->add('event_hooks', array('external_plugin' => true, 'backend_maintenance' => true, @@ -46,8 +46,8 @@ class serendipity_event_vgwort extends serendipity_event { global $serendipity; $sql = "CREATE TABLE IF NOT EXISTS {$serendipity['dbPrefix']}vgwort ( entry_id INTEGER, - counter_public TEXT UNIQUE NOT NULL, - counter_private TEXT UNIQUE NOT NULL);"; + counter_public VARCHAR(32) UNIQUE NOT NULL, + counter_private VARCHAR(32) UNIQUE NOT NULL);"; serendipity_db_schema_import($sql); } @@ -61,7 +61,7 @@ class serendipity_event_vgwort extends serendipity_event { $entry = array_values($entry)[0]['entries'][0]; $fullEntry = $entry['body']; if (! empty($entry['extended'])) { - $fullEntry += $entry['extended']; + $fullEntry .= $entry['extended']; } $rawEntry = strip_tags($fullEntry); @@ -70,14 +70,14 @@ class serendipity_event_vgwort extends serendipity_event { } /** - * Import the Zählmarken stored in the given CSV. Store them in the database, with an entry id if there are available entries (=that are long enough) + * Import the counter codes ("Zählmarken") stored in the given CSV. Store them in the database, with an entry id if there are available entries (=that are long enough) * */ function import($csv) { // NOTE: We should use one of the included CSV functions. But they don't work with the format the csv file has currently $csv = explode(";Zählmarke für HTML Texte;Zählmarke für HTML Texte - SSL (https://...);Zählmarke für Dokumente (erlaubte Formate: PDF, ePub);Zählmarke für Dokumente (erlaubte Formate: PDF, ePub) - SSL (https://...)", $csv); $entries = $this->markableEntries(); foreach ($csv as $csvline) { - // we have to remvoe newlines here, because the CSV currently contains newlines where there should be none, + // we have to remove newlines here, because the CSV currently contains newlines where there should be none, // which trips up the selection via array indexes selection below $csvline = str_replace(array("\n", "\r"), '', $csvline); $csvline = explode(';', $csvline); @@ -92,7 +92,7 @@ class serendipity_event_vgwort extends serendipity_event { } /** - * Return array of up to 100 ids of entries long enough to get a Zählmarke and not already marked + * Return array of up to 100 ids of entries long enough to get a counter code and not already marked * */ function markableEntries() { global $serendipity; @@ -134,7 +134,7 @@ class serendipity_event_vgwort extends serendipity_event { } /** - * Return an array of unused public and private Zählmarken + * Return an array of unused public and private counter codes * */ function unused() { return $this->getCounter(0); @@ -143,12 +143,12 @@ class serendipity_event_vgwort extends serendipity_event { function getCounter($entry_id) { global $serendipity; $sql = "SELECT counter_public, counter_private FROM {$serendipity['dbPrefix']}vgwort - WHERE entry_id == " . (int) $entry_id; + WHERE entry_id = " . (int) $entry_id; return serendipity_db_query($sql, false); } /** - * If entry is long enough and not already marked, assign one of the unused Zählmarken + * If entry is long enough and not already marked, assign one of the unused counter codes * */ function assignUnusedCounter($entry_id) { if ($this->isMarkable($entry_id)) { @@ -227,13 +227,13 @@ class serendipity_event_vgwort extends serendipity_event { case 'backend_view_entry': $counter = $this->getCounter($eventData['id'])[0]; $eventData['info_more'] = '
- Length: ' . $this->entryLength($eventData['id']) . ''; + ' . PLUGIN_EVENT_VGWORT_LENGTH . ': ' . $this->entryLength($eventData['id']) . ''; if (is_array($counter) && $counter['counter_public']) { - $eventData['info_more'] .='Zählmarke: ' . $counter['counter_public'] . ' - Identifikationscode: ' . $counter['counter_private'] . ''; + $eventData['info_more'] .='' . PLUGIN_EVENT_VGWORT_COUNTERCODE . ': ' . $counter['counter_public'] . ' + ' . PLUGIN_EVENT_VGWORT_PRIVATECODE . ': ' . $counter['counter_private'] . ''; } - + $eventData['info_more'] .= '
'; return true; break; @@ -247,7 +247,7 @@ class serendipity_event_vgwort extends serendipity_event { return false; } if ($counter['counter_public']) { - // the entry has a Zählmarke, but we have to make sure it is also shown completely + // the entry has a counter code, but we have to make sure it is also shown completely if ((empty($eventData['extended'])) || $serendipity['feedFull'] == 1) { $eventData['feed_body'] .= ''; } @@ -264,7 +264,7 @@ class serendipity_event_vgwort extends serendipity_event { return false; } if ($counter['counter_public']) { - // the entry has a Zählmarke, but we have to make sure it is also shown completely + // the entry has a counter code, but we have to make sure it is also shown completely if ((! $eventData['has_extended']) || ($serendipity['GET']['action'] == 'read' && is_int($serendipity['GET']['id']))) { $eventData['display_dat'] .= ''; } diff --git a/serendipity_event_vgwort/vgwortMenu.tpl b/serendipity_event_vgwort/vgwortMenu.tpl index 22a8e46b..32d6bb5d 100644 --- a/serendipity_event_vgwort/vgwortMenu.tpl +++ b/serendipity_event_vgwort/vgwortMenu.tpl @@ -1,10 +1,10 @@
-

Zählmarken

+

{$CONST.PLUGIN_EVENT_VGWORT_TPL_TITLE}

Reserve: {$unused}

- +