Subscribe.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. namespace dokuwiki\Ui;
  3. use dokuwiki\Form\Form;
  4. /**
  5. * DokuWiki Subscribe Interface
  6. *
  7. * @package dokuwiki\Ui
  8. */
  9. class Subscribe extends Ui
  10. {
  11. /**
  12. * Display the subscribe form
  13. *
  14. * @author Adrian Lang <lang@cosmocode.de>
  15. *
  16. * @return void
  17. */
  18. public function show()
  19. {
  20. global $INPUT;
  21. global $INFO;
  22. global $ID;
  23. global $lang;
  24. global $conf;
  25. $stime_days = $conf['subscribe_time'] / 60 / 60 / 24;
  26. // print intro
  27. echo p_locale_xhtml('subscr_form');
  28. // list up current subscriptions
  29. echo '<h2>'.$lang['subscr_m_current_header'].'</h2>';
  30. echo '<div class="level2">';
  31. if ($INFO['subscribed'] === false) {
  32. echo '<p>'.$lang['subscr_m_not_subscribed'].'</p>';
  33. } else {
  34. echo '<ul>';
  35. foreach ($INFO['subscribed'] as $sub) {
  36. echo '<li><div class="li">';
  37. if ($sub['target'] !== $ID) {
  38. echo '<code class="ns">'.hsc(prettyprint_id($sub['target'])).'</code>';
  39. } else {
  40. echo '<code class="page">'.hsc(prettyprint_id($sub['target'])).'</code>';
  41. }
  42. $sstl = sprintf($lang['subscr_style_'.$sub['style']], $stime_days);
  43. if (!$sstl) $sstl = hsc($sub['style']);
  44. echo ' ('.$sstl.') ';
  45. echo '<a href="'.wl(
  46. $ID,
  47. array(
  48. 'do' => 'subscribe',
  49. 'sub_target'=> $sub['target'],
  50. 'sub_style' => $sub['style'],
  51. 'sub_action'=> 'unsubscribe',
  52. 'sectok' => getSecurityToken()
  53. )
  54. ).
  55. '" class="unsubscribe">'.$lang['subscr_m_unsubscribe'].
  56. '</a></div></li>';
  57. }
  58. echo '</ul>';
  59. }
  60. echo '</div>';
  61. // Add new subscription form
  62. echo '<h2>'.$lang['subscr_m_new_header'].'</h2>';
  63. echo '<div class="level2">';
  64. $ns = getNS($ID).':';
  65. $targets = [
  66. $ID => '<code class="page">'.prettyprint_id($ID).'</code>',
  67. $ns => '<code class="ns">'.prettyprint_id($ns).'</code>',
  68. ];
  69. $styles = [
  70. 'every' => $lang['subscr_style_every'],
  71. 'digest' => sprintf($lang['subscr_style_digest'], $stime_days),
  72. 'list' => sprintf($lang['subscr_style_list'], $stime_days),
  73. ];
  74. // create the form
  75. $form = new Form(['id' => 'subscribe__form']);
  76. $form->addTagOpen('div')->addClass('no');
  77. $form->setHiddenField('id', $ID);
  78. $form->setHiddenField('do', 'subscribe');
  79. $form->setHiddenField('sub_action', 'subscribe');
  80. $form->addFieldsetOpen($lang['subscr_m_subscribe']);
  81. $value = (array_key_exists($INPUT->post->str('sub_target'), $targets)) ?
  82. $INPUT->str('sub_target') : key($targets);
  83. foreach ($targets as $val => $label) {
  84. $data = ($value === $val) ? ['checked' => 'checked'] : [];
  85. $form->addRadioButton('sub_target', $label)->val($val)->attrs($data);
  86. }
  87. $form->addFieldsetClose();
  88. $form->addFieldsetOpen($lang['subscr_m_receive']);
  89. $value = (array_key_exists($INPUT->post->str('sub_style'), $styles)) ?
  90. $INPUT->str('sub_style') : key($styles);
  91. foreach ($styles as $val => $label) {
  92. $data = ($value === $val) ? ['checked' => 'checked'] : [];
  93. $form->addRadioButton('sub_style', $label)->val($val)->attrs($data);
  94. }
  95. $form->addFieldsetClose();
  96. $form->addButton('do[subscribe]', $lang['subscr_m_subscribe'])->attr('type', 'submit');
  97. $form->addTagClose('div');
  98. print $form->toHTML('Subscribe');
  99. echo '</div>';
  100. }
  101. }