addon-admin.class.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <?php
  2. /**
  3. * The admin-specific functionality of the plugin.
  4. *
  5. * @link h
  6. * @since 1.0.0
  7. *
  8. * @package Rev_addon
  9. * @subpackage Rev_addon/admin
  10. */
  11. /**
  12. * The admin-specific functionality of the plugin.
  13. *
  14. * Defines the plugin name, version, and two examples hooks for how to
  15. * enqueue the admin-specific stylesheet and JavaScript.
  16. *
  17. * @package Rev_addon
  18. * @subpackage Rev_addon/admin
  19. * @author ThemePunch <info@themepunch.com>
  20. */
  21. class Rev_addon_Admin {
  22. /**
  23. * The ID of this plugin.
  24. *
  25. * @since 1.0.0
  26. * @access private
  27. * @var string $plugin_name The ID of this plugin.
  28. */
  29. private $plugin_name;
  30. /**
  31. * The version of this plugin.
  32. *
  33. * @since 1.0.0
  34. * @access private
  35. * @var string $version The current version of this plugin.
  36. */
  37. private $version;
  38. /**
  39. * Initialize the class and set its properties.
  40. *
  41. * @since 1.0.0
  42. * @param string $plugin_name The name of this plugin.
  43. * @param string $version The version of this plugin.
  44. */
  45. public function __construct( $plugin_name, $version ) {
  46. $this->plugin_name = $plugin_name;
  47. $this->version = $version;
  48. }
  49. /**
  50. * Register the stylesheets for the admin area.
  51. *
  52. * @since 1.0.0
  53. */
  54. public function enqueue_styles() {
  55. /**
  56. * This function is provided for demonstration purposes only.
  57. *
  58. * An instance of this class should be passed to the run() function
  59. * defined in Rev_addon_Loader as all of the hooks are defined
  60. * in that particular class.
  61. *
  62. * The Rev_addon_Loader will then create the relationship
  63. * between the defined hooks and the functions defined in this
  64. * class.
  65. */
  66. if(isset($_GET["page"]) && $_GET["page"]=="rev_addon"){
  67. wp_enqueue_style('rs-plugin-settings', RS_PLUGIN_URL .'admin/assets/css/admin.css', array(), RevSliderGlobals::SLIDER_REVISION);
  68. wp_enqueue_style( $this->plugin_name, RS_PLUGIN_URL . 'admin/assets/css/rev_addon-admin.css', array( ), $this->version);
  69. }
  70. }
  71. /**
  72. * Register the JavaScript for the admin area.
  73. *
  74. * @since 1.0.0
  75. */
  76. public function enqueue_scripts() {
  77. /**
  78. * This function is provided for demonstration purposes only.
  79. *
  80. * An instance of this class should be passed to the run() function
  81. * defined in Rev_addon_Loader as all of the hooks are defined
  82. * in that particular class.
  83. *
  84. * The Rev_addon_Loader will then create the relationship
  85. * between the defined hooks and the functions defined in this
  86. * class.
  87. */
  88. if(isset($_GET["page"]) && $_GET["page"]=="rev_addon"){
  89. wp_enqueue_script('tp-tools', RS_PLUGIN_URL .'public/assets/js/jquery.themepunch.tools.min.js', array(), RevSliderGlobals::SLIDER_REVISION );
  90. wp_enqueue_script('unite_admin', RS_PLUGIN_URL .'admin/assets/js/admin.js', array(), RevSliderGlobals::SLIDER_REVISION );
  91. wp_enqueue_script( $this->plugin_name, RS_PLUGIN_URL .'admin/assets/js/rev_addon-admin.js', array( 'jquery' ), $this->version, false );
  92. wp_localize_script( $this->plugin_name, 'rev_slider_addon', array(
  93. 'ajax_url' => admin_url( 'admin-ajax.php' ),
  94. 'please_wait_a_moment' => __("Please Wait a Moment",'revslider'),
  95. 'settings_saved' => __("Settings saved",'revslider')
  96. ));
  97. }
  98. }
  99. /**
  100. * Register the administration menu for this plugin into the WordPress Dashboard menu.
  101. *
  102. * @since 1.0.0
  103. */
  104. public function add_plugin_admin_menu() {
  105. $this->plugin_screen_hook_suffix = add_submenu_page(
  106. 'revslider',
  107. __( 'Add-Ons', 'revslider' ),
  108. __( 'Add-Ons', 'revslider' ),
  109. 'manage_options',
  110. $this->plugin_name,
  111. array( $this, 'display_plugin_admin_page' )
  112. );
  113. }
  114. /**
  115. * Render the settings page for this plugin.
  116. *
  117. * @since 1.0.0
  118. */
  119. public function display_plugin_admin_page() {
  120. include_once( RS_PLUGIN_PATH.'admin/views/rev_addon-admin-display.php' );
  121. }
  122. /**
  123. * Activates Installed Add-On/Plugin
  124. *
  125. * @since 1.0.0
  126. */
  127. public function activate_plugin() {
  128. // Verify that the incoming request is coming with the security nonce
  129. if( wp_verify_nonce( $_REQUEST['nonce'], 'ajax_rev_slider_addon_nonce' ) ) {
  130. if(isset($_REQUEST['plugin'])){
  131. //update_option( "rev_slider_addon_gal_default", sanitize_text_field($_REQUEST['default_gallery']) );
  132. $result = activate_plugin( $_REQUEST['plugin'] );
  133. if ( is_wp_error( $result ) ) {
  134. // Process Error
  135. die('0');
  136. }
  137. die( '1' );
  138. }
  139. else{
  140. die( '0' );
  141. }
  142. }
  143. else {
  144. die( '-1' );
  145. }
  146. }
  147. /**
  148. * Deactivates Installed Add-On/Plugin
  149. *
  150. * @since 1.0.0
  151. */
  152. public function deactivate_plugin() {
  153. // Verify that the incoming request is coming with the security nonce
  154. if( wp_verify_nonce( $_REQUEST['nonce'], 'ajax_rev_slider_addon_nonce' ) ) {
  155. if(isset($_REQUEST['plugin'])){
  156. //update_option( "rev_slider_addon_gal_default", sanitize_text_field($_REQUEST['default_gallery']) );
  157. $result = deactivate_plugins( $_REQUEST['plugin'] );
  158. if ( is_wp_error( $result ) ) {
  159. // Process Error
  160. die('0');
  161. }
  162. die( '1' );
  163. }
  164. else{
  165. die( '0' );
  166. }
  167. }
  168. else {
  169. die( '-1' );
  170. }
  171. }
  172. /**
  173. * Install Add-On/Plugin
  174. *
  175. * @since 1.0.0
  176. */
  177. public function install_plugin() {
  178. if( wp_verify_nonce( $_REQUEST['nonce'], 'ajax_rev_slider_addon_nonce' ) ) {
  179. if(isset($_REQUEST['plugin'])){
  180. global $wp_version, $rslb;
  181. $plugin_slug = basename($_REQUEST['plugin']);
  182. $plugin_result = false;
  183. $plugin_message = 'UNKNOWN';
  184. if(0 !== strpos($plugin_slug, 'revslider-')) die( '-1' );
  185. $done = false;
  186. $count = 0;
  187. do{
  188. $url = $rslb->get_url('updates');
  189. $url .= '/addons/'.$plugin_slug.'/'.$plugin_slug.'.zip';
  190. $get = wp_remote_post($url, array(
  191. 'user-agent' => 'WordPress/'.$wp_version.'; '.get_bloginfo('url'),
  192. 'body' => '',
  193. 'timeout' => 45
  194. ));
  195. $response_code = wp_remote_retrieve_response_code( $get );
  196. if($response_code == 200){
  197. $done = true;
  198. }else{
  199. $rslb->move_server_list();
  200. }
  201. $count++;
  202. }while($done == false && $count < 5);
  203. if( !$get || $get["response"]["code"] != "200" ){
  204. $plugin_message = 'FAILED TO DOWNLOAD';
  205. }else{
  206. $plugin_message = 'ZIP is there';
  207. $upload_dir = wp_upload_dir();
  208. $file = $upload_dir['basedir']. '/revslider/templates/' . $plugin_slug . '.zip';
  209. @mkdir(dirname($file));
  210. $ret = @file_put_contents( $file, $get['body'] );
  211. WP_Filesystem();
  212. global $wp_filesystem;
  213. $upload_dir = wp_upload_dir();
  214. $d_path = WP_PLUGIN_DIR;
  215. $unzipfile = unzip_file( $file, $d_path);
  216. if( is_wp_error($unzipfile) ){
  217. define('FS_METHOD', 'direct'); //lets try direct.
  218. WP_Filesystem(); //WP_Filesystem() needs to be called again since now we use direct !
  219. //@chmod($file, 0775);
  220. $unzipfile = unzip_file( $file, $d_path);
  221. if( is_wp_error($unzipfile) ){
  222. $d_path = WP_PLUGIN_DIR;
  223. $unzipfile = unzip_file( $file, $d_path);
  224. if( is_wp_error($unzipfile) ){
  225. $f = basename($file);
  226. $d_path = str_replace($f, '', $file);
  227. $unzipfile = unzip_file( $file, $d_path);
  228. }
  229. }
  230. }
  231. @unlink($file);
  232. die('1');
  233. }
  234. //$result = activate_plugin( $plugin_slug.'/'.$plugin_slug.'.php' );
  235. }
  236. else{
  237. die( '0' );
  238. }
  239. }
  240. else {
  241. die( '-1' );
  242. }
  243. }
  244. } // END of class