WYSIJA_help_licence

Class managing the admin vital part to integrate wordpress.

Defined (1)

The class is defined in the following location(s).

/helpers/licence.php  
  1. class WYSIJA_help_licence extends WYSIJA_help{ 
  2.  
  3. function __construct() { 
  4. parent::__construct(); 
  5.  
  6. /** 
  7. * @param string $source 
  8. * @return string 
  9. */ 
  10. function get_url_checkout($source = 'not_specified', $campaign = 'wpadmin') { 
  11. $helper_toolbox = WYSIJA::get('toolbox' , 'helper'); 
  12. $currency = 'USD'; 
  13. if($helper_toolbox->is_european()) { 
  14. $currency = 'EUR'; 
  15. return 'http://www.mailpoet.com/checkout/?wysijadomain='.$this->getDomainInfo(true).'&nc=1&utm_medium=plugin&utm_campaign='.$campaign.'&utm_source='.$source.'¤cy='.$currency; 
  16.  
  17. /** 
  18. * @param boolean $checkout_data 
  19. * @return string 
  20. */ 
  21. function getDomainInfo($checkout_data = false) { 
  22. $domain_data = array(); 
  23.  
  24. $url = admin_url('admin.php'); 
  25.  
  26. $helper_toolbox = WYSIJA::get('toolbox', 'helper'); 
  27. $domain_data['domain_name'] = $helper_toolbox->_make_domain_name($url); 
  28.  
  29. if(is_multisite()) { 
  30. $domain_data['multisite_domain'] = $helper_toolbox->_make_domain_name(network_site_url()); 
  31. $domain_data['url'] = $url; 
  32. $domain_data['cron_url'] = site_url( 'wp-cron.php').'?'.WYSIJA_CRON.'&action=wysija_cron&process=all&silent=1'; 
  33.  
  34. if($checkout_data) { 
  35. $model_config = WYSIJA::get('config' , 'model'); 
  36. if(!$model_config->getValue('poll_origin')) { 
  37. $domain_data['poll_origin'] = 'unidentified'; 
  38. }else{ 
  39. $domain_data['poll_origin'] = $model_config->getValue('poll_origin'); 
  40. $domain_data['poll_origin_url'] = $model_config->getValue('poll_origin_url'); 
  41.  
  42. $domain_data['installed_time'] = $model_config->getValue('installed_time'); 
  43.  
  44.  
  45. return base64_encode(serialize($domain_data)); 
  46.  
  47. function check($js = false) { 
  48.  
  49. $domain_data = $this->getDomainInfo(); 
  50.  
  51. if($js === false) { 
  52. WYSIJA::update_option('wysijey', $domain_data); 
  53.  
  54. $response=array(); 
  55. $response['domain_name'] = $domain_data; 
  56. $response['nocontact'] = false; 
  57.  
  58. $model_config=WYSIJA::get('config', 'model'); 
  59. if($model_config->getValue('nocurl')) { 
  60. $json_result=false; 
  61. }else{ 
  62. $helper_http = WYSIJA::get('http', 'helper'); 
  63. $json_result = $helper_http->wp_request('http://www.mailpoet.com/?wysijap=checkout&wysijashop-page=1&controller=customer&action=checkDomain&data='.urlencode($domain_data)); 
  64.  
  65. if($json_result!==false) { 
  66. $decoded = json_decode($json_result, true); 
  67.  
  68. if(isset($decoded['result']) === false) { 
  69. // service unavailable 
  70. $response['nocontact'] = true; 
  71. // make sure to re check later 
  72. WYSIJA::update_option('wysicheck', true); 
  73. } else { 
  74. // set result 
  75. $response['result'] = $decoded['result']; 
  76.  
  77. if($decoded['result'] === true) { 
  78. // set premium key 
  79. $config_data = array( 
  80. 'premium_key' => base64_encode(get_option('home').time()),  
  81. 'premium_val' => time(),  
  82. 'premium_expire_at' => (int) $decoded['expire_at'] 
  83. ); 
  84.  
  85. // success message 
  86. $this->notice(__('Premium version is valid for your site.', WYSIJA)); 
  87.  
  88. // stop checking premium 
  89. WYSIJA::update_option('wysicheck', false); 
  90. } else { 
  91. // set error 
  92.  
  93. if(isset($decoded['error'])) { 
  94. $response['code'] = $decoded['code']; 
  95. switch($response['code']) { 
  96. case 1: //Domain \'%1$s\' does not exist. 
  97. //$error_msg=__('\'%1$s\' does not exist!', WYSIJA); 
  98.  
  99. $error_msg=__('Your website doesn\'t seem to have a license! Log into your [link]account manager[/link] to add a license for this website.', WYSIJA); 
  100. break; 
  101. case 2: //'Licence (id: %d) does not exist for domain "%s" 
  102. $error_msg=__('There\'s no license for "%1$s". If you\'re Premium, add this domain in your [link]account manager[/link].', WYSIJA); 
  103. break; 
  104. case 3: //Licence has expired 
  105.  
  106. $renew_url = 'http://www.mailpoet.com/checkout/?utm_medium=plugin&utm_campaign=renewal_deal&utm_source=renewal_deal_'; 
  107. $link_renew = '<a href="'.$renew_url.'has_expired'.'" target="_blank" >'.__('Renew now.', WYSIJA).'</a>'; 
  108. $error_msg=__('Your Premium licence has expired.', WYSIJA). ' ' . $link_renew; 
  109.  
  110. break; 
  111. case 4: //You need to manually add this domain to your [link]account manager[/link] 
  112. $error_msg=__('You can add this domain to your [link]account manager[/link].', WYSIJA); 
  113. break; 
  114. case 5: //Your licence does not allow more domains, please upgrade your licence in your [link]account manager[/link] 
  115. $error_msg=__('Your licence doesn\'t allow more domains. Upgrade from your [link]account manager[/link].', WYSIJA); 
  116. break; 
  117. default: 
  118. $error_msg=$decoded['error']; 
  119. $this->error(str_replace( 
  120. array('[link]', '[/link]', '%1$s'),  
  121. array('<a href="http://www.mailpoet.com/account/licences/" target="_blank">', '</a>', $decoded['domain']),  
  122. $error_msg), true); 
  123.  
  124. // reset premium key data 
  125. $config_data = array('premium_key' => '', 'premium_val' => ''); 
  126.  
  127. WYSIJA::update_option('wysicheck', false); 
  128.  
  129. // update config 
  130. $model_config = WYSIJA::get('config', 'model'); 
  131. $model_config->save($config_data); 
  132. }else{ 
  133. $response['nocontact']=true; 
  134. WYSIJA::update_option('wysicheck', true); 
  135.  
  136. return $response; 
  137.  
  138.  
  139. function dkim_config() { 
  140.  
  141.  
  142. //checkif the open ssl function for priv and ub key are present on that server 
  143. $helper_toolbox = WYSIJA::get('toolbox', 'helper'); 
  144. $dkim_domain = $helper_toolbox->_make_domain_name(admin_url('admin.php')); 
  145. $res1=$errorssl=false; 
  146. if(function_exists('openssl_pkey_new')) { 
  147. while ($err = openssl_error_string()); 
  148. $res1=openssl_pkey_new(array('private_key_bits' => 1024)); 
  149. $errorssl=openssl_error_string(); 
  150.  
  151. if(function_exists('openssl_pkey_new') && $res1 && !$errorssl && function_exists('openssl_pkey_get_details')) { 
  152.  
  153. $rsaKey = array('private' => '', 'public' => '', 'error' => ''); 
  154. $res = openssl_pkey_new(array('private_key_bits' => 1024)); 
  155.  
  156. if($res && !openssl_error_string()) { 
  157. // Get private key 
  158. $privkey = ''; 
  159. openssl_pkey_export($res, $privkey); 
  160.  
  161. // Get public key 
  162. $pubkey = openssl_pkey_get_details($res); 
  163.  
  164.  
  165. $configData=array('dkim_domain'=>$dkim_domain, 'dkim_privk'=>$privkey, 'dkim_pubk'=>$pubkey['key'], 'dkim_1024'=>1); 
  166.  
  167. $mConfig = WYSIJA::get('config', 'model'); 
  168. $mConfig->save($configData); 
  169.  
  170. }else{//fetch them through a request to mailpoet.com 
  171. $domainData=$this->getDomainInfo(); 
  172. $hHTTP = WYSIJA::get('http', 'helper'); 
  173.  
  174. $jsonResult = $hHTTP->wp_request('http://www.mailpoet.com/?wysijap=checkout&wysijashop-page=1&controller=customer&action=checkDkimNew&data='.$domainData); 
  175.  
  176. //remotely connect to host 
  177. if($jsonResult!==false) { 
  178. $decoded=json_decode($jsonResult); 
  179.  
  180. $configData=array('dkim_domain'=>$dkim_domain, 'dkim_privk'=>$decoded->dkim_privk, 'dkim_pubk'=>$decoded->dkim_pubk->key, 'dkim_1024'=>1); 
  181.  
  182. $mConfig = WYSIJA::get('config', 'model'); 
  183. $mConfig->save($configData); 
  184. WYSIJA::update_option('dkim_autosetup', false); 
  185.  
  186. }else{ 
  187. WYSIJA::update_option('dkim_autosetup', true); 
  188.  
  189.  
  190.