templates_standard_commands.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright (C) 2000,2001 Florian Sander
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. static void template_add_subcontent(struct template_content *content,
  19. struct llist_2string *params,
  20. char *included_text)
  21. {
  22. Assert(!content->subcontent);
  23. if (included_text)
  24. content->subcontent = templates_content_parse(included_text);
  25. }
  26. /* template_send_module_version():
  27. * sends the module version (surprise!)
  28. */
  29. static void template_send_module_version(int idx, struct template_content *tpc)
  30. {
  31. dprintf(idx, "%s", MODULE_VERSION);
  32. }
  33. /* <?slang #?>
  34. * outputs a line from the slangfile
  35. */
  36. static void template_send_slang(int idx, struct template_content *tpc)
  37. {
  38. dprintf(idx, "%s", getslang(tpc->intpar1));
  39. }
  40. static void template_add_cmd_slang(struct template_content *content,
  41. struct llist_2string *params,
  42. char *included_text)
  43. {
  44. for (; params; params = params->next)
  45. if (!strcasecmp(params->s1, "id"))
  46. content->intpar1 = atoi(params->s2);
  47. }
  48. static void template_add_cmd_template(struct template_content *content,
  49. struct llist_2string *params,
  50. char *included_text)
  51. {
  52. for (; params; params = params->next) {
  53. if (!strcasecmp(params->s1, "name")) {
  54. content->charpar1 = nmalloc(strlen(params->s2) + 1);
  55. strcpy(content->charpar1, params->s2);
  56. return;
  57. }
  58. }
  59. putlog(LOG_MISC, "*", "ERROR: missing parameter for template tag!");
  60. }
  61. static void template_send_template(int idx, struct template_content *tpc)
  62. {
  63. if (tpc->charpar1)
  64. template_send(glob_skin, tpc->charpar1, idx);
  65. }
  66. static void template_send_form_method(int idx, struct template_content *tpc)
  67. {
  68. if (get_param_value(idx, "dontpost"))
  69. dprintf(idx, "GET");
  70. else
  71. dprintf(idx, "POST");
  72. }
  73. static void template_send_if_dontpost(int idx, struct template_content *tpc)
  74. {
  75. if (get_param_value(idx, "dontpost"))
  76. templates_content_send(tpc->subcontent, idx);
  77. }
  78. static void template_send_botnick(int idx, struct template_content *tpc)
  79. {
  80. dprintf(idx, "%s", botname);
  81. }
  82. struct template_commands templates_standard_commands[] =
  83. {
  84. {"module_version", template_send_module_version, NULL},
  85. {"slang", template_send_slang, template_add_cmd_slang},
  86. {"template", template_send_template, template_add_cmd_template},
  87. {"form_method", template_send_form_method, NULL},
  88. {"if_dontpost", template_send_if_dontpost, template_add_subcontent},
  89. {"botnick", template_send_botnick, NULL},
  90. {0, 0, 0},
  91. };