typography/typography.php

72 lines
1.6 KiB
PHP

<?php
/*
* Name: Typography
* Description: Applies typographical enhancements to the postings before displaying them
* Version: 0.2
* Author: Tobias Diekershoff <tobias@social.diekershoff.de>
* License: GPL 2.0
*/
use Friendica\Core\PConfig;
use Friendica\Core\Addon;
function typography_install () {
Addon::registerHook ('prepare_body', 'addon/typography/typography.php', 'typography_render' );
}
function typography_uninstall () {
Addon::unregisterHook ('prepare_body', 'addon/typography/typography.php', 'typography_render' );
}
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',
'en',
'en-US',
'en-GB',
'de');
$lng_long = array(
'hungarian',
'icelandic',
'turkish',
'bulgarian',
'czech',
'finnish',
'french',
'italian',
'romanian',
'spanish',
'portuguese',
'norwegian',
'russian',
'swedish',
'polish',
'english',
'english',
'english',
'german');
$l = new Text_LanguageDetect;
$lng = $l->detectSimple($o['html']);
$lng = str_replace( $lng_long, $lng_id, $lng);
$typo->set_smart_quotes_language($lng);
$typo->set_diacritic_language($lng);
$typo->set_hyphenation_language($lng);
$o['html'] = $typo->process($o['html']);
$a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/typography/style.css' . '" media="all" />';
unset($l);
}