From 8e988b7c21b99b460d1a8c115893eeb7e7d97853 Mon Sep 17 00:00:00 2001 From: garvinhicking Date: Thu, 11 May 2006 08:14:39 +0000 Subject: [PATCH] =?utf8?q?Added=20helper=20API=20class=20by=20Falk=20D?= =?utf8?q?=C3=B6ring?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- docs/NEWS | 4 + include/plugin_api_extension.inc.php | 127 +++++++++++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 include/plugin_api_extension.inc.php diff --git a/docs/NEWS b/docs/NEWS index d985436..6239db0 100644 --- a/docs/NEWS +++ b/docs/NEWS @@ -3,6 +3,10 @@ Version 1.1-alpha5() ------------------------------------------------------------------------ + * Added "plugin_api_extension" class, which contains some helper + methods for future use, like re-ordering DB items or checking + valid emails. (Falk Döring) + * Fix multiple occurences of the string "--" in the entry title to not mess up HTML display because of weird Firefox interpretation (Bug #1474290) (garvinhicking) diff --git a/include/plugin_api_extension.inc.php b/include/plugin_api_extension.inc.php new file mode 100644 index 0000000..f728277 --- /dev/null +++ b/include/plugin_api_extension.inc.php @@ -0,0 +1,127 @@ + $value) { + if (strlen($where)) { + $where .= ' AND '; + } + $where .= $key . ' = ' . $value; + } + $q = 'SELECT '.implode(", ", array_keys($update_array)).' + FROM '. $serendipity['dbPrefix'] . $table .' + WHERE '.$where; + $old = serendipity_db_query($q, true, 'assoc'); + + if (is_array($old)) { + $where = array(); + $update = array(); + switch ($moveto) { + case 'up': + foreach ($update_array as $key => $value) { + if ($value) { + $where[$key] = ($old[$key] - 1); + $update[$key] = $old[$key]; + $update_1[$key] = ($old[$key] - 1); + } else { + $where[$key] = $old[$key]; + } + } + break; + case 'down': + foreach ($update_array as $key => $value) { + if ($value) { + $where[$key] = ($old[$key] + 1); + $update[$key] = $old[$key]; + $update_1[$key] = ($old[$key] + 1); + } else { + $where[$key] = $old[$key]; + } + } + break; + default: + return false; + } + serendipity_db_update($table, $where, $update); + serendipity_db_update($table, $where_array, $update_1); + return true; + } + } + return false; + } + + /** + * + * Check if a string is a valid email + * + * @access public + * @author Falk Doering + * @param string The email string + * @return bool is valid email true, else false + * + */ + + function isEmail($email) + { + $preg = '^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@(([_a-zA-Z0-9-]+\.)+([a-zA-Z]{2,}|museum)|localhost)$'; + return (preg_match($preg, $email) != 0); + } + +} -- 2.39.5