Skip to content

Instantly share code, notes, and snippets.

@brendandawes brendandawes/ifttt.php
Last active Mar 24, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.