PageRenderTime 25ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/wordpress-console/complete.php

https://gitlab.com/blueprintmrk/bladencountyrecords
PHP | 206 lines | 156 code | 36 blank | 14 comment | 23 complexity | d82d7473b97fac1f1706e1b58081c81a MD5 | raw file
  1. <?php
  2. require( 'common.php' );
  3. if ( isset($_POST['partial'] ) ) {
  4. $secret = get_option('wordpress-console-secret');
  5. if ( !$secret ) {
  6. return;
  7. }
  8. if ( !isset( $_POST['signature'] ) || !$_POST['signature'] ) {
  9. return;
  10. }
  11. $partial = stripslashes( $_POST['partial'] );
  12. if ( hash_hmac( 'sha1', $partial, $secret ) != $_POST['signature'] ) {
  13. return;
  14. }
  15. if ( !preg_match( '#([0-9a-z_-]+)$#i', $partial, $m ) ) {
  16. die( json_encode( false ) );
  17. }
  18. $candidates = preg_grep( "/^{$m[1]}/", complete( $m[1] ) );
  19. sort( $candidates );
  20. die( json_encode( ( array ) $candidates ) );
  21. } else {
  22. error( 'Error initializing session.' );
  23. }
  24. // returns array of possible matches
  25. function complete( $string ) {
  26. /**
  27. * parse the line-buffer backwards to see if we have a
  28. * - constant
  29. * - function
  30. * - variable
  31. */
  32. $m = array();
  33. if ( preg_match( '#\$([A-Za-z0-9_]+)->#', $string, $a ) ) {
  34. /* check for $o->... */
  35. $name = $a[1];
  36. if ( isset( $GLOBALS[$name] ) && is_object( $GLOBALS[$name] ) ) {
  37. $c = get_class_methods( $GLOBALS[$name] );
  38. foreach ( $c as $v ) {
  39. $m[] = $v.'(';
  40. }
  41. $c = get_class_vars( get_class( $GLOBALS[$name] ) );
  42. foreach ( $c as $k => $v ) {
  43. $m[] = $k;
  44. }
  45. return $m;
  46. }
  47. } else if ( preg_match( '#\$([A-Za-z0-9_]+)\[([^\]]+)\]->#', $string, $a ) ) {
  48. /* check for $o[...]->... */
  49. $name = $a[1];
  50. if ( isset( $GLOBALS[$name] ) &&
  51. is_array( $GLOBALS[$name] ) &&
  52. isset( $GLOBALS[$name][$a[2]] ) ) {
  53. $c = get_class_methods( $GLOBALS[$name][$a[2]] );
  54. foreach ( $c as $v ) {
  55. $m[] = $v.'(';
  56. }
  57. $c = get_class_vars( get_class( $GLOBALS[$name][$a[2]] ) );
  58. foreach ( $c as $k => $v ) {
  59. $m[] = $k;
  60. }
  61. return $m;
  62. }
  63. } else if ( preg_match( '#([A-Za-z0-9_]+)::#', $string, $a ) ) {
  64. /* check for Class:: */
  65. $name = $a[1];
  66. if ( class_exists( $name, false ) ) {
  67. $c = get_class_methods( $name );
  68. foreach ( $c as $v ) {
  69. $m[] = sprintf( '%s::%s(', $name, $v );
  70. }
  71. $cl = new ReflectionClass( $name );
  72. $c = $cl->getConstants();
  73. foreach ( $c as $k => $v ) {
  74. $m[] = sprintf( '%s::%s', $name, $k );
  75. }
  76. return $m;
  77. }
  78. } else if ( preg_match( '#\$([a-zA-Z]?[a-zA-Z0-9_]*)$#', $string ) ) {
  79. $m = array_keys( $GLOBALS );
  80. return $m;
  81. } else if ( preg_match( '#new #', $string ) ) {
  82. $c = get_declared_classes();
  83. foreach ( $c as $v ) {
  84. $m[] = $v.'(';
  85. }
  86. return $m;
  87. } else if ( preg_match( '#^:set #', $string ) ) {
  88. foreach ( PHP_Shell_Options::getInstance()->getOptions() as $v ) {
  89. $m[] = $v;
  90. }
  91. return $m;
  92. }
  93. $f = get_defined_functions();
  94. foreach ( $f['internal'] as $v ) {
  95. $m[] = $v.'(';
  96. }
  97. foreach ( $f['user'] as $v ) {
  98. $m[] = $v.'(';
  99. }
  100. $c = get_declared_classes();
  101. foreach ( $c as $v ) {
  102. $m[] = $v.'::';
  103. }
  104. $c = get_defined_constants();
  105. foreach ( $c as $k => $v ) {
  106. $m[] = $k;
  107. }
  108. /* taken from http://de3.php.net/manual/en/reserved.php */
  109. $m[] = 'abstract';
  110. $m[] = 'and';
  111. $m[] = 'array(';
  112. $m[] = 'as';
  113. $m[] = 'break';
  114. $m[] = 'case';
  115. $m[] = 'catch';
  116. $m[] = 'class';
  117. $m[] = 'const';
  118. $m[] = 'continue';
  119. # $m[] = 'declare';
  120. $m[] = 'default';
  121. $m[] = 'die(';
  122. $m[] = 'do';
  123. $m[] = 'echo(';
  124. $m[] = 'else';
  125. $m[] = 'elseif';
  126. $m[] = 'empty(';
  127. # $m[] = 'enddeclare';
  128. $m[] = 'eval(';
  129. $m[] = 'exception';
  130. $m[] = 'extends';
  131. $m[] = 'exit(';
  132. $m[] = 'extends';
  133. $m[] = 'final';
  134. $m[] = 'for (';
  135. $m[] = 'foreach (';
  136. $m[] = 'function';
  137. $m[] = 'global';
  138. $m[] = 'if';
  139. $m[] = 'implements';
  140. $m[] = 'include "';
  141. $m[] = 'include_once "';
  142. $m[] = 'interface';
  143. $m[] = 'isset(';
  144. $m[] = 'list(';
  145. $m[] = 'new';
  146. $m[] = 'or';
  147. $m[] = 'print(';
  148. $m[] = 'private';
  149. $m[] = 'protected';
  150. $m[] = 'public';
  151. $m[] = 'require "';
  152. $m[] = 'require_once "';
  153. $m[] = 'return';
  154. $m[] = 'static';
  155. $m[] = 'switch (';
  156. $m[] = 'throw';
  157. $m[] = 'try';
  158. $m[] = 'unset(';
  159. # $m[] = 'use';
  160. $m[] = 'var';
  161. $m[] = 'while';
  162. $m[] = 'xor';
  163. $m[] = '__FILE__';
  164. $m[] = '__FUNCTION__';
  165. $m[] = '__CLASS__';
  166. $m[] = '__LINE__';
  167. $m[] = '__METHOD__';
  168. return $m;
  169. }
  170. ?>