function sp_compile_forums($forums, $parent = 0, $level = 0, $valueURL = false) { $out = ''; $indent = ' → '; foreach ($forums as $forum) { if ($forum->parent == $parent && $forum->forum_id != $parent) { if ($valueURL) { $out .= '<option value="' . $forum->forum_permalink . '">'; } else { $out .= '<option value="' . $forum->forum_id . '">'; } $out .= str_repeat($indent, $level) . sp_create_name_extract($forum->forum_name) . "</option>\n"; if (!empty($forum->children)) { $out .= sp_compile_forums($forums, $forum->forum_id, $level + 1, $valueURL); } } } return $out; }
function sp_QuickLinksForum($args = '', $label = '') { $defs = array('tagId' => 'spQuickLinksForum', 'tagClass' => 'spControl', 'length' => 40, 'echo' => 1); $a = wp_parse_args($args, $defs); $a = apply_filters('sph_QuickLinksForum_args', $a); extract($a, EXTR_SKIP); # sanitize before use $tagId = esc_attr($tagId); $tagClass = esc_attr($tagClass); $length = (int) $length; $echo = (int) $echo; # load data and check if empty or denied $groups = new spGroupView('', false); if ($groups->groupViewStatus == 'no access' || $groups->groupViewStatus == 'no data') { return; } $out = "<div class='{$tagClass}' id='{$tagId}'>\n"; if (!empty($label)) { $label = sp_filter_title_display($label); $indent = ' '; } if (empty($length)) { $length = 40; } $level = 0; if ($groups->pageData) { $out .= "<select id='spQuickLinksForumSelect' class='{$tagClass}' name='spQuickLinksForumSelect' "; $out .= 'onchange="javascript:spjChangeURL(this)"'; $out .= ">\n"; if ($label) { $out .= '<option>' . $label . '</option>' . "\n"; } foreach ($groups->pageData as $group) { $out .= '<optgroup class="spList" label="' . esc_attr($indent . sp_create_name_extract($group->group_name)) . '">' . "\n"; if ($group->forums) { foreach ($group->forums as $forum) { $out .= '<option value="' . $forum->forum_permalink . '">'; $out .= str_repeat($indent, $level) . sp_create_name_extract($forum->forum_name, $length) . '</option>' . "\n"; if (!empty($forum->subforums)) { $out .= sp_compile_forums($forum->subforums, $forum->forum_id, 1, true); } } } $out .= "</optgroup>\n"; } $out .= "</select>\n"; } $out .= "</div>\n"; $out = apply_filters('sph_QuickLinksForum', $out, $a); if ($echo) { echo $out; } else { return $out; } }