From 25277b2b2f37896470c7d709400375519c7d835a Mon Sep 17 00:00:00 2001 From: andy Date: Wed, 14 May 2014 12:02:45 +0200 Subject: [PATCH] Added tt-rss-mobilize plugin for supporting Readability and other mobilizer services out of the box. --- Dockerfile | 11 ++++++-- configure-db.php | 45 ++------------------------------ configure-plugin-mobilize.php | 49 +++++++++++++++++++++++++++++++++++ run.sh | 3 +++ ttrss-plugin-mobilize.pgsql | 9 +++++++ utils.php | 45 ++++++++++++++++++++++++++++++++ 6 files changed, 117 insertions(+), 45 deletions(-) create mode 100644 configure-plugin-mobilize.php create mode 100644 run.sh create mode 100644 ttrss-plugin-mobilize.pgsql create mode 100644 utils.php diff --git a/Dockerfile b/Dockerfile index 0faed16..40e030c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,11 +27,15 @@ WORKDIR /var/www/ttrss RUN cp config.php-dist config.php RUN sed -i -e "/'SELF_URL_PATH'/s/ '.*'/ 'http:\/\/localhost\/'/" config.php -# install feedly theme +# install Feedly theme RUN git clone https://github.com/levito/tt-rss-feedly-theme.git RUN ln -s /var/www/ttrss/tt-rss-feedly-theme/feedly /var/www/ttrss/themes/feedly RUN ln -s /var/www/ttrss/tt-rss-feedly-theme/feedly.css /var/www/ttrss/themes/feedly.css +# install ttrss-mobilize plugin +RUN git clone https://github.com/sepich/tt-rss-mobilize.git /var/www/ttrss/plugins/mobilize +ADD ttrss-plugin-mobilize.pgsql /var/www/ttrss/plugins/mobilize/ttrss-plugin-mobilize.pgsql + # apply ownership of ttrss + addons to www-data RUN chown www-data:www-data -R /var/www @@ -44,6 +48,9 @@ ENV DB_USER ttrss ENV DB_PASS ttrss # always re-configure database with current ENV when RUNning container, then monitor all services +ADD run.sh /run.sh +ADD utils.php /utils.php ADD configure-db.php /configure-db.php +ADD configure-plugin-mobilize.php /configure-plugin-mobilize.php ADD supervisord.conf /etc/supervisor/conf.d/supervisord.conf -CMD php /configure-db.php && supervisord -c /etc/supervisor/conf.d/supervisord.conf +CMD sh /run.sh && supervisord -c /etc/supervisor/conf.d/supervisord.conf diff --git a/configure-db.php b/configure-db.php index e71140a..911f490 100644 --- a/configure-db.php +++ b/configure-db.php @@ -1,6 +1,8 @@ #!/usr/bin/env php $value) { $contents = preg_replace('/(define\s*\(\'' . $name . '\',\s*)(.*)(\);)/', '$1"' . $value . '"$3', $contents); } file_put_contents($confpath, $contents); - -function env($name, $default = null) -{ - $v = getenv($name) ?: $default; - - if ($v === null) { - error('The env ' . $name . ' does not exist'); - } - - return $v; -} - -function error($text) -{ - echo 'Error: ' . $text . PHP_EOL; - exit(1); -} - -function dbconnect($config) -{ - $map = array('host' => 'HOST', 'port' => 'PORT', 'dbname' => 'NAME', 'user' => 'USER', 'password' => 'PASS'); - $dsn = $config['DB_TYPE'] . ':'; - foreach ($map as $d => $h) { - if (isset($config['DB_' . $h])) { - $dsn .= $d . '=' . $config['DB_' . $h] . ';'; - } - } - $pdo = new \PDO($dsn); - $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - return $pdo; -} - -function dbcheck($config) -{ - try { - dbconnect($config); - return true; - } - catch (PDOException $e) { - return false; - } -} - diff --git a/configure-plugin-mobilize.php b/configure-plugin-mobilize.php new file mode 100644 index 0000000..c0e614c --- /dev/null +++ b/configure-plugin-mobilize.php @@ -0,0 +1,49 @@ +#!/usr/bin/env php +query('SELECT 1 FROM plugin_mobilize_feeds'); + // reached this point => table found, assume db is complete +} +catch (PDOException $e) { + echo 'Database table for mobilize plugin not found, applying schema... ' . PHP_EOL; + $schema = file_get_contents('plugins/mobilize/ttrss-plugin-mobilize.pgsql'); + $schema = preg_replace('/--(.*?);/', '', $schema); + $schema = preg_replace('/[\r\n]/', ' ', $schema); + $schema = trim($schema, ' ;'); + foreach (explode(';', $schema) as $stm) { + $pdo->exec($stm); + } + unset($pdo); +} + +$contents = file_get_contents($confpath); +foreach ($config as $name => $value) { + $contents = preg_replace('/(define\s*\(\'' . $name . '\',\s*)(.*)(\);)/', '$1"' . $value . '"$3', $contents); +} +file_put_contents($confpath, $contents); diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..a00771e --- /dev/null +++ b/run.sh @@ -0,0 +1,3 @@ +#/bin/sh +php /configure-db.php && \ +php /configure-plugin-mobilize.php diff --git a/ttrss-plugin-mobilize.pgsql b/ttrss-plugin-mobilize.pgsql new file mode 100644 index 0000000..ccd9194 --- /dev/null +++ b/ttrss-plugin-mobilize.pgsql @@ -0,0 +1,9 @@ +CREATE TABLE "plugin_mobilize_feeds" ( "id" int NOT NULL, "owner_uid" int NOT NULL, "mobilizer_id" int NOT NULL, PRIMARY KEY ("id","owner_uid") ); +CREATE TABLE "plugin_mobilize_mobilizers" ( "id" int NOT NULL, "description" varchar(255) NOT NULL, "url" varchar(1000) NOT NULL, PRIMARY KEY ("id") ) ; + +INSERT INTO "plugin_mobilize_mobilizers" ( "id", "description", "url") VALUES +(0, 'Readability', 'http://www.readability.com/m?url=%s'), +(1, 'Instapaper', 'http://www.instapaper.com/m?u=%s'), +(2, 'Google Mobilizer', 'http://www.google.com/gwt/x?u=%s'), +(3, 'Original Stripped', 'http://strip=%s'), +(4, 'Original', '%s'); diff --git a/utils.php b/utils.php new file mode 100644 index 0000000..99279eb --- /dev/null +++ b/utils.php @@ -0,0 +1,45 @@ + 'HOST', 'port' => 'PORT', 'dbname' => 'NAME', 'user' => 'USER', 'password' => 'PASS'); + $dsn = $config['DB_TYPE'] . ':'; + foreach ($map as $d => $h) { + if (isset($config['DB_' . $h])) { + $dsn .= $d . '=' . $config['DB_' . $h] . ';'; + } + } + $pdo = new \PDO($dsn); + $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + return $pdo; +} + +function dbcheck($config) +{ + try { + dbconnect($config); + return true; + } + catch (PDOException $e) { + return false; + } +} + +?>