/** * Get form inputter. * * @param string The field name * @param string The field description * @param array The field details * @param ?string The actual current value of the field (NULL: none) * @param boolean Whether this is for a new entry * @return ?tempcode The Tempcode for the input field (NULL: skip the field - it's not input) */ function get_field_inputter($_cf_name, $_cf_description, $field, $actual_value, $new) { if (is_null($actual_value)) { $actual_value = ''; } // Plug anomaly due to unusual corruption $_actual_value = explode(' ', $actual_value, 2); if (!array_key_exists(1, $_actual_value)) { $_actual_value[1] = $_actual_value[0]; } return form_input_page_link($_cf_name, $_cf_description, 'field_' . strval($field['id']), $_actual_value[0], $field['cf_required'] == 1); }
/** * Outputs a Comcode tag helper dialog. */ function comcode_helper_script() { require_lang('comcode'); $type = get_param('type', 'step1'); list($tag_list, $custom_tag_list) = _get_details_comcode_tags(); require_code('comcode_text'); global $DANGEROUS_TAGS, $TEXTUAL_TAGS; if ($type == 'step1') { $title = get_page_title('COMCODE_TAG'); $keep = symbol_tempcode('KEEP'); $comcode_groups = ''; $groups = _get_group_tags(); $non_wysiwyg_tags = _get_non_wysiwyg_tags(); $in_wysiwyg = get_param_integer('in_wysiwyg', 0) == 1; foreach ($groups as $groupname => $grouptags) { sort($grouptags); $comcode_types = ''; foreach ($grouptags as $tag) { $custom = array_key_exists($tag, $custom_tag_list); if ($in_wysiwyg && !$custom && !in_array($tag, $non_wysiwyg_tags)) { continue; } if (array_key_exists($tag, $DANGEROUS_TAGS) && !has_specific_permission(get_member(), 'comcode_dangerous')) { continue; } if ($custom) { $description = make_string_tempcode(escape_html(is_integer($custom_tag_list[$tag]['tag_description']) ? get_translated_text($custom_tag_list[$tag]['tag_description']) : $custom_tag_list[$tag]['tag_description'])); } else { $description = do_lang_tempcode('COMCODE_TAG_' . $tag); } $url = find_script('comcode_helper') . '?type=step2&tag=' . urlencode($tag) . '&field_name=' . get_param('field_name') . $keep->evaluate(); if (get_param('utheme', '') != '') { $url .= '&utheme=' . get_param('utheme'); } $link_caption = escape_html($tag); $usage = ''; $comcode_types .= static_evaluate_tempcode(do_template('BLOCK_HELPER_BLOCK_CHOICE', array('USAGE' => $usage, 'DESCRIPTION' => $description, 'URL' => $url, 'LINK_CAPTION' => $link_caption))); } if ($comcode_types != '') { $comcode_groups .= static_evaluate_tempcode(do_template('BLOCK_HELPER_BLOCK_GROUP', array('IMG' => NULL, 'TITLE' => do_lang_tempcode('COMCODE_GROUP_' . $groupname), 'LINKS' => $comcode_types))); } } $content = do_template('BLOCK_HELPER_START', array('_GUID' => 'd2d6837cdd8b19d80ea95ab9f5d09c9a', 'GET' => true, 'TITLE' => $title, 'LINKS' => $comcode_groups)); } elseif ($type == 'step2') { require_code('form_templates'); $actual_tag = get_param('tag'); if (!isset($tag_list[$actual_tag]) && !isset($custom_tag_list[$actual_tag])) { warn_exit(do_lang_tempcode('INTERNAL_ERROR')); } $tag = $actual_tag; if ($tag == 'attachment_safe') { $tag = 'attachment'; } $title = get_page_title('_COMCODE_HELPER', true, array($tag)); $fields = new ocp_tempcode(); $fields_advanced = new ocp_tempcode(); $done_tag_contents = false; $hidden = new ocp_tempcode(); $javascript = ''; $preview = true; require_code('comcode_text'); $defaults = parse_single_comcode_tag(get_param('parse_defaults', '', true), $actual_tag); $default_embed = array_key_exists('', $defaults) ? '[semihtml]' . $defaults[''] . '[/semihtml]' : get_param('default', ''); $embed_required = true; if ($tag == 'contents') { $embed_required = false; } if (isset($custom_tag_list[$tag]['tag_description'])) { $tag_description = protect_from_escaping($custom_tag_list[$tag]['tag_description']); } else { $tag_description = protect_from_escaping(do_lang('COMCODE_TAG_' . $tag)); } if (array_key_exists($tag, $tag_list)) { $params = $tag_list[$tag]; if ($tag == 'include') { $default_embed = array_key_exists('', $defaults) ? $defaults[''] : get_param('default', ''); if (strpos($default_embed, ':') === false) { $default_embed = ':' . $default_embed; } $fields->attach(form_input_page_link(do_lang_tempcode('PAGE'), '', 'tag_contents', $default_embed, true, NULL, 'comcode')); $done_tag_contents = true; } elseif ($tag == 'concepts') { foreach ($params as $param) { $description = do_lang('COMCODE_TAG_' . $tag . '_PARAM_' . $param); $fields->attach(form_input_line_multi(ucwords(str_replace('_', ' ', $param)), protect_from_escaping($description), $param, get_defaults_multi($defaults, $param), 1)); } } elseif ($tag == 'jumping') { foreach ($params as $param) { $description = do_lang('COMCODE_TAG_' . $tag . '_PARAM_' . $param); $fields->attach(form_input_line_multi(ucwords(str_replace('_', ' ', $param)), protect_from_escaping($description), $param, get_defaults_multi($defaults, $param), 2)); } } elseif ($tag == 'shocker') { foreach ($params as $param) { $description = do_lang('COMCODE_TAG_' . $tag . '_PARAM_' . $param); if ($param == 'left' || $param == 'right') { $fields->attach(form_input_line_multi(ucwords(str_replace('_', ' ', $param)), protect_from_escaping($description), $param, get_defaults_multi($defaults, $param), 2)); } else { $fields->attach(form_input_line(ucwords(str_replace('_', ' ', $param)), protect_from_escaping($description), $param, '', false)); } } } elseif ($tag == 'random') { foreach ($params as $param) { $description = do_lang('COMCODE_TAG_' . $tag . '_PARAM_' . $param); $fields->attach(form_input_line_multi(ucwords(str_replace('_', ' ', $param)), protect_from_escaping($description), $param, get_defaults_multi($defaults, $param), $param != 'X' ? 2 : 0)); } } elseif ($tag == 'sections') { foreach ($params as $param) { if ($param == 'default') { $description = do_lang('COMCODE_TAG_' . $tag . '_PARAM_' . $param); $default = array_key_exists($param, $defaults) ? $defaults[$param] : get_param('default_' . $param, '1'); $fields->attach(form_input_integer(ucwords(str_replace('_', ' ', $param)), protect_from_escaping($description), $param, intval($default), false)); } elseif ($param == 'name') { $description = do_lang('COMCODE_TAG_' . $tag . '_PARAM_' . $param); $fields->attach(form_input_line_multi(ucwords(str_replace('_', ' ', $param)), protect_from_escaping($description), $param, get_defaults_multi($defaults, $param), 2)); } } } elseif ($tag == 'big_tabs') { foreach ($params as $param) { if ($param == 'default') { $description = do_lang('COMCODE_TAG_' . $tag . '_PARAM_' . $param); $default = array_key_exists($param, $defaults) ? $defaults[$param] : get_param('default_' . $param, '1'); $fields->attach(form_input_integer(ucwords(str_replace('_', ' ', $param)), protect_from_escaping($description), $param, intval($default), false)); } elseif ($param == 'name') { $description = do_lang('COMCODE_TAG_' . $tag . '_PARAM_' . $param); $fields->attach(form_input_line_multi(ucwords(str_replace('_', ' ', $param)), protect_from_escaping($description), $param, get_defaults_multi($defaults, $param), 2)); } elseif ($param == 'switch_time') { $description = do_lang('COMCODE_TAG_' . $tag . '_PARAM_' . $param); $default = array_key_exists($param, $defaults) ? $defaults[$param] : get_param('default_' . $param, '6000'); $fields->attach(form_input_integer(ucwords(str_replace('_', ' ', $param)), protect_from_escaping($description), $param, intval($default), false)); } } } elseif ($tag == 'tabs') { foreach ($params as $param) { if ($param == 'default') { $description = do_lang('COMCODE_TAG_' . $tag . '_PARAM_' . $param); $default = array_key_exists($param, $defaults) ? $defaults[$param] : get_param('default_' . $param, '1'); $fields->attach(form_input_integer(ucwords(str_replace('_', ' ', $param)), protect_from_escaping($description), $param, intval($default), false)); } elseif ($param == 'name') { $description = do_lang('COMCODE_TAG_' . $tag . '_PARAM_' . $param); $fields->attach(form_input_line_multi(ucwords(str_replace('_', ' ', $param)), protect_from_escaping($description), $param, get_defaults_multi($defaults, $param), 2)); } } } else { if (count($params) > 0) { require_code('form_templates'); foreach ($params as $param) { $parameter_name = do_lang('COMCODE_TAG_' . $tag . '_NAME_OF_PARAM_' . $param, NULL, NULL, NULL, NULL, false); if (is_null($parameter_name)) { $parameter_name = ucwords(str_replace('_', ' ', $param)); } $descriptiont = do_lang('COMCODE_TAG_' . $tag . '_PARAM_' . $param); $supports_comcode = strpos($descriptiont, do_lang('BLOCK_IND_SUPPORTS_COMCODE')) !== false; $descriptiont = trim(str_replace(do_lang('BLOCK_IND_SUPPORTS_COMCODE'), '', $descriptiont)); $is_advanced = strpos($descriptiont, do_lang('BLOCK_IND_ADVANCED')) !== false; $descriptiont = trim(str_replace(do_lang('BLOCK_IND_ADVANCED'), '', $descriptiont)); $default = array_key_exists($param, $defaults) ? $defaults[$param] : get_param('default_' . $param, ''); if (!array_key_exists($param, $defaults)) { $matches = array(); if (preg_match('#' . do_lang('BLOCK_IND_DEFAULT') . ': ["\']([^"]*)["\']#Ui', $descriptiont, $matches) != 0) { $default = $matches[1]; } } $descriptiont = preg_replace('#\\s*' . do_lang('BLOCK_IND_DEFAULT') . ': ["\']([^"]*)["\'](?-U)\\.?(?U)#Ui', '', $descriptiont); if ($tag == 'page' && $param == 'param' && substr_count($default, ':') == 1) { $fields->attach(form_input_page_link($parameter_name, protect_from_escaping($descriptiont), $param, $default, true, NULL)); } elseif ($tag == 'attachment' && $param == 'thumb_url' && addon_installed('filedump')) { $field = form_input_tree_list(do_lang_tempcode('THUMBNAIL'), do_lang_tempcode('COMCODE_TAG_attachment_PARAM_thumb_url'), 'thumb_url', '', 'choose_filedump_file', array('only_images' => true), false, $default, false); $fields_advanced->attach($field); } else { if (substr($descriptiont, 0, 12) == '0|1 – ') { $field = form_input_tick($parameter_name, protect_from_escaping(ucfirst(substr($descriptiont, 12))), $param, $default == '1'); } elseif (substr($descriptiont, -1) != '.' && strpos($descriptiont, '|') !== false) { $list = new ocp_tempcode(); if (substr($descriptiont, 0, 1) != '=') { $list->attach(form_input_list_entry('')); } foreach (explode('|', $descriptiont) as $item) { if (strpos($item, '=') !== false) { list($item, $label) = explode('=', $item, 2); // Simplify the choices if ($tag == 'attachment') { if ($item == 'inline_extract' && get_param_integer('is_archive', NULL) === 0) { continue; } if ($item == 'island_extract' && get_param_integer('is_archive', NULL) === 0) { continue; } if ($item == 'inline' && get_param_integer('is_image', NULL) === 0) { continue; } if ($item == 'island' && get_param_integer('is_image', NULL) === 0) { continue; } if ($item == 'code' && (get_param_integer('is_image', NULL) === 1 || get_param_integer('is_archive', NULL) === 1)) { continue; } if ($item == 'mail' && get_param('default_type', NULL) !== NULL) { continue; } } $list->attach(form_input_list_entry($item, $item == $default, protect_from_escaping($label))); } else { $list->attach(form_input_list_entry($item, $item == $default)); } } $field = form_input_list($parameter_name, '', $param, $list, NULL, false, false); } elseif ($param == 'width' || $param == 'height') { $field = form_input_integer($parameter_name, protect_from_escaping($descriptiont), $param, $default == '' ? NULL : intval($default), false); } else { if ($supports_comcode) { $field = form_input_line_comcode($parameter_name, protect_from_escaping($descriptiont), $param, $default, false); } else { $field = form_input_line($parameter_name, protect_from_escaping($descriptiont), $param, $default, false); } } if ($is_advanced) { $fields_advanced->attach($field); } else { $fields->attach($field); } } } if ($tag == 'attachment') { if (get_option('eager_wysiwyg') == '0') { $field = form_input_tick(do_lang_tempcode('COMCODE_TAG_attachment_safe'), do_lang_tempcode('COMCODE_TAG_attachment_safe_DESCRIPTION'), '_safe', $actual_tag == 'attachment_safe' || $actual_tag == 'attachment2'); $fields_advanced->attach($field); } } } } } else { $_params = $custom_tag_list[$tag]; $params = explode(',', $_params['tag_parameters']); foreach ($params as $param) { $description = new ocp_tempcode(); $fields->attach(form_input_line(preg_replace('#=.*$#', '', ucwords(str_replace('_', ' ', $param))), protect_from_escaping($description), preg_replace('#=.*$#', '', $param), preg_replace('#^.*=#U', '', $param), false)); } $tag_description = new ocp_tempcode(); $tag_description->attach(is_integer($_params['tag_description']) ? get_translated_text($_params['tag_description']) : $_params['tag_description']); $tag_description->attach(paragraph(is_integer($_params['tag_example']) ? get_translated_text($_params['tag_example']) : $_params['tag_example'])); } if ($tag == 'attachment') { if (get_option('eager_wysiwyg') == '0') { $javascript .= "document.getElementById('type').onchange=function() { document.getElementById('_safe').checked=(this.options[this.selectedIndex].value=='inline'); };"; } if ($default_embed != '' || !addon_installed('filedump')) { $hidden->attach(form_input_hidden('tag_contents', $default_embed)); $tag_description = new ocp_tempcode(); if (substr($default_embed, 0, 4) == 'new_') { $preview = NULL; } } else { $filedump_url = build_url(array('page' => 'filedump'), get_module_zone('filedump')); $fields->attach(form_input_tree_list(do_lang_tempcode('FILE'), do_lang_tempcode('COMCODE_TAG_attachment_EMBED_FILE', escape_html($filedump_url->evaluate())), 'tag_contents', '', 'choose_filedump_file', array('attachment_ready' => true), true, '', false)); } } elseif ($tag == 'sections' || $tag == 'big_tabs' || $tag == 'tabs' || $tag == 'list') { $fields->attach(form_input_text_multi(do_lang_tempcode('TAG_CONTENTS'), protect_from_escaping(do_lang('COMCODE_TAG_' . $tag . '_EMBED')), 'tag_contents', explode(',', $default_embed), 2)); } elseif (array_key_exists($tag, $TEXTUAL_TAGS) || $tag == 'menu') { if ($tag == 'menu' && $default_embed == '') { $default_embed = '-contracted section +expanded section page = URL page = URL +expanded section page = URL page = URL'; } $descriptiont = do_lang('COMCODE_TAG_' . $tag . '_EMBED'); $descriptiont = trim(str_replace(do_lang('BLOCK_IND_SUPPORTS_COMCODE'), '', $descriptiont)); $fields->attach(form_input_text_comcode(do_lang_tempcode('TAG_CONTENTS'), protect_from_escaping(do_lang('COMCODE_TAG_' . $tag . '_EMBED')), 'tag_contents', $default_embed, $embed_required, NULL, true)); } else { if (!$done_tag_contents) { $descriptiont = do_lang('COMCODE_TAG_' . $tag . '_EMBED', NULL, NULL, NULL, NULL, false); if (is_null($descriptiont)) { $descriptiont = ''; } $supports_comcode = strpos($descriptiont, do_lang('BLOCK_IND_SUPPORTS_COMCODE')) !== false; $descriptiont = trim(str_replace(do_lang('BLOCK_IND_SUPPORTS_COMCODE'), '', $descriptiont)); if ($supports_comcode) { $fields->attach(form_input_line_comcode(do_lang_tempcode('TAG_CONTENTS'), protect_from_escaping($descriptiont), 'tag_contents', $default_embed, $embed_required)); } else { $fields->attach(form_input_line(do_lang_tempcode('TAG_CONTENTS'), protect_from_escaping($descriptiont), 'tag_contents', $default_embed, $embed_required)); } } } if (!$fields_advanced->is_empty()) { $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('SECTION_HIDDEN' => true, 'TITLE' => do_lang_tempcode('ADVANCED')))); $fields->attach($fields_advanced); } $keep = symbol_tempcode('KEEP'); $post_url = find_script('comcode_helper') . '?type=step3&field_name=' . get_param('field_name') . $keep->evaluate(); if (get_param('utheme', '') != '') { $post_url .= '&utheme=' . get_param('utheme'); } 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'); } $text = $tag_description->is_empty() ? new ocp_tempcode() : do_lang_tempcode('COMCODE_HELPER_2', escape_html($tag), $tag_description); $hidden->attach(form_input_hidden('tag', $tag)); $content = do_template('FORM_SCREEN', array('_GUID' => '270058349d048a8be6570bba97c81fa2', 'TITLE' => $title, 'JAVASCRIPT' => $javascript, 'TARGET' => '_self', 'SKIP_VALIDATION' => true, 'FIELDS' => $fields, 'URL' => $post_url, 'TEXT' => $text, 'SUBMIT_NAME' => $submit_name, 'HIDDEN' => $hidden, 'PREVIEW' => $preview, 'THEME' => $GLOBALS['FORUM_DRIVER']->get_theme())); } elseif ($type == 'step3') { require_javascript('javascript_posting'); require_javascript('javascript_editing'); $field_name = get_param('field_name'); $tag = post_param('tag'); $title = get_page_title('_COMCODE_HELPER', true, array($tag)); if (get_option('eager_wysiwyg') == '0') { if ($tag == 'attachment' && post_param_integer('_safe', 0) == 1) { $tag = 'attachment_safe'; } } list($comcode, $bparameters) = _get_preview_environment_comcode($tag); if ($tag == 'sections' || $tag == 'big_tabs' || $tag == 'tabs' || $tag == 'list') { $comcode_xml = $bparameters; } else { $comcode_xml = '<' . $tag . $bparameters . '>' . post_param('tag_contents', '') . '</' . $tag . '>'; } $comcode_semihtml = comcode_to_tempcode($comcode, NULL, false, 60, NULL, NULL, true, false, false); $content = do_template('BLOCK_HELPER_DONE', array('TITLE' => $title, 'FIELD_NAME' => $field_name, 'BLOCK' => $tag, 'COMCODE_XML' => $comcode_xml, 'COMCODE' => $comcode, 'COMCODE_SEMIHTML' => $comcode_semihtml)); } $content->handle_symbol_preprocessing(); $echo = do_template('POPUP_HTML_WRAP', array('TITLE' => do_lang_tempcode('COMCODE_HELPER'), 'EXTRA_HEAD' => $GLOBALS['EXTRA_HEAD'], 'EXTRA_FOOT' => $GLOBALS['EXTRA_FOOT'], 'CONTENT' => $content)); exit($echo->evaluate()); $echo->handle_symbol_preprocessing(); $echo->evaluate_echo(); }