Force every upload to be public

I'd like that every file uploaded by the user could only be set as public (it would be better if the user cannot see the related dropdown menu). Is there any obvious solution?

  • you can overwrite the form view and remove the access input.

    Then you can do a check on the 'create','object' and 'update','object' event to change the access_id to public if it isn't already.

  • Thank you Matt. I'm not happy when I have to modify the code because it means I possibly have to deal with my modifications when a new release of the framework is released. However, I have already deeply modified the file plugin in order to use amazonS3 for file storage, but I didn't find the way to hide that menu: am I looking in the right place?

  • You misunderstand me, I don't mean modify the core files - you can do all of that in your own plugin that would be immune from core upgrades.

     

    http://docs.elgg.org/wiki/Engine/Views

    http://docs.elgg.org/wiki/Elgg_Events

  • Hi,

    Its very simple..

    there are two files involve in this aperation..

    1. C:\xampp\htdocs\elgg-1.8.9\mod\file\views\default\forms\file\upload.php

    comments below section from this file

    <!--<div>
        <label><?php //echo elgg_echo('access'); ?></label><br />
        <?php //echo elgg_view('input/hidden', array('name' => 'access_id', 'value' => $access_id)); ?>
    </div>-->

     

    2. C:\xampp\htdocs\elgg-1.8.9\mod\file\actions\file\upload.php

    at line number 72 u will find "$file->access_id = $access_id;"

    //$access_id = (int) get_input("access_id");  -- comment this line
    $access_id = 2;//For Logged User and paste this code it will work

     

    Now you can create your view in your plugin to over write below logic it will work..

  • I see that not all plugins are compatible with all cores, so I thought I have to check if my self-written or modified plugin is still valid with the new core: am I wrong?

    In particular, if I modify a plugin, i.e. I don't write a plugin on my own, I have to deal also with that plugin updates...

    Thanks however to all for the suggestions and in particular to saurabh who made all the work for me :D

  • That is another way to do it, though don't modify those files directly, that will break forward compatibility when upgrading.  As I said before, use a new plugin to overwrite the view and action if you're going this route.  My solution with the event handler is nicer in terms of compatibility with any other plugins that might modify the action though.

    Also, access id 2 is actually public, not logged in.

    It's better to use the defined constants when dealing with access:

    ACCESS_PRIVATE

    ACCESS_FRIENDS

    ACCESS_LOGGED_IN

    ACCESS_PUBLIC

  • Thank you again, but since I already deeply modified the file plugin, at a point that I can almost consider it like a plugin of mine, it's not an error to follow saurabh indications (except for constants names, where I totally agree with your point of view). I know it will give me some issues in the future, in particular I will have to compare my code to any new file plugin, but I think that in my case there is no better way to achieve the whole result!

  • You should consider to move your modified file plugin to a proper own plugin, (maybe renaming some stuff it is enough) and re download a unmodified file plugin. andreaconsole from the future it will appreciate this

Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking