Use classmap autoloader for stapibas classes master github/master
authorChristian Weiske <cweiske@cweiske.de>
Sun, 2 Apr 2023 18:55:24 +0000 (20:55 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Sun, 2 Apr 2023 18:55:24 +0000 (20:55 +0200)
.gitignore
README.rst
bin/stapibas
composer.json [new file with mode: 0644]
composer.lock [new file with mode: 0644]
src/stapibas/PDO.php
src/stapibas/autoloader.php [deleted file]
www/www-header.php
www/xmlrpc.php

index c1892ca6727f2aa4163effb0eef2e3abf91c2afa..16c635b47126570bfab2a5c1e41ee089248ac8cb 100644 (file)
@@ -3,3 +3,5 @@ www/test.htm
 lib/*
 /dist/
 /bin/phar-stapibas.php
+/README.html
+/vendor/
index 22ffb07f6c4010fa4bfaf2c821bde7257b8ba3ab..fea31c2475a459a41cbad875b19ee6fa476ed437 100644 (file)
@@ -1,38 +1,24 @@
 ********
 stapibas
 ********
-The standalone Pingback server, written in PHP.
+The standalone Linkback server, written in PHP.
 
-- Receives linkbacks (webmention and pingbacks)
+- Receives linkbacks (`webmention`__ and `pingbacks`__)
 - Watches your website's Feed to send out linkbacks to all linked URLs
 
-Alternative to `Trackback ‘em All`__
+Alternative to `Trackback ‘em All`__ and `Telegraph`__
 
+__ https://www.w3.org/TR/webmention/
+__ http://www.hixie.ch/specs/pingback/pingback
 __ http://scott.yang.id.au/code/trackback-em-all/
-
-
-============
-Dependencies
-============
-- PHP 5.3+
-- PDO
-- `Console_CommandLine`__
-- `Net_URL2`__
-- `HTTP_Request2`__
-- `PEAR2 Services_Linkback`__
-- `SimplePie`__
-
-__ http://pear.php.net/package/Console_CommandLine
-__ http://pear.php.net/package/Net_URL2
-__ http://pear.php.net/package/HTTP_Request2
-__ https://github.com/pear2/Services_Linkback
-__ http://simplepie.org/
+__ https://telegraph.p3k.io/
 
 
 =================
-Pingback receiver
+Linkback receiver
 =================
-stapibas receives pingbacks for your website and puts them into a database.
+stapibas receives linkbacks (webmentions + pingbacks) for your website
+and puts them into a database.
 
 It also sends them as email to a configured address.
 
@@ -42,24 +28,42 @@ Setup
 Let your website send out the following HTTP headers::
 
   X-Pingback: http://stapibas.example.org/xmlrpc.php
-  Header set Link '<http://stapibas.example.org/xmlrpc.php>; rel="webmention"'
+  Link: '<http://stapibas.example.org/xmlrpc.php>; rel="webmention"'
+
+In Apache you can do this with the following configuration::
+
+  Header set X-Pingback "http://stapibas.example.org/xmlrpc.php"
+  Header append Link '<http://stapibas.example.org/xmlrpc.php>; rel="webmention"'
+
 
 Now, whitelist your domain in the database:
 Add an ``lt_url`` of ``https://example.org/%`` in the ``linkbacktargets`` table.
 
 That's all.
 
+.. note::
+   stapibas does not display the linkbacks in any way - you have to do this yourself.
+
+   If you're looking for a ready-made solution, look at the tools listed
+   on https://indieweb.org/Webmention
+
+
 
 ===============
-Pingback sender
+Linkback sender
 ===============
-stapibas is able to send pingbacks out to other websites at behalf of
+stapibas is able to send linkbacks out to other websites at behalf of
 your website.
 
 It does this by watching your website's Atom (or RSS) feed.
 Whenever it changes, it fetches the articles that are new or got updated and
 sends out pingbacks to the remote websites.
 
+It only works on links that are inside an ``e-content`` section
+that itself has to be inside a `h-entry`__.
+
+__ http://microformats.org/wiki/h-entry
+
 
 Setup
 =====
@@ -74,6 +78,11 @@ HTTP POST request, sending the feed URL::
 
 This tells stapibas to check this feed the next time the pinger runs.
 
+.. note::
+   stapibas does not check itself if the feed changed!
+
+   You need to notify it manually.
+
 
 Run the pinger
 ==============
@@ -83,3 +92,11 @@ extract new URLs from the feed and send pingbacks to them.
 ::
 
    $ php bin/stapibas
+
+
+============
+Dependencies
+============
+- PHP 8.0+
+- PDO
+- PHP libraries that get installed with ``composer install --no-dev``
index 97028ec3af2b5277425cde7c0a4eea185c27b74b..e284137548c2c86c064132a345cc29eda75f8583 100755 (executable)
@@ -2,7 +2,7 @@
 <?php
 namespace stapibas;
 require_once __DIR__ . '/../data/config.php';
-require_once 'stapibas/autoloader.php';
+require_once __DIR__ . '/../vendor/autoload.php';
 
 $cli = new Cli();
 $cli->run();
diff --git a/composer.json b/composer.json
new file mode 100644 (file)
index 0000000..26365d0
--- /dev/null
@@ -0,0 +1,14 @@
+{
+    "name": "cweiske/stapibas",
+    "description": "The standalone Linkback server, written in PHP.",
+    "autoload": {
+        "classmap": ["src/"]
+    },
+    "require": {
+        "pear/console_commandline": "^1.2.6",
+        "pear/net_url2": "^2.2",
+        "pear/http_request2": "^2.5",
+        "pear2/services_linkback": "^0.4.0",
+        "simplepie/simplepie": "^1.8"
+    }
+}
diff --git a/composer.lock b/composer.lock
new file mode 100644 (file)
index 0000000..5c573e1
--- /dev/null
@@ -0,0 +1,439 @@
+{
+    "_readme": [
+        "This file locks the dependencies of your project to a known state",
+        "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
+        "This file is @generated automatically"
+    ],
+    "content-hash": "a228cc8658bd875469df78992799f272",
+    "packages": [
+        {
+            "name": "pear/console_commandline",
+            "version": "v1.2.6",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/pear/Console_CommandLine.git",
+                "reference": "611c5bff2e47ec5a184748cb5fedc2869098ff28"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/pear/Console_CommandLine/zipball/611c5bff2e47ec5a184748cb5fedc2869098ff28",
+                "reference": "611c5bff2e47ec5a184748cb5fedc2869098ff28",
+                "shasum": ""
+            },
+            "require": {
+                "ext-dom": "*",
+                "ext-xml": "*",
+                "pear/pear_exception": "^1.0.0",
+                "php": ">=5.3.0"
+            },
+            "require-dev": {
+                "phpunit/phpunit": "*"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-0": {
+                    "Console": "./"
+                },
+                "exclude-from-classmap": [
+                    "tests/"
+                ]
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "include-path": [
+                ""
+            ],
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Richard Quadling",
+                    "email": "rquadling@gmail.com"
+                },
+                {
+                    "name": "David Jean Louis",
+                    "email": "izimobil@gmail.com"
+                }
+            ],
+            "description": "A full featured command line options and arguments parser.",
+            "homepage": "https://github.com/pear/Console_CommandLine",
+            "keywords": [
+                "console"
+            ],
+            "support": {
+                "issues": "http://pear.php.net/bugs/search.php?cmd=display&package_name[]=Console_CommandLine",
+                "source": "https://github.com/pear/Console_CommandLine"
+            },
+            "time": "2023-04-02T18:49:53+00:00"
+        },
+        {
+            "name": "pear/http2",
+            "version": "v2.0.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/pear/HTTP2.git",
+                "reference": "72e15b4faa86f6109c6fc3aa82c5515b6453b3b5"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/pear/HTTP2/zipball/72e15b4faa86f6109c6fc3aa82c5515b6453b3b5",
+                "reference": "72e15b4faa86f6109c6fc3aa82c5515b6453b3b5",
+                "shasum": ""
+            },
+            "require-dev": {
+                "phpunit/phpunit": "^9"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-0": {
+                    "HTTP2": "./"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "BSD-2-Clause"
+            ],
+            "authors": [
+                {
+                    "name": "Michael Wallner",
+                    "email": "mike@php.net",
+                    "role": "Lead"
+                },
+                {
+                    "name": "Philippe Jausions",
+                    "email": "jausions@php.net",
+                    "role": "Lead"
+                }
+            ],
+            "description": "Miscellaneous HTTP utilities",
+            "homepage": "http://pear.php.net/package/HTTP2",
+            "support": {
+                "issues": "http://pear.php.net/bugs/search.php?cmd=display&package_name[]=HTTP2",
+                "source": "https://github.com/pear/HTTP2"
+            },
+            "time": "2023-03-22T20:22:11+00:00"
+        },
+        {
+            "name": "pear/http_request2",
+            "version": "v2.5.1",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/pear/HTTP_Request2.git",
+                "reference": "db4ce7844f838d3adca0513a77420c0fec22ed2d"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/pear/HTTP_Request2/zipball/db4ce7844f838d3adca0513a77420c0fec22ed2d",
+                "reference": "db4ce7844f838d3adca0513a77420c0fec22ed2d",
+                "shasum": ""
+            },
+            "require": {
+                "pear/net_url2": "^2.2.0",
+                "pear/pear_exception": "^1.0.0",
+                "php": ">=5.6.0"
+            },
+            "require-dev": {
+                "yoast/phpunit-polyfills": "^1.0.0"
+            },
+            "suggest": {
+                "ext-curl": "Allows using cURL as a request backend.",
+                "ext-fileinfo": "Adds support for looking up mime-types using finfo.",
+                "ext-openssl": "Allows handling SSL requests when not using cURL.",
+                "ext-zlib": "Allows handling gzip compressed responses."
+            },
+            "type": "library",
+            "autoload": {
+                "psr-0": {
+                    "HTTP_Request2": ""
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "BSD-3-Clause"
+            ],
+            "authors": [
+                {
+                    "name": "Alexey Borzov",
+                    "email": "avb@php.net"
+                }
+            ],
+            "description": "Provides an easy way to perform HTTP requests.",
+            "homepage": "https://pear.php.net/package/HTTP_Request2",
+            "keywords": [
+                "PEAR",
+                "curl",
+                "http",
+                "request"
+            ],
+            "support": {
+                "docs": "https://pear.php.net/manual/en/package.http.http-request2.php",
+                "issues": "https://github.com/pear/HTTP_Request2/issues",
+                "source": "https://github.com/pear/HTTP_Request2"
+            },
+            "time": "2022-01-06T18:20:25+00:00"
+        },
+        {
+            "name": "pear/net_url2",
+            "version": "v2.2.2",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/pear/Net_URL2.git",
+                "reference": "07fd055820dbf466ee3990abe96d0e40a8791f9d"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/pear/Net_URL2/zipball/07fd055820dbf466ee3990abe96d0e40a8791f9d",
+                "reference": "07fd055820dbf466ee3990abe96d0e40a8791f9d",
+                "shasum": ""
+            },
+            "require": {
+                "php": ">=5.1.4"
+            },
+            "require-dev": {
+                "phpunit/phpunit": ">=3.3.0"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "2.2.x-dev"
+                }
+            },
+            "autoload": {
+                "classmap": [
+                    "Net/URL2.php"
+                ]
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "include-path": [
+                "./"
+            ],
+            "license": [
+                "BSD-3-Clause"
+            ],
+            "authors": [
+                {
+                    "name": "David Coallier",
+                    "email": "davidc@php.net"
+                },
+                {
+                    "name": "Tom Klingenberg",
+                    "email": "tkli@php.net"
+                },
+                {
+                    "name": "Christian Schmidt",
+                    "email": "chmidt@php.net"
+                }
+            ],
+            "description": "Class for parsing and handling URL. Provides parsing of URLs into their constituent parts (scheme, host, path etc.), URL generation, and resolving of relative URLs.",
+            "homepage": "https://github.com/pear/Net_URL2",
+            "keywords": [
+                "PEAR",
+                "net",
+                "networking",
+                "rfc3986",
+                "uri",
+                "url"
+            ],
+            "support": {
+                "issues": "https://pear.php.net/bugs/search.php?cmd=display&package_name[]=Net_URL2",
+                "source": "https://github.com/pear/Net_URL2"
+            },
+            "time": "2017-08-25T06:16:11+00:00"
+        },
+        {
+            "name": "pear/pear_exception",
+            "version": "v1.0.2",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/pear/PEAR_Exception.git",
+                "reference": "b14fbe2ddb0b9f94f5b24cf08783d599f776fff0"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/pear/PEAR_Exception/zipball/b14fbe2ddb0b9f94f5b24cf08783d599f776fff0",
+                "reference": "b14fbe2ddb0b9f94f5b24cf08783d599f776fff0",
+                "shasum": ""
+            },
+            "require": {
+                "php": ">=5.2.0"
+            },
+            "require-dev": {
+                "phpunit/phpunit": "<9"
+            },
+            "type": "class",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "1.0.x-dev"
+                }
+            },
+            "autoload": {
+                "classmap": [
+                    "PEAR/"
+                ]
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "include-path": [
+                "."
+            ],
+            "license": [
+                "BSD-2-Clause"
+            ],
+            "authors": [
+                {
+                    "name": "Helgi Thormar",
+                    "email": "dufuz@php.net"
+                },
+                {
+                    "name": "Greg Beaver",
+                    "email": "cellog@php.net"
+                }
+            ],
+            "description": "The PEAR Exception base class.",
+            "homepage": "https://github.com/pear/PEAR_Exception",
+            "keywords": [
+                "exception"
+            ],
+            "support": {
+                "issues": "http://pear.php.net/bugs/search.php?cmd=display&package_name[]=PEAR_Exception",
+                "source": "https://github.com/pear/PEAR_Exception"
+            },
+            "time": "2021-03-21T15:43:46+00:00"
+        },
+        {
+            "name": "pear2/services_linkback",
+            "version": "v0.4.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/pear2/Services_Linkback.git",
+                "reference": "61790889871cae0bc6e54adb2637b9e0ec93275f"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/pear2/Services_Linkback/zipball/61790889871cae0bc6e54adb2637b9e0ec93275f",
+                "reference": "61790889871cae0bc6e54adb2637b9e0ec93275f",
+                "shasum": ""
+            },
+            "require": {
+                "ext-xmlrpc": "*",
+                "pear/http2": "^2.0",
+                "pear/http_request2": "^2.5",
+                "pear/net_url2": "^2.2"
+            },
+            "require-dev": {
+                "pear/stream_var": "^2.0",
+                "phpunit/phpunit": "^9",
+                "squizlabs/php_codesniffer": "~2.6"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-0": {
+                    "PEAR2\\Services\\Linkback\\": "src"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "LGPL-3.0+"
+            ],
+            "authors": [
+                {
+                    "name": "Christian Weiske",
+                    "email": "cweiske@php.net",
+                    "homepage": "http://cweiske.de/"
+                }
+            ],
+            "description": "Pingback+webmention client and server implementation ",
+            "homepage": "http://pear2.php.net/PEAR2_Services_Linkback",
+            "support": {
+                "email": "pear-general@lists.php.net",
+                "issues": "https://github.com/pear2/Services_Linkback/issues/",
+                "source": "https://github.com/pear2/Services_Linkback/tree/v0.4.0"
+            },
+            "time": "2023-03-22T21:18:04+00:00"
+        },
+        {
+            "name": "simplepie/simplepie",
+            "version": "1.8.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/simplepie/simplepie.git",
+                "reference": "65b095d87bc00898d8fa7737bdbcda93a3fbcc55"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/simplepie/simplepie/zipball/65b095d87bc00898d8fa7737bdbcda93a3fbcc55",
+                "reference": "65b095d87bc00898d8fa7737bdbcda93a3fbcc55",
+                "shasum": ""
+            },
+            "require": {
+                "ext-pcre": "*",
+                "ext-xml": "*",
+                "ext-xmlreader": "*",
+                "php": ">=7.2.0"
+            },
+            "require-dev": {
+                "friendsofphp/php-cs-fixer": "^2.19 || ^3.8",
+                "psr/simple-cache": "^1 || ^2 || ^3",
+                "yoast/phpunit-polyfills": "^1.0.1"
+            },
+            "suggest": {
+                "ext-curl": "",
+                "ext-iconv": "",
+                "ext-intl": "",
+                "ext-mbstring": "",
+                "mf2/mf2": "Microformat module that allows for parsing HTML for microformats"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-0": {
+                    "SimplePie": "library"
+                },
+                "psr-4": {
+                    "SimplePie\\": "src"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "BSD-3-Clause"
+            ],
+            "authors": [
+                {
+                    "name": "Ryan Parman",
+                    "homepage": "http://ryanparman.com/",
+                    "role": "Creator, alumnus developer"
+                },
+                {
+                    "name": "Sam Sneddon",
+                    "homepage": "https://gsnedders.com/",
+                    "role": "Alumnus developer"
+                },
+                {
+                    "name": "Ryan McCue",
+                    "email": "me@ryanmccue.info",
+                    "homepage": "http://ryanmccue.info/",
+                    "role": "Developer"
+                }
+            ],
+            "description": "A simple Atom/RSS parsing library for PHP",
+            "homepage": "http://simplepie.org/",
+            "keywords": [
+                "atom",
+                "feeds",
+                "rss"
+            ],
+            "support": {
+                "issues": "https://github.com/simplepie/simplepie/issues",
+                "source": "https://github.com/simplepie/simplepie/tree/1.8.0"
+            },
+            "time": "2023-01-20T08:37:35+00:00"
+        }
+    ],
+    "packages-dev": [],
+    "aliases": [],
+    "minimum-stability": "stable",
+    "stability-flags": [],
+    "prefer-stable": false,
+    "prefer-lowest": false,
+    "platform": [],
+    "platform-dev": [],
+    "plugin-api-version": "2.3.0"
+}
index 7b85906b17ddd90e1808027aa71beb961fbc6b08..65a6b7336848f18dffbbae3cfa8d75490ba72521 100644 (file)
@@ -6,8 +6,9 @@ namespace stapibas;
  */
 class PDO extends \PDO
 {
-    public function query()
-    {
+    public function query(
+        string $query, ?int $fetchMode = null, mixed ...$fetchModeArgs
+    ): \PDOStatement|false {
         $args = func_get_args();
         $res = call_user_func_array(array('parent', 'query'), $args);
         if ($res !== false) {
@@ -17,7 +18,7 @@ class PDO extends \PDO
         $this->handleError();
     }
 
-    public function exec($statement)
+    public function exec(string $statement): int|false
     {
         $res = parent::exec($statement);
         if ($res !== false) {
@@ -36,4 +37,4 @@ class PDO extends \PDO
     }
 }
 
-?>
\ No newline at end of file
+?>
diff --git a/src/stapibas/autoloader.php b/src/stapibas/autoloader.php
deleted file mode 100644 (file)
index 6ff3f1b..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-<?php
-function stapibas_autoload($className)
-{
-    $className = ltrim($className, '\\');
-    $fileName  = '';
-    $namespace = '';
-    if ($lastNsPos = strripos($className, '\\')) {
-        $namespace = substr($className, 0, $lastNsPos);
-        $className = substr($className, $lastNsPos + 1);
-        $fileName  = str_replace('\\', '/', $namespace) . '/';
-    }
-    $fileName .= str_replace('_', '/', $className) . '.php';
-
-    if (stream_resolve_include_path($fileName)) {
-        require $fileName;
-    }
-}
-
-spl_autoload_register('stapibas_autoload');
-?>
index f42ebc77f4010d3ec06568ee9edb9f1ffaf596ba..1e53013161f448e1d48afa832fa1d4897c25b3b0 100644 (file)
@@ -4,7 +4,7 @@ header('HTTP/1.0 500 Internal Server error');
 header('Content-type: text/plain');
 
 require_once __DIR__ . '/../data/config.php';
-require_once 'stapibas/autoloader.php';
+require_once __DIR__ . '/../vendor/autoload.php';
 
 $db = new PDO($dbdsn, $dbuser, $dbpass);
 $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
index 5a564886456ef2e3543e65a7ff0d849ef86a00b6..5eb3927ed2248cae352b5db2d9e1abd2791f20d8 100644 (file)
@@ -3,7 +3,7 @@ namespace stapibas;
 /**
  * Simply stores all pingbacks in the database.
  */
-require_once 'www-header.php';
+require_once '../vendor/autoload.php';
 
 $s = new \PEAR2\Services\Linkback\Server();