Skip to content

Commit

Permalink
fix checkbox entryproperties re-sets
Browse files Browse the repository at this point in the history
References #260 and #261 and commit 8b51c37
Closes #376
  • Loading branch information
ophian committed Dec 11, 2015
1 parent bb0bae1 commit 7fe8d91
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function introspect(&$propbag)
$propbag->add('description', PLUGIN_EVENT_ENTRYPROPERTIES_DESC);
$propbag->add('stackable', false);
$propbag->add('author', 'Garvin Hicking');
$propbag->add('version', '1.38');
$propbag->add('version', '1.39');
$propbag->add('requirements', array(
'serendipity' => '1.6',
'smarty' => '2.6.27',
Expand Down Expand Up @@ -215,12 +215,21 @@ function addProperties(&$properties, &$eventData) {
$property = serendipity_fetchEntryProperties($eventData['id']);
$supported_properties = serendipity_event_entryproperties::getSupportedProperties();

// cleanup properties first, if none disable_markups plugins were set or a previous selected was reset
// Cleanup properties first, if none disable_markups plugins were set, or a previous selected one was re-set
if (is_array($serendipity['POST']['properties']) && !is_array($serendipity['POST']['properties']['disable_markups'])) {
$q = "DELETE FROM {$serendipity['dbPrefix']}entryproperties WHERE entryid = " . (int)$eventData['id'] . " AND property LIKE 'ep_disable_markup_%'";
serendipity_db_query($q);
}

// Special case for input type checkbox entryproperties
$reset_properties = array('is_sticky', 'no_frontpage', 'hiderss');
foreach($reset_properties AS $property) {
if (!isset($serendipity['POST']['propertyform']) && is_array($serendipity['POST']['properties']) && !in_array($property, $serendipity['POST']['properties'])) {
$q = "DELETE FROM {$serendipity['dbPrefix']}entryproperties WHERE entryid = " . (int)$eventData['id'] . " AND property = 'ep_{$property}'";
serendipity_db_query($q);
}
}

// Special case for disable markups.
if (is_array($properties['disable_markups'])) {
$q = "DELETE FROM {$serendipity['dbPrefix']}entryproperties WHERE entryid = " . (int)$eventData['id'] . " AND property LIKE 'ep_disable_markup_%'";
Expand All @@ -238,7 +247,7 @@ function addProperties(&$properties, &$eventData) {
// possibly only wants to update entry metadata and left out any specific properties, which need to be kept.
// An empty string like "" will properly remove an entryproperty, and POST values will always set an array index to an empty string.
// $serendipipty['POST']['propertyform'] will be set whenever the entryeditor was properly displayed and unticked checkboxes shall remain.
// (Not for checkboxes, but checkboxes are not used for entryproperties)
// (Not for checkboxes, but checkboxes are not used for entryproperties) - (Edit: Well, actually we do have some, see reset special case checkboxed properties above!)
if (!isset($properties[$prop_key]) && !isset($serendipity['POST']['propertyform'])) {
continue;
}
Expand Down

0 comments on commit 7fe8d91

Please sign in to comment.