Add Task CSV export and Kanboard CLI
This commit is contained in:
75
app/Core/Cli.php
Normal file
75
app/Core/Cli.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace Core;
|
||||
|
||||
use Closure;
|
||||
|
||||
/**
|
||||
* CLI class
|
||||
*
|
||||
* @package core
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class Cli
|
||||
{
|
||||
/**
|
||||
* Default command name
|
||||
*
|
||||
* @access public
|
||||
* @var string
|
||||
*/
|
||||
public $default_command = 'help';
|
||||
|
||||
/**
|
||||
* List of registered commands
|
||||
*
|
||||
* @access private
|
||||
* @var array
|
||||
*/
|
||||
private $commands = array();
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @param string $command Command name
|
||||
* @param Closure $callback Command callback
|
||||
*/
|
||||
public function register($command, Closure $callback)
|
||||
{
|
||||
$this->commands[$command] = $callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a command
|
||||
*
|
||||
* @access public
|
||||
* @param string $command Command name
|
||||
*/
|
||||
public function call($command)
|
||||
{
|
||||
if (isset($this->commands[$command])) {
|
||||
$this->commands[$command]();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine which command to execute
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
if (php_sapi_name() !== 'cli') {
|
||||
die('This script work only from the command line.');
|
||||
}
|
||||
|
||||
if ($GLOBALS['argc'] === 1) {
|
||||
$this->call($this->default_command);
|
||||
}
|
||||
|
||||
$this->call($GLOBALS['argv'][1]);
|
||||
$this->call($this->default_command);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace Core;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
|
||||
@@ -70,6 +70,22 @@ class Response
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a CSV response
|
||||
*
|
||||
* @access public
|
||||
* @param array $data Data to serialize in csv
|
||||
* @param integer $status_code HTTP status code
|
||||
*/
|
||||
public function csv(array $data, $status_code = 200)
|
||||
{
|
||||
$this->status($status_code);
|
||||
$this->nocache();
|
||||
header('Content-Type: text/csv');
|
||||
Tool::csv($data);
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a Json response
|
||||
*
|
||||
@@ -83,7 +99,6 @@ class Response
|
||||
$this->nocache();
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($data);
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -100,7 +115,6 @@ class Response
|
||||
$this->nocache();
|
||||
header('Content-Type: text/plain; charset=utf-8');
|
||||
echo $data;
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -117,7 +131,6 @@ class Response
|
||||
$this->nocache();
|
||||
header('Content-Type: text/html; charset=utf-8');
|
||||
echo $data;
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -134,7 +147,6 @@ class Response
|
||||
$this->nocache();
|
||||
header('Content-Type: text/xml; charset=utf-8');
|
||||
echo $data;
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -169,7 +181,6 @@ class Response
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
header('Content-Type: application/octet-stream');
|
||||
echo $data;
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
34
app/Core/Tool.php
Normal file
34
app/Core/Tool.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Core;
|
||||
|
||||
/**
|
||||
* Tool class
|
||||
*
|
||||
* @package core
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class Tool
|
||||
{
|
||||
/**
|
||||
* Write a CSV file
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @param array $rows Array of rows
|
||||
* @param string $filename Output filename
|
||||
*/
|
||||
public static function csv(array $rows, $filename = 'php://output')
|
||||
{
|
||||
$fp = fopen($filename, 'w');
|
||||
|
||||
if (is_resource($fp)) {
|
||||
|
||||
foreach ($rows as $fields) {
|
||||
fputcsv($fp, $fields);
|
||||
}
|
||||
|
||||
fclose($fp);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,26 @@ class Translator
|
||||
*/
|
||||
private static $locales = array();
|
||||
|
||||
/**
|
||||
* Flag to enable HTML escaping
|
||||
*
|
||||
* @static
|
||||
* @access private
|
||||
* @var boolean
|
||||
*/
|
||||
private static $enable_escaping = true;
|
||||
|
||||
/**
|
||||
* Disable HTML escaping for translations
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
*/
|
||||
public static function disableEscaping()
|
||||
{
|
||||
self::$enable_escaping = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a translation
|
||||
*
|
||||
@@ -42,8 +62,10 @@ class Translator
|
||||
array_shift($args);
|
||||
array_unshift($args, $this->get($identifier, $identifier));
|
||||
|
||||
foreach ($args as &$arg) {
|
||||
$arg = htmlspecialchars($arg, ENT_QUOTES, 'UTF-8', false);
|
||||
if (self::$enable_escaping) {
|
||||
foreach ($args as &$arg) {
|
||||
$arg = htmlspecialchars($arg, ENT_QUOTES, 'UTF-8', false);
|
||||
}
|
||||
}
|
||||
|
||||
return call_user_func_array(
|
||||
|
||||
Reference in New Issue
Block a user