if (!defined('srkVersion')) { exit(403); } require_once $srkEnv->appPath . '/modules/render.php'; require_once $srkEnv->appPath . '/modules/file.php'; require_once $srkEnv->appPath . '/modules/pen.php'; require_once $srkEnv->appPath . '/modules/like.php'; if ($srkEnv->reqURLLength >= 2) { if ($srkEnv->reqURL[2] == 'query' && $srkEnv->reqMethod == 'POST') { if ($srkEnv->reqURLLength == 3) { if ($srkEnv->reqURL[3] == 'catalog') { $penList = penListGet(); $catalog = array(); foreach ($penList as $content) { if (matchFilter(json_decode(fixJSONString($_POST['filter'])), $content)) { array_push($catalog, $content); } } srkSend(array('catalog' => $catalog)); } } elseif ($srkEnv->reqURLLength == 4) { $penId = $srkEnv->reqURL[4]; if (!is_dir($srkEnv->penPath . '/' . $penId)) { srkSend(array('error' => 'No such pen')); } elseif ($srkEnv->reqURL[3] == 'content') { $content = getFileContent($srkEnv->penPath . '/' . $penId . '/content.md'); if ($content === -1) { $content = 'No pen content'; } srkSend(array('content' => $content));
} srkSend((object) array('error' => false, 'accessList' => $res)); } else { srkSend((object) array('error' => 'Access denied')); } } } elseif ($srkEnv->reqURL[2] == 'pen') { if (!in_array('pen', $user->getField("accessList"))) { srkSend((object) array('error' => 'Access denied')); } elseif ($srkEnv->reqURLLength == 3 && $srkEnv->reqURL[3] == 'update') { $penId = $_POST['penId']; $penPath = $srkEnv->penPath . '/pen/' . $penId; $reqFileName = false; $reqText = false; $content = $_POST['content']; $configStr = fixJSONString($_POST['config']); $config = json_decode($configStr); if (!isset($_POST['config'])) { $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)) {