chat.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. ),
  78. 'Connection' => array(
  79. array(
  80. 'type' => 'password-alt',
  81. 'name' => 'CHAT-authKey-include',
  82. 'label' => 'Auth Key',
  83. 'value' => $GLOBALS['CHAT-authKey-include']
  84. ),
  85. array(
  86. 'type' => 'password-alt',
  87. 'name' => 'CHAT-secret',
  88. 'label' => 'API Secret',
  89. 'value' => $GLOBALS['CHAT-secret']
  90. ),
  91. array(
  92. 'type' => 'input',
  93. 'name' => 'CHAT-appID-include',
  94. 'label' => 'App ID',
  95. 'value' => $GLOBALS['CHAT-appID-include']
  96. ),
  97. array(
  98. 'type' => 'input',
  99. 'name' => 'CHAT-cluster-include',
  100. 'label' => 'App Cluster',
  101. 'value' => $GLOBALS['CHAT-cluster-include']
  102. ),
  103. )
  104. );
  105. }
  106. function sendChatMessage($array)
  107. {
  108. $message = isset($array['data']['message']) ? $array['data']['message'] : null;
  109. $message = htmlspecialchars($message, ENT_QUOTES);
  110. $now = date("Y-m-d H:i:s");
  111. $currentIP = userIP();
  112. try {
  113. $connect = new Dibi\Connection([
  114. 'driver' => 'sqlite3',
  115. 'database' => $GLOBALS['dbLocation'] . $GLOBALS['dbName'],
  116. ]);
  117. $newMessage = [
  118. 'username' => $GLOBALS['organizrUser']['username'],
  119. 'gravatar' => $GLOBALS['organizrUser']['image'],
  120. 'uid' => $GLOBALS['organizrUser']['uid'],
  121. 'date' => $now,
  122. 'ip' => $currentIP,
  123. 'message' => $message
  124. ];
  125. $connect->query('INSERT INTO [chatroom]', $newMessage);
  126. $options = array(
  127. 'cluster' => $GLOBALS['CHAT-cluster-include'],
  128. 'useTLS' => true
  129. );
  130. $pusher = new Pusher\Pusher(
  131. $GLOBALS['CHAT-authKey-include'],
  132. $GLOBALS['CHAT-secret'],
  133. $GLOBALS['CHAT-appID-include'],
  134. $options
  135. );
  136. $pusher->trigger('org_channel', 'my-event', $newMessage);
  137. return true;
  138. } catch (Dibi\Exception $e) {
  139. return $e;
  140. }
  141. }
  142. function getChatMessage()
  143. {
  144. try {
  145. $connect = new Dibi\Connection([
  146. 'driver' => 'sqlite3',
  147. 'database' => $GLOBALS['dbLocation'] . $GLOBALS['dbName'],
  148. ]);
  149. $all = $connect->fetchAll('SELECT `username`, `gravatar`, `uid`, `date`, `message` FROM chatroom LIMIT ' . $GLOBALS['CHAT-messageLoadLimit']);
  150. return $all;
  151. } catch (Dibi\Exception $e) {
  152. return false;
  153. }
  154. }