Skip to content
This repository has been archived by the owner on Oct 2, 2019. It is now read-only.

Kirby 3 #24

Open
tristantbg opened this issue Nov 13, 2018 · 7 comments
Open

Kirby 3 #24

tristantbg opened this issue Nov 13, 2018 · 7 comments

Comments

@tristantbg
Copy link

Do you plan to make a K3 version of this great plugin ? :)

@fabianmichael
Copy link
Owner

Yesss! But unfortunately, I dod not find the time for working on that so far. The PHP Typography library also made some great progress since the last release of Kirby-Typography, so a new release would be overdue anyway.

@nilshoerrmann
Copy link

@fabianmichael, what's the status of this plugin?
Are there still plans for a Kirby 3 compatible version?

@fabianmichael
Copy link
Owner

@nilshoerrmann I am currently drowing in work and don’t know, when I can continue working on this plugin. I had big plans in the first place, like a panel view for customizing the plugin. As PHP Typography comes with a myriad of options, I always found it much nicer the way you can edit its settings in WordPress. But I will probably have to stick to the old way of configuring the plugin, even with a revamped version for Kirby 3.

In the meantime, I also found out the the most-used feature in my projects is hyphenation. I got a working prototype for a hyphenation plugin, please let me know if you are interested in that instead.

@nilshoerrmann
Copy link

Thanks for the offer. We are mostly interested in quote, apostrophe and dash handling – hyphenation has not been that important for us so far :)

@tristantbg
Copy link
Author

@nilshoerrmann
In the meantime, I also found out the the most-used feature in my projects is hyphenation. I got a working prototype for a hyphenation plugin, please let me know if you are interested in that instead.

Hi @fabianmichael, if you could share with us the hyphenation plugin it would be much appreciated !
This is also what I used the most.

@fabianmichael
Copy link
Owner

@tristantbg I’ll try my best. Could take a few days though, as I have to investigate how to store settings for multilanguage-environments.

@nilshoerrmann
Copy link

nilshoerrmann commented Jun 5, 2019

I started a little experiment yesterday, if I can get the latest version of PHP Typography running in Kirby 3 and created a simple plugin that takes an array of settings per language and applies them in a field method called typography, e. g. $field->typography().

@fabianmichael: We never used Kirby 2 and thus we never used your plugin. We don't know how it works internally but our custom plugin does what we need for our projects. Now we don't want to get into your way and don't know how to proceed: we can just keep our plugin private, we can provide you with our plugin code, we can release it as a new plugin for K3. What do you think?

This is was the plugin does:

<?php

@include_once __DIR__ . '/vendor/autoload.php';

Kirby::plugin('hananils/typography', [
    'options' => [
        'settings' => [
            '*' => [
                'style_ampersands' => false,
                'style_caps' => false,
                'style_initial_quotes' => false,
                'style_numbers' => false,
                'style_hanging_punctuation' => false,
                'initial_quote_tags' => false
            ],
            'de' => [
                'smart_quotes_primary' => 'doubleLow9Reversed',
                'smart_quotes_secondary' => 'singleLow9Reversed',
                'smart_dashes_style' => 'international',
                'hyphenation_language' => 'de_DE',
                'diacritic_language' => 'de_DE'
            ],
            'fr' => [
                'smart_quotes_primary' => 'doubleGuillemetsFrench',
                'smart_quotes_secondary' => 'doubleCurled',
                'hyphenation_language' => 'fr_FR',
                'diacritic_language' => 'fr_FR'
            ]
        ]
    ],
    'fieldMethods' => [
        'typography' => function ($field) {
            $settings = new \PHP_Typography\Settings(true);
            $rules = kirby()->option('hananils.typography.settings');
            $language = kirby()->language()->code();

            // Get global settings
            $global = [];
            if (isset($rules['*']) && is_array($rules['*'])) {
                $global = $rules['*'];
            }

            // Get local settings
            $local = [];
            if (!empty($language) && isset($rules[$language]) && is_array($rules[$language])) {
                $local = $rules[$language];
            }

            // Apply settings
            $rules = array_merge($global, $local);
            foreach ($rules as $key => $value) {
                $setting = 'set_' . $key;
                if (method_exists($settings, $setting)) {
                    $settings->$setting($value);
                }
            }

            // Apply typographic styles
            $typographer = new \PHP_Typography\PHP_Typography();
            $field->value = $typographer->process($field->toString(), $settings);

            // Return field for chaning
            return $field;
        }
    ]
]);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants