- if($_POST['type'] == 'jot') {
-
- do {
- $dups = false;
- $hash = random_string();
- $r = q("SELECT `id` FROM `item` WHERE `hash` = '%s' LIMIT 1",
- dbesc($hash));
- if(count($r))
- $dups = true;
- } while($dups == true);
-
-
- $r = q("INSERT INTO `item` (`uid`,`type`,`contact-id`,`owner-name`,`owner-link`,`owner-avatar`, `created`,`edited`,`hash`,`body`,
- `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`)
- VALUES( %d, '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )",
- intval($profile_uid),
- "jot",
- intval($contact_id),
- dbesc($contact_record['name']),
- dbesc($contact_record['url']),
- dbesc($contact_record['thumb']),
- datetime_convert(),
- datetime_convert(),
- dbesc($hash),
- dbesc(escape_tags(trim($_POST['body']))),
- dbesc($str_contact_allow),
- dbesc($str_group_allow),
- dbesc($str_contact_deny),
- dbesc($str_group_deny)
+ $uri = item_new_uri($a->get_hostname(),$profile_uid);
+
+ $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`, `verb`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`)
+ VALUES( %d, '%s', %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )",
+ intval($profile_uid),
+ dbesc($post_type),
+ intval($wall),
+ intval($gravity),
+ intval($contact_id),
+ dbesc($contact_record['name']),
+ dbesc($contact_record['url']),
+ dbesc($contact_record['thumb']),
+ dbesc($author['name']),
+ dbesc($author['url']),
+ dbesc($author['thumb']),
+ dbesc(datetime_convert()),
+ dbesc(datetime_convert()),
+ dbesc(datetime_convert()),
+ dbesc($uri),
+ dbesc($title),
+ dbesc($body),
+ dbesc($location),
+ dbesc($verb),
+ dbesc($str_contact_allow),
+ dbesc($str_group_allow),
+ dbesc($str_contact_deny),
+ dbesc($str_group_deny)
+ );
+ $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
+ dbesc($uri));
+ if(count($r)) {
+ $post_id = $r[0]['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.
+ // TODO merge with subsequent UPDATE operation and save a db write
+
+ $r = q("UPDATE `item` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s'
+ WHERE `id` = %d LIMIT 1",
+ dbesc($parent_item['allow_cid']),
+ dbesc($parent_item['allow_gid']),
+ dbesc($parent_item['deny_cid']),
+ dbesc($parent_item['deny_gid']),
+ intval($post_id)
+ );
+
+ if(($user['notify-flags'] & NOTIFY_COMMENT) && ($contact_record != $author)) {
+ require_once('bbcode.php');
+ $from = $author['name'];
+ $tpl = file_get_contents('view/cmnt_received_eml.tpl');
+ $email_tpl = replace_macros($tpl, array(
+ '$sitename' => $a->config['sitename'],
+ '$siteurl' => $a->get_baseurl(),
+ '$username' => $user['username'],
+ '$email' => $user['email'],
+ '$from' => $from,
+ '$body' => strip_tags(bbcode($body))
+ ));
+
+ $res = mail($user['email'], $from . t(" commented on your item at ") . $a->config['sitename'],
+ $email_tpl,t("From: Administrator@") . $a->get_hostname() );
+ }
+ }
+ else {
+ $parent = $post_id;
+
+ if(($user['notify-flags'] & NOTIFY_WALL) && ($contact_record != $author)) {
+ require_once('bbcode.php');
+ $from = $author['name'];
+ $tpl = file_get_contents('view/wall_received_eml.tpl');
+ $email_tpl = replace_macros($tpl, array(
+ '$sitename' => $a->config['sitename'],
+ '$siteurl' => $a->get_baseurl(),
+ '$username' => $user['username'],
+ '$email' => $user['email'],
+ '$from' => $from,
+ '$body' => strip_tags(bbcode($body))
+ ));
+
+ $res = mail($user['email'], $from . t(" posted on your profile wall at ") . $a->config['sitename'],
+ $email_tpl,t("From: Administrator@") . $a->get_hostname() );
+ }
+ }