PageRenderTime 29ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/bridge/plugins/layersliderwp-5.3.2.installable/LayerSlider/wp/actions.php

https://gitlab.com/juanito.abelo/nlmobile
PHP | 662 lines | 469 code | 115 blank | 78 comment | 126 complexity | 88745887f58755c42ed14b58c26303c2 MD5 | raw file
  1. <?php
  2. add_action('init', 'ls_register_form_actions');
  3. function ls_register_form_actions() {
  4. if(current_user_can(get_option('layerslider_custom_capability', 'manage_options'))) {
  5. // Remove slider
  6. if(isset($_GET['page']) && $_GET['page'] == 'layerslider' && isset($_GET['action']) && $_GET['action'] == 'remove') {
  7. if(check_admin_referer('remove_'.$_GET['id'])) {
  8. add_action('admin_init', 'layerslider_removeslider');
  9. }
  10. }
  11. // Restore slider
  12. if(isset($_GET['page']) && $_GET['page'] == 'layerslider' && isset($_GET['action']) && $_GET['action'] == 'restore') {
  13. if(check_admin_referer('restore_'.$_GET['id'])) {
  14. LS_Sliders::restore( (int) $_GET['id'] );
  15. header('Location: admin.php?page=layerslider'); die();
  16. }
  17. }
  18. // Duplicate slider
  19. if(isset($_GET['page']) && $_GET['page'] == 'layerslider' && isset($_GET['action']) && $_GET['action'] == 'duplicate') {
  20. if(check_admin_referer('duplicate_'.$_GET['id'])) {
  21. add_action('admin_init', 'layerslider_duplicateslider');
  22. }
  23. }
  24. // Import sample sliders
  25. if(isset($_GET['page']) && $_GET['page'] == 'layerslider' && isset($_GET['action']) && $_GET['action'] == 'import_sample') {
  26. if(check_admin_referer('import-sample-sliders')) {
  27. add_action('admin_init', 'layerslider_import_sample_slider');
  28. }
  29. }
  30. // Slider list bulk actions
  31. if(isset($_POST['ls-bulk-action'])) {
  32. if(check_admin_referer('bulk-action')) {
  33. add_action('admin_init', 'ls_sliders_bulk_action');
  34. }
  35. }
  36. // Add new slider
  37. if(isset($_POST['ls-add-new-slider'])) {
  38. if(check_admin_referer('add-slider')) {
  39. add_action('admin_init', 'ls_add_new_slider');
  40. }
  41. }
  42. // Google Fonts
  43. if(isset($_POST['ls-save-google-fonts'])) {
  44. if(check_admin_referer('save-google-fonts')) {
  45. add_action('admin_init', 'ls_save_google_fonts');
  46. }
  47. }
  48. // Advanced settings
  49. if(isset($_POST['ls-save-advanced-settings'])) {
  50. if(check_admin_referer('save-advanced-settings')) {
  51. add_action('admin_init', 'ls_save_advanced_settings');
  52. }
  53. }
  54. // Access permission
  55. if(isset($_POST['ls-access-permission'])) {
  56. if(check_admin_referer('save-access-permissions')) {
  57. add_action('admin_init', 'ls_save_access_permissions');
  58. }
  59. }
  60. // Import sliders
  61. if(isset($_POST['ls-import'])) {
  62. if(check_admin_referer('import-sliders')) {
  63. add_action('admin_init', 'ls_import_sliders');
  64. }
  65. }
  66. // Export sliders
  67. if(isset($_POST['ls-export'])) {
  68. if(check_admin_referer('export-sliders')) {
  69. add_action('admin_init', 'ls_export_sliders');
  70. }
  71. }
  72. // Custom CSS editor
  73. if(isset($_POST['ls-user-css'])) {
  74. if(check_admin_referer('save-user-css')) {
  75. add_action('admin_init', 'ls_save_user_css');
  76. }
  77. }
  78. // Skin editor
  79. if(isset($_POST['ls-user-skins'])) {
  80. if(check_admin_referer('save-user-skin')) {
  81. add_action('admin_init', 'ls_save_user_skin');
  82. }
  83. }
  84. // Transition builder
  85. if(isset($_POST['ls-user-transitions'])) {
  86. if(check_admin_referer('save-user-transitions')) {
  87. add_action('admin_init', 'ls_save_user_transitions');
  88. }
  89. }
  90. // Compatibility: convert old sliders to new data storage since 3.6
  91. if(isset($_GET['page']) && $_GET['page'] == 'layerslider' && isset($_GET['action']) && $_GET['action'] == 'convert') {
  92. if(check_admin_referer('convertoldsliders')) {
  93. add_action('admin_init', 'layerslider_convert');
  94. }
  95. }
  96. if(isset($_GET['page']) && $_GET['page'] == 'layerslider' && isset($_GET['action']) && $_GET['action'] == 'hide-support-notice') {
  97. if(check_admin_referer('hide-support-notice')) {
  98. update_option('ls-show-support-notice', 0);
  99. header('Location: admin.php?page=layerslider');
  100. die();
  101. }
  102. }
  103. if(isset($_GET['page']) && $_GET['page'] == 'layerslider' && isset($_GET['action']) && $_GET['action'] == 'hide-revalidation-notice') {
  104. if(check_admin_referer('hide-revalidation-notice')) {
  105. update_option('ls-show-revalidation-notice', 0);
  106. header('Location: admin.php?page=layerslider');
  107. die();
  108. }
  109. }
  110. // AJAX functions
  111. add_action('wp_ajax_ls_save_slider', 'ls_save_slider');
  112. add_action('wp_ajax_ls_save_screen_options', 'ls_save_screen_options');
  113. add_action('wp_ajax_ls_get_mce_sliders', 'ls_get_mce_sliders');
  114. add_action('wp_ajax_ls_update_box_toggles', 'ls_update_box_toggles');
  115. add_action('wp_ajax_ls_get_post_details', 'ls_get_post_details');
  116. add_action('wp_ajax_ls_get_taxonomies', 'ls_get_taxonomies');
  117. }
  118. }
  119. function ls_add_new_slider() {
  120. $id = LS_Sliders::add($_POST['title']);
  121. header('Location: admin.php?page=layerslider&action=edit&id='.$id.'&showsettings=1');
  122. die();
  123. }
  124. function ls_sliders_bulk_action() {
  125. // Remove
  126. if($_POST['action'] === 'remove') {
  127. if(!empty($_POST['sliders']) && is_array($_POST['sliders'])) {
  128. foreach($_POST['sliders'] as $item) { LS_Sliders::remove( intval($item) ); }
  129. header('Location: admin.php?page=layerslider&message=removeSuccess'); die();
  130. } else {
  131. header('Location: admin.php?page=layerslider&message=removeSelectError&error=1'); die();
  132. }
  133. }
  134. // Delete
  135. if($_POST['action'] === 'delete') {
  136. if(!empty($_POST['sliders']) && is_array($_POST['sliders'])) {
  137. foreach($_POST['sliders'] as $item) { LS_Sliders::delete( intval($item)); }
  138. header('Location: admin.php?page=layerslider&message=deleteSuccess'); die();
  139. } else {
  140. header('Location: admin.php?page=layerslider&message=deleteSelectError&error=1'); die();
  141. }
  142. }
  143. // Restore
  144. if($_POST['action'] === 'restore') {
  145. if(!empty($_POST['sliders']) && is_array($_POST['sliders'])) {
  146. foreach($_POST['sliders'] as $item) { LS_Sliders::restore( intval($item)); }
  147. header('Location: admin.php?page=layerslider&message=restoreSuccess'); die();
  148. } else {
  149. header('Location: admin.php?page=layerslider&message=restoreSelectError&error=1'); die();
  150. }
  151. }
  152. // Merge
  153. if($_POST['action'] === 'merge') {
  154. // Error check
  155. if(!isset($_POST['sliders'][1]) || !is_array($_POST['sliders'])) {
  156. header('Location: admin.php?page=layerslider&error=1&message=mergeSelectError');
  157. die();
  158. }
  159. if($sliders = LS_Sliders::find($_POST['sliders'])) {
  160. foreach($sliders as $key => $item) {
  161. // Get IDs
  162. $ids[] = '#' . $item['id'];
  163. // Merge slides
  164. if($key === 0) { $data = $item['data']; }
  165. else { $data['layers'] = array_merge($data['layers'], $item['data']['layers']); }
  166. }
  167. // Save as new
  168. $name = 'Merged sliders of ' . implode(', ', $ids);
  169. $data['properties']['title'] = $name;
  170. LS_Sliders::add($name, $data);
  171. }
  172. header('Location: admin.php?page=layerslider&message=mergeSuccess');
  173. die();
  174. }
  175. }
  176. function ls_save_google_fonts() {
  177. // Build object to save
  178. $fonts = array();
  179. if(isset($_POST['urlParams'])) {
  180. foreach($_POST['urlParams'] as $key => $val) {
  181. if(!empty($val)) {
  182. $fonts[] = array(
  183. 'param' => $val,
  184. 'admin' => isset($_POST['onlyOnAdmin'][$key]) ? true : false
  185. );
  186. }
  187. }
  188. }
  189. // Google Fonts character sets
  190. array_shift($_POST['scripts']);
  191. update_option('ls-google-font-scripts', $_POST['scripts']);
  192. // Save & redirect back
  193. update_option('ls-google-fonts', $fonts);
  194. header('Location: admin.php?page=layerslider&message=googleFontsUpdated');
  195. die();
  196. }
  197. function ls_save_advanced_settings() {
  198. $options = array('use_custom_jquery', 'include_at_footer', 'conditional_script_loading', 'concatenate_output', 'put_js_to_body');
  199. foreach($options as $item) {
  200. update_option('ls_'.$item, array_key_exists($item, $_POST));
  201. }
  202. header('Location: admin.php?page=layerslider&message=generalUpdated');
  203. die();
  204. }
  205. function ls_save_screen_options() {
  206. $_POST['options'] = !empty($_POST['options']) ? $_POST['options'] : array();
  207. update_option('ls-screen-options', $_POST['options']);
  208. die();
  209. }
  210. function ls_get_mce_sliders() {
  211. $sliders = LS_Sliders::find(array('limit' => 50));
  212. foreach($sliders as $key => $item) {
  213. $sliders[$key]['preview'] = apply_filters('ls_get_preview_for_slider', $item );
  214. }
  215. die(json_encode($sliders));
  216. }
  217. function ls_update_box_toggles() {
  218. // Get toggle settings
  219. $toggles = get_option('ls-collapsed-boxes', false);
  220. $toggles = !is_array($toggles) ? array() : $toggles;
  221. // Get new setting
  222. $key = $_POST['key'];
  223. $collapsed = $_POST['collapsed'];
  224. // Update & Save
  225. $toggles[$key] = ($collapsed == 'true') ? true : false;
  226. update_option('ls-collapsed-boxes', $toggles);
  227. }
  228. function ls_save_slider() {
  229. // Vars
  230. $id = (int) $_POST['id'];
  231. $settings = $slides = $callbacks = $data = array();
  232. // Decode data
  233. parse_str($_POST['settings'], $settings);
  234. parse_str($_POST['callbacks'], $callbacks);
  235. if(!empty($_POST['slides']) && is_array($_POST['slides'])) {
  236. foreach($_POST['slides'] as $key => $val) {
  237. $tmp = array();
  238. parse_str($val, $tmp);
  239. $slides['ls_data']['layers'][$key] = $tmp['ls_data']['layers'][$key];
  240. }
  241. }
  242. $data = array_merge_recursive($settings, $slides, $callbacks);
  243. $data = $data['ls_data'];
  244. $title = esc_sql($data['properties']['title']);
  245. $slug = !empty($data['properties']['slug']) ? esc_sql($data['properties']['slug']) : '';
  246. // Relative URL
  247. if(isset($data['properties']['relativeurls'])) {
  248. $data = layerslider_convert_urls($data);
  249. }
  250. // WPML
  251. if(function_exists('icl_register_string')) {
  252. layerslider_register_wpml_strings($id, $data);
  253. }
  254. // Update the slider
  255. if(empty($id)) {
  256. LS_Sliders::add($title, $data);
  257. } else {
  258. LS_Sliders::update($id, $title, $data, $slug);
  259. }
  260. die(json_encode(array('status' => 'ok')));
  261. }
  262. /********************************************************/
  263. /* Action to duplicate slider */
  264. /********************************************************/
  265. function layerslider_duplicateslider() {
  266. // Check and get the ID
  267. $id = (int) $_GET['id'];
  268. if(!isset($_GET['id'])) {
  269. return;
  270. }
  271. // Get the original slider
  272. $slider = LS_Sliders::find( (int)$_GET['id'] );
  273. $data = $slider['data'];
  274. // Name check
  275. if(empty($data['properties']['title'])) {
  276. $data['properties']['title'] = 'Unnamed';
  277. }
  278. // Insert the duplicate
  279. $data['properties']['title'] .= ' copy';
  280. LS_Sliders::add($data['properties']['title'], $data);
  281. // Success
  282. header('Location: admin.php?page=layerslider');
  283. die();
  284. }
  285. /********************************************************/
  286. /* Action to remove slider */
  287. /********************************************************/
  288. function layerslider_removeslider() {
  289. // Check received data
  290. if(empty($_GET['id'])) { return false; }
  291. // Remove the slider
  292. LS_Sliders::remove( intval($_GET['id']) );
  293. // Reload page
  294. header('Location: admin.php?page=layerslider');
  295. die();
  296. }
  297. /********************************************************/
  298. /* Action to import sample slider */
  299. /********************************************************/
  300. function layerslider_import_sample_slider() {
  301. // Get samples and importUtil
  302. $sliders = LS_Sources::getDemoSliders();
  303. include LS_ROOT_PATH.'/classes/class.ls.importutil.php';
  304. // Check reference
  305. if(!empty($_GET['slider']) && $_GET['slider'] == 'all') {
  306. foreach($sliders as $item) {
  307. if(file_exists($item['file'])) {
  308. $import = new LS_ImportUtil($item['file']);
  309. }
  310. }
  311. } elseif(!empty($_GET['slider']) && is_string($_GET['slider'])) {
  312. if($item = LS_Sources::getDemoSlider($_GET['slider'])) {
  313. if(file_exists($item['file'])) {
  314. $import = new LS_ImportUtil($item['file']);
  315. }
  316. }
  317. }
  318. header('Location: '.menu_page_url('layerslider', 0));
  319. die();
  320. }
  321. // PLUGIN USER PERMISSIONS
  322. //-------------------------------------------------------
  323. function ls_save_access_permissions() {
  324. // Get capability
  325. $capability = ($_POST['custom_role'] == 'custom') ? $_POST['custom_capability'] : $_POST['custom_role'];
  326. // Test value
  327. if(empty($capability) || !current_user_can($capability)) {
  328. header('Location: admin.php?page=layerslider&error=1&message=permissionError');
  329. die();
  330. } else {
  331. update_option('layerslider_custom_capability', $capability);
  332. header('Location: admin.php?page=layerslider&message=permissionSuccess');
  333. die();
  334. }
  335. }
  336. // IMPORT SLIDERS
  337. //-------------------------------------------------------
  338. function ls_import_sliders() {
  339. // Check export file if any
  340. if(!is_uploaded_file($_FILES['import_file']['tmp_name'])) {
  341. header('Location: '.$_SERVER['REQUEST_URI'].'&error=1&message=importSelectError');
  342. die('No data received.');
  343. }
  344. include LS_ROOT_PATH.'/classes/class.ls.importutil.php';
  345. $import = new LS_ImportUtil($_FILES['import_file']['tmp_name'], $_FILES['import_file']['name']);
  346. header('Location: '.menu_page_url('layerslider', 0));
  347. die();
  348. }
  349. // EXPORT SLIDERS
  350. //-------------------------------------------------------
  351. function ls_export_sliders() {
  352. // Get sliders
  353. if(isset($_POST['sliders'][0]) && $_POST['sliders'][0] == -1) {
  354. $sliders = LS_Sliders::find(array('limit' => 500));
  355. } elseif(!empty($_POST['sliders'])) {
  356. $sliders = LS_Sliders::find($_POST['sliders']);
  357. } else {
  358. header('Location: admin.php?page=layerslider&error=1&message=exportSelectError');
  359. die('Invalid data received.');
  360. }
  361. // Check results
  362. if(empty($sliders)) {
  363. header('Location: admin.php?page=layerslider&error=1&message=exportNotFound');
  364. die('Invalid data received.');
  365. }
  366. if(class_exists('ZipArchive')) {
  367. include LS_ROOT_PATH.'/classes/class.ls.exportutil.php';
  368. $zip = new LS_ExportUtil;
  369. }
  370. // Gather slider data
  371. foreach($sliders as $item) {
  372. // Slider settings array for fallback mode
  373. $data[] = $item['data'];
  374. // If ZipArchive is available
  375. if(class_exists('ZipArchive')) {
  376. // Add slider folder and settings.json
  377. $name = empty($item['name']) ? 'slider_' . $item['id'] : $item['name'];
  378. $name = sanitize_file_name($name);
  379. $zip->addSettings(json_encode($item['data']), $name);
  380. // Add images?
  381. if(isset($_POST['exportWithImages'])) {
  382. $images = $zip->getImagesForSlider($item['data']);
  383. $images = $zip->getFSPaths($images);
  384. $zip->addImage($images, $name);
  385. }
  386. }
  387. }
  388. if(class_exists('ZipArchive')) {
  389. $zip->download();
  390. } else {
  391. $name = 'LayerSlider Export '.date('Y-m-d').' at '.date('H.i.s').'.json';
  392. header('Content-type: application/force-download');
  393. header('Content-Disposition: attachment; filename="'.str_replace(' ', '_', $name).'"');
  394. die(base64_encode(json_encode($data)));
  395. }
  396. }
  397. // TRANSITION BUILDER
  398. //-------------------------------------------------------
  399. function ls_save_user_css() {
  400. // Get target file and content
  401. $upload_dir = wp_upload_dir();
  402. $file = $upload_dir['basedir'].'/layerslider.custom.css';
  403. // Attempt to save changes
  404. if(is_writable($upload_dir['basedir'])) {
  405. file_put_contents($file, stripslashes($_POST['contents']));
  406. header('Location: admin.php?page=ls-style-editor&edited=1');
  407. die();
  408. // File isn't writable
  409. } else {
  410. wp_die(__("It looks like your files isn't writable, so PHP couldn't make any changes (CHMOD).", "LayerSlider"), __('Cannot write to file', 'LayerSlider'), array('back_link' => true) );
  411. }
  412. }
  413. // SKIN EDITOR
  414. //-------------------------------------------------------
  415. function ls_save_user_skin() {
  416. // Error checking
  417. if(empty($_POST['skin']) || strpos($_POST['skin'], '..') !== false) {
  418. wp_die(__("It looks like you haven't selected any skin to edit.", "LayerSlider"), __('No skin selected.', 'LayerSlider'), array('back_link' => true) );
  419. }
  420. // Get skin file and contents
  421. $skin = LS_Sources::getSkin($_POST['skin']);
  422. $file = $skin['file'];
  423. // Attempt to write the file
  424. if(is_writable($file)) {
  425. file_put_contents($file, stripslashes($_POST['contents']));
  426. header('Location: admin.php?page=ls-skin-editor&skin='.$skin['handle'].'&edited=1');
  427. } else {
  428. wp_die(__("It looks like your files isn't writable, so PHP couldn't make any changes (CHMOD).", "LayerSlider"), __('Cannot write to file', 'LayerSlider'), array('back_link' => true) );
  429. }
  430. }
  431. // TRANSITION BUILDER
  432. //-------------------------------------------------------
  433. function ls_save_user_transitions() {
  434. // Array to hold transitions
  435. $transitions = array();
  436. // Get transitions
  437. $transitions['t2d'] = isset($_POST['t2d']) ? $_POST['t2d'] : array();
  438. $transitions['t3d'] = isset($_POST['t3d']) ? $_POST['t3d'] : array();
  439. array_walk_recursive($transitions['t2d'], 'layerslider_builder_convert_numbers');
  440. array_walk_recursive($transitions['t3d'], 'layerslider_builder_convert_numbers');
  441. // Iterate over the sections
  442. foreach($transitions['t3d'] as $key => $val) {
  443. // Rows
  444. if(strstr($val['rows'], ',')) { $tmp = explode(',', $val['rows']); $tmp[0] = (int) trim($tmp[0]); $tmp[1] = (int) trim($tmp[1]); $transitions['t3d'][$key]['rows'] = $tmp; }
  445. else { $transitions['t3d'][$key]['rows'] = (int) $val['rows']; }
  446. // Cols
  447. if(strstr($val['cols'], ',')) { $tmp = explode(',', $val['cols']); $tmp[0] = (int) trim($tmp[0]); $tmp[1] = (int) trim($tmp[1]); $transitions['t3d'][$key]['cols'] = $tmp; }
  448. else { $transitions['t3d'][$key]['cols'] = (int) $val['cols']; }
  449. // Depth
  450. if(isset($val['tile']['depth'])) {
  451. $transitions['t3d'][$key]['tile']['depth'] = 'large'; }
  452. // Before
  453. if(!isset($val['before']['enabled'])) {
  454. unset($transitions['t3d'][$key]['before']['transition']); }
  455. // After
  456. if(!isset($val['after']['enabled'])) {
  457. unset($transitions['t3d'][$key]['after']['transition']); }
  458. }
  459. // Iterate over the sections
  460. foreach($transitions['t2d'] as $key => $val) {
  461. if(strstr($val['rows'], ',')) { $tmp = explode(',', $val['rows']); $tmp[0] = (int) trim($tmp[0]); $tmp[1] = (int) trim($tmp[1]); $transitions['t2d'][$key]['rows'] = $tmp; }
  462. else { $transitions['t2d'][$key]['rows'] = (int) $val['rows']; }
  463. if(strstr($val['cols'], ',')) { $tmp = explode(',', $val['cols']); $tmp[0] = (int) trim($tmp[0]); $tmp[1] = (int) trim($tmp[1]); $transitions['t2d'][$key]['cols'] = $tmp; }
  464. else { $transitions['t2d'][$key]['cols'] = (int) $val['cols']; }
  465. if(empty($val['transition']['rotateX'])) {
  466. unset($transitions['t2d'][$key]['transition']['rotateX']); }
  467. if(empty($val['transition']['rotateY'])) {
  468. unset($transitions['t2d'][$key]['transition']['rotateY']); }
  469. if(empty($val['transition']['rotate'])) {
  470. unset($transitions['t2d'][$key]['transition']['rotate']); }
  471. if(empty($val['transition']['scale']) || $val['transition']['scale'] == '1.0' || $val['transition']['scale'] == '1') {
  472. unset($transitions['t2d'][$key]['transition']['scale']); }
  473. }
  474. // Save transitions
  475. $upload_dir = wp_upload_dir();
  476. $custom_trs = $upload_dir['basedir'] . '/layerslider.custom.transitions.js';
  477. $data = 'var layerSliderCustomTransitions = '.json_encode($transitions).';';
  478. file_put_contents($custom_trs, $data);
  479. die('SUCCESS');
  480. }
  481. // --
  482. function ls_get_post_details() {
  483. $params = $_POST['params'];
  484. $queryArgs = array(
  485. 'post_status' => 'publish',
  486. 'limit' => 30,
  487. 'posts_per_page' => 30,
  488. 'post_type' => $params['post_type']
  489. );
  490. if(!empty($params['post_orderby'])) {
  491. $queryArgs['orderby'] = $params['post_orderby']; }
  492. if(!empty($params['post_order'])) {
  493. $queryArgs['order'] = $params['post_order']; }
  494. if(!empty($params['post_categories'][0])) {
  495. $queryArgs['category__in'] = $params['post_categories']; }
  496. if(!empty($params['post_tags'][0])) {
  497. $queryArgs['tag__in'] = $params['post_tags']; }
  498. if(!empty($params['post_taxonomy']) && !empty($params['post_tax_terms'])) {
  499. $queryArgs['tax_query'][] = array(
  500. 'taxonomy' => $params['post_taxonomy'],
  501. 'field' => 'id',
  502. 'terms' => $params['post_tax_terms']
  503. );
  504. }
  505. $posts = LS_Posts::find($queryArgs)->getParsedObject();
  506. die(json_encode($posts));
  507. }
  508. function ls_get_taxonomies() {
  509. die(json_encode(array_values(get_terms($_POST['taxonomy']))));
  510. }