/** * This function updates specified settings * @param array $values * 'varname' => $vbulletin->GPC['varname'], * 'grouptitle' => $vbulletin->GPC['grouptitle'], * 'optioncode' => $vbulletin->GPC['optioncode'], * 'defaultvalue' => $vbulletin->GPC['defaultvalue'], * 'displayorder' => $vbulletin->GPC['displayorder'], * 'volatile' => $vbulletin->GPC['volatile'], * 'datatype' => $vbulletin->GPC['datatype'], * 'validationcode' => $vbulletin->GPC['validationcode'], * 'product' => $vbulletin->GPC['product'], * 'blacklist' => $vbulletin->GPC['blacklist'], * 'title' => $vbulletin->GPC['title'], * 'username' => $vbulletin->userinfo['username'], * 'description' => $vbulletin->GPC['description'] * @return array, $response */ public function updateSetting($values) { require_once DIR . '/includes/class_xml.php'; require_once DIR . '/includes/functions_file.php'; require_once DIR . '/includes/adminfunctions_options.php'; require_once DIR . '/includes/adminfunctions.php'; $response = array(); $langid = $values['volatile'] ? -1 : 0; if (defined('DEV_AUTOEXPORT') and DEV_AUTOEXPORT) { $old_setting = vB::getDbAssertor()->getRow('setting', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, 'varname' => $values['varname'])); } vB::getDbAssertor()->assertQuery('setting', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_UPDATE, 'grouptitle' => $values['grouptitle'], 'optioncode' => $values['optioncode'], 'defaultvalue' => $values['defaultvalue'], 'displayorder' => $values['displayorder'], 'volatile' => $values['volatile'], 'datatype' => $values['datatype'], 'validationcode' => $values['validationcode'], 'product' => $values['product'], 'blacklist' => $values['blacklist'], 'ispublic' => $values['ispublic'], 'adminperm' => isset($values['adminperm']) ? $values['adminperm'] : '', vB_dB_Query::CONDITIONS_KEY => array(array('field' => 'varname', 'value' => $values['varname'], 'operator' => vB_dB_Query::OPERATOR_EQ)))); $phrases = vB::getDbAssertor()->assertQuery('vBForum:phrase', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, 'languageid' => array(-1, 0), 'fieldname' => 'vbsettings', 'varname' => array("setting_" . $values['varname'] . "_title", "setting_" . $values['varname'] . "_desc"))); $full_product_info = fetch_product_list(true); $product_version = $full_product_info[$values['product']]['version']; if ($phrases and $phrases->valid()) { foreach ($phrases as $phrase) { if ($phrase['varname'] == "setting_" . $values['varname'] . "_title") { vB::getDbAssertor()->assertQuery('vBForum:phrase', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_UPDATE, 'languageid' => $langid, 'text' => $values['title'], 'product' => $values['product'], 'username' => $values['username'], 'dateline' => TIMENOW, 'version' => $product_version, vB_dB_Query::CONDITIONS_KEY => array(array('field' => 'languageid', 'value' => $phrase['languageid'], 'operator' => vB_dB_Query::OPERATOR_EQ), array('field' => 'varname', 'value' => "setting_" . $values['varname'] . "_title", 'operator' => vB_dB_Query::OPERATOR_EQ)))); } else { if ($phrase['varname'] == "setting_" . $values['varname'] . "_desc") { vB::getDbAssertor()->assertQuery('vBForum:phrase', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_UPDATE, 'languageid' => $langid, 'text' => $values['description'], 'product' => $values['product'], 'username' => $values['username'], 'dateline' => TIMENOW, 'version' => $product_version, vB_dB_Query::CONDITIONS_KEY => array(array('field' => 'languageid', 'value' => $phrase['languageid'], 'operator' => vB_dB_Query::OPERATOR_EQ), array('field' => 'varname', 'value' => "setting_" . $values['varname'] . "_desc", 'operator' => vB_dB_Query::OPERATOR_EQ)))); } } } } vB::getDatastore()->build_options(); $response['update'] = true; return $response; }
/** * Installs a product from the xml text * * This function depends on the vb class loader, which requires that the * framework init is called. * * @return bool True if the product requires a template merge, false otherwise */ function install_product($xml, $allow_overwrite) { global $vbphrase; global $vbulletin; global $db; require_once(DIR . '/includes/class_bitfield_builder.php'); require_once(DIR . '/includes/class_xml.php'); require_once(DIR . '/includes/class_block.php'); //share some code with the main xml style import require_once(DIR . '/includes/adminfunctions_template.php'); print_dots_start('<b>' . $vbphrase['importing_product'] . "</b>, $vbphrase[please_wait]", ':', 'dspan'); $xmlobj = new vB_XML_Parser($xml); if ($xmlobj->error_no == 1) { print_dots_stop(); throw new vB_Exception_AdminStopMessage('no_xml_and_no_path'); } if(!$arr = $xmlobj->parse()) { print_dots_stop(); throw new vB_Exception_AdminStopMessage( array('xml_error_x_at_line_y', $xmlobj->error_string(), $xmlobj->error_line())); } // ############## general product information $info = array( 'productid' => substr(preg_replace('#[^a-z0-9_]#', '', strtolower($arr['productid'])), 0, 25), 'title' => $arr['title'], 'description' => $arr['description'], 'version' => $arr['version'], 'active' => $arr['active'], 'url' => $arr['url'], 'versioncheckurl' => $arr['versioncheckurl'] ); if (!$info['productid']) { print_dots_stop(); if (!empty($arr['plugin'])) { throw new vB_Exception_AdminStopMessage('this_file_appears_to_be_a_plugin'); } else { throw new vB_Exception_AdminStopMessage('invalid_file_specified'); } } if (strtolower($info['productid']) == 'vbulletin') { print_dots_stop(); throw new vB_Exception_AdminStopMessage(array('product_x_installed_no_overwrite', 'vBulletin')); } // check for bitfield conflicts on install $bitfields = vB_Bitfield_Builder::return_data(); if (!$bitfields) { $bfobj =& vB_Bitfield_Builder::init(); if ($bfobj->errors) { print_dots_stop(); throw new vB_Exception_AdminStopMessage(array( 'bitfield_conflicts_x', '<li>' . implode('</li><li>', $bfobj->errors) . '</li>' )); } } // get system version info $system_versions = array( 'php' => PHP_VERSION, 'vbulletin' => $vbulletin->options['templateversion'], 'products' => fetch_product_list(true) ); $mysql_version = $db->query_first("SELECT VERSION() AS version"); $system_versions['mysql'] = $mysql_version['version']; // ############## import dependencies if (is_array($arr['dependencies']['dependency'])) { $dependencies =& $arr['dependencies']['dependency']; if (!isset($dependencies[0])) { $dependencies = array($dependencies); } $dependency_errors = array(); $ignore_dependency_errors = array(); // let's check the dependencies foreach ($dependencies AS $dependency) { // if we get an error, we haven't met this dependency // if we go through without a problem, we have automatically met // all dependencies for this "class" (mysql, php, vb, a specific product, etc) $this_dependency_met = true; // build a phrase for the version compats -- will look like (minver / maxver) if ($dependency['minversion']) { $compatible_phrase = construct_phrase( $vbphrase['compatible_starting_with_x'], htmlspecialchars_uni($dependency['minversion']) ); } else { $compatible_phrase = ''; } if ($dependency['maxversion']) { $incompatible_phrase = construct_phrase( $vbphrase['incompatible_with_x_and_greater'], htmlspecialchars_uni($dependency['maxversion']) ); } else { $incompatible_phrase = ''; } if ($compatible_phrase OR $incompatible_phrase) { $required_version_info = "($compatible_phrase"; if ($compatible_phrase AND $incompatible_phrase) { $required_version_info .= ' / '; } $required_version_info .= "$incompatible_phrase)"; } // grab the appropriate installed version string if ($dependency['dependencytype'] == 'product') { // group dependencies into types -- individual products get their own group $dependency_type_key = "product-$dependency[parentproductid]"; // undocumented feature -- you can put a producttitle attribute in a dependency so the id isn't displayed $parent_product_title = (!empty($dependency['producttitle']) ? $dependency['producttitle'] : $dependency['parentproductid']); $parent_product = $system_versions['products']["$dependency[parentproductid]"]; if (!$parent_product) { // required product is not installed $dependency_errors["$dependency_type_key"] = construct_phrase( $vbphrase['product_x_must_be_installed'], htmlspecialchars_uni($parent_product_title), $required_version_info ); continue; // can't do version checks if the product isn't installed } else if ($parent_product['active'] == 0) { // product is installed, but inactive $dependency_errors["{$dependency_type_key}-inactive"] = construct_phrase( $vbphrase['product_x_must_be_activated'], htmlspecialchars_uni($parent_product_title) ); $this_dependency_met = false; // allow version checks to continue } $sys_version_str = $parent_product['version']; $version_incompatible_phrase = 'product_incompatible_version_x_product_y'; } else { $dependency_type_key = $dependency['dependencytype']; $parent_product_title = ''; $sys_version_str = $system_versions["$dependency[dependencytype]"]; $version_incompatible_phrase = 'product_incompatible_version_x_' . $dependency['dependencytype']; } // if no version string, we are trying to do an unsupported dep check if ($sys_version_str == '') { continue; } $sys_version = fetch_version_array($sys_version_str); // error if installed version < minversion if ($dependency['minversion']) { $dep_version = fetch_version_array($dependency['minversion']); for ($i = 0; $i <= 5; $i++) { if ($sys_version["$i"] < $dep_version["$i"]) { // installed version is too old $dependency_errors["$dependency_type_key"] = construct_phrase( $vbphrase["$version_incompatible_phrase"], htmlspecialchars_uni($sys_version_str), $required_version_info, $parent_product_title ); $this_dependency_met = false; break; } else if ($sys_version["$i"] > $dep_version["$i"]) { break; } } } // error if installed version >= maxversion if ($dependency['maxversion']) { $dep_version = fetch_version_array($dependency['maxversion']); $all_equal = true; for ($i = 0; $i <= 5; $i++) { if ($sys_version["$i"] > $dep_version["$i"]) { // installed version is newer than the maxversion $dependency_errors["$dependency_type_key"] = construct_phrase( $vbphrase["$version_incompatible_phrase"], htmlspecialchars_uni($sys_version_str), $required_version_info, $parent_product_title ); $this_dependency_met = false; break; } else if ($sys_version["$i"] < $dep_version["$i"]) { // not every part is the same and since we've got less we can exit $all_equal = false; break; } else if ($sys_version["$i"] != $dep_version["$i"]) { // not every part is the same $all_equal = false; } } if ($all_equal == true) { // installed version is same as the max version, which is the first incompat version $dependency_errors["$dependency_type_key"] = construct_phrase( $vbphrase["$version_incompatible_phrase"], htmlspecialchars_uni($sys_version_str), $required_version_info, $parent_product_title ); $this_dependency_met = false; } } if ($this_dependency_met) { // we met 1 dependency for this type -- this emulates or'ing together groups $ignore_dependency_errors["$dependency_type_key"] = true; } } // for any group we met a dependency for, ignore any errors we might // have gotten for the group foreach ($ignore_dependency_errors AS $dependency_type_key => $devnull) { unset($dependency_errors["$dependency_type_key"]); } if ($dependency_errors) { $dependency_errors = array_unique($dependency_errors); $dependency_errors = '<ol><li>' . implode('</li><li>', $dependency_errors) . '</li></ol>'; print_dots_stop(); throw new vB_Exception_AdminStopMessage( array('dependencies_not_met_x', $dependency_errors)); } } // look to see if we already have this product installed if ($existingprod = $db->query_first(" SELECT * FROM " . TABLE_PREFIX . "product WHERE productid = '" . $db->escape_string($info['productid']) . "'" )) { if (!$allow_overwrite) { print_dots_stop(); throw new vB_Exception_AdminStopMessage( array('product_x_installed_no_overwrite', $info['title'])); } $active = $existingprod['active']; // not sure what we're deleting, so rebuild everything $rebuild = array( 'templates' => true, 'plugins' => true, 'phrases' => true, 'options' => true, 'cron' => true ); $installed_version = $existingprod['version']; } else { $active = ($info['active'] ? 1 : 0); $rebuild = array( 'templates' => false, 'plugins' => false, 'phrases' => false, 'options' => false, 'cron' => false ); $installed_version = null; } // ############## import install/uninstall code if (is_array($arr['codes']['code'])) { $codes =& $arr['codes']['code']; if (!isset($codes[0])) { $codes = array($codes); } // run each of the codes foreach ($codes AS $code) { // Run if: code version is * (meaning always run), no version // previously installed, or if the code is for a newer version // than is currently installed if ($code['version'] == '*' OR $installed_version === null OR is_newer_version($code['version'], $installed_version)) { eval($code['installcode']); } } // Clear routes from datastore build_datastore('routes', serialize(array()), 1); //assume that the product may have installed content types and purge the content type cache vB_Cache::instance()->purge('vb_types.types'); } // dependencies checked, install code run. Now clear out the old product info; // settings should be retained in memory already delete_product($info['productid'], false, true); if (is_array($codes)) { // we've now run all the codes, if execution is still going // then it's going to complete fully, so insert the codes foreach ($codes AS $code) { /* insert query */ $db->query_write(" INSERT INTO " . TABLE_PREFIX . "productcode (productid, version, installcode, uninstallcode) VALUES ('" . $db->escape_string($info['productid']) . "', '" . $db->escape_string($code['version']) . "', '" . $db->escape_string($code['installcode']) . "', '" . $db->escape_string($code['uninstallcode']) . "') "); } } if (is_array($dependencies)) { // dependencies met, codes run -- now we can insert the dependencies into the DB foreach ($dependencies AS $dependency) { /* insert query */ $db->query_write(" INSERT INTO " . TABLE_PREFIX . "productdependency (productid, dependencytype, parentproductid, minversion, maxversion) VALUES ('" . $db->escape_string($info['productid']) . "', '" . $db->escape_string($dependency['dependencytype']) . "', '" . $db->escape_string($dependency['parentproductid']) . "', '" . $db->escape_string($dependency['minversion']) . "', '" . $db->escape_string($dependency['maxversion']) . "') "); } } /* insert query */ $db->query_write(" INSERT INTO " . TABLE_PREFIX . "product (productid, title, description, version, active, url, versioncheckurl) VALUES ('" . $db->escape_string($info['productid']) . "', '" . $db->escape_string($info['title']) . "', '" . $db->escape_string($info['description']) . "', '" . $db->escape_string($info['version']) . "', " . intval($active) . ", '" . $db->escape_string($info['url']) . "', '" . $db->escape_string($info['versioncheckurl']) . "') "); // ############## import templates if (is_array($arr['templates']['template'])) { $querybits = array(); $querytemplates = 0; $templates =& $arr['templates']['template']; if (!isset($templates[0])) { $templates = array($templates); } foreach ($templates AS $template) { $title = $db->escape_string($template['name']); $template['template'] = $db->escape_string($template['value']); $template['username'] = $db->escape_string($template['username']); $template['templatetype'] = $db->escape_string($template['templatetype']); $template['date'] = intval($template['date']); if ($template['templatetype'] != 'template') { // template is a special template $querybits[] = "(-1, '$template[templatetype]', '$title', '$template[template]', '', $template[date], '$template[username]', '" . $db->escape_string($template['version']) . "', '" . $db->escape_string($info['productid']) . "')"; } else { // template is a standard template $querybits[] = "(-1, '$template[templatetype]', '$title', '" . $db->escape_string(compile_template($template['value'])) . "', '$template[template]', $template[date], '$template[username]', '" . $db->escape_string($template['version']) . "', '" . $db->escape_string($info['productid']) . "')"; } if (++$querytemplates % 20 == 0) { /*insert query*/ $db->query_write(" REPLACE INTO " . TABLE_PREFIX . "template (styleid, templatetype, title, template, template_un, dateline, username, version, product) VALUES " . implode(',', $querybits) . " "); $querybits = array(); } // Send some output to the browser inside this loop so certain hosts // don't artificially kill the script. See bug #34585 echo ' '; vbflush(); } // insert any remaining templates if (!empty($querybits)) { /*insert query*/ $db->query_write(" REPLACE INTO " . TABLE_PREFIX . "template (styleid, templatetype, title, template, template_un, dateline, username, version, product) VALUES " . implode(',', $querybits) . " "); } unset($querybits); $rebuild['templates'] = true; } // ############## import stylevars if (is_array($arr['stylevardfns']['stylevargroup'])) { xml_import_stylevar_definitions($arr['stylevardfns'], $info['productid']); } if (is_array($arr['stylevars']['stylevar'])) { xml_import_stylevars($arr['stylevars'], -1); } // ############## import hooks/plugins if (is_array($arr['plugins']['plugin'])) { $plugins =& $arr['plugins']['plugin']; if (!isset($plugins[0])) { $plugins = array($plugins); } foreach ($plugins AS $plugin) { $plugin['product'] = $info['productid']; unset($plugin['devkey']); $db->query_write(fetch_query_sql($plugin, 'plugin')); } $rebuild['plugins'] = true; } // ############## import phrases if (is_array($arr['phrases']['phrasetype'])) { require_once(DIR . '/includes/adminfunctions_language.php'); $master_phrasetypes = array(); $master_phrasefields = array(); foreach(fetch_phrasetypes_array(false) as $phrasetype) { $master_phrasefields["$phrasetype[fieldname]"] = true; } $phrasetypes =& $arr['phrases']['phrasetype']; if (!isset($phrasetypes[0])) { $phrasetypes = array($phrasetypes); } foreach ($phrasetypes AS $phrasetype) { if (empty($phrasetype['phrase'])) { continue; } if ($phrasetype['fieldname'] == '' OR !preg_match('#^[a-z0-9_]+$#i', $phrasetype['fieldname'])) // match a-z, A-Z, 0-9,_ only { continue; } $fieldname = $master_phrasefields["$phrasetype[fieldname]"]; if (!$fieldname) { $db->query_write(" INSERT IGNORE INTO " . TABLE_PREFIX . "phrasetype (fieldname, title, editrows, product) VALUES ('" . $db->escape_string($phrasetype['fieldname']) . "', '" . $db->escape_string($phrasetype['name']) . "', 3, '" . $db->escape_string($info['productid']) . "') "); // need to add the column to the language table as well require_once(DIR . '/includes/class_dbalter.php'); $db_alter = new vB_Database_Alter_MySQL($db); if ($db_alter->fetch_table_info('language')) { $db_alter->add_field(array( 'name' => "phrasegroup_$phrasetype[fieldname]", 'type' => 'mediumtext' )); } } $phrases =& $phrasetype['phrase']; if (!isset($phrases[0])) { $phrases = array($phrases); } $sql = array(); foreach ($phrases AS $phrase) { $sql[] = " (-1, '" . $db->escape_string($phrasetype['fieldname']) . "', '" . $db->escape_string($phrase['name']) . "', '" . $db->escape_string($phrase['value']) . "', '" . $db->escape_string($info['productid']) . "', '" . $db->escape_string($phrase['username']) . "', " . intval($phrase['date']) . ", '" . $db->escape_string($phrase['version']) . "') "; } /*insert query*/ $db->query_write(" REPLACE INTO " . TABLE_PREFIX . "phrase (languageid, fieldname, varname, text, product, username, dateline, version) VALUES " . implode(',', $sql) ); } $rebuild['phrases'] = true; } // ############## import settings if (is_array($arr['options']['settinggroup'])) { $settinggroups =& $arr['options']['settinggroup']; if (!isset($settinggroups[0])) { $settinggroups = array($settinggroups); } foreach ($settinggroups AS $group) { if (empty($group['setting'])) { continue; } // create the setting group if it doesn't already exist /*insert query*/ $db->query_write(" INSERT IGNORE INTO " . TABLE_PREFIX . "settinggroup (grouptitle, displayorder, volatile, product) VALUES ('" . $db->escape_string($group['name']) . "', " . intval($group['displayorder']) . ", 1, '" . $db->escape_string($info['productid']) . "') "); $settings =& $group['setting']; if (!isset($settings[0])) { $settings = array($settings); } $setting_bits = array(); foreach ($settings AS $setting) { if (isset($vbulletin->options["$setting[varname]"])) { $newvalue = $vbulletin->options["$setting[varname]"]; } else { $newvalue = $setting['defaultvalue']; } $setting_bits[] = "( '" . $db->escape_string($setting['varname']) . "', '" . $db->escape_string($group['name']) . "', '" . $db->escape_string(trim($newvalue)) . "', '" . $db->escape_string(trim($setting['defaultvalue'])) . "', '" . $db->escape_string(trim($setting['datatype'])) . "', '" . $db->escape_string($setting['optioncode']) . "', " . intval($setting['displayorder']) . ", " . intval($setting['advanced']) . ", 1, '" . $db->escape_string($setting['validationcode']) . "', " . intval($setting['blacklist']) . ", '" . $db->escape_string($info['productid']) . "'\n\t)"; } /*insert query*/ $db->query_write(" REPLACE INTO " . TABLE_PREFIX . "setting (varname, grouptitle, value, defaultvalue, datatype, optioncode, displayorder, advanced, volatile, validationcode, blacklist, product) VALUES " . implode(",\n\t", $setting_bits) ); } $rebuild['options'] = true; } // ############## import admin help if (is_array($arr['helptopics']['helpscript'])) { $help_scripts =& $arr['helptopics']['helpscript']; if (!isset($help_scripts[0])) { $help_scripts = array($help_scripts); } foreach ($help_scripts AS $help_script) { // Deal with single entry if (!is_array($help_script['helptopic'][0])) { $help_script['helptopic'] = array($help_script['helptopic']); } $help_sql = array(); foreach ($help_script['helptopic'] AS $topic) { $helpsql[] = " ('" . $db->escape_string($help_script['name']) . "', '" . $db->escape_string($topic['act']) . "', '" . $db->escape_string($topic['opt']) . "', " . intval($topic['disp']) . ", 1, '" . $db->escape_string($info['productid']) . "') "; } if (!empty($helpsql)) { /*insert query*/ $db->query_write(" REPLACE INTO " . TABLE_PREFIX . "adminhelp (script, action, optionname, displayorder, volatile, product) VALUES " . implode(",\n\t", $helpsql) ); } } } // ############## import cron if (is_array($arr['cronentries']['cron'])) { require_once(DIR . '/includes/functions_cron.php'); $cron_entries =& $arr['cronentries']['cron']; if (!isset($cron_entries[0])) { $cron_entries = array($cron_entries); } foreach ($cron_entries AS $cron) { $cron['varname'] = preg_replace('#[^a-z0-9_]#i', '', $cron['varname']); if (!$cron['varname']) { continue; } $cron['active'] = ($cron['active'] ? 1 : 0); $cron['loglevel'] = ($cron['loglevel'] ? 1 : 0); $scheduling = $cron['scheduling']; $scheduling['weekday'] = intval($scheduling['weekday']); $scheduling['day'] = intval($scheduling['day']); $scheduling['hour'] = intval($scheduling['hour']); $scheduling['minute'] = explode(',', preg_replace('#[^0-9,-]#i', '', $scheduling['minute'])); if (count($scheduling['minute']) == 0) { $scheduling['minute'] = array(0); } else { $scheduling['minute'] = array_map('intval', $scheduling['minute']); } /*insert query*/ $db->query_write(" REPLACE INTO " . TABLE_PREFIX . "cron (weekday, day, hour, minute, filename, loglevel, active, varname, volatile, product) VALUES ($scheduling[weekday], $scheduling[day], $scheduling[hour], '" . $db->escape_string(serialize($scheduling['minute'])) . "', '" . $db->escape_string($cron['filename']) . "', $cron[loglevel], $cron[active], '" . $db->escape_string($cron['varname']) . "', 1, '" . $db->escape_string($info['productid']) . "') "); $cronid = $db->insert_id(); // replace either inserts, or deletes+inserts if ($cronid) { build_cron_item($cronid); } $rebuild['cron'] = true; } } // ############## import faq if (is_array($arr['faqentries']['faq'])) { $faq_entries =& $arr['faqentries']['faq']; if (!isset($faq_entries[0])) { $faq_entries = array($faq_entries); } $sql = array(); foreach ($faq_entries AS $faq) { $sql[] = " ('" . $db->escape_string($faq['faqname']) . "', '" . $db->escape_string($faq['faqparent']) . "', " . intval($faq['displayorder']) . ", 1, '" . $db->escape_string($info['productid']) . "') "; } if ($sql) { /*insert query*/ $db->query_write(" REPLACE INTO " . TABLE_PREFIX . "faq (faqname, faqparent, displayorder, volatile, product) VALUES " . implode(',', $sql) . " "); } } // Check if the plugin system is disabled. If it is, enable it. if (!$vbulletin->options['enablehooks']) { $db->query_write(" UPDATE " . TABLE_PREFIX . "setting SET value = '1' WHERE varname = 'enablehooks' "); $rebuild['options'] = true; } // Now rebuild everything we need... if ($rebuild['plugins']) { vBulletinHook::build_datastore($db); if ($active) { $plugin_data = $db->query_read(" SELECT * FROM " . TABLE_PREFIX . "datastore WHERE title IN ('pluginlist', 'pluginlistadmin') "); while ($plugin_info = $db->fetch_array($plugin_data)) { if ($plugin_info['title'] == 'pluginlist') { $vbulletin->pluginlist = unserialize($plugin_info['data']); } else if ($plugin_info['title'] == 'pluginlistadmin') { $vbulletin->pluginlistadmin = unserialize($plugin_info['data']); } } // enable any hooks -- this is mainly necessary for importing templates (template_safe_functions hook) if (!defined('DISABLE_HOOKS')) { if (!empty($vbulletin->pluginlistadmin) AND is_array($vbulletin->pluginlistadmin)) { $vbulletin->pluginlist = array_merge($vbulletin->pluginlist, $vbulletin->pluginlistadmin); unset($vbulletin->pluginlistadmin); } vBulletinHook::set_pluginlist($vbulletin->pluginlist); } } } if ($rebuild['templates']) { build_all_styles(); } if ($rebuild['phrases']) { require_once(DIR . '/includes/adminfunctions_language.php'); build_language(); } if ($rebuild['options']) { build_options(); } if ($rebuild['cron']) { require_once(DIR . '/includes/functions_cron.php'); build_cron_next_run(); } build_product_datastore(); // build bitfields to remove/add this products bitfields vB_Bitfield_Builder::save($db); // reload block types $blockmanager = vB_BlockManager::create($vbulletin); $blockmanager->reloadBlockTypes(); print_dots_stop(); $info['need_merge'] = ($rebuild['templates'] AND $installed_version); return $info; }
/** * Everything that comes after the install - no reason to break this up into chunks at present * */ public function post_install() { // dependencies checked, install code run. Now clear out the old product info; // settings should be retained in memory already delete_product($this->productinfo['productid'], false, true); $codes =& $this->productobj['codes']['code']; if (!isset($codes[0])) { $codes = array($codes); } if (is_array($codes)) { // we've now run all the codes, if execution is still going // then it's going to complete fully, so insert the codes foreach ($codes as $code) { /* insert query */ $this->db->query_write("\n\t\t\t\t\tINSERT INTO " . TABLE_PREFIX . "productcode\n\t\t\t\t\t\t(productid, version, installcode, uninstallcode)\n\t\t\t\t\tVALUES\n\t\t\t\t\t\t('" . $this->db->escape_string($this->productinfo['productid']) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string($code['version']) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string($code['installcode']) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string($code['uninstallcode']) . "')\n\t\t\t\t"); } } if (is_array($this->productobj['dependencies']['dependency'])) { $dependencies =& $this->productobj['dependencies']['dependency']; if (!isset($dependencies[0])) { $dependencies = array($dependencies); } // dependencies met, codes run -- now we can insert the dependencies into the DB foreach ($dependencies as $dependency) { /* insert query */ $this->db->query_write("\n\t\t\t\t\tINSERT INTO " . TABLE_PREFIX . "productdependency\n\t\t\t\t\t\t(productid, dependencytype, parentproductid, minversion, maxversion)\n\t\t\t\t\tVALUES\n\t\t\t\t\t\t('" . $this->db->escape_string($this->productinfo['productid']) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string($dependency['dependencytype']) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string($dependency['parentproductid']) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string($dependency['minversion']) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string($dependency['maxversion']) . "')\n\t\t\t\t"); } } /* insert query */ $this->db->query_write("\n\t\t\tINSERT INTO " . TABLE_PREFIX . "product\n\t\t\t\t(productid, title, description, version, active, url, versioncheckurl)\n\t\t\tVALUES\n\t\t\t\t('" . $this->db->escape_string($this->productinfo['productid']) . "',\n\t\t\t\t'" . $this->db->escape_string($this->productinfo['title']) . "',\n\t\t\t\t'" . $this->db->escape_string($this->productinfo['description']) . "',\n\t\t\t\t'" . $this->db->escape_string($this->productinfo['version']) . "',\n\t\t\t\t" . intval($this->active) . ",\n\t\t\t\t'" . $this->db->escape_string($this->productinfo['url']) . "',\n\t\t\t\t'" . $this->db->escape_string($this->productinfo['versioncheckurl']) . "')\n\t\t"); // ############## import templates if (is_array($this->productobj['templates']['template'])) { $querybits = array(); $querytemplates = 0; $templates =& $this->productobj['templates']['template']; if (!isset($templates[0])) { $templates = array($templates); } foreach ($templates as $template) { $querybit = array('styleid' => '-1', 'title' => $template['name'], 'template' => $template['templatetype'] == 'template' ? compile_template($template['value']) : $template['value'], 'template_un' => $template['templatetype'] == 'template' ? $template['value'] : '', 'dateline' => $template['date'], 'username' => $template['username'], 'version' => $template['version'], 'product' => $template['productid']); $querybit['templatetype'] = $template['templatetype']; $querybits[] = $querybit; if (++$querytemplates % 20 == 0) { /*insert query*/ vB::getDbAssertor()->assertQuery('replaceTemplates', array('querybits' => $querybits)); $querybits = array(); } if (!defined('SUPPRESS_KEEPALIVE_ECHO')) { echo ' '; vbflush(); } } // insert any remaining templates if (!empty($querybits)) { /*insert query*/ vB::getDbAssertor()->assertQuery('replaceTemplates', array('querybits' => $querybits)); } unset($querybits); $rebuild['templates'] = true; } // ############## import stylevars if (isset($this->productobj['stylevardfns']['stylevargroup']) and is_array($this->productobj['stylevardfns']['stylevargroup'])) { xml_import_stylevar_definitions($this->productobj['stylevardfns'], $this->productinfo['productid']); } if (isset($this->productobj['stylevars']['stylevar']) and is_array($this->productobj['stylevars']['stylevar'])) { xml_import_stylevars($this->productobj['stylevars'], -1); } // ############## import hooks if (is_array($this->productobj['hooks']['hook'])) { $hooks =& $this->productobj['hooks']['hook']; if (!isset($hooks[0])) { $hooks = array($hooks); } foreach ($hooks as $hook) { $hook['product'] = $this->productinfo['productid']; $this->db->query_write(fetch_query_sql($hook, 'hook')); } $rebuild['hooks'] = true; } // ############## import phrases if (is_array($this->productobj['phrases']['phrasetype'])) { $master_phrasetypes = array(); $master_phrasefields = array(); foreach (vB_Api::instanceInternal('phrase')->fetch_phrasetypes(false) as $phrasetype) { $master_phrasefields["{$phrasetype['fieldname']}"] = true; } $phrasetypes = vB_Api::instanceInternal('phrase')->fetch_phrasetypes(false); if (!isset($phrasetypes[0])) { $phrasetypes = array($phrasetypes); } foreach ($phrasetypes as $phrasetype) { if (empty($phrasetype['phrase'])) { continue; } if ($phrasetype['fieldname'] == '' or !preg_match('#^[a-z0-9_]+$#i', $phrasetype['fieldname'])) { continue; } $fieldname = $master_phrasefields["{$phrasetype['fieldname']}"]; if (!$fieldname) { $this->db->query_write("\n\t\t\t\t\t\tINSERT IGNORE INTO " . TABLE_PREFIX . "phrasetype\n\t\t\t\t\t\t\t(fieldname, title, editrows, product)\n\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t\t('" . $this->db->escape_string($phrasetype['fieldname']) . "',\n\t\t\t\t\t\t\t'" . $this->db->escape_string($phrasetype['name']) . "',\n\t\t\t\t\t\t\t3,\n\t\t\t\t\t\t\t'" . $this->db->escape_string($this->productinfo['productid']) . "')\n\t\t\t\t\t"); // need to add the column to the language table as well require_once DIR . '/includes/class_dbalter.php'; $this->db_alter = new vB_Database_Alter_MySQL($this->db); if ($this->db_alter->fetch_table_info('language')) { $this->db_alter->add_field(array('name' => "phrasegroup_{$phrasetype['fieldname']}", 'type' => 'mediumtext')); } } $phrases =& $phrasetype['phrase']; if (!isset($phrases[0])) { $phrases = array($phrases); } $sql = array(); foreach ($phrases as $phrase) { $sql[] = "\n\t\t\t\t\t\t(-1,\n\t\t\t\t\t\t'" . $this->db->escape_string($phrasetype['fieldname']) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string($phrase['name']) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string($phrase['value']) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string($this->productinfo['productid']) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string($phrase['username']) . "',\n\t\t\t\t\t\t" . intval($phrase['date']) . ",\n\t\t\t\t\t\t'" . $this->db->escape_string($phrase['version']) . "')\n\t\t\t\t\t"; } /*insert query*/ $this->db->query_write("\n\t\t\t\t\tREPLACE INTO " . TABLE_PREFIX . "phrase\n\t\t\t\t\t\t(languageid, fieldname, varname, text, product, username, dateline, version)\n\t\t\t\t\tVALUES\n\t\t\t\t\t\t" . implode(',', $sql)); } $rebuild['phrases'] = true; } // ############## import settings if (is_array($this->productobj['options']['settinggroup'])) { $settinggroups =& $this->productobj['options']['settinggroup']; if (!isset($settinggroups[0])) { $settinggroups = array($settinggroups); } foreach ($settinggroups as $group) { if (empty($group['setting'])) { continue; } // create the setting group if it doesn't already exist /*insert query*/ $this->db->query_write("\n\t\t\t\t\tINSERT IGNORE INTO " . TABLE_PREFIX . "settinggroup\n\t\t\t\t\t\t(grouptitle, displayorder, volatile, product)\n\t\t\t\t\tVALUES\n\t\t\t\t\t\t('" . $this->db->escape_string($group['name']) . "',\n\t\t\t\t\t\t" . intval($group['displayorder']) . ",\n\t\t\t\t\t\t1,\n\t\t\t\t\t\t'" . $this->db->escape_string($this->productinfo['productid']) . "')\n\t\t\t\t"); $settings =& $group['setting']; if (!isset($settings[0])) { $settings = array($settings); } $setting_bits = array(); foreach ($settings as $setting) { if (isset($this->registry->options["{$setting['varname']}"])) { $newvalue = $this->registry->options["{$setting['varname']}"]; } else { $newvalue = $setting['defaultvalue']; } $setting_bits[] = "(\n\t\t\t\t\t\t'" . $this->db->escape_string($setting['varname']) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string($group['name']) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string(trim($newvalue)) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string(trim($setting['defaultvalue'])) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string(trim($setting['datatype'])) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string($setting['optioncode']) . "',\n\t\t\t\t\t\t" . intval($setting['displayorder']) . ",\n\t\t\t\t\t\t" . intval($setting['advanced']) . ",\n\t\t\t\t\t\t1,\n\t\t\t\t\t\t'" . $this->db->escape_string($setting['validationcode']) . "',\n\t\t\t\t\t\t" . intval($setting['blacklist']) . ",\n\t\t\t\t\t\t" . intval($setting['public']) . ",\n\t\t\t\t\t\t'" . $this->db->escape_string($this->productinfo['productid']) . "'\n\t)"; } /*insert query*/ $this->db->query_write("\n\t\t\t\t\tREPLACE INTO " . TABLE_PREFIX . "setting\n\t\t\t\t\t\t(varname, grouptitle, value, defaultvalue, datatype, optioncode, displayorder, advanced, volatile, validationcode, blacklist, ispublic, product)\n\t\t\t\t\tVALUES\n\t\t\t\t\t\t" . implode(",\n\t", $setting_bits)); } $rebuild['options'] = true; } // ############## import admin help if (isset($this->productobj['helptopics']['helpscript']) and is_array($this->productobj['helptopics']['helpscript'])) { $help_scripts =& $this->productobj['helptopics']['helpscript']; if (!isset($help_scripts[0])) { $help_scripts = array($help_scripts); } foreach ($help_scripts as $help_script) { // Deal with single entry if (!is_array($help_script['helptopic'][0])) { $help_script['helptopic'] = array($help_script['helptopic']); } $help_sql = array(); foreach ($help_script['helptopic'] as $topic) { $helpsql[] = "\n\t\t\t\t\t\t('" . $this->db->escape_string($help_script['name']) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string($topic['act']) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string($topic['opt']) . "',\n\t\t\t\t\t\t" . intval($topic['disp']) . ",\n\t\t\t\t\t\t1,\n\t\t\t\t\t\t'" . $this->db->escape_string($this->productinfo['productid']) . "')\n\t\t\t\t\t"; } if (!empty($helpsql)) { /*insert query*/ $this->db->query_write("\n\t\t\t\t\t\tREPLACE INTO " . TABLE_PREFIX . "adminhelp\n\t\t\t\t\t\t\t(script, action, optionname, displayorder, volatile, product)\n\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t\t" . implode(",\n\t", $helpsql)); } } } // ############## import cron if (isset($this->productobj['cronentries']['cron']) and is_array($this->productobj['cronentries']['cron'])) { require_once DIR . '/includes/functions_cron.php'; $cron_entries =& $this->productobj['cronentries']['cron']; if (!isset($cron_entries[0])) { $cron_entries = array($cron_entries); } foreach ($cron_entries as $cron) { $cron['varname'] = preg_replace('#[^a-z0-9_]#i', '', $cron['varname']); if (!$cron['varname']) { continue; } $cron['active'] = $cron['active'] ? 1 : 0; $cron['loglevel'] = $cron['loglevel'] ? 1 : 0; $scheduling = $cron['scheduling']; $scheduling['weekday'] = intval($scheduling['weekday']); $scheduling['day'] = intval($scheduling['day']); $scheduling['hour'] = intval($scheduling['hour']); $scheduling['minute'] = explode(',', preg_replace('#[^0-9,-]#i', '', $scheduling['minute'])); if (count($scheduling['minute']) == 0) { $scheduling['minute'] = array(0); } else { $scheduling['minute'] = array_map('intval', $scheduling['minute']); } /*insert query*/ $this->db->query_write("\n\t\t\t\t\tREPLACE INTO " . TABLE_PREFIX . "cron\n\t\t\t\t\t\t(weekday, day, hour, minute, filename, loglevel, active, varname, volatile, product)\n\t\t\t\t\tVALUES\n\t\t\t\t\t\t({$scheduling['weekday']},\n\t\t\t\t\t\t{$scheduling['day']},\n\t\t\t\t\t\t{$scheduling['hour']},\n\t\t\t\t\t\t'" . $this->db->escape_string(serialize($scheduling['minute'])) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string($cron['filename']) . "',\n\t\t\t\t\t\t{$cron['loglevel']},\n\t\t\t\t\t\t{$cron['active']},\n\t\t\t\t\t\t'" . $this->db->escape_string($cron['varname']) . "',\n\t\t\t\t\t\t1,\n\t\t\t\t\t\t'" . $this->db->escape_string($this->productinfo['productid']) . "')\n\t\t\t\t"); $cronid = $this->db->insert_id(); // replace either inserts, or deletes+inserts if ($cronid) { build_cron_item($cronid); } $rebuild['cron'] = true; } } // ############## import faq if (isset($this->productobj['faqentries']['faq']) and is_array($this->productobj['faqentries']['faq'])) { $faq_entries =& $this->productobj['faqentries']['faq']; if (!isset($faq_entries[0])) { $faq_entries = array($faq_entries); } $sql = array(); foreach ($faq_entries as $faq) { $sql[] = "\n\t\t\t\t\t('" . $this->db->escape_string($faq['faqname']) . "',\n\t\t\t\t\t'" . $this->db->escape_string($faq['faqparent']) . "',\n\t\t\t\t\t" . intval($faq['displayorder']) . ",\n\t\t\t\t\t1,\n\t\t\t\t\t'" . $this->db->escape_string($this->productinfo['productid']) . "')\n\t\t\t\t"; } if ($sql) { /*insert query*/ $this->db->query_write("\n\t\t\t\t\tREPLACE INTO " . TABLE_PREFIX . "faq\n\t\t\t\t\t\t(faqname, faqparent, displayorder, volatile, product)\n\t\t\t\t\tVALUES\n\t\t\t\t\t\t" . implode(',', $sql) . "\n\t\t\t\t"); } } // ############## import widgets /* Copied from adminfinctions_product.php At some point we need to get rid of this product install duplication */ if (isset($this->productobj['widgets']['widget']) and is_array($this->productobj['widgets']['widget'])) { $widgets =& $this->productobj['widgets']['widget']; if (!isset($widgets[0])) { $widgets = array($widgets); } $assertor = vB::getDbAssertor(); foreach ($widgets as $widget) { $existing = $assertor->getRow('widget', array('guid' => $widget['guid'], 'product' => $info['productid'])); if ($existing['widgetid']) { $data = $widget + $existing; unset($data['definitions']); $data['isthirdparty'] = 1; $data['product'] = $info['productid']; $result = $assertor->update('widget', $data, array('widgetid' => $existing['widgetid'])); $wdfs_old = $assertor->getRows('widgetdefinition', array('widgetid' => $existing['widgetid'])); $assertor->delete('widgetdefinition', array('widgetid' => $existing['widgetid'])); $index_old = array(); foreach ($wdfs_old as $key => $definition) { $index_old[$key] = $definition['name']; } $wdfs_new =& $widget['definitions']['definition']; if (!isset($wdfs_new[0])) { $wdfs_new = array($wdfs_new); } foreach ($wdfs_new as &$definition) { if ($key_old = array_search($definition['name'], $index_old)) { $definition = $definition + $wdfs_old[$key_old]; } $data = $definition; $data['product'] = $info['productid']; $data['widgetid'] = $existing['widgetid']; $assertor->insert('widgetdefinition', $data); } } else { $data = $widget; $data['isthirdparty'] = 1; $data['product'] = $info['productid']; unset($data['definitions']); $result = $assertor->insert('widget', $data); $widgetid = is_array($result) ? array_pop($result) : $result; if ($widgetid and is_array($widget['definitions']['definition'])) { $definitions =& $widget['definitions']['definition']; if (!isset($definitions[0])) { $definitions = array($definitions); } foreach ($definitions as $definition) { $data = $definition; $data['widgetid'] = $widgetid; $data['product'] = $info['productid']; $assertor->insert('widgetdefinition', $data); } } } } } $products = fetch_product_list(true); // Check if the plugin system is disabled. If it is, enable it if this product isn't installed. if (!$this->registry->options['enablehooks'] and !$products[$this->productinfo['productid']]) { $this->db->query_write("\n\t\t\t\tUPDATE " . TABLE_PREFIX . "setting\n\t\t\t\tSET value = '1'\n\t\t\t\tWHERE varname = 'enablehooks'\n\t\t\t"); $rebuild['options'] = true; } // Now rebuild everything we need... if ($rebuild['hooks']) { vB_Api::instanceInternal("Hook")->buildHookDatastore(); } if ($rebuild['templates']) { if ($error = build_all_styles(0, 0, '')) { return $error; } } if ($rebuild['phrases']) { require_once DIR . '/includes/adminfunctions_language.php'; build_language(); } if ($rebuild['options']) { vB::getDatastore()->build_options(); } if ($rebuild['cron']) { require_once DIR . '/includes/functions_cron.php'; build_cron_next_run(); } build_product_datastore(); // build bitfields to remove/add this products bitfields vB_Bitfield_Builder::save($this->db); print_dots_stop(); $this->productinfo['need_merge'] = ($rebuild['templates'] and $installed_version); return $this->productinfo; }
print_stop_message('product_x_uninstalled', $vbulletin->GPC['productid']); } // ############################################################################# if ($_REQUEST['do'] == 'productdelete') { $vbulletin->input->clean_array_gpc('r', array('productid' => TYPE_STR)); if (strtolower($vbulletin->GPC['productid']) == 'vbulletin') { print_cp_redirect('plugin.php?do=product'); } $dependency_result = $db->query_read("\r\n\t\tSELECT productid, parentproductid\r\n\t\tFROM " . TABLE_PREFIX . "productdependency\r\n\t\tWHERE dependencytype = 'product' AND parentproductid <> ''\r\n\t"); // find child products -- these may break if we uninstall this $dependency_list = array(); while ($dependency = $db->fetch_array($dependency_result)) { $dependency_list["{$dependency['parentproductid']}"][] = $dependency['productid']; } $children = fetch_product_dependencies($vbulletin->GPC['productid'], $dependency_list); $product_list = fetch_product_list(true); $children_text = array(); foreach ($children as $childproductid) { $childproduct = $product_list["{$childproductid}"]; if ($childproduct) { $children_text[] = $childproduct['title']; } } if ($children_text) { $affected_children = construct_phrase($vbphrase['uninstall_product_break_products_x'], '<li>' . implode('</li><li>', $children_text) . '</li>'); } else { $affected_children = ''; } print_delete_confirmation('product', $vbulletin->GPC['productid'], 'plugin', 'productkill', '', 0, $affected_children); } // #############################################################################
/** * Reads XML style file and imports data from it into the database * * @param string XML data * @param integer Style ID * @param integer Parent style ID * @param string New style title * @param boolean Allow vBulletin version mismatch * @param integer Display order for new style * @param boolean Allow user selection of new style */ function xml_import_style($xml = false, $styleid = -1, $parentid = -1, $title = '', $anyversion = false, $displayorder = 1, $userselect = true) { // $GLOBALS['path'] needs to be passed into this function or reference $vbulletin->GPC['path'] global $vbulletin, $vbphrase; print_dots_start('<b>' . $vbphrase['importing_style'] . "</b>, {$vbphrase['please_wait']}", ':', 'dspan'); require_once DIR . '/includes/class_xml.php'; $xmlobj = new vB_XML_Parser($xml, $vbulletin->GPC['path']); if ($xmlobj->error_no == 1) { print_dots_stop(); print_stop_message('no_xml_and_no_path'); } else { if ($xmlobj->error_no == 2) { print_dots_stop(); print_stop_message('please_ensure_x_file_is_located_at_y', 'vbulletin-style.xml', $vbulletin->GPC['path']); } } if (!($arr = $xmlobj->parse())) { print_dots_stop(); print_stop_message('xml_error_x_at_line_y', $xmlobj->error_string(), $xmlobj->error_line()); } if (!$arr['templategroup']) { print_dots_stop(); print_stop_message('invalid_file_specified'); } $version = $arr['vbversion']; $master = $arr['type'] == 'master' ? 1 : 0; $title = empty($title) ? $arr['name'] : $title; $product = empty($arr['product']) ? 'vbulletin' : $arr['product']; $arr = $arr['templategroup']; if (empty($arr[0])) { $arr = array($arr); } $full_product_info = fetch_product_list(true); $product_info = $full_product_info["{$product}"]; // version check if ($version != $product_info['version'] and !$anyversion and !$master) { print_dots_stop(); print_stop_message('upload_file_created_with_different_version', $product_info['version'], $version); } if ($master) { // overwrite master style echo "<h3>{$vbphrase['master_style']}</h3>\n<p>{$vbphrase['please_wait']}</p>"; vbflush(); $vbulletin->db->query_write("DELETE FROM " . TABLE_PREFIX . "template WHERE styleid = -10 AND (product = '" . $vbulletin->db->escape_string($product) . "'" . iif($product == 'vbulletin', " OR product = ''") . ")"); $vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "template SET styleid = -10 WHERE styleid = -1 AND (product = '" . $vbulletin->db->escape_string($product) . "'" . iif($product == 'vbulletin', " OR product = ''") . ")"); $styleid = -1; } else { if ($styleid == -1) { // creating a new style if ($test = $vbulletin->db->query_first("SELECT styleid FROM " . TABLE_PREFIX . "style WHERE title = '" . $vbulletin->db->escape_string($title) . "'")) { print_dots_stop(); print_stop_message('style_already_exists', $title); } else { echo "<h3><b>" . construct_phrase($vbphrase['creating_a_new_style_called_x'], $title) . "</b></h3>\n<p>{$vbphrase['please_wait']}</p>"; vbflush(); /*insert query*/ $styleresult = $vbulletin->db->query_write("\n\t\t\t\t\tINSERT INTO " . TABLE_PREFIX . "style\n\t\t\t\t\t(title, parentid, displayorder, userselect)\n\t\t\t\t\tVALUES\n\t\t\t\t\t('" . $vbulletin->db->escape_string($title) . "', {$parentid}, {$displayorder}, " . ($userselect ? 1 : 0) . ")\n\t\t\t\t"); $styleid = $vbulletin->db->insert_id($styleresult); } } else { // overwriting an existing style if ($getstyle = $vbulletin->db->query_first("SELECT title FROM " . TABLE_PREFIX . "style WHERE styleid = {$styleid}")) { echo "<h3><b>" . construct_phrase($vbphrase['overwriting_style_x'], $getstyle['title']) . "</b></h3>\n<p>{$vbphrase['please_wait']}</p>"; vbflush(); } else { print_dots_stop(); print_stop_message('cant_overwrite_non_existent_style'); } } } // types array... $types = array($vbphrase['template'], $vbphrase['stylevar'], $vbphrase['css'], $vbphrase['replacement_variable']); $querybits = array(); $querytemplates = 0; foreach ($arr as $templategroup) { if (empty($templategroup['template'][0])) { $tg = array($templategroup['template']); } else { $tg =& $templategroup['template']; } foreach ($tg as $template) { $title = $vbulletin->db->escape_string($template['name']); $template['template'] = $vbulletin->db->escape_string($template['value']); $template['username'] = $vbulletin->db->escape_string($template['username']); if ($template['templatetype'] != 'template') { // template is a special template $querybits[] = "({$styleid}, '{$template['templatetype']}', '{$title}', '{$template['template']}', '', {$template['date']}, '{$template['username']}', '" . $vbulletin->db->escape_string($template['version']) . "', '" . $vbulletin->db->escape_string($product) . "')"; } else { // template is a standard template $querybits[] = "({$styleid}, '{$template['templatetype']}', '{$title}', '" . $vbulletin->db->escape_string(compile_template($template['value'])) . "', '{$template['template']}', {$template['date']}, '{$template['username']}', '" . $vbulletin->db->escape_string($template['version']) . "', '" . $vbulletin->db->escape_string($product) . "')"; } if (++$querytemplates % 20 == 0) { /*insert query*/ $vbulletin->db->query_write("\n\t\t\t\t\tREPLACE INTO " . TABLE_PREFIX . "template\n\t\t\t\t\t(styleid, templatetype, title, template, template_un, dateline, username, version, product)\n\t\t\t\t\tVALUES\n\t\t\t\t\t" . implode(',', $querybits) . "\n\t\t\t\t"); $querybits = array(); } } } // insert any remaining templates if (!empty($querybits)) { /*insert query*/ $vbulletin->db->query_write("\n\t\t\tREPLACE INTO " . TABLE_PREFIX . "template\n\t\t\t(styleid, templatetype, title, template, template_un, dateline, username, version, product)\n\t\t\tVALUES\n\t\t\t" . implode(',', $querybits) . "\n\t\t"); } unset($querybits); // now delete any templates that were moved into the temporary styleset for safe-keeping $vbulletin->db->query_write("DELETE FROM " . TABLE_PREFIX . "template WHERE styleid = -10 AND (product = '" . $vbulletin->db->escape_string($product) . "'" . iif($product == 'vbulletin', " OR product = ''") . ")"); print_dots_stop(); }
print_stop_message('pruned_moderator_log_successfully'); } // ###################### Start modify ####################### if ($_REQUEST['do'] == 'choose') { $users = $db->query_read("\n\t\tSELECT DISTINCT moderatorlog.userid, user.username\n\t\tFROM " . TABLE_PREFIX . "moderatorlog AS moderatorlog\n\t\tINNER JOIN " . TABLE_PREFIX . "user AS user USING(userid)\n\t\tORDER BY username\n\t"); $userlist = array('no_value' => $vbphrase['all_log_entries']); while ($user = $db->fetch_array($users)) { $userlist["{$user['userid']}"] = $user['username']; } print_form_header('modlog', 'view'); print_table_header($vbphrase['moderator_log_viewer']); print_input_row($vbphrase['log_entries_to_show_per_page'], 'perpage', 15); print_select_row($vbphrase['show_only_entries_generated_by'], 'userid', $userlist); print_time_row($vbphrase['start_date'], 'startdate', 0, 0); print_time_row($vbphrase['end_date'], 'enddate', 0, 0); if (count($products = fetch_product_list()) > 1) { print_select_row($vbphrase['product'], 'product', array('' => $vbphrase['all_products']) + $products); } print_select_row($vbphrase['order_by'], 'orderby', array('date' => $vbphrase['date'], 'user' => $vbphrase['username']), 'date'); print_submit_row($vbphrase['view'], 0); if (can_access_logs($vbulletin->config['SpecialUsers']['canpruneadminlog'], 0, '')) { print_form_header('modlog', 'prunelog'); print_table_header($vbphrase['prune_moderator_log']); print_select_row($vbphrase['remove_entries_logged_by_user'], 'userid', $userlist); if (count($products) > 1) { print_select_row($vbphrase['product'], 'product', array('' => $vbphrase['all_products']) + $products); } print_input_row($vbphrase['remove_entries_older_than_days'], 'daysprune', 30); print_submit_row($vbphrase['prune_log_entries'], 0); } }
if ($adminmessage['execurl']) { $buttons .= '<input type="submit" name="address[' . $adminmessage['adminmessageid'] . ']" value="' . $vbphrase['address'] . '" class="button" />'; } if ($adminmessage['dismissable'] or !$adminmessage['execurl']) { $buttons .= ' <input type="submit" name="dismiss[' . $adminmessage['adminmessageid'] . ']" value="' . $vbphrase['dismiss'] . '" class="button" />'; } print_description_row("<div style=\"float: right\">{$buttons}</div><div>" . $vbphrase['admin_attention_required'] . "</div>", false, 2, 'thead'); print_description_row('<div class="smallfont">' . fetch_error($adminmessage['varname']) . "</div>"); } $news_rows['admin_messages'] = ob_get_clean(); } if (can_administer('canadminstyles')) { // before the quick stats, display the number of templates that need updating require_once DIR . '/includes/adminfunctions_template.php'; $need_updates = 0; $full_product_info = fetch_product_list(true); $update_templates = $db->query_read("\n\t\tSELECT tCustom.version AS customversion, tGlobal.version AS globalversion,\n\t\t\ttGlobal.product\n\t\tFROM " . TABLE_PREFIX . "template AS tCustom\n\t\tINNER JOIN " . TABLE_PREFIX . "template AS tGlobal ON (tGlobal.styleid = -1 AND tGlobal.title = tCustom.title)\n\t\tINNER JOIN " . TABLE_PREFIX . "style AS style ON (style.styleid = tCustom.styleid)\n\t\tWHERE tCustom.styleid <> -1\n\t\t\tAND tCustom.templatetype = 'template'\n\t"); while ($update_template = $db->fetch_array($update_templates)) { if (!$update_template['product']) { $update_template['product'] = 'vbulletin'; } $product_version = $full_product_info["{$update_template['product']}"]['version']; // version in the template is newer than the version of the product, // which probably means it's using the vB version if (is_newer_version($update_template['globalversion'], $product_version)) { $update_template['globalversion'] = $product_version; } if (is_newer_version($update_template['customversion'], $product_version)) { $update_template['customversion'] = $product_version; } if (is_newer_version($update_template['globalversion'], $update_template['customversion'])) {
} if (strtolower($info['productid']) == 'vbulletin') { print_dots_stop(); print_stop_message('product_x_installed_no_overwrite', 'vBulletin'); } // check for bitfield conflicts on install $bitfields = vB_Bitfield_Builder::return_data(); if (!$bitfields) { $bfobj =& vB_Bitfield_Builder::init(); if ($bfobj->errors) { print_dots_stop(); print_stop_message('bitfield_conflicts_x', '<li>' . implode('</li><li>', $bfobj->errors) . '</li>'); } } // get system version info $system_versions = array('php' => PHP_VERSION, 'vbulletin' => $vbulletin->options['templateversion'], 'products' => fetch_product_list(true)); $mysql_version = $db->query_first("SELECT VERSION() AS version"); $system_versions['mysql'] = $mysql_version['version']; // ############## import dependencies if (is_array($arr['dependencies']['dependency'])) { $dependencies =& $arr['dependencies']['dependency']; if (!isset($dependencies[0])) { $dependencies = array($dependencies); } $dependency_errors = array(); $ignore_dependency_errors = array(); // let's check the dependencies foreach ($dependencies as $dependency) { // if we get an error, we haven't met this dependency // if we go through without a problem, we have automatically met // all dependencies for this "class" (mysql, php, vb, a specific product, etc)
function autoexport_write_master_style() { require_once(DIR . '/includes/adminfunctions_template.php'); $full_product_info = fetch_product_list(true); $xml = get_style_export_xml(-1, 'vbulletin', $full_product_info['vbulletin']['version'], '', 2); autoexport_write_file_with_backup(DIR . '/install/vbulletin-style.xml', $xml); //we don't want the templates in the xml on the filesystem require_once(DIR . '/includes/class_filesystemxml_template.php'); $helper = new vB_FilesystemXml_Template(); $helper->remove_product_templates('vbulletin'); }
function fetch_old_templates() { global $db; $full_product_info = fetch_product_list(true); $customcache = array(); $count = 0; $templates = $db->query_read("\n\t\tSELECT tCustom.templateid, tCustom.title, tCustom.styleid, tCustom.mergestatus AS custommergestatus,\n\t\t\ttCustom.username AS customuser, tCustom.dateline AS customdate, tCustom.version AS customversion,\n\t\t\ttGlobal.username AS globaluser, tGlobal.dateline AS globaldate, tGlobal.version AS globalversion,\n\t\t\ttGlobal.product\n\t\tFROM " . TABLE_PREFIX . "template AS tCustom\n\t\tINNER JOIN " . TABLE_PREFIX . "style AS style ON (style.styleid = tCustom.styleid)\n\t\tINNER JOIN " . TABLE_PREFIX . "template AS tGlobal ON (tGlobal.styleid = IF(style.type = 'standard', -1, -2) AND tGlobal.title = tCustom.title)\n\t\tWHERE\n\t\t\ttCustom.styleid > 0\n\t\t\t\tAND\n\t\t\ttCustom.templatetype = 'template'\n\t\t\t\tAND\n\t\t\ttCustom.mergestatus = 'none'\n\t\tORDER BY tCustom.title\n\t"); while ($template = $db->fetch_array($templates)) { if (!$template['product']) { $template['product'] = 'vbulletin'; } $product_version = $full_product_info["{$template['product']}"]['version']; // version in the template is newer than the version of the product, // which probably means it's using the vB version if (is_newer_version($template['globalversion'], $product_version)) { $template['globalversion'] = $product_version; } if (is_newer_version($template['customversion'], $product_version)) { $template['customversion'] = $product_version; } if (is_newer_version($template['globalversion'], $template['customversion'])) { $count++; $customcache["{$template['styleid']}"]["{$template['templateid']}"] = $template; } } return array('count' => $count, 'cache' => $customcache); }
/** * Step #7 Check Product Dependencies * */ function step_7() { if (VB_AREA == 'Install') { $this->skip_message(); return; } $this->show_message($this->phrase['final']['verifying_product_dependencies']); require_once DIR . '/includes/class_upgrade_product.php'; $this->product = new vB_Upgrade_Product($this->registry, $this->phrase['vbphrase'], true, $this->caller); $dependency_list = array(); $product_dependencies = $this->db->query_read("\n\t\t\tSELECT pd.*\n\t\t\tFROM " . TABLE_PREFIX . "productdependency AS pd\n\t\t\tINNER JOIN " . TABLE_PREFIX . "product AS p ON (p.productid = pd.productid)\n\t\t\tWHERE\n\t\t\t\tpd.productid IN ('vbblog', 'vbcms', 'skimlinks', 'forumrunner', 'postrelease', 'vbapi')\n\t\t\t\t\tAND\n\t\t\t\tp.active = 1\n\t\t\tORDER BY\n\t\t\t\tpd.dependencytype, pd.parentproductid, pd.minversion\n\t\t"); while ($product_dependency = $this->db->fetch_array($product_dependencies)) { $dependency_list["{$product_dependency['productid']}"][] = array('dependencytype' => $product_dependency['dependencytype'], 'parentproductid' => $product_dependency['parentproductid'], 'minversion' => $product_dependency['minversion'], 'maxversion' => $product_dependency['maxversion']); } $product_list = fetch_product_list(true); $disabled = array(); foreach ($dependency_list as $productid => $dependencies) { $this->show_message(sprintf($this->phrase['final']['verifying_product_x'], $productid)); $this->product->productinfo['productid'] = $productid; $disableproduct = false; try { $this->product->import_dependencies($dependencies); } catch (vB_Exception_AdminStopMessage $e) { $message = $this->stop_exception($e); $this->show_message($message); $disableproduct = true; } if ($disableproduct) { $disabled[] = $productid; $this->product->disable(); $this->add_adminmessage('disabled_product_x_y_z', array('dismissable' => 1, 'script' => '', 'action' => '', 'execurl' => '', 'method' => '', 'status' => 'undone'), true, array($product_list["{$productid}"]['title'], $productid, $message)); $this->show_message(sprintf($this->phrase['final']['product_x_disabled'], $productid)); } } if (!should_install_suite()) { if (!$disabled['vbblog'] and $product_list['vbblog']['active']) { $this->product = new vB_Upgrade_Product($this->registry, $this->phrase['vbphrase'], true, $this->caller); $this->product->productinfo['productid'] = 'vbblog'; $this->product->disable(); $this->show_message(sprintf($this->phrase['final']['product_x_disabled'], 'vbblog')); } if (!$disabled['vbcms'] and $product_list['vbcms']['active']) { $this->product = new vB_Upgrade_Product($this->registry, $this->phrase['vbphrase'], true, $this->caller); $this->product->productinfo['productid'] = 'vbcms'; $this->product->disable(); $this->show_message(sprintf($this->phrase['final']['product_x_disabled'], 'vbcms')); } } }
/** * Add a new phrase or update an existing phrase * @param string $fieldname New Phrase Type for adding, old Phrase Type for editing * @param string $varname New Varname for adding, old Varname for editing * @param array $data Phrase data to be added or updated * 'text' => Phrase text array. * 'oldvarname' => Old varname for editing only * 'oldfieldname' => Old fieldname for editing only * 't' => * 'ismaster' => * 'product' => Product ID of the phrase * @return void */ public function save($fieldname, $varname, $data) { $fieldname = trim($fieldname); $varname = trim($varname); $vb5_config =& vB::getConfig(); $install = false; if (defined('VBINSTALL') and VBINSTALL) { $install = true; } $session = vB::getCurrentSession(); if (!empty($session)) { $userinfo = $session->fetch_userinfo(); } else { $userinfo = vB_User::fetchUserinfo(1); } require_once DIR . '/includes/adminfunctions.php'; $full_product_info = fetch_product_list(true); if (empty($varname)) { throw new vB_Exception_Api('please_complete_required_fields'); } if (!preg_match('#^[' . self::VALID_CLASS . ']+$#', $varname)) { throw new vB_Exception_Api('invalid_phrase_varname'); } require_once DIR . '/includes/functions_misc.php'; foreach ($data['text'] as $text) { if (!validate_string_for_interpolation($text)) { throw new vB_Exception_Api('phrase_text_not_safe', array($varname)); } } // it's an update if (!empty($data['oldvarname']) and !empty($data['oldfieldname'])) { if (vB::getDbAssertor()->getField('phrase_fetchid', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_STORED, 'varname' => $varname))) { // Don't check if we are moving a phrase to another group but keeping the same name. See VBV-4192. if ($varname != $data['oldvarname'] and $fieldname != $data['oldfieldname']) { throw new vB_Exception_Api('there_is_already_phrase_named_x', array($varname)); } if ($varname != $data['oldvarname']) { throw new vB_Exception_Api('variable_name_exists', array($data['oldvarname'], $varname)); } } if (!is_array($data['oldfieldname'])) { $data['oldfieldname'] = array($data['oldfieldname']); } if (!in_array($fieldname, $data['oldfieldname'])) { $data['oldfieldname'][] = $fieldname; } // delete old phrases vB::getDbAssertor()->assertQuery('deleteOldPhrases', array('varname' => $data['oldvarname'], 'fieldname' => $data['oldfieldname'], 't' => $data['t'], 'debug' => empty($data['skipdebug']) && ($vb5_config['Misc']['debug'] or $install))); $update = 1; $this->setPhraseDate(); } if (empty($update)) { if (empty($data['text'][0]) and $data['text'][0] != '0' and !$data['t'] or empty($varname)) { throw new vB_Exception_Api('please_complete_required_fields'); } if (vB::getDbAssertor()->getField('phrase_fetchid', array('varname' => $varname, 'fieldname' => $fieldname))) { throw new vB_Exception_Api('there_is_already_phrase_named_x', array($varname)); } } if ($data['ismaster']) { if (($vb5_config['Misc']['debug'] or $install) and !$data['t']) { /*insert query*/ vB::getDbAssertor()->assertQuery('phrase', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_REPLACE, 'languageid' => -1, 'varname' => $varname, 'text' => $data['text'][0], 'fieldname' => $fieldname, 'product' => $data['product'], 'username' => $userinfo['username'], 'dateline' => vB::getRequest()->getTimeNow(), 'version' => $full_product_info[$data['product']]['version'])); } unset($data['text'][0]); } foreach ($data['text'] as $_languageid => $txt) { $_languageid = intval($_languageid); if (!empty($txt) or $txt == '0') { /*insert query*/ vB::getDbAssertor()->assertQuery('phrase', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_REPLACE, 'languageid' => $_languageid, 'varname' => $varname, 'text' => $txt, 'fieldname' => $fieldname, 'product' => $data['product'], 'username' => $userinfo['username'], 'dateline' => vB::getRequest()->getTimeNow(), 'version' => $full_product_info[$data['product']]['version'])); } } require_once DIR . '/includes/adminfunctions.php'; require_once DIR . '/includes/adminfunctions_language.php'; build_language(-1); }
/** * Insert a new cron or Update an existing cron * * @param array $data Cron data to be inserted or updated * 'varname' => Varname * 'filename' => Filename * 'title' => Title * 'description' => Description * 'logphrase' => Log Phrase * 'weekday' => Day of the Week (Note: this overrides the 'day of the month' option) * 'day' => Day of the Month * 'hour' => Hour * 'minute' => Minute * 'active' => Active. Boolean. * 'loglevel' => Log Entries. Boolean. * 'product' => Product * 'volatile' => vBulletin Default. Boolean. * @param int $cronid If not 0, it's the cron ID to be updated * * @return int New cron ID or updated Cron's ID */ public function save($data, $cronid = 0) { $this->checkHasAdminPermission('canadmincron'); $cronid = intval($cronid); $vb5_config = vB::getConfig(); $userinfo = vB::getDatastore()->get_value('userinfo'); if (empty($cronid)) { if (empty($data['varname'])) { throw new vB_Exception_Api('please_complete_required_fields'); } if (!preg_match('#^[a-z0-9_]+$#i', $data['varname'])) { throw new vB_Exception_Api('invalid_phrase_varname'); } if (vB::getDbAssertor()->getRow('cron', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, 'varname' => $data['varname']))) { throw new vB_Exception_Api('there_is_already_option_named_x', array($data['varname'])); } if (empty($data['title'])) { throw new vB_Exception_Api('please_complete_required_fields'); } } else { $cron = vB::getDbAssertor()->getRow('cron', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, 'cronid' => $cronid)); if (!$cron) { throw new vB_Exception_Api('invalid_option_specified'); } if ((!$cron['volatile'] or $vb5_config['Misc']['debug']) and empty($data['title'])) { // custom entry or in debug mode means the title is editable throw new vB_Exception_Api('please_complete_required_fields'); } $data['varname'] = $cron['varname']; } if ($data['filename'] == '' or $data['filename'] == './includes/cron/.php') { throw new vB_Exception_Api('invalid_filename_specified'); } $data['weekday'] = str_replace('*', '-1', $data['weekday']); $data['day'] = str_replace('*', '-1', $data['day']); $data['hour'] = str_replace('*', '-1', $data['hour']); // need to deal with minute properly :) sort($data['minute'], SORT_NUMERIC); $newminute = array(); foreach ($data['minute'] as $time) { $newminute["{$time}"] = true; } unset($newminute["-2"]); // this is the "-" (don't run) entry if ($newminute["-1"]) { // its run every minute so lets just ignore every other entry $newminute = array(0 => -1); } else { // $newminute's keys are the values of the GPC variable, so get the values back $newminute = array_keys($newminute); } if (empty($cronid)) { /*insert query*/ $cronid = vB::getDbAssertor()->assertQuery('cron', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_INSERT, 'varname' => trim($data['varname']))); if (!empty($cronid['errors'])) { throw new vB_Exception_Api('invalid_data'); } } else { // updating an entry. If we're changing the volatile status, we // need to remove the entries in the opposite language id. // Only possible in debug mode. if ($data['volatile'] != $cron['volatile']) { $old_languageid = $cron['volatile'] ? -1 : 0; vB::getDbAssertor()->assertQuery('phrase', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_DELETE, 'languageid' => $old_languageid, 'fieldname' => 'cron', 'varname' => array('task_$cron[varname]_title', 'task_$cron[varname]_desc', 'task_$cron[varname]_log'))); } } $escaped_product = $data['product']; // update $result = vB::getDbAssertor()->assertQuery('cron', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_UPDATE, 'loglevel' => intval($data['loglevel']), 'weekday' => intval($data['weekday']), 'day' => intval($data['day']), 'hour' => intval($data['hour']), 'minute' => serialize($newminute), 'filename' => $data['filename'], 'active' => $data['active'], 'volatile' => $data['volatile'], 'product' => $data['product'], vB_dB_Query::CONDITIONS_KEY => array('cronid' => $cronid))); if (!empty($result['errors'])) { throw new vB_Exception_Api('invalid_data'); } $new_languageid = $data['volatile'] ? -1 : 0; require_once DIR . '/includes/adminfunctions.php'; $full_product_info = fetch_product_list(true); $product_version = $full_product_info["{$escaped_product}"]['version']; if (!$data['volatile'] or $vb5_config['Misc']['debug']) { /*insert_query*/ $result = vB::getDbAssertor()->assertQuery('cron_insertphrases', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_STORED, 'new_languageid' => $new_languageid, 'varname' => $data['varname'], 'product' => $data['product'], 'username' => $userinfo['username'], 'timenow' => vB::getRequest()->getTimeNow(), 'product_version' => $product_version, 'title' => trim($data['title']), 'description' => trim($data['description']), 'logphrase' => trim($data['logphrase']))); if (!empty($result['errors'])) { throw new vB_Exception_Api('invalid_data'); } require_once DIR . '/includes/adminfunctions_language.php'; build_language(); } require_once DIR . '/includes/functions_cron.php'; build_cron_item($cronid); build_cron_next_run(); return $cronid; }
/** * This function updates group settings. * @param array $group Group values * @return array, $response */ public function updateGroupSettings($group, $username, $oldproduct = '', $adminperm = false) { $this->checkHasAdminPermission('canadminsettings'); require_once DIR . '/includes/class_xml.php'; require_once DIR . '/includes/functions_file.php'; require_once DIR . '/includes/adminfunctions_options.php'; require_once DIR . '/includes/adminfunctions.php'; $response = array(); $existing = vB::getDbAssertor()->assertQuery('settinggroup', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, 'grouptitle' => $group['grouptitle'])); if ($existing->valid()) { $existing = $existing->current(); if (!empty($existing['adminperm']) and !vB::getUserContext()->hasAdminPermission($existing['adminperm'])) { throw new vB_Exception_AccessDenied('no_permission'); } } $updates = array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_UPDATE, 'displayorder' => $group['displayorder'], 'volatile' => $group['volatile'], 'product' => $group['product'], vB_dB_Query::CONDITIONS_KEY => array(array('field' => 'grouptitle', 'value' => $group['grouptitle'], 'operator' => vB_dB_Query::OPERATOR_EQ))); if ($adminperms !== false and vB::getUserContext()->hasAdminPermission('canadminsettingsall')) { $adminperm = vB::getCleaner()->clean($adminperm, vB_Cleaner::TYPE_STR); if (empty($adminperm)) { $updates['adminperm'] = ''; } else { $updates['adminperm'] = substr($adminperm, 0, 32); } } $updateSetting = vB::getDbAssertor()->assertQuery('settinggroup', $updates); if ($updateSetting['errors']) { $response['errors'] = $updateSetting['errors']; } $full_product_info = fetch_product_list(true); $product_version = $full_product_info[$group['product']]['version']; $updatePhrase = vB::getDbAssertor()->assertQuery('vBForum:phrase', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_UPDATE, 'text' => $group['title'], 'product' => $group['product'], 'username' => $username, 'dateline' => TIMENOW, 'version' => $product_version, vB_dB_Query::CONDITIONS_KEY => array(array('field' => 'varname', 'value' => "settinggroup_" . $group['grouptitle'], 'operator' => vB_dB_Query::OPERATOR_EQ)))); if ($updatePhrase['errors']) { $response['errors'] = $updatePhrase['errors']; } $settingnames = array(); $phrasenames = array(); $settings = vB::getDbAssertor()->assertQuery('setting', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, 'grouptitle' => $group['grouptitle'], 'product' => $oldproduct)); if ($settings and $settings->valid()) { foreach ($settings as $setting) { $settingnames[] = $setting['varname']; $phrasenames[] = 'setting_' . $setting['varname'] . '_desc'; $phrasenames[] = 'setting_' . $setting['varname'] . '_title'; } $full_product_info = fetch_product_list(true); $product_version = $full_product_info[$group['product']]['version']; vB::getDbAssertor()->assertQuery('setting', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_UPDATE, 'product' => $group['product'], vB_dB_Query::CONDITIONS_KEY => array(array('field' => 'varname', 'value' => $settingnames, 'operator' => vB_dB_Query::OPERATOR_EQ)))); vB::getDbAssertor()->assertQuery('vBForum:phrase', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_UPDATE, 'product' => $group['product'], 'username' => $username, 'dateline' => TIMENOW, 'version' => $product_version, vB_dB_Query::CONDITIONS_KEY => array(array('field' => 'varname', 'value' => $phrasenames, 'operator' => vB_dB_Query::OPERATOR_EQ), array('field' => 'fieldname', 'value' => 'vbsettings', 'operator' => vB_dB_Query::OPERATOR_EQ)))); } vB::getDatastore()->build_options(); if (defined('DEV_AUTOEXPORT') and DEV_AUTOEXPORT) { require_once DIR . '/includes/functions_filesystemxml.php'; autoexport_write_settings_and_language(-1, array($oldproduct, $group['product'])); } $response['update'] = true; return $response; }
/** * Find and replace phrases in languages * * @param array $replace A list of phrase ID to be replaced * @param string $searchstring Search string * @param string $replacestring Replace string * @param int $languageid Language ID * @return void */ public function replace($replace, $searchstring, $replacestring, $languageid) { $this->checkHasAdminPermission('canadminlanguages'); if (empty($replace)) { throw new vB_Exception_Api('please_complete_required_fields'); } $userinfo = vB::getCurrentSession()->fetch_userinfo(); require_once DIR . '/includes/adminfunctions.php'; $full_product_info = fetch_product_list(true); $phrases = vB::getDbAssertor()->assertQuery('phrase', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, 'phraseid' => $replace)); $products = array(); foreach ($phrases as $phrase) { $phrase['product'] = empty($phrase['product']) ? 'vbulletin' : $phrase['product']; $phrase['text'] = str_replace($searchstring, $replacestring, $phrase['text']); if ($phrase['languageid'] == $languageid) { // update vB::getDbAssertor()->assertQuery('phrase', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_UPDATE, 'text' => $phrase['text'], 'username' => $userinfo['username'], 'dateline' => vB::getRequest()->getTimeNow(), 'version' => $full_product_info["{$phrase['product']}"]['version'], vB_dB_Query::CONDITIONS_KEY => array('phraseid' => $phrase['phraseid']))); } else { // insert /*insert query*/ vB::getDbAssertor()->assertQuery('phrase_replace', array('languageid' => $languageid, 'varname' => $phrase['varname'], 'text' => $phrase['text'], 'fieldname' => $phrase['fieldname'], 'product' => $phrase['product'], 'username' => $userinfo['username'], 'dateline' => vB::getRequest()->getTimeNow(), 'version' => $full_product_info["{$phrase['product']}"]['version'])); } $products[$phrase['product']] = 1; } $this->setPhraseDate(); return array_keys($products); }
/** * Additional data to update after a save call (such as denormalized values in other tables). * In batch updates, is executed for each record updated. * * @param boolean Do the query? */ function post_save_each($doquery = true) { // replace (master) phrase entry require_once DIR . '/includes/adminfunctions.php'; $full_product_info = fetch_product_list(true); $product_version = $full_product_info['vbprojecttools']['version']; $db =& $this->registry->db; foreach ($this->info_phrase as $info_name => $phrase_name) { if ($this->info["{$info_name}"] !== null) { $phrase = sprintf($phrase_name, $this->fetch_field('issuetypeid')); $db->query_write("\r\n\t\t\t\t\tREPLACE INTO " . TABLE_PREFIX . "phrase\r\n\t\t\t\t\t\t(languageid, fieldname, varname, text, product, username, dateline, version)\r\n\t\t\t\t\tVALUES\r\n\t\t\t\t\t\t(\r\n\t\t\t\t\t\t\t0,\r\n\t\t\t\t\t\t\t'projecttools',\r\n\t\t\t\t\t\t\t'" . $db->escape_string($phrase) . "',\r\n\t\t\t\t\t\t\t'" . $db->escape_string($this->info["{$info_name}"]) . "',\r\n\t\t\t\t\t\t\t'vbprojecttools',\r\n\t\t\t\t\t\t\t'" . $db->escape_string($this->registry->userinfo['username']) . "',\r\n\t\t\t\t\t\t\t" . TIMENOW . ",\r\n\t\t\t\t\t\t\t'" . $db->escape_string($product_version) . "'\r\n\t\t\t\t\t\t)\r\n\t\t\t\t"); } } if ($this->info['rebuild_caches']) { require_once DIR . '/includes/adminfunctions_language.php'; build_language(); require_once DIR . '/includes/adminfunctions_projecttools.php'; build_issue_type_cache(); } ($hook = vBulletinHook::fetch_hook('pt_issuetypedata_postsave')) ? eval($hook) : false; return true; }
/** * Update a template * * @param integer $templateid Template ID to be updated * @param string $title Template name. * @param string $content Template content. * @param string $product The product ID which the template belongs to. * @param string $oldcontent The content of the template at the time it was loaded. This is used to prevent * cases where the template was changed while editing. Pass false to force an update. * @param boolean $savehistory Whether to save the change in template history. * @param string $histcomment Comment of the change to be saved to template history. * @param boolean $forcesaveonerror save the template even though there are errors. */ public function update($templateid, $title, $content, $product, $oldcontent, $savehistory, $histcomment, $forcesaveonerror = false, $additional = array()) { $templateid = intval($templateid); $title = trim($title); $content = trim($content); $product = trim($product); $histcomment = trim($histcomment); $userinfo = vB::getCurrentSession()->fetch_userinfo(); $timenow = vB::getRequest()->getTimeNow(); require_once DIR . '/includes/adminfunctions.php'; require_once DIR . '/includes/adminfunctions_template.php'; // Required for check_template_conflict_error() $style_lib = vB_Library::instance('Style'); // Compile template if (!empty($additional['textonly'])) { $template = $content; } else { $template = $this->compile($content, $forcesaveonerror); } // TODO: Product API $full_product_info = fetch_product_list(true); if (!$forcesaveonerror) { $errors = check_template_conflict_error($template); if (!empty($errors)) { throw new vB_Exception_Api('template_conflict_errors', array($errors)); } } $old_template = $this->fetchByID($templateid); // Test whether the template exists if new template title is not the same as old one's if (strtolower($title) != strtolower($old_template['title'])) { $result = vB::getDbAssertor()->assertQuery('template_fetchbystyleandtitle', array('styleid' => $old_template['styleid'], 'title' => $title)); if ($result->valid()) { throw new vB_Exception_Api('invalidid', array('templateid')); } } if ($oldcontent === false) { $hash = md5($old_template['template_un']); } else { $hash = md5($oldcontent); } $result = $this->saveTemplate($title, $template, $content, $timenow, $userinfo['username'], $full_product_info[$product]['version'], $product, $templateid, $hash, $old_template['styleid'], $savehistory, $histcomment, $additional); if ($result == 0) { // we have an edit conflict throw new vB_Exception_Api('edit_conflict'); } else { // Remove templatemerge record vB::getDbAssertor()->assertQuery('templatemerge', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_DELETE, 'templateid' => $templateid)); // update any customized templates to reflect a change of product id if ($old_template['styleid'] == -1 and $product != $old_template['product']) { $result = vB::getDbAssertor()->assertQuery('template_updatecustom_product', array('product' => $product, 'title' => $title)); } //we need to rebuild the style if a css template is changed, we may need to republish. if (preg_match('#\\.css$#i', $title)) { $style_lib->buildStyle($old_template['styleid'], $title, array('docss' => 0, 'dostylevars' => 0, 'doreplacements' => 0, 'doposteditor' => 0), false); } return true; } }
print_input_row($vbphrase['showperm'], 'show', '', true, 30); if ($vbulletin->GPC['type'] == 'tab') { print_yes_no_row($vbphrase['usetabid'], 'usetabid', $navelement['usetabid']); print_input_row($vbphrase['scripts'], 'scripts', $navelement['scripts'], true, 30); } else { construct_hidden_code('usetabid', 0); construct_hidden_code('scripts', ''); } print_yes_no_row($vbphrase['newpage'], 'newpage', $navelement['newpage']); ($hook = vBulletinHook::fetch_hook('navigation_admin_add')) ? eval($hook) : false; print_submit_row($vbphrase['save']); } if ($_REQUEST['do'] == 'doadd') { $tabs = get_navigation_parents($navlist, array('tab')); $parents = get_navigation_parents($navlist, array('tab', 'menu')); $products = fetch_product_list(false, true, false); $vbulletin->input->clean_array_gpc('r', array('order' => TYPE_INT, 'parent' => TYPE_STR, 'product' => TYPE_STR, 'type' => TYPE_STR, 'active' => TYPE_BOOL, 'identity' => TYPE_STR, 'show' => TYPE_STR, 'url' => TYPE_STR, 'title' => TYPE_STR, 'usetabid' => TYPE_BOOL, 'scripts' => TYPE_STR, 'newpage' => TYPE_BOOL)); //-- checks --// if ($vbulletin->GPC['type'] == 'tab' and $vbulletin->GPC['parent']) { print_stop_message('tabs_cannot_have_parent'); } if ($vbulletin->GPC['type'] == 'menu' and $vbulletin->GPC['url']) { print_stop_message('menu_cannot_have_url'); } if (!in_array($vbulletin->GPC['type'], array('tab', 'menu', 'link'))) { print_stop_message('invalid_type'); } if ($vbulletin->GPC['usetabid'] and $vbulletin->GPC['type'] != 'tab') { print_stop_message('tabs_only'); } $showvars = explode('.', $vbulletin->GPC['show']);
/** * Installs a product from the xml text * * This function depends on the vb class loader, which requires that the * framework init is called. * * @return bool True if the product requires a template merge, false otherwise */ function install_product($xml, $allow_overwrite = false, $verbose = true) { global $vbphrase; global $vbulletin; $assertor = vB::getDbAssertor(); require_once DIR . '/includes/class_bitfield_builder.php'; require_once DIR . '/includes/class_xml.php'; //share some code with the main xml style import require_once DIR . '/includes/adminfunctions_template.php'; if ($verbose) { print_dots_start('<b>' . $vbphrase['importing_product'] . "</b>, {$vbphrase['please_wait']}", ':', 'dspan'); } $xmlobj = new vB_XML_Parser($xml); if ($xmlobj->error_no() == 1) { if ($verbose) { print_dots_stop(); } throw new vB_Exception_AdminStopMessage('no_xml_and_no_path'); } if (!($arr = $xmlobj->parse())) { if ($verbose) { print_dots_stop(); } throw new vB_Exception_AdminStopMessage(array('xml_error_x_at_line_y', $xmlobj->error_string(), $xmlobj->error_line())); } // ############## general product information $info = array('productid' => substr(preg_replace('#[^a-z0-9_]#', '', strtolower($arr['productid'])), 0, 25), 'title' => $arr['title'], 'description' => $arr['description'], 'version' => $arr['version'], 'active' => $arr['active'], 'url' => $arr['url'], 'versioncheckurl' => $arr['versioncheckurl']); if (!$info['productid']) { if ($verbose) { print_dots_stop(); } throw new vB_Exception_AdminStopMessage('invalid_file_specified'); } if (strtolower($info['productid']) == 'vbulletin') { if ($verbose) { print_dots_stop(); } throw new vB_Exception_AdminStopMessage(array('product_x_installed_no_overwrite', 'vBulletin')); } // check for bitfield conflicts on install $bitfields = vB_Bitfield_Builder::return_data(); if (!$bitfields) { $bfobj =& vB_Bitfield_Builder::init(); if ($bfobj->errors) { if ($verbose) { print_dots_stop(); } throw new vB_Exception_AdminStopMessage(array('bitfield_conflicts_x', '<li>' . implode('</li><li>', $bfobj->errors) . '</li>')); } } // get system version info $system_versions = array('php' => PHP_VERSION, 'vbulletin' => $vbulletin->options['templateversion'], 'products' => fetch_product_list(true)); $mysql_version = $assertor->getRow('mysqlVersion'); $system_versions['mysql'] = $mysql_version['version']; // ############## import dependencies if (isset($arr['dependencies']['dependency']) and is_array($arr['dependencies']['dependency'])) { $dependencies =& $arr['dependencies']['dependency']; if (!isset($dependencies[0])) { $dependencies = array($dependencies); } $dependency_errors = array(); $ignore_dependency_errors = array(); // let's check the dependencies foreach ($dependencies as $dependency) { // if we get an error, we haven't met this dependency // if we go through without a problem, we have automatically met // all dependencies for this "class" (mysql, php, vb, a specific product, etc) $this_dependency_met = true; // build a phrase for the version compats -- will look like (minver / maxver) if ($dependency['minversion']) { $compatible_phrase = construct_phrase($vbphrase['compatible_starting_with_x'], htmlspecialchars_uni($dependency['minversion'])); } else { $compatible_phrase = ''; } if ($dependency['maxversion']) { $incompatible_phrase = construct_phrase($vbphrase['incompatible_with_x_and_greater'], htmlspecialchars_uni($dependency['maxversion'])); } else { $incompatible_phrase = ''; } if ($compatible_phrase or $incompatible_phrase) { $required_version_info = "({$compatible_phrase}"; if ($compatible_phrase and $incompatible_phrase) { $required_version_info .= ' / '; } $required_version_info .= "{$incompatible_phrase})"; } // grab the appropriate installed version string if ($dependency['dependencytype'] == 'product') { // group dependencies into types -- individual products get their own group $dependency_type_key = "product-{$dependency['parentproductid']}"; // undocumented feature -- you can put a producttitle attribute in a dependency so the id isn't displayed $parent_product_title = !empty($dependency['producttitle']) ? $dependency['producttitle'] : $dependency['parentproductid']; $parent_product = $system_versions['products']["{$dependency['parentproductid']}"]; if (!$parent_product) { // required product is not installed $dependency_errors["{$dependency_type_key}"] = construct_phrase($vbphrase['product_x_must_be_installed'], htmlspecialchars_uni($parent_product_title), $required_version_info); continue; // can't do version checks if the product isn't installed } else { if ($parent_product['active'] == 0) { // product is installed, but inactive $dependency_errors["{$dependency_type_key}-inactive"] = construct_phrase($vbphrase['product_x_must_be_activated'], htmlspecialchars_uni($parent_product_title)); $this_dependency_met = false; // allow version checks to continue } } $sys_version_str = $parent_product['version']; $version_incompatible_phrase = 'product_incompatible_version_x_product_y'; } else { $dependency_type_key = $dependency['dependencytype']; $parent_product_title = ''; $sys_version_str = $system_versions["{$dependency['dependencytype']}"]; $version_incompatible_phrase = 'product_incompatible_version_x_' . $dependency['dependencytype']; } // if no version string, we are trying to do an unsupported dep check if ($sys_version_str == '') { continue; } $sys_version = fetch_version_array($sys_version_str); // error if installed version < minversion if ($dependency['minversion']) { $dep_version = fetch_version_array($dependency['minversion']); for ($i = 0; $i <= 5; $i++) { if ($sys_version["{$i}"] < $dep_version["{$i}"]) { // installed version is too old $dependency_errors["{$dependency_type_key}"] = construct_phrase($vbphrase["{$version_incompatible_phrase}"], htmlspecialchars_uni($sys_version_str), $required_version_info, $parent_product_title); $this_dependency_met = false; break; } else { if ($sys_version["{$i}"] > $dep_version["{$i}"]) { break; } } } } // error if installed version >= maxversion if ($dependency['maxversion']) { $dep_version = fetch_version_array($dependency['maxversion']); $all_equal = true; for ($i = 0; $i <= 5; $i++) { if ($sys_version["{$i}"] > $dep_version["{$i}"]) { // installed version is newer than the maxversion $dependency_errors["{$dependency_type_key}"] = construct_phrase($vbphrase["{$version_incompatible_phrase}"], htmlspecialchars_uni($sys_version_str), $required_version_info, $parent_product_title); $this_dependency_met = false; break; } else { if ($sys_version["{$i}"] < $dep_version["{$i}"]) { // not every part is the same and since we've got less we can exit $all_equal = false; break; } else { if ($sys_version["{$i}"] != $dep_version["{$i}"]) { // not every part is the same $all_equal = false; } } } } if ($all_equal == true) { // installed version is same as the max version, which is the first incompat version $dependency_errors["{$dependency_type_key}"] = construct_phrase($vbphrase["{$version_incompatible_phrase}"], htmlspecialchars_uni($sys_version_str), $required_version_info, $parent_product_title); $this_dependency_met = false; } } if ($this_dependency_met) { // we met 1 dependency for this type -- this emulates or'ing together groups $ignore_dependency_errors["{$dependency_type_key}"] = true; } } // for any group we met a dependency for, ignore any errors we might // have gotten for the group foreach ($ignore_dependency_errors as $dependency_type_key => $devnull) { unset($dependency_errors["{$dependency_type_key}"]); } if ($dependency_errors) { $dependency_errors = array_unique($dependency_errors); $dependency_errors = '<ol><li>' . implode('</li><li>', $dependency_errors) . '</li></ol>'; if ($verbose) { print_dots_stop(); } throw new vB_Exception_AdminStopMessage(array('dependencies_not_met_x', $dependency_errors)); } } // look to see if we already have this product installed if ($existingprod = $assertor->getRow('product', array('productid' => $info['productid']))) { if (!$allow_overwrite) { if ($verbose) { print_dots_stop(); } throw new vB_Exception_AdminStopMessage(array('product_x_installed_no_overwrite', $info['title'])); } $active = $existingprod['active']; // not sure what we're deleting, so rebuild everything $rebuild = array('templates' => true, 'hooks' => true, 'phrases' => true, 'options' => true, 'cron' => true); $installed_version = $existingprod['version']; } else { $active = $info['active'] ? 1 : 0; $rebuild = array('templates' => false, 'hooks' => false, 'phrases' => false, 'options' => false, 'cron' => false); $installed_version = null; } // ############## import install/uninstall code if (isset($arr['codes']['code']) and is_array($arr['codes']['code'])) { $codes =& $arr['codes']['code']; if (!isset($codes[0])) { $codes = array($codes); } // run each of the codes foreach ($codes as $code) { // Run if: code version is * (meaning always run), no version // previously installed, or if the code is for a newer version // than is currently installed if ($code['version'] == '*' or $installed_version === null or is_newer_version($code['version'], $installed_version)) { eval($code['installcode']); } } // Clear routes from datastore build_datastore('routes', serialize(array()), 1); //assume that the product may have installed content types and purge the content type cache vB_Cache::instance()->purge('vb_types.types'); } // dependencies checked, install code run. Now clear out the old product info; // settings should be retained in memory already delete_product($info['productid'], false, true); if (is_array($codes)) { // we've now run all the codes, if execution is still going // then it's going to complete fully, so insert the codes $productCodes = array(); foreach ($codes as $code) { /* insert query */ $productCodes[] = array('productid' => $info['productid'], 'version' => $code['version'], 'installcode' => $code['installcode'], 'uninstallcode' => $code['uninstallcode']); } $assertor->insertMultiple('productcode', array('productid', 'version', 'installcode', 'uninstallcode'), $productCodes); } if (is_array($dependencies)) { // dependencies met, codes run -- now we can insert the dependencies into the DB $productDependencies = array(); foreach ($dependencies as $dependency) { /* insert query */ $productDependencies[] = array('productid' => $info['productid'], 'dependencytype' => $dependency['dependencytype'], 'parentproductid' => $dependency['parentproductid'], 'minversion' => $dependency['minversion'], 'maxversion' => $dependency['maxversion']); } $assertor->insertMultiple('productdependency', array('productid', 'dependencytype', 'parentproductid', 'minversion', 'maxversion'), $productDependencies); } /* insert query */ $assertor->insert('product', array('productid' => $info['productid'], 'title' => $info['title'], 'description' => $info['description'], 'version' => $info['version'], 'active' => intval($active), 'url' => $info['url'], 'versioncheckurl' => $info['versioncheckurl'])); // ############## import templates if (isset($arr['templates']['template']) and is_array($arr['templates']['template'])) { $querybits = array(); $querytemplates = 0; $templates =& $arr['templates']['template']; if (!isset($templates[0])) { $templates = array($templates); } foreach ($templates as $template) { $title = $template['name']; $template['template'] = $template['value']; $template['username'] = $template['username']; $template['templatetype'] = $template['templatetype']; $template['date'] = intval($template['date']); if ($template['templatetype'] != 'template') { // template is a special template $querybits[] = array('styleid' => -1, 'templatetype' => $template['templatetype'], 'title' => $title, 'template' => $template['template'], 'template_un' => '', 'dateline' => $template['date'], 'username' => $template['username'], 'version' => $template['version'], 'product' => $info['productid']); } else { // template is a standard template $querybits[] = array('styleid' => -1, 'templatetype' => $template['templatetype'], 'title' => $title, 'template' => compile_template($template['value']), 'template_un' => $template['template'], 'dateline' => $template['date'], 'username' => $template['username'], 'version' => $template['version'], 'product' => $info['productid']); } if (++$querytemplates % 20 == 0) { /*insert query*/ $assertor->assertQuery('replaceValues', array('values' => $querybits, 'table' => 'template')); $querybits = array(); } // Send some output to the browser inside this loop so certain hosts // don't artificially kill the script. See bug #34585 if (VB_AREA != 'Upgrade' and VB_AREA != 'Install') { echo ' '; vbflush(); } } // insert any remaining templates if (!empty($querybits)) { /*insert query*/ $assertor->assertQuery('replaceValues', array('values' => $querybits, 'table' => 'template')); } unset($querybits); $rebuild['templates'] = true; } // ############## import stylevars if (isset($arr['stylevardfns']['stylevargroup']) and is_array($arr['stylevardfns']['stylevargroup'])) { xml_import_stylevar_definitions($arr['stylevardfns'], $info['productid']); } if (!empty($arr['stylevars']) and is_array($arr['stylevars']) and is_array($arr['stylevars']['stylevar'])) { xml_import_stylevars($arr['stylevars'], -1); } // ############## import hooks if (isset($arr['hooks']['hook']) and is_array($arr['hooks']['hook'])) { $hooks =& $arr['hooks']['hook']; if (!isset($hooks[0])) { $hooks = array($hooks); } foreach ($hooks as $hook) { $hook['product'] = $info['productid']; $assertor->insert('hook', $hook); } $rebuild['hooks'] = true; } // ############## import phrases if (isset($arr['phrases']['phrasetype']) and is_array($arr['phrases']['phrasetype'])) { require_once DIR . '/includes/adminfunctions_language.php'; $master_phrasetypes = array(); $master_phrasefields = array(); foreach (vB_Api::instanceInternal('phrase')->fetch_phrasetypes(false) as $phrasetype) { $master_phrasefields["{$phrasetype['fieldname']}"] = true; } $phrasetypes =& $arr['phrases']['phrasetype']; if (!isset($phrasetypes[0])) { $phrasetypes = array($phrasetypes); } foreach ($phrasetypes as $phrasetype) { if (empty($phrasetype['phrase'])) { continue; } if ($phrasetype['fieldname'] == '' or !preg_match('#^[a-z0-9_]+$#i', $phrasetype['fieldname'])) { continue; } $fieldname = $master_phrasefields["{$phrasetype['fieldname']}"]; if (!$fieldname) { $assertor->assertQuery('installProductPhraseTypeInsert', array('fieldname' => $phrasetype['fieldname'], 'title' => $phrasetype['name'], 'editrows' => 3, 'product' => $info['productid'])); // need to add the column to the language table as well $assertor->assertQuery('addLanguageFromPackage', array('fieldname' => $phrasetype['fieldname'])); } $phrases =& $phrasetype['phrase']; if (!isset($phrases[0])) { $phrases = array($phrases); } $sql = array(); foreach ($phrases as $phrase) { $sql[] = array('languageid' => -1, 'fieldname' => $phrasetype['fieldname'], 'varname' => $phrase['name'], 'text' => $phrase['value'], 'product' => $info['productid'], 'username' => $phrase['username'], 'dateline' => $phrase['date'], 'version' => $phrase['version']); } /*insert query*/ $assertor->assertQuery('replaceValues', array('values' => $sql, 'table' => 'phrase')); } $rebuild['phrases'] = true; } // ############## import settings if (isset($arr['options']['settinggroup']) and is_array($arr['options']['settinggroup'])) { $settinggroups =& $arr['options']['settinggroup']; if (!isset($settinggroups[0])) { $settinggroups = array($settinggroups); } foreach ($settinggroups as $group) { if (empty($group['setting'])) { continue; } // create the setting group if it doesn't already exist $check = $assertor->assertQuery('settinggroup', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, 'grouptitle' => $group['name'])); if ($check->valid()) { $current = $check->current(); if ($group['adminperm'] != $current['adminperm'] or $group['displayorder'] != $current['displayorder']) { $assertor->assertQuery('settinggroup', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_UPDATE, 'grouptitle' => $group['name'], 'displayorder' => $group['displayorder'], 'adminperm' => $group['adminperm'])); } } else { /*insert query*/ $assertor->assertQuery('settinggroup', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_INSERTIGNORE, 'grouptitle' => $group['name'], 'displayorder' => $group['displayorder'], 'volatile' => 1, 'product' => $info['productid'], 'adminperm' => $group['adminperm'])); } $settings =& $group['setting']; if (!isset($settings[0])) { $settings = array($settings); } $setting_bits = array(); foreach ($settings as $setting) { if (isset($vbulletin->options["{$setting['varname']}"])) { $newvalue = $vbulletin->options["{$setting['varname']}"]; } else { $newvalue = $setting['defaultvalue']; } $setting_bits[] = array('varname' => $setting['varname'], 'grouptitle' => $group['name'], 'value' => trim($newvalue), 'defaultvalue' => trim($setting['defaultvalue']), 'datatype' => trim($setting['datatype']), 'optioncode' => $setting['optioncode'], 'displayorder' => $setting['displayorder'], 'advanced' => intval($setting['advanced']), 'volatile' => 1, 'validationcode' => $setting['validationcode'], 'blacklist' => $setting['blacklist'], 'ispublic' => intval($setting['public']), 'product' => $info['productid'], 'adminperm' => empty($setting['adminperm']) ? '' : $setting['adminperm']); } /*insert query*/ $assertor->assertQuery('replaceValues', array('values' => $setting_bits, 'table' => 'setting')); } $rebuild['options'] = true; } // ############## import admin help if (isset($arr['helptopics']['helpscript']) and is_array($arr['helptopics']['helpscript'])) { $help_scripts =& $arr['helptopics']['helpscript']; if (!isset($help_scripts[0])) { $help_scripts = array($help_scripts); } foreach ($help_scripts as $help_script) { // Deal with single entry if (!is_array($help_script['helptopic'][0])) { $help_script['helptopic'] = array($help_script['helptopic']); } $help_sql = array(); foreach ($help_script['helptopic'] as $topic) { $helpsql[] = array('script' => $help_script['name'], 'action' => $topic['act'], 'optionname' => $topic['opt'], 'displayorder' => intval($topic['disp']), 'volatile' => 1, 'product' => $info['productid']); } if (!empty($helpsql)) { /*insert query*/ $assertor->assertQuery('replaceValues', array('values' => $helpsql, 'table' => 'adminhelp')); } } } // ############## import cron if (isset($arr['cronentries']['cron']) and is_array($arr['cronentries']['cron'])) { require_once DIR . '/includes/functions_cron.php'; $cron_entries =& $arr['cronentries']['cron']; if (!isset($cron_entries[0])) { $cron_entries = array($cron_entries); } foreach ($cron_entries as $cron) { $cron['varname'] = preg_replace('#[^a-z0-9_]#i', '', $cron['varname']); if (!$cron['varname']) { continue; } $cron['active'] = $cron['active'] ? 1 : 0; $cron['loglevel'] = $cron['loglevel'] ? 1 : 0; $scheduling = $cron['scheduling']; $scheduling['weekday'] = intval($scheduling['weekday']); $scheduling['day'] = intval($scheduling['day']); $scheduling['hour'] = intval($scheduling['hour']); $scheduling['minute'] = explode(',', preg_replace('#[^0-9,-]#i', '', $scheduling['minute'])); if (count($scheduling['minute']) == 0) { $scheduling['minute'] = array(0); } else { $scheduling['minute'] = array_map('intval', $scheduling['minute']); } /*insert query*/ $cronSql[] = array('weekday' => $scheduling['weekday'], 'day' => $scheduling['day'], 'hour' => $scheduling['hour'], 'minute' => serialize($scheduling['minute']), 'filename' => $cron['filename'], 'loglevel' => $cron['loglevel'], 'active' => $cron['active'], 'varname' => $cron['varname'], 'volatile' => 1, 'product' => $info['productid']); $cronid = $assertor->assertQuery('replaceValues', array('values' => $cronSql, 'table' => 'cron', 'returnId' => true)); if ($cronid) { build_cron_item($cronid); } $rebuild['cron'] = true; } } // ############## import faq if (isset($arr['faqentries']['faq']) and is_array($arr['faqentries']['faq'])) { $faq_entries =& $arr['faqentries']['faq']; if (!isset($faq_entries[0])) { $faq_entries = array($faq_entries); } $sql = array(); foreach ($faq_entries as $faq) { $sql[] = array('faqname' => $faq['faqname'], 'faqparent' => $faq['faqparent'], 'displayorder' => intval($faq['displayorder']), 'volatile' => 1, 'product' => $info['productid']); } if ($sql) { /*insert query*/ $assertor->assertQuery('replaceValues', array('values' => $sql, 'table' => 'faq')); } } // ############## import widgets if (isset($arr['widgets']['widget']) and is_array($arr['widgets']['widget'])) { $widgetImporter = new vB_Xml_Import_Widget($info['productid']); $widgetImporter->importFromParsedXML($arr['widgets']); } // ############## import pagetemplates if (isset($arr['pagetemplates']['pagetemplate']) and is_array($arr['pagetemplates']['pagetemplate'])) { $pageTemplateImporter = new vB_Xml_Import_PageTemplate($info['productid']); $pageTemplateImporter->importFromParsedXML($arr['pagetemplates']); } // ############## import page if (isset($arr['pages']['page']) and is_array($arr['pages']['page'])) { $pageImporter = new vB_Xml_Import_Page($info['productid']); $pageImporter->importFromParsedXML($arr['pages']); } // ############## import channels if (isset($arr['channels']['channel']) and is_array($arr['channels']['channel'])) { $channelImporter = new vB_Xml_Import_Channel($info['productid']); $channelImporter->importFromParsedXML($arr['channels']); } // ############## import routes if (isset($arr['routes']['route']) and is_array($arr['routes']['route'])) { $routeImporter = new vB_Xml_Import_Route($info['productid']); $routeImporter->importFromParsedXML($arr['routes']); } if (isset($routeImporter)) { // update pages and channels with new route ids if (isset($pageImporter)) { $pageImporter->updatePageRoutes(); } if (isset($channelImporter)) { $channelImporter->updateChannelRoutes(); } } // Check if the hook system is disabled. If it is, enable it. if (!$vbulletin->options['enablehooks']) { $assertor->update('setting', array('value' => 1), array('varname' => 'enablehooks')); $rebuild['options'] = true; } // Now rebuild everything we need... if ($rebuild['hooks']) { vB_Api::instanceInternal("Hook")->buildHookDatastore(); } if ($rebuild['templates']) { if ($error = build_all_styles(0, 0, '', false, $verbose)) { return $error; } } if ($rebuild['phrases']) { require_once DIR . '/includes/adminfunctions_language.php'; build_language(); } if ($rebuild['options']) { vB::getDatastore()->build_options(); } if ($rebuild['cron']) { require_once DIR . '/includes/functions_cron.php'; build_cron_next_run(); } build_product_datastore(); // build bitfields to remove/add this products bitfields vB_Bitfield_Builder::save(); if ($verbose) { print_dots_stop(); } $info['need_merge'] = ($rebuild['templates'] and $installed_version); return $info; }
/** * Reads XML style file and imports data from it into the database * * @param string XML data * @param integer Style ID * @param integer Parent style ID * @param string New style title * @param boolean Allow vBulletin version mismatch * @param integer Display order for new style * @param boolean Allow user selection of new style * @param int|null Starting template group index for this run of importing templates (0 based). * Null means all templates (single run) * @paream int|null * * @return array Array of information about the imported style */ function xml_import_style( $xml = false, $styleid = -1, $parentid = -1, $title = '', $anyversion = false, $displayorder = 1, $userselect = true, $startat = null, $perpage = null ) { // $GLOBALS['path'] needs to be passed into this function or reference $vbulletin->GPC['path'] global $vbulletin, $vbphrase; print_dots_start('<b>' . $vbphrase['importing_style'] . "</b>, $vbphrase[please_wait]", ':', 'dspan'); require_once(DIR . '/includes/class_xml.php'); //where is this used? I hate having this random global value in the middle of this function $xmlobj = new vB_XML_Parser($xml, $vbulletin->GPC['path']); if ($xmlobj->error_no == 1) { print_dots_stop(); print_stop_message('no_xml_and_no_path'); } else if ($xmlobj->error_no == 2) { print_dots_stop(); print_stop_message('please_ensure_x_file_is_located_at_y', 'vbulletin-style.xml', $vbulletin->GPC['path']); } if(!$parsed_xml = $xmlobj->parse()) { print_dots_stop(); print_stop_message('xml_error_x_at_line_y', $xmlobj->error_string(), $xmlobj->error_line()); } $version = $parsed_xml['vbversion']; $master = ($parsed_xml['type'] == 'master' ? 1 : 0); $title = (empty($title) ? $parsed_xml['name'] : $title); $product = (empty($parsed_xml['product']) ? 'vbulletin' : $parsed_xml['product']); $one_pass = (is_null($startat) AND is_null($perpage)); if (!$one_pass AND (!is_numeric($startat) OR !is_numeric($perpage) OR $perpage <= 0 OR $startat < 0)) { print_dots_stop(); print_stop_message(''); } if ($one_pass OR ($startat == 0)) { // version check $full_product_info = fetch_product_list(true); $product_info = $full_product_info["$product"]; if ($version != $product_info['version'] AND !$anyversion AND !$master) { print_dots_stop(); print_stop_message('upload_file_created_with_different_version', $product_info['version'], $version); } //Initialize the style -- either init the master, create a new style, or verify the style to overwrite. if ($master) { $import_data = @unserialize(fetch_adminutil_text('master_style_import')); if (!empty($import_data) AND (TIMENOW - $import_data['last_import']) <= 30) { print_dots_stop(); print_stop_message('must_wait_x_seconds_master_style_import', vb_number_format($import_data['last_import'] + 30 - TIMENOW)); } // overwrite master style echo "<h3>$vbphrase[master_style]</h3>\n<p>$vbphrase[please_wait]</p>"; vbflush(); $vbulletin->db->query_write(" DELETE FROM " . TABLE_PREFIX . "template WHERE styleid = -10 AND (product = '" . $vbulletin->db->escape_string($product) . "'" . iif($product == 'vbulletin', " OR product = ''") . ")" ); $vbulletin->db->query_write(" UPDATE " . TABLE_PREFIX . "template SET styleid = -10 WHERE styleid = -1 AND (product = '" . $vbulletin->db->escape_string($product) . "'" . iif($product == 'vbulletin', " OR product = ''") . ") "); $styleid = -1; } else { if ($styleid == -1) { // creating a new style $test = $vbulletin->db->query_first(" SELECT styleid FROM " . TABLE_PREFIX . "style WHERE title = '" . $vbulletin->db->escape_string($title) . "'" ); if ($test) { print_dots_stop(); print_stop_message('style_already_exists', $title); } else { echo "<h3><b>" . construct_phrase($vbphrase['creating_a_new_style_called_x'], $title) . "</b></h3>\n<p>$vbphrase[please_wait]</p>"; vbflush(); /*insert query*/ $styleresult = $vbulletin->db->query_write(" INSERT INTO " . TABLE_PREFIX . "style (title, parentid, displayorder, userselect) VALUES ('" . $vbulletin->db->escape_string($title) . "', $parentid, $displayorder, " . ($userselect ? 1 : 0) . ") "); $styleid = $vbulletin->db->insert_id($styleresult); } } else { // overwriting an existing style if ($getstyle = $vbulletin->db->query_first("SELECT title FROM " . TABLE_PREFIX . "style WHERE styleid = $styleid")) { echo "<h3><b>" . construct_phrase($vbphrase['overwriting_style_x'], $getstyle['title']) . "</b></h3>\n<p>$vbphrase[please_wait]</p>"; vbflush(); } else { print_dots_stop(); print_stop_message('cant_overwrite_non_existent_style'); } } } } //load the templates if ($arr = $parsed_xml['templategroup']) { if (empty($arr[0])) { $arr = array($arr); } $templates_done = (is_numeric($startat) AND (count($arr) < $startat)); if ($one_pass OR !$templates_done) { if (!$one_pass) { $arr = array_slice($arr, $startat, $perpage); } xml_import_template_groups($styleid, $product, $arr, !$one_pass); } } else { $templates_done = true; } //note that templates may actually be done at this point, but templates_done is //only true if templates were completed in a prior step. If we are doing a multi-pass //process, we don't want to install stylevars in the same pass. We aren't really done //until we hit a pass where the templates are done before processing. $done = ($one_pass OR $templates_done); if ($done) { //load stylevars and definitions // re-import any stylevar definitions if ($master AND !empty($parsed_xml['stylevardfns']['stylevargroup'])) { xml_import_stylevar_definitions($parsed_xml['stylevardfns'], 'vbulletin'); } //if the tag is present but empty we'll end up with a string with whitespace which //is a non "empty" value. if (!empty($parsed_xml['stylevars']) AND is_array($parsed_xml['stylevars'])) { xml_import_stylevars($parsed_xml['stylevars'], $styleid); } if ($master) { xml_import_restore_adsense_templates(); build_adminutil_text('master_style_import', serialize(array('last_import' => TIMENOW))); } print_dots_stop(); } return array( 'version' => $version, 'master' => $master, 'title' => $title, 'product' => $product, 'done' => $done ); }
public function updateLanguagePhrases($params, $db, $check_only = false) { if ($check_only) { return !empty($params['languageid']) and !empty($params['def']) and !empty($params['fieldname']); } else { $params = vB::getCleaner()->cleanArray($params, array('def' => vB_Cleaner::TYPE_ARRAY_STR, 'phr' => vB_Cleaner::TYPE_ARRAY_STR, 'prod' => vB_Cleaner::TYPE_ARRAY_STR, 'fieldname' => vB_Cleaner::TYPE_STR, 'languageid' => vB_Cleaner::TYPE_INT)); $sql = array(); require_once DIR . '/includes/adminfunctions.php'; $full_product_info = fetch_product_list(true); $userinfo = vB::getCurrentSession()->fetch_userinfo(); foreach (array_keys($params['def']) as $varname) { $defphrase =& $params['def']["{$varname}"]; $newphrase =& $params['phr']["{$varname}"]; $product =& $params['prod']["{$varname}"]; $product_version = $full_product_info["{$product}"]['version']; if ($newphrase != $defphrase) { $sql[] = "\n\t\t\t\t\t\t(" . $params['languageid'] . ",\n\t\t\t\t\t\t'" . $db->escape_string($params['fieldname']) . "',\n\t\t\t\t\t\t'" . $db->escape_string($varname) . "',\n\t\t\t\t\t\t'" . $db->escape_string($newphrase) . "',\n\t\t\t\t\t\t'" . $db->escape_string($product) . "',\n\t\t\t\t\t\t'" . $db->escape_string($userinfo['username']) . "',\n\t\t\t\t\t\t" . TIMENOW . ",\n\t\t\t\t\t\t'" . $db->escape_string($product_version) . "')\n\t\t\t\t\t"; } } if (!empty($sql)) { $query = "\n\t\t\t\t\t### UPDATE CHANGED PHRASES FROM LANGUAGE:" . $vbulletin->GPC['dolanguageid'] . ", PHRASETYPE:" . $vbulletin->GPC['fieldname'] . " ###\n\t\t\t\t\tREPLACE INTO " . TABLE_PREFIX . "phrase\n\t\t\t\t\t\t(languageid, fieldname, varname, text, product, username, dateline, version)\n\t\t\t\t\tVALUES\n\t\t\t\t\t\t" . implode(",\n\t\t\t\t", $sql) . "\n\t\t\t\t"; $resultclass = 'vB_dB_' . $this->db_type . '_result'; $result = new $resultclass($db, $query); return $result; } } }
print_stop_message('no_file_uploaded_and_no_local_file_found'); } } xml_import_language($xml, $vbulletin->GPC['dolanguageid'], $vbulletin->GPC['title'], $vbulletin->GPC['anyversion']); build_language_datastore(); print_cp_redirect("language.php?" . $vbulletin->session->vars['sessionurl'] . "do=rebuild&goto=language.php?" . $vbulletin->session->vars['sessionurl'], 0); } // ########################################################################## if ($_REQUEST['do'] == 'files') { require_once DIR . '/includes/functions_misc.php'; $languages = fetch_language_titles_array('', 1); // download form print_form_header('language', 'download', 0, 1, 'downloadform" target="download'); print_table_header($vbphrase['download']); print_label_row($vbphrase['language'], '<select name="dolanguageid" tabindex="1" class="bginput">' . iif($vbulletin->debug, '<option value="-1">' . MASTER_LANGUAGE . '</option>') . construct_select_options($languages, $vbulletin->GPC['dolanguageid']) . '</select>', '', 'top', 'languageid'); print_select_row($vbphrase['product'], 'product', fetch_product_list()); print_input_row($vbphrase['filename'], 'filename', DEFAULT_FILENAME); print_yes_no_row($vbphrase['include_custom_phrases'], 'custom', 0); print_yes_no_row($vbphrase['just_fetch_phrases'], 'just_phrases', 0); print_submit_row($vbphrase['download']); ?> <script type="text/javascript"> <!-- function js_confirm_upload(tform, filefield) { if (filefield.value == "") { return confirm("<?php echo construct_phrase($vbphrase['you_did_not_specify_a_file_to_upload'], '" + tform.serverfile.value + "'); ?> ");
/** * Massive merge templates * * @param string $product Product string ID. * @param integer $startat Start offset of the merge. * * @return integer New startat value. -1 if no more to do. */ public function massMerge($product = 'vbulletin', $startat = 0) { $this->checkHasAdminPermission('canadmintemplates'); require_once DIR . '/includes/adminfunctions.php'; // TODO: Product API $full_product_info = fetch_product_list(true); $vbulletin =& vB::get_registry(); require_once DIR . '/includes/class_template_merge.php'; require_once DIR . '/includes/adminfunctions_template.php'; $merge = new vB_Template_Merge($vbulletin); $merge->time_limit = 5; $merge_data = new vB_Template_Merge_Data($vbulletin); $merge_data->start_offset = $startat; if ($product == 'vbulletin' or !$product) { $merge_data->add_condition("tnewmaster.product IN ('', 'vbulletin')"); } else { $merge_data->add_condition("tnewmaster.product = '" . mysql_escape_string($product) . "'"); $merge->merge_version = $full_product_info[$product]['version']; } $completed = $merge->merge_templates($merge_data, $output); if ($completed) { // completed build_all_styles(); vB_Library::instance('Style')->setCssDate(); return -1; } else { return $merge_data->start_offset + $merge->fetch_processed_count(); } }
$vbulletin->input->clean_array_gpc('r', array('group' => TYPE_STR, 'searchstring' => TYPE_STR, 'expandset' => TYPE_STR)); $template = $db->query_first("\n\t\tSELECT template.*, style.title AS style\n\t\tFROM " . TABLE_PREFIX . "template AS template\n\t\tLEFT JOIN " . TABLE_PREFIX . "style AS style USING(styleid)\n\t\tWHERE templateid = " . $vbulletin->GPC['templateid'] . "\n\t"); if ($template['styleid'] == -1) { $template['style'] = $vbphrase['global_templates']; } print_form_header('template', 'updatetemplate'); print_table_header(construct_phrase($vbphrase['x_y_id_z'], $vbphrase['template'], $template['title'], $template['templateid'])); construct_hidden_code('templateid', $template['templateid']); construct_hidden_code('group', $vbulletin->GPC['group']); construct_hidden_code('searchstring', $vbulletin->GPC['searchstring']); construct_hidden_code('dostyleid', $template['styleid']); construct_hidden_code('expandset', $vbulletin->GPC['expandset']); construct_hidden_code('oldtitle', $template['title']); construct_hidden_code('lastedit', $template['dateline']); $backlink = "template.php?" . $vbulletin->session->vars['sessionurl'] . "do=modify&expandset={$template['styleid']}&group=" . $vbulletin->GPC['group'] . "&templateid=" . $vbulletin->GPC['templateid'] . "&searchstring=" . urlencode($vbulletin->GPC['searchstring']); $products = fetch_product_list(); if ($template['styleid'] == -1) { print_select_row($vbphrase['product'], 'product', $products, $template['product']); } else { print_label_row($vbphrase['product'], $products[$template['product'] ? $template['product'] : 'vbulletin']); construct_hidden_code('product', $template['product'] ? $template['product'] : 'vbulletin'); } print_label_row($vbphrase['style'], "<a href=\"{$backlink}\" title=\"" . $vbphrase['edit_templates'] . "\"><b>{$template['style']}</b></a>"); print_input_row($vbphrase['title'] . ($template['styleid'] != -1 ? '<dfn>' . construct_link_code($vbphrase['view_history'], 'template.php?do=history&dostyleid=' . $template['styleid'] . '&title=' . urlencode($template['title']), 1) . '</dfn>' : ''), 'title', $template['title']); print_textarea_row($vbphrase['template'] . ' <br /><br /> <span class="smallfont">' . iif($template['styleid'] != -1, construct_link_code($vbphrase['show_default'], "template.php?" . $vbulletin->session->vars['sessionurl'] . "do=view&title={$template['title']}", 1) . '<br /><br />', '') . '<!--' . $vbphrase['wrap_text'] . '<input type="checkbox" unselectable="on" onclick="set_wordwrap(\'ta_template\', this.checked);" accesskey="w" checked="checked" />--> </span>', 'template', $template['template_un'], 22, '75" style="width:100%', true, true, 'ltr', 'code'); print_template_javascript(); print_label_row($vbphrase['save_in_template_history'], '<label for="savehistory"><input type="checkbox" name="savehistory" id="savehistory" value="1" tabindex="1" />' . $vbphrase['yes'] . '</label><br /><span class="smallfont">' . $vbphrase['comment'] . '</span> <input type="text" name="histcomment" value="" tabindex="1" class="bginput" size="50" />'); print_submit_row($vbphrase['save'], '_default_', 2, '', "<input type=\"submit\" class=\"button\" tabindex=\"1\" name=\"return\" value=\"{$vbphrase['save_and_reload']}\" accesskey=\"e\" />");
// select friendly name for current language $svname_result = $db->query_first("\r\n\t\t\t\tSELECT text\r\n\t\t\t\tFROM " . TABLE_PREFIX . "phrase\r\n\t\t\t\tWHERE\r\n\t\t\t\t\tvarname = 'stylevar_" . $db->escape_string($vbulletin->GPC['stylevarid']) . "_name'\r\n\t\t\t"); if (!empty($svname_result)) { $stylevar['friendlyname'] = $svname_result['text']; } // select description for current language $svdesc_result = $db->query_first("\r\n\t\t\t\tSELECT text\r\n\t\t\t\tFROM " . TABLE_PREFIX . "phrase\r\n\t\t\t\tWHERE\r\n\t\t\t\t\tvarname = 'stylevar_" . $db->escape_string($vbulletin->GPC['stylevarid']) . "_description'\r\n\t\t\t"); if (!empty($svdesc_result)) { $stylevar['description'] = $svdesc_result['text']; } } } // add / editing definition print_form_header('stylevar', 'dfn_dosave', 0, 1); print_table_header($vbphrase['add_new_stylevar']); print_select_row($vbphrase['product'], 'product', fetch_product_list(), $stylevar['product']); print_input_row($vbphrase['group'], 'svgroup', $stylevar['stylevargroup']); print_input_row($vbphrase['stylevarid'], 'stylevarid', $stylevar['stylevarid']); print_input_row($vbphrase['friendly_name'], 'svfriendlyname', $stylevar['friendlyname']); print_input_row($vbphrase['description'], 'svdescription', $stylevar['description']); // keys match with enum entry that we have, value should be mapped to a vbphrase $svtypesarray = array($vbphrase['simple_types'] => array('string' => $vbphrase['string'], 'numeric' => $vbphrase['numeric'], 'url' => $vbphrase['url'], 'path' => $vbphrase['path'], 'color' => $vbphrase['color'], 'imagedir' => $vbphrase['imagedir'], 'image' => $vbphrase['image'], 'fontlist' => $vbphrase['fontlist'], 'size' => $vbphrase['size']), $vbphrase['complex_types'] => array('background' => $vbphrase['background'], 'font' => $vbphrase['font'], 'textdecoration' => $vbphrase['text_decoration'], 'dimension' => $vbphrase['dimension'], 'border' => $vbphrase['border'], 'padding' => $vbphrase['padding'], 'margin' => $vbphrase['margin'])); print_select_row($vbphrase['data_type'], 'svdatatype', $svtypesarray, $stylevar['datatype']); print_input_row($vbphrase['validation_regular_expression'] . '<br />' . $vbphrase['validation_re_optional'], 'svvalidation', $stylevar['validation']); $svunitsarray = array('' => '', '%' => '%', 'px' => 'px', 'pt' => 'pt', 'em' => 'em', 'ex' => 'ex', 'pc' => 'pc', 'in' => 'in', 'cm' => 'cm', 'mm' => 'mm'); //not currently used by anything. // print_select_row($vbphrase['units'] . '<br />~~Optional, only used by numerics type, discarded by other datatypes~~', 'svunit', $svunitsarray, $stylevar['units']); construct_hidden_code('oldsvid', $stylevar['stylevarid']); print_submit_row($vbphrase['save']); } // ########################################################################
/** * Everything that comes after the install - no reason to break this up into chunks at present * */ public function post_install() { // dependencies checked, install code run. Now clear out the old product info; // settings should be retained in memory already delete_product($this->productinfo['productid'], false, true); $codes =& $this->productobj['codes']['code']; if (!isset($codes[0])) { $codes = array($codes); } if (is_array($codes)) { // we've now run all the codes, if execution is still going // then it's going to complete fully, so insert the codes foreach ($codes as $code) { /* insert query */ $this->db->query_write("\n\t\t\t\t\tINSERT INTO " . TABLE_PREFIX . "productcode\n\t\t\t\t\t\t(productid, version, installcode, uninstallcode)\n\t\t\t\t\tVALUES\n\t\t\t\t\t\t('" . $this->db->escape_string($this->productinfo['productid']) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string($code['version']) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string($code['installcode']) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string($code['uninstallcode']) . "')\n\t\t\t\t"); } } if (is_array($this->productobj['dependencies']['dependency'])) { $dependencies =& $this->productobj['dependencies']['dependency']; if (!isset($dependencies[0])) { $dependencies = array($dependencies); } // dependencies met, codes run -- now we can insert the dependencies into the DB foreach ($dependencies as $dependency) { /* insert query */ $this->db->query_write("\n\t\t\t\t\tINSERT INTO " . TABLE_PREFIX . "productdependency\n\t\t\t\t\t\t(productid, dependencytype, parentproductid, minversion, maxversion)\n\t\t\t\t\tVALUES\n\t\t\t\t\t\t('" . $this->db->escape_string($this->productinfo['productid']) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string($dependency['dependencytype']) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string($dependency['parentproductid']) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string($dependency['minversion']) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string($dependency['maxversion']) . "')\n\t\t\t\t"); } } /* insert query */ $this->db->query_write("\n\t\t\tINSERT INTO " . TABLE_PREFIX . "product\n\t\t\t\t(productid, title, description, version, active, url, versioncheckurl)\n\t\t\tVALUES\n\t\t\t\t('" . $this->db->escape_string($this->productinfo['productid']) . "',\n\t\t\t\t'" . $this->db->escape_string($this->productinfo['title']) . "',\n\t\t\t\t'" . $this->db->escape_string($this->productinfo['description']) . "',\n\t\t\t\t'" . $this->db->escape_string($this->productinfo['version']) . "',\n\t\t\t\t" . intval($this->active) . ",\n\t\t\t\t'" . $this->db->escape_string($this->productinfo['url']) . "',\n\t\t\t\t'" . $this->db->escape_string($this->productinfo['versioncheckurl']) . "')\n\t\t"); // ############## import templates if (!empty($this->productobj['templates']['template']) and is_array($this->productobj['templates']['template'])) { $querybits = array(); $querytemplates = 0; $templates =& $this->productobj['templates']['template']; if (!isset($templates[0])) { $templates = array($templates); } foreach ($templates as $template) { $title = $this->db->escape_string($template['name']); $template['template'] = $this->db->escape_string($template['value']); $template['username'] = $this->db->escape_string($template['username']); $template['templatetype'] = $this->db->escape_string($template['templatetype']); $template['date'] = intval($template['date']); if ($template['templatetype'] != 'template') { // template is a special template $querybits[] = "(-1, '{$template['templatetype']}', '{$title}', '{$template['template']}', '', {$template['date']}, '{$template['username']}', '" . $this->db->escape_string($template['version']) . "', '" . $this->db->escape_string($this->productinfo['productid']) . "')"; } else { // template is a standard template $querybits[] = "(-1, '{$template['templatetype']}', '{$title}', '" . $this->db->escape_string(compile_template($template['value'])) . "', '{$template['template']}', {$template['date']}, '{$template['username']}', '" . $this->db->escape_string($template['version']) . "', '" . $this->db->escape_string($this->productinfo['productid']) . "')"; } if (++$querytemplates % 20 == 0) { /*insert query*/ $this->db->query_write("\n\t\t\t\t\t\tREPLACE INTO " . TABLE_PREFIX . "template\n\t\t\t\t\t\t\t(styleid, templatetype, title, template, template_un, dateline, username, version, product)\n\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t\t" . implode(',', $querybits) . "\n\t\t\t\t\t"); $querybits = array(); } if (!defined('SUPPRESS_KEEPALIVE_ECHO')) { echo ' '; vbflush(); } } // insert any remaining templates if (!empty($querybits)) { /*insert query*/ $this->db->query_write("\n\t\t\t\t\tREPLACE INTO " . TABLE_PREFIX . "template\n\t\t\t\t\t\t(styleid, templatetype, title, template, template_un, dateline, username, version, product)\n\t\t\t\t\tVALUES\n\t\t\t\t\t\t" . implode(',', $querybits) . "\n\t\t\t\t"); } unset($querybits); $rebuild['templates'] = true; } if (is_array($this->productobj['templates_mobile']['template'])) { $querybits = array(); $querytemplates = 0; $templates =& $this->productobj['templates_mobile']['template']; if (!isset($templates[0])) { $templates = array($templates); } foreach ($templates as $template) { $title = $this->db->escape_string($template['name']); $template['template'] = $this->db->escape_string($template['value']); $template['username'] = $this->db->escape_string($template['username']); $template['templatetype'] = $this->db->escape_string($template['templatetype']); $template['date'] = intval($template['date']); if ($template['templatetype'] != 'template') { // template is a special template $querybits[] = "(-2, '{$template['templatetype']}', '{$title}', '{$template['template']}', '', {$template['date']}, '{$template['username']}', '" . $this->db->escape_string($template['version']) . "', '" . $this->db->escape_string($this->productinfo['productid']) . "')"; } else { // template is a standard template $querybits[] = "(-2, '{$template['templatetype']}', '{$title}', '" . $this->db->escape_string(compile_template($template['value'])) . "', '{$template['template']}', {$template['date']}, '{$template['username']}', '" . $this->db->escape_string($template['version']) . "', '" . $this->db->escape_string($this->productinfo['productid']) . "')"; } if (++$querytemplates % 20 == 0) { /*insert query*/ $this->db->query_write("\n\t\t\t\t\t\tREPLACE INTO " . TABLE_PREFIX . "template\n\t\t\t\t\t\t\t(styleid, templatetype, title, template, template_un, dateline, username, version, product)\n\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t\t" . implode(',', $querybits) . "\n\t\t\t\t\t"); $querybits = array(); } if (!defined('SUPPRESS_KEEPALIVE_ECHO')) { echo ' '; vbflush(); } } // insert any remaining templates if (!empty($querybits)) { /*insert query*/ $this->db->query_write("\n\t\t\t\t\tREPLACE INTO " . TABLE_PREFIX . "template\n\t\t\t\t\t\t(styleid, templatetype, title, template, template_un, dateline, username, version, product)\n\t\t\t\t\tVALUES\n\t\t\t\t\t\t" . implode(',', $querybits) . "\n\t\t\t\t"); } unset($querybits); $rebuild['templates'] = true; } // ############## import stylevars if (!empty($this->productobj['stylevardfns']['stylevargroup']) and is_array($this->productobj['stylevardfns']['stylevargroup'])) { xml_import_stylevar_definitions($this->productobj['stylevardfns'], $this->productinfo['productid'], -1); } if (!empty($this->productobj['stylevars']['stylevar']) and is_array($this->productobj['stylevars']['stylevar'])) { xml_import_stylevars($this->productobj['stylevars'], -1); } if (is_array($this->productobj['stylevardfns_mobile']['stylevargroup'])) { xml_import_stylevar_definitions($this->productobj['stylevardfns_mobile'], $this->productinfo['productid'], -2); } if (is_array($this->productobj['stylevars_mobile']['stylevar'])) { xml_import_stylevars($this->productobj['stylevars_mobile'], -2); } // ############## import hooks/plugins if (is_array($this->productobj['plugins']['plugin'])) { $plugins =& $this->productobj['plugins']['plugin']; if (!isset($plugins[0])) { $plugins = array($plugins); } foreach ($plugins as $plugin) { $plugin['product'] = $this->productinfo['productid']; unset($plugin['devkey']); $this->db->query_write(fetch_query_sql($plugin, 'plugin')); } $rebuild['plugins'] = true; } // ############## import phrases if (is_array($this->productobj['phrases']['phrasetype'])) { require_once DIR . '/includes/adminfunctions_language.php'; $master_phrasetypes = array(); $master_phrasefields = array(); foreach (fetch_phrasetypes_array(false) as $phrasetype) { $master_phrasefields["{$phrasetype['fieldname']}"] = true; } $phrasetypes =& $this->productobj['phrases']['phrasetype']; if (!isset($phrasetypes[0])) { $phrasetypes = array($phrasetypes); } foreach ($phrasetypes as $phrasetype) { if (empty($phrasetype['phrase'])) { continue; } if ($phrasetype['fieldname'] == '' or !preg_match('#^[a-z0-9_]+$#i', $phrasetype['fieldname'])) { continue; } $fieldname = $master_phrasefields["{$phrasetype['fieldname']}"]; if (!$fieldname) { $this->db->query_write("\n\t\t\t\t\t\tINSERT IGNORE INTO " . TABLE_PREFIX . "phrasetype\n\t\t\t\t\t\t\t(fieldname, title, editrows, product)\n\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t\t('" . $this->db->escape_string($phrasetype['fieldname']) . "',\n\t\t\t\t\t\t\t'" . $this->db->escape_string($phrasetype['name']) . "',\n\t\t\t\t\t\t\t3,\n\t\t\t\t\t\t\t'" . $this->db->escape_string($this->productinfo['productid']) . "')\n\t\t\t\t\t"); // need to add the column to the language table as well require_once DIR . '/includes/class_dbalter.php'; $this->db_alter = new vB_Database_Alter_MySQL($this->db); if ($this->db_alter->fetch_table_info('language')) { $this->db_alter->add_field(array('name' => "phrasegroup_{$phrasetype['fieldname']}", 'type' => 'mediumtext')); } } $phrases =& $phrasetype['phrase']; if (!isset($phrases[0])) { $phrases = array($phrases); } $sql = array(); foreach ($phrases as $phrase) { $sql[] = "\n\t\t\t\t\t\t(-1,\n\t\t\t\t\t\t'" . $this->db->escape_string($phrasetype['fieldname']) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string($phrase['name']) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string($phrase['value']) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string($this->productinfo['productid']) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string($phrase['username']) . "',\n\t\t\t\t\t\t" . intval($phrase['date']) . ",\n\t\t\t\t\t\t'" . $this->db->escape_string($phrase['version']) . "')\n\t\t\t\t\t"; } /*insert query*/ $this->db->query_write("\n\t\t\t\t\tREPLACE INTO " . TABLE_PREFIX . "phrase\n\t\t\t\t\t\t(languageid, fieldname, varname, text, product, username, dateline, version)\n\t\t\t\t\tVALUES\n\t\t\t\t\t\t" . implode(',', $sql)); } $rebuild['phrases'] = true; } // ############## import settings if (is_array($this->productobj['options']['settinggroup'])) { $settinggroups =& $this->productobj['options']['settinggroup']; if (!isset($settinggroups[0])) { $settinggroups = array($settinggroups); } foreach ($settinggroups as $group) { if (empty($group['setting'])) { continue; } // create the setting group if it doesn't already exist /*insert query*/ $this->db->query_write("\n\t\t\t\t\tINSERT IGNORE INTO " . TABLE_PREFIX . "settinggroup\n\t\t\t\t\t\t(grouptitle, displayorder, volatile, product)\n\t\t\t\t\tVALUES\n\t\t\t\t\t\t('" . $this->db->escape_string($group['name']) . "',\n\t\t\t\t\t\t" . intval($group['displayorder']) . ",\n\t\t\t\t\t\t1,\n\t\t\t\t\t\t'" . $this->db->escape_string($this->productinfo['productid']) . "')\n\t\t\t\t"); $settings =& $group['setting']; if (!isset($settings[0])) { $settings = array($settings); } $setting_bits = array(); foreach ($settings as $setting) { if (isset($this->registry->options["{$setting['varname']}"])) { $newvalue = $this->registry->options["{$setting['varname']}"]; } else { $newvalue = $setting['defaultvalue']; } $setting_bits[] = "(\n\t\t\t\t\t\t'" . $this->db->escape_string($setting['varname']) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string($group['name']) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string(trim($newvalue)) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string(trim($setting['defaultvalue'])) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string(trim($setting['datatype'])) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string($setting['optioncode']) . "',\n\t\t\t\t\t\t" . intval($setting['displayorder']) . ",\n\t\t\t\t\t\t" . intval($setting['advanced']) . ",\n\t\t\t\t\t\t1,\n\t\t\t\t\t\t'" . $this->db->escape_string($setting['validationcode']) . "',\n\t\t\t\t\t\t" . intval($setting['blacklist']) . ",\n\t\t\t\t\t\t'" . $this->db->escape_string($this->productinfo['productid']) . "'\n\t)"; } /*insert query*/ $this->db->query_write("\n\t\t\t\t\tREPLACE INTO " . TABLE_PREFIX . "setting\n\t\t\t\t\t\t(varname, grouptitle, value, defaultvalue, datatype, optioncode, displayorder, advanced, volatile, validationcode, blacklist, product)\n\t\t\t\t\tVALUES\n\t\t\t\t\t\t" . implode(",\n\t", $setting_bits)); } $rebuild['options'] = true; } // ############## import admin help if (!empty($this->productobj['helptopics']['helpscript']) and is_array($this->productobj['helptopics']['helpscript'])) { $help_scripts =& $this->productobj['helptopics']['helpscript']; if (!isset($help_scripts[0])) { $help_scripts = array($help_scripts); } foreach ($help_scripts as $help_script) { // Deal with single entry if (!is_array($help_script['helptopic'][0])) { $help_script['helptopic'] = array($help_script['helptopic']); } $help_sql = array(); foreach ($help_script['helptopic'] as $topic) { $helpsql[] = "\n\t\t\t\t\t\t('" . $this->db->escape_string($help_script['name']) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string($topic['act']) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string($topic['opt']) . "',\n\t\t\t\t\t\t" . intval($topic['disp']) . ",\n\t\t\t\t\t\t1,\n\t\t\t\t\t\t'" . $this->db->escape_string($this->productinfo['productid']) . "')\n\t\t\t\t\t"; } if (!empty($helpsql)) { /*insert query*/ $this->db->query_write("\n\t\t\t\t\t\tREPLACE INTO " . TABLE_PREFIX . "adminhelp\n\t\t\t\t\t\t\t(script, action, optionname, displayorder, volatile, product)\n\t\t\t\t\t\tVALUES\n\t\t\t\t\t\t\t" . implode(",\n\t", $helpsql)); } } } // ############## import cron if (!empty($this->productobj['cronentries']['cron']) and is_array($this->productobj['cronentries']['cron'])) { require_once DIR . '/includes/functions_cron.php'; $cron_entries =& $this->productobj['cronentries']['cron']; if (!isset($cron_entries[0])) { $cron_entries = array($cron_entries); } foreach ($cron_entries as $cron) { $cron['varname'] = preg_replace('#[^a-z0-9_]#i', '', $cron['varname']); if (!$cron['varname']) { continue; } $cron['active'] = $cron['active'] ? 1 : 0; $cron['loglevel'] = $cron['loglevel'] ? 1 : 0; $scheduling = $cron['scheduling']; $scheduling['weekday'] = intval($scheduling['weekday']); $scheduling['day'] = intval($scheduling['day']); $scheduling['hour'] = intval($scheduling['hour']); $scheduling['minute'] = explode(',', preg_replace('#[^0-9,-]#i', '', $scheduling['minute'])); if (count($scheduling['minute']) == 0) { $scheduling['minute'] = array(0); } else { $scheduling['minute'] = array_map('intval', $scheduling['minute']); } /*insert query*/ $this->db->query_write("\n\t\t\t\t\tREPLACE INTO " . TABLE_PREFIX . "cron\n\t\t\t\t\t\t(weekday, day, hour, minute, filename, loglevel, active, varname, volatile, product)\n\t\t\t\t\tVALUES\n\t\t\t\t\t\t({$scheduling['weekday']},\n\t\t\t\t\t\t{$scheduling['day']},\n\t\t\t\t\t\t{$scheduling['hour']},\n\t\t\t\t\t\t'" . $this->db->escape_string(serialize($scheduling['minute'])) . "',\n\t\t\t\t\t\t'" . $this->db->escape_string($cron['filename']) . "',\n\t\t\t\t\t\t{$cron['loglevel']},\n\t\t\t\t\t\t{$cron['active']},\n\t\t\t\t\t\t'" . $this->db->escape_string($cron['varname']) . "',\n\t\t\t\t\t\t1,\n\t\t\t\t\t\t'" . $this->db->escape_string($this->productinfo['productid']) . "')\n\t\t\t\t"); $cronid = $this->db->insert_id(); // replace either inserts, or deletes+inserts if ($cronid) { build_cron_item($cronid); } $rebuild['cron'] = true; } } // ############## import faq if (!empty($this->productobj['faqentries']['faq']) and is_array($this->productobj['faqentries']['faq'])) { $faq_entries =& $this->productobj['faqentries']['faq']; if (!isset($faq_entries[0])) { $faq_entries = array($faq_entries); } $sql = array(); foreach ($faq_entries as $faq) { $sql[] = "\n\t\t\t\t\t('" . $this->db->escape_string($faq['faqname']) . "',\n\t\t\t\t\t'" . $this->db->escape_string($faq['faqparent']) . "',\n\t\t\t\t\t" . intval($faq['displayorder']) . ",\n\t\t\t\t\t1,\n\t\t\t\t\t'" . $this->db->escape_string($this->productinfo['productid']) . "')\n\t\t\t\t"; } if ($sql) { /*insert query*/ $this->db->query_write("\n\t\t\t\t\tREPLACE INTO " . TABLE_PREFIX . "faq\n\t\t\t\t\t\t(faqname, faqparent, displayorder, volatile, product)\n\t\t\t\t\tVALUES\n\t\t\t\t\t\t" . implode(',', $sql) . "\n\t\t\t\t"); } } $this->productinfo['process'] = VB_AREA; $this->productinfo['username'] = '******' . VB_AREA; import_navigation($this->productobj, $this->productinfo); $products = fetch_product_list(true); // Check if the plugin system is disabled. If it is, enable it if this product isn't installed. if (!$this->registry->options['enablehooks'] and !$products[$this->productinfo['productid']]) { $this->db->query_write("\n\t\t\t\tUPDATE " . TABLE_PREFIX . "setting\n\t\t\t\tSET value = '1'\n\t\t\t\tWHERE varname = 'enablehooks'\n\t\t\t"); $rebuild['options'] = true; } // Now rebuild everything we need... if ($rebuild['plugins']) { vBulletinHook::build_datastore($this->db); if ($this->active) { $plugin_data = $this->db->query_read("\n\t\t\t\t\tSELECT *\n\t\t\t\t\tFROM " . TABLE_PREFIX . "datastore\n\t\t\t\t\tWHERE title IN ('pluginlist', 'pluginlistadmin')\n\t\t\t\t"); while ($plugin_info = $this->db->fetch_array($plugin_data)) { if ($plugin_info['title'] == 'pluginlist') { $this->registry->pluginlist = unserialize($plugin_info['data']); } else { if ($plugin_info['title'] == 'pluginlistadmin') { $this->registry->pluginlistadmin = unserialize($plugin_info['data']); } } } // enable any hooks -- this is mainly necessary for importing templates (template_safe_functions hook) if (!defined('DISABLE_HOOKS') and VB_AREA != 'Upgrade') { if (!empty($this->registry->pluginlistadmin) and is_array($this->registry->pluginlistadmin)) { $this->registry->pluginlist = array_merge($this->registry->pluginlist, $this->registry->pluginlistadmin); unset($this->registry->pluginlistadmin); } vBulletinHook::set_pluginlist($this->registry->pluginlist, $vbulletin->options['hookerrors']); } } } if ($rebuild['templates']) { if ($error = build_all_styles(0, 0, '', false, 'standard')) { return $error; } if ($error = build_all_styles(0, 0, '', false, 'mobile')) { return $error; } } if ($rebuild['phrases']) { require_once DIR . '/includes/adminfunctions_language.php'; build_language(); } if ($rebuild['options']) { build_options(); } if ($rebuild['cron']) { require_once DIR . '/includes/functions_cron.php'; build_cron_next_run(); } build_product_datastore(); build_activitystream_datastore(); // build bitfields to remove/add this products bitfields vB_Bitfield_Builder::save($this->db); // reload block types $blockmanager = vB_BlockManager::create($this->registry); $blockmanager->reloadBlockTypes(); print_dots_stop(); $this->productinfo['need_merge'] = ($rebuild['templates'] and $installed_version); return $this->productinfo; }
/** * Reads XML style file and imports data from it into the database * * @param string $xml XML data * @param integer $styleid Style ID * @param integer $parentid Parent style ID * @param string $title New style title * @param boolean $anyversion Allow vBulletin version mismatch * @param integer $displayorder Display order for new style * @param boolean $userselct Allow user selection of new style * @param int|null $startat Starting template group index for this run of importing templates (0 based). Null means all templates (single run) * @param int|null $perpage Number of templates to import at a time * @param boolean $scilent Run silently (do not echo) * @param array|boolean $parsed_xml Parsed array of XML data. If provided the function will ignore $xml and use the provided, already parsed data. * * @return array Array of information about the imported style */ function xml_import_style($xml = false, $styleid = -1, $parentid = -1, $title = '', $anyversion = false, $displayorder = 1, $userselect = true, $startat = null, $perpage = null, $scilent = false, $parsed_xml = false) { // $GLOBALS['path'] needs to be passed into this function or reference $vbulletin->GPC['path'] //checking the root node name if (!empty($xml)) { $r = new XMLReader(); if ($r->xml($xml)) { if ($r->read()) { $node_name = $r->name; if ($node_name != 'style') { print_stop_message2('file_uploaded_not_in_right_format_error'); } } else { //can not read the document print_stop_message2('file_uploaded_unreadable'); } } else { //can not open the xml print_stop_message2('file_uploaded_unreadable'); } } global $vbulletin; if (!$scilent) { $vbphrase = vB_Api::instanceInternal('phrase')->fetch(array('importing_style', 'please_wait', 'creating_a_new_style_called_x')); print_dots_start('<b>' . $vbphrase['importing_style'] . "</b>, {$vbphrase['please_wait']}", ':', 'dspan'); } require_once DIR . '/includes/class_xml.php'; if (empty($parsed_xml)) { //where is this used? I hate having this random global value in the middle of this function $xmlobj = new vB_XML_Parser($xml, $vbulletin->GPC['path']); if ($xmlobj->error_no() == 1) { if ($scilent) { throw new vB_Exception_AdminStopMessage('no_xml_and_no_path'); } print_dots_stop(); print_stop_message2('no_xml_and_no_path'); } else { if ($xmlobj->error_no() == 2) { if ($scilent) { throw new vB_Exception_AdminStopMessage(array('please_ensure_x_file_is_located_at_y', 'vbulletin-style.xml', $vbulletin->GPC['path'])); } print_dots_stop(); print_stop_message2(array('please_ensure_x_file_is_located_at_y', 'vbulletin-style.xml', $vbulletin->GPC['path'])); } } if (!($parsed_xml = $xmlobj->parse())) { if ($scilent) { throw new vB_Exception_AdminStopMessage(array('xml_error_x_at_line_y', $xmlobj->error_string(), $xmlobj->error_line())); } print_dots_stop(); print_stop_message2(array('xml_error_x_at_line_y', $xmlobj->error_string(), $xmlobj->error_line())); } } $version = $parsed_xml['vbversion']; $master = $parsed_xml['type'] == 'master' ? 1 : 0; $title = empty($title) ? $parsed_xml['name'] : $title; $product = empty($parsed_xml['product']) ? 'vbulletin' : $parsed_xml['product']; $one_pass = (is_null($startat) and is_null($perpage)); if (!$one_pass and (!is_numeric($startat) or !is_numeric($perpage) or $perpage <= 0 or $startat < 0)) { if ($scilent) { throw new vB_Exception_AdminStopMessage(''); } print_dots_stop(); print_stop_message2(''); } $outputtext = ''; if ($one_pass or $startat == 0) { require_once DIR . '/includes/adminfunctions.php'; // version check $full_product_info = fetch_product_list(true); $product_info = $full_product_info["{$product}"]; if ($version != $product_info['version'] and !$anyversion and !$master) { if ($scilent) { throw new vB_Exception_AdminStopMessage(array('upload_file_created_with_different_version', $product_info['version'], $version)); } print_dots_stop(); print_stop_message2(array('upload_file_created_with_different_version', $product_info['version'], $version)); } //Initialize the style -- either init the master, create a new style, or verify the style to overwrite. if ($master) { $import_data = @unserialize(fetch_adminutil_text('master_style_import')); if (!empty($import_data) and TIMENOW - $import_data['last_import'] <= 30) { if ($scilent) { throw new vB_Exception_AdminStopMessage(array('must_wait_x_seconds_master_style_import', vb_number_format($import_data['last_import'] + 30 - TIMENOW))); } print_dots_stop(); print_stop_message2(array('must_wait_x_seconds_master_style_import', vb_number_format($import_data['last_import'] + 30 - TIMENOW))); } // overwrite master style // if ($printInfo AND (VB_AREA != 'Upgrade' AND VB_AREA != 'Install')) // { // echo "<h3>$vbphrase[master_style]</h3>\n<p>$vbphrase[please_wait]</p>"; // vbflush(); // } $products = array($product); if ($product == 'vbulletin') { $products[] = ''; } vB::getDbAssertor()->assertQuery('vBForum:deleteProductTemplates', array('products' => $products)); vB::getDbAssertor()->assertQuery('vBForum:updateProductTemplates', array('products' => $products)); $styleid = -1; } else { if ($styleid == -1) { // creating a new style if (vB::getDbAssertor()->getRow('style', array('title' => $title))) { if ($scilent) { throw new vB_Exception_AdminStopMessage(array('style_already_exists', $title)); } print_dots_stop(); print_stop_message2(array('style_already_exists', $title)); } else { if (!$scilent) { if (VB_AREA != 'Upgrade' or VB_AREA != 'Install') { $outputtext = construct_phrase($vbphrase['creating_a_new_style_called_x'], $title) . "<br>\n"; } else { // this isn't compatible with the ajax installer echo "<h3><b>" . construct_phrase($vbphrase['creating_a_new_style_called_x'], $title) . "</b></h3>\n<p>{$vbphrase['please_wait']}</p>"; vbflush(); } } /*insert query*/ $styleid = vB::getDbAssertor()->insert('style', array('title' => $title, 'parentid' => $parentid, 'displayorder' => $displayorder, 'userselect' => $userselect ? 1 : 0)); if (is_array($styleid)) { $styleid = array_pop($styleid); } } } else { // overwriting an existing style if (vB::getDbAssertor()->getRow('style', array('styleid' => $styleid))) { // if ($printInfo AND (VB_AREA != 'Upgrade' AND VB_AREA != 'Install')) // { // echo "<h3><b>" . construct_phrase($vbphrase['overwriting_style_x'], $getstyle['title']) . "</b></h3>\n<p>$vbphrase[please_wait]</p>"; // vbflush(); // } } else { if ($scilent) { throw new vB_Exception_AdminStopMessage('cant_overwrite_non_existent_style'); } print_dots_stop(); print_stop_message2('cant_overwrite_non_existent_style'); } } } } else { //We should never get styleid = -1 unless $master is true; if ($styleid == -1 and !$master) { $stylerec = vB::getDbAssertor()->getRow('style', array('title' => $title)); if ($stylerec and intval($stylerec['styleid'])) { $styleid = $stylerec['styleid']; } else { if ($scilent) { throw new vB_Exception_AdminStopMessage(array('incorrect_style_setting', $title)); } print_dots_stop(); print_stop_message2(array('incorrect_style_setting', $title)); } } } //load the templates if ($arr = $parsed_xml['templategroup']) { if (empty($arr[0])) { $arr = array($arr); } $templates_done = (is_numeric($startat) and count($arr) <= $startat); if ($one_pass or !$templates_done) { if (!$one_pass) { $arr = array_slice($arr, $startat, $perpage); } $outputtext .= xml_import_template_groups($styleid, $product, $arr, !$one_pass); } } else { $templates_done = true; } //note that templates may actually be done at this point, but templates_done is //only true if templates were completed in a prior step. If we are doing a multi-pass //process, we don't want to install stylevars in the same pass. We aren't really done //until we hit a pass where the templates are done before processing. $done = ($one_pass or $templates_done); if ($done) { //load stylevars and definitions // re-import any stylevar definitions if ($master and !empty($parsed_xml['stylevardfns']['stylevargroup'])) { xml_import_stylevar_definitions($parsed_xml['stylevardfns'], 'vbulletin'); } //if the tag is present but empty we'll end up with a string with whitespace which //is a non "empty" value. if (!empty($parsed_xml['stylevars']) and is_array($parsed_xml['stylevars'])) { xml_import_stylevars($parsed_xml['stylevars'], $styleid); } if ($master) { xml_import_restore_ad_templates(); build_adminutil_text('master_style_import', serialize(array('last_import' => TIMENOW))); } if (!$scilent) { print_dots_stop(); } } $fastDs = vB_FastDS::instance(); //We want to force a fastDS rebuild, but we can't just call rebuild. There may be dual web servers, // and calling rebuild only rebuilds one of them. $options = vB::getDatastore()->getValue('miscoptions'); $options['tmtdate'] = vB::getRequest()->getTimeNow(); vB::getDatastore()->build('miscoptions', serialize($options), 1); return array('version' => $version, 'master' => $master, 'title' => $title, 'product' => $product, 'done' => $done, 'overwritestyleid' => $styleid, 'output' => $outputtext); }