1 | <?php
|
---|
2 | /*
|
---|
3 | CPAINT Backend Debug Interface
|
---|
4 |
|
---|
5 | released under the terms of the GPL
|
---|
6 | see http://www.fsf.org/licensing/licenses/gpl.txt for details
|
---|
7 |
|
---|
8 | @package CPAINT
|
---|
9 | @access public
|
---|
10 | @author Paul Sullivan <wiley14@gmail.com>
|
---|
11 | @author Stephan Tijink <stijink@googlemail.com>
|
---|
12 | @copyright Copyright (c) 2005-2006 Paul Sullivan - http://sf.net/projects/cpaint
|
---|
13 | @version 2.0.2
|
---|
14 | */
|
---|
15 |
|
---|
16 | if (!(isset($_GET["cpaint_function"]) || isset($_POST["cpaint_function"]))) {
|
---|
17 | $debug_html_start = '
|
---|
18 | <html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
---|
19 | <title>CPAINT Debug Interface</title>
|
---|
20 | <style type="text/css">body { background-color: #9999CC; margin-top: 0px; }
|
---|
21 | .style3 { font-family: Arial, Helvetica, sans-serif; font-size: 12px; }
|
---|
22 | .style4 { font-size: 20px; color: #FFFFFF; font-family: Arial, Helvetica, sans-serif;}
|
---|
23 | .style5 { font-size: 16px; color: #FFFFFF; font-family: Arial, Helvetica, sans-serif; font-weight: bold; }
|
---|
24 | .style6 { font-size: 12px; color: #FFFFFF; font-family: Arial, Helvetica, sans-serif; font-weight: bold; }
|
---|
25 | div, iframe { margin: 0px; border: 1px solid #9999CC; }
|
---|
26 | </style>
|
---|
27 | <script type="text/javascript">
|
---|
28 | function showForm(divId) {
|
---|
29 | if (document.getElementById(divId).style.display == "block") {
|
---|
30 | document.getElementById(divId).style.display = "none";
|
---|
31 | } else {
|
---|
32 | document.getElementById(divId).style.display = "block";
|
---|
33 | }
|
---|
34 | }
|
---|
35 | </script>
|
---|
36 | </head>
|
---|
37 | <body>
|
---|
38 | <table width="100%" border="0" cellspacing="0" cellpadding="0">
|
---|
39 | <tr><td bgcolor="#9999CC"><div align="justify"><span class="style4">CPAINT Debug Interface</span></div></td></tr>
|
---|
40 | <tr><td bgcolor="#9999CC"><div align="justify"><span class="style6" style="color:#FFFFFF;">backend filename: '.$_SERVER["SCRIPT_NAME"].'</span></div></td></tr>
|
---|
41 | <tr><td height="10" bgcolor="#9999CC" class="style3"></td></tr>
|
---|
42 | <tr><td height="10" bgcolor="#9999CC" class="style3"></td></tr>
|
---|
43 | <tr><td bgcolor="#FFFFFF" class="style3"><blockquote>';
|
---|
44 | $debug_html_end = "</blockquote></td></tr></table><br><iframe name=\"results\" class=\"style3\" width=\"100%\" height=\"100%\" scrolling=\"yes\" allowtransparency=\"false\" style=\"background-color: #FFFFFF\"></iframe></body></html>";
|
---|
45 |
|
---|
46 | // get function names and function variables/values
|
---|
47 | $functionArray = getCallableCode();
|
---|
48 |
|
---|
49 | $debug_body = "";
|
---|
50 | if (count($functionArray) > 0) {
|
---|
51 | foreach ($functionArray as $func_name=>$func_variables) {
|
---|
52 | $debug_body = $debug_body . "<form method=\"get\" target=\"results\"><a href=\"javascript:showForm('" . $func_name . "_form');\">" . $func_name . "</a><div id=\"" . $func_name . "_form\" style=\"display: none;\">";
|
---|
53 |
|
---|
54 | $debug_body = $debug_body . '<table border="0">';
|
---|
55 | if ( count($func_variables) > 0) {
|
---|
56 | foreach ($func_variables as $var_name=>$var_preset) {
|
---|
57 | $debug_body = $debug_body . '<tr><td class="style3">Parameter (<strong>$'.$var_name.'</strong>):</td><td><input type="text" name="cpaint_argument[]"></td>';
|
---|
58 | if (strlen($var_preset) > 0) { $debug_body = $debug_body . "<td class=\"style3\"> default value is <strong>".$var_preset." </strong></td>"; }
|
---|
59 | $debug_body = $debug_body . '</tr>';
|
---|
60 | }
|
---|
61 | }
|
---|
62 | $debug_body = $debug_body . "<tr><td class=\"style3\">Response Type:</td><td><select name=\"cpaint_response_type\"><option>TEXT</option><option>XML</option><option>OBJECT</option></select></td></tr>";
|
---|
63 | $debug_body = $debug_body . "<tr><td colspan=\"3\"><input type=\"hidden\" name=\"cpaint_function\" value=\"" . $func_name . "\"><input type=\"submit\"></td></tr></table></div></form>";
|
---|
64 | }
|
---|
65 | }
|
---|
66 |
|
---|
67 | print($debug_html_start . $debug_body . $debug_html_end);
|
---|
68 | die();
|
---|
69 | }
|
---|
70 |
|
---|
71 | function getCallableCode() {
|
---|
72 | $scriptName = $_SERVER['SCRIPT_FILENAME'];
|
---|
73 | $fileLines = file($scriptName);
|
---|
74 | for ($i=0; $i < sizeof($fileLines); ++$i) {
|
---|
75 | $line = trim($fileLines[$i]);
|
---|
76 | if (substr($line, 0, 9) == "FUNCTION " || substr($line,0,9) == "function ") {
|
---|
77 | $match[] = $line;
|
---|
78 | }
|
---|
79 | }
|
---|
80 | for ($i = 0; $i < sizeof($match); ++$i) {
|
---|
81 | $line = str_replace("function ", "", $match[$i]);
|
---|
82 | $line = str_replace("FUNCTION ", "", $line);
|
---|
83 | $line = str_replace("{", "", $line);
|
---|
84 | $parts = explode("(", $line);
|
---|
85 | $func_name = trim($parts[0]);
|
---|
86 |
|
---|
87 | $Tempargs = explode(")", $parts[1]);
|
---|
88 | $args = explode(",", $Tempargs[0]);
|
---|
89 | $argSize = sizeof($args);
|
---|
90 |
|
---|
91 | // check args for preset values
|
---|
92 | if ($argSize > 0) {
|
---|
93 | foreach ($args as $arg) {
|
---|
94 | $arg = trim ($arg);
|
---|
95 | $varArray = explode ("=", $arg);
|
---|
96 | $var_name = trim (str_replace ("$", "", $varArray["0"]));
|
---|
97 | $var_value = trim ($varArray["1"]);
|
---|
98 | $resultArray[$func_name][$var_name] = $var_value;
|
---|
99 | }
|
---|
100 | }
|
---|
101 | }
|
---|
102 | return $resultArray;
|
---|
103 | }
|
---|
104 | ?> |
---|