Initial code drop
This commit is contained in:
48
front/front.php
Normal file
48
front/front.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
add_shortcode('mvp', 'mvp_content');
|
||||
|
||||
function mvp_content() {
|
||||
|
||||
$settings = get_option('mvp_settings');
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $settings['url'] . "/oauth/token");
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
||||
curl_setopt($ch, CURLOPT_HEADER, FALSE);
|
||||
|
||||
curl_setopt($ch, CURLOPT_POST, TRUE);
|
||||
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, 'client_id=' . $settings['client_id'] . '&grant_type=password&username=' . $settings['username'] . '&password=' . $settings['password']);
|
||||
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
||||
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
||||
"Content-Type: application/x-www-form-urlencoded"
|
||||
));
|
||||
|
||||
$response = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
$config = json_decode($response);
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $settings['url'] . "/packages?start_date=" . date("Y-m-d", strtotime('-1 days')));
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
||||
|
||||
$headers = array('Authorization: ' . $config->token_type . ' ' . $config->access_token);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
if ($response) {
|
||||
require_once MVP_PLUGIN_DIR . '/front/wrapper.php';
|
||||
|
||||
$content = mvp_view($response);
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
19
front/wrapper.php
Normal file
19
front/wrapper.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
function mvp_view($data) {
|
||||
if (!empty($data)) {
|
||||
$tmp = json_decode($data);
|
||||
|
||||
foreach ($tmp->_items as $article) {
|
||||
if ($article->pubstatus == "usable") {
|
||||
?>
|
||||
<div class="article">
|
||||
<h2><?php echo $article->headline ?></h2>
|
||||
<?php echo $article->body_html; ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user