WordPress.org

Ready to get started?Download WordPress

Forums

WP Publication Archive
display filesize (2 posts)

  1. LLvS
    Member
    Posted 2 years ago #

    I want to display my downloads other than it's in the original code, so I missed the filesize, so I added a new function to the plugin, maybe it will help you. (You have to make a copy of the plugin to not overwrite it on updates.) This will only work correct if your are only using internal documents.

    open class.publication-markup.php and add

    public function get_the_reallink() {
    		$uri = apply_filters( 'wpa-uri', $this->uri, $this->ID );
    		$uri = str_replace('|', '://', $uri);
    		return $uri;
    	}
    
    	public function get_the_size() {
    		clearstatcaches;
    		$uri = $this->get_the_reallink();
    		$uri = str_replace(get_option('home'), $_SERVER['DOCUMENT_ROOT'], $uri, $count);
    		if ($count = 0) {
    			$uri = str_replace(get_option('home'), $_SERVER['DOCUMENT_ROOT'], $uri);
    		}
    		return $this->format_bytes(filesize($uri));
    	}
    
    	private function format_bytes($a_bytes) {
    		if ($a_bytes < 1024) {
            	return number_format ($a_bytes , 2, ',', '.') .' B';
        	} elseif ($a_bytes < 1048576) {
            	return number_format (round($a_bytes / 1024, 2) , 2, ',', '.') .' KiB';
        	} elseif ($a_bytes < 1073741824) {
            	return number_format (round($a_bytes / 1048576, 2) , 2, ',', '.') . ' MiB';
        	} else {
            	return number_format (round($a_bytes / 1073741824, 2) , 2, ',', '.') . ' GiB';
        	}
    	}

    open class.wp-publication-archive.php and edit the function shortcode_handler to display the filesize

  2. Eric Mann
    Member
    Plugin Author

    Posted 2 years ago #

    Please submit your changes as a patch, or fork the plugin on GitHub (https://github.com/ericmann/WP-Publication-Archive) and submit a pull request so I can include this functionality.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic