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'); } } } } }
function asb_admin_manage_sideboxes() { global $mybb, $db, $page, $lang, $html, $scripts, $all_scripts, $min; $addons = asb_get_all_modules(); // if there are add-on modules if (is_array($addons)) { // display them foreach ($addons as $module) { if (!$module->is_valid()) { continue; } $id = $box_type = $module->get('base_name'); $title = $module->get('title'); $title_url = $html->url(array("action" => 'edit_box', "addon" => $box_type)); $title_link = $html->link($title_url, $title, array("class" => 'add_box_link', "title" => $lang->asb_add_new_sidebox)); // add the HTML $modules .= <<<EOF \t\t\t<div id="{$id}" class="draggable box_type"> \t\t\t\t{$title_link} \t\t\t</div> EOF; // build the JS to enable dragging $module_script .= <<<EOF \tnew Draggable('{$id}', { revert: true }); EOF; } } $custom = asb_get_all_custom(); // if there are custom boxes if (is_array($custom)) { // display them foreach ($custom as $module) { $id = $box_type = $module->get('base_name'); $title = $module->get('title'); $title_url = $html->url(array("action" => 'edit_box', "addon" => $box_type)); $title_link = $html->link($title_url, $title, array("class" => 'add_box_link', "title" => $lang->asb_add_new_sidebox)); // add the HTML $custom_boxes .= <<<EOF \t\t\t<div id="{$id}" class="draggable custom_type"> \t\t\t\t{$title_link} \t\t\t</div> EOF; // build the js to enable dragging $module_script .= <<<EOF \tnew Draggable('{$id}', { revert: true }); EOF; } } $sideboxes = asb_get_all_sideboxes($mybb->input['page']); // if there are side boxes if (is_array($sideboxes)) { // display them foreach ($sideboxes as $sidebox) { // build the side box $box = asb_build_sidebox_info($sidebox); // and sort it by position if ($sidebox->get('position')) { $right_boxes .= $box; } else { $left_boxes .= $box; } } } $page->add_breadcrumb_item($lang->asb_manage_sideboxes); // set up the page header $page->extra_header .= <<<EOF \t<script type="text/javascript"> \t<!-- \tlang.deleting_sidebox = "{$lang->asb_ajax_deleting_sidebox}"; \t// --> \t</script> \t<link rel="stylesheet" type="text/css" href="styles/asb_acp.css" media="screen" /> \t<script src="../jscripts/scriptaculous.js?load=effects,dragdrop,controls" type="text/javascript"></script> \t<script type="text/javascript" src="jscripts/peeker.js"></script> \t<script src="jscripts/imodal.js" type="text/javascript"></script> \t<link rel="stylesheet" type="text/css" href="styles/default/imodal.css"/> \t<script src="jscripts/asb/asb{$min}.js" type="text/javascript"></script> \t<script src="jscripts/asb/asb_modal{$min}.js" type="text/javascript"></script> \t<script src="jscripts/asb/asb_sideboxes{$min}.js" type="text/javascript"></script> EOF; $page->output_header("{$lang->asb} - {$lang->asb_manage_sideboxes}"); asb_output_tabs('asb'); $filter_text = ''; if ($mybb->input['page']) { $filter_text = $lang->sprintf($lang->asb_filter_label, $all_scripts[$mybb->input['page']]); } // build the display $markup = <<<EOF \t<div id="droppable_container">{$filter_text} \t\t<table width="100%" class="back_drop"> \t\t\t<tr> \t\t\t\t<td width="18%" class="column_head">{$lang->asb_addon_modules}</td> \t\t\t\t<td width="18%" class="column_head">{$lang->asb_custom}</td> \t\t\t\t<td width="30%" class="column_head">{$lang->asb_position_left}</td> \t\t\t\t<td width="30%" class="column_head">{$lang->asb_position_right}</td> \t\t\t</tr> \t\t\t<tr> \t\t\t\t<td id="addon_menu" valign="top" rowspan="2"> \t\t\t\t\t{$modules} \t\t\t\t</td> \t\t\t\t<td id="custom_menu" valign="top" rowspan="2"> \t\t\t\t\t{$custom_boxes} \t\t\t\t</td> \t\t\t\t<td id="left_column" valign="top" class="column forum_column"> \t\t\t\t\t{$left_boxes} \t\t\t\t</td> \t\t\t\t<td id="right_column" valign="top" class="column forum_column"> \t\t\t\t\t{$right_boxes} \t\t\t\t</td> \t\t\t</tr> \t\t\t<tr height="45px;"> \t\t\t\t<td id="trash_column" class="column trashcan" colspan="2"></td> \t\t\t</tr> \t\t</table> \t</div> \t<script type="text/javascript"> \t<!-- {$module_script} \t// --> \t</script> EOF; // and display it echo $markup; // output the link menu and MyBB footer asb_output_footer('manage_sideboxes'); }
function asb_activate() { // get the last cached version require_once MYBB_ROOT . 'inc/plugins/asb/functions_install.php'; // if we just upgraded . . . $old_version = asb_get_cache_version(); $info = asb_info(); if (version_compare($old_version, $info['version'], '<')) { global $lang; if (!$lang->asb) { $lang->load('asb'); } if (!class_exists('WildcardPluginInstaller')) { require_once MYBB_ROOT . 'inc/plugins/asb/classes/installer.php'; } $installer = new WildcardPluginInstaller(MYBB_ROOT . 'inc/plugins/asb/install_data.php'); $installer->install(); /* * remove a work-around for the MyBB 1.6.11 language bug * that was fixed in 1.6.12 */ if (version_compare($old_version, '2.0.5', '<')) { @unlink(MYBB_ROOT . 'inc/languages/english/admin/asb_addon.lang.php'); } /* * upgrade existing side boxes settings and removed old js files */ if (version_compare($old_version, '2.1', '<')) { require_once MYBB_ROOT . 'inc/plugins/asb/classes/forum.php'; $sideboxes = asb_get_all_sideboxes(); foreach ($sideboxes as $sidebox) { $settings = array(); foreach ((array) $sidebox->get('settings') as $name => $setting) { $settings[$name] = $setting['value']; } $sidebox->set('settings', $settings); $sidebox->save(); } for ($x = 1; $x < 4; $x++) { $module_name = 'example'; if ($x != 1) { $module_name .= $x; } $module = new Addon_type($module_name); $module->remove(); } asb_cache_has_changed(); $removed_files = array('jscripts/asb.js', 'jscripts/asb_xmlhttp.js', 'admin/jscripts/asb.js', 'admin/jscripts/asb_modal.js', 'admin/jscripts/asb_scripts.js', 'admin/jscripts/asb_sideboxes.js'); foreach ($removed_files as $file) { @unlink(MYBB_ROOT . $file); } } } asb_set_cache_version(); // change the permissions to on by default change_admin_permission('config', 'asb'); }