Skip to content

Instantly share code, notes, and snippets.

@renekorss
Created July 5, 2016 13:33
Show Gist options
  • Save renekorss/379edcfb40cd54d7155ce868f16359a8 to your computer and use it in GitHub Desktop.
Save renekorss/379edcfb40cd54d7155ce868f16359a8 to your computer and use it in GitHub Desktop.
Publish all Voog articles
<?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