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.
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.
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.
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.
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.