/***************************************************************************
* Dolphin Smart Community Builder
* -----------------
* begin : Mon Mar 23 2006
* copyright : (C) 2006 BoonEx Group
* website : http://www.boonex.com/
* This file is part of Dolphin - Smart Community Builder
*
* Dolphin is free software. This work is licensed under a Creative Commons Attribution 3.0 License.
* http://creativecommons.org/licenses/by/3.0/
*
* Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the Creative Commons Attribution 3.0 License for more details.
* You should have received a copy of the Creative Commons Attribution 3.0 License along with Dolphin,
* see license.txt file; if not, write to marketing@boonex.com
***************************************************************************/
require_once( '../inc/header.inc.php' );
require_once( BX_DIRECTORY_PATH_INC . 'design.inc.php' );
require_once( BX_DIRECTORY_PATH_INC . 'admin_design.inc.php' );
require_once( BX_DIRECTORY_PATH_INC . 'languages.inc.php' );
require_once( BX_DIRECTORY_PATH_INC . 'utils.inc.php' );
// DECLARATIONS
define('SEARCH_COMBINE_WORDS_AS_AND', 0);
define('SEARCH_COMBINE_WORDS_AS_OR', 1);
define('SEARCH_COMBINE_WORDS_AS_EXACT', 2);
function messageTemplate($message)
{
ob_start();
?>
= $message ?>
return ob_get_clean();
}
/**
* Validates an array, moving all integer values to keys.
*
* @param array $array
* @return array( 0 => true) if the original array contained non-integers
* array( int_key => true) if the original array was OK
*/
function validateListArray($array)
{
if(is_array($array)) {
$tmp = array();
foreach ($array as $value) {
$iVal = (int)$value;
if($iVal != $value) return array(0 => true);
$tmp[$iVal] = true;
}
$array = $tmp;
}
return count($array) <= 0 || isset($array[0]) ? array(0 => true) : $array;
}
function findLangStrings(
$searchText,
$groupWords = SEARCH_COMBINE_WORDS_AS_EXACT,
$searchInKeys = true,
$searchInStrings = true,
$searchInParams = true,
$arrCategoryIDs = null,
$arrLanguageIDs = null
) {
function sqlLikeClause($fieldName, $arrWords, $groupWords) {
if (!is_array($arrWords) || strlen($fieldName) <= 0) return '';
switch ($groupWords) {
case SEARCH_COMBINE_WORDS_AS_AND: $sql = implode("%' AND $fieldName LIKE '%", $arrWords);
break;
case SEARCH_COMBINE_WORDS_AS_OR: $sql = implode("%' OR $fieldName LIKE '%", $arrWords);
break;
default: $sql = implode(' ', $arrWords);
}
$sql = "($fieldName LIKE '%$sql%')";
return $sql;
}
function sqlInClause($fieldName, $arrIDs) {
$sql = '';
$sqlValid = false;
if(is_array($arrIDs))
{
$sql = "($fieldName IN(";
foreach ($arrIDs as $ID => $val)
{
$ID = (int)$ID;
if($ID <= 0) continue;
$sqlValid = true;
$sql .= $ID.',';
}
$sql = trim($sql,',');
$sql .= '))';
}
return $sqlValid ? $sql : '';
}
function implodeNonEmpty($strGlue, $arr) {
foreach ($arr as $key => $val)
if (strlen($val) <= 0) unset($arr[$key]);
return implode($strGlue, $arr);
}
if ( strlen($searchText) > 0 ) {
$searchText = addslashes($searchText);
$likeWildcards = array ('%', '_');
$likeWildcardsEscaped = array('\%', '\_');
$searchText = str_replace($likeWildcards, $likeWildcardsEscaped, $searchText);
$arrWords = preg_split("/\s+/", $searchText, -1, PREG_SPLIT_NO_EMPTY);
foreach( $arrWords as $key => $val )
$arrWords[$key] = strtoupper( $val );
$sqlSearchInKeys = $searchInKeys ? sqlLikeClause('UPPER(`LocalizationKeys`.`Key`)', $arrWords, $groupWords) : '';
$sqlSearchInStrings = $searchInStrings ? sqlLikeClause('UPPER(`LocalizationStrings`.`String`)', $arrWords, $groupWords) : '';
$sqlSearchInParams = $searchInParams ? sqlLikeClause('UPPER(`LocalizationStringParams`.`Description`)', $arrWords, $groupWords) : '';
$sqlSearchClause = implodeNonEmpty(' OR ', array($sqlSearchInKeys, $sqlSearchInStrings, $sqlSearchInParams));
$sqlSearchClause = "($sqlSearchClause)";
} else
$sqlSearchClause = '';
$sqlSearchInCategories = sqlInClause('`LocalizationCategories`.`ID`', $arrCategoryIDs);
$sqlSearchInLanguages = sqlInClause('`LocalizationLanguages`.`ID`', $arrLanguageIDs);
$sqlWhereClause = implodeNonEmpty(' AND ', array($sqlSearchClause, $sqlSearchInCategories, $sqlSearchInLanguages));
if ( strlen($sqlWhereClause) )
$sqlWhereClause = "WHERE $sqlWhereClause ";
else
$sqlWhereClause = '';
$sql = "
SELECT DISTINCT
`LocalizationStrings`.`IDKey` AS `IDKey`,
`LocalizationStrings`.`IDLanguage` AS `IDLanguage`,
`LocalizationKeys`.`Key` AS `Key`,
`LocalizationStrings`.`String` AS `String`,
`LocalizationLanguages`.`Title` AS `Language`,
`LocalizationCategories`.`Name` AS `Category`
FROM `LocalizationStringParams`
RIGHT JOIN `LocalizationKeys` ON
(`LocalizationStringParams`.`IDKey` = `LocalizationKeys`.`ID`)
LEFT JOIN `LocalizationStrings` ON
(`LocalizationStrings`.`IDKey` = `LocalizationKeys`.`ID`)
LEFT JOIN `LocalizationCategories` ON
(`LocalizationKeys`.`IDCategory` = `LocalizationCategories`.`ID`)
LEFT JOIN `LocalizationLanguages` ON
(`LocalizationStrings`.`IDLanguage` = `LocalizationLanguages`.`ID`)
$sqlWhereClause
ORDER BY
`Language`, `Category`, `Key`";
$resSearchResult = db_res($sql);
return $resSearchResult;
}
function searchBlock() {
global $searchString,
$searchCombineWordsAs,
$searchShowAdvancedSettings,
$searchInKeys,
$searchInStrings,
$searchInParams,
$searchCategories,
$searchLanguages;
ob_start();
?>
return panelSection("Search for strings", ob_get_clean() );
}
function addLangKeyForm() {
function addLangKey()
{
$newKeyName = process_db_input($_POST['NewKeyName']);
$newCategoryName = process_db_input($_POST['NewCategoryName']);
$categoryID = (int)$_POST['NewKeyCategory'];
$newStringParams = $_POST['NewStringParameters'];
$langStrings = $_POST['LangStrings'];
if (!is_array($langStrings) || count($langStrings) < 1) return 'Error: wrong form data.';
foreach ($langStrings as $key => $value)
$langStrings[$key] = process_db_input($value);
if ( strlen($newKeyName) <= 0 ) return 'Error: Key name is not specified.';
if ( strlen($newCategoryName) > 0 )
{
db_res("INSERT INTO `LocalizationCategories` (`Name`) VALUES ('$newCategoryName')");
$categoryID = mysql_insert_id();
if ( !$categoryID )
return 'Error: Could not create a new category.';
}
else
{
$cnt = db_res('SELECT COUNT(*) FROM `LocalizationCategories` WHERE `ID`='.$categoryID);
$cnt = mysql_fetch_row($cnt);
if ( $cnt[0] <= 0 ) return 'Error: Wrong category specified.';
}
db_res("INSERT INTO `LocalizationKeys` (`IDCategory`, `Key`) VALUES ($categoryID, '$newKeyName')", 0);
$newKeyID = mysql_insert_id();
if ( $newKeyID <= 0 ) return 'Error: Could not insert a new language key.';
// parse string params
$arrParams = array();
preg_match_all('/([0-9]+) - (\S+[^\\n\\r]*)/', $newStringParams, $arrParams);
foreach ($arrParams[1] as $key => $paramID)
{
$paramID = (int)$paramID;
$paramDescription = $arrParams[2][$key];
$paramDescription = process_db_input($paramDescription);
db_res("
INSERT INTO `LocalizationStringParams`
(`IDKey`, `IDParam`, `Description`)
VALUES ($newKeyID, $paramID, '$paramDescription')"
);
if( !mysql_affected_rows() )
return 'Could not insert a string parameter.';
}
foreach( $langStrings as $langKey => $langString ) {
//NOTE: This piece of code can potentially
// insert language strings that don't belong
// to any language in case if a client generates
// his POST data himself in an unusual way.
// As this issue is not in fact dangerous for the script's
// security, no checks have been added to prevent this.
$langKey = (int)$langKey;
db_res("
INSERT INTO `LocalizationStrings`
(`IDKey`, `IDLanguage`, `String`)
VALUES ($newKeyID, $langKey, '$langString')
");
if (mysql_affected_rows() <= 0) return 'Error: could not add a language string.';
}
if ( $_POST['RecompileLangFiles'] == 'on' )
{
if ( !compileLanguage() )
{
return 'Error: could not recompile language files.';
}
}
return 'A new language key has been successfully created.';
}
ob_start();
?>
Add a new language key
if ( isset($_POST['AddLangKey']) )
{
?>
exit();
}
?>