]> git.mxchange.org Git - friendica.git/blob - mod/item.php
2b03ecaa2f8c28bd9f6d88e563dca68df6c79938
[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         if($_POST['type'] == 'jot') {
28
29                 do {
30                         $dups = false;
31                         $hash = random_string();
32                         $r = q("SELECT `id` FROM `item` WHERE `hash` = '%s' LIMIT 1",
33                         dbesc($hash));
34                         if(count($r))
35                                 $dups = true;
36                 } while($dups == true);
37
38
39                 $r = q("INSERT INTO `item` (`uid`,`type`,`contact-id`,`created`,`edited`,`hash`,`body`)
40                         VALUES( %d, '%s', %d, '%s', '%s', '%s', '%s' )",
41                         intval($profile_uid),
42                         "jot",
43                         intval($contact_id),
44                         datetime_convert(),
45                         datetime_convert(),
46                         dbesc($hash),
47                         dbesc(escape_tags(trim($_POST['body'])))
48                 );
49                 $r = q("SELECT `id` FROM `item` WHERE `hash` = '%s' LIMIT 1",
50                         dbesc($hash));
51                 if(count($r)) {
52                         $post_id = $r[0]['id'];
53                         if(! $parent)
54                                 $parent = $post_id;
55                         $r = q("UPDATE `item` SET `parent` = %d, `visible` = 1
56                                 WHERE `id` = %d LIMIT 1",
57                                 intval($parent),
58                                 intval($post_id));
59                 }
60
61 //              require('notifier.php');
62
63
64 //              notifier($a,$post_id,$parent);
65
66         }
67         goaway($a->get_baseurl() . "/profile/$profile_uid");
68
69
70
71
72
73
74
75 }