Page MenuHomeCode

No OneTemporary

This document is not UTF8. It was detected as Shift JIS and converted to UTF8 for display.
diff --git a/includes/SmartLine/SmartLine.php b/includes/SmartLine/SmartLine.php
new file mode 100644
--- /dev/null
+++ b/includes/SmartLine/SmartLine.php
@@ -0,0 +1,328 @@
+<?php
+
+/*
+ SmartLine 0.1
+ http://www.espace-win.org/EWOSP/SmartLine
+ (c) 2007 Espace Win Open Source Project, some rights reserved.
+ Released under BSD License
+
+ Developer leader: S饕astien Santoro aka Dereckson
+ http://purl.espace-win.org/Who/Dereckson
+
+ Support: http://purl.espace-win.org/EWOSP/Support
+
+ 0.1 2007-07-28 01:36 [DcK] Initial release
+*/
+
+///////////////////////////////////////////////////////////////////////////////
+// SECTION I - INITIALIZATION
+///////////////////////////////////////////////////////////////////////////////
+
+//Constants
+if (!defined('STDOUT')) define('STDOUT', 1, true);
+if (!defined('STDERR')) define('STDERR', -1, true);
+
+///////////////////////////////////////////////////////////////////////////////
+// SECTION Ibis - L10n
+///////////////////////////////////////////////////////////////////////////////
+
+
+//Assumes $lang is a standard array
+if (empty($lang) || !is_array($lang)) {
+ $lang = array();
+}
+
+$lang = array_merge($lang, array(
+ //Errors
+ 'InvalidCommand' => "Invalid command %s. Use <strong>showcommands</strong> to show all commands.",
+ 'RegisteredButNotExistingCommand' => "[CRITICAL ERROR] The command %s has correctly been registered but its method or class doesn't exist.",
+ 'NotYetHelpForThiscommand' => "This command hasn't been documented yet.",
+
+ //Help
+ 'DefaultHelp' => "This SmartLine is a command line interface.
+ <br /><br /><strong>showcommands</strong> prints the list.
+ <br /><strong>help &lt;command&gt;</strong> prints help for this command.",
+ 'Help' => array(
+ 'help' => "<strong>help &lt;command&gt;</strong> prints command help.",
+ 'showcommands' => 'show available commands'
+ )
+));
+
+///////////////////////////////////////////////////////////////////////////////
+// SECTION II - HELPERS FUNCTIONS
+///////////////////////////////////////////////////////////////////////////////
+
+//Error Handler
+function SmartLineHandler($level, $error, $file, $line) {
+ switch ($level) {
+ case E_NOTICE:
+ $type = 'Notice';
+ break;
+
+ CASE E_WARNING:
+ $type = 'Warning';
+ break;
+
+ CASE E_ERROR:
+ $type = 'Error';
+ break;
+
+ default:
+ $type = "#$level";
+ }
+ $_SESSION['SmartLineOutput'][STDERR][] = "[PHP $type] $error ";
+ return true;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// SECTION III - BASE CLASSES
+///////////////////////////////////////////////////////////////////////////////
+
+//SmartLineCommand is a class implemanting a SmartLine command.
+//If you want to create a more complex command, extends this class.
+class SmartLineCommand {
+ public function __construct ($SmartLine) {
+ $this->SmartLine = $SmartLine;
+ }
+
+ //Gets command help
+ //Returns help text to print
+ //Returns false for default behavior
+ //(ie prints $lang['Help'][$command])
+ public function help () {
+ return false;
+ }
+
+ //Runs command
+ //$argv is an array containing args, $argc = count($argv)
+ public function run ($argv, $argc) {
+
+ }
+
+ //Gets the SmartLine where this instance of the command is registered
+ public $SmartLine;
+}
+
+//This class represents a SmartLine instance.
+//If you use only register_object, you can use it directly
+//If you use register_method, extends this class in your SmartLine.
+class SmartLine {
+ public function __construct () {
+ //Assumes we've an empty array where store registered commands.
+ $this->commands = array();
+ //Let's register standard commands
+ $this->register_object('showcommands', 'ShowCommandsSmartLineCommand');
+ $this->register_object('help', 'HelpSmartLineCommand');
+ }
+
+ //Registers a private method as command
+ public function register_method ($command, $function = null, $useArgvArgc = false) {
+ if (is_null($function)) $function = $command;
+
+ if (!method_exists($this, $function)) {
+ $this->lastError = "Registration failed. Unknown method $function";
+ return false;
+ }
+
+ $className = ucfirst($function) . 'SmartLineCommand';
+ //If class exists, add a uniqid after function
+ while (class_exists($className)) {
+ $className = uniqid(ucfirst($function)) . 'SmartLineCommand';
+ }
+ //Creates the class
+ if ($useArgvArgc) {
+ $call = "$this->SmartLine->$function(\$argv, \$argc);";
+ } else {
+ //We don't know how many args we've, so we use call_user_func_array
+ $call = "array_shift(\$argv);
+ call_user_func_array(
+ array(&\$this->SmartLine, '$function'),
+ \$argv
+ );";
+ }
+ $code = "class $className extends SmartLineCommand {
+ public function run (\$argv, \$argc) {
+ $call
+ }
+}";
+ eval($code);
+ $this->register_object($command, $className);
+ return true;
+ }
+
+ //Registers an object extending SmartLineCommand as command
+ public function register_object ($command, $object) {
+ if (is_object($object)) {
+ //Sets SmartLine property
+ $object->SmartLine = $this;
+ } elseif (is_string($object)) {
+ //Creates a new instance of $object
+ $object = new $object($this);
+ } else {
+ $this->lastError = "Registration failed. register_object second parameter must be a class name (string) or an already initialized instance of such class (object) and not a " . gettype($object);
+ return false;
+ }
+ if (!$this->caseSensitive) $command = strtolower($command);
+ $this->commands[$command] = $object;
+ return true;
+ }
+
+ //Returns true if $command has been registred
+ public function isRegistered ($command) {
+ if (!$this->caseSensitive) $command = strtolower($command);
+ return array_key_exists($command, $this->commands);
+ }
+
+ //Executes an expression
+ public function execute ($expression) {
+ //Does nothing if blank line
+ if (!$expression) return;
+
+ //Prepares $argv and $argc
+ $argv = $this->expression2argv($expression);
+ $argc = count($argv);
+
+ //Gets command
+ $command = $this->caseSensitive ? $argv[0] : strtolower($argv[0]);
+
+ //If command doesn't exist, throws an error
+ if (!array_key_exists($command, $this->commands)) {
+ global $lang;
+ $this->puts(sprintf($lang['InvalidCommand'], $command), STDERR);
+ return false;
+ }
+
+ //Executes command, intercepting error and returns result
+ set_error_handler("SmartLineHandler");
+ $result = $this->commands[$command]->run($argv, $argc);
+ restore_error_handler();
+ return $result;
+ }
+
+ public function puts ($message, $output = STDOUT) {
+ //Adds message to current output queue
+ $_SESSION['SmartLineOutput'][$output][] = $message;
+ }
+
+ public function truncate ($output = STDOUT) {
+ unset($_SESSION['SmartLineOutput'][$output]);
+ }
+
+ public function gets ($output = STDOUT) {
+ if (count($_SESSION['SmartLineOutput'][$output] > 0))
+ return array_pop($_SESSION['SmartLineOutput'][$output]);
+ }
+
+ public function count ($output = STDOUT) {
+ return count($_SESSION['SmartLineOutput'][$output]);
+ }
+
+ public function gets_all ($output = STDOUT, $prefix = '<p>', $suffix = '</p>') {
+ $count = count($_SESSION['SmartLineOutput'][$output]);
+ if ($count == 0) return;
+ for ($i = 0 ; $i < $count ; $i++)
+ $buffer .= $prefix . $_SESSION['SmartLineOutput'][$output][$i] . $suffix;
+ unset ($_SESSION['SmartLineOutput'][$output]);
+ return $buffer;
+ }
+
+ public function prints_all ($output = STDOUT, $prefix = '<p>', $suffix = '</p>') {
+ $count = count($_SESSION['SmartLineOutput'][$output]);
+ if ($count == 0) return;
+ for ($i = 0 ; $i < $count ; $i++)
+ echo $prefix, $_SESSION['SmartLineOutput'][$output][$i], $suffix;
+ unset ($_SESSION['SmartLineOutput'][$output]);
+ }
+
+ public function gethelp ($command) {
+ return $this->commands[$command]->help();
+ }
+
+ private function expression2argv ($expression) {
+ //Checks if expression contains "
+ $pos1 = strpos($expression, '"');
+
+ //We isolate "subexpression"
+ if ($pos1 !== false) {
+ $pos2 = $pos1;
+ do {
+ $pos2 = strpos($expression, '"', $pos2 + 1);
+ } while ($pos2 !== false && ($expression[$pos2 - 1] == "\\" && $expression[$pos2 - 2] != "\\"));
+
+ if ($pos2 === false) {
+ //If final quote is missing, throws a warning and autoadds it.
+ $this->puts("[Warning] Final \" missing in $expression.", STDERR);
+ $argv = $this->expression2argv(substr($expression, 0, $pos1));
+ $argv[] = substr($expression, $pos1 + 1);
+ return $argv;
+ }
+ return array_merge(
+ $this->expression2argv(substr($expression, 0, $pos1)),
+ array(substr($expression, $pos1 + 1, $pos2 - $pos1 - 1)),
+ $this->expression2argv(substr($expression, $pos2 + 1))
+ );
+ }
+
+ //Standard expression (ie without ")
+ $argv = array();
+ $items = explode(' ', $expression);
+ foreach ($items as $item) {
+ $item = trim($item);
+ if (!$item) {
+ //blank, we ignore
+ continue;
+ }
+ $argv[] = $item;
+ }
+ return $argv;
+ }
+
+ //Contains last error
+ public $lastError = '';
+
+ //If true, command isn't equal to Command
+ public $caseSensitive = true;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// SECTION IV - STANDARD COMMANDS
+///////////////////////////////////////////////////////////////////////////////
+
+/*
+ * These commands are availaible in all default smartlines instance
+ */
+
+//Standard command "showcommands"
+class ShowCommandsSmartLineCommand extends SmartLineCommand {
+ public function run ($argv, $argc) {
+ $commands = array_keys($this->SmartLine->commands);
+ sort($commands);
+ $this->SmartLine->puts(implode(' ', $commands));
+ }
+}
+
+//Standard command "help"
+class HelpSmartLineCommand extends SmartLineCommand {
+ public function run ($argv, $argc) {
+ global $lang;
+ if ($argc == 1) {
+ $this->SmartLine->puts($lang['DefaultHelp']);
+ } elseif (!$this->SmartLine->isRegistered($argv[1])) {
+ $this->SmartLine->puts(sprintf($lang['InvalidCommand'], str_replace(' ', '&nbsp;', $argv[1])), STDERR);
+ } else {
+ $command = strtolower($argv[1]);
+ if (!$help = $this->SmartLine->gethelp($command)) {
+ if (array_key_exists($command, $lang['Help'])) {
+ $help = $lang['Help'][$command];
+ } else {
+ $help = $lang['NotYetHelpForThiscommand'];
+ }
+ }
+ $this->SmartLine->puts($help);
+ }
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
+?>
\ No newline at end of file
diff --git a/includes/SmartLine/ZedCommands.php b/includes/SmartLine/ZedCommands.php
new file mode 100644
--- /dev/null
+++ b/includes/SmartLine/ZedCommands.php
@@ -0,0 +1,110 @@
+<?php
+
+/*
+ * Zed
+ * (c) 2010, Dereckson, some rights reserved
+ * Released under BSD license
+ *
+ * SmartLine
+ *
+ */
+
+///
+/// Register commands
+///
+
+$smartLine->register_object('goto', 'GotoLineCommand');
+$smartLine->register_object('list', 'ListSmartLineCommand');
+$smartLine->register_object('unixtime', 'UnixTimeSmartLineCommand');
+
+///
+/// list
+///
+$lang['Help']['list'] = "Lists specified objects (bodies)";
+
+class ListSmartLineCommand extends SmartLineCommand {
+ public function run ($argv, $argc) {
+ if ($argc == 1) {
+ $this->SmartLine->puts("Available lists: bodies");
+ return;
+ }
+
+ switch ($objects = $argv[1]) {
+ case 'bodies':
+ $list = $this->get_list(TABLE_BODIES, "CONCAT('B', body_code)", "body_name");
+ $this->SmartLine->puts($list);
+ break;
+
+ case 'places':
+ if ($argv[2] == "-a" || $argv[2] == "--all") {
+ //Global bodies places list
+ $list = $this->get_list(TABLE_PLACES, "CONCAT('B', body_code, place_code)", "place_name");
+ } else {
+ //Local places (or equivalent) list
+ global $CurrentPerso;
+ switch ($CurrentPerso->location_global[0]) {
+ case 'B':
+ $body_code = substr($CurrentPerso->location_global, 1, 5);
+ $list = $this->get_list(TABLE_PLACES, "CONCAT('B', body_code, place_code)", "place_name", "body_code = $body_code");
+ break;
+
+ case 'S':
+ $this->SmartLine->puts("I don't have a map of the spaceship.", STDERR);
+ return;
+
+ default:
+ $this->SmartLine->puts("Unknown location type. Can only handle B or S.", STDERR);
+ return;
+ }
+ }
+ $this->SmartLine->puts($list);
+ break;
+
+ default:
+ $this->SmartLine->puts("Unknown objects to list: $objects", STDERR);
+ }
+
+ }
+
+ public function get_list ($table, $key, $value, $where = null) {
+ global $db;
+ $sql = "SELECT $key as `key`, $value as value FROM $table ";
+ if ($where) $sql .= "WHERE $where ";
+ $sql .= "ORDER BY `key` ASC";
+ if (!$result = $db->sql_query($sql)) {
+ message_die(SQL_ERROR, "Unable to fetch list", '', __LINE__, __FILE__, $sql);
+ }
+ while ($row = $db->sql_fetchrow($result)) {
+ $rows .= "<tr><td>$row[key]</td><td>$row[value]</td></tr>";
+ }
+ $this->SmartLine->truncate(STDERR);
+ return "<table cellpadding=4><thead scope=\"row\"><tr><th>Key</th><th>Value</th></thead><tbody>$rows</tbody></table>";
+ }
+}
+
+///
+/// unixtime
+///
+
+$lang['Help']['unixtime'] = "Prints current unixtime (seconds elapsed since 1970-01-01 00:00, UTC) or the specified unixtime date.";
+
+class UnixTimeSmartLineCommand extends SmartLineCommand {
+ public function run ($argv, $argc) {
+ date_default_timezone_set('UTC');
+ if ($argc == 1) {
+ $this->SmartLine->puts(time());
+ } elseif ($argc == 2 && is_numeric($argv[1])) {
+ $this->SmartLine->puts(strftime("%Y-%m-%d %X", $argv[1]));
+ } else {
+ array_shift($argv);
+ $date = implode(' ', $argv);
+ if ($time = strtotime($date) !== false) {
+ $this->SmartLine->puts("Unixtime from $date: <span class=\"highlight\">$time</span>");
+ } else {
+ $this->SmartLine->puts("$date isn't a unixtime nor a valid date strtotime is able to parse.", STDERR);
+ }
+ }
+ }
+}
+
+?>
\ No newline at end of file
diff --git a/includes/SmartLine/ZedSmartLine.php b/includes/SmartLine/ZedSmartLine.php
new file mode 100644
--- /dev/null
+++ b/includes/SmartLine/ZedSmartLine.php
@@ -0,0 +1,73 @@
+<?php
+
+/*
+ * Zed
+ * (c) 2010, Dereckson, some rights reserved
+ * Released under BSD license
+ *
+ * SmartLine
+ *
+ */
+
+///
+/// Helpers
+///
+
+/*
+ * Logs a Smartline command
+ * @param string $command the command to log
+ * @param boolean $isError indicates if the command is an error
+ */
+function log_C ($command, $isError = false) {
+ global $db, $CurrentPerso;
+ $isError = $isError ? 1 : 0;
+ $command = $db->sql_escape($command);
+ $sql = "INSERT INTO " . TABLE_LOG_SMARTLINE . " (perso_id, command_time, command_text, isError)
+ VALUES ($CurrentPerso->id, UNIX_TIMESTAMP(), '$command', $isError)";
+ if (!$db->sql_query($sql))
+ message_die(SQL_ERROR, "Historique C", '', __LINE__, __FILE__, $sql);
+}
+
+///
+/// Executes command
+///
+
+if ($C = $_POST['C']) {
+ //Initializes SmartLine object
+ require_once("SmartLine.php");
+ $smartLine = new SmartLine();
+
+ require_once("ZedCommands.php");
+
+ //Executes SmartLine
+ $smartLine->execute($C);
+
+ $error = $smartLine->count(STDERR) > 0;
+
+ if ($smartLine->count(STDOUT) > 0)
+ $smarty->assign("SmartLine_STDOUT", $smartLine->gets_all(STDOUT, '', '<br />'));
+
+ if ($error)
+ $smarty->assign("SmartLine_STDERR", $smartLine->gets_all(STDERR, '', '<br />'));
+
+ log_C($C, $error);
+}
+
+///
+/// Gets SmartLine history
+///
+
+$sql = "SELECT command_time, command_text FROM log_smartline
+ WHERE isError = 0 AND perso_id = $CurrentPerso->id
+ ORDER BY command_time DESC LIMIT 100";
+if (!$result = $db->sql_query($sql)) {
+ message_die(SQL_ERROR, "Wiki fetching", '', __LINE__, __FILE__, $sql);
+}
+$i = 0;
+while ($row = $db->sql_fetchrow($result)) {
+ $commands[$i]->time = get_hypership_time($row['command_time']);
+ $commands[$i]->text = $row['command_text'];
+ $i++;
+}
+$smarty->assign("SmartLineHistory", $commands);
+?>
\ No newline at end of file
diff --git a/lang/en/footer.conf b/lang/en/footer.conf
new file mode 100644
--- /dev/null
+++ b/lang/en/footer.conf
@@ -0,0 +1,1 @@
+SmartLineHistory = SmartLine History
\ No newline at end of file
diff --git a/lang/fr/footer.conf b/lang/fr/footer.conf
new file mode 100644
--- /dev/null
+++ b/lang/fr/footer.conf
@@ -0,0 +1,1 @@
+SmartLineHistory = Historique SmartLine
\ No newline at end of file
diff --git a/skins/zed/error_block.tpl b/skins/zed/error_block.tpl
new file mode 100644
--- /dev/null
+++ b/skins/zed/error_block.tpl
@@ -0,0 +1,17 @@
+ <div class="clear clearfix"></div>
+ <div class="grid_16 alpha omega">
+ <h1>{$TITLE}</h1>
+ <p>{$ERROR_TEXT}</p>
+ <p><a href="/">{#BackToHome#}</a></p>
+ </div>
+ <div class="clear"></div>
+ <hr />
+ <div class="grid_12 alpha">
+ <p>[ {#Product#} / {#FatalErrorInterrupt#} ]</p>
+ </div>
+ <div class="grid_4 omega">
+ <p style="text-align: right">[ <a href="/?action=user.logout">{#Logout#}</a> ]</p>
+ </div>
+</div>
+</body>
+</html>
\ No newline at end of file
diff --git a/skins/zed/smartline.tpl b/skins/zed/smartline.tpl
new file mode 100644
--- /dev/null
+++ b/skins/zed/smartline.tpl
@@ -0,0 +1,23 @@
+ <!-- SmartLine -->
+ <div class="grid_16 alpha omega" id="SmartLine">
+ <!-- SmartLine line -->
+ <form method="post" name="SmartLine">
+{if $SmartLineHistory}
+ <div class="grid_4 left alpha">
+ <select name="SmartLineHistory" id="SmartLineHistory" class="black" onChange=UpdateSmartLine()>
+ <option value="">[ {#SmartLineHistory#} ]</option>
+{foreach from=$SmartLineHistory item=command}
+ <option value="{$command->text|escape}">{$command->time} | {$command->text|escape}</option>
+{/foreach}
+ </select>
+ </div>
+ <div class="grid_12 right omega">
+{else}
+ <div class="grid_16 alpha omega left" style="width: 100.2%">
+{/if}
+ <input name="C" type="text" id="SmartLineBar" maxlength=255 class="black" style="text-align: left;">
+ </div>
+ </form>
+ </div>
+
+ <div class="clear"></div>
\ No newline at end of file
diff --git a/skins/zed/smartline_results.tpl b/skins/zed/smartline_results.tpl
new file mode 100644
--- /dev/null
+++ b/skins/zed/smartline_results.tpl
@@ -0,0 +1,11 @@
+ <!-- SmartLine output -->
+ <div id="SmartLineResults" class="black">
+{if $SmartLine_STDOUT}
+ <p>{$SmartLine_STDOUT}</p>
+{/if}
+{if $SmartLine_STDERR}
+ <p class="error">{$SmartLine_STDERR}</p>
+{/if}
+ </div>
+
+ <div class="clear"></div>
\ No newline at end of file

File Metadata

Mime Type
text/x-diff
Expires
Sun, Nov 10, 18:12 (2 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
20962
Default Alt Text
(20 KB)

Event Timeline