public function write($data) { global $srkEnv; if (!is_dir($srkEnv->cachePath)) { mkdir($srkEnv->cachePath); } return takeDownString($this->fileName, $data); }
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); } }
$code = randId(16); } while (is_file($srkEnv->userPath . '/invite_' . $code . '.json')); $codeFileName = $srkEnv->userPath . '/invite_' . $code . '.json'; takeDownJSON($codeFileName, $defInfo); } } srkSend((object) array('res' => 'Done')); } } elseif ($srkEnv->reqURL[2] == 'file') { if (!in_array('file', $user->getField("accessList"))) { srkSend((object) array('error' => 'Access denied')); } elseif ($srkEnv->reqURLLength == 3 && $srkEnv->reqURL[3] == 'upload') { $fileName = $_POST['fileName']; $fileContent = uploadFileContentDecipher(); if ($fileName && $fileContent) { $writeRes = takeDownString($fileName, $fileContent); srkSend((object) array('error' => $writeRes)); } else { srkSend((object) array('error' => 'Content error')); } } elseif ($srkEnv->reqURLLength == 3 && $srkEnv->reqURL[3] == 'hash') { $fileName = $_POST['fileName']; if ($fileName && is_file($fileName)) { srkSend((object) array('md5' => md5_file($fileName))); } elseif ($fileName && !is_file($fileName)) { srkSend((object) array('md5' => '')); } else { srkSend((object) array('error' => 'File error')); } } elseif ($srkEnv->reqURLLength == 3 && $srkEnv->reqURL[3] == 'log') { srkStream($srkEnv->logFileName);
function commentPost($user) { global $srkEnv; if (strlen($_POST['content']) > 140) { return 'Too long'; } elseif (!is_string($_POST['content']) || strlen($_POST['content']) < 2) { return 'Invalid comment'; } $penCommentPath = $srkEnv->penPath . '/' . $_POST['penId'] . '/comment'; if (!is_dir($penCommentPath)) { mkdir($penCommentPath); } $commentId = ''; do { $commentId = randId(8); } while (is_dir($penCommentPath . '/' . $commentId)); $commentPath = $penCommentPath . '/' . $commentId; mkdir($commentPath); takeDownString($commentPath . '/content.html', $_POST['content']); $config = (object) array('commentId' => $commentId, 'owner' => $user->getField('userId'), 'modifyTime' => time()); takeDownJSON($commentPath . '/config.json', $config); commentListGenerate(); return false; }