function penUpdate($penId, $penConfig, $penContent) { global $srkEnv; $penPath = $srkEnv->penPath . '/' . $penId; $err = false; $res = ''; if (!is_dir($penPath)) { mkdir($penPath); } if ($penConfig) { $penConfig->penId = $penId; if (!isset($penConfig->title)) { $penConfig->title = $penId; } if (!isset($penConfig->modifyTime)) { $penConfig->modifyTime = time(); } if (takeDownJSON($penPath . '/config.json', $penConfig)) { $err = true; $res .= 'Failed to write config file '; } else { $res .= 'Config file updated '; } } if ($penContent) { if (takeDownString($penPath . '/content.md', $penContent)) { $err = true; $res .= 'Failed to write content file '; } else { $res .= 'Content file updated '; } } penListGenerate(); if ($err) { return (object) array('error' => $res, 'res' => 'error'); } else { return (object) array('error' => $err, 'res' => $res); } }
$config = false; } elseif ($config === null) { srkSend((object) array('error' => 'Illegal config file ')); } if ($config) { $config->author = $_SESSION['userId']; } $updRes = penUpdate($penId, $config, $content); srkSend($updRes); } elseif ($srkEnv->reqURL[3] == 'remove') { $penId = $_POST['penId']; $penPath = $srkEnv->penPath . "/" . $penId; if (is_dir($penPath)) { srkLog($penPath); rmdirDFS($penPath); penListGenerate(); srkSend((object) array('error' => false)); } else { srkSend((object) array('error' => 'No such pen')); } } elseif ($srkEnv->reqURLLength == 4 && $srkEnv->reqURL[3] == 'content') { $penId = $srkEnv->reqURL[4]; $penPath = $srkEnv->penPath . '/' . $penId; $res = (object) array(); $res->content = getFileContent($penPath . '/content.md'); if ($res->content == -1) { $res->content = ''; } $res->config = getFileContent($penPath . '/config.json'); if ($res->config == -1) { $res->config = json_encode($srkContent->defaultPenConfig);