aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authormjfriaza <mjfriaza@noreply.codeberg.org>2021-02-18 13:28:05 +0100
committermjfriaza <mjfriaza@noreply.codeberg.org>2021-02-18 13:28:05 +0100
commit655ae9d1cdaa940bb7861eb34f4f489a636879b2 (patch)
tree0a10c3d602f5da23dca56ac1360c3ee98282e079 /include
parent76163fc37b76570e158ab32d53a1c0e0cc298bad (diff)
parent08c9152abdfa90da09931bdcc6e6c81ea243434c (diff)
downloadvolse-hubzilla-655ae9d1cdaa940bb7861eb34f4f489a636879b2.tar.gz
volse-hubzilla-655ae9d1cdaa940bb7861eb34f4f489a636879b2.tar.bz2
volse-hubzilla-655ae9d1cdaa940bb7861eb34f4f489a636879b2.zip
Merge branch 'dev' into dev
Diffstat (limited to 'include')
-rw-r--r--include/attach.php10
-rw-r--r--include/bbcode.php4
-rw-r--r--include/bookmarks.php14
-rw-r--r--include/cdav.php4
-rw-r--r--include/channel.php2
-rw-r--r--include/connections.php6
-rw-r--r--include/contact_widgets.php38
-rw-r--r--include/conversation.php114
-rw-r--r--[-rwxr-xr-x]include/dba/dba_driver.php0
-rw-r--r--[-rwxr-xr-x]include/dba/dba_pdo.php0
-rw-r--r--include/dir_fns.php31
-rw-r--r--include/help.php2
-rw-r--r--include/html2plain.php4
-rw-r--r--include/import.php6
-rw-r--r--[-rwxr-xr-x]include/items.php152
-rw-r--r--include/js_strings.php9
-rw-r--r--include/network.php41
-rw-r--r--[-rwxr-xr-x]include/oembed.php7
-rw-r--r--include/photo/photo_driver.php116
-rw-r--r--[-rwxr-xr-x]include/plugin.php0
-rw-r--r--include/security.php242
-rw-r--r--include/taxonomy.php50
-rw-r--r--include/text.php8
23 files changed, 472 insertions, 388 deletions
diff --git a/include/attach.php b/include/attach.php
index b4f697f81..9ba6be109 100644
--- a/include/attach.php
+++ b/include/attach.php
@@ -2987,10 +2987,7 @@ function attach_folder_select_list($channel_id) {
if($r) {
foreach($r as $rv) {
- $x = attach_folder_rpaths($r,$rv);
- if($x) {
- $out[$x[0]] = $x[1];
- }
+ $out[$rv['hash']] = $rv['display_path'];
}
}
@@ -3020,7 +3017,7 @@ function attach_folder_rpaths($all_folders,$that_folder) {
if(! $found)
$error = true;
}
- while((! $found) && (! $error) && ($parent_hash != ''));
+ while((! $error) && ($parent_hash != ''));
}
return (($error) ? false : [ $current_hash , $path ]);
@@ -3067,8 +3064,7 @@ function attach_syspaths($channel_id,$attach_hash) {
function attach_upgrade() {
-
- $r = q("select id, uid, hash from attach where os_path = '' and display_path = '' limit 100");
+ $r = q("SELECT id, uid, hash FROM attach WHERE os_path = '' OR display_path = '' LIMIT 100");
if($r) {
foreach($r as $rv) {
$x = attach_syspaths($rv['uid'],$rv['hash']);
diff --git a/include/bbcode.php b/include/bbcode.php
index d79429719..e1a5c7e47 100644
--- a/include/bbcode.php
+++ b/include/bbcode.php
@@ -966,7 +966,7 @@ function bbtopoll($s) {
$pl['poll_id'] = $match[1];
$pl['poll_question'] = $match[2];
- $match = '';
+ $match = [];
if(preg_match_all("/\[poll\-answer=(.*?)\](.*?)\[\/poll\-answer\]/is",$s,$match,PREG_SET_ORDER)) {
$pl['answer'] = [];
foreach($match as $m) {
@@ -1349,7 +1349,7 @@ function bbcode($Text, $options = []) {
// Check for table of content with params
while(strpos($Text,'[toc') !== false) {
$toc_id = 'toc-' . random_string(10);
- $Text = preg_replace("/\[toc([^\]]+?)\]/ism", '<ul id="' . $toc_id . '" class="toc"$1></ul><script>$("#' . $toc_id . '").toc();</script>', $Text, 1);
+ $Text = preg_replace("/\[toc([^\]]+?)\]/ism", '<ul id="' . $toc_id . '" class="toc" $1></ul><script>$("#' . $toc_id . '").toc();</script>', $Text, 1);
}
// Check for centered text
if (strpos($Text,'[/center]') !== false) {
diff --git a/include/bookmarks.php b/include/bookmarks.php
index 21456c871..145119347 100644
--- a/include/bookmarks.php
+++ b/include/bookmarks.php
@@ -18,7 +18,7 @@ function bookmark_add($channel,$sender,$taxonomy,$private,$opts = null) {
$channel_id = $channel['channel_id'];
if($private)
- $iarr['contact_allow'] = array($channel['channel_hash']);
+ $iarr['contact_allow'] = array($channel['channel_hash']);
$iarr['mitem_link'] = $taxonomy['url'];
$iarr['mitem_desc'] = $taxonomy['term'];
$iarr['mitem_flags'] = (($ischat) ? MENU_ITEM_CHATROOM : 0);
@@ -41,34 +41,34 @@ function bookmark_add($channel,$sender,$taxonomy,$private,$opts = null) {
if(! $menu_id) {
$x = menu_list($arr['menu_channel_id'],$arr['menu_name'],$arr['menu_flags']);
- if($x)
+ if($x)
$menu_id = $x[0]['menu_id'];
- else
+ else
$menu_id = menu_create($arr);
}
if(! $menu_id) {
logger('bookmark_add: unable to create menu ' . $arr['menu_name']);
- return;
+ return;
}
logger('add_bookmark: menu_id ' . $menu_id);
$r = q("select * from menu_item where mitem_link = '%s' and mitem_menu_id = %d and mitem_channel_id = %d limit 1",
dbesc($iarr['mitem_link']),
intval($menu_id),
- intval($channel_id)
+ intval($channel_id)
);
if($r)
logger('add_bookmark: duplicate menu entry', LOGGER_DEBUG);
if(! $r) {
$r = menu_add_item($menu_id,$channel_id,$iarr);
- menu_sync_packet($channel_id,get_observer_hash(),$menu_id);
+ menu_sync_packet($channel_id,get_observer_hash(),$menu_id);
}
return $r;
}
function get_bookmark_link($observer) {
- if((! $observer) || ($observer['xchan_network'] !== 'zot'))
+ if((! $observer) || !in_array($observer['xchan_network'], ['zot6', 'zot']))
return '';
$h = @parse_url($observer['xchan_url']);
diff --git a/include/cdav.php b/include/cdav.php
index ef248a9fe..fcce0ec4a 100644
--- a/include/cdav.php
+++ b/include/cdav.php
@@ -111,7 +111,7 @@ function process_cdav_card($f, &$vcard, $edit = false) {
function import_cdav_card($id, $ext, $table, $column, $objects, $profile, $backend, &$ids, $notice = false) {
$i = 0;
- $newid = (count($ids) ? false : true);
+ $newid = (count($ids) ? false : true);
while ($object = $objects->getNext()) {
@@ -161,7 +161,7 @@ function import_cdav_card($id, $ext, $table, $column, $objects, $profile, $backe
);
}
- if($notice && $exp == 'vcf') {
+ if($notice && $ext == 'vcf') {
notice(
'<strong>' . t('INVALID CARD DISMISSED!') . '</strong>' . EOL .
'<strong>' . t('Name: ') . '</strong>' . (($object->FN) ? $object->FN : t('Unknown')) . EOL .
diff --git a/include/channel.php b/include/channel.php
index d610a0b9a..2d79cd074 100644
--- a/include/channel.php
+++ b/include/channel.php
@@ -651,7 +651,7 @@ function change_channel_keys($channel) {
foreach($h as $hv) {
$hv['hubloc_guid_sig'] = $sig;
$hv['hubloc_hash'] = $hash;
- $hv['hubloc_url_sig'] = base64url_encode(rsa_sign(z_root(),$modifed['channel_prvkey']));
+ $hv['hubloc_url_sig'] = base64url_encode(rsa_sign(z_root(),$modified['channel_prvkey']));
hubloc_store_lowlevel($hv);
}
}
diff --git a/include/connections.php b/include/connections.php
index bd41e112e..87db7faa9 100644
--- a/include/connections.php
+++ b/include/connections.php
@@ -211,8 +211,8 @@ function mark_orphan_hubsxchans() {
if($dirmode == DIRECTORY_MODE_NORMAL)
return;
- $r = q("update hubloc set hubloc_error = 1 where hubloc_error = 0
- and hubloc_network = 'zot' and hubloc_connected < %s - interval %s",
+ $r = q("UPDATE hubloc SET hubloc_error = 1 WHERE hubloc_error = 0
+ AND hubloc_network IN ('zot6', 'zot') AND hubloc_connected < %s - INTERVAL %s",
db_utcnow(), db_quoteinterval('36 day')
);
@@ -357,7 +357,7 @@ function contact_remove($channel_id, $abook_id) {
call_hooks('connection_remove',$x);
- $archive = get_pconfig($channel_id, 'system','archive_removed_contacts');
+ $archive = get_pconfig($channel_id, 'system', 'archive_removed_contacts');
if($archive) {
q("update abook set abook_archived = 1 where abook_id = %d and abook_channel = %d",
intval($abook_id),
diff --git a/include/contact_widgets.php b/include/contact_widgets.php
index 3b22a3c6d..a5f867b0f 100644
--- a/include/contact_widgets.php
+++ b/include/contact_widgets.php
@@ -71,35 +71,39 @@ function categories_widget($baseurl,$selected = '') {
$item_normal = item_normal();
- $key = __FUNCTION__ . "-" . App::$profile['profile_uid'];
- $content = Cache::get($key, '5 MINUTE');
+ $key = __FUNCTION__ . "-" . App::$profile['profile_uid'];
+ $content = Cache::get($key, '5 MINUTE');
if (! $content) {
- $r = q("select distinct(term.term) from term join item on term.oid = item.id
- where item.uid = %d
- and term.uid = item.uid
- and term.ttype = %d
- and term.otype = %d
- and item.owner_xchan = '%s'
- and item.item_wall = 1
- and item.verb != '%s'
+
+ $content = Cache::get($key, '1 MONTH');
+
+ $arr = [
+ "SELECT distinct(term.term) FROM term JOIN item ON term.oid = item.id
+ WHERE item.uid = %d
+ AND term.uid = item.uid
+ AND term.ttype = %d
+ AND term.otype = %d
+ AND item.owner_xchan = '%s'
+ AND item.item_wall = 1
+ AND item.verb != '%s'
$item_normal
$sql_extra
- order by term.term asc",
+ ORDER BY term.term ASC",
intval(App::$profile['profile_uid']),
intval(TERM_CATEGORY),
intval(TERM_OBJ_POST),
dbesc(App::$profile['channel_hash']),
dbesc(ACTIVITY_UPDATE)
- );
+ ];
+
+ \Zotlabs\Daemon\Master::Summon([ 'Cache_query', $key, base64_encode(json_encode($arr)) ]);
}
- else
- $r = unserialize($content);
- $terms = array();
- if($r && count($r)) {
+ $r = unserialize($content);
- Cache::set($key, serialize($r));
+ $terms = [];
+ if($r && count($r)) {
foreach($r as $rr)
$terms[] = array('name' => $rr['term'], 'selected' => (($selected == $rr['term']) ? 'selected' : ''));
diff --git a/include/conversation.php b/include/conversation.php
index 6615b04c3..08d16a413 100644
--- a/include/conversation.php
+++ b/include/conversation.php
@@ -90,18 +90,18 @@ function item_redir_and_replace_images($body, $images, $cid) {
function localize_item(&$item){
if (activity_match($item['verb'],ACTIVITY_LIKE) || activity_match($item['verb'],ACTIVITY_DISLIKE)){
-
+
if(! $item['obj'])
return;
if(intval($item['item_thread_top']))
- return;
+ return;
$obj = json_decode($item['obj'],true);
if((! $obj) && ($item['obj'])) {
logger('localize_item: failed to decode object: ' . print_r($item['obj'],true));
}
-
+
if(is_array($obj['author']) && $obj['author']['link'])
$author_link = get_rel_link($obj['author']['link'],'alternate');
elseif(is_array($obj['actor']) && $obj['actor']['url'])
@@ -167,7 +167,7 @@ function localize_item(&$item){
if($author_link && $author_name && $item_url) {
$author = '[zrl=' . chanlink_url($item['author']['xchan_url']) . ']' . $item['author']['xchan_name'] . '[/zrl]';
$objauthor = '[zrl=' . chanlink_url($author_link) . ']' . $author_name . '[/zrl]';
-
+
$plink = '[zrl=' . zid($item_url) . ']' . $post_type . '[/zrl]';
if(activity_match($item['verb'],ACTIVITY_LIKE)) {
@@ -189,7 +189,7 @@ function localize_item(&$item){
$item['shortlocalize'] = sprintf($shortbodyverb, '[bdi]' . $author_name . '[/bdi]', $post_type);
$item['body'] = $item['localize'] = sprintf($bodyverb, '[bdi]' . $author . '[/bdi]', '[bdi]' . $objauthor . '[/bdi]', $plink);
- if($Bphoto != "")
+ if($Bphoto != "")
$item['body'] .= "\n\n\n" . '[zrl=' . chanlink_url($author_link) . '][zmg=80x80]' . $Bphoto . '[/zmg][/zrl]';
}
@@ -201,7 +201,7 @@ function localize_item(&$item){
if (activity_match($item['verb'],ACTIVITY_FRIEND)) {
- if ($item['obj_type'] == "" || $item['obj_type'] !== ACTIVITY_OBJ_PERSON)
+ if ($item['obj_type'] == "" || $item['obj_type'] !== ACTIVITY_OBJ_PERSON)
return;
$Aname = $item['author']['xchan_name'];
@@ -209,7 +209,7 @@ function localize_item(&$item){
$obj= json_decode($item['obj'],true);
-
+
$Blink = $Bphoto = '';
if($obj['link']) {
@@ -282,7 +282,7 @@ function localize_item(&$item){
$Alink = $item['author']['xchan_url'];
$A = '[zrl=' . chanlink_url($Alink) . '][bdi]' . $Aname . '[/bdi][/zrl]';
-
+
$txt = t('%1$s is %2$s','mood');
$item['body'] = sprintf($txt, $A, t($verb));
@@ -295,15 +295,15 @@ function localize_item(&$item){
// (and update to json storage)
if (activity_match($item['verb'],ACTIVITY_TAG)) {
- $r = q("SELECT * from item,contact WHERE
+ $r = q("SELECT * from item,contact WHERE
item.contact-id=contact.id AND item.mid='%s';",
dbesc($item['parent_mid']));
if(count($r)==0) return;
$obj=$r[0];
-
+
$author = '[zrl=' . zid($item['author-link']) . ']' . $item['author-name'] . '[/zrl]';
$objauthor = '[zrl=' . zid($obj['author-link']) . ']' . $obj['author-name'] . '[/zrl]';
-
+
switch($obj['verb']){
case ACTIVITY_POST:
switch ($obj['obj_type']){
@@ -416,7 +416,7 @@ function count_descendants($item) {
* likes (etc.) can apply to other things besides posts. Check if they are post
* children, in which case we handle them specially. Activities which are unrecognised
* as having special meaning and hidden will be treated as posts or comments and visible
- * in the stream.
+ * in the stream.
*
* @param array $item
* @return boolean
@@ -438,14 +438,14 @@ function visible_activity($item) {
}
// We only need edit activities for other federated protocols
- // which do not support edits natively. While this does federate
+ // which do not support edits natively. While this does federate
// edits, it presents a number of issues locally - such as #757 and #758.
// The SQL check for an edit activity would not perform that well so to fix these issues
- // requires an additional item flag (perhaps 'item_edit_activity') that we can add to the
+ // requires an additional item flag (perhaps 'item_edit_activity') that we can add to the
// query for searches and notifications.
- // For now we'll just forget about trying to make edits work on network protocols that
- // don't support them.
+ // For now we'll just forget about trying to make edits work on network protocols that
+ // don't support them.
// if(is_edit_activity($item))
// return false;
@@ -455,7 +455,7 @@ function visible_activity($item) {
/**
* @brief Check if a given activity is an edit activity
- *
+ *
*
* @param array $item
* @return boolean
@@ -463,11 +463,11 @@ function visible_activity($item) {
function is_edit_activity($item) {
- $post_types = [ ACTIVITY_OBJ_NOTE, ACTIVITY_OBJ_COMMENT, basename(ACTIVITY_OBJ_NOTE), basename(ACTIVITY_OBJ_COMMENT)];
+ $post_types = [ ACTIVITY_OBJ_NOTE, ACTIVITY_OBJ_COMMENT, basename(ACTIVITY_OBJ_NOTE), basename(ACTIVITY_OBJ_COMMENT)];
- // In order to share edits with networks which have no concept of editing, we'll create
+ // In order to share edits with networks which have no concept of editing, we'll create
// separate activities to indicate the edit. Our network will not require them, since our
- // edits are automatically applied and the activity indicated.
+ // edits are automatically applied and the activity indicated.
if(($item['verb'] === ACTIVITY_UPDATE) && (in_array($item['obj_type'],$post_types)))
return true;
@@ -678,12 +678,12 @@ function conversation($items, $mode, $update, $page_mode = 'traditional', $prepa
foreach($items as $item) {
- $x = [
- 'mode' => $mode,
- 'item' => $item
+ $x = [
+ 'mode' => $mode,
+ 'item' => $item
];
call_hooks('stream_item',$x);
-
+
if($x['item']['blocked'])
continue;
@@ -699,7 +699,7 @@ function conversation($items, $mode, $update, $page_mode = 'traditional', $prepa
$is_new = false;
if($mode === 'search' || $mode === 'community') {
- if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
+ if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
&& ($item['id'] != $item['parent']))
continue;
}
@@ -726,7 +726,7 @@ function conversation($items, $mode, $update, $page_mode = 'traditional', $prepa
$drop = array(
'pagedropping' => $page_dropping,
'dropping' => $dropping,
- 'select' => t('Select'),
+ 'select' => t('Select'),
'delete' => t('Delete'),
);
@@ -739,6 +739,8 @@ function conversation($items, $mode, $update, $page_mode = 'traditional', $prepa
? t('Private Message')
: false
);
+ $locktype = $item['item_private'];
+
$likebuttons = false;
$shareable = false;
@@ -769,7 +771,7 @@ function conversation($items, $mode, $update, $page_mode = 'traditional', $prepa
$tmp_item = array(
'template' => $tpl,
'toplevel' => 'toplevel_item',
- 'item_type' => intval($item['item_type']),
+ 'item_type' => intval($item['item_type']),
'mode' => $mode,
'approve' => t('Approve'),
'delete' => t('Delete'),
@@ -783,6 +785,7 @@ function conversation($items, $mode, $update, $page_mode = 'traditional', $prepa
'name' => $profile_name,
'sparkle' => $sparkle,
'lock' => $lock,
+ 'locktype' => $locktype,
'thumb' => $profile_avatar,
'title' => $item['title'],
'body' => $body['html'],
@@ -844,7 +847,7 @@ function conversation($items, $mode, $update, $page_mode = 'traditional', $prepa
$conv = new Zotlabs\Lib\ThreadStream($mode, $preview, $uploading, $prepared_item);
- // In the display mode we don't have a profile owner.
+ // In the display mode we don't have a profile owner.
if($mode === 'display' && $items)
$conv->set_profile_owner($items[0]['uid']);
@@ -861,7 +864,7 @@ function conversation($items, $mode, $update, $page_mode = 'traditional', $prepa
$x = [ 'mode' => $mode, 'item' => $item ];
call_hooks('stream_item',$x);
-
+
if($x['item']['blocked'])
continue;
@@ -970,9 +973,9 @@ function best_link_url($item) {
function thread_action_menu($item,$mode = '') {
$menu = [];
-
+
if((local_channel()) && local_channel() == $item['uid']) {
- $menu[] = [
+ $menu[] = [
'menu' => 'view_source',
'title' => t('View Source'),
'icon' => 'code',
@@ -982,7 +985,7 @@ function thread_action_menu($item,$mode = '') {
if(! in_array($mode, [ 'network-new', 'search', 'community'])) {
if($item['parent'] == $item['id'] && (get_observer_hash() != $item['author_xchan'])) {
- $menu[] = [
+ $menu[] = [
'menu' => 'follow_thread',
'title' => t('Follow Thread'),
'icon' => 'plus',
@@ -991,7 +994,7 @@ function thread_action_menu($item,$mode = '') {
];
}
- $menu[] = [
+ $menu[] = [
'menu' => 'unfollow_thread',
'title' => t('Unfollow Thread'),
'icon' => 'minus',
@@ -1018,7 +1021,7 @@ function author_is_pmable($xchan, $abook) {
call_hooks('author_is_pmable',$x);
if($x['result'] !== 'unset')
return $x['result'];
-
+
if($xchan['xchan_network'] === 'zot' && get_observer_hash())
return true;
return false;
@@ -1063,7 +1066,7 @@ function thread_author_menu($item, $mode = '') {
if($contact) {
$poke_link = ((Apps::system_app_installed($local_channel, 'Poke')) ? z_root() . '/poke/?f=&c=' . $contact['abook_id'] : '');
- if (! intval($contact['abook_self']))
+ if (! intval($contact['abook_self']))
$contact_url = z_root() . '/connedit/' . $contact['abook_id'];
$posts_link = z_root() . '/network/?cid=' . $contact['abook_id'];
@@ -1075,7 +1078,7 @@ function thread_author_menu($item, $mode = '') {
$ratings_url = (($rating_enabled) ? z_root() . '/ratings/' . urlencode($item['author_xchan']) : '');
if($profile_link) {
- $menu[] = [
+ $menu[] = [
'menu' => 'view_profile',
'title' => t('View Profile'),
'icon' => 'fw',
@@ -1085,7 +1088,7 @@ function thread_author_menu($item, $mode = '') {
}
if($posts_link) {
- $menu[] = [
+ $menu[] = [
'menu' => 'view_posts',
'title' => t('Recent Activity'),
'icon' => 'fw',
@@ -1095,7 +1098,7 @@ function thread_author_menu($item, $mode = '') {
}
if($follow_url) {
- $menu[] = [
+ $menu[] = [
'menu' => 'follow',
'title' => t('Connect'),
'icon' => 'fw',
@@ -1105,7 +1108,7 @@ function thread_author_menu($item, $mode = '') {
}
if($contact_url) {
- $menu[] = [
+ $menu[] = [
'menu' => 'connedit',
'title' => t('Edit Connection'),
'icon' => 'fw',
@@ -1115,7 +1118,7 @@ function thread_author_menu($item, $mode = '') {
}
if($pm_url) {
- $menu[] = [
+ $menu[] = [
'menu' => 'prv_message',
'title' => t('Message'),
'icon' => 'fw',
@@ -1125,7 +1128,7 @@ function thread_author_menu($item, $mode = '') {
}
if($ratings_url) {
- $menu[] = [
+ $menu[] = [
'menu' => 'ratings',
'title' => t('Ratings'),
'icon' => 'fw',
@@ -1135,7 +1138,7 @@ function thread_author_menu($item, $mode = '') {
}
if($poke_link) {
- $menu[] = [
+ $menu[] = [
'menu' => 'poke',
'title' => t('Poke'),
'icon' => 'fw',
@@ -1209,8 +1212,8 @@ function builtin_activity_puller($item, &$conv_responses) {
if((activity_match($item['verb'], $verb)) && ($item['id'] != $item['parent'])) {
$name = (($item['author']['xchan_name']) ? $item['author']['xchan_name'] : t('Unknown'));
- $url = (($item['author_xchan'] && $item['author']['xchan_photo_s'])
- ? '<a class="dropdown-item" href="' . chanlink_hash($item['author_xchan']) . '">' . '<img class="menu-img-1" src="' . zid($item['author']['xchan_photo_s']) . '" alt="' . urlencode($name) . '" /> ' . $name . '</a>'
+ $url = (($item['author_xchan'] && $item['author']['xchan_photo_s'])
+ ? '<a class="dropdown-item" href="' . chanlink_hash($item['author_xchan']) . '">' . '<img class="menu-img-1" src="' . zid($item['author']['xchan_photo_s']) . '" alt="' . urlencode($name) . '" /> ' . $name . '</a>'
: '<a class="dropdown-item" href="#" class="disabled">' . $name . '</a>'
);
@@ -1222,7 +1225,7 @@ function builtin_activity_puller($item, &$conv_responses) {
if($item['obj_type'] === 'Answer')
continue;
- if(! ((isset($conv_responses[$mode][$item['thr_parent'] . '-l']))
+ if(! ((isset($conv_responses[$mode][$item['thr_parent'] . '-l']))
&& (is_array($conv_responses[$mode][$item['thr_parent'] . '-l']))))
$conv_responses[$mode][$item['thr_parent'] . '-l'] = array();
@@ -1297,9 +1300,9 @@ function status_editor($a, $x, $popup = false, $module='') {
}
/**
- * This is our general purpose content editor.
+ * This is our general purpose content editor.
* It was once nicknamed "jot" and you may see references to "jot" littered throughout the code.
- * They are referring to the content editor or components thereof.
+ * They are referring to the content editor or components thereof.
*/
function hz_status_editor($a, $x, $popup = false) {
@@ -1341,7 +1344,7 @@ function hz_status_editor($a, $x, $popup = false) {
$weblink = (($mimetype === 'text/bbcode') ? t('Insert web link') : false);
if(x($x, 'hide_weblink'))
$weblink = false;
-
+
$embedPhotos = t('Embed (existing) photo from your photo albums');
$writefiles = (($mimetype === 'text/bbcode') ? perm_is_allowed($x['profile_uid'], get_observer_hash(), 'write_storage') : false);
@@ -1366,9 +1369,9 @@ function hz_status_editor($a, $x, $popup = false) {
$webpage = ((x($x,'webpage')) ? $x['webpage'] : '');
$reset = ((x($x,'reset')) ? $x['reset'] : '');
-
+
$feature_auto_save_draft = ((feature_enabled($x['profile_uid'], 'auto_save_draft')) ? "true" : "false");
-
+
$tpl = get_markup_template('jot-header.tpl');
$tplmacros = [
@@ -1394,7 +1397,7 @@ function hz_status_editor($a, $x, $popup = false) {
'$reset' => $reset
];
- call_hooks('jot_header_tpl_filter',$tplmacros);
+ call_hooks('jot_header_tpl_filter',$tplmacros);
App::$page['htmlhead'] .= replace_macros($tpl, $tplmacros);
$tpl = get_markup_template('jot.tpl');
@@ -1421,7 +1424,7 @@ function hz_status_editor($a, $x, $popup = false) {
$catsenabled = ((feature_enabled($x['profile_uid'], 'categories') && (! $webpage)) ? 'categories' : '');
// avoid illegal offset errors
- if(! array_key_exists('permissions',$x))
+ if(! array_key_exists('permissions',$x))
$x['permissions'] = [ 'allow_cid' => '', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '' ];
$jotplugins = '';
@@ -1514,6 +1517,7 @@ function hz_status_editor($a, $x, $popup = false) {
'$parent' => ((array_key_exists('parent',$x) && $x['parent']) ? $x['parent'] : 0),
'$reset' => $reset,
'$is_owner' => ((local_channel() && (local_channel() == $x['profile_uid'])) ? true : false),
+ '$customjotheaders' => '',
'$custommoretoolsdropdown' => '',
'$custommoretoolsbuttons' => '',
'$customsubmitright' => []
@@ -1539,7 +1543,7 @@ function get_item_children($arr, $parent) {
$thr_parent = $item['thr_parent'];
if($thr_parent == '')
$thr_parent = $item['parent_mid'];
-
+
if($thr_parent == $parent['mid']) {
$item['children'] = get_item_children($arr, $item);
$children[] = $item;
@@ -1698,9 +1702,9 @@ function prepare_page($item) {
return replace_macros(get_markup_template($tpl), array(
'$body' => $body['html']
));
-
+
}
-
+
$tpl = get_pconfig($item['uid'], 'system', 'pagetemplate');
if (! $tpl)
$tpl = 'page_display.tpl';
diff --git a/include/dba/dba_driver.php b/include/dba/dba_driver.php
index b96601fec..b96601fec 100755..100644
--- a/include/dba/dba_driver.php
+++ b/include/dba/dba_driver.php
diff --git a/include/dba/dba_pdo.php b/include/dba/dba_pdo.php
index 49f741601..49f741601 100755..100644
--- a/include/dba/dba_pdo.php
+++ b/include/dba/dba_pdo.php
diff --git a/include/dir_fns.php b/include/dir_fns.php
index f477b35dd..88a1bb74f 100644
--- a/include/dir_fns.php
+++ b/include/dir_fns.php
@@ -16,7 +16,6 @@ require_once('include/permissions.php');
* @return array
*/
function find_upstream_directory($dirmode) {
- global $DIRECTORY_FALLBACK_SERVERS;
$preferred = get_config('system','directory_server');
@@ -28,7 +27,7 @@ function find_upstream_directory($dirmode) {
);
if(($r) && ($r[0]['site_flags'] & DIRECTORY_MODE_STANDALONE)) {
$preferred = '';
- }
+ }
}
@@ -39,14 +38,16 @@ function find_upstream_directory($dirmode) {
* from our list of directory servers. However, if we're a directory
* server ourself, point at the local instance
* We will then set this value so this should only ever happen once.
- * Ideally there will be an admin setting to change to a different
+ * Ideally there will be an admin setting to change to a different
* directory server if you don't like our choice or if circumstances change.
*/
+ $directory_fallback_servers = get_directory_fallback_servers();
+
$dirmode = intval(get_config('system','directory_mode'));
if ($dirmode == DIRECTORY_MODE_NORMAL) {
- $toss = mt_rand(0,count($DIRECTORY_FALLBACK_SERVERS));
- $preferred = $DIRECTORY_FALLBACK_SERVERS[$toss];
+ $toss = mt_rand(0,count($directory_fallback_servers));
+ $preferred = $directory_fallback_servers[$toss];
set_config('system','directory_server',$preferred);
} else{
set_config('system','directory_server',z_root());
@@ -94,7 +95,7 @@ function get_directory_setting($observer, $setting) {
$ret = get_config('directory', $setting);
- // 'safemode' is the default if there is no observer or no established preference.
+ // 'safemode' is the default if there is no observer or no established preference.
if($setting == 'safemode' && $ret === false)
$ret = 1;
@@ -152,8 +153,8 @@ function dir_sort_links() {
*
* Checks the directory mode of this hub to see if it is some form of directory server. If it is,
* get the directory realm of this hub. Fetch a list of all other directory servers in this realm and request
- * a directory sync packet. This will contain both directory updates and new ratings. Store these all in the DB.
- * In the case of updates, we will query each of them asynchronously from a poller task. Ratings are stored
+ * a directory sync packet. This will contain both directory updates and new ratings. Store these all in the DB.
+ * In the case of updates, we will query each of them asynchronously from a poller task. Ratings are stored
* directly if the rater's signature matches.
*
* @param int $dirmode;
@@ -189,7 +190,7 @@ function sync_directories($dirmode) {
[
'site_url' => DIRECTORY_FALLBACK_MASTER,
'site_flags' => DIRECTORY_MODE_PRIMARY,
- 'site_update' => NULL_DATE,
+ 'site_update' => NULL_DATE,
'site_directory' => DIRECTORY_FALLBACK_MASTER . '/dirsearch',
'site_realm' => DIRECTORY_REALM,
'site_valid' => 1,
@@ -335,11 +336,11 @@ function update_directory_entry($ud) {
// modify the directory search to only return zot6 entries, and also modify this function
// to *only* fetch the zot6 entries.
// Otherwise we'll be showing duplicates or have a mostly empty directory for a good chunk of
- // the transition period. Directory server load will likely increase "moderately" during this transition.
- // The one month counter begins when the primary directory has upgraded to a release which uses this code.
+ // the transition period. Directory server load will likely increase "moderately" during this transition.
+ // The one month counter begins when the primary directory has upgraded to a release which uses this code.
// Hubzilla channels running traditional zot which have not upgraded can or will be dropped from the directory or
// "not found" at the end of the transition period as the directory will only serve zot6 entries at that time.
-
+
$uri = Webfinger::zot_url($ud['ud_addr']);
if($uri) {
$record = Zotfinger::exec($uri);
@@ -347,8 +348,8 @@ function update_directory_entry($ud) {
// Check the HTTP signature
$hsig = $record['signature'];
- if($hsig && $hsig['signer'] === $url && $hsig['header_valid'] === true && $hsig['content_valid'] === true) {
- $x = \Zotlabs\Lib\Libzot::import_xchan($record['data'], 0, $ud);
+ if($hsig && $hsig['signer'] === $uri && $hsig['header_valid'] === true && $hsig['content_valid'] === true) {
+ $x = Libzot::import_xchan($record['data'], 0, $ud);
if($x['success']) {
$success = true;
}
@@ -394,7 +395,7 @@ function local_dir_update($uid, $force) {
$profile['description'] = $p[0]['pdesc'];
$profile['birthday'] = $p[0]['dob'];
- if ($age = age($p[0]['dob'],$p[0]['channel_timezone'],''))
+ if ($age = age($p[0]['dob'],$p[0]['channel_timezone'],''))
$profile['age'] = $age;
$profile['gender'] = $p[0]['gender'];
diff --git a/include/help.php b/include/help.php
index affe64495..ebf1ccc08 100644
--- a/include/help.php
+++ b/include/help.php
@@ -299,7 +299,7 @@ function load_context_help() {
break;
array_pop($args);
- $path = implode($args,'/');
+ $path = implode('/', $args);
}
return $context_help;
diff --git a/include/html2plain.php b/include/html2plain.php
index 979354079..fde70bd01 100644
--- a/include/html2plain.php
+++ b/include/html2plain.php
@@ -40,7 +40,7 @@ function breaklines($line, $level, $wraplength = 75)
$newlines[] = $line;
- return(implode($newlines, "\n"));
+ return(implode("\n", $newlines));
}
function quotelevel($message, $wraplength = 75)
@@ -73,7 +73,7 @@ function quotelevel($message, $wraplength = 75)
if (!$startquote or ($line != ''))
$newlines[] = breaklines($line, $currlevel, $wraplength);
}
- return(implode($newlines, "\n"));
+ return(implode("\n", $newlines));
}
function collecturls($message) {
diff --git a/include/import.php b/include/import.php
index d02cc1e1f..8ce582ede 100644
--- a/include/import.php
+++ b/include/import.php
@@ -1358,7 +1358,7 @@ function sync_files($channel, $files) {
$headers = [];
$headers['Accept'] = 'application/x-zot+json' ;
$headers['Sigtoken'] = random_string();
- $headers = HTTPSig::create_sig($headers,$channel['channel_prvkey'], 'acct:' . channel_reddress($channel),true,'sha512');
+ $headers = HTTPSig::create_sig($headers, $channel['channel_prvkey'], channel_url($channel), true, 'sha512');
$x = z_post_url($fetch_url,$parr,$redirects,[ 'filep' => $fp, 'headers' => $headers]);
fclose($fp);
@@ -1463,13 +1463,13 @@ function sync_files($channel, $files) {
$headers = [];
$headers['Accept'] = 'application/x-zot+json' ;
$headers['Sigtoken'] = random_string();
- $headers = HTTPSig::create_sig($headers,$channel['channel_prvkey'],'acct:' . channel_reddress($channel),true,'sha512');
+ $headers = HTTPSig::create_sig($headers, $channel['channel_prvkey'], channel_url($channel), true, 'sha512');
$x = z_post_url($fetch_url,$parr,$redirects,[ 'filep' => $fp, 'headers' => $headers]);
fclose($fp);
// Override remote hub thumbnails storage settings
- if(! boolval(get_config('system','filesystem_storage_thumbnails', 0))) {
+ if(! boolval(get_config('system','photo_storage_type', 1))) {
$p['os_storage'] = 0;
$p['content'] = file_get_contents($stored_image);
@unlink($stored_image);
diff --git a/include/items.php b/include/items.php
index 2426c189f..83108455f 100755..100644
--- a/include/items.php
+++ b/include/items.php
@@ -11,6 +11,7 @@ use Zotlabs\Lib\ThreadListener;
use Zotlabs\Lib\IConfig;
use Zotlabs\Lib\Activity;
use Zotlabs\Lib\Libsync;
+use Zotlabs\Lib\Libzot;
use Zotlabs\Access\PermissionLimits;
use Zotlabs\Access\PermissionRoles;
use Zotlabs\Access\AccessList;
@@ -130,7 +131,7 @@ function collect_recipients($item, &$private_envelope,$include_groups = true) {
case 'sit':
case 'any':
case 'con':
- if($rr['xchan_network'] != 'zot')
+ if(!in_array($rr['xchan_network'], ['zot6', 'zot']))
break;
case 'pub':
case '':
@@ -790,8 +791,8 @@ function get_item_elements($x,$allow_code = false) {
dbesc($arr['author_xchan'])
);
if($r) {
- if($r[0]['xchan_pubkey'] && $r[0]['xchan_network'] === 'zot') {
- if(rsa_verify($x['body'],base64url_decode($arr['sig']),$r[0]['xchan_pubkey'])) {
+ if($r[0]['xchan_pubkey'] && $r[0]['xchan_network'] === 'zot6') {
+ if(Libzot::verify($x['body'], $arr['sig'], $r[0]['xchan_pubkey'])) {
$arr['item_verified'] = 1;
}
else {
@@ -2206,6 +2207,7 @@ function item_store_update($arr, $allow_exec = false, $deliver = true) {
return $ret;
}
+
// override the unseen flag with the original
$arr['item_unseen'] = $orig[0]['item_unseen'];
@@ -2672,6 +2674,11 @@ function tag_deliver($uid, $item_id) {
}
if ($is_group && intval($item['item_private']) === 2 && intval($item['item_thread_top'])) {
+
+ // do not turn the groups own direkt messages into group items
+ if($item['item_wall'] && $item['author_xchan'] === $u[0]['channel_hash'])
+ return;
+
// group delivery via DM
if(perm_is_allowed($uid,$item['owner_xchan'],'post_wall') || perm_is_allowed($uid,$item['owner_xchan'],'tag_deliver')) {
logger('group DM delivery for ' . $u[0]['channel_address']);
@@ -2682,6 +2689,12 @@ function tag_deliver($uid, $item_id) {
if ($is_group && intval($item['item_thread_top']) && intval($item['item_wall']) && $item['author_xchan'] !== $item['owner_xchan']) {
+
+ if($item['resource_type'] === 'group_item') {
+ logger('resource_type group_item: already shared');
+ return;
+ }
+
if (strpos($item['body'],'[/share]')) {
logger('W2W post already shared');
return;
@@ -3113,11 +3126,12 @@ function tgroup_check($uid, $item) {
}
}
}
-*/
+
if(! $found) {
logger('tgroup_check: mention was in a reshare or exceeded max_tagged_forums - ignoring');
continue;
}
+*/
return true;
}
@@ -3203,16 +3217,18 @@ function start_delivery_chain($channel, $item, $item_id, $parent, $group = false
$arr = [];
if ($edit) {
+
// process edit or delete action
- $r = q("select * from item where source_xchan = '%s' and body like '%s' and uid = %d limit 1",
- dbesc($item['owner_xchan']),
- dbesc("%message_id='" . $item['mid'] . "'%"),
- intval($channel['channel_id'])
+ $r = q("select * from item where uid = %d and resource_id = '%s' and source_xchan = '%s' and resource_type = 'group_item' limit 1",
+ intval($channel['channel_id']),
+ dbesc($item['mid']),
+ dbesc($item['author_xchan'])
);
+
if ($r) {
if (intval($item['item_deleted'])) {
- drop_item($r[0]['id'],false,DROPITEM_PHASE1);
- Master::Summon([ 'Notifier','drop',$r[0]['id'] ]);
+ drop_item($r[0]['id'], false, DROPITEM_PHASE1);
+ Master::Summon([ 'Notifier', 'drop', $r[0]['id'] ]);
return;
}
$arr['id'] = intval($r[0]['id']);
@@ -3242,6 +3258,9 @@ function start_delivery_chain($channel, $item, $item_id, $parent, $group = false
$arr['item_uplink'] = 0;
$arr['source_xchan'] = $item['owner_xchan'];
+ $arr['resource_id'] = $item['mid'];
+ $arr['resource_type'] = 'group_item';
+
$arr['item_private'] = (($channel['channel_allow_cid'] || $channel['channel_allow_gid']
|| $channel['channel_deny_cid'] || $channel['channel_deny_gid']) ? 1 : 0);
@@ -3263,12 +3282,13 @@ function start_delivery_chain($channel, $item, $item_id, $parent, $group = false
"' message_id='" . $item['mid'] .
"']";
if($item['title'])
- $bb .= '[b]'.$item['title'].'[/b]'."\r\n";
+ $bb .= '[h3][b]'.$item['title'].'[/b][/h3]'."\r\n";
$bb .= $item['body'];
$bb .= "[/share]";
}
$arr['body'] = $bb;
+ $arr['term'] = $item['term'];
$arr['author_xchan'] = $channel['channel_hash'];
$arr['owner_xchan'] = $channel['channel_hash'];
@@ -3950,10 +3970,10 @@ function drop_item($id,$interactive = true,$stage = DROPITEM_NORMAL) {
);
if($items) {
foreach($items as $i)
- delete_item_lowlevel($i,$stage,$force);
+ delete_item_lowlevel($i, $stage);
}
else
- delete_item_lowlevel($item,$stage,$force);
+ delete_item_lowlevel($item, $stage);
if(! $interactive)
return 1;
@@ -3987,7 +4007,6 @@ function drop_item($id,$interactive = true,$stage = DROPITEM_NORMAL) {
*
* @param array $item
* @param int $stage
- * @param boolean $force
* @return boolean
*/
function delete_item_lowlevel($item, $stage = DROPITEM_NORMAL) {
@@ -4299,54 +4318,54 @@ function fetch_post_tags($items, $link = false) {
*/
function zot_feed($uid, $observer_hash, $arr) {
- $result = array();
- $mindate = null;
+ $result = [];
+ $mindate = null;
$message_id = null;
- $wall = true;
+ $wall = true;
require_once('include/security.php');
- if(array_key_exists('mindate',$arr)) {
- $mindate = datetime_convert('UTC','UTC',$arr['mindate']);
+ if (array_key_exists('mindate', $arr)) {
+ $mindate = datetime_convert('UTC', 'UTC', $arr['mindate']);
}
- if(array_key_exists('message_id',$arr)) {
+ if (array_key_exists('message_id', $arr)) {
$message_id = $arr['message_id'];
}
- if(array_key_exists('wall',$arr)) {
+ if (array_key_exists('wall', $arr)) {
$wall = intval($arr['wall']);
}
- if(! $mindate)
+ if (!$mindate)
$mindate = NULL_DATE;
$mindate = dbesc($mindate);
logger('zot_feed: requested for uid ' . $uid . ' from observer ' . $observer_hash, LOGGER_DEBUG);
- if($message_id)
- logger('message_id: ' . $message_id,LOGGER_DEBUG);
+ if ($message_id)
+ logger('message_id: ' . $message_id, LOGGER_DEBUG);
- if(! perm_is_allowed($uid,$observer_hash,'view_stream')) {
+ if (!perm_is_allowed($uid, $observer_hash, 'view_stream')) {
logger('zot_feed: permission denied.');
return $result;
}
- if(! is_sys_channel($uid))
- $sql_extra = item_permissions_sql($uid,$observer_hash);
+ if (!is_sys_channel($uid))
+ $sql_extra = item_permissions_sql($uid, $observer_hash);
$limit = " LIMIT 5000 ";
- if($mindate > NULL_DATE) {
+ if ($mindate > NULL_DATE) {
$sql_extra .= " and ( created > '$mindate' or changed > '$mindate' ) ";
}
- if($message_id) {
+ if ($message_id) {
$sql_extra .= " and mid = '" . dbesc($message_id) . "' ";
- $limit = '';
+ $limit = '';
}
- if($wall) {
+ if ($wall) {
$sql_extra .= " and item_wall = 1 ";
}
@@ -4355,17 +4374,17 @@ function zot_feed($uid, $observer_hash, $arr) {
$item_normal = item_normal();
- if(is_sys_channel($uid)) {
+ if (is_sys_channel($uid)) {
- $nonsys_uids = q("SELECT channel_id FROM channel WHERE channel_system = 0");
- $nonsys_uids_str = ids_to_querystr($nonsys_uids,'channel_id');
+ $nonsys_uids = q("SELECT channel_id FROM channel WHERE channel_system = 0");
+ $nonsys_uids_str = ids_to_querystr($nonsys_uids, 'channel_id');
$r = q("SELECT parent, postopts FROM item
WHERE uid IN ( %s )
AND item_private = 0
$item_normal
$sql_extra ORDER BY created ASC $limit",
- intval($nonsys_uids_str)
+ dbesc($nonsys_uids_str)
);
}
else {
@@ -4379,19 +4398,19 @@ function zot_feed($uid, $observer_hash, $arr) {
$parents = [];
- if($r) {
- foreach($r as $rv) {
- if(array_key_exists($rv['parent'],$parents))
+ if ($r) {
+ foreach ($r as $rv) {
+ if (array_key_exists($rv['parent'], $parents))
continue;
- if(strpos($rv['postopts'],'nodeliver') !== false)
+ if (strpos($rv['postopts'], 'nodeliver') !== false)
continue;
$parents[$rv['parent']] = $rv;
- if(count($parents) > 200)
+ if (count($parents) > 200)
break;
}
- $parents_str = ids_to_querystr($parents,'parent');
- $sys_query = ((is_sys_channel($uid)) ? $sql_extra : '');
+ $parents_str = ids_to_querystr($parents, 'parent');
+ $sys_query = ((is_sys_channel($uid)) ? $sql_extra : '');
$item_normal = item_normal();
$items = q("SELECT item.*, item.id AS item_id FROM item
@@ -4400,25 +4419,23 @@ function zot_feed($uid, $observer_hash, $arr) {
);
}
- if($items) {
+ if ($items) {
xchan_query($items);
$items = fetch_post_tags($items);
require_once('include/conversation.php');
- $items = conv_sort($items,'ascending');
+ $items = conv_sort($items, 'ascending');
}
else
- $items = array();
+ $items = [];
- logger('zot_feed: number items: ' . count($items),LOGGER_DEBUG);
+ logger('zot_feed: number items: ' . count($items), LOGGER_DEBUG);
- foreach($items as $item)
+ foreach ($items as $item)
$result[] = encode_item($item);
return $result;
}
-
-
function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = CLIENT_MODE_NORMAL,$module = 'network') {
$result = array('success' => false);
@@ -4458,7 +4475,7 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C
$sql_extra = " AND item.parent IN ( SELECT parent FROM item WHERE $item_uids and item_thread_top = 1 $sql_options $item_normal ) ";
if($arr['since_id'])
- $sql_extra .= " and item.id > " . $since_id . " ";
+ $sql_extra .= " and item.id > " . intval($arr['since_id']) . " ";
if($arr['cat'])
$sql_extra .= protect_sprintf(term_query('item', $arr['cat'], TERM_CATEGORY));
@@ -4543,9 +4560,11 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C
// only setup pagination on initial page view
$pager_sql = '';
} else {
- $itemspage = (($channel) ? get_pconfig($uid,'system','itemspage') : 10);
- App::set_pager_itemspage(((intval($itemspage)) ? $itemspage : 10));
- $pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval(App::$pager['itemspage']), intval(App::$pager['start']));
+ if(! $arr['total']) {
+ $itemspage = (($channel) ? get_pconfig($uid,'system','itemspage') : 10);
+ App::set_pager_itemspage(((intval($itemspage)) ? $itemspage : 10));
+ $pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval(App::$pager['itemspage']), intval(App::$pager['start']));
+ }
}
if (isset($arr['start']) && isset($arr['records']))
@@ -4581,7 +4600,6 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C
require_once('include/security.php');
$sql_extra .= item_permissions_sql($channel['channel_id'],$observer_hash);
-
if($arr['pages'])
$item_restrict = " AND item_type = " . ITEM_TYPE_WEBPAGE . " ";
else
@@ -4594,11 +4612,23 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C
// "New Item View" - show all items unthreaded in reverse created date order
- $items = q("SELECT item.*, item.id AS item_id FROM item
+ if ($arr['total']) {
+ $items = dbq("SELECT count(item.id) AS total FROM item
WHERE $item_uids $item_restrict
$simple_update
- $sql_extra $sql_nets $sql_extra3
- ORDER BY item.received DESC $pager_sql"
+ $sql_extra $sql_nets $sql_extra3"
+ );
+ if ($items) {
+ return intval($items[0]['total']);
+ }
+ return 0;
+ }
+
+ $items = dbq("SELECT item.*, item.id AS item_id FROM item
+ WHERE $item_uids $item_restrict
+ $simple_update
+ $sql_extra $sql_nets $sql_extra3
+ ORDER BY item.received DESC $pager_sql"
);
require_once('include/items.php');
@@ -4619,7 +4649,7 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C
// Fetch a page full of parent items for this page
- $r = q("SELECT distinct item.id AS item_id, item.$ordering FROM item
+ $r = dbq("SELECT distinct item.id AS item_id, item.$ordering FROM item
left join abook on item.author_xchan = abook.abook_xchan
WHERE $item_uids $item_restrict
AND item.parent = item.id
@@ -4630,7 +4660,7 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C
}
else {
// update
- $r = q("SELECT item.parent AS item_id FROM item
+ $r = dbq("SELECT item.parent AS item_id FROM item
left join abook on item.author_xchan = abook.abook_xchan
WHERE $item_uids $item_restrict $simple_update
and (abook.abook_blocked = 0 or abook.abook_flags is null)
@@ -4705,7 +4735,7 @@ function webpage_to_namespace($webpage) {
function update_remote_id($channel,$post_id,$webpage,$pagetitle,$namespace,$remote_id,$mid) {
- if(! $post_id)
+ if(! intval($post_id))
return;
$page_type = webpage_to_namespace($webpage);
@@ -4727,7 +4757,7 @@ function update_remote_id($channel,$post_id,$webpage,$pagetitle,$namespace,$remo
// as the entire mid. If it were the post_id the link would be less portable.
IConfig::Set(
- intval($post_id),
+ $post_id,
'system',
$page_type,
($pagetitle) ? $pagetitle : substr($mid,0,16),
diff --git a/include/js_strings.php b/include/js_strings.php
index 6f559f4c4..e06e105fd 100644
--- a/include/js_strings.php
+++ b/include/js_strings.php
@@ -47,10 +47,10 @@ function js_strings() {
'days' => tt('%d days', '%d days', '%d'),
'months' => tt('%d months', '%d months', '%d'),
'years' => tt('%d years', '%d years', '%d'),
-
+
// get plural function code
'plural_func' => tf(),
-
+
'$t01' => ((t('timeago.prefixAgo') == 'timeago.prefixAgo') ? '' : ((t('timeago.prefixAgo') == 'NONE') ? '' : t('timeago.prefixAgo'))),
'$t02' => ((t('timeago.prefixFromNow') == 'timeago.prefixFromNow') ? '' : ((t('timeago.prefixFromNow') == 'NONE') ? '' : t('timeago.prefixFromNow'))),
'$t03' => ((t('timeago.suffixAgo') == 'timeago.suffixAgo') ? 'ago' : ((t('timeago.suffixAgo') == 'NONE') ? '' : t('timeago.suffixAgo'))),
@@ -113,6 +113,9 @@ function js_strings() {
'$month' => t('month','calendar'),
'$week' => t('week','calendar'),
'$day' => t('day','calendar'),
- '$allday' => t('All day','calendar')
+ '$allday' => t('All day','calendar'),
+
+ // mod cloud
+ '$download_info' => t('Please stand by while your download is being prepared.')
));
}
diff --git a/include/network.php b/include/network.php
index bcd66cf85..f5ff48fce 100644
--- a/include/network.php
+++ b/include/network.php
@@ -1,8 +1,10 @@
<?php
+use Zotlabs\Lib\LDSignatures;
use Zotlabs\Lib\Zotfinger;
use Zotlabs\Lib\Libzot;
use Zotlabs\Lib\Queue;
+use Zotlabs\Web\HTTPSig;
/**
* @file include/network.php
@@ -404,6 +406,31 @@ function json_return_and_die($x, $content_type = 'application/json') {
killme();
}
+function as_return_and_die($obj,$channel) {
+
+ $x = array_merge(['@context' => [
+ ACTIVITYSTREAMS_JSONLD_REV,
+ 'https://w3id.org/security/v1',
+ z_root() . ZOT_APSCHEMA_REV
+ ]], $obj );
+
+ $headers = [];
+ $headers['Content-Type'] = 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' ;
+ $x['signature'] = LDSignatures::sign($x,$channel);
+ $ret = json_encode($x, JSON_UNESCAPED_SLASHES);
+ logger('data: ' . jindent($ret), LOGGER_DATA);
+ $headers['Date'] = datetime_convert('UTC','UTC', 'now', 'D, d M Y H:i:s \\G\\M\\T');
+ $headers['Digest'] = HTTPSig::generate_digest_header($ret);
+ $headers['(request-target)'] = strtolower($_SERVER['REQUEST_METHOD']) . ' ' . $_SERVER['REQUEST_URI'];
+
+ $h = HTTPSig::create_sig($headers,$channel['channel_prvkey'],channel_url($channel));
+ HTTPSig::set_headers($h);
+
+ echo $ret;
+ killme();
+
+}
+
/**
* @brief Send HTTP status header.
*
@@ -714,7 +741,7 @@ function sxml2array ( $xmlObject, $out = array () )
* @brief xml2array() will convert the given XML text to an array in the XML structure.
*
* Link: http://www.bin-co.com/php/scripts/xml2array/
- * Portions significantly re-written by mike@macgirvin.com
+ * Portions significantly re-written by mike@macgirvin.com
* (namespaces, lowercase tags, get_attribute default changed, more...)
*
* Examples: $array = xml2array(file_get_contents('feed.xml'));
@@ -1113,8 +1140,8 @@ function discover_by_webbie($webbie, $protocol = '') {
// Check the HTTP signature
$hsig = $record['signature'];
- if($hsig && ($hsig['signer'] === $url || $hsig['signer'] === $link['href']) && $hsig['header_valid'] === true && $hsig['content_valid'] === true)
- $hsig_valid = true;
+ if($hsig && $hsig['signer'] === $link['href'] && $hsig['header_valid'] === true && $hsig['content_valid'] === true)
+ $hsig_valid = true;
if(! $hsig_valid) {
logger('http signature not valid: ' . print_r($hsig,true));
@@ -1431,7 +1458,7 @@ function scrape_feed($url) {
function do_delivery($deliveries, $force = false) {
// $force is set if a site that wasn't responding suddenly returns to life.
- // Try and shove through everything going to that site while it's responding.
+ // Try and shove through everything going to that site while it's responding.
if(! (is_array($deliveries) && count($deliveries)))
return;
@@ -1978,7 +2005,7 @@ function getBestSupportedMimeType($mimeTypes = null, $acceptedTypes = false) {
// check if there is a different quality
if (strpos($a, ';q=')) {
// divide "mime/type;q=X" into two parts: "mime/type" i "X"
- list($a, $q) = explode(';q=', $a);
+ [$a, $q] = explode(';q=', $a);
}
// mime-type $a is accepted with the quality $q
// WARNING: $q == 0 means, that mime-type isn’t supported!
@@ -2069,7 +2096,7 @@ function get_request_string($url) {
* Takes the output of parse_url and builds a URL from it
*
*/
-
+
function unparse_url($parsed_url) {
$scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
$host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
@@ -2081,4 +2108,4 @@ function unparse_url($parsed_url) {
$query = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : '';
$fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : '';
return "$scheme$user$pass$host$port$path$query$fragment";
-}
+}
diff --git a/include/oembed.php b/include/oembed.php
index eeae7a174..1550eaacf 100755..100644
--- a/include/oembed.php
+++ b/include/oembed.php
@@ -189,6 +189,13 @@ function oembed_fetch_url($embedurl){
$entries = $xpath->query("//link[@type='application/json+oembed']");
foreach($entries as $e){
$href = $e->getAttributeNode("href")->nodeValue;
+
+ // Youtube will happily hand us an http oembed URL even if we specify an https link; and the returned http link will fail with a 40x if you try and fetch it
+ // This is not our bug, but good luck getting google to fix it.
+ if (strpos($href,'http:') === 0 && strpos($href,'youtu') !== false) {
+ $href = str_replace('http:','https:', $href);
+ }
+
$x = z_fetch_url($href . '&maxwidth=' . App::$videowidth);
if($x['success'])
$txt = $x['body'];
diff --git a/include/photo/photo_driver.php b/include/photo/photo_driver.php
index f61919eea..87b1d96fe 100644
--- a/include/photo/photo_driver.php
+++ b/include/photo/photo_driver.php
@@ -64,15 +64,23 @@ function photo_factory($data, $type = null) {
*
* @param string $filename
* Image filename
- * @param string $headers (optional)
- * Headers to check for Content-Type (from curl request)
+ * @param string $data (optional)
+ * Data array fetched from cURL with z_fetch_url
* @return null|string Guessed mimetype
*/
-function guess_image_type($filename, $headers = '') {
-// logger('Photo: guess_image_type: '.$filename . ($headers?' from curl headers':''), LOGGER_DEBUG);
+function guess_image_type($filename, $data = '') {
+
+ if($data)
+ $headers = (is_array($data) ? $data['header'] : $data);
+
+ // logger('Photo: guess_image_type: '.$filename . ($headers?' from curl headers':''), LOGGER_DEBUG);
+
$type = null;
$m = null;
+ $ph = photo_factory('');
+ $types = $ph->supportedTypes();
+
if($headers) {
$hdrs = [];
$h = explode("\n", $headers);
@@ -81,19 +89,14 @@ function guess_image_type($filename, $headers = '') {
$hdrs[strtolower($k)] = $v;
}
logger('Curl headers: ' .var_export($hdrs, true), LOGGER_DEBUG);
- if(array_key_exists('content-type', $hdrs)) {
- $ph = photo_factory('');
- $types = $ph->supportedTypes();
-
- if(array_key_exists($hdrs['content-type'], $types))
- $type = $hdrs['content-type'];
- }
+ if(array_key_exists('content-type', $hdrs) && array_key_exists($hdrs['content-type'], $types))
+ $type = $hdrs['content-type'];
}
if(is_null($type)){
$ignore_imagick = get_config('system', 'ignore_imagick');
// Guessing from extension? Isn't that... dangerous?
- if(class_exists('Imagick') && file_exists($filename) && is_readable($filename) && !$ignore_imagick) {
+ if(class_exists('Imagick') && ! $ignore_imagick) {
$v = Imagick::getVersion();
preg_match('/ImageMagick ([0-9]+\.[0-9]+\.[0-9]+)/', $v['versionString'], $m);
if(version_compare($m[1], '6.6.7') >= 0) {
@@ -102,8 +105,18 @@ function guess_image_type($filename, $headers = '') {
* but at least it comes from the data inside the image,
* we won't be tricked by a manipulated extension
*/
- $image = new Imagick($filename);
- $type = $image->getImageMimeType();
+ $body = false;
+ if (strpos($filename, 'http') === false && file_exists($filename) && is_readable($filename))
+ $body == file_get_contents($filename);
+ elseif (is_array($data) && array_key_exists('body', $data))
+ $body = $data['body'];
+ if ($body) {
+ $image = new Imagick($filename);
+ $image->readImageBlob($body);
+ $r = $image->identifyImage();
+ if ($r && is_array($r) && array_key_exists($r['mimetype'], $types))
+ $type = $r['mimetype'];
+ }
}
else {
// earlier imagick versions have issues with scaling png's
@@ -115,8 +128,6 @@ function guess_image_type($filename, $headers = '') {
if(is_null($type)) {
$ext = pathinfo($filename, PATHINFO_EXTENSION);
- $ph = photo_factory('');
- $types = $ph->supportedTypes();
foreach($types as $m => $e) {
if($ext === $e) {
$type = $m;
@@ -124,12 +135,12 @@ function guess_image_type($filename, $headers = '') {
}
}
- if(is_null($type) && (strpos($filename, 'http') === false)) {
+ if(is_null($type) && strpos($filename, 'http') === 0) {
$size = getimagesize($filename);
- $ph = photo_factory('');
- $types = $ph->supportedTypes();
- $type = ((array_key_exists($size['mime'], $types)) ? $size['mime'] : 'image/jpeg');
+ if (array_key_exists($size['mime'], $types))
+ $type = $size['mime'];
}
+
if(is_null($type)) {
if(strpos(strtolower($filename),'jpg') !== false)
$type = 'image/jpeg';
@@ -139,8 +150,8 @@ function guess_image_type($filename, $headers = '') {
$type = 'image/gif';
elseif(strpos(strtolower($filename),'png') !== false)
$type = 'image/png';
- elseif(strpos(strtolower($filename),'webp') !== false)
- $type = 'image/webp';
+ elseif(strpos(strtolower($filename),'webp') !== false)
+ $type = 'image/webp';
}
}
@@ -205,7 +216,11 @@ function import_xchan_photo($photo, $xchan, $thing = false, $force = false) {
if($thing)
$hash = photo_new_resource();
else {
- $r = q("SELECT resource_id, edited, mimetype, expires, description FROM photo WHERE xchan = '%s' AND photo_usage = %d AND imgscale = 4 LIMIT 1", dbesc($xchan), intval(PHOTO_XCHAN));
+ $r = q("SELECT resource_id, edited, mimetype, expires, description FROM photo WHERE xchan = '%s' AND photo_usage = %d AND imgscale = %d LIMIT 1",
+ dbesc($xchan),
+ intval(PHOTO_XCHAN),
+ intval(PHOTO_RES_PROFILE_300)
+ );
if($r) {
$hash = $r[0]['resource_id'];
$modified = $r[0]['edited'];
@@ -220,7 +235,7 @@ function import_xchan_photo($photo, $xchan, $thing = false, $force = false) {
$photo_failure = false;
$img_str = '';
- if($photo) {
+ if($photo && strpos($photo, z_root() . '/' . get_default_profile_photo()) === false) {
if($force || empty($modified))
$result = z_fetch_url($photo, true);
@@ -260,7 +275,7 @@ function import_xchan_photo($photo, $xchan, $thing = false, $force = false) {
if($result['success']) {
$img_str = $result['body'];
- $type = guess_image_type($photo, $result['header']);
+ $type = guess_image_type($photo, $result);
if(is_null($type))
$photo_failure = true;
}
@@ -316,26 +331,20 @@ function import_xchan_photo($photo, $xchan, $thing = false, $force = false) {
'filename' => basename($photo),
'album' => $album,
'photo_usage' => $flags,
- 'imgscale' => 4,
'edited' => $modified,
'description' => (array_key_exists('etag', $hdrs) ? $hdrs['etag'] : ''),
'expires' => gmdate('Y-m-d H:i:s', (isset($expires) ? $expires : time() + 86400))
];
- $r = $img->save($p);
- if($r === false)
- $photo_failure = true;
+ $r1 = $img->storeThumbnail($p, PHOTO_RES_PROFILE_300);
$img->scaleImage(80);
- $p['imgscale'] = 5;
- $r = $img->save($p);
- if($r === false)
- $photo_failure = true;
+ $r2 = $img->storeThumbnail($p, PHOTO_RES_PROFILE_80);
$img->scaleImage(48);
- $p['imgscale'] = 6;
- $r = $img->save($p);
- if($r === false)
+ $r3 = $img->storeThumbnail($p, PHOTO_RES_PROFILE_48);
+
+ if($r1 === false || $r2 === false || $r3 === false)
$photo_failure = true;
$photo = z_root() . '/photo/' . $hash . '-4';
@@ -379,8 +388,7 @@ function import_channel_photo_from_url($photo, $aid, $uid) {
if($result['success']) {
$img_str = $result['body'];
- $type = guess_image_type($photo, $result['header']);
-
+ $type = guess_image_type($photo, $result);
import_channel_photo($img_str, $type, $aid, $uid);
}
}
@@ -401,8 +409,17 @@ function import_channel_photo($photo, $type, $aid, $uid) {
logger('Importing channel photo for ' . $uid, LOGGER_DEBUG);
+ $r = q("SELECT resource_id FROM photo WHERE uid = %d AND photo_usage = %d AND imgscale = %d",
+ intval($uid),
+ intval(PHOTO_PROFILE),
+ intval(PHOTO_RES_PROFILE_300)
+ );
+ if ($r)
+ $hash = $r[0]['resource_id'];
+ else
+ $hash = photo_new_resource();
+
$photo_failure = false;
- $hash = photo_new_resource();
$filename = $hash;
$img = photo_factory($photo, $type);
@@ -415,31 +432,26 @@ function import_channel_photo($photo, $type, $aid, $uid) {
'resource_id' => $hash,
'filename' => $filename,
'album' => t('Profile Photos'),
- 'photo_usage' => PHOTO_PROFILE,
- 'imgscale' => 4,
+ 'photo_usage' => PHOTO_PROFILE
];
// photo size
$img->scaleImageSquare(300);
- $r = $img->save($p);
- if($r === false)
- $photo_failure = true;
+ $r1 = $img->storeThumbnail($p, PHOTO_RES_PROFILE_300);
// thumb size
$img->scaleImage(80);
- $p['imgscale'] = 5;
- $r = $img->save($p);
- if($r === false)
- $photo_failure = true;
+ $r2 = $img->storeThumbnail($p, PHOTO_RES_PROFILE_80);
// micro size
$img->scaleImage(48);
- $p['imgscale'] = 6;
- $r = $img->save($p);
- if($r === false)
+ $r3 = $img->storeThumbnail($p, PHOTO_RES_PROFILE_48);
+
+ if($r1 === false || $r2 === false || $r3 === false)
$photo_failure = true;
- } else {
+ }
+ else {
logger('Invalid image.');
$photo_failure = true;
}
diff --git a/include/plugin.php b/include/plugin.php
index c789ad522..c789ad522 100755..100644
--- a/include/plugin.php
+++ b/include/plugin.php
diff --git a/include/security.php b/include/security.php
index c9df00f1e..40905925f 100644
--- a/include/security.php
+++ b/include/security.php
@@ -19,26 +19,26 @@ function authenticate_success($user_record, $channel = null, $login_initial = fa
$lastlog_updated = false;
- if(x($user_record, 'account_id')) {
+ if (x($user_record, 'account_id')) {
App::$account = $user_record;
$_SESSION['account_id'] = $user_record['account_id'];
$_SESSION['authenticated'] = 1;
- if($channel)
+ if ($channel)
$uid_to_load = $channel['channel_id'];
- if(! $uid_to_load) {
- $uid_to_load = (((x($_SESSION,'uid')) && (intval($_SESSION['uid'])))
+ if (!$uid_to_load) {
+ $uid_to_load = (((x($_SESSION, 'uid')) && (intval($_SESSION['uid'])))
? intval($_SESSION['uid'])
: intval(App::$account['account_default_channel'])
);
}
- if($uid_to_load) {
+ if ($uid_to_load) {
change_channel($uid_to_load);
}
- if($login_initial || $update_lastlog) {
+ if ($login_initial || $update_lastlog) {
q("update account set account_lastlog = '%s' where account_id = %d",
dbesc(datetime_convert()),
intval($_SESSION['account_id'])
@@ -50,24 +50,24 @@ function authenticate_success($user_record, $channel = null, $login_initial = fa
}
- if(($login_initial) && (! $lastlog_updated)) {
+ if (($login_initial) && (!$lastlog_updated)) {
call_hooks('logged_in', $user_record);
// might want to log success here
}
- if($return || x($_SESSION, 'workflow')) {
+ if ($return || x($_SESSION, 'workflow')) {
unset($_SESSION['workflow']);
return;
}
- if((App::$module !== 'home') && x($_SESSION,'login_return_url') && strlen($_SESSION['login_return_url'])) {
+ if ((App::$module !== 'home') && x($_SESSION, 'login_return_url') && strlen($_SESSION['login_return_url'])) {
$return_url = $_SESSION['login_return_url'];
// don't let members get redirected to a raw ajax page update - this can happen
// if DHCP changes the IP address at an unfortunate time and paranoia is turned on
- if(strstr($return_url,'update_'))
+ if (strstr($return_url, 'update_'))
$return_url = '';
unset($_SESSION['login_return_url']);
@@ -76,11 +76,11 @@ function authenticate_success($user_record, $channel = null, $login_initial = fa
/* This account has never created a channel. Send them to new_channel by default */
- if(App::$module === 'login') {
+ if (App::$module === 'login') {
$r = q("select count(channel_id) as total from channel where channel_account_id = %d and channel_removed = 0 ",
intval(App::$account['account_id'])
);
- if(($r) && (! $r[0]['total']))
+ if (($r) && (!$r[0]['total']))
goaway(z_root() . '/new_channel');
}
@@ -88,14 +88,14 @@ function authenticate_success($user_record, $channel = null, $login_initial = fa
}
function atoken_login($atoken) {
- if(! $atoken)
+ if (!$atoken)
return false;
$_SESSION['authenticated'] = 1;
$_SESSION['visitor_id'] = $atoken['xchan_hash'];
$_SESSION['atoken'] = $atoken['atoken_id'];
- \App::set_observer($atoken);
+ App::set_observer($atoken);
return true;
}
@@ -109,14 +109,14 @@ function atoken_login($atoken) {
function atoken_xchan($atoken) {
$c = channelx_by_n($atoken['atoken_uid']);
- if($c) {
+ if ($c) {
return [
'atoken_id' => $atoken['atoken_id'],
- 'xchan_hash' => substr($c['channel_hash'],0,16) . '.' . $atoken['atoken_name'],
+ 'xchan_hash' => substr($c['channel_hash'], 0, 16) . '.' . $atoken['atoken_name'],
'xchan_name' => $atoken['atoken_name'],
- 'xchan_addr' => 'guest:' . $atoken['atoken_name'] . '@' . \App::get_hostname(),
+ 'xchan_addr' => 'guest:' . $atoken['atoken_name'] . '@' . App::get_hostname(),
'xchan_network' => 'unknown',
- 'xchan_url' => z_root() . '/guest/' . substr($c['channel_hash'],0,16) . '.' . $atoken['atoken_name'],
+ 'xchan_url' => z_root() . '/guest/' . substr($c['channel_hash'], 0, 16) . '.' . $atoken['atoken_name'],
'xchan_hidden' => 1,
'xchan_photo_mimetype' => 'image/png',
'xchan_photo_l' => z_root() . '/' . get_default_profile_photo(300),
@@ -133,16 +133,16 @@ function atoken_delete($atoken_id) {
$r = q("select * from atoken where atoken_id = %d",
intval($atoken_id)
);
- if(! $r)
+ if (!$r)
return;
$c = q("select channel_id, channel_hash from channel where channel_id = %d",
intval($r[0]['atoken_uid'])
);
- if(! $c)
+ if (!$c)
return;
- $atoken_xchan = substr($c[0]['channel_hash'],0,16) . '.' . $r[0]['atoken_name'];
+ $atoken_xchan = substr($c[0]['channel_hash'], 0, 16) . '.' . $r[0]['atoken_name'];
q("delete from atoken where atoken_id = %d",
intval($atoken_id)
@@ -168,41 +168,41 @@ function atoken_create_xchan($xchan) {
$r = q("select xchan_hash from xchan where xchan_hash = '%s'",
dbesc($xchan['xchan_hash'])
);
- if($r)
+ if ($r)
return;
$xchan['xchan_guid'] = $xchan['xchan_hash'];
$store = [];
- foreach($xchan as $k => $v) {
- if(strpos($k,'xchan_') === 0) {
+ foreach ($xchan as $k => $v) {
+ if (strpos($k, 'xchan_') === 0) {
$store[$k] = $v;
}
}
-
- $r = xchan_store_lowlevel($store);
+
+ xchan_store_lowlevel($store);
return true;
}
-function atoken_abook($uid,$xchan_hash) {
+function atoken_abook($uid, $xchan_hash) {
- if(substr($xchan_hash,16,1) != '.')
+ if (substr($xchan_hash, 16, 1) != '.')
return false;
$r = q("select channel_hash from channel where channel_id = %d limit 1",
intval($uid)
);
- if(! $r)
+ if (!$r)
return false;
$x = q("select * from atoken where atoken_uid = %d and atoken_name = '%s'",
intval($uid),
- dbesc(substr($xchan_hash,17))
+ dbesc(substr($xchan_hash, 17))
);
- if($x) {
+ if ($x) {
$xchan = atoken_xchan($x[0]);
$xchan['abook_blocked'] = 0;
$xchan['abook_ignored'] = 0;
@@ -215,12 +215,12 @@ function atoken_abook($uid,$xchan_hash) {
function pseudo_abook($xchan) {
- if(! $xchan)
+ if (!$xchan)
return false;
// set abook_pseudo to flag that we aren't really connected.
- $xchan['abook_pseudo'] = 1;
+ $xchan['abook_pseudo'] = 1;
$xchan['abook_blocked'] = 0;
$xchan['abook_ignored'] = 0;
$xchan['abook_pending'] = 0;
@@ -240,7 +240,7 @@ function change_channel($change_channel) {
$ret = false;
- if($change_channel) {
+ if ($change_channel) {
$r = q("select channel.*, xchan.* from channel left join xchan on channel.channel_hash = xchan.xchan_hash where channel_id = %d and channel_account_id = %d and channel_removed = 0 limit 1",
intval($change_channel),
@@ -249,7 +249,7 @@ function change_channel($change_channel) {
// It's not there. Is this an administrator, and is this the sys channel?
if (is_developer()) {
- if (! $r) {
+ if (!$r) {
if (is_site_admin()) {
$r = q("select channel.*, xchan.* from channel left join xchan on channel.channel_hash = xchan.xchan_hash where channel_id = %d and channel_system = 1 and channel_removed = 0 limit 1",
intval($change_channel)
@@ -258,19 +258,19 @@ function change_channel($change_channel) {
}
}
- if($r) {
+ if ($r) {
$hash = $r[0]['channel_hash'];
$_SESSION['uid'] = intval($r[0]['channel_id']);
App::set_channel($r[0]);
$_SESSION['theme'] = $r[0]['channel_theme'];
- $_SESSION['mobile_theme'] = get_pconfig(local_channel(),'system', 'mobile_theme');
- $_SESSION['cloud_tiles'] = get_pconfig(local_channel(),'system', 'cloud_tiles');
+ $_SESSION['mobile_theme'] = get_pconfig(local_channel(), 'system', 'mobile_theme');
+ $_SESSION['cloud_tiles'] = get_pconfig(local_channel(), 'system', 'cloud_tiles');
date_default_timezone_set($r[0]['channel_timezone']);
// Update the active timestamp at most once a day
- if(substr($r[0]['channel_active'],0,10) !== substr(datetime_convert(),0,10)) {
- $z = q("UPDATE channel SET channel_active = '%s' WHERE channel_id = %d",
+ if (substr($r[0]['channel_active'], 0, 10) !== substr(datetime_convert(), 0, 10)) {
+ q("UPDATE channel SET channel_active = '%s' WHERE channel_id = %d",
dbesc(datetime_convert()),
intval($r[0]['channel_id'])
);
@@ -280,17 +280,17 @@ function change_channel($change_channel) {
$x = q("select * from xchan where xchan_hash = '%s' limit 1",
dbesc($hash)
);
- if($x) {
+ if ($x) {
$_SESSION['my_url'] = $x[0]['xchan_url'];
$_SESSION['my_address'] = channel_reddress($r[0]);
App::set_observer($x[0]);
App::set_perms(get_all_perms(local_channel(), $hash));
}
- if(! is_dir('store/' . $r[0]['channel_address']))
- @os_mkdir('store/' . $r[0]['channel_address'], STORAGE_DEFAULT_PERMISSIONS,true);
+ if (!is_dir('store/' . $r[0]['channel_address']))
+ @os_mkdir('store/' . $r[0]['channel_address'], STORAGE_DEFAULT_PERMISSIONS, true);
- $arr = [ 'channel_id' => $change_channel, 'chanx' => $ret ];
+ $arr = ['channel_id' => $change_channel, 'chanx' => $ret];
call_hooks('change_channel', $arr);
}
@@ -333,18 +333,17 @@ function permissions_sql($owner_id, $remote_observer = null, $table = '') {
if (($local_channel) && ($local_channel == $owner_id)) {
return EMPTY_STR;
}
-
/**
- * Authenticated visitor.
+ * Authenticated visitor.
*/
else {
- $observer = ((! is_null($remote_observer)) ? $remote_observer : get_observer_hash());
+ $observer = ((!is_null($remote_observer)) ? $remote_observer : get_observer_hash());
if ($observer) {
- $sec = get_security_ids($owner_id,$observer);
+ $sec = get_security_ids($owner_id, $observer);
// always allow the channel owner, even if authenticated as a visitor
@@ -354,14 +353,14 @@ function permissions_sql($owner_id, $remote_observer = null, $table = '') {
return EMPTY_STR;
}
}
- }
+ }
if (is_array($sec['allow_cid']) && count($sec['allow_cid'])) {
$ca = [];
foreach ($sec['allow_cid'] as $c) {
$ca[] = '<' . $c . '>';
}
- $cs = implode('|',$ca);
+ $cs = implode('|', $ca);
}
else {
$cs = '<<>>'; // should be impossible to match
@@ -372,7 +371,7 @@ function permissions_sql($owner_id, $remote_observer = null, $table = '') {
foreach ($sec['allow_gid'] as $g) {
$ga[] = '<' . $g . '>';
}
- $gs = implode('|',$ga);
+ $gs = implode('|', $ga);
}
else {
$gs = '<<>>'; // should be impossible to match
@@ -420,39 +419,38 @@ function item_permissions_sql($owner_id, $remote_observer = null) {
* Profile owner - everything is visible
*/
- if(($local_channel) && ($local_channel == $owner_id)) {
+ if (($local_channel) && ($local_channel == $owner_id)) {
$sql = '';
}
-
/**
- * Authenticated visitor.
+ * Authenticated visitor.
*/
else {
- $observer = (($remote_observer) ? $remote_observer : get_observer_hash());
+ $observer = (($remote_observer) ? $remote_observer : get_observer_hash());
- if($observer) {
+ if ($observer) {
- $scope = scopes_sql($owner_id,$observer);
- $sec = get_security_ids($owner_id,$observer);
+ $scope = scopes_sql($owner_id, $observer);
+ $sec = get_security_ids($owner_id, $observer);
// always allow the channel owner, even if authenticated as a visitor
- if($sec['channel_id']) {
- foreach($sec['channel_id'] as $ch) {
- if($observer === $ch) {
+ if ($sec['channel_id']) {
+ foreach ($sec['channel_id'] as $ch) {
+ if ($observer === $ch) {
return EMPTY_STR;
}
}
- }
+ }
if (is_array($sec['allow_cid']) && count($sec['allow_cid'])) {
$ca = [];
foreach ($sec['allow_cid'] as $c) {
$ca[] = '<' . $c . '>';
}
- $cs = implode('|',$ca);
+ $cs = implode('|', $ca);
}
else {
$cs = '<<>>'; // should be impossible to match
@@ -463,7 +461,7 @@ function item_permissions_sql($owner_id, $remote_observer = null) {
foreach ($sec['allow_gid'] as $g) {
$ga[] = '<' . $g . '>';
}
- $gs = implode('|',$ga);
+ $gs = implode('|', $ga);
}
else {
$gs = '<<>>'; // should be impossible to match
@@ -493,21 +491,20 @@ function item_permissions_sql($owner_id, $remote_observer = null) {
*/
-
-function scopes_sql($uid,$observer) {
+function scopes_sql($uid, $observer) {
$str = " and ( public_policy = 'authenticated' ";
- if(! is_foreigner($observer))
+ if (!is_foreigner($observer))
$str .= " or public_policy = 'network: red' ";
- if(local_channel())
+ if (local_channel())
$str .= " or public_policy = 'site: " . App::get_hostname() . "' ";
$ab = q("select * from abook where abook_xchan = '%s' and abook_channel = %d limit 1",
dbesc($observer),
intval($uid)
);
- if(! $ab)
+ if (!$ab)
return $str . " ) ";
- if($ab[0]['abook_pending'])
+ if ($ab[0]['abook_pending'])
$str .= " or public_policy = 'any connections' ";
$str .= " or public_policy = 'contacts' ) ";
return $str;
@@ -526,14 +523,14 @@ function public_permissions_sql($observer_hash) {
if ($observer_hash) {
- $sec = get_security_ids($owner_id,$observer_hash);
+ $sec = get_security_ids($owner_id, $observer_hash);
if (is_array($sec['allow_cid']) && count($sec['allow_cid'])) {
$ca = [];
foreach ($sec['allow_cid'] as $c) {
$ca[] = '<' . $c . '>';
}
- $cs = implode('|',$ca);
+ $cs = implode('|', $ca);
}
else {
$cs = '<<>>'; // should be impossible to match
@@ -544,7 +541,7 @@ function public_permissions_sql($observer_hash) {
foreach ($sec['allow_gid'] as $g) {
$ga[] = '<' . $g . '>';
}
- $gs = implode('|',$ga);
+ $gs = implode('|', $ga);
}
else {
$gs = '<<>>'; // should be impossible to match
@@ -598,7 +595,7 @@ function check_form_security_token($typename = '', $formname = 'form_security_to
$x = explode('.', $hash);
if (time() > (IntVal($x[0]) + $max_livetime) || time() < (IntVal($x[0]) + $min_livetime))
- return false;
+ return false;
$sec_hash = hash('whirlpool', App::$observer['xchan_guid'] . ((local_channel()) ? App::$channel['channel_prvkey'] : '') . session_id() . $x[0] . $typename);
@@ -606,16 +603,19 @@ function check_form_security_token($typename = '', $formname = 'form_security_to
}
function check_form_security_std_err_msg() {
+ /** @noinspection PhpToStringImplementationInspection */
return t('The form security token was not correct. This probably happened because the form has been opened for too long (>3 hours) before submitting it.') . EOL;
}
+
function check_form_security_token_redirectOnErr($err_redirect, $typename = '', $formname = 'form_security_token') {
if (!check_form_security_token($typename, $formname)) {
logger('check_form_security_token failed: user ' . App::$observer['xchan_name'] . ' - form element ' . $typename);
logger('check_form_security_token failed: _REQUEST data: ' . print_r($_REQUEST, true), LOGGER_DATA);
- notice( check_form_security_std_err_msg() );
- goaway(z_root() . $err_redirect );
+ notice(check_form_security_std_err_msg());
+ goaway(z_root() . $err_redirect);
}
}
+
function check_form_security_token_ForbiddenOnErr($typename = '', $formname = 'form_security_token') {
if (!check_form_security_token($typename, $formname)) {
logger('check_form_security_token failed: user ' . App::$observer['xchan_name'] . ' - form element ' . $typename);
@@ -636,7 +636,7 @@ function init_groups_visitor($contact_id) {
dbesc($contact_id)
);
- if (! $x) {
+ if (!$x) {
return $groups;
}
@@ -648,8 +648,8 @@ function init_groups_visitor($contact_id) {
dbesc($x[0]['xchan_pubkey'])
);
- if($xchans) {
- $hashes = ids_to_querystr($xchans,'xchan_hash',true);
+ if ($xchans) {
+ $hashes = ids_to_querystr($xchans, 'xchan_hash', true);
}
// private profiles are treated as a virtual group
@@ -672,21 +672,19 @@ function init_groups_visitor($contact_id) {
}
-
-
function get_security_ids($channel_id, $ob_hash) {
- $ret = [
- 'channel_id' => [],
- 'allow_cid' => [],
- 'allow_gid' => []
+ $ret = [
+ 'channel_id' => [],
+ 'allow_cid' => [],
+ 'allow_gid' => []
];
- if($channel_id) {
+ if ($channel_id) {
$ch = q("select channel_hash, channel_portable_id from channel where channel_id = %d",
- intval($channel_id)
+ intval($channel_id)
);
- if($ch) {
+ if ($ch) {
$ret['channel_id'][] = $ch[0]['channel_hash'];
$ret['channel_id'][] = $ch[0]['channel_portable_id'];
}
@@ -709,13 +707,13 @@ function get_security_ids($channel_id, $ob_hash) {
);
if ($xchans) {
- $ret['allow_cid'] = ids_to_array($xchans,'xchan_hash');
- $hashes = ids_to_querystr($xchans,'xchan_hash',true);
+ $ret['allow_cid'] = ids_to_array($xchans, 'xchan_hash');
+ $hashes = ids_to_querystr($xchans, 'xchan_hash', true);
// private profiles are treated as a virtual group
$r = q("SELECT abook_profile from abook where abook_xchan in ( " . protect_sprintf($hashes) . " ) and abook_profile != '' ");
- if($r) {
+ if ($r) {
foreach ($r as $rv) {
$groups[] = 'vp.' . $rv['abook_profile'];
}
@@ -724,7 +722,7 @@ function get_security_ids($channel_id, $ob_hash) {
// physical groups this identity is a member of
$r = q("SELECT hash FROM pgrp left join pgrp_member on pgrp.id = pgrp_member.gid WHERE xchan in ( " . protect_sprintf($hashes) . " ) ");
- if($r) {
+ if ($r) {
foreach ($r as $rv) {
$groups[] = $rv['hash'];
}
@@ -746,39 +744,39 @@ function get_security_ids($channel_id, $ob_hash) {
// will likely be too expensive.
// Returns a string list of comma separated channel_ids suitable for direct inclusion in a SQL query
-function stream_perms_api_uids($perms = NULL, $limit = 0, $rand = 0 ) {
- $perms = is_null($perms) ? (PERMS_SITE|PERMS_NETWORK|PERMS_PUBLIC) : $perms;
+function stream_perms_api_uids($perms = NULL, $limit = 0, $rand = 0) {
+ $perms = is_null($perms) ? (PERMS_SITE | PERMS_NETWORK | PERMS_PUBLIC) : $perms;
$ret = array();
$limit_sql = (($limit) ? " LIMIT " . intval($limit) . " " : '');
$random_sql = (($rand) ? " ORDER BY " . db_getfunc('RAND') . " " : '');
- if(local_channel())
+ if (local_channel())
$ret[] = local_channel();
$x = q("select uid, v from pconfig where cat = 'perm_limits' and k = 'view_stream' ");
- if($x) {
+ if ($x) {
$y = [];
- foreach($x as $xv) {
- if(intval($xv['v']) & $perms) {
+ foreach ($x as $xv) {
+ if (intval($xv['v']) & $perms) {
$y[] = $xv;
}
}
- if($y) {
- $ids = ids_to_querystr($y,'uid');
+ if ($y) {
+ $ids = ids_to_querystr($y, 'uid');
$r = q("select channel_id from channel where channel_id in ( $ids ) and ( channel_pageflags & %d ) = 0 and channel_system = 0 and channel_removed = 0 $random_sql $limit_sql ",
- intval(PAGE_ADULT|PAGE_CENSORED)
+ intval(PAGE_ADULT | PAGE_CENSORED)
);
- if($r) {
- foreach($r as $rr)
- if(! in_array($rr['channel_id'], $ret))
+ if ($r) {
+ foreach ($r as $rr)
+ if (!in_array($rr['channel_id'], $ret))
$ret[] = $rr['channel_id'];
}
}
}
$str = '';
- if($ret) {
- foreach($ret as $rr) {
- if($str)
+ if ($ret) {
+ foreach ($ret as $rr) {
+ if ($str)
$str .= ',';
$str .= intval($rr);
}
@@ -791,39 +789,39 @@ function stream_perms_api_uids($perms = NULL, $limit = 0, $rand = 0 ) {
return $str;
}
-function stream_perms_xchans($perms = NULL ) {
- $perms = is_null($perms) ? (PERMS_SITE|PERMS_NETWORK|PERMS_PUBLIC) : $perms;
+function stream_perms_xchans($perms = NULL) {
+ $perms = is_null($perms) ? (PERMS_SITE | PERMS_NETWORK | PERMS_PUBLIC) : $perms;
$ret = array();
- if(local_channel())
+ if (local_channel())
$ret[] = get_observer_hash();
$x = q("select uid, v from pconfig where cat = 'perm_limits' and k = 'view_stream' ");
- if($x) {
+ if ($x) {
$y = [];
- foreach($x as $xv) {
- if(intval($xv['v']) & $perms) {
+ foreach ($x as $xv) {
+ if (intval($xv['v']) & $perms) {
$y[] = $xv;
}
}
- if($y) {
- $ids = ids_to_querystr($y,'uid');
+ if ($y) {
+ $ids = ids_to_querystr($y, 'uid');
$r = q("select channel_hash from channel where channel_id in ( $ids ) and ( channel_pageflags & %d ) = 0 and channel_system = 0 and channel_removed = 0 ",
- intval(PAGE_ADULT|PAGE_CENSORED)
+ intval(PAGE_ADULT | PAGE_CENSORED)
);
- if($r) {
- foreach($r as $rr)
- if(! in_array($rr['channel_hash'], $ret))
+ if ($r) {
+ foreach ($r as $rr)
+ if (!in_array($rr['channel_hash'], $ret))
$ret[] = $rr['channel_hash'];
}
}
}
$str = '';
- if($ret) {
- foreach($ret as $rr) {
- if($str)
+ if ($ret) {
+ foreach ($ret as $rr) {
+ if ($str)
$str .= ',';
$str .= "'" . dbesc($rr) . "'";
}
diff --git a/include/taxonomy.php b/include/taxonomy.php
index e06568d19..7745b6a5b 100644
--- a/include/taxonomy.php
+++ b/include/taxonomy.php
@@ -354,30 +354,32 @@ function pub_tagadelic($net,$site,$limit,$recent,$safemode,$type) {
$sql_extra .= " and not term.term in ( " . stringify_array($unsafetags,true) . ") ";
}
}
-
-
- $key = __FUNCTION__ . "-" . md5($site . $recent . $safemode . $limit . $type);
- $content = Cache::get($key, '1 MINUTE');
-
- if(! $content) {
- // Fetch tags
- $r = q("SELECT term, count(term) AS total FROM term LEFT JOIN item ON term.oid = item.id
- where term.ttype = %d
- and otype = %d and item_type = %d
- $sql_extra $uids $item_normal
- group by term order by total desc %s",
- intval($type),
- intval(TERM_OBJ_POST),
- intval(ITEM_TYPE_POST),
- ((intval($count)) ? "limit $count" : '')
- );
- } else
- $r = unserialize($content);
-
- if(! $r)
- return array();
- else
- Cache::set($key, serialize($r));
+
+ $key = __FUNCTION__ . "-" . md5($site . $recent . $safemode . $limit . $type);
+
+ $content = Cache::get($key, '5 MINUTE');
+ if(! $content) {
+
+ $content = Cache::get($key, '1 MONTH');
+ $arr = [
+ "SELECT term, count(term) AS total FROM term LEFT JOIN item ON term.oid = item.id
+ WHERE term.ttype = %d
+ AND otype = %d
+ AND item_type = %d
+ $sql_extra $uids $item_normal
+ GROUP BY term ORDER BY total DESC %s",
+ intval($type),
+ intval(TERM_OBJ_POST),
+ intval(ITEM_TYPE_POST),
+ (intval($count) ? "LIMIT $count" : '')
+ ];
+
+ \Zotlabs\Daemon\Master::Summon([ 'Cache_query', $key, base64_encode(json_encode($arr)) ]);
+ }
+
+ $r = unserialize($content);
+ if(! $r)
+ return [];
return Zotlabs\Text\Tagadelic::calc($r);
}
diff --git a/include/text.php b/include/text.php
index 76df9e17b..1e08d136c 100644
--- a/include/text.php
+++ b/include/text.php
@@ -7,7 +7,7 @@ use Zotlabs\Lib as Zlib;
use Michelf\MarkdownExtra;
use Ramsey\Uuid\Uuid;
-use Ramsey\Uuid\Exception\UnsatisfiedDependencyException;
+use Ramsey\Uuid\Exception\UnableToBuildUuidException;
use Zotlabs\Lib\SvgSanitizer;
@@ -1801,7 +1801,7 @@ function prepare_body(&$item,$attach = false,$opts = false) {
$tags = format_hashtags($item);
- if($item['resource_type'])
+ if($item['resource_type'] == 'photo')
$mentions = format_mentions($item);
$categories = format_categories($item,$writeable);
@@ -3824,7 +3824,7 @@ function new_uuid() {
try {
$hash = Uuid::uuid4()->toString();
- } catch (UnsatisfiedDependencyException $e) {
+ } catch (UnableToBuildUuidException $e) {
$hash = random_string(48);
}
@@ -3842,7 +3842,7 @@ function uuid_from_url($url) {
try {
$hash = Uuid::uuid5(Uuid::NAMESPACE_URL, $url)->toString();
- } catch (UnsatisfiedDependencyException $e) {
+ } catch (UnableToBuildUuidException $e) {
$hash = md5($url);
}
return $hash;