Friendica addon for a more typographically correct rendering of the postings depending on the used language in the posting.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.6 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. <?php
  2. /*
  3. * Name: Typography
  4. * Description: Applies typographical enhancements to the postings before displaying them
  5. * Version: 0.2
  6. * Author: Tobias Diekershoff <tobias@social.diekershoff.de>
  7. * License: GPL 2.0
  8. */
  9. use Friendica\Core\PConfig;
  10. use Friendica\Core\Addon;
  11. function typography_install () {
  12. Addon::registerHook ('prepare_body', 'addon/typography/typography.php', 'typography_render' );
  13. }
  14. function typography_uninstall () {
  15. Addon::unregisterHook ('prepare_body', 'addon/typography/typography.php', 'typography_render' );
  16. }
  17. function typography_render ( &$a, &$o) {
  18. require_once('php-typography/php-typography.php');
  19. $typo = new phpTypography();
  20. $lng_id = array(
  21. 'hu',
  22. 'is',
  23. 'tr',
  24. 'bg',
  25. 'cs',
  26. 'fi',
  27. 'fr',
  28. 'it',
  29. 'ro',
  30. 'es',
  31. 'pt',
  32. 'no',
  33. 'ru',
  34. 'sv',
  35. 'pl',
  36. 'en',
  37. 'en-US',
  38. 'en-GB',
  39. 'de');
  40. $lng_long = array(
  41. 'hungarian',
  42. 'icelandic',
  43. 'turkish',
  44. 'bulgarian',
  45. 'czech',
  46. 'finnish',
  47. 'french',
  48. 'italian',
  49. 'romanian',
  50. 'spanish',
  51. 'portuguese',
  52. 'norwegian',
  53. 'russian',
  54. 'swedish',
  55. 'polish',
  56. 'english',
  57. 'english',
  58. 'english',
  59. 'german');
  60. $l = new Text_LanguageDetect;
  61. $lng = $l->detectSimple($o['html']);
  62. $lng = str_replace( $lng_long, $lng_id, $lng);
  63. $typo->set_smart_quotes_language($lng);
  64. $typo->set_diacritic_language($lng);
  65. $typo->set_hyphenation_language($lng);
  66. $o['html'] = $typo->process($o['html']);
  67. $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->getBaseurl() . '/addon/typography/style.css' . '" media="all" />';
  68. unset($l);
  69. }