Created
July 5, 2016 13:33
-
-
Save renekorss/379edcfb40cd54d7155ce868f16359a8 to your computer and use it in GitHub Desktop.
Publish all Voog articles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
const HOST = 'HOST.voog.com'; | |
const TOKEN = 'MY_TOKEN'; | |
// Get first 250 articles | |
$articles = curlRequest('articles?per_page=250'); | |
foreach ($articles as $article) | |
{ | |
$newData = array( | |
'published' => true | |
); | |
// Publish article if not yet published | |
if(!$article->published) | |
{ | |
$article = curlRequest('articles/'.$article->id, 'PATCH', $newData); | |
} | |
} | |
// Method to get JSON from Voog API | |
function curlRequest($url, $method = 'GET', $data = null) | |
{ | |
// Init curl | |
$ch = curl_init(); | |
$url = 'http://'.HOST.'/admin/api/'.$url; | |
// Add token to URL | |
if(strpos($url, '?') !== false){ | |
$url .= '&api_token='.TOKEN; | |
} | |
else{ | |
$url .= '?api_token='.TOKEN; | |
} | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
if($data) | |
{ | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json')); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); | |
} | |
$result = curl_exec($ch); | |
curl_close($ch); | |
// Return JSON | |
return json_decode($result); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment