diff --git a/inc/classes/csslisible.class.php b/inc/classes/csslisible.class.php index 00849b5..b9cf770 100644 --- a/inc/classes/csslisible.class.php +++ b/inc/classes/csslisible.class.php @@ -175,6 +175,14 @@ function __construct($args = array(), $values = array()) { $values = $_POST; } + if(php_sapi_name() === 'cli'){ + $values = getopt('', array('filename::','tab_opened::')); + $values['clean_css'] = '1'; + if(!isset($values['tab_opened'])){ + $values['tab_opened'] = 'file'; + } + } + $this->set_default_values($values); $this->posted_values = $this->translating_values($this->posted_values); @@ -359,6 +367,12 @@ private function get_url_contents( $url ) { private function get_buffer_from_files() { + if (php_sapi_name() === 'cli') { + if (isset($this->posted_values['filename']) && is_readable($this->posted_values['filename']) && pathinfo($this->posted_values['filename'], PATHINFO_EXTENSION) === 'css') { + $this->buffer = file_get_contents($this->posted_values['filename']); + } + } + if ( isset( $_FILES['clean_css_file']['name'][0] ) ) { $buffer_tmp = ''; // Obtaining clean array of files diff --git a/inc/header.php b/inc/header.php index 7f1a8c1..838d447 100644 --- a/inc/header.php +++ b/inc/header.php @@ -28,15 +28,19 @@ $_posted_values = $_POST; } -if (empty($_posted_values) && $_SERVER['REQUEST_METHOD'] === 'POST') { +if (empty($_posted_values) && isset($_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] === 'POST') { $input = file_get_contents('php://input'); $_posted_values = json_decode($input, true); } +if (php_sapi_name() === 'cli') { + $_posted_values = getopt('', array('filename::')); +} + $args['listing_proprietes'] = $listing_proprietes; $CSSLisible = new CSSLisible( $args, $_posted_values ); -if ( isset( $_posted_values['api'] ) || isset( $_GET['api'] ) ) { +if ( isset( $_posted_values['api'] ) || isset( $_GET['api'] ) || php_sapi_name() === 'cli' ) { header( 'Content-type: text/css; charset=utf-8' ); exit( $CSSLisible->buffer ); }