2 define('AT_INCLUDE_PATH', '../../../../include/');
3 require(AT_INCLUDE_PATH.'vitals.inc.php');
7 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
8 <title>Paste from file tool</title>
9 <script src="<?php echo $_base_path; ?>jscripts/infusion/InfusionAll.js" type="text/javascript"></script>
10 <script src="<?php echo $this->base_path; ?>jscripts/ATutor.js" type="text/javascript"></script>
11 <script type="text/javascript">
12 ATutor = ATutor || {};
13 ATutor.mods = ATutor.mods || {};
14 ATutor.mods.editor = ATutor.mods.editor || {};
16 var errorStringPrefix = '<div id="error"><h4><?php echo _AT('the_follow_errors_occurred'); ?></h4><ul><li>';
17 var errorStringSuffix = '</li></ul></div>';
21 ATutor.mods.editor.insertErrorMsg = function (errorString) {
22 jQuery("#subnavlistcontainer", window.opener.document).before(errorStringPrefix + errorString + errorStringSuffix);
25 ATutor.mods.editor.removeErrorMsg = function () {
26 jQuery("#error", window.opener.document).remove();
29 ATutor.mods.editor.testStuff = function () {
30 var body = ATutor.mods.editor.stuff;
31 body = body.replace(/\\/g,"");
33 jQuery("#body_text", window.opener.document).val(body);
37 ATutor.mods.editor.pasteFromFile = function (body, title, head) {
38 body = body.replace(/\\/g,"");
39 if (jQuery("#html", window.opener.document).attr("checked") &&
40 (<?php echo $_SESSION['prefs']['PREF_CONTENT_EDITOR']; ?> !== 1)) {
41 window.opener.tinyMCE.activeEditor.setContent(body);
43 jQuery("#body_text", window.opener.document).val(body);
47 jQuery("#ctitle",window.opener.document).val(title);
50 jQuery("#head", window.opener.document).html(head);
51 jQuery("#use_customized_head", window.opener.document).attr("checked", true);
65 private $errorMsg = "";
67 public function getTitle() {
71 public function setTitle($value) {
72 $this->title = $value;
75 public function getHead() {
79 public function setHead($value) {
83 public function getBody() {
87 public function setBody($value) {
91 public function getErrorMsg() {
92 return $this->errorMsg;
95 public function setErrorMsg($value) {
96 $this->errorMsg = $value;
103 * Parses a named uploaded file of html or txt type
104 * The function identifies title, head and body for html files,
105 * or body for text files.
107 * @return FileData object
109 function paste_from_file() {
110 $fileData = new FileData();
111 if ($_FILES['uploadedfile_paste']['name'] == '') {
112 $fileData->setErrorMsg(_AT('AT_ERROR_FILE_NOT_SELECTED'));
113 } elseif (($_FILES['uploadedfile_paste']['type'] == 'text/plain')
114 || ($_FILES['uploadedfile_paste']['type'] == 'text/html') ) {
116 $path_parts = pathinfo($_FILES['uploadedfile_paste']['name']);
117 $ext = strtolower($path_parts['extension']);
119 if (in_array($ext, array('html', 'htm'))) {
120 $contents = file_get_contents($_FILES['uploadedfile_paste']['tmp_name']);
122 /* get the <title></title> of this page */
123 $start_pos = strpos(strtolower($contents), '<title>');
124 $end_pos = strpos(strtolower($contents), '</title>');
126 if (($start_pos !== false) && ($end_pos !== false)) {
127 $start_pos += strlen('<title>');
128 $fileData->setTitle(trim(substr($contents, $start_pos, $end_pos-$start_pos)));
133 $fileData->setHead(trim(get_html_head_by_tag($contents, array("link", "style", "script"))));
134 $fileData->setBody(trim(get_html_body($contents)));
135 } else if ($ext == 'txt') {
136 $fileData->setBody(trim(file_get_contents($_FILES['uploadedfile_paste']['tmp_name'])));
139 $fileData->setErrorMsg(_AT('AT_ERROR_BAD_FILE_TYPE'));
144 if (isset($_POST['submit_file']))
146 echo '<script type="text/javascript">';
147 echo 'ATutor.mods.editor.removeErrorMsg();';
148 $fileData = paste_from_file();
149 $errorMessage = $fileData->getErrorMsg();
150 if ($errorMessage == "") {
151 echo 'ATutor.mods.editor.pasteFromFile('.json_encode($fileData->getBody()).','.json_encode($fileData->getTitle()).','.json_encode($fileData->getHead()).');';
153 echo 'ATutor.mods.editor.insertErrorMsg("'.$errorMessage.'");';
155 echo "window.close();";
161 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form" enctype="multipart/form-data">
162 <input type="file" name="uploadedfile_paste" id="uploadedfile" class="formfield" size="20" />
163 <input type="submit" name="submit_file" id="submit_file" value="<?php echo _AT('paste'); ?>" class="button" />