You are here

public function InstapageCmsPluginWPConnector::getDeprecatedData in Instapage plugin 8.3

Same name and namespace in other branches
  1. 7.3 core/connectors/InstapageCmsPluginWPConnector.php \InstapageCmsPluginWPConnector::getDeprecatedData()

Gets the landing pages saved in legacy DB structure.

Return value

array List of landing pages from legacy DB structure.

File

core/connectors/InstapageCmsPluginWPConnector.php, line 765

Class

InstapageCmsPluginWPConnector
Class that utilizes native WordPress functions to perform actions like remote requests and DB operations.

Code

public function getDeprecatedData() {
  global $wpdb;
  $sql = "SELECT {$wpdb->posts}.ID, {$wpdb->postmeta}.meta_key, {$wpdb->postmeta}.meta_value FROM {$wpdb->posts} INNER JOIN {$wpdb->postmeta} ON ({$wpdb->posts}.ID = {$wpdb->postmeta}.post_id) WHERE ({$wpdb->posts}.post_type = %s) AND ({$wpdb->posts}.post_status = 'publish') AND ({$wpdb->postmeta}.meta_key IN ('instapage_my_selected_page', 'instapage_name', 'instapage_my_selected_page', 'instapage_slug'))";
  $rows = $this
    ->getResults($sql, 'instapage_post');
  $posts = array();
  foreach ($rows as $row) {
    if (!array_key_exists($row->ID, $posts)) {
      $posts[$row->ID] = array();
    }
    $posts[$row->ID][$row->meta_key] = $row->meta_value;
  }
  $results = array();
  foreach ($posts as $post) {
    $pageObj = new stdClass();
    $pageObj->id = 0;
    $pageObj->landingPageId = $post['instapage_my_selected_page'];
    $pageObj->slug = $post['instapage_slug'];
    $pageObj->type = 'page';
    $pageObj->enterprise_url = $pageObj->slug ? InstapageCmsPluginConnector::getHomeURL() . '/' . $pageObj->slug : InstapageCmsPluginConnector::getHomeURL();
    $results[] = $pageObj;
  }
  $frontPageId = get_option('instapage_front_page_id', false);
  if ($frontPageId) {
    $pageObj = new stdClass();
    $pageObj->id = 0;
    $pageObj->landingPageId = $frontPageId;
    $pageObj->slug = '';
    $pageObj->type = 'home';
    $pageObj->enterprise_url = InstapageCmsPluginConnector::getHomeURL();
    $results[] = $pageObj;
  }
  $notFoundId = get_option('instapage_404_page_id', false);
  if ($notFoundId) {
    $page = InstapageCmsPluginPageModel::getInstance();
    $pageObj = new stdClass();
    $pageObj->id = 0;
    $pageObj->landingPageId = $notFoundId;
    $pageObj->slug = $page
      ->getRandomSlug();
    $pageObj->type = '404';
    $pageObj->enterprise_url = InstapageCmsPluginConnector::getHomeURL() . '/' . $pageObj->slug;
    $results[] = $pageObj;
  }
  return $results;
}