Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter Max Ziebell

    (@max-ziebell)

    found it:

    -media XYZ

    is there a documentation for extending the search?

    Plugin Author Brady Vercher

    (@bradyvercher)

    All of the search modifiers are implemented as self-contained filter callbacks. There isn’t any documentation, but you can see how the media search is implemented here.

    Thread Starter Max Ziebell

    (@max-ziebell)

    Yes thank you. Found that yesterday in the source and wrote my own modifier in minutes. Now it pulls filelinks from our internal WebDav-School-Server… and runs the exposed URL through an authentication Proxy … great stuff!

    Cheers°

    Plugin Author Brady Vercher

    (@bradyvercher)

    Awesome! That sounds pretty cool. Glad to hear you were able to get it worked out.

    Cheers,
    Brady

    Thread Starter Max Ziebell

    (@max-ziebell)

    In your Plugin:
    It’s only so cool because you provided this plugin. Just had to register a recursive filesearch and paginate it. Now the teachers can link files from our webdav to certain users groups in the webpage (behind a login-gate).

    Additional PHP file in webroot (works as proxy):
    Then I return a URL through your plugin that runs through a PHP that determines if the requested path (actually not in any webroot) is valid and the logged in user has enough rights to download. Then I simply forward the file via PHP (open file… write to browser).

    Thread Starter Max Ziebell

    (@max-ziebell)

    Here is the code …
    I am still changing things around and I stripped the particulars of our server. Please watch out for the parts with the capital letters. Hope this helps somebody! usage: -download {query}

    function bils_download_search( $results, $args ) {
    
    	// downloadsearch doesn't need paging, so if page arg is greater than one, abort.
    	// We also don't want to get files for queries less than two characters.
    	if ( intval( $args['page'] ) > 1 || strlen( $args['s'] ) < 2 ) {
    		wp_die( 0 );
    	}
    
    	$fileinfos = new RecursiveIteratorIterator(
    	    new FilesOnlyFilter(
    	        new VisibleOnlyFilter(
    	            new RecursiveDirectoryIterator(
    	                $PATH_TO_YOUR_FILEDIRECTORY,
    	                FilesystemIterator::SKIP_DOTS
    	                    | FilesystemIterator::UNIX_PATHS
    	            )
    	        )
    	    ),
    	    RecursiveIteratorIterator::LEAVES_ONLY,
    	    RecursiveIteratorIterator::CATCH_GET_CHILD
    	);
    
    	foreach ($fileinfos as $pathname => $fileinfo) {
    		$fpn = $fileinfos->getSubPathname();
    		if (stripos($fpn , $args['s'])!==false) {
    			$results[] = array(
    					'title'     => '/'.$fpn,
    					'permalink' => 'https://PATH-TO-YOUR-SERVER-OR.PROXY?f='.$fpn,
    					'info'      => 'download',
    			);
    		}
    	}
    
    	return $results;
    }
    add_filter( 'better_internal_link_search_modifier-download', 'bils_download_search', 10, 2 );
    
    class VisibleOnlyFilter extends RecursiveFilterIterator
    {
        public function accept()
        {
            $fileName = $this->getInnerIterator()->current()->getFileName();
            $firstChar = $fileName[0];
            return $firstChar !== '.';
        }
    }
    
    class FilesOnlyFilter extends RecursiveFilterIterator
    {
        public function accept()
        {
            $iterator = $this->getInnerIterator();
    
            // allow traversal
            if ($iterator->hasChildren()) {
                return true;
            }
    
            // filter entries, only allow true files
            return $iterator->current()->isFile();
        }
    }

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Search Media files’ is closed to new replies.