You need to be logged in to post in the forum - Log In

An active JCE Pro Subscription is required to post in the forum - Buy a Subscription

Support is currently Online

Official support hours
Monday to Friday
09:00 - 17:00 Europe/London (BST)

#103200 Custom Filesystem with rootdir = $articleid

Posted in ‘Editor’
This is a public ticket

Everybody will be able to see its contents. Do not include usernames, passwords or any other sensitive information.

Latest post by Ryan on Monday, 06 April 2020 16:08 BST

unipg
I'm trying to implement a filesystem plugin that I'd like to use in a specific JCE profile for com_content component and Editors users. Like the variables $id, $username, $usertype, etc. that you can use to specify dinamically the root directory, I'd like to add a variable, i.e. $articleid, that will dinamically set the root directory to a folder named with the id of the article you're currently editing (i.e. /mypath/123). So, every article has its own folder (this is very useful in a scenario when article editing need to be moved frequently from a usergroup to another, and you don't want to migrate files). Well, in my scenario Editors can't create articles, they can just edit an existing one. So I'm sure that JCE is called for an article that already has an id. But I can realize this? I'm trying to override the WFFileSystem getRootDir() method but I can't figure out how to detect consistently the current article id. I've tried this way, and it works, but I'm not sure it is reliable...

if(!empty($registry->get('com_content')->edit->article->id)) {
	$article_id = reset($registry->get('com_content')->edit->article->id);
	if (!empty($article_id)) {
		if ($article_id>0) {
			$root .= '/' . $article_id;
...
Any suggestions?

Ryan
An event is a available that you can use in a custom Joomla system plugin to change the root directory for each user based on your criteria. The onWfFileSystemGetRootDir event is triggered when the root directory is requested, passing a relative url of the value set in the File Directory Path, or "images". Here is an example system plugin with all the available events exposed - https://github.com/widgetfactory/wf_filesystem_events To get the article id, which is only available on existing articles, you could try:

$id = JFactory::getApplication()->getInt('id');

Ryan Demmer

Lead Developer / CEO / CTO

Just because you're not paranoid doesn't mean everybody isn't out to get you.

unipg
Uhm, I've tried your suggestion but I noticed no differences between using events or overriding getRootDir(). In both cases I can set the root path but I need a way to get the article id, and getApplication() returns it only in

$session	= JFactory::getSession();
$registry	= $session->get('registry');
$article_id = reset($registry->get('com_content')->edit->article->id);
or in an http_referrer property. I can't use getApplication->input because when editing an article, the FileBrowser is opened in a popup window, so with a new url different from the editing page, and there's no trace of article id, nor of the component I'm using... Do you know how can I get these informations? For instance, how do you get the current component used to choose the right profile to apply? I guess I can found there what I'm looking for... thank you 🙂

Ryan
Perhaps it is stored in the User State, eg:

$app  = JFactory::getApplication();
$data = $app->getUserState('com_content.edit.article.data', array());

$articleid = (int) $data->id;

Ryan Demmer

Lead Developer / CEO / CTO

Just because you're not paranoid doesn't mean everybody isn't out to get you.

Ruslan518
Hi!

Nice idea. Can we get $articleid in picture manager by default option in future updates?

For example images/$id/$year/$month/$articleid

Thanks

Ryan
The article id is only available when an article has been saved, ie: not a new article, so you would have to save the article before adding any content before you could correctly access the folder where your images are stored.

Ryan Demmer

Lead Developer / CEO / CTO

Just because you're not paranoid doesn't mean everybody isn't out to get you.