private function InstapageCmsPluginAjaxController::getLandingPages in Instapage plugin 8.3
Same name and namespace in other branches
- 7.3 core/InstapageCmsPluginAjaxController.php \InstapageCmsPluginAjaxController::getLandingPages()
Gets the landing pages stored in the DB.
1 call to InstapageCmsPluginAjaxController::getLandingPages()
- InstapageCmsPluginAjaxController::doAction in core/
InstapageCmsPluginAjaxController.php - Executes an action set in the request.
File
- core/
InstapageCmsPluginAjaxController.php, line 364
Class
- InstapageCmsPluginAjaxController
- Main controller for AJAX actions. Results are returned as encoded JSON objects. Data for actions are stored in $_POST['data'] table.
Code
private function getLandingPages() {
$api = InstapageCmsPluginAPIModel::getInstance();
$post = InstapageCmsPluginHelper::getPostData();
$tokens = array(
$post->data->subAccountToken,
);
$headers = array(
'accountkeys' => InstapageCmsPluginHelper::getAuthHeader($tokens),
);
$responseJson = $api
->apiCall('page/list', null, $headers);
$response = json_decode($responseJson);
$page = InstapageCmsPluginPageModel::getInstance();
$publishedPages = $page
->getAll(array(
'instapage_id',
));
$selfInstapageId = isset($post->data->selfInstapageId) ? $post->data->selfInstapageId : null;
if (InstapageCmsPluginHelper::checkResponse($response)) {
if (is_array($response->data)) {
foreach ($response->data as $key => $returnedPage) {
foreach ($publishedPages as $published_page) {
if ($returnedPage->id != $selfInstapageId && $returnedPage->id == $published_page->instapage_id) {
unset($response->data[$key]);
break;
}
}
}
$response->data = array_values($response->data);
}
else {
$response->data = array();
}
echo json_encode((object) array(
'status' => 'OK',
'data' => $response->data,
));
}
else {
return false;
}
}