Skip to content

Instantly share code, notes, and snippets.

@jkishner
Created August 21, 2012 16:21
Show Gist options
  • Save jkishner/3416990 to your computer and use it in GitHub Desktop.
Save jkishner/3416990 to your computer and use it in GitHub Desktop.
php app to convert journal entry from form into URL that launches Day One iPhone app and enters journal entry
<html>
<head></head>
<body>
<?php
/* if the "submit" variable does not exist, the form has not been submitted - display initial page */
if (!isset($_POST['submit'])) {
?>
<h1>DayOne Entry Form</h1>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input name="email" size="30">
<textarea name="dayone" cols="40" rows="5"></textarea>
<input type="submit" name="submit" value="Go">
</form>
<?php
}
else
/* if the "submit" variable exists, the form has been submitted - look for and process form data */
// display result
{
$dayone = $_POST['dayone'];
$email = $_POST['email'];
$dayone = rawurlencode($dayone); // turns spaces into %20
$dayone_copy = str_replace("%5C","",$dayone); // remove slashes before apostrophes
echo 'dayone://post?entry=' . $dayone_copy; // print it out for copy and paste with mouse
$dayone_new = str_replace("%","%25",$dayone_copy); // turns % to ascii hx code %25 so it will show in email body http://www.asciitable.com/
echo '<br><br>';
echo '<a href="dayone://post?entry=' . $dayone_copy . '">Copy this link.</a> Paste it into the body of an email to yourself. Open the email on your iPhone and tap on the link. It will enter your journal entry into DayOne.';
echo '<br><br>';
echo '<a href="mailto:' . $email . '?Subject=Day%20One&Body=dayone://post%3Fentry='. $dayone_new . '">Email to yourself</a>'; // turns ? to ascii hx code %3F so it will show in email body http://www.asciitable.com/
}
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment