function maybeAddRedir($file_id, $url) { try { $file_redir = File_redirection::getByUrl($url); } catch (NoResultException $e) { $file_redir = new File_redirection(); $file_redir->urlhash = File::hashurl($url); $file_redir->url = $url; $file_redir->file_id = $file_id; $result = $file_redir->insert(); if ($result === false) { common_log_db_error($file_redir, "INSERT", __FILE__); // TRANS: Client exception thrown when a database error was thrown during a file upload operation. throw new ClientException(_('There was a database error while saving your file. Please try again.')); } } }
/** * Store the full-length scrubbed HTML of a remote notice to an attachment * file on our server. We'll link to this at the end of the cropped version. * * @param string $title plaintext for HTML page's title * @param string $rendered HTML fragment for HTML page's body * @return File */ function saveHTMLFile($title, $rendered) { $final = sprintf("<!DOCTYPE html>\n" . '<html><head>' . '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">' . '<title>%s</title>' . '</head>' . '<body>%s</body></html>', htmlspecialchars($title), $rendered); $filename = File::filename($this->localProfile(), 'ostatus', 'text/html'); $filepath = File::path($filename); $fileurl = File::url($filename); file_put_contents($filepath, $final); $file = new File(); $file->filename = $filename; $file->urlhash = File::hashurl($fileurl); $file->url = $fileurl; $file->size = filesize($filepath); $file->date = time(); $file->mimetype = 'text/html'; $file_id = $file->insert(); if ($file_id === false) { common_log_db_error($file, "INSERT", __FILE__); // TRANS: Server exception. throw new ServerException(_m('Could not store HTML content of long post as file.')); } return $file; }
static function saveNew($data, $file_id, $url) { $file_redir = new File_redirection(); $file_redir->urlhash = File::hashurl($url); $file_redir->url = $url; $file_redir->file_id = $file_id; $file_redir->redirections = intval($data['redirects']); $file_redir->httpcode = intval($data['code']); $file_redir->insert(); }