diff --git a/.docker/.env b/.docker/.env index 6fa5f89c..5a33b925 100644 --- a/.docker/.env +++ b/.docker/.env @@ -1,32 +1,19 @@ -COMPOSE_PROJECT_NAME=italystrap -PROJECT_NAME=italystrap -PHP_VERSION=7.4 -WP_VERSION=6.0 -WP_PORT_TEST=8888 -DB_PORT_TEST=8889 -PMA_PORT_TEST=8890 +# Docker only +PROJECT_NAME="italystrap" +PHP_VERSION="7.4" +WP_VERSION="6.0" -DB_HOST=mysql -DB_NAME=test -DB_USER=root -DB_PASSWORD=root -TABLE_PREFIX=wp_ +WP_PORT=8888 +DB_PORT=8889 +PMA_PORT=8890 -TEST_SITE_DB_DSN=mysql:host=localhost;dbname=test -WP_ROOT_FOLDER="/tmp/wordpress" -TEST_SITE_WP_ADMIN_PATH="/wp-admin" -TEST_SITE_DB_NAME="test" -TEST_SITE_DB_HOST="localhost" -TEST_SITE_DB_USER="root" -TEST_SITE_DB_PASSWORD="root" -TEST_SITE_TABLE_PREFIX="wp_" -TEST_DB_NAME="test" -TEST_DB_HOST="localhost" -TEST_DB_USER="root" -TEST_DB_PASSWORD="root" -TEST_TABLE_PREFIX="wp_" -TEST_SITE_WP_URL="http://wp.localhost" -TEST_SITE_WP_DOMAIN="wp.localhost" -TEST_SITE_ADMIN_EMAIL="admin@wp.localhost" -TEST_SITE_ADMIN_USERNAME="admin" -TEST_SITE_ADMIN_PASSWORD="password" \ No newline at end of file +# Docker and Codeception +DB_NAME="test" +DB_HOST="mysql" +DB_USER="root" +DB_PASSWORD="root" + +# Functional tests +APP_URL=http://localhost +ADMIN_USERNAME=root +ADMIN_PASSWORD=root diff --git a/.docker/codecept b/.docker/codecept old mode 100644 new mode 100755 index cd578182..fa3eb03b --- a/.docker/codecept +++ b/.docker/codecept @@ -1,3 +1,6 @@ #!/usr/bin/env bash -docker exec -w //var/www/html/wp-content/themes/italystrap italystrap_test sh -c "vendor/bin/codecept ${*}" +# Get project name from .env file +PROJECT_NAME=$(grep PROJECT_NAME .env | cut -d '=' -f2 | tr -d '"') + +docker exec -w /var/www/html/wp-content/themes/"${PROJECT_NAME}" "${PROJECT_NAME}"_test sh -c "vendor/bin/codecept ${*}" \ No newline at end of file diff --git a/.docker/composer b/.docker/composer old mode 100644 new mode 100755 index bd804ad9..c8ebad53 --- a/.docker/composer +++ b/.docker/composer @@ -1,3 +1,6 @@ #!/usr/bin/env bash -docker-compose run -w //var/www/html/wp-content/themes/italystrap --rm wordpress sh -c "composer ${*}" +# Get project name from .env file +PROJECT_NAME=$(grep PROJECT_NAME .env | cut -d '=' -f2 | tr -d '"') + +docker-compose run -w /var/www/html/wp-content/themes/"${PROJECT_NAME}" --rm wordpress sh -c "composer ${*}" diff --git a/.docker/docker-compose.yml b/.docker/docker-compose.yml index cb7903f1..69671cfb 100644 --- a/.docker/docker-compose.yml +++ b/.docker/docker-compose.yml @@ -10,7 +10,7 @@ services: container_name: ${PROJECT_NAME:-wordpress}_test restart: always ports: - - ${WP_PORT_TEST}:80 + - ${WP_PORT}:80 environment: WORDPRESS_DB_HOST: ${DB_HOST:-mysql} WORDPRESS_DB_NAME: ${DB_NAME:-test} @@ -20,46 +20,28 @@ services: WORDPRESS_DEBUG: 1 volumes: - ../:/var/www/html/wp-content/themes/${PROJECT_NAME:-wordpress} + - ../tests/_output/:/var/www/html/wp-content/themes/${PROJECT_NAME:-wordpress}/tests/_output/ + - ./codeception.yml:/var/www/html/wp-content/themes/${PROJECT_NAME:-wordpress}/codeception.yml #- ./mu-plugins/:/var/www/html/wp-content/mu-plugins/ depends_on: - mysql networks: - wpbrowser: -# aliases: -# - wp - -# https://mklasen.com/adding-and-using-wp-cli-in-a-docker-compose-setup/ -# wpcli: -# container_name: ${PROJECT_NAME:-wp-cli}-cli_test -# depends_on: -# - wordpress -# image: wordpress:cli -## user: 1000:1000 -# command: tail -f /dev/null -# volumes: -# - wordpress:/var/www/html -# environment: -# WORDPRESS_DB_HOST: ${NAME}-db:3306 -# WORDPRESS_DB_USER: ${DB_USER} -# WORDPRESS_DB_PASSWORD: ${DB_PASSWORD} -# WORDPRESS_DB_NAME: ${DB_NAME} -# profiles: -# - dev + integration_test_networks: mysql: image: mysql:${DB_VERSION:-5.7} container_name: ${PROJECT_NAME:-wordpress}_mysql_test restart: always ports: - - ${DB_PORT_TEST}:3306 + - ${DB_PORT}:3306 environment: MYSQL_DATABASE: ${DB_NAME:-test} - #MYSQL_USER: ${TEST_SITE_DB_USER:-root} + #MYSQL_USER: ${DB_USER:-root} MYSQL_PASSWORD: ${DB_PASSWORD:-root} #MYSQL_RANDOM_ROOT_PASSWORD: '1' MYSQL_ROOT_PASSWORD: ${DB_PASSWORD:-root} networks: - - wpbrowser + - integration_test_networks phpmyadmin: depends_on: @@ -68,14 +50,14 @@ services: container_name: ${PROJECT_NAME}_phpmyadmin_test restart: always ports: - - ${PMA_PORT_TEST}:80 + - ${PMA_PORT}:80 environment: # For max upload from PHPMYADMIN https://github.com/10up/wp-local-docker-v2/issues/40#issuecomment-719915040 UPLOAD_LIMIT: 1G PMA_HOST: ${DB_HOST:-mysql} MYSQL_ROOT_PASSWORD: ${DB_PASSWORD:-root} networks: - - wpbrowser + - integration_test_networks chromedriver: image: selenium/standalone-chrome:4.6.0-20221104 @@ -85,8 +67,8 @@ services: - "4444:4444" - "7900:7900" networks: - - wpbrowser + - integration_test_networks networks: - wpbrowser: + integration_test_networks: driver: bridge diff --git a/.docker/ssh b/.docker/ssh old mode 100644 new mode 100755 index 51bc0abe..aaae7896 --- a/.docker/ssh +++ b/.docker/ssh @@ -1,3 +1,6 @@ #!/usr/bin/env bash -docker exec -it -w //var/www/html/wp-content/themes/italystrap italystrap_test sh +# Get project name from .env file +PROJECT_NAME=$(grep PROJECT_NAME .env | cut -d '=' -f2 | tr -d '"') + +docker exec -it -w //var/www/html/wp-content/themes/"${PROJECT_NAME}" "${PROJECT_NAME}"_test sh diff --git a/.docker/wordpress/Dockerfile b/.docker/wordpress/Dockerfile index 0bfc4fbf..f2014b35 100644 --- a/.docker/wordpress/Dockerfile +++ b/.docker/wordpress/Dockerfile @@ -3,6 +3,20 @@ ARG WP_VERSION FROM wordpress:${WP_VERSION}-php${PHP_VERSION} +# Install pcov for code coverage +RUN set -eux; \ + pecl install pcov; \ + docker-php-ext-enable pcov + +# If you want to use xdebug, uncomment the following lines +# Install xdebug for code coverage +#RUN set -eux; \ +# pecl install xdebug-3.1.4; \ +# docker-php-ext-enable xdebug + +# Set XDEBUG_MODE=coverage or xdebug.mode=coverage +#ENV XDEBUG_MODE=coverage + RUN set -eux; \ apt-get update && apt-get install -y \ git \ @@ -10,6 +24,9 @@ RUN set -eux; \ less # Needed for the WP-CLI \ rm -rf /var/lib/apt/lists/* +# Git add safe directory for the working directory + + # Needed for Db driver # https://github.com/Codeception/Codeception/issues/3605 RUN docker-php-ext-install \ diff --git a/.docker/wp b/.docker/wp deleted file mode 100644 index b2c7801c..00000000 --- a/.docker/wp +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -docker exec -w /var/www/html/wp-content/plugins/mhh-extended-links mhh-extended-links_test sh -c "wp ${*} --allow-root" diff --git a/.env b/.env index 6cd3f106..9d355fbe 100644 --- a/.env +++ b/.env @@ -1,7 +1,9 @@ TEST=test COMPOSE_PROJECT_NAME=italystrap PROJECT_NAME=italystrap +FOLDER_NAME=italystrap PHP_VERSION=7.4 +MATRIX_PHP_VERSION=80 WP_VERSION=6.0 WP_PORT_TEST=8888 DB_PORT_TEST=8889 @@ -19,14 +21,13 @@ TABLE_PREFIX=wp_ TESTS_DIR=tests/php -#WP_ROOT_FOLDER="../../../" -WP_ROOT_FOLDER="/var/www/html" +WP_ROOT_FOLDER="../../../" # WPUnit Suite config WPUNIT_ROOT_FOLDER="../../../" -#WPUNIT_ROOT_FOLDER="/var/www/html" + WPUNIT_DB_NAME=test -WPUNIT_DB_HOST=mysql +WPUNIT_DB_HOST=localhost WPUNIT_DB_USER=root WPUNIT_DB_PASSWORD=root WPUNIT_TABLE_PREFIX=wp_ @@ -34,48 +35,27 @@ WPUNIT_SITE_WP_DOMAIN=localhost.local WPUNIT_SITE_ADMIN_EMAIL=admin@localhost.local # Functional and Acceptance Unit Suite config for WPDB driver -WPDB_DB_DSN=mysql:host=mysql;dbname=test +WPDB_DB_DSN=mysql:host=localhost;dbname=test WPDB_DB_USER=root WPDB_DB_PASSWORD=root # This is the url inside the container -WPDB_WP_URL=http://localhost -WPDB_WP_DOMAIN=localhost +WPDB_WP_URL=http://localhost:8888 +#WPDB_WP_DOMAIN=localhost:8888 WPDB_TABLE_PREFIX=wp_ WPDB_DUMP_FILE="tests/_data/dump.sql" # Functional and Acceptance Unit Suite config for WPBrowser driver # This is the url inside the container -WPBROWSER_WP_URL=http://localhost -#WPBROWSER_ADMIN_USERNAME=root -#WPBROWSER_ADMIN_PASSWORD=root -WPBROWSER_ADMIN_USERNAME=admin -WPBROWSER_ADMIN_PASSWORD=password +WPBROWSER_WP_URL=http://localhost:8888 +WPBROWSER_ADMIN_USERNAME=root +WPBROWSER_ADMIN_PASSWORD=root WPBROWSER_WP_ADMIN_PATH=/wp-admin # Used only for acceptance.suite.yml tests inside WPWebDriver configuration. # The value must be the name of the WordPress container # for resolving the correct IP of the machine if you use Docker as environment. # This will be also used for replace the hardcoded dump URL with the one below -CHROMEDRIVER_WP_URL="http://italystrap_test" +CHROMEDRIVER_WP_URL="http://localhost:8888" # This must be the name of the Selenium container -CHROMEDRIVER_HOST=chromedriver +CHROMEDRIVER_HOST=localhost CHROMEDRIVER_PORT="4444" - -#TEST_SITE_DB_DSN=mysql:host=localhost;dbname=test -#WP_ROOT_FOLDER="/tmp/wordpress" -#TEST_SITE_WP_ADMIN_PATH="/wp-admin" -#TEST_SITE_DB_NAME="test" -#TEST_SITE_DB_HOST="localhost" -#TEST_SITE_DB_USER="root" -#TEST_SITE_DB_PASSWORD="root" -#TEST_SITE_TABLE_PREFIX="wp_" -#TEST_DB_NAME="test" -#TEST_DB_HOST="localhost" -#TEST_DB_USER="root" -#TEST_DB_PASSWORD="root" -#TEST_TABLE_PREFIX="wp_" -#TEST_SITE_WP_URL="http://wp.localhost" -#TEST_SITE_WP_DOMAIN="wp.localhost" -#TEST_SITE_ADMIN_EMAIL="admin@wp.localhost" -#TEST_SITE_ADMIN_USERNAME="admin" -#TEST_SITE_ADMIN_PASSWORD="password" \ No newline at end of file diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml new file mode 100644 index 00000000..573e9af1 --- /dev/null +++ b/.github/workflows/integration.yml @@ -0,0 +1,106 @@ +name: CI + +env: + REPOSITORY_NAME: italystrap + PROJECT_KIND: themes + DB_HOST: localhost + DB_NAME: test + DB_USER: root + DB_PASSWORD: root + TABLE_PREFIX: wp_ + APP_FOLDER_PATH: /tmp/app + APP_PORT: 8888 + APP_HOST: localhost + APP_USER: root + APP_PASSWORD: root + +on: + push: + branches: + - master + pull_request: + + workflow_dispatch: + +jobs: + + tests: + name: 🐘 Tests on PHP ${{matrix.php_versions}} & APP version ${{matrix.app_versions}} + + strategy: + matrix: + php_versions: ['8'] + app_versions: ['6.0'] + + runs-on: ubuntu-latest + continue-on-error: ${{ matrix.php_versions == '8.2' }} + if: "!contains(github.event.head_commit.message, '--skip ci') && !github.event.pull_request.draft" + + steps: + - uses: actions/checkout@v3 + + - name: Start Selenium for using later + run: docker run -d --net=host --shm-size=2g selenium/standalone-chrome:4.6.0-20221104 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{matrix.php_versions}} + + - name: Start MySQL + run: | + sudo systemctl start mysql.service + mysql -e "CREATE DATABASE IF NOT EXISTS ${{env.DB_NAME}};" -u${{env.DB_USER}} -p${{env.DB_PASSWORD}} + + - name: Install CLI + run: | + curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar + chmod +x wp-cli.phar + sudo mv wp-cli.phar /usr/local/bin/wp + wp cli info + + - name: Create folder for running the App + run: mkdir -p ${{env.APP_FOLDER_PATH}} + + - name: Install App + working-directory: ${{env.APP_FOLDER_PATH}} + run: | + wp core download --version="${{matrix.app_versions}}" + wp config create --dbname="${{env.DB_NAME}}" --dbuser="${{env.DB_USER}}" --dbpass="${{env.DB_PASSWORD}}" --dbhost="${{env.DB_HOST}}" --dbprefix="${{env.TABLE_PREFIX}}" + wp core install --url="${{env.APP_HOST}}:${{env.APP_PORT}}" --title="Test" --admin_user="${{env.APP_USER}}" --admin_password="${{env.APP_PASSWORD}}" --admin_email="${{env.APP_USER}}@${{env.APP_HOST}}.test" --skip-email + wp core update-db + cp -r $GITHUB_WORKSPACE ${{env.APP_FOLDER_PATH}}/wp-content/${{env.PROJECT_KIND}}/${{env.REPOSITORY_NAME}} + + - uses: "ramsey/composer-install@v2" + with: + working-directory: "${{env.APP_FOLDER_PATH}}/wp-content/${{env.PROJECT_KIND}}/${{env.REPOSITORY_NAME}}" + + - name: Activate ${{env.REPOSITORY_NAME}} + working-directory: ${{env.APP_FOLDER_PATH}} + run: | + wp plugin deactivate --all + wp site empty --yes + wp theme activate ${{env.REPOSITORY_NAME}} + wp theme list --status=active + chmod -R 777 wp-content/${{env.PROJECT_KIND}}/${{env.REPOSITORY_NAME}} + ls -la wp-content/${{env.PROJECT_KIND}}/${{env.REPOSITORY_NAME}} + wp db export wp-content/${{env.PROJECT_KIND}}/${{env.REPOSITORY_NAME}}/tests/_data/dump.sql + + - name: Build codeception + working-directory: ${{env.APP_FOLDER_PATH}}/wp-content/${{env.PROJECT_KIND}}/${{env.REPOSITORY_NAME}} + run: ./vendor/bin/codecept build + + - name: Run Unit & Integration test + working-directory: ${{env.APP_FOLDER_PATH}}/wp-content/${{env.PROJECT_KIND}}/${{env.REPOSITORY_NAME}} + run: | + ./vendor/bin/codecept run unit + ./vendor/bin/codecept run integration + + - name: Start dev server + run: php -S ${{env.APP_HOST}}:${{env.APP_PORT}} -t ${{env.APP_FOLDER_PATH}} >/dev/null 2>&1 & + + - name: Run Functional and Acceptance test + working-directory: ${{env.APP_FOLDER_PATH}}/wp-content/${{env.PROJECT_KIND}}/${{env.REPOSITORY_NAME}} + run: | + ./vendor/bin/codecept run functional --debug + ./vendor/bin/codecept run acceptance --debug diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index e769d17d..00000000 --- a/.travis.yml +++ /dev/null @@ -1,126 +0,0 @@ -# https://www.theaveragedev.com/installing-and-setting-up-wordpress-and-nginx-for-travis-ci-tests/ - -language: php - -notifications: - email: false - -php: - - 7.2 - - nightly - -matrix: - fast_finish: true - allow_failures: - - php: nightly - - env: WP_VERSION=nightly - -services: - - mysql - -cache: - apt: true - directories: - - $HOME/.composer/cache - -addons: - apt: - packages: - - libjpeg-dev - - libpng12-dev - - php7.0-fpm - - php7.0-mysql - - nginx - hosts: - - wp.localhost - -env: - global: - - WP_FOLDER="/tmp/wordpress" - - WP_URL="http://wp.localhost" - - WP_DOMAIN="wp.localhost" - - DB_NAME="test" - - TEST_DB_NAME="wploader" - - WP_TABLE_PREFIX="wp_" - - WP_ADMIN_USERNAME="admin" - - WP_ADMIN_PASSWORD="admin" - matrix: - - WP_VERSION=latest - - WP_VERSION=nightly - -before_install: - # create the databases that will be used in the tests - - mysql -e "create database IF NOT EXISTS $DB_NAME;" -uroot - - mysql -e "create database IF NOT EXISTS $TEST_DB_NAME;" -uroot - # set up folders - - mkdir -p $WP_FOLDER - - mkdir tools - # install wp-cli in the `tools` folder - - wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar -P $(pwd)/tools/ - - chmod +x tools/wp-cli.phar && mv tools/wp-cli.phar tools/wp - # append the `tools` folder to the PATH - - export PATH=$PATH:$(pwd)/tools - # prepend the `vendor/bin` folder the PATH - - export PATH=vendor/bin:$PATH - -install: - # install WordPress - - cd $WP_FOLDER - - ls - - wp core download --version=$WP_VERSION - - wp config create --dbname="$DB_NAME" --dbuser="root" --dbpass="" --dbhost="127.0.0.1" --dbprefix="$WP_TABLE_PREFIX" - - wp core install --url="$WP_URL" --title="Test" --admin_user="$WP_ADMIN_USERNAME" --admin_password="$WP_ADMIN_PASSWORD" --admin_email="admin@$WP_DOMAIN" --skip-email - - wp rewrite structure '/%postname%/' --hard - # update WordPress database to avoid prompts - - wp core update-db - # copy the theme in the WordPress themes folder - - cp -r $TRAVIS_BUILD_DIR $WP_FOLDER/wp-content/themes/italystrap - # show the themes folder contents to make sure the theme folder is there - - cd $WP_FOLDER/wp-content/themes/italystrap - - | - if [ $TRAVIS_PHP_VERSION = 'nightly' ]; then - composer install --prefer-dist --no-suggest --ignore-platform-reqs; - else - composer install --prefer-dist --no-suggest - fi - - ls -l - # activate the theme - - wp theme activate italystrap - # make sure the theme is active on the site - - wp theme list --status=active - # export a dump of the just installed database to the _data folder - - wp db export $TRAVIS_BUILD_DIR/tests/_data/dump.sql - # get back to the build folder - - cd $TRAVIS_BUILD_DIR - - | - if [ $TRAVIS_PHP_VERSION = 'nightly' ]; then - composer install --prefer-dist --no-suggest --ignore-platform-reqs; - else - composer install --prefer-dist --no-suggest - fi - - ls -l - # open up the site folder to allow the PHP application to read/write/execute on it - - sudo chmod -R 777 $WP_FOLDER - # copy the Nginx configuration file to the available sites - #- sudo cp build/travis-nginx-conf /etc/nginx/sites-available/$WP_DOMAIN - #- sudo sed -e "s?%WP_FOLDER%?$WP_FOLDER?g" --in-place /etc/nginx/sites-available/$WP_DOMAIN - #- sudo sed -e "s?%WP_DOMAIN%?$WP_DOMAIN?g" --in-place /etc/nginx/sites-available/$WP_DOMAIN - # enable the site - - sudo ln -s /etc/nginx/sites-available/$WP_DOMAIN /etc/nginx/sites-enabled/ - -before_script: - # restart Nnginx and PHP-FPM services - - sudo service php7.0-fpm restart - - sudo service nginx restart - - # build Codeception modules - - codecept build - -script: - - find ./config/ ./functions/ ./src/ ./templates/ ./tests/ -type f -name '*.php' -print0 | xargs -0 -L 1 -P 4 -- php -l - - vendor/bin/phpcs --ignore=./tests/_support/* ./config/ ./functions/ ./src/ ./templates/ ./tests/ - - vendor/bin/phpstan analyze -# - vendor/bin/psalm - - codecept run wpunit && codecept run unit --coverage-text -# - vendor/bin/infection --threads=4 -# - vendor/bin/phpbench run --report=performance \ No newline at end of file diff --git a/404.php b/404.php index 71394282..93b63f46 100644 --- a/404.php +++ b/404.php @@ -1,4 +1,5 @@ make( EventDispatcherInterface::class ); +/** @var ListenerRegisterInterface $listenerRegister */ +$listenerRegister = $injector->make(ListenerRegisterInterface::class); /** @var ConfigInterface $config */ $config = $injector->make(ConfigInterface::class); @@ -105,7 +106,7 @@ addListener( + $listenerRegister->addListener( 'comment_form_comments_closed', static function () { echo '

' . __( 'Comments are closed.', 'italystrap' ) . '

'; diff --git a/composer.json b/composer.json index ac138d6b..01261e7c 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ ], "require": { "php" : ">=7.4", - "italystrap/empress": "^2.0.0", + "italystrap/empress": "dev-modularized", "italystrap/event": "dev-master", "italystrap/config": "^2.0", "italystrap/helpers": "^1.0", @@ -43,7 +43,8 @@ "rdlowrey/auryn": "^1.4", "overclokk/minimum-requirements": "dev-master", "cmb2/cmb2": "2.6.0", - "yiisoft/json": "^1.0" + "yiisoft/json": "^1.0", + "symfony/polyfill-php80": "^1.0" }, "require-dev": { "lucatume/wp-browser": "^3.0.0", @@ -58,32 +59,40 @@ "codeception/module-cli": "^1.0", "codeception/util-universalframework": "^1.0", "phpspec/prophecy-phpunit": "^2.0.0", - "italystrap/debug": "^2.0", + + "italystrap/debug": "dev-master", "italystrap/theme-json-generator": "dev-master", + "squizlabs/php_codesniffer": "*", "phpcompatibility/php-compatibility": "*", "dealerdirect/phpcodesniffer-composer-installer": "^0.7", - "phpstan/phpstan": "^1.8.2", - "szepeviktor/phpstan-wordpress": "^v1.1.0", + "vimeo/psalm": "^4.8", + "humanmade/psalm-plugin-wordpress": "^2.0", + "phpbench/phpbench": "@dev", "infection/infection": "^0.25.0", "infection/codeception-adapter": "^0.4.0", + "phpmetrics/phpmetrics": "^2.7.0", "brianium/paratest": "^6.0.0", + "symfony/asset": "^5.0", "inpsyde/assets": "^2.1", "downshiftorg/wp-http": "^2.0", "wordpress/wordpress": "dev-master", - "humanmade/psalm-plugin-wordpress": "^2.0", "monolog/monolog": "^2.3", "franzl/studio": "^0.15.0", "rector/rector": "^0.14.0", - "hoa/console": "^3.17" + "hoa/console": "^3.17", + "fig/event-dispatcher-util": "^1.0" }, "autoload": { "psr-4": { - "ItalyStrap\\": "src/" + "ItalyStrap\\": [ + "src/", + "tests/_data/Experimental/src/" + ] }, "files": [ "functions/core-booleans.php", @@ -96,11 +105,15 @@ ] }, "autoload-dev": { - "classmap": [ - "tests/" - ], "psr-4": { - "ItalyStrap\\Tests\\": "tests/" + "ItalyStrap\\Tests\\": [ + "tests/src", + "tests/_data/fixtures/src" + ], + "ItalyStrap\\Tests\\Unit\\": "tests/unit", + "ItalyStrap\\Tests\\Integration\\": "tests/integration", + "ItalyStrap\\Tests\\Functional\\": "tests/functional", + "ItalyStrap\\Tests\\Acceptance\\": "tests/acceptance" } }, "extra": { @@ -108,7 +121,7 @@ "vendor/{$name}/": ["cmb2/cmb2"] }, "theme-json": { - "callable": "\\ItalyStrap\\Asset\\JsonData::getJsonData", + "callable": "\\ItalyStrap\\Asset\\ThemeJson::writeJson", "path-for-theme-sass": "assets/sass/" } }, @@ -127,58 +140,58 @@ "@infection" ], "cs": [ - "vendor\\bin\\phpcbf -p --ignore=./tests/_support/* ./config/ ./functions/ ./src/ ./templates/ ./tests/ && vendor\\bin\\phpcs -p --ignore=./tests/_support/* ./config/ ./functions/ ./src/ ./templates/ ./tests/" + "@php vendor/bin/phpcs -p" ], - "psalm": [ - "vendor\\bin\\psalm --no-cache" + "cs:fix": [ + "@php vendor/bin/phpcbf -p" ], - "phpstan": [ - "vendor\\bin\\phpstan analyze --level=max" + "psalm": [ + "@php vendor//bin//psalm --no-cache" ], "analyze": [ - "vendor\\bin\\phpstan analyze --level=max && vendor\\bin\\psalm" + "@php vendor//bin//phpstan analyze --level=max && vendor//bin//psalm" ], "infection": [ - "vendor\\bin\\infection --threads=8" + "@php vendor//bin//infection --threads=8" ], "unit": [ - "vendor\\bin\\codecept run unit", + "@php vendor//bin//codecept run unit", "@clean" ], "unit:cov": [ - "vendor\\bin\\codecept run unit --coverage", + "@php vendor//bin//codecept run unit --coverage", "@clean" ], "unit:debug": [ - "vendor\\bin\\codecept run unit --debug", + "@php vendor//bin//codecept run unit --debug", "@clean" ], - "wpunit": [ - "vendor\\bin\\codecept run wpunit", + "integration": [ + "@php vendor//bin//codecept run integration", "@clean" ], - "wpunit:debug": [ - "vendor\\bin\\codecept run wpunit --debug", + "integration:debug": [ + "@php vendor//bin//codecept run integration --debug", "@clean" ], "functional": [ - "vendor\\bin\\codecept run functional" + "@php vendor//bin//codecept run functional" ], "bench": [ - "vendor\\bin\\phpbench run --report=performance" + "@php vendor//bin//phpbench run --report=performance" ], "metrics": [ - "vendor\\bin\\phpmetrics --report-html='./tests/_output/report' ./src", + "@php vendor//bin//phpmetrics --report-html='./tests/_output/report' ./src", "@clean" ], "insights": [ - "vendor\\bin\\phpinsights" + "@php vendor//bin//phpinsights" ], "clean": [ - "vendor\\bin\\codecept clean" + "@php vendor//bin//codecept clean" ], "rector": [ - "vendor\\bin\\rector process src" + "@php vendor//bin//rector process src" ], "theme:json": [ "\\ItalyStrap\\ThemeJsonGenerator\\Composer\\Plugin::run" diff --git a/composer.phar b/composer.phar deleted file mode 100644 index 3fb713fd..00000000 Binary files a/composer.phar and /dev/null differ diff --git a/config/assets/scripts.php b/config/assets/scripts.php index 6e5cf51d..e3ff99fe 100644 --- a/config/assets/scripts.php +++ b/config/assets/scripts.php @@ -1,4 +1,5 @@ CURRENT_TEMPLATE_SLUG, - AssetConfigBuilder::FILE_NAME => experimental_generate_asset_index_filename( 'js' ), -// Asset::DEPENDENCIES => ['jquery'], - Asset::IN_FOOTER => true, - Asset::LOCALIZE => [ - Script::OBJECT_NAME => 'pluginParams', - Script::PARAMS => [ - 'ajaxurl' => admin_url( '/admin-ajax.php' ), - 'ajaxnonce' => wp_create_nonce( 'ajaxnonce' ), - // 'api_endpoint' => site_url( '/wp-json/rest/v1/' ), - ], - ], - ], + [ + Asset::HANDLE => CURRENT_TEMPLATE_SLUG, + AssetConfigBuilder::FILE_NAME => experimental_generate_asset_index_filename('js'), +// Asset::DEPENDENCIES => ['jquery'], + Asset::IN_FOOTER => true, + Asset::LOCALIZE => [ + Script::OBJECT_NAME => 'pluginParams', + Script::PARAMS => [ + 'ajaxurl' => admin_url('/admin-ajax.php'), + 'ajaxnonce' => wp_create_nonce('ajaxnonce'), + // 'api_endpoint' => site_url( '/wp-json/rest/v1/' ), + ], + ], + ], ]; diff --git a/config/assets/styles.php b/config/assets/styles.php index 9a211ee9..0283ffb0 100644 --- a/config/assets/styles.php +++ b/config/assets/styles.php @@ -1,16 +1,18 @@ CURRENT_TEMPLATE_SLUG, - AssetConfigBuilder::FILE_NAME => experimental_generate_asset_index_filename( 'css' ), - ], + [ + Asset::HANDLE => CURRENT_TEMPLATE_SLUG, + AssetConfigBuilder::FILE_NAME => experimental_generate_asset_index_filename('css'), + ], ]; diff --git a/config/autoload/components.global.php b/config/autoload/components.global.php deleted file mode 100644 index e4c06b69..00000000 --- a/config/autoload/components.global.php +++ /dev/null @@ -1,128 +0,0 @@ - [ - AuthorInfo::class, - ], - - AurynConfig::ALIASES => [ - - ], - - AurynConfig::DEFINITIONS => [ - - \ItalyStrap\Components\Navigations\Navbar::class => [ - ':fallback_cb' => [ \ItalyStrap\Navbar\BootstrapNavMenu::class, 'fallback' ], - ], - - NavMenuPrimary::class => [ - '+fallback' => static function ( string $named_param, Injector $injector ): callable { - return $injector->make( NavMenuFallback::class ); - }, - ], - ], - - /** - * ======================================================================== - * - * Components Subscriber Classes - * - * ======================================================================== - */ - ComponentSubscriberExtension::class => [ - - Breadcrumbs::class, - - PostAuthorInfo::class, - ArchiveAuthorInfo::class, - ArchiveHeadline::class, - - FeaturedImage::class, - Title::class, - Meta::class, - Preview::class, - Content::class, - Excerpt::class, - Modified::class, - Pager::class, - Pagination::class, -// BlockQuery::class, - - Sidebar::class, - - Entry::class, - - EntryNoneImage::class, - EntryNoneTitle::class, - EntryNoneContent::class, - EntryNone::class, - - Loop::class, - - SiteLogo::class, - SiteTitle::class, -// SiteTagline::class, - - MiscNavigation::class, - CustomHeaderImage::class, - - NavMenuToggleButton::class, - NavMenuHeader::class, - NavMenuPrimary::class, - NavMenuSecondary::class, - MainNavigationOlder::class, -// MainNavigation::class, - - Comments::class, - Colophon::class, - Header::class, - FooterWidgetArea::class, - Footer::class, - Index::class => Index::class, - ], -]; diff --git a/config/autoload/config.global.php b/config/autoload/config.global.php index e8d24ec9..b141f7cb 100644 --- a/config/autoload/config.global.php +++ b/config/autoload/config.global.php @@ -1,48 +1,34 @@ [ - ConfigThemeModsProvider::class => [ - '+theme_mods' => static function () { - return (array) \get_theme_mods(); - }, - ], - ], - - ConfigProviderExtension::class => [ - ConfigThemeProvider::class, - ConfigCustomHeaderProvider::class, - ConfigSiteLogoProvider::class, - ConfigColorSectionProvider::class, - ConfigMiscProvider::class, - ConfigNavigationProvider::class, - ConfigColophonProvider::class, + AurynConfig::DEFINITIONS => [ + ConfigThemeModsProvider::class => [ + '+theme_mods' => static function () { + return (array) \get_theme_mods(); + }, + ], + ], - ConfigNotFoundProvider::class, - ConfigPostThumbnailProvider::class, - ConfigThemeSupportProvider::class, - ConfigPostTypeSupportProvider::class, - ConfigSidebarProvider::class, + ConfigProviderExtension::class => [ + ConfigCustomHeaderProvider::class, + ConfigSiteLogoProvider::class, + ConfigColorSectionProvider::class, + ConfigMiscProvider::class, + ConfigColophonProvider::class, - /** This must run after all */ - ConfigThemeModsProvider::class, - ], + ConfigNotFoundProvider::class, + ], ]; diff --git a/config/autoload/customizer.global.php b/config/autoload/customizer.global.php index 4a43b9fd..6df74f53 100644 --- a/config/autoload/customizer.global.php +++ b/config/autoload/customizer.global.php @@ -1,4 +1,5 @@ [ - SiteLogoFields::class, - BreadcrumsFields::class, - CustomCssFields::class, - SiteIdentityFields::class, - PanelFields::class, - BetaFields::class, - ColorFields::class, - ColophonFields::class, - CustomHeaderFields::class, - LayoutFields::class, - NavbarFields::class, - PostThumbnailFields::class, - PostContentTemplateFields::class, - NotFoundFields::class, - ], - SubscribersConfigExtension::SUBSCRIBERS => [ - DefaultPostThumbnailSubscriber::class, - ThemeSubmenuPageSubscriber::class, - ], + CustomizerProviderExtension::class => [ + SiteLogoFields::class, + BreadcrumsFields::class, + CustomCssFields::class, + SiteIdentityFields::class, + PanelFields::class, + BetaFields::class, + ColorFields::class, + ColophonFields::class, + CustomHeaderFields::class, + LayoutFields::class, + NavbarFields::class, + PostThumbnailFields::class, + PostContentTemplateFields::class, + NotFoundFields::class, + ], + SubscribersConfigExtension::SUBSCRIBERS => [ + DefaultPostThumbnailSubscriber::class, + ThemeSubmenuPageSubscriber::class, + ], ]; diff --git a/config/autoload/dependencies.global.php b/config/autoload/dependencies.global.php index a88bb5ed..a579d1c5 100644 --- a/config/autoload/dependencies.global.php +++ b/config/autoload/dependencies.global.php @@ -1,287 +1,185 @@ [ - EventDispatcher::class, - SubscriberRegister::class, - - /** - * Make sure the config is shared. - * Already shared in bootstrap.php or in ACM if is active. - */ - Config::class, - - Attributes::class, - Tag::class, - View\View::class, - - ImageSizeInterface::class, - - \WP_Theme::class, - \WP_Query::class, - ], - - /** - * ========================================================== - * - * Autoload Aliases Class - * - * string - * - * ========================================================== - */ - AurynConfig::ALIASES => [ - EventDispatcherInterface::class => EventDispatcher::class, - SubscriberRegisterInterface::class => SubscriberRegister::class, - - ConfigInterface::class => Config::class, - - AttributesInterface::class => Attributes::class, - TagInterface::class => Tag::class, - - FileInfoFactoryInterface::class => FileInfoFactory::class, - SearchFileStrategy::class => FilesHierarchyIterator::class, - FinderInterface::class => Finder::class, - - ViewInterface::class => View\View::class, - - ImageSizeInterface::class => ImageSize::class, - - NavMenuLocationInterface::class => NavMenuLocation::class, - NavMenuInterface::class => NavMenu::class, - - Walker_Nav_Menu::class => Navbar\BootstrapNavMenu::class, - ], - - /** - * ========================================================== - * - * Autoload Classes definitions - * - * @example : - * 'walker' => '\NameSpace\ClassName', - * ':walker' => new \NameSpace\ClassName(), - * '+walker' => function () { - * return new \NameSpace\ClassName(); - * }, - * - * ========================================================== - */ - AurynConfig::DEFINITIONS => [ - View\View::class => [ - '+finder' => static function ( string $named_param, Injector $injector ): FinderInterface { - $config = $injector->make( ConfigInterface::class ); - - $stylesheet_dir = $config->get( \ItalyStrap\Config\ConfigThemeProvider::STYLESHEET_DIR ); - $template_dir = $config->get( \ItalyStrap\Config\ConfigThemeProvider::TEMPLATE_DIR ); - $view_dir = $config->get( \ItalyStrap\Config\ConfigThemeProvider::VIEW_DIR ); - - $finder = (new FinderFactory())->make() - ->in( [ - $stylesheet_dir . '/' . $view_dir, - $template_dir . '/' . $view_dir, - ] ); - - return $finder; - }, - ], - - EditorSubscriber::class => [ - '+finder' => static function ( string $named_param, Injector $injector ) { - $config = $injector->make( ConfigInterface::class ); - - $stylesheet_dir = $config->get( \ItalyStrap\Config\ConfigThemeProvider::STYLESHEET_DIR ); - $template_dir = $config->get( \ItalyStrap\Config\ConfigThemeProvider::TEMPLATE_DIR ); - - $finder = (new FinderFactory())->make() - ->in( [ - $stylesheet_dir . '/assets/', - $template_dir . '/assets/', - ] ); - - $finder->names([ - '../css/editor-style.css', - '../assets/css/editor-style.css', - ]); - - return $finder; - }, - ], - ], - - /** - * ========================================================== - * - * Autoload Parameters Definitions - * - * string - * - * ========================================================== - */ - AurynConfig::DEFINE_PARAM => [ - ], - - /** - * ======================================================================== - * - * Autoload Delegates - * @link https://github.com/rdlowrey/auryn#instantiation-delegates - * 'MyComplexClass' => $complexClassFactory, - * 'SomeClassWithDelegatedInstantiation' => 'MyFactory', - * 'SomeClassWithDelegatedInstantiation' => 'MyFactory::factoryMethod' - * - * string - * - * ======================================================================== - */ - AurynConfig::DELEGATIONS => [ - \WP_Theme::class => static function (): \WP_Theme { - return \wp_get_theme( \get_template() ); - }, - \WP_Query::class => static function (): \WP_Query { - global $wp_query; - return $wp_query; - }, - ], - - /** - * ======================================================================== - * - * Autoload Prepares - * @link https://github.com/rdlowrey/auryn#prepares-and-setter-injection - * - * string - * - * ======================================================================== - */ - AurynConfig::PREPARATIONS => [ - - /** - * This class is lazy loaded - */ - AssetManager::class => new ExperimentalAssetPreparator(), - ], - - /** - * ======================================================================== - * - * Lazyload Classes - * Loaded on admin and front-end - * - * Useful if you need to load lazily your classes, for example - * if you want classes are loaded only when are really needed. - * - * ======================================================================== - */ - AurynConfig::PROXY => [ - AssetManager::class, -// SidebarsSubscriber::class, - ], - - /** - * ======================================================================== - * - * Autoload Subscribers Classes - * Loaded on admin and front-end - * - * If you use key => value pair make sure to bind the key with an option name - * to activate or deactivate the service from an option panel. - * - * ======================================================================== - */ - SubscribersConfigExtension::SUBSCRIBERS => [ - - AfterSetupThemeEvent::class, - License::class, - ConfigCurrentTemplateSubscriber::class, - ConfigWpSubscriber::class, - - ExperimentalCustomizerOptionWithAndPosition::class, - OembedWrapper::class, - - /** - * Register Theme stuff - */ - NavMenusSubscriber::class, - SidebarsSubscriber::class, - SupportSubscriber::class, - TextDomainSubscriber::class, - ThumbnailsSubscriber::class, - PostTypeSupportSubscriber::class, - Metaboxes::class, - - Admin\Nav_Menu\ItemCustomFields::class, - - CustomizerBodyTagAttributesSubscriber::class, - CustomizerAssetsSubscriber::class, - InlineStyleSubscriber::class, - - /** - * With this class I can lazyload the AssetManager::class - * see above in the PROXY config. - */ - AssetsSubscriber::class, - Asset\EditorSubscriber::class, - ], + /** + * ========================================================== + * + * Autoload Shared Classes + * + * string|object + * + * ========================================================== + */ + AurynConfig::SHARING => [ + /** + * Make sure the config is shared. + * Already shared in bootstrap.php or in ACM if it is active. + */ + Config::class, + + Attributes::class, + Tag::class, + View::class, + + \WP_Theme::class, + \WP_Query::class, + ], + + /** + * ========================================================== + * + * Autoload Aliases Class + * + * string + * + * ========================================================== + */ + AurynConfig::ALIASES => [ + + ConfigInterface::class => Config::class, + + AttributesInterface::class => Attributes::class, + TagInterface::class => Tag::class, + + FileInfoFactoryInterface::class => FileInfoFactory::class, + SearchFileStrategy::class => FilesHierarchyIterator::class, +// FinderInterface::class => Finder::class, + + ViewInterface::class => View::class, + ], + + /** + * ========================================================== + * + * Autoload Classes definitions + * + * @example : + * 'walker' => '\NameSpace\ClassName', + * ':walker' => new \NameSpace\ClassName(), + * '+walker' => function () { + * return new \NameSpace\ClassName(); + * }, + * + * ========================================================== + */ + AurynConfig::DEFINITIONS => [ + View::class => [ + '+finder' => new ExperimentalViewFileFinderFactory(), + ], + ], + + /** + * ========================================================== + * + * Autoload Parameters Definitions + * + * string + * + * ========================================================== + */ + AurynConfig::DEFINE_PARAM => [ + ], + + /** + * ======================================================================== + * + * Autoload Delegates + * @link https://github.com/rdlowrey/auryn#instantiation-delegates + * 'MyComplexClass' => $complexClassFactory, + * 'SomeClassWithDelegatedInstantiation' => 'MyFactory', + * 'SomeClassWithDelegatedInstantiation' => 'MyFactory::factoryMethod' + * + * string + * + * ======================================================================== + */ + AurynConfig::DELEGATIONS => [ + \WP_Theme::class => static function (): \WP_Theme { + + return \wp_get_theme(\get_template()); + }, + \WP_Query::class => static function (): \WP_Query { + + global $wp_query; + return $wp_query; + }, + ], + + /** + * ======================================================================== + * + * Autoload Prepares + * @link https://github.com/rdlowrey/auryn#prepares-and-setter-injection + * + * string + * + * ======================================================================== + */ + AurynConfig::PREPARATIONS => [ + ], + + /** + * ======================================================================== + * + * Lazyload Classes + * Loaded on admin and front-end + * + * Useful if you need to load lazily your classes, for example + * if you want classes are loaded only when are really needed. + * + * ======================================================================== + */ + AurynConfig::PROXY => [ + ], + + /** + * ======================================================================== + * + * Autoload Subscribers Classes + * Loaded on admin and front-end + * + * If you use key => value pair make sure to bind the key with an option name + * to activate or deactivate the service from an option panel. + * + * ======================================================================== + */ + SubscribersConfigExtension::SUBSCRIBERS => [ + + ExperimentalCustomizerOptionWithAndPositionSubscriber::class, + OembedWrapperSubscriber::class, + + CustomizerBodyTagAttributesSubscriber::class, + CustomizerAssetsSubscriber::class, + + ExperimentalHookComponentsDeprecationSubscriber::class, + ], ]; diff --git a/config/autoload/subscribers.global.php b/config/autoload/subscribers.global.php deleted file mode 100644 index 8ed9605a..00000000 --- a/config/autoload/subscribers.global.php +++ /dev/null @@ -1,9 +0,0 @@ - [ - ], -]; diff --git a/config/index.php b/config/cache/config-cache.php similarity index 100% rename from config/index.php rename to config/cache/config-cache.php diff --git a/config/dependencies.config.php b/config/dependencies.config.php index d9ebc9f6..b7108baf 100644 --- a/config/dependencies.config.php +++ b/config/dependencies.config.php @@ -1,16 +1,55 @@ execute(ExperimentalThemeFileFinderFactory::class) + ), + // ProvidersCacheInterface::CACHE_PATH => get_template_directory() . '/config/cache/config-cache.php', + fn(): array => [ + // ProvidersCacheInterface::CACHE_PATH => get_template_directory() . '/config/cache/config-cache.php', + ProvidersCacheInterface::ENABLE_CACHE => true, + ], + /** This must run after all */ + fn(): array => [ + ConfigProviderExtension::class => [ + /** This must run after all */ + ConfigThemeModsProvider::class, + ], + ], + ], + ); + + $collection->build(); -return static function ( FinderInterface $finder ): ConfigInterface { - return ConfigFactory::make()->merge( - ...(new PhpFileProvider( - '/config/autoload/{{,*.}global,{,*.}local}.php', - $finder - ))() - ); + return $collection->collection(); }; diff --git a/config/layout.php b/config/layout.php index d4a44578..d1c7453e 100644 --- a/config/layout.php +++ b/config/layout.php @@ -1,4 +1,5 @@ \__( 'Content Sidebar', 'italystrap' ), - // 'content_sidebar_sidebar' => \__( 'Content Sidebar Sidebar', 'italystrap' ), - // 'sidebar_content_sidebar' => \__( 'Sidebar Content Sidebar', 'italystrap' ), - // 'sidebar_sidebar_content' => \__( 'Sidebar Sidebar content', 'italystrap' ), - 'sidebar_content' => \__( 'Sidebar Content', 'italystrap' ), - 'full_width' => \__( 'Full width, no sidebar', 'italystrap' ), - ] + 'italystrap_layout_settings', + [ + 'content_sidebar' => \__('Content Sidebar', 'italystrap'), + // 'content_sidebar_sidebar' => \__( 'Content Sidebar Sidebar', 'italystrap' ), + // 'sidebar_content_sidebar' => \__( 'Sidebar Content Sidebar', 'italystrap' ), + // 'sidebar_sidebar_content' => \__( 'Sidebar Sidebar content', 'italystrap' ), + 'sidebar_content' => \__('Sidebar Content', 'italystrap'), + 'full_width' => \__('Full width, no sidebar', 'italystrap'), + ] ); return $layout; diff --git a/config/template-content.php b/config/template-content.php index 023f6645..c97aa3d7 100644 --- a/config/template-content.php +++ b/config/template-content.php @@ -1,4 +1,5 @@ \__( 'Hide breadcrumbs', 'italystrap' ), - 'hide_title' => \__( 'Hide title', 'italystrap' ), - 'hide_meta' => \__( 'Hide meta info', 'italystrap' ), - 'hide_thumb' => \__( 'Hide feautured image', 'italystrap' ), - 'hide_figcaption' => \__( 'Hide figure caption', 'italystrap' ), - 'hide_content' => \__( 'Hide the content', 'italystrap' ), - 'hide_author' => \__( 'Hide author box', 'italystrap' ), - // 'hide_social' => \__( 'Hide builtin social sharing', 'italystrap' ), + 'hide_breadcrumbs' => \__('Hide breadcrumbs', 'italystrap'), + 'hide_title' => \__('Hide title', 'italystrap'), + 'hide_meta' => \__('Hide meta info', 'italystrap'), + 'hide_thumb' => \__('Hide feautured image', 'italystrap'), + 'hide_figcaption' => \__('Hide figure caption', 'italystrap'), + 'hide_content' => \__('Hide the content', 'italystrap'), + 'hide_author' => \__('Hide author box', 'italystrap'), + // 'hide_social' => \__( 'Hide builtin social sharing', 'italystrap' ), ]; -if ( ! \is_customize_preview() ) { - $template_content['hide_comments'] = __( 'Hide comments', 'italystrap' ); - $template_content['hide_comments_form'] = __( 'Hide comments form', 'italystrap' ); +if (! \is_customize_preview()) { + $template_content['hide_comments'] = __('Hide comments', 'italystrap'); + $template_content['hide_comments_form'] = __('Hide comments form', 'italystrap'); } -return \apply_filters( 'italystrap_template_content_settings', $template_content ); +return \apply_filters('italystrap_template_content_settings', $template_content); diff --git a/functions/asset-helpers.php b/functions/asset-helpers.php index b8156c2e..603bee42 100644 --- a/functions/asset-helpers.php +++ b/functions/asset-helpers.php @@ -1,4 +1,5 @@ $files */ - $files = config_files_finder()->allFiles( $name ); - $last_key = \array_key_last( $files ); +function get_config_file_content_last(string $name): array +{ - $config_file_content = require $files[ $last_key ]; + /** @var array $files */ + $files = (new ExperimentalConfigFilesFinderFactory())()->allFiles($name); + $last_key = \array_key_last($files); - /** - * removes all NULL, FALSE and Empty Strings but leaves 0 (zero) values - * https://php.net/manual/en/function.array-filter.php#111091 - */ - return array_filter( $config_file_content, fn( $val ) => ! is_null( $val ) ); -} + $config_file_content = require $files[ $last_key ]; -/** - * This function return a Finder object - * with config dirs with this order: - * 0 => Parent - * 1 => Child - * @return FinderInterface - */ -function config_files_finder(): FinderInterface { - - static $experimental_finder = null; - - if ( ! $experimental_finder ) { - $experimental_finder = ( new FinderFactory() ) - ->make() - ->in( - [ - /** - * To remember: - * This is the correct hierarchy to load and override - * the parent with child config. - */ - get_template_directory() . '/config/', - get_stylesheet_directory() . '/config/', - ] - ); - } - - return $experimental_finder; + /** + * removes all NULL, FALSE and Empty Strings but leaves 0 (zero) values + * https://php.net/manual/en/function.array-filter.php#111091 + */ + return array_filter($config_file_content, fn($val) => ! is_null($val)); } diff --git a/functions/core-booleans.php b/functions/core-booleans.php index 43bee822..ac42cc9a 100644 --- a/functions/core-booleans.php +++ b/functions/core-booleans.php @@ -1,18 +1,20 @@ alias( AurynInjector::class, EmpressInjector::class ); - $injector->share( $injector ); - add_filter( 'italystrap_injector', function () use ( $injector ) { - return $injector; - } ); - } - - if ( !is_debug() ) { - return $injector; - } - - if ( !($injector instanceof AurynInjector) ) { - $injector = new DebugInjector( $injector ); - $injector->alias( AurynInjector::class, DebugInjector::class ); - $injector->share( $injector ); - add_filter( 'italystrap_injector', function () use ( $injector ) { - return $injector; - } ); - } - - return $injector; - } +if (!function_exists('\ItalyStrap\Factory\injector')) { + + /** + * @return AurynInjector + * @throws ConfigException + */ + function injector(): AurynInjector + { + + /** + * Injector from ACM if is active + */ + $injector = apply_filters('italystrap_injector', false); + + if (!$injector) { + $injector = new EmpressInjector(); + $injector->alias(AurynInjector::class, EmpressInjector::class); + $injector->share($injector); + add_filter('italystrap_injector', function () use ($injector) { + return $injector; + }); + } + + if (!is_debug()) { + return $injector; + } + + if (!($injector instanceof AurynInjector)) { + $injector = new DebugInjector($injector); + $injector->alias(AurynInjector::class, DebugInjector::class); + $injector->share($injector); + add_filter('italystrap_injector', function () use ($injector) { + return $injector; + }); + } + + return $injector; + } } diff --git a/functions/italystrap.php b/functions/italystrap.php index 3f1ddb91..98c2d547 100644 --- a/functions/italystrap.php +++ b/functions/italystrap.php @@ -1,18 +1,28 @@ make(EventDispatcherInterface::class) + ->dispatch(new Index()); - /** - * @TODO Are they good hooks? - */ - do_action( 'italystrap_build', $args ); - do_action( 'italystrap', $args ); + /** + * @TODO Are they good hooks? + */ +// do_action('italystrap_build', $args); +// do_action('italystrap', $args); } diff --git a/lib/bootstrap.php b/lib/bootstrap.php index 5ade222e..5b2bc71a 100644 --- a/lib/bootstrap.php +++ b/lib/bootstrap.php @@ -1,4 +1,5 @@ require_once dirname( __FILE__ ) . \'/../src/bootstrap.php\'' ); - -require_once dirname( __FILE__ ) . '/../src/bootstrap.php'; +_deprecated_file( + '/lib/bootstrap.php', + '4.0.0', + '/src/bootstrap.php', + 'require_once dirname( __FILE__ ) . \'/../src/bootstrap.php\'' +); +require_once dirname(__FILE__) . '/../src/bootstrap.php'; diff --git a/lib/index.php b/lib/index.php index daea36f5..40d30d24 100644 --- a/lib/index.php +++ b/lib/index.php @@ -1,4 +1,5 @@ +
+ + + + + +
+ +
+ +
+ + + +
+ + + +
+ + + +
+ + + + + +
+ + +
+ + + + + + + + + + + + + + +
+ \ No newline at end of file diff --git a/parts/footer.html b/parts/footer.html new file mode 100644 index 00000000..e69de29b diff --git a/parts/header.html b/parts/header.html new file mode 100644 index 00000000..e69de29b diff --git a/patterns/colophon.php b/patterns/colophon.php new file mode 100644 index 00000000..e217ce00 --- /dev/null +++ b/patterns/colophon.php @@ -0,0 +1,27 @@ +make(ViewInterface::class); +$config = $injector->make(ConfigInterface::class); + +echo $view->render(Colophon::TEMPLATE_NAME, [ + Colophon::CONTENT => \wp_strip_all_tags((string)$config->get(ConfigColophonProvider::COLOPHON, '')), +]); diff --git a/patterns/footer-default.php b/patterns/footer-default.php new file mode 100644 index 00000000..82421319 --- /dev/null +++ b/patterns/footer-default.php @@ -0,0 +1,30 @@ +make(\Psr\EventDispatcher\EventDispatcherInterface::class); +?> +dispatch(new Before()); ?> + + + + + +dispatch(new After()); ?> diff --git a/phpcs.xml b/phpcs.xml index 58a043b3..b4c01a9e 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -1,7 +1,7 @@ - A custom set of rules to check for a WPized WordPress project + A custom set of rules to check for this project @@ -10,38 +10,22 @@ - + + + ./config/ + ./functions/ + ./lib/ + ./patterns/ + ./src/ + ./templates/ + ./tests/ - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - + */vendor/* + */tests/_support/* diff --git a/phpstan.neon.dist b/phpstan.neon.dist deleted file mode 100644 index 1b742ad5..00000000 --- a/phpstan.neon.dist +++ /dev/null @@ -1,43 +0,0 @@ -#$ composer update --optimize-autoloader -#$ vendor/bin/phpstan analyze - -includes: - # @see https://github.com/phpstan/phpstan/blob/master/conf/bleedingEdge.neon - - vendor/phpstan/phpstan/conf/bleedingEdge.neon - - vendor/szepeviktor/phpstan-wordpress/extension.neon -parameters: - level: max - inferPrivatePropertyTypeFromConstructor: true - reportUnmatchedIgnoredErrors: false - paths: - - %currentWorkingDirectory%/src/ - - %currentWorkingDirectory%/config/ - excludes_analyse: - - %currentWorkingDirectory%/src/Admin/ - - %currentWorkingDirectory%/src/Asset/ - - %currentWorkingDirectory%/src/Components/ - - %currentWorkingDirectory%/src/Css/ - - %currentWorkingDirectory%/src/Custom/ - - %currentWorkingDirectory%/src/Customizer/ - - %currentWorkingDirectory%/src/Navbar/ - - %currentWorkingDirectory%/src/User/ - - %currentWorkingDirectory%/config/theme/scripts.php - - %currentWorkingDirectory%/config/theme/styles.php - - %currentWorkingDirectory%/config/customizer.php - - %currentWorkingDirectory%/config/html_attrs.php - - %currentWorkingDirectory%/config/structure.php - autoload_files: - # Procedural code - - %currentWorkingDirectory%/functions/autoload.php - ignoreErrors: - # Uses func_get_args() - - '#^Function apply_filters invoked with [34567] parameters, 2 required\.$#' - - '#Access to an undefined property ItalyStrap\\Config\\Config::\$[a-zA-Z0-9_]+#' - - '#Access to an undefined property ItalyStrap\\Config\\ConfigInterface::\$[a-zA-Z0-9_]+#' - - '#Class ItalyStrap\\Migrations\\Old_Hooks not found#' - - '#Argument of an invalid type ItalyStrap\\Config\\[a-zA-Z_]+ supplied for foreach, only iterables are supported.#' - - '#Function new_cmb2_box not found#' - - '#Constant CURRENT_TEMPLATE_SLUG not found#' - - '#Constant STYLESHEETPATH not found#' - - '#Constant TEMPLATEPATH not found#' - - '#Constant ITALYSTRAP_THEME_VERSION not found.#' diff --git a/psalm.xml b/psalm.xml index 95b79516..7583d94c 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,6 +1,6 @@ - + + - + + diff --git a/src/Admin/Nav_Menu/ItemCustomFields.php b/src/Admin/Nav_Menu/ItemCustomFields.php deleted file mode 100644 index b0d92b03..00000000 --- a/src/Admin/Nav_Menu/ItemCustomFields.php +++ /dev/null @@ -1,321 +0,0 @@ - - * - * @forked from ItalyStrap - * @package ItalyStrap - * @since 4.0.0 - * @uses Walker_Nav_Menu_Edit - * @deprecated - */ -final class ItemCustomFields implements SubscriberInterface { - - /** - * Holds our custom fields - * - */ - private array $fields = []; - - private string $key_pattern; - - /** - * Init the constructor - */ - public function __construct() { - $this->key_pattern = 'menu-item-%s'; - $this->setFields( - [ - [ - 'type' => 'text', - 'id' => 'glyphicon', - 'name' => 'glyphicon', - 'label' => __( 'Icon css class', 'italystrap' ), - 'desc' => __( 'Example: fa fa-icon fa-3x', 'italystrap' ), - ], - ] - ); - } - - /** - * Print field - * - * @param int $id Nav menu ID. - * @param object $item Menu item data object. - */ - public function printFields( $id, $item ) { - - foreach ($this->getFields() as $field) : - $field = array_merge( $this->defaultField(), $field ); - $key = sprintf( $this->key_pattern, $field[ 'id' ] ); - $id = sprintf( 'edit-%s-%s', $key, $item->ID ); - $name = sprintf( '%s[%s]', $key, $item->ID ); - $value = (string)get_post_meta( $item->ID, $key, true ); - $class = sprintf( 'field-%s', $field[ 'id' ] ); - ?> -

- $field[ 'type' ], - 'id' => '%1$s', - 'class' => 'widefat %1$s', - 'name' => '%3$s', - 'value' => '%4$s', - ] - ); - - printf( - '', - esc_attr( $id ), - esc_html( $field[ 'label' ] ), - esc_attr( $name ), - esc_attr( $value ) - ) ?> -
- -

- getFields() as $field) { - $var = $field[ 'id' ]; - $menu_item->$var = get_post_meta( $menu_item->ID, sprintf( $this->key_pattern, $var ), true ); - } - - return $menu_item; - } - - /** - * Save custom field value - * - * @wp_hook action wp_update_nav_menu_item - * - * @param int $menu_id Nav menu ID - * @param int $menu_item_db_id Menu item ID - * @param array $menu_item_args Menu item data - */ - public function saveFields( int $menu_id, int $menu_item_db_id, array $menu_item_args ) { - - if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { - return; - } - - check_admin_referer( 'update-nav_menu', 'update-nav-menu-nonce' ); - - foreach ($this->getFields() as $field) { - $key = sprintf( $this->key_pattern, $field[ 'id' ] ); - - if ( empty( $_POST[ $key ][ $menu_item_db_id ] ) ) { - delete_post_meta( $menu_item_db_id, $key ); - continue; - } - - update_post_meta( $menu_item_db_id, $key, sanitize_text_field( $_POST[ $key ][ $menu_item_db_id ] ) ); - } - } - - /** - * Define new Walker edit - * - * @param string $class The walker class to use. - * Default 'Walker_Nav_Menu_Edit'. - * @param int $menu_id The menu id, derived from $_POST['menu']. - * - * @return string The new walker class to use. - */ - public function register() { - return NavMenuEdit::class; - } - - /** - * Add our fields to the screen options toggle - * - * @param array $columns Menu item columns - * - * @return array - */ - public function columns( $columns ): array { - return array_merge( $columns, iterator_to_array( $this->getColumns() ) ); - } - - /** - * @return Generator - */ - private function getColumns() { - foreach ($this->getFields() as $field) { - yield $field[ 'id' ] => $field[ 'label' ]; - } - } - - /** - * @return array - */ - private function getFields(): array { - return $this->fields; - } - - /** - * @param array $fields - */ - private function setFields( array $fields ) { - $this->fields = $fields; - } - - /** - * @return array - */ - private function defaultField(): array { - - $uniqid = uniqid(); - - return [ - 'type' => 'text', - 'id' => $uniqid, - 'name' => $uniqid, - 'label' => __( 'Label not provided', 'italystrap' ), - 'desc' => '', - ]; - } - - /** - * Returns an array of events (hooks) that this subscriber wants to register with - * the Events Manager API. - * - * The array key is the name of the hook. The value can be: - * - * * The method name - * * An array with the method name and priority - * * An array with the method name, priority and number of accepted arguments - * - * For instance: - * - * array( - * // 'event_name' => 'method_name', - * 'italystrap_before_header' => 'render', - * ) - * array( - * // 'event_name' => 'method_name', - * 'italystrap_before_entry_content' => array( - * 'function_to_add' => 'render', - * 'priority' => 30, // Default 10 - * 'accepted_args' => 1 // Default 1 - * ), - * ); - * - * @return array - */ - public function getSubscribedEvents(): iterable { - - /** - * Add new checkboxes to the "Screen options" menu - */ - yield 'manage_nav-menus_columns' => [ - SubscriberInterface::CALLBACK => 'columns', - SubscriberInterface::PRIORITY => 11, - ]; - - /** - * Add the value fro new custom fields to the object in the Nav Walker - */ - yield 'wp_setup_nav_menu_item' => 'addCustomNavFields'; - - /** - * Save the value - */ - yield 'wp_update_nav_menu_item' => [ - SubscriberInterface::CALLBACK => 'saveFields', - SubscriberInterface::PRIORITY => 10, - SubscriberInterface::ACCEPTED_ARGS => 3, - ]; - - /** - * Display the added custom fields - */ - yield 'wp_nav_menu_item_custom_fields' => [ - SubscriberInterface::CALLBACK => 'printFields', - SubscriberInterface::PRIORITY => 10, - SubscriberInterface::ACCEPTED_ARGS => 5, - ]; - -// return [ - - /** - * Register new class for Menu Edit - */ -// 'wp_edit_nav_menu_walker' => [ -// SubscriberInterface::CALLBACK => 'register', -// 'accepted_args' => 2, -// ], - - /** - * Add new checkboxes to the "Screen options" menu - */ -// 'manage_nav-menus_columns' => [ -// SubscriberInterface::CALLBACK => 'columns', -// SubscriberInterface::PRIORITY => 11, -// ], - - /** - * Add the value fro new custom fields to the object in the Nav Walker - */ -// 'wp_setup_nav_menu_item' => 'addCustomNavFields', - - /** - * Save the value - */ -// 'wp_update_nav_menu_item' => [ -// SubscriberInterface::CALLBACK => 'saveFields', -// SubscriberInterface::PRIORITY => 10, -// SubscriberInterface::ACCEPTED_ARGS => 3, -// ], - - /** - * Display the added custom fields - */ -// 'wp_nav_menu_item_custom_fields' => [ -// SubscriberInterface::CALLBACK => 'printFields', -// SubscriberInterface::PRIORITY => 10, -// SubscriberInterface::ACCEPTED_ARGS => 5, -// ], -// ]; - } -} diff --git a/src/Asset/Application/EditorSubscriber.php b/src/Asset/Application/EditorSubscriber.php new file mode 100644 index 00000000..c41188d0 --- /dev/null +++ b/src/Asset/Application/EditorSubscriber.php @@ -0,0 +1,75 @@ + $this; + } + + public function __construct(ConfigInterface $config, FinderInterface $finder, GlobalDispatcherInterface $dispatcher) + { + $this->config = $config; + $this->finder = $finder; + $this->globalDispatcher = $dispatcher; + } + + /** + * Add Custom CSS in visual editor + * + * @link http://codex.wordpress.org/Function_Reference/add_editor_style + * @link https://developer.wordpress.org/reference/functions/add_editor_style/ + + * Leggere qui perché forse c'è un problema con i font, non prende il path giusto + * @link http://codeboxr.com/blogs/adding-twitter-bootstrap-support-in-wordpress-visual-editor + * @link https://www.google.it/search?q=wordpress+add+css+bootstrap+visual+editor&oq=wordpress+add+css+bootstrap+visual+editor&gs_l=serp.3...893578.895997.0.896668.10.10.0.0.0.3.388.1849.0j1j4j2.7.0....0...1c.1.52.serp..8.2.732.wb3nJL89Fxk + */ + public function __invoke(): void + { + + /** @var SplFileInfo $editor_style */ + $editor_style = ''; + foreach ($this->finder as $file) { + $editor_style = $file; + break; + } + + /** + * @TODO In fase di test bisogna verificare sia il path to url per il child + * che per il parent theme, qui per esempio prendo tutto dal child + * e dovrebbe fare la fallback sul parent in caso il child non + * sia installato + * http:://italystrap.test\dir/dir\dir + */ + $style_url = str_replace( + (string) realpath((string) $this->config->get(ConfigThemeProvider::STYLESHEET_DIR)), + (string) $this->config->get(ConfigThemeProvider::STYLESHEET_DIR_URI), // Replace + $editor_style->getRealPath() + ); + + $style_url = str_replace('\\', '/', $style_url); + + $arg = (array)$this->globalDispatcher->filter('italystrap_visual_editor_style', [ $style_url ]); + + add_editor_style($arg); + } +} diff --git a/src/Asset/Application/InlineStyleSubscriber.php b/src/Asset/Application/InlineStyleSubscriber.php new file mode 100644 index 00000000..72cac82f --- /dev/null +++ b/src/Asset/Application/InlineStyleSubscriber.php @@ -0,0 +1,79 @@ + [ + self::CALLBACK => $this, + self::PRIORITY => 11, + ]; + } + + public function __construct(ConfigInterface $config, InlineStyleGenerator $style) + { + $this->style = $style; + $this->config = $config; + } + + public function __invoke(): void + { + $output = $this->style->render( + '#site-title a', + 'color', + ConfigColorSectionProvider::HEADER_COLOR, + '#' + ); + + $output .= $this->style->render( + 'h1,h2,h3,h4,h5,h6,.h1,.h2,.h3,.h4,.h5,.h6,.heading', + 'color', + ConfigColorSectionProvider::HX_COLOR, + '#' + ); + + $output .= $this->style->render( + 'a', + 'color', + ConfigColorSectionProvider::LINK_COLOR, + '#' + ); + + if (! $output) { + return; + } + + \printf( + '', + (string) $this->config->get(ConfigThemeProvider::PREFIX), + \wp_strip_all_tags($this->minifyOutput($output)) + ); + } + + private function minifyOutput(string $style): string + { + return \str_replace( + [ + "\n", + "\r", + "\t", + ' ', + ], + '', + $style + ); + } +} diff --git a/src/Asset/EditorSubscriber.php b/src/Asset/EditorSubscriber.php deleted file mode 100644 index bdcff577..00000000 --- a/src/Asset/EditorSubscriber.php +++ /dev/null @@ -1,78 +0,0 @@ - 'enqueue'; - } - - /** - * Editor constructor. - * @param Config $config - * @param Finder $finder - */ - public function __construct( Config $config, Finder $finder, EventDispatcher $dispatcher ) { - $this->config = $config; - $this->finder = $finder; - $this->dispatcher = $dispatcher; - } - - /** - * Add Custom CSS in visual editor - * - * @link http://codex.wordpress.org/Function_Reference/add_editor_style - * @link https://developer.wordpress.org/reference/functions/add_editor_style/ - - * Leggere qui perché forse c'è un problema con i font, non prende il path giusto - * @link http://codeboxr.com/blogs/adding-twitter-bootstrap-support-in-wordpress-visual-editor - * @link https://www.google.it/search?q=wordpress+add+css+bootstrap+visual+editor&oq=wordpress+add+css+bootstrap+visual+editor&gs_l=serp.3...893578.895997.0.896668.10.10.0.0.0.3.388.1849.0j1j4j2.7.0....0...1c.1.52.serp..8.2.732.wb3nJL89Fxk - */ - public function enqueue(): void { - - /** @var SplFileInfo $editor_style */ - $editor_style = ''; - foreach ( $this->finder as $file ) { - $editor_style = $file; - break; - } - - /** - * @TODO In fase di test bisogna verificare sia il path to url per il child - * che per il parent theme, qui per esempio prendo tutto dal child - * e dovrebbe fare la fallback sul parent in caso il child non - * sia installato - * http:://italystrap.test\dir/dir\dir - */ - $style_url = str_replace( - (string) realpath( (string) $this->config->get( ConfigThemeProvider::STYLESHEET_DIR ) ), - (string) $this->config->get( ConfigThemeProvider::STYLESHEET_DIR_URI ), // Replace - $editor_style->getRealPath() - ); - - $style_url = str_replace('\\', '/', $style_url); - - $arg = (array)$this->dispatcher->filter( 'italystrap_visual_editor_style', [ $style_url ] ); - - add_editor_style( $arg ); - } -} diff --git a/src/Asset/ExperimentalAssetPreparator.php b/src/Asset/ExperimentalAssetPreparator.php deleted file mode 100644 index 1d261b15..00000000 --- a/src/Asset/ExperimentalAssetPreparator.php +++ /dev/null @@ -1,85 +0,0 @@ -make(EventDispatcher::class); - $experimental_assets_path_generator = static function ( string $dir ): array { - $sub_dir = ( defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ) ? 'src/' : ''; - - return \array_unique( - [ - STYLESHEETPATH . '/assets/' . $dir, - STYLESHEETPATH . '/' . $dir, // This is added for avoid BC breaks - STYLESHEETPATH . '/' . $dir . $sub_dir, // This is added for avoid BC breaks - TEMPLATEPATH . '/assets/' . $dir, - ] - ); - }; - - $css_finder = ( new FinderFactory() )->make() - ->in( $experimental_assets_path_generator('css/') ); - - $js_finder = ( new FinderFactory() )->make() - ->in( $experimental_assets_path_generator('js/') ); - - $injector->defineParam('base_url', \get_option( 'siteurl' ) . '/'); - /** - * @psalm-suppress UndefinedConstant - */ - $injector->defineParam('base_path', ABSPATH); - - /** @var ConfigBuilder $config_builder */ - $config_builder = $injector->make( ConfigBuilder::class ); - - $config_builder->withType( - Style::EXTENSION, - \ItalyStrap\Core\is_debug() ? DebugStyle::class : Style::class - ); - $config_builder->withFinderForType( Style::EXTENSION, $css_finder); - - $config_builder->withType( - Script::EXTENSION, - \ItalyStrap\Core\is_debug() ? DebugScript::class : Script::class - ); - $config_builder->withFinderForType( Script::EXTENSION, $js_finder); - - /** - * @todo Maybe I can add a check for forcing child to load its own assets - * is_child() ? [] : get_config_file_content_last( 'assets/[styles|scripts]' ) - * because assetss should not be loaded from parent by default. - * @var array - */ - $styles = $event_dispatcher->filter( - 'italystrap_config_enqueue_style', - get_config_file_content_last( 'assets/styles' ) - ); - - /** @var array $scripts */ - $scripts = $event_dispatcher->filter( - 'italystrap_config_enqueue_script', - get_config_file_content_last( 'assets/scripts' ) - ); - - $config_builder->addConfig( $styles ); - $config_builder->addConfig( $scripts ); - - $asset_loader = $injector->make( GeneratorLoader::class ); - $assets = $asset_loader->load( $config_builder->parseConfig() ); - - $manager->withAssets(...$assets); - } -} diff --git a/src/Asset/Infrastructure/ExperimentalAssetPreparator.php b/src/Asset/Infrastructure/ExperimentalAssetPreparator.php new file mode 100644 index 00000000..e8732147 --- /dev/null +++ b/src/Asset/Infrastructure/ExperimentalAssetPreparator.php @@ -0,0 +1,92 @@ +make(EventDispatcher::class); + $experimental_assets_path_generator = static function (string $dir): array { + $sub_dir = ( defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ) ? 'src/' : ''; + + return \array_unique( + [ + STYLESHEETPATH . '/assets/' . $dir, + STYLESHEETPATH . '/' . $dir, // This is added for avoid BC breaks + STYLESHEETPATH . '/' . $dir . $sub_dir, // This is added for avoid BC breaks + TEMPLATEPATH . '/assets/' . $dir, + ] + ); + }; + + $css_finder = ( new FinderFactory() )->make() + ->in($experimental_assets_path_generator('css/')); + + $js_finder = ( new FinderFactory() )->make() + ->in($experimental_assets_path_generator('js/')); + + $injector->defineParam('base_url', \get_option('siteurl') . '/'); + /** + * @psalm-suppress UndefinedConstant + */ + $injector->defineParam('base_path', ABSPATH); + + /** @var ConfigBuilder $config_builder */ + $config_builder = $injector->make(ConfigBuilder::class); + + $config_builder->withType( + Style::EXTENSION, + \ItalyStrap\Core\is_debug() ? DebugStyle::class : Style::class + ); + $config_builder->withFinderForType(Style::EXTENSION, $css_finder); + + $config_builder->withType( + Script::EXTENSION, + \ItalyStrap\Core\is_debug() ? DebugScript::class : Script::class + ); + $config_builder->withFinderForType(Script::EXTENSION, $js_finder); + + /** + * @todo Maybe I can add a check for forcing child to load its own assets + * is_child() ? [] : get_config_file_content_last( 'assets/[styles|scripts]' ) + * because assetss should not be loaded from parent by default. + * @var array + */ + $styles = $event_dispatcher->filter( + 'italystrap_config_enqueue_style', + get_config_file_content_last('assets/styles') + ); + + /** @var array $scripts */ + $scripts = $event_dispatcher->filter( + 'italystrap_config_enqueue_script', + get_config_file_content_last('assets/scripts') + ); + + $config_builder->addConfig($styles); + $config_builder->addConfig($scripts); + + $asset_loader = $injector->make(GeneratorLoader::class); + $assets = $asset_loader->load($config_builder->parseConfig()); + + $manager->withAssets(...$assets); + } +} diff --git a/src/Asset/Infrastructure/InlineStyleGenerator.php b/src/Asset/Infrastructure/InlineStyleGenerator.php new file mode 100644 index 00000000..2fd32f79 --- /dev/null +++ b/src/Asset/Infrastructure/InlineStyleGenerator.php @@ -0,0 +1,55 @@ +config = $config; + } + + /** + * This will generate a line of CSS for use in header or footer output. + * If the setting ($mod_name) has no defined value, the CSS will not be output. + * + * @param string $selector CSS selector. + * @param string $property The name of the CSS *property* to modify. + * @param string $mod_name The name of the 'theme_mod' option to fetch. + * @param string $prefix Optional. Anything that needs to be output + * before the CSS property. Example '#'. + * @param string $postfix Optional. Anything that needs to be output + * after the CSS property. Example 'px'. + * @return string Returns a single line of CSS with selectors, + * property and value. + */ + public function render( + string $selector, + string $property, + string $mod_name, + string $prefix, + string $postfix = '' + ): string { + + $value = (string) $this->config->get($mod_name); + + if (empty($value)) { + return ''; + } + + return \sprintf( + '%1$s{%2$s:%3$s%4$s%5$s;}', + $selector, + $property, + $prefix, + $value, + $postfix + ); + } +} diff --git a/src/Asset/InlineStyleGenerator.php b/src/Asset/InlineStyleGenerator.php deleted file mode 100644 index 4e91c6c8..00000000 --- a/src/Asset/InlineStyleGenerator.php +++ /dev/null @@ -1,56 +0,0 @@ -config = $config; - } - - /** - * This will generate a line of CSS for use in header or footer output. - * If the setting ($mod_name) has no defined value, the CSS will not be output. - * - * @param string $selector CSS selector. - * @param string $property The name of the CSS *property* to modify. - * @param string $mod_name The name of the 'theme_mod' option to fetch. - * @param string $prefix Optional. Anything that needs to be output - * before the CSS property. Example '#'. - * @param string $postfix Optional. Anything that needs to be output - * after the CSS property. Example 'px'. - * @return string Returns a single line of CSS with selectors, - * property and value. - */ - public function render( - string $selector, - string $property, - string $mod_name, - string $prefix, - string $postfix = '' - ): string { - - $value = (string) $this->config->get( $mod_name ); - - if ( empty( $value ) ) { - return ''; - } - - return \sprintf( - '%1$s{%2$s:%3$s%4$s%5$s;}', - $selector, - $property, - $prefix, - $value, - $postfix - ); - } -} diff --git a/src/Asset/InlineStyleSubscriber.php b/src/Asset/InlineStyleSubscriber.php deleted file mode 100644 index 9dbee4b1..00000000 --- a/src/Asset/InlineStyleSubscriber.php +++ /dev/null @@ -1,76 +0,0 @@ - [ - self::CALLBACK => 'enqueue', - self::PRIORITY => 11, - ]; - } - - public function __construct( ConfigInterface $config, InlineStyleGenerator $style ) { - $this->style = $style; - $this->config = $config; - } - - public function enqueue(): void { - $output = $this->style->render( - '#site-title a', - 'color', - ConfigColorSectionProvider::HEADER_COLOR, - '#' - ); - - $output .= $this->style->render( - 'h1,h2,h3,h4,h5,h6,.h1,.h2,.h3,.h4,.h5,.h6,.heading', - 'color', - ConfigColorSectionProvider::HX_COLOR, - '#' - ); - - $output .= $this->style->render( - 'a', - 'color', - ConfigColorSectionProvider::LINK_COLOR, - '#' - ); - - if ( ! $output ) { - return; - } - - \printf( - '', - (string) $this->config->get(ConfigThemeProvider::PREFIX), - \wp_strip_all_tags( $this->minifyOutput( $output ) ) - ); - } - - private function minifyOutput( string $style ): string { - return \str_replace( - [ - "\n", - "\r", - "\t", - ' ', - ], - '', - $style - ); - } -} diff --git a/src/Asset/JsonData.php b/src/Asset/JsonData.php deleted file mode 100644 index ccaf193c..00000000 --- a/src/Asset/JsonData.php +++ /dev/null @@ -1,259 +0,0 @@ -buildJsonData(); - -// $result = $data->parseDataAndCleanFromEmptyValue( $result ); - - if ( \count( $result ) === 0 ) { - throw new \RuntimeException('The theme.json is empty'); - } - - return $result; - } - - private function buildJsonData(): array { - - $font_family = new Preset( - [ - [ - // phpcs:ignore - 'fontFamily' => 'system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"', - 'slug' => "base", - "name" => "Default font family", - ], - [ - // phpcs:ignore - 'fontFamily' => 'SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace', - 'slug' => "monospace", - "name" => "Font family for code", - ], - ], - 'fontFamily' - ); - - $custom = new Custom( - [ - 'contentSize' => 'clamp(16rem, 60vw, 60rem)', - 'wideSize' => 'clamp(16rem, 85vw, 70rem)', - 'baseFontSize' => "1rem", - 'spacer' => [ - 'base' => '1rem', - 'v' => 'calc( {{spacer.base}} * 4 )', - 'h' => 'calc( {{spacer.base}} * 4 )', - 's' => 'calc( {{spacer.base}} / 1.5 )', - 'm' => 'calc( {{spacer.base}} * 2 )', - 'l' => 'calc( {{spacer.base}} * 3 )', - 'xl' => 'calc( {{spacer.base}} * 4 )', - ], - 'lineHeight' => [ - 'base' => 1.5, - 'xs' => 1.1, - 's' => 1.3, - 'm' => '{{lineHeight.base}}', - 'l' => 1.7 - ], - 'body' => [ - 'bg' => '{{color.base}}', - 'text' => '{{color.bodyBg}}', - ], - 'link' => [ - 'bg' => '{{color.base}}', - 'text' => '{{color.bodyBg}}', - 'decoration' => 'underline', - 'hover' => [ - 'text' => '{{color.bodyColor}}', - 'decoration' => 'underline', - ], - ], - 'button' => [ - 'bg' => '{{color.base}}', - // 'text' => $button_text_hover->toHex(), - 'borderColor' => 'transparent', - 'borderRadius' => 'calc( {{fontSize.base}} /4)', - 'hover' => [ - // 'bg' => $button_bg_hover->toHex(), - // 'text' => $button_text_hover->toHex(), - 'borderColor' => 'transparent', - ], - 'padding' => ' 0.25em 0.7em', - ], - 'form' => [ - 'border' => [ - 'color' => '', - 'width' => '', - ], - 'input' => [ - 'color' => '', - ], - ], - 'navbar' => [ - 'min' => [ - 'height' => 'calc( {{spacer.base}} * 5.3125 )', - ], - ], - 'query' => [ - 'post' => [ - 'title' => '{{fontSize.h1}}', - ], - ], - // 'site-blocks' => [ - // 'margin' => [ - // 'top' => '', - // ], - // ], - ] - ); - - return [ - '$schema' => 'https://schemas.wp.org/trunk/theme.json', - SectionNames::VERSION => 2, - - SectionNames::SETTINGS => [ - 'layout' => [ - 'contentSize' => 'clamp(16rem, 60vw, 60rem)', - 'wideSize' => 'clamp(16rem, 85vw, 70rem)', - ], - ], - - /** - * ============================================ - * Styles for FSE and Front-End - * ============================================ - */ - SectionNames::STYLES => [ - - 'typography' => FTypo::make() - ->fontFamily( $font_family->varOf('base') ) -// ->fontSize( $font_sizes->varOf( 'base' ) ) - ->fontSize( '18px' ) - ->fontStyle( 'normal' ) - ->fontWeight( '300' ) - ->letterSpacing( 'normal' ) - ->lineHeight( $custom->varOf( 'lineHeight.m' ) ) - ->textDecoration( 'none' ) - ->textTransform( 'none' ) - ->toArray(), - - /** - * ============================================ - * Blocks styles - * ============================================ - */ - 'blocks' => [ - - /** - * ============================================ - * Blocks elements for images - * ============================================ - */ - 'core/site-logo' => [ // wp-block-site-logo {figure element} - 'spacing' => [ - 'margin' => (string) FSpace::shorthand(['0']), - 'padding' => (string) FSpace::shorthand(['0']), - ], - ], - 'core/image' => [ // wp-block-image {figure element} - 'spacing' => [ - 'margin' => (string) FSpace::make() - ->top( '1rem' ) - ->bottom( '0px' ), - ], - ], - 'core/post-featured-image' => [ // wp-block-post-featured-image {figure element} -// 'spacing' => [ -// 'margin' => (string) FSpace::make() -// ->top( '1rem' ) -// ->bottom('0'), -// ], - ], -// 'core/gallery' => [ // wp-block-gallery {figure element} -// ], - - 'core/post-title' => [ // .wp-block-post-title - 'color' => FClr::make() - ->text( 'inherit' ) - ->toArray(), -// 'border' => (new Border()) -// ->style('solid') -// ->width('1px') -// ->color('black') -// ->toArray(), - 'typography' => FTypo::make() - ->fontSize( '35px' ) - ->toArray(), - 'elements' => [ - 'link' => [ // .wp-block-post-title a - 'color' => FClr::make() - ->text( 'inherit' ) - ->background( 'transparent' ) - ->toArray(), - ], - ], - ], - - 'core/post-date' => [ - 'typography' => FTypo::make() -// ->fontSize( '0.75rem' ) - ->toArray(), - ], - 'core/post-author' => [ - 'typography' => FTypo::make() -// ->fontSize( '16px' ) - ->toArray(), - ], - 'core/post-terms' => [ - 'typography' => FTypo::make() -// ->fontSize( '0.75rem' ) - ->toArray(), - ], - - /** - * ============================================ - * Blocks for content - * ============================================ - */ - 'core/post-content' => [ // .wp-block-post-content - 'color' => FClr::make() - ->text( 'inherit' ) - ->toArray(), - ], - 'core/post-excerpt' => [ // .wp-block-post-content - 'color' => FClr::make() - ->text( 'inherit' ) - ->toArray(), - ], - 'core/paragraph' => [ // .wp-block-post-content - 'color' => FClr::make() - ->text( 'inherit' ) - ->toArray(), - 'spacing' => [ - 'margin' => (string) FSpace::make() - ->top( '1.2rem' ) - ->bottom( '0px' ), - ], - ], - - ], - ], - ]; - } -} diff --git a/src/Asset/Module.php b/src/Asset/Module.php new file mode 100644 index 00000000..26cdfa1e --- /dev/null +++ b/src/Asset/Module.php @@ -0,0 +1,66 @@ + [ + + ], + AurynConfig::ALIASES => [ + + ], + AurynConfig::DEFINITIONS => [ + EditorSubscriber::class => [ + '+finder' => static function (string $named_param, Injector $injector): FinderInterface { + + $config = $injector->make(ConfigInterface::class); + $stylesheet_dir = (string)$config->get(ConfigThemeProvider::STYLESHEET_DIR); + $template_dir = (string)$config->get(ConfigThemeProvider::TEMPLATE_DIR); + $finder = (new FinderFactory())->make() + ->in([ + $stylesheet_dir . '/assets/', + $template_dir . '/assets/', + ]); + $finder->names([ + '../css/editor-style.css', + '../assets/css/editor-style.css', + ]); + return $finder; + }, + ], + ], + AurynConfig::PREPARATIONS => [ + + /** + * This class is lazy loaded + */ + AssetManager::class => new ExperimentalAssetPreparator(), + ], + AurynConfig::PROXY => [ + AssetManager::class, + ], + SubscribersConfigExtension::SUBSCRIBERS => [ + InlineStyleSubscriber::class, + AssetsSubscriber::class, + EditorSubscriber::class, + ] + ]; + } +} diff --git a/src/Asset/ThemeJson.php b/src/Asset/ThemeJson.php new file mode 100644 index 00000000..7eac7684 --- /dev/null +++ b/src/Asset/ThemeJson.php @@ -0,0 +1,280 @@ +buildJsonData(); + +// $result = $data->parseDataAndCleanFromEmptyValue( $result ); + + if (\count($result) === 0) { + throw new \RuntimeException('The theme.json is empty'); + } + + return $result; + } + + private function buildJsonData(): array + { + + $font_family = new Preset( + [ + [ + // phpcs:ignore + 'fontFamily' => 'system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"', + 'slug' => "base", + "name" => "Default font family", + ], + [ + // phpcs:ignore + 'fontFamily' => 'SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace', + 'slug' => "monospace", + "name" => "Font family for code", + ], + ], + 'fontFamily' + ); + + $custom = new Custom( + [ + 'contentSize' => 'clamp(16rem, 60vw, 60rem)', + 'wideSize' => 'clamp(16rem, 85vw, 70rem)', + 'baseFontSize' => "1rem", + 'spacer' => [ + 'base' => '1rem', + 'v' => 'calc( {{spacer.base}} * 4 )', + 'h' => 'calc( {{spacer.base}} * 4 )', + 's' => 'calc( {{spacer.base}} / 1.5 )', + 'm' => 'calc( {{spacer.base}} * 2 )', + 'l' => 'calc( {{spacer.base}} * 3 )', + 'xl' => 'calc( {{spacer.base}} * 4 )', + ], + 'lineHeight' => [ + 'base' => 1.5, + 'xs' => 1.1, + 's' => 1.3, + 'm' => '{{lineHeight.base}}', + 'l' => 1.7 + ], + 'body' => [ + 'bg' => '{{color.base}}', + 'text' => '{{color.bodyBg}}', + ], + 'link' => [ + 'bg' => '{{color.base}}', + 'text' => '{{color.bodyBg}}', + 'decoration' => 'underline', + 'hover' => [ + 'text' => '{{color.bodyColor}}', + 'decoration' => 'underline', + ], + ], + 'button' => [ + 'bg' => '{{color.base}}', + // 'text' => $button_text_hover->toHex(), + 'borderColor' => 'transparent', + 'borderRadius' => 'calc( {{fontSize.base}} /4)', + 'hover' => [ + // 'bg' => $button_bg_hover->toHex(), + // 'text' => $button_text_hover->toHex(), + 'borderColor' => 'transparent', + ], + 'padding' => ' 0.25em 0.7em', + ], + 'form' => [ + 'border' => [ + 'color' => '', + 'width' => '', + ], + 'input' => [ + 'color' => '', + ], + ], + 'navbar' => [ + 'min' => [ + 'height' => 'calc( {{spacer.base}} * 5.3125 )', + ], + ], + 'query' => [ + 'post' => [ + 'title' => '{{fontSize.h1}}', + ], + ], + // 'site-blocks' => [ + // 'margin' => [ + // 'top' => '', + // ], + // ], + ] + ); + + $custom->withCollection( + $font_family + ); + + return [ + '$schema' => 'https://schemas.wp.org/trunk/theme.json', + SectionNames::VERSION => 2, + + SectionNames::SETTINGS => [ + 'layout' => [ + 'contentSize' => 'clamp(16rem, 60vw, 60rem)', + 'wideSize' => 'clamp(16rem, 85vw, 70rem)', + ], +// 'custom' => $custom->toArray(), + ], + + /** + * ============================================ + * Styles for FSE and Front-End + * ============================================ + */ + SectionNames::STYLES => [ + + 'typography' => FTypo::make() + ->fontFamily($font_family->varOf('base')) +// ->fontSize( $font_sizes->varOf( 'base' ) ) + ->fontSize('18px') + ->fontStyle('normal') + ->fontWeight('300') + ->letterSpacing('normal') + ->lineHeight($custom->varOf('lineHeight.m')) + ->textDecoration('none') + ->textTransform('none') + ->toArray(), + + /** + * ============================================ + * Blocks styles + * ============================================ + */ + 'blocks' => [ + + /** + * ============================================ + * Blocks elements for images + * ============================================ + */ + 'core/site-logo' => [ // wp-block-site-logo {figure element} + 'spacing' => [ + 'margin' => (string) FSpace::shorthand(['0']), + 'padding' => (string) FSpace::shorthand(['0']), + ], + ], + 'core/image' => [ // wp-block-image {figure element} + 'spacing' => [ + 'margin' => (string) FSpace::make() + ->top('1rem') + ->bottom('0px'), + ], + ], + 'core/post-featured-image' => [ // wp-block-post-featured-image {figure element} +// 'spacing' => [ +// 'margin' => (string) FSpace::make() +// ->top( '1rem' ) +// ->bottom('0'), +// ], + ], +// 'core/gallery' => [ // wp-block-gallery {figure element} +// ], + + 'core/post-title' => [ // .wp-block-post-title + 'color' => FClr::make() + ->text('inherit') + ->toArray(), +// 'border' => (new Border()) +// ->style('solid') +// ->width('1px') +// ->color('black') +// ->toArray(), + 'typography' => FTypo::make() + ->fontSize('35px') + ->toArray(), + 'elements' => [ + 'link' => [ // .wp-block-post-title a + 'color' => FClr::make() + ->text('inherit') + ->background('transparent') + ->toArray(), + ], + ], + ], + + 'core/post-date' => [ + 'typography' => FTypo::make() +// ->fontSize( '0.75rem' ) + ->toArray(), + ], + 'core/post-author' => [ + 'typography' => FTypo::make() +// ->fontSize( '16px' ) + ->toArray(), + 'spacing' => [ + 'margin' => (string) FSpace::make() +// ->top($custom->varOf('spacer.base')) + ->top('2rem') + ->bottom('0px'), + ], + ], + 'core/post-terms' => [ + 'typography' => FTypo::make() +// ->fontSize( '0.75rem' ) + ->toArray(), + ], + + /** + * ============================================ + * Blocks for content + * ============================================ + */ + 'core/post-content' => [ // .wp-block-post-content + 'color' => FClr::make() + ->text('inherit') + ->toArray(), + ], + 'core/post-excerpt' => [ // .wp-block-post-content + 'color' => FClr::make() + ->text('inherit') + ->toArray(), + ], + 'core/paragraph' => [ // .wp-block-post-content + 'color' => FClr::make() + ->text('inherit') + ->toArray(), + 'spacing' => [ + 'margin' => (string) FSpace::make() + ->top('2rem') + ->bottom('0px'), + ], + ], + 'core/search' => [ + 'spacing' => [ + 'margin' => (string) FSpace::make() +// ->top($custom->varOf('spacer.base')) + ->top('2rem') + ->bottom('0px'), + ], + ], + ], + ], + ]; + } +} diff --git a/src/Asset/index.php b/src/Asset/index.php deleted file mode 100644 index a5bcf147..00000000 --- a/src/Asset/index.php +++ /dev/null @@ -1,4 +0,0 @@ -config = $config; - $this->info = $info; - } - - public function shouldDisplay(): bool { - return \is_author(); - } - - public function display(): void { - echo $this->info->render(null, []); - } -} diff --git a/src/Components/ArchiveHeadline.php b/src/Components/ArchiveHeadline.php deleted file mode 100644 index 733efe81..00000000 --- a/src/Components/ArchiveHeadline.php +++ /dev/null @@ -1,41 +0,0 @@ -config = $config; - $this->view = $view; - $this->dispatcher = $dispatcher; - } - - public function shouldDisplay(): bool { - return ( \is_archive() || \is_search() ) && ! \is_author(); - } - - public function display(): void { - echo \do_blocks( $this->view->render( 'misc/archive-headline', [ - EventDispatcherInterface::class => $this->dispatcher, - ] ) ); - } -} diff --git a/src/Components/AuthorInfo.php b/src/Components/AuthorInfo.php deleted file mode 100644 index 11ce11e4..00000000 --- a/src/Components/AuthorInfo.php +++ /dev/null @@ -1,19 +0,0 @@ -view = $view; - } - - public function render( $slugs, $data = [] ): string { - return \do_shortcode( \do_blocks( $this->view->render( $slugs ?? 'temp/author-info', $data ) ) ); - } -} diff --git a/src/Components/BlockQuery.php b/src/Components/BlockQuery.php deleted file mode 100644 index d7286496..00000000 --- a/src/Components/BlockQuery.php +++ /dev/null @@ -1,88 +0,0 @@ -config = $config; -// $this->view = $view; -// } - - public function shouldDisplay(): bool { - return ! \is_404(); - } - - public function display(): void { - \ob_start(); - - ?> - - -
- - - - - - -
- - - - -
- - -
- - - - -
- - -
- - - - - - -
- - -
- - - - - -
- - - - - -
- - - - -
- - - dispatcher = $dispatcher; - $this->config = $config; - $this->support = $support; - } - - public function shouldDisplay(): bool { - return $this->support->has('breadcrumbs') - && \in_array( - $this->config->get('current_template_file'), - \explode( ',', $this->config->get( 'breadcrumbs_show_on', '' ) ), - true - ) - && ! \in_array( 'hide_breadcrumbs', $this->config->get('post_content_template'), true ); - } - - public function display(): void { - $args = [ - // 'home' => '', - ]; - - ob_start(); - $this->dispatcher->dispatch( 'do_breadcrumbs', $args ); - echo (string)ob_get_clean(); - } -} diff --git a/src/Components/Colophon.php b/src/Components/Colophon.php deleted file mode 100644 index 177bd904..00000000 --- a/src/Components/Colophon.php +++ /dev/null @@ -1,58 +0,0 @@ -config->get(ConfigColophonProvider::COLOPHON_ACTION, self::EVENT_NAME); - $event_priority = (int)$this->config->get(ConfigColophonProvider::COLOPHON_PRIORITY, self::EVENT_PRIORITY); - yield $event_name => [ - static::CALLBACK => 'display', - static::PRIORITY => $event_priority, - ]; - } - - public function __construct( - ConfigInterface $config, - ViewInterface $view, - EventDispatcherInterface $dispatcher - ) { - $this->config = $config; - $this->view = $view; - $this->dispatcher = $dispatcher; - } - - public function shouldDisplay(): bool { - return true; - } - - public function display(): void { - $content = (string)$this->config->get( ConfigColophonProvider::COLOPHON, '' ); - - if ( empty( $content ) ) { - return; - } - - echo \do_blocks( $this->view->render( 'footers/colophon', [ - self::CONTENT => $this->dispatcher->filter( 'italystrap_colophon_output', $content ), - ] ) ); - } -} diff --git a/src/Components/Comments.php b/src/Components/Comments.php deleted file mode 100644 index 9e533a2a..00000000 --- a/src/Components/Comments.php +++ /dev/null @@ -1,37 +0,0 @@ -config = $config; - $this->view = $view; - } - - public function shouldDisplay(): bool { - return \is_singular() - && \post_type_supports( (string)\get_post_type(), 'comments' ) - && ! \in_array( 'hide_comments', $this->config->get('post_content_template'), true ); - } - - public function display(): void { - echo \do_blocks( $this->view->render( 'comments' ) ); - } -} diff --git a/src/Components/ComponentInterface.php b/src/Components/ComponentInterface.php deleted file mode 100644 index a62fcc6e..00000000 --- a/src/Components/ComponentInterface.php +++ /dev/null @@ -1,13 +0,0 @@ -subscriberRegister = $subscriberRegister; - $this->dispatcher = $dispatcher; - } - - /** - * @inheritDoc - */ - public function name(): string { - return self::class; - } - - /** - * @inheritDoc - */ - public function execute(AurynConfigInterface $application) { - $this->dispatcher->addListener( - 'template_include', - function ( string $current_template = '' ) use ( $application ): string { - $application->walk( $this->name(), [$this, 'walk'] ); - return $current_template; - }, - PHP_INT_MAX - 5, - 3 - ); - } - - /** - * @return void - */ - public function walk( string $class, $index_or_optionName, Injector $injector ) { - /** @var SubscriberInterface|ComponentInterface $instance */ - $instance = $injector - ->share($class) - ->proxy($class, $this->proxyCallback()) - ->make($class); - - if ( $this->shouldNotDisplay( $instance ) ) { - return; - } - - $this->subscriberRegister->addSubscriber( $instance ); - } - - private function shouldNotDisplay( ComponentInterface $instance ): bool { - return ! $instance->shouldDisplay(); - } - - /** - * @psalm-return \Closure(string, callable):\ProxyManager\Proxy\ValueHolderInterface&VirtualProxyInterface - */ - private function proxyCallback(): \Closure { - // phpcs:disable - return static fn(string $className, callable $callback): VirtualProxyInterface => (new LazyLoadingValueHolderFactory)->createProxy( - // phpcs:enable - $className, - static function ( - ?object &$object, - ?object $proxy, - string $method, - array $parameters, - ?\Closure &$initializer - ) use ( $callback ) { - $object = $callback(); - $initializer = null; - } - ); - } -} diff --git a/src/Components/Content.php b/src/Components/Content.php deleted file mode 100644 index bd3a785a..00000000 --- a/src/Components/Content.php +++ /dev/null @@ -1,34 +0,0 @@ -config = $config; - $this->view = $view; - } - - public function shouldDisplay(): bool { - return \is_singular() - && \post_type_supports( (string)\get_post_type(), 'editor' ) - && ! \in_array( 'hide_content', $this->config->get('post_content_template'), true ); - } - - public function display(): void { - echo \do_blocks( $this->view->render( 'temp/content', [] ) ); - } -} diff --git a/src/Components/CustomHeaderImage.php b/src/Components/CustomHeaderImage.php deleted file mode 100644 index 92ccad35..00000000 --- a/src/Components/CustomHeaderImage.php +++ /dev/null @@ -1,90 +0,0 @@ -config = $config; - $this->view = $view; - $this->tag = $tag; - $this->dispatcher = $dispatcher; - } - - public function shouldDisplay(): bool { - return \has_header_image(); - } - - public function display(): void { - echo \do_blocks( $this->view->render( 'headers/custom-header', [ - EventDispatcherInterface::class => $this->dispatcher, - self::CONTENT => $this->printFigureContainer(), - ] ) ); - } - - private function printFigureContainer(): string { - return $this->view->render('figure', [ - Tag::class => $this->tag, - 'figureAttributes' => [ - 'class' => \sprintf( - 'wp-block-image %s size-large', - (string)$this->config->get(ConfigCustomHeaderProvider::CUSTOM_HEADER_ALIGNMENT) - ), - ], - self::CONTENT => \get_header_image_tag(), - ]); - } - - private function printAnchorTag(): string { - return \sprintf( - '%s%s%s', - $this->tag->open( 'custom-header-anchor', 'a', [ - 'href' => \get_home_url( null, '/' ), - 'rel' => 'home', - ] ), - \get_header_image_tag(), - $this->tag->close('custom-header-anchor') - ); - } - - private function printForAttachment(): string { - $post_meta_id = \absint( \get_post_meta( \get_the_ID(), '_italystrap_custom_header_id', true ) ); - return $this->getAttachmentImage($post_meta_id); - } - - private function getAttachmentImage( int $id, string $size = 'full' ): string { - - $attr = [ - 'class' => "attachment-$id attachment-header size-header", - 'alt' => esc_attr( $this->config->get( 'GET_BLOGINFO_NAME' ) ), - ]; - - return \wp_get_attachment_image( $id, $size, false, $attr ); - } -} diff --git a/src/Components/Entry.php b/src/Components/Entry.php deleted file mode 100644 index 0ed6ea03..00000000 --- a/src/Components/Entry.php +++ /dev/null @@ -1,69 +0,0 @@ -config = $config; - $this->view = $view; - $this->dispatcher = $dispatcher; - } - - public function shouldDisplay(): bool { - return true; - } - - public function display(): void { - // Is it a good idea to pass (array) \get_post( null, ARRAY_A ); to data? - - $classes = \get_post_class(); - $classes = $this->classeForPostThumbnail( $classes ); - /** - * Remove the 'hentry' css class to prevents error in search console - */ - foreach ( $classes as $key => $class ) { - if ( 'hentry' === $class ) { - unset( $classes[ $key ] ); - } - } - - echo $this->view->render( 'posts/entry-post', [ - EventDispatcherInterface::class => $this->dispatcher, - 'id' => \get_the_ID(), - 'class_names' => \join( ' ', $classes ) - ] ); - } - - private function classeForPostThumbnail( array $classes ): array { - /** - * If has not a post thumbnail just bail out. - */ - if ( ! has_post_thumbnail() ) { - return $classes; - } - - $classes[] = 'post-thumbnail-' . $this->config->get( 'post_thumbnail_alignment' ); - - return $classes; - } -} diff --git a/src/Components/EntryNone.php b/src/Components/EntryNone.php deleted file mode 100644 index 4737bf08..00000000 --- a/src/Components/EntryNone.php +++ /dev/null @@ -1,41 +0,0 @@ -config = $config; - $this->view = $view; - $this->dispatcher = $dispatcher; - } - - public function shouldDisplay(): bool { - return true; - } - - public function display(): void { - echo \do_blocks( $this->view->render( 'posts/none', [ - EventDispatcherInterface::class => $this->dispatcher, - ] ) ); - } -} diff --git a/src/Components/EntryNoneContent.php b/src/Components/EntryNoneContent.php deleted file mode 100644 index a8a289dd..00000000 --- a/src/Components/EntryNoneContent.php +++ /dev/null @@ -1,45 +0,0 @@ -config = $config; - $this->view = $view; - $this->dispatcher = $dispatcher; - } - - public function shouldDisplay(): bool { - return true; - } - - public function display(): void { - echo \do_blocks( $this->view->render( - 'posts/none/content', - [ - 'content' => (string)$this->config->get(ConfigNotFoundProvider::CONTENT), - ] - ) ); - } -} diff --git a/src/Components/EntryNoneImage.php b/src/Components/EntryNoneImage.php deleted file mode 100644 index 04b90a9c..00000000 --- a/src/Components/EntryNoneImage.php +++ /dev/null @@ -1,69 +0,0 @@ -config = $config; - $this->view = $view; - $this->dispatcher = $dispatcher; - $this->tag = $tag; - } - - public function shouldDisplay(): bool { - return \is_404() && 'show' === (string)$this->config->get(ConfigNotFoundProvider::SHOW_IMAGE, ''); - } - - public function display(): void { - echo $this->view->render( 'figure', [ - Tag::class => $this->tag, - 'context' => self::class, - 'figureAttributes' => [ - 'class' => \sprintf( - '%s wp-block-post-featured-image', - (string)$this->config->get(ConfigPostThumbnailProvider::POST_THUMBNAIL_ALIGNMENT), - ), - ], - 'content' => $this->content(), - ] ); - } - - private function content() { - $size = (string)$this->config->get(ConfigPostThumbnailProvider::POST_THUMBNAIL_SIZE); - $html = \wp_get_attachment_image( - (int)$this->config->get(ConfigNotFoundProvider::ID_IMAGE, 0), - $size, - false, - [ - 'class' => "attachment-{$size} size-{$size} wp-post-image", - ] - ); - - return $this->dispatcher->filter('italystrap_lazyload_images_in_this_content', $html); - } -} diff --git a/src/Components/EntryNoneTitle.php b/src/Components/EntryNoneTitle.php deleted file mode 100644 index 973ada40..00000000 --- a/src/Components/EntryNoneTitle.php +++ /dev/null @@ -1,45 +0,0 @@ -config = $config; - $this->view = $view; - $this->dispatcher = $dispatcher; - } - - public function shouldDisplay(): bool { - return true; - } - - public function display(): void { - echo \do_blocks( $this->view->render( 'posts/none/title', [ - 'content' => (string)$this->config->get(ConfigNotFoundProvider::TITLE), - 'headlineAttributes' => [ - 'class' => 'page-title', - ], - ] ) ); - } -} diff --git a/src/Components/Excerpt.php b/src/Components/Excerpt.php deleted file mode 100644 index 5a22d532..00000000 --- a/src/Components/Excerpt.php +++ /dev/null @@ -1,33 +0,0 @@ -config = $config; - $this->view = $view; - } - - public function shouldDisplay(): bool { - return ! \is_singular() - && \post_type_supports( (string)\get_post_type(), 'excerpt' ) - && ! \in_array( 'hide_excerpt', $this->config->get('post_content_template'), true ); - } - - public function display(): void { - echo \do_blocks( $this->view->render( 'temp/excerpt', [] ) ); - } -} diff --git a/src/Components/FeaturedImage.php b/src/Components/FeaturedImage.php deleted file mode 100644 index f063cd15..00000000 --- a/src/Components/FeaturedImage.php +++ /dev/null @@ -1,66 +0,0 @@ -config = $config; - $this->view = $view; - } - - public function shouldDisplay(): bool { - return post_type_supports( (string)get_post_type(), 'thumbnail' ) - && !in_array( 'hide_thumb', $this->config->get('post_content_template'), true ); - } - - public function display(): void { -// if ( is_singular() ) { -// $this->config->add( ConfigPostThumbnailProvider::POST_THUMBNAIL_SIZE, 'post-thumbnail' ); -// $this->config->add( ConfigPostThumbnailProvider::POST_THUMBNAIL_ALIGNMENT, 'aligncenter' ); -// } - - $size = (string)$this->config->get( ConfigPostThumbnailProvider::POST_THUMBNAIL_SIZE ); - $size = $this->getThumbnailSizeForFullWidthLayout($size); - - $alignment = (string)$this->config->get(ConfigPostThumbnailProvider::POST_THUMBNAIL_ALIGNMENT); - $config = [ - 'align' => \str_replace('align', '', $alignment), - 'sizeSlug' => $size, - ]; - - echo \do_blocks( '' ); - } - - public function getThumbnailSizeForFullWidthLayout( string $size ): string { - $site_layout = (string) $this->config->get( 'site_layout' ); - - if ( 'full_width' === $site_layout ) { - return 'full-width'; - } - - if ( \is_page_template( 'full-width.php' ) ) { - return 'full-width'; - } - - return $size; - } -} diff --git a/src/Components/Footer.php b/src/Components/Footer.php deleted file mode 100644 index 5917e5d5..00000000 --- a/src/Components/Footer.php +++ /dev/null @@ -1,41 +0,0 @@ -config = $config; - $this->view = $view; - $this->dispatcher = $dispatcher; - } - - public function shouldDisplay(): bool { - return true; - } - - public function display(): void { - echo $this->view->render( 'footer', [ - EventDispatcherInterface::class => $this->dispatcher, - ] ); - } -} diff --git a/src/Components/FooterWidgetArea.php b/src/Components/FooterWidgetArea.php deleted file mode 100644 index 7cc44c0e..00000000 --- a/src/Components/FooterWidgetArea.php +++ /dev/null @@ -1,38 +0,0 @@ -config = $config; - $this->view = $view; - } - - public function shouldDisplay(): bool { - return true; - } - - public function display(): void { - echo \do_blocks( $this->view->render( 'footers/widget-area', [ - 'footer_sidebars' => ConfigSidebarProvider::FOOTERS, - ] ) ); - } -} diff --git a/src/Components/Footers/WidgetArea.php b/src/Components/Footers/WidgetArea.php deleted file mode 100644 index c5282ec9..00000000 --- a/src/Components/Footers/WidgetArea.php +++ /dev/null @@ -1,67 +0,0 @@ -view = $view; - } - - /** - * Render the output of the controller. - * - * @param $view - */ - public function render( $view ): void { - - $this->data['footer_sidebars'] = apply_filters( - 'footer_sidebars_widgets', - [ - 'footer-box-1', - 'footer-box-2', - 'footer-box-3', - 'footer-box-4', - ] - ); - - $this->data['col'] = $this->setCol(); - - echo \do_blocks( $this->view->render( $view, $this->data ) ); - } - - /** - * Set col-x number for sidebars style - * - * @see footer.php The file to display footer - */ - private function setCol(): int { - - global $sidebars_widgets, $wp_registered_widgets, $wp_registered_widget_controls; - - $count = 0; - - foreach ( $this->data['footer_sidebars'] as $value ) { - if ( ! empty( $sidebars_widgets[ $value ][0] ) ) { - $count++; - } - } - - $count = ( 0 === $count ) ? 1 : $count ; - - return \intval( \floor( 12 / $count ) ); - } -} diff --git a/src/Components/Header.php b/src/Components/Header.php deleted file mode 100644 index aa2570ad..00000000 --- a/src/Components/Header.php +++ /dev/null @@ -1,56 +0,0 @@ -config = $config; - $this->view = $view; - $this->dispatcher = $dispatcher; - $this->tag = $tag; - } - - public function shouldDisplay(): bool { - return true; - } - - public function display(): void { - echo $this->view->render( self::VIEW, [ - EventDispatcherInterface::class => $this->dispatcher, - Tag::class => $this->tag, - self::BODY_CLASS_NAMES => \sprintf( - '%s %s', - \join( ' ', \get_body_class() ), - $this->config->get('current_template_slug') - ), - self::WRAPPER_CLASS_NAMES => 'wrapper wp-site-blocks', - ] ); - } -} diff --git a/src/Components/Index.php b/src/Components/Index.php deleted file mode 100644 index 4d1ceb38..00000000 --- a/src/Components/Index.php +++ /dev/null @@ -1,43 +0,0 @@ -config = $config; - $this->view = $view; - $this->dispatcher = $dispatcher; - } - - public function shouldDisplay(): bool { - return true; - } - - public function display(): void { - echo \do_blocks( $this->view->render( 'index', [ - EventDispatcherInterface::class => $this->dispatcher, - 'container_class_names' => $this->config->get('container_width'), - 'row_class_names' => 'row', - ] ) ); - } -} diff --git a/src/Components/Loop.php b/src/Components/Loop.php deleted file mode 100644 index f28ed60c..00000000 --- a/src/Components/Loop.php +++ /dev/null @@ -1,41 +0,0 @@ -config = $config; - $this->view = $view; - $this->dispatcher = $dispatcher; - } - - public function shouldDisplay(): bool { - return true; - } - - public function display(): void { - echo \do_blocks( $this->view->render( 'posts/loop', [ - EventDispatcherInterface::class => $this->dispatcher, - ] ) ); - } -} diff --git a/src/Components/MainNavigation.php b/src/Components/MainNavigation.php deleted file mode 100644 index 0ce2f735..00000000 --- a/src/Components/MainNavigation.php +++ /dev/null @@ -1,43 +0,0 @@ -config = $config; - $this->view = $view; - $this->dispatcher = $dispatcher; - } - - public function shouldDisplay(): bool { - return true; - } - - public function display(): void { - echo \do_blocks( $this->view->render( 'navigation', [ - EventDispatcherInterface::class => $this->dispatcher, - self::CONTEXT => 'this-context', - ] ) ); - } -} diff --git a/src/Components/MainNavigationOlder.php b/src/Components/MainNavigationOlder.php deleted file mode 100644 index 73c6697a..00000000 --- a/src/Components/MainNavigationOlder.php +++ /dev/null @@ -1,51 +0,0 @@ -config = $config; - $this->view = $view; - $this->navbar = $navbar; - $this->navMenuPrimary = $navMenuPrimary; - $this->navMenuSecondary = $navMenuSecondary; - } - - public function shouldDisplay(): bool { - return true; - } - - public function display(): void { - echo \do_blocks( $this->view->render( 'headers/navbar', [ - 'mods' => $this->config, - Navbar::class => $this->navbar, - NavMenuPrimary::class => $this->navMenuPrimary, - NavMenuSecondary::class => $this->navMenuSecondary, - ] ) ); - } -} diff --git a/src/Components/Meta.php b/src/Components/Meta.php deleted file mode 100644 index 4f324d19..00000000 --- a/src/Components/Meta.php +++ /dev/null @@ -1,33 +0,0 @@ -config = $config; - $this->view = $view; - } - - public function shouldDisplay(): bool { - return \post_type_supports( (string)\get_post_type(), 'entry-meta' ) - && ! \in_array( 'hide_meta', $this->config->get('post_content_template'), true ); - } - - public function display(): void { - echo \do_blocks( $this->view->render( 'temp/meta', [] ) ); - } -} diff --git a/src/Components/MiscNavigation.php b/src/Components/MiscNavigation.php deleted file mode 100644 index d7e0d0ff..00000000 --- a/src/Components/MiscNavigation.php +++ /dev/null @@ -1,42 +0,0 @@ -config = $config; - $this->view = $view; - $this->dispatcher = $dispatcher; - } - - public function shouldDisplay(): bool { - return \has_nav_menu( 'info-menu' ) - && \has_nav_menu( 'social-menu' ); - } - - public function display(): void { - echo \do_blocks( $this->view->render( 'headers/navbar-top', [ - EventDispatcherInterface::class => $this->dispatcher, - ] ) ); - } -} diff --git a/src/Components/Modified.php b/src/Components/Modified.php deleted file mode 100644 index 52b06dbe..00000000 --- a/src/Components/Modified.php +++ /dev/null @@ -1,32 +0,0 @@ -config = $config; - $this->view = $view; - } - - public function shouldDisplay(): bool { - return true; - } - - public function display(): void { - echo \do_blocks( $this->view->render( 'posts/parts/modified', [] ) ); - } -} diff --git a/src/Components/NavMenuHeader.php b/src/Components/NavMenuHeader.php deleted file mode 100644 index 211a0004..00000000 --- a/src/Components/NavMenuHeader.php +++ /dev/null @@ -1,40 +0,0 @@ -config = $config; - $this->view = $view; - $this->dispatcher = $dispatcher; - } - - public function shouldDisplay(): bool { - return true; - } - - public function display(): void { - echo $this->view->render('navigation/header', [ - EventDispatcherInterface::class => $this->dispatcher, - ]); - } -} diff --git a/src/Components/NavMenuPrimary.php b/src/Components/NavMenuPrimary.php deleted file mode 100644 index 9d8d7c6b..00000000 --- a/src/Components/NavMenuPrimary.php +++ /dev/null @@ -1,58 +0,0 @@ -config = $config; - $this->view = $view; - $this->menu = $menu; - $this->location = $location; - $this->fallback = $fallback; - } - - public function shouldDisplay(): bool { - return true; - } - - public function display(): void { - echo $this->menu->render([ - NavMenu::MENU_CLASS_NAME => \sprintf( - 'nav navbar-nav %s', - $this->config->get('mods.navbar.main_menu_x_align') - ), - NavMenu::MENU_ID => 'main-menu', - NavMenu::FALLBACK_CB => $this->fallback, - NavMenu::THEME_LOCATION => self::class, - ]); - } -} diff --git a/src/Components/NavMenuSecondary.php b/src/Components/NavMenuSecondary.php deleted file mode 100644 index a74e0dfe..00000000 --- a/src/Components/NavMenuSecondary.php +++ /dev/null @@ -1,48 +0,0 @@ -config = $config; - $this->view = $view; - $this->menu = $menu; - $this->location = $location; - } - - public function shouldDisplay(): bool { - return $this->location->has(self::class); - } - - public function display(): void { - echo $this->menu->render([ - NavMenu::MENU_CLASS_NAME => 'nav navbar-nav navbar-right', - NavMenu::MENU_ID => 'secondary-menu', - NavMenu::FALLBACK_CB => false, - NavMenu::THEME_LOCATION => self::class, - ]); - } -} diff --git a/src/Components/NavMenuToggleButton.php b/src/Components/NavMenuToggleButton.php deleted file mode 100644 index c0435a04..00000000 --- a/src/Components/NavMenuToggleButton.php +++ /dev/null @@ -1,47 +0,0 @@ -config = $config; - $this->view = $view; - $this->dispatcher = $dispatcher; - } - - public function shouldDisplay(): bool { - return true; - } - - public function display(): void { - echo ''; - } -} diff --git a/src/Components/Navigations/LinkPages.php b/src/Components/Navigations/LinkPages.php deleted file mode 100644 index c767ee15..00000000 --- a/src/Components/Navigations/LinkPages.php +++ /dev/null @@ -1,43 +0,0 @@ -dispatcher = $dispatcher; - } - /** - * Render the output of the controller. - */ - public function render() : string { - - /** - * Arguments for wp_link_pages - * - * @link https://developer.wordpress.org/reference/functions/wp_link_pages/ - * @var array - */ - $args = [ - 'echo' => false, - ]; - - $args = $this->dispatcher->filter( 'italystrap_wp_link_pages_args', $args ); - - return wp_link_pages( $args ); - } -} diff --git a/src/Components/Navigations/Navbar.php b/src/Components/Navigations/Navbar.php deleted file mode 100644 index 6b65f9d1..00000000 --- a/src/Components/Navigations/Navbar.php +++ /dev/null @@ -1,501 +0,0 @@ -config = $config; - $this->walker = $walker; - $this->fallback_cb = $fallback_cb; - - /** - * Count this instance - */ - self::$instance_count ++; - - $this->number = self::$instance_count; - - $this->navbar_id = \apply_filters( 'italystrap_navbar_id', 'italystrap-menu-' . $this->number ); - $this->navbar_id = \apply_filters( 'italystrap_navbar_id_' . $this->number, $this->navbar_id ); - - $this->menu = $menu; - } - - /** - * Get the wp_nav_menu with default parameters for Bootstrap CSS style - * - * @param array $args The wp_nav_menu arguments. - * - * @return false|null|string Return the wp_nav_menu HTML - */ - public function get_wp_nav_menu( array $args = [] ) {// phpcs:ignore - - /** - * Arguments for wp_nav_menu() - * For filtering wp_nav_menu use the 'wp_nav_menu' hooks with 2 parameters - * add_filter( 'wp_nav_menu', 'your_functions', 10, 2 ); - * For this situation the container attribute is set to false because - * we need the collapsable functionality of Bootstrap CSS. - * - * @todo Non credo mi possa essere utile https://github.com/devaloka/nav-menu ma si - * potrebbe comunque creare una classe a parte per wp_nav_menu e togliere da qui. - * - * @link https://developer.wordpress.org/reference/functions/wp_nav_menu/ - * @var array - */ - $defaults = [ - 'menu' => '', - 'container' => false, - // WP Default div. - 'container_class' => false, - 'container_id' => false, - 'menu_class' => \sprintf( - 'nav navbar-nav %s', - $this->config->get('navbar.main_menu_x_align') - ), - 'menu_id' => 'main-menu', - 'echo' => false, - 'fallback_cb' => $this->fallback_cb, - 'before' => '', - 'after' => '', - 'link_before' => '', - 'link_after' => '', - 'items_wrap' => '
    %3$s
', - 'item_spacing' => 'preserve', - 'depth' => 10, - 'walker' => $this->walker, - 'theme_location' => 'main-menu', - 'search' => false, - ]; - - $args = wp_parse_args( $args, $defaults ); - - $args = apply_filters( 'italystrap_' . $args[ 'theme_location' ] . '_args', $args, $this->navbar_id ); - - return wp_nav_menu( $args ); - } - - /** - * Get secondary wp-nav-menu - * - * @return false|null|string Return the secondary wp_nav_menu HTML - */ - public function get_secondary_wp_nav_menu() {// phpcs:ignore - - if ( ! has_nav_menu( 'secondary-menu' ) ) { - return ''; - } - - $args = [ - 'menu_class' => 'nav navbar-nav navbar-right', - 'menu_id' => 'secondary-menu', - 'fallback_cb' => false, - 'theme_location' => 'secondary-menu' - ]; - - return $this->get_wp_nav_menu( $args ); - } - - /** - * Get Brand - * - * @return string Return the HTML for brand name and/or image. - */ - public function get_brand() {// phpcs:ignore - - /** - * The ID of the logo image for navbar - * By default in the customizer is set a url for the image instead of an integer - * When it is choices an image than it will set an integer for $this->config['navbar_logo'] - * - * @var integer - */ - $attachment_id = (int)apply_filters( - 'italystrap_navbar_logo_image_id', - $this->config->get( ConfigSiteLogoProvider::BRAND_IMAGE_ID ) - ); - - $brand = ''; - - if ( $attachment_id && 'display_image' === $this->config[ 'display_navbar_brand' ] ) { - $attr = ['class' => 'img-brand img-responsive center-block', 'alt' => esc_attr( \get_option( 'blogname' ) ) - . ' ‐ ' - . esc_attr( \get_option( 'blogdescription' ) ), 'itemprop' => 'image']; - - /** - * Size default: navbar-brand-image - */ - $brand .= wp_get_attachment_image( - $attachment_id, - $this->config[ 'navbar_logo_image_size' ], - false, - $attr - ); - - $brand .= ''; - } elseif ( $attachment_id && 'display_all' === $this->config[ 'display_navbar_brand' ] ) { - $attr = [ - 'class' => 'img-brand img-responsive center-block', - 'alt' => esc_attr( \get_option( 'blogname' ) ) - . ' - ' - . esc_attr( \get_option( 'blogdescription' ) ), - 'itemprop' => 'image', - 'style' => 'display:inline;margin-right:15px;' - ]; - - /** - * Size default: navbar-brand-image - */ - $brand .= wp_get_attachment_image( - $attachment_id, - $this->config[ 'navbar_logo_image_size' ], - false, - $attr - ); - - $brand .= '' - . esc_attr( \get_option( 'blogname' ) ) . ''; - } else { - $brand .= '' - . esc_attr( \get_option( 'blogname' ) ) - . ''; - } - - return $brand; - } - - /** - * Get the HTML for description - * - * @param array $attr The navbar brand attributes. - * - * @return string Return the HTML for description - */ - public function get_navbar_brand( array $attr = [] ) {// phpcs:ignore - - if ( 'none' === $this->config[ 'display_navbar_brand' ] ) { - return apply_filters( 'italystrap_navbar_brand_none', '', $this->navbar_id ); - } - - $default = [ - 'class' => 'navbar-brand', - 'href' => esc_url( $this->config->get( 'HOME_URL' ) ), - 'title' => sprintf( - '%s - %s', - \get_option( 'blogname' ), - \get_option( 'blogdescription' ) - ), - 'rel' => 'home', - 'itemprop' => 'url' - ]; - - return $this->createElement( - 'navbar_brand', - 'a', - array_merge( $default, $attr ), - $this->get_brand() - ); - } - - /** - * Get the HTML for toggle button - * - * @return string Return the HTML for toggle button - */ - public function get_toggle_button() {// phpcs:ignore - - $icon_bar = apply_filters( - 'italystrap_icon_bar', - '   ' - ); - - $a = ['class' => 'navbar-toggle', 'data-toggle' => 'collapse', 'data-target' => '#' . $this->navbar_id]; - -// $output = sprintf( -// '%s%s', -// $this->get_attr( $a, 'toggle_button' ), -// esc_attr__( 'Toggle navigation', 'italystrap' ), -// $icon_bar -// ); -// -// return apply_filters( 'italystrap_toggle_button', $output, $this->navbar_id ); - /** - * '%s%s' - */ - return $this->createElement( - 'toggle_button', - 'button', - $a, - $this->createElement( - 'toggle_button_content', - 'span', - ['class' => 'sr-only screen-reader-text'], - esc_attr__( 'Toggle navigation', 'italystrap' ) - ) . trim( $icon_bar ) - ); - } - - /** - * Get the HTML for Navbar Header - * - * @return string Return the HTML for Navbar Header - */ - public function get_navbar_header() {// phpcs:ignore - - $a = [ - 'class' => 'navbar-header', - 'itemprop' => 'publisher', - 'itemscope' => true, - 'itemtype' => 'https://schema.org/Organization', - ]; - - return $this->createElement( - 'navbar_header', - 'div', - $a, - $this->get_navbar_brand() . $this->get_toggle_button() - ); - } - - /** - * Get the collapsable HTML menu - * - * http://bootsnipp.com/snippets/featured/expanding-search-button-in-css - * - * @return string Return the HTML - */ - public function get_collapsable_menu() {// phpcs:ignore - - $a = [ - 'id' => $this->navbar_id, - 'class' => 'navbar-collapse collapse', - ]; - - return $this->createElement( - 'collapsable_menu', - 'div', - $a, - $this->get_wp_nav_menu() . $this->get_secondary_wp_nav_menu() - ); - } - - /** - * A container inside the navbar-default/revers - * - * @return string The html output. - */ - public function get_last_container() {// phpcs:ignore -// add_filter( 'italystrap_pre_last_container', '__return_true' ); - $a = [ - 'id' => 'menus-container-' . $this->number, - 'class' => $this->config[ 'navbar' ][ 'menus_width' ], - ]; - - return $this->createElement( - 'last_container', - 'div', - $a, - $this->get_navbar_header() . $this->get_collapsable_menu() - ); - } - - /** - * The regulare navbar container, - * this manage the type of navabr available from Twitter Bootstrap - * - * @see http://getbootstrap.com/components/#navbar - * - * navbar-default - * navbar-inverse - * - * navbar navbar-default navbar-relative-top - * - * navbar navbar-default navbar-fixed-top // body { padding-top: 70px; } - * navbar navbar-default navbar-fixed-bottom // body { padding-bottom: 70px; } - * - * navbar navbar-default navbar-static-top - * - * @return string The navbar string. - */ - public function get_navbar_container() {// phpcs:ignore - - $a = [ - 'class' => sprintf( - 'navbar %s %s', - $this->config[ 'navbar' ][ 'type' ], - $this->config[ 'navbar' ][ 'position' ] - ), - 'itemscope' => true, - 'itemtype' => 'https://schema.org/SiteNavigationElement', - ]; - - return $this->createElement( - 'navbar_container', - 'nav', - $a, - $this->get_last_container() - ); - } - - /** - * Generate the nav tag container of entire navbar - * - * @see http://getbootstrap.com/components/#navbar - * - * This manage the full width or boxed width (.conainer or null) - * - * @return string Return the entire navbar. - */ - public function get_nav_container() {// phpcs:ignore - -// if ( 'none' === $this->config[ 'navbar' ][ 'nav_width' ] ) { -// return $this->get_navbar_container(); -// } - -// d( $this->config ); - - $a = [ - 'id' => 'main-navbar-container-' . $this->navbar_id, - 'class' => sprintf( - 'navbar-wrapper %s', - $this->config[ 'navbar' ][ 'nav_width' ] - ), - ]; - - return $this->createElement( 'nav_container', 'div', $a, $this->get_navbar_container() ); - } - - /** - * @param string $context - * @param string $tag - * @param array $attr - * @param string $content - * @return string - */ - private function createElement( string $context, string $tag, array $attr, string $content ): string { - -// if ( !is_string( $context ) ) { -// throw new \InvalidArgumentException( 'The $context variable must be a string', 0 ); -// } -// -// if ( !is_string( $tag ) ) { -// throw new \InvalidArgumentException( 'The $tag variable must be a string', 0 ); -// } -// -// if ( !is_string( $content ) ) { -// throw new \InvalidArgumentException( 'The $content variable must be a string', 0 ); -// } - - $content = (string)apply_filters( 'italystrap_' . $context . '_child', $content, $this->navbar_id ); - - if ( empty( $content ) ) { - $content = ' '; - } - - if ( (bool) apply_filters( 'italystrap_pre_' . $context, false ) ) { - return $content; - } - - $tag = apply_filters( 'italystrap_' . $context . '_tag', $tag, $this->navbar_id ); - - $output = sprintf( - '<%1$s%2$s>%3$s', - esc_attr( $tag ), - $this->getAttr( $attr, $context ), - $content - ); - - return apply_filters( 'italystrap_' . $context, $output, $this->navbar_id ); - } - - /** - * Render the HTML tag attributes from an array - * - * @param array $attr The HTML attributes with key value. - * @param string $context - * - * @return string Return a string with HTML attributes - */ - private function getAttr( array $attr = [], $context = '' ) { - return get_attr( $context, $attr, false, $this->navbar_id ); - } - - /** - * @return string - */ - public function render() { - return $this->get_nav_container(); - } - - /** - * Output the HTML - */ - public function output(): void { - echo $this->render(); - } -} diff --git a/src/Components/Navigations/index.php b/src/Components/Navigations/index.php deleted file mode 100644 index b3d9bbc7..00000000 --- a/src/Components/Navigations/index.php +++ /dev/null @@ -1 +0,0 @@ -config = $config; - $this->view = $view; - } - - public function shouldDisplay(): bool { - return \is_single() - && \post_type_supports( (string)\get_post_type(), 'post_navigation' ); - } - - public function display(): void { - echo \do_blocks( $this->view->render( 'temp/pager', [] ) ); - } -} diff --git a/src/Components/Pagination.php b/src/Components/Pagination.php deleted file mode 100644 index 922dff4c..00000000 --- a/src/Components/Pagination.php +++ /dev/null @@ -1,32 +0,0 @@ -config = $config; - $this->view = $view; - } - - public function shouldDisplay(): bool { - return ! \is_404(); - } - - public function display(): void { - echo \do_blocks( $this->view->render( 'temp/pagination', [] ) ); - } -} diff --git a/src/Components/PostAuthorInfo.php b/src/Components/PostAuthorInfo.php deleted file mode 100644 index 76bd2e9d..00000000 --- a/src/Components/PostAuthorInfo.php +++ /dev/null @@ -1,33 +0,0 @@ -config = $config; - $this->author = $author; - } - - public function shouldDisplay(): bool { - return \post_type_supports( (string)\get_post_type(), 'author' ) - && \is_singular() - && ! \in_array( 'hide_author', $this->config->get('post_content_template'), true ); - } - - public function display(): void { - echo $this->author->render(null, []); - } -} diff --git a/src/Components/Preview.php b/src/Components/Preview.php deleted file mode 100644 index f4942c8b..00000000 --- a/src/Components/Preview.php +++ /dev/null @@ -1,45 +0,0 @@ -output() ); - } - - /** - * @return false|string - */ - private function output() { - \ob_start(); - ?> - -
- Note: You are previewing this post. This post has not yet been published.', - 'italystrap' - ) - ); - ?> -
- - config = $config; - $this->view = $view; - } - - public function shouldDisplay(): bool { - return 'full_width' !== $this->config->get( 'site_layout' ); - } - - public function display(): void { - echo $this->view->render( 'sidebar', [ - 'index' => ConfigSidebarProvider::SIDEBAR_PRIMARY, - ] ); - } -} diff --git a/src/Components/SiteLogo.php b/src/Components/SiteLogo.php deleted file mode 100644 index 8db30935..00000000 --- a/src/Components/SiteLogo.php +++ /dev/null @@ -1,64 +0,0 @@ -config = $config; - $this->view = $view; - $this->dispatcher = $dispatcher; - $this->support = $support; - $this->json = $json; - } - - public function shouldDisplay(): bool { - return $this->support->has( ConfigThemeSupportProvider::CUSTOM_LOGO ) - && $this->config->get( ConfigSiteLogoProvider::CUSTOM_LOGO_ID ); - } - - public function display(): void { - $size_name_registered = (string)$this->config->get(ConfigSiteLogoProvider::BRAND_IMAGE_SIZE); - $width = (int)$this->config->get(ThumbnailsSubscriber::class . '.' . $size_name_registered . '.width'); - - $block_attributes = $this->json->encode([ - 'width' => $width, - 'shouldSyncIcon' => 'false', - 'className' => 'is-style-default', - ]); - - echo \do_blocks( $this->view->render('misc/site-logo', [ - self::ATTRIBUTES => $block_attributes - ]) ); - } -} diff --git a/src/Components/SiteTagline.php b/src/Components/SiteTagline.php deleted file mode 100644 index 11703620..00000000 --- a/src/Components/SiteTagline.php +++ /dev/null @@ -1,39 +0,0 @@ -config = $config; - $this->view = $view; - $this->dispatcher = $dispatcher; - } - - public function shouldDisplay(): bool { - return true; - } - - public function display(): void { - echo \do_blocks( '' ); - } -} diff --git a/src/Components/SiteTitle.php b/src/Components/SiteTitle.php deleted file mode 100644 index f247f209..00000000 --- a/src/Components/SiteTitle.php +++ /dev/null @@ -1,39 +0,0 @@ -config = $config; - $this->view = $view; - $this->dispatcher = $dispatcher; - } - - public function shouldDisplay(): bool { - return true; - } - - public function display(): void { - echo \do_blocks( '' ); - } -} diff --git a/src/Components/SubscribedEventsAware.php b/src/Components/SubscribedEventsAware.php index a89c6dc2..99b1d449 100644 --- a/src/Components/SubscribedEventsAware.php +++ b/src/Components/SubscribedEventsAware.php @@ -1,14 +1,16 @@ [ - self::CALLBACK => self::DISPLAY_METHOD_NAME, - self::PRIORITY => self::EVENT_PRIORITY, - ]; - } +trait SubscribedEventsAware +{ + public function getSubscribedEvents(): iterable + { + yield self::EVENT_NAME => [ + self::CALLBACK => self::DISPLAY_METHOD_NAME, + self::PRIORITY => self::EVENT_PRIORITY, + ]; + } } diff --git a/src/Components/Title.php b/src/Components/Title.php deleted file mode 100644 index e95ca943..00000000 --- a/src/Components/Title.php +++ /dev/null @@ -1,40 +0,0 @@ -config = $config; - $this->view = $view; - } - - public function shouldDisplay(): bool { - return \post_type_supports( (string)\get_post_type(), 'title' ) - && ! \in_array( 'hide_title', $this->config->get('post_content_template'), true ); - } - - public function display(): void { - - $post_title_config = [ - "level" => \is_singular() ? 1 : 2, - "isLink" => true, - "rel" => "bookmark", - "className" => "entry-title", - ]; - - echo \do_blocks( $this->view->render( 'temp/title', $post_title_config ) ); - } -} diff --git a/src/Config/AlignmentChoicesTrait.php b/src/Config/AlignmentChoicesTrait.php index 10d101e7..9ac0348e 100644 --- a/src/Config/AlignmentChoicesTrait.php +++ b/src/Config/AlignmentChoicesTrait.php @@ -1,57 +1,63 @@ \__( 'None', 'italystrap' ) - ]; - } - - private function getHorizontalStandard(): iterable { - yield from $this->alignNone(); - yield 'container-fluid' => \__('Full witdh (deprecated)', 'italystrap'); - yield 'container' => \__('Standard width (deprecated)', 'italystrap'); - yield AlignmentKeys::ALIGN_FULL => \__('Align Full', 'italystrap'); - yield AlignmentKeys::ALIGN_WIDE => \__('Align Wide', 'italystrap'); - } - - private function getHorizontalThumb(): iterable { - yield from $this->alignNone(); - yield AlignmentKeys::ALIGN_FULL => \__('Align Full', 'italystrap'); - yield AlignmentKeys::ALIGN_WIDE => \__('Align Wide', 'italystrap'); - yield AlignmentKeys::ALIGN_CENTER => \__('Align Center', 'italystrap'); - yield AlignmentKeys::ALIGN_LEFT => \__('Align Left', 'italystrap'); - yield AlignmentKeys::ALIGN_RIGHT => \__('Align Right', 'italystrap'); - } - - private function getHorizontalAll(): iterable { - yield from $this->getHorizontalStandard(); - yield AlignmentKeys::ALIGN_FULL => \__('Align Full', 'italystrap'); - yield AlignmentKeys::ALIGN_WIDE => \__('Align Wide', 'italystrap'); - yield AlignmentKeys::ALIGN_CENTER => \__('Align Center', 'italystrap'); - yield AlignmentKeys::ALIGN_LEFT => \__('Align Left', 'italystrap'); - yield AlignmentKeys::ALIGN_RIGHT => \__('Align Right', 'italystrap'); - } - - private function getAllHorizontalAlignment(): iterable { - return (array)$this->dispatcher->filter( - 'italystrap_horizontal_alignment_choices_trait', - [ - ...$this->getHorizontalStandard(), - AlignmentKeys::ALIGN_FULL => \__('Align Full', 'italystrap'), - AlignmentKeys::ALIGN_WIDE => \__('Align Wide', 'italystrap'), - AlignmentKeys::ALIGN_CENTER => \__('Align Center', 'italystrap'), - AlignmentKeys::ALIGN_LEFT => \__('Align Left', 'italystrap'), - AlignmentKeys::ALIGN_RIGHT => \__('Align Right', 'italystrap'), - ] - ); - } +trait AlignmentChoicesTrait +{ + private EventDispatcherInterface $dispatcher; + + private function alignNone(): iterable + { + return [ + AlignmentKeys::ALIGN_NONE => \__('None', 'italystrap') + ]; + } + + private function getHorizontalStandard(): iterable + { + yield from $this->alignNone(); + yield 'container-fluid' => \__('Full witdh (deprecated)', 'italystrap'); + yield 'container' => \__('Standard width (deprecated)', 'italystrap'); + yield AlignmentKeys::ALIGN_FULL => \__('Align Full', 'italystrap'); + yield AlignmentKeys::ALIGN_WIDE => \__('Align Wide', 'italystrap'); + } + + private function getHorizontalThumb(): iterable + { + yield from $this->alignNone(); + yield AlignmentKeys::ALIGN_FULL => \__('Align Full', 'italystrap'); + yield AlignmentKeys::ALIGN_WIDE => \__('Align Wide', 'italystrap'); + yield AlignmentKeys::ALIGN_CENTER => \__('Align Center', 'italystrap'); + yield AlignmentKeys::ALIGN_LEFT => \__('Align Left', 'italystrap'); + yield AlignmentKeys::ALIGN_RIGHT => \__('Align Right', 'italystrap'); + } + + private function getHorizontalAll(): iterable + { + yield from $this->getHorizontalStandard(); + yield AlignmentKeys::ALIGN_FULL => \__('Align Full', 'italystrap'); + yield AlignmentKeys::ALIGN_WIDE => \__('Align Wide', 'italystrap'); + yield AlignmentKeys::ALIGN_CENTER => \__('Align Center', 'italystrap'); + yield AlignmentKeys::ALIGN_LEFT => \__('Align Left', 'italystrap'); + yield AlignmentKeys::ALIGN_RIGHT => \__('Align Right', 'italystrap'); + } + + private function getAllHorizontalAlignment(): iterable + { + return (array)$this->dispatcher->filter( + 'italystrap_horizontal_alignment_choices_trait', + [ + ...$this->getHorizontalStandard(), + AlignmentKeys::ALIGN_FULL => \__('Align Full', 'italystrap'), + AlignmentKeys::ALIGN_WIDE => \__('Align Wide', 'italystrap'), + AlignmentKeys::ALIGN_CENTER => \__('Align Center', 'italystrap'), + AlignmentKeys::ALIGN_LEFT => \__('Align Left', 'italystrap'), + AlignmentKeys::ALIGN_RIGHT => \__('Align Right', 'italystrap'), + ] + ); + } } diff --git a/src/Config/AlignmentKeys.php b/src/Config/AlignmentKeys.php index 2eaa28f5..c91f312e 100644 --- a/src/Config/AlignmentKeys.php +++ b/src/Config/AlignmentKeys.php @@ -1,13 +1,15 @@ ''; - yield self::COLOPHON_ACTION => Colophon::EVENT_NAME; - yield self::COLOPHON_PRIORITY => Colophon::EVENT_PRIORITY; - } + public function __invoke(): iterable + { + yield self::COLOPHON => ''; + yield self::COLOPHON_ACTION => Content::class; + yield self::COLOPHON_PRIORITY => Colophon::EVENT_PRIORITY; + } } diff --git a/src/Config/ConfigColorSectionProvider.php b/src/Config/ConfigColorSectionProvider.php index 7cd9ed81..d4ee3d1e 100644 --- a/src/Config/ConfigColorSectionProvider.php +++ b/src/Config/ConfigColorSectionProvider.php @@ -1,19 +1,21 @@ '';// Set by WordPress. - yield self::HEADER_COLOR => '';// Set by WordPress. - yield self::LINK_COLOR => ''; - yield self::HX_COLOR => ''; - } + public function __invoke(): iterable + { + yield self::BG_COLOR => '';// Set by WordPress. + yield self::HEADER_COLOR => '';// Set by WordPress. + yield self::LINK_COLOR => ''; + yield self::HX_COLOR => ''; + } } diff --git a/src/Config/ConfigCurrentTemplateSubscriber.php b/src/Config/ConfigCurrentTemplateSubscriber.php deleted file mode 100644 index e3c55f6b..00000000 --- a/src/Config/ConfigCurrentTemplateSubscriber.php +++ /dev/null @@ -1,52 +0,0 @@ - [ - self::CALLBACK => self::REGISTER_CB, - self::PRIORITY => PHP_INT_MAX - 100, - ]; - } - - private ConfigInterface $config; - private FileInfoFactoryInterface $fileInfoFactory; - - /** - * Init sidebars registration - */ - public function __construct( - ConfigInterface $config, - FileInfoFactoryInterface $fileInfoFactory - ) { - $this->config = $config; - $this->fileInfoFactory = $fileInfoFactory; - } - - public function register( string $current_template = '' ): string { - $current_template = $this->fileInfoFactory->make( $current_template ); - $base_name = $current_template->getBasename(); - $slug = $current_template->getBasename('.'.$current_template->getExtension()); - - define( 'CURRENT_TEMPLATE', $base_name ); - define( 'CURRENT_TEMPLATE_SLUG', $slug ); - - $this->config->add( self::TEMPLATE_FILE_NAME, $base_name ); - $this->config->add( self::TEMPLATE_FILE_SLUG, $slug ); - - return $current_template->__toString(); - } -} diff --git a/src/Config/ConfigCustomHeaderProvider.php b/src/Config/ConfigCustomHeaderProvider.php index 618439ff..cbb30578 100644 --- a/src/Config/ConfigCustomHeaderProvider.php +++ b/src/Config/ConfigCustomHeaderProvider.php @@ -1,13 +1,15 @@ 'alignfull'; - } + public function __invoke(): iterable + { + yield self::CUSTOM_HEADER_ALIGNMENT => 'alignfull'; + } } diff --git a/src/Config/ConfigLayoutProvider.php b/src/Config/ConfigLayoutProvider.php index b1f3ab15..ade56c1b 100644 --- a/src/Config/ConfigLayoutProvider.php +++ b/src/Config/ConfigLayoutProvider.php @@ -1,17 +1,19 @@ ''; - yield self::SITE_LAYOUT => 'content_sidebar'; - yield self::CONTAINER_WIDTH => 'container'; - } + public function __invoke(): iterable + { + yield self::POST_CONTENT_TEMPLATE => ''; + yield self::SITE_LAYOUT => 'content_sidebar'; + yield self::CONTAINER_WIDTH => 'container'; + } } diff --git a/src/Config/ConfigMiscProvider.php b/src/Config/ConfigMiscProvider.php index dfdc2e45..a106af21 100644 --- a/src/Config/ConfigMiscProvider.php +++ b/src/Config/ConfigMiscProvider.php @@ -1,25 +1,27 @@ theme_mods['site_layout'] ); - // https://core.trac.wordpress.org/ticket/24844 - 'site_layout' => (string) \apply_filters( 'theme_mod_site_layout', 'content_sidebar' ), +class ConfigMiscProvider +{ + public function __invoke(): iterable + { + return [ + /** + * Layout configuration + * It's still in alpha version + */ + //( is_customize_preview() ? get_theme_mod('site_layout') : $this->theme_mods['site_layout'] ); + // https://core.trac.wordpress.org/ticket/24844 + 'site_layout' => (string) \apply_filters('theme_mod_site_layout', 'content_sidebar'), - 'container_width' => 'container', // container-fluid. + 'container_width' => 'container', // container-fluid. - 'post_content_template' => '', - 'breadcrumbs_show_on' => '', - ]; - } + 'post_content_template' => '', + 'breadcrumbs_show_on' => '', + ]; + } } diff --git a/src/Config/ConfigNavigationProvider.php b/src/Config/ConfigNavigationProvider.php deleted file mode 100644 index 5ee92352..00000000 --- a/src/Config/ConfigNavigationProvider.php +++ /dev/null @@ -1,34 +0,0 @@ - [ - /** - * options: - * navbar-default - * navbar-inverse - */ - 'type' => 'navbar-inverse', - 'position' => 'navbar-static-top', - 'nav_width' => 'none', // This is the container of entire navbar. - 'menus_width' => 'container', // This is the container of the 2 menus inside the nav container - //and the navbar_header brand and toggle. - 'main_menu_x_align' => 'navbar-left', - ], - NavMenusSubscriber::class => - [ - NavMenuPrimary::class => \__( 'Primary menu', 'italystrap' ), - NavMenuSecondary::class => \__( 'Secondary menu', 'italystrap' ), - ], - ]; - } -} diff --git a/src/Config/ConfigNotFoundProvider.php b/src/Config/ConfigNotFoundProvider.php index 42aaed33..e0b429c5 100644 --- a/src/Config/ConfigNotFoundProvider.php +++ b/src/Config/ConfigNotFoundProvider.php @@ -1,24 +1,26 @@ NotFoundFields::SHOW_IMAGE; - yield self::ID_IMAGE => 0; - yield self::TITLE => \esc_attr__( 'Nothing Found', 'italystrap' ); - yield self::CONTENT => \esc_attr__( - 'It seems we can’t find what you’re looking for. Perhaps searching can help.', - 'italystrap' - ); - } + public function __invoke(): iterable + { + yield self::SHOW_IMAGE => NotFoundFields::SHOW_IMAGE; + yield self::ID_IMAGE => 0; + yield self::TITLE => \esc_attr__('Nothing Found', 'italystrap'); + yield self::CONTENT => \esc_attr__( + 'It seems we can’t find what you’re looking for. Perhaps searching can help.', + 'italystrap' + ); + } } diff --git a/src/Config/ConfigPostThumbnailProvider.php b/src/Config/ConfigPostThumbnailProvider.php deleted file mode 100644 index 11bbe803..00000000 --- a/src/Config/ConfigPostThumbnailProvider.php +++ /dev/null @@ -1,94 +0,0 @@ - self::POST_THUMBNAIL_SIZE_DEFAULT; - yield self::POST_THUMBNAIL_ALIGNMENT => AlignmentKeys::ALIGN_FULL; - yield self::POST_CONTENT_WIDTH => $this->getContentWidth( - 1170, - 12, - 8, - 30 - ); - - yield ThumbnailsSubscriber::class => [ - 'navbar-brand-image' => [ - self::WIDTH => 45, - self::HEIGHT => 45, - self::CROP => true, - ], - - /** - * La full-width serve solo per la pagina omonima - * Si potrebbe invece settare "large" a 1140 (verificare se 1170 va bene) e risparmiare - * spazio avendo una immagine di meno poichè entrambe non vengono croppate - * "large" può essere settata anche con altezza a 9999 - */ - 'full-width' => [ - self::WIDTH => $container - $gutter, - self::HEIGHT => 9999, - self::CROP => false, - ], - 'one_half' => [ - self::WIDTH => $container / 2 - $gutter, - self::HEIGHT => ($container / 2 - $gutter) * 3 / 4, - self::CROP => true, - ], - 'one_third' => [ - self::WIDTH => $container / 3 - $gutter, - self::HEIGHT => ($container / 3 - $gutter) * 3 / 4, - self::CROP => true, - ], - 'one_fourth' => [ - self::WIDTH => $container / 4 - $gutter, - self::HEIGHT => ($container / 4 - $gutter) * 3 / 4, - self::CROP => true, - ], - 'one_six' => [ - self::WIDTH => $container / 6 - $gutter, - self::HEIGHT => ($container / 6 - $gutter) * 3 / 4, - self::CROP => true, - ], - ]; - } - - /** - * Get the content width - * - * @param int $container_width - * @param int $column - * @param int $content_column_width - * @param int $gutter - * @return int [description] - */ - private function getContentWidth( - int $container_width, - int $column, - int $content_column_width, - int $gutter = 0 - ): int { - return intval( $container_width / $column * $content_column_width - $gutter ); - } -} diff --git a/src/Config/ConfigPostTypeSupportProvider.php b/src/Config/ConfigPostTypeSupportProvider.php deleted file mode 100644 index c1971c1c..00000000 --- a/src/Config/ConfigPostTypeSupportProvider.php +++ /dev/null @@ -1,19 +0,0 @@ - [ - 'post' => [ 'post_navigation', 'entry-meta' ], - 'page' => [ 'post_navigation', 'entry-meta' ], - 'download' => [ 'post_navigation', 'entry-meta' ], - ], - ]; - } -} diff --git a/src/Config/ConfigProviderExtension.php b/src/Config/ConfigProviderExtension.php index 19881dbb..99372e4c 100644 --- a/src/Config/ConfigProviderExtension.php +++ b/src/Config/ConfigProviderExtension.php @@ -1,43 +1,40 @@ config = $config; - } - - /** - * @inheritDoc - */ - public function name(): string { - return self::class; - } - - /** - * @inheritDoc - */ - public function execute(AurynConfigInterface $application) { - $application->walk( self::class, [$this, 'walk'] ); - } - - public function walk( string $class, $index_or_optionName, Injector $injector ): void { - $config_object = $injector->share($class)->make($class); - if (\is_callable( $config_object )) { - $this->config->merge( $injector->execute( $config_object ) ); - } - } +class ConfigProviderExtension implements Extension +{ + private ConfigInterface $config; + + /** + * @param ConfigInterface $config + */ + public function __construct(ConfigInterface $config) + { + $this->config = $config; + } + + public function name(): string + { + return self::class; + } + + public function execute(AurynConfigInterface $application) + { + $application->walk(self::class, $this); + } + + public function __invoke(string $class, $index_or_optionName, Injector $injector): void + { + $config_object = $injector->share($class)->make($class); + if (\is_callable($config_object)) { + $this->config->merge($injector->execute($config_object)); + } + } } diff --git a/src/Config/ConfigSidebarProvider.php b/src/Config/ConfigSidebarProvider.php deleted file mode 100644 index c36d2fe4..00000000 --- a/src/Config/ConfigSidebarProvider.php +++ /dev/null @@ -1,58 +0,0 @@ - [ - self::SIDEBAR_PRIMARY => [ - S::NAME => \__( 'Sidebar', 'italystrap' ), - S::ID => 'sidebar-1', - ], - - self::FOOTER_BOX_1 => [ - S::NAME => \__( 'Footer Box 1', 'italystrap' ), - S::ID => 'footer-box-1', - S::DESCRIPTION => \__( 'Footer box 1 widget area.', 'italystrap' ), - ], - - self::FOOTER_BOX_2 => [ - S::NAME => \__( 'Footer Box 2', 'italystrap' ), - S::ID => 'footer-box-2', - S::DESCRIPTION => \__( 'Footer box 2 widget area.', 'italystrap' ), - ], - - self::FOOTER_BOX_3 => [ - S::NAME => \__( 'Footer Box 3', 'italystrap' ), - S::ID => 'footer-box-3', - S::DESCRIPTION => \__( 'Footer box 3 widget area.', 'italystrap' ), - ], - - self::FOOTER_BOX_4 => [ - S::NAME => \__( 'Footer Box 4', 'italystrap' ), - S::ID => 'footer-box-4', - S::DESCRIPTION => \__( 'Footer box 4 widget area.', 'italystrap' ), - ], - ], - ]; - } -} diff --git a/src/Config/ConfigSiteLogoProvider.php b/src/Config/ConfigSiteLogoProvider.php index e34d2e54..b2b00dc7 100644 --- a/src/Config/ConfigSiteLogoProvider.php +++ b/src/Config/ConfigSiteLogoProvider.php @@ -1,21 +1,23 @@ 'display_name'; - yield self::BRAND_IMAGE_ID => 0; - yield self::BRAND_IMAGE_SIZE => 'navbar-brand-image'; - yield self::BRAND_IMAGE_MOBILE => 0; - } + public function __invoke(): iterable + { + yield self::DISPLAY_NAVBAR_BRAND_IMAGE => 'display_name'; + yield self::BRAND_IMAGE_ID => 0; + yield self::BRAND_IMAGE_SIZE => 'navbar-brand-image'; + yield self::BRAND_IMAGE_MOBILE => 0; + } } diff --git a/src/Config/ConfigThemeModsProvider.php b/src/Config/ConfigThemeModsProvider.php index 9f44d8f0..4a0dea90 100644 --- a/src/Config/ConfigThemeModsProvider.php +++ b/src/Config/ConfigThemeModsProvider.php @@ -1,17 +1,20 @@ theme_mods = $theme_mods; - } + public function __construct(array $theme_mods) + { + $this->theme_mods = $theme_mods; + } - public function __invoke(): iterable { - return $this->theme_mods; - } + public function __invoke(): iterable + { + return $this->theme_mods; + } } diff --git a/src/Config/ConfigThemeProvider.php b/src/Config/ConfigThemeProvider.php deleted file mode 100644 index 25c398bf..00000000 --- a/src/Config/ConfigThemeProvider.php +++ /dev/null @@ -1,58 +0,0 @@ -theme = $theme; - $this->dispatcher = $dispatcher; - } - - public function __invoke(): iterable { -// 'ITALYSTRAP_THEME' => true, -// 'ITALYSTRAP_THEME_NAME' => wp_get_theme( $get_template )->display( 'Name' ), -// 'ITALYSTRAP_THEME_VERSION' => wp_get_theme( $get_template )->display( 'Version' ), -// 'ITALYSTRAP_THEME_AUTHOR' => wp_get_theme( $get_template )->display( 'Author', false ), -// 'ITALYSTRAP_CURRENT_THEME_NAME' => $current_theme_name, -// 'PREFIX' => $prefix, -// '_PREFIX' => '_' . $prefix, -// 'TEMPLATEURL' => get_template_directory_uri(), -// 'STYLESHEETURL' => get_stylesheet_directory_uri(), -// 'PARENTPATH' => get_template_directory(), -// 'CHILDPATH' => get_stylesheet_directory(), -// 'GET_BLOGINFO_NAME' => get_option( 'blogname' ), -// 'GET_BLOGINFO_DESCRIPTION' => get_option( 'blogdescription' ), -// 'HOME_URL' => get_home_url( null, '/' ), -// 'PAGE_ON_FRONT' => absint( get_option( 'page_on_front' ) ), -// 'PAGE_FOR_POSTS' => absint( get_option( 'page_for_posts' ) ), - - yield self::THEME_NAME => (string)$this->theme->display( 'Name' ); - yield self::THEME_VERSION => (string)$this->theme->display( 'Version' ); - yield self::THEME_AUTHOR => (string)$this->theme->display( 'Author' ); - yield self::TEMPLATE_DIR_URI => $this->theme->get_template_directory_uri(); - yield self::STYLESHEET_DIR_URI => $this->theme->get_stylesheet_directory_uri(); - yield self::TEMPLATE_DIR => $this->theme->get_template_directory(); - yield self::STYLESHEET_DIR => $this->theme->get_stylesheet_directory(); - yield self::THEME_BETA => false; - yield self::VIEW_DIR => (string) $this->dispatcher->filter( 'italystrap_template_dir', 'templates' ); - yield self::PREFIX => \strtolower( (string)$this->theme->display( 'Name' ) ); - } -} diff --git a/src/Config/ConfigThemeSupportProvider.php b/src/Config/ConfigThemeSupportProvider.php deleted file mode 100644 index 4ae82f42..00000000 --- a/src/Config/ConfigThemeSupportProvider.php +++ /dev/null @@ -1,361 +0,0 @@ -config = $config; - } - - public function __invoke(): iterable { - $logo_size_name_registered = (string)$this->config->get(ConfigSiteLogoProvider::BRAND_IMAGE_SIZE); - - yield SupportSubscriber::class => [ - /** - * Add default posts and comments RSS feed links to head. - */ - 'automatic-feed-links', - - /** - * Enable support for Post Thumbnails on posts, pages and archives template. - * @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails - */ - 'post-thumbnails', - - /** - * Switch default core markup for search form, comment form, and comments - * to output valid HTML5. - */ - 'html5' => [ - 'search-form', - 'comment-form', - 'comment-list', - 'gallery', - 'caption', - 'script', - ], - - /** - * Enable support for title-tag. - */ - 'title-tag', - - /** - * Enable support for Post Formats. - * See http://codex.wordpress.org/Post_Formats - * - * @var array - */ - 'post-formats' => [ - 'aside', - 'image', - 'gallery', - 'link', - 'quote', - 'status', - 'video', - 'audio', - 'chat', - ], - - /** - * Custom header value array - * Some ideas for default images https://unsplash.it/ - * - * @var array - */ - self::CUSTOM_HEADER => [ - 'default-image' => '', - 'width' => 1140, - 'height' => 200, - 'flex-height' => true, - 'flex-width' => true, - 'uploads' => true, - 'random-default' => false, - 'header-text' => true, - 'default-text-color' => '000', - 'wp-head-callback' => '', - 'admin-head-callback' => '', - 'admin-preview-callback' => '', - 'video' => true, - ], - - self::CUSTOM_LOGO => [ - 'width' => (int)$this->config->get( - ThumbnailsSubscriber::class . ".$logo_size_name_registered.width" - ), - 'height' => (int)$this->config->get( - ThumbnailsSubscriber::class . ".$logo_size_name_registered.height" - ), - 'flex-height' => true, - 'flex-width' => true, - 'header-text' => ['site-title', 'site-description'], - 'unlink-homepage-logo' => true, - ], - - /** - * Custom background support - * - * @link http://codex.wordpress.org/Custom_Backgrounds - * @var array - * $defaults = array( - * 'default-image' => '', - * 'default-repeat' => 'repeat', - * 'default-position-x' => 'left', - * 'default-attachment' => 'scroll', - * 'default-color' => '', - * 'wp-head-callback' => '_custom_background_cb', - * 'admin-head-callback' => '', - * 'admin-preview-callback' => '', - * ); - * - * 'wp-head-callback' => null In case is printed from Theme customizer - */ - 'custom-background' => \apply_filters( 'custom_background_support', [] ), - - /** - * @since 4.5 WordPress Core - * @see https://make.wordpress.org/core/2016/03/22/implementing-selective-refresh-support-for-widgets/ - */ - 'customize-selective-refresh-widgets', - - /** - * Add support for the builtin breadcrumbs - */ - 'breadcrumbs', - - /** - * Define and register starter content to showcase the theme on new sites. - * @see twentyseventeen - * @link https://make.wordpress.org/core/2016/11/30/starter-content-for-themes-in-4-7/ - * @link https://roots.io/using-and-customizing-wordpress-starter-content/ - * - * @link https://gist.github.com/igorbenic/10d22c620fc264aac674f17fbfd07750 - * - * @var array - */ - 'starter-content' => [ - 'widgets' => [ - // Place three core-defined widgets in the sidebar area. - 'sidebar-1' => [ - 'text_business_info', - 'search', - 'text_about', - 'italystrap_posts', - // 'text_test' => array( - // 'text' => array( - // 'title' => 'Title test' - // ), - // ), - ], - - // Add the core-defined business info widget to the footer 1 area. - 'footer-box-1' => [ - 'text_business_info', - ], - - // Put two core-defined widgets in the footer 2 area. - 'footer-box-2' => [ - 'text_about', - 'search', - ], - ], - - // Specify the core-defined pages to create and add custom thumbnails to some of them. - 'posts' => [ - 'home', - 'about' => [ - 'thumbnail' => '{{image-sandwich}}', - ], - 'contact' => [ - 'thumbnail' => '{{image-default}}', - ], - 'test' => [ - 'thumbnail' => '{{image-default}}', - 'post_content' => 'POST CONTENT', - ], - 'blog' => [ - 'thumbnail' => '{{image-coffee}}', - ], - 'homepage-section' => [ - 'thumbnail' => '{{image-default}}', - ], - ], - - // Create the custom image attachments used as post thumbnails for pages. - 'attachments' => [ - 'image-default' => [ - 'post_title' => _x( 'Default', 'Theme starter content', 'italystrap' ), - 'file' => 'assets/img/italystrap-default-image.png', // URL relative to the template directory. - ], - 'image-sandwich' => [ - 'post_title' => _x( 'Sandwich', 'Theme starter content', 'italystrap' ), - 'file' => 'img/images/sandwich.jpg', - ], - 'image-coffee' => [ - 'post_title' => _x( 'Coffee', 'Theme starter content', 'italystrap' ), - 'file' => 'img/images/coffee.jpg', - ], - ], - - // Default to a static front page and assign the front and posts pages. - 'options' => [ - 'show_on_front' => 'page', - 'page_on_front' => '{{home}}', - 'page_for_posts' => '{{blog}}', - ], - - // Set the front page section theme mods to the IDs of the core-registered pages. - 'theme_mods' => [ - 'panel_1' => '{{homepage-section}}', - 'panel_2' => '{{about}}', - 'panel_3' => '{{blog}}', - 'panel_4' => '{{contact}}', - ], - - // Set up nav menus for each of the two areas registered in the theme. - 'nav_menus' => [ - // Assign a menu to the "top" location. - 'info-menu' => [ - 'name' => __( 'Info Menu', 'italystrap' ), - 'items' => [ - 'link_home', // Note that the core "home" page is actually a - //link in case a static front page is not used. - 'page_about', - 'page_blog', - 'page_contact', - ], - ], - - // Assign a menu to the "social" location. - 'social-menu' => [ - 'name' => __( 'Social Links Menu', 'italystrap' ), - 'items' => [ - 'link_yelp', - 'link_facebook', - 'link_twitter', - 'link_instagram', - 'link_email', - 'link_test', - ], - ], - - // Assign a menu to the "social" location. - 'main-menu' => [ - 'name' => __( 'Main Menu', 'italystrap' ), - 'items' => [ - 'link_home', // Note that the core "home" page is actually a - //link in case a static front page is not used. - 'page_about', - 'page_blog', - 'page_contact', - 'page_test', - ], - ], - ], - ], - - /** ================================= - * Theme support for Gutenberg editor - * - * https://wordpress.org/gutenberg/handbook/designers-developers/developers/themes/theme-support/ - * - * @since WordPress 5.0 - ===================================*/ - - // 'editor-font-sizes' => [ - // [ - // 'name' => __( 'Extra Small', 'italystrap' ), - // 'shortName' => __( 'XS', 'italystrap' ), - // 'size' => ceil( $font_size_base * 0.75 ), - // 'slug' => 'extra-small', - // ], - // [ - // 'name' => __( 'Small', 'italystrap' ), - // 'shortName' => __( 'S', 'italystrap' ), - // 'size' => ceil( $font_size_base * 0.85 ), - // 'slug' => 'small', - // ], - // [ - // 'name' => __( 'Normal', 'italystrap' ), - // 'shortName' => __( 'M', 'italystrap' ), - // 'size' => $font_size_base, - // 'slug' => 'normal', - // ], - // [ - // 'name' => __( 'Large', 'italystrap' ), - // 'shortName' => __( 'L', 'italystrap' ), - // 'size' => ceil( $font_size_base * 1.25 ), - // // 'unit' => 'rem', - // 'slug' => 'large', - // ], - // [ - // 'name' => __( 'Huge', 'italystrap' ), - // 'shortName' => __( 'XL', 'italystrap' ), - // 'size' => ceil( $font_size_base * 1.7 ), - // 'slug' => 'huge', - // ], - // [ - // 'name' => __( 'Extra Huge', 'italystrap' ), - // 'shortName' => __( 'XXL', 'italystrap' ), - // 'size' => ceil( $font_size_base * 2.15 ), - // 'slug' => 'extra-huge', - // ], - // [ - // 'name' => __( 'H1', 'italystrap' ), - // 'shortName' => __( 'H1', 'italystrap' ), - // 'size' => ceil( $font_size_base * 2.6 ), - // 'slug' => 'h1', - // ], - // ], - - /** - * If the theme support align-wide then activate it - */ - 'align-wide', - - /** - * Support for Gutenberg editor style - * Then make sure you are loading the editor-style.css - */ - 'editor-styles', - - /** - * If the theme has dark background then activate it - */ - // 'dark-editor-style', - - /** - * This will add: - *
...
- * - * @link https://wordpress.org/gutenberg/handbook/designers-developers/developers/themes/theme-support/#responsive-embedded-content - * @TODO - */ - 'responsive-embeds', - - /** - * https://wordpress.org/support/topic/wp-block-styles/ - * Some blocks in Gutenberg like tables, quotes, separator benefit from structural styles - * (margin, padding, border etc…) - * They are applied visually only in the editor (back-end) but not on the front-end - * to avoid the risk of conflicts with the styles wanted in the theme. - * If you want to display them on front to have a base to work with, in this case, - * you can add support for wp-block-styles. - * You can consult Matias Ventura’s tickets to keep you informed about Gutenberg developments: - * https://make.wordpress.org/core/2018/06/05/whats-new-in-gutenberg-5th-june/ - */ - 'wp-block-styles', - ]; - } -} diff --git a/src/Config/ConfigWpSubscriber.php b/src/Config/ConfigWpSubscriber.php deleted file mode 100644 index f7ab0653..00000000 --- a/src/Config/ConfigWpSubscriber.php +++ /dev/null @@ -1,77 +0,0 @@ - [ - self::CALLBACK => self::REGISTER_CB, - self::PRIORITY => PHP_INT_MIN, - ]; - } - - /** - * Init sidebars registration - */ - public function __construct( - ConfigInterface $config, - \WP_Query $query - ) { - $this->config = $config; - $this->query = $query; - } - - public function register(): void { - $id = $this->query->get_queried_object_id(); - - if ( is_singular() ) { - $this->config->add( - ConfigLayoutProvider::POST_CONTENT_TEMPLATE, - (array) get_post_meta( $id, '_italystrap_template_settings', true ) - ); - } else { - $this->config->add( - ConfigLayoutProvider::POST_CONTENT_TEMPLATE, - explode( - ',', - is_array( $this->config->get( ConfigLayoutProvider::POST_CONTENT_TEMPLATE ) ) - ? $this->config->get( ConfigLayoutProvider::POST_CONTENT_TEMPLATE )[0] - : $this->config->get( ConfigLayoutProvider::POST_CONTENT_TEMPLATE ) - ) - ); - } - - /** - * If in page settings are set then override the global settings for the layout. - */ - if ( $page_layout = (string) get_post_meta( $id, '_italystrap_layout_settings', true ) ) { - $this->config->add( ConfigLayoutProvider::SITE_LAYOUT, $page_layout ); - } - - /** - * If in page settings are set then override the global settings for the layout. - */ - if ( $container_width = (string) get_post_meta( $id, '_italystrap_width_settings', true ) ) { - $this->config->add( ConfigLayoutProvider::CONTAINER_WIDTH, $container_width ); - } - - $array = [ - self::CURRENT_PAGE_ID => $id, - ]; - - $this->config->merge($array); - } -} diff --git a/src/Config/TemplatePositionTrait.php b/src/Config/TemplatePositionTrait.php index 88e5cd4b..7115ee16 100644 --- a/src/Config/TemplatePositionTrait.php +++ b/src/Config/TemplatePositionTrait.php @@ -1,40 +1,42 @@ dispatcher->filter( - 'italystrap_template_positions_trait', - [ - 'italystrap_before' => \__( 'After the </body>', 'italystrap' ), +trait TemplatePositionTrait +{ + private function getAllPosition(): iterable + { + return (array)$this->dispatcher->filter( + 'italystrap_template_positions_trait', + [ + 'italystrap_before' => \__('After the </body>', 'italystrap'), - 'italystrap_before_header' => \__( 'Before the header', 'italystrap' ), - 'italystrap_content_header' => \__( 'The content header', 'italystrap' ), - 'italystrap_after_header' => \__( 'After the header', 'italystrap' ), + 'italystrap_before_header' => \__('Before the header', 'italystrap'), + 'italystrap_content_header' => \__('The content header', 'italystrap'), + 'italystrap_after_header' => \__('After the header', 'italystrap'), - 'italystrap_before_main' => \__( 'Before the Main Content', 'italystrap' ), + 'italystrap_before_main' => \__('Before the Main Content', 'italystrap'), - 'italystrap_before_content' => \__( 'Before the Content', 'italystrap' ), + 'italystrap_before_content' => \__('Before the Content', 'italystrap'), - 'italystrap_before_loop' => \__( 'Before the Loop', 'italystrap' ), - 'italystrap_loop' => \__( 'The Loop', 'italystrap' ), - 'italystrap_after_loop' => \__( 'After the Loop', 'italystrap' ), + 'italystrap_before_loop' => \__('Before the Loop', 'italystrap'), + 'italystrap_loop' => \__('The Loop', 'italystrap'), + 'italystrap_after_loop' => \__('After the Loop', 'italystrap'), - 'italystrap_after_content' => \__( 'After the Content', 'italystrap' ), + 'italystrap_after_content' => \__('After the Content', 'italystrap'), - 'italystrap_after_main' => \__( 'After the Main Content', 'italystrap' ), + 'italystrap_after_main' => \__('After the Main Content', 'italystrap'), - 'italystrap_before_footer' => \__( 'In the footer open', 'italystrap' ), - 'italystrap_footer' => \__( 'In the footer', 'italystrap' ), - 'italystrap_after_footer' => \__( 'In the footer closed', 'italystrap' ), + 'italystrap_before_footer' => \__('In the footer open', 'italystrap'), + 'italystrap_footer' => \__('In the footer', 'italystrap'), + 'italystrap_after_footer' => \__('In the footer closed', 'italystrap'), // phpcs:disable 'italystrap_after' => \__( 'At the end of the page before the </body>', 'italystrap' ), // phpcs:enable - ] - ); - } + ] + ); + } } diff --git a/src/Customizer/BetaFields.php b/src/Customizer/BetaFields.php index 39751c07..5a0ad21e 100644 --- a/src/Customizer/BetaFields.php +++ b/src/Customizer/BetaFields.php @@ -1,59 +1,61 @@ manager = $manager; - $this->config = $config; - } - - public function __invoke(): void { - $prefix = $this->config->get(ConfigThemeProvider::PREFIX); - $id_beta = 'beta'; - - $this->manager->add_section( - $id_beta, - [ - 'title' => \__( 'Beta version', 'italystrap' ), - 'panel' => PanelFields::class, - 'priority' => 160, - ] - ); - - $this->manager->add_setting( - $id_beta, - [ - 'default' => $this->config->get($id_beta), - 'type' => 'theme_mod', - 'transport' => 'postMessage', - 'sanitize_callback' => 'wp_kses_post', - ] - ); - - $this->manager->add_control( - "{$prefix}_{$id_beta}", - [ - 'label' => __( 'Beta version', 'italystrap' ), - 'description' => __( 'Only if you want use some beta stuff', 'italystrap' ), - 'section' => self::SECTION, - 'settings' => $id_beta, - 'priority' => 10, - 'type' => 'checkbox', - ] - ); - } +use ItalyStrap\Theme\Infrastructure\Config\ConfigThemeProvider; + +class BetaFields +{ + public const SECTION = 'beta'; + + private \WP_Customize_Manager $manager; + private ConfigInterface $config; + + public function __construct( + \WP_Customize_Manager $manager, + ConfigInterface $config + ) { + $this->manager = $manager; + $this->config = $config; + } + + public function __invoke(): void + { + $prefix = $this->config->get(ConfigThemeProvider::PREFIX); + $id_beta = 'beta'; + + $this->manager->add_section( + $id_beta, + [ + 'title' => \__('Beta version', 'italystrap'), + 'panel' => PanelFields::class, + 'priority' => 160, + ] + ); + + $this->manager->add_setting( + $id_beta, + [ + 'default' => $this->config->get($id_beta), + 'type' => 'theme_mod', + 'transport' => 'postMessage', + 'sanitize_callback' => 'wp_kses_post', + ] + ); + + $this->manager->add_control( + "{$prefix}_{$id_beta}", + [ + 'label' => __('Beta version', 'italystrap'), + 'description' => __('Only if you want use some beta stuff', 'italystrap'), + 'section' => self::SECTION, + 'settings' => $id_beta, + 'priority' => 10, + 'type' => 'checkbox', + ] + ); + } } diff --git a/src/Customizer/BreadcrumsFields.php b/src/Customizer/BreadcrumsFields.php index fe2d1959..a7d74688 100644 --- a/src/Customizer/BreadcrumsFields.php +++ b/src/Customizer/BreadcrumsFields.php @@ -1,76 +1,78 @@ manager = $manager; - $this->control = $control; - $this->theme = $theme; - } + public function __construct( + \WP_Customize_Manager $manager, + FieldControlFactory $control, + \WP_Theme $theme + ) { + $this->manager = $manager; + $this->control = $control; + $this->theme = $theme; + } - public function __invoke(): void { + public function __invoke(): void + { - if ( ! class_exists( '\ItalyStrap\Customizer\Control\Multicheck' ) ) { - return; - } + if (! class_exists('\ItalyStrap\Customizer\Control\Multicheck')) { + return; + } - $id = 'italystrap'; + $id = 'italystrap'; - $this->manager->add_section( - self::class, - [ - 'title' => \__( 'Breadcrumbs', 'italystrap' ), - 'panel' => PanelFields::class, - 'description' => \__( 'Allows you to show the breadcrumbs on selected templates.', 'italystrap' ), - ] - ); + $this->manager->add_section( + self::class, + [ + 'title' => \__('Breadcrumbs', 'italystrap'), + 'panel' => PanelFields::class, + 'description' => \__('Allows you to show the breadcrumbs on selected templates.', 'italystrap'), + ] + ); - $id_breadcrumbs = 'breadcrumbs_show_on'; - $this->manager->add_setting( - $id_breadcrumbs, - [ - 'type' => 'theme_mod', - 'transport' => 'postMessage', - 'sanitize_callback' => 'sanitize_text_field', - ] - ); + $id_breadcrumbs = 'breadcrumbs_show_on'; + $this->manager->add_setting( + $id_breadcrumbs, + [ + 'type' => 'theme_mod', + 'transport' => 'postMessage', + 'sanitize_callback' => 'sanitize_text_field', + ] + ); - $this->manager->add_control( - $this->control->make( - '\ItalyStrap\Customizer\Control\Multicheck', - $this->manager, - "{$id}_{$id_breadcrumbs}", - [ - 'label' => \__( 'Display breadcrumbs on', 'italystrap' ), - 'section' => self::class, - 'type' => 'multicheck', - 'settings' => $id_breadcrumbs, - 'choices' => \array_merge( - [ - '404.php' => \__( '404', 'italystrap' ), - 'archive.php' => \__( 'Archive', 'italystrap' ), - 'author.php' => \__( 'Author', 'italystrap' ), - 'front-page.php' => \__( 'Front page', 'italystrap' ), - 'home.php' => \__( 'Home', 'italystrap' ), - 'page.php' => \__( 'Page', 'italystrap' ), - 'search.php' => \__( 'Search', 'italystrap' ), - 'single.php' => \__( 'Single', 'italystrap' ), - ], - $this->theme->get_page_templates() - ), - ] - ) - ); - } + $this->manager->add_control( + $this->control->make( + '\ItalyStrap\Customizer\Control\Multicheck', + $this->manager, + "{$id}_{$id_breadcrumbs}", + [ + 'label' => \__('Display breadcrumbs on', 'italystrap'), + 'section' => self::class, + 'type' => 'multicheck', + 'settings' => $id_breadcrumbs, + 'choices' => \array_merge( + [ + '404.php' => \__('404', 'italystrap'), + 'archive.php' => \__('Archive', 'italystrap'), + 'author.php' => \__('Author', 'italystrap'), + 'front-page.php' => \__('Front page', 'italystrap'), + 'home.php' => \__('Home', 'italystrap'), + 'page.php' => \__('Page', 'italystrap'), + 'search.php' => \__('Search', 'italystrap'), + 'single.php' => \__('Single', 'italystrap'), + ], + $this->theme->get_page_templates() + ), + ] + ) + ); + } } diff --git a/src/Customizer/BuildThumbnailSizeChoicesTrait.php b/src/Customizer/BuildThumbnailSizeChoicesTrait.php index e0a163a6..1bbf32bc 100644 --- a/src/Customizer/BuildThumbnailSizeChoicesTrait.php +++ b/src/Customizer/BuildThumbnailSizeChoicesTrait.php @@ -1,27 +1,29 @@ dispatcher->filter( 'image_size_names_choose', [ - '' => \__('Select dimension', 'italystrap'), - ] ); +trait BuildThumbnailSizeChoicesTrait +{ + private function buildSizeChoices() + { + $size_choices = $this->dispatcher->filter('image_size_names_choose', [ + '' => \__('Select dimension', 'italystrap'), + ]); - foreach ( $this->config->get(ThumbnailsSubscriber::class) as $name => $size ) { - $size_choices[$name] = \sprintf( - '%s %sx%spx', - $name, - $size[ ConfigPostThumbnailProvider::WIDTH ], - $size[ ConfigPostThumbnailProvider::HEIGHT ] - ); - } + foreach ($this->config->get(ThumbnailsSubscriber::class) as $name => $size) { + $size_choices[$name] = \sprintf( + '%s %sx%spx', + $name, + $size[ ConfigPostThumbnailProvider::WIDTH ], + $size[ ConfigPostThumbnailProvider::HEIGHT ] + ); + } - return $size_choices; - } + return $size_choices; + } } diff --git a/src/Customizer/ColophonFields.php b/src/Customizer/ColophonFields.php index 242d0863..e74ac751 100644 --- a/src/Customizer/ColophonFields.php +++ b/src/Customizer/ColophonFields.php @@ -1,4 +1,5 @@ manager = $manager; - $this->config = $config; - $this->dispatcher = $dispatcher; - } + public function __construct( + \WP_Customize_Manager $manager, + ConfigInterface $config, + EventDispatcherInterface $dispatcher + ) { + $this->manager = $manager; + $this->config = $config; + $this->dispatcher = $dispatcher; + } - public function __invoke(): void { - $this->manager->add_section( - self::class, - [ - 'title' => \__( 'Footer\'s Colophon', 'italystrap' ), - 'description' => \__( 'Add text for footer\'s colophon here', 'italystrap' ), - 'panel' => PanelFields::class, - 'priority' => 160, - 'theme_supports' => '', - ] - ); + public function __invoke(): void + { + $this->manager->add_section( + self::class, + [ + 'title' => \__('Footer\'s Colophon', 'italystrap'), + 'description' => \__('Add text for footer\'s colophon here', 'italystrap'), + 'panel' => PanelFields::class, + 'priority' => 160, + 'theme_supports' => '', + ] + ); - $this->manager->add_setting( - ConfigColophonProvider::COLOPHON, - [ - 'default' => (string)$this->config->get( ConfigColophonProvider::COLOPHON, '' ), - 'type' => 'theme_mod', - 'transport' => 'postMessage', - 'sanitize_callback' => 'wp_kses_post', - ] - ); + $this->manager->add_setting( + ConfigColophonProvider::COLOPHON, + [ + 'default' => (string)$this->config->get(ConfigColophonProvider::COLOPHON, ''), + 'type' => 'theme_mod', + 'transport' => 'postMessage', + 'sanitize_callback' => 'wp_kses_post', + ] + ); - $this->manager->add_control( - ConfigColophonProvider::COLOPHON, - [ - 'label' => \__( 'Footer\'s Colophon', 'italystrap' ), - 'description' => \__( 'Add text for footer\'s colophon here', 'italystrap' ), - 'section' => self::class, - 'settings' => ConfigColophonProvider::COLOPHON, - 'priority' => 10, - 'type' => 'textarea', - ] - ); + $this->manager->add_control( + ConfigColophonProvider::COLOPHON, + [ + 'label' => \__('Footer\'s Colophon', 'italystrap'), + 'description' => \__('Add text for footer\'s colophon here', 'italystrap'), + 'section' => self::class, + 'settings' => ConfigColophonProvider::COLOPHON, + 'priority' => 10, + 'type' => 'textarea', + ] + ); - $this->manager->add_setting( - ConfigColophonProvider::COLOPHON_ACTION, - [ - 'default' => (string)$this->config->get( ConfigColophonProvider::COLOPHON_ACTION ), - 'type' => 'theme_mod', - 'transport' => 'refresh', - 'sanitize_callback' => 'sanitize_text_field', - ] - ); + $this->manager->add_setting( + ConfigColophonProvider::COLOPHON_ACTION, + [ + 'default' => (string)$this->config->get(ConfigColophonProvider::COLOPHON_ACTION), + 'type' => 'theme_mod', + 'transport' => 'refresh', + 'sanitize_callback' => 'sanitize_text_field', + ] + ); - $this->manager->add_control( - ConfigColophonProvider::COLOPHON_ACTION, - [ - 'label' => \__( 'Footer\'s Colophon Position', 'italystrap' ), - 'description' => \__( 'Add text for footer\'s colophon here', 'italystrap' ), - 'section' => self::class, - 'settings' => ConfigColophonProvider::COLOPHON_ACTION, - 'priority' => 10, - 'type' => 'select', - 'choices' => $this->getAllPosition(), - ] - ); + $this->manager->add_control( + ConfigColophonProvider::COLOPHON_ACTION, + [ + 'label' => \__('Footer\'s Colophon Position', 'italystrap'), + 'description' => \__('Add text for footer\'s colophon here', 'italystrap'), + 'section' => self::class, + 'settings' => ConfigColophonProvider::COLOPHON_ACTION, + 'priority' => 10, + 'type' => 'select', + 'choices' => $this->getAllPosition(), + ] + ); - $this->manager->add_setting( - ConfigColophonProvider::COLOPHON_PRIORITY, - [ - 'default' => (int)$this->config->get( ConfigColophonProvider::COLOPHON_PRIORITY ), - 'type' => 'theme_mod', - 'transport' => 'refresh', - 'sanitize_callback' => 'sanitize_text_field', - ] - ); + $this->manager->add_setting( + ConfigColophonProvider::COLOPHON_PRIORITY, + [ + 'default' => (int)$this->config->get(ConfigColophonProvider::COLOPHON_PRIORITY), + 'type' => 'theme_mod', + 'transport' => 'refresh', + 'sanitize_callback' => 'sanitize_text_field', + ] + ); - $this->manager->add_control( - ConfigColophonProvider::COLOPHON_PRIORITY, - [ - 'label' => \__( 'Footer\'s Colophon Position', 'italystrap' ), - 'description' => \__( 'Add text for footer\'s colophon here', 'italystrap' ), - 'section' => self::class, - 'settings' => ConfigColophonProvider::COLOPHON_PRIORITY, - 'priority' => 10, - 'type' => 'number', - ] - ); - } + $this->manager->add_control( + ConfigColophonProvider::COLOPHON_PRIORITY, + [ + 'label' => \__('Footer\'s Colophon Position', 'italystrap'), + 'description' => \__('Add text for footer\'s colophon here', 'italystrap'), + 'section' => self::class, + 'settings' => ConfigColophonProvider::COLOPHON_PRIORITY, + 'priority' => 10, + 'type' => 'number', + ] + ); + } } diff --git a/src/Customizer/ColorFields.php b/src/Customizer/ColorFields.php index 398c2229..4a317617 100644 --- a/src/Customizer/ColorFields.php +++ b/src/Customizer/ColorFields.php @@ -1,85 +1,87 @@ manager = $manager; - $this->config = $config; - $this->control = $control; - } + public function __construct( + \WP_Customize_Manager $manager, + ConfigInterface $config, + FieldControlFactory $control + ) { + $this->manager = $manager; + $this->config = $config; + $this->control = $control; + } - public function __invoke(): void { - $this->manager->get_setting( ConfigColorSectionProvider::HEADER_COLOR )->transport = 'postMessage'; - $this->manager->get_setting( ConfigColorSectionProvider::BG_COLOR )->transport = 'postMessage'; - $this->manager->get_section( self::SECTION )->title = \__( 'Theme Colors', 'italystrap' ); + public function __invoke(): void + { + $this->manager->get_setting(ConfigColorSectionProvider::HEADER_COLOR)->transport = 'postMessage'; + $this->manager->get_setting(ConfigColorSectionProvider::BG_COLOR)->transport = 'postMessage'; + $this->manager->get_section(self::SECTION)->title = \__('Theme Colors', 'italystrap'); - $id_link_color = ConfigColorSectionProvider::LINK_COLOR; - $prefix = $this->config->get(ConfigThemeProvider::PREFIX); + $id_link_color = ConfigColorSectionProvider::LINK_COLOR; + $prefix = $this->config->get(ConfigThemeProvider::PREFIX); - $this->manager->add_setting( - $id_link_color, - [ - 'default' => $this->config->get($id_link_color), - 'type' => 'theme_mod', - 'transport' => 'postMessage', - 'sanitize_callback' => 'sanitize_hex_color', - ] - ); + $this->manager->add_setting( + $id_link_color, + [ + 'default' => $this->config->get($id_link_color), + 'type' => 'theme_mod', + 'transport' => 'postMessage', + 'sanitize_callback' => 'sanitize_hex_color', + ] + ); - $this->manager->add_control( - $this->control->make( - \WP_Customize_Color_Control::class, - $this->manager, - "{$prefix}_{$id_link_color}", - [ - 'label' => \__( 'Link Color', 'italystrap' ), - 'section' => self::SECTION, - 'settings' => $id_link_color, - 'priority' => 10, - ] - ) - ); + $this->manager->add_control( + $this->control->make( + \WP_Customize_Color_Control::class, + $this->manager, + "{$prefix}_{$id_link_color}", + [ + 'label' => \__('Link Color', 'italystrap'), + 'section' => self::SECTION, + 'settings' => $id_link_color, + 'priority' => 10, + ] + ) + ); - $id_hx_color = ConfigColorSectionProvider::HX_COLOR; - $this->manager->add_setting( - $id_hx_color, - [ - 'default' => $this->config->get($id_hx_color), - 'type' => 'theme_mod', - 'transport' => 'postMessage', - 'sanitize_callback' => 'sanitize_hex_color', - ] - ); + $id_hx_color = ConfigColorSectionProvider::HX_COLOR; + $this->manager->add_setting( + $id_hx_color, + [ + 'default' => $this->config->get($id_hx_color), + 'type' => 'theme_mod', + 'transport' => 'postMessage', + 'sanitize_callback' => 'sanitize_hex_color', + ] + ); - $this->manager->add_control( - $this->control->make( - \WP_Customize_Color_Control::class, - $this->manager, - "{$prefix}_{$id_hx_color}", - [ - 'label' => \__( 'Heading Color', 'italystrap' ), - 'section' => self::SECTION, - 'settings' => $id_hx_color, - 'priority' => 10, - ] - ) - ); - } + $this->manager->add_control( + $this->control->make( + \WP_Customize_Color_Control::class, + $this->manager, + "{$prefix}_{$id_hx_color}", + [ + 'label' => \__('Heading Color', 'italystrap'), + 'section' => self::SECTION, + 'settings' => $id_hx_color, + 'priority' => 10, + ] + ) + ); + } } diff --git a/src/Customizer/Control/Checkbox.php b/src/Customizer/Control/Checkbox.php index 9f0aab90..a34d9832 100644 --- a/src/Customizer/Control/Checkbox.php +++ b/src/Customizer/Control/Checkbox.php @@ -1,4 +1,5 @@ - - link(); ?> value="value() ); ?>" /> - + + link(); ?> value="value()); ?>" /> + - - + + manager = $manager; - $this->config = $config; - $this->control = $control; - $this->theme = $theme; - } + public function __construct( + \WP_Customize_Manager $manager, + ConfigInterface $config, + FieldControlFactory $control, + \WP_Theme $theme + ) { + $this->manager = $manager; + $this->config = $config; + $this->control = $control; + $this->theme = $theme; + } - public function __invoke(): void { + public function __invoke(): void + { - $custom_css = $this->config->get('custom_css'); - if ( ! empty( $custom_css ) ) { - $custom_css = \strip_tags($custom_css); - /** @var WP_Post|WP_Error Post on success, error on failure. $post */ - $post = \wp_update_custom_css_post($custom_css); - $this->assertValueIsSaved($post); - \remove_theme_mod('custom_css'); - \set_theme_mod(self::class, true); - return; - } + $custom_css = $this->config->get('custom_css'); + if (! empty($custom_css)) { + $custom_css = \strip_tags($custom_css); + /** @var WP_Post|WP_Error Post on success, error on failure. $post */ + $post = \wp_update_custom_css_post($custom_css); + $this->assertValueIsSaved($post); + \remove_theme_mod('custom_css'); + \set_theme_mod(self::class, true); + return; + } - if ((bool)$this->config->get(self::class, false)) { - return; - } + if ((bool)$this->config->get(self::class, false)) { + return; + } - $this->manager->add_section( - self::class, - [ - 'title' => \__( 'Additional CSS', 'italystrap' ), - 'description' => \__( 'Add custom CSS here', 'italystrap' ), - 'panel' => PanelFields::class, - 'theme_supports' => '', - ] - ); + $this->manager->add_section( + self::class, + [ + 'title' => \__('Additional CSS', 'italystrap'), + 'description' => \__('Add custom CSS here', 'italystrap'), + 'panel' => PanelFields::class, + 'theme_supports' => '', + ] + ); - $id_custom_css = 'custom_css'; - $this->manager->add_setting( - $id_custom_css, - [ - 'default' => (string)$this->config->get('custom_css'), - 'type' => 'theme_mod', - 'transport' => 'refresh', - 'sanitize_callback' => 'sanitize_text_field', - ] - ); + $id_custom_css = 'custom_css'; + $this->manager->add_setting( + $id_custom_css, + [ + 'default' => (string)$this->config->get('custom_css'), + 'type' => 'theme_mod', + 'transport' => 'refresh', + 'sanitize_callback' => 'sanitize_text_field', + ] + ); - $this->manager->add_control( - $this->control->make( - Textarea::class, - $this->manager, - $id_custom_css, - [ - 'label' => \__( 'Custom CSS', 'italystrap' ), - 'description' => \__( 'Insert here your custom CSS', 'italystrap' ), - 'section' => self::class, - 'settings' => $id_custom_css, - ] - ) - ); - } + $this->manager->add_control( + $this->control->make( + Textarea::class, + $this->manager, + $id_custom_css, + [ + 'label' => \__('Custom CSS', 'italystrap'), + 'description' => \__('Insert here your custom CSS', 'italystrap'), + 'section' => self::class, + 'settings' => $id_custom_css, + ] + ) + ); + } - /** - * @param WP_Post|WP_Error $post - */ - private function assertValueIsSaved($post): void { - if ( ! $post instanceof \WP_Error) { - return; - } + /** + * @param WP_Post|WP_Error $post + */ + private function assertValueIsSaved($post): void + { + if (! $post instanceof \WP_Error) { + return; + } - throw new \RuntimeException($post->get_error_message(), $post->get_error_code()); - } + throw new \RuntimeException($post->get_error_message(), $post->get_error_code()); + } } diff --git a/src/Customizer/CustomHeaderFields.php b/src/Customizer/CustomHeaderFields.php index 18f92cea..e8417fc7 100644 --- a/src/Customizer/CustomHeaderFields.php +++ b/src/Customizer/CustomHeaderFields.php @@ -1,4 +1,5 @@ manager = $manager; - $this->config = $config; - $this->dispatcher = $dispatcher; - } + public function __construct( + \WP_Customize_Manager $manager, + ConfigInterface $config, + EventDispatcherInterface $dispatcher + ) { + $this->manager = $manager; + $this->config = $config; + $this->dispatcher = $dispatcher; + } - public function __invoke(): void { - $prefix = $this->config->get(ConfigThemeProvider::PREFIX); + public function __invoke(): void + { + $prefix = $this->config->get(ConfigThemeProvider::PREFIX); - if ( \get_theme_mod('custom_header', false ) ) { - \remove_theme_mod('custom_header'); - } + if (\get_theme_mod('custom_header', false)) { + \remove_theme_mod('custom_header'); + } - $id_custom_header = ConfigCustomHeaderProvider::CUSTOM_HEADER_ALIGNMENT; - $this->manager->add_setting( - $id_custom_header, - [ - 'default' => $this->config->get( $id_custom_header ), - 'type' => 'theme_mod', - 'transport' => 'refresh', - 'sanitize_callback' => 'sanitize_text_field', - ] - ); + $id_custom_header = ConfigCustomHeaderProvider::CUSTOM_HEADER_ALIGNMENT; + $this->manager->add_setting( + $id_custom_header, + [ + 'default' => $this->config->get($id_custom_header), + 'type' => 'theme_mod', + 'transport' => 'refresh', + 'sanitize_callback' => 'sanitize_text_field', + ] + ); - $this->manager->add_control( - "{$prefix}_$id_custom_header", - [ - 'label' => \__( 'Container width of the header', 'italystrap' ), - 'section' => self::SECTION, - 'type' => 'select', - 'settings' => $id_custom_header, - 'choices' => $this->getHorizontalThumb(), - ] - ); + $this->manager->add_control( + "{$prefix}_$id_custom_header", + [ + 'label' => \__('Container width of the header', 'italystrap'), + 'section' => self::SECTION, + 'type' => 'select', + 'settings' => $id_custom_header, + 'choices' => $this->getHorizontalThumb(), + ] + ); -// $id_custom_header_size = 'custom_image_size'; -// $this->registerSizeChoicesFor( -// $prefix, -// $id_custom_header_size, -// \__('Select the size of the cusom image', 'italystrap'), -// self::SECTION, -// 'select', -// 80 -// ); - } +// $id_custom_header_size = 'custom_image_size'; +// $this->registerSizeChoicesFor( +// $prefix, +// $id_custom_header_size, +// \__('Select the size of the cusom image', 'italystrap'), +// self::SECTION, +// 'select', +// 80 +// ); + } } diff --git a/src/Customizer/CustomizerAssetsSubscriber.php b/src/Customizer/CustomizerAssetsSubscriber.php index 10a1b574..adeb38b3 100644 --- a/src/Customizer/CustomizerAssetsSubscriber.php +++ b/src/Customizer/CustomizerAssetsSubscriber.php @@ -1,54 +1,59 @@ 'enqueueScriptOnLivePreview', - 'customize_controls_enqueue_scripts' => 'enqueueCustomizeControl', - ]; - } - - public function __construct( ConfigInterface $config) { - $this->config = $config; - } - - /** - * This outputs the javascript needed to automate the live settings preview. - * Also keep in mind that this function isn't necessary unless your settings. - */ - public function enqueueScriptOnLivePreview(): void { - \wp_enqueue_script( - self::class, - $this->config->get( ConfigThemeProvider::TEMPLATE_DIR_URI ) - . '/src/Customizer/assets/js/live-preview.min.js', - ['jquery', 'customize-preview'], - null, - true - ); - } - - /** - * This outputs the javascript needed to automate the live settings preview. - * Also keep in mind that this function isn't necessary unless your settings. - */ - public function enqueueCustomizeControl(): void { - \wp_enqueue_script( - self::class, - $this->config->get( ConfigThemeProvider::TEMPLATE_DIR_URI ) - . '/src/Customizer/assets/js/customize-controls.min.js', - ['jquery'], - null, - true - ); - } +use ItalyStrap\Theme\Infrastructure\Config\ConfigThemeProvider; + +class CustomizerAssetsSubscriber implements SubscriberInterface +{ + private ConfigInterface $config; + + public function getSubscribedEvents(): iterable + { + return [ + 'customize_preview_init' => 'enqueueScriptOnLivePreview', + 'customize_controls_enqueue_scripts' => 'enqueueCustomizeControl', + ]; + } + + public function __construct(ConfigInterface $config) + { + $this->config = $config; + } + + /** + * This outputs the javascript needed to automate the live settings preview. + * Also keep in mind that this function isn't necessary unless your settings. + */ + public function enqueueScriptOnLivePreview(): void + { + \wp_enqueue_script( + self::class, + $this->config->get(ConfigThemeProvider::TEMPLATE_DIR_URI) + . '/src/Customizer/assets/js/live-preview.min.js', + ['jquery', 'customize-preview'], + null, + true + ); + } + + /** + * This outputs the javascript needed to automate the live settings preview. + * Also keep in mind that this function isn't necessary unless your settings. + */ + public function enqueueCustomizeControl(): void + { + \wp_enqueue_script( + self::class, + $this->config->get(ConfigThemeProvider::TEMPLATE_DIR_URI) + . '/src/Customizer/assets/js/customize-controls.min.js', + ['jquery'], + null, + true + ); + } } diff --git a/src/Customizer/CustomizerBodyTagAttributesSubscriber.php b/src/Customizer/CustomizerBodyTagAttributesSubscriber.php index 701065a5..72eb1422 100644 --- a/src/Customizer/CustomizerBodyTagAttributesSubscriber.php +++ b/src/Customizer/CustomizerBodyTagAttributesSubscriber.php @@ -1,38 +1,41 @@ [ - SubscriberInterface::CALLBACK => '__invoke', - ]; - } - - public function __construct( - ConfigInterface $config - ) { - $this->config = $config; - } - - /** - * Used for the breadcrumbs display on customizer with javascript - */ - public function __invoke( array $attr ): array { - - if ( ! \is_customize_preview() ) { - return $attr; - } - - $attr['data-current-template'] = $this->config->get(ConfigCurrentTemplateSubscriber::TEMPLATE_FILE_NAME); - return $attr; - } +use ItalyStrap\Theme\Application\ConfigCurrentTemplateSubscriber; + +class CustomizerBodyTagAttributesSubscriber implements SubscriberInterface +{ + private ConfigInterface $config; + + public function getSubscribedEvents(): iterable + { + yield 'italystrap_body_attr' => [ + SubscriberInterface::CALLBACK => $this, + ]; + } + + public function __construct( + ConfigInterface $config + ) { + $this->config = $config; + } + + /** + * Used for the breadcrumbs display on customizer with javascript + */ + public function __invoke(array $attr): array + { + + if (! \is_customize_preview()) { + return $attr; + } + + $attr['data-current-template'] = $this->config->get(ConfigCurrentTemplateSubscriber::TEMPLATE_FILE_NAME); + return $attr; + } } diff --git a/src/Customizer/CustomizerProviderExtension.php b/src/Customizer/CustomizerProviderExtension.php index da8c0e94..99588f38 100644 --- a/src/Customizer/CustomizerProviderExtension.php +++ b/src/Customizer/CustomizerProviderExtension.php @@ -1,50 +1,55 @@ dispatcher = $dispatcher; - $this->injector = $injector; - } - - /** - * @inheritDoc - */ - public function name(): string { - return self::class; - } - - /** - * @inheritDoc - */ - public function execute( AurynConfigInterface $application ): void { - $this->dispatcher->addListener( 'customize_register', $this->buildCallable( $application ), 99, 3 ); - } - - public function walk( string $class, $index_or_optionName, Injector $injector ): void { - $object = $injector->make($class); - if (\is_callable($object)) { - $injector->execute($object); - } - } - - private function buildCallable( AurynConfigInterface $application ): callable { - return function ( \WP_Customize_Manager $manager ) use ( $application ): void { - $this->injector->share( $manager ); - $application->walk( $this->name(), [$this, 'walk'] ); - }; - } +use ItalyStrap\Event\ListenerRegisterInterface; + +class CustomizerProviderExtension implements \ItalyStrap\Empress\Extension +{ + private ListenerRegisterInterface $listenerRegister; + private Injector $injector; + + public function __construct( + ListenerRegisterInterface $listenerRegister, + Injector $injector + ) { + $this->listenerRegister = $listenerRegister; + $this->injector = $injector; + } + + /** + * @inheritDoc + */ + public function name(): string + { + return self::class; + } + + /** + * @inheritDoc + */ + public function execute(AurynConfigInterface $application): void + { + $this->listenerRegister->addListener('customize_register', $this->buildCallable($application), 99, 3); + } + + public function __invoke(string $class, $index_or_optionName, Injector $injector): void + { + $object = $injector->make($class); + if (\is_callable($object)) { + $injector->execute($object); + } + } + + private function buildCallable(AurynConfigInterface $application): callable + { + return function (\WP_Customize_Manager $manager) use ($application): void { + $this->injector->share($manager); + $application->walk($this->name(), $this); + }; + } } diff --git a/src/Customizer/DefaultPostThumbnailSubscriber.php b/src/Customizer/DefaultPostThumbnailSubscriber.php index 706fb1ec..c645676e 100644 --- a/src/Customizer/DefaultPostThumbnailSubscriber.php +++ b/src/Customizer/DefaultPostThumbnailSubscriber.php @@ -1,37 +1,41 @@ [ - SubscriberInterface::CALLBACK => '__invoke', - ]; - } - - public function __construct( ConfigInterface $config ) { - $this->config = $config; - } - - /** - * @param int|false $thumbnail_id - * @return int - */ - public function __invoke( $thumbnail_id ): int { - $thumbnail_id = (int)$thumbnail_id; - - if ( empty( $thumbnail_id ) ) { - return (int)$this->config->get(ConfigPostThumbnailProvider::POST_THUMBNAIL_ID_DEFAULT, 0); - } - - return $thumbnail_id; - } +use ItalyStrap\Theme\Infrastructure\Config\ConfigPostThumbnailProvider; + +final class DefaultPostThumbnailSubscriber implements SubscriberInterface +{ + private ConfigInterface $config; + + public function getSubscribedEvents(): iterable + { + yield 'post_thumbnail_id' => [ + SubscriberInterface::CALLBACK => '__invoke', + ]; + } + + public function __construct(ConfigInterface $config) + { + $this->config = $config; + } + + /** + * @param int|false $thumbnail_id + * @return int + */ + public function __invoke($thumbnail_id): int + { + $thumbnail_id = (int)$thumbnail_id; + + if (empty($thumbnail_id)) { + return (int)$this->config->get(ConfigPostThumbnailProvider::POST_THUMBNAIL_ID_DEFAULT, 0); + } + + return $thumbnail_id; + } } diff --git a/src/Customizer/FieldControlFactory.php b/src/Customizer/FieldControlFactory.php index 3a85cd11..5498bf26 100644 --- a/src/Customizer/FieldControlFactory.php +++ b/src/Customizer/FieldControlFactory.php @@ -1,16 +1,17 @@ manager = $manager; - $this->config = $config; - } + public function __construct( + \WP_Customize_Manager $manager, + ConfigInterface $config + ) { + $this->manager = $manager; + $this->config = $config; + } - public function __invoke(): void { - $prefix = $this->config->get(ConfigThemeProvider::PREFIX); + public function __invoke(): void + { + $prefix = $this->config->get(ConfigThemeProvider::PREFIX); - $this->manager->add_section( - 'italystrap_layout_options', - [ - 'title' => \__( 'Layout', 'italystrap' ), // Visible title of section. - 'panel' => PanelFields::class, + $this->manager->add_section( + 'italystrap_layout_options', + [ + 'title' => \__('Layout', 'italystrap'), // Visible title of section. + 'panel' => PanelFields::class, // phpcs:disable 'description' => \__( 'Allows you to customize the layout for all archive type pages. (Not page and post).', 'italystrap' ), // phpcs:enable - ] - ); + ] + ); - /** - * Container Width - */ - $this->manager->add_setting( - 'container_width', - [ - 'default' => $this->config->get('container_width'), - 'type' => 'theme_mod', - 'transport' => 'refresh', - 'sanitize_callback' => 'sanitize_text_field', - ] - ); + /** + * Container Width + */ + $this->manager->add_setting( + 'container_width', + [ + 'default' => $this->config->get('container_width'), + 'type' => 'theme_mod', + 'transport' => 'refresh', + 'sanitize_callback' => 'sanitize_text_field', + ] + ); - $this->manager->add_control( - 'italystrap_container_width', - [ - 'label' => \__( 'Container width (Global)', 'italystrap' ), - 'section' => 'italystrap_layout_options', - 'type' => 'radio', - 'settings' => 'container_width', - 'choices' => \apply_filters( 'italystrap_theme_width', [] ), - ] - ); + $this->manager->add_control( + 'italystrap_container_width', + [ + 'label' => \__('Container width (Global)', 'italystrap'), + 'section' => 'italystrap_layout_options', + 'type' => 'radio', + 'settings' => 'container_width', + 'choices' => \apply_filters('italystrap_theme_width', []), + ] + ); - /** - * Container Width of the header - */ - $this->manager->add_setting( - 'site_layout', - [ - 'default' => $this->config->get('content_sidebar'), - 'type' => 'theme_mod', - 'transport' => 'refresh', - 'sanitize_callback' => 'sanitize_text_field', - ] - ); + /** + * Container Width of the header + */ + $this->manager->add_setting( + 'site_layout', + [ + 'default' => $this->config->get('content_sidebar'), + 'type' => 'theme_mod', + 'transport' => 'refresh', + 'sanitize_callback' => 'sanitize_text_field', + ] + ); - $this->manager->add_control( - 'italystrap_site_layout', - [ - 'label' => \__( 'Layout (Global)', 'italystrap' ), - 'section' => 'italystrap_layout_options', - 'type' => 'radio', - 'settings' => 'site_layout', - 'choices' => require \get_template_directory() . '/config/layout.php', - ] - ); - } + $this->manager->add_control( + 'italystrap_site_layout', + [ + 'label' => \__('Layout (Global)', 'italystrap'), + 'section' => 'italystrap_layout_options', + 'type' => 'radio', + 'settings' => 'site_layout', + 'choices' => require \get_template_directory() . '/config/layout.php', + ] + ); + } } diff --git a/src/Customizer/NavbarFields.php b/src/Customizer/NavbarFields.php index 54c382b3..3a3dfd95 100644 --- a/src/Customizer/NavbarFields.php +++ b/src/Customizer/NavbarFields.php @@ -1,38 +1,40 @@ manager = $manager; - $this->config = $config; - $this->factory = $factory; - } + public function __construct( + \WP_Customize_Manager $manager, + ConfigInterface $config, + FieldControlFactory $factory + ) { + $this->manager = $manager; + $this->config = $config; + $this->factory = $factory; + } - public function __invoke(): void { - $prefix = $this->config->get(ConfigThemeProvider::PREFIX); + public function __invoke(): void + { + $prefix = $this->config->get(ConfigThemeProvider::PREFIX); - $this->manager->add_section( - self::class, - [ - 'title' => \__( 'Navbar Settings', 'italystrap' ), // Visible title of section. - 'panel' => PanelFields::class, + $this->manager->add_section( + self::class, + [ + 'title' => \__('Navbar Settings', 'italystrap'), // Visible title of section. + 'panel' => PanelFields::class, // phpcs:disable 'description' => \__( 'Allows you to customize settings for the main navbar. Remember that this uses the Twitter Bootstrap Navbar style, if you want more info read the documentation.', 'italystrap' ), // phpcs:enabl @@ -78,94 +80,94 @@ public function __invoke(): void { // phpcs:disable 'description' => \__( 'Select the position of the navbar. By default is set to "relative top", you can chose "fixed top", "fixed bottom" or "static top", with the "static top" you also have to set the navbar "full width" for fixing the correct padding.', 'italystrap' ), // phpcs:enable - 'section' => self::class, - 'type' => 'radio', - 'choices' => [ - 'navbar-relative-top' => \__( 'Default relative top', 'italystrap' ), - 'navbar-static-top' => \__( 'Static Top', 'italystrap' ), - 'navbar-fixed-top' => \__( 'Fixed Top', 'italystrap' ), - 'navbar-fixed-bottom' => \__( 'Fixed Bottom', 'italystrap' ), - ], - ] - ); + 'section' => self::class, + 'type' => 'radio', + 'choices' => [ + 'navbar-relative-top' => \__('Default relative top', 'italystrap'), + 'navbar-static-top' => \__('Static Top', 'italystrap'), + 'navbar-fixed-top' => \__('Fixed Top', 'italystrap'), + 'navbar-fixed-bottom' => \__('Fixed Bottom', 'italystrap'), + ], + ] + ); - $this->manager->add_setting( - 'navbar[nav_width]', - [ - 'default' => $this->config->get('navbar.nav_width'), - 'type' => 'theme_mod', - 'transport' => 'postMessage', - 'sanitize_callback' => 'sanitize_text_field' - ] - ); - $this->manager->add_control( - 'italystrap_navbar[nav_width]', - [ - 'settings' => 'navbar[nav_width]', - 'label' => \__( 'Navbar width', 'italystrap' ), + $this->manager->add_setting( + 'navbar[nav_width]', + [ + 'default' => $this->config->get('navbar.nav_width'), + 'type' => 'theme_mod', + 'transport' => 'postMessage', + 'sanitize_callback' => 'sanitize_text_field' + ] + ); + $this->manager->add_control( + 'italystrap_navbar[nav_width]', + [ + 'settings' => 'navbar[nav_width]', + 'label' => \__('Navbar width', 'italystrap'), // phpcs:disable 'description' => \__( 'Select the nav_width of navbar, this enlarges the navbar to the windows size (use it also width Static Top option).', 'italystrap' ), // phpcs:enable - 'section' => self::class, - 'type' => 'radio', - 'choices' => [ - 'container' => \__( 'Boxed', 'italystrap' ), - 'none' => \__( 'Full width', 'italystrap' ), - ], - ] - ); + 'section' => self::class, + 'type' => 'radio', + 'choices' => [ + 'container' => \__('Boxed', 'italystrap'), + 'none' => \__('Full width', 'italystrap'), + ], + ] + ); - /** - * Select the menus_width of navbar - */ - $this->manager->add_setting( - 'navbar[menus_width]', - [ - 'default' => $this->config->get('navbar.menus_width'), - 'type' => 'theme_mod', - 'transport' => 'postMessage', - 'sanitize_callback' => 'sanitize_text_field' - ] - ); - $this->manager->add_control( - 'italystrap_navbar[menus_width]', - [ - 'settings' => 'navbar[menus_width]', - 'label' => \__( 'Navbar menus width', 'italystrap' ), + /** + * Select the menus_width of navbar + */ + $this->manager->add_setting( + 'navbar[menus_width]', + [ + 'default' => $this->config->get('navbar.menus_width'), + 'type' => 'theme_mod', + 'transport' => 'postMessage', + 'sanitize_callback' => 'sanitize_text_field' + ] + ); + $this->manager->add_control( + 'italystrap_navbar[menus_width]', + [ + 'settings' => 'navbar[menus_width]', + 'label' => \__('Navbar menus width', 'italystrap'), // phpcs:disable 'description' => \__( 'Select the menus_width, this is the width of the container of the 2 menu, main-menu and secondary-menu, with the full width the menus will enlarge to the widnows size, with the "width of the content" they will sized like the size of the content. If you have select the "default boxed width" leave the default value.', 'italystrap' ), // phpcs:enable - 'section' => self::class, - 'type' => 'radio', - 'choices' => $this->getHorizontalStandard(), - // 'active_callback' => function ( $control ) { - // return $control->manager->get_setting('navbar[nav_width]')->value() == 'none'; - // }, - ] - ); + 'section' => self::class, + 'type' => 'radio', + 'choices' => $this->getHorizontalStandard(), + // 'active_callback' => function ( $control ) { + // return $control->manager->get_setting('navbar[nav_width]')->value() == 'none'; + // }, + ] + ); - $this->manager->add_setting( - 'navbar[main_menu_x_align]', - [ - 'default' => $this->config->get('navbar.main_menu_x_align'), - 'type' => 'theme_mod', - 'transport' => 'postMessage', - 'sanitize_callback' => 'sanitize_text_field' - ] - ); - $this->manager->add_control( - 'italystrap_navbar[main_menu_x_align]', - [ - 'settings' => 'navbar[main_menu_x_align]', - 'label' => \__( 'Main menu align', 'italystrap' ), - 'description' => \__( 'Select the main menu alignment', 'italystrap' ), - 'section' => self::class, - 'type' => 'radio', - 'choices' => [ - 'navbar-left' => \__( 'Left', 'italystrap' ), - 'navbar-right' => \__( 'Right', 'italystrap' ), - ], - ] - ); - } + $this->manager->add_setting( + 'navbar[main_menu_x_align]', + [ + 'default' => $this->config->get('navbar.main_menu_x_align'), + 'type' => 'theme_mod', + 'transport' => 'postMessage', + 'sanitize_callback' => 'sanitize_text_field' + ] + ); + $this->manager->add_control( + 'italystrap_navbar[main_menu_x_align]', + [ + 'settings' => 'navbar[main_menu_x_align]', + 'label' => \__('Main menu align', 'italystrap'), + 'description' => \__('Select the main menu alignment', 'italystrap'), + 'section' => self::class, + 'type' => 'radio', + 'choices' => [ + 'navbar-left' => \__('Left', 'italystrap'), + 'navbar-right' => \__('Right', 'italystrap'), + ], + ] + ); + } } diff --git a/src/Customizer/NotFoundFields.php b/src/Customizer/NotFoundFields.php index 4bb5c6cd..9f5d58c0 100644 --- a/src/Customizer/NotFoundFields.php +++ b/src/Customizer/NotFoundFields.php @@ -1,146 +1,148 @@ manager = $manager; - $this->config = $config; - $this->control = $control; - } - - public function __invoke(): void { - $id = 'italystrap'; - - $this->manager->add_section( - self::class, - [ - 'title' => \__( '404 Page not found', 'italystrap' ), - 'panel' => PanelFields::class, - 'description' => \__( 'Customize the 404 page for this theme.', 'italystrap' ), - ] - ); - - $show_image = ConfigNotFoundProvider::SHOW_IMAGE; - $this->manager->add_setting( - ConfigNotFoundProvider::SHOW_IMAGE, - [ - 'default' => $this->config->get(ConfigNotFoundProvider::SHOW_IMAGE), - 'type' => 'theme_mod', - 'transport' => 'postMessage', - 'sanitize_callback' => 'sanitize_text_field', - ] - ); - - $this->manager->add_control( - "{$id}_{$show_image}", - [ - 'label' => \__( 'Show or hide 404 image', 'italystrap' ), - 'description' => \__( 'Select one option for showing or hiding the not found image.', 'italystrap' ), - 'section' => self::class, - 'settings' => ConfigNotFoundProvider::SHOW_IMAGE, - 'priority' => 10, - 'type' => 'radio', - 'choices' => [ - self::SHOW_IMAGE => \__( 'Show the 404 image', 'italystrap' ), - self::HIDE_IMAGE => \__( 'Hide the 404 image', 'italystrap' ), - ], - ] - ); - - - $this->manager->add_setting( - ConfigNotFoundProvider::ID_IMAGE, - [ - 'default' => $this->config->get(ConfigNotFoundProvider::ID_IMAGE), - 'type' => 'theme_mod', - 'transport' => 'postMessage', - 'sanitize_callback' => 'sanitize_text_field', - ] - ); - - $id_image = ConfigNotFoundProvider::ID_IMAGE; - $this->manager->add_control( - $this->control->make( - \WP_Customize_Media_Control::class, - $this->manager, - "{$id}_{$id_image}", - [ - 'label' => \__( 'Default 404 Image', 'italystrap' ), - 'description' => \sprintf( +use ItalyStrap\Theme\Infrastructure\Config\ConfigPostThumbnailProvider; + +class NotFoundFields +{ + public const SHOW_IMAGE = 'show'; + public const HIDE_IMAGE = 'hide'; + + private \WP_Customize_Manager $manager; + private ConfigInterface $config; + private FieldControlFactory $control; + + public function __construct( + \WP_Customize_Manager $manager, + ConfigInterface $config, + FieldControlFactory $control + ) { + $this->manager = $manager; + $this->config = $config; + $this->control = $control; + } + + public function __invoke(): void + { + $id = 'italystrap'; + + $this->manager->add_section( + self::class, + [ + 'title' => \__('404 Page not found', 'italystrap'), + 'panel' => PanelFields::class, + 'description' => \__('Customize the 404 page for this theme.', 'italystrap'), + ] + ); + + $show_image = ConfigNotFoundProvider::SHOW_IMAGE; + $this->manager->add_setting( + ConfigNotFoundProvider::SHOW_IMAGE, + [ + 'default' => $this->config->get(ConfigNotFoundProvider::SHOW_IMAGE), + 'type' => 'theme_mod', + 'transport' => 'postMessage', + 'sanitize_callback' => 'sanitize_text_field', + ] + ); + + $this->manager->add_control( + "{$id}_{$show_image}", + [ + 'label' => \__('Show or hide 404 image', 'italystrap'), + 'description' => \__('Select one option for showing or hiding the not found image.', 'italystrap'), + 'section' => self::class, + 'settings' => ConfigNotFoundProvider::SHOW_IMAGE, + 'priority' => 10, + 'type' => 'radio', + 'choices' => [ + self::SHOW_IMAGE => \__('Show the 404 image', 'italystrap'), + self::HIDE_IMAGE => \__('Hide the 404 image', 'italystrap'), + ], + ] + ); + + + $this->manager->add_setting( + ConfigNotFoundProvider::ID_IMAGE, + [ + 'default' => $this->config->get(ConfigNotFoundProvider::ID_IMAGE), + 'type' => 'theme_mod', + 'transport' => 'postMessage', + 'sanitize_callback' => 'sanitize_text_field', + ] + ); + + $id_image = ConfigNotFoundProvider::ID_IMAGE; + $this->manager->add_control( + $this->control->make( + \WP_Customize_Media_Control::class, + $this->manager, + "{$id}_{$id_image}", + [ + 'label' => \__('Default 404 Image', 'italystrap'), + 'description' => \sprintf( // phpcs:disable \__( 'This is a default 404 image, it will be displayed in 404 page (must be at least %dpx width)', 'italystrap' ), // phpcs:enable - $this->config->get(ConfigPostThumbnailProvider::POST_CONTENT_WIDTH) - ), - 'section' => self::class, - 'settings' => ConfigNotFoundProvider::ID_IMAGE, - 'priority' => 10, - ] - ) - ); - - $id_title = ConfigNotFoundProvider::TITLE; - $this->manager->add_setting( - ConfigNotFoundProvider::TITLE, - [ - 'default' => $this->config->get(ConfigNotFoundProvider::TITLE), - 'type' => 'theme_mod', - 'transport' => 'postMessage', - 'sanitize_callback' => 'sanitize_text_field', - ] - ); - - $this->manager->add_control( - "{$id}_{$id_title}", - [ - 'label' => \__( '404 Page Title', 'italystrap' ), - 'description' => \__( 'Add a title for the 404 page.', 'italystrap' ), - 'section' => self::class, - 'settings' => ConfigNotFoundProvider::TITLE, - 'priority' => 10, - 'type' => 'text', - ] - ); - - $this->manager->add_setting( - ConfigNotFoundProvider::CONTENT, - [ - 'default' => $this->config->get(ConfigNotFoundProvider::CONTENT), - 'type' => 'theme_mod', - 'transport' => 'postMessage', - 'sanitize_callback' => 'sanitize_text_field', - ] - ); - - $id_content = ConfigNotFoundProvider::CONTENT; - $this->manager->add_control( - "{$id}_{$id_content}", - [ - 'label' => \__( '404 Page Text', 'italystrap' ), - 'description' => \__( 'The text for the content for the 404 page. HTML allowed.', 'italystrap' ), - 'section' => self::class, - 'settings' => ConfigNotFoundProvider::CONTENT, - 'priority' => 10, - 'type' => 'textarea', - ] - ); - } + $this->config->get(ConfigPostThumbnailProvider::POST_CONTENT_WIDTH) + ), + 'section' => self::class, + 'settings' => ConfigNotFoundProvider::ID_IMAGE, + 'priority' => 10, + ] + ) + ); + + $id_title = ConfigNotFoundProvider::TITLE; + $this->manager->add_setting( + ConfigNotFoundProvider::TITLE, + [ + 'default' => $this->config->get(ConfigNotFoundProvider::TITLE), + 'type' => 'theme_mod', + 'transport' => 'postMessage', + 'sanitize_callback' => 'sanitize_text_field', + ] + ); + + $this->manager->add_control( + "{$id}_{$id_title}", + [ + 'label' => \__('404 Page Title', 'italystrap'), + 'description' => \__('Add a title for the 404 page.', 'italystrap'), + 'section' => self::class, + 'settings' => ConfigNotFoundProvider::TITLE, + 'priority' => 10, + 'type' => 'text', + ] + ); + + $this->manager->add_setting( + ConfigNotFoundProvider::CONTENT, + [ + 'default' => $this->config->get(ConfigNotFoundProvider::CONTENT), + 'type' => 'theme_mod', + 'transport' => 'postMessage', + 'sanitize_callback' => 'sanitize_text_field', + ] + ); + + $id_content = ConfigNotFoundProvider::CONTENT; + $this->manager->add_control( + "{$id}_{$id_content}", + [ + 'label' => \__('404 Page Text', 'italystrap'), + 'description' => \__('The text for the content for the 404 page. HTML allowed.', 'italystrap'), + 'section' => self::class, + 'settings' => ConfigNotFoundProvider::CONTENT, + 'priority' => 10, + 'type' => 'textarea', + ] + ); + } } diff --git a/src/Customizer/PanelFields.php b/src/Customizer/PanelFields.php index 24652fa4..acf32de2 100644 --- a/src/Customizer/PanelFields.php +++ b/src/Customizer/PanelFields.php @@ -1,34 +1,36 @@ manager = $manager; - $this->config = $config; - } + public function __construct( + \WP_Customize_Manager $manager, + ConfigInterface $config + ) { + $this->manager = $manager; + $this->config = $config; + } - public function __invoke(): void { - $this->manager->add_panel( - self::class, - [ - 'title' => \sprintf( - \__( '%s Options', 'italystrap' ), - (string)$this->config->get( ConfigThemeProvider::THEME_NAME, '' ) - ), - 'priority' => 10, - ] - ); - } + public function __invoke(): void + { + $this->manager->add_panel( + self::class, + [ + 'title' => \sprintf( + \__('%s Options', 'italystrap'), + (string)$this->config->get(ConfigThemeProvider::THEME_NAME, '') + ), + 'priority' => 10, + ] + ); + } } diff --git a/src/Customizer/PostContentTemplateFields.php b/src/Customizer/PostContentTemplateFields.php index 22eef81a..f2d16268 100644 --- a/src/Customizer/PostContentTemplateFields.php +++ b/src/Customizer/PostContentTemplateFields.php @@ -1,73 +1,75 @@ manager = $manager; - $this->config = $config; - $this->factory = $factory; - } + public function __construct( + \WP_Customize_Manager $manager, + ConfigInterface $config, + FieldControlFactory $factory + ) { + $this->manager = $manager; + $this->config = $config; + $this->factory = $factory; + } - public function __invoke(): void { - if ( ! \class_exists( '\ItalyStrap\Customizer\Control\Multicheck' ) ) { - return; - } + public function __invoke(): void + { + if (! \class_exists('\ItalyStrap\Customizer\Control\Multicheck')) { + return; + } - $prefix = $this->config->get(ConfigThemeProvider::PREFIX); + $prefix = $this->config->get(ConfigThemeProvider::PREFIX); - $this->manager->add_section( - self::class, - [ - 'title' => \__( 'Post content template', 'italystrap' ), - 'panel' => PanelFields::class, - 'description' => - \__( + $this->manager->add_section( + self::class, + [ + 'title' => \__('Post content template', 'italystrap'), + 'panel' => PanelFields::class, + 'description' => + \__( // phpcs:disable 'Allows you to customize the post content template for all archive type pages. (Not page and post).', // phpcs:enable - 'italystrap' - ), - ] - ); + 'italystrap' + ), + ] + ); - $id_post_content_template = 'post_content_template'; - $this->manager->add_setting( - $id_post_content_template, - [ - // 'default' => $this->config->get(), - 'type' => 'theme_mod', - 'transport' => 'postMessage', - 'sanitize_callback' => 'sanitize_text_field', - ] - ); + $id_post_content_template = 'post_content_template'; + $this->manager->add_setting( + $id_post_content_template, + [ + // 'default' => $this->config->get(), + 'type' => 'theme_mod', + 'transport' => 'postMessage', + 'sanitize_callback' => 'sanitize_text_field', + ] + ); - $this->manager->add_control( - $this->factory->make( - '\ItalyStrap\Customizer\Control\Multicheck', - $this->manager, - "{$prefix}_$id_post_content_template", - [ - 'label' => \__( 'Template content settings', 'italystrap' ), - 'section' => self::class, - 'type' => 'multicheck', - 'settings' => $id_post_content_template, - 'choices' => require \get_template_directory() . '/config/template-content.php', - ] - ) - ); - } + $this->manager->add_control( + $this->factory->make( + '\ItalyStrap\Customizer\Control\Multicheck', + $this->manager, + "{$prefix}_$id_post_content_template", + [ + 'label' => \__('Template content settings', 'italystrap'), + 'section' => self::class, + 'type' => 'multicheck', + 'settings' => $id_post_content_template, + 'choices' => require \get_template_directory() . '/config/template-content.php', + ] + ) + ); + } } diff --git a/src/Customizer/PostThumbnailFields.php b/src/Customizer/PostThumbnailFields.php index 3974b67c..8b59130f 100644 --- a/src/Customizer/PostThumbnailFields.php +++ b/src/Customizer/PostThumbnailFields.php @@ -1,121 +1,125 @@ manager = $manager; - $this->config = $config; - $this->control = $control; - $this->dispatcher = $dispatcher; - } + public function __construct( + \WP_Customize_Manager $manager, + ConfigInterface $config, + FieldControlFactory $control, + EventDispatcherInterface $dispatcher + ) { + $this->manager = $manager; + $this->config = $config; + $this->control = $control; + $this->dispatcher = $dispatcher; + } - public function __invoke(): void { - $id = 'italystrap'; + public function __invoke(): void + { + $id = 'italystrap'; - $this->manager->add_section( - self::class, - [ - 'title' => __( 'Thumbnails', 'italystrap' ), - 'panel' => PanelFields::class, - 'description' => __( 'Allows you to customize image settings for ItalyStrap.', 'italystrap' ), - ] - ); + $this->manager->add_section( + self::class, + [ + 'title' => __('Thumbnails', 'italystrap'), + 'panel' => PanelFields::class, + 'description' => __('Allows you to customize image settings for ItalyStrap.', 'italystrap'), + ] + ); - $this->manager->add_setting( - ConfigPostThumbnailProvider::POST_THUMBNAIL_ID_DEFAULT, - [ - 'default' => (int)$this->config->get(ConfigPostThumbnailProvider::POST_THUMBNAIL_ID_DEFAULT, 0), - 'type' => 'theme_mod', - 'transport' => 'postMessage', - 'sanitize_callback' => 'sanitize_text_field', - ] - ); + $this->manager->add_setting( + ConfigPostThumbnailProvider::POST_THUMBNAIL_ID_DEFAULT, + [ + 'default' => (int)$this->config->get(ConfigPostThumbnailProvider::POST_THUMBNAIL_ID_DEFAULT, 0), + 'type' => 'theme_mod', + 'transport' => 'postMessage', + 'sanitize_callback' => 'sanitize_text_field', + ] + ); - $id_default_image = ConfigPostThumbnailProvider::POST_THUMBNAIL_ID_DEFAULT; - $this->manager->add_control( - $this->control->make( - \WP_Customize_Media_Control::class, - $this->manager, - "{$id}_{$id_default_image}", - [ - 'label' => \__( 'Default Image', 'italystrap' ), + $id_default_image = ConfigPostThumbnailProvider::POST_THUMBNAIL_ID_DEFAULT; + $this->manager->add_control( + $this->control->make( + \WP_Customize_Media_Control::class, + $this->manager, + "{$id}_{$id_default_image}", + [ + 'label' => \__('Default Image', 'italystrap'), // phpcs:disable 'description' => \__( 'It will be displayed if no feautured image will be added in your content page/post if the theme supports this feature.', 'italystrap' ), // phpcs:enable - 'section' => self::class, - 'settings' => ConfigPostThumbnailProvider::POST_THUMBNAIL_ID_DEFAULT, - 'priority' => 10, - ] - ) - ); + 'section' => self::class, + 'settings' => ConfigPostThumbnailProvider::POST_THUMBNAIL_ID_DEFAULT, + 'priority' => 10, + ] + ) + ); - $this->manager->add_setting( - ConfigPostThumbnailProvider::POST_THUMBNAIL_SIZE, - [ - 'default' => (string)$this->config->get(ConfigPostThumbnailProvider::POST_THUMBNAIL_SIZE), - 'type' => 'theme_mod', - 'transport' => 'refresh', - 'sanitize_callback' => 'sanitize_text_field', - ] - ); + $this->manager->add_setting( + ConfigPostThumbnailProvider::POST_THUMBNAIL_SIZE, + [ + 'default' => (string)$this->config->get(ConfigPostThumbnailProvider::POST_THUMBNAIL_SIZE), + 'type' => 'theme_mod', + 'transport' => 'refresh', + 'sanitize_callback' => 'sanitize_text_field', + ] + ); - $id_thumb_size = ConfigPostThumbnailProvider::POST_THUMBNAIL_SIZE; - $this->manager->add_control( - "{$id}_{$id_thumb_size}", - [ - 'settings' => ConfigPostThumbnailProvider::POST_THUMBNAIL_SIZE, - 'label' => \__( 'Post thumbnail size', 'italystrap' ), + $id_thumb_size = ConfigPostThumbnailProvider::POST_THUMBNAIL_SIZE; + $this->manager->add_control( + "{$id}_{$id_thumb_size}", + [ + 'settings' => ConfigPostThumbnailProvider::POST_THUMBNAIL_SIZE, + 'label' => \__('Post thumbnail size', 'italystrap'), // phpcs:disable 'description' => \__( 'Change image size of post thumbnail in archive, author, blog, category, search, and tag pages.', 'italystrap' ), // phpcs:enable - 'section' => self::class, - 'type' => 'select', - 'choices' => $this->buildSizeChoices(), - ] - ); + 'section' => self::class, + 'type' => 'select', + 'choices' => $this->buildSizeChoices(), + ] + ); - $this->manager->add_setting( - ConfigPostThumbnailProvider::POST_THUMBNAIL_ALIGNMENT, - [ - 'default' => (string)$this->config->get(ConfigPostThumbnailProvider::POST_THUMBNAIL_ALIGNMENT), - 'type' => 'theme_mod', - 'transport' => 'refresh', - 'sanitize_callback' => 'sanitize_text_field', - ] - ); + $this->manager->add_setting( + ConfigPostThumbnailProvider::POST_THUMBNAIL_ALIGNMENT, + [ + 'default' => (string)$this->config->get(ConfigPostThumbnailProvider::POST_THUMBNAIL_ALIGNMENT), + 'type' => 'theme_mod', + 'transport' => 'refresh', + 'sanitize_callback' => 'sanitize_text_field', + ] + ); - $id_thumb_align = ConfigPostThumbnailProvider::POST_THUMBNAIL_ALIGNMENT; - $this->manager->add_control( - "{$id}_{$id_thumb_align}", - [ - 'settings' => ConfigPostThumbnailProvider::POST_THUMBNAIL_ALIGNMENT, - 'label' => \__( 'Archive post thumbnail alignment', 'italystrap' ), + $id_thumb_align = ConfigPostThumbnailProvider::POST_THUMBNAIL_ALIGNMENT; + $this->manager->add_control( + "{$id}_{$id_thumb_align}", + [ + 'settings' => ConfigPostThumbnailProvider::POST_THUMBNAIL_ALIGNMENT, + 'label' => \__('Archive post thumbnail alignment', 'italystrap'), // phpcs:disable 'description' => \__( 'Change image alignment of post thumbnail in archive, author, blog, category, search, and tag pages.', 'italystrap' ), // phpcs:enable - 'section' => self::class, - 'type' => 'select', - 'choices' => $this->getHorizontalThumb(), - ] - ); - } + 'section' => self::class, + 'type' => 'select', + 'choices' => $this->getHorizontalThumb(), + ] + ); + } } diff --git a/src/Customizer/SiteIdentityFields.php b/src/Customizer/SiteIdentityFields.php index 1c6cb65d..2001d526 100644 --- a/src/Customizer/SiteIdentityFields.php +++ b/src/Customizer/SiteIdentityFields.php @@ -1,20 +1,22 @@ manager = $manager; - } + public function __construct( + \WP_Customize_Manager $manager + ) { + $this->manager = $manager; + } - public function __invoke(): void { - $this->manager->get_setting( 'blogname' )->transport = 'postMessage'; - $this->manager->get_setting( 'blogdescription' )->transport = 'postMessage'; - } + public function __invoke(): void + { + $this->manager->get_setting('blogname')->transport = 'postMessage'; + $this->manager->get_setting('blogdescription')->transport = 'postMessage'; + } } diff --git a/src/Customizer/SiteLogoFields.php b/src/Customizer/SiteLogoFields.php index 9df9e3a2..4d4e4251 100644 --- a/src/Customizer/SiteLogoFields.php +++ b/src/Customizer/SiteLogoFields.php @@ -1,136 +1,140 @@ manager = $manager; - $this->config = $config; - $this->control = $control; - $this->dispatcher = $dispatcher; - } - - public function __invoke(): void { - $prefix = $this->config->get(ConfigThemeProvider::PREFIX); - - $id_separator = 'separator'; - $this->manager->add_setting( $id_separator, [] ); - - $this->manager->add_control( - new class( - $this->manager, - "{$prefix}_$id_separator", - [ - 'section' => self::SECTION, - 'settings' => $id_separator, - 'priority' => 80, - ] - ) extends \WP_Customize_Control { +use ItalyStrap\Theme\Infrastructure\Config\ConfigThemeProvider; + +class SiteLogoFields +{ + use BuildThumbnailSizeChoicesTrait; + use SizeChoicesTrait; + + public const SECTION = 'title_tagline'; + + private \WP_Customize_Manager $manager; + private ConfigInterface $config; + private FieldControlFactory $control; + private EventDispatcherInterface $dispatcher; + + public function __construct( + \WP_Customize_Manager $manager, + ConfigInterface $config, + FieldControlFactory $control, + EventDispatcherInterface $dispatcher + ) { + $this->manager = $manager; + $this->config = $config; + $this->control = $control; + $this->dispatcher = $dispatcher; + } + + public function __invoke(): void + { + $prefix = $this->config->get(ConfigThemeProvider::PREFIX); + + $id_separator = 'separator'; + $this->manager->add_setting($id_separator, []); + + $this->manager->add_control( + new class ( + $this->manager, + "{$prefix}_$id_separator", + [ + 'section' => self::SECTION, + 'settings' => $id_separator, + 'priority' => 80, + ] + ) extends \WP_Customize_Control { // phpcs:disable protected function render_content() { echo ''; } // phpcs:enable - } - ); - - $id_navbar_brand_display = 'display_navbar_brand'; - $this->manager->add_setting( - $id_navbar_brand_display, - [ - 'default' => $this->config->get( ConfigSiteLogoProvider::DISPLAY_NAVBAR_BRAND_IMAGE ), - 'type' => 'theme_mod', - 'transport' => 'postMessage', - 'sanitize_callback' => 'sanitize_text_field', - ] - ); - - $this->manager->add_control( - "{$prefix}_{$id_navbar_brand_display}", - [ - 'settings' => $id_navbar_brand_display, - 'label' => \__( 'Display the navbar brand', 'italystrap' ), + } + ); + + $id_navbar_brand_display = 'display_navbar_brand'; + $this->manager->add_setting( + $id_navbar_brand_display, + [ + 'default' => $this->config->get(ConfigSiteLogoProvider::DISPLAY_NAVBAR_BRAND_IMAGE), + 'type' => 'theme_mod', + 'transport' => 'postMessage', + 'sanitize_callback' => 'sanitize_text_field', + ] + ); + + $this->manager->add_control( + "{$prefix}_{$id_navbar_brand_display}", + [ + 'settings' => $id_navbar_brand_display, + 'label' => \__('Display the navbar brand', 'italystrap'), // phpcs:disable 'description' => \__( 'Select the type of navbar brand to visualize or select to hide navbar brand, if you select to visualize navbar with image you also have to select the image and the size of the image to visualize in the above controls.', 'italystrap' ), // phpcs:enable - 'section' => self::SECTION, - 'type' => 'radio', - 'priority' => 80, - 'choices' => [ - 'none' => \__( 'Hide navbar brand', 'italystrap' ), - 'display_image' => \__( 'Display navbar brand image', 'italystrap' ), - 'display_name' => \__( 'Display navbar brand name', 'italystrap' ), - 'display_all' => \__( 'Display navbar brand image and name', 'italystrap' ), - ], - ] - ); - -// d(\get_theme_mod('custom_logo')); -// d(\get_option( 'site_logo' )); -// d(\get_option( 'site_icon' )); -// d($this->config); - - $old_logo_id = \get_theme_mod('logo'); - $brand_image_id = ConfigSiteLogoProvider::BRAND_IMAGE_ID; - if ( ! empty( $old_logo_id ) ) { - $this->config->add( 'navbar_logo_image', \absint( $old_logo_id ) ); - \set_theme_mod( 'navbar_logo_image', \absint( $old_logo_id ) ); - \update_option( 'site_logo', \absint( $old_logo_id ) ); - \remove_theme_mod( $brand_image_id ); - } - - $this->manager->add_setting( - $brand_image_id, - [ - 'default' => $this->config->get($brand_image_id), - 'type' => 'theme_mod', - 'transport' => 'refresh', - 'sanitize_callback' => 'sanitize_text_field', - ] - ); - - $this->manager->add_control( - new \WP_Customize_Media_Control( - $this->manager, - "{$prefix}_{$brand_image_id}", - [ - 'label' => \__( 'Your logo brand for nav menu', 'italystrap' ), - 'description' => \__( 'Insert here your logo brand for nav menu', 'italystrap' ), - 'section' => self::SECTION, - 'settings' => $brand_image_id, - 'priority' => 80, - ] - ) - ); - - $id_logo_img_size = ConfigSiteLogoProvider::BRAND_IMAGE_SIZE; - $this->registerSizeChoicesFor( - $prefix, - $id_logo_img_size, - \__( 'Logo image size', 'italystrap' ), - self::SECTION, - 'select', - 80 - ); - } + 'section' => self::SECTION, + 'type' => 'radio', + 'priority' => 80, + 'choices' => [ + 'none' => \__('Hide navbar brand', 'italystrap'), + 'display_image' => \__('Display navbar brand image', 'italystrap'), + 'display_name' => \__('Display navbar brand name', 'italystrap'), + 'display_all' => \__('Display navbar brand image and name', 'italystrap'), + ], + ] + ); + +// d(\get_theme_mod('custom_logo')); +// d(\get_option( 'site_logo' )); +// d(\get_option( 'site_icon' )); +// d($this->config); + + $old_logo_id = \get_theme_mod('logo'); + $brand_image_id = ConfigSiteLogoProvider::BRAND_IMAGE_ID; + if (! empty($old_logo_id)) { + $this->config->add('navbar_logo_image', \absint($old_logo_id)); + \set_theme_mod('navbar_logo_image', \absint($old_logo_id)); + \update_option('site_logo', \absint($old_logo_id)); + \remove_theme_mod($brand_image_id); + } + + $this->manager->add_setting( + $brand_image_id, + [ + 'default' => $this->config->get($brand_image_id), + 'type' => 'theme_mod', + 'transport' => 'refresh', + 'sanitize_callback' => 'sanitize_text_field', + ] + ); + + $this->manager->add_control( + new \WP_Customize_Media_Control( + $this->manager, + "{$prefix}_{$brand_image_id}", + [ + 'label' => \__('Your logo brand for nav menu', 'italystrap'), + 'description' => \__('Insert here your logo brand for nav menu', 'italystrap'), + 'section' => self::SECTION, + 'settings' => $brand_image_id, + 'priority' => 80, + ] + ) + ); + + $id_logo_img_size = ConfigSiteLogoProvider::BRAND_IMAGE_SIZE; + $this->registerSizeChoicesFor( + $prefix, + $id_logo_img_size, + \__('Logo image size', 'italystrap'), + self::SECTION, + 'select', + 80 + ); + } } diff --git a/src/Customizer/SizeChoicesTrait.php b/src/Customizer/SizeChoicesTrait.php index b227ea0f..b55a9929 100644 --- a/src/Customizer/SizeChoicesTrait.php +++ b/src/Customizer/SizeChoicesTrait.php @@ -1,39 +1,41 @@ manager->add_setting( - $id, - [ - 'default' => $this->config->get($id), - 'type' => 'theme_mod', - 'transport' => 'refresh', - 'sanitize_callback' => 'sanitize_text_field', - ] - ); + private function registerSizeChoicesFor( + string $prefix, + string $id, + string $label, + string $section, + string $type, + int $priority + ): void { + $this->manager->add_setting( + $id, + [ + 'default' => $this->config->get($id), + 'type' => 'theme_mod', + 'transport' => 'refresh', + 'sanitize_callback' => 'sanitize_text_field', + ] + ); - $this->manager->add_control( - "{$prefix}_$id", - [ - 'settings' => $id, - 'label' => $label, - 'section' => $section, - 'type' => $type, - 'priority' => $priority, - 'choices' => $this->buildSizeChoices(), - ] - ); - } + $this->manager->add_control( + "{$prefix}_$id", + [ + 'settings' => $id, + 'label' => $label, + 'section' => $section, + 'type' => $type, + 'priority' => $priority, + 'choices' => $this->buildSizeChoices(), + ] + ); + } } diff --git a/src/Customizer/ThemeSubmenuPageSubscriber.php b/src/Customizer/ThemeSubmenuPageSubscriber.php index 46324e52..791c5f4a 100644 --- a/src/Customizer/ThemeSubmenuPageSubscriber.php +++ b/src/Customizer/ThemeSubmenuPageSubscriber.php @@ -1,29 +1,32 @@ [ - SubscriberInterface::CALLBACK => '__invoke', - ]; - } +class ThemeSubmenuPageSubscriber implements SubscriberInterface +{ + public function getSubscribedEvents(): iterable + { + yield 'admin_menu' => [ + SubscriberInterface::CALLBACK => '__invoke', + ]; + } - /** - * @link https://developer.wordpress.org/themes/advanced-topics/customizer-api/#focusing - * autofocus[panel|section|control]=ID - */ - public function __invoke(): void { - \add_submenu_page( - 'italystrap-dashboard', - \__('Theme Options', 'italystrap'), - \__('Theme Options', 'italystrap'), - 'edit_theme_options', - \admin_url('customize.php?autofocus[panel]=' . PanelFields::class) - ); - } + /** + * @link https://developer.wordpress.org/themes/advanced-topics/customizer-api/#focusing + * autofocus[panel|section|control]=ID + */ + public function __invoke(): void + { + \add_submenu_page( + 'italystrap-dashboard', + \__('Theme Options', 'italystrap'), + \__('Theme Options', 'italystrap'), + 'edit_theme_options', + \admin_url('customize.php?autofocus[panel]=' . PanelFields::class) + ); + } } diff --git a/src/Debug/Module.php b/src/Debug/Module.php new file mode 100644 index 00000000..42ebae6a --- /dev/null +++ b/src/Debug/Module.php @@ -0,0 +1,34 @@ + [ + DebugView::class, + ], + AurynConfig::ALIASES => [ + ViewInterface::class => DebugView::class + ], + AurynConfig::DEFINITIONS => [ + DebugView::class => [ + '+view' => static function (string $named_param, Injector $injector): ViewInterface { + $finder = (new ExperimentalViewFileFinderFactory())($named_param, $injector); + return $injector->make(View::class, [':finder' => $finder]); + }, + ], + ], + ]; + } +} diff --git a/src/Debug/View.php b/src/Debug/View.php index 6fe8e99d..76c233c2 100644 --- a/src/Debug/View.php +++ b/src/Debug/View.php @@ -4,30 +4,25 @@ namespace ItalyStrap\Debug; -use ItalyStrap\Config\Config_Interface; use ItalyStrap\View\ViewInterface; -use function func_get_args; final class View implements ViewInterface { + private ViewInterface $view; - - public function __construct( ViewInterface $view ) { + public function __construct(ViewInterface $view) { $this->view = $view; } - /** - * @inheritDoc - */ - public function render( $slugs, $data = [] ): string { + public function render($slugs, $data = []): string { if ($slugs === 'sidebar') { return $this->view->render( $slugs, $data ); } $slugs = (array)$slugs; -// $prefix = "
START DEBUG {$slugs[0]}
"; -// $suffix = "
END DEBUG {$slugs[0]}
"; + $prefix = "
START DEBUG {$slugs[0]}
"; + $suffix = "
END DEBUG {$slugs[0]}
"; $content = \sprintf( '%s%s%s', diff --git a/src/Experimental/ExperimentalConfigFilesFinderFactory.php b/src/Experimental/ExperimentalConfigFilesFinderFactory.php new file mode 100644 index 00000000..4958bdaf --- /dev/null +++ b/src/Experimental/ExperimentalConfigFilesFinderFactory.php @@ -0,0 +1,45 @@ + Parent + * 1 => Child + * @return FinderInterface + */ + public function __invoke(): FinderInterface + { + static $experimental_finder = null; + + if (!$experimental_finder) { + $experimental_finder = (new FinderFactory()) + ->make() + ->in(array_unique( + [ + /** + * To remember: + * This is the correct hierarchy to load and override + * the parent with child config. + */ + get_template_directory() . '/config/', + get_stylesheet_directory() . '/config/', + ] + )); + } + + return $experimental_finder; + } +} diff --git a/src/Experimental/ExperimentalCustomizerOptionWithAndPosition.php b/src/Experimental/ExperimentalCustomizerOptionWithAndPosition.php deleted file mode 100644 index 85bb8553..00000000 --- a/src/Experimental/ExperimentalCustomizerOptionWithAndPosition.php +++ /dev/null @@ -1,82 +0,0 @@ - 'registerThemePositions'; - - /** - * This filter is deprecated. Use 'italystrap_theme_positions' instead. - */ - yield 'italystrap_widget_area_position' => 'registerThemePositions'; - - yield 'italystrap_theme_width' => 'registerThemeWidth'; - } - - - /** - * Register theme position - * - * @param array $new_position - * - * @return array Array with theme position. - */ - public function registerThemePositions( array $new_position ): array { - return array_merge( - [ - 'italystrap_before' => \__( 'After the </body>', 'italystrap' ), - - 'italystrap_before_header' => \__( 'Before the header', 'italystrap' ), - 'italystrap_content_header' => \__( 'The content header', 'italystrap' ), - 'italystrap_after_header' => \__( 'After the header', 'italystrap' ), - - 'italystrap_before_main' => \__( 'Before the Main Content', 'italystrap' ), - 'italystrap_before_content' => \__( 'Before the Content', 'italystrap' ), - - 'italystrap_before_loop' => \__( 'Before the Loop', 'italystrap' ), - 'italystrap_loop' => \__( 'The Loop', 'italystrap' ), - 'italystrap_after_loop' => \__( 'After the Loop', 'italystrap' ), - - 'italystrap_after_content' => \__( 'After the Content', 'italystrap' ), - - 'italystrap_after_main' => \__( 'After the Main Content', 'italystrap' ), - 'italystrap_before_footer' => \__( 'In the footer open', 'italystrap' ), - 'italystrap_footer' => \__( 'In the footer', 'italystrap' ), - 'italystrap_after_footer' => \__( 'In the footer closed', 'italystrap' ), - - // phpcs:disable - 'italystrap_after' => \__( 'At the end of the page before the </body>', 'italystrap' ), - // phpcs:enable - ], - $new_position - ); - } - - /** - * Register theme width - * - * @param array $new_width - * @return array Array with theme position. - */ - public function registerThemeWidth( array $new_width ): array { - - $site_width = \apply_filters( - 'italystrap_theme_width_settings', - [ - // 'none' => \__( 'None', 'italystrap' ), - 'container' => \__( 'Standard container (deprecated)', 'italystrap' ), - 'container-fluid' => \__( 'Fluid container (deprecated)', 'italystrap' ), - ] - ); - - return array_merge( $site_width, $new_width ); - } -} diff --git a/src/Experimental/ExperimentalCustomizerOptionWithAndPositionSubscriber.php b/src/Experimental/ExperimentalCustomizerOptionWithAndPositionSubscriber.php new file mode 100644 index 00000000..99e006bf --- /dev/null +++ b/src/Experimental/ExperimentalCustomizerOptionWithAndPositionSubscriber.php @@ -0,0 +1,79 @@ + 'registerThemePositions'; + + /** + * This filter is deprecated. Use 'italystrap_theme_positions' instead. + */ + yield 'italystrap_widget_area_position' => 'registerThemePositions'; + + yield 'italystrap_theme_width' => 'registerThemeWidth'; + } + + + /** + * @param array $new_position + * + * @return array Array with theme position. + */ + public function registerThemePositions(array $new_position): array + { + return array_merge( + [ + 'italystrap_before' => \__('After the </body>', 'italystrap'), + + 'italystrap_before_header' => \__('Before the header', 'italystrap'), + 'italystrap_content_header' => \__('The content header', 'italystrap'), + 'italystrap_after_header' => \__('After the header', 'italystrap'), + + 'italystrap_before_main' => \__('Before the Main Content', 'italystrap'), + 'italystrap_before_content' => \__('Before the Content', 'italystrap'), + + 'italystrap_before_loop' => \__('Before the Loop', 'italystrap'), + 'italystrap_loop' => \__('The Loop', 'italystrap'), + 'italystrap_after_loop' => \__('After the Loop', 'italystrap'), + + 'italystrap_after_content' => \__('After the Content', 'italystrap'), + + 'italystrap_after_main' => \__('After the Main Content', 'italystrap'), + 'italystrap_before_footer' => \__('In the footer open', 'italystrap'), + 'italystrap_footer' => \__('In the footer', 'italystrap'), + 'italystrap_after_footer' => \__('In the footer closed', 'italystrap'), + + // phpcs:disable + 'italystrap_after' => \__( 'At the end of the page before the </body>', 'italystrap' ), + // phpcs:enable + ], + $new_position + ); + } + + /** + * @param array $new_width + * @return array Array with theme position. + */ + public function registerThemeWidth(array $new_width): array + { + + $site_width = \apply_filters( + 'italystrap_theme_width_settings', + [ + // 'none' => \__( 'None', 'italystrap' ), + 'container' => \__('Standard container (deprecated)', 'italystrap'), + 'container-fluid' => \__('Fluid container (deprecated)', 'italystrap'), + ] + ); + + return array_merge($site_width, $new_width); + } +} diff --git a/src/Experimental/ExperimentalHookComponentsDeprecationSubscriber.php b/src/Experimental/ExperimentalHookComponentsDeprecationSubscriber.php new file mode 100644 index 00000000..ddfa5625 --- /dev/null +++ b/src/Experimental/ExperimentalHookComponentsDeprecationSubscriber.php @@ -0,0 +1,240 @@ + 'onHeader'; + yield HeaderContent::class => 'onHeaderContent'; + yield BodyOpened::class => 'onBodyOpened'; + + yield FooterBefore::class => 'onFooterBefore'; + yield FooterAfter::class => 'onFooterAfter'; + yield Footer::class => 'onFooter'; + yield FooterContent::class => 'onFooterContent'; + yield BodyClosing::class => 'onBodyClosing'; + + yield SideabrBefore::class => 'onSidebarBefore'; + yield SidebarAfter::class => 'onSidebarAfter'; + + yield PostsContent::class => 'onPostsContent'; + yield PostsContentBefore::class => 'onPostsContentBefore'; + yield PostsContentAfter::class => 'onPostsContentAfter'; + + yield PostsNotFoundContent::class => 'onPostsNotFoundContent'; + yield PostsNotFound::class => 'onPostsNotFound'; + + yield PostContent::class => 'onPostContent'; + + yield IndexContent::class => 'onIndexContent'; + yield IndexContentBefore::class => 'onIndexContentBefore'; + yield IndexContentAfter::class => 'onIndexContentAfter'; + yield Index::class => 'onIndex'; + } + + public function __construct(GlobalDispatcher $globalDispatcher) + { + $this->globalDispatcher = $globalDispatcher; + } + + public function onIndex(Index $event) + { + } + + public function onIndexContent(IndexContent $event) + { + $this->appendContent( + [ + 'italystrap_before_loop', + 'italystrap_loop', + 'italystrap_after_loop', + ], + IndexContent::class, + $event + ); + } + + public function onIndexContentBefore(IndexContentBefore $event) + { + $this->appendContent(['italystrap_before_content'], IndexContentBefore::class, $event); + } + + public function onIndexContentAfter(IndexContentAfter $event) + { + $this->appendContent(['italystrap_after_content'], IndexContentAfter::class, $event); + } + + public function onPostsContent(PostsContent $event) + { + $this->appendContent( + [ + 'italystrap_before_entry', + 'italystrap_entry', + 'italystrap_after_entry', + ], + PostsContent::class, + $event + ); + } + + public function onPostsContentBefore(PostsContentBefore $event) + { + $this->appendContent(['italystrap_before_while'], PostsContentBefore::class, $event); + } + + public function onPostsContentAfter(PostsContentAfter $event) + { + $this->appendContent(['italystrap_after_while'], PostsContentAfter::class, $event); + } + + public function onPostsNotFoundContent(PostsNotFoundContent $event) + { + $this->appendContent( + [ + 'italystrap_before_entry_content_none', + 'italystrap_entry_content_none', + 'italystrap_after_entry_content_none', + ], + PostsNotFoundContent::class, + $event + ); + } + + public function onPostsNotFound(PostsNotFound $event) + { + $this->appendContent(['italystrap_content_none'], PostsNotFound::class, $event); + } + + public function onPostContent(PostContent $event) + { + $this->appendContent( + [ + 'italystrap_before_entry_content', + 'italystrap_entry_content', + 'italystrap_after_entry_content', + ], + PostContent::class, + $event + ); + } + + public function onSidebarBefore(SideabrBefore $event) + { + $this->appendContent(['italystrap_before_sidebar_widget_area'], SideabrBefore::class, $event); + } + + public function onSidebarAfter(SidebarAfter $event) + { + $this->appendContent(['italystrap_after_sidebar_widget_area'], SidebarAfter::class, $event); + } + + public function onHeader(Header $event) + { + $this->appendContent(['italystrap_header'], Header::class, $event); + } + + public function onHeaderContent(HeaderContent $event) + { + $this->appendContent( + [ + 'italystrap_before_header', + 'italystrap_content_header', + 'italystrap_after_header', + ], + HeaderContent::class, + $event + ); + } + + public function onBodyOpened(BodyOpened $event) + { + $this->appendContent(['italystrap_before'], BodyOpened::class, $event); + } + + public function onFooter(Footer $event) + { + $this->appendContent(['italystrap_after_main'], Footer::class, $event); + } + + public function onFooterContent(FooterContent $event) + { + $this->appendContent(['italystrap_footer'], FooterContent::class, $event); + } + + public function onBodyClosing(BodyClosing $event) + { + $this->appendContent(['italystrap_after'], BodyClosing::class, $event); + } + + public function onFooterBefore(FooterBefore $event) + { + $this->appendContent(['italystrap_before_footer'], FooterBefore::class, $event); + } + + public function onFooterAfter(FooterAfter $event) + { + $this->appendContent(['italystrap_after_footer'], FooterAfter::class, $event); + } + + private function appendContent(array $eventName, string $replacement, object $event): void + { + ob_start(); + foreach ($eventName as $name) { + $this->globalDispatcher->trigger($name); + $this->deprecatedEventName($name, $replacement); + } + $event->appendContent((string)ob_get_clean()); + } + + private function deprecatedEventName(string $eventName, string $replacement): void + { + if ( + !\is_user_logged_in() + || (isset($_SERVER['HTTP_X_TEST_REQUEST']) && isset($_SERVER['HTTP_X_WPBROWSER_REQUEST'])) + ) { + return; + } + + _deprecated_hook( + $eventName, + '4.0.0', + sprintf( + 'Use %s instead', + $replacement + ) + ); + } +} diff --git a/src/Experimental/ExperimentalThemeFileFinderFactory.php b/src/Experimental/ExperimentalThemeFileFinderFactory.php new file mode 100644 index 00000000..4c4b2f7b --- /dev/null +++ b/src/Experimental/ExperimentalThemeFileFinderFactory.php @@ -0,0 +1,30 @@ +make() + ->in(array_unique( + [ + /** + * To remember: + * This is the correct hierarchy to load and override + * the parent with child config. + */ + get_template_directory(), + get_stylesheet_directory(), + ] + )); + } +} diff --git a/src/Experimental/ExperimentalViewFileFinderFactory.php b/src/Experimental/ExperimentalViewFileFinderFactory.php new file mode 100644 index 00000000..f1a26013 --- /dev/null +++ b/src/Experimental/ExperimentalViewFileFinderFactory.php @@ -0,0 +1,29 @@ +make(ConfigInterface::class); + $stylesheet_dir = $config->get(ConfigThemeProvider::STYLESHEET_DIR); + $template_dir = $config->get(ConfigThemeProvider::TEMPLATE_DIR); + $view_dir = $config->get(ConfigThemeProvider::VIEW_DIR); + $finder = (new FinderFactory())->make() + ->in([ + $stylesheet_dir . '/' . $view_dir, + $template_dir . '/' . $view_dir, + ]); + return $finder; + } +} diff --git a/src/Experimental/OembedWrapper.php b/src/Experimental/OembedWrapper.php deleted file mode 100644 index f3aa2c4c..00000000 --- a/src/Experimental/OembedWrapper.php +++ /dev/null @@ -1,72 +0,0 @@ - [ - SubscriberInterface::CALLBACK => 'embedWrap', - SubscriberInterface::PRIORITY => 10, // 10 default - SubscriberInterface::ACCEPTED_ARGS => 4 // 3 default - ]; - } - - /** - * Wrap embedded media as suggested by Readability - * Add code to Oembed media - * - * @link https://gist.github.com/965956 - * @link http://www.readability.com/publishers/guidelines#publisher - * Rootstheme function - * Renamed and modify for new bootstrap class for video embed - * - * @since 1.0.0 - * @since 4.0.0 (Refactored) - * - * @see WP_Embed::shortcode() - * - * @param mixed $cache The cached HTML result, stored in post meta. - * @param string $url The attempted embed URL. - * @param array $attr An array of shortcode attributes. - * @param int $post_ID Post ID. - * - * @return string Return the new HTML. - */ - public function embedWrap( $cache, string $url, array $attr, int $post_ID ): string { - - if ( \strpos( $cache, 'class="twitter-tweet"' ) ) { - return $cache; - } - - $container_attr = get_attr( - 'embed-responsive', - [ - 'class' => 'entry-content-asset embed-responsive embed-responsive-16by9' - ] - ); - - $ifr_attr = get_attr( - 'embed-responsive-item', - [ - 'class' => 'embed-responsive-item' - ] - ); - - $elements = \explode(' ', $cache ); - - if ( ! \in_array( 'class', $elements, true ) ) { - \array_splice( $elements, 1, 0, \trim( $ifr_attr ) ); - } - - return \sprintf( - '%s', - $container_attr, - \implode( ' ', $elements ) - ); - } -} diff --git a/src/Experimental/OembedWrapperSubscriber.php b/src/Experimental/OembedWrapperSubscriber.php new file mode 100644 index 00000000..d699895e --- /dev/null +++ b/src/Experimental/OembedWrapperSubscriber.php @@ -0,0 +1,76 @@ + [ + SubscriberInterface::CALLBACK => $this, + SubscriberInterface::PRIORITY => 10, // 10 default + SubscriberInterface::ACCEPTED_ARGS => 4 // 3 default + ]; + } + + /** + * Wrap embedded media as suggested by Readability + * Add code to Oembed media + * + * @link https://gist.github.com/965956 + * @link http://www.readability.com/publishers/guidelines#publisher + * Rootstheme function + * Renamed and modify for new bootstrap class for video embed + * + * @since 1.0.0 + * @since 4.0.0 (Refactored) + * + * @see WP_Embed::shortcode() + * + * @param mixed $cache The cached HTML result, stored in post meta. + * @param string $url The attempted embed URL. + * @param array $attr An array of shortcode attributes. + * @param int $post_ID Post ID. + * + * @return string Return the new HTML. + */ + public function __invoke($cache, string $url, array $attr, int $post_ID): string + { + + if (\strpos($cache, 'class="twitter-tweet"')) { + return $cache; + } + + $container_attr = get_attr( + 'embed-responsive', + [ + 'class' => 'entry-content-asset embed-responsive embed-responsive-16by9' + ] + ); + + $ifr_attr = get_attr( + 'embed-responsive-item', + [ + 'class' => 'embed-responsive-item' + ] + ); + + $elements = \explode(' ', $cache); + + if (! \in_array('class', $elements, true)) { + \array_splice($elements, 1, 0, \trim($ifr_attr)); + } + + return \sprintf( + '%s', + $container_attr, + \implode(' ', $elements) + ); + } +} diff --git a/src/Experimental/PhpFileProvider.php b/src/Experimental/PhpFileProvider.php deleted file mode 100644 index 2562979c..00000000 --- a/src/Experimental/PhpFileProvider.php +++ /dev/null @@ -1,32 +0,0 @@ -pattern = $pattern; - $this->finder = $finder; - } - - /** - * @return \Generator - */ - public function __invoke(): \Generator { - $this->finder->names([$this->pattern]); - foreach ($this->finder as $file) { - yield include $file; - } - } -} diff --git a/src/Navbar/index.php b/src/Navbar/index.php deleted file mode 100644 index a5bcf147..00000000 --- a/src/Navbar/index.php +++ /dev/null @@ -1,4 +0,0 @@ - + * + * @forked from ItalyStrap + * @package ItalyStrap + * @since 4.0.0 + * @uses Walker_Nav_Menu_Edit + * @deprecated + */ +final class ItemCustomFieldsSubscriber implements SubscriberInterface +{ + /** + * Holds our custom fields + * + */ + private array $fields = []; + + private string $key_pattern; + + /** + * Init the constructor + */ + public function __construct() + { + $this->key_pattern = 'menu-item-%s'; + $this->setFields( + [ + [ + 'type' => 'text', + 'id' => 'glyphicon', + 'name' => 'glyphicon', + 'label' => __('Icon css class', 'italystrap'), + 'desc' => __('Example: fa fa-icon fa-3x', 'italystrap'), + ], + ] + ); + } + + /** + * Print field + * + * @param int $id Nav menu ID. + * @param object $item Menu item data object. + */ + public function printFields($id, $item) + { + + foreach ($this->getFields() as $field) : + $field = array_merge($this->defaultField(), $field); + $key = sprintf($this->key_pattern, $field[ 'id' ]); + $id = sprintf('edit-%s-%s', $key, $item->ID); + $name = sprintf('%s[%s]', $key, $item->ID); + $value = (string)get_post_meta($item->ID, $key, true); + $class = sprintf('field-%s', $field[ 'id' ]); + ?> +

+ $field[ 'type' ], + 'id' => '%1$s', + 'class' => 'widefat %1$s', + 'name' => '%3$s', + 'value' => '%4$s', + ] + ); + + printf( + '', + esc_attr($id), + esc_html($field[ 'label' ]), + esc_attr($name), + esc_attr($value) + ) ?> +
+ +

+ getFields() as $field) { + $var = $field[ 'id' ]; + $menu_item->$var = get_post_meta($menu_item->ID, sprintf($this->key_pattern, $var), true); + } + + return $menu_item; + } + + /** + * Save custom field value + * + * @wp_hook action wp_update_nav_menu_item + * + * @param int $menu_id Nav menu ID + * @param int $menu_item_db_id Menu item ID + * @param array $menu_item_args Menu item data + */ + public function saveFields(int $menu_id, int $menu_item_db_id, array $menu_item_args) + { + + if (defined('DOING_AJAX') && DOING_AJAX) { + return; + } + + check_admin_referer('update-nav_menu', 'update-nav-menu-nonce'); + + foreach ($this->getFields() as $field) { + $key = sprintf($this->key_pattern, $field[ 'id' ]); + + if (empty($_POST[ $key ][ $menu_item_db_id ])) { + delete_post_meta($menu_item_db_id, $key); + continue; + } + + update_post_meta($menu_item_db_id, $key, sanitize_text_field($_POST[ $key ][ $menu_item_db_id ])); + } + } + + /** + * Define new Walker edit + * + * @param string $class The walker class to use. + * Default 'Walker_Nav_Menu_Edit'. + * @param int $menu_id The menu id, derived from $_POST['menu']. + * + * @return string The new walker class to use. + */ + public function register(): string + { + return NavMenuEdit::class; + } + + /** + * Add our fields to the screen options toggle + * + * @param array $columns Menu item columns + * + * @return array + */ + public function columns($columns): array + { + return array_merge($columns, iterator_to_array($this->getColumns())); + } + + /** + * @return Generator + */ + private function getColumns() + { + foreach ($this->getFields() as $field) { + yield $field[ 'id' ] => $field[ 'label' ]; + } + } + + /** + * @return array + */ + private function getFields(): array + { + return $this->fields; + } + + /** + * @param array $fields + */ + private function setFields(array $fields) + { + $this->fields = $fields; + } + + /** + * @return array + */ + private function defaultField(): array + { + + $uniqid = uniqid(); + + return [ + 'type' => 'text', + 'id' => $uniqid, + 'name' => $uniqid, + 'label' => __('Label not provided', 'italystrap'), + 'desc' => '', + ]; + } + + /** + * Returns an array of events (hooks) that this subscriber wants to register with + * the Events Manager API. + * + * The array key is the name of the hook. The value can be: + * + * * The method name + * * An array with the method name and priority + * * An array with the method name, priority and number of accepted arguments + * + * For instance: + * + * array( + * // 'event_name' => 'method_name', + * 'italystrap_before_header' => 'render', + * ) + * array( + * // 'event_name' => 'method_name', + * 'italystrap_before_entry_content' => array( + * 'function_to_add' => 'render', + * 'priority' => 30, // Default 10 + * 'accepted_args' => 1 // Default 1 + * ), + * ); + * + * @return array + */ + public function getSubscribedEvents(): iterable + { + + /** + * Add new checkboxes to the "Screen options" menu + */ + yield 'manage_nav-menus_columns' => [ + SubscriberInterface::CALLBACK => 'columns', + SubscriberInterface::PRIORITY => 11, + ]; + + /** + * Add the value for new custom fields to the object in the Nav Walker + */ + yield 'wp_setup_nav_menu_item' => 'addCustomNavFields'; + + /** + * Save the value + */ + yield 'wp_update_nav_menu_item' => [ + SubscriberInterface::CALLBACK => 'saveFields', + SubscriberInterface::PRIORITY => 10, + SubscriberInterface::ACCEPTED_ARGS => 3, + ]; + + /** + * Display the added custom fields + */ + yield 'wp_nav_menu_item_custom_fields' => [ + SubscriberInterface::CALLBACK => 'printFields', + SubscriberInterface::PRIORITY => 10, + SubscriberInterface::ACCEPTED_ARGS => 5, + ]; + +// return [ + + /** + * Register new class for Menu Edit + */ +// 'wp_edit_nav_menu_walker' => [ +// SubscriberInterface::CALLBACK => 'register', +// 'accepted_args' => 2, +// ], + + /** + * Add new checkboxes to the "Screen options" menu + */ +// 'manage_nav-menus_columns' => [ +// SubscriberInterface::CALLBACK => 'columns', +// SubscriberInterface::PRIORITY => 11, +// ], + + /** + * Add the value fro new custom fields to the object in the Nav Walker + */ +// 'wp_setup_nav_menu_item' => 'addCustomNavFields', + + /** + * Save the value + */ +// 'wp_update_nav_menu_item' => [ +// SubscriberInterface::CALLBACK => 'saveFields', +// SubscriberInterface::PRIORITY => 10, +// SubscriberInterface::ACCEPTED_ARGS => 3, +// ], + + /** + * Display the added custom fields + */ +// 'wp_nav_menu_item_custom_fields' => [ +// SubscriberInterface::CALLBACK => 'printFields', +// SubscriberInterface::PRIORITY => 10, +// SubscriberInterface::ACCEPTED_ARGS => 5, +// ], +// ]; + } +} diff --git a/src/Admin/Nav_Menu/NavMenuEdit.php b/src/Navigation/Admin/NavMenuEdit.php similarity index 97% rename from src/Admin/Nav_Menu/NavMenuEdit.php rename to src/Navigation/Admin/NavMenuEdit.php index 87dca0ef..e8216812 100644 --- a/src/Admin/Nav_Menu/NavMenuEdit.php +++ b/src/Navigation/Admin/NavMenuEdit.php @@ -9,11 +9,12 @@ * @since 3.0.0 */ -namespace ItalyStrap\Admin\Nav_Menu; +namespace ItalyStrap\Navigation\Admin; /** * @infection-ignore-all */ -use \Walker_Nav_Menu_Edit; + +use Walker_Nav_Menu_Edit; /** * Custom Walker for Nav Menu Editor diff --git a/src/Navigation/Application/NavMenusSubscriber.php b/src/Navigation/Application/NavMenusSubscriber.php new file mode 100644 index 00000000..11474297 --- /dev/null +++ b/src/Navigation/Application/NavMenusSubscriber.php @@ -0,0 +1,68 @@ + $this; + } + + public function __construct(ConfigInterface $config, NavMenuLocation $location) + { + $this->config = $config; + $this->location = $location; + } + + public function __invoke() + { + $this->location->registerMany((array)$this->config->get(self::class, [])); + $this->updateOlderNavMenu(); + } + + private function updateOlderNavMenu(): void + { + + $update = 1; + + if ((int)\get_theme_mod('nav_menu_locations_update') < $update) { + $menu_location = \get_nav_menu_locations(); + + $new_keys = [ + 'main-menu' => NavMenuPrimary::class, + 'secondary-menu' => NavMenuSecondary::class, +// 'social-menu' => '0', +// 'info-menu' => '0', +// 'footer-menu' => '0', + ]; + + $new_menu_locations = []; + foreach ($menu_location as $location => $menu_id) { + if (! \array_key_exists((string)$location, $new_keys)) { + continue; + } + + if ($menu_id === 0) { + continue; + } + + $new_menu_locations[$new_keys[$location]] = $menu_id; + } + + \set_theme_mod('nav_menu_locations', $new_menu_locations); + \set_theme_mod('nav_menu_locations_update', $update); + } + } +} diff --git a/src/Navigation/Domain/NavMenu.php b/src/Navigation/Domain/NavMenu.php new file mode 100644 index 00000000..59f57eff --- /dev/null +++ b/src/Navigation/Domain/NavMenu.php @@ -0,0 +1,71 @@ +walker = $walker; + $this->fallback_cb = $fallback_cb ?? 'wp_page_menu'; + } + + public function render(array $options = []): string + { + return (string)wp_nav_menu(\array_replace($this->getDefaultOptions(), $options)); + } + + private function getDefaultOptions(): array + { + return [ + self::MENU => '', + self::CONTAINER => '', + self::CONTAINER_CLASS_NAME => '', + self::CONTAINER_ID => '', + self::MENU_CLASS_NAME => '', + self::MENU_ID => '', + self::ECHO => false, + self::FALLBACK_CB => $this->fallback_cb, + self::BEFORE => '', + self::AFTER => '', + self::LINK_BEFORE => '', + self::LINK_AFTER => '', + self::ITEMS_WRAP => '
    %3$s
', + self::ITEMS_SPACING => 'preserve', + self::DEPTH => 10, + self::WALKER => $this->walker, + self::THEME_LOCATION => '', + self::SEARCH => false, + ]; + } +} diff --git a/src/Navigation/Domain/NavMenuInterface.php b/src/Navigation/Domain/NavMenuInterface.php new file mode 100644 index 00000000..e7f98355 --- /dev/null +++ b/src/Navigation/Domain/NavMenuInterface.php @@ -0,0 +1,10 @@ +dispatcher = $dispatcher ?? new EventDispatcher(); + public function __construct( ListenerRegisterInterface $listenerRegister = null ) { + $this->listenerRegister = $listenerRegister ?? new GlobalOrderedListenerProvider(); } /** @@ -65,9 +66,9 @@ public function start_lvl( &$output, $depth = 0, $args = [] ) { return $classes; }; - $this->dispatcher->addListener( 'nav_menu_submenu_css_class', $listener, 10, 3 ); + $this->listenerRegister->addListener( 'nav_menu_submenu_css_class', $listener, 10, 3 ); parent::start_lvl( $output, $depth, $args ); - $this->dispatcher->removeListener( 'nav_menu_submenu_css_class', $listener ); + $this->listenerRegister->removeListener( 'nav_menu_submenu_css_class', $listener ); $output = \str_replace( 'class=', 'role="menu" class=', $output ); } diff --git a/src/Navigation/Infrastructure/Config/ConfigNavigationProvider.php b/src/Navigation/Infrastructure/Config/ConfigNavigationProvider.php new file mode 100644 index 00000000..d23e32d0 --- /dev/null +++ b/src/Navigation/Infrastructure/Config/ConfigNavigationProvider.php @@ -0,0 +1,36 @@ + [ + /** + * options: + * navbar-default + * navbar-inverse + */ + 'type' => 'navbar-inverse', + 'position' => 'navbar-static-top', + 'nav_width' => 'none', // This is the container of entire navbar. + 'menus_width' => 'container', // This is the container of the 2 menus inside the nav container + //and the navbar_header brand and toggle. + 'main_menu_x_align' => 'navbar-left', + ], + NavMenusSubscriber::class => + [ + NavMenuPrimary::class => \__('Primary menu', 'italystrap'), + NavMenuSecondary::class => \__('Secondary menu', 'italystrap'), + ], + ]; + } +} diff --git a/src/Navigation/Infrastructure/NavMenuFallback.php b/src/Navigation/Infrastructure/NavMenuFallback.php new file mode 100644 index 00000000..f272bae4 --- /dev/null +++ b/src/Navigation/Infrastructure/NavMenuFallback.php @@ -0,0 +1,66 @@ +attributes = $attributes; + $this->tag = $tag; + } + + /** + * Menu Fallback + * ============= + * If this function is assigned to the wp_nav_menu's fallback_cb variable + * and a menu has not been assigned to the theme location in the WordPress + * menu manager the function with display nothing to a non-logged in user, + * and will add a link to the WordPress menu manager if logged in as an admin. + * + * @param array $wp_nav_menu_args passed from the wp_nav_menu function. + * @return string + */ + public function __invoke(array $wp_nav_menu_args): string + { + + if (! \current_user_can('manage_options')) { + return ''; + } + + $output = $this->tag->open( + self::class, + $wp_nav_menu_args[ NavMenu::CONTAINER ] ?? '', + [ + 'id' => $wp_nav_menu_args[ NavMenu::CONTAINER_ID ], + 'class' => $wp_nav_menu_args[ NavMenu::CONTAINER_CLASS_NAME ] + ] + ); + + $output .= \sprintf( + '
  • %s
  • ', + $this->attributes->render( + self::class, + [ + 'id' => $wp_nav_menu_args[ NavMenu::MENU_ID ], + 'class' => $wp_nav_menu_args[ NavMenu::MENU_CLASS_NAME ] + ] + ), + (string)\admin_url('nav-menus.php') ?? '', + \__('Add a menu', 'italystrap') + ); + + $output .= $this->tag->close(self::class); + + return $output; // XSS ok. + } +} diff --git a/src/Navigation/Module.php b/src/Navigation/Module.php new file mode 100644 index 00000000..1d2e35fe --- /dev/null +++ b/src/Navigation/Module.php @@ -0,0 +1,85 @@ + [ + ], + AurynConfig::ALIASES => [ + NavMenuLocationInterface::class => NavMenuLocation::class, + NavMenuInterface::class => NavMenu::class, + Walker_Nav_Menu::class => BootstrapNavMenu::class, + ], + + AurynConfig::DEFINITIONS => [ + + Navbar::class => [ + ':fallback_cb' => [ BootstrapNavMenu::class, 'fallback' ], + ], + + NavMenuPrimary::class => [ + '+fallback' => static fn(string $named_param, Injector $injector): callable => $injector->make(NavMenuFallback::class), + ], + ], + + ConfigProviderExtension::class => [ + ConfigNavigationProvider::class, + ], + + SubscribersConfigExtension::SUBSCRIBERS => [ + ItemCustomFieldsSubscriber::class, + NavMenusSubscriber::class, + ], + ComponentSubscriberExtension::class => [ + Breadcrumbs::class, + + NavMenuToggleButton::class, + NavMenuHeader::class, + NavMenuPrimary::class, + NavMenuSecondary::class, + MainNavigationOlder::class, + // MainNavigation::class, + + MiscNavigation::class, + +// Navbar::class, + NavMenuPrimary::class, + + Pager::class, + Pagination::class, + ], + ]; + } +} diff --git a/src/Navigation/NavMenu.php b/src/Navigation/NavMenu.php deleted file mode 100644 index bd35459c..00000000 --- a/src/Navigation/NavMenu.php +++ /dev/null @@ -1,68 +0,0 @@ -walker = $walker; - $this->fallback_cb = $fallback_cb ?? 'wp_page_menu'; - } - - public function render( array $options = [] ): string { - return (string)wp_nav_menu( \array_replace( $this->getDefaultOptions(), $options ) ); - } - - private function getDefaultOptions(): array { - return [ - self::MENU => '', - self::CONTAINER => '', - self::CONTAINER_CLASS_NAME => '', - self::CONTAINER_ID => '', - self::MENU_CLASS_NAME => '', - self::MENU_ID => '', - self::ECHO => false, - self::FALLBACK_CB => $this->fallback_cb, - self::BEFORE => '', - self::AFTER => '', - self::LINK_BEFORE => '', - self::LINK_AFTER => '', - self::ITEMS_WRAP => '
      %3$s
    ', - self::ITEMS_SPACING => 'preserve', - self::DEPTH => 10, - self::WALKER => $this->walker, - self::THEME_LOCATION => '', - self::SEARCH => false, - ]; - } -} diff --git a/src/Navigation/NavMenuFallback.php b/src/Navigation/NavMenuFallback.php deleted file mode 100644 index 4cf425f8..00000000 --- a/src/Navigation/NavMenuFallback.php +++ /dev/null @@ -1,62 +0,0 @@ -attributes = $attributes; - $this->tag = $tag; - } - - /** - * Menu Fallback - * ============= - * If this function is assigned to the wp_nav_menu's fallback_cb variable - * and a menu has not been assigned to the theme location in the WordPress - * menu manager the function with display nothing to a non-logged in user, - * and will add a link to the WordPress menu manager if logged in as an admin. - * - * @param array $wp_nav_menu_args passed from the wp_nav_menu function. - * @return string - */ - public function __invoke( array $wp_nav_menu_args ): string { - - if ( ! \current_user_can( 'manage_options' ) ) { - return ''; - } - - $output = $this->tag->open( - self::class, - $wp_nav_menu_args[ NavMenu::CONTAINER ] ?? '', - [ - 'id' => $wp_nav_menu_args[ NavMenu::CONTAINER_ID ], - 'class' => $wp_nav_menu_args[ NavMenu::CONTAINER_CLASS_NAME ] - ] - ); - - $output .= \sprintf( - '
  • %s
  • ', - $this->attributes->render( - self::class, - [ - 'id' => $wp_nav_menu_args[ NavMenu::MENU_ID ], - 'class' => $wp_nav_menu_args[ NavMenu::MENU_CLASS_NAME ] - ] - ), - (string)\admin_url( 'nav-menus.php' ) ?? '', - \__( 'Add a menu', 'italystrap' ) - ); - - $output .= $this->tag->close(self::class); - - return $output; // XSS ok. - } -} diff --git a/src/Navigation/NavMenuInterface.php b/src/Navigation/NavMenuInterface.php deleted file mode 100644 index a83c95ca..00000000 --- a/src/Navigation/NavMenuInterface.php +++ /dev/null @@ -1,8 +0,0 @@ - [ + SubscriberInterface::CALLBACK => $this, + SubscriberInterface::PRIORITY => self::EVENT_PRIORITY, + ]; + } + + private GlobalDispatcherInterface $dispatcher; + private ConfigInterface $config; + private Support $support; + + public function __construct( + GlobalDispatcherInterface $dispatcher, + ConfigInterface $config, + Support $support + ) { + $this->dispatcher = $dispatcher; + $this->config = $config; + $this->support = $support; + } + + public function shouldDisplay(): bool + { + return $this->support->has('breadcrumbs') + && \in_array( + $this->config->get('current_template_file'), + \explode(',', $this->config->get('breadcrumbs_show_on', '')), + true + ) + && ! \in_array('hide_breadcrumbs', $this->config->get('post_content_template'), true); + } + + /** + * @examples: + * $args = [ + * 'home' => '', + * ]; + */ + public function __invoke(Content $event): void + { + ob_start(); + $this->dispatcher->trigger('do_breadcrumbs', []); + $event->appendContent((string)ob_get_clean()); + } +} diff --git a/src/Navigation/UI/Components/Events/NavMenuHeaderContent.php b/src/Navigation/UI/Components/Events/NavMenuHeaderContent.php new file mode 100644 index 00000000..da15237d --- /dev/null +++ b/src/Navigation/UI/Components/Events/NavMenuHeaderContent.php @@ -0,0 +1,13 @@ +dispatcher = $dispatcher; + } + /** + * Render the output of the controller. + */ + public function render(): string + { + + /** + * Arguments for wp_link_pages + * + * @link https://developer.wordpress.org/reference/functions/wp_link_pages/ + * @var array + */ + $args = [ + 'echo' => false, + ]; + + $args = $this->dispatcher->filter('italystrap_wp_link_pages_args', $args); + + return wp_link_pages($args); + } +} diff --git a/src/Navigation/UI/Components/MainNavigation.php b/src/Navigation/UI/Components/MainNavigation.php new file mode 100644 index 00000000..b1fe1021 --- /dev/null +++ b/src/Navigation/UI/Components/MainNavigation.php @@ -0,0 +1,50 @@ +config = $config; + $this->view = $view; + $this->dispatcher = $dispatcher; + } + + public function shouldDisplay(): bool + { + return true; + } + + public function display(): void + { + echo \do_blocks($this->view->render(self::TEMPLATE_NAME, [ + EventDispatcherInterface::class => $this->dispatcher, + self::CONTEXT => 'this-context', + ])); + } +} diff --git a/src/Navigation/UI/Components/MainNavigationOlder.php b/src/Navigation/UI/Components/MainNavigationOlder.php new file mode 100644 index 00000000..7b911c9b --- /dev/null +++ b/src/Navigation/UI/Components/MainNavigationOlder.php @@ -0,0 +1,54 @@ +config = $config; + $this->view = $view; + $this->navbar = $navbar; + $this->navMenuPrimary = $navMenuPrimary; + $this->navMenuSecondary = $navMenuSecondary; + } + + public function shouldDisplay(): bool + { + return true; + } + + public function display(): void + { + echo \do_blocks($this->view->render('navigation/navbar', [ + 'mods' => $this->config, + Navbar::class => $this->navbar, + NavMenuPrimary::class => $this->navMenuPrimary, + NavMenuSecondary::class => $this->navMenuSecondary, + ])); + } +} diff --git a/src/Navigation/UI/Components/MiscNavigation.php b/src/Navigation/UI/Components/MiscNavigation.php new file mode 100644 index 00000000..12880a16 --- /dev/null +++ b/src/Navigation/UI/Components/MiscNavigation.php @@ -0,0 +1,49 @@ +config = $config; + $this->view = $view; + $this->dispatcher = $dispatcher; + } + + public function shouldDisplay(): bool + { + return \has_nav_menu('info-menu') + && \has_nav_menu('social-menu'); + } + + public function display(): void + { + echo \do_blocks($this->view->render(self::TEMPLATE_NAME, [ + EventDispatcherInterface::class => $this->dispatcher, + ])); + } +} diff --git a/src/Navigation/UI/Components/NavMenuHeader.php b/src/Navigation/UI/Components/NavMenuHeader.php new file mode 100644 index 00000000..0ea8ada3 --- /dev/null +++ b/src/Navigation/UI/Components/NavMenuHeader.php @@ -0,0 +1,51 @@ +config = $config; + $this->view = $view; + $this->globalDispatcher = $globalDispatcher; + $this->dispatcher = $dispatcher; + } + + public function shouldDisplay(): bool + { + return true; + } + + public function display(): void + { + echo $this->view->render('navigation/header', [ + GlobalDispatcherInterface::class => $this->globalDispatcher, + EventDispatcherInterface::class => $this->dispatcher, + ]); + } +} diff --git a/src/Navigation/UI/Components/NavMenuPrimary.php b/src/Navigation/UI/Components/NavMenuPrimary.php new file mode 100644 index 00000000..e18d9b3c --- /dev/null +++ b/src/Navigation/UI/Components/NavMenuPrimary.php @@ -0,0 +1,63 @@ +config = $config; + $this->view = $view; + $this->menu = $menu; + $this->location = $location; + $this->fallback = $fallback; + } + + public function shouldDisplay(): bool + { + return true; + } + + public function display(): void + { + echo $this->menu->render([ + NavMenu::MENU_CLASS_NAME => \sprintf( + 'nav navbar-nav %s', + $this->config->get('mods.navbar.main_menu_x_align') + ), + NavMenu::MENU_ID => 'main-menu', + NavMenu::FALLBACK_CB => $this->fallback, + NavMenu::THEME_LOCATION => self::class, + ]); + } +} diff --git a/src/Navigation/UI/Components/NavMenuSecondary.php b/src/Navigation/UI/Components/NavMenuSecondary.php new file mode 100644 index 00000000..27779381 --- /dev/null +++ b/src/Navigation/UI/Components/NavMenuSecondary.php @@ -0,0 +1,53 @@ +config = $config; + $this->view = $view; + $this->menu = $menu; + $this->location = $location; + } + + public function shouldDisplay(): bool + { + return $this->location->has(self::class); + } + + public function display(): void + { + echo $this->menu->render([ + NavMenu::MENU_CLASS_NAME => 'nav navbar-nav navbar-right', + NavMenu::MENU_ID => 'secondary-menu', + NavMenu::FALLBACK_CB => false, + NavMenu::THEME_LOCATION => self::class, + ]); + } +} diff --git a/src/Navigation/UI/Components/NavMenuToggleButton.php b/src/Navigation/UI/Components/NavMenuToggleButton.php new file mode 100644 index 00000000..629bb8a9 --- /dev/null +++ b/src/Navigation/UI/Components/NavMenuToggleButton.php @@ -0,0 +1,52 @@ +config = $config; + $this->view = $view; + $this->dispatcher = $dispatcher; + } + + public function shouldDisplay(): bool + { + return true; + } + + public function display(): void + { + echo ''; + } +} diff --git a/src/Navigation/UI/Components/Navbar.php b/src/Navigation/UI/Components/Navbar.php new file mode 100644 index 00000000..1b99f669 --- /dev/null +++ b/src/Navigation/UI/Components/Navbar.php @@ -0,0 +1,507 @@ +config = $config; + $this->walker = $walker; + $this->fallback_cb = $fallback_cb; + + /** + * Count this instance + */ + self::$instance_count++; + + $this->number = self::$instance_count; + + $this->navbar_id = \apply_filters('italystrap_navbar_id', 'italystrap-menu-' . $this->number); + $this->navbar_id = \apply_filters('italystrap_navbar_id_' . $this->number, $this->navbar_id); + + $this->menu = $menu; + } + + /** + * Get the wp_nav_menu with default parameters for Bootstrap CSS style + * + * @param array $args The wp_nav_menu arguments. + * + * @return false|null|string Return the wp_nav_menu HTML + */ + public function get_wp_nav_menu( array $args = [] ) {// phpcs:ignore + + /** + * Arguments for wp_nav_menu() + * For filtering wp_nav_menu use the 'wp_nav_menu' hooks with 2 parameters + * add_filter( 'wp_nav_menu', 'your_functions', 10, 2 ); + * For this situation the container attribute is set to false because + * we need the collapsable functionality of Bootstrap CSS. + * + * @todo Non credo mi possa essere utile https://github.com/devaloka/nav-menu ma si + * potrebbe comunque creare una classe a parte per wp_nav_menu e togliere da qui. + * + * @link https://developer.wordpress.org/reference/functions/wp_nav_menu/ + * @var array + */ + $defaults = [ + 'menu' => '', + 'container' => false, + // WP Default div. + 'container_class' => false, + 'container_id' => false, + 'menu_class' => \sprintf( + 'nav navbar-nav %s', + $this->config->get('navbar.main_menu_x_align') + ), + 'menu_id' => 'main-menu', + 'echo' => false, + 'fallback_cb' => $this->fallback_cb, + 'before' => '', + 'after' => '', + 'link_before' => '', + 'link_after' => '', + 'items_wrap' => '
      %3$s
    ', + 'item_spacing' => 'preserve', + 'depth' => 10, + 'walker' => $this->walker, + 'theme_location' => 'main-menu', + 'search' => false, + ]; + + $args = wp_parse_args($args, $defaults); + + $args = apply_filters('italystrap_' . $args[ 'theme_location' ] . '_args', $args, $this->navbar_id); + + return wp_nav_menu($args); + } + + /** + * Get secondary wp-nav-menu + * + * @return false|null|string Return the secondary wp_nav_menu HTML + */ + public function get_secondary_wp_nav_menu() {// phpcs:ignore + + if (! has_nav_menu('secondary-menu')) { + return ''; + } + + $args = [ + 'menu_class' => 'nav navbar-nav navbar-right', + 'menu_id' => 'secondary-menu', + 'fallback_cb' => false, + 'theme_location' => 'secondary-menu' + ]; + + return $this->get_wp_nav_menu($args); + } + + /** + * Get Brand + * + * @return string Return the HTML for brand name and/or image. + */ + public function get_brand() {// phpcs:ignore + + /** + * The ID of the logo image for navbar + * By default in the customizer is set a url for the image instead of an integer + * When it is choices an image than it will set an integer for $this->config['navbar_logo'] + * + * @var integer + */ + $attachment_id = (int)apply_filters( + 'italystrap_navbar_logo_image_id', + $this->config->get(ConfigSiteLogoProvider::BRAND_IMAGE_ID) + ); + + $brand = ''; + + if ($attachment_id && 'display_image' === $this->config[ 'display_navbar_brand' ]) { + $attr = ['class' => 'img-brand img-responsive center-block', 'alt' => esc_attr(\get_option('blogname')) + . ' ‐ ' + . esc_attr(\get_option('blogdescription')), 'itemprop' => 'image']; + + /** + * Size default: navbar-brand-image + */ + $brand .= wp_get_attachment_image( + $attachment_id, + $this->config[ 'navbar_logo_image_size' ], + false, + $attr + ); + + $brand .= ''; + } elseif ($attachment_id && 'display_all' === $this->config[ 'display_navbar_brand' ]) { + $attr = [ + 'class' => 'img-brand img-responsive center-block', + 'alt' => esc_attr(\get_option('blogname')) + . ' - ' + . esc_attr(\get_option('blogdescription')), + 'itemprop' => 'image', + 'style' => 'display:inline;margin-right:15px;' + ]; + + /** + * Size default: navbar-brand-image + */ + $brand .= wp_get_attachment_image( + $attachment_id, + $this->config[ 'navbar_logo_image_size' ], + false, + $attr + ); + + $brand .= '' + . esc_attr(\get_option('blogname')) . ''; + } else { + $brand .= '' + . esc_attr(\get_option('blogname')) + . ''; + } + + return $brand; + } + + /** + * Get the HTML for description + * + * @param array $attr The navbar brand attributes. + * + * @return string Return the HTML for description + */ + public function get_navbar_brand( array $attr = [] ) {// phpcs:ignore + + if ('none' === $this->config[ 'display_navbar_brand' ]) { + return apply_filters('italystrap_navbar_brand_none', '', $this->navbar_id); + } + + $default = [ + 'class' => 'navbar-brand', + 'href' => esc_url($this->config->get('HOME_URL')), + 'title' => sprintf( + '%s - %s', + \get_option('blogname'), + \get_option('blogdescription') + ), + 'rel' => 'home', + 'itemprop' => 'url' + ]; + + return $this->createElement( + 'navbar_brand', + 'a', + array_merge($default, $attr), + $this->get_brand() + ); + } + + /** + * Get the HTML for toggle button + * + * @return string Return the HTML for toggle button + */ + public function get_toggle_button() {// phpcs:ignore + + $icon_bar = apply_filters( + 'italystrap_icon_bar', + '   ' + ); + + $a = ['class' => 'navbar-toggle', 'data-toggle' => 'collapse', 'data-target' => '#' . $this->navbar_id]; + +// $output = sprintf( +// '%s%s', +// $this->get_attr( $a, 'toggle_button' ), +// esc_attr__( 'Toggle navigation', 'italystrap' ), +// $icon_bar +// ); +// +// return apply_filters( 'italystrap_toggle_button', $output, $this->navbar_id ); + /** + * '%s%s' + */ + return $this->createElement( + 'toggle_button', + 'button', + $a, + $this->createElement( + 'toggle_button_content', + 'span', + ['class' => 'sr-only screen-reader-text'], + esc_attr__('Toggle navigation', 'italystrap') + ) . trim($icon_bar) + ); + } + + /** + * Get the HTML for Navbar Header + * + * @return string Return the HTML for Navbar Header + */ + public function get_navbar_header() {// phpcs:ignore + + $a = [ + 'class' => 'navbar-header', + 'itemprop' => 'publisher', + 'itemscope' => true, + 'itemtype' => 'https://schema.org/Organization', + ]; + + return $this->createElement( + 'navbar_header', + 'div', + $a, + $this->get_navbar_brand() . $this->get_toggle_button() + ); + } + + /** + * Get the collapsable HTML menu + * + * http://bootsnipp.com/snippets/featured/expanding-search-button-in-css + * + * @return string Return the HTML + */ + public function get_collapsable_menu() {// phpcs:ignore + + $a = [ + 'id' => $this->navbar_id, + 'class' => 'navbar-collapse collapse', + ]; + + return $this->createElement( + 'collapsable_menu', + 'div', + $a, + $this->get_wp_nav_menu() . $this->get_secondary_wp_nav_menu() + ); + } + + /** + * A container inside the navbar-default/revers + * + * @return string The html output. + */ + public function get_last_container() {// phpcs:ignore +// add_filter( 'italystrap_pre_last_container', '__return_true' ); + $a = [ + 'id' => 'menus-container-' . $this->number, + 'class' => $this->config[ 'navbar' ][ 'menus_width' ], + ]; + + return $this->createElement( + 'last_container', + 'div', + $a, + $this->get_navbar_header() . $this->get_collapsable_menu() + ); + } + + /** + * The regulare navbar container, + * this manage the type of navabr available from Twitter Bootstrap + * + * @see http://getbootstrap.com/components/#navbar + * + * navbar-default + * navbar-inverse + * + * navbar navbar-default navbar-relative-top + * + * navbar navbar-default navbar-fixed-top // body { padding-top: 70px; } + * navbar navbar-default navbar-fixed-bottom // body { padding-bottom: 70px; } + * + * navbar navbar-default navbar-static-top + * + * @return string The navbar string. + */ + public function get_navbar_container() {// phpcs:ignore + + $a = [ + 'class' => sprintf( + 'navbar %s %s', + $this->config[ 'navbar' ][ 'type' ], + $this->config[ 'navbar' ][ 'position' ] + ), + 'itemscope' => true, + 'itemtype' => 'https://schema.org/SiteNavigationElement', + ]; + + return $this->createElement( + 'navbar_container', + 'nav', + $a, + $this->get_last_container() + ); + } + + /** + * Generate the nav tag container of entire navbar + * + * @see http://getbootstrap.com/components/#navbar + * + * This manage the full width or boxed width (.conainer or null) + * + * @return string Return the entire navbar. + */ + public function get_nav_container() {// phpcs:ignore + +// if ( 'none' === $this->config[ 'navbar' ][ 'nav_width' ] ) { +// return $this->get_navbar_container(); +// } + +// d( $this->config ); + + $a = [ + 'id' => 'main-navbar-container-' . $this->navbar_id, + 'class' => sprintf( + 'navbar-wrapper %s', + $this->config[ 'navbar' ][ 'nav_width' ] + ), + ]; + + return $this->createElement('nav_container', 'div', $a, $this->get_navbar_container()); + } + + /** + * @param string $context + * @param string $tag + * @param array $attr + * @param string $content + * @return string + */ + private function createElement(string $context, string $tag, array $attr, string $content): string + { + +// if ( !is_string( $context ) ) { +// throw new \InvalidArgumentException( 'The $context variable must be a string', 0 ); +// } +// +// if ( !is_string( $tag ) ) { +// throw new \InvalidArgumentException( 'The $tag variable must be a string', 0 ); +// } +// +// if ( !is_string( $content ) ) { +// throw new \InvalidArgumentException( 'The $content variable must be a string', 0 ); +// } + + $content = (string)apply_filters('italystrap_' . $context . '_child', $content, $this->navbar_id); + + if (empty($content)) { + $content = ' '; + } + + if ((bool) apply_filters('italystrap_pre_' . $context, false)) { + return $content; + } + + $tag = apply_filters('italystrap_' . $context . '_tag', $tag, $this->navbar_id); + + $output = sprintf( + '<%1$s%2$s>%3$s', + esc_attr($tag), + $this->getAttr($attr, $context), + $content + ); + + return apply_filters('italystrap_' . $context, $output, $this->navbar_id); + } + + /** + * Render the HTML tag attributes from an array + * + * @param array $attr The HTML attributes with key value. + * @param string $context + * + * @return string Return a string with HTML attributes + */ + private function getAttr(array $attr = [], $context = '') + { + return get_attr($context, $attr, false, $this->navbar_id); + } + + /** + * @return string + */ + public function render() + { + return $this->get_nav_container(); + } + + /** + * Output the HTML + */ + public function output(): void + { + echo $this->render(); + } +} diff --git a/src/Navigation/UI/Components/Pager.php b/src/Navigation/UI/Components/Pager.php new file mode 100644 index 00000000..bdc3dcb0 --- /dev/null +++ b/src/Navigation/UI/Components/Pager.php @@ -0,0 +1,41 @@ +config = $config; + $this->view = $view; + } + + public function shouldDisplay(): bool + { + return \is_single() + && \post_type_supports((string)\get_post_type(), 'post_navigation'); + } + + public function display(): void + { + echo \do_blocks($this->view->render(self::TEMPLATE_NAME)); + } +} diff --git a/src/Navigation/UI/Components/Pagination.php b/src/Navigation/UI/Components/Pagination.php new file mode 100644 index 00000000..4d4f332c --- /dev/null +++ b/src/Navigation/UI/Components/Pagination.php @@ -0,0 +1,40 @@ +config = $config; + $this->view = $view; + } + + public function shouldDisplay(): bool + { + return ! \is_404(); + } + + public function display(): void + { + echo \do_blocks($this->view->render(self::TEMPLATE_NAME)); + } +} diff --git a/src/StdLib/CMB2Factory.php b/src/StdLib/CMB2Factory.php deleted file mode 100644 index 7d825d0c..00000000 --- a/src/StdLib/CMB2Factory.php +++ /dev/null @@ -1,10 +0,0 @@ - [ - SubscriberInterface::CALLBACK => Registrable::REGISTER_CB, - SubscriberInterface::PRIORITY => 1, - ]; - } - - public function __construct( Injector $injector, EventDispatcher $dispatcher ) { - $this->dispatcher = $dispatcher; - $this->injector = $injector; - } - - /** - * @return void - */ - public function register() { - - /** - * Fires before ItalyStrap theme load. - * - * @since 4.0.0 - */ - $this->dispatcher->dispatch( 'italystrap_theme_will_load', $this->injector ); - - /** - * Fires once ItalyStrap theme is loading. - * - * @since 4.0.0 - */ - $this->dispatcher->dispatch( 'italystrap_theme_load', $this->injector ); - - /** - * Fires once ItalyStrap theme has loaded. - * - * @since 4.0.0 - */ - $this->dispatcher->dispatch( 'italystrap_theme_loaded', $this->injector ); - } -} diff --git a/src/Theme/Application/AfterSetupThemeSubscriber.php b/src/Theme/Application/AfterSetupThemeSubscriber.php new file mode 100644 index 00000000..2adeb36e --- /dev/null +++ b/src/Theme/Application/AfterSetupThemeSubscriber.php @@ -0,0 +1,63 @@ + [ + SubscriberInterface::CALLBACK => $this, + SubscriberInterface::PRIORITY => 1, + ]; + } + + public function __construct(Injector $injector, GlobalDispatcherInterface $globalDispatcher) + { + $this->globalDispatcher = $globalDispatcher; + $this->injector = $injector; + } + + public function __invoke(): void + { + + /** + * Fires before ItalyStrap theme load. + * + * @since 4.0.0 + */ + $this->globalDispatcher->trigger('italystrap_theme_will_load', $this->injector); + + /** + * Fires once ItalyStrap theme is loading. + * + * @since 4.0.0 + */ + $this->globalDispatcher->trigger('italystrap_theme_load', $this->injector); + + /** + * Fires once ItalyStrap theme has loaded. + * + * @since 4.0.0 + */ + $this->globalDispatcher->trigger('italystrap_theme_loaded', $this->injector); + } +} diff --git a/src/Theme/Application/ConfigCurrentTemplateSubscriber.php b/src/Theme/Application/ConfigCurrentTemplateSubscriber.php new file mode 100644 index 00000000..96908ab5 --- /dev/null +++ b/src/Theme/Application/ConfigCurrentTemplateSubscriber.php @@ -0,0 +1,49 @@ + [ + self::CALLBACK => $this, + self::PRIORITY => PHP_INT_MAX - 100, + ]; + } + + private ConfigInterface $config; + private FileInfoFactoryInterface $fileInfoFactory; + + public function __construct( + ConfigInterface $config, + FileInfoFactoryInterface $fileInfoFactory + ) { + $this->config = $config; + $this->fileInfoFactory = $fileInfoFactory; + } + + public function __invoke(string $current_template = ''): string + { + $current_template = $this->fileInfoFactory->make($current_template); + $base_name = $current_template->getBasename(); + $slug = $current_template->getBasename('.' . $current_template->getExtension()); + + !defined('CURRENT_TEMPLATE') && define('CURRENT_TEMPLATE', $base_name); + !defined('CURRENT_TEMPLATE_SLUG') && define('CURRENT_TEMPLATE_SLUG', $slug); + + $this->config->set(self::TEMPLATE_FILE_NAME, $base_name); + $this->config->set(self::TEMPLATE_FILE_SLUG, $slug); + + return $current_template->__toString(); + } +} diff --git a/src/Theme/Application/ConfigWpSubscriber.php b/src/Theme/Application/ConfigWpSubscriber.php new file mode 100644 index 00000000..7acee5b0 --- /dev/null +++ b/src/Theme/Application/ConfigWpSubscriber.php @@ -0,0 +1,73 @@ + [ + self::CALLBACK => $this, + self::PRIORITY => PHP_INT_MIN, + ]; + } + public function __construct( + ConfigInterface $config, + \WP_Query $query + ) { + $this->config = $config; + $this->query = $query; + } + + public function __invoke(): void + { + $id = $this->query->get_queried_object_id(); + + if (is_singular()) { + $this->config->add( + ConfigLayoutProvider::POST_CONTENT_TEMPLATE, + (array) get_post_meta($id, '_italystrap_template_settings', true) + ); + } else { + $this->config->add( + ConfigLayoutProvider::POST_CONTENT_TEMPLATE, + explode( + ',', + is_array($this->config->get(ConfigLayoutProvider::POST_CONTENT_TEMPLATE)) + ? $this->config->get(ConfigLayoutProvider::POST_CONTENT_TEMPLATE)[0] + : $this->config->get(ConfigLayoutProvider::POST_CONTENT_TEMPLATE) + ) + ); + } + + /** + * If in page settings are set then override the global settings for the layout. + */ + if ($page_layout = (string) get_post_meta($id, '_italystrap_layout_settings', true)) { + $this->config->add(ConfigLayoutProvider::SITE_LAYOUT, $page_layout); + } + + /** + * If in page settings are set then override the global settings for the layout. + */ + if ($container_width = (string) get_post_meta($id, '_italystrap_width_settings', true)) { + $this->config->add(ConfigLayoutProvider::CONTAINER_WIDTH, $container_width); + } + + $array = [ + self::CURRENT_PAGE_ID => $id, + ]; + + $this->config->merge($array); + } +} diff --git a/src/Theme/Application/LicenseSubscriber.php b/src/Theme/Application/LicenseSubscriber.php new file mode 100644 index 00000000..05417ba7 --- /dev/null +++ b/src/Theme/Application/LicenseSubscriber.php @@ -0,0 +1,63 @@ + [ + SubscriberInterface::CALLBACK => $this, + ]; + } + + public function __construct(\WP_Theme $theme, ConfigInterface $config) + { + $this->config = $config; + $this->theme = $theme; + } + + public function __invoke(array $edd_config): iterable + { + + /** + * EDD configuration for this theme + * + * @link italystrap.com + * @since 4.0.0 + * + * @package ItalyStrap + */ + $item_name = 'ItalyStrap Theme Framework'; + $theme_slug = 'italystrap'; + + $edd_config[] = [ + 'config' => [ + 'item_name' => $item_name, // Name of theme + 'theme_slug' => $theme_slug, // Theme slug + 'version' => $this->theme->display('Version'), // The current version of this theme + 'author' => $this->theme->display('Author'), // The author of this theme + 'download_id' => '', // Optional, used for generating a license renewal link + 'renew_url' => '', // Optional, allows for a custom license renewal link + 'beta' => $this->config->get('beta'), // Optional, set to true to opt into beta versions + ], + 'strings' => [ + 'theme-license' => \sprintf( + /* translators: %s: Theme name */ + \__('%s License', 'italystrap'), + $this->theme->display('Name') + ), + ], + ]; + + return $edd_config; + } +} diff --git a/src/Theme/Application/MetaBoxesSubscriber.php b/src/Theme/Application/MetaBoxesSubscriber.php new file mode 100644 index 00000000..495a5b8a --- /dev/null +++ b/src/Theme/Application/MetaBoxesSubscriber.php @@ -0,0 +1,152 @@ + $this; + } + + public function __construct(ConfigInterface $config, CMB2Factory $factory) + { + $this->config = $config; + $this->factory = $factory; + } + + public function __invoke() + { + + if (experimental_is_block_theme()) { + return; + } + + $prefix = (string)$this->config->get(ConfigThemeProvider::PREFIX); + $post_id = \array_key_exists('post', $_GET) ? \absint($_GET['post']) : null; + $post_type = \array_key_exists('post_type', $_GET) + ? \esc_attr($_GET['post_type']) + : (string)\get_post_type($post_id); + + $cmb = $this->factory->make([ + 'id' => "$prefix-template-settings-metabox", + 'title' => \__('Custom settings', 'italystrap'), + 'object_types' => [ + 'page', + 'post', + 'download', + 'product', + 'forum', + 'topic', + 'reply', + ], + 'context' => 'side', + 'priority' => 'low', + ]); + + $cmb->add_field( + [ + 'name' => \__('Page container width settings', 'italystrap'), + 'desc' => \sprintf( + \__('Choose the width of the page container for this %s', 'italystrap'), + $post_type + ), + 'id' => "_{$prefix}_width_settings", + 'type' => 'radio', + 'show_option_none' => \sprintf( + \__('Default width set in %s', 'italystrap'), + $post_type + ), + 'options' => \apply_filters('italystrap_theme_width', []), + ] + ); + + $cmb->add_field( + [ + 'name' => \__('Layout settings', 'italystrap'), + 'desc' => \sprintf( + \__('Advance layout setting for this %s', 'italystrap'), + $post_type + ), + 'id' => "_{$prefix}_layout_settings", + 'type' => 'radio', + 'show_option_none' => sprintf( + \__('Default layout set in %s', 'italystrap'), + $post_type + ), + 'options' => require \get_template_directory() . '/config/layout.php', + ] + ); + + $cmb->add_field( + [ + 'name' => \__('Template settings', 'italystrap'), + 'desc' => \sprintf( + \__('Advance template content setting for this %s', 'italystrap'), + $post_type + ), + 'id' => "_{$prefix}_template_settings", + 'type' => 'multicheck', + 'options' => require \get_template_directory() . '/config/template-content.php', + ] + ); + + if (\current_theme_supports('custom-header') && \get_theme_mod('header_image_data')) { + $cmb->add_field( + [ + 'name' => \__('Custom header', 'italystrap'), + 'desc' => \__('The image for the theme header', 'italystrap'), + 'id' => "_{$prefix}_custom_header", + 'type' => 'file', + 'options' => [ + 'url' => false, // Hide the text input for the url + ], + 'default' => null, + 'text' => [ + 'add_upload_file_text' => \__('Add or upload image', 'italystrap') + ], + ] + ); + } + + /** + * This functionality is not already developed + */ + if (\current_theme_supports('featured-video')) { + /** + * @example https://github.com/WebDevStudios/CMB2/wiki/Field-Types#oembed + * $url = \esc_url( \get_post_meta( \get_the_ID(), 'wiki_test_embed', 1 ) ); + * echo \wp_oembed_get( $url ); + */ + $cmb->add_field( + [ + 'name' => \__('Video URL', 'italystrap'), + // phpcs:disable + 'desc' => \sprintf( + 'Enter a youtube, twitter, or instagram URL. Supports services listed at %s. This will be shown instead of feature image.', + 'http://codex.wordpress.org/Embeds' + ), + // phpcs:enable + 'default' => '', + 'id' => "_{$prefix}_featured_video", + 'type' => 'text', + ] + ); + } + } +} diff --git a/src/Theme/Application/PostTypeSupportSubscriber.php b/src/Theme/Application/PostTypeSupportSubscriber.php new file mode 100644 index 00000000..7bdfa158 --- /dev/null +++ b/src/Theme/Application/PostTypeSupportSubscriber.php @@ -0,0 +1,30 @@ + $this; + } + + private ConfigInterface $config; + + public function __construct(ConfigInterface $config) + { + $this->config = $config; + } + + public function __invoke(): void + { + foreach ((array)$this->config->get(self::class, []) as $post_type => $features) { + \add_post_type_support($post_type, $features); + } + } +} diff --git a/src/Theme/Application/SidebarsSubscriber.php b/src/Theme/Application/SidebarsSubscriber.php new file mode 100644 index 00000000..656d0ada --- /dev/null +++ b/src/Theme/Application/SidebarsSubscriber.php @@ -0,0 +1,104 @@ + + */ + private array $registered_sidebars; + + public function getSubscribedEvents(): iterable + { + yield 'widgets_init' => 'register'; + yield 'dynamic_sidebar_before' => 'parseDynamicSidebarBefore'; + } + + private Config $config; + + public function __construct(Config $config, Tag $tag) + { + $this->config = $config; + $this->tag = $tag; + $this->registered_sidebars = []; + } + + public function register(): void + { + foreach ((array)$this->config->get(self::class, []) as $key => $sidebar) { + $this->registered_sidebars[$key] = register_sidebar($sidebar); + } + } + + /** + * @param int|string $index + */ + public function parseDynamicSidebarBefore($index): void + { + /** @var array $wp_registered_sidebars */ + global $wp_registered_sidebars; + $wp_registered_sidebars[ $index ] = array_merge( + (array)$wp_registered_sidebars[$index], + array_filter($this->getDefault($index)) + ); + } + + /** + * @param int|string $id + */ + private function getDefault($id): array + { + $widget_context = $id . '-widget'; + $title_context = $id . '-title'; + + return [ + self::NAME => '', + self::ID => '', + self::DESCRIPTION => '', + self::CLASS_NAME => '', + self::BEFORE_WIDGET => $this->tag->open( + $widget_context, + 'div', + ['id' => '%1$s', 'class' => 'widget %2$s'] + ), + self::AFTER_WIDGET => $this->tag->close($widget_context), + self::BEFORE_TITLE => $this->tag->open( + $title_context, + 'h3', + ['class' => 'widgettitle widget-title'] + ), + self::AFTER_TITLE => $this->tag->close($title_context), + ]; + } + + private function defaultSidebarConfig(array $sidebar): array + { + $defaults = $this->getDefault($sidebar[ 'id' ]); + return array_merge($defaults, $sidebar); + } +} diff --git a/src/Theme/Application/SupportSubscriber.php b/src/Theme/Application/SupportSubscriber.php new file mode 100644 index 00000000..43f63362 --- /dev/null +++ b/src/Theme/Application/SupportSubscriber.php @@ -0,0 +1,44 @@ + [ + static::CALLBACK => $this, + static::PRIORITY => 20, + ]; + } + + public function __construct(ConfigInterface $config, Support $support) + { + $this->config = $config; + $this->support = $support; + } + + /** + * @link http://codex.wordpress.org/Function_Reference/add_theme_support + */ + public function __invoke(): void + { + foreach ((array) $this->config->get(self::class) as $feature => $parameters) { + if (\is_string($parameters)) { + $this->support->add($parameters); + continue; + } + + $this->support->add($feature, $parameters); + } + } +} diff --git a/src/Theme/Application/TextDomainSubscriber.php b/src/Theme/Application/TextDomainSubscriber.php new file mode 100644 index 00000000..42f91e94 --- /dev/null +++ b/src/Theme/Application/TextDomainSubscriber.php @@ -0,0 +1,42 @@ + [ + static::CALLBACK => $this, + static::PRIORITY => 20, + ]; + } + + private Config $config; + + public function __construct(Config $config) + { + $this->config = $config; + } + + public function __invoke() + { + \load_theme_textdomain( + 'italystrap', + $this->config->get(ConfigThemeProvider::TEMPLATE_DIR) . '/languages' + ); + + /** + * @TODO Is it good to register the child theme textdomain here? + */ +// if ( is_child_theme() ) { +// \load_child_theme_textdomain( 'CHILD', $this->config->get( 'CHILDPATH' ) . '/languages' ); +// } + } +} diff --git a/src/Theme/Application/ThumbnailsSubscriber.php b/src/Theme/Application/ThumbnailsSubscriber.php new file mode 100644 index 00000000..8cda4b69 --- /dev/null +++ b/src/Theme/Application/ThumbnailsSubscriber.php @@ -0,0 +1,112 @@ + [ + static::CALLBACK => $this, + static::PRIORITY => 20, + ]; + } + + + public function __construct(ConfigInterface $config, ImageSizeInterface $image_sizes) + { + $this->config = $config; + $this->image_sizes_obj = $image_sizes; + } + + /** + * Register image size + * + * thumbnail_size_w + * thumbnail_size_h + * thumbnail_crop + * medium_size_h: The medium size height. + * medium_size_w: The medium size width. + * large_size_h: The large size height. + * large_size_w: The large size width. + * + * @example update_option( 'large_size_h', 700 ); + * @example + * add_image_size( + * 'medium', + * get_option( 'medium_size_w' ), + * get_option( 'medium_size_h' ), + * true + * ); // For cropping the default image size. + + * Maybe first remove_image_size and then add_image_size it's better + * + * @link https://developer.wordpress.org/reference/functions/add_image_size/ + * @link http://wordpress.stackexchange.com/questions/30965/set-default-image-sizes-in-wordpress-to-hard-crop + * + * @return void + */ + public function __invoke(): void + { + + /** + * $content_width is a global variable used by WordPress for max image upload sizes + * and media embeds (in pixels). + * + * Example: If the content area is 640px wide, + * set $content_width = 620; so images and videos will not overflow. + * Default: 750px is the default ItalyStrap container width. + */ + global $content_width; + if (! isset($content_width)) { + $content_width = (string)$this->config->get(ConfigPostThumbnailProvider::POST_CONTENT_WIDTH, '750'); + } + + /** + * 'post-thumbnails' is by default the size displayed for posts, pages and all archives. + */ + set_post_thumbnail_size($content_width, intval($content_width * 3 / 4)); + + $sizes = (array)$this->config->get(self::class, []); + array_walk($sizes, function (array $params, string $name): void { + $params = array_merge($this->getDefaultImageParams(), $params); + + $this->image_sizes_obj->addSize( + $name, + (int)$params[ ConfigPostThumbnailProvider::WIDTH ], + (int)$params[ ConfigPostThumbnailProvider::HEIGHT ], + (bool)$params[ ConfigPostThumbnailProvider::CROP ] ?? false + ); + }); + } + + private function getDefaultImageParams(): array + { + return [ + ConfigPostThumbnailProvider::WIDTH => 0, + ConfigPostThumbnailProvider::HEIGHT => 0, + ConfigPostThumbnailProvider::CROP => false, + ]; + } +} diff --git a/src/Theme/ExperimentalThemeFileFinderFactory.php b/src/Theme/ExperimentalThemeFileFinderFactory.php deleted file mode 100644 index e77eac04..00000000 --- a/src/Theme/ExperimentalThemeFileFinderFactory.php +++ /dev/null @@ -1,29 +0,0 @@ -make( FinderInterface::class ); - $finder = (new FinderFactory())->make() - ->in( - \array_unique( - [ - /** - * To remember: - * This is the correct hierarchy to load and override - * the parent with child config. - */ - get_template_directory(), - get_stylesheet_directory(), - ] - ) - ); - return $finder; - } -} diff --git a/src/Theme/Infrastructure/CMB2Factory.php b/src/Theme/Infrastructure/CMB2Factory.php new file mode 100644 index 00000000..6c5d4679 --- /dev/null +++ b/src/Theme/Infrastructure/CMB2Factory.php @@ -0,0 +1,13 @@ + self::POST_THUMBNAIL_SIZE_DEFAULT; + yield self::POST_THUMBNAIL_ALIGNMENT => AlignmentKeys::ALIGN_FULL; + yield self::POST_CONTENT_WIDTH => $this->getContentWidth( + 1170, + 12, + 8, + 30 + ); + + yield ThumbnailsSubscriber::class => [ + 'navbar-brand-image' => [ + self::WIDTH => 45, + self::HEIGHT => 45, + self::CROP => true, + ], + + /** + * La full-width serve solo per la pagina omonima + * Si potrebbe invece settare "large" a 1140 (verificare se 1170 va bene) e risparmiare + * spazio avendo una immagine di meno poichè entrambe non vengono croppate + * "large" può essere settata anche con altezza a 9999 + */ + 'full-width' => [ + self::WIDTH => $container - $gutter, + self::HEIGHT => 9999, + self::CROP => false, + ], + 'one_half' => [ + self::WIDTH => $container / 2 - $gutter, + self::HEIGHT => ($container / 2 - $gutter) * 3 / 4, + self::CROP => true, + ], + 'one_third' => [ + self::WIDTH => $container / 3 - $gutter, + self::HEIGHT => ($container / 3 - $gutter) * 3 / 4, + self::CROP => true, + ], + 'one_fourth' => [ + self::WIDTH => $container / 4 - $gutter, + self::HEIGHT => ($container / 4 - $gutter) * 3 / 4, + self::CROP => true, + ], + 'one_six' => [ + self::WIDTH => $container / 6 - $gutter, + self::HEIGHT => ($container / 6 - $gutter) * 3 / 4, + self::CROP => true, + ], + ]; + } + + /** + * Get the content width + * + * @param int $container_width + * @param int $column + * @param int $content_column_width + * @param int $gutter + * @return int [description] + */ + private function getContentWidth( + int $container_width, + int $column, + int $content_column_width, + int $gutter = 0 + ): int { + return intval($container_width / $column * $content_column_width - $gutter); + } +} diff --git a/src/Theme/Infrastructure/Config/ConfigPostTypeSupportProvider.php b/src/Theme/Infrastructure/Config/ConfigPostTypeSupportProvider.php new file mode 100644 index 00000000..63b53296 --- /dev/null +++ b/src/Theme/Infrastructure/Config/ConfigPostTypeSupportProvider.php @@ -0,0 +1,21 @@ + [ + 'post' => [ 'post_navigation', 'entry-meta' ], + 'page' => [ 'post_navigation', 'entry-meta' ], + 'download' => [ 'post_navigation', 'entry-meta' ], + ], + ]; + } +} diff --git a/src/Theme/Infrastructure/Config/ConfigSidebarProvider.php b/src/Theme/Infrastructure/Config/ConfigSidebarProvider.php new file mode 100644 index 00000000..31d20c12 --- /dev/null +++ b/src/Theme/Infrastructure/Config/ConfigSidebarProvider.php @@ -0,0 +1,59 @@ + [ + self::SIDEBAR_PRIMARY => [ + S::NAME => \__('Sidebar', 'italystrap'), + S::ID => 'sidebar-1', + ], + + self::FOOTER_BOX_1 => [ + S::NAME => \__('Footer Box 1', 'italystrap'), + S::ID => 'footer-box-1', + S::DESCRIPTION => \__('Footer box 1 widget area.', 'italystrap'), + ], + + self::FOOTER_BOX_2 => [ + S::NAME => \__('Footer Box 2', 'italystrap'), + S::ID => 'footer-box-2', + S::DESCRIPTION => \__('Footer box 2 widget area.', 'italystrap'), + ], + + self::FOOTER_BOX_3 => [ + S::NAME => \__('Footer Box 3', 'italystrap'), + S::ID => 'footer-box-3', + S::DESCRIPTION => \__('Footer box 3 widget area.', 'italystrap'), + ], + + self::FOOTER_BOX_4 => [ + S::NAME => \__('Footer Box 4', 'italystrap'), + S::ID => 'footer-box-4', + S::DESCRIPTION => \__('Footer box 4 widget area.', 'italystrap'), + ], + ], + ]; + } +} diff --git a/src/Theme/Infrastructure/Config/ConfigThemeProvider.php b/src/Theme/Infrastructure/Config/ConfigThemeProvider.php new file mode 100644 index 00000000..452ad8ad --- /dev/null +++ b/src/Theme/Infrastructure/Config/ConfigThemeProvider.php @@ -0,0 +1,61 @@ +theme = $theme; + $this->dispatcher = $dispatcher; + } + + public function __invoke(): iterable + { +// 'ITALYSTRAP_THEME' => true, +// 'ITALYSTRAP_THEME_NAME' => wp_get_theme( $get_template )->display( 'Name' ), +// 'ITALYSTRAP_THEME_VERSION' => wp_get_theme( $get_template )->display( 'Version' ), +// 'ITALYSTRAP_THEME_AUTHOR' => wp_get_theme( $get_template )->display( 'Author', false ), +// 'ITALYSTRAP_CURRENT_THEME_NAME' => $current_theme_name, +// 'PREFIX' => $prefix, +// '_PREFIX' => '_' . $prefix, +// 'TEMPLATEURL' => get_template_directory_uri(), +// 'STYLESHEETURL' => get_stylesheet_directory_uri(), +// 'PARENTPATH' => get_template_directory(), +// 'CHILDPATH' => get_stylesheet_directory(), +// 'GET_BLOGINFO_NAME' => get_option( 'blogname' ), +// 'GET_BLOGINFO_DESCRIPTION' => get_option( 'blogdescription' ), +// 'HOME_URL' => get_home_url( null, '/' ), +// 'PAGE_ON_FRONT' => absint( get_option( 'page_on_front' ) ), +// 'PAGE_FOR_POSTS' => absint( get_option( 'page_for_posts' ) ), + + yield self::THEME_NAME => (string)$this->theme->display('Name'); + yield self::THEME_VERSION => (string)$this->theme->display('Version'); + yield self::THEME_AUTHOR => (string)$this->theme->display('Author'); + yield self::TEMPLATE_DIR_URI => $this->theme->get_template_directory_uri(); + yield self::STYLESHEET_DIR_URI => $this->theme->get_stylesheet_directory_uri(); + yield self::TEMPLATE_DIR => $this->theme->get_template_directory(); + yield self::STYLESHEET_DIR => $this->theme->get_stylesheet_directory(); + yield self::THEME_BETA => false; + yield self::VIEW_DIR => (string) $this->dispatcher->filter('italystrap_template_dir', 'templates'); + yield self::PREFIX => \strtolower((string)$this->theme->display('Name')); + } +} diff --git a/src/Theme/Infrastructure/Config/ConfigThemeSupportProvider.php b/src/Theme/Infrastructure/Config/ConfigThemeSupportProvider.php new file mode 100644 index 00000000..b6f89d50 --- /dev/null +++ b/src/Theme/Infrastructure/Config/ConfigThemeSupportProvider.php @@ -0,0 +1,383 @@ +config = $config; + } + + public function __invoke(): iterable + { + $logo_size_name_registered = (string)$this->config->get(ConfigSiteLogoProvider::BRAND_IMAGE_SIZE); + + yield SupportSubscriber::class => [ + /** + * Add default posts and comments RSS feed links to head. + */ + 'automatic-feed-links', + + /** + * Enable support for Post Thumbnails on posts, pages and archives template. + * @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails + */ + 'post-thumbnails', + + /** + * Switch default core markup for search form, comment form, and comments + * to output valid HTML5. + */ + 'html5' => [ + 'search-form', + 'comment-form', + 'comment-list', + 'gallery', + 'caption', + 'style', + 'script', + ], + + /** + * Enable support for title-tag. + */ + 'title-tag', + + /** + * Enable support for Post Formats. + * See http://codex.wordpress.org/Post_Formats + * + * @var array + */ + 'post-formats' => [ + 'aside', + 'image', + 'gallery', + 'link', + 'quote', + 'status', + 'video', + 'audio', + 'chat', + ], + + /** + * Custom header value array + * Some ideas for default images https://unsplash.it/ + * + * @var array + */ + self::CUSTOM_HEADER => [ + 'default-image' => '', + 'width' => 1140, + 'height' => 200, + 'flex-height' => true, + 'flex-width' => true, + 'uploads' => true, + 'random-default' => false, + 'header-text' => true, + 'default-text-color' => '000', + 'wp-head-callback' => '', + 'admin-head-callback' => '', + 'admin-preview-callback' => '', + 'video' => true, + ], + + self::CUSTOM_LOGO => [ + 'width' => (int)$this->config->get( + ThumbnailsSubscriber::class . ".$logo_size_name_registered.width" + ), + 'height' => (int)$this->config->get( + ThumbnailsSubscriber::class . ".$logo_size_name_registered.height" + ), + 'flex-height' => true, + 'flex-width' => true, + 'header-text' => ['site-title', 'site-description'], + 'unlink-homepage-logo' => true, + ], + + /** + * Custom background support + * + * @link http://codex.wordpress.org/Custom_Backgrounds + * @var array + * $defaults = array( + * 'default-image' => '', + * 'default-repeat' => 'repeat', + * 'default-position-x' => 'left', + * 'default-attachment' => 'scroll', + * 'default-color' => '', + * 'wp-head-callback' => '_custom_background_cb', + * 'admin-head-callback' => '', + * 'admin-preview-callback' => '', + * ); + * + * 'wp-head-callback' => null In case is printed from Theme customizer + */ + 'custom-background' => \apply_filters('custom_background_support', []), + + /** + * @since 4.5 WordPress Core + * @see https://make.wordpress.org/core/2016/03/22/implementing-selective-refresh-support-for-widgets/ + */ + 'customize-selective-refresh-widgets', + + /** + * Add support for the builtin breadcrumbs + */ + 'breadcrumbs', + + /** + * Define and register starter content to showcase the theme on new sites. + * @see twentyseventeen + * @link https://make.wordpress.org/core/2016/11/30/starter-content-for-themes-in-4-7/ + * @link https://roots.io/using-and-customizing-wordpress-starter-content/ + * + * @link https://gist.github.com/igorbenic/10d22c620fc264aac674f17fbfd07750 + * + * @var array + */ +// 'starter-content' => [ +// 'widgets' => [ +// // Place three core-defined widgets in the sidebar area. +// 'sidebar-1' => [ +// 'text_business_info', +// 'search', +// 'text_about', +// 'italystrap_posts', +// // 'text_test' => array( +// // 'text' => array( +// // 'title' => 'Title test' +// // ), +// // ), +// ], +// +// // Add the core-defined business info widget to the footer 1 area. +// 'footer-box-1' => [ +// 'text_business_info', +// ], +// +// // Put two core-defined widgets in the footer 2 area. +// 'footer-box-2' => [ +// 'text_about', +// 'search', +// ], +// ], +// +// // Specify the core-defined pages to create and add custom thumbnails to some of them. +// 'posts' => [ +// 'home', +// 'about' => [ +// 'thumbnail' => '{{image-sandwich}}', +// ], +// 'contact' => [ +// 'thumbnail' => '{{image-default}}', +// ], +// 'test' => [ +// 'thumbnail' => '{{image-default}}', +// 'post_content' => 'POST CONTENT', +// ], +// 'blog' => [ +// 'thumbnail' => '{{image-coffee}}', +// ], +// 'homepage-section' => [ +// 'thumbnail' => '{{image-default}}', +// ], +// ], +// +// // Create the custom image attachments used as post thumbnails for pages. +// 'attachments' => [ +// 'image-default' => [ +// 'post_title' => _x('Default', 'Theme starter content', 'italystrap'), +// 'file' => 'assets/img/italystrap-default-image.png', // URL relative to the template directory. +// ], +// 'image-sandwich' => [ +// 'post_title' => _x('Sandwich', 'Theme starter content', 'italystrap'), +// 'file' => 'img/images/sandwich.jpg', +// ], +// 'image-coffee' => [ +// 'post_title' => _x('Coffee', 'Theme starter content', 'italystrap'), +// 'file' => 'img/images/coffee.jpg', +// ], +// ], +// +// // Default to a static front page and assign the front and posts pages. +// 'options' => [ +// 'show_on_front' => 'page', +// 'page_on_front' => '{{home}}', +// 'page_for_posts' => '{{blog}}', +// ], +// +// // Set the front page section theme mods to the IDs of the core-registered pages. +// 'theme_mods' => [ +// 'panel_1' => '{{homepage-section}}', +// 'panel_2' => '{{about}}', +// 'panel_3' => '{{blog}}', +// 'panel_4' => '{{contact}}', +// ], +// +// // Set up nav menus for each of the two areas registered in the theme. +// 'nav_menus' => [ +// // Assign a menu to the "top" location. +// 'info-menu' => [ +// 'name' => __('Info Menu', 'italystrap'), +// 'items' => [ +// 'link_home', // Note that the core "home" page is actually a +// //link in case a static front page is not used. +// 'page_about', +// 'page_blog', +// 'page_contact', +// ], +// ], +// +// // Assign a menu to the "social" location. +// 'social-menu' => [ +// 'name' => __('Social Links Menu', 'italystrap'), +// 'items' => [ +// 'link_yelp', +// 'link_facebook', +// 'link_twitter', +// 'link_instagram', +// 'link_email', +// 'link_test', +// ], +// ], +// +// // Assign a menu to the "social" location. +// 'main-menu' => [ +// 'name' => __('Main Menu', 'italystrap'), +// 'items' => [ +// 'link_home', // Note that the core "home" page is actually a +// //link in case a static front page is not used. +// 'page_about', +// 'page_blog', +// 'page_contact', +// 'page_test', +// ], +// ], +// ], +// ], + + /** ================================= + * Theme support for Gutenberg editor + * + * https://wordpress.org/gutenberg/handbook/designers-developers/developers/themes/theme-support/ + * + * @see _add_default_theme_supports() + * + * @since WordPress 5.0 + ===================================*/ + + // 'editor-font-sizes' => [ + // [ + // 'name' => __( 'Extra Small', 'italystrap' ), + // 'shortName' => __( 'XS', 'italystrap' ), + // 'size' => ceil( $font_size_base * 0.75 ), + // 'slug' => 'extra-small', + // ], + // [ + // 'name' => __( 'Small', 'italystrap' ), + // 'shortName' => __( 'S', 'italystrap' ), + // 'size' => ceil( $font_size_base * 0.85 ), + // 'slug' => 'small', + // ], + // [ + // 'name' => __( 'Normal', 'italystrap' ), + // 'shortName' => __( 'M', 'italystrap' ), + // 'size' => $font_size_base, + // 'slug' => 'normal', + // ], + // [ + // 'name' => __( 'Large', 'italystrap' ), + // 'shortName' => __( 'L', 'italystrap' ), + // 'size' => ceil( $font_size_base * 1.25 ), + // // 'unit' => 'rem', + // 'slug' => 'large', + // ], + // [ + // 'name' => __( 'Huge', 'italystrap' ), + // 'shortName' => __( 'XL', 'italystrap' ), + // 'size' => ceil( $font_size_base * 1.7 ), + // 'slug' => 'huge', + // ], + // [ + // 'name' => __( 'Extra Huge', 'italystrap' ), + // 'shortName' => __( 'XXL', 'italystrap' ), + // 'size' => ceil( $font_size_base * 2.15 ), + // 'slug' => 'extra-huge', + // ], + // [ + // 'name' => __( 'H1', 'italystrap' ), + // 'shortName' => __( 'H1', 'italystrap' ), + // 'size' => ceil( $font_size_base * 2.6 ), + // 'slug' => 'h1', + // ], + // ], + + /** + * If the theme support align-wide then activate it + * https://developer.wordpress.org/block-editor/how-to-guides/themes/theme-support/#wide-alignment + */ + 'align-wide', + + /** + * Support for Gutenberg editor style + * Then make sure you are loading the editor-style.css + * https://developer.wordpress.org/block-editor/how-to-guides/themes/theme-support/#editor-styles + */ + 'editor-styles', + + /** + * If the theme has dark background then activate it + */ + // 'dark-editor-style', + + /** + * This will add: + *
    ...
    + * + * @link https://wordpress.org/gutenberg/handbook/designers-developers/developers/themes/theme-support/#responsive-embedded-content + * @TODO + */ + 'responsive-embeds', + + /** + * https://developer.wordpress.org/block-editor/how-to-guides/themes/theme-support/#default-block-styles + * https://wordpress.org/support/topic/wp-block-styles/ + * Some blocks in Gutenberg like tables, quotes, separator benefit from structural styles + * (margin, padding, border etc…) + * They are applied visually only in the editor (back-end) but not on the front-end + * to avoid the risk of conflicts with the styles wanted in the theme. + * If you want to display them on front to have a base to work with, in this case, + * you can add support for wp-block-styles. + * You can consult Matias Ventura’s tickets to keep you informed about Gutenberg developments: + * https://make.wordpress.org/core/2018/06/05/whats-new-in-gutenberg-5th-june/ + */ + 'wp-block-styles', + + /** + * https://developer.wordpress.org/block-editor/how-to-guides/themes/theme-support/#block-based-template-parts + * This feature allows themes to register block templates parts: + * - The block template parts editor UI is activated + * - The theme also need to add html files in a folder called parts + * - - Example: + * - - - parts/footer.html + * - - - parts/header.html + */ + 'block-template-parts', + ]; + } +} diff --git a/src/Theme/Infrastructure/ImageSize.php b/src/Theme/Infrastructure/ImageSize.php new file mode 100644 index 00000000..0f6765ce --- /dev/null +++ b/src/Theme/Infrastructure/ImageSize.php @@ -0,0 +1,32 @@ + [ - SubscriberInterface::CALLBACK => '__invoke', - ]; - } - - public function __construct( \WP_Theme $theme, ConfigInterface $config ) { - $this->config = $config; - $this->theme = $theme; - } - - public function __invoke( array $edd_config ): iterable { - - /** - * EDD configuration for this theme - * - * @link italystrap.com - * @since 4.0.0 - * - * @package ItalyStrap - */ - $item_name = 'ItalyStrap Theme Framework'; - $theme_slug = 'italystrap'; - - $edd_config[] = [ - 'config' => [ - 'item_name' => $item_name, // Name of theme - 'theme_slug' => $theme_slug, // Theme slug - 'version' => $this->theme->display('Version'), // The current version of this theme - 'author' => $this->theme->display('Author'), // The author of this theme - 'download_id' => '', // Optional, used for generating a license renewal link - 'renew_url' => '', // Optional, allows for a custom license renewal link - 'beta' => $this->config->get('beta'), // Optional, set to true to opt into beta versions - ], - 'strings' => [ - 'theme-license' => \sprintf( - /* translators: %s: Theme name */ - \__( '%s License', 'italystrap' ), - $this->theme->display('Name') - ), - ], - ]; - - return $edd_config; - } -} diff --git a/src/Theme/Metaboxes.php b/src/Theme/Metaboxes.php deleted file mode 100644 index 3ae51748..00000000 --- a/src/Theme/Metaboxes.php +++ /dev/null @@ -1,145 +0,0 @@ - '__invoke'; - } - - public function __construct(ConfigInterface $config, CMB2Factory $factory) { - $this->config = $config; - $this->factory = $factory; - } - - public function __invoke() { - - if ( experimental_is_block_theme() ) { - return; - } - - $prefix = (string)$this->config->get(ConfigThemeProvider::PREFIX); - $post_id = \array_key_exists('post', $_GET ) ? \absint( $_GET['post'] ) : null; - $post_type = \array_key_exists('post_type', $_GET ) - ? \esc_attr( $_GET['post_type'] ) - : (string)\get_post_type( $post_id ); - - $cmb = $this->factory->make([ - 'id' => "$prefix-template-settings-metabox", - 'title' => \__( 'Custom settings', 'italystrap' ), - 'object_types' => [ - 'page', - 'post', - 'download', - 'product', - 'forum', - 'topic', - 'reply', - ], - 'context' => 'side', - 'priority' => 'low', - ]); - - $cmb->add_field( - [ - 'name' => \__( 'Page container width settings', 'italystrap' ), - 'desc' => \sprintf( - \__( 'Choose the width of the page container for this %s', 'italystrap' ), - $post_type - ), - 'id' => "_{$prefix}_width_settings", - 'type' => 'radio', - 'show_option_none' => \sprintf( - \__( 'Default width set in %s', 'italystrap' ), - $post_type - ), - 'options' => \apply_filters( 'italystrap_theme_width', [] ), - ] - ); - - $cmb->add_field( - [ - 'name' => \__( 'Layout settings', 'italystrap' ), - 'desc' => \sprintf( - \__( 'Advance layout setting for this %s', 'italystrap' ), - $post_type - ), - 'id' => "_{$prefix}_layout_settings", - 'type' => 'radio', - 'show_option_none' => sprintf( - \__( 'Default layout set in %s', 'italystrap' ), - $post_type - ), - 'options' => require \get_template_directory() . '/config/layout.php', - ] - ); - - $cmb->add_field( - [ - 'name' => \__( 'Template settings', 'italystrap' ), - 'desc' => \sprintf( - \__( 'Advance template content setting for this %s', 'italystrap' ), - $post_type - ), - 'id' => "_{$prefix}_template_settings", - 'type' => 'multicheck', - 'options' => require \get_template_directory() . '/config/template-content.php', - ] - ); - - if ( \current_theme_supports( 'custom-header' ) && \get_theme_mod( 'header_image_data' ) ) { - $cmb->add_field( - [ - 'name' => \__( 'Custom header', 'italystrap' ), - 'desc' => \__( 'The image for the theme header', 'italystrap' ), - 'id' => "_{$prefix}_custom_header", - 'type' => 'file', - 'options' => [ - 'url' => false, // Hide the text input for the url - ], - 'default' => null, - 'text' => [ - 'add_upload_file_text' => \__( 'Add or upload image', 'italystrap' ) - ], - ] - ); - } - - /** - * This functionality is not already developed - */ - if ( \current_theme_supports( 'featured-video' ) ) { - /** - * @example https://github.com/WebDevStudios/CMB2/wiki/Field-Types#oembed - * $url = \esc_url( \get_post_meta( \get_the_ID(), 'wiki_test_embed', 1 ) ); - * echo \wp_oembed_get( $url ); - */ - $cmb->add_field( - [ - 'name' => \__( 'Video URL', 'italystrap' ), - // phpcs:disable - 'desc' => \sprintf( - 'Enter a youtube, twitter, or instagram URL. Supports services listed at %s. This will be shown instead of feature image.', - 'http://codex.wordpress.org/Embeds' - ), - // phpcs:enable - 'default' => '', - 'id' => "_{$prefix}_featured_video", - 'type' => 'text', - ] - ); - } - } -} diff --git a/src/Theme/Module.php b/src/Theme/Module.php new file mode 100644 index 00000000..bb184185 --- /dev/null +++ b/src/Theme/Module.php @@ -0,0 +1,62 @@ + [ + ImageSizeInterface::class, + Support::class + ], + AurynConfig::ALIASES => [ + ImageSizeInterface::class => ImageSize::class, + ], + ConfigProviderExtension::class => [ + ConfigThemeProvider::class, + ConfigThemeSupportProvider::class, + ConfigPostTypeSupportProvider::class, + ConfigSidebarProvider::class, + ConfigPostThumbnailProvider::class, + ], + SubscribersConfigExtension::SUBSCRIBERS => [ + AfterSetupThemeSubscriber::class, + ConfigCurrentTemplateSubscriber::class, + ConfigWpSubscriber::class, + LicenseSubscriber::class, + SidebarsSubscriber::class, + SupportSubscriber::class, + TextDomainSubscriber::class, + ThumbnailsSubscriber::class, + PostTypeSupportSubscriber::class, + MetaBoxesSubscriber::class, + ] + ]; + } +} diff --git a/src/Theme/NavMenusSubscriber.php b/src/Theme/NavMenusSubscriber.php deleted file mode 100644 index 02e1ac06..00000000 --- a/src/Theme/NavMenusSubscriber.php +++ /dev/null @@ -1,65 +0,0 @@ - [ - static::CALLBACK => '__invoke', - ]; - } - - public function __construct( ConfigInterface $config, NavMenuLocation $location ) { - $this->config = $config; - $this->location = $location; - } - - public function __invoke() { - $this->location->registerMany($this->config->get(self::class, [])); - $this->updateOlderNavMenu(); - } - - private function updateOlderNavMenu(): void { - - $update = 1; - - if ( (int)\get_theme_mod('nav_menu_locations_update') < $update ) { - $menu_location = \get_nav_menu_locations(); - - $new_keys = [ - 'main-menu' => NavMenuPrimary::class, - 'secondary-menu' => NavMenuSecondary::class, -// 'social-menu' => '0', -// 'info-menu' => '0', -// 'footer-menu' => '0', - ]; - - $new_menu_locations = []; - foreach ( $menu_location as $location => $menu_id ) { - if ( ! \array_key_exists( (string)$location, $new_keys ) ) { - continue; - } - - if ( $menu_id === 0 ) { - continue; - } - - $new_menu_locations[$new_keys[$location]] = $menu_id; - } - - \set_theme_mod( 'nav_menu_locations', $new_menu_locations ); - \set_theme_mod( 'nav_menu_locations_update', $update ); - } - } -} diff --git a/src/Theme/PostTypeSupportSubscriber.php b/src/Theme/PostTypeSupportSubscriber.php deleted file mode 100644 index 6d629048..00000000 --- a/src/Theme/PostTypeSupportSubscriber.php +++ /dev/null @@ -1,26 +0,0 @@ - '__invoke'; - } - - private ConfigInterface $config; - - public function __construct( ConfigInterface $config ) { - $this->config = $config; - } - - public function __invoke(): void { - foreach ( (array)$this->config->get(self::class, []) as $post_type => $features ) { - \add_post_type_support( $post_type, $features ); - } - } -} diff --git a/src/Theme/Registrable.php b/src/Theme/Registrable.php deleted file mode 100644 index a79ab679..00000000 --- a/src/Theme/Registrable.php +++ /dev/null @@ -1,23 +0,0 @@ - - */ - private $registered_sidebars; - - /** - * @inheritDoc - */ - public function getSubscribedEvents(): iterable { - yield 'widgets_init' => static::REGISTER_CB; - yield 'dynamic_sidebar_before' => 'parseDynamicSidebarBefore'; - } - - private Config $config; - - /** - * Init sidebars registration - * @param Config $config - * @param Tag $tag - */ - public function __construct( Config $config, Tag $tag ) { - $this->config = $config; - $this->tag = $tag; - } - - /** - * @inheritDoc - */ - public function register():void { - foreach ( (array)$this->config->get(self::class, []) as $key => $sidebar ) { - $this->registered_sidebars[ $key ] = register_sidebar( $sidebar ); - } - } - - /** - * @param int|string $index - */ - public function parseDynamicSidebarBefore( $index ): void { - /** @var array $wp_registered_sidebars */ - global $wp_registered_sidebars; - $wp_registered_sidebars[ $index ] = array_merge( - $wp_registered_sidebars[ $index ], - array_filter($this->getDefault($index)) - ); - } - - /** - * @param int|string $id - * @return array - */ - private function getDefault( $id ): array { - $widget_context = $id . '-widget'; - $title_context = $id . '-title'; - - return [ - self::NAME => '', - self::ID => '', - self::DESCRIPTION => '', - self::CLASS_NAME => '', - self::BEFORE_WIDGET => $this->tag->open( - $widget_context, - 'div', - ['id' => '%1$s', 'class' => 'widget %2$s'] - ), - self::AFTER_WIDGET => $this->tag->close( $widget_context ), - self::BEFORE_TITLE => $this->tag->open( - $title_context, - 'h3', - ['class' => 'widgettitle widget-title'] - ), - self::AFTER_TITLE => $this->tag->close( $title_context ), - ]; - } - - /** - * @param array $sidebar - * @return array - */ - private function defaultSidebarConfig( array $sidebar ) : array { - $defaults = $this->getDefault( $sidebar[ 'id' ] ); - return array_merge( $defaults, $sidebar ); - } -} diff --git a/src/Theme/Support.php b/src/Theme/Support.php deleted file mode 100644 index 281bf403..00000000 --- a/src/Theme/Support.php +++ /dev/null @@ -1,41 +0,0 @@ - [ - static::CALLBACK => static::REGISTER_CB, - static::PRIORITY => 20, - ]; - } - - public function __construct( ConfigInterface $config, Support $support ) { - $this->config = $config; - $this->support = $support; - } - - /** - * Add theme supports - * @link http://codex.wordpress.org/Function_Reference/add_theme_support - * @return void - */ - public function register(): void { - foreach ( (array) $this->config->get(self::class) as $feature => $parameters ) { - if ( \is_string( $parameters ) ) { - $this->support->add( $parameters ); - } else { - $this->support->add( $feature, $parameters ); - } - } - } -} diff --git a/src/Theme/TextDomainSubscriber.php b/src/Theme/TextDomainSubscriber.php deleted file mode 100644 index 5f59bf33..00000000 --- a/src/Theme/TextDomainSubscriber.php +++ /dev/null @@ -1,53 +0,0 @@ - [ - static::CALLBACK => self::REGISTER_CB, - static::PRIORITY => 20, - ]; - } - - private Config $config; - - /** - * Init some functionality - * @param Config $config - */ - public function __construct( Config $config ) { - $this->config = $config; - } - - /** - * @return void - */ - public function register() { - - /** - * Make theme available for translation. - */ - \load_theme_textdomain( - 'italystrap', - $this->config->get( ConfigThemeProvider::TEMPLATE_DIR ) . '/languages' - ); - -// if ( is_child_theme() ) { -// \load_child_theme_textdomain( 'CHILD', $this->config->get( 'CHILDPATH' ) . '/languages' ); -// } - } -} diff --git a/src/Theme/ThumbnailsSubscriber.php b/src/Theme/ThumbnailsSubscriber.php deleted file mode 100644 index 885b794b..00000000 --- a/src/Theme/ThumbnailsSubscriber.php +++ /dev/null @@ -1,106 +0,0 @@ - [ - static::CALLBACK => self::REGISTER_CB, - static::PRIORITY => 20, - ]; - } - - - public function __construct( ConfigInterface $config, ImageSizeInterface $image_sizes ) { - $this->config = $config; - $this->image_sizes_obj = $image_sizes; - } - - /** - * Register image size - * - * thumbnail_size_w - * thumbnail_size_h - * thumbnail_crop - * medium_size_h: The medium size height. - * medium_size_w: The medium size width. - * large_size_h: The large size height. - * large_size_w: The large size width. - * - * @example update_option( 'large_size_h', 700 ); - * @example - * add_image_size( - * 'medium', - * get_option( 'medium_size_w' ), - * get_option( 'medium_size_h' ), - * true - * ); // For cropping the default image size. - - * Maybe first remove_image_size and then add_image_size it's better - * - * @link https://developer.wordpress.org/reference/functions/add_image_size/ - * @link http://wordpress.stackexchange.com/questions/30965/set-default-image-sizes-in-wordpress-to-hard-crop - * - * @return void - */ - public function register(): void { - - /** - * $content_width is a global variable used by WordPress for max image upload sizes - * and media embeds (in pixels). - * - * Example: If the content area is 640px wide, - * set $content_width = 620; so images and videos will not overflow. - * Default: 750px is the default ItalyStrap container width. - */ - global $content_width; - if ( ! isset( $content_width ) ) { - $content_width = (string)$this->config->get(ConfigPostThumbnailProvider::POST_CONTENT_WIDTH, '750'); - } - - /** - * 'post-thumbnails' is by default the size displayed for posts, pages and all archives. - */ - set_post_thumbnail_size( $content_width, intval( $content_width * 3 / 4 ) ); - - $sizes = (array)$this->config->get(self::class, []); - array_walk( $sizes, function ( array $params, string $name ): void { - $params = array_merge( $this->getDefaultImageParams(), $params ); - - $this->image_sizes_obj->addSize( - $name, - (int)$params[ ConfigPostThumbnailProvider::WIDTH ], - (int)$params[ ConfigPostThumbnailProvider::HEIGHT ], - (bool)$params[ ConfigPostThumbnailProvider::CROP ] ?? false - ); - } ); - } - - private function getDefaultImageParams(): array { - return [ - ConfigPostThumbnailProvider::WIDTH => 0, - ConfigPostThumbnailProvider::HEIGHT => 0, - ConfigPostThumbnailProvider::CROP => false, - ]; - } -} diff --git a/src/Theme/index.php b/src/Theme/index.php deleted file mode 100644 index b3d9bbc7..00000000 --- a/src/Theme/index.php +++ /dev/null @@ -1 +0,0 @@ - [ + SubscriberInterface::CALLBACK => $this, + SubscriberInterface::PRIORITY => self::EVENT_PRIORITY, + ]; + } + + private AuthorInfo $authorInfo; + + public function __construct(AuthorInfo $info) + { + $this->authorInfo = $info; + } + + public function shouldDisplay(): bool + { + return is_author(); + } + + public function __invoke(Content $event): void + { + $event->appendContent((string)$this->authorInfo); + } +} diff --git a/src/UI/Components/Archive/ArchiveHeadline.php b/src/UI/Components/Archive/ArchiveHeadline.php new file mode 100644 index 00000000..7332a461 --- /dev/null +++ b/src/UI/Components/Archive/ArchiveHeadline.php @@ -0,0 +1,43 @@ + [ + SubscriberInterface::CALLBACK => $this, + SubscriberInterface::PRIORITY => self::EVENT_PRIORITY, + ]; + } + + public const TEMPLATE_NAME = 'archive/archive-headline'; + + private ViewInterface $view; + + public function __construct( + ViewInterface $view + ) { + $this->view = $view; + } + + public function shouldDisplay(): bool + { + return \is_archive() && ! \is_author(); + } + + public function __invoke(PostsContentBefore $event): void + { + $event->appendContent($this->view->render(self::TEMPLATE_NAME, [])); + } +} diff --git a/src/UI/Components/Archive/SearchHeadline.php b/src/UI/Components/Archive/SearchHeadline.php new file mode 100644 index 00000000..4810749b --- /dev/null +++ b/src/UI/Components/Archive/SearchHeadline.php @@ -0,0 +1,43 @@ + [ + SubscriberInterface::CALLBACK => $this, + SubscriberInterface::PRIORITY => self::EVENT_PRIORITY, + ]; + } + + public const TEMPLATE_NAME = 'archive/search-headline'; + + private ViewInterface $view; + + public function __construct( + ViewInterface $view + ) { + $this->view = $view; + } + + public function shouldDisplay(): bool + { + return \is_search(); + } + + public function __invoke(PostsContentBefore $event): void + { + $event->appendContent($this->view->render(self::TEMPLATE_NAME, [])); + } +} diff --git a/src/UI/Components/Comments/Comments.php b/src/UI/Components/Comments/Comments.php new file mode 100644 index 00000000..72df63a7 --- /dev/null +++ b/src/UI/Components/Comments/Comments.php @@ -0,0 +1,44 @@ + [ + SubscriberInterface::CALLBACK => $this, + SubscriberInterface::PRIORITY => 20, + ]; + } + + public const TEMPLATE_NAME = 'comments/comments'; + + private ConfigInterface $config; + private ViewInterface $view; + public function __construct(ConfigInterface $config, ViewInterface $view) + { + $this->config = $config; + $this->view = $view; + } + + public function shouldDisplay(): bool + { + return \is_singular() + && \post_type_supports((string)\get_post_type(), 'comments') + && ! \in_array('hide_comments', $this->config->get('post_content_template'), true); + } + + public function __invoke(Content $event): void + { + $event->appendContent($this->view->render(self::TEMPLATE_NAME)); + } +} diff --git a/src/UI/Components/ComponentInterface.php b/src/UI/Components/ComponentInterface.php new file mode 100644 index 00000000..6404f55d --- /dev/null +++ b/src/UI/Components/ComponentInterface.php @@ -0,0 +1,12 @@ +content .= $content; + } + + public function __toString(): string + { + return $this->content; + } +} diff --git a/src/UI/Components/ContentRenderableInterface.php b/src/UI/Components/ContentRenderableInterface.php new file mode 100644 index 00000000..273ffb27 --- /dev/null +++ b/src/UI/Components/ContentRenderableInterface.php @@ -0,0 +1,12 @@ +config->get( + ConfigColophonProvider::COLOPHON_ACTION, + Content::class + ); + $event_priority = (int)$this->config->get(ConfigColophonProvider::COLOPHON_PRIORITY, self::EVENT_PRIORITY); + yield $event_name => [ + static::CALLBACK => $this, + static::PRIORITY => $event_priority, + ]; + } + + public const EVENT_PRIORITY = 20; + public const CONTENT = 'content'; + + public const TEMPLATE_NAME = 'footer/colophon'; + + private ConfigInterface $config; + private ViewInterface $view; + + public function __construct( + ConfigInterface $config, + ViewInterface $view + ) { + $this->config = $config; + $this->view = $view; + } + + public function shouldDisplay(): bool + { + return true; + } + + public function __invoke(Content $event): void + { + $content = (string)$this->config->get(ConfigColophonProvider::COLOPHON, ''); + + if (empty($content)) { + return; + } + + $event->appendContent($this->view->render(self::TEMPLATE_NAME, [ + self::CONTENT => $content, + ])); + } +} diff --git a/src/UI/Components/Footer/Events/After.php b/src/UI/Components/Footer/Events/After.php new file mode 100644 index 00000000..d746197d --- /dev/null +++ b/src/UI/Components/Footer/Events/After.php @@ -0,0 +1,13 @@ + $this; + } + + public const TEMPLATE_NAME = 'footer/footer'; + private ViewInterface $view; + + private TagInterface $tag; + + private EventDispatcherInterface $dispatcher; + + public function __construct( + ViewInterface $view, + TagInterface $tag, + EventDispatcherInterface $dispatcher + ) { + $this->view = $view; + $this->tag = $tag; + $this->dispatcher = $dispatcher; + } + + public function shouldDisplay(): bool + { + return true; + } + + public function __invoke(\ItalyStrap\UI\Components\Main\Events\Footer $event) + { + $event->appendContent($this->view->render(self::TEMPLATE_NAME, [ + EventDispatcherInterface::class => $this->dispatcher, + TagInterface::class => $this->tag, + ])); + } +} diff --git a/src/UI/Components/Footer/FooterWidgetArea.php b/src/UI/Components/Footer/FooterWidgetArea.php new file mode 100644 index 00000000..da7bca0e --- /dev/null +++ b/src/UI/Components/Footer/FooterWidgetArea.php @@ -0,0 +1,41 @@ + $this; + } + + public const TEMPLATE_NAME = 'footer/widget-area'; + + private ViewInterface $view; + + public function __construct( + ViewInterface $view + ) { + $this->view = $view; + } + + public function shouldDisplay(): bool + { + return true; + } + + public function __invoke(Content $event): void + { + $event->appendContent($this->view->render(self::TEMPLATE_NAME, [ + 'footer_sidebars' => ConfigSidebarProvider::FOOTERS, + ])); + } +} diff --git a/src/UI/Components/Header/CustomHeaderImage.php b/src/UI/Components/Header/CustomHeaderImage.php new file mode 100644 index 00000000..d21fde0b --- /dev/null +++ b/src/UI/Components/Header/CustomHeaderImage.php @@ -0,0 +1,106 @@ + [ + SubscriberInterface::CALLBACK => $this, + SubscriberInterface::PRIORITY => self::EVENT_PRIORITY, + ]; + } + + public const TEMPLATE_NAME = 'header/custom-header'; + + public const CONTENT = 'content'; + public const CONTAINER_WIDTH = 'container_width'; + + private ConfigInterface $config; + private ViewInterface $view; + private TagInterface $tag; + + public function __construct( + ConfigInterface $config, + ViewInterface $view, + TagInterface $tag, + Figure $figure + ) { + $this->config = $config; + $this->view = $view; + $this->tag = $tag; + $this->figure = $figure; + } + + public function shouldDisplay(): bool + { + return \has_header_image(); + } + + public function __invoke(Content $event): void + { + $event->appendContent($this->view->render(self::TEMPLATE_NAME, [ + self::CONTENT => $this->printFigureContainer(), + ])); + } + + private function printFigureContainer(): string + { + return $this->view->render(Figure::TEMPLATE_NAME, [ + TagInterface::class => $this->tag, + Figure::CONTEXT => self::class, + Figure::ATTR => [ + 'class' => \sprintf( + 'wp-block-image %s size-large', + (string)$this->config->get(ConfigCustomHeaderProvider::CUSTOM_HEADER_ALIGNMENT) + ), + ], + Figure::CONTENT => \get_header_image_tag(), + ]); + } + + private function printAnchorTag(): string + { + return \sprintf( + '%s%s%s', + $this->tag->open('custom-header-anchor', 'a', [ + 'href' => \get_home_url(null, '/'), + 'rel' => 'home', + ]), + \get_header_image_tag(), + $this->tag->close('custom-header-anchor') + ); + } + + private function printForAttachment(): string + { + $post_meta_id = \absint(\get_post_meta(\get_the_ID(), '_italystrap_custom_header_id', true)); + return $this->getAttachmentImage($post_meta_id); + } + + private function getAttachmentImage(int $id, string $size = 'full'): string + { + + $attr = [ + 'class' => "attachment-$id attachment-header size-header", + 'alt' => esc_attr($this->config->get('GET_BLOGINFO_NAME')), + ]; + + return \wp_get_attachment_image($id, $size, false, $attr); + } +} diff --git a/src/UI/Components/Header/Events/BodyOpened.php b/src/UI/Components/Header/Events/BodyOpened.php new file mode 100644 index 00000000..737542cf --- /dev/null +++ b/src/UI/Components/Header/Events/BodyOpened.php @@ -0,0 +1,13 @@ + $this; + } + + public const TEMPLATE_NAME = 'header/header'; + public const WRAPPER_CLASS_NAMES = 'wrapper_class_names'; + + private ViewInterface $view; + private TagInterface $tag; + private EventDispatcherInterface $dispatcher; + + public function __construct( + ViewInterface $view, + EventDispatcherInterface $dispatcher, + TagInterface $tag + ) { + $this->view = $view; + $this->dispatcher = $dispatcher; + $this->tag = $tag; + } + + public function shouldDisplay(): bool + { + return true; + } + + public function __invoke(\ItalyStrap\UI\Components\Main\Events\Header $event): void + { + $event->appendContent($this->view->render(self::TEMPLATE_NAME, [ + EventDispatcherInterface::class => $this->dispatcher, + TagInterface::class => $this->tag, + self::WRAPPER_CLASS_NAMES => 'wrapper wp-site-blocks', + ])); + } +} diff --git a/src/UI/Components/Main/Canvas.php b/src/UI/Components/Main/Canvas.php new file mode 100644 index 00000000..4bde43ca --- /dev/null +++ b/src/UI/Components/Main/Canvas.php @@ -0,0 +1,54 @@ + $this; + } + + public const TEMPLATE_NAME = 'main/canvas'; + public const BODY_CLASS_NAMES = 'body_class_names'; + + private ConfigInterface $config; + + private EventDispatcherInterface $dispatcher; + private ViewInterface $view; + + public function __construct( + ConfigInterface $config, + ViewInterface $view, + EventDispatcherInterface $dispatcher + ) { + $this->config = $config; + $this->view = $view; + $this->dispatcher = $dispatcher; + } + + public function shouldDisplay(): bool + { + return true; + } + + public function __invoke(Events\Index $event): void + { + $event->appendContent($this->view->render(self::TEMPLATE_NAME, [ + EventDispatcherInterface::class => $this->dispatcher, + self::BODY_CLASS_NAMES => \sprintf( + '%s %s', + \join(' ', \get_body_class()), + $this->config->get('current_template_slug') + ), + ])); + } +} diff --git a/src/UI/Components/Main/Events/Canvas.php b/src/UI/Components/Main/Events/Canvas.php new file mode 100644 index 00000000..98985c68 --- /dev/null +++ b/src/UI/Components/Main/Events/Canvas.php @@ -0,0 +1,13 @@ + $this; + } + + public const TEMPLATE_NAME = 'main/main'; + + private EventDispatcherInterface $dispatcher; + + private ConfigInterface $config; + private ViewInterface $view; + + public function __construct( + ConfigInterface $config, + ViewInterface $view, + EventDispatcherInterface $dispatcher + ) { + $this->config = $config; + $this->view = $view; + $this->dispatcher = $dispatcher; + } + + public function shouldDisplay(): bool + { + return true; + } + + public function __invoke(Events\Canvas $event): void + { + $event->appendContent($this->view->render(self::TEMPLATE_NAME, [ + EventDispatcherInterface::class => $this->dispatcher, + 'container_class_names' => (string)$this->config->get('container_width', ''), + 'row_class_names' => 'row', + ])); + } +} diff --git a/src/UI/Components/Posts/Events/PostContent.php b/src/UI/Components/Posts/Events/PostContent.php new file mode 100644 index 00000000..656e6971 --- /dev/null +++ b/src/UI/Components/Posts/Events/PostContent.php @@ -0,0 +1,13 @@ + $this; + } + + public const TEMPLATE_NAME = 'posts/not-found'; + + private ViewInterface $view; + private EventDispatcherInterface $dispatcher; + + public function __construct( + ViewInterface $view, + EventDispatcherInterface $dispatcher + ) { + $this->view = $view; + $this->dispatcher = $dispatcher; + } + + public function shouldDisplay(): bool + { + return true; + } + + public function __invoke(PostsNotFound $event) + { + $event->appendContent($this->view->render(self::TEMPLATE_NAME, [ + EventDispatcherInterface::class => $this->dispatcher, + ])); + } +} diff --git a/src/UI/Components/Posts/NotFound/Content.php b/src/UI/Components/Posts/NotFound/Content.php new file mode 100644 index 00000000..eef1e586 --- /dev/null +++ b/src/UI/Components/Posts/NotFound/Content.php @@ -0,0 +1,82 @@ + [ + SubscriberInterface::CALLBACK => $this, + SubscriberInterface::PRIORITY => self::EVENT_PRIORITY, + ]; + } + + public const TEMPLATE_NAME = 'posts/not-found/content'; + + public const CONTENT = 'content'; + public const SEARCH = 'search'; + + private ConfigInterface $config; + private ViewInterface $view; + + private string $search = ''; + + public function __construct( + ConfigInterface $config, + ViewInterface $view, + Search $search + ) { + $this->config = $config; + $this->view = $view; + $this->searchObj = $search; + } + + public function shouldDisplay(): bool + { + return true; + } + + public function __invoke(PostsNotFoundContent $event): void + { + $event->appendContent($this->view->render(self::TEMPLATE_NAME, [ + self::CONTENT => $this->content(), + self::SEARCH => $this->search, + ])); + } + private function content(): string + { + if (\is_front_page() && \current_user_can('publish_posts')) { + return \sprintf( + '%s %s.', + \__('Ready to publish your first post?', 'italystrap'), + \esc_url(\admin_url('post-new.php')), + \__('Get started here', 'italystrap') + ); + } + + $this->search = (string)$this->searchObj; + + if (\is_search()) { + return \__( + 'Sorry, but nothing matched your search terms. Please try again with some different keywords.', + 'italystrap' + ); + } + + return (string)$this->config->get(ConfigNotFoundProvider::CONTENT); + } +} diff --git a/src/UI/Components/Posts/NotFound/Image.php b/src/UI/Components/Posts/NotFound/Image.php new file mode 100644 index 00000000..71612101 --- /dev/null +++ b/src/UI/Components/Posts/NotFound/Image.php @@ -0,0 +1,98 @@ + [ + SubscriberInterface::CALLBACK => $this, + SubscriberInterface::PRIORITY => self::EVENT_PRIORITY, + ]; + } + + public const TEMPLATE_NAME = 'elements/figure'; + + private ConfigInterface $config; + private ViewInterface $view; + private GlobalDispatcherInterface $dispatcher; + private TagInterface $tag; + + public function __construct( + ConfigInterface $config, + ViewInterface $view, + GlobalDispatcherInterface $dispatcher, + TagInterface $tag, + Figure $figure + ) { + $this->config = $config; + $this->view = $view; + $this->dispatcher = $dispatcher; + $this->tag = $tag; + $this->figure = $figure; + $this->imageId = (int)$this->config->get(ConfigNotFoundProvider::ID_IMAGE, 0); + } + + public function shouldDisplay(): bool + { + return \is_404() + && 'show' === (string)$this->config->get(ConfigNotFoundProvider::SHOW_IMAGE, '') + && $this->hasImage(); + } + + public function __invoke(PostsNotFoundContent $event): void + { + $this->figure->withContext(self::class); + $this->figure->withContent($this->content()); + $this->figure->withAttributes([ + 'class' => \sprintf( + '%s wp-block-post-featured-image', + (string)$this->config->get(ConfigPostThumbnailProvider::POST_THUMBNAIL_ALIGNMENT), + ), + ]); + + $event->appendContent((string)$this->figure); + } + + private function content(): string + { + $size = (string)$this->config->get(ConfigPostThumbnailProvider::POST_THUMBNAIL_SIZE); + $html = \wp_get_attachment_image( + $this->imageId, + $size, + false, + [ + 'class' => "attachment-{$size} size-{$size} wp-post-image", + ] + ); + + return (string)$this->dispatcher->filter('italystrap_lazyload_images_in_this_content', $html); + } + + private function hasImage(): bool + { + return (bool)$this->imageId; + } +} diff --git a/src/UI/Components/Posts/NotFound/Title.php b/src/UI/Components/Posts/NotFound/Title.php new file mode 100644 index 00000000..fb939c59 --- /dev/null +++ b/src/UI/Components/Posts/NotFound/Title.php @@ -0,0 +1,50 @@ + [ + SubscriberInterface::CALLBACK => $this, + SubscriberInterface::PRIORITY => self::EVENT_PRIORITY, + ]; + } + + public const TEMPLATE_NAME = 'posts/not-found/title'; + + private ConfigInterface $config; + private ViewInterface $view; + + public function __construct( + ConfigInterface $config, + ViewInterface $view + ) { + $this->config = $config; + $this->view = $view; + } + + public function shouldDisplay(): bool + { + return true; + } + + public function __invoke(PostsNotFoundContent $event): void + { + $event->appendContent($this->view->render(self::TEMPLATE_NAME, [ + 'content' => (string)$this->config->get(ConfigNotFoundProvider::TITLE), + ])); + } +} diff --git a/src/UI/Components/Posts/Parts/Content.php b/src/UI/Components/Posts/Parts/Content.php new file mode 100644 index 00000000..87a94f26 --- /dev/null +++ b/src/UI/Components/Posts/Parts/Content.php @@ -0,0 +1,47 @@ + [ + SubscriberInterface::CALLBACK => $this, + SubscriberInterface::PRIORITY => self::EVENT_PRIORITY, + ]; + } + + public const TEMPLATE_NAME = 'posts/parts/content'; + + private ConfigInterface $config; + private ViewInterface $view; + + public function __construct(ConfigInterface $config, ViewInterface $view) + { + $this->config = $config; + $this->view = $view; + } + + public function shouldDisplay(): bool + { + return \is_singular() + && \post_type_supports((string)\get_post_type(), 'editor') + && ! \in_array('hide_content', (array)$this->config->get('post_content_template', []), true); + } + + public function __invoke(PostContent $event): void + { + $event->appendContent($this->view->render(self::TEMPLATE_NAME, [])); + } +} diff --git a/src/UI/Components/Posts/Parts/Excerpt.php b/src/UI/Components/Posts/Parts/Excerpt.php new file mode 100644 index 00000000..a3b4bd55 --- /dev/null +++ b/src/UI/Components/Posts/Parts/Excerpt.php @@ -0,0 +1,47 @@ + [ + SubscriberInterface::CALLBACK => $this, + SubscriberInterface::PRIORITY => self::EVENT_PRIORITY, + ]; + } + + public const TEMPLATE_NAME = 'posts/parts/excerpt'; + + private ConfigInterface $config; + private ViewInterface $view; + + public function __construct(ConfigInterface $config, ViewInterface $view) + { + $this->config = $config; + $this->view = $view; + } + + public function shouldDisplay(): bool + { + return ! \is_singular() + && \post_type_supports((string)\get_post_type(), 'excerpt') + && ! \in_array('hide_excerpt', (array)$this->config->get('post_content_template', []), true); + } + + public function __invoke(PostContent $event): void + { + $event->appendContent($this->view->render(self::TEMPLATE_NAME, [])); + } +} diff --git a/src/UI/Components/Posts/Parts/FeaturedImage.php b/src/UI/Components/Posts/Parts/FeaturedImage.php new file mode 100644 index 00000000..5265d683 --- /dev/null +++ b/src/UI/Components/Posts/Parts/FeaturedImage.php @@ -0,0 +1,88 @@ + [ + SubscriberInterface::CALLBACK => $this, + SubscriberInterface::PRIORITY => self::EVENT_PRIORITY, + ]; + } + + public const TEMPLATE_NAME = 'posts/parts/featured-image'; + + public const ATTRIBUTES = 'attributes'; + + private ConfigInterface $config; + private ViewInterface $view; + private Json $json; + + public function __construct( + ConfigInterface $config, + ViewInterface $view, + Json $json + ) { + $this->config = $config; + $this->view = $view; + $this->json = $json; + } + + public function shouldDisplay(): bool + { + return post_type_supports((string)get_post_type(), 'thumbnail') + && !in_array('hide_thumb', (array)$this->config->get('post_content_template', []), true); + } + + public function __invoke(PostContent $event): void + { +// if ( is_singular() ) { +// $this->config->add( ConfigPostThumbnailProvider::POST_THUMBNAIL_SIZE, 'post-thumbnail' ); +// $this->config->add( ConfigPostThumbnailProvider::POST_THUMBNAIL_ALIGNMENT, 'aligncenter' ); +// } + + $size = (string)$this->config->get(ConfigPostThumbnailProvider::POST_THUMBNAIL_SIZE); + $size = $this->getThumbnailSizeForFullWidthLayout($size); + $alignment = (string)$this->config->get(ConfigPostThumbnailProvider::POST_THUMBNAIL_ALIGNMENT); + + $event->appendContent($this->view->render(self::TEMPLATE_NAME, [ + self::ATTRIBUTES => $this->json->encode([ + 'align' => \str_replace('align', '', $alignment), + 'sizeSlug' => $size, + ]), + ])); + } + + public function getThumbnailSizeForFullWidthLayout(string $size): string + { + $site_layout = (string) $this->config->get('site_layout'); + + if ('full_width' === $site_layout) { + return 'full-width'; + } + + if (\is_page_template('full-width.php')) { + return 'full-width'; + } + + return $size; + } +} diff --git a/src/UI/Components/Posts/Parts/Meta.php b/src/UI/Components/Posts/Parts/Meta.php new file mode 100644 index 00000000..51cfec61 --- /dev/null +++ b/src/UI/Components/Posts/Parts/Meta.php @@ -0,0 +1,46 @@ + [ + SubscriberInterface::CALLBACK => $this, + SubscriberInterface::PRIORITY => self::EVENT_PRIORITY, + ]; + } + + public const TEMPLATE_NAME = 'posts/parts/meta'; + + private ConfigInterface $config; + private ViewInterface $view; + + public function __construct(ConfigInterface $config, ViewInterface $view) + { + $this->config = $config; + $this->view = $view; + } + + public function shouldDisplay(): bool + { + return \post_type_supports((string)\get_post_type(), 'entry-meta') + && ! \in_array('hide_meta', (array)$this->config->get('post_content_template', []), true); + } + + public function __invoke(PostContent $event): void + { + $event->appendContent($this->view->render(self::TEMPLATE_NAME, [])); + } +} diff --git a/src/UI/Components/Posts/Parts/Modified.php b/src/UI/Components/Posts/Parts/Modified.php new file mode 100644 index 00000000..642bc114 --- /dev/null +++ b/src/UI/Components/Posts/Parts/Modified.php @@ -0,0 +1,42 @@ + [ + SubscriberInterface::CALLBACK => $this, + SubscriberInterface::PRIORITY => self::EVENT_PRIORITY, + ]; + } + + public const TEMPLATE_NAME = 'posts/parts/modified'; + + private ViewInterface $view; + + public function __construct(ViewInterface $view) + { + $this->view = $view; + } + + public function shouldDisplay(): bool + { + return true; + } + + public function __invoke(PostContent $event): void + { + $event->appendContent($this->view->render(self::TEMPLATE_NAME, [])); + } +} diff --git a/src/UI/Components/Posts/Parts/PostAuthorInfo.php b/src/UI/Components/Posts/Parts/PostAuthorInfo.php new file mode 100644 index 00000000..899ddea1 --- /dev/null +++ b/src/UI/Components/Posts/Parts/PostAuthorInfo.php @@ -0,0 +1,45 @@ + [ + SubscriberInterface::CALLBACK => $this, + SubscriberInterface::PRIORITY => self::EVENT_PRIORITY, + ]; + } + + private ConfigInterface $config; + private AuthorInfo $authorInfo; + + public function __construct(ConfigInterface $config, AuthorInfo $author) + { + $this->config = $config; + $this->authorInfo = $author; + } + + public function shouldDisplay(): bool + { + return \post_type_supports((string)\get_post_type(), 'author') + && \is_singular() + && ! \in_array('hide_author', $this->config->get('post_content_template'), true); + } + + public function __invoke(PostContent $event): void + { + $event->appendContent((string)$this->authorInfo); + } +} diff --git a/src/UI/Components/Posts/Parts/Preview.php b/src/UI/Components/Posts/Parts/Preview.php new file mode 100644 index 00000000..9e938b65 --- /dev/null +++ b/src/UI/Components/Posts/Parts/Preview.php @@ -0,0 +1,43 @@ + [ + SubscriberInterface::CALLBACK => $this, + SubscriberInterface::PRIORITY => self::EVENT_PRIORITY, + ]; + } + + public const TEMPLATE_NAME = 'posts/parts/preview'; + + private ViewInterface $view; + + public function __construct( + ViewInterface $view + ) { + $this->view = $view; + } + + public function shouldDisplay(): bool + { + return \is_preview(); + } + + public function __invoke(PostContent $event): void + { + $event->appendContent($this->view->render(self::TEMPLATE_NAME, [])); + } +} diff --git a/src/UI/Components/Posts/Parts/Title.php b/src/UI/Components/Posts/Parts/Title.php new file mode 100644 index 00000000..6ef9d2d2 --- /dev/null +++ b/src/UI/Components/Posts/Parts/Title.php @@ -0,0 +1,61 @@ + [ + SubscriberInterface::CALLBACK => $this, + SubscriberInterface::PRIORITY => self::EVENT_PRIORITY, + ]; + } + + public const TEMPLATE_NAME = 'posts/parts/title'; + + public const ATTRIBUTES = 'attributes'; + + private ConfigInterface $config; + private ViewInterface $view; + private Json $json; + + public function __construct( + ConfigInterface $config, + ViewInterface $view, + Json $json + ) { + $this->config = $config; + $this->view = $view; + $this->json = $json; + } + + public function shouldDisplay(): bool + { + return \post_type_supports((string)\get_post_type(), 'title') + && ! \in_array('hide_title', (array)$this->config->get('post_content_template', []), true); + } + + public function __invoke(PostContent $event): void + { + $event->appendContent($this->view->render(self::TEMPLATE_NAME, [ + self::ATTRIBUTES => $this->json->encode([ + "level" => \is_singular() ? 1 : 2, + "isLink" => true, + "rel" => "bookmark", + "className" => "entry-title", + ]), + ])); + } +} diff --git a/src/UI/Components/Posts/Post.php b/src/UI/Components/Posts/Post.php new file mode 100644 index 00000000..0d5d5a55 --- /dev/null +++ b/src/UI/Components/Posts/Post.php @@ -0,0 +1,75 @@ + $this; + } + + public const TEMPLATE_NAME = 'posts/post'; + + private ConfigInterface $config; + private ViewInterface $view; + private EventDispatcherInterface $dispatcher; + + public function __construct( + ConfigInterface $config, + ViewInterface $view, + EventDispatcherInterface $dispatcher + ) { + $this->config = $config; + $this->view = $view; + $this->dispatcher = $dispatcher; + } + + public function shouldDisplay(): bool + { + return true; + } + + public function __invoke(PostsContent $event): void + { + $event->appendContent($this->view->render(self::TEMPLATE_NAME, [ + EventDispatcherInterface::class => $this->dispatcher, + 'id' => \get_the_ID(), + 'class_names' => \join(' ', $this->classForPostThumbnail()) + ])); + } + + private function classForPostThumbnail(): array + { + $classes = \get_post_class(); + + /** + * If it has not a post thumbnail just bail out. + */ + if (! has_post_thumbnail()) { + return $classes; + } + + /** + * Remove the 'hentry' css class to prevents error in search console + */ + foreach ($classes as $key => $class) { + if ('hentry' === $class) { + unset($classes[ $key ]); + } + } + + $classes[] = 'post-thumbnail-' . $this->config->get('post_thumbnail_alignment'); + + return $classes; + } +} diff --git a/src/UI/Components/Posts/Posts.php b/src/UI/Components/Posts/Posts.php new file mode 100644 index 00000000..2fb7f14e --- /dev/null +++ b/src/UI/Components/Posts/Posts.php @@ -0,0 +1,44 @@ + $this; + } + + public const TEMPLATE_NAME = 'posts/posts'; + + private ViewInterface $view; + private EventDispatcherInterface $dispatcher; + + public function __construct( + ViewInterface $view, + EventDispatcherInterface $dispatcher + ) { + $this->view = $view; + $this->dispatcher = $dispatcher; + } + + public function shouldDisplay(): bool + { + return true; + } + + public function __invoke(Content $event): void + { + $event->appendContent($this->view->render(self::TEMPLATE_NAME, [ + EventDispatcherInterface::class => $this->dispatcher, + ])); + } +} diff --git a/src/UI/Components/Sidebars/Events/After.php b/src/UI/Components/Sidebars/Events/After.php new file mode 100644 index 00000000..95ba2434 --- /dev/null +++ b/src/UI/Components/Sidebars/Events/After.php @@ -0,0 +1,13 @@ + $this; + } + + public const TEMPLATE_NAME = 'sidebars/sidebar'; + public const INDEX = 'index'; + + private ConfigInterface $config; + private ViewInterface $view; + private EventDispatcherInterface $dispatcher; + public function __construct( + ConfigInterface $config, + ViewInterface $view, + EventDispatcherInterface $dispatcher + ) { + $this->config = $config; + $this->view = $view; + $this->dispatcher = $dispatcher; + } + + public function shouldDisplay(): bool + { + return ('full_width' !== $this->config->get('site_layout')) + && \is_active_sidebar(ConfigSidebarProvider::SIDEBAR_PRIMARY); + } + + public function __invoke(ContentAfter $event): void + { + $event->appendContent($this->view->render(self::TEMPLATE_NAME, [ + EventDispatcherInterface::class => $this->dispatcher, + self::INDEX => ConfigSidebarProvider::SIDEBAR_PRIMARY, + ])); + } +} diff --git a/src/UI/Components/Site/Logo.php b/src/UI/Components/Site/Logo.php new file mode 100644 index 00000000..f9a8266b --- /dev/null +++ b/src/UI/Components/Site/Logo.php @@ -0,0 +1,70 @@ + [ + SubscriberInterface::CALLBACK => $this, + SubscriberInterface::PRIORITY => self::EVENT_PRIORITY, + ]; + } + + public const ATTRIBUTES = 'attributes'; + + public const TEMPLATE_NAME = 'site/logo'; + + private ConfigInterface $config; + private ViewInterface $view; + private Support $support; + private Json $json; + + public function __construct( + ConfigInterface $config, + ViewInterface $view, + Support $support, + Json $json + ) { + $this->config = $config; + $this->view = $view; + $this->support = $support; + $this->json = $json; + } + + public function shouldDisplay(): bool + { + return $this->support->has(ConfigThemeSupportProvider::CUSTOM_LOGO) + && $this->config->get(ConfigSiteLogoProvider::CUSTOM_LOGO_ID); + } + + public function __invoke(NavMenuHeaderContent $event): void + { + $size_name_registered = (string)$this->config->get(ConfigSiteLogoProvider::BRAND_IMAGE_SIZE); + $width = (int)$this->config->get(ThumbnailsSubscriber::class . '.' . $size_name_registered . '.width'); + + $event->appendContent($this->view->render(self::TEMPLATE_NAME, [ + self::ATTRIBUTES => $this->json->encode([ + 'width' => $width, + 'shouldSyncIcon' => 'false', + 'className' => 'is-style-default', + ]), + ])); + } +} diff --git a/src/UI/Components/Site/Tagline.php b/src/UI/Components/Site/Tagline.php new file mode 100644 index 00000000..186414f4 --- /dev/null +++ b/src/UI/Components/Site/Tagline.php @@ -0,0 +1,44 @@ + [ + SubscriberInterface::CALLBACK => $this, + SubscriberInterface::PRIORITY => self::EVENT_PRIORITY, + ]; + } + + public const ATTRIBUTES = 'attributes'; + + public const TEMPLATE_NAME = 'site/tagline'; + private ViewInterface $view; + + public function __construct( + ViewInterface $view + ) { + $this->view = $view; + } + + public function shouldDisplay(): bool + { + return true; + } + + public function __invoke(NavMenuHeaderContent $event): void + { + $event->appendContent($this->view->render(self::TEMPLATE_NAME)); + } +} diff --git a/src/UI/Components/Site/Title.php b/src/UI/Components/Site/Title.php new file mode 100644 index 00000000..33307043 --- /dev/null +++ b/src/UI/Components/Site/Title.php @@ -0,0 +1,44 @@ + [ + SubscriberInterface::CALLBACK => $this, + SubscriberInterface::PRIORITY => self::EVENT_PRIORITY, + ]; + } + + public const ATTRIBUTES = 'attributes'; + + public const TEMPLATE_NAME = 'site/title'; + private ViewInterface $view; + + public function __construct( + ViewInterface $view + ) { + $this->view = $view; + } + + public function shouldDisplay(): bool + { + return true; + } + + public function __invoke(NavMenuHeaderContent $event): void + { + $event->appendContent($this->view->render(self::TEMPLATE_NAME)); + } +} diff --git a/src/UI/Elements/AuthorInfo.php b/src/UI/Elements/AuthorInfo.php new file mode 100644 index 00000000..bc70d455 --- /dev/null +++ b/src/UI/Elements/AuthorInfo.php @@ -0,0 +1,60 @@ + 96, + self::SHOW_BIO => true, + self::BYLINE => '', + self::IS_LINK => true, + self::CLASS_NAME => 'author-info', + ]; + + private array $attributes = []; + + private ViewInterface $view; + private Json $json; + + public function __construct(ViewInterface $view, Json $json) + { + $this->view = $view; + $this->json = $json; + } + + public function withAttributes(array $attributes): void + { + $this->attributes = $attributes; + } + + public function withContext(string $context): void + { + } + + public function withContent(string $content): void + { + } + + public function __toString() + { + return \do_shortcode( + $this->view->render(self::TEMPLATE_NAME, [ + self::ATTR => $this->json->encode(\array_merge(self::DEFAULT, $this->attributes)), + ]) + ); + } +} diff --git a/src/UI/Elements/ElementInterface.php b/src/UI/Elements/ElementInterface.php new file mode 100644 index 00000000..514186cd --- /dev/null +++ b/src/UI/Elements/ElementInterface.php @@ -0,0 +1,18 @@ +view = $view; + $this->tag = $tag; + } + + public function withAttributes(array $attributes): void + { + $this->attributes = $attributes; + } + + public function withContext(string $context): void + { + $this->context = $context; + } + + public function withContent(string $content): void + { + $this->content = $content; + } + + public function __toString(): string + { + return $this->view->render(self::TEMPLATE_NAME, [ + TagInterface::class => $this->tag, + self::ATTR => $this->attributes, + self::CONTEXT => $this->context, + self::CONTENT => $this->content, + ]); + } +} diff --git a/src/UI/Elements/Search.php b/src/UI/Elements/Search.php new file mode 100644 index 00000000..63a8e73f --- /dev/null +++ b/src/UI/Elements/Search.php @@ -0,0 +1,52 @@ +view = $view; + $this->tag = $tag; + } + + public function withAttributes(array $attributes): void + { + $this->attributes = $attributes; + } + + public function withContext(string $context): void + { + $this->context = $context; + } + + public function withContent(string $content): void + { + $this->content = $content; + } + + public function __toString(): string + { + return $this->view->render(self::TEMPLATE_NAME, [ +// TagInterface::class => $this->tag, +// self::ATTR => $this->attributes, +// self::CONTEXT => $this->context, +// self::CONTENT => $this->content, + ]); + } +} diff --git a/src/UI/Infrastructure/ComponentSubscriberExtension.php b/src/UI/Infrastructure/ComponentSubscriberExtension.php new file mode 100644 index 00000000..edd4f430 --- /dev/null +++ b/src/UI/Infrastructure/ComponentSubscriberExtension.php @@ -0,0 +1,85 @@ +subscriberRegister = $subscriberRegister; + $this->listenerRegister = $listenerRegister; + $this->proxy = new ProxyFactory(); + } + + public function name(): string + { + return self::class; + } + + public function execute(AurynConfigInterface $application) + { +// $listeners = [ +// 'template_include', +// 'enqueue_block_editor_assets', +// ]; +// +// foreach ($listeners as $listener) { +// $this->listenerRegister->addListener( +// $listener, +// function (string $current_template = '') use ($application): string { +// $application->walk($this->name(), $this); +// return $current_template; +// }, +// PHP_INT_MAX - 5 +// ); +// } +// + $application->walk($this->name(), $this); + + $this->listenerRegister->addListener( + 'template_include', + function (string $current_template = '') use ($application): string { + $application->walk($this->name(), $this); + return $current_template; + }, + PHP_INT_MAX - 5 + ); + } + + public function __invoke(string $class, $index_or_optionName, Injector $injector): void + { + /** @var SubscriberInterface|ComponentInterface $instance */ + $instance = $injector + ->share($class) + ->proxy($class, $this->proxy) + ->make($class); + + if ($this->shouldNotDisplay($instance)) { + return; + } + + $this->subscriberRegister->addSubscriber($instance); + } + + private function shouldNotDisplay(ComponentInterface $instance): bool + { + return ! $instance->shouldDisplay(); + } +} diff --git a/src/UI/Infrastructure/ViewBlock.php b/src/UI/Infrastructure/ViewBlock.php new file mode 100644 index 00000000..6edbbaea --- /dev/null +++ b/src/UI/Infrastructure/ViewBlock.php @@ -0,0 +1,24 @@ +view = $view; + } + + public function render($slugs, $data = []): string + { + return do_blocks($this->view->render($slugs, $data)); + } +} diff --git a/src/UI/Infrastructure/ViewBlockInterface.php b/src/UI/Infrastructure/ViewBlockInterface.php new file mode 100644 index 00000000..cb032473 --- /dev/null +++ b/src/UI/Infrastructure/ViewBlockInterface.php @@ -0,0 +1,11 @@ +content; + } + } + + return ''; + } +} diff --git a/src/UI/Module.php b/src/UI/Module.php new file mode 100644 index 00000000..c533e244 --- /dev/null +++ b/src/UI/Module.php @@ -0,0 +1,101 @@ + [ + ViewBlockInterface::class, + AuthorInfo::class, + ], + AurynConfig::ALIASES => [ + ViewBlockInterface::class => ViewBlock::class, + ], + AurynConfig::DEFINITIONS => [ + Main::class => [ + 'view' => ViewBlockInterface::class, + ], + ], + ComponentSubscriberExtension::class => [ + + PostAuthorInfo::class, + ArchiveAuthorInfo::class, + ArchiveHeadline::class, + SearchHeadline::class, + + FeaturedImage::class, + Title::class, + Meta::class, + Preview::class, + Content::class, + Excerpt::class, + Modified::class, + + Sidebar::class, + + Post::class, + + NotFoundImage::class, + NotFoundTitle::class, + NotFoundContent::class, + NotFound::class, + + Posts::class, + + SiteLogo::class, + SiteTitle::class, + SiteTagline::class, + + CustomHeaderImage::class, + + Comments::class, + Colophon::class, + Header::class, + FooterWidgetArea::class, + Footer::class, + Main::class => Main::class, + Canvas::class, + ], + ]; + } +} diff --git a/src/bootstrap.php b/src/bootstrap.php index 8ce48000..bdc94983 100644 --- a/src/bootstrap.php +++ b/src/bootstrap.php @@ -1,92 +1,52 @@ alias( EventDispatcherInterface::class, EventDispatcher::class ) - ->share( EventDispatcher::class ) - ->alias( SubscriberRegisterInterface::class, SubscriberRegister::class ) - ->share( SubscriberRegister::class ) - ->alias( ConfigInterface::class, Config::class ) - ->share( Config::class ); - - $event_dispatcher = $injector->make( EventDispatcher::class ); - - $injector - ->alias(FinderInterface::class, Finder::class) - ->delegate(Finder::class, ExperimentalThemeFileFinderFactory::class) - ->share( FinderInterface::class ); - - $finder = $injector->make( FinderInterface::class ); - - $injector_config = $injector->make( AurynConfig::class, [ - ':dependencies' => (require __DIR__ . '/../config/dependencies.config.php')($finder) - ] ); - - $injector_config->extend( $injector->make( ConfigProviderExtension::class ) ); - $injector_config->extend( $injector->make( SubscribersConfigExtension::class ) ); - $injector_config->extend( $injector->make( ComponentSubscriberExtension::class ) ); - $injector_config->extend( $injector->make( CustomizerProviderExtension::class ) ); - - /** - * ======================================================================== - * - * Load the framework - * In this case the priority is at -1 because we have to make sure - * everything is loaded, plugins as well. - * - * ======================================================================== - */ - $event_dispatcher->addListener( 'after_setup_theme', fn() => $injector_config->resolve(), -1 ); +use function ItalyStrap\Factory\injector; - /** - * So, now in your child theme you can do something like that: - * $injector = require \get_template_directory() . '/src/bootstrap.php'; - * - * or even better: - * (static function( Injector $injector ) {...do stuff})(require \get_template_directory() . '/src/bootstrap.php'); - */ - return $injector; +require __DIR__ . DIRECTORY_SEPARATOR . '../vendor/autoload.php'; + +return (static function (Injector $injector): Injector { + $injectorConfig = $injector->make(AurynConfig::class, [ + ':dependencies' => (require __DIR__ . '/../config/dependencies.config.php')($injector) + ]); + + $injectorConfig->extendFromClassName(ConfigProviderExtension::class); + $injectorConfig->extendFromClassName(SubscribersConfigExtension::class); + $injectorConfig->extendFromClassName(ComponentSubscriberExtension::class); + $injectorConfig->extendFromClassName(CustomizerProviderExtension::class); + + $listenerProvider = $injector + ->share(GlobalOrderedListenerProvider::class) + ->make(GlobalOrderedListenerProvider::class); + + /** + * ======================================================================== + * + * Load the framework + * In this case the priority is at -1 because we have to make sure + * everything is loaded, plugins as well. + * + * ======================================================================== + */ + $listenerProvider->addListener('after_setup_theme', fn() => $injectorConfig->resolve(), -1); + + /** + * So, now in your child theme you can do something like that: + * $injector = require \get_template_directory() . '/src/bootstrap.php'; + * + * or even better: + * (static function( Injector $injector ) {...do stuff})(require \get_template_directory() . '/src/bootstrap.php'); + */ + return $injector; })(injector()); diff --git a/templates/archive/archive-headline.php b/templates/archive/archive-headline.php new file mode 100644 index 00000000..b1317506 --- /dev/null +++ b/templates/archive/archive-headline.php @@ -0,0 +1,13 @@ + + + + \ No newline at end of file diff --git a/templates/archive/search-headline.php b/templates/archive/search-headline.php new file mode 100644 index 00000000..476d58f2 --- /dev/null +++ b/templates/archive/search-headline.php @@ -0,0 +1,12 @@ + + + + diff --git a/templates/comments.php b/templates/comments.php deleted file mode 100644 index 7564f948..00000000 --- a/templates/comments.php +++ /dev/null @@ -1,53 +0,0 @@ - - -
    - - - - - -
    - -
    - -
    - - - -
    - - - -
    - - - -
    - - - - - -
    - - -
    - - - - - - - - - - - - - - -
    - diff --git a/templates/comments/comments.php b/templates/comments/comments.php new file mode 100644 index 00000000..111528be --- /dev/null +++ b/templates/comments/comments.php @@ -0,0 +1,54 @@ + + +
    + + + + + +
    + +
    + +
    + + + +
    + + + +
    + + + +
    + + + + + +
    + + +
    + + + + + + + + + + + + + + +
    + diff --git a/templates/elements/author-info.php b/templates/elements/author-info.php new file mode 100644 index 00000000..40648460 --- /dev/null +++ b/templates/elements/author-info.php @@ -0,0 +1,10 @@ + + diff --git a/templates/elements/figure.php b/templates/elements/figure.php new file mode 100644 index 00000000..2eadf7a9 --- /dev/null +++ b/templates/elements/figure.php @@ -0,0 +1,23 @@ +get(TagInterface::class); + +$context = (string)$config->get(ElementInterface::CONTEXT, __FILE__); +$attributes = (array)$config->get(ElementInterface::ATTR, []); + +echo $tag->open($context, 'figure', $attributes); +echo $this->get(ElementInterface::CONTENT, ''); +echo $tag->close($context); diff --git a/templates/elements/search.php b/templates/elements/search.php new file mode 100644 index 00000000..d31f534f --- /dev/null +++ b/templates/elements/search.php @@ -0,0 +1,8 @@ + + diff --git a/templates/figure.php b/templates/figure.php deleted file mode 100644 index 6da06217..00000000 --- a/templates/figure.php +++ /dev/null @@ -1,20 +0,0 @@ -get(Tag::class); - -$context = (string)$config->get('context', __FILE__); -$attributes = (array)$config->get('figureAttributes', []); - -echo $tag->open($context, 'figure', $attributes); -echo $this->get('content'); -echo $tag->close($context); diff --git a/templates/footer.php b/templates/footer.php deleted file mode 100644 index 2125ecc3..00000000 --- a/templates/footer.php +++ /dev/null @@ -1,36 +0,0 @@ -get(EventDispatcherInterface::class); - -$dispatcher->dispatch( 'italystrap_before_footer' ); - -open_tag_e( 'footer', 'footer', [ - 'class' => 'site-footer', -] ); - -$dispatcher->dispatch( 'italystrap_footer' ); - -close_tag_e( 'footer' ); - -$dispatcher->dispatch( 'italystrap_after_footer' ); - -close_tag_e( 'wrapper' ); - -$dispatcher->dispatch( 'italystrap_after' ); - -\wp_footer(); - -close_tag_e( 'body' ); -?> - diff --git a/templates/footer/colophon.php b/templates/footer/colophon.php new file mode 100644 index 00000000..b9a0f3c6 --- /dev/null +++ b/templates/footer/colophon.php @@ -0,0 +1,22 @@ + + +
    + +
    + +

    get(Colophon::CONTENT, '')); ?>

    + +
    + +
    + diff --git a/templates/footer/footer.php b/templates/footer/footer.php new file mode 100644 index 00000000..d1972c30 --- /dev/null +++ b/templates/footer/footer.php @@ -0,0 +1,34 @@ +get(EventDispatcherInterface::class); + +/** @var TagInterface $tag */ +$tag = $this->get(TagInterface::class); + +?> +dispatch(new Before()); ?> + + +
    + dispatch(new Content()); ?> +
    + + +dispatch(new After()); ?> +close('wrapper'); + +echo $dispatcher->dispatch(new BodyClosing()); diff --git a/templates/footer/widget-area.php b/templates/footer/widget-area.php new file mode 100644 index 00000000..0716decc --- /dev/null +++ b/templates/footer/widget-area.php @@ -0,0 +1,33 @@ + + +
    + +
    + get('footer_sidebars', []) as $value) : ?> + + +
    + +
    + + + + +
    + +
    + + + +
    +
    +

    Text

    +
    +
    + diff --git a/templates/footers/colophon.php b/templates/footers/colophon.php deleted file mode 100644 index a294b6e7..00000000 --- a/templates/footers/colophon.php +++ /dev/null @@ -1,29 +0,0 @@ - - -
    - -
    - -

    get( Colophon::CONTENT, '' ) ) ; ?>

    - -
    - -
    - diff --git a/templates/footers/index.php b/templates/footers/index.php deleted file mode 100644 index b3d9bbc7..00000000 --- a/templates/footers/index.php +++ /dev/null @@ -1 +0,0 @@ - - -
    - -
    - get( 'footer_sidebars', [] ) as $value ) : ?> - - -
    - -
    - - - - -
    - -
    - diff --git a/templates/header.php b/templates/header.php deleted file mode 100644 index be645dc2..00000000 --- a/templates/header.php +++ /dev/null @@ -1,42 +0,0 @@ -get(EventDispatcherInterface::class); - -/** @var string $body_class */ -$body_class = $this->get(Header::BODY_CLASS_NAMES); - -/** @var string $wrapper_class */ -$wrapper_class = $this->get(Header::WRAPPER_CLASS_NAMES); - -?> -> - - - - - $body_class, -] ); - -\wp_body_open(); - -$dispatcher->dispatch('italystrap_before'); - -open_tag_e( 'wrapper', 'div', [ - 'class' => $wrapper_class, -] ); - -$dispatcher->dispatch('italystrap_before_header'); - -$dispatcher->dispatch('italystrap_content_header'); - -$dispatcher->dispatch('italystrap_after_header'); diff --git a/templates/header/custom-header.php b/templates/header/custom-header.php new file mode 100644 index 00000000..7ac4dabb --- /dev/null +++ b/templates/header/custom-header.php @@ -0,0 +1,19 @@ + + + + diff --git a/templates/header/header.php b/templates/header/header.php new file mode 100644 index 00000000..b21faddb --- /dev/null +++ b/templates/header/header.php @@ -0,0 +1,22 @@ +get(EventDispatcherInterface::class); +$tag = (object)$this->get(TagInterface::class); + +echo $dispatcher->dispatch(new BodyOpened()); + +echo $tag->open('wrapper', 'div', [ + 'class' => (string)$this->get(Header::WRAPPER_CLASS_NAMES, ''), +]); + +echo $dispatcher->dispatch(new Content()); diff --git a/templates/headers/custom-header.php b/templates/headers/custom-header.php deleted file mode 100644 index cd7b3ec7..00000000 --- a/templates/headers/custom-header.php +++ /dev/null @@ -1,23 +0,0 @@ -get(EventDispatcherInterface::class); -?> - - - diff --git a/templates/headers/index.php b/templates/headers/index.php deleted file mode 100644 index b3d9bbc7..00000000 --- a/templates/headers/index.php +++ /dev/null @@ -1 +0,0 @@ - diff --git a/templates/headers/navbar.php b/templates/headers/navbar.php deleted file mode 100644 index f9d7db0a..00000000 --- a/templates/headers/navbar.php +++ /dev/null @@ -1,123 +0,0 @@ -get(Navbar::class); - -/** @var NavMenuPrimary $nav_menu_primary */ -$nav_menu_primary = $config->get(NavMenuPrimary::class); - -/** @var NavMenuSecondary $nav_menu_secondary */ -$nav_menu_secondary = $config->get(NavMenuSecondary::class); - - -$number = \esc_attr( $config->get('number', \rand() ) ); -$navbar_id = 'italystrap-menu-' . $number; - - -open_tag_e('nav_container', 'div', [ - 'id' => 'main-navbar-container-' . $navbar_id, - 'class' => sprintf( - 'navbar-wrapper %s', - $config->get('mods.navbar.nav_width') - ), -]); - - open_tag_e('navbar_container', 'nav', [ - // 'class' => 'navbar navbar-expand-lg navbar-light bg-light', - 'class' => \sprintf( - 'navbar %s %s', - $config->get('mods.navbar.type'), - $config->get('mods.navbar.position') - ), - 'role' => 'navigation', - 'itemscope' => true, - 'itemtype' => 'https://schema.org/SiteNavigationElement', - ]); - - /** - * This was "'last_container'" - */ - open_tag_e('nav-inner-container', 'div', [ - 'id' => 'menus-container-' . $number, - 'class' => $config->get('mods.navbar.menus_width'), - ]); - - /** - * - * - * - */ - open_tag_e( - 'navbar_header', - 'div', - [ - 'class' => 'navbar-header', - 'itemprop' => 'publisher', - 'itemscope' => true, - 'itemtype' => 'https://schema.org/Organization', - ] - ); - - echo $navbar->get_navbar_brand(); - -/** - * = BS3 navbar-toggle - * >= BS4 navbar-toggler - */ - ?> - - $navbar_id, - 'class' => 'navbar-collapse collapse', - ]); - - $nav_menu_primary->display(); - $nav_menu_secondary->display(); - - close_tag_e('collapsable_menu'); - close_tag_e('nav-inner-container'); - close_tag_e('navbar_container'); - - close_tag_e('nav_container'); diff --git a/templates/index.html b/templates/index.html deleted file mode 100644 index ec42d487..00000000 --- a/templates/index.html +++ /dev/null @@ -1,18 +0,0 @@ - -
    - - - - -
    - - -
    - - - -
    - - -
    - \ No newline at end of file diff --git a/templates/index.php b/templates/index.php deleted file mode 100644 index 966cb4f5..00000000 --- a/templates/index.php +++ /dev/null @@ -1,78 +0,0 @@ -get(EventDispatcherInterface::class); - -/** @var string $container_class_names */ -$container_class_names = (string)$this->get('container_class_names'); - -/** @var string $row_class_names */ -$row_class_names = (string)$this->get('row_class_names'); - -$dispatcher->dispatch( 'italystrap_before_main' ); - -?> - -
    - $container_class_names, -// ] ); -// open_tag_e( 'index-row', 'div', [ -// 'class' => $row_class_names, -// ] ); - - $dispatcher->dispatch( 'italystrap_before_content' ); -?> - -
    - - -
    - - dispatch( 'italystrap_before_loop' ); - - $dispatcher->dispatch( 'italystrap_loop' ); - - $dispatcher->dispatch( 'italystrap_after_loop' ); - ?> - -
    - - - dispatch( 'italystrap_after_content' ); ?> - -
    - - -
    - -dispatch( 'italystrap_after_main' ); diff --git a/templates/main/canvas.php b/templates/main/canvas.php new file mode 100644 index 00000000..360dd972 --- /dev/null +++ b/templates/main/canvas.php @@ -0,0 +1,31 @@ +get(EventDispatcherInterface::class); + +?> +> + + + + + +get(MainCanvas::BODY_CLASS_NAMES, '')); ?>> + + +dispatch(new Canvas()); ?> + + + + diff --git a/templates/main/main.php b/templates/main/main.php new file mode 100644 index 00000000..7b554db9 --- /dev/null +++ b/templates/main/main.php @@ -0,0 +1,45 @@ +get(EventDispatcherInterface::class); + +$containerClassName = (string)$this->get('container_class_names'); +$rowClassName = (string)$this->get('row_class_names'); +?> +dispatch(new Header()); ?> + +
    + +
    + + dispatch(new ContentBefore()); ?> + + +
    + dispatch(new Content()); ?> +
    + + + dispatch(new ContentAfter()); ?> + +
    + +
    + + +dispatch(new Footer()); ?> + diff --git a/templates/misc/archive-headline.php b/templates/misc/archive-headline.php deleted file mode 100644 index cb3f2274..00000000 --- a/templates/misc/archive-headline.php +++ /dev/null @@ -1,34 +0,0 @@ - - - - \ No newline at end of file diff --git a/templates/misc/author-info.php b/templates/misc/author-info.php deleted file mode 100644 index 8f7360d9..00000000 --- a/templates/misc/author-info.php +++ /dev/null @@ -1,81 +0,0 @@ -get( 'author' ); - -/** - * Check if $author_info exist - */ -if ( ! $author_info ) { - return; -} - -?> -
    'author-info well', - 'itemprop' => 'author', - 'itemscope' => true, - 'itemtype' => 'https://schema.org/Person' - ] -); ?>> -
    -
    - avatar ) : - ?> - avatar autore - - get('ID'), - 94, // Size - null, // Default image URL - $author_info->get('nickname'), - [ 'class' => 'img-circle img-responsive center-block' ] - ); ?> - -
    -
    -

    nickname ); ?>

    - description ) { ?> -

    - description ) ); ?> -

    - - user_url ) { ?> - - -
    -
    -
    diff --git a/templates/misc/index.php b/templates/misc/index.php deleted file mode 100644 index b3d9bbc7..00000000 --- a/templates/misc/index.php +++ /dev/null @@ -1 +0,0 @@ - diff --git a/templates/navigation.php b/templates/navigation.php deleted file mode 100644 index 681c154c..00000000 --- a/templates/navigation.php +++ /dev/null @@ -1,41 +0,0 @@ -get(EventDispatcherInterface::class); - -$context = (string)$config->get(\ItalyStrap\Components\MainNavigation::CONTEXT); -?> - - - diff --git a/templates/navigation/header.php b/templates/navigation/header.php index 910869a0..d62474e0 100644 --- a/templates/navigation/header.php +++ b/templates/navigation/header.php @@ -1,16 +1,24 @@ get(GlobalDispatcherInterface::class); /** @var EventDispatcherInterface $dispatcher */ -$dispatcher = $config->get(EventDispatcherInterface::class); +$dispatcher = $this->get(EventDispatcherInterface::class); ?> diff --git a/templates/navigation/navbar-top.php b/templates/navigation/navbar-top.php new file mode 100644 index 00000000..7b8fb059 --- /dev/null +++ b/templates/navigation/navbar-top.php @@ -0,0 +1,48 @@ + diff --git a/templates/navigation/navbar.php b/templates/navigation/navbar.php new file mode 100644 index 00000000..55967054 --- /dev/null +++ b/templates/navigation/navbar.php @@ -0,0 +1,111 @@ +get(Navbar::class); + +/** @var NavMenuPrimary $nav_menu_primary */ +$nav_menu_primary = $config->get(NavMenuPrimary::class); + +/** @var NavMenuSecondary $nav_menu_secondary */ +$nav_menu_secondary = $config->get(NavMenuSecondary::class); + + +$number = \esc_attr($config->get('number', \rand())); +$navbar_id = 'italystrap-menu-' . $number; + + +open_tag_e('nav_container', 'div', [ + 'id' => 'main-navbar-container-' . $navbar_id, + 'class' => sprintf( + 'navbar-wrapper %s', + $config->get('mods.navbar.nav_width') + ), +]); + + open_tag_e('navbar_container', 'nav', [ + // 'class' => 'navbar navbar-expand-lg navbar-light bg-light', + 'class' => \sprintf( + 'navbar %s %s', + $config->get('mods.navbar.type'), + $config->get('mods.navbar.position') + ), + 'role' => 'navigation', + 'itemscope' => true, + 'itemtype' => 'https://schema.org/SiteNavigationElement', + ]); + + /** + * This was "'last_container'" + */ + open_tag_e('nav-inner-container', 'div', [ + 'id' => 'menus-container-' . $number, + 'class' => $config->get('mods.navbar.menus_width'), + ]); + + /** + * + * + * + */ + open_tag_e( + 'navbar_header', + 'div', + [ + 'class' => 'navbar-header', + 'itemprop' => 'publisher', + 'itemscope' => true, + 'itemtype' => 'https://schema.org/Organization', + ] + ); + + echo $navbar->get_navbar_brand(); + +/** + * = BS3 navbar-toggle + * >= BS4 navbar-toggler + */ + ?> + + $navbar_id, + 'class' => 'navbar-collapse collapse', + ]); + + $nav_menu_primary->display(); + $nav_menu_secondary->display(); + + close_tag_e('collapsable_menu'); + close_tag_e('nav-inner-container'); + close_tag_e('navbar_container'); + + close_tag_e('nav_container'); diff --git a/templates/navigation/navigation.php b/templates/navigation/navigation.php new file mode 100644 index 00000000..c1ced803 --- /dev/null +++ b/templates/navigation/navigation.php @@ -0,0 +1,42 @@ +get(EventDispatcherInterface::class); + +$context = (string)$config->get(\ItalyStrap\Navigation\UI\Components\MainNavigation::CONTEXT); +?> + + + diff --git a/templates/temp/pager.php b/templates/navigation/pager.php similarity index 99% rename from templates/temp/pager.php rename to templates/navigation/pager.php index 7de640f0..29a0e776 100644 --- a/templates/temp/pager.php +++ b/templates/navigation/pager.php @@ -1,4 +1,5 @@ diff --git a/templates/temp/pagination.php b/templates/navigation/pagination.php similarity index 63% rename from templates/temp/pagination.php rename to templates/navigation/pagination.php index f417a2c4..2751f902 100644 --- a/templates/temp/pagination.php +++ b/templates/navigation/pagination.php @@ -1,13 +1,14 @@
    - + - + - +
    diff --git a/templates/posts/entry-post.php b/templates/posts/entry-post.php deleted file mode 100644 index 004db7d3..00000000 --- a/templates/posts/entry-post.php +++ /dev/null @@ -1,32 +0,0 @@ -get(EventDispatcherInterface::class); - -/** @var int|null $id */ -$id = $this->get('id'); - -/** @var string $class_names */ -$class_names = $this->get('class_names'); -?> - $id, 'class' => $class_names ] ) ?>> -dispatch( 'italystrap_before_entry_content' ); - - $dispatcher->dispatch( 'italystrap_entry_content' ); - - $dispatcher->dispatch( 'italystrap_after_entry_content' ); -?> - diff --git a/templates/posts/index.php b/templates/posts/index.php deleted file mode 100644 index a5bcf147..00000000 --- a/templates/posts/index.php +++ /dev/null @@ -1,4 +0,0 @@ - -
    'no-results not-found'] ); ?>> - -
    diff --git a/templates/posts/none/content.php b/templates/posts/none/content.php deleted file mode 100644 index 376f640d..00000000 --- a/templates/posts/none/content.php +++ /dev/null @@ -1,48 +0,0 @@ - -
    -

    - Get started here.', 'italystrap' ), - [ - 'a' => [ - 'href' => [], - 'title' => [], - ] - ] - ); - \printf( - $message, - \esc_url( \admin_url( 'post-new.php' ) ) - ); - - ?> -

    - -

    -

    ' ); -else : - ?>

    get('content') ); ?>

    ' ); -endif; - -?> -
    diff --git a/templates/posts/none/index.php b/templates/posts/none/index.php deleted file mode 100644 index b3d9bbc7..00000000 --- a/templates/posts/none/index.php +++ /dev/null @@ -1 +0,0 @@ - - -
    -

    get('headlineAttributes') ); ?>> - get('content') ); ?> -

    -
    - diff --git a/templates/posts/not-found.php b/templates/posts/not-found.php new file mode 100644 index 00000000..74b7da3f --- /dev/null +++ b/templates/posts/not-found.php @@ -0,0 +1,21 @@ +get(EventDispatcherInterface::class); + +?> + +
    + dispatch(new PostsNotFoundContent()); ?> +
    + diff --git a/templates/posts/not-found/content.php b/templates/posts/not-found/content.php new file mode 100644 index 00000000..690a7b67 --- /dev/null +++ b/templates/posts/not-found/content.php @@ -0,0 +1,18 @@ + + +
    + +

    get(Content::CONTENT, '')); ?>

    + + get(Content::SEARCH, ''); ?> +
    + diff --git a/templates/posts/not-found/title.php b/templates/posts/not-found/title.php new file mode 100644 index 00000000..bb2cf165 --- /dev/null +++ b/templates/posts/not-found/title.php @@ -0,0 +1,18 @@ + + +
    + +

    get('content')); ?>

    + +
    + diff --git a/templates/posts/parts/content.php b/templates/posts/parts/content.php index df5c8346..104a52d3 100644 --- a/templates/posts/parts/content.php +++ b/templates/posts/parts/content.php @@ -1,24 +1,6 @@ 'entry-content wp-block-post-content' ] ); - -if ( \is_singular() ) { - \the_content(); -} else { - \the_excerpt(); -} +declare(strict_types=1); -close_tag_e( 'entry_content' ); +?> + \ No newline at end of file diff --git a/templates/temp/excerpt.php b/templates/posts/parts/excerpt.php similarity index 98% rename from templates/temp/excerpt.php rename to templates/posts/parts/excerpt.php index 9e273060..60453a71 100644 --- a/templates/temp/excerpt.php +++ b/templates/posts/parts/excerpt.php @@ -1,4 +1,5 @@ diff --git a/templates/posts/parts/featured-image.php b/templates/posts/parts/featured-image.php new file mode 100644 index 00000000..0f997e93 --- /dev/null +++ b/templates/posts/parts/featured-image.php @@ -0,0 +1,13 @@ + + diff --git a/templates/posts/parts/index.php b/templates/posts/parts/index.php deleted file mode 100644 index b3d9bbc7..00000000 --- a/templates/posts/parts/index.php +++ /dev/null @@ -1 +0,0 @@ - General Settings - * the_time( get_option('date_format') ); - * - *