function asb_create_script_info($return = false)
{
    require_once MYBB_ROOT . 'inc/plugins/asb/classes/script_info.php';
    $scripts = array("index" => array("title" => 'Index', "filename" => 'index.php', "template_name" => 'index', "hook" => 'index_start', "find_top" => '{$header}', "find_bottom" => '{$footer}', "active" => 1), "forumdisplay" => array("title" => 'Forum Display', "filename" => 'forumdisplay.php', "template_name" => 'forumdisplay_threadlist', "hook" => 'forumdisplay_start', "find_top" => '<div class="float_right">
	{$newthread}
</div>', "find_bottom" => '{$inline_edit_js}', "active" => 1), "showthread" => array("title" => 'Show Thread', "filename" => 'showthread.php', "template_name" => 'showthread', "hook" => 'showthread_start', "find_top" => '{$ratethread}', "find_bottom" => '{$footer}', "active" => 1), "member" => array("title" => 'Member Profile', "filename" => 'member.php', "action" => 'profile', "template_name" => 'member_profile', "hook" => 'member_profile_start', "find_top" => '{$header}', "find_bottom" => '{$footer}', "active" => 1), "memberlist" => array("title" => 'Member List', "filename" => 'memberlist.php', "template_name" => 'memberlist', "hook" => 'memberlist_start', "find_top" => '{$multipage}', "find_bottom" => '{$footer}', "active" => 1), "showteam" => array("title" => 'Forum Team', "filename" => 'showteam.php', "template_name" => 'showteam', "hook" => 'showteam_start', "find_top" => '{$header}', "find_bottom" => '{$footer}', "active" => 1), "stats" => array("title" => 'Statistics', "filename" => 'stats.php', "template_name" => 'stats', "hook" => 'stats_start', "find_top" => '{$header}', "find_bottom" => '{$footer}', "active" => 1), "portal" => array("title" => 'Portal', "filename" => 'portal.php', "template_name" => 'portal', "hook" => 'portal_start', "replace_all" => 1, "replacement" => <<<EOF
<html>
<head>
<title>{\$mybb->settings['bbname']}</title>
{\$headerinclude}
</head>
<body>
{\$header}
{\$asb_left}
{\$announcements}
{\$asb_right}
{\$footer}
</body>
</html>
EOF
, "active" => 1));
    if ($return == false) {
        foreach ($scripts as $info) {
            $this_script = new ScriptInfo($info);
            $this_script->save();
        }
        return true;
    } else {
        foreach ($scripts as $key => $info) {
            $ret_scripts[$key] = new ScriptInfo($info);
        }
        return $ret_scripts;
        // upgrade script will save these script defs
    }
}
Пример #2
0
function asb_admin_manage_scripts()
{
    global $mybb, $db, $page, $lang, $html, $min;
    require_once MYBB_ROOT . 'inc/plugins/asb/classes/script_info.php';
    $page->add_breadcrumb_item($lang->asb, $html->url());
    if ($mybb->request_method == 'post') {
        if ($mybb->input['mode'] == 'edit') {
            $mybb->input['action'] = $mybb->input['script_action'];
            $script_info = new ScriptInfo($mybb->input);
            if (!$script_info->save()) {
                flash_message($lang->asb_script_save_fail, 'error');
                admin_redirect($html->url(array("action" => 'manage_scripts')));
            }
            flash_message($lang->asb_script_save_success, 'success');
            asb_cache_has_changed();
            admin_redirect($html->url(array("action" => 'manage_scripts')));
        } elseif ($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" => 'manage_scripts')));
            }
            if ($_FILES['file']['error']) {
                flash_message($lang->sprintf($lang->asb_custom_import_file_error, $_FILES['file']['error']), 'error');
                admin_redirect($html->url(array("action" => 'manage_scripts')));
            }
            if (!is_uploaded_file($_FILES['file']['tmp_name'])) {
                flash_message($lang->asb_custom_import_file_upload_error, 'error');
                admin_redirect($html->url(array("action" => 'manage_scripts')));
            }
            $contents = @file_get_contents($_FILES['file']['tmp_name']);
            @unlink($_FILES['file']['tmp_name']);
            if (strlen(trim($contents)) == 0) {
                flash_message($lang->asb_custom_import_file_empty, 'error');
                admin_redirect($html->url(array("action" => 'manage_scripts')));
            }
            $this_script = new ScriptInfo();
            if (!$this_script->import($contents)) {
                flash_message($lang->asb_script_import_fail, 'error');
                admin_redirect($html->url(array("action" => 'manage_scripts')));
            }
            if (!$this_script->save()) {
                flash_message($lang->asb_script_import_fail, 'error');
            }
            flash_message($lang->asb_script_import_success, 'success');
            asb_cache_has_changed();
            admin_redirect($html->url(array("action" => 'manage_scripts')));
        }
    }
    if ($mybb->input['mode'] == 'delete' && $mybb->input['id']) {
        $this_script = new ScriptInfo((int) $mybb->input['id']);
        if (!$this_script->remove()) {
            flash_message($lang->asb_script_delete_fail, 'error');
        } else {
            flash_message($lang->asb_script_delete_success, 'success');
            asb_cache_has_changed();
        }
    } elseif ($mybb->input['mode'] == 'export' && $mybb->input['id']) {
        $this_script = new ScriptInfo((int) $mybb->input['id']);
        if (!$this_script->export()) {
            flash_message($lang->asb_script_export_fail, 'error');
            admin_redirect($html->url(array("action" => 'manage_scripts')));
        }
        exit;
    } elseif (($mybb->input['mode'] == 'activate' || $mybb->input['mode'] == 'deactivate') && $mybb->input['id']) {
        $this_script = new ScriptInfo((int) $mybb->input['id']);
        $this_script->set('active', $mybb->input['mode'] == 'activate');
        if (!$this_script->save()) {
            $action = $mybb->input['mode'] == 'activate' ? $lang->asb_script_activate_fail : $lang->asb_script_deactivate_fail;
            flash_message($action, 'error');
        } else {
            $action = $mybb->input['mode'] == 'activate' ? $lang->asb_script_activate_success : $lang->asb_script_deactivate_success;
            flash_message($action, 'success');
            asb_cache_has_changed();
        }
        admin_redirect($html->url(array("action" => 'manage_scripts')));
    }
    $data = array("active" => 'false', "find_top" => '{$header}', "find_bottom" => '{$footer}', "replace_all" => 0, "eval" => 0, "width_left" => 160, "width_right" => 160);
    if ($mybb->input['mode'] == 'edit') {
        $this_script = new ScriptInfo((int) $mybb->input['id']);
        $detected_show = ' style="display: none;"';
        $button_text = $lang->asb_add;
        $filename = '';
        $action = $lang->asb_edit_script;
        if ($this_script->is_valid()) {
            $data = $this_script->get('data');
            $detected_info = asb_detect_script_info($data['filename']);
            $detected_show = '';
            $button_text = $lang->asb_update;
            $filename = $data['filename'];
            $action = "{$lang->asb_edit} {$data['title']}";
        }
        $lang->asb_edit_script = $action;
        $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;
        }
        $page->extra_header .= <<<EOF
\t<script type="text/javascript" src="./jscripts/peeker.js"></script>
\t<script type="text/javascript" src="jscripts/asb/asb_scripts{$min}.js"></script>
\t<script type="text/javascript">
\t<!--
\t\tASB.scripts.setCurrent('{$filename}');
\t// -->
\t</script>
\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_manage_scripts, $html->url(array("action" => 'manage_scripts')));
        $page->add_breadcrumb_item($lang->asb_edit_script);
        $page->output_header("{$lang->asb} - {$lang->asb_manage_scripts} - {$lang->asb_edit_script}");
        asb_output_tabs('asb_edit_script');
        $spinner = <<<EOF
<div class="ajax_spinners" style="display: none;">
\t<img src="../images/spinner.gif" alt="{$lang->asb_detecting} . . ."/><br /><br />
</div>
EOF;
        $form = new Form($html->url(array("action" => 'manage_scripts', "mode" => 'edit')), 'post', 'edit_script');
        $form_container = new FormContainer($lang->asb_edit_script);
        $form_container->output_row("{$lang->asb_title}:", $lang->asb_title_desc, $form->generate_text_box('title', $data['title']));
        $form_container->output_row("{$lang->asb_filename}:", $lang->asb_filename_desc, $form->generate_text_box('filename', $data['filename'], array("id" => 'filename')));
        $form_container->output_row("{$lang->asb_action}:", $lang->sprintf($lang->asb_scriptvar_generic_desc, strtolower($lang->asb_action)), "{$spinner}<div id=\"action_list\"{$detected_show}>{$detected_info['actions']}</div>" . $form->generate_text_box('script_action', $data['action'], array("id" => 'action')));
        $form_container->output_row($lang->asb_page, $lang->sprintf($lang->asb_scriptvar_generic_desc, strtolower($lang->asb_page)), $form->generate_text_box('page', $data['page']));
        $form_container->output_row($lang->asb_width_left, $lang->asb_width_left_desc, $form->generate_text_box('width_left', $data['width_left']));
        $form_container->output_row($lang->asb_width_right, $lang->asb_width_right_desc, $form->generate_text_box('width_right', $data['width_right']));
        $form_container->output_row("{$lang->asb_output_to_vars}?", $lang->sprintf($lang->asb_output_to_vars_desc, '<span style="font-family: courier; font-weight: bold; font-size: 1.2em;">$asb_left</span> and <span style="font-family: courier; font-weight: bold; font-size: 1.2em;";>$asb_right</span>'), $form->generate_yes_no_radio('eval', $data['eval'], true, array("id" => 'eval_yes', "class" => 'eval'), array("id" => 'eval_no', "class" => 'eval')), '', '', array("id" => 'var_output'));
        $form_container->output_row("{$lang->asb_template}:", $lang->asb_template_desc, "{$spinner}<div id=\"template_list\"{$detected_show}>{$detected_info['templates']}</div>" . $form->generate_text_box('template_name', $data['template_name'], array("id" => 'template_name')), '', '', array("id" => 'template_row'));
        $form_container->output_row("{$lang->asb_hook}:", $lang->asb_hook_desc, "{$spinner}<div id=\"hook_list\"{$detected_show}>{$detected_info['hooks']}</div>" . $form->generate_text_box('hook', $data['hook'], array("id" => 'hook')), '', '', array("id" => 'hook_row'));
        $form_container->output_row($lang->asb_header_search_text, $lang->asb_header_search_text_desc, $form->generate_text_area('find_top', $data['find_top'], array("id" => 'find_top', 'class' => 'codepress mybb', 'style' => 'width: 100%; height: 100px;')), '', '', array("id" => 'header_search'));
        $form_container->output_row($lang->asb_footer_search_text, $lang->asb_footer_search_text_desc, $form->generate_text_area('find_bottom', $data['find_bottom'], array("id" => 'find_bottom', 'class' => 'codepress mybb', 'style' => 'width: 100%; height: 100px;')) . $form->generate_hidden_field('id', $data['id']) . $form->generate_hidden_field('active', $data['active']) . $form->generate_hidden_field('action', 'manage_scripts') . $form->generate_hidden_field('mode', 'edit'), '', '', array("id" => 'footer_search'));
        $form_container->output_row($lang->asb_replace_template, $lang->asb_replace_template_desc, $form->generate_yes_no_radio('replace_all', $data['replace_all'], true, array("id" => 'replace_all_yes', "class" => 'replace_all'), array("id" => 'replace_all_no', "class" => 'replace_all')), '', '', array("id" => 'replace_all'));
        $form_container->output_row($lang->asb_replacement_content, $lang->asb_replacement_content_desc, $form->generate_text_area('replacement', $data['replacement'], array("id" => 'replacement', 'class' => 'codepress mybb', 'style' => 'width: 100%; height: 240px;')), '', '', array("id" => 'replace_content'));
        $form_container->end();
        $buttons = array($form->generate_submit_button($button_text, array('name' => 'add')));
        $form->output_submit_wrapper($buttons);
        $form->end();
        // output CodePress scripts if necessary
        if ($admin_options['codepress'] != 0) {
            echo <<<EOF
\t\t<script type="text/javascript">
\t\t<!--
\t\t\tEvent.observe('edit_script', 'submit', function() {
\t\t\t\tif (\$('find_top_cp')) {
\t\t\t\t\tvar area = \$('find_top_cp');
\t\t\t\t\tarea.id = 'find_top';
\t\t\t\t\tarea.value = find_top.getCode();
\t\t\t\t\tarea.disabled = false;
\t\t\t\t}

\t\t\t\tif (\$('find_bottom_cp')) {
\t\t\t\t\tvar area = \$('find_bottom_cp');
\t\t\t\t\tarea.id = 'find_bottom';
\t\t\t\t\tarea.value = find_bottom.getCode();
\t\t\t\t\tarea.disabled = false;
\t\t\t\t}

\t\t\t\tif (\$('replacement_cp')) {
\t\t\t\t\tvar area = \$('replacement_cp');
\t\t\t\t\tarea.id = 'replacement';
\t\t\t\t\tarea.value = replacement.getCode();
\t\t\t\t\tarea.disabled = false;
\t\t\t\t}
\t\t\t});
\t\t// -->
\t\t</script>
EOF;
        }
        // output the link menu and MyBB footer
        asb_output_footer('edit_scripts');
    } else {
        $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_manage_scripts);
        $page->output_header("{$lang->asb} - {$lang->asb_manage_scripts}");
        asb_output_tabs('asb_scripts');
        $new_script_url = $html->url(array("action" => 'manage_scripts', "mode" => 'edit'));
        $new_script_link = $html->link($new_script_url, $lang->asb_add_new_script, array("style" => 'font-weight: bold;', "title" => $lang->asb_add_new_script, "icon" => "{$mybb->settings['bburl']}/inc/plugins/asb/images/add.png"), array("alt" => '+', "title" => $lang->asb_add_new_script, "style" => 'margin-bottom: -3px;'));
        echo $new_script_link . '<br /><br />';
        $table = new Table();
        $table->construct_header($lang->asb_title, array("width" => '16%'));
        $table->construct_header($lang->asb_filename, array("width" => '16%'));
        $table->construct_header($lang->asb_action, array("width" => '7%'));
        $table->construct_header($lang->asb_page, array("width" => '7%'));
        $table->construct_header($lang->asb_template, array("width" => '18%'));
        $table->construct_header($lang->asb_hook, array("width" => '20%'));
        $table->construct_header($lang->asb_status, array("width" => '7%'));
        $table->construct_header($lang->asb_controls, array("width" => '8%'));
        $query = $db->simple_select('asb_script_info', '*', '', array("order_by" => 'title', "order_dir" => 'ASC'));
        if ($db->num_rows($query) > 0) {
            while ($data = $db->fetch_array($query)) {
                $edit_url = $html->url(array("action" => 'manage_scripts', "mode" => 'edit', "id" => $data['id']));
                $activate_url = $html->url(array("action" => 'manage_scripts', "mode" => 'activate', "id" => $data['id']));
                $deactivate_url = $html->url(array("action" => 'manage_scripts', "mode" => 'deactivate', "id" => $data['id']));
                $activate_link = $html->link($activate_url, $lang->asb_inactive, array("style" => 'font-weight: bold; color: red;', "title" => $lang->asb_inactive_desc));
                $deactivate_link = $html->link($deactivate_url, $lang->asb_active, array("style" => 'font-weight: bold; color: green', "title" => $lang->asb_active_desc));
                $none = <<<EOF
<span style="color: gray;"><em>{$lang->asb_none}</em></span>
EOF;
                $table->construct_cell($html->link($edit_url, $data['title'], array("style" => 'font-weight: bold;')));
                $table->construct_cell($data['filename']);
                $table->construct_cell($data['action'] ? $data['action'] : $none);
                $table->construct_cell($data['page'] ? $data['page'] : $none);
                $table->construct_cell($data['template_name'] ? $data['template_name'] : $none);
                $table->construct_cell($data['hook'] ? $data['hook'] : $none);
                $table->construct_cell($data['active'] ? $deactivate_link : $activate_link);
                // options popup
                $popup = new PopupMenu("script_{$data['id']}", $lang->asb_options);
                // edit
                $popup->add_item($lang->asb_edit, $edit_url);
                // export
                $popup->add_item($lang->asb_custom_export, $html->url(array("action" => 'manage_scripts', "mode" => 'export', "id" => $data['id'])));
                // delete
                $popup->add_item($lang->asb_delete, $html->url(array("action" => 'manage_scripts', "mode" => 'delete', "id" => $data['id'])), "return confirm('{$lang->asb_script_del_warning}');");
                // popup cell
                $table->construct_cell($popup->fetch());
                $table->construct_row();
            }
        } else {
            $table->construct_cell("<span style=\"color: gray;\"><em>{$lang->asb_no_scripts}</em></span>", array("colspan" => 8));
            $table->construct_row();
        }
        $table->output($lang->asb_script_info);
        $form = new Form($html->url(array("action" => 'manage_scripts', "mode" => 'import')), 'post', '', 1);
        $form_container = new FormContainer($lang->asb_custom_import);
        $form_container->output_row($lang->asb_custom_import_select_file, '', $form->generate_file_upload_box('file'));
        $form_container->end();
        $import_buttons[] = $form->generate_submit_button($lang->asb_custom_import, array('name' => 'import'));
        $form->output_submit_wrapper($import_buttons);
        $form->end();
        // output the link menu and MyBB footer
        asb_output_footer('manage_scripts');
    }
}