2015-09-21 17:04:51 +00:00
< ? php
register_module ([
" name " => " Raw page source " ,
2020-08-08 00:18:01 +00:00
" version " => " 0.8 " ,
2015-09-21 17:04:51 +00:00
" author " => " Starbeamrainbowlabs " ,
" description " => " Adds a 'raw' action that shows you the raw source of a page. " ,
" id " => " action-raw " ,
" code " => function () {
2015-12-21 14:03:21 +00:00
global $settings ;
2016-06-12 20:15:43 +00:00
/**
2020-08-08 00:18:01 +00:00
* @ api { get } ? action = raw & page = { pageName }[ & typeheader = { typeName }] Get the raw source code of a page
2016-06-12 20:15:43 +00:00
* @ apiName RawSource
* @ apiGroup Page
* @ apiPermission Anonymous
*
2020-08-08 00:18:01 +00:00
* @ apiParam { string } page The page to return the source of .
* @ apiParam { string } typeheader Optional ; v0 . 22 +. The content - type header to set on the response . If not set , defaults to text / markdown . Valid values : plaintext ( returns text / plain ) . Does NOT change the content delivered . Useful for debugging if your browser doesn ' t display text returned with text / markdown .
2016-06-12 20:15:43 +00:00
*/
2015-12-21 14:03:21 +00:00
2015-12-26 12:55:19 +00:00
/*
* ██████ █████ ██ ██
* ██ ██ ██ ██ ██ ██
* ██████ ███████ ██ █ ██
* ██ ██ ██ ██ ██ ███ ██
* ██ ██ ██ ██ ███ ███
*/
2015-09-21 17:04:51 +00:00
add_action ( " raw " , function () {
2017-10-14 15:09:46 +00:00
global $pageindex , $env ;
if ( empty ( $pageindex -> { $env -> page })) {
http_response_code ( 404 );
exit ( " Error: The page with the name $env->page could not be found. \n " );
}
2020-08-08 00:18:01 +00:00
if ( isset ( $_GET [ " typeheader " ]) && $_GET [ " typeheader " ] == " plaintext " )
header ( " content-type: text/plain " );
else
header ( " content-type: text/markdown " );
header ( " content-disposition: inline " );
2017-10-14 15:09:46 +00:00
header ( " content-length: " . filesize ( $env -> page_filename ));
2016-10-18 17:38:34 +00:00
exit ( file_get_contents ( $env -> page_filename ));
2015-09-21 17:04:51 +00:00
});
2015-12-21 14:03:21 +00:00
add_help_section ( " 800-raw-page-content " , " Viewing Raw Page Content " , " <p>Although you can use the edit page to view a page's source, you can also ask $settings->sitename to send you the raw page source and nothing else. This feature is intented for those who want to automate their interaction with $settings->sitename .</p>
< p > To use this feature , navigate to the page for which you want to see the source , and then alter the < code > action </ code > parameter in the url 's query string to be <code>raw</code>. If the <code>action</code> parameter doesn' t exist , add it . Note that when used on an file ' s page this action will return the source of the description and not the file itself .</ p > " );
2015-09-21 17:04:51 +00:00
}
]);
?>