<?php
/************************************************************************/
-/* Transformable */
+/* AContent */
/************************************************************************/
-/* Copyright (c) 2009 */
-/* Adaptive Technology Resource Centre / University of Toronto */
+/* Copyright (c) 2010 */
+/* Inclusive Design Institute */
/* */
/* This program is free software. You can redistribute it and/or */
/* modify it under the terms of the GNU General Public License */
TR_DATE_UNIX_TIMESTAMP: seconds since epoch
TR_DATE_INDEX_VALUE: 0-x, index into a date array
*/
-function AT_date($format='%Y-%M-%d', $timestamp = '', $formTR_type=TR_DATE_MYSQL_DATETIME) {
+function AT_date($format='%Y-%M-%d', $timestamp = '', $format_type=TR_DATE_MYSQL_DATETIME) {
static $day_name_ext, $day_name_con, $month_name_ext, $month_name_con;
global $_config;
'date_dec');
}
- if ($formTR_type == TR_DATE_INDEX_VALUE) {
+ if ($format_type == TR_DATE_INDEX_VALUE) {
// apply timezone offset
apply_timezone($timestamp);
if ($timestamp == '') {
$timestamp = time();
- $formTR_type = TR_DATE_UNIX_TIMESTAMP;
+ $format_type = TR_DATE_UNIX_TIMESTAMP;
}
/* convert the date to a Unix timestamp before we do anything with it */
- if ($formTR_type == TR_DATE_MYSQL_DATETIME) {
+ if ($format_type == TR_DATE_MYSQL_DATETIME) {
$year = substr($timestamp,0,4);
$month = substr($timestamp,5,2);
$day = substr($timestamp,8,2);
$sec = substr($timestamp,17,2);
$timestamp = mktime($hour, $min, $sec, $month, $day, $year);
- } else if ($formTR_type == TR_DATE_MYSQL_TIMESTAMP_14) {
+ } else if ($format_type == TR_DATE_MYSQL_TIMESTAMP_14) {
$year = substr($timestamp,0,4);
$month = substr($timestamp,4,2);
$day = substr($timestamp,6,2);
/**
* Transforms text based on formatting preferences. Original $input is also changed (passed by reference).
* Can be called as:
- * 1) $output = TR_print($input, $name);
+ * 1) $output = AT_print($input, $name);
* echo $output;
*
- * 2) echo TR_print($input, $name); // prefered method
+ * 2) echo AT_print($input, $name); // prefered method
*
* @access public
* @param string $input text being transformed
* @see query_bit() in include/vitals.inc.php
* @author Joel Kronenberg
*/
- function TR_print($input, $name, $runtime_html = true) {
+ function AT_print($input, $name, $runtime_html = true) {
global $_field_formatting;
if (!isset($_field_formatting[$name])) {
function make_clickable($text) {
$text = embed_media($text);
- $text = preg_replace("/([\s])(http[s]?):\/\/([\^\s\<]*)([a-zA-Z0-9\#\?\/\&\=])/i",
- "\\1<a href=\"\\2://\\3\\4\">\\3\\4</a>", $text);
+ // The next 3 preg_replace convert plain text URL to clickable URL.
+ // limited conversion. It doesn't cover the case when the stuff in front of the URL is not a word. For example:
+ // <p>http://google.ca</p>
+ // "http://google.ca"
+ // 1. remove the spaces in [media] tag, otherwise, the next line converts URL inside [media] into <a> tag
+ $text = preg_replace("/(\[media\])([\s]*)(.*)(\[\/media\])/", '$1$3$4', $text);
+ $text = preg_replace("/(\[media\])(.*)([\s]*)(\[\/media\])/U", '$1$2$4', $text);
+ // 2. convert URL
+ $text = preg_replace('/(^|[\n ])([\w]*?[\"]*)((?<!(\[media\]))http(s)?:\/\/[\w]+[^ \,\"\n\r\t\)<]*)/is',
+ '$1$2<a href="$3">$3</a>', $text);
- $text = preg_replace('/([_a-zA-Z0-9\-]+(\.[_a-zA-Z0-9\-]+)*'.
- '\@'.'[_a-zA-Z0-9\-]+(\.[_a-zA-Z0-9\-]+)*'.'(\.[a-zA-Z]{1,6})+)/i',
- "<a href=\"mailto:\\1\">\\1</a>",
+ // convert email address to clickable URL that pops up "send email" interface with the address filled in
+ $text = preg_replace('/(?|<a href="mailto[\s]*:[\s]*([_a-zA-Z0-9\-]+(\.[_a-zA-Z0-9\-]+)*'.'\@'
+ .'[_a-zA-Z0-9\-]+(\.[_a-zA-Z0-9\-]+)*'.'(\.[a-zA-Z]{1,6})+)">(.*)<\/a>'
+ .'|((((([_a-zA-Z0-9\-]+(\.[_a-zA-Z0-9\-]+)*'.'\@'
+ .'[_a-zA-Z0-9\-]+(\.[_a-zA-Z0-9\-]+)*'.'(\.[a-zA-Z]{1,6})+))))))/i',
+ "<a href=\"mailto:\\1\">\\5</a>",
$text);
return $text;