We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Mark Huot's file extension and Multi Site Manager

Development and Programming

Paul Bell's avatar
Paul Bell
103 posts
17 years ago
Paul Bell's avatar Paul Bell

Mark’s extension works really well, and I think it’s an improvement on EE’s standard method for uploading files in a lot of situations. I’m working on a site now where I’ve duplicated everything to a second site in using MSM. I’ve created some new file upload locations in the new site which work fine. I’ve also modified the paths on the old file locations, which were associated with the old fields.

Everything shows up as it should in the CP, but on the live site, only my new fields show up as images. I’ve checked in the DB, and the data in weblog_data is sound. For some reason, the tags aren’t being processed properly when the custom field is a duplicate from the old site.

Does anyone have ideas, or know what I should try - I’ve been poking around for a few hours now with no success. Any help welcome!

       
Paul Bell's avatar
Paul Bell
103 posts
17 years ago
Paul Bell's avatar Paul Bell

Right, I’ve cracked it! The problem comes because I had fields with the same names in both of my sites, so when the replacement happens, it uses the field data from whichever field comes first, regardless of which site it’s from (so on the second site, it gets replaced with nothing). This explains why when I create new file fields on the new site, they work just fine.

So, I needed to modify the extension to check the Site ID, and then get the right set of fields based on that. Here’s what I did - this code is from V3.11 of the templates.

I replaced the following (starting about line 1109):

function modify_template( $tagdata, $row )
    {
        global $DB, $FNS, $TMPL, $EXT, $SESS;
        global $all_fields, $file_fields;
        
        if($EXT->last_call !== false)
        {
            $tagdata = $EXT->last_call;
        }
        
        if(!isset($SESS->cache)) $SESS->cache = array();
        if(!isset($SESS->cache['mh_file_ext_fields']))
        {
            $SESS->cache['mh_file_ext_fields'] = $DB->query('SELECT * FROM exp_weblog_fields f, exp_upload_prefs p WHERE f.field_type="file" AND p.id=f.field_list_items');
        }
        
        //    =============================================
        //    Loop Through Fields
        //    =============================================
        foreach($SESS->cache['mh_file_ext_fields']->result as $file_field)
        {

With this:

function modify_template( $tagdata, $row )
    {
        global $DB, $FNS, $TMPL, $EXT, $SESS, $PREFS;
        global $all_fields, $file_fields;
        
        if($EXT->last_call !== false)
        {
            $tagdata = $EXT->last_call;
        }
        
        $site_id=$PREFS->ini('site_id');
        
        if(!isset($SESS->cache)) $SESS->cache = array();
        if(!isset($SESS->cache['mh_file_ext_fields_'.$site_id]))
        {
            $SESS->cache['mh_file_ext_fields_'.$site_id] = $DB->query('SELECT * FROM exp_weblog_fields f, exp_upload_prefs p WHERE f.field_type="file" AND p.id=f.field_list_items AND f.site_id = '.$site_id);
        }
        
        //    =============================================
        //    Loop Through Fields
        //    =============================================
        foreach($SESS->cache['mh_file_ext_fields_'.$site_id]->result as $file_field)
        {

You’ll see that we need to declare $PREFS as global, to get the id of the site we’re looking at. Then the query is modified to search based on the site id. We cache each of these queries separately.

This post was helpful in finding out how we get at the id of the current site.

You still might run into problems if you use the “site” parameter in your weblog entries tag - the code above would require a tweak, but I don’t think it’s 100% straightforward. To fully MSM-ify this module, will require a bit more thought, but the above has worked for me. Hope it helps someone.

       
viewcreative's avatar
viewcreative
116 posts
about 17 years ago
viewcreative's avatar viewcreative

Hi Paul,

Your post is over two years old, but it has shed some light on the situation!

I need to be able to pull in custom file fields from articles spread over 3 separate sites. I’m currently working on MSMifying Mark Huots file extension to support this.

I’ll post my amends if/when I work it all out.

Matt

       
aferraccioli's avatar
aferraccioli
59 posts
16 years ago
aferraccioli's avatar aferraccioli

Dude, you just saved my life.

Thank-you for discovering this. wow.

       
Kev-O's avatar
Kev-O
50 posts
16 years ago
Kev-O's avatar Kev-O

+1 saved my life

Thanks alot!

Hi Paul, Your post is over two years old, but it has shed some light on the situation!

Actually I think he posted that just 2 weeks before 😊

       
viewcreative's avatar
viewcreative
116 posts
16 years ago
viewcreative's avatar viewcreative
+1 saved my life Thanks alot!
Hi Paul, Your post is over two years old, but it has shed some light on the situation!
Actually I think he posted that just 2 weeks before 😊

Yeah! You’re indeed correct. I was looking at the joined date!

       
negs's avatar
negs
43 posts
16 years ago
negs's avatar negs

Hi!

I had this same problem. But I didn’t want to modify the extension. So, I just changed the name of the field slightly, and that worked. This would be a great solution for less technical folks.

In this case, each of my sites is for a different country, so if the original field was called {the-pic}, I changed the name of the field in my Australia site to {the-pic-australia} and then for England {the-pic-england}, and on and on.

       
Chris Arnold's avatar
Chris Arnold
201 posts
15 years ago
Chris Arnold's avatar Chris Arnold

Thanks for the post negs. I’ve used the same method and it seems to work. Hopefully when Mark gets some free time to update his extension, he’ll take this issue into account. Otherwise, great, simple extension!

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.