Plugin Directory

Changeset 1768535


Ignore:
Timestamp:
11/16/2017 05:28:41 PM (8 years ago)
Author:
xcf33
Message:

1.1 release code

Location:
lndr-page-builder/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • lndr-page-builder/trunk/README.txt

    r1767069 r1768535  
    55Requires at least: 4.7
    66Tested up to: 4.8
    7 Stable tag: 1.0
     7Stable tag: 1.1
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    5151== Screenshots ==
    5252
    53 1. https://raw.githubusercontent.com/makehero/lndr_wordpress/master/screenshot1.png
     531. screenshot1.png
    5454
    5555== Changelog ==
    5656
    57571.0 Fully working version
     581.1 Added instant publishing feature
    5859
    5960== Upgrade notice ==
  • lndr-page-builder/trunk/includes/class-lndr-activator.php

    r1767069 r1768535  
    2323class Lndr_Activator {
    2424    /**
    25      * Short Description. (use period)
     25     * Plugin installation
     26     * perform installation task when the plugin is activated.
    2627     *
    27      * Long Description.
    28      *
    29      * @since    1.0.0
     28     * @since    1.0
    3029     */
    3130    public function activate() {
     31    global $lndr_version;
     32    add_option('lndr_version', $lndr_version);
    3233    flush_rewrite_rules();
    3334    wp_schedule_event(time(), 'two_minutes', 'lndr_cron');
  • lndr-page-builder/trunk/includes/class-lndr-deactivator.php

    r1767069 r1768535  
    3131     */
    3232    public static function deactivate() {
     33
     34    delete_option('lndr_version');
     35
    3336    flush_rewrite_rules();
    3437    $timestamp = wp_next_scheduled( 'lndr_cron' );
  • lndr-page-builder/trunk/includes/class-lndr.php

    r1767069 r1768535  
    7070
    7171        $this->plugin_name = 'Lndr';
    72         $this->version = '1.0.0';
     72        $this->version = '1.1';
    7373
    7474        $this->load_dependencies();
  • lndr-page-builder/trunk/lndr.php

    r1767069 r1768535  
    44Description: This plugin allows you to publish pages from Lndr to Wordpress websites directly.
    55Author: Incc.io
    6 Version: 1.0
    7 Author URI: http://alpha.makehero.co
     6Version: 1.1
     7Author URI: http://www.lndr.co
    88*/
    99
     
    2424*/
    2525
     26global $lndr_version;
     27$lndr_version = '1.1';
     28
    2629/**
    2730 * The code that runs during plugin activation.
     
    3336  lndr_rewrite_api_route();
    3437  $activator->activate();
    35   // lndr_custom_post_type();
    3638}
     39
     40/**
     41 * check for Lndr version and perform updates accordingly
     42 */
     43function 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}
     54add_action( 'plugins_loaded', 'lndr_update_check' );
    3755
    3856add_filter( 'cron_schedules', 'lndr_custom_cron_schedule' );
  • lndr-page-builder/trunk/public/class-lndr-public.php

    r1767069 r1768535  
    8888    ));
    8989
     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    ));
    9095  }
    9196
     
    173178    }
    174179
    175     // Create a new unpublished page
     180    // Create a new published page and set special meta to "reserved"
    176181    $new_post = [
    177182      'post_title' => $path . ' | Lndr',
    178183      'post_type' => 'page',
    179184      'post_content' => '',
    180       'post_status' => 'draft',
     185      'post_status' => 'publish',
    181186      'post_name' => $path,
     187      'meta_input' => [
     188        'lndr_project_id' => "reserved",
     189      ],
    182190    ];
    183191    $post_saved = wp_insert_post($new_post, true);
     
    223231    );
    224232    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    }
    226255  }
    227256
     
    387416      $existing_post_by_alias = $this->get_post_by_path($path);
    388417      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']);
    400423        }
    401424      }
     
    408431          if (substr($page['publish_url'], 0, strlen($base_url)) == $base_url) {
    409432            // $lndr_path = ltrim(substr($page['publish_url'], strlen($base_url)), '/');
     433            // we simply update the post name and the path/slug will be updated
    410434            if ($path != $existing_post_by_project_id->post_name) {
    411435              $update_post = [
     
    503527    {
    504528      // For multiple post, we attach the post meta
    505       // @todo: this is not most efficient right now
     529      // @todo: this is not the most efficient method right now
    506530      foreach ($posts as $post) {
    507531        $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        }
    509537      }
    510538      return $data;
  • lndr-page-builder/trunk/public/lndr-page-template.php

    r1767069 r1768535  
    1010  // Get current post id
    1111  $lndr_project_id = get_post_meta($post->ID, 'lndr_project_id', true);
    12   $url = LNDR_BASE . 'projects/' . $lndr_project_id;
    1312
    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    }
    2940  }
    3041}
Note: See TracChangeset for help on using the changeset viewer.