if ($vbulletin->GPC['parentid'] == $vbulletin->GPC['dostyleid']) { print_stop_message('cant_parent_style_to_self'); } $ts_info = $db->query_first("\n\t\tSELECT styleid, title, parentlist\n\t\tFROM " . TABLE_PREFIX . "style WHERE styleid = " . $vbulletin->GPC['parentid'] . "\n\t"); $parents = explode(',', $ts_info['parentlist']); foreach ($parents as $childid) { if ($childid == $vbulletin->GPC['dostyleid']) { print_stop_message('cant_parent_x_to_child'); } } // end Sanity check $db->query_write("\n\t\tUPDATE " . TABLE_PREFIX . "style\n\t\tSET title = '" . $db->escape_string($vbulletin->GPC['title']) . "',\n\t\tparentid = " . $vbulletin->GPC['parentid'] . ",\n\t\tuserselect = " . $vbulletin->GPC['userselect'] . ",\n\t\tdisplayorder = " . $vbulletin->GPC['displayorder'] . "\n\t\tWHERE styleid = " . $vbulletin->GPC['dostyleid'] . "\n\t"); ($hook = vBulletinHook::fetch_hook('admin_style_save')) ? eval($hook) : false; build_style_datastore(); if ($vbulletin->GPC['parentid'] != $vbulletin->GPC['oldparentid']) { build_template_parentlists(); print_rebuild_style($vbulletin->GPC['dostyleid'], $vbulletin->GPC['title'], 1, 1, 1, 1); print_cp_redirect("template.php?" . $vbulletin->session->vars['sessionurl'] . "do=modify&expandset=" . $vbulletin->GPC['dostyleid'] . "&modify&group=" . $vbulletin->GPC['group'], 1); } else { define('CP_REDIRECT', "template.php?do=modify&expandset=" . $vbulletin->GPC['dostyleid'] . "&modify&group=" . $vbulletin->GPC['group']); print_stop_message('saved_style_x_successfully', $vbulletin->GPC['title']); } } // ############################################################################# // form to edit a style if ($_REQUEST['do'] == 'editstyle') { $vbulletin->input->clean_array_gpc('r', array('dostyleid' => TYPE_INT)); $style = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "style WHERE styleid = " . $vbulletin->GPC['dostyleid']); print_form_header('template', 'updatestyle'); construct_hidden_code('dostyleid', $vbulletin->GPC['dostyleid']); construct_hidden_code('oldparentid', $style['parentid']);
/** * Builds all data from the template table into the fields in the style table * * @param boolean If true, will drop the template table and rebuild, so that template ids are renumbered from zero * @param boolean If true, will fix styles with no parent style specified * @param string If set, will redirect to specified URL on completion */ function build_all_styles($renumber = 0, $install = 0, $goto = '') { global $vbulletin, $template_table_query, $template_table_fields, $vbphrase; // ----------------------------------------------------------------------------- // ----------------------------------------------------------------------------- // this bit of text is used for upgrade scripts where the phrase system // is not available it should NOT be converted into phrases!!! $phrases = array('master_style' => 'MASTER STYLE', 'done' => 'Done', 'style' => 'Style', 'styles' => 'Styles', 'templates' => 'Templates', 'css' => 'CSS', 'stylevars' => 'Stylevars', 'replacement_variables' => 'Replacement Variables', 'controls' => 'Controls', 'rebuild_style_information' => 'Rebuild Style Information', 'updating_style_information_for_each_style' => 'Updating style information for each style', 'updating_styles_with_no_parents' => 'Updating style sets with no parent information', 'updated_x_styles' => 'Updated %1$s Styles', 'no_styles_needed_updating' => 'No Styles Needed Updating'); foreach ($phrases as $key => $val) { if (!isset($vbphrase["{$key}"])) { $vbphrase["{$key}"] = $val; } } // ----------------------------------------------------------------------------- // ----------------------------------------------------------------------------- if (!empty($goto)) { $form_tags = true; } echo "<!--<p> </p>-->\n\t<blockquote>" . iif($form_tags, "<form>") . "<div class=\"tborder\">\n\t<div class=\"tcat\" style=\"padding:4px\" align=\"center\"><b>" . $vbphrase['rebuild_style_information'] . "</b></div>\n\t<div class=\"alt1\" style=\"padding:4px\">\n<blockquote>\n\t"; vbflush(); // useful for restoring utterly broken (or pre vb3) styles if ($install) { echo "<p><b>" . $vbphrase['updating_styles_with_no_parents'] . "</b></p>\n<ul class=\"smallfont\">\n"; vbflush(); $vbulletin->db->query_write("\n\t\t\tUPDATE " . TABLE_PREFIX . "style\n\t\t\tSET parentid = -1,\n\t\t\tparentlist = CONCAT(styleid,',-1')\n\t\t\tWHERE parentid = 0\n\t\t"); $affected = $vbulletin->db->affected_rows(); if ($affected) { echo "<li>" . construct_phrase($vbphrase['updated_x_styles'], $affected) . "</li>\n"; vbflush(); } else { echo "<li>" . $vbphrase['no_styles_needed_updating'] . "</li>\n"; vbflush(); } echo "</ul>\n"; vbflush(); } // creates a temporary table in order to renumber all templates from 1 to n sequentially if ($renumber) { echo "<p><b>" . $vbphrase['updating_template_ids'] . "</b></p>\n<ul class=\"smallfont\">\n"; vbflush(); $vbulletin->db->query_write("DROP TABLE IF EXISTS " . TABLE_PREFIX . "template_temp"); $vbulletin->db->query_write($template_table_query); echo "<li>" . $vbphrase['temporary_template_table_created'] . "</li>\n"; vbflush(); /*insert query*/ $vbulletin->db->query_write("\n\t\t\tINSERT INTO " . TABLE_PREFIX . "template_temp\n\t\t\t({$template_table_fields})\n\t\t\tSELECT {$template_table_fields} FROM " . TABLE_PREFIX . "template ORDER BY styleid, templatetype, title\n\t\t"); $rows = $vbulletin->db->affected_rows(); echo "<li>" . construct_phrase($vbphrase['temporary_template_table_populated_with_x_templates'], $rows) . "</li>\n"; vbflush(); $vbulletin->db->query_write("DROP TABLE " . TABLE_PREFIX . "template"); echo "<li>" . $vbphrase['old_template_table_dropped'] . "</li>\n"; vbflush(); $vbulletin->db->query_write("ALTER TABLE " . TABLE_PREFIX . "template_temp RENAME " . TABLE_PREFIX . "template"); echo "<li>" . $vbphrase['temporary_template_table_renamed'] . "</li>\n"; vbflush(); echo "</ul>\n"; vbflush(); } // the main bit. echo "<p><b>" . $vbphrase['updating_style_information_for_each_style'] . "</b></p>\n"; vbflush(); build_template_parentlists(); $styleactions = array('docss' => 1, 'dostylevars' => 1, 'doreplacements' => 1, 'doposteditor' => 1); if (defined('NO_POST_EDITOR_BUILD')) { $styleactions['doposteditor'] = 0; } build_style(-1, $vbphrase['master_style'], $styleactions); echo "</blockquote></div>"; if ($form_tags) { echo "\n\t\t<div class=\"tfoot\" style=\"padding:4px\" align=\"center\">\n\t\t<input type=\"button\" class=\"button\" value=\" " . $vbphrase['done'] . " \" onclick=\"window.location='{$goto}';\" />\n\t\t</div>"; } echo "</div>" . iif($form_tags, "</form>") . "</blockquote>\n\t"; vbflush(); build_style_datastore(); }
/** * Builds all data from the template table into the fields in the style table * * @param boolean If true, will drop the template table and rebuild, so that template ids are renumbered from zero * @param boolean If true, will fix styles with no parent style specified * @param boolean If true, reset the master cache */ public function buildAllStyles($renumber = 0, $install = 0, $resetcache = false) { $vbphrase = vB_Api::instanceInternal('phrase')->fetch(array('master_style')); // creates a temporary table in order to renumber all templates from 1 to n sequentially if ($renumber) { vB::getDbAssertor()->assertQuery('template_table_query_drop'); vB::getDbAssertor()->assertQuery('template_table_query'); /*insert query*/ vB::getDbAssertor()->assertQuery('template_table_query_insert'); vB::getDbAssertor()->assertQuery('template_drop'); vB::getDbAssertor()->assertQuery('template_table_query_alter'); } require_once DIR . '/includes/adminfunctions_template.php'; build_template_parentlists(); $styleactions = array('docss' => 1, 'dostylevars' => 1, 'doreplacements' => 1, 'doposteditor' => 1); $this->buildStyle(-1, $vbphrase['master_style'], $styleactions, $resetcache); $this->buildStyleDatastore(); return true; }
/** * Update style * * @param integer $dostyleid Style ID to be updated. * @param string $title Style title. * @param integer $parentid New parent style ID for the style. * @param boolean $userselect Whether user is able to choose the style. * @param integer $displayorder Display order of the style. * @param boolean $rebuild Whether to rebuild style * @param string $guid Theme GUID * @param binary $icon Theme icon * @param boolean $iconRemove Whether to remove the current icon (if there is one, and we're not uploading a new one) * @param binary $previewImage Theme preview image * @param boolean $previewImageRemove Whether to remove the current preview image (if there is one, and we're not uploading a new one) */ public function updateStyle($dostyleid, $title, $parentid, $userselect, $displayorder, $rebuild = false, $guid = '', $icon = '', $iconRemove = false, $previewImage = '', $previewImageRemove = false) { if (!vB::getUserContext()->hasAdminPermission('canadminstyles')) { throw new vB_Exception_Api('no_permission'); } $vboptions = vB::getDatastore()->getValue('options'); if ($vboptions['styleid'] == $dostyleid) { // If a style is default style, we should always allow user to select it. $userselect = 1; } if (!$title) { throw new vB_Exception_Api('please_complete_required_fields'); } // SANITY CHECK (prevent invalid nesting) if ($parentid == $dostyleid) { throw new vB_Exception_Api('cant_parent_style_to_self'); } $parents = array(); if ($parentid != -1) { $ts_info = $this->library->fetchStyleByID($parentid); $parents = explode(',', $ts_info['parentlist']); } foreach ($parents as $childid) { if ($childid == $dostyleid) { throw new vB_Exception_Api('cant_parent_x_to_child', array('style')); } } // end Sanity check vB::getDbAssertor()->update('style', array('title' => $title, 'parentid' => $parentid, 'userselect' => intval($userselect), 'displayorder' => $displayorder), array('styleid' => $dostyleid)); // add theme data $this->addThemeData($dostyleid, $guid, $icon, $iconRemove, $previewImage, $previewImageRemove); if ($rebuild) { require_once DIR . '/includes/adminfunctions_template.php'; build_template_parentlists(); $this->buildStyle($dostyleid, $title, array('docss' => 1, 'dostylevars' => 1, 'doreplacements' => 1, 'doposteditor' => 1), false); } $this->library->buildStyleDatastore(); return true; }
} } if ($vbulletin->GPC['parentid'] < 0) { $mastertype = $vbulletin->GPC['parentid'] == -2 ? 'mobile' : 'standard'; } else { $mastertype = $ts_info['type']; } if ($mastertype != $style['type']) { print_stop_message('cant_move_style_to_another_master'); } // end Sanity check $db->query_write("\n\t\tUPDATE " . TABLE_PREFIX . "style\n\t\tSET\n\t\t\ttitle = '" . $db->escape_string($vbulletin->GPC['title']) . "',\n\t\t\tparentid = " . $vbulletin->GPC['parentid'] . ",\n\t\t\tuserselect = " . $vbulletin->GPC['userselect'] . ",\n\t\t\tdisplayorder = " . $vbulletin->GPC['displayorder'] . "\n\t\tWHERE\n\t\t\tstyleid = " . $vbulletin->GPC['dostyleid'] . "\n\t"); ($hook = vBulletinHook::fetch_hook('admin_style_save')) ? eval($hook) : false; build_style_datastore(); if ($vbulletin->GPC['parentid'] != $vbulletin->GPC['oldparentid']) { build_template_parentlists($mastertype); print_rebuild_style($vbulletin->GPC['dostyleid'], $vbulletin->GPC['title'], 1, 1, 1, 1); print_cp_redirect("template.php?" . $vbulletin->session->vars['sessionurl'] . "do=modify&expandset=" . $vbulletin->GPC['dostyleid'] . "&modify&group=" . $vbulletin->GPC['group'], 1); } else { define('CP_REDIRECT', "template.php?do=modify&expandset=" . $vbulletin->GPC['dostyleid'] . "&modify&group=" . $vbulletin->GPC['group']); print_stop_message('saved_style_x_successfully', $vbulletin->GPC['title']); } } // ############################################################################# // form to edit a style if ($_REQUEST['do'] == 'editstyle') { $vbulletin->input->clean_array_gpc('r', array('dostyleid' => TYPE_INT)); $style = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "style WHERE styleid = " . $vbulletin->GPC['dostyleid']); print_form_header('template', 'updatestyle'); construct_hidden_code('dostyleid', $vbulletin->GPC['dostyleid']); construct_hidden_code('oldparentid', $style['parentid']);
/** * Builds all data from the template table into the fields in the style table * * @param boolean If true, will drop the template table and rebuild, so that template ids are renumbered from zero * @param boolean If true, will fix styles with no parent style specified * @param string If set, will redirect to specified URL on completion * @param boolean If true, reset the master cache * @param boolean Whether to print status/edit information */ function build_all_styles($renumber = 0, $install = 0, $goto = '', $resetcache = false, $printInfo = true) { // ----------------------------------------------------------------------------- // ----------------------------------------------------------------------------- // this bit of text is used for upgrade scripts where the phrase system // is not available it should NOT be converted into phrases!!! $phrases = array('master_style' => 'MASTER STYLE', 'done' => 'Done', 'style' => 'Style', 'styles' => 'Styles', 'templates' => 'Templates', 'css' => 'CSS', 'stylevars' => 'Stylevars', 'replacement_variables' => 'Replacement Variables', 'controls' => 'Controls', 'rebuild_style_information' => 'Rebuild Style Information', 'updating_style_information_for_each_style' => 'Updating style information for each style', 'updating_styles_with_no_parents' => 'Updating style sets with no parent information', 'updated_x_styles' => 'Updated %1$s Styles', 'no_styles_needed_updating' => 'No Styles Needed Updating'); $vbphrase = vB_Api::instanceInternal('phrase')->fetch($phrases); foreach ($phrases as $key => $val) { if (!isset($vbphrase["{$key}"])) { $vbphrase["{$key}"] = $val; } } // ----------------------------------------------------------------------------- // ----------------------------------------------------------------------------- if (!empty($goto)) { $form_tags = true; } if ($printInfo and (VB_AREA != 'Upgrade' and VB_AREA != 'Install')) { echo "<!--<p> </p>-->\n\t\t<blockquote>" . iif($form_tags, "<form>") . "<div class=\"tborder\">\n\t\t<div class=\"tcat\" style=\"padding:4px\" align=\"center\"><b>" . $vbphrase['rebuild_style_information'] . "</b></div>\n\t\t<div class=\"alt1\" style=\"padding:4px\">\n<blockquote>\n\t\t"; vbflush(); } // useful for restoring utterly broken (or pre vb3) styles if ($install) { if ($printInfo and (VB_AREA != 'Upgrade' and VB_AREA != 'Install')) { echo "<p><b>" . $vbphrase['updating_styles_with_no_parents'] . "</b></p>\n<ul class=\"smallfont\">\n"; vbflush(); } vB::getDbAssertor()->assertQuery('updt_style_parentlist'); } // creates a temporary table in order to renumber all templates from 1 to n sequentially if ($renumber) { if ($printInfo and (VB_AREA != 'Upgrade' and VB_AREA != 'Install')) { echo "<p><b>" . $vbphrase['updating_template_ids'] . "</b></p>\n<ul class=\"smallfont\">\n"; vbflush(); } vB::getDbAssertor()->assertQuery('dropTableBlogTrackbackCount', array('tablename' => 'template_temp')); if ($printInfo and (VB_AREA != 'Upgrade' and VB_AREA != 'Install')) { echo "<li>" . $vbphrase['temporary_template_table_created'] . "</li>\n"; vbflush(); } /*insert query*/ vB::getDbAssertor()->assertQuery('template_table_query_insert'); vB::getDbAssertor()->assertQuery('dropTableBlogTrackbackCount', array('tablename' => 'template')); if ($printInfo and (VB_AREA != 'Upgrade' and VB_AREA != 'Install')) { echo "<li>" . $vbphrase['old_template_table_dropped'] . "</li>\n"; vbflush(); } vB::getDbAssertor()->assertQuery('template_table_query_alter'); if ($printInfo and (VB_AREA != 'Upgrade' and VB_AREA != 'Install')) { echo "<li>" . $vbphrase['temporary_template_table_renamed'] . "</li>\n"; vbflush(); echo "</ul>\n"; vbflush(); } } if ($printInfo and (VB_AREA != 'Upgrade' and VB_AREA != 'Install')) { // the main bit. echo "<p><b>" . $vbphrase['updating_style_information_for_each_style'] . "</b></p>\n"; vbflush(); } build_template_parentlists(); $styleactions = array('docss' => 1, 'dostylevars' => 1, 'doreplacements' => 1, 'doposteditor' => 1); if (defined('NO_POST_EDITOR_BUILD')) { $styleactions['doposteditor'] = 0; } if ($error = build_style(-1, $vbphrase['master_style'], $styleactions, '', '', $resetcache, $printInfo)) { return $error; } if ($printInfo and (VB_AREA != 'Upgrade' and VB_AREA != 'Install')) { echo "</blockquote></div>"; if ($form_tags) { echo "\n\t\t\t<div class=\"tfoot\" style=\"padding:4px\" align=\"center\">\n\t\t\t<input type=\"button\" class=\"button\" value=\" " . $vbphrase['done'] . " \" onclick=\"window.location='{$goto}';\" />\n\t\t\t</div>"; } echo "</div>" . iif($form_tags, "</form>") . "</blockquote>\n\t\t"; vbflush(); } vB_Library::instance('Style')->buildStyleDatastore(); }