chat.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. // PLUGIN INFORMATION
  3. $GLOBALS['plugins'][]['chat'] = array( // Plugin Name
  4. 'name' => 'Chat', // Plugin Name
  5. 'author' => 'CauseFX', // Who wrote the plugin
  6. 'category' => 'Utilities', // One to Two Word Description
  7. 'link' => '', // Link to plugin info
  8. 'license' => 'personal,business', // License Type use , for multiple
  9. 'idPrefix' => 'CHAT', // html element id prefix
  10. 'configPrefix' => 'CHAT', // config file prefix for array items without the hypen
  11. 'version' => '1.0.0', // SemVer of plugin
  12. 'image' => 'plugins/images/chat.png', // 1:1 non transparent image for plugin
  13. 'settings' => true, // does plugin need a settings page? true or false
  14. 'homepage' => false // Is plugin for use on homepage? true or false
  15. );
  16. class Chat extends Organizr
  17. {
  18. public function _chatPluginGetSettings()
  19. {
  20. return array(
  21. 'custom' => '
  22. <div class="row">
  23. <div class="col-lg-12">
  24. <div class="panel panel-info">
  25. <div class="panel-heading">
  26. <span lang="en">Notice</span>
  27. </div>
  28. <div class="panel-wrapper collapse in" aria-expanded="true">
  29. <div class="panel-body">
  30. <ul class="list-icons">
  31. <li><i class="fa fa-chevron-right text-danger"></i> <a href="https://dashboard.pusher.com/accounts/sign_up" target="_blank">Signup for Pusher [FREE]</a></li>
  32. <li><i class="fa fa-chevron-right text-danger"></i> Create an App called whatever you like and choose a cluster (Close to you)</li>
  33. <li><i class="fa fa-chevron-right text-danger"></i> Frontend (JQuery) - Backend (PHP)</li>
  34. <li><i class="fa fa-chevron-right text-danger"></i> Click the overview tab on top left</li>
  35. <li><i class="fa fa-chevron-right text-danger"></i> Copy and paste the 4 values into Organizr</li>
  36. <li><i class="fa fa-chevron-right text-danger"></i> Save and reload!</li>
  37. </ul>
  38. </div>
  39. </div>
  40. </div>
  41. </div>
  42. </div>
  43. ',
  44. 'Options' => array(
  45. array(
  46. 'type' => 'select',
  47. 'name' => 'CHAT-Auth-include',
  48. 'label' => 'Minimum Authentication',
  49. 'value' => $this->config['CHAT-Auth-include'],
  50. 'options' => $this->groupSelect()
  51. ),
  52. array(
  53. 'type' => 'number',
  54. 'name' => 'CHAT-messageLoadLimit',
  55. 'label' => '# of Previous Messages',
  56. 'value' => $this->config['CHAT-messageLoadLimit'],
  57. 'placeholder' => ''
  58. ),
  59. array(
  60. 'type' => 'select',
  61. 'name' => 'CHAT-userRefreshTimeout',
  62. 'label' => 'Refresh Seconds',
  63. 'value' => $this->config['CHAT-userRefreshTimeout'],
  64. 'options' => $this->optionTime()
  65. ),
  66. array(
  67. 'type' => 'select',
  68. 'name' => 'CHAT-newMessageSound-include',
  69. 'label' => 'Message Sound',
  70. 'value' => $this->config['CHAT-newMessageSound-include'],
  71. 'options' => $this->getSounds()
  72. ),
  73. array(
  74. 'type' => 'switch',
  75. 'name' => 'CHAT-useSSL',
  76. 'label' => 'Use Pusher SSL',
  77. 'help' => 'If messages get stuck sending, please turn this option off.',
  78. 'value' => $this->config['CHAT-useSSL']
  79. )
  80. ),
  81. 'Connection' => array(
  82. array(
  83. 'type' => 'password-alt',
  84. 'name' => 'CHAT-authKey-include',
  85. 'label' => 'Auth Key',
  86. 'value' => $this->config['CHAT-authKey-include']
  87. ),
  88. array(
  89. 'type' => 'password-alt',
  90. 'name' => 'CHAT-secret',
  91. 'label' => 'API Secret',
  92. 'value' => $this->config['CHAT-secret']
  93. ),
  94. array(
  95. 'type' => 'input',
  96. 'name' => 'CHAT-appID-include',
  97. 'label' => 'App ID',
  98. 'value' => $this->config['CHAT-appID-include']
  99. ),
  100. array(
  101. 'type' => 'input',
  102. 'name' => 'CHAT-cluster-include',
  103. 'label' => 'App Cluster',
  104. 'value' => $this->config['CHAT-cluster-include']
  105. ),
  106. )
  107. );
  108. }
  109. public function _chatPluginSendChatMessage($array)
  110. {
  111. $message = isset($array['message']) ? $array['message'] : null;
  112. if (!$message) {
  113. $this->setAPIResponse('error', 'No message supplied', 409);
  114. return false;
  115. }
  116. $message = htmlspecialchars($message, ENT_QUOTES);
  117. $now = date("Y-m-d H:i:s");
  118. $currentIP = $this->userIP();
  119. $newMessage = [
  120. 'username' => $this->user['username'],
  121. 'gravatar' => $this->user['image'],
  122. 'uid' => $this->user['uid'],
  123. 'date' => $now,
  124. 'ip' => $currentIP,
  125. 'message' => $message
  126. ];
  127. $response = [
  128. array(
  129. 'function' => 'query',
  130. 'query' => array(
  131. 'INSERT INTO [chatroom]',
  132. $newMessage
  133. )
  134. ),
  135. ];
  136. $query = $this->processQueries($response);
  137. if ($query) {
  138. $options = array(
  139. 'cluster' => $GLOBALS['CHAT-cluster-include'],
  140. 'useTLS' => $GLOBALS['CHAT-useSSL']
  141. );
  142. $pusher = new Pusher\Pusher(
  143. $GLOBALS['CHAT-authKey-include'],
  144. $GLOBALS['CHAT-secret'],
  145. $GLOBALS['CHAT-appID-include'],
  146. $options
  147. );
  148. $pusher->trigger('org_channel', 'my-event', $newMessage);
  149. $this->setAPIResponse('success', 'Chat message accepted', 200);
  150. return true;
  151. }
  152. $this->setAPIResponse('error', 'Chat error occurred', 409);
  153. return false;
  154. }
  155. public function _chatPluginGetChatMessages()
  156. {
  157. $response = [
  158. array(
  159. 'function' => 'fetchAll',
  160. 'query' => array(
  161. 'SELECT `username`, `gravatar`, `uid`, `date`, `message` FROM chatroom LIMIT ' . $this->config['CHAT-messageLoadLimit']
  162. )
  163. ),
  164. ];
  165. return $this->processQueries($response);
  166. }
  167. }