Import External Images

One plugin I use pretty frequently for WordPress is Import External Images. It lets you copy and paste content into your site, then with a couple of clicks it will sideload all of the images in that post that are still linked to external sources. I modified the one on WordPress.org to work with Squarespace and GoDaddy’s website builder. Let me know if you find any issues.

Download: import-external-images

Milestones

So, I’ve been watching the registrations on transfermyemail.ca and find it interesting the countries that I’m seeing there. It has started being used in Argentina, the Philippines, Austria,  Nigeria, and the UK, apart from Canada and the USA.  The consistent story I hear with most users is that they’re moving from an old/slow/bad host to something newer and better, and either aren’t being given the support to migrate cPanel that they need, or they aren’t on cPanel and have no easy email migration path. PERFECT! This is exactly why I launched the site! Still free for now. Try it out!

Adventures in VPS Land

So, 24 hours of using Virpus, and here’s my review. I’ll be frank here, I use Ramnode, love Ramnode, and have nothing but good things to say about them. I also use Cirrus Tech to host a Windows VPS. But I’m not one to put all of my eggs in one basket, especially with so many businesses relying on my hosting, so I signed up with no expectations for one of the Virpus Linux Seattle-based VPS’s, adding cPanel.

Since signing up, I’ve been able to considerably drop the load from one of my main VPS’s through this new VPS.

It was provisioned instantly, but looks like the IP address wasn’t automatically registered in WHM/cPanel’s system (maybe because I did it after hours?), so I had to wait for that and run a few commands to both install and register WHM… no biggie, it’s self managed, you get what you pay for. After getting it all set up and running, I moved over about 25 sites and swapped DNS IPs to see what it would be like load-wise. Support was quick to respond, even after-hours (not quite as fast as Ramnode but still very prompt and courteous).

Seems very stable, speeds are good, and I ran some hard disk tests which were comparable with Ramnode – almost exactly on par.

The server virtualization technology in use is Xen – which has pros and cons, like me having to patch my own kernel if there are security vulnerabilities, but not having to request second level quotas to be enabled. Also Xen is more flexible from a memory perspective, whereas Ramnode bites the big one when the server gets overloaded by requests due to the technology used: I can expect my clamav, spamd, and mysql services to need to restart daily – thankfully they do this on their own.

Now, I’m a server admin and web developer by trade, so I tend to know my stuff, so don’t take my ease of setup and use as what your experience will be like, but as far as I’m concerned the cost vs the features is well worth it. None of my mission critical sites are on it at this point, until I give it some break in time, but I’d be quite happy setting up clients on here if it continues with this level of responsiveness.

TransferMyEmail

Made some changes to TransferMyEmail yesterday and today – basically I rewrote the parsing routine for folder structure and output of checkboxes. This was needed because originally I had been using “INBOX” as the root folder, which worked to a certain extent, but then had some feedback from Germany, where I found out “POSTEINGANG” could be used too, and also Gmail has a folder structure that is based partly on IMAP and partly on their tags. So you could have a list of folders, then in the middle a [GMAIL] root folder, then some other folders after that.

Long story short, it should handle anything you throw at it to a depth of 3 subfolders, and still iterate through everything properly.

Check out the project here: http://transfermyemail.ca

Afterglow

I have this social aggregation project I’ve been working on called AfterGlow, and it’s not without its challenges, but tonight I did some work on it on a few areas that have been insufficient up until now. Instagram’s API supports pagination, so I added support for that – full support too, so it will continue down your Instagram feed until it reaches your set maximum results or the end of the feed. I also tweaked the parser for Pinterest to allow for date stamps to be read properly, and time sorting works as a result. They have a unique stamp compared to the other feeds so it took a few extra lines of code – I had only recently switched them from scraping over to RSS. Finally, I edited the moderation side of the admin dashboard so that it would be sorted by date too, and fixed the loading screen so it actually gets injected before the server parses and returns all of the feeds.

Check it out here: AfterGlow.me

WordPress Plugin: PDFs Open in New Tab

I had a client recently where I had to import over 150 pages into their site in order to get the moved over to WordPress. I didn’t have access to the database as it was a proprietary CMS they were using, so I ended up having to use HTTrack to take an offsite copy of the entire site. Needless to say, I ended up writing a few tools to import everything so I wouldn’t have to do it manually. I uploaded all of the html files to the server, sideloaded all of the images, set the first attachment as the featured image, and was done in probably 1/10th of the time it would have taken to go through them all one by one and copy and paste. Then I realized that all of the attached PDF files opened in the same tab. I could handle this one of three ways:

  1. Find and replace in the database
  2. Javascript or jQuery to append the target attribute
  3. Use WordPress hooks and some fancy Regex

I opted for number 3, as it would be basically transparent, and wrote a quick plugin. This can easily be adapted to work with any extension of attachment. Here we go:

 

How to transfer email accounts and messages between servers?

Moving emails to your new server should be relatively easy – if you want to transfer your email messages from one server to another, you can now do this with only your login details. No FTP transfers needed, and you don’t need to drag and drop between accounts in your mail program. It utilizes the IMAP protocol so it will sync everything for you directly without removing email from your old server.  It will transfer your entire email directory structure to the new server, including all sub folders that you select. You can now easily transfer emails from your previous host to your new host without any effort.

The script is finally complete, and you can find it here: https://brendancarr.ca/migrateemail/

Please note, it doesn’t actually transfer emails, but it will let you test the email transfer procedure itself and supports SSL so you can use it on Gmail.  Please feel free to contact me if you would like to utilize it.

brendan@carr.ca

PHP Best Practices

You know the worst part about focusing on function over form, and working mostly on your own? You neglect to make sure that your coding style is uniform, that you’re following best practices, and that your code is properly SPACED and INDENTED (one tab per level). A lot of times I don’t have to go back to the code or share it, so it just gets left the way it is – because it works.

I don’t even want to go into how many times I’ve had to go back over my code and space out variables inside of brackets, and move them from being in the function calls themselves to being declared outside of the function call. At the same time, you have to make sure you don’t copy extra variables – that is, instead of copying predefined variables to smaller-named variables, just use the predefined variables to keep memory usage down.

Following DRY princples (Don’t Repeat Yourself) is another one. When I am starting something from scratch, I’m famous for repeating procedures that could be condensed into a single function call, then called multiple times. At least when reviewing after the initial coding spree I will go back and condense and clean up, but it’s still not fun when you get into 1000s of lines of code. We iterate versions and find better ways to do things for a reason, I guess.

Ultimately, it’s up to the coder as to their own particular style, but realistically, if you train yourself to do it ahead of time rather than just powering through an evening getting the project completed and working (I’m guilty) as soon as possible, then you’ll save yourself time in the long run.

 

IMAP Migration PHP Script v2

A few things have changed since the last time I posted the IMAP migration script, and my wishlist of features is almost complete. Instead of a single file that you have to manually specify variables in, you now have fillable form that uses jQuery.post to send variables to another file (called process.php), which handles the actual migration. What this does is solve the memory issue, as you can specify the incremental value (number of emails it will transfer at a time) and it also makes it a little more user-friendly. I added support for unread emails (instead of just marking everything as read), and changed the imap_body command to “peek” instead of doing a full open, which marks the email as read as it’s transferring. This time around I am not going to post the code, but it will be included in the zip file.

On the todo list is directory traversing for people who organize their emails into folders, and some bug fixes.

Unzip this into a folder on your server, then run “email.php” from your browser.

Download here

 

imapmigration

WordPress Variable Monitoring Script

I ran into an issue with WP E-commerce recently where the shipping options appeared to be unchecked every day that we went to go and look at them. Turns out it was a line in one of the shipping files that reset the shipping array to just “shipwire” which made it appear as if someone was turning off shipping every day (or a cron job, in this case).

Read about it here: https://wordpress.org/support/topic/upgrade-to-43-and-problems-with-shipping-calculator

Anyways, I created a script to monitor changes to custom_shipping_options and thereby found out what the issue was. Here’s the code, hope it helps.