Igor's Blog

Force PHP GD library to load JPEG images that have invalid data
While updating code my my travelblog.ws project I came across an issue where I was not able to upload certain JPEG files to the blog and have them automatically scaled down for thumbnail generation. The files opened fine on my Mac but PHP would not load them.
PHP PDO doesn't work binding multiple IN statement values
PHP's PDO is a great way to access databases and works as expected on the most part, that is until you come to the IN() operator. Some peculiarities begin to emerge there as I've discovered recently when updating code for my travelblog.ws project.
Taking SMTP out of your web app, a quick start with SendGrid
After struggling with emails not being being delivered to subscribers using SMTP over at travelblog.ws I started to look at alternatives to sending email and came across SendGrid. With SendGrid it's possible make use of your existing code that sends emails while taking SMTP completely out of the picture, at least on your end.
Getting the total number of rows with MySQL LIMIT clause
The MySQL SELECT statement syntax includes a LIMIT clause that can be used to restrict how much data is returned from the database. This is fantastic for pagination but in most cases you also want to know how many rows there are in total, which typically requires a second query. With MySQL there is a special option that can be passed to SELECT to do this calculation for you automatically.
How to set MySQL connection timezone with PDO
For my travelblog.ws project I store all dates as UTC in columns using the DATETIME data type i.e. my code converts dates to UTC before storing them. Because DATETIME is time zone agnostic this worked great, that is until I needed to use the TIMESTAMP data type on a number of new columns that I've added.
Using PHP in_array function with Smarty
I've come across a requirement in some of my Smarty templates to check if a value of a variable appears in an array. The PHP in_array function does this for you and according to the Smarty documentation any PHP function can be used as a variable modifier so this should be very easy to implement.
Example code to register a custom node type definition with PHPCR and Jackalope using a CND file
This is a bit of code from my latest personal project that's using PHPCR / Jackalope for it's storage backend. With Jackalope you can keep using nt:unstructured as your node type, but it makes a lot of sense to create custom node types when you are certain of what your data will look like. With a custom node type you are guaranteed that the structure of the node you're trying to store will be as defined and you don't have to worry about writing additional validation code yourself since the storage backend will take care of it for you.
Self initialising repository session wrapper class for PHPCR Jackalope Doctrine-Dbal
Jackalope's Doctrine-Dbal implementation is great to use if you don't want to run a Jackrabbit server, however one of the difficulties for a first-time user is having to go through the bootstrapping process and initialising the repository. After a bit of poking around the command line utility code that comes with Jackalope I put together this class that detects if the repository hasn't been initialised and does the initialisation automatically for you. It also wraps the session so you're guaranteed a valid repository with an open session when you use this.
PHP Composer makes it super easy to manage library dependencies - a simple example
Until recently all of my PHP development relied on manually downloading library dependencies and making them work with existing projects. Now that I started work on a new project from scratch I decided to try out Composer for library management and wow does it save a lot of time and hassle!
Updating the FlatPress PostViews plugin to use a tracking pixel
FlatPress has a great plugin called PostViews that counts the number of times a blog post has been viewed. One of the issues I had with this plugin is it stopped tracking the number of views when I turned on HTML caching at my CloudFlare front end. Naturally the HTML was cached for most requests and therefore the plugin was never executed. The solution to this was to use a tracking pixel and set CloudFlare to disable caching on the tracking pixel itself so that I could capture each of the views.
Here's an addition to your programmer's toolbox - strfunc.net
I've said it previously that I am a huge fan of online tooling that assists you while developing software. I've even written some of my own (UUID to OID Converter) online tools. Recently I wanted to use a popular online string functions website, but to my surprise, I found that it was no longer working. As a response to this, I've decided to put up my own: http://strfunc.net.
Create an e-Commerce web site in one day with Bootstrap, PayPal and PHP
I had an idea for a website a couple of weeks ago. It was a very simple concept - you write a text note up to 140 characters in length, pay for it and it gets sent anonymously on an A6 sized postcard anywhere around the world. The product was simple, the implementation of the site even simpler. Using modern technologies, implementing an e-Commerce web site is almost trivial. This article will show how I managed to take my idea from a concept to a fully functional e-Commerce web site in one day.
A quick start with the PayPal PHP SDK for the REST API
PayPal's REST APIs are a very easy way to add e-Commerce functionality to your web project. There is a PHP SDK available for it, and there is a very good API Samples site that covers just about anything you would want to do with the SDK. However something that I thought was missing from this documentation was how to create your PayPal App and Sandbox accounts as well as the autoload.php file that's references but never actually included in the package.
Make FlatPress generate meta tags without the use of the SEO Metatag Info plugin
Meta tags are still very important for SEO (Search Engine Optimisation) and posting to social media. For example if you don't have the description meta tag for your blog post, Facebook doesn't show the page description. This makes these tags crucial for any blog. If you use FlatPress, there is the SEO Metatag Info available to generate these tags for you automatically, however, recently I've noticed that there is a security issue with this plugin which allows anyone to write arbitrary files to your server and I quickly disabled the plugin and came up with an alternative to generating the meta tags I needed.
Share a link to a web page using a Google Plus app activity
I wanted to have a way of automatically sharing my blog posts directly to my Google+ stream for a while. After starting work on this feature I quickly hit multiple road blocks. However, I was able to come to some sort of compromise with the Google+ API and can now share links for my blog articles to my Google App's feed, here's how I did it.
Example of using the Google Plus OAuth refresh token
If you want to avoid prompting the user to give permission to your app every time it tries to use their Google+ account for authentication/authorisation, you probably want to use the refresh token to gain the same access.
Creating a Twitter App and integrating it into your PHP project with TwitterOAuth
Twitter is a great way to share content and with the use of the TwitterOAuth, a Twitter OAuth REST API PHP library, adding twitter functionality to your PHP project is easy as pie. I've recently added Twitter auto-post functionality to my blog software and wanted to share my notes. My goal was to be able to tweet directly from my blog admin pages, so this entry shows how to set up your own Twitter App, how to establish a connection with Twitter and to sent message and photo tweets using your own Twitter account.
SSL enabling FlatPress
Now that my blog is finally moved to a new host and SSL is fully set up, here's a quick note on how to make FlatPress work over HTTPS. By default, even if you change the Blog URL in the Options screen, FlatPress will not use that in all cases, the changes need to be done in the actual code too.
Blog activity graph for FlatPress
Here's a small addition to FlatPress. It's a blog activity graph that displays the number of blog posts per month over the past number of months. I got this idea when looking at the Cobertura home page and seeing their commit activity graph.
RaspberryPi and a USB monitor combined to make a photo frame (part 4)
A while back I wrote an entry on how to get the Lenovo LT1421 USB DisplayLink monitor working on a RaspberryPi. Now I took that a bit further and created a photo frame using the Raspberry Pi model A, a USB monitor and a bunch of software and some custom scripts.
Integrating with Facebook using PHP and pre-authenticated tokens (part 2)
This is the second part out of a series of posts showing how to integrate with Facebook. The first part went through the necessary steps of setting up a Facebook app and getting a pre-authenticated token ready. This part will get down to the actual PHP code needed to do the posting.
Integrating with Facebook using PHP and pre-authenticated tokens (part 1)
I've been hacking at the FlatPress code for some time now and as one of the features I thought it was lacking was Facebook integration. I've experimented with adding Facebook posting features using the OAuth2 approach with the Facebook APIs but didn't particularly like those so I've decided to try the pre-authenticated tokens with the FacebookSession object and personally think it's a nicer solution.
Add a URL shortener plugin to FlatPress
Ever since I've started sharing my blog posts on Twitter, I've wanted to have my own URL shortener. There was no such feature with FlatPress out-of-the-box, so I went ahead and made my own plugin. This post shows how to write a shortener plugin for FlatPress and then how to configure it to redirect from the short to real URLs.
'More on this blog' plugin for FlatPress
This plugin creates a box with a number of links to other posts on the same blog. The look and feel is configurable via CSS. By default it displays 4 random posts, but that can be changed via code. I created this plugin to expose readers to more content and also to create more internal linking.
SEO Metadata Plugin removing quotes, punctuation characters
I've been noticing that the SEO Metadata Plugin for FlatPress has been removing quotes and other punctuation characters from the metadata. This makes any blog snippets on social media sites (Facebook, Google Plus, etc) appear unprofessional. The plugin can already preserve these characters, it just needs to be configured.
Adding Google search to a FlatPress theme
Although FlatPress includes a search feature, I found it to be quite limited, so I had a look at adding Google search to a theme in FlatPress and found that to be quite easy to do. There is some tinkering with the FlatPress code itself, however the end result is a fully working search for FlatPress that is backed by the power of Google.
Add FlatPress static page links to the sitemap.php site map generator
This question has been asked several times so I thought it was about time I've addressed it. Here's a bit of code that will add all of the static pages that are defined in FlatPress to the site map generator output.
Page view statistics generator for FlatPress
The PostViews plugin for FlatPress is useful and captures how many times a blog post has been viewed, what I felt it was missing was a way to show this information across all of the pages. To fill that gap, I wrote a small script that uses data that PostViews generates to visualise a histogram of all of the blog's pages and posts and views per post.
Adding GitLab Commits to a DokuWiki page (a very rough plugin)
I was surprised to find that there hasn't been a plugin created to show all of the commits from the GitLab Git commit page in DokuWiki, so I went about creating my own. The plugin is very rough and hardcodes a lot of things, but it gets the job done.
A better way to place AdSense ads in a FlatPress theme
In a previous post I talked about placing Google AdSense ads into FlatPress themes without violating Google policy. In this post I will talk about a better way to achieve the same effect: basically this comes down to making sure that a single ad unit is only shown once per page.
Download Counter BBCode Plugin for FlatPress
This is a plugin for FlatPress that adds a BBCode 'download' tag with a link to the file to download and a counter for how many times the file has been downloaded.
Adding Google AdSense ads to FlatPress without violating Google policy
When I started modifying the FlatPress theme I am using to include AdSense content, I wanted to be able to have the main blog page not displaying any ads within the entry, but when viewing a single entry, I wanted additional ads shown inline with the entry itself.
Adding the number of views to the FlatPress LastEntries plugin
One of the things I wanted to have on this blog was the ability to see how many views there were for the entries in one quick glance. The LastEntries plugin gives the list of last 10 entries, but does not show how many times each one has been viewed.
Adding a Google compatible sitemap to FlatPress
I could not find a FlatPress sitemap generator, the one that was available previously seems to be down now, so I've decided to write my own based on some of the SQL export code on the FlatPress wiki.

Previous Post

Next Post

Programming, DIY, Games, Hacks, Tech and more.
Follow me on...
Current and Past Projects
See my Resume


RSS Feed

My Other Web Sites

Igor and Elise's Travels
Riverside Expressway Cam
StrFunc() Online
300 George St Blogumentary
Guru JSON-RPC Tester
Extrudifier Object Designer

Recent Blog Posts

Older versions of JD-GUI crashing on macOS Sierra

How does Seeed Fusion stack up as a low budget PCB fab

Where to find the last item (Robbie's lost lyrics) in GravityFalls Lake level

Detecting print requests to print contents of a DIV with JavaScript

Using Google DFP with AdSense on responsive pages

How to change the email subject line in Gmail

Force PHP GD library to load JPEG images that have invalid data

How to uninstall Samsung Smart Switch from your Mac

Facebook adds weather forecasts but forgets to adjust them to your time zone

No sound or microphone when answering calls on an iPhone

Recent Galleries

Space Food - Chocolate Ice Cream with Chocolate Chips

Legeod Star Wars AT-DP kit

DIY spare parts computer build with a RAIDMAX Anura case

Fake 'Lepin' brand Lego packaging

Hardwood garden bench with clear resin void filler

Fixing a 3D printer extruder that stopped heating up

Easily increase disk space in a Lenovo Ideapad 100S 14" laptop with an M.2 SSD

Making a multi-piece 3D printed solder spool holder stand

DIY indoor apartment grow light wiring

Good Friday Electronics fun Easter Bunny LED PCB Kit IBEABU-01.0

Top Categories

Blogs I follow

Matt Moores Blog
Georgi's FlatPress Guide
Perplexing Permutations
The Security Sleuth


RAWS Parts Online
Alpha Dimensions Hosting
Kristensen Photography
Ilia Rogatchevski
Travelling Fairy

Blog Activity

Blog Activity
Follow me on... 
...or subscribe for updates!

Don't show this again