Relative Path of File in HTML block

Permalink 1 user found helpful
Hi,
I'm building a site that I'm going to move later. I have a ton of audio files uploaded to the file manager, and I want to code some of them into the HTML block audio tags directly, as they will play inline.

Problem is my site name will change when I move it, and then all the src URLs will die!

I know I can upload the files to a separate directory, and call them in the HTML like you do from a theme's image folder, but I want to do this from the file manager.

Any help?

 
frizzleb replied on at Permalink Reply
frizzleb
I believe I understand what you are trying to do.

This is the bast way to grab an object from the file manager and embed it on the page.
<?php
$file = File::getByID($fID);
$path = $file->getPath()
?>
<embed src="<?php $path ?>"  hidden="true" autostart="true" loop="1">
duxferrarie replied on at Permalink Reply
That makes sense, but all I get is

->getPath()

appearing on the page. I'm trying to do this inside the HTML block, maybe that's the problem?
frizzleb replied on at Permalink Reply
frizzleb
My apologise I did not notice the html block part. I'm afraid that there is no easy way to dynamically link to file manager files in the html block. But it would be very easy to customise a block to do what you want.
frizzleb replied on at Permalink Reply
frizzleb
Simply place the code into the view.php file.
jordanlev replied on at Permalink Reply
jordanlev
Concrete5 does have a nice feature of the Content block (not the HTML block) where it will automatically change the URL's when you move a site's location. Note that the URL's need to be in a certain format -- but you can find out by using the "Insert Link to Page" toolbar button, then viewing the HTML source to see what it inserted for you.

So one option would be to use the Content block, click the "HTML" button in the toolbar, and paste in your HTML there, making sure the links follow the appropriate format so they will automatically get rewritten upon deployment.
jordanlev replied on at Permalink Reply
jordanlev
Or another option is to run this query directly on your MySQL database when you deploy:

--Sanity check:
SELECT * FROM btContentLocal WHERE content LIKE '%/old/base/dir/%';
--Run the update (with optional WHERE clauses at the end as a "safety feature"):
UPDATE btContentLocal SET content = REPLACE(content, '/old/base/dir/', '/new/dir/') WHERE content LIKE '%/old/base/dir/%';


Run the first line first, just to make sure it gives you sane results and you're not going to accidentally break anything.

Then run the second line to actually perform the update.

This probably doesn't apply to you, but If you have any url's in image blocks (in the "Image Links to URL" field), you also want to run these:
SELECT * FROM btContentImage WHERE externalLink LIKE '%/old/base/dir/%';
UPDATE btContentImage SET externalLink = REPLACE(externalLink, '/old/base/dir/', '/new/dir/') WHERE externalLink LIKE '%/old/base/dir/%';

(same deal as above -- run the first line first, make sure it's sane, then run the second one to perform the update).
Steff replied on at Permalink Reply
Steff
Thanks jordanlev. This SQL statement was exactly what I was looking for.

Kind regards,
Steff
duxferrarie replied on at Permalink Reply
Indeed, it calls the file by fID in the URL, but the content block HTML side does not allow me to insert and <audio> tag, just cuts it right out.

I'll figure something out. I've had to do a lot of DB work on this project, so I guess I'll just have to do it that way.

Just for clarity, this is what I'm trying to embed in the page:

<audio controls preload="auto" autobuffer>
<source src="http://mydev.com/stage/files/3512/9953/8707/audiofile.mp3"/>
<source src="http://mydev.com/stage/files/3512/9953/8707/audiofile.ogg"/>
</audio>


or in some cases:

<a onclick="this.firstChild.play()"><audio src="http://mydev.com/stage/files/3512/9953/8707/audiofile.mp3"></audio>Play Button Graphic Coming Soon</a>


I really want to replace the hardcoded path with something wieldy.

Thanks for the help guys.
jordanlev replied on at Permalink Reply
jordanlev
That sure is annoying that the html block is stripping out that tag.

I think what you really want is just a "raw text" block of some kind.

I found this php block on the marketplace which is close:
http://www.concrete5.org/marketplace/addons/simple-php-block/...

But you're definitely going to want to edit the packages/nd_php_package/blocks/nd_php/view.php file, changing this:
<div id="NDPHPBlock<?php   echo intval($bID)?>" class="NDPHPBlock">
<?php   eval($content); ?>
</div>

to this:

<?php echo $content; ?>


And then for that sql query I had above, you want to run it against the "btNdPhpBlockContent" table, not btContentLocal.
duxferrarie replied on at Permalink Best Answer Reply
Raw text block kind of kills the idea of a CMS :-)

I really would love a hack to the editor that would let me insert file, such that the output on the page would be something like this:

<a onclick="this.firstChild.play()"><audio src="/index.php/download_file/view/32/"></audio>text</a>


The "text" is a word in Persian that is being read by a narrator. I want every vocabulary word read out onclick on the page (it's a Persian learning site, btw). I really want to do this without a player, since player controls are totally pointless when the sound file is 3 seconds and one word long.

Anyway I'd love the option in the TinyMCE's "add file" that would allow this kind of audio tag insertion.

UPDATE: This is a TinyMCE issue, submitted as bug.
http://tinymce.moxiecode.com/develop/bugtracker_view.php?id=4218...