0byt3m1n1
Path:
/
data
/
0
/
0
/
6
/
46
/
6861
/
user
/
7034
/
cgi-bin
/
mt
/
docs
/
[
Home
]
File: mtmanual_dynamic.html
<html> <head> <title>DYNAMIC PUBLISHING</title> <link rel="stylesheet" href="doc-styles.css" type="text/css"> </head> <body> <h3>Movable Type User Manual: DYNAMIC PUBLISHING</h3> <p><a href="mtmanual.html">« Table of Contents</a></p> <a name="__index__"></a> <ul> <li><a href="#dynamic publishing">DYNAMIC PUBLISHING</a></li> <ul> <li><a href="#installation and requirements">Installation and Requirements</a></li> <ul> <li><a href="#requirements">Requirements</a></li> <li><a href="#enabling dynamic publishing">Enabling Dynamic Publishing</a></li> </ul> <li><a href="#advantages of dynamic publishing">Advantages of Dynamic Publishing</a></li> <li><a href="#combining static and dynamic publishing">Combining Static and Dynamic Publishing</a></li> <li><a href="#optimizing your dynamic pages">Optimizing your Dynamic Pages</a></li> <ul> <li><a href="#pagelevel caching">Page-level Caching</a></li> <li><a href="#conditional requests">Conditional Requests</a></li> </ul> <li><a href="#php plugin api">PHP Plugin API</a></li> </ul> </ul> <hr size="1" color="#CCCCCC"> <p> <h1><a name="dynamic publishing"></a>DYNAMIC PUBLISHING</h1> <p>Movable Type's dynamic publishing allows you to combine static page generation with dynamic pages on a per-template basis. You can use this to balance the publishing and traffic for your weblog, and it gives you the best of both worlds: you can turn on static page generation for frequently-requested pages like your site index and feeds, and use dynamic pages for your monthly, individual, and other archive pages. This completely eliminates the need to manually rebuild your files; when you update the design of your archive templates, for example, the design of your site will immediately be updated without requiring you to rebuild.</p> <p> <h2><a name="installation and requirements"></a>Installation and Requirements</h2> <p> <h3><a name="requirements"></a>Requirements</h3> <p>In addition to the requirements for Movable Type itself, the dynamic publishing option has the following requirements:</p> <ul> <li><strong><a name="item_A_MySQL_database"></a>A MySQL database</strong><br> Dynamic publishing requires the speed and agility of a full relational database. Therefore, the Berkeley DB format will not be supported. (PostgreSQL and SQLite support is forthcoming, but is not available in the 3.1 release.) <p></p> <li><strong><a name="item_later"></a>PHP 4.0.6 or later (NOTE!: this point should be confirmed)</strong><br> Also, your PHP installation must be compiled to work with your database. <p></p> <li><strong><a name="item_Server"></a>Apache HTTP Server or Microsoft Internet Information Server (IIS)</strong><br> For Apache installations, support for the mod_rewrite module is preferred, but not required. <p></p></ul> <p> <h3><a name="enabling dynamic publishing"></a>Enabling Dynamic Publishing</h3> <ol> <li><strong><a name="item_Turn_on_the_dynamic_page_option_in_Movable_Type%2E"></a>Turn on the dynamic page option in Movable Type.</strong><br> Go to the ``Templates'' panel in Movable Type and choose either ``Build archives dynamically'' or ``Custom'' from the ``Dynamic Building Options'' menu. If you choose ``Custom'', you will need to edit each template you want to enable as dynamic and select the ``Build this template each time it is visited'' option. <p></p> <li><strong><a name="item_Set_up_the_template_cache_directory%2E"></a>Set up the template cache directory.</strong><br> In your weblog's root directory, create a new subdirectory named templates_c. It should have a permission mask of 777. <p></p> <li><strong><a name="item_For_Apache_web_servers%3A_set_up_your_%2Ehtaccess_"></a>For Apache web servers: set up your .htaccess file.</strong><br> In your weblog root directory, you need to create a .htaccess file which will handle request for dynamic pages. This file should look like this: <pre># Disable fancy indexes, so mtview.php gets a chance... Options -Indexes <IfModule mod_rewrite.c> # The mod_rewrite solution is the preferred way to invoke # dynamic pages, because of its flexibility. # Add mtview.php to the list of DirectoryIndex options, listing it last, # so it is invoked only if the common choices aren't present... <IfModule mod_dir.c> DirectoryIndex index.php index.html index.htm default.htm default.html default.asp /mtview.php </IfModule> RewriteEngine on # don't serve mtview.php if the request is for a real directory # (allows the DirectoryIndex lookup to function) RewriteCond %{REQUEST_FILENAME} !-d # don't serve mtview.php if the request is for a real file # (allows the actual file to be served) RewriteCond %{REQUEST_FILENAME} !-f # anything else is handed to mtview.php for resolution RewriteRule ^(.*)$ /mtview.php [L,QSA] </IfModule> <IfModule !mod_rewrite.c> # if mod_rewrite is unavailable, we forward any missing page # or unresolved directory index requests to mtview # if mtview.php can resolve the request, it returns a 200 # result code which prevents any 4xx error code from going # to the server's access logs. However, an error will be # reported in the error log file. If this is your only choice, # and you want to suppress these messages, adding a "LogLevel crit" # directive within your VirtualHost or root configuration for # Apache will turn them off. ErrorDocument 404 /mtview.php ErrorDocument 403 /mtview.php </IfModule> </pre><p>(If you already have a .htaccess file, simply append the above lines to it.)</p> <p>The ``mtview.php'' script referenced above will be created once you do a rebuild of the new ``Dynamic Site Bootstrapper'' index template. If your weblog root is in a subdirectory of your site, adjust the path to the ``mtview.php'' script above to match the actual location of this file (ie: use ``/weblog/mtview.php'' if your weblog root is under a ``weblog'' directory).</p> <p></p> <li><strong><a name="item_For_Microsoft_IIS_web_servers%2C_customize_your_er"></a>For Microsoft IIS web servers, customize your error handlers:</strong><br> For Internet Information Server, you will need to configure your weblog directory to use the ``mtview.php'' script as a custom error document. You should use it for 403 and 404 errors. <p></p></ol> <p> <h2><a name="advantages of dynamic publishing"></a>Advantages of Dynamic Publishing</h2> <ul> <li><strong><a name="item_Dynamic_pages_reflect_template_changes_immediately"></a>Dynamic pages reflect template changes immediately.</strong><br> <li><strong><a name="item_Rebuild_times_are_substantially_reduced%2C_regardl"></a>Rebuild times are substantially reduced, regardless of the number of posts your blog contains.</strong><br> <li><strong><a name="item_Comment_and_trackback_pings_made_to_your_weblog_ar"></a>Comment and trackback pings made to your weblog are also faster since if your archives are dynamic.</strong><br> <li><strong><a name="item_All_trackback_pings_are_listed_on_your_dynamic_arc"></a>All trackback pings are listed on your dynamic archive pages, as soon as they are posted to the database.</strong><br> <li><strong><a name="item_You_save_a_lot_of_disk_space_by_not_building_all_t"></a>You save a lot of disk space by not building all those physical files.</strong><br> <li><strong><a name="item_You_can_have_any_number_of_presentations_of_your_s"></a>You can have any number of presentations of your site, using different index/archive templates without incurring any disk space penalty.</strong><br> </ul> <p> <h2><a name="combining static and dynamic publishing"></a>Combining Static and Dynamic Publishing</h2> <p>Movable Type has added dynamic publishing as an option in addition to the static publishing it is known for. You don't have to choose just one or the other-- you can have any combination of the two.</p> <p>This means you can enable dynamic publishing for certain index and/or archive templates and use static publishing for others. This gives you a lot of flexibility in how you publish your site. Depending on your traffic flow, you may want to continue to publish your index and Atom/RSS/RDF feeds statically if those pages receive heavy traffic.</p> <p>Archive pages are generally the best choice for dynamic publishing since they receive less traffic and consume the most disk space.</p> <p> <h2><a name="optimizing your dynamic pages"></a>Optimizing your Dynamic Pages</h2> <p>Keep in mind that by using dynamic publishing, each un-cached page view will result in a number of database queries to build the page. Depending on the performance of your web server and the complexity of your templates, this may take anywhere from a fraction of a second to several seconds. Here are some tips you can use to optimize the speed of your dynamic pages:</p> <ul> <li><strong><a name="item_For_your_main_index%2C_consider_reducing_the_numbe"></a>For your main index, consider reducing the number of entries that are displayed. Instead of using the default of the last several days of posts, try using a fixed number of posts, like this:</strong><br> <pre><MTEntries lastn="10"> </pre><p>You may tune this parameter as desired.</p> <li><strong><a name="item_speed"></a>Certain tags are more ``expensive'' than others, in terms of their execution speed (the query for producing their content is generally more complex). Tags such as ``MTArchiveList'' and ``MTSubCategories'' are good examples.</strong><br> </ul> <p> <h3><a name="pagelevel caching"></a>Page-level Caching</h3> <p><i>Note</i>: This is an experimental features which may not work in some environments.</p> <p>Another way to optimize the dynamic publishing feature is to enable page-level caching. This feature gives you near-static page speed, since the dynamic pages are cached into the file system from one request to the next. Over time, this will cause your disk space savings to shrink, but the performance benefit may be worth it.</p> <p>To enable page-level caching, you will need to create a ``cache'' subdirectory in your weblog's root directory. It should also have a permission mask of 777. After doing this, edit your ``Dynamic Site Bootstrapper'' index template and add this line:</p> <pre>$mt->caching = true; </pre><p>It should be placed just above the line that reads ``$mt->view();''. Removing this line will disable the caching option.</p> <p>Once you do that, your dynamic pages will cache themselves into the cache directory you created. Cached pages are individually rebuilt (and only upon request) when the weblog content is newer than the cached page.</p> <p> <h3><a name="conditional requests"></a>Conditional Requests</h3> <p>If you would like, you can enable conditional requests (HTTP 304 responses) for your dynamic pages. Usually when pages are generated dynamically, they are generated unconditionally. In some cases, this is desired, so conditional requests are disabled by default. You can enable them by adding this to your ``mtview.php'' script:</p> <pre>$mt->conditional = true; </pre><p>Add this above the ``$mt->view();'' line. The timestamp that is associated with the conditional requests is the last time your weblog was modified (any portion of your weblog, including comments, trackback pings, template changes, etc.).</p> <p>You can even get fancy and set the conditional behavior conditionally! Here's how you can enable it just for your feeds:</p> <pre>if (preg_match('/(index|atom)\.(rss|xml|rdf)/', $_SERVER['REQUEST_URI'])) { $mt->conditional = true; } </pre><p> <h2><a name="php plugin api"></a>PHP Plugin API</h2> <p>Movable Type's dynamic publishing mode supports plugins as well. The architecture is different, but should be familiar in some respects.</p> <p>Two key components to the PHP-based dynamic publishing engine are the Smarty template package (http://smarty.php.net/) and Justin Vincent's ezSQL library (http://php.justinvincent.com/).</p> <p>The ``php'' subdirectory under Movable Type's main directory contains all the files and resources related to the dynamic publishing engine:</p> <pre>mt/php/ lib/ Native MT tags and modules extlib/ Third-party packages (ezSQL and Smarty) plugins/ Third-party MT/PHP plugins </pre><p>Plugin files should be placed in the ``plugins'' directory. To develop MT/PHP plugins, you should familiarize yourself with how to create add-ons for Smarty. Custom blocks, functions and modifiers are the basis for adding container tags, variable tags and global filters respectively for MT/PHP.</p> <ul> <li><strong><a name="item_Variable_Tags"></a>Variable Tags</strong><br> A sample plugin that implements a custom variable tag. <ul> <li><strong><a name="item_Save_the_following_in_a_file_named_%22function%2EM"></a>Save the following in a file named ``function.MTServerUptime.php'':</strong><br> <pre><?php function smarty_function_MTServerUptime($args, &$ctx) { $data = shell_exec('uptime'); return $data; } ?> </pre><li><strong><a name="item_Upload_function%2EMTServerUptime%2Ephp_into_the_%6"></a>Upload function.MTServerUptime.php into the ``php/plugins'' subdirectory.</strong><br> <li><strong><a name="item_In_one_of_your_dynamic_templates%2C_add_the_follow"></a>In one of your dynamic templates, add the following:</strong><br> <pre>Uptime: <$MTServerUptime$> </pre><li><strong><a name="item_After_saving_this_dynamic_template%2C_look_at_it_w"></a>After saving this dynamic template, look at it with your browser. You should see the output from your system's uptime command.</strong><br> </ul> <li><strong><a name="item_Container_Tags"></a>Container Tags</strong><br> Container tags are a little more complicated than variable tags. Here's an example of one. Create ``php/plugins/block.MTLoop.php'': <pre><?php function smarty_block_MTLoop($args, $content, &$ctx, &$repeat) { if (!isset($content)) { $i = 1; } else { $i = $ctx->stash('i_value') + 1; } if ($i <= 5) { $repeat = true; } else { $repeat = false; } $ctx->stash('i_value', $i); return $content; } ?> </pre><p>And create ``php/plugins/function.MTLoopIValue.php'':</p> <pre><?php function smarty_function_MTLoopIValue($args, &$ctx) { return $ctx->stash('i_value'); } ?> </pre><p></p> <li><strong><a name="item_Conditional_Tags"></a>Conditional Tags</strong><br> A conditional tag is just another variety of a container tag. Here's a simple one (save to ``php/plugins/block.MTEntryIfTitle.php''): <pre><?php function smarty_block_MTEntryIfTitle($args, $content, &$ctx, &$repeat) { if (!isset($content)) { $e = $ctx->stash('entry'); $title = $e['entry_title']; return $ctx->_hdlr_if($args, $content, $ctx, $repeat, trim($title) != ''); } else { return $ctx->_hdlr_if($args, $content, $ctx, $repeat); } } ?> </pre><p>Please note that conditional tags should have a ``If'' somewhere in the tag name to function properly with the <MTElse> container tag.</p> <p></p> <li><strong><a name="item_Global_Filters"></a>Global Filters</strong><br> Global filters are called ``modifiers'' in Smarty terminology. They're very easy to create (save this file as ``php/plugins/modifier.rot13.php''): <pre><?php function smarty_modifier_rot13($s, $arg) { // str_rot13 is available in PHP 4.2.0 and later. return str_rot13($s); } ?> </pre><p>You can then use this filter like this:</p> <pre><$MTEntryTitle rot13="1"$> </pre><p>If you require access to the $ctx variable, you can access it through the global ``$mt'' variable, which has a method named context that returns the template context (Smarty object).</p> <p></p></ul> <p>There is a wealth of information on how to write Smarty routines on the Smarty web site: <a href="http://smarty.php.net/manual/en/plugins.php">http://smarty.php.net/manual/en/plugins.php</a></p> <hr size="1" color="#CCCCCC"> <span class="copyright">Copyright © 2001-2004 Six Apart. All Rights Reserved.</span> </body> </html>