Exemplo n.º 1
0
function asb_admin()
{
    // globalize as needed to save wasted work
    global $page;
    if ($page->active_action != 'asb') {
        // not our turn
        return false;
    }
    // now load up, this is our time
    global $mybb, $lang, $html, $scripts, $all_scripts, $min;
    if (!$lang->asb) {
        $lang->load('asb');
    }
    if ($mybb->settings['asb_minify_js']) {
        $min = '.min';
    }
    // a few general functions and classes for the ACP side
    require_once MYBB_ROOT . 'inc/plugins/asb/classes/acp.php';
    // URL, link and image markup generator
    $html = new HTMLGenerator(ASB_URL, array('addon', 'pos', 'topic', 'ajax'));
    $scripts = asb_get_all_scripts();
    if (is_array($scripts) && !empty($scripts)) {
        foreach ($scripts as $filename => $script) {
            $all_scripts[$filename] = $script['title'];
        }
    } else {
        $scripts = $all_scripts = array();
    }
    // if there is an existing function for the action
    $page_function = 'asb_admin_' . $mybb->input['action'];
    if (function_exists($page_function)) {
        // run it
        $page_function();
    } else {
        // default to the main page
        asb_admin_manage_sideboxes();
    }
    // get out
    exit;
}
Exemplo n.º 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');
                }
            }
        }
    }
}