Example #1
0
 /**
  * Standard modular run function for newsletter hooks.
  *
  * @return ?array				Tuple of result details: HTML list of all types that can be choosed, title for selection list (NULL: disabled)
  */
 function choose_categories()
 {
     if (get_forum_type() != 'ocf') {
         return NULL;
     }
     require_code('ocf_forums2');
     return array(ocf_get_forum_tree_secure(NULL, NULL, true), do_lang('SECTION_FORUMS'));
 }
Example #2
0
 /**
  * Standard function to create the standardised category tree
  *
  * @param  ID_TEXT		Notification code
  * @param  ?ID_TEXT		The ID of where we're looking under (NULL: N/A)
  * @return array 			Tree structure
  */
 function create_category_tree($notification_code, $id)
 {
     require_code('ocf_forums2');
     $notification_category = get_param('id', NULL);
     $done_in_url = is_null($notification_category);
     $total = $GLOBALS['FORUM_DB']->query_value_null_ok('f_forums', 'COUNT(*)');
     if ($total > 300) {
         return parent::create_category_tree($notification_code, $id);
     }
     // Too many, so just allow removing UI
     if (!is_null($id)) {
         if (substr($id, 0, 6) != 'forum:') {
             warn_exit(do_lang_tempcode('INTERNAL_ERROR'));
         }
         $id = substr($id, 6);
     }
     $_pagelinks = ocf_get_forum_tree_secure(NULL, is_null($id) ? NULL : intval($id), false, NULL, '', NULL, NULL, false, 1);
     $pagelinks = array();
     foreach ($_pagelinks as $p) {
         $p['id'] = 'forum:' . strval($p['id']);
         $p['title'] = do_lang('A_FORUM', $p['title']);
         $pagelinks[] = $p;
         if (!$done_in_url) {
             if ('forum:' . $p['id'] == $notification_category) {
                 $done_in_url = true;
             }
         }
     }
     if (is_null($id)) {
         $max_topic_rows = max(0, 200 - $total);
         $types2 = $GLOBALS['SITE_DB']->query_select('notifications_enabled', array('l_code_category'), array('l_notification_code' => 'ocf_topic', 'l_member_id' => get_member()), 'ORDER BY id DESC', $max_topic_rows);
         if (count($types2) == $max_topic_rows) {
             $types2 = array();
         }
         // Too many to consider
         foreach ($types2 as $type) {
             if (is_numeric($type['l_code_category'])) {
                 $title = $GLOBALS['FORUM_DB']->query_value_null_ok('f_topics', 't_cache_first_title', array('id' => intval($type['l_code_category'])));
                 if (!is_null($title)) {
                     $pagelinks[] = array('id' => $type['l_code_category'], 'title' => do_lang('A_TOPIC', $title));
                     if (!$done_in_url) {
                         if ($type['l_code_category'] == $notification_category) {
                             $done_in_url = true;
                         }
                     }
                 }
             }
         }
     }
     if (!$done_in_url && is_numeric($notification_category)) {
         $title = $GLOBALS['FORUM_DB']->query_value_null_ok('f_topics', 't_cache_first_title', array('id' => intval($notification_category)));
         $pagelinks[] = array('id' => $notification_category, 'title' => do_lang('A_TOPIC', $title));
     }
     return $pagelinks;
 }
Example #3
0
 /**
  * Standard modular page-link finder function (does not return the main entry-points that are not inside the tree).
  *
  * @param  ?integer  The number of tree levels to computer (NULL: no limit)
  * @param  boolean	Whether to not return stuff that does not support permissions (unless it is underneath something that does).
  * @param  ?string	Position to start at in the tree. Does not need to be respected. (NULL: from root)
  * @param  boolean	Whether to avoid returning categories.
  * @return ?array 	A tuple: 1) full tree structure [made up of (pagelink, permission-module, permissions-id, title, children, ?entry point for the children, ?children permission module, ?whether there are children) OR a list of maps from a get_* function] 2) permissions-page 3) optional base entry-point for the tree 4) optional permission-module 5) optional permissions-id (NULL: disabled).
  */
 function get_page_links($max_depth = NULL, $require_permission_support = false, $start_at = NULL, $dont_care_about_categories = false)
 {
     unset($require_permission_support);
     $permission_page = 'topics';
     require_code('ocf_forums');
     require_code('ocf_forums2');
     $forum_id = NULL;
     if (!is_null($start_at)) {
         $matches = array();
         if (preg_match('#[^:]*:forumview:type=misc:id=(.*)#', $start_at, $matches) != 0) {
             $forum_id = intval($matches[1]);
         }
     }
     $adjusted_max_depth = is_null($max_depth) ? NULL : (is_null($forum_id) ? $max_depth : $max_depth);
     if (get_forum_type() == 'ocf') {
         $structure = $dont_care_about_categories ? array() : ocf_get_forum_tree_secure(NULL, $forum_id, false, NULL, '', NULL, NULL, false, $adjusted_max_depth, true);
     } else {
         $structure = array();
     }
     return array($structure, $permission_page, '_SELF:_SELF:type=misc:id=!', 'forums');
 }
Example #4
0
/**
 * Generate a tempcode tree based selection list (ala nice_get_*) for choosing a forum OR a map of details. Also capable of getting comma-separated ancester forum lists. Also capable of displaying topic lists in the tree. In other words... this function is incredibly powerful, and complex.
 *
 * @param  ?MEMBER		The member that the view privileges are done for (NULL: current member).
 * @param  ?AUTO_LINK	The forum we are starting from (NULL: capture the whole tree).
 * @param  boolean		Whether to get a tempcode list (as opposed to a list of maps).
 * @param  ?array			The forum(s) to select by default (NULL: no preference). Only applies if !$topics_too. An array of AUTO_LINK's (for IDs) or strings (for names).
 * @param  string			The ancester list at this point of the recursion (blank for the start).
 * @param  ?AUTO_LINK	ID of a forum to skip display/recursion for (NULL: none).
 * @param  ?boolean		Whether the child forums are ordered alphabetically (NULL: find from DB).
 * @param  boolean		Whether to generate a compound list (a list of all the ancesters, for each point in the forum tree) as well as the tree.
 * @param  ?integer		The number of recursive levels to search (NULL: all)
 * @param  boolean		Whether to generate tree statistics.
 * @return mixed			Each tempcode of the tree if $field_format or else a list of maps, OR (if $use_compound_list) a pair of the tempcode and the compound list.
 */
function ocf_get_forum_tree_secure($member_id = NULL, $base_forum = NULL, $field_format = false, $selected_forum = NULL, $tree = '', $skip = NULL, $order_sub_alpha = NULL, $use_compound_list = false, $levels = NULL, $do_stats = false)
{
    if ($levels == -1 && !$use_compound_list) {
        return $use_compound_list ? array(array(), '') : array();
    }
    global $FORUM_TREE_SECURE_CACHE;
    if (is_null($member_id)) {
        $member_id = get_member();
    }
    if (is_null($order_sub_alpha)) {
        if (is_null($base_forum)) {
            $order_sub_alpha = false;
        } else {
            $order_sub_alpha = $GLOBALS['FORUM_DB']->query_value('f_forums', 'f_order_sub_alpha', array('id' => $base_forum));
        }
    }
    $out = array();
    $order = $order_sub_alpha ? 'f_name' : 'f_position,id';
    $forums = array();
    if (is_null($FORUM_TREE_SECURE_CACHE)) {
        $FORUM_TREE_SECURE_CACHE = mixed();
        $num_forums = $GLOBALS['FORUM_DB']->query_value('f_forums', 'COUNT(*)');
        $FORUM_TREE_SECURE_CACHE = $num_forums >= 300;
        // Mark it as 'huge'
    }
    if ($FORUM_TREE_SECURE_CACHE === true) {
        $forums = $GLOBALS['FORUM_DB']->query('SELECT id,f_order_sub_alpha,f_name,f_category_id,f_parent_forum,f_position FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_forums WHERE id IS NOT NULL AND ' . db_string_equal_to('f_redirection', '') . ' AND ' . (is_null($base_forum) ? 'f_parent_forum IS NULL' : 'f_parent_forum=' . strval($base_forum)) . ' ORDER BY f_position', 200);
    } else {
        if (is_null($FORUM_TREE_SECURE_CACHE) || $FORUM_TREE_SECURE_CACHE === false) {
            $FORUM_TREE_SECURE_CACHE = $GLOBALS['FORUM_DB']->query('SELECT id,f_order_sub_alpha,f_name,f_category_id,f_parent_forum,f_position FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_forums WHERE id IS NOT NULL AND ' . db_string_equal_to('f_redirection', '') . ' ORDER BY f_position');
        }
        foreach ($FORUM_TREE_SECURE_CACHE as $x) {
            if ($x['f_parent_forum'] === $base_forum) {
                $forums[] = $x;
            }
        }
    }
    global $M_SORT_KEY;
    $M_SORT_KEY = $order;
    uasort($forums, 'multi_sort');
    $compound_list = '';
    foreach ($forums as $forum) {
        $access = has_category_access($member_id, 'forums', strval($forum['id']));
        $cat_sort_key = '!' . (is_null($forum['f_category_id']) ? '' : strval($forum['f_category_id']));
        if ($access && $skip !== $forum['id'] && $levels !== 0) {
            $cat_bit = '';
            if (!is_null($forum['f_category_id'])) {
                global $CATEGORY_TITLES;
                if (is_null($CATEGORY_TITLES)) {
                    $CATEGORY_TITLES = collapse_2d_complexity('id', 'c_title', $GLOBALS['FORUM_DB']->query_select('f_categories', array('id', 'c_title')));
                }
                $cat_bit = array_key_exists($forum['f_category_id'], $CATEGORY_TITLES) ? $CATEGORY_TITLES[$forum['f_category_id']] : do_lang('NA');
                //if (strlen($pre.$cat_bit)>26) $cat_bit='...';
            }
            if ($field_format) {
                $pre = $tree == '' ? '' : $tree . ' > ';
                $below = ocf_get_forum_tree_secure($member_id, $forum['id'], true, $selected_forum, $pre . $forum['f_name'], $skip, $forum['f_order_sub_alpha'], $use_compound_list, NULL, $do_stats);
                if ($use_compound_list) {
                    list($below, $_compound_list) = $below;
                    $compound_list .= strval($forum['id']) . ',' . $_compound_list;
                }
                $selected = false;
                if (!is_null($selected_forum)) {
                    foreach ($selected_forum as $s) {
                        if (is_integer($s) && $s == $forum['id']) {
                            $selected = true;
                        }
                        if (is_string($s) && $s == $forum['f_name']) {
                            $selected = true;
                        }
                    }
                }
                $line = do_template('OCF_FORUM_LIST_LINE', array('_GUID' => '2fb4bd9ed5c875de6155bef588c877f9', 'PRE' => $pre, 'NAME' => $forum['f_name'], 'CAT_BIT' => $cat_bit));
                if (!array_key_exists($cat_sort_key, $out)) {
                    $out[$cat_sort_key] = '';
                }
                $out[$cat_sort_key] .= '<option value="' . (!$use_compound_list ? strval($forum['id']) : strval($forum['id']) . ',' . $_compound_list) . '"' . ($selected ? ' selected="selected"' : '') . '>' . $line->evaluate() . '</option>';
                //$out.=$below;
                if ($levels !== 0) {
                    $out[$cat_sort_key] .= $below->evaluate();
                }
            } else {
                if ($use_compound_list) {
                    $below = ocf_get_forum_tree_secure($member_id, $forum['id'], true, $selected_forum, $forum['f_name'], $skip, $forum['f_order_sub_alpha'], $use_compound_list, NULL, $do_stats);
                    list($below, $_compound_list) = $below;
                    $compound_list .= strval($forum['id']) . ',' . $_compound_list;
                }
                $element = array('id' => $forum['id'], 'compound_list' => !$use_compound_list ? strval($forum['id']) : strval($forum['id']) . ',' . $_compound_list, 'second_cat' => $cat_bit, 'title' => $forum['f_name'], 'group' => $forum['f_category_id'], 'children' => ocf_get_forum_tree_secure($member_id, $forum['id'], false, $selected_forum, $tree, $skip, false, false, $levels, $do_stats));
                if ($do_stats) {
                    $element['child_count'] = $GLOBALS['FORUM_DB']->query_value('f_forums', 'COUNT(*)', array('f_parent_forum' => $forum['id']));
                }
                if (!array_key_exists($cat_sort_key, $out)) {
                    $out[$cat_sort_key] = array();
                }
                $out[$cat_sort_key][] = $element;
            }
        }
    }
    // Up to now we worked into an array, so we could benefit from how it would auto-sort into the category>forum-position ordering ocPortal uses. Now we need to unzip it
    $real_out = mixed();
    if ($field_format) {
        $real_out = '';
        foreach ($out as $str) {
            $real_out .= $str;
        }
    } else {
        $real_out = array();
        foreach ($out as $arr) {
            $real_out = array_merge($real_out, $arr);
        }
    }
    if ($field_format) {
        if ($GLOBALS['XSS_DETECT']) {
            ocp_mark_as_escaped($real_out);
        }
        $real_out = make_string_tempcode($real_out);
    }
    if ($use_compound_list) {
        return array($real_out, $compound_list);
    } else {
        return $real_out;
    }
}
/**
 * Get a form field for editing a forum multi code, set up with a default of the given forum multi code.
 *
 * @param  SHORT_TEXT	The multi code.
 * @return tempcode		The form field.
 */
function ocf_get_forum_multi_code_field($forum_multi_code)
{
    require_code('form_templates');
    if ($forum_multi_code != '') {
        $selected = array_map('intval', explode(',', substr($forum_multi_code, 1)));
        $type = $forum_multi_code[0];
    } else {
        $selected = NULL;
        $type = '+';
    }
    require_code('ocf_forums2');
    $list = ocf_get_forum_tree_secure(NULL, NULL, true, $selected);
    return form_input_all_and_not(do_lang_tempcode('SECTION_FORUMS'), do_lang_tempcode('USE_IN_ALL_FORUMS'), 'forum_multi_code', $list, $type);
}
Example #6
0
 /**
  * Standard modular simple function for ajax-tree hooks. Returns a normal <select> style <option>-list, for fallback purposes
  *
  * @param  ?ID_TEXT		The ID to do under (NULL: root) - not always supported
  * @param  array			Options being passed through
  * @param  ?ID_TEXT		The ID to select by default (NULL: none)
  * @return tempcode		The nice list
  */
 function simple($id, $options, $it = NULL)
 {
     unset($id);
     require_code('ocf_forums2');
     $compound_list = array_key_exists('compound_list', $options) ? $options['compound_list'] : false;
     $addable_filter = array_key_exists('addable_filter', $options) ? $options['addable_filter'] : false;
     require_code('ocf_forums');
     require_code('ocf_forums2');
     $tree = ocf_get_forum_tree_secure(NULL, NULL, true, is_null($it) ? NULL : array(intval($it)), '', NULL, NULL, $compound_list, NULL, false);
     if ($compound_list) {
         list($tree, ) = $tree;
     }
     return $tree;
 }
Example #7
0
/**
 * Shows an HTML page for making block Comcode.
 */
function block_helper_script()
{
    require_lang('comcode');
    require_lang('blocks');
    require_code('zones2');
    require_code('zones3');
    check_specific_permission('comcode_dangerous');
    $title = get_page_title('BLOCK_HELPER');
    require_code('form_templates');
    require_all_lang();
    $type_wanted = get_param('block_type', 'main');
    $type = get_param('type', 'step1');
    $content = new ocp_tempcode();
    if ($type == 'step1') {
        // Find what addons all our block files are in, and icons if possible
        $hooks = find_all_hooks('systems', 'addon_registry');
        $hook_keys = array_keys($hooks);
        $hook_files = array();
        foreach ($hook_keys as $hook) {
            $path = get_file_base() . '/sources_custom/hooks/systems/addon_registry/' . filter_naughty_harsh($hook) . '.php';
            if (!file_exists($path)) {
                $path = get_file_base() . '/sources/hooks/systems/addon_registry/' . filter_naughty_harsh($hook) . '.php';
            }
            $hook_files[$hook] = file_get_contents($path);
        }
        unset($hook_keys);
        $addon_icons = array();
        $addons_blocks = array();
        foreach ($hook_files as $addon_name => $hook_file) {
            $matches = array();
            if (preg_match('#function get_file_list\\(\\)\\s*\\{([^\\}]*)\\}#', $hook_file, $matches) != 0) {
                if (!defined('HIPHOP_PHP')) {
                    $addon_files = eval($matches[1]);
                } else {
                    require_code('hooks/systems/addon_registry/' . $addon_name);
                    $hook_ob = object_factory('Hook_addon_registry_' . $addon_name);
                    $addon_files = $hook_ob->get_file_list();
                }
                foreach ($addon_files as $file) {
                    if (substr($file, 0, 31) == 'themes/default/images/bigicons/' && !array_key_exists($addon_name, $addon_icons)) {
                        $addon_icons[$addon_name] = find_theme_image('bigicons/' . basename($file, '.png'), false, true);
                    }
                    if (substr($file, 0, 21) == 'sources_custom/blocks/' || substr($file, 0, 15) == 'sources/blocks/') {
                        if ($addon_name == 'staff_messaging') {
                            $addon_name = 'core_feedback_features';
                        }
                        $addons_blocks[basename($file, '.php')] = $addon_name;
                    }
                }
            }
        }
        // Find where blocks have been used
        $block_usage = array();
        $zones = find_all_zones(false, true);
        foreach ($zones as $_zone) {
            $zone = $_zone[0];
            $pages = find_all_pages_wrap($zone, true);
            foreach ($pages as $filename => $type) {
                if (substr(strtolower($filename), -4) == '.txt') {
                    $matches = array();
                    $contents = file_get_contents(zone_black_magic_filterer((substr($type, 0, 15) == 'comcode_custom/' ? get_custom_file_base() : get_file_base()) . '/' . ($zone == '' ? '' : $zone . '/') . 'pages/' . $type . '/' . $filename));
                    //$fallback=get_file_base().'/'.(($zone=='')?'':($zone.'/')).'pages/comcode/'.fallback_lang().'/'.$filename;
                    //if (file_exists($fallback)) $contents.=file_get_contents($fallback);
                    $num_matches = preg_match_all('#\\[block[^\\]]*\\](.*)\\[/block\\]#U', $contents, $matches);
                    for ($i = 0; $i < $num_matches; $i++) {
                        $block_used = $matches[1][$i];
                        if (!array_key_exists($block_used, $block_usage)) {
                            $block_usage[$block_used] = array();
                        }
                        $block_usage[$block_used][] = $zone . ':' . basename($filename, '.txt');
                    }
                }
            }
        }
        // Show block list
        $links = new ocp_tempcode();
        $blocks = find_all_blocks();
        $dh = @opendir(get_file_base() . '/sources_custom/miniblocks');
        if ($dh !== false) {
            while (($file = readdir($dh)) !== false) {
                if (substr($file, -4) == '.php' && preg_match('#^[\\w\\-]*$#', substr($file, 0, strlen($file) - 4)) != 0) {
                    $blocks[substr($file, 0, strlen($file) - 4)] = 'sources_custom';
                }
            }
            closedir($dh);
        }
        $block_types = array();
        $block_types_icon = array();
        $keep = symbol_tempcode('KEEP');
        foreach (array_keys($blocks) as $block) {
            if (array_key_exists($block, $addons_blocks)) {
                $addon_name = $addons_blocks[$block];
                $addon_icon = array_key_exists($addon_name, $addon_icons) ? $addon_icons[$addon_name] : NULL;
                $addon_name = preg_replace('#^core\\_#', '', $addon_name);
            } else {
                $addon_name = NULL;
                $addon_icon = NULL;
            }
            $this_block_type = is_null($addon_name) || strpos($addon_name, 'block') !== false || $addon_name == 'core' ? substr($block, 0, strpos($block, '_') === false ? strlen($block) : strpos($block, '_')) : $addon_name;
            if (!array_key_exists($this_block_type, $block_types)) {
                $block_types[$this_block_type] = new ocp_tempcode();
            }
            if (!is_null($addon_icon)) {
                $block_types_icon[$this_block_type] = $addon_icon;
            }
            $block_description = do_lang('BLOCK_' . $block . '_DESCRIPTION', NULL, NULL, NULL, NULL, false);
            $block_use = do_lang('BLOCK_' . $block . '_USE', NULL, NULL, NULL, NULL, false);
            if (is_null($block_description)) {
                $block_description = '';
            }
            if (is_null($block_use)) {
                $block_use = '';
            }
            $descriptiont = $block_description == '' && $block_use == '' ? new ocp_tempcode() : do_lang_tempcode('BLOCK_HELPER_1X', $block_description, $block_use);
            $url = find_script('block_helper') . '?type=step2&block=' . urlencode($block) . '&field_name=' . get_param('field_name') . $keep->evaluate();
            if (get_param('utheme', '') != '') {
                $url .= '&utheme=' . get_param('utheme');
            }
            $url .= '&block_type=' . $type_wanted;
            $link_caption = do_lang_tempcode('NICE_BLOCK_NAME', escape_html(cleanup_block_name($block)), $block);
            $usage = array_key_exists($block, $block_usage) ? $block_usage[$block] : array();
            $block_types[$this_block_type]->attach(do_template('BLOCK_HELPER_BLOCK_CHOICE', array('USAGE' => $usage, 'DESCRIPTION' => $descriptiont, 'URL' => $url, 'LINK_CAPTION' => $link_caption)));
        }
        /*if (array_key_exists($type_wanted,$block_types)) We don't do this now, as we structure by addon name
        		{
        			$x=$block_types[$type_wanted];
        			unset($block_types[$type_wanted]);
        			$block_types=array_merge(array($type_wanted=>$x),$block_types);
        		}*/
        ksort($block_types);
        // We sort now instead
        $move_after = $block_types['adminzone_frontpage'];
        unset($block_types['adminzone_frontpage']);
        $block_types['adminzone_frontpage'] = $move_after;
        foreach ($block_types as $block_type => $_links) {
            switch ($block_type) {
                case 'side':
                case 'main':
                case 'bottom':
                    $type_title = do_lang_tempcode('BLOCKS_TYPE_' . $block_type);
                    $img = NULL;
                    break;
                default:
                    $type_title = do_lang_tempcode('BLOCKS_TYPE_ADDON', escape_html(cleanup_block_name($block_type)));
                    $img = array_key_exists($block_type, $block_types_icon) ? $block_types_icon[$block_type] : NULL;
                    break;
            }
            $links->attach(do_template('BLOCK_HELPER_BLOCK_GROUP', array('IMG' => $img, 'TITLE' => $type_title, 'LINKS' => $_links)));
        }
        $content = do_template('BLOCK_HELPER_START', array('_GUID' => 'd2d6837cdd8b19d80ea95ab9f5d09c9a', 'GET' => true, 'TITLE' => $title, 'LINKS' => $links));
    } elseif ($type == 'step2') {
        require_code('comcode_text');
        $defaults = parse_single_comcode_tag(get_param('parse_defaults', '', true), 'block');
        $block = trim(get_param('block'));
        $title = get_page_title('_BLOCK_HELPER', true, array(escape_html($block)));
        $fields = new ocp_tempcode();
        $parameters = get_block_parameters($block);
        $parameters[] = 'failsafe';
        $parameters[] = 'cache';
        $parameters[] = 'quick_cache';
        if (!isset($defaults['cache'])) {
            $defaults['cache'] = block_cache_default($block);
        }
        if (is_null($parameters)) {
            $parameters = array();
        }
        $advanced_ind = do_lang('BLOCK_IND_ADVANCED');
        $param_classes = array('normal' => array(), 'advanced' => array());
        foreach ($parameters as $parameter) {
            $param_class = 'normal';
            if ($parameter == 'cache' || $parameter == 'quick_cache' || $parameter == 'failsafe' || strpos(do_lang('BLOCK_' . $block . '_PARAM_' . $parameter), $advanced_ind) !== false) {
                $param_class = 'advanced';
            }
            $param_classes[$param_class][] = $parameter;
        }
        foreach ($param_classes as $param_class => $parameters) {
            if (count($parameters) == 0) {
                if ($param_class == 'normal') {
                    $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('SECTION_HIDDEN' => false, 'TITLE' => do_lang_tempcode('PARAMETERS'), 'HELP' => protect_from_escaping(paragraph(do_lang_tempcode('BLOCK_HELPER_NO_PARAMETERS'), '', 'nothing_here')))));
                }
                continue;
            }
            if ($param_class == 'advanced') {
                $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('SECTION_HIDDEN' => true, 'TITLE' => do_lang_tempcode('ADVANCED'))));
            }
            foreach ($parameters as $parameter) {
                $matches = array();
                switch ($parameter) {
                    case 'quick_cache':
                    case 'cache':
                    case 'failsafe':
                        $description = do_lang('BLOCK_PARAM_' . $parameter);
                        break;
                    default:
                        $description = do_lang('BLOCK_' . $block . '_PARAM_' . $parameter);
                        break;
                }
                $description = str_replace(do_lang('BLOCK_IND_STRIPPABLE_1'), '', $description);
                $description = trim(str_replace(do_lang('BLOCK_IND_ADVANCED'), '', $description));
                // Work out default value for field
                $default = '';
                if (preg_match('#' . do_lang('BLOCK_IND_DEFAULT') . ': ["\']([^"]*)["\']#Ui', $description, $matches) != 0) {
                    $default = $matches[1];
                    $has_default = true;
                    $description = preg_replace('#\\s*' . do_lang('BLOCK_IND_DEFAULT') . ': ["\']([^"]*)["\'](?-U)\\.?(?U)#Ui', '', $description);
                } else {
                    $has_default = false;
                }
                if (isset($defaults[$parameter])) {
                    $default = $defaults[$parameter];
                    $has_default = true;
                }
                // Show field
                if ($block . ':' . $parameter == 'side_stored_menu:type') {
                    $matches = array();
                    $dh = opendir(get_file_base() . '/themes/default/templates/');
                    $options = array();
                    while (($file = readdir($dh)) !== false) {
                        if (preg_match('^MENU\\_([a-z]+)\\.tpl$^', $file, $matches) != 0) {
                            $options[] = $matches[1];
                        }
                    }
                    closedir($dh);
                    $dh = opendir(get_custom_file_base() . '/themes/default/templates_custom/');
                    while (($file = readdir($dh)) !== false) {
                        if (preg_match('^MENU\\_([a-z]+)\\.tpl$^', $file, $matches) != 0 && !file_exists(get_file_base() . '/themes/default/templates/' . $file)) {
                            $options[] = $matches[1];
                        }
                    }
                    closedir($dh);
                    sort($options);
                    $list = new ocp_tempcode();
                    foreach ($options as $option) {
                        $list->attach(form_input_list_entry($option, $has_default && $option == $default));
                    }
                    $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false));
                } elseif ($block . ':' . $parameter == 'side_stored_menu:param') {
                    $list = new ocp_tempcode();
                    $rows = $GLOBALS['SITE_DB']->query_select('menu_items', array('DISTINCT i_menu'), NULL, 'ORDER BY i_menu');
                    foreach ($rows as $row) {
                        $list->attach(form_input_list_entry($row['i_menu'], $has_default && $row['i_menu'] == $default));
                    }
                    $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false));
                } elseif ($block . ':' . $parameter == 'side_shoutbox:param') {
                    $list = new ocp_tempcode();
                    $rows = $GLOBALS['SITE_DB']->query_select('chat_rooms', array('id', 'room_name'), array('is_im' => 0), '', 100);
                    foreach ($rows as $row) {
                        $list->attach(form_input_list_entry(strval($row['id']), $has_default && strval($row['id']) == $default, $row['room_name']));
                    }
                    $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false));
                } elseif ($block . ':' . $parameter == 'main_poll:param') {
                    $list = new ocp_tempcode();
                    $rows = $GLOBALS['SITE_DB']->query_select('poll', array('id', 'question'), NULL, 'ORDER BY id DESC', 100);
                    $list->attach(form_input_list_entry('', false, do_lang('NA')));
                    foreach ($rows as $row) {
                        $list->attach(form_input_list_entry(strval($row['id']), $has_default && strval($row['id']) == $default, get_translated_text($row['question'])));
                    }
                    $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false));
                } elseif ($block . ':' . $parameter == 'main_awards:param') {
                    $list = new ocp_tempcode();
                    $rows = $GLOBALS['SITE_DB']->query_select('award_types', array('id', 'a_title'));
                    foreach ($rows as $row) {
                        $list->attach(form_input_list_entry(strval($row['id']), $has_default && strval($row['id']) == $default, get_translated_text($row['a_title'])));
                    }
                    $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false));
                } elseif ($parameter == 'zone' || $parameter == 'param' && $block == 'main_as_zone_access') {
                    $list = new ocp_tempcode();
                    $list->attach(form_input_list_entry('_SEARCH', $default == ''));
                    $list->attach(nice_get_zones($default == '' ? NULL : $default));
                    $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false));
                } elseif (($parameter == 'forum' || $parameter == 'param' && in_array($block, array('main_forum_topics'))) && get_forum_type() == 'ocf') {
                    require_code('ocf_forums');
                    require_code('ocf_forums2');
                    if (!addon_installed('ocf_forum')) {
                        warn_exit(do_lang_tempcode('NO_FORUM_INSTALLED'));
                    }
                    $list = ocf_get_forum_tree_secure(NULL, NULL, true, explode(',', $default));
                    $fields->attach(form_input_multi_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list));
                } elseif ($parameter == 'param' && in_array($block, array('side_root_galleries', 'main_gallery_tease', 'main_gallery_embed', 'main_image_fader'))) {
                    require_code('galleries');
                    $list = nice_get_gallery_tree($default);
                    $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false));
                } elseif ($parameter == 'param' && in_array($block, array('main_download_category'))) {
                    require_code('downloads');
                    $list = nice_get_download_category_tree($default == '' ? NULL : intval($default));
                    $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false));
                } elseif ($parameter == 'param' && in_array($block, array('main_contact_catalogues')) || $parameter == 'catalogue' && in_array($block, array('main_recent_cc_entries'))) {
                    require_code('catalogues');
                    $list = nice_get_catalogues($default, false);
                    $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false));
                } elseif ($parameter == 'param' && in_array($block, array('main_cc_embed')) && $GLOBALS['SITE_DB']->query_value('catalogue_categories', 'COUNT(*)') < 500) {
                    $list = new ocp_tempcode();
                    $categories = $GLOBALS['SITE_DB']->query_select('catalogue_categories', array('id', 'cc_title', 'c_name'), NULL, 'ORDER BY c_name,id');
                    $last_cat = mixed();
                    foreach ($categories as $cat) {
                        if (is_null($last_cat) || $cat['c_name'] != $last_cat) {
                            $list->attach(form_input_list_entry($cat['c_name'], $has_default && $cat['c_name'] == $default, $cat['c_name'], false, true));
                            $last_cat = $cat['c_name'];
                        }
                        $list->attach(form_input_list_entry(strval($cat['id']), $has_default && strval($cat['id']) == $default, get_translated_text($cat['cc_title'])));
                    }
                    $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false));
                } elseif ($parameter == 'param' && in_array($block, array('main_banner_wave', 'main_topsites'))) {
                    require_code('banners');
                    $list = nice_get_banner_types($default);
                    $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false));
                } elseif ($parameter == 'param' && in_array($block, array('main_newsletter_signup'))) {
                    $list = new ocp_tempcode();
                    $rows = $GLOBALS['SITE_DB']->query_select('newsletters', array('id', 'title'));
                    foreach ($rows as $newsletter) {
                        $list->attach(form_input_list_entry(strval($newsletter['id']), $has_default && strval($newsletter['id']) == $default, get_translated_text($newsletter['title'])));
                    }
                    $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false));
                } elseif ($parameter == 'filter' && in_array($block, array('bottom_news', 'main_news', 'side_news', 'side_news_archive'))) {
                    require_code('news');
                    $list = nice_get_news_categories($default == '' ? -1 : intval($default));
                    $fields->attach(form_input_multi_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list));
                } elseif ($parameter == 'font') {
                    $fonts = array();
                    $dh = opendir(get_file_base() . '/data/fonts');
                    while ($f = readdir($dh)) {
                        if (substr($f, -4) == '.ttf') {
                            $fonts[] = substr($f, 0, strlen($f) - 4);
                        }
                    }
                    closedir($dh);
                    $dh = opendir(get_custom_file_base() . '/data_custom/fonts');
                    while ($f = readdir($dh)) {
                        if (substr($f, -4) == '.ttf') {
                            $fonts[] = substr($f, 0, strlen($f) - 4);
                        }
                    }
                    closedir($dh);
                    $fonts = array_unique($fonts);
                    sort($fonts);
                    $list = new ocp_tempcode();
                    foreach ($fonts as $font) {
                        $list->attach(form_input_list_entry($font, $font == $default));
                    }
                    $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false));
                } elseif (preg_match('#' . do_lang('BLOCK_IND_EITHER') . ' (.+)#i', $description, $matches) != 0) {
                    $description = preg_replace('# \\(' . do_lang('BLOCK_IND_EITHER') . '.*\\)#U', '', $description);
                    $list = new ocp_tempcode();
                    $matches2 = array();
                    $num_matches = preg_match_all('#\'([^\']*)\'="([^"]*)"#', $matches[1], $matches2);
                    if ($num_matches != 0) {
                        for ($i = 0; $i < $num_matches; $i++) {
                            $list->attach(form_input_list_entry($matches2[1][$i], $matches2[1][$i] == $default, $matches2[2][$i]));
                        }
                    } else {
                        $num_matches = preg_match_all('#\'([^\']*)\'#', $matches[1], $matches2);
                        for ($i = 0; $i < $num_matches; $i++) {
                            $list->attach(form_input_list_entry($matches2[1][$i], $matches2[1][$i] == $default));
                        }
                    }
                    $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false));
                } elseif (preg_match('#\\(' . do_lang('BLOCK_IND_HOOKTYPE') . ': \'([^\'/]*)/([^\'/]*)\'\\)#i', $description, $matches) != 0) {
                    $description = preg_replace('#\\s*\\(' . do_lang('BLOCK_IND_HOOKTYPE') . ': \'([^\'/]*)/([^\'/]*)\'\\)#i', '', $description);
                    $list = new ocp_tempcode();
                    $hooks = find_all_hooks($matches[1], $matches[2]);
                    ksort($hooks);
                    if ($default == '' && $has_default) {
                        $list->attach(form_input_list_entry('', true));
                    }
                    foreach (array_keys($hooks) as $hook) {
                        if ($block == 'side_tag_cloud') {
                            if (substr($hook, -1) == 'y') {
                                $hook .= ',' . substr($hook, 0, strlen($hook) - 1) . 'ies';
                            } elseif (substr($hook, -1) != 's' && $hook != 'quiz') {
                                $hook .= ',' . $hook . 's';
                            }
                        }
                        $list->attach(form_input_list_entry($hook, $hook == $default));
                    }
                    if ($block == 'main_search' && $parameter == 'limit_to' || $block == 'side_tag_cloud') {
                        $fields->attach(form_input_multi_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, 0));
                    } else {
                        $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false));
                    }
                } elseif (($default == '0' || $default == '1' || strpos($description, '\'0\'') !== false || strpos($description, '\'1\'') !== false) && do_lang('BLOCK_IND_WHETHER') != '' && strpos(strtolower($description), do_lang('BLOCK_IND_WHETHER')) !== false) {
                    $fields->attach(form_input_tick(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $default == '1'));
                } elseif (do_lang('BLOCK_IND_NUMERIC') != '' && strpos($description, do_lang('BLOCK_IND_NUMERIC')) !== false) {
                    $fields->attach(form_input_integer(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $default == '' ? NULL : intval($default), false));
                } else {
                    $fields->attach(form_input_line(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $default, false));
                }
            }
        }
        $keep = symbol_tempcode('KEEP');
        $post_url = find_script('block_helper') . '?type=step3&field_name=' . get_param('field_name') . $keep->evaluate();
        if (get_param('utheme', '') != '') {
            $post_url .= '&utheme=' . get_param('utheme');
        }
        $post_url .= '&block_type=' . $type_wanted;
        if (get_param('save_to_id', '') != '') {
            $post_url .= '&save_to_id=' . urlencode(get_param('save_to_id'));
            $submit_name = do_lang_tempcode('SAVE');
            // Allow remove option
            $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('SECTION_HIDDEN' => false, 'TITLE' => do_lang_tempcode('ACTIONS'), 'HELP' => '')));
            $fields->attach(form_input_tick(do_lang_tempcode('REMOVE'), '', '_delete', false));
        } else {
            $submit_name = do_lang_tempcode('USE');
        }
        $block_description = do_lang('BLOCK_' . $block . '_DESCRIPTION', NULL, NULL, NULL, NULL, false);
        if (is_null($block_description)) {
            $block_description = '';
        }
        $block_use = do_lang('BLOCK_' . $block . '_USE', NULL, NULL, NULL, NULL, false);
        if (is_null($block_use)) {
            $block_use = '';
        }
        if ($block_description == '' && $block_use == '') {
            $text = new ocp_tempcode();
        } else {
            $text = do_lang_tempcode('BLOCK_HELPER_2', escape_html(cleanup_block_name($block)), escape_html($block_description), escape_html($block_use));
        }
        $hidden = form_input_hidden('block', $block);
        $content = do_template('FORM_SCREEN', array('_GUID' => '270058349d048a8be6570bba97c81fa2', 'TITLE' => $title, 'TARGET' => '_self', 'SKIP_VALIDATION' => true, 'FIELDS' => $fields, 'URL' => $post_url, 'TEXT' => $text, 'SUBMIT_NAME' => $submit_name, 'HIDDEN' => $hidden, 'PREVIEW' => true, 'THEME' => $GLOBALS['FORUM_DRIVER']->get_theme()));
        if ($fields->is_empty()) {
            $type = 'step3';
        }
    }
    if ($type == 'step3') {
        require_javascript('javascript_posting');
        require_javascript('javascript_editing');
        $field_name = get_param('field_name');
        $bparameters = '';
        $bparameters_xml = '';
        $bparameters_tempcode = '';
        $block = trim(either_param('block'));
        $parameters = get_block_parameters($block);
        $parameters[] = 'failsafe';
        $parameters[] = 'cache';
        $parameters[] = 'quick_cache';
        if (in_array('param', $parameters)) {
            $_parameters = array('param');
            unset($parameters[array_search('param', $parameters)]);
            $parameters = array_merge($_parameters, $parameters);
        }
        foreach ($parameters as $parameter) {
            $value = post_param($parameter, NULL);
            if (is_null($value)) {
                if (post_param_integer('tick_on_form__' . $parameter, NULL) === NULL) {
                    continue;
                }
                // If not on form, continue, otherwise must be 0
                $value = '0';
            }
            if ($value != '' && ($parameter != 'failsafe' || $value == '1') && ($parameter != 'cache' || $value != block_cache_default($block)) && ($parameter != 'quick_cache' || $value == '1')) {
                if ($parameter == 'param') {
                    $bparameters .= '="' . str_replace('"', '\\"', $value) . '"';
                } else {
                    $bparameters .= ' ' . $parameter . '="' . str_replace('"', '\\"', $value) . '"';
                }
                $bparameters_xml = '<blockParam key="' . escape_html($parameter) . '" val="' . escape_html($value) . '" />';
                $bparameters_tempcode .= ',' . $parameter . '=' . str_replace(',', '\\,', $value);
            }
        }
        $comcode = '[block' . $bparameters . ']' . $block . '[/block]';
        $comcode_xml = '<block>' . $bparameters_xml . $block . '</block>';
        $tempcode = '{$BLOCK,block=' . $block . $bparameters_tempcode . '}';
        if ($type_wanted == 'template') {
            $comcode = $tempcode;
        }
        // This is what will be written in
        $comcode_semihtml = comcode_to_tempcode($comcode, NULL, false, 60, NULL, NULL, true, false, false);
        $content = do_template('BLOCK_HELPER_DONE', array('_GUID' => '575d6c8120d6001c8156560be518f296', 'TITLE' => $title, 'FIELD_NAME' => $field_name, 'BLOCK' => $block, 'COMCODE_XML' => $comcode_xml, 'COMCODE' => $comcode, 'COMCODE_SEMIHTML' => $comcode_semihtml));
    }
    global $EXTRA_HEAD;
    if (!isset($EXTRA_HEAD)) {
        $EXTRA_HEAD = new ocp_tempcode();
    }
    $EXTRA_HEAD->attach('<meta name="robots" content="noindex" />');
    // XHTMLXHTML
    $echo = do_template('POPUP_HTML_WRAP', array('TITLE' => do_lang_tempcode('BLOCK_HELPER'), 'CONTENT' => $content));
    $echo->handle_symbol_preprocessing();
    $echo->evaluate_echo();
}