예제 #1
0
function asb_admin_custom_boxes()
{
    global $lang, $mybb, $db, $page, $html, $min;
    if ($mybb->input['mode'] == 'export') {
        if ((int) $mybb->input['id'] == 0) {
            flash_message($lang->asb_custom_export_error, 'error');
            admin_redirect($html->url(array("action" => 'custom_boxes')));
        }
        $this_custom = new Custom_type($mybb->input['id']);
        if (!$this_custom->is_valid()) {
            flash_message($lang->asb_custom_export_error, 'error');
            admin_redirect($html->url(array("action" => 'custom_boxes')));
        }
        $this_custom->export();
        exit;
    }
    if ($mybb->input['mode'] == 'delete') {
        // info good?
        if ((int) $mybb->input['id'] == 0) {
            flash_message($lang->asb_add_custom_box_delete_failure, 'error');
            admin_redirect($html->url(array("action" => 'custom_boxes')));
        }
        // nuke it
        $this_custom = new Custom_type($mybb->input['id']);
        // success?
        if (!$this_custom->remove()) {
            flash_message($lang->asb_add_custom_box_delete_failure, 'error');
            admin_redirect($html->url(array("action" => 'custom_boxes')));
        }
        // :)
        flash_message($lang->asb_add_custom_box_delete_success, 'success');
        asb_cache_has_changed();
        admin_redirect($html->url(array("action" => 'custom_boxes')));
    }
    // POSTing?
    if ($mybb->request_method == 'post') {
        if ($mybb->input['mode'] == 'import') {
            if (!$_FILES['file'] || $_FILES['file']['error'] == 4) {
                flash_message($lang->asb_custom_import_no_file, 'error');
                admin_redirect($html->url(array("action" => 'custom_boxes')));
            }
            if ($_FILES['file']['error']) {
                flash_message($lang->sprintf($lang->asb_custom_import_file_error, $_FILES['file']['error']), 'error');
                admin_redirect($html->url(array("action" => 'custom_boxes')));
            }
            if (!is_uploaded_file($_FILES['file']['tmp_name'])) {
                flash_message($lang->asb_custom_import_file_upload_error, 'error');
                admin_redirect($html->url(array("action" => 'custom_boxes')));
            }
            $contents = @file_get_contents($_FILES['file']['tmp_name']);
            @unlink($_FILES['file']['tmp_name']);
            if (!trim($contents)) {
                flash_message($lang->asb_custom_import_file_empty, 'error');
                admin_redirect($html->url(array("action" => 'custom_boxes')));
            }
            require_once MYBB_ROOT . 'inc/class_xml.php';
            $parser = new XMLParser($contents);
            $tree = $parser->get_tree();
            if (!is_array($tree) || empty($tree)) {
                flash_message($lang->asb_custom_import_file_empty, 'error');
                admin_redirect($html->url(array("action" => 'custom_boxes')));
            }
            if (!is_array($tree['asb_custom_sideboxes']) || empty($tree['asb_custom_sideboxes'])) {
                if (!is_array($tree['adv_sidebox']) || !is_array($tree['adv_sidebox']['custom_sidebox'])) {
                    flash_message($lang->asb_custom_import_file_empty, 'error');
                    admin_redirect($html->url(array("action" => 'custom_boxes')));
                }
                $results = asb_legacy_custom_import($tree);
                if (!is_array($results)) {
                    flash_message($results, 'error');
                    admin_redirect($html->url(array("action" => 'custom_boxes')));
                }
                $custom = new Custom_type($results);
            } else {
                $custom = new Custom_type();
                if (!$custom->import($contents)) {
                    flash_message($lang->asb_custom_import_fail_generic, 'error');
                    admin_redirect($html->url(array("action" => 'custom_boxes')));
                }
            }
            if (!$custom->save()) {
                flash_message($lang->asb_custom_box_save_failure, 'error');
                admin_redirect($html->url(array("action" => 'custom_boxes')));
            }
            flash_message($lang->asb_custom_import_save_success, 'success');
            admin_redirect($html->url(array("action" => 'custom_boxes', "id" => $custom->get('id'))));
        } else {
            // saving?
            if ($mybb->input['save_box_submit'] == 'Save') {
                if (!$mybb->input['box_name'] || !$mybb->input['box_content']) {
                    flash_message($lang->asb_custom_box_save_failure_no_content, 'error');
                    admin_redirect($html->url(array("action" => 'custom_boxes')));
                }
                $this_custom = new Custom_type((int) $mybb->input['id']);
                // get the info
                $this_custom->set('title', $mybb->input['box_name']);
                $this_custom->set('description', $mybb->input['box_description']);
                $this_custom->set('content', $mybb->input['box_content']);
                $this_custom->set('wrap_content', $mybb->input['wrap_content'] == 'yes');
                // success?
                if (!$this_custom->save()) {
                    flash_message($lang->asb_custom_box_save_failure, 'error');
                    admin_redirect($html->url(array("action" => 'custom_boxes', "id" => $this_custom->get('id'))));
                }
                flash_message($lang->asb_custom_box_save_success, 'success');
                asb_cache_has_changed();
                admin_redirect($html->url(array("action" => 'custom_boxes', "id" => $this_custom->get('id'))));
            }
        }
    }
    $page->add_breadcrumb_item($lang->asb, $html->url());
    if ($mybb->input['mode'] == 'edit') {
        $queryadmin = $db->simple_select('adminoptions', '*', "uid='{$mybb->user['uid']}'");
        $admin_options = $db->fetch_array($queryadmin);
        if ($admin_options['codepress'] != 0) {
            $page->extra_header .= <<<EOF
\t<link type="text/css" href="./jscripts/codepress/languages/codepress-mybb.css" rel="stylesheet" id="cp-lang-style"/>
\t<script type="text/javascript" src="./jscripts/codepress/codepress.js"></script>
\t<script type="text/javascript">
\t<!--
\t\tCodePress.language = 'mybb';
\t// -->
\t</script>
EOF;
        }
        $this_box = new Custom_type((int) $mybb->input['id']);
        $action = $lang->asb_add_custom;
        if ($this_box->get('id')) {
            $specify_box = '&amp;id=' . $this_box->get('id');
            $currently_editing = $lang->asb_editing . ': <strong>' . $this_box->get('title') . '</strong>';
            $action = $lang->asb_edit . ' ' . $this_box->get('title');
        } else {
            // new box
            $specify_box = '';
            $sample_content = <<<EOF
<tr>
\t\t<td class="trow1">{$lang->asb_sample_content_line1} (HTML)</td>
\t</tr>
\t<tr>
\t\t<td class="trow2">{$lang->asb_sample_content_line2}</td>
\t</tr>
\t<tr>
\t\t<td class="trow1"><strong>{$lang->asb_sample_content_line3}</td>
\t</tr>
EOF;
            $this_box->set('content', $sample_content);
            $this_box->set('wrap_content', true);
        }
        $page->extra_header .= <<<EOF
\t<link rel="stylesheet" type="text/css" href="styles/asb_acp.css" media="screen" />
\t<script src="jscripts/asb/asb{$min}.js" type="text/javascript"></script>
EOF;
        $page->add_breadcrumb_item($lang->asb_custom_boxes, $html->url(array("action" => 'custom_boxes')));
        $page->add_breadcrumb_item($lang->asb_add_custom);
        $page->output_header("{$lang->asb} - {$action}");
        asb_output_tabs('asb_add_custom');
        $form = new Form($html->url(array("action" => 'custom_boxes')) . $specify_box, 'post', 'edit_box');
        $form_container = new FormContainer($currently_editing);
        $form_container->output_cell($lang->asb_name);
        $form_container->output_cell($lang->asb_description);
        $form_container->output_cell($lang->asb_custom_box_wrap_content);
        $form_container->output_row('');
        // name
        $form_container->output_cell($form->generate_text_box('box_name', $this_box->get('title'), array("id" => 'box_name')));
        // description
        $form_container->output_cell($form->generate_text_box('box_description', $this_box->get('description')));
        // wrap content?
        $form_container->output_cell($form->generate_check_box('wrap_content', 'yes', $lang->asb_custom_box_wrap_content_desc, array("checked" => $this_box->get('wrap_content'))));
        $form_container->output_row('');
        $form_container->output_cell('Content:', array("colspan" => 3));
        $form_container->output_row('');
        // content
        $form_container->output_cell($form->generate_text_area('box_content', $this_box->get('content'), array("id" => 'box_content', 'class' => 'codepress mybb', 'style' => 'width: 100%; height: 240px;')), array("colspan" => 3));
        $form_container->output_row('');
        // finish form
        $form_container->end();
        $buttons[] = $form->generate_submit_button('Save', array('name' => 'save_box_submit'));
        $form->output_submit_wrapper($buttons);
        $form->end();
        if ($admin_options['codepress'] != 0) {
            echo <<<EOF
\t\t<script type="text/javascript">
\t\t<!--
\t\t\tEvent.observe('edit_box', 'submit', function() {
\t\t\t\tif (\$('box_content_cp')) {
\t\t\t\t\tvar area = \$('box_content_cp');
\t\t\t\t\tarea.id = 'box_content';
\t\t\t\t\tarea.value = box_content.getCode();
\t\t\t\t\tarea.disabled = false;
\t\t\t\t}
\t\t\t});
\t\t// -->
\t\t</script>
EOF;
            // build link bar and ACP footer
            asb_output_footer('edit_custom');
        }
    }
    $page->extra_header .= <<<EOF
\t<link rel="stylesheet" type="text/css" href="styles/asb_acp.css" media="screen" />
\t<script src="jscripts/asb/asb{$min}.js" type="text/javascript"></script>
EOF;
    $page->add_breadcrumb_item($lang->asb_custom_boxes);
    $page->output_header("{$lang->asb} - {$lang->asb_custom_boxes}");
    asb_output_tabs('asb_custom');
    $new_box_url = $html->url(array("action" => 'custom_boxes', "mode" => 'edit'));
    $new_box_link = $html->link($new_box_url, $lang->asb_add_custom_box_types, array("style" => 'font-weight: bold;', "title" => $lang->asb_add_custom_box_types, "icon" => "{$mybb->settings['bburl']}/inc/plugins/asb/images/add.png"), array("alt" => '+', "style" => 'margin-bottom: -3px;', "title" => $lang->asb_add_custom_box_types));
    echo $new_box_link . '<br /><br />';
    $table = new Table();
    $table->construct_header($lang->asb_name);
    $table->construct_header($lang->asb_custom_box_desc);
    $table->construct_header($lang->asb_controls, array("colspan" => 2));
    $custom = asb_get_all_custom();
    // if there are saved types . . .
    if (is_array($custom) && !empty($custom)) {
        // display them
        foreach ($custom as $this_custom) {
            $data = $this_custom->get('data');
            // name (edit link)
            $edit_url = $html->url(array("action" => 'custom_boxes', "mode" => 'edit', "id" => $data['id']));
            $edit_link = $html->link($edit_url, $data['title'], array("title" => $lang->asb_edit, "style" => 'font-weight: bold;'));
            $table->construct_cell($edit_link, array("width" => '30%'));
            // description
            if ($data['description']) {
                $description = $data['description'];
            } else {
                $description = "<em>{$lang->asb_no_description}</em>";
            }
            $table->construct_cell($description, array("width" => '60%'));
            // options popup
            $popup = new PopupMenu('box_' . $data['id'], $lang->asb_options);
            // edit
            $popup->add_item($lang->asb_edit, $edit_url);
            // delete
            $popup->add_item($lang->asb_delete, $html->url(array("action" => 'custom_boxes', "mode" => 'delete', "id" => $data['id'])), "return confirm('{$lang->asb_custom_del_warning}');");
            // export
            $popup->add_item($lang->asb_custom_export, $html->url(array("action" => 'custom_boxes', "mode" => 'export', "id" => $data['id'])));
            // popup cell
            $table->construct_cell($popup->fetch(), array("width" => '10%'));
            // finish the table
            $table->construct_row();
        }
    } else {
        // no saved types
        $table->construct_cell($lang->asb_no_custom_boxes, array("colspan" => 4));
        $table->construct_row();
    }
    $table->output($lang->asb_custom_box_types);
    echo '<br /><br />';
    $import_form = new Form($html->url(array("action" => 'custom_boxes', "mode" => 'import')), 'post', '', 1);
    $import_form_container = new FormContainer($lang->asb_custom_import);
    $import_form_container->output_row($lang->asb_custom_import_select_file, '', $import_form->generate_file_upload_box('file'));
    $import_form_container->end();
    $import_buttons[] = $import_form->generate_submit_button($lang->asb_custom_import, array('name' => 'import'));
    $import_form->output_submit_wrapper($import_buttons);
    $import_form->end();
    // build link bar and ACP footer
    asb_output_footer('custom');
}
예제 #2
0
function asb_build_cache(&$asb)
{
    global $db;
    // fresh start
    $asb['custom'] = $asb['sideboxes'] = $asb['scripts'] = $asb['all_scripts'] = array();
    // update the run time and changed flag before we even start
    $asb['last_run'] = TIME_NOW;
    $asb['has_changed'] = false;
    // all the general side box related objects
    require_once MYBB_ROOT . 'inc/plugins/asb/classes/forum.php';
    // get all the active scripts' info
    $all_scripts = asb_get_all_scripts();
    // no scripts, no work to do
    if (!is_array($all_scripts) || empty($all_scripts)) {
        return;
    }
    // store the script definitions and a master list
    foreach ($all_scripts as $filename => $script) {
        $asb['scripts'][$filename] = $script;
    }
    $asb['all_scripts'] = array_keys($all_scripts);
    // load all detected modules
    $addons = asb_get_all_modules();
    // get any custom boxes
    $custom = asb_get_all_custom();
    // get any sideboxes
    $sideboxes = asb_get_all_sideboxes();
    if (!is_array($sideboxes) || empty($sideboxes)) {
        return;
    }
    foreach ($sideboxes as $sidebox) {
        // build basic data
        $scripts = $sidebox->get('scripts');
        $id = (int) $sidebox->get('id');
        $pos = $sidebox->get('position') ? 1 : 0;
        $asb['sideboxes'][$id] = $sidebox->get('data');
        $module = $sidebox->get('box_type');
        // no scripts == all scripts
        if (empty($scripts)) {
            // add this side box to the 'global' set (to be merged with the current script when applicable)
            $scripts = array('global');
        }
        // for each script in which the side box is used, add a pointer and if it is a custom box, cache its contents
        foreach ($scripts as $filename) {
            // side box from a module?
            if (isset($addons[$module]) && $addons[$module] instanceof Addon_type) {
                // store the module name and all the template vars used
                $asb['scripts'][$filename]['sideboxes'][$pos][$id] = $module;
                $asb['scripts'][$filename]['template_vars'][$id] = "{$module}_{$id}";
                // if there are any templates get their names so we can cache them
                $templates = $addons[$module]->get('templates');
                if (is_array($templates) && !empty($templates)) {
                    foreach ($templates as $template) {
                        $asb['scripts'][$filename]['templates'][] = $template['title'];
                    }
                }
                // AJAX?
                if ($addons[$module]->xmlhttp && $sidebox->has_settings) {
                    $settings = $sidebox->get('settings');
                    // again, default here is off if anything goes wrong
                    if ($settings['xmlhttp_on']) {
                        // if all is good add the script building info
                        $asb['scripts'][$filename]['extra_scripts'][$id]['position'] = $pos;
                        $asb['scripts'][$filename]['extra_scripts'][$id]['module'] = $module;
                        $asb['scripts'][$filename]['extra_scripts'][$id]['rate'] = $settings['xmlhttp_on'];
                    }
                }
                if ($addons[$module]->has_scripts) {
                    foreach ($addons[$module]->get('scripts') as $script) {
                        $asb['scripts'][$filename]['js'][$script] = $script;
                    }
                }
            } else {
                if (isset($custom[$module]) && $custom[$module] instanceof Custom_type) {
                    // store the pointer
                    $asb['scripts'][$filename]['sideboxes'][$pos][$id] = $module;
                    $asb['scripts'][$filename]['template_vars'][$id] = "{$module}_{$id}";
                    // and cache the contents
                    $asb['custom'][$module] = $custom[$module]->get('data');
                }
            }
        }
    }
}