init.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. class NSFW extends Plugin {
  3. private $host;
  4. function about() {
  5. return array(1.0,
  6. "Hide article content based on tags",
  7. "fox",
  8. false);
  9. }
  10. function init($host) {
  11. $this->host = $host;
  12. $host->add_hook($host::HOOK_RENDER_ARTICLE, $this);
  13. $host->add_hook($host::HOOK_RENDER_ARTICLE_CDM, $this);
  14. $host->add_hook($host::HOOK_PREFS_TAB, $this);
  15. }
  16. function get_js() {
  17. return file_get_contents(dirname(__FILE__) . "/init.js");
  18. }
  19. function hook_render_article($article) {
  20. $tags = array_map("trim", explode(",", $this->host->get($this, "tags")));
  21. $a_tags = array_map("trim", explode(",", $article["tag_cache"]));
  22. if (count(array_intersect($tags, $a_tags)) > 0) {
  23. $article["content"] = "<div class='nswf wrapper'><button onclick=\"nsfwShow(this)\">".__("Not work safe (click to toggle)")."</button>
  24. <div class='nswf content' style='display : none'>".$article["content"]."</div></div>";
  25. }
  26. return $article;
  27. }
  28. function hook_render_article_cdm($article) {
  29. $tags = array_map("trim", explode(",", $this->host->get($this, "tags")));
  30. $a_tags = array_map("trim", explode(",", $article["tag_cache"]));
  31. if (count(array_intersect($tags, $a_tags)) > 0) {
  32. $article["content"] = "<div class='nswf wrapper'><button onclick=\"nsfwShow(this)\">".__("Not work safe (click to toggle)")."</button>
  33. <div class='nswf content' style='display : none'>".$article["content"]."</div></div>";
  34. }
  35. return $article;
  36. }
  37. function hook_prefs_tab($args) {
  38. if ($args != "prefPrefs") return;
  39. print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__("NSFW Plugin")."\">";
  40. print "<br/>";
  41. $tags = $this->host->get($this, "tags");
  42. print "<form dojoType=\"dijit.form.Form\">";
  43. print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
  44. evt.preventDefault();
  45. if (this.validate()) {
  46. new Ajax.Request('backend.php', {
  47. parameters: dojo.objectToQuery(this.getValues()),
  48. onComplete: function(transport) {
  49. Notify.info(transport.responseText);
  50. }
  51. });
  52. //this.reset();
  53. }
  54. </script>";
  55. print_hidden("op", "pluginhandler");
  56. print_hidden("method", "save");
  57. print_hidden("plugin", "nsfw");
  58. print "<table width=\"100%\" class=\"prefPrefsList\">";
  59. print "<tr><td width=\"40%\">".__("Tags to consider NSFW (comma-separated)")."</td>";
  60. print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" name=\"tags\" value=\"$tags\"></td></tr>";
  61. print "</table>";
  62. print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">".
  63. __("Save")."</button>";
  64. print "</form>";
  65. print "</div>"; #pane
  66. }
  67. function save() {
  68. $tags = explode(",", $_POST["tags"]);
  69. $tags = array_map("trim", $tags);
  70. $tags = array_map("mb_strtolower", $tags);
  71. $tags = join(", ", $tags);
  72. $this->host->set($this, "tags", $tags);
  73. echo __("Configuration saved.");
  74. }
  75. function api_version() {
  76. return 2;
  77. }
  78. }