Hello command line

This commit is contained in:
markseu 2013-06-07 22:01:12 +02:00 committed by Dominik Wilkowski
parent 8fce351cf0
commit c956825e24
5 changed files with 90 additions and 16 deletions

View file

@ -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>

View file

@ -1,5 +0,0 @@
<?php
require_once("system/core/core.php");
$yellow = new Yellow();
$yellow->request();
?>

View file

@ -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);
?>

View file

@ -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);
?>

13
yellow.php Executable file
View file

@ -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]);
}
?>