api.adcommfr.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. /**
  3. * ADcomments basic fast reply implementation class
  4. */
  5. class ADcommFR {
  6. /**
  7. * Contains alter config as key=>value
  8. *
  9. * @var array
  10. */
  11. protected $altCfg = array();
  12. /**
  13. * Current instance administrator login
  14. *
  15. * @var string
  16. */
  17. protected $myLogin = '';
  18. /**
  19. * Contains fast replies array as idx=>replyText
  20. *
  21. * @var array
  22. */
  23. protected $fastRepliesList = array();
  24. /**
  25. * Contains available princess list logins as login=>login
  26. *
  27. * @var array
  28. */
  29. protected $princessList = array();
  30. public function __construct() {
  31. $this->loadAlter();
  32. $this->setmyLogin();
  33. $this->loadPrincessList();
  34. }
  35. /**
  36. * Loads system alter config into protected prop
  37. *
  38. * @global object $ubillingConfig
  39. *
  40. * @return void
  41. */
  42. protected function loadAlter() {
  43. global $ubillingConfig;
  44. $this->altCfg = $ubillingConfig->getAlter();
  45. }
  46. /**
  47. * Preloads princess list from config option
  48. *
  49. * @return void
  50. */
  51. protected function loadPrincessList() {
  52. if (isset($this->altCfg['PRINCESS_LIST'])) {
  53. if (!empty($this->altCfg['PRINCESS_LIST'])) {
  54. $princessRaw = explode(',', $this->altCfg['PRINCESS_LIST']);
  55. if (!empty($princessRaw)) {
  56. foreach ($princessRaw as $io => $eachPrincess) {
  57. $eachPrincess = trim($eachPrincess);
  58. $this->princessList[$eachPrincess] = $eachPrincess;
  59. }
  60. }
  61. }
  62. }
  63. }
  64. /**
  65. * Checks is me an princess or not?
  66. *
  67. * @return bool
  68. */
  69. public function iAmPrincess() {
  70. $result = false;
  71. if (isset($this->princessList[$this->myLogin])) {
  72. $result = true;
  73. }
  74. return ($result);
  75. }
  76. /**
  77. * Sets current administrator login into private prop
  78. *
  79. * @return void
  80. */
  81. protected function setmyLogin() {
  82. $this->myLogin = whoami();
  83. }
  84. /**
  85. * Sets available fast replies
  86. *
  87. * @param array $replyArr
  88. *
  89. * @return void
  90. */
  91. protected function setFastReplies($replyArr) {
  92. if (!empty($replyArr)) {
  93. $this->fastRepliesList = $replyArr;
  94. }
  95. }
  96. /**
  97. * Renders princess fast replies form
  98. *
  99. * @return string
  100. */
  101. public function renderPrincessFastReplies() {
  102. $result = '';
  103. $this->loadAlter();
  104. $this->loadPrincessList();
  105. if ($this->iAmPrincess()) {
  106. if (@$this->altCfg['PRINCESS_FAST_REPLIES']) {
  107. $replyArr = explode(',', $this->altCfg['PRINCESS_FAST_REPLIES']);
  108. $this->setFastReplies($replyArr);
  109. if (!empty($this->fastRepliesList)) {
  110. $result .= wf_tag('div', false, '', 'style="float: left; margin-left: 15px;"');
  111. foreach ($this->fastRepliesList as $io => $eachReply) {
  112. $btnLabel = wf_img('skins/icon_ok.gif') . ' ' . $eachReply;
  113. $btnStyle = 'style="width: 100%; text-align: left;"';
  114. $inputs = wf_SubmitClassed($eachReply, 'frButton', ADcomments::PROUTE_NEW_TEXT, $btnLabel, '', $btnStyle);
  115. $result .= wf_Form('', 'POST', $inputs, '');
  116. $result .= wf_delimiter(0);
  117. }
  118. $result .= wf_tag('div', true);
  119. }
  120. }
  121. }
  122. return ($result);
  123. }
  124. }