function entry_categories_list() { if (!($string = io_load_file(CONTENT_DIR . 'categories.txt'))) { return false; } $lines = explode("\n", trim($string)); $idstack = array(0); $indentstack = array(); // $categories = array(0=>null); $lastindent = 0; $lastid = 0; $parent = 0; $NEST = 0; foreach ($lines as $v) { $vt = trim($v); if (!$vt) { continue; } $text = ''; $indent = utils_countdashes($vt, $text); $val = explode(':', $text); $id = trim($val[1]); $label = trim($val[0]); // echo "PARSE: $id:$label\n"; if ($indent > $lastindent) { // echo "INDENT ($indent, $id, $lastid)\n"; $parent = $lastid; array_push($indentstack, $lastindent); array_push($idstack, $lastid); $lastindent = $indent; $NEST++; } elseif ($indent < $lastindent) { // echo "DEDENT ($indent)\n"; do { $dedent = array_pop($indentstack); array_pop($idstack); $NEST--; } while ($dedent > $indent); if ($dedent < $indent) { return false; } //trigger_error("failed parsing ($dedent<$indent)", E_USER_ERROR); $parent = end($idstack); $lastindent = $indent; $lastid = $id; } $lastid = $id; // echo "NEST: $NEST\n"; $categories[$id] = $parent; } return $categories; }
function do_print_categories_list(&$lines, &$indentstack, &$result, $params) { global $smarty, $fpdb; extract($params); if (empty($lines)) { $l = count($indentstack) - 1; if ($l > 0) { $arr = array_fill(0, $l, $ord . $ird); } else { $arr = array(); } $result = array_merge($result, $arr); return ''; } $str = ''; $v = reset($lines); $vt = ltrim($v); $indent = utils_countdashes($vt, $text); $indent_old = end($indentstack); $val = explode(':', $text); $vt = $val[0]; $vid = trim($val[1]); $catname = $params['name']; if ($indent > $indent_old) { array_push($indentstack, $indent); array_pop($result); array_push($result, $old); //array_push($result, $ild); do_print_categories_list($lines, $indentstack, $result, $params); } elseif ($indent < $indent_old) { array_pop($indentstack); array_push($result, $ord); array_push($result, $ird); do_print_categories_list($lines, $indentstack, $result, $params); } else { array_push($result, $ild); $cat_entry = $params['selected']; //list($catId) = each($categories); if (isset($params['type']) && ($params['type'] == 'form' || $params['type'] == 'check')) { $string = '<label><input name="' . $catname . 'cats[' . $vid . ']" '; if ((bool) array_intersect(array($vid), $cat_entry)) { $string .= 'checked="checked" '; } $string .= 'type="checkbox" />'; $before = $string; } elseif (isset($params['type']) && $params['type'] == 'radio') { $string = '<label><input name="' . $catname . 'cats" type="radio" value="' . $vid . '"'; if ((bool) array_intersect(array($vid), $cat_entry)) { $string .= 'checked="checked" '; } $string .= ' />'; $before = $string; } elseif (isset($params['type']) && $params['type'] == 'linked') { $before = '<a href="' . get_category_link($vid) . '">'; } array_push($result, $before); array_push($result, $vt); if (isset($params['type']) && ($params['type'] == 'form' || $params['type'] == 'check' || $params['type'] == 'radio')) { $string = '</label>'; $after = $string; } elseif (isset($params['type']) && $params['type'] == 'linked') { $after = '</a>'; if (isset($params['count']) && $params['count']) { $index =& $fpdb->get_index($vid); $count = $index ? $index->length() : 0; $after = " ({$count}) " . $after; } } array_push($result, $after); array_push($result, $ird); array_shift($lines); do_print_categories_list($lines, $indentstack, $result, $params); } return implode($result); }