Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Dodanie powidomienia dźwiękowego w daddy-shoutbox
maciek9669
post 4.02.2015, 10:55:20
Post #1





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 3.02.2015

Ostrzeżenie: (0%)
-----


Nw czy to dobre miejsce do zadania tego pytania
Chciałbym dodać do shoutboxa opartego na daddy-shoutbox dodać dzwięk po nadejściu nowej widomości lub przynajmniej po odświeżeniu pola z wiadomościami ale nie mam pojęcia jak js dopiero się uczę
bazuje na kilku plikach

index
  1. <!DOCTYPE html>
  2.  
  3. <meta http-equiv="content-type" content="text/html; charset=ISO-8859-2">
  4.  
  5. <style type="text/css">
  6. body {
  7. background: url('http://tag.16mb.com/bg.jpg') repeat fixed;
  8. font-size: 18px;
  9. font-family: Arial,Helvetica,sans-serif;
  10. }
  11. #daddy-shoutbox {
  12. padding: 5px;
  13. background: url('http://tag.16mb.com/bgs.jpg') repeat fixed;
  14. color: white;
  15. width: 500px;
  16. font-family: Arial,Helvetica,sans-serif;
  17. font-size: 11px;
  18. }
  19. #tab {
  20. font-size: 14px;
  21. }
  22. .shoutbox-list {
  23. border-bottom: 1px solid #083030;
  24.  
  25. padding: 5px;
  26. display: none;
  27. }
  28. #daddy-shoutbox-list {
  29. text-align: left;
  30. margin: 0px auto;
  31. }
  32. #daddy-shoutbox-form {
  33. text-align: left;
  34.  
  35. }
  36. .shoutbox-list-time {
  37. color: #8DA2B4;
  38. }
  39. .shoutbox-list-nick {
  40. margin-left: 15px;
  41. font-weight: bold;
  42. }
  43. .shoutbox-list-message {
  44. margin-left: 15px;
  45. }
  46. </style>
  47. <title>Czat</title>
  48. <script type="text/javascript" src="Czat_pliki/jquery.js"></script>
  49. <script type="text/javascript" src="Czat_pliki/jquery_002.js"></script>
  50. </head>
  51. <body alink="white" link="white" vlink="white">
  52. <div id="tab">
  53. <table align="center" border="0" cellspacing="1" height="25" width="512">
  54. <tbody><tr>
  55. <td align="center" background="Czat_pliki/bgs.jpg">
  56. <a href="http://tag.16mb.com/" style="text-decoration: none;">ZWZST</a>
  57. </td>
  58. <td align="center" background="Czat_pliki/bgs.jpg">
  59. <a href="http://tag.16mb.com/2/" style="text-decoration: none;">Kanał 2</a>
  60. </td>
  61. <td align="center" background="Czat_pliki/bgs.jpg">
  62. <a href="http://tag.16mb.com/3/" style="text-decoration: none;">Kanał 3</a>
  63. </td>
  64. <td align="center" background="Czat_pliki/bgs.jpg">
  65. <a href="http://tag.16mb.com/4/" style="text-decoration: none;">Kanał 4</a>
  66. </td>
  67. </tr>
  68. </tbody></table>
  69. </div>
  70. <div id="daddy-shoutbox">
  71. <div id="daddy-shoutbox-list"></div>
  72. <br>
  73. <center><form id="daddy-shoutbox-form" action="daddy-shoutbox.php?action=add" method="post">
  74. <br>
  75. Tekst: <input name="message" style="white-space:pre-wrap; margin-left: 20px; width:400px">
  76. <br>
  77. <br>
  78. Nick: <input name="nickname" style="margin-left: 25px;" type="text">
  79. <input value="Wyslij" type="submit">
  80. <span id="daddy-shoutbox-response"></span>
  81. </form>
  82. <div id="clear-button" style="text-align: right;">
  83. <form style="align: right;" action="clear.php"><input value="Clear" type="submit"></form></div></center>
  84. </div>
  85.  
  86. </center>
  87.  
  88. <script type="text/javascript">
  89. var count = 0;
  90. var files = '';
  91. var lastTime = 0;
  92.  
  93. function prepare(response) {
  94. var d = new Date();
  95. count++;
  96. d.setTime(response.time*1000);
  97. var mytime = d.getHours()+':'+d.getMinutes()+':'+d.getSeconds();
  98. var string = '<div class="shoutbox-list" id="list-'+count+'">'
  99. + '<span class="shoutbox-list-time">'+mytime+'</span>'
  100. + '<span class="shoutbox-list-nick">'+response.nickname+':</span>'
  101. + '<span class="shoutbox-list-message">'+response.message+'</span>'
  102. +'</div>';
  103.  
  104. return string;
  105. }
  106.  
  107. function success(response, status) {
  108. if(status == 'success') {
  109. lastTime = response.time;
  110. $('#daddy-shoutbox-response').html('<img src="'+files+'images/accept.png" />');
  111. $('#daddy-shoutbox-list').append(prepare(response));
  112. $('input[@name=message]').attr('value', '').focus();
  113. $('#list-'+count).fadeIn('slow');
  114. timeoutID = setTimeout(refresh, 3000);
  115. }
  116. }
  117.  
  118. function validate(formData, jqForm, options) {
  119. for (var i=0; i < formData.length; i++) {
  120. if (!formData[i].value) {
  121. alert('Uzupełnij wszystkie pola!');
  122. $('input[@name='+formData[i].name+']').css('background', 'red');
  123. return false;
  124. }
  125. }
  126. $('#daddy-shoutbox-response').html('<img src="http://tag.16mb.com/loader.gif" />');
  127. clearTimeout(timeoutID);
  128. }
  129.  
  130. function refresh() {
  131.  
  132. $.getJSON(files+"daddy-shoutbox.php?action=view&time="+lastTime, function(json) {
  133. if(json.length) {
  134. for(i=0; i < json.length; i++) {
  135. $('#daddy-shoutbox-list').append(prepare(json[i]));
  136. $('#list-' + count).fadeIn('slow');
  137. }
  138. var j = i-1;
  139. lastTime = json[j].time;
  140. }
  141. //alert(lastTime);
  142. });
  143. timeoutID = setTimeout(refresh, 3000);
  144. }
  145.  
  146. // wait for the DOM to be loaded
  147. $(document).ready(function() {
  148. var options = {
  149. dataType: 'json',
  150. beforeSubmit: validate,
  151. success: success
  152. };
  153. $('#daddy-shoutbox-form').ajaxForm(options);
  154. timeoutID = setTimeout(refresh, 100);
  155. });
  156. </script>
  157. <center><a style="text-decoration: none; color: black;"><font color="#083030" size="10">IP: <script language="JavaScript" type="text/javascript" src="Czat_pliki/adres_ip.htm"></script>91.206.211.201</font></a></center>
  158.  
  159. </body></html>


link do czatu Czat
link do plików użytych w Shutbox pliki

Ten post edytował maciek9669 4.02.2015, 11:09:49
Go to the top of the page
+Quote Post
rad11
post 4.02.2015, 14:53:18
Post #2





Grupa: Zarejestrowani
Postów: 1 270
Pomógł: 184
Dołączył: 7.10.2012
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


Tam gdzie pobierasz dane , sprawdz czy jest to nowa wiadomosc jezeli jest to uruchom:

  1. $('audio').attr('autoplay', 'true')


a w strukturze html gdzie usmiesc:

  1. <audio controls style="display:none;">
  2. <source src="http://www.w3schools.com/html/horse.ogg" type="audio/ogg">
  3. <source src="http://www.w3schools.com/html/horse.mp3" type="audio/mpeg">
  4. </audio>


Ten post edytował rad11 4.02.2015, 15:02:28
Go to the top of the page
+Quote Post
maciek9669
post 4.02.2015, 16:56:51
Post #3





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 3.02.2015

Ostrzeżenie: (0%)
-----


Cytat(rad11 @ 4.02.2015, 14:53:18 ) *
Tam gdzie pobierasz dane , sprawdz czy jest to nowa wiadomosc jezeli jest to uruchom:

  1. $('audio').attr('autoplay', 'true')

A mogłbyś wyjaśnic gdzie dokładnie bo sczerze mówiąc umiem dopiero podstawy podstaw JS. To był gotowy czat skonfigurowałem go pod siebie go pod siebie został mi tylko ten dźwięk...

Ten post edytował maciek9669 4.02.2015, 17:00:42
Go to the top of the page
+Quote Post
rad11
post 4.02.2015, 20:10:05
Post #4





Grupa: Zarejestrowani
Postów: 1 270
Pomógł: 184
Dołączył: 7.10.2012
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


pokaz kod files+"daddy-shoutbox.php?action=view&time="+lastTime tego pliku.
Go to the top of the page
+Quote Post
maciek9669
post 4.02.2015, 23:27:37
Post #5





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 3.02.2015

Ostrzeżenie: (0%)
-----


Trochę kombinowałem. Wstawiłem to co kazałeś
do index.htm
  1. function refresh() {
  2.  
  3. $.getJSON(files+"daddy-shoutbox.php?action=view&time="+lastTime, function(json) {
  4.  
  5. if(json.length) {
  6. $('audio').attr('autoplay', 'true');
  7. for(i=0; i < json.length; i++) {
  8.  
  9. $('#daddy-shoutbox-list').append(prepare(json[i]));
  10.  
  11. $('#list-' + count).fadeIn('slow');
  12.  
  13.  
  14. }

ale dzwięk jest tylko kiedy wyczyszczę stronę button-em "clear" i wprowadzę jedną wiadomość


daddy-shoutbox
  1. <?php header('Content-Type: text/html; charset=utf-8'); ?>
  2. <?php
  3.  
  4. function replace(&$item, $key) {
  5. $item = str_replace('|', '-', $item);
  6. }
  7. if (!function_exists('file_put_contents')) {
  8. function file_put_contents($fileName, $data) {
  9. if (is_array($data)) {
  10. $data = join('', $data);
  11. }
  12. $res = @fopen($fileName, 'w+b');
  13. if ($res) {
  14. $write = @fwrite($res, $data);
  15. if($write === false) {
  16. return false;
  17. } else {
  18. return $write;
  19. }
  20. }
  21. }
  22. }
  23. //file_put_contents('debug.txt', print_r($_GET, true));
  24. switch($_GET['action']) {
  25. case 'add':
  26. array_walk($_POST, 'replace');
  27. $arr = file('messages.txt');
  28. if(count($arr) > 10)
  29. $_POST['nickname'] = htmlentities($_POST['nickname'], ENT_COMPAT, 'utf-8');
  30. $_POST['message'] = htmlentities($_POST['message'], ENT_COMPAT, 'utf-8');
  31. $time = time();
  32. $arr[] = $time.'|'.$_POST['nickname'].'|'.$_POST['message'].'|'.$_SERVER['REMOTE_ADDR']."\n";
  33. file_put_contents('messages.txt', implode('', $arr));
  34. $data['response'] = 'Good work';
  35. $data['nickname'] = $_POST['nickname'];
  36. $data['message'] = $_POST['message'];
  37. $data['time'] = $time;
  38. break;
  39. case 'view':
  40. $data = array();
  41. $arr = file('messages.txt');
  42. if(!$_GET['time'])
  43. $_GET['time'] = 0;
  44. foreach($arr as $row) {
  45. $aTemp = null;
  46. list($aTemp['time'], $aTemp['nickname'], $aTemp['message']) = explode('|', $row);
  47. if($aTemp['message'] AND $aTemp['time'] > $_GET['time'])
  48. $data[] = $aTemp;
  49. }
  50. //file_put_contents('debug.txt', print_r($data, true));
  51. break;
  52. }
  53. require_once('JSON.php');
  54. $json = new Services_JSON();
  55. $out = $json->encode($data);
  56. print $out;
  57. ?>


JSON.php LINK
w postaci bezpośredniego linku do pliku bo nie zmieścił sie plik w poście

Ten post edytował maciek9669 4.02.2015, 23:29:32
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 31.07.2025 - 09:53