chat.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. //'fileName'=>'php-mailer.php',
  10. //'configFile'=>'php-mailer.php',
  11. //'apiFile'=>'php-mailer.php',
  12. 'idPrefix' => 'CHAT', // html element id prefix
  13. 'configPrefix' => 'CHAT', // config file prefix for array items without the hypen
  14. 'version' => '1.0.0', // SemVer of plugin
  15. 'image' => 'plugins/images/chat.png', // 1:1 non transparent image for plugin
  16. 'settings' => true, // does plugin need a settings page? true or false
  17. 'homepage' => false // Is plugin for use on homepage? true or false
  18. );
  19. // INCLUDE/REQUIRE FILES
  20. // PLUGIN FUNCTIONS
  21. /* GET CHAT SETTINGS */
  22. function chatGetSettings()
  23. {
  24. return array(
  25. 'custom' => '
  26. <div class="row">
  27. <div class="col-lg-12">
  28. <div class="panel panel-info">
  29. <div class="panel-heading">
  30. <span lang="en">Notice</span>
  31. </div>
  32. <div class="panel-wrapper collapse in" aria-expanded="true">
  33. <div class="panel-body">
  34. <ul class="list-icons">
  35. <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>
  36. <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>
  37. <li><i class="fa fa-chevron-right text-danger"></i> Frontend (JQuery) - Backend (PHP)</li>
  38. <li><i class="fa fa-chevron-right text-danger"></i> Click the overview tab on top left</li>
  39. <li><i class="fa fa-chevron-right text-danger"></i> Copy and paste the 4 values into Organizr</li>
  40. <li><i class="fa fa-chevron-right text-danger"></i> Save and reload!</li>
  41. </ul>
  42. </div>
  43. </div>
  44. </div>
  45. </div>
  46. </div>
  47. ',
  48. 'Options' => array(
  49. array(
  50. 'type' => 'select',
  51. 'name' => 'CHAT-Auth-include',
  52. 'label' => 'Minimum Authentication',
  53. 'value' => $GLOBALS['CHAT-Auth-include'],
  54. 'options' => groupSelect()
  55. ),
  56. array(
  57. 'type' => 'number',
  58. 'name' => 'CHAT-messageLoadLimit',
  59. 'label' => '# of Previous Messages',
  60. 'value' => $GLOBALS['CHAT-messageLoadLimit'],
  61. 'placeholder' => ''
  62. ),
  63. array(
  64. 'type' => 'select',
  65. 'name' => 'CHAT-userRefreshTimeout',
  66. 'label' => 'Refresh Seconds',
  67. 'value' => $GLOBALS['CHAT-userRefreshTimeout'],
  68. 'options' => optionTime()
  69. ),
  70. array(
  71. 'type' => 'select',
  72. 'name' => 'CHAT-newMessageSound-include',
  73. 'label' => 'Message Sound',
  74. 'value' => $GLOBALS['CHAT-newMessageSound-include'],
  75. 'options' => getSounds()
  76. ),
  77. array(
  78. 'type' => 'switch',
  79. 'name' => 'CHAT-useSSL',
  80. 'label' => 'Use Pusher SSL',
  81. 'help' => 'If messages get stuck sending, please turn this option off.',
  82. 'value' => $GLOBALS['CHAT-useSSL']
  83. )
  84. ),
  85. 'Connection' => array(
  86. array(
  87. 'type' => 'password-alt',
  88. 'name' => 'CHAT-authKey-include',
  89. 'label' => 'Auth Key',
  90. 'value' => $GLOBALS['CHAT-authKey-include']
  91. ),
  92. array(
  93. 'type' => 'password-alt',
  94. 'name' => 'CHAT-secret',
  95. 'label' => 'API Secret',
  96. 'value' => $GLOBALS['CHAT-secret']
  97. ),
  98. array(
  99. 'type' => 'input',
  100. 'name' => 'CHAT-appID-include',
  101. 'label' => 'App ID',
  102. 'value' => $GLOBALS['CHAT-appID-include']
  103. ),
  104. array(
  105. 'type' => 'input',
  106. 'name' => 'CHAT-cluster-include',
  107. 'label' => 'App Cluster',
  108. 'value' => $GLOBALS['CHAT-cluster-include']
  109. ),
  110. )
  111. );
  112. }
  113. function sendChatMessage($array)
  114. {
  115. $message = isset($array['data']['message']) ? $array['data']['message'] : null;
  116. $message = htmlspecialchars($message, ENT_QUOTES);
  117. $now = date("Y-m-d H:i:s");
  118. $currentIP = userIP();
  119. try {
  120. $connect = new Dibi\Connection([
  121. 'driver' => 'sqlite3',
  122. 'database' => $GLOBALS['dbLocation'] . $GLOBALS['dbName'],
  123. ]);
  124. $newMessage = [
  125. 'username' => $GLOBALS['organizrUser']['username'],
  126. 'gravatar' => $GLOBALS['organizrUser']['image'],
  127. 'uid' => $GLOBALS['organizrUser']['uid'],
  128. 'date' => $now,
  129. 'ip' => $currentIP,
  130. 'message' => $message
  131. ];
  132. $connect->query('INSERT INTO [chatroom]', $newMessage);
  133. $options = array(
  134. 'cluster' => $GLOBALS['CHAT-cluster-include'],
  135. 'useTLS' => $GLOBALS['CHAT-useSSL']
  136. );
  137. $pusher = new Pusher\Pusher(
  138. $GLOBALS['CHAT-authKey-include'],
  139. $GLOBALS['CHAT-secret'],
  140. $GLOBALS['CHAT-appID-include'],
  141. $options
  142. );
  143. $pusher->trigger('org_channel', 'my-event', $newMessage);
  144. return true;
  145. } catch (Dibi\Exception $e) {
  146. return $e;
  147. }
  148. }
  149. function getChatMessage()
  150. {
  151. try {
  152. $connect = new Dibi\Connection([
  153. 'driver' => 'sqlite3',
  154. 'database' => $GLOBALS['dbLocation'] . $GLOBALS['dbName'],
  155. ]);
  156. $all = $connect->fetchAll('SELECT `username`, `gravatar`, `uid`, `date`, `message` FROM chatroom LIMIT ' . $GLOBALS['CHAT-messageLoadLimit']);
  157. return $all;
  158. } catch (Dibi\Exception $e) {
  159. return false;
  160. }
  161. }