Edit File by line
/home/zeestwma/ajeebong.../wp-conte.../plugins/code-sni.../php/export
File: class-export-attachment.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Code_Snippets;
[2] Fix | Delete
[3] Fix | Delete
/**
[4] Fix | Delete
* Handles exporting snippets from the site to a downloadable file over HTTP.
[5] Fix | Delete
*
[6] Fix | Delete
* @package Code_Snippets
[7] Fix | Delete
*/
[8] Fix | Delete
class Export_Attachment extends Export {
[9] Fix | Delete
[10] Fix | Delete
/**
[11] Fix | Delete
* Set up the current page to act like a downloadable file instead of being shown in the browser
[12] Fix | Delete
*
[13] Fix | Delete
* @param string $language File format. Used for file extension.
[14] Fix | Delete
* @param string $mime_type File MIME type. Used for Content-Type header.
[15] Fix | Delete
*/
[16] Fix | Delete
private function do_headers( string $language, string $mime_type = 'text/plain' ) {
[17] Fix | Delete
header( 'Content-Disposition: attachment; filename=' . sanitize_file_name( $this->build_filename( $language ) ) );
[18] Fix | Delete
header( sprintf( 'Content-Type: %s; charset=%s', sanitize_mime_type( $mime_type ), get_bloginfo( 'charset' ) ) );
[19] Fix | Delete
}
[20] Fix | Delete
[21] Fix | Delete
/**
[22] Fix | Delete
* Export snippets in JSON format as a downloadable file.
[23] Fix | Delete
*/
[24] Fix | Delete
public function download_snippets_json() {
[25] Fix | Delete
$this->do_headers( 'json', 'application/json' );
[26] Fix | Delete
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
[27] Fix | Delete
echo wp_json_encode(
[28] Fix | Delete
$this->create_export_object(),
[29] Fix | Delete
apply_filters( 'code_snippets/export/json_encode_options', 0 )
[30] Fix | Delete
);
[31] Fix | Delete
exit;
[32] Fix | Delete
}
[33] Fix | Delete
[34] Fix | Delete
/**
[35] Fix | Delete
* Export snippets in their code file format.
[36] Fix | Delete
*/
[37] Fix | Delete
public function download_snippets_code() {
[38] Fix | Delete
$lang = $this->snippets_list[0]->lang;
[39] Fix | Delete
[40] Fix | Delete
$mime_types = [
[41] Fix | Delete
'php' => 'text/php',
[42] Fix | Delete
'css' => 'text/css',
[43] Fix | Delete
'js' => 'text/javascript',
[44] Fix | Delete
'json' => 'application/json',
[45] Fix | Delete
];
[46] Fix | Delete
[47] Fix | Delete
$this->do_headers( $lang, $mime_types[ $lang ] ?? 'text/plain' );
[48] Fix | Delete
[49] Fix | Delete
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
[50] Fix | Delete
echo $this->export_snippets_code( $this->snippets_list[0]->type );
[51] Fix | Delete
exit;
[52] Fix | Delete
}
[53] Fix | Delete
}
[54] Fix | Delete
[55] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function