����C %# , #&')*)-0-(0%()(��C (((((((((((((((((((((((((((((((((((((((((((((((((((����"�������@�@�hC��}!���Ѱ��<"� 9iׂIIIHk�+?�c?��*Y�����!�du)b�T�9вU�$8G��I.�澬��D���Sq� q�}.<��Z�l�V!X� *x�-�\����t3i�Ũ�sNv71�ƛ\��z|t�L���$�����*f��kʮ��7�H;���~F%�'3�@�H�q�` 9mOL����/x@ @��G
d�8F�ه��Ka�Kdr�Fh.�]y4 JЛ��]�K�B�E$��$ $ �PR�����G�]��u�i$�$���'! "#031���C/Td=S�Q?���62Ccj{ ����̏d�چ/c�V�`��Wz͈�{Y`�d�h�L �]OB���l���o���mr���n��s-ڗEZ��N�_��1%b���H�ϣ������V�7):�ӷ)�}�~�(�;�!�b1�5K��[E�vϻ>��q.%� ���O���(�c�#x�$�'+��`٥v��v(�����M�"�v��B��.�a ���T�~�ϕ�hy(6nݱl��1yNɓx�������AR�8�rqv1.cS�+��_���&@�� �u�M�5Ĉ�Xm���eL�X�q��y#�9]�c�}ɄL��d�eJ몓���I1T�d��CaM�$��T�,�X �bʭ�!�%F5��X1x#���!�q��\��F��2��&Rq���C�ol~�̱�.0ϦL�d�`.������ ���m{�Y~k{C��}bv�;U��c<�r�~ɜs�1�j��]W�l��*նCr��Q�N9�-������d��E؛��nF��eړ�8(q��5UgRȱGTA��*������̆��V�珰����ezN��h�U]�T�FG�^���<��ay�,!���5.� �u�bΚ�V�J%��m�Dxn'�����6�@BPa�`��Hts� �ɮ���Ŏ�Zɬ��%B�X��d5Z���hC}�䅸�p+ k=��ʒ(�aՏFG&�%@/�{+�Yu+�ȣGѩ"O%�|vȲxF>�N(��ou�h6 &Y5��8�7�E$-��']n,@TD\��+���Ry�U��U^�Q,f>��1�����q��f��U��� ����F���ڥ��>I�����fNUw�u��#OMMQ6� N�*��_�� k� ����rS��`���1�:��!�F'<+� � b?O��2 !Q12A��� "3a������#$��?�,�7�!`yǮ(�1�6w��a���� �F�#��?*"s���v>��Ⱥ����f�v��͑���s����������]Gn��S ���ȥpG ы�E�g�)Z���x�rY�q�]�@f�_܃�pչEڎّC ����Ŝ*/ �h�O�Sv�و\��5��U��y��|o�Hm2C�S�BW����)��5��{T��W���=o*RA��<����L0g4{��쁢�ep�rw�8��7��U���t<Ԍѻ7�fGf�k}���Ê�㛆Gռz�Q@��{C��'G��8�!�S$�j��x���|���צV<��,����u�k�uu�rM�f�_dϣi ߫�ԟn�!K����mxu�=�槻�'j�X�����������%!A "1QR#Br��?�R:��R�n�b[�II?#��6<:�$gN����lGNlrr��dעMMn`ɿy�,�%B�e�W��dVS��r���� %�tT��(�ɷ��S�]�O]#�_LEMHN�M���kv���~X���O6�U�V_�����b���J�t�774����D!1AQa"2q�#3BRb����0���� 4CSr����cst�����?��^q���7�dG�U�"p��moz��'��n_x���唹e������<6��O�t���R>k��s=�Cr���e�?�i��� ����/��ں$be���o`ޮ�GHy�;fNAl�8��.�\�S������"���a�úF�YvNk�-*`v�k�ʈ2f�EE��Wa�,� �fF^#�;��[9��^~������Y$:0#W3������Z*���I�Z�ڹ�k�n--9=��G��;7F)m{T�Ɇ��=�����Ȭ5�5�B�aڞ5M����#m�5Ʀ��m�8��+Hh���$�}�:&�e�Q�[;i]С�:�:��o����$<~��5RB�?�s3�5�r��O��ֿ�w�P/��̅���(�Z6�R>)��N��4�!ʊ�wz�-�r�w+�yk���q�1�bKhƸ�4N�Ӑ�X����Q��_��})�+e1�5��n��q?��[�^�9�<�z3Fsi�8�'�)9p)�{��RP�Z+�*��p(aY��V����6l�g�9��;���d�u���Nt@�3�sTwzaŇ�GT�b�H��(#��*zc�������9K�b1�����t����Ê��
�Z?g�iD���H�R���B���^M����v���O���L�D,'d�q�C�P�����$Δ��U�֟֊=�s��F�$��J�ދZ?�N��������A�N�WP��,�� �¦�&;�x��dup�����i���Ipd���;�Dž!��ֿѮAb%�u��}j��-p��>I�[�N�bi����G�'�;4w�m]H�]����#LӘNN��R��������s�.]��en��-�8e��Ps����Q��;���ț�E�ݫ���7��g�_L��W��EZ:/��I���a�g�n�ܤ��iٹ���ŷ�T���H~i�a�����֎�~KV������ A-2m]�F"�m�9-Zbǰ�״ @����~�4�N�[�Uxč�tl>������u#r�gѐ�3���;M9�<�J�����1�vfL8����1�P�HgP�Xv��������{����O�}�n��KQ؋����7<�l�fey<�}�>�bX���4<`Y7���si��V)�s�:�{�rO�h�z �@4VW�B���&�������ɡob܋�F��4>y�s�fXWS�N�O$�,.u:�ԫ��g�yao4��$h��D#��ٸf^kh�7�#1Z�֥&���*�v-��;bޭ����Q�����h�ow�y]�ه.+�7�M�ⴻ �JY��g�f�i3q��KC��3�¹�?5�Z.N��^Z w���KF͂���7��ރ۞��wj��T�J.�q��\Sv1U����R��욽&�N����pЖ`�`у��m`v�n#z��4��>e��V�`'���h�����'�j�AҔ�-�4:H���n]9�h<��n����U�6m��2c�E�1/�Y�%���I��~ʏ�|VBƟ@����;�������%�M9M���}��1�D��d����%g���O��]��у&�r��f�7�uܲ���(!1AQaq�������0� ���?!��*��@)�Je�G��j��{�['��v+���������)���(�/����д%젍Z��kk�Lu�Rm���j.c���@Z� V�J��d��j���h6���2AO�� a;oBu���H�=���nK�W8�B�ɰ�u?��бأm,�sr����|����8˨i��qI2tZ�ۄJP��XE��������zޔj~]UMu����zv!����N�&�1�Y��zJ�ՠ��\p��o'ሸ�C؊Y��TD"HM5�Ъ��i߯a���F����A)�����ڮ����z�E���@�hg�֝8�1jk��\�M�3�8ܢ�� ������s�7����N}�ޭ������GN�Bc���L pk�;�J�δ3�e�iU�gAYW]\�>�GyگQ=��f�KA;T�a`eM+Q �� �Ln���̌]GM�����<Ħ�j���H��N�M�x�}aX{̣S� ��ԅ��n�MA�S�r�(����(�L��zo9���.�;
�ӳf������`Ӕ٢3�� IW��\9~_���saa�\ԊW�ܭX:���ӆ�38�ty*����N�qP����BI�Y��jE��>DP�!�R%-��4��'�皺;��~J�!�7m���X��h�P!曭���$�\�AYj�.lC��4��+�jD�dgC0-*���|��`ZD�+л�C"��)��s��8Kq�pq���Ms��4� ��7\U`�.��[Ey8��AH!/��,���(:M -�T䓥�~O�4-���Ԓn��}HDN7���K���$�_Ԕ䚞`�R�hB�_aX?4V��ŗ�@ه�u�a�;�{PcT+�������7YBo�?��r-ͩ{�ĎA�� ����˼n��M286��G���1���V�˜Jв"l��V5���5�C]h���̊�A���%� �'p���Ԃ���Ր��9=�d�=�e�{�'<3�_ �:^�~��4�(�n�-C�s��5m![�jmIqU�~�Tw8��`���p�H8�u�Д l m�aP�0�������9y����CM��F1G糞�.�U~�������FC�{�!e(Y�:���P����7~;�L�N^{�1r�\���ԬG(���0d�ÏO�qK�Z�⑼�T�{ 2��s��Kd�Տ?mMQ��=���6�7�i�����H+����9��d��=��;�QؤH8n�Lb�D��yS%�(�{b���Cu���p�t#C���$A"�H{���jqᶯ�:�n=E����hH�`�!�m��MA������?�v6���+MԿ⟚qK�i�D�*Q5��CZ���2�|]�:Xd+�t�:o@��M��� :�32��b����[\5=�ֵ7])�|t��Ϻ����w�B�ń�e���!`�:��I,��9:����j@/a 8����+<�u�(T^ۺ~��2oE�B�%b)��z��ݳځ�)��i�j��&��Fi`qr��w���7�@��P�� �3Z&<�m�S�C����7t�T����ƴ�q~J�e�r6�Z]�rL���ه�E17'�x���+[�ܜTc6�/�����W�`�qpMJ���N5^����x�}{l�Fm������1�oZ\�����/d�/6� �uӸ�0elXuX;M��$M�}mB��������Z%e���3f�js����O�J~2�z�86�*PB��v�Ν��e-��.�/��L�O����2����9���4}|��T5M���hÐ7�F*��l+y0����:|��=k[�d�;|�ԉe�=w�<��õ�<��'!1AQaq����� ������?��5����)�(���+>v����6&{���Ǹ@����M�����v��iA 6T'�w��h�s �E}�x��G&'g�� J~1q�f�f���&��q˘���-���vYm
�/i1 �I��6��u,)�#�,����l}*&`�$�ͬe�%�w3�x�Ѥ�Xc�D��执g�峕�5B/�|$��=���%8 a��2.l� c�@G� �\�/x[өq�]�v5?�����N|�!���\��,>��{�"r�/��?��&!1QAa�� ��ᑱ����?ĊD�肭�� nv@�yޝ (�����I ����U - ���b�m�E>,��1v!�d�&�� ���&�檔�5D�&0P��Ԕ�͒@Z��:E"� Q��`>PH:~�O�����P�3W��@hM��k�U��\�O��R�������5ʄ�,��f�|��r���}јxo)�"+h�QK���/��0�`�5�{M~�� ���'!1AQaq���0 �������?�?�k��#^�~�G��#V,������#Z�1'ܤ����������~p�O%O�O�\�q�`�~��}��E�Ű5 �輸�du����x\�$���s[�{T2t`B��gq�4Z]b� 㛪�3,(@����bAp�r)9:@|b�!r�g:N�^�Ʌ��� �x_�\��pm7I��0?>^k��������w���|.K�[sF@�]Gn*L �yO� le�P�.p��֍�j�S�=�ʨ�ןQF�"��5zʼn���k�*8�u" ����Fg��� �cSy�V������Ƈ��N��ؐ(�����48hV�A�ӎ^��^ ���jyB� ��p"�����y]�ļlU�(�7�U`3�pCGF'&yg������o��z������X��ν:�P"@�G@x[��o&MJ�$F.����hi w;}�/^͇q���n�mN�/�TQ���އ��O1\,}��bQ #¯^S!)��X���#GPȏ�t�� c^\��' }iIZ���a�)��������z��4͊�Ξy��48,��f���#�����KP!Jx�|w�ʆ�������������#��Z�������< �~K��r�p&qH/;�R���沽�+�E�R���~0v���V#ʀ�T��S(-ڝ��B�y�b�C�D������b��������8��~�= �Y�ͧ]��@n����M�k2�%�;�%,�r6�LR腻?^��;KŇ=�ք ���=`�ɥ��/����z�&�I{���#J��M���C��}�H9^UJ�,P ��pS����G�d69Ϭu���%"��ˢP��K�"k)��=��9� ����㇌,��Oli��Xzh� " � ������R��^�s����N�k��Q>�63(���� ��PQ�Py�����3����$f+W՛=4�ǁ`*��^��Eb�K�t�6��^��!�籷��ȭ��K{/;�L���p�x�����;a���Oلz�[�.NP4�]Gc�T�v����~sg'LED��]j��'�G�]�6rY����UPw�*O�İՋi�'8�۴�#g�Xx+=�eU6�R��c�"�u2��~�?n�y�;�u��3�'��6�f������b��߬M�$*��k&?6���*^1n����ێz)<��Gz� �����7����Y� ��ۃ)$A��2�L6� ե�H�<�r��#ʽ2��O��R���z�A��XW��@���������<�G� Ϥ�^�˓i�M�W���6 ��0��m){c�;ݧ�>R�a����}1�ٯ%�EY2�Q��Ep���$ ��E��qS��t#+x� *�h�UI��XM?�'//��a'�G�����q@���<��z��؟����cd��z�ˬT_u�Ѯ����&�z�k ��n ]�a%�py»�`Qd�xc������n�� ��*��oTd�;'j�<�!j���'�(~�ʹW�M� P�mȘ��@֨V+��R�`�$��`�+@��_[�kG����P���Zh9�R����&5b�v���Z���#p�&�Ա+��8�etZ7G���;��@"�e0���v7����?��z�?_���_�q1�T�"�p�ˎ/U 6_�B�>��0( ��}G#������Ȣ�p�� �9��;/& `�B&$�y��t(�*z�x���Ӕ������S�?Kȏ3���{p� b � ۍ-�z܈֦��6?<���ǬP�N�G �更� �6�/h�����0Z���������i�ua��e�*M'A� �x��v�q.>�F� oN{��Q���{gD��L��u��=|���O xN���d���q�8(��E�Uu��,��O� t�DJ ����;��G����e���C��VYZ�� ���T4{����(�Ӳ'c�t�f��w�c�jr�e�m �#7,�6��B�E4Q�P�.P�(&��^{9H-�m�o ��q�g1���=��>p�)/"p0!4�mS6ú�FN���h��D �)��XdT �FؤZ⸚�k���H�c8v� <���u�P�Հ���:��_�EN��|�ӛ��u?-�/�o�Lhk�ܸ�S�;�Rī�����T"�N����M��px7<�� j�$��`�Y)Pjh 5` K�Qf�4�C�bX"�D���;HD�Z�9R b�F)�UA����v�#��HD�!{������>I� �`�ԁ i�4�)t*�ç�Le�_���>ru�GEQg��ǔct��ō0��l6v���d�� ��GG8���v^�|�#JyZPSO�� Y�CuAߐ�"�x���OfHF@�K�V�!少Eҕ]h� ��[���)��.q����*0I<8��^�6�}p��^tho���ig�i����DK���p,��2�3�I��5����쓄OY�6s7Qs�Ow^�w�J/�A➰������0������g(Մ��y��Kԇ����QS��?H���w�X�=��ҞX�~���Q=�'���p?7�@g�~�G�}�r��g�T?���
One Hat Cyber Team
One Hat Cyber Team
Your IP :
18.216.220.244
Server IP :
172.67.155.96
Server :
Linux server3.shared.spaceship.host 4.18.0-372.9.1.1.lve.el8.x86_64 #1 SMP Tue May 24 07:49:22 EDT 2022 x86_64
Server Software :
LiteSpeed
PHP Version :
5.6.40
Buat File
|
Buat Folder
Dir :
~
/
home
/
rlcugxuggt
/
dafrifilms.com
/
wp-includes
/
js
/
Edit File Name:
heartbeat.js
/** * Heartbeat API * * Heartbeat is a simple server polling API that sends XHR requests to * the server every 15 - 60 seconds and triggers events (or callbacks) upon * receiving data. Currently these 'ticks' handle transports for post locking, * login-expiration warnings, autosave, and related tasks while a user is logged in. * * Available PHP filters (in ajax-actions.php): * - heartbeat_received * - heartbeat_send * - heartbeat_tick * - heartbeat_nopriv_received * - heartbeat_nopriv_send * - heartbeat_nopriv_tick * @see wp_ajax_nopriv_heartbeat(), wp_ajax_heartbeat() * * Custom jQuery events: * - heartbeat-send * - heartbeat-tick * - heartbeat-error * - heartbeat-connection-lost * - heartbeat-connection-restored * - heartbeat-nonces-expired * * @since 3.6.0 * @output wp-includes/js/heartbeat.js */ ( function( $, window, undefined ) { /** * Constructs the Heartbeat API. * * @since 3.6.0 * * @return {Object} An instance of the Heartbeat class. * @constructor */ var Heartbeat = function() { var $document = $(document), settings = { // Suspend/resume. suspend: false, // Whether suspending is enabled. suspendEnabled: true, // Current screen id, defaults to the JS global 'pagenow' when present // (in the admin) or 'front'. screenId: '', // XHR request URL, defaults to the JS global 'ajaxurl' when present. url: '', // Timestamp, start of the last connection request. lastTick: 0, // Container for the enqueued items. queue: {}, // Connect interval (in seconds). mainInterval: 60, // Used when the interval is set to 5 seconds temporarily. tempInterval: 0, // Used when the interval is reset. originalInterval: 0, // Used to limit the number of Ajax requests. minimalInterval: 0, // Used together with tempInterval. countdown: 0, // Whether a connection is currently in progress. connecting: false, // Whether a connection error occurred. connectionError: false, // Used to track non-critical errors. errorcount: 0, // Whether at least one connection has been completed successfully. hasConnected: false, // Whether the current browser window is in focus and the user is active. hasFocus: true, // Timestamp, last time the user was active. Checked every 30 seconds. userActivity: 0, // Flag whether events tracking user activity were set. userActivityEvents: false, // Timer that keeps track of how long a user has focus. checkFocusTimer: 0, // Timer that keeps track of how long needs to be waited before connecting to // the server again. beatTimer: 0 }; /** * Sets local variables and events, then starts the heartbeat. * * @since 3.8.0 * @access private * * @return {void} */ function initialize() { var options, hidden, visibilityState, visibilitychange; if ( typeof window.pagenow === 'string' ) { settings.screenId = window.pagenow; } if ( typeof window.ajaxurl === 'string' ) { settings.url = window.ajaxurl; } // Pull in options passed from PHP. if ( typeof window.heartbeatSettings === 'object' ) { options = window.heartbeatSettings; // The XHR URL can be passed as option when window.ajaxurl is not set. if ( ! settings.url && options.ajaxurl ) { settings.url = options.ajaxurl; } /* * Logic check: the interval can be from 1 to 3600 seconds and can be set temporarily * to 5 seconds. It can be set in the initial options or changed later from JS * or from PHP through the AJAX responses. */ if ( options.interval ) { settings.mainInterval = options.interval; if ( settings.mainInterval < 1 ) { settings.mainInterval = 1; } else if ( settings.mainInterval > 3600 ) { settings.mainInterval = 3600; } } /* * Used to limit the number of Ajax requests. Overrides all other intervals * if they are shorter. Needed for some hosts that cannot handle frequent requests * and the user may exceed the allocated server CPU time, etc. The minimal interval * can be up to 600 seconds, however setting it to longer than 120 seconds * will limit or disable some of the functionality (like post locks). * Once set at initialization, minimalInterval cannot be changed/overridden. */ if ( options.minimalInterval ) { options.minimalInterval = parseInt( options.minimalInterval, 10 ); settings.minimalInterval = options.minimalInterval > 0 && options.minimalInterval <= 600 ? options.minimalInterval : 0; } if ( settings.minimalInterval && settings.mainInterval < settings.minimalInterval ) { settings.mainInterval = settings.minimalInterval; } // 'screenId' can be added from settings on the front end where the JS global // 'pagenow' is not set. if ( ! settings.screenId ) { settings.screenId = options.screenId || 'front'; } if ( options.suspension === 'disable' ) { settings.suspendEnabled = false; } } // Convert to milliseconds. settings.mainInterval = settings.mainInterval * 1000; settings.originalInterval = settings.mainInterval; if ( settings.minimalInterval ) { settings.minimalInterval = settings.minimalInterval * 1000; } /* * Switch the interval to 120 seconds by using the Page Visibility API. * If the browser doesn't support it (Safari < 7, Android < 4.4, IE < 10), the * interval will be increased to 120 seconds after 5 minutes of mouse and keyboard * inactivity. */ if ( typeof document.hidden !== 'undefined' ) { hidden = 'hidden'; visibilitychange = 'visibilitychange'; visibilityState = 'visibilityState'; } else if ( typeof document.msHidden !== 'undefined' ) { // IE10. hidden = 'msHidden'; visibilitychange = 'msvisibilitychange'; visibilityState = 'msVisibilityState'; } else if ( typeof document.webkitHidden !== 'undefined' ) { // Android. hidden = 'webkitHidden'; visibilitychange = 'webkitvisibilitychange'; visibilityState = 'webkitVisibilityState'; } if ( hidden ) { if ( document[hidden] ) { settings.hasFocus = false; } $document.on( visibilitychange + '.wp-heartbeat', function() { if ( document[visibilityState] === 'hidden' ) { blurred(); window.clearInterval( settings.checkFocusTimer ); } else { focused(); if ( document.hasFocus ) { settings.checkFocusTimer = window.setInterval( checkFocus, 10000 ); } } }); } // Use document.hasFocus() if available. if ( document.hasFocus ) { settings.checkFocusTimer = window.setInterval( checkFocus, 10000 ); } $(window).on( 'pagehide.wp-heartbeat', function() { // Don't connect anymore. suspend(); // Abort the last request if not completed. if ( settings.xhr && settings.xhr.readyState !== 4 ) { settings.xhr.abort(); } }); $(window).on( 'pageshow.wp-heartbeat', /** * Handles pageshow event, specifically when page navigation is restored from back/forward cache. * * @param {jQuery.Event} event * @param {PageTransitionEvent} event.originalEvent */ function ( event ) { if ( event.originalEvent.persisted ) { /* * When page navigation is stored via bfcache (Back/Forward Cache), consider this the same as * if the user had just switched to the tab since the behavior is similar. */ focused(); } } ); // Check for user activity every 30 seconds. window.setInterval( checkUserActivity, 30000 ); // Start one tick after DOM ready. $( function() { settings.lastTick = time(); scheduleNextTick(); }); } /** * Returns the current time according to the browser. * * @since 3.6.0 * @access private * * @return {number} Returns the current time. */ function time() { return (new Date()).getTime(); } /** * Checks if the iframe is from the same origin. * * @since 3.6.0 * @access private * * @return {boolean} Returns whether or not the iframe is from the same origin. */ function isLocalFrame( frame ) { var origin, src = frame.src; /* * Need to compare strings as WebKit doesn't throw JS errors when iframes have * different origin. It throws uncatchable exceptions. */ if ( src && /^https?:\/\//.test( src ) ) { origin = window.location.origin ? window.location.origin : window.location.protocol + '//' + window.location.host; if ( src.indexOf( origin ) !== 0 ) { return false; } } try { if ( frame.contentWindow.document ) { return true; } } catch(e) {} return false; } /** * Checks if the document's focus has changed. * * @since 4.1.0 * @access private * * @return {void} */ function checkFocus() { if ( settings.hasFocus && ! document.hasFocus() ) { blurred(); } else if ( ! settings.hasFocus && document.hasFocus() ) { focused(); } } /** * Sets error state and fires an event on XHR errors or timeout. * * @since 3.8.0 * @access private * * @param {string} error The error type passed from the XHR. * @param {number} status The HTTP status code passed from jqXHR * (200, 404, 500, etc.). * * @return {void} */ function setErrorState( error, status ) { var trigger; if ( error ) { switch ( error ) { case 'abort': // Do nothing. break; case 'timeout': // No response for 30 seconds. trigger = true; break; case 'error': if ( 503 === status && settings.hasConnected ) { trigger = true; break; } /* falls through */ case 'parsererror': case 'empty': case 'unknown': settings.errorcount++; if ( settings.errorcount > 2 && settings.hasConnected ) { trigger = true; } break; } if ( trigger && ! hasConnectionError() ) { settings.connectionError = true; $document.trigger( 'heartbeat-connection-lost', [error, status] ); wp.hooks.doAction( 'heartbeat.connection-lost', error, status ); } } } /** * Clears the error state and fires an event if there is a connection error. * * @since 3.8.0 * @access private * * @return {void} */ function clearErrorState() { // Has connected successfully. settings.hasConnected = true; if ( hasConnectionError() ) { settings.errorcount = 0; settings.connectionError = false; $document.trigger( 'heartbeat-connection-restored' ); wp.hooks.doAction( 'heartbeat.connection-restored' ); } } /** * Gathers the data and connects to the server. * * @since 3.6.0 * @access private * * @return {void} */ function connect() { var ajaxData, heartbeatData; // If the connection to the server is slower than the interval, // heartbeat connects as soon as the previous connection's response is received. if ( settings.connecting || settings.suspend ) { return; } settings.lastTick = time(); heartbeatData = $.extend( {}, settings.queue ); // Clear the data queue. Anything added after this point will be sent on the next tick. settings.queue = {}; $document.trigger( 'heartbeat-send', [ heartbeatData ] ); wp.hooks.doAction( 'heartbeat.send', heartbeatData ); ajaxData = { data: heartbeatData, interval: settings.tempInterval ? settings.tempInterval / 1000 : settings.mainInterval / 1000, _nonce: typeof window.heartbeatSettings === 'object' ? window.heartbeatSettings.nonce : '', action: 'heartbeat', screen_id: settings.screenId, has_focus: settings.hasFocus }; if ( 'customize' === settings.screenId ) { ajaxData.wp_customize = 'on'; } settings.connecting = true; settings.xhr = $.ajax({ url: settings.url, type: 'post', timeout: 30000, // Throw an error if not completed after 30 seconds. data: ajaxData, dataType: 'json' }).always( function() { settings.connecting = false; scheduleNextTick(); }).done( function( response, textStatus, jqXHR ) { var newInterval; if ( ! response ) { setErrorState( 'empty' ); return; } clearErrorState(); if ( response.nonces_expired ) { $document.trigger( 'heartbeat-nonces-expired' ); wp.hooks.doAction( 'heartbeat.nonces-expired' ); } // Change the interval from PHP. if ( response.heartbeat_interval ) { newInterval = response.heartbeat_interval; delete response.heartbeat_interval; } // Update the heartbeat nonce if set. if ( response.heartbeat_nonce && typeof window.heartbeatSettings === 'object' ) { window.heartbeatSettings.nonce = response.heartbeat_nonce; delete response.heartbeat_nonce; } // Update the Rest API nonce if set and wp-api loaded. if ( response.rest_nonce && typeof window.wpApiSettings === 'object' ) { window.wpApiSettings.nonce = response.rest_nonce; // This nonce is required for api-fetch through heartbeat.tick. // delete response.rest_nonce; } $document.trigger( 'heartbeat-tick', [response, textStatus, jqXHR] ); wp.hooks.doAction( 'heartbeat.tick', response, textStatus, jqXHR ); // Do this last. Can trigger the next XHR if connection time > 5 seconds and newInterval == 'fast'. if ( newInterval ) { interval( newInterval ); } }).fail( function( jqXHR, textStatus, error ) { setErrorState( textStatus || 'unknown', jqXHR.status ); $document.trigger( 'heartbeat-error', [jqXHR, textStatus, error] ); wp.hooks.doAction( 'heartbeat.error', jqXHR, textStatus, error ); }); } /** * Schedules the next connection. * * Fires immediately if the connection time is longer than the interval. * * @since 3.8.0 * @access private * * @return {void} */ function scheduleNextTick() { var delta = time() - settings.lastTick, interval = settings.mainInterval; if ( settings.suspend ) { return; } if ( ! settings.hasFocus ) { interval = 120000; // 120 seconds. Post locks expire after 150 seconds. } else if ( settings.countdown > 0 && settings.tempInterval ) { interval = settings.tempInterval; settings.countdown--; if ( settings.countdown < 1 ) { settings.tempInterval = 0; } } if ( settings.minimalInterval && interval < settings.minimalInterval ) { interval = settings.minimalInterval; } window.clearTimeout( settings.beatTimer ); if ( delta < interval ) { settings.beatTimer = window.setTimeout( function() { connect(); }, interval - delta ); } else { connect(); } } /** * Sets the internal state when the browser window becomes hidden or loses focus. * * @since 3.6.0 * @access private * * @return {void} */ function blurred() { settings.hasFocus = false; } /** * Sets the internal state when the browser window becomes visible or is in focus. * * @since 3.6.0 * @access private * * @return {void} */ function focused() { settings.userActivity = time(); // Resume if suspended. resume(); if ( ! settings.hasFocus ) { settings.hasFocus = true; scheduleNextTick(); } } /** * Suspends connecting. */ function suspend() { settings.suspend = true; } /** * Resumes connecting. */ function resume() { settings.suspend = false; } /** * Runs when the user becomes active after a period of inactivity. * * @since 3.6.0 * @access private * * @return {void} */ function userIsActive() { settings.userActivityEvents = false; $document.off( '.wp-heartbeat-active' ); $('iframe').each( function( i, frame ) { if ( isLocalFrame( frame ) ) { $( frame.contentWindow ).off( '.wp-heartbeat-active' ); } }); focused(); } /** * Checks for user activity. * * Runs every 30 seconds. Sets 'hasFocus = true' if user is active and the window * is in the background. Sets 'hasFocus = false' if the user has been inactive * (no mouse or keyboard activity) for 5 minutes even when the window has focus. * * @since 3.8.0 * @access private * * @return {void} */ function checkUserActivity() { var lastActive = settings.userActivity ? time() - settings.userActivity : 0; // Throttle down when no mouse or keyboard activity for 5 minutes. if ( lastActive > 300000 && settings.hasFocus ) { blurred(); } // Suspend after 10 minutes of inactivity when suspending is enabled. // Always suspend after 60 minutes of inactivity. This will release the post lock, etc. if ( ( settings.suspendEnabled && lastActive > 600000 ) || lastActive > 3600000 ) { suspend(); } if ( ! settings.userActivityEvents ) { $document.on( 'mouseover.wp-heartbeat-active keyup.wp-heartbeat-active touchend.wp-heartbeat-active', function() { userIsActive(); }); $('iframe').each( function( i, frame ) { if ( isLocalFrame( frame ) ) { $( frame.contentWindow ).on( 'mouseover.wp-heartbeat-active keyup.wp-heartbeat-active touchend.wp-heartbeat-active', function() { userIsActive(); }); } }); settings.userActivityEvents = true; } } // Public methods. /** * Checks whether the window (or any local iframe in it) has focus, or the user * is active. * * @since 3.6.0 * @memberOf wp.heartbeat.prototype * * @return {boolean} True if the window or the user is active. */ function hasFocus() { return settings.hasFocus; } /** * Checks whether there is a connection error. * * @since 3.6.0 * * @memberOf wp.heartbeat.prototype * * @return {boolean} True if a connection error was found. */ function hasConnectionError() { return settings.connectionError; } /** * Connects as soon as possible regardless of 'hasFocus' state. * * Will not open two concurrent connections. If a connection is in progress, * will connect again immediately after the current connection completes. * * @since 3.8.0 * * @memberOf wp.heartbeat.prototype * * @return {void} */ function connectNow() { settings.lastTick = 0; scheduleNextTick(); } /** * Disables suspending. * * Should be used only when Heartbeat is performing critical tasks like * autosave, post-locking, etc. Using this on many screens may overload * the user's hosting account if several browser windows/tabs are left open * for a long time. * * @since 3.8.0 * * @memberOf wp.heartbeat.prototype * * @return {void} */ function disableSuspend() { settings.suspendEnabled = false; } /** * Gets/Sets the interval. * * When setting to 'fast' or 5, the interval is 5 seconds for the next 30 ticks * (for 2 minutes and 30 seconds) by default. In this case the number of 'ticks' * can be passed as second argument. If the window doesn't have focus, * the interval slows down to 2 minutes. * * @since 3.6.0 * * @memberOf wp.heartbeat.prototype * * @param {string|number} speed Interval: 'fast' or integer between 1 and 3600 (seconds). * Fast equals 5. * @param {number} ticks Tells how many ticks before the interval reverts back. * Value must be between 1 and 30. Used with speed = 'fast' or 5. * * @return {number} Current interval in seconds. */ function interval( speed, ticks ) { var newInterval, oldInterval = settings.tempInterval ? settings.tempInterval : settings.mainInterval; if ( speed ) { if ( 'fast' === speed ) { // Special case, see below. newInterval = 5000; } else if ( 'long-polling' === speed ) { // Allow long polling (experimental). settings.mainInterval = 0; return 0; } else { speed = parseInt( speed, 10 ); if ( speed >= 1 && speed <= 3600 ) { newInterval = speed * 1000; } else { newInterval = settings.originalInterval; } } if ( settings.minimalInterval && newInterval < settings.minimalInterval ) { newInterval = settings.minimalInterval; } // Special case, runs for a number of ticks then reverts to the previous interval. if ( 5000 === newInterval ) { ticks = parseInt( ticks, 10 ) || 30; ticks = ticks < 1 || ticks > 30 ? 30 : ticks; settings.countdown = ticks; settings.tempInterval = newInterval; } else { settings.countdown = 0; settings.tempInterval = 0; settings.mainInterval = newInterval; } /* * Change the next connection time if new interval has been set. * Will connect immediately if the time since the last connection * is greater than the new interval. */ if ( newInterval !== oldInterval ) { scheduleNextTick(); } } return settings.tempInterval ? settings.tempInterval / 1000 : settings.mainInterval / 1000; } /** * Enqueues data to send with the next XHR. * * As the data is send asynchronously, this function doesn't return the XHR * response. To see the response, use the custom jQuery event 'heartbeat-tick' * on the document, example: * $(document).on( 'heartbeat-tick.myname', function( event, data, textStatus, jqXHR ) { * // code * }); * If the same 'handle' is used more than once, the data is not overwritten when * the third argument is 'true'. Use `wp.heartbeat.isQueued('handle')` to see if * any data is already queued for that handle. * * @since 3.6.0 * * @memberOf wp.heartbeat.prototype * * @param {string} handle Unique handle for the data, used in PHP to * receive the data. * @param {*} data The data to send. * @param {boolean} noOverwrite Whether to overwrite existing data in the queue. * * @return {boolean} True if the data was queued. */ function enqueue( handle, data, noOverwrite ) { if ( handle ) { if ( noOverwrite && this.isQueued( handle ) ) { return false; } settings.queue[handle] = data; return true; } return false; } /** * Checks if data with a particular handle is queued. * * @since 3.6.0 * * @param {string} handle The handle for the data. * * @return {boolean} True if the data is queued with this handle. */ function isQueued( handle ) { if ( handle ) { return settings.queue.hasOwnProperty( handle ); } } /** * Removes data with a particular handle from the queue. * * @since 3.7.0 * * @memberOf wp.heartbeat.prototype * * @param {string} handle The handle for the data. * * @return {void} */ function dequeue( handle ) { if ( handle ) { delete settings.queue[handle]; } } /** * Gets data that was enqueued with a particular handle. * * @since 3.7.0 * * @memberOf wp.heartbeat.prototype * * @param {string} handle The handle for the data. * * @return {*} The data or undefined. */ function getQueuedItem( handle ) { if ( handle ) { return this.isQueued( handle ) ? settings.queue[handle] : undefined; } } initialize(); // Expose public methods. return { hasFocus: hasFocus, connectNow: connectNow, disableSuspend: disableSuspend, interval: interval, hasConnectionError: hasConnectionError, enqueue: enqueue, dequeue: dequeue, isQueued: isQueued, getQueuedItem: getQueuedItem }; }; /** * Ensure the global `wp` object exists. * * @namespace wp */ window.wp = window.wp || {}; /** * Contains the Heartbeat API. * * @namespace wp.heartbeat * @type {Heartbeat} */ window.wp.heartbeat = new Heartbeat(); }( jQuery, window ));
Save