Skip to content

Commit

Permalink
Basic CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
Darklg committed Dec 15, 2024
1 parent 7da6adb commit d73b5e8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
14 changes: 14 additions & 0 deletions inc/classes/csslisible.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions inc/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

0 comments on commit d73b5e8

Please sign in to comment.