@@ -239,15 +239,15 @@ function rexshop_payment_page()
239239 'uid ' => (int ) $ mybb ->user ['uid ' ],
240240 ]));
241241
242- $ enddate = (int ) (TIME_NOW + rexshop_remaining_seconds (intval ($ mybb ->user ['uid ' ]), false ));
242+ $ enddate = (int ) (TIME_NOW + rexshop_remaining_seconds (intval ($ mybb ->user ['uid ' ]), null , false ));
243243
244244 if ($ enddate > TIME_NOW ) {
245245 $ offsetquery = $ db ->simple_select ("users " , "timezone " , "uid=' " . intval ($ mybb ->user ['uid ' ]) . "' " );
246246 $ offset = (int ) $ db ->fetch_field ($ offsetquery , "timezone " );
247247 $ enddate += (3600 * $ offset );
248248
249249 $ contents .= "Your subscription expires: " . date ('j, M Y H:m ' , $ enddate ) . " GMT " . (strpos ($ offset , '- ' ) !== false ? $ offset : "+ {$ offset }" ) . "<br><br> " ;
250- } else if ($ enddate <= -1 ) {
250+ } elseif ($ enddate <= -1 ) {
251251 $ contents .= "Your subscription will never expire " ;
252252 }
253253
@@ -367,12 +367,14 @@ function handleCompletedTransaction($request)
367367 }
368368
369369 //How much seconds the user has remaining & expire old purchases.
370- $ remainingSeconds = rexshop_remaining_seconds ($ userId );
370+ $ remainingSeconds = rexshop_remaining_seconds ($ userId, $ request [ ' order ' ][ ' products ' ][ 0 ][ ' sku ' ] );
371371
372372 //Figure out how much seconds the user has purchased.
373373 $ purchasedSeconds = rexshop_purchased_seconds ($ request , $ request ['order ' ]['products ' ][0 ]['sku ' ]);
374374
375- $ newEnddate = $ purchasedSeconds < 0 ? -1 : TIME_NOW + $ remainingSeconds + $ purchasedSeconds ;
375+ $ newEnddate = $ purchasedSeconds < 0
376+ ? -1
377+ : TIME_NOW + $ remainingSeconds + $ purchasedSeconds ;
376378
377379 rexshop_store_transaction ($ request , $ userId , $ newEnddate , $ request ['order ' ]['products ' ][0 ]['sku ' ]);
378380
@@ -445,7 +447,7 @@ function handleRefundedTransaction($request)
445447 $ refundedSeconds = $ refundedAmount * $ pricePerSecond ;
446448
447449 //Check how much time the user has left
448- $ remainingSeconds = rexshop_remaining_seconds ($ userId , false );
450+ $ remainingSeconds = rexshop_remaining_seconds ($ userId , $ request [ ' order ' ][ ' products ' ][ 0 ][ ' sku ' ], false );
449451
450452 //Subtract the time that was refunded.
451453 $ newEndDate = TIME_NOW + ($ remainingSeconds - $ refundedSeconds );
@@ -570,11 +572,11 @@ function handleDisputedTransaction($request)
570572 return rexshop_on_failure ();
571573 }
572574
573- //Figure out how much time to suspend
575+ //Figure out how much time to suspend
574576 $ secondsToSuspend = rexshop_purchased_seconds ($ request , $ usergroup );
575577
576578 //Figure out how much time the user has left.
577- $ remainingSeconds = rexshop_remaining_seconds ($ userId , false );
579+ $ remainingSeconds = rexshop_remaining_seconds ($ userId , null , false );
578580
579581 $ completed = REXSHOP_STATUS_COMPLETED ;
580582
@@ -683,7 +685,7 @@ function rexshop_products_usergroup($product)
683685 break 2 ;
684686 }
685687 }
686- } else if (isset ($ product ['addons ' ])) {
688+ } elseif (isset ($ product ['addons ' ])) {
687689 foreach ($ product ['addons ' ] as $ addon ) {
688690 if (strtolower ($ addon ['name ' ]) !== 'usergroup ' ) {
689691 continue ;
@@ -715,13 +717,18 @@ function rexshop_products_usergroup($product)
715717 * @param boolean $expiresExisting
716718 * @return integer
717719 */
718- function rexshop_remaining_seconds ($ userId , $ expireExisting = true )
720+ function rexshop_remaining_seconds ($ userId , $ sku = null , $ expireExisting = true )
719721{
720722 global $ db ;
721723
722724 $ remainingSeconds = 0 ;
723725
724- $ query = $ db ->query ("SELECT * FROM ` " . TABLE_PREFIX . "rexshop_logs` WHERE `uid`=' " . (int ) $ userId . "' AND `expired`='0' " );
726+ $ queryString = "SELECT * FROM ` " . TABLE_PREFIX . "rexshop_logs` WHERE `uid`=' " . (int ) $ userId . "' AND `expired`='0' " ;
727+ if (isset ($ sku )) {
728+ $ queryString .= " AND `product_sku`=' " . rexshop_regex_escape ($ sku , '/[^a-zA-Z0-9]/ ' ) . "' " ;
729+ }
730+
731+ $ query = $ db ->query ($ queryString );
725732 $ resultCount = $ db ->num_rows ($ query );
726733 if ($ resultCount <= 0 ) {
727734 return $ remainingSeconds ;
@@ -1231,7 +1238,7 @@ function rexshop_fetch_products($acp = false)
12311238 $ usergroups = explode (', ' , ltrim (rtrim (trim ($ addon ['value ' ], ' ' ), ', ' ), ', ' ));
12321239 if (empty ($ usergroups )) {
12331240 continue ;
1234- }
1241+ }
12351242
12361243 $ usergroupIds = [];
12371244 foreach ($ usergroups as $ usergroup ) {
@@ -1250,7 +1257,7 @@ function rexshop_fetch_products($acp = false)
12501257 if (! in_array ((int ) $ mybb ->user ['usergroup ' ], $ usergroupIds )) {
12511258 continue 2 ;
12521259 }
1253- } else if (mb_strtolower ($ addon ['name ' ]) === 'excludeusergroups ' || mb_strtolower ($ addon ['name ' ]) === 'excludeusergroup ' ) {
1260+ } elseif (mb_strtolower ($ addon ['name ' ]) === 'excludeusergroups ' || mb_strtolower ($ addon ['name ' ]) === 'excludeusergroup ' ) {
12541261 if (in_array ((int ) $ mybb ->user ['usergroup ' ], $ usergroupIds )) {
12551262 continue 2 ;
12561263 }
0 commit comments