private function write() { if ($this->status == 'normal') { return takeDownJSON($this->fileName, $this->data); } else { return 'Like writing error'; } }
public function update($data) { global $srkEnv; if ($data['passwd'] != $data['repeatPasswd']) { return (object) array('res' => 'Passwords do not match', 'field' => 'passwd'); } $authRes = $this->authenticate($data['prevPasswd']); if ($authRes) { return (object) array('res' => $authRes, 'field' => 'prevPasswd'); } $prevEmail = $this->data->email; if ($data['email'] !== $this->data->email) { if (is_file(self::getEmailFileName($data['email']))) { return (object) array('res' => 'Email exists', 'field' => 'email'); } } foreach (self::$allowUpdateList as $field) { if (isset($data[$field]) && strlen($data[$field]) > 0) { if (!preg_match(self::$matchExp[$field], $data[$field])) { $errText = 'Invalid ' . $key . '(regular exp: ' . self::$matchExp[$field] . ')'; return (object) array('res' => $errText, 'field' => $field); } else { $this->data->{$field} = $data[$field]; } } } if ($prevEmail != $this->data->email) { unlink($this->getEmailFileName($prevEmail)); $emailFileName = $this->getMyEmailFileName(); if ($emailFileName !== false) { takeDownJSON($emailFileName, (object) array('owner' => $this->id)); } } $writeRes = $this->writeUser(); if ($writeRes) { return (object) array('res' => $writeRes); } else { return (object) array('res' => 'success'); } }
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); } }
$inviteObj->value = $inviteCode; array_push($res, $inviteObj); } } srkSend((object) array('list' => $res)); } elseif ($srkEnv->reqURLLength == 4 && $srkEnv->reqURL[3] == 'generate') { $count = (int) $srkEnv->reqURL[4]; $defInfo = (object) array('used' => false); if ($count > 0 && $count < 16) { for ($i = 0; $i < $count; ++$i) { $code = ''; do { $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'));
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; }