Remove empty elements. self::$dependency_api_data = array_filter( self::$dependency_api_data ); set_site_transient( 'wp_plugin_dependencies_plugin_data', self::$dependency_api_data, 0 ); return self::$dependency_api_data; } /** * Gets plugin directory names. * * @since 6.5.0 * * @return array An array of plugin directory names. */ protected static function get_plugin_dirnames() { if ( is_array( self::$plugin_dirnames ) ) { return self::$plugin_dirnames; } self::$plugin_dirnames = array(); $plugin_files = array_keys( self::get_plugins() ); foreach ( $plugin_files as $plugin_file ) { $slug = self::convert_to_slug( $plugin_file ); self::$plugin_dirnames[ $slug ] = $plugin_file; } return self::$plugin_dirnames; } /** * Gets circular dependency data. * * @since 6.5.0 * * @return array[] An array of circular dependency pairings. */ protected static function get_circular_dependencies() { if ( is_array( self::$circular_dependencies_pairs ) ) { return self::$circular_dependencies_pairs; } if ( null === self::$dependencies ) { return array(); } self::$circular_dependencies_slugs = array(); self::$circular_dependencies_pairs = array(); foreach ( self::$dependencies as $dependent => $dependencies ) { /* * $dependent is in 'a/a.php' format. Dependencies are stored as slugs, i.e. 'a'. * * Convert $dependent to slug format for checking. */ $dependent_slug = self::convert_to_slug( $dependent ); self::$circular_dependencies_pairs = array_merge( self::$circular_dependencies_pairs, self::check_for_circular_dependencies( array( $dependent_slug ), $dependencies ) ); } return self::$circular_dependencies_pairs; } /** * Checks for circular dependencies. * * @since 6.5.0 * * @param array $dependents Array of dependent plugins. * @param array $dependencies Array of plugins dependencies. * @return array A circular dependency pairing, or an empty array if none exists. */ protected static function check_for_circular_dependencies( $dependents, $dependencies ) { $circular_dependencies_pairs = array(); // Check for a self-dependency. $dependents_location_in_its_own_dependencies = array_intersect( $dependents, $dependencies ); if ( ! empty( $dependents_location_in_its_own_dependencies ) ) { foreach ( $dependents_location_in_its_own_dependencies as $self_dependency ) { self::$circular_dependencies_slugs[] = $self_dependency; $circular_dependencies_pairs[] = array( $self_dependency, $self_dependency ); // No need to check for itself again. unset( $dependencies[ array_search( $self_dependency, $dependencies, true ) ] ); } } /* * Check each dependency to see: * 1. If it has dependencies. * 2. If its list of dependencies includes one of its own dependents. */ foreach ( $dependencies as $dependency ) { // Check if the dependency is also a dependent. $dependency_location_in_dependents = array_search( $dependency, self::$dependent_slugs, true ); if ( false !== $dependency_location_in_dependents ) { $dependencies_of_the_dependency = self::$dependencies[ $dependency_location_in_dependents ]; foreach ( $dependents as $dependent ) { // Check if its dependencies includes one of its own dependents. $dependent_location_in_dependency_dependencies = array_search( $dependent, $dependencies_of_the_dependency, true ); if ( false !== $dependent_location_in_dependency_dependencies ) { self::$circular_dependencies_slugs[] = $dependent; self::$circular_dependencies_slugs[] = $dependency; $circular_dependencies_pairs[] = array( $dependent, $dependency ); // Remove the dependent from its dependency's dependencies. unset( $dependencies_of_the_dependency[ $dependent_location_in_dependency_dependencies ] ); } } $dependents[] = $dependency; /* * Now check the dependencies of the dependency's dependencies for the dependent. * * Yes, that does make sense. */ $circular_dependencies_pairs = array_merge( $circular_dependencies_pairs, self::check_for_circular_dependencies( $dependents, array_unique( $dependencies_of_the_dependency ) ) ); } } return $circular_dependencies_pairs; } /** * Converts a plugin filepath to a slug. * * @since 6.5.0 * * @param string $plugin_file The plugin's filepath, relative to the plugins directory. * @return string The plugin's slug. */ protected static function convert_to_slug( $plugin_file ) { if ( 'hello.php' === $plugin_file ) { return 'hello-dolly'; } return str_contains( $plugin_file, '/' ) ? dirname( $plugin_file ) : str_replace( '.php', '', $plugin_file ); } } urn $this->recrawlPostManually($urlTuple->saved_post_id); // Get the errors from the post saver so that we can use them later. $this->setErrors($postSaver->getErrors()); return null; } } // If saved, delete. if($urlTuple) Factory::databaseService()->deleteUrl($urlTuple->id); // Now, save the URL $urlId = Factory::databaseService()->addUrl($siteId, $postUrl, $thumbnailUrl, $categoryId); // Define the required variables. These variables will be changed by savePost function. $nextPageUrl = null; $nextPageUrls = null; $draftPostId = null; $postId = null; $finished = false; while(!$finished) { $postId = $postSaver->savePost($siteId, $settings, $urlId, false, $nextPageUrl, $nextPageUrls, $postId); $nextPageUrl = $postSaver->getNextPageUrl(); $nextPageUrls = $postSaver->getNextPageUrls(); if(!$nextPageUrl || !$postId) $finished = true; } // var_dump("Saving the post is finished. Post ID is "); // var_dump($postId); // Get the errors from the post saver so that we can use them later. $this->setErrors($postSaver->getErrors()); return $postId; } /** * Recrawl a post manually by its post ID * * @param int $postId ID of the post to be recrawled * @return null|int ID of the post or null if there was something wrong */ public function recrawlPostManually($postId) { if(!$postId || $postId < 1) return null; $urlTuple = Factory::databaseService()->getUrlByPostId($postId); if(!$urlTuple) return null; // Define the required variables. These variables will be changed by savePost method. $siteId = $urlTuple->post_id; $nextPageUrl = null; $nextPageUrls = null; $draftPostId = null; $settings = get_post_meta($siteId); $postSaver = new PostSaver(); $postSaver->setIsRecrawl(true); $finished = false; while(!$finished) { $postId = $postSaver->savePost($siteId, $settings, $urlTuple->id, false, $nextPageUrl, $nextPageUrls, $postId); $nextPageUrl = $postSaver->getNextPageUrl(); $nextPageUrls = $postSaver->getNextPageUrls(); if(!$nextPageUrl || !$postId) $finished = true; } // var_dump("Recrawling the post is finished. Post ID is "); // var_dump($postId); // Get the errors from the post saver so that we can use them later. $this->setErrors($postSaver->getErrors()); $this->isRecrawled = true; return $postId; } /** * Get URL types to be shown as options in a select element. * @return array URL types as key,value pairs */ private function getUrlTypes() { return [ "url_type_queue" => _wpcc("In Queue"), "url_type_saved" => _wpcc("Already Saved"), "url_type_all" => _wpcc("All") ]; } }