From 1727f0776084213bc09f7f8bb233a7d395ee4134 Mon Sep 17 00:00:00 2001 From: utahta Date: Mon, 17 Jul 2017 16:00:10 +0900 Subject: [PATCH 1/4] Add docker with php53 --- Makefile | 7 + dockerfiles/php53/Dockerfile | 25 +++ dockerfiles/php53/Makefile | 6 + dockerfiles/php53/docker-compose.yml | 27 +++ dockerfiles/php53/docker-entrypoint.sh | 221 +++++++++++++++++++++++++ 5 files changed, 286 insertions(+) create mode 100644 dockerfiles/php53/Dockerfile create mode 100644 dockerfiles/php53/Makefile create mode 100644 dockerfiles/php53/docker-compose.yml create mode 100755 dockerfiles/php53/docker-entrypoint.sh diff --git a/Makefile b/Makefile index e763660..d8bf1e2 100644 --- a/Makefile +++ b/Makefile @@ -37,3 +37,10 @@ docker/up-wp46-php56: build docker/stop-wp46-php56: @make -s -C ./dockerfiles stop-wp46-php56 + +docker/up-wp48-php53: + @make -s -C ./dockerfiles/php53 up + +docker/stop-wp48-php53: + @make -s -C ./dockerfiles/php53 stop + diff --git a/dockerfiles/php53/Dockerfile b/dockerfiles/php53/Dockerfile new file mode 100644 index 0000000..e8d23fa --- /dev/null +++ b/dockerfiles/php53/Dockerfile @@ -0,0 +1,25 @@ +FROM centos:6 + +RUN set -ex; \ + yum -y update; \ + yum -y install httpd php php-mbstring php-mysql php-gd php-xml + +ENV WORDPRESS_VERSION 4.8 +ENV WORDPRESS_SHA1 3738189a1f37a03fb9cb087160b457d7a641ccb4 + +RUN set -ex; \ + curl -o wordpress.tar.gz -fSL "https://wordpress.org/wordpress-${WORDPRESS_VERSION}.tar.gz"; \ + echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c -; \ +# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress + tar -xzf wordpress.tar.gz -C /usr/src/; \ + rm -f wordpress.tar.gz + +WORKDIR /var/www/html +VOLUME /var/www/html + +COPY docker-entrypoint.sh /usr/local/bin/ + +ENTRYPOINT ["docker-entrypoint.sh"] + +CMD ["/usr/sbin/apachectl", "-DFOREGROUND"] + diff --git a/dockerfiles/php53/Makefile b/dockerfiles/php53/Makefile new file mode 100644 index 0000000..838733b --- /dev/null +++ b/dockerfiles/php53/Makefile @@ -0,0 +1,6 @@ +up: + docker-compose up -d + +stop: + docker-compose stop + diff --git a/dockerfiles/php53/docker-compose.yml b/dockerfiles/php53/docker-compose.yml new file mode 100644 index 0000000..b172890 --- /dev/null +++ b/dockerfiles/php53/docker-compose.yml @@ -0,0 +1,27 @@ +version: '2' + +services: + db: + image: mysql:5.7 + environment: + MYSQL_ROOT_PASSWORD: wordpress + MYSQL_DATABASE: wordpress + MYSQL_USER: wordpress + MYSQL_PASSWORD: wordpress + volumes: + - db_data_php53:/var/lib/mysql + + wordpress: + depends_on: + - db + build: . + ports: + - 8005:80 + volumes: + - ~/repos/WP-Social-Bookmarking-Light/build/wp-social-bookmarking-light:/var/www/html/wp-content/plugins/wp-social-bookmarking-light + environment: + WORDPRESS_DB_HOST: db:3306 + WORDPRESS_DB_PASSWORD: wordpress + +volumes: + db_data_php53: diff --git a/dockerfiles/php53/docker-entrypoint.sh b/dockerfiles/php53/docker-entrypoint.sh new file mode 100755 index 0000000..7cef38c --- /dev/null +++ b/dockerfiles/php53/docker-entrypoint.sh @@ -0,0 +1,221 @@ +#!/bin/bash +# see https://github.com/docker-library/wordpress/blob/master/docker-entrypoint.sh + +set -euo pipefail + +# usage: file_env VAR [DEFAULT] +# ie: file_env 'XYZ_DB_PASSWORD' 'example' +# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of +# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature) +file_env() { + local var="$1" + local fileVar="${var}_FILE" + local def="${2:-}" + if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then + echo >&2 "error: both $var and $fileVar are set (but are exclusive)" + exit 1 + fi + local val="$def" + if [ "${!var:-}" ]; then + val="${!var}" + elif [ "${!fileVar:-}" ]; then + val="$(< "${!fileVar}")" + fi + export "$var"="$val" + unset "$fileVar" +} + +if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ] || [ "$1" == "/usr/sbin/apachectl" ]; then + if ! [ -e index.php -a -e wp-includes/version.php ]; then + echo >&2 "WordPress not found in $PWD - copying now..." + if [ "$(ls -A)" ]; then + echo >&2 "WARNING: $PWD is not empty - press Ctrl+C now if this is an error!" + ( set -x; ls -A; sleep 10 ) + fi + tar cf - --one-file-system -C /usr/src/wordpress . | tar xf - + echo >&2 "Complete! WordPress has been successfully copied to $PWD" + if [ ! -e .htaccess ]; then + # NOTE: The "Indexes" option is disabled in the php:apache base image + cat > .htaccess <<-'EOF' + # BEGIN WordPress + + RewriteEngine On + RewriteBase / + RewriteRule ^index\.php$ - [L] + RewriteCond %{REQUEST_FILENAME} !-f + RewriteCond %{REQUEST_FILENAME} !-d + RewriteRule . /index.php [L] + + # END WordPress + EOF + #chown www-data:www-data .htaccess + fi + fi + + # TODO handle WordPress upgrades magically in the same way, but only if wp-includes/version.php's $wp_version is less than /usr/src/wordpress/wp-includes/version.php's $wp_version + + # allow any of these "Authentication Unique Keys and Salts." to be specified via + # environment variables with a "WORDPRESS_" prefix (ie, "WORDPRESS_AUTH_KEY") + uniqueEnvs=( + AUTH_KEY + SECURE_AUTH_KEY + LOGGED_IN_KEY + NONCE_KEY + AUTH_SALT + SECURE_AUTH_SALT + LOGGED_IN_SALT + NONCE_SALT + ) + envs=( + WORDPRESS_DB_HOST + WORDPRESS_DB_USER + WORDPRESS_DB_PASSWORD + WORDPRESS_DB_NAME + "${uniqueEnvs[@]/#/WORDPRESS_}" + WORDPRESS_TABLE_PREFIX + WORDPRESS_DEBUG + ) + haveConfig= + for e in "${envs[@]}"; do + file_env "$e" + if [ -z "$haveConfig" ] && [ -n "${!e}" ]; then + haveConfig=1 + fi + done + + # linking backwards-compatibility + if [ -n "${!MYSQL_ENV_MYSQL_*}" ]; then + haveConfig=1 + # host defaults to "mysql" below if unspecified + : "${WORDPRESS_DB_USER:=${MYSQL_ENV_MYSQL_USER:-root}}" + if [ "$WORDPRESS_DB_USER" = 'root' ]; then + : "${WORDPRESS_DB_PASSWORD:=${MYSQL_ENV_MYSQL_ROOT_PASSWORD:-}}" + else + : "${WORDPRESS_DB_PASSWORD:=${MYSQL_ENV_MYSQL_PASSWORD:-}}" + fi + : "${WORDPRESS_DB_NAME:=${MYSQL_ENV_MYSQL_DATABASE:-}}" + fi + + # only touch "wp-config.php" if we have environment-supplied configuration values + if [ "$haveConfig" ]; then + : "${WORDPRESS_DB_HOST:=mysql}" + : "${WORDPRESS_DB_USER:=root}" + : "${WORDPRESS_DB_PASSWORD:=}" + : "${WORDPRESS_DB_NAME:=wordpress}" + + # version 4.4.1 decided to switch to windows line endings, that breaks our seds and awks + # https://github.com/docker-library/wordpress/issues/116 + # https://github.com/WordPress/WordPress/commit/1acedc542fba2482bab88ec70d4bea4b997a92e4 + sed -ri -e 's/\r$//' wp-config* + + if [ ! -e wp-config.php ]; then + awk '/^\/\*.*stop editing.*\*\/$/ && c == 0 { c = 1; system("cat") } { print }' wp-config-sample.php > wp-config.php <<'EOPHP' +// If we're behind a proxy server and using HTTPS, we need to alert Wordpress of that fact +// see also http://codex.wordpress.org/Administration_Over_SSL#Using_a_Reverse_Proxy +if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { + $_SERVER['HTTPS'] = 'on'; +} + +EOPHP + #chown www-data:www-data wp-config.php + fi + + # see http://stackoverflow.com/a/2705678/433558 + sed_escape_lhs() { + echo "$@" | sed -e 's/[]\/$*.^|[]/\\&/g' + } + sed_escape_rhs() { + echo "$@" | sed -e 's/[\/&]/\\&/g' + } + php_escape() { + php -r 'var_export(('$2') $argv[1]);' -- "$1" + } + set_config() { + key="$1" + value="$2" + var_type="${3:-string}" + start="(['\"])$(sed_escape_lhs "$key")\2\s*," + end="\);" + if [ "${key:0:1}" = '$' ]; then + start="^(\s*)$(sed_escape_lhs "$key")\s*=" + end=";" + fi + sed -ri -e "s/($start\s*).*($end)$/\1$(sed_escape_rhs "$(php_escape "$value" "$var_type")")\3/" wp-config.php + } + + set_config 'DB_HOST' "$WORDPRESS_DB_HOST" + set_config 'DB_USER' "$WORDPRESS_DB_USER" + set_config 'DB_PASSWORD' "$WORDPRESS_DB_PASSWORD" + set_config 'DB_NAME' "$WORDPRESS_DB_NAME" + + for unique in "${uniqueEnvs[@]}"; do + uniqVar="WORDPRESS_$unique" + if [ -n "${!uniqVar}" ]; then + set_config "$unique" "${!uniqVar}" + else + # if not specified, let's generate a random value + currentVal="$(sed -rn -e "s/define\((([\'\"])$unique\2\s*,\s*)(['\"])(.*)\3\);/\4/p" wp-config.php)" + if [ "$currentVal" = 'put your unique phrase here' ]; then + set_config "$unique" "$(head -c1m /dev/urandom | sha1sum | cut -d' ' -f1)" + fi + fi + done + + if [ "$WORDPRESS_TABLE_PREFIX" ]; then + set_config '$table_prefix' "$WORDPRESS_TABLE_PREFIX" + fi + + if [ "$WORDPRESS_DEBUG" ]; then + set_config 'WP_DEBUG' 1 boolean + fi + + TERM=dumb php -- <<'EOPHP' +connect_error) { + fwrite($stderr, "\n" . 'MySQL Connection Error: (' . $mysql->connect_errno . ') ' . $mysql->connect_error . "\n"); + --$maxTries; + if ($maxTries <= 0) { + exit(1); + } + sleep(3); + } +} while ($mysql->connect_error); + +if (!$mysql->query('CREATE DATABASE IF NOT EXISTS `' . $mysql->real_escape_string($dbName) . '`')) { + fwrite($stderr, "\n" . 'MySQL "CREATE DATABASE" Error: ' . $mysql->error . "\n"); + $mysql->close(); + exit(1); +} + +$mysql->close(); +EOPHP + fi + + # now that we're definitely done writing configuration, let's clear out the relevant envrionment variables (so that stray "phpinfo()" calls don't leak secrets from our code) + for e in "${envs[@]}"; do + unset "$e" + done +fi + +exec "$@" From 1f9766839a28dcfbd4e28cd76a5e014127a02a34 Mon Sep 17 00:00:00 2001 From: utahta Date: Mon, 17 Jul 2017 16:01:44 +0900 Subject: [PATCH 2/4] Fix initialize --- wp-social-bookmarking-light.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wp-social-bookmarking-light.php b/wp-social-bookmarking-light.php index e5b9c56..91eea1a 100644 --- a/wp-social-bookmarking-light.php +++ b/wp-social-bookmarking-light.php @@ -41,4 +41,5 @@ /** * initialize */ -(new \WpSocialBookmarkingLight\Plugin())->init(); +$wpSocialBookmarkingLight = new \WpSocialBookmarkingLight\Plugin(); +$wpSocialBookmarkingLight->init(); From 0f510eb5919e58cbdf5f7a82bbe6f77fe4135aad Mon Sep 17 00:00:00 2001 From: utahta Date: Mon, 17 Jul 2017 16:39:40 +0900 Subject: [PATCH 3/4] Fix work on php5.3 --- dockerfiles/php53/docker-compose.yml | 1 + src/WpSocialBookmarkingLight/Option.php | 2 -- src/WpSocialBookmarkingLight/Plugin.php | 20 +++++++++++--------- src/WpSocialBookmarkingLight/Service.php | 5 ++++- wp-social-bookmarking-light.php | 3 +-- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/dockerfiles/php53/docker-compose.yml b/dockerfiles/php53/docker-compose.yml index b172890..6a68437 100644 --- a/dockerfiles/php53/docker-compose.yml +++ b/dockerfiles/php53/docker-compose.yml @@ -22,6 +22,7 @@ services: environment: WORDPRESS_DB_HOST: db:3306 WORDPRESS_DB_PASSWORD: wordpress + WORDPRESS_DEBUG: 1 volumes: db_data_php53: diff --git a/src/WpSocialBookmarkingLight/Option.php b/src/WpSocialBookmarkingLight/Option.php index 1bf5936..368b8c6 100644 --- a/src/WpSocialBookmarkingLight/Option.php +++ b/src/WpSocialBookmarkingLight/Option.php @@ -106,7 +106,6 @@ public function save(array $data) 'button_type' => $data['gree_button_type'], 'button_size' => $data['gree_button_size'] ), - 'evernote' => array('button_type' => $data['evernote_button_type']), 'tumblr' => array('button_type' => $data['tumblr_button_type']), 'atode' => array('button_type' => $data['atode_button_type']), 'google_plus_one' => array( @@ -228,7 +227,6 @@ private function defaultOption() 'button_type' => '4', 'button_size' => '16' ), - 'evernote' => array('button_type' => 'article-clipper'), 'tumblr' => array('button_type' => '1'), 'atode' => array('button_type' => 'iconsja'), 'google_plus_one' => array( diff --git a/src/WpSocialBookmarkingLight/Plugin.php b/src/WpSocialBookmarkingLight/Plugin.php index 08f72cb..fa949ef 100644 --- a/src/WpSocialBookmarkingLight/Plugin.php +++ b/src/WpSocialBookmarkingLight/Plugin.php @@ -40,13 +40,14 @@ public function getBuilder() /** * Initialize wp actions */ - public function init() + public static function init() { add_action('init', function() { - add_action('wp_head', array($this, 'head')); - add_action('wp_footer', array($this, 'footer')); - add_filter('the_content', array($this, 'theContent')); - add_action('admin_menu', array($this, 'adminMenu')); + $plugin = new Plugin(); + add_action('wp_head', array($plugin, 'head')); + add_action('wp_footer', array($plugin, 'footer')); + add_filter('the_content', array($plugin, 'theContent')); + add_action('admin_menu', array($plugin, 'adminMenu')); }); } @@ -100,17 +101,18 @@ public function theContent($content) public function adminMenu() { if( function_exists('add_options_page') ){ + $admin = $this->admin; $page = add_options_page('WP Social Bookmarking Light', 'WP Social Bookmarking Light', 'manage_options', __FILE__, - function () { - echo $this->admin->page(); + function () use($admin) { + echo $admin->page(); }); add_action('admin_print_styles-' . $page, array($this->admin, 'enqueueStyles')); add_action('admin_print_scripts-' . $page, array($this->admin, 'enqueueScripts')); - add_action('admin_head-' . $page, function () { - echo $this->admin->head(); + add_action('admin_head-' . $page, function () use($admin) { + echo $admin->head(); }); } } diff --git a/src/WpSocialBookmarkingLight/Service.php b/src/WpSocialBookmarkingLight/Service.php index 1ca23b6..8ade894 100644 --- a/src/WpSocialBookmarkingLight/Service.php +++ b/src/WpSocialBookmarkingLight/Service.php @@ -102,7 +102,10 @@ private function link($url, $alt, $icon, $width, $height, $blank = true) */ public function invokeService($service) { - $method = str_replace('_', '', ucwords($service, '_')); // snake_case to camelCase + // snake_case to camelCase + $method = str_replace('_', "\t", $service); + $method = ucwords($method); // for php 5.3 + $method = str_replace("\t", '', $method); return $this->$method(); } diff --git a/wp-social-bookmarking-light.php b/wp-social-bookmarking-light.php index 91eea1a..c65b6bd 100644 --- a/wp-social-bookmarking-light.php +++ b/wp-social-bookmarking-light.php @@ -41,5 +41,4 @@ /** * initialize */ -$wpSocialBookmarkingLight = new \WpSocialBookmarkingLight\Plugin(); -$wpSocialBookmarkingLight->init(); +\WpSocialBookmarkingLight\Plugin::init(); From db97ecd98753306320f8ea4efd007089e4532e81 Mon Sep 17 00:00:00 2001 From: utahta Date: Mon, 17 Jul 2017 17:07:57 +0900 Subject: [PATCH 4/4] v2.0.1 --- readme.txt | 6 +++++- wp-social-bookmarking-light.php | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/readme.txt b/readme.txt index f05672c..47d61a9 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Donate link: https://gumroad.com/l/rWLrL Tags: social, bookmarks, bookmarking, Hatena, Twitter, Facebook, Tumblr, Google Bookmark, Delicious, Digg, reddit, LinkedIn, Instapaper, StumbleUpon, mixi, gree, atode, toread, line, pocket, Pinterest Requires at least: 4.0.0 Tested up to: 4.7 -Stable tag: 2.0.0 +Stable tag: 2.0.1 This plugin inserts social share links at the top or bottom of each post. @@ -49,6 +49,10 @@ This is the list of used social sites: == Changelog == += 2.0.1 = +* Fixed: for PHP 5.3 [#50](https://github.com/utahta/WP-Social-Bookmarking-Light/pull/50) +* Note: We don't intend to actively support on PHP 5.5 or lower, but if you get some problems, please report it. We will fix it. + = 2.0.0 = * Breaking Changes: Drop support for PHP 5.5 or lower, Require PHP 5.6 or higher [#46](https://github.com/utahta/WP-Social-Bookmarking-Light/pull/46) * Breaking Changes: Remove terminated some services diff --git a/wp-social-bookmarking-light.php b/wp-social-bookmarking-light.php index c65b6bd..d80fb72 100644 --- a/wp-social-bookmarking-light.php +++ b/wp-social-bookmarking-light.php @@ -5,7 +5,7 @@ Description: This plugin inserts social share links at the top or bottom of each post. Author: utahta Author URI: https://github.com/utahta/WP-Social-Bookmarking-Light -Version: 2.0.0 +Version: 2.0.1 */ /* Copyright 2010 utahta (email : labs.ninxit@gmail.com)