summaryrefslogtreecommitdiff
path: root/shell/bin/editor.php
blob: 2d5d9c37faa9aa883394756f25c2939a7b4b107a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php
class p_editor extends prog {
	public static function main($args, $env) {
		if (isset($_POST['stdin'])) {
			if (isset($args[1])) {
				echo $args[0].': saving to `'.$args[1]."'\n";
				file_put_contents($args[1],$_POST['stdin']);
			} else {
				echo htmlentities($_POST['stdin']);
			}
		} else {
			if (isset($args[1]) && file_exists($args[1])) {
				$text = file_get_contents($args[1]);
			} else {
				$text = '';
			}
			echo '<div class="editor">';
			echo '<input type="hidden" name="stdout_dest" value="'.$_POST['c'].'" />';
			echo '<textarea name="stdin">'.htmlentities($text).'</textarea>'."\n";
			echo '<input type="submit" value="save" />';
			echo '</div>';
		}
	}
}