+
+// 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']);
+ }
+ }
+ }
+
+}}
+
+