/** * Creates and runs an INSERT query to save the data from the object into the database * * @param string The system's table prefix * @param string The name of the database table to be affected (do not include TABLE_PREFIX in your argument) * @param boolean Whether or not to actually run the query * @param bool Perform REPLACE INTO instead of INSERT * * @return integer Returns the ID of the inserted record */ function db_insert($tableprefix, $table, $doquery = true, $replace = false) { static $requiredfields = null; if ($requiredfields === null) { $requiredfields = $this->check_required(); } if ($this->has_errors()) { return false; } else { if (is_array($this->{$table}) and !empty($this->{$table}) and $requiredfields) { $sql = $this->fetch_insert_sql($tableprefix, $table, $replace); if ($doquery) { /*insert query*/ $this->dbobject->query_write($sql); // Not all of our tables have AUTO_INCREMENT fields, i.e. customavatar if ($insertid = $this->dbobject->insert_id()) { return $insertid; } else { return -1; } } else { echo "<pre>{$sql}<hr /></pre>"; return 123456789; } } else { return 0; } } }
public function CreateAccount() { if ($this->vbulletin->options['dle_onoff'] && $this->vbulletin->options['dle_register']) { $user_name = $this->vbulletin->GPC['username']; $user_pass = $this->vbulletin->GPC['password']; $user_pass_md5 = $this->vbulletin->GPC['password_md5']; $user_email = $this->vbulletin->GPC['email']; if (DLE_CHARSET && DLE_CHARSET != $this->vbulletin->userinfo['lang_charset']) { $user_name = iconv($this->vbulletin->userinfo['lang_charset'], DLE_CHARSET, $user_name); $user_pass = iconv($this->vbulletin->userinfo['lang_charset'], DLE_CHARSET, $user_pass); $user_email = iconv($this->vbulletin->userinfo['lang_charset'], DLE_CHARSET, $user_email); $user_pass_md5 = iconv($this->vbulletin->userinfo['lang_charset'], DLE_CHARSET, $user_pass_md5); } if ($user_pass) { $user_pass_hash = md5(md5($user_pass)); $user_pass_md5 = md5($user_pass); } else { $user_pass_hash = md5($user_pass_md5); } $this->_db_connect(); $user_name = $this->db->escape_string($user_name); $user_email = $this->db->escape_string($user_email); $user_id = $this->db->query_first("SELECT user_id FROM " . USERPREFIX . "_users WHERE name='{$user_name}' OR email='{$user_email}'"); if (!$user_id) { $reg_group = $this->vbulletin->options['dle_reg_group'] < 3 ? 4 : $this->vbulletin->options['dle_reg_group']; if ($this->vbulletin->options['dle_hash']) { $hash = md5(uniqid(time())); $this->setcookie('dle_hash', $hash, 365); } else { $hash = ''; } $this->db->query_write("INSERT INTO " . USERPREFIX . "_users \n (name, password, email, reg_date, lastdate, user_group, logged_ip, hash) VALUES \n ('{$user_name}', '{$user_pass_hash}', '{$user_email}', '" . TIMENOW . "', '" . TIMENOW . "', '{$reg_group}', '" . $this->db->escape_string(IPADDRESS) . "', '{$hash}')"); if (!$this->lock_connect) { $id = $this->db->insert_id(); $this->setcookie("dle_user_id", $id, 365); $this->setcookie("dle_password", $user_pass_md5, 365); if (!session_id()) { session_start(); } $_SESSION['dle_user_id'] = $id; $_SESSION['dle_password'] = $user_pass_md5; $_SESSION['member_lasttime'] = TIMENOW; } } $this->_db_disconnect(); } }
/** * 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; }
/** * 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; }