commit 4ac14cd3c9705e4d17b47c902f4cbf4038a485c9 Author: Simon Vieille Date: Mon Mar 2 21:51:04 2015 +0100 init diff --git a/DEBIAN/.control.swp b/DEBIAN/.control.swp new file mode 100644 index 0000000..f70cfc5 Binary files /dev/null and b/DEBIAN/.control.swp differ diff --git a/DEBIAN/control b/DEBIAN/control new file mode 100644 index 0000000..2d27491 --- /dev/null +++ b/DEBIAN/control @@ -0,0 +1,8 @@ +Package: walldeblan +Version: 0.1 +Section: base +Priority: optional +Architecture: all +Depends: php5 (>= 5.3.3-7+squeeze15), php5-curl +Maintainer: Simon Vieille +Description: Client en ligne de commande pour envoyer des scripts à colorer sur le service en ligne wall.deblan.org. diff --git a/usr/bin/walldeblan b/usr/bin/walldeblan new file mode 100755 index 0000000..dc32b49 --- /dev/null +++ b/usr/bin/walldeblan @@ -0,0 +1,170 @@ +#!/usr/bin/php +curl = curl_init(); + } + + public function setCode($code) + { + $this->code = $code; + + return $this; + } + + public function setCodeFromFile($file) + { + $this->code = (file_exists($file) && is_readable($file)) ? file_get_contents($file) : ''; + + return $this; + } + + public function getCode() + { + return $this->code; + } + + public function setLanguage($language) + { + $this->language = $language; + + return $this; + } + + public function getLanguage() + { + return $this->language; + } + + public function setTitle($title) + { + $this->title = $title; + + return $this; + } + + public function getTitle() + { + return $this->title; + } + + public function setShowLines($showLines) + { + $this->showLines = (bool) $showLines; + + return $this; + } + + public function getShowLines() + { + return $this->showLines; + } + + public function paste() + { + $options = array( + CURLOPT_URL => 'https://wall.deblan.org', + CURLOPT_HEADER => true, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_POST => true, + CURLOPT_POSTFIELDS => http_build_query(array( + 'code' => $this->getCode(), + 'language' => $this->getLanguage(), + 'title' => $this->getTitle(), + 'line' => $this->getShowLines() + )) + ); + + curl_setopt_array($this->curl, $options); + + $header = curl_exec($this->curl); + + if (curl_errno($this->curl)) { + throw new WallException('Curl error: '.curl_error($this->curl)); + } else { + $http_code = curl_getinfo($this->curl, CURLINFO_HTTP_CODE); + if (in_array($http_code, array(301, 302, 200))) { + preg_match('`location: ([^\s]+)`i', $header, $matches); + + return 'https://wall.deblan.org'.trim(array_pop($matches)); + } else { + throw new WallException(sprintf('HTTP header error: unexpected response code (%s)', $http_code)); + } + } + } +} + +function getHelp() +{ + global $argv; + + return << [language] +Using "-" as filename for stdin. + +Available languages: + + "html" for HTML + "xml" for XML + "css" for CSS + "javascript" for JAVASCRIPT + "php" for PHP + "sql" for SQL + "yaml" for YAML + "perl" for PERL + "c" for C/C++ + "asp" for ASP + "python" for PYTHON + "bash" for BASH + "actionscript" for ACTION SCRIPT + "texte" for TEXTE +EOH; +} + +try { + if (!isset($argv[1])) { + throw new InvalidArgumentException('I miss the first parameter...'); + } + + Wall::getInstance()->setLanguage(isset($argv[2]) ? $argv[2] : 'texte'); + + if ($argv[1] == '-') { + $handle = fopen('php://stdin', 'r'); + $code = ""; + + while (!feof($handle)) { + $code.= rtrim(fgets($handle)).PHP_EOL; + } + + Wall::getInstance()->setCode($code); + } else { + Wall::getInstance()->setCodeFromFile($argv[1]); + } + + echo Wall::getInstance()->paste(), PHP_EOL; +} catch (WallException $e) { + echo 'WALL ERROR: '.$e->getMessage(); + echo getHelp(); +} catch (Exception $e) { + echo 'SCRIPT ERROR: ', $e->getMessage(), PHP_EOL; + echo getHelp(); +}