/** * @method POST */ function update() { // get token $token = Utilities::ValidateJWTToken(apache_request_headers()); // check if token is not null if ($token != NULL) { parse_str($this->request->data, $request); // parse request $name = $request['name']; $content = $request['content']; $site = Site::GetBySiteId($token->SiteId); $directory = SITES_LOCATION . '/' . $site['FriendlyId'] . '/themes/' . $site['Theme'] . '/styles/'; $f = $directory . $name . '.less'; file_put_contents($f, $content); // save to file $errors = Publish::GetLESSErrors($site, $name); if ($errors == NULL) { // publishes all css Publish::PublishAllCSS($site['SiteId']); // send success $response = new Tonic\Response(Tonic\Response::OK); $response->contentType = 'text/HTML'; $response->body = 'yay!'; } else { // send errors $response = new Tonic\Response(Tonic\Response::BADREQUEST); $response->contentType = 'text/HTML'; $response->body = $errors; } return $response; } else { // return an unauthorized exception (401) return new Tonic\Response(Tonic\Response::UNAUTHORIZED); } }