Changeset 13263 for trunk/src/bp-core/bp-core-attachments.php
- Timestamp:
- 03/15/2022 11:21:26 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/bp-core-attachments.php
r13215 r13263 1640 1640 1641 1641 /** 1642 * Returns a file's mime type. 1643 * 1644 * @since 10.2.0 1645 * 1646 * @param string $file Absolute path of a file or directory. 1647 * @return false|string False if the mime type is not supported by WordPress. 1648 * The mime type of a file or 'directory' for a directory. 1649 */ 1650 function bp_attachements_get_mime_type( $file = '' ) { 1651 $file_type = wp_check_filetype( $file, wp_get_mime_types() ); 1652 $file_mime = $file_type['type']; 1653 1654 if ( false === $file_mime && is_dir( $file ) ) { 1655 $file_mime = 'directory'; 1656 } 1657 1658 return $file_mime; 1659 } 1660 1661 /** 1662 * Returns a BP Attachments file object. 1663 * 1664 * @since 10.2.0 1665 * 1666 * @param SplFileInfo $file The SplFileInfo file object. 1667 * @return null|object Null if the file is not supported by WordPress. 1668 * A BP Attachments file object otherwise. 1669 */ 1670 function bp_attachments_get_file_object( SplFileInfo $file ) { 1671 $path = $file->getPathname(); 1672 $mime_type = bp_attachements_get_mime_type( $path ); 1673 1674 // Mime type not supported by WordPress. 1675 if ( false === $mime_type ) { 1676 return null; 1677 } 1678 1679 $_file = new stdClass(); 1680 1681 $_file->name = $file->getfilename(); 1682 $_file->path = $path; 1683 $_file->size = $file->getSize(); 1684 $_file->type = $file->getType(); 1685 $_file->mime_type = bp_attachements_get_mime_type( $_file->path ); 1686 $_file->last_modified = $file->getMTime(); 1687 $_file->latest_access_date = $file->getATime(); 1688 $_file->id = pathinfo( $_file->name, PATHINFO_FILENAME ); 1689 1690 return $_file; 1691 } 1692 1693 /** 1642 1694 * List the files of a directory. 1643 1695 * … … 1656 1708 1657 1709 foreach ( $iterator as $file ) { 1658 $_file = new stdClass(); 1659 1660 $_file->name = $file->getfilename(); 1661 $_file->path = $file->getPathname(); 1662 $_file->size = $file->getSize(); 1663 $_file->type = $file->getType(); 1664 $_file->mime_type = mime_content_type( $_file->path ); 1665 $_file->last_modified = $file->getMTime(); 1666 $_file->latest_access_date = $file->getATime(); 1667 $_file->id = pathinfo( $_file->name, PATHINFO_FILENAME ); 1668 $files[ $_file->id ] = $_file; 1710 $supported_file = bp_attachments_get_file_object( $file ); 1711 1712 if ( is_null( $supported_file) ) { 1713 continue; 1714 } 1715 1716 $files[ $supported_file->id ] = $supported_file; 1669 1717 } 1670 1718 … … 1693 1741 1694 1742 foreach ( $iterator as $file ) { 1695 $_file = new stdClass(); 1696 1697 $_file->name = $file->getfilename(); 1698 $_file->path = $file->getPathname(); 1699 $_file->size = $file->getSize(); 1700 $_file->type = $file->getType(); 1701 $_file->mime_type = mime_content_type( $_file->path ); 1702 $_file->last_modified = $file->getMTime(); 1703 $_file->latest_access_date = $file->getATime(); 1704 $_file->parent_dir_path = str_replace( '\\', '/', dirname( $_file->path ) ); 1705 $_file->parent_dir_url = str_replace( $basedir, $bp_upload['baseurl'], $_file->parent_dir_path ); 1706 $_file->id = pathinfo( $_file->name, PATHINFO_FILENAME ); 1743 $supported_file = bp_attachments_get_file_object( $file ); 1744 1745 if ( is_null( $supported_file) ) { 1746 continue; 1747 } 1748 1749 $supported_file->parent_dir_path = str_replace( '\\', '/', dirname( $supported_file->path ) ); 1750 $supported_file->parent_dir_url = str_replace( $basedir, $bp_upload['baseurl'], $supported_file->parent_dir_path ); 1707 1751 1708 1752 // Ensure URL is https if SSL is set/forced. 1709 1753 if ( is_ssl() ) { 1710 $ _file->parent_dir_url = str_replace( 'http://', 'https://', $_file->parent_dir_url );1711 } 1712 1713 $file_id = $ _file->id;1714 if ( $ _file->parent_dir_path !== $directory_path ) {1715 $file_id = trailingslashit( str_replace( trailingslashit( $directory_path ), '', $ _file->parent_dir_path ) ) . $file_id;1716 } 1717 1718 $files[ $file_id ] = $ _file;1754 $supported_file->parent_dir_url = str_replace( 'http://', 'https://', $supported_file->parent_dir_url ); 1755 } 1756 1757 $file_id = $supported_file->id; 1758 if ( $supported_file->parent_dir_path !== $directory_path ) { 1759 $file_id = trailingslashit( str_replace( trailingslashit( $directory_path ), '', $supported_file->parent_dir_path ) ) . $file_id; 1760 } 1761 1762 $files[ $file_id ] = $supported_file; 1719 1763 } 1720 1764
Note: See TracChangeset
for help on using the changeset viewer.