LanguageCacheBuilder::getInstance()->reset();
}
- /**
- * Searches in language items.
- *
- * @param string $search search query
- * @param string $replace
- * @param integer $languageID
- * @param integer $useRegex
- * @param integer $searchVariableName
- * @return array
- */
- public static function search($search, $replace = null, $languageID = null, $useRegex = 0, $searchVariableName = 0) {
- $results = array();
-
- // build condition
- $conditionBuilder = new PreparedStatementConditionBuilder();
-
- // search field
- $statementParameters = array();
- if ($searchVariableName) $searchCondition = 'languageItem ';
- else $searchCondition = 'languageItemValue ';
-
- // regex
- if ($useRegex) {
- $searchCondition .= "REGEXP ?";
- $statementParameters[] = $search;
- }
- else {
- $searchCondition .= "LIKE ?";
- $statementParameters[] = '%'.$search.'%';
- }
-
- if (!$searchVariableName) {
- $searchCondition .= ' OR languageCustomItemValue ';
- // regex
- if ($useRegex) {
- $searchCondition .= "REGEXP ?";
- $statementParameters[] = $search;
- }
- else {
- $searchCondition .= "LIKE ?";
- $statementParameters[] = '%'.$search.'%';
- }
- }
-
- $conditionBuilder->add($searchCondition, $statementParameters);
- if ($languageID !== null) $conditionBuilder->add("languageID = ?", array($languageID));
-
- // search
- $updatedItems = array();
- $sql = "SELECT *
- FROM wcf".WCF_N."_language_item
- ".$conditionBuilder;
- $statement = WCF::getDB()->prepareStatement($sql);
- $statement->execute($conditionBuilder->getParameters());
-
- while ($row = $statement->fetchArray()) {
- if ($replace !== null) {
- // search and replace
- $matches = 0;
- if ($useRegex) {
- $newValue = preg_replace('~'.$search.'~s', $replace, ($row['languageCustomItemValue'] ?: $row['languageItemValue']), -1, $matches);
- }
- else {
- $newValue = StringUtil::replaceIgnoreCase($search, $replace, ($row['languageCustomItemValue'] ?: $row['languageItemValue']), $matches);
- }
-
- if ($matches > 0) {
- // update value
- if (!isset($updatedItems[$row['languageID']])) $updatedItems[$row['languageID']] = array();
- if (!isset($updatedItems[$row['languageID']][$row['languageCategoryID']])) $updatedItems[$row['languageID']][$row['languageCategoryID']] = array();
- $updatedItems[$row['languageID']][$row['languageCategoryID']][$row['languageItem']] = $newValue;
-
- // save matches
- $row['matches'] = $matches;
- }
- }
-
- $results[] = $row;
- }
-
- // save updates
- if (!empty($updatedItems)) {
- foreach ($updatedItems as $languageID => $categories) {
- $language = new LanguageEditor($languageID);
-
- foreach ($categories as $categoryID => $items) {
- $useCustom = array();
- foreach (array_keys($items) as $item) {
- $useCustom[$item] = 1;
- }
-
- $category = new LanguageCategory($categoryID);
- $language->updateItems($items, $category, PACKAGE_ID, $useCustom);
- }
- }
- }
-
- return $results;
- }
-
/**
* Enables the multilingualism feature for given languages.
*
use wcf\data\package\PackageCache;
use wcf\data\DatabaseObject;
use wcf\system\application\ApplicationHandler;
-use wcf\system\database\util\PreparedStatementConditionBuilder;
use wcf\system\WCF;
use wcf\util\FileUtil;
-use wcf\util\StringUtil;
/**
* Represents a template.
public function getSource() {
return @file_get_contents($this->getPath());
}
-
- /**
- * Searches in templates.
- *
- * @param string $search search query
- * @param string $replace
- * @param array $templateIDs
- * @param integer $invertTemplates
- * @param integer $useRegex
- * @param integer $caseSensitive
- * @param integer $invertSearch
- * @return array
- */
- public static function search($search, $replace = null, $templateIDs = null, $invertTemplates = 0, $useRegex = 0, $caseSensitive = 0, $invertSearch = 0) {
- // get available template ids
- $results = array();
- $availableTemplateIDs = array();
- $sql = "SELECT templateName, templateID, templateGroupID, packageID
- FROM wcf".WCF_N."_template
- ".($replace !== null ? "WHERE templateGroupID <> 0" : "");
- $statement = WCF::getDB()->prepareStatement($sql);
- $statement->execute();
- while ($row = $statement->fetchArray()) {
- if (!isset($availableTemplateIDs[$row['templateName'].'-'.$row['templateGroupID']]) || PACKAGE_ID == $row['packageID']) {
- $availableTemplateIDs[$row['templateName'].'-'.$row['templateGroupID']] = $row['templateID'];
- }
- }
-
- // get templates
- if (empty($availableTemplateIDs)) return $results;
-
- $conditions = new PreparedStatementConditionBuilder();
- $conditions->add("template.templateID IN (?)", array($availableTemplateIDs));
- if ($templateIDs !== null) $conditions->add("template.templateID ".($invertTemplates ? "NOT " : "")." IN (?)", array($templateIDs));
-
- $sql = "SELECT template.*, group.templateGroupFolderName, package.packageDir
- FROM wcf".WCF_N."_template template
- LEFT JOIN wcf".WCF_N."_template_group group
- ON (group.templateGroupID = template.templateGroupID)
- LEFT JOIN wcf".WCF_N."_package package
- ON (package.packageID = template.packageID)
- ".$conditions."
- ORDER BY templateName ASC";
- $statement = WCF::getDB()->prepareStatement($sql);
- $statement->execute($conditions->getParameters());
- unset($availableTemplateIDs);
- while ($row = $statement->fetchArray()) {
- $template = new TemplateEditor(null, $row);
- if ($replace === null) {
- // search
- if ($useRegex) $matches = (intval(preg_match('/'.$search.'/s'.(!$caseSensitive ? 'i' : ''), $template->getSource())) !== 0);
- else {
- if ($caseSensitive) $matches = (mb_strpos($template->getSource(), $search) !== false);
- else $matches = (mb_strripos($template->getSource(), $search) !== false);
- }
-
- if (($matches && !$invertSearch) || (!$matches && $invertSearch)) {
- $results[] = $row;
- }
- }
- else {
- // search and replace
- $matches = 0;
- if ($useRegex) {
- $newSource = preg_replace('/'.$search.'/s'.(!$caseSensitive ? 'i' : ''), $replace, $template->getSource(), -1, $matches);
- }
- else {
- if ($caseSensitive) $newSource = str_replace($search, $replace, $template->getSource(), $matches);
- else $newSource = StringUtil::replaceIgnoreCase($search, $replace, $template->getSource(), $matches);
- }
-
- if ($matches > 0) {
- $template->setSource($newSource);
- $row['matches'] = $matches;
- $results[] = $row;
- }
- }
- }
-
- return $results;
- }
}