aboutsummaryrefslogtreecommitdiff
path: root/engine/lib
diff options
context:
space:
mode:
Diffstat (limited to 'engine/lib')
-rw-r--r--engine/lib/mb_wrapper.php46
-rw-r--r--engine/lib/metadata.php4
-rw-r--r--engine/lib/metastrings.php14
3 files changed, 58 insertions, 6 deletions
diff --git a/engine/lib/mb_wrapper.php b/engine/lib/mb_wrapper.php
new file mode 100644
index 000000000..7b3327edc
--- /dev/null
+++ b/engine/lib/mb_wrapper.php
@@ -0,0 +1,46 @@
+<?php
+ /**
+ * Elgg wrapper functions for multibyte string support.
+ *
+ * @package Elgg
+ * @subpackage Core
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Curverider Ltd
+ * @copyright Curverider Ltd 2008-2009
+ * @link http://elgg.org/
+ */
+
+ /**
+ * Wrapper function: Returns the result of mb_strtolower if mb_support is present, else the
+ * result of strtolower is returned.
+ *
+ * @param string $string The string.
+ * @param string $charset The charset (if multibyte support is present) : default 'UTF8'
+ * @return string
+ */
+ function elgg_strtolower($string, $charset = 'UTF8')
+ {
+ if (is_callable('mb_strtolower'))
+ return mb_strtolower($string, $charset);
+
+ return strtolower($string);
+ }
+
+ /**
+ * Wrapper function: Returns the result of mb_strtoupper if mb_support is present, else the
+ * result of strtoupper is returned.
+ *
+ * @param string $string The string.
+ * @param string $charset The charset (if multibyte support is present) : default 'UTF8'
+ * @return string
+ */
+ function elgg_strtoupper($string, $charset = 'UTF8')
+ {
+ if (is_callable('mb_strtoupper'))
+ return mb_strtoupper($string, $charset);
+
+ return strtoupper($string);
+ }
+
+ // TODO: Other wrapper functions
+?> \ No newline at end of file
diff --git a/engine/lib/metadata.php b/engine/lib/metadata.php
index ebc425f17..79a5faacf 100644
--- a/engine/lib/metadata.php
+++ b/engine/lib/metadata.php
@@ -797,8 +797,8 @@
if (is_string($string)) {
$ar = explode(",",$string);
- $ar = array_map('trim', $ar); // trim blank spaces
- //$ar = array_map('strtolower', $ar); // make lower case : [Marcus Povey 20090210 - Commented out since strtolower is not UTF8 safe]
+ $ar = array_map('trim', $ar); // trim blank spaces
+ $ar = array_map('elgg_strtolower', $ar); // make lower case : [Marcus Povey 20090605 - Using mb wrapper function using UTF8 safe function where available]
$ar = array_filter($ar, 'is_not_null'); // Remove null values
return $ar;
}
diff --git a/engine/lib/metastrings.php b/engine/lib/metastrings.php
index b37456b3a..2e308e12e 100644
--- a/engine/lib/metastrings.php
+++ b/engine/lib/metastrings.php
@@ -21,9 +21,10 @@
* Return the meta string id for a given tag, or false.
*
* @param string $string The value (whatever that is) to be stored
+ * @param bool $case_sensitive Do we want to make the query case sensitive?
* @return mixed Integer tag or false.
*/
- function get_metastring_id($string)
+ function get_metastring_id($string, $case_sensitive = true)
{
global $CONFIG, $METASTRINGS_CACHE, $METASTRINGS_DEADNAME_CACHE;
@@ -49,7 +50,11 @@
if ($metastrings_memcache) $msfc = $metastrings_memcache->load($string);
if ($msfc) return $msfc;
- $row = get_data_row("SELECT * from {$CONFIG->dbprefix}metastrings where string='$string' limit 1");
+ // Case sensitive
+ $cs = "";
+ if ($case_sensitive) $cs = " BINARY ";
+
+ $row = get_data_row("SELECT * from {$CONFIG->dbprefix}metastrings where string=$cs'$string' limit 1");
if ($row) {
$METASTRINGS_CACHE[$row->id] = $row->string; // Cache it
@@ -106,15 +111,16 @@
* It returns the id of the tag, whether by creating it or updating it.
*
* @param string $string The value (whatever that is) to be stored
+ * @param bool $case_sensitive Do we want to make the query case sensitive?
* @return mixed Integer tag or false.
*/
- function add_metastring($string)
+ function add_metastring($string, $case_sensitive = true)
{
global $CONFIG, $METASTRINGS_CACHE, $METASTRINGS_DEADNAME_CACHE;
$sanstring = sanitise_string($string);
- $id = get_metastring_id($string);
+ $id = get_metastring_id($string, $case_sensitive);
if ($id) return $id;
$result = insert_data("INSERT into {$CONFIG->dbprefix}metastrings (string) values ('$sanstring')");