/freemius/includes/class-fs-security.php

  1. <?php 
  2. /** 
  3. * @package Freemius 
  4. * @copyright Copyright (c) 2015, Freemius, Inc. 
  5. * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License 
  6. * @since 1.0.3 
  7. */ 
  8.  
  9. if ( ! defined( 'ABSPATH' ) ) { 
  10. exit; 
  11.  
  12. define( 'WP_FS__SECURITY_PARAMS_PREFIX', 's_' ); 
  13.  
  14. class FS_Security { 
  15. /** 
  16. * @var FS_Security 
  17. * @since 1.0.3 
  18. */ 
  19. private static $_instance; 
  20. /** 
  21. * @var FS_Logger 
  22. * @since 1.0.3 
  23. */ 
  24. private static $_logger; 
  25.  
  26. public static function instance() { 
  27. if ( ! isset( self::$_instance ) ) { 
  28. self::$_instance = new FS_Security(); 
  29. self::$_logger = FS_Logger::get_logger( 
  30. WP_FS__SLUG,  
  31. WP_FS__DEBUG_SDK,  
  32. WP_FS__ECHO_DEBUG_SDK 
  33. ); 
  34.  
  35. return self::$_instance; 
  36.  
  37. private function __construct() { 
  38.  
  39. /** 
  40. * @param \FS_Scope_Entity $entity 
  41. * @param int $timestamp 
  42. * @param string $action 
  43. * 
  44. * @return string 
  45. */ 
  46. function get_secure_token( FS_Scope_Entity $entity, $timestamp, $action = '' ) { 
  47. return md5( 
  48. $timestamp . 
  49. $entity->id . 
  50. $entity->secret_key . 
  51. $entity->public_key . 
  52. $action 
  53. ); 
  54.  
  55. /** 
  56. * @param \FS_Scope_Entity $entity 
  57. * @param int|bool $timestamp 
  58. * @param string $action 
  59. * 
  60. * @return array 
  61. */ 
  62. function get_context_params( FS_Scope_Entity $entity, $timestamp = false, $action = '' ) { 
  63. if ( false === $timestamp ) { 
  64. $timestamp = time(); 
  65.  
  66. return array( 
  67. 's_ctx_type' => $entity->get_type(),  
  68. 's_ctx_id' => $entity->id,  
  69. 's_ctx_ts' => $timestamp,  
  70. 's_ctx_secure' => $this->get_secure_token( $entity, $timestamp, $action ),  
  71. ); 
.