2015-01-04 21:46:33 +01:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* Name: Typography
|
|
|
|
* Description: Applies typographical enhancements to the postings before displaying them
|
2019-12-30 08:04:23 +01:00
|
|
|
* Version: 0.3
|
2018-07-09 18:29:35 +02:00
|
|
|
* Author: Tobias Diekershoff <tobias@social.diekershoff.de>
|
2015-01-04 21:46:33 +01:00
|
|
|
* License: GPL 2.0
|
|
|
|
*/
|
|
|
|
|
2019-12-30 07:44:28 +01:00
|
|
|
use Friendica\DI;
|
2017-11-06 10:46:39 +01:00
|
|
|
use Friendica\Core\PConfig;
|
2018-01-21 08:14:19 +01:00
|
|
|
use Friendica\Core\Addon;
|
2017-11-06 10:46:39 +01:00
|
|
|
|
2015-01-04 21:46:33 +01:00
|
|
|
function typography_install () {
|
2018-01-21 08:14:19 +01:00
|
|
|
Addon::registerHook ('prepare_body', 'addon/typography/typography.php', 'typography_render' );
|
2015-01-04 21:46:33 +01:00
|
|
|
}
|
|
|
|
function typography_uninstall () {
|
2018-01-21 08:14:19 +01:00
|
|
|
Addon::unregisterHook ('prepare_body', 'addon/typography/typography.php', 'typography_render' );
|
2015-01-04 21:46:33 +01:00
|
|
|
}
|
|
|
|
function typography_render ( &$a, &$o) {
|
|
|
|
require_once('php-typography/php-typography.php');
|
|
|
|
$typo = new phpTypography();
|
|
|
|
$lng_id = array(
|
|
|
|
'hu',
|
|
|
|
'is',
|
|
|
|
'tr',
|
|
|
|
'bg',
|
|
|
|
'cs',
|
|
|
|
'fi',
|
|
|
|
'fr',
|
|
|
|
'it',
|
|
|
|
'ro',
|
|
|
|
'es',
|
|
|
|
'pt',
|
|
|
|
'no',
|
|
|
|
'ru',
|
|
|
|
'sv',
|
|
|
|
'pl',
|
2018-07-09 18:29:35 +02:00
|
|
|
'en',
|
|
|
|
'en-US',
|
2015-02-24 19:10:06 +01:00
|
|
|
'en-GB',
|
2015-01-04 21:46:33 +01:00
|
|
|
'de');
|
|
|
|
$lng_long = array(
|
|
|
|
'hungarian',
|
|
|
|
'icelandic',
|
|
|
|
'turkish',
|
|
|
|
'bulgarian',
|
|
|
|
'czech',
|
|
|
|
'finnish',
|
|
|
|
'french',
|
|
|
|
'italian',
|
|
|
|
'romanian',
|
|
|
|
'spanish',
|
|
|
|
'portuguese',
|
|
|
|
'norwegian',
|
|
|
|
'russian',
|
|
|
|
'swedish',
|
|
|
|
'polish',
|
|
|
|
'english',
|
2018-07-09 18:29:35 +02:00
|
|
|
'english',
|
|
|
|
'english',
|
2015-01-04 21:46:33 +01:00
|
|
|
'german');
|
|
|
|
$l = new Text_LanguageDetect;
|
|
|
|
$lng = $l->detectSimple($o['html']);
|
|
|
|
$lng = str_replace( $lng_long, $lng_id, $lng);
|
2018-01-29 08:46:37 +01:00
|
|
|
$typo->set_smart_quotes_language($lng);
|
|
|
|
$typo->set_diacritic_language($lng);
|
|
|
|
$typo->set_hyphenation_language($lng);
|
2015-01-04 21:46:33 +01:00
|
|
|
$o['html'] = $typo->process($o['html']);
|
2019-12-30 07:44:28 +01:00
|
|
|
$a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . DI::baseUrl()->get() . '/addon/typography/style.css' . '" media="all" />';
|
2015-01-04 21:46:33 +01:00
|
|
|
unset($l);
|
|
|
|
}
|