Changeset 2457492
- Timestamp:
- 01/16/2021 11:32:12 AM (4 years ago)
- Location:
- super-reactions/trunk
- Files:
-
- 7 added
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
super-reactions/trunk/admin/assets/dist/css/srea-admin.css
r2452813 r2457492 1 .srea-settings-wrapper{2 display: flex;3 flex-direction: column;1 { 2 ; 3 ; 4 4 } 5 5 6 .srea-settings-wrapper .srea-template-selector { 6 .srea-admin-wrapper { 7 display: block; 8 margin: 0 auto; 9 max-width: 900px; 10 height: 100%; 11 background-color: #ffffff; 12 } 13 14 .srea-admin-wrapper select, .srea-admin-wrapper input { 15 border-radius: 0; 16 } 17 18 .srea-admin-header { 19 display: flex; 20 flex-basis: 50%; 21 background-color: #ffffff; 22 box-shadow: 1px 1px 5px 2px #cccccc; 23 padding: 10px; 24 align-items: center; 25 } 26 27 .srea-admin-header .srea-admin-title { 28 text-align: center; 29 flex: 1 0 auto; 30 justify-self: center; 31 } 32 33 .srea-admin-main { 34 padding: 20px; 35 } 36 37 .srea-admin-main .srea-settings-wrapper { 38 display: flex; 39 justify-content: flex-start; 40 flex-wrap: wrap; 41 } 42 43 .srea-admin-main .srea-settings-wrapper .srea-template-selector { 7 44 display: flex; 8 45 align-items: center; 9 justify-content: space-between; 10 width: 180px; 11 margin-bottom: 20px; 46 flex-grow: 1; 47 flex-basis: 33%; 12 48 } 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 -
super-reactions/trunk/admin/assets/dist/css/srea-admin.min.css
r2452813 r2457492 1 .srea-settings-wrapper{display:flex;flex-direction:column}.srea-settings-wrapper .srea-template-selector{display:flex;align-items:center;justify-content:space-between;width:180px;margin-bottom:20px}1 px} -
super-reactions/trunk/admin/class-init.php
r2452813 r2457492 24 24 add_action( 'admin_enqueue_scripts', array( $this, 'assets' ) ); 25 25 add_action( 'admin_menu', array( $this, 'add_menu_page' ) ); 26 add_action( 'admin_init', array( $this, 'register_settings' ) );27 26 } 28 27 … … 30 29 if ( 'toplevel_page_super-reactions' === $hook ) { 31 30 wp_enqueue_style( 'srea-admin' ); 31 32 32 } 33 33 } … … 47 47 public function renbder_settings_page() { 48 48 ?> 49 <form method="POST" action="options.php"> 50 <?php 51 settings_fields( 'super-reactions' ); 52 do_settings_sections( 'super-reactions' ); 53 submit_button(); 54 ?> 55 </form> 49 <div class="srea-admin-wrapper"> 50 <div class="srea-admin-header"> 51 <div class="srea-logo"> 52 <?php srea_logo( 100, 100 ); ?> 53 </div> 54 <div class="srea-admin-title"> 55 <h1><?php esc_html_e( 'Super Reactions', 'super-reactions' ); ?></h1> 56 </div> 57 </div> 58 <div class="srea-admin-main"> 59 <section class="srea-settings"> 60 <h2><?php esc_html_e( 'Templates:', 'super-reactions' ); ?></h2> 61 <?php $this->template_selector(); ?> 62 <?php wp_nonce_field('srea_save_settings'); ?> 63 </section> 64 </div> 65 </div> 56 66 <?php 57 }58 59 public function register_settings() {60 61 add_settings_section(62 'srea_settings_section',63 __( 'Super Reaction Settings', 'wp-reaction' ),64 array(),65 'super-reactions'66 );67 68 add_settings_field(69 'srea_config',70 __( 'Reaction Templates:', 'super-reactions' ),71 array( $this, 'template_selector' ),72 'super-reactions',73 'srea_settings_section'74 );75 76 register_setting( 'super-reactions', 'srea_config' );77 67 } 78 68 … … 80 70 ?> 81 71 <div class="srea-settings-wrapper"> 82 <?php $this->render_setting_row( 'post' ); ?> 83 <?php $this->render_setting_row( 'page' ); ?> 72 <?php 73 $args = array( 74 'public' => true, 75 ); 76 77 $post_types = get_post_types( $args ); 78 79 // remove attachment from the list 80 unset( $post_types['attachment'] ); 81 82 foreach ( $post_types as $post_type ) { 83 $this->render_setting_row( $post_type ); 84 } 85 86 ?> 84 87 </div> 85 88 <?php … … 87 90 88 91 private function render_setting_row( $post_type ) { 89 $reactions = Functions\srea_reactions();92 $reactions = srea_reactions(); 90 93 ?> 91 94 <div class="srea-template-selector"> 92 95 <label for="srea-template-selector-<?php echo esc_attr( $post_type ); ?>"><?php echo ucfirst( $post_type ) . ':'; ?></label> 93 <select name=" srea_config[active_template][<?php echo esc_attr( $post_type ); ?>]" id="srea-template-selector-<?php echo esc_attr( $post_type ); ?>">96 <select name="" id="srea-template-selector-<?php echo esc_attr( $post_type ); ?>"> 94 97 <option value="0"><?php esc_html_e( 'Disable', 'super-reactions' ); ?></option> 95 98 <?php foreach ( $reactions as $slug => $reaction ) : ?> 96 <?php $selected = Functions\srea_get_active_template_slug( $post_type ) === $slug ? 'selected' : ''; ?>99 <?php $selected = srea_get_active_template_slug( $post_type ) === $slug ? 'selected' : ''; ?> 97 100 <option value="<?php echo esc_attr( $slug ); ?>" <?php echo esc_attr( $selected ); ?> ><?php echo esc_html( $reaction['name'] ); ?></option> 98 101 <?php endforeach; ?> -
super-reactions/trunk/constants.php
r2452811 r2457492 6 6 define( 'SREA_URL', plugin_dir_url( __FILE__ ) ); 7 7 8 define( 'SREA_VERSION', '1. 0.5' );8 define( 'SREA_VERSION', '1.' ); 9 9 define( 'SREA_SLUG', 'super_reactions' ); 10 10 … … 13 13 14 14 define( 'SREA_FRONT_ASSETS', SREA_URL . 'front/assets/dist/' ); 15 15 16 define( 'SREA_ADMIN_ASSETS', SREA_ADMIN_URL . 'assets/dist/' ); -
super-reactions/trunk/front/assets/dist/js/srea-front.js
r2452813 r2457492 1 'use strict';1 ; 2 2 3 3 var srea = { 4 handleAction: function handleAction(e) { 5 if (e.target.tagName !== 'BUTTON') return; 4 handleAction: function handleAction(e) { 5 var _e$currentTarget$data = e.currentTarget.dataset, 6 id = _e$currentTarget$data.sreaPostId, 7 sreaSlug = _e$currentTarget$data.sreaSlug, 8 n = _e$currentTarget$data.nonce, 9 currentReaction = _e$currentTarget$data.reacted; 10 var $clickedButton = e.target.closest('.srea-button'); 11 var sreaAction = $clickedButton.dataset.sreaAction; 12 var $parent = e.target.closest('.srea-template'); 6 13 7 var _e$currentTarget$data = e.currentTarget.dataset, 8 id = _e$currentTarget$data.sreaPostId, 9 sreaSlug = _e$currentTarget$data.sreaSlug, 10 n = _e$currentTarget$data.nonce, 11 prevReaction = _e$currentTarget$data.reacted; 14 if (!sreaAction || !id) { 15 return false; 16 } 12 17 13 14 srea.$el = { 15 'button': e.target.closest('.srea-button'), 16 'template': e.currentTarget 17 }; 18 19 srea.action = srea.$el.button.dataset.sreaAction; 20 srea.counterElement = srea.getCounter(e.target); 21 srea.prevReaction = jQuery(srea.$el.template).find('[data-srea-action="' + prevReaction + '"]').siblings('.srea-template-count'); 22 23 srea.showLoader(); 24 srea.disableButton(); 25 26 srea.sendReaction({ 27 action: 'srea_handle_post_reactions', 28 current: prevReaction, 29 srea_action: srea.action, 30 slug: sreaSlug, 31 post_id: id, 32 n: n 33 }); 34 }, 35 getCounter: function getCounter(node) { 36 return jQuery(node).siblings('.srea-template-count').get(0); 37 }, 38 sendReaction: function sendReaction(data) { 39 jQuery.post(SREA.ajaxurl, data, srea.updateView); 40 }, 41 updateView: function updateView(res) { 42 if (res.success) { 43 srea.setReaction(); 44 srea.prevReaction.textContent = res.data.old_count; 45 srea.counterElement.textContent = res.data.count; 46 srea.enableButton(); 47 } 48 }, 49 setReaction: function setReaction() { 50 srea.$el.template.setAttribute('data-reacted', srea.action); 51 }, 52 getLoader: function getLoader() { 53 var loader = document.createElement('div'); 54 loader.className = 'srea-loader'; 55 return loader; 56 }, 57 showLoader: function showLoader() { 58 srea.counterElement.innerHTML = ''; 59 srea.counterElement.appendChild(srea.getLoader()); 60 }, 61 enableButton: function enableButton() { 62 srea.$el.button.disabled = false; 63 }, 64 disableButton: function disableButton() { 65 srea.$el.button.disabled = true; 66 } 18 var counterElement = jQuery(e.target).siblings('.srea-template-count'); 19 var currentReactionElement = jQuery($parent).find("[data-srea-action=\"".concat(currentReaction, "\"]")).siblings('.srea-template-count'); 20 counterElement.html(srea.getLoader()); 21 $clickedButton.disabled = true; 22 var data = { 23 action: 'srea_handle_post_reactions', 24 current: currentReaction, 25 srea_action: sreaAction, 26 slug: sreaSlug, 27 post_id: id, 28 n: n 29 }; 30 jQuery.post(SREA.ajaxurl, data, function (res) { 31 if (res.success) { 32 $parent.setAttribute('data-reacted', sreaAction); 33 currentReactionElement.html(res.data.old_count); 34 counterElement.html(res.data.count); 35 $clickedButton.disabled = false; 36 } 37 }); 38 }, 39 getLoader: function getLoader() { 40 var loader = document.createElement('div'); 41 loader.className = 'srea-loader'; 42 return loader; 43 } 67 44 }; 68 69 45 window.addEventListener('DOMContentLoaded', function () { 70 71 var sreaElement = document.querySelectorAll('.srea-template'); 72 73 sreaElement.forEach(function (el, i) { 74 el.addEventListener('click', srea.handleAction); 75 }); 46 var sreaElement = document.querySelectorAll('.srea-template'); 47 sreaElement.forEach(function (el, i) { 48 el.addEventListener('click', srea.handleAction); 49 }); 76 50 }); -
super-reactions/trunk/front/assets/dist/js/srea-front.min.js
r2452813 r2457492 1 "use strict";var srea={handleAction:function(e){ if("BUTTON"===e.target.tagName){var t=e.currentTarget.dataset,a=t.sreaPostId,n=t.sreaSlug,r=t.nonce,s=t.reacted;srea.$el={button:e.target.closest(".srea-button"),template:e.currentTarget},srea.action=srea.$el.button.dataset.sreaAction,srea.counterElement=srea.getCounter(e.target),srea.prevReaction=jQuery(srea.$el.template).find('[data-srea-action="'+s+'"]').siblings(".srea-template-count"),srea.showLoader(),srea.disableButton(),srea.sendReaction({action:"srea_handle_post_reactions",current:s,srea_action:srea.action,slug:n,post_id:a,n:r})}},getCounter:function(e){return jQuery(e).siblings(".srea-template-count").get(0)},sendReaction:function(e){jQuery.post(SREA.ajaxurl,e,srea.updateView)},updateView:function(e){e.success&&(srea.setReaction(),srea.prevReaction.textContent=e.data.old_count,srea.counterElement.textContent=e.data.count,srea.enableButton())},setReaction:function(){srea.$el.template.setAttribute("data-reacted",srea.action)},getLoader:function(){var e=document.createElement("div");return e.className="srea-loader",e},showLoader:function(){srea.counterElement.innerHTML="",srea.counterElement.appendChild(srea.getLoader())},enableButton:function(){srea.$el.button.disabled=!1},disableButton:function(){srea.$el.button.disabled=!0}};window.addEventListener("DOMContentLoaded",function(){document.querySelectorAll(".srea-template").forEach(function(e,t){e.addEventListener("click",srea.handleAction)})});1 "use strict";var srea={handleAction:function(e){}};window.addEventListener("DOMContentLoaded",function(){document.querySelectorAll(".srea-template").forEach(function(e,t){e.addEventListener("click",srea.handleAction)})}); -
super-reactions/trunk/includes/ajax.php
r2452813 r2457492 30 30 } 31 31 32 $user_reaction = Functions\srea_get_user_reaction( $post_id, $slug );32 $user_reaction = srea_get_user_reaction( $post_id, $slug ); 33 33 34 34 $params['slug'] = $slug; … … 47 47 } 48 48 } else { 49 $params['time'] = current_time( 'mysql' , false);49 $params['time'] = current_time( 'mysql' ); 50 50 $params['content_type'] = 'post'; 51 51 $params['value'] = 1; -
super-reactions/trunk/includes/class-assets.php
r2452813 r2457492 52 52 53 53 public function register_admin_scripts() { 54 wp_register_script( 'srea-admin', SREA_ADMIN_ASSETS . 'js/srea-admin' . $this->suffix . '.js', SREA_VERSION, false );54 wp_register_script( 'srea-admin', SREA_ADMIN_ASSETS . 'js/srea-admin' . $this->suffix . '.js', SREA_VERSION, e ); 55 55 } 56 56 -
super-reactions/trunk/includes/functions/functions.php
r2452813 r2457492 1 1 <?php 2 3 namespace SREA\Includes\Functions;4 2 5 3 use SREA\Includes\DB; … … 12 10 function srea_reactions() { 13 11 return ( new SREA_Reactions() )->get_all(); 14 }15 16 function srea_get_config( string $option, $default = false ) {17 $options = get_option( 'srea_config', array() );18 19 return $options[ $option ] ?? $default;20 12 } 21 13 … … 32 24 33 25 } 26 27 28 29 30 31 32 33 34 35 36 37 38 -
super-reactions/trunk/includes/functions/templates.php
r2452813 r2457492 1 1 <?php 2 3 namespace SREA\Includes\Functions;4 2 5 3 function srea_get_template( string $reaction_slug ) { … … 9 7 10 8 $reaction = srea_get_reaction( $reaction_slug ); 11 $template = call_user_func_array( 'SREA\Includes\Functions\\' .$reaction['content_callback'], array( get_the_ID(), get_post_type(), $reaction, $reaction_slug ) );9 $template = call_user_func_array( $reaction['content_callback'], array( get_the_ID(), get_post_type(), $reaction, $reaction_slug ) ); 12 10 13 11 return apply_filters( 'srea_filter_template_markup', $template, $reaction_slug ); … … 15 13 16 14 function srea_get_active_template_slug( string $section ) { 17 $active_template = srea_get_ config( 'active_template', array() );15 $active_template = srea_get_( 'active_template', array() ); 18 16 return apply_filters( 'srea_filter_active_template_slug', $active_template[ $section ] ?? '' ); 19 17 } -
super-reactions/trunk/includes/hooks.php
r2452813 r2457492 8 8 9 9 function srea_add_reaction_buttons( $content ) { 10 $templates = array(11 Functions\srea_get_active_template_slug( 'post' ),12 Functions\srea_get_active_template_slug( 'page' ),13 );14 10 15 if ( in_array( 'disable', $templates, true ) ) { 16 return $content; 11 $post_type = get_post_type(); 12 13 if ( is_singular( $post_type ) ) { 14 $reaction_markup = srea_get_active_template( $post_type ); 15 if ( 'disable' != $reaction_markup ) { 16 $content .= $reaction_markup; 17 } 17 18 } 18 19 19 $section = is_single() ? 'post' : ( is_page() ? 'page' : '' ); 20 21 $reaction_markup = Functions\srea_get_active_template( $section ); 22 23 return $content . $reaction_markup; 20 return $content; 24 21 } -
super-reactions/trunk/languages/super-reactions.pot
r2452813 r2457492 16 16 "Plural-Forms: nplurals=2; plural=(n != 1);\n" 17 17 18 #: admin/class-init.php:37 18 #: admin/ajax.php:16 19 msgid "Saved!" 20 msgstr "" 21 22 #: admin/ajax.php:23 23 msgid "Failed!" 24 msgstr "" 25 26 #: admin/class-init.php:37, admin/class-init.php:55 19 27 msgid "Super Reactions" 20 28 msgstr "" … … 24 32 msgstr "" 25 33 26 #: admin/class-init.php: 7027 msgid " ReactionTemplates:"34 #: admin/class-init.php:0 35 msgid "Templates:" 28 36 msgstr "" 29 37 30 #: admin/class-init.php:9 438 #: admin/class-init.php:9 31 39 msgid "Disable" 32 40 msgstr "" -
super-reactions/trunk/readme.txt
r2452811 r2457492 6 6 Tested up to: 5.6 7 7 Requires PHP: 7.0 8 Stable tag: 1. 0.58 Stable tag: 1. 9 9 License: GPLv3 10 10 License URI: http://www.gnu.org/licenses/gpl-3.0.html … … 27 27 == Changelog == 28 28 29 = 1.0.0 = 29 30 = 1.1.0 = 31 * New admin interface 32 * Autosave configs 33 * Code improvements 34 35 = 1.0.5 = 30 36 * Initial Version. -
super-reactions/trunk/super-reactions.php
r2452825 r2457492 4 4 * Plugin Name: Super Reactions 5 5 * Description: Get meaningful reactions from users. 6 * Version: 1. 0.56 * Version: 1. 7 7 * Author: Super Reactions Team 8 8 * Text Domain: super-reactions … … 24 24 require_once 'vendor/autoload.php'; 25 25 26 register_activation_hook( __FILE__, '\SREA\srea_activation_hook_callback' );27 28 function srea_activation_hook_callback() {29 \SREA\Includes\Init::activate();30 }31 32 register_deactivation_hook( __FILE__, '\SREA\srea_deactivation_hook_callback' );33 34 function srea_deactivation_hook_callback() {35 \SREA\Includes\Init::deactivate();36 }37 38 26 Admin::instance(); 39 27 Assets::instance(); -
super-reactions/trunk/vendor/composer/autoload_classmap.php
r2452832 r2457492 12 12 'SREA\\Includes\\Assets' => $baseDir . '/includes/class-assets.php', 13 13 'SREA\\Includes\\DB' => $baseDir . '/includes/class-db.php', 14 'SREA\\Includes\\Init' => $baseDir . '/includes/class-init.php',15 14 'SREA\\Includes\\SREA_Reactions' => $baseDir . '/includes/class-reactions.php', 16 15 ); -
super-reactions/trunk/vendor/composer/autoload_files.php
r2452813 r2457492 8 8 return array( 9 9 'd7087685a66a9bc40ee207a689b61d6b' => $baseDir . '/constants.php', 10 10 11 '957270c1e830953d8ce3586b81de9f3a' => $baseDir . '/includes/functions/functions.php', 11 12 '4954a77bb950b640e6ac002ba8f822f6' => $baseDir . '/includes/functions/helpers.php', … … 13 14 '77480ddb9859d9f3c791246cfc990e2e' => $baseDir . '/includes/hooks.php', 14 15 '3426d36287fe85bae7001c4d7404d49d' => $baseDir . '/includes/ajax.php', 16 15 17 ); -
super-reactions/trunk/vendor/composer/autoload_static.php
r2452832 r2457492 9 9 public static $files = array ( 10 10 'd7087685a66a9bc40ee207a689b61d6b' => __DIR__ . '/../..' . '/constants.php', 11 11 12 '957270c1e830953d8ce3586b81de9f3a' => __DIR__ . '/../..' . '/includes/functions/functions.php', 12 13 '4954a77bb950b640e6ac002ba8f822f6' => __DIR__ . '/../..' . '/includes/functions/helpers.php', … … 14 15 '77480ddb9859d9f3c791246cfc990e2e' => __DIR__ . '/../..' . '/includes/hooks.php', 15 16 '3426d36287fe85bae7001c4d7404d49d' => __DIR__ . '/../..' . '/includes/ajax.php', 17 16 18 ); 17 19 … … 22 24 'SREA\\Includes\\Assets' => __DIR__ . '/../..' . '/includes/class-assets.php', 23 25 'SREA\\Includes\\DB' => __DIR__ . '/../..' . '/includes/class-db.php', 24 'SREA\\Includes\\Init' => __DIR__ . '/../..' . '/includes/class-init.php',25 26 'SREA\\Includes\\SREA_Reactions' => __DIR__ . '/../..' . '/includes/class-reactions.php', 26 27 );
Note: See TracChangeset
for help on using the changeset viewer.