Resource icon

MetaMirror 1.6.1

No permission to download
I have over 325,000 attachments in my forum and I have never used the Attachment Manager in the Admin CP. I don't see any need for that application.

Yeah, me neither. But someone metioned being able to see the rehosted files there as a benefit.
 
That would be me, as you can use it to sort, largest attachments, latest, by date range and filter attachments by user too. You don't even have to go to post to view attachment. Useful and built into xenforo, whether you use it or not.
 
Last edited:
That would be me, as you can use it to sort, largest attachments, latest, by date range and filter attachments by user too. You don't even have to go to post to view attachment. Useful and built into xenforo, whether you use it or not.

I use phpmyadmin to see latest attachment, largest attachment and similar things.
 
Another thing to consider, Mick. When your cron runs I assume you are using SELECT and LIKE '%[I M G]%'. If so are you limiting the number of posts or searching all the messages?

edit: name correction
 
Last edited:
Another thing to consider, Mike. When your cron runs I assume you are using SELECT and LIKE '%[I M G]%'. If so are you limiting the number of posts or searching all the messages?

Limiting, and it flags posts with a magic number when they have been processed.

I use [/IMG] as it's less likely to be used in conversation.

Code:
                SELECT * FROM ".self::$table_name."
                INNER JOIN xf_thread ON (xf_thread.thread_id = xf_post.thread_id)
                WHERE ".self::$column_name." LIKE '%[/IMG]%'
                AND  MetaMirror_Processed != ".MMR_MAGIC."
                ".$excluder."
                LIMIT 0, ".self::$max_posts

The $excluder is for forum exclusions
Code:
        $excluder = isset (self::$exclude_forums[0]) ? ("AND node_id NOT IN (".$db->quote(self::$exclude_forums).")"):"";

I have $max_posts at 10

(P.S., Mick, not Mike).
 
Any thoughts on adding a path setting so we can tell it to add our cdn in the url? Also the ability to have it check again and update the links with that setting would be nice.

Great Job on this Mike. I have so many old posts with dead pics. You have made a pretty awesome mod here on so many levels.
 
Any thoughts on adding a path setting so we can tell it to add our cdn in the url? Also the ability to have it check again and update the links with that setting would be nice.

Great Job on this Mike. I have so many old posts with dead pics. You have made a pretty awesome mod here on so many levels.

Mick :)

Can you explain more what you mean by a path setting? Can you give a real-world example?

Note it accounts for the external data path, if you use that for CDN.
 
Mick West updated MetaMirror with a new update entry:

Sanitized file names

As well as performing a check to see if the data is an image (with exif_imagetype), I now also strip off any file extension that is not in
('jpg','jpeg','png','gif','bmp','ico')

Safe extensions are added back onto hashed file names generated from files with parameters, so other programs can still see them as images.

Read the rest of this update entry...
 
Well, I have the cdn settings but the app says that the images will be set to the url of my site without the cdn settings. So my cdn is http://cdn.mysite.com/images and the app is setting them as http://mysite.com/images. I saw you mention it would read that in one of the updates. Possibly it doesn't if it's already run before that update?

The URLs re-writing is permanent, in that it edits the actual URL in the post. The fix to include the external data path was in one of the later version, so if the URLs were already re-written, then they won't be changed again.

If the files are accessible via the CDN, then you might be able to do text replace to fix them.
 
I haven't had time to look into the code but sniffing on the importer files (i love to reading importers because you can learn so much!) I took the code that imports attachments and came up with this method (not my code, I just took it and removed unnecessary lines):

Watch out for:
  • $this->_getDb(): I don't know where you'll use this code (probably a model) so I just left it unmodified. This code is from a model so the class where I took it extends XenForo_Model. If you use it somewhere else, make sure to use a proper database object.
PHP:
    public function importPostAttachment($fileName, $tempFile, $userId, $postId, $date, array $attach = array())
    {
        $upload = new XenForo_Upload($fileName, $tempFile);
  
        try
        {
            $dataExtra = array('upload_date' => $date, 'attach_count' => 1);
            $dataId = $this->getModelFromCache('XenForo_Model_Attachment')->insertUploadedAttachmentData($upload, $userId, $dataExtra);
        }
        catch (XenForo_Exception $e)
        {
            return false;
        }
  
        $dw = XenForo_DataWriter::create('XenForo_DataWriter_Attachment');
        //$dw->setImportMode(true);
  
        $dw->bulkSet(array(
                'data_id' => $dataId,
                'content_type' => 'post',
                'content_id' => $postId,
                'attach_date' => $date,
                'unassociated' => 0
        ));
        $dw->bulkSet($attach);
  
        $dw->save();
  
        $newAttachmentId = $dw->get('attachment_id');
  
        $this->_getDb()->query('
                UPDATE xf_post SET
                attach_count = IF(attach_count < 65535, attach_count + 1, 65535)
                WHERE post_id = ?
                ', $postId);
  
        return $newAttachmentId;
    }

That seems to work just fine. I'm going to do a bit of work on smoothing out the process, and I should be able to do a version with the option to save as attachments soon.

Incidentally I found the code that XF uses for sanitizing attachment see _checkImageState() in XenForo/Upload.php
 
Rather than limiting the size, an option to scale to a maximum size would be better. For example scale images larger than 1600px to 1600px width.
 
very nice update. do you think we could have an option to put it in moderator bar instead of navigation bar please :)

It's set up to run as a cron job once you've enabled it. So once you have it configured there is (in theory) no need to ever touch it again. So I don't really see the point of having it in the moderator bar.

But you could just use a template mod to add a link to /admin.php?MetaMirror/ if you want easy access to the testing tool.
 
Back
Top Bottom