Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added is_slug() and updated t() to take arguments

  • Loading branch information...
commit f8ff75388d57a8d0830e410395ef0cf7e1cb99c7 1 parent 155a496
@mosbth authored
Showing with 32 additions and 1 deletion.
  1. +32 −1 src/bootstrap.php
View
33 src/bootstrap.php
@@ -32,11 +32,31 @@ function exceptionHandler($e) {
/**
* i18n, internationalization, send all strings though this function to enable i18n.
+ * Inspired by Drupal´s t()-function.
*
* @param string $str the string to check up for translation.
+ * @param array $args associative array with arguments to be replaced in the $str.
+ * - !variable: Inserted as is. Use this for text that has already been
+ * sanitized.
+ * - @variable: Escaped to HTML using htmlEnt(). Use this for anything
+ * displayed on a page on the site.
* @returns string the translated string.
*/
-function t($str) {
+function t($str, $args = array()) {
+ // translate string
+ //$str = gettext($str);
+
+ // santitize and replace arguments
+ if(!empty($args)) {
+ foreach($args as $key => $val) {
+ switch($key[0]) {
+ case '@': $args[$key] = htmlEnt($val); break;
+ case '!':
+ default: /* pass through */ break;
+ }
+ }
+ return strtr($str, $args);
+ }
return $str;
}
@@ -217,6 +237,17 @@ function slugify($str) {
/**
+ * Check if string is slugified, containing [a-zA-Z0-9-].
+ *
+ * @param string $str the string to check.
+ * @returns boolean true is slugified, else false.
+ */
+function is_slugified($str) {
+ return preg_match('/^[a-zA-Z0-9-]$/', $str);
+}
+
+
+/**
* Get a smaller part of text, a teaser, break at space/word/dot.
*
* @param string $str string to get the first part from.

0 comments on commit f8ff753

Please sign in to comment.
Something went wrong with that request. Please try again.