PageRenderTime 51ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/revslider/includes/framework/update.class.php

https://gitlab.com/webkod3r/tripolis
PHP | 234 lines | 150 code | 67 blank | 17 comment | 47 complexity | 08f32ff6d5fd4cd981c5ebd7777e3020 MD5 | raw file
  1. <?php
  2. /**
  3. * @author ThemePunch <info@themepunch.com>
  4. * @link http://www.themepunch.com/
  5. * @copyright 2015 ThemePunch
  6. */
  7. if( !defined( 'ABSPATH') ) exit();
  8. class RevSliderUpdate {
  9. private $plugin_url = 'http://codecanyon.net/item/slider-revolution-responsive-wordpress-plugin/2751380';
  10. private $remote_url = 'http://updates.themepunch.tools/check_for_updates.php';
  11. private $remote_url_info = 'http://updates.themepunch.tools/revslider/revslider.php';
  12. private $plugin_slug = 'revslider';
  13. private $plugin_path = 'revslider/revslider.php';
  14. private $version;
  15. private $plugins;
  16. private $option;
  17. public function __construct($version) {
  18. $this->option = $this->plugin_slug . '_update_info';
  19. $this->_retrieve_version_info();
  20. $this->version = $version;
  21. }
  22. public function add_update_checks(){
  23. add_filter('pre_set_site_transient_update_plugins', array(&$this, 'set_update_transient'));
  24. add_filter('plugins_api', array(&$this, 'set_updates_api_results'), 10, 3);
  25. }
  26. public function set_update_transient($transient) {
  27. $this->_check_updates();
  28. if(isset($transient) && !isset($transient->response)) {
  29. $transient->response = array();
  30. }
  31. if(!empty($this->data->basic) && is_object($this->data->basic)) {
  32. if(version_compare($this->version, $this->data->basic->version, '<')) {
  33. $this->data->basic->new_version = $this->data->basic->version;
  34. $transient->response[$this->plugin_path] = $this->data->basic;
  35. }
  36. }
  37. return $transient;
  38. }
  39. public function set_updates_api_results($result, $action, $args) {
  40. $this->_check_updates();
  41. if(isset($args->slug) && $args->slug == $this->plugin_slug && $action == 'plugin_information') {
  42. if(is_object($this->data->full) && !empty($this->data->full)) {
  43. $result = $this->data->full;
  44. }
  45. }
  46. return $result;
  47. }
  48. protected function _check_updates() {
  49. //reset saved options
  50. //update_option($this->option, false);
  51. $force_check = false;
  52. if(isset($_GET['checkforupdates']) && $_GET['checkforupdates'] == 'true') $force_check = true;
  53. // Get data
  54. if(empty($this->data)) {
  55. $data = get_option($this->option, false);
  56. $data = $data ? $data : new stdClass;
  57. $this->data = is_object($data) ? $data : maybe_unserialize($data);
  58. }
  59. $last_check = get_option('revslider-update-check');
  60. if($last_check == false){ //first time called
  61. $last_check = time();
  62. update_option('revslider-update-check', $last_check);
  63. }
  64. // Check for updates
  65. if(time() - $last_check > 172800 || $force_check == true){
  66. $data = $this->_retrieve_update_info();
  67. if(isset($data->basic)) {
  68. update_option('revslider-update-check', time());
  69. $this->data->checked = time();
  70. $this->data->basic = $data->basic;
  71. $this->data->full = $data->full;
  72. update_option('revslider-stable-version', $data->full->stable);
  73. update_option('revslider-latest-version', $data->full->version);
  74. }
  75. }
  76. // Save results
  77. update_option($this->option, $this->data);
  78. }
  79. public function _retrieve_update_info() {
  80. global $wp_version;
  81. $data = new stdClass;
  82. // Build request
  83. $code = get_option('revslider-code', '');
  84. $validated = get_option('revslider-valid', 'false');
  85. $stable_version = get_option('revslider-stable-version', '4.2');
  86. $rattr = array(
  87. 'code' => urlencode($code),
  88. 'version' => urlencode(RevSliderGlobals::SLIDER_REVISION)
  89. );
  90. if($validated !== 'true' && version_compare(RevSliderGlobals::SLIDER_REVISION, $stable_version, '<')){ //We'll get the last stable only now!
  91. $rattr['get_stable'] = 'true';
  92. }
  93. $request = wp_remote_post($this->remote_url_info, array(
  94. 'user-agent' => 'WordPress/'.$wp_version.'; '.get_bloginfo('url'),
  95. 'body' => $rattr
  96. ));
  97. if(!is_wp_error($request)) {
  98. if($response = maybe_unserialize($request['body'])) {
  99. if(is_object($response)) {
  100. $data = $response;
  101. $data->basic->url = $this->plugin_url;
  102. $data->full->url = $this->plugin_url;
  103. $data->full->external = 1;
  104. }
  105. }
  106. }
  107. return $data;
  108. }
  109. public function _retrieve_version_info($force_check = false) {
  110. global $wp_version;
  111. $last_check = get_option('revslider-update-check-short');
  112. if($last_check == false){ //first time called
  113. $last_check = time();
  114. update_option('revslider-update-check-short', $last_check);
  115. }
  116. // Check for updates
  117. if(time() - $last_check > 172800 || $force_check == true){
  118. update_option('revslider-update-check-short', time());
  119. $purchase = (get_option('revslider-valid', 'false') == 'true') ? get_option('revslider-code', '') : '';
  120. $response = wp_remote_post($this->remote_url, array(
  121. 'user-agent' => 'WordPress/'.$wp_version.'; '.get_bloginfo('url'),
  122. 'body' => array(
  123. 'item' => urlencode('revslider'),
  124. 'version' => urlencode(RevSliderGlobals::SLIDER_REVISION),
  125. 'code' => urlencode($purchase)
  126. )
  127. ));
  128. $response_code = wp_remote_retrieve_response_code( $response );
  129. $version_info = wp_remote_retrieve_body( $response );
  130. if ( $response_code != 200 || is_wp_error( $version_info ) ) {
  131. update_option('revslider-connection', false);
  132. return false;
  133. }else{
  134. update_option('revslider-connection', true);
  135. }
  136. $version_info = json_decode($version_info);
  137. if(isset($version_info->version)){
  138. update_option('revslider-latest-version', $version_info->version);
  139. }
  140. if(isset($version_info->stable)){
  141. update_option('revslider-stable-version', $version_info->stable);
  142. }
  143. if(isset($version_info->notices)){
  144. update_option('revslider-notices', $version_info->notices);
  145. }
  146. if(isset($version_info->dashboard)){
  147. update_option('revslider-dashboard', $version_info->dashboard);
  148. }
  149. if(isset($version_info->deactivated) && $version_info->deactivated === true){
  150. if(get_option('revslider-valid', 'false') == 'true'){
  151. //remove validation, add notice
  152. update_option('revslider-valid', 'false');
  153. update_option('revslider-deact-notice', true);
  154. }
  155. }
  156. }
  157. if($force_check == true){ //force that the update will be directly searched
  158. update_option('revslider-update-check', '');
  159. }
  160. }
  161. }
  162. /**
  163. * old classname extends new one (old classnames will be obsolete soon)
  164. * @since: 5.0
  165. **/
  166. class UniteUpdateClassRev extends RevSliderUpdate {}
  167. ?>