Skip to content

Commit

Permalink
(feat): add emergency button
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdhoek1 committed Apr 7, 2021
1 parent 612a4ac commit 379bc6e
Show file tree
Hide file tree
Showing 17 changed files with 253 additions and 51 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Version [2.0.4]

### Feat

- Add escape element setting to openpub-settings.
- Add escape element setting in editor of openpub-item.

## Version [2.0.3]

### Fix:
Expand Down
25 changes: 13 additions & 12 deletions config/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@
*/
'item' => [
'fields' => [
'comments' => OWC\OpenPub\Base\RestAPI\ItemFields\CommentField::class,
'connected' => OWC\OpenPub\Base\RestAPI\ItemFields\ConnectedField::class,
'portal_url' => OWC\OpenPub\Base\RestAPI\ItemFields\PortalURL::class,
'date_modified' => OWC\OpenPub\Base\RestAPI\ItemFields\DateModified::class,
'downloads' => OWC\OpenPub\Base\RestAPI\ItemFields\DownloadsField::class,
'expired' => OWC\OpenPub\Base\RestAPI\ItemFields\ExpiredField::class,
'highlighted' => OWC\OpenPub\Base\RestAPI\ItemFields\HighlightedItemField::class,
'image' => OWC\OpenPub\Base\RestAPI\ItemFields\FeaturedImageField::class,
'links' => OWC\OpenPub\Base\RestAPI\ItemFields\LinksField::class,
'notes' => OWC\OpenPub\Base\RestAPI\ItemFields\NotesField::class,
'synonyms' => OWC\OpenPub\Base\RestAPI\ItemFields\SynonymsField::class,
'taxonomies' => OWC\OpenPub\Base\RestAPI\ItemFields\TaxonomyField::class,
'comments' => OWC\OpenPub\Base\RestAPI\ItemFields\CommentField::class,
'connected' => OWC\OpenPub\Base\RestAPI\ItemFields\ConnectedField::class,
'portal_url' => OWC\OpenPub\Base\RestAPI\ItemFields\PortalURL::class,
'date_modified' => OWC\OpenPub\Base\RestAPI\ItemFields\DateModified::class,
'downloads' => OWC\OpenPub\Base\RestAPI\ItemFields\DownloadsField::class,
'expired' => OWC\OpenPub\Base\RestAPI\ItemFields\ExpiredField::class,
'highlighted' => OWC\OpenPub\Base\RestAPI\ItemFields\HighlightedItemField::class,
'image' => OWC\OpenPub\Base\RestAPI\ItemFields\FeaturedImageField::class,
'links' => OWC\OpenPub\Base\RestAPI\ItemFields\LinksField::class,
'notes' => OWC\OpenPub\Base\RestAPI\ItemFields\NotesField::class,
'synonyms' => OWC\OpenPub\Base\RestAPI\ItemFields\SynonymsField::class,
'taxonomies' => OWC\OpenPub\Base\RestAPI\ItemFields\TaxonomyField::class,
'escape_element' => OWC\OpenPub\Base\RestAPI\ItemFields\EscapeElementField::class,
],
],
'theme' => [
Expand Down
27 changes: 27 additions & 0 deletions config/escape_element_metabox.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

return [
'escape_element' => [
'id' => 'escape_element',
'title' => __('Escape element', 'openpub-base'),
'post_types' => ['openpub-item'],
'context' => 'normal',
'priority' => 'low',
'autosave' => true,
'fields' => [
'settings' => [
[
'name' => __('Enable escape element', 'openpub-base'),
'desc' => __('Show escape element on portal page.', 'openpub-base'),
'id' => 'escape_element_active',
'type' => 'radio',
'options' => [
'1' => __('Yes', 'openpub-base'),
'0' => __('No', 'openpub-base'),
],
'std' => '0',
],
]
]
]
];
6 changes: 6 additions & 0 deletions config/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
'desc' => __('Use portal url in api.', 'openpub-base'),
'id' => 'setting_use_portal_url',
'type' => 'checkbox',
],
'openpub_use_escape_element' => [
'name' => __('Escape element', 'openpub-base'),
'desc' => __('Enable escape element.', 'openpub-base'),
'id' => 'setting_use_escape_element',
'type' => 'checkbox',
]
],
],
Expand Down
Binary file modified languages/openpub-base-nl_NL.mo
Binary file not shown.
47 changes: 34 additions & 13 deletions languages/openpub-base-nl_NL.po
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,26 @@ msgstr ""
"X-Poedit-SearchPath-1: src\n"
"X-Poedit-SearchPathExcluded-0: vendor\n"

#: config/escape_element_metabox.php:6 config/settings.php:30
msgid "Escape element"
msgstr "Ontsnap element"

#: config/escape_element_metabox.php:14
msgid "Enable escape element"
msgstr "Gebruik ontsnap element"

#: config/escape_element_metabox.php:15
msgid "Show escape element on portal page."
msgstr "Ontsnap element weergeven op portaal pagina."

#: config/escape_element_metabox.php:19
msgid "Yes"
msgstr "Ja"

#: config/escape_element_metabox.php:20
msgid "No"
msgstr "Nee"

#: config/metaboxes.php:6
msgid "Data"
msgstr "Gegevens"
Expand All @@ -30,11 +50,8 @@ msgid "Highlighted item"
msgstr "Uitgelichte item"

#: config/metaboxes.php:15
msgid ""
"Use this option to select current item to be a highlighted (featured) item"
msgstr ""
"Gebruik deze optie om het huidige item te selecteren als een uitgelicht "
"(gekenmerkt) item"
msgid "Use this option to select current item to be a highlighted (featured) item"
msgstr "Gebruik deze optie om het huidige item te selecteren als een uitgelicht (gekenmerkt) item"

#: config/metaboxes.php:20
msgid "Synonyms"
Expand Down Expand Up @@ -371,39 +388,43 @@ msgstr "Portal"
msgid "Portal URL"
msgstr "Portal URL"

#: config/settings.php:19
#: config/settings.php:18
msgid "Portal OpenPub item slug"
msgstr "Portal OpenPub item slug"

#: config/settings.php:20
#: config/settings.php:19
msgid "URL for OpenPub items in the portal, eg \"onderwerp\""
msgstr "URL voor OpenPub items in de portal, bv \"onderwerp\""

#: config/settings.php:25
msgid "Use portal url in api."
msgstr "Gebruik portal url in de api."

#: config/settings.php:29
#: config/settings.php:31
msgid "Enable escape element."
msgstr "Gebruik ontsnap element."

#: config/settings.php:40
msgid "Elasticsearch"
msgstr "Elasticsearch"

#: config/settings.php:36
#: config/settings.php:47
msgid "Instance url"
msgstr "Instance url"

#: config/settings.php:37 config/settings.php:43
#: config/settings.php:48 config/settings.php:54
msgid "URL inclusief http(s)://"
msgstr "URL inclusief http(s)://"

#: config/settings.php:42
#: config/settings.php:53
msgid "Instance shield"
msgstr "Instance user/wachtwoord"

#: config/settings.php:48
#: config/settings.php:59
msgid "Instance prefix"
msgstr "Instance prefix"

#: config/settings.php:49
#: config/settings.php:60
msgid "Use this prefix to group multiple instances"
msgstr ""
"Dit voorvoegsel wordt gebruikt om meerdere bronnen in ElasticSearch te "
Expand Down
40 changes: 32 additions & 8 deletions languages/openpub-base.pot
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,26 @@ msgstr ""
"X-Poedit-SearchPathExcluded-1: node_modules\n"
"X-Poedit-SearchPathExcluded-2: vendor\n"

#: config/escape_element_metabox.php:6 config/settings.php:30
msgid "Escape element"
msgstr ""

#: config/escape_element_metabox.php:14
msgid "Enable escape element"
msgstr ""

#: config/escape_element_metabox.php:15
msgid "Show escape element on portal page."
msgstr ""

#: config/escape_element_metabox.php:19
msgid "Yes"
msgstr ""

#: config/escape_element_metabox.php:20
msgid "No"
msgstr ""

#: config/metaboxes.php:6
msgid "Data"
msgstr ""
Expand Down Expand Up @@ -261,39 +281,43 @@ msgstr ""
msgid "Portal URL"
msgstr ""

#: config/settings.php:19
#: config/settings.php:18
msgid "Portal OpenPub item slug"
msgstr ""

#: config/settings.php:20
#: config/settings.php:19
msgid "URL for OpenPub items in the portal, eg \"onderwerp\""
msgstr ""

#: config/settings.php:25
msgid "Use portal url in api."
msgstr ""

#: config/settings.php:29
#: config/settings.php:31
msgid "Enable escape element."
msgstr ""

#: config/settings.php:40
msgid "Elasticsearch"
msgstr ""

#: config/settings.php:36
#: config/settings.php:47
msgid "Instance url"
msgstr ""

#: config/settings.php:37 config/settings.php:43
#: config/settings.php:48 config/settings.php:54
msgid "URL inclusief http(s)://"
msgstr ""

#: config/settings.php:42
#: config/settings.php:53
msgid "Instance shield"
msgstr ""

#: config/settings.php:48
#: config/settings.php:59
msgid "Instance prefix"
msgstr ""

#: config/settings.php:49
#: config/settings.php:60
msgid "Use this prefix to group multiple instances"
msgstr ""

Expand Down
2 changes: 1 addition & 1 deletion openpub-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Plugin Name: Yard | OpenPub Base
* Plugin URI: https://www.openwebconcept.nl/
* Description: Acts as foundation for other OpenPub related content plugins. This plugin implements actions to allow for other plugins to add and/or change Custom Posttypes, Metaboxes, Taxonomies, en Posts 2 posts relations.
* Version: 2.0.3
* Version: 2.0.4
* Author: Yard | Digital Agency
* Author URI: https://www.yard.nl/
* License: GPL-3.0
Expand Down
2 changes: 1 addition & 1 deletion src/Base/Foundation/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Plugin
*
* @var string VERSION
*/
const VERSION = '2.0.3';
const VERSION = '2.0.4';

/**
* Path to the root of the plugin.
Expand Down
9 changes: 7 additions & 2 deletions src/Base/Metabox/MetaboxServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ public function register()
*/
public function registerMetaboxes($rwmbMetaboxes)
{
$configMetaboxes = $this->plugin->config->get('metaboxes');
$metaboxes = [];
$configMetaboxes = $this->plugin->config->get('metaboxes');

if ($this->plugin->settings->useEscapeElement()) {
$configMetaboxes = array_merge($configMetaboxes, $this->plugin->config->get('escape_element_metabox'));
}

$metaboxes = [];

foreach ($configMetaboxes as $metabox) {
$metaboxes[] = $this->processMetabox($metabox);
Expand Down
7 changes: 6 additions & 1 deletion src/Base/Models/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Item
public function __construct(array $data, array $meta = null)
{
$this->data = $data;
$this->meta = is_null($meta) ? [] : $meta;
$this->meta = is_null($meta) ? get_post_meta($data['ID']) : $meta;
}

/**
Expand Down Expand Up @@ -255,6 +255,11 @@ public function getMeta(string $value, string $default = '', bool $single = true
return $single ? current($this->meta[$prefix]) : $this->meta[$prefix];
}

public function getEscapeElement(): bool
{
return $this->getMeta('escape_element_active', '0', true, '_owc_');
}

public function getPortalURL(): string
{
return $this->createPortalURL();
Expand Down
39 changes: 39 additions & 0 deletions src/Base/RestAPI/ItemFields/EscapeElementField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace OWC\OpenPub\Base\RestAPI\ItemFields;

use OWC\OpenPub\Base\Models\Item;
use OWC\OpenPub\Base\Support\CreatesFields;
use WP_Post;

/**
* Adds escape element field to the output.
*/
class EscapeElementField extends CreatesFields
{
/**
* The condition for the creator.
*
* @return callable
*/
protected function condition(): callable
{
return function () {
return $this->plugin->settings->useEscapeElement();
};
}

/**
* Create the identifications field for a given post.
*
* @param WP_Post $post
*
* @return bool
*/
public function create(WP_Post $post): bool
{
$itemModel = new Item($post->to_array());

return $itemModel->getEscapeElement();
}
}
11 changes: 9 additions & 2 deletions src/Base/Settings/SettingsPageOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,18 @@ public function usePortalURL(): string
return $this->settings['_owc_setting_use_portal_url'] ?? '';
}

public function useEscapeElement(): bool
{
return $this->settings['_owc_setting_use_escape_element'] ?? false;
}

public static function make(): self
{
$defaultSettings = [
'_owc_setting_portal_url' => '',
'_owc_setting_portal_openpub_item_slug' => '',
'_owc_setting_portal_url' => '',
'_owc_setting_portal_openpub_item_slug' => '',
'_owc_setting_use_portal_url' => 0,
'_owc_setting_use_escape_element' => 0
];

return new static(wp_parse_args(get_option('_owc_openpub_base_settings'), $defaultSettings));
Expand Down
4 changes: 2 additions & 2 deletions src/Base/Settings/SettingsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public function registerSettingsPage($rwmbSettingsPages)
*/
public function registerSettings($rwmbMetaboxes)
{
$configMetaboxes = $this->plugin->config->get('settings');
$metaboxes = [];
$configMetaboxes = $this->plugin->config->get('settings');
$metaboxes = [];

foreach ($configMetaboxes as $metabox) {
$metaboxes[] = $this->processMetabox($metabox);
Expand Down
Loading

0 comments on commit 379bc6e

Please sign in to comment.