Changeset 3130084
- Timestamp:
- 08/02/2024 02:16:21 PM (20 months ago)
- Location:
- flowheel-integrator/trunk
- Files:
-
- 4 edited
-
flowheel-integrator.php (modified) (3 diffs)
-
readme.txt (modified) (1 diff)
-
src/exporter.php (modified) (7 diffs)
-
src/pages.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
flowheel-integrator/trunk/flowheel-integrator.php
r3116257 r3130084 8 8 Plugin Name: Flowheel Integrator 9 9 Description: Flowheel Integrator is a plugin which provides API endpoints for exporting Wordpress pages into HTML. 10 Version: 1. 0.010 Version: 1.1.0 11 11 Author: Prospecter Ventures AG 12 12 License: GPL2 … … 43 43 register_rest_route( 44 44 'fhint-api/v1', 45 '/wp-template-info', 46 array( 47 'methods' => 'GET', 48 'callback' => 'fhint\fhint_wp_template_info', 49 ) 50 ); 51 register_rest_route( 52 'fhint-api/v1', 53 '/post-info', 54 array( 55 'methods' => 'GET', 56 'callback' => 'fhint\fhint_post_info', 57 ) 58 ); 59 register_rest_route( 60 'fhint-api/v1', 45 61 '/export/(?P<id>\d+)', 46 62 array( … … 49 65 ) 50 66 ); 67 register_rest_route( 68 'fhint-api/v1', 69 '/export/front-page', 70 array( 71 'methods' => 'GET', 72 'callback' => 'fhint\fhint_export_front_page', 73 ) 74 ); 75 register_rest_route( 76 'fhint-api/v1', 77 '/get-info/(?P<id>\d+)', 78 array( 79 'methods' => 'GET', 80 'callback' => 'fhint\fhint_get_info', 81 ) 82 ); 51 83 } -
flowheel-integrator/trunk/readme.txt
r3116257 r3130084 4 4 Requires at least: 4.7 5 5 Tested up to: 6.5 6 Stable tag: 1. 0.06 Stable tag: 1.1.0 7 7 License: GPLv2 8 8 -
flowheel-integrator/trunk/src/exporter.php
r3116257 r3130084 10 10 use DOMDocument; 11 11 use DOMXPath; 12 use WP_Error; 12 13 13 14 function fhint_export_pages() … … 60 61 { 61 62 62 $wpUrl = get_bloginfo('wpurl');63 64 63 $response = wp_remote_get(get_page_link($page->ID)); 65 64 if (is_wp_error($response) && wp_remote_retrieve_response_code($response) != 200) { … … 70 69 return $response; 71 70 } 71 72 $modifiedHtml = fhint_parse_html($htmlContent); 73 if (is_wp_error($response)) { 74 return $response->get_error_message(); 75 } 76 77 return array( 78 'url' => get_page_link($page->ID), 79 'title' => $page->post_title, 80 'name' => $page->post_name, 81 'html' => $modifiedHtml, 82 ); 83 } 84 85 function fhint_export_front_page() 86 { 87 88 $wpUrl = get_bloginfo('wpurl'); 89 $response = wp_remote_get($wpUrl); 90 if (is_wp_error($response) && wp_remote_retrieve_response_code($response) != 200) { 91 return $response; 92 } 93 $htmlContent = wp_remote_retrieve_body($response); 94 if (is_wp_error($htmlContent) && wp_remote_retrieve_response_code($response) != 200) { 95 return $response; 96 } 97 98 $modifiedHtml = fhint_parse_html($htmlContent); 99 if (is_wp_error($response)) { 100 return $response->get_error_message(); 101 } 102 103 $data = array( 104 'url' => $wpUrl, 105 'title' => 'Front Page', 106 'name' => 'index', 107 'html' => $modifiedHtml, 108 ); 109 110 return rest_ensure_response( 111 array( 112 'data' => $data 113 ) 114 ); 115 } 116 117 function fhint_parse_html($htmlContent) 118 { 119 120 $wpUrl = get_bloginfo('wpurl'); 72 121 73 122 // Remove header and footer … … 84 133 $dom->loadHTML($htmlContent); 85 134 if (!$dom) { 86 return $response;135 return new WP_Error('invalid_argument', 'dom false'); 87 136 } 88 137 … … 105 154 if ($srcUrl != null && !isAbsolute($srcUrl)) { 106 155 $srcUrl = $wpUrl + $srcUrl; 107 $ linkElement->setAttribute('src', $srcUrl);156 $imgElement->setAttribute('src', $srcUrl); 108 157 } 109 158 $srcSetUrl = $imgElement->getAttribute('srcset'); 110 159 if ($srcSetUrl != null && !isAbsolute($srcSetUrl)) { 111 160 $srcSetUrl = $wpUrl + $srcSetUrl; 112 $ linkElement->setAttribute('src', $srcSetUrl);161 $imgElement->setAttribute('src', $srcSetUrl); 113 162 } 114 163 } 115 164 116 165 foreach ($scriptElements as $scriptElement) { 117 $scriptUrl = $scriptElement->getAttribute('src'); 118 if ($scriptUrl != null && !isAbsolute($scriptUrl)) { 119 $scriptUrl = $wpUrl + $scriptUrl; 120 $linkElement->setAttribute('src', $scriptUrl); 121 } 166 $scriptElement->parentNode->removeChild($scriptElement); 167 // $scriptUrl = $scriptElement->getAttribute('src'); 168 // if ($scriptUrl != null && !isAbsolute($scriptUrl)) { 169 // $scriptUrl = $wpUrl + $scriptUrl; 170 // $scriptElement->setAttribute('src', $scriptUrl); 171 // } 122 172 } 123 173 … … 130 180 $aUrl = $post->post_name . '.html'; 131 181 $aElement->setAttribute('href', $aUrl); 182 } else { 183 $aUrl = 'index.html'; 184 $aElement->setAttribute('href', $aUrl); 132 185 } 133 186 } … … 137 190 $modifiedHtml = str_replace(["\n", "\r", "\r\n", "\t"], '', $modifiedHtml); 138 191 139 return array( 140 'url' => get_page_link($page->ID), 141 'title' => $page->post_title, 142 'name' => $page->post_name, 143 'html' => $modifiedHtml, 144 ); 192 return $modifiedHtml; 145 193 } 146 194 -
flowheel-integrator/trunk/src/pages.php
r3116257 r3130084 33 33 ); 34 34 } 35 36 function fhint_wp_template_info() 37 { 38 $templates = get_posts( 39 array( 40 'post_type' => 'wp_template', 41 'post_status' => 'publish', 42 'number' => -1, // Retrieve all pages 43 ) 44 ); 45 46 $templates_info = array(); 47 48 foreach ($templates as $template) { 49 $templates_info[] = array( 50 'page_id' => $template->ID, 51 'url' => get_page_link($template->ID), 52 ); 53 } 54 55 return rest_ensure_response( 56 array( 57 'data' => $templates_info 58 ) 59 ); 60 } 61 62 function fhint_post_info() 63 { 64 $posts = get_posts( 65 array( 66 'post_type' => 'post', 67 'post_status' => 'publish', 68 'number' => -1, // Retrieve all pages 69 ) 70 ); 71 72 $posts_info = array(); 73 74 foreach ($posts as $post) { 75 $posts_info[] = array( 76 'page_id' => $post->ID, 77 'url' => get_page_link($post->ID), 78 ); 79 } 80 81 return rest_ensure_response( 82 array( 83 'data' => $posts_info 84 ) 85 ); 86 } 87 88 function fhint_get_info($request) 89 { 90 $id = $request['id']; 91 $page = get_post($id); 92 93 94 $pages_info[] = array( 95 'page_id' => $page->ID, 96 'url' => get_page_link($page->ID), 97 'name' => $page->post_name 98 ); 99 100 return rest_ensure_response( 101 array( 102 'data' => $pages_info 103 ) 104 ); 105 }
Note: See TracChangeset
for help on using the changeset viewer.