t('Guitar chord filter')); case 'description': return t("Substitutes [a,b,...,c] with a diagram for a guitar chord where a, b,...,c are the position played on every string, or 'x' if the string is not played."); case 'prepare': return $text; case 'process': return _guitar_filter_substitute_chords($text); } } /** * Implementation of hook_filter_tips(). */ function guitar_filter_filter_tips($delta, $format, $long = FALSE) { if ($long) { return t('For example, the notation for a simple C major chord is: x,3,2,0,1,0. The x indicates a string that is not played, and the numbers indicate the position of fingers on each string. To insert that chord into your text, use [C major:x,3,2,0,1,0]'); } else { return t('To post chord diagrams, use the notation [C major:x,3,2,0,1,0]'); } } /** * Replace chord tags with chords diagrams */ function _guitar_filter_substitute_chords($text) { if (preg_match_all("/\[((([^:\]])*):)?(((\d+|x),)+(\d+|x))\]/i", $text, $match)) { foreach ($match[4] as $key => $notes) { $mtch[] = $match[0][$key]; $notes = explode(',', $notes); $name = $match[2][$key]; $repl[] = theme('guitar_diagram_chord', $notes, $name); } return str_replace($mtch, $repl, $text); } else { return $text; } }