/** * Verify if product upgrade step needs to be executed * * @param string version string */ private function verify_product_version($version = null) { if (!$this->caninstall) { $this->add_error($this->productresult, self::PHP_TRIGGER_ERROR, true); return false; } if (is_newer_version($this->product->installed_version, $version)) { $this->skip_message(); return false; } return true; }
/** * Used to do sorting of version number strings via usort(). * adminfunctions_template.php must be required before you use this! * * @param string Version number string 1 * @param string Version number string 2 * * @return integer 0 if the same, -1 if #1 < #2, 1 if #1 > #2 */ function version_sort($a, $b) { if ($a == $b) { return 0; } else { if ($a == '*') { // * < non-* return -1; } else { if ($b == '*') { // any non-* > * return 1; } } } return is_newer_version($a, $b) ? 1 : -1; }
/** * Execute install code for product * */ public function install() { $vbulletin =& $this->registry; $vbphrase =& $this->vbphrase; $db =& $vbulletin->db; // ############## import install/uninstall code if (is_array($this->productobj['codes']['code'])) { $codes =& $this->productobj['codes']['code']; if (!isset($codes[0])) { $codes = array($codes); } require_once DIR . "/includes/functions.php"; // 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 $this->installed_version === null or is_newer_version($code['version'], $this->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'); } }
//you'd end up with templates from multiple styles with no attempt to handle duplicates //and no requirement that the styles in question were parents/children of each other. if ($export_styleid == -1) { $sqlcondition = "styleid = -1"; $parentlist = "-1"; } else { // query everything from the specified style $style = $db->query_first($q = "SELECT * FROM " . TABLE_PREFIX . "style WHERE styleid = " . $export_styleid); $sqlcondition = "templateid IN(" . implode(',', unserialize($style['templatelist'])) . ")"; $parentlist = $style['parentlist']; } // ############## templates $gettemplates = $db->query_read("\r\n\t\tSELECT title, templatetype, username, dateline, version, product,\r\n\t\t\tIF(templatetype = 'template', template_un, template) AS template\r\n\t\tFROM " . TABLE_PREFIX . "template\r\n\t\tWHERE product = '" . $db->escape_string($vbulletin->GPC['productid']) . "'\r\n\t\t\tAND {$sqlcondition}\r\n\t\tORDER BY title\r\n\t"); $xml->add_group('templates'); while ($template = $db->fetch_array($gettemplates)) { if (is_newer_version($template['version'], $product_details['version'])) { // version in the template is newer than the version of the product, // which probably means it's using the vB version $template['version'] = $product_details['version']; } $xml->add_tag('template', $template['template'], array('name' => htmlspecialchars($template['title']), 'templatetype' => $template['templatetype'], 'date' => $template['dateline'], 'username' => $template['username'], 'version' => htmlspecialchars_uni($template['version'])), true); } $xml->close_group(); // ############## Stylevars $stylevarinfo = get_stylevars_for_export($vbulletin->GPC['productid'], $parentlist, true); $stylevar_cache = $stylevarinfo['stylevars']; $stylevar_dfn_cache = $stylevarinfo['stylevardfns']; $xml->add_group('stylevardfns'); foreach ($stylevar_dfn_cache as $stylevargroupname => $stylevargroup) { $xml->add_group('stylevargroup', array('name' => $stylevargroupname)); foreach ($stylevargroup as $stylevar) {
$customcache = array(); $templates = $db->query_read("\n\t\tSELECT tCustom.templateid, tCustom.title, tCustom.styleid,\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 . "template AS tGlobal ON (tGlobal.styleid = -1 AND tGlobal.title = tCustom.title)\n\t\tWHERE tCustom.styleid <> -1\n\t\t\tAND tCustom.templatetype = 'template'\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'])) { $customcache["{$template['styleid']}"]["{$template['templateid']}"] = $template; } } if (empty($customcache)) { print_stop_message('all_templates_are_up_to_date'); } cache_styles(); print_form_header('', ''); print_table_header($vbphrase['updated_default_templates']); print_description_row('<span class="smallfont">' . construct_phrase($vbphrase['updated_default_templates_desc'], $vbulletin->options['templateversion']) . '</span>'); print_table_break(' '); foreach ($stylecache as $styleid => $style) { if (is_array($customcache["{$styleid}"])) { print_description_row($style['title'], 0, 2, 'thead'); foreach ($customcache["{$styleid}"] as $templateid => $template) {
function log_upgrade_step() { global $vbulletin, $steptitles, $upgradecore_phrases; if (THIS_SCRIPT == 'finalupgrade.php') { return; } if (defined('SCRIPTCOMPLETE')) { require_once DIR . '/includes/adminfunctions_template.php'; if (is_newer_version(VERSION, $vbulletin->options['templateversion'])) { echo "<ul><li>" . $upgradecore_phrases['update_v_number']; $vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "setting SET value = '" . VERSION . "' WHERE varname = 'templateversion'"); } else { echo "<ul><li>" . $upgradecore_phrases['skipping_v_number_update']; } build_options(); echo "<b>{$upgradecore_phrases['done']}</b></li></ul>"; } if (is_numeric($vbulletin->GPC['step']) and !defined('NO_LOG')) { // use time() not TIMENOW to actually time the script's execution /*insert query*/ $vbulletin->db->query_write("\n\t\t\tINSERT INTO " . TABLE_PREFIX . "upgradelog(script, steptitle, step, startat, perpage, dateline)\n\t\t\tVALUES ('" . THIS_SCRIPT . "', '" . $vbulletin->db->escape_string($steptitles["{$vbulletin->GPC['step']}"]) . "', " . (defined('SCRIPTCOMPLETE') ? 0 : $vbulletin->GPC['step']) . ", {$vbulletin->GPC['startat']}, {$vbulletin->GPC['perpage']}, " . time() . ")\n\t\t"); } }
/** * Function used for usort'ing a collection of templates. * This function will return newer versions first. * * @param array First version * @param array Second version * * @return integer -1, 0, 1 */ function history_compare($a, $b) { // if either of them does not have a version, make it look really old to the // comparison tool so it doesn't get bumped all the way up when its not supposed to if (!$a['version']) { $a['version'] = "0.0.0"; } if (!$b['version']) { $b['version'] = "0.0.0"; } // these return values are backwards to sort in descending order if (is_newer_version($a['version'], $b['version'])) { return -1; } else if (is_newer_version($b['version'], $a['version'])) { return 1; } else { if($a['type'] == $b['type']) { return ($a['dateline'] > $b['dateline']) ? -1 : 1; } else if($a['type'] == "historical") { return 1; } else { return -1; } } }
while ($phrase = $db->fetch_array($phrases)) { if ($phrase['globalversion'] == '') { // No version on the global phrase. Wasn't edited in 3.6, // can't tell when it was last edited. Skip it. continue; } if ($phrase['customversion'] == '' and $phrase['globalversion'] < '3.6') { // don't know when the custom version was last edited, // and the global was edited before 3.6, so we don't know what's newer continue; } if (!$phrase['product']) { $phrase['product'] = 'vbulletin'; } $product_version = $full_product_info["{$phrase['product']}"]['version']; if (is_newer_version($phrase['globalversion'], $phrase['customversion'])) { $customcache["{$phrase['languageid']}"]["{$phrase['phraseid']}"] = $phrase; } } if (empty($customcache)) { print_stop_message('all_phrases_are_up_to_date'); } $languages = fetch_languages_array(); print_form_header('', ''); print_table_header($vbphrase['find_updated_phrases']); print_description_row('<span class="smallfont">' . construct_phrase($vbphrase['updated_default_phrases_desc'], $vbulletin->options['templateversion']) . '</span>'); print_table_break(' '); foreach ($languages as $languageid => $language) { if (is_array($customcache["{$languageid}"])) { print_description_row($language['title'], 0, 2, 'thead'); foreach ($customcache["{$languageid}"] as $phraseid => $phrase) {
/** * Determines whether a merge should be attempted on a template. * * @param array Array of template info. Record returned by data method. * * @return bool True if a merge should be attempted. */ public function can_merge_template($template_info) { if ($template_info['mergestatus'] == 'conflicted') { return false; } return is_newer_version($template_info['newmasterversion'], $template_info['oldmasterversion']); }
// see if we have a patch or something $safeid = preg_replace('#[^a-z0-9_]#', '', $product['productid']); if (file_exists(DIR . '/includes/version_' . $safeid . '.php')) { include_once(DIR . '/includes/version_' . $safeid . '.php'); } $define_name = 'FILE_VERSION_' . strtoupper($safeid); if (defined($define_name) AND constant($define_name) !== '') { $product['version'] = constant($define_name); } print_form_header('', ''); if (is_newer_version($latest_version, $product['version'])) { print_table_header(construct_phrase($vbphrase['product_x_out_of_date'], htmlspecialchars_uni($product['title']))); print_label_row($vbphrase['installed_version'], htmlspecialchars_uni($product['version'])); print_label_row($vbphrase['latest_version'], htmlspecialchars_uni($latest_version)); if ($product['url']) { print_description_row( '<a href="' . htmlspecialchars_uni($product['url']) . '" target="_blank">' . $vbphrase['click_here_for_more_info'] . '</a>', false, 2, '', 'center' ); } }
/** * Reads all data from the bbcode table and writes the serialized data to the datastore */ function build_bbcode_cache() { global $vbulletin; DEVDEBUG("Updating bbcode cache template..."); $bbcodes = $vbulletin->db->query_read("\n\t\tSELECT *\n\t\tFROM " . TABLE_PREFIX . "bbcode\n\t"); $bbcodearray = array(); while ($bbcode = $vbulletin->db->fetch_array($bbcodes)) { $bbcodearray["{$bbcode['bbcodeid']}"] = array(); foreach ($bbcode as $field => $value) { if (!is_numeric($field)) { $bbcodearray["{$bbcode['bbcodeid']}"]["{$field}"] = $value; } } $bbcodearray["{$bbcode['bbcodeid']}"]['strip_empty'] = intval($bbcode['options']) & $vbulletin->bf_misc['bbcodeoptions']['strip_empty'] ? 1 : 0; $bbcodearray["{$bbcode['bbcodeid']}"]['stop_parse'] = intval($bbcode['options']) & $vbulletin->bf_misc['bbcodeoptions']['stop_parse'] ? 1 : 0; $bbcodearray["{$bbcode['bbcodeid']}"]['disable_smilies'] = intval($bbcode['options']) & $vbulletin->bf_misc['bbcodeoptions']['disable_smilies'] ? 1 : 0; $bbcodearray["{$bbcode['bbcodeid']}"]['disable_wordwrap'] = intval($bbcode['options']) & $vbulletin->bf_misc['bbcodeoptions']['disable_wordwrap'] ? 1 : 0; } build_datastore('bbcodecache', serialize($bbcodearray), 1); $vbulletin->db->query_write("TRUNCATE TABLE " . TABLE_PREFIX . "postparsed"); // bbcodes changed, so posts could parse differently if (is_newer_version($vbulletin->options['templateversion'], '3.6', true)) { $vbulletin->db->query_write("TRUNCATE TABLE " . TABLE_PREFIX . "sigparsed"); } ($hook = vBulletinHook::fetch_hook('admin_cache_bbcode')) ? eval($hook) : false; }
/** * Find custom phrases that need updating * @return array Updated phrases */ public function findUpdates() { $this->checkHasAdminPermission('canadminlanguages'); require_once DIR . '/includes/adminfunctions_template.php'; require_once DIR . '/includes/adminfunctions.php'; $full_product_info = fetch_product_list(true); // query custom phrases $customcache = array(); $phrases = vB::getDbAssertor()->getRows('phrase_fetchupdates', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_STORED)); foreach ($phrases as $phrase) { if ($phrase['globalversion'] == '') { // No version on the global phrase. Wasn't edited in 3.6, // can't tell when it was last edited. Skip it. continue; } if ($phrase['customversion'] == '' and $phrase['globalversion'] < '3.6') { // don't know when the custom version was last edited, // and the global was edited before 3.6, so we don't know what's newer continue; } if (!$phrase['product']) { $phrase['product'] = 'vbulletin'; } $product_version = $full_product_info["{$phrase['product']}"]['version']; if (is_newer_version($phrase['globalversion'], $phrase['customversion'])) { $customcache["{$phrase['languageid']}"]["{$phrase['phraseid']}"] = $phrase; } } return $customcache; }
/** * Log the current location of the upgrade * * @param string Upgrade Step * @param int Startat value for multi step steps * @param bool Process only the current version upgrade */ public function log_upgrade_step($step, $startat = 0, $only = false) { $complete = $step == $this->stepcount; $perpage = 0; $insertstep = true; if ($complete) { $step = 0; if ($this->SHORT_VERSION == 'final' or $only) { $this->db->query_write("\n\t\t\t\t\tDELETE FROM " . TABLE_PREFIX . "upgradelog\n\t\t\t\t\tWHERE script IN ('final', 'vbblog', 'vbcms', 'skimlinks', 'forumrunner', 'postrelease')\n\t\t\t\t"); $insertstep = false; } else { if (is_newer_version($this->LONG_VERSION, $this->registry->options['templateversion'])) { $this->db->query_write("UPDATE " . TABLE_PREFIX . "setting SET value = '" . $this->LONG_VERSION . "' WHERE varname = 'templateversion'"); } if (!defined('SKIPDB')) { build_options(); } $this->registry->options['templateversion'] = $this->LONG_VERSION; } } if ($insertstep and !defined('SKIPDB')) { // use time() not TIMENOW to actually time the script's execution /*insert query*/ $this->db->query_write("\n\t\t\t\tINSERT INTO " . TABLE_PREFIX . "upgradelog(script, steptitle, step, startat, perpage, dateline, only)\n\t\t\t\tVALUES (\n\t\t\t\t\t'" . $this->db->escape_string($this->SHORT_VERSION) . "',\n\t\t\t\t\t'',\n\t\t\t\t\t{$step},\n\t\t\t\t\t{$startat},\n\t\t\t\t\t{$perpage},\n\t\t\t\t\t" . time() . ",\n\t\t\t\t\t" . intval($only) . "\n\t\t\t)"); } }
/** * Updates the setting table based on data passed in then rebuilds the datastore. * Only entries in the array are updated (allows partial updates). * * @param array Array of settings. Format: [setting_name] = new_value */ function save_settings($settings) { global $vbulletin, $vbphrase; $varnames = array(); foreach (array_keys($settings) as $varname) { $varnames[] = $vbulletin->db->escape_string($varname); } $rebuildstyle = false; $oldsettings = $vbulletin->db->query_read("\n\t\tSELECT value, varname, datatype, optioncode\n\t\tFROM " . TABLE_PREFIX . "setting\n\t\tWHERE varname IN ('" . implode("', '", $varnames) . "')\n\t\tORDER BY varname\n\t"); while ($oldsetting = $vbulletin->db->fetch_array($oldsettings)) { switch ($oldsetting['varname']) { // ************************************************** case 'bbcode_html_colors': $settings['bbcode_html_colors'] = serialize($settings['bbcode_html_colors']); break; // ************************************************** // ************************************************** case 'styleid': $vbulletin->db->query_write("\n\t\t\t\t\tUPDATE " . TABLE_PREFIX . "style\n\t\t\t\t\tSET userselect = 1\n\t\t\t\t\tWHERE styleid = " . $settings['styleid'] . "\n\t\t\t\t"); break; case 'as_content': $vbulletin->db->query_write("\n\t\t\t\t\tUPDATE " . TABLE_PREFIX . "activitystreamtype\n\t\t\t\t\tSET enabled = 0;\n\t\t\t\t"); $vbulletin->db->query_write("\n\t\t\t\t\tUPDATE " . TABLE_PREFIX . "activitystreamtype\n\t\t\t\t\tSET enabled = 1\n\t\t\t\t\tWHERE typeid IN (" . implode(",", array_keys($vbulletin->GPC['setting']['as_content'])) . ")\n\t\t\t\t"); build_activitystream_datastore(); $settings['as_content'] = ''; break; // ************************************************** // ************************************************** case 'banemail': build_datastore('banemail', $settings['banemail']); $settings['banemail'] = ''; break; // ************************************************** // ************************************************** case 'editormodes': $vbulletin->input->clean_array_gpc('p', array('fe' => TYPE_UINT, 'qr' => TYPE_UINT, 'qe' => TYPE_UINT)); $settings['editormodes'] = serialize(array('fe' => $vbulletin->GPC['fe'], 'qr' => $vbulletin->GPC['qr'], 'qe' => $vbulletin->GPC['qe'])); break; // ************************************************** // ************************************************** case 'cookiepath': case 'cookiedomain': if ($settings[$oldsetting['varname'] . '_other'] and $settings[$oldsetting['varname'] . '_value']) { $settings[$oldsetting['varname']] = $settings[$oldsetting['varname'] . '_value']; } break; case 'apipostidmanage': $store = array('enable' => $settings['apipostidmanage']['enable'], 'iphone' => $settings['apipostidmanage']['iphone'], 'android' => $settings['apipostidmanage']['android'], 'facebook' => $settings['apipostidmanage']['facebook']); $settings["{$oldsetting['varname']}"] = serialize($store); break; // ************************************************** // ************************************************** default: ($hook = vBulletinHook::fetch_hook('admin_options_processing')) ? eval($hook) : false; if ($oldsetting['optioncode'] == 'multiinput') { $store = array(); foreach ($settings["{$oldsetting['varname']}"] as $value) { if ($value != '') { $store[] = $value; } } $settings["{$oldsetting['varname']}"] = serialize($store); } else { if (preg_match('#^(usergroup|forum)s?:([0-9]+|all|none)$#', $oldsetting['optioncode'])) { // serialize the array of usergroup inputs if (!is_array($settings["{$oldsetting['varname']}"])) { $settings["{$oldsetting['varname']}"] = array(); } $settings["{$oldsetting['varname']}"] = array_map('intval', $settings["{$oldsetting['varname']}"]); $settings["{$oldsetting['varname']}"] = serialize($settings["{$oldsetting['varname']}"]); } } } $newvalue = validate_setting_value($settings["{$oldsetting['varname']}"], $oldsetting['datatype']); // this is a strict type check because we want '' to be different from 0 // some special cases below only use != checks to see if the logical value has changed if (strval($oldsetting['value']) !== strval($newvalue)) { switch ($oldsetting['varname']) { case 'activememberdays': case 'activememberoptions': if ($oldsetting['value'] != $newvalue) { $vbulletin->options["{$oldsetting['varname']}"] = $newvalue; require_once DIR . '/includes/functions_databuild.php'; build_birthdays(); } break; case 'showevents': case 'showholidays': if ($oldsetting['value'] != $newvalue) { $vbulletin->options["{$oldsetting['varname']}"] = $newvalue; require_once DIR . '/includes/functions_calendar.php'; build_events(); } break; case 'languageid': if ($oldsetting['value'] != $newvalue) { $vbulletin->options['languageid'] = $newvalue; require_once DIR . '/includes/adminfunctions_language.php'; build_language($vbulletin->options['languageid']); } break; case 'cpstylefolder': $admindm =& datamanager_init('Admin', $vbulletin, ERRTYPE_CP); $admindm->set_existing($vbulletin->userinfo); $admindm->set('cssprefs', $newvalue); $admindm->save(); unset($admindm); break; case 'smcolumns': case 'attachthumbssize': if ($oldsetting['value'] != $newvalue) { $rebuildstyle = true; } case 'storecssasfile': if (!is_demo_mode() and $oldsetting['value'] != $newvalue) { $vbulletin->options['storecssasfile'] = $newvalue; $rebuildstyle = true; } break; case 'loadlimit': update_loadavg(); break; case 'tagcloud_usergroup': build_datastore('tagcloud', serialize(''), 1); break; case 'censorwords': case 'codemaxlines': case 'url_nofollow': case 'url_nofollow_whitelist': if ($oldsetting['value'] != $newvalue) { $vbulletin->db->query_write("TRUNCATE TABLE " . TABLE_PREFIX . "postparsed"); if (is_newer_version($vbulletin->options['templateversion'], '3.6', true)) { $vbulletin->db->query_write("TRUNCATE TABLE " . TABLE_PREFIX . "sigparsed"); } } ($hook = vBulletinHook::fetch_hook('admin_options_processing_censorcode')) ? eval($hook) : false; break; case 'album_recentalbumdays': if ($oldsetting['value'] > $newvalue) { require_once DIR . '/includes/functions_album.php'; exec_rebuild_album_updates(); } default: ($hook = vBulletinHook::fetch_hook('admin_options_processing_build')) ? eval($hook) : false; } if (is_demo_mode() and in_array($oldsetting['varname'], array('storecssasfile', 'attachfile', 'usefileavatar', 'errorlogdatabase', 'errorlogsecurity', 'safeupload', 'tmppath'))) { continue; } $vbulletin->db->query_write("\n\t\t\t\tUPDATE " . TABLE_PREFIX . "setting\n\t\t\t\tSET value = '" . $vbulletin->db->escape_string($newvalue) . "'\n\t\t\t\tWHERE varname = '" . $vbulletin->db->escape_string($oldsetting['varname']) . "'\n\t\t\t"); } } build_options(); if ($rebuildstyle) { require_once DIR . '/includes/adminfunctions_template.php'; print_rebuild_style(-1, '', 1, 0, 0, 0); print_rebuild_style(-2, '', 1, 0, 0, 0); } }
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); }