# HG changeset patch # User Dan Fuhry # Date 1347729493 14400 # Node ID 07ceb3e35e258e690fb356c35b266968b0c12266 # Parent c36fbf04faac7a10c4a9b7e1da53c4e3c158da63 Added support for the render_getpage_norender hook, allowing transposition to take place via the "key" parameter when including Halftone pages as templates. diff -r c36fbf04faac -r 07ceb3e35e25 Halftone.php --- a/Halftone.php Sun Sep 02 23:48:00 2012 -0400 +++ b/Halftone.php Sat Sep 15 13:18:13 2012 -0400 @@ -15,6 +15,7 @@ $plugins->attachHook('render_wikiformat_posttemplates', 'halftone_process_tags($text);'); $plugins->attachHook('html_attribute_whitelist', '$whitelist["halftone"] = array("title", "transpose");'); $plugins->attachHook('session_started', 'register_special_page(\'HalftoneRender\', \'Halftone AJAX render handler\', false);'); +$plugins->attachHook('render_getpage_norender', 'halftone_set_keys_from_tpl_vars($text);'); define('KEY_C', 0); define('KEY_D', 2); @@ -272,6 +273,42 @@ return $result; } +function halftone_set_keys_from_tpl_vars(&$text) +{ + global $db, $session, $paths, $template, $plugins; // Common objects + + // did they specify a key? + if ( !isset($template->tpl_strings['key']) ) + { + return false; + } + + // is the key valid? + if ( !is_string(key_to_name($template->tpl_strings['key'])) ) + { + return false; + } + + if ( preg_match_all('/(.+?)<\/halftone>/s', $text, $matches) ) + { + foreach ( $matches[0] as $i => $whole_match ) + { + $attribs = decodeTagAttributes($matches[1][$i]); + $attribs['transpose'] = $template->tpl_strings['key']; + + // re-encode tag attributes + $attribs_encoded = ''; + foreach ( $attribs as $k => $v ) + { + $attribs_encoded .= sprintf(" %s=\"%s\"", $k, htmlspecialchars($v)); + } + + $new_match = str_replace_once('' . implode("", $line_final) . "\n"; } - else if ( preg_match('/^=\s*(.+?)\s*=$/', $line, $match) ) + else if ( preg_match('/^=\s*(.+?)\s*=\r?$/', $line, $match) ) { $song .= "\n
\n== {$match[1]} ==\n\n"; } @@ -432,7 +469,12 @@ $song .= "$line
\n"; } } - return $song . '
'; + $song .= ''; + + //header('Content-type: text/plain'); + //die($song); + + return $song; } function page_Special_HalftoneRender()