aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/attach.php192
-rw-r--r--install/schema_mysql.sql2
-rw-r--r--install/schema_postgres.sql2
-rw-r--r--mod/dirsearch.php5
-rw-r--r--mod/filestorage.php3
-rw-r--r--mod/sharedwithme.php39
-rw-r--r--mod/sitelist.php3
7 files changed, 115 insertions, 131 deletions
diff --git a/include/attach.php b/include/attach.php
index c66ba40d5..9c71beb23 100644
--- a/include/attach.php
+++ b/include/attach.php
@@ -779,10 +779,12 @@ function attach_delete($channel_id, $resource) {
intval($channel_id)
);
-
if(! $r)
return;
+ $cloudpath = get_parent_cloudpath($channel_id, $channel_address, $resource);
+ $object = get_file_activity_object($channel_id, $resource, $cloudpath);
+
// If resource is a directory delete everything in the directory recursive
if($r[0]['flags'] & ATTACH_FLAG_DIR) {
$x = q("SELECT hash, flags FROM attach WHERE folder = '%s' AND uid = %d",
@@ -825,7 +827,8 @@ function attach_delete($channel_id, $resource) {
intval($channel_id)
);
- file_activity($channel_id, $resource, $cloudpath='', $allow_cid='', $allow_gid='', $deny_cid='', $deny_gid='', 'drop', $no_activity=false);
+ file_activity($channel_id, $object, $allow_cid='', $allow_gid='', $deny_cid='', $deny_gid='', 'update', $no_activity=false);
+
}
/**
@@ -961,118 +964,75 @@ function pipe_streams($in, $out) {
return $size;
}
-function file_activity($channel_id, $hash, $cloudpath, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $verb, $no_activity) {
+function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $verb, $no_activity) {
require_once('include/items.php');
$poster = get_app()->get_observer();
- switch($verb) {
- case 'post':
- $activity = ACTIVITY_POST;
- $x = q("SELECT creator, filename, filetype, filesize, revision, folder, flags, created, edited FROM attach WHERE uid = %d AND hash = '%s' LIMIT 1",
- intval($channel_id),
- dbesc($hash)
- );
- break;
- case 'drop':
- $activity = ACTIVITY_UPDATE;
- break;
- default:
- return;
- break;
- }
-
- $url = (($cloudpath && $x[0]['filename']) ? rawurlencode($cloudpath . $x[0]['filename']) : 'unavailable');
-
$mid = item_message_id();
- $item_flags = ITEM_WALL|ITEM_ORIGIN|ITEM_UNSEEN;
-
- $links = array();
- $links[] = array(
- 'rel' => 'alternate',
- 'type' => 'text/html',
- 'href' => $url
- );
-
$objtype = ACTIVITY_OBJ_FILE;
- $object = array(
- 'type' => ACTIVITY_OBJ_FILE,
- 'title' => (($x[0]['filename']) ? $x[0]['filename'] : 'unavailable'),
- 'id' => $url,
- 'link' => $links,
-
- 'hash' => $hash,
- 'creator' => (($x[0]['creator']) ? $x[0]['creator'] : ''),
- 'filename' => (($x[0]['filename']) ? $x[0]['filename'] : ''),
- 'filetype' => (($x[0]['filetype']) ? $x[0]['filetype'] : ''),
- 'filesize' => (($x[0]['filesize']) ? $x[0]['filesize'] : ''),
- 'revision' => (($x[0]['revision']) ? $x[0]['revision'] : ''),
- 'folder' => (($x[0]['folder']) ? $x[0]['folder'] : ''),
- 'flags' => (($x[0]['flags']) ? $x[0]['flags'] : ''),
- 'created' => (($x[0]['created']) ? $x[0]['created'] : ''),
- 'edited' => (($x[0]['edited']) ? $x[0]['edited'] : '')
- );
+ $item_flags = ITEM_WALL|ITEM_ORIGIN|ITEM_UNSEEN;
$private = (($allow_cid || $allow_gid || $deny_cid || $deny_gid) ? 1 : 0);
- if($verb == 'post') {
- //check if activity item exists
- //if yes send update (drop) activity and create a new one
- $y = q("SELECT * FROM item WHERE verb = '%s' AND obj_type = '%s' AND object LIKE '%s'",
- dbesc(ACTIVITY_POST),
- dbesc(ACTIVITY_OBJ_FILE),
- dbesc('%"hash":"' . $hash . '"%')
- );
+ $jsonobject = json_encode($object);
- if($y) {
+ //check if item for this object exists
+ $y = q("SELECT * FROM item WHERE verb = '%s' AND obj_type = '%s' AND object = '%s' LIMIT 1",
+ dbesc(ACTIVITY_POST),
+ dbesc($objtype),
+ dbesc($jsonobject)
+ );
- $dmid = item_message_id();
-
- $object['mid'] = $mid; //attach mid for update object
-
- $arr = array();
-
- $arr['aid'] = get_account_id();
- $arr['uid'] = $channel_id;
- $arr['mid'] = $dmid;
- $arr['parent_mid'] = $dmid;
- $arr['item_flags'] = $item_flags;
- $arr['author_xchan'] = $poster['xchan_hash'];
- $arr['owner_xchan'] = $poster['xchan_hash'];
- $arr['title'] = '';
- //updates must be visible to everybody -> perms may have changed
- $arr['allow_cid'] = '';
- $arr['allow_gid'] = '';
- $arr['deny_cid'] = '';
- $arr['deny_gid'] = '';
- $arr['item_restrict'] = ITEM_HIDDEN;
- $arr['item_private'] = 0;
- $arr['verb'] = ACTIVITY_UPDATE;
- $arr['obj_type'] = $objtype;
- $arr['object'] = json_encode($object);
- $arr['body'] = '';
-
- $post = item_store($arr);
- $item_id = $post['item_id'];
-
- if($item_id) {
- proc_run('php',"include/notifier.php","activity",$item_id);
- }
- call_hooks('post_local_end', $arr);
+ if($y) {
+ $update = true;
+ $object['d_mid'] = $y[0]['mid']; //attach mid of the old object
+ $u_jsonobject = json_encode($object);
+ }
- unset($object['mid']); //remove mid for new object
+ if($update && $verb == 'post' ) {
+ //send update activity and create a new one
+
+ $u_mid = item_message_id();
+
+ $arr = array();
+
+ $arr['aid'] = get_account_id();
+ $arr['uid'] = $channel_id;
+ $arr['mid'] = $u_mid;
+ $arr['parent_mid'] = $u_mid;
+ $arr['item_flags'] = $item_flags;
+ $arr['author_xchan'] = $poster['xchan_hash'];
+ $arr['owner_xchan'] = $poster['xchan_hash'];
+ $arr['title'] = '';
+ //updates should be visible to everybody -> perms may have changed
+ $arr['allow_cid'] = '';
+ $arr['allow_gid'] = '';
+ $arr['deny_cid'] = '';
+ $arr['deny_gid'] = '';
+ $arr['item_restrict'] = ITEM_HIDDEN;
+ $arr['item_private'] = 0;
+ $arr['verb'] = ACTIVITY_UPDATE;
+ $arr['obj_type'] = $objtype;
+ $arr['object'] = $u_jsonobject;
+ $arr['body'] = '';
+
+ $post = item_store($arr);
+ $item_id = $post['item_id'];
+ if($item_id) {
+ proc_run('php',"include/notifier.php","activity",$item_id);
+ }
- //notice( t('File activity updated') . EOL);
+ call_hooks('post_local_end', $arr);
- if($no_activity) {
- return;
- }
+ $update = false;
+
+ //notice( t('File activity updated') . EOL);
- }
}
if($no_activity) {
@@ -1095,9 +1055,9 @@ function file_activity($channel_id, $hash, $cloudpath, $allow_cid, $allow_gid, $
$arr['deny_gid'] = $deny_gid;
$arr['item_restrict'] = ITEM_HIDDEN;
$arr['item_private'] = $private;
- $arr['verb'] = $activity;
+ $arr['verb'] = (($update) ? ACTIVITY_UPDATE : ACTIVITY_POST);
$arr['obj_type'] = $objtype;
- $arr['object'] = json_encode($object);
+ $arr['object'] = (($update) ? $u_jsonobject : $jsonobject);
$arr['body'] = '';
$post = item_store($arr);
@@ -1114,3 +1074,41 @@ function file_activity($channel_id, $hash, $cloudpath, $allow_cid, $allow_gid, $
return;
}
+
+function get_file_activity_object($channel_id, $hash, $cloudpath) {
+
+ $x = q("SELECT creator, filename, filetype, filesize, revision, folder, flags, created, edited FROM attach WHERE uid = %d AND hash = '%s' LIMIT 1",
+ intval($channel_id),
+ dbesc($hash)
+ );
+
+ $url = rawurlencode($cloudpath . $x[0]['filename']);
+
+ $links = array();
+ $links[] = array(
+ 'rel' => 'alternate',
+ 'type' => 'text/html',
+ 'href' => $url
+ );
+
+ $object = array(
+ 'type' => ACTIVITY_OBJ_FILE,
+ 'title' => $x[0]['filename'],
+ 'id' => $url,
+ 'link' => $links,
+
+ 'hash' => $hash,
+ 'creator' => $x[0]['creator'],
+ 'filename' => $x[0]['filename'],
+ 'filetype' => $x[0]['filetype'],
+ 'filesize' => $x[0]['filesize'],
+ 'revision' => $x[0]['revision'],
+ 'folder' => $x[0]['folder'],
+ 'flags' => $x[0]['flags'],
+ 'created' => $x[0]['created'],
+ 'edited' => $x[0]['edited']
+ );
+
+ return $object;
+
+}
diff --git a/install/schema_mysql.sql b/install/schema_mysql.sql
index 52570898b..226ea2308 100644
--- a/install/schema_mysql.sql
+++ b/install/schema_mysql.sql
@@ -13,6 +13,7 @@ CREATE TABLE IF NOT EXISTS `abook` (
`abook_their_perms` int(11) NOT NULL DEFAULT '0',
`abook_closeness` tinyint(3) unsigned NOT NULL DEFAULT '99',
`abook_rating` int(11) NOT NULL DEFAULT '0',
+ `abook_rating_text` TEXT NOT NULL DEFAULT '',
`abook_created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`abook_updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`abook_connected` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
@@ -1529,6 +1530,7 @@ CREATE TABLE IF NOT EXISTS `xlink` (
`xlink_xchan` char(255) NOT NULL DEFAULT '',
`xlink_link` char(255) NOT NULL DEFAULT '',
`xlink_rating` int(11) NOT NULL DEFAULT '0',
+ `xlink_rating_text` TEXT NOT NULL DEFAULT '',
`xlink_updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`xlink_id`),
KEY `xlink_xchan` (`xlink_xchan`),
diff --git a/install/schema_postgres.sql b/install/schema_postgres.sql
index a1b5a76fb..8539e672d 100644
--- a/install/schema_postgres.sql
+++ b/install/schema_postgres.sql
@@ -7,6 +7,7 @@ CREATE TABLE "abook" (
"abook_their_perms" bigint NOT NULL DEFAULT '0',
"abook_closeness" numeric(3) NOT NULL DEFAULT '99',
"abook_rating" bigint NOT NULL DEFAULT '0',
+ "abook_rating_text" TEXT NOT NULL DEFAULT '',
"abook_created" timestamp NOT NULL DEFAULT '0001-01-01 00:00:00',
"abook_updated" timestamp NOT NULL DEFAULT '0001-01-01 00:00:00',
"abook_connected" timestamp NOT NULL DEFAULT '0001-01-01 00:00:00',
@@ -1142,6 +1143,7 @@ CREATE TABLE "xlink" (
"xlink_xchan" text NOT NULL DEFAULT '',
"xlink_link" text NOT NULL DEFAULT '',
"xlink_rating" bigint NOT NULL DEFAULT '0',
+ "xlink_rating_text" TEXT NOT NULL DEFAULT '',
"xlink_updated" timestamp NOT NULL DEFAULT '0001-01-01 00:00:00',
PRIMARY KEY ("xlink_id")
);
diff --git a/mod/dirsearch.php b/mod/dirsearch.php
index 4a44feb7d..06d530849 100644
--- a/mod/dirsearch.php
+++ b/mod/dirsearch.php
@@ -355,14 +355,15 @@ function dir_parse_query($s) {
function list_public_sites() {
+ $rand = db_getfunc('rand');
$realm = get_directory_realm();
if($realm == DIRECTORY_REALM) {
- $r = q("select * from site where site_access != 0 and site_register !=0 and ( site_realm = '%s' or site_realm = '') order by rand()",
+ $r = q("select * from site where site_access != 0 and site_register !=0 and ( site_realm = '%s' or site_realm = '') order by $rand",
dbesc($realm)
);
}
else {
- $r = q("select * from site where site_access != 0 and site_register !=0 and site_realm = '%s' order by rand()",
+ $r = q("select * from site where site_access != 0 and site_register !=0 and site_realm = '%s' order by $rand",
dbesc($realm)
);
}
diff --git a/mod/filestorage.php b/mod/filestorage.php
index 9852f4e73..05f6a79e6 100644
--- a/mod/filestorage.php
+++ b/mod/filestorage.php
@@ -38,8 +38,9 @@ function filestorage_post(&$a) {
//Build directory tree and redirect
$channel = $a->get_channel();
$cloudPath = get_parent_cloudpath($channel_id, $channel['channel_address'], $resource);
+ $object = get_file_activity_object($channel_id, $resource, $cloudPath);
- file_activity($channel_id, $resource, $cloudPath, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny, 'post', $no_activity);
+ file_activity($channel_id, $object, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny, 'post', $no_activity);
goaway($cloudPath);
}
diff --git a/mod/sharedwithme.php b/mod/sharedwithme.php
index baaf41f61..8b7d2661c 100644
--- a/mod/sharedwithme.php
+++ b/mod/sharedwithme.php
@@ -24,38 +24,17 @@ function sharedwithme_content(&$a) {
foreach($x as $xx) {
$object = json_decode($xx['object'],true);
- $hash = $object['hash'];
- //If object has a mid it's an update activity - the inlcuded mid is the latest and should not be removed
- $update = (($object['mid']) ? true : false);
+ $d_mid = $object['d_mid'];
+ $u_mid = $xx['mid'];
- if($update) {
-
- $mid = $object['mid'];
-
- unset($object['mid']); //remove mid from object to match the post activity object
-
- $y = q("DELETE FROM item WHERE (mid != '%s' AND obj_type = '%s') AND (object = '%s' AND verb = '%s') OR (object = '%s' AND verb = '%s')",
- dbesc($mid),
- dbesc(ACTIVITY_OBJ_FILE),
- dbesc(json_encode($object)),
- dbesc(ACTIVITY_POST),
- dbesc($xx['object']),
- dbesc(ACTIVITY_UPDATE)
- );
-
- }
-
- else {
-
- $z = q("DELETE FROM item WHERE (obj_type = '%s' AND object LIKE '%s') AND (verb = '%s' OR verb = '%s')",
- dbesc(ACTIVITY_OBJ_FILE),
- dbesc('%"hash":"' . $hash . '"%'),
- dbesc(ACTIVITY_POST),
- dbesc(ACTIVITY_UPDATE)
- );
-
- }
+ $y = q("DELETE FROM item WHERE obj_type = '%s' AND (verb = '%s' AND mid = '%s') OR (verb = '%s' AND mid = '%s')",
+ dbesc(ACTIVITY_OBJ_FILE),
+ dbesc(ACTIVITY_POST),
+ dbesc($d_mid),
+ dbesc(ACTIVITY_UPDATE),
+ dbesc($u_mid)
+ );
}
diff --git a/mod/sitelist.php b/mod/sitelist.php
index 95cf862df..4e52f0463 100644
--- a/mod/sitelist.php
+++ b/mod/sitelist.php
@@ -9,8 +9,9 @@ function sitelist_init(&$a) {
$sql_order = " order by site_url ";
+ $rand = db_getfunc('rand');
if($order == 'random')
- $sql_order = " order by rand() ";
+ $sql_order = " order by $rand ";
$sql_limit = " limit $start, $limit ";