-
-/**
- * Returns an indent array for printMessageinfo()
- * This represents the amount of indent needed (value),
- * for this message number (key)
- */
-
-/*
- * Notes for future work:
- * indent_array should contain: indent_level, parent and flags,
- * sibling notes ..
- * To achieve that we need to define the following flags:
- * 0: hasnochildren
- * 1: haschildren
- * 2: is first
- * 4: is last
- * a node has sibling nodes if it's not the last node
- * a node has no sibling nodes if it's the last node
- * By using binary comparations we can store the flag in one var
- *
- * example:
- * -1 par = 0, level = 0, flag = 1 + 2 + 4 = 7 (haschildren, isfirst, islast)
- * \-2 par = 1, level = 1, flag = 0 + 2 = 2 (hasnochildren, isfirst)
- * |-3 par = 1, level = 1, flag = 1 + 4 = 5 (haschildren, islast)
- * \-4 par = 3, level = 2, flag = 1 + 2 + 4 = 7 (haschildren, isfirst, islast)
- * \-5 par = 4, level = 3, flag = 0 + 2 + 4 = 6 (hasnochildren, isfirst, islast)
- */
-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,$iCnt=count($thread_new[$i])-1;$k<$iCnt;++$k) {
- $chars = count_chars($thread_new[$i][$k], 1);
- if (isset($chars['40'])) { /* testing for ( */
- $level += $chars['40'];
- }
- if (isset($chars['41'])) { /* testing for ) */
- $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] += $chars['32'];
- }
- for ($x=0;$x<=$level;$x++) {
- if (isset($spaces[$x])) {
- $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] = ($indent < 0) ? 0 : $indent;
- $spaces_total = 0;
- }
- }
- return $indent_array;
-}
-
-