/** * {@inheritdoc} */ public function next() { $buffer = ''; while (1) { parent::next(); if ($this->valid() === false) { return; } $buffer .= $this->current . "\n"; if ($string = $this->parser->parse($buffer)) { $this->current = $string[0]; $this->key = $this->current['name']; return; } } }
/** * Installs localisation strings from a Textpack. * * Created strings get a well-known static modifcation date set in the past. * This is done to avoid tampering with lastmod dates used for RPC server * interactions, caching and update checks. * * @param string $textpack The Textpack to install * @param bool $add_new_langs If TRUE, installs strings for any included language * @return int Number of installed strings * @package L10n */ function install_textpack($textpack, $add_new_langs = false) { $parser = new Textpattern_Textpack_Parser(); $parser->setLanguage(get_pref('language', 'en-gb')); $textpack = $parser->parse($textpack); if (!$textpack) { return 0; } $installed_langs = safe_column('lang', 'txp_lang', "1 = 1 group by lang"); $done = 0; foreach ($textpack as $translation) { extract($translation); if (!$add_new_langs && !in_array($lang, $installed_langs)) { continue; } $where = "lang = '" . doSlash($lang) . "' and name = '" . doSlash($name) . "'"; if (safe_count('txp_lang', $where)) { $r = safe_update('txp_lang', "lastmod = '2005-08-14',\n data = '" . doSlash($data) . "',\n event = '" . doSlash($event) . "',\n owner = '" . doSlash($owner) . "'", $where); } else { $r = safe_insert('txp_lang', "lastmod = '2005-08-14',\n data = '" . doSlash($data) . "',\n event = '" . doSlash($event) . "',\n owner = '" . doSlash($owner) . "',\n lang = '" . doSlash($lang) . "',\n name = '" . doSlash($name) . "'"); } if ($r) { $done++; } } return $done; }