<?php
  // calendar_contenteditable.php
  // Help out calendar_contenteditable.html
  if (isset($_POST['tihis'])) {
    if (isset($_POST['ticpc'])) {
    if (strpos(str_replace('+',' ',urldecode($_POST['ticpc'])) . '~$#', '.cpc~$#') !== false && strpos('~$#' . str_replace('+',' ',urldecode($_POST['ticpc'])), '~$#tmp' . DIRECTORY_SEPARATOR) !== false) {
    //file_put_contents('zx.zx9','' . str_replace('+',' ',urldecode($_POST['ticpc'])));
    file_put_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . str_replace('+',' ',urldecode($_POST['ticpc'])), str_replace('+',' ',urldecode($_POST['tihis'])));
    }
    } else {
    file_put_contents('tihis.txt', str_replace('+',' ',urldecode($_POST['tihis'])));
    }
    exit;
  } else if (isset($_GET['tihis'])) {
   if (strpos(str_replace('+',' ',urldecode($_GET['tihis'])) . '~$#', '.cpc~$#') !== false && strpos('~$#' . str_replace('+',' ',urldecode($_GET['tihis'])), '~$#tmp' . DIRECTORY_SEPARATOR) !== false) {
   if (file_exists(str_replace('+',' ',urldecode($_GET['tihis'])))) {
    $newih=file_get_contents(str_replace('+',' ',urldecode($_GET['tihis'])));
    if (trim($newih) == $newih) {
    file_put_contents(str_replace('+',' ',urldecode($_GET['tihis'])),    file_get_contents(str_replace('+',' ',urldecode($_GET['tihis']))) . ' '  );
    } else if (3 == 4) {
    unlink(str_replace('+',' ',urldecode($_GET['tihis'])));
    }
    if (strpos($newih, '<cap' . 'tion ') !== false) {
      if (strpos($newih, '<cap' . 'tion data-durl="') !== false) {
      $usualis=file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . basename(explode('"',explode('<cap' . 'tion data-durl="', $newih)[1])[0]));
      } else {
      $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;
   }
   } else {
    header('Location: /calendar_contenteditable.html');
    exit;
   }
  } else if (file_exists('tihis.txt')) {
    $newih=file_get_contents('tihis.txt');
    unlink('tihis.txt');
    if (strpos($newih, '<cap' . 'tion ') !== false) {
      if (strpos($newih, '<cap' . 'tion data-durl="') !== false) {
      $usualis=file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . basename(explode('"',explode('<cap' . 'tion data-durl="', $newih)[1])[0]));
      } else {
      $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;
  }
?>
