Created
July 19, 2011 14:02
-
-
Save larscwallin/1092461 to your computer and use it in GitHub Desktop.
SIMPLX Debugger Alpha
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Install: | |
1. Create a new Snippet called simplx_debugger | |
2. Copy and paste the contents of "simplx_debugger.php" and save. | |
3. Create a new Chunk called simplx.debugger.js | |
4. Copy and paste the contents of "simplx.debugger.js" and save. | |
5. Create a new Plugin called codemirror_debugger | |
6. Copy and paste the contents of "codemirror_debugger_plugin.php" and save. | |
7. Go to "System Events" and check all *FormPrerender events you like (snippet,plugin etc). Set Priority to something like 20. | |
8. Install/update your SIMPLX_RPC to version 0.6.5 from my gist (https://gist.github.com/1125061) | |
9. Install NuSOAP for PHP 5.3 using my gist (https://gist.github.com/1125063) or from SourceForge. Put it in Assets/Components/nusoap | |
Now everything should work :) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$simplx_debugger_js = $modx->getChunk('simplx.debugger.js'); | |
$simplx_rpc_js = $modx->getChunk('simplx.jsonrpc.js'); | |
$modx->regClientStartupHTMLBlock($simplx_rpc_js); | |
$modx->regClientStartupHTMLBlock($simplx_debugger_js); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js" type="text/javascript"></script> | |
<script type="text/javascript"> | |
simplx.debugger = { | |
simplxRPCObject:null, | |
run:function(code){ | |
var compilingMask; | |
if(code){ | |
compilingMask = new Ext.LoadMask(Ext.getBody(), {msg:"Compiling... Press ESC to cancel."}); | |
console.log(Ext.getBody()); | |
var map = new Ext.KeyMap(Ext.getBody(), { | |
key: Ext.EventObject.ESC, | |
fn: function(){ | |
compilingMask.hide(); | |
simplxRPCObject.callback = function(){return true;} | |
} | |
}); | |
compilingMask.show(); | |
}else{ | |
return; | |
} | |
var rpcOptions = { | |
"url":"[[+rpc_service_url]]", | |
"pageid":"[[+rpc_service_endpoint]]", | |
"usesnippetmatching":"1", | |
"dummyresponse":null, | |
"rpc":{ | |
"jsonrpc":"2.0", | |
"id":"1", | |
"method":"simplx.debugger", | |
"params":{ | |
"sourcecode":code, | |
"language":29, | |
"input":"", | |
"run":true | |
} | |
}}; | |
// Create and init the simplx.jsonrpc helper object. | |
simplxRPCObject = new simplx.jsonrpc(); | |
simplxRPCObject.init(rpcOptions); // Call the init method passing the rpcOptions json | |
simplxRPCObject.callback = function(jsobject){ | |
compilingMask.disable(); | |
compilingMask.hide(); | |
simplx.view.openDialog(simplx.view.templateResponse(jsobject.result)); | |
}; // Assign the function reference for success responses | |
simplxRPCObject.errorcallback= function(jsobject){ | |
compilingMask.disable(); | |
compilingMask.hide(); | |
}; // Assign the function reference for error responses | |
simplxRPCObject.execute(); // Now lets fire away the query. | |
}, | |
}; | |
simplx.view = { | |
setup: function(){ | |
if($){ | |
//Add button | |
var sibling = $("#cm-replace"); | |
if(sibling){ | |
$(sibling).after(" <button id=\"simplx_debugger_run\" type=\"button\" class=\"x-btn x-btn-text bmenu x-btn-noicon\" style=\"padding: 6px\">Debug</button>"); | |
$("#simplx_debugger_run").click(function(){ | |
simplx.debugger.run(MODx.editor.getValue()); | |
}); | |
}else{} | |
} | |
}, | |
openDialog: function(content){ | |
var win = new Ext.Window({ | |
width:400 | |
,padding:10 | |
,html:content | |
,id:"simplx_debugger_console" | |
,height:300 | |
,autoScroll:true | |
,title:"Debugger result" | |
}); | |
win.show(); | |
}, | |
templateResponse: function(data){ | |
data.source=null; | |
var output = data.output ? data.output : "Execution returned no errors :)"; | |
return data.output; | |
} | |
}; | |
Ext.onReady(function(){ | |
simplx.view.setup(); | |
}); | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once($modx->getOption('base_path').'assets/components/nusoap/'.'lib/nusoap.php'); | |
/* | |
Download the NUSOAP library from http://nusoapforphp53.sourceforge.net/ | |
*/ | |
class simplx_debugger{ | |
public $proxyhost = ''; | |
public $proxyport = ''; | |
public $proxyusername = ''; | |
public $proxypassword = ''; | |
public $serviceuri = 'http://ideone.com/api/1/service.wsdl'; | |
public $username = ''; | |
public $password = ''; | |
public $timeout = 5; | |
private $client = null; | |
function __construct($debugServiceURI){ | |
if($debugServiceURI){ | |
$this->serviceuri = $debugServiceURI; | |
} | |
$this->client = new nusoap_client($this->serviceuri, 'wsdl', $this->proxyhost, $this->proxyport, $this->proxyusername, $this->proxypassword); | |
} | |
public function createSubmission($sourceCode='', $language = 29, $input='',$run=true,$private=true){ | |
$status; | |
$result; | |
$link; | |
$iterator = 0; | |
if(!$sourceCode){ | |
return false; | |
} | |
$createSubmissionIn = array( | |
'user'=>$this->username, | |
'pass'=>$this->password, | |
'sourceCode'=>$sourceCode, | |
'language'=> $language, | |
'input'=>$input, | |
'run'=>$run, | |
'private'=>$private | |
); | |
$result = $this->client->call('createSubmission', $createSubmissionIn, '', '', false, true); | |
$link = $result['link']; | |
// Was a link returned from the ideone service? If not, the query probably failed. | |
if($link != ''){ | |
// Before we return we wait for the web service to return a status code of 0 which means that compilation is finished. | |
$status = $this->checkSubmissionStatus($link); | |
// While compilation status is not 0 AND the timeout limit is not exceeded. | |
while($status != 0 && $iterator < $this->timeout){ | |
$status = $this->getSubmissionStatus($link); | |
// Wait 1 sec between queries. | |
sleep(1); | |
// Iterate the iterator which servers to check the compilation timeout. | |
$iterator++; | |
} | |
}else{ | |
return false; | |
} | |
// Ok, the web service is done compiling so lets return the array which holds link and error information. | |
return $result; | |
} | |
public function checkSubmissionStatus($link){ | |
$getSubmissionStatusIn = array( | |
'user'=>$this->username, | |
'pass'=>$this->password, | |
'link'=>$link | |
); | |
$result = $this->client->call('getSubmissionStatus', $getSubmissionStatusIn, '', '', false, true); | |
return $result['status']; | |
} | |
public function getSubmissionStatus($link){ | |
$getSubmissionStatusIn = array( | |
'user'=>$this->username, | |
'pass'=>$this->password, | |
'link'=>$link | |
); | |
return $this->client->call('getSubmissionStatus', $getSubmissionStatusIn, '', '', false, true); | |
} | |
public function getSubmissionDetails($link,$withSource=true,$withInput=true,$withOutput=true,$withStderr=true,$withCmpinfo=true){ | |
if(!$link){ | |
//return false; | |
} | |
$getSubmissionDetailsIn = array( | |
'user'=>$this->username, | |
'pass'=>$this->password, | |
'link'=>$link, | |
'withSource'=>$withSource, | |
'withInput'=>$withInput, | |
'withOutput'=>$withOutput, | |
'withStderr'=>$withStderr, | |
'withCmpinfo'=>$withCmpinfo | |
); | |
return $this->client->call('getSubmissionDetails', $getSubmissionDetailsIn, '', '', false, true); | |
} | |
} | |
$username = isset($username) ? $username : 'larscwallin'; | |
$password = isset($password) ? $password : 'ideone'; | |
$sourcecode = isset($sourcecode) ? $sourcecode : ''; | |
$template = isset($template) ? $template : ''; | |
/* | |
Ada gnat-4.3.2 12768 7 | |
Assembler nasm-2.07 12425 13 | |
Assembler gcc-4.3.4 4251 45 | |
AWK (gawk) gawk-3.1.6 3993 104 | |
AWK (mawk) mawk-1.3.3 1412 105 | |
Bash bash 4.0.35 34063 28 | |
bc bc-1.06.95 2111 110 | |
Brainf**k bff-1.0.3.1 33658 12 | |
C gcc-4.3.4 503323 11 | |
C# mono-2.8 94408 27 | |
C++ gcc-4.3.4 903965 1 | |
C++0x gcc-4.5.1 31038 44 | |
C99 strict gcc-4.3.4 23210 34 | |
CLIPS clips 6.24 3002 14 | |
Clojure clojure 1.1.0 6070 111 | |
COBOL open-cobol-1.0 5932 118 | |
COBOL 85 tinycobol-0.65.9 6313 106 | |
Common Lisp (clisp) clisp 2.47 13927 32 | |
D (dmd) dmd-2.042 11633 102 | |
Erlang erl-5.7.3 5531 36 | |
F# fsharp-2.0.0 4659 124 | |
Factor factor-0.93 803 123 | |
Falcon falcon-0.9.6.6 710 125 | |
Forth gforth-0.7.0 3368 107 | |
Fortran gfortran-4.3.4 21228 5 | |
Go gc-2010-07-14 7069 114 | |
Groovy groovy-1.7 2658 121 | |
Haskell ghc-6.8.2 28102 21 | |
Icon iconc 9.4.3 2111 16 | |
Intercal c-intercal 28.0-r1 2693 9 | |
Java sun-jdk-1.6.0.17 489295 10 | |
JavaScript (rhino) rhino-1.6.5 15520 35 | |
JavaScript (spidermonkey) spidermonkey-1.7 16015 112 | |
Lua luac 5.1.4 9042 26 | |
Nemerle ncc 0.9.3 2191 30 | |
Nice nicec 0.9.6 1829 25 | |
Nimrod nimrod-0.8.8 431 122 | |
Objective-C gcc-4.5.1 4990 43 | |
Ocaml ocamlopt 3.10.2 4312 8 | |
Oz mozart-1.4.0 1504 119 | |
Pascal (fpc) fpc 2.2.0 95291 22 | |
Pascal (gpc) gpc 20070904 14177 2 | |
Perl perl 5.12.1 63235 3 | |
Perl 6 rakudo-2010.08 3184 54 | |
PHP php 5.2.11 140522 29 | |
Pike pike 7.6.86 8658 19 | |
Prolog (gnu) gprolog-1.3.1 4141 108 | |
Prolog (swi) swipl 5.6.64 44476 15 | |
Python python 2.6.4 127081 4 | |
Python 3 python-3.1.2 32151 116 | |
R R-2.11.1 5240 117 | |
Ruby ruby-1.9.2 35929 17 | |
Scala scala-2.8.0.final 7978 39 | |
Scheme (guile) guile 1.8.5 9384 33 | |
Smalltalk gst 3.1 3617 23 | |
SQL sqlite3-3.7.3 11968 40 | |
Tcl tclsh 8.5.7 5601 38 | |
Text text 6.10 7355 62 | |
Unlambda unlambda-2.0.0 1118 115 | |
Visual Basic .NET mono-2.4.2.3 19949 101 | |
Whitespace wspace 0.3 7881 6 | |
*/ | |
$language = isset($language) ? $language : 29; // Default to PHP | |
$input= isset($input) ? $input : ''; | |
$run = isset($input) ? (bool)$run : true; | |
$private = isset($private) ? (bool)$private : true; | |
$client = new simplx_debugger(); | |
$client->username = $username; | |
$client->password = $password; | |
$result = $client->createSubmission($sourcecode,$language,$input,$run,$private); | |
$result = $client->getSubmissionDetails($result['link']); | |
if($template != ''){ | |
print $modx->parseChunk($template,$result); | |
}else{ | |
print json_encode($result); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment