From 1b83db41e5e02f5dfef8ce57183a49ee5f0844de Mon Sep 17 00:00:00 2001 From: DariusIII Date: Sun, 13 Apr 2014 20:35:22 +0200 Subject: [PATCH] More fixes --- bin/monitor.php | 2 +- lib/Film.php | 8 ++++---- lib/functions.php | 21 +++++++++++++++++++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/bin/monitor.php b/bin/monitor.php index 90bc60dc4..e0811bdcc 100644 --- a/bin/monitor.php +++ b/bin/monitor.php @@ -9,7 +9,7 @@ require_once(dirname(__FILE__)."/../lib/showsleep.php"); require_once(dirname(__FILE__)."/../lib/functions.php"); -$version="0.3r1091"; +$version="0.3r1092"; $db = new DB(); $functions = new Functions(); diff --git a/lib/Film.php b/lib/Film.php index 35cacecac..288a68ed1 100644 --- a/lib/Film.php +++ b/lib/Film.php @@ -1127,7 +1127,7 @@ class Film $andYearIn .= $end . ')'; } $IMDBCheck = $this->db->queryOneRow( - sprintf('%s WHERE title %s %s', $query, $this->db->likeString($this->currentTitle), $andYearIn)); + sprintf('%s WHERE title %s %s', $query, $this->functions->likeString($this->currentTitle), $andYearIn)); // Look by %word%word%word% etc.. if ($IMDBCheck === false) { @@ -1138,7 +1138,7 @@ class Film } $IMDBCheck = $this->db->queryOneRow( sprintf("%s WHERE replace(replace(title, \"'\", ''), '!', '') %s %s", - $query, $this->db->likeString($tempTitle), $andYearIn + $query, $this->functions->likeString($tempTitle), $andYearIn ) ); } @@ -1149,7 +1149,7 @@ class Film if ($tempTitle !== $this->currentTitle) { $IMDBCheck = $this->db->queryOneRow( sprintf('%s WHERE title %s %s', - $query, $this->db->likeString($tempTitle), $andYearIn + $query, $this->functions->likeString($tempTitle), $andYearIn ) ); @@ -1162,7 +1162,7 @@ class Film } $IMDBCheck = $this->db->queryOneRow( sprintf("%s WHERE replace(replace(replace(title, \"'\", ''), '!', ''), '\"', '') %s %s", - $query, $this->db->likeString($tempTitle), $andYearIn + $query, $this->functions->likeString($tempTitle), $andYearIn ) ); } diff --git a/lib/functions.php b/lib/functions.php index 8c2783feb..877bb9985 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -3651,6 +3651,27 @@ class Functions } } + /** + * Formats a 'like' string. ex.(LIKE '%chocolate%') + * + * @param string $str The string. + * @param bool $left Add a % to the left. + * @param bool $right Add a % to the right. + * + * @return string + */ + public function likeString($str, $left=true, $right=true) + { + return ( + (DB_TYPE === 'mysql' ? 'LIKE ' : 'ILIKE ') . + $this->escapeString( + ($left ? '%' : '') . + $str . + ($right ? '%' : '') + ) + ); + } + //end of testing