aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/output.php
diff options
context:
space:
mode:
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-08-21 23:58:35 +0000
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-08-21 23:58:35 +0000
commit8a73785aee3e51c26c65053a4de7c5d7f0ebb673 (patch)
tree41e7e607886b0498a0d8d4dc79df6aaa5094d385 /engine/lib/output.php
parentb81f168b0bfc298c6eb1c0a2a857311f076c40bd (diff)
downloadelgg-8a73785aee3e51c26c65053a4de7c5d7f0ebb673.tar.gz
elgg-8a73785aee3e51c26c65053a4de7c5d7f0ebb673.tar.bz2
Merged r6586:6587 from 1.7 branch into trunk
git-svn-id: http://code.elgg.org/elgg/trunk@6842 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib/output.php')
-rw-r--r--engine/lib/output.php88
1 files changed, 87 insertions, 1 deletions
diff --git a/engine/lib/output.php b/engine/lib/output.php
index 3b82447b0..3280517b0 100644
--- a/engine/lib/output.php
+++ b/engine/lib/output.php
@@ -138,9 +138,29 @@ function elgg_format_url($url) {
*
* @param string $title The title
* @return string The optimised title
+ * @deprecated 1.8
*/
function friendly_title($title) {
- return elgg_view('output/friendlytitle', array('title' => $title));
+ elgg_deprecated_notice('friendly_title was deprecated by elgg_get_friendly_title', 1.8);
+ return elgg_get_friendly_title($title);
+}
+
+/**
+ * When given a title, returns a version suitable for inclusion in a URL
+ *
+ * @todo add plugin hook so that developers can provide their own friendly title
+ * @param string $title The title
+ * @return string The optimised title
+ * @since 1.7.2
+ */
+function elgg_get_friendly_title($title) {
+ //$title = iconv('UTF-8', 'ASCII//TRANSLIT', $title);
+ $title = preg_replace("/[^\w ]/","",$title);
+ $title = str_replace(" ","-",$title);
+ $title = str_replace("--","-",$title);
+ $title = trim($title);
+ $title = strtolower($title);
+ return $title;
}
/**
@@ -148,8 +168,74 @@ function friendly_title($title) {
*
* @param int $time A UNIX epoch timestamp
* @return string The friendly time
+ * @deprecated 1.8
*/
function friendly_time($time) {
+ elgg_deprecated_notice('friendly_time was deprecated by elgg_view_friendly_time', 1.8);
+ return elgg_view_friendly_time($time);
+}
+
+/**
+ * Displays a UNIX timestamp in a friendly way (eg "less than a minute ago")
+ *
+ * @todo add plugin hook so that developers can provide their own friendly time
+ * @param int $time A UNIX epoch timestamp
+ * @return string The friendly time
+ * @since 1.7.2
+ */
+function elgg_get_friendly_time($time) {
+ $diff = time() - (int)$time;
+
+ $minute = 60;
+ $hour = $minute * 60;
+ $day = $hour * 24;
+
+ if ($diff < $minute) {
+ return elgg_echo("friendlytime:justnow");
+ } else if ($diff < $hour) {
+ $diff = round($diff / $minute);
+ if ($diff == 0) {
+ $diff = 1;
+ }
+
+ if ($diff > 1) {
+ return sprintf(elgg_echo("friendlytime:minutes"), $diff);
+ } else {
+ return sprintf(elgg_echo("friendlytime:minutes:singular"), $diff);
+ }
+ } else if ($diff < $day) {
+ $diff = round($diff / $hour);
+ if ($diff == 0) {
+ $diff = 1;
+ }
+
+ if ($diff > 1) {
+ return sprintf(elgg_echo("friendlytime:hours"), $diff);
+ } else {
+ return sprintf(elgg_echo("friendlytime:hours:singular"), $diff);
+ }
+ } else {
+ $diff = round($diff / $day);
+ if ($diff == 0) {
+ $diff = 1;
+ }
+
+ if ($diff > 1) {
+ return sprintf(elgg_echo("friendlytime:days"), $diff);
+ } else {
+ return sprintf(elgg_echo("friendlytime:days:singular"), $diff);
+ }
+ }
+}
+
+/**
+ * Displays a UNIX timestamp in a friendly way
+ *
+ * @param int $time A UNIX epoch timestamp
+ * @return string The friendly time HTML
+ * @since 1.7.2
+ */
+function elgg_view_friendly_time($time) {
return elgg_view('output/friendlytime', array('time' => $time));
}