• Resolved FelixSima

    (@felixsima)


    Hey. First of all, thank you for this great plugin, it’s a masterpiece.

    I’m having a problem regarding the users abilities to create folders.
    I am using this shortcode:

    [fileaway type=”table” fadein=”opacity” makedir=”true” fadetime=”500″ theme=”silk” bulkdownload=”on” manager=”on” name=”files” sub=”/fa-userrole/fa-username” password=”pass” user_override=”fa-userid”]

    Everything works well, the users are able to create directories and everything, with one exception. If the username contains a period ( . ), then the creation of directories becomes a problem. It seems that it creates another folder without the period in its name. So, for example, let’s take the user test.test . The files can be found in the “test.test” folder, but when the user creates a new sub directory, a new folder is created on the base folder with the same name as the user but the period is replaced by space (test test), and that’s where it creates the new subdirectory, while all the files are on the ‘test.test’ folder. Any ideas? Thank you!

    https://ww.wp.xz.cn/plugins/file-away/

Viewing 15 replies - 1 through 15 (of 24 total)
  • Plugin Author thomstark

    (@thomstark)

    Thanks for the positive feedback. Unfortunately, I strip periods out for other security reasons. You have a couple of options.

    1) Use a different dynamic path, like fa-firstlast
    2) Create a little shortcode of your own to strip out periods like so:

    class my_fileaway_extension
    {
    	public function __construct()
    	{
    		add_shortcode('fileaway_extended', array($this, 'sc'));
    	}
    	public function sc($atts = array())
    	{
    		if(!class_exists('fileaway') || !is_user_logged_in()) return;
    		$u = wp_get_current_user();
    		$login = str_replace(array('.',"'",'"'), '', $u->user_login);
    		if(isset($atts['sub'])) unset($atts['sub']);
    		$atts['sub'] = 'fa-userrole/'.$login;
    		$fileaway = new fileaway;
    		return $fileaway->sc($atts);
    	}
    }
    new my_fileaway_extension;

    Put that class in your theme’s functions.php, or in your own plugin if you know how to do that. The function above removes periods, apostrophes and double-quotes from the username string before it passes it to file away.

    Then replace your current shortcode on your page with this:

    [fileaway_extended fadein="opacity" makedir="true" fadetime="500" theme="silk" manager="on" name="files" password="pass" user_override="fa-userid"]

    We’ve removed the sub attribute from the shortcode because we handle that in our custom php function. We’ve also removed the bulkdownload attribute, because it’s redundant with manager mode enabled. We’ve also removed the type=”table” attribute, because with manager mode enabled, that’s a given.

    Plugin Author thomstark

    (@thomstark)

    If you need to do it with File Up as well, ditch the above code and replace it with this:

    class my_fileaway_extension
    {
    	public function __construct()
    	{
    		add_shortcode('fileaway_extended', array($this, 'sc'));
    		add_shortcode('fileup_extended', array($this, 'up'));
    	}
    	public function sc($atts = array())
    	{
    		if(!class_exists('fileaway') || !is_user_logged_in()) return;
    		$u = wp_get_current_user();
    		$login = str_replace(array('.',"'",'"'), '', $u->user_login);
    		if(isset($atts['sub'])) unset($atts['sub']);
    		$atts['sub'] = 'fa-userrole/'.$login;
    		$fileaway = new fileaway;
    		return $fileaway->sc($atts);
    	}
    	public function up($atts = array())
    	{
    		if(!class_exists('fileup') || !is_user_logged_in()) return;
    		$u = wp_get_current_user();
    		$login = str_replace(array('.',"'",'"'), '', $u->user_login);
    		if(isset($atts['sub'])) unset($atts['sub']);
    		$atts['sub'] = 'fa-userrole/'.$login;
    		$fileup = new fileup;
    		return $fileup->sc($atts);
    	}
    }
    new my_fileaway_extension;

    Then use [fileaway_extended] and [fileup_extended] with all your ordinary attributes except for the sub attribute.

    Thread Starter FelixSima

    (@felixsima)

    Thx for your quick response. I placed the new class in my themes functions.php but it doesn’t seem to register the new shortcode. I replaced the old shortcode with the new “fileaway_extended” and it displays the uninterpreted shortcode on the page.

    Plugin Author thomstark

    (@thomstark)

    Well, it should work fine. Be sure you include it after the opening <?php tag in the functions.php (obviously). You did include the last line:

    new my_fileaway_extension;

    right?

    Do you have more than one functions.php?

    Would you mind pasting the code here that you pasted there exactly for me?

    Thread Starter FelixSima

    (@felixsima)

    class my_fileaway_extension
    {
    public function __construct()
    {
    add_shortcode(‘fileaway_extended’, array($this, ‘sc’));
    }
    public function sc($atts = array())
    {
    if(!class_exists(‘fileaway’) || !is_user_logged_in()) return;
    $u = wp_get_current_user();
    $login = str_replace(array(‘.’,”‘”,'”‘), ”, $u->user_login);
    if(isset($atts[‘sub’])) unset($atts[‘sub’]);
    $atts[‘sub’] = ‘fa-userrole/’.$login;
    $fileaway = new fileaway;
    return $fileaway->sc($atts);
    }
    }
    new my_fileaway_extension;

    It’s only one functions.php, and yes, it is between php tags

    Plugin Author thomstark

    (@thomstark)

    If all else fails, remove it from your functions.php, then create a blank document in Notepad, and paste this in:

    <?php
    /*
    ** Plugin Name: File Away Extended
    ** Plugin URI: http://ww.wp.xz.cn/plugins/file-away/
    ** Description: My File Away Add-On
    ** Version: 1
    ** Author: Felix
    */
    
    class my_fileaway_extension
    {
    	public function __construct()
    	{
    		add_shortcode('fileaway_extended', array($this, 'sc'));
    		add_shortcode('fileup_extended', array($this, 'up'));
    	}
    	public function sc($atts = array())
    	{
    		if(!class_exists('fileaway') || !is_user_logged_in()) return;
    		$u = wp_get_current_user();
    		$login = str_replace(array('.',"'",'"'), '', $u->user_login);
    		if(isset($atts['sub'])) unset($atts['sub']);
    		$atts['sub'] = 'fa-userrole/'.$login;
    		$fileaway = new fileaway;
    		return $fileaway->sc($atts);
    	}
    	public function up($atts = array())
    	{
    		if(!class_exists('fileup') || !is_user_logged_in()) return;
    		$u = wp_get_current_user();
    		$login = str_replace(array('.',"'",'"'), '', $u->user_login);
    		if(isset($atts['sub'])) unset($atts['sub']);
    		$atts['sub'] = 'fa-userrole/'.$login;
    		$fileup = new fileup;
    		return $fileup->sc($atts);
    	}
    }
    new my_fileaway_extension;

    save it as: fileaway-extended.php

    uploaded it to a folder that you’ll create like so:

    wp-content/plugins/fileaway-extended/

    Then go to your plugins page and activate your new plugin.

    Plugin Author thomstark

    (@thomstark)

    Or, you could give me access and I’ll figure out what the hangup is.

    Thread Starter FelixSima

    (@felixsima)

    Ok, now it works, but the problem is that the extended plugin function removes the dot while the uploader uses the users name as it is (with dot included), so I still have 2 different folders (test.test and testtest). Would it be posible for the manager to use the users name as it is (dot included)?

    Plugin Author thomstark

    (@thomstark)

    You mean you’re using a different uploader than File Up? You didn’t mention that.

    Thread Starter FelixSima

    (@felixsima)

    No, no, the file up I mean.

    [fileup sub=”/fa-userrole/fa-username” makedir=”true” theme=”silver-bullet”]

    [fileaway_extended fadein=”opacity” makedir=”true” fadetime=”500″ theme=”silk” bulkdownload=”on” manager=”on” name=”files” password=”wp!@#$%^” user_override=”fa-userid”]

    These are the 2 shortcodes I’m currently using.

    Plugin Author thomstark

    (@thomstark)

    The code I provided you has a new shortcode for both File Away and File Up, as I mentioned several comments back:

    [fileup_extended makedir=”true” theme=”silver-bullet”]

    [fileaway_extended fadein=”opacity” makedir=”true” fadetime=”500″ theme=”silk” bulkdownload=”on” manager=”on” name=”files” password=”wp!@#$%^” user_override=”fa-userid”]

    Plugin Author thomstark

    (@thomstark)

    The first code block I pasted did not have a File Up extended shortcode. The next two do. Re-read the third comment of the thread.

    Thread Starter FelixSima

    (@felixsima)

    oh, sorry, I missed that. Just a sec

    Thread Starter FelixSima

    (@felixsima)

    Ok, now it works. But what happens if at some point there will be 2 users, one testtest and the other one test.test . Wouldn’t that result in mixing their files?

    Plugin Author thomstark

    (@thomstark)

    Yes, that’s a good point. If two users with the same role have the same login except for periods, then yeah, it’ll point to the same directory. We can modify this to include the user id in the directory path, if you want to do that. Want me to modify the code to include the user id?

Viewing 15 replies - 1 through 15 (of 24 total)

The topic ‘Username dynamic path bug’ is closed to new replies.