]> git.mxchange.org Git - friendica.git/blob - mod/item.php
588dd9a9d3f48a3f2a579d43a56ab42f3c714960
[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                 $_SESSION['sysmsg'] .= "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                 $r = q("INSERT INTO `item` (`uid`,`type`,`contact-id`,`created`,`edited`,`hash`,`body`)
39                         VALUES( %d, '%s', %d, '%s', '%s', '%s', '%s' )",
40                         intval($profile_uid),
41                         "jot",
42                         intval($contact_id),
43                         datetime_convert(),
44                         datetime_convert(),
45                         dbesc($hash),
46                         dbesc(escape_tags(trim($_POST['body'])))
47                 );
48                 $r = q("SELECT `id` FROM `item` WHERE `hash` = '%s' LIMIT 1",
49                         dbesc($hash));
50                 if(count($r)) {
51                         $post_id = $r[0]['id'];
52                         if(! $parent)
53                                 $parent = $post_id;
54                         $r = q("UPDATE `item` SET `parent` = %d, `visible` = 1
55                                 WHERE `id` = %d LIMIT 1",
56                                 intval($parent),
57                                 intval($post_id));
58                 }
59         }
60         goaway($a->get_baseurl() . "/profile/$uid");
61
62
63
64
65
66
67
68 }