Beispiel #1
0
/**
 * Install our theme
 */
function insert_templates()
{
    global $mybb, $output, $cache, $db, $lang;
    require MYBB_ROOT . 'inc/config.php';
    $db = db_connection($config);
    require_once MYBB_ROOT . 'inc/class_datacache.php';
    $cache = new datacache();
    $output->print_header($lang->theme_installation, 'theme');
    echo $lang->theme_step_importing;
    $db->delete_query("themes");
    $db->delete_query("templates");
    $db->delete_query("themestylesheets");
    my_rmdir_recursive(MYBB_ROOT . "cache/themes", array(MYBB_ROOT . "cache/themes/index.html"));
    $insert_array = array('title' => 'Default Templates');
    $templateset = $db->insert_query("templatesets", $insert_array);
    $contents = @file_get_contents(INSTALL_ROOT . 'resources/mybb_theme.xml');
    if (!empty($mybb->config['admin_dir']) && file_exists(MYBB_ROOT . $mybb->config['admin_dir'] . "/inc/functions_themes.php")) {
        require_once MYBB_ROOT . $mybb->config['admin_dir'] . "/inc/functions.php";
        require_once MYBB_ROOT . $mybb->config['admin_dir'] . "/inc/functions_themes.php";
    } elseif (file_exists(MYBB_ROOT . "admin/inc/functions_themes.php")) {
        require_once MYBB_ROOT . "admin/inc/functions.php";
        require_once MYBB_ROOT . "admin/inc/functions_themes.php";
    } else {
        $output->print_error("Please make sure your admin directory is uploaded correctly.");
    }
    $theme_id = import_theme_xml($contents, array("templateset" => -2, "version_compat" => 1));
    $tid = build_new_theme("Default", null, $theme_id);
    // Update our properties template set to the correct one
    $query = $db->simple_select("themes", "stylesheets, properties", "tid='{$tid}'", array('limit' => 1));
    $theme = $db->fetch_array($query);
    $properties = my_unserialize($theme['properties']);
    $stylesheets = my_unserialize($theme['stylesheets']);
    $properties['templateset'] = $templateset;
    unset($properties['inherited']['templateset']);
    // 1.8: Stylesheet Colors
    $contents = @file_get_contents(INSTALL_ROOT . 'resources/mybb_theme_colors.xml');
    require_once MYBB_ROOT . "inc/class_xml.php";
    $parser = new XMLParser($contents);
    $tree = $parser->get_tree();
    if (is_array($tree) && is_array($tree['colors'])) {
        if (is_array($tree['colors']['scheme'])) {
            foreach ($tree['colors']['scheme'] as $tag => $value) {
                $exp = explode("=", $value['value']);
                $properties['colors'][$exp[0]] = $exp[1];
            }
        }
        if (is_array($tree['colors']['stylesheets'])) {
            $count = count($properties['disporder']) + 1;
            foreach ($tree['colors']['stylesheets']['stylesheet'] as $stylesheet) {
                $new_stylesheet = array("name" => $db->escape_string($stylesheet['attributes']['name']), "tid" => $tid, "attachedto" => $db->escape_string($stylesheet['attributes']['attachedto']), "stylesheet" => $db->escape_string($stylesheet['value']), "lastmodified" => TIME_NOW, "cachefile" => $db->escape_string($stylesheet['attributes']['name']));
                $sid = $db->insert_query("themestylesheets", $new_stylesheet);
                $css_url = "css.php?stylesheet={$sid}";
                $cached = cache_stylesheet($tid, $stylesheet['attributes']['name'], $stylesheet['value']);
                if ($cached) {
                    $css_url = $cached;
                }
                // Add to display and stylesheet list
                $properties['disporder'][$stylesheet['attributes']['name']] = $count;
                $stylesheets[$stylesheet['attributes']['attachedto']]['global'][] = $css_url;
                ++$count;
            }
        }
    }
    $db->update_query("themes", array("def" => 1, "properties" => $db->escape_string(my_serialize($properties)), "stylesheets" => $db->escape_string(my_serialize($stylesheets))), "tid = '{$tid}'");
    echo $lang->theme_step_imported;
    $output->print_footer('configuration');
}
function insert_templates()
{
    global $output, $cache, $db, $lang;
    require MYBB_ROOT . 'inc/config.php';
    $db = db_connection($config);
    require_once MYBB_ROOT . 'inc/class_datacache.php';
    $cache = new datacache();
    $output->print_header($lang->theme_installation, 'theme');
    echo $lang->theme_step_importing;
    $db->delete_query("themes");
    $db->delete_query("templates");
    $db->delete_query("themestylesheets");
    my_rmdir_recursive(MYBB_ROOT . "cache/themes", array(MYBB_ROOT . "cache/themes/index.html"));
    $insert_array = array('title' => 'Default Templates');
    $templateset = $db->insert_query("templatesets", $insert_array);
    $contents = @file_get_contents(INSTALL_ROOT . 'resources/mybb_theme.xml');
    if (file_exists(MYBB_ROOT . $mybb->config['admin_dir'] . "/inc/functions_themes.php")) {
        require_once MYBB_ROOT . $mybb->config['admin_dir'] . "/inc/functions.php";
        require_once MYBB_ROOT . $mybb->config['admin_dir'] . "/inc/functions_themes.php";
    } elseif (file_exists(MYBB_ROOT . "admin/inc/functions_themes.php")) {
        require_once MYBB_ROOT . "admin/inc/functions.php";
        require_once MYBB_ROOT . "admin/inc/functions_themes.php";
    } else {
        $output->print_error("Please make sure your admin directory is uploaded correctly.");
    }
    $theme_id = import_theme_xml($contents, array("templateset" => -2, "version_compat" => 1));
    $tid = build_new_theme("Default", null, $theme_id);
    // Update our properties template set to the correct one
    $query = $db->simple_select("themes", "properties", "tid='{$tid}'", array('limit' => 1));
    $properties = unserialize($db->fetch_field($query, "properties"));
    $properties['templateset'] = $templateset;
    unset($properties['inherited']['templateset']);
    $db->update_query("themes", array("def" => 1, "properties" => $db->escape_string(serialize($properties))), "tid='{$tid}'");
    echo $lang->theme_step_imported;
    $output->print_footer('configuration');
}
Beispiel #3
0
function upgradethemes()
{
    global $output, $db, $system_upgrade_detail, $lang, $mybb;
    $output->print_header($lang->upgrade_templates_reverted);
    $charset = $db->build_create_table_collation();
    if ($system_upgrade_detail['revert_all_templates'] > 0) {
        $db->drop_table("templates");
        $db->write_query("CREATE TABLE " . TABLE_PREFIX . "templates (\n\t\t  tid int unsigned NOT NULL auto_increment,\n\t\t  title varchar(120) NOT NULL default '',\n\t\t  template text NOT NULL,\n\t\t  sid int(10) NOT NULL default '0',\n\t\t  version varchar(20) NOT NULL default '0',\n\t\t  status varchar(10) NOT NULL default '',\n\t\t  dateline int(10) NOT NULL default '0',\n\t\t  PRIMARY KEY  (tid)\n\t\t) ENGINE=MyISAM{$charset};");
    }
    if ($system_upgrade_detail['revert_all_themes'] > 0) {
        $db->drop_table("themes");
        $db->write_query("CREATE TABLE " . TABLE_PREFIX . "themes (\n\t\t tid smallint unsigned NOT NULL auto_increment,\n\t\t name varchar(100) NOT NULL default '',\n\t\t pid smallint unsigned NOT NULL default '0',\n\t\t def smallint(1) NOT NULL default '0',\n\t\t properties text NOT NULL,\n\t\t stylesheets text NOT NULL,\n\t\t allowedgroups text NOT NULL,\n\t\t PRIMARY KEY (tid)\n\t\t) ENGINE=MyISAM{$charset};");
        $db->drop_table("themestylesheets");
        $db->write_query("CREATE TABLE " . TABLE_PREFIX . "themestylesheets(\n\t\t\tsid int unsigned NOT NULL auto_increment,\n\t\t\tname varchar(30) NOT NULL default '',\n\t\t\ttid int unsigned NOT NULL default '0',\n\t\t\tattachedto text NOT NULL,\n\t\t\tstylesheet text NOT NULL,\n\t\t\tcachefile varchar(100) NOT NULL default '',\n\t\t\tlastmodified bigint(30) NOT NULL default '0',\n\t\t\tPRIMARY KEY(sid)\n\t\t) ENGINE=MyISAM{$charset};");
        $contents = @file_get_contents(INSTALL_ROOT . 'resources/mybb_theme.xml');
        if (file_exists(MYBB_ROOT . $mybb->config['admin_dir'] . "/inc/functions_themes.php")) {
            require_once MYBB_ROOT . $mybb->config['admin_dir'] . "/inc/functions.php";
            require_once MYBB_ROOT . $mybb->config['admin_dir'] . "/inc/functions_themes.php";
        } else {
            if (file_exists(MYBB_ROOT . "admin/inc/functions_themes.php")) {
                require_once MYBB_ROOT . "admin/inc/functions.php";
                require_once MYBB_ROOT . "admin/inc/functions_themes.php";
            } else {
                $output->print_error("Upewnij się, że katalog /admin został poprawnie załadowany na serwer.");
            }
        }
        import_theme_xml($contents, array("templateset" => -2, "no_templates" => 1, "version_compat" => 1));
        $tid = build_new_theme("Default", null, 1);
        $db->update_query("themes", array("def" => 1), "tid='{$tid}'");
        $db->update_query("users", array('style' => $tid));
        $db->update_query("forums", array('style' => 0));
        $db->drop_table("templatesets");
        $db->write_query("CREATE TABLE " . TABLE_PREFIX . "templatesets (\n\t\t  sid smallint unsigned NOT NULL auto_increment,\n\t\t  title varchar(120) NOT NULL default '',\n\t\t  PRIMARY KEY  (sid)\n\t\t) ENGINE=MyISAM{$charset};");
        $db->insert_query("templatesets", array('title' => 'Default Templates'));
    } else {
        // Re-import master
        $contents = @file_get_contents(INSTALL_ROOT . 'resources/mybb_theme.xml');
        if (file_exists(MYBB_ROOT . $mybb->config['admin_dir'] . "/inc/functions_themes.php")) {
            require_once MYBB_ROOT . $mybb->config['admin_dir'] . "/inc/functions_themes.php";
        } else {
            if (file_exists(MYBB_ROOT . "admin/inc/functions_themes.php")) {
                require_once MYBB_ROOT . "admin/inc/functions_themes.php";
            } else {
                $output->print_error();
            }
        }
        // Import master theme
        import_theme_xml($contents, array("tid" => 1, "no_templates" => 1, "version_compat" => 1));
    }
    $sid = -2;
    // Now deal with the master templates
    $contents = @file_get_contents(INSTALL_ROOT . 'resources/mybb_theme.xml');
    $parser = new XMLParser($contents);
    $tree = $parser->get_tree();
    $theme = $tree['theme'];
    if (is_array($theme['templates'])) {
        $templates = $theme['templates']['template'];
        foreach ($templates as $template) {
            $templatename = $db->escape_string($template['attributes']['name']);
            $templateversion = intval($template['attributes']['version']);
            $templatevalue = $db->escape_string($template['value']);
            $time = TIME_NOW;
            $query = $db->simple_select("templates", "tid", "sid='-2' AND title='" . $db->escape_string($templatename) . "'");
            $oldtemp = $db->fetch_array($query);
            if ($oldtemp['tid']) {
                $update_array = array('template' => $templatevalue, 'version' => $templateversion, 'dateline' => $time);
                $db->update_query("templates", $update_array, "title='" . $db->escape_string($templatename) . "' AND sid='-2'");
            } else {
                $insert_array = array('title' => $templatename, 'template' => $templatevalue, 'sid' => $sid, 'version' => $templateversion, 'dateline' => $time);
                $db->insert_query("templates", $insert_array);
                ++$newcount;
            }
        }
    }
    $output->print_contents($lang->upgrade_templates_reverted_success);
    $output->print_footer("rebuildsettings");
}
Beispiel #4
0
if ($mybb->input['action'] == "add") {
    $plugins->run_hooks("admin_style_themes_add");
    $query = $db->simple_select("themes", "tid, name");
    while ($theme = $db->fetch_array($query)) {
        $themes[$theme['tid']] = $theme['name'];
    }
    if ($mybb->request_method == "post") {
        if (!$mybb->input['name']) {
            $errors[] = $lang->error_missing_name;
        } else {
            if (in_array($mybb->input['name'], $themes)) {
                $errors[] = $lang->error_theme_already_exists;
            }
        }
        if (!$errors) {
            $tid = build_new_theme($mybb->input['name'], null, $mybb->input['tid']);
            $plugins->run_hooks("admin_style_themes_add_commit");
            // Log admin action
            log_admin_action(htmlspecialchars_uni($mybb->input['name']), $tid);
            flash_message($lang->success_theme_created, 'success');
            admin_redirect("index.php?module=style-themes&action=edit&tid=" . $tid);
        }
    }
    $page->add_breadcrumb_item($lang->create_new_theme, "index.php?module=style-themes&action=add");
    $page->output_header("{$lang->themes} - {$lang->create_new_theme}");
    $page->output_nav_tabs($sub_tabs, 'create_theme');
    if ($errors) {
        $page->output_inline_error($errors);
    }
    $form = new Form("index.php?module=style-themes&action=add", "post");
    $form_container = new FormContainer($lang->create_a_theme);
Beispiel #5
0
/**
 * Import an entire theme (stylesheets, properties & templates) from an XML file.
 *
 * @param string The contents of the XML file
 * @param array Optional array of options or overrides
 * @return boolean True on success, false on failure
 */
function import_theme_xml($xml, $options = array())
{
    global $mybb, $db;
    require_once MYBB_ROOT . "inc/class_xml.php";
    $parser = new XMLParser($xml);
    $tree = $parser->get_tree();
    if (!is_array($tree) || !is_array($tree['theme'])) {
        return -1;
    }
    $theme = $tree['theme'];
    // Do we have MyBB 1.2 template's we're importing?
    $css_120 = "";
    if (is_array($theme['cssbits'])) {
        $cssbits = kill_tags($theme['cssbits']);
        foreach ($cssbits as $name => $values) {
            $css_120 .= "{$name} {\n";
            foreach ($values as $property => $value) {
                if (is_array($value)) {
                    $property = str_replace('_', ':', $property);
                    $css_120 .= "}\n{$name} {$property} {\n";
                    foreach ($value as $property2 => $value2) {
                        $css_120 .= "\t{$property2}: {$value2}\n";
                    }
                } else {
                    $css_120 .= "\t{$property}: {$value}\n";
                }
            }
            $css_120 .= "}\n";
        }
    }
    if (is_array($theme['themebits'])) {
        $themebits = kill_tags($theme['themebits']);
        $theme['properties']['tag'] = 'properties';
        foreach ($themebits as $name => $value) {
            if ($name == "extracss") {
                $css_120 .= $value;
                continue;
            }
            $theme['properties'][$name] = $value;
        }
    }
    if ($css_120) {
        $css_120 = upgrade_css_120_to_140($css_120);
        $theme['stylesheets']['tag'] = 'stylesheets';
        $theme['stylesheets']['stylesheet'][0]['tag'] = 'stylesheet';
        $theme['stylesheets']['stylesheet'][0]['attributes'] = array('name' => 'global.css', 'version' => $mybb->version_code);
        $theme['stylesheets']['stylesheet'][0]['value'] = $css_120;
        unset($theme['cssbits']);
        unset($theme['themebits']);
    }
    if (is_array($theme['properties'])) {
        foreach ($theme['properties'] as $property => $value) {
            if ($property == "tag" || $property == "value") {
                continue;
            }
            $properties[$property] = $value['value'];
        }
    }
    if (empty($mybb->input['name'])) {
        $name = $theme['attributes']['name'];
    } else {
        $name = $mybb->input['name'];
    }
    $version = $theme['attributes']['version'];
    $query = $db->simple_select("themes", "tid", "name='" . $db->escape_string($name) . "'", array("limit" => 1));
    $existingtheme = $db->fetch_array($query);
    if ($options['force_name_check'] && $existingtheme['tid']) {
        return -3;
    } else {
        if ($existingtheme['tid']) {
            $options['tid'] = $existingtheme['tid'];
        }
    }
    if ($mybb->version_code != $version && $options['version_compat'] != 1) {
        return -2;
    }
    // Do we have any templates to insert?
    if (!empty($theme['templates']['template']) && !$options['no_templates']) {
        if ($options['templateset']) {
            $sid = $options['templateset'];
        } else {
            $sid = $db->insert_query("templatesets", array('title' => $db->escape_string($name) . " Templates"));
        }
        $templates = $theme['templates']['template'];
        if (is_array($templates)) {
            // Theme only has one custom template
            if (array_key_exists("attributes", $templates)) {
                $templates = array($templates);
            }
        }
        $security_check = false;
        $templatecache = array();
        foreach ($templates as $template) {
            if (check_template($template['value'])) {
                $security_check = true;
                break;
            }
            $templatecache[] = array("title" => $db->escape_string($template['attributes']['name']), "template" => $db->escape_string($template['value']), "sid" => $db->escape_string($sid), "version" => $db->escape_string($template['attributes']['version']), "dateline" => TIME_NOW);
        }
        if ($security_check == true) {
            return -4;
        }
        foreach ($templatecache as $template) {
            // PostgreSQL causes apache to stop sending content sometimes and
            // causes the page to stop loading during many queries all at one time
            if ($db->engine == "pgsql") {
                echo " ";
                flush();
            }
            $db->insert_query("templates", $template);
        }
        $properties['templateset'] = $sid;
    }
    // Not overriding an existing theme
    if (!$options['tid']) {
        // Insert the theme
        $theme_id = build_new_theme($name, $properties, $options['parent']);
    } else {
        $db->delete_query("themestylesheets", "tid='{$options['tid']}'");
        $db->update_query("themes", array("properties" => $db->escape_string(serialize($properties))), "tid='{$options['tid']}'");
        $theme_id = $options['tid'];
    }
    // If we have any stylesheets, process them
    if (!empty($theme['stylesheets']['stylesheet']) && !$options['no_stylesheets']) {
        // Are we dealing with a single stylesheet?
        if (isset($theme['stylesheets']['stylesheet']['tag'])) {
            // Trick the system into thinking we have a good array =P
            $theme['stylesheets']['stylesheet'] = array($theme['stylesheets']['stylesheet']);
        }
        foreach ($theme['stylesheets']['stylesheet'] as $stylesheet) {
            if (substr($stylesheet['attributes']['name'], -4) != ".css") {
                continue;
            }
            if (!$stylesheet['attributes']['lastmodified']) {
                $stylesheet['attributes']['lastmodified'] = TIME_NOW;
            }
            $new_stylesheet = array("name" => $db->escape_string($stylesheet['attributes']['name']), "tid" => $theme_id, "attachedto" => $db->escape_string($stylesheet['attributes']['attachedto']), "stylesheet" => $db->escape_string($stylesheet['value']), "lastmodified" => intval($stylesheet['attributes']['lastmodified']), "cachefile" => $db->escape_string($stylesheet['attributes']['name']));
            $sid = $db->insert_query("themestylesheets", $new_stylesheet);
            $css_url = "css.php?stylesheet={$sid}";
            $cached = cache_stylesheet($theme_id, $stylesheet['attributes']['name'], $stylesheet['value']);
            if ($cached) {
                $css_url = $cached;
            }
            $attachedto = $stylesheet['attributes']['attachedto'];
            if (!$attachedto) {
                $attachedto = "global";
            }
            // private.php?compose,folders|usercp.php,global|global
            $attachedto = explode("|", $attachedto);
            foreach ($attachedto as $attached_file) {
                $attached_actions = explode(",", $attached_file);
                $attached_file = array_shift($attached_actions);
                if (count($attached_actions) == 0) {
                    $attached_actions = array("global");
                }
                foreach ($attached_actions as $action) {
                    $theme_stylesheets[$attached_file][$action][] = $css_url;
                }
            }
        }
        // Now we have our list of built stylesheets, save them
        $updated_theme = array("stylesheets" => $db->escape_string(serialize($theme_stylesheets)));
        $db->update_query("themes", $updated_theme, "tid='{$theme_id}'");
    }
    update_theme_stylesheet_list($theme_id);
    // And done?
    return $theme_id;
}