Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
201 changes: 101 additions & 100 deletions CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion config/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
'item' => [
'fields' => [
'author_id' => OWC\OpenPub\Base\RestAPI\ItemFields\AuthorField::class,
'author_id' => OWC\OpenPub\Base\RestAPI\ItemFields\AuthorField::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,
Expand Down
6 changes: 6 additions & 0 deletions config/cmb2_settings_pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
'id' => 'setting_openpub_enable_show_on',
'type' => 'checkbox'
],
'openpub_related_items_own_type' => [
'name' => __('Related items type', 'openpub-base'),
'desc' => __('Scope related items to the type(s) of the current item when no explicit type is requested.', 'openpub-base'),
'id' => 'setting_openpub_related_items_own_type',
'type' => 'checkbox'
],
'openpub_expired_heading' => [
'type' => 'heading',
'name' => __('Expired', 'openpub-base'),
Expand Down
Binary file modified languages/openpub-base-nl_NL.mo
Binary file not shown.
20 changes: 14 additions & 6 deletions languages/openpub-base-nl_NL.po
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ msgctxt "Admin Filter definition"
msgid "Usage"
msgstr "Toepassing"

#: config/cmb2_settings_pages.php:46
#: config/cmb2_settings_pages.php:52
#: config/posttypes.php:39
#: config/posttypes.php:47
msgid "Expired"
Expand Down Expand Up @@ -432,23 +432,31 @@ msgstr "Gebruik een element waarmee de website verlaten kan worden zonder dat er
msgid "Used for configuring on which websites an OpenPub item should be displayed on."
msgstr "Wordt gebruikt voor het instellen van de websites waarop een OpenPub item weergegeven moet worden."

#: config/cmb2_settings_pages.php:47
#: config/cmb2_settings_pages.php:45
msgid "Related items type"
msgstr "Type gerelateerde items"

#: config/cmb2_settings_pages.php:46
msgid "Scope related items to the type(s) of the current item when no explicit type is requested."
msgstr "Beperk gerelateerde items tot het type/de typen van het huidige item wanneer er geen expliciet type is opgegeven."

#: config/cmb2_settings_pages.php:53
msgid "OpenPub items without an expiration date expire automatically when the field below has a value bigger than 0. Existing OpenPub items without an expiration date will be assigned a value of the published date plus the value given in days. New OpenPub items will have a value of the current date plus the value given in days."
msgstr "Items zonder een einddatum verlopen automatisch als het veld hieronder een waarde heeft die groter is dan 0. Bestaande OpenPub items zonder een einddatum krijgen een waarde toegewezen van de publicatie datum plus de waarde die is opgegeven in dagen. Nieuwe OpenPub items krijgen een waarde van de huidige datum plus de waarde die is opgegeven in dagen."

#: config/cmb2_settings_pages.php:50
#: config/cmb2_settings_pages.php:56
msgid "Days to expire"
msgstr "Dagen tot verlopen"

#: config/cmb2_settings_pages.php:51
#: config/cmb2_settings_pages.php:57
msgid "After how many days should an item expire?"
msgstr "Na hoeveel dagen moet een item verlopen?"

#: config/cmb2_settings_pages.php:56
#: config/cmb2_settings_pages.php:62
msgid "Admin notices"
msgstr "Administratieve mededelingen"

#: config/cmb2_settings_pages.php:57
#: config/cmb2_settings_pages.php:63
msgid "Disable upgrade admin notices."
msgstr "Schakel administratieve mededelingen over upgraden uit."

Expand Down
18 changes: 13 additions & 5 deletions languages/openpub-base.pot
Original file line number Diff line number Diff line change
Expand Up @@ -177,29 +177,37 @@ msgstr ""
msgid "Used for configuring on which websites an OpenPub item should be displayed on."
msgstr ""

#: config/cmb2_settings_pages.php:45
msgid "Related items type"
msgstr ""

#: config/cmb2_settings_pages.php:46
msgid "Scope related items to the type(s) of the current item when no explicit type is requested."
msgstr ""

#: config/cmb2_settings_pages.php:52
#: config/posttypes.php:39
#: config/posttypes.php:47
msgid "Expired"
msgstr ""

#: config/cmb2_settings_pages.php:47
#: config/cmb2_settings_pages.php:53
msgid "OpenPub items without an expiration date expire automatically when the field below has a value bigger than 0. Existing OpenPub items without an expiration date will be assigned a value of the published date plus the value given in days. New OpenPub items will have a value of the current date plus the value given in days."
msgstr ""

#: config/cmb2_settings_pages.php:50
#: config/cmb2_settings_pages.php:56
msgid "Days to expire"
msgstr ""

#: config/cmb2_settings_pages.php:51
#: config/cmb2_settings_pages.php:57
msgid "After how many days should an item expire?"
msgstr ""

#: config/cmb2_settings_pages.php:56
#: config/cmb2_settings_pages.php:62
msgid "Admin notices"
msgstr ""

#: config/cmb2_settings_pages.php:57
#: config/cmb2_settings_pages.php:63
msgid "Disable upgrade admin notices."
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: 3.8.7
* Version: 3.9.0
* Author: Yard | Digital Agency
* Author URI: https://www.yard.nl/
* License: GPL-3.0
Expand Down
2 changes: 1 addition & 1 deletion src/Base/ElasticPress/ElasticPress.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ public function setIndexNameByEnvironment($indexName, $siteID)

protected function getEnvironmentVariable(): string
{
return $_ENV['environment'] ?? '';
return getenv('environment') ?: '';
}

/**
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 @@ -8,7 +8,7 @@
class Plugin
{
public const NAME = 'openpub-base';
public const VERSION = '3.8.7';
public const VERSION = '3.9.0';

protected string $rootPath;
public Config $config;
Expand Down
14 changes: 7 additions & 7 deletions src/Base/Metabox/MetaboxServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ protected function registerMetaboxFields(CMB2 $metabox, array $fields): void

protected function addExpirationDefaultValue(array $configMetaboxes): array
{
$configMetaboxes['base']['fields']['general']['expiration']['default_cb'] = function( $field_args, $field ) {
$post = get_post( $field->object_id );
if ( ! $post || $post->post_status !== 'auto-draft' ) {
return '';
}
return strtotime( 'midnight', strtotime( '+' . $this->plugin->settings->expireAfter() . ' days' ) );
};
$configMetaboxes['base']['fields']['general']['expiration']['default_cb'] = function ($field_args, $field) {
$post = get_post($field->object_id);
if (! $post || $post->post_status !== 'auto-draft') {
return '';
}
return strtotime('midnight', strtotime('+' . $this->plugin->settings->expireAfter() . ' days'));
};

return $configMetaboxes;
}
Expand Down
18 changes: 9 additions & 9 deletions src/Base/Models/PortalLinkGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ private function getShowOnPortalURL(): string
return '';
}

// Filter out terms where slug is not numeric
$terms = array_filter($terms, function($term) {
return is_numeric($term->slug);
});

// Sort terms by slug (blog ID)
usort($terms, function($a, $b) {
return intval($a->slug) <=> intval($b->slug);
});
// Filter out terms where slug is not numeric
$terms = array_filter($terms, function ($term) {
return is_numeric($term->slug);
});

// Sort terms by slug (blog ID)
usort($terms, function ($a, $b) {
return intval($a->slug) <=> intval($b->slug);
});

$portalURL = reset($terms);

Expand Down
16 changes: 8 additions & 8 deletions src/Base/PostType/PostTypeServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ public function orderByPublishedDate(WP_Query $query): void
*/
public function registerPostTypes(): void
{
if (! function_exists('register_extended_post_type')) {
return;
}
if (! function_exists('register_extended_post_type')) {
return;
}

$this->configPostTypes = apply_filters('owc/openpub-base/before-register-posttypes', $this->plugin->config->get('posttypes'));
$this->configPostTypes = apply_filters('owc/openpub-base/before-register-posttypes', $this->plugin->config->get('posttypes'));

foreach ($this->configPostTypes as $postTypeName => $postType) {
// Examples of registering post types: http://johnbillion.com/extended-cpts/
register_extended_post_type($postTypeName, $postType['args'], $postType['names']);
}
foreach ($this->configPostTypes as $postTypeName => $postType) {
// Examples of registering post types: http://johnbillion.com/extended-cpts/
register_extended_post_type($postTypeName, $postType['args'], $postType['names']);
}
}

/**
Expand Down
31 changes: 27 additions & 4 deletions src/Base/RestAPI/Controllers/ItemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected function itemQueryBuilder(WP_REST_Request $request = null): Item
$items->query(Item::addAudienceParameters($this->getAudienceParam($request)));
}

return apply_filters('owc/openpub/rest-api/items/query/parameters', $items, $request);
return apply_filters('owc/openpub/rest-api/items/query/parameters', $items, $request);
}

/**
Expand Down Expand Up @@ -131,11 +131,18 @@ protected function addRelated(array $item, WP_REST_Request $request): array
'posts_per_page' => 10,
'post_status' => 'publish',
'post_type' => 'openpub-item',
'no_found_rows' => true,
])
->query(Item::addExpirationParameters());

if ($this->getTypeParam($request)) {
$items->query(Item::addTypeParameter($this->getTypeParam($request)));
$type = $this->getTypeParam($request);

if (! $type && $this->plugin->settings->useRelatedItemsOwnType()) {
$type = $this->getItemTypeSlugs($item);
}

if ($type) {
$items->query(Item::addTypeParameter($type));
}

if ($this->showOnParamIsValid($request) && $this->plugin->settings->useShowOn()) {
Expand All @@ -146,7 +153,7 @@ protected function addRelated(array $item, WP_REST_Request $request): array
$items->query(Item::addAudienceParameters($this->getAudienceParam($request)));
}

$items = apply_filters('owc/openpub/rest-api/items/query/parameters', $items, $request);
$items = apply_filters('owc/openpub/rest-api/items/query/parameters', $items, $request);

$query = new WP_Query($items->getQueryArgs());
return array_map([$this, 'transform'], $query->posts);
Expand Down Expand Up @@ -194,6 +201,22 @@ protected function hasHighlightedParam(WP_REST_Request $request): bool
return true;
}

/**
* Get the type slugs already attached to an item, comma-separated.
*
* @since 3.9.0
*/
protected function getItemTypeSlugs(array $item): string
{
$types = $item['taxonomies']['openpub-type'] ?? [];

if (! is_array($types) || [] === $types) {
return '';
}

return implode(',', array_column($types, 'slug'));
}

protected function getTypeParam(WP_REST_Request $request): string
{
$typeParam = $request->get_param('type');
Expand Down
10 changes: 5 additions & 5 deletions src/Base/RestAPI/ItemFields/TaxonomyField.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ class TaxonomyField extends CreatesFields
*/
public function create(WP_Post $post): array
{
$result = [];
$result = [];

$taxonomies = apply_filters('owc/openpub-base/before-register-extended-taxonomies', $this->plugin->config->get('taxonomies'));
$taxonomies = apply_filters('owc/openpub-base/before-register-extended-taxonomies', $this->plugin->config->get('taxonomies'));

if (! is_array($taxonomies) || 1 > count($taxonomies)) {
return $result;
}
return $result;
}

$taxonomiesKeys = array_unique(array_keys($taxonomies));
$taxonomiesKeys = array_unique(array_keys($taxonomies));

foreach ($taxonomiesKeys as $taxonomy) {
$result[$taxonomy] = $this->getTerms($post->ID, $taxonomy);
Expand Down
10 changes: 5 additions & 5 deletions src/Base/RestAPI/RestAPIServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ public function registerRoutes(): void
'permission_callback' => '__return_true',
]);

register_rest_route($this->namespace, 'items/active', [
'methods' => WP_REST_Server::READABLE,
'callback' => [new ItemController($this->plugin), 'getActiveItems'],
'permission_callback' => '__return_true',
]);
register_rest_route($this->namespace, 'items/active', [
'methods' => WP_REST_Server::READABLE,
'callback' => [new ItemController($this->plugin), 'getActiveItems'],
'permission_callback' => '__return_true',
]);

register_rest_route($this->namespace, 'items/(?P<id>\d+)', [
'methods' => WP_REST_Server::READABLE,
Expand Down
11 changes: 11 additions & 0 deletions src/Base/Settings/SettingsPageOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ public function useShowOn(): bool
return filter_var($setting, FILTER_VALIDATE_BOOLEAN);
}

/**
* @since 3.9.0
*/
public function useRelatedItemsOwnType(): bool
{
$setting = $this->settings['_owc_setting_openpub_related_items_own_type'] ?? false;

return filter_var($setting, FILTER_VALIDATE_BOOLEAN);
}

public function expireAfter(): int
{
return $this->settings['_owc_setting_openpub_expired_auto_after_days'] ?? 0;
Expand All @@ -75,6 +85,7 @@ public static function make(): self
'_owc_setting_use_portal_url' => 0,
'_owc_setting_use_escape_element' => 0,
'_owc_setting_openpub_enable_show_on' => 0,
'_owc_setting_openpub_related_items_own_type' => 0,
'_owc_setting_openpub_expired_auto_after_days' => 0,
'_owc_setting_openpub_disable_upgrade_admin_notice' => 0
];
Expand Down
18 changes: 18 additions & 0 deletions tests/Stubs/WordPress/CMB2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

class CMB2
{
public array $args = [];

public array $fields = [];

public function __construct(array $args = [])
{
$this->args = $args;
}

public function add_field(array $field)
{
$this->fields[] = $field;
}
}
Loading
Loading