init.php 855 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. class Af_Lang_Detect extends Plugin {
  3. private $host;
  4. private $lang;
  5. function about() {
  6. return array(1.0,
  7. "Detect article language",
  8. "fox");
  9. }
  10. function init($host) {
  11. $this->host = $host;
  12. $host->add_hook($host::HOOK_ARTICLE_FILTER, $this);
  13. require_once __DIR__ . "/languagedetect/LanguageDetect.php";
  14. $this->lang = new Text_LanguageDetect();
  15. $this->lang->setNameMode(2);
  16. }
  17. function hook_article_filter($article) {
  18. if ($this->lang) {
  19. $entry_language = $this->lang->detect($article['title'] . " " . $article['content'], 1);
  20. if (count($entry_language) > 0) {
  21. $possible = array_keys($entry_language);
  22. $entry_language = $possible[0];
  23. _debug("detected language: $entry_language");
  24. $article["language"] = $entry_language;
  25. }
  26. }
  27. return $article;
  28. }
  29. function api_version() {
  30. return 2;
  31. }
  32. }