init.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. class NSFW extends Plugin {
  3. private $link;
  4. private $host;
  5. function about() {
  6. return array(1.0,
  7. "Hide article content based on tags",
  8. "fox",
  9. false);
  10. }
  11. function init($host) {
  12. $this->link = $host->get_link();
  13. $this->host = $host;
  14. $host->add_hook($host::HOOK_RENDER_ARTICLE, $this);
  15. $host->add_hook($host::HOOK_RENDER_ARTICLE_CDM, $this);
  16. $host->add_hook($host::HOOK_PREFS_TAB, $this);
  17. }
  18. function get_js() {
  19. return file_get_contents(dirname(__FILE__) . "/init.js");
  20. }
  21. function hook_render_article($article) {
  22. $tags = array_map("trim", explode(", ", $this->host->get($this, "tags")));
  23. if (count(array_intersect($tags, $article["tags"])) > 0) {
  24. $article["content"] = "<div class='nswf wrapper'><button onclick=\"nsfwShow(this)\">".__("Not work safe (click to toggle)")."</button>
  25. <div class='nswf content' style='display : none'>".$article["content"]."</div></div>";
  26. }
  27. return $article;
  28. }
  29. function hook_render_article_cdm($article) {
  30. $tags = array_map("trim", explode(", ", $this->host->get($this, "tags")));
  31. if (count(array_intersect($tags, $article["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 "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pluginhandler\">";
  56. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"save\">";
  57. print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"plugin\" value=\"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(",", db_escape_string($this->link, $_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. }
  76. ?>