DIZ-CS.RU - Мы с Вами НАВСЕГДА!
Активный форум » WEB-мастеру » Скрипты для uCoz » Мгновенное оповещение как на сайте vk(php скрипт)
  • Страница 1 из 1
  • 1
Сообщение # 1
Аватарка [ErSTe™]
OFF
Пользователь
Сообщения:119
Награды:138
Отзывы:3
Skype пользователя:


Всем привет, вот решил написать небольшой скрипт мгн. оповещений как на ВК.
Работаем по тому же принципу как и в теме мгн. обновления: http://usite.su/forum/31-3667-1
В любом шаблоне перед пишем:
В любом шаблоне перед пишем:

Code


создаём папку js и в ней два файла: cookie.js, ualert.js и вставляем перед
В ualert.js пишим:

Code
setTimeout(function () {     
         
     var source = new EventSource('/php/evstream/index.php');  
  source.addEventListener('message', function(e) {  
     // Пришли какие-то данные  
  var data = e.data;  
  data = data.split('alert: ');  
  eval('var newalert = '+data[1]+';');  

  for( i = 0; i < 4; i++ ){  
  if(!$('#uBox_'+newalert[i].id).html() && cookie('uBox_'+newalert[i].id)==null){  
  $('#pmm_player').remove();  
  $('body').append('');  
  $('.uBox').animate({bottom:'10'}, {queue:false}).fadeIn().append('
Новое уведомление от '+newalert[i].title+'
Тема: '+newalert[i].message+'
');  
  }  
  }  
  }, false);  

  source.addEventListener('open', function(e) {  
     // Соединение было открыто  
  }, false);  

  source.addEventListener('error', function(e) {  
     if (e.eventPhase == EventSource.CLOSED) {  
     // Соединение закрыто  
     }  
  }, false);  

     }, 5);  

  function ualert_hide(id){  
  cookie('uBox_'+id, '1', {expires: 1});  

  $('#uBox_'+id).animate({bottom:'10'}).fadeOut();  

  }


В cookie.js пишим:

Code
function cookie(name, value, options) {     
      if (typeof value != 'undefined') {     
      options = options || {};     
      if (value === null) {     
      value = '';     
      options.expires = -1;     
      }     
      var expires = '';     
      if (options.expires && (typeof options.expires == 'number' ||     
  options.expires.toUTCString)) {     
      var date;     
      if (typeof options.expires == 'number') {     
      date = new Date();     
      date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));     
      } else {     
      date = options.expires;     
      }     
      expires = '; expires=' + date.toUTCString();     
      }     
      var path = options.path ? '; path=' + (options.path) : '';     
      var domain = options.domain ? '; domain=' + (options.domain) : '';     
      var secure = options.secure ? '; secure' : '';     
      document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain,     
  secure].join('');     
      } else {     
      var cookieValue = null;     
      if (document.cookie && document.cookie != '') {     
      var cookies = document.cookie.split(';');     
      for (var i = 0; i < cookies.length; i++) {     
      var cookie = jQuery.trim(cookies[i]);     
      if (cookie.substring(0, name.length + 1) == (name + '=')) {     
      cookieValue = decodeURIComponent(cookie.substring(name.length + 1));     
      break;     
      }     
      }     
      }     
      return cookieValue;     
      }     
     };


Создаём в папке php папку evstream, в ней создаём 2 файла: base.php, index.php
Своего рода базой является base.php, в нём пишем:

Code
  • Страница 1 из 1
  • 1
Поиск:
Писать на форуме могут только авторизованные пользователи.