if(! function_exists('xmlify')) {
function xmlify($str) {
- $buffer = '';
+/* $buffer = '';
- for($x = 0; $x < mb_strlen($str); $x ++) {
- $char = $str[$x];
+ $len = mb_strlen($str);
+ for($x = 0; $x < $len; $x ++) {
+ $char = mb_substr($str,$x,1);
switch( $char ) {
$buffer .= $char;
break;
}
- }
+ }*/
+
+ $buffer = mb_ereg_replace("&", "&", $str);
+ $buffer = mb_ereg_replace("'", "'", $buffer);
+ $buffer = mb_ereg_replace("\"", """, $buffer);
+ $buffer = mb_ereg_replace("<", "<", $buffer);
+ $buffer = mb_ereg_replace(">", ">", $buffer);
+
$buffer = trim($buffer);
return($buffer);
}}
if(! function_exists('unxmlify')) {
function unxmlify($s) {
- $ret = str_replace('&','&', $s);
- $ret = str_replace(array('<','>','"','''),array('<','>','"',"'"),$ret);
+// $ret = str_replace('&','&', $s);
+// $ret = str_replace(array('<','>','"','''),array('<','>','"',"'"),$ret);
+ $ret = mb_ereg_replace('&', '&', $s);
+ $ret = mb_ereg_replace(''', "'", $ret);
+ $ret = mb_ereg_replace('"', '"', $ret);
+ $ret = mb_ereg_replace('<', "<", $ret);
+ $ret = mb_ereg_replace('>', ">", $ret);
return $ret;
}}
return false;
}}
+
+// Find any non-embedded images in private items and add redir links to them
+
+if(! function_exists('redir_private_images')) {
+function redir_private_images($a, &$item) {
+
+ $matches = false;
+ $cnt = preg_match_all('|\[img\](http[^\[]*?/photo/[a-fA-F0-9]+?(-[0-9]\.[\w]+?)?)\[\/img\]|', $item['body'], $matches, PREG_SET_ORDER);
+ if($cnt) {
+ //logger("redir_private_images: matches = " . print_r($matches, true));
+ foreach($matches as $mtch) {
+ if(strpos($mtch[1], '/redir') !== false)
+ continue;
+
+ if((local_user() == $item['uid']) && ($item['private'] != 0) && ($item['contact-id'] != $a->contact['id']) && ($item['network'] == NETWORK_DFRN)) {
+ //logger("redir_private_images: redir");
+ $img_url = $a->get_baseurl() . '/redir?f=1&quiet=1&url=' . $mtch[1] . '&conurl=' . $item['author-link'];
+ $item['body'] = str_replace($mtch[0], "[img]".$img_url."[/img]", $item['body']);
+ }
+ }
+ }
+
+}}
+
+
// Given an item array, convert the body element from bbcode to html and add smilie icons.
// If attach is true, also add icons for item attachments
-
if(! function_exists('prepare_body')) {
function prepare_body($item,$attach = false) {
$s = file_get_contents($cachefile);
$a->save_timestamp($stamp1, "file");
} else {
+ redir_private_images($a, $item);
$s = prepare_text($item['body']);
+
$stamp1 = microtime(true);
file_put_contents($cachefile, $s);
$a->save_timestamp($stamp1, "file");
+
logger('prepare_body: put item '.$item["id"].' into cachefile '.$cachefile);
}
- } else
+ } else {
+ redir_private_images($a, $item);
$s = prepare_text($item['body']);
+ }
$prep_arr = array('item' => $item, 'html' => $s);
$cnt = preg_match_all('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"|',$r,$matches, PREG_SET_ORDER);
if($cnt) {
foreach($matches as $mtch) {
- $icontype = strtolower(substr($mtch[3],0,strpos($mtch[3],'/')));
+ $filetype = strtolower(substr( $mtch[3], 0, strpos($mtch[3],'/') ));
+ if($filetype) {
+ $filesubtype = strtolower(substr( $mtch[3], strpos($mtch[3],'/') + 1 ));
+ $filesubtype = str_replace('.', '-', $filesubtype);
+ }
+ else {
+ $filetype = 'unkn';
+ $filesubtype = 'unkn';
+ }
+
+ $icon = '<div class="attachtype icon s22 type-' . $filetype . ' subtype-' . $filesubtype . '"></div>';
+ /*$icontype = strtolower(substr($mtch[3],0,strpos($mtch[3],'/')));
switch($icontype) {
case 'video':
case 'audio':
default:
$icon = '<div class="attachtype icon s22 type-unkn"></div>';
break;
- }
+ }*/
+
$title = ((strlen(trim($mtch[4]))) ? escape_tags(trim($mtch[4])) : escape_tags($mtch[1]));
$title .= ' ' . $mtch[2] . ' ' . t('bytes');
if((local_user() == $item['uid']) && ($item['contact-id'] != $a->contact['id']) && ($item['network'] == NETWORK_DFRN))