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

/themify/themify-wpajax.php

https://gitlab.com/BGCX067/facilware-theme-hg-to-git
PHP | 207 lines | 141 code | 12 blank | 54 comment | 24 complexity | c61c4b649152487a4c051c05e23b45b0 MD5 | raw file
  1. <?php
  2. /**
  3. * @package themify
  4. * @since 1.1.3
  5. * @author Elio Rivero
  6. *
  7. * ----------------------------------------------------------------------
  8. * DO NOT EDIT THIS FILE
  9. * ----------------------------------------------------------------------
  10. * AJAX functions to:
  11. * Save Settings
  12. * Get Settings
  13. * Reset Settings
  14. * Reset Styling
  15. * Import / Export
  16. * Upload Images
  17. * Upload Files
  18. *
  19. * http://themify.me
  20. * Copyright (C) 2011 Themify
  21. *
  22. ***************************************************************************/
  23. /**
  24. * Save user settings
  25. * @since 1.1.3
  26. * @package themify
  27. */
  28. function themify_save(){
  29. check_ajax_referer( 'ajax-nonce', 'nonce' );
  30. $data = explode("&", $_POST['data']);
  31. $temp = array();
  32. foreach($data as $a){
  33. $v = explode("=", $a);
  34. $temp[$v[0]] = urldecode( str_replace("+"," ",preg_replace('/%([0-9a-f]{2})/ie', "chr(hexdec('\\1'))", urlencode($v[1]))) );
  35. }
  36. set_data($temp);
  37. echo 'Your settings were saved';
  38. die();
  39. }
  40. add_action('wp_ajax_themify_save', 'themify_save');
  41. /**
  42. * Reset Styling
  43. * @since 1.1.3
  44. * @package themify
  45. */
  46. function themify_reset_styling(){
  47. check_ajax_referer( 'ajax-nonce', 'nonce' );
  48. $data = explode("&", $_POST['data']);
  49. $temp_data = array();
  50. foreach($data as $a){
  51. $v = explode("=", $a);
  52. $temp_data[$v[0]] = str_replace("+"," ",preg_replace('/%([0-9a-f]{2})/ie', "chr(hexdec('\\1'))", $v[1]));
  53. }
  54. $temp = array();
  55. foreach($temp_data as $key => $val){
  56. if(strpos($key, 'styling') === false){
  57. $temp[$key] = $val;
  58. }
  59. }
  60. print_r(set_data($temp));
  61. die();
  62. }
  63. add_action('wp_ajax_themify_reset_styling', 'themify_reset_styling');
  64. /**
  65. * Reset Settings
  66. * @since 1.1.3
  67. * @package themify
  68. */
  69. function themify_reset_setting(){
  70. check_ajax_referer( 'ajax-nonce', 'nonce' );
  71. $data = explode("&", $_POST['data']);
  72. $temp_data = array();
  73. foreach($data as $a){
  74. $v = explode("=", $a);
  75. $temp_data[$v[0]] = str_replace("+"," ",preg_replace('/%([0-9a-f]{2})/ie', "chr(hexdec('\\1'))", $v[1]));
  76. }
  77. $temp = array();
  78. foreach($temp_data as $key => $val){
  79. if(strpos($key, 'setting') === false){
  80. $temp[$key] = $val;
  81. }
  82. }
  83. print_r(set_data($temp));
  84. die();
  85. }
  86. add_action('wp_ajax_themify_reset_setting', 'themify_reset_setting');
  87. /**
  88. * Export Settings to zip file and prompt to download
  89. * NOTE: This function is not called through AJAX but it is kept here for consistency.
  90. * @since 1.1.3
  91. * @package themify
  92. */
  93. function themify_export(){
  94. //Check nonce of export feature
  95. check_admin_referer( 'themify_export_nonce' );
  96. global $theme;
  97. if(class_exists('ZipArchive')){
  98. $datafile = 'data_export.txt';
  99. $handler = fopen($datafile, 'w');
  100. fwrite($handler,serialize(get_data()));
  101. fclose($handler);
  102. $files_to_zip = array(
  103. '../wp-content/themes/' . $theme['Name'] . '/custom-modules.php',
  104. '../wp-content/themes/' . $theme['Name'] . '/custom-functions.php',
  105. '../wp-content/themes/' . $theme['Name'] . '/custom-config.xml',
  106. $datafile
  107. );
  108. print_r($files_to_zip);
  109. $file = $theme['Name'].'_themify_export_'.date("Y-m-d").'.zip';
  110. $result = themify_create_zip( $files_to_zip, $file, true );
  111. if($result){
  112. if((isset($file))&&(file_exists($file))){
  113. header("Pragma: public");
  114. header("Expires: 0");
  115. header("Content-type: application/zip");
  116. header('Content-Disposition: inline; filename="' . $file . '"');
  117. header("Content-Transfer-Encoding: Binary");
  118. header("Content-length: ".filesize($file));
  119. header('Content-Type: application/octet-stream');
  120. header('Content-Disposition: attachment; filename="' . $file . '"');
  121. ob_clean();
  122. flush();
  123. readfile($file);
  124. } else {
  125. return false;
  126. }
  127. unlink($datafile);
  128. unlink($file);
  129. }
  130. } else {
  131. if(ini_get('zlib.output_compression')) {
  132. ini_set('zlib.output_compression', 'Off');
  133. }
  134. header('Pragma: public');
  135. header('Expires: 0');
  136. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  137. header('Cache-Control: private',false);
  138. header('Content-Type: application/force-download');
  139. header('Content-Disposition: attachment; filename="'.$theme['Name'].'_themify_export_'.date("Y-m-d").'.txt"');
  140. header('Content-Transfer-Encoding: binary');
  141. ob_clean();
  142. flush();
  143. echo serialize(get_data());
  144. }
  145. return;
  146. }
  147. /**
  148. * Import Settings from uploaded zip file
  149. * NOTE: This function is not called through AJAX but it is kept here for consistency.
  150. * @since 1.1.3
  151. * @package themify
  152. */
  153. function themify_import(){
  154. if(!empty($_FILES)) {
  155. if(!is_dir(TEMPLATEPATH.'/themify/temp')){
  156. mkdir(TEMPLATEPATH.'/themify/temp', 0777);
  157. }
  158. if(move_uploaded_file($_FILES['Filedata']['tmp_name'], TEMPLATEPATH.'/themify/temp/'.basename($_FILES['Filedata']['name']))){
  159. $file = basename($_FILES['Filedata']['name']);
  160. $ext = substr(strrchr($file, '.'), 1);
  161. $dir = 'temp/';
  162. if($ext == 'zip' || $ext == 'rar'){
  163. themify_extract_zip(TEMPLATEPATH.'/themify/'.$dir.$file);
  164. } else if($ext == 'txt'){
  165. $handler = fopen($dir.$file, 'r');
  166. if(filesize($dir.$file) > 0){
  167. $data = fread($handler, filesize($dir.$file));
  168. set_data(unserialize($data));
  169. }
  170. fclose($fh);
  171. }
  172. $handle = opendir('temp/');
  173. while($file = readdir($handle)){
  174. if($file != '.' && $file != '..'){
  175. unlink('temp/'.$file);
  176. }
  177. }
  178. rmdir('temp/');
  179. echo 'true';
  180. } else {
  181. echo 'false';
  182. }
  183. }
  184. }
  185. /**
  186. * Pull data for inspection
  187. * @since 1.1.3
  188. * @package themify
  189. */
  190. function themify_pull(){
  191. print_r(get_data());
  192. die();
  193. }
  194. add_action('wp_ajax_themify_pull', 'themify_pull');
  195. ?>