aboutsummaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authormarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-06-05 17:43:35 +0000
committermarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-06-05 17:43:35 +0000
commita4340107482a45d9a1b04dbfda9a6c0578c75e59 (patch)
treee244f172e3440d2a07b0752949c08210aec72770 /engine
parentc15e8643b1eb0e8821bd3fb254a16d77b50f4bdd (diff)
downloadelgg-a4340107482a45d9a1b04dbfda9a6c0578c75e59.tar.gz
elgg-a4340107482a45d9a1b04dbfda9a6c0578c75e59.tar.bz2
Closes #639:
* Metastrings can be searched either case sensitive or insensitive modes. * Tags now have case lowered in a UTF8 safe way (requires mbstring support). * Introducing mb_wrapper.php containing multibyte wrapper functions. * Version bump. * Introduces #1043 for consideration. git-svn-id: https://code.elgg.org/elgg/trunk@3322 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine')
-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')");