diff options
Diffstat (limited to 'mod')
92 files changed, 2714 insertions, 2483 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..a884b7658 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']); @@ -279,7 +237,7 @@ function admin_page_site_post(&$a){ $register_text = ((x($_POST,'register_text')) ? notags(trim($_POST['register_text'])) : ''); $frontpage = ((x($_POST,'frontpage')) ? notags(trim($_POST['frontpage'])) : ''); $mirror_frontpage = ((x($_POST,'mirror_frontpage')) ? intval(trim($_POST['mirror_frontpage'])) : 0); - + $directory_server = ((x($_POST,'directory_server')) ? trim($_POST['directory_server']) : ''); $allowed_sites = ((x($_POST,'allowed_sites')) ? notags(trim($_POST['allowed_sites'])) : ''); $allowed_email = ((x($_POST,'allowed_email')) ? notags(trim($_POST['allowed_email'])) : ''); $not_allowed_email = ((x($_POST,'not_allowed_email')) ? notags(trim($_POST['not_allowed_email'])) : ''); @@ -296,15 +254,15 @@ function admin_page_site_post(&$a){ $proxy = ((x($_POST,'proxy')) ? notags(trim($_POST['proxy'])) : ''); $timeout = ((x($_POST,'timeout')) ? intval(trim($_POST['timeout'])) : 60); $delivery_interval = ((x($_POST,'delivery_interval'))? intval(trim($_POST['delivery_interval'])) : 0); + $delivery_batch_count = ((x($_POST,'delivery_batch_count') && $_POST['delivery_batch_count'] > 0)? intval(trim($_POST['delivery_batch_count'])) : 1); $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', 'delivery_batch_count', $delivery_batch_count); set_config('system', 'poll_interval', $poll_interval); set_config('system', 'maxloadavg', $maxloadavg); set_config('system', 'frontpage', $frontpage); @@ -314,6 +272,9 @@ function admin_page_site_post(&$a){ set_config('system', 'verify_email', $verify_email); set_config('system', 'default_expire_days', $default_expire_days); + if($directory_server) + set_config('system','directory_server',$directory_server); + if ($banner == '') { del_config('system', 'banner'); } else { @@ -374,10 +335,10 @@ function admin_page_site(&$a) { /* Installed langs */ $lang_choices = array(); - $langs = glob('view/*/strings.php'); + $langs = glob('view/*/hstrings.php'); if(is_array($langs) && count($langs)) { - if(! in_array('view/en/strings.php',$langs)) + if(! in_array('view/en/hstrings.php',$langs)) $langs[] = 'view/en/'; asort($langs); foreach($langs as $l) { @@ -413,6 +374,26 @@ function admin_page_site(&$a) { } } + $dir_choices = null; + $dirmode = get_config('system','directory_mode'); + $realm = get_directory_realm(); + + // directory server should not be set or settable unless we are a directory client + + if($dirmode == DIRECTORY_MODE_NORMAL) { + $x = q("select site_url from site where site_flags in (%d,%d) and site_realm = '%s'", + intval(DIRECTORY_MODE_SECONDARY), + intval(DIRECTORY_MODE_PRIMARY), + dbesc($realm) + ); + if($x) { + $dir_choices = array(); + foreach($x as $xx) { + $dir_choices[$xx['site_url']] = $xx['site_url']; + } + } + } + /* Banner */ $banner = get_config('system', 'banner'); if($banner == false) @@ -465,7 +446,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), @@ -483,10 +463,13 @@ function admin_page_site(&$a) { '$disable_discover_tab' => array('disable_discover_tab', t("Disable discovery tab"), get_config('system','disable_discover_tab'), t("Remove the tab in the network view with public content pulled from sources chosen for this site.")), '$login_on_homepage' => array('login_on_homepage', t("login on Homepage"),((intval($homelogin) || $homelogin === false) ? 1 : '') , t("Present a login box to visitors on the home page if no other content has been configured.")), + '$directory_server' => (($dir_choices) ? array('directory_server', t("Directory Server URL"), get_config('system','directory_server'), t("Default directory server"), $dir_choices) : null), + '$proxyuser' => array('proxyuser', t("Proxy user"), get_config('system','proxyuser'), ""), '$proxy' => array('proxy', t("Proxy URL"), get_config('system','proxy'), ""), '$timeout' => array('timeout', t("Network timeout"), (x(get_config('system','curl_timeout'))?get_config('system','curl_timeout'):60), t("Value is in seconds. Set to 0 for unlimited (not recommended).")), '$delivery_interval' => array('delivery_interval', t("Delivery interval"), (x(get_config('system','delivery_interval'))?get_config('system','delivery_interval'):2), t("Delay background delivery processes by this many seconds to reduce system load. Recommend: 4-5 for shared hosts, 2-3 for virtual private servers. 0-1 for large dedicated servers.")), + '$delivery_batch_count' => array('delivery_batch_count', t('Deliveries per process'),(x(get_config('system','delivery_batch_count'))?get_config('system','delivery_batch_count'):1), t("Number of deliveries to attempt in a single operating system process. Adjust if necessary to tune system performance. Recommend: 1-5.")), '$poll_interval' => array('poll_interval', t("Poll interval"), (x(get_config('system','poll_interval'))?get_config('system','poll_interval'):2), t("Delay background polling processes by this many seconds to reduce system load. If 0, use delivery interval.")), '$maxloadavg' => array('maxloadavg', t("Maximum Load Average"), ((intval(get_config('system','maxloadavg')) > 0)?get_config('system','maxloadavg'):50), t("Maximum system load before delivery and poll processes are deferred - default 50.")), '$default_expire_days' => array('default_expire_days', t('Expiration period in days for imported (matrix/network) content'), intval(get_config('system','default_expire_days')), t('0 for no expiration of imported content')), @@ -599,7 +582,7 @@ function admin_page_dbsync(&$a) { } } if(! count($failed)) - return '<h3>' . t('No failed updates.') . '</h3>'; + return '<div class="generic-content-wrapper-styled"><h3>' . t('No failed updates.') . '</h3></div>'; $o = replace_macros(get_markup_template('failed_updates.tpl'),array( '$base' => $a->get_baseurl(true), @@ -786,11 +769,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 +930,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 +938,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 +1456,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..0af2666cc 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)) @@ -153,7 +153,6 @@ function channel_content(&$a, $update = 0, $load = false) { else $page_mode = 'client'; - $abook_uids = " and abook.abook_channel = " . intval($a->profile['profile_uid']) . " "; $simple_update = (($update) ? " AND item_unseen = 1 " : ''); @@ -165,23 +164,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 $simple_update + 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 +205,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 +217,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 +237,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']), @@ -267,9 +259,6 @@ function channel_content(&$a, $update = 0, $load = false) { } - - - if((! $update) && (! $load)) { // This is ugly, but we can't pass the profile_uid through the session to the ajax updater, @@ -338,9 +327,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..79a5c050b 100644 --- a/mod/chat.php +++ b/mod/chat.php @@ -54,20 +54,24 @@ 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; + $arr['expire'] = intval($_POST['chat_expire']); + if(intval($arr['expire']) < 0) + $arr['expire'] = 0; 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 +162,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,20 +199,15 @@ 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'); $o = replace_macros(get_markup_template('chatroom_new.tpl'),array( '$header' => t('New Chatroom'), '$name' => array('room_name',t('Chatroom Name'),'', ''), + '$chat_expire' => array('chat_expire',t('Expiration of chats (minutes)'),120,''), '$permissions' => t('Permissions'), '$acl' => populate_acl($channel_acl,false), '$submit' => t('Submit') 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..877c12dc7 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), @@ -214,15 +214,14 @@ function connedit_post(&$a) { } - if($r) info( t('Connection updated.') . EOL); else 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))) { - proc_run('php', 'include/notifier.php', 'permission_update', $contact_id); + && (! intval($a->poi['abook_self']))) { + proc_run('php', 'include/notifier.php', (($new_friend) ? 'permission_create' : 'permission_update'), $contact_id); } if($new_friend) { @@ -241,11 +240,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 +314,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 +381,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 +407,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 +416,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 +425,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 +434,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 +445,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 +511,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 +553,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'); @@ -669,12 +652,31 @@ function connedit_content(&$a) { $perms[] = array('perms_' . $k, $v[3], (($contact['abook_their_perms'] & $v[1]) ? "1" : ""),$thisperm, $v[1], (($channel[$v[0]] == PERMS_SPECIFIC) ? '' : '1'), $v[4], $checkinherited); } + $locstr = ''; + + $locs = q("select hubloc_addr as location from hubloc left join site on hubloc_url = site_url where hubloc_hash = '%s' + and hubloc_deleted = 0 and site_dead = 0", + dbesc($contact['xchan_hash']) + ); + + if($locs) { + foreach($locs as $l) { + if(strlen($locstr)) + $locstr .= ', '; + $locstr .= $l['location']; + } + } + else + $locstr = t('none'); + $o .= replace_macros($tpl,array( '$header' => (($self) ? t('Connection Default Permissions') : sprintf( t('Connection: %s'),$contact['xchan_name'])), '$autoperms' => array('autoperms',t('Apply these permissions automatically'), ((get_pconfig(local_channel(),'system','autoperms')) ? 1 : 0), 'Connection requests will be approved without your interaction', array(t('No'),('Yes'))), '$addr' => $contact['xchan_addr'], - '$addr_text' => t('This connection\'s address is'), + '$addr_text' => t('This connection\'s primary address is'), + '$loc_text' => t('Available locations:'), + '$locstr' => $locstr, '$notself' => (($self) ? '' : '1'), '$self' => (($self) ? '1' : ''), '$autolbl' => t('The permissions indicated on this page will be applied to all new connections.'), @@ -685,8 +687,8 @@ function connedit_content(&$a) { '$lbl_rating_txt' => t('Optionally explain your rating'), '$connfilter' => feature_enabled(local_channel(),'connfilter'), '$connfilter_label' => t('Custom Filter'), - '$incl' => array('abook_incl',t('Only import posts with this text'), $contact['abook_incl'],t('words one per line or #tags or /patterns/, leave blank to import all posts')), - '$excl' => array('abook_excl',t('Do not import posts with this text'), $contact['abook_excl'],t('words one per line or #tags or /patterns/, leave blank to import all posts')), + '$incl' => array('abook_incl',t('Only import posts with this text'), $contact['abook_incl'],t('words one per line or #tags or /patterns/ or lang=xx, leave blank to import all posts')), + '$excl' => array('abook_excl',t('Do not import posts with this text'), $contact['abook_excl'],t('words one per line or #tags or /patterns/ or lang=xx, leave blank to import all posts')), '$rating_text' => array('rating_text', t('Optionally explain your rating'),$rating_text,''), '$rating_info' => t('This information is public!'), '$rating' => $rating, @@ -698,7 +700,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 2aaa42607..937564a79 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']; @@ -407,13 +398,15 @@ function list_public_sites() { $rand = db_getfunc('rand'); $realm = get_directory_realm(); if($realm == DIRECTORY_REALM) { - $r = q("select * from site where site_access != 0 and site_register !=0 and ( site_realm = '%s' or site_realm = '') order by $rand", - dbesc($realm) + $r = q("select * from site where site_access != 0 and site_register !=0 and ( site_realm = '%s' or site_realm = '') and site_type = %d order by $rand", + dbesc($realm), + intval(SITE_TYPE_ZOT) ); } else { - $r = q("select * from site where site_access != 0 and site_register !=0 and site_realm = '%s' order by $rand", - dbesc($realm) + $r = q("select * from site where site_access != 0 and site_register !=0 and site_realm = '%s' and site_type = %d order by $rand", + dbesc($realm), + intval(SITE_TYPE_ZOT) ); } 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/dreport.php b/mod/dreport.php new file mode 100644 index 000000000..c320bf0e6 --- /dev/null +++ b/mod/dreport.php @@ -0,0 +1,138 @@ +<?php + +function dreport_content(&$a) { + + if(! local_channel()) { + notice( t('Permission denied') . EOL); + return; + } + + $table = 'item'; + + $channel = $a->get_channel(); + + $mid = ((argc() > 1) ? argv(1) : ''); + + if($mid === 'mail') { + $table = 'mail'; + $mid = ((argc() > 2) ? argv(2) : ''); + } + + + if(! $mid) { + notice( t('Invalid message') . EOL); + return; + } + + switch($table) { + case 'item': + $i = q("select id from item where mid = '%s' and author_xchan = '%s' ", + dbesc($mid), + dbesc($channel['channel_hash']) + ); + break; + case 'mail': + $i = q("select id from mail where mid = '%s' and from_xchan = '%s'", + dbesc($mid), + dbesc($channel['channel_hash']) + ); + break; + default: + break; + } + + if(! $i) { + notice( t('Permission denied') . EOL); + return; + } + + $r = q("select * from dreport where dreport_xchan = '%s' and dreport_mid = '%s'", + dbesc($channel['channel_hash']), + dbesc($mid) + ); + + if(! $r) { + notice( t('no results') . EOL); + return; + } + + + $o .= '<h2>' . sprintf( t('Delivery report for %1$s'),substr($mid,0,32)) . '...' . '</h2>'; + $o .= '<table>'; + + for($x = 0; $x < count($r); $x++ ) { + $r[$x]['name'] = escape_tags(substr($r[$x]['dreport_recip'],strpos($r[$x]['dreport_recip'],' '))); + + // This has two purposes: 1. make the delivery report strings translateable, and + // 2. assign an ordering to item delivery results so we can group them and provide + // a readable report with more interesting events listed toward the top and lesser + // interesting items towards the bottom + + switch($r[$x]['dreport_result']) { + case 'channel sync processed': + $r[$x]['gravity'] = 0; + $r[$x]['dreport_result'] = t('channel sync processed'); + break; + case 'queued': + $r[$x]['gravity'] = 2; + $r[$x]['dreport_result'] = t('queued'); + break; + case 'posted': + $r[$x]['gravity'] = 3; + $r[$x]['dreport_result'] = t('posted'); + break; + case 'accepted for delivery': + $r[$x]['gravity'] = 4; + $r[$x]['dreport_result'] = t('accepted for delivery'); + break; + case 'updated': + $r[$x]['gravity'] = 5; + $r[$x]['dreport_result'] = t('updated'); + case 'update ignored': + $r[$x]['gravity'] = 6; + $r[$x]['dreport_result'] = t('update ignored'); + break; + case 'permission denied': + $r[$x]['dreport_result'] = t('permission denied'); + $r[$x]['gravity'] = 6; + break; + case 'recipient not found': + $r[$x]['dreport_result'] = t('recipient not found'); + break; + case 'mail recalled': + $r[$x]['dreport_result'] = t('mail recalled'); + break; + case 'duplicate mail received': + $r[$x]['dreport_result'] = t('duplicate mail received'); + break; + case 'mail delivered': + $r[$x]['dreport_result'] = t('mail delivered'); + break; + default: + $r[$x]['gravity'] = 1; + break; + } + } + + usort($r,'dreport_gravity_sort'); + + + foreach($r as $rr) { + $o .= '<tr><td width="40%">' . $rr['name'] . '</td><td width="20%">' . escape_tags($rr['dreport_result']) . '</td><td width="20%">' . escape_tags($rr['dreport_time']) . '</td></tr>'; + } + $o .= '</table>'; + + return $o; + + + +} + +function dreport_gravity_sort($a,$b) { + if($a['gravity'] == $b['gravity']) { + if($a['name'] === $b['name']) + return strcmp($a['dreport_time'],$b['dreport_time']); + return strcmp($a['name'],$b['name']); + } + return (($a['gravity'] > $b['gravity']) ? 1 : (-1)); +}
\ No newline at end of file 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..2f999858f 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); @@ -83,7 +90,6 @@ function editpost_content(&$a) { $category .= ', '; $category .= $cat['term']; } - } if($itm[0]['attach']) { @@ -119,10 +125,10 @@ 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'], + '$ptyp' => $itm[0]['obj_type'], '$content' => undo_post_tagging($itm[0]['body']), '$post_id' => $post_id, '$parent' => (($itm[0]['parent'] != $itm[0]['id']) ? $itm[0]['parent'] : ''), 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/ffsapi.php b/mod/ffsapi.php new file mode 100644 index 000000000..f4033e63b --- /dev/null +++ b/mod/ffsapi.php @@ -0,0 +1,65 @@ +<?php + + +function ffsapi_content(&$a) { + +$baseurl = z_root(); +$name = get_config('system','sitename'); +$description = t('Share content from Firefox to $Projectname'); +$author = 'Mike Macgirvin'; +$homepage = 'http://hubzilla.org'; +$activate = t('Activate the Firefox $Projectname provider'); + +$s = <<< EOT + +<script> + +var baseurl = '$baseurl'; + +var data = { + "origin": baseurl, + // currently required + "name": '$name', + "iconURL": baseurl+"/images/hz-16.png", + "icon32URL": baseurl+"/images/hz-32.png", + "icon64URL": baseurl+"/images/hz-64.png", + + // at least one of these must be defined + // "workerURL": baseurl+"/worker.js", + // "sidebarURL": baseurl+"/sidebar.htm", + "shareURL": baseurl+"/rpost?f=&url=%{url}", + + // status buttons are scheduled for Firefox 26 or 27 + //"statusURL": baseurl+"/statusPanel.html", + + // social bookmarks are available in Firefox 26 + "markURL": baseurl+"/rbmark?f=&url=%{url}&title=%{title}", + // icons should be 32x32 pixels + // "markedIcon": baseurl+"/images/checkbox-checked-32.png", + // "unmarkedIcon": baseurl+"/images/checkbox-unchecked-32.png", + "unmarkedIcon": baseurl+"/images/hz-bookmark-32.png", + + // should be available for display purposes + "description": '$description', + "author": '$author', + "homepageURL": '$homepage', + + // optional + "version": "1.0" +} + +function activate(node) { + var event = new CustomEvent("ActivateSocialFeature"); + var jdata = JSON.stringify(data); + node.setAttribute("data-service", JSON.stringify(data)); + node.dispatchEvent(event); +} +</script> + +<button onclick="activate(this)" title="activate the demo provider" class="btn btn-primary">$activate</button> + +EOT; + +return $s; + +} diff --git a/mod/fhublocs.php b/mod/fhublocs.php new file mode 100644 index 000000000..dce00e383 --- /dev/null +++ b/mod/fhublocs.php @@ -0,0 +1,80 @@ +<?php + +require_once('include/zot.php'); +require_once('include/crypto.php'); + +/* fix missing or damaged hublocs */ + +function fhublocs_content(&$a) { + + if(! is_site_admin()) + return; + + $o = ''; + + $r = q("select * from channel where channel_removed = 0"); + $sitekey = get_config('system','pubkey'); + + if($r) { + foreach($r as $rr) { + $found = false; + $primary_address = ''; + $x = zot_get_hublocs($rr['channel_hash']); + if($x) { + foreach($x as $xx) { + if($xx['hubloc_url'] === z_root() && $xx['hubloc_sitekey'] === $sitekey) { + $found = true; + break; + } + } + if($found) { + $o .= 'Hubloc exists for ' . $rr['channel_name'] . EOL; + continue; + } + } + $y = q("select xchan_addr from xchan where xchan_hash = '%s' limit 1", + dbesc($rr['channel_hash']) + ); + if($y) + $primary_address = $y[0]['xchan_addr']; + + $hub_address = $rr['channel']['channel_address'] . '@' . get_app()->get_hostname(); + + + $primary = (($hub_address === $primary_address) ? 1 : 0); + if(! $y) + $primary = 1; + + $m = q("delete from hubloc where hubloc_hash = '%s' and hubloc_url = '%s' ", + dbesc($rr['channel_hash']), + dbesc(z_root()) + ); + + // Create a verified hub location pointing to this site. + + $h = q("insert into hubloc ( hubloc_guid, hubloc_guid_sig, hubloc_hash, hubloc_addr, hubloc_primary, hubloc_url, hubloc_url_sig, hubloc_host, hubloc_callback, hubloc_sitekey, hubloc_network ) + values ( '%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s' )", + dbesc($rr['channel_guid']), + dbesc($rr['channel_guid_sig']), + dbesc($rr['channel_hash']), + dbesc($rr['channel_address'] . '@' . get_app()->get_hostname()), + intval($primary), + dbesc(z_root()), + dbesc(base64url_encode(rsa_sign(z_root(),$rr['channel_prvkey']))), + dbesc(get_app()->get_hostname()), + dbesc(z_root() . '/post'), + dbesc($sitekey), + dbesc('zot') + ); + + if($h) + $o . 'local hubloc created for ' . $rr['channel_name'] . EOL; + else + $o .= 'DB update failed for ' . $rr['channel_name'] . EOL; + + } + + return $o; + + } +}
\ No newline at end of file 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 b698d93b6..bf2463bbc 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; @@ -70,6 +69,7 @@ function home_content(&$a, $update = 0, $load = false) { goaway($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..72d8f92e9 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,367 @@ 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($seize) { + if($completed < 5) { + // create new hubloc for the new channel at this site - // 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); + } + + 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)) + . "')" ); - $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']; + $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['conv'])) + import_conv($channel,$data['conv']); + + if(is_array($data['mail'])) + import_mail($channel,$data['mail']); + + 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']); + + $addon = array('channel' => $channel,'data' => $data); + call_hooks('import_channel',$addon); + + $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 +487,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..591dc8407 100644 --- a/mod/item.php +++ b/mod/item.php @@ -96,7 +96,7 @@ function item_post(&$a) { $owner_hash = null; $message_id = ((x($_REQUEST,'message_id') && $api_source) ? strip_tags($_REQUEST['message_id']) : ''); - $created = ((x($_REQUEST,'created')) ? datetime_convert('UTC','UTC',$_REQUEST['created']) : datetime_convert()); + $created = ((x($_REQUEST,'created')) ? datetime_convert(date_default_timezone_get(),'UTC',$_REQUEST['created']) : datetime_convert()); $post_id = ((x($_REQUEST,'post_id')) ? intval($_REQUEST['post_id']) : 0); $app = ((x($_REQUEST,'source')) ? strip_tags($_REQUEST['source']) : ''); $return_path = ((x($_REQUEST,'return')) ? $_REQUEST['return'] : ''); @@ -107,7 +107,6 @@ function item_post(&$a) { $layout_mid = ((x($_REQUEST,'layout_mid')) ? escape_tags($_REQUEST['layout_mid']): ''); $plink = ((x($_REQUEST,'permalink')) ? escape_tags($_REQUEST['permalink']) : ''); $obj_type = ((x($_REQUEST,'obj_type')) ? escape_tags($_REQUEST['obj_type']) : ACTIVITY_OBJ_NOTE); - // allow API to bulk load a bunch of imported items with sending out a bunch of posts. $nopush = ((x($_REQUEST,'nopush')) ? intval($_REQUEST['nopush']) : 0); @@ -115,7 +114,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 +196,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 +294,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 +304,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 +317,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 +337,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 +371,23 @@ function item_post(&$a) { } else { + if(! $walltowall) { + 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); + } + elseif(! $api_source) { - // 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 + // if no ACL has been defined and we aren't using the API, the form + // didn't send us any parameters. This means there's no ACL or it has + // been reset to the default audience. + // If $api_source is set and there are no ACL parameters, we default + // to the channel permissions which were set in the ACL contructor. - $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(array('allow_cid' => '', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '')); + } } @@ -404,33 +399,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 +462,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 +531,6 @@ function item_post(&$a) { $body = preg_replace_callback('/\[img(.*?)\](.*?)\[\/img\]/ism','red_zrlify_img_callback',$body); - - - $body = bb_translate_video($body); /** @@ -628,7 +607,9 @@ function item_post(&$a) { if(preg_match_all('/(\[attachment\](.*?)\[\/attachment\])/',$body,$match)) { $attachments = array(); + $i = 0; 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 +622,13 @@ 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][$i],$attach_link,$body); + $i++; } } @@ -662,31 +649,28 @@ 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); + $item_consensus = (($consensus) ? 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 +694,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 +727,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 +806,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 +855,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 +885,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 +897,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 +943,11 @@ function item_post(&$a) { logger('post_complete'); + + + + + // figure out how to return, depending on from whence we came if($api_source) @@ -983,7 +982,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 +1008,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 +1044,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 +1104,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 +1158,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..9f66e3263 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']) ); @@ -38,11 +35,12 @@ function locs_post(&$a) { } } + if($_REQUEST['drop']) { $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 +50,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 +79,6 @@ function locs_post(&$a) { function locs_content(&$a) { - if(! local_channel()) { notice( t('Permission denied.') . EOL); return; @@ -80,6 +86,13 @@ function locs_content(&$a) { $channel = $a->get_channel(); + if($_REQUEST['sync']) { + proc_run('php','include/notifier.php','location',$channel['channel_id']); + info( t('Syncing locations') . EOL); + goaway(z_root() . '/locs'); + } + + $r = q("select * from hubloc where hubloc_hash = '%s'", dbesc($channel['channel_hash']) ); @@ -91,18 +104,20 @@ 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)'), '$mkprm' => t('Primary Location'), '$drop' => t('Drop location'), '$submit' => t('Submit'), + '$sync' => t('Sync now'), + '$sync_text' => t('Please wait several minutes between consecutive operations.'), + '$drop_text' => t('When possible, drop a location by logging into that website/hub and removing your channel.'), + '$last_resort' => t('Use this form to drop the location if the hub is no longer operating.'), '$hubs' => $r )); diff --git a/mod/mail.php b/mod/mail.php index 1b0ea17c4..536149a28 100644 --- a/mod/mail.php +++ b/mod/mail.php @@ -97,11 +97,15 @@ function mail_post(&$a) { $ret = send_message(0, $recipient, $body, $subject, $replyto, $expires); - if(! $ret['success']) { + if($ret['success']) { + xchan_mail_query($ret['mail']); + build_sync_packet(0,array('conv' => array($ret['conv']),'mail' => array(encode_mail($ret['mail'],true)))); + } + else { notice($ret['message']); } - goaway(z_root() . '/message'); + goaway(z_root() . '/mail/combined'); } @@ -125,44 +129,60 @@ 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')) { - if(! intval(argv(2))) + if((argc() == 4) && (argv(2) === 'drop')) { + if(! intval(argv(3))) return; - $cmd = argv(1); - - $r = private_messages_drop(local_channel(), argv(2)); + $cmd = argv(2); + $mailbox = argv(1); + $r = private_messages_drop(local_channel(), argv(3)); if($r) { - info( t('Message deleted.') . EOL ); + //info( t('Message deleted.') . EOL ); } - goaway($a->get_baseurl(true) . '/message' ); + goaway($a->get_baseurl(true) . '/mail/' . $mailbox); } - if((argc() == 3) && (argv(1) === 'recall')) { - if(! intval(argv(2))) + if((argc() == 4) && (argv(2) === 'recall')) { + if(! intval(argv(3))) return; - $cmd = argv(1); - $r = q("update mail set mail_flags = mail_flags | %d where id = %d and channel_id = %d", - intval(MAIL_RECALLED), - intval(argv(2)), + $cmd = argv(2); + $mailbox = argv(1); + $r = q("update mail set mail_recalled = 1 where id = %d and channel_id = %d", + intval(argv(3)), intval(local_channel()) ); - proc_run('php','include/notifier.php','mail',intval(argv(2))); + $x = q("select * from mail where id = %d and channel_id = %d", + intval(argv(3)), + intval(local_channel()) + ); + if($x) { + build_sync_packet(local_channel(),array('mail' => encode_mail($x[0],true))); + } + + proc_run('php','include/notifier.php','mail',intval(argv(3))); if($r) { info( t('Message recalled.') . EOL ); } - goaway($a->get_baseurl(true) . '/message' ); + goaway($a->get_baseurl(true) . '/mail/' . $mailbox . '/' . argv(3)); + + } + if((argc() == 4) && (argv(2) === 'dropconv')) { + if(! intval(argv(3))) + return; + $cmd = argv(2); + $mailbox = argv(1); + $r = private_messages_drop(local_channel(), argv(3), true); + if($r) + info( t('Conversation removed.') . EOL ); + goaway($a->get_baseurl(true) . '/mail/' . $mailbox); } if((argc() > 1) && (argv(1) === 'new')) { - $o .= $header; - $plaintext = true; $tpl = get_markup_template('msg-header.tpl'); @@ -177,68 +197,48 @@ function mail_content(&$a) { $a->page['htmlhead'] .= $header; - - $preselect = (isset($a->argv[2])?array($a->argv[2]):false); - $prename = $preurl = $preid = ''; - + $prename = ''; + $preid = ''; + if(x($_REQUEST,'hash')) { + $r = q("select abook.*, xchan.* from abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d and abook_xchan = '%s' limit 1", intval(local_channel()), dbesc($_REQUEST['hash']) ); - if($r) { - $prename = $r[0]['xchan_name']; - $preurl = $r[0]['xchan_url']; - $preid = $r[0]['abook_id']; - $preselect = array($preid); - } - } + if(!$r) { + $r = q("select * from xchan where xchan_hash = '%s' and xchan_network = 'zot' limit 1", + dbesc($_REQUEST['hash']) + ); + } - if($preselect) { - $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(argv(2)) - ); if($r) { - $prename = $r[0]['xchan_name']; + $prename = (($r[0]['abook_id']) ? $r[0]['xchan_name'] : $r[0]['xchan_addr']); $preurl = $r[0]['xchan_url']; - $preid = $r[0]['abook_id']; + $preid = (($r[0]['abook_id']) ? ($r[0]['xchan_hash']) : ''); + } + else { + notice( t('Requested channel is not in this network') . EOL ); } - } - - $prefill = (($preselect) ? $prename : ''); - if(! $prefill) { - if(array_key_exists('to',$_REQUEST)) - $prefill = $_REQUEST['to']; } - // the ugly select box - - $select = contact_select('messageto','message-to-select', $preselect, 4, true, false, false, 10); - $tpl = get_markup_template('prv_message.tpl'); $o .= replace_macros($tpl,array( + '$new' => true, '$header' => t('Send Private Message'), '$to' => t('To:'), - '$showinputs' => 'true', - '$prefill' => $prefill, - '$autocomp' => $autocomp, + '$prefill' => $prename, '$preid' => $preid, '$subject' => t('Subject:'), '$subjtxt' => ((x($_REQUEST,'subject')) ? strip_tags($_REQUEST['subject']) : ''), '$text' => ((x($_REQUEST,'body')) ? htmlspecialchars($_REQUEST['body'], ENT_COMPAT, 'UTF-8') : ''), - '$readonly' => '', '$yourmessage' => t('Your message:'), - '$select' => $select, '$parent' => '', - '$upload' => t('Upload photo'), '$attach' => t('Attach file'), '$insert' => t('Insert web link'), - '$wait' => t('Please wait'), '$submit' => t('Send'), '$defexpire' => '', '$feature_expire' => ((feature_enabled(local_channel(),'content_expire')) ? true : false), @@ -246,124 +246,137 @@ function mail_content(&$a) { '$feature_encrypt' => ((feature_enabled(local_channel(),'content_encrypt')) ? true : false), '$encrypt' => t('Encrypt text'), '$cipher' => $cipher, - - )); return $o; } + switch(argv(1)) { + case 'combined': + $mailbox = 'combined'; + break; + case 'inbox': + $mailbox = 'inbox'; + break; + case 'outbox': + $mailbox = 'outbox'; + break; + default: + $mailbox = 'combined'; + break; + } - if((argc() > 1) && (intval(argv(1)))) { - - $o .= $header; - - $plaintext = true; + $last_message = private_messages_list(local_channel(), $mailbox, 0, 1); -// if( local_channel() && feature_enabled(local_channel(),'richtext') ) -// $plaintext = false; + $mid = ((argc() > 2) && (intval(argv(2)))) ? argv(2) : $last_message[0]['id']; - $messages = private_messages_fetch_conversation(local_channel(), argv(1), true); + $plaintext = true; - if(! $messages) { - info( t('Message not found.') . EOL); - return $o; - } +// if( local_channel() && feature_enabled(local_channel(),'richtext') ) +// $plaintext = false; - if($messages[0]['to_xchan'] === $channel['channel_hash']) - $a->poi = $messages[0]['from']; - else - $a->poi = $messages[0]['to']; -// require_once('include/Contact.php'); -// $a->set_widget('mail_conversant',vcard_from_xchan($a->poi,$get_observer_hash,'mail')); + if($mailbox == 'combined') { + $messages = private_messages_fetch_conversation(local_channel(), $mid, true); + } + else { + $messages = private_messages_fetch_message(local_channel(), $mid, true); + } + if(! $messages) { + //info( t('Message not found.') . EOL); + return; + } - $tpl = get_markup_template('msg-header.tpl'); - - $a->page['htmlhead'] .= replace_macros($tpl, array( - '$nickname' => $channel['channel_address'], - '$baseurl' => $a->get_baseurl(true), - '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'), - '$linkurl' => t('Please enter a link URL:'), - '$expireswhen' => t('Expires YYYY-MM-DD HH:MM') - )); + if($messages[0]['to_xchan'] === $channel['channel_hash']) + $a->poi = $messages[0]['from']; + else + $a->poi = $messages[0]['to']; +// require_once('include/Contact.php'); - $mails = array(); - $seen = 0; - $unknown = false; - - foreach($messages as $message) { - - $s = theme_attachments($message); - - $mails[] = array( - 'id' => $message['id'], - 'from_name' => $message['from']['xchan_name'], - 'from_url' => chanlink_hash($message['from_xchan']), - 'from_photo' => $message['from']['xchan_photo_m'], - 'to_name' => $message['to']['xchan_name'], - 'to_url' => chanlink_hash($message['to_xchan']), - 'to_photo' => $message['to']['xchan_photo_m'], - 'subject' => $message['title'], - 'body' => smilies(bbcode($message['body']) . $s), - '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.') : ''), - 'date' => datetime_convert('UTC',date_default_timezone_get(),$message['created'],'D, d M Y - g:i A'), - ); - - $seen = $message['seen']; +// $a->set_widget('mail_conversant',vcard_from_xchan($a->poi,$get_observer_hash,'mail')); - } - $recp = (($message['from_xchan'] === $channel['channel_hash']) ? 'to' : 'from'); + $tpl = get_markup_template('msg-header.tpl'); + + $a->page['htmlhead'] .= replace_macros($tpl, array( + '$nickname' => $channel['channel_address'], + '$baseurl' => $a->get_baseurl(true), + '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'), + '$linkurl' => t('Please enter a link URL:'), + '$expireswhen' => t('Expires YYYY-MM-DD HH:MM') + )); -// FIXME - move this HTML to template + $mails = array(); + + $seen = 0; + $unknown = false; + + foreach($messages as $message) { + + $s = theme_attachments($message); + + $mails[] = array( + 'mailbox' => $mailbox, + 'id' => $message['id'], + 'mid' => $message['mid'], + 'from_name' => $message['from']['xchan_name'], + 'from_url' => chanlink_hash($message['from_xchan']), + 'from_photo' => $message['from']['xchan_photo_s'], + 'to_name' => $message['to']['xchan_name'], + 'to_url' => chanlink_hash($message['to_xchan']), + 'to_photo' => $message['to']['xchan_photo_s'], + 'subject' => $message['title'], + 'body' => smilies(bbcode($message['body']) . $s), + 'delete' => t('Delete message'), + 'dreport' => t('Delivery report'), + 'recall' => t('Recall message'), + 'can_recall' => (($channel['channel_hash'] == $message['from_xchan']) ? true : false), + 'is_recalled' => (intval($message['mail_recalled']) ? t('Message has been recalled.') : ''), + 'date' => datetime_convert('UTC',date_default_timezone_get(),$message['created'], 'c'), + ); + + $seen = $message['seen']; - $select = $message[$recp]['xchan_name'] . '<input type="hidden" name="messageto" value="' . $message[$recp]['xchan_hash'] . '" />'; - $parent = '<input type="hidden" name="replyto" value="' . $message['parent_mid'] . '" />'; + } - $tpl = get_markup_template('mail_display.tpl'); - $o = replace_macros($tpl, array( - '$prvmsg_header' => t('Private Conversation'), - '$thread_id' => $a->argv[1], - '$thread_subject' => $message['title'], - '$thread_seen' => $seen, - '$delete' => t('Delete conversation'), - '$canreply' => (($unknown) ? false : '1'), - '$unknown_text' => t("No secure communications available. You <strong>may</strong> be able to respond from the sender's profile page."), - '$mails' => $mails, + $recp = (($message['from_xchan'] === $channel['channel_hash']) ? 'to' : 'from'); + + $tpl = get_markup_template('mail_display.tpl'); + $o = replace_macros($tpl, array( + '$mailbox' => $mailbox, + '$prvmsg_header' => $message['title'], + '$thread_id' => $mid, + '$thread_subject' => $message['title'], + '$thread_seen' => $seen, + '$delete' => t('Delete Conversation'), + '$canreply' => (($unknown) ? false : '1'), + '$unknown_text' => t("No secure communications available. You <strong>may</strong> be able to respond from the sender's profile page."), + '$mails' => $mails, - // reply - '$header' => t('Send Reply'), - '$to' => t('To:'), - '$showinputs' => '', - '$subject' => t('Subject:'), - '$subjtxt' => $message['title'], - '$readonly' => ' readonly="readonly" style="background: #BBBBBB;" ', - '$yourmessage' => t('Your message:'), - '$text' => '', - '$select' => $select, - '$parent' => $parent, - '$upload' => t('Upload photo'), - '$attach' => t('Attach file'), - '$insert' => t('Insert web link'), - '$submit' => t('Submit'), - '$wait' => t('Please wait'), - '$defexpire' => '', - '$feature_expire' => ((feature_enabled(local_channel(),'content_expire')) ? true : false), - '$expires' => t('Set expiration date'), - '$feature_encrypt' => ((feature_enabled(local_channel(),'content_encrypt')) ? true : false), - '$encrypt' => t('Encrypt text'), - '$cipher' => $cipher, - - )); + // reply + '$header' => t('Send Reply'), + '$to' => t('To:'), + '$reply' => true, + '$subject' => t('Subject:'), + '$subjtxt' => $message['title'], + '$yourmessage' => sprintf(t('Your message for %s (%s):'), $message[$recp]['xchan_name'], $message[$recp]['xchan_addr']), + '$text' => '', + '$parent' => $message['parent_mid'], + '$recphash' => $message[$recp]['xchan_hash'], + '$attach' => t('Attach file'), + '$insert' => t('Insert web link'), + '$submit' => t('Submit'), + '$defexpire' => '', + '$feature_expire' => ((feature_enabled(local_channel(),'content_expire')) ? true : false), + '$expires' => t('Set expiration date'), + '$feature_encrypt' => ((feature_enabled(local_channel(),'content_encrypt')) ? true : false), + '$encrypt' => t('Encrypt text'), + '$cipher' => $cipher, + )); - return $o; - } + return $o; } 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..73239d2cb 100644 --- a/mod/message.php +++ b/mod/message.php @@ -24,14 +24,7 @@ function message_content(&$a) { if(! $cipher) $cipher = 'aes256'; - - - $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))) return; @@ -39,45 +32,73 @@ function message_content(&$a) { $r = private_messages_drop(local_channel(), argv(2), true); if($r) info( t('Conversation removed.') . EOL ); - goaway($a->get_baseurl(true) . '/message' ); + goaway($a->get_baseurl(true) . '/mail/combined' ); } - if(argc() == 1) { - - // list messages - $o .= $header; + if(argc() == 2) { + + switch(argv(1)) { + case 'combined': + $mailbox = 'combined'; + $header = t('Conversations'); + break; + case 'inbox': + $mailbox = 'inbox'; + $header = t('Received Messages'); + break; + case 'outbox': + $mailbox = 'outbox'; + $header = t('Sent Messages'); + break; + default: + break; + } // 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']); + $r = private_messages_list(local_channel(), $mailbox, $a->pager['start'], $a->pager['itemspage']); if(! $r) { info( t('No messages.') . EOL); 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' => $header, + '$messages' => $messages + )); + + $o .= alt_pager($a,count($r)); + return $o; - } + return; + + } +*/ + return; } 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..33a895fdf 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,15 @@ 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) { - 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']); + attach_delete($page_owner_uid, $i['resource_id'], 1 ); + // This is now being done in attach_delete() + // drop_item($i['id'],false,DROPITEM_PHASE1,true /* force removal of linked items */); + // proc_run('php','include/notifier.php','drop',$i['id']); } } @@ -152,6 +160,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']); @@ -172,34 +183,29 @@ function photos_post(&$a) { ); if($r) { +/* q("DELETE FROM `photo` WHERE `uid` = %d AND `resource_id` = '%s'", 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 +213,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]; @@ -228,15 +233,46 @@ function photos_post(&$a) { intval($page_owner_uid) ); if(count($r)) { - $ph = photo_factory(dbunescbin($r[0]['data']), $r[0]['type']); + $d = (($r[0]['os_storage']) ? @file_get_contents($r[0]['data']) : dbunescbin($r[0]['data'])); + $ph = photo_factory($d, $r[0]['type']); if($ph->is_valid()) { $rotate_deg = ( (intval($_POST['rotate']) == 1) ? 270 : 90 ); $ph->rotate($rotate_deg); $width = $ph->getWidth(); $height = $ph->getHeight(); + + if(intval($r[0]['os_storage'])) { + @file_put_contents($r[0]['data'],$ph->imageString()); + $data = $r[0]['data']; + $fsize = @filesize($r[0]['data']); + q("update attach set filesize = %d where hash = '%s' and uid = %d limit 1", + intval($fsize), + dbesc($resource_id), + intval($page_owner_uid) + ); + } + else { + $data = $ph->imageString(); + $fsize = strlen($data); + } + + $x = q("update photo set data = '%s', `size` = %d, height = %d, width = %d where `resource_id` = '%s' and uid = %d and scale = 0", + dbescbin($data), + intval($fsize), + intval($height), + intval($width), + dbesc($resource_id), + intval($page_owner_uid) + ); + + if($width > 1024 || $height > 1024) + $ph->scaleImage(1024); + + $width = $ph->getWidth(); + $height = $ph->getHeight(); - $x = q("update photo set data = '%s', height = %d, width = %d where `resource_id` = '%s' and uid = %d and scale = 0", + $x = q("update photo set data = '%s', height = %d, width = %d where `resource_id` = '%s' and uid = %d and scale = 1", dbescbin($ph->imageString()), intval($height), intval($width), @@ -244,51 +280,52 @@ function photos_post(&$a) { intval($page_owner_uid) ); - if($width > 640 || $height > 640) { + + if($width > 640 || $height > 640) $ph->scaleImage(640); - $width = $ph->getWidth(); - $height = $ph->getHeight(); - - $x = q("update photo set data = '%s', height = %d, width = %d where `resource_id` = '%s' and uid = %d and scale = 1", - dbescbin($ph->imageString()), - intval($height), - intval($width), - dbesc($resource_id), - intval($page_owner_uid) - ); - } - if($width > 320 || $height > 320) { + $width = $ph->getWidth(); + $height = $ph->getHeight(); + + $x = q("update photo set data = '%s', height = %d, width = %d where `resource_id` = '%s' and uid = %d and scale = 2", + dbescbin($ph->imageString()), + intval($height), + intval($width), + dbesc($resource_id), + intval($page_owner_uid) + ); + + + if($width > 320 || $height > 320) $ph->scaleImage(320); - $width = $ph->getWidth(); - $height = $ph->getHeight(); - $x = q("update photo set data = '%s', height = %d, width = %d where `resource_id` = '%s' and uid = %d and scale = 2", - dbescbin($ph->imageString()), - intval($height), - intval($width), - dbesc($resource_id), - intval($page_owner_uid) - ); - } + $width = $ph->getWidth(); + $height = $ph->getHeight(); + + $x = q("update photo set data = '%s', height = %d, width = %d where `resource_id` = '%s' and uid = %d and scale = 3", + dbescbin($ph->imageString()), + intval($height), + intval($width), + dbesc($resource_id), + intval($page_owner_uid) + ); } } } - $p = q("SELECT * FROM `photo` WHERE `resource_id` = '%s' AND `uid` = %d ORDER BY `scale` DESC", + $p = q("SELECT type, is_nsfw, description, resource_id, scale, allow_cid, allow_gid, deny_cid, deny_gid FROM photo WHERE resource_id = '%s' AND uid = %d ORDER BY scale DESC", dbesc($resource_id), intval($page_owner_uid) ); 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 +333,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 +369,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 +454,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 +517,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 +543,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 +595,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,15 +607,25 @@ 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)'), - '$visible' => array('visible', t('Create a status post for this upload'), 0, '', array(t('No'), t('Yes'))), + '$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')), 'onclick="showHideBodyTextarea();"'), + '$caption' => array('description', t('Caption (optional):')), + '$body' => array('body', t('Description (optional):'),'', 'Description will only appear in the status post'), '$albums' => $albums['albums'], '$selname' => $selname, '$permissions' => t('Permissions'), @@ -590,22 +650,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 +682,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 +705,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 +809,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 +929,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 +958,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 +1004,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') ); @@ -954,13 +1021,13 @@ function photos_content(&$a) { $likebuttons = ''; if($can_post || $can_comment) { - $likebuttons = replace_macros($like_tpl,array( - '$id' => $link_item['id'], - '$likethis' => t("I like this \x28toggle\x29"), - '$nolike' => t("I don't like this \x28toggle\x29"), - '$share' => t('Share'), - '$wait' => t('Please wait') - )); + $likebuttons = array( + 'id' => $link_item['id'], + 'likethis' => t("I like this \x28toggle\x29"), + 'nolike' => t("I don't like this \x28toggle\x29"), + 'share' => t('Share'), + 'wait' => t('Please wait') + ); } $comments = ''; @@ -1119,7 +1186,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 +1230,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 +1246,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 c68ce9646..4c52de44a 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 @@ -701,9 +691,8 @@ function post_post(&$a) { * Any hub with the same URL and a different sitekey cannot be valid. * 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, hubloc_error = 1 where hubloc_url = '%s' and hubloc_sitekey != '%s' ", dbesc($hub['hubloc_url']), dbesc($sender['sitekey']) ); @@ -711,11 +700,12 @@ function post_post(&$a) { $sitekey = $sender['sitekey']; } - // $sender['sitekey'] is a new addition to the protcol to distinguish + // $sender['sitekey'] is a new addition to the protcol to distinguish // hublocs coming from re-installed sites. Older sites will not provide // this field and we have to still mark them valid, since we can't tell // if this hubloc has the same sitekey as the packet we received. + // Update our DB to show when we last communicated successfully with this hub // This will allow us to prune dead hubs from using up resources @@ -727,30 +717,26 @@ 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 and hubloc_sitekey = '%s' ", - intval(HUBLOC_OFFLINE), + if(intval($hub['hubloc_error'])) { + q("update hubloc set hubloc_error = 0 where hubloc_id = %d and hubloc_sitekey = '%s' ", intval($hub['hubloc_id']), dbesc($sitekey) ); - if ($r[0]['hubloc_flags'] & HUBLOC_FLAGS_ORPHANCHECK) { - q("update hubloc set hubloc_flags = (hubloc_flags & ~%d) where hubloc_id = %d and hubloc_sitekey = '%s' ", - intval(HUBLOC_FLAGS_ORPHANCHECK), + if(intval($r[0]['hubloc_orphancheck'])) { + q("update hubloc set hubloc_orhpancheck = 0 where hubloc_id = %d and hubloc_sitekey = '%s' ", intval($hub['hubloc_id']), dbesc($sitekey) ); } - - 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']) ); } - + $connecting_url = $hub['hubloc_url']; } + /** @TODO check which hub is primary and take action if mismatched */ if (array_key_exists('recipients', $data)) 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/pubsites.php b/mod/pubsites.php index 726c681fa..ae8601366 100644 --- a/mod/pubsites.php +++ b/mod/pubsites.php @@ -13,6 +13,8 @@ function pubsites_content(&$a) { } $url .= '/sites'; + $o .= '<div class="generic-content-wrapper-styled">'; + $o .= '<h1>' . t('Public Sites') . '</h1>'; $o .= '<div class="descriptive-text">' . @@ -33,6 +35,9 @@ function pubsites_content(&$a) { } $o .= '</table>'; + + $o .= '</div>'; + } } return $o; diff --git a/mod/rate.php b/mod/rate.php index a3a36b4a9..f30afed64 100644 --- a/mod/rate.php +++ b/mod/rate.php @@ -22,8 +22,9 @@ function rate_init(&$a) { $a->poi = $r[0]; } else { - $r = q("select * from site where site_url like '%s' ", - dbesc('%' . $target) + $r = q("select * from site where site_url like '%s' and site_type = %d", + dbesc('%' . $target), + intval(SITE_TYPE_ZOT) ); if($r) { $a->data['site'] = $r[0]; diff --git a/mod/ratingsearch.php b/mod/ratingsearch.php index 9c4f2f827..173dd39ff 100644 --- a/mod/ratingsearch.php +++ b/mod/ratingsearch.php @@ -35,8 +35,9 @@ function ratingsearch_init(&$a) { if($p) $target = $p[0]['xchan_hash']; else { - $p = q("select * from site where site_url like '%s' ", - dbesc('%' . $hash) + $p = q("select * from site where site_url like '%s' and site_type = %d ", + dbesc('%' . $hash), + intval(SITE_TYPE_ZOT) ); if($p) { $target = strtolower($hash); diff --git a/mod/rbmark.php b/mod/rbmark.php index cbd32098b..4401e3626 100644 --- a/mod/rbmark.php +++ b/mod/rbmark.php @@ -77,7 +77,9 @@ function rbmark_content(&$a) { $channel = $a->get_channel(); - $m = menu_list($channel,'',MENU_BOOKMARK); + + $m = menu_list($channel['channel_id'],'',MENU_BOOKMARK); + $menus = array(); if($m) { $menus = array(0 => ''); 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/regdir.php b/mod/regdir.php index dce50e76a..7168c3373 100644 --- a/mod/regdir.php +++ b/mod/regdir.php @@ -86,8 +86,9 @@ function regdir_init(&$a) { if ($dirmode == DIRECTORY_MODE_STANDALONE) { $r = array(array('site_url' => z_root())); } else { - $r = q("select site_url from site where site_flags in ( 1, 2 ) and site_realm = '%s' $sql_extra ", - dbesc(get_directory_realm()) + $r = q("select site_url from site where site_flags in ( 1, 2 ) and site_realm = '%s' and site_type = %d $sql_extra ", + dbesc(get_directory_realm()), + intval(SITE_TYPE_ZOT) ); } if ($r) { 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..a0085fca9 100644 --- a/mod/search.php +++ b/mod/search.php @@ -35,6 +35,8 @@ function search_content(&$a,$update = 0, $load = false) { $o = '<div id="live-search"></div>' . "\r\n"; + $o = '<div class="generic-content-wrapper-styled">' . "\r\n"; + $o .= '<h3>' . t('Search') . '</h3>'; if(x($a->data,'search')) @@ -59,6 +61,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 +131,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 +150,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 +160,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']) ); } @@ -209,6 +214,8 @@ function search_content(&$a,$update = 0, $load = false) { $o .= conversation($a,$items,'search',$update,'client'); + $o .= '</div>'; + return $o; } diff --git a/mod/settings.php b/mod/settings.php index b0ba04dfc..9a18d8e48 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; } @@ -225,7 +218,8 @@ function settings_post(&$a) { check_form_security_token_redirectOnErr('/settings/account', 'settings_account'); - call_hooks('settings_account', $_POST); + call_hooks('account_settings_post', $_POST); +// call_hooks('settings_account', $_POST); $errs = array(); @@ -318,17 +312,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 +366,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 +393,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 +501,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 +657,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 +983,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,10 +1103,13 @@ 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'), t('%Y - current year, %m - current month')), + '$attach_path' => array('attach_path', t('Default file upload folder'), get_pconfig(local_channel(),'system','attach_path'), t('%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.'), + '$firefoxshare' => t('Firefox Share $Projectname provider'), )); call_hooks('settings_form',$o); diff --git a/mod/setup.php b/mod/setup.php index bba29921e..e5ac25965 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); @@ -288,7 +292,7 @@ function setup_content(&$a) { case 2: { // Database config - $dbhost = ((x($_POST,'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost'); + $dbhost = ((x($_POST,'dbhost')) ? notags(trim($_POST['dbhost'])) : '127.0.0.1'); $dbuser = notags(trim($_POST['dbuser'])); $dbport = intval(notags(trim($_POST['dbport']))); $dbpass = notags(trim($_POST['dbpass'])); @@ -308,7 +312,7 @@ function setup_content(&$a) { '$status' => $wizard_status, - '$dbhost' => array('dbhost', t('Database Server Name'), $dbhost, t('Default is localhost')), + '$dbhost' => array('dbhost', t('Database Server Name'), $dbhost, t('Default is 127.0.0.1')), '$dbport' => array('dbport', t('Database Port'), $dbport, t('Communication port number - use 0 for default')), '$dbuser' => array('dbuser', t('Database Login Name'), $dbuser, ''), '$dbpass' => array('dbpass', t('Database Login Password'), $dbpass, ''), @@ -330,7 +334,7 @@ function setup_content(&$a) { }; break; case 3: { // Site settings require_once('include/datetime.php'); - $dbhost = ((x($_POST,'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost'); + $dbhost = ((x($_POST,'dbhost')) ? notags(trim($_POST['dbhost'])) : '127.0.0.1'); $dbport = intval(notags(trim($_POST['dbuser']))); $dbuser = notags(trim($_POST['dbuser'])); $dbpass = notags(trim($_POST['dbpass'])); diff --git a/mod/share.php b/mod/share.php index d5a389bdf..7ed6cf9a6 100644 --- a/mod/share.php +++ b/mod/share.php @@ -42,6 +42,12 @@ function share_init(&$a) { xchan_query($r); + $is_photo = (($r[0]['obj_type'] === ACTIVITY_OBJ_PHOTO) ? true : false); + if($is_photo) { + $object = json_decode($r[0]['object'],true); + $photo_bb = $object['bbcode']; + } + if (strpos($r[0]['body'], "[/share]") !== false) { $pos = strpos($r[0]['body'], "[share"); $o = substr($r[0]['body'], $pos); @@ -53,9 +59,9 @@ function share_init(&$a) { "' posted='".$r[0]['created']. "' message_id='".$r[0]['mid']."']"; if($r[0]['title']) - $o .= '[b]'.$r[0]['title'].'[/b]'."\n"; - $o .= $r[0]['body']; - $o.= "[/share]"; + $o .= '[b]'.$r[0]['title'].'[/b]'."\r\n"; + $o .= (($is_photo) ? $photo_bb . "\r\n" . $r[0]['body'] : $r[0]['body']); + $o .= "[/share]"; } if(local_channel()) { diff --git a/mod/siteinfo.php b/mod/siteinfo.php index c5a1cf12b..2fffccc73 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.'), + '$visit' => t('Please visit <a href="http://hubzilla.org">hubzilla.org</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/sitelist.php b/mod/sitelist.php index 12911cbd4..30b2359ac 100644 --- a/mod/sitelist.php +++ b/mod/sitelist.php @@ -28,7 +28,9 @@ function sitelist_init(&$a) { $result = array('success' => false); - $r = q("select count(site_url) as total from site where true $sql_extra "); + $r = q("select count(site_url) as total from site where site_type = %d $sql_extra ", + intval(SITE_TYPE_ZOT) + ); if($r) $result['total'] = intval($r[0]['total']); @@ -36,7 +38,9 @@ function sitelist_init(&$a) { $result['start'] = $start; $result['limit'] = $limit; - $r = q("select * from site where true $sql_extra $sql_order $sql_limit"); + $r = q("select * from site where site_type = %d $sql_extra $sql_order $sql_limit", + intval(SITE_TYPE_ZOT) + ); $result['results'] = 0; $result['entries'] = array(); 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..162545a2f 100755 --- a/mod/subthread.php +++ b/mod/subthread.php @@ -11,9 +11,12 @@ function subthread_content(&$a) { return; } - $activity = ACTIVITY_FOLLOW; + if(argv(1) === 'sub') + $activity = ACTIVITY_FOLLOW; + elseif(argv(1) === 'unsub') + $activity = ACTIVITY_UNFOLLOW; - $item_id = ((argc() > 1) ? notags(trim(argv(1))) : 0); + $item_id = ((argc() > 2) ? notags(trim(argv(2))) : 0); $r = q("SELECT * FROM `item` WHERE `parent` = '%s' OR `parent_mid` = '%s' and parent = id LIMIT 1", dbesc($item_id), @@ -67,6 +70,8 @@ function subthread_content(&$a) { killme(); + + $mid = item_message_id(); $post_type = (($item['resource_type'] === 'photo') ? t('photo') : t('status')); @@ -96,30 +101,31 @@ 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; - + if($activity === ACTIVITY_FOLLOW) + $bodyverb = t('%1$s is following %2$s\'s %3$s'); + if($activity === ACTIVITY_UNFOLLOW) + $bodyverb = t('%1$s stopped following %2$s\'s %3$s'); $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]'; @@ -146,100 +152,7 @@ function subthread_content(&$a) { killme(); - - - - - - - - - - - - - - - - - - - - - - - - - - $post_type = (($item['resource_id']) ? t('photo') : t('status')); - $objtype = (($item['resource_id']) ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE ); - - $link = xmlify('<link rel="alternate" type="text/html" href="' . $a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . '" />' . "\n") ; - $body = $item['body']; - - $obj = <<< EOT - - <object> - <type>$objtype</type> - <local>1</local> - <id>{$item['mid']}</id> - <link>$link</link> - <title></title> - <content>$body</content> - </object> -EOT; - - $arr = array(); - - $arr['mid'] = $mid; - $arr['uid'] = $owner_uid; - $arr['contact-id'] = $contact['id']; - $arr['type'] = 'activity'; - $arr['wall'] = $item['wall']; - $arr['origin'] = 1; - $arr['gravity'] = GRAVITY_LIKE; - $arr['parent'] = $item['id']; - $arr['parent-mid'] = $item['mid']; - $arr['thr_parent'] = $item['mid']; - $arr['owner-name'] = $remote_owner['name']; - $arr['owner-link'] = $remote_owner['url']; - $arr['owner-avatar'] = $remote_owner['thumb']; - $arr['author-name'] = $contact['name']; - $arr['author-link'] = $contact['url']; - $arr['author-avatar'] = $contact['thumb']; - - $ulink = '[zrl=' . $contact['url'] . ']' . $contact['name'] . '[/zrl]'; - $alink = '[zrl=' . $item['author-link'] . ']' . $item['author-name'] . '[/zrl]'; - $plink = '[zrl=' . $a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . ']' . $post_type . '[/zrl]'; - $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink ); - - $arr['verb'] = $activity; - $arr['object-type'] = $objtype; - $arr['object'] = $obj; - $arr['allow_cid'] = $item['allow_cid']; - $arr['allow_gid'] = $item['allow_gid']; - $arr['deny_cid'] = $item['deny_cid']; - $arr['deny_gid'] = $item['deny_gid']; - $arr['visible'] = 1; - $arr['unseen'] = 1; - $arr['last-child'] = 0; - - $post = item_store($arr); - $post_id = $post['item_id']; - - if(! $item['visible']) { - $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d AND `uid` = %d", - intval($item['id']), - intval($owner_uid) - ); - } - - $arr['id'] = $post_id; - - call_hooks('post_local_end', $arr); - - killme(); - } + 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..b1b81473b --- /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['account'] = $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 06b9d90ea..ee22383a3 100644 --- a/mod/uexport.php +++ b/mod/uexport.php @@ -41,26 +41,24 @@ function uexport_init(&$a) { } function uexport_content(&$a) { - + $y = datetime_convert('UTC',date_default_timezone_get(),'now','Y'); - $ly = $y-1; - $expurl = z_root() . '/uexport'; + $yearurl = z_root() . '/uexport/' . $y; + $janurl = z_root() . '/uexport/' . $y . '/1'; + $impurl = '/import_items'; $o = replace_macros(get_markup_template('uexport.tpl'), array( '$title' => t('Export Channel'), '$basictitle' => t('Export Channel'), '$basic' => t('Export your basic channel information to a 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 server hub, but does not contain your content.'), '$fulltitle' => t('Export Content'), '$full' => t('Export your channel information and recent content to a JSON backup that can be restored or imported to another server hub. This backs up all of your connections, permissions, profile data and several months 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 or month:'), + '$by_year' => t('Export your posts from a given year.'), - '$extra' => t('You may also export your posts and conversations for a particular year or month. Click on one of the recent years or months below.'), - '$extra2' => sprintf( '<a href="%1$s/%2$s">%2$s</a>: <a href="%1$s/%2$s/1">' . t('Jan') . '</a> <a href="%1$s/%2$s/2">' . t('Feb') . '</a> <a href="%1$s/%2$s/3">' . t('Mar') . '</a> <a href="%1$s/%2$s/4">' . t('Apr') . '</a> <a href="%1$s/%2$s/5">' . t('May') . '</a> <a href="%1$s/%2$s/6">' . t('Jun') . '</a> <a href="%1$s/%2$s/7">' . t('Jul') . '</a> <a href="%1$s/%2$s/8">' . t('Aug') . '</a> <a href="%1$s/%2$s/9">' . t('Sep') . '</a> <a href="%1$s/%2$s/10"> ' . t('Oct') . '</a> <a href="%1$s/%2$s/11">' . t('Nov') . '</a> <a href="%1$s/%2$s/12">' . t('Dec') . '</a>',$expurl,$ly), - '$extra3' => sprintf( '<a href="%1$s/%2$s">%2$s</a>: <a href="%1$s/%2$s/1">' . t('Jan') . '</a> <a href="%1$s/%2$s/2">' . t('Feb') . '</a> <a href="%1$s/%2$s/3">' . t('Mar') . '</a> <a href="%1$s/%2$s/4">' . t('Apr') . '</a> <a href="%1$s/%2$s/5">' . t('May') . '</a> <a href="%1$s/%2$s/6">' . t('Jun') . '</a> <a href="%1$s/%2$s/7">' . t('Jul') . '</a> <a href="%1$s/%2$s/8">' . t('Aug') . '</a> <a href="%1$s/%2$s/9">' . t('Sep') . '</a> <a href="%1$s/%2$s/10"> ' . t('Oct') . '</a> <a href="%1$s/%2$s/11">' . t('Nov') . '</a> <a href="%1$s/%2$s/12">' . t('Dec') . '</a>',$expurl,$y), - '$extra4' => t('If the export fails (possibly due to memory exhaustion on your server hub), please try again selecting a more limited date range.'), - '$extra5' => sprintf( t('Or adjust the date in your browser location bar to select other dates. For example the year 2013; <a href="%1$s/2013">%1$s/2013</a> or the month September 2013; <a href="%1$s/2013/9">%1$s/2013/9</a>'),$expurl), - '$extra6' => t('Please visit') . ' https://hub.tld/import_items ' . t('on another hub to import the backup files(s).'), - '$extra7' => t('We advise you to clone the channel on the new hub first and than to import the backup file(s) (from the same channel) in chronological order. Importing the backup files into another channel will certainly give permission issues.') + '$extra' => t('You may also export your posts and conversations for a particular year or month. Adjust the date in your browser location bar to select other dates. If the export fails (possibly due to memory exhaustion on your server hub), please try again selecting a more limited date range.'), + '$extra2' => sprintf( t('To select all posts for a given year, such as this year, visit <a href="%1$s">%2$s</a>'),$yearurl,$yearurl), + '$extra3' => sprintf( t('To select all posts for a given month, such as January of this year, visit <a href="%1$s">%2$s</a>'),$janurl,$janurl), + '$extra4' => sprintf( t('These content files may be imported or restored by visiting <a href="%1$s">%2$s</a> on any site containing your channel. For best results please import or restore these in date order (oldest first).'),$impurl,$impurl) )); 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 6d750b48d..fff7c9e1b 100644 --- a/mod/zfinger.php +++ b/mod/zfinger.php @@ -5,303 +5,8 @@ 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); - - 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'; - - $ret['site']['project'] = PLATFORM_NAME; - - // 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); + $x = zotinfo($_REQUEST); + json_return_and_die($x); } 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.'; |