- `cutycapt <http://cutycapt.sourceforge.net/>`_
- imagemagick's ``convert``
- ``xvfb-run``
-
+- PEAR's ``System.php``
=======================
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)
class Options
{
- public static $options = array(
+ public $options = array(
/**
* Browser settings
*/
*/
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'])) {
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;
}
}
?>
<?php
+namespace phancap;
+/**
+ * Check if everything is setup
+ */
+header('HTTP/1.0 500 Internal Server Error');
+if (file_exists(__DIR__ . '/../src/phancap/Autoloader.php')) {
+ include_once __DIR__ . '/../src/phancap/Autoloader.php';
+ Autoloader::register();
+} else {
+ include_once 'phancap/Autoloader.php';
+}
+header('HTTP/1.0 200 OK');
+?>
+<?xml version="1.0" encoding="utf-8"?>
+<html>
+ <head>
+ <title>phancap</title>
+ </head>
+ <body>
+ <h1>phancap</h1>
+ <p>
+ Web service to create website screenshots.
+ </p>
+
+ <h2>API</h2>
+ <p>
+ The API is accessible at <a href="get.php">get.php</a>.
+ </p>
+ <table border="1">
+ <caption>Available URL parameters</caption>
+ <thead>
+ <tr>
+ <th>Name</th>
+ <th>Description</th>
+ <th>Type</th>
+ <th>Default</th>
+ </tr>
+ </thead>
+ <tbody>
+<?php
+$options = new Options();
+$config = new Config();
+try {
+ $config->load();
+ $options->setConfig($config);
+} catch (\Exception $e) {}
+foreach ($options->options as $name => $option) {
+ echo '<tr>'
+ . '<td><tt>' . $name . '</tt></td>'
+ . '<td>' . htmlspecialchars($option['title']) . '</td>'
+ . '<td>'
+ . (
+ is_array($option['type'])
+ ? ('One of: <tt>' . implode('</tt>, <tt>', $option['type']) . '</tt>')
+ : str_replace('skip', ' ', $option['type'])
+ )
+ . '</td>'
+ . '<td> <tt>' . $option['default'] . '</tt></td>'
+ . '</tr>';
+}
?>
+ </tbody>
+ </table>
+
+
+ <h2>Tools</h2>
+ <ul>
+ <li>
+ <a href="setup.php">Setup check</a> to test if everything is ok
+ </li>
+ </ul>
+ </body>
+</html>
--- /dev/null
+<?php
+namespace phancap;
+/**
+ * Check if everything is setup
+ */
+header('HTTP/1.0 500 Internal Server Error');
+
+if (file_exists(__DIR__ . '/../src/phancap/Autoloader.php')) {
+ include_once __DIR__ . '/../src/phancap/Autoloader.php';
+ Autoloader::register();
+} else {
+ include_once 'phancap/Autoloader.php';
+}
+
+$messages = array();
+
+$config = new Config();
+try {
+ $config->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 = <<<HTM
+<?xml version="1.0" encoding="utf-8"?>
+<html>
+ <head>
+ <title>phancap setup check</title>
+ <style type="text/css">
+ li.ok:before {
+ content: '✔';
+ color: green;
+ padding: 0 0.5ex;
+ margin-right: 1ex;
+ }
+ li.err:before {
+ content: "✘";
+ color: white;
+ background-color: red;
+ padding: 0 0.5ex;
+ margin-right: 0.5ex;
+ }
+ </style>
+ </head>
+ <body>
+ <h1>phancap setup check</h1>
+<ul>
+HTM;
+foreach ($messages as $key => $messages) {
+ if (!is_numeric($key)) {
+ $out .= '<li>' . htmlspecialchars($key)
+ . '<ul>';
+ }
+ foreach ($messages as $data) {
+ list($state, $message) = $data;
+ $out .= '<li class="' . $state . '">';
+ $out .= htmlspecialchars($message);
+ $out .= '</li>' . "\n";
+ }
+ if (!is_numeric($key)) {
+ $out .= '</ul></li>' . "\n";
+ }
+}
+$out .= <<<HTM
+ </ul>
+ <p>
+ <a href="./">back</a> to the index
+ </p>
+ </body>
+</html>
+HTM;
+echo $out;
+?>