Recent Topics

1 Sep 27, 2006 21:26    

I am working in the implementation of blogs in a site I maintain. The blogs will replace existing bulletin-like sections that the site owner updates weekly. There is a collection of images that will be available for use in the postings and will be stored in the site owner's media directory. I am not using the blog directories because the site will have at least two separate blogs and the images are common for all of them. There will be instances in which I (as administrator) will be doing the weekly postings on behalf of the site owner. However I found that when I login with my administrator account I don't have access to the site owner's media directory and therefore cannot select images from there to use in the postings.

How can I add access to other users' media directories to my administrator account?

2 Sep 28, 2006 00:42

Add the lines marked with "+" to blogs/inc/MODEL/files/_file.funcs.php. The patch is against CVS HEAD, but is probably alright for 1.8.


  /**
   * Get an array of available Fileroots.
   *
   * @return array of FileRoots (key being the FileRoot's ID)
   */
  function get_available_FileRoots()
  {
        global $current_User;

        $r = array();

        // The user's blog (if available) is the default/first one:
        $FileRootCache = & get_Cache( 'FileRootCache' );
        $user_FileRoot = & $FileRootCache->get_by_type_and_ID( 'user', $current_User->ID );
        if( $user_FileRoot )
        { // We got a user media dir:
                $r[ $user_FileRoot->ID ] = & $user_FileRoot;
        }

+       if( $current_User->group_ID == 1 )
+       {
+               global $DB;
+               foreach( $DB->get_col( 'SELECT user_ID FROM T_users WHERE user_ID != '.$current_User->ID ) as $other_user_ID )
+               {
+                       $user_FileRoot = & $FileRootCache->get_by_type_and_ID( 'user', $other_user_ID );
+                       if( $user_FileRoot )
+                       { // We got a user media dir:
+                               $r[ $user_FileRoot->ID ] = & $user_FileRoot;
+                       }
+               }
+       }
+
        $BlogCache = & get_Cache( 'BlogCache' );
        $bloglist = $BlogCache->load_user_blogs( 'browse', $current_User->ID );

        // blog media dirs:
        foreach( $bloglist as $blog_ID )
        {
                if( $Root = & $FileRootCache->get_by_type_and_ID( 'collection', $blog_ID ) )
                {
                        $r[ $Root->ID ] = & $Root;
                }
        }

        return $r;
  }

3 Sep 28, 2006 03:42

That if statement appears to fail, therefore nothing happens even though I am logged in as administrator and the group ID is 1.

The first if of the added block of code, that is.

4 Sep 30, 2006 00:16

Use


pre_dump($current_User->group_ID);


to see if your group is really 1.

Use


pre_dump( gettype($user_FileRoot) );


before


if( $user_FileRoot ) 


to see, if you get any FileRoot.

5 Sep 30, 2006 00:54

I get NULL as group ID. 8|

6 Sep 30, 2006 15:23

Oh.. then use


if( $current_User->Group->ID == 1 ) 


instead (for 1.8.x). The original patch above is for 1.9+.

7 Sep 30, 2006 16:56

That worked fine but then it goes and creates a media folder for every registered user no matter their user level. Level 0 users are only allowed to comment on posts and that is the default user level. They do not need a media folder. People allowed to post new messages are level 1 and those are the ones that will have images to use in posts.

8 Sep 30, 2006 17:05

Yes.. the problem is that media dirs get created, if the get queried.

The fix would be to have an extra param to User::get_media_dir, let this default to false and call it with "true", if it's used e.g. in the Filemanager itself.

I'll look into having this for 1.9, but for 1.8 you'd have to hack it yourself.

9 Sep 30, 2006 17:11

The problem is that I don't know PHP. :( I do know how to change skins and such and can follow the logic to some extent but I cannot go into the actual coding. I do know how to code in Perl but this is very different.

Thanks anyway.

10 Sep 30, 2006 17:19

Well not all hope is lost. Looking at the snippet of code above I could probably filter out the level 0 users on the SQL query. I will try that later.

11 Sep 30, 2006 17:27

Yes, would be the way to go in your case.

12 Sep 30, 2006 18:35

It worked!!! :D

foreach( $DB->get_col( 'SELECT user_ID FROM T_users WHERE user_level != 0 AND user_ID != '.$current_User->ID ) as $other_user_ID )

Thanks a lot for your help.


Form is loading...