From cfa8251d7f30f7f34ca3e2569648cca675f9d72f Mon Sep 17 00:00:00 2001 From: David Shanske Date: Fri, 20 Oct 2017 16:54:23 -0500 Subject: [PATCH 01/23] Fix name of icon for eat. --- includes/kind-sprite.svg | 4 ++-- svgs/{food.svg => eat.svg} | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename svgs/{food.svg => eat.svg} (100%) diff --git a/includes/kind-sprite.svg b/includes/kind-sprite.svg index ee8b0f4..7b46e79 100644 --- a/includes/kind-sprite.svg +++ b/includes/kind-sprite.svg @@ -1,9 +1,9 @@ article audio bookmark checkin drinkevent drinkeatevent exercise favorite foodissue favorite issue itineraryjamlike listenmood note photo playquote read recipereply repost rsvptag Date: Fri, 20 Oct 2017 17:19:14 -0500 Subject: [PATCH 03/23] Mistake in yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8b31b3e..9498ec6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,6 +19,7 @@ env: - SVN_REPO: https://plugins.svn.wordpress.org/indieweb-post-kinds/ - GH_REF: https://github.com/dshanske/indieweb-post-kinds.git - secure: SKEHj0zThPfUhTyTKtgNuzqPp+uvdUUcMWT0ZqyARjnOGII6dO2UDzQIUc5WolgFd/HYIFfaDzBd3+FPdDTunPiwIHxIYcyr2EjvEQLJYM1zqTAUtjEPpztemKRtrnbNd1TQgWIIqIaNk//WuYkuW7+vc/HsyyTm6PGEbHK6zj11UG8ZYT8ru/Sw+PxHebwlz3d+8H6iEvFSX/rkc1kMpntwNMoFYb9PgwhkvtJ6KkVRKu4uMCkXf6BnlVqJSAGdTn+XckDeY+pwgsWGIAPakLD9MKxAq2MMqfmCxTK8uMN3VBetlbbkT7JMaYyU95gw3+3QrcPLlmRLNdbiuguD39J820wjtflEUNCJ3Heg8JF0q4z/69s6n3LEinDxtJNesK/0G//nYjsLaKXARFfnvLSRbhZvxeePsmEWTxEGt9KvoW7iD/vnwYmf1aYeobwBfkCkvA7t5FSNUTMvI8yo33DWdOyFKdWRL0V2JaaOh0H81kaXOEBayplmDfdbNX7y77/bLU863V0JkORSsJNv7ZGl8zR77ja/s1Ep0F3d43QhIoQk40w8SckpLEx+2bUs3J2jNpBeike5cut7RuSPTt7G2AiipTfmPa666f+CsmfNAjd2MYFfB2NL5ZHwjmOuxYE6hicdKt2vwOjLa31hLY/u3bT8s346w+DzIPZmItU= + matrix: include: - php: 7.1 @@ -44,7 +45,6 @@ before_script: if [[ "$TRAVISCI" == "phpcs" ]] ; then composer install fi -- bash bin/install-wp-tests.sh wordpress root '' localhost $WP_VERSION script: - | if [[ ! -z "$WP_VERSION" ]] ; then From cd90d77bcc98b434a0c1e158dd334af863ec6280 Mon Sep 17 00:00:00 2001 From: David Shanske Date: Fri, 20 Oct 2017 17:26:39 -0500 Subject: [PATCH 04/23] Adopt changes from other project to improve testing --- .travis.yml | 13 ---- bin/install-php-phpunit.sh | 124 +++++++++++++++++++++++++++++++++++++ bin/patches/README.md | 2 + bin/patches/node.patch | 51 +++++++++++++++ bin/patches/openssl.patch | 52 ++++++++++++++++ 5 files changed, 229 insertions(+), 13 deletions(-) create mode 100755 bin/install-php-phpunit.sh create mode 100644 bin/patches/README.md create mode 100644 bin/patches/node.patch create mode 100644 bin/patches/openssl.patch diff --git a/.travis.yml b/.travis.yml index 9498ec6..0c65dad 100644 --- a/.travis.yml +++ b/.travis.yml @@ -50,22 +50,9 @@ script: if [[ ! -z "$WP_VERSION" ]] ; then # Run the build because otherwise there will be a bunch of warnings about # failed `stat` calls from `filemtime()`. - npm install || exit 1 - npm run build || exit 1 - # Make sure phpegjs parser is up to date - node bin/create-php-parser.js || exit 1 - if ! git diff --quiet --exit-code lib/parser.php; then - echo 'ERROR: The PEG parser has been updated, but the generated PHP version' - echo ' (lib/parser.php) has not. Run `bin/create-php-parser.js` and' - echo ' commit the resulting changes to resolve this.' - sleep .2 # Otherwise Travis doesn't want to print the whole message - exit 1 - fi echo Running with the following versions: php -v phpunit --version - # Check parser syntax - php lib/parser.php || exit 1 # Run PHPUnit tests phpunit || exit 1 WP_MULTISITE=1 phpunit || exit 1 diff --git a/bin/install-php-phpunit.sh b/bin/install-php-phpunit.sh new file mode 100755 index 0000000..b53ad3f --- /dev/null +++ b/bin/install-php-phpunit.sh @@ -0,0 +1,124 @@ +#!/bin/bash + +# Uses phpbrew to install older php versions on modern(ish) distros. +# Installs the correct version of phpunit for the requested php +# version. ~/.phpbrew is expected to be cached so we only have +# to build php the first time. + +# we have to save and restore the original working directory, because +# phpbrew can mess up if we don't run it from the home directory +ORIG_DIR=`pwd`; +THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +PHP52_PATH=$HOME/.phpbrew/php/php-5.2.17 + +# install phpunit + +mkdir -p $HOME/phpunit-bin + +if [[ ${SWITCH_TO_PHP:0:3} == "5.2" ]]; then + # use the phpunit in the PHP5.2 installation + ln -s ${PHP52_PATH}/lib/php/phpunit/phpunit.php $HOME/phpunit-bin/phpunit +elif [[ ${TRAVIS_PHP_VERSION:0:2} == "5." ]] || [[ ${SWITCH_TO_PHP:0:2} == "5." ]]; then + wget -O $HOME/phpunit-bin/phpunit https://phar.phpunit.de/phpunit-4.8.phar + chmod +x $HOME/phpunit-bin/phpunit +else + composer global require "phpunit/phpunit=6.*" +fi + +export PATH=$HOME/phpunit-bin/:$PATH + +if [[ ${SWITCH_TO_PHP:0:3} == "5.2" ]] || [[ ${SWITCH_TO_PHP:0:3} == "5.3" ]]; then + PHPBREW_BUILT_CHECK=$HOME/.phpbrew/bashrc + + # directory to install phpbrew into + mkdir -p $HOME/php-utils-bin + + # install phpbrew + curl -L -o $HOME/php-utils-bin/phpbrew https://github.com/phpbrew/phpbrew/raw/f6a422e1ba49293ee73bc4c317795c021bc57020/phpbrew + chmod +x $HOME/php-utils-bin/phpbrew + + # needs to be on the path for switching php versions to work + export PATH=$HOME/php-utils-bin:$PATH + + # php and phpunit3.6 installs should be cached, only build if they're not there. + if [ ! -f $PHPBREW_BUILT_CHECK ]; then + + # init with known --old to get 5.2 and 5.3 + $HOME/php-utils-bin/phpbrew init + $HOME/php-utils-bin/phpbrew known --old + + # build PHP5.2 + tail -F $HOME/.phpbrew/build/php-5.2.17/build.log & + TAIL_PID=$! + $HOME/php-utils-bin/phpbrew install --patch ${THIS_DIR}/patches/node.patch --patch ${THIS_DIR}/patches/openssl.patch 5.2 +default +mysql +pdo \ + +gettext +phar +openssl -- --with-openssl-dir=/usr/include/openssl --enable-spl --with-mysql --with-mysqli=/usr/bin/mysql_config --with-pdo-mysql=/usr + kill -TERM $TAIL_PID + + # build PHP5.3 + tail -F $HOME/.phpbrew/build/php-5.3.29/build.log & + TAIL_PID=$! + $HOME/php-utils-bin/phpbrew install --patch ${THIS_DIR}/patches/node.patch --patch ${THIS_DIR}/patches/openssl.patch 5.3 +default +mysql +pdo \ + +gettext +phar +openssl -- --with-openssl-dir=/usr/include/openssl --enable-spl --with-mysql --with-mysqli=/usr/bin/mysql_config --with-pdo-mysql=/usr + kill -TERM $TAIL_PID + + # install PHPUnit 3.6. The only install method available is from source, using git branches old + # enough that they don't rely on any PHP5.3+ features. This clones each needed dependency + # and then we add the paths to the include_path by setting up an extra .ini file + cd ${PHP52_PATH}/lib/php + + # dependencies + git clone --depth=1 --branch=1.1 git://github.com/sebastianbergmann/dbunit.git + git clone --depth=1 --branch=1.1 git://github.com/sebastianbergmann/php-code-coverage.git + git clone --depth=1 --branch=1.3.2 git://github.com/sebastianbergmann/php-file-iterator.git + git clone --depth=1 --branch=1.1.1 git://github.com/sebastianbergmann/php-invoker.git + git clone --depth=1 --branch=1.1.2 git://github.com/sebastianbergmann/php-text-template.git + git clone --depth=1 --branch=1.0.3 git://github.com/sebastianbergmann/php-timer.git + git clone --depth=1 --branch=1.1.4 git://github.com/sebastianbergmann/php-token-stream.git + git clone --depth=1 --branch=1.1 git://github.com/sebastianbergmann/phpunit-mock-objects.git + git clone --depth=1 --branch=1.1 git://github.com/sebastianbergmann/phpunit-selenium.git + git clone --depth=1 --branch=1.0.0 git://github.com/sebastianbergmann/phpunit-story.git + + # and the version of phpunit that we expect to run with php 5.2 + git clone --depth=1 --branch=3.6 git://github.com/sebastianbergmann/phpunit.git + + # fix up the version number of phpunit + sed -i 's/@package_version@/3.6-git/g' phpunit/PHPUnit/Runner/Version.php + + # now set up an ini file that adds all of the above to include_path for the PHP5.2 install + mkdir -p ${PHP52_PATH}/var/db + echo "include_path=.:${PHP52_PATH}/lib/php:${PHP52_PATH}/lib/php/dbunit:${PHP52_PATH}/lib/php/php-code-coverage:${PHP52_PATH}/lib/php/php-file-iterator:${PHP52_PATH}/lib/php/php-invoker:${PHP52_PATH}/lib/php/php-text-template:${PHP52_PATH}/lib/php/php-timer:${PHP52_PATH}/lib/php/php-token-stream:${PHP52_PATH}/lib/php/phpunit-mock-objects:${PHP52_PATH}/lib/php/phpunit-selenium:${PHP52_PATH}/lib/php/phpunit-story:${PHP52_PATH}/lib/php/phpunit" > ${PHP52_PATH}/var/db/path.ini + + # one more PHPUnit dependency that we need to install using pear under PHP5.2 + cd $HOME + export PHPBREW_RC_ENABLE=1 + source $HOME/.phpbrew/bashrc + phpbrew use 5.2.17 + pear channel-discover pear.symfony-project.com + pear install pear.symfony-project.com/YAML-1.0.2 + + # manually go back to the system php, we can't use `phpbrew switch-off` + # because we're running a version of php that phpbrew doesn't work with at this point + unset PHPBREW_PHP + unset PHPBREW_PATH + __phpbrew_set_path + __phpbrew_reinit + eval `$BIN env` + + # clean up build directory + rm -rf $HOME/.phpbrew/build/* + fi + + # all needed php versions and phpunit versions are installed, either from the above + # install script, or from travis cache, so switch to using them + cd $HOME + export PHPBREW_RC_ENABLE=1 + source $HOME/.phpbrew/bashrc + + if [[ ${SWITCH_TO_PHP:0:3} == "5.2" ]]; then + phpbrew use 5.2.17 + else + phpbrew use 5.3.29 + fi +fi + +cd $ORIG_DIR diff --git a/bin/patches/README.md b/bin/patches/README.md new file mode 100644 index 0000000..8ea482c --- /dev/null +++ b/bin/patches/README.md @@ -0,0 +1,2 @@ +This directory contains patches required to build +older versions of PHP on trusty. \ No newline at end of file diff --git a/bin/patches/node.patch b/bin/patches/node.patch new file mode 100644 index 0000000..e5dbab7 --- /dev/null +++ b/bin/patches/node.patch @@ -0,0 +1,51 @@ +--- ext/dom/node.c 2012-08-06 17:49:48.826716692 +0800 ++++ ext/dom/node.c 2012-08-06 17:52:47.633484660 +0800 +@@ -1895,9 +1895,17 @@ static void dom_canonicalization(INTERNA + RETVAL_FALSE; + } else { + if (mode == 0) { ++#ifdef LIBXML2_NEW_BUFFER ++ ret = xmlOutputBufferGetSize(buf); ++#else + ret = buf->buffer->use; ++#endif + if (ret > 0) { ++#ifdef LIBXML2_NEW_BUFFER ++ RETVAL_STRINGL((char *) xmlOutputBufferGetContent(buf), ret, 1); ++#else + RETVAL_STRINGL((char *) buf->buffer->content, ret, 1); ++#endif + } else { + RETVAL_EMPTY_STRING(); + } +--- ext/dom/documenttype.c 2012-08-06 18:02:16.019640870 +0800 ++++ ext/dom/documenttype.c 2012-08-06 18:06:16.612228905 +0800 +@@ -205,7 +205,13 @@ int dom_documenttype_internal_subset_rea + if (buff != NULL) { + xmlNodeDumpOutput (buff, NULL, (xmlNodePtr) intsubset, 0, 0, NULL); + xmlOutputBufferFlush(buff); ++ ++#ifdef LIBXML2_NEW_BUFFER ++ ZVAL_STRINGL(*retval, xmlOutputBufferGetContent(buff), ++ xmlOutputBufferGetSize(buff), 1); ++#else + ZVAL_STRINGL(*retval, buff->buffer->content, buff->buffer->use, 1); ++#endif + (void)xmlOutputBufferClose(buff); + return SUCCESS; + } +--- ext/simplexml/simplexml.c 2012-08-06 18:10:44.621017026 +0800 ++++ ext/simplexml/simplexml.c 2012-08-06 18:12:48.016270419 +0800 +@@ -1417,7 +1417,12 @@ SXE_METHOD(asXML) + + xmlNodeDumpOutput(outbuf, (xmlDocPtr) sxe->document->ptr, node, 0, 0, ((xmlDocPtr) sxe->document->ptr)->encoding); + xmlOutputBufferFlush(outbuf); ++#ifdef LIBXML2_NEW_BUFFER ++ RETVAL_STRINGL((char *)xmlOutputBufferGetContent(outbuf), ++ xmlOutputBufferGetSize(outbuf), 1); ++#else + RETVAL_STRINGL((char *)outbuf->buffer->content, outbuf->buffer->use, 1); ++#endif + xmlOutputBufferClose(outbuf); + } + } else { diff --git a/bin/patches/openssl.patch b/bin/patches/openssl.patch new file mode 100644 index 0000000..3b0e010 --- /dev/null +++ b/bin/patches/openssl.patch @@ -0,0 +1,52 @@ +--- ext/openssl/xp_ssl.c ++++ ext/openssl/xp_ssl.c +@@ -328,10 +328,12 @@ static inline int php_openssl_setup_cryp + sslsock->is_client = 1; + method = SSLv23_client_method(); + break; ++#ifndef OPENSSL_NO_SSL2 + case STREAM_CRYPTO_METHOD_SSLv2_CLIENT: + sslsock->is_client = 1; + method = SSLv2_client_method(); + break; ++#endif + case STREAM_CRYPTO_METHOD_SSLv3_CLIENT: + sslsock->is_client = 1; + method = SSLv3_client_method(); +@@ -348,10 +350,12 @@ static inline int php_openssl_setup_cryp + sslsock->is_client = 0; + method = SSLv3_server_method(); + break; ++#ifndef OPENSSL_NO_SSL2 + case STREAM_CRYPTO_METHOD_SSLv2_SERVER: + sslsock->is_client = 0; + method = SSLv2_server_method(); + break; ++#endif + case STREAM_CRYPTO_METHOD_TLS_SERVER: + sslsock->is_client = 0; + method = TLSv1_server_method(); +@@ -629,9 +633,11 @@ static inline int php_openssl_tcp_sockop + case STREAM_CRYPTO_METHOD_SSLv23_CLIENT: + sock->method = STREAM_CRYPTO_METHOD_SSLv23_SERVER; + break; ++#ifndef OPENSSL_NO_SSL2 + case STREAM_CRYPTO_METHOD_SSLv2_CLIENT: + sock->method = STREAM_CRYPTO_METHOD_SSLv2_SERVER; + break; ++#endif + case STREAM_CRYPTO_METHOD_SSLv3_CLIENT: + sock->method = STREAM_CRYPTO_METHOD_SSLv3_SERVER; + break; +@@ -911,9 +917,11 @@ php_stream *php_openssl_ssl_socket_facto + if (strncmp(proto, "ssl", protolen) == 0) { + sslsock->enable_on_connect = 1; + sslsock->method = STREAM_CRYPTO_METHOD_SSLv23_CLIENT; ++#ifndef OPENSSL_NO_SSL2 + } else if (strncmp(proto, "sslv2", protolen) == 0) { + sslsock->enable_on_connect = 1; + sslsock->method = STREAM_CRYPTO_METHOD_SSLv2_CLIENT; ++#endif + } else if (strncmp(proto, "sslv3", protolen) == 0) { + sslsock->enable_on_connect = 1; + sslsock->method = STREAM_CRYPTO_METHOD_SSLv3_CLIENT; From 63b3fbe63a8ea6c578221cfacadeed8538d869dc Mon Sep 17 00:00:00 2001 From: David Shanske Date: Fri, 20 Oct 2017 17:42:38 -0500 Subject: [PATCH 05/23] Remove PHP 5.2 test due minimum requirements --- .travis.yml | 7 ------- bin/install-php-phpunit.sh | 39 +++----------------------------------- composer.json | 10 ++++++++++ 3 files changed, 13 insertions(+), 43 deletions(-) create mode 100644 composer.json diff --git a/.travis.yml b/.travis.yml index 0c65dad..3e8c3d8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,8 +30,6 @@ matrix: env: WP_VERSION=latest SWITCH_TO_PHP=5.3 - php: 5.6 env: TRAVISCI=phpcs - - php: 7.1 - env: TRAVISCI=js before_script: - export PATH="$HOME/.composer/vendor/bin:$PATH" - | @@ -61,8 +59,3 @@ script: if [[ "$TRAVISCI" == "phpcs" ]] ; then ./vendor/bin/phpcs fi - - | - if [[ "$TRAVISCI" == "js" ]] ; then - npm install || exit 1 - npm run ci || exit 1 - fi diff --git a/bin/install-php-phpunit.sh b/bin/install-php-phpunit.sh index b53ad3f..775695c 100755 --- a/bin/install-php-phpunit.sh +++ b/bin/install-php-phpunit.sh @@ -9,16 +9,12 @@ # phpbrew can mess up if we don't run it from the home directory ORIG_DIR=`pwd`; THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -PHP52_PATH=$HOME/.phpbrew/php/php-5.2.17 # install phpunit mkdir -p $HOME/phpunit-bin -if [[ ${SWITCH_TO_PHP:0:3} == "5.2" ]]; then - # use the phpunit in the PHP5.2 installation - ln -s ${PHP52_PATH}/lib/php/phpunit/phpunit.php $HOME/phpunit-bin/phpunit -elif [[ ${TRAVIS_PHP_VERSION:0:2} == "5." ]] || [[ ${SWITCH_TO_PHP:0:2} == "5." ]]; then +if [[ ${TRAVIS_PHP_VERSION:0:2} == "5." ]] || [[ ${SWITCH_TO_PHP:0:2} == "5." ]]; then wget -O $HOME/phpunit-bin/phpunit https://phar.phpunit.de/phpunit-4.8.phar chmod +x $HOME/phpunit-bin/phpunit else @@ -27,7 +23,7 @@ fi export PATH=$HOME/phpunit-bin/:$PATH -if [[ ${SWITCH_TO_PHP:0:3} == "5.2" ]] || [[ ${SWITCH_TO_PHP:0:3} == "5.3" ]]; then +if [[ ${SWITCH_TO_PHP:0:3} == "5.3" ]]; then PHPBREW_BUILT_CHECK=$HOME/.phpbrew/bashrc # directory to install phpbrew into @@ -47,13 +43,6 @@ if [[ ${SWITCH_TO_PHP:0:3} == "5.2" ]] || [[ ${SWITCH_TO_PHP:0:3} == "5.3" ]]; t $HOME/php-utils-bin/phpbrew init $HOME/php-utils-bin/phpbrew known --old - # build PHP5.2 - tail -F $HOME/.phpbrew/build/php-5.2.17/build.log & - TAIL_PID=$! - $HOME/php-utils-bin/phpbrew install --patch ${THIS_DIR}/patches/node.patch --patch ${THIS_DIR}/patches/openssl.patch 5.2 +default +mysql +pdo \ - +gettext +phar +openssl -- --with-openssl-dir=/usr/include/openssl --enable-spl --with-mysql --with-mysqli=/usr/bin/mysql_config --with-pdo-mysql=/usr - kill -TERM $TAIL_PID - # build PHP5.3 tail -F $HOME/.phpbrew/build/php-5.3.29/build.log & TAIL_PID=$! @@ -61,11 +50,6 @@ if [[ ${SWITCH_TO_PHP:0:3} == "5.2" ]] || [[ ${SWITCH_TO_PHP:0:3} == "5.3" ]]; t +gettext +phar +openssl -- --with-openssl-dir=/usr/include/openssl --enable-spl --with-mysql --with-mysqli=/usr/bin/mysql_config --with-pdo-mysql=/usr kill -TERM $TAIL_PID - # install PHPUnit 3.6. The only install method available is from source, using git branches old - # enough that they don't rely on any PHP5.3+ features. This clones each needed dependency - # and then we add the paths to the include_path by setting up an extra .ini file - cd ${PHP52_PATH}/lib/php - # dependencies git clone --depth=1 --branch=1.1 git://github.com/sebastianbergmann/dbunit.git git clone --depth=1 --branch=1.1 git://github.com/sebastianbergmann/php-code-coverage.git @@ -78,24 +62,9 @@ if [[ ${SWITCH_TO_PHP:0:3} == "5.2" ]] || [[ ${SWITCH_TO_PHP:0:3} == "5.3" ]]; t git clone --depth=1 --branch=1.1 git://github.com/sebastianbergmann/phpunit-selenium.git git clone --depth=1 --branch=1.0.0 git://github.com/sebastianbergmann/phpunit-story.git - # and the version of phpunit that we expect to run with php 5.2 - git clone --depth=1 --branch=3.6 git://github.com/sebastianbergmann/phpunit.git - # fix up the version number of phpunit sed -i 's/@package_version@/3.6-git/g' phpunit/PHPUnit/Runner/Version.php - # now set up an ini file that adds all of the above to include_path for the PHP5.2 install - mkdir -p ${PHP52_PATH}/var/db - echo "include_path=.:${PHP52_PATH}/lib/php:${PHP52_PATH}/lib/php/dbunit:${PHP52_PATH}/lib/php/php-code-coverage:${PHP52_PATH}/lib/php/php-file-iterator:${PHP52_PATH}/lib/php/php-invoker:${PHP52_PATH}/lib/php/php-text-template:${PHP52_PATH}/lib/php/php-timer:${PHP52_PATH}/lib/php/php-token-stream:${PHP52_PATH}/lib/php/phpunit-mock-objects:${PHP52_PATH}/lib/php/phpunit-selenium:${PHP52_PATH}/lib/php/phpunit-story:${PHP52_PATH}/lib/php/phpunit" > ${PHP52_PATH}/var/db/path.ini - - # one more PHPUnit dependency that we need to install using pear under PHP5.2 - cd $HOME - export PHPBREW_RC_ENABLE=1 - source $HOME/.phpbrew/bashrc - phpbrew use 5.2.17 - pear channel-discover pear.symfony-project.com - pear install pear.symfony-project.com/YAML-1.0.2 - # manually go back to the system php, we can't use `phpbrew switch-off` # because we're running a version of php that phpbrew doesn't work with at this point unset PHPBREW_PHP @@ -114,9 +83,7 @@ if [[ ${SWITCH_TO_PHP:0:3} == "5.2" ]] || [[ ${SWITCH_TO_PHP:0:3} == "5.3" ]]; t export PHPBREW_RC_ENABLE=1 source $HOME/.phpbrew/bashrc - if [[ ${SWITCH_TO_PHP:0:3} == "5.2" ]]; then - phpbrew use 5.2.17 - else + if [[ ${SWITCH_TO_PHP:0:3} == "5.3" ]]; then phpbrew use 5.3.29 fi fi diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..fabff92 --- /dev/null +++ b/composer.json @@ -0,0 +1,10 @@ +{ + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.4", + "wimg/php-compatibility": "dev-master", + "wp-coding-standards/wpcs": "dev-develop" + }, + "scripts": { + "lint": "phpcs" + } +} From 497ce0007c9265daabc1366484561a96243b1ce2 Mon Sep 17 00:00:00 2001 From: David Shanske Date: Fri, 20 Oct 2017 17:52:20 -0500 Subject: [PATCH 06/23] Add default files to phpcs --- phpcs.ruleset.xml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/phpcs.ruleset.xml b/phpcs.ruleset.xml index 5e6148c..451366c 100644 --- a/phpcs.ruleset.xml +++ b/phpcs.ruleset.xml @@ -1,9 +1,15 @@ - - Defaults for Indieweb + + Indieweb Post Kinds Standards + ./phpunit + indieweb-post-kinds.php + + // + + From 7c2268dfa1017727af4166293cfc4c4e0486d480 Mon Sep 17 00:00:00 2001 From: David Shanske Date: Fri, 20 Oct 2017 18:21:33 -0500 Subject: [PATCH 07/23] Try something simpler --- .travis.yml | 91 ++++++++++++++++++++++++++++---------- bin/install-php-phpunit.sh | 91 -------------------------------------- 2 files changed, 67 insertions(+), 115 deletions(-) delete mode 100755 bin/install-php-phpunit.sh diff --git a/.travis.yml b/.travis.yml index 3e8c3d8..9c0a3f9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,48 +1,95 @@ -language: php +sudo: false dist: trusty -sudo: required +language: php notifications: email: on_success: never - on_failure: chang + on_failure: change cache: directories: - vendor - $HOME/.composer/cache - - $HOME/.phpbrew after_success: curl -L https://raw.githubusercontent.com/miya0001/travis2wpplugin/master/deploy.sh | bash env: matrix: - WP_VERSION=latest WP_MULTISITE=0 global: + - WP_TRAVISCI=travis:phpunit - SVN_REPO: https://plugins.svn.wordpress.org/indieweb-post-kinds/ - GH_REF: https://github.com/dshanske/indieweb-post-kinds.git - secure: SKEHj0zThPfUhTyTKtgNuzqPp+uvdUUcMWT0ZqyARjnOGII6dO2UDzQIUc5WolgFd/HYIFfaDzBd3+FPdDTunPiwIHxIYcyr2EjvEQLJYM1zqTAUtjEPpztemKRtrnbNd1TQgWIIqIaNk//WuYkuW7+vc/HsyyTm6PGEbHK6zj11UG8ZYT8ru/Sw+PxHebwlz3d+8H6iEvFSX/rkc1kMpntwNMoFYb9PgwhkvtJ6KkVRKu4uMCkXf6BnlVqJSAGdTn+XckDeY+pwgsWGIAPakLD9MKxAq2MMqfmCxTK8uMN3VBetlbbkT7JMaYyU95gw3+3QrcPLlmRLNdbiuguD39J820wjtflEUNCJ3Heg8JF0q4z/69s6n3LEinDxtJNesK/0G//nYjsLaKXARFfnvLSRbhZvxeePsmEWTxEGt9KvoW7iD/vnwYmf1aYeobwBfkCkvA7t5FSNUTMvI8yo33DWdOyFKdWRL0V2JaaOh0H81kaXOEBayplmDfdbNX7y77/bLU863V0JkORSsJNv7ZGl8zR77ja/s1Ep0F3d43QhIoQk40w8SckpLEx+2bUs3J2jNpBeike5cut7RuSPTt7G2AiipTfmPa666f+CsmfNAjd2MYFfB2NL5ZHwjmOuxYE6hicdKt2vwOjLa31hLY/u3bT8s346w+DzIPZmItU= - matrix: include: - - php: 7.1 - env: WP_VERSION=latest - - php: 5.6 - env: WP_VERSION=latest WP_PULUGIN_DEPLOY=1 - - php: 7.1 - env: WP_VERSION=latest SWITCH_TO_PHP=5.3 - - php: 5.6 - env: TRAVISCI=phpcs + - php: 7.2 + - php: 7.1 + - php: 7.0 + - php: 5.6 + - php: 5.6 + env: WP_PULUGIN_DEPLOY=1 + - php: 5.6 + env: WP_TRAVISCI=travis:phpcs + - php: 5.5 + - php: 5.4 + - php: 5.3 + dist: precise before_script: - - export PATH="$HOME/.composer/vendor/bin:$PATH" - - | +- | + # Remove Xdebug for a huge performance increase: + if [ -f ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini ]; then + phpenv config-rm xdebug.ini + else + echo "xdebug.ini does not exist" + fi +- | + # Export Composer's global bin dir to PATH: + composer config --list --global + export PATH=`composer config --list --global | grep '\[home\]' | { read a; echo "${a#* }/vendor/bin:$PATH"; }` +- | + # Install the specified version of PHPUnit depending on the PHP version: + if [[ "$WP_TRAVISCI" == "travis:phpunit" ]]; then + case "$TRAVIS_PHP_VERSION" in + 7.2|7.1|7.0|nightly) + echo "Using PHPUnit 6.x" + composer global require "phpunit/phpunit:^6" + ;; + 5.6|5.5|5.4|5.3) + echo "Using PHPUnit 4.x" + composer global require "phpunit/phpunit:^4" + ;; + 5.2) + # Do nothing, use default PHPUnit 3.6.x + echo "Using default PHPUnit, hopefully 3.6" + ;; + *) + echo "No PHPUnit version handling for PHP version $TRAVIS_PHP_VERSION" + exit 1 + ;; + esac + fi + if [[ "$WP_TRAVISCI" == "travis:phpcs" ]] ; then + composer install + fi + +- mysql --version +- phpenv versions +- php --version +- php -m +- which phpunit +- phpunit --version +- curl --version +- grunt --version +- git --version +- svn --version +- locale -a +before_install: +- export PATH="$HOME/.composer/vendor/bin:$PATH" +- | if [[ ! -z "$WP_VERSION" ]] ; then set -e bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION - source bin/install-php-phpunit.sh set +e fi - - | - if [[ "$TRAVISCI" == "phpcs" ]] ; then - composer install - fi script: - | if [[ ! -z "$WP_VERSION" ]] ; then @@ -55,7 +102,3 @@ script: phpunit || exit 1 WP_MULTISITE=1 phpunit || exit 1 fi - - | - if [[ "$TRAVISCI" == "phpcs" ]] ; then - ./vendor/bin/phpcs - fi diff --git a/bin/install-php-phpunit.sh b/bin/install-php-phpunit.sh deleted file mode 100755 index 775695c..0000000 --- a/bin/install-php-phpunit.sh +++ /dev/null @@ -1,91 +0,0 @@ -#!/bin/bash - -# Uses phpbrew to install older php versions on modern(ish) distros. -# Installs the correct version of phpunit for the requested php -# version. ~/.phpbrew is expected to be cached so we only have -# to build php the first time. - -# we have to save and restore the original working directory, because -# phpbrew can mess up if we don't run it from the home directory -ORIG_DIR=`pwd`; -THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -# install phpunit - -mkdir -p $HOME/phpunit-bin - -if [[ ${TRAVIS_PHP_VERSION:0:2} == "5." ]] || [[ ${SWITCH_TO_PHP:0:2} == "5." ]]; then - wget -O $HOME/phpunit-bin/phpunit https://phar.phpunit.de/phpunit-4.8.phar - chmod +x $HOME/phpunit-bin/phpunit -else - composer global require "phpunit/phpunit=6.*" -fi - -export PATH=$HOME/phpunit-bin/:$PATH - -if [[ ${SWITCH_TO_PHP:0:3} == "5.3" ]]; then - PHPBREW_BUILT_CHECK=$HOME/.phpbrew/bashrc - - # directory to install phpbrew into - mkdir -p $HOME/php-utils-bin - - # install phpbrew - curl -L -o $HOME/php-utils-bin/phpbrew https://github.com/phpbrew/phpbrew/raw/f6a422e1ba49293ee73bc4c317795c021bc57020/phpbrew - chmod +x $HOME/php-utils-bin/phpbrew - - # needs to be on the path for switching php versions to work - export PATH=$HOME/php-utils-bin:$PATH - - # php and phpunit3.6 installs should be cached, only build if they're not there. - if [ ! -f $PHPBREW_BUILT_CHECK ]; then - - # init with known --old to get 5.2 and 5.3 - $HOME/php-utils-bin/phpbrew init - $HOME/php-utils-bin/phpbrew known --old - - # build PHP5.3 - tail -F $HOME/.phpbrew/build/php-5.3.29/build.log & - TAIL_PID=$! - $HOME/php-utils-bin/phpbrew install --patch ${THIS_DIR}/patches/node.patch --patch ${THIS_DIR}/patches/openssl.patch 5.3 +default +mysql +pdo \ - +gettext +phar +openssl -- --with-openssl-dir=/usr/include/openssl --enable-spl --with-mysql --with-mysqli=/usr/bin/mysql_config --with-pdo-mysql=/usr - kill -TERM $TAIL_PID - - # dependencies - git clone --depth=1 --branch=1.1 git://github.com/sebastianbergmann/dbunit.git - git clone --depth=1 --branch=1.1 git://github.com/sebastianbergmann/php-code-coverage.git - git clone --depth=1 --branch=1.3.2 git://github.com/sebastianbergmann/php-file-iterator.git - git clone --depth=1 --branch=1.1.1 git://github.com/sebastianbergmann/php-invoker.git - git clone --depth=1 --branch=1.1.2 git://github.com/sebastianbergmann/php-text-template.git - git clone --depth=1 --branch=1.0.3 git://github.com/sebastianbergmann/php-timer.git - git clone --depth=1 --branch=1.1.4 git://github.com/sebastianbergmann/php-token-stream.git - git clone --depth=1 --branch=1.1 git://github.com/sebastianbergmann/phpunit-mock-objects.git - git clone --depth=1 --branch=1.1 git://github.com/sebastianbergmann/phpunit-selenium.git - git clone --depth=1 --branch=1.0.0 git://github.com/sebastianbergmann/phpunit-story.git - - # fix up the version number of phpunit - sed -i 's/@package_version@/3.6-git/g' phpunit/PHPUnit/Runner/Version.php - - # manually go back to the system php, we can't use `phpbrew switch-off` - # because we're running a version of php that phpbrew doesn't work with at this point - unset PHPBREW_PHP - unset PHPBREW_PATH - __phpbrew_set_path - __phpbrew_reinit - eval `$BIN env` - - # clean up build directory - rm -rf $HOME/.phpbrew/build/* - fi - - # all needed php versions and phpunit versions are installed, either from the above - # install script, or from travis cache, so switch to using them - cd $HOME - export PHPBREW_RC_ENABLE=1 - source $HOME/.phpbrew/bashrc - - if [[ ${SWITCH_TO_PHP:0:3} == "5.3" ]]; then - phpbrew use 5.3.29 - fi -fi - -cd $ORIG_DIR From 5e877b162d75488db4e37024547ea11fbae3670a Mon Sep 17 00:00:00 2001 From: David Shanske Date: Fri, 20 Oct 2017 18:29:18 -0500 Subject: [PATCH 08/23] PHPCS fixes --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 9c0a3f9..edd5e6e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -102,3 +102,7 @@ script: phpunit || exit 1 WP_MULTISITE=1 phpunit || exit 1 fi + - | + if [[ "$WP_TRAVISCI" == "travis:phpcs" ]] ; then + ./vendor/bin/phpcs + fi From 8e0dcd25620c6768ee41af429bbf0dd6814eaf12 Mon Sep 17 00:00:00 2001 From: David Shanske Date: Fri, 20 Oct 2017 18:31:45 -0500 Subject: [PATCH 09/23] Fix YAML issue --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index edd5e6e..67de91a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -102,7 +102,7 @@ script: phpunit || exit 1 WP_MULTISITE=1 phpunit || exit 1 fi - - | - if [[ "$WP_TRAVISCI" == "travis:phpcs" ]] ; then - ./vendor/bin/phpcs - fi + - | + if [[ "$WP_TRAVISCI" == "travis:phpcs" ]] ; then + ./vendor/bin/phpcs + fi From c91f216b6563956ac63e37b229398b33cc5531ee Mon Sep 17 00:00:00 2001 From: David Shanske Date: Fri, 20 Oct 2017 19:12:25 -0500 Subject: [PATCH 10/23] Additional Support for PHPCS --- .travis.yml | 2 +- phpcs.ruleset.xml | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 67de91a..5377237 100644 --- a/.travis.yml +++ b/.travis.yml @@ -104,5 +104,5 @@ script: fi - | if [[ "$WP_TRAVISCI" == "travis:phpcs" ]] ; then - ./vendor/bin/phpcs + ./vendor/bin/phpcs -p -s -v -n . --standard=./phpcs.ruleset.xml --extensions=php fi diff --git a/phpcs.ruleset.xml b/phpcs.ruleset.xml index 451366c..68ecc48 100644 --- a/phpcs.ruleset.xml +++ b/phpcs.ruleset.xml @@ -1,8 +1,10 @@ Indieweb Post Kinds Standards - ./phpunit - indieweb-post-kinds.php + + ./indieweb-post-kinds.php + ./includes/ + */includes/*\.(inc|css|js|svg) From b684ece012738fd483cc246a0aaff8b37ae95ea7 Mon Sep 17 00:00:00 2001 From: David Shanske Date: Fri, 20 Oct 2017 19:20:19 -0500 Subject: [PATCH 11/23] Fix Scope of PHPCS --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5377237..c1f45e8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -104,5 +104,5 @@ script: fi - | if [[ "$WP_TRAVISCI" == "travis:phpcs" ]] ; then - ./vendor/bin/phpcs -p -s -v -n . --standard=./phpcs.ruleset.xml --extensions=php + ./vendor/bin/phpcs -p -s -v -n --standard=./phpcs.ruleset.xml --extensions=php fi From 1a8dae7354bbc29bbc4382cc9532cdcc9fbf7477 Mon Sep 17 00:00:00 2001 From: David Shanske Date: Fri, 20 Oct 2017 19:52:10 -0500 Subject: [PATCH 12/23] A bunch of PHPCS induced changes --- includes/class-kind-config.php | 109 +++++---- includes/class-kind-meta.php | 56 ++--- includes/class-kind-plugins.php | 16 +- includes/class-kind-tabmeta.php | 38 +-- includes/class-kind-taxonomy.php | 146 ++++++------ includes/class-kind-view.php | 90 ++++---- includes/class-link-preview.php | 50 ++-- includes/class-parse-mf2.php | 227 ++++++++++-------- includes/class-parse-this.php | 63 ++--- includes/kind-functions.php | 5 +- includes/tabs/tab-details.php | 8 +- includes/tabs/tab-main.php | 9 +- includes/tabs/tab-other.php | 4 +- includes/views/kind-bookmark.php | 9 +- includes/views/kind-checkin.php | 5 +- includes/views/kind-favorite.php | 9 +- includes/views/kind-jam.php | 11 +- includes/views/kind-like.php | 9 +- includes/views/kind-listen.php | 11 +- includes/views/kind-photo.php | 21 +- includes/views/kind-rsvp.php | 7 +- includes/views/kind-video.php | 18 +- includes/views/kind-watch.php | 11 +- includes/views/kind.php | 9 +- indieweb-post-kinds.php | 7 +- languages/post_kinds.pot | 381 ++++++++++++++++--------------- phpcs.ruleset.xml | 2 +- 27 files changed, 706 insertions(+), 625 deletions(-) diff --git a/includes/class-kind-config.php b/includes/class-kind-config.php index 5d6328e..7c7b7b3 100644 --- a/includes/class-kind-config.php +++ b/includes/class-kind-config.php @@ -70,8 +70,10 @@ public static function init() { public static function admin_init() { add_settings_section( 'iwt-content', - __( 'Content Options', - 'indieweb-post-kinds' ), + __( + 'Content Options', + 'indieweb-post-kinds' + ), array( 'Kind_Config', 'options_callback' ), 'iwt_options' ); @@ -94,26 +96,27 @@ public static function admin_init() { 'embeds', __( 'Embed Sites into your Response', 'indieweb-post-kinds' ), array( 'Kind_Config', 'checkbox_callback' ), - 'iwt_options', 'iwt-content' , array( 'name' => 'kind_embeds' ) + 'iwt_options', 'iwt-content' , array( + 'name' => 'kind_embeds', + ) ); add_settings_field( 'display', __( 'Display Before Kind', 'indieweb-post-kinds' ), array( 'Kind_Config', 'radio_callback' ), - 'iwt_options', 'iwt-content' , - array( + 'iwt_options', 'iwt-content' , + array( 'name' => 'kind_display', 'class' => Kind_Taxonomy::before_kind() ? '' : 'hidden', 'options' => array( 'icon' => __( 'Show Icon', 'indieweb-post-kinds' ), 'text' => __( 'Show Text', 'indieweb-post-kinds' ), - 'hide' => __( 'Display Nothing', 'indieweb-post-kinds' ) - ) + 'hide' => __( 'Display Nothing', 'indieweb-post-kinds' ), + ), ) ); - if ( POST_KINDS_KSES ) { add_settings_field( 'contentelements', @@ -121,7 +124,9 @@ public static function admin_init() { array( 'Kind_Config', 'textbox_callback' ), 'iwt_options', 'iwt-content', - array( 'name' => 'kind_kses' ) + array( + 'name' => 'kind_kses', + ) ); } // Add Query Var to Admin @@ -129,7 +134,7 @@ public static function admin_init() { } - public static function query_var($vars) { + public static function query_var( $vars ) { $vars[] = 'kindurl'; return $vars; } @@ -169,9 +174,9 @@ public static function options_callback() { * * @access public * @param array $args { - * Arguments. + * Arguments. * - * @type string $name Checkbox Name. + * @type string $name Checkbox Name. */ public static function checkbox_callback( array $args ) { $option = get_option( $args['name'] ); @@ -194,7 +199,7 @@ public static function textbox_callback( array $args ) { if ( is_array( $option ) ) { $option = print_r( $option, true ); } - echo " '; + echo " '; } /** @@ -226,7 +231,7 @@ public static function defaultkind_callback() { $defaultkind = get_option( 'kind_default' ); foreach ( $terms as $term ) { - echo '' . Kind_Taxonomy::get_kind_info( $term, 'singular_name' ) . '
'; + echo '' . Kind_Taxonomy::get_kind_info( $term, 'singular_name' ) . '
'; } } @@ -238,7 +243,7 @@ public static function defaultkind_callback() { public static function radio_callback( array $args ) { $display = get_option( 'kind_display' ); foreach ( $args['options'] as $key => $value ) { - echo '' . $value . '
'; + echo '' . $value . '
'; } } @@ -252,9 +257,9 @@ public static function radio_callback( array $args ) { public static function options_form() { Kind_Taxonomy::kind_defaultterms(); echo '
'; - echo '

' . esc_html__( 'Indieweb Post Kinds', 'Post kinds' ) . '

'; + echo '

' . esc_html__( 'Indieweb Post Kinds', 'indieweb-post-kinds' ) . '

'; echo '

'; - esc_html_e( 'Adds support for responding and interacting with other sites.', 'Post kinds' ); + esc_html_e( 'Adds support for responding and interacting with other sites.', 'indieweb-post-kinds' ); echo '


'; echo '
'; settings_fields( 'iwt_options' ); @@ -264,40 +269,44 @@ public static function options_form() { } public static function add_post_help_tab() { - get_current_screen()->add_help_tab( array( - 'id' => 'post_kind_help', - 'title' => __( 'Post Properties', 'indieweb-post-kinds' ), - 'content' => __(' -

The Post Properties tab represents the Microformats properties of a Post. For different kinds of posts, the different - fields mean something different. Example: Artist Name vs Author Name

-
    Main -
  • URL - The URL the post is responding to
  • -
  • Name/Title - The name of what is being responded to
  • -
  • Summary/Quote - Summary of what the post is responding to or quote
  • -
  • Tags - Tags or categories for the piece to be displayed as hashtags
  • -
-
    Details -
  • Site Name/Publication/Album
  • -
  • Featured Image/Site Icon - The URL of a featured image of what is being responded to or a site icon
  • -
  • Published Time
  • -
  • Updated Time
  • -
-
    Author -
  • Author/Artist Name
  • -
  • Author/Artist URL
  • -
  • Author/Artist Photo URL
  • -
-
    Other -
  • Start Time
  • -
  • End Time
  • -
  • Duration - Duration is calculated based on the difference between start and end time. You may just use the time field, - omitting date and timezone and setting start time to 0:00:00 to set a simple duration.
  • -
  • RSVP - For RSVP posts, you can specify whether you are attending, not attending, unsure, or simply interested.
  • -
- ', 'indieweb-post-kinds'), - ) ); + get_current_screen()->add_help_tab( + array( + 'id' => 'post_kind_help', + 'title' => __( 'Post Properties', 'indieweb-post-kinds' ), + 'content' => __( + ' +

The Post Properties tab represents the Microformats properties of a Post. For different kinds of posts, the different + fields mean something different. Example: Artist Name vs Author Name

+
    Main +
  • URL - The URL the post is responding to
  • +
  • Name/Title - The name of what is being responded to
  • +
  • Summary/Quote - Summary of what the post is responding to or quote
  • +
  • Tags - Tags or categories for the piece to be displayed as hashtags
  • +
+
    Details +
  • Site Name/Publication/Album
  • +
  • Featured Image/Site Icon - The URL of a featured image of what is being responded to or a site icon
  • +
  • Published Time
  • +
  • Updated Time
  • +
+
    Author +
  • Author/Artist Name
  • +
  • Author/Artist URL
  • +
  • Author/Artist Photo URL
  • +
+
    Other +
  • Start Time
  • +
  • End Time
  • +
  • Duration - Duration is calculated based on the difference between start and end time. You may just use the time field, + omitting date and timezone and setting start time to 0:00:00 to set a simple duration.
  • +
  • RSVP - For RSVP posts, you can specify whether you are attending, not attending, unsure, or simply interested.
  • +
+ ', 'indieweb-post-kinds' + ), + ) + ); } } // End Class -?> + diff --git a/includes/class-kind-meta.php b/includes/class-kind-meta.php index d527632..5233bd9 100644 --- a/includes/class-kind-meta.php +++ b/includes/class-kind-meta.php @@ -141,7 +141,7 @@ public static function sanitize_content( $value ) { return $value; } $allowed = wp_kses_allowed_html( 'post' ); - if ( 1 == get_option( 'kind_protection' ) ) { + if ( 1 === (int) get_option( 'kind_protection' ) ) { $allowed = json_decode( get_option( 'kind_kses' ), true ); } return wp_kses( $value , $allowed ); @@ -190,7 +190,7 @@ public function build_meta( $raw ) { * * @return string|array Either a string indicating the URL or an array of URLs. */ - public function get_url( ) { + public function get_url() { if ( ! isset( $this->meta ) ) { return false; } @@ -310,7 +310,7 @@ public function get_author() { * * array $author Data on Author. */ - public function set_author($author) { + public function set_author( $author ) { if ( ! isset( $author ) ) { return false; } @@ -326,7 +326,7 @@ public function set_author($author) { $this->meta['cite']['author'] = $author; } - public function set_cite($cite) { + public function set_cite( $cite ) { if ( ! $cite ) { return false; } @@ -342,7 +342,7 @@ public function set_cite($cite) { $this->meta['cite'] = $cite; } - public function build_time($date, $time, $offset) { + public function build_time( $date, $time, $offset ) { if ( empty( $date ) ) { $date = '0000-01-01'; } @@ -352,34 +352,38 @@ public function build_time($date, $time, $offset) { return $date . 'T' . $time . $offset; } - public static function DateIntervalToString(\DateInterval $interval) { + public static function date_interval_to_string( \DateInterval $interval ) { // Reading all non-zero date parts. - $date = array_filter(array( - 'Y' => $interval->y, - 'M' => $interval->m, - 'D' => $interval->d, - )); + $date = array_filter( + array( + 'Y' => $interval->y, + 'M' => $interval->m, + 'D' => $interval->d, + ) + ); // Reading all non-zero time parts. - $time = array_filter(array( - 'H' => $interval->h, - 'M' => $interval->i, - 'S' => $interval->s, - )); + $time = array_filter( + array( + 'H' => $interval->h, + 'M' => $interval->i, + 'S' => $interval->s, + ) + ); - $specString = 'P'; + $spec = 'P'; // Adding each part to the spec-string. foreach ( $date as $key => $value ) { - $specString .= $value . $key; + $spec .= $value . $key; } if ( count( $time ) > 0 ) { - $specString .= 'T'; + $spec .= 'T'; foreach ( $time as $key => $value ) { - $specString .= $value . $key; + $spec .= $value . $key; } } - return $specString; + return $spec; } public function get_duration() { @@ -398,14 +402,14 @@ public function calculate_duration( $start_string, $end_string ) { if ( ! is_string( $start_string ) || ! is_string( $end_string ) ) { return false; } - if ( $start_string == $end_string ) { + if ( $start_string === $end_string ) { return false; } $start = date_create_from_format( 'Y-m-d\TH:i:sP', $start_string ); $end = date_create_from_format( 'Y-m-d\TH:i:sP', $end_string ); - if ( ($start instanceof DateTime) && ($end instanceof DateTime) ) { + if ( ($start instanceof DateTime) && ($end instanceof DateTime) ) { $duration = $start->diff( $end ); - return self::DateIntervalToString( $duration ); + return self::date_interval_to_string( $duration ); } return false; } @@ -417,7 +421,7 @@ public function divide_time( $time_string ) { return; } $time['date'] = $datetime->format( 'Y-m-d' ); - if ( '0000-01-01' == $time['date'] ) { + if ( '0000-01-01' === $time['date'] ) { $time['date'] = ''; } $time['time'] = $datetime->format( 'H:i:s' ); @@ -435,7 +439,7 @@ public function get( $key ) { return ifset( $this->meta[ $key ] ); } - public function set( $key, $value) { + public function set( $key, $value ) { $this->meta[ $key ] = self::sanitize_text( $value ); } diff --git a/includes/class-kind-plugins.php b/includes/class-kind-plugins.php index c110154..7e3da15 100755 --- a/includes/class-kind-plugins.php +++ b/includes/class-kind-plugins.php @@ -21,19 +21,19 @@ public static function init() { } // Replaces need for Replacing the Entire Excerpt - public static function semantic_post_type($post_type, $post_id) { + public static function semantic_post_type( $post_type, $post_id ) { return _x( 'this', 'indieweb-post-kinds' ) . ' ' . strtolower( get_post_kind( $post_id ) ); } // Replacement for the Semantic Linkbacks Comment Excerpt - public static function comment_text_excerpt($text, $comment = null, $args = array()) { + public static function comment_text_excerpt( $text, $comment = null, $args = array() ) { // only change text for pingbacks/trackbacks/webmentions if ( ! $comment || '' === $comment->comment_type || ! get_comment_meta( $comment->comment_ID, 'semantic_linkbacks_canonical', true ) ) { return $text; } // check comment type $comment_type = get_comment_meta( $comment->comment_ID, 'semantic_linkbacks_type', true ); - if ( ! $comment_type || ! in_array( $comment_type, array_keys( SemanticLinkbacksPlugin::get_comment_type_strings() ) ) ) { + if ( ! $comment_type || ! in_array( $comment_type, array_keys( SemanticLinkbacksPlugin::get_comment_type_strings() ), true ) ) { $comment_type = 'mention'; } $_kind = get_the_terms( $comment->comment_post_ID, 'kind' ); @@ -61,7 +61,7 @@ public static function comment_text_excerpt($text, $comment = null, $args = arra $url = get_comment_meta( $comment->comment_ID, 'semantic_linkbacks_source', true ); } // parse host - $host = parse_url( $url, PHP_URL_HOST ); + $host = wp_parse_url( $url, PHP_URL_HOST ); // strip leading www, if any $host = preg_replace( '/^www\./', '', $host ); // generate output @@ -105,17 +105,17 @@ public static function micropub_set_kind( $input, $wp_args ) { } // Video & audio come before photo, because either of these could contain a photo - if ( isset( $input['properties']['video'] ) || isset( $_FILES['video'] ) ) { + if ( isset( $input['properties']['video'] ) || isset( $_FILES['video'] ) ) { set_post_kind( $wp_args['ID'], 'video' ); return; } - if ( isset( $input['properties']['audio'] ) || isset( $_FILES['audio'] ) ) { + if ( isset( $input['properties']['audio'] ) || isset( $_FILES['audio'] ) ) { set_post_kind( $wp_args['ID'], 'audio' ); return; } - if ( isset( $input['properties']['photo'] ) || isset( $_FILES['photo'] ) ) { + if ( isset( $input['properties']['photo'] ) || isset( $_FILES['photo'] ) ) { set_post_kind( $wp_args['ID'], 'photo' ); return; } @@ -156,4 +156,4 @@ public static function post_formats( $input, $wp_args ) { } // End Class Kind_Plugins -?> + diff --git a/includes/class-kind-tabmeta.php b/includes/class-kind-tabmeta.php index 9289010..aa7be3f 100755 --- a/includes/class-kind-tabmeta.php +++ b/includes/class-kind-tabmeta.php @@ -58,7 +58,8 @@ public static function enqueue_admin_scripts() { // Provide a global object to our JS file containing our REST API endpoint, and API nonce // Nonce must be 'wp_rest' - wp_localize_script( 'kindmeta-response', 'rest_object', + wp_localize_script( + 'kindmeta-response', 'rest_object', array( 'api_nonce' => wp_create_nonce( 'wp_rest' ), 'api_url' => rest_url( '/link-preview/1.0/' ), @@ -87,8 +88,8 @@ public static function kind_get_timezones() { $seconds = $zone->getOffset( new DateTime( 'now' , $zone ) ); $o[] = self::tz_seconds_to_offset( $seconds ); } // exceptions must be catched, else a blank page - catch (Exception $e) { - // die("Exception : " . $e->getMessage() . '
'); + catch ( Exception $e ) { + die( 'Exception : ' . $e->getMessage() . '
' ); // what to do in catch ? , nothing just relax } } @@ -103,7 +104,7 @@ public static function kind_the_time( $prefix, $label, $time ) { if ( isset( $time['offset'] ) ) { $offset = $time['offset']; } - $string = '
'; + $string = '
'; $string .= ''; $string .= ''; $string .= self::select_offset( $prefix, $offset ); @@ -112,10 +113,10 @@ public static function kind_the_time( $prefix, $label, $time ) { public static function select_offset( $prefix, $select ) { $tzlist = self::kind_get_timezones(); - $string = ''; foreach ( $tzlist as $key => $value ) { $string .= '