{"id":13,"date":"2004-06-20T13:19:59","date_gmt":"2004-06-20T21:19:59","guid":{"rendered":""},"modified":"2016-05-25T23:34:41","modified_gmt":"2016-05-26T06:34:41","slug":"mt-cgi-to-php","status":"publish","type":"post","link":"https:\/\/mikeindustries.com\/blog\/archive\/2004\/06\/mt-cgi-to-php","title":{"rendered":"Converting CGI Movable Type Templates to PHP"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" src=\"\/blog\/images\/inline\/php.gif\" width=\"70\" height=\"70\" border=\"0\" class=\"rightinline\" \/>I love Movable Type.  I really do. But there are two things about it which really chap my hide. The first is that it doesn&#8217;t offer dynamic page serving, so I must recompile my entire site after making a change.  I can live with this problem as recompiling is just a question of hitting a button and waiting awhile.<\/p>\n<p>The second problem, however, is that Six Apart left a few important pages as raw CGI queries. I&#8217;m talking mainly about the Search Results page, the Comment Listing page, and the Trackback page. I understand why the company initially set things up this way since when Movable Type first came out, not nearly as many people were using PHP as they are now.  But now that PHP is so widespread, it would sure be nice if the company offered its customers an easy way to convert these templates to PHP.<\/p>\n<p>Short of this, I&#8217;d like to share the ways I de-CGI&#8217;d these templates on Mike Industries. If you build portions of your pages dynamically with PHP, this entry is for you.<br \/>\n<!--more--><\/p>\n<h4>There are three ways to eliminate CGI pages from Movable Type:<\/h4>\n<ol>\n<li>Eliminate the Movable Type CGI templates entirely<\/li>\n<li>Use PHP to parse CGI output into a format that PHP can understand<\/li>\n<li>Create PHP pages which wrap CGI pages as includes<\/li>\n<\/ol>\n<p>I ended up applying all three methods, each for a different template I was trying to deal with.  We&#8217;ll start with the Comments template.<\/p>\n<h3>window.open is so 2003<\/h3>\n<p>With the release of Movable Type 3.0, I&#8217;m not sure why Six Apart didn&#8217;t get rid of the default popup commenting system.  Comments in a popup window used to be okay until the advertising world <a href=\"http:\/\/british.nerp.net\/commentary\/x10ads.html\" >completely ruined the whole concept of a popup<\/a>. The fact is that today, people just don&#8217;t like popups.  And with Windows XP Service Pack 2 about to be released into the population, spawning them is only going to get harder.<\/p>\n<p>What a lot of Movable Type users, including myself, have done is simply place comments inline at the bottom of each post. This eliminates the popup and the resulting CGI page as well. Accomplishing this is as simple as moving the comment fields from your Comment Listing template to your Individual Archive template and changing the &#8220;Comments&#8221; link to point to your individual entry page instead of popping up the comment window.<\/p>\n<h3>Search is critical&#8230; don&#8217;t lose it<\/h3>\n<p>I&#8217;ve seen a lot of PHP-driven Movable Type blogs which have simply removed search functionality from their site, and I can only guess that it&#8217;s because the Search Results page isn&#8217;t easily skinnable out of the box. It, like the Comment Listing Page, is a .cgi page. Again, Six Apart, put your wrists out so I can slap them lightly with a ruler.<\/p>\n<p>Not wanting to ditch search functionality, I scoured the web and found that <a href=\"http:\/\/www.orangehairedboy.com\/scripts\/search_mt_with_php.php\" target=\"_blank\">one orange-haired boy from Edinburgh<\/a> had figured out a way to make a CGI sub-call from a PHP page and display the results in PHP. I know CGI like the back of somebody&#8217;s hand I&#8217;ve never met, and I only know a little more about PHP, so I won&#8217;t even attempt to explain how it&#8217;s done. All I know is that it took me 5 minutes to implement, and the Orange Haired One has easy-to-follow instructions on his site. Go check it out.<\/p>\n<h3>Don&#8217;t lack the trackback<\/h3>\n<p>As with search, a lot of people seem to have removed trackback functionality from their sites as well. Some just may not like the concept of trackbacks, but if you&#8217;ve eliminated this feature just because it&#8217;s another MT CGI annoyance, it&#8217;s time to bring it back! Trackbacks are a great indicator of who else is talking about your posts at any given time.<\/p>\n<p>I wasn&#8217;t able to find any information on Six Apart&#8217;s site or support forums related to converting the Trackbacks page to PHP so I then turned to Google.  No dice there either so it was time to apply my <a href=\"http:\/\/www.wonderquest.com\/BrainCells.htm\" target=\"_blank\">9 or 10 brain cells<\/a> worth of PHP knowledge to solving this problem on my own.<\/p>\n<p>To my surprise, the solution was dead-simple. So dead simple in fact that I&#8217;m thinking it might work well for search too. Through about 5 minutes of trial-and-error using various commands like implode() and virtual(), I found that by calling the trackback CGI template (mt-tb.cgi) from a PHP page using the include() command, both the CGI and the PHP will execute and the problem is solved! All of you PHP-heads out there are probably shaking your heads right now thinking I&#8217;m a moron for not knowing that already, but hey, there&#8217;s no documentation out there about it. I even did a Google search for &#8220;mt-tb.php&#8221; (a logical name to call your newly created PHP trackback page), and nothing came up.<\/p>\n<p>So if you&#8217;d like to turn your Trackbacks template in a PHP page, simply create a new PHP page and put this code in it:<\/p>\n<p><textarea style=\"width: 90%; height: 80px;\" wrap=\"virtual\">&lt;?php $entry_id = $_GET[&#8216;entry_id&#8217;]; $callurl = &#8220;http:\/\/path_to_original_trackback_template\/mt-tb.cgi?__mode=view&#038;entry_id=&#8221;.$entry_id; include($callurl); ?&gt;<\/textarea><\/p>\n<p>Then skin the original Trackback template, insert whatever PHP you want, and you&#8217;re set.<\/p>\n<p>As mentioned before, I&#8217;m not a PHP expert, so if you are and you see a problem with this method (or a better way to do it), please post it in the comments. I&#8217;m frankly a little surprised that CGI executes when called as a PHP include, so if this isn&#8217;t possible on all servers, it wouldn&#8217;t shock me. Works great for me though!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I love Movable Type. I really do. But there are two things about it which really chap my hide. The first is that it doesn&#8217;t offer dynamic page serving, so I must recompile my entire site after making a change. I can live with this problem as recompiling is just a question of hitting a [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[37,282],"tags":[],"class_list":["post-13","post","type-post","status-publish","format-standard","hentry","category-code","category-original"],"_links":{"self":[{"href":"https:\/\/mikeindustries.com\/blog\/wp-json\/wp\/v2\/posts\/13","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mikeindustries.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mikeindustries.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mikeindustries.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/mikeindustries.com\/blog\/wp-json\/wp\/v2\/comments?post=13"}],"version-history":[{"count":0,"href":"https:\/\/mikeindustries.com\/blog\/wp-json\/wp\/v2\/posts\/13\/revisions"}],"wp:attachment":[{"href":"https:\/\/mikeindustries.com\/blog\/wp-json\/wp\/v2\/media?parent=13"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mikeindustries.com\/blog\/wp-json\/wp\/v2\/categories?post=13"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mikeindustries.com\/blog\/wp-json\/wp\/v2\/tags?post=13"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}