13 **!*/ |
13 **!*/ |
14 |
14 |
15 $plugins->attachHook('render_wikiformat_posttemplates', 'halftone_process_tags($text);'); |
15 $plugins->attachHook('render_wikiformat_posttemplates', 'halftone_process_tags($text);'); |
16 $plugins->attachHook('html_attribute_whitelist', '$whitelist["halftone"] = array("title", "transpose");'); |
16 $plugins->attachHook('html_attribute_whitelist', '$whitelist["halftone"] = array("title", "transpose");'); |
17 $plugins->attachHook('session_started', 'register_special_page(\'HalftoneRender\', \'Halftone AJAX render handler\', false);'); |
17 $plugins->attachHook('session_started', 'register_special_page(\'HalftoneRender\', \'Halftone AJAX render handler\', false);'); |
|
18 $plugins->attachHook('render_getpage_norender', 'halftone_set_keys_from_tpl_vars($text);'); |
18 |
19 |
19 define('KEY_C', 0); |
20 define('KEY_C', 0); |
20 define('KEY_D', 2); |
21 define('KEY_D', 2); |
21 define('KEY_E', 4); |
22 define('KEY_E', 4); |
22 define('KEY_F', 5); |
23 define('KEY_F', 5); |
270 $result = $prechord . $kname . $match[1]; |
271 $result = $prechord . $kname . $match[1]; |
271 // echo "$chord{$match[1]} + $increment = $result<br />"; |
272 // echo "$chord{$match[1]} + $increment = $result<br />"; |
272 return $result; |
273 return $result; |
273 } |
274 } |
274 |
275 |
|
276 function halftone_set_keys_from_tpl_vars(&$text) |
|
277 { |
|
278 global $db, $session, $paths, $template, $plugins; // Common objects |
|
279 |
|
280 // did they specify a key? |
|
281 if ( !isset($template->tpl_strings['key']) ) |
|
282 { |
|
283 return false; |
|
284 } |
|
285 |
|
286 // is the key valid? |
|
287 if ( !is_string(key_to_name($template->tpl_strings['key'])) ) |
|
288 { |
|
289 return false; |
|
290 } |
|
291 |
|
292 if ( preg_match_all('/<halftone(.*?)>(.+?)<\/halftone>/s', $text, $matches) ) |
|
293 { |
|
294 foreach ( $matches[0] as $i => $whole_match ) |
|
295 { |
|
296 $attribs = decodeTagAttributes($matches[1][$i]); |
|
297 $attribs['transpose'] = $template->tpl_strings['key']; |
|
298 |
|
299 // re-encode tag attributes |
|
300 $attribs_encoded = ''; |
|
301 foreach ( $attribs as $k => $v ) |
|
302 { |
|
303 $attribs_encoded .= sprintf(" %s=\"%s\"", $k, htmlspecialchars($v)); |
|
304 } |
|
305 |
|
306 $new_match = str_replace_once('<halftone', "<halftone{$attribs_encoded}", str_replace_once($matches[1][$i], '', $whole_match)); |
|
307 $text = str_replace_once($whole_match, $new_match, $text); |
|
308 } |
|
309 } |
|
310 } |
|
311 |
275 function halftone_process_tags(&$text) |
312 function halftone_process_tags(&$text) |
276 { |
313 { |
277 global $circle_of_fifths; |
314 global $circle_of_fifths; |
278 |
315 |
279 static $css_added = false; |
316 static $css_added = false; |
413 } |
450 } |
414 } |
451 } |
415 $class_append = preg_match('/^w?c+$/', $line_pattern) ? ' labeled' : ''; |
452 $class_append = preg_match('/^w?c+$/', $line_pattern) ? ' labeled' : ''; |
416 $song .= '<span class="halftone-line' . $class_append . '">' . implode("", $line_final) . "</span>\n"; |
453 $song .= '<span class="halftone-line' . $class_append . '">' . implode("", $line_final) . "</span>\n"; |
417 } |
454 } |
418 else if ( preg_match('/^=\s*(.+?)\s*=$/', $line, $match) ) |
455 else if ( preg_match('/^=\s*(.+?)\s*=\r?$/', $line, $match) ) |
419 { |
456 { |
420 $song .= "</div>\n<div class=\"section\">\n== {$match[1]} ==\n\n"; |
457 $song .= "</div>\n<div class=\"section\">\n== {$match[1]} ==\n\n"; |
421 } |
458 } |
422 else if ( trim($line) == '' ) |
459 else if ( trim($line) == '' ) |
423 { |
460 { |