GIF89a=( õ' 7IAXKgNgYvYx\%wh…hŽth%ˆs%—x¨}9®Œ©€&©‰%¶†(¹–.¹5·œD¹&Çš)ÇŸ5ǘ;Í£*È¡&Õ²)ׯ7×µ<Ñ»4ï°3ø‘HÖ§KͯT÷¨Yÿšqÿ»qÿÔFØ !ù ' !ÿ NETSCAPE2.0 , =( þÀ“pH,È¤rÉl:ŸÐ¨tJ­Z¯Ø¬vËíz¿à°xL.›Ïè´zÍn»ßð¸|N¯Ûïø¼~Ïïûÿ€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§gª«ªE¯°¨¬ª±²Œ¹º¹E¾­”´ÂB¶¯ §Åȸ»ÑD¾¿Á•ÄÅ®° ÝH¾ÒLÀÆDÙ«D¶BÝïðÀ¾DÑÑÔTÌÍíH òGö¨A RÎڐ |¥ ٭&ºìE8œ¹kGÔAÞpx­a¶­ã R2XB®åE8I€Õ6Xî:vT)äžþÀq¦è³¥ì仕F~%xñ  4#ZÔ‰O|-4Bs‘X:= QÉ œš lºÒyXJŠGȦ|s hÏíK–3l7·B|¥$'7Jީܪ‰‡àá”Dæn=Pƒ ¤Òëí‰`䌨ljóá¯Éüv>á–Á¼5 ½.69ûϸd«­ºÀûnlv©‹ªîf{¬ÜãPbŸ  l5‘ޝpß ´ ˜3aÅùäI«O’ý·‘áÞ‡˜¾Æ‚ÙÏiÇÿ‹Àƒ #öó)pâš Þ½ ‘Ý{ó)vmÞü%D~ 6f s}ŃƒDØW Eþ`‡þ À…L8xá†ç˜{)x`X/> Ì}mø‚–RØ‘*|`D=‚Ø_ ^ð5 !_…'aä“OÚ—7âcð`D”Cx`ÝÂ¥ä‹éY¹—F¼¤¥Š?¡Õ™ n@`} lď’ÄÉ@4>ñd œ à‘vÒxNÃ×™@žd=ˆgsžG±æ ´²æud &p8Qñ)ˆ«lXD©øÜéAžHìySun jª×k*D¤LH] †¦§C™Jä–´Xb~ʪwStŽ6K,°£qÁœ:9ت:¨þªl¨@¡`‚ûÚ ».Û¬¯t‹ÆSÉ[:°=Š‹„‘Nåû”Ìî{¿ÂA ‡Rà›ÀÙ6úë°Ÿð0Ä_ ½;ÃϱîÉì^ÇÛÇ#Ëë¼ôº!±Ä˜íUîÅÇ;0L1óÁµö«p% AÀºU̬ݵ¼á%霼€‡¯Á~`ÏG¯»À× ­²± =4ªnpð3¾¤³¯­ü¾¦îuÙuµÙ®|%2ÊIÿür¦#0·ÔJ``8È@S@5ê¢ ö×Þ^`8EÜ]ý.뜃Âç 7 ú ȉÞj œ½Dç zý¸iþœÑÙûÄë!ˆÞÀl§Ïw‹*DçI€nEX¯¬¼ &A¬Go¼QföõFç°¯;é¦÷îŽêJ°îúôF5¡ÌQ|îúöXªæ»TÁÏyñêï]ê² o óÎC=öõ›ÒÓPB@ D×½œä(>èCÂxŽ`±«Ÿ–JЀ»Û á¤±p+eE0`ëŽ`A Ú/NE€Ø†À9‚@¤à H½7”à‡%B‰`Àl*ƒó‘–‡8 2ñ%¸ —€:Ù1Á‰E¸àux%nP1ð!‘ðC)¾P81lÑɸF#ˆ€{´âé°ÈB„0>±û °b¡Š´±O‚3È–Ù()yRpbµ¨E.Z‘D8ÊH@% òŒx+%Ù˜Æcü »¸˜fõ¬b·d`Fê™8èXH"ÉÈ-±|1Ô6iI, 2““¬$+](A*jÐ QTÂo‰.ÛU슬Œã„Ž`¯SN¡–¶Äåyše¯ª’­¬‚´b¦Éož œ)åyâ@Ì®3 ÎtT̉°&Ø+žLÀf"Ø-|žçÔ>‡Ðv¦Ðžì\‚ Q1)Ž@Žh#aP72”ˆ™¨$‚ !ù " , =( …7IAXG]KgNgYvYxR"k\%w]'}hŽth%ˆg+ˆs%—r.—m3šx3˜x¨}9®€&©€+¨‡7§‰%¶†(¹–.¹œD¹&ǘ;Í•&ײ)×»4ïÌ6ò§KÍ þ@‘pH,È¤rÉl:ŸÐ¨tJ­Z¯Ø¬vËíz¿à°xL.›Ïè´zÍn»ßð¸|N¯Ûïø¼~Ïïûÿ€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§g «¬ E ±± ¨­¶°ººE Á´”·®C¬²§Ç¶Œ»ÓDÃÕƷ¯Ê±H½ºM×ÁGÚ¬D¶BËÁ½î½DÓôTÏÛßîG»ôõC×CÌ l&âž:'òtU³6ɹ#·Ø)€'Ü.6±&ëÍÈ» K(8p0N?!æ2"ÛˆNIJX>R¼ÐO‚M '¡¨2¸*Ÿþ>#n↠å@‚<[:¡Iïf’ ¤TÚ˘CdbÜÙ“[«ŽEú5MBo¤×@€`@„€Êt W-3 ¶Ÿ¡BíêäjIÝ…Eò9[T…$íêﯧ„…•s»Óȳ¹€ÅÚdc®UUρ#±Ùïldj?´í¼²`\ŽÁðÞu|3'ÖŒ]ë6 ¶S#²‡˜FKLÈ *N E´‘áäŠ$˜›eÄYD„ºq«.è촁ƒs \-ÔjA 9²õ÷å- üúM[Âx(ís÷ì®x€|í¡Ù’p¦‚ ŽkÛTÇDpE@WÜ ²Ç]kŠ1¨ þ€·Yb ÓÁ‰l°*n0 ç™—žzBdОu¾7ĉBl€â‰-ºx~|UåU‰  h*Hœ|e"#"?vpÄiŠe6^ˆ„+qâŠm8 #VÇá ‘å–ÄV„œ|Аè•m"сœn|@›U¶ÆÎž—Špb¥G¨ED”€±Úê2FÌIç? >Éxå Œ± ¡¤„%‘žjŸ‘ꄯ<Ìaà9ijÐ2˜D¦È&›†Z`‚å]wþ¼Â:ç6àB¤7eFJ|õÒ§Õ,¨äàFÇ®cS·Ê¶+B°,‘Þ˜ºNûãØ>PADÌHD¹æž«ÄÀnÌ¥}­#Ë’ë QÀÉSÌÂÇ2ÌXÀ{æk²lQÁ2«ÊðÀ¯w|2Í h‹ÄÂG€,m¾¶ë3ÐÙ6-´ÅE¬L°ÆIij*K½ÀÇqï`DwVÍQXœÚÔpeœ±¬Ñ q˜§Tœ½µƒ°Œìu Â<¶aØ*At¯lmEØ ü ôÛN[P1ÔÛ¦­±$ÜÆ@`ùåDpy¶yXvCAyåB`ŽD¶ 0QwG#¯ æš[^Äþ $ÀÓÝǦ{„L™[±úKÄgÌ;ï£S~¹ìGX.ôgoT.»åˆ°ùŸûù¡?1zö¦Ÿž:ÅgÁ|ìL¹ „®£œŠ‚à0œ]PÁ^p F<"•ç?!,ñ‡N4—…PÄ Á„ö¨Û:Tè@hÀ‹%táÿ:ø-žI<`þ‹p I….)^ 40D#p@ƒj4–؀:²‰1Øâr˜¼F2oW¼#Z†;$Q q” ‘ ÂK¦ñNl#29 !’F@¥Bh·ᏀL!—XFóLH‘Kh¤.«hE&JòG¨¥<™WN!€ÑÙÚˆY„@†>Œž19J" 2,/ &.GXB%ÌRÈ9B6¹W]’î×ÔW¥’IÎ$ ñ‹ÓŒE8YÆ ¼³™ñA5“à®Q.aŸB€&Ø©³ JÁ—! ¦t)K%tœ-¦JF bòNMxLôþ)ÐR¸Ð™‘ èÝ6‘O!THÌ„HÛ ‰ !ù ) , =( …AXKgNgYvYxR"k\%wh…hŽh%ˆg+ˆs%—r.—x3˜x¨}9®€&©€+¨Œ,©‡7§‰%¶†(¹–.¹5·&Çš)ǘ;Í•&×£*Ȳ)ׯ7×»4ï°3øÌ6ò‘HÖ§KÍ»Hó¯T÷¨Yÿ»qÿÇhÿ þÀ”pH,È¤rÉl:ŸÐ¨tJ­Z¯Ø¬vËíz¿à°xL.›Ïè´zÍn»ßð¸|N¯Ûïø¼~Ïïûÿ€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§g ª« E$±²¨ª­ · °²½$E$ÂÕ««D· Í ¿¦Ç¶¸ÌŒ¾³CÃÅÆ E ééH½MÛÂGâªD­ çBêêϾD²ÒaÀà€Š1r­ðÓ¤ ÔožzU!L˜C'¾yW½UGtäÇïÙllê0×àÂuGþ)AÀs[þ·xì ÁxO%ƒûX2ó—  P£n›R/¡ÑšHše+êDm?# —‘Ç£6¡8íJ¡ŸâDiäªM¥Ö„ôj“¬¹£5oQ7°- <‡ *´lãÓŒ2r/a!l)dÈ A™ÈE¢ôÔ͆…ð ;Ö˜c ¡%ß‚’Ùˆâ¸b½—pe~C"BíëÚHïeF2§æŠ8qb t_`urŠeü wÅu3êæPv§h•"ß`íÍxçLĹÜÖ3á  ~Öº“®›¸ÏMDfJÙ °„ÛµáWõ%§œ‚à©–‚X ÓØ)@®Ñ›Eþ´wëuÅSxb8y\mÖzœ¥§ZbºE—ÂLªÌw!y(>¡™wú=Ç|ÅÝs¢d €CÁW)HÜcC$€L Ä7„r.á\{)@ð` @ äXÈ$PD” `šaG:§æˆOˆ72EÐamn]ù"ŒcÊxÑŒ° &dR8`g«iÙŸLR!¦P …d’ä¡“¦ðÎTƒ¦ià|À _ ¥ Qi#¦Šg›Æ ›noMµ ›V ã£)p ç£ÎW…š=Âeªk§†j„ ´®1ß²sÉxéW«jšl|0¯B0Û, \jÛ´›6±¬¶C ÛíWþï|ëÙ‹¸ñzĸV {ì;Ýñn¼òVˆm³I¼³.Ðã¤PN¥ ²µ¼„µCã+¹ÍByî£Ñ¾HŸ›ëê 7ìYÆFTk¨SaoaY$Dµœìï¿Ã29RÈkt Çïfñ ÇÒ:ÀÐSp¹3ÇI¨â¥DZÄ ü9Ïýögñ½­uÔ*3)O‘˜Ö[_hv ,àî×Et Ÿé¶BH€ Õ[ü±64M@ÔSÌM7dÐl5-ÄÙU܍´©zߌ3Ô€3ž„ „ ¶ÛPô½5×g› êÚ˜kN„Ý…0Îj4€Ìë°“#{þÕ3S2çKÜ'ợlø¼Ú2K{° {Û¶?žm𸧠ËI¼nEò='êüóºè^üæÃ_Û=°óž‚ì#Oý¿Í'¡½áo..ÏYìnüñCœO±Áa¿¢Kô½o,üÄËbö²çºíï{ËC Ú— "”Ï{ËK ÍÒw„õ±Oz dÕ¨à:$ ƒô—«v»] A#ð «€¿šéz)Rx׿ˆ¥‚d``èw-îyÏf×K!ð€þ­Ð|ìPľ„=Ì`ý(f” 'Pa ¥ÐBJa%Ðâf§„%Š¡}FàáÝ×6>ÉäŠG"éŽè=ø!oа^FP¼Ø©Q„ÀCÙÁ`(Ž\ÄÝ® ©Â$<n@dÄ E#ììUÒI! ‚#lù‹`k¦ÐÇ'Rró’ZýNBÈMF Í[¤+‹ðɈ-áwj¨¥þ8¾rá ,VÂh„"|½œ=×G_¦Ñ™EØ 0i*%̲˜Æda0mV‚k¾)›;„&6 p>ÓjK “¦Ç# âDÂ:ûc?:R Ó¬fÞéI-Ì“•Ã<ä=™Ï7˜3œ¨˜c2ŒW ,ˆ”8(T™P‰F¡Jhç"‚ ; 403WebShell
403Webshell
Server IP : 172.67.177.218  /  Your IP : 216.73.216.195
Web Server : LiteSpeed
System : Linux premium229.web-hosting.com 4.18.0-553.45.1.lve.el8.x86_64 #1 SMP Wed Mar 26 12:08:09 UTC 2025 x86_64
User : akhalid ( 749)
PHP Version : 8.3.22
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /usr/src/litespeed-wp-plugin/6.5.3/litespeed-cache/src/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/src/litespeed-wp-plugin/6.5.3/litespeed-cache/src/crawler-map.cls.php
<?php

/**
 * The Crawler Sitemap Class
 *
 * @since      	1.1.0
 */

namespace LiteSpeed;

defined('WPINC') || exit();

class Crawler_Map extends Root
{
	const LOG_TAG = '🐞🗺️';

	const BM_MISS = 1;
	const BM_HIT = 2;
	const BM_BLACKLIST = 4;

	private $_home_url; // Used to simplify urls
	private $_tb;
	private $_tb_blacklist;
	private $__data;
	private $_conf_map_timeout;
	private $_urls = array();

	/**
	 * Instantiate the class
	 *
	 * @since 1.1.0
	 */
	public function __construct()
	{
		$this->_home_url = get_home_url();
		$this->__data = Data::cls();
		$this->_tb = $this->__data->tb('crawler');
		$this->_tb_blacklist = $this->__data->tb('crawler_blacklist');
		$this->_conf_map_timeout = $this->conf(Base::O_CRAWLER_MAP_TIMEOUT);
	}

	/**
	 * Save URLs crawl status into DB
	 *
	 * @since  3.0
	 * @access public
	 */
	public function save_map_status($list, $curr_crawler)
	{
		global $wpdb;
		Utility::compatibility();

		$total_crawler = count(Crawler::cls()->list_crawlers());
		$total_crawler_pos = $total_crawler - 1;

		// Replace current crawler's position
		$curr_crawler = (int) $curr_crawler;
		foreach ($list as $bit => $ids) {
			// $ids = [ id => [ url, code ], ... ]
			if (!$ids) {
				continue;
			}
			self::debug("Update map [crawler] $curr_crawler [bit] $bit [count] " . count($ids));

			// Update res first, then reason
			$right_pos = $total_crawler_pos - $curr_crawler;
			$sql_res = "CONCAT( LEFT( res, $curr_crawler ), '$bit', RIGHT( res, $right_pos ) )";

			$id_all = implode(',', array_map('intval', array_keys($ids)));

			$wpdb->query("UPDATE `$this->_tb` SET res = $sql_res WHERE id IN ( $id_all )");

			// Add blacklist
			if ($bit == 'B' || $bit == 'N') {
				$q = "SELECT a.id, a.url FROM `$this->_tb_blacklist` a LEFT JOIN `$this->_tb` b ON b.url=a.url WHERE b.id IN ( $id_all )";
				$existing = $wpdb->get_results($q, ARRAY_A);
				// Update current crawler status tag in existing blacklist
				if ($existing) {
					$count = $wpdb->query("UPDATE `$this->_tb_blacklist` SET res = $sql_res WHERE id IN ( " . implode(',', array_column($existing, 'id')) . ' )');
					self::debug('Update blacklist [count] ' . $count);
				}

				// Append new blacklist
				if (count($ids) > count($existing)) {
					$new_urls = array_diff(array_column($ids, 'url'), array_column($existing, 'url'));

					self::debug('Insert into blacklist [count] ' . count($new_urls));

					$q = "INSERT INTO `$this->_tb_blacklist` ( url, res, reason ) VALUES " . implode(',', array_fill(0, count($new_urls), '( %s, %s, %s )'));
					$data = array();
					$res = array_fill(0, $total_crawler, '-');
					$res[$curr_crawler] = $bit;
					$res = implode('', $res);
					$default_reason = $total_crawler > 1 ? str_repeat(',', $total_crawler - 1) : ''; // Pre-populate default reason value first, update later
					foreach ($new_urls as $url) {
						$data[] = $url;
						$data[] = $res;
						$data[] = $default_reason;
					}
					$wpdb->query($wpdb->prepare($q, $data));
				}
			}

			// Update sitemap reason w/ HTTP code
			$reason_array = array();
			foreach ($ids as $id => $v2) {
				$code = (int) $v2['code'];
				if (empty($reason_array[$code])) {
					$reason_array[$code] = array();
				}
				$reason_array[$code][] = (int) $id;
			}

			foreach ($reason_array as $code => $v2) {
				// Complement comma
				if ($curr_crawler) {
					$code = ',' . $code;
				}
				if ($curr_crawler < $total_crawler_pos) {
					$code .= ',';
				}

				$count = $wpdb->query(
					"UPDATE `$this->_tb` SET reason=CONCAT(SUBSTRING_INDEX(reason, ',', $curr_crawler), '$code', SUBSTRING_INDEX(reason, ',', -$right_pos)) WHERE id IN (" .
						implode(',', $v2) .
						')'
				);

				self::debug("Update map reason [code] $code [pos] left $curr_crawler right -$right_pos [count] $count");

				// Update blacklist reason
				if ($bit == 'B' || $bit == 'N') {
					$count = $wpdb->query(
						"UPDATE `$this->_tb_blacklist` a LEFT JOIN `$this->_tb` b ON b.url = a.url SET a.reason=CONCAT(SUBSTRING_INDEX(a.reason, ',', $curr_crawler), '$code', SUBSTRING_INDEX(a.reason, ',', -$right_pos)) WHERE b.id IN (" .
							implode(',', $v2) .
							')'
					);

					self::debug("Update blacklist [code] $code [pos] left $curr_crawler right -$right_pos [count] $count");
				}
			}
			// Reset list
			$list[$bit] = array();
		}

		return $list;
	}

	/**
	 * Add one record to blacklist
	 * NOTE: $id is sitemap table ID
	 *
	 * @since  3.0
	 * @access public
	 */
	public function blacklist_add($id)
	{
		global $wpdb;

		$id = (int) $id;

		// Build res&reason
		$total_crawler = count(Crawler::cls()->list_crawlers());
		$res = str_repeat('B', $total_crawler);
		$reason = implode(',', array_fill(0, $total_crawler, 'Man'));

		$row = $wpdb->get_row("SELECT a.url, b.id FROM `$this->_tb` a LEFT JOIN `$this->_tb_blacklist` b ON b.url = a.url WHERE a.id = '$id'", ARRAY_A);
		if (!$row) {
			self::debug('blacklist failed to add [id] ' . $id);
			return;
		}

		self::debug('Add to blacklist [url] ' . $row['url']);

		$q = "UPDATE `$this->_tb` SET res = %s, reason = %s WHERE id = %d";
		$wpdb->query($wpdb->prepare($q, array($res, $reason, $id)));

		if ($row['id']) {
			$q = "UPDATE `$this->_tb_blacklist` SET res = %s, reason = %s WHERE id = %d";
			$wpdb->query($wpdb->prepare($q, array($res, $reason, $row['id'])));
		} else {
			$q = "INSERT INTO `$this->_tb_blacklist` (url, res, reason) VALUES (%s, %s, %s)";
			$wpdb->query($wpdb->prepare($q, array($row['url'], $res, $reason)));
		}
	}

	/**
	 * Delete one record from blacklist
	 *
	 * @since  3.0
	 * @access public
	 */
	public function blacklist_del($id)
	{
		global $wpdb;
		if (!$this->__data->tb_exist('crawler_blacklist')) {
			return;
		}

		$id = (int) $id;
		self::debug('blacklist delete [id] ' . $id);

		$wpdb->query("UPDATE `$this->_tb` SET res=REPLACE(REPLACE(res, 'N', '-'), 'B', '-') WHERE url=(SELECT url FROM `$this->_tb_blacklist` WHERE id='$id')");
		$wpdb->query("DELETE FROM `$this->_tb_blacklist` WHERE id='$id'");
	}

	/**
	 * Empty blacklist
	 *
	 * @since  3.0
	 * @access public
	 */
	public function blacklist_empty()
	{
		global $wpdb;

		if (!$this->__data->tb_exist('crawler_blacklist')) {
			return;
		}

		self::debug('Truncate blacklist');
		$wpdb->query("UPDATE `$this->_tb` SET res=REPLACE(REPLACE(res, 'N', '-'), 'B', '-')");
		$wpdb->query("TRUNCATE `$this->_tb_blacklist`");
	}

	/**
	 * List blacklist
	 *
	 * @since  3.0
	 * @access public
	 */
	public function list_blacklist($limit = false, $offset = false)
	{
		global $wpdb;

		if (!$this->__data->tb_exist('crawler_blacklist')) {
			return array();
		}

		$q = "SELECT * FROM `$this->_tb_blacklist` ORDER BY id DESC";

		if ($limit !== false) {
			if ($offset === false) {
				$total = $this->count_blacklist();
				$offset = Utility::pagination($total, $limit, true);
			}
			$q .= ' LIMIT %d, %d';
			$q = $wpdb->prepare($q, $offset, $limit);
		}
		return $wpdb->get_results($q, ARRAY_A);
	}

	/**
	 * Count blacklist
	 */
	public function count_blacklist()
	{
		global $wpdb;

		if (!$this->__data->tb_exist('crawler_blacklist')) {
			return false;
		}

		$q = "SELECT COUNT(*) FROM `$this->_tb_blacklist`";
		return $wpdb->get_var($q);
	}

	/**
	 * Empty sitemap
	 *
	 * @since  3.0
	 * @access public
	 */
	public function empty_map()
	{
		Data::cls()->tb_del('crawler');

		$msg = __('Sitemap cleaned successfully', 'litespeed-cache');
		Admin_Display::succeed($msg);
	}

	/**
	 * List generated sitemap
	 *
	 * @since  3.0
	 * @access public
	 */
	public function list_map($limit, $offset = false)
	{
		global $wpdb;

		if (!$this->__data->tb_exist('crawler')) {
			return array();
		}

		if ($offset === false) {
			$total = $this->count_map();
			$offset = Utility::pagination($total, $limit, true);
		}

		$type = Router::verify_type();

		$where = '';
		if (!empty($_POST['kw'])) {
			$q = "SELECT * FROM `$this->_tb` WHERE url LIKE %s";
			if ($type == 'hit') {
				$q .= " AND res LIKE '%H%'";
			}
			if ($type == 'miss') {
				$q .= " AND res LIKE '%M%'";
			}
			if ($type == 'blacklisted') {
				$q .= " AND res LIKE '%B%'";
			}
			$q .= ' ORDER BY id LIMIT %d, %d';
			$where = '%' . $wpdb->esc_like($_POST['kw']) . '%';
			return $wpdb->get_results($wpdb->prepare($q, $where, $offset, $limit), ARRAY_A);
		}

		$q = "SELECT * FROM `$this->_tb`";
		if ($type == 'hit') {
			$q .= " WHERE res LIKE '%H%'";
		}
		if ($type == 'miss') {
			$q .= " WHERE res LIKE '%M%'";
		}
		if ($type == 'blacklisted') {
			$q .= " WHERE res LIKE '%B%'";
		}
		$q .= ' ORDER BY id LIMIT %d, %d';
		// self::debug("q=$q offset=$offset, limit=$limit");
		return $wpdb->get_results($wpdb->prepare($q, $offset, $limit), ARRAY_A);
	}

	/**
	 * Count sitemap
	 */
	public function count_map()
	{
		global $wpdb;

		if (!$this->__data->tb_exist('crawler')) {
			return false;
		}

		$q = "SELECT COUNT(*) FROM `$this->_tb`";

		$type = Router::verify_type();
		if ($type == 'hit') {
			$q .= " WHERE res LIKE '%H%'";
		}
		if ($type == 'miss') {
			$q .= " WHERE res LIKE '%M%'";
		}
		if ($type == 'blacklisted') {
			$q .= " WHERE res LIKE '%B%'";
		}

		return $wpdb->get_var($q);
	}

	/**
	 * Generate sitemap
	 *
	 * @since    1.1.0
	 * @access public
	 */
	public function gen($manual = false)
	{
		$count = $this->_gen();

		if (!$count) {
			Admin_Display::error(__('No valid sitemap parsed for crawler.', 'litespeed-cache'));
			return;
		}

		if (!defined('DOING_CRON') && $manual) {
			$msg = sprintf(__('Sitemap created successfully: %d items', 'litespeed-cache'), $count);
			Admin_Display::succeed($msg);
		}
	}

	/**
	 * Generate the sitemap
	 *
	 * @since    1.1.0
	 * @access private
	 */
	private function _gen()
	{
		global $wpdb;

		if (!$this->__data->tb_exist('crawler')) {
			$this->__data->tb_create('crawler');
		}

		if (!$this->__data->tb_exist('crawler_blacklist')) {
			$this->__data->tb_create('crawler_blacklist');
		}

		// use custom sitemap
		if (!($sitemap = $this->conf(Base::O_CRAWLER_SITEMAP))) {
			return false;
		}

		$offset = strlen($this->_home_url);
		$sitemap = Utility::sanitize_lines($sitemap);

		try {
			foreach ($sitemap as $this_map) {
				$this->_parse($this_map);
			}
		} catch (\Exception $e) {
			self::debug('❌ failed to parse custom sitemap: ' . $e->getMessage());
		}

		if (is_array($this->_urls) && !empty($this->_urls)) {
			if ($this->conf(Base::O_CRAWLER_DROP_DOMAIN)) {
				foreach ($this->_urls as $k => $v) {
					if (stripos($v, $this->_home_url) !== 0) {
						unset($this->_urls[$k]);
						continue;
					}
					$this->_urls[$k] = substr($v, $offset);
				}
			}

			$this->_urls = array_unique($this->_urls);
		}

		self::debug('Truncate sitemap');
		$wpdb->query("TRUNCATE `$this->_tb`");

		self::debug('Generate sitemap');

		// Filter URLs in blacklist
		$blacklist = $this->list_blacklist();

		$full_blacklisted = array();
		$partial_blacklisted = array();
		foreach ($blacklist as $v) {
			if (strpos($v['res'], '-') === false) {
				// Full blacklisted
				$full_blacklisted[] = $v['url'];
			} else {
				// Replace existing reason
				$v['reason'] = explode(',', $v['reason']);
				$v['reason'] = array_map(function ($element) {
					return $element ? 'Existed' : '';
				}, $v['reason']);
				$v['reason'] = implode(',', $v['reason']);
				$partial_blacklisted[$v['url']] = array(
					'res' => $v['res'],
					'reason' => $v['reason'],
				);
			}
		}

		// Drop all blacklisted URLs
		$this->_urls = array_diff($this->_urls, $full_blacklisted);

		// Default res & reason
		$crawler_count = count(Crawler::cls()->list_crawlers());
		$default_res = str_repeat('-', $crawler_count);
		$default_reason = $crawler_count > 1 ? str_repeat(',', $crawler_count - 1) : '';

		$data = array();
		foreach ($this->_urls as $url) {
			$data[] = $url;
			$data[] = array_key_exists($url, $partial_blacklisted) ? $partial_blacklisted[$url]['res'] : $default_res;
			$data[] = array_key_exists($url, $partial_blacklisted) ? $partial_blacklisted[$url]['reason'] : $default_reason;
		}

		foreach (array_chunk($data, 300) as $data2) {
			$this->_save($data2);
		}

		// Reset crawler
		Crawler::cls()->reset_pos();

		return count($this->_urls);
	}

	/**
	 * Save data to table
	 *
	 * @since 3.0
	 * @access private
	 */
	private function _save($data, $fields = 'url,res,reason')
	{
		global $wpdb;

		if (empty($data)) {
			return;
		}

		$q = "INSERT INTO `$this->_tb` ( $fields ) VALUES ";

		// Add placeholder
		$q .= Utility::chunk_placeholder($data, $fields);

		// Store data
		$wpdb->query($wpdb->prepare($q, $data));
	}

	/**
	 * Parse custom sitemap and return urls
	 *
	 * @since    1.1.1
	 * @access private
	 */
	private function _parse($sitemap)
	{
		/**
		 * Read via wp func to avoid allow_url_fopen = off
		 * @since  2.2.7
		 */
		$response = wp_remote_get($sitemap, array('timeout' => $this->_conf_map_timeout, 'sslverify' => false));
		if (is_wp_error($response)) {
			$error_message = $response->get_error_message();
			self::debug('failed to read sitemap: ' . $error_message);
			throw new \Exception('Failed to remote read ' . $sitemap);
		}

		$xml_object = simplexml_load_string($response['body'], null, LIBXML_NOCDATA);
		if (!$xml_object) {
			if ($this->_urls) {
				return;
			}
			throw new \Exception('Failed to parse xml ' . $sitemap);
		}

		// start parsing
		$xml_array = (array) $xml_object;
		if (!empty($xml_array['sitemap'])) {
			// parse sitemap set
			if (is_object($xml_array['sitemap'])) {
				$xml_array['sitemap'] = (array) $xml_array['sitemap'];
			}

			if (!empty($xml_array['sitemap']['loc'])) {
				// is single sitemap
				$this->_parse($xml_array['sitemap']['loc']);
			} else {
				// parse multiple sitemaps
				foreach ($xml_array['sitemap'] as $val) {
					$val = (array) $val;
					if (!empty($val['loc'])) {
						$this->_parse($val['loc']); // recursive parse sitemap
					}
				}
			}
		} elseif (!empty($xml_array['url'])) {
			// parse url set
			if (is_object($xml_array['url'])) {
				$xml_array['url'] = (array) $xml_array['url'];
			}
			// if only 1 element
			if (!empty($xml_array['url']['loc'])) {
				$this->_urls[] = $xml_array['url']['loc'];
			} else {
				foreach ($xml_array['url'] as $val) {
					$val = (array) $val;
					if (!empty($val['loc'])) {
						$this->_urls[] = $val['loc'];
					}
				}
			}
		}
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit