2018-10-07 03:36:19 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
// FILEPATH URL --> RELATIVE_PATH
|
|
|
|
// SIDE-EFFECT: Written redirect PHP to filepath
|
|
|
|
// Create a simple PHP redirection file at $filepath to $url;
|
|
|
|
// return the relative path to it.
|
|
|
|
function write_alias($filepath, $url)
|
|
|
|
{
|
|
|
|
$file_p = fopen($filepath, 'w');
|
2018-10-09 19:39:09 -05:00
|
|
|
$redirect_string = "<?php header('Location: " . $url . "'); ?>\n";
|
2018-10-07 03:36:19 -05:00
|
|
|
|
2018-10-09 19:39:09 -05:00
|
|
|
if (fwrite($file_p, $redirect_string)) {
|
|
|
|
fclose($file_p);
|
|
|
|
return $filepath;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 0;
|
|
|
|
}
|
2018-10-07 03:36:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// FILEPATH SOURCE_STRING --> RELATIVE_PATH
|
|
|
|
// SIDE-EFFECT: Written metadata TXT at $filepath.txt
|
|
|
|
// Create a metadata file for set path;
|
|
|
|
// return the relative path to it.
|
|
|
|
function write_metadata($filepath, $source)
|
|
|
|
{
|
|
|
|
if (empty($source)) {
|
|
|
|
$source = "[citation needed]";
|
|
|
|
}
|
|
|
|
|
|
|
|
$file_p = fopen($filepath . ".txt", 'w');
|
|
|
|
$source_string = "Source:\n"
|
|
|
|
. prefix_text(set_line_length($source, 50),
|
|
|
|
" ");
|
|
|
|
|
2018-10-09 19:39:09 -05:00
|
|
|
if (fwrite($file_p, $source_string)) {
|
|
|
|
fclose($file_p);
|
|
|
|
return $source_string;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// FILENAME --> FILE_EXTENSION
|
|
|
|
// Return the file-extension of a filename.
|
|
|
|
function file_extension($file_name)
|
|
|
|
{
|
2019-01-26 23:58:19 -06:00
|
|
|
return strtolower(pathinfo($file_name, PATHINFO_EXTENSION));
|
2018-10-07 03:36:19 -05:00
|
|
|
}
|
|
|
|
|
2019-01-27 01:51:11 -06:00
|
|
|
// FILENAME --> BOOLEAN
|
|
|
|
// Return whether or not a filename has an 'image' file-extension
|
|
|
|
function is_image($file_name)
|
|
|
|
{
|
|
|
|
$file_ext = file_extension($file_name);
|
|
|
|
|
|
|
|
if (in_array(($file_ext), array("jpg", "jpeg", "jpg", "png"))) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-07 03:36:19 -05:00
|
|
|
|
|
|
|
?>
|