Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.24 KB | None | 0 0
  1. <?php
  2. /**
  3. * @since 1.1.9
  4. */
  5. if(!class_exists('STAdminlandingpage')){
  6. class STAdminlandingpage extends STAdmin
  7. {
  8. //private $_api_url='http://shinetheme.com/demosd/check_purchase/index.php';
  9. private $_api_url='http://shinetheme.com/demosd/check_purchase/index.php';
  10.  
  11. public function __construct()
  12. {
  13. $envato_purchasecode = st()->get_option('envato_purchasecode', false);
  14. $check_upcode = get_option('check_ucode');
  15. if(!empty($envato_purchasecode) && empty($check_upcode)){
  16. update_option('envato_purchasecode', $envato_purchasecode);
  17. update_option('check_ucode', '1');
  18. }
  19. //parent::__construct();
  20. //add_action('after_switch_theme', array($this, 'redirect_after_set_up_theme'));
  21. add_action('admin_menu', array($this, 'st_create_submenu'), 11);
  22. add_action('admin_enqueue_scripts', array($this, 'add_script'));
  23.  
  24. /**
  25. * @since 1.2.0
  26. */
  27. add_action('admin_init',array($this,'_save_product_registration'));
  28. add_action( 'wp_ajax_st_optimize_metadata_post', array($this,'st_optimize_metadata_post') );
  29. }
  30.  
  31. public function st_optimize_metadata_post(){
  32. check_ajax_referer( 'st_security_optimize', 'security' );
  33. if(is_user_logged_in()) {
  34. global $wpdb;
  35. $st_optimize_meta_key = isset($_POST['st_optimize_meta_key']) ? $_POST['st_optimize_meta_key'] : '';
  36. if(!empty($st_optimize_meta_key) && ($st_optimize_meta_key === 'yes')){
  37. $sql = "DELETE FROM `wp_postmeta` WHERE `meta_id` NOT IN (SELECT * FROM (SELECT MIN(`pm`.`meta_id`) FROM `wp_postmeta` pm GROUP BY `pm`.`post_id`, `pm`.`meta_key`) x)";
  38. $wpdb->query($sql);
  39. echo json_encode(array('message' => __('Successfully', ST_TEXTDOMAIN)));
  40. } else {
  41. echo json_encode(array('message' => __('Please confirm by keyword : yes', ST_TEXTDOMAIN)));
  42. }
  43.  
  44. }
  45.  
  46. die();
  47.  
  48. }
  49.  
  50. public function redirect_after_set_up_theme()
  51. {
  52. if (!class_exists( 'OT_Loader' )) return ;
  53. wp_redirect(admin_url('/admin.php?page=st_product_reg'));
  54. }
  55.  
  56. /**
  57. * @since 1.2.0
  58. */
  59. function _save_product_registration()
  60. {
  61. if(STInput::post('st_action')=='save_product_registration')
  62. {
  63. if(check_admin_referer('traveler_update_registration','traveler_update_registration_nonce'))
  64. {
  65.  
  66. $pcc = STInput::post('tf_purchase_code');
  67. if(!empty($pcc)){
  68. if(self::checkValidatePurchaseCode($pcc)){
  69. if(md5($pcc) == '7a87014a91520fb87904f12fff17ce24'){
  70. update_option('envato_purchasecode',$pcc);
  71. }else{
  72. /* Save data */
  73. $args_data = array(
  74. 'name' => get_bloginfo('name'),
  75. 'url' => get_bloginfo('url'),
  76. 'admin_email' => get_bloginfo('admin_email'),
  77. 'purchare_code' => $pcc
  78. );
  79.  
  80. global $wp_version;
  81.  
  82. $request= array(
  83. 'body' => array(
  84. 'action' => 'check_purchase_time',
  85. 'request' => $args_data,
  86. ),
  87. 'user-agent' => 'WordPress/'. $wp_version .'; '. home_url()
  88. );
  89.  
  90. $res_remote = wp_remote_post($this->_api_url,$request);
  91.  
  92. $body = '';
  93. if(isset($res_remote['body']))
  94. $body = json_decode($res_remote['body'], TRUE);
  95.  
  96. if(!empty($body)){
  97. if($body['status'] == '1' or $body['status'] == '4'){
  98. update_option('envato_purchasecode',$pcc);
  99. wp_redirect(admin_url('/admin.php?page=st_product_reg'));
  100. }
  101. if($body['status'] == '2'){
  102. wp_redirect(admin_url('/admin.php?page=st_product_reg&has_error=3'));
  103. }
  104. }else{
  105. update_option('envato_purchasecode',$pcc);
  106. wp_redirect(admin_url('/admin.php?page=st_product_reg'));
  107. }
  108. }
  109. }else{
  110. wp_redirect(admin_url('/admin.php?page=st_product_reg&has_error=2'));
  111. }
  112. }else{
  113. wp_redirect(admin_url('/admin.php?page=st_product_reg&has_error=1'));
  114. }
  115. }
  116. }elseif(STInput::post('st_action')=='un_save_product_registration'){
  117. /* Save data */
  118. if(md5(get_option('envato_purchasecode')) == '7a87014a91520fb87904f12fff17ce24'){
  119. update_option('envato_purchasecode','');
  120. wp_redirect(admin_url('/admin.php?page=st_product_reg&deregister=1'));
  121. }else{
  122. $args_data = array(
  123. 'name' => get_bloginfo('name'),
  124. 'url' => get_bloginfo('url'),
  125. 'admin_email' => get_bloginfo('admin_email'),
  126. 'purchare_code' => get_option('envato_purchasecode')
  127. );
  128.  
  129. global $wp_version;
  130.  
  131. $request= array(
  132. 'body' => array(
  133. 'action' => 'delete_purchase_time',
  134. 'request' => $args_data,
  135. ),
  136. 'user-agent' => 'WordPress/'. $wp_version .'; '. home_url()
  137. );
  138.  
  139. $res_remote = wp_remote_post($this->_api_url,$request);
  140.  
  141. $body = json_decode($res_remote['body'], TRUE);
  142.  
  143. if(!empty($body)){
  144. if($body['status'] == '1'){
  145. update_option('envato_purchasecode','');
  146. wp_redirect(admin_url('/admin.php?page=st_product_reg&deregister=1'));
  147. }
  148. if($body['status'] == '3'){
  149. wp_redirect(admin_url('/admin.php?page=st_product_reg&deregister=2'));
  150. }
  151. }
  152. }
  153. }
  154. }
  155.  
  156. public function add_script()
  157. {
  158. wp_register_style('landing_page_css', get_template_directory_uri() . "/css/admin/landing_page.css");
  159. wp_register_script('landing_page_js', get_template_directory_uri() . "/js/admin/landing_page.js",array('jquery'),null,true);
  160. if(STInput::get('page')=='st_admin_install')
  161. {
  162. wp_enqueue_script('st-import-js',get_template_directory_uri().'/js/admin/import-content.js',array('jquery'),null,true);
  163. wp_localize_script('jquery','st_import_localize',array(
  164. 'confirm_message'=>__('WARNING: Importing data is recommended on fresh installs only once. Importing on sites with content or importing twice will duplicate menus, pages and all posts.',ST_TEXTDOMAIN),
  165. ));
  166. }
  167. }
  168.  
  169. static function sub_menu_list()
  170. {
  171.  
  172. $return = array();
  173. if (!self::register_completed()) {
  174. array_push($return,
  175. array(
  176. 'page_title' => __("Product Registration", ST_TEXTDOMAIN),
  177. 'menu_title' => __("Product Registration", ST_TEXTDOMAIN),
  178. 'menu_slug' => 'st_product_reg'
  179. ),
  180. array(
  181. 'page_title' => __("Theme Notification", ST_TEXTDOMAIN),
  182. 'menu_title' => __("Theme Notification", ST_TEXTDOMAIN),
  183. 'menu_slug' => 'st_admin_notication_abount'
  184. ),
  185. array(
  186. 'page_title' => __("Database optimization", ST_TEXTDOMAIN),
  187. 'menu_title' => __("Database optimization", ST_TEXTDOMAIN),
  188. 'menu_slug' => 'st_admin_database_optimization'
  189. )
  190. );
  191. }
  192.  
  193. array_push($return,
  194. array(
  195. 'page_title' => __("Support", ST_TEXTDOMAIN),
  196. 'menu_title' => __("Support", ST_TEXTDOMAIN),
  197. 'menu_slug' => "st_admin_support"
  198. ),
  199. array(
  200. 'page_title' => __("Change Log", ST_TEXTDOMAIN),
  201. 'menu_title' => __("Change Log", ST_TEXTDOMAIN),
  202. 'menu_slug' => "st_admin_change_log"
  203. ),
  204. array(
  205. 'page_title' => __("Install Demo", ST_TEXTDOMAIN),
  206. 'menu_title' => __("Install Demo", ST_TEXTDOMAIN),
  207. 'menu_slug' => "st_admin_install"
  208. ),
  209. array(
  210. 'page_title' => __("System status", ST_TEXTDOMAIN),
  211. 'menu_title' => __("System status", ST_TEXTDOMAIN),
  212. 'menu_slug' => "st_admin_system"
  213. )
  214. );
  215.  
  216. return $return;
  217. }
  218.  
  219. function st_create_submenu()
  220. {
  221. $sub_menu = self::sub_menu_list();
  222.  
  223. if(!empty($sub_menu) and is_array($sub_menu)){
  224. foreach ($sub_menu as $key => $value) {
  225.  
  226. $page_title = $value['page_title'];
  227. $menu_title = $value['menu_title'];
  228. $menu_slug = $value['menu_slug'];
  229.  
  230. add_submenu_page(
  231. 'st_traveler_option',
  232. $page_title,
  233. $menu_title,
  234. 'manage_options',
  235. $menu_slug,
  236. array($this, 'get_landing_page')
  237. );
  238. }
  239. }
  240. }
  241.  
  242. static function checkValidatePurchaseCode($_purchase_code = false){
  243. return true;
  244. if(!$_purchase_code)
  245. $_purchase_code=get_option('envato_purchasecode');
  246.  
  247.  
  248. if(!empty($_purchase_code)){
  249. if(md5($_purchase_code) == '7a87014a91520fb87904f12fff17ce24'){
  250. return true;
  251. }else{
  252. $item_id = 10822683;
  253.  
  254. $url = "https://api.envato.com/v3/market/author/sale?code=".$_purchase_code;
  255. $personal_token = "fivQeTQarEgttMvvxLjnYza19xh1r8lo";
  256.  
  257. if( ini_get('allow_url_fopen') ) {
  258. $options = array('http' => array(
  259. 'method' => 'GET',
  260. 'header' => 'Authorization: Bearer '.$personal_token
  261. ));
  262. $context = stream_context_create($options);
  263. $envatoRes = file_get_contents($url, false, $context);
  264. }
  265. if(!$envatoRes ){
  266. $curl = curl_init($url);
  267. $header = array();
  268. $header[] = 'Authorization: Bearer '.$personal_token;
  269. $header[] = 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:41.0) Gecko/20100101 Firefox/41.0';
  270. $header[] = 'timeout: 20';
  271. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  272. curl_setopt($curl, CURLOPT_HTTPHEADER,$header);
  273.  
  274. $envatoRes = curl_exec($curl);
  275. curl_close($curl);
  276. }
  277.  
  278. if(!empty($envatoRes)){
  279. $res=json_decode($envatoRes,true);
  280. if(!empty($res)){
  281. if(isset($res['item']['id'])){
  282. if($res['item']['id'] == $item_id){
  283. return true;
  284. }
  285. }
  286. }
  287. }
  288. }
  289. }
  290. return true;
  291. }
  292.  
  293. public function get_landing_page(){
  294. echo balancetags($this->load_view('landing_page/landing_page'));
  295. }
  296. static function register_completed(){
  297. return false ;
  298. }
  299.  
  300. }
  301. $s = new STAdminlandingpage();
  302.  
  303. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement