Plugin Directory

Changeset 3264323


Ignore:
Timestamp:
03/31/2025 08:52:31 AM (12 months ago)
Author:
lwsdevelopers
Message:

New hook

Location:
woorewards/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • woorewards/trunk/assets/lws-adminpanel/include/tools/session.php

    r3227529 r3264323  
    1313    private $dirty = false;
    1414    private $user = false;
     15    private $sent = false;
     16    private $created = true;
     17
     18    const OBF = true;
    1519
    1620    static public function set($key, $value)
    1721    {
    18         $GLOBALS['lwssession_user']->maybeLoad();
    19         $GLOBALS['lwssession_user']->dirty = true;
    20         $GLOBALS['lwssession_user']->data[$key] = \maybe_serialize($value);
     22        $me = $GLOBALS['lwssession_user'];
     23        $me->maybeLoad();
     24        $me->dirty = true;
     25        $me->data[$key] = \maybe_serialize($value);
     26        $me->maybeSend();
    2127    }
    2228
     
    4551            unset($me->data[$key]);
    4652        }
     53        $me->maybeSend();
    4754    }
    4855
     
    5360        \add_action('shutdown', [$me, 'save'], 200);
    5461        \add_action('wp_logout', [$me, 'clean']);
    55         \LWS\Adminpanel\Tools\Conveniences::addGreadyHook('wp', [$me, 'send']);
     62        $me->maybeRepeat();
     63    }
     64
     65    /** Force start a session.
     66     * Call this if you are sure you will use it later,
     67     * but too late to place the session cookie. */
     68    static public function start()
     69    {
     70        $GLOBALS['lwssession_user']->maybeSend();
     71    }
     72
     73    /** repeat the session cookie if any */
     74    public function maybeRepeat()
     75    {
     76        if ($this->hasUser()) {
     77            $this->maybeSend();
     78        }
     79    }
     80
     81    private function maybeSend()
     82    {
     83        if (!$this->sent) {
     84            $this->send();
     85        }
    5686    }
    5787
    5888    public function send()
    5989    {
     90        $this->sent = true;
    6091        if (!\headers_sent()) {
    6192            \setcookie(
    6293                $this->getCookieName(),
    63                 \base64_encode($this->getUser()),
     94                self::OBF ? \base64_encode($this->getUser()) : $this->getUser(),
    6495                $this->getExpiry(),
    6596                COOKIEPATH ? COOKIEPATH : '/',
     
    76107        $this->user = false;
    77108        $this->dirty = false;
    78         \setcookie(
    79             $this->getCookieName(),
    80             '',
    81             0,
    82             COOKIEPATH ? COOKIEPATH : '/',
    83             COOKIE_DOMAIN
    84         );
     109        $this->sent = false;
     110        $this->created = false;
     111        if (!\headers_sent()) {
     112            \setcookie(
     113                $this->getCookieName(),
     114                '',
     115                0,
     116                COOKIEPATH ? COOKIEPATH : '/',
     117                COOKIE_DOMAIN
     118            );
     119        }
    85120    }
    86121
     
    170205    }
    171206
     207    private function readUser()
     208    {
     209        $user = false;
     210        $name = $this->getCookieName();
     211        if (isset($_COOKIE[$name]) && $_COOKIE[$name]) {
     212            // read from cookie if any
     213            if (self::OBF) $user = \sanitize_key((string)\base64_decode((string)$_COOKIE[$name]));
     214            else $user = \sanitize_key((string)$_COOKIE[$name]);
     215            // valid format
     216            if (!\in_array(\substr($user, 0, 2), ['l_', 'g_'], true)) {
     217                $user = false;
     218            }
     219        }
     220        return $user;
     221    }
     222
     223    private function hasUser(): bool
     224    {
     225        $this->getUser();
     226        return !$this->created;
     227    }
     228
    172229    private function getUser(): string
    173230    {
    174231        if (false === $this->user) {
    175             $name = $this->getCookieName();
    176             if (isset($_COOKIE[$name]) && $_COOKIE[$name]) {
    177                 // read from cookie if any
    178                 $this->user = (string)\base64_decode((string)$_COOKIE[$name]);
    179                 if (!\in_array(\substr($this->user, 0, 2), ['l_', 'g_'], true)) {
    180                     $this->user = false;
    181                 }
    182             }
    183             return $this->user ?: $this->createUser();
     232            $this->created = false;
     233            $this->user = $this->readUser();
     234            $read = $this->user;
     235            if (!$this->user) $this->user = $this->createUser();
    184236        }
    185237        return $this->user;
     
    189241    {
    190242        if (false === $this->user) {
     243            $this->created = true;
    191244            $u = \get_current_user_id();
    192245            if ($u) {
  • woorewards/trunk/assets/lws-adminpanel/js/tools/tools.js

    r3188612 r3264323  
    2626value=elt.val();else value=elt.text();value=value.toString().normalize('NFD').replace(/[\u0300-\u036f]/g,'').toLowerCase().trim().replace(/\s+/g,'-').replace(/[^\w\-]+/g,'').replace(/\-\-+/g,'-');if('input'==tag||'textarea'==tag||'select'==tag)
    2727elt.val(value);else elt.text(value)}})(jQuery)
    28 jQuery(function($){window.lwsDate={isLeapYear:function(year){return(((year%4===0)&&(year%100!==0))||(year%400===0))},getMonthLength:function(monthIndex,year){if(1==monthIndex&&this.isLeapYear(year))return 29;return[31,28,31,30,31,30,31,31,30,31,30,31][monthIndex]},isLastDayOfMonth:function(date){return date.getDate()==this.getMonthLength(date.getMonth(),date.getFullYear())},addMonth:function(date,add,stayAtLast){let d=date.getDate(),m=date.getMonth(),y=date.getFullYear();let n=m+add;if(add>=0)y+=Math.floor(n/12);else y-=Math.ceil(-n/12);m=(n%12);if(m<0)m+=12;if(undefined!==stayAtLast&&stayAtLast&&this.isLastDayOfMonth(date)){d=this.getMonthLength(m,y)}else{d=Math.min(d,this.getMonthLength(m,y))}
    29 let r=new Date();r.setFullYear(y);r.setMonth(m);r.setDate(d);return r},toString:function(date){return date?date.toISOString().split('T')[0]:''},fromString:function(str){if(!str.length)return!1;let d=Date.parse(str);return isNaN(d)?!1:new Date(d)}}})
     28jQuery(function($){window.lwsDate=(function(){let self={isLeapYear:function(year){return(((year%4===0)&&(year%100!==0))||(year%400===0))},getMonthLength:function(monthIndex,year){if(1===monthIndex&&this.isLeapYear(year))return 29;return[31,28,31,30,31,30,31,31,30,31,30,31][monthIndex]},isLastDayOfMonth:function(date){return date.getDate()===this.getMonthLength(date.getMonth(),date.getFullYear())},addMonth:function(date,add,stayAtLast){let d=date.getDate(),m=date.getMonth(),y=date.getFullYear();let n=m+add;if(add>=0)y+=Math.floor(n/12);else y-=Math.ceil(-n/12);m=(n%12);if(m<0)m+=12;if(undefined!==stayAtLast&&stayAtLast&&this.isLastDayOfMonth(date)){d=this.getMonthLength(m,y)}else{d=Math.min(d,this.getMonthLength(m,y))}
     29let r=new Date();r.setFullYear(y);r.setMonth(m);r.setDate(d);return r},toString:function(date){return date?date.toISOString().split('T')[0]:''},fromString:function(str){if(!str.length)return!1;let d=Date.parse(str);return isNaN(d)?!1:new Date(d)}};return self})();(function(nav){window.lwsIsMobileDevice=(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(nav)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(nav.substr(0,4))?"yes":"no")})(navigator.userAgent||navigator.vendor||window.opera)})
  • woorewards/trunk/assets/lws-adminpanel/lws-adminpanel.php

    r3253331 r3264323  
    66 * Author: Long Watch Studio
    77 * Author URI: https://longwatchstudio.com
    8  * Version: 5.5.19
     8 * Version: 5.6.1.1
    99 * Text Domain: lws-adminpanel
    1010 *
     
    5858
    5959add_filter('lws_adminpanel_versions', function($versions){
    60     $versions['5.5.19'] = __FILE__;
     60    $versions['5.6.1.1'] = __FILE__;
    6161    return $versions;
    6262});
  • woorewards/trunk/include/abstracts/unlockable.php

    r3188612 r3264323  
    5050        if ($reward !== false) {
    5151            $this->incrRedeemCount($user->ID);
     52            \do_action('lws_woorewards_reward_created', $reward, $this, $user);
    5253            if ($this->isEmailEnabled())
    5354                $this->sendMail($user, $reward, $mailTemplate);
  • woorewards/trunk/readme.txt

    r3253331 r3264323  
    55Tested up to: 6.7
    66Requires PHP: 7.0.0
    7 Stable tag: 5.4.10
     7Stable tag: 5.4.11
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    110110== Changelog ==
    111111
     112= 5.4.11 =
     113* Dev - new hook
     114* MyRewards Pro :
     115    * Fix - Free product duplicated without discount on order again
     116    * Update - Facebook share URL for mobile
     117    * Feature - Show generated coupon code in reward popup
     118
    112119= 5.4.10 =
    113120* Fix - language loading path
  • woorewards/trunk/woorewards.php

    r3253331 r3264323  
    77 * Author: Long Watch Studio
    88 * Author URI: https://longwatchstudio.com
    9  * Version: 5.4.10
     9 * Version: 5.4.11
    1010 * License: Copyright LongWatchStudio 2022
    1111 * Text Domain: woorewards-lite
     
    111111    private function defineConstants()
    112112    {
    113         define('LWS_WOOREWARDS_VERSION', '5.4.10');
     113        define('LWS_WOOREWARDS_VERSION', '5.4.11');
    114114        define('LWS_WOOREWARDS_FILE', __FILE__);
    115115        define('LWS_WOOREWARDS_DOMAIN', 'woorewards-lite');
     
    149149    public function addPluginVersion($url)
    150150    {
    151         return '5.4.10';
     151        return '5.4.11';
    152152    }
    153153
Note: See TracChangeset for help on using the changeset viewer.