From b06f528fe5bcc74677707ab30df9f4beb13bd160 Mon Sep 17 00:00:00 2001 From: Cindy Li Date: Tue, 24 Aug 2010 20:24:55 +0000 Subject: [PATCH] 1. .flv conversion to use flowplayer must come after url conversion in makeClickable() 2. clean up output.inc.php to remove the functions that are not in use --- docs/home/classes/ContentUtility.class.php | 72 ++- docs/home/ims/include/ims_template.inc.php | 1 - docs/home/imscc/include/ims_template.inc.php | 1 - docs/include/lib/output.inc.php | 438 +------------------ 4 files changed, 58 insertions(+), 454 deletions(-) diff --git a/docs/home/classes/ContentUtility.class.php b/docs/home/classes/ContentUtility.class.php index ef16db6..2c3efbb 100644 --- a/docs/home/classes/ContentUtility.class.php +++ b/docs/home/classes/ContentUtility.class.php @@ -209,6 +209,10 @@ class ContentUtility { return $text; } + // remove the spaces in [media] tag, otherwise, the next line converts URL inside [media] into tag + $text = preg_replace("/(\[media\])([\s]*)(.*)(\[\/media\])/", '$1$3$4', $text); + $text = preg_replace("/(\[media\])(.*)([\s]*)(\[\/media\])/U", '$1$2$4', $text); + $media_matches = Array(); /* @@ -289,32 +293,35 @@ class ContentUtility { } } - $text = ContentUtility::embedFLV($text); - return $text; } - private static function makeClickable($text) { + public static function makeClickable($text) { $text = ContentUtility::embedMedia($text); - // $text = eregi_replace("([[:space:]])(http[s]?)://([^[:space:]<]*)([[:alnum:]#?/&=])", "\\1\\3\\4", $text); - // - // $text = eregi_replace( '([_a-zA-Z0-9\-]+(\.[_a-zA-Z0-9\-]+)*'. - // '\@'.'[_a-zA-Z0-9\-]+(\.[_a-zA-Z0-9\-]+)*'.'(\.[a-zA-Z]{1,6})+)', - // "\\1", - // $text); - - $text = preg_replace("/([\s])(http[s]?):\/\/(.*)(\s|\$|)(.*)/U", - "\\1\\3\\4\\5", $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', - "\\1", + // 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: + //

http://google.ca

+ // "http://google.ca" + $text = preg_replace('/(^|[\n ])([\w]*?[\"]*)((?$3', $text); + + // convert email address to clickable URL that pops up "send email" interface with the address filled in + $text = preg_replace('/(?|(.*)<\/a>' + .'|((((([_a-zA-Z0-9\-]+(\.[_a-zA-Z0-9\-]+)*'.'\@' + .'[_a-zA-Z0-9\-]+(\.[_a-zA-Z0-9\-]+)*'.'(\.[a-zA-Z]{1,6})+))))))/i', + "\\5", $text); + + // flv conversion needs to come after url conversion (2 lines above) otherwise the url to flowplayer swf file + // in the script for a.flowplayerholder is converted + $text = ContentUtility::embedFLV($text); + return $text; } - private static function myCodes($text, $html = false) { + public static function myCodes($text, $html = false) { global $_base_path; global $HTTP_USER_AGENT; @@ -400,7 +407,7 @@ class ContentUtility { $text = str_replace("[code]","[code][/code]",$text); - $text = preg_replace("/\[code\]\s*(.*)\s*\[\\/code\]/Usei", "highlight_code(fix_quotes('\\1'), $html)", $text); + $text = preg_replace("/\[code\]\s*(.*)\s*\[\\/code\]/Usei", "ContentUtility::highlightCode(ContentUtility::fixQuotes('\\1'), $html)", $text); // now remove the */ + private static function highlightCode($code, $html) { + // XHTMLize PHP highlight_string output until it gets fixed in PHP + static $search = array( + '
', + '', + 'color="'); + + static $replace = array( + '
', + '', + 'style="color:'); + if (!$html) { + $code = str_replace('<', '<', $code); + $code = str_replace("\r", '', $code); + } + + return str_replace($search, $replace, highlight_string($code, true)); + } + + /* contributed by Thomas M. Duffey */ + private static function fixQuotes($text){ + return str_replace('\\"', '"', $text); + } + + public static function imageReplace($text) { /* image urls do not require http:// */ // $text = eregi_replace("\[image(\|)?([[:alnum:][:space:]]*)\]" . diff --git a/docs/home/ims/include/ims_template.inc.php b/docs/home/ims/include/ims_template.inc.php index 24a5639..c904ad5 100644 --- a/docs/home/ims/include/ims_template.inc.php +++ b/docs/home/ims/include/ims_template.inc.php @@ -91,7 +91,6 @@ function print_organizations($parent_id, $html_link = ''.$content['title'].''; /* save the content as HTML files */ - /* @See: include/lib/format_content.inc.php */ $content['text'] = str_replace('CONTENT_DIR/', '', $content['text']); /* Commented by Cindy Qi Li on Jan 12, 2010 diff --git a/docs/home/imscc/include/ims_template.inc.php b/docs/home/imscc/include/ims_template.inc.php index ad32171..3384bd3 100644 --- a/docs/home/imscc/include/ims_template.inc.php +++ b/docs/home/imscc/include/ims_template.inc.php @@ -116,7 +116,6 @@ function print_organizations($parent_id, $html_link = ''.$content['title'].''; /* save the content as HTML files */ - /* @See: include/lib/format_content.inc.php */ $content['text'] = str_replace('CONTENT_DIR/', '', $content['text']); /* Commented by Cindy Qi Li on Jan 12, 2010 * AContent does not support glossary diff --git a/docs/include/lib/output.inc.php b/docs/include/lib/output.inc.php index 6aa0d81..f09a0bf 100644 --- a/docs/include/lib/output.inc.php +++ b/docs/include/lib/output.inc.php @@ -11,7 +11,8 @@ /************************************************************************/ if (!defined('TR_INCLUDE_PATH')) { exit; } -require(TR_INCLUDE_PATH . 'classes/DAO/LanguageTextDAO.class.php'); +require_once(TR_INCLUDE_PATH . 'classes/DAO/LanguageTextDAO.class.php'); +require_once(TR_INCLUDE_PATH . '../home/classes/ContentUtility.class.php'); /**********************************************************************************/ /* Output functions found in this file, in order: @@ -359,15 +360,15 @@ function AT_date($format='%Y-%M-%d', $timestamp = '', $format_type=TR_DATE_MYSQL } if (query_bit($_field_formatting[$name], TR_FORMTR_ATCODES)) { - $input = trim(myCodes(' ' . $input . ' ')); + $input = trim(ContentUtility::myCodes(' ' . $input . ' ')); } if (query_bit($_field_formatting[$name], TR_FORMTR_LINKS)) { - $input = trim(make_clickable(' ' . $input . ' ')); + $input = trim(ContentUtility::makeClickable(' ' . $input . ' ')); } if (query_bit($_field_formatting[$name], TR_FORMTR_IMAGES)) { - $input = trim(image_replace(' ' . $input . ' ')); + $input = trim(ContentUtility::imageReplace(' ' . $input . ' ')); } @@ -452,435 +453,6 @@ function smile_replace($text) { return $text; } - -/* Used specifically for the visual editor -*/ -function smile_javascript () { - global $_base_path; - global $smile_pics; - global $smile_codes; - - static $i = 0; - - while ($smile_pics [$i]) { - echo 'case "'.$smile_codes[$i].'":'."\n"; - echo 'pic = "'.$smile_pics[$i].'";'."\n"; - echo 'break;'."\n"; - $i++; - } -} - -function myCodes($text, $html = false) { - global $_base_path; - global $HTTP_USER_AGENT; - - if (substr($HTTP_USER_AGENT,0,11) == 'Mozilla/4.7') { - $text = str_replace('[quote]','

',$text); - $text = str_replace('[/quote]','

',$text); - - $text = str_replace('[reply]','

',$text); - $text = str_replace('[/reply]','

',$text); - } else { - $text = str_replace('[quote]','

',$text); - $text = str_replace('[/quote]','

',$text); - - $text = str_replace('[reply]','

',$text); - $text = str_replace('[/reply]','

',$text); - } - - $text = str_replace('[b]','',$text); - $text = str_replace('[/b]','',$text); - - $text = str_replace('[i]','',$text); - $text = str_replace('[/i]','',$text); - - $text = str_replace('[u]','',$text); - $text = str_replace('[/u]','',$text); - - $text = str_replace('[center]','

',$text); - $text = str_replace('[/center]','

',$text); - - /* colours */ - $text = str_replace('[blue]','',$text); - $text = str_replace('[/blue]','',$text); - - $text = str_replace('[orange]','',$text); - $text = str_replace('[/orange]','',$text); - - $text = str_replace('[red]','',$text); - $text = str_replace('[/red]','',$text); - - $text = str_replace('[purple]','',$text); - $text = str_replace('[/purple]','',$text); - - $text = str_replace('[green]','',$text); - $text = str_replace('[/green]','',$text); - - $text = str_replace('[gray]','',$text); - $text = str_replace('[/gray]','',$text); - - $text = str_replace('[op]',' '._AT('view_entire_post').'',$text); - - $text = str_replace('[head1]','

',$text); - $text = str_replace('[/head1]','

',$text); - - $text = str_replace('[head2]','

',$text); - $text = str_replace('[/head2]','

',$text); - - $text = str_replace('[cid]',$_base_path.'content.php?cid='.$_SESSION['s_cid'],$text); - - global $sequence_links; - if (isset($sequence_links['previous']) && $sequence_links['previous']['url']) { - $text = str_replace('[pid]', $sequence_links['previous']['url'], $text); - } - if (isset($sequence_links['next']) && $sequence_links['next']['url']) { - $text = str_replace('[nid]', $sequence_links['next']['url'], $text); - } - if (isset($sequence_links['resume']) && $sequence_links['resume']['url']) { - $text = str_replace('[nid]', $sequence_links['resume']['url'], $text); - } - if (isset($sequence_links['first']) && $sequence_links['first']['url']) { - $text = str_replace('[fid]', $sequence_links['first']['url'], $text); - } - - /* contributed by Thomas M. Duffey */ - $html = !$html ? 0 : 1; - $text = preg_replace("/\[code\]\s*(.*)\s*\[\\/code\]/Usei", "highlight_code(fix_quotes('\\1'), $html)", $text); - - return $text; -} - -/* contributed by Thomas M. Duffey */ -function highlight_code($code, $html) { - // XHTMLize PHP highlight_string output until it gets fixed in PHP - static $search = array( - '
', - '', - 'color="'); - - static $replace = array( - '
', - '', - 'style="color:'); - if (!$html) { - $code = str_replace('<', '<', $code); - $code = str_replace("\r", '', $code); - } - - return str_replace($search, $replace, highlight_string($code, true)); -} - -/* contributed by Thomas M. Duffey */ -function fix_quotes($text){ - return str_replace('\\"', '"', $text); -} - -function embed_media($text) { - if (preg_match("/\[media(\|[0-9]+\|[0-9]+)?\]*/", $text)==0){ - return $text; - } - - $media_matches = Array(); - - /* - First, we search though the text for all different kinds of media defined by media tags and store the results in $media_matches. - - Then the different replacements for the different media tags are stored in $media_replace. - - Lastly, we loop through all $media_matches / $media_replaces. (We choose $media_replace as index because $media_matches is multi-dimensioned.) It is important that for each $media_matches there is a $media_replace with the same index. For each media match we check the width/height, or we use the default value of 425x350. We then replace the height/width/media1/media2 parameter placeholders in $media_replace with the correct ones, before running a str_replace on $text, replacing the given media with its correct replacement. - - */ - - // youtube videos - preg_match_all("#\[media[0-9a-z\|]*\]http://([a-z0-9\.]*)?youtube.com/watch\?v=([a-z0-9_-]+)\[/media\]#i",$text,$media_matches[1],PREG_SET_ORDER); - $media_replace[1] = ''; - - // .mpg - preg_match_all("#\[media[0-9a-z\|]*\]([.\w\d]+[^\s\"]+).mpg\[/media\]#i",$text,$media_matches[2],PREG_SET_ORDER); - $media_replace[2] = "##MEDIA1##.mpg"; - - // .avi - preg_match_all("#\[media[0-9a-z\|]*\]([.\w\d]+[^\s\"]+).avi\[/media\]#i",$text,$media_matches[3],PREG_SET_ORDER); - $media_replace[3] = "##MEDIA1##.avi"; - - // .wmv - preg_match_all("#\[media[0-9a-z\|]*\]([.\w\d]+[^\s\"]+).wmv\[/media\]#i",$text,$media_matches[4],PREG_SET_ORDER); - $media_replace[4] = "##MEDIA1##.wmv"; - - // .mov - preg_match_all("#\[media[0-9a-z\|]*\]([.\w\d]+[^\s\"]+).mov\[/media\]#i",$text,$media_matches[5],PREG_SET_ORDER); - $media_replace[5] = "##MEDIA1##.mov"; - - // .swf - preg_match_all("#\[media[0-9a-z\|]*\]([.\w\d]+[^\s\"]+).swf\[/media\]#i",$text,$media_matches[6],PREG_SET_ORDER); - $media_replace[6] = " ##MEDIA1##.swf"; - - // .mp3 - preg_match_all("#\[media[0-9a-z\|]*\](.+[^\s\"]+).mp3\[/media\]#i",$text,$media_matches[7],PREG_SET_ORDER); - $media_replace[7] = "##MEDIA1##.mp3"; - - // .wav - preg_match_all("#\[media[0-9a-z\|]*\](.+[^\s\"]+).wav\[/media\]#i",$text,$media_matches[8],PREG_SET_ORDER); - $media_replace[8] ="##MEDIA1##.wav"; - - // .ogg - preg_match_all("#\[media[0-9a-z\|]*\](.+[^\s\"]+).ogg\[/media\]#i",$text,$media_matches[9],PREG_SET_ORDER); - $media_replace[9] ="##MEDIA1##.ogg"; - - // .mid - preg_match_all("#\[media[0-9a-z\|]*\](.+[^\s\"]+).mid\[/media\]#i",$text,$media_matches[10],PREG_SET_ORDER); - $media_replace[10] ="##MEDIA1##.mid"; - - $text = preg_replace("#\[media[0-9a-z\|]*\](.+[^\s\"]+).mid\[/media\]#i", "\\1.mid", $text); - - // Executing the replace - for ($i=1;$i<=count($media_replace);$i++){ - foreach($media_matches[$i] as $media) - { - - //find width and height for each matched media - if (preg_match("/\[media\|([0-9]*)\|([0-9]*)\]*/", $media[0], $matches)) - { - $width = $matches[1]; - $height = $matches[2]; - } - else - { - $width = 425; - $height = 350; - } - - //replace media tags with embedded media for each media tag - $media_input = $media_replace[$i]; - $media_input = str_replace("##WIDTH##","$width",$media_input); - $media_input = str_replace("##HEIGHT##","$height",$media_input); - $media_input = str_replace("##MEDIA1##","$media[1]",$media_input); - $media_input = str_replace("##MEDIA2##","$media[2]",$media_input); - $text = str_replace($media[0],$media_input,$text); - } - } - - return $text; -} - -function make_clickable($text) { - $text = embed_media($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: - //

http://google.ca

- // "http://google.ca" - // 1. remove the spaces in [media] tag, otherwise, the next line converts URL inside [media] into 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]*?[\"]*)((?$3', $text); - - // convert email address to clickable URL that pops up "send email" interface with the address filled in - $text = preg_replace('/(?|(.*)<\/a>' - .'|((((([_a-zA-Z0-9\-]+(\.[_a-zA-Z0-9\-]+)*'.'\@' - .'[_a-zA-Z0-9\-]+(\.[_a-zA-Z0-9\-]+)*'.'(\.[a-zA-Z]{1,6})+))))))/i', - "\\5", - $text); - - return $text; -} - -function image_replace($text) { - /* image urls do not require http:// */ - - $text = preg_replace("/\[image(\|)?([a-zA-Z0-9\s]*)\]". - "[\s]*". - "([a-zA-Z0-9\#\?\/\&\=\:\\\"\'\_\.\-]+)[\s]*". - "((\[\/image\])|(.*\[\/image\]))/i", - "\"\\2\"", - $text); - - return $text; -} - -function formTR_final_output($text, $nl2br = true) { - global $_base_path; - - $text = str_replace('CONTENT_DIR/', '', $text); - - if ($nl2br) { - return nl2br(image_replace(make_clickable(myCodes(' '.$text, false)))); - } - return image_replace(make_clickable(myCodes(' '.$text, true))); -} - -/****************************************************************************************/ -/* @See: ./user/search.php & ./index.php */ -function highlight($input, $var) {//$input is the string, $var is the text to be highlighted - if ($var != "") { - $xtemp = ""; - $i=0; - /* - The following 'if' statement is a check to ensure that the search term is not part of the tag, ''. Words within this string are avoided in case a previously highlighted string is used for the haystack, $input. To avoid any html breaks in the highlighted string, the search word is avoided completely. - */ - if (strpos('', $var) !== false) { - return $input; - } - while($i'; - $i += strlen($var); - } - else { - $xtemp .= $input{$i}; - $i++; - } - } - $input = $xtemp; - } - return $input; -} - - -/* @See: ./index.php */ -function formTR_content($input, $html = 0, $glossary, $simple = false) { - global $_base_path, $_config_defaults; - - if (!$html) { - $input = str_replace('<', '<', $input); - $input = str_replace('<?php', ' $v) { - $k = urldecode($k); - $v = str_replace("\n", '
', $v); - $v = str_replace("\r", '', $v); - - /* escape special characters */ - $k = preg_quote($k); - - $k = str_replace('<', '<', $k); - $k = str_replace('/', '\/', $k); - - $original_term = $k; - $term = $original_term; - - $term = '(\s*'.$term.'\s*)'; - $term = str_replace(' ','((
)*\s*)', $term); - - $def = htmlspecialchars($v); - if ($simple) { - $input = preg_replace - ("/(\[\?\])$term(\[\/\?\])/i", - '\\2', - $input); - } else { - $input = preg_replace - ("/(\[\?\])$term(\[\/\?\])/i", - '\\2?', - $input); - } - } - } else if (!$user_glossary) { - $input = str_replace(array('[?]','[/?]'), '', $input); - } - - $input = str_replace('CONTENT_DIR', '', $input); - - if (isset($_config_defaults['latex_server']) && $_config_defaults['latex_server']) { - // see: http://www.forkosh.com/mimetex.html - $input = preg_replace('/\[tex\](.*?)\[\/tex\]/sie', "''", $input); - } - - if ($html) { - $x = formTR_final_output($input, false); - return $x; - } - - $output = formTR_final_output($input); - - $output = '

'.$output.'

'; - - return $output; -} - -/*********************************************************************** - @See /include/Classes/Message/Message.class.php - Jacek Materna -*/ - -/** -* Take a code as input and grab its language specific message. Also cache the resulting -* message. Return the message. Same as get_message but key value in cache is string -* @access public -* @param string $codes Message Code to translate - > 'term' field in DB -* @return string The translated language specific message for code $code -* @author Jacek Materna -*/ -function getTranslatedCodeStr($codes) { - - /* this is where we want to get the msgs from the database inside a static variable */ - global $_cache_msgs_new; - static $_msgs_new; - - if (!isset($_msgs_new)) { - if ( !($lang_et = cache(120, 'msgs_new', $_SESSION['lang'])) ) { - global $db, $_base_path; - - $parent = Language::getParentCode($_SESSION['lang']); - - /* get $_msgs_new from the DB */ - $sql = 'SELECT * FROM '.TABLE_PREFIX.'language_text WHERE variable="_msgs" AND (language_code="'.$_SESSION['lang'].'" OR language_code="'.$parent.'")'; - $result = @mysql_query($sql, $db); - $i = 1; - while ($row = @mysql_fetch_assoc($result)) { - // do not cache key as a digit (no contstant(), use string) - $_cache_msgs_new[$row['term']] = str_replace('SITE_URL/', $_base_path, $row['text']); - if (TR_DEVEL) { - $_cache_msgs_new[$row['term']] .= ' ('.$row['term'].')'; - } - } - - cache_variable('_cache_msgs_new'); - endcache(true, false); - } - $_msgs_new = $_cache_msgs_new; - } - - if (is_array($codes)) { - /* this is an array with terms to replace */ - $code = array_shift($codes); - - $message = $_msgs_new[$code]; - $terms = $codes; - - /* replace the tokens with the terms */ - $message = vsprintf($message, $terms); - - } else { - $message = $_msgs_new[$codes]; - - if ($message == '') { - /* the language for this msg is missing: */ - - $sql = 'SELECT * FROM '.TABLE_PREFIX.'language_text WHERE variable="_msgs"'; - $result = @mysql_query($sql, $db); - $i = 1; - while ($row = @mysql_fetch_assoc($result)) { - if (($row['term']) === $codes) { - $message = '['.$row['term'].']'; - break; - } - } - } - $code = $codes; - } - return $message; -} - function html_get_list($array) { $list = ''; foreach ($array as $value) { -- 2.17.1