admin_url( 'admin-ajax.php' ) ) ); wp_enqueue_script( 'makeAnimation' ); } function galoover_ae_create_mya_post($type, $postType, $template = ''){ switch ($type) { case 'allPage': $my_post = array( 'post_title' => 'mya_all_page', 'post_status' => 'private', 'post_name' => 'mya_all_page', 'post_parent' => 0, 'post_type' => $postType ); break; case 'thisTemplate': $my_post = array( 'post_title' => 'mya_this_template', 'post_status' => 'private', 'post_name' => 'mya_this_template', 'post_parent' => 0, 'post_type' => $postType, 'post_excerpt' => $template ); break; case 'homePage': $my_post = array( 'post_title' => 'mya_home_page', 'post_status' => 'private', 'post_name' => 'mya_home_page', 'post_parent' => 0, 'post_type' => $postType ); break; case 'frontPage': $my_post = array( 'post_title' => 'mya_front_page', 'post_status' => 'private', 'post_name' => 'mya_front_page', 'post_parent' => 0, 'post_type' => $postType ); break; } $id = wp_insert_post( $my_post ); return $id; } function galoover_ae_get_post_id($type, $theme, $template = ''){ global $wpdb; $postType = 'mya_' . $theme; switch ($type) { case 'allPage': $sql = "SELECT ID FROM {$wpdb->prefix}posts WHERE post_title = 'mya_all_page' AND post_status = 'private' AND post_parent = '0' AND post_type = '$postType'"; break; case 'thisTemplate': $sql = "SELECT ID FROM {$wpdb->prefix}posts WHERE post_title = 'mya_this_template' AND post_status = 'private' AND post_parent = '0' AND post_type = '$postType' AND post_excerpt = '$template'"; break; case 'homePage': $sql = "SELECT ID FROM {$wpdb->prefix}posts WHERE post_title = 'mya_home_page' AND post_parent = '0' AND post_type = '$postType' "; break; case 'frontPage': $sql = "SELECT ID FROM {$wpdb->prefix}posts WHERE post_title = 'mya_front_page' AND post_status = 'private' AND post_parent = '0' AND post_type = '$postType'"; break; } $result = $wpdb->get_row($sql); if($result){ $id = $result->ID; }else{ $id = galoover_ae_create_mya_post($type, $postType, $template); } return $id; } function galoover_ae_create_animation($animationName, $eleXPath, $parentId){ $my_post = array( 'post_title' => $animationName, 'post_excerpt' => $eleXPath, 'post_status' => 'private', 'post_parent' => $parentId, 'post_type' => 'mya_animation' ); $id = wp_insert_post( $my_post ); return $id; } function galoover_ae_update_animation($animationId, $animationName, $eleXPath, $parentId){ $my_post = array( 'ID' => $animationId, 'post_title' => $animationName, 'post_excerpt' => $eleXPath, 'post_parent' => $parentId ); $id = wp_update_post( $my_post ); return $id; } function galoover_ae_create_post_meta_animation($animationId, $animationType, $animationData){ global $wpdb; $sql = "SELECT meta_id FROM {$wpdb->prefix}postmeta WHERE post_id = '$animationId' AND meta_key = '$animationType'"; $result = $wpdb->get_row($sql); if($result){ update_post_meta( $animationId, $animationType, $animationData ); }else{ add_post_meta( $animationId, $animationType, $animationData, true ); } } function galoover_ae_save_animation(){ if ( ! is_admin() ) { return 0; } $animationPageValue = isset( $_POST['animationPageValue'] ) ? sanitize_text_field($_POST['animationPageValue']) : ''; $animationPageData = isset( $_POST['animationPageData'] ) ? (array) $_POST['animationPageData'] : array(); $theme = isset( $animationPageData['theme'] ) ? sanitize_text_field($animationPageData['theme']) : ''; if($animationPageValue == '1' || $animationPageValue == '2'){ $parentId = $animationPageData['id']; }else{ switch ($animationPageValue) { case '3': $type = 'homePage'; break; case '4': $type = 'frontPage'; break; case '5': $type = 'thisTemplate'; $template = isset( $animationPageData['template'] ) ? sanitize_text_field($animationPageData['template']) : ''; break; case '0': $type = 'allPage'; break; } $parentId = galoover_ae_get_post_id($type, $theme, $template); } $animationName = isset( $_POST['animationName'] ) ? sanitize_text_field($_POST['animationName']) : ''; $eleXPath = isset( $_POST['eleXPath'] ) ? sanitize_text_field($_POST['eleXPath']) : ''; $animationId = isset( $_POST['animationId'] ) ? sanitize_text_field($_POST['animationId']) : ''; if($animationId){ galoover_ae_update_animation($animationId, $animationName, $eleXPath, $parentId); }else{ $animationId = galoover_ae_create_animation($animationName, $eleXPath, $parentId); } $animationData = isset( $_POST['animationData'] ) ? (array) $_POST['animationData'] : array(); $animationType = isset( $_POST['animationType'] ) ? sanitize_text_field($_POST['animationType']) : ''; galoover_ae_create_post_meta_animation($animationId, $animationType, $animationData); wp_send_json_success($animationId);die; } add_action( 'wp_ajax_galoover_ae_save_animation', 'galoover_ae_save_animation' ); function galoover_ae_remove_animation(){ if ( ! is_admin() ) { return 0; } $postId = isset( $_POST['id'] ) ? sanitize_text_field($_POST['id']) : ''; if($postId){ $status = wp_delete_post($postId); delete_post_meta( $postId, 'load_effect' ); delete_post_meta( $postId, 'hover_effect' ); delete_post_meta( $postId, 'click_effect' ); } if($status != false){ wp_send_json_success('Animation deleted successfully.');die; } } add_action( 'wp_ajax_galoover_ae_remove_animation', 'galoover_ae_remove_animation' ); function galoover_ae_get_animation_list(){ global $wpdb; $template = isset( $_POST['template'] ) ? sanitize_text_field($_POST['template']) : ''; $page = isset( $_POST['page'] ) ? sanitize_text_field($_POST['page']) : ''; $theme = isset( $_POST['theme'] ) ? sanitize_text_field($_POST['theme']) : ''; $id = isset( $_POST['id'] ) ? sanitize_text_field($_POST['id']) : ''; $animationList = array(); if($theme){ $parentId = galoover_ae_get_post_id('allPage', $theme); $sql = "SELECT ID, post_title, post_excerpt FROM {$wpdb->prefix}posts WHERE post_parent = '$parentId' AND post_type = 'mya_animation' "; $animationAllPage = $wpdb->get_results($sql); $animationList = array_merge($animationList, $animationAllPage); if($template){ $parentId = galoover_ae_get_post_id('thisTemplate', $theme, $template); $sql = "SELECT ID, post_title, post_excerpt FROM {$wpdb->prefix}posts WHERE post_parent = '$parentId' AND post_type = 'mya_animation' "; $animationThisTemplate = $wpdb->get_results($sql); $animationList = array_merge($animationList, $animationThisTemplate); } if($page){ switch ($page) { case 'home': $parentId = galoover_ae_get_post_id('homePage', $theme); $sql = "SELECT ID, post_title, post_excerpt FROM {$wpdb->prefix}posts WHERE post_parent = '$parentId' AND post_type = 'mya_animation' "; $animationHomePage = $wpdb->get_results($sql); $animationList = array_merge($animationList, $animationHomePage); break; case 'front': $parentId = galoover_ae_get_post_id('frontPage', $theme); $sql = "SELECT ID, post_title, post_excerpt FROM {$wpdb->prefix}posts WHERE post_parent = '$parentId' AND post_type = 'mya_animation' "; $animationFrontPage = $wpdb->get_results($sql); $animationList = array_merge($animationList, $animationFrontPage); break; case 'page': case 'post': if($id){ $sql = "SELECT ID, post_title, post_excerpt FROM {$wpdb->prefix}posts WHERE post_parent = '$id' AND post_type = 'mya_animation' "; $animationThisPost = $wpdb->get_results($sql); $animationList = array_merge($animationList, $animationThisPost); } } } foreach ($animationList as $key => $animation) { $sql = "SELECT COUNT(*) FROM {$wpdb->prefix}postmeta WHERE post_id = '$animation->ID' AND meta_key LIKE '%_effect' AND meta_value <> '' "; $result = $wpdb->get_var($sql); $result = $result[0]; if($result !== '0'){ $resultList[] = $animationList[$key]; }else{ wp_delete_post($animation->ID); } } } wp_send_json_success($resultList);die; } add_action( 'wp_ajax_galoover_ae_get_animation_list', 'galoover_ae_get_animation_list' ); function galoover_ae_get_animation_data(){ global $wpdb; $postId = isset( $_POST['id'] ) ? sanitize_text_field($_POST['id']) : ''; if($postId){ $sql = "SELECT meta_key, meta_value FROM {$wpdb->prefix}postmeta WHERE post_id = '$postId' AND meta_key LIKE '%_effect' AND meta_value <> '' "; $result = $wpdb->get_results($sql); $sql = "SELECT post_parent FROM {$wpdb->prefix}posts WHERE ID = '$postId' AND post_type = 'mya_animation' "; $parentId = $wpdb->get_row($sql); $sql = "SELECT post_title, post_excerpt, post_type FROM {$wpdb->prefix}posts WHERE ID = '$parentId->post_parent' "; $parentData = $wpdb->get_row($sql); switch ($parentData->post_type) { case 'post': $pageValue = 1; break; case 'page': $pageValue = 2; break; default: if($parentData->post_title === 'mya_home_page'){ $pageValue = 3; }else{ if($parentData->post_title === 'mya_all_page'){ $pageValue = 0; }else{ if($parentData->post_title === 'mya_front_page'){ $pageValue = 4; }else{ if($parentData->post_title === 'mya_this_template'){ $pageValue = 5; } } } } break; } } if($result){ foreach ($result as $key => $animationField) { $animationField->meta_value = unserialize($animationField->meta_value); } $data['pageValue'] = $pageValue; $data['animationList'] = $result; wp_send_json_success($data);die; } } add_action( 'wp_ajax_galoover_ae_get_animation_data', 'galoover_ae_get_animation_data' ); galoover_ae_fs()->add_action('after_uninstall', 'galoover_ae_fs_uninstall_cleanup'); function galoover_ae_fs_uninstall_cleanup(){ global $wpdb; $sql = "SELECT ID, post_parent FROM {$wpdb->prefix}posts WHERE post_status = 'private' AND post_type LIKE 'mya_%' "; $posts = $wpdb->get_results($sql); foreach ( $posts as $post ) { if($post->post_parent !== 0){ delete_post_meta( $post->ID, 'load_effect' ); delete_post_meta( $post->ID, 'hover_effect' ); delete_post_meta( $post->ID, 'click_effect' ); } wp_delete_post( $post->ID, true ); } }