Пример #1
0
 /**
  * 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;
 }
Пример #2
0
 $xml->add_group('plugins');
 $plugins = $db->query_read("\r\n\t\tSELECT *\r\n\t\tFROM " . TABLE_PREFIX . "plugin\r\n\t\tWHERE product = '" . $db->escape_string($vbulletin->GPC['productid']) . "'\r\n\t\tORDER BY hookname\r\n\t");
 while ($plugin = $db->fetch_array($plugins)) {
     $params = array('active' => $plugin['active'], 'executionorder' => $plugin['executionorder']);
     $xml->add_group('plugin', $params);
     $xml->add_tag('title', $plugin['title']);
     $xml->add_tag('hookname', $plugin['hookname']);
     $xml->add_tag('phpcode', $plugin['phpcode']);
     $xml->close_group();
 }
 unset($plugin);
 $db->free_result($plugins);
 $xml->close_group();
 // ############## phrases
 require_once DIR . '/includes/adminfunctions_language.php';
 $phrasetypes = fetch_phrasetypes_array(false);
 $phrases = array();
 $getphrases = $db->query_read("\r\n\t\tSELECT *\r\n\t\tFROM " . TABLE_PREFIX . "phrase\r\n\t\tWHERE languageid IN (" . implode(',', $export_languageids) . ")\r\n\t\t\tAND product = '" . $db->escape_string($vbulletin->GPC['productid']) . "'\r\n\t\tORDER BY languageid, fieldname, varname\r\n\t");
 while ($getphrase = $db->fetch_array($getphrases)) {
     $phrases["{$getphrase['fieldname']}"]["{$getphrase['varname']}"] = $getphrase;
 }
 unset($getphrase);
 $db->free_result($getphrases);
 $xml->add_group('phrases');
 // make sure the phrasegroups are in a reliable order
 ksort($phrases);
 foreach ($phrases as $_fieldname => $typephrases) {
     // create a group for each phrase type that we have phrases for
     // then insert the phrases
     $xml->add_group('phrasetype', array('name' => $phrasetypes["{$_fieldname}"]['title'], 'fieldname' => $_fieldname));
     // make sure the phrases are in a reliable order
Пример #3
0
/**
* Imports a language from a language XML file
*
* @param	string	XML language string
* @param	integer	Language to overwrite
* @param	string	Override title for imported language
* @param	boolean	Allow import of language from mismatched vBulletin version
* @param	boolean	Allow user-select of imported language
* @param	boolean	Echo output..
* @param	boolean	Read charset from XML header
*/
function xml_import_language($xml = false, $languageid = -1, $title = '', $anyversion = false, $userselect = true, $output = true, $readcharset = false)
{
    global $vbulletin, $vbphrase;
    print_dots_start('<b>' . $vbphrase['importing_language'] . "</b>, {$vbphrase['please_wait']}", ':', 'dspan');
    require_once DIR . '/includes/class_xml.php';
    require_once DIR . '/includes/functions_misc.php';
    $xmlobj = new vB_XML_Parser($xml, $GLOBALS['path'], $readcharset);
    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-language.xml', $GLOBALS['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['phrasetype']) {
        print_dots_stop();
        print_stop_message('invalid_file_specified');
    }
    $title = empty($title) ? $arr['name'] : $title;
    $version = $arr['vbversion'];
    $master = $arr['type'] == 'master' ? 1 : 0;
    $just_phrases = $arr['type'] == 'phrases' ? 1 : 0;
    if (!empty($arr['settings'])) {
        $langinfo = $arr['settings'];
    }
    $langinfo['product'] = empty($arr['product']) ? 'vbulletin' : $arr['product'];
    // look for skipped groups
    $skipped_groups = array();
    if (!empty($arr['skippedgroups'])) {
        $skippedgroups =& $arr['skippedgroups']['skippedgroup'];
        if (!is_array($skippedgroups[0])) {
            $skippedgroups = array($skippedgroups);
        }
        foreach ($skippedgroups as $skipped) {
            if (is_array($skipped)) {
                $skipped_groups[] = $vbulletin->db->escape_string($skipped['value']);
            } else {
                $skipped_groups[] = $vbulletin->db->escape_string($skipped);
            }
        }
    }
    if ($skipped_groups) {
        $sql_skipped = "AND " . TABLE_PREFIX . "phrase.fieldname NOT IN ('" . implode("', '", $skipped_groups) . "')";
    } else {
        $sql_skipped = '';
    }
    foreach ($langinfo as $key => $val) {
        $langinfo["{$key}"] = $vbulletin->db->escape_string(trim($val));
    }
    $langinfo['options'] = intval($langinfo['options']);
    if ($version != $vbulletin->options['templateversion'] and !$anyversion and !$master) {
        print_dots_stop();
        print_stop_message('upload_file_created_with_different_version', $vbulletin->options['templateversion'], $version);
    }
    //set up the phrase array
    $arr = $arr['phrasetype'];
    if (!is_array($arr[0])) {
        $arr = array($arr);
    }
    //spin through the phrases to check validity.  We want to do this *before* we prep for import
    //so that if we abort do to an error, we haven't made any changes first
    foreach (array_keys($arr) as $key) {
        $phraseTypes =& $arr["{$key}"];
        foreach ($phraseTypes['phrase'] as $phrase) {
            if (!validate_string_for_interpolation($phrase['value'])) {
                print_dots_stop();
                print_stop_message('phrase_text_not_safe', $phrase['name']);
            }
        }
    }
    // prepare for import
    if ($master) {
        // lets stop it from dieing cause someone borked a previous update
        $vbulletin->db->query_write("DELETE FROM " . TABLE_PREFIX . "phrase WHERE languageid = -10");
        // master style
        if ($output and VB_AREA != 'Install' and VB_AREA != 'Upgrade') {
            echo "<h3>{$vbphrase['master_language']}</h3>\n<p>{$vbphrase['please_wait']}</p>";
            vbflush();
        }
        $vbulletin->db->query_write("\n\t\t\tUPDATE " . TABLE_PREFIX . "phrase SET\n\t\t\t\tlanguageid = -10\n\t\t\tWHERE languageid = -1\n\t\t\t\tAND (product = '" . $vbulletin->db->escape_string($langinfo['product']) . "'" . iif($langinfo['product'] == 'vbulletin', " OR product = ''") . ")\n\t\t\t\t{$sql_skipped}\n\t\t");
        $languageid = -1;
    } else {
        if ($languageid == 0) {
            // creating a new language
            if ($just_phrases) {
                print_dots_stop();
                print_stop_message('language_only_phrases', $title);
            } else {
                if ($test = $vbulletin->db->query_first("SELECT languageid FROM " . TABLE_PREFIX . "language WHERE title = '" . $vbulletin->db->escape_string($title) . "'")) {
                    print_dots_stop();
                    print_stop_message('language_already_exists', $title);
                } else {
                    echo "<h3><b>" . construct_phrase($vbphrase['creating_a_new_language_called_x'], $title) . "</b></h3>\n<p>{$vbphrase['please_wait']}</p>";
                    vbflush();
                    /*insert query*/
                    $vbulletin->db->query_write("\n\t\t\t\t\tINSERT INTO " . TABLE_PREFIX . "language (\n\t\t\t\t\t\ttitle, options, languagecode, charset,\n\t\t\t\t\t\tdateoverride, timeoverride, decimalsep, thousandsep,\n\t\t\t\t\t\tregistereddateoverride, calformat1override, calformat2override, locale, logdateoverride\n\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t'" . $vbulletin->db->escape_string($title) . "', {$langinfo['options']}, '{$langinfo['languagecode']}', '{$langinfo['charset']}',\n\t\t\t\t\t\t'{$langinfo['dateoverride']}', '{$langinfo['timeoverride']}', '{$langinfo['decimalsep']}', '{$langinfo['thousandsep']}',\n\t\t\t\t\t\t'{$langinfo['registereddateoverride']}', '{$langinfo['calformat1override']}', '{$langinfo['calformat2override']}', '{$langinfo['locale']}', '{$langinfo['logdateoverride']}'\n\t\t\t\t\t)\n\t\t\t\t");
                    $languageid = $vbulletin->db->insert_id();
                }
            }
        } else {
            // overwriting an existing language
            if ($getlanguage = $vbulletin->db->query_first("SELECT title FROM " . TABLE_PREFIX . "language WHERE languageid = {$languageid}")) {
                if (!$just_phrases) {
                    echo "<h3><b>" . construct_phrase($vbphrase['overwriting_language_x'], $getlanguage['title']) . "</b></h3>\n<p>{$vbphrase['please_wait']}</p>";
                    vbflush();
                    $vbulletin->db->query_write("\n\t\t\t\t\t\tUPDATE " . TABLE_PREFIX . "language SET\n\t\t\t\t\t\t\toptions = {$langinfo['options']},\n\t\t\t\t\t\t\tlanguagecode = '{$langinfo['languagecode']}',\n\t\t\t\t\t\t\tcharset = '{$langinfo['charset']}',\n\t\t\t\t\t\t\tlocale = '{$langinfo['locale']}',\n\t\t\t\t\t\t\timagesoverride = '{$langinfo['imagesoverride']}',\n\t\t\t\t\t\t\tdateoverride = '{$langinfo['dateoverride']}',\n\t\t\t\t\t\t\ttimeoverride = '{$langinfo['timeoverride']}',\n\t\t\t\t\t\t\tdecimalsep = '{$langinfo['decimalsep']}',\n\t\t\t\t\t\t\tthousandsep = '{$langinfo['thousandsep']}',\n\t\t\t\t\t\t\tregistereddateoverride = '{$langinfo['registereddateoverride']}',\n\t\t\t\t\t\t\tcalformat1override = '{$langinfo['calformat1override']}',\n\t\t\t\t\t\t\tcalformat2override = '{$langinfo['calformat2override']}',\n\t\t\t\t\t\t\tlogdateoverride = '{$langinfo['logdateoverride']}'\n\t\t\t\t\t\tWHERE languageid = {$languageid}\n\t\t\t\t\t");
                    $vbulletin->db->query_write("\n\t\t\t\t\t\tUPDATE " . TABLE_PREFIX . "phrase, " . TABLE_PREFIX . "phrase AS phrase2\n\t\t\t\t\t\tSET " . TABLE_PREFIX . "phrase.languageid = -11\n\t\t\t\t\t\tWHERE " . TABLE_PREFIX . "phrase.languageid = {$languageid}\n\t\t\t\t\t\t\tAND (" . TABLE_PREFIX . "phrase.product = '" . $vbulletin->db->escape_string($langinfo['product']) . "'" . iif($langinfo['product'] == 'vbulletin', " OR " . TABLE_PREFIX . "phrase.product = ''") . ")\n\t\t\t\t\t\t\tAND (phrase2.product = '" . $vbulletin->db->escape_string($langinfo['product']) . "'" . iif($langinfo['product'] == 'vbulletin', " OR phrase2.product = ''") . ")\n\t\t\t\t\t\t\tAND " . TABLE_PREFIX . "phrase.varname = phrase2.varname\n\t\t\t\t\t\t\tAND phrase2.languageid = 0\n\t\t\t\t\t\t\tAND " . TABLE_PREFIX . "phrase.fieldname = phrase2.fieldname\n\t\t\t\t\t\t\t{$sql_skipped}\n\t\t\t\t\t");
                    $vbulletin->db->query_write("\n\t\t\t\t\t\tUPDATE " . TABLE_PREFIX . "phrase SET\n\t\t\t\t\t\t\tlanguageid = -10\n\t\t\t\t\t\tWHERE languageid = {$languageid}\n\t\t\t\t\t\t\tAND (product = '" . $vbulletin->db->escape_string($langinfo['product']) . "'" . iif($langinfo['product'] == 'vbulletin', " OR product = ''") . ")\n\t\t\t\t\t\t\t{$sql_skipped}\n\t\t\t\t\t");
                }
            } else {
                print_stop_message('cant_overwrite_non_existent_language');
            }
        }
    }
    // get current phrase types
    $current_phrasetypes = fetch_phrasetypes_array(false);
    if (!$master) {
        $globalPhrases = array();
        $getphrases = $vbulletin->db->query_read("\n\t\t\tSELECT varname, fieldname\n\t\t\tFROM " . TABLE_PREFIX . "phrase\n\t\t\tWHERE languageid IN (0, -1)\n\t\t");
        while ($getphrase = $vbulletin->db->fetch_array($getphrases)) {
            $globalPhrases["{$getphrase['varname']}~{$getphrase['fieldname']}"] = true;
        }
    }
    // import language
    // track new phrasetypes
    $new_phrasetypes = array();
    foreach (array_keys($arr) as $key) {
        $phraseTypes =& $arr["{$key}"];
        $sql = array();
        $strlen = 0;
        if ($phraseTypes['fieldname'] == '' or !preg_match('#^[a-z0-9_]+$#i', $phraseTypes['fieldname'])) {
            continue;
        }
        $fieldname = $phraseTypes['fieldname'];
        if (!is_array($phraseTypes['phrase'][0])) {
            $phraseTypes['phrase'] = array($phraseTypes['phrase']);
        }
        // check if the phrasetype is new
        if (!isset($current_phrasetypes[$fieldname]) and !empty($phraseTypes['phrase'])) {
            $new_phrasetypes[] = array('fieldname' => $fieldname, 'title' => $phraseTypes['name']);
        }
        // Send some output to the browser inside this loop so certain hosts
        // don't artificially kill the script. See bug #34585
        if ($output) {
            echo ' ';
            vbflush();
        }
        foreach ($phraseTypes['phrase'] as $phrase) {
            if ($master) {
                $insertLanguageId = -1;
            } else {
                if (!isset($globalPhrases["{$phrase['name']}~{$fieldname}"])) {
                    $insertLanguageId = 0;
                } else {
                    if ($phrase['custom']) {
                        // this is a custom phrase (language 0) -- we don't want it to end up in the custom language
                        continue;
                    } else {
                        $insertLanguageId = $languageid;
                    }
                }
            }
            $sql[] = "\n\t\t\t\t({$insertLanguageId},\n\t\t\t\t'" . $vbulletin->db->escape_string($fieldname) . "',\n\t\t\t\t'" . $vbulletin->db->escape_string($phrase['name']) . "',\n\t\t\t\t'" . $vbulletin->db->escape_string($phrase['value']) . "',\n\t\t\t\t'" . $vbulletin->db->escape_string($langinfo['product']) . "',\n\t\t\t\t'" . $vbulletin->db->escape_string($phrase['username']) . "',\n\t\t\t\t" . intval($phrase['date']) . ",\n\t\t\t\t'" . $vbulletin->db->escape_string($phrase['version']) . "')\n\t\t\t";
            $strlen += strlen(end($sql));
            if ($strlen > 102400) {
                // insert max of 100k of phrases at a time
                /*insert query*/
                $vbulletin->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(",\n", $sql));
                $sql = array();
                $strlen = 0;
            }
            // Send some output to the browser inside this loop so certain hosts
            // don't artificially kill the script. See bug #34585
            if ($output) {
                echo ' ';
                vbflush();
            }
        }
        if ($sql) {
            /*insert query*/
            $vbulletin->db->query_write("\n\t\t\t\tREPLACE INTO " . TABLE_PREFIX . "phrase\n\t\t\t\t\t(languageid, fieldname, varname, text, product, username, dateline, version)\n\t\t\t\tVALUES\n\t\t\t\t\t" . implode(",\n", $sql));
        }
        unset($arr["{$key}"], $phraseTypes);
    }
    unset($sql, $arr, $current_phrasetypes);
    // insert any new phrasetypes
    foreach ($new_phrasetypes as $phrasetype) {
        add_phrase_type($phrasetype['fieldname'], $phrasetype['title'], $langinfo['product']);
    }
    $vbulletin->db->query_write("\n\t\tUPDATE IGNORE " . TABLE_PREFIX . "phrase\n\t\tSET " . TABLE_PREFIX . "phrase.languageid = {$languageid}\n\t\tWHERE " . TABLE_PREFIX . "phrase.languageid = -11\n\t\t\tAND (" . TABLE_PREFIX . "phrase.product = '" . $vbulletin->db->escape_string($langinfo['product']) . "'" . iif($langinfo['product'] == 'vbulletin', " OR " . TABLE_PREFIX . "phrase.product = ''") . ")\n\t\t\t{$sql_skipped}\n\t");
    // now delete any phrases that were moved into the temporary language for safe-keeping
    $vbulletin->db->query_write("\n\t\tDELETE FROM " . TABLE_PREFIX . "phrase\n\t\tWHERE languageid IN (-10, -11)\n\t\t\tAND (product = '" . $vbulletin->db->escape_string($langinfo['product']) . "'" . iif($langinfo['product'] == 'vbulletin', " OR product = ''") . ")\n\t\t\t{$sql_skipped}\n\t");
    print_dots_stop();
}
Пример #4
0
	<?php 
            // build top options and get language info
            $languages = fetch_languages_array();
            if ($vbulletin->debug) {
                $mlanguages = array('-1' => array('languageid' => -1, 'title' => $vbphrase['master_language']));
                $languages = $mlanguages + $languages;
            }
            $langoptions = array();
            foreach ($languages as $langid => $lang) {
                $langoptions["{$lang['languageid']}"] = $lang['title'];
                if ($lang['languageid'] == $vbulletin->GPC['dolanguageid']) {
                    $language = $lang;
                }
            }
            $phrasetypeoptions = array();
            $phrasetypes = fetch_phrasetypes_array();
            foreach ($phrasetypes as $fieldname => $type) {
                $phrasetypeoptions["{$fieldname}"] = $type['title'];
            }
            print_phrase_ref_popup_javascript();
            // get custom phrases
            $numcustom = 0;
            if ($vbulletin->GPC['dolanguageid'] != -1) {
                $custom_phrases = fetch_custom_phrases($vbulletin->GPC['dolanguageid'], $vbulletin->GPC['fieldname']);
                $numcustom = sizeof($custom_phrases);
            }
            // get inherited and customized phrases
            $standard_phrases = fetch_standard_phrases($vbulletin->GPC['dolanguageid'], $vbulletin->GPC['fieldname'], $numcustom);
            $numstandard = sizeof($standard_phrases);
            $totalphrases = $numcustom + $numstandard;
            $numpages = ceil($totalphrases / $perpage);
Пример #5
0
/**
* 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;
}