Skip to content

Instantly share code, notes, and snippets.

@brendandawes
Last active March 24, 2018 17:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brendandawes/3a3f07b15d307c8282e6a1eec3def4fd to your computer and use it in GitHub Desktop.
Save brendandawes/3a3f07b15d307c8282e6a1eec3def4fd to your computer and use it in GitHub Desktop.
Script for use with IFTTT to automate making Kirby blog posts from Instagram
<?php
require($_SERVER['DOCUMENT_ROOT'] . '/kirby/bootstrap.php');
// Path to a configuration file outside of a web accesible directory containing your secret pass phrase and salt.
include '/Path/To/Your/conf.inc';
if(get('id').$SALT==$IFTTT_PASS.$SALT) {
$articles = page('blog')->children();
$sort = ($articles->count() + 1);
$date = date('Y-m-d H:i:s');
$dirname = $date . '-' . $sort;
$text = stripslashes(get('params'));
$caption = urldecode( get('caption'));
$titleIndex = strpos($caption,'.');
$title = "";
if ($titleIndex === false){
$title = $caption;
$caption = "";
}else {
$title = substr($caption,0,$titleIndex);
$caption = substr($caption,$titleIndex+2);
}
$text .= '<p></p>'.$caption;
$content = array('title' => $title, 'date' => $date, 'text' => $text,'blogid' => $sort, 'tags' => 'Process');
$article = $articles->create($dirname, 'article',$content);
// Download image
downloadImage(get('thumbnail'),$_SERVER['DOCUMENT_ROOT'].'/content/05-blog/'.$article->dirname().'/thumbnail.jpg'
);
} else {
echo('ID NOT VALID');
}
function downloadImage($image_url, $image_file){
$fp = fopen ($image_file, 'w+');
$ch = curl_init($image_url);
// curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_TIMEOUT, 1000);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0');
// curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_exec($ch);
curl_close($ch);
fclose($fp);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment