]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - scripts/console.php
Merged
[quix0rs-gnu-social.git] / scripts / console.php
index 210d2b6b2fcd885c4b91c33b1ca912f017e1e853..910c663b016141fed6cd44c3b3da17e801576b87 100755 (executable)
@@ -18,7 +18,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-# Abort if called from a web server
+// Abort if called from a web server
 
 define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
 
@@ -27,7 +27,7 @@ console.php - provide an interactive PHP interpreter for testing
 
 ENDOFHELP;
 
-require_once INSTALLDIR.'/scripts/commandline.inc';
+require_once INSTALLDIR.'/scripts/commandline.inc.php';
 
 // Assume we're on a terminal if on Windows, otherwise posix_isatty tells us.
 define('CONSOLE_INTERACTIVE', !function_exists('posix_isatty') || posix_isatty(0));
@@ -45,10 +45,12 @@ function read_input_line($prompt)
     if (CONSOLE_INTERACTIVE) {
         if (CONSOLE_READLINE) {
             $line = readline($prompt);
-            readline_add_history($line);
-            if (defined('CONSOLE_HISTORY')) {
-                // Save often; it's easy to hit fatal errors.
-                readline_write_history(CONSOLE_HISTORY);
+            if (trim($line) != '') {
+                readline_add_history($line);
+                if (defined('CONSOLE_HISTORY')) {
+                    // Save often; it's easy to hit fatal errors.
+                    readline_write_history(CONSOLE_HISTORY);
+                }
             }
             return $line;
         } else {
@@ -73,7 +75,7 @@ function read_input_line($prompt)
  */
 function readline_emulation($prompt)
 {
-    if(file_exists(trim(shell_exec('which bash')))) {
+    if(CONSOLE_INTERACTIVE && file_exists(trim(shell_exec('which bash')))) {
         $encPrompt = escapeshellarg($prompt);
         $command = "read -er -p $encPrompt && echo \"\$REPLY\"";
         $encCommand = escapeshellarg($command);
@@ -103,13 +105,15 @@ function readline_emulation($prompt)
     if (feof(STDIN)) {
         return false;
     }
-    print $prompt;
+    if (CONSOLE_INTERACTIVE) {
+        print $prompt;
+    }
     return fgets(STDIN);
 }
 
 function console_help()
 {
-    print "Welcome to StatusNet's interactive PHP console!\n";
+    print "Welcome to GNU social's interactive PHP console!\n";
     print "Type some PHP code and it'll execute...\n";
     print "\n";
     print "Hint: return a value of any type to output it via var_export():\n";
@@ -123,13 +127,18 @@ function console_help()
     print "Type ctrl+D or enter 'exit' to exit.\n";
 }
 
-
-print "StatusNet interactive PHP console... type ctrl+D or enter 'exit' to exit.\n";
-$prompt = common_config('site', 'name') . '> ';
+if (CONSOLE_INTERACTIVE) {
+    print "GNU social interactive PHP console... type ctrl+D or enter 'exit' to exit.\n";
+    $prompt = common_slugify(common_config('site', 'name')) . '> ';
+} else {
+    $prompt = '';
+}
 while (!feof(STDIN)) {
     $line = read_input_line($prompt);
     if ($line === false) {
-        print "\n";
+        if (CONSOLE_INTERACTIVE) {
+            print "\n";
+        }
         break;
     } elseif ($line !== '') {
         try {
@@ -154,5 +163,7 @@ while (!feof(STDIN)) {
             print get_class($e) . ": " . $e->getMessage() . "\n";
         }
     }
-    print "\n";
+    if (CONSOLE_INTERACTIVE) {
+        print "\n";
+    }
 }