+ if(count($r))
+ $contact_record = $r[0];
+ }
+
+ $post_type = notags(trim($_POST['type']));
+
+ if($post_type === 'net-comment') {
+ if($parent_item !== null) {
+ if($parent_item['type'] === 'remote') {
+ $post_type = 'remote-comment';
+ }
+ else {
+ $post_type = 'wall-comment';
+ }
+ }
+ }
+
+ $str_tags = '';
+ $inform = '';
+
+ $tags = get_tags($body);
+
+
+ if(count($tags)) {
+ foreach($tags as $tag) {
+ if(strpos($tag,'#') === 0) {
+ $basetag = str_replace('_',' ',substr($tag,1));
+ $body = str_replace($tag,'#[url=' . $a->get_baseurl() . '/search?search=' . rawurlencode($basetag) . ']' . $basetag . '[/url]',$body);
+ if(strlen($str_tags))
+ $str_tags .= ',';
+ $str_tags .= '#[url=' . $a->get_baseurl() . '/search?search=' . rawurlencode($basetag) . ']' . $basetag . '[/url]';
+ continue;
+ }
+ if(strpos($tag,'@') === 0) {
+ $name = substr($tag,1);
+ if((strpos($name,'@')) || (strpos($name,'http://'))) {
+ $newname = $name;
+ $links = @lrdd($name);
+ if(count($links)) {
+ foreach($links as $link) {
+ if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
+ $profile = $link['@attributes']['href'];
+ if($link['@attributes']['rel'] === 'salmon') {
+ if(strlen($inform))
+ $inform .= ',';
+ $inform .= 'url:' . str_replace(',','%2c',$link['@attributes']['href']);
+ }
+ }
+ }
+ }
+ else {
+ $newname = $name;
+ if(strstr($name,'_')) {
+ $newname = str_replace('_',' ',$name);
+ $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
+ dbesc($newname),
+ intval($profile_uid)
+ );
+ }
+ else {
+ $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
+ dbesc($name),
+ intval($profile_uid)
+ );
+ }
+ if(count($r)) {
+ $profile = $r[0]['url'];
+ $newname = $r[0]['name'];
+ if(strlen($inform))
+ $inform .= ',';
+ $inform .= 'cid:' . $r[0]['id'];
+ }
+ }
+ if($profile) {
+ $body = str_replace($name,'[url=' . $profile . ']' . $newname . '[/url]', $body);
+ $profile = str_replace(',','%2c',$profile);
+ if(strlen($str_tags))
+ $str_tags .= ',';
+ $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]';
+ }
+ }
+ }
+ }
+
+ $wall = 0;
+ if($post_type === 'wall' || $post_type === 'wall-comment')
+ $wall = 1;
+
+ if(! strlen($verb))
+ $verb = ACTIVITY_POST ;
+
+ $gravity = (($parent) ? 6 : 0 );
+
+ $notify_type = (($parent) ? 'comment-new' : 'wall-new' );
+
+ $uri = item_new_uri($a->get_hostname(),$profile_uid);
+
+ $datarray = array();
+ $datarray['uid'] = $profile_uid;
+ $datarray['type'] = $post_type;
+ $datarray['wall'] = $wall;
+ $datarray['gravity'] = $gravity;
+ $datarray['contact-id'] = $contact_id;
+ $datarray['owner-name'] = $contact_record['name'];
+ $datarray['owner-link'] = $contact_record['url'];
+ $datarray['owner-avatar'] = $contact_record['thumb'];
+ $datarray['author-name'] = $author['name'];
+ $datarray['author-link'] = $author['url'];
+ $datarray['author-avatar'] = $author['thumb'];
+ $datarray['created'] = datetime_convert();
+ $datarray['edited'] = datetime_convert();
+ $datarray['changed'] = datetime_convert();
+ $datarray['uri'] = $uri;
+ $datarray['title'] = $title;
+ $datarray['body'] = $body;
+ $datarray['location'] = $location;
+ $datarray['coord'] = $coord;
+ $datarray['tag'] = $str_tags;
+ $datarray['inform'] = $inform;
+ $datarray['verb'] = $verb;
+ $datarray['allow_cid'] = $str_contact_allow;
+ $datarray['allow_gid'] = $str_group_allow;
+ $datarray['deny_cid'] = $str_contact_deny;
+ $datarray['deny_gid'] = $str_group_deny;
+ $datarray['private'] = $private;
+
+ /**
+ * These fields are for the convenience of plugins...
+ * 'self' if true indicates the owner is posting on their own wall
+ * If parent is 0 it is a top-level post.
+ */
+
+ $datarray['parent'] = $parent;
+ $datarray['self'] = $self;
+
+
+ call_hooks('post_local',$datarray);
+
+ $r = q("INSERT INTO `item` (`uid`,`type`,`wall`,`gravity`,`contact-id`,`owner-name`,`owner-link`,`owner-avatar`,
+ `author-name`, `author-link`, `author-avatar`, `created`, `edited`, `changed`, `uri`, `title`, `body`, `location`, `coord`,
+ `tag`, `inform`, `verb`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`, `private` )
+ VALUES( %d, '%s', %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d )",
+ intval($datarray['uid']),
+ dbesc($datarray['type']),
+ intval($datarray['wall']),
+ intval($datarray['gravity']),
+ intval($datarray['contact-id']),
+ dbesc($datarray['owner-name']),
+ dbesc($datarray['owner-link']),
+ dbesc($datarray['owner-avatar']),
+ dbesc($datarray['author-name']),
+ dbesc($datarray['author-link']),
+ dbesc($datarray['author-avatar']),
+ dbesc($datarray['created']),
+ dbesc($datarray['edited']),
+ dbesc($datarray['changed']),
+ dbesc($datarray['uri']),
+ dbesc($datarray['title']),
+ dbesc($datarray['body']),
+ dbesc($datarray['location']),
+ dbesc($datarray['coord']),
+ dbesc($datarray['tag']),
+ dbesc($datarray['inform']),
+ dbesc($datarray['verb']),
+ dbesc($datarray['allow_cid']),
+ dbesc($datarray['allow_gid']),
+ dbesc($datarray['deny_cid']),
+ dbesc($datarray['deny_gid']),
+ intval($datarray['private'])
+ );
+
+ $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
+ dbesc($datarray['uri']));
+ if(count($r)) {
+ $post_id = $r[0]['id'];
+ logger('mod_item: saved item ' . $post_id);
+
+ if($parent) {
+
+ // This item is the last leaf and gets the comment box, clear any ancestors
+ $r = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent` = %d ",
+ dbesc(datetime_convert()),
+ intval($parent)
+ );
+
+ // Inherit ACL's from the parent item.
+
+ $r = q("UPDATE `item` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s', `private` = %d