Esempio n. 1
0
function save_notice($noticeid, $title, $html, $displayorder, $active, $persistent, $dismissible, $criteria_array, $username, $templateversion)
{
    $noticeid = save_notice_info($noticeid, $title, $displayorder, $active, $persistent, $dismissible, $criteria_array);
    save_notice_phrase($noticeid, $html, $username, $templateversion);
    // update the datastore notice cache
    build_notice_datastore();
    // rebuild languages
    require_once DIR . '/includes/adminfunctions_language.php';
    build_language();
}
Esempio n. 2
0
 /**
  * Step #3 - Import Language XML
  *
  */
 function step_3()
 {
     $this->show_message($this->phrase['final']['import_latest_language']);
     require_once DIR . '/includes/adminfunctions_language.php';
     if (!($xml = file_read(DIR . '/install/vbulletin-language.xml'))) {
         $this->add_error(sprintf($this->phrase['vbphrase']['file_not_found'], 'vbulletin-language.xml'), self::PHP_TRIGGER_ERROR, true);
         return;
     }
     $this->show_message(sprintf($this->phrase['vbphrase']['importing_file'], 'vbulletin-language.xml'));
     xml_import_language($xml, -1, '', false, true, !defined('SUPPRESS_KEEPALIVE_ECHO'));
     build_language();
     build_language_datastore();
     $this->show_message($this->phrase['core']['import_done']);
 }
Esempio n. 3
0
 /**
  * Delete a cron
  *
  * @param int $cronid Cron ID to be deleted
  *
  * @return void
  */
 public function delete($cronid)
 {
     $this->checkHasAdminPermission('canadmincron');
     $cronid = intval($cronid);
     $cron = vB::getDbAssertor()->getRow('cron', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, 'cronid' => $cronid));
     // delete phrases
     vB::getDbAssertor()->assertQuery('phrase', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_DELETE, 'fieldname' => 'cron', 'varname' => array('task_{$escaped_varname}_title', 'task_{$escaped_varname}_desc', 'task_{$escaped_varname}_log')));
     vB::getDbAssertor()->assertQuery('cron', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_DELETE, 'cronid' => $cronid));
     require_once DIR . '/includes/adminfunctions_language.php';
     build_language();
 }
Esempio n. 4
0
            } else {
                $sellanguages = array();
                while ($language = $db->fetch_array($languages)) {
                    $sellanguages[$language['languageid']] = $language['title'];
                }
                $languageids = implode(',', array_keys($sellanguages));
                $db->query_write("\n\t\t\tUPDATE " . TABLE_PREFIX . "user\n\t\t\tSET languageid = 0\n\t\t\tWHERE languageid NOT IN ({$languageids})\n\t\t");
                if (empty($vbulletin->GPC['languageid'])) {
                    print_form_header('tools', 'language');
                    print_table_header('Select the new default language');
                    print_select_row('Language', 'languageid', $sellanguages, $vbulletin->options['languageid']);
                    print_submit_row('Submit', '');
                } else {
                    $db->query_write("\n\t\t\t\tUPDATE " . TABLE_PREFIX . "setting\n\t\t\t\tSET value = " . $vbulletin->GPC['languageid'] . "\n\t\t\t\tWHERE varname = 'languageid'\n\t\t\t");
                    build_options();
                    build_language($vbulletin->GPC['languageid']);
                    build_language_datastore();
                    define('SCRIPT_REDIRECT', true);
                }
            }
        }
    }
}
if (defined('SCRIPT_REDIRECT')) {
    echo '<p align="center" class="smallfont"><a href="tools.php" onclick="javascript:clearTimeout(timerID);">' . $vbphrase['processing_complete_proceed'] . '</a></p>';
    echo "\n<script type=\"text/javascript\">\n";
    echo "myvar = \"\"; timeout = " . 10 . ";\n\tfunction exec_refresh()\n\t{\n\t\twindow.status=\"" . $vbphrase['redirecting'] . "\"+myvar; myvar = myvar + \" .\";\n\t\ttimerID = setTimeout(\"exec_refresh();\", 100);\n\t\tif (timeout > 0)\n\t\t{ timeout -= 1; }\n\t\telse { clearTimeout(timerID); window.status=\"\"; window.location=\"tools.php\"; }\n\t}\n\texec_refresh();";
    echo "\n</script>\n";
}
?>
<!-- START CONTROL PANEL FOOTER -->
Esempio n. 5
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;
 }
Esempio n. 6
0
    if (empty($newlang['title']) or empty($newlang['charset'])) {
        print_stop_message('please_complete_required_fields');
    }
    // User has defined a locale.
    if ($newlang['locale'] != '') {
        if (!setlocale(LC_TIME, $newlang['locale']) or !setlocale(LC_CTYPE, $newlang['locale'])) {
            print_stop_message('invalid_locale', $newlang['locale']);
        }
        if ($newlang['dateoverride'] == '' or $newlang['timeoverride'] == '' or $newlang['registereddateoverride'] == '' or $newlang['calformat1override'] == '' or $newlang['calformat2override'] == '' or $newlang['logdateoverride'] == '') {
            print_stop_message('locale_define_fill_in_all_overrides');
        }
    }
    /*insert query*/
    $db->query_write(fetch_query_sql($newlang, 'language'));
    $_languageid = $db->insert_id($result);
    build_language($_languageid);
    build_language_datastore();
    define('CP_REDIRECT', 'language.php?dolanguageid=' . $_languageid);
    print_stop_message('saved_language_x_successfully', $newlang['title']);
}
// ##########################################################################
if ($_REQUEST['do'] == 'add') {
    print_form_header('language', 'insert');
    print_table_header($vbphrase['add_new_language']);
    print_description_row($vbphrase['general_settings'], 0, 2, 'thead');
    print_input_row($vbphrase['title'], 'title');
    print_yes_no_row($vbphrase['allow_user_selection'], 'userselect');
    print_yes_no_row($vbphrase['enable_directional_markup_fix'], 'options[dirmark]');
    print_label_row($vbphrase['text_direction'], "<label for=\"rb_l2r\"><input type=\"radio\" name=\"options[direction]\" id=\"rb_l2r\" value=\"1\" tabindex=\"1\" checked=\"checked\" />{$vbphrase['left_to_right']}</label><br />\n\t\t <label for=\"rb_r2l\"><input type=\"radio\" name=\"options[direction]\" id=\"rb_r2l\" value=\"0\" tabindex=\"1\" />{$vbphrase['right_to_left']}</label>", '', 'top', 'direction');
    print_input_row($vbphrase['language_code'], 'languagecode', 'en');
    print_input_row($vbphrase['html_charset'] . "<code>&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=<b>ISO-8859-1</b>&quot; /&gt;</code>", 'charset', 'ISO-8859-1');
Esempio n. 7
0
	/**
	*
	* @param	boolean	Do the query?
	*/
	function post_save_once($doquery = true)
	{
		require_once(DIR . '/includes/blog_functions_category.php');
		build_category_genealogy($this->fetch_field('userid'));
		build_blog_user_counters($this->fetch_field('userid'));

		if (!$this->fetch_field('userid'))
		{	// Admin Defined Category
			$this->registry->db->query_write("
				DELETE FROM " . TABLE_PREFIX . "phrase
				WHERE
					product = 'vbblog'
						AND
					varname IN ('category" . $this->fetch_field('blogcategoryid') . "_title', 'category" . $this->fetch_field('blogcategoryid') . "_desc')
						AND
					fieldname = 'vbblogcat'
						AND
					languageid IN (0,-1)
			");
			$this->registry->db->query_write("
				INSERT INTO " . TABLE_PREFIX . "phrase
					(languageid, fieldname, varname, text, product, username, dateline, version)
				VALUES
					(0,
					'vbblogcat',
					'category" . $this->fetch_field('blogcategoryid') . "_title',
					'" . $this->registry->db->escape_string($this->fetch_field('title')) . "',
					'vbblog',
					'" . $this->registry->db->escape_string($this->registry->userinfo['username']) . "',
					" . TIMENOW . ",
					'" . $this->registry->db->escape_string($this->registry->options['templateversion']) . "'
					),
					(0,
					'vbblogcat',
					'category" . $this->fetch_field('blogcategoryid') . "_desc',
					'" . $this->registry->db->escape_string($this->fetch_field('description')) . "',
					'vbblog',
					'" . $this->registry->db->escape_string($this->registry->userinfo['username']) . "',
					" . TIMENOW . ",
					'" . $this->registry->db->escape_string($this->registry->options['templateversion']) . "'
					)
			");

			require_once(DIR . '/includes/adminfunctions_language.php');
			build_language();
		}

		($hook = vBulletinHook::fetch_hook('blog_categorydata_postsave')) ? eval($hook) : false;
	}
Esempio n. 8
0
	/**
	* Additional data to update after a delete call (such as denormalized values in other tables).
	*
	* @param	boolean	Do the query?
	*/
	function post_delete($doquery = true)
	{
		$db =& $this->registry->db;

		// need to rebuild last post info in forums that use this prefix
		require_once(DIR . '/includes/functions_databuild.php');

		$forums = $db->query_read("
			SELECT forumid
			FROM " . TABLE_PREFIX . "forumprefixset
			WHERE prefixsetid = '" . $db->escape_string($this->fetch_field('prefixsetid')) . "'
		");
		while ($forum = $db->fetch_array($forums))
		{
			build_forum_counters($forum['forumid']);
		}

		$db->query_write("
			DELETE FROM " . TABLE_PREFIX . "forumprefixset
			WHERE prefixsetid = '" . $db->escape_string($this->fetch_field('prefixsetid')) . "'
		");

		// delete this set's phrases
		$db->query_write("
			DELETE FROM " . TABLE_PREFIX . "phrase
			WHERE varname = '" . $db->escape_string('prefixset_' .  $this->fetch_field('prefixsetid') . '_title') . "'
				AND fieldname = 'prefix'
		");

		// now find all the phrases for child prefixes to remove
		$prefix_phrases = array();
		$prefixids = array();

		$prefix_sql = $db->query_read("
			SELECT prefixid
			FROM " . TABLE_PREFIX . "prefix
			WHERE prefixsetid = '" . $db->escape_string($this->fetch_field('prefixsetid')) . "'
		");
		while ($prefix = $db->fetch_array($prefix_sql))
		{
			$prefix_phrases[] = "'" . $db->escape_string("prefix_$prefix[prefixid]_title_plain") . "'";
			$prefix_phrases[] = "'" . $db->escape_string("prefix_$prefix[prefixid]_title_rich") . "'";

			$prefixids[] = "'" . $db->escape_string($prefix['prefixid']) . "'";
		}

		if ($prefix_phrases)
		{
			$db->query_write("
				DELETE FROM " . TABLE_PREFIX . "phrase
				WHERE varname IN (" . implode(',', $prefix_phrases) . ")
					AND fieldname = 'global'
			");

			$db->query_write("
				UPDATE " . TABLE_PREFIX . "thread SET
					prefixid = ''
				WHERE prefixid IN (" . implode(',', $prefixids) . ")
			");
		}

		// now delete the child prefixes themselves
		$db->query_write("
			DELETE FROM " . TABLE_PREFIX . "prefix
			WHERE prefixsetid = '" . $db->escape_string($this->fetch_field('prefixsetid')) . "'
		");

		require_once(DIR . '/includes/adminfunctions_language.php');
		build_language();

		require_once(DIR . '/includes/adminfunctions_prefix.php');
		build_prefix_datastore();

		($hook = vBulletinHook::fetch_hook('prefixsetdata_delete')) ? eval($hook) : false;
		return true;
	}
Esempio n. 9
0
 /**
  * Additional data to update after a delete call (such as denormalized values in other tables).
  *
  * @param	boolean	Do the query?
  */
 function post_delete($doquery = true)
 {
     $db =& $this->registry->db;
     $escaped_type = $db->escape_string($this->fetch_field('issuetypeid'));
     $db->query_write("\r\n\t\t\tDELETE FROM " . TABLE_PREFIX . "pt_projectpermission WHERE issuetypeid = '{$escaped_type}'\r\n\t\t");
     $db->query_write("\r\n\t\t\tDELETE FROM " . TABLE_PREFIX . "pt_projecttype WHERE issuetypeid = '{$escaped_type}'\r\n\t\t");
     $db->query_write("\r\n\t\t\tDELETE FROM " . TABLE_PREFIX . "pt_projecttypeprivatelastpost WHERE issuetypeid = '{$escaped_type}'\r\n\t\t");
     $del_phrases = array();
     foreach ($this->info_phrase as $phrase_name) {
         $del_phrases[] = sprintf($phrase_name, $escaped_type);
     }
     $db->query_write("\r\n\t\t\tDELETE FROM " . TABLE_PREFIX . "phrase\r\n\t\t\tWHERE varname IN ('" . implode('", "', $del_phrases) . "')\r\n\t\t\t\tAND fieldname = 'projecttools'\r\n\t\t");
     if ($this->info['rebuild_caches']) {
         require_once DIR . '/includes/adminfunctions_language.php';
         build_language();
         require_once DIR . '/includes/adminfunctions_projecttools.php';
         build_issue_type_cache();
     }
     // update any issues with this status...
     if ($this->info['delete_deststatusid'] and $dest_status = $this->registry->db->query_first("\r\n\t\t\tSELECT *\r\n\t\t\tFROM " . TABLE_PREFIX . "pt_issuestatus\r\n\t\t\tWHERE issuestatusid = " . intval($this->info['delete_deststatusid']) . "\r\n\t\t")) {
         // ... to the destination status
         $this->registry->db->query_write("\r\n\t\t\t\tUPDATE " . TABLE_PREFIX . "pt_issue SET\r\n\t\t\t\t\tissuestatusid = {$dest_status['issuestatusid']},\r\n\t\t\t\t\tissuetypeid = '{$dest_status['issuetypeid']}'\r\n\t\t\t\tWHERE issuetypeid = '{$escaped_type}'\r\n\t\t\t");
     }
     ($hook = vBulletinHook::fetch_hook('pt_issuetypedata_delete')) ? eval($hook) : false;
     return true;
 }
/**
* Installs a product from the xml text
*
* This function depends on the vb class loader, which requires that the
* framework init is called.
*
* @return bool True if the product requires a template merge, false otherwise
*/
function install_product($xml, $allow_overwrite = false, $verbose = true)
{
    global $vbphrase;
    global $vbulletin;
    $assertor = vB::getDbAssertor();
    require_once DIR . '/includes/class_bitfield_builder.php';
    require_once DIR . '/includes/class_xml.php';
    //share some code with the main xml style import
    require_once DIR . '/includes/adminfunctions_template.php';
    if ($verbose) {
        print_dots_start('<b>' . $vbphrase['importing_product'] . "</b>, {$vbphrase['please_wait']}", ':', 'dspan');
    }
    $xmlobj = new vB_XML_Parser($xml);
    if ($xmlobj->error_no() == 1) {
        if ($verbose) {
            print_dots_stop();
        }
        throw new vB_Exception_AdminStopMessage('no_xml_and_no_path');
    }
    if (!($arr = $xmlobj->parse())) {
        if ($verbose) {
            print_dots_stop();
        }
        throw new vB_Exception_AdminStopMessage(array('xml_error_x_at_line_y', $xmlobj->error_string(), $xmlobj->error_line()));
    }
    // ############## general product information
    $info = array('productid' => substr(preg_replace('#[^a-z0-9_]#', '', strtolower($arr['productid'])), 0, 25), 'title' => $arr['title'], 'description' => $arr['description'], 'version' => $arr['version'], 'active' => $arr['active'], 'url' => $arr['url'], 'versioncheckurl' => $arr['versioncheckurl']);
    if (!$info['productid']) {
        if ($verbose) {
            print_dots_stop();
        }
        throw new vB_Exception_AdminStopMessage('invalid_file_specified');
    }
    if (strtolower($info['productid']) == 'vbulletin') {
        if ($verbose) {
            print_dots_stop();
        }
        throw new vB_Exception_AdminStopMessage(array('product_x_installed_no_overwrite', 'vBulletin'));
    }
    // check for bitfield conflicts on install
    $bitfields = vB_Bitfield_Builder::return_data();
    if (!$bitfields) {
        $bfobj =& vB_Bitfield_Builder::init();
        if ($bfobj->errors) {
            if ($verbose) {
                print_dots_stop();
            }
            throw new vB_Exception_AdminStopMessage(array('bitfield_conflicts_x', '<li>' . implode('</li><li>', $bfobj->errors) . '</li>'));
        }
    }
    // get system version info
    $system_versions = array('php' => PHP_VERSION, 'vbulletin' => $vbulletin->options['templateversion'], 'products' => fetch_product_list(true));
    $mysql_version = $assertor->getRow('mysqlVersion');
    $system_versions['mysql'] = $mysql_version['version'];
    // ############## import dependencies
    if (isset($arr['dependencies']['dependency']) and is_array($arr['dependencies']['dependency'])) {
        $dependencies =& $arr['dependencies']['dependency'];
        if (!isset($dependencies[0])) {
            $dependencies = array($dependencies);
        }
        $dependency_errors = array();
        $ignore_dependency_errors = array();
        // let's check the dependencies
        foreach ($dependencies as $dependency) {
            // if we get an error, we haven't met this dependency
            // if we go through without a problem, we have automatically met
            // all dependencies for this "class" (mysql, php, vb, a specific product, etc)
            $this_dependency_met = true;
            // build a phrase for the version compats -- will look like (minver / maxver)
            if ($dependency['minversion']) {
                $compatible_phrase = construct_phrase($vbphrase['compatible_starting_with_x'], htmlspecialchars_uni($dependency['minversion']));
            } else {
                $compatible_phrase = '';
            }
            if ($dependency['maxversion']) {
                $incompatible_phrase = construct_phrase($vbphrase['incompatible_with_x_and_greater'], htmlspecialchars_uni($dependency['maxversion']));
            } else {
                $incompatible_phrase = '';
            }
            if ($compatible_phrase or $incompatible_phrase) {
                $required_version_info = "({$compatible_phrase}";
                if ($compatible_phrase and $incompatible_phrase) {
                    $required_version_info .= ' / ';
                }
                $required_version_info .= "{$incompatible_phrase})";
            }
            // grab the appropriate installed version string
            if ($dependency['dependencytype'] == 'product') {
                // group dependencies into types -- individual products get their own group
                $dependency_type_key = "product-{$dependency['parentproductid']}";
                // undocumented feature -- you can put a producttitle attribute in a dependency so the id isn't displayed
                $parent_product_title = !empty($dependency['producttitle']) ? $dependency['producttitle'] : $dependency['parentproductid'];
                $parent_product = $system_versions['products']["{$dependency['parentproductid']}"];
                if (!$parent_product) {
                    // required product is not installed
                    $dependency_errors["{$dependency_type_key}"] = construct_phrase($vbphrase['product_x_must_be_installed'], htmlspecialchars_uni($parent_product_title), $required_version_info);
                    continue;
                    // can't do version checks if the product isn't installed
                } else {
                    if ($parent_product['active'] == 0) {
                        // product is installed, but inactive
                        $dependency_errors["{$dependency_type_key}-inactive"] = construct_phrase($vbphrase['product_x_must_be_activated'], htmlspecialchars_uni($parent_product_title));
                        $this_dependency_met = false;
                        // allow version checks to continue
                    }
                }
                $sys_version_str = $parent_product['version'];
                $version_incompatible_phrase = 'product_incompatible_version_x_product_y';
            } else {
                $dependency_type_key = $dependency['dependencytype'];
                $parent_product_title = '';
                $sys_version_str = $system_versions["{$dependency['dependencytype']}"];
                $version_incompatible_phrase = 'product_incompatible_version_x_' . $dependency['dependencytype'];
            }
            // if no version string, we are trying to do an unsupported dep check
            if ($sys_version_str == '') {
                continue;
            }
            $sys_version = fetch_version_array($sys_version_str);
            // error if installed version < minversion
            if ($dependency['minversion']) {
                $dep_version = fetch_version_array($dependency['minversion']);
                for ($i = 0; $i <= 5; $i++) {
                    if ($sys_version["{$i}"] < $dep_version["{$i}"]) {
                        // installed version is too old
                        $dependency_errors["{$dependency_type_key}"] = construct_phrase($vbphrase["{$version_incompatible_phrase}"], htmlspecialchars_uni($sys_version_str), $required_version_info, $parent_product_title);
                        $this_dependency_met = false;
                        break;
                    } else {
                        if ($sys_version["{$i}"] > $dep_version["{$i}"]) {
                            break;
                        }
                    }
                }
            }
            // error if installed version >= maxversion
            if ($dependency['maxversion']) {
                $dep_version = fetch_version_array($dependency['maxversion']);
                $all_equal = true;
                for ($i = 0; $i <= 5; $i++) {
                    if ($sys_version["{$i}"] > $dep_version["{$i}"]) {
                        // installed version is newer than the maxversion
                        $dependency_errors["{$dependency_type_key}"] = construct_phrase($vbphrase["{$version_incompatible_phrase}"], htmlspecialchars_uni($sys_version_str), $required_version_info, $parent_product_title);
                        $this_dependency_met = false;
                        break;
                    } else {
                        if ($sys_version["{$i}"] < $dep_version["{$i}"]) {
                            // not every part is the same and since we've got less we can exit
                            $all_equal = false;
                            break;
                        } else {
                            if ($sys_version["{$i}"] != $dep_version["{$i}"]) {
                                // not every part is the same
                                $all_equal = false;
                            }
                        }
                    }
                }
                if ($all_equal == true) {
                    // installed version is same as the max version, which is the first incompat version
                    $dependency_errors["{$dependency_type_key}"] = construct_phrase($vbphrase["{$version_incompatible_phrase}"], htmlspecialchars_uni($sys_version_str), $required_version_info, $parent_product_title);
                    $this_dependency_met = false;
                }
            }
            if ($this_dependency_met) {
                // we met 1 dependency for this type -- this emulates or'ing together groups
                $ignore_dependency_errors["{$dependency_type_key}"] = true;
            }
        }
        // for any group we met a dependency for, ignore any errors we might
        // have gotten for the group
        foreach ($ignore_dependency_errors as $dependency_type_key => $devnull) {
            unset($dependency_errors["{$dependency_type_key}"]);
        }
        if ($dependency_errors) {
            $dependency_errors = array_unique($dependency_errors);
            $dependency_errors = '<ol><li>' . implode('</li><li>', $dependency_errors) . '</li></ol>';
            if ($verbose) {
                print_dots_stop();
            }
            throw new vB_Exception_AdminStopMessage(array('dependencies_not_met_x', $dependency_errors));
        }
    }
    // look to see if we already have this product installed
    if ($existingprod = $assertor->getRow('product', array('productid' => $info['productid']))) {
        if (!$allow_overwrite) {
            if ($verbose) {
                print_dots_stop();
            }
            throw new vB_Exception_AdminStopMessage(array('product_x_installed_no_overwrite', $info['title']));
        }
        $active = $existingprod['active'];
        // not sure what we're deleting, so rebuild everything
        $rebuild = array('templates' => true, 'hooks' => true, 'phrases' => true, 'options' => true, 'cron' => true);
        $installed_version = $existingprod['version'];
    } else {
        $active = $info['active'] ? 1 : 0;
        $rebuild = array('templates' => false, 'hooks' => false, 'phrases' => false, 'options' => false, 'cron' => false);
        $installed_version = null;
    }
    // ############## import install/uninstall code
    if (isset($arr['codes']['code']) and is_array($arr['codes']['code'])) {
        $codes =& $arr['codes']['code'];
        if (!isset($codes[0])) {
            $codes = array($codes);
        }
        // run each of the codes
        foreach ($codes as $code) {
            // Run if: code version is * (meaning always run), no version
            //		previously installed, or if the code is for a newer version
            //		than is currently installed
            if ($code['version'] == '*' or $installed_version === null or is_newer_version($code['version'], $installed_version)) {
                eval($code['installcode']);
            }
        }
        // Clear routes from datastore
        build_datastore('routes', serialize(array()), 1);
        //assume that the product may have installed content types and purge the content type cache
        vB_Cache::instance()->purge('vb_types.types');
    }
    // dependencies checked, install code run. Now clear out the old product info;
    // settings should be retained in memory already
    delete_product($info['productid'], false, true);
    if (is_array($codes)) {
        // we've now run all the codes, if execution is still going
        // then it's going to complete fully, so insert the codes
        $productCodes = array();
        foreach ($codes as $code) {
            /* insert query */
            $productCodes[] = array('productid' => $info['productid'], 'version' => $code['version'], 'installcode' => $code['installcode'], 'uninstallcode' => $code['uninstallcode']);
        }
        $assertor->insertMultiple('productcode', array('productid', 'version', 'installcode', 'uninstallcode'), $productCodes);
    }
    if (is_array($dependencies)) {
        // dependencies met, codes run -- now we can insert the dependencies into the DB
        $productDependencies = array();
        foreach ($dependencies as $dependency) {
            /* insert query */
            $productDependencies[] = array('productid' => $info['productid'], 'dependencytype' => $dependency['dependencytype'], 'parentproductid' => $dependency['parentproductid'], 'minversion' => $dependency['minversion'], 'maxversion' => $dependency['maxversion']);
        }
        $assertor->insertMultiple('productdependency', array('productid', 'dependencytype', 'parentproductid', 'minversion', 'maxversion'), $productDependencies);
    }
    /* insert query */
    $assertor->insert('product', array('productid' => $info['productid'], 'title' => $info['title'], 'description' => $info['description'], 'version' => $info['version'], 'active' => intval($active), 'url' => $info['url'], 'versioncheckurl' => $info['versioncheckurl']));
    // ############## import templates
    if (isset($arr['templates']['template']) and is_array($arr['templates']['template'])) {
        $querybits = array();
        $querytemplates = 0;
        $templates =& $arr['templates']['template'];
        if (!isset($templates[0])) {
            $templates = array($templates);
        }
        foreach ($templates as $template) {
            $title = $template['name'];
            $template['template'] = $template['value'];
            $template['username'] = $template['username'];
            $template['templatetype'] = $template['templatetype'];
            $template['date'] = intval($template['date']);
            if ($template['templatetype'] != 'template') {
                // template is a special template
                $querybits[] = array('styleid' => -1, 'templatetype' => $template['templatetype'], 'title' => $title, 'template' => $template['template'], 'template_un' => '', 'dateline' => $template['date'], 'username' => $template['username'], 'version' => $template['version'], 'product' => $info['productid']);
            } else {
                // template is a standard template
                $querybits[] = array('styleid' => -1, 'templatetype' => $template['templatetype'], 'title' => $title, 'template' => compile_template($template['value']), 'template_un' => $template['template'], 'dateline' => $template['date'], 'username' => $template['username'], 'version' => $template['version'], 'product' => $info['productid']);
            }
            if (++$querytemplates % 20 == 0) {
                /*insert query*/
                $assertor->assertQuery('replaceValues', array('values' => $querybits, 'table' => 'template'));
                $querybits = array();
            }
            // Send some output to the browser inside this loop so certain hosts
            // don't artificially kill the script. See bug #34585
            if (VB_AREA != 'Upgrade' and VB_AREA != 'Install') {
                echo ' ';
                vbflush();
            }
        }
        // insert any remaining templates
        if (!empty($querybits)) {
            /*insert query*/
            $assertor->assertQuery('replaceValues', array('values' => $querybits, 'table' => 'template'));
        }
        unset($querybits);
        $rebuild['templates'] = true;
    }
    // ############## import stylevars
    if (isset($arr['stylevardfns']['stylevargroup']) and is_array($arr['stylevardfns']['stylevargroup'])) {
        xml_import_stylevar_definitions($arr['stylevardfns'], $info['productid']);
    }
    if (!empty($arr['stylevars']) and is_array($arr['stylevars']) and is_array($arr['stylevars']['stylevar'])) {
        xml_import_stylevars($arr['stylevars'], -1);
    }
    // ############## import hooks
    if (isset($arr['hooks']['hook']) and is_array($arr['hooks']['hook'])) {
        $hooks =& $arr['hooks']['hook'];
        if (!isset($hooks[0])) {
            $hooks = array($hooks);
        }
        foreach ($hooks as $hook) {
            $hook['product'] = $info['productid'];
            $assertor->insert('hook', $hook);
        }
        $rebuild['hooks'] = true;
    }
    // ############## import phrases
    if (isset($arr['phrases']['phrasetype']) and is_array($arr['phrases']['phrasetype'])) {
        require_once DIR . '/includes/adminfunctions_language.php';
        $master_phrasetypes = array();
        $master_phrasefields = array();
        foreach (vB_Api::instanceInternal('phrase')->fetch_phrasetypes(false) as $phrasetype) {
            $master_phrasefields["{$phrasetype['fieldname']}"] = true;
        }
        $phrasetypes =& $arr['phrases']['phrasetype'];
        if (!isset($phrasetypes[0])) {
            $phrasetypes = array($phrasetypes);
        }
        foreach ($phrasetypes as $phrasetype) {
            if (empty($phrasetype['phrase'])) {
                continue;
            }
            if ($phrasetype['fieldname'] == '' or !preg_match('#^[a-z0-9_]+$#i', $phrasetype['fieldname'])) {
                continue;
            }
            $fieldname = $master_phrasefields["{$phrasetype['fieldname']}"];
            if (!$fieldname) {
                $assertor->assertQuery('installProductPhraseTypeInsert', array('fieldname' => $phrasetype['fieldname'], 'title' => $phrasetype['name'], 'editrows' => 3, 'product' => $info['productid']));
                // need to add the column to the language table as well
                $assertor->assertQuery('addLanguageFromPackage', array('fieldname' => $phrasetype['fieldname']));
            }
            $phrases =& $phrasetype['phrase'];
            if (!isset($phrases[0])) {
                $phrases = array($phrases);
            }
            $sql = array();
            foreach ($phrases as $phrase) {
                $sql[] = array('languageid' => -1, 'fieldname' => $phrasetype['fieldname'], 'varname' => $phrase['name'], 'text' => $phrase['value'], 'product' => $info['productid'], 'username' => $phrase['username'], 'dateline' => $phrase['date'], 'version' => $phrase['version']);
            }
            /*insert query*/
            $assertor->assertQuery('replaceValues', array('values' => $sql, 'table' => 'phrase'));
        }
        $rebuild['phrases'] = true;
    }
    // ############## import settings
    if (isset($arr['options']['settinggroup']) and is_array($arr['options']['settinggroup'])) {
        $settinggroups =& $arr['options']['settinggroup'];
        if (!isset($settinggroups[0])) {
            $settinggroups = array($settinggroups);
        }
        foreach ($settinggroups as $group) {
            if (empty($group['setting'])) {
                continue;
            }
            // create the setting group if it doesn't already exist
            $check = $assertor->assertQuery('settinggroup', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, 'grouptitle' => $group['name']));
            if ($check->valid()) {
                $current = $check->current();
                if ($group['adminperm'] != $current['adminperm'] or $group['displayorder'] != $current['displayorder']) {
                    $assertor->assertQuery('settinggroup', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_UPDATE, 'grouptitle' => $group['name'], 'displayorder' => $group['displayorder'], 'adminperm' => $group['adminperm']));
                }
            } else {
                /*insert query*/
                $assertor->assertQuery('settinggroup', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_INSERTIGNORE, 'grouptitle' => $group['name'], 'displayorder' => $group['displayorder'], 'volatile' => 1, 'product' => $info['productid'], 'adminperm' => $group['adminperm']));
            }
            $settings =& $group['setting'];
            if (!isset($settings[0])) {
                $settings = array($settings);
            }
            $setting_bits = array();
            foreach ($settings as $setting) {
                if (isset($vbulletin->options["{$setting['varname']}"])) {
                    $newvalue = $vbulletin->options["{$setting['varname']}"];
                } else {
                    $newvalue = $setting['defaultvalue'];
                }
                $setting_bits[] = array('varname' => $setting['varname'], 'grouptitle' => $group['name'], 'value' => trim($newvalue), 'defaultvalue' => trim($setting['defaultvalue']), 'datatype' => trim($setting['datatype']), 'optioncode' => $setting['optioncode'], 'displayorder' => $setting['displayorder'], 'advanced' => intval($setting['advanced']), 'volatile' => 1, 'validationcode' => $setting['validationcode'], 'blacklist' => $setting['blacklist'], 'ispublic' => intval($setting['public']), 'product' => $info['productid'], 'adminperm' => empty($setting['adminperm']) ? '' : $setting['adminperm']);
            }
            /*insert query*/
            $assertor->assertQuery('replaceValues', array('values' => $setting_bits, 'table' => 'setting'));
        }
        $rebuild['options'] = true;
    }
    // ############## import admin help
    if (isset($arr['helptopics']['helpscript']) and is_array($arr['helptopics']['helpscript'])) {
        $help_scripts =& $arr['helptopics']['helpscript'];
        if (!isset($help_scripts[0])) {
            $help_scripts = array($help_scripts);
        }
        foreach ($help_scripts as $help_script) {
            // Deal with single entry
            if (!is_array($help_script['helptopic'][0])) {
                $help_script['helptopic'] = array($help_script['helptopic']);
            }
            $help_sql = array();
            foreach ($help_script['helptopic'] as $topic) {
                $helpsql[] = array('script' => $help_script['name'], 'action' => $topic['act'], 'optionname' => $topic['opt'], 'displayorder' => intval($topic['disp']), 'volatile' => 1, 'product' => $info['productid']);
            }
            if (!empty($helpsql)) {
                /*insert query*/
                $assertor->assertQuery('replaceValues', array('values' => $helpsql, 'table' => 'adminhelp'));
            }
        }
    }
    // ############## import cron
    if (isset($arr['cronentries']['cron']) and is_array($arr['cronentries']['cron'])) {
        require_once DIR . '/includes/functions_cron.php';
        $cron_entries =& $arr['cronentries']['cron'];
        if (!isset($cron_entries[0])) {
            $cron_entries = array($cron_entries);
        }
        foreach ($cron_entries as $cron) {
            $cron['varname'] = preg_replace('#[^a-z0-9_]#i', '', $cron['varname']);
            if (!$cron['varname']) {
                continue;
            }
            $cron['active'] = $cron['active'] ? 1 : 0;
            $cron['loglevel'] = $cron['loglevel'] ? 1 : 0;
            $scheduling = $cron['scheduling'];
            $scheduling['weekday'] = intval($scheduling['weekday']);
            $scheduling['day'] = intval($scheduling['day']);
            $scheduling['hour'] = intval($scheduling['hour']);
            $scheduling['minute'] = explode(',', preg_replace('#[^0-9,-]#i', '', $scheduling['minute']));
            if (count($scheduling['minute']) == 0) {
                $scheduling['minute'] = array(0);
            } else {
                $scheduling['minute'] = array_map('intval', $scheduling['minute']);
            }
            /*insert query*/
            $cronSql[] = array('weekday' => $scheduling['weekday'], 'day' => $scheduling['day'], 'hour' => $scheduling['hour'], 'minute' => serialize($scheduling['minute']), 'filename' => $cron['filename'], 'loglevel' => $cron['loglevel'], 'active' => $cron['active'], 'varname' => $cron['varname'], 'volatile' => 1, 'product' => $info['productid']);
            $cronid = $assertor->assertQuery('replaceValues', array('values' => $cronSql, 'table' => 'cron', 'returnId' => true));
            if ($cronid) {
                build_cron_item($cronid);
            }
            $rebuild['cron'] = true;
        }
    }
    // ############## import faq
    if (isset($arr['faqentries']['faq']) and is_array($arr['faqentries']['faq'])) {
        $faq_entries =& $arr['faqentries']['faq'];
        if (!isset($faq_entries[0])) {
            $faq_entries = array($faq_entries);
        }
        $sql = array();
        foreach ($faq_entries as $faq) {
            $sql[] = array('faqname' => $faq['faqname'], 'faqparent' => $faq['faqparent'], 'displayorder' => intval($faq['displayorder']), 'volatile' => 1, 'product' => $info['productid']);
        }
        if ($sql) {
            /*insert query*/
            $assertor->assertQuery('replaceValues', array('values' => $sql, 'table' => 'faq'));
        }
    }
    // ############## import widgets
    if (isset($arr['widgets']['widget']) and is_array($arr['widgets']['widget'])) {
        $widgetImporter = new vB_Xml_Import_Widget($info['productid']);
        $widgetImporter->importFromParsedXML($arr['widgets']);
    }
    // ############## import pagetemplates
    if (isset($arr['pagetemplates']['pagetemplate']) and is_array($arr['pagetemplates']['pagetemplate'])) {
        $pageTemplateImporter = new vB_Xml_Import_PageTemplate($info['productid']);
        $pageTemplateImporter->importFromParsedXML($arr['pagetemplates']);
    }
    // ############## import page
    if (isset($arr['pages']['page']) and is_array($arr['pages']['page'])) {
        $pageImporter = new vB_Xml_Import_Page($info['productid']);
        $pageImporter->importFromParsedXML($arr['pages']);
    }
    // ############## import channels
    if (isset($arr['channels']['channel']) and is_array($arr['channels']['channel'])) {
        $channelImporter = new vB_Xml_Import_Channel($info['productid']);
        $channelImporter->importFromParsedXML($arr['channels']);
    }
    // ############## import routes
    if (isset($arr['routes']['route']) and is_array($arr['routes']['route'])) {
        $routeImporter = new vB_Xml_Import_Route($info['productid']);
        $routeImporter->importFromParsedXML($arr['routes']);
    }
    if (isset($routeImporter)) {
        // update pages and channels with new route ids
        if (isset($pageImporter)) {
            $pageImporter->updatePageRoutes();
        }
        if (isset($channelImporter)) {
            $channelImporter->updateChannelRoutes();
        }
    }
    // Check if the hook system is disabled. If it is, enable it.
    if (!$vbulletin->options['enablehooks']) {
        $assertor->update('setting', array('value' => 1), array('varname' => 'enablehooks'));
        $rebuild['options'] = true;
    }
    // Now rebuild everything we need...
    if ($rebuild['hooks']) {
        vB_Api::instanceInternal("Hook")->buildHookDatastore();
    }
    if ($rebuild['templates']) {
        if ($error = build_all_styles(0, 0, '', false, $verbose)) {
            return $error;
        }
    }
    if ($rebuild['phrases']) {
        require_once DIR . '/includes/adminfunctions_language.php';
        build_language();
    }
    if ($rebuild['options']) {
        vB::getDatastore()->build_options();
    }
    if ($rebuild['cron']) {
        require_once DIR . '/includes/functions_cron.php';
        build_cron_next_run();
    }
    build_product_datastore();
    // build bitfields to remove/add this products bitfields
    vB_Bitfield_Builder::save();
    if ($verbose) {
        print_dots_stop();
    }
    $info['need_merge'] = ($rebuild['templates'] and $installed_version);
    return $info;
}
Esempio n. 11
0
/**
* Reads a language or languages and updates the language db table with the denormalized phrase cache
*
* @param	integer	ID of language to be built; if -1, build all
* @param	integer	Not sure actually... any ideas?	
* @param	boolean.  Wether to reset the static vars the function uses to cache items for recursing
* 			when we we build the master language.  Otherwise if we attempt to call this function
* 			twice in the same pageload we don't actually manage to update any changes after the first
* 			call. 
* 			The better approach would be to use an internal function and a master function t
* 			hat generates the cached values once and passes them in.
* 			However that means unwinding this function which works but is... odd.  
*/
function build_language($languageid = -1, $phrasearray = 0, $reset_static=true)
{
	global $vbulletin;
	static $masterlang, $jsphrases = null;

	if($reset_static)
	{
		$masterlang = null;
		$jsphrases = null; 
	}

	// load js safe phrases
	if ($jsphrases === null)
	{
		require_once(DIR . '/includes/class_xml.php');
		$xmlobj = new vB_XML_Parser(false, DIR . '/includes/xml/js_safe_phrases.xml');
		$safephrases = $xmlobj->parse();

		$jsphrases = array();

		if (is_array($safephrases['phrase']))
		{
			foreach ($safephrases['phrase'] AS $varname)
			{
				$jsphrases["$varname"] = true;
			}
		}
		unset($safephrases, $xmlobj);
	}


	// update all languages if this is the master language
	if ($languageid == -1)
	{
		$languages = $vbulletin->db->query_read("SELECT languageid FROM " . TABLE_PREFIX . "language");
		while ($language = $vbulletin->db->fetch_array($languages))
		{
			build_language($language['languageid'], 0, false);
		}
		return;
	}

	// get phrase types for language update
	$gettypes = array();
	$getphrasetypes = $vbulletin->db->query_read("
		SELECT fieldname
		FROM " . TABLE_PREFIX . "phrasetype
		WHERE editrows <> 0 AND
			special = 0
	");
	while ($getphrasetype = $vbulletin->db->fetch_array($getphrasetypes))
	{
		$gettypes[] = "'" . $vbulletin->db->escape_string($getphrasetype['fieldname']) . "'";
	}
	unset($getphrasetype);
	$vbulletin->db->free_result($getphrasetypes);

	if (empty($masterlang))
	{
		$masterlang = array();

		$phrases = $vbulletin->db->query_read("
			SELECT fieldname, varname, text
			FROM " . TABLE_PREFIX . "phrase
			WHERE languageid IN(-1,0) AND
				fieldname IN (" . implode(',', $gettypes) . ")
		");
		while ($phrase = $vbulletin->db->fetch_array($phrases))
		{
			if (isset($jsphrases["$phrase[varname]"]))
			{
				$phrase['text'] = fetch_js_safe_string($phrase['text']);
			}
			if (strpos($phrase['text'], '{1}') !== false)
			{
				$phrase['text'] = str_replace('%', '%%', $phrase['text']);
			}

			$phrase['text'] = str_replace(
				array('', ''),
				'',
				$phrase['text']
			);

			$masterlang["{$phrase['fieldname']}"]["$phrase[varname]"] = $phrase['text'];
		}
	}

	// get phrases for language update
	$phrasearray = $masterlang;
	$phrasetemplate = array();
	$phrases = $vbulletin->db->query_read("
		SELECT varname, text, fieldname
		FROM " . TABLE_PREFIX . "phrase
		WHERE languageid = $languageid AND fieldname IN (" . implode(',', $gettypes) . ")
	");

	while ($phrase = $vbulletin->db->fetch_array($phrases, DBARRAY_BOTH))
	{
		if (isset($jsphrases["$phrase[varname]"]))
		{
			$phrase['text'] = fetch_js_safe_string($phrase['text']);
		}
		if (strpos($phrase['text'], '{1}') !== false)
		{
			$phrase['text'] = str_replace('%', '%%', $phrase['text']);
		}
		$phrasearray["{$phrase['fieldname']}"]["$phrase[varname]"] = $phrase['text'];
	}
	unset($phrase);
	$vbulletin->db->free_result($phrases);

	$SQL = 'title = title';

	foreach($phrasearray as $fieldname => $phrases)
	{
		ksort($phrases);
		$cachefield = $fieldname;
		$phrases = preg_replace('/\{([0-9]+)\}/siU', '%\\1$s', $phrases);
		$cachetext = $vbulletin->db->escape_string(serialize($phrases));
		$SQL .= ", phrasegroup_$cachefield = '$cachetext'";
	}

	$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "language SET $SQL WHERE languageid = $languageid");

}
Esempio n. 12
0
 /**
  * Additional data to update after a delete call (such as denormalized values in other tables).
  *
  * @param	boolean	Do the query?
  */
 function post_delete($doquery = true)
 {
     $db =& $this->registry->db;
     $db->query_write("\n\t\t\tUPDATE " . TABLE_PREFIX . "thread SET\n\t\t\t\tprefixid = ''\n\t\t\tWHERE prefixid = '" . $db->escape_string($this->fetch_field('prefixid')) . "'\n\t\t");
     // need to rebuild last post info in forums that use this prefix
     require_once DIR . '/includes/functions_databuild.php';
     //		$forums = $db->query_read("
     //			SELECT forumid
     //			FROM " . TABLE_PREFIX . "forumprefixset
     //			WHERE prefixsetid = '" . $db->escape_string($this->fetch_field('prefixsetid')) . "'
     //		");
     //		while ($forum = $db->fetch_array($forums))
     //		{
     //			build_forum_counters($forum['forumid']);
     //		}
     $db->query_write("\n\t\t\tDELETE FROM " . TABLE_PREFIX . "phrase\n\t\t\tWHERE varname IN (\n\t\t\t\t\t'" . $db->escape_string('prefix_' . $this->fetch_field('prefixid') . '_title_plain') . "',\n\t\t\t\t\t'" . $db->escape_string('prefix_' . $this->fetch_field('prefixid') . '_title_rich') . "'\n\t\t\t\t)\n\t\t\t\tAND fieldname = 'global'\n\t\t");
     require_once DIR . '/includes/adminfunctions_language.php';
     build_language();
     require_once DIR . '/includes/adminfunctions_prefix.php';
     build_prefix_datastore();
     // Legacy Hook 'prefixdata_delete' Removed //
     return true;
 }
Esempio n. 13
0
 /**
  * Set language as default language
  * @param int $languageid Language ID to be set as default
  * @return void
  */
 public function setDefault($languageid)
 {
     $this->checkHasAdminPermission('canadminlanguages');
     require_once DIR . '/includes/adminfunctions.php';
     require_once DIR . '/includes/adminfunctions_language.php';
     $languageid = intval($languageid);
     vB::getDbAssertor()->assertQuery('setting', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_UPDATE, 'value' => $languageid, vB_dB_Query::CONDITIONS_KEY => array('varname' => 'languageid')));
     vB::getDatastore()->build_options();
     $vbulletin->options['languageid'] = $languageid;
     build_language($languageid);
 }
Esempio n. 14
0
 /**
  * Add a new phrase or update an existing phrase
  * @param string $fieldname New Phrase Type for adding, old Phrase Type for editing
  * @param string $varname New Varname for adding, old Varname for editing
  * @param array $data Phrase data to be added or updated
  *              'text' => Phrase text array.
  *              'oldvarname' => Old varname for editing only
  *              'oldfieldname' => Old fieldname for editing only
  *              't' =>
  *              'ismaster' =>
  *              'product' => Product ID of the phrase
  * @return void
  */
 public function save($fieldname, $varname, $data)
 {
     $fieldname = trim($fieldname);
     $varname = trim($varname);
     $vb5_config =& vB::getConfig();
     $install = false;
     if (defined('VBINSTALL') and VBINSTALL) {
         $install = true;
     }
     $session = vB::getCurrentSession();
     if (!empty($session)) {
         $userinfo = $session->fetch_userinfo();
     } else {
         $userinfo = vB_User::fetchUserinfo(1);
     }
     require_once DIR . '/includes/adminfunctions.php';
     $full_product_info = fetch_product_list(true);
     if (empty($varname)) {
         throw new vB_Exception_Api('please_complete_required_fields');
     }
     if (!preg_match('#^[' . self::VALID_CLASS . ']+$#', $varname)) {
         throw new vB_Exception_Api('invalid_phrase_varname');
     }
     require_once DIR . '/includes/functions_misc.php';
     foreach ($data['text'] as $text) {
         if (!validate_string_for_interpolation($text)) {
             throw new vB_Exception_Api('phrase_text_not_safe', array($varname));
         }
     }
     // it's an update
     if (!empty($data['oldvarname']) and !empty($data['oldfieldname'])) {
         if (vB::getDbAssertor()->getField('phrase_fetchid', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_STORED, 'varname' => $varname))) {
             // Don't check if we are moving a phrase to another group but keeping the same name. See VBV-4192.
             if ($varname != $data['oldvarname'] and $fieldname != $data['oldfieldname']) {
                 throw new vB_Exception_Api('there_is_already_phrase_named_x', array($varname));
             }
             if ($varname != $data['oldvarname']) {
                 throw new vB_Exception_Api('variable_name_exists', array($data['oldvarname'], $varname));
             }
         }
         if (!is_array($data['oldfieldname'])) {
             $data['oldfieldname'] = array($data['oldfieldname']);
         }
         if (!in_array($fieldname, $data['oldfieldname'])) {
             $data['oldfieldname'][] = $fieldname;
         }
         // delete old phrases
         vB::getDbAssertor()->assertQuery('deleteOldPhrases', array('varname' => $data['oldvarname'], 'fieldname' => $data['oldfieldname'], 't' => $data['t'], 'debug' => empty($data['skipdebug']) && ($vb5_config['Misc']['debug'] or $install)));
         $update = 1;
         $this->setPhraseDate();
     }
     if (empty($update)) {
         if (empty($data['text'][0]) and $data['text'][0] != '0' and !$data['t'] or empty($varname)) {
             throw new vB_Exception_Api('please_complete_required_fields');
         }
         if (vB::getDbAssertor()->getField('phrase_fetchid', array('varname' => $varname, 'fieldname' => $fieldname))) {
             throw new vB_Exception_Api('there_is_already_phrase_named_x', array($varname));
         }
     }
     if ($data['ismaster']) {
         if (($vb5_config['Misc']['debug'] or $install) and !$data['t']) {
             /*insert query*/
             vB::getDbAssertor()->assertQuery('phrase', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_REPLACE, 'languageid' => -1, 'varname' => $varname, 'text' => $data['text'][0], 'fieldname' => $fieldname, 'product' => $data['product'], 'username' => $userinfo['username'], 'dateline' => vB::getRequest()->getTimeNow(), 'version' => $full_product_info[$data['product']]['version']));
         }
         unset($data['text'][0]);
     }
     foreach ($data['text'] as $_languageid => $txt) {
         $_languageid = intval($_languageid);
         if (!empty($txt) or $txt == '0') {
             /*insert query*/
             vB::getDbAssertor()->assertQuery('phrase', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_REPLACE, 'languageid' => $_languageid, 'varname' => $varname, 'text' => $txt, 'fieldname' => $fieldname, 'product' => $data['product'], 'username' => $userinfo['username'], 'dateline' => vB::getRequest()->getTimeNow(), 'version' => $full_product_info[$data['product']]['version']));
         }
     }
     require_once DIR . '/includes/adminfunctions.php';
     require_once DIR . '/includes/adminfunctions_language.php';
     build_language(-1);
 }
Esempio n. 15
0
/**
* Reads a language or languages and updates the language db table with the denormalized phrase cache
*
* @param	integer	ID of language to be built; if -1, build all
* @param	integer	Not sure actually... any ideas?
* @param	boolean.  Wether to reset the static vars the function uses to cache items for recursing
* 			when we we build the master language.  Otherwise if we attempt to call this function
* 			twice in the same pageload we don't actually manage to update any changes after the first
* 			call.
* 			The better approach would be to use an internal function and a master function
* 			that generates the cached values once and passes them in.
* 			However that means unwinding this function which works but is... odd.
*/
function build_language($languageid = -1, $phrasearray = 0, $reset_static = true)
{
    global $vbulletin;
    static $masterlang, $jsphrases = null;
    if ($reset_static) {
        $masterlang = null;
        $jsphrases = null;
    }
    // load js safe phrases
    if ($jsphrases === null) {
        require_once DIR . '/includes/class_xml.php';
        $xmlobj = new vB_XML_Parser(false, DIR . '/includes/xml/js_safe_phrases.xml');
        $safephrases = $xmlobj->parse();
        $jsphrases = array();
        if (is_array($safephrases['phrase'])) {
            foreach ($safephrases['phrase'] as $varname) {
                $jsphrases["{$varname}"] = true;
            }
        }
        unset($safephrases, $xmlobj);
    }
    // update all languages if this is the master language
    if ($languageid == -1) {
        $languages = $vbulletin->db->query_read("SELECT languageid FROM " . TABLE_PREFIX . "language");
        while ($language = $vbulletin->db->fetch_array($languages)) {
            build_language($language['languageid'], 0, false);
        }
        return;
    }
    // get phrase types for language update
    $gettypes = array();
    $getphrasetypes = $vbulletin->db->query_read("\n\t\tSELECT fieldname\n\t\tFROM " . TABLE_PREFIX . "phrasetype\n\t\tWHERE editrows <> 0 AND\n\t\t\tspecial = 0\n\t");
    while ($getphrasetype = $vbulletin->db->fetch_array($getphrasetypes)) {
        $gettypes[] = "'" . $vbulletin->db->escape_string($getphrasetype['fieldname']) . "'";
    }
    unset($getphrasetype);
    $vbulletin->db->free_result($getphrasetypes);
    if (empty($masterlang)) {
        $masterlang = array();
        $phrases = $vbulletin->db->query_read("\n\t\t\tSELECT fieldname, varname, text, languageid\n\t\t\tFROM " . TABLE_PREFIX . "phrase\n\t\t\tWHERE languageid IN(-1,0) AND\n\t\t\t\tfieldname IN (" . implode(',', $gettypes) . ")\n\t\t");
        while ($phrase = $vbulletin->db->fetch_array($phrases)) {
            if (isset($jsphrases["{$phrase['varname']}"])) {
                $phrase['text'] = fetch_js_safe_string($phrase['text']);
            }
            if (strpos($phrase['text'], '{1}') !== false) {
                $phrase['text'] = str_replace('%', '%%', $phrase['text']);
            }
            $phrase['text'] = str_replace(array('', ''), '', $phrase['text']);
            if (!isset($masterlang["{$phrase['fieldname']}"]["{$phrase['varname']}"]) or !$phrase['languageid']) {
                $masterlang["{$phrase['fieldname']}"]["{$phrase['varname']}"] = $phrase['text'];
            }
        }
    }
    // get phrases for language update
    $phrasearray = $masterlang;
    $phrasetemplate = array();
    $phrases = $vbulletin->db->query_read("\n\t\tSELECT varname, text, fieldname\n\t\tFROM " . TABLE_PREFIX . "phrase\n\t\tWHERE languageid = {$languageid} AND fieldname IN (" . implode(',', $gettypes) . ")\n\t");
    while ($phrase = $vbulletin->db->fetch_array($phrases, DBARRAY_BOTH)) {
        if (isset($jsphrases["{$phrase['varname']}"])) {
            $phrase['text'] = fetch_js_safe_string($phrase['text']);
        }
        if (strpos($phrase['text'], '{1}') !== false) {
            $phrase['text'] = str_replace('%', '%%', $phrase['text']);
        }
        $phrasearray["{$phrase['fieldname']}"]["{$phrase['varname']}"] = $phrase['text'];
    }
    unset($phrase);
    $vbulletin->db->free_result($phrases);
    $SQL = 'title = title';
    foreach ($phrasearray as $fieldname => $phrases) {
        ksort($phrases);
        $cachefield = $fieldname;
        $phrases = preg_replace('/\\{([0-9]+)\\}/siU', '%\\1$s', $phrases);
        $cachetext = $vbulletin->db->escape_string(serialize($phrases));
        $SQL .= ", phrasegroup_{$cachefield} = '{$cachetext}'";
    }
    // This only loads the last dateline for the ckeditor group, if this functionality is ever needed for other groups,
    // just move this code block into the foreach() above
    $maxdateline = $vbulletin->db->query_first("\n\t\tSELECT MAX(dateline) AS dateline\n\t\tFROM " . TABLE_PREFIX . "phrase\n\t\tWHERE\n\t\t\tlanguageid IN ({$languageid},-1)\n\t\t\t\tAND\n\t\t\tfieldname = 'ckeditor'\n\t");
    $info['ckeditor'] = array('maxdateline' => $maxdateline['dateline']);
    $SQL .= ", phrasegroupinfo = '" . $vbulletin->db->escape_string(serialize($info)) . "'";
    $vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "language SET {$SQL} WHERE languageid = {$languageid}");
}
Esempio n. 16
0
    print_input_row($vbphrase['title_for_uploaded_language'], 'title');
    print_yes_no_row($vbphrase['ignore_language_version'], 'anyversion', 0);
    print_yes_no_row($vbphrase['read_charset_from_file'], 'readcharset', 1);
    print_submit_row($vbphrase['import']);
}
// ##########################################################################
if ($_REQUEST['do'] == 'rebuild') {
    $vbulletin->input->clean_array_gpc('r', array('goto' => vB_Cleaner::TYPE_STR));
    $help = construct_help_button('', NULL, '', 1);
    echo "<p>&nbsp;</p>\n\t<blockquote><form><div class=\"tborder\">\n\t<div class=\"tcat\" style=\"padding:4px\" align=\"center\"><div style=\"float:" . vB_Template_Runtime::fetchStyleVar('right') . "\">{$help}</div><b>" . $vbphrase['rebuild_language_information'] . "</b></div>\n\t<div class=\"alt1\" style=\"padding:4px\">\n<blockquote>\n\t";
    vbflush();
    $languages = vB::getDatastore()->getValue('languagecache');
    foreach ($languages as $language) {
        echo "<p>" . construct_phrase($vbphrase['rebuilding_language_x'], "<b>{$language['title']}</b>") . iif($language['languageid'] == $vbulletin->options['languageid'], " ({$vbphrase['default']})") . ' ...';
        vbflush();
        build_language($language['languageid']);
        echo "<b>" . $vbphrase['done'] . "</b></p>\n";
        vbflush();
    }
    build_language_datastore();
    echo "</blockquote></div>\n\t<div class=\"tfoot\" style=\"padding:4px\" align=\"center\">\n\t\t<input type=\"button\" class=\"button\" value=\" {$vbphrase['done']} \" onclick=\"window.location='" . str_replace("'", "\\'", htmlspecialchars_uni($vbulletin->GPC['goto'])) . "';\" />\n\t</div>\n\t</div></form></blockquote>\n\t";
    vbflush();
}
// ##########################################################################
if ($_REQUEST['do'] == 'setdefault') {
    if ($vbulletin->GPC['dolanguageid'] == 0) {
        print_stop_message2('invalid_language_specified');
    }
    vB_Api::instanceInternal('language')->setDefault($vbulletin->GPC['dolanguageid']);
    $_REQUEST['do'] = 'modify';
}
/**
* Updates the setting table based on data passed in then rebuilds the datastore.
* Only entries in the array are updated (allows partial updates).
*
* @param	array	Array of settings. Format: [setting_name] = new_value
*
*/
function save_settings($settings)
{
    global $vbulletin, $vbphrase;
    //a few variables to track changes for processing after all variables are updated.
    $rebuildstyle = false;
    $templatecachepathchanged = false;
    $oldtemplatepath = null;
    $newtemplatepath = null;
    $userContext = vB::getUserContext();
    $cleaner = vB::getCleaner();
    $canAdminAll = $userContext->hasAdminPermission('canadminsettingsall');
    $oldsettings = vB::getDbAssertor()->assertQuery('vBAdmincp:getCurrentSettings', array('varname' => array_keys($settings)));
    foreach ($oldsettings as $oldsetting) {
        //check the setting and group permissions
        if (!empty($oldsetting['adminperm']) and !$userContext->hasAdminPermission($oldsetting['adminperm']) or !empty($oldsetting['groupperm']) and !$userContext->hasAdminPermission($oldsetting['groupperm'])) {
            throw new vB_Exception_Api('no_permission');
        }
        switch ($oldsetting['varname']) {
            // **************************************************
            case 'bbcode_html_colors':
                $settings['bbcode_html_colors'] = serialize($settings['bbcode_html_colors']);
                break;
                // **************************************************
            // **************************************************
            case 'styleid':
                vB::getDbAssertor()->assertQuery('vBForum:style', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_UPDATE, 'userselect' => 1, vB_dB_Query::CONDITIONS_KEY => array(array('field' => 'styleid', 'value' => $settings['styleid'], 'operator' => vB_dB_Query::OPERATOR_EQ))));
                break;
                // **************************************************
            // **************************************************
            case 'banemail':
                vB::getDatastore()->build('banemail', $settings['banemail']);
                $settings['banemail'] = '';
                break;
                // **************************************************
            // **************************************************
            case 'editormodes':
                $vbulletin->input->clean_array_gpc('p', array('fe' => vB_Cleaner::TYPE_UINT, 'qr' => vB_Cleaner::TYPE_UINT, 'qe' => vB_Cleaner::TYPE_UINT));
                $settings['editormodes'] = serialize(array('fe' => $vbulletin->GPC['fe'], 'qr' => $vbulletin->GPC['qr'], 'qe' => $vbulletin->GPC['qe']));
                break;
                // **************************************************
            // **************************************************
            case 'attachresizes':
                $vbulletin->input->clean_array_gpc('p', array('attachresizes' => vB_Cleaner::TYPE_ARRAY_UINT));
                $value = @unserialize($oldsetting['value']);
                $invalidate = array();
                if ($value[vB_Api_Filedata::SIZE_ICON] != $vbulletin->GPC['attachresizes'][vB_Api_Filedata::SIZE_ICON]) {
                    $invalidate[] = vB_Api_Filedata::SIZE_ICON;
                }
                if ($value[vB_Api_Filedata::SIZE_THUMB] != $vbulletin->GPC['attachresizes'][vB_Api_Filedata::SIZE_THUMB]) {
                    $invalidate[] = vB_Api_Filedata::SIZE_THUMB;
                }
                if ($value[vB_Api_Filedata::SIZE_SMALL] != $vbulletin->GPC['attachresizes'][vB_Api_Filedata::SIZE_SMALL]) {
                    $invalidate[] = vB_Api_Filedata::SIZE_SMALL;
                }
                if ($value[vB_Api_Filedata::SIZE_MEDIUM] != $vbulletin->GPC['attachresizes'][vB_Api_Filedata::SIZE_MEDIUM]) {
                    $invalidate[] = vB_Api_Filedata::SIZE_MEDIUM;
                }
                if ($value[vB_Api_Filedata::SIZE_LARGE] != $vbulletin->GPC['attachresizes'][vB_Api_Filedata::SIZE_LARGE]) {
                    $invalidate[] = vB_Api_Filedata::SIZE_LARGE;
                }
                if (!empty($invalidate)) {
                    vB::getDbAssertor()->update('vBForum:filedataresize', array('reload' => 1), array('resize_type' => $invalidate));
                }
                $settings['attachresizes'] = serialize(array(vB_Api_Filedata::SIZE_ICON => $vbulletin->GPC['attachresizes'][vB_Api_Filedata::SIZE_ICON], vB_Api_Filedata::SIZE_THUMB => $vbulletin->GPC['attachresizes'][vB_Api_Filedata::SIZE_THUMB], vB_Api_Filedata::SIZE_SMALL => $vbulletin->GPC['attachresizes'][vB_Api_Filedata::SIZE_SMALL], vB_Api_Filedata::SIZE_MEDIUM => $vbulletin->GPC['attachresizes'][vB_Api_Filedata::SIZE_MEDIUM], vB_Api_Filedata::SIZE_LARGE => $vbulletin->GPC['attachresizes'][vB_Api_Filedata::SIZE_LARGE]));
                break;
            case 'thumbquality':
                if ($oldsetting['value'] != $settings['thumbquality']) {
                    vB::getDbAssertor()->update('vBForum:filedataresize', array('reload' => 1), vB_dB_Query::CONDITION_ALL);
                }
                break;
                // **************************************************
            // **************************************************
            case 'cookiepath':
            case 'cookiedomain':
                if ($settings[$oldsetting['varname'] . '_other'] and $settings[$oldsetting['varname'] . '_value']) {
                    $settings[$oldsetting['varname']] = $settings[$oldsetting['varname'] . '_value'];
                }
                break;
                // **************************************************
            // **************************************************
            default:
                // Legacy Hook 'admin_options_processing' Removed //
                if ($oldsetting['optioncode'] == 'multiinput') {
                    $store = array();
                    foreach ($settings["{$oldsetting['varname']}"] as $value) {
                        if ($value != '') {
                            $store[] = $value;
                        }
                    }
                    $settings["{$oldsetting['varname']}"] = serialize($store);
                } else {
                    if (preg_match('#^(usergroup|forum)s?:([0-9]+|all|none)$#', $oldsetting['optioncode'])) {
                        // serialize the array of usergroup inputs
                        if (!is_array($settings["{$oldsetting['varname']}"])) {
                            $settings["{$oldsetting['varname']}"] = array();
                        }
                        $settings["{$oldsetting['varname']}"] = array_map('intval', $settings["{$oldsetting['varname']}"]);
                        $settings["{$oldsetting['varname']}"] = serialize($settings["{$oldsetting['varname']}"]);
                    }
                }
        }
        $newvalue = validate_setting_value($settings["{$oldsetting['varname']}"], $oldsetting['datatype']);
        if ($canAdminAll and isset($_POST['adminperm_' . $oldsetting[varname]])) {
            $newAdminPerm = substr($cleaner->clean($_POST['adminperm_' . $oldsetting[varname]], vB_Cleaner::TYPE_STR), 0, 32);
        } else {
            $newAdminPerm = $oldsetting['adminperm'];
        }
        // this is a strict type check because we want '' to be different from 0
        // some special cases below only use != checks to see if the logical value has changed
        if ($oldsetting['value'] === NULL or strval($oldsetting['value']) !== strval($newvalue) or strval($oldsetting['adminperm']) !== strval($newAdminPerm)) {
            switch ($oldsetting['varname']) {
                case 'cache_templates_as_files':
                    if (!is_demo_mode()) {
                        $templatecachepathchanged = true;
                    }
                    break;
                case 'template_cache_path':
                    if (!is_demo_mode()) {
                        $oldtemplatepath = strval($oldsetting['value']);
                        $newtemplatepath = $newvalue;
                    }
                    break;
                case 'languageid':
                    if ($oldsetting['value'] != $newvalue) {
                        vB::getDatastore()->setOption('languageid', $newvalue, false);
                        require_once DIR . '/includes/adminfunctions_language.php';
                        build_language($newvalue);
                    }
                    break;
                case 'cpstylefolder':
                    $admindm =& datamanager_init('Admin', $vbulletin, vB_DataManager_Constants::ERRTYPE_CP);
                    $admindm->set_existing(vB::getCurrentSession()->fetch_userinfo());
                    $admindm->set('cssprefs', $newvalue);
                    $admindm->save();
                    unset($admindm);
                    break;
                case 'attachthumbssize':
                    if ($oldsetting['value'] != $newvalue) {
                        $rebuildstyle = true;
                    }
                case 'storecssasfile':
                    if (!is_demo_mode() and $oldsetting['value'] != $newvalue) {
                        vB::getDatastore()->setOption('storecssasfile', $newvalue, false);
                        $rebuildstyle = true;
                    }
                    break;
                case 'loadlimit':
                    update_loadavg();
                    break;
                case 'tagcloud_usergroup':
                    build_datastore('tagcloud', serialize(''), 1);
                    break;
                case 'censorwords':
                case 'codemaxlines':
                case 'url_nofollow':
                case 'url_nofollow_whitelist':
                    if ($oldsetting['value'] != $newvalue) {
                        if (vB::getDatastore()->getOption('templateversion') >= '3.6') {
                            vB::getDbAssertor()->assertQuery('truncateTable', array('table' => 'sigparsed'));
                        }
                    }
                    // Legacy Hook 'admin_options_processing_censorcode' Removed //
                    break;
                case 'album_recentalbumdays':
                    if ($oldsetting['value'] > $newvalue) {
                        require_once DIR . '/includes/functions_album.php';
                        exec_rebuild_album_updates();
                    }
                default:
                    // Legacy Hook 'admin_options_processing_build' Removed //
            }
            if (is_demo_mode() and in_array($oldsetting['varname'], array('cache_templates_as_files', 'template_cache_path', 'storecssasfile', 'attachfile', 'usefileavatar', 'errorlogdatabase', 'errorlogsecurity', 'safeupload', 'tmppath'))) {
                continue;
            }
            $updateSetting = vB::getDbAssertor()->assertQuery('setting', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_UPDATE, 'value' => $newvalue, 'adminperm' => $newAdminPerm, vB_dB_Query::CONDITIONS_KEY => array(array('field' => 'varname', 'value' => $oldsetting['varname'], 'operator' => vB_dB_Query::OPERATOR_EQ))));
        }
    }
    if (!isset($oldsetting)) {
        return false;
    }
    vB::getDatastore()->build_options();
    if (defined('DEV_AUTOEXPORT') and DEV_AUTOEXPORT) {
        require_once DIR . '/includes/functions_filesystemxml.php';
        $xml = get_settings_export_xml('vbulletin');
        autoexport_write_file_with_backup(DIR . '/install/vbulletin-settings.xml', $xml);
    }
    //handle changes for cache_templates_as_files and template_cache_path
    //we do it here because there are interactions between them and we don't
    //want to redo the chache changes twice if both are changed.
    $api = vB_Api::instanceInternal('template');
    if ($templatecachepathchanged or !is_null($oldtemplatepath) and !is_null($newtemplatepath)) {
        if (vB::getDatastore()->getOption('cache_templates_as_files')) {
            if (!is_null($oldtemplatepath)) {
                //temporarily set the datastore path to the old value to clear it.
                vB::getDatastore()->setOption('template_cache_path', $oldtemplatepath, false);
                $api->deleteAllTemplateFiles();
                vB::getDatastore()->setOption('template_cache_path', $newtemplatepath, false);
            }
            $api->saveAllTemplatesToFile();
        } else {
            //we we changed directories and the cache is off, delete from the old directory
            if (!is_null($oldtemplatepath)) {
                vB::getDatastore()->setOption('template_cache_path', $oldtemplatepath, false);
                $api->deleteAllTemplateFiles();
                vB::getDatastore()->setOption('template_cache_path', $newtemplatepath, false);
            } else {
                $api->deleteAllTemplateFiles();
            }
        }
    }
    if ($rebuildstyle) {
        require_once DIR . '/includes/adminfunctions_template.php';
        print_rebuild_style(-1, '', 1, 0, 0, 0);
    }
    return true;
}
Esempio n. 18
0
	/**
	* Additional data to update after a delete call (such as denormalized values in other tables).
	*
	* @param	boolean	Do the query?
	*/
	function post_delete($doquery = true)
	{
		$db =& $this->registry->db;

		$db->query_write("
			UPDATE " . TABLE_PREFIX . "thread SET
				prefixid = ''
			WHERE prefixid = '" . $db->escape_string($this->fetch_field('prefixid')) . "'
		");

		// need to rebuild last post info in forums that use this prefix
		require_once(DIR . '/includes/functions_databuild.php');

		$forums = $db->query_read("
			SELECT forumid
			FROM " . TABLE_PREFIX . "forumprefixset
			WHERE prefixsetid = '" . $db->escape_string($this->fetch_field('prefixsetid')) . "'
		");
		while ($forum = $db->fetch_array($forums))
		{
			build_forum_counters($forum['forumid']);
		}

		$db->query_write("
			DELETE FROM " . TABLE_PREFIX . "phrase
			WHERE varname IN (
					'" . $db->escape_string('prefix_' .  $this->fetch_field('prefixid') . '_title_plain') . "',
					'" . $db->escape_string('prefix_' .  $this->fetch_field('prefixid') . '_title_rich') . "'
				)
				AND fieldname = 'global'
		");

		require_once(DIR . '/includes/adminfunctions_language.php');
		build_language();

		require_once(DIR . '/includes/adminfunctions_prefix.php');
		build_prefix_datastore();

		($hook = vBulletinHook::fetch_hook('prefixdata_delete')) ? eval($hook) : false;
		return true;
	}
Esempio n. 19
0
 /**
  * Additional data to update after a delete call (such as denormalized values in other tables).
  *
  * @param	boolean	Do the query?
  */
 function post_delete($doquery = true)
 {
     $this->registry->db->query_first("\r\n\t\t\tDELETE FROM " . TABLE_PREFIX . "phrase\r\n\t\t\tWHERE varname = 'issuestatus" . $this->fetch_field('issuestatusid') . "'\r\n\t\t\t\tAND fieldname = 'projecttools'\r\n\t\t");
     if ($this->info['rebuild_caches']) {
         require_once DIR . '/includes/adminfunctions_language.php';
         build_language();
         require_once DIR . '/includes/adminfunctions_projecttools.php';
         build_issue_type_cache();
     }
     // update any issues with this status...
     if ($this->info['delete_deststatusid'] and $dest_status = $this->registry->db->query_first("\r\n\t\t\tSELECT *\r\n\t\t\tFROM " . TABLE_PREFIX . "pt_issuestatus\r\n\t\t\tWHERE issuestatusid = " . intval($this->info['delete_deststatusid']) . "\r\n\t\t\t\tAND issuetypeid = '" . $this->registry->db->escape_string($this->fetch_field('issuetypeid')) . "'\r\n\t\t")) {
         // ... to the destination status
         $this->registry->db->query_write("\r\n\t\t\t\tUPDATE " . TABLE_PREFIX . "pt_issue SET\r\n\t\t\t\t\tissuestatusid = {$dest_status['issuestatusid']}\r\n\t\t\t\tWHERE issuestatusid = " . $this->fetch_field('issuestatusid'));
     } else {
         // ... or, if we don't know a destination, the default start state
         $this->registry->db->query_write("\r\n\t\t\t\tUPDATE " . TABLE_PREFIX . "pt_issue AS issue\r\n\t\t\t\tINNER JOIN " . TABLE_PREFIX . "pt_projecttype AS projecttype ON\r\n\t\t\t\t\t(projecttype.projectid = issue.projectid\r\n\t\t\t\t\tAND projecttype.issuetypeid = '" . $this->registry->db->escape_string($this->fetch_field('issuetypeid')) . "')\r\n\t\t\t\tSET issue.issuestatusid = projecttype.startstatusid\r\n\t\t\t\tWHERE issue.issuestatusid = " . $this->fetch_field('issuestatusid'));
     }
     if ($this->info['rebuild_caches']) {
         rebuild_project_counters(false);
         rebuild_milestone_counters(false);
     }
     ($hook = vBulletinHook::fetch_hook('pt_issuestatusdata_delete')) ? eval($hook) : false;
     return true;
 }
Esempio n. 20
0
/**
* Updates the setting table based on data passed in then rebuilds the datastore.
* Only entries in the array are updated (allows partial updates).
*
* @param	array	Array of settings. Format: [setting_name] = new_value
*/
function save_settings($settings)
{
    global $vbulletin, $vbphrase, $stylevar;
    $varnames = array();
    foreach (array_keys($settings) as $varname) {
        $varnames[] = $vbulletin->db->escape_string($varname);
    }
    $oldsettings = $vbulletin->db->query_read("\n\t\tSELECT value, varname, datatype, optioncode\n\t\tFROM " . TABLE_PREFIX . "setting\n\t\tWHERE varname IN ('" . implode("', '", $varnames) . "')\n\t\tORDER BY varname\n\t");
    while ($oldsetting = $vbulletin->db->fetch_array($oldsettings)) {
        switch ($oldsetting['varname']) {
            // **************************************************
            case 'bbcode_html_colors':
                $settings['bbcode_html_colors'] = serialize($settings['bbcode_html_colors']);
                break;
                // **************************************************
            // **************************************************
            case 'styleid':
                $vbulletin->db->query_write("\n\t\t\t\t\tUPDATE " . TABLE_PREFIX . "style\n\t\t\t\t\tSET userselect = 1\n\t\t\t\t\tWHERE styleid = " . $settings['styleid'] . "\n\t\t\t\t");
                break;
                // **************************************************
            // **************************************************
            case 'banemail':
                build_datastore('banemail', $settings['banemail']);
                $settings['banemail'] = '';
                break;
                // **************************************************
            // **************************************************
            case 'editormodes':
                $vbulletin->input->clean_array_gpc('p', array('fe' => TYPE_UINT, 'qr' => TYPE_UINT, 'qe' => TYPE_UINT));
                $settings['editormodes'] = serialize(array('fe' => $vbulletin->GPC['fe'], 'qr' => $vbulletin->GPC['qr'], 'qe' => $vbulletin->GPC['qe']));
                break;
                // **************************************************
            // **************************************************
            case 'cookiepath':
            case 'cookiedomain':
                if ($settings[$oldsetting['varname'] . '_other'] and $settings[$oldsetting['varname'] . '_value']) {
                    $settings[$oldsetting['varname']] = $settings[$oldsetting['varname'] . '_value'];
                }
                break;
                // **************************************************
            // **************************************************
            default:
                ($hook = vBulletinHook::fetch_hook('admin_options_processing')) ? eval($hook) : false;
                if ($oldsetting['optioncode'] == 'multiinput') {
                    $store = array();
                    foreach ($settings["{$oldsetting['varname']}"] as $value) {
                        if ($value != '') {
                            $store[] = $value;
                        }
                    }
                    $settings["{$oldsetting['varname']}"] = serialize($store);
                } else {
                    if (preg_match('#^usergroup:[0-9]+$#', $oldsetting['optioncode'])) {
                        // serialize the array of usergroup inputs
                        if (!is_array($settings["{$oldsetting['varname']}"])) {
                            $settings["{$oldsetting['varname']}"] = array();
                        }
                        $settings["{$oldsetting['varname']}"] = array_map('intval', $settings["{$oldsetting['varname']}"]);
                        $settings["{$oldsetting['varname']}"] = serialize($settings["{$oldsetting['varname']}"]);
                    }
                }
        }
        $newvalue = validate_setting_value($settings["{$oldsetting['varname']}"], $oldsetting['datatype']);
        // this is a strict type check because we want '' to be different from 0
        // some special cases below only use != checks to see if the logical value has changed
        if (strval($oldsetting['value']) !== strval($newvalue)) {
            switch ($oldsetting['varname']) {
                case 'activememberdays':
                case 'activememberoptions':
                    if ($oldsetting['value'] != $newvalue) {
                        $vbulletin->options["{$oldsetting['varname']}"] = $newvalue;
                        require_once DIR . '/includes/functions_databuild.php';
                        build_birthdays();
                    }
                    break;
                case 'showevents':
                case 'showholidays':
                    if ($oldsetting['value'] != $newvalue) {
                        $vbulletin->options["{$oldsetting['varname']}"] = $newvalue;
                        require_once DIR . '/includes/functions_calendar.php';
                        build_events();
                    }
                    break;
                case 'languageid':
                    if ($oldsetting['value'] != $newvalue) {
                        $vbulletin->options['languageid'] = $newvalue;
                        require_once DIR . '/includes/adminfunctions_language.php';
                        build_language($vbulletin->options['languageid']);
                    }
                    break;
                case 'cpstylefolder':
                    $admindm =& datamanager_init('Admin', $vbulletin, ERRTYPE_CP);
                    $admindm->set_existing($vbulletin->userinfo);
                    $admindm->set('cssprefs', $newvalue);
                    $admindm->save();
                    unset($admindm);
                    break;
                case 'storecssasfile':
                    if (!is_demo_mode() and $oldsetting['value'] != $newvalue) {
                        $vbulletin->options['storecssasfile'] = $newvalue;
                        require_once DIR . '/includes/adminfunctions_template.php';
                        print_rebuild_style(-1, '', 1, 0, 0, 0);
                    }
                    break;
                case 'loadlimit':
                    update_loadavg();
                    break;
                case 'view_tagcloud_as_usergroup':
                    build_datastore('tagcloud', serialize(''), 1);
                    break;
                case 'censorwords':
                case 'codemaxlines':
                    if ($oldsetting['value'] != $newvalue) {
                        $vbulletin->db->query_write("TRUNCATE TABLE " . TABLE_PREFIX . "postparsed");
                        if ($vbulletin->options['templateversion'] >= '3.6') {
                            $vbulletin->db->query_write("TRUNCATE TABLE " . TABLE_PREFIX . "sigparsed");
                        }
                    }
                    ($hook = vBulletinHook::fetch_hook('admin_options_processing_censorcode')) ? eval($hook) : false;
                    break;
                default:
                    ($hook = vBulletinHook::fetch_hook('admin_options_processing_build')) ? eval($hook) : false;
            }
            if (is_demo_mode() and in_array($oldsetting['varname'], array('storecssasfile', 'attachfile', 'usefileavatar', 'errorlogdatabase', 'errorlogsecurity', 'safeupload', 'tmppath'))) {
                continue;
            }
            $vbulletin->db->query_write("\n\t\t\t\tUPDATE " . TABLE_PREFIX . "setting\n\t\t\t\tSET value = '" . $vbulletin->db->escape_string($newvalue) . "'\n\t\t\t\tWHERE varname = '" . $vbulletin->db->escape_string($oldsetting['varname']) . "'\n\t\t\t");
        }
    }
    build_options();
}
/**
* Reads a language or languages and updates the language db table with the denormalized phrase cache
*
* @param	integer	ID of language to be built; if -1, build all
* @param	integer	Not sure actually... any ideas?
* @param	boolean.  Wether to reset the static vars the function uses to cache items for recursing
* 			when we we build the master language.  Otherwise if we attempt to call this function
* 			twice in the same pageload we don't actually manage to update any changes after the first
* 			call.
* 			The better approach would be to use an internal function and a master function t
* 			hat generates the cached values once and passes them in.
* 			However that means unwinding this function which works but is... odd.
*/
function build_language($languageid = -1, $phrasearray = 0, $reset_static = true)
{
    static $masterlang = null, $jsphrases = null;
    if ($reset_static) {
        $masterlang = null;
        $jsphrases = null;
    }
    // load js safe phrases
    if ($jsphrases === null) {
        require_once DIR . '/includes/class_xml.php';
        $xmlobj = new vB_XML_Parser(false, DIR . '/includes/xml/js_safe_phrases.xml');
        $safephrases = $xmlobj->parse();
        $jsphrases = array();
        if (is_array($safephrases['phrase'])) {
            foreach ($safephrases['phrase'] as $varname) {
                $jsphrases["{$varname}"] = true;
            }
        }
        unset($safephrases, $xmlobj);
    }
    // update all languages if this is the master language
    if ($languageid == -1) {
        $languages = vB::getDatastore()->getValue('languagecache');
        if (empty($languages)) {
            // during install, the datastore is empty
            $languages = vB::getDbAssertor()->assertQuery('language', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, vB_Db_Query::COLUMNS_KEY => array('languageid')));
        }
        foreach ($languages as $language) {
            build_language($language['languageid'], 0, false);
        }
        return;
    }
    // get phrase types for language update
    $gettypes = array();
    $getphrasetypes = vB::getDbAssertor()->getRows('vBForum:fetchphrasetypes', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_STORED));
    foreach ($getphrasetypes as $getphrasetype) {
        $gettypes[] = $getphrasetype['fieldname'];
    }
    unset($getphrasetype);
    //This can be called early in the install process, before phrases have been inserted
    if (empty($gettypes)) {
        return true;
    }
    if (empty($masterlang)) {
        $masterlang = array();
        $phrases = vB::getDbAssertor()->assertQuery('vBForum:phrase', array('languageid' => array(-1, 0), 'fieldname' => $gettypes, vB_dB_Query::COLUMNS_KEY => array('fieldname', 'varname', 'text')));
        foreach ($phrases as $phrase) {
            if (isset($jsphrases["{$phrase['varname']}"])) {
                $phrase['text'] = fetch_js_safe_string($phrase['text']);
            }
            if (strpos($phrase['text'], '{1}') !== false) {
                $phrase['text'] = str_replace('%', '%%', $phrase['text']);
            }
            $phrase['text'] = str_replace(array(''), '', $phrase['text']);
            $masterlang["{$phrase['fieldname']}"]["{$phrase['varname']}"] = $phrase['text'];
        }
    }
    // get phrases for language update
    $phrasearray = $masterlang;
    $phrasetemplate = array();
    $phrases = vB::getDbAssertor()->assertQuery('vBForum:phrase', array('languageid' => $languageid, 'fieldname' => $gettypes, vB_dB_Query::COLUMNS_KEY => array('fieldname', 'varname', 'text')));
    foreach ($phrases as $phrase) {
        if (isset($jsphrases["{$phrase['varname']}"])) {
            $phrase['text'] = fetch_js_safe_string($phrase['text']);
        }
        if (strpos($phrase['text'], '{1}') !== false) {
            $phrase['text'] = str_replace('%', '%%', $phrase['text']);
        }
        $phrasearray["{$phrase['fieldname']}"]["{$phrase['varname']}"] = $phrase['text'];
    }
    unset($phrase);
    if (!empty($phrasearray)) {
        vB::getDbAssertor()->assertQuery('vBForum:rebuildLanguage', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_METHOD, 'phrasearray' => $phrasearray, 'languageid' => $languageid));
    }
    vB_Cache::instance()->event("vB_Language_languageCache");
}
Esempio n. 22
0
    }
    if ($vbulletin->GPC['ismaster']) {
        if ($vbulletin->debug and !$vbulletin->GPC['t']) {
            /*insert query*/
            $db->query_write("\n\t\t\t\tINSERT INTO " . TABLE_PREFIX . "phrase\n\t\t\t\t\t(languageid, varname, text, fieldname, product, username, dateline, version)\n\t\t\t\tVALUES\n\t\t\t\t\t(-1,\n\t\t\t\t\t'" . $db->escape_string($vbulletin->GPC['varname']) . "',\n\t\t\t\t\t'" . $db->escape_string($vbulletin->GPC['text'][0]) . "',\n\t\t\t\t\t'" . $db->escape_string($vbulletin->GPC['fieldname']) . "',\n\t\t\t\t\t'" . $db->escape_string($vbulletin->GPC['product']) . "',\n\t\t\t\t\t'" . $db->escape_string($vbulletin->userinfo['username']) . "',\n\t\t\t\t\t" . TIMENOW . ",\n\t\t\t\t\t'" . $db->escape_string($full_product_info[$vbulletin->GPC['product']]['version']) . "')\n\t\t\t");
        }
        unset($vbulletin->GPC['text'][0]);
    }
    foreach ($vbulletin->GPC['text'] as $_languageid => $txt) {
        $_languageid = intval($_languageid);
        if (!empty($txt) or $txt == '0') {
            /*insert query*/
            $db->query_write("\n\t\t\t\tINSERT INTO " . TABLE_PREFIX . "phrase\n\t\t\t\t\t(languageid, varname, text, fieldname, product, username, dateline, version)\n\t\t\t\tVALUES\n\t\t\t\t\t({$_languageid},\n\t\t\t\t\t'" . $db->escape_string($vbulletin->GPC['varname']) . "',\n\t\t\t\t\t'" . $db->escape_string($txt) . "',\n\t\t\t\t\t'" . $db->escape_string($vbulletin->GPC['fieldname']) . "',\n\t\t\t\t\t'" . $db->escape_string($vbulletin->GPC['product']) . "',\n\t\t\t\t\t'" . $db->escape_string($vbulletin->userinfo['username']) . "',\n\t\t\t\t\t" . TIMENOW . ",\n\t\t\t\t\t'" . $db->escape_string($full_product_info[$vbulletin->GPC['product']]['version']) . "')\n\t\t\t");
        }
    }
    build_language(-1);
    define('CP_REDIRECT', "phrase.php?fieldname=" . $vbulletin->GPC['sourcefieldname'] . "&amp;page=" . $vbulletin->GPC['pagenumber'] . "&amp;pp=" . $vbulletin->GPC['perpage']);
    print_stop_message('saved_phrase_x_successfully', $vbulletin->GPC['varname']);
}
// #############################################################################
if ($_REQUEST['do'] == 'add' or $_REQUEST['do'] == 'edit') {
    ?>
<script type="text/javascript">
function copy_default_text(targetlanguage)
{
	var deftext = fetch_object("default_phrase").value
	if (deftext == "")
	{
		alert("<?php 
    echo $vbphrase['default_text_is_empty'];
    ?>
Esempio n. 23
0
 /**
  * Saves a page based on page editor info
  * @param 	mixed	$input
  * @return 	mixed	array
  * 	success boolean
  * 	url string -- DEPRECATED this will not always be correct due to the lack of complete route data.  See the action savePage
  * 		in the front end controller for a way to generate the correct url for the updated page
  * 	pageid int -- the pageid for the update or created page
  */
 public function pageSave($input)
 {
     $this->checkHasAdminPermission('canusesitebuilder');
     /* Sample input
     		Array
     		(
     			[pageid] => 1,
     			[screenlayoutid] => 2,
     			[displaysections[0 => [{"widgetId":"3","widgetInstanceId":"1"},{"widgetId":"4","widgetInstanceId":"2"}],
     			[displaysections[1 => [{"widgetId":"1","widgetInstanceId":"3"},{"widgetId":"2","widgetInstanceId":"4"}],
     			[pagetitle] => Forums,
     			[resturl] => forums,
     			[pagetemplateid] => 0,	// 0 if we are saving the page template as a new page template
     			[templatetitle] => Name,
     			[btnSaveEditPage] =>
     		)
     		*/
     $done = false;
     $i = 0;
     $displaysections = array();
     foreach ($input as $key => $value) {
         if (!empty($value) and preg_match('/^displaysections\\[([0-9]+)$/i', $key, $matches)) {
             $displaysection_value = json_decode($value, true);
             if (!empty($displaysection_value)) {
                 $displaysections[$matches[1]] = $displaysection_value;
             }
         }
     }
     // TODO: apparently JQuery will send POST data using the UTF-8 charset,
     // so we don't convert the resturl. However, if the url can be edited from anywhere
     // else than Site Builder, we'll need to convert it properly to ensure that the
     // route table gets the proper UTF-8 characters saved.
     // cleaning input
     $input = array('pagetitle' => trim(strval($input['pagetitle'])), 'resturl' => trim(strval($input['resturl']), " \t\n\r\v/"), 'pageid' => intval($input['pageid']), 'nodeid' => intval($input['nodeid']), 'userid' => intval($input['userid']), 'pagetemplateid' => intval($input['pagetemplateid']), 'templatetitle' => trim(strval($input['templatetitle'])), 'screenlayoutid' => intval($input['screenlayoutid']), 'displaysections' => $displaysections, 'metadescription' => trim(strval($input['metadescription'])));
     // we need to check that resturl does not contain any reserved characters.
     if (!$this->checkCustomUrl($input['resturl'])) {
         throw new vB_Exception_Api('invalid_custom_url', vB_String::INVALID_CUSTOM_URL_CHAR);
     }
     if (empty($input['pagetitle'])) {
         throw new vB_Exception_Api('page_title_cannot_be_empty');
     }
     if (empty($input['templatetitle']) and $input['pagetemplateid'] < 1) {
         throw new vB_Exception_Api('page_template_title_cannot_be_empty');
     }
     if ($input['screenlayoutid'] < 1) {
         throw new vB_Exception_Api('you_must_specify_a_screen_layout');
     }
     $this->db = vB::getDbAssertor();
     // --- save the page template ----------------------------
     // get page info
     $forceNewPage = false;
     /* if prefix is modified, we need to create a new page, pagetemplate and widgets */
     $isPrefixUsed = false;
     if ($input['pageid'] > 0) {
         $page = $this->fetchPageById($input['pageid'], array('nodeid' => $input['nodeid'], 'userid' => $input['userid']));
         if (!is_array($page)) {
             $page = array();
         } else {
             $forceNewPage = ($page['isgeneric'] and $input['resturl'] != $page['urlprefix']);
             // if we are modifying a page url, we need to check the new url...
             if ($input['resturl'] != $page['urlprefix']) {
                 $isPrefixUsed = vB5_Route::isPrefixUsed($input['resturl'], $page['routeid']);
             }
         }
     } else {
         // if it is a new page, we need to check the url
         $isPrefixUsed = vB5_Route::isPrefixUsed($input['resturl']);
         $page = array();
     }
     $routeApi = vB_Api::instanceInternal('route');
     // if the used prefix is a 301 to another route, then we can take it.
     if ($isPrefixUsed !== FALSE and empty($isPrefixUsed['redirectRouteId'])) {
         throw new vB_Exception_Api('this_url_is_already_used');
     }
     // page template
     $valuePairs = array('title' => $input['templatetitle'], 'screenlayoutid' => $input['screenlayoutid']);
     $pagetemplateid = $input['pagetemplateid'];
     if ($pagetemplateid < 1 or $forceNewPage) {
         $valuePairs['guid'] = vB_Xml_Export_PageTemplate::createGUID($valuePairs);
         // If no widgets were configured on the page template, we won't have a page template ID.
         $pagetemplateid = $this->db->insert('pagetemplate', $valuePairs);
         if (is_array($pagetemplateid)) {
             $pagetemplateid = (int) array_pop($pagetemplateid);
         }
         $newTemplate = true;
     } else {
         $this->db->update('pagetemplate', $valuePairs, array('pagetemplateid' => $pagetemplateid));
         $newTemplate = false;
     }
     // widgets on page template
     $widgetApi = vB_Api::instanceInternal('widget');
     $currentWidgetInstances = $widgetApi->fetchWidgetInstancesByPageTemplateId($pagetemplateid);
     $currentWidgetInstanceIds = $this->getAllCurrentModuleInstances($currentWidgetInstances);
     $savedWidgetInstanceIds = array();
     $widgets = array();
     foreach ($input['displaysections'] as $displaycolumn => $columnwidgets) {
         $displayorder = 0;
         foreach ($columnwidgets as $columnwidget) {
             $columnwidgetid = intval($columnwidget['widgetId']);
             $columnwidgetinstanceid = intval($columnwidget['widgetInstanceId']);
             if (!$columnwidgetid) {
                 continue;
             }
             if ($newTemplate) {
                 $widgetInstanceId = 0;
             } else {
                 $widgetInstanceId = $columnwidgetinstanceid;
                 $savedWidgetInstanceIds[$widgetInstanceId] = $columnwidgetid;
             }
             $widget = array('widgetinstanceid' => $widgetInstanceId, 'pagetemplateid' => $pagetemplateid, 'widgetid' => $columnwidgetid, 'displaysection' => $displaycolumn, 'displayorder' => $displayorder);
             if (isset($columnwidget['subModules'])) {
                 $widget['subModules'] = $columnwidget['subModules'];
                 $widget['displaySubModules'] = $columnwidget['displaySubModules'];
                 if (!$newTemplate) {
                     $savedWidgetInstanceIds += $this->getAllSubModulesInstances($columnwidget['subModules']);
                 }
             }
             $widgets[] = $widget;
             ++$displayorder;
         }
     }
     // check we are not adding a system widget
     $newWidgets = array_diff_key($savedWidgetInstanceIds, $currentWidgetInstanceIds);
     if ($newWidgets) {
         foreach ($newWidgets as $widgetId) {
             if ($widgetApi->isSystemWidget($widgetId)) {
                 throw new vB_Exception_Api('cannot_add_system_module');
             }
         }
     }
     // check we are not removing a system widget
     $deleteWidgets = array_diff_key($currentWidgetInstanceIds, $savedWidgetInstanceIds);
     if ($deleteWidgets) {
         foreach ($deleteWidgets as $widgetId) {
             if ($widgetApi->isSystemWidget($widgetId)) {
                 throw new vB_Exception_Api('cannot_remove_system_module');
             }
         }
     }
     // save widget placements on the page template
     foreach ($widgets as $widget) {
         $widgetinstanceid = $widget['widgetinstanceid'];
         unset($widget['widgetinstanceid']);
         $subModules = isset($widget['subModules']) ? $widget['subModules'] : array();
         unset($widget['subModules']);
         $displaySubModules = isset($widget['displaySubModules']) ? $widget['displaySubModules'] : array();
         unset($widget['displaySubModules']);
         if ($widgetinstanceid > 0 and !$forceNewPage) {
             $this->db->update('widgetinstance', $widget, array('widgetinstanceid' => $widgetinstanceid));
         } else {
             $widgetinstanceid = $this->db->insert('widgetinstance', $widget);
             if (is_array($widgetinstanceid)) {
                 $widgetinstanceid = (int) array_pop($widgetinstanceid);
             }
         }
         // save submodules if available
         if (!empty($subModules)) {
             $this->saveSubModules($pagetemplateid, $widgetinstanceid, $subModules, $displaySubModules, $forceNewPage);
         }
     }
     // remove any widgets that have been removed from the page template
     if (!empty($deleteWidgets)) {
         $deleted = $widgetApi->deleteWidgetInstances(array_keys($deleteWidgets));
         if ($deleted != count($deleteWidgets)) {
             throw new vB_Exception_Api('unable_to_delete_widget_instances');
         }
     }
     // --- save the page  ---------------------------------
     // permalink
     $urlprefix = $input['resturl'];
     $valuePairs = array('pagetemplateid' => $pagetemplateid);
     // save page
     if (!empty($page) and !$forceNewPage) {
         // update page record
         $conditions = array('pageid' => $page['pageid']);
         $this->save($valuePairs, $conditions);
         $pageid = $page['pageid'];
         $guidforphrase = vB_Library::instance('phrase')->cleanGuidForPhrase($page['guid']);
         // update this page's current route if needed
         if ($input['resturl'] != $page['urlprefix']) {
             $data = array('prefix' => $urlprefix);
             if (isset($input['nodeid']) and !empty($input['nodeid'])) {
                 $data['nodeid'] = $input['nodeid'];
             }
             vB5_Route::updateRoute($page['routeid'], $data);
         }
     } else {
         $valuePairs['guid'] = vB_Xml_Export_Page::createGUID($valuePairs);
         $guidforphrase = vB_Library::instance('phrase')->cleanGuidForPhrase($valuePairs['guid']);
         // insert a new page
         $pageid = $this->save($valuePairs);
         if (is_array($pageid)) {
             $pageid = (int) array_pop($pageid);
         }
         // route
         if (isset($page['routeid'])) {
             // update this page's current route
             $data = array('pageid' => $pageid, 'prefix' => $urlprefix, 'nodeid' => $input['nodeid']);
             $routeid = vB5_Route::updateRoute($page['routeid'], $data);
         } else {
             $valuePairs = array('prefix' => $urlprefix, 'contentid' => $pageid);
             $routeid = $routeApi->createRoute('vB5_Route_Page', $valuePairs);
         }
         if (is_array($routeid)) {
             $routeid = (int) array_pop($routeid);
         }
         // update page with routeid (for deleting it when deleting a page)
         $routeApi->updateNewPageRoute($pageid, $routeid);
         // VBV-13666. Since $forceNewPage is true, we have created a new
         // page record corresponding to $pageid. But it appears that the
         // actual page being used is still the old page record. Thus we need
         // to update the routeid in the old page record so that the redirect
         // works correctly (the page route class gets the cannonical route
         // record based on the routeid in the page record). When/if we fix/change
         // the behavior for creating a new page record when updating the page
         // route prefix, this code will be wrong-- instead, we will need code
         // in the if branch above (for updating a page as opposed to creating
         // a new one), to update the routeid in the page record.
         if (!empty($page['pageid'])) {
             $routeApi->updateNewPageRoute($page['pageid'], $routeid);
         }
     }
     // Insert/Update phrases for page title, meta description.
     // Only update phrases of current language. Keep other translations.
     $phraseLib = vB_Library::instance('phrase');
     $currentlanguageid = vB::getCurrentSession()->get('languageid');
     if (empty($currentlanguageid)) {
         $currentlanguageid = vB::getDatastore()->getOption('languageid');
     }
     $translations = vB::getDbAssertor()->assertQuery('phrase', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, vB_dB_Query::CONDITIONS_KEY => array(array('field' => 'varname', 'value' => array('page_' . $guidforphrase . '_title', 'page_' . $guidforphrase . '_metadesc'), 'operator' => vB_dB_Query::OPERATOR_EQ), array('field' => 'fieldname', 'value' => 'pagemeta', 'operator' => vB_dB_Query::OPERATOR_EQ), array('field' => 'languageid', 'value' => array(-1, $currentlanguageid), 'operator' => vB_dB_Query::OPERATOR_NE))));
     $pagetrans = array('page_' . $guidforphrase . '_title' => array(), 'page_' . $guidforphrase . '_metadesc' => array());
     $hasdefault = array();
     $productid = false;
     foreach ($translations as $translation) {
         if (!$productid) {
             $productid = $translation['product'];
         }
         $pagetrans[$translation['varname']][$translation['languageid']] = $translation['text'];
         if ($translation['languageid'] == 0) {
             $hasdefault[$translation['varname']] = true;
         }
     }
     // Add input text to translates
     $pagetrans['page_' . $guidforphrase . '_title'][$currentlanguageid] = $input['pagetitle'];
     $pagetrans['page_' . $guidforphrase . '_metadesc'][$currentlanguageid] = $input['metadescription'];
     foreach (array_keys($pagetrans) as $varname) {
         if (empty($hasdefault[$varname]) or $currentlanguageid == vB::getDatastore()->getOption('languageid')) {
             // If the page phrase doesn't have a default one (languageid = 0) or current language is default language
             // We should update the phrase for default language (languageid = 0)
             $pagetrans[$varname][0] = $pagetrans[$varname][$currentlanguageid];
         }
     }
     if (!$productid) {
         $page = vB::getDbAssertor()->getColumn('page', 'product', array('pageid' => $pageid));
         $productid = array_pop($page);
     }
     $phraseLib->save('pagemeta', 'page_' . $guidforphrase . '_title', array('text' => $pagetrans['page_' . $guidforphrase . '_title'], 'product' => $productid, 'oldvarname' => 'page_' . $guidforphrase . '_title', 'oldfieldname' => 'global', 'skipdebug' => 1));
     $phraseLib->save('pagemeta', 'page_' . $guidforphrase . '_metadesc', array('text' => $pagetrans['page_' . $guidforphrase . '_metadesc'], 'product' => $productid, 'oldvarname' => 'page_' . $guidforphrase . '_metadesc', 'oldfieldname' => 'global', 'skipdebug' => 1));
     build_language();
     vB_Cache::instance()->event('pageChg_' . $pageid);
     $page = $this->fetchPageById($pageid, array('nodeid' => $input['nodeid'], 'userid' => $input['userid']));
     return array('success' => true, 'url' => $page['url'], 'pageid' => $pageid);
 }
Esempio n. 24
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;
}
Esempio n. 25
0
 /**
  * Delete a phrase
  * @param int $phraseid Pharse ID to be deleted
  * @return void
  */
 public function delete($phraseid)
 {
     $this->checkHasAdminPermission('canadminlanguages');
     $getvarname = vB::getDbAssertor()->getRow('phrase', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, 'phraseid' => $phraseid));
     if ($getvarname) {
         vB::getDbAssertor()->assertQuery('phrase', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_DELETE, 'varname' => $getvarname['varname'], 'fieldname' => $getvarname['fieldname']));
         require_once DIR . '/includes/adminfunctions.php';
         require_once DIR . '/includes/adminfunctions_language.php';
         build_language(-1);
     } else {
         throw new vB_Exception_Api('invalid_phrase_specified');
     }
     return $getvarname;
 }
Esempio n. 26
0
// *************************************************************************************************
if ($_REQUEST['do'] == 'remove') {
    $vbulletin->input->clean_array_gpc('r', array('minimumreputation' => TYPE_INT));
    print_form_header('adminreputation', 'kill');
    construct_hidden_code('minimumreputation', $vbulletin->GPC['minimumreputation']);
    print_table_header($vbphrase['confirm_deletion']);
    print_description_row(construct_phrase($vbphrase['are_you_sure_you_want_to_delete_the_reputation_level_x'], '<i>' . $vbulletin->GPC['minimumreputation'] . '</i>'));
    print_submit_row($vbphrase['yes'], '', 2, $vbphrase['no']);
}
// *************************************************************************************************
if ($_POST['do'] == 'kill') {
    $vbulletin->input->clean_array_gpc('p', array('minimumreputation' => TYPE_INT));
    $reputationlevel = $db->query_first("\n\t\tSELECT reputationlevelid\n\t\tFROM " . TABLE_PREFIX . "reputationlevel\n\t\tWHERE minimumreputation = " . $vbulletin->GPC['minimumreputation']);
    $db->query_write("\n\t\tDELETE FROM " . TABLE_PREFIX . "phrase\n\t\tWHERE fieldname = 'reputationlevel' AND\n\t\t\t\tvarname IN ('reputation{$reputationlevel['reputationlevelid']}')\n\t");
    require_once DIR . '/includes/adminfunctions_language.php';
    build_language();
    $db->query_write("\n\t\tDELETE FROM " . TABLE_PREFIX . "reputationlevel\n\t\tWHERE minimumreputation = " . $vbulletin->GPC['minimumreputation']);
    build_reputationids();
    define('CP_REDIRECT', 'adminreputation.php?do=modify');
    print_stop_message('deleted_reputation_level_successfully');
}
// *************************************************************************************************
if ($_POST['do'] == 'updateminimums') {
    $vbulletin->input->clean_array_gpc('p', array('reputation' => TYPE_ARRAY));
    if (is_array($vbulletin->GPC['reputation'])) {
        foreach ($vbulletin->GPC['reputation'] as $index => $value) {
            if ($found["{$value}"]) {
                print_stop_message('no_permission_duplicate_reputation');
            } else {
                $found["{$value}"] = 1;
            }
Esempio n. 27
0
 /**
  * Additional data to update after a delete call (such as denormalized values in other tables).
  *
  * @param	boolean	Do the query?
  */
 function post_delete($doquery = true)
 {
     $db =& $this->registry->db;
     // need to rebuild last post info in forums that use this prefix
     //		require_once(DIR . '/includes/functions_databuild.php');
     //		$channels = $db->query_read("
     //			SELECT nodeid
     //			FROM " . TABLE_PREFIX . "channelprefixset
     //			WHERE prefixsetid = '" . $db->escape_string($this->fetch_field('prefixsetid')) . "'
     //		");
     //		while ($channel = $db->fetch_array($channels))
     //		{
     //			build_forum_counters($channel['forumid']);
     //		}
     $db->query_write("\n\t\t\tDELETE FROM " . TABLE_PREFIX . "channelprefixset\n\t\t\tWHERE prefixsetid = '" . $db->escape_string($this->fetch_field('prefixsetid')) . "'\n\t\t");
     // delete this set's phrases
     $db->query_write("\n\t\t\tDELETE FROM " . TABLE_PREFIX . "phrase\n\t\t\tWHERE varname = '" . $db->escape_string('prefixset_' . $this->fetch_field('prefixsetid') . '_title') . "'\n\t\t\t\tAND fieldname = 'prefix'\n\t\t");
     // now find all the phrases for child prefixes to remove
     $prefix_phrases = array();
     $prefixids = array();
     $prefix_sql = $db->query_read("\n\t\t\tSELECT prefixid\n\t\t\tFROM " . TABLE_PREFIX . "prefix\n\t\t\tWHERE prefixsetid = '" . $db->escape_string($this->fetch_field('prefixsetid')) . "'\n\t\t");
     while ($prefix = $db->fetch_array($prefix_sql)) {
         $prefix_phrases[] = "'" . $db->escape_string("prefix_{$prefix['prefixid']}_title_plain") . "'";
         $prefix_phrases[] = "'" . $db->escape_string("prefix_{$prefix['prefixid']}_title_rich") . "'";
         $prefixids[] = "'" . $db->escape_string($prefix['prefixid']) . "'";
     }
     if ($prefix_phrases) {
         $db->query_write("\n\t\t\t\tDELETE FROM " . TABLE_PREFIX . "phrase\n\t\t\t\tWHERE varname IN (" . implode(',', $prefix_phrases) . ")\n\t\t\t\t\tAND fieldname = 'global'\n\t\t\t");
         $db->query_write("\n\t\t\t\tUPDATE " . TABLE_PREFIX . "node SET\n\t\t\t\t\tprefixid = ''\n\t\t\t\tWHERE prefixid IN (" . implode(',', $prefixids) . ")\n\t\t\t");
     }
     // now delete the child prefixes themselves
     $db->query_write("\n\t\t\tDELETE FROM " . TABLE_PREFIX . "prefix\n\t\t\tWHERE prefixsetid = '" . $db->escape_string($this->fetch_field('prefixsetid')) . "'\n\t\t");
     require_once DIR . '/includes/adminfunctions_language.php';
     build_language();
     require_once DIR . '/includes/adminfunctions_prefix.php';
     build_prefix_datastore();
     // Legacy Hook 'prefixsetdata_delete' Removed //
     return true;
 }
Esempio n. 28
0
function xml_import_help_topics($xml = false)
{
    global $vbulletin, $vbphrase;
    print_dots_start('<b>' . $vbphrase['importing_admin_help'] . "</b>, {$vbphrase['please_wait']}", ':', 'dspan');
    require_once DIR . '/includes/class_xml.php';
    $xmlobj = new vB_XML_Parser($xml, $GLOBALS['path']);
    if ($xmlobj->error_no == 1) {
        print_dots_stop();
        print_stop_message('no_xml_and_no_path');
    } else {
        if ($xmlobj->error_no == 2) {
            print_dots_stop();
            print_stop_message('please_ensure_x_file_is_located_at_y', 'vbulletin-adminhelp.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['helpscript']) {
        print_dots_stop();
        print_stop_message('invalid_file_specified');
    }
    $product = empty($arr['product']) ? 'vbulletin' : $arr['product'];
    $has_phrases = !empty($arr['hasphrases']);
    $arr = $arr['helpscript'];
    if ($product == 'vbulletin') {
        $product_sql = "product IN ('vbulletin', '')";
    } else {
        $product_sql = "product = '" . $vbulletin->db->escape_string($product) . "'";
    }
    $vbulletin->db->query_write("\n\t\tDELETE FROM " . TABLE_PREFIX . "adminhelp\n\t\tWHERE {$product_sql}\n\t\t\t AND volatile = 1\n\t");
    if ($has_phrases) {
        $vbulletin->db->query_write("\n\t\t\tDELETE FROM " . TABLE_PREFIX . "phrase\n\t\t\tWHERE {$product_sql}\n\t\t\t\tAND fieldname = 'cphelptext'\n\t\t\t\tAND languageid = -1\n\t\t");
    }
    // Deal with single entry
    if (!is_array($arr[0])) {
        $arr = array($arr);
    }
    foreach ($arr as $helpscript) {
        $help_sql = array();
        $phrase_sql = array();
        $help_sql_len = 0;
        $phrase_sql_len = 0;
        // Deal with single entry
        if (!is_array($helpscript['helptopic'][0])) {
            $helpscript['helptopic'] = array($helpscript['helptopic']);
        }
        foreach ($helpscript['helptopic'] as $topic) {
            $help_sql[] = "\n\t\t\t\t('" . $vbulletin->db->escape_string($helpscript['name']) . "',\n\t\t\t\t'" . $vbulletin->db->escape_string($topic['act']) . "',\n\t\t\t\t'" . $vbulletin->db->escape_string($topic['opt']) . "',\n\t\t\t\t" . intval($topic['disp']) . ",\n\t\t\t\t1,\n\t\t\t\t'" . $vbulletin->db->escape_string($product) . "')\n\t\t\t";
            $help_sql_len += strlen(end($help_sql));
            if ($has_phrases) {
                $phrase_name = fetch_help_phrase_short_name(array('script' => $helpscript['name'], 'action' => $topic['act'], 'optionname' => $topic['opt']));
                if (isset($topic['text']['value'])) {
                    $phrase_sql[] = "\n\t\t\t\t\t\t(-1,\n\t\t\t\t\t\t'cphelptext',\n\t\t\t\t\t\t'{$phrase_name}_text',\n\t\t\t\t\t\t'" . $vbulletin->db->escape_string($topic['text']['value']) . "',\n\t\t\t\t\t\t'" . $vbulletin->db->escape_string($product) . "',\n\t\t\t\t\t\t'" . $vbulletin->db->escape_string($topic['text']['username']) . "',\n\t\t\t\t\t\t" . intval($topic['text']['date']) . ",\n\t\t\t\t\t\t'" . $vbulletin->db->escape_string($topic['text']['version']) . "')\n\t\t\t\t\t";
                    $phrase_sql_len += strlen(end($phrase_sql));
                }
                if (isset($topic['title']['value'])) {
                    $phrase_sql[] = "\n\t\t\t\t\t\t(-1,\n\t\t\t\t\t\t'cphelptext',\n\t\t\t\t\t\t'{$phrase_name}_title',\n\t\t\t\t\t\t'" . $vbulletin->db->escape_string($topic['title']['value']) . "',\n\t\t\t\t\t\t'" . $vbulletin->db->escape_string($product) . "',\n\t\t\t\t\t\t'" . $vbulletin->db->escape_string($topic['title']['username']) . "',\n\t\t\t\t\t\t" . intval($topic['title']['date']) . ",\n\t\t\t\t\t\t'" . $vbulletin->db->escape_string($topic['title']['version']) . "')\n\t\t\t\t\t";
                    $phrase_sql_len += strlen(end($phrase_sql));
                }
            }
            if ($phrase_sql_len > 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", $phrase_sql));
                $phrase_sql = array();
                $phrase_sql_len = 0;
            }
            if ($help_sql_len > 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 . "adminhelp\n\t\t\t\t\t\t(script, action, optionname, displayorder, volatile, product)\n\t\t\t\t\tVALUES\n\t\t\t\t\t\t" . implode(",\n\t", $help_sql));
                $help_sql = array();
                $help_sql_len = 0;
            }
        }
        if ($help_sql) {
            /*insert query*/
            $vbulletin->db->query_write("\n\t\t\t\tREPLACE INTO " . TABLE_PREFIX . "adminhelp\n\t\t\t\t\t(script, action, optionname, displayorder, volatile, product)\n\t\t\t\tVALUES\n\t\t\t\t\t" . implode(",\n\t", $help_sql));
        }
        if ($phrase_sql) {
            /*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", $phrase_sql));
        }
    }
    // stop the 'dots' counter feedback
    print_dots_stop();
    require_once DIR . '/includes/adminfunctions_language.php';
    build_language();
}
 /**
  * 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;
 }