diff options
Diffstat (limited to 'mod')
82 files changed, 2001 insertions, 2146 deletions
diff --git a/mod/acl.php b/mod/acl.php index e919bb912..dc29e3eff 100644 --- a/mod/acl.php +++ b/mod/acl.php @@ -90,23 +90,21 @@ function acl_init(&$a){ // Getting info from the abook is better for local users because it contains info about permissions if(local_channel()) { if($extra_channels_sql != '') - $extra_channels_sql = " OR (abook_channel IN ($extra_channels_sql)) and not (abook_flags & ". intval(ABOOK_FLAG_HIDDEN) . ') > 0'; + $extra_channels_sql = " OR (abook_channel IN ($extra_channels_sql)) and abook_hidden = 0 "; - $r = q("SELECT abook_id as id, xchan_hash as hash, xchan_name as name, xchan_photo_s as micro, xchan_url as url, xchan_addr as nick, abook_their_perms, abook_flags + $r = q("SELECT abook_id as id, xchan_hash as hash, xchan_name as name, xchan_photo_s as micro, xchan_url as url, xchan_addr as nick, abook_their_perms, abook_flags, abook_self FROM abook left join xchan on abook_xchan = xchan_hash - WHERE (abook_channel = %d $extra_channels_sql) AND not ( abook_flags & %d )>0 and not (xchan_flags & %d )>0 $sql_extra2 order by $order_extra2 xchan_name asc" , - intval(local_channel()), - intval(ABOOK_FLAG_BLOCKED|ABOOK_FLAG_PENDING|ABOOK_FLAG_ARCHIVED), - intval(XCHAN_FLAGS_DELETED) + WHERE (abook_channel = %d $extra_channels_sql) AND abook_blocked = 0 and abook_pending = 0 and abook_archived = 0 and xchan_deleted = 0 $sql_extra2 order by $order_extra2 xchan_name asc" , + intval(local_channel()) ); } else { // Visitors - $r = q("SELECT xchan_hash as id, xchan_hash as hash, xchan_name as name, xchan_photo_s as micro, xchan_url as url, xchan_addr as nick, 0 as abook_their_perms, 0 as abook_flags + $r = q("SELECT xchan_hash as id, xchan_hash as hash, xchan_name as name, xchan_photo_s as micro, xchan_url as url, xchan_addr as nick, 0 as abook_their_perms, 0 as abook_flags, 0 as abook_self FROM xchan left join xlink on xlink_link = xchan_hash - WHERE xlink_xchan = '%s' AND NOT (xchan_flags & %d) > 0 $sql_extra2 order by $order_extra2 xchan_name asc" , - dbesc(get_observer_hash()), - intval(XCHAN_FLAGS_DELETED)); + WHERE xlink_xchan = '%s' AND xchan_deleted = 0 $sql_extra2 order by $order_extra2 xchan_name asc" , + dbesc(get_observer_hash()) + ); // Find contacts of extra channels // This is probably more complicated than it needs to be @@ -118,12 +116,9 @@ function acl_init(&$a){ $known_hashes[] = "'".$rr['hash']."'"; $known_hashes_sql = 'AND xchan_hash not in ('.join(',',$known_hashes).')'; - $r2 = q("SELECT abook_id as id, xchan_hash as hash, xchan_name as name, xchan_photo_s as micro, xchan_url as url, xchan_addr as nick, abook_their_perms, abook_flags + $r2 = q("SELECT abook_id as id, xchan_hash as hash, xchan_name as name, xchan_photo_s as micro, xchan_url as url, xchan_addr as nick, abook_their_perms, abook_flags, abook_self FROM abook left join xchan on abook_xchan = xchan_hash - WHERE abook_channel IN ($extra_channels_sql) $known_hashes_sql AND not ( abook_flags & %d )>0 and not (xchan_flags & %d )>0 $sql_extra2 order by $order_extra2 xchan_name asc" , - intval(ABOOK_FLAG_BLOCKED|ABOOK_FLAG_PENDING|ABOOK_FLAG_ARCHIVED|ABOOK_FLAG_HIDDEN), - intval(XCHAN_FLAGS_DELETED) - ); + WHERE abook_channel IN ($extra_channels_sql) $known_hashes_sql AND abook_blocked = 0 and abook_pending = 0 and abook_archived = 0 and abook_hidden = 0 and xchan_deleted = 0 $sql_extra2 order by $order_extra2 xchan_name asc"); if($r2) $r = array_merge($r,$r2); @@ -150,10 +145,9 @@ function acl_init(&$a){ } if(intval(get_config('system','taganyone')) || intval(get_pconfig(local_channel(),'system','taganyone'))) { if((count($r) < 100) && $type == 'c') { - $r2 = q("SELECT substr(xchan_hash,1,18) as id, xchan_hash as hash, xchan_name as name, xchan_photo_s as micro, xchan_url as url, xchan_addr as nick, 0 as abook_their_perms, 0 as abook_flags + $r2 = q("SELECT substr(xchan_hash,1,18) as id, xchan_hash as hash, xchan_name as name, xchan_photo_s as micro, xchan_url as url, xchan_addr as nick, 0 as abook_their_perms, 0 as abook_flags, 0 as abook_self FROM xchan - WHERE not (xchan_flags & %d )>0 $sql_extra2 order by $order_extra2 xchan_name asc" , - intval(XCHAN_FLAGS_DELETED) + WHERE xchan_deleted = 0 $sql_extra2 order by $order_extra2 xchan_name asc" ); if($r2) $r = array_merge($r,$r2); @@ -165,24 +159,21 @@ function acl_init(&$a){ $r = q("SELECT xchan_hash as id, xchan_name as name, xchan_addr as nick, xchan_photo_s as micro, xchan_url as url FROM abook left join xchan on abook_xchan = xchan_hash WHERE abook_channel = %d and ( (abook_their_perms = null) or (abook_their_perms & %d )>0) - and not (xchan_flags & %d)>0 + and xchan_deleted = 0 $sql_extra3 ORDER BY `xchan_name` ASC ", intval(local_channel()), - intval(PERMS_W_MAIL), - intval(XCHAN_FLAGS_DELETED) + intval(PERMS_W_MAIL) ); } elseif(($type == 'a') || ($type == 'p')) { $r = q("SELECT abook_id as id, xchan_name as name, xchan_hash as hash, xchan_addr as nick, xchan_photo_s as micro, xchan_network as network, xchan_url as url, xchan_addr as attag , abook_their_perms FROM abook left join xchan on abook_xchan = xchan_hash WHERE abook_channel = %d - and not (xchan_flags & %d)>0 + and xchan_deleted = 0 $sql_extra3 ORDER BY xchan_name ASC ", - intval(local_channel()), - intval(XCHAN_FLAGS_DELETED) - + intval(local_channel()) ); } @@ -226,7 +217,7 @@ function acl_init(&$a){ "xid" => $g['hash'], "link" => $g['nick'], "nick" => substr($g['nick'],0,strpos($g['nick'],'@')), - "self" => (($g['abook_flags'] & ABOOK_FLAG_SELF) ? 'abook-self' : ''), + "self" => (intval($g['abook_self']) ? 'abook-self' : ''), "taggable" => 'taggable', "label" => t('network') ); @@ -239,7 +230,7 @@ function acl_init(&$a){ "xid" => $g['hash'], "link" => $g['nick'], "nick" => (($g['nick']) ? substr($g['nick'],0,strpos($g['nick'],'@')) : t('RSS')), - "self" => (($g['abook_flags'] & ABOOK_FLAG_SELF) ? 'abook-self' : ''), + "self" => (intval($g['abook_self']) ? 'abook-self' : ''), "taggable" => '', "label" => '', ); diff --git a/mod/admin.php b/mod/admin.php index beb629396..2b7bb007d 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -1,7 +1,7 @@ <?php /** * @file mod/admin.php - * @brief RedMatrix's admin controller. + * @brief Hubzilla's admin controller. * * Controller for the /admin/ area. */ @@ -84,46 +84,6 @@ function admin_content(&$a) { return login(false); } - /* - * Side bar links - */ - - // array( url, name, extra css classes ) - $aside = array( - 'site' => array($a->get_baseurl(true)."/admin/site/", t("Site") , "site"), - 'users' => array($a->get_baseurl(true)."/admin/users/", t("Accounts") , "users"), - 'channels' => array($a->get_baseurl(true)."/admin/channels/", t("Channels") , "channels"), - 'plugins' => array($a->get_baseurl(true)."/admin/plugins/", t("Plugins") , "plugins"), - 'themes' => array($a->get_baseurl(true)."/admin/themes/", t("Themes") , "themes"), - 'queue' => array(z_root() . '/admin/queue', t('Inspect queue'), 'queue'), -// 'hubloc' => array($a->get_baseurl(true)."/admin/hubloc/", t("Server") , "server"), - 'profs' => array(z_root() . '/admin/profs', t('Profile Config'), 'profs'), - 'dbsync' => array($a->get_baseurl(true)."/admin/dbsync/", t('DB updates'), "dbsync") - ); - - /* get plugins admin page */ - - $r = q("SELECT * FROM addon WHERE plugin_admin = 1"); - $aside['plugins_admin'] = array(); - foreach ($r as $h){ - $plugin = $h['name']; - $aside['plugins_admin'][] = array($a->get_baseurl(true) . '/admin/plugins/' . $plugin, $plugin, 'plugin'); - // temp plugins with admin - $a->plugins_admin[] = $plugin; - } - - $aside['logs'] = Array($a->get_baseurl(true)."/admin/logs/", t("Logs"), "logs"); - - $t = get_markup_template("admin_aside.tpl"); - $a->page['aside'] .= replace_macros( $t, array( - '$admin' => $aside, - '$admtxt' => t('Admin'), - '$plugadmtxt' => t('Plugin Features'), - '$logtxt' => t('Logs'), - '$h_pending' => t('User registrations waiting for confirmation'), - '$admurl'=> $a->get_baseurl(true)."/admin/" - )); - /* * Page content @@ -148,9 +108,9 @@ function admin_content(&$a) { case 'themes': $o = admin_page_themes($a); break; - case 'hubloc': - $o = admin_page_hubloc($a); - break; +// case 'hubloc': +// $o = admin_page_hubloc($a); +// break; case 'logs': $o = admin_page_logs($a); break; @@ -209,9 +169,7 @@ function admin_page_summary(&$a) { // available channels, primary and clones $channels = array(); - $r = q("SELECT COUNT(*) AS total, COUNT(CASE WHEN channel_primary = 1 THEN 1 ELSE NULL END) AS main, COUNT(CASE WHEN channel_primary = 0 THEN 1 ELSE NULL END) AS clones FROM channel WHERE NOT (channel_pageflags & %d)>0", - intval(PAGE_REMOVED) - ); + $r = q("SELECT COUNT(*) AS total, COUNT(CASE WHEN channel_primary = 1 THEN 1 ELSE NULL END) AS main, COUNT(CASE WHEN channel_primary = 0 THEN 1 ELSE NULL END) AS clones FROM channel WHERE channel_removed = 0"); if ($r) { $channels['total'] = array('label' => t('# Channels'), 'val' => $r[0]['total']); $channels['main'] = array('label' => t('# primary'), 'val' => $r[0]['main']); @@ -299,11 +257,9 @@ function admin_page_site_post(&$a){ $poll_interval = ((x($_POST,'poll_interval')) ? intval(trim($_POST['poll_interval'])) : 0); $maxloadavg = ((x($_POST,'maxloadavg')) ? intval(trim($_POST['maxloadavg'])) : 50); $feed_contacts = ((x($_POST,'feed_contacts')) ? intval($_POST['feed_contacts']) : 0); - $diaspora_enabled = ((x($_POST,'diaspora_enabled')) ? intval($_POST['diaspora_enabled']) : 0); $verify_email = ((x($_POST,'verify_email')) ? 1 : 0); set_config('system', 'feed_contacts', $feed_contacts); - set_config('system', 'diaspora_enabled', $diaspora_enabled); set_config('system', 'delivery_interval', $delivery_interval); set_config('system', 'poll_interval', $poll_interval); set_config('system', 'maxloadavg', $maxloadavg); @@ -465,7 +421,6 @@ function admin_page_site(&$a) { '$theme' => array('theme', t("System theme"), get_config('system','theme'), t("Default system theme - may be over-ridden by user profiles - <a href='#' id='cnftheme'>change theme settings</a>"), $theme_choices), '$theme_mobile' => array('theme_mobile', t("Mobile system theme"), get_config('system','mobile_theme'), t("Theme for mobile devices"), $theme_choices_mobile), // '$site_channel' => array('site_channel', t("Channel to use for this website's static pages"), get_config('system','site_channel'), t("Site Channel")), - '$diaspora_enabled' => array('diaspora_enabled',t('Enable Diaspora Protocol'), get_config('system','diaspora_enabled'), t('Communicate with Diaspora and Friendica - experimental')), '$feed_contacts' => array('feed_contacts', t('Allow Feeds as Connections'),get_config('system','feed_contacts'),t('(Heavy system resource usage)')), '$maximagesize' => array('maximagesize', t("Maximum image size"), intval(get_config('system','maximagesize')), t("Maximum size in bytes of uploaded images. Default is 0, which means no limits.")), '$register_policy' => array('register_policy', t("Does this site allow new member registration?"), get_config('system','register_policy'), "", $register_choices), @@ -786,11 +741,10 @@ function admin_page_users(&$a){ $users = q("SELECT `account_id` , `account_email`, `account_lastlog`, `account_created`, `account_expires`, " . "`account_service_class`, ( account_flags & %d )>0 as `blocked`, " . "(SELECT %s FROM channel as ch " . - "WHERE ch.channel_account_id = ac.account_id and not (ch.channel_pageflags & %d )>0) as `channels` " . + "WHERE ch.channel_account_id = ac.account_id and ch.channel_removed = 0 ) as `channels` " . "FROM account as ac where true $serviceclass $order limit %d offset %d ", intval(ACCOUNT_BLOCKED), db_concat('ch.channel_address', ' '), - intval(PAGE_REMOVED), intval($a->pager['itemspage']), intval($a->pager['start']) ); @@ -948,9 +902,7 @@ function admin_page_channels(&$a){ /* get channels */ - $total = q("SELECT count(*) as total FROM channel where not (channel_pageflags & %d)>0", - intval(PAGE_REMOVED|PAGE_SYSTEM) - ); + $total = q("SELECT count(*) as total FROM channel where channel_removed = 0 and channel_system = 0"); if($total) { $a->set_pager_total($total[0]['total']); $a->set_pager_itemspage(100); @@ -958,8 +910,7 @@ function admin_page_channels(&$a){ $order = " order by channel_name asc "; - $channels = q("SELECT * from channel where not ( channel_pageflags & %d )>0 $order limit %d offset %d ", - intval(PAGE_REMOVED|PAGE_SYSTEM), + $channels = q("SELECT * from channel where channel_removed = 0 and channel_system = 0 $order limit %d offset %d ", intval($a->pager['itemspage']), intval($a->pager['start']) ); @@ -1477,4 +1428,4 @@ function admin_page_profs(&$a) { '$submit' => t('Save') )); } -}
\ No newline at end of file +} diff --git a/mod/attach.php b/mod/attach.php index 118c67dd5..ad5dead07 100644 --- a/mod/attach.php +++ b/mod/attach.php @@ -35,7 +35,7 @@ function attach_init(&$a) { } header('Content-disposition: attachment; filename="' . $r['data']['filename'] . '"'); - if($r['data']['flags'] & ATTACH_FLAG_OS ) { + if(intval($r['data']['os_storage'])) { $fname = dbunescbin($r['data']['data']); $istream = fopen('store/' . $c[0]['channel_address'] . '/' . $fname,'rb'); $ostream = fopen('php://output','wb'); diff --git a/mod/block.php b/mod/block.php index 043b0e9e8..df3909629 100644 --- a/mod/block.php +++ b/mod/block.php @@ -50,10 +50,10 @@ function block_content(&$a) { $r = q("select item.* from item left join item_id on item.id = item_id.iid where item.uid = %d and sid = '%s' and service = 'BUILDBLOCK' and - item_restrict = %d $sql_options $revision limit 1", + item_type = %d $sql_options $revision limit 1", intval($u[0]['channel_id']), dbesc($page_id), - intval(ITEM_BUILDBLOCK) + intval(ITEM_TYPE_BLOCK) ); if(! $r) { @@ -62,10 +62,10 @@ function block_content(&$a) { $x = q("select item.* from item left join item_id on item.id = item_id.iid where item.uid = %d and sid = '%s' and service = 'BUILDBLOCK' and - item_restrict = %d $revision limit 1", + item_type = %d $revision limit 1", intval($u[0]['channel_id']), dbesc($page_id), - intval(ITEM_BUILDBLOCK) + intval(ITEM_TYPE_BLOCK) ); if($x) { // Yes, it's there. You just aren't allowed to see it. diff --git a/mod/blocks.php b/mod/blocks.php index 11e7d4a30..97cc5cd53 100644 --- a/mod/blocks.php +++ b/mod/blocks.php @@ -84,7 +84,7 @@ function blocks_content(&$a) { } $x = array( - 'webpage' => ITEM_BUILDBLOCK, + 'webpage' => ITEM_TYPE_BLOCK, 'is_owner' => true, 'nickname' => $a->profile['channel_address'], 'lockstate' => (($channel['channel_allow_cid'] || $channel['channel_allow_gid'] || $channel['channel_deny_cid'] || $channel['channel_deny_gid']) ? 'lock' : 'unlock'), @@ -108,9 +108,9 @@ function blocks_content(&$a) { $editor = status_editor($a,$x); $r = q("select iid, sid, mid, title, body, mimetype, created, edited from item_id left join item on item_id.iid = item.id - where item_id.uid = %d and service = 'BUILDBLOCK' and item_restrict = %d order by item.created desc", + where item_id.uid = %d and service = 'BUILDBLOCK' and item_type = %d order by item.created desc", intval($owner), - intval(ITEM_BUILDBLOCK) + intval(ITEM_TYPE_BLOCK) ); $pages = null; @@ -143,21 +143,21 @@ function blocks_content(&$a) { $url = z_root() . '/editblock/' . $which; $o .= replace_macros(get_markup_template('blocklist.tpl'), array( - '$baseurl' => $url, - '$title' => t('Blocks'), - '$name' => t('Block Name'), + '$baseurl' => $url, + '$title' => t('Blocks'), + '$name' => t('Block Name'), '$blocktitle' => t('Block Title'), - '$created' => t('Created'), - '$edited' => t('Edited'), - '$create' => t('Create'), - '$edit' => t('Edit'), - '$share' => t('Share'), - '$delete' => t('Delete'), - '$editor' => $editor, - '$pages' => $pages, - '$channel' => $which, - '$view' => t('View'), - '$preview' => '1', + '$created' => t('Created'), + '$edited' => t('Edited'), + '$create' => t('Create'), + '$edit' => t('Edit'), + '$share' => t('Share'), + '$delete' => t('Delete'), + '$editor' => $editor, + '$pages' => $pages, + '$channel' => $which, + '$view' => t('View'), + '$preview' => '1', )); return $o; diff --git a/mod/bookmarks.php b/mod/bookmarks.php index a5b9c473f..c3d25253f 100644 --- a/mod/bookmarks.php +++ b/mod/bookmarks.php @@ -9,7 +9,9 @@ function bookmarks_init(&$a) { $u = $a->get_channel(); - $i = q("select * from item where id = %d and uid = %d limit 1", + $item_normal = item_normal(); + + $i = q("select * from item where id = %d and uid = %d $item_normal limit 1", intval($item_id), intval(local_channel()) ); @@ -23,7 +25,7 @@ function bookmarks_init(&$a) { $terms = get_terms_oftype($item['term'],TERM_BOOKMARK); - if($terms && (! $item['item_restrict'])) { + if($terms) { require_once('include/bookmarks.php'); $s = q("select * from xchan where xchan_hash = '%s' limit 1", diff --git a/mod/branchtopic.php b/mod/branchtopic.php index 609cb19ec..d49bbaf4c 100644 --- a/mod/branchtopic.php +++ b/mod/branchtopic.php @@ -33,8 +33,7 @@ function branchtopic_init(&$a) { intval(local_channel()) ); - $x = q("update item set parent = id, route = '', item_flags = (item_flags | %d) where id = %d", - intval(ITEM_THREAD_TOP), + $x = q("update item set parent = id, route = '', item_thread_top = 1 where id = %d", intval($item_id) ); diff --git a/mod/channel.php b/mod/channel.php index b06602994..d1064e939 100644 --- a/mod/channel.php +++ b/mod/channel.php @@ -145,7 +145,7 @@ function channel_content(&$a, $update = 0, $load = false) { * Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups */ - + $item_normal = item_normal(); $sql_extra = item_permissions_sql($a->profile['profile_uid']); if(get_pconfig($a->profile['profile_uid'],'system','channel_list_mode') && (! $mid)) @@ -165,23 +165,20 @@ function channel_content(&$a, $update = 0, $load = false) { if(($update) && (! $load)) { if ($mid) { - $r = q("SELECT parent AS item_id from item where mid like '%s' and uid = %d AND item_restrict = 0 - AND (item_flags & %d) > 0 $simple_update $sql_extra limit 1", + $r = q("SELECT parent AS item_id from item where mid like '%s' and uid = %d $item_normal + AND item_wall = 1 AND item_unseen = 1 $sql_extra limit 1", dbesc($mid . '%'), - intval($a->profile['profile_uid']), - intval(ITEM_WALL) + intval($a->profile['profile_uid']) ); } else { $r = q("SELECT distinct parent AS `item_id`, created from item left join abook on ( item.owner_xchan = abook.abook_xchan $abook_uids ) - WHERE uid = %d AND item_restrict = 0 - AND (item_flags & %d) > 0 $simple_update - AND ((abook.abook_flags & %d) = 0 or abook.abook_flags is null) + WHERE uid = %d $item_normal + AND item_wall = 1 AND item_unseen = 1 + AND (abook.abook_blocked = 0 or abook.abook_flags is null) $sql_extra ORDER BY created DESC", - intval($a->profile['profile_uid']), - intval(ITEM_WALL), - intval(ABOOK_FLAG_BLOCKED) + intval($a->profile['profile_uid']) ); $_SESSION['loadtime'] = datetime_convert(); } @@ -209,11 +206,10 @@ function channel_content(&$a, $update = 0, $load = false) { if($load || ($_COOKIE['jsAvailable'] != 1)) { if ($mid) { - $r = q("SELECT parent AS item_id from item where mid = '%s' and uid = %d AND item_restrict = 0 - AND (item_flags & %d)>0 $sql_extra limit 1", + $r = q("SELECT parent AS item_id from item where mid = '%s' and uid = %d $item_normal + AND item_wall = 1 $sql_extra limit 1", dbesc($mid), - intval($a->profile['profile_uid']), - intval(ITEM_WALL) + intval($a->profile['profile_uid']) ); if (! $r) { notice( t('Permission denied.') . EOL); @@ -222,15 +218,12 @@ function channel_content(&$a, $update = 0, $load = false) { } else { $r = q("SELECT distinct id AS item_id, created FROM item left join abook on item.author_xchan = abook.abook_xchan - WHERE uid = %d AND item_restrict = 0 - AND (item_flags & %d)>0 and (item_flags & %d)>0 - AND ((abook.abook_flags & %d) = 0 or abook.abook_flags is null) + WHERE uid = %d $item_normal + AND item_wall = 1 and item_thread_top = 1 + AND (abook_blocked = 0 or abook.abook_flags is null) $sql_extra $sql_extra2 ORDER BY created DESC $pager_sql ", - intval($a->profile['profile_uid']), - intval(ITEM_WALL), - intval(ITEM_THREAD_TOP), - intval(ABOOK_FLAG_BLOCKED) + intval($a->profile['profile_uid']) ); } } @@ -245,7 +238,7 @@ function channel_content(&$a, $update = 0, $load = false) { $items = q("SELECT `item`.*, `item`.`id` AS `item_id` FROM `item` - WHERE `item`.`uid` = %d AND `item`.`item_restrict` = 0 + WHERE `item`.`uid` = %d $item_normal AND `item`.`parent` IN ( %s ) $sql_extra ", intval($a->profile['profile_uid']), @@ -338,9 +331,7 @@ function channel_content(&$a, $update = 0, $load = false) { } if($is_owner && $update_unseen) { - $r = q("UPDATE item SET item_unseen = 0 WHERE item_unseen = 1 - AND (item_flags & %d) > 0 AND uid = %d $update_unseen", - intval(ITEM_WALL), + $r = q("UPDATE item SET item_unseen = 0 where item_unseen = 1 and item_wall = 1 AND uid = %d $update_unseen", intval(local_channel()) ); } diff --git a/mod/chat.php b/mod/chat.php index c54d29313..ef9089b6f 100644 --- a/mod/chat.php +++ b/mod/chat.php @@ -54,20 +54,21 @@ function chat_post(&$a) { goaway(z_root() . '/chat/' . $channel['channel_address']); } + $acl = new AccessList($channel); + $acl->set_from_array($_REQUEST); - $arr = array('name' => $room); - $arr['allow_gid'] = perms2str($_REQUEST['group_allow']); - $arr['allow_cid'] = perms2str($_REQUEST['contact_allow']); - $arr['deny_gid'] = perms2str($_REQUEST['group_deny']); - $arr['deny_cid'] = perms2str($_REQUEST['contact_deny']); + $arr = $acl->get(); + $arr['name'] = $room; chatroom_create($channel,$arr); - $x = q("select cr_id from chatroom where cr_name = '%s' and cr_uid = %d limit 1", + $x = q("select * from chatroom where cr_name = '%s' and cr_uid = %d limit 1", dbesc($room), intval(local_channel()) ); + build_sync_packet(0, array('chatroom' => $x)); + if($x) goaway(z_root() . '/chat/' . $channel['channel_address'] . '/' . $x[0]['cr_id']); @@ -158,7 +159,10 @@ function chat_content(&$a) { intval($a->profile['profile_uid']) ); if($x) { - $private = ((($x[0]['allow_cid']) || ($x[0]['allow_gid']) || ($x[0]['deny_cid']) || ($x[0]['deny_gid'])) ? true : false); + $acl = new AccessList(false); + $acl->set($x[0]); + + $private = $acl->is_private(); $room_name = $x[0]['cr_name']; if($bookmark_link) $bookmark_link .= '&url=' . z_root() . '/chat/' . argv(1) . '/' . argv(2) . '&title=' . urlencode($x[0]['cr_name']) . (($private) ? '&private=1' : '') . '&ischat=1'; @@ -192,14 +196,8 @@ function chat_content(&$a) { if(local_channel() && argc() > 2 && argv(2) === 'new') { - - - $channel_acl = array( - 'allow_cid' => $channel['channel_allow_cid'], - 'allow_gid' => $channel['channel_allow_gid'], - 'deny_cid' => $channel['channel_deny_cid'], - 'deny_gid' => $channel['channel_deny_gid'] - ); + $acl = new AccessList($channel); + $channel_acl = $acl->get(); require_once('include/acl_selectors.php'); diff --git a/mod/cloud.php b/mod/cloud.php index 4b5d45f97..efb33f935 100644 --- a/mod/cloud.php +++ b/mod/cloud.php @@ -1,7 +1,7 @@ <?php /** * @file mod/cloud.php - * @brief Initialize RedMatrix's cloud (SabreDAV). + * @brief Initialize Hubzilla's cloud (SabreDAV). * * Module for accessing the DAV storage area. */ @@ -12,30 +12,12 @@ use RedMatrix\RedDAV; // composer autoloader for SabreDAV require_once('vendor/autoload.php'); -// workaround for HTTP-auth in CGI mode -if (x($_SERVER, 'REDIRECT_REMOTE_USER')) { - $userpass = base64_decode(substr($_SERVER["REDIRECT_REMOTE_USER"], 6)) ; - if(strlen($userpass)) { - list($name, $password) = explode(':', $userpass); - $_SERVER['PHP_AUTH_USER'] = $name; - $_SERVER['PHP_AUTH_PW'] = $password; - } -} - -if (x($_SERVER, 'HTTP_AUTHORIZATION')) { - $userpass = base64_decode(substr($_SERVER["HTTP_AUTHORIZATION"], 6)) ; - if(strlen($userpass)) { - list($name, $password) = explode(':', $userpass); - $_SERVER['PHP_AUTH_USER'] = $name; - $_SERVER['PHP_AUTH_PW'] = $password; - } -} - /** * @brief Fires up the SabreDAV server. * * @param App &$a */ + function cloud_init(&$a) { require_once('include/reddav.php'); @@ -91,6 +73,8 @@ function cloud_init(&$a) { $server->addPlugin($lockPlugin); +/* This next bit should no longer be needed... */ + // The next section of code allows us to bypass prompting for http-auth if a // FILE is being accessed anonymously and permissions allow this. This way // one can create hotlinks to public media files in their cloud and anonymous @@ -101,32 +85,27 @@ function cloud_init(&$a) { // In order to avoid prompting for passwords for viewing a DIRECTORY, add // the URL query parameter 'davguest=1'. - $isapublic_file = false; - $davguest = ((x($_SESSION, 'davguest')) ? true : false); - - if ((! $auth->observer) && ($_SERVER['REQUEST_METHOD'] === 'GET')) { - try { - $x = RedFileData('/' . $a->cmd, $auth); - if($x instanceof RedDAV\RedFile) - $isapublic_file = true; - } - catch (Exception $e) { - $isapublic_file = false; - } - } - - if ((! $auth->observer) && (! $isapublic_file) && (! $davguest)) { - try { - $auth->Authenticate($server, t('$Projectname - Guests: Username: {your email address}, Password: +++')); - } - catch (Exception $e) { - logger('mod_cloud: auth exception' . $e->getMessage()); - http_status_exit($e->getHTTPCode(), $e->getMessage()); - } - } +// $isapublic_file = false; +// $davguest = ((x($_SESSION, 'davguest')) ? true : false); + +// if ((! $auth->observer) && ($_SERVER['REQUEST_METHOD'] === 'GET')) { +// try { +// $x = RedFileData('/' . $a->cmd, $auth); +// if($x instanceof RedDAV\RedFile) +// $isapublic_file = true; +// } +// catch (Exception $e) { +// $isapublic_file = false; +// } +// } + +// if ((! $auth->observer) && (! $isapublic_file) && (! $davguest)) { +// logger('mod_cloud: auth exception'); +// http_status_exit(401, 'Permission denied.'); +// } require_once('include/RedDAV/RedBrowser.php'); - // provide a directory view for the cloud in Red Matrix + // provide a directory view for the cloud in Hubzilla $browser = new RedDAV\RedBrowser($auth); $auth->setBrowserPlugin($browser); diff --git a/mod/connections.php b/mod/connections.php index 8b95cbf2a..2060ca85e 100644 --- a/mod/connections.php +++ b/mod/connections.php @@ -42,46 +42,43 @@ function connections_content(&$a) { if(! $_REQUEST['aj']) $_SESSION['return_url'] = $a->query_string; - $search_flags = 0; + $search_flags = ''; $head = ''; if(argc() == 2) { switch(argv(1)) { case 'blocked': - $search_flags = ABOOK_FLAG_BLOCKED; + $search_flags = " and abook_blocked = 1 "; $head = t('Blocked'); $blocked = true; break; case 'ignored': - $search_flags = ABOOK_FLAG_IGNORED; + $search_flags = " and abook_ignored = 1 "; $head = t('Ignored'); $ignored = true; break; case 'hidden': - $search_flags = ABOOK_FLAG_HIDDEN; + $search_flags = " and abook_hidden = 1 "; $head = t('Hidden'); $hidden = true; break; case 'archived': - $search_flags = ABOOK_FLAG_ARCHIVED; + $search_flags = " and abook_archived = 1 "; $head = t('Archived'); $archived = true; break; case 'pending': - $search_flags = ABOOK_FLAG_PENDING; + $search_flags = " and abook_pending = 1 "; $head = t('New'); $pending = true; nav_set_selected('intros'); break; case 'ifpending': - $r = q("SELECT COUNT(abook.abook_id) AS total FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash where abook_channel = %d and (abook_flags & %d)>0 and not ((abook_flags & %d)>0 or (xchan_flags & %d)>0)", - intval(local_channel()), - intval(ABOOK_FLAG_PENDING), - intval(ABOOK_FLAG_SELF|ABOOK_FLAG_IGNORED), - intval(XCHAN_FLAGS_DELETED|XCHAN_FLAGS_ORPHAN) + $r = q("SELECT COUNT(abook.abook_id) AS total FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash where abook_channel = %d and abook_pending = 1 and abook_self = 0 and abook_ignored = 0 and xchan_deleted = 0 and xchan_orphan = 0 ", + intval(local_channel()) ); if($r && $r[0]['total']) { - $search_flags = ABOOK_FLAG_PENDING; + $search_flags = " and abook_pending = 1 "; $head = t('New'); $pending = true; nav_set_selected('intros'); @@ -89,7 +86,7 @@ function connections_content(&$a) { } else { $head = t('All'); - $search_flags = 0; + $search_flags = ''; $all = true; $a->argc = 1; unset($a->argv[1]); @@ -97,7 +94,7 @@ function connections_content(&$a) { nav_set_selected('intros'); break; // case 'unconnected': -// $search_flags = ABOOK_FLAG_UNCONNECTED; +// $search_flags = " and abook_unconnected = 1 "; // $head = t('Unconnected'); // $unconnected = true; // break; @@ -105,19 +102,19 @@ function connections_content(&$a) { case 'all': $head = t('All'); default: - $search_flags = 0; + $search_flags = ''; $all = true; break; } - $sql_extra = (($search_flags) ? " and ( abook_flags & " . $search_flags . " )>0 " : ""); + $sql_extra = $search_flags; if(argv(1) === 'pending') - $sql_extra .= " and not ( abook_flags & " . ABOOK_FLAG_IGNORED . " )>0 "; + $sql_extra .= " and abook_ignored = 0 "; } else { - $sql_extra = " and not ( abook_flags & " . ABOOK_FLAG_BLOCKED . " )>0 "; + $sql_extra = " and abook_blocked = 0 "; $unblocked = true; } @@ -203,10 +200,8 @@ function connections_content(&$a) { } $r = q("SELECT COUNT(abook.abook_id) AS total FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash - where abook_channel = %d and not (abook_flags & %d)>0 and not (xchan_flags & %d )>0 $sql_extra $sql_extra2 ", - intval(local_channel()), - intval(ABOOK_FLAG_SELF), - intval(XCHAN_FLAGS_DELETED|XCHAN_FLAGS_ORPHAN) + where abook_channel = %d and abook_self = 0 and xchan_deleted = 0 and xchan_orphan = 0 $sql_extra $sql_extra2 ", + intval(local_channel()) ); if($r) { $a->set_pager_total($r[0]['total']); @@ -214,10 +209,8 @@ function connections_content(&$a) { } $r = q("SELECT abook.*, xchan.* FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash - WHERE abook_channel = %d and not (abook_flags & %d)>0 and not ( xchan_flags & %d)>0 $sql_extra $sql_extra2 ORDER BY xchan_name LIMIT %d OFFSET %d ", + WHERE abook_channel = %d and abook_self = 0 and xchan_deleted = 0 and xchan_orphan = 0 $sql_extra $sql_extra2 ORDER BY xchan_name LIMIT %d OFFSET %d ", intval(local_channel()), - intval(ABOOK_FLAG_SELF), - intval(XCHAN_FLAGS_DELETED|XCHAN_FLAGS_ORPHAN), intval($a->pager['itemspage']), intval($a->pager['start']) ); @@ -237,7 +230,7 @@ function connections_content(&$a) { 'thumb' => $rr['xchan_photo_m'], 'name' => $rr['xchan_name'], 'username' => $rr['xchan_name'], - 'classes' => (($rr['abook_flags'] & ABOOK_FLAG_ARCHIVED) ? 'archived' : ''), + 'classes' => (intval($rr['abook_archived']) ? 'archived' : ''), 'link' => z_root() . '/connedit/' . $rr['abook_id'], 'edit' => t('Edit'), 'url' => chanlink_url($rr['xchan_url']), diff --git a/mod/connedit.php b/mod/connedit.php index 0944a3dca..75a5fd719 100644 --- a/mod/connedit.php +++ b/mod/connedit.php @@ -79,7 +79,7 @@ function connedit_post(&$a) { call_hooks('contact_edit_post', $_POST); - if($orig_record[0]['abook_flags'] & ABOOK_FLAG_SELF) { + if(intval($orig_record[0]['abook_self'])) { $autoperms = intval($_POST['autoperms']); $is_self = true; } @@ -130,7 +130,6 @@ function connedit_post(&$a) { } } - $abook_flags = $orig_record[0]['abook_flags']; $new_friend = false; if(! $is_self) { @@ -176,8 +175,7 @@ function connedit_post(&$a) { } } - if(($_REQUEST['pending']) && ($abook_flags & ABOOK_FLAG_PENDING)) { - $abook_flags = ( $abook_flags ^ ABOOK_FLAG_PENDING ); + if(($_REQUEST['pending']) && intval($orig_record[0]['abook_pending'])) { $new_friend = true; if(! $abook_my_perms) { @@ -192,13 +190,15 @@ function connedit_post(&$a) { } } - $r = q("UPDATE abook SET abook_profile = '%s', abook_my_perms = %d , abook_closeness = %d, abook_flags = %d, + $abook_pending = $new_friend ? 0 : $orig_record[0]['abook_pending']; + + $r = q("UPDATE abook SET abook_profile = '%s', abook_my_perms = %d , abook_closeness = %d, abook_pending = %d, abook_incl = '%s', abook_excl = '%s' where abook_id = %d AND abook_channel = %d", dbesc($profile_id), intval($abook_my_perms), intval($closeness), - intval($abook_flags), + intval($abook_pending), dbesc($abook_incl), dbesc($abook_excl), intval($contact_id), @@ -221,7 +221,7 @@ function connedit_post(&$a) { notice( t('Failed to update connection record.') . EOL); if($a->poi && $a->poi['abook_my_perms'] != $abook_my_perms - && (! ($a->poi['abook_flags'] & ABOOK_FLAG_SELF))) { + && (! intval($a->poi['abook_self']))) { proc_run('php', 'include/notifier.php', 'permission_update', $contact_id); } @@ -241,11 +241,12 @@ function connedit_post(&$a) { $pr = q("select * from profile where uid = %d and is_default = 1 and hide_friends = 0", intval($channel['channel_id']) ); - if(($pr) && (! ($abook_flags & ABOOK_FLAG_HIDDEN)) - && (intval(get_pconfig($channel['channel_id'],'system','post_newfriend')))) { + if(($pr) && (! intval($orig_record[0]['abook_hidden'])) && (intval(get_pconfig($channel['channel_id'],'system','post_newfriend')))) { $xarr = array(); $xarr['verb'] = ACTIVITY_FRIEND; - $xarr['item_flags'] = ITEM_WALL|ITEM_ORIGIN|ITEM_THREAD_TOP; + $xarr['item_wall'] = 1; + $xarr['item_origin'] = 1; + $xarr['item_thread_top'] = 1; $xarr['owner_xchan'] = $xarr['author_xchan'] = $channel['channel_hash']; $xarr['allow_cid'] = $channel['channel_allow_cid']; $xarr['allow_gid'] = $channel['channel_allow_gid']; @@ -314,16 +315,15 @@ function connedit_clone(&$a) { if(! $a->poi) return; - $r = q("SELECT abook.*, xchan.* - FROM abook left join xchan on abook_xchan = xchan_hash - WHERE abook_channel = %d and abook_id = %d LIMIT 1", - intval(local_channel()), - intval($a->poi['abook_id']) - ); - if($r) { - $a->poi = $r[0]; - } - + $r = q("SELECT abook.*, xchan.* + FROM abook left join xchan on abook_xchan = xchan_hash + WHERE abook_channel = %d and abook_id = %d LIMIT 1", + intval(local_channel()), + intval($a->poi['abook_id']) + ); + if($r) { + $a->poi = $r[0]; + } $clone = $a->poi; @@ -382,10 +382,9 @@ function connedit_content(&$a) { $cmd = argv(2); $orig_record = q("SELECT abook.*, xchan.* FROM abook left join xchan on abook_xchan = xchan_hash - WHERE abook_id = %d AND abook_channel = %d AND NOT ( abook_flags & %d )>0 LIMIT 1", + WHERE abook_id = %d AND abook_channel = %d AND abook_self = 0 LIMIT 1", intval($contact_id), - intval(local_channel()), - intval(ABOOK_FLAG_SELF) + intval(local_channel()) ); if(! count($orig_record)) { @@ -409,9 +408,6 @@ function connedit_content(&$a) { if($cmd === 'block') { if(abook_toggle_flag($orig_record[0],ABOOK_FLAG_BLOCKED)) { - // info((($orig_record[0]['abook_flags'] & ABOOK_FLAG_BLOCKED) - // ? t('Channel has been unblocked') - // : t('Channel has been blocked')) . EOL ); connedit_clone($a); } else @@ -421,9 +417,6 @@ function connedit_content(&$a) { if($cmd === 'ignore') { if(abook_toggle_flag($orig_record[0],ABOOK_FLAG_IGNORED)) { - // info((($orig_record[0]['abook_flags'] & ABOOK_FLAG_IGNORED) - // ? t('Channel has been unignored') - // : t('Channel has been ignored')) . EOL ); connedit_clone($a); } else @@ -433,9 +426,6 @@ function connedit_content(&$a) { if($cmd === 'archive') { if(abook_toggle_flag($orig_record[0],ABOOK_FLAG_ARCHIVED)) { - // info((($orig_record[0]['abook_flags'] & ABOOK_FLAG_ARCHIVED) - // ? t('Channel has been unarchived') - // : t('Channel has been archived')) . EOL ); connedit_clone($a); } else @@ -445,9 +435,6 @@ function connedit_content(&$a) { if($cmd === 'hide') { if(abook_toggle_flag($orig_record[0],ABOOK_FLAG_HIDDEN)) { - // info((($orig_record[0]['abook_flags'] & ABOOK_FLAG_HIDDEN) - // ? t('Channel has been unhidden') - // : t('Channel has been hidden')) . EOL ); connedit_clone($a); } else @@ -459,11 +446,8 @@ function connedit_content(&$a) { // Though maybe somebody will want this eventually (??) if($cmd === 'approve') { - if($orig_record[0]['abook_flags'] & ABOOK_FLAG_PENDING) { + if(intval($orig_record[0]['abook_pending'])) { if(abook_toggle_flag($orig_record[0],ABOOK_FLAG_PENDING)) { - // info((($orig_record[0]['abook_flags'] & ABOOK_FLAG_PENDING) - // ? t('Channel has been approved') - // : t('Channel has been unapproved')) . EOL ); connedit_clone($a); } else @@ -528,35 +512,35 @@ function connedit_content(&$a) { ), 'block' => array( - 'label' => (($contact['abook_flags'] & ABOOK_FLAG_BLOCKED) ? t('Unblock') : t('Block')), + 'label' => (intval($contact['abook_blocked']) ? t('Unblock') : t('Block')), 'url' => $a->get_baseurl(true) . '/connedit/' . $contact['abook_id'] . '/block', - 'sel' => (($contact['abook_flags'] & ABOOK_FLAG_BLOCKED) ? 'active' : ''), + 'sel' => (intval($contact['abook_blocked']) ? 'active' : ''), 'title' => t('Block (or Unblock) all communications with this connection'), - 'info' => (($contact['abook_flags'] & ABOOK_FLAG_BLOCKED) ? t('This connection is blocked!') : ''), + 'info' => (intval($contact['abook_blocked']) ? t('This connection is blocked!') : ''), ), 'ignore' => array( - 'label' => (($contact['abook_flags'] & ABOOK_FLAG_IGNORED) ? t('Unignore') : t('Ignore')), + 'label' => (intval($contact['abook_ignored']) ? t('Unignore') : t('Ignore')), 'url' => $a->get_baseurl(true) . '/connedit/' . $contact['abook_id'] . '/ignore', - 'sel' => (($contact['abook_flags'] & ABOOK_FLAG_IGNORED) ? 'active' : ''), + 'sel' => (intval($contact['abook_ignored']) ? 'active' : ''), 'title' => t('Ignore (or Unignore) all inbound communications from this connection'), - 'info' => (($contact['abook_flags'] & ABOOK_FLAG_IGNORED) ? t('This connection is ignored!') : ''), + 'info' => (intval($contact['abook_ignored']) ? t('This connection is ignored!') : ''), ), 'archive' => array( - 'label' => (($contact['abook_flags'] & ABOOK_FLAG_ARCHIVED) ? t('Unarchive') : t('Archive')), + 'label' => (intval($contact['abook_archived']) ? t('Unarchive') : t('Archive')), 'url' => $a->get_baseurl(true) . '/connedit/' . $contact['abook_id'] . '/archive', - 'sel' => (($contact['abook_flags'] & ABOOK_FLAG_ARCHIVED) ? 'active' : ''), + 'sel' => (intval($contact['abook_archived']) ? 'active' : ''), 'title' => t('Archive (or Unarchive) this connection - mark channel dead but keep content'), - 'info' => (($contact['abook_flags'] & ABOOK_FLAG_ARCHIVED) ? t('This connection is archived!') : ''), + 'info' => (intval($contact['abook_archived']) ? t('This connection is archived!') : ''), ), 'hide' => array( - 'label' => (($contact['abook_flags'] & ABOOK_FLAG_HIDDEN) ? t('Unhide') : t('Hide')), + 'label' => (intval($contact['abook_hidden']) ? t('Unhide') : t('Hide')), 'url' => $a->get_baseurl(true) . '/connedit/' . $contact['abook_id'] . '/hide', - 'sel' => (($contact['abook_flags'] & ABOOK_FLAG_HIDDEN) ? 'active' : ''), + 'sel' => (intval($contact['abook_hidden']) ? 'active' : ''), 'title' => t('Hide or Unhide this connection from your other connections'), - 'info' => (($contact['abook_flags'] & ABOOK_FLAG_HIDDEN) ? t('This connection is hidden!') : ''), + 'info' => (intval($contact['abook_hidden']) ? t('This connection is hidden!') : ''), ), 'delete' => array( @@ -570,7 +554,7 @@ function connedit_content(&$a) { $self = false; - if(($contact['abook_flags'] & ABOOK_FLAG_SELF)) + if(intval($contact['abook_self'])) $self = true; require_once('include/contact_selectors.php'); @@ -698,7 +682,7 @@ function connedit_content(&$a) { '$pending_modal_body' => sprintf(t('(%s) would like to connect with you. Please approve this connection to allow communication.'), $contact['xchan_addr']), '$pending_modal_approve' => t('Approve'), '$pending_modal_dismiss' => t('Approve Later'), - '$is_pending' => (($contact['abook_flags'] & ABOOK_FLAG_PENDING) ? 1 : ''), + '$is_pending' => (intval($contact['abook_pending']) ? 1 : ''), '$unapproved' => $unapproved, '$inherited' => t('inherited'), '$submit' => t('Submit'), diff --git a/mod/contactgroup.php b/mod/contactgroup.php index 6138f9e19..61ca37054 100644 --- a/mod/contactgroup.php +++ b/mod/contactgroup.php @@ -9,10 +9,9 @@ function contactgroup_content(&$a) { } if((argc() > 2) && (intval(argv(1))) && (argv(2))) { - $r = q("SELECT abook_xchan from abook where abook_xchan = '%s' and abook_channel = %d and not ( abook_flags & %d )>0 limit 1", + $r = q("SELECT abook_xchan from abook where abook_xchan = '%s' and abook_channel = %d and abook_self = 0 limit 1", dbesc(base64url_decode(argv(2))), - intval(local_channel()), - intval(ABOOK_FLAG_SELF) + intval(local_channel()) ); if($r) $change = $r[0]['abook_xchan']; diff --git a/mod/dav.php b/mod/dav.php index 2f811a7f0..d4695a544 100644 --- a/mod/dav.php +++ b/mod/dav.php @@ -1,7 +1,7 @@ <?php /** * @file mod/dav.php - * @brief Initialize RedMatrix's cloud (SabreDAV). + * @brief Initialize Hubzilla's cloud (SabreDAV). * * Module for accessing the DAV storage area from a DAV client. */ @@ -127,12 +127,10 @@ function dav_init(&$a) { } require_once('include/RedDAV/RedBrowser.php'); - // provide a directory view for the cloud in Red Matrix + // provide a directory view for the cloud in Hubzilla $browser = new RedDAV\RedBrowser($auth); $auth->setBrowserPlugin($browser); - $server->addPlugin($browser); - // Experimental QuotaPlugin // require_once('include/RedDAV/QuotaPlugin.php'); // $server->addPlugin(new RedDAV\QuotaPlugin($auth)); diff --git a/mod/directory.php b/mod/directory.php index 44d80cff1..3c230e173 100644 --- a/mod/directory.php +++ b/mod/directory.php @@ -251,7 +251,7 @@ function directory_content(&$a) { $hometown = ((x($profile,'hometown') == 1) ? $profile['hometown'] : False); - $about = ((x($profile,'about') == 1) ? bbcode(strip_bbimage($profile['about'])) : False); + $about = ((x($profile,'about') == 1) ? bbcode($profile['about']) : False); $keywords = ((x($profile,'keywords')) ? $profile['keywords'] : ''); diff --git a/mod/dirsearch.php b/mod/dirsearch.php index d997020b2..132ed252b 100644 --- a/mod/dirsearch.php +++ b/mod/dirsearch.php @@ -127,7 +127,6 @@ function dirsearch_content(&$a) { if($forums) $safesql .= dir_flag_build(' AND ','xchan_flags',XCHAN_FLAGS_PUBFORUM, $forums); - // we only support an age range currently. You must set both agege // (greater than or equal) and agele (less than or equal) @@ -170,21 +169,16 @@ function dirsearch_content(&$a) { $sql_extra .= " and xchan_addr like '%%" . get_app()->get_hostname() . "' "; } - - $safesql .= (($safe > 0) ? " and not ( xchan_flags & " . intval(XCHAN_FLAGS_CENSORED|XCHAN_FLAGS_SELFCENSORED) . " )>0 " : ''); + $safesql = (($safe > 0) ? " and xchan_censored = 0 and xchan_selfcensored = 0 " : ''); if($safe < 0) - $safesql .= " and ( xchan_flags & " . intval(XCHAN_FLAGS_CENSORED|XCHAN_FLAGS_SELFCENSORED) . " )>0 "; + $safesql = " and ( xchan_censored = 1 OR xchan_selfcensored = 1 ) "; if($limit) $qlimit = " LIMIT $limit "; else { $qlimit = " LIMIT " . intval($perpage) . " OFFSET " . intval($startrec); if($return_total) { - $r = q("SELECT COUNT(xchan_hash) AS `total` FROM xchan left join xprof on xchan_hash = xprof_hash where $logic $sql_extra and xchan_network = 'zot' and not ( xchan_flags & %d)>0 and not ( xchan_flags & %d )>0 and not ( xchan_flags & %d )>0 $safesql ", - intval(XCHAN_FLAGS_HIDDEN), - intval(XCHAN_FLAGS_ORPHAN), - intval(XCHAN_FLAGS_DELETED) - ); + $r = q("SELECT COUNT(xchan_hash) AS `total` FROM xchan left join xprof on xchan_hash = xprof_hash where $logic $sql_extra and xchan_network = 'zot' and xchan_hidden = 0 and xchan_orphan = 0 and xchan_deleted = 0 $safesql "); if($r) { $ret['total_items'] = $r[0]['total']; } @@ -251,13 +245,10 @@ function dirsearch_content(&$a) { json_return_and_die($spkt); } else { - - $r = q("SELECT xchan.*, xprof.* from xchan left join xprof on xchan_hash = xprof_hash where ( $logic $sql_extra ) $hub_query and xchan_network = 'zot' and not ( xchan_flags & %d )>0 and not ( xchan_flags & %d )>0 and not ( xchan_flags & %d )>0 $safesql $order $qlimit ", - intval(XCHAN_FLAGS_HIDDEN), - intval(XCHAN_FLAGS_ORPHAN), - intval(XCHAN_FLAGS_DELETED) + $r = q("SELECT xchan.*, xprof.* from xchan left join xprof on xchan_hash = xprof_hash + where ( $logic $sql_extra ) $hub_query and xchan_network = 'zot' and xchan_hidden = 0 and xchan_orphan = 0 and xchan_deleted = 0 + $safesql $order $qlimit " ); - $ret['page'] = $page + 1; $ret['records'] = count($r); } @@ -283,7 +274,7 @@ function dirsearch_content(&$a) { $entry['name'] = $rr['xchan_name']; $entry['hash'] = $rr['xchan_hash']; - $entry['public_forum'] = (($rr['xchan_flags'] & XCHAN_FLAGS_PUBFORUM) ? true : false); + $entry['public_forum'] = (intval($rr['xchan_pubforum']) ? true : false); $entry['url'] = $rr['xchan_url']; $entry['photo_l'] = $rr['xchan_photo_l']; diff --git a/mod/display.php b/mod/display.php index 8c4707bb2..b2d9ba34b 100644 --- a/mod/display.php +++ b/mod/display.php @@ -85,7 +85,7 @@ function display_content(&$a, $update = 0, $load = false) { $target_item = null; - $r = q("select id, uid, mid, parent_mid, item_restrict from item where mid like '%s' limit 1", + $r = q("select id, uid, mid, parent_mid, item_type, item_deleted from item where mid like '%s' limit 1", dbesc($item_hash . '%') ); @@ -95,7 +95,7 @@ function display_content(&$a, $update = 0, $load = false) { $r = null; - if($target_item['item_restrict'] & ITEM_WEBPAGE) { + if($target_item['item_type'] == ITEM_TYPE_WEBPAGE) { $x = q("select * from channel where channel_id = %d limit 1", intval($target_item['uid']) ); @@ -161,6 +161,7 @@ function display_content(&$a, $update = 0, $load = false) { } $observer_hash = get_observer_hash(); + $item_normal = item_normal(); $sql_extra = public_permissions_sql($observer_hash); @@ -179,9 +180,9 @@ function display_content(&$a, $update = 0, $load = false) { if(local_channel()) { $r = q("SELECT * from item - WHERE item_restrict = 0 - and uid = %d + WHERE uid = %d and mid = '%s' + $item_normal limit 1", intval(local_channel()), dbesc($target_item['parent_mid']) @@ -202,13 +203,13 @@ function display_content(&$a, $update = 0, $load = false) { $r = q("SELECT * from item - WHERE item_restrict = 0 - and mid = '%s' + WHERE mid = '%s' AND (((( `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' AND item_private = 0 ) and owner_xchan in ( " . stream_perms_xchans(($observer_hash) ? (PERMS_NETWORK|PERMS_PUBLIC) : PERMS_PUBLIC) . " )) OR uid = %d ) $sql_extra ) + $item_normal limit 1", dbesc($target_item['parent_mid']), intval($sysid) @@ -228,7 +229,7 @@ function display_content(&$a, $update = 0, $load = false) { $items = q("SELECT `item`.*, `item`.`id` AS `item_id` FROM `item` - WHERE item_restrict = 0 and parent in ( %s ) ", + WHERE parent in ( %s ) $item_normal ", dbesc($parents_str) ); @@ -251,7 +252,7 @@ function display_content(&$a, $update = 0, $load = false) { } if($updateable) { - $x = q("UPDATE item SET item_unseen = 0 WHERE item_unseen = 1 AND uid = %d and parent = %d ", + $x = q("UPDATE item SET item_unseen = 0 where item_unseen = 1 AND uid = %d and parent = %d ", intval(local_channel()), intval($r[0]['parent']) ); @@ -270,7 +271,7 @@ function display_content(&$a, $update = 0, $load = false) { dbesc($item_hash) ); if($r) { - if($r[0]['item_flags'] & ITEM_DELETED) { + if(intval($r[0]['item_deleted'])) { notice( t('Item has been removed.') . EOL ); } else { diff --git a/mod/editblock.php b/mod/editblock.php index faa283b63..9269676b1 100644 --- a/mod/editblock.php +++ b/mod/editblock.php @@ -111,6 +111,7 @@ function editblock_content(&$a) { $a->page['htmlhead'] .= replace_macros(get_markup_template('jot-header.tpl'), array( '$baseurl' => $a->get_baseurl(), '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'), + '$pretext' => '', '$ispublic' => ' ', // t('Visible to <strong>everybody</strong>'), '$geotag' => '', '$nickname' => $channel['channel_address'], @@ -130,14 +131,14 @@ function editblock_content(&$a) { $editor = replace_macros($tpl,array( '$return_path' => $rp, '$action' => 'item', - '$webpage' => ITEM_BUILDBLOCK, + '$webpage' => ITEM_TYPE_BLOCK, '$share' => t('Edit'), - '$bold' => t('Bold'), - '$italic' => t('Italic'), - '$underline' => t('Underline'), - '$quote' => t('Quote'), - '$code' => t('Code'), - '$writefiles' => (perm_is_allowed($owner, get_observer_hash(), 'post_photos') || perm_is_allowed($owner, get_observer_hash(), 'write_storage')), + '$bold' => t('Bold'), + '$italic' => t('Italic'), + '$underline' => t('Underline'), + '$quote' => t('Quote'), + '$code' => t('Code'), + '$writefiles' => perm_is_allowed($owner, get_observer_hash(), 'write_storage'), '$upload' => t('Upload photo'), '$attach' => t('Attach file'), '$weblink' => t('Insert web link'), diff --git a/mod/editlayout.php b/mod/editlayout.php index a39611a58..fc68cfe3c 100644 --- a/mod/editlayout.php +++ b/mod/editlayout.php @@ -105,6 +105,7 @@ function editlayout_content(&$a) { $a->page['htmlhead'] .= replace_macros(get_markup_template('jot-header.tpl'), array( '$baseurl' => $a->get_baseurl(), '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'), + '$pretext' => '', '$ispublic' => ' ', // t('Visible to <strong>everybody</strong>'), '$geotag' => $geotag, '$nickname' => $channel['channel_address'], @@ -129,7 +130,7 @@ function editlayout_content(&$a) { $editor = replace_macros($tpl,array( '$return_path' => $rp, '$action' => 'item', - '$webpage' => ITEM_PDL, + '$webpage' => ITEM_TYPE_PDL, '$share' => t('Edit'), '$bold' => t('Bold'), '$italic' => t('Italic'), diff --git a/mod/editpost.php b/mod/editpost.php index e907a07d0..d4dc35ef8 100644 --- a/mod/editpost.php +++ b/mod/editpost.php @@ -32,6 +32,12 @@ function editpost_content(&$a) { return; } + if($itm[0]['resource_type'] === 'event' && $itm[0]['resource_id']) { + goaway(z_root() . '/events/event/' . $itm[0]['resource_id']); + } + + + $plaintext = true; // if(feature_enabled(local_channel(),'richtext')) // $plaintext = false; @@ -41,6 +47,7 @@ function editpost_content(&$a) { $a->page['htmlhead'] .= replace_macros(get_markup_template('jot-header.tpl'), array( '$baseurl' => $a->get_baseurl(), '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'), + '$pretext' => '', '$ispublic' => ' ', // t('Visible to <strong>everybody</strong>'), '$geotag' => $geotag, '$nickname' => $channel['channel_address'], @@ -48,7 +55,7 @@ function editpost_content(&$a) { '$confirmdelete' => t('Delete item?'), )); - if($itm[0]['item_flags'] & ITEM_OBSCURED) { + if(intval($itm[0]['item_obscured'])) { $key = get_config('system','prvkey'); if($itm[0]['title']) $itm[0]['title'] = crypto_unencapsulate(json_decode_plus($itm[0]['title']),$key); @@ -119,7 +126,7 @@ function editpost_content(&$a) { '$noloc' => t('Clear browser location'), '$voting' => t('Toggle voting'), '$feature_voting' => $voting, - '$consensus' => (($itm[0]['item_flags'] & ITEM_CONSENSUS) ? 1 : 0), + '$consensus' => intval($itm[0]['item_consensus']), '$wait' => t('Please wait'), '$permset' => t('Permission settings'), '$ptyp' => $itm[0]['type'], diff --git a/mod/editwebpage.php b/mod/editwebpage.php index cdf5d8c20..0192fd9c0 100644 --- a/mod/editwebpage.php +++ b/mod/editwebpage.php @@ -102,7 +102,7 @@ function editwebpage_content(&$a) { return; } - if($itm[0]['item_flags'] & ITEM_OBSCURED) { + if(intval($itm[0]['item_obscured'])) { $key = get_config('system','prvkey'); if($itm[0]['title']) $itm[0]['title'] = crypto_unencapsulate(json_decode_plus($itm[0]['title']),$key); @@ -146,6 +146,7 @@ function editwebpage_content(&$a) { $a->page['htmlhead'] .= replace_macros(get_markup_template('jot-header.tpl'), array( '$baseurl' => $a->get_baseurl(), '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'), + '$pretext' => '', '$ispublic' => ' ', // t('Visible to <strong>everybody</strong>'), '$geotag' => $geotag, '$nickname' => $channel['channel_address'], @@ -165,15 +166,12 @@ function editwebpage_content(&$a) { $rp = 'webpages/' . $which; - logger('canwrite: ' . (perm_is_allowed($owner, get_observer_hash(), 'post_photos') || perm_is_allowed($owner, get_observer_hash(), 'write_storage'))); - $editor = replace_macros($tpl,array( '$return_path' => $rp, - '$webpage' => ITEM_WEBPAGE, + '$webpage' => ITEM_TYPE_WEBPAGE, '$placeholdpagetitle' => t('Page link title'), '$pagetitle' => $page_title, - '$writefiles' => (perm_is_allowed($owner, get_observer_hash(), 'post_photos') || perm_is_allowed($owner, get_observer_hash(), 'write_storage')), - + '$writefiles' => perm_is_allowed($owner, get_observer_hash(), 'write_storage'), '$action' => 'item', '$share' => t('Edit'), '$bold' => t('Bold'), diff --git a/mod/events.php b/mod/events.php index 640020738..d76602a33 100755 --- a/mod/events.php +++ b/mod/events.php @@ -8,7 +8,7 @@ require_once('include/items.php'); function events_post(&$a) { - logger('post: ' . print_r($_REQUEST,true)); + logger('post: ' . print_r($_REQUEST,true), LOGGER_DATA); if(! local_channel()) return; @@ -41,16 +41,11 @@ function events_post(&$a) { $categories = escape_tags(trim($_POST['category'])); - - // only allow editing your own events. if(($xchan) && ($xchan !== get_observer_hash())) return; - // The default setting for the `private` field in event_store() is false, so mirror that - $private_event = false; - if($start_text) { $start = $start_text; } @@ -89,14 +84,14 @@ function events_post(&$a) { $summary = escape_tags(trim($_POST['summary'])); $desc = escape_tags(trim($_POST['desc'])); $location = escape_tags(trim($_POST['location'])); - $type = 'event'; + $type = escape_tags(trim($_POST['type'])); require_once('include/text.php'); linkify_tags($a, $desc, local_channel()); linkify_tags($a, $location, local_channel()); $action = ($event_hash == '') ? 'new' : "event/" . $event_hash; - $onerror_url = $a->get_baseurl() . "/events/" . $action . "?summary=$summary&description=$desc&location=$location&start=$start_text&finish=$finish_text&adjust=$adjust&nofinish=$nofinish"; + $onerror_url = $a->get_baseurl() . "/events/" . $action . "?summary=$summary&description=$desc&location=$location&start=$start_text&finish=$finish_text&adjust=$adjust&nofinish=$nofinish&type=$type"; if(strcmp($finish,$start) < 0 && !$nofinish) { notice( t('Event can not end before it has started.') . EOL); if(intval($_REQUEST['preview'])) { @@ -119,6 +114,8 @@ function events_post(&$a) { $channel = $a->get_channel(); + $acl = new AccessList(false); + if($event_id) { $x = q("select * from event where id = %d and uid = %d limit 1", intval($event_id), @@ -132,44 +129,33 @@ function events_post(&$a) { } return; } + + $acl->set($x[0]); + + $created = $x[0]['created']; + $edited = datetime_convert(); + if($x[0]['allow_cid'] === '<' . $channel['channel_hash'] . '>' && $x[0]['allow_gid'] === '' && $x[0]['deny_cid'] === '' && $x[0]['deny_gid'] === '') { $share = false; } else { $share = true; - $str_group_allow = $x[0]['allow_gid']; - $str_contact_allow = $x[0]['allow_cid']; - $str_group_deny = $x[0]['deny_gid']; - $str_contact_deny = $x[0]['deny_cid']; - - if(strlen($str_group_allow) || strlen($str_contact_allow) - || strlen($str_group_deny) || strlen($str_contact_deny)) { - $private_event = true; - } } } else { + $created = $edited = datetime_convert(); if($share) { - $str_group_allow = perms2str($_POST['group_allow']); - $str_contact_allow = perms2str($_POST['contact_allow']); - $str_group_deny = perms2str($_POST['group_deny']); - $str_contact_deny = perms2str($_POST['contact_deny']); - - if(strlen($str_group_allow) || strlen($str_contact_allow) - || strlen($str_group_deny) || strlen($str_contact_deny)) { - $private_event = true; - } + $acl->set_from_array($_POST); } else { - $str_contact_allow = '<' . $channel['channel_hash'] . '>'; - $str_group_allow = $str_contact_deny = $str_group_deny = ''; - $private_event = true; + $acl->set(array('allow_cid' => '<' . $channel['channel_hash'] . '>', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '')); } } $post_tags = array(); $channel = $a->get_channel(); + $ac = $acl->get(); if(strlen($categories)) { $cats = explode(',',$categories); @@ -196,11 +182,11 @@ function events_post(&$a) { $datarray['uid'] = local_channel(); $datarray['account'] = get_account_id(); $datarray['event_xchan'] = $channel['channel_hash']; - $datarray['allow_cid'] = $str_contact_allow; - $datarray['allow_gid'] = $str_group_allow; - $datarray['deny_cid'] = $str_contact_deny; - $datarray['deny_gid'] = $str_group_deny; - $datarray['private'] = (($private_event) ? 1 : 0); + $datarray['allow_cid'] = $ac['allow_cid']; + $datarray['allow_gid'] = $ac['allow_gid']; + $datarray['deny_cid'] = $ac['deny_cid']; + $datarray['deny_gid'] = $ac['deny_gid']; + $datarray['private'] = (($acl->is_private()) ? 1 : 0); $datarray['id'] = $event_id; $datarray['created'] = $created; $datarray['edited'] = $edited; @@ -245,6 +231,27 @@ function events_post(&$a) { function events_content(&$a) { + if(argc() > 2 && argv(1) == 'ical') { + $event_id = argv(2); + + require_once('include/security.php'); + $sql_extra = permissions_sql(local_channel()); + + $r = q("select * from event where event_hash = '%s' $sql_extra limit 1", + dbesc($event_id) + ); + if($r) { + header('Content-type: text/calendar'); + header('content-disposition: attachment; filename="' . t('event') . '-' . $event_id . '.ics"' ); + echo ical_wrapper($r); + killme(); + } + else { + notice( t('Event not found.') . EOL ); + return; + } + } + if(! local_channel()) { notice( t('Permission denied.') . EOL); return; @@ -323,6 +330,10 @@ function events_content(&$a) { killme(); } + + + + if($mode == 'view') { @@ -383,8 +394,18 @@ function events_content(&$a) { intval(local_channel()), intval($_GET['id']) ); - } else { - + } elseif($export) { + $r = q("SELECT * from event where uid = %d + AND (( `adjust` = 0 AND ( `finish` >= '%s' or nofinish = 1 ) AND `start` <= '%s' ) + OR ( `adjust` = 1 AND ( `finish` >= '%s' or nofinish = 1 ) AND `start` <= '%s' )) ", + intval(local_channel()), + dbesc($start), + dbesc($finish), + dbesc($adjust_start), + dbesc($adjust_finish) + ); + } + else { // fixed an issue with "nofinish" events not showing up in the calendar. // There's still an issue if the finish date crosses the end of month. // Noting this for now - it will need to be fixed here and in Friendica. @@ -401,17 +422,19 @@ function events_content(&$a) { dbesc($adjust_start), dbesc($adjust_finish) ); - } + $links = array(); - if($r) { + if($r && ! $export) { xchan_query($r); $r = fetch_post_tags($r,true); $r = sort_by_date($r); + } + if($r) { foreach($r as $rr) { $j = (($rr['adjust']) ? datetime_convert('UTC',date_default_timezone_get(),$rr['start'], 'j') : datetime_convert('UTC','UTC',$rr['start'],'j')); if(! x($links,$j)) @@ -419,7 +442,6 @@ function events_content(&$a) { } } - $events=array(); $last_date = ''; @@ -444,8 +466,9 @@ function events_content(&$a) { $is_first = ($d !== $last_date); $last_date = $d; -// FIXME - $edit = (($rr['item_flags'] & ITEM_WALL) ? array($a->get_baseurl().'/events/event/'.$rr['event_hash'],t('Edit event'),'','') : null); + + $edit = (intval($rr['item_wall']) ? array($a->get_baseurl().'/events/event/'.$rr['event_hash'],t('Edit event'),'','') : null); + $drop = array($a->get_baseurl().'/events/drop/'.$rr['event_hash'],t('Delete event'),'',''); $title = strip_tags(html_entity_decode(bbcode($rr['summary']),ENT_QUOTES,'UTF-8')); @@ -569,9 +592,7 @@ function events_content(&$a) { if(x($_REQUEST,'location')) $orig_event['location'] = $_REQUEST['location']; if(x($_REQUEST,'start')) $orig_event['start'] = $_REQUEST['start']; if(x($_REQUEST,'finish')) $orig_event['finish'] = $_REQUEST['finish']; - } - - if($mode === 'edit' || $mode === 'new') { + if(x($_REQUEST,'type')) $orig_event['type'] = $_REQUEST['type']; $n_checked = ((x($orig_event) && $orig_event['nofinish']) ? ' checked="checked" ' : ''); $a_checked = ((x($orig_event) && $orig_event['adjust']) ? ' checked="checked" ' : ''); @@ -590,9 +611,6 @@ function events_content(&$a) { if($orig_event['event_xchan']) $sh_checked .= ' disabled="disabled" '; - - - $sdt = ((x($orig_event)) ? $orig_event['start'] : 'now'); $fdt = ((x($orig_event)) ? $orig_event['finish'] : 'now'); @@ -618,6 +636,7 @@ function events_content(&$a) { $fminute = ((x($orig_event)) ? datetime_convert('UTC', $tz, $fdt, 'i') : 0); $ftext = datetime_convert('UTC',$tz,$fdt); $ftext = substr($ftext,0,14) . "00:00"; + $type = ((x($orig_event)) ? $orig_event['type'] : 'event'); $f = get_config('system','event_input_format'); if(! $f) @@ -645,18 +664,16 @@ function events_content(&$a) { require_once('include/acl_selectors.php'); - $perm_defaults = array( - 'allow_cid' => $channel['channel_allow_cid'], - 'allow_gid' => $channel['channel_allow_gid'], - 'deny_cid' => $channel['channel_deny_cid'], - 'deny_gid' => $channel['channel_deny_gid'] - ); + $acl = new AccessList($channel); + $perm_defaults = $acl->get(); + $tpl = get_markup_template('event_form.tpl'); $o .= replace_macros($tpl,array( '$post' => $a->get_baseurl() . '/events', '$eid' => $eid, + '$type' => $type, '$xchan' => $event_xchan, '$mid' => $mid, '$event_hash' => $event_id, @@ -669,7 +686,7 @@ function events_content(&$a) { '$s_text' => t('Event Starts:'), '$stext' => $stext, '$ftext' => $ftext, - '$required' => ' <span class="required" title="' . t('Required') . '">*</span>', + '$required' => '<span class="required" title="' . t('Required') . '">*</span>', '$ModalCANCEL' => t('Cancel'), '$ModalOK' => t('OK'), '$s_dsel' => datetimesel($f,new DateTime(),DateTime::createFromFormat('Y',$syear+5),DateTime::createFromFormat('Y-m-d H:i',"$syear-$smonth-$sday $shour:$sminute"),'start_text',true,true,'','',true), diff --git a/mod/filer.php b/mod/filer.php index e8160bba2..8d69503b2 100644 --- a/mod/filer.php +++ b/mod/filer.php @@ -27,8 +27,7 @@ function filer_content(&$a) { intval(local_channel()) ); if($r) { - $x = q("update item set item_flags = ( item_flags | %d ) where id = %d and uid = %d", - intval(ITEM_RETAINED), + $x = q("update item set item_retained = 1 where id = %d and uid = %d", intval($r[0]['parent']), intval(local_channel()) ); diff --git a/mod/filestorage.php b/mod/filestorage.php index 8b52c086b..7ba8c1801 100644 --- a/mod/filestorage.php +++ b/mod/filestorage.php @@ -28,20 +28,20 @@ function filestorage_post(&$a) { return; } - $str_group_allow = perms2str($_REQUEST['group_allow']); - $str_contact_allow = perms2str($_REQUEST['contact_allow']); - $str_group_deny = perms2str($_REQUEST['group_deny']); - $str_contact_deny = perms2str($_REQUEST['contact_deny']); - $channel = $a->get_channel(); + + $acl = new AccessList($channel); + $acl->set_from_array($_REQUEST); + $x = $acl->get(); + $cloudPath = get_parent_cloudpath($channel_id, $channel['channel_address'], $resource); //get the object before permissions change so we can catch eventual former allowed members $object = get_file_activity_object($channel_id, $resource, $cloudPath); - attach_change_permissions($channel_id, $resource, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny, $recurse); + attach_change_permissions($channel_id, $resource, $x['allow_cid'], $x['allow_gid'], $x['deny_cid'], $x['deny_gid'], $recurse); - file_activity($channel_id, $object, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny, 'post', $notify); + file_activity($channel_id, $object, $x['allow_cid'], $x['allow_gid'], $x['deny_cid'], $x['deny_gid'], 'post', $notify); goaway($cloudPath); } @@ -117,7 +117,7 @@ function filestorage_content(&$a) { } $file = intval(argv(2)); - $r = q("select id, uid, folder, filename, revision, flags, hash, allow_cid, allow_gid, deny_cid, deny_gid from attach where id = %d and uid = %d limit 1", + $r = q("select id, uid, folder, filename, revision, flags, is_dir, os_storage, hash, allow_cid, allow_gid, deny_cid, deny_gid from attach where id = %d and uid = %d limit 1", intval($file), intval($owner) ); @@ -125,11 +125,11 @@ function filestorage_content(&$a) { $f = $r[0]; $channel = $a->get_channel(); - $cloudpath = get_cloudpath($f) . (($f['flags'] & ATTACH_FLAG_DIR) ? '?f=&davguest=1' : ''); + $cloudpath = get_cloudpath($f) . (intval($f['is_dir']) ? '?f=&davguest=1' : ''); $parentpath = get_parent_cloudpath($channel['channel_id'], $channel['channel_address'], $f['hash']); $aclselect_e = populate_acl($f, false); - $is_a_dir = (($f['flags'] & ATTACH_FLAG_DIR) ? true : false); + $is_a_dir = (intval($f['is_dir']) ? true : false); $lockstate = (($f['allow_cid'] || $f['allow_gid'] || $f['deny_cid'] || $f['deny_gid']) ? 'lock' : 'unlock'); diff --git a/mod/group.php b/mod/group.php index 66297d6ac..ce9633669 100644 --- a/mod/group.php +++ b/mod/group.php @@ -117,12 +117,9 @@ function group_content(&$a) { check_form_security_token_ForbiddenOnErr('group_member_change', 't'); - $r = q("SELECT abook_xchan from abook left join xchan on abook_xchan = xchan_hash where abook_xchan = '%s' and abook_channel = %d and not (xchan_flags & %d)>0 and not (abook_flags & %d)>0 and not (abook_flags & %d)>0 limit 1", + $r = q("SELECT abook_xchan from abook left join xchan on abook_xchan = xchan_hash where abook_xchan = '%s' and abook_channel = %d and xchan_deleted = 0 and abook_blocked = 0 and abook_pending = 0 limit 1", dbesc(base64url_decode(argv(2))), - intval(local_channel()), - intval(XCHAN_FLAGS_DELETED), - intval(ABOOK_FLAG_BLOCKED), - intval(ABOOK_FLAG_PENDING) + intval(local_channel()) ); if(count($r)) $change = base64url_decode(argv(2)); @@ -203,7 +200,7 @@ function group_content(&$a) { $textmode = (($switchtotext && (count($members) > $switchtotext)) ? true : false); foreach($members as $member) { if($member['xchan_url']) { - $member['archived'] = (($member['abook_flags'] & ABOOK_FLAG_ARCHIVED) ? true : false); + $member['archived'] = (intval($member['abook_archived']) ? true : false); $member['click'] = 'groupChangeMember(' . $group['id'] . ',\'' . base64url_encode($member['xchan_hash']) . '\',\'' . $sec_token . '\'); return false;'; $groupeditor['members'][] = micropro($member,true,'mpgroup', $textmode); } @@ -211,18 +208,15 @@ function group_content(&$a) { group_rmv_member(local_channel(),$group['name'],$member['xchan_hash']); } - $r = q("SELECT abook.*, xchan.* FROM `abook` left join xchan on abook_xchan = xchan_hash WHERE `abook_channel` = %d AND not (abook_flags & %d)>0 and not (xchan_flags & %d)>0 and not (abook_flags & %d)>0 order by xchan_name asc", - intval(local_channel()), - intval(ABOOK_FLAG_BLOCKED), - intval(XCHAN_FLAGS_DELETED), - intval(ABOOK_FLAG_PENDING) + $r = q("SELECT abook.*, xchan.* FROM `abook` left join xchan on abook_xchan = xchan_hash WHERE `abook_channel` = %d AND abook_blocked = 0 and abook_pending = 0 and xchan_deleted = 0 order by xchan_name asc", + intval(local_channel()) ); if(count($r)) { $textmode = (($switchtotext && (count($r) > $switchtotext)) ? true : false); foreach($r as $member) { if(! in_array($member['xchan_hash'],$preselected)) { - $member['archived'] = (($member['abook_flags'] & ABOOK_FLAG_ARCHIVED) ? true : false); + $member['archived'] = (intval($member['abook_archived']) ? true : false); $member['click'] = 'groupChangeMember(' . $group['id'] . ',\'' . base64url_encode($member['xchan_hash']) . '\',\'' . $sec_token . '\'); return false;'; $groupeditor['contacts'][] = micropro($member,true,'mpall', $textmode); } diff --git a/mod/help.php b/mod/help.php index 694b356aa..16ec069a7 100644 --- a/mod/help.php +++ b/mod/help.php @@ -11,25 +11,160 @@ */ -if(! function_exists('load_doc_file')) { + function load_doc_file($s) { $lang = get_app()->language; if(! isset($lang)) $lang = 'en'; $b = basename($s); $d = dirname($s); - if(file_exists("$d/$lang/$b")) - return file_get_contents("$d/$lang/$b"); + + $c = find_doc_file("$d/$lang/$b"); + if($c) + return $c; + $c = find_doc_file($s); + if($c) + return $c; + return ''; +} + +function find_doc_file($s) { if(file_exists($s)) return file_get_contents($s); return ''; -}} +} + +function search_doc_files($s) { + + $a = get_app(); + + $itemspage = get_pconfig(local_channel(),'system','itemspage'); + $a->set_pager_itemspage(((intval($itemspage)) ? $itemspage : 20)); + $pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval($a->pager['itemspage']), intval($a->pager['start'])); + + $regexop = db_getfunc('REGEXP'); + + $r = q("select item_id.sid, item.* from item left join item_id on item.id = item_id.iid where service = 'docfile' and + body $regexop '%s' and item_type = %d $pager_sql", + dbesc($s), + intval(ITEM_TYPE_DOC) + ); + + $r = fetch_post_tags($r,true); + + for($x = 0; $x < count($r); $x ++) { + + $r[$x]['text'] = $r[$x]['body']; + + $r[$x]['rank'] = 0; + if($r[$x]['term']) { + foreach($r[$x]['term'] as $t) { + if(stristr($t['term'],$s)) { + $r[$x]['rank'] ++; + } + } + } + if(stristr($r[$x]['sid'],$s)) + $r[$x]['rank'] ++; + $r[$x]['rank'] += substr_count(strtolower($r[$x]['text']),strtolower($s)); + // bias the results to the observer's native language + if($r[$x]['lang'] === $a->language) + $r[$x]['rank'] = $r[$x]['rank'] + 10; + + } + usort($r,'doc_rank_sort'); + return $r; +} + + +function doc_rank_sort($s1,$s2) { + if($s1['rank'] == $s2['rank']) + return 0; + return (($s1['rank'] < $s2['rank']) ? 1 : (-1)); +} + + + + +function store_doc_file($s) { + + if(is_dir($s)) + return; + + $item = array(); + $sys = get_sys_channel(); + + $item['aid'] = 0; + $item['uid'] = $sys['channel_id']; + + + if(strpos($s,'.md')) + $mimetype = 'text/markdown'; + elseif(strpos($s,'.html')) + $mimetype = 'text/html'; + else + $mimetype = 'text/bbcode'; + + require_once('include/html2plain.php'); + + $item['body'] = html2plain(prepare_text(file_get_contents($s),$mimetype, true)); + $item['mimetype'] = 'text/plain'; + + $item['plink'] = z_root() . '/' . str_replace('doc','help',$s); + $item['owner_xchan'] = $item['author_xchan'] = $sys['channel_hash']; + $item['item_type'] = ITEM_TYPE_DOC; + + $r = q("select item.* from item left join item_id on item.id = item_id.iid where service = 'docfile' and + sid = '%s' and item_type = %d limit 1", + dbesc($s), + intval(ITEM_TYPE_DOC) + ); + + if($r) { + $item['id'] = $r[0]['id']; + $item['mid'] = $item['parent_mid'] = $r[0]['mid']; + $x = item_store_update($item); + } + else { + $item['mid'] = $item['parent_mid'] = item_message_id(); + $x = item_store($item); + } + + if($x['success']) { + update_remote_id($sys,$x['item_id'],ITEM_TYPE_DOC,$s,'docfile',0,$item['mid']); + } + + +} function help_content(&$a) { nav_set_selected('help'); + if($_REQUEST['search']) { + + $o .= '<h2>' . t('Documentation Search') . ' - ' . htmlspecialchars($_REQUEST['search']) . '</h2>'; + + $r = search_doc_files($_REQUEST['search']); + if($r) { + $o .= '<ul class="help-searchlist">'; + foreach($r as $rr) { + $dirname = dirname($rr['sid']); + $fname = basename($rr['sid']); + $fname = substr($fname,0,strrpos($fname,'.')); + $path = trim(substr($dirname,4),'/'); + + $o .= '<li><a href="help/' . (($path) ? $path . '/' : '') . $fname . '" >' . ucwords(str_replace('_',' ',notags($fname))) . '</a><br />' . + str_replace('$Projectname',PLATFORM_NAME,substr($rr['text'],0,200)) . '...<br /><br /></li>'; + + } + $o .= '</ul>'; + } + return $o; + } + + global $lang; $doctype = 'markdown'; diff --git a/mod/home.php b/mod/home.php index 3091be3a1..242b2dcec 100644 --- a/mod/home.php +++ b/mod/home.php @@ -44,7 +44,6 @@ function home_content(&$a, $update = 0, $load = false) { $splash = ((argc() > 1 && argv(1) === 'splash') ? true : false); - call_hooks('home_content',$o); if($o) return $o; @@ -68,6 +67,7 @@ function home_content(&$a, $update = 0, $load = false) { goaway(z_root() . '/' . $frontpage); } + $sitename = get_config('system','sitename'); if($sitename) $o .= '<h1>' . sprintf( t("Welcome to %s") ,$sitename) . '</h1>'; diff --git a/mod/hostxrd.php b/mod/hostxrd.php index ef86f2dd9..0e18c133b 100644 --- a/mod/hostxrd.php +++ b/mod/hostxrd.php @@ -2,7 +2,8 @@ function hostxrd_init(&$a) { header('Access-Control-Allow-Origin: *'); - header("Content-type: text/xml"); + header("Content-type: application/xrd+xml"); + logger('hostxrd',LOGGER_DEBUG); $tpl = get_markup_template('xrd_host.tpl'); $x = replace_macros(get_markup_template('xrd_host.tpl'), array( diff --git a/mod/impel.php b/mod/impel.php index 0b29bcf02..da7138438 100644 --- a/mod/impel.php +++ b/mod/impel.php @@ -32,17 +32,17 @@ function impel_init(&$a) { switch($j['type']) { case 'webpage': - $arr['item_restrict'] = ITEM_WEBPAGE; + $arr['item_type'] = ITEM_TYPE_WEBPAGE; $namespace = 'WEBPAGE'; $installed_type = t('webpage'); break; case 'block': - $arr['item_restrict'] = ITEM_BUILDBLOCK; + $arr['item_type'] = ITEM_TYPE_BLOCK; $namespace = 'BUILDBLOCK'; $installed_type = t('block'); break; case 'layout': - $arr['item_restrict'] = ITEM_PDL; + $arr['item_type'] = ITEM_TYPE_PDL; $namespace = 'PDL'; $installed_type = t('layout'); break; @@ -157,7 +157,8 @@ function impel_init(&$a) { dbesc($namespace), intval(local_channel()) ); - $i = q("select id, edited, item_restrict from item where mid = '%s' and uid = %d limit 1", + + $i = q("select id, edited, item_deleted from item where mid = '%s' and uid = %d limit 1", dbesc($arr['mid']), intval(local_channel()) ); @@ -170,7 +171,7 @@ function impel_init(&$a) { $x = item_store_update($arr,$execflag); } else { - if(($i) && ($i[0]['item_restrict'] & ITEM_DELETED)) { + if(($i) && (intval($i[0]['item_deleted']))) { // was partially deleted already, finish it off q("delete from item where mid = '%s' and uid = %d", dbesc($arr['mid']), @@ -182,7 +183,7 @@ function impel_init(&$a) { if($x['success']) { $item_id = $x['item_id']; - update_remote_id($channel,$item_id,$arr['item_restrict'],$pagetitle,$namespace,$remote_id,$arr['mid']); + update_remote_id($channel,$item_id,$arr['item_type'],$pagetitle,$namespace,$remote_id,$arr['mid']); } } diff --git a/mod/import.php b/mod/import.php index 24780b6c4..563967aa2 100644 --- a/mod/import.php +++ b/mod/import.php @@ -6,6 +6,8 @@ require_once('include/Contact.php'); require_once('include/zot.php'); require_once('include/identity.php'); +require_once('include/import.php'); + function import_post(&$a) { @@ -36,6 +38,9 @@ function import_post(&$a) { $filesize = intval($_FILES['filename']['size']); $filetype = $_FILES['filename']['type']; + $completed = ((array_key_exists('import_step',$_SESSION)) ? intval($_SESSION['import_step']) : 0); + if($completed) + logger('saved import step: ' . $_SESSION['import_step']); if($src) { @@ -106,448 +111,359 @@ function import_post(&$a) { if(array_key_exists('compatibility',$data) && array_key_exists('database',$data['compatibility'])) { $v1 = substr($data['compatibility']['database'],-4); $v2 = substr(DB_UPDATE_VERSION,-4); - if($data['compatibility']['project'] !== PLATFORM_NAME) { - notice( t('The data provided is not compatible with this project.') ); - return; + if($v2 > $v1) { + $t = sprintf( t('Warning: Database versions differ by %1$d updates.'), $v2 - $v1 ); + notice($t); } } - if($v2 > $v1) { - $t = sprintf( t('Warning: Database versions differ by %1$d updates.'), $v2 - $v1 ); - notice($t); - } - // import channel - $channel = $data['channel']; - - $r = q("select * from channel where (channel_guid = '%s' or channel_hash = '%s' or channel_address = '%s' ) limit 1", - dbesc($channel['channel_guid']), - dbesc($channel['channel_hash']), - dbesc($channel['channel_address']) - ); + if(array_key_exists('channel',$data)) { - // We should probably also verify the hash + if($completed < 1) { + $channel = import_channel($data['channel']); - if($r) { - if($r[0]['channel_guid'] === $channel['channel_guid'] || $r[0]['channel_hash'] === $channel['channel_hash']) { - logger('mod_import: duplicate channel. ', print_r($channel,true)); - notice( t('Cannot create a duplicate channel identifier on this system. Import failed.') . EOL); - return; } else { - // try at most ten times to generate a unique address. - $x = 0; - $found_unique = false; - do { - $tmp = $channel['channel_address'] . mt_rand(1000,9999); - $r = q("select * from channel where channel_address = '%s' limit 1", - dbesc($tmp) - ); - if(! $r) { - $channel['channel_address'] = $tmp; - $found_unique = true; - break; - } - $x ++; - } while ($x < 10); - if(! $found_unique) { - logger('mod_import: duplicate channel. randomisation failed.', print_r($channel,true)); - notice( t('Unable to create a unique channel address. Import failed.') . EOL); - return; - } - } + $r = q("select * from channel where channel_account_id = %d and channel_guid = '%s' limit 1", + intval(get_account_id()), + dbesc($channel['channel_guid']) + ); + if($r) + $channel = $r[0]; + } + if(! $channel) { + logger('mod_import: channel not found. ', print_r($channel,true)); + notice( t('Cloned channel not found. Import failed.') . EOL); + return; + } } - unset($channel['channel_id']); - $channel['channel_account_id'] = get_account_id(); - $channel['channel_primary'] = (($seize) ? 1 : 0); + if(! $channel) + $channel = $a->get_channel(); - dbesc_array($channel); - - $r = dbq("INSERT INTO channel (`" - . implode("`, `", array_keys($channel)) - . "`) VALUES ('" - . implode("', '", array_values($channel)) - . "')" ); - - if(! $r) { - logger('mod_import: channel clone failed. ', print_r($channel,true)); - notice( t('Channel clone failed. Import failed.') . EOL); - return; - } - - $r = q("select * from channel where channel_account_id = %d and channel_guid = '%s' limit 1", - intval(get_account_id()), - $channel['channel_guid'] // Already dbesc'd - ); - if(! $r) { + if(! $channel) { logger('mod_import: channel not found. ', print_r($channel,true)); - notice( t('Cloned channel not found. Import failed.') . EOL); + notice( t('No channel. Import failed.') . EOL); return; } - // reset - $channel = $r[0]; - set_default_login_identity(get_account_id(),$channel['channel_id'],false); - - if($data['photo']) { - require_once('include/photo/photo_driver.php'); - import_channel_photo(base64url_decode($data['photo']['data']),$data['photo']['type'],get_account_id(),$channel['channel_id']); - } - $profiles = $data['profile']; - if($profiles) { - foreach($profiles as $profile) { - unset($profile['id']); - $profile['aid'] = get_account_id(); - $profile['uid'] = $channel['channel_id']; + if($completed < 2) { + if(is_array($data['config'])) { + import_config($channel,$data['config']); + } - // we are going to reset all profile photos to the original - // somebody will have to fix this later and put all the applicable photos into the export + logger('import step 2'); + $_SESSION['import_step'] = 2; + ref_session_write(session_id(), serialize($_SESSION)); + } - $profile['photo'] = z_root() . '/photo/profile/l/' . $channel['channel_id']; - $profile['thumb'] = z_root() . '/photo/profile/m/' . $channel['channel_id']; + if($completed < 3) { - dbesc_array($profile); - $r = dbq("INSERT INTO profile (`" - . implode("`, `", array_keys($profile)) - . "`) VALUES ('" - . implode("', '", array_values($profile)) - . "')" ); + if($data['photo']) { + require_once('include/photo/photo_driver.php'); + import_channel_photo(base64url_decode($data['photo']['data']),$data['photo']['type'],get_account_id(),$channel['channel_id']); } - } + if(is_array($data['profile'])) + import_profiles($channel,$data['profile']); - $hublocs = $data['hubloc']; - if($hublocs) { - foreach($hublocs as $hubloc) { - $arr = array( - 'guid' => $hubloc['hubloc_guid'], - 'guid_sig' => $hubloc['hubloc_guid_sig'], - 'url' => $hubloc['hubloc_url'], - 'url_sig' => $hubloc['hubloc_url_sig'] - ); - - $hash = make_xchan_hash($hubloc['hubloc_guid'],$hubloc['hubloc_guid_sig']); - if($hubloc['hubloc_network'] === 'zot' && $hash !== $hubloc['hubloc_hash']) { - logger('forged hubloc: ' . print_r($hubloc,true)); - continue; - } - - if(array_key_exists('hubloc_primary',$hubloc)) { - if(intval($hubloc['hubloc_primary'])) { - $hubloc['hubloc_flags'] |= HUBLOC_FLAGS_PRIMARY; - unset($hubloc['hubloc_primary']); - } - if(intval($hubloc['hubloc_orphancheck'])) { - $hubloc['hubloc_flags'] |= HUBLOC_FLAGS_ORPHANCHECK; - unset($hubloc['hubloc_orphancheck']); - } - if(intval($hubloc['hubloc_deleted'])) { - $hubloc['hubloc_flags'] |= HUBLOC_FLAGS_DELETED; - unset($hubloc['hubloc_deleted']); - } - if(intval($hubloc['hubloc_error'])) { - $hubloc['hubloc_status'] |= HUBLOC_ERROR; - unset($hubloc['hubloc_error']); - } - } + logger('import step 3'); + $_SESSION['import_step'] = 3; + ref_session_write(session_id(), serialize($_SESSION)); + } - if(($hubloc['hubloc_hash'] === $channel['channel_hash']) && ($hubloc['hubloc_flags'] & HUBLOC_FLAGS_PRIMARY) && ($seize)) - $hubloc['hubloc_flags'] = ($hubloc['hubloc_flags'] ^ HUBLOC_FLAGS_PRIMARY); - if(! zot_gethub($arr)) { - unset($hubloc['hubloc_id']); - dbesc_array($hubloc); - - $r = dbq("INSERT INTO hubloc (`" - . implode("`, `", array_keys($hubloc)) - . "`) VALUES ('" - . implode("', '", array_values($hubloc)) - . "')" ); + if($completed < 4) { - } + if(is_array($data['hubloc'])) { + import_hublocs($channel,$data['hubloc'],$seize); } + logger('import step 4'); + $_SESSION['import_step'] = 4; + ref_session_write(session_id(), serialize($_SESSION)); } - // create new hubloc for the new channel at this site - - $r = q("insert into hubloc ( hubloc_guid, hubloc_guid_sig, hubloc_hash, hubloc_addr, hubloc_network, hubloc_flags, - hubloc_url, hubloc_url_sig, hubloc_host, hubloc_callback, hubloc_sitekey ) - values ( '%s', '%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s' )", - dbesc($channel['channel_guid']), - dbesc($channel['channel_guid_sig']), - dbesc($channel['channel_hash']), - dbesc($channel['channel_address'] . '@' . get_app()->get_hostname()), - dbesc('zot'), - intval(($seize) ? HUBLOC_FLAGS_PRIMARY : 0), - dbesc(z_root()), - dbesc(base64url_encode(rsa_sign(z_root(),$channel['channel_prvkey']))), - dbesc(get_app()->get_hostname()), - dbesc(z_root() . '/post'), - dbesc(get_config('system','pubkey')) - ); - - // reset the original primary hubloc if it is being seized - - if($seize) - $r = q("update hubloc set hubloc_flags = (hubloc_flags & ~%d) where (hubloc_flags & %d)>0 and hubloc_hash = '%s' and hubloc_url != '%s' ", - intval(HUBLOC_FLAGS_PRIMARY), - intval(HUBLOC_FLAGS_PRIMARY), - dbesc($channel['channel_hash']), - dbesc(z_root()) - ); - - // import xchans and contact photos + if($completed < 5) { + // create new hubloc for the new channel at this site - if($seize) { - - // replace any existing xchan we may have on this site if we're seizing control - - $r = q("delete from xchan where xchan_hash = '%s'", - dbesc($channel['channel_hash']) - ); - - $r = q("insert into xchan ( xchan_hash, xchan_guid, xchan_guid_sig, xchan_pubkey, xchan_photo_l, xchan_photo_m, xchan_photo_s, xchan_addr, xchan_url, xchan_follow, xchan_connurl, xchan_name, xchan_network, xchan_photo_date, xchan_name_date ) values ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')", - dbesc($channel['channel_hash']), + $r = q("insert into hubloc ( hubloc_guid, hubloc_guid_sig, hubloc_hash, hubloc_addr, hubloc_network, hubloc_primary, + hubloc_url, hubloc_url_sig, hubloc_host, hubloc_callback, hubloc_sitekey ) + values ( '%s', '%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s' )", dbesc($channel['channel_guid']), dbesc($channel['channel_guid_sig']), - dbesc($channel['channel_pubkey']), - dbesc($a->get_baseurl() . "/photo/profile/l/" . $channel['channel_id']), - dbesc($a->get_baseurl() . "/photo/profile/m/" . $channel['channel_id']), - dbesc($a->get_baseurl() . "/photo/profile/s/" . $channel['channel_id']), + dbesc($channel['channel_hash']), dbesc($channel['channel_address'] . '@' . get_app()->get_hostname()), - dbesc(z_root() . '/channel/' . $channel['channel_address']), - dbesc(z_root() . '/follow?f=&url=%s'), - dbesc(z_root() . '/poco/' . $channel['channel_address']), - dbesc($channel['channel_name']), dbesc('zot'), - dbesc(datetime_convert()), - dbesc(datetime_convert()) + intval(($seize) ? 1 : 0), + dbesc(z_root()), + dbesc(base64url_encode(rsa_sign(z_root(),$channel['channel_prvkey']))), + dbesc(get_app()->get_hostname()), + dbesc(z_root() . '/post'), + dbesc(get_config('system','pubkey')) ); + + // reset the original primary hubloc if it is being seized + + if($seize) { + $r = q("update hubloc set hubloc_primary = 0 where hubloc_primary = 1 and hubloc_hash = '%s' and hubloc_url != '%s' ", + dbesc($channel['channel_hash']), + dbesc(z_root()) + ); + } + logger('import step 5'); + $_SESSION['import_step'] = 5; + ref_session_write(session_id(), serialize($_SESSION)); } + - $xchans = $data['xchan']; - if($xchans) { - foreach($xchans as $xchan) { + if($completed < 6) { - $hash = make_xchan_hash($xchan['xchan_guid'],$xchan['xchan_guid_sig']); - if($xchan['xchan_network'] === 'zot' && $hash !== $xchan['xchan_hash']) { - logger('forged xchan: ' . print_r($xchan,true)); - continue; - } + // import xchans and contact photos - $r = q("select xchan_hash from xchan where xchan_hash = '%s' limit 1", - dbesc($xchan['xchan_hash']) - ); - if($r) - continue; + if($seize) { - dbesc_array($xchan); - - $r = dbq("INSERT INTO xchan (`" - . implode("`, `", array_keys($xchan)) - . "`) VALUES ('" - . implode("', '", array_values($xchan)) - . "')" ); + // replace any existing xchan we may have on this site if we're seizing control - - require_once('include/photo/photo_driver.php'); - $photos = import_profile_photo($xchan['xchan_photo_l'],$xchan['xchan_hash']); - if($photos[4]) - $photodate = NULL_DATE; - else - $photodate = $xchan['xchan_photo_date']; - - $r = q("update xchan set xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s', xchan_photo_date = '%s' - where xchan_hash = '%s'", - dbesc($photos[0]), - dbesc($photos[1]), - dbesc($photos[2]), - dbesc($photos[3]), - dbesc($photodate), - dbesc($xchan['xchan_hash']) + $r = q("delete from xchan where xchan_hash = '%s'", + dbesc($channel['channel_hash']) + ); + + $r = q("insert into xchan ( xchan_hash, xchan_guid, xchan_guid_sig, xchan_pubkey, xchan_photo_l, xchan_photo_m, xchan_photo_s, xchan_addr, xchan_url, xchan_follow, xchan_connurl, xchan_name, xchan_network, xchan_photo_date, xchan_name_date, xchan_hidden, xchan_orphan, xchan_censored, xchan_selfcensored, xchan_system, xchan_pubforum, xchan_deleted ) values ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d, %d, %d, %d )", + dbesc($channel['channel_hash']), + dbesc($channel['channel_guid']), + dbesc($channel['channel_guid_sig']), + dbesc($channel['channel_pubkey']), + dbesc($a->get_baseurl() . "/photo/profile/l/" . $channel['channel_id']), + dbesc($a->get_baseurl() . "/photo/profile/m/" . $channel['channel_id']), + dbesc($a->get_baseurl() . "/photo/profile/s/" . $channel['channel_id']), + dbesc($channel['channel_address'] . '@' . get_app()->get_hostname()), + dbesc(z_root() . '/channel/' . $channel['channel_address']), + dbesc(z_root() . '/follow?f=&url=%s'), + dbesc(z_root() . '/poco/' . $channel['channel_address']), + dbesc($channel['channel_name']), + dbesc('zot'), + dbesc(datetime_convert()), + dbesc(datetime_convert()), + 0,0,0,0,0,0,0 ); - } + logger('import step 6'); + $_SESSION['import_step'] = 6; + ref_session_write(session_id(), serialize($_SESSION)); } -// FIXME - ensure we have an xchan if somebody is trying to pull a fast one + if($completed < 7) { - - $friends = 0; - $feeds = 0; - - // import contacts - $abooks = $data['abook']; - if($abooks) { - foreach($abooks as $abook) { - if(array_key_exists('abook_blocked',$abook) && intval($abook['abook_blocked'])) { - $abook['abook_flags'] |= ABOOK_FLAG_BLOCKED; - } - if(array_key_exists('abook_ignored',$abook) && intval($abook['abook_ignored'])) { - $abook['abook_flags'] |= ABOOK_FLAG_IGNORED; - } - if(array_key_exists('abook_hidden',$abook) && intval($abook['abook_hidden'])) { - $abook['abook_flags'] |= ABOOK_FLAG_HIDDEN; - } - if(array_key_exists('abook_archived',$abook) && intval($abook['abook_archived'])) { - $abook['abook_flags'] |= ABOOK_FLAG_ARCHIVED; - } - if(array_key_exists('abook_pending',$abook) && intval($abook['abook_pending'])) { - $abook['abook_flags'] |= ABOOK_FLAG_PENDING; - } - if(array_key_exists('abook_unconnected',$abook) && intval($abook['abook_unconnected'])) { - $abook['abook_flags'] |= ABOOK_FLAG_UNCONNECTED; - } - if(array_key_exists('abook_self',$abook) && intval($abook['abook_self'])) { - $abook['abook_flags'] |= ABOOK_FLAG_SELF; - } - if(array_key_exists('abook_feed',$abook) && intval($abook['abook_feed'])) { - $abook['abook_flags'] |= ABOOK_FLAG_FEED; - } + $xchans = $data['xchan']; + if($xchans) { + foreach($xchans as $xchan) { - if(! ( $abook['abook_flags'] & ABOOK_FLAG_SELF)) { - if($max_friends !== false && $friends > $max_friends) + $hash = make_xchan_hash($xchan['xchan_guid'],$xchan['xchan_guid_sig']); + if($xchan['xchan_network'] === 'zot' && $hash !== $xchan['xchan_hash']) { + logger('forged xchan: ' . print_r($xchan,true)); continue; - if($max_feeds !== false && ($abook['abook_flags'] & ABOOK_FLAG_FEED) && $feeds > $max_feeds) + } + + if(! array_key_exists('xchan_hidden',$xchan)) { + $xchan['xchan_hidden'] = (($xchan['xchan_flags'] & 0x0001) ? 1 : 0); + $xchan['xchan_orphan'] = (($xchan['xchan_flags'] & 0x0002) ? 1 : 0); + $xchan['xchan_censored'] = (($xchan['xchan_flags'] & 0x0004) ? 1 : 0); + $xchan['xchan_selfcensored'] = (($xchan['xchan_flags'] & 0x0008) ? 1 : 0); + $xchan['xchan_system'] = (($xchan['xchan_flags'] & 0x0010) ? 1 : 0); + $xchan['xchan_pubforum'] = (($xchan['xchan_flags'] & 0x0020) ? 1 : 0); + $xchan['xchan_deleted'] = (($xchan['xchan_flags'] & 0x1000) ? 1 : 0); + } + + $r = q("select xchan_hash from xchan where xchan_hash = '%s' limit 1", + dbesc($xchan['xchan_hash']) + ); + if($r) continue; + + dbesc_array($xchan); + + $r = dbq("INSERT INTO xchan (`" + . implode("`, `", array_keys($xchan)) + . "`) VALUES ('" + . implode("', '", array_values($xchan)) + . "')" ); + + + require_once('include/photo/photo_driver.php'); + $photos = import_xchan_photo($xchan['xchan_photo_l'],$xchan['xchan_hash']); + if($photos[4]) + $photodate = NULL_DATE; + else + $photodate = $xchan['xchan_photo_date']; + + $r = q("update xchan set xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s', xchan_photo_date = '%s' + where xchan_hash = '%s'", + dbesc($photos[0]), + dbesc($photos[1]), + dbesc($photos[2]), + dbesc($photos[3]), + dbesc($photodate), + dbesc($xchan['xchan_hash']) + ); + } - unset($abook['abook_id']); - $abook['abook_account'] = get_account_id(); - $abook['abook_channel'] = $channel['channel_id']; - dbesc_array($abook); - $r = dbq("INSERT INTO abook (`" - . implode("`, `", array_keys($abook)) - . "`) VALUES ('" - . implode("', '", array_values($abook)) - . "')" ); - - $friends ++; - if($abook['abook_flags'] & ABOOK_FLAG_FEED) - $feeds ++; } + logger('import step 7'); + $_SESSION['import_step'] = 7; + ref_session_write(session_id(), serialize($_SESSION)); } - $configs = $data['config']; - if($configs) { - foreach($configs as $config) { - unset($config['id']); - $config['uid'] = $channel['channel_id']; - dbesc_array($config); - $r = dbq("INSERT INTO pconfig (`" - . implode("`, `", array_keys($config)) - . "`) VALUES ('" - . implode("', '", array_values($config)) - . "')" ); - } - } - $groups = $data['group']; - if($groups) { - $saved = array(); - foreach($groups as $group) { - $saved[$group['hash']] = array('old' => $group['id']); - unset($group['id']); - $group['uid'] = $channel['channel_id']; - dbesc_array($group); - $r = dbq("INSERT INTO groups (`" - . implode("`, `", array_keys($group)) - . "`) VALUES ('" - . implode("', '", array_values($group)) - . "')" ); - } - $r = q("select * from `groups` where uid = %d", - intval($channel['channel_id']) - ); - if($r) { - foreach($r as $rr) { - $saved[$rr['hash']]['new'] = $rr['id']; - } - } - } + // FIXME - ensure we have an xchan if somebody is trying to pull a fast one + + if($completed < 8) { + $friends = 0; + $feeds = 0; + + // import contacts + $abooks = $data['abook']; + if($abooks) { + foreach($abooks as $abook) { + + unset($abook['abook_id']); + unset($abook['abook_rating']); + unset($abook['abook_rating_text']); + $abook['abook_account'] = get_account_id(); + $abook['abook_channel'] = $channel['channel_id']; + if(! array_key_exists('abook_blocked',$abook)) { + $abook['abook_blocked'] = (($abook['abook_flags'] & 0x0001 ) ? 1 : 0); + $abook['abook_ignored'] = (($abook['abook_flags'] & 0x0002 ) ? 1 : 0); + $abook['abook_hidden'] = (($abook['abook_flags'] & 0x0004 ) ? 1 : 0); + $abook['abook_archived'] = (($abook['abook_flags'] & 0x0008 ) ? 1 : 0); + $abook['abook_pending'] = (($abook['abook_flags'] & 0x0010 ) ? 1 : 0); + $abook['abook_unconnected'] = (($abook['abook_flags'] & 0x0020 ) ? 1 : 0); + $abook['abook_self'] = (($abook['abook_flags'] & 0x0080 ) ? 1 : 0); + $abook['abook_feed'] = (($abook['abook_flags'] & 0x0100 ) ? 1 : 0); + } - $group_members = $data['group_member']; - if($group_members) { - foreach($group_members as $group_member) { - unset($group_member['id']); - $group_member['uid'] = $channel['channel_id']; - foreach($saved as $x) { - if($x['old'] == $group_member['gid']) - $group_member['gid'] = $x['new']; + if($abook['abook_self']) { + $role = get_pconfig($channel['channel_id'],'system','permissions_role'); + if(($role === 'forum') || ($abook['abook_my_perms'] & PERMS_W_TAGWALL)) { + q("update xchan set xchan_pubforum = 1 where xchan_hash = '%s' ", + dbesc($abook['abook_xchan']) + ); + } + } + else { + if($max_friends !== false && $friends > $max_friends) + continue; + if($max_feeds !== false && intval($abook['abook_feed']) && ($feeds > $max_feeds)) + continue; + } + + dbesc_array($abook); + $r = dbq("INSERT INTO abook (`" + . implode("`, `", array_keys($abook)) + . "`) VALUES ('" + . implode("', '", array_values($abook)) + . "')" ); + + $friends ++; + if(intval($abook['abook_feed'])) + $feeds ++; } - dbesc_array($group_member); - $r = dbq("INSERT INTO group_member (`" - . implode("`, `", array_keys($group_member)) - . "`) VALUES ('" - . implode("', '", array_values($group_member)) - . "')" ); } + logger('import step 8'); + $_SESSION['import_step'] = 8; + ref_session_write(session_id(), serialize($_SESSION)); } - $saved_notification_flags = notifications_off($channel['channel_id']); - - if($import_posts && array_key_exists('item',$data) && $data['item']) { - foreach($data['item'] as $i) { - $item = get_item_elements($i); - $r = q("select id, edited from item where mid = '%s' and uid = %d limit 1", - dbesc($item['mid']), + if($completed < 9) { + $groups = $data['group']; + if($groups) { + $saved = array(); + foreach($groups as $group) { + $saved[$group['hash']] = array('old' => $group['id']); + unset($group['id']); + $group['uid'] = $channel['channel_id']; + dbesc_array($group); + $r = dbq("INSERT INTO groups (`" + . implode("`, `", array_keys($group)) + . "`) VALUES ('" + . implode("', '", array_values($group)) + . "')" ); + } + $r = q("select * from `groups` where uid = %d", intval($channel['channel_id']) ); if($r) { - if($item['edited'] > $r[0]['edited']) { - $item['id'] = $r[0]['id']; - $item['uid'] = $channel['channel_id']; - item_store_update($item); - continue; - } - } - else { - $item['aid'] = $channel['channel_account_id']; - $item['uid'] = $channel['channel_id']; - $item_result = item_store($item); - } - + foreach($r as $rr) { + $saved[$rr['hash']]['new'] = $rr['id']; + } + } } - } - - notifications_on($channel['channel_id'],$saved_notification_flags); - if(array_key_exists('item_id',$data) && $data['item_id']) { - foreach($data['item_id'] as $i) { - $r = q("select id from item where mid = '%s' and uid = %d limit 1", - dbesc($i['mid']), - intval($channel['channel_id']) - ); - if(! $r) - continue; - $z = q("select * from item_id where service = '%s' and sid = '%s' and iid = %d and uid = %d limit 1", - dbesc($i['service']), - dbesc($i['sid']), - intval($r[0]['id']), - intval($channel['channel_id']) - ); - if(! $z) { - q("insert into item_id (iid,uid,sid,service) values(%d,%d,'%s','%s')", - intval($r[0]['id']), - intval($channel['channel_id']), - dbesc($i['sid']), - dbesc($i['service']) - ); + $group_members = $data['group_member']; + if($group_members) { + foreach($group_members as $group_member) { + unset($group_member['id']); + $group_member['uid'] = $channel['channel_id']; + foreach($saved as $x) { + if($x['old'] == $group_member['gid']) + $group_member['gid'] = $x['new']; + } + dbesc_array($group_member); + $r = dbq("INSERT INTO group_member (`" + . implode("`, `", array_keys($group_member)) + . "`) VALUES ('" + . implode("', '", array_values($group_member)) + . "')" ); } } + logger('import step 9'); + $_SESSION['import_step'] = 9; + ref_session_write(session_id(), serialize($_SESSION)); } + if(is_array($data['obj'])) + import_objs($channel,$data['obj']); + + if(is_array($data['likes'])) + import_likes($channel,$data['likes']); + + if(is_array($data['app'])) + import_apps($channel,$data['app']); + + if(is_array($data['chatroom'])) + import_chatrooms($channel,$data['chatroom']); + + if(is_array($data['event'])) + import_events($channel,$data['event']); + + if(is_array($data['event_item'])) + import_items($channel,$data['event_item']); + + if(is_array($data['menu'])) + import_menus($channel,$data['menu']); + + + $saved_notification_flags = notifications_off($channel['channel_id']); + + if($import_posts && array_key_exists('item',$data) && $data['item']) + import_items($channel,$data['item']); + + notifications_on($channel['channel_id'],$saved_notification_flags); + + + if(array_key_exists('item_id',$data) && $data['item_id']) + import_item_ids($channel,$data['item_id']); -// FIXME - ensure we have a self entry if somebody is trying to pull a fast one + // FIXME - ensure we have a self entry if somebody is trying to pull a fast one // send out refresh requests // notify old server that it may no longer be primary. @@ -563,6 +479,7 @@ function import_post(&$a) { change_channel($channel['channel_id']); + unset($_SESSION['import_step']); goaway(z_root() . '/network' ); } diff --git a/mod/import_items.php b/mod/import_items.php new file mode 100644 index 000000000..6b97939c9 --- /dev/null +++ b/mod/import_items.php @@ -0,0 +1,129 @@ +<?php + +require_once('include/import.php'); + +function import_items_post(&$a) { + + if(! local_channel()) + return; + + $data = null; + + $src = $_FILES['filename']['tmp_name']; + $filename = basename($_FILES['filename']['name']); + $filesize = intval($_FILES['filename']['size']); + $filetype = $_FILES['filename']['type']; + + if($src) { + // This is OS specific and could also fail if your tmpdir isn't very large + // mostly used for Diaspora which exports gzipped files. + + if(strpos($filename,'.gz')){ + @rename($src,$src . '.gz'); + @system('gunzip ' . escapeshellarg($src . '.gz')); + } + + if($filesize) { + $data = @file_get_contents($src); + } + unlink($src); + } + + if(! $src) { + + $old_address = ((x($_REQUEST,'old_address')) ? $_REQUEST['old_address'] : ''); + + if(! $old_address) { + logger('mod_import: nothing to import.'); + notice( t('Nothing to import.') . EOL); + return; + } + + $email = ((x($_REQUEST,'email')) ? $_REQUEST['email'] : ''); + $password = ((x($_REQUEST,'password')) ? $_REQUEST['password'] : ''); + + $year = ((x($_REQUEST,'year')) ? $_REQUEST['year'] : ''); + + $channelname = substr($old_address,0,strpos($old_address,'@')); + $servername = substr($old_address,strpos($old_address,'@')+1); + + $scheme = 'https://'; + $api_path = '/api/red/channel/export/items?f=&channel=' . $channelname . '&year=' . intval($year); + $binary = false; + $redirects = 0; + $opts = array('http_auth' => $email . ':' . $password); + $url = $scheme . $servername . $api_path; + $ret = z_fetch_url($url, $binary, $redirects, $opts); + if(! $ret['success']) + $ret = z_fetch_url('http://' . $servername . $api_path, $binary, $redirects, $opts); + if($ret['success']) + $data = $ret['body']; + else + notice( t('Unable to download data from old server') . EOL); + + } + + if(! $data) { + logger('mod_import: empty file.'); + notice( t('Imported file is empty.') . EOL); + return; + } + + $data = json_decode($data,true); + +// logger('import: data: ' . print_r($data,true)); +// print_r($data); + + + if(array_key_exists('compatibility',$data) && array_key_exists('database',$data['compatibility'])) { + $v1 = substr($data['compatibility']['database'],-4); + $v2 = substr(DB_UPDATE_VERSION,-4); + if($v2 > $v1) { + $t = sprintf( t('Warning: Database versions differ by %1$d updates.'), $v2 - $v1 ); + notice($t); + } + } + + $channel = $a->get_channel(); + + $saved_notification_flags = notifications_off($channel['channel_id']); + + if(array_key_exists('item',$data) && $data['item']) { + import_items($channel,$data['item']); + } + + notifications_on($channel['channel_id'],$saved_notification_flags); + + if(array_key_exists('item_id',$data) && $data['item_id']) { + import_item_ids($channel,$data['item_id']); + } + + info( t('Import completed') . EOL); + return; +} + + + + +function import_items_content(&$a) { + + + + + if(! local_channel()) { + notice( t('Permission denied') . EOL); + return login(); + } + + $o = replace_macros(get_markup_template('item_import.tpl'),array( + '$title' => t('Import Items'), + '$desc' => t('Use this form to import existing posts and content from an export file.'), + '$label_filename' => t('File to Upload'), + '$submit' => t('Submit') + )); + + return $o; + +} + + diff --git a/mod/invite.php b/mod/invite.php index 1fdfbacc6..46fa7b413 100644 --- a/mod/invite.php +++ b/mod/invite.php @@ -73,7 +73,7 @@ function invite_post(&$a) { $account = $a->get_account(); - $res = mail($recip, sprintf( t('Please join us on Red'), $a->config['sitename']), + $res = mail($recip, sprintf( t('Please join us on $Projectname'), $a->config['sitename']), $nmessage, "From: " . $account['account_email'] . "\n" . 'Content-type: text/plain; charset=UTF-8' . "\n" diff --git a/mod/item.php b/mod/item.php index bff312cfe..d0cf59091 100644 --- a/mod/item.php +++ b/mod/item.php @@ -115,7 +115,7 @@ function item_post(&$a) { * Check service class limits */ if ($uid && !(x($_REQUEST,'parent')) && !(x($_REQUEST,'post_id'))) { - $ret = item_check_service_class($uid,(($_REQUEST['webpage'] == ITEM_WEBPAGE) ? true : false)); + $ret = item_check_service_class($uid,(($_REQUEST['webpage'] == ITEM_TYPE_WEBPAGE) ? true : false)); if (!$ret['success']) { notice( t($ret['message']) . EOL) ; if(x($_REQUEST,'return')) @@ -197,7 +197,7 @@ function item_post(&$a) { if($parent) { logger('mod_item: item_post parent=' . $parent); $can_comment = false; - if((array_key_exists('owner',$parent_item)) && ($parent_item['owner']['abook_flags'] & ABOOK_FLAG_SELF)) + if((array_key_exists('owner',$parent_item)) && intval($parent_item['owner']['abook_self'])) $can_comment = perm_is_allowed($profile_uid,$observer['xchan_hash'],'post_comments'); else $can_comment = can_comment_on_post($observer['xchan_hash'],$parent_item); @@ -295,7 +295,7 @@ function item_post(&$a) { // For comments, We need to additionally look at the parent and see if it's a wall post that originated locally. if($observer['xchan_name'] != $owner_xchan['xchan_name']) { - if($parent_item && ($parent_item['item_flags'] & (ITEM_WALL|ITEM_ORIGIN)) == (ITEM_WALL|ITEM_ORIGIN)) { + if(($parent_item) && ($parent_item['item_wall'] && $parent_item['item_origin'])) { $walltowall_comment = true; $walltowall = true; } @@ -305,6 +305,8 @@ function item_post(&$a) { } } + $acl = new AccessList($channel); + $public_policy = ((x($_REQUEST,'public_policy')) ? escape_tags($_REQUEST['public_policy']) : map_scope($channel['channel_r_stream'],true)); if($webpage) @@ -316,28 +318,17 @@ function item_post(&$a) { $private = 0; // webpages are allowed to change ACLs after the fact. Normal conversation items aren't. if($webpage) { - $str_group_allow = perms2str($_REQUEST['group_allow']); - $str_contact_allow = perms2str($_REQUEST['contact_allow']); - $str_group_deny = perms2str($_REQUEST['group_deny']); - $str_contact_deny = perms2str($_REQUEST['contact_deny']); + $acl->set_from_array($_REQUEST); } else { - $str_group_allow = $orig_post['allow_gid']; - $str_contact_allow = $orig_post['allow_cid']; - $str_group_deny = $orig_post['deny_gid']; - $str_contact_deny = $orig_post['deny_cid']; + $acl->set($orig_post); $public_policy = $orig_post['public_policy']; $private = $orig_post['item_private']; } - if((strlen($str_group_allow)) - || strlen($str_contact_allow) - || strlen($str_group_deny) - || strlen($str_contact_deny) - || strlen($public_policy) - || $private) { + if($private || $public_policy || $acl->is_private()) $private = 1; - } + $location = $orig_post['location']; $coord = $orig_post['coord']; @@ -347,12 +338,32 @@ function item_post(&$a) { $body = trim($_REQUEST['body']); $item_flags = $orig_post['item_flags']; - // force us to recalculate if we need to obscure this post + $item_origin = $orig_post['item_origin']; + $item_unseen = $orig_post['item_unseen']; + $item_starred = $orig_post['item_starred']; + $item_uplink = $orig_post['item_uplink']; + $item_consensus = $orig_post['item_consensus']; + $item_wall = $orig_post['item_wall']; + $item_thread_top = $orig_post['item_thread_top']; + $item_notshown = $orig_post['item_notshown']; + $item_nsfw = $orig_post['item_nsfw']; + $item_relay = $orig_post['item_relay']; + $item_mentionsme = $orig_post['item_mentionsme']; + $item_nocomment = $orig_post['item_nocomment']; + $item_obscured = $orig_post['item_obscured']; + $item_verified = $orig_post['item_verified']; + $item_retained = $orig_post['item_retained']; + $item_rss = $orig_post['item_rss']; + $item_deleted = $orig_post['item_deleted']; + $item_type = $orig_post['item_type']; + $item_hidden = $orig_post['item_hidden']; + $item_unpublished = $orig_post['item_unpublished']; + $item_delayed = $orig_post['item_delayed']; + $item_pending_remove = $orig_post['item_pending_remove']; + $item_blocked = $orig_post['item_blocked']; + - if($item_flags & ITEM_OBSCURED) - $item_flags = ($item_flags ^ ITEM_OBSCURED); - $item_restrict = $orig_post['item_restrict']; $postopts = $orig_post['postopts']; $created = $orig_post['created']; $mid = $orig_post['mid']; @@ -361,38 +372,12 @@ function item_post(&$a) { } else { - - // if coming from the API and no privacy settings are set, - // use the user default permissions - as they won't have - // been supplied via a form. - - if(($api_source) - && (! array_key_exists('contact_allow',$_REQUEST)) - && (! array_key_exists('group_allow',$_REQUEST)) - && (! array_key_exists('contact_deny',$_REQUEST)) - && (! array_key_exists('group_deny',$_REQUEST))) { - $str_group_allow = $channel['channel_allow_gid']; - $str_contact_allow = $channel['channel_allow_cid']; - $str_group_deny = $channel['channel_deny_gid']; - $str_contact_deny = $channel['channel_deny_cid']; - } - elseif($walltowall) { - - // use the channel owner's default permissions - - $str_group_allow = $channel['channel_allow_gid']; - $str_contact_allow = $channel['channel_allow_cid']; - $str_group_deny = $channel['channel_deny_gid']; - $str_contact_deny = $channel['channel_deny_cid']; - } - else { - - // use the posted permissions - - $str_group_allow = perms2str($_REQUEST['group_allow']); - $str_contact_allow = perms2str($_REQUEST['contact_allow']); - $str_group_deny = perms2str($_REQUEST['group_deny']); - $str_contact_deny = perms2str($_REQUEST['contact_deny']); + if((! $walltowall) && + ((array_key_exists('contact_allow',$_REQUEST)) + || (array_key_exists('group_allow',$_REQUEST)) + || (array_key_exists('contact_deny',$_REQUEST)) + || (array_key_exists('group_deny',$_REQUEST)))) { + $acl->set_from_array($_REQUEST); } @@ -404,33 +389,15 @@ function item_post(&$a) { $body .= trim($_REQUEST['attachment']); $postopts = ''; - $private = ( - ( strlen($str_group_allow) - || strlen($str_contact_allow) - || strlen($str_group_deny) - || strlen($str_contact_deny) - || strlen($public_policy) - ) ? 1 : 0); + $private = intval($acl->is_private() || ($public_policy)); // If this is a comment, set the permissions from the parent. if($parent_item) { $private = 0; - - if(($parent_item['item_private']) - || strlen($parent_item['allow_cid']) - || strlen($parent_item['allow_gid']) - || strlen($parent_item['deny_cid']) - || strlen($parent_item['deny_gid']) - || strlen($parent_item['public_policy'])) { - $private = (($parent_item['item_private']) ? $parent_item['item_private'] : 1); - } - + $acl->set($parent_item); + $private = intval($acl->is_private() || $parent_item['item_private']); $public_policy = $parent_item['public_policy']; - $str_contact_allow = $parent_item['allow_cid']; - $str_group_allow = $parent_item['allow_gid']; - $str_contact_deny = $parent_item['deny_cid']; - $str_group_deny = $parent_item['deny_gid']; $owner_hash = $parent_item['owner_xchan']; } @@ -485,6 +452,11 @@ function item_post(&$a) { } } + $gacl = $acl->get(); + $str_contact_allow = $gacl['allow_cid']; + $str_group_allow = $gacl['allow_gid']; + $str_contact_deny = $gacl['deny_cid']; + $str_group_deny = $gacl['deny_gid']; if($mimetype === 'text/bbcode') { @@ -549,9 +521,6 @@ function item_post(&$a) { $body = preg_replace_callback('/\[img(.*?)\](.*?)\[\/img\]/ism','red_zrlify_img_callback',$body); - - - $body = bb_translate_video($body); /** @@ -629,6 +598,7 @@ function item_post(&$a) { if(preg_match_all('/(\[attachment\](.*?)\[\/attachment\])/',$body,$match)) { $attachments = array(); foreach($match[2] as $mtch) { + $attach_link = ''; $hash = substr($mtch,0,strpos($mtch,',')); $rev = intval(substr($mtch,strpos($mtch,','))); $r = attach_by_hash_nodata($hash,$rev); @@ -641,7 +611,12 @@ function item_post(&$a) { 'revision' => $r['data']['revision'] ); } - $body = str_replace($match[1],'',$body); + $ext = substr($r['data']['filename'],strrpos($r['data']['filename'],'.')); + if(strpos($r['data']['filetype'],'audio/') !== false) + $attach_link = '[audio]' . z_root() . '/attach/' . $r['data']['hash'] . '/' . $r['data']['revision'] . (($ext) ? $ext : '') . '[/audio]'; + elseif(strpos($r['data']['filetype'],'video/') !== false) + $attach_link = '[video]' . z_root() . '/attach/' . $r['data']['hash'] . '/' . $r['data']['revision'] . (($ext) ? $ext : '') . '[/video]'; + $body = str_replace($match[1],$attach_link,$body); } } @@ -662,31 +637,27 @@ function item_post(&$a) { } } - $item_unseen = 1; - + + $item_unseen = ((local_channel() != $profile_uid) ? 1 : 0); + $item_wall = (($post_type === 'wall' || $post_type === 'wall-comment') ? 1 : 0); + $item_origin = (($origin) ? 1 : 0); + // determine if this is a wall post if($parent) { - if($parent_item['item_flags'] & ITEM_WALL) { - $item_flags = $item_flags | ITEM_WALL; - } + $item_wall = $parent_item['item_wall']; } else { if(! $webpage) { - $item_flags = $item_flags | ITEM_WALL; + $item_wall = 1; } } - if($origin) - $item_flags = $item_flags | ITEM_ORIGIN; if($moderated) - $item_restrict = $item_restrict | ITEM_MODERATED; + $item_blocked = ITEM_MODERATED; - if($webpage) - $item_restrict = $item_restrict | $webpage; - if(! strlen($verb)) $verb = ACTIVITY_POST ; @@ -710,14 +681,10 @@ function item_post(&$a) { $datarray = array(); - if(! $parent) { - $item_flags = $item_flags | ITEM_THREAD_TOP; - } + $item_thead_top = ((! $parent) ? 1 : 0); - if($consensus) - $item_flags |= ITEM_CONSENSUS; - if ((! $plink) && ($item_flags & ITEM_THREAD_TOP)) { + if ((! $plink) && ($item_thread_top)) { $plink = z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . $mid; } @@ -747,18 +714,41 @@ function item_post(&$a) { $datarray['deny_cid'] = $str_contact_deny; $datarray['deny_gid'] = $str_group_deny; $datarray['item_private'] = $private; + $datarray['item_wall'] = $item_wall; $datarray['attach'] = $attachments; $datarray['thr_parent'] = $thr_parent; $datarray['postopts'] = $postopts; - $datarray['item_restrict'] = $item_restrict; - $datarray['item_flags'] = $item_flags; + $datarray['item_unseen'] = $item_unseen; + $datarray['item_wall'] = $item_wall; + $datarray['item_origin'] = $item_origin; + $datarray['item_type'] = $webpage; + $datarray['item_thread_top'] = $item_thread_top; + $datarray['item_unseen'] = $item_unseen; + $datarray['item_starred'] = $item_starred; + $datarray['item_uplink'] = $item_uplink; + $datarray['item_consensus'] = $item_consensus; + $datarray['item_notshown'] = $item_notshown; + $datarray['item_nsfw'] = $item_nsfw; + $datarray['item_relay'] = $item_relay; + $datarray['item_mentionsme'] = $item_mentionsme; + $datarray['item_nocomment'] = $item_nocomment; + $datarray['item_obscured'] = $item_obscured; + $datarray['item_verified'] = $item_verified; + $datarray['item_retained'] = $item_retained; + $datarray['item_rss'] = $item_rss; + $datarray['item_deleted'] = $item_deleted; + $datarray['item_hidden'] = $item_hidden; + $datarray['item_unpublished'] = $item_unpublished; + $datarray['item_delayed'] = $item_delayed; + $datarray['item_pending_remove'] = $item_pending_remove; + $datarray['item_blocked'] = $item_blocked; + $datarray['layout_mid'] = $layout_mid; $datarray['public_policy'] = $public_policy; $datarray['comment_policy'] = map_scope($channel['channel_w_comment']); $datarray['term'] = $post_tags; $datarray['plink'] = $plink; $datarray['route'] = $route; - $datarray['item_unseen'] = $item_unseen; // preview mode - prepare the body for display and send it via json @@ -803,17 +793,9 @@ function item_post(&$a) { if($uid) { if($channel['channel_hash'] === $datarray['author_xchan']) { $datarray['sig'] = base64url_encode(rsa_sign($datarray['body'],$channel['channel_prvkey'])); - $datarray['item_flags'] = $datarray['item_flags'] | ITEM_VERIFIED; + $datarray['item_verified'] = 1; } } - - logger('Encrypting local storage'); - $key = get_config('system','pubkey'); - $datarray['item_flags'] = $datarray['item_flags'] | ITEM_OBSCURED; - if($datarray['title']) - $datarray['title'] = json_encode(crypto_encapsulate($datarray['title'],$key)); - if($datarray['body']) - $datarray['body'] = json_encode(crypto_encapsulate($datarray['body'],$key)); } if($orig_post) { @@ -860,7 +842,7 @@ function item_post(&$a) { // only send comment notification if this is a wall-to-wall comment, // otherwise it will happen during delivery - if(($datarray['owner_xchan'] != $datarray['author_xchan']) && ($parent_item['item_flags'] & ITEM_WALL)) { + if(($datarray['owner_xchan'] != $datarray['author_xchan']) && (intval($parent_item['item_wall']))) { notification(array( 'type' => NOTIFY_COMMENT, 'from_xchan' => $datarray['author_xchan'], @@ -890,7 +872,7 @@ function item_post(&$a) { )); } - if($uid && $uid == $profile_uid && (! $datarray['item_restrict'])) { + if($uid && $uid == $profile_uid && (is_item_normal($datarray))) { q("update channel set channel_lastpost = '%s' where channel_id = %d", dbesc(datetime_convert()), intval($uid) @@ -902,9 +884,8 @@ function item_post(&$a) { // This way we don't see every picture in your new photo album posted to your wall at once. // They will show up as people comment on them. - if($parent_item['item_restrict'] & ITEM_HIDDEN) { - $r = q("UPDATE `item` SET `item_restrict` = %d WHERE `id` = %d", - intval($parent_item['item_restrict'] - ITEM_HIDDEN), + if(intval($parent_item['item_hidden'])) { + $r = q("UPDATE item SET item_hidden = 0 WHERE id = %d", intval($parent_item['id']) ); } @@ -949,6 +930,11 @@ function item_post(&$a) { logger('post_complete'); + + + + + // figure out how to return, depending on from whence we came if($api_source) @@ -983,7 +969,7 @@ function item_content(&$a) { if((argc() == 3) && (argv(1) === 'drop') && intval(argv(2))) { require_once('include/items.php'); - $i = q("select id, uid, author_xchan, owner_xchan, source_xchan, item_restrict from item where id = %d limit 1", + $i = q("select id, uid, author_xchan, owner_xchan, source_xchan, item_type from item where id = %d limit 1", intval(argv(2)) ); @@ -1009,7 +995,7 @@ function item_content(&$a) { // if this is a different page type or it's just a local delete // but not by the item author or owner, do a simple deletion - if($i[0]['item_restrict'] || ($local_delete && (! $can_delete))) { + if(intval($i[0]['item_type']) || ($local_delete && (! $can_delete))) { drop_item($i[0]['id']); } else { @@ -1045,6 +1031,23 @@ function fix_attached_photo_permissions($uid,$xchan_hash,$body, if(! strlen($image_uri)) continue; $srch = '<' . $xchan_hash . '>'; + + $r = q("select folder from attach where hash = '%s' and uid = %d limit 1", + dbesc($image_uri), + intval($uid) + ); + if($r && $r[0]['folder']) { + $f = q("select * from attach where hash = '%s' and is_dir = 1 and uid = %d limit 1", + dbesc($r[0]['folder']), + intval($uid) + ); + if(($f) && (($f[0]['allow_cid']) || ($f[0]['allow_gid']) || ($f[0]['deny_cid']) || ($f[0]['deny_gid']))) { + $str_contact_allow = $f[0]['allow_cid']; + $str_group_allow = $f[0]['allow_gid']; + $str_contact_deny = $f[0]['deny_cid']; + $str_group_deny = $f[0]['deny_gid']; + } + } $r = q("SELECT id FROM photo WHERE allow_cid = '%s' AND allow_gid = '' AND deny_cid = '' AND deny_gid = '' @@ -1088,6 +1091,21 @@ function fix_attached_photo_permissions($uid,$xchan_hash,$body, intval($uid) ); } + $r = q("select id from attach where hash = '%s' and uid = %d limit 1", + dbesc($image_uri), + intval($uid) + ); + if($r) { + q("update attach SET allow_cid = '%s', allow_gid = '%s', deny_cid = '%s', deny_gid = '%s' + WHERE id = %d AND uid = %d", + dbesc($str_contact_allow), + dbesc($str_group_allow), + dbesc($str_contact_deny), + dbesc($str_group_deny), + intval($r[0]['id']), + intval($uid) + ); + } } } } @@ -1127,17 +1145,15 @@ function item_check_service_class($channel_id,$iswebpage) { $ret = array('success' => false, 'message' => ''); if ($iswebpage) { - // note: we aren't counting comanche templates and blocks, only webpages - $r = q("select count(id) as total from item where parent = id - and ( item_restrict & %d ) > 0 and ( item_restrict & %d ) = 0 and uid = %d ", - intval(ITEM_WEBPAGE), - intval(ITEM_DELETED), + $r = q("select count(i.id) as total from item i + right join channel c on (i.author_xchan=c.channel_hash and i.uid=c.channel_id ) + and i.parent=i.id and i.item_type = %d and i.item_deleted = 0 and i.uid= %d ", + intval(ITEM_TYPE_WEBPAGE), intval($channel_id) ); } else { - $r = q("select count(id) as total from item where parent = id and item_restrict = 0 and (item_flags & %d) > 0 and uid = %d ", - intval(ITEM_WALL), + $r = q("select count(id) as total from item where parent = id and item_wall = 1 and uid = %d " . item_normal(), intval($channel_id) ); } diff --git a/mod/layouts.php b/mod/layouts.php index 689a31c8c..fd77cfc37 100644 --- a/mod/layouts.php +++ b/mod/layouts.php @@ -99,7 +99,7 @@ function layouts_content(&$a) { dbesc(argv(3)) ); if($r) { - header('Content-type: application/x-redmatrix-layout'); + header('Content-type: application/x-hubzilla-layout'); header('Content-disposition: attachment; filename="' . $r[0]['sid'] . '.pdl"'); echo json_encode($r); killme(); @@ -111,7 +111,7 @@ function layouts_content(&$a) { // This lets you post pages at other people's channels. $x = array( - 'webpage' => ITEM_PDL, + 'webpage' => ITEM_TYPE_PDL, 'is_owner' => true, 'nickname' => $a->profile['channel_address'], 'bang' => '', @@ -134,10 +134,10 @@ function layouts_content(&$a) { $editor = status_editor($a,$x); - $r = q("select iid, sid, mid, title, body, mimetype, created, edited from item_id left join item on item_id.iid = item.id - where item_id.uid = %d and service = 'PDL' and item_restrict = %d order by item.created desc", + $r = q("select iid, sid, mid, title, body, mimetype, created, edited, item_type from item_id left join item on item_id.iid = item.id + where item_id.uid = %d and service = 'PDL' and item_type = %d order by item.created desc", intval($owner), - intval(ITEM_PDL) + intval(ITEM_TYPE_PDL) ); $pages = null; diff --git a/mod/like.php b/mod/like.php index 63524823b..ce8bc3063 100755 --- a/mod/like.php +++ b/mod/like.php @@ -117,8 +117,7 @@ function like_content(&$a) { } elseif($obj_type == 'thing') { - $r = q("select * from obj left join term on obj_obj = term_hash where term_hash != '' - and obj_type = %d and term_hash = '%s' limit 1", + $r = q("select * from obj where obj_type = %d and obj_obj = '%s' limit 1", intval(TERM_OBJ_THING), dbesc(argv(2)) ); @@ -146,18 +145,18 @@ function like_content(&$a) { $links = array(); $links[] = array('rel' => 'alternate', 'type' => 'text/html', - 'href' => z_root() . '/thing/' . $r[0]['term_hash']); + 'href' => z_root() . '/thing/' . $r[0]['obj_obj']); if($r[0]['imgurl']) - $links[] = array('rel' => 'photo', 'href' => $r[0]['imgurl']); + $links[] = array('rel' => 'photo', 'href' => $r[0]['obj_imgurl']); $target = json_encode(array( 'type' => $tgttype, - 'title' => $r[0]['term'], - 'id' => z_root() . '/thing/' . $r[0]['term_hash'], + 'title' => $r[0]['obj_term'], + 'id' => z_root() . '/thing/' . $r[0]['obj_obj'], 'link' => $links )); - $plink = '[zrl=' . z_root() . '/thing/' . $r[0]['term_hash'] . ']' . $r[0]['term'] . '[/zrl]'; + $plink = '[zrl=' . z_root() . '/thing/' . $r[0]['obj_obj'] . ']' . $r[0]['obj_term'] . '[/zrl]'; } @@ -226,10 +225,17 @@ function like_content(&$a) { q("delete from likes where id = %d limit 1", intval($z[0]['id']) ); - drop_item($z[0]['iid'],false); - if($interactive) { - notice( t('Previous action reversed.') . EOL); - return $o; + if($z[0]['i_mid']) { + $r = q("select id from item where mid = '%s' and uid = %d limit 1", + dbesc($z[0]['i_mid']), + intval($ch[0]['channel_id']) + ); + if($r) + drop_item($r[0]['id'],false); + if($interactive) { + notice( t('Previous action reversed.') . EOL); + return $o; + } } killme(); } @@ -244,9 +250,10 @@ function like_content(&$a) { // get the item. Allow linked photos (which are normally hidden) to be liked - $r = q("SELECT * FROM item WHERE id = %d and (item_restrict = 0 or item_restrict = %d) LIMIT 1", - intval($item_id), - intval(ITEM_HIDDEN) + $r = q("SELECT * FROM item WHERE id = %d + and item_type = 0 and item_deleted = 0 and item_unpublished = 0 + and item_delayed = 0 and item_pending_remove = 0 and item_blocked = 0 LIMIT 1", + intval($item_id) ); if(! $item_id || (! $r)) { @@ -306,7 +313,9 @@ function like_content(&$a) { $multi_undo = 1; } - $r = q("SELECT id, parent, uid, verb FROM item WHERE verb in ( $verbs ) AND item_restrict = 0 + $item_normal = item_normal(); + + $r = q("SELECT id, parent, uid, verb FROM item WHERE verb in ( $verbs ) $item_normal AND author_xchan = '%s' AND ( parent = %d OR thr_parent = '%s') and uid = %d ", dbesc($observer['xchan_hash']), intval($item_id), @@ -341,9 +350,12 @@ function like_content(&$a) { $mid = item_message_id(); - if($extended_like) { - $item_flags = ITEM_THREAD_TOP|ITEM_ORIGIN|ITEM_WALL; + $arr = array(); + if($extended_like) { + $arr['item_thread_top'] = 1; + $arr['item_origin'] = 1; + $arr['item_wall'] = 1; } else { $post_type = (($item['resource_type'] === 'photo') ? t('photo') : t('status')); @@ -375,18 +387,19 @@ function like_content(&$a) { ), )); - if(! ($item['item_flags'] & ITEM_THREAD_TOP)) + if(! intval($item['item_thread_top'])) $post_type = 'comment'; - $item_flags = ITEM_ORIGIN | ITEM_NOTSHOWN; - if($item['item_flags'] & ITEM_WALL) - $item_flags |= ITEM_WALL; + $arr['item_origin'] = 1; + $arr['item_notshown'] = 1; + + if(intval($item['item_wall'])) + $arr['item_wall'] = 1; // if this was a linked photo and was hidden, unhide it. - if($item['item_restrict'] & ITEM_HIDDEN) { - $r = q("update item set item_restrict = (item_restrict ^ %d) where id = %d", - intval(ITEM_HIDDEN), + if(intval($item['item_hidden'])) { + $r = q("update item set item_hidden = 0 where id = %d", intval($item['id']) ); } @@ -414,7 +427,6 @@ function like_content(&$a) { killme(); - $arr = array(); if($extended_like) { $ulink = '[zrl=' . $ch[0]['xchan_url'] . ']' . $ch[0]['xchan_name'] . '[/zrl]'; @@ -440,6 +452,7 @@ function like_content(&$a) { $arr['aid'] = (($extended_like) ? $ch[0]['channel_account_id'] : $owner_aid); $arr['uid'] = $owner_uid; $arr['item_flags'] = $item_flags; + $arr['item_wall'] = $item_wall; $arr['parent_mid'] = (($extended_like) ? $mid : $item['mid']); $arr['owner_xchan'] = (($extended_like) ? $ch[0]['xchan_hash'] : $thread_owner['xchan_hash']); $arr['author_xchan'] = $observer['xchan_hash']; @@ -483,9 +496,9 @@ function like_content(&$a) { intval($post_id), dbesc($mid), dbesc($activity), - dbesc(($tgttype)?$tgttype:$objtype), + dbesc(($tgttype)? $tgttype : $objtype), dbesc($obj_id), - dbesc(json_encode(($target)?$target:$object)) + dbesc(($target) ? $target : $object) ); $r = q("select * from likes where liker = '%s' and likee = '%s' and i_mid = '%s' and verb = '%s' and target_type = '%s' and target_id = '%s' ", dbesc($observer['xchan_hash']), diff --git a/mod/parse_url.php b/mod/linkinfo.php index 2a6f7663e..c3df1305d 100644 --- a/mod/parse_url.php +++ b/mod/linkinfo.php @@ -1,29 +1,180 @@ <?php -require_once('include/oembed.php'); - -/* To-Do -https://developers.google.com/+/plugins/snippet/ - -<meta itemprop="name" content="Toller Titel"> -<meta itemprop="description" content="Eine tolle Beschreibung"> -<meta itemprop="image" content="http://maple.libertreeproject.org/images/tree-icon.png"> - -<body itemscope itemtype="http://schema.org/Product"> - <h1 itemprop="name">Shiny Trinket</h1> - <img itemprop="image" src="{image-url}" /> - <p itemprop="description">Shiny trinkets are shiny.</p> -</body> -*/ - -if(!function_exists('deletenode')) { - function deletenode(&$doc, $node) - { - $xpath = new DomXPath($doc); - $list = $xpath->query("//".$node); - foreach ($list as $child) - $child->parentNode->removeChild($child); + +function arr_add_hashes(&$item,$k) { + $item = '#' . $item; +} + + + +function linkinfo_content(&$a) { + + logger('linkinfo: ' . print_r($_REQUEST,true)); + + $text = null; + $str_tags = ''; + + + $br = "\n"; + + if(x($_GET,'binurl')) + $url = trim(hex2bin($_GET['binurl'])); + else + $url = trim($_GET['url']); + + if((substr($url,0,1) != '/') && (substr($url,0,4) != 'http')) + $url = 'http://' . $url; + + + if($_GET['title']) + $title = strip_tags(trim($_GET['title'])); + + if($_GET['description']) + $text = strip_tags(trim($_GET['description'])); + + if($_GET['tags']) { + $arr_tags = str_getcsv($_GET['tags']); + if(count($arr_tags)) { + array_walk($arr_tags,'arr_add_hashes'); + $str_tags = $br . implode(' ',$arr_tags) . $br; + } + } + + logger('linkinfo: ' . $url); + + $result = z_fetch_url($url,false,0,array('novalidate' => true, 'nobody' => true)); + if($result['success']) { + $hdrs=array(); + $h = explode("\n",$result['header']); + foreach ($h as $l) { + list($k,$v) = array_map("trim", explode(":", trim($l), 2)); + $hdrs[$k] = $v; + } + if (array_key_exists('Content-Type', $hdrs)) + $type = $hdrs['Content-Type']; + if($type) { + $zrl = is_matrix_url($url); + if(stripos($type,'image/') !== false) { + if($zrl) + echo $br . '[zmg]' . $url . '[/zmg]' . $br; + else + echo $br . '[img]' . $url . '[/img]' . $br; + killme(); + } + if(stripos($type,'video/') !== false) { + if($zrl) + echo $br . '[zvideo]' . $url . '[/zvideo]' . $br; + else + echo $br . '[video]' . $url . '[/video]' . $br; + killme(); + } + if(stripos($type,'audio/') !== false) { + if($zrl) + echo $br . '[zaudio]' . $url . '[/zaudio]' . $br; + else + echo $br . '[audio]' . $url . '[/audio]' . $br; + killme(); + } + } } + + $template = $br . '#^[url=%s]%s[/url]%s' . $br; + + $arr = array('url' => $url, 'text' => ''); + + call_hooks('parse_link', $arr); + + if(strlen($arr['text'])) { + echo $arr['text']; + killme(); + } + + $x = oembed_process($url); + if($x) { + echo $x; + killme(); + } + + if($url && $title && $text) { + + $text = $br . '[quote]' . trim($text) . '[/quote]' . $br; + + $title = str_replace(array("\r","\n"),array('',''),$title); + + $result = sprintf($template,$url,($title) ? $title : $url,$text) . $str_tags; + + logger('linkinfo (unparsed): returns: ' . $result); + + echo $result; + killme(); + } + + $siteinfo = parseurl_getsiteinfo($url); + + // If this is a Red site, use zrl rather than url so they get zids sent to them by default + + if( x($siteinfo,'generator') && (strpos($siteinfo['generator'],PLATFORM_NAME . ' ') === 0)) + $template = str_replace('url','zrl',$template); + + if($siteinfo["title"] == "") { + echo sprintf($template,$url,$url,'') . $str_tags; + killme(); + } else { + $text = $siteinfo["text"]; + $title = $siteinfo["title"]; + } + + $image = ""; + + if(sizeof($siteinfo["images"]) > 0){ + /* Execute below code only if image is present in siteinfo */ + + $total_images = 0; + $max_images = get_config('system','max_bookmark_images'); + if($max_images === false) + $max_images = 2; + else + $max_images = intval($max_images); + + foreach ($siteinfo["images"] as $imagedata) { + if ($url) { + $image .= sprintf('[url=%s]', $url); + } + $image .= '[img='.$imagedata["width"].'x'.$imagedata["height"].']'.$imagedata["src"].'[/img]'; + if ($url) { + $image .= '[/url]'; + } + $image .= "\n"; + $total_images ++; + if($max_images && $max_images >= $total_images) + break; + } + } + + if(strlen($text)) { + $text = $br.'[quote]'.trim($text).'[/quote]'.$br ; + } + + if($image) { + $text = $br.$br.$image.$text; + } + $title = str_replace(array("\r","\n"),array('',''),$title); + + $result = sprintf($template,$url,($title) ? $title : $url,$text) . $str_tags; + + logger('linkinfo: returns: ' . $result, LOGGER_DEBUG); + + echo trim($result); + killme(); + +} + + +function deletexnode(&$doc, $node) { + $xpath = new DomXPath($doc); + $list = $xpath->query("//".$node); + foreach ($list as $child) + $child->parentNode->removeChild($child); } function completeurl($url, $scheme) { @@ -53,6 +204,7 @@ function completeurl($url, $scheme) { return($complete); } + function parseurl_getsiteinfo($url) { $siteinfo = array(); @@ -70,17 +222,17 @@ function parseurl_getsiteinfo($url) { $doc = new DOMDocument(); @$doc->loadHTML($body); - deletenode($doc, 'style'); - deletenode($doc, 'script'); - deletenode($doc, 'option'); - deletenode($doc, 'h1'); - deletenode($doc, 'h2'); - deletenode($doc, 'h3'); - deletenode($doc, 'h4'); - deletenode($doc, 'h5'); - deletenode($doc, 'h6'); - deletenode($doc, 'ol'); - deletenode($doc, 'ul'); + deletexnode($doc, 'style'); + deletexnode($doc, 'script'); + deletexnode($doc, 'option'); + deletexnode($doc, 'h1'); + deletexnode($doc, 'h2'); + deletexnode($doc, 'h3'); + deletexnode($doc, 'h4'); + deletexnode($doc, 'h5'); + deletexnode($doc, 'h6'); + deletexnode($doc, 'ol'); + deletexnode($doc, 'ul'); $xpath = new DomXPath($doc); @@ -215,167 +367,3 @@ function parseurl_getsiteinfo($url) { return($siteinfo); } - -function arr_add_hashes(&$item,$k) { - $item = '#' . $item; -} - -function parse_url_content(&$a) { - - $text = null; - $str_tags = ''; - - - $br = "\n"; - - if(x($_GET,'binurl')) - $url = trim(hex2bin($_GET['binurl'])); - else - $url = trim($_GET['url']); - - if((substr($url,0,1) != '/') && (substr($url,0,4) != 'http')) - $url = 'http://' . $url; - - - if($_GET['title']) - $title = strip_tags(trim($_GET['title'])); - - if($_GET['description']) - $text = strip_tags(trim($_GET['description'])); - - if($_GET['tags']) { - $arr_tags = str_getcsv($_GET['tags']); - if(count($arr_tags)) { - array_walk($arr_tags,'arr_add_hashes'); - $str_tags = $br . implode(' ',$arr_tags) . $br; - } - } - - logger('parse_url: ' . $url); - - $result = z_fetch_url($url,false,0,array('novalidate' => true, 'nobody' => true)); - if($result['success']) { - $hdrs=array(); - $h = explode("\n",$result['header']); - foreach ($h as $l) { - list($k,$v) = array_map("trim", explode(":", trim($l), 2)); - $hdrs[$k] = $v; - } - if (array_key_exists('Content-Type', $hdrs)) - $type = $hdrs['Content-Type']; - if($type) { - $zrl = is_matrix_url($url); - if(stripos($type,'image/') !== false) { - if($zrl) - echo $br . '[zmg]' . $url . '[/zmg]' . $br; - else - echo $br . '[img]' . $url . '[/img]' . $br; - killme(); - } - if(stripos($type,'video/') !== false) { - if($zrl) - echo $br . '[zvideo]' . $url . '[/zvideo]' . $br; - else - echo $br . '[video]' . $url . '[/video]' . $br; - killme(); - } - if(stripos($type,'audio/') !== false) { - if($zrl) - echo $br . '[zaudio]' . $url . '[/zaudio]' . $br; - else - echo $br . '[audio]' . $url . '[/audio]' . $br; - killme(); - } - } - } - - $template = $br . '#^[url=%s]%s[/url]%s' . $br; - - $arr = array('url' => $url, 'text' => ''); - - call_hooks('parse_link', $arr); - - if(strlen($arr['text'])) { - echo $arr['text']; - killme(); - } - - $x = oembed_process($url); - if($x) { - echo $x; - killme(); - } - - if($url && $title && $text) { - - - $text = $br . '[quote]' . trim($text) . '[/quote]' . $br; - - $title = str_replace(array("\r","\n"),array('',''),$title); - - $result = sprintf($template,$url,($title) ? $title : $url,$text) . $str_tags; - - logger('parse_url (unparsed): returns: ' . $result); - - echo $result; - killme(); - } - - $siteinfo = parseurl_getsiteinfo($url); - - // If this is a Red site, use zrl rather than url so they get zids sent to them by default - - if( x($siteinfo,'generator') && (strpos($siteinfo['generator'],PLATFORM_NAME . ' ') === 0)) - $template = str_replace('url','zrl',$template); - - if($siteinfo["title"] == "") { - echo sprintf($template,$url,$url,'') . $str_tags; - killme(); - } else { - $text = $siteinfo["text"]; - $title = $siteinfo["title"]; - } - - $image = ""; - - if(sizeof($siteinfo["images"]) > 0){ - /* Execute below code only if image is present in siteinfo */ - - $total_images = 0; - $max_images = get_config('system','max_bookmark_images'); - if($max_images === false) - $max_images = 2; - else - $max_images = intval($max_images); - - foreach ($siteinfo["images"] as $imagedata) { - if ($url) { - $image .= sprintf('[url=%s]', $url); - } - $image .= '[img='.$imagedata["width"].'x'.$imagedata["height"].']'.$imagedata["src"].'[/img]'; - if ($url) { - $image .= '[/url]'; - } - $image .= "\n"; - $total_images ++; - if($max_images && $max_images >= $total_images) - break; - } - } - - if(strlen($text)) { - $text = $br.'[quote]'.trim($text).'[/quote]'.$br ; - } - - if($image) { - $text = $br.$br.$image.$text; - } - $title = str_replace(array("\r","\n"),array('',''),$title); - - $result = sprintf($template,$url,($title) ? $title : $url,$text) . $str_tags; - - logger('parse_url: returns: ' . $result, LOGGER_DEBUG); - - echo trim($result); - killme(); -} diff --git a/mod/locs.php b/mod/locs.php index 5b04bb343..3c6a5da67 100644 --- a/mod/locs.php +++ b/mod/locs.php @@ -22,13 +22,10 @@ function locs_post(&$a) { return; } - $r = q("update hubloc set hubloc_flags = (hubloc_flags - %d) where (hubloc_flags & %d)>0 and hubloc_hash = '%s' ", - intval(HUBLOC_FLAGS_PRIMARY), - intval(HUBLOC_FLAGS_PRIMARY), + $r = q("update hubloc set hubloc_primary = 0 where hubloc_primary = 1 and hubloc_hash = '%s' ", dbesc($channel['channel_hash']) ); - $r = q("update hubloc set hubloc_flags = (hubloc_flags | %d) where hubloc_id = %d and hubloc_hash = '%s'", - intval(HUBLOC_FLAGS_PRIMARY), + $r = q("update hubloc set hubloc_primary = 1 where hubloc_id = %d and hubloc_hash = '%s'", intval($hubloc_id), dbesc($channel['channel_hash']) ); @@ -42,7 +39,7 @@ function locs_post(&$a) { $hubloc_id = intval($_REQUEST['drop']); if($hubloc_id) { - $r = q("select hubloc_id, hubloc_flags from hubloc where hubloc_id = %d and hubloc_url != '%s' and hubloc_hash = '%s' limit 1", + $r = q("select * from hubloc where hubloc_id = %d and hubloc_url != '%s' and hubloc_hash = '%s' limit 1", intval($hubloc_id), dbesc(z_root()), dbesc($channel['channel_hash']) @@ -52,12 +49,21 @@ function locs_post(&$a) { notice( t('Location not found.') . EOL); return; } - if($r[0]['hubloc_flags'] & HUBLOC_FLAGS_PRIMARY) { - notice( t('Primary location cannot be removed.') . EOL); - return; + if(intval($r[0]['hubloc_primary'])) { + $x = q("select hubloc_id from hubloc where hubloc_primary = 1 and hubloc_hash = '%s'", + dbesc($channel['channel_hash']) + ); + if(! $x) { + notice( t('Location lookup failed.')); + return; + } + if(count($x) == 1) { + notice( t('Please select another location to become primary before removing the primary location.') . EOL); + return; + } } - $r = q("update hubloc set hubloc_flags = (hubloc_flags | %d) where hubloc_id = %d and hubloc_hash = '%s'", - intval(HUBLOC_FLAGS_DELETED), + + $r = q("update hubloc set hubloc_deleted = 1 where hubloc_id = %d and hubloc_hash = '%s'", intval($hubloc_id), dbesc($channel['channel_hash']) ); @@ -72,7 +78,6 @@ function locs_post(&$a) { function locs_content(&$a) { - if(! local_channel()) { notice( t('Permission denied.') . EOL); return; @@ -91,12 +96,10 @@ function locs_content(&$a) { for($x = 0; $x < count($r); $x ++) { - $r[$x]['primary'] = (($r[$x]['hubloc_flags'] & HUBLOC_FLAGS_PRIMARY) ? true : false); - $r[$x]['deleted'] = (($r[$x]['hubloc_flags'] & HUBLOC_FLAGS_DELETED) ? true : false); + $r[$x]['primary'] = (intval($r[$x]['hubloc_primary']) ? true : false); + $r[$x]['deleted'] = (intval($r[$x]['hubloc_deleted']) ? true : false); } - - $o = replace_macros(get_markup_template('locmanage.tpl'), array( '$header' => t('Manage Channel Locations'), '$loc' => t('Location (address)'), diff --git a/mod/mail.php b/mod/mail.php index 1b0ea17c4..80d7f477d 100644 --- a/mod/mail.php +++ b/mod/mail.php @@ -125,8 +125,7 @@ function mail_content(&$a) { $tpl = get_markup_template('mail_head.tpl'); $header = replace_macros($tpl, array( - '$messages' => t('Messages'), - '$tab_content' => $tab_content + '$header' => t('Messages'), )); if((argc() == 3) && (argv(1) === 'drop')) { @@ -145,8 +144,7 @@ function mail_content(&$a) { if(! intval(argv(2))) return; $cmd = argv(1); - $r = q("update mail set mail_flags = mail_flags | %d where id = %d and channel_id = %d", - intval(MAIL_RECALLED), + $r = q("update mail set mail_recalled = 1 where id = %d and channel_id = %d", intval(argv(2)), intval(local_channel()) ); @@ -161,8 +159,6 @@ function mail_content(&$a) { if((argc() > 1) && (argv(1) === 'new')) { - $o .= $header; - $plaintext = true; $tpl = get_markup_template('msg-header.tpl'); @@ -312,7 +308,7 @@ function mail_content(&$a) { 'delete' => t('Delete message'), 'recall' => t('Recall message'), 'can_recall' => (($channel['channel_hash'] == $message['from_xchan']) ? true : false), - 'is_recalled' => (($message['mail_flags'] & MAIL_RECALLED) ? t('Message has been recalled.') : ''), + 'is_recalled' => (intval($message['mail_recalled']) ? t('Message has been recalled.') : ''), 'date' => datetime_convert('UTC',date_default_timezone_get(),$message['created'],'D, d M Y - g:i A'), ); diff --git a/mod/manage.php b/mod/manage.php index 3712be6f1..b609ede44 100644 --- a/mod/manage.php +++ b/mod/manage.php @@ -41,9 +41,8 @@ function manage_content(&$a) { $channels = null; if(local_channel()) { - $r = q("select channel.*, xchan.* from channel left join xchan on channel.channel_hash = xchan.xchan_hash where channel.channel_account_id = %d and not ( channel_pageflags & %d )>0 order by channel_name ", - intval(get_account_id()), - intval(PAGE_REMOVED) + $r = q("select channel.*, xchan.* from channel left join xchan on channel.channel_hash = xchan.xchan_hash where channel.channel_account_id = %d and channel_removed = 0 order by channel_name ", + intval(get_account_id()) ); $account = get_app()->get_account(); @@ -56,14 +55,14 @@ function manage_content(&$a) { $channels[$x]['default_links'] = '1'; - $c = q("SELECT id, item_restrict, item_flags FROM item - WHERE item_restrict = 0 and item_unseen = 1 and uid = %d", + $c = q("SELECT id, item_wall FROM item + WHERE item_unseen = 1 and uid = %d " . item_normal(), intval($channels[$x]['channel_id']) ); if($c) { foreach ($c as $it) { - if($it['item_flags'] & ITEM_WALL) + if(intval($it['item_wall'])) $channels[$x]['home'] ++; else $channels[$x]['network'] ++; @@ -71,20 +70,16 @@ function manage_content(&$a) { } - $intr = q("SELECT COUNT(abook.abook_id) AS total FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash where abook_channel = %d and (abook_flags & %d)>0 and not ((abook_flags & %d)>0 or (xchan_flags & %d)>0)", - intval($channels[$x]['channel_id']), - intval(ABOOK_FLAG_PENDING), - intval(ABOOK_FLAG_SELF|ABOOK_FLAG_IGNORED), - intval(XCHAN_FLAGS_DELETED|XCHAN_FLAGS_ORPHAN) + $intr = q("SELECT COUNT(abook.abook_id) AS total FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash where abook_channel = %d and abook_pending = 1 and abook_self = 0 and abook_ignored = 0 and xchan_deleted = 0 and xchan_orphan = 0 ", + intval($channels[$x]['channel_id']) ); if($intr) $channels[$x]['intros'] = intval($intr[0]['total']); - $mails = q("SELECT count(id) as total from mail WHERE channel_id = %d AND not (mail_flags & %d)>0 and from_xchan != '%s' ", + $mails = q("SELECT count(id) as total from mail WHERE channel_id = %d AND mail_seen = 0 and from_xchan != '%s' ", intval($channels[$x]['channel_id']), - intval(MAIL_SEEN), dbesc($channels[$x]['channel_hash']) ); @@ -127,9 +122,8 @@ function manage_content(&$a) { } } - $r = q("select count(channel_id) as total from channel where channel_account_id = %d and not ( channel_pageflags & %d )>0", - intval(get_account_id()), - intval(PAGE_REMOVED) + $r = q("select count(channel_id) as total from channel where channel_account_id = %d and channel_removed = 0", + intval(get_account_id()) ); $limit = account_service_class_fetch(get_account_id(),'total_identities'); if($limit !== false) { diff --git a/mod/menu.php b/mod/menu.php index ad47ad1fd..bfc45adef 100644 --- a/mod/menu.php +++ b/mod/menu.php @@ -48,7 +48,7 @@ function menu_post(&$a) { $r = menu_create($_REQUEST); if($r) { menu_sync_packet($uid,get_observer_hash(),$r); - + //info( t('Menu created.') . EOL); goaway(z_root() . '/mitem/' . $r . (($a->is_sys) ? '?f=&sys=1' : '')); } @@ -59,6 +59,8 @@ function menu_post(&$a) { } + + function menu_content(&$a) { $uid = local_channel(); diff --git a/mod/message.php b/mod/message.php index 4a1ff26d1..9f62f6b61 100644 --- a/mod/message.php +++ b/mod/message.php @@ -26,11 +26,6 @@ function message_content(&$a) { - $tpl = get_markup_template('mail_head.tpl'); - $header = replace_macros($tpl, array( - '$messages' => t('Messages'), - '$tab_content' => $tab_content - )); if((argc() == 3) && (argv(1) === 'dropconv')) { if(! intval(argv(2))) @@ -43,13 +38,9 @@ function message_content(&$a) { } if(argc() == 1) { - // list messages - - $o .= $header; // private_messages_list() can do other more complicated stuff, for now keep it simple - $r = private_messages_list(local_channel(), '', $a->pager['start'], $a->pager['itemspage']); if(! $r) { @@ -57,24 +48,33 @@ function message_content(&$a) { return $o; } - $tpl = get_markup_template('mail_list.tpl'); + $messages = array(); + foreach($r as $rr) { - - $o .= replace_macros($tpl, array( - '$id' => $rr['id'], - '$from_name' => $rr['from']['xchan_name'], - '$from_url' => chanlink_hash($rr['from_xchan']), - '$from_photo' => $rr['from']['xchan_photo_s'], - '$to_name' => $rr['to']['xchan_name'], - '$to_url' => chanlink_hash($rr['to_xchan']), - '$to_photo' => $rr['to']['xchan_photo_s'], - '$subject' => (($rr['seen']) ? $rr['title'] : '<strong>' . $rr['title'] . '</strong>'), - '$delete' => t('Delete conversation'), - '$body' => smilies(bbcode($rr['body'])), - '$date' => datetime_convert('UTC',date_default_timezone_get(),$rr['created'], t('D, d M Y - g:i A')), - '$seen' => $rr['seen'] - )); + $messages[] = array( + 'id' => $rr['id'], + 'from_name' => $rr['from']['xchan_name'], + 'from_url' => chanlink_hash($rr['from_xchan']), + 'from_photo' => $rr['from']['xchan_photo_s'], + 'to_name' => $rr['to']['xchan_name'], + 'to_url' => chanlink_hash($rr['to_xchan']), + 'to_photo' => $rr['to']['xchan_photo_s'], + 'subject' => (($rr['seen']) ? $rr['title'] : '<strong>' . $rr['title'] . '</strong>'), + 'delete' => t('Delete conversation'), + 'body' => smilies(bbcode($rr['body'])), + 'date' => datetime_convert('UTC',date_default_timezone_get(),$rr['created'], t('D, d M Y - g:i A')), + 'seen' => $rr['seen'] + ); } + + + $tpl = get_markup_template('mail_head.tpl'); + $o = replace_macros($tpl, array( + '$header' => t('Messages'), + '$messages' => $messages + )); + + $o .= alt_pager($a,count($r)); return $o; } diff --git a/mod/mitem.php b/mod/mitem.php index 60d7885dc..d6572bd56 100644 --- a/mod/mitem.php +++ b/mod/mitem.php @@ -127,12 +127,7 @@ function mitem_content(&$a) { $menu_names[] = $menus['menu_name']; } - $perm_defaults = array( - 'allow_cid' => $channel['channel_allow_cid'], - 'allow_gid' => $channel['channel_allow_gid'], - 'deny_cid' => $channel['channel_deny_cid'], - 'deny_gid' => $channel['channel_deny_gid'] - ); + $acl = new AccessList($channel); $lockstate = (($channel['channel_allow_cid'] || $channel['channel_allow_gid'] || $channel['channel_deny_cid'] || $channel['channel_deny_gid']) ? 'lock' : 'unlock'); @@ -153,7 +148,7 @@ function mitem_content(&$a) { '$menu_id' => $a->data['menu']['menu_id'], '$permissions' => t('Menu Item Permissions'), '$permdesc' => t("\x28click to open/close\x29"), - '$aclselect' => populate_acl($perm_defaults,false), + '$aclselect' => populate_acl($acl->get(),false), '$mitem_desc' => array('mitem_desc', t('Link Name'), '', 'Visible name of the link','*'), '$mitem_link' => array('mitem_link', t('Link or Submenu Target'), '', t('Enter URL of the link or select a menu name to create a submenu'), '*', 'list="menu-names"'), '$usezid' => array('usezid', t('Use magic-auth if available'), true, '', array(t('No'), t('Yes'))), @@ -211,6 +206,7 @@ function mitem_content(&$a) { if(argc() == 4 && argv(3) == 'drop') { menu_sync_packet($uid,get_observer_hash(),$mitem['mitem_menu_id']); $r = menu_del_item($mitem['mitem_menu_id'], $uid, intval(argv(2))); + menu_sync_packet($uid,get_observer_hash(),$mitem['mitem_menu_id']); if($r) info( t('Menu item deleted.') . EOL); else diff --git a/mod/mood.php b/mod/mood.php index 7663b2632..92a4f391b 100755 --- a/mod/mood.php +++ b/mod/mood.php @@ -61,9 +61,6 @@ function mood_init(&$a) { $mid = item_message_id(); $action = sprintf( t('%1$s is %2$s','mood'), '[zrl=' . $poster['xchan_url'] . ']' . $poster['xchan_name'] . '[/zrl]' , $verbs[$verb]); - $item_flags = ITEM_WALL|ITEM_ORIGIN; - if(! $parent_mid) - $item_flags |= ITEM_THREAD_TOP; $arr = array(); @@ -71,7 +68,6 @@ function mood_init(&$a) { $arr['uid'] = $uid; $arr['mid'] = $mid; $arr['parent_mid'] = (($parent_mid) ? $parent_mid : $mid); - $arr['item_flags'] = $item_flags; $arr['author_xchan'] = $poster['xchan_hash']; $arr['owner_xchan'] = (($parent_mid) ? $r[0]['owner_xchan'] : $poster['xchan_hash']); $arr['title'] = ''; @@ -82,8 +78,13 @@ function mood_init(&$a) { $arr['item_private'] = $private; $arr['verb'] = $activity; $arr['body'] = $action; + $arr['item_origin'] = 1; + $arr['item_wall'] = 1; + $arr['item_unseen'] = 1; + if(! $parent_mid) + $item['item_thread_top'] = 1; - if ((! $arr['plink']) && ($arr['item_flags'] & ITEM_THREAD_TOP)) { + if ((! $arr['plink']) && intval($arr['item_thread_top'])) { $arr['plink'] = z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . $arr['mid']; } diff --git a/mod/network.php b/mod/network.php index e8630278a..53de975a4 100644 --- a/mod/network.php +++ b/mod/network.php @@ -40,7 +40,7 @@ function network_content(&$a, $update = 0, $load = false) { call_hooks('network_content_init', $arr); $channel = $a->get_channel(); - + $item_normal = item_normal(); $datequery = $datequery2 = ''; @@ -115,6 +115,8 @@ function network_content(&$a, $update = 0, $load = false) { $file = ((x($_GET,'file')) ? $_GET['file'] : ''); + $deftag = ''; + if(x($_GET,'search') || x($_GET,'file')) $nouveau = true; if($cid) { @@ -130,7 +132,10 @@ function network_content(&$a, $update = 0, $load = false) { goaway($a->get_baseurl(true) . '/network'); // NOTREACHED } - $def_acl = array('allow_cid' => '<' . $r[0]['abook_xchan'] . '>'); + if($_GET['pf'] === '1') + $deftag = '@' . t('forum') . '+' . intval($cid) . '+'; + else + $def_acl = array('allow_cid' => '<' . $r[0]['abook_xchan'] . '>'); } if(! $update) { @@ -153,17 +158,21 @@ function network_content(&$a, $update = 0, $load = false) { 'deny_gid' => $channel['channel_deny_gid'] ); + $private_editing = ((($group || $cid) && (! intval($_GET['pf']))) ? true : false); + $x = array( 'is_owner' => true, 'allow_location' => ((intval(get_pconfig($channel['channel_id'],'system','use_browser_location'))) ? '1' : ''), 'default_location' => $channel['channel_location'], 'nickname' => $channel['channel_address'], - 'lockstate' => (($group || $cid || $channel['channel_allow_cid'] || $channel['channel_allow_gid'] || $channel['channel_deny_cid'] || $channel['channel_deny_gid']) ? 'lock' : 'unlock'), - 'acl' => populate_acl((($group || $cid) ? $def_acl : $channel_acl)), - 'bang' => (($group || $cid) ? '!' : ''), + 'lockstate' => (($private_editing || $channel['channel_allow_cid'] || $channel['channel_allow_gid'] || $channel['channel_deny_cid'] || $channel['channel_deny_gid']) ? 'lock' : 'unlock'), + 'acl' => populate_acl((($private_editing) ? $def_acl : $channel_acl)), + 'bang' => (($private_editing) ? '!' : ''), 'visitor' => true, 'profile_uid' => local_channel() ); + if($deftag) + $x['pretext'] = $deftag; $status_editor = status_editor($a,$x); $o .= $status_editor; @@ -176,12 +185,12 @@ function network_content(&$a, $update = 0, $load = false) { $sql_options = (($star) - ? " and (item_flags & " . intval(ITEM_STARRED) . ") > 0" + ? " and item_starred = 1 " : ''); $sql_nets = ''; - $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE (item_flags & " . intval(ITEM_THREAD_TOP) . ")>0 $sql_options ) "; + $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE item_thread_top = 1 $sql_options ) "; if($group) { $contact_str = ''; @@ -198,7 +207,7 @@ function network_content(&$a, $update = 0, $load = false) { info( t('Collection is empty')); } - $sql_extra = " AND item.parent IN ( SELECT DISTINCT parent FROM item WHERE true $sql_options AND (( author_xchan IN ( $contact_str ) OR owner_xchan in ( $contact_str )) or allow_gid like '" . protect_sprintf('%<' . dbesc($group_hash) . '>%') . "' ) and id = parent and item_restrict = 0 ) "; + $sql_extra = " AND item.parent IN ( SELECT DISTINCT parent FROM item WHERE true $sql_options AND (( author_xchan IN ( $contact_str ) OR owner_xchan in ( $contact_str )) or allow_gid like '" . protect_sprintf('%<' . dbesc($group_hash) . '>%') . "' ) and id = parent $item_normal ) "; $x = group_rec_byhash(local_channel(), $group_hash); @@ -216,14 +225,14 @@ function network_content(&$a, $update = 0, $load = false) { elseif($cid) { - $r = q("SELECT abook.*, xchan.* from abook left join xchan on abook_xchan = xchan_hash where abook_id = %d and abook_channel = %d and not ( abook_flags & " . intval(ABOOK_FLAG_BLOCKED) . ") > 0 limit 1", + $r = q("SELECT abook.*, xchan.* from abook left join xchan on abook_xchan = xchan_hash where abook_id = %d and abook_channel = %d and abook_blocked = 0 limit 1", intval($cid), intval(local_channel()) ); if($r) { - $sql_extra = " AND item.parent IN ( SELECT DISTINCT parent FROM item WHERE true $sql_options AND uid = " . intval(local_channel()) . " AND ( author_xchan = '" . dbesc($r[0]['abook_xchan']) . "' or owner_xchan = '" . dbesc($r[0]['abook_xchan']) . "' ) and item_restrict = 0 ) "; + $sql_extra = " AND item.parent IN ( SELECT DISTINCT parent FROM item WHERE true $sql_options AND uid = " . intval(local_channel()) . " AND ( author_xchan = '" . dbesc($r[0]['abook_xchan']) . "' or owner_xchan = '" . dbesc($r[0]['abook_xchan']) . "' ) $item_normal ) "; $title = replace_macros(get_markup_template("section_title.tpl"),array( - '$title' => t('Connection: ') . $r[0]['xchan_name'] + '$title' => '<a href="' . zid($r[0]['xchan_url']) . '" ><img src="' . zid($r[0]['xchan_photo_s']) . '" alt="' . urlencode($r[0]['xchan_name']) . '" /></a> <a href="' . zid($r[0]['xchan_url']) . '" >' . $r[0]['xchan_name'] . '</a>' )); $o = $tabs; $o .= $title; @@ -324,9 +333,8 @@ function network_content(&$a, $update = 0, $load = false) { } if($conv) { - $sql_extra .= sprintf(" AND parent IN (SELECT distinct(parent) from item where ( author_xchan like '%s' or ( item_flags & %d ) > 0) and item_restrict = 0 ) ", - dbesc(protect_sprintf($channel['channel_hash'])), - intval(ITEM_MENTIONSME) + $sql_extra .= sprintf(" AND parent IN (SELECT distinct(parent) from item where ( author_xchan like '%s' or item_mentionsme = 1 )) ", + dbesc(protect_sprintf($channel['channel_hash'])) ); } @@ -405,12 +413,11 @@ function network_content(&$a, $update = 0, $load = false) { $items = q("SELECT item.*, item.id AS item_id, received FROM item left join abook on ( item.owner_xchan = abook.abook_xchan $abook_uids ) - WHERE true $uids AND item_restrict = 0 - and ((abook.abook_flags & %d) = 0 or abook.abook_flags is null) + WHERE true $uids $item_normal + and (abook.abook_blocked = 0 or abook.abook_flags is null) $simple_update $sql_extra $sql_nets - ORDER BY item.received DESC $pager_sql ", - intval(ABOOK_FLAG_BLOCKED) + ORDER BY item.received DESC $pager_sql " ); require_once('include/items.php'); @@ -434,12 +441,11 @@ function network_content(&$a, $update = 0, $load = false) { $r = q("SELECT distinct item.id AS item_id, $ordering FROM item left join abook on ( item.owner_xchan = abook.abook_xchan $abook_uids ) - WHERE true $uids AND item.item_restrict = 0 + WHERE true $uids $item_normal AND item.parent = item.id - and ((abook.abook_flags & %d) = 0 or abook.abook_flags is null) + and (abook.abook_blocked = 0 or abook.abook_flags is null) $sql_extra3 $sql_extra $sql_nets - ORDER BY $ordering DESC $pager_sql ", - intval(ABOOK_FLAG_BLOCKED) + ORDER BY $ordering DESC $pager_sql " ); } @@ -447,10 +453,9 @@ function network_content(&$a, $update = 0, $load = false) { // this is an update $r = q("SELECT item.parent AS item_id FROM item left join abook on ( item.owner_xchan = abook.abook_xchan $abook_uids ) - WHERE true $uids AND item.item_restrict = 0 $simple_update - and ((abook.abook_flags & %d) = 0 or abook.abook_flags is null) - $sql_extra3 $sql_extra $sql_nets ", - intval(ABOOK_FLAG_BLOCKED) + WHERE true $uids $item_normal $simple_update + and (abook.abook_blocked = 0 or abook.abook_flags is null) + $sql_extra3 $sql_extra $sql_nets " ); $_SESSION['loadtime'] = datetime_convert(); } @@ -464,7 +469,7 @@ function network_content(&$a, $update = 0, $load = false) { $parents_str = ids_to_querystr($r,'item_id'); $items = q("SELECT item.*, item.id AS item_id FROM item - WHERE true $uids AND item.item_restrict = 0 + WHERE true $uids $item_normal AND item.parent IN ( %s ) $sql_extra ", dbesc($parents_str) @@ -500,7 +505,7 @@ function network_content(&$a, $update = 0, $load = false) { } if(($update_unseen) && (! $firehose)) - $r = q("UPDATE item SET item_unseen = 0 where item_unseen = 1 AND uid = %d $update_unseen ", + $r = q("UPDATE item SET item_unseen = 0 WHERE item_unseen = 1 AND uid = %d $update_unseen ", intval(local_channel()) ); diff --git a/mod/oexchange.php b/mod/oexchange.php index a684bd5d8..867cea6f2 100644 --- a/mod/oexchange.php +++ b/mod/oexchange.php @@ -47,7 +47,7 @@ function oexchange_content(&$a) { $tags = (((x($_REQUEST,'tags')) && strlen($_REQUEST['tags'])) ? '&tags=' . urlencode(notags(trim($_REQUEST['tags']))) : ''); - $ret = z_fetch_url($a->get_baseurl() . '/parse_url?f=&url=' . $url . $title . $description . $tags); + $ret = z_fetch_url($a->get_baseurl() . '/urlinfo?f=&url=' . $url . $title . $description . $tags); if($ret['success']) $s = $ret['body']; diff --git a/mod/openid.php b/mod/openid.php index 1af95a81c..b9ca672a9 100644 --- a/mod/openid.php +++ b/mod/openid.php @@ -131,8 +131,8 @@ function openid_content(&$a) { $x = q("insert into xchan ( xchan_hash, xchan_guid, xchan_guid_sig, xchan_pubkey, xchan_photo_mimetype, xchan_photo_l, xchan_addr, xchan_url, xchan_connurl, xchan_follow, xchan_connpage, xchan_name, xchan_network, xchan_photo_date, - xchan_name_date, xchan_flags) - values ( '%s', '%s', '%s', '%s' , '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d) ", + xchan_name_date, xchan_hidden) + values ( '%s', '%s', '%s', '%s' , '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', 1) ", dbesc($url), dbesc(''), dbesc(''), @@ -147,8 +147,7 @@ function openid_content(&$a) { dbesc($name), dbesc($network), dbesc(datetime_convert()), - dbesc(datetime_convert()), - intval(XCHAN_FLAGS_HIDDEN) + dbesc(datetime_convert()) ); if($x) { $r = q("select * from xchan where xchan_hash = '%s' limit 1", @@ -156,7 +155,7 @@ function openid_content(&$a) { ); if($r) { - $photos = import_profile_photo($pphoto,$url); + $photos = import_xchan_photo($pphoto,$url); if($photos) { $z = q("update xchan set xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s' where xchan_hash = '%s'", diff --git a/mod/p.php b/mod/p.php deleted file mode 100644 index 924fd7eba..000000000 --- a/mod/p.php +++ /dev/null @@ -1,52 +0,0 @@ -<?php /** @file */ - -require_once('include/bb2diaspora.php'); - -// used in Diaspora communications to provide a server copy of a sent post in XML format. - -function p_init(&$a) { - - if(argc() < 2) - http_status_exit(401); - - $mid = str_replace('.xml','',argv(1)); - - $r = q("select * from item where mid = '%s' and (item_flags & %d)>0 and item_private = 0 limit 1", - dbesc($mid), - intval(ITEM_WALL) - ); - - - if((! $r) || (! perm_is_allowed($r[0]['uid'],'','view_stream'))) - http_status_exit(404); - - - $c = q("select * from channel where channel_id = %d limit 1", - intval($r[0]['uid']) - ); - - if(! $c) - http_status_exit(404); - - $myaddr = $c[0]['channel_address'] . '@' . $a->get_hostname(); - - $item = $r[0]; - - $title = $item['title']; - $body = bb2diaspora_itembody($item); - $created = datetime_convert('UTC','UTC',$item['created'],'Y-m-d H:i:s \U\T\C'); - - $tpl = get_markup_template('diaspora_post.tpl'); - $msg = replace_macros($tpl, array( - '$body' => xmlify($body), - '$guid' => $item['mid'], - '$handle' => xmlify($myaddr), - '$public' => 'true', - '$created' => $created, - '$provider' => (($item['app']) ? $item['app'] : t('$projectname')) - )); - - header('Content-type: text/xml'); - echo $msg; - killme(); -}
\ No newline at end of file diff --git a/mod/page.php b/mod/page.php index 3cb63a2bc..b635a60f2 100644 --- a/mod/page.php +++ b/mod/page.php @@ -62,12 +62,12 @@ function page_init(&$a) { $sql_options = item_permissions_sql($u[0]['channel_id']); $r = q("select item.* from item left join item_id on item.id = item_id.iid - where item.uid = %d and sid = '%s' and (( service = 'WEBPAGE' and - item_restrict = %d ) or ( service = 'PDL' and item_restrict = %d )) $sql_options $revision limit 1", + where item.uid = %d and sid = '%s' and (( service = 'WEBPAGE' and item_type = %d ) + OR ( service = 'PDL' AND item_type = %d )) $sql_options $revision limit 1", intval($u[0]['channel_id']), dbesc($page_id), - intval(ITEM_WEBPAGE), - intval(ITEM_PDL) + intval(ITEM_TYPE_WEBPAGE), + intval(ITEM_TYPE_PDL) ); if(! $r) { @@ -75,10 +75,10 @@ function page_init(&$a) { $x = q("select item.* from item left join item_id on item.id = item_id.iid where item.uid = %d and sid = '%s' and service = 'WEBPAGE' and - item_restrict = %d $revision limit 1", + item_type = %d $revision limit 1", intval($u[0]['channel_id']), dbesc($page_id), - intval(ITEM_WEBPAGE) + intval(ITEM_TYPE_WEBPAGE) ); if($x) { @@ -91,7 +91,7 @@ function page_init(&$a) { return; } - if($r[0]['item_restrict'] == ITEM_PDL) { + if($r[0]['item_type'] == ITEM_TYPE_PDL) { require_once('include/comanche.php'); comanche_parser(get_app(),$r[0]['body']); get_app()->pdl = $r[0]['body']; @@ -122,8 +122,8 @@ function page_content(&$a) { if(! $r) return; - if($r[0]['item_restrict'] == ITEM_PDL) { - $r[0]['body'] = t('Lorem Ipsum'); + if($r[0]['item_type'] == ITEM_TYPE_PDL) { + $r[0]['body'] = t('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'); $r[0]['mimetype'] = 'text/plain'; $r[0]['title'] = ''; diff --git a/mod/photo.php b/mod/photo.php index 66280cb76..e8cd95f1c 100644 --- a/mod/photo.php +++ b/mod/photo.php @@ -22,14 +22,6 @@ function photo_init(&$a) { // NOTREACHED } - if($photo === 'qr') { - $t = $_GET['qr']; - require_once('library/phpqrcode/phpqrcode.php'); - header("Content-type: image/png"); - QRcode::png(($t) ? $t : '.'); - killme(); - } - $observer_xchan = get_observer_hash(); $default = get_default_profile_photo(); @@ -61,14 +53,17 @@ function photo_init(&$a) { $uid = $person; - $r = q("SELECT * FROM photo WHERE scale = %d AND uid = %d AND profile = 1 LIMIT 1", + $r = q("SELECT * FROM photo WHERE scale = %d AND uid = %d AND photo_usage = %d LIMIT 1", intval($resolution), - intval($uid) + intval($uid), + intval(PHOTO_PROFILE) ); if(count($r)) { $data = dbunescbin($r[0]['data']); $mimetype = $r[0]['type']; } + if(intval($r[0]['os_storage'])) + $data = file_get_contents($data); if(! isset($data)) { $data = file_get_contents($default); $mimetype = 'image/png'; @@ -128,7 +123,7 @@ function photo_init(&$a) { ); if($r) { - $allowed = (($r[0]['uid']) ? perm_is_allowed($r[0]['uid'],$observer_xchan,'view_photos') : true); + $allowed = (($r[0]['uid']) ? perm_is_allowed($r[0]['uid'],$observer_xchan,'view_storage') : true); $sql_extra = permissions_sql($r[0]['uid']); @@ -142,6 +137,8 @@ function photo_init(&$a) { if($r && $allowed) { $data = dbunescbin($r[0]['data']); $mimetype = $r[0]['type']; + if(intval($r[0]['os_storage'])) + $data = file_get_contents($data); } else { diff --git a/mod/photos.php b/mod/photos.php index 2af90610e..cd293b39d 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -6,6 +6,7 @@ require_once('include/acl_selectors.php'); require_once('include/bbcode.php'); require_once('include/security.php'); require_once('include/Contact.php'); +require_once('include/attach.php'); require_once('include/text.php'); @@ -62,7 +63,7 @@ function photos_post(&$a) { $page_owner_uid = $a->data['channel']['channel_id']; - if(perm_is_allowed($page_owner_uid,get_observer_hash(),'post_photos')) + if(perm_is_allowed($page_owner_uid,get_observer_hash(),'write_storage')) $can_post = true; if(! $can_post) { @@ -84,6 +85,7 @@ function photos_post(&$a) { $owner_record = $s[0]; + $acl = new AccessList($a->data['channel']); if((argc() > 3) && (argv(2) === 'album')) { @@ -106,11 +108,16 @@ function photos_post(&$a) { $newalbum = notags(trim($_REQUEST['albumname'])); if($newalbum != $album) { - $x = photos_album_rename($page_owner_uid,$album,$newalbum); - if($x) { - $newurl = str_replace(bin2hex($album),bin2hex($newalbum),$_SESSION['photo_return']); - goaway($a->get_baseurl() . '/' . $newurl); - } + + // @fixme - syncronise with DAV or disallow completely + + goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']); + +// $x = photos_album_rename($page_owner_uid,$album,$newalbum); +// if($x) { +// $newurl = str_replace(bin2hex($album),bin2hex($newalbum),$_SESSION['photo_return']); +// goaway($a->get_baseurl() . '/' . $newurl); +// } } /* @@ -136,14 +143,14 @@ function photos_post(&$a) { goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']); } - $r = q("select id, item_restrict from item where resource_id in ( $str ) and resource_type = 'photo' and uid = %d", + $r = q("select id from item where resource_id in ( $str ) and resource_type = 'photo' and uid = %d " . item_normal(), intval($page_owner_uid) ); if($r) { foreach($r as $i) { + attach_delete($page_owner_uid, $i['resource_id'], 1 ); drop_item($i['id'],false,DROPITEM_PHASE1,true /* force removal of linked items */); - if(! $item_restrict) - proc_run('php','include/notifier.php','drop',$i['id']); + proc_run('php','include/notifier.php','drop',$i['id']); } } @@ -152,6 +159,9 @@ function photos_post(&$a) { q("delete from photo where resource_id in ( $str ) and uid = %d", intval($page_owner_uid) ); + + // @FIXME do the same for the linked attach + } goaway($a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address']); @@ -176,30 +186,22 @@ function photos_post(&$a) { intval($page_owner_uid), dbesc($r[0]['resource_id']) ); + attach_delete($page_owner_uid, $r[0]['resource_id'], 1 ); + $i = q("SELECT * FROM `item` WHERE `resource_id` = '%s' AND resource_type = 'photo' and `uid` = %d LIMIT 1", dbesc($r[0]['resource_id']), intval($page_owner_uid) ); if(count($i)) { - q("UPDATE `item` SET item_restrict = (item_restrict | %d), `edited` = '%s', `changed` = '%s' WHERE `parent_mid` = '%s' AND `uid` = %d", - intval(ITEM_DELETED), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - dbesc($i[0]['mid']), - intval($page_owner_uid) - ); - + drop_item($i[0]['id'],true,DROPITEM_PHASE1); $url = $a->get_baseurl(); - $drop_id = intval($i[0]['id']); - - if($i[0]['visible']) - proc_run('php',"include/notifier.php","drop","$drop_id"); } } goaway($a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/album/' . $_SESSION['album_return']); } + if(($a->argc > 2) && ((x($_POST,'desc') !== false) || (x($_POST,'newtag') !== false)) || (x($_POST,'albname') !== false)) { @@ -207,11 +209,10 @@ function photos_post(&$a) { $rawtags = ((x($_POST,'newtag')) ? notags(trim($_POST['newtag'])) : ''); $item_id = ((x($_POST,'item_id')) ? intval($_POST['item_id']) : 0); $albname = ((x($_POST,'albname')) ? notags(trim($_POST['albname'])) : ''); - $adult = ((x($_POST,'adult')) ? intval($_POST['adult']) : 0); - $str_group_allow = perms2str($_POST['group_allow']); - $str_contact_allow = perms2str($_POST['contact_allow']); - $str_group_deny = perms2str($_POST['group_deny']); - $str_contact_deny = perms2str($_POST['contact_deny']); + $is_nsfw = ((x($_POST,'adult')) ? intval($_POST['adult']) : 0); + + $acl->set_from_array($_POST); + $perm = $acl->get(); $resource_id = $a->argv[2]; @@ -282,13 +283,12 @@ function photos_post(&$a) { if($p) { $ext = $phototypes[$p[0]['type']]; - $r = q("UPDATE `photo` SET `description` = '%s', `album` = '%s', `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s' WHERE `resource_id` = '%s' AND `uid` = %d", + $r = q("UPDATE `photo` SET `description` = '%s', `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s' WHERE `resource_id` = '%s' AND `uid` = %d", dbesc($desc), - dbesc($albname), - dbesc($str_contact_allow), - dbesc($str_group_allow), - dbesc($str_contact_deny), - dbesc($str_group_deny), + dbesc($perm['allow_cid']), + dbesc($perm['allow_gid']), + dbesc($perm['deny_cid']), + dbesc($perm['deny_gid']), dbesc($resource_id), intval($page_owner_uid) ); @@ -296,10 +296,10 @@ function photos_post(&$a) { $item_private = (($str_contact_allow || $str_group_allow || $str_contact_deny || $str_group_deny) ? true : false); - $old_adult = (($p[0]['photo_flags'] & PHOTO_ADULT) ? 1 : 0); - if($old_adult != $adult) { - $r = q("update photo set photo_flags = ( photo_flags ^ %d) where resource_id = '%s' and uid = %d", - intval(PHOTO_ADULT), + $old_is_nsfw = $p[0]['is_nsfw']; + if($old_is_nsfw != $is_nsfw) { + $r = q("update photo set is_nsfw = %d where resource_id = '%s' and uid = %d", + intval($is_nsfw), dbesc($resource_id), intval($page_owner_uid) ); @@ -332,14 +332,25 @@ function photos_post(&$a) { // make sure the linked item has the same permissions as the photo regardless of any other changes $x = q("update item set allow_cid = '%s', allow_gid = '%s', deny_cid = '%s', deny_gid = '%s', item_private = %d where id = %d", - dbesc($str_contact_allow), - dbesc($str_group_allow), - dbesc($str_contact_deny), - dbesc($str_group_deny), - intval($item_private), + dbesc($perm['allow_cid']), + dbesc($perm['allow_gid']), + dbesc($perm['deny_cid']), + dbesc($perm['deny_gid']), + intval($acl->is_private()), intval($item_id) ); + // make sure the attach has the same permissions as the photo regardless of any other changes + $x = q("update attach set allow_cid = '%s', allow_gid = '%s', deny_cid = '%s', deny_gid = '%s' where hash = '%s' and uid = %d and is_photo = 1", + dbesc($perm['allow_cid']), + dbesc($perm['allow_gid']), + dbesc($perm['deny_cid']), + dbesc($perm['deny_gid']), + dbesc($resource_id), + intval($page_owner_uid) + ); + + if(strlen($rawtags)) { @@ -406,15 +417,16 @@ function photos_post(&$a) { $observer = $a->data['observer']; $_REQUEST['source'] = 'photos'; + require_once('include/attach.php'); - if(!local_channel()) { + if(! local_channel()) { $_REQUEST['contact_allow'] = expand_acl($channel['channel_allow_cid']); - $_REQUEST['group_allow'] = expand_acl($channel['channel_allow_gid']); - $_REQUEST['contact_deny'] = expand_acl($channel['channel_deny_cid']); - $_REQUEST['group_deny'] = expand_acl($channel['channel_deny_gid']); + $_REQUEST['group_allow'] = expand_acl($channel['channel_allow_gid']); + $_REQUEST['contact_deny'] = expand_acl($channel['channel_deny_cid']); + $_REQUEST['group_deny'] = expand_acl($channel['channel_deny_gid']); } - $r = photo_upload($channel, $observer, $_REQUEST); + $r = attach_store($a->channel,get_observer_hash(), '', $_REQUEST); if(! $r['success']) { notice($r['message'] . EOL); @@ -468,7 +480,12 @@ function photos_content(&$a) { $datatype = argv(2); $datum = argv(3); } else { - $datatype = 'summary'; + if(argc() > 2) { + $datatype = argv(2); + $datum = ''; + } + else + $datatype = 'summary'; } if(argc() > 4) @@ -489,8 +506,8 @@ function photos_content(&$a) { $observer = $a->get_observer(); - $can_post = perm_is_allowed($owner_uid,$observer['xchan_hash'],'post_photos'); - $can_view = perm_is_allowed($owner_uid,$observer['xchan_hash'],'view_photos'); + $can_post = perm_is_allowed($owner_uid,$observer['xchan_hash'],'write_storage'); + $can_view = perm_is_allowed($owner_uid,$observer['xchan_hash'],'view_storage'); if(! $can_view) { notice( t('Access to this item is restricted.') . EOL); @@ -541,14 +558,10 @@ function photos_content(&$a) { if($_is_owner) { $channel = $a->get_channel(); - $channel_acl = array( - 'allow_cid' => $channel['channel_allow_cid'], - 'allow_gid' => $channel['channel_allow_gid'], - 'deny_cid' => $channel['channel_deny_cid'], - 'deny_gid' => $channel['channel_deny_gid'] - ); + $acl = new AccessList($channel); + $channel_acl = $acl->get(); - $lockstate = (($channel['channel_allow_cid'] || $channel['channel_allow_gid'] || $channel['channel_deny_cid'] || $channel['channel_deny_gid']) ? 'lock' : 'unlock'); + $lockstate = (($acl->is_private()) ? 'lock' : 'unlock'); } $aclselect = (($_is_owner) ? populate_acl($channel_acl,false) : ''); @@ -557,14 +570,22 @@ function photos_content(&$a) { $albums = ((array_key_exists('albums', $a->data)) ? $a->data['albums'] : photos_albums_list($a->data['channel'],$a->data['observer'])); + if(! $selname) { + $def_album = get_pconfig($a->data['channel']['channel_id'],'system','photo_path'); + if($def_album) { + $selname = filepath_macro($def_album); + $albums['album'][] = array('text' => $selname); + } + } + $tpl = get_markup_template('photos_upload.tpl'); $upload_form = replace_macros($tpl,array( '$pagename' => t('Upload Photos'), '$sessid' => session_id(), '$usage' => $usage_message, '$nickname' => $a->data['channel']['channel_address'], - '$newalbum_label' => t('Enter a new album name'), - '$newalbum_placeholder' => t('or select an existing one (doubleclick)'), + '$newalbum_label' => t('Enter an album name'), + '$newalbum_placeholder' => t('or select an existing album (doubleclick)'), '$visible' => array('visible', t('Create a status post for this upload'), 0, '', array(t('No'), t('Yes'))), '$albums' => $albums['albums'], '$selname' => $selname, @@ -590,22 +611,23 @@ function photos_content(&$a) { if($datatype === 'album') { - - - if((strlen($datum) & 1) || (! ctype_xdigit($datum))) { - notice( t('Album name could not be decoded') . EOL); - logger('mod_photos: illegal album encoding: ' . $datum); - $datum = ''; + if(strlen($datum)) { + if((strlen($datum) & 1) || (! ctype_xdigit($datum))) { + notice( t('Album name could not be decoded') . EOL); + logger('mod_photos: illegal album encoding: ' . $datum); + $datum = ''; + } } - $album = hex2bin($datum); + $album = (($datum) ? hex2bin($datum) : ''); $r = q("SELECT `resource_id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s' - AND `scale` <= 4 and ((photo_flags = %d) or (photo_flags & %d ) > 0) $sql_extra GROUP BY `resource_id`", + AND `scale` <= 4 and photo_usage IN ( %d, %d ) and is_nsfw = %d $sql_extra GROUP BY `resource_id`", intval($owner_uid), dbesc($album), intval(PHOTO_NORMAL), - intval(($unsafe) ? (PHOTO_PROFILE|PHOTO_ADULT) : PHOTO_PROFILE) + intval(PHOTO_PROFILE), + intval($unsafe) ); if(count($r)) { $a->set_pager_total(count($r)); @@ -621,13 +643,14 @@ function photos_content(&$a) { $r = q("SELECT p.resource_id, p.id, p.filename, p.type, p.scale, p.description, p.created FROM photo p INNER JOIN - (SELECT resource_id, max(scale) scale FROM photo WHERE uid = %d AND album = '%s' AND scale <= 4 AND (photo_flags = %d or photo_flags = %d ) $sql_extra GROUP BY resource_id) ph + (SELECT resource_id, max(scale) scale FROM photo WHERE uid = %d AND album = '%s' AND scale <= 4 AND photo_usage IN ( %d, %d ) and is_nsfw = %d $sql_extra GROUP BY resource_id) ph ON (p.resource_id = ph.resource_id AND p.scale = ph.scale) ORDER BY created $order LIMIT %d OFFSET %d", intval($owner_uid), dbesc($album), - intvaL(PHOTO_NORMAL), - intval(($unsafe) ? (PHOTO_PROFILE|PHOTO_ADULT) : PHOTO_PROFILE), + intval(PHOTO_NORMAL), + intval(PHOTO_PROFILE), + intval($unsafe), intval($a->pager['itemspage']), intval($a->pager['start']) ); @@ -643,17 +666,21 @@ function photos_content(&$a) { $album_e = $album; } $albums = ((array_key_exists('albums', $a->data)) ? $a->data['albums'] : photos_albums_list($a->data['channel'],$a->data['observer'])); - $edit_tpl = get_markup_template('album_edit.tpl'); - $album_edit = replace_macros($edit_tpl,array( - '$nametext' => t('Enter a new album name'), - '$name_placeholder' => t('or select an existing one (doubleclick)'), - '$nickname' => $a->data['channel']['channel_address'], - '$album' => $album_e, - '$albums' => $albums['albums'], - '$hexalbum' => bin2hex($album), - '$submit' => t('Submit'), - '$dropsubmit' => t('Delete Album') - )); + + // @fixme - syncronise actions with DAV + +// $edit_tpl = get_markup_template('album_edit.tpl'); +// $album_edit = replace_macros($edit_tpl,array( +// '$nametext' => t('Enter a new album name'), +// '$name_placeholder' => t('or select an existing one (doubleclick)'), +// '$nickname' => $a->data['channel']['channel_address'], +// '$album' => $album_e, +// '$albums' => $albums['albums'], +// '$hexalbum' => bin2hex($album), +// '$submit' => t('Submit'), +// '$dropsubmit' => t('Delete Album') +// )); + } } @@ -743,7 +770,7 @@ function photos_content(&$a) { // fetch image, item containing image, then comments - $ph = q("SELECT aid,uid,xchan,resource_id,created,edited,title,`description`,album,filename,`type`,height,width,`size`,scale,profile,photo_flags,allow_cid,allow_gid,deny_cid,deny_gid FROM `photo` WHERE `uid` = %d AND `resource_id` = '%s' + $ph = q("SELECT id,aid,uid,xchan,resource_id,created,edited,title,`description`,album,filename,`type`,height,width,`size`,scale,photo_usage,is_nsfw,allow_cid,allow_gid,deny_cid,deny_gid FROM `photo` WHERE `uid` = %d AND `resource_id` = '%s' $sql_extra ORDER BY `scale` ASC ", intval($owner_uid), dbesc($datum) @@ -863,9 +890,10 @@ function photos_content(&$a) { $linked_items = fetch_post_tags($linked_items,true); $link_item = $linked_items[0]; + $item_normal = item_normal(); $r = q("select * from item where parent_mid = '%s' - and item_restrict = 0 and uid = %d $sql_extra ", + $item_normal and uid = %d $sql_extra ", dbesc($link_item['mid']), intval($link_item['uid']) @@ -891,7 +919,7 @@ function photos_content(&$a) { } if((local_channel()) && (local_channel() == $link_item['uid'])) { - q("UPDATE `item` SET item_unseen = 0 WHERE item_unseen = 1 AND parent = %d AND uid = %d ", + q("UPDATE `item` SET item_unseen = 0 WHERE parent = %d and uid = %d and item_unseen = 1", intval($link_item['parent']), intval(local_channel()) ); @@ -937,7 +965,7 @@ function photos_content(&$a) { 'help_tags' => t('Example: @bob, @Barbara_Jensen, @jim@example.com'), 'item_id' => ((count($linked_items)) ? $link_item['id'] : 0), 'adult_enabled' => feature_enabled($owner_uid,'adult_photo_flagging'), - 'adult' => array('adult',t('Flag as adult in album view'), (($ph[0]['photo_flags'] & PHOTO_ADULT) ? 1 : 0),''), + 'adult' => array('adult',t('Flag as adult in album view'), intval($ph[0]['is_nsfw']),''), 'submit' => t('Submit'), 'delete' => t('Delete Photo') ); @@ -1119,7 +1147,7 @@ function photos_content(&$a) { $photo_tpl = get_markup_template('photo_view.tpl'); $o .= replace_macros($photo_tpl, array( - '$id' => $link_item['id'], //$ph[0]['id'], + '$id' => $ph[0]['id'], '$album' => $album_e, '$tools' => $tools, '$lock' => $lockstate[1], @@ -1163,12 +1191,13 @@ function photos_content(&$a) { //$o = ''; $r = q("SELECT `resource_id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' - and ((photo_flags = %d) or (photo_flags & %d) > 0) $sql_extra GROUP BY `resource_id`", + and photo_usage in ( %d, %d ) and is_nsfw = %d $sql_extra GROUP BY `resource_id`", intval($a->data['channel']['channel_id']), dbesc('Contact Photos'), dbesc( t('Contact Photos')), intval(PHOTO_NORMAL), - intval(($unsafe) ? (PHOTO_PROFILE|PHOTO_ADULT) : PHOTO_PROFILE) + intval(PHOTO_PROFILE), + intval($unsafe) ); if(count($r)) { $a->set_pager_total(count($r)); @@ -1178,13 +1207,14 @@ function photos_content(&$a) { $r = q("SELECT p.resource_id, p.id, p.filename, p.type, p.album, p.scale, p.created FROM photo p INNER JOIN (SELECT resource_id, max(scale) scale FROM photo WHERE uid=%d AND album != '%s' AND album != '%s' - AND (photo_flags = %d or ( photo_flags & %d ) > 0 ) $sql_extra group by resource_id) ph + AND photo_usage IN ( %d, %d ) and is_nsfw = %d $sql_extra group by resource_id) ph ON (p.resource_id = ph.resource_id and p.scale = ph.scale) ORDER by p.created DESC LIMIT %d OFFSET %d", intval($a->data['channel']['channel_id']), dbesc('Contact Photos'), dbesc( t('Contact Photos')), intval(PHOTO_NORMAL), - intval(($unsafe) ? (PHOTO_PROFILE|PHOTO_ADULT) : PHOTO_PROFILE), + intval(PHOTO_PROFILE), + intval($unsafe), intval($a->pager['itemspage']), intval($a->pager['start']) ); diff --git a/mod/ping.php b/mod/ping.php index b676726fe..394dbf089 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -43,6 +43,8 @@ function ping_init(&$a) { $vnotify = false; + $item_normal = item_normal(); + if(local_channel()) { $vnotify = get_pconfig(local_channel(),'system','vnotify'); $evdays = intval(get_pconfig(local_channel(),'system','evdays')); @@ -156,16 +158,13 @@ function ping_init(&$a) { ); break; case 'home': - $r = q("update item set item_unseen = 0 where item_unseen = 1 and (item_flags & %d) > 0 and uid = %d", - intval(ITEM_WALL), + $r = q("update item set item_unseen = 0 where item_unseen = 1 and item_wall = 1 and uid = %d", intval(local_channel()) ); break; case 'messages': - $r = q("update mail set mail_flags = ( mail_flags | %d ) where channel_id = %d and not (mail_flags & %d) > 0", - intval(MAIL_SEEN), - intval(local_channel()), - intval(MAIL_SEEN) + $r = q("update mail set mail_seen = 1 where mail_seen = 0 and channel_id = %d ", + intval(local_channel()) ); break; case 'all_events': @@ -243,11 +242,9 @@ function ping_init(&$a) { if(argc() > 1 && argv(1) === 'messages') { $channel = $a->get_channel(); $t = q("select mail.*, xchan.* from mail left join xchan on xchan_hash = from_xchan - where channel_id = %d and not ( mail_flags & %d ) > 0 and not (mail_flags & %d ) > 0 + where channel_id = %d and mail_seen = 0 and mail_deleted = 0 and from_xchan != '%s' order by created desc limit 50", intval(local_channel()), - intval(MAIL_SEEN), - intval(MAIL_DELETED), dbesc($channel['channel_hash']) ); @@ -259,7 +256,7 @@ function ping_init(&$a) { 'url' => $zz['xchan_url'], 'photo' => $zz['xchan_photo_s'], 'when' => relative_date($zz['created']), - 'hclass' => (($zz['mail_flags'] & MAIL_SEEN) ? 'notify-seen' : 'notify-unseen'), + 'hclass' => (intval($zz['mail_seen']) ? 'notify-seen' : 'notify-unseen'), 'message' => t('sent you a private message'), ); } @@ -273,7 +270,7 @@ function ping_init(&$a) { $result = array(); $r = q("SELECT * FROM item - WHERE item_restrict = 0 and item_unseen = 1 and uid = %d + WHERE item_unseen = 1 and uid = %d $item_normal and author_xchan != '%s' ORDER BY created DESC limit 300", intval(local_channel()), dbesc($ob_hash) @@ -282,7 +279,7 @@ function ping_init(&$a) { if($r) { xchan_query($r); foreach($r as $item) { - if((argv(1) === 'home') && (! ($item['item_flags'] & ITEM_WALL))) + if((argv(1) === 'home') && (! intval($item['item_wall']))) continue; $result[] = format_notification($item); } @@ -295,11 +292,8 @@ function ping_init(&$a) { if(argc() > 1 && (argv(1) === 'intros')) { $result = array(); - $r = q("SELECT * FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash where abook_channel = %d and (abook_flags & %d) > 0 and not ((abook_flags & %d) > 0 or (xchan_flags & %d) > 0) ORDER BY abook_created DESC LIMIT 50", - intval(local_channel()), - intval(ABOOK_FLAG_PENDING), - intval(ABOOK_FLAG_SELF|ABOOK_FLAG_IGNORED), - intval(XCHAN_FLAGS_DELETED|XCHAN_FLAGS_ORPHAN) + $r = q("SELECT * FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash where abook_channel = %d and abook_pending = 1 and abook_self = 0 and abook_ignored = 0 and xchan_deleted = 0 and xchan_orphan = 0 ORDER BY abook_created DESC LIMIT 50", + intval(local_channel()) ); if($r) { @@ -327,6 +321,7 @@ function ping_init(&$a) { $r = q("SELECT * FROM event left join xchan on event_xchan = xchan_hash WHERE `event`.`uid` = %d AND start < '%s' AND start > '%s' and `ignore` = 0 + and type in ( 'event', 'birthday' ) ORDER BY `start` DESC LIMIT 1000", intval(local_channel()), dbesc(datetime_convert('UTC', date_default_timezone_get(), 'now + ' . intval($evdays) . ' days')), @@ -378,8 +373,9 @@ function ping_init(&$a) { $t1 = dba_timer(); if($vnotify & (VNOTIFY_NETWORK|VNOTIFY_CHANNEL)) { - $r = q("SELECT id, item_restrict, item_flags FROM item - WHERE item_restrict = 0 and item_unseen = 1 and uid = %d + $r = q("SELECT id, item_wall FROM item + WHERE item_unseen = 1 and uid = %d + $item_normal and author_xchan != '%s'", intval(local_channel()), dbesc($ob_hash) @@ -390,7 +386,7 @@ function ping_init(&$a) { call_hooks('network_ping', $arr); foreach ($r as $it) { - if($it['item_flags'] & ITEM_WALL) + if(intval($it['item_wall'])) $result['home'] ++; else $result['network'] ++; @@ -406,11 +402,8 @@ function ping_init(&$a) { $t2 = dba_timer(); if($vnotify & VNOTIFY_INTRO) { - $intr = q("SELECT COUNT(abook.abook_id) AS total FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash where abook_channel = %d and (abook_flags & %d) > 0 and not ((abook_flags & %d) > 0 or (xchan_flags & %d) > 0)", - intval(local_channel()), - intval(ABOOK_FLAG_PENDING), - intval(ABOOK_FLAG_SELF|ABOOK_FLAG_IGNORED), - intval(XCHAN_FLAGS_DELETED|XCHAN_FLAGS_ORPHAN) + $intr = q("SELECT COUNT(abook.abook_id) AS total FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash where abook_channel = %d and abook_pending = 1 and abook_self = 0 and abook_ignored = 0 and xchan_deleted = 0 and xchan_orphan = 0 ", + intval(local_channel()) ); $t3 = dba_timer(); @@ -424,9 +417,8 @@ function ping_init(&$a) { if($vnotify & VNOTIFY_MAIL) { $mails = q("SELECT count(id) as total from mail - WHERE channel_id = %d AND not (mail_flags & %d) > 0 and from_xchan != '%s' ", + WHERE channel_id = %d AND mail_seen = 0 and from_xchan != '%s' ", intval(local_channel()), - intval(MAIL_SEEN), dbesc($channel['channel_hash']) ); if($mails) @@ -448,6 +440,7 @@ function ping_init(&$a) { if($vnotify & (VNOTIFY_EVENT|VNOTIFY_EVENTTODAY|VNOTIFY_BIRTHDAY)) { $events = q("SELECT type, start, adjust FROM `event` WHERE `event`.`uid` = %d AND start < '%s' AND start > '%s' and `ignore` = 0 + and type in ( 'event', 'birthday' ) ORDER BY `start` ASC ", intval(local_channel()), dbesc(datetime_convert('UTC', date_default_timezone_get(), 'now + ' . intval($evdays) . ' days')), diff --git a/mod/poke.php b/mod/poke.php index 6257a2821..f66d28956 100755 --- a/mod/poke.php +++ b/mod/poke.php @@ -87,10 +87,8 @@ function poke_init(&$a) { $arr = array(); - $arr['item_flags'] = ITEM_WALL | ITEM_ORIGIN; - if($parent_item) - $arr['item_flags'] |= ITEM_THREAD_TOP; + $arr['item_wall'] = 1; $arr['owner_xchan'] = (($parent_item) ? $parent_item['owner_xchan'] : $channel['channel_hash']); $arr['parent_mid'] = (($parent_mid) ? $parent_mid : $mid); $arr['title'] = ''; @@ -115,6 +113,13 @@ function poke_init(&$a) { $arr['object'] = json_encode($obj); + $arr['item_origin'] = 1; + $arr['item_wall'] = 1; + $arr['item_unseen'] = 1; + if(! $parent_item) + $item['item_thread_top'] = 1; + + post_activity_item($arr); return; diff --git a/mod/post.php b/mod/post.php index a429dc33a..00e599b49 100644 --- a/mod/post.php +++ b/mod/post.php @@ -103,9 +103,7 @@ function post_init(&$a) { // Any channel will do, providing it's currently active. We just need to have an // identity to attach to the packet we send back. So find one. - $c = q("select * from channel where not ( channel_pageflags & %d )>0 limit 1", - intval(PAGE_REMOVED) - ); + $c = q("select * from channel where channel_removed = 0 limit 1"); if (! $c) { // nobody here @@ -286,20 +284,13 @@ function post_init(&$a) { $a->set_groups(init_groups_visitor($_SESSION['visitor_id'])); info(sprintf( t('Welcome %s. Remote authentication successful.'),$xx['xchan_name'])); logger('mod_zot: auth success from ' . $xx['xchan_addr']); - q("update hubloc set hubloc_status = (hubloc_status | %d ) where hubloc_id = %d ", - intval(HUBLOC_WORKS), - intval($xx['hubloc_id']) - ); - } else { + } + else { if ($test) { $ret['message'] .= 'auth failure. ' . print_r($_REQUEST,true) . print_r($j,true) . EOL; continue; } logger('mod_zot: magic-auth failure - not authenticated: ' . $xx['xchan_addr']); - q("update hubloc set hubloc_status = (hubloc_status | %d ) where hubloc_id = %d ", - intval(HUBLOC_RECEIVE_ERROR), - intval($xx['hubloc_id']) - ); } if ($test) { @@ -308,7 +299,6 @@ function post_init(&$a) { } } - /** * @FIXME we really want to save the return_url in the session before we * visit rmagic. This does however prevent a recursion if you visit @@ -700,20 +690,16 @@ function post_post(&$a) { // a dead hub came back to life - reset any tombstones we might have - if ($hub['hubloc_status'] & HUBLOC_OFFLINE) { - q("update hubloc set hubloc_status = (hubloc_status & ~%d) where hubloc_id = %d", - intval(HUBLOC_OFFLINE), + if(intval($hub['hubloc_error'])) { + q("update hubloc set hubloc_error = 0 where hubloc_id = %d", intval($hub['hubloc_id']) ); - if ($r[0]['hubloc_flags'] & HUBLOC_FLAGS_ORPHANCHECK) { - q("update hubloc set hubloc_flags = (hubloc_flags & ~%d) where hubloc_id = %d", - intval(HUBLOC_FLAGS_ORPHANCHECK), + if(intval($r[0]['hubloc_orphancheck'])) { + q("update hubloc set hubloc_orhpancheck = 0 where hubloc_id = %d", intval($hub['hubloc_id']) ); } - q("update xchan set xchan_flags = (xchan_flags & ~%d) where (xchan_flags & %d)>0 and xchan_hash = '%s'", - intval(XCHAN_FLAGS_ORPHAN), - intval(XCHAN_FLAGS_ORPHAN), + q("update xchan set xchan_orphan = 0 where xchan_orphan = 1 and xchan_hash = '%s'", dbesc($hub['hubloc_hash']) ); } @@ -725,8 +711,7 @@ function post_post(&$a) { * Get rid of them (mark them deleted). There's a good chance they were re-installs. */ - q("update hubloc set hubloc_flags = ( hubloc_flags | %d ) where hubloc_url = '%s' and hubloc_sitekey != '%s' ", - intval(HUBLOC_FLAGS_DELETED), + q("update hubloc set hubloc_deleted = 1 where hubloc_url = '%s' and hubloc_sitekey != '%s' ", dbesc($hub['hubloc_url']), dbesc($hub['hubloc_sitekey']) ); diff --git a/mod/profile_photo.php b/mod/profile_photo.php index c70e8fc94..7067a9f76 100644 --- a/mod/profile_photo.php +++ b/mod/profile_photo.php @@ -92,12 +92,15 @@ function profile_photo_post(&$a) { $is_default_profile = 1; if($_REQUEST['profile']) { - $r = q("select id, is_default from profile where id = %d and uid = %d limit 1", + $r = q("select id, profile_guid, is_default, gender from profile where id = %d and uid = %d limit 1", intval($_REQUEST['profile']), intval(local_channel()) ); - if(($r) && (! intval($r[0]['is_default']))) - $is_default_profile = 0; + if($r) { + $profile = $r[0]; + if(! intval($profile['is_default'])) + $is_default_profile = 0; + } } @@ -130,7 +133,7 @@ function profile_photo_post(&$a) { if($r) { $base_image = $r[0]; - $base_image['data'] = dbunescbin($base_image['data']); + $base_image['data'] = (($r[0]['os_storage']) ? @file_get_contents($base_image['data']) : dbunescbin($base_image['data'])); $im = photo_factory($base_image['data'], $base_image['type']); if($im->is_valid()) { @@ -143,7 +146,7 @@ function profile_photo_post(&$a) { 'filename' => $base_image['filename'], 'album' => t('Profile Photos')); $p['scale'] = 4; - $p['photo_flags'] = (($is_default_profile) ? PHOTO_PROFILE : PHOTO_NORMAL); + $p['photo_usage'] = (($is_default_profile) ? PHOTO_PROFILE : PHOTO_NORMAL); $r1 = $im->save($p); @@ -167,20 +170,21 @@ function profile_photo_post(&$a) { return; } + $channel = $a->get_channel(); + // If setting for the default profile, unset the profile photo flag from any other photos I own if($is_default_profile) { - $r = q("UPDATE photo SET profile = 0 WHERE profile = 1 AND resource_id != '%s' AND `uid` = %d", - dbesc($base_image['resource_id']), - intval(local_channel()) - ); - $r = q("UPDATE photo SET photo_flags = ( photo_flags & ~%d ) WHERE ( photo_flags & %d )>0 + $r = q("UPDATE photo SET photo_usage = %d WHERE photo_usage = %d AND resource_id != '%s' AND `uid` = %d", - intval(PHOTO_PROFILE), + intval(PHOTO_NORMAL), intval(PHOTO_PROFILE), dbesc($base_image['resource_id']), intval(local_channel()) ); + + send_profile_photo_activity($channel,$base_image,$profile); + } else { $r = q("update profile set photo = '%s', thumb = '%s' where id = %d and uid = %d", @@ -194,7 +198,6 @@ function profile_photo_post(&$a) { // We'll set the updated profile-photo timestamp even if it isn't the default profile, // so that browsers will do a cache update unconditionally - $channel = $a->get_channel(); $r = q("UPDATE xchan set xchan_photo_mimetype = '%s', xchan_photo_date = '%s' where xchan_hash = '%s'", @@ -210,7 +213,9 @@ function profile_photo_post(&$a) { // Now copy profile-permissions to pictures, to prevent privacyleaks by automatically created folder 'Profile Pictures' - profile_photo_set_profile_perms($_REQUEST['profile']); + profile_photo_set_profile_perms($_REQUEST['profile']); + + } else @@ -221,34 +226,104 @@ function profile_photo_post(&$a) { return; // NOTREACHED } - $src = $_FILES['userfile']['tmp_name']; - $filename = basename($_FILES['userfile']['name']); - $filesize = intval($_FILES['userfile']['size']); - $filetype = $_FILES['userfile']['type']; - if ($filetype=="") $filetype=guess_image_type($filename); - - $maximagesize = get_config('system','maximagesize'); - - if(($maximagesize) && ($filesize > $maximagesize)) { - notice( sprintf(t('Image exceeds size limit of %d'), $maximagesize) . EOL); - @unlink($src); - return; + + + $hash = photo_new_resource(); + $smallest = 0; + + require_once('include/attach.php'); + + $res = attach_store($a->get_channel(), get_observer_hash(), '', array('album' => t('Profile Photos'), 'hash' => $hash)); + + logger('attach_store: ' . print_r($res,true)); + + if($res && intval($res['data']['is_photo'])) { + $i = q("select * from photo where resource_id = '%s' and uid = %d order by scale", + dbesc($hash), + intval(local_channel()) + ); + + if(! $i) { + notice( t('Image upload failed.') . EOL ); + return; + } + $os_storage = false; + + foreach($i as $ii) { + if(intval($ii['scale']) < 2) { + $smallest = intval($ii['scale']); + $os_storage = intval($ii['os_storage']); + $imagedata = $ii['data']; + $filetype = $ii['type']; + } + } } - $imagedata = @file_get_contents($src); + $imagedata = (($os_storage) ? @file_get_contents($imagedata) : $imagedata); $ph = photo_factory($imagedata, $filetype); if(! $ph->is_valid()) { notice( t('Unable to process image.') . EOL ); - @unlink($src); return; } - $ph->orient($src); - @unlink($src); - return profile_photo_crop_ui_head($a, $ph); + + return profile_photo_crop_ui_head($a, $ph, $hash, $smallest); } +function send_profile_photo_activity($channel,$photo,$profile) { + + // for now only create activities for the default profile + + if(! intval($profile['is_default'])) + return; + + $arr = array(); + $arr['item_thread_top'] = 1; + $arr['item_origin'] = 1; + $arr['item_wall'] = 1; + $arr['obj_type'] = ACTIVITY_OBJ_PHOTO; + $arr['verb'] = ACTIVITY_UPDATE; + + $arr['object'] = json_encode(array( + 'type' => $arr['obj_type'], + 'id' => z_root() . '/photo/profile/l/' . $channel['channel_id'], + 'link' => array('rel' => 'photo', 'type' => $photo['type'], 'href' => z_root() . '/photo/profile/l/' . $channel['channel_id']) + )); + + if(stripos($profile['gender'],t('female')) !== false) + $t = t('%1$s updated her %2$s'); + elseif(stripos($profile['gender'],t('male')) !== false) + $t = t('%1$s updated his %2$s'); + else + $t = t('%1$s updated their %2$s'); + + $ptext = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo['resource_id'] . ']' . t('profile photo') . '[/zrl]'; + + $ltext = '[zrl=' . z_root() . '/profile/' . $channel['channel_address'] . ']' . '[zmg=150x150]' . z_root() . '/photo/' . $photo['resource_id'] . '-4[/zmg][/zrl]'; + + $arr['body'] = sprintf($t,$channel['channel_name'],$ptext) . "\n\n" . $ltext; + + $acl = new AccessList($channel); + $x = $acl->get(); + $arr['allow_cid'] = $x['allow_cid']; + + $arr['allow_gid'] = $x['allow_gid']; + $arr['deny_cid'] = $x['deny_cid']; + $arr['deny_gid'] = $x['deny_gid']; + + $arr['uid'] = $channel['channel_id']; + $arr['aid'] = $channel['channel_account_id']; + + $arr['owner_xchan'] = $channel['channel_hash']; + $arr['author_xchan'] = $channel['channel_hash']; + + post_activity_item($arr); + + +} + + /* @brief Generate content of profile-photo view * * @param $a Current application @@ -257,7 +332,6 @@ function profile_photo_post(&$a) { */ -if(! function_exists('profile_photo_content')) { function profile_photo_content(&$a) { if(! local_channel()) { @@ -301,20 +375,12 @@ function profile_photo_content(&$a) { if(($r[0]['album'] == t('Profile Photos')) && ($havescale)) { // unset any existing profile photos - $r = q("UPDATE photo SET profile = 0 WHERE profile = 1 AND uid = %d", - intval(local_channel())); - $r = q("UPDATE photo SET photo_flags = (photo_flags & ~%d ) WHERE (photo_flags & %d )>0 AND uid = %d", - intval(PHOTO_PROFILE), + $r = q("UPDATE photo SET photo_usage = %d WHERE photo_usage = %d AND uid = %d", + intval(PHOTO_NORMAL), intval(PHOTO_PROFILE), intval(local_channel())); - // set all sizes of this one as profile photos - $r = q("UPDATE photo SET profile = 1 WHERE uid = %d AND resource_id = '%s'", - intval(local_channel()), - dbesc($resource_id) - ); - - $r = q("UPDATE photo SET photo_flags = ( photo_flags | %d ) WHERE uid = %d AND resource_id = '%s'", + $r = q("UPDATE photo SET photo_usage = %d WHERE uid = %d AND resource_id = '%s'", intval(PHOTO_PROFILE), intval(local_channel()), dbesc($resource_id) @@ -331,7 +397,7 @@ function profile_photo_content(&$a) { goaway($a->get_baseurl() . '/profiles'); } - $r = q("SELECT `data`, `type` FROM photo WHERE id = %d and uid = %d limit 1", + $r = q("SELECT `data`, `type`, resource_id, os_storage FROM photo WHERE id = %d and uid = %d limit 1", intval($r[0]['id']), intval(local_channel()) @@ -341,9 +407,31 @@ function profile_photo_content(&$a) { return; } - $ph = photo_factory(dbunescbin($r[0]['data']), $r[0]['type']); - // go ahead as if we have just uploaded a new photo to crop - profile_photo_crop_ui_head($a, $ph); + if(intval($r[0]['os_storage'])) + $data = @file_get_contents($r[0]['data']); + else + $data = dbunescbin($r[0]['data']); + + $ph = photo_factory($data, $r[0]['type']); + $smallest = 0; + if($ph->is_valid()) { + // go ahead as if we have just uploaded a new photo to crop + $i = q("select resource_id, scale from photo where resource_id = '%s' and uid = %d order by scale", + dbesc($r[0]['resource_id']), + intval(local_channel()) + ); + + if($i) { + $hash = $i[0]['resource_id']; + foreach($i as $ii) { + if(intval($ii['scale']) < 2) { + $smallest = intval($ii['scale']); + } + } + } + } + + profile_photo_crop_ui_head($a, $ph, $hash, $smallest); } $profiles = q("select id, profile_name as name, is_default from profile where uid = %d", @@ -371,7 +459,7 @@ function profile_photo_content(&$a) { return $o; } else { - $filename = $a->data['imagecrop'] . '-' . $a->data['imagecrop_resolution'] . '.' . $a->data['imagecrop_ext']; + $filename = $a->data['imagecrop'] . '-' . $a->data['imagecrop_resolution']; $resolution = $a->data['imagecrop_resolution']; $tpl = get_markup_template("cropbody.tpl"); $o .= replace_macros($tpl,array( @@ -388,7 +476,7 @@ function profile_photo_content(&$a) { } return; // NOTREACHED -}} +} /* @brief Generate the UI for photo-cropping * @@ -399,8 +487,8 @@ function profile_photo_content(&$a) { */ -if(! function_exists('profile_photo_crop_ui_head')) { -function profile_photo_crop_ui_head(&$a, $ph){ + +function profile_photo_crop_ui_head(&$a, $ph, $hash, $smallest){ $max_length = get_config('system','max_image_length'); if(! $max_length) @@ -417,34 +505,10 @@ function profile_photo_crop_ui_head(&$a, $ph){ $height = $ph->getHeight(); } - $hash = photo_new_resource(); - $smallest = 0; - - $p = array('aid' => get_account_id(), 'uid' => local_channel(), 'resource_id' => $hash, - 'filename' => $filename, 'album' => t('Profile Photos'), 'scale' => 0); - $r = $ph->save($p); - - if($r) - info( t('Image uploaded successfully.') . EOL ); - else - notice( t('Image upload failed.') . EOL ); - - if($width > 640 || $height > 640) { - $ph->scaleImage(640); - $p['scale'] = 1; - - $r = $ph->save($p); - - if($r === false) - notice( sprintf(t('Image size reduction [%s] failed.'),"640") . EOL ); - else - $smallest = 1; - } $a->data['imagecrop'] = $hash; $a->data['imagecrop_resolution'] = $smallest; - $a->data['imagecrop_ext'] = $ph->getExt(); $a->page['htmlhead'] .= replace_macros(get_markup_template("crophead.tpl"), array()); return; -}} +} diff --git a/mod/public.php b/mod/public.php index 64ae9d20a..45edda6c0 100644 --- a/mod/public.php +++ b/mod/public.php @@ -16,11 +16,13 @@ function public_content(&$a, $update = 0, $load = false) { if(get_config('system','disable_discover_tab')) return; + $item_normal = item_normal(); + if(! $update) { $maxheight = get_config('system','home_divmore_height'); if(! $maxheight) - $maxheight = 75; + $maxheight = 400; $o .= '<div id="live-public"></div>' . "\r\n"; $o .= "<script> var profile_uid = " . ((intval(local_channel())) ? local_channel() : (-1)) @@ -69,7 +71,7 @@ function public_content(&$a, $update = 0, $load = false) { require_once('include/security.php'); if(get_config('system','site_firehose')) { - $uids = " and item.uid in ( " . stream_perms_api_uids(PERMS_PUBLIC) . " ) and item_private = 0 and (item_flags & " . intval(ITEM_WALL) . " ) > 0 "; + $uids = " and item.uid in ( " . stream_perms_api_uids(PERMS_PUBLIC) . " ) and item_private = 0 and item_wall = 1 "; } else { $sys = get_sys_channel(); @@ -78,10 +80,12 @@ function public_content(&$a, $update = 0, $load = false) { $a->data['firehose'] = intval($sys['channel_id']); } + if(get_config('system','public_list_mode')) + $page_mode = 'list'; + else + $page_mode = 'client'; - $page_mode = 'list'; - $simple_update = (($update) ? " and item.item_unseen = 1 " : ''); if($update && $_SESSION['loadtime']) @@ -101,12 +105,11 @@ function public_content(&$a, $update = 0, $load = false) { $r = q("SELECT distinct item.id AS item_id, $ordering FROM item left join abook on item.author_xchan = abook.abook_xchan - WHERE true $uids AND item.item_restrict = 0 + WHERE true $uids $item_normal AND item.parent = item.id - and ((abook.abook_flags & %d) = 0 or abook.abook_flags is null) + and (abook.abook_blocked = 0 or abook.abook_flags is null) $sql_extra3 $sql_extra $sql_nets - ORDER BY $ordering DESC $pager_sql ", - intval(ABOOK_FLAG_BLOCKED) + ORDER BY $ordering DESC $pager_sql " ); @@ -115,11 +118,10 @@ function public_content(&$a, $update = 0, $load = false) { $r = q("SELECT distinct item.id AS item_id, $ordering FROM item left join abook on item.author_xchan = abook.abook_xchan - WHERE true $uids AND item.item_restrict = 0 + WHERE true $uids $item_normal AND item.parent = item.id $simple_update - and ((abook.abook_flags & %d) = 0 or abook.abook_flags is null) - $sql_extra3 $sql_extra $sql_nets", - intval(ABOOK_FLAG_BLOCKED) + and (abook.abook_blocked = 0 or abook.abook_flags is null) + $sql_extra3 $sql_extra $sql_nets" ); $_SESSION['loadtime'] = datetime_convert(); } @@ -132,7 +134,7 @@ function public_content(&$a, $update = 0, $load = false) { $parents_str = ids_to_querystr($r,'item_id'); $items = q("SELECT item.*, item.id AS item_id FROM item - WHERE true $uids AND item.item_restrict = 0 + WHERE true $uids $item_normal AND item.parent IN ( %s ) $sql_extra ", dbesc($parents_str) diff --git a/mod/receive.php b/mod/receive.php deleted file mode 100644 index deaf8cb37..000000000 --- a/mod/receive.php +++ /dev/null @@ -1,77 +0,0 @@ -<?php - -/** - * Diaspora endpoint - */ - -require_once('include/crypto.php'); -require_once('include/diaspora.php'); - - -function receive_post(&$a) { - - - $enabled = intval(get_config('system','diaspora_enabled')); - if(! $enabled) { - logger('mod-diaspora: disabled'); - http_status_exit(500); - } - - $public = false; - - if((argc() == 2) && (argv(1) === 'public')) { - $public = true; - } - else { - - if(argc() != 3 || argv(1) !== 'users') - http_status_exit(500); - - $guid = argv(2); - - // Diaspora sites *may* provide a truncated guid. - - $r = q("SELECT * FROM channel left join xchan on channel_hash = xchan_hash WHERE channel_guid like '%s' AND (channel_pageflags & %d ) = 0 LIMIT 1", - dbesc($guid . '%'), - intval(PAGE_REMOVED) - ); - if(! $r) - http_status_exit(500); - - $importer = $r[0]; - } - - // It is an application/x-www-form-urlencoded that has been urlencoded twice. - - logger('mod-diaspora: receiving post', LOGGER_DEBUG); - - $xml = urldecode($_POST['xml']); - - logger('mod-diaspora: new salmon ' . $xml, LOGGER_DATA); - - if(! $xml) - http_status_exit(500); - - logger('mod-diaspora: message is okay', LOGGER_DEBUG); - - $msg = diaspora_decode($importer,$xml); - - logger('mod-diaspora: decoded', LOGGER_DEBUG); - - logger('mod-diaspora: decoded msg: ' . print_r($msg,true), LOGGER_DATA); - - if(! is_array($msg)) - http_status_exit(500); - - logger('mod-diaspora: dispatching', LOGGER_DEBUG); - - $ret = 0; - if($public) - diaspora_dispatch_public($msg); - else - $ret = diaspora_dispatch($importer,$msg); - - http_status_exit(($ret) ? $ret : 200); - // NOTREACHED -} - diff --git a/mod/rpost.php b/mod/rpost.php index 0c0916646..d519a996b 100644 --- a/mod/rpost.php +++ b/mod/rpost.php @@ -94,15 +94,13 @@ function rpost_content(&$a) { $channel = $a->get_channel(); - $channel_acl = array( - 'allow_cid' => $channel['channel_allow_cid'], - 'allow_gid' => $channel['channel_allow_gid'], - 'deny_cid' => $channel['channel_deny_cid'], - 'deny_gid' => $channel['channel_deny_gid'] - ); + + $acl = new AccessList($channel); + + $channel_acl = $acl->get(); if($_REQUEST['url']) { - $x = z_fetch_url(z_root() . '/parse_url?f=&url=' . urlencode($_REQUEST['url'])); + $x = z_fetch_url(z_root() . '/linkinfo?f=&url=' . urlencode($_REQUEST['url'])); if($x['success']) $_REQUEST['body'] = $_REQUEST['body'] . $x['body']; } @@ -112,8 +110,7 @@ function rpost_content(&$a) { 'allow_location' => ((intval(get_pconfig($channel['channel_id'],'system','use_browser_location'))) ? '1' : ''), 'default_location' => $channel['channel_location'], 'nickname' => $channel['channel_address'], - 'lockstate' => (($channel['channel_allow_cid'] || $channel['channel_allow_gid'] - || $channel['channel_deny_cid'] || $channel['channel_deny_gid']) ? 'lock' : 'unlock'), + 'lockstate' => (($acl->is_private()) ? 'lock' : 'unlock'), 'acl' => populate_acl($channel_acl), 'bang' => '', 'visitor' => true, diff --git a/mod/search.php b/mod/search.php index 426642141..ce8357fb9 100644 --- a/mod/search.php +++ b/mod/search.php @@ -59,6 +59,10 @@ function search_content(&$a,$update = 0, $load = false) { $search = substr($search,1); goaway(z_root() . '/directory' . '?f=1&navsearch=1&search=' . $search); } + if(strpos($search,'?') === 0) { + $search = substr($search,1); + goaway(z_root() . '/help' . '?f=1&navsearch=1&search=' . $search); + } // look for a naked webbie if(strpos($search,'@') !== false) { @@ -125,6 +129,7 @@ function search_content(&$a,$update = 0, $load = false) { } + $item_normal = item_normal(); $pub_sql = public_permissions_sql($observer_hash); require_once('include/identity.php'); @@ -143,7 +148,7 @@ function search_content(&$a,$update = 0, $load = false) { if($load) { $r = null; - + if(ACTIVE_DBTYPE == DBTYPE_POSTGRES) { $prefix = 'distinct on (created, mid)'; $suffix = 'ORDER BY created DESC, mid'; @@ -153,26 +158,24 @@ function search_content(&$a,$update = 0, $load = false) { } if(local_channel()) { $r = q("SELECT $prefix mid, item.id as item_id, item.* from item - WHERE item_restrict = 0 AND ( item_flags & %d ) = 0 - AND ((( `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' AND item_private = 0 ) + WHERE ((( `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' AND item_private = 0 ) OR ( `item`.`uid` = %d )) OR item.owner_xchan = '%s' ) + $item_normal $sql_extra $suffix $pager_sql ", - intval(ITEM_OBSCURED), intval(local_channel()), dbesc($sys['xchan_hash']) ); } if($r === null) { $r = q("SELECT $prefix mid, item.id as item_id, item.* from item - WHERE item_restrict = 0 AND ( item_flags & %d ) = 0 - AND (((( `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' + WHERE (((( `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' AND item_private = 0 ) and owner_xchan in ( " . stream_perms_xchans(($observer) ? (PERMS_NETWORK|PERMS_PUBLIC) : PERMS_PUBLIC) . " )) $pub_sql ) OR owner_xchan = '%s') + $item_normal $sql_extra $suffix $pager_sql", - intval(ITEM_OBSCURED), dbesc($sys['xchan_hash']) ); } diff --git a/mod/settings.php b/mod/settings.php index b0ba04dfc..8bfff3765 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -123,13 +123,6 @@ function settings_post(&$a) { call_hooks('feature_settings_post', $_POST); - if($_POST['dspr-submit']) { - set_pconfig(local_channel(),'system','diaspora_allowed',intval($_POST['dspr_allowed'])); - set_pconfig(local_channel(),'system','diaspora_public_comments',intval($_POST['dspr_pubcomment'])); - set_pconfig(local_channel(),'system','prevent_tag_hijacking',intval($_POST['dspr_hijack'])); - info( t('Diaspora Policy Settings updated.') . EOL); - } - build_sync_packet(); return; } @@ -318,17 +311,16 @@ function settings_post(&$a) { foreach($global_perms as $k => $v) { $set_perms .= ', ' . $v[0] . ' = ' . intval($_POST[$k]) . ' '; } - - $str_group_allow = perms2str($_POST['group_allow']); - $str_contact_allow = perms2str($_POST['contact_allow']); - $str_group_deny = perms2str($_POST['group_deny']); - $str_contact_deny = perms2str($_POST['contact_deny']); - $r = q("update channel set channel_allow_cid = '%s', channel_allow_gid = '%s', channel_deny_cid = '%s', channel_deny_gid = '%s' - where channel_id = %d", - dbesc($str_contact_allow), - dbesc($str_group_allow), - dbesc($str_contact_deny), - dbesc($str_group_deny), + $acl = new AccessList($channel); + $acl->set_from_array($_POST); + $x = $acl->get(); + + $r = q("update channel set channel_allow_cid = '%s', channel_allow_gid = '%s', + channel_deny_cid = '%s', channel_deny_gid = '%s' where channel_id = %d", + dbesc($x['allow_cid']), + dbesc($x['allow_gid']), + dbesc($x['deny_cid']), + dbesc($x['deny_gid']), intval(local_channel()) ); } @@ -373,10 +365,9 @@ function settings_post(&$a) { ); } - $r = q("update abook set abook_my_perms = %d where abook_channel = %d and (abook_flags & %d)>0", + $r = q("update abook set abook_my_perms = %d where abook_channel = %d and abook_self = 1", intval(($role_permissions['perms_auto']) ? intval($role_permissions['perms_accept']) : 0), - intval(local_channel()), - intval(ABOOK_FLAG_SELF) + intval(local_channel()) ); set_pconfig(local_channel(),'system','autoperms',(($role_permissions['perms_auto']) ? intval($role_permissions['perms_accept']) : 0)); @@ -401,6 +392,8 @@ function settings_post(&$a) { $maxreq = ((x($_POST,'maxreq')) ? intval($_POST['maxreq']) : 0); $expire = ((x($_POST,'expire')) ? intval($_POST['expire']) : 0); $evdays = ((x($_POST,'evdays')) ? intval($_POST['evdays']) : 3); + $photo_path = ((x($_POST,'photo_path')) ? escape_tags(trim($_POST['photo_path'])) : ''); + $attach_path = ((x($_POST,'attach_path')) ? escape_tags(trim($_POST['attach_path'])) : ''); $channel_menu = ((x($_POST['channel_menu'])) ? htmlspecialchars_decode(trim($_POST['channel_menu']),ENT_QUOTES) : ''); @@ -507,6 +500,8 @@ function settings_post(&$a) { set_pconfig(local_channel(),'system','vnotify',$vnotify); set_pconfig(local_channel(),'system','always_show_in_notices',$always_show_in_notices); set_pconfig(local_channel(),'system','evdays',$evdays); + set_pconfig(local_channel(),'system','photo_path',$photo_path); + set_pconfig(local_channel(),'system','attach_path',$attach_path); $r = q("update channel set channel_name = '%s', channel_pageflags = %d, channel_timezone = '%s', channel_location = '%s', channel_notifyflags = %d, channel_max_anon_mail = %d, channel_max_friend_req = %d, channel_expire_days = %d $set_perms where channel_id = %d", dbesc($username), @@ -661,35 +656,17 @@ function settings_content(&$a) { $settings_addons = ""; $o = ''; - $diaspora_enabled = get_config('system','diaspora_enabled'); $r = q("SELECT * FROM `hook` WHERE `hook` = 'feature_settings' "); - if((! $r) && (! $diaspora_enabled)) + if(! $r) $settings_addons = t('No feature settings configured'); - if($diaspora_enabled) { - $dspr_allowed = get_pconfig(local_channel(),'system','diaspora_allowed'); - if($dspr_allowed === false) - $dspr_allowed = 1; - $pubcomments = get_pconfig(local_channel(),'system','diaspora_public_comments'); - if($pubcomments === false) - $pubcomments = 1; - $hijacking = get_pconfig(local_channel(),'system','prevent_tag_hijacking'); - } - call_hooks('feature_settings', $settings_addons); $tpl = get_markup_template("settings_addons.tpl"); $o .= replace_macros($tpl, array( '$form_security_token' => get_form_security_token("settings_featured"), '$title' => t('Feature/Addon Settings'), - '$diaspora_enabled' => $diaspora_enabled, - '$dsprdesc' => t('Settings for the built-in Diaspora emulator'), - '$pubcomments' => array('dspr_pubcomment', t('Allow any Diaspora member to comment on your public posts'), $pubcomments, '', $yes_no), - '$dspr_allowed' => array('dspr_allowed', t('Enable the Diaspora protocol for this channel'), $dspr_allowed, '', $yes_no), - '$dsprtitle' => t('Diaspora Policy Settings'), - '$hijacking' => array('dspr_hijack', t('Prevent your hashtags from being redirected to other sites'), $hijacking, '', $yes_no), - '$dsprsubmit' => t('Submit'), '$settings_addons' => $settings_addons )); return $o; @@ -1005,15 +982,8 @@ function settings_content(&$a) { $stpl = get_markup_template('settings.tpl'); - $celeb = false; - - $perm_defaults = array( - 'allow_cid' => $channel['channel_allow_cid'], - 'allow_gid' => $channel['channel_allow_gid'], - 'deny_cid' => $channel['channel_deny_cid'], - 'deny_gid' => $channel['channel_deny_gid'] - ); - + $acl = new AccessList($channel); + $perm_defaults = $acl->get(); require_once('include/group.php'); $group_select = mini_group_select(local_channel(),$channel['channel_default_group']); @@ -1132,7 +1102,9 @@ function settings_content(&$a) { '$expert' => feature_enabled(local_channel(),'expert'), '$hint' => t('Please enable expert mode (in <a href="settings/features">Settings > Additional features</a>) to adjust!'), '$lbl_misc' => t('Miscellaneous Settings'), - '$menus' => $menu, + '$photo_path' => array('photo_path', t('Default photo upload folder'), get_pconfig(local_channel(),'system','photo_path'), '%Y - current year, %m - current month'), + '$attach_path' => array('attach_path', t('Default file upload folder'), get_pconfig(local_channel(),'system','attach_path'), '%Y - current year, %m - current month'), + '$menus' => $menu, '$menu_desc' => t('Personal menu to display in your channel pages'), '$removeme' => t('Remove Channel'), '$removechannel' => t('Remove this channel.'), diff --git a/mod/setup.php b/mod/setup.php index bba29921e..15820f14e 100755 --- a/mod/setup.php +++ b/mod/setup.php @@ -68,6 +68,10 @@ function setup_post(&$a) { $adminmail = trim($_POST['adminmail']); $siteurl = trim($_POST['siteurl']); + // $siteurl should not have a trailing slash + + $siteurl = rtrim($siteurl,'/'); + require_once('include/dba/dba_driver.php'); unset($db); $db = dba_factory($dbhost, $dbport, $dbuser, $dbpass, $dbdata, $dbtype, true); diff --git a/mod/siteinfo.php b/mod/siteinfo.php index c5a1cf12b..14aaef144 100644 --- a/mod/siteinfo.php +++ b/mod/siteinfo.php @@ -84,7 +84,6 @@ function siteinfo_init(&$a) { 'register_policy' => $register_policy[$a->config['system']['register_policy']], 'directory_mode' => $directory_mode[$a->config['system']['directory_mode']], 'language' => get_config('system','language'), - 'diaspora_emulation' => get_config('system','diaspora_enabled'), 'rss_connections' => get_config('system','feed_contacts'), 'expiration' => $site_expire, 'default_service_restrictions' => $service_class, @@ -151,6 +150,9 @@ function siteinfo_content(&$a) { if(file_exists('doc/site_donate.html')) $donate .= file_get_contents('doc/site_donate.html'); + if(function_exists('sys_getloadavg')) + $loadavg = sys_getloadavg(); + $o = replace_macros(get_markup_template('siteinfo.tpl'), array( '$title' => t('$Projectname'), '$description' => t('This is a hub of $Projectname - a global cooperative network of decentralized privacy enhanced websites.'), @@ -159,11 +161,13 @@ function siteinfo_content(&$a) { '$tag' => $tag, '$polled' => t('Last background fetch: '), '$lastpoll' => get_poller_runtime(), + '$load_average' => t('Current load average: '), + '$loadavg_all' => $loadavg[0] . ', ' . $loadavg[1] . ', ' . $loadavg[2], '$commit' => $commit, '$web_location' => t('Running at web location') . ' ' . z_root(), '$visit' => t('Please visit <a href="https://redmatrix.me">redmatrix.me</a> to learn more about $Projectname.'), '$bug_text' => t('Bug reports and issues: please visit'), - '$bug_link_url' => 'https://github.com/redmatrix/redmatrix/issues', + '$bug_link_url' => 'https://github.com/redmatrix/hubzilla/issues', '$bug_link_text' => t('$projectname issues'), '$contact' => t('Suggestions, praise, etc. - please email "redmatrix" at librelist - dot com'), '$donate' => $donate, diff --git a/mod/starred.php b/mod/starred.php index b6736fd85..103e5f4b4 100644 --- a/mod/starred.php +++ b/mod/starred.php @@ -19,15 +19,15 @@ function starred_init(&$a) { if(! count($r)) killme(); - $item_flags = ( $r[0]['item_flags'] ^ ITEM_STARRED ); + $item_starred = (intval($r[0]['item_starred']) ? 0 : 1); - $r = q("UPDATE item SET item_flags = %d WHERE uid = %d and id = %d", - intval($item_flags), + $r = q("UPDATE item SET item_starred = %d WHERE uid = %d and id = %d", + intval($item_starred), intval(local_channel()), intval($message_id) ); header('Content-type: application/json'); - echo json_encode(array('result' => (($item_flags & ITEM_STARRED) ? 1 : 0))); + echo json_encode(array('result' => $item_starred)); killme(); } diff --git a/mod/subthread.php b/mod/subthread.php index eeb8f131d..9cfe5c24d 100755 --- a/mod/subthread.php +++ b/mod/subthread.php @@ -96,30 +96,28 @@ function subthread_content(&$a) { ), )); - if(! ($item['item_flags'] & ITEM_THREAD_TOP)) + if(! intval($item['item_thread_top'])) $post_type = 'comment'; - $bodyverb = t('%1$s is following %2$s\'s %3$s'); - $item_flags = ITEM_ORIGIN | ITEM_NOTSHOWN; - if($item['item_flags'] & ITEM_WALL) - $item_flags |= ITEM_WALL; - - $arr = array(); - $arr['mid'] = $mid; - $arr['aid'] = $owner_aid; - $arr['uid'] = $owner_uid; - $arr['item_flags'] = $item_flags; - $arr['parent'] = $item['id']; - $arr['parent_mid'] = $item['mid']; - $arr['thr_parent'] = $item['mid']; - $arr['owner_xchan'] = $thread_owner['xchan_hash']; - $arr['author_xchan'] = $observer['xchan_hash']; + $arr['mid'] = $mid; + $arr['aid'] = $owner_aid; + $arr['uid'] = $owner_uid; + $arr['parent'] = $item['id']; + $arr['parent_mid'] = $item['mid']; + $arr['thr_parent'] = $item['mid']; + $arr['owner_xchan'] = $thread_owner['xchan_hash']; + $arr['author_xchan'] = $observer['xchan_hash']; + $arr['item_origin'] = 1; + $arr['item_notshown'] = 1; + if(intval($item['item_wall'])) + $arr['item_wall'] = 1; + else + $arr['item_wall'] = 0; - $ulink = '[zrl=' . $item_author['xchan_url'] . ']' . $item_author['xchan_name'] . '[/zrl]'; $alink = '[zrl=' . $observer['xchan_url'] . ']' . $observer['xchan_name'] . '[/zrl]'; $plink = '[zrl=' . $a->get_baseurl() . '/display/' . $item['mid'] . ']' . $post_type . '[/zrl]'; diff --git a/mod/tagger.php b/mod/tagger.php index f411bd6d5..9f9855ed8 100644 --- a/mod/tagger.php +++ b/mod/tagger.php @@ -107,11 +107,9 @@ function tagger_content(&$a) { $arr['owner_xchan'] = $item['owner_xchan']; $arr['author_xchan'] = $channel['channel_hash']; + $arr['item_origin'] = 1; + $arr['item_wall'] = ((intval($item['item_wall'])) ? 1 : 0); - $arr['item_flags'] = ITEM_ORIGIN; - if($item['item_flags'] & ITEM_WALL) - $arr['item_flags'] |= ITEM_WALL; - $ulink = '[zrl=' . $channel['xchan_url'] . ']' . $channel['channel_name'] . '[/zrl]'; $alink = '[zrl=' . $item['xchan_url'] . ']' . $item['xchan_name'] . '[/zrl]'; $plink = '[zrl=' . $item['plink'] . ']' . $post_type . '[/zrl]'; diff --git a/mod/tasks.php b/mod/tasks.php new file mode 100644 index 000000000..ed267cc92 --- /dev/null +++ b/mod/tasks.php @@ -0,0 +1,107 @@ +<?php + +require_once('include/event.php'); + + +function tasks_init(&$a) { + + +// logger('request: ' . print_r($_REQUEST,true)); + + $arr = array(); + + if(argc() > 1 && argv(1) === 'fetch') { + if(argc() > 2 && argv(2) === 'all') + $arr['all'] = 1; + + $x = tasks_fetch($arr); + if($x['tasks']) { + $x['html'] = ''; + foreach($x['tasks'] as $y) { + $x['html'] .= '<div class="tasklist-item"><input type="checkbox" onchange="taskComplete(' . $y['id'] . '); return false;" /> ' . $y['summary'] . '</div>'; + } + } + json_return_and_die($x); + } + +} + + + +function tasks_post(&$a) { + + +// logger('post: ' . print_r($_POST,true)); + + + if(! local_channel()) + return; + + $channel = $a->get_channel(); + + if((argc() > 2) && (argv(1) === 'complete') && intval(argv(2))) { + $ret = array('success' => false); + $r = q("select * from event where `type` = 'task' and uid = %d and id = %d limit 1", + intval(local_channel()), + intval(argv(2)) + ); + if($r) { + $event = $r[0]; + if($event['event_status'] === 'COMPLETED') { + $event['event_status'] = 'IN-PROCESS'; + $event['event_status_date'] = NULL_DATE; + $event['event_percent'] = 0; + $event['event_sequence'] = $event['event_sequence'] + 1; + $event['edited'] = datetime_convert(); + } + else { + $event['event_status'] = 'COMPLETED'; + $event['event_status_date'] = datetime_convert(); + $event['event_percent'] = 100; + $event['event_sequence'] = $event['event_sequence'] + 1; + $event['edited'] = datetime_convert(); + } + $x = event_store_event($event); + if($x) + $ret['success'] = true; + } + json_return_and_die($ret); + } + + if(argc() == 2 && argv(1) === 'new') { + $text = escape_tags(trim($_REQUEST['summary'])); + if(! $text) + return array('success' => false); + $event = array(); + $event['aid'] = $channel['channel_account_id']; + $event['uid'] = $channel['channel_id']; + $event['event_xchan'] = $channel['channel_hash']; + $event['type'] = 'task'; + $event['nofinish'] = true; + $event['created'] = $event['edited'] = $event['start'] = datetime_convert(); + $event['adjust'] = 1; + $event['allow_cid'] = '<' . $channel['channel_hash'] . '>'; + $event['summary'] = escape_tags($_REQUEST['summary']); + $x = event_store_event($event); + if($x) + $x['success'] = true; + else + $x = array('success' => false); + json_return_and_die($x); + } + + +} + + + + + +function tasks_content(&$a) { + + if(! local_channel()) + return; + + + return ''; +}
\ No newline at end of file diff --git a/mod/thing.php b/mod/thing.php index 842832d16..280cc194d 100644 --- a/mod/thing.php +++ b/mod/thing.php @@ -5,8 +5,9 @@ */ require_once('include/items.php'); +require_once('include/security.php'); require_once('include/contact_selectors.php'); - +require_once('include/acl_selectors.php'); function thing_init(&$a) { @@ -65,46 +66,57 @@ function thing_init(&$a) { if((! $name) || (! $translated_verb)) return; + $acl = new AccessList($channel); + + if(array_key_exists('contact_allow',$_REQUEST) + || array_key_exists('group_allow',$_REQUEST) + || array_key_exists('contact_deny',$_REQUEST) + || array_key_exists('group_deny',$_REQUEST)) { + $acl->set_from_array($_REQUEST); + } + + $x = $acl->get(); + if($term_hash) { - $t = q("select * from obj left join term on obj_obj = term_hash where term_hash != '' and obj_type = %d and term_hash = '%s' limit 1", - intval(TERM_OBJ_THING), - dbesc($term_hash) + $t = q("select * from obj where obj_obj = '%s' and obj_channel = %d limit 1", + dbesc($term_hash), + intval(local_channel()) ); if(! $t) { notice( t('Item not found.') . EOL); return; } $orig_record = $t[0]; - if($photo != $orig_record['imgurl']) { - $arr = import_profile_photo($photo,get_observer_hash(),true); + if($photo != $orig_record['obj_imgurl']) { + $arr = import_xchan_photo($photo,get_observer_hash(),true); $local_photo = $arr[0]; $local_photo_type = $arr[3]; } else - $local_photo = $orig_record['imgurl']; + $local_photo = $orig_record['obj_imgurl']; - $r = q("update term set term = '%s', url = '%s', imgurl = '%s' where term_hash = '%s' and uid = %d", + $r = q("update obj set obj_term = '%s', obj_url = '%s', obj_imgurl = '%s', obj_edited = '%s', allow_cid = '%s', allow_gid = '%s', deny_cid = '%s', deny_gid = '%s' where obj_obj = '%s' and obj_channel = %d ", dbesc($name), dbesc(($url) ? $url : z_root() . '/thing/' . $term_hash), dbesc($local_photo), + dbesc(datetime_convert()), + dbesc($x['allow_cid']), + dbesc($x['allow_gid']), + dbesc($x['deny_cid']), + dbesc($x['deny_gid']), dbesc($term_hash), intval(local_channel()) ); info( t('Thing updated') . EOL); - $datestamp = datetime_convert(); - - $r = q("select obj.*, term.term as obj_term, term.url as obj_url, term.imgurl as obj_imgurl, '%s' as obj_created, '%s' as obj_edited, '%s' as obj_baseurl from obj left join term on obj_obj = term.term_hash where obj_channel = %d and term.term_hash = '%s'", - dbesc($datestamp), - dbesc($datestamp), - dbesc(z_root()), + $r = q("select * from obj where obj_channel = %d and obj_obj = '%s' limit 1", intval(local_channel()), dbesc($term_hash) ); - - if($r) - build_sync_packet(0,array('obj' => $r)); + if($r) { + build_sync_packet(0, array('obj' => $r)); + } return; } @@ -122,45 +134,29 @@ function thing_init(&$a) { $local_photo = null; if($photo) { - $arr = import_profile_photo($photo,get_observer_hash(),true); + $arr = import_xchan_photo($photo,get_observer_hash(),true); $local_photo = $arr[0]; $local_photo_type = $arr[3]; } - $r = q("select * from term where uid = %d and otype = %d and type = %d and term = '%s' limit 1", - intval(local_channel()), - intval(TERM_OBJ_THING), - intval(TERM_THING), - dbesc($name) - ); - if(! $r) { - $r = q("insert into term ( aid, uid, oid, otype, type, term, url, imgurl, term_hash ) - values( %d, %d, %d, %d, %d, '%s', '%s', '%s', '%s' ) ", - intval($account_id), - intval(local_channel()), - 0, - intval(TERM_OBJ_THING), - intval(TERM_THING), - dbesc($name), - dbesc(($url) ? $url : z_root() . '/thing/' . $hash), - dbesc(($photo) ? $local_photo : ''), - dbesc($hash) - ); - $r = q("select * from term where uid = %d and otype = %d and type = %d and term = '%s' limit 1", - intval(local_channel()), - intval(TERM_OBJ_THING), - intval(TERM_THING), - dbesc($name) - ); - } - $term = $r[0]; + $created = datetime_convert(); + $url = (($url) ? $url : z_root() . '/thing/' . $hash); - $r = q("insert into obj ( obj_page, obj_verb, obj_type, obj_channel, obj_obj) values ('%s','%s', %d, %d, '%s') ", + $r = q("insert into obj ( obj_page, obj_verb, obj_type, obj_channel, obj_obj, obj_term, obj_url, obj_imgurl, obj_created, obj_edited, allow_cid, allow_gid, deny_cid, deny_gid ) values ('%s','%s', %d, %d, '%s','%s','%s','%s','%s','%s','%s','%s','%s','%s') ", dbesc($profile['profile_guid']), dbesc($verb), intval(TERM_OBJ_THING), intval(local_channel()), - dbesc($term['term_hash']) + dbesc($hash), + dbesc($name), + dbesc($url), + dbesc(($photo) ? $local_photo : ''), + dbesc($created), + dbesc($created), + dbesc($x['allow_cid']), + dbesc($x['allow_gid']), + dbesc($x['deny_cid']), + dbesc($x['deny_gid']) ); if(! $r) { @@ -169,24 +165,18 @@ function thing_init(&$a) { } info( t('Thing added')); - - $datestamp = datetime_convert(); - - $r = q("select obj.*, term.term as obj_term, term.url as obj_url, term.imgurl as obj_imgurl, '%s' as obj_created, '%s' as obj_edited, '%s' as obj_baseurl from obj left join term on obj_obj = term.term_hash where obj_channel = %d and term.term_hash = '%s' ", - dbesc($datestamp), - dbesc($datestamp), - dbesc(z_root()), + + $r = q("select * from obj where obj_channel = %d and obj_obj = '%s' limit 1", intval(local_channel()), - dbesc($term['term_hash']) + dbesc($hash) ); - - if($r) - build_sync_packet(0,array('obj' => $r)); - + if($r) { + build_sync_packet(0, array('obj' => $r)); + } if($activity) { $arr = array(); - $links = array(array('rel' => 'alternate','type' => 'text/html', 'href' => $term['url'])); + $links = array(array('rel' => 'alternate','type' => 'text/html', 'href' => $url)); if($local_photo) $links[] = array('rel' => 'photo', 'type' => $local_photo_type, 'href' => $local_photo); @@ -194,10 +184,10 @@ function thing_init(&$a) { $obj = json_encode(array( 'type' => $objtype, - 'id' => $term['url'], + 'id' => $url, 'link' => $links, - 'title' => $term['term'], - 'content' => $term['term'] + 'title' => $name, + 'content' => $name )); $bodyverb = str_replace('OBJ: ', '',t('OBJ: %1$s %2$s %3$s')); @@ -205,10 +195,12 @@ function thing_init(&$a) { $arr['owner_xchan'] = $channel['channel_hash']; $arr['author_xchan'] = $channel['channel_hash']; - $arr['item_flags'] = ITEM_ORIGIN|ITEM_WALL|ITEM_THREAD_TOP; + $arr['item_origin'] = 1; + $arr['item_wall'] = 1; + $arr['item_thread_top'] = 1; $ulink = '[zrl=' . $channel['xchan_url'] . ']' . $channel['channel_name'] . '[/zrl]'; - $plink = '[zrl=' . $term['url'] . ']' . $term['term'] . '[/zrl]'; + $plink = '[zrl=' . $url . ']' . $name . '[/zrl]'; $arr['body'] = sprintf( $bodyverb, $ulink, $translated_verb, $plink ); @@ -242,9 +234,19 @@ function thing_init(&$a) { function thing_content(&$a) { + // @FIXME one problem with things is we can't share them unless we provide the channel in the url + // so we can definitively lookup the owner. + if(argc() == 2) { - $r = q("select * from obj left join term on obj_obj = term_hash where term_hash != '' and obj_type = %d and term_hash = '%s' limit 1", + $r = q("select obj_channel from obj where obj_type = %d and obj_obj = '%s' limit 1", + intval(TERM_OBJ_THING), + dbesc(argv(1)) + ); + if($r) + $sql_extra = permissions_sql($r[0]['obj_channel']); + + $r = q("select * from obj where obj_type = %d and obj_obj = '%s' $sql_extra limit 1", intval(TERM_OBJ_THING), dbesc(argv(1)) ); @@ -270,12 +272,17 @@ function thing_content(&$a) { return; } + $acl = new AccessList($channel); + $channel_acl = $acl->get(); + + $lockstate = (($acl->is_private()) ? 'lock' : 'unlock'); + $thing_hash = ''; if(argc() == 3 && argv(1) === 'edit') { $thing_hash = argv(2); - $r = q("select * from obj left join term on obj_obj = term_hash where term_hash != '' and obj_type = %d and term_hash = '%s' limit 1", + $r = q("select * from obj where obj_type = %d and obj_obj = '%s' limit 1", intval(TERM_OBJ_THING), dbesc($thing_hash) ); @@ -295,11 +302,14 @@ function thing_content(&$a) { '$activity' => array('activity',t('Post an activity'),true,t('Only sends to viewers of the applicable profile')), '$thing_hash' => $thing_hash, '$thing_lbl' => t('Name of thing e.g. something'), - '$thething' => $r[0]['term'], + '$thething' => $r[0]['obj_term'], '$url_lbl' => t('URL of thing (optional)'), - '$theurl' => $r[0]['url'], + '$theurl' => $r[0]['obj_url'], '$img_lbl' => t('URL for photo of thing (optional)'), - '$imgurl' => $r[0]['imgurl'], + '$imgurl' => $r[0]['obj_imgurl'], + '$permissions' => t('Permissions'), + '$aclselect' => populate_acl($channel_acl,false), + '$lockstate' => $lockstate, '$submit' => t('Submit') )); @@ -309,7 +319,7 @@ function thing_content(&$a) { if(argc() == 3 && argv(1) === 'drop') { $thing_hash = argv(2); - $r = q("select * from obj left join term on obj_obj = term_hash where term_hash != '' and obj_type = %d and term_hash = '%s' limit 1", + $r = q("select * from obj where obj_type = %d and obj_obj = '%s' limit 1", intval(TERM_OBJ_THING), dbesc($thing_hash) ); @@ -324,10 +334,10 @@ function thing_content(&$a) { intval(TERM_OBJ_THING), intval(local_channel()) ); - $x = q("delete from term where term_hash = '%s' and uid = %d", - dbesc($thing_hash), - intval(local_channel()) - ); + + $r[0]['obj_deleted'] = 1; + + build_sync_packet(0,array('obj' => $r)); return $o; } @@ -343,6 +353,9 @@ function thing_content(&$a) { '$thing_lbl' => t('Name of thing e.g. something'), '$url_lbl' => t('URL of thing (optional)'), '$img_lbl' => t('URL for photo of thing (optional)'), + '$permissions' => t('Permissions'), + '$aclselect' => populate_acl($channel_acl,false), + '$lockstate' => $lockstate, '$submit' => t('Submit') )); diff --git a/mod/uexport.php b/mod/uexport.php index fbbe9953b..df66474f1 100644 --- a/mod/uexport.php +++ b/mod/uexport.php @@ -46,7 +46,9 @@ function uexport_content(&$a) { '$basictitle' => t('Export Channel'), '$basic' => t('Export your basic channel information to a small file. This acts as a backup of your connections, permissions, profile and basic data, which can be used to import your data to a new hub, but does not contain your content.'), '$fulltitle' => t('Export Content'), - '$full' => t('Export your channel information and all the content to a JSON backup. This backs up all of your connections, permissions, profile data and all of your content, but is generally not suitable for importing a channel to a new hub as this file may be VERY large. Please be patient - it may take several minutes for this download to begin.') + '$full' => t('Export your channel information and all the content to a JSON backup. This backs up all of your connections, permissions, profile data and the last year of posts. This file may be VERY large. Please be patient - it may take several minutes for this download to begin.'), + '$by_year' => t('Export your posts from a given year.'), + )); return $o; } diff --git a/mod/update_channel.php b/mod/update_channel.php index bdde0a3be..5f4436d59 100644 --- a/mod/update_channel.php +++ b/mod/update_channel.php @@ -37,7 +37,7 @@ function update_channel_content(&$a) { $pattern = "/<img([^>]*) src=\"([^\"]*)\"/"; $replace = "<img\${1} dst=\"\${2}\""; - $text = preg_replace($pattern, $replace, $text); +// $text = preg_replace($pattern, $replace, $text); if(! $load) { $replace = '<br />' . t('[Embedded content - reload page to view]') . '<br />'; diff --git a/mod/update_display.php b/mod/update_display.php index 5802852bb..d41e2e5cb 100644 --- a/mod/update_display.php +++ b/mod/update_display.php @@ -19,7 +19,7 @@ function update_display_content(&$a) { $text = display_content($a,$profile_uid, $load); $pattern = "/<img([^>]*) src=\"([^\"]*)\"/"; $replace = "<img\${1} dst=\"\${2}\""; - $text = preg_replace($pattern, $replace, $text); +// $text = preg_replace($pattern, $replace, $text); if(! $load) { $replace = '<br />' . t('[Embedded content - reload page to view]') . '<br />'; diff --git a/mod/update_home.php b/mod/update_home.php index c139682e1..80ae2438f 100644 --- a/mod/update_home.php +++ b/mod/update_home.php @@ -15,7 +15,7 @@ function update_home_content(&$a) { $text = home_content($a,$profile_uid, $load); $pattern = "/<img([^>]*) src=\"([^\"]*)\"/"; $replace = "<img\${1} dst=\"\${2}\""; - $text = preg_replace($pattern, $replace, $text); +// $text = preg_replace($pattern, $replace, $text); if(! $load) { $replace = '<br />' . t('[Embedded content - reload page to view]') . '<br />'; diff --git a/mod/update_network.php b/mod/update_network.php index 0021af876..acd5ccdc8 100644 --- a/mod/update_network.php +++ b/mod/update_network.php @@ -17,7 +17,7 @@ function update_network_content(&$a) { $text = network_content($a,$profile_uid, $load); $pattern = "/<img([^>]*) src=\"([^\"]*)\"/"; $replace = "<img\${1} dst=\"\${2}\""; - $text = preg_replace($pattern, $replace, $text); +// $text = preg_replace($pattern, $replace, $text); if(! $load) { $replace = '<br />' . t('[Embedded content - reload page to view]') . '<br />'; diff --git a/mod/update_public.php b/mod/update_public.php index d0a08e0e6..bac1ccf15 100644 --- a/mod/update_public.php +++ b/mod/update_public.php @@ -15,7 +15,7 @@ function update_public_content(&$a) { $text = public_content($a,$profile_uid, $load); $pattern = "/<img([^>]*) src=\"([^\"]*)\"/"; $replace = "<img\${1} dst=\"\${2}\""; - $text = preg_replace($pattern, $replace, $text); +// $text = preg_replace($pattern, $replace, $text); if(! $load) { $replace = '<br />' . t('[Embedded content - reload page to view]') . '<br />'; diff --git a/mod/update_search.php b/mod/update_search.php index ec7599b79..de29e89bd 100644 --- a/mod/update_search.php +++ b/mod/update_search.php @@ -40,7 +40,7 @@ function update_search_content(&$a) { $pattern = "/<img([^>]*) src=\"([^\"]*)\"/"; $replace = "<img\${1} dst=\"\${2}\""; - $text = preg_replace($pattern, $replace, $text); +// $text = preg_replace($pattern, $replace, $text); if(! $load) { $replace = '<br />' . t('[Embedded content - reload page to view]') . '<br />'; diff --git a/mod/viewconnections.php b/mod/viewconnections.php index ef6681e64..d9a9aecc1 100644 --- a/mod/viewconnections.php +++ b/mod/viewconnections.php @@ -34,26 +34,23 @@ function viewconnections_content(&$a) { $is_owner = ((local_channel() && local_channel() == $a->profile['uid']) ? true : false); - $abook_flags = ABOOK_FLAG_PENDING|ABOOK_FLAG_SELF; - $xchan_flags = XCHAN_FLAGS_ORPHAN|XCHAN_FLAGS_DELETED; + $abook_flags = " and abook_pending = 0 and abook_self = 0 "; + $sql_extra = ''; + if(! $is_owner) { - $abook_flags = $abook_flags | ABOOK_FLAG_HIDDEN; - $xchan_flags = $xchan_flags | XCHAN_FLAGS_HIDDEN; + $abook_flags = " and abook_hidden = 0 "; + $sql_extra = " and xchan_hidden = 0 "; } - $r = q("SELECT count(*) as total FROM abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d and not (abook_flags & %d )>0 and not ( xchan_flags & %d )>0 ", - intval($a->profile['uid']), - intval($abook_flags), - intval($xchan_flags) + $r = q("SELECT count(*) as total FROM abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d $abook_flags and xchan_orphan = 0 and xchan_deleted = 0 $sql_extra ", + intval($a->profile['uid']) ); if($r) { $a->set_pager_total($r[0]['total']); } - $r = q("SELECT * FROM abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d and not ( abook_flags & %d )>0 and not ( xchan_flags & %d )>0 order by xchan_name LIMIT %d OFFSET %d ", + $r = q("SELECT * FROM abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d $abook_flags and xchan_orphan = 0 and xchan_deleted = 0 $sql_extra order by xchan_name LIMIT %d OFFSET %d ", intval($a->profile['uid']), - intval($abook_flags), - intval($xchan_flags), intval($a->pager['itemspage']), intval($a->pager['start']) ); @@ -71,7 +68,7 @@ function viewconnections_content(&$a) { if($url) { $contacts[] = array( 'id' => $rr['abook_id'], - 'archived' => (($rr['abook_flags'] & ABOOK_FLAG_ARCHIVED) ? true : false), + 'archived' => (intval($rr['abook_archived']) ? true : false), 'img_hover' => sprintf( t('Visit %s\'s profile [%s]'), $rr['xchan_name'], $rr['xchan_url']), 'thumb' => $rr['xchan_photo_m'], 'name' => substr($rr['xchan_name'],0,20), diff --git a/mod/viewsrc.php b/mod/viewsrc.php index 3125ae4c0..cffb01b6e 100644 --- a/mod/viewsrc.php +++ b/mod/viewsrc.php @@ -20,15 +20,17 @@ function viewsrc_content(&$a) { notice( t('Item not found.') . EOL); } + $item_normal = item_normal(); + if(local_channel() && $item_id) { - $r = q("select item_flags, body, id from item where item_restrict = 0 and uid in (%d , %d) and id = %d limit 1", + $r = q("select id, item_flags, item_obscured, body from item where uid in (%d , %d) and id = %d $item_normal limit 1", intval(local_channel()), intval($sys['channel_id']), intval($item_id) ); if($r) { - if($r[0]['item_flags'] & ITEM_OBSCURED) + if(intval($r[0]['item_obscured'])) $r[0]['body'] = crypto_unencapsulate(json_decode($r[0]['body'],true),get_config('system','prvkey')); $o = (($json) ? json_encode($r[0]['body']) : str_replace("\n",'<br />',$r[0]['body'])); } diff --git a/mod/wall_attach.php b/mod/wall_attach.php index 4b7103802..8677c2b83 100644 --- a/mod/wall_attach.php +++ b/mod/wall_attach.php @@ -21,30 +21,39 @@ function wall_attach_post(&$a) { $observer = $a->get_observer(); - if($_FILES['userfile']['tmp_name']) { - $x = @getimagesize($_FILES['userfile']['tmp_name']); - logger('getimagesize: ' . print_r($x,true), LOGGER_DATA); - if(($x) && ($x[2] === IMAGETYPE_GIF || $x[2] === IMAGETYPE_JPEG || $x[2] === IMAGETYPE_PNG)) { - $args = array( 'source' => 'editor', 'visible' => 0, 'contact_allow' => array($channel['channel_hash'])); - $ret = photo_upload($channel,$observer,$args); - if($ret['success']) { - echo "\n\n" . $ret['body'] . "\n\n"; - killme(); - } - if($using_api) - return; - notice($ret['message']); - killme(); - } - } - - $r = attach_store($channel,(($observer) ? $observer['xchan_hash'] : '')); +// if($_FILES['userfile']['tmp_name']) { +// $x = @getimagesize($_FILES['userfile']['tmp_name']); +// logger('getimagesize: ' . print_r($x,true), LOGGER_DATA); +// if(($x) && ($x[2] === IMAGETYPE_GIF || $x[2] === IMAGETYPE_JPEG || $x[2] === IMAGETYPE_PNG)) { +// $args = array( 'source' => 'editor', 'visible' => 0, 'contact_allow' => array($channel['channel_hash'])); +// $ret = photo_upload($channel,$observer,$args); +// if($ret['success']) { +// echo "\n\n" . $ret['body'] . "\n\n"; +// killme(); +// } +// if($using_api) +// return; +// notice($ret['message']); +// killme(); +// } +// } + + $def_album = get_pconfig($channel['channel_id'],'system','photo_path'); + $def_attach = get_pconfig($channel['channel_id'],'system','attach_path'); + + $r = attach_store($channel,(($observer) ? $observer['xchan_hash'] : ''),'', array('source' => 'editor', 'visible' => 0, 'album' => $def_album, 'directory' => $def_attach, 'allow_cid' => '<' . $channel['channel_hash'] . '>')); if(! $r['success']) { notice( $r['message'] . EOL); killme(); } + if(intval($r['data']['is_photo'])) { + echo "\n\n" . $r['body'] . "\n\n"; + if($using_api) + return; + killme(); + } echo "\n\n" . '[attachment]' . $r['data']['hash'] . ',' . $r['data']['revision'] . '[/attachment]' . "\n"; killme(); diff --git a/mod/webfinger.php b/mod/webfinger.php index a646961a8..74bfc3ce5 100644 --- a/mod/webfinger.php +++ b/mod/webfinger.php @@ -15,7 +15,7 @@ function webfinger_content(&$a) { if(x($_GET,'addr')) { $addr = trim($_GET['addr']); if(strpos($addr,'@') !== false) { - $res = webfinger_rfc7033($addr); + $res = webfinger_rfc7033($addr,true); if(! $res) $res = old_webfinger($addr); } diff --git a/mod/webpages.php b/mod/webpages.php index 362f7bacb..8e12b5910 100644 --- a/mod/webpages.php +++ b/mod/webpages.php @@ -102,7 +102,7 @@ function webpages_content(&$a) { $o = profile_tabs($a, $is_owner, $a->profile['channel_address']); $x = array( - 'webpage' => ITEM_WEBPAGE, + 'webpage' => ITEM_TYPE_WEBPAGE, 'is_owner' => true, 'nickname' => $a->profile['channel_address'], 'lockstate' => (($channel['channel_allow_cid'] || $channel['channel_allow_gid'] || $channel['channel_deny_cid'] || $channel['channel_deny_gid']) ? 'lock' : 'unlock'), @@ -133,9 +133,9 @@ function webpages_content(&$a) { $sql_extra = item_permissions_sql($owner); $r = q("select * from item_id left join item on item_id.iid = item.id - where item_id.uid = %d and service = 'WEBPAGE' and item_restrict = %d $sql_extra order by item.created desc", + where item_id.uid = %d and service = 'WEBPAGE' and item_type = %d $sql_extra order by item.created desc", intval($owner), - intval(ITEM_WEBPAGE) + intval(ITEM_TYPE_WEBPAGE) ); $pages = null; diff --git a/mod/wfinger.php b/mod/wfinger.php index 1493dd6ba..8b9abe4af 100644 --- a/mod/wfinger.php +++ b/mod/wfinger.php @@ -1,5 +1,7 @@ <?php +require_once('include/zot.php'); + function wfinger_init(&$a) { $result = array(); @@ -11,15 +13,16 @@ function wfinger_init(&$a) { elseif(x($_SERVER,'SERVER_PORT') && (intval($_SERVER['SERVER_PORT']) == 443)) $scheme = 'https'; - // Don't complain to me - I'm just implementing the spec. + $zot = intval($_REQUEST['zot']); - if($scheme !== 'https') { + if(($scheme !== 'https') && (! $zot)) { header($_SERVER["SERVER_PROTOCOL"] . ' ' . 500 . ' ' . 'Webfinger requires HTTPS'); killme(); } - $resource = $_REQUEST['resource']; + $resource = $_REQUEST['resource']; + logger('webfinger: ' . $resource,LOGGER_DEBUG); $r = null; @@ -30,7 +33,7 @@ function wfinger_init(&$a) { if(strpos($channel,'@') !== false) { $host = substr($channel,strpos($channel,'@')+1); if(strcasecmp($host,get_app()->get_hostname())) { - goaway('https://' . $host . '/.well-known/webfinger?resource=' . $resource); + goaway('https://' . $host . '/.well-known/webfinger?f=&resource=' . $resource . (($zot) ? '&zot=' . $zot : '')); } $channel = substr($channel,0,strpos($channel,'@')); } @@ -46,16 +49,14 @@ function wfinger_init(&$a) { } - header('Access-Control-Allow-Origin: *'); header('Content-type: application/jrd+json'); - if($resource && $r) { - $h = q("select hubloc_addr from hubloc where hubloc_hash = '%s'", + $h = q("select hubloc_addr from hubloc where hubloc_hash = '%s' and hubloc_deleted = 0", dbesc($r[0]['channel_hash']) ); @@ -105,6 +106,10 @@ function wfinger_init(&$a) { ) ); + if($zot) { + // get a zotinfo packet and return it with webfinger + $result['zot'] = zotinfo(array('address' => $r[0]['xchan_addr'])); + } } else { header($_SERVER["SERVER_PROTOCOL"] . ' ' . 400 . ' ' . 'Bad Request'); diff --git a/mod/xrd.php b/mod/xrd.php index 4fa81c7f3..a373f8bf5 100644 --- a/mod/xrd.php +++ b/mod/xrd.php @@ -5,6 +5,7 @@ require_once('include/crypto.php'); function xrd_init(&$a) { $uri = urldecode(notags(trim($_GET['uri']))); + logger('xrd: ' . $uri,LOGGER_DEBUG); if(substr($uri,0,4) === 'http') $name = basename($uri); @@ -24,14 +25,14 @@ function xrd_init(&$a) { $dspr = replace_macros(get_markup_template('xrd_diaspora.tpl'),array( '$baseurl' => $a->get_baseurl(), - '$dspr_guid' => $r[0]['channel_guid'], + '$dspr_guid' => $r[0]['channel_guid'] . str_replace('.','',$a->get_hostname()), '$dspr_key' => base64_encode(pemtorsa($r[0]['channel_pubkey'])) )); $salmon_key = salmon_key($r[0]['channel_pubkey']); header('Access-Control-Allow-Origin: *'); - header("Content-type: text/xml"); + header("Content-type: application/xrd+xml"); $tpl = get_markup_template('view/xrd_person.tpl'); diff --git a/mod/zfinger.php b/mod/zfinger.php index 6b93b3410..fb3333280 100644 --- a/mod/zfinger.php +++ b/mod/zfinger.php @@ -5,302 +5,9 @@ function zfinger_init(&$a) { require_once('include/zot.php'); require_once('include/crypto.php'); - $ret = array('success' => false); - $zhash = ((x($_REQUEST,'guid_hash')) ? $_REQUEST['guid_hash'] : ''); - $zguid = ((x($_REQUEST,'guid')) ? $_REQUEST['guid'] : ''); - $zguid_sig = ((x($_REQUEST,'guid_sig')) ? $_REQUEST['guid_sig'] : ''); - $zaddr = ((x($_REQUEST,'address')) ? $_REQUEST['address'] : ''); - $ztarget = ((x($_REQUEST,'target')) ? $_REQUEST['target'] : ''); - $zsig = ((x($_REQUEST,'target_sig')) ? $_REQUEST['target_sig'] : ''); - $zkey = ((x($_REQUEST,'key')) ? $_REQUEST['key'] : ''); - $mindate = ((x($_REQUEST,'mindate')) ? $_REQUEST['mindate'] : ''); - $feed = ((x($_REQUEST,'feed')) ? intval($_REQUEST['feed']) : 0); + $x = zotinfo($_REQUEST); + json_return_and_die($x); - if($ztarget) { - if((! $zkey) || (! $zsig) || (! rsa_verify($ztarget,base64url_decode($zsig),$zkey))) { - logger('zfinger: invalid target signature'); - $ret['message'] = t("invalid target signature"); - json_return_and_die($ret); - } - } - - // allow re-written domains so bob@foo.example.com can provide an address of bob@example.com - // The top-level domain also needs to redirect .well-known/zot-info to the sub-domain with a 301 or 308 - - // TODO: Make 308 work in include/network.php for zot_fetch_url and zot_post_url - - if(($zaddr) && ($s = get_config('system','zotinfo_domainrewrite'))) { - $arr = explode('^',$s); - if(count($arr) == 2) - $zaddr = str_replace($arr[0],$arr[1],$zaddr); - } - - $r = null; - - if(strlen($zhash)) { - $r = q("select channel.*, xchan.* from channel left join xchan on channel_hash = xchan_hash - where channel_hash = '%s' limit 1", - dbesc($zhash) - ); - } - elseif(strlen($zguid) && strlen($zguid_sig)) { - $r = q("select channel.*, xchan.* from channel left join xchan on channel_hash = xchan_hash - where channel_guid = '%s' and channel_guid_sig = '%s' limit 1", - dbesc($zguid), - dbesc($zguid_sig) - ); - } - elseif(strlen($zaddr)) { - if(strpos($zaddr,'[system]') === false) { /* normal address lookup */ - $r = q("select channel.*, xchan.* from channel left join xchan on channel_hash = xchan_hash - where ( channel_address = '%s' or xchan_addr = '%s' ) limit 1", - dbesc($zaddr), - dbesc($zaddr) - ); - } - - else { - - /** - * The special address '[system]' will return a system channel if one has been defined, - * Or the first valid channel we find if there are no system channels. - * - * This is used by magic-auth if we have no prior communications with this site - and - * returns an identity on this site which we can use to create a valid hub record so that - * we can exchange signed messages. The precise identity is irrelevant. It's the hub - * information that we really need at the other end - and this will return it. - * - */ - - $r = q("select channel.*, xchan.* from channel left join xchan on channel_hash = xchan_hash - where ( channel_pageflags & %d )>0 order by channel_id limit 1", - intval(PAGE_SYSTEM) - ); - if(! $r) { - $r = q("select channel.*, xchan.* from channel left join xchan on channel_hash = xchan_hash - where not ( channel_pageflags & %d )>0 order by channel_id limit 1", - intval(PAGE_REMOVED) - ); - } - } - } - else { - $ret['message'] = 'Invalid request'; - json_return_and_die($ret); - } - - if(! $r) { - $ret['message'] = 'Item not found.'; - json_return_and_die($ret); - } - - $e = $r[0]; - - $id = $e['channel_id']; - - $sys_channel = (($e['channel_pageflags'] & PAGE_SYSTEM) ? true : false); - $special_channel = (($e['channel_pageflags'] & PAGE_PREMIUM) ? true : false); - $adult_channel = (($e['channel_pageflags'] & PAGE_ADULT) ? true : false); - $censored = (($e['channel_pageflags'] & PAGE_CENSORED) ? true : false); - $searchable = (($e['channel_pageflags'] & PAGE_HIDDEN) ? false : true); - $deleted = (($e['xchan_flags'] & XCHAN_FLAGS_DELETED) ? true : false); - - if($deleted || $censored || $sys_channel) - $searchable = false; - - $public_forum = false; - - $role = get_pconfig($e['channel_id'],'system','permissions_role'); - if($role === 'forum') { - $public_forum = true; - } - else { - // check if it has characteristics of a public forum based on custom permissions. - $t = q("select abook_my_perms from abook where abook_channel = %d and (abook_flags & %d)>0 limit 1", - intval($e['channel_id']), - intval(ABOOK_FLAG_SELF) - ); - if($t && ($t[0]['abook_my_perms'] & PERMS_W_TAGWALL)) - $public_forum = true; - } - - - // This is for birthdays and keywords, but must check access permissions - $p = q("select * from profile where uid = %d and is_default = 1", - intval($e['channel_id']) - ); - - $profile = array(); - - if($p) { - - if(! intval($p[0]['publish'])) - $searchable = false; - - $profile['description'] = $p[0]['pdesc']; - $profile['birthday'] = $p[0]['dob']; - if(($profile['birthday'] != '0000-00-00') && (($bd = z_birthday($p[0]['dob'],$e['channel_timezone'])) !== '')) - $profile['next_birthday'] = $bd; - - if($age = age($p[0]['dob'],$e['channel_timezone'],'')) - $profile['age'] = $age; - $profile['gender'] = $p[0]['gender']; - $profile['marital'] = $p[0]['marital']; - $profile['sexual'] = $p[0]['sexual']; - $profile['locale'] = $p[0]['locality']; - $profile['region'] = $p[0]['region']; - $profile['postcode'] = $p[0]['postal_code']; - $profile['country'] = $p[0]['country_name']; - $profile['about'] = $p[0]['about']; - $profile['homepage'] = $p[0]['homepage']; - $profile['hometown'] = $p[0]['hometown']; - - if($p[0]['keywords']) { - $tags = array(); - $k = explode(' ',$p[0]['keywords']); - if($k) { - foreach($k as $kk) { - if(trim($kk," \t\n\r\0\x0B,")) { - $tags[] = trim($kk," \t\n\r\0\x0B,"); - } - } - } - if($tags) - $profile['keywords'] = $tags; - } - } - - $ret['success'] = true; - - // Communication details - - $ret['guid'] = $e['xchan_guid']; - $ret['guid_sig'] = $e['xchan_guid_sig']; - $ret['key'] = $e['xchan_pubkey']; - $ret['name'] = $e['xchan_name']; - $ret['name_updated'] = $e['xchan_name_date']; - $ret['address'] = $e['xchan_addr']; - $ret['photo_mimetype'] = $e['xchan_photo_mimetype']; - $ret['photo'] = $e['xchan_photo_l']; - $ret['photo_updated'] = $e['xchan_photo_date']; - $ret['url'] = $e['xchan_url']; - $ret['connections_url']= (($e['xchan_connurl']) ? $e['xchan_connurl'] : z_root() . '/poco/' . $e['channel_address']); - $ret['target'] = $ztarget; - $ret['target_sig'] = $zsig; - $ret['searchable'] = $searchable; - $ret['adult_content'] = $adult_channel; - $ret['public_forum'] = $public_forum; - if($deleted) - $ret['deleted'] = $deleted; - - // premium or other channel desiring some contact with potential followers before connecting. - // This is a template - %s will be replaced with the follow_url we discover for the return channel. - - if($special_channel) - $ret['connect_url'] = z_root() . '/connect/' . $e['channel_address']; - - // This is a template for our follow url, %s will be replaced with a webbie - - $ret['follow_url'] = z_root() . '/follow?f=&url=%s'; - - $ztarget_hash = (($ztarget && $zsig) - ? make_xchan_hash($ztarget,$zsig) - : '' ); - - $permissions = get_all_perms($e['channel_id'],$ztarget_hash,false); - - if($ztarget_hash) { - $permissions['connected'] = false; - $b = q("select * from abook where abook_xchan = '%s' and abook_channel = %d limit 1", - dbesc($ztarget_hash), - intval($e['channel_id']) - ); - if($b) - $permissions['connected'] = true; - } - - $ret['permissions'] = (($ztarget && $zkey) ? crypto_encapsulate(json_encode($permissions),$zkey) : $permissions); - - if($permissions['view_profile']) - $ret['profile'] = $profile; - - // array of (verified) hubs this channel uses - - $x = zot_encode_locations($e); - if($x) - $ret['locations'] = $x; - - $ret['site'] = array(); - $ret['site']['url'] = z_root(); - $ret['site']['url_sig'] = base64url_encode(rsa_sign(z_root(),$e['channel_prvkey'])); - - $dirmode = get_config('system','directory_mode'); - if(($dirmode === false) || ($dirmode == DIRECTORY_MODE_NORMAL)) - $ret['site']['directory_mode'] = 'normal'; - - if($dirmode == DIRECTORY_MODE_PRIMARY) - $ret['site']['directory_mode'] = 'primary'; - elseif($dirmode == DIRECTORY_MODE_SECONDARY) - $ret['site']['directory_mode'] = 'secondary'; - elseif($dirmode == DIRECTORY_MODE_STANDALONE) - $ret['site']['directory_mode'] = 'standalone'; - if($dirmode != DIRECTORY_MODE_NORMAL) - $ret['site']['directory_url'] = z_root() . '/dirsearch'; - - - // hide detailed site information if you're off the grid - - if($dirmode != DIRECTORY_MODE_STANDALONE) { - - $register_policy = intval(get_config('system','register_policy')); - - if($register_policy == REGISTER_CLOSED) - $ret['site']['register_policy'] = 'closed'; - if($register_policy == REGISTER_APPROVE) - $ret['site']['register_policy'] = 'approve'; - if($register_policy == REGISTER_OPEN) - $ret['site']['register_policy'] = 'open'; - - - $access_policy = intval(get_config('system','access_policy')); - - if($access_policy == ACCESS_PRIVATE) - $ret['site']['access_policy'] = 'private'; - if($access_policy == ACCESS_PAID) - $ret['site']['access_policy'] = 'paid'; - if($access_policy == ACCESS_FREE) - $ret['site']['access_policy'] = 'free'; - if($access_policy == ACCESS_TIERED) - $ret['site']['access_policy'] = 'tiered'; - - $ret['site']['accounts'] = account_total(); - - require_once('include/identity.php'); - $ret['site']['channels'] = channel_total(); - - - $ret['site']['version'] = PLATFORM_NAME . ' ' . RED_VERSION . '[' . DB_UPDATE_VERSION . ']'; - - $ret['site']['admin'] = get_config('system','admin_email'); - - $visible_plugins = array(); - if(is_array($a->plugins) && count($a->plugins)) { - $r = q("select * from addon where hidden = 0"); - if($r) - foreach($r as $rr) - $visible_plugins[] = $rr['name']; - } - - $ret['site']['plugins'] = $visible_plugins; - $ret['site']['sitehash'] = get_config('system','location_hash'); - $ret['site']['sitename'] = get_config('system','sitename'); - $ret['site']['sellpage'] = get_config('system','sellpage'); - $ret['site']['location'] = get_config('system','site_location'); - $ret['site']['realm'] = get_directory_realm(); - - } - call_hooks('zot_finger',$ret); - json_return_and_die($ret); } diff --git a/mod/zotfeed.php b/mod/zotfeed.php index 78a667330..fffb0e4ab 100644 --- a/mod/zotfeed.php +++ b/mod/zotfeed.php @@ -9,7 +9,7 @@ function zotfeed_init(&$a) { $mindate = (($_REQUEST['mindate']) ? datetime_convert('UTC','UTC',$_REQUEST['mindate']) : ''); if(! $mindate) - $mindate = datetime_convert('UTC','UTC', 'now - 4 days'); + $mindate = datetime_convert('UTC','UTC', 'now - 14 days'); if(get_config('system','block_public') && (! get_account_id()) && (! remote_channel())) { $result['message'] = 'Public access denied'; @@ -21,16 +21,15 @@ function zotfeed_init(&$a) { $channel_address = ((argc() > 1) ? argv(1) : ''); if($channel_address) { - $r = q("select channel_id, channel_name from channel where channel_address = '%s' and not (channel_pageflags & %d) > 0 limit 1", - dbesc(argv(1)), - intval(PAGE_REMOVED) + $r = q("select channel_id, channel_name from channel where channel_address = '%s' and channel_removed = 0 limit 1", + dbesc(argv(1)) ); } else { $x = get_sys_channel(); if($x) $r = array($x); - $mindate = datetime_convert('UTC','UTC', 'now - 2 days'); + $mindate = datetime_convert('UTC','UTC', 'now - 14 days'); } if(! $r) { $result['message'] = 'Channel not found.'; |