Plugin Directory

Changeset 2457492

Timestamp:
01/16/2021 11:32:12 AM (4 years ago)
Author:
h71
Message:

version-1.1.0

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  ;
    44}
    55
    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 {
    744  display: flex;
    845  align-items: center;
    9   justify-content: space-between;
    10   width: 180px;
    11   margin-bottom: 20px;
     46  flex-grow: 1;
     47  flex-basis: 33%;
    1248}
     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}
     1px}
  • super-reactions/trunk/admin/class-init.php

    r2452813 r2457492  
    2424        add_action( 'admin_enqueue_scripts', array( $this, 'assets' ) );
    2525        add_action( 'admin_menu', array( $this, 'add_menu_page' ) );
    26         add_action( 'admin_init', array( $this, 'register_settings' ) );
    2726    }
    2827
     
    3029        if ( 'toplevel_page_super-reactions' === $hook ) {
    3130            wp_enqueue_style( 'srea-admin' );
     31
    3232        }
    3333    }
     
    4747    public function renbder_settings_page() {
    4848        ?>
    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>
    5666        <?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' );
    7767    }
    7868
     
    8070        ?>
    8171        <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        ?>
    8487        </div>
    8588        <?php
     
    8790
    8891    private function render_setting_row( $post_type ) {
    89         $reactions = Functions\srea_reactions();
     92        $reactions = srea_reactions();
    9093        ?>
    9194            <div class="srea-template-selector">
    9295                <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 ); ?>">
    9497                    <option value="0"><?php esc_html_e( 'Disable', 'super-reactions' ); ?></option>
    9598                    <?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' : ''; ?>
    97100                        <option value="<?php echo esc_attr( $slug ); ?>" <?php echo esc_attr( $selected ); ?> ><?php echo esc_html( $reaction['name'] ); ?></option>
    98101                    <?php endforeach; ?>
  • super-reactions/trunk/constants.php

    r2452811 r2457492  
    66define( 'SREA_URL', plugin_dir_url( __FILE__ ) );
    77
    8 define( 'SREA_VERSION', '1.0.5' );
     8define( 'SREA_VERSION', '1.' );
    99define( 'SREA_SLUG', 'super_reactions' );
    1010
     
    1313
    1414define( 'SREA_FRONT_ASSETS', SREA_URL . 'front/assets/dist/' );
     15
    1516define( 'SREA_ADMIN_ASSETS', SREA_ADMIN_URL . 'assets/dist/' );
  • super-reactions/trunk/front/assets/dist/js/srea-front.js

    r2452813 r2457492  
    1 'use strict';
     1;
    22
    33var 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');
    613
    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    }
    1217
    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  }
    6744};
    68 
    6945window.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  });
    7650});
  • 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  
    3030    }
    3131
    32     $user_reaction = Functions\srea_get_user_reaction( $post_id, $slug );
     32    $user_reaction = srea_get_user_reaction( $post_id, $slug );
    3333
    3434    $params['slug']       = $slug;
     
    4747        }
    4848    } else {
    49         $params['time']         = current_time( 'mysql', false );
     49        $params['time']         = current_time( 'mysql' );
    5050        $params['content_type'] = 'post';
    5151        $params['value']        = 1;
  • super-reactions/trunk/includes/class-assets.php

    r2452813 r2457492  
    5252
    5353    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 );
    5555    }
    5656
  • super-reactions/trunk/includes/functions/functions.php

    r2452813 r2457492  
    11<?php
    2 
    3 namespace SREA\Includes\Functions;
    42
    53use SREA\Includes\DB;
     
    1210function srea_reactions() {
    1311    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;
    2012}
    2113
     
    3224
    3325}
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
  • super-reactions/trunk/includes/functions/templates.php

    r2452813 r2457492  
    11<?php
    2 
    3 namespace SREA\Includes\Functions;
    42
    53function srea_get_template( string $reaction_slug ) {
     
    97
    108    $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 ) );
    1210
    1311    return apply_filters( 'srea_filter_template_markup', $template, $reaction_slug );
     
    1513
    1614function srea_get_active_template_slug( string $section ) {
    17     $active_template = srea_get_config( 'active_template', array() );
     15    $active_template = srea_get_( 'active_template', array() );
    1816    return apply_filters( 'srea_filter_active_template_slug', $active_template[ $section ] ?? '' );
    1917}
  • super-reactions/trunk/includes/hooks.php

    r2452813 r2457492  
    88
    99function 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     );
    1410
    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        }
    1718    }
    1819
    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;
    2421}
  • super-reactions/trunk/languages/super-reactions.pot

    r2452813 r2457492  
    1616"Plural-Forms: nplurals=2; plural=(n != 1);\n"
    1717
    18 #: admin/class-init.php:37
     18#: admin/ajax.php:16
     19msgid "Saved!"
     20msgstr ""
     21
     22#: admin/ajax.php:23
     23msgid "Failed!"
     24msgstr ""
     25
     26#: admin/class-init.php:37, admin/class-init.php:55
    1927msgid "Super Reactions"
    2028msgstr ""
     
    2432msgstr ""
    2533
    26 #: admin/class-init.php:70
    27 msgid "Reaction Templates:"
     34#: admin/class-init.php:0
     35msgid "Templates:"
    2836msgstr ""
    2937
    30 #: admin/class-init.php:94
     38#: admin/class-init.php:9
    3139msgid "Disable"
    3240msgstr ""
  • super-reactions/trunk/readme.txt

    r2452811 r2457492  
    66Tested up to: 5.6
    77Requires PHP: 7.0
    8 Stable tag: 1.0.5
     8Stable tag: 1.
    99License: GPLv3
    1010License URI: http://www.gnu.org/licenses/gpl-3.0.html
     
    2727== Changelog ==
    2828
    29 = 1.0.0 =
     29
     30= 1.1.0 =
     31* New admin interface
     32* Autosave configs
     33* Code improvements
     34
     35= 1.0.5 =
    3036* Initial Version.
  • super-reactions/trunk/super-reactions.php

    r2452825 r2457492  
    44 * Plugin Name: Super Reactions
    55 * Description: Get meaningful reactions from users.
    6  * Version:     1.0.5
     6 * Version:     1.
    77 * Author:      Super Reactions Team
    88 * Text Domain: super-reactions
     
    2424require_once 'vendor/autoload.php';
    2525
    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 
    3826Admin::instance();
    3927Assets::instance();
  • super-reactions/trunk/vendor/composer/autoload_classmap.php

    r2452832 r2457492  
    1212    'SREA\\Includes\\Assets' => $baseDir . '/includes/class-assets.php',
    1313    'SREA\\Includes\\DB' => $baseDir . '/includes/class-db.php',
    14     'SREA\\Includes\\Init' => $baseDir . '/includes/class-init.php',
    1514    'SREA\\Includes\\SREA_Reactions' => $baseDir . '/includes/class-reactions.php',
    1615);
  • super-reactions/trunk/vendor/composer/autoload_files.php

    r2452813 r2457492  
    88return array(
    99    'd7087685a66a9bc40ee207a689b61d6b' => $baseDir . '/constants.php',
     10
    1011    '957270c1e830953d8ce3586b81de9f3a' => $baseDir . '/includes/functions/functions.php',
    1112    '4954a77bb950b640e6ac002ba8f822f6' => $baseDir . '/includes/functions/helpers.php',
     
    1314    '77480ddb9859d9f3c791246cfc990e2e' => $baseDir . '/includes/hooks.php',
    1415    '3426d36287fe85bae7001c4d7404d49d' => $baseDir . '/includes/ajax.php',
     16
    1517);
  • super-reactions/trunk/vendor/composer/autoload_static.php

    r2452832 r2457492  
    99    public static $files = array (
    1010        'd7087685a66a9bc40ee207a689b61d6b' => __DIR__ . '/../..' . '/constants.php',
     11
    1112        '957270c1e830953d8ce3586b81de9f3a' => __DIR__ . '/../..' . '/includes/functions/functions.php',
    1213        '4954a77bb950b640e6ac002ba8f822f6' => __DIR__ . '/../..' . '/includes/functions/helpers.php',
     
    1415        '77480ddb9859d9f3c791246cfc990e2e' => __DIR__ . '/../..' . '/includes/hooks.php',
    1516        '3426d36287fe85bae7001c4d7404d49d' => __DIR__ . '/../..' . '/includes/ajax.php',
     17
    1618    );
    1719
     
    2224        'SREA\\Includes\\Assets' => __DIR__ . '/../..' . '/includes/class-assets.php',
    2325        'SREA\\Includes\\DB' => __DIR__ . '/../..' . '/includes/class-db.php',
    24         'SREA\\Includes\\Init' => __DIR__ . '/../..' . '/includes/class-init.php',
    2526        'SREA\\Includes\\SREA_Reactions' => __DIR__ . '/../..' . '/includes/class-reactions.php',
    2627    );
Note: See TracChangeset for help on using the changeset viewer.