Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- new function()
- {
- /**
- * Execute Macro
- *
- * @returns {void}
- */
- this.exec = function()
- {
- // Ensure we're set up correcly
- komodo.assertMacroVersion(3);
- if (komodo.view) { komodo.view.setFocus() };
- // Get text to execute
- var ke = komodo.editor;
- if(!ke.selText)
- {
- // Use all text in file
- var text = ko.views.manager.currentView.scimoz.text.trim()
- }
- else
- {
- // Use selected text
- var text = komodo.interpolate('%s').trim();
- }
- // Prepend php opening tag if necessary
- if (text.substr(0,2) != '<?')
- {
- text = '<?php ' + text;
- }
- // Write temporary file
- var file = this.writeFile(text);
- // get PHP binary path
- var phpBinary = Components.classes['@activestate.com/koPrefService;1']
- .getService(Components.interfaces.koIPrefService)
- .prefs.getStringPref('phpDefaultInterpreter');
- // Run php
- ko.run.runEncodedCommand(window, phpBinary + ' -d display_errors=true ' + file);
- };
- /**
- * Write data to file
- *
- * @param {string} data Data to write to file
- *
- * @returns {string} File path
- */
- this.writeFile = function(data)
- {
- // Get temp file path
- var tmpFile = Components.classes["@mozilla.org/file/directory_service;1"].
- getService(Components.interfaces.nsIProperties).
- get("TmpD", Components.interfaces.nsIFile);
- tmpFile.append("krsp.php");
- // Initialize (create) file
- var file = Components.classes["@mozilla.org/file/local;1"].
- createInstance(Components.interfaces.nsILocalFile);
- file.initWithPath(tmpFile.path);
- // Open stream to file
- var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"].
- createInstance(Components.interfaces.nsIFileOutputStream);
- foStream.init(file, 0x02 | 0x08 | 0x20, 0666, 0);
- // Use converter to ensure UTF-8 encoding
- var converter = Components.classes["@mozilla.org/intl/converter-output-stream;1"].
- createInstance(Components.interfaces.nsIConverterOutputStream);
- // Write to file
- converter.init(foStream, "UTF-8", 0, 0);
- converter.writeString(data);
- converter.close();
- return tmpFile.path;
- };
- this.exec();
- }
Add Comment
Please, Sign In to add comment