commit 5c9c56eb9a505ddb5ee88c421345c19c694a1c44
parent 1391315a90d3560777707c4054a09851eabc09e5
Author: markseu <mark2011@mayberg.se>
Date: Fri, 7 Jun 2013 22:01:12 +0200
Hello command line
Diffstat:
5 files changed, 92 insertions(+), 16 deletions(-)
diff --git a/.htaccess b/.htaccess
@@ -11,7 +11,8 @@ RewriteRule ^media/plugins/(core_.+) system/core/$1 [L]
RewriteCond %{REQUEST_URI} \.(css|js|png)$
RewriteRule ^media/plugins/(.+) system/plugins/$1 [L]
+RewriteRule ^$ yellow.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
-RewriteRule ^ index.php [L]
+RewriteRule ^ yellow.php [L]
</IfModule>
diff --git a/index.php b/index.php
@@ -1,5 +0,0 @@
-<?php
-require_once("system/core/core.php");
-$yellow = new Yellow();
-$yellow->request();
-?>
diff --git a/system/core/core.php b/system/core/core.php
@@ -5,7 +5,7 @@
// Yellow main class
class Yellow
{
- const Version = "0.1.3";
+ const Version = "0.1.4";
var $page; //current page data
var $pages; //current page tree from file system
var $toolbox; //toolbox with helpers
@@ -26,7 +26,8 @@ class Yellow
$this->config->setDefault("template", "default");
$this->config->setDefault("style", "default");
$this->config->setDefault("yellowVersion", Yellow::Version);
- $this->config->setDefault("baseLocation", $this->toolbox->getBaseLocation());
+ $this->config->setDefault("serverName", $this->toolbox->getServerName());
+ $this->config->setDefault("baseLocation", $this->toolbox->getServerBase());
$this->config->setDefault("styleLocation", "/media/styles/");
$this->config->setDefault("imageLocation", "/media/images/");
$this->config->setDefault("pluginLocation", "media/plugins/");
@@ -48,12 +49,11 @@ class Yellow
$this->config->load($this->config->get("configDir").$this->config->get("configFile"));
$this->text->load($this->config->get("configDir").$this->config->get("textStringFile"), $this->toolbox);
}
-
+
// Start and handle request
function request()
{
$this->toolbox->timerStart($time);
- $this->plugins->load();
$this->processRequest();
$this->toolbox->timerStop($time);
if(defined("DEBUG") && DEBUG>=1) echo "Yellow::request time:$time ms<br>\n";
@@ -114,7 +114,8 @@ class Yellow
if($this->toolbox->isFileLocation($location) && is_dir($this->getContentDirectory("$location/")))
{
$statusCode = 301;
- $this->sendStatus($statusCode, "Location: http://$_SERVER[SERVER_NAME]$baseLocation$location/");
+ $serverName = $this->config->get("serverName");
+ $this->sendStatus($statusCode, "Location: http://$serverName$baseLocation$location/");
} else {
$statusCode = 404;
}
@@ -211,6 +212,16 @@ class Yellow
$this->config->get("contentDir"), $this->config->get("contentHomeDir"), "", "");
}
+ // Execute a plugin command
+ function plugin($name, $args = NULL)
+ {
+ $statusCode = 0;
+ if(!$this->plugins->isExisting($name)) die("Pluggin '$name' does not exist!");
+ $plugin = $this->plugins->plugins[$name];
+ if(method_exists($plugin["obj"], "onCommand")) $statusCode = $plugin["obj"]->onCommand(func_get_args());
+ return $statusCode;
+ }
+
// Register plugin
function registerPlugin($name, $class, $version)
{
@@ -606,12 +617,18 @@ class Yellow_Pages
// Yellow toolbox with helpers
class Yellow_Toolbox
{
- // Return base location from current HTTP request
- static function getBaseLocation()
+ // Return server name from current HTTP request
+ static function getServerName()
{
- $baseLocation = "/";
- if(preg_match("/^(.*)\//", $_SERVER["SCRIPT_NAME"], $matches)) $baseLocation = $matches[1];
- return $baseLocation;
+ return $_SERVER["SERVER_NAME"];
+ }
+
+ // Return server base from current HTTP request
+ static function getServerBase()
+ {
+ $serverBase = "/";
+ if(preg_match("/^(.*)\//", $_SERVER["SCRIPT_NAME"], $matches)) $serverBase = $matches[1];
+ return $serverBase;
}
// Return location from current HTTP request
@@ -1137,6 +1154,7 @@ class Yellow_Plugins
global $yellow;
require_once("core_markdown.php");
require_once("core_rawhtml.php");
+ require_once("core_commandline.php");
require_once("core_webinterface.php");
foreach($yellow->toolbox->getDirectoryEntries($yellow->config->get("pluginDir"), "/.*\.php/", true, false) as $entry)
{
@@ -1183,4 +1201,7 @@ function substru() { return call_user_func_array("mb_substr", func_get_args());
function strlenb() { return call_user_func_array("strlen", func_get_args()); }
function strposb() { return call_user_func_array("strpos", func_get_args()); }
function substrb() { return call_user_func_array("substr", func_get_args()); }
+
+// Error reporting for PHP 5
+error_reporting(E_ALL ^ E_NOTICE);
?>
\ No newline at end of file
diff --git a/system/core/core_commandline.php b/system/core/core_commandline.php
@@ -0,0 +1,44 @@
+<?php
+// Copyright (c) 2013 Datenstrom, http://datenstrom.se
+// This file may be used and distributed under the terms of the public license.
+
+// Command line core plugin
+class Yellow_Commandline
+{
+ const Version = "0.0.0"; //Hello command line!
+ var $yellow; //access to API
+
+ // Initialise plugin
+ function initPlugin($yellow)
+ {
+ $this->yellow = $yellow;
+ }
+
+ // Handle command
+ function onCommand($args)
+ {
+ $statusCode = 0;
+ list($name, $command) = $args;
+ if($command == "version") $statusCode = $this->version($args);
+ else $this->help();
+ return $statusCode;
+ }
+
+ // Show available commands
+ function help()
+ {
+ echo "Yellow command line ".Yellow_Commandline::Version."\n";
+ echo "Syntax: yellow version\n";
+ }
+
+ // Show software version
+ function version($args)
+ {
+ echo "Yellow ".Yellow::Version."\n";
+ foreach($this->yellow->plugins->plugins as $key=>$value) echo "$value[class] $value[version]\n";
+ return 0;
+ }
+}
+
+$yellow->registerPlugin("commandline", "Yellow_Commandline", Yellow_Commandline::Version);
+?>
+\ No newline at end of file
diff --git a/yellow.php b/yellow.php
@@ -0,0 +1,13 @@
+<?php
+require_once("system/core/core.php");
+if(PHP_SAPI != "cli")
+{
+ $yellow = new Yellow();
+ $yellow->plugins->load();
+ $yellow->request();
+} else {
+ $yellow = new Yellow();
+ $yellow->plugins->load();
+ $yellow->plugin("commandline", $argv[1], $argv[2], $argv[3], $argv[4], $argv[5]);
+}
+?>
+\ No newline at end of file