]> git.mxchange.org Git - friendica.git/blob - mod/item.php
facebook style comments
[friendica.git] / mod / item.php
1 <?php
2
3
4 function item_post(&$a) {
5
6         if((! local_user()) && (! remote_user()))
7                 return;
8
9         require_once('include/security.php');
10
11         $uid = $_SESSION['uid'];
12         $parent = ((x($_POST,'parent')) ? intval($_POST['parent']) : 0);
13         $profile_uid = ((x($_POST,'profile_uid')) ? intval($_POST['profile_uid']) : 0);
14         if(! can_write_wall($a,$profile_uid)) {
15                 notice("Permission denied." . EOL) ;
16                 return;
17         }
18
19         if((x($_SESSION,'visitor_id')) && (intval($_SESSION['visitor_id'])))
20                 $contact_id = $_SESSION['visitor_id'];
21         else {
22                 $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
23                         intval($_SESSION['uid']));
24                 if(count($r))
25                         $contact_id = $r[0]['id'];
26         }       
27
28         $notify_type = (($parent) ? 'comment-new' : 'wall-new' );
29
30         if($_POST['type'] == 'jot') {
31
32                 do {
33                         $dups = false;
34                         $hash = random_string();
35                         $r = q("SELECT `id` FROM `item` WHERE `hash` = '%s' LIMIT 1",
36                         dbesc($hash));
37                         if(count($r))
38                                 $dups = true;
39                 } while($dups == true);
40
41
42                 $r = q("INSERT INTO `item` (`uid`,`type`,`contact-id`,`created`,`edited`,`hash`,`body`)
43                         VALUES( %d, '%s', %d, '%s', '%s', '%s', '%s' )",
44                         intval($profile_uid),
45                         "jot",
46                         intval($contact_id),
47                         datetime_convert(),
48                         datetime_convert(),
49                         dbesc($hash),
50                         dbesc(escape_tags(trim($_POST['body'])))
51                 );
52                 $r = q("SELECT `id` FROM `item` WHERE `hash` = '%s' LIMIT 1",
53                         dbesc($hash));
54                 if(count($r)) {
55                         $post_id = $r[0]['id'];
56                         if(! $parent)
57                                 $parent = $post_id;
58                         $r = q("UPDATE `item` SET `parent` = %d, `visible` = 1
59                                 WHERE `id` = %d LIMIT 1",
60                                 intval($parent),
61                                 intval($post_id));
62                 }
63
64                 $url = bin2hex($a->get_baseurl());
65
66                 proc_close(proc_open("php include/notifier.php $url $notify_type $post_id > notify.log &",
67                         array(),$foo));
68
69         }
70         goaway($a->get_baseurl() . "/profile/$profile_uid");
71
72
73
74
75
76
77
78 }