Skip to content
Permalink
Browse files

Introduces parse_page() and fetch_page().

Allows fetching and parsing page templates similarly to
forms. These functions do all the needed processing on the
background.

Now Textpattern also allows page templates that only
contain a single empty byte such as '0' or an empty string,
instead of displaying unexplained 404 error page. This error
page is displayed when the template is missing.

The fetching method used for pages can be extended with
a 'page.fetch' callback event, similarly to forms.

Closes issue #363

git-svn-id: http://textpattern.googlecode.com/svn/development/4.x@5228 2fea6a4d-a838-0410-917b-93a53c48e9d2
  • Loading branch information...
gocom committed Feb 16, 2013
1 parent bf4da06 commit ea0f3eac58b4fc31f6f671a206921fc6b1e08d3b
Showing with 72 additions and 13 deletions.
  1. +65 −0 textpattern/lib/txplib_misc.php
  2. +7 −13 textpattern/publish.php
@@ -4719,6 +4719,71 @@ function parse_form($name)
return $out;
}
/**
* Gets a page template's contents.
*
* The page template's reading method can be modified
* by registering a handler to a 'page.fetch' callback
* event. Any value returned by the callback function
* will be used as the template markup.
*
* @param string $name The template
* @return string|bool The page template, or FALSE on error
* @package TagParser
* @since 4.6.0
* @example
* echo fetch_page('default');
*/
function fetch_page($name)
{
if (has_handler('page.fetch'))
{
$page = callback_event('page.fetch', '', false, compact('name'));
}
else
{
$page = safe_field('user_html', 'txp_page', "name = '".doSlash($name)."'");
}
if ($page === false)
{
return false;
}
trace_add('['.gTxt('page').': '.$name.']');
return $page;
}
/**
* Parses a page template.
*
* @param string $name The template
* @return string|bool The parsed page template, or FALSE on error
* @since 4.6.0
* @package TagParser
* @example
* echo parse_page('default');
*/
function parse_page($name)
{
global $pretext;
$page = fetch_page($name);
if ($page !== false)
{
$pretext['secondpass'] = false;
$page = parse($page);
$pretext['secondpass'] = true;
trace_add('[ ~~~ '.gTxt('secondpass').' ~~~ ]');
$page = parse($page);
}
return $page;
}
/**
* Gets a category's title.
*
@@ -675,22 +675,16 @@ function textpattern()
txp_die(gTxt('410_gone'), '410');
}
$html = safe_field('user_html', 'txp_page', "name='".doSlash($pretext['page'])."'");
if (!$html)
{
txp_die(gTxt('unknown_section'), '404');
}
// Useful for clean URLs with error-handlers.
txp_status_header('200 OK');
trace_add('['.gTxt('page').': '.$pretext['page'].']');
set_error_handler("tagErrorHandler");
$pretext['secondpass'] = false;
$html = parse($html);
$pretext['secondpass'] = true;
trace_add('[ ~~~ '.gTxt('secondpass').' ~~~ ]');
$html = parse($html); // The function so nice, he ran it twice.
set_error_handler('tagErrorHandler');
$html = parse_page($pretext['page']);
if ($html === false)
{
txp_die(gTxt('unknown_section'), '404');
}
// Make sure the page has an article tag if necessary.
if (!$has_article_tag and $production_status != 'live' and $pretext['context'] == 'article' and (!empty($pretext['id']) or !empty($pretext['c']) or !empty($pretext['q']) or !empty($pretext['pg'])))

0 comments on commit ea0f3ea

Please sign in to comment.
You can’t perform that action at this time.