Changeset 1768535
- Timestamp:
- 11/16/2017 05:28:41 PM (8 years ago)
- Location:
- lndr-page-builder/trunk
- Files:
-
- 7 edited
-
README.txt (modified) (2 diffs)
-
includes/class-lndr-activator.php (modified) (1 diff)
-
includes/class-lndr-deactivator.php (modified) (1 diff)
-
includes/class-lndr.php (modified) (1 diff)
-
lndr.php (modified) (3 diffs)
-
public/class-lndr-public.php (modified) (6 diffs)
-
public/lndr-page-template.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
lndr-page-builder/trunk/README.txt
r1767069 r1768535 5 5 Requires at least: 4.7 6 6 Tested up to: 4.8 7 Stable tag: 1. 07 Stable tag: 1.1 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 51 51 == Screenshots == 52 52 53 1. https://raw.githubusercontent.com/makehero/lndr_wordpress/master/screenshot1.png53 1. screenshot1.png 54 54 55 55 == Changelog == 56 56 57 57 1.0 Fully working version 58 1.1 Added instant publishing feature 58 59 59 60 == Upgrade notice == -
lndr-page-builder/trunk/includes/class-lndr-activator.php
r1767069 r1768535 23 23 class Lndr_Activator { 24 24 /** 25 * Short Description. (use period) 25 * Plugin installation 26 * perform installation task when the plugin is activated. 26 27 * 27 * Long Description. 28 * 29 * @since 1.0.0 28 * @since 1.0 30 29 */ 31 30 public function activate() { 31 global $lndr_version; 32 add_option('lndr_version', $lndr_version); 32 33 flush_rewrite_rules(); 33 34 wp_schedule_event(time(), 'two_minutes', 'lndr_cron'); -
lndr-page-builder/trunk/includes/class-lndr-deactivator.php
r1767069 r1768535 31 31 */ 32 32 public static function deactivate() { 33 34 delete_option('lndr_version'); 35 33 36 flush_rewrite_rules(); 34 37 $timestamp = wp_next_scheduled( 'lndr_cron' ); -
lndr-page-builder/trunk/includes/class-lndr.php
r1767069 r1768535 70 70 71 71 $this->plugin_name = 'Lndr'; 72 $this->version = '1. 0.0';72 $this->version = '1.1'; 73 73 74 74 $this->load_dependencies(); -
lndr-page-builder/trunk/lndr.php
r1767069 r1768535 4 4 Description: This plugin allows you to publish pages from Lndr to Wordpress websites directly. 5 5 Author: Incc.io 6 Version: 1. 07 Author URI: http:// alpha.makehero.co6 Version: 1.1 7 Author URI: http://www.lndr.co 8 8 */ 9 9 … … 24 24 */ 25 25 26 global $lndr_version; 27 $lndr_version = '1.1'; 28 26 29 /** 27 30 * The code that runs during plugin activation. … … 33 36 lndr_rewrite_api_route(); 34 37 $activator->activate(); 35 // lndr_custom_post_type();36 38 } 39 40 /** 41 * check for Lndr version and perform updates accordingly 42 */ 43 function lndr_update_check() { 44 global $lndr_version; 45 if (get_site_option('lndr_version') != $lndr_version) { 46 // update for specific versions 47 if ($lndr_version == '1.1') { 48 // we had added a new service path for manual sync, however, there's no need to do anything 49 // as it is automatically added 50 } 51 update_option( "lndr_version", $lndr_version ); 52 } 53 } 54 add_action( 'plugins_loaded', 'lndr_update_check' ); 37 55 38 56 add_filter( 'cron_schedules', 'lndr_custom_cron_schedule' ); -
lndr-page-builder/trunk/public/class-lndr-public.php
r1767069 r1768535 88 88 )); 89 89 90 // This is an internal service for us to manually sync contents 91 register_rest_route('service/lndr', 'lndr_sync', array( 92 'methods' => 'GET', 93 'callback' => array(&$this, 'lndr_sync'), 94 )); 90 95 } 91 96 … … 173 178 } 174 179 175 // Create a new unpublished page180 // Create a new published page and set special meta to "reserved" 176 181 $new_post = [ 177 182 'post_title' => $path . ' | Lndr', 178 183 'post_type' => 'page', 179 184 'post_content' => '', 180 'post_status' => ' draft',185 'post_status' => 'publish', 181 186 'post_name' => $path, 187 'meta_input' => [ 188 'lndr_project_id' => "reserved", 189 ], 182 190 ]; 183 191 $post_saved = wp_insert_post($new_post, true); … … 223 231 ); 224 232 return json_encode($response); 225 233 } 234 235 public function lndr_sync(WP_REST_Request $request) { 236 $base_url = home_url(); 237 $this->sync_posts(); 238 $page_id = $request->get_param('post_id'); 239 if (isset($page_id)) { 240 // let's see if the page now has a meta data association 241 $lndr_project_id = get_post_meta($page_id, 'lndr_project_id', true); 242 // the lndr project id is no longer "reserved" 243 if (is_numeric($lndr_project_id)) { 244 wp_safe_redirect($base_url . '/' . '?p=' . $page_id); 245 exit; 246 } 247 // otherwise for safety let's redirect back to home page 248 wp_safe_redirect($base_url); 249 exit; 250 } 251 else { 252 wp_safe_redirect($base_url); 253 exit; 254 } 226 255 } 227 256 … … 387 416 $existing_post_by_alias = $this->get_post_by_path($path); 388 417 if (isset($existing_post_by_alias)) { 389 // case 1. this post was created (reserved) for this page, however it unpublished, let's just update it 390 if ($existing_post_by_alias->post_status != 'publish') { 391 $update_post = [ 392 'ID' => $existing_post_by_alias->ID, 393 'post_status' => 'publish', 394 ]; 395 // Update the post into the database 396 // @todo: catch error? 397 wp_update_post( $update_post ); 398 // create a new postmeta 399 add_post_meta($existing_post_by_alias->ID, 'lndr_project_id', $page['id'], true); 418 // case 1. this post was created (reserved) for this page, however it is unpublished, let's just update it 419 $lndr_project_id = get_post_meta($existing_post_by_alias->ID, 'lndr_project_id', true); 420 if ($lndr_project_id == 'reserved') { 421 // update the new post meta 422 update_post_meta($existing_post_by_alias->ID, 'lndr_project_id', $page['id']); 400 423 } 401 424 } … … 408 431 if (substr($page['publish_url'], 0, strlen($base_url)) == $base_url) { 409 432 // $lndr_path = ltrim(substr($page['publish_url'], strlen($base_url)), '/'); 433 // we simply update the post name and the path/slug will be updated 410 434 if ($path != $existing_post_by_project_id->post_name) { 411 435 $update_post = [ … … 503 527 { 504 528 // For multiple post, we attach the post meta 505 // @todo: this is not most efficientright now529 // @todo: this is not the most efficient method right now 506 530 foreach ($posts as $post) { 507 531 $lndr_project_id = get_post_meta($post->ID, 'lndr_project_id', true); 508 $data[$post->ID] = $lndr_project_id; 532 // We exclude posts that have a lndr_project_id = reserved 533 // so they don't get deleted through the sync 534 if ($lndr_project_id != 'reserved') { 535 $data[$post->ID] = $lndr_project_id; 536 } 509 537 } 510 538 return $data; -
lndr-page-builder/trunk/public/lndr-page-template.php
r1767069 r1768535 10 10 // Get current post id 11 11 $lndr_project_id = get_post_meta($post->ID, 'lndr_project_id', true); 12 $url = LNDR_BASE . 'projects/' . $lndr_project_id;13 12 14 $response = wp_remote_get($url); 15 if ($response['response']['code'] == '200') { 16 require_once plugin_dir_path( __FILE__ ) . 'simple_html_dom.inc'; 17 $body = wp_remote_retrieve_body($response); 18 $html = str_get_html($body); 19 // Because we are issuing redirect 20 $http_response = $response['http_response']->get_response_object(); 21 $uri = $http_response->url; 22 $html = lndr_parse_page($html, $uri); 23 print $html; 24 } else { 25 // Render some type of Wordpress 404 26 global $wp_query; 27 $wp_query->set_404(); 28 status_header(404); 13 // If we simply reserved the page, let's manually trigger a sync to process it 14 if ($lndr_project_id == 'reserved') { 15 // When user visits a page that has a lndr_project_id of reserved, 16 // we send them to a manual processing page, after processing, if the page is published 17 // they will be redirected back and page will be shown 18 $base_url = home_url(); 19 wp_safe_redirect($base_url . '/service/lndr/lndr_sync?post_id=' . $post->ID); 20 } 21 else { 22 $url = LNDR_BASE . 'projects/' . $lndr_project_id; 23 24 $response = wp_remote_get($url); 25 if ($response['response']['code'] == '200') { 26 require_once plugin_dir_path( __FILE__ ) . 'simple_html_dom.inc'; 27 $body = wp_remote_retrieve_body($response); 28 $html = str_get_html($body); 29 // Because we are issuing redirect 30 $http_response = $response['http_response']->get_response_object(); 31 $uri = $http_response->url; 32 $html = lndr_parse_page($html, $uri); 33 print $html; 34 } else { 35 // Render some type of Wordpress 404 36 global $wp_query; 37 $wp_query->set_404(); 38 status_header(404); 39 } 29 40 } 30 41 }
Note: See TracChangeset
for help on using the changeset viewer.