mirror of
https://github.com/bcit-ci/CodeIgniter.git
synced 2025-02-20 11:13:29 +08:00
...
parent
9ed36387a2
commit
83de781851
@ -54,7 +54,7 @@ Will generate (without the spaces/linebreaks):
|
||||
</ul>[/code]
|
||||
|
||||
|
||||
[b]The contents of"generate_list_helper.php":[/b]
|
||||
[b]The contents of"generate_list_helper.php" (updated november 16, 13:25 GMT)[/b]
|
||||
[code]<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
function generate_list($resource, $options, $template)
|
||||
@ -96,7 +96,7 @@ function generate_list($resource, $options, $template)
|
||||
// place the values in the item variable
|
||||
if (!is_array($item))
|
||||
{
|
||||
$item_output = preg_replace('/\{CONTENT\}/', $item, $item_output);
|
||||
$item_output = str_replace('{CONTENT}', $item, $item_output);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -127,22 +127,19 @@ function generate_list($resource, $options, $template)
|
||||
|
||||
foreach ($item as $key => $value)
|
||||
{
|
||||
// if the value is an array, replace the first found instance of SUBS with a sublist
|
||||
// if the value is an array, replace any instance of SUBS with a sublist
|
||||
if (!is_array($value))
|
||||
{
|
||||
$item_output = preg_replace('/\{'.strtoupper($key).'\}/', $value, $item_output);
|
||||
$item_output = str_replace('{'.strtoupper($key).'}', $value, $item_output);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (empty($value)) $sublist = '';
|
||||
else $sublist = generate_list($value, $next_options, $template);
|
||||
if ($sublist != '') $sublist = $options['link'].$sublist;
|
||||
$item_output = preg_replace('/\{SUBS\}/', $sublist, $item_output, 1);
|
||||
$item_output = str_replace('{SUBS}', $sublist, $item_output);
|
||||
}
|
||||
}
|
||||
|
||||
// replace any leftover nonexisting {SUBS}
|
||||
$item_output = preg_replace('/\{SUBS\}/', '', $item_output);
|
||||
}
|
||||
|
||||
// check if any values were replaced, if not assume sublist, generate and continue
|
||||
@ -159,7 +156,7 @@ function generate_list($resource, $options, $template)
|
||||
}
|
||||
|
||||
// place the indent
|
||||
$item_output = preg_replace('/\{INDENT\}/', str_repeat($options['indent'], $options['level']), $item_output);
|
||||
$item_output = str_replace('{INDENT}', str_repeat($options['indent'], $options['level']), $item_output);
|
||||
|
||||
// if there are methods set, replace their tags
|
||||
if (count($options['functions']) > 0)
|
||||
@ -171,12 +168,12 @@ function generate_list($resource, $options, $template)
|
||||
if (method_exists($ci->$function[1], $function[0]))
|
||||
{
|
||||
$replace_value = $ci->$function[1]->$function[0]($options['level'], $options['current_alternate']);
|
||||
$item_output = preg_replace('/\{'.strtoupper($function[0]).'\}/', $replace_value, $item_output);
|
||||
$item_output = str_replace('{'.strtoupper($function[0]).'}', $replace_value, $item_output);
|
||||
}
|
||||
elseif (function_exists($function[1]))
|
||||
{
|
||||
$replace_value = $function[0]($options['level'], $options['current_alternate']);
|
||||
$item_output = preg_replace('/\{'.$function[0].'\}/', $replace_value, $item_output);
|
||||
$item_output = str_replace('{'.strtoupper($function[0]).'}', $replace_value, $item_output);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -187,7 +184,7 @@ function generate_list($resource, $options, $template)
|
||||
$alternate_max = count($options['alternate']);
|
||||
$alternate = $alternate_max;
|
||||
while($options['current_alternate'] % $alternate != 0 && $alternate > 0) $alternate--;
|
||||
$item_output = preg_replace('/\{ALTERNATE\}/', $options['alternate'][$alternate - 1], $item_output);
|
||||
$item_output = str_replace('{ALTERNATE}', $options['alternate'][$alternate - 1], $item_output);
|
||||
}
|
||||
|
||||
// link the items with the link only if it isn't the last item
|
||||
@ -200,6 +197,9 @@ function generate_list($resource, $options, $template)
|
||||
$options['current_alternate']++;
|
||||
$resource_count--;
|
||||
|
||||
// cleanup and replace any leftover tags
|
||||
$item_output = preg_replace('/\{([a-zA-z0-9_]*)\}/', '', $item_output);
|
||||
|
||||
// place the new item at the end of the current list
|
||||
$output .= $item_output;
|
||||
unset($item_output);
|
||||
|
Loading…
x
Reference in New Issue
Block a user