Exemplo n.º 1
0
 /**
  * Standard modular run function for OcCLE hooks.
  *
  * @param  array	The options with which the command was called
  * @param  array	The parameters with which the command was called
  * @param  array	A reference to the OcCLE filesystem object
  * @return array	Array of stdcommand, stdhtml, stdout, and stderr responses
  */
 function run($options, $parameters, &$occle_fs)
 {
     if (array_key_exists('h', $options) || array_key_exists('help', $options)) {
         return array('', do_command_help('exit', array('h'), array()), '', '');
     } else {
         return array('if (document.getElementById(\'occle_box\')) load_occle(); else window.location.href=\'' . xmlentities(addslashes(static_evaluate_tempcode(build_url(array('page' => ''), '')))) . '\';', '', do_lang('SUCCESS'), '');
     }
 }
Exemplo n.º 2
0
 /**
  * The UI to delete trackbacks.
  *
  * @return tempcode		The UI
  */
 function choose()
 {
     $title = get_page_title('MANAGE_TRACKBACKS');
     $trackback_rows = $GLOBALS['SITE_DB']->query_select('trackbacks', array('*'), NULL, 'ORDER BY id DESC', 1000);
     $trackbacks = '';
     foreach ($trackback_rows as $value) {
         $trackbacks .= static_evaluate_tempcode(do_template('TRACKBACK', array('ID' => strval($value['id']), 'TIME_RAW' => strval($value['trackback_time']), 'TIME' => get_timezoned_date($value['trackback_time']), 'URL' => $value['trackback_url'], 'TITLE' => $value['trackback_title'], 'EXCERPT' => $value['trackback_excerpt'], 'NAME' => $value['trackback_name'])));
     }
     return do_template('TRACKBACK_DELETE_SCREEN', array('_GUID' => '51f7e4c1976bcaf120758d2c86771289', 'TITLE' => $title, 'TRACKBACKS' => $trackbacks, 'LOTS' => count($trackback_rows) == 1000));
 }
Exemplo n.º 3
0
 /**
  * Standard modular run function for ajax-tree hooks. Generates XML for a tree list, which is interpreted by Javascript and expanded on-demand (via new calls).
  *
  * @param  ?ID_TEXT		The ID to do under (NULL: root)
  * @param  array			Options being passed through
  * @param  ?ID_TEXT		The ID to select by default (NULL: none)
  * @return string			XML in the special category,entry format
  */
 function run($id, $options, $default = NULL)
 {
     if ($id === NULL) {
         $id = '';
     }
     require_code('files2');
     require_code('images');
     $fullpath = get_custom_file_base() . '/uploads/filedump';
     if ($id != '') {
         $fullpath .= '/' . $id;
     }
     $folder = isset($options['folder']) && $options['folder'];
     // We want to select folders, not files
     $out = '';
     if (has_actual_page_access(NULL, 'filedump') && file_exists($fullpath)) {
         $files = get_directory_contents($fullpath, '', false, false);
         foreach ($files as $f) {
             $description = $GLOBALS['SITE_DB']->query_value_null_ok('filedump', 'description', array('name' => basename($f), 'path' => $id . '/'));
             if (isset($options['attachment_ready']) && $options['attachment_ready']) {
                 $entry_id = 'url_' . 'uploads/filedump/' . ($id == '' ? '' : rawurlencode($id) . '/') . rawurlencode($f);
             } else {
                 $entry_id = 'uploads/filedump/' . ($id == '' ? '' : rawurlencode($id) . '/') . rawurlencode($f);
             }
             if (is_dir($fullpath . '/' . $f)) {
                 $has_children = count(get_directory_contents($fullpath . '/' . $f, '', false, false)) > 0;
                 $out .= '<category id="' . xmlentities(($id == '' ? '' : $id . '/') . $f) . '" title="' . xmlentities($f) . '" has_children="' . ($has_children ? 'true' : 'false') . '" selectable="' . ($folder ? 'true' : 'false') . '"></category>';
             } elseif (!$folder) {
                 if (!isset($options['only_images']) || !$options['only_images'] || is_image($f)) {
                     if (is_null($description) || get_translated_text($description) == '') {
                         $_description = '';
                         if (is_image($f)) {
                             $url = get_custom_base_url() . '/uploads/filedump/' . ($id == '' ? '' : $id . '/') . $f;
                             $_description = static_evaluate_tempcode(do_image_thumb($url, '', true, true));
                         }
                     } else {
                         $_description = escape_html(get_translated_text($description));
                     }
                     $out .= '<entry id="' . xmlentities($entry_id) . '" title="' . xmlentities($f) . '" description_html="' . xmlentities($_description) . '" selectable="true"></entry>';
                 }
             }
         }
         // Mark parent cats for pre-expansion
         if (!is_null($default) && $default != '') {
             $cat = '';
             foreach (explode('/', $default) as $_cat) {
                 if ($_cat != '') {
                     $cat .= '/';
                     $cat .= $_cat;
                 }
                 $out .= '<expand>' . $cat . '</expand>';
             }
         }
     }
     return '<result>' . $out . '</result>';
 }
Exemplo n.º 4
0
 /**
  * Standard modular run function for OcCLE hooks.
  *
  * @param  array	The options with which the command was called
  * @param  array	The parameters with which the command was called
  * @param  array	A reference to the OcCLE filesystem object
  * @return array	Array of stdcommand, stdhtml, stdout, and stderr responses
  */
 function run($options, $parameters, &$occle_fs)
 {
     if (array_key_exists('h', $options) || array_key_exists('help', $options)) {
         return array('', do_command_help('clear_caches', array('h'), array(true)), '', '');
     } else {
         require_code('view_modes');
         $_caches = mixed();
         if (array_key_exists(0, $parameters)) {
             $_caches = array();
             $caches = explode(',', $parameters[0]);
             foreach ($caches as $cache) {
                 $_caches[] = trim($cache);
             }
         }
         $messages = static_evaluate_tempcode(ocportal_cleanup($_caches));
         if ($messages == '') {
             $messages = do_lang('SUCCESS');
         }
         return array('', $messages, '', '');
     }
 }
Exemplo n.º 5
0
/**
 * Recurser helper function for _build_keep_post_fields.
 *
 * @param  ID_TEXT		Key name to put value under
 * @param  mixed			Value (string or array)
 * @return string			The builtup hidden form fields
 */
function _fixed_post_parser($key, $value)
{
    $out = '';
    if (!is_string($key)) {
        $key = strval($key);
    }
    if (is_array($value)) {
        foreach ($value as $k => $v) {
            if (is_string($k)) {
                $out .= _fixed_post_parser($key . '[' . $k . ']', $v);
            } else {
                $out .= _fixed_post_parser($key . '[' . strval($k) . ']', $v);
            }
        }
    } else {
        if (get_magic_quotes_gpc()) {
            $value = stripslashes($value);
        }
        $out .= static_evaluate_tempcode(form_input_hidden($key, is_string($value) ? $value : strval($value)));
    }
    return $out;
}
Exemplo n.º 6
0
/**
 * Create a form field input matrix for permission setting.
 *
 * @param  ID_TEXT		Permission ID (pagelink style) for the resource being set
 * @param  array			An inverted list showing what view permissions are set for what we're setting permissions for
 * @param  array			List of overridable privilege codes for what we're setting permissions for
 * @param  array			List of privilege settings relating to what we're setting permissions for, from the database
 * @param  array			Multi-dimensional array showing what the inherited defaults for this permission would be
 * @param  boolean		Whether to not include the stuff to make it fit alongside other form fields in a normal form table
 * @param  ?tempcode		Label for view permissions (NULL: default)
 * @return tempcode		The form field matrix
 */
function get_permissions_matrix($server_id, $access, $overridables, $specific_permissions, $default_access, $no_outer = false, $pinterface_view = NULL)
{
    require_lang('permissions');
    require_javascript('javascript_permissions');
    $admin_groups = $GLOBALS['FORUM_DRIVER']->get_super_admin_groups();
    $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(true, true);
    if (is_null($pinterface_view)) {
        $pinterface_view = do_lang_tempcode('PINTERFACE_VIEW');
    }
    // Permission rows for matrix
    $permission_rows = new ocp_tempcode();
    $all_groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(true);
    foreach (array_keys($access) as $id) {
        if (!array_key_exists($id, $groups) && array_key_exists($id, $all_groups)) {
            $groups[$id] = $all_groups[$id];
        }
    }
    foreach ($groups as $id => $group_name) {
        if (!in_array($id, $admin_groups)) {
            $perhaps = count($access) == 0 ? 1 : $access[$id];
            $view_access = $perhaps == 1;
            $tabindex = get_form_field_tabindex(NULL);
            $overrides = new ocp_tempcode();
            $all_global = true;
            foreach (array_keys($overridables) as $override) {
                if (isset($specific_permissions[$override][$id])) {
                    $all_global = false;
                }
            }
            foreach ($overridables as $override => $cat_support) {
                $lang_string = do_lang_tempcode('PT_' . $override);
                if (is_array($cat_support)) {
                    $lang_string = do_lang_tempcode($cat_support[1]);
                }
                if (is_array($cat_support)) {
                    $cat_support = $cat_support[0];
                }
                if ($cat_support == 0) {
                    continue;
                }
                $overrides->attach(do_template('FORM_SCREEN_INPUT_PERMISSION_OVERRIDE', array('FORCE_PRESETS' => $no_outer, 'GROUP_NAME' => $group_name, 'VIEW_ACCESS' => $view_access, 'TABINDEX' => strval($tabindex), 'GROUP_ID' => strval($id), 'SP' => $override, 'ALL_GLOBAL' => $all_global, 'TITLE' => $lang_string, 'DEFAULT_ACCESS' => $default_access[$id][$override], 'CODE' => isset($specific_permissions[$override][$id]) ? $specific_permissions[$override][$id] : '-1')));
            }
            $permission_rows->attach(do_template('FORM_SCREEN_INPUT_PERMISSION', array('_GUID' => 'e2c4459ae995d33376c07e498f1d973a', 'FORCE_PRESETS' => $no_outer, 'GROUP_NAME' => $group_name, 'OVERRIDES' => $overrides->evaluate(), 'ALL_GLOBAL' => $all_global, 'VIEW_ACCESS' => $view_access, 'TABINDEX' => strval($tabindex), 'GROUP_ID' => strval($id), 'PINTERFACE_VIEW' => $pinterface_view)));
        } else {
            $overridables_filtered = array();
            foreach ($overridables as $override => $cat_support) {
                if (is_array($cat_support)) {
                    $cat_support = $cat_support[0];
                }
                if ($cat_support == 1) {
                    $overridables_filtered[$override] = 1;
                }
            }
            $permission_rows->attach(do_template('FORM_SCREEN_INPUT_PERMISSION_ADMIN', array('FORCE_PRESETS' => $no_outer, 'OVERRIDES' => $overridables_filtered, 'GROUP_NAME' => $group_name, 'GROUP_ID' => strval($id), 'PINTERFACE_VIEW' => $pinterface_view)));
        }
    }
    if (count($overridables) == 0 && !$no_outer) {
        return $permission_rows;
    }
    // Find out colour for our vertical text image headings (CSS can't rotate text), using the CSS as a basis
    $tmp_file = @file_get_contents(get_custom_file_base() . '/themes/' . $GLOBALS['FORUM_DRIVER']->get_theme() . '/templates_cached/' . user_lang() . '/global.css');
    $color = 'FF00FF';
    $matches = array();
    if ($tmp_file !== false) {
        if (preg_match('#\\nth.*\\sbackground-color:\\s*\\#([\\dA-Fa-f]*);.*\\}#sU', $tmp_file, $matches) != 0) {
            $color = $matches[1];
        }
    }
    // For heading up the table matrix
    $overrides_array = array();
    foreach ($overridables as $override => $cat_support) {
        $lang_string = do_lang_tempcode('PT_' . $override);
        if (is_array($cat_support)) {
            $lang_string = do_lang_tempcode($cat_support[1]);
        }
        if (is_array($cat_support)) {
            $cat_support = $cat_support[0];
        }
        if ($cat_support == 0) {
            continue;
        }
        $overrides_array[$override] = array('TITLE' => $lang_string);
    }
    // Finish off the matrix and return
    $inner = do_template('FORM_SCREEN_INPUT_PERMISSION_MATRIX', array('_GUID' => '0f019c7e60366fa04058097ee6f3829a', 'SERVER_ID' => $server_id, 'COLOR' => $color, 'OVERRIDES' => $overrides_array, 'PERMISSION_ROWS' => $permission_rows));
    if ($no_outer) {
        return make_string_tempcode(static_evaluate_tempcode($inner));
    }
    return make_string_tempcode(static_evaluate_tempcode(do_template('FORM_SCREEN_INPUT_PERMISSION_MATRIX_OUTER', array('_GUID' => '2a2f9f78f3639185300c92cab50767c5', 'INNER' => $inner))));
}
/*
This script will spot when a theme has bits of default theme CSS that is not adjusted for that theme's seed.
It could fix CSS upgraded via diff, or just poor copy-and-pasting of code back from the default theme CSS files.

Take BACKUPs before running this.
*/
require_code('themewizard');
$theme = get_param('theme', NULL);
if ($theme === NULL) {
    echo '<p>You must pick a theme&hellip;</p><ul>';
    require_code('themes2');
    $themes = find_all_themes();
    foreach (array_keys($themes) as $theme) {
        if ($theme != 'default') {
            echo '<li><a href="' . static_evaluate_tempcode(build_url(array('page' => 'fix_partial_themewizard_css', 'theme' => $theme), 'adminzone')) . '">' . escape_html($theme) . '</a></li>';
        }
    }
    echo '</ul>';
    return;
}
$seed = find_theme_seed($theme);
$dark = find_theme_dark($theme);
$default_seed = get_param('force_default_seed', find_theme_seed('default'));
if ($default_seed == $seed) {
    warn_exit('Theme has same seed as default theme, cannot continue, would be a no-op.');
}
list($canonical_theme_map, $canonical_theme_landscape) = calculate_theme($default_seed, 'default', 'equations', 'colours', false);
list($theme_map, $theme_landscape) = calculate_theme($seed, 'default', 'equations', 'colours', $dark);
// ===
// CSS
Exemplo n.º 8
0
/**
 * 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 &ndash; ') {
                                $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();
}
Exemplo n.º 9
0
require_code('points');
$_id = isset($map['param']) ? $map['param'] : '';
if ($_id == '') {
    $id = get_member();
} else {
    $id = intval($_id);
}
$username = $GLOBALS['FORUM_DRIVER']->get_username($id);
$group_points = get_group_points();
$fields = new ocp_tempcode();
asort($group_points);
echo '<div class="wide_table_wrap"><table class="solidborder wide_table spaced_table"><thead></thead><tbody><tr><th>Usergroup</th><th>One-off point bonus</th><th>Monthly points</th><th>' . escape_html($username) . ' in this group?</th></tr>';
$groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(false, true, true);
$my_groups = $GLOBALS['FORUM_DRIVER']->get_members_groups($id);
$done = 0;
foreach ($group_points as $group_id => $points) {
    if ($points['p_points_one_off'] != 0 || in_array($group_id, $my_groups)) {
        $group_name = $groups[$group_id];
        echo '<tr
		><td>' . escape_html($group_name) . '</td>
		<td>' . escape_html(integer_format($points['p_points_one_off'])) . '</td>
		<td>' . escape_html(integer_format($points['p_points_per_month'])) . ' <span class="associated_details">per month</span></td>
		<td>' . (in_array($group_id, $my_groups) ? '<img src="' . escape_html(find_theme_image('checklist/checklist1')) . '" /> Yes' : '<img src="' . escape_html(find_theme_image('checklist/checklist0')) . '" /> No') . '</td>
		</tr>';
        $done++;
    }
}
if ($done == 0) {
    echo '<tr><td colspan="4"><p class="nothing_here">No bonuses configured yet. <a href="' . escape_html(static_evaluate_tempcode(build_url(array('page' => 'group_points'), 'adminzone'))) . '">Configure bonuses here</a>.</p></td></tr>';
}
echo '</tbody></table></div>';
Exemplo n.º 10
0
/**
 * Implement a rating at the quantum level.
 *
 * @param  ?integer		Rating given (NULL: unrate)
 * @range 1 10
 * @param  ID_TEXT		The page name the rating is on
 * @param  MEMBER			The member doing the rating
 * @param  ID_TEXT		The type (download, etc) that this rating is for
 * @param  ID_TEXT		The second level type (probably blank)
 * @param  ID_TEXT		The ID of the type that this rating is for
 * @param  ?string		The title to where the commenting will pass back to (to put into the comment topic header) (NULL: don't know)
 * @param  mixed			The URL to where the commenting will pass back to (to put into the comment topic header) (URLPATH or Tempcode)
 */
function actualise_specific_rating($rating, $page_name, $member_id, $content_type, $type, $content_id, $content_url, $content_title)
{
    if (!is_null($rating)) {
        if ($rating > 10 || $rating < 1) {
            log_hack_attack_and_exit('VOTE_CHEAT');
        }
    }
    $rating_for_type = $content_type . ($type == '' ? '' : '_' . $type);
    if (!has_specific_permission($member_id, 'rate', $page_name)) {
        return;
    }
    $already_rated = already_rated(array($rating_for_type), $content_id);
    if (!is_null($rating)) {
        if ($already_rated) {
            // Delete, in preparation for re-rating
            $GLOBALS['SITE_DB']->query_delete('rating', array('rating_for_type' => $rating_for_type, 'rating_for_id' => $content_id, 'rating_member' => $member_id, 'rating_ip' => get_ip_address()));
        }
    }
    list($_content_title, $submitter, , $safe_content_url, $cma_info) = get_details_behind_feedback_code($content_type, $content_id);
    if (is_null($content_title)) {
        $content_title = $_content_title;
    }
    if ($member_id === $submitter && !is_guest($member_id)) {
        return;
    }
    if (!is_null($rating)) {
        $GLOBALS['SITE_DB']->query_insert('rating', array('rating_for_type' => $rating_for_type, 'rating_for_id' => $content_id, 'rating_member' => $member_id, 'rating_ip' => get_ip_address(), 'rating_time' => time(), 'rating' => $rating));
    } else {
        $GLOBALS['SITE_DB']->query_delete('rating', array('rating_for_type' => $rating_for_type, 'rating_for_id' => $content_id, 'rating_member' => $member_id, 'rating_ip' => get_ip_address()));
    }
    // Top rating / liked
    if ($rating === 10 && $type == '') {
        $content_type_title = $content_type;
        if (!is_null($cma_info) && isset($cma_info['content_type_label'])) {
            $content_type_title = do_lang($cma_info['content_type_label']);
        }
        // Special case. Would prefer not to hard-code, but important for usability
        if ($content_type == 'post' && $content_title == '' && get_forum_type() == 'ocf') {
            $content_title = do_lang('POST_IN', $GLOBALS['FORUM_DB']->query_value('f_topics', 't_cache_first_title', array('id' => $GLOBALS['FORUM_DB']->query_value('f_posts', 'p_topic_id', array('id' => intval($content_id))))));
        }
        if (!is_null($submitter) && !is_guest($submitter)) {
            // Give points
            if ($member_id != $submitter) {
                if (addon_installed('points') && !$already_rated) {
                    require_code('points2');
                    require_lang('points');
                    system_gift_transfer(do_lang('CONTENT_LIKED'), intval(get_option('points_if_liked')), $submitter);
                }
            }
            // Notification
            require_code('notifications');
            $subject = do_lang('CONTENT_LIKED_NOTIFICATION_MAIL_SUBJECT', get_site_name(), $content_title == '' ? ocp_mb_strtolower($content_type_title) : $content_title);
            $rendered_award = '';
            $award_hook = convert_ocportal_type_codes('feedback_type_code', $content_type, 'award_hook');
            if ($award_hook != '') {
                require_code('hooks/systems/awards/' . $award_hook);
                $award_ob = object_factory('Hook_awards_' . $award_hook);
                $award_content_row = content_get_row($content_id, $award_ob->info());
                if (!is_null($award_content_row)) {
                    $rendered_award = preg_replace('#&amp;keep_\\w+=[^&]*#', '', static_evaluate_tempcode($award_ob->run($award_content_row, '_SEARCH')));
                }
            }
            $mail = do_lang('CONTENT_LIKED_NOTIFICATION_MAIL', comcode_escape(get_site_name()), comcode_escape($content_title == '' ? ocp_mb_strtolower($content_type_title) : $content_title), array(comcode_escape(is_object($safe_content_url) ? $safe_content_url->evaluate() : $safe_content_url), $rendered_award, comcode_escape($GLOBALS['FORUM_DRIVER']->get_username(get_member()))));
            dispatch_notification('like', NULL, $subject, $mail, array($submitter));
        }
        // Put on activity wall / whatever
        $real_content_type = convert_ocportal_type_codes('feedback_type_code', $content_type, 'cma_hook');
        if (may_view_content_behind_feedback_code($GLOBALS['FORUM_DRIVER']->get_guest_id(), $real_content_type, $content_id)) {
            if (is_null($submitter)) {
                $submitter = $GLOBALS['FORUM_DRIVER']->get_guest_id();
            }
            $activity_type = is_null($submitter) || is_guest($submitter) ? '_ACTIVITY_LIKES' : 'ACTIVITY_LIKES';
            if ($content_title == '') {
                syndicate_described_activity($activity_type . '_UNTITLED', ocp_mb_strtolower($content_type_title), $content_type_title, '', url_to_pagelink(is_object($safe_content_url) ? $safe_content_url->evaluate() : $safe_content_url), '', '', convert_ocportal_type_codes('feedback_type_code', $content_type, 'addon_name'), 1, NULL, false, $submitter);
            } else {
                syndicate_described_activity($activity_type, $content_title, ocp_mb_strtolower($content_type_title), $content_type_title, url_to_pagelink(is_object($safe_content_url) ? $safe_content_url->evaluate() : $safe_content_url), '', '', convert_ocportal_type_codes('feedback_type_code', $content_type, 'addon_name'), 1, NULL, false, $submitter);
            }
        }
    }
    // Enter them for a prize draw to win a free jet
    // NOT IMPLEMENTED- Anyone want to donate the jet?
}
Exemplo n.º 11
0
 /**
  * The UI to confirm sending of our newsletter.
  *
  * @return tempcode		The UI
  */
 function confirm_send()
 {
     $title = get_page_title('NEWSLETTER_SEND');
     $message = post_param('message');
     $subject = post_param('subject');
     $lang = choose_language($title);
     $template = post_param('template', 'MAIL');
     $in_full = post_param_integer('in_full', 0);
     $html_only = post_param_integer('html_only', 0);
     $from_email = post_param('from_email', '');
     $from_name = post_param('from_name', '');
     $extra_post_data = array();
     require_code('uploads');
     if (is_swf_upload(true) && array_key_exists('file', $_FILES) || array_key_exists('file', $_FILES) && is_uploaded_file($_FILES['file']['tmp_name'])) {
         $_csv_data = array();
         $myfile = fopen($_FILES['file']['tmp_name'], 'rt');
         $del = ',';
         $csv_test_line = fgetcsv($myfile, 4096, $del);
         if (count($csv_test_line) == 1 && strpos($csv_test_line[0], ';') !== false) {
             $del = ';';
         }
         rewind($myfile);
         while (($csv_line = fgetcsv($myfile, 4096, $del)) !== false) {
             $_csv_data[] = $csv_line;
         }
         fclose($myfile);
         $extra_post_data['csv_data'] = serialize($_csv_data);
     }
     if (post_param_integer('make_periodic', 0) == 1) {
         // We're making a periodic newsletter. Thus we need to pass this info
         // through to the next step
         $extra_post_data['make_periodic'] = '1';
         // Re-generate preview from latest chosen_categories
         $message = $this->generate_whats_new_comcode(post_param('chosen_categories', ''), $in_full, $lang, get_input_date('cutoff'));
     }
     $address = $GLOBALS['FORUM_DRIVER']->get_member_email_address(get_member());
     if ($address == '') {
         $address = get_option('staff_address');
     }
     $username = $GLOBALS['FORUM_DRIVER']->get_username(get_member());
     $message = newsletter_variable_substitution($message, $subject, '', '', do_lang('UNKNOWN'), $address, 'test', '');
     require_code('mail');
     require_code('tempcode_compiler');
     $in_html = false;
     if (strpos($message, '<html') !== false) {
         $_preview = template_to_tempcode($message);
         $in_html = true;
     } else {
         $comcode_version = comcode_to_tempcode($message, get_member(), true);
         $_preview = do_template('MAIL', array('TITLE' => $subject, 'CSS' => css_tempcode(true, true, $comcode_version->evaluate()), 'LANG' => get_site_default_lang(), 'LOGOURL' => get_logo_url(''), 'CONTENT' => $comcode_version), NULL, false, NULL, '.tpl', 'templates', $GLOBALS['FORUM_DRIVER']->get_theme(''));
         $in_html = $html_only == 1;
     }
     $text_preview = $html_only == 1 ? '' : comcode_to_clean_text(static_evaluate_tempcode(template_to_tempcode($message)));
     require_code('mail');
     $preview_subject = $subject;
     if (post_param_integer('make_periodic', 0) == 1) {
         $preview_subject .= ' - ' . get_timezoned_date(time(), false, false, false, true);
     }
     require_code('comcode_text');
     $preview = do_template('NEWSLETTER_CONFIRM_WRAP', array('_GUID' => '02bd5a782620141f8589e647e2c6d90b', 'TEXT_PREVIEW' => $text_preview, 'PREVIEW' => $_preview, 'SUBJECT' => $subject));
     mail_wrap($preview_subject, $html_only == 1 ? $_preview->evaluate() : $message, array($address), $username, $from_email, $from_name, 3, NULL, true, NULL, true, $in_html);
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('MANAGE_NEWSLETTER')), array('_SELF:_SELF:new', do_lang_tempcode('NEWSLETTER_SEND'))));
     breadcrumb_set_self(do_lang_tempcode('CONFIRM'));
     require_code('templates_confirm_screen');
     return form_confirm_screen($title, $preview, 'send', get_param('old_type', 'new'), $extra_post_data);
 }
Exemplo n.º 12
0
/**
 * Make some Comcode more readable.
 *
 * @param  string			Comcode text to change
 * @return string			Clean text
 */
function comcode_to_clean_text($message_plain)
{
    //$message_plain=str_replace("\n",'',$message_plain);
    if (strpos($message_plain, '[') === false && strpos($message_plain, '{') === false) {
        return $message_plain;
    }
    require_code('tempcode_compiler');
    if (strpos($message_plain, '[code') === false && strpos($message_plain, '[no_parse') === false && strpos($message_plain, '[tt') === false) {
        // Change username links to plain username namings
        $message_plain = preg_replace('#\\{\\{([^\\}\\{]*)\\}\\}#', '\\1', $message_plain);
        // Remove directives etc
        do {
            $before = $message_plain;
            $message_plain = preg_replace('#\\{([^\\}\\{]*)\\}#', '', $message_plain);
        } while ($message_plain != $before);
        if (strpos($message_plain, '{') !== false) {
            $message_plain = static_evaluate_tempcode(template_to_tempcode($message_plain, 0, false, '', NULL, NULL, true));
        }
    }
    $match = array();
    if (preg_match("#\\[semihtml\\](.*)\\[\\/semihtml\\]#Us", $message_plain, $match) != 0) {
        require_code('comcode_from_html');
        $message_plain = str_replace($match[0], semihtml_to_comcode($match[0]), $message_plain);
    }
    if (preg_match("#^\\s*\\[html\\](.*)\\[\\/html\\]\\s*\$#Us", $message_plain, $match) != 0) {
        require_code('comcode_from_html');
        $message_plain = str_replace($match[0], semihtml_to_comcode($match[0]), $message_plain);
    }
    $message_plain = array_key_exists(1, $match) ? $match[1] : $message_plain;
    $message_plain = preg_replace("#\\[url=\"([^\"]*)\"(.*)\\]([^\\[\\]]*)\\[/url\\]#", '${1}', $message_plain);
    $message_plain = preg_replace("#\\[img(.*)\\]([^\\[\\]]*)\\[/img\\]#", '', $message_plain);
    $message_plain = @html_entity_decode(strip_tags($message_plain), ENT_QUOTES, get_charset());
    $message_plain = str_replace(']http', ']' . chr(10) . 'http', str_replace('[/url]', chr(10) . '[/url]', $message_plain));
    $message_plain = preg_replace('#\\[random [^=]*="([^"]*)"[^\\]]*\\].*\\[/random\\]#Us', '${1}', $message_plain);
    $message_plain = preg_replace('#\\[abbr="([^"]*)"[^\\]]*\\].*\\[/abbr\\]#Us', '${1}', $message_plain);
    $message_plain = preg_replace_callback('#\\[indent[^\\]]*\\](.*)\\[/indent\\]#Us', '_indent_callback', $message_plain);
    $message_plain = preg_replace_callback('#\\[title([^\\]])*\\](.*)\\[/title\\]#Us', '_title_callback', $message_plain);
    $message_plain = preg_replace_callback('#\\[box="([^"]*)"[^\\]]*\\](.*)\\[/box\\]#Us', '_box_callback', $message_plain);
    $tags_to_strip_inards = array('if_in_group', 'snapback', 'post', 'thread', 'topic', 'include', 'staff_note', 'attachment', 'attachment2', 'attachment_safe', 'contents', 'block', 'random');
    foreach ($tags_to_strip_inards as $s) {
        $message_plain = preg_replace('#\\[' . $s . '[^\\]]*\\].*\\[/' . $s . '\\]#Us', '', $message_plain);
    }
    $message_plain = preg_replace('#\\[surround="accessibility_hidden"\\].*\\[/surround\\]#Us', '', $message_plain);
    $tags_to_strip = array('surround', 'ticker', 'jumping', 'right', 'center', 'left', 'align', 'list', 'concepts', 'html', 'semihtml', 'concept', 'size', 'color', 'font', 'tt', 'address', 'sup', 'sub', 'box');
    foreach ($tags_to_strip as $s) {
        $message_plain = preg_replace('#\\[' . $s . '[^\\]]*\\](.*)\\[/' . $s . '\\]#U', '${1}', $message_plain);
    }
    $message_plain = str_replace(array('[/*]', '[*]', '[list]' . chr(10), chr(10) . '[/list]', '[list]', '[/list]', '[b]', '[/b]', '[i]', '[/i]', '[u]', '[/u]', '[highlight]', '[/highlight]'), array('', ' - ', '', '', '', '', '**', '**', '*', '*', '__', '__', '***', '***'), $message_plain);
    $message_plain = preg_replace('#\\[list[^\\[\\]]*\\]#', '', $message_plain);
    $message_plain = preg_replace('#\\{\\$,[^\\{\\}]*\\}#', '', $message_plain);
    return trim($message_plain);
}
Exemplo n.º 13
0
/**
 * Get an ordered array of all the entries in the specified catalogue.
 *
 * @param  ?AUTO_LINK		The ID of the category for which the entries are being collected (NULL: entries are [and must be] passed instead)
 * @param  ID_TEXT			The name of the catalogue
 * @param  ?array				A database row of the catalogue we are working with (NULL: read it in)
 * @param  ID_TEXT			The view type we're doing
 * @set    PAGE SEARCH CATEGORY
 * @param  ID_TEXT			The template set we are rendering this category using
 * @param  ?integer			The maximum number of entries to show on a single page of this this category (NULL: all)
 * @param  ?integer			The entry number to start at (NULL: all)
 * @param  ?mixed				The entries to show, may be from other categories. Can either be SQL fragment, or array (NULL: use $start and $max)
 * @param  ?AUTO_LINK		The virtual root for display of this category (NULL: default)
 * @param  ?SHORT_INTEGER	The display type to use (NULL: lookup from $catalogue)
 * @param  boolean			Whether to perform sorting
 * @param  ?array				A list of entry rows (NULL: select them normally)
 * @param  string				Search filter (blank: no filter)
 * @param  ?ID_TEXT			Orderer (NULL: read from environment)
 * @return array				An array containing our built up entries (renderable tempcode), our sorting interface, and our entries (entry records from database, with an additional 'map' field), and the max rows
 */
function get_catalogue_category_entry_buildup($category_id, $catalogue_name, $catalogue, $view_type, $tpl_set, $max, $start, $select, $root, $display_type = NULL, $do_sorting = true, $entries = NULL, $search = '', $_order_by = NULL)
{
    if (addon_installed('ecommerce')) {
        require_code('ecommerce');
    }
    $is_ecomm = is_ecommerce_catalogue($catalogue_name);
    if (is_null($catalogue)) {
        $_catalogues = $GLOBALS['SITE_DB']->query_select('catalogues', array('*'), array('c_name' => $catalogue_name), '', 1);
        $catalogue = $_catalogues[0];
    }
    $or_list = mixed();
    if (is_null($entries) && !is_null($select)) {
        if (is_array($select) && count($select) == 0 || is_string($select) && $select == '') {
            $entries = array();
        } else {
            if (!is_array($select)) {
                $or_list = $select;
            } else {
                $or_list = '';
                foreach ($select as $s) {
                    if ($or_list != '') {
                        $or_list .= ' OR ';
                    }
                    $or_list .= 'e.id=' . strval($s);
                }
            }
        }
    }
    if (is_null($display_type)) {
        $display_type = get_param_integer('keep_cat_display_type', $catalogue['c_display_type']);
    }
    // Find order field
    global $CAT_FIELDS_CACHE;
    if (isset($CAT_FIELDS_CACHE[$catalogue_name])) {
        $fields = $CAT_FIELDS_CACHE[$catalogue_name];
    } else {
        $fields = $GLOBALS['SITE_DB']->query_select('catalogue_fields', array('*'), array('c_name' => $catalogue_name), 'ORDER BY cf_order');
    }
    $CAT_FIELDS_CACHE[$catalogue_name] = $fields;
    if ($do_sorting) {
        global $NON_CANONICAL_PARAMS;
        $NON_CANONICAL_PARAMS[] = 'order';
        if (is_null($_order_by)) {
            $_order_by = get_param('order', '');
        }
        if ($_order_by == '' || strpos($_order_by, ' ') === false) {
            $order_by = '0';
            $direction = 'ASC';
            foreach ($fields as $i => $field) {
                if ($field['cf_defines_order'] != 0) {
                    $order_by = strval($i);
                    $direction = $field['cf_defines_order'] == 1 ? 'ASC' : 'DESC';
                    $_order_by = strval($field['id']) . ' ' . $direction;
                    break;
                }
            }
        } else {
            list($order_by, $direction) = explode(' ', $_order_by);
            if ($direction != 'ASC' && $direction != 'DESC') {
                log_hack_attack_and_exit('ORDERBY_HACK');
            }
            if ($order_by != 'rating' && $order_by != 'add_date') {
                $found = false;
                foreach ($fields as $i => $field) {
                    if ($order_by == strval($field['id'])) {
                        $order_by = strval($i);
                        $found = true;
                        break;
                    }
                }
                if (!$found) {
                    $order_by = '0';
                }
                // Could not find
            }
        }
    } else {
        $order_by = mixed();
        $direction = 'ASC';
    }
    // Get entries in this category
    $map = '1=1';
    if (!is_null($category_id)) {
        $map .= ' AND cc_id=' . strval($category_id);
    }
    if (!has_specific_permission(get_member(), 'see_unvalidated')) {
        $map .= ' AND ce_validated=1';
    }
    if (!is_null($or_list)) {
        $map .= ' AND (' . $or_list . ')';
    }
    $in_db_sorting = !is_null($order_by) && $do_sorting;
    require_code('fields');
    if (is_null($entries)) {
        if ($in_db_sorting) {
            $num_entries = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM ' . get_table_prefix() . 'catalogue_entries e WHERE ' . $map);
            if ($order_by == 'add_date') {
                $entries = $max == 0 ? array() : $GLOBALS['SITE_DB']->query('SELECT e.* FROM ' . get_table_prefix() . 'catalogue_entries e WHERE ' . $map . ' ORDER BY ce_add_date ' . $direction, $max, $start);
            } elseif ($order_by == 'rating') {
                $select_rating = '(SELECT AVG(rating) FROM ' . get_table_prefix() . 'rating WHERE ' . db_string_equal_to('rating_for_type', 'catalogues') . ' AND rating_for_id=e.id) AS compound_rating';
                $entries = $max == 0 ? array() : $GLOBALS['SITE_DB']->query('SELECT e.*,' . $select_rating . ' FROM ' . get_table_prefix() . 'catalogue_entries e  WHERE ' . $map . ' ORDER BY compound_rating ' . $direction, $max, $start);
            } else {
                $ob = get_fields_hook($fields[intval($order_by)]['cf_type']);
                list(, , $table) = $ob->get_field_value_row_bits($fields[$order_by]);
                if (strpos($table, '_trans') !== false) {
                    $join = get_table_prefix() . 'catalogue_entries e LEFT JOIN ' . get_table_prefix() . 'catalogue_efv_' . $table . ' f ON f.ce_id=e.id AND f.cf_id=' . strval($fields[$order_by]['id']) . ' LEFT JOIN ' . get_table_prefix() . 'translate t ON f.cv_value=t.id';
                    $entries = $max == 0 ? array() : $GLOBALS['SITE_DB']->query('SELECT e.* FROM ' . $join . ' WHERE ' . $map . ' ' . ($num_entries > 300 ? '' : 'ORDER BY t.text_original ' . $direction), $max, $start);
                } else {
                    $join = get_table_prefix() . 'catalogue_entries e LEFT JOIN ' . get_table_prefix() . 'catalogue_efv_' . $table . ' f ON f.ce_id=e.id AND f.cf_id=' . strval($fields[$order_by]['id']);
                    $entries = $max == 0 ? array() : $GLOBALS['SITE_DB']->query('SELECT e.* FROM ' . $join . ' WHERE ' . $map . ' ORDER BY f.cv_value ' . $direction, $max, $start);
                }
            }
            $start = 0;
            // To stop it skipping itself
        } else {
            if ((is_null($order_by) || !$do_sorting) && !is_null($max)) {
                $entries = $max == 0 ? array() : $GLOBALS['SITE_DB']->query('SELECT e.* FROM ' . get_table_prefix() . 'catalogue_entries e WHERE ' . $map, $max, $start);
                $num_entries = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM ' . get_table_prefix() . 'catalogue_entries e WHERE ' . $map);
                $start = 0;
                // To stop it skipping itself
            } else {
                $entries = $max == 0 ? array() : $GLOBALS['SITE_DB']->query('SELECT e.* FROM ' . get_table_prefix() . 'catalogue_entries e WHERE ' . $map);
                $num_entries = count($entries);
            }
        }
    } else {
        $num_entries = count($entries);
    }
    if ($num_entries > 300 && !$in_db_sorting) {
        $in_db_sorting = true;
    }
    // Needed to stop huge slow down
    foreach ($entries as $i => $entry) {
        $entries[$i]['map'] = get_catalogue_entry_map($entry, $catalogue, $view_type, $tpl_set, $root, $fields, $display_type == 1 && !$is_ecomm && !is_null($order_by) ? array(0, intval($order_by)) : NULL, false, false, intval($order_by));
    }
    // Implement search filter
    if ($search != '') {
        $new_entries = array();
        for ($i = 0; $i < $num_entries; $i++) {
            $two_d_list = $entries[$i]['map']['FIELDS_2D'];
            $all_output = '';
            foreach ($two_d_list as $index => $l) {
                $all_output .= (is_object($l['VALUE']) ? $l['VALUE']->evaluate() : $l['VALUE']) . ' ';
            }
            if (strpos(strtolower($all_output), strtolower($search)) !== false) {
                $new_entries[] = $entries[$i];
            }
        }
        $entries = $new_entries;
    }
    disable_php_memory_limit();
    if ($do_sorting) {
        // Sort entries
        $selectors = new ocp_tempcode();
        foreach ($fields as $i => $field) {
            if ($field['cf_searchable'] == 1) {
                $potential_sorter_name = get_translated_text($field['cf_name']);
                foreach (array('ASC' => '_ASCENDING', 'DESC' => '_DESCENDING') as $dir_code => $dir_lang) {
                    $sort_sel = $order_by == strval($i) && $direction == $dir_code;
                    $_potential_sorter_name = new ocp_tempcode();
                    $_potential_sorter_name->attach(escape_html($potential_sorter_name));
                    $_potential_sorter_name->attach(do_lang_tempcode($dir_lang));
                    $selectors->attach(do_template('RESULTS_BROWSER_SORTER', array('_GUID' => 'dfdsfdsusd0fsd0dsf', 'SELECTED' => $sort_sel, 'NAME' => protect_from_escaping($_potential_sorter_name), 'VALUE' => strval($field['id']) . ' ' . $dir_code)));
                }
            }
        }
        $extra_sorts = array();
        $extra_sorts['add_date'] = '_ADDED';
        if (get_option('is_on_rating') == '0') {
            $has_ratings = false;
        } else {
            if (is_null($entries)) {
                $has_ratings = false;
                foreach ($entries as $entry) {
                    if ($entry['allow_rating'] == 1) {
                        $has_ratings = true;
                    }
                }
                if ($has_ratings) {
                    $extra_sorts['rating'] = 'RATING';
                }
            } else {
                $has_ratings = true;
            }
        }
        foreach ($extra_sorts as $extra_sort_code => $extra_sort_lang) {
            foreach (array('ASC' => '_ASCENDING', 'DESC' => '_DESCENDING') as $dir_code => $dir_lang) {
                $sort_sel = $order_by == $extra_sort_code && $direction == $dir_code;
                $_potential_sorter_name = new ocp_tempcode();
                $_potential_sorter_name->attach(do_lang_tempcode($extra_sort_lang));
                $_potential_sorter_name->attach(do_lang_tempcode($dir_lang));
                $selectors->attach(do_template('RESULTS_BROWSER_SORTER', array('_GUID' => 'xfdsfdsusd0fsd0dsf', 'SELECTED' => $sort_sel, 'NAME' => protect_from_escaping($_potential_sorter_name), 'VALUE' => $extra_sort_code . ' ' . $dir_code)));
            }
        }
        $sort_url = get_self_url(false, false, array('order' => NULL), false, true);
        $sorting = do_template('RESULTS_BROWSER_SORT', array('_GUID' => '9fgjfdklgjdfgkjlfdjgd90', 'SORT' => 'order', 'RAND' => uniqid(''), 'URL' => $sort_url, 'SELECTORS' => $selectors));
        if (!$in_db_sorting) {
            for ($i = 0; $i < $num_entries; $i++) {
                if (!array_key_exists($i, $entries)) {
                    continue;
                }
                for ($j = $i + 1; $j < $num_entries; $j++) {
                    if (!array_key_exists($j, $entries)) {
                        continue;
                    }
                    $a = @$entries[$j]['map']['FIELD_' . $order_by];
                    if (array_key_exists('FIELD_' . $order_by . '_PLAIN', @$entries[$j]['map'])) {
                        $a = @$entries[$j]['map']['FIELD_' . $order_by . '_PLAIN'];
                    }
                    $b = @$entries[$i]['map']['FIELD_' . $order_by];
                    if (array_key_exists('FIELD_' . $order_by . '_PLAIN', @$entries[$i]['map'])) {
                        $b = @$entries[$i]['map']['FIELD_' . $order_by . '_PLAIN'];
                    }
                    if (is_object($a)) {
                        $a = $a->evaluate();
                    }
                    if (is_object($b)) {
                        $b = $b->evaluate();
                    }
                    if ($fields[$order_by]['cf_type'] == 'date') {
                        $bits = explode(' ', $a, 2);
                        $date_bits = explode(strpos($bits[0], '-') !== false ? '-' : '/', $bits[0], 3);
                        if (!array_key_exists(1, $date_bits)) {
                            $date_bits[1] = date('m');
                        }
                        if (!array_key_exists(2, $date_bits)) {
                            $date_bits[2] = date('Y');
                        }
                        $time_bits = explode(':', $bits[1], 3);
                        if (!array_key_exists(1, $time_bits)) {
                            $time_bits[1] = '00';
                        }
                        if (!array_key_exists(2, $time_bits)) {
                            $time_bits[2] = '00';
                        }
                        $time_a = mktime(intval($time_bits[0]), intval($time_bits[1]), intval($time_bits[2]), intval($date_bits[1]), intval($date_bits[2]), intval($date_bits[0]));
                        $bits = explode(' ', $b, 2);
                        $date_bits = explode(strpos($bits[0], '-') !== false ? '-' : '/', $bits[0], 3);
                        if (!array_key_exists(1, $date_bits)) {
                            $date_bits[1] = date('m');
                        }
                        if (!array_key_exists(2, $date_bits)) {
                            $date_bits[2] = date('Y');
                        }
                        $time_bits = explode(':', $bits[1], 3);
                        if (!array_key_exists(1, $time_bits)) {
                            $time_bits[1] = '00';
                        }
                        if (!array_key_exists(2, $time_bits)) {
                            $time_bits[2] = '00';
                        }
                        $time_b = mktime(intval($time_bits[0]), intval($time_bits[1]), intval($time_bits[2]), intval($date_bits[1]), intval($date_bits[2]), intval($date_bits[0]));
                        $r = $time_a < $time_b ? -1 : ($time_a == $time_b ? 0 : 1);
                    } else {
                        $r = strnatcmp(strtolower($a), strtolower($b));
                    }
                    if ($r < 0 && $direction == 'ASC' || $r > 0 && $direction == 'DESC') {
                        $temp = $entries[$i];
                        $entries[$i] = $entries[$j];
                        $entries[$j] = $temp;
                    }
                }
            }
        }
    } else {
        $sorting = new ocp_tempcode();
    }
    // Build up entries
    $entry_buildup = new ocp_tempcode();
    $extra_map = array();
    if ($is_ecomm) {
        require_lang('shopping');
        $i = 0;
        for ($i = 0; $i < $num_entries; $i++) {
            if (!array_key_exists($i, $entries)) {
                break;
            }
            $entry = $entries[$i];
            $extra_map[$i]['ADD_TO_CART'] = build_url(array('page' => 'shopping', 'type' => 'add_item', 'product_id' => $entry['id'], 'hook' => 'catalogue_items'), get_module_zone('shopping'));
        }
    }
    if ($display_type == 2) {
        for ($i = 0; $i < $num_entries; $i++) {
            if (!array_key_exists($i, $entries)) {
                break;
            }
            $entry = $entries[$i];
            if (is_null($start) || $in_db_sorting || $i >= $start && $i < $start + $max) {
                $tab_entry_map = $entry['map'] + (array_key_exists($i, $extra_map) ? $extra_map[$i] : array());
                if (get_option('is_on_comments') == '1' && $entry['allow_comments'] >= 1 || get_option('is_on_rating') == '1' && $entry['allow_rating'] == 1 || get_option('is_on_trackbacks') == '1' && $entry['allow_trackbacks'] == 1) {
                    $tab_entry_map['VIEW_URL'] = build_url(array('page' => 'catalogues', 'type' => 'entry', 'id' => $entry['id'], 'root' => $root == -1 ? NULL : $root), get_module_zone('catalogues'));
                } else {
                    $tab_entry_map['VIEW_URL'] = '';
                }
                $entry_buildup->attach(static_evaluate_tempcode(do_template('CATALOGUE_' . $tpl_set . '_TAB_ENTRY', $tab_entry_map, NULL, false, 'CATALOGUE_DEFAULT_TAB_ENTRY')));
            }
            if (!is_null($start) && $i >= $start + $max) {
                break;
            }
        }
        if (!$entry_buildup->is_empty()) {
            $head = new ocp_tempcode();
            $field_count = 0;
            foreach ($fields as $i => $field) {
                if (($field['cf_put_in_category'] == 1 && $view_type == 'CATEGORY' || $field['cf_put_in_search'] == 1 && $view_type == 'SEARCH') && $field['cf_visible'] == 1) {
                    if ($field['cf_searchable'] == 1) {
                        $sort_url_asc = get_self_url(false, false, array('order' => strval($field['id']) . ' ASC'), true);
                        $sort_url_desc = get_self_url(false, false, array('order' => strval($field['id']) . ' DESC'), true);
                        $sort_asc_selected = $order_by == strval($field['id']) && $direction == 'ASC';
                        $sort_desc_selected = $order_by == strval($field['id']) && $direction == 'DESC';
                    } else {
                        $sort_url_asc = '';
                        $sort_url_desc = '';
                        $sort_asc_selected = false;
                        $sort_desc_selected = false;
                    }
                    $head->attach(do_template('CATALOGUE_' . $tpl_set . '_TAB_FIELD_HEAD', array('SORT_ASC_SELECTED' => $sort_asc_selected, 'SORT_DESC_SELECTED' => $sort_desc_selected, 'SORT_URL_ASC' => $sort_url_asc, 'SORT_URL_DESC' => $sort_url_desc, 'CATALOGUE' => $catalogue_name, 'FIELDID' => strval($i), '_FIELDID' => strval($field['id']), 'FIELD' => get_translated_text($field['cf_name']), 'FIELDTYPE' => $field['cf_type']), NULL, false, 'CATALOGUE_DEFAULT_TAB_FIELD_HEAD'));
                    $field_count++;
                }
            }
            $entry_buildup = do_template('CATALOGUE_' . $tpl_set . '_TAB_WRAP', array('CATALOGUE' => $catalogue_name, 'HEAD' => $head, 'CONTENT' => $entry_buildup, 'FIELD_COUNT' => strval($field_count)), NULL, false, 'CATALOGUE_DEFAULT_TAB_WRAP');
        }
    } elseif ($display_type == 0) {
        for ($i = 0; $i < $num_entries; $i++) {
            if (!array_key_exists($i, $entries)) {
                break;
            }
            $entry = $entries[$i];
            if (is_null($max) || $in_db_sorting || (is_null($start) || $i >= $start && $i < $start + $max)) {
                $entry_buildup->attach(do_template('CATALOGUE_' . $tpl_set . '_ENTRY_EMBED', $entry['map'] + (array_key_exists($i, $extra_map) ? $extra_map[$i] : array()), NULL, false, 'CATALOGUE_DEFAULT_ENTRY_EMBED'));
            }
        }
    } else {
        for ($i = 0; $i < $num_entries; $i++) {
            if (!array_key_exists($i, $entries)) {
                break;
            }
            $entry = $entries[$i];
            if (is_null($start) || $in_db_sorting || $i >= $start && $i < $start + $max) {
                $entry_buildup->attach(do_template('CATALOGUE_' . $tpl_set . '_LINE', $entry['map'] + (array_key_exists($i, $extra_map) ? $extra_map[$i] : array()), NULL, false, 'CATALOGUE_DEFAULT_LINE'));
            }
        }
        if (!$entry_buildup->is_empty()) {
            $entry_buildup = do_template('CATALOGUE_' . $tpl_set . '_LINE_WRAP', $entry['map'] + array('CATALOGUE' => $catalogue_name, 'CONTENT' => $entry_buildup), NULL, false, 'CATALOGUE_DEFAULT_LINE_WRAP');
        }
    }
    return array($entry_buildup, $sorting, $entries, $num_entries);
}
Exemplo n.º 14
0
 /**
  * Get tempcode for a zone adding/editing form.
  *
  * @param  boolean		Whether the zone editor will be used
  * @param  SHORT_TEXT	The zone title
  * @param  ID_TEXT		The zones default page
  * @param  SHORT_TEXT	The header text
  * @param  ?ID_TEXT		The theme (NULL: no override)
  * @param  BINARY			Whether the zone is wide
  * @param  BINARY			Whether the zone requires a session for pages to be used
  * @param  BINARY			Whether the zone in displayed in the menu coded into some themes
  * @param  ?ID_TEXT		Name of the zone (NULL: unknown)
  * @return array			A tuple: The tempcode for the fields, hidden fields, and extra Javascript
  */
 function get_form_fields($in_zone_editor = false, $title = '', $default_page = 'start', $header_text = '', $theme = NULL, $wide = 0, $require_session = 0, $displayed_in_menu = 1, $zone = NULL)
 {
     require_lang('permissions');
     $javascript = '';
     $fields = '';
     $hidden = new ocp_tempcode();
     require_code('form_templates');
     $fields .= static_evaluate_tempcode(form_input_line(do_lang_tempcode('TITLE'), do_lang_tempcode('DESCRIPTION_TITLE'), 'title', $title, true));
     $fields .= static_evaluate_tempcode(form_input_line(do_lang_tempcode('DEFAULT_PAGE'), do_lang_tempcode('DESCRIPTION_DEFAULT_PAGE'), 'default_page', $default_page, true));
     $fields .= static_evaluate_tempcode(form_input_line(do_lang_tempcode('HEADER_TEXT'), do_lang_tempcode('DESCRIPTION_HEADER_TEXT'), 'header_text', $header_text, false));
     $list = '';
     $list .= static_evaluate_tempcode(form_input_list_entry('0', $wide == 0, do_lang_tempcode('NO')));
     $list .= static_evaluate_tempcode(form_input_list_entry('1', $wide == 1, do_lang_tempcode('YES')));
     $list .= static_evaluate_tempcode(form_input_list_entry('-1', is_null($wide), do_lang_tempcode('RELY_FORUMS')));
     $fields .= static_evaluate_tempcode(form_input_list(do_lang_tempcode('WIDE'), do_lang_tempcode('DESCRIPTION_WIDE'), 'wide', make_string_tempcode($list)));
     $fields .= static_evaluate_tempcode(form_input_tick(do_lang_tempcode('DISPLAYED_IN_MENU'), do_lang_tempcode('DESCRIPTION_DISPLAYED_IN_MENU'), 'displayed_in_menu', $displayed_in_menu == 1));
     // Theme
     require_code('themes2');
     $entries = nice_get_themes($theme, false, true);
     $fields .= static_evaluate_tempcode(form_input_list(do_lang_tempcode('THEME'), do_lang_tempcode(get_forum_type() == 'ocf' ? '_DESCRIPTION_THEME_OCF' : '_DESCRIPTION_THEME', substr(preg_replace('#[^A-Za-z\\d]#', '_', get_site_name()), 0, 80)), 'theme', $entries));
     $fields .= static_evaluate_tempcode(do_template('FORM_SCREEN_FIELD_SPACER', array('SECTION_HIDDEN' => true, 'TITLE' => do_lang_tempcode('ADVANCED'))));
     $fields .= static_evaluate_tempcode(form_input_tick(do_lang_tempcode('REQUIRE_SESSION'), do_lang_tempcode('DESCRIPTION_REQUIRE_SESSION'), 'require_session', $require_session == 1));
     if (!$in_zone_editor && !is_null($zone) && addon_installed('zone_logos')) {
         // Logos
         handle_max_file_size($hidden, 'image');
         require_code('themes2');
         $themes = find_all_themes();
         foreach ($themes as $theme => $theme_name) {
             $fields .= static_evaluate_tempcode(do_template('FORM_SCREEN_FIELD_SPACER', array('SECTION_HIDDEN' => true, 'TITLE' => do_lang_tempcode('THEME_LOGO', escape_html($theme_name)))));
             $fields .= static_evaluate_tempcode(form_input_upload(do_lang_tempcode('IMAGE'), do_lang_tempcode('DESCRIPTION_UPLOAD'), 'logo_upload_' . $theme, false, NULL, NULL, true, str_replace(' ', '', get_option('valid_images'))));
             require_code('themes2');
             $ids = get_all_image_ids_type('logo', false, NULL, $theme);
             $current_logo = 'logo/' . $zone . '-logo';
             if (!in_array($current_logo, $ids)) {
                 $current_logo = 'logo/-logo';
             }
             foreach ($ids as $id) {
                 $test = find_theme_image($id, true, false, $theme);
                 if ($test == '') {
                     $test = find_theme_image($id, false, false, 'default');
                 }
                 if ($test == '' && $id == $current_logo) {
                     $current_logo = $ids[0];
                 }
             }
             $fields .= static_evaluate_tempcode(form_input_picture_choose_specific(do_lang_tempcode('ALT_FIELD', do_lang_tempcode('STOCK')), do_lang_tempcode('DESCRIPTION_ALTERNATE_STOCK'), 'logo_select_' . $theme, $ids, NULL, $current_logo, NULL, true, NULL, $theme));
             $javascript .= 'standardAlternateFields(\'logo_upload_' . $theme . '\',\'logo_select_' . $theme . '*\');';
         }
     }
     if ($zone !== '') {
         $fields .= static_evaluate_tempcode(do_template('FORM_SCREEN_FIELD_SPACER', array('TITLE' => do_lang_tempcode('PERMISSIONS'))));
         // Permissions
         $admin_groups = $GLOBALS['FORUM_DRIVER']->get_super_admin_groups();
         $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(false, true);
         foreach ($groups as $id => $name) {
             if (in_array($id, $admin_groups)) {
                 continue;
             }
             $perhaps = is_null($zone) ? true : $GLOBALS['SITE_DB']->query_value_null_ok('group_zone_access', 'zone_name', array('zone_name' => $zone, 'group_id' => $id));
             $fields .= static_evaluate_tempcode(form_input_tick(do_lang_tempcode('ACCESS_FOR', escape_html($name)), do_lang_tempcode('DESCRIPTION_ACCESS_FOR', escape_html($name)), 'access_' . strval($id), !is_null($perhaps)));
         }
     }
     return array(make_string_tempcode($fields), $hidden, $javascript);
 }
Exemplo n.º 15
0
/**
 * Get tempcode for a Comcode tag. This function should always return (errors should be placed in the Comcode output stream), for stability reasons (i.e. if you're submitting something, you can't have the whole submit process die half way through in an unstructured fashion).
 *
 * @param  string			The tag being converted
 * @param  array			A map of the attributes (name=>val) for the tag. Val is usually a string, although in select places, the XML parser may pass tempcode.
 * @param  mixed			Tempcode of the inside of the tag ([between]THIS[/between]); the XML parser may pass in special stuff here, which is interpreted only for select tags
 * @param  boolean		Whether we are allowed to proceed even if this tag is marked as 'dangerous'
 * @param  string			A special identifier to mark where the resultant tempcode is going to end up (e.g. the ID of a post)
 * @param  integer		The position this tag occurred at in the Comcode
 * @param  MEMBER			The member who is responsible for this Comcode
 * @param  boolean		Whether to check as arbitrary admin
 * @param  object			The database connection to use
 * @param  string			The whole chunk of comcode
 * @param  boolean		Whether this is for WML output
 * @param  boolean		Whether this is only a structure sweep
 * @param  boolean		Whether we are in semi-parse-mode (some tags might convert differently)
 * @param  ?array			A list of words to highlight (NULL: none)
 * @param  ?MEMBER		The member we are running on behalf of, with respect to how attachments are handled; we may use this members attachments that are already within this post, and our new attachments will be handed to this member (NULL: member evaluating)
 * @param  boolean		Whether what we have came from inside a semihtml tag
 * @param  boolean		Whether what we have came from semihtml mode
 * @return tempcode		The tempcode for the Comcode
 */
function _do_tags_comcode($tag, $attributes, $embed, $comcode_dangerous, $pass_id, $marker, $source_member, $as_admin, $connection, &$comcode, $wml, $structure_sweep, $semiparse_mode, $highlight_bits = NULL, $on_behalf_of_member = NULL, $in_semihtml = false, $is_all_semihtml = false)
{
    if ($structure_sweep && $tag != 'title') {
        return new ocp_tempcode();
    }
    $param_given = isset($attributes['param']);
    if (!isset($attributes['param']) && $tag != 'block') {
        $attributes['param'] = '';
    }
    global $DANGEROUS_TAGS, $STRUCTURE_LIST, $COMCODE_PARSE_TITLE;
    if (isset($DANGEROUS_TAGS[$tag]) && !$comcode_dangerous) {
        $username = $GLOBALS['FORUM_DRIVER']->get_username($source_member);
        if (is_null($username)) {
            $username = do_lang('UNKNOWN');
        }
        if ($semiparse_mode) {
            $params = '';
            foreach ($attributes as $key => $val) {
                $params .= ' ' . $key . '="' . comcode_escape($val) . '"';
            }
            return make_string_tempcode('<input class="ocp_keep_ui_controlled" size="45" title="[' . $tag . '' . escape_html($params) . ']' . ($in_semihtml || $is_all_semihtml ? escape_html($embed->evaluate()) : escape_html($embed->evaluate())) . '[/' . $tag . ']" type="text" value="' . ($tag == 'block' ? do_lang('COMCODE_EDITABLE_BLOCK', escape_html($embed->evaluate())) : do_lang('COMCODE_EDITABLE_TAG', escape_html($tag))) . '" />');
        }
        return do_template('WARNING_TABLE', array('WARNING' => do_lang_tempcode('comcode:NO_ACCESS_FOR_TAG', escape_html($tag), escape_html($username))));
        //return new ocp_tempcode();
    }
    // These are just bbcode compatibility tags.. we will remap to our proper comcode
    if ($tag == 'php') {
        $attributes['param'] = 'php';
        $tag = 'code';
    } elseif ($tag == 'sql') {
        $attributes['param'] = 'sql';
        $tag = 'code';
    } elseif ($tag == 'codebox') {
        $attributes['scroll'] = '1';
        $tag = 'code';
    } elseif ($tag == 'left') {
        $attributes['param'] = 'left';
        $tag = 'align';
    } elseif ($tag == 'center') {
        $attributes['param'] = 'center';
        $tag = 'align';
    } elseif ($tag == 'right') {
        $attributes['param'] = 'right';
        $tag = 'align';
    } elseif ($tag == 'thread') {
        $tag = 'topic';
    } elseif ($tag == 'internal_table' || $tag == 'external_table') {
        $tag = 'box';
        if (array_key_exists('class', $attributes)) {
            $attributes['type'] = $attributes['class'];
        }
    }
    if ($semiparse_mode) {
        $non_text_tags = array('attachment', 'section_controller', 'big_tab_controller', 'currency', 'block', 'contents', 'concepts', 'flash', 'menu', 'email', 'reference', 'upload', 'page', 'exp_thumb', 'exp_ref', 'thumb', 'snapback', 'post', 'thread', 'topic', 'include', 'random', 'jumping', 'shocker');
        // Also in JAVASCRIPT_EDITING.tpl
        if ($tag == 'attachment_safe') {
            if (preg_match('#^new\\_\\d+$#', $embed->evaluate()) != 0) {
                $non_text_tags[] = 'attachment_safe';
            }
        }
        if (in_array($tag, $non_text_tags)) {
            $params = '';
            foreach ($attributes as $key => $val) {
                $params .= ' ' . $key . '="' . str_replace('"', '\\"', $val) . '"';
            }
            if ($tag != 'block' || !is_file(get_file_base() . '/sources_custom/miniblocks/' . $embed->evaluate() . '.php')) {
                return make_string_tempcode('<input class="ocp_keep_ui_controlled" size="45" title="[' . $tag . '' . escape_html($params) . ']' . ($in_semihtml || $is_all_semihtml ? escape_html($embed->evaluate()) : escape_html($embed->evaluate())) . '[/' . $tag . ']" type="text" value="' . ($tag == 'block' ? do_lang('comcode:COMCODE_EDITABLE_BLOCK', escape_html($embed->evaluate())) : do_lang('comcode:COMCODE_EDITABLE_TAG', escape_html($tag))) . '" />');
            } else {
                return make_string_tempcode('[block' . escape_html($params) . ']' . ($in_semihtml || $is_all_semihtml ? $embed->evaluate() : escape_html($embed->evaluate())) . '[/block]');
            }
        }
    }
    $temp_tpl = new ocp_tempcode();
    switch ($tag) {
        case 'no_parse':
            $temp_tpl->attach($embed);
            break;
        case 'currency':
            if (addon_installed('ecommerce')) {
                $bracket = array_key_exists('bracket', $attributes) && $attributes['bracket'] == '1';
                if ($attributes['param'] == '') {
                    $attributes['param'] = get_option('currency');
                }
                $temp_tpl = do_template('COMCODE_CURRENCY', array('_GUID' => 'ee1fcdae082af6397ff3bad89006e012', 'AMOUNT' => $embed, 'FROM_CURRENCY' => $attributes['param'], 'BRACKET' => $bracket));
            }
            break;
        case 'overlay':
            $x = strval(array_key_exists('x', $attributes) ? intval($attributes['x']) : 100);
            $y = strval(array_key_exists('y', $attributes) ? intval($attributes['y']) : 100);
            $width = strval(array_key_exists('width', $attributes) ? intval($attributes['width']) : 300);
            $height = strval(array_key_exists('height', $attributes) ? intval($attributes['height']) : 300);
            $timein = strval(array_key_exists('timein', $attributes) ? intval($attributes['timein']) : 0);
            $timeout = strval(array_key_exists('timeout', $attributes) ? intval($attributes['timeout']) : -1);
            $temp_tpl = do_template('COMCODE_OVERLAY', array('_GUID' => 'dfd0f7a72cc2bf6b613b28f8165a0034', 'UNIQ_ID' => 'a' . uniqid('', true), 'EMBED' => $embed, 'ID' => $attributes['param'] != '' ? $attributes['param'] : 'rand' . uniqid('', true), 'X' => $x, 'Y' => $y, 'WIDTH' => $width, 'HEIGHT' => $height, 'TIMEIN' => $timein, 'TIMEOUT' => $timeout));
            break;
        case 'code':
            if ($wml) {
                $temp_tpl->attach('<b>');
                $temp_tpl->attach($embed);
                $temp_tpl->attach('</b>');
                break;
            }
            list($_embed, $title) = do_code_box($attributes['param'], $embed, array_key_exists('numbers', $attributes) && $attributes['numbers'] == '1', $in_semihtml, $is_all_semihtml);
            if (!is_null($_embed)) {
                $tpl = array_key_exists('scroll', $attributes) && $attributes['scroll'] == '1' ? 'COMCODE_CODE_SCROLL' : 'COMCODE_CODE';
                if ($tpl == 'COMCODE_CODE_SCROLL' && substr_count($_embed, chr(10)) < 10) {
                    $style = 'height: auto';
                } else {
                    $style = '';
                }
                $temp_tpl = do_template($tpl, array('_GUID' => 'c5d46d0927272fcacbbabcfab0ef6b0c', 'STYLE' => $style, 'TYPE' => $attributes['param'], 'CONTENT' => $_embed, 'TITLE' => $title));
            } else {
                $_embed = '';
            }
            if ($temp_tpl->is_empty()) {
                if ($in_semihtml || $is_all_semihtml) {
                    require_code('comcode_from_html');
                    $back_to_comcode = semihtml_to_comcode($embed->evaluate());
                    // Undo what's happened already
                    //$back_to_comcode=html_entity_decode($back_to_comcode,ENT_QUOTES,get_charset()); // Remove the escaping entities that were inside the code tag
                    $embed = comcode_to_tempcode($back_to_comcode, $source_member, $as_admin, 80, $pass_id, $connection);
                    // Re-parse (with full security)
                }
                $_embed = $embed->evaluate();
                if (!array_key_exists('scroll', $attributes) && strlen($_embed) > 1000) {
                    $attributes['scroll'] = '1';
                }
                $tpl = array_key_exists('scroll', $attributes) && $attributes['scroll'] == '1' ? 'COMCODE_CODE_SCROLL' : 'COMCODE_CODE';
                $title = do_lang_tempcode('CODE');
                if ($tpl == 'COMCODE_CODE_SCROLL' && substr_count($_embed, chr(10)) < 10) {
                    $style = 'height: auto';
                } else {
                    $style = '';
                }
                $temp_tpl = do_template($tpl, array('CONTENT' => $_embed, 'TITLE' => $title, 'STYLE' => $style, 'TYPE' => $attributes['param']));
            }
            break;
        case 'list':
            if (is_array($embed)) {
                $parts = $embed;
            } else {
                $_embed = trim($embed->evaluate());
                $_embed = str_replace('[/*]', '', $_embed);
                $parts = explode('[*]', $_embed);
            }
            if (isset($temp_tpl->preprocessable_bits)) {
                $temp_tpl->preprocessable_bits = array_merge($temp_tpl->preprocessable_bits, $embed->preprocessable_bits);
            }
            if ($wml) {
                foreach ($parts as $i => $part) {
                    if ($i == 0 && str_replace(array('&nbsp;', '<br />', ' '), array('', '', ''), trim($part)) == '') {
                        continue;
                    }
                    $temp_tpl->attach('<br />* ');
                    $temp_tpl->attach($part);
                }
                $temp_tpl->attach('<br />* ');
                break;
            }
            $type = $attributes['param'];
            if ($type != '') {
                if ($type == '1') {
                    $type = 'decimal';
                } elseif ($type == 'a') {
                    $type = 'lower-alpha';
                } elseif ($type == 'i') {
                    $type = 'lower-roman';
                } elseif ($type == 'x') {
                    $type = 'none';
                } elseif (!in_array($type, array('circle', 'disc', 'square', 'armenian', 'decimal', 'decimal-leading-zero', 'georgian', 'lower-alpha', 'lower-greek', 'lower-latin', 'lower-roman', 'upper-alpha', 'upper-latin', 'upper-roman'))) {
                    $type = 'disc';
                }
                $tag = in_array($type, array('circle', 'disc', 'square')) ? 'ul' : 'ol';
                $temp_tpl->attach('<' . $tag . ' style="list-style-type: ' . $type . '">');
                foreach ($parts as $i => $part) {
                    if ($i == 0 && str_replace(array('&nbsp;', '<br />', ' '), array('', '', ''), trim($part)) == '') {
                        continue;
                    }
                    $temp_tpl->attach('<li>' . preg_replace('#\\<br /\\>(\\&nbsp;|\\s)*$#D', '', preg_replace('#^\\<br /\\>(\\&nbsp;|\\s)*#D', '', $part)) . '</li>');
                }
                $temp_tpl->attach('</' . $tag . '>');
            } else {
                $temp_tpl->attach('<ul>');
                foreach ($parts as $i => $part) {
                    if ($i == 0 && str_replace(array('&nbsp;', '<br />', ' '), array('', '', ''), trim($part)) == '') {
                        continue;
                    }
                    $temp_tpl->attach('<li>' . preg_replace('#\\<br /\\>(\\&nbsp;|\\s)*$#D', '', preg_replace('#^\\<br /\\>(\\&nbsp;|\\s)*#D', '', $part)) . '</li>');
                }
                $temp_tpl->attach('</ul>');
            }
            break;
        case 'snapback':
            require_lang('ocf');
            $post_id = intval($embed->evaluate());
            $s_title = $attributes['param'] == '' ? do_lang_tempcode('FORUM_POST_NUMBERED', integer_format($post_id)) : make_string_tempcode($attributes['param']);
            $forum = array_key_exists('forum', $attributes) ? $attributes['forum'] : '';
            $temp_tpl = do_template('COMCODE_SNAPBACK', array('URL' => $GLOBALS['FORUM_DRIVER']->post_url($post_id, $forum), 'TITLE' => $s_title));
            break;
        case 'post':
            require_lang('ocf');
            $post_id = intval($embed->evaluate());
            $s_title = $attributes['param'] == '' ? do_lang_tempcode('FORUM_POST_NUMBERED', integer_format($post_id)) : make_string_tempcode($attributes['param']);
            $forum = array_key_exists('forum', $attributes) ? $attributes['forum'] : '';
            $temp_tpl->attach(hyperlink($GLOBALS['FORUM_DRIVER']->post_url($post_id, $forum), $s_title));
            break;
        case 'topic':
            require_lang('ocf');
            $topic_id = intval($embed->evaluate());
            $s_title = $attributes['param'] == '' ? do_lang_tempcode('FORUM_TOPIC_NUMBERED', integer_format($topic_id)) : make_string_tempcode($attributes['param']);
            $forum = array_key_exists('forum', $attributes) ? $attributes['forum'] : '';
            $temp_tpl->attach(hyperlink($GLOBALS['FORUM_DRIVER']->topic_url($topic_id, $forum), $s_title));
            break;
        case 'staff_note':
            $temp_tpl = new ocp_tempcode();
            return $temp_tpl;
        case 'section':
            if ($wml) {
                $temp_tpl = $embed;
                break;
            }
            $name = array_key_exists('param', $attributes) ? $attributes['param'] : 'section' . strval(mt_rand(0, 100));
            $default = array_key_exists('default', $attributes) ? $attributes['default'] : '0';
            $temp_tpl = do_template('COMCODE_SECTION', array('_GUID' => 'a902962ccdc80046c999d6fed907d105', 'PASS_ID' => 'x' . $pass_id, 'DEFAULT' => $default == '1', 'NAME' => $name, 'CONTENT' => $embed));
            break;
        case 'section_controller':
            if ($wml) {
                break;
            }
            $sections = explode(',', $embed->evaluate());
            $temp_tpl = do_template('COMCODE_SECTION_CONTROLLER', array('_GUID' => '133bf24892e9e3ec2a01146d6ec418fe', 'SECTIONS' => $sections, 'PASS_ID' => 'x' . $pass_id));
            break;
        case 'big_tab':
            if ($wml) {
                $temp_tpl = $embed;
                break;
            }
            $name = array_key_exists('param', $attributes) ? $attributes['param'] : 'big_tab' . strval(mt_rand(0, 100));
            $default = array_key_exists('default', $attributes) ? $attributes['default'] : '0';
            $temp_tpl = do_template('COMCODE_BIG_TABS_TAB', array('PASS_ID' => 'x' . $pass_id, 'DEFAULT' => $default == '1', 'NAME' => $name, 'CONTENT' => $embed));
            break;
        case 'big_tab_controller':
            if ($wml) {
                break;
            }
            $tabs = explode(',', $embed->evaluate());
            if (!array_key_exists('switch_time', $attributes)) {
                $attributes['switch_time'] = '6000';
            }
            $temp_tpl = do_template('COMCODE_BIG_TABS_CONTROLLER', array('SWITCH_TIME' => $attributes['switch_time'], 'TABS' => $tabs, 'PASS_ID' => 'x' . $pass_id));
            break;
        case 'tab':
            if ($wml) {
                $temp_tpl = $embed;
                break;
            }
            $default = array_key_exists('default', $attributes) ? $attributes['default'] : '0';
            $temp_tpl = do_template('COMCODE_TAB_BODY', array('DEFAULT' => $default == '1', 'TITLE' => trim($attributes['param']), 'CONTENT' => $embed));
            break;
        case 'tabs':
            if ($wml) {
                break;
            }
            $heads = new ocp_tempcode();
            $tabs = explode(',', $attributes['param']);
            foreach ($tabs as $i => $tab) {
                $heads->attach(do_template('COMCODE_TAB_HEAD', array('TITLE' => trim($tab), 'FIRST' => $i == 0, 'LAST' => !array_key_exists($i + 1, $tabs))));
            }
            $temp_tpl = do_template('COMCODE_TAB_CONTROLLER', array('HEADS' => $heads, 'CONTENT' => $embed));
            break;
        case 'carousel':
            if ($attributes['param'] == '') {
                $attributes['param'] = '40';
            }
            $temp_tpl = do_template('COMCODE_CAROUSEL', array('CONTENT' => $embed, 'SCROLL_AMOUNT' => $attributes['param']));
            break;
        case 'menu':
            if ($wml) {
                break;
            }
            $name = array_key_exists('param', $attributes) ? $attributes['param'] : 'mnu' . strval(mt_rand(0, 100));
            $type = array_key_exists('type', $attributes) ? $attributes['type'] : 'tree';
            require_code('menus');
            require_code('menus_comcode');
            $temp_tpl = build_comcode_menu($embed->evaluate(), $name, $source_member, $type);
            break;
        case 'if_in_group':
            $groups = '';
            $_groups = explode(',', $attributes['param']);
            $all_groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list();
            foreach ($_groups as $group) {
                $find = array_search($group, $all_groups);
                if ($find === false) {
                    if ($groups != '') {
                        $groups .= ',';
                    }
                    $groups .= $group;
                } else {
                    if ($groups != '') {
                        $groups .= ',';
                    }
                    $groups .= strval($find);
                }
            }
            $temp_tpl = do_template('COMCODE_IF_IN_GROUP', array('_GUID' => '761a7cc07f7b4b68508d68ce19b87d2c', 'TYPE' => array_key_exists('type', $attributes) ? $attributes['type'] : '', 'CONTENT' => $embed, 'GROUPS' => $groups));
            break;
        case 'acronym':
        case 'abbr':
            $temp_tpl = do_template('COMCODE_ABBR', array('_GUID' => 'acbc4f991dsf03f81b61919b74ac24c91', 'CONTENT' => $embed, 'TITLE' => $attributes['param']));
            break;
        case 'address':
            $temp_tpl = do_template('COMCODE_ADDRESS', array('_GUID' => 'acbcsdf9910703f81b61919b74ac24c91', 'CONTENT' => $embed));
            break;
        case 'dfn':
            $temp_tpl = do_template('COMCODE_DFN', array('_GUID' => 'acbc4f9910703f81b61sf19b74ac24c91', 'CONTENT' => $embed));
            break;
        case 'pulse':
            $min_color = array_key_exists('min', $attributes) ? $attributes['min'] : '0000FF';
            $max_color = array_key_exists('max', $attributes) ? $attributes['max'] : 'FF0044';
            if (substr($min_color, 0, 1) == '#') {
                $min_color = substr($min_color, 1);
            }
            if (substr($max_color, 0, 1) == '#') {
                $max_color = substr($max_color, 1);
            }
            $speed = $attributes['param'] == '' ? 100 : intval($attributes['param']);
            $temp_tpl = do_template('COMCODE_PULSE', array('_GUID' => 'adsd4f9910sfd03f81b61919b74ac24c91', 'RAND_ID' => uniqid('', true), 'CONTENT' => $embed, 'MIN_COLOR' => $min_color, 'MAX_COLOR' => $max_color, 'SPEED' => strval($speed)));
            break;
        case 'del':
            $cite = array_key_exists('cite', $attributes) ? $attributes['cite'] : NULL;
            if (!is_null($cite)) {
                $temp_tpl = test_url($cite, 'del', $cite, $source_member);
            }
            $datetime = array_key_exists('datetime', $attributes) ? $attributes['datetime'] : NULL;
            $temp_tpl->attach(do_template('COMCODE_DEL', array('_GUID' => 'acsd4f9910sfd03f81b61919b74ac24c91', 'CONTENT' => $embed, 'CITE' => $cite, 'DATETIME' => $datetime)));
            break;
        case 'ins':
            $cite = array_key_exists('cite', $attributes) ? $attributes['cite'] : NULL;
            if (!is_null($cite)) {
                $temp_tpl = test_url($cite, 'ins', $cite, $source_member);
                if (!$temp_tpl->is_empty()) {
                    break;
                }
            }
            $datetime = array_key_exists('datetime', $attributes) ? $attributes['datetime'] : NULL;
            $temp_tpl->attach(do_template('COMCODE_INS', array('_GUID' => 'asss4f9910703f81b61919bsfc24c91', 'CONTENT' => $embed, 'CITE' => $cite, 'DATETIME' => $datetime)));
            break;
        case 'cite':
            $temp_tpl = do_template('COMCODE_CITE', array('_GUID' => 'acbcsf910703f81b61919b74ac24c91', 'CONTENT' => $embed));
            break;
        case 'b':
            if ($semiparse_mode) {
                $temp_tpl = make_string_tempcode('<b>' . $embed->evaluate() . '</b>');
                break;
            }
            $temp_tpl = do_template('COMCODE_BOLD', array('_GUID' => 'acbc4fds910703f81b619sf74ac24c91', 'CONTENT' => $embed));
            break;
        case 'align':
            if ($wml) {
                $temp_tpl = $embed;
                break;
            }
            $align = array_key_exists('param', $attributes) ? $attributes['param'] : 'left';
            $temp_tpl = do_template('COMCODE_ALIGN', array('_GUID' => '950b4d9db12cac6bf536860bedd96a36', 'ALIGN' => $align, 'CONTENT' => $embed));
            break;
        case 'indent':
            if ($wml) {
                $temp_tpl = $embed;
                break;
            }
            $indent = array_key_exists('param', $attributes) ? $attributes['param'] : '10';
            if (!is_numeric($indent)) {
                $indent = '10';
            }
            $temp_tpl = do_template('COMCODE_INDENT', array('_GUID' => 'd8e69fa17eebd5312e3ad5788e3a1343', 'INDENT' => $indent, 'CONTENT' => $embed));
            break;
        case 'surround':
            if ($wml) {
                $temp_tpl = $embed;
                break;
            }
            if ($semiparse_mode && $embed->evaluate() == '') {
                $temp_tpl = make_string_tempcode('<kbd class="ocp_keep" title="no_parse">[surround="' . comcode_escape(array_key_exists('param', $attributes) ? $attributes['param'] : 'float_surrounder') . '"]' . $embed->evaluate() . '[/surround]</kbd>');
                break;
            }
            $class = array_key_exists('param', $attributes) && $attributes['param'] != '' ? $attributes['param'] : 'float_surrounder';
            $temp_tpl = do_template('COMCODE_SURROUND', array('_GUID' => 'e8e69fa17eebd5312e3ad5788e3a1343', 'CLASS' => $class, 'CONTENT' => $embed));
            break;
        case 'i':
            if ($semiparse_mode) {
                $temp_tpl = make_string_tempcode('<i>' . $embed->evaluate() . '</i>');
                break;
            }
            $temp_tpl = do_template('COMCODE_ITALICS', array('_GUID' => '4321a1fe3825418e57a29410183c0c60', 'CONTENT' => $embed));
            break;
        case 'u':
            if ($semiparse_mode) {
                $temp_tpl = make_string_tempcode('<u>' . $embed->evaluate() . '</u>');
                break;
            }
            $temp_tpl = do_template('COMCODE_UNDERLINE', array('_GUID' => '69cc8e73b17f9e6a35eb1af2bd1dc6ab', 'CONTENT' => $embed));
            break;
        case 's':
            if ($wml) {
                $temp_tpl = $embed;
                break;
            }
            if ($semiparse_mode) {
                $temp_tpl = make_string_tempcode('<strike>' . $embed->evaluate() . '</strike>');
                break;
            }
            $temp_tpl = do_template('COMCODE_STRIKE', array('_GUID' => 'ed242591cefd365497cc0c63abbb11a9', 'CONTENT' => $embed));
            break;
        case 'tooltip':
            $param = is_object($attributes['param']) ? $attributes['param'] : comcode_to_tempcode($attributes['param'], $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member);
            if ($wml) {
                $temp_tpl->attach($embed);
                $temp_tpl->attach('[ ');
                $temp_tpl->attach($param);
                $temp_tpl->attach(' ]');
                break;
            }
            $temp_tpl = do_template('COMCODE_TOOLTIP', array('_GUID' => 'c9f4793dc0c1a92cd7d08ae1b87c2308', 'URL' => array_key_exists('url', $attributes) ? $attributes['url'] : '', 'TOOLTIP' => $param, 'CONTENT' => $embed));
            break;
        case 'sup':
            if ($wml) {
                $temp_tpl->attach('^');
                $temp_tpl->attach($embed);
                break;
            }
            $temp_tpl = do_template('COMCODE_SUP', array('_GUID' => '74d2ecfe193dacb6d922bc288828196a', 'CONTENT' => $embed));
            break;
        case 'sub':
            if ($wml) {
                $temp_tpl->attach('{');
                $temp_tpl->attach($embed);
                $temp_tpl->attach('}');
                break;
            }
            $temp_tpl = do_template('COMCODE_SUB', array('_GUID' => '515e310e00a6d7c30f7dca0a5956ebcf', 'CONTENT' => $embed));
            break;
        case 'title':
            if ($semiparse_mode && strpos($comcode, '[contents') !== false) {
                $temp_tpl = make_string_tempcode('[title' . reinsert_parameters($attributes) . ']' . $embed->evaluate() . '[/title]');
                break;
            }
            $level = $attributes['param'] != '' ? intval($attributes['param']) : 1;
            if ($level == 0) {
                $level = 1;
            }
            // Stop crazy Comcode causing stack errors with the toc
            $uniq_id = strval(count($STRUCTURE_LIST));
            $STRUCTURE_LIST[] = array($level, $embed, $uniq_id);
            if ($level == 1) {
                $template = 'SCREEN_TITLE';
            } elseif ($level == 2) {
                $template = 'COMCODE_SECTION_TITLE';
            } elseif ($level == 3) {
                $template = 'COMCODE_MINOR_TITLE';
            } elseif ($level == 4) {
                $template = 'COMCODE_VERY_MINOR_TITLE';
            } else {
                $template = 'COMCODE_VERY_MINOR_TITLE';
            }
            if ($level == 1) {
                if (is_null($COMCODE_PARSE_TITLE)) {
                    $COMCODE_PARSE_TITLE = $embed->evaluate();
                    if (is_object($COMCODE_PARSE_TITLE)) {
                        $COMCODE_PARSE_TITLE = $COMCODE_PARSE_TITLE->evaluate();
                    }
                }
            }
            $base = array_key_exists('base', $attributes) ? intval($attributes['base']) : 2;
            if (array_key_exists('number', $attributes) && $level >= $base) {
                $list_types = $attributes['number'] == '' ? array() : explode(',', $attributes['number']);
                $list_types = array_merge($list_types, array('decimal', 'lower-alpha', 'lower-roman', 'upper-alpha', 'upper-roman', 'disc'));
                $numerals = array('i', 'ii', 'iii', 'iv', 'v', 'vi', 'viii', 'ix', 'x', 'xi', 'xii', 'xiii', 'xiv', 'xv', 'xvi', 'xvii', 'xviii', 'xix', 'xx');
                $symbol_lookup = array('decimal' => range(1, 100), 'lower-alpha' => range('a', 'z'), 'lower-roman' => $numerals, 'upper-alpha' => range('A', 'Z'), 'upper-roman' => str_replace('i', 'I', str_replace('v', 'V', str_replace('x', 'X', $numerals))));
                $level_text = '';
                $list_pos = count($STRUCTURE_LIST) - 2;
                for ($j = $level; $j >= $base; $j--) {
                    $num_before = 0;
                    for ($i = $list_pos; $i >= 0; $i--) {
                        $list_pos--;
                        if ($STRUCTURE_LIST[$i][0] == $j - 1) {
                            break;
                        }
                        if ($STRUCTURE_LIST[$i][0] == $j) {
                            $num_before++;
                        }
                    }
                    $level_number = @strval($symbol_lookup[$list_types[$j - $base]][$num_before]);
                    $level_text = $level_number . ($level_text != '' ? '.' : '') . $level_text;
                }
                $old_embed = $embed;
                $embed = make_string_tempcode($level_text . ' &ndash; ');
                $embed->attach($old_embed);
            }
            if ($wml) {
                if ($level == 1) {
                    $temp_tpl->attach('<br /><p><big><u><b>');
                    $temp_tpl->attach($embed);
                    $temp_tpl->attach('</b></u></big></p><br />');
                } elseif ($level == 2) {
                    $temp_tpl->attach('<br /><p><big><u>');
                    $temp_tpl->attach($embed);
                    $temp_tpl->attach('</u></big></p><br />');
                } elseif ($level == 3) {
                    $temp_tpl->attach('<br /><p><big>');
                    $temp_tpl->attach($embed);
                    $temp_tpl->attach('</big></p><br />');
                } elseif ($level == 4) {
                    $temp_tpl->attach('<br /><p>');
                    $temp_tpl->attach($embed);
                    $temp_tpl->attach('</p><br />');
                }
                break;
            }
            if ($semiparse_mode) {
                $temp_tpl = make_string_tempcode('<h' . strval($level) . ($level == 1 ? ' class="main_page_title"' : '') . '><span class="inner">' . $embed->evaluate() . '</span></h' . strval($level) . '>');
                break;
            }
            $tpl_map = array('ID' => substr($pass_id, 0, 5) == 'panel' ? NULL : $uniq_id, 'TITLE' => $embed, 'HELP_URL' => '', 'HELP_TERM' => '');
            if (array_key_exists('sub', $attributes)) {
                $tpl_map['SUB'] = protect_from_escaping(comcode_to_tempcode($attributes['sub'], $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member));
            }
            $temp_tpl = do_template($template, $tpl_map);
            break;
        case 'attachment':
        case 'attachment2':
            // legacy
        // legacy
        case 'attachment_safe':
            if ($wml) {
                break;
            }
            require_code('attachments');
            if (is_null($on_behalf_of_member)) {
                $on_behalf_of_member = $source_member;
            }
            $id = $embed->evaluate();
            global $COMCODE_ATTACHMENTS;
            if (!is_numeric($id) && !$as_admin && !has_specific_permission($source_member, 'exceed_filesize_limit')) {
                // We work all this out before we do any downloads, to make sure orphaned files aren't dumped on the file system (possible hack method)
                if (get_forum_type() == 'ocf') {
                    require_lang('ocf');
                    require_code('ocf_groups');
                    $daily_quota = ocf_get_member_best_group_property($source_member, 'max_daily_upload_mb');
                } else {
                    $daily_quota = 5;
                    // 5 is a hard coded default for non-OCF forums
                }
                if (!is_null($daily_quota)) {
                    $_size_uploaded_today = $connection->query('SELECT SUM(a_file_size) AS the_answer FROM ' . $connection->get_table_prefix() . 'attachments WHERE a_member_id=' . strval((int) $source_member) . ' AND a_add_time>' . strval(time() - 60 * 60 * 24));
                    if (is_null($_size_uploaded_today[0]['the_answer'])) {
                        $_size_uploaded_today[0]['the_answer'] = 0;
                    }
                    $size_uploaded_today = ceil((double) $_size_uploaded_today[0]['the_answer'] / 1024.0 / 1024.0);
                    $attach_size = 0;
                    require_code('uploads');
                    is_swf_upload(true);
                    foreach ($_FILES as $_file) {
                        $attach_size += floatval($_file['size']) / 1024.0 / 1024.0;
                    }
                    if ($size_uploaded_today + $attach_size > floatval($daily_quota)) {
                        $temp_tpl = do_template('WARNING_TABLE', array('WARNING' => do_lang_tempcode('OVER_DAILY_QUOTA', integer_format($daily_quota), float_format($size_uploaded_today))));
                        break;
                    }
                }
            }
            $thumb_url = array_key_exists('thumb_url', $attributes) ? $attributes['thumb_url'] : '';
            // Embedded attachments
            if (!is_numeric($id) && substr($id, 0, 4) != 'new_' && substr($id, 0, 4) != 'url_') {
                $file = base64_decode(str_replace(chr(10), '', $id));
                if ($file === false) {
                    $temp_tpl = do_template('WARNING_TABLE', array('WARNING' => do_lang_tempcode('comcode:CORRUPT_ATTACHMENT')));
                    break;
                }
                $md5 = md5(substr($file, 0, 30));
                $original_filename = array_key_exists('filename', $attributes) ? $attributes['filename'] : $md5 . '.dat';
                if (get_file_extension($original_filename) != 'dat') {
                    require_code('files2');
                    check_extension($original_filename, true);
                    $new_filename = $md5 . '.' . get_file_extension($original_filename) . '.dat';
                } else {
                    $new_filename = $md5 . '.' . get_file_extension($original_filename);
                }
                $path = get_custom_file_base() . '/uploads/attachments/' . $new_filename;
                $myfile = @fopen($path, 'wb');
                if ($myfile === false) {
                    $temp_tpl = do_template('WARNING_TABLE', array('WARNING' => intelligent_write_error_inline($path)));
                    break;
                }
                if (fwrite($myfile, $file) < strlen($file)) {
                    warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
                }
                fclose($myfile);
                fix_permissions($path);
                sync_file($path);
                $_size = strlen($file);
                $url = 'uploads/attachments/' . $new_filename;
                if ($connection->connection_write != $GLOBALS['SITE_DB']->connection_write) {
                    $url = get_custom_base_url() . '/' . $url;
                }
                // Thumbnail
                if ($thumb_url == '') {
                    require_code('images');
                    if (is_image($original_filename)) {
                        $gd = get_option('is_on_gd') == '1' && function_exists('imagetypes');
                        if ($gd) {
                            require_code('images');
                            if (!is_saveable_image($url)) {
                                $ext = '.png';
                            } else {
                                $ext = '.' . get_file_extension($original_filename);
                            }
                            $thumb_url = 'uploads/attachments_thumbs/' . $md5 . $ext;
                            convert_image(get_custom_base_url() . '/' . $url, get_custom_file_base() . '/' . $thumb_url, -1, -1, intval(get_option('thumb_width')), true, NULL, false, true);
                            if ($connection->connection_write != $GLOBALS['SITE_DB']->connection_write) {
                                $thumb_url = get_custom_base_url() . '/' . $thumb_url;
                            }
                        } else {
                            $thumb_url = $url;
                        }
                    }
                }
                if (addon_installed('galleries')) {
                    require_code('images');
                    if (is_video($url) && $connection->connection_read == $GLOBALS['SITE_DB']->connection_read) {
                        require_code('transcoding');
                        $url = transcode_video($url, 'attachments', 'a_url', 'a_original_filename', NULL, NULL);
                    }
                }
                $attachment = array('a_member_id' => $on_behalf_of_member, 'a_file_size' => $_size, 'a_url' => $url, 'a_thumb_url' => $thumb_url, 'a_original_filename' => $original_filename, 'a_num_downloads' => 0, 'a_last_downloaded_time' => NULL, 'a_add_time' => time());
                $attachment['a_description'] = array_key_exists('description', $attributes) ? is_object($attributes['description']) ? '[html]' . $attributes['description']->evaluate() . '[/html]' : $attributes['description'] : '';
                $attach_id = $connection->query_insert('attachments', $attachment, true);
                $attachment['id'] = $attach_id;
                // Create and document attachment
                if (!array_key_exists('type', $attributes)) {
                    $attributes['type'] = 'auto';
                }
                $COMCODE_ATTACHMENTS[$pass_id][] = array('tag_type' => $tag, 'type' => 'new', 'attachmenttype' => $attributes['type'], 'description' => $attachment['a_description'], 'id' => intval($attach_id), 'marker' => $marker, 'comcode' => $comcode);
                // Marker will allow us to search back and replace this with the added id
            } elseif (!is_numeric($id)) {
                require_code('uploads');
                if (substr($id, 0, 4) == 'new_') {
                    $_id = substr($id, 4);
                    if (!is_numeric($_id)) {
                        $temp_tpl = do_template('WARNING_TABLE', array('WARNING' => do_lang_tempcode('comcode:INVALID_ATTACHMENT')));
                        break;
                    }
                    $attributes['type'] = post_param('attachmenttype' . $_id, array_key_exists('type', $attributes) ? $attributes['type'] : 'auto');
                    if (substr($attributes['type'], -8) == '_extract') {
                        $attributes['type'] = substr($attributes['type'], 0, strlen($attributes['type']) - 8);
                    }
                    $urls = get_url('', 'file' . $_id, 'uploads/attachments', 2, OCP_UPLOAD_ANYTHING, (!array_key_exists('thumb', $attributes) || $attributes['thumb'] != '0') && $thumb_url == '', '', '', true, true, true);
                    if ($urls[0] == '') {
                        return new ocp_tempcode();
                    }
                    //warn_exit(do_lang_tempcode('ERROR_UPLOADING'));  Can't do this, because this might not be post-calculated if something went wrong once
                    is_swf_upload(true);
                    $_size = $_FILES['file' . $_id]['size'];
                    $original_filename = $_FILES['file' . $_id]['name'];
                    if (get_magic_quotes_gpc()) {
                        $original_filename = stripslashes($original_filename);
                    }
                } elseif (substr($id, 0, 4) == 'url_') {
                    if (!has_specific_permission($source_member, 'draw_to_server') && !$as_admin) {
                        break;
                    }
                    $_id = '!';
                    $attributes['type'] = post_param('attachmenttype' . $_id, array_key_exists('type', $attributes) ? $attributes['type'] : 'auto');
                    $url = remove_url_mistakes(substr($id, 4));
                    $_POST['_specify_url'] = $url;
                    // Little hack, as we need to read it from a POST
                    if (get_magic_quotes_gpc()) {
                        $_POST['_specify_url'] = addslashes($_POST['_specify_url']);
                    }
                    $urls = get_url('_specify_url', '', 'uploads/filedump', 1, OCP_UPLOAD_ANYTHING, (!array_key_exists('thumb', $attributes) || $attributes['thumb'] != '0') && $thumb_url == '', '', '', true, true);
                    if ($urls[0] == '') {
                        return new ocp_tempcode();
                    }
                    $original_filename = rawurldecode(substr($url, strrpos($url, '/') + 1));
                    if (url_is_local($urls[0])) {
                        $_size = @filesize(get_custom_file_base() . '/' . rawurldecode($urls[0]));
                        if ($_size === false) {
                            $_size = filesize(get_file_base() . '/' . rawurldecode($urls[0]));
                        }
                    } else {
                        $_size = 0;
                    }
                } else {
                    $temp_tpl = do_template('WARNING_TABLE', array('WARNING' => do_lang_tempcode('comcode:INVALID_ATTACHMENT')));
                    break;
                }
                if ($urls[0] == '') {
                    require_code('images');
                    require_code('files2');
                    $temp_tpl = do_template('WARNING_TABLE', array('WARNING' => do_lang_tempcode('ATTACHMENT_WOULD_NOT_UPLOAD', float_format(get_max_file_size() / 1024 / 1024), float_format(get_max_image_size() / 1024 / 1024))));
                    break;
                }
                $url = $urls[0];
                if ($connection->connection_write != $GLOBALS['SITE_DB']->connection_write) {
                    $url = get_custom_base_url() . '/' . $url;
                }
                if ($thumb_url == '') {
                    $thumb_url = array_key_exists(1, $urls) ? $urls[1] : '';
                }
                if ($thumb_url != '' && $connection != $GLOBALS['SITE_DB']) {
                    $thumb_url = get_custom_base_url() . '/' . $thumb_url;
                }
                $num_downloads = 0;
                $last_downloaded_time = NULL;
                $add_time = time();
                $member_id = $on_behalf_of_member;
                if (addon_installed('galleries')) {
                    require_code('images');
                    if (is_video($url) && $connection->connection_read == $GLOBALS['SITE_DB']->connection_read) {
                        require_code('transcoding');
                        $url = transcode_video($url, 'attachments', 'a_url', 'a_original_filename', NULL, NULL);
                    }
                }
                $attachment = array('a_member_id' => $member_id, 'a_file_size' => $_size, 'a_url' => $url, 'a_thumb_url' => $thumb_url, 'a_original_filename' => $original_filename, 'a_num_downloads' => $num_downloads, 'a_last_downloaded_time' => $last_downloaded_time, 'a_add_time' => $add_time);
                $attachment['a_description'] = post_param('caption' . $_id, array_key_exists('description', $attributes) ? is_object($attributes['description']) ? '[html]' . $attributes['description']->evaluate() . '[/html]' : $attributes['description'] : '');
                $attach_id = $connection->query_insert('attachments', $attachment, true);
                $attachment['id'] = $attach_id;
                if ($tag == 'attachment2' || $tag == 'attachment_safe' || substr($id, 0, 4) == 'url_') {
                    $connection->query_delete('attachment_refs', array('r_referer_type' => 'null', 'r_referer_id' => '', 'a_id' => $attachment['id']), '', 1);
                    $connection->query_insert('attachment_refs', array('r_referer_type' => 'null', 'r_referer_id' => '', 'a_id' => $attachment['id']));
                }
                // Create and document attachment
                $COMCODE_ATTACHMENTS[$pass_id][] = array('tag_type' => $tag, 'time' => time(), 'type' => substr($id, 0, 4) == 'new_' ? 'new' : 'url', 'attachmenttype' => $attributes['type'], 'description' => $attachment['a_description'], 'id' => intval($attach_id), 'marker' => $marker, 'comcode' => $comcode);
                // Marker will allow us to search back and replace this with the added id
                // Existing attachments
            } else {
                $__id = intval($id);
                // Check we have permission to re-use this
                $owner = $connection->query_value_null_ok('attachments', 'a_member_id', array('id' => $__id));
                if (is_null($owner)) {
                    $temp_tpl = do_template('WARNING_TABLE', array('WARNING' => do_lang_tempcode('MISSING_RESOURCE_COMCODE', 'attachment', escape_html(strval($__id)))));
                    if (!in_array(get_page_name(), $GLOBALS['DONT_CARE_MISSING_PAGES']) && !running_script('iframe')) {
                        require_code('failure');
                        relay_error_notification(do_lang('MISSING_RESOURCE_COMCODE', 'attachment', strval($__id)), false, $GLOBALS['FORUM_DRIVER']->is_staff($source_member) ? 'error_occurred_missing_reference_important' : 'error_occurred_missing_reference');
                    }
                    break;
                }
                $_attachment = $connection->query_select('attachments', array('*'), array('id' => $__id), '', 1);
                $attachment = $_attachment[0];
                $already_referenced = array_key_exists($__id, $GLOBALS['ATTACHMENTS_ALREADY_REFERENCED']);
                if ($already_referenced || $as_admin || $source_member === $owner || (has_specific_permission($source_member, 'reuse_others_attachments') || $owner == $source_member) && has_attachment_access($source_member, $__id)) {
                    if (!array_key_exists('type', $attributes)) {
                        $attributes['type'] = 'auto';
                    }
                    $COMCODE_ATTACHMENTS[$pass_id][] = array('tag_type' => $tag, 'time' => $attachment['a_add_time'], 'type' => 'existing', 'id' => $__id, 'attachmenttype' => $attributes['type'], 'marker' => $marker, 'comcode' => $comcode);
                } else {
                    require_lang('permissions');
                    $username = $GLOBALS['FORUM_DRIVER']->get_username($source_member);
                    if (is_null($username)) {
                        $username = do_lang('DELETED');
                    }
                    $temp_tpl = do_template('WARNING_TABLE', array('WARNING' => do_lang_tempcode('permissions:ACCESS_DENIED__REUSE_ATTACHMENT', $username)));
                    break;
                    //access_denied('REUSE_ATTACHMENT');
                }
                if ($connection->connection_write != $GLOBALS['SITE_DB']->connection_write) {
                    if (url_is_local($attachment['a_url'])) {
                        $attachment['a_url'] = get_custom_base_url() . '/' . $attachment['a_url'];
                    }
                    if (url_is_local($attachment['a_url'])) {
                        $attachment['a_thumb_url'] = get_custom_base_url() . '/' . $attachment['a_thumb_url'];
                    }
                }
                $attachment['a_description'] = array_key_exists('description', $attributes) ? is_object($attributes['description']) ? '[html]' . $attributes['description']->evaluate() . '[/html]' : $attributes['description'] : $attachment['a_description'];
            }
            // Now, render it
            // ==============
            $temp_tpl = render_attachment($tag, $attributes, $attachment, $pass_id, $source_member, $as_admin, $connection, $highlight_bits, $on_behalf_of_member, $semiparse_mode);
            if (array_key_exists('float', $attributes)) {
                $temp_tpl = do_template('FLOATER', array('_GUID' => '802fe29019be80993296de7cc8b5cc5e', 'FLOAT' => $attributes['float'], 'CONTENT' => $temp_tpl));
            }
            break;
        case 'include':
            $codename = $embed->evaluate();
            $zone = $attributes['param'];
            if ($zone == '_SEARCH') {
                $zone = get_comcode_zone($codename);
            }
            if ($zone == '_SELF') {
                $zone = get_zone_name();
            }
            $temp_comcode_parse_title = $COMCODE_PARSE_TITLE;
            $temp = request_page($codename, false, $zone, NULL, true);
            $COMCODE_PARSE_TITLE = $temp_comcode_parse_title;
            if ($temp->is_empty()) {
                $temp_tpl = do_template('WARNING_TABLE', array('WARNING' => do_lang_tempcode('MISSING_RESOURCE_COMCODE', 'include', hyperlink(build_url(array('page' => 'cms_comcode_pages', 'type' => '_ed', 'page_link' => $zone . ':' . $codename), get_module_zone('cms_comcode_pages')), $zone . ':' . $codename, false, true))));
                if (!in_array(get_page_name(), $GLOBALS['DONT_CARE_MISSING_PAGES']) && !running_script('iframe')) {
                    require_code('failure');
                    relay_error_notification(do_lang('MISSING_RESOURCE_COMCODE', 'include', $zone . ':' . $codename), false, $GLOBALS['FORUM_DRIVER']->is_staff($source_member) ? 'error_occurred_missing_reference_important' : 'error_occurred_missing_reference');
                }
            } else {
                $temp_tpl = symbol_tempcode('LOAD_PAGE', array($codename, $zone));
            }
            break;
        case 'random':
            unset($attributes['param']);
            if ($wml) {
                $top_attribute = array_pop($attributes);
                $temp_tpl = is_object($top_attribute) ? $top_attribute : comcode_to_tempcode($top_attribute, $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member);
                break;
            }
            $max = $embed->evaluate() == '' ? intval($embed->evaluate()) : 0;
            foreach ($attributes as $num => $val) {
                $_temp = is_object($val) ? $val : comcode_to_tempcode($val, $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member);
                $attributes[$num] = $_temp->evaluate();
                if (intval($num) > $max) {
                    $max = intval($num);
                }
            }
            $_parts = new ocp_tempcode();
            krsort($attributes);
            foreach ($attributes as $num => $val) {
                $_parts->attach(do_template('COMCODE_RANDOM_PART', array('_GUID' => '5fa49a916304f9caa0ddedeb01531142', 'NUM' => strval($num), 'VAL' => $val)));
            }
            $temp_tpl = do_template('COMCODE_RANDOM', array('_GUID' => '9b77aaf593b12c763fb0c367fab415b6', 'UNIQID' => uniqid('', true), 'FULL' => $embed, 'MAX' => strval($max), 'PARTS' => $_parts));
            break;
        case 'jumping':
            unset($attributes['param']);
            if ($wml) {
                $top_attribute = array_pop($attributes);
                $temp_tpl = is_object($top_attribute) ? $top_attribute : comcode_to_tempcode($top_attribute, $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member);
                break;
            }
            $_parts = new ocp_tempcode();
            foreach ($attributes as $val) {
                $_temp = is_object($val) ? $val : comcode_to_tempcode($val, $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member);
                $_parts->attach(do_template('COMCODE_JUMPING_PART', array('_GUID' => 'd163bd11920f39f0cb8ff2f6ba48bc80', 'PART' => $_temp->evaluate())));
            }
            $embed = $embed->evaluate();
            $temp_tpl = do_template('COMCODE_JUMPING', array('_GUID' => '85e9f83ed134868436a7db7692f56047', 'UNIQID' => uniqid('', true), 'FULL' => implode(', ', $attributes), 'TIME' => strval((int) $embed), 'PARTS' => $_parts));
            break;
        case 'shocker':
            if ($wml) {
                $top_attribute = array_pop($attributes);
                $temp_tpl = is_object($top_attribute) ? $top_attribute : comcode_to_tempcode($top_attribute, $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member);
                break;
            }
            $_parts = new ocp_tempcode();
            foreach ($attributes as $key => $val) {
                if (substr($key, 0, 5) == 'left_') {
                    $left = $val;
                    $right = array_key_exists('right_' . substr($key, 5), $attributes) ? $attributes['right_' . substr($key, 5)] : '';
                    $left = is_object($left) ? $left : comcode_to_tempcode($left, $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member);
                    $right = is_object($right) ? $right : comcode_to_tempcode($right, $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member);
                    $_parts->attach(do_template('COMCODE_SHOCKER_PART', array('LEFT' => $left, 'RIGHT' => $right)));
                }
            }
            $min_color = array_key_exists('min', $attributes) ? $attributes['min'] : '0000FF';
            $max_color = array_key_exists('max', $attributes) ? $attributes['max'] : 'FF0044';
            if (substr($min_color, 0, 1) == '#') {
                $min_color = substr($min_color, 1);
            }
            if (substr($max_color, 0, 1) == '#') {
                $max_color = substr($max_color, 1);
            }
            $embed = $embed->evaluate();
            $temp_tpl = do_template('COMCODE_SHOCKER', array('UNIQID' => uniqid('', true), 'MIN_COLOR' => $min_color, 'MAX_COLOR' => $max_color, 'FULL' => implode(', ', $attributes), 'TIME' => strval(intval($embed)), 'PARTS' => $_parts));
            break;
        case 'ticker':
            if ($wml) {
                $temp_tpl = $embed;
                break;
            }
            $width = $attributes['param'];
            if (!is_numeric($width)) {
                $width = '300';
            }
            $fspeed = array_key_exists('speed', $attributes) ? float_to_raw_string(floatval($attributes['speed'])) : '1';
            $temp_tpl = do_template('COMCODE_TICKER', array('_GUID' => 'e48893cda61995261577f0556443c537', 'UNIQID' => uniqid('', true), 'SPEED' => $fspeed, 'WIDTH' => $width, 'TEXT' => $embed));
            break;
        case 'highlight':
            if ($wml) {
                $temp_tpl->attach('<i>');
                $temp_tpl->attach($embed);
                $temp_tpl->attach('</i>');
                break;
            }
            $temp_tpl = do_template('COMCODE_HIGHLIGHT', array('_GUID' => '695d041b6605f06ec2aeee1e82f87185', 'CONTENT' => $embed));
            break;
        case 'size':
            $size = array_key_exists('param', $attributes) ? $attributes['param'] : '1';
            if ($wml) {
                if (floatval($size) >= 1.5) {
                    $temp_tpl->attach('<big>');
                    $temp_tpl->attach($embed);
                    $temp_tpl->attach('</big>');
                } elseif (floatval($size) < 0.8) {
                    $temp_tpl->attach('<small>');
                    $temp_tpl->attach($embed);
                    $temp_tpl->attach('</small>');
                } else {
                    $temp_tpl->attach($embed);
                }
                break;
            }
            if (is_numeric($size)) {
                $size = 'font-size: ' . $size . 'em;';
            } elseif (substr($size, 0, 1) == '+') {
                $size = 'font-size: ' . substr($size, 1) . 'em';
            } elseif (substr($size, -1) == '%') {
                $size = 'font-size: ' . float_to_raw_string(floatval(substr($size, 0, strlen($size) - 1)) / 100.0) . 'em';
            } elseif (substr($size, -2) == 'of') {
                $new_size = '1em';
                switch ($size) {
                    case '1of':
                        $new_size = '8pt';
                        break;
                    case '2of':
                        $new_size = '10pt';
                        break;
                    case '3of':
                        $new_size = '12pt';
                        break;
                    case '4of':
                        $new_size = '14pt';
                        break;
                    case '5of':
                        $new_size = '18pt';
                        break;
                    case '6of':
                        $new_size = '24pt';
                        break;
                    case '7of':
                        $new_size = '36pt';
                        break;
                }
                $size = 'font-size: ' . $new_size;
            } else {
                $size = 'font-size: ' . $size;
            }
            $size_len = strlen($size);
            filter_html($as_admin, $source_member, 0, $size_len, $size, false, false);
            $temp_tpl = do_template('COMCODE_FONT', array('_GUID' => 'fb23fdcb45aabdfeca9f37ed8098948e', 'CONTENT' => $embed, 'SIZE' => $size, 'COLOR' => '', 'FACE' => ''));
            break;
        case 'color':
            if ($wml) {
                $temp_tpl = $embed;
                break;
            }
            $color = array_key_exists('param', $attributes) ? 'color: ' . $attributes['param'] . ';' : '';
            $temp_tpl = do_template('COMCODE_FONT', array('_GUID' => 'bd146414c9239ba2076f4b683df437d7', 'CONTENT' => $embed, 'SIZE' => '', 'COLOR' => $color, 'FACE' => ''));
            $color_len = strlen($color);
            filter_html($as_admin, $source_member, 0, $color_len, $color, false, false);
            break;
        case 'tt':
            if ($wml) {
                $temp_tpl->attach('<i>');
                $temp_tpl->attach($embed);
                $temp_tpl->attach('</i>');
                break;
            }
            $temp_tpl = do_template('COMCODE_TELETYPE', array('CONTENT' => $embed));
            break;
        case 'samp':
            if ($wml) {
                $temp_tpl->attach('<i>');
                $temp_tpl->attach($embed);
                $temp_tpl->attach('</i>');
                break;
            }
            $temp_tpl = do_template('COMCODE_SAMP', array('CONTENT' => $embed));
            break;
        case 'q':
            if ($wml) {
                $temp_tpl->attach('<i>');
                $temp_tpl->attach($embed);
                $temp_tpl->attach('</i>');
                break;
            }
            $temp_tpl = do_template('COMCODE_Q', array('CONTENT' => $embed));
            break;
        case 'var':
            if ($wml) {
                $temp_tpl->attach('<i>');
                $temp_tpl->attach($embed);
                $temp_tpl->attach('</i>');
                break;
            }
            $temp_tpl = do_template('COMCODE_VAR', array('CONTENT' => $embed));
            break;
        case 'font':
            $face = $attributes['param'];
            if ($face == '' && array_key_exists('face', $attributes)) {
                $face = $attributes['face'];
            }
            $color = array_key_exists('color', $attributes) ? $attributes['color'] : '';
            $size = array_key_exists('size', $attributes) ? $attributes['size'] : '';
            if ($face == '/') {
                $face = '';
            }
            if ($color == '/') {
                $color = '';
            }
            if ($size == '/') {
                $size = '';
            }
            if ($wml) {
                $before = '';
                $after = '';
                if ($size != '') {
                    if (floatval($size) >= 1.5) {
                        $before = '<big>';
                        $after = '</big>';
                    } elseif (floatval($size) < 0.8) {
                        $before = '<small>';
                        $after = '</small>';
                    }
                }
                $temp_tpl->attach($before);
                $temp_tpl->attach($embed);
                $temp_tpl->attach($after);
                break;
            }
            if ($color != '') {
                $color = 'color: ' . $color . ';';
            }
            if ($size != '') {
                if (is_numeric($size)) {
                    $size = 'font-size: ' . $size . 'em;';
                } elseif (substr($size, 0, 1) == '+') {
                    $size = 'font-size: ' . substr($size, 1) . 'em';
                } elseif (substr($size, -1) == '%') {
                    $size = 'font-size: ' . float_to_raw_string(floatval(substr($size, 0, strlen($size) - 1)) / 100.0) . 'em';
                } elseif (substr($size, -2) == 'of') {
                    $new_size = '1em';
                    switch ($size) {
                        case '1of':
                            $new_size = '8pt';
                            break;
                        case '2of':
                            $new_size = '10pt';
                            break;
                        case '3of':
                            $new_size = '12pt';
                            break;
                        case '4of':
                            $new_size = '14pt';
                            break;
                        case '5of':
                            $new_size = '18pt';
                            break;
                        case '6of':
                            $new_size = '24pt';
                            break;
                        case '7of':
                            $new_size = '36pt';
                            break;
                    }
                    $size = 'font-size: ' . $new_size;
                } else {
                    $size = 'font-size: ' . $size;
                }
            }
            if ($face != '') {
                $face = 'font-family: ' . str_replace('\'', '', $face) . ';';
            }
            $size_len = strlen($size);
            filter_html($as_admin, $source_member, 0, $size_len, $size, false, false);
            $color_len = strlen($color);
            filter_html($as_admin, $source_member, 0, $color_len, $color, false, false);
            $face_len = strlen($face);
            filter_html($as_admin, $source_member, 0, $face_len, $face, false, false);
            $temp_tpl = do_template('COMCODE_FONT', array('_GUID' => 'f5fcafe737b8fdf466a6a51773e09c9b', 'CONTENT' => $embed, 'SIZE' => $size, 'COLOR' => $color, 'FACE' => $face));
            break;
        case 'box':
            if ($wml) {
                $temp_tpl->attach('<br /><p>');
                if ($attributes['param'] != '') {
                    $temp_tpl->attach('<big>');
                    $temp_tpl->attach($attributes['param']);
                    $temp_tpl->attach('</big><br /><br />');
                }
                $temp_tpl->attach($embed);
                $temp_tpl->attach('</p></br />');
                break;
            }
            // Legacy parameter. There used to be 'place' and 'nowrap' and 'class', but these are now gone.
            $breadth = array_key_exists('breadth', $attributes) ? $attributes['breadth'] : '100%';
            if ($breadth == 'WIDE') {
                $breadth = '100%';
            }
            if ($breadth == 'WIDE_HIGH') {
                $breadth = '100%';
            }
            if ($breadth == 'THIN') {
                $breadth = 'auto';
            }
            // The new versions
            $dimensions = array_key_exists('dimensions', $attributes) ? comcode_to_tempcode($attributes['dimensions'], $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member) : make_string_tempcode($breadth);
            $type = array_key_exists('type', $attributes) ? $attributes['type'] : '';
            $options = array_key_exists('options', $attributes) ? $attributes['options'] : '';
            $meta = $comcode_dangerous && array_key_exists('meta', $attributes) ? $attributes['meta'] : '';
            //Insecure, unneeded here
            $links = $comcode_dangerous && array_key_exists('links', $attributes) ? $attributes['links'] : '';
            //Insecure, unneeded here
            $converted = is_object($attributes['param']) ? $attributes['param'] : comcode_to_tempcode($attributes['param'], $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member);
            $temp_tpl = directive_tempcode('BOX', $embed, array($converted, $dimensions, make_string_tempcode($type), make_string_tempcode($options), make_string_tempcode($meta), make_string_tempcode($links)));
            if (array_key_exists('float', $attributes)) {
                $temp_tpl = do_template('FLOATER', array('_GUID' => '54e8fc9ec1e16cfc5c8824e22f1e8745', 'FLOAT' => $attributes['float'], 'CONTENT' => $temp_tpl));
            }
            break;
        case 'concept':
            if ($wml) {
                $temp_tpl = $embed;
                break;
            }
            if (!array_key_exists('param', $attributes) || $attributes['param'] == '') {
                $key = $embed->evaluate();
                $temp_tpl = symbol_tempcode('DISPLAY_CONCEPT', array($key));
            } else {
                $temp_tpl = do_template('COMCODE_CONCEPT_INLINE', array('_GUID' => '381a59de4d6f8967446c12bf4641a9ce', 'TEXT' => $embed, 'FULL' => $attributes['param']));
            }
            break;
        case 'concepts':
            if ($wml) {
                break;
            }
            $title = $embed->evaluate();
            $concepts = new ocp_tempcode();
            foreach ($attributes as $_key => $_value) {
                if (substr($_key, -4) == '_key') {
                    $key = $_value;
                    $cid = substr($_key, 0, strlen($_key) - 4);
                    $to_parse = array_key_exists($cid . '_value', $attributes) ? $attributes[$cid . '_value'] : new ocp_tempcode();
                    $value = is_object($to_parse) ? $to_parse : comcode_to_tempcode($to_parse, $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member);
                    $concepts->attach(do_template('COMCODE_CONCEPTS_CONCEPT', array('_GUID' => '4baf6dabc32146c594c7fd922791b6b2', 'A' => 'concept___' . preg_replace('#[^\\w]#', '_', $key), 'KEY' => $key, 'VALUE' => $value)));
                }
            }
            $temp_tpl = do_template('COMCODE_CONCEPTS', array('_GUID' => '4c7a1d70753dc1d209b9951aa10f361a', 'TITLE' => $title, 'CONCEPTS' => $concepts));
            break;
        case 'exp_ref':
            if ($wml) {
                break;
            }
            $_embed = $embed->evaluate();
            if (strpos($_embed, '.') !== false) {
                break;
            }
            $stub = get_file_base() . '/data_custom/images/' . get_zone_name() . '/';
            $stub2 = get_base_url() . '/data_custom/images/' . get_zone_name() . '/';
            if (!file_exists($stub)) {
                $stub = get_file_base() . '/data/images/' . get_zone_name() . '/';
                $stub2 = get_base_url() . '/data/images/' . get_zone_name() . '/';
            }
            if (!file_exists($stub)) {
                $stub = get_file_base() . '/data_custom/images/';
                $stub2 = get_base_url() . '/data_custom/images/';
            }
            if (!file_exists($stub)) {
                $stub = get_file_base() . '/data/images/';
                $stub2 = get_base_url() . '/data/images/';
            }
            if (substr($_embed, 0, 1) == '/') {
                $_embed = substr($_embed, 1);
            }
            if (file_exists($stub . $_embed . '.png')) {
                $url = $stub2 . $_embed . '.png';
            } elseif (file_exists($stub . $_embed . '.gif')) {
                $url = $stub2 . $_embed . '.gif';
            } elseif (file_exists($stub . $_embed . '.jpg')) {
                $url = $stub2 . $_embed . '.jpg';
            } elseif (file_exists($stub . $_embed . '.jpeg')) {
                $url = $stub2 . $_embed . '.jpeg';
            } else {
                $stub = get_file_base() . '/data/images/docs/';
                $stub2 = get_base_url() . '/data/images/docs/';
                if (substr($_embed, 0, 1) == '/') {
                    $_embed = substr($_embed, 1);
                }
                if (file_exists($stub . $_embed . '.png')) {
                    $url = $stub2 . $_embed . '.png';
                } elseif (file_exists($stub . $_embed . '.gif')) {
                    $url = $stub2 . $_embed . '.gif';
                } elseif (file_exists($stub . $_embed . '.jpg')) {
                    $url = $stub2 . $_embed . '.jpg';
                } elseif (file_exists($stub . $_embed . '.jpeg')) {
                    $url = $stub2 . $_embed . '.jpeg';
                } else {
                    $temp_tpl = do_template('WARNING_TABLE', array('WARNING' => do_lang_tempcode('MISSING_RESOURCE_COMCODE', 'exp_ref', escape_html($_embed))));
                    if (array_key_exists('COMCODE_BROKEN_URLS', $GLOBALS)) {
                        $GLOBALS['COMCODE_BROKEN_URLS'][] = array($_embed, NULL);
                    } elseif (!in_array(get_page_name(), $GLOBALS['DONT_CARE_MISSING_PAGES']) && !running_script('iframe')) {
                        require_code('failure');
                        relay_error_notification(do_lang('MISSING_RESOURCE_COMCODE', 'exp_ref', $_embed), false, $GLOBALS['FORUM_DRIVER']->is_staff($source_member) ? 'error_occurred_missing_reference_important' : 'error_occurred_missing_reference');
                    }
                    break;
                }
            }
            $text = make_string_tempcode($attributes['param']);
            if ($text->is_empty()) {
                $text = do_lang_tempcode('EXAMPLE');
            }
            $temp_tpl = do_template('COMCODE_EXP_REF', array('_GUID' => '89e7f528e72096e3458d6acb70734d0b', 'TEXT' => $text, 'URL' => $url));
            break;
        case 'exp_thumb':
            if ($wml) {
                break;
            }
            $_embed = $embed->evaluate();
            if (strpos($_embed, '.') !== false) {
                break;
            }
            $stub = get_file_base() . '/data/images/' . get_zone_name() . '/';
            $stub2 = get_base_url() . '/data/images/' . get_zone_name() . '/';
            if (substr($_embed, 0, 1) == '/') {
                $_embed = substr($_embed, 1);
            }
            if (file_exists($stub . $_embed . '.png')) {
                $url_full = $stub2 . $_embed . '.png';
            } elseif (file_exists($stub . $_embed . '.gif')) {
                $url_full = $stub2 . $_embed . '.gif';
            } elseif (file_exists($stub . $_embed . '.jpg')) {
                $url_full = $stub2 . $_embed . '.jpg';
            } elseif (file_exists($stub . $_embed . '.jpeg')) {
                $url_full = $stub2 . $_embed . '.jpeg';
            } else {
                $stub = get_file_base() . '/data/images/docs/';
                $stub2 = get_base_url() . '/data/images/docs/';
                if (substr($_embed, 0, 1) == '/') {
                    $_embed = substr($_embed, 1);
                }
                if (file_exists($stub . $_embed . '.png')) {
                    $url_full = $stub2 . $_embed . '.png';
                } elseif (file_exists($stub . $_embed . '.gif')) {
                    $url_full = $stub2 . $_embed . '.gif';
                } elseif (file_exists($stub . $_embed . '.jpg')) {
                    $url_full = $stub2 . $_embed . '.jpg';
                } elseif (file_exists($stub . $_embed . '.jpeg')) {
                    $url_full = $stub2 . $_embed . '.jpeg';
                } else {
                    $temp_tpl = do_template('WARNING_TABLE', array('WARNING' => do_lang_tempcode('MISSING_RESOURCE_COMCODE', 'exp_thumb', escape_html($_embed))));
                    if (array_key_exists('COMCODE_BROKEN_URLS', $GLOBALS)) {
                        $GLOBALS['COMCODE_BROKEN_URLS'][] = $_embed;
                    } elseif (!in_array(get_page_name(), $GLOBALS['DONT_CARE_MISSING_PAGES']) && !running_script('iframe')) {
                        require_code('failure');
                        relay_error_notification(do_lang('MISSING_RESOURCE_COMCODE', 'exp_thumb', $_embed), false, $GLOBALS['FORUM_DRIVER']->is_staff($source_member) ? 'error_occurred_missing_reference_important' : 'error_occurred_missing_reference');
                    }
                    break;
                }
            }
            $float = array_key_exists('float', $attributes) ? $attributes['float'] : 'right';
            $text = $attributes['param'];
            if (get_option('is_on_gd') == '0' || !function_exists('imagetypes')) {
                $url_thumb = $url_full;
            } else {
                $new_name = $_embed . '_thumb.png';
                $file_thumb = $stub . $new_name;
                if (file_exists($file_thumb)) {
                    $url_thumb = $stub2 . rawurlencode($new_name);
                } else {
                    $new_name = $_embed . '.png';
                    $file_thumb = get_custom_file_base() . '/uploads/auto_thumbs/' . $new_name;
                    if (!file_exists($file_thumb)) {
                        require_code('images');
                        convert_image($url_full, $file_thumb, -1, -1, 150, false);
                    }
                    $url_thumb = get_custom_base_url() . '/uploads/auto_thumbs/' . rawurlencode($new_name);
                }
            }
            if (get_param_integer('wide_print', 0) == 1) {
                $temp_tpl = do_template('COMCODE_EXP_THUMB_PRINT', array('_GUID' => 'de7f8a7fa29c2335f381a0beb3da9406', 'FLOAT' => $float, 'TEXT' => $text, 'URL_THUMB' => $url_thumb, 'URL_FULL' => $url_full));
            } else {
                $temp_tpl = do_template('COMCODE_EXP_THUMB', array('_GUID' => 'ce7f8a7fa29c2335f381a0beb3da9406', 'FLOAT' => $float, 'TEXT' => $text, 'URL_THUMB' => $url_thumb, 'URL_FULL' => $url_full));
            }
            break;
        case 'thumb':
            if ($wml) {
                break;
            }
            $_embed = $embed->evaluate();
            $_embed = remove_url_mistakes($_embed);
            $_embed = check_naughty_javascript_url($source_member, $_embed, $as_admin);
            if (substr($_embed, 0, 1) == '/') {
                $_embed = substr($_embed, 1);
            }
            if (url_is_local($_embed)) {
                if (file_exists(get_file_base() . '/' . $_embed) && !file_exists(get_custom_file_base() . '/' . $_embed)) {
                    $url_full = get_base_url() . '/' . $_embed;
                } else {
                    $url_full = get_custom_base_url() . '/' . $_embed;
                }
            } else {
                $url_full = $_embed;
            }
            $align = array_key_exists('align', $attributes) ? $attributes['align'] : 'bottom';
            if (get_option('is_on_gd') == '0' || !function_exists('imagetypes') || !has_specific_permission($source_member, 'draw_to_server') && !$as_admin) {
                $url_thumb = $url_full;
            } else {
                if ($attributes['param'] != '') {
                    $url_thumb = url_is_local($attributes['param']) ? get_custom_base_url() . '/' . $attributes['param'] : $attributes['param'];
                }
                if ($attributes['param'] == '' || url_is_local($attributes['param']) && !file_exists(get_custom_file_base() . '/' . rawurldecode($attributes['param']))) {
                    $new_name = url_to_filename($url_full);
                    require_code('images');
                    if (!is_saveable_image($new_name)) {
                        $new_name .= '.png';
                    }
                    if (is_null($new_name)) {
                        $temp_tpl = do_template('WARNING_TABLE', array('WARNING' => do_lang_tempcode('URL_THUMB_TOO_LONG')));
                        break;
                    }
                    $file_thumb = get_custom_file_base() . '/uploads/auto_thumbs/' . $new_name;
                    if (!file_exists($file_thumb) && strpos($file_thumb, '{$') === false) {
                        convert_image($url_full, $file_thumb, -1, -1, intval(get_option('thumb_width')), false);
                    }
                    $url_thumb = get_custom_base_url() . '/uploads/auto_thumbs/' . rawurlencode($new_name);
                }
            }
            $caption = array_key_exists('caption', $attributes) ? $attributes['caption'] : '';
            $temp_tpl = do_template('COMCODE_THUMB', array('_GUID' => '1b0d25f72ef5f816091269e29c586d60', 'CAPTION' => $caption, 'RAND' => strval(mt_rand(0, 32000)), 'ALIGN' => $align, 'PASS_ID' => intval($pass_id) < 0 ? strval(mt_rand(0, 10000)) : $pass_id, 'URL_THUMB' => $url_thumb, 'URL_FULL' => $url_full));
            if (array_key_exists('float', $attributes)) {
                $temp_tpl = do_template('FLOATER', array('_GUID' => 'cbc56770714a44f56676f43da282cc7a', 'FLOAT' => $attributes['float'], 'CONTENT' => $temp_tpl));
            }
            break;
        case 'img':
            if ($wml) {
                break;
            }
            if ($semiparse_mode && array_key_exists('rollover', $attributes)) {
                $temp_tpl = make_string_tempcode('[img' . reinsert_parameters($attributes) . ']' . $embed->evaluate() . '[/img]');
                break;
            }
            $_embed = $embed->evaluate();
            $given_url = $_embed;
            $_embed = remove_url_mistakes($_embed);
            if (substr($_embed, 0, 1) == '/') {
                $_embed = substr($_embed, 1);
            }
            $_embed = check_naughty_javascript_url($source_member, $_embed, $as_admin);
            if (url_is_local($_embed)) {
                if (file_exists(get_file_base() . '/' . $_embed) && !file_exists(get_custom_file_base() . '/' . $_embed)) {
                    $url_full = get_base_url() . '/' . $_embed;
                } else {
                    $url_full = get_custom_base_url() . '/' . $_embed;
                }
            } else {
                $url_full = $_embed;
            }
            $temp_tpl = test_url($url_full, 'img', @html_entity_decode($given_url, ENT_QUOTES, get_charset()), $source_member);
            $align = array_key_exists('align', $attributes) ? $attributes['align'] : '';
            $caption = is_object($attributes['param']) ? $attributes['param'] : comcode_to_tempcode($attributes['param'], $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member);
            if (array_key_exists('title', $attributes)) {
                $tooltip = is_object($attributes['title']) ? $attributes['title'] : comcode_to_tempcode($attributes['title'], $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member);
            } else {
                $tooltip = $caption;
            }
            $rollover = array_key_exists('rollover', $attributes) ? $attributes['rollover'] : NULL;
            if (!is_null($rollover) && url_is_local($rollover)) {
                if (file_exists(get_file_base() . '/' . $rollover) && !file_exists(get_custom_file_base() . '/' . $rollover)) {
                    $rollover = get_base_url() . '/' . $rollover;
                } else {
                    $rollover = get_custom_base_url() . '/' . $rollover;
                }
            }
            $refresh_time = array_key_exists('refresh_time', $attributes) ? strval(intval($attributes['refresh_time'])) : '0';
            $temp_tpl->attach(do_template('COMCODE_IMG', array('_GUID' => '70166d8dbb0aff064b99c0dd30ed77a8', 'RAND' => uniqid('', true), 'REFRESH_TIME' => $refresh_time, 'ROLLOVER' => $rollover, 'ALIGN' => $align, 'URL' => $url_full, 'TOOLTIP' => $tooltip, 'CAPTION' => $caption)));
            if (array_key_exists('float', $attributes)) {
                $temp_tpl = do_template('FLOATER', array('_GUID' => '918162250c80e10212efd9a051545b9b', 'FLOAT' => $attributes['float'], 'CONTENT' => $temp_tpl));
            }
            break;
        case 'flash':
            if ($wml) {
                break;
            }
            $_embed = $embed->evaluate();
            $given_url = $_embed;
            $_embed = remove_url_mistakes($_embed);
            if (substr($_embed, 0, 1) == '/') {
                $_embed = substr($_embed, 1);
            }
            $_embed = check_naughty_javascript_url($source_member, $_embed, $as_admin);
            $url_full = url_is_local($_embed) ? get_custom_base_url() . '/' . $_embed : $_embed;
            $temp_tpl = test_url($url_full, 'flash', @html_entity_decode($given_url, ENT_QUOTES, get_charset()), $source_member);
            if ($attributes['param'] == '' || strpos($attributes['param'], 'x') === false) {
                if (!array_key_exists('width', $attributes)) {
                    $attributes['width'] = '300';
                }
                if (!array_key_exists('height', $attributes)) {
                    $attributes['height'] = '300';
                }
                $attributes['param'] = $attributes['width'] . 'x' . $attributes['height'];
            }
            list($width, $height) = explode('x', $attributes['param'], 2);
            if (addon_installed('jwplayer') && (substr($url_full, -4) == '.flv' || substr($url_full, -4) == '.mp4' || substr($url_full, -4) == '.mp3' || substr($url_full, -4) == '.webm')) {
                $temp_tpl->attach(do_template('COMCODE_FLV', array('_GUID' => '4746684d9e098709cc6671e1b00ce47e', 'URL' => $url_full, 'WIDTH' => $width, 'HEIGHT' => $height)));
            } else {
                $temp_tpl->attach(do_template('COMCODE_SWF', array('_GUID' => '8bc61ad75977a5a85eff96454af31fe8', 'URL' => $url_full, 'WIDTH' => $width, 'HEIGHT' => $height)));
            }
            break;
        case 'url':
            // Make them both HTML strings
            $url = $embed->evaluate();
            if (is_object($attributes['param'])) {
                $switch_over = true;
                // We know if must be Comcode XML
                $attributes['param'] = $attributes['param']->evaluate();
            } else {
                $switch_over = !looks_like_url($url) && looks_like_url($attributes['param'], true);
                if (strpos($attributes['param'], '[') !== false || strpos($attributes['param'], '{') !== false) {
                    $param_temp = comcode_to_tempcode(escape_html($attributes['param']), $source_member, $as_admin, 60, NULL, $connection, false, false, true, false, false, $highlight_bits, $on_behalf_of_member);
                    global $ADVERTISING_BANNERS;
                    $temp_ab = $ADVERTISING_BANNERS;
                    $ADVERTISING_BANNERS = array();
                    $caption = $param_temp;
                    $ADVERTISING_BANNERS = $temp_ab;
                } else {
                    $caption = make_string_tempcode(escape_html($attributes['param']));
                    // Consistency of escaping
                }
            }
            // Do we need to switch around?
            if ($switch_over) {
                $url = $attributes['param'];
                $caption = $embed;
            }
            // If we weren't given a caption, use the URL, but crop if necessary
            if ($caption->evaluate() == '') {
                $_caption = $url;
                // Shorten the URL if it is too long
                $max_link_length = 50;
                if (strlen($_caption) > $max_link_length) {
                    $_caption = escape_html(substr(@html_entity_decode($_caption, ENT_QUOTES, get_charset()), 0, intval($max_link_length / 2 - 3))) . '&hellip;' . escape_html(substr(@html_entity_decode($_caption, ENT_QUOTES, get_charset()), intval(-$max_link_length / 2)));
                }
                $caption = make_string_tempcode($_caption);
            }
            // Tidy up the URL now
            $url = @html_entity_decode($url, ENT_QUOTES, get_charset());
            $url = fixup_protocolless_urls($url);
            // Integrity and security
            $url = check_naughty_javascript_url($source_member, $url, $as_admin);
            // More URL tidying
            $local = url_is_local($url) || strpos($url, get_domain()) !== false;
            $given_url = $url;
            if ($url != '' && $url[0] != '#') {
                if (substr($url, 0, 1) == '/') {
                    $url = substr($url, 1);
                }
                $url_full = url_is_local($url) ? get_base_url() . '/' . $url : $url;
                if ($GLOBALS['XSS_DETECT']) {
                    ocp_mark_as_escaped($url_full);
                }
            } else {
                $url_full = $url;
            }
            $striped_base_url = str_replace('www.', '', str_replace('http://', '', get_base_url()));
            if ($striped_base_url != '' && substr($url, 0, 1) != '%' && strpos($url_full, $striped_base_url) === false) {
                $temp_tpl = test_url($url_full, 'url', $given_url, $source_member);
            }
            // Render
            if (!array_key_exists('target', $attributes)) {
                $attributes['target'] = $local ? '_top' : '_blank';
            }
            if ($attributes['target'] == 'blank') {
                $attributes['target'] = '_blank';
            }
            $rel = $as_admin || has_specific_permission($source_member, 'search_engine_links') ? '' : 'nofollow';
            if ($attributes['target'] == '_blank') {
                $title = (is_object($caption) ? static_evaluate_tempcode($caption) : $caption) . ' ' . do_lang('LINK_NEW_WINDOW');
            } else {
                $title = '';
            }
            $temp_tpl->attach(do_template('COMCODE_URL', array('_GUID' => 'd1657530e6d3d57e6a4791fb3bfa0dd7', 'TITLE' => $title, 'REL' => $rel, 'TARGET' => $attributes['target'], 'URL' => $url_full, 'CAPTION' => $caption)));
            break;
        case 'email':
            $_embed = $embed->evaluate();
            require_code('type_validation');
            require_code('obfuscate');
            // If we need to switch
            if (is_object($attributes['param']) || !is_valid_email_address($_embed) && is_valid_email_address($attributes['param'])) {
                $temp = $embed;
                // Is tempcode
                $_embed = $attributes['param'];
                $attributes['param'] = $temp;
            } else {
                $attributes['param'] = comcode_to_tempcode($attributes['param'], $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member);
                // Becomes tempcode
            }
            if ($attributes['param']->is_empty()) {
                $attributes['param'] = obfuscate_email_address($_embed);
            }
            $subject = array_key_exists('subject', $attributes) ? $attributes['subject'] : '';
            $body = array_key_exists('body', $attributes) ? $attributes['body'] : '';
            $title = '';
            if (array_key_exists('title', $attributes)) {
                $title = $attributes['title'];
            }
            $temp_tpl = do_template('COMCODE_EMAIL', array('_GUID' => '5f6ade8fe07701b6858575153d78f4e9', 'TITLE' => $title, 'ADDRESS' => obfuscate_email_address($_embed), 'SUBJECT' => $subject, 'BODY' => $body, 'CAPTION' => $attributes['param']));
            break;
        case 'reference':
            if ($wml) {
                break;
            }
            if (array_key_exists('type', $attributes) && $attributes['type'] == 'url') {
                $_embed = $embed->evaluate();
                $_embed = check_naughty_javascript_url($source_member, $_embed, $as_admin);
                if (!array_key_exists('title', $attributes)) {
                    $attributes['title'] = $attributes['param'];
                }
                if (is_object($attributes['title']) || $attributes['title'] != '') {
                    $_title = is_object($attributes['title']) ? make_string_tempcode(escape_html($attributes['title'])) : comcode_to_tempcode($attributes['title'], $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member);
                    $title = $_title->evaluate();
                } else {
                    $title = $_embed;
                }
                $embed = hyperlink($_embed, $title, true);
            }
            $temp_tpl = do_template('COMCODE_REFERENCE', array_merge($attributes, array('SOURCE' => $embed)));
            break;
        case 'upload':
            // This points to a file path, not a URL
            $_embed = $embed->evaluate();
            $type = array_key_exists('type', $attributes) ? $attributes['type'] : 'downloads';
            if (is_object($attributes['param']) || $attributes['param'] != '') {
                $_caption = is_object($attributes['param']) ? make_string_tempcode(escape_html($attributes['param'])) : comcode_to_tempcode($attributes['param'], $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member);
                $__caption = $_caption->evaluate();
            } else {
                $__caption = $_embed;
            }
            $url = get_custom_base_url() . '/' . $type . '/' . rawurlencode($_embed);
            $url = check_naughty_javascript_url($source_member, $url, $as_admin);
            $temp_tpl = test_url($url, 'upload', $_embed, $source_member);
            $temp_tpl->attach(hyperlink($url, $__caption));
            break;
        case 'page':
            $ignore_if_hidden = array_key_exists('ignore_if_hidden', $attributes) && $attributes['ignore_if_hidden'] == '1';
            unset($attributes['ignore_if_hidden']);
            // Two sets of parameters: simple style and complex style; both are completely incompatible
            $hash = '';
            if ($attributes == array('param' => '')) {
                $zone = '_SEARCH';
                $caption = $embed;
                $attributes = array('page' => $caption->evaluate());
            } elseif (array_keys($attributes) == array('param')) {
                $caption = $embed;
                if ($wml) {
                    $temp_tpl = $embed;
                    break;
                } else {
                    if (strpos($attributes['param'], ':') !== false) {
                        global $OVERRIDE_SELF_ZONE;
                        $page_link = $attributes['param'];
                        list($zone, $attributes, $hash) = page_link_decode($page_link);
                        if (!array_key_exists('page', $attributes)) {
                            $attributes['page'] = '';
                        }
                        if ($zone == '_SELF' && !is_null($OVERRIDE_SELF_ZONE)) {
                            $zone = $OVERRIDE_SELF_ZONE;
                        }
                    } else {
                        $zone = '_SEARCH';
                        // Changed in v3 from '_SELF', to allow context-sensitivity
                        $attributes = array_merge(array('page' => $attributes['param']), $attributes);
                    }
                }
            } else {
                $caption = array_key_exists('caption', $attributes) ? comcode_to_tempcode($attributes['caption'], $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member) : $embed;
                if ($wml) {
                    $temp_tpl = $caption;
                    break;
                } else {
                    $zone = $param_given ? $attributes['param'] : '_SEARCH';
                    // Changed in v3 from '_SELF', to allow context-sensitivity
                    unset($attributes['caption']);
                    if (!array_key_exists('page', $attributes)) {
                        $attributes = array_merge(array('page' => $embed->evaluate()), $attributes);
                    }
                }
            }
            unset($attributes['param']);
            foreach ($attributes as $key => $val) {
                if (is_object($val)) {
                    $attributes[$key] = $val->evaluate();
                }
            }
            if ($zone == '_SEARCH') {
                $zone = get_page_zone($attributes['page'], false);
                if (is_null($zone)) {
                    $zone = '';
                }
            }
            $pl_url = build_url($attributes, $zone, NULL, false, false, false, $hash);
            $temp_tpl = hyperlink($pl_url, $caption);
            $page = $attributes['page'];
            if ($page != '') {
                if ($zone == '_SELF') {
                    $zone = get_zone_name();
                }
                if ($zone == '_SEARCH') {
                    $zone = get_page_zone($page, false);
                    if (is_null($zone)) {
                        $zone = '';
                    }
                    // Oh dear, well it will be correctly identified as not found anyway
                }
                $ptest = _request_page($page, $zone);
                if ($ptest !== false) {
                    if ($page == 'topicview' && array_key_exists('id', $attributes)) {
                        if (!is_numeric($attributes['id'])) {
                            $attributes['id'] = $GLOBALS['SITE_DB']->query_value_null_ok('url_id_monikers', 'm_resource_id', array('m_resource_page' => $page, 'm_moniker' => $attributes['id']));
                        }
                        if (!is_null($attributes['id'])) {
                            $test = $GLOBALS['FORUM_DB']->query_value_null_ok('f_topics', 'id', array('id' => $attributes['id']));
                            if (is_null($test)) {
                                $ptest = false;
                            }
                        } else {
                            $ptest = false;
                        }
                    }
                }
                if ($ptest === false) {
                    //$temp_tpl->attach(' ['.do_lang('MISSING_RESOURCE').']');  // Don't want this as we might be making the page immediately
                    if (!in_array(get_page_name(), $GLOBALS['DONT_CARE_MISSING_PAGES']) && !in_array($page, $GLOBALS['DONT_CARE_MISSING_PAGES']) && !running_script('iframe')) {
                        if ($ignore_if_hidden) {
                            $temp_tpl = do_template('COMCODE_DEL', array('CONTENT' => $caption));
                        } else {
                            require_code('failure');
                            relay_error_notification(do_lang('MISSING_RESOURCE_COMCODE', 'page_link', $page_link), false, $GLOBALS['FORUM_DRIVER']->is_staff($source_member) ? 'error_occurred_missing_reference_important' : 'error_occurred_missing_reference');
                        }
                    }
                }
            }
            break;
        case 'hide':
            if ($wml) {
                $temp_tpl = $embed;
                break;
            }
            if (array_key_exists('param', $attributes)) {
                $text = is_object($attributes['param']) ? $attributes['param'] : comcode_to_tempcode($attributes['param'], $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member);
            } else {
                $text = do_lang_tempcode('EXPAND');
            }
            $temp_tpl = do_template('COMCODE_HIDE', array('_GUID' => 'a591a0d1e6bb3dde0f22cebb9c7ab93e', 'TEXT' => $text, 'CONTENT' => $embed));
            break;
        case 'quote':
            if ($wml) {
                $temp_tpl->attach('<br /><br />' . $attributes['param'] . ':');
                $temp_tpl->attach($embed);
                break;
            }
            $cite = array_key_exists('cite', $attributes) ? $attributes['cite'] : NULL;
            if (!is_null($cite)) {
                $temp_tpl = test_url($cite, 'quote', $cite, $source_member);
            }
            if ($attributes['param'] == '' && isset($attributes['author'])) {
                $attributes['param'] = $attributes['author'];
            }
            // Compatibility with SMF
            if ($attributes['param'] != '') {
                if (is_numeric($attributes['param'])) {
                    $attributes['param'] = $GLOBALS['FORUM_DRIVER']->get_username($attributes['param']);
                    if (is_null($attributes['param'])) {
                        $attributes['param'] = do_lang('UNKNOWN');
                    }
                } else {
                    $attributes['param'] = protect_from_escaping(comcode_to_tempcode($attributes['param'], $source_member, $as_admin, 60, NULL, $connection, false, false, false, false, false, $highlight_bits, $on_behalf_of_member));
                }
                $temp_tpl->attach(do_template('COMCODE_QUOTE_BY', array('_GUID' => '18f55a548892ad08b0b50b3b586b5b95', 'CITE' => $cite, 'CONTENT' => $embed, 'BY' => $attributes['param'], 'SAIDLESS' => array_key_exists('saidless', $attributes) ? $attributes['saidless'] : '0')));
            } else {
                $temp_tpl->attach(do_template('COMCODE_QUOTE', array('_GUID' => 'fa275de59433c17da19b22814c17fdc5', 'CITE' => $cite, 'CONTENT' => $embed)));
            }
            break;
        case 'html':
            if ($wml) {
                break;
            }
            $temp_tpl = $embed;
            // Plain HTML. But it's been filtered already
            break;
        case 'semihtml':
            $temp_tpl = $embed;
            // Hybrid HTML. But it's been filtered already
            break;
        case 'block':
            if ($wml) {
                break;
            }
            $attributes['block'] = trim($embed->evaluate());
            if (preg_match('#^[\\w\\-]*$#', $attributes['block']) == 0) {
                $temp_tpl = paragraph(do_lang_tempcode('MISSING_BLOCK_FILE', escape_html($attributes['block'])), '90dfdlksds8d7dyddssddxs', 'error_marker');
                break;
                // Avoids a suspected hack attempt by just filtering early
            }
            $_attributes = array();
            foreach ($attributes as $key => $val) {
                $_attributes[] = $key . '=' . $val;
            }
            $temp_tpl = symbol_tempcode('BLOCK', $_attributes);
            break;
        case 'contents':
            if ($wml) {
                break;
            }
            // Do structure sweep
            $urls_for = array();
            $old_structure_list = $STRUCTURE_LIST;
            $STRUCTURE_LIST = array();
            // reset for e.g. comcode_text_to_tempcode calls (which don't itself reset it, although _comcode_to_tempcode does for top level parses)
            if (array_key_exists('files', $attributes) && $comcode_dangerous) {
                $s_zone = array_key_exists('zone', $attributes) ? $attributes['zone'] : get_zone_name();
                $pages = find_all_pages($s_zone, 'comcode_custom/' . get_site_default_lang(), 'txt') + find_all_pages($s_zone, 'comcode/' . get_site_default_lang(), 'txt');
                $prefix = $attributes['files'];
                foreach ($pages as $pg_name => $pg_type) {
                    if (substr($pg_name, 0, strlen($prefix)) == $prefix) {
                        $i = count($STRUCTURE_LIST);
                        comcode_to_tempcode(file_get_contents(zone_black_magic_filterer(get_file_base() . '/' . $s_zone . '/pages/' . $pg_type . '/' . $pg_name . '.txt'), FILE_TEXT), $source_member, $as_admin, 60, NULL, $connection, false, false, false, true, false, NULL, $on_behalf_of_member);
                        $page_url = build_url(array('page' => $pg_name), $s_zone);
                        while (array_key_exists($i, $STRUCTURE_LIST)) {
                            $urls_for[] = $page_url;
                            $i++;
                        }
                    }
                }
                $base = array_key_exists('base', $attributes) ? intval($attributes['base']) : 1;
            } else {
                if (substr($comcode, 0, 8) == '<comcode') {
                    require_code('comcode_xml');
                    if (!$as_admin) {
                        check_specific_permission('comcode_dangerous', NULL, $source_member);
                    }
                    $_ = new comcode_xml_to_tempcode($comcode, $source_member, 60, NULL, $connection, false, false, false, true, false, $on_behalf_of_member);
                } else {
                    require_code('comcode_text');
                    comcode_text_to_tempcode($comcode, $source_member, $as_admin, 60, NULL, $connection, false, false, false, true, false, NULL, $on_behalf_of_member);
                }
                $base = array_key_exists('base', $attributes) ? intval($attributes['base']) : 1;
            }
            $list_types = $embed->evaluate() == '' ? array() : explode(',', $embed->evaluate());
            $list_types += array('decimal', 'lower-alpha', 'lower-roman', 'upper-alpha', 'upper-roman', 'disc');
            $levels_allowed = array_key_exists('levels', $attributes) ? intval($attributes['levels']) : NULL;
            // Convert the list structure into a tree structure
            $past_level_stack = array(1);
            $subtree_stack = array(array());
            $levels = 1;
            foreach ($STRUCTURE_LIST as $i => $struct) {
                $level = $struct[0];
                $title = $struct[1];
                $uniq_id = $struct[2];
                $url = array_key_exists($i, $urls_for) ? $urls_for[$i] : '';
                if ($level > $levels_allowed && !is_null($levels_allowed)) {
                    continue;
                }
                // Going down the tree
                if ($level > $past_level_stack[$levels - 1]) {
                    array_push($past_level_stack, $level);
                    array_push($subtree_stack, array(array($uniq_id, $title->evaluate(), $url)));
                    $levels++;
                } else {
                    // Going back up the tree, destroying levels that must have now closed off
                    while ($level < $past_level_stack[$levels - 1] && $levels > 2) {
                        array_pop($past_level_stack);
                        $subtree = array_pop($subtree_stack);
                        $levels--;
                        // Alter the last of the next level on stack so it is actually taking the closed off level as children, and changing from a property list to a pair: property list & children
                        $subtree_stack[$levels - 1][count($subtree_stack[$levels - 1]) - 1] = array($subtree_stack[$levels - 1][count($subtree_stack[$levels - 1]) - 1], $subtree);
                    }
                    // Store the title where we are
                    $subtree_stack[$levels - 1][] = array($uniq_id, $title->evaluate(), $url);
                }
            }
            // Clean up... going up until we're with 1
            while ($levels > 1) {
                array_pop($past_level_stack);
                $subtree = array_pop($subtree_stack);
                $levels--;
                $parent_level_start_index = count($subtree_stack[$levels - 1]) - 1;
                if ($parent_level_start_index < 0) {
                    $subtree_stack[$levels - 1] = $subtree;
                } else {
                    $subtree_stack[$levels - 1][$parent_level_start_index] = array($subtree_stack[$levels - 1][$parent_level_start_index], $subtree);
                }
            }
            // Now we have the structure to display
            $levels_t = _do_contents_level($subtree_stack[0], $list_types, $base);
            $temp_tpl = do_template('COMCODE_CONTENTS', array('_GUID' => 'ca2f5320fa930e2257a2e74e4f98e5a0', 'LEVELS' => $levels_t));
            $STRUCTURE_LIST = $old_structure_list;
            // Restore, so subsequent 'title' tags have correct numbering
            break;
    }
    // Last ditch effort: custom tags
    if ($temp_tpl->is_definitely_empty() && !$wml) {
        global $REPLACE_TARGETS;
        if (array_key_exists($tag, $REPLACE_TARGETS)) {
            $replace = $REPLACE_TARGETS[$tag]['replace'];
            $parameters = explode(',', $REPLACE_TARGETS[$tag]['parameters']);
            $binding = array('CONTENT' => $embed, 'RAND' => uniqid('', true));
            foreach ($parameters as $parameter) {
                $parameter = trim($parameter);
                $parts = explode('=', $parameter);
                if (count($parts) == 1) {
                    $parts[] = '';
                }
                if (count($parts) != 2) {
                    continue;
                }
                list($parameter, $default) = $parts;
                if (!array_key_exists($parameter, $attributes) || $attributes[$parameter] == '') {
                    $attributes[$parameter] = $default;
                }
                $binding[strtoupper($parameter)] = $attributes[$parameter];
                $replace = str_replace('{' . $parameter . '}', '{' . strtoupper($parameter) . '*}', $replace);
            }
            $replace = str_replace('{content}', array_key_exists($tag, $GLOBALS['TEXTUAL_TAGS']) ? '{CONTENT}' : '{CONTENT*}', $replace);
            require_code('tempcode_compiler');
            $temp_tpl = template_to_tempcode($replace);
            $temp_tpl = $temp_tpl->bind($binding, '(custom comcode: ' . $tag . ')');
        }
    }
    return $temp_tpl;
}
 /**
  * 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('catalogues');
     $catalogue_name = array_key_exists('catalogue_name', $options) ? $options['catalogue_name'] : NULL;
     $addable_filter = array_key_exists('addable_filter', $options) ? $options['addable_filter'] : false;
     $compound_list = array_key_exists('compound_list', $options) ? $options['compound_list'] : false;
     if (is_null($catalogue_name)) {
         $out = '';
         $catalogues = $GLOBALS['SITE_DB']->query_select('catalogues', array('c_name'));
         foreach ($catalogues as $catalogue) {
             $out .= static_evaluate_tempcode(nice_get_catalogue_category_tree($catalogue['c_name'], is_null($it) ? NULL : intval($it), $addable_filter, $compound_list));
         }
         return make_string_tempcode($out);
     } else {
         return nice_get_catalogue_category_tree($catalogue_name, is_null($it) ? NULL : intval($it), $addable_filter, $compound_list);
     }
 }
Exemplo n.º 17
0
 /**
  * Gets the default value for the config option.
  *
  * @return ?string		The default value (NULL: option is disabled)
  */
 function get_default()
 {
     return has_no_forum() ? NULL : static_evaluate_tempcode(do_template('COMMENTS_DEFAULT_TEXT'));
 }
Exemplo n.º 18
0
 function _send($token, $row, $post_to_uid = 'me', $member_id = NULL)
 {
     require_lang('facebook');
     require_code('facebook_connect');
     // Prepare message
     list($message) = render_activity($row, false);
     $name = $row['a_label_1'];
     require_code('character_sets');
     $name = convert_to_internal_encoding($name, get_charset(), 'utf-8');
     $link = $row['a_pagelink_1'] == '' ? '' : static_evaluate_tempcode(pagelink_to_tempcode($row['a_pagelink_1']));
     $message = html_entity_decode(strip_tags($message->evaluate()), ENT_COMPAT, get_charset());
     $message = convert_to_internal_encoding($message, get_charset(), 'utf-8');
     // Send message
     $appid = get_option('facebook_appid');
     $appsecret = get_option('facebook_secret_code');
     $fb = new ocpFacebook(array('appId' => $appid, 'secret' => $appsecret));
     $fb->setAccessToken($token);
     $attachment = array('description' => $message);
     if ($name != '' && $name != $message) {
         $attachment['name'] = $name;
     }
     if ($link != '') {
         $attachment['link'] = $link;
     }
     if (count($attachment) == 1) {
         $attachment = array('message' => $message);
     }
     if ($post_to_uid == 'me') {
         $post_to_uid = $fb->getUser();
     }
     // May not be needed, but just in case
     try {
         $ret = $fb->api('/' . $post_to_uid . '/feed', 'POST', $attachment);
     } catch (Exception $e) {
         if (!is_null($member_id) && count($_POST) == 0) {
             $this->auth_set($member_id, get_self_url());
         }
         warn_exit($e->getMessage());
     }
     return true;
 }
Exemplo n.º 19
0
require_code('themes2');
$themes = find_all_themes();
foreach (array_keys($themes) as $theme) {
    if ($theme != 'default') {
        $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(true, true);
        foreach (array_keys($groups) as $gid) {
            $GLOBALS['SITE_DB']->query_insert('group_category_access', array('group_id' => $gid, 'module_the_name' => 'theme', 'category_name' => $theme), false, true);
        }
        echo '<li>';
        echo '<a href="' . static_evaluate_tempcode(build_url(array('page' => 'start', 'keep_theme_test' => '1', 'keep_theme' => $theme), '')) . '">' . escape_html($theme) . '</a><br />
					<span class="associated_details">(Other useful views:
						<a href="' . static_evaluate_tempcode(build_url(array('page' => 'start', 'keep_theme_test' => '1', 'keep_theme' => $theme, 'keep_theme_seed' => '664422', 'keep_theme_algorithm' => 'hsv', 'keep_theme_source' => $theme), '')) . '">with brown seed</a> /
						<a href="' . static_evaluate_tempcode(build_url(array('page' => 'start', 'keep_theme_test' => '1', 'keep_theme' => $theme, 'keep_su' => 'Guest'), '')) . '">as Guest</a> /
						<a href="' . static_evaluate_tempcode(build_url(array('page' => 'cms_news', 'type' => 'ad', 'keep_theme_test' => '1', 'keep_theme' => $theme), 'cms')) . '">Add News Form</a> /
						<a href="' . static_evaluate_tempcode(build_url(array('page' => 'news', 'keep_theme_test' => '1', 'type' => 'view', 'id' => 1, 'keep_theme' => $theme), 'site')) . '">News screen</a> /
						<a href="' . static_evaluate_tempcode(build_url(array('page' => '', 'keep_theme_test' => '1', 'keep_theme' => $theme), 'forum')) . '">forumview</a>)
					</span>';
        // Find unreferenced images
        $dh = opendir(get_custom_file_base() . '/themes/' . $theme . '/images_custom');
        $images = array();
        while (($f = readdir($dh)) !== false) {
            if (is_image($f)) {
                $img_code = basename($f, '.' . get_file_extension($f));
                if (isset($images[$img_code])) {
                    echo '<br />Duplicated theme image: ' . escape_html($img_code);
                }
                $images[$img_code] = 1;
            }
        }
        $images_copy = $images + $default_images;
        closedir($dh);
Exemplo n.º 20
0
/**
 * Relay an error message, if appropriate, to e-mail listeners (sometimes ocProducts, and site staff).
 *
 * @param  string			A error message (in HTML)
 * @param  boolean		Also send to ocProducts
 * @param  ID_TEXT		The notification type
 */
function relay_error_notification($text, $ocproducts = true, $notification_type = 'error_occurred')
{
    // Make sure we don't send too many error emails
    if (function_exists('get_value') && $GLOBALS['BOOTSTRAPPING'] == 0 && array_key_exists('SITE_DB', $GLOBALS) && !is_null($GLOBALS['SITE_DB'])) {
        $num = intval(get_value('num_error_mails_' . date('Y-m-d'))) + 1;
        if ($num == 51) {
            return;
        }
        // We've sent too many error mails today
        $GLOBALS['SITE_DB']->query('DELETE FROM ' . get_table_prefix() . 'values WHERE the_name LIKE \'' . db_encode_like('num\\_error\\_mails\\_%') . '\'');
        persistant_cache_delete('VALUES');
        set_value('num_error_mails_' . date('Y-m-d'), strval($num));
    }
    if (!function_exists('require_lang')) {
        return;
    }
    require_code('urls');
    require_code('tempcode');
    $error_url = running_script('index') ? static_evaluate_tempcode(build_url(array('page' => '_SELF'), '_SELF', NULL, true, false, true)) : get_self_url_easy();
    require_code('notifications');
    require_code('comcode');
    $mail = do_lang('ERROR_MAIL', comcode_escape($error_url), str_replace(array('[html', '[/html'), array('&#91;html', '&#91;/html'), $text), NULL, get_site_default_lang());
    dispatch_notification($notification_type, NULL, do_lang('ERROR_OCCURRED_SUBJECT', get_page_name(), NULL, NULL, get_site_default_lang()), $mail, NULL, A_FROM_SYSTEM_PRIVILEGED);
    if ($ocproducts && get_option('send_error_emails_ocproducts', true) == '1' && !running_script('cron_bridge') && strpos($text, '_custom/') === false && strpos($text, 'data/occle.php') === false && strpos($text, '/mini') === false && strpos($text, 'A transaction for the wrong IPN e-mail went through') === false && strpos($text, 'has been disabled for security reasons') === false && strpos($text, 'max_questions') === false && strpos($text, 'Error at offset') === false && strpos($text, 'Unable to allocate memory for pool') === false && strpos($text, 'Out of memory') === false && strpos($text, 'Disk is full writing') === false && strpos($text, 'Disk quota exceeded') === false && strpos($text, 'from storage engine') === false && strpos($text, 'Lost connection to MySQL server') === false && strpos($text, 'Unable to save result set') === false && strpos($text, '.MYI') === false && strpos($text, 'MySQL server has gone away') === false && strpos($text, 'Incorrect key file') === false && strpos($text, 'Too many connections') === false && strpos($text, 'marked as crashed and should be repaired') === false && strpos($text, 'connect to') === false && strpos($text, 'Access denied for') === false && strpos($text, 'Unknown database') === false && strpos($text, 'headers already sent') === false && preg_match('#Maximum execution time of \\d+ seconds#', $text) == 0 && preg_match('#Out of memory \\(allocated (1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24)\\d{6}\\)#', $text) == 0 && strpos($text, 'is marked as crashed and last') === false && strpos($text, 'failed to open stream: Permission denied') === false && strpos($text, 'phpinfo() has been disabled') === false && (strpos($text, 'Maximum execution time') === false || strpos($text, '/js_') === false && strpos($text, '/caches_filesystem.php') === false && strpos($text, '/files2.php') === false) && (strpos($text, 'doesn\'t exist') === false || strpos($text, 'import') === false) && (strpos($text, 'No such file or directory') === false || strpos($text, 'admin_setupwizard') === false) && strpos($text, 'File(/tmp/) is not within the allowed path') === false) {
        require_code('mail');
        mail_wrap(do_lang('ERROR_OCCURRED_SUBJECT', get_page_name(), NULL, NULL, get_site_default_lang()) . ' ' . ocp_version_full(), $mail, array('errors_final' . strval(ocp_version()) . '@ocportal.com'), '', '', '', 3, NULL, true, NULL, true);
    }
    if ($ocproducts && !is_null(get_value('agency_email_address'))) {
        require_code('mail');
        $agency_email_address = get_value('agency_email_address');
        mail_wrap(do_lang('ERROR_OCCURRED_SUBJECT', get_page_name(), NULL, NULL, get_site_default_lang()) . ' ' . ocp_version_full(), $mail, array($agency_email_address), '', '', '', 3, NULL, true, NULL, true);
    }
}
Exemplo n.º 21
0
 /**
  * Send out a notification to members enabled.
  */
 function dispatch()
 {
     if (running_script('stress_test_loader')) {
         return;
     }
     if (get_page_name() == 'admin_import') {
         return;
     }
     $subject = $this->subject;
     $message = $this->message;
     $no_cc = $this->no_cc;
     if ($GLOBALS['DEBUG_MODE']) {
         if (strpos($this->message, 'keep_devtest') !== false && $this->notification_code != 'hack_attack' && $this->notification_code != 'auto_ban' && strpos($this->message, running_script('index') ? static_evaluate_tempcode(build_url(array('page' => '_SELF'), '_SELF', NULL, true, false, true)) : get_self_url_easy()) === false && (strpos(ocp_srv('HTTP_REFERER'), 'keep_devtest') === false || strpos($this->message, ocp_srv('HTTP_REFERER')) === false)) {
             // Bad URL - it has to be general, not session-specific
             fatal_exit(do_lang_tempcode('INTERNAL_ERROR'));
         }
     }
     $ob = _get_notification_ob_for_code($this->notification_code);
     if (is_null($ob)) {
         if (get_page_name() != 'admin_setupwizard') {
             // Setupwizard may have removed after register_shutdown_function was called
             fatal_exit('Missing notification code: ' . $this->notification_code);
         }
         return;
     }
     require_lang('notifications');
     require_code('mail');
     if (function_exists('set_time_limit')) {
         @set_time_limit(0);
     }
     if ($this->store_in_staff_messaging_system && addon_installed('staff_messaging')) {
         require_lang('messaging');
         list($type, $id) = explode('_', $this->code_category, 2);
         $message_url = build_url(array('page' => 'admin_messaging', 'type' => 'view', 'id' => $id, 'message_type' => $type), get_module_zone('admin_messaging'), NULL, false, false, true);
         $message = do_lang('MESSAGING_NOTIFICATION_WRAPPER', $message, $message_url->evaluate());
         require_code('feedback');
         actualise_post_comment(true, $type, $id, $message_url, $subject, get_option('messaging_forum_name'), true, 1, true, true, true);
     }
     $testing = get_param_integer('keep_debug_notifications', 0) == 1;
     $start = 0;
     $max = 300;
     do {
         list($members, $possibly_has_more) = $ob->list_members_who_have_enabled($this->notification_code, $this->code_category, $this->to_member_ids, $start, $max);
         if (get_value('notification_safety_testing') === '1') {
             if (count($members) > 20) {
                 $members = array(6 => A_INSTANT_EMAIL);
                 // This is just for testing on ocportal.com, if lots of notifications going out it's probably a scary bug, so send just to Chris (#6) with a note
                 $message = 'OVER-ADDRESSED?' . "\n\n" . $message;
             }
         }
         foreach ($members as $to_member_id => $setting) {
             if (!is_null($this->no_notify_for__notification_code)) {
                 if (notifications_enabled($this->no_notify_for__notification_code, $this->no_notify_for__code_category, $to_member_id)) {
                     continue;
                 }
                 // Signal they are getting some other notification for this
             }
             if ($to_member_id !== $this->from_member_id || $testing) {
                 $no_cc = _dispatch_notification_to_member($to_member_id, $setting, $this->notification_code, $this->code_category, $subject, $message, $this->from_member_id, $this->priority, $no_cc);
             }
         }
         $start += $max;
     } while ($possibly_has_more);
 }
Exemplo n.º 22
0
 /**
  * The calendar area view for viewing a single day.
  *
  * @param  string			The day we are viewing
  * @param  string			The day (Y-m-d) we are viewing
  * @param  array			List of components of our viewed ID
  * @param  MEMBER			The member ID we are viewing as
  * @param  ?array			The type filter (NULL: none)
  * @return tempcode		The UI
  */
 function view_calendar_view_day($view_id, $day, $explode, $member_id, $filter)
 {
     $start_year = intval($explode[0]);
     $start_month = intval($explode[1]);
     $start_day = intval($explode[2]);
     $period_start = mktime(0, 0, 0, $start_month, $start_day, $start_year);
     $period_end = mktime(0, 0, 0, $start_month, $start_day + 1, $start_year);
     $happenings = calendar_matches($member_id, true, $period_start, $period_end, $filter);
     global $M_SORT_KEY;
     $M_SORT_KEY = 0;
     usort($happenings, 'multi_sort');
     $hours = new ocp_tempcode();
     $streams = array(array());
     foreach ($happenings as $happening) {
         list($e_id, $event, $from, $to, $real_from, $real_to, $utc_real_from) = $happening;
         $date = is_null($event['e_start_hour']) ? '' : locale_filter(my_strftime(do_lang('calendar_minute'), $from));
         if (is_numeric($e_id)) {
             $map = array_merge($filter, array('page' => '_SELF', 'type' => 'view', 'id' => $event['e_id'], 'day' => date('Y-m-d', $utc_real_from), 'date' => $view_id));
             if (get_param_integer('member_id', get_member()) != get_member()) {
                 $map['member_id'] = get_param_integer('member_id');
             }
             $url = build_url($map, '_SELF');
         } else {
             $url = $e_id;
         }
         $icon = $event['t_logo'];
         $from_h = intval(date('H', $from));
         if (!is_null($to)) {
             $date = date_range($real_from, $real_to, !is_null($event['e_start_hour']));
             //$date2=date('H:i',$to);
             if ($to >= $period_end - 60) {
                 $to_h = 24;
             } else {
                 $to_h = intval(date('H', $to));
                 if (date('i', $to) != '0') {
                     $to_h++;
                 }
             }
         } else {
             $to_h = $from_h;
         }
         // Try and find us a stream that can fit us
         $found_stream = NULL;
         foreach ($streams as $i => $stream) {
             for ($h = $from_h; $h <= $to_h; $h++) {
                 if (array_key_exists($h, $stream)) {
                     break;
                 }
             }
             if ($h == $to_h + 1 && !array_key_exists($h - 1, $stream)) {
                 $found_stream = $i;
                 break;
             }
         }
         if (is_null($found_stream)) {
             $streams[] = array();
             $found_stream = count($streams) - 1;
         }
         // Fill in stream gaps as appropriate
         $title = is_integer($event['e_title']) ? get_translated_text($event['e_title']) : $event['e_title'];
         $down = strval($to_h - $from_h);
         $description = intval($down) < 3 ? new ocp_tempcode() : (is_numeric($event['e_content']) ? get_translated_tempcode($event['e_content']) : $event['e_content']);
         $priority_lang = do_lang_tempcode('PRIORITY_' . strval($event['e_priority']));
         $priority_icon = 'calendar/priority_' . strval($event['e_priority']);
         $streams[$found_stream][$from_h] = array('TPL' => 'CALENDAR_DAY_ENTRY', 'DESCRIPTION' => $description, 'DOWN' => $down, 'ID' => is_string($event['e_id']) ? $event['e_id'] : strval($event['e_id']), 'T_TITLE' => array_key_exists('t_title', $event) ? is_string($event['t_title']) ? $event['t_title'] : get_translated_text($event['t_title']) : 'RSS', 'PRIORITY' => strval($event['e_priority']), 'ICON' => $icon, 'TIME' => $date, 'TITLE' => $title, 'URL' => $url, 'PRIORITY_LANG' => $priority_lang, 'PRIORITY_ICON' => $priority_icon, 'RECURRING' => $event['e_recurrence'] != 'none');
         for ($h = $from_h + 1; $h < $to_h; $h++) {
             $streams[$found_stream][$h] = array('TPL' => '-1');
         }
     }
     for ($i = 0; $i < 24; $i++) {
         // Work out the hour
         $hour = locale_filter(date(do_lang('time_hour_and_mins'), $i * 60 * 60));
         // The streams need rendering for each hour
         $_streams = new ocp_tempcode();
         foreach ($streams as $stream) {
             $down = '1';
             $priority = 'free_time';
             $entry = mixed();
             if (!array_key_exists($i, $stream)) {
                 $class = 'free_time_hourly';
                 $text = '&nbsp;';
                 $entry = static_evaluate_tempcode(do_template('CALENDAR_DAY_ENTRY_FREE', array('_GUID' => '0091fbb877164ac797cb88b4571b5d35', 'CLASS' => $class, 'TEXT' => $text)));
                 /*HTMLHTML*/
             } else {
                 if ($stream[$i]['TPL'] != '-1') {
                     $down = $stream[$i]['DOWN'];
                     $priority = $stream[$i]['PRIORITY'];
                     $entry = static_evaluate_tempcode(do_template($stream[$i]['TPL'], $stream[$i]));
                     /*HTMLHTML*/
                 } else {
                     $entry = '';
                 }
             }
             if ($down == '0') {
                 $down = '1';
             }
             if ($entry != '') {
                 $timestamp = $period_start + $i * 60 * 60;
                 if (has_actual_page_access(NULL, 'cms_calendar', NULL, NULL) && has_submit_permission('low', get_member(), get_ip_address(), 'cms_calendar')) {
                     $and_filter = $this->get_and_filter();
                     $add_url = build_url(array('page' => 'cms_calendar', 'type' => 'ad', 'date' => date('Y-m-d H:i:s', $timestamp), 'e_type' => count($and_filter) == 1 ? $and_filter[0] : NULL), get_module_zone('cms_calendar'));
                 } else {
                     $add_url = new ocp_tempcode();
                 }
                 $_streams->attach(static_evaluate_tempcode(do_template('CALENDAR_DAY_STREAM_HOUR', array('_GUID' => '93a8fb53183a4225ec3bf7f2ea07cfc5', 'CURRENT' => date('Y-m-d H', utctime_to_usertime()) == date('Y-m-d H', $timestamp), 'ADD_URL' => $add_url, 'PRIORITY' => $priority, 'DOWN' => $down, 'ENTRY' => $entry))));
             }
         }
         $hours->attach(do_template('CALENDAR_DAY_HOUR', array('_GUID' => 'd967ce3f793942f78104c53b105f9f74', 'HOUR' => $hour, 'STREAMS' => $_streams)));
     }
     return do_template('CALENDAR_DAY', array('_GUID' => '60e102b38025c1b1618ac36070564065', 'HOURS' => $hours, 'PERIOD_START' => strval($period_start), 'PERIOD_END' => strval($period_end)));
 }
Exemplo n.º 23
0
 /**
  * The UI to edit a configuration page.
  *
  * @return tempcode		The UI
  */
 function config_category()
 {
     require_javascript('javascript_validation');
     /*$GLOBALS['HELPER_PANEL_PIC']='pagepics/config';
     		$GLOBALS['HELPER_PANEL_TUTORIAL']='tut_adv_configuration';*/
     $page = get_param('id');
     $title = get_page_title(do_lang_tempcode('CONFIG_CATEGORY_' . $page), false);
     $post_url = build_url(array('page' => '_SELF', 'type' => 'set', 'id' => $page, 'redirect' => get_param('redirect', NULL)), '_SELF');
     $category_description = do_lang_tempcode('CONFIG_CATEGORY_DESCRIPTION__' . $page);
     $rows = $GLOBALS['SITE_DB']->query_select('config', array('*'), array('the_page' => $page));
     // Addin special ones
     if ($page == 'SITE') {
         $rows[] = array('the_name' => 'timezone', 'human_name' => 'TIME_ZONE', 'config_value' => '', 'the_type' => 'special', 'eval' => '', 'the_page' => 'SITE', 'section' => 'GENERAL', 'explanation' => '', 'shared_hosting_restricted' => 0);
     }
     /*global $M_SORT_KEY;	This is a lame sort - it doesn't preserve internal order
     		$M_SORT_KEY='section';
     		usort($rows,'multi_sort');*/
     // Better sort
     $all_known_groups = array();
     foreach ($rows as $myrow) {
         $_group = do_lang($myrow['section'], NULL, NULL, NULL, NULL, false);
         if (is_null($_group)) {
             $_group = $myrow['section'];
         }
         $_group = strtolower(trim(preg_replace('#(&.*;)|[^\\w\\d\\s]#U', '', $_group)));
         if (array_key_exists($_group, $all_known_groups) && $all_known_groups[$_group] != $myrow['section']) {
             $_group = 'std_' . $myrow['section'];
         }
         // If cat names translate to same things or are in non-latin characters like Cyrillic
         $all_known_groups[$_group] = $myrow['section'];
     }
     $old_rows = $rows;
     $rows = array();
     ksort($all_known_groups);
     foreach ($all_known_groups as $group_codename) {
         foreach ($old_rows as $myrow) {
             if ($myrow['section'] == $group_codename) {
                 $rows[] = $myrow;
             }
         }
     }
     // Move advanced group options to the end
     $rows2 = array();
     foreach ($rows as $i => $row) {
         if ($row['section'] == 'ADVANCED') {
             $rows2[] = $row;
             unset($rows[$i]);
         }
     }
     $rows = array_merge($rows, $rows2);
     // UI hooks
     $ui_hooks = find_all_hooks('modules', 'admin_config');
     $upload_max_filesize = ini_get('upload_max_filesize') == '0' ? do_lang('NA') : clean_file_size(php_return_bytes(ini_get('upload_max_filesize')));
     $post_max_size = ini_get('post_max_size') == '0' ? do_lang('NA') : clean_file_size(php_return_bytes(ini_get('post_max_size')));
     $groups = new ocp_tempcode();
     require_code('form_templates');
     $current_group = '';
     $out = '';
     $_groups = array();
     foreach ($rows as $myrow) {
         if ($myrow['eval'] != '' && $myrow['the_name'] != 'detect_lang_forum') {
             if (defined('HIPHOP_PHP')) {
                 require_code('hooks/systems/config_default/' . $myrow['the_name']);
                 $hook = object_factory('Hook_config_default_' . $myrow['the_name']);
                 if (is_null($hook->get_default())) {
                     continue;
                 }
             } else {
                 $GLOBALS['REQUIRE_LANG_LOOP'] = 10;
                 // LEGACY Workaround for corrupt webhost installers
                 if (is_null(@eval($myrow['eval'] . ';'))) {
                     continue;
                 }
                 // @'d in case default is corrupt, don't want it to give errors forever
                 $GLOBALS['REQUIRE_LANG_LOOP'] = 0;
                 // LEGACY
             }
         }
         $_group = do_lang($myrow['section'], NULL, NULL, NULL, NULL, false);
         $name = do_lang($myrow['human_name'], NULL, NULL, NULL, NULL, false);
         $_group_tempcode = is_null($_group) ? make_string_tempcode($myrow['section']) : do_lang_tempcode($myrow['section']);
         $name_tempcode = is_null($name) ? make_string_tempcode($myrow['human_name']) : do_lang_tempcode($myrow['human_name']);
         if (get_forum_type() == 'ocf' && $myrow['explanation'] == 'CONFIG_OPTION_forum_in_portal') {
             $exp_string = $myrow['explanation'] . '__ocf';
         } else {
             $exp_string = $myrow['explanation'];
         }
         $_explanation = do_lang($exp_string, NULL, NULL, NULL, NULL, false);
         if (is_null($_explanation)) {
             $_explanation = do_lang('CONFIG_GROUP_DEFAULT_DESCRIP_' . $myrow['section'], NULL, NULL, NULL, NULL, false);
             if (is_null($_explanation)) {
                 $explanation = new ocp_tempcode();
             } else {
                 $explanation = do_lang_tempcode('CONFIG_GROUP_DEFAULT_DESCRIP_' . $myrow['section']);
             }
         } else {
             $explanation = do_lang_tempcode($exp_string);
         }
         if ($myrow['shared_hosting_restricted'] == 1 && !is_null($GLOBALS['CURRENT_SHARE_USER'])) {
             continue;
         }
         if ($myrow['section'] != $current_group && $current_group != '') {
             $_current_group = do_lang_tempcode($current_group);
             $_group_description = do_lang('CONFIG_GROUP_DESCRIP_' . $current_group, escape_html($post_max_size), escape_html($upload_max_filesize), NULL, NULL, false);
             if (is_null($_group_description)) {
                 $group_description = new ocp_tempcode();
             } else {
                 $group_description = do_lang_tempcode('CONFIG_GROUP_DESCRIP_' . $current_group, escape_html($post_max_size), escape_html($upload_max_filesize));
             }
             $group = do_template('CONFIG_GROUP', array('_GUID' => 'af4c31daa1bc39714ab83b11bd6d3e51', 'GROUP_DESCRIPTION' => $group_description, 'GROUP_NAME' => $current_group, 'GROUP' => $out, 'CURRENT_GROUP' => $_current_group));
             $groups->attach($group->evaluate());
             $out = '';
         }
         $_groups[$myrow['section']] = $_group_tempcode;
         switch ($myrow['the_type']) {
             case 'special':
                 switch ($myrow['the_name']) {
                     case 'timezone':
                         $list = '';
                         $timezone = get_site_timezone();
                         foreach (get_timezone_list() as $_timezone => $timezone_nice) {
                             $list .= static_evaluate_tempcode(form_input_list_entry($_timezone, $_timezone == $timezone, $timezone_nice));
                         }
                         $out .= static_evaluate_tempcode(form_input_list(do_lang_tempcode('TIME_ZONE'), do_lang_tempcode('DESCRIPTION_TIMEZONE_SITE'), 'timezone', make_string_tempcode($list)));
                         break;
                     default:
                         require_code('hooks/modules/admin_config/' . filter_naughty_harsh($myrow['the_name']));
                         $hook_ob = object_factory('Hook_admin_config_' . filter_naughty_harsh($myrow['the_name']));
                         $out .= static_evaluate_tempcode($hook_ob->run($myrow));
                         break;
                 }
                 break;
             case 'integer':
                 $out .= static_evaluate_tempcode(form_input_integer($name_tempcode, $explanation, $myrow['the_name'], intval(get_option($myrow['the_name'])), false));
                 break;
             case 'line':
                 if (strpos($myrow['the_name'], 'colour') !== false && substr(get_option($myrow['the_name']), 0, 1) == '#') {
                     $out .= static_evaluate_tempcode(form_input_colour($name_tempcode, $explanation, $myrow['the_name'], get_option($myrow['the_name']), false, NULL, true));
                 } elseif ($myrow['the_name'] == 'currency') {
                     $list = '';
                     require_code('currency');
                     $currencies = array_keys(get_currency_map());
                     foreach ($currencies as $currency) {
                         $list .= static_evaluate_tempcode(form_input_list_entry($currency, $currency == get_option($myrow['the_name'])));
                     }
                     $out .= static_evaluate_tempcode(form_input_list($name_tempcode, $explanation, $myrow['the_name'], make_string_tempcode($list)));
                 } elseif ($myrow['the_name'] == 'payment_gateway') {
                     $list = '';
                     $all_via = find_all_hooks('systems', 'ecommerce_via');
                     foreach (array_keys($all_via) as $via) {
                         $list .= static_evaluate_tempcode(form_input_list_entry($via, $via == get_option($myrow['the_name'])));
                     }
                     $out .= static_evaluate_tempcode(form_input_list($name_tempcode, $explanation, $myrow['the_name'], make_string_tempcode($list)));
                 } else {
                     /*if (strpos($myrow['the_name'],'password')!==false)  password fields can't take defaults
                     			$out.=static_evaluate_tempcode(form_input_password($name_tempcode,$explanation,$myrow['the_name'],get_option($myrow['the_name']),false));
                     		else
                     			*/
                     $out .= static_evaluate_tempcode(form_input_line($name_tempcode, $explanation, $myrow['the_name'], get_option($myrow['the_name']), false));
                 }
                 break;
             case 'list':
                 $list = '';
                 $_value = get_option($myrow['the_name']);
                 $values = explode('|', $myrow['c_data']);
                 foreach ($values as $value) {
                     $_option_text = do_lang('CONFIG_OPTION_' . $myrow['the_name'] . '_VALUE_' . $value, NULL, NULL, NULL, NULL, false);
                     if (!is_null($_option_text)) {
                         $option_text = do_lang_tempcode('CONFIG_OPTION_' . $myrow['the_name'] . '_VALUE_' . $value);
                     } else {
                         $option_text = make_string_tempcode($value);
                     }
                     $list .= static_evaluate_tempcode(form_input_list_entry($value, $_value == $value, $option_text));
                 }
                 $out .= static_evaluate_tempcode(form_input_list($name_tempcode, $explanation, $myrow['the_name'], make_string_tempcode($list), NULL, false, false));
                 break;
             case 'transline':
                 $out .= static_evaluate_tempcode(form_input_line($name_tempcode, $explanation, $myrow['the_name'], get_option($myrow['the_name']), false));
                 break;
             case 'text':
                 $out .= static_evaluate_tempcode(form_input_text($name_tempcode, $explanation, $myrow['the_name'], get_option($myrow['the_name']), false, NULL, true));
                 break;
             case 'transtext':
                 $out .= static_evaluate_tempcode(form_input_text($name_tempcode, $explanation, $myrow['the_name'], get_option($myrow['the_name']), false, NULL, true));
                 break;
             case 'float':
                 $out .= static_evaluate_tempcode(form_input_float($name_tempcode, $explanation, $myrow['the_name'], floatval(get_option($myrow['the_name'])), false));
                 break;
             case 'tick':
                 $out .= static_evaluate_tempcode(form_input_tick($name_tempcode, $explanation, $myrow['the_name'], get_option($myrow['the_name']) == '1'));
                 break;
             case 'date':
                 $out .= static_evaluate_tempcode(form_input_date($name_tempcode, $explanation, $myrow['the_name'], false, false, false, intval(get_option($myrow['the_name'])), 40, intval(date('Y')) - 20, NULL, false));
                 break;
             case 'forum':
             case '?forum':
                 if (get_forum_type() == 'ocf' && addon_installed('ocf_forum')) {
                     $current_setting = get_option($myrow['the_name']);
                     if (!is_numeric($current_setting)) {
                         $_current_setting = $GLOBALS['FORUM_DB']->query_value_null_ok('f_forums', 'id', array('f_name' => $current_setting));
                         if (is_null($_current_setting)) {
                             if ($myrow['the_type'] == '?forum') {
                                 $current_setting = NULL;
                             } else {
                                 $current_setting = strval(db_get_first_id());
                                 attach_message(do_lang_tempcode('FORUM_CURRENTLY_UNSET', $name_tempcode), 'notice');
                             }
                         } else {
                             $current_setting = strval($_current_setting);
                         }
                     }
                     $out .= static_evaluate_tempcode(form_input_tree_list($name_tempcode, $explanation, $myrow['the_name'], NULL, 'choose_forum', array(), false, $current_setting));
                 } else {
                     $out .= static_evaluate_tempcode(form_input_line($name_tempcode, $explanation, $myrow['the_name'], get_option($myrow['the_name']), false));
                 }
                 break;
             case 'category':
                 if (get_forum_type() == 'ocf') {
                     $tmp_value = $GLOBALS['FORUM_DB']->query_value_null_ok('f_categories', 'id', array('c_title' => get_option($myrow['the_name'])));
                     require_code('ocf_forums2');
                     $_list = ocf_nice_get_categories(NULL, $tmp_value);
                     $out .= static_evaluate_tempcode(form_input_list($name_tempcode, $explanation, $myrow['the_name'], $_list));
                 } else {
                     $out .= static_evaluate_tempcode(form_input_line($name_tempcode, $explanation, $myrow['the_name'], get_option($myrow['the_name']), false));
                 }
                 break;
             case 'usergroup':
                 if (get_forum_type() == 'ocf') {
                     $tmp_value = $GLOBALS['FORUM_DB']->query_value_null_ok('f_groups g LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'translate t ON t.id=g.g_name', 'g.id', array('text_original' => get_option($myrow['the_name'])));
                     require_code('ocf_groups');
                     $_list = ocf_nice_get_usergroups($tmp_value);
                     $out .= static_evaluate_tempcode(form_input_list($name_tempcode, $explanation, $myrow['the_name'], $_list));
                 } else {
                     $out .= static_evaluate_tempcode(form_input_line($name_tempcode, $explanation, $myrow['the_name'], get_option($myrow['the_name']), false));
                 }
                 break;
         }
         $current_group = $myrow['section'];
     }
     if ($out != '') {
         $_group_description = do_lang('CONFIG_GROUP_DESCRIP_' . $current_group, escape_html($post_max_size), escape_html($upload_max_filesize), NULL, NULL, false);
         if (is_null($_group_description)) {
             $group_description = new ocp_tempcode();
         } else {
             $group_description = do_lang_tempcode('CONFIG_GROUP_DESCRIP_' . $current_group, escape_html($post_max_size), escape_html($upload_max_filesize));
         }
         $group = do_template('CONFIG_GROUP', array('_GUID' => '84c0db86002a33a383a7c2e195dd3913', 'GROUP_DESCRIPTION' => $group_description, 'GROUP_NAME' => $current_group, 'GROUP' => $out, 'CURRENT_GROUP' => $_group_tempcode));
         $groups->attach($group->evaluate());
     }
     list($warning_details, $ping_url) = handle_conflict_resolution();
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('CONFIGURATION'))));
     breadcrumb_set_self(do_lang_tempcode('CONFIG_CATEGORY_' . $page));
     return do_template('CONFIG_CATEGORY_SCREEN', array('_GUID' => 'd01b28b71c38bbb52b6aaf877c7f7b0e', 'CATEGORY_DESCRIPTION' => $category_description, '_GROUPS' => $_groups, 'PING_URL' => $ping_url, 'WARNING_DETAILS' => $warning_details, 'TITLE' => $title, 'URL' => $post_url, 'GROUPS' => $groups, 'SUBMIT_NAME' => do_lang_tempcode('SAVE')));
 }
Exemplo n.º 24
0
 function _send($token, $secret, $row)
 {
     require_lang('twitter');
     require_code('twitter');
     list($message) = render_activity($row, false);
     $link = static_evaluate_tempcode(pagelink_to_tempcode($row['a_pagelink_1']));
     // Shorten message for Twitter purposes
     $chopped_message = html_entity_decode(strip_tags($message->evaluate()), ENT_COMPAT, get_charset());
     $max_length = 255;
     $shortened_link = mixed();
     if ($link != '') {
         $shortened_link = http_download_file('http://is.gd/api.php?longurl=' . urlencode($link));
         $max_length -= strlen($shortened_link) + 1;
     }
     if (strlen($chopped_message) > $max_length) {
         $chopped_message = substr($chopped_message, 0, $max_length - 3) . '...';
     }
     if ($link != '') {
         $chopped_message .= ' ' . $shortened_link;
     }
     require_code('character_sets');
     $chopped_message = convert_to_internal_encoding($chopped_message, get_charset(), 'utf-8');
     require_code('developer_tools');
     destrictify();
     // Initiate Twitter connection
     $api_key = get_option('twitter_api_key');
     $api_secret = get_option('twitter_api_secret');
     $twitter = new Twitter($api_key, $api_secret);
     $twitter->setOAuthToken($token);
     $twitter->setOAuthTokenSecret($secret);
     // Send message
     try {
         $twitter->statusesUpdate($chopped_message);
     } catch (TwitterException $e) {
         attach_message($e->getMessage(), 'warn');
         return false;
     }
     return true;
 }
Exemplo n.º 25
0
 /**
  * Standard PHP XML parser function.
  *
  * @param  object			The parser object (same as 'this')
  */
 function endElement($parser)
 {
     $tag = array_pop($this->tag_stack);
     $tag_attributes = array_pop($this->attribute_stack);
     switch ($tag) {
         case 'substitution':
             list($zone, $attributes, $hash) = page_link_decode($this->substitution_current_match_key);
             if ($zone == '_WILD') {
                 $zone = REGEXP_CODENAME;
             }
             if (!isset($attributes['page'])) {
                 $attributes['page'] = '';
             }
             /*
             Commented for performance. This isn't user-data, so we're safe
             $zone=str_replace('~','\~',preg_quote($zone)); // We are using '~' as deliminators for the regexp, as the usual '/' and '#' feature in URL separators
             $hash=str_replace('~','\~',preg_quote($hash));
             */
             if ($attributes['page'] == '_WILD_NOT_START') {
                 $zones = find_all_zones(false, true);
                 if (isset($zones[$zone])) {
                     $attributes['page'] = '(?!' . $zones[$zone][3] . ')' . REGEXP_CODENAME;
                 } else {
                     $attributes['page'] = '_WILD';
                 }
             }
             if ($attributes['page'] == '_WILD') {
                 $attributes['page'] = REGEXP_CODENAME;
             }
             foreach ($attributes as $key => $val) {
                 $attributes[$key] = $val;
             }
             $_source_url = build_url($attributes, $zone, NULL, false, false, true, $hash);
             $source_url = urldecode(urldecode($_source_url->evaluate()));
             // urldecode because we don't want our regexp syntax mangled. Highly unlikely our sub's are going to really use special characters as parts of the URL
             if (strpos($source_url, '.htm') === false && strpos($source_url, '.php') === false) {
                 $source_url .= '(?:/index\\.php)?';
             }
             $source_url1 = str_replace(array('.htm', '?', '(\\?', ')\\?', '&', get_base_url() . '/' . REGEXP_CODENAME . '/'), array('\\.htm', '\\?', '(?', ')?', '(?:&[^<>]*)*&', get_base_url() . '/?' . REGEXP_CODENAME . '/'), $source_url) . '(?:[&\\?][^<>]*)*';
             $escaped_source_url = escape_html($source_url);
             if ($source_url == $escaped_source_url) {
                 $source_url2 = $source_url1;
             } else {
                 $source_url2 = str_replace(array('.htm', '?', '(\\?', ')\\?', '&', get_base_url() . '/' . REGEXP_CODENAME . '/'), array('\\.htm', '\\?', '(?', ')?', '(?:&[^<>]*)*&', get_base_url() . '/?' . REGEXP_CODENAME . '/'), $escaped_source_url) . '(?:[&\\?][^<>]*)*';
             }
             $from = '^.*<a[^<>]*\\shref="(' . $source_url2 . ')"[^<>]*>(<abbr[^<>]*>)?([^<>]*)(</abbr>)?</a>';
             $regexp = '#^' . $source_url1 . '$#';
             $have_url_match = preg_match($regexp, get_self_url(true)) != 0;
             // we either bind rule via URL match, or finding it in the defined breadcrumb chain
             if ($have_url_match && preg_match('~' . $from . '~Us', $this->current_breadcrumbs) == 0) {
                 // Probably it's a non-link chain in the breadcrumbs, so try to bind to the <span> portion too (possibly nested)
                 $from = '^.*(<span>(<span[^<>]*>)?|<a[^<>]*\\shref="(' . $source_url2 . ')"[^<>]*>)(<abbr[^<>]*>)?([^<>]*)(</abbr>)?((</(span)>)?</(a|span)>)';
                 $from_non_link = true;
             } else {
                 $from_non_link = false;
             }
             $to = '';
             foreach (array_reverse($this->links) as $link) {
                 list($zone, $attributes, $hash) = page_link_decode($link[0]);
                 $target_url = build_url($attributes, $zone, NULL, false, false, false, $hash);
                 $_link_title = $link[1] === NULL ? do_lang('UNKNOWN') : $link[1];
                 $link_title = preg_match('#\\{\\!|\\{\\?|\\{\\$|\\[#', $_link_title) == 0 ? $_link_title : static_evaluate_tempcode(comcode_to_tempcode($_link_title));
                 if ($target_url->evaluate() == '') {
                     $to .= $link_title . $this->breadcrumb_tpl;
                 } else {
                     $to .= '<a title="' . do_lang('GO_BACKWARDS_TO', escape_html(strip_tags($link_title))) . '" href="' . escape_html($target_url->evaluate()) . '">' . $link_title . '</a>' . $this->breadcrumb_tpl;
                 }
             }
             $_target_url = $from_non_link ? '${3}' : '${1}';
             $existing_label = $from_non_link ? '${5}' : '${3}';
             $_link_title = $this->substitution_current_label === NULL ? $existing_label : $this->substitution_current_label;
             $link_title = preg_match('#(\\{\\!)|(\\{\\?)|(\\{\\$)|(\\[)#', $_link_title) == 0 ? $_link_title : static_evaluate_tempcode(comcode_to_tempcode($_link_title));
             if ($from_non_link) {
                 $to .= '${1}' . $link_title . '${7}';
             } else {
                 $to .= '<a title="' . do_lang('GO_BACKWARDS_TO', escape_html(strip_tags($link_title))) . '" href="' . escape_html($_target_url) . '">${2}' . $link_title . '${4}</a>';
             }
             $this->substitutions[$from] = $to;
             break;
         case 'link':
             $text = trim(str_replace('\\n', chr(10), $this->text_so_far));
             $this->links[] = array($text, isset($tag_attributes['label']) ? $tag_attributes['label'] : NULL);
             break;
     }
 }
Exemplo n.º 26
0
<?php

/*
 ocPortal
 Copyright (c) ocProducts, 2004-2012
 See text/EN/licence.txt for full licencing information.
*/
/**
 * @license		http://opensource.org/licenses/cpal_1.0 Common Public Attribution License
 * @copyright	ocProducts Ltd
 * @package		classifieds
 */
require_lang('classifieds');
if (!isset($map['param'])) {
    $map['param'] = 'classifieds';
}
$catalogue_name = $map['param'];
$show_free = isset($map['show_free']) && $map['show_free'] == '1';
$prices = $GLOBALS['SITE_DB']->query_select('classifieds_prices', array('*'), array('c_catalogue_name' => $catalogue_name), 'ORDER BY c_price');
$data = array();
foreach ($prices as $price) {
    if (!$show_free && $price['c_price'] == 0.0) {
        continue;
    }
    $data[] = array('PRICE' => float_format($price['c_price'], 2), 'LABEL' => get_translated_text($price['c_label']));
}
echo static_evaluate_tempcode(do_template('CLASSIFIEDS', array('DATA' => $data)));
Exemplo n.º 27
0
/**
 * Send out booking mails.
 *
 * @param  array		Booking details structure.
 */
function send_booking_emails($request)
{
    require_code('notifications');
    // Send receipt to customer
    $customer_email = $GLOBALS['FORUM_DRIVER']->get_member_email_address(get_member());
    $customer_name = $GLOBALS['FORUM_DRIVER']->get_username(get_member());
    $receipt = do_template('BOOKING_CONFIRM_FCOMCODE', array('EMAIL_ADDRESS' => $customer_email, 'MEMBER_ID' => strval(get_member()), 'USERNAME' => $customer_name, 'PRICE' => float_format(find_booking_price($request)), 'DETAILS' => make_booking_request_printable($request)));
    dispatch_notification('booking_customer', NULL, do_lang('SUBJECT_BOOKING_CONFIRM', get_site_name()), static_evaluate_tempcode($receipt), array(get_member()), A_FROM_SYSTEM_PRIVILEGED);
    // Send notice to staff
    $notice = do_template('BOOKING_NOTICE_FCOMCODE', array('EMAIL_ADDRESS' => $customer_email, 'MEMBER_ID' => strval(get_member()), 'USERNAME' => $customer_name, 'PRICE' => float_format(find_booking_price($request)), 'DETAILS' => make_booking_request_printable($request)), get_site_default_lang());
    dispatch_notification('booking_inform_staff', NULL, do_lang('SUBJECT_BOOKING_NOTICE', $GLOBALS['FORUM_DRIVER']->get_username(get_member()), get_site_name()), static_evaluate_tempcode($notice), NULL, NULL, 2);
}
Exemplo n.º 28
0
/**
 * Render a menu branch to tempcode.
 *
 * @param  array			The menu branch map
 * @param  SHORT_TEXT	An identifier for the menu (will be used as a unique id by menu javascript code)
 * @param  MEMBER			The member the menu is being built as
 * @param  integer		The depth into the menu that this branch resides at
 * @param  ID_TEXT		The menu type (determines what templates get used)
 * @param  boolean		Whether to generate Comcode with admin privilege
 * @param  array			Array of all other branches
 * @param  integer		The level
 * @return array			A pair: array of parameters of the menu branch (or NULL if unrenderable, or Tempcode of something to attach), and whether it is expanded
 */
function render_menu_branch($branch, $codename, $source_member, $level, $type, $as_admin, $all_branches, $the_level = 1)
{
    global $REDIRECTED_TO;
    $caption = mixed();
    // Initialise type to mixed
    if (is_string($branch['caption']) && strpos($branch['caption'], '[') !== false) {
        $caption = comcode_to_tempcode($branch['caption'], $source_member, $as_admin);
    } else {
        $caption = $branch['caption'];
    }
    if (!is_null($branch['only_on_page']) && $branch['only_on_page'] != '') {
        if (strpos($branch['only_on_page'], '{') !== false) {
            require_code('tempcode_compiler');
            $branch['only_on_page'] = static_evaluate_tempcode(template_to_tempcode($branch['only_on_page']));
        }
        if ($branch['only_on_page'] != '' && !match_key_match($branch['only_on_page'])) {
            return array(NULL, false);
        }
        // We are not allowed to render this on this page
    }
    $current_zone = false;
    $current_page = false;
    $expand_this = false;
    $tooltip = array_key_exists('caption_long', $branch) ? $branch['caption_long'] : '';
    if (is_null($tooltip)) {
        $tooltip = '';
    }
    // Caused by corrupt in DB. translate table join failed due to corrupt lang string reference
    $dp = $GLOBALS['ZONE']['zone_default_page'];
    $url = mixed();
    // Spacers
    if ($branch['type'] == 'blank') {
        return array(do_template('MENU_SPACER_' . filter_naughty_harsh($type), array('MENU' => $codename, 'TOP_LEVEL' => $the_level == 1, 'THE_LEVEL' => strval($the_level), 'CURRENT' => $current_page, 'CURRENT_ZONE' => $current_zone), NULL, false, 'MENU_SPACER_tree'), false);
    }
    // Normal branches...
    $users_current_zone = get_zone_name();
    // Work out the final URL to use
    $url = $branch['special'];
    if (is_object($url)) {
        if (isset($url->seq_parts) && isset($url->seq_parts[0]) && $url->seq_parts[0][3] == 'PAGE_LINK') {
            $url = $url->seq_parts[0][1][0];
            if (is_object($url)) {
                $url = $url->evaluate();
            }
        } elseif (isset($url->bits) && isset($url->bits[0]) && $url->bits[0][2] == 'PAGE_LINK') {
            $url = $url->bits[0][3][0];
            if (is_object($url)) {
                $url = $url->evaluate();
            }
        } elseif (substr($url->evaluate(), 0, strlen(get_base_url())) == get_base_url()) {
            $page_link = url_to_pagelink($url->evaluate(), true, true);
            if ($page_link != '') {
                $url = $page_link;
            }
        }
    }
    if (!is_object($url)) {
        $parts = array();
        if (preg_match('#([\\w-]*):([\\w-]+|[^/]|$)((:(.*))*)#', $url, $parts) != 0 && $parts[1] != 'mailto') {
            $page_link = $url;
            list($zone_name, $map, $hash) = page_link_decode($url);
            if ($zone_name == 'forum' && get_forum_type() != 'ocf') {
                return array(NULL, false);
            }
            if (!isset($map['page'])) {
                $map['page'] = get_zone_default_page($zone_name);
            }
            // If we need to check access
            if (array_key_exists('check_perms', $branch['modifiers'])) {
                if (!has_zone_access(get_member(), $zone_name)) {
                    return array(NULL, false);
                }
                if (!has_page_access(get_member(), $map['page'], $zone_name)) {
                    return array(NULL, false);
                }
            }
            // Scan for Tempcode symbols etc
            foreach ($map as $key => $val) {
                if (strpos($val, '{') !== false) {
                    require_code('tempcode_compiler');
                    $map[$key] = template_to_tempcode($val);
                }
            }
            $url = build_url($map, $zone_name, NULL, false, false, false, $hash);
            // See if this is current page
            $somewhere_definite = false;
            $_parts = array();
            foreach ($all_branches as $_branch) {
                if (!is_string($_branch['special'])) {
                    continue;
                }
                if (preg_match('#([\\w-]*):([\\w-]+|[^/]|$)((:(.*))*)#', $_branch['special'], $_parts) != 0) {
                    if ($_parts[1] == $users_current_zone) {
                        $somewhere_definite = true;
                    }
                }
            }
            $current_zone = $zone_name == $users_current_zone || !is_null($REDIRECTED_TO) && $zone_name == $REDIRECTED_TO['r_to_zone'] && !$somewhere_definite;
            // This code is a bit smart, as zone menus usually have a small number of zones on them - redirects will be counted into the zone redirected to, so long as there is no more suitable zone and so long as it is not a transparent redirect
            if ($zone_name == $users_current_zone || !is_null($REDIRECTED_TO) && $zone_name == $REDIRECTED_TO['r_to_zone'] && array_key_exists('page', $map) && $map['page'] == $REDIRECTED_TO['r_to_page']) {
                $current_page = true;
                foreach ($map as $k => $v) {
                    if (is_integer($v)) {
                        $v = strval($v);
                    }
                    if (is_object($v)) {
                        $v = $v->evaluate();
                    }
                    if ($v == '' && $k == 'page') {
                        $v = 'start';
                        if ($zone_name == $users_current_zone) {
                            global $ZONE;
                            $v = $ZONE['zone_default_page'];
                        }
                    }
                    $pv = get_param($k, $k == 'page' ? $dp : NULL, true);
                    if ($pv !== $v && ($k != 'page' || is_null($REDIRECTED_TO) || !is_null($REDIRECTED_TO) && ($v !== $REDIRECTED_TO['r_to_page'] || $zone_name != $REDIRECTED_TO['r_to_zone'])) && ($k != 'type' || $v != 'misc') && ($v != $dp || $k != 'page' || get_param('page', '') != '') && substr($k, 0, 5) != 'keep_') {
                        $current_page = false;
                        break;
                    }
                }
            }
        } else {
            $page_link = '';
            $sym_pos = mixed();
            $sym_pos = is_null($url) ? false : strpos($url, '{$');
            if ($sym_pos !== false) {
                $_url = new ocp_tempcode();
                $len = strlen($url);
                $prev = 0;
                do {
                    $p_len = $sym_pos + 1;
                    $balance = 1;
                    while ($p_len < $len && $balance != 0) {
                        if ($url[$p_len] == '{') {
                            $balance++;
                        } elseif ($url[$p_len] == '}') {
                            $balance--;
                        }
                        $p_len++;
                    }
                    $_url->attach(substr($url, $prev, $sym_pos - $prev));
                    $_ret = new ocp_tempcode();
                    $_ret->parse_from($url, $sym_pos, $p_len);
                    $_url->attach($_ret);
                    $prev = $p_len;
                    $sym_pos = strpos($url, '{$', $sym_pos + 1);
                } while ($sym_pos !== false);
                $_url->attach(substr($url, $prev));
                $url = $_url;
            }
        }
    } else {
        $page_link = NULL;
    }
    // Children
    $children = new ocp_tempcode();
    $display = 'block';
    if ($branch['type'] == 'drawer') {
        $new_children = array();
        foreach ($branch['children'] as $i => $child) {
            list($children2, $_expand_this) = render_menu_branch($child, $codename, $source_member, $level + 1, $type, $as_admin, $all_branches, $the_level + 1);
            if ($_expand_this) {
                $expand_this = true;
            }
            if ($children2 !== '' && !is_null($children2)) {
                $new_children[] = $children2;
            }
        }
        $num = count($new_children);
        foreach ($new_children as $i => $child) {
            if (is_object($child)) {
                $children->attach($child);
            } else {
                $children->attach(do_template('MENU_BRANCH_' . filter_naughty_harsh($type), $child + array('POSITION' => strval($i), 'LAST' => $i == $num - 1, 'BRETHREN_COUNT' => strval($num)), NULL, false, 'MENU_BRANCH_tree'));
            }
        }
        if ($children->is_empty()) {
            return array(NULL, false);
        }
        // Nothing here!
        if (!array_key_exists('expanded', $branch['modifiers']) && !$expand_this && !$current_page) {
            $display = has_js() ? 'none' : 'block';
            // We remap to 'none' using JS. If no JS, it remains visible. Once we have learn't we have JS, we don't need to do it again
        } else {
            $display = 'block';
        }
    }
    // Data cleanups
    $escape = is_string($caption) && !array_key_exists('comcode', $branch['modifiers']);
    if ($escape) {
        $caption = escape_html($caption);
    }
    // Access key
    if ($page_link === '_SEARCH:help') {
        $accesskey = '6';
    } elseif ($page_link === '_SEARCH:rules') {
        $accesskey = '7';
    } elseif ($page_link === '_SEARCH:staff:type=misc') {
        $accesskey = '5';
    } else {
        $accesskey = '';
    }
    // Other properties
    $popup = array_key_exists('popup', $branch['modifiers']);
    $popup_width = '';
    $popup_height = '';
    if ($popup) {
        $popup_width = strval($branch['width']);
        $popup_height = strval($branch['height']);
    }
    $new_window = array_key_exists('new_window', $branch['modifiers']);
    // Render!
    $rendered_branch = array('RANDOM' => substr(md5(uniqid('')), 0, 7), 'CAPTION' => $caption, 'IMG' => array_key_exists('img', $branch) ? $branch['img'] : '', 'URL' => $url, 'PAGE_LINK' => $page_link, 'ACCESSKEY' => $accesskey, 'POPUP' => $popup, 'POPUP_WIDTH' => $popup_width, 'POPUP_HEIGHT' => $popup_height, 'NEW_WINDOW' => $new_window, 'TOOLTIP' => $tooltip, 'CHILDREN' => $children, 'DISPLAY' => $display, 'MENU' => $codename, 'TOP_LEVEL' => $the_level == 1, 'THE_LEVEL' => strval($the_level), 'CURRENT' => $current_page, 'CURRENT_ZONE' => $current_zone);
    return array($rendered_branch, $current_page || $expand_this);
}
Exemplo n.º 29
0
 /**
  * Render posts.
  *
  * @param  integer		Maximum to load if non-threaded
  * @param  array			Tree structure of posts
  * @param  boolean		Whether the current user may reply to the topic (influences what buttons show)
  * @param  ?AUTO_LINK	Only show posts under here (NULL: show posts from root)
  * @param  array			Review ratings rows
  * @param  AUTO_LINK		ID of forum this topic in in
  * @return tempcode		Rendered tree structure
  */
 function _render_post_tree($num_to_show_limit, $tree, $may_reply, $highlight_by_user, $all_individual_review_ratings, $forum_id)
 {
     list($rendered, ) = $tree;
     $sequence = new ocp_tempcode();
     foreach ($rendered as $post) {
         if (get_forum_type() == 'ocf') {
             require_code('ocf_topicview');
             require_code('ocf_posts');
             $post += ocf_get_details_to_show_post($post);
         }
         // Misc details
         $datetime_raw = $post['date'];
         $datetime = get_timezoned_date($post['date']);
         $poster_url = is_guest($post['user']) ? new ocp_tempcode() : $GLOBALS['FORUM_DRIVER']->member_profile_url($post['user'], false, true);
         $poster_name = array_key_exists('username', $post) ? $post['username'] : $GLOBALS['FORUM_DRIVER']->get_username($post['user']);
         if (is_null($poster_name)) {
             $poster_name = do_lang('UNKNOWN');
         }
         $highlight = $highlight_by_user === $post['user'];
         // Find review, if there is one
         $individual_review_ratings = array();
         foreach ($all_individual_review_ratings as $potential_individual_review_rating) {
             if ($potential_individual_review_rating['r_post_id'] == $post['id']) {
                 $individual_review_ratings[$potential_individual_review_rating['r_rating_type']] = array('REVIEW_TITLE' => $potential_individual_review_rating['r_rating_type'], 'REVIEW_RATING' => float_to_raw_string($potential_individual_review_rating['r_rating']));
             }
         }
         // Edit URL
         $emphasis = new ocp_tempcode();
         $buttons = new ocp_tempcode();
         $last_edited = new ocp_tempcode();
         $last_edited_raw = '';
         $unvalidated = new ocp_tempcode();
         $poster = mixed();
         $poster_details = new ocp_tempcode();
         $is_spacer_post = false;
         if (get_forum_type() == 'ocf') {
             // Spacer post fiddling
             if (!is_null($this->first_post_id) && !is_null($this->topic_title) && !is_null($this->topic_description) && !is_null($this->topic_description_link)) {
                 $is_spacer_post = $post['id'] == $this->first_post_id && substr($post['message_comcode'], 0, strlen('[semihtml]' . do_lang('SPACER_POST_MATCHER'))) == '[semihtml]' . do_lang('SPACER_POST_MATCHER');
                 if ($is_spacer_post) {
                     $c_prefix = do_lang('COMMENT') . ': #';
                     if (substr($this->topic_description, 0, strlen($c_prefix)) == $c_prefix && $this->topic_description_link != '') {
                         list($linked_type, $linked_id) = explode('_', substr($this->topic_description, strlen($c_prefix)), 2);
                         $linked_url = $this->topic_description_link;
                         require_code('ocf_posts');
                         list($new_description, $new_post) = ocf_display_spacer_post($linked_type, $linked_id);
                         //if (!is_null($new_description)) $this->topic_description=$new_description;	Actually, it's a bit redundant
                         if (!is_null($new_post)) {
                             $post['message'] = $new_post;
                         }
                         $highlight = false;
                         $this->topic_title = do_lang('SPACER_TOPIC_TITLE_WRAP', $this->topic_title);
                         $post['title'] = do_lang('SPACER_TOPIC_TITLE_WRAP', $post['title']);
                         $this->topic_description = '';
                     }
                 }
             }
             // Misc meta details for post
             $emphasis = ocf_get_post_emphasis($post);
             $unvalidated = $post['validated'] == 0 ? do_lang_tempcode('UNVALIDATED') : new ocp_tempcode();
             if (array_key_exists('last_edit_time', $post)) {
                 $last_edited = do_template('OCF_TOPIC_POST_LAST_EDITED', array('LAST_EDIT_DATE_RAW' => is_null($post['last_edit_time']) ? '' : strval($post['last_edit_time']), 'LAST_EDIT_DATE' => $post['last_edit_time_string'], 'LAST_EDIT_PROFILE_URL' => $GLOBALS['FORUM_DRIVER']->member_profile_url($post['last_edit_by'], false, true), 'LAST_EDIT_USERNAME' => $post['last_edit_by_username']));
                 $last_edited_raw = is_null($post['last_edit_time']) ? '' : strval($post['last_edit_time']);
             }
             // Post buttons
             if (!$is_spacer_post) {
                 if (!is_null($this->topic_id)) {
                     if (is_null($this->topic_info)) {
                         $this->topic_info = ocf_read_in_topic($this->topic_id, 0, 0, false, false);
                     }
                     require_lang('ocf');
                     $buttons = ocf_render_post_buttons($this->topic_info, $post, $may_reply);
                 }
             }
             // OCF renderings of poster
             static $hooks = NULL;
             if (is_null($hooks)) {
                 $hooks = find_all_hooks('modules', 'topicview');
             }
             static $hook_objects = NULL;
             if (is_null($hook_objects)) {
                 $hook_objects = array();
                 foreach (array_keys($hooks) as $hook) {
                     require_code('hooks/modules/topicview/' . filter_naughty_harsh($hook));
                     $object = object_factory('Hook_' . filter_naughty_harsh($hook), true);
                     if (is_null($object)) {
                         continue;
                     }
                     $hook_objects[$hook] = $object;
                 }
             }
             if (!$is_spacer_post) {
                 if (!is_guest($post['poster'])) {
                     require_code('ocf_members2');
                     $poster_details = ocf_show_member_box($post, false, $hooks, $hook_objects, false);
                 } else {
                     $custom_fields = new ocp_tempcode();
                     if (array_key_exists('ip_address', $post) && addon_installed('ocf_forum')) {
                         $custom_fields->attach(do_template('OCF_TOPIC_POST_CUSTOM_FIELD', array('NAME' => do_lang_tempcode('IP_ADDRESS'), 'VALUE' => $post['ip_address'])));
                         $poster_details = do_template('OCF_GUEST_DETAILS', array('CUSTOM_FIELDS' => $custom_fields));
                     } else {
                         $poster_details = new ocp_tempcode();
                     }
                 }
             }
             if (addon_installed('ocf_forum')) {
                 if (!is_guest($post['poster'])) {
                     $poster = do_template('OCF_POSTER_MEMBER', array('ONLINE' => member_is_online($post['poster']), 'ID' => strval($post['poster']), 'POSTER_DETAILS' => $poster_details, 'PROFILE_URL' => $GLOBALS['FORUM_DRIVER']->member_profile_url($post['poster'], false, true), 'POSTER_USERNAME' => $post['poster_username']));
                 } else {
                     $ip_link = array_key_exists('ip_address', $post) && has_actual_page_access(get_member(), 'admin_lookup') ? build_url(array('page' => 'admin_lookup', 'param' => $post['ip_address']), get_module_zone('admin_lookup')) : new ocp_tempcode();
                     $poster = do_template('OCF_POSTER_GUEST', array('IP_LINK' => $ip_link, 'POSTER_DETAILS' => $poster_details, 'POSTER_USERNAME' => $post['poster_username']));
                 }
             } else {
                 $poster = make_string_tempcode(escape_html($post['poster_username']));
             }
         }
         // Child posts
         $children = mixed();
         // NULL
         $other_ids = array();
         if (array_key_exists('children', $post)) {
             foreach ($post['children'][1] as $u) {
                 $other_ids[] = strval($u['id']);
             }
             if ($this->is_threaded) {
                 $children = $this->_render_post_tree($num_to_show_limit, $post['children'], $may_reply, $highlight_by_user, $all_individual_review_ratings, $forum_id);
             }
         }
         if (get_forum_type() == 'ocf') {
             require_code('feedback');
             actualise_rating(true, 'post', strval($post['id']), get_self_url(), $post['title']);
             $rating = display_rating(get_self_url(), $post['title'], 'post', strval($post['id']), 'RATING_INLINE_DYNAMIC', $post['user']);
         } else {
             $rating = new ocp_tempcode();
         }
         if (array_key_exists('intended_solely_for', $post)) {
             decache('side_ocf_personal_topics', array(get_member()));
             decache('_new_pp', array(get_member()));
         }
         // Render
         $sequence->attach(static_evaluate_tempcode(do_template('POST', array('_GUID' => 'eb7df038959885414e32f58e9f0f9f39', 'INDIVIDUAL_REVIEW_RATINGS' => $individual_review_ratings, 'HIGHLIGHT' => $highlight, 'TITLE' => $post['title'], 'TIME_RAW' => strval($datetime_raw), 'TIME' => $datetime, 'POSTER_ID' => strval($post['user']), 'POSTER_URL' => $poster_url, 'POSTER_NAME' => $poster_name, 'POSTER' => $poster, 'POSTER_DETAILS' => $poster_details, 'ID' => strval($post['id']), 'POST' => $post['message'], 'POST_COMCODE' => isset($post['message_comcode']) ? $post['message_comcode'] : NULL, 'CHILDREN' => $children, 'OTHER_IDS' => count($other_ids) == 0 ? NULL : $other_ids, 'RATING' => $rating, 'EMPHASIS' => $emphasis, 'BUTTONS' => $buttons, 'LAST_EDITED_RAW' => $last_edited_raw, 'LAST_EDITED' => $last_edited, 'TOPIC_ID' => is_null($this->topic_id) ? '' : strval($this->topic_id), 'UNVALIDATED' => $unvalidated, 'IS_SPACER_POST' => $is_spacer_post, 'NUM_TO_SHOW_LIMIT' => strval($num_to_show_limit)))));
     }
     return $sequence;
 }
Exemplo n.º 30
0
/**
 * Get information for the user relating to an addon that they are intending to uninstall.
 *
 * @param  string			Name of the addon
 * @param  ?array			List of addons that we're currently uninstalling (so dependencies from these are irrelevant). (NULL: none)
 * @param  ?array			Addon details. (NULL: load in function)
 * @return array			Pair: warnings, files
 */
function inform_about_addon_uninstall($name, $also_uninstalling = NULL, $addon_row = NULL)
{
    if (is_null($also_uninstalling)) {
        $also_uninstalling = array();
    }
    // Read/show info
    if (is_null($addon_row)) {
        $addon_row = read_addon_info($name);
    }
    $files = new ocp_tempcode();
    // The files can come in as either a newline-separated string or an array.
    // If its an array then we use it as-is, if it's a string then we explode it first.
    if (is_array($addon_row['addon_files'])) {
        $loopable = $addon_row['addon_files'];
    } else {
        $loopable = explode(chr(10), $addon_row['addon_files']);
    }
    foreach ($loopable as $i => $filename) {
        $files->attach(do_template('ADDON_INSTALL_FILES', array('I' => strval($i), 'DISABLED' => true, 'PATH' => $filename)));
    }
    // Check dependencies
    $dependencies = $addon_row['addon_dependencies_on_this'];
    foreach ($also_uninstalling as $d) {
        if (in_array($d, $dependencies)) {
            unset($dependencies[array_search($d, $dependencies)]);
        }
    }
    $warnings = new ocp_tempcode();
    $_dependencies_str = new ocp_tempcode();
    foreach ($dependencies as $in) {
        if (!$_dependencies_str->is_empty()) {
            $_dependencies_str->attach(do_lang_tempcode('LIST_SEP'));
        }
        $_dependencies_str->attach(escape_html($in));
    }
    if (count($dependencies) != 0) {
        if ($addon_row['addon_author'] == 'Core Team') {
            $post_fields = build_keep_post_fields();
            foreach ($dependencies as $in) {
                $post_fields->attach(form_input_hidden('uninstall_' . $in, $in));
            }
            if (get_param('type', 'misc') == 'addon_uninstall') {
                $post_fields->attach(form_input_hidden('uninstall_' . $name, $name));
                $url = static_evaluate_tempcode(build_url(array('page' => '_SELF', 'type' => 'multi_action'), '_SELF'));
            } else {
                $url = get_self_url(true);
            }
            warn_exit(do_lang_tempcode('_ADDON_WARNING_PRESENT_DEPENDENCIES', $_dependencies_str->evaluate(), escape_html($name), array(escape_html($url), $post_fields)));
        } else {
            $warnings->attach(do_template('ADDON_INSTALL_WARNING', array('WARNING' => do_lang_tempcode('ADDON_WARNING_PRESENT_DEPENDENCIES', $_dependencies_str, escape_html($name)))));
        }
    }
    return array($warnings, $files);
}