<?php
  // calendar_contenteditable.php
  // Help out calendar_contenteditable.html
  if (isset($_POST['tihis'])) {
    file_put_contents('tihis.txt', str_replace('+',' ',urldecode($_POST['tihis'])));
    exit;
  } else if (file_exists('tihis.txt')) {
    $newih=file_get_contents('tihis.txt');
    unlink('tihis.txt');
    if (strpos($newih, '<cap' . 'tion ') !== false) {
      $usualis=file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'calendar_contenteditable.html');
      $bittochange='<cap' . 'tion ' . explode('</table>', explode('<cap' . 'tion ', $usualis)[-1 + sizeof(explode('<cap' . 'tion ', $usualis))])[0];
      echo str_replace($bittochange, $newih, $usualis);
      exit;
    } else {
      header('Location: /calendar_contenteditable.html');
      exit;
    }
  } else {
    header('Location: /calendar_contenteditable.html');
    exit;
  }
?>
