define('FRIENDICA_CODENAME', 'The Tazmans Flax-lily');
define('FRIENDICA_VERSION', '2018.08-dev');
define('DFRN_PROTOCOL_VERSION', '2.23');
-define('DB_UPDATE_VERSION', 1277);
+define('DB_UPDATE_VERSION', 1278);
define('NEW_UPDATE_ROUTINE_VERSION', 1170);
/**
-- ------------------------------------------
-- Friendica 2018.08-dev (The Tazmans Flax-lily)
--- DB_UPDATE_VERSION 1277
+-- DB_UPDATE_VERSION 1278
-- ------------------------------------------
`icid` int unsigned COMMENT 'Id of the item-content table entry that contains the whole item content',
`iaid` int unsigned COMMENT 'Id of the item-activity table entry that contains the activity data',
`extid` varchar(255) NOT NULL DEFAULT '' COMMENT '',
+ `post-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Post type (personal note, bookmark, ...)',
`global` boolean NOT NULL DEFAULT '0' COMMENT '',
`private` boolean NOT NULL DEFAULT '0' COMMENT 'distribution is restricted',
- `bookmark` boolean NOT NULL DEFAULT '0' COMMENT 'item has been bookmarked',
`visible` boolean NOT NULL DEFAULT '0' COMMENT '',
`moderated` boolean NOT NULL DEFAULT '0' COMMENT '',
`deleted` boolean NOT NULL DEFAULT '0' COMMENT 'item has been deleted',
`unseen` boolean NOT NULL DEFAULT '1' COMMENT 'item has not been seen',
`mention` boolean NOT NULL DEFAULT '0' COMMENT 'The owner of this item was mentioned in it',
`forum_mode` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
+ `psid` int unsigned COMMENT 'ID of the permission set of this post',
`allow_cid` mediumtext COMMENT 'Access Control - list of allowed contact.id \'<19><78>\'',
`allow_gid` mediumtext COMMENT 'Access Control - list of allowed groups',
`deny_cid` mediumtext COMMENT 'Access Control - list of denied contact.id',
`resource-id` varchar(32) NOT NULL DEFAULT '' COMMENT 'Used to link other tables to items, it identifies the linked resource (e.g. photo) and if set must also set resource_type',
`event-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Used to link to the event.id',
`attach` mediumtext COMMENT 'JSON structure representing attachments to this item',
- `type` varchar(20) NOT NULL DEFAULT '' COMMENT '',
+ `type` varchar(20) COMMENT 'Deprecated',
+ `bookmark` boolean COMMENT 'Deprecated',
`file` mediumtext COMMENT 'Deprecated',
`location` varchar(255) COMMENT 'Deprecated',
`coord` varchar(255) COMMENT 'Deprecated',
INDEX `uid_wall_changed` (`uid`,`wall`,`changed`),
INDEX `uid_eventid` (`uid`,`event-id`),
INDEX `icid` (`icid`),
- INDEX `iaid` (`iaid`)
+ INDEX `iaid` (`iaid`),
+ INDEX `psid` (`psid`)
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Structure for all posts';
--
UNIQUE INDEX `uid_cat_k` (`uid`,`cat`,`k`)
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='personal (per user) configuration storage';
+--
+-- TABLE permissionset
+--
+CREATE TABLE IF NOT EXISTS `permissionset` (
+ `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
+ `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner id of this permission set',
+ `allow_cid` mediumtext COMMENT 'Access Control - list of allowed contact.id \'<19><78>\'',
+ `allow_gid` mediumtext COMMENT 'Access Control - list of allowed groups',
+ `deny_cid` mediumtext COMMENT 'Access Control - list of denied contact.id',
+ `deny_gid` mediumtext COMMENT 'Access Control - list of denied groups',
+ PRIMARY KEY(`id`),
+ INDEX `uid_allow_cid_allow_gid_deny_cid_deny_gid` (`allow_cid`(50),`allow_gid`(30),`deny_cid`(50),`deny_gid`(30))
+) DEFAULT COLLATE utf8mb4_general_ci COMMENT='';
+
--
-- TABLE photo
--
`visible` boolean NOT NULL DEFAULT '0' COMMENT '',
`starred` boolean NOT NULL DEFAULT '0' COMMENT '',
`ignored` boolean NOT NULL DEFAULT '0' COMMENT '',
- `bookmark` boolean NOT NULL DEFAULT '0' COMMENT '',
+ `post-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Post type (personal note, bookmark, ...)',
`unseen` boolean NOT NULL DEFAULT '1' COMMENT '',
`deleted` boolean NOT NULL DEFAULT '0' COMMENT '',
`origin` boolean NOT NULL DEFAULT '0' COMMENT '',
`forum_mode` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
`mention` boolean NOT NULL DEFAULT '0' COMMENT '',
`network` char(4) NOT NULL DEFAULT '' COMMENT '',
+ `bookmark` boolean COMMENT '',
PRIMARY KEY(`iid`),
INDEX `uid_network_commented` (`uid`,`network`,`commented`),
INDEX `uid_network_created` (`uid`,`network`,`created`),
}
$user_info = api_get_user($a);
- $_REQUEST['type'] = 'wall';
$_REQUEST['profile_uid'] = api_user();
$_REQUEST['api_source'] = true;
$txt = requestdata('status');
}
$_REQUEST['profile_uid'] = api_user();
- if ($parent) {
- $_REQUEST['type'] = 'net-comment';
- } else {
+ if (!$parent) {
// Check for throttling (maximum posts per day, week and month)
$throttle_day = Config::get('system', 'throttle_limit_day');
if ($throttle_day > 0) {
throw new TooManyRequestsException(L10n::t("Monthly posting limit of %d post reached. The post was rejected.", "Monthly posting limit of %d posts reached. The post was rejected.", $throttle_month));
}
}
-
- $_REQUEST['type'] = 'wall';
}
if (x($_FILES, 'media')) {
}
$_REQUEST['body'] = $post;
$_REQUEST['profile_uid'] = api_user();
- $_REQUEST['type'] = 'wall';
$_REQUEST['api_source'] = true;
if (!x($_REQUEST, "source")) {
'$wait' => L10n::t('Please wait'),
'$permset' => L10n::t('Permission settings'),
'$shortpermset' => L10n::t('permissions'),
- '$ptyp' => $notes_cid ? 'note' : 'wall',
+ '$wall' => $notes_cid ? 0 : 1,
+ '$posttype' => $notes_cid ? Item::PT_PERSONAL_NOTE : Item::PT_ARTICLE,
'$content' => defaults($x, 'content', ''),
'$post_id' => defaults($x, 'post_id', ''),
'$baseurl' => System::baseUrl(true),
'$shortnoloc' => L10n::t('clear location'),
'$wait' => L10n::t('Please wait'),
'$permset' => L10n::t('Permission settings'),
- '$ptyp' => $item['type'],
+ '$wall' => $item['wall'],
+ '$posttype' => $item['post-type'],
'$content' => undo_post_tagging($item['body']),
'$post_id' => $post_id,
'$baseurl' => System::baseUrl(),
$objecttype = null;
$profile_uid = defaults($_REQUEST, 'profile_uid', local_user());
+ $posttype = defaults($_REQUEST, 'post_type', Item::PT_ARTICLE);
if ($thr_parent || $thr_parent_uri) {
if ($thr_parent) {
$parent_contact = Contact::getDetailsByURL($parent_item["author-link"]);
$objecttype = ACTIVITY_OBJ_COMMENT;
-
- if (!x($_REQUEST, 'type')) {
- $_REQUEST['type'] = 'net-comment';
- }
}
if ($parent) {
$app = strip_tags(defaults($_REQUEST, 'source', ''));
$extid = strip_tags(defaults($_REQUEST, 'extid', ''));
$object = defaults($_REQUEST, 'object', '');
+ $wall = intval(defaults($_REQUEST, 'wall', 1));
// Ensure that the user id in a thread always stay the same
if (!is_null($parent_user) && in_array($parent_user, [local_user(), 0])) {
$str_contact_deny = $parent_item['deny_cid'];
$str_group_deny = $parent_item['deny_gid'];
$private = $parent_item['private'];
+
+ $wall = $parent_item['wall'];
}
$pubmail_enabled = defaults($_REQUEST, 'pubmail_enable', false) && !$private;
$contact_record = dba::selectFirst('contact', [], ['uid' => $profile_uid, 'self' => true]);
}
- $post_type = notags(trim($_REQUEST['type']));
-
- if ($post_type === 'net-comment' && $parent_item !== null) {
- if ($parent_item['wall'] == 1) {
- $post_type = 'wall-comment';
- } else {
- $post_type = 'remote-comment';
- }
- }
-
// Look for any tags and linkify them
$str_tags = '';
$inform = '';
$contact_id = $private_id;
$contact_record = $forum_contact;
$_REQUEST['origin'] = false;
+ $wall = 0;
}
/*
// embedded bookmark or attachment in post? set bookmark flag
- $bookmark = 0;
$data = BBCode::getAttachmentData($body);
- if (preg_match_all("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism", $body, $match, PREG_SET_ORDER) || isset($data["type"])) {
+ if ((preg_match_all("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism", $body, $match, PREG_SET_ORDER) || isset($data["type"]))
+ && ($posttype != Item::PT_PERSONAL_NOTE)) {
+ $posttype = Item::PT_PAGE;
$objecttype = ACTIVITY_OBJ_BOOKMARK;
- $bookmark = 1;
}
$body = bb_translate_video($body);
}
}
- $wall = 0;
-
- if (($post_type === 'wall' || $post_type === 'wall-comment') && !count($forum_contact)) {
- $wall = 1;
- }
-
if (!strlen($verb)) {
$verb = ACTIVITY_POST;
}
$datarray = [];
$datarray['uid'] = $profile_uid;
- $datarray['type'] = $post_type;
$datarray['wall'] = $wall;
$datarray['gravity'] = $gravity;
$datarray['network'] = $network;
$datarray['file'] = $categories;
$datarray['inform'] = $inform;
$datarray['verb'] = $verb;
+ $datarray['post-type'] = $posttype;
$datarray['object-type'] = $objecttype;
$datarray['allow_cid'] = $str_contact_allow;
$datarray['allow_gid'] = $str_group_allow;
$datarray['private'] = $private;
$datarray['pubmail'] = $pubmail_enabled;
$datarray['attach'] = $attachments;
- $datarray['bookmark'] = intval($bookmark);
// This is not a bug. The item store function changes 'parent-uri' to 'thr-parent' and fetches 'parent-uri' new. (We should change this)
$datarray['parent-uri'] = $thr_parent_uri;
// desired.
$sql_post_table = '';
- $sql_options = (($star) ? " AND `thread`.`starred` " : '');
- $sql_options .= (($bmark) ? " AND `thread`.`bookmark` " : '');
+ $sql_options = ($star ? " AND `thread`.`starred` " : '');
+ $sql_options .= ($bmark ? sprintf(" AND `thread`.`post-type` = %d ", Item::PT_PAGE) : '');
$sql_extra = $sql_options;
$sql_extra2 = '';
$sql_extra3 = '';
$o .= status_editor($a, $x, $a->contact['id']);
}
- $condition = ["`uid` = ? AND `type` = 'note' AND `gravity` = ? AND NOT `wall`
- AND `allow_cid` = ? AND `contact-id` = ?",
- local_user(), GRAVITY_PARENT, '<' . $a->contact['id'] . '>', $a->contact['id']];
+ $condition = ['uid' => local_user(), 'post-type' => Item::PT_PERSONAL_NOTE, 'gravity' => GRAVITY_PARENT,
+ 'wall' => false, 'allow_cid' => '<' . $a->contact['id'] . '>', 'contact-id'=> $a->contact['id']];
- $notes = dba::count('item', $condition);
-
- $a->set_pager_total($notes);
$a->set_pager_itemspage(40);
$params = ['order' => ['created' => true],
}
}
- $o .= paginate($a);
+ $o .= alt_pager($a, count($r));
return $o;
}
function oexchange_content(App $a) {
- if (! local_user()) {
+ if (!local_user()) {
$o = Login::form();
return $o;
}
return;
}
- $url = (((x($_REQUEST,'url')) && strlen($_REQUEST['url']))
+ $url = ((x($_REQUEST,'url') && strlen($_REQUEST['url']))
? urlencode(notags(trim($_REQUEST['url']))) : '');
- $title = (((x($_REQUEST,'title')) && strlen($_REQUEST['title']))
+ $title = ((x($_REQUEST,'title') && strlen($_REQUEST['title']))
? '&title=' . urlencode(notags(trim($_REQUEST['title']))) : '');
- $description = (((x($_REQUEST,'description')) && strlen($_REQUEST['description']))
+ $description = ((x($_REQUEST,'description') && strlen($_REQUEST['description']))
? '&description=' . urlencode(notags(trim($_REQUEST['description']))) : '');
- $tags = (((x($_REQUEST,'tags')) && strlen($_REQUEST['tags']))
+ $tags = ((x($_REQUEST,'tags') && strlen($_REQUEST['tags']))
? '&tags=' . urlencode(notags(trim($_REQUEST['tags']))) : '');
$s = Network::fetchUrl(System::baseUrl() . '/parse_url?f=&url=' . $url . $title . $description . $tags);
- if (! strlen($s)) {
+ if (!strlen($s)) {
return;
}
$post = [];
$post['profile_uid'] = local_user();
- $post['return'] = '/oexchange/done' ;
+ $post['return'] = '/oexchange/done';
$post['body'] = Friendica\Content\Text\HTML::toBBCode($s);
- $post['type'] = 'wall';
$_REQUEST = $post;
require_once('mod/item.php');
$arr['uid'] = $page_owner_uid;
$arr['uri'] = $uri;
$arr['parent-uri'] = $uri;
- $arr['type'] = 'photo';
+ $arr['post-type'] = Item::PT_IMAGE;
$arr['wall'] = 1;
$arr['resource-id'] = $p[0]['resource-id'];
$arr['contact-id'] = $owner_record['id'];
$arr['uid'] = $page_owner_uid;
$arr['uri'] = $uri;
$arr['parent-uri'] = $uri;
- $arr['type'] = 'activity';
$arr['wall'] = 1;
$arr['contact-id'] = $owner_record['id'];
$arr['owner-name'] = $owner_record['name'];
$comments .= replace_macros($cmnt_tpl, [
'$return_path' => '',
'$jsreload' => $return_url,
- '$type' => 'wall-comment',
'$id' => $link_item['id'],
'$parent' => $link_item['id'],
'$profile_uid' => $owner_uid,
$comments .= replace_macros($cmnt_tpl,[
'$return_path' => '',
'$jsreload' => $return_url,
- '$type' => 'wall-comment',
'$id' => $link_item['id'],
'$parent' => $link_item['id'],
'$profile_uid' => $owner_uid,
$comments .= replace_macros($cmnt_tpl, [
'$return_path' => '',
'$jsreload' => $return_url,
- '$type' => 'wall-comment',
'$id' => $item['item_id'],
'$parent' => $item['parent'],
'$profile_uid' => $owner_uid,
$arr['uid'] = $uid;
$arr['uri'] = $uri;
$arr['parent-uri'] = ($parent_uri ? $parent_uri : $uri);
- $arr['type'] = 'activity';
$arr['wall'] = 1;
$arr['contact-id'] = $poster['id'];
$arr['owner-name'] = $poster['name'];
$arr['uri'] = $uri;
$arr['uid'] = $owner_uid;
$arr['contact-id'] = $contact['id'];
- $arr['type'] = 'activity';
$arr['wall'] = $item['wall'];
$arr['origin'] = 1;
$arr['gravity'] = GRAVITY_ACTIVITY;
$arr['uri'] = $uri;
$arr['uid'] = $owner_uid;
$arr['contact-id'] = $contact['id'];
- $arr['type'] = 'activity';
$arr['wall'] = $item['wall'];
$arr['gravity'] = GRAVITY_COMMENT;
$arr['parent'] = $item['id'];
"icid" => ["type" => "int unsigned", "relation" => ["item-content" => "id"], "comment" => "Id of the item-content table entry that contains the whole item content"],
"iaid" => ["type" => "int unsigned", "relation" => ["item-activity" => "id"], "comment" => "Id of the item-activity table entry that contains the activity data"],
"extid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+ "post-type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "Post type (personal note, bookmark, ...)"],
"global" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
"private" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "distribution is restricted"],
- "bookmark" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "item has been bookmarked"],
"visible" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
"moderated" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
"deleted" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "item has been deleted"],
"unseen" => ["type" => "boolean", "not null" => "1", "default" => "1", "comment" => "item has not been seen"],
"mention" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "The owner of this item was mentioned in it"],
"forum_mode" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
- // User specific fields. Should possible be replaced with something different
+ "psid" => ["type" => "int unsigned", "relation" => ["permissionset" => "id"], "comment" => "ID of the permission set of this post"],
+ // These fields will be replaced by the "psid" from above
"allow_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed contact.id '<19><78>'"],
"allow_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed groups"],
"deny_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied contact.id"],
"deny_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied groups"],
+ // These fields will be moved into some item-delivery-information table
"postopts" => ["type" => "text", "comment" => "External post connectors add their network name to this comma-separated string to identify that they should be delivered to these networks during delivery"],
"inform" => ["type" => "mediumtext", "comment" => "Additional receivers of this post"],
// It is to be decided whether these fields belong to the user or the structure
"resource-id" => ["type" => "varchar(32)", "not null" => "1", "default" => "", "comment" => "Used to link other tables to items, it identifies the linked resource (e.g. photo) and if set must also set resource_type"],
"event-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["event" => "id"], "comment" => "Used to link to the event.id"],
- // Will be replaced by the "attach" table
+ // Could possibly be replaced by the "attach" table?
"attach" => ["type" => "mediumtext", "comment" => "JSON structure representing attachments to this item"],
- // Seems to be only used for notes, but is filled at many places.
- // Will be replaced with some general field that contain the values of "origin" and "wall" as well.
- "type" => ["type" => "varchar(20)", "not null" => "1", "default" => "", "comment" => ""],
// Deprecated fields. Will be removed in upcoming versions
+ "type" => ["type" => "varchar(20)", "comment" => "Deprecated"],
+ "bookmark" => ["type" => "boolean", "comment" => "Deprecated"],
"file" => ["type" => "mediumtext", "comment" => "Deprecated"],
"location" => ["type" => "varchar(255)", "comment" => "Deprecated"],
"coord" => ["type" => "varchar(255)", "comment" => "Deprecated"],
"uid_eventid" => ["uid","event-id"],
"icid" => ["icid"],
"iaid" => ["iaid"],
+ "psid" => ["psid"],
]
];
$database["item-activity"] = [
"uid_cat_k" => ["UNIQUE", "uid", "cat", "k"],
]
];
+ $database["permissionset"] = [
+ "comment" => "",
+ "fields" => [
+ "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
+ "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner id of this permission set"],
+ "allow_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed contact.id '<19><78>'"],
+ "allow_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed groups"],
+ "deny_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied contact.id"],
+ "deny_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied groups"],
+ ],
+ "indexes" => [
+ "PRIMARY" => ["id"],
+ "uid_allow_cid_allow_gid_deny_cid_deny_gid" => ["allow_cid(50)", "allow_gid(30)", "deny_cid(50)", "deny_gid(30)"],
+ ]
+ ];
$database["photo"] = [
"comment" => "photo storage",
"fields" => [
"visible" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
"starred" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
"ignored" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
- "bookmark" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+ "post-type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "Post type (personal note, bookmark, ...)"],
"unseen" => ["type" => "boolean", "not null" => "1", "default" => "1", "comment" => ""],
"deleted" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
"origin" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
"forum_mode" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
"mention" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
"network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => ""],
+ "bookmark" => ["type" => "boolean", "comment" => ""],
],
"indexes" => [
"PRIMARY" => ["iid"],
use Friendica\Database\DBM;
use Friendica\Model\Contact;
use Friendica\Model\Item;
+use Friendica\Model\PermissionSet;
use dba;
require_once 'include/dba.php';
if (!self::update1206()) {
return;
}
- if (!self::update1276()) {
+ if (!self::update1278()) {
return;
}
}
*
* @return bool "true" when the job is done
*/
- private static function update1276()
+ private static function update1278()
{
// Was the script completed?
- if (Config::get("system", "post_update_version") >= 1276) {
+ if (Config::get("system", "post_update_version") >= 1278) {
return true;
}
- $id = Config::get("system", "post_update_version_1276_id", 0);
+ $id = Config::get("system", "post_update_version_1278_id", 0);
logger("Start from item " . $id, LOGGER_DEBUG);
$fields = array_merge(Item::MIXED_CONTENT_FIELDLIST, ['network', 'author-id', 'owner-id', 'tag', 'file',
- 'author-name', 'author-avatar', 'author-link', 'owner-name', 'owner-avatar', 'owner-link', 'id']);
+ 'author-name', 'author-avatar', 'author-link', 'owner-name', 'owner-avatar', 'owner-link', 'id',
+ 'uid', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'psid', 'post-type', 'bookmark', 'type']);
$start_id = $id;
$rows = 0;
$item['owner-id'] = Contact::getIdForURL($item["owner-link"], 0, false, $default);
}
+ if (empty($item['psid'])) {
+ $item['psid'] = PermissionSet::fetchIDForPost($item);
+ }
+
+ if ($item['post-type'] == 0) {
+ if (!empty($item['type']) && ($item['type'] == 'note')) {
+ $item['post-type'] = Item::PT_PERSONAL_NOTE;
+ } elseif (!empty($item['type']) && ($item['type'] == 'photo')) {
+ $item['post-type'] = Item::PT_IMAGE;
+ } elseif (!empty($item['bookmark']) && $item['bookmark']) {
+ $item['post-type'] = Item::PT_PAGE;
+ }
+ }
+
Item::update($item, ['id' => $id]);
++$rows;
}
dba::close($items);
- Config::set("system", "post_update_version_1276_id", $id);
+ Config::set("system", "post_update_version_1278_id", $id);
logger("Processed rows: " . $rows . " - last processed item: " . $id, LOGGER_DEBUG);
if ($start_id == $id) {
- Config::set("system", "post_update_version", 1276);
+ Config::set("system", "post_update_version", 1278);
logger("Done", LOGGER_DEBUG);
return true;
}
$item_arr['uri'] = $event['uri'];
$item_arr['parent-uri'] = $event['uri'];
$item_arr['guid'] = $event['guid'];
- $item_arr['type'] = 'activity';
+ $item_arr['post-type'] = Item::PT_EVENT;
$item_arr['wall'] = $event['cid'] ? 0 : 1;
$item_arr['contact-id'] = $contact['id'];
$item_arr['owner-name'] = $contact['name'];
use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\DBM;
+use Friendica\Model\PermissionSet;
use Friendica\Object\Image;
use Friendica\Protocol\Diaspora;
use Friendica\Protocol\OStatus;
class Item extends BaseObject
{
+ // Posting types, inspired by https://www.w3.org/TR/activitystreams-vocabulary/#object-types
+ const PT_ARTICLE = 0;
+ const PT_NOTE = 1;
+ const PT_PAGE = 2;
+ const PT_IMAGE = 16;
+ const PT_AUDIO = 17;
+ const PT_VIDEO = 18;
+ const PT_DOCUMENT = 19;
+ const PT_EVENT = 32;
+ const PT_PERSONAL_NOTE = 128;
+
// Field list that is used to display the items
const DISPLAY_FIELDLIST = ['uid', 'id', 'parent', 'uri', 'thr-parent', 'parent-uri', 'guid', 'network',
'commented', 'created', 'edited', 'received', 'verb', 'object-type', 'postopts', 'plink',
const DELIVER_FIELDLIST = ['uid', 'id', 'parent', 'uri', 'thr-parent', 'parent-uri', 'guid',
'created', 'edited', 'verb', 'object-type', 'object', 'target',
'private', 'title', 'body', 'location', 'coord', 'app',
- 'attach', 'tag', 'bookmark', 'deleted', 'extid',
+ 'attach', 'tag', 'deleted', 'extid', 'post-type',
'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
'author-id', 'author-link', 'owner-link', 'contact-uid',
'signed_text', 'signature', 'signer', 'network'];
// All fields in the item table
const ITEM_FIELDLIST = ['id', 'uid', 'parent', 'uri', 'parent-uri', 'thr-parent', 'guid',
- 'contact-id', 'type', 'wall', 'gravity', 'extid', 'icid', 'iaid',
+ 'contact-id', 'type', 'wall', 'gravity', 'extid', 'icid', 'iaid', 'psid',
'created', 'edited', 'commented', 'received', 'changed', 'verb',
'postopts', 'plink', 'resource-id', 'event-id', 'tag', 'attach', 'inform',
- 'file', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
+ 'file', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'post-type',
'private', 'pubmail', 'moderated', 'visible', 'starred', 'bookmark',
'unseen', 'deleted', 'origin', 'forum_mode', 'mention', 'global', 'network',
'title', 'content-warning', 'body', 'location', 'coord', 'app',
$threadfields = ['thread' => ['iid', 'uid', 'contact-id', 'owner-id', 'author-id',
'created', 'edited', 'commented', 'received', 'changed', 'wall', 'private',
- 'pubmail', 'moderated', 'visible', 'starred', 'ignored', 'bookmark',
+ 'pubmail', 'moderated', 'visible', 'starred', 'ignored', 'post-type',
'unseen', 'deleted', 'origin', 'forum_mode', 'mention', 'network']];
$select_fields = self::constructSelectFields($fields, $selected);
$fields['item'] = ['id', 'uid', 'parent', 'uri', 'parent-uri', 'thr-parent', 'guid',
'contact-id', 'owner-id', 'author-id', 'type', 'wall', 'gravity', 'extid',
'created', 'edited', 'commented', 'received', 'changed', 'postopts',
- 'resource-id', 'event-id', 'tag', 'attach', 'inform',
- 'file', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
+ 'resource-id', 'event-id', 'tag', 'attach', 'inform', 'post-type',
+ 'file', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'psid',
'private', 'pubmail', 'moderated', 'visible', 'starred', 'bookmark',
'unseen', 'deleted', 'origin', 'forum_mode', 'mention', 'global',
'id' => 'item_id', 'network', 'icid', 'iaid', 'id' => 'internal-iid',
}
}
- $author_owner_fields = ['author-name', 'author-avatar', 'author-link', 'owner-name', 'owner-avatar', 'owner-link'];
- foreach ($author_owner_fields as $field) {
+ $clear_fields = ['bookmark', 'type', 'author-name', 'author-avatar', 'author-link', 'owner-name', 'owner-avatar', 'owner-link'];
+ foreach ($clear_fields as $field) {
if (array_key_exists($field, $fields)) {
$fields[$field] = null;
}
// If it is a posting where users should get notifications, then define it as wall posting
if ($notify) {
$item['wall'] = 1;
- $item['type'] = 'wall';
$item['origin'] = 1;
$item['network'] = NETWORK_DFRN;
$item['protocol'] = PROTOCOL_DFRN;
$item['parent-uri'] = $item['thr-parent'];
}
- $item['type'] = defaults($item, 'type', 'remote');
-
if (isset($item['gravity'])) {
$item['gravity'] = intval($item['gravity']);
} elseif ($item['parent-uri'] === $item['uri']) {
$item['gravity'] = GRAVITY_PARENT;
} elseif (activity_match($item['verb'], ACTIVITY_POST)) {
$item['gravity'] = GRAVITY_COMMENT;
- } elseif ($item['type'] == 'activity') {
- $item['gravity'] = GRAVITY_ACTIVITY;
} else {
$item['gravity'] = GRAVITY_UNKNOWN; // Should not happen
- logger('Unknown gravity for verb: ' . $item['verb'] . ' - type: ' . $item['type'], LOGGER_DEBUG);
+ logger('Unknown gravity for verb: ' . $item['verb'], LOGGER_DEBUG);
}
$uid = intval($item['uid']);
$item['visible'] = ((x($item, 'visible') !== false) ? intval($item['visible']) : 1);
$item['deleted'] = 0;
$item['parent-uri'] = trim(defaults($item, 'parent-uri', $item['uri']));
+ $item['post-type'] = defaults($item, 'post-type', self::PT_ARTICLE);
$item['verb'] = trim(defaults($item, 'verb', ''));
$item['object-type'] = trim(defaults($item, 'object-type', ''));
$item['object'] = trim(defaults($item, 'object', ''));
$item['deny_cid'] = trim(defaults($item, 'deny_cid', ''));
$item['deny_gid'] = trim(defaults($item, 'deny_gid', ''));
$item['private'] = intval(defaults($item, 'private', 0));
- $item['bookmark'] = intval(defaults($item, 'bookmark', 0));
$item['body'] = trim(defaults($item, 'body', ''));
$item['tag'] = trim(defaults($item, 'tag', ''));
$item['attach'] = trim(defaults($item, 'attach', ''));
$files = '';
}
+ // Creates the permission set
+ // Currently we only store the data but don't using it
+ $item['psid'] = PermissionSet::fetchIDForPost($item);
+
// We are doing this outside of the transaction to avoid timing problems
if (!self::insertActivity($item)) {
self::insertContent($item);
$item['contact-id'] = $self['id'];
}
- if (in_array($item['type'], ["net-comment", "wall-comment"])) {
- $item['type'] = 'remote-comment';
- } elseif ($item['type'] == 'wall') {
- $item['type'] = 'remote';
- }
-
/// @todo Handling of "event-id"
$notify = false;
$item['contact-id'] = $item['author-id'];
}
- if (in_array($item['type'], ["net-comment", "wall-comment"])) {
- $item['type'] = 'remote-comment';
- } elseif ($item['type'] == 'wall') {
- $item['type'] = 'remote';
- }
-
$public_shadow = self::insert($item, false, false, true);
logger("Stored public shadow for thread ".$itemid." under id ".$public_shadow, LOGGER_DEBUG);
unset($item['starred']);
$item['contact-id'] = Contact::getIdForURL($item['author-link']);
- if (in_array($item['type'], ["net-comment", "wall-comment"])) {
- $item['type'] = 'remote-comment';
- } elseif ($item['type'] == 'wall') {
- $item['type'] = 'remote';
- }
-
$public_shadow = self::insert($item, false, false, true);
logger("Stored public shadow for comment ".$item['uri']." under id ".$public_shadow, LOGGER_DEBUG);
'uri' => self::newURI($item['uid']),
'uid' => $item['uid'],
'contact-id' => $item_contact_id,
- 'type' => 'activity',
'wall' => $item['wall'],
'origin' => 1,
'network' => NETWORK_DFRN,
private static function addThread($itemid, $onlyshadow = false)
{
$fields = ['uid', 'created', 'edited', 'commented', 'received', 'changed', 'wall', 'private', 'pubmail',
- 'moderated', 'visible', 'starred', 'bookmark', 'contact-id',
+ 'moderated', 'visible', 'starred', 'contact-id', 'post-type',
'deleted', 'origin', 'forum_mode', 'mention', 'network', 'author-id', 'owner-id'];
$condition = ["`id` = ? AND (`parent` = ? OR `parent` = 0)", $itemid, $itemid];
$item = self::selectFirst($fields, $condition);
private static function updateThread($itemid, $setmention = false)
{
- $fields = ['uid', 'guid', 'created', 'edited', 'commented', 'received', 'changed',
- 'wall', 'private', 'pubmail', 'moderated', 'visible', 'starred', 'bookmark', 'contact-id',
+ $fields = ['uid', 'guid', 'created', 'edited', 'commented', 'received', 'changed', 'post-type',
+ 'wall', 'private', 'pubmail', 'moderated', 'visible', 'starred', 'contact-id',
'deleted', 'origin', 'forum_mode', 'network', 'author-id', 'owner-id'];
$condition = ["`id` = ? AND (`parent` = ? OR `parent` = 0)", $itemid, $itemid];
--- /dev/null
+<?php
+/**
+ * @file src/Model/PermissionSet.php
+ */
+namespace Friendica\Model;
+
+use Friendica\BaseObject;
+use Friendica\Database\DBM;
+use dba;
+
+require_once 'include/dba.php';
+
+/**
+ * @brief functions for interacting with the permission set of an object (item, photo, event, ...)
+ */
+class PermissionSet extends BaseObject
+{
+ /**
+ * Fetch the id of a given permission set. Generate a new one when needed
+ *
+ * @param array $postarray The array from an item, picture or event post
+ * @return id
+ */
+ public static function fetchIDForPost($postarray)
+ {
+ $condition = ['uid' => $postarray['uid'],
+ 'allow_cid' => self::sortPermissions($postarray['allow_cid']),
+ 'allow_gid' => self::sortPermissions($postarray['allow_gid']),
+ 'deny_cid' => self::sortPermissions($postarray['deny_cid']),
+ 'deny_gid' => self::sortPermissions($postarray['deny_gid'])];
+
+ $set = dba::selectFirst('permissionset', ['id'], $condition);
+
+ if (!DBM::is_result($set)) {
+ dba::insert('permissionset', $condition, true);
+
+ $set = dba::selectFirst('permissionset', ['id'], $condition);
+ }
+ return $set['id'];
+ }
+
+ private static function sortPermissions($permissionlist)
+ {
+ $cleaned_list = trim($permissionlist, '<>');
+
+ if (empty($cleaned_list)) {
+ return $permissionlist;
+ }
+
+ $elements = explode('><', $cleaned_list);
+
+ if (count($elements) <= 1) {
+ return $permissionlist;
+ }
+
+ asort($elements);
+
+ return '<' . implode('><', $elements) . '>';
+ }
+}
'$return_path' => $a->query_string,
'$threaded' => $this->isThreaded(),
'$jsreload' => '',
- '$type' => $conv->getMode() === 'profile' ? 'wall-comment' : 'net-comment',
+ '$wall' => ($conv->getMode() === 'profile'),
'$id' => $this->getId(),
'$parent' => $this->getId(),
'$qcomment' => $qcomment,
XML::addElement($doc, $entry, "dfrn:extid", $item['extid']);
}
- if ($item['bookmark']) {
+ if ($item['post-type'] == Item::PT_PAGE) {
XML::addElement($doc, $entry, "dfrn:bookmark", "true");
}
|| ($item["verb"] == ACTIVITY_ATTENDMAYBE)
) {
$is_like = true;
- $item["type"] = "activity";
$item["gravity"] = GRAVITY_ACTIVITY;
// only one like or dislike per person
// splitted into two queries for performance issues
$item["extid"] = XML::getFirstNodeValue($xpath, "dfrn:extid/text()", $entry);
if (XML::getFirstNodeValue($xpath, "dfrn:bookmark/text()", $entry) == "true") {
- $item["bookmark"] = true;
+ $item["post-type"] = Item::PT_PAGE;
}
$notice_info = $xpath->query("statusnet:notice_info", $entry);
}
if ($entrytype == DFRN::REPLY_RC) {
- $item["type"] = "remote-comment";
$item["wall"] = 1;
} elseif ($entrytype == DFRN::TOP_LEVEL) {
if (!isset($item["object-type"])) {
$header = [];
$header["uid"] = $importer["importer_uid"];
$header["network"] = NETWORK_DFRN;
- $header["type"] = "remote";
$header["wall"] = 0;
$header["origin"] = 0;
$header["contact-id"] = $importer["id"];
$datarray["guid"] = $guid;
$datarray["uri"] = self::getUriFromGuid($author, $guid);
- $datarray["type"] = "remote-comment";
$datarray["verb"] = ACTIVITY_POST;
$datarray["gravity"] = GRAVITY_COMMENT;
$datarray["guid"] = $guid;
$datarray["uri"] = self::getUriFromGuid($author, $guid);
- $datarray["type"] = "activity";
$datarray["verb"] = $verb;
$datarray["gravity"] = GRAVITY_ACTIVITY;
$datarray["parent-uri"] = $parent_item["uri"];
$header = [];
$header["uid"] = $importer["uid"];
$header["network"] = NETWORK_FEED;
- $header["type"] = "remote";
$header["wall"] = 0;
$header["origin"] = 0;
$header["gravity"] = GRAVITY_PARENT;
$header = [];
$header["uid"] = $importer["uid"];
$header["network"] = NETWORK_OSTATUS;
- $header["type"] = "remote-comment";
$header["wall"] = 0;
$header["origin"] = 0;
$header["gravity"] = GRAVITY_COMMENT;
$orig_uri = $xpath->query("activity:object/atom:id", $entry)->item(0)->nodeValue;
logger("Favorite ".$orig_uri." ".print_r($item, true));
- $item["type"] = "activity";
$item["verb"] = ACTIVITY_LIKE;
$item["parent-uri"] = $orig_uri;
$item["gravity"] = GRAVITY_ACTIVITY;
} else {
$item["parent-uri"] = $item["uri"];
$item["gravity"] = GRAVITY_PARENT;
- $item["type"] = "remote";
}
if (($item['author-link'] != '') && !empty($item['protocol'])) {
logger('Delete expired items', LOGGER_DEBUG);
// physically remove anything that has been deleted for more than two months
$condition = ["`deleted` AND `changed` < UTC_TIMESTAMP() - INTERVAL 60 DAY"];
- $rows = dba::select('item', ['id', 'iaid', 'icid'], $condition);
+ $rows = dba::select('item', ['id', 'iaid', 'icid', 'psid'], $condition);
while ($row = dba::fetch($rows)) {
dba::delete('item', ['id' => $row['id']]);
if (!empty($row['iaid']) && !dba::exists('item', ['iaid' => $row['iaid']])) {
if (!empty($row['icid']) && !dba::exists('item', ['icid' => $row['icid']])) {
dba::delete('item-content', ['id' => $row['icid']]);
}
+ // When the permission set will be used in photo and events as well.
+ // this query here needs to be extended.
+ if (!empty($row['psid']) && !dba::exists('item', ['psid' => $row['psid']])) {
+ dba::delete('permissionset', ['id' => $row['psid']]);
+ }
}
dba::close($rows);
}
function update_1191() {
-
Config::set('system', 'maintenance', 1);
if (Addon::isEnabled('forumlist')) {
Config::set('system', 'maintenance', 0);
return UPDATE_SUCCESS;
-
}
function update_1203() {
dba::update('contact', ['blocked' => false, 'pending' => false], ['uid' => 0, 'blocked' => true, 'pending' => true]);
return UPDATE_SUCCESS;
}
+
+function update_1278() {
+ Config::set('system', 'maintenance', 1);
+ Config::set('system', 'maintenance_reason', L10n::t('%s: Updating post-type.', DBM::date().' '.date('e')));
+
+ Item::update(['post-type' => Item::PT_PAGE], ['bookmark' => true]);
+ Item::update(['post-type' => Item::PT_PERSONAL_NOTE], ['type' => 'note']);
+
+ Config::set('system', 'maintenance', 0);
+
+ return UPDATE_SUCCESS;
+}
-
-
<div id="profile-jot-wrapper" >
<div id="profile-jot-banner-wrapper">
<div id="profile-jot-desc" > </div>
<div id="profile-jot-banner-end"></div>
<form id="profile-jot-form" action="{{$action}}" method="post" >
- <input type="hidden" name="type" value="{{$ptyp}}" />
+ <input type="hidden" name="wall" value="{{$wall}}" />
+ <input type="hidden" name="post_type" value="{{$posttype}}" />
<input type="hidden" name="profile_uid" value="{{$profile_uid}}" />
<input type="hidden" name="return" value="{{$return_path|escape:'html'}}" />
<input type="hidden" name="location" id="jot-location" value="{{$defloc|escape:'html'}}" />
<div id="profile-jot-plugin-wrapper">
- {{$jotplugins}}
+ {{$jotplugins}}
</div>
<div id="profile-rotator-wrapper" style="display: {{$visitor}};" >
-
{{* The button to open the jot - in This theme we move the button with js to the second nav bar *}}
<button class="btn btn-sm btn-main pull-right" id="jotOpen" aria-label="{{$new_post}}" title="{{$new_post}}" onclick="jotShow();"><i class="fa fa-pencil-square-o fa-2x"></i></button>
<div id="profile-jot-banner-end"></div>
{{* The hidden input fields which submit important values with the post *}}
- <input type="hidden" name="type" value="{{$ptyp}}" />
+ <input type="hidden" name="jot" value="{{$jot}}" />
+ <input type="hidden" name="post_type" value="{{$posttype}}" />
<input type="hidden" name="profile_uid" value="{{$profile_uid}}" />
<input type="hidden" name="return" value="{{$return_path}}" />
<input type="hidden" name="location" id="jot-location" value="{{$defloc}}" />
- <input type="hidden" name="type" value="{{$ptyp}}" />
+ <input type="hidden" name="wall" value="{{$wall}}" />
+ <input type="hidden" name="post_type" value="{{$posttype}}" />
<input type="hidden" name="profile_uid" value="{{$profile_uid}}" />
<input type="hidden" name="return" value="{{$return_path}}" />
<input type="hidden" name="location" id="jot-location" value="{{$defloc}}" />
-
-
<div id="profile-jot-wrapper" >
<div id="profile-jot-banner-wrapper">
<div id="profile-jot-desc" > </div>
<div id="profile-jot-banner-end"></div>
<form id="profile-jot-form" action="{{$action}}" method="post" >
- <input type="hidden" name="type" value="{{$ptyp}}" />
+ <input type="hidden" name="wall" value="{{$wall}}" />
+ <input type="hidden" name="post_type" value="{{$posttype}}" />
<input type="hidden" name="profile_uid" value="{{$profile_uid}}" />
<input type="hidden" name="return" value="{{$return_path}}" />
<input type="hidden" name="location" id="jot-location" value="{{$defloc}}" />
</div>
{{/if}}
<div id="jot-text-wrap">
- <img id="profile-jot-text-loading" src="images/rotator.gif" alt="{{$wait}}" title="{{$wait}}" style="display: none;" /><br>
- <textarea rows="5" cols="80" class="profile-jot-text" id="profile-jot-text" name="body" placeholder="{{$share}}">
+ <img id="profile-jot-text-loading" src="images/rotator.gif" alt="{{$wait}}" title="{{$wait}}" style="display: none;" /><br>
+ <textarea rows="5" cols="80" class="profile-jot-text" id="profile-jot-text" name="body" placeholder="{{$share}}">
{{if $content}}{{$content}}{{/if}}
</textarea>
</div>
</div>
<div id="profile-jot-plugin-wrapper" style="display: none;">
- {{$jotplugins}}
+ {{$jotplugins}}
</div>
<div id="profile-jot-tools-end"></div>