-* Returns an indent array for printMessageinfo()
-* This represents the amount of indent needed (value),
-* for this message number (key)
-*/
-function get_parent_level ($thread_new) {
- $parent = '';
- $child = '';
- $cutoff = 0;
-
- /* loop through the threads and take unwanted characters out
- of the thread string then chop it up
- */
- for ($i=0;$i<count($thread_new);$i++) {
- $thread_new[$i] = preg_replace("/\s\(/", "(", $thread_new[$i]);
- $thread_new[$i] = preg_replace("/(\d+)/", "$1|", $thread_new[$i]);
- $thread_new[$i] = preg_split("/\|/", $thread_new[$i], -1, PREG_SPLIT_NO_EMPTY);
- }
- $indent_array = array();
- if (!$thread_new) {
- $thread_new = array();
- }
- /* looping through the parts of one message thread */
-
- for ($i=0;$i<count($thread_new);$i++) {
- /* first grab the parent, it does not indent */
-
- if (isset($thread_new[$i][0])) {
- if (preg_match("/(\d+)/", $thread_new[$i][0], $regs)) {
- $parent = $regs[1];
- }
- }
- $indent_array[$parent] = 0;
-
- /* now the children, checking each thread portion for
- ),(, and space, adjusting the level and space values
- to get the indent level
- */
- $level = 0;
- $spaces = array();
- $spaces_total = 0;
- $indent = 0;
- $fake = FALSE;
- for ($k=1;$k<(count($thread_new[$i]))-1;$k++) {
- $chars = count_chars($thread_new[$i][$k], 1);
- if (isset($chars['40'])) { /* testing for ( */
- $level = $level + $chars['40'];
- }
- if (isset($chars['41'])) { /* testing for ) */
- $level = $level - $chars['41'];
- $spaces[$level] = 0;
- /* if we were faking lets stop, this portion
- of the thread is over
- */
- if ($level == $cutoff) {
- $fake = FALSE;
- }
- }
- if (isset($chars['32'])) { /* testing for space */
- if (!isset($spaces[$level])) {
- $spaces[$level] = 0;
- }
- $spaces[$level] = $spaces[$level] + $chars['32'];
- }
- for ($x=0;$x<=$level;$x++) {
- if (isset($spaces[$x])) {
- $spaces_total = $spaces_total + $spaces[$x];
- }
- }
- $indent = $level + $spaces_total;
- /* must have run into a message that broke the thread
- so we are adjusting for that portion
- */
- if ($fake == TRUE) {
- $indent = $indent +1;
- }
- if (preg_match("/(\d+)/", $thread_new[$i][$k], $regs)) {
- $child = $regs[1];
- }
- /* the thread must be broken if $indent == 0
- so indent the message once and start faking it
- */
- if ($indent == 0) {
- $indent = 1;
- $fake = TRUE;
- $cutoff = $level;
- }
- /* dont need abs but if indent was negative
- errors would occur
- */
- $indent_array[$child] = abs($indent);
- $spaces_total = 0;
- }
- }
- return $indent_array;
-}
-