From 9379b9f65e1231053a41271ba20c8b161726cc70 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Wed, 9 Apr 2014 20:03:15 +0200 Subject: [PATCH] index that shows options and setup check --- README.rst | 2 +- src/phancap/Adapter/Cutycapt.php | 22 +++++++- src/phancap/Options.php | 8 +-- www/index.php | 72 ++++++++++++++++++++++++ www/setup.php | 95 ++++++++++++++++++++++++++++++++ 5 files changed, 193 insertions(+), 6 deletions(-) create mode 100644 www/setup.php diff --git a/README.rst b/README.rst index 78a67ec..17faa8e 100644 --- a/README.rst +++ b/README.rst @@ -157,7 +157,7 @@ Dependencies - `cutycapt `_ - imagemagick's ``convert`` - ``xvfb-run`` - +- PEAR's ``System.php`` ======================= diff --git a/src/phancap/Adapter/Cutycapt.php b/src/phancap/Adapter/Cutycapt.php index 863c732..461fdaa 100644 --- a/src/phancap/Adapter/Cutycapt.php +++ b/src/phancap/Adapter/Cutycapt.php @@ -6,9 +6,29 @@ class Adapter_Cutycapt protected $lockHdl; protected $lockFile = null; + /** + * @return mixed TRUE if all is fine, array with error messages otherwise + */ public function isAvailable() { - //FIXME: setup check for xvfbrun, cutycapt, convert + $old = error_reporting(error_reporting() & ~E_STRICT); + $arErrors = array(); + if (\System::which('xvfb-run') === false) { + $arErrors[] = '"xvfb-run" is not installed'; + } + if (\System::which('cutycapt') === false) { + $arErrors[] = '"cutycapt" is not installed'; + } + if (\System::which('convert') === false) { + $arErrors[] = '"convert" (imagemagick) is not installed'; + } + + error_reporting($old); + if (count($arErrors)) { + return $arErrors; + } + + return true; } public function render(Image $img, Options $options) diff --git a/src/phancap/Options.php b/src/phancap/Options.php index b51f2a7..6aaa49f 100644 --- a/src/phancap/Options.php +++ b/src/phancap/Options.php @@ -3,7 +3,7 @@ namespace phancap; class Options { - public static $options = array( + public $options = array( /** * Browser settings */ @@ -96,7 +96,7 @@ class Options */ public function parse($arValues) { - foreach (static::$options as $name => $arOption) { + foreach ($this->options as $name => $arOption) { $this->values[$name] = $arOption['default']; if (!isset($arValues[$name])) { if (isset($arOption['required'])) { @@ -263,8 +263,8 @@ class Options public function setConfig(Config $config) { $this->config = $config; - static::$options['smaxage']['default'] = $this->config->screenshotMaxAge; - static::$options['smaxage']['min'] = $this->config->screenshotMinAge; + $this->options['smaxage']['default'] = $this->config->screenshotMaxAge; + $this->options['smaxage']['min'] = $this->config->screenshotMinAge; } } ?> diff --git a/www/index.php b/www/index.php index 6eff33c..7036104 100644 --- a/www/index.php +++ b/www/index.php @@ -1,4 +1,76 @@ + + + + phancap + + +

phancap

+

+ Web service to create website screenshots. +

+ +

API

+

+ The API is accessible at get.php. +

+ + + + + + + + + + + +load(); + $options->setConfig($config); +} catch (\Exception $e) {} +foreach ($options->options as $name => $option) { + echo '' + . '' + . '' + . '' + . '' + . ''; +} ?> + +
Available URL parameters
NameDescriptionTypeDefault
' . $name . '' . htmlspecialchars($option['title']) . '' + . ( + is_array($option['type']) + ? ('One of: ' . implode(', ', $option['type']) . '') + : str_replace('skip', ' ', $option['type']) + ) + . ' ' . $option['default'] . '
+ + +

Tools

+ + + diff --git a/www/setup.php b/www/setup.php new file mode 100644 index 0000000..747699a --- /dev/null +++ b/www/setup.php @@ -0,0 +1,95 @@ +load(); + $messages[][] = array('ok', 'Configuration check ok'); +} catch (\Exception $e) { + $messages[][] = array('err', $e->getMessage()); +} + +$adapter = array( + 'Cutycapt' +); +foreach ($adapter as $classpart) { + $class = '\\phancap\\Adapter_' . $classpart; + $adapter = new $class(); + $adapter->setConfig($config); + $errors = $adapter->isAvailable(); + if ($errors === true) { + $messages[][] = array( + 'ok', 'Adapter ' . $classpart . ' is available' + ); + } else { + foreach ($errors as $msg) { + $messages['Adapter: '. $classpart][] = array('err', $msg); + } + } +} + +header('HTTP/1.0 200 OK'); + +$out = << + + + phancap setup check + + + +

phancap setup check

+
    +HTM; +foreach ($messages as $key => $messages) { + if (!is_numeric($key)) { + $out .= '
  • ' . htmlspecialchars($key) + . '
      '; + } + foreach ($messages as $data) { + list($state, $message) = $data; + $out .= '
    • '; + $out .= htmlspecialchars($message); + $out .= '
    • ' . "\n"; + } + if (!is_numeric($key)) { + $out .= '
  • ' . "\n"; + } +} +$out .= << +

    + back to the index +

    + + +HTM; +echo $out; +?> -- 2.30.2