array( 'loading' => __('Tree is loading...', 'f4-tree'), 'error' => __('An error occured', 'f4-tree'), ) ) ); } /** * Show the tree in backend * * @since 1.0.0 * @access public * @static */ public static function show_tree_in_backend() { if(!Tree::is_tree_enabled()) { return; } include F4_TREE_PATH . 'Tree/views/tree.php'; } /** * Ajax load tree * * @since 1.0.0 * @access public * @static */ public static function ajax_load_tree() { $post_id = isset($_REQUEST['post_id']) ? intval($_REQUEST['post_id']) : 0; $post_type = isset($_REQUEST['post_type']) ? sanitize_title($_REQUEST['post_type']) : 'page'; $lang = isset($_REQUEST['lang']) ? sanitize_title($_REQUEST['lang']) : ''; Core::maybe_change_current_language($lang); $treeview = Tree::get_tree($post_id, $post_type); $treeview = apply_filters('F4/TREE/Tree/ajax_load_tree', $treeview); echo wp_json_encode($treeview); die(); } /** * Ajax move post * * @since 1.0.0 * @access public * @static */ public static function ajax_move_tree_post() { global $wpdb; $posts_sorted = json_decode(stripslashes($_REQUEST['posts_sorted'] ?? '[]'), true); if(!is_array($posts_sorted)) { $posts_sorted = []; } $posts_sorted = apply_filters('F4/TREE/Tree/move_tree_post_get_sorted_post_ids', $posts_sorted); $lang = isset($_REQUEST['lang']) ? sanitize_title($_REQUEST['lang']) : ''; Core::maybe_change_current_language($lang); foreach($posts_sorted as $post_index => $post_item) { $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_parent = %d, menu_order = %d WHERE ID = %d", $post_item['parent_post_id'], $post_index, $post_item['post_id'] ) ); clean_post_cache($post_item['post_id']); } do_action('F4/TREE/Tree/move_tree_post', $posts_sorted); echo Tree::update_changed_timestamp(); die(); } /** * Ajax refresh tree * * @since 1.0.0 * @access public * @static */ public static function ajax_refresh_tree() { session_write_close(); ignore_user_abort(true); $last_request_timestamp = isset($_REQUEST['timestamp']) ? intval($_REQUEST['timestamp']) : null; $post_id = isset($_REQUEST['post_id']) ? intval($_REQUEST['post_id']) : -1; $post_type = isset($_REQUEST['post_type']) ? sanitize_title($_REQUEST['post_type']) : 'page'; $lang = isset($_REQUEST['lang']) ? sanitize_title($_REQUEST['lang']) : ''; Core::maybe_change_current_language($lang); set_time_limit(299); // 5 min - 1 sec while(true) { echo ' '; ob_flush(); flush(); if(connection_status() != CONNECTION_NORMAL) { break; die(); } clearstatcache(); Tree::clear_changed_timestamp_cache(); $last_change_timestamp = Tree::get_changed_timestamp(); if($last_request_timestamp === null || $last_change_timestamp > $last_request_timestamp) { wp_cache_init(); $response = array( //'sample-permalink' => get_sample_permalink_html($post_id), // @todo: temporarily disabled because of manual change overwrite 'sample-permalink' => '', 'data' => Tree::get_tree($post_id, $post_type), 'timestamp' => $last_change_timestamp ); $responseJSON = wp_json_encode($response); echo $responseJSON; break; } else { sleep(1); } } die(); } /** * Remove parent id dropdown * * @since 1.0.0 * @access public * @static */ public static function remove_page_attributes_parent_id($args) { if(Tree::is_tree_enabled()) { $args['child_of'] = '-10'; } return $args; } /** * Update last change time if the post edit lock changes * * @since 1.0.0 * @access public * @static */ public static function updated_edit_lock($meta_id, $post_id, $meta_key, $meta_value) { if($meta_key === '_edit_lock' && Tree::is_tree_post_type($post_id)) { Tree::update_changed_timestamp(); } } /** * Update last change time if post is saved or deleted * * @since 1.0.0 * @access public * @static */ public static function update_post($post_id) { if(Tree::is_tree_post_type($post_id)) { Tree::update_changed_timestamp(); } } /** * Show tree admin settings * * @since 1.0.0 * @access public * @static */ public static function add_admin_settings_fields() { include 'views/admin-settings-fields.php'; } } ?>