Plugin Directory

Changeset 2763492


Ignore:
Timestamp:
07/29/2022 01:31:17 PM (4 years ago)
Author:
allkeyshop
Message:

Bugs fixes

Location:
allkeyshop-affiliate/trunk
Files:
7 added
11 edited

Legend:

Unmodified
Added
Removed
  • allkeyshop-affiliate/trunk/assets/js/widgetMetaBox.js

    r2756437 r2763492  
    66    let templateValue = templateInput.value;
    77
     8    let positionInput = document.querySelector('#aks-plugin_position-input');
     9    let positionValue = positionInput.value;
     10
    811    return {
    912        game : gameValue,
    10         template: templateValue
     13        template: templateValue,
     14        position : positionValue
    1115    };
    1216}
     
    1721    if (metaBoxData.game === null) return false;
    1822
     23    // Without Classic Editor
    1924    if (tinymce.activeEditor === null || tinymce.activeEditor.id !== 'content') {
    2025        let insertedBlock = wp.blocks.createBlock('core/shortcode', {
    2126            text: '[allkeyshop_widget_offers game="' + metaBoxData.game.value + '" template="' + metaBoxData.template + '"]',
    2227        });
    23    
    24         wp.data.dispatch( 'core/block-editor' ).insertBlocks(insertedBlock);
    25     } else {
    26         tinymce.activeEditor.execCommand('mceInsertContent', false, '[allkeyshop_widget game="' + metaBoxData.game.value + '" template="' + metaBoxData.template + '"]');
     28        let coreBlockEditor = wp.data.select( 'core/block-editor' );
     29        let blockPosition = 0;
     30        switch(metaBoxData.position) {
     31            case 'top' : blockPosition = 0; break;
     32            case 'bottom' : blockPosition = coreBlockEditor.getBlockCount(); break;
     33            case 'cursor' : blockPosition = coreBlockEditor.getBlockIndex(coreBlockEditor.getAdjacentBlockClientId()); break;
     34            default :;
     35        }
     36        wp.data.dispatch( 'core/block-editor' ).insertBlock(insertedBlock, blockPosition);
     37    } else { // With Classic Editor
     38        let insertedContent = '[allkeyshop_widget_offers game="' + metaBoxData.game.value + '" template="' + metaBoxData.template + '"]';
     39        switch(metaBoxData.position) {
     40            case 'top' : tinymce.activeEditor.setContent(insertedContent + tinymce.activeEditor.getContent()); tinymce.activeEditor.insertContent(''); break;
     41            case 'bottom' : tinymce.activeEditor.setContent(tinymce.activeEditor.getContent() + insertedContent); tinymce.activeEditor.insertContent(''); break;
     42            case 'cursor' : tinymce.activeEditor.insertContent(insertedContent); break;
     43            default :;
     44        }
    2745    }
    2846}
  • allkeyshop-affiliate/trunk/assets/views/index.php

    r2756437 r2763492  
    66</script>
    77<div class="aks-plugin_container">
    8     <h1>Allkeyshop Affiliate Plugin</h1>
     8    <?php require('include/header.php'); ?>
    99    <div class="aks-plugin_dashboard">
    1010        <div class="aks-plugin_content-box grid-full">
  • allkeyshop-affiliate/trunk/assets/views/widgetMetaBox.php

    r2756437 r2763492  
    66    <div class="field">
    77        <label for="aks-plugin_template-input"><?php _e('Select a template', 'aks-affiliate'); ?></label>
    8         <select name="aks-plugin-template" id="aks-plugin_template-input">
    9             <option value="none">Default</option>
    10             <?php foreach ($templates as $templateId => $templateData) : ?>
    11                 <option value="<?php echo esc_attr($templateId); ?>" <?php echo ($templateId == $template) ? 'selected' : ''?> ><?php echo esc_html($templateData['label']); ?></option>
    12             <?php endforeach; ?>
     8        <?php AllkeyshopAffiliate\Services\ViewHelper::getTemplateSelect(['id' => 'aks-plugin_template-input', 'name' => 'aks-plugin-template', 'value' => $template], 'game-prices-comparison'); ?>
     9    </div>
     10    <div class="field">
     11        <label for="aks-plugin_position-input"><?php _e('Select a position', 'aks-affiliate'); ?></label>
     12        <select name="aks-plugin-position" id="aks-plugin_position-input">
     13            <option value="top"><?php _e('At the top', 'aks-affiliate'); ?></option>
     14            <option value="bottom"><?php _e('At the bottom', 'aks-affiliate'); ?></option>
     15            <option value="cursor"><?php _e('At the cursor position', 'aks-affiliate'); ?></option>
    1316        </select>
    1417    </div>
  • allkeyshop-affiliate/trunk/languages/aks-affiliate-fr_FR.po

    r2756437 r2763492  
    1 # Copyright (C) 2022
    2 # This file is distributed under the same license as the Allkeyshop Affiliate plugin.
     1# Copyright (C) 2022 Allkeyshop
     2# This file is distributed under the GPL v2 or later.
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Allkeyshop Affiliate\n"
     5"Project-Id-Version: Allkeyshop Affiliate 1.0.0\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/aks-affiliate\n"
    7 "POT-Creation-Date: 2022-06-13T13:09:12+00:00\n"
    8 "PO-Revision-Date: 2022-06-13 15:15+0200\n"
     7"POT-Creation-Date: 2022-07-29T13:10:45+00:00\n"
     8"PO-Revision-Date: 2022-07-29 15:17+0200\n"
    99"Last-Translator: \n"
    1010"Language-Team: \n"
     
    2020msgid "Allkeyshop Affiliate"
    2121msgstr "Allkeyshop Affiliate"
     22
     23#. Description of the plugin
     24msgid "Earn money by adding game prices comparison widgets"
     25msgstr "Gagnez de l'argent en ajoutant des widget de comparaison de prix"
     26
     27#. Author of the plugin
     28msgid "Allkeyshop"
     29msgstr "Allkeyshop"
     30
     31#: assets/views/helper/select-template.php:2
     32msgid "Default"
     33msgstr "Aucun template"
    2234
    2335#: assets/views/index.php:11
     
    104116msgstr "Sélectionnez un template"
    105117
     118#: assets/views/widgetMetaBox.php:11
     119msgid "Select a position"
     120msgstr "Sélectionnez une position"
     121
     122#: assets/views/widgetMetaBox.php:13
     123msgid "At the top"
     124msgstr "Au début"
     125
     126#: assets/views/widgetMetaBox.php:14
     127msgid "At the bottom"
     128msgstr "À la fin"
     129
    106130#: assets/views/widgetMetaBox.php:15
     131msgid "At the cursor position"
     132msgstr "À la position du curseur"
     133
     134#: assets/views/widgetMetaBox.php:18
    107135msgid "Insert"
    108136msgstr "Insérer"
  • allkeyshop-affiliate/trunk/languages/aks-affiliate.pot

    r2756437 r2763492  
    1 # Copyright (C) 2022
    2 # This file is distributed under the same license as the Allkeyshop Affiliate plugin.
     1# Copyright (C) 2022 Allkeyshop
     2# This file is distributed under the GPL v2 or later.
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Allkeyshop Affiliate\n"
     5"Project-Id-Version: Allkeyshop Affiliate 1.0.0\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/aks-affiliate\n"
    77"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
     
    1010"Content-Type: text/plain; charset=UTF-8\n"
    1111"Content-Transfer-Encoding: 8bit\n"
    12 "POT-Creation-Date: 2022-06-13T13:09:12+00:00\n"
     12"POT-Creation-Date: 2022-07-29T13:10:45+00:00\n"
    1313"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    1414"X-Generator: WP-CLI 2.6.0\n"
     
    1717#. Plugin Name of the plugin
    1818msgid "Allkeyshop Affiliate"
     19msgstr ""
     20
     21#. Description of the plugin
     22msgid "Earn money by adding game prices comparison widgets"
     23msgstr ""
     24
     25#. Author of the plugin
     26msgid "Allkeyshop"
     27msgstr ""
     28
     29#: assets/views/helper/select-template.php:2
     30msgid "Default"
    1931msgstr ""
    2032
     
    7183msgstr ""
    7284
     85#: assets/views/widgetMetaBox.php:11
     86msgid "Select a position"
     87msgstr ""
     88
     89#: assets/views/widgetMetaBox.php:13
     90msgid "At the top"
     91msgstr ""
     92
     93#: assets/views/widgetMetaBox.php:14
     94msgid "At the bottom"
     95msgstr ""
     96
    7397#: assets/views/widgetMetaBox.php:15
     98msgid "At the cursor position"
     99msgstr ""
     100
     101#: assets/views/widgetMetaBox.php:18
    74102msgid "Insert"
    75103msgstr ""
  • allkeyshop-affiliate/trunk/main.php

    r2756437 r2763492  
    33 * Plugin Name:       Allkeyshop Affiliate
    44 * Description:       Earn money by adding game prices comparison widgets
    5  * Version:           1.0.0
     5 * Version:           1.0.1
    66 * Requires at least: 5.9
    77 * Requires PHP:      7.0
     
    1919require_once __DIR__ .'/src/Services/AffiliateApi.php';
    2020require_once __DIR__ .'/src/Services/VaksApi.php';
     21require_once __DIR__ .'/src/Services/ViewHelper.php';
    2122require_once __DIR__ .'/src/Controller/Manager.php';
    2223require_once __DIR__ .'/src/MetaBox/WidgetMetaBox.php';
  • allkeyshop-affiliate/trunk/readme.txt

    r2756437 r2763492  
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
    9 Stable tag: 1.0.0
     9Stable tag: 1.0.1
    1010
    1111Allkeyshop Widget integration for WordPress
  • allkeyshop-affiliate/trunk/src/Controller/Manager.php

    r2756437 r2763492  
    1414    public static $widgetJs;
    1515    public static $apiKey = null;
    16     public static $templates = null;
    1716
    1817    /**
     
    2120    public static function init()
    2221    {
    23         self::$assetDir = AKS_AFFILIATE_PLUGIN_PATH_ROOT . '/assets/';
     22        self::$assetDir = AKS_AFFILIATE_PLUGIN_PATH_ROOT . 'assets/';
    2423        self::$viewsDir = self::$assetDir . 'views/';
    2524        self::$affiliateUrl = defined('AKS_AFFILIATE_PLUGIN_ENV') ? 'http://aks.affiliate.local' : 'https://affiliate.allkeyshop.com';
     
    6160            'dashicons-buddicons-buddypress-logo'
    6261        );
     62
     63        add_submenu_page(
     64            'allkeyshop-affiliate',
     65            'Allkeyshop Affiliate Dashboard',
     66            'Dashboard',
     67            'manage_options',
     68            'allkeyshop-affiliate',
     69            function () {
     70                self::mainPage();
     71            },
     72            'dashicons-buddicons-buddypress-logo'
     73        );
     74
     75        /*add_submenu_page(
     76            'allkeyshop-affiliate',
     77            'Create Game Page',
     78            'Create Game Page',
     79            'manage_options',
     80            'create-game-page',
     81            function () {
     82                self::createGamePage();
     83            },
     84            'dashicons-media-text'
     85        );*/
    6386    }
    6487
     
    84107
    85108    /**
    86      * Load all the template of teh current api key
    87      */
    88     protected static function _loadTemplates()
    89     {
    90         if (self::$apiKey === null) return;
    91         $templates = AffiliateApi::loadTemplates(self::$apiKey);
    92         self::$templates = [];
    93         if ($templates['success']) {
    94             foreach($templates['data'] as $templateData) {
    95                 if (!isset(self::$templates[$templateData['type']])) {
    96                     self::$templates[$templateData['type']] = [];
    97                 }
    98                 self::$templates[$templateData['type']][$templateData['id']] = $templateData;
    99             }
    100         }
    101     }
    102 
    103     /**
    104      * Return the template for teh current API key
    105      * @param string $type Type of the template
    106      */
    107     public static function getTemplates(?string $type)
    108     {
    109         if (self::$templates === null) {
    110             self::_loadTemplates();
    111         }
    112         if ($type !== null) {
    113             if (!isset(self::$templates[$type])) {
    114                 return [];
    115             }
    116             return self::$templates[$type];
    117         }
    118        
    119         $allTemplates = [];
    120         foreach(self::$templates as $type => $templates) {
    121             foreach($templates as $id => $templateData) {
    122                 $allTemplates[$id] = $templateData;
    123             }
    124         }
    125 
    126         return $allTemplates;
    127     }
    128 
    129     /**
    130      * Return the template according to its id
    131      * @param int $templateId the template id
    132      */
    133     public static function getTemplate($templateId)
    134     {
    135         $templates = self::getTemplates();
    136         if ($templates === null) return null;
    137         if (array_key_exists($templateId, $templates)) {
    138             return $templates[$templateId];
    139         }
    140         return null;
    141     }
    142 
    143     /**
    144109     * Load the global JS and CSS files
    145110     */
     
    238203    public static function createGamePage()
    239204    {
    240         $data = ['idPage' => null, 'url' => null, 'error' => null];
     205        $data = ['error' => null];
    241206        if(isset($_POST['game']) && is_numeric($_POST['game'])) {
    242207            $gameId = intval($_POST['game']);
    243             $pageSlug = (!empty($_POST['slug'])) ? sanitize_title($_POST['slug']) : null;
     208            $template = (!empty($_POST['template'])) ? intval($_POST['template']) : null;
     209            if ($template === 0) {
     210                $template = null;
     211            }
    244212            $title = (!empty($_POST['title'])) ? sanitize_text_field($_POST['title']) : null;
    245            
    246             $idPage = self::_createGamePage($gameId, ['slug' => $pageSlug, 'title' => $title], $errors);
     213
     214            $idPage = self::_createGamePage($gameId, ['template' => $template, 'title' => $title], $errors);
     215            $data['error'] = $errors;
     216
    247217            if ($idPage !== null) {
    248                 $data['idPage'] = $idPage;
    249                 $data['url'] = get_page_link($idPage);
     218                $data['url'] = get_edit_post_link($idPage);
    250219            }
    251220        }
     
    257226     * @param int $gameId
    258227     * @param array $options array for some specific options :
    259      *                       - slug : allow to change the page slug
     228     *                       - template : template of the widget
    260229     *                       - title: Change the title of the page
    261230     * @param array $errors allow to retrieve the errors when the game page creation fail
    262231     */
    263     protected static function _createGamePage($gameId, $options = [], &$errors = null) {
     232    protected static function _createGamePage($gameId, $options = [], &$errors = null)
     233    {
     234        ob_start();
     235        require_once(self::$viewsDir . 'gamePageContent.php');
     236        $postContent = ob_get_contents();
     237        ob_end_clean();
    264238
    265239        $gameTitle = VaksApi::getGamesTitle($gameId);
     
    268242            'post_status'   => 'publish',
    269243            'post_type'     => 'page',
    270             'post_content'  => '[allkeyshop_game_page game="' . $gameId . '" template="3"]',
     244            'post_content'  => $postContent,
    271245            'post_author'   => get_current_user_id()
    272246        ];
  • allkeyshop-affiliate/trunk/src/MetaBox/WidgetMetaBox.php

    r2756437 r2763492  
    33
    44use AllkeyshopAffiliate\Manager;
     5use AllkeyshopAffiliate\Services\AffiliateApi;
    56
    67class WidgetMetaBox
     
    4849    {
    4950        $data = [
    50             'templates' => Manager::getTemplates('game-prices-comparison'),
    5151            'game' => get_post_meta($post->ID, self::META_KEY_GAME, true),
    5252            'template' => get_post_meta($post->ID, self::META_KEY_TEMPLATE, true)
  • allkeyshop-affiliate/trunk/src/Services/AffiliateApi.php

    r2756437 r2763492  
    66class AffiliateApi
    77{
    8 
    98    public static $apiUrl;
     9    private static $_templates = [];
    1010
    1111    public static function init() {
     
    4444    }
    4545
     46    protected static function _hasLoadedTemplates(string $apiKey)
     47    {
     48        return isset(self::$_templates[$apiKey]);
     49    }
     50
     51    protected static function _getTemplatesOfType(array $apiKeyTemplates, string $type = null)
     52    {
     53        if ($type !== null) {
     54            if (isset($apiKeyTemplates[$type])) {
     55                return $apiKeyTemplates[$type];
     56            }
     57            return [];
     58        }
     59
     60        $allTemplates = [];
     61        foreach($apiKeyTemplates as $type => $typeTemplates) {
     62            foreach($typeTemplates as $id => $templateData) {
     63                $allTemplates[$id] = $templateData;
     64            }
     65        }
     66        return $allTemplates;
     67    }
     68
     69    protected static function _getTemplates(string $apiKey, string $type = null)
     70    {
     71        if (isset(self::$_templates[$apiKey])) {
     72            return self::_getTemplatesOfType(self::$_templates[$apiKey], $type);
     73        }
     74        return [];
     75    }
     76
    4677    /**
    47      * Get the template for an API key
     78     * Get all the templates for an API key
    4879     * @param string $apiKey
     80     * @param string $type template type
     81     * @param bool $forceRefresh allow to bypass the cache
    4982     * @return array
    5083     */
    51     public static function loadTemplates(string $apiKey)
     84    public static function loadTemplates(string $apiKey, string $type = null, bool $forceRefresh = false)
    5285    {
     86        if (self::_hasLoadedTemplates($apiKey) && !$forceRefresh) {
     87            return self::_getTemplates($apiKey, $type);
     88        }
    5389        $path = 'get-templates/' . $apiKey;
    54         return self::call($path);
     90        $apiCall = self::call($path);
     91        $templates = [];
     92        if ($apiCall['success']) {
     93            foreach($apiCall['data'] as $templateData) {
     94                if (!isset($templates[$templateData['type']])) {
     95                    $templates[$templateData['type']] = [];
     96                }
     97                $templates[$templateData['type']][$templateData['id']] = $templateData;
     98            }
     99        }
     100        self::$_templates[$apiKey] = $templates;
     101        return self::_getTemplatesOfType(self::$_templates[$apiKey], $type);
     102    }
     103
     104    public static function getTemplate(string $apiKey, $templateId)
     105    {
     106        $templates = self::loadTemplates($apiKey);
     107        if (isset($templates[$templateId])) {
     108            return $templates[$templateId];
     109        }
     110        return null;
    55111    }
    56112
Note: See TracChangeset for help on using the changeset viewer.