Changeset 2473653
- Timestamp:
- 02/12/2021 10:36:45 AM (5 years ago)
- Location:
- abyssale
- Files:
-
- 12 added
- 4 edited
-
tags/1.2 (added)
-
tags/1.2/README.md (added)
-
tags/1.2/README.txt (added)
-
tags/1.2/abyssale.php (added)
-
tags/1.2/common (added)
-
tags/1.2/common/abyssale-api.php (added)
-
tags/1.2/imgs (added)
-
tags/1.2/imgs/logo-abyssale.png (added)
-
tags/1.2/partials (added)
-
tags/1.2/partials/admin-editor.php (added)
-
tags/1.2/partials/admin-settings-display.php (added)
-
tags/1.2/partials/template-section.php (added)
-
trunk/README.txt (modified) (1 diff)
-
trunk/abyssale.php (modified) (8 diffs)
-
trunk/common/abyssale-api.php (modified) (3 diffs)
-
trunk/partials/admin-settings-display.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
abyssale/trunk/README.txt
r2449826 r2473653 3 3 Requires at least: 5.5.3 4 4 Tested up to: 5.5.3 5 Stable tag: 1. 15 Stable tag: 1.2 6 6 Requires PHP: 7.0 7 7 License: GNU General Public License (GPL) version 3 -
abyssale/trunk/abyssale.php
r2449826 r2473653 3 3 * Plugin Name: Abyssale 4 4 * Description: Create an header image when you create a new blog post. 5 * Version: 1. 15 * Version: 1.2 6 6 * Author: Abyssale 7 7 * Author URI: https://www.abyssale.com/?utm_source=wp-plugins&utm_campaign=author-uri&utm_medium=wordpress … … 62 62 $response = $this->abyssaleApi->callAbyssaleApi( 63 63 $settingsOptions["template_id"], 64 $settingsOptions["format"], 64 65 sanitize_text_field($_POST["title"]), 65 66 get_the_author_meta('display_name', $post->post_author), … … 206 207 207 208 add_settings_field( 209 'format', 210 'Template format:', 211 array($this, 'renderTemplateFormat'), 212 'abyssale_template_settings', 213 'section_templates' 214 ); 215 216 add_settings_field( 208 217 'title', 209 218 'Wordpress title:', … … 285 294 { 286 295 $output['template_id'] = sanitize_text_field($input['template_id']); 296 $output['format'] = sanitize_text_field($input['format']); 287 297 $output['title'] = sanitize_text_field($input['title']); 288 298 $output['author_name'] = sanitize_text_field($input['author_name']); … … 302 312 } 303 313 314 $format = sanitize_text_field($_POST["abyssale_plugin_template_settings"]["format"]); 304 315 $title = sanitize_text_field($_POST["abyssale_plugin_template_settings"]["title"]); 305 316 $authorName = sanitize_text_field($_POST["abyssale_plugin_template_settings"]["author_name"]); … … 324 335 "image" => $image, 325 336 "creation_date" => $creationDate, 337 "format" => $format, 326 338 ) 327 339 ); … … 458 470 } 459 471 472 public function renderTemplateFormat($args) 473 { 474 $templateFormats = array(); 475 $optionsApikey = get_option('abyssale_plugin_settings'); 476 $optionsTemplate = get_option('abyssale_plugin_template_settings'); 477 if ($optionsApikey["api_key"] != null && $optionsTemplate["template_id"] != null) { 478 $response = $this->abyssaleApi->getTemplate($optionsTemplate["template_id"], false); 479 if ($response["is_error"] == true) { 480 throw new Exception("An error occurred when retrieving the template."); 481 } 482 483 $templateFormats = $response["template"]["formats"]; 484 } 485 486 $options = get_option('abyssale_plugin_template_settings'); 487 printf('<select style="width:300px" id="format" name="%s" value="%s">', esc_attr('abyssale_plugin_template_settings[format]'), esc_attr($options["format"])); 488 foreach ($templateFormats as $format) { 489 if ($format["id"] == $options["format"]) { 490 echo '<option selected="selected" value="'.esc_attr($format["id"]).'">'.esc_attr($format["id"]).'</option>'; 491 } else { 492 echo '<option value="'.esc_attr($format["id"]).'">'.esc_attr($format["id"]).'</option>'; 493 } 494 } 495 echo '</select>'; 496 } 497 460 498 public function renderHidden($args) 461 499 { … … 483 521 $response = $this->abyssaleApi->callAbyssaleApi( 484 522 $settingsOptions["template_id"], 523 $settingsOptions["format"], 485 524 "Title example", 486 525 "Author name", -
abyssale/trunk/common/abyssale-api.php
r2435497 r2473653 77 77 } 78 78 79 public function callAbyssaleApi($templateId, $ title, $authorName, $creationDate, $image, $options)79 public function callAbyssaleApi($templateId, $format, $title, $authorName, $creationDate, $image, $options) 80 80 { 81 81 if ($templateId == null) { … … 89 89 "elements" => array() 90 90 ); 91 92 if ($format != null && $format != "") { 93 $requestBody["template_format_name"] = $format; 94 } 95 91 96 if (isset($options["title"]) && $options["title"] != "" && ($title != "" || $title != null)) { 92 97 $requestBody["elements"][$options["title"]] = array( … … 124 129 'headers' => array( 125 130 "x-api-key" => $this->apiKey, 126 'Content-Type' => 'application/json' 131 'Content-Type' => 'application/json', 132 "X-Referer" => "wordpress" 127 133 ), 128 134 'body' => json_encode($requestBody), -
abyssale/trunk/partials/admin-settings-display.php
r2435497 r2473653 121 121 jQuery(id).find('option').remove().end().append('<option value="none">None</option>').val('none') 122 122 } 123 124 jQuery("#format").find('option').remove().end().append('<option value="default">Default</option>').val('default') 123 125 }, 124 126 success: function(response) { 125 127 if("template_id" in response) { 126 for (const templateElement of response["elements"]) {128 for (const templateElement of response["elements"]) { 127 129 jQuery("#title")[0].options.add( new Option(templateElement["name"],templateElement["name"]) ) 128 130 jQuery("#author_name")[0].options.add( new Option(templateElement["name"],templateElement["name"]) ) 129 131 jQuery("#image")[0].options.add( new Option(templateElement["name"],templateElement["name"]) ) 130 132 jQuery("#creation_date")[0].options.add( new Option(templateElement["name"],templateElement["name"]) ) 133 } 134 135 jQuery("#format").find('option').remove().end(); 136 for (const format of response["formats"]) { 137 jQuery("#format")[0].options.add( new Option(format["id"],format["id"]) ) 131 138 } 132 139 }
Note: See TracChangeset
for help on using the changeset viewer.