Created
February 5, 2015 22:13
-
-
Save aprohl5/75f4e9778cc0c9e53006 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Completely changing the book tree markup | |
function mskcc_preprocess_book_tree(&$variables) { | |
//strings in need of insertion | |
$replacementBeginning = '<li class="left-navigation__item"><a class="left-navigation__item__link" '; | |
$replacementMiddle = '<span class="left-navigation__item__link__txt">'; | |
$replacementEnd = '</span><span class="arrow-right"></span></a></li>'; | |
//split up the block by link for easy loop through | |
$tree_array = explode("\n", $variables['tree']); | |
$tree_array_length = count($tree_array); | |
//reset tree for when markup will be placed back in | |
$variables['tree'] = ''; | |
//loop through each link and replace the markup | |
for ($i = 0; $i < $tree_array_length - 1; $i++) { | |
$length = strpos( $tree_array[$i], "href"); | |
$tree_array[$i] = substr_replace($tree_array[$i], $replacementBeginning, 0, $length ); | |
$start = strpos ($tree_array[$i], "</a>"); | |
$tree_array[$i] = substr_replace($tree_array[$i], $replacementEnd, $start ); | |
//prep the individual links for insertion of the middle String ($replacementMiddle) | |
$sub_tree_array = explode(">", $tree_array[$i] ); | |
$sub_tree_array_length = count($sub_tree_array); | |
$tree_array[$i] = ''; | |
for ($j = 0; $j < $sub_tree_array_length - 1; $j++) { | |
$sub_tree_array[$j] = $sub_tree_array[$j] . ">"; | |
$tree_array[$i] = $tree_array[$i] . $sub_tree_array[$j]; | |
if ( $j == 1) { | |
$tree_array[$i] = $tree_array[$i] . $replacementMiddle; | |
} | |
} | |
//put everything back together | |
$variables['tree'] = $variables['tree'] . "\n" . $tree_array[$i]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment