Posts Tagged Expression Engine
Bootstrapping ExpressionEngine to integrate with other scripts
Posted by Avi in Programming on February 15th, 2011
Very often I’ve had to have external scripts access the ExpressionEngine environment, including the database, the sessions, and whatever else. For example, a cron job, or just simple one off scripts. So there are two ways most people do this, both are annoying. The simplest, is to create a template with PHP enabled. This is annoying because of all the extra steps involved, plus you get the overhead of extra database queries. The second is to create a module action. This is even more annoying, less database overhead, but you have to go through extra loops of creating a module and installing it. Plus you get to work with meaningless URL like http://mysite.com?ACT=324.
For EE1, I had distilled out all the code necessary to instantiate all the global EE objects. This was a one time annoyance, and I had to, unfortunately, duplicate a lot (read:all) the code, but it has come in handy many times.
Recently, I had to do this for EE2 as well, and it was not so straightforward.
Of course I began by distilling index.php and CodeIgniter.php, duplicating all that code. The only tricky parts, are that you need a fake “controller”.
I handled this by creating a small class, instantiating it:
class A extends Controller {}
$EE = new A;
Once I got to that point, all I had to do was call:
$EE->core->_initialize_core();
Now you can integrate EE anywhere, including any other systems or frameworks:
$system_path = '/path/to/system';
include 'boostrap-ee2.php';
And we have our $EE super global god object.
The full code is hosted on Github:
Fixing PATH_INFO on bluehost and other shared hosts
Posted by Avi in Programming on August 7th, 2009
The first time I setup an Expression Engine site on bluehost, and removed the index.php file via the .htaccess file, I ran into a problem where every template was redirecting back to the main index template. At the time, I traced this down to fact that the “segments” were not getting populated properly.
A brief search led to the EE wiki, which advocated swapping out PATH_INFO for ORIG_PATH_INFO. Although not being a fan of hacking core stuff, I was kind of cornered into this, so I went for it. This has been my running solution for the past two years.
Recently, I ran into an issue where the $_SERVER['PHP_SELF'] was not returning anything after the file name. In other words, for http://mysite/foo.php/bar, PHP_SELF should be equal to foo.php/bar.
I spoke with my host about it (a similar host to bluehost), and they said to put the following in the php.ini file: cgi.fix_pathinfo=Off
After, I did this, PHP_SELF worked fine. Unfortunately, I ran into a similar situation like I described at the outset. Then it hit me…I changed ORIG_PATH_INFO back to PATH_INFO and…it worked!
So now I listed this as another potential solution in the EE wiki.
Templatizer
Posted by Avi in Programming on May 19th, 2009
I released an extension the other day for EE. You can find it here.
The basic idea is that creating templates in Expression Engine, especially if you don’t plan to edit them from the CP, can sometimes be a little repetitive and annoying.
Normally with EE, the templates are stored in the database, and you have the option of also storing them on the filesystem. But in order for them to be recognized by EE, they must reside in the database at least.
Using this extension, you can start your template off as a physical file, and the first time you view it in the browser, it will automatically be recognized by EE and inserted into the database!
Presenting a list of Timezones to the user
Posted by Avi in Programming on March 12th, 2009
I first got into timezones when I working on an calendar app which displayed various times of day which are pertinent to Jewish daily life. The app would display calculated times which of course would differ based on the timezone of the given location. As I investigated into timezones, I found them to be fairly complicated. Not all timezones are even on the hour…some are at 30 minute offsets, some at 45 minutes, and historically there have been even stranger offsets than that.
To make matters worse, there’s the whole issue of Daylight Saving Time. Apparently some places have it some don’t. Some countries have a set date for DST, some pick a new one each year depending on circumstances. And of course, DST does not mean only adding one hour.
Read the rest of this entry »