$value) {
// Key is either the name of the menu item or 0. Array and value are always arrays.
if($key !== 0) { // Page settings
$level[$i] = array($key, $value[0]);
if(!empty($value[0][0]) && strpos($value[0][0], $tms['self_rt_site']) === 0) { // Without this if statement all files listed in the structure will have an index in the content array.
$split = explode('#', $value[0][0]); // Use when indexing only the current page
$split = explode('?', $split[0]); // Use when indexing only the current page
$value[0][0] = $split[0]; // Use when indexing only the current page
$ci =& $tms['s']['content2'][$value[0][0]]; // Content index
// Page settings, $value[0][0] = self relative to site
$len = count($level);
foreach($tms['s']['keys'] as $k => $v) {
$def = '';
$ci[$v] = '';
// Starting from the found node, search upwards through the levels
if(empty($value[0]['_'.$v]) && empty($value[0]['_o.'.$v])) { // Search for c_$v in higher levels. The 'c_' changes the $v value to only affect children of the node it is defined on.
if(!empty($tms['s'][$v])) // key
$def = $tms['s'][$v];
for($j = $len - 2; $j > -1; $j--) { // Overwrite the default value if one exists
if(!empty($level[$j][1]['_'.$v])) { // _key of ascendent
$def = ''; // Overwrite the default
$ci[$v] .= $level[$j][1]['_'.$v];
break;
}
elseif(!empty($level[$j][1]['_d.'.$v])) { // _d.key of ascendent
$def = ''; // Overwrite the default
$ci[$v] .= $level[$j][1]['_d.'.$v];
break;
}
if(!empty($level[$j][1][$v])) { // key of ascendent
$ci[$v] .= $level[$j][1][$v]; // Add to the default
}
elseif(!empty($level[$j][1]['d.'.$v])) { // d.key of ascendent
$ci[$v] .= $level[$j][1]['d.'.$v]; // Add to the default
}
}
if(!empty($level[$len - 1][1][$v])) { // key of current
$ci[$v] .= $level[$len - 1][1][$v]; // Add to the default
}
if(!empty($level[$len - 1][1]['o.'.$v])) { // o.key of current
$ci[$v] .= $level[$len - 1][1]['o.'.$v]; // Add to the default
}
$ci[$v] = $def.$ci[$v]; // Assign the default value
}
else {
if(!empty($value[0]['_'.$v])) // _key of current
$ci[$v] .= $value[0]['_'.$v];
if(!empty($value[0]['_o.'.$v])) { // _o.key of current
$ci[$v] .= $value[0]['_o.'.$v];
}
}
}
//
for($j = count($level); --$j >= 0;)
{
$ci['branch'][$j]['title'] = $level[$j][0];
$ci['branch'][$j]['path'] = (empty($level[$j][1][0])) ? $level[$j][1]['alias'] : $level[$j][1][0];
$ci['branch'][$j]['alias'] = (empty($level[$j][1]['alias'])) ? false : true;
$ci['branch'][$j]['token'] = tms_token_encode_title($level[$j][0]);
$ci['branch'][$j]['hide_from_breadcrumb'] = (empty($level[$j][1]['hide_from_breadcrumb'])) ? false : $level[$j][1]['hide_from_breadcrumb'];
$ci['branch'][$j]['breadcrumb_title'] = (empty($level[$j][1]['breadcrumb_title'])) ? false : $level[$j][1]['breadcrumb_title'];
$ci['branch'][$j]['hide_from_title'] = (empty($level[$j][1]['hide_from_title'])) ? false : $level[$j][1]['hide_from_title'];
$ci['branch'][$j]['title_title'] = (empty($level[$j][1]['title_title'])) ? false : $level[$j][1]['title_title'];
}
$ci['title'] = $ci['section'] = $ci['section_title'] = $ci['subsection'] = $ci['subsection_title'] = $ci['previous'] = $ci['previous_title'] = $ci['next'] = $ci['next_title'] = '';
if($i) {
$ci['title'] = $level[$i - 1][0]; // Titles must already be html encoded as php array index cannot contain unusual characters.
$ci['section'] = ($i && !empty($level[$i - 1][1][0])) ? $level[$i - 1][1][0] : $level[$i - 1][1]['alias'];
$ci['section_title'] = $level[$i - 1][0];
}
foreach($value as $k => $v) {
if($k === 0)
continue;
if($k !== 0) {
$ci['subsection'] = (empty($v[0][0])) ? $v[0]['alias'] : $v[0][0];
$ci['subsection_title'] = $k;
}
break;
}
$m = 0;
$f = false;
foreach($array as $k => $v) {
if($k == $key) {
if($m == 0) {
$ci['previous'] = '';
$ci['previous_title'] = '';
}
$f = true;
}
else {
if(!$f) {
$ci['previous'] = (empty($v[0][0])) ? $v[0]['alias'] : $v[0][0];
$ci['previous_title'] = $k;
}
else {
$ci['next'] = (empty($v[0][0])) ? $v[0]['alias'] : $v[0][0];
$ci['next_title'] = $k;
break;
}
}
$m++;
}
foreach(array('next','previous','section','subsection') as $v)
if(!empty($ci[$v]) && strpos($ci[$v], '://') === false) // Path is site relative. (Determined by checking that "://", from http://, https:// or ftp:// etc. , is not in the path.
$ci[$v] = $tms['site_rt_root'].$ci[$v];
if(!empty($tms['s']['content'][$value[0][0]]))
$ci = array_merge($ci, $tms['s']['content'][$value[0][0]]);
}
tms_prepare_tms_site($value, $i, $level);
}
}
if($i == 0) {
$ci =& $tms['s']['content2'][$tms['self_rt_site']];
if(empty($ci['branch'])) { // Does not exist in structure.
$ci['title'] = $ci['section'] = $ci['section_title'] = $ci['subsection'] = $ci['subsection_title'] = $ci['previous'] = $ci['previous_title'] = $ci['next'] = $ci['next_title'] = '';
end($tms['s']['keys']);
do { // Search through site array, excluding unwanted $tms['s'] keys.
$k = current($tms['s']['keys']);
if(empty($tms['s'][$k]))
$tms['s'][$k] = false;
$ci[$k] = $tms['s'][$k]; // The default set in the constants file.
}
while(prev($tms['s']['keys']));
$ci['branch'][0]['path'] = $tms['self_rt_site'];
$ci['branch'][0]['title'] = $tms['self_rt_site'];
$ci['branch'][0]['alias'] = false;
if(!empty($tms['s']['breadcrumb_omit_unassigned'])) // Allows the unassigned breadcrumb to be removed
$ci['branch'][0]['unassigned'] = true;
if(!empty($tms['s']['content'][$tms['self_rt_site']]))
$ci = array_merge($ci, $tms['s']['content'][$tms['self_rt_site']]);
}
}
return;
}
tms_prepare_tms_site();
// Page should merge site and content[page]
$tms['p'] = $tms['s']['content2'][$tms['self_rt_site']];
//echo '
';print_r($tms['p']);echo '
';
//echo '';print_r($tms['s']['content']);echo '
';
//echo '';print_r($tms['s']['content2']);echo '
';
//echo '';print_r($tms['s']['branch']);echo '
';
//echo 'Previous: '.$tms['p']['previous'].'
';
//echo 'Previous title: '.$tms['p']['previous_title'].'
';
//echo 'Next: '.$tms['p']['next'].'
';
//echo 'Next title: '.$tms['p']['next_title'].'
';
//echo 'Section: '.$tms['p']['section'].'
';
//echo 'Section title: '.$tms['p']['section_title'].'
';
function tms_get_site_navigation($i = 0, $ni = -1, $args = false, $array = false, $max = -1, $n = '', $branch_len = 0, $first_call = true, $st = 0, $stb = 0)
{
global $tms;
if ($ni)
{
if ($first_call)
{
if ($array === false)
{
$array = $tms['s']['structure'];
// If $i != 0, find the starting point in the array.
if ($i != 0)
{
for ($j = -1; ++$j < $i;)
{
if (!empty($tms['p']['branch'][$j]) && !empty($array[$tms['p']['branch'][$j]['title']]))
{
$array = $array[$tms['p']['branch'][$j]['title']];
$tms['dstest'] .= 'xxxxxx '.$tms['p']['branch'][$j]['title']."\n";
}
else
{
$array = array ();
}
}
}
$branch_len = count($tms['p']['branch']);
if ($ni > 0)
{
$max = $i + $ni;
}
$st = $i; // st = Starting level
$stb = pow(2, $i); // st = Starting level binary
}
// On the very rare occasion that on the first call an array is passed to the function. Check PHP_SELF against the branch array.
else
{
if (empty($tms['p']['branch'][0]['unassigned']))
{
$branch_len = count($tms['p']['branch']);
$s_array = $tms['s']['structure'];
$flag = false;
for($j = 0; $j < $branch_len; $j++)
{
if($array == $s_array[$tms['p']['branch'][$j]['title']])
{
$flag = true;
break;
}
else
{
$s_array = $s_array[$tms['p']['branch'][$j]['title']];
}
}
// The array passed to the function is a sub array of the structure array.
if($flag)
{
$i = $j + 1;
}
}
// $i is now either what was sent to the function or a value representing how deep into the structure array the current array was.
if($ni > 0)
{
$max = $i + $ni;
}
$st = $i; // st = Starting level
$stb = pow(2, $i); // st = Starting level binary
}
}
else
{
$i++;
}
// Check for further items before doing the following.
if(($max < 1 || $i < $max) && is_array($array) && !empty($array) && count($array) > 0)
{
$m = 0;
foreach($array as $title => $v)
{
if($title && (empty($v[0]['hide_from_menu']) || ($v[0]['hide_from_menu'] !== true && !($v[0]['hide_from_menu'] & $stb))))
{
if(empty($v[0][0]))
{
$vo_path = $path = $v[0]['alias'];
}
else
{
$vo_path = $path = $v[0][0];
}
if(strpos($path, '://') === false) // Path is site relative. (Determined by checking that "://", from http://, https:// or ftp:// etc. , is not in the path.
{
$path = $tms['site_rt_root'].$path;
if ($tms['s']['full_uri_navigation'])
{
$path = $tms['s']['domain'].$path;
}
}
$n .= str_repeat("\t", ($i * 2) + 1).'= 0;)
{
$n .= '';
}
}
$n .= nl2br($title);
if($args['inner_spans'])
{
for($k = $args['inner_spans']; --$k >= 0;)
{
$n .= '';
}
}
$n .= '';
if(!empty($n_a))
{
$n .= "\n".str_repeat("\t", ($i * 2) + 2).'';
$n .= "\n".$n_a;
$n .= str_repeat("\t", ($i * 2) + 2).'
'."\n".str_repeat("\t", ($i * 2) + 1);
}
$n .= ''."\n";
$m++;
}
}
if($first_call && $m != 0)
{
$b = str_repeat("\t", $i * 2).'';
$n .= "\n";
}
}
}
else
{
$n = '';
}
return $n;
}
function tms_get_site_title($title = '', $s = 0) {
global $tms;
if(!$tms['s']['title_separator'] || count($tms['s']['title_separator']) == 0)
$tms['s']['title_separator'] = array(' - ');
$tms['s']['title_separator'] = array_pad($tms['s']['title_separator'], 15, $tms['s']['title_separator'][count($tms['s']['title_separator']) - 1]);
if(!empty($tms['s']['title_append'])) {
$title = $tms['s']['title_append'].$title;
}
if (!empty($tms['p']['site_title'])) {
$title = $tms['s']['title_separator'][$s].$title;
$s++;
$title = $tms['p']['site_title'].$title;
}
elseif(!empty($tms['s']['site_title'])) {
$title = $tms['s']['title_separator'][$s].$title;
$s++;
$title = $tms['s']['site_title'].$title;
}
$branch = $tms['p']['branch'];
$len = count($branch);
for($i = 0; $i < $len; $i++) {
if(!($tms['s']['breadcrumb_omit_home'] && strtolower($branch[$i]['title']) == 'home') && empty($branch[$i]['unassigned']))
$title = $branch[$i]['title'].$tms['s']['title_separator'][$s].$title;
$s++;
}
return $title;
}
function tms_get_site_title_2($title = '', $s = 0) {
global $tms;
if (!$tms['s']['title_separator'] || count($tms['s']['title_separator']) == 0) {
$tms['s']['title_separator'] = array(' - ');
}
$tms['s']['title_separator'] = array_pad($tms['s']['title_separator'], 15, $tms['s']['title_separator'][count($tms['s']['title_separator']) - 1]);
$branch = $tms['p']['branch'];
$len = count($branch);
// Remove waste titles.
for ($i = 0; $i < $len; $i++)
{
// Check if the branch item does not have hide from title.
// Check if unnassigned items should be omitted and that unnassigned pages should not be omitted from the breadcrumb.
if (empty($branch[$i]['hide_from_title']) && !((empty($tms['s']['title_omit_unassigned']) || $tms['s']['title_omit_unassigned'] === false) && !empty($branch[$i]['unassigned'])))
{
$branch_title = $branch[$i]['title'];
// Check if there is a custom breadcrumb title.
if (!empty($branch[$i]['title_title']))
{
$branch_title = $branch[$i]['title_title'];
}
$title = $branch_title.$tms['s']['title_separator'][$s].$title;
$s++;
}
}
return $title;
}
function tms_get_site_breadcrumb($breadcrumb = '') {
global $tms;
// Check if there is a custom breadcrumb start.
if ($tms['s']['breadcrumb_start'])
{
$breadcrumb .= ''.$tms['s']['breadcrumb_start'].'';
}
// Sort the branch array by key.
ksort($tms['p']['branch']);
$raw_branch = $tms['p']['branch'];
// Check if the home page should show its breadcrumb.
if ($tms['s']['breadcrumb_omit_home'] == true && strpos($raw_branch[0]['path'], '/index.') === 0)
{
array_shift($raw_branch);
}
$len = count($raw_branch);
// Check whether the breadcrumb should have a site title.
if (!empty($tms['s']['breadcrumb_with_site_title']))
{
// Check for a custom site title.
if (empty($tms['s']['breadcrumb_site_title']))
{
$title = $tms['s']['site_title'];
}
else
{
$title = $tms['s']['breadcrumb_site_title'];
}
array_unshift($raw_branch, array('title' => $title, 'path' => '/index.php', 'alias' => false,));
$len++;
}
$branch = array();
// Remove waste crumbs.
for ($i = 0; $i < $len; $i++)
{
// Check if the branch item does not have hide from breadcrumb.
// Check if unnassigned items should be omitted and that unnassigned pages should not be omitted from the breadcrumb.
if (empty($raw_branch[$i]['hide_from_breadcrumb']) && !(!empty($tms['s']['breadcrumb_omit_unassigned']) && !empty($raw_branch[$i]['unassigned'])))
{
$branch[] = $raw_branch[$i];
}
}
$len = count($branch);
// Check if breadcrumb is reversed.
$branch = ($tms['s']['breadcrumb_reversed'] === true) ? array_reverse($branch) : $branch;
$first = ($tms['s']['breadcrumb_reversed'] === true) ? $len - 1 : 0;
$last = ($tms['s']['breadcrumb_reversed'] === true) ? 0 : $len - 1;
$domain = '';
// Check if full uri is needed.
if ($tms['s']['full_uri_navigation'])
{
$domain = $tms['s']['domain'];
}
// Loop through branch.
for ($i = 0; $i < $len; $i++)
{
// Check if there is a custom breadcrumb title.
if (!empty($branch[$i]['breadcrumb_title']))
{
$branch[$i]['title'] = $branch[$i]['breadcrumb_title'];
}
// Check if there should be a separator.
if ($i != 0)
{
$breadcrumb .= $tms['s']['breadcrumb_separator'];
}
// Check if the last crumb should not be a link.
if ($tms['s']['breadcrumb_current_as_link'] === false && $i == $last)
{
$breadcrumb .= $branch[$i]['title'];
}
else
{
if ($branch[$i]['alias'] && $branch[$i]['path'] == $branch[$i + 1]['path'])
{
$breadcrumb .= $branch[$i]['title'];
}
elseif ($branch[$i]['alias'])
{
$breadcrumb .= ''.$branch[$i]['title'].'';
}
else
{
$breadcrumb .= ''.$branch[$i]['title'].'';
}
}
}
$breadcrumb .= $tms['s']['breadcrumb_end'];
return $breadcrumb;
}
function tms_get_site_breadcrumb_2() {
global $tms;
$breadcrumb = '';
// Sort the branch array by key.
ksort($tms['p']['branch']);
$raw_branch = $tms['p']['branch'];
$len = count($raw_branch);
$branch = array();
// Remove waste crumbs.
for ($i = 0; $i < $len; $i++)
{
// Check if the branch item does not have hide from breadcrumb.
// Check if unnassigned items should be omitted and that unnassigned pages should not be omitted from the breadcrumb.
if (empty($raw_branch[$i]['hide_from_breadcrumb']) && !(!empty($tms['s']['breadcrumb_omit_unassigned']) && !empty($raw_branch[$i]['unassigned'])))
{
$branch[] = $raw_branch[$i];
}
}
$len = count($branch);
// Check if breadcrumb is reversed.
$branch = ($tms['s']['breadcrumb_reversed'] === true) ? array_reverse($branch) : $branch;
$first = ($tms['s']['breadcrumb_reversed'] === true) ? $len - 1 : 0;
$last = ($tms['s']['breadcrumb_reversed'] === true) ? 0 : $len - 1;
$domain = '';
// Check if full uri is needed.
if ($tms['s']['full_uri_navigation'])
{
$domain = $tms['s']['domain'];
}
// Loop through branch.
for ($i = 0; $i < $len; $i++)
{
// Check if there is a custom breadcrumb title.
if (!empty($branch[$i]['breadcrumb_title']))
{
$branch[$i]['title'] = $branch[$i]['breadcrumb_title'];
}
// Check if there should be a separator.
if ($i != 0)
{
$breadcrumb .= $tms['s']['breadcrumb_separator'];
}
// Check if the last crumb should not be a link.
if ($tms['s']['breadcrumb_current_as_link'] === false && $i == $last)
{
$breadcrumb .= $branch[$i]['title'];
}
else
{
if ($branch[$i]['alias'] && $branch[$i]['path'] == $branch[$i + 1]['path'])
{
$breadcrumb .= $branch[$i]['title'];
}
elseif ($branch[$i]['alias'])
{
$breadcrumb .= ''.$branch[$i]['title'].'';
}
else
{
$breadcrumb .= ''.$branch[$i]['title'].'';
}
}
}
return $breadcrumb;
}
function tms_get_document_identification() {
// Example output: class="t-default"
global $tms;
$output = 't-'.$tms['p']['t'].' ';
if(!empty($tms['p']['class']))
$output .= $tms['p']['class'];
if(!empty($tms['p']['id']))
$output .= '" id="'.$tms['p']['id'];
return str_replace(' ', ' ', ' class="'.$output.'"');
}
function tms_token_encode_title($title, $prefix = '') {
return $prefix.preg_replace('/-+/', '-', preg_replace('/[^a-z0-9]/', '-', html_entity_decode(strtolower($title), ENT_QUOTES, 'ISO-8859-1'))); // UTF-8 caused a MBCS warning, maybe a bug in PHP.
}
function tms_get_date_modified($format = 'j F Y') { // l, jS F Y \a\t g:i a
//$format = str_replace('S', '\<\s\u\p\>S\<\/\s\u\p\>', $format);
$d = filemtime($_SERVER['SCRIPT_FILENAME']);
return date($format, $d);
}
// Function taken from the original tms_functions.php file
function tms_get_core_menu($menu) {
global $tms;
$core_section_uri = $tms['s']['site_up_structure'][count($tms['s']['site_up_structure']) - 1]['uri'];
echo("\t\t\t\t".''."\n");
foreach($menu as $key => $val) {
list($href, $title) = explode(':', $val);
$url = 'http://www.tcd.ie'.$href;
$class = '';
if($title == 'TCD Home')
$class = 'class="core-tab"';
echo("\t\t\t\t\t");
if($url == $core_section_uri) // If the current URL is where you are then assign id = selected to the li element.
echo('- '.$key.'
'."\n");
else
echo('- '.$key.'
'."\n");
}
echo("\t\t\t\t".'
'."\n");
}
function tms_include($filename, $top_heading_level = false) { // top_heading_level should be an integer
global $tms;
if(is_file($filename)) {
ob_start();
include($filename);
$contents = ob_get_contents();
ob_end_clean();
if($top_heading_level !== false) {
$i = 0;
for($i; ++$i < 7;)
if(strpos($contents, ' $top_heading_level)
for($j = $i - 1; ++$j < 7;) {
$contents = str_replace(' 0;) {
$d = $j - $diff;
if($d > 6)
$d = 6;
$contents = str_replace('