コード例 #1
0
function asb_build_theme_exclude_select()
{
    $all_themes = asb_get_all_themes(true);
    $theme_count = min(5, count($all_themes));
    if ($theme_count == 0) {
        return $theme_select = <<<EOF
php
<select name=\\"upsetting[asb_exclude_theme][]\\" size=\\"1\\">
\t<option value=\\"0\\">no themes!</option>
</select>

EOF;
    }
    // Create an option for each theme and insert code to unserialize each option and 'remember' settings
    foreach ($all_themes as $tid => $name) {
        $name = addcslashes($name, '"');
        $theme_select .= <<<EOF
<option value=\\"{$tid}\\" " . (is_array(unserialize(\$setting['value'])) ? (\$setting['value'] != "" && in_array("{$tid}", unserialize(\$setting['value'])) ? "selected=\\"selected\\"":""):"") . ">{$name}</option>
EOF;
    }
    // put it all together
    return <<<EOF
php
<select multiple name=\\"upsetting[asb_exclude_theme][]\\" size=\\"{$theme_count}\\">
{$theme_select}
</select>

EOF;
}
コード例 #2
0
function asb_admin_edit_box()
{
    global $page, $lang, $mybb, $db, $html, $scripts, $all_scripts, $min;
    $sidebox = new Sidebox($mybb->input['id']);
    $id = (int) $sidebox->get('id');
    $position = (int) $mybb->input['box_position'];
    if ($mybb->input['ajax'] == 1) {
        $position = (int) $mybb->input['pos'];
        if ($id) {
            $position = (int) $sidebox->get('position');
        }
    }
    $is_custom = $is_module = false;
    $custom_title = 0;
    $module = $mybb->input['addon'];
    $parent = new Addon_type($module);
    if (!$parent->is_valid()) {
        // did this box come from a custom static box?
        $variable_array = explode('_', $module);
        $custom_id = $variable_array[count($variable_array) - 1];
        $parent = new Custom_type($custom_id);
        if ($parent->is_valid()) {
            $is_custom = true;
        } else {
            flash_message($lang->asb_edit_fail_bad_module, 'error');
            if ($mybb->input['ajax'] != 1) {
                admin_redirect($html->url());
            }
            die('<error>asb</error>');
        }
    } else {
        $is_module = true;
    }
    // saving?
    if ($mybb->request_method == 'post') {
        $sidebox->set('position', $position);
        // display order
        if (!isset($mybb->input['display_order']) || (int) $mybb->input['display_order'] == 0) {
            // get a total number of side boxes on the same side and put it at the bottom
            $query = $db->simple_select('asb_sideboxes', 'display_order', "position='{$position}'");
            $display_order = (int) (($db->num_rows($query) + 1) * 10);
        } else {
            // or back off if they entered a value
            $display_order = (int) $mybb->input['display_order'];
        }
        $sidebox->set('display_order', $display_order);
        // scripts
        $script_list = $mybb->input['script_select_box'];
        if ($script_list[0] == 'all_scripts' || count($script_list) >= count($all_scripts)) {
            $script_list = array();
        }
        $sidebox->set('scripts', $script_list);
        // groups
        $group_list = $mybb->input['group_select_box'];
        if ($group_list[0] == 'all') {
            $group_list = array();
        }
        $sidebox->set('groups', $group_list);
        // themes
        $theme_list = $mybb->input['theme_select_box'];
        if ($theme_list[0] == 'all_themes') {
            $theme_list = array();
        }
        $sidebox->set('themes', $theme_list);
        // box type
        $sidebox->set('box_type', $module);
        $sidebox->set('wrap_content', true);
        if ($is_module) {
            $sidebox->set('wrap_content', $parent->get('wrap_content'));
            $addon_settings = $parent->get('settings');
            // if the parent module has settings . . .
            if (is_array($addon_settings)) {
                // loop through them
                $settings = array();
                foreach ($addon_settings as $setting) {
                    // and if the setting has a value
                    if (isset($mybb->input[$setting['name']])) {
                        // store it
                        $settings[$setting['name']] = $mybb->input[$setting['name']];
                    }
                }
                $settings = $parent->do_settings_save($settings);
                $sidebox->set('settings', $settings);
            }
        } elseif ($is_custom) {
            // then use its wrap_content property
            $sidebox->set('wrap_content', $parent->get('wrap_content'));
        }
        // if the text field isn't empty . . .
        if ($mybb->input['box_title']) {
            // use it
            $sidebox->set('title', $mybb->input['box_title']);
        } else {
            // otherwise, check the hidden field (original title)
            if ($mybb->input['current_title']) {
                // if it exists, use it
                $sidebox->set('title', $mybb->input['current_title']);
            } else {
                // otherwise use the default title
                $sidebox->set('title', $parent->get('title'));
            }
        }
        $sidebox->set('title_link', trim($mybb->input['title_link']));
        // save the side box
        $new_id = $sidebox->save();
        asb_cache_has_changed();
        // AJAX?
        if ($mybb->input['ajax'] != 1) {
            // if in the standard form handle it with a redirect
            flash_message($lang->asb_save_success, 'success');
            admin_redirect('index.php?module=config-asb');
        }
        $column_id = 'left_column';
        if ($position) {
            $column_id = 'right_column';
        }
        // creating a new box?
        $build_script = '';
        if ($id == 0) {
            // grab the insert id
            $id = $new_id;
            // then escape the title
            $box_title = addcslashes($sidebox->get('title'), "'");
            /*
             * create the new <div> representation of the side box
             * (title only it will be filled in later by the updater)
             */
            $build_script = "ASB.sidebox.createDiv({$id}, '{$box_title}', '{$column_id}'); ";
        }
        // update the side box after we're done via AJAX
        $script = <<<EOF
<script type="text/javascript">
{$build_script}ASB.sidebox.updateDiv({$id});
</script>
EOF;
        // the modal box will eval() any scripts passed as output (that are valid).
        echo $script;
        exit;
    }
    if ($id == 0) {
        $page_title = $lang->asb_add_a_sidebox;
        // this is a new box, check the page view filter to try to predict which script the user will want
        if ($mybb->input['page']) {
            // start them out with the script they are viewing for Which Scripts
            $selected_scripts[] = $mybb->input['page'];
        } else {
            // if page isn't set at all then just start out with all scripts
            $selected_scripts = 'all_scripts';
        }
        $custom_title = 0;
        $current_title = '';
    } else {
        $page_title = $lang->asb_edit_a_sidebox;
        // . . . otherwise we are editing so pull the actual info from the side box
        $selected_scripts = $sidebox->get('scripts');
        if (empty($selected_scripts)) {
            $selected_scripts = 'all_scripts';
        } elseif (isset($selected_scripts[0]) && strlen($selected_scripts[0]) == 0) {
            $script_warning = <<<EOF
<span style="color: red;">{$lang->asb_all_scripts_deactivated}</span><br />
EOF;
        }
        // check the name of the add-on/custom against the display name of the sidebox, if they differ . . .
        if ($sidebox->get('title') != $parent->get('title')) {
            // then this box has a custom title
            $custom_title = 1;
        }
    }
    // AJAX?
    if ($mybb->input['ajax'] == 1) {
        // the content is much different
        echo <<<EOF
<div id="ModalContentContainer">
\t<div class="ModalTitle">
\t\t{$page_title}
\t\t<a href="javascript:;" id="modalClose" class="float_right modalClose">&nbsp;</a>
\t</div>
\t<div class="ModalContent">

EOF;
        $form = new Form('', 'post', 'modal_form');
    } else {
        // standard form stuff
        $page->add_breadcrumb_item($lang->asb);
        $page->add_breadcrumb_item($page_title);
        // add a little CSS
        $page->extra_header .= <<<EOF
\t<link rel="stylesheet" type="text/css" href="styles/asb_acp.css" media="screen" />
\t<script type="text/javascript" src="jscripts/peeker.js"></script>
\t<script src="jscripts/asb/asb{$min}.js" type="text/javascript"></script>

EOF;
        $page->output_header("{$lang->asb} - {$page_title}");
        $form = new Form($html->url(array("action" => 'edit_box', "id" => $id, "addon" => $module)), 'post', 'modal_form');
    }
    $tabs = array("general" => $lang->asb_modal_tab_general, "permissions" => $lang->asb_modal_tab_permissions, "pages" => $lang->asb_modal_tab_pages, "themes" => $lang->asb_modal_tab_themes, "settings" => $lang->asb_modal_tab_settings);
    // we only need a 'Settings' tab if the current module type has settings
    $do_settings = true;
    if (!$sidebox->has_settings && !$parent->has_settings) {
        unset($tabs['settings']);
        $do_settings = false;
    }
    reset($tabs);
    $observe_onload = false;
    if ($mybb->input['ajax'] != 1) {
        $observe_onload = true;
    }
    $page->output_tab_control($tabs, $observe_onload);
    // custom title?
    if ($custom_title == 1) {
        // alter the descrption
        $current_title = <<<EOF
<em>{$lang->asb_current_title}</em><br /><br /><strong>{$sidebox->get('title')}</strong><br />{$lang->asb_current_title_info}
EOF;
    } else {
        // default description
        $current_title = $lang->asb_default_title_info;
    }
    // current editing text
    $currently_editing = '"' . $parent->get('title') . '"';
    $box_action = $lang->asb_creating;
    if (isset($mybb->input['id'])) {
        $box_action = $lang->asb_editing;
    }
    echo "\n<div id=\"tab_general\">\n";
    $form_container = new FormContainer('<h3>' . $lang->sprintf($lang->asb_new_sidebox_action, $box_action, $currently_editing) . '</h3>');
    if ($mybb->input['ajax'] != 1) {
        // box title
        $form_container->output_row($lang->asb_custom_title, $current_title, $form->generate_text_box('box_title') . $form->generate_hidden_field('current_title', $sidebox->get('title')), 'box_title', array("id" => 'box_title'));
        // title link
        $form_container->output_row($lang->asb_title_link, $lang->asb_title_link_desc, $form->generate_text_box('title_link', $sidebox->get('title_link')), 'title_link', array("id" => 'title_link'));
        // position
        $form_container->output_row($lang->asb_position, '', $form->generate_radio_button('box_position', 0, $lang->asb_position_left, array("checked" => $sidebox->get('position') == 0)) . '&nbsp;&nbsp;' . $form->generate_radio_button('box_position', 1, $lang->asb_position_right, array("checked" => $sidebox->get('position') != 0)));
        // display order
        $form_container->output_row($lang->asb_display_order, '', $form->generate_text_box('display_order', $sidebox->get('display_order')));
    } else {
        // box title
        $form_container->output_row($lang->asb_title, $current_title, $form->generate_text_box('box_title'), 'box_title', array("id" => 'box_title'));
        // title link and hidden fields
        $form_container->output_row($lang->asb_title_link, $lang->asb_title_link_desc, $form->generate_text_box('title_link', $sidebox->get('title_link')) . $form->generate_hidden_field('current_title', $sidebox->get('title')) . $form->generate_hidden_field('display_order', $sidebox->get('display_order')) . $form->generate_hidden_field('pos', $position), 'title_link', array("id" => 'title_link'));
    }
    $form_container->end();
    echo "\n</div>\n<div id=\"tab_permissions\" style=\"text-align: center;\">\n";
    $form_container = new FormContainer($lang->asb_which_groups);
    // prepare options for which groups
    $options = array();
    $groups = array();
    $options['all'] = $lang->asb_all_groups;
    $options[0] = $lang->asb_guests;
    // look for all groups except Super Admins
    $query = $db->simple_select('usergroups', 'gid, title', "gid != '1'", array('order_by' => 'gid'));
    while ($usergroup = $db->fetch_array($query)) {
        // store them their titles by groud id
        $options[(int) $usergroup['gid']] = $usergroup['title'];
    }
    // do we have groups stored?
    $groups = $sidebox->get('groups');
    if (empty($groups)) {
        $groups = 'all';
    }
    // which groups
    $form_container->output_row('', $script_warning, $form->generate_select_box('group_select_box[]', $options, $groups, array('id' => 'group_select_box', 'multiple' => true, 'size' => 5)));
    $form_container->output_row('', '', $form->generate_hidden_field('this_group_count', count($options)));
    $form_container->end();
    echo "\n</div>\n<div id=\"tab_pages\" style=\"text-align: center;\">\n";
    $form_container = new FormContainer($lang->asb_which_scripts);
    // prepare for which scripts
    $choices = array();
    $choices['all_scripts'] = $lang->asb_all;
    // are there active scripts?
    if (is_array($all_scripts)) {
        // loop through them
        foreach ($all_scripts as $filename => $title) {
            // store the script as a choice
            $choices[$filename] = $title;
        }
    }
    // if there are few scripts to choose from, alter the layout and/or wording of choices
    switch (count($choices)) {
        case 3:
            $choices['all_scripts'] = $lang->asb_both_scripts;
            break;
        case 2:
            unset($choices['all_scripts']);
            $selected_scripts = array_flip($choices);
            break;
        case 1:
            $choices['all_scripts'] = $lang->asb_all_scripts_disabled;
            break;
    }
    // which scripts
    $form_container->output_row('', $script_warning, $form->generate_select_box('script_select_box[]', $choices, $selected_scripts, array("id" => 'script_select_box', "multiple" => true)));
    $form_container->end();
    echo "\n</div>\n<div id=\"tab_themes\" style=\"text-align: center;\">\n";
    $form_container = new FormContainer($lang->asb_which_themes);
    // do we have themes stored?
    $themes = $sidebox->get('themes');
    if (empty($themes)) {
        $themes = 'all_themes';
    }
    $choices = array("all_themes" => 'All Themes') + asb_get_all_themes();
    // which scripts
    $form_container->output_row('', '', $form->generate_select_box('theme_select_box[]', $choices, $themes, array("id" => 'theme_select_box', "multiple" => true)));
    $form_container->end();
    if ($do_settings) {
        echo "</div>\n<div id=\"tab_settings\">\n";
        if ($mybb->input['ajax'] == 1) {
            echo "<div style=\"max-height: 400px; overflow: auto; clear: both;\">\n";
        }
        $form_container = new FormContainer($lang->asb_modal_tab_settings_desc);
        $settings = $parent->get('settings');
        if ($id) {
            $sidebox_settings = $sidebox->get('settings');
            foreach ($settings as $name => $value) {
                if (isset($sidebox_settings[$name])) {
                    $settings[$name]['value'] = $sidebox_settings[$name];
                }
            }
        }
        foreach ((array) $settings as $setting) {
            // allow the handler to build module settings
            asb_build_setting($form, $form_container, $setting);
        }
        $form_container->end();
        $parent->do_settings_load();
        echo "</div>\n";
    }
    // AJAX gets a little different wrap-up
    if ($mybb->input['ajax'] == 1) {
        echo "</div>\n<div class=\"ModalButtonRow\">\n";
        $buttons[] = $form->generate_submit_button($lang->asb_cancel, array('id' => 'modalCancel'));
        $buttons[] = $form->generate_submit_button($lang->asb_save, array('id' => 'modalSubmit'));
        $form->output_submit_wrapper($buttons);
        echo "\n</div>\n";
        $form->end();
        echo "\n</div>\n";
    } else {
        echo "\n</div>\n";
        // finish form and page
        $buttons[] = $form->generate_submit_button($lang->asb_save, array('name' => 'save_box_submit'));
        $form->output_submit_wrapper($buttons);
        $form->end();
        // output the link menu and MyBB footer
        asb_output_footer('edit_box');
    }
}
コード例 #3
0
function asb_build_theme_visibility_list($sidebox, $colspan, $global)
{
    global $lang;
    $themes = asb_get_all_themes();
    $good_themes = $sidebox->get('themes');
    if (!$themes) {
        return false;
    }
    if (!$good_themes || count($good_themes) == count($themes)) {
        $theme_list = $lang->asb_visibile_for_all_themes;
        if ($global) {
            return '';
        }
    } else {
        $theme_list = '';
        foreach ($themes as $tid => $name) {
            if ($good_themes && !in_array($tid, $good_themes)) {
                $theme_list .= <<<EOF
{$sep}<s>{$name}</s>
EOF;
            } else {
                $theme_list .= <<<EOF
{$sep}{$name}
EOF;
            }
            $sep = ', ';
        }
    }
    return <<<EOF

\t<tr>
\t\t<td colspan="{$colspan}">{$theme_list}</td>
\t</tr>
EOF;
}