Changeset 2763492
- Timestamp:
- 07/29/2022 01:31:17 PM (4 years ago)
- Location:
- allkeyshop-affiliate/trunk
- Files:
-
- 7 added
- 11 edited
-
assets/js/widgetMetaBox.js (modified) (2 diffs)
-
assets/views/createGamePage.php (added)
-
assets/views/gamePageContent.php (added)
-
assets/views/helper (added)
-
assets/views/helper/select-template.php (added)
-
assets/views/include (added)
-
assets/views/include/header.php (added)
-
assets/views/index.php (modified) (1 diff)
-
assets/views/widgetMetaBox.php (modified) (1 diff)
-
languages/aks-affiliate-fr_FR.mo (modified) (previous)
-
languages/aks-affiliate-fr_FR.po (modified) (3 diffs)
-
languages/aks-affiliate.pot (modified) (4 diffs)
-
main.php (modified) (2 diffs)
-
readme.txt (modified) (1 diff)
-
src/Controller/Manager.php (modified) (7 diffs)
-
src/MetaBox/WidgetMetaBox.php (modified) (2 diffs)
-
src/Services/AffiliateApi.php (modified) (2 diffs)
-
src/Services/ViewHelper.php (added)
Legend:
- Unmodified
- Added
- Removed
-
allkeyshop-affiliate/trunk/assets/js/widgetMetaBox.js
r2756437 r2763492 6 6 let templateValue = templateInput.value; 7 7 8 let positionInput = document.querySelector('#aks-plugin_position-input'); 9 let positionValue = positionInput.value; 10 8 11 return { 9 12 game : gameValue, 10 template: templateValue 13 template: templateValue, 14 position : positionValue 11 15 }; 12 16 } … … 17 21 if (metaBoxData.game === null) return false; 18 22 23 // Without Classic Editor 19 24 if (tinymce.activeEditor === null || tinymce.activeEditor.id !== 'content') { 20 25 let insertedBlock = wp.blocks.createBlock('core/shortcode', { 21 26 text: '[allkeyshop_widget_offers game="' + metaBoxData.game.value + '" template="' + metaBoxData.template + '"]', 22 27 }); 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 } 27 45 } 28 46 } -
allkeyshop-affiliate/trunk/assets/views/index.php
r2756437 r2763492 6 6 </script> 7 7 <div class="aks-plugin_container"> 8 < h1>Allkeyshop Affiliate Plugin</h1>8 <?php require('include/header.php'); ?> 9 9 <div class="aks-plugin_dashboard"> 10 10 <div class="aks-plugin_content-box grid-full"> -
allkeyshop-affiliate/trunk/assets/views/widgetMetaBox.php
r2756437 r2763492 6 6 <div class="field"> 7 7 <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> 13 16 </select> 14 17 </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. 3 3 msgid "" 4 4 msgstr "" 5 "Project-Id-Version: Allkeyshop Affiliate \n"5 "Project-Id-Version: Allkeyshop Affiliate 1.0.0\n" 6 6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/aks-affiliate\n" 7 "POT-Creation-Date: 2022-0 6-13T13:09:12+00:00\n"8 "PO-Revision-Date: 2022-0 6-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" 9 9 "Last-Translator: \n" 10 10 "Language-Team: \n" … … 20 20 msgid "Allkeyshop Affiliate" 21 21 msgstr "Allkeyshop Affiliate" 22 23 #. Description of the plugin 24 msgid "Earn money by adding game prices comparison widgets" 25 msgstr "Gagnez de l'argent en ajoutant des widget de comparaison de prix" 26 27 #. Author of the plugin 28 msgid "Allkeyshop" 29 msgstr "Allkeyshop" 30 31 #: assets/views/helper/select-template.php:2 32 msgid "Default" 33 msgstr "Aucun template" 22 34 23 35 #: assets/views/index.php:11 … … 104 116 msgstr "Sélectionnez un template" 105 117 118 #: assets/views/widgetMetaBox.php:11 119 msgid "Select a position" 120 msgstr "Sélectionnez une position" 121 122 #: assets/views/widgetMetaBox.php:13 123 msgid "At the top" 124 msgstr "Au début" 125 126 #: assets/views/widgetMetaBox.php:14 127 msgid "At the bottom" 128 msgstr "À la fin" 129 106 130 #: assets/views/widgetMetaBox.php:15 131 msgid "At the cursor position" 132 msgstr "À la position du curseur" 133 134 #: assets/views/widgetMetaBox.php:18 107 135 msgid "Insert" 108 136 msgstr "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. 3 3 msgid "" 4 4 msgstr "" 5 "Project-Id-Version: Allkeyshop Affiliate \n"5 "Project-Id-Version: Allkeyshop Affiliate 1.0.0\n" 6 6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/aks-affiliate\n" 7 7 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" … … 10 10 "Content-Type: text/plain; charset=UTF-8\n" 11 11 "Content-Transfer-Encoding: 8bit\n" 12 "POT-Creation-Date: 2022-0 6-13T13:09:12+00:00\n"12 "POT-Creation-Date: 2022-07-29T13:10:45+00:00\n" 13 13 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 14 14 "X-Generator: WP-CLI 2.6.0\n" … … 17 17 #. Plugin Name of the plugin 18 18 msgid "Allkeyshop Affiliate" 19 msgstr "" 20 21 #. Description of the plugin 22 msgid "Earn money by adding game prices comparison widgets" 23 msgstr "" 24 25 #. Author of the plugin 26 msgid "Allkeyshop" 27 msgstr "" 28 29 #: assets/views/helper/select-template.php:2 30 msgid "Default" 19 31 msgstr "" 20 32 … … 71 83 msgstr "" 72 84 85 #: assets/views/widgetMetaBox.php:11 86 msgid "Select a position" 87 msgstr "" 88 89 #: assets/views/widgetMetaBox.php:13 90 msgid "At the top" 91 msgstr "" 92 93 #: assets/views/widgetMetaBox.php:14 94 msgid "At the bottom" 95 msgstr "" 96 73 97 #: assets/views/widgetMetaBox.php:15 98 msgid "At the cursor position" 99 msgstr "" 100 101 #: assets/views/widgetMetaBox.php:18 74 102 msgid "Insert" 75 103 msgstr "" -
allkeyshop-affiliate/trunk/main.php
r2756437 r2763492 3 3 * Plugin Name: Allkeyshop Affiliate 4 4 * Description: Earn money by adding game prices comparison widgets 5 * Version: 1.0. 05 * Version: 1.0.1 6 6 * Requires at least: 5.9 7 7 * Requires PHP: 7.0 … … 19 19 require_once __DIR__ .'/src/Services/AffiliateApi.php'; 20 20 require_once __DIR__ .'/src/Services/VaksApi.php'; 21 require_once __DIR__ .'/src/Services/ViewHelper.php'; 21 22 require_once __DIR__ .'/src/Controller/Manager.php'; 22 23 require_once __DIR__ .'/src/MetaBox/WidgetMetaBox.php'; -
allkeyshop-affiliate/trunk/readme.txt
r2756437 r2763492 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html 9 Stable tag: 1.0. 09 Stable tag: 1.0.1 10 10 11 11 Allkeyshop Widget integration for WordPress -
allkeyshop-affiliate/trunk/src/Controller/Manager.php
r2756437 r2763492 14 14 public static $widgetJs; 15 15 public static $apiKey = null; 16 public static $templates = null;17 16 18 17 /** … … 21 20 public static function init() 22 21 { 23 self::$assetDir = AKS_AFFILIATE_PLUGIN_PATH_ROOT . ' /assets/';22 self::$assetDir = AKS_AFFILIATE_PLUGIN_PATH_ROOT . 'assets/'; 24 23 self::$viewsDir = self::$assetDir . 'views/'; 25 24 self::$affiliateUrl = defined('AKS_AFFILIATE_PLUGIN_ENV') ? 'http://aks.affiliate.local' : 'https://affiliate.allkeyshop.com'; … … 61 60 'dashicons-buddicons-buddypress-logo' 62 61 ); 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 );*/ 63 86 } 64 87 … … 84 107 85 108 /** 86 * Load all the template of teh current api key87 */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 key105 * @param string $type Type of the template106 */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 id131 * @param int $templateId the template id132 */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 /**144 109 * Load the global JS and CSS files 145 110 */ … … 238 203 public static function createGamePage() 239 204 { 240 $data = [' idPage' => null, 'url' => null, 'error' => null];205 $data = ['error' => null]; 241 206 if(isset($_POST['game']) && is_numeric($_POST['game'])) { 242 207 $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 } 244 212 $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 247 217 if ($idPage !== null) { 248 $data['idPage'] = $idPage; 249 $data['url'] = get_page_link($idPage); 218 $data['url'] = get_edit_post_link($idPage); 250 219 } 251 220 } … … 257 226 * @param int $gameId 258 227 * @param array $options array for some specific options : 259 * - slug : allow to change the page slug228 * - template : template of the widget 260 229 * - title: Change the title of the page 261 230 * @param array $errors allow to retrieve the errors when the game page creation fail 262 231 */ 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(); 264 238 265 239 $gameTitle = VaksApi::getGamesTitle($gameId); … … 268 242 'post_status' => 'publish', 269 243 'post_type' => 'page', 270 'post_content' => '[allkeyshop_game_page game="' . $gameId . '" template="3"]',244 'post_content' => $postContent, 271 245 'post_author' => get_current_user_id() 272 246 ]; -
allkeyshop-affiliate/trunk/src/MetaBox/WidgetMetaBox.php
r2756437 r2763492 3 3 4 4 use AllkeyshopAffiliate\Manager; 5 use AllkeyshopAffiliate\Services\AffiliateApi; 5 6 6 7 class WidgetMetaBox … … 48 49 { 49 50 $data = [ 50 'templates' => Manager::getTemplates('game-prices-comparison'),51 51 'game' => get_post_meta($post->ID, self::META_KEY_GAME, true), 52 52 'template' => get_post_meta($post->ID, self::META_KEY_TEMPLATE, true) -
allkeyshop-affiliate/trunk/src/Services/AffiliateApi.php
r2756437 r2763492 6 6 class AffiliateApi 7 7 { 8 9 8 public static $apiUrl; 9 private static $_templates = []; 10 10 11 11 public static function init() { … … 44 44 } 45 45 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 46 77 /** 47 * Get the templatefor an API key78 * Get all the templates for an API key 48 79 * @param string $apiKey 80 * @param string $type template type 81 * @param bool $forceRefresh allow to bypass the cache 49 82 * @return array 50 83 */ 51 public static function loadTemplates(string $apiKey )84 public static function loadTemplates(string $apiKey, string $type = null, bool $forceRefresh = false) 52 85 { 86 if (self::_hasLoadedTemplates($apiKey) && !$forceRefresh) { 87 return self::_getTemplates($apiKey, $type); 88 } 53 89 $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; 55 111 } 56 112
Note: See TracChangeset
for help on using the changeset viewer.