Skip to content

Commit

Permalink
Merge pull request #39 from modfin/fixes-2023-11
Browse files Browse the repository at this point in the history
Polylang fixes, and additional stuff
  • Loading branch information
joeledstrom authored Nov 15, 2023
2 parents 06afddb + b1a137e commit 579bb5a
Show file tree
Hide file tree
Showing 15 changed files with 294 additions and 72 deletions.
4 changes: 4 additions & 0 deletions admin/css/mfn-wp-plugin-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ input.wide {
color: rgba(44,51,56,.5);
}

.mfn-settings-table input::placeholder {
color: rgba(44,51,56,.5);
}

.mfn-settings-table th {
text-align: left;
}
Expand Down
26 changes: 15 additions & 11 deletions admin/js/mfn-wp-plugin-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@
return new Promise((resolve) => setTimeout(resolve, ms));
}

function no_cache_param(p) {
return p + 'no-cache='+Math.round((Math.random()*1000000));
}

function mfn_sync_single_item(post_id) {
$.get(mfn_admin_params.plugin_url + '/cc.php?mode=sync&limit=1&offset=0&post_id=' + post_id)
$.get(mfn_admin_params.plugin_url + '/cc.php?mode=sync&limit=1&offset=0&post_id=' + post_id + no_cache_param('&'))
.done(function () {
if (post_id !== null) {
$('#mfn-item-restore-status').html('');
Expand Down Expand Up @@ -83,7 +87,7 @@
.html('<div class=\'mfn-do-fade mfn-spinner-container\'><span class=\'mfn-spinner\'></span></div> Waiting...</span>');
}

$.get(mfn_admin_params.plugin_url + '/cc.php?mode=sync&limit=' + limit + '&offset=' + offset, function (data) {
$.get(mfn_admin_params.plugin_url + '/cc.php?mode=sync&limit=' + limit + '&offset=' + offset + no_cache_param('&'), function (data) {
sync_condition = 'running';
var fetched = parseInt(data.split(' ')[0]);
var inserted = parseInt(data.split(' ')[1]);
Expand Down Expand Up @@ -127,7 +131,7 @@

async function syncTax() {
$('#mfn-sync-tax-status').html('<div class=\'mfn-do-fade mfn-spinner-container\'><span class=\'mfn-spinner\'></span></div>');
await $.get(mfn_admin_params.plugin_url + '/cc.php?mode=sync-tax', function () {
await $.get(mfn_admin_params.plugin_url + '/cc.php?mode=sync-tax' + no_cache_param('&'), function () {
$('#mfn-sync-tax-status')
.html("<div class='mfn-status-container mfn-highlight-status mfn-do-slide-top'><span class=\"dashicons dashicons-yes mfn-success-icon mfn-do-fade\"></span>Done!</div>");
});
Expand Down Expand Up @@ -246,7 +250,7 @@
return;
}

$.get(pluginUrl + '/cc.php?mode=ping', function (data) {
$.get(pluginUrl + '/cc.php?mode=ping' + no_cache_param('&'), function (data) {
if (data === 'pong') {
pluginUrlTestEl
.html("<span class=\"dashicons dashicons-yes mfn-success-icon mfn-do-fade\"></span><span style='cursor:default;' title='" + mfn_admin_params.plugin_url + "'><strong>Current:</strong> (" + mfn_admin_params.plugin_url + ")</span>");
Expand Down Expand Up @@ -301,7 +305,7 @@
var subStatusEl = $('#mfn-subscription-status');
var subStatusContainerEl = $('#mfn-status-container');

$.get(pluginUrl + '/cc.php?mode=verify-subscription').done(function (res) {
$.get(pluginUrl + '/cc.php?mode=verify-subscription' + no_cache_param('&')).done(function (res) {
// got error from websub verification
if (msg !== '') {
mfn_subscription_error(msg, 'mfn-subscription-status');
Expand Down Expand Up @@ -341,7 +345,7 @@
var subStatusEl = $('#mfn-subscription-status');
$('#mfn-sub-button').attr("disabled", true);

$.get(pluginUrl + '/cc.php?mode=subscribe', function (msg) {
$.get(pluginUrl + '/cc.php?mode=subscribe' + no_cache_param('&'), function (msg) {
subStatusEl.html('<div class=\'mfn-do-fade mfn-spinner-container\'><span class=\'mfn-spinner\'></span></div> Subscribing...');
mfn_verify_subscription(pluginUrl, verificationRetries, msg);
});
Expand All @@ -353,7 +357,7 @@
$('#mfn-unsub-button').attr("disabled", true);
$('#save-submit-btn').prop("disabled", false);

$.get(pluginUrl + '/cc.php?mode=unsubscribe', function () {
$.get(pluginUrl + '/cc.php?mode=unsubscribe' + no_cache_param('&'), function () {
subStatusEl
.html('<div class=\'mfn-do-fade mfn-spinner-container\'><span class=\'mfn-spinner\'></span></div> Unsubscribing...');

Expand All @@ -377,7 +381,7 @@
function mfn_clear_settings(){
var pluginUrl = mfn_admin_params.plugin_url;

$.get(pluginUrl + '/cc.php?mode=clear-settings', function () {
$.get(pluginUrl + '/cc.php?mode=clear-settings' + no_cache_param('&'), function () {
setTimeout(function () {
location.reload();
}, 100);
Expand All @@ -399,7 +403,7 @@
.html('<span class="mfn-status-container mfn-status-container-delete mfn-do-fade"><div class=\'mfn-do-fade mfn-spinner-container\'><span class=\'mfn-spinner\'></span></div> <b>Deleting tags...</b></span>');
delTagsBtnSpanEl.removeClass("dashicons dashicons-tag");
delTagsBtnSpanEl.html('<div class=\'mfn-do-fade\'><span class=\'mfn-spinner\'></span></div>');
$.get(pluginUrl + '/cc.php?mode=delete-all-tags&limit=10', function (data) {
$.get(pluginUrl + '/cc.php?mode=delete-all-tags&limit=10' + no_cache_param('&'), function (data) {
var parts = data.split(';');
var i = parseInt(parts[0]);
var deleted = parseInt(parts[1]);
Expand All @@ -422,7 +426,7 @@
if (acceptedTypes.includes(type)) {

var modalUrl = mfn_admin_params.plugin_url + '/admin/partials/modals/mfn-modal-' + type + '.php';
await $.get(modalUrl, function (data) {
await $.get(modalUrl + no_cache_param('?'), function (data) {
$('body').append(data);
// modal main events
$('.mfn-close-modal').click(function() {
Expand All @@ -449,7 +453,7 @@
delPostsBtnSpanEl.addClass("dashicons dashicons-admin-post");
}

$.get(pluginUrl + '/cc.php?mode=delete-all-posts&limit=10&include-dirty=' + includeDirty, function (data, xhr) {
$.get(pluginUrl + '/cc.php?mode=delete-all-posts&limit=10&include-dirty=' + includeDirty + no_cache_param('&'), function (data, xhr) {
var parts = data.split(';');
var i = parseInt(parts[0]);
var deleted = parseInt(parts[1]);
Expand Down
27 changes: 27 additions & 0 deletions admin/partials/mfn-wp-plugin-admin-display.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@
$verify_signature = $options['verify_signature'] ?? 'off';
$reset_cache = $options['reset_cache'] ?? 'on';
$enable_attachments = $options['enable_attachments'] ?? 'off';
$taxonomy_disable_cus_prefix = $options['taxonomy_disable_cus_prefix'] ?? "off";

// Rewrite settings
$rewrite = isset($options['rewrite_post_type']) ? unserialize($options['rewrite_post_type']) : null;
$slug = (isset($rewrite['slug']) && $rewrite['slug'] !== '' ? $rewrite['slug'] : MFN_POST_TYPE);
$archive_name = (isset($rewrite['archive-name']) && $rewrite['archive-name'] !== '' ? $rewrite['archive-name'] : MFN_ARCHIVE_NAME);
$singular_name = (isset($rewrite['singular-name']) && $rewrite['singular-name'] !== '' ? $rewrite['singular-name'] : MFN_SINGULAR_NAME);
$taxonomy_rewrite_slug = $options['taxonomy_rewrite_slug'] ?? '';

// HTML
echo '
Expand Down Expand Up @@ -184,6 +186,21 @@ function toggleQueryInput(e) {
</div>
</td>
</tr>
<tr>
<td>
' . mfn_parse_label('label_rewrite_taxonomy_slug') . '
' . mfn_parse_small('small_mfn-news-tag') . '
</td>
</tr>
<tr>
<td class="mfn-inline-td">
<input type="text" class="regular-text wide" pattern="\S+" name="' . $this->plugin_name . '[taxonomy_rewrite_slug]' . '" id="' . $this->plugin_name . '-taxonomy_rewrite_slug"' . ' value="' . $taxonomy_rewrite_slug . '" ' . $is_readonly . ' placeholder="' . MFN_TAXONOMY_NAME . '">
<div class="mfn-tooltip-box">
<span class="mfn-info-icon-wrapper"><i class="dashicons dashicons-info-outline"></i></span>
<span class="mfn-tooltip-text">' . mfn_get_text('tooltip_taxonomy_rewrite_slug') . '</span>
</div>
</td>
</tr>
<tr>
<td>
' . mfn_parse_label('label_rewrite_post_type_archive_name') . '
Expand Down Expand Up @@ -383,6 +400,16 @@ function toggleQueryInput(e) {
</p>
<td>
</tr>
<tr>
<td>
<p>
<input type="checkbox" id="' . $this->plugin_name . '-taxonomy_disable_cus_prefix" name="' . $this->plugin_name . '[taxonomy_disable_cus_prefix]" ' . checked($taxonomy_disable_cus_prefix, "on", false) . ' value="on" ' . $is_readonly . '>
' . mfn_parse_label('label_taxonomy_disable_cus_prefix') . '
<br>
' . mfn_parse_small('small_taxonomy_disable_cus_prefix_description') . '
</p>
<td>
</tr>
</tbody>
</table>
</div>
Expand Down
7 changes: 7 additions & 0 deletions admin/partials/modals/mfn-modal-clear-settings.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<?php
require_once('../../../config.php');

$is_admin = current_user_can('manage_options');

if (!$is_admin) {
echo "you are not admin";
die();
}

$queries = array();
parse_str($_SERVER['QUERY_STRING'], $queries);

Expand Down
7 changes: 7 additions & 0 deletions admin/partials/modals/mfn-modal-delete-posts.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<?php
require_once('../../../config.php');

$is_admin = current_user_can('manage_options');

if (!$is_admin) {
echo "you are not admin";
die();
}

$queries = array();
parse_str($_SERVER['QUERY_STRING'], $queries);

Expand Down
7 changes: 7 additions & 0 deletions admin/partials/modals/mfn-modal-delete-tags.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<?php
require_once('../../../config.php');

$is_admin = current_user_can('manage_options');

if (!$is_admin) {
echo "you are not admin";
die();
}

$queries = array();
parse_str($_SERVER['QUERY_STRING'], $queries);

Expand Down
7 changes: 7 additions & 0 deletions admin/partials/modals/mfn-modal-restore-item.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<?php
require_once('../../../config.php');

$is_admin = current_user_can('manage_options');

if (!$is_admin) {
echo "you are not admin";
die();
}

$queries = array();
parse_str($_SERVER['QUERY_STRING'], $queries);

Expand Down
7 changes: 7 additions & 0 deletions admin/partials/sections/mfn-wp-plugin-admin-status.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<?php
require_once('../../../config.php');

$is_admin = current_user_can('manage_options');

if (!$is_admin) {
echo "you are not admin";
die();
}

$subscriptions = get_option("mfn-subscriptions");
$subscription = mfn_get_subscription_by_plugin_url($subscriptions, mfn_plugin_url());
$subscription_id = $subscription['subscription_id'] ?? "";
Expand Down
8 changes: 6 additions & 2 deletions api.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,12 @@ function MFN_get_feed($include_content, $hasTags = array(), $hasNotTags = array(
INNER JOIN (
SELECT
po.ID,
group_concat(CONCAT(ter.name, ':', ter.slug) ORDER BY ter.slug LIKE '" . MFN_TAG_PREFIX . "-cus-%', ter.slug) AS tags,
group_concat(SUBSTRING_INDEX(ter.slug, '_', 1) ORDER BY ter.slug LIKE '" . MFN_TAG_PREFIX . "-cus-%', ter.slug) AS tag_slugs
group_concat(CONCAT(ter.name, ':', ter.slug)
ORDER BY (ter.slug LIKE '" . MFN_TAG_PREFIX . "-cus-%'
|| ter.slug NOT LIKE '" . MFN_TAG_PREFIX . "%'), ter.slug) AS tags,
group_concat(SUBSTRING_INDEX(ter.slug, '_', 1)
ORDER BY (ter.slug LIKE '" . MFN_TAG_PREFIX . "-cus-%'
|| ter.slug NOT LIKE '" . MFN_TAG_PREFIX . "%'), ter.slug) AS tag_slugs
FROM $wpdb->posts po
INNER JOIN $wpdb->term_relationships r
ON r.object_id = po.ID
Expand Down
7 changes: 7 additions & 0 deletions cc.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,16 @@ function mfn_delete_all_tags(): array

$options = get_option( "mfn-wp-plugin" );
$wpml_enabled = defined( 'WPML_PLUGIN_BASENAME' ) && isset( $options['language_plugin'] ) && $options['language_plugin'] == 'wpml';
$pll_enabled = isset($options['language_plugin']) && $options['language_plugin'] == 'pll';

if ( $wpml_enabled ) {
$terms = MFN_get_terms_wpml( '' );
} else if ( $pll_enabled ) {
$terms = get_terms( array(
'taxonomy' => MFN_TAXONOMY_NAME,
'hide_empty' => false,
'lang' => '',
) );
} else {
$terms = get_terms( array(
'taxonomy' => MFN_TAXONOMY_NAME,
Expand Down
Loading

0 comments on commit 579bb5a

Please sign in to comment.