Exemplo n.º 1
0
 /**
  * Fetch phrases
  *
  * @param array $phrases An array of phrase ID to be fetched
  * @param int $languageid Language ID. If not set, it will use current session's languageid
  *
  * @return array Phrase' texts
  */
 public static function fetchStatic($phrases, $languageid = NULL)
 {
     if (empty($phrases)) {
         return array();
     }
     $languageIds = array($languageid, 0, -1);
     $languages = vB::getDatastore()->getValue('languagecache');
     $fastDS = vB_FastDS::instance();
     //First try from fastds
     if ($fastDS and $languageid > -1) {
         $cached = $fastDS->getPhrases((array) $phrases, $languageid);
     } else {
         if ($fastDS) {
             $cached = $fastDS->getPhrases((array) $phrases, -1);
         }
     }
     $return = array();
     if (!empty($cached)) {
         foreach ($phrases as $index => $phraseKey) {
             if (!empty($cached[$phraseKey])) {
                 unset($phrases[$index]);
                 $return[$phraseKey] = $cached[$phraseKey];
             }
         }
     }
     if (!empty($phrases)) {
         $phrasesdata = vB::getDbAssertor()->assertQuery('fetchPhraseList', array('varname' => $phrases, 'languageid' => $languageIds));
         $realphrases = array();
         foreach ($phrasesdata as $phrase) {
             // User-selected language (>=1) overwrites custom phrase (0), which overwrites master language phrase (-1)
             if (empty($realphrases[$phrase['varname']]) or $realphrases[$phrase['varname']]['languageid'] < $phrase['languageid']) {
                 $realphrases[$phrase['varname']] = $phrase;
                 if (strpos($phrase['text'], '{1}') !== false) {
                     $search = array('/%/s', '/\\{([0-9]+)\\}/siU');
                     $replace = array('%%', '%\\1$s');
                     $thisPhrase = preg_replace($search, $replace, $phrase['text']);
                 } else {
                     $thisPhrase = $phrase['text'];
                 }
                 // Conversion to UTF-8 is done in sendAsJson(), so if we do it here, we'll end up double-encoding and potentially corrupting
                 // multibyte characters.
                 /*
                 if (!empty($languages[$phrase['languageid']])
                 	AND !empty($languages[$phrase['languageid']]['charset'])
                 	AND ($languages[$phrase['languageid']]['charset'] !== 'UTF-8'))
                 {
                 	$thisPhrase = vB5_String::toCharset($phrase['text'], $languages[$phrase['languageid']]['charset'], 'UTF-8');
                 }
                 */
                 $return[$phrase['varname']] = $thisPhrase;
             }
         }
     }
     return $return;
 }
Exemplo n.º 2
0
 /**
  *	Rewrites the file cache for the templates for all styles.
  */
 public function saveAllTemplatesToFile()
 {
     $template_path = vB::getDatastore()->getOption('template_cache_path');
     $db = vB::getDBAssertor();
     $result = $db->select('template', array(), false, array('templateid', 'template', 'textonly'));
     foreach ($result as $template) {
         $this->saveTemplateToFileSystem($template['templateid'], $template['template'], $template_path, $template['textonly']);
     }
     $fastDs = vB_FastDS::instance();
     //We want to force a fastDS rebuild, but we can't just call rebuild. There may be dual web servers,
     // and calling rebuild only rebuilds one of them.
     $options = vB::getDatastore()->getValue('miscoptions');
     $options['tmtdate'] = vB::getRequest()->getTimeNow();
     vB::getDatastore()->build('miscoptions', serialize($options), 1);
 }
Exemplo n.º 3
0
 /**
  * Fetches a rendered phrase.
  * If the phrase is not in the local phrase cache, then the phrasekey cache is
  * loaded and purged.
  *
  * @param string $phrasekey					- The phrasekey of the phrase
  * @param array mixed						- Array of parameters to parse into the phrase
  * @return string							- The translated phrase
  */
 public static function fetchSinglePhrase($phrasekey, $parameters = array())
 {
     if (!isset(self::$languageid)) {
         self::setLanguage();
     }
     $fastDS = vB_FastDS::instance();
     if ($fastDS) {
         $phrase = $fastDS->getPhrases($phrasekey, self::$languageid);
     }
     if (empty($phrase)) {
         //Since we're sorted by languageid descending- if there's a phrase from the requested languageid we'll get it. If not, we'll get the default language.
         $phrase = vB::getDbAssertor()->getRow('phrase', array('varname' => $phrasekey, 'languageid' => array(-1, self::$languageid)), array('field' => 'languageid', 'direction' => vB_dB_Query::SORT_DESC));
         $phrase = $phrase['text'];
     }
     return self::replaceVars($phrase, (array) $parameters);
 }
Exemplo n.º 4
0
 /** reBuilds the fastDS data. This is called if the cached value is lost, or after upgrade.
  *
  *	@param	integer		the maximum space allowed for caching this data.
  *
  *	@return	integer		estimate of the space used. Note that we can't be exact.
  **/
 protected function buildTemplates($maxSize)
 {
     self::$building = true;
     $styleid = vB::getDatastore()->getOption('styleid');
     // Still don't have a language, fall back to master language
     if (!$styleid) {
         $styleid = -1;
     }
     $this->styleid = $styleid;
     //We sort by languageid, descending. So for a given template, the first
     // record we get is what we want.
     $templates = vB::getDbAssertor()->assertQuery('template', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, 'styleid' => array($styleid, 0, -1)), array('field' => array('styleid'), 'direction' => array(vB_dB_Query::SORT_DESC)));
     $size = 0;
     $this->templatesCached = true;
     $used = array();
     foreach ($templates as $template) {
         if (isset($used[$template['title']])) {
             continue;
         }
         $used[$template['title']] = 1;
         if ($size + strlen($template['template']) > $maxSize) {
             //We weren't able to cache.  Let's un-set whatever we have.
             foreach ($used as $template => $value) {
                 $this->clearValue('tm' . $template);
             }
             $this->templatesCached = false;
             self::$building = false;
             return false;
         }
         $size += strlen($template['template']) + strlen($template['title']);
         $this->setTemplate($template['title'], $template['template']);
     }
     $this->tmRebuilt = vB::getRequest()->getTimeNow();
     self::$building = false;
     return $size;
 }
Exemplo n.º 5
0
 /**
  * Reads settings from the settings then saves the values to the datastore
  *
  * After reading the contents of the setting table, the function will rebuild
  * the $vbulletin->options array, then serialize the array and save that serialized
  * array into the 'options' entry of the datastore in the database
  *
  * Extracted from adminfunctions.php
  *
  * @return	array	The $vbulletin->options array
  */
 public function build_options()
 {
     $options = array();
     $result = $this->db_assertor->assertQuery('setting', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT));
     foreach ($result as $setting) {
         $options["{$setting['varname']}"] = $this->validate_setting_value($setting['value'], $setting['datatype'], true, false);
     }
     if (isset($options['cookiepath']) and substr($options['cookiepath'], -1, 1) != '/') {
         $options['cookiepath'] .= '/';
         $this->db_assertor->assertQuery('setting', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_UPDATE, 'varname' => 'cookiepath', 'value' => $options['cookiepath']));
     }
     $this->build('options', serialize($options), 1);
     $this->registered['options'] = $options;
     // Build public options
     $publicoptions = array();
     foreach ($result as $setting) {
         if ($setting['ispublic']) {
             $publicoptions["{$setting['varname']}"] = $options["{$setting['varname']}"];
         }
     }
     $this->build('publicoptions', serialize($publicoptions), 1);
     $this->registered['publicoptions'] = $publicoptions;
     vB_Api::instanceInternal('options')->setOptionsDate();
     //We want to force a fastDS rebuild, but we can't just call rebuild. There may be dual web servers,
     // and calling rebuild only rebuilds one of them.
     if ($fastDS = vB_FastDS::instance()) {
         $fastDS->setDsChanged('options');
     }
     return $options;
 }
/**
* Reads XML style file and imports data from it into the database
*
* @param	string	$xml		XML data
* @param	integer	$styleid	Style ID
* @param	integer	$parentid	Parent style ID
* @param	string	$title		New style title
* @param	boolean	$anyversion	Allow vBulletin version mismatch
* @param	integer	$displayorder	Display order for new style
* @param	boolean	$userselct	Allow user selection of new style
* @param  	int|null	$startat	Starting template group index for this run of importing templates (0 based). Null means all templates (single run)
* @param  	int|null	$perpage	Number of templates to import at a time
* @param	boolean	$scilent		Run silently (do not echo)
* @param	array|boolean	$parsed_xml	Parsed array of XML data. If provided the function will ignore $xml and use the provided, already parsed data.
*
* @return	array	Array of information about the imported style
*/
function xml_import_style($xml = false, $styleid = -1, $parentid = -1, $title = '', $anyversion = false, $displayorder = 1, $userselect = true, $startat = null, $perpage = null, $scilent = false, $parsed_xml = false)
{
    // $GLOBALS['path'] needs to be passed into this function or reference $vbulletin->GPC['path']
    //checking the root node name
    if (!empty($xml)) {
        $r = new XMLReader();
        if ($r->xml($xml)) {
            if ($r->read()) {
                $node_name = $r->name;
                if ($node_name != 'style') {
                    print_stop_message2('file_uploaded_not_in_right_format_error');
                }
            } else {
                //can not read the document
                print_stop_message2('file_uploaded_unreadable');
            }
        } else {
            //can not open the xml
            print_stop_message2('file_uploaded_unreadable');
        }
    }
    global $vbulletin;
    if (!$scilent) {
        $vbphrase = vB_Api::instanceInternal('phrase')->fetch(array('importing_style', 'please_wait', 'creating_a_new_style_called_x'));
        print_dots_start('<b>' . $vbphrase['importing_style'] . "</b>, {$vbphrase['please_wait']}", ':', 'dspan');
    }
    require_once DIR . '/includes/class_xml.php';
    if (empty($parsed_xml)) {
        //where is this used?  I hate having this random global value in the middle of this function
        $xmlobj = new vB_XML_Parser($xml, $vbulletin->GPC['path']);
        if ($xmlobj->error_no() == 1) {
            if ($scilent) {
                throw new vB_Exception_AdminStopMessage('no_xml_and_no_path');
            }
            print_dots_stop();
            print_stop_message2('no_xml_and_no_path');
        } else {
            if ($xmlobj->error_no() == 2) {
                if ($scilent) {
                    throw new vB_Exception_AdminStopMessage(array('please_ensure_x_file_is_located_at_y', 'vbulletin-style.xml', $vbulletin->GPC['path']));
                }
                print_dots_stop();
                print_stop_message2(array('please_ensure_x_file_is_located_at_y', 'vbulletin-style.xml', $vbulletin->GPC['path']));
            }
        }
        if (!($parsed_xml = $xmlobj->parse())) {
            if ($scilent) {
                throw new vB_Exception_AdminStopMessage(array('xml_error_x_at_line_y', $xmlobj->error_string(), $xmlobj->error_line()));
            }
            print_dots_stop();
            print_stop_message2(array('xml_error_x_at_line_y', $xmlobj->error_string(), $xmlobj->error_line()));
        }
    }
    $version = $parsed_xml['vbversion'];
    $master = $parsed_xml['type'] == 'master' ? 1 : 0;
    $title = empty($title) ? $parsed_xml['name'] : $title;
    $product = empty($parsed_xml['product']) ? 'vbulletin' : $parsed_xml['product'];
    $one_pass = (is_null($startat) and is_null($perpage));
    if (!$one_pass and (!is_numeric($startat) or !is_numeric($perpage) or $perpage <= 0 or $startat < 0)) {
        if ($scilent) {
            throw new vB_Exception_AdminStopMessage('');
        }
        print_dots_stop();
        print_stop_message2('');
    }
    $outputtext = '';
    if ($one_pass or $startat == 0) {
        require_once DIR . '/includes/adminfunctions.php';
        // version check
        $full_product_info = fetch_product_list(true);
        $product_info = $full_product_info["{$product}"];
        if ($version != $product_info['version'] and !$anyversion and !$master) {
            if ($scilent) {
                throw new vB_Exception_AdminStopMessage(array('upload_file_created_with_different_version', $product_info['version'], $version));
            }
            print_dots_stop();
            print_stop_message2(array('upload_file_created_with_different_version', $product_info['version'], $version));
        }
        //Initialize the style -- either init the master, create a new style, or verify the style to overwrite.
        if ($master) {
            $import_data = @unserialize(fetch_adminutil_text('master_style_import'));
            if (!empty($import_data) and TIMENOW - $import_data['last_import'] <= 30) {
                if ($scilent) {
                    throw new vB_Exception_AdminStopMessage(array('must_wait_x_seconds_master_style_import', vb_number_format($import_data['last_import'] + 30 - TIMENOW)));
                }
                print_dots_stop();
                print_stop_message2(array('must_wait_x_seconds_master_style_import', vb_number_format($import_data['last_import'] + 30 - TIMENOW)));
            }
            // overwrite master style
            //			if  ($printInfo AND (VB_AREA != 'Upgrade' AND VB_AREA != 'Install'))
            //			{
            //				echo "<h3>$vbphrase[master_style]</h3>\n<p>$vbphrase[please_wait]</p>";
            //				vbflush();
            //			}
            $products = array($product);
            if ($product == 'vbulletin') {
                $products[] = '';
            }
            vB::getDbAssertor()->assertQuery('vBForum:deleteProductTemplates', array('products' => $products));
            vB::getDbAssertor()->assertQuery('vBForum:updateProductTemplates', array('products' => $products));
            $styleid = -1;
        } else {
            if ($styleid == -1) {
                // creating a new style
                if (vB::getDbAssertor()->getRow('style', array('title' => $title))) {
                    if ($scilent) {
                        throw new vB_Exception_AdminStopMessage(array('style_already_exists', $title));
                    }
                    print_dots_stop();
                    print_stop_message2(array('style_already_exists', $title));
                } else {
                    if (!$scilent) {
                        if (VB_AREA != 'Upgrade' or VB_AREA != 'Install') {
                            $outputtext = construct_phrase($vbphrase['creating_a_new_style_called_x'], $title) . "<br>\n";
                        } else {
                            // this isn't compatible with the ajax installer
                            echo "<h3><b>" . construct_phrase($vbphrase['creating_a_new_style_called_x'], $title) . "</b></h3>\n<p>{$vbphrase['please_wait']}</p>";
                            vbflush();
                        }
                    }
                    /*insert query*/
                    $styleid = vB::getDbAssertor()->insert('style', array('title' => $title, 'parentid' => $parentid, 'displayorder' => $displayorder, 'userselect' => $userselect ? 1 : 0));
                    if (is_array($styleid)) {
                        $styleid = array_pop($styleid);
                    }
                }
            } else {
                // overwriting an existing style
                if (vB::getDbAssertor()->getRow('style', array('styleid' => $styleid))) {
                    //					if  ($printInfo AND (VB_AREA != 'Upgrade' AND VB_AREA != 'Install'))
                    //					{
                    //						echo "<h3><b>" . construct_phrase($vbphrase['overwriting_style_x'], $getstyle['title']) . "</b></h3>\n<p>$vbphrase[please_wait]</p>";
                    //						vbflush();
                    //					}
                } else {
                    if ($scilent) {
                        throw new vB_Exception_AdminStopMessage('cant_overwrite_non_existent_style');
                    }
                    print_dots_stop();
                    print_stop_message2('cant_overwrite_non_existent_style');
                }
            }
        }
    } else {
        //We should never get styleid = -1 unless $master is true;
        if ($styleid == -1 and !$master) {
            $stylerec = vB::getDbAssertor()->getRow('style', array('title' => $title));
            if ($stylerec and intval($stylerec['styleid'])) {
                $styleid = $stylerec['styleid'];
            } else {
                if ($scilent) {
                    throw new vB_Exception_AdminStopMessage(array('incorrect_style_setting', $title));
                }
                print_dots_stop();
                print_stop_message2(array('incorrect_style_setting', $title));
            }
        }
    }
    //load the templates
    if ($arr = $parsed_xml['templategroup']) {
        if (empty($arr[0])) {
            $arr = array($arr);
        }
        $templates_done = (is_numeric($startat) and count($arr) <= $startat);
        if ($one_pass or !$templates_done) {
            if (!$one_pass) {
                $arr = array_slice($arr, $startat, $perpage);
            }
            $outputtext .= xml_import_template_groups($styleid, $product, $arr, !$one_pass);
        }
    } else {
        $templates_done = true;
    }
    //note that templates may actually be done at this point, but templates_done is
    //only true if templates were completed in a prior step. If we are doing a multi-pass
    //process, we don't want to install stylevars in the same pass.  We aren't really done
    //until we hit a pass where the templates are done before processing.
    $done = ($one_pass or $templates_done);
    if ($done) {
        //load stylevars and definitions
        // re-import any stylevar definitions
        if ($master and !empty($parsed_xml['stylevardfns']['stylevargroup'])) {
            xml_import_stylevar_definitions($parsed_xml['stylevardfns'], 'vbulletin');
        }
        //if the tag is present but empty we'll end up with a string with whitespace which
        //is a non "empty" value.
        if (!empty($parsed_xml['stylevars']) and is_array($parsed_xml['stylevars'])) {
            xml_import_stylevars($parsed_xml['stylevars'], $styleid);
        }
        if ($master) {
            xml_import_restore_ad_templates();
            build_adminutil_text('master_style_import', serialize(array('last_import' => TIMENOW)));
        }
        if (!$scilent) {
            print_dots_stop();
        }
    }
    $fastDs = vB_FastDS::instance();
    //We want to force a fastDS rebuild, but we can't just call rebuild. There may be dual web servers,
    // and calling rebuild only rebuilds one of them.
    $options = vB::getDatastore()->getValue('miscoptions');
    $options['tmtdate'] = vB::getRequest()->getTimeNow();
    vB::getDatastore()->build('miscoptions', serialize($options), 1);
    return array('version' => $version, 'master' => $master, 'title' => $title, 'product' => $product, 'done' => $done, 'overwritestyleid' => $styleid, 'output' => $outputtext);
}