Changes to the File System in 4.0.5+ (Affects themes, custom blocks and more) > - IP.Board (IPB) News
Kanał Rss Kanał Rss
Kanał Atom Kanał Atom

Changes to the File System in 4.0.5+ (Affects themes, custom blocks and more)

wersja drukowalna wersja Microsoft Word wersja HTML

For the IPS4.0.5 release, we changed how files are stored and loaded within the suite. Previously we stored the entire URL which was convenient but it made it problematic when you moved your community or tried to move images to another system such as Amazon S3.

From 4.0.5 onwards, just the container and file name is stored in the database. This is much better for the database as it means you do not need to update your database when you change your URL and it's easier to move the files as there are no database changes to update.
However, it does mean that you need to change how you display images in many cases.

For example, if you had something like this:


You'll notice that now it is just a broken image. You can use the new {file} tag to display it, like this:

<strong>{file="$member->group['icon']" extension="core_Theme"}</strong>

This will now display correctly. The extension parameter is mapped to the FileStorage extension found in /applications/{app}/extensions/core/FileStorage.

So, for example, if you are managing gallery Images, the extension is gallery_Images. If you're managing Pages records, the extension is cms_Records.

When writing code, you will need to be mindful of the changes. From IPS4.0.5 on newer, you will need to use code similar to this below:

# Create and save (this is largely the same)
$file = IPSFile::create( 'core_Theme', 'file.txt', $contents );
# Calling (string) on $file now returns just the container/file.txt e.g. (monthly_04_2015/file.txt)
IPSDb::i()->insert( 'table', array( 'url' => (string) $file ) );

# Load and show
$row = IPSDb::i()->select( '*', 'table', array( 'file=?', 'file.txt' ) );
# We now have the container/file.txt, but we need the full URL
$url = IPSFile::get( 'app_Extension', $row['url'] )->url;
print "<a href='{$url}'>";

The most important part to keep in mind is that (string) $file will now store just container/file.txt and you need to call IPSFile::get( 'app_Extension', $row['url'] )->url to get the full URL.

czw, 01 wrzesień 2016