diff options
Diffstat (limited to 'mod')
126 files changed, 10020 insertions, 5179 deletions
diff --git a/mod/_well_known.php b/mod/_well_known.php index 5c5f6585f..d88bc2391 100644 --- a/mod/_well_known.php +++ b/mod/_well_known.php @@ -3,12 +3,11 @@ function _well_known_init(&$a){
if(argc() > 1) {
- switch(argv(1)) {
- case "host-meta":
- require_once('mod/hostxrd.php');
- hostxrd_init($a);
- break;
+ $arr = array('server' => $_SERVER, 'request' => $_REQUEST);
+ call_hooks('well_known', $arr);
+
+ switch(argv(1)) {
case 'zot-info':
$a->argc -= 1;
array_shift($a->argv);
@@ -17,6 +16,25 @@ function _well_known_init(&$a){ zfinger_init($a);
break;
+ case 'webfinger':
+ $a->argc -= 1;
+ array_shift($a->argv);
+ $a->argv[0] = 'wfinger';
+ require_once('mod/wfinger.php');
+ wfinger_init($a);
+ break;
+
+ case 'host-meta':
+ $a->argc -= 1;
+ array_shift($a->argv);
+ $a->argv[0] = 'hostxrd';
+ require_once('mod/hostxrd.php');
+ hostxrd_init($a);
+ break;
+
+ default:
+ break;
+
}
}
diff --git a/mod/achievements.php b/mod/achievements.php new file mode 100644 index 000000000..1910def73 --- /dev/null +++ b/mod/achievements.php @@ -0,0 +1,84 @@ +<?php + +function achievements_content(&$a) { + + if(argc() > 1) + $which = argv(1); + else { + notice( t('Requested profile is not available.') . EOL ); + return; +} + + $profile = 0; + $profile = argv(1); + profile_load($a,$which,$profile); + + $r = q("select channel_id from channel where channel_address = '%s'", + dbesc($which) + ); + if($r) { + $owner = intval($r[0]['channel_id']); + } + + $observer = $a->get_observer(); + $ob_hash = (($observer) ? $observer['xchan_hash'] : ''); + $perms = get_all_perms($owner,$ob_hash); + if(! $perms['view_profile']) { + notice( t('Permission denied.') . EOL); + return; + } + +// By default, all badges are false + $contactbadge = false; + $profilebadge = false; + $keywordsbadge = false; + +// Check number of contacts. Award a badge if over 10 +// We'll figure these out on each page load instead of +// writing them to the DB because that will mean one needs +// to retain their achievements - eg, you can't add +// a bunch of channels just to get your badge, and then +// delete them all again. If these become popular or +// used in profiles or something, we may need to reconsider +// and add a table for this - because this won't scale. + + $r = q("select * from abook where abook_channel = %d", + intval($owner) + ); + + if (count($r)) + $contacts = count($r); + // We're checking for 11 to adjust for the abook record for self + if ($contacts >= 11) + $contactbadge = true; + +// Check if an about field in the profile has been created. + + $r = q("select * from profile where uid = %d and about <> ''", + intval($owner) + ); + + if ($r) + $profilebadge = 1; + +// Check if keywords have been set + + $r = q("select * from profile where uid = %d and keywords <> ''", + intval($owner) + ); + + if($r) + $keywordsbadge = 1; + +// FIXME - stick ths in a template, and make it look pretty. + $o .= "Template not implemented"; + $o .= "If this is one, you get the profile badge" . $profilebadge . "<br>"; + $o .= "If this is one, you get the contact badge" . $contactbadge . "<br>"; + $o .= "If this is one you get the keywords badge" . $keywordsbadge . "<br>"; + $o .= "I haven't done the top level posts badge yet" . $toplevelpostsbadge . "<br>"; + $o .= "I haven't done the number of channels badge yet" . $channelsbadge; + + +return $o; + +} diff --git a/mod/acl.php b/mod/acl.php index 2f1866f85..fa399a9b5 100644 --- a/mod/acl.php +++ b/mod/acl.php @@ -39,7 +39,7 @@ function acl_init(&$a){ // count groups and contacts if ($type=='' || $type=='g'){ - $r = q("SELECT COUNT(`id`) AS g FROM `group` WHERE `deleted` = 0 AND `uid` = %d $sql_extra", + $r = q("SELECT COUNT(`id`) AS g FROM `groups` WHERE `deleted` = 0 AND `uid` = %d $sql_extra", intval(local_user()) ); $group_count = (int)$r[0]['g']; @@ -49,37 +49,52 @@ function acl_init(&$a){ if ($type=='' || $type=='c'){ $r = q("SELECT COUNT(abook_id) AS c FROM abook left join xchan on abook_xchan = xchan_hash - WHERE abook_channel = %d AND not ( abook_flags & %d ) $sql_extra2" , + WHERE abook_channel = %d AND not ( abook_flags & %d ) and not (xchan_flags & %d ) $sql_extra2" , intval(local_user()), - intval(ABOOK_FLAG_SELF|ABOOK_FLAG_BLOCKED|ABOOK_FLAG_PENDING|ABOOK_FLAG_ARCHIVE) + intval(ABOOK_FLAG_BLOCKED|ABOOK_FLAG_PENDING|ABOOK_FLAG_ARCHIVED), + intval(XCHAN_FLAGS_DELETED) ); $contact_count = (int)$r[0]['c']; + + if(intval(get_config('system','taganyone')) || intval(get_pconfig(local_user(),'system','taganyone'))) { + if(((! $r) || (! $r[0]['total'])) && $type == 'c') { + $r = q("SELECT COUNT(xchan_hash) AS c FROM xchan + WHERE not (xchan_flags & %d ) $sql_extra2" , + intval(XCHAN_FLAGS_DELETED) + ); + $contact_count = (int)$r[0]['c']; + } + } + } elseif ($type == 'm') { // autocomplete for Private Messages - $r = q("SELECT COUNT(`id`) AS c FROM `contact` - WHERE `uid` = %d AND `self` = 0 - AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 - AND `network` IN ('%s','%s','%s') $sql_extra2" , + + $r = q("SELECT count(xchan_hash) as c + FROM abook left join xchan on abook_xchan = xchan_hash + WHERE abook_channel = %d and ( (abook_their_perms = null) or (abook_their_perms & %d )) + and not ( xchan_flags & %d ) + $sql_extra2 ", intval(local_user()), - dbesc(NETWORK_DFRN), - dbesc(NETWORK_ZOT), - dbesc(NETWORK_DIASPORA) + intval(PERMS_W_MAIL), + intval(XCHAN_FLAGS_DELETED) ); - $contact_count = (int)$r[0]['c']; + + if($r) + $contact_count = (int)$r[0]['c']; } elseif ($type == 'a') { // autocomplete for Contacts - $r = q("SELECT COUNT(`id`) AS c FROM `contact` - WHERE `uid` = %d AND `self` = 0 - AND `pending` = 0 $sql_extra2" , - intval(local_user()) + $r = q("SELECT COUNT(abook_id) AS c FROM abook left join xchan on abook_xchan = xchan_hash + WHERE abook_channel = %d and not ( xchan_flags & %d ) $sql_extra2" , + intval(local_user()), + intval(XCHAN_FLAGS_DELETED) ); $contact_count = (int)$r[0]['c']; @@ -94,14 +109,14 @@ function acl_init(&$a){ if ($type=='' || $type=='g'){ - $r = q("SELECT `group`.`id`, `group`.`hash`, `group`.`name`, + $r = q("SELECT `groups`.`id`, `groups`.`hash`, `groups`.`name`, GROUP_CONCAT(DISTINCT `group_member`.`xchan` SEPARATOR ',') as uids - FROM `group`,`group_member` - WHERE `group`.`deleted` = 0 AND `group`.`uid` = %d - AND `group_member`.`gid`=`group`.`id` + FROM `groups`,`group_member` + WHERE `groups`.`deleted` = 0 AND `groups`.`uid` = %d + AND `group_member`.`gid`=`groups`.`id` $sql_extra - GROUP BY `group`.`id` - ORDER BY `group`.`name` + GROUP BY `groups`.`id` + ORDER BY `groups`.`name` LIMIT %d,%d", intval(local_user()), intval($start), @@ -121,32 +136,47 @@ function acl_init(&$a){ ); } } - + if ($type=='' || $type=='c') { - $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 + $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 FROM abook left join xchan on abook_xchan = xchan_hash - WHERE abook_channel = %d AND not ( abook_flags & %d ) $sql_extra2 order by xchan_name asc" , + WHERE abook_channel = %d AND not ( abook_flags & %d ) and not (xchan_flags & %d ) $sql_extra2 order by xchan_name asc" , intval(local_user()), - intval(ABOOK_FLAG_SELF|ABOOK_FLAG_BLOCKED|ABOOK_FLAG_PENDING|ABOOK_FLAG_ARCHIVE) + intval(ABOOK_FLAG_BLOCKED|ABOOK_FLAG_PENDING|ABOOK_FLAG_ARCHIVED), + intval(XCHAN_FLAGS_DELETED) ); + if(intval(get_config('system','taganyone')) || intval(get_pconfig(local_user(),'system','taganyone'))) { + if((! $r) && $type == 'c') { + $r = 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 + FROM xchan + WHERE not (xchan_flags & %d ) $sql_extra2 order by xchan_name asc" , + intval(XCHAN_FLAGS_DELETED) + ); + } + } } elseif($type == 'm') { $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 )) + and not (xchan_flags & %d) $sql_extra3 ORDER BY `xchan_name` ASC ", intval(local_user()), - intval(PERMS_W_MAIL) + intval(PERMS_W_MAIL), + intval(XCHAN_FLAGS_DELETED) ); } elseif($type == 'a') { - $r = q("SELECT abook_id as id, xchan_name as name, xchan_addr as nick, xchan_photo_s as micro, xchan_network as network, xchan_url as url, xchan_addr as attag FROM abook left join xchan on abook_xchan = xchan_hash + $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) $sql_extra3 ORDER BY xchan_name ASC ", - intval(local_user()) + intval(local_user()), + intval(XCHAN_FLAGS_DELETED) + ); } elseif($type == 'x') { @@ -195,14 +225,31 @@ function acl_init(&$a){ if(count($r)) { foreach($r as $g){ + if(($g['abook_their_perms'] & PERMS_W_TAGWALL) && $type == 'c') { + $contacts[] = array( + "type" => "c", + "photo" => "images/twopeople.png", + "name" => $g['name'] . '+', + "id" => $g['id'] . '+', + "xid" => $g['hash'], + "link" => $g['nick'], + "nick" => substr($g['nick'],0,strpos($g['nick'],'@')), + "self" => (($g['abook_flags'] & ABOOK_FLAG_SELF) ? 'abook-self' : ''), + "taggable" => 'taggable', + "label" => t('network') + ); + } $contacts[] = array( - "type" => "c", - "photo" => $g['micro'], - "name" => $g['name'], - "id" => $g['id'], - "xid" => $g['hash'], - "link" => $g['nick'], - "nick" => substr($g['nick'],0,strpos($g['nick'],'@')) + "type" => "c", + "photo" => $g['micro'], + "name" => $g['name'], + "id" => $g['id'], + "xid" => $g['hash'], + "link" => $g['nick'], + "nick" => substr($g['nick'],0,strpos($g['nick'],'@')), + "self" => (($g['abook_flags'] & ABOOK_FLAG_SELF) ? 'abook-self' : ''), + "taggable" => '', + "label" => '', ); } } @@ -226,6 +273,10 @@ function navbar_complete(&$a) { // logger('navbar_complete'); + if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { + return; + } + $dirmode = intval(get_config('system','directory_mode')); $search = ((x($_REQUEST,'query')) ? htmlentities($_REQUEST['query'],ENT_COMPAT,'UTF-8',false) : ''); if(! $search || mb_strlen($search) < 2) @@ -251,14 +302,9 @@ function navbar_complete(&$a) { } if(! $url) { + require_once("include/dir_fns.php"); $directory = find_upstream_directory($dirmode); - - if($directory) { - $url = $directory['url']; - } - else { - $url = DIRECTORY_FALLBACK_MASTER . '/dirsearch'; - } + $url = $directory['url'] . '/dirsearch'; } if($url) { @@ -275,4 +321,4 @@ function navbar_complete(&$a) { } } return array(); -}
\ No newline at end of file +} diff --git a/mod/admin.php b/mod/admin.php index aa3d7b294..74e2d8f56 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -1,7 +1,7 @@ <?php /** - * Friendica admin + * Red admin */ @@ -9,7 +9,7 @@ * @param App $a */ function admin_post(&$a){ - + logger('admin_post', LOGGER_DEBUG); if(!is_site_admin()) { return; @@ -24,6 +24,10 @@ function admin_post(&$a){ case 'users': admin_page_users_post($a); break; + case 'channels': + admin_page_channels_post($a); + break; + case 'plugins': if (argc() > 2 && is_file("addon/" . argv(2) . "/" . argv(2) . ".php")){ @@ -49,11 +53,15 @@ function admin_post(&$a){ if(is_ajax()) return; goaway($a->get_baseurl(true) . '/admin/themes/' . $theme ); + return; break; case 'logs': admin_page_logs_post($a); break; + case 'hubloc': + admin_page_hubloc_post($a); + break; case 'dbsync': admin_page_dbsync_post($a); break; @@ -70,6 +78,7 @@ function admin_post(&$a){ */ function admin_content(&$a) { + logger('admin_content', LOGGER_DEBUG); if(!is_site_admin()) { return login(false); } @@ -80,11 +89,13 @@ function admin_content(&$a) { // 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("Users") , "users"), - 'plugins'=> Array($a->get_baseurl(true)."/admin/plugins/", t("Plugins") , "plugins"), - 'themes' => Array($a->get_baseurl(true)."/admin/themes/", t("Themes") , "themes"), - 'dbsync' => Array($a->get_baseurl(true)."/admin/dbsync/", t('DB updates'), "dbsync") + '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"), + 'hubloc' => Array($a->get_baseurl(true)."/admin/hubloc/", t("Server") , "server"), + 'dbsync' => Array($a->get_baseurl(true)."/admin/dbsync/", t('DB updates'), "dbsync") ); /* get plugins admin page */ @@ -126,12 +137,18 @@ function admin_content(&$a) { case 'users': $o = admin_page_users($a); break; + case 'channels': + $o = admin_page_channels($a); + break; case 'plugins': $o = admin_page_plugins($a); break; case 'themes': $o = admin_page_themes($a); break; + case 'hubloc': + $o = admin_page_hubloc($a); + break; case 'logs': $o = admin_page_logs($a); break; @@ -188,7 +205,7 @@ function admin_page_summary(&$a) { '$users' => Array( t('Registered users'), $users), '$accounts' => $accounts, '$pending' => Array( t('Pending registrations'), $pending), - '$version' => Array( t('Version'), FRIENDICA_VERSION), + '$version' => Array( t('Version'), RED_VERSION), '$build' => get_config('system','db_version'), '$plugins' => Array( t('Active plugins'), $a->plugins ) )); @@ -207,13 +224,18 @@ function admin_page_site_post(&$a){ check_form_security_token_redirectOnErr('/admin/site', 'admin_site'); $sitename = ((x($_POST,'sitename')) ? notags(trim($_POST['sitename'])) : ''); - $banner = ((x($_POST,'banner')) ? trim($_POST['banner']) : false); + $banner = ((x($_POST,'banner')) ? trim($_POST['banner']) : false); + $admininfo = ((x($_POST,'admininfo')) ? trim($_POST['admininfo']) : false); $language = ((x($_POST,'language')) ? notags(trim($_POST['language'])) : ''); $theme = ((x($_POST,'theme')) ? notags(trim($_POST['theme'])) : ''); - $maximagesize = ((x($_POST,'maximagesize')) ? intval(trim($_POST['maximagesize'])) : 0); + $theme_mobile = ((x($_POST,'theme_mobile')) ? notags(trim($_POST['theme_mobile'])) : ''); + $theme_accessibility = ((x($_POST,'theme_accessibility')) ? notags(trim($_POST['theme_accessibility'])) : ''); + $site_channel = ((x($_POST,'site_channel')) ? notags(trim($_POST['site_channel'])) : ''); + $maximagesize = ((x($_POST,'maximagesize')) ? intval(trim($_POST['maximagesize'])) : 0); $register_policy = ((x($_POST,'register_policy')) ? intval(trim($_POST['register_policy'])) : 0); + $access_policy = ((x($_POST,'access_policy')) ? intval(trim($_POST['access_policy'])) : 0); $abandon_days = ((x($_POST,'abandon_days')) ? intval(trim($_POST['abandon_days'])) : 0); $register_text = ((x($_POST,'register_text')) ? notags(trim($_POST['register_text'])) : ''); @@ -222,6 +244,8 @@ function admin_page_site_post(&$a){ $allowed_email = ((x($_POST,'allowed_email')) ? notags(trim($_POST['allowed_email'])) : ''); $block_public = ((x($_POST,'block_public')) ? True : False); $force_publish = ((x($_POST,'publish_all')) ? True : False); + $disable_discover_tab = ((x($_POST,'disable_discover_tab')) ? True : False); + $no_login_on_homepage = ((x($_POST,'no_login_on_homepage')) ? True : False); $global_directory = ((x($_POST,'directory_submit_url')) ? notags(trim($_POST['directory_submit_url'])) : ''); $no_community_page = !((x($_POST,'no_community_page')) ? True : False); @@ -231,7 +255,7 @@ function admin_page_site_post(&$a){ $timeout = ((x($_POST,'timeout')) ? intval(trim($_POST['timeout'])) : 60); $delivery_interval = ((x($_POST,'delivery_interval'))? intval(trim($_POST['delivery_interval'])) : 0); $poll_interval = ((x($_POST,'poll_interval'))? intval(trim($_POST['poll_interval'])) : 0); - $ssl_policy = ((x($_POST,'ssl_policy')) ? intval($_POST['ssl_policy']) : 0); +// $ssl_policy = ((x($_POST,'ssl_policy')) ? intval($_POST['ssl_policy']) : 0); /* if($ssl_policy != intval(get_config('system','ssl_policy'))) { if($ssl_policy == SSL_POLICY_FULL) { @@ -274,11 +298,12 @@ function admin_page_site_post(&$a){ } } */ - set_config('system','ssl_policy',$ssl_policy); +// set_config('system','ssl_policy',$ssl_policy); set_config('system','delivery_interval',$delivery_interval); set_config('system','poll_interval',$poll_interval); set_config('system','maxloadavg',$maxloadavg); - set_config('config','sitename',$sitename); + set_config('system','sitename',$sitename); + set_config('system','no_login_on_homepage',$no_login_on_homepage); if ($banner=="") { del_config('system','banner'); @@ -287,17 +312,37 @@ function admin_page_site_post(&$a){ set_config('system','banner', $banner); } + if ($admininfo==''){ + del_config('system','admininfo'); + } + else { + set_config('system','admininfo', $admininfo); + } set_config('system','language', $language); set_config('system','theme', $theme); + if ( $theme_mobile === '---' ) { + del_config('system','mobile_theme'); + } else { + set_config('system','mobile_theme', $theme_mobile); + } + if ( $theme_accessibility === '---' ) { + del_config('system','accessibility_theme'); + } else { + set_config('system','accessibility_theme', $theme_accessibility); + } + + set_config('system','site_channel', $site_channel); set_config('system','maximagesize', $maximagesize); set_config('system','register_policy', $register_policy); + set_config('system','access_policy', $access_policy); set_config('system','account_abandon_days', $abandon_days); set_config('system','register_text', $register_text); set_config('system','allowed_sites', $allowed_sites); set_config('system','allowed_email', $allowed_email); set_config('system','block_public', $block_public); set_config('system','publish_all', $force_publish); + set_config('system','disable_discover_tab', $disable_discover_tab); if($global_directory=="") { del_config('system','directory_submit_url'); } @@ -337,14 +382,24 @@ function admin_page_site(&$a) { $lang_choices[$t[1]] = $t[1]; } } - + /* Installed themes */ $theme_choices = array(); + $theme_choices_mobile = array(); + $theme_choices_mobile["---"] = t("No special theme for mobile devices"); + $theme_choices_accessibility = array(); + $theme_choices_accessibility["---"] =t("No special theme for accessibility"); $files = glob('view/theme/*'); if($files) { foreach($files as $file) { $f = basename($file); - $theme_name = ((file_exists($file . '/.experimental')) ? sprintf("%s - Experimental", $f) : $f); + $theme_name = ((file_exists($file . '/experimental')) ? sprintf("%s - Experimental", $f) : $f); + if (file_exists($file . '/mobile')) { + $theme_choices_mobile[$f] = $theme_name; + } + if (file_exists($file . '/accessibility')) { + $theme_choices_accessibility[$f] = $theme_name; + } $theme_choices[$f] = $theme_name; } } @@ -356,17 +411,28 @@ function admin_page_site(&$a) { $banner = 'red'; $banner = htmlspecialchars($banner); + /* Admin Info */ + $admininfo = get_config('system','admininfo'); + /* Register policy */ $register_choices = Array( - REGISTER_CLOSED => t("Closed"), - REGISTER_APPROVE => t("Requires approval"), - REGISTER_OPEN => t("Open") + REGISTER_CLOSED => t("No"), + REGISTER_APPROVE => t("Yes - with approval"), + REGISTER_OPEN => t("Yes") ); - $ssl_choices = array( - SSL_POLICY_NONE => t("No SSL policy, links will track page SSL state"), - SSL_POLICY_FULL => t("Force all links to use SSL") + /* Acess policy */ + $access_choices = Array( + ACCESS_PRIVATE => t("My site is not a public server"), + ACCESS_PAID => t("My site has paid access only"), + ACCESS_FREE => t("My site has free access only"), + ACCESS_TIERED => t("My site offers free accounts with optional paid upgrades") ); + +// $ssl_choices = array( +// SSL_POLICY_NONE => t("No SSL policy, links will track page SSL state"), +// SSL_POLICY_FULL => t("Force all links to use SSL") +// ); $t = get_markup_template("admin_site.tpl"); return replace_macros($t, array( @@ -380,22 +446,27 @@ function admin_page_site(&$a) { '$baseurl' => $a->get_baseurl(true), // name, label, value, help string, extra data... - '$sitename' => array('sitename', t("Site name"), htmlentities($a->config['sitename'], ENT_QUOTES), ""), + '$sitename' => array('sitename', t("Site name"), htmlspecialchars(get_config('system','sitename'), ENT_QUOTES, 'UTF-8'),''), '$banner' => array('banner', t("Banner/Logo"), $banner, ""), + '$admininfo' => array('admininfo', t("Administrator Information"), $admininfo, t("Contact information for site administrators. Displayed on siteinfo page. BBCode can be used here")), '$language' => array('language', t("System language"), get_config('system','language'), "", $lang_choices), '$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), - '$ssl_policy' => array('ssl_policy', t("SSL link policy"), (string) intval(get_config('system','ssl_policy')), t("Determines whether generated links should be forced to use SSL"), $ssl_choices), - '$maximagesize' => array('maximagesize', t("Maximum image size"), 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("Register policy"), $a->config['system']['register_policy'], "", $register_choices), - '$register_text' => array('register_text', t("Register text"), htmlentities($a->config['register_text'], ENT_QUOTES, 'UTF-8'), t("Will be displayed prominently on the registration page.")), + '$theme_mobile' => array('theme_mobile', t("Mobile system theme"), get_config('system','mobile_theme'), t("Theme for mobile devices"), $theme_choices_mobile), + '$theme_accessibility' => array('theme_accessibility', t("Accessibility system theme"), get_config('system','accessibility_theme'), t("Accessibility theme"), $theme_choices_accessibility), + '$site_channel' => array('site_channel', t("Channel to use for this website's static pages"), get_config('system','site_channel'), t("Site Channel")), +// '$ssl_policy' => array('ssl_policy', t("SSL link policy"), (string) intval(get_config('system','ssl_policy')), t("Determines whether generated links should be forced to use SSL"), $ssl_choices), + '$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), + '$access_policy' => array('access_policy', t("Which best describes the types of account offered by this hub?"), get_config('system','access_policy'), "This is displayed on the public server site list.", $access_choices), + '$register_text' => array('register_text', t("Register text"), htmlspecialchars(get_config('system','register_text'), ENT_QUOTES, 'UTF-8'), t("Will be displayed prominently on the registration page.")), '$abandon_days' => array('abandon_days', t('Accounts abandoned after x days'), get_config('system','account_abandon_days'), t('Will not waste system resources polling external sites for abandonded accounts. Enter 0 for no time limit.')), '$allowed_sites' => array('allowed_sites', t("Allowed friend domains"), get_config('system','allowed_sites'), t("Comma separated list of domains which are allowed to establish friendships with this site. Wildcards are accepted. Empty to allow any domains")), '$allowed_email' => array('allowed_email', t("Allowed email domains"), get_config('system','allowed_email'), t("Comma separated list of domains which are allowed in email addresses for registrations to this site. Wildcards are accepted. Empty to allow any domains")), '$block_public' => array('block_public', t("Block public"), get_config('system','block_public'), t("Check to block public access to all otherwise public personal pages on this site unless you are currently logged in.")), '$force_publish' => array('publish_all', t("Force publish"), get_config('system','publish_all'), t("Check to force all profiles on this site to be listed in the site directory.")), - '$global_directory' => array('directory_submit_url', t("Global directory update URL"), get_config('system','directory_submit_url'), t("URL to update the global directory. If this is not set, the global directory is completely unavailable to the application.")), + '$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.")), + '$no_login_on_homepage' => array('no_login_on_homepage', t("No login on Homepage"), get_config('system','no_login_on_homepage'), t("Check to hide the login form from your sites homepage when visitors arrive who are not logged in (e.g. when you put the content of the homepage in via the site channel).")), - '$no_community_page' => array('no_community_page', t("Show Community Page"), !get_config('system','no_community_page'), t("Display a Community page showing all recent public postings on this site.")), '$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).")), @@ -407,6 +478,74 @@ function admin_page_site(&$a) { )); } +function admin_page_hubloc_post(&$a){ + check_form_security_token_redirectOnErr('/admin/hubloc', 'admin_hubloc'); + require_once('include/zot.php'); + + //prepare for ping + + if ( $_POST['hublocid']) { + $hublocid = $_POST['hublocid']; + $arrhublocurl = q("SELECT hubloc_url FROM hubloc WHERE hubloc_id = %d ", + intval($hublocid) + ); + $hublocurl = $arrhublocurl[0]['hubloc_url'] . '/post'; + + //perform ping + $m = zot_build_packet($a->get_channel(),'ping'); + $r = zot_zot($hublocurl,$m); + //handle results and set the hubloc flags in db to make results visible + $r2 = $r['body']; + $r3 = $r2['success']; + if ( $r3['success'] == True ){ + //set HUBLOC_OFFLINE to 0 + logger(' success = true ',LOGGER_DEBUG); + } else { + //set HUBLOC_OFFLINE to 1 + logger(' success = false ', LOGGER_DEBUG); + + } + + //unfotunatly zping wont work, I guess return format is not correct + //require_once('mod/zping.php'); + //$r = zping_content($hublocurl); + //logger('zping answer: ' . $r, LOGGER_DEBUG); + + + //in case of repair store new pub key for tested hubloc (all channel with this hubloc) in db + //after repair set hubloc flags to 0 + + } + + + goaway($a->get_baseurl(true) . '/admin/hubloc' ); + return; +} + +function admin_page_hubloc(&$a) { + $o = ''; + $hubloc = q("SELECT hubloc_id, hubloc_addr, hubloc_host, hubloc_status FROM hubloc"); + + + if(! $hubloc){ + notice( t('No server found') . EOL); + goaway($a->get_baseurl(true) . '/admin/hubloc'); + } + + $t = get_markup_template("admin_hubloc.tpl"); + return replace_macros($t, array( + '$hubloc' => $hubloc, + '$th_hubloc' => array(t('ID'), t('for channel'), t('on server'), t('Status')), + '$title' => t('Administration'), + '$page' => t('Server'), + '$queues' => $queues, + //'$accounts' => $accounts, /*$accounts is empty here*/ + '$pending' => Array( t('Pending registrations'), $pending), + '$plugins' => Array( t('Active plugins'), $a->plugins ), + '$form_security_token' => get_form_security_token("admin_hubloc") + )); + return $o; +} function admin_page_dbsync(&$a) { @@ -490,7 +629,7 @@ function admin_page_users_post(&$a){ if (x($_POST,'page_users_delete')){ require_once("include/Contact.php"); foreach($users as $uid){ - user_remove($uid); + account_remove($uid,true); } notice( sprintf( tt("%s user deleted", "%s users deleted", count($users)), count($users)) ); } @@ -532,9 +671,9 @@ function admin_page_users(&$a){ check_form_security_token_redirectOnErr('/admin/users', 'admin_users', 't'); // delete user require_once("include/Contact.php"); - user_remove($uid); + account_remove($uid,true); - notice( sprintf(t("User '%s' deleted"), $user[0]['username']) . EOL); + notice( sprintf(t("User '%s' deleted"), $account[0]['account_email']) . EOL); }; break; case "block":{ check_form_security_token_redirectOnErr('/admin/users', 'admin_users', 't'); @@ -543,7 +682,7 @@ function admin_page_users(&$a){ intval( $uid ) ); - notice( sprintf( (($account['account_flags'] & ACCOUNT_BLOCKED) ? t("User '%s' unblocked"):t("User '%s' blocked")) , $account[0]['account_email']) . EOL); + notice( sprintf( (($account[0]['account_flags'] & ACCOUNT_BLOCKED) ? t("User '%s' unblocked"):t("User '%s' blocked")) , $account[0]['account_email']) . EOL); }; break; } goaway($a->get_baseurl(true) . '/admin/users' ); @@ -552,7 +691,7 @@ function admin_page_users(&$a){ } /* get pending */ - $pending = q("SELECT * from account where (account_flags & %d ) ", + $pending = q("SELECT account.*, register.hash from account left join register on account_id = register.uid where (account_flags & %d ) ", intval(ACCOUNT_PENDING) ); @@ -564,40 +703,43 @@ function admin_page_users(&$a){ $a->set_pager_itemspage(100); } -// FIXME this is borked since there is no more user table - - $users = q("SELECT `user` . * , `contact`.`name` , `contact`.`url` , `contact`.`micro`, `lastitem`.`lastitem_date` - FROM - (SELECT MAX(`item`.`changed`) as `lastitem_date`, `item`.`uid` - FROM `item` - WHERE `item`.`type` = 'wall' - GROUP BY `item`.`uid`) AS `lastitem` - RIGHT OUTER JOIN `user` ON `user`.`uid` = `lastitem`.`uid`, - `contact` - WHERE - `user`.`uid` = `contact`.`uid` - AND `user`.`verified` =1 - AND `contact`.`self` =1 - ORDER BY `contact`.`name` LIMIT %d, %d - ", - intval($a->pager['start']), - intval($a->pager['itemspage']) - ); + +// WEe'll still need to link email addresses to admin/users/channels or some such, but this bit doesn't exist yet. +// That's where we need to be doing last post/channel flags/etc, not here. + + + $serviceclass = (($_REQUEST['class']) ? " and account_service_class = '" . dbesc($_REQUEST['class']) . "' " : ''); + + + $order = " order by account_email asc "; + if($_REQUEST['order'] === 'expires') + $order = " order by account_expires desc "; + + $users =q("SELECT `account_id` , `account_email`, `account_lastlog`, `account_created`, `account_expires`, " . "`account_service_class`, ( account_flags & %d ) > 0 as `blocked`, " . + "(SELECT GROUP_CONCAT( ch.channel_address SEPARATOR ' ') FROM channel as ch " . + "WHERE ch.channel_account_id = ac.account_id and not (ch.channel_pageflags & %d )) as `channels` " . + "FROM account as ac where true $serviceclass $order limit %d , %d ", + intval(ACCOUNT_BLOCKED), + intval(PAGE_REMOVED), + intval($a->pager['start']), + intval($a->pager['itemspage']) + ); - function _setup_users($e){ - $accounts = Array( - t('Normal Account'), - t('Soapbox Account'), - t('Community/Celebrity Account'), - t('Automatic Friend Account') - ); - $e['page_flags'] = $accounts[$e['page-flags']]; - $e['register_date'] = relative_date($e['register_date']); - $e['login_date'] = relative_date($e['login_date']); - $e['lastitem_date'] = relative_date($e['lastitem_date']); - return $e; - } - $users = array_map("_setup_users", $users); +// function _setup_users($e){ +// $accounts = Array( +// t('Normal Account'), +// t('Soapbox Account'), +// t('Community/Celebrity Account'), +// t('Automatic Friend Account') +// ); + +// $e['page_flags'] = $accounts[$e['page-flags']]; +// $e['register_date'] = relative_date($e['register_date']); +// $e['login_date'] = relative_date($e['login_date']); +// $e['lastitem_date'] = relative_date($e['lastitem_date']); +// return $e; +// } +// $users = array_map("_setup_users", $users); $t = get_markup_template("admin_users.tpl"); @@ -608,16 +750,16 @@ function admin_page_users(&$a){ '$submit' => t('Submit'), '$select_all' => t('select all'), '$h_pending' => t('User registrations waiting for confirm'), - '$th_pending' => array( t('Request date'), t('Name'), t('Email') ), + '$th_pending' => array( t('Request date'), t('Email') ), '$no_pending' => t('No registrations.'), '$approve' => t('Approve'), '$deny' => t('Deny'), '$delete' => t('Delete'), '$block' => t('Block'), '$unblock' => t('Unblock'), - + '$h_users' => t('Users'), - '$th_users' => array( t('Name'), t('Email'), t('Register date'), t('Last login'), t('Last item'), t('Account') ), + '$th_users' => array( t('ID'), t('Email'), t('All Channels'), t('Register date'), t('Last login'), t('Expires'), t('Service Class')), '$confirm_delete_multi' => t('Selected users will be deleted!\n\nEverything these users had posted on this site will be permanently deleted!\n\nAre you sure?'), '$confirm_delete' => t('The user {0} will be deleted!\n\nEverything this user has posted on this site will be permanently deleted!\n\nAre you sure?'), @@ -636,6 +778,133 @@ function admin_page_users(&$a){ /** + * Channels admin page + * + * @param App $a + */ +function admin_page_channels_post(&$a){ + $channels = ( x($_POST, 'channel') ? $_POST['channel'] : Array() ); + + check_form_security_token_redirectOnErr('/admin/channels', 'admin_channels'); + + if (x($_POST,'page_channels_block')){ + foreach($channels as $uid){ + q("UPDATE channel SET channel_pageflags = ( channel_pageflags ^ %d ) where channel_id = %d", + intval(PAGE_CENSORED), + intval( $uid ) + ); + } + notice( sprintf( tt("%s channel censored/uncensored", "%s channelss censored/uncensored", count($channels)), count($channels)) ); + } + if (x($_POST,'page_channels_delete')){ + require_once("include/Contact.php"); + foreach($channels as $uid){ + channel_remove($uid,true); + } + notice( sprintf( tt("%s channel deleted", "%s channels deleted", count($channels)), count($channels)) ); + } + + goaway($a->get_baseurl(true) . '/admin/channels' ); + return; // NOTREACHED +} + +/** + * @param App $a + * @return string + */ +function admin_page_channels(&$a){ + if (argc() > 2) { + $uid = argv(3); + $channel = q("SELECT * FROM channel WHERE channel_id = %d", + intval($uid) + ); + + if (! $channel) { + notice( t('Channel not found') . EOL); + goaway($a->get_baseurl(true) . '/admin/channels' ); + } + + switch(argv(2)){ + case "delete":{ + check_form_security_token_redirectOnErr('/admin/channels', 'admin_channels', 't'); + // delete channel + require_once("include/Contact.php"); + channel_remove($uid,true); + + notice( sprintf(t("Channel '%s' deleted"), $channel[0]['channel_name']) . EOL); + }; break; + + case "block":{ + check_form_security_token_redirectOnErr('/admin/channels', 'admin_channels', 't'); + q("UPDATE channel SET channel_pageflags = ( channel_pageflags ^ %d ) where channel_id = %d", + intval(PAGE_CENSORED), + intval( $uid ) + ); + + notice( sprintf( (($channel[0]['channel_pageflags'] & PAGE_CENSORED) ? t("Channel '%s' uncensored"): t("Channel '%s' censored")) , $channel[0]['channel_name'] . ' (' . $channel[0]['channel_address'] . ')' ) . EOL); + }; break; + } + goaway($a->get_baseurl(true) . '/admin/channels' ); + return ''; // NOTREACHED + + } + + /* get channels */ + + $total = q("SELECT count(*) as total FROM channel where not (channel_pageflags & %d)", + intval(PAGE_REMOVED) + ); + if($total) { + $a->set_pager_total($total[0]['total']); + $a->set_pager_itemspage(100); + } + + $order = " order by channel_name asc "; + + $channels = q("SELECT * from channel where not ( channel_pageflags & %d ) $order limit %d , %d ", + intval(PAGE_REMOVED), + intval($a->pager['start']), + intval($a->pager['itemspage']) + ); + + if($channels) { + for($x = 0; $x < count($channels); $x ++) { + if($channels[$x]['channel_pageflags'] & PAGE_CENSORED) + $channels[$x]['blocked'] = true; + else + $channels[$x]['blocked'] = false; + } + } + + $t = get_markup_template("admin_channels.tpl"); + $o = replace_macros($t, array( + // strings // + '$title' => t('Administration'), + '$page' => t('Channels'), + '$submit' => t('Submit'), + '$select_all' => t('select all'), + '$delete' => t('Delete'), + '$block' => t('Censor'), + '$unblock' => t('Uncensor'), + + '$h_channels' => t('Channel'), + '$th_channels' => array( t('UID'), t('Name'), t('Address')), + + '$confirm_delete_multi' => t('Selected channels will be deleted!\n\nEverything that was posted in these channels on this site will be permanently deleted!\n\nAre you sure?'), + '$confirm_delete' => t('The channel {0} will be deleted!\n\nEverything that was posted in this channel on this site will be permanently deleted!\n\nAre you sure?'), + + '$form_security_token' => get_form_security_token("admin_channels"), + + // values // + '$baseurl' => $a->get_baseurl(true), + '$channels' => $channels, + )); + $o .= paginate($a); + return $o; +} + + +/** * Plugins admin page * * @param App $a @@ -689,12 +958,16 @@ function admin_page_plugins(&$a){ } $admin_form=""; + if (is_array($a->plugins_admin) && in_array($plugin, $a->plugins_admin)){ @require_once("addon/$plugin/$plugin.php"); - $func = $plugin.'_plugin_admin'; - $func($a, $admin_form); + if(function_exists($plugin.'_plugin_admin')) { + $func = $plugin.'_plugin_admin'; + $func($a, $admin_form); + } } - + + $t = get_markup_template("admin_plugins_details.tpl"); return replace_macros($t, array( '$title' => t('Administration'), @@ -1035,7 +1308,7 @@ readable."); // name, label, value, help string, extra data... '$debugging' => array('debugging', t("Debugging"),get_config('system','debugging'), ""), - '$logfile' => array('logfile', t("Log file"), get_config('system','logfile'), t("Must be writable by web server. Relative to your Friendica top-level directory.")), + '$logfile' => array('logfile', t("Log file"), get_config('system','logfile'), t("Must be writable by web server. Relative to your Red top-level directory.")), '$loglevel' => array('loglevel', t("Log level"), get_config('system','loglevel'), "", $log_choices), '$form_security_token' => get_form_security_token("admin_logs"), diff --git a/mod/allfriends.php b/mod/allfriends.php deleted file mode 100644 index bb4df30be..000000000 --- a/mod/allfriends.php +++ /dev/null @@ -1,60 +0,0 @@ -<?php - -require_once('include/socgraph.php'); - -function allfriends_content(&$a) { - - $o = ''; - - if(! local_user()) { - notice( t('Permission denied.') . EOL); - return; - } - - if(argc() > 1) - $cid = intval(argv(1)); - if(! $cid) - return; - - $c = q("select name, url, photo from contact where id = %d and uid = %d limit 1", - intval($cid), - intval(local_user()) - ); - - $a->page['aside'] .= '<div class="vcard">' - . '<div class="fn label">' . $c[0]['name'] . '</div>' - . '<div id="profile-photo-wrapper">' - . '<a href="/contacts/' . $cid . '"><img class="photo" width="175" height="175" - src="' . $c[0]['photo'] . '" alt="' . $c[0]['name'] . '" /></div>' - . '</div>'; - - - if(! count($c)) - return; - - $o .= '<h2>' . sprintf( t('Friends of %s'), $c[0]['name']) . '</h2>'; - - - $r = all_friends(local_user(),$cid); - - if(! count($r)) { - $o .= t('No friends to display.'); - return $o; - } - - $tpl = get_markup_template('common_friends.tpl'); - - foreach($r as $rr) { - - $o .= replace_macros($tpl,array( - '$url' => $rr['url'], - '$name' => $rr['name'], - '$photo' => $rr['photo'], - '$tags' => '' - )); - } - - $o .= cleardiv(); -// $o .= paginate($a); - return $o; -} diff --git a/mod/attach.php b/mod/attach.php index a5f9d1a6b..cf72d09c6 100644 --- a/mod/attach.php +++ b/mod/attach.php @@ -17,12 +17,35 @@ function attach_init(&$a) { return; } - header('Content-type: ' . $r['data']['filetype']); - header('Content-disposition: attachment; filename=' . $r['data']['filename']); - if($r['data']['flags'] & ATTACH_FLAG_OS ) - echo @file_get_contents($r['data']['data']); + $c = q("select channel_address from channel where channel_id = %d limit 1", + intval($r['data']['uid']) + ); + + if(! $c) + return; + + + $unsafe_types = array('text/html','text/css','application/javascript'); + + if(in_array($r['data']['filetype'],$unsafe_types)) { + header('Content-type: text/plain'); + } + else { + header('Content-type: ' . $r['data']['filetype']); + } + + header('Content-disposition: attachment; filename="' . $r['data']['filename'] . '"'); + if($r['data']['flags'] & ATTACH_FLAG_OS ) { + $istream = fopen('store/' . $c[0]['channel_address'] . '/' . $r['data']['data'],'rb'); + $ostream = fopen('php://output','wb'); + if($istream && $ostream) { + pipe_streams($istream,$ostream); + fclose($istream); + fclose($ostream); + } + } else echo $r['data']['data']; killme(); -}
\ No newline at end of file +} diff --git a/mod/authtest.php b/mod/authtest.php new file mode 100644 index 000000000..b6d940db2 --- /dev/null +++ b/mod/authtest.php @@ -0,0 +1,54 @@ +<?php + +require_once('include/zot.php'); +require_once('mod/magic.php'); + +function authtest_content(&$a) { + + + $auth_success = false; + $o .= '<h3>Magic-Auth Diagnostic</h3>'; + + if(! local_user()) { + notice( t('Permission denied.') . EOL); + return $o; + } + + $o .= '<form action="authtest" method="get">'; + $o .= 'Target URL: <input type="text" style="width: 250px;" name="dest" value="' . $_GET['dest'] .'" />'; + $o .= '<input type="submit" name="submit" value="Submit" /></form>'; + + $o .= '<br /><br />'; + + if(x($_GET,'dest')) { + if(strpos($_GET['dest'],'@')) { + $_GET['dest'] = $_REQUEST['dest'] = 'https://' . substr($_GET['dest'],strpos($_GET['dest'],'@')+1) . '/channel/' . substr($_GET['dest'],0,strpos($_GET['dest'],'@')); + } + + $_REQUEST['test'] = 1; + $x = magic_init($a); + $o .= 'Local Setup returns: ' . print_r($x,true); + + + + if($x['url']) { + $z = z_fetch_url($x['url'] . '&test=1'); + if($z['success']) { + $j = json_decode($z['body'],true); + if(! $j) + $o .= 'json_decode failure from remote site. ' . print_r($z['body'],true); + $o .= 'Remote site responded: ' . print_r($j,true); + if($j['success'] && strpos($j['message'],'Authentication Success')) + $auth_success = true; + } + else { + $o .= 'fetch url failure.' . print_r($z,true); + } + } + + if(! $auth_success) + $o .= 'Authentication Failed!' . EOL; + } + + return str_replace("\n",'<br />',$o); +} diff --git a/mod/block.php b/mod/block.php new file mode 100644 index 000000000..043b0e9e8 --- /dev/null +++ b/mod/block.php @@ -0,0 +1,86 @@ +<?php + +require_once('include/items.php'); +require_once('include/conversation.php'); +require_once('include/page_widgets.php'); + +function block_init(&$a) { + + $which = argv(1); + $profile = 0; + profile_load($a,$which,$profile); + + if($a->profile['profile_uid']) + head_set_icon($a->profile['thumb']); + +} + + +function block_content(&$a) { + + if(! perm_is_allowed($a->profile['profile_uid'],get_observer_hash(),'view_pages')) { + notice( t('Permission denied.') . EOL); + return; + } + + if(argc() < 3) { + notice( t('Invalid item.') . EOL); + return; + } + + $channel_address = argv(1); + $page_id = argv(2); + + $u = q("select channel_id from channel where channel_address = '%s' limit 1", + dbesc($channel_address) + ); + + if(! $u) { + notice( t('Channel not found.') . EOL); + return; + } + + if($_REQUEST['rev']) + $revision = " and revision = " . intval($_REQUEST['rev']) . " "; + else + $revision = " order by revision desc "; + + require_once('include/security.php'); + $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 = 'BUILDBLOCK' and + item_restrict = %d $sql_options $revision limit 1", + intval($u[0]['channel_id']), + dbesc($page_id), + intval(ITEM_BUILDBLOCK) + ); + + if(! $r) { + + // Check again with no permissions clause to see if it is a permissions issue + + $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", + intval($u[0]['channel_id']), + dbesc($page_id), + intval(ITEM_BUILDBLOCK) + ); + if($x) { + // Yes, it's there. You just aren't allowed to see it. + notice( t('Permission denied.') . EOL); + } + else { + notice( t('Page not found.') . EOL); + } + return; + } + + xchan_query($r); + $r = fetch_post_tags($r,true); + + $o .= prepare_page($r[0]); + return $o; + +} diff --git a/mod/blocks.php b/mod/blocks.php new file mode 100644 index 000000000..74a980c25 --- /dev/null +++ b/mod/blocks.php @@ -0,0 +1,103 @@ +<?php + +function blocks_content(&$a) { + + + + if(argc() > 1) + $which = argv(1); + else { + notice( t('Requested profile is not available.') . EOL ); + $a->error = 404; + return; + } + + profile_load($a,$which,0); + + + // Figure out who the page owner is. + $r = q("select channel_id from channel where channel_address = '%s'", + dbesc($which) + ); + if($r) { + $owner = intval($r[0]['channel_id']); + } + + // Block design features from visitors + + if((! local_user()) || (local_user() != $owner)) { + notice( t('Permission denied.') . EOL); + return; + } + + + + +// Get the observer, check their permissions + + $observer = $a->get_observer(); + $ob_hash = (($observer) ? $observer['xchan_hash'] : ''); + + $perms = get_all_perms($owner,$ob_hash); + + if(! $perms['write_pages']) { + notice( t('Permission denied.') . EOL); + return; + } + +// if(local_user() && local_user() == $owner) { + // $a->set_widget('design',design_tools()); + // } + + + +// Create a status editor (for now - we'll need a WYSIWYG eventually) to create pages +// Nickname is set to the observers xchan, and profile_uid to the owners. This lets you post pages at other people's channels. +require_once ('include/conversation.php'); + $x = array( + 'webpage' => ITEM_BUILDBLOCK, + 'is_owner' => true, + 'nickname' => $a->profile['channel_address'], + 'lockstate' => (($group || $cid || $channel['channel_allow_cid'] || $channel['channel_allow_gid'] || $channel['channel_deny_cid'] || $channel['channel_deny_gid']) ? 'lock' : 'unlock'), + 'bang' => (($group || $cid) ? '!' : ''), + 'showacl' => false, + 'visitor' => true, + 'mimetype' => 'choose', + 'ptlabel' => t('Block Name'), + 'profile_uid' => intval($owner), + ); + + $o .= status_editor($a,$x); + + //Get a list of blocks. We can't display all them because endless scroll makes that unusable, so just list titles and an edit link. +//TODO - this should be replaced with pagelist_widget + +$r = q("select * from item_id where uid = %d and service = 'BUILDBLOCK' order by sid asc", + intval($owner) +); + + $pages = null; + + if($r) { + $pages = array(); + foreach($r as $rr) { + $pages[$rr['iid']][] = array('url' => $rr['iid'],'title' => $rr['sid']); + } + } + + +//Build the base URL for edit links + $url = z_root() . "/editblock/" . $which; +// This isn't pretty, but it works. Until I figure out what to do with the UI, it's Good Enough(TM). + return $o . replace_macros(get_markup_template("blocklist.tpl"), array( + '$baseurl' => $url, + '$edit' => t('Edit'), + '$pages' => $pages, + '$channel' => $which, + '$view' => t('View'), + '$preview' => '1', + + )); + + +} diff --git a/mod/bookmarks.php b/mod/bookmarks.php new file mode 100644 index 000000000..9ccc171fe --- /dev/null +++ b/mod/bookmarks.php @@ -0,0 +1,86 @@ +<?php + +function bookmarks_init(&$a) { + if(! local_user()) + return; + $item_id = intval($_REQUEST['item']); + if(! $item_id) + return; + + $u = $a->get_channel(); + + $i = q("select * from item where id = %d and uid = %d limit 1", + intval($item_id), + intval(local_user()) + ); + + if(! $i) + return; + + $i = fetch_post_tags($i); + + $item = $i[0]; + + $terms = get_terms_oftype($item['term'],TERM_BOOKMARK); + + if($terms && (! $item['item_restrict'])) { + require_once('include/bookmarks.php'); + + $s = q("select * from xchan where xchan_hash = '%s' limit 1", + dbesc($item['author_xchan']) + ); + if(! $s) { + logger('mod_bookmarks: author lookup failed.'); + killme(); + } + foreach($terms as $t) { + bookmark_add($u,$s[0],$t,$item['item_private']); + info( t('Bookmark added') . EOL); + } + } + killme(); +} + +function bookmarks_content(&$a) { + if(! local_user()) { + notice( t('Permission denied.') . EOL); + return; + } + + + require_once('include/menu.php'); + require_once('include/conversation.php'); + + $channel = $a->get_channel(); + + $o = profile_tabs($a,true,$channel['channel_address']); + + $o .= '<h3>' . t('My Bookmarks') . '</h3>'; + + $x = menu_list(local_user(),'',MENU_BOOKMARK); + + if($x) { + foreach($x as $xx) { + $y = menu_fetch($xx['menu_name'],local_user(),get_observer_hash()); + $o .= menu_render($y,'',true); + } + } + + $o .= '<h3>' . t('My Connections Bookmarks') . '</h3>'; + + + $x = menu_list(local_user(),'',MENU_SYSTEM|MENU_BOOKMARK); + + if($x) { + foreach($x as $xx) { + $y = menu_fetch($xx['menu_name'],local_user(),get_observer_hash()); + $o .= menu_render($y,'',true); + } + } + + + + return $o; + +} + diff --git a/mod/chanman.php b/mod/chanman.php new file mode 100644 index 000000000..7a89708d7 --- /dev/null +++ b/mod/chanman.php @@ -0,0 +1,31 @@ +<?php /** @file */ + + +/** + Placeholder file at present. This is going to involve a bit of work. + + This file will deal with the deletion of channels and management of hublocs. + + We need to provide the following functionality: + + - Delete my account and all channels from the entire network + + - Delete my account and all channels from this server + + - Delete a channel from the entire network + + - Delete a channel from this server + + - List all hub locations for this channel + + - Remove this/some hub location from this channel + + - promote this/some hub location to primary + + - Remove hub location 'xyz' from this channel, (this should possibly only be allowed if that hub has been down for a period of time) + + - Some of these actions should probably require email verification + +*/ + + diff --git a/mod/channel.php b/mod/channel.php index 0a49b41eb..395160d2c 100644 --- a/mod/channel.php +++ b/mod/channel.php @@ -1,12 +1,28 @@ <?php +require_once('include/contact_widgets.php'); +require_once('include/items.php'); +require_once("include/bbcode.php"); +require_once('include/security.php'); +require_once('include/conversation.php'); +require_once('include/acl_selectors.php'); +require_once('include/permissions.php'); + + function channel_init(&$a) { + $which = null; if(argc() > 1) $which = argv(1); - else { - notice( t('Requested profile is not available.') . EOL ); - $a->error = 404; + if(! $which) { + if(local_user()) { + $channel = $a->get_channel(); + if($channel && $channel['channel_address']) + $which = $channel['channel_address']; + } + } + if(! $which) { + notice( t('You must be logged in to see this page.') . EOL ); return; } @@ -27,58 +43,20 @@ function channel_init(&$a) { } - -function channel_aside(&$a) { - - require_once('include/contact_widgets.php'); - require_once('include/items.php'); - - if(! $a->profile['profile_uid']) - return; - - $channel_display = get_pconfig($a->profile['profile_uid'],'system','channel_format'); - if(! $channel_display) - profile_create_sidebar($a); - - if($channel_display === 'full') - $a->page['template'] = 'full'; - else { - $cat = ((x($_REQUEST,'cat')) ? htmlspecialchars($_REQUEST['cat']) : ''); - $a->set_widget('archive',posted_date_widget($a->get_baseurl(true) . '/channel/' . $a->profile['channel_address'],$a->profile['profile_uid'],true)); - $a->set_widget('categories',categories_widget($a->get_baseurl(true) . '/channel/' . $a->profile['channel_address'],$cat)); - } -} - - function channel_content(&$a, $update = 0, $load = false) { $category = $datequery = $datequery2 = ''; - if(argc() > 2) { - for($x = 2; $x < argc(); $x ++) { - if(is_a_date_arg(argv($x))) { - if($datequery) - $datequery2 = escape_tags(argv($x)); - else - $datequery = escape_tags(argv($x)); - } - } - } + $mid = $_GET['mid']; + $datequery = ((x($_GET,'dend') && is_a_date_arg($_GET['dend'])) ? notags($_GET['dend']) : ''); + $datequery2 = ((x($_GET,'dbegin') && is_a_date_arg($_GET['dbegin'])) ? notags($_GET['dbegin']) : ''); if(get_config('system','block_public') && (! get_account_id()) && (! remote_user())) { return login(); } - - - require_once("include/bbcode.php"); - require_once('include/security.php'); - require_once('include/conversation.php'); - require_once('include/acl_selectors.php'); - require_once('include/items.php'); - require_once('include/permissions.php'); - + $category = ((x($_REQUEST,'cat')) ? $_REQUEST['cat'] : ''); $groups = array(); @@ -96,12 +74,18 @@ function channel_content(&$a, $update = 0, $load = false) { $is_owner = (((local_user()) && ($a->profile['profile_uid'] == local_user())) ? true : false); + $channel = $a->get_channel(); $observer = $a->get_observer(); $ob_hash = (($observer) ? $observer['xchan_hash'] : ''); $perms = get_all_perms($a->profile['profile_uid'],$ob_hash); if(! $perms['view_stream']) { + // We may want to make the target of this redirect configurable + if($perms['view_profile']) { + notice( t('Insufficient permissions. Request redirected to profile page.') . EOL); + goaway (z_root() . "/profile/" . $a->profile['channel_address']); + } notice( t('Permission denied.') . EOL); return; } @@ -113,19 +97,30 @@ function channel_content(&$a, $update = 0, $load = false) { $o .= common_friends_visitor_widget($a->profile['profile_uid']); + if($channel && $is_owner) { + $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'] + ); + } + else + $channel_acl = array(); + if($perms['post_wall']) { $x = array( 'is_owner' => $is_owner, -// FIXME - 'allow_location' => ((($is_owner || $observer) && $a->profile['allow_location']) ? true : false), - 'default_location' => (($is_owner) ? $a->profile['default_location'] : ''), + 'allow_location' => ((($is_owner || $observer) && (intval(get_pconfig($a->profile['profile_uid'],'system','use_browser_location')))) ? true : false), + 'default_location' => (($is_owner) ? $a->profile['channel_location'] : ''), 'nickname' => $a->profile['channel_address'], 'lockstate' => (((strlen($a->profile['channel_allow_cid'])) || (strlen($a->profile['channel_allow_gid'])) || (strlen($a->profile['channel_deny_cid'])) || (strlen($a->profile['channel_deny_gid']))) ? 'lock' : 'unlock'), - 'acl' => (($is_owner) ? populate_acl($channel, false) : ''), + 'acl' => (($is_owner) ? populate_acl($channel_acl) : ''), + 'showacl' => (($is_owner) ? 'yes' : ''), 'bang' => '', - 'visitor' => (($is_owner || $observer) ? 'block' : 'none'), + 'visitor' => (($is_owner || $observer) ? true : false), 'profile_uid' => $a->profile['profile_uid'] ); @@ -144,25 +139,35 @@ function channel_content(&$a, $update = 0, $load = false) { if(($update) && (! $load)) { - - $r = q("SELECT distinct parent AS `item_id` from item - left join abook on item.author_xchan = abook.abook_xchan - WHERE uid = %d AND item_restrict = 0 - AND (item_flags & %d) AND ( item_flags & %d ) - AND ((abook.abook_flags & %d) = 0 or abook.abook_flags is null) - $sql_extra - ORDER BY created DESC", - intval($a->profile['profile_uid']), - intval(ITEM_WALL), - intval(ITEM_UNSEEN), - intval(ABOOK_FLAG_BLOCKED) - ); + 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) AND (item_flags & %d) $sql_extra limit 1", + dbesc($mid), + intval($a->profile['profile_uid']), + intval(ITEM_WALL), + intval(ITEM_UNSEEN) + ); + } else { + $r = q("SELECT distinct parent AS `item_id` from item + left join abook on item.author_xchan = abook.abook_xchan + WHERE uid = %d AND item_restrict = 0 + AND (item_flags & %d) AND ( item_flags & %d ) + AND ((abook.abook_flags & %d) = 0 or abook.abook_flags is null) + $sql_extra + ORDER BY created DESC", + intval($a->profile['profile_uid']), + intval(ITEM_WALL), + intval(ITEM_UNSEEN), + intval(ABOOK_FLAG_BLOCKED) + ); + } } else { + if(x($category)) { - $sql_extra .= protect_sprintf(file_tag_file_query('item',$category,'category')); + $sql_extra .= protect_sprintf(term_query('item', $category, TERM_CATEGORY)); } if($datequery) { @@ -172,25 +177,36 @@ function channel_content(&$a, $update = 0, $load = false) { $sql_extra2 .= protect_sprintf(sprintf(" AND item.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery2)))); } - - $a->set_pager_itemspage(40); - + $itemspage = get_pconfig(local_user(),'system','itemspage'); + $a->set_pager_itemspage(((intval($itemspage)) ? $itemspage : 20)); $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage'])); - if($load) { - $r = q("SELECT distinct id AS item_id FROM item - left join abook on item.author_xchan = abook.abook_xchan - WHERE uid = %d AND item_restrict = 0 - AND (item_flags & %d) and (item_flags & %d) - AND ((abook.abook_flags & %d) = 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) - - ); + 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) $sql_extra limit 1", + dbesc($mid), + intval($a->profile['profile_uid']), + intval(ITEM_WALL) + ); + if (! $r) { + notice( t('Permission denied.') . EOL); + } + + } else { + $r = q("SELECT distinct id AS item_id FROM item + left join abook on item.author_xchan = abook.abook_xchan + WHERE uid = %d AND item_restrict = 0 + AND (item_flags & %d) and (item_flags & %d) + AND ((abook.abook_flags & %d) = 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) + ); + } } else { $r = array(); @@ -214,6 +230,12 @@ function channel_content(&$a, $update = 0, $load = false) { $items = fetch_post_tags($items, true); $items = conv_sort($items,'created'); + if ($load && $mid && (! count($items))) { + // This will happen if we don't have sufficient permissions + // to view the parent item (or the item itself if it is toplevel) + notice( t('Permission denied.') . EOL); + } + } else { $items = array(); } @@ -242,12 +264,14 @@ function channel_content(&$a, $update = 0, $load = false) { '$spam' => '0', '$nouveau' => '0', '$wall' => '1', + '$fh' => '0', '$page' => (($a->pager['page'] != 1) ? $a->pager['page'] : 1), '$search' => '', '$order' => '', + '$list' => ((x($_REQUEST,'list')) ? intval($_REQUEST['list']) : 0), '$file' => '', '$cats' => (($category) ? $category : ''), - '$uri' => '', + '$mid' => $mid, '$dend' => $datequery, '$dbegin' => $datequery2 )); @@ -269,10 +293,17 @@ function channel_content(&$a, $update = 0, $load = false) { } - $o .= conversation($a,$items,'channel',$update,'client'); + if($_COOKIE['jsAvailable'] == 1) { + $o .= conversation($a,$items,'channel',$update,'client'); + } else { + $o .= conversation($a,$items,'channel',$update,'traditional'); + } - if(! $update) + if((! $update) || ($_COOKIE['jsAvailable'] != 1)) $o .= alt_pager($a,count($items)); + if($mid) + $o .= '<div id="content-complete"></div>'; + return $o; } diff --git a/mod/chanview.php b/mod/chanview.php index 8de59b92e..ca3410c8f 100644 --- a/mod/chanview.php +++ b/mod/chanview.php @@ -29,22 +29,25 @@ function chanview_content(&$a) { ); } elseif($_REQUEST['url']) { - $r = q("select * from xchan where xchan_url = '%s' limit 1", + + // if somebody re-installed they will have more than one xchan, use the most recent name date as this is + // the most useful consistently ascending table item we have. + + $r = q("select * from xchan where xchan_url = '%s' order by xchan_name_date desc limit 1", dbesc($_REQUEST['url']) ); } if($r) { - $xchan = $r[0]; + $a->poi = $r[0]; } - // Here, let's see if we have an xchan. If we don't, how we proceed is determined by what // info we do have. If it's a URL, we can offer to visit it directly. If it's a webbie or // address, we can and should try to import it. If it's just a hash, we can't continue, but we // probably wouldn't have a hash if we don't already have an xchan for this channel. - if(! $xchan) { + if(! $a->poi) { logger('mod_chanview: fallback'); // This is hackish - construct a zot address from the url if($_REQUEST['url']) { @@ -64,26 +67,26 @@ function chanview_content(&$a) { dbesc($_REQUEST['address']) ); if($r) - $xchan = $r[0]; + $a->poi = $r[0]; } } } - if(! $xchan) { + if(! $a->poi) { notice( t('Channel not found.') . EOL); return; } - if($xchan['xchan_hash']) - $a->set_widget('vcard',vcard_from_xchan($xchan,$observer,'chanview')); - - $url = (($observer) - ? z_root() . '/magic?f=&dest=' . $xchan['xchan_url'] . '&addr=' . $xchan['xchan_addr'] - : $xchan['xchan_url'] - ); - + $url = $a->poi['xchan_url']; + if($observer) + $url = zid($url); + + // let somebody over-ride the iframed viewport presentation + + if((! local_user()) || (get_pconfig(local_user(),'system','chanview_full'))) + goaway($url); $o = replace_macros(get_markup_template('chanview.tpl'),array( '$url' => $url, diff --git a/mod/chat.php b/mod/chat.php new file mode 100644 index 000000000..caf800f80 --- /dev/null +++ b/mod/chat.php @@ -0,0 +1,235 @@ +<?php /** @file */ + +require_once('include/chat.php'); +require_once('include/bookmarks.php'); + +function chat_init(&$a) { + + $which = null; + if(argc() > 1) + $which = argv(1); + if(! $which) { + if(local_user()) { + $channel = $a->get_channel(); + if($channel && $channel['channel_address']) + $which = $channel['channel_address']; + } + } + if(! $which) { + notice( t('You must be logged in to see this page.') . EOL ); + return; + } + + $profile = 0; + $channel = $a->get_channel(); + + if((local_user()) && (argc() > 2) && (argv(2) === 'view')) { + $which = $channel['channel_address']; + $profile = argv(1); + } + + $a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $a->get_baseurl() . '/feed/' . $which .'" />' . "\r\n" ; + + // Run profile_load() here to make sure the theme is set before + // we start loading content + + profile_load($a,$which,$profile); + +} + +function chat_post(&$a) { + + if($_POST['room_name']) + $room = strip_tags(trim($_POST['room_name'])); + + if((! $room) || (! local_user())) + return; + + $channel = $a->get_channel(); + + + if($_POST['action'] === 'drop') { + logger('delete chatroom'); + chatroom_destroy($channel,array('cr_name' => $room)); + goaway(z_root() . '/chat/' . $channel['channel_address']); + } + + + $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']); + + chatroom_create($channel,$arr); + + $x = q("select cr_id from chatroom where cr_name = '%s' and cr_uid = %d limit 1", + dbesc($room), + intval(local_user()) + ); + + if($x) + goaway(z_root() . '/chat/' . $channel['channel_address'] . '/' . $x[0]['cr_id']); + + // that failed. Try again perhaps? + + goaway(z_root() . '/chat/' . $channel['channel_address'] . '/new'); + + +} + + +function chat_content(&$a) { + + if(local_user()) + $channel = $a->get_channel(); + + $ob = $a->get_observer(); + $observer = get_observer_hash(); + if(! $observer) { + notice( t('Permission denied.') . EOL); + return; + } + + if(! perm_is_allowed($a->profile['profile_uid'],$observer,'chat')) { + notice( t('Permission denied.') . EOL); + return; + } + + if((argc() > 3) && intval(argv(2)) && (argv(3) === 'leave')) { + chatroom_leave($observer,argv(2),$_SERVER['REMOTE_ADDR']); + goaway(z_root() . '/channel/' . argv(1)); + } + + + if((argc() > 3) && intval(argv(2)) && (argv(3) === 'status')) { + $ret = array('success' => false); + $room_id = intval(argv(2)); + if(! $room_id || ! $observer) + return; + + $r = q("select * from chatroom where cr_id = %d limit 1", + intval($room_id) + ); + if(! $r) { + json_return_and_die($ret); + } + require_once('include/security.php'); + $sql_extra = permissions_sql($r[0]['cr_uid']); + + $x = q("select * from chatroom where cr_id = %d and cr_uid = %d $sql_extra limit 1", + intval($room_id), + intval($r[0]['cr_uid']) + ); + if(! $x) { + json_return_and_die($ret); + } + $y = q("select count(*) as total from chatpresence where cp_room = %d", + intval($room_id) + ); + if($y) { + $ret['success'] = true; + $ret['chatroom'] = $r[0]['cr_name']; + $ret['inroom'] = $y[0]['total']; + } + + // figure out how to present a timestamp of the last activity, since we don't know the observer's timezone. + + $z = q("select created from chat where chat_room = %d order by created desc limit 1", + intval($room_id) + ); + if($z) { + $ret['last'] = $z[0]['created']; + } + json_return_and_die($ret); + } + + + if(argc() > 2 && intval(argv(2))) { + + $room_id = intval(argv(2)); + $bookmark_link = get_bookmark_link($ob); + + $x = chatroom_enter($observer,$room_id,'online',$_SERVER['REMOTE_ADDR']); + if(! $x) + return; + $x = q("select * from chatroom where cr_id = %d and cr_uid = %d $sql_extra limit 1", + intval($room_id), + 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); + $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'; + } + else { + notice( t('Room not found') . EOL); + return; + } + + $o = replace_macros(get_markup_template('chat.tpl'),array( + '$is_owner' => ((local_user() && local_user() == $x[0]['cr_uid']) ? true : false), + '$room_name' => $room_name, + '$room_id' => $room_id, + '$baseurl' => z_root(), + '$nickname' => argv(1), + '$submit' => t('Submit'), + '$leave' => t('Leave Room'), + '$drop' => t('Delete This Room'), + '$away' => t('I am away right now'), + '$online' => t('I am online'), + '$bookmark_link' => $bookmark_link, + '$bookmark' => t('Bookmark this room') + + )); + return $o; + } + + + + + + if(local_user() && 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'] + ); + + 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'),'', ''), + '$permissions' => t('Permissions'), + '$acl' => populate_acl($channel_acl), + '$submit' => t('Submit') + )); + return $o; + } + + + + require_once('include/conversation.php'); + + $o = profile_tabs($a,((local_user() && local_user() == $a->profile['profile_uid']) ? true : false),$a->profile['channel_address']); + + require_once('include/widgets.php'); + + $o .= replace_macros(get_markup_template('chatrooms.tpl'), array( + '$header' => sprintf( t('%1$s\'s Chatrooms'), $a->profile['name']), + '$baseurl' => z_root(), + '$nickname' => $channel['channel_address'], + '$rooms' => widget_chatroom_list(array()), + '$newroom' => t('New Chatroom'), + '$is_owner' => ((local_user() && local_user() == $a->profile['profile_uid']) ? 1 : 0) + )); + + return $o; + +} diff --git a/mod/chatsvc.php b/mod/chatsvc.php new file mode 100644 index 000000000..43aa3d3c0 --- /dev/null +++ b/mod/chatsvc.php @@ -0,0 +1,159 @@ +<?php /** @file */ + +require_once('include/security.php'); + +function chatsvc_init(&$a) { + +//logger('chatsvc'); + + $ret = array('success' => false); + + $a->data['chat']['room_id'] = intval($_REQUEST['room_id']); + $x = q("select cr_uid from chatroom where cr_id = %d and cr_id != 0 limit 1", + intval($a->data['chat']['room_id']) + ); + if(! $x) + json_return_and_die($ret); + + $a->data['chat']['uid'] = $x[0]['cr_uid']; + + if(! perm_is_allowed($a->data['chat']['uid'],get_observer_hash(),'chat')) { + json_return_and_die($ret); + } + +} + +function chatsvc_post(&$a) { + + $ret = array('success' => false); + + $room_id = $a->data['chat']['room_id']; + $text = escape_tags($_REQUEST['chat_text']); + if(! $text) + return; + + $sql_extra = permissions_sql($a->data['chat']['uid']); + + $r = q("select * from chatroom where cr_uid = %d and cr_id = %d $sql_extra", + intval($a->data['chat']['uid']), + intval($a->data['chat']['room_id']) + ); + if(! $r) + json_return_and_die($ret); + + $arr = array( + 'chat_room' => $a->data['chat']['room_id'], + 'chat_xchan' => get_observer_hash(), + 'chat_text' => $text + ); + + call_hooks('chat_post',$arr); + + $x = q("insert into chat ( chat_room, chat_xchan, created, chat_text ) + values( %d, '%s', '%s', '%s' )", + intval($a->data['chat']['room_id']), + dbesc(get_observer_hash()), + dbesc(datetime_convert()), + dbesc($arr['chat_text']) + ); + + $ret['success'] = true; + json_return_and_die($ret); +} + +function chatsvc_content(&$a) { + + $status = strip_tags($_REQUEST['status']); + $room_id = intval($a->data['chat']['room_id']); + $stopped = ((x($_REQUEST,'stopped') && intval($_REQUEST['stopped'])) ? true : false); + + if($status && $room_id) { + + $x = q("select channel_address from channel where channel_id = %d limit 1", + intval($a->data['chat']['uid']) + ); + + $r = q("update chatpresence set cp_status = '%s', cp_last = '%s' where cp_room = %d and cp_xchan = '%s' and cp_client = '%s' limit 1", + dbesc($status), + dbesc(datetime_convert()), + intval($room_id), + dbesc(get_observer_hash()), + dbesc($_SERVER['REMOTE_ADDR']) + ); + + goaway(z_root() . '/chat/' . $x[0]['channel_address'] . '/' . $room_id); + } + + if(! $stopped) { + + $lastseen = intval($_REQUEST['last']); + + $ret = array('success' => false); + + $sql_extra = permissions_sql($a->data['chat']['uid']); + + $r = q("select * from chatroom where cr_uid = %d and cr_id = %d $sql_extra", + intval($a->data['chat']['uid']), + intval($a->data['chat']['room_id']) + ); + if(! $r) + json_return_and_die($ret); + + $inroom = array(); + + $r = q("select * from chatpresence left join xchan on xchan_hash = cp_xchan where cp_room = %d order by xchan_name", + intval($a->data['chat']['room_id']) + ); + if($r) { + foreach($r as $rr) { + switch($rr['cp_status']) { + case 'away': + $status = t('Away'); + break; + case 'online': + default: + $status = t('Online'); + break; + } + + $inroom[] = array('img' => zid($rr['xchan_photo_m']), 'img_type' => $rr['xchan_photo_mimetype'],'name' => $rr['xchan_name'], status => $status); + } + } + + $chats = array(); + + $r = q("select * from chat left join xchan on chat_xchan = xchan_hash where chat_room = %d and chat_id > %d order by created", + intval($a->data['chat']['room_id']), + intval($lastseen) + ); + if($r) { + foreach($r as $rr) { + $chats[] = array( + 'id' => $rr['chat_id'], + 'img' => zid($rr['xchan_photo_m']), + 'img_type' => $rr['xchan_photo_mimetype'], + 'name' => $rr['xchan_name'], + 'isotime' => datetime_convert('UTC', date_default_timezone_get(), $rr['created'], 'c'), + 'localtime' => datetime_convert('UTC', date_default_timezone_get(), $rr['created'], 'r'), + 'text' => smilies(bbcode($rr['chat_text'])) + ); + } + } + } + + $r = q("update chatpresence set cp_last = '%s' where cp_room = %d and cp_xchan = '%s' and cp_client = '%s' limit 1", + dbesc(datetime_convert()), + intval($a->data['chat']['room_id']), + dbesc(get_observer_hash()), + dbesc($_SERVER['REMOTE_ADDR']) + ); + + $ret['success'] = true; + if(! $stopped) { + $ret['inroom'] = $inroom; + $ret['chats'] = $chats; + } + json_return_and_die($ret); + +} + diff --git a/mod/cloud.php b/mod/cloud.php new file mode 100644 index 000000000..3606325bd --- /dev/null +++ b/mod/cloud.php @@ -0,0 +1,134 @@ +<?php + + use Sabre\DAV; + + 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; + } + } + + + + + +function cloud_init(&$a) { + + require_once('include/reddav.php'); + + if(! is_dir('store')) + mkdir('store',STORAGE_DEFAULT_PERMISSIONS,false); + + $which = null; + if(argc() > 1) + $which = argv(1); + + $profile = 0; + $channel = $a->get_channel(); + + $a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $a->get_baseurl() . '/feed/' . $which .'" />' . "\r\n" ; + + if($which) + profile_load($a,$which,$profile); + + + + + $auth = new RedBasicAuth(); + + $ob_hash = get_observer_hash(); + + if($ob_hash) { + if(local_user()) { + $channel = $a->get_channel(); + $auth->setCurrentUser($channel['channel_address']); + $auth->channel_name = $channel['channel_address']; + $auth->channel_id = $channel['channel_id']; + $auth->channel_hash = $channel['channel_hash']; + if($channel['channel_timezone']) + $auth->timezone = $channel['channel_timezone']; + } + $auth->observer = $ob_hash; + } + + if($_GET['davguest']) + $_SESSION['davguest'] = true; + + + + $_SERVER['QUERY_STRING'] = str_replace(array('?f=','&f='),array('',''),$_SERVER['QUERY_STRING']); + $_SERVER['QUERY_STRING'] = strip_zids($_SERVER['QUERY_STRING']); + $_SERVER['QUERY_STRING'] = preg_replace('/[\?&]davguest=(.*?)([\?&]|$)/ism','',$_SERVER['QUERY_STRING']); + + $_SERVER['REQUEST_URI'] = str_replace(array('?f=','&f='),array('',''),$_SERVER['REQUEST_URI']); + $_SERVER['REQUEST_URI'] = strip_zids($_SERVER['REQUEST_URI']); + $_SERVER['REQUEST_URI'] = preg_replace('/[\?&]davguest=(.*?)([\?&]|$)/ism','',$_SERVER['REQUEST_URI']); + + $rootDirectory = new RedDirectory('/',$auth); + $server = new DAV\Server($rootDirectory); + $lockBackend = new DAV\Locks\Backend\File('store/[data]/locks'); + $lockPlugin = new DAV\Locks\Plugin($lockBackend); + + $server->addPlugin($lockPlugin); + + // 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 viewers won't get asked to login. + // If a DIRECTORY is accessed or there are permission issues accessing the file and we aren't previously authenticated via zot, + // prompt for HTTP-auth. This will be the default case for mounting a DAV directory. + // 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 RedFile) + $isapublic_file = true; + } + catch ( Exception $e ) { + $isapublic_file = false; + } + } + + if((! $auth->observer) && (! $isapublic_file) && (! $davguest)) { + try { + $auth->Authenticate($server, t('Red Matrix - Guests: Username: {your email address}, Password: +++')); + } + catch ( Exception $e) { + logger('mod_cloud: auth exception' . $e->getMessage()); + http_status_exit($e->getHTTPCode(),$e->getMessage()); + } + } + +// $browser = new DAV\Browser\Plugin(); + + $browser = new RedBrowser($auth); + + $auth->setBrowserPlugin($browser); + + + $server->addPlugin($browser); + + + // All we need to do now, is to fire up the server + $server->exec(); + + killme(); +}
\ No newline at end of file diff --git a/mod/common.php b/mod/common.php index 4afaf37eb..e19a9d3a9 100644 --- a/mod/common.php +++ b/mod/common.php @@ -21,14 +21,6 @@ function common_init(&$a) { } -function common_aside(&$a) { - if(! $a->profile['profile_uid']) - return; - - profile_create_sidebar($a); -} - - function common_content(&$a) { $o = ''; diff --git a/mod/community.php b/mod/community.php deleted file mode 100644 index 4f6c3d3c9..000000000 --- a/mod/community.php +++ /dev/null @@ -1,105 +0,0 @@ -<?php - -function community_init(&$a) { - if(! local_user()) { - unset($_SESSION['theme']); - unset($_SESSION['mobile-theme']); - } - - -} - - -function community_content(&$a, $update = 0) { - - $o = ''; - - if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { - notice( t('Public access denied.') . EOL); - return; - } - - if(get_config('system','no_community_page')) { - notice( t('Not available.') . EOL); - return; - } - - require_once("include/bbcode.php"); - require_once('include/security.php'); - require_once('include/conversation.php'); - - - $o .= '<h3>' . t('Community') . '</h3>'; - if(! $update) { - nav_set_selected('community'); - $o .= '<div id="live-community"></div>' . "\r\n"; - $o .= "<script> var profile_uid = -1; var netargs = '/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n"; - } - - if(x($a->data,'search')) - $search = notags(trim($a->data['search'])); - else - $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : ''); - - - // Here is the way permissions work in this module... - // Only public posts can be shown - // OR your own posts if you are a logged in member - - if(! get_pconfig(local_user(),'system','alt_pager')) { - $r = q("SELECT COUNT(distinct(`item`.`uri`)) AS `total` - FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` LEFT JOIN `user` ON `user`.`uid` = `item`.`uid` - WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0 - AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' - AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' - AND `item`.`private` = 0 AND `item`.`wall` = 1 AND `user`.`hidewall` = 0 - AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0" - ); - - if(count($r)) - $a->set_pager_total($r[0]['total']); - - if(! $r[0]['total']) { - info( t('No results.') . EOL); - return $o; - } - - } - - $r = q("SELECT distinct(`item`.`uri`), `item`.*, `item`.`id` AS `item_id`, - `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`, - `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, - `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`, - `user`.`nickname`, `user`.`hidewall` - FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` - LEFT JOIN `user` ON `user`.`uid` = `item`.`uid` - WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0 - AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' - AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' - AND `item`.`private` = 0 AND `item`.`wall` = 1 AND `user`.`hidewall` = 0 - AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 group by `item`.`uri` - ORDER BY `received` DESC LIMIT %d, %d ", - intval($a->pager['start']), - intval($a->pager['itemspage']) - - ); - - if(! count($r)) { - info( t('No results.') . EOL); - return $o; - } - - // we behave the same in message lists as the search module - - $o .= conversation($a,$r,'community',$update); - - if(! get_pconfig(local_user(),'system','alt_pager')) { - $o .= paginate($a); - } - else { - $o .= alt_pager($a,count($r)); - } - - return $o; -} - diff --git a/mod/connect.php b/mod/connect.php new file mode 100644 index 000000000..f7748bcaf --- /dev/null +++ b/mod/connect.php @@ -0,0 +1,124 @@ +<?php /** @file */ + + +require_once('include/Contact.php'); +require_once('include/contact_widgets.php'); +require_once('include/items.php'); + + +function connect_init(&$a) { + if(argc() > 1) + $which = argv(1); + else { + notice( t('Requested profile is not available.') . EOL ); + $a->error = 404; + return; + } + + $r = q("select * from channel where channel_address = '%s' limit 1", + dbesc($which) + ); + + if($r) + $a->data['channel'] = $r[0]; + + profile_load($a,$which,''); +} + +function connect_post(&$a) { + + if(! array_key_exists('channel', $a->data)) + return; + + $edit = ((local_user() && (local_user() == $a->data['channel']['channel_id'])) ? true : false); + + if($edit) { + $has_premium = (($a->data['channel']['channel_pageflags'] & PAGE_PREMIUM) ? 1 : 0); + $premium = (($_POST['premium']) ? intval($_POST['premium']) : 0); + $text = escape_tags($_POST['text']); + + if($has_premium != $premium) { + $r = q("update channel set channel_pageflags = ( channel_pageflags ^ %d ) where channel_id = %d limit 1", + intval(PAGE_PREMIUM), + intval(local_user()) + ); + proc_run('php','include/notifier.php','refresh_all',$a->data['channel']['channel_id']); + } + set_pconfig($a->data['channel']['channel_id'],'system','selltext',$text); + // reload the page completely to get fresh data + goaway(z_root() . '/' . $a->query_string); + + } + + $url = ''; + $observer = $a->get_observer(); + if(($observer) && ($_POST['submit'] === t('Continue'))) { + if($observer['xchan_follow']) + $url = sprintf($observer['xchan_follow'],urlencode($a->data['channel']['channel_address'] . '@' . $a->get_hostname())); + if(! $url) { + $r = q("select * from hubloc where hubloc_hash = '%s' order by hubloc_id desc limit 1", + dbesc($observer['xchan_hash']) + ); + if($r) + $url = $r[0]['hubloc_url'] . '/follow?f=&url=' . urlencode($a->data['channel']['channel_address'] . '@' . $a->get_hostname()); + } + } + if($url) + goaway($url . '&confirm=1'); + else + notice('Unable to connect to your home hub location.'); + +} + + + +function connect_content(&$a) { + + $edit = ((local_user() && (local_user() == $a->data['channel']['channel_id'])) ? true : false); + + $text = get_pconfig($a->data['channel']['channel_id'],'system','selltext'); + + if($edit) { + + $o = replace_macros(get_markup_template('sellpage_edit.tpl'),array( + '$header' => t('Premium Channel Setup'), + '$address' => $a->data['channel']['channel_address'], + '$premium' => array('premium', t('Enable premium channel connection restrictions'),(($a->data['channel']['channel_pageflags'] & PAGE_PREMIUM) ? '1' : ''),''), + '$lbl_about' => t('Please enter your restrictions or conditions, such as paypal receipt, usage guidelines, etc.'), + '$text' => $text, + '$desc' => t('This channel may require additional steps or acknowledgement of the following conditions prior to connecting:'), + '$lbl2' => t('Potential connections will then see the following text before proceeding:'), + '$desc2' => t('By continuing, I certify that I have complied with any instructions provided on this page.'), + '$submit' => t('Submit'), + + + )); + return $o; + } + else { + if(! $text) + $text = t('(No specific instructions have been provided by the channel owner.)'); + + $submit = replace_macros(get_markup_template('sellpage_submit.tpl'), array( + '$continue' => t('Continue'), + '$address' => $a->data['channel']['channel_address'] + )); + + $o = replace_macros(get_markup_template('sellpage_view.tpl'),array( + '$header' => t('Restricted or Premium Channel'), + '$desc' => t('This channel may require additional steps or acknowledgement of the following conditions prior to connecting:'), + '$text' => prepare_text($text), + + '$desc2' => t('By continuing, I certify that I have complied with any instructions provided on this page.'), + '$submit' => $submit, + + )); + + $arr = array('channel' => $a->data['channel'],'observer' => $a->get_observer(), 'sellpage' => $o, 'submit' => $submit); + call_hooks('connect_premium', $arr); + $o = $arr['sellpage']; + + } + + return $o; +}
\ No newline at end of file diff --git a/mod/connections.php b/mod/connections.php index 8e002d870..3c3a704b2 100644 --- a/mod/connections.php +++ b/mod/connections.php @@ -6,41 +6,19 @@ require_once('include/contact_selectors.php'); require_once('include/group.php'); require_once('include/contact_widgets.php'); require_once('include/zot.php'); +require_once('include/widgets.php'); function connections_init(&$a) { if(! local_user()) return; - if((argc() == 2) && intval(argv(1))) { - $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_user()), - intval(argv(1)) - ); - if($r) { - $a->data['abook'] = $r[0]; - } - } -} - -function connections_aside(&$a) { - - if(x($a->data,'abook')) { - $a->set_widget('vcard',vcard_from_xchan($a->data['abook'],$a->get_observer())); - } - else { - $a->set_widget('follow', follow_widget()); - } - - $a->set_widget('collections', group_side('connections','group',false,0,((array_key_exists('abook',$a->data)) ? $a->data['abook']['abook_xchan'] : ''))); - $a->set_widget('findpeople',findpeople_widget()); + $channel = $a->get_channel(); + if($channel) + head_set_icon($channel['xchan_photo_s']); } - - function connections_post(&$a) { if(! local_user()) @@ -57,16 +35,16 @@ function connections_post(&$a) { if(! $orig_record) { notice( t('Could not access contact record.') . EOL); - goaway($a->get_baseurl(true) . '/connections'); + goaway(z_root() . '/connections'); return; // NOTREACHED } call_hooks('contact_edit_post', $_POST); - $profile_id = intval($_POST['profile-assign']); + $profile_id = $_POST['profile_assign']; if($profile_id) { - $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1", - intval($profile_id), + $r = q("SELECT profile_guid FROM profile WHERE profile_guid = '%s' AND `uid` = %d LIMIT 1", + dbesc($profile_id), intval(local_user()) ); if(! count($r)) { @@ -94,20 +72,24 @@ function connections_post(&$a) { } $abook_flags = $orig_record[0]['abook_flags']; + $new_friend = false; + if(($_REQUEST['pending']) && ($abook_flags & ABOOK_FLAG_PENDING)) { $abook_flags = ( $abook_flags ^ ABOOK_FLAG_PENDING ); + $new_friend = true; } - $r = q("UPDATE abook SET abook_profile = %d, abook_my_perms = %d , abook_closeness = %d, abook_flags = %d + $r = q("UPDATE abook SET abook_profile = '%s', abook_my_perms = %d , abook_closeness = %d, abook_flags = %d where abook_id = %d AND abook_channel = %d LIMIT 1", - intval($profile_id), + dbesc($profile_id), intval($abook_my_perms), intval($closeness), intval($abook_flags), intval($contact_id), intval(local_user()) ); + if($r) info( t('Connection updated.') . EOL); else @@ -118,6 +100,28 @@ function connections_post(&$a) { proc_run('php', 'include/notifier.php', 'permission_update', $contact_id); } + if($new_friend) { + $channel = $a->get_channel(); + $default_group = $channel['channel_default_group']; + if($default_group) { + require_once('include/group.php'); + $g = group_rec_byhash(local_user(),$default_group); + if($g) + group_add_member(local_user(),'',$a->data['abook_xchan'],$g['id']); + } + + + + // Check if settings permit ("post new friend activity" is allowed, and + // friends in general or this friend in particular aren't hidden) + // and send out a new friend activity + // TODO + + // pull in a bit of content if there is any to pull in + proc_run('php','include/onepoll.php',$contact_id); + + } + // Refresh the structure in memory with the new data $r = q("SELECT abook.*, xchan.* @@ -126,317 +130,54 @@ function connections_post(&$a) { intval(local_user()), intval($contact_id) ); - if($r) + if($r) { $a->data['abook'] = $r[0]; + } + + if($new_friend) { + $arr = array('channel_id' => local_user(), 'abook' => $a->data['abook']); + call_hooks('accept_follow', $arr); + } + + connections_clone($a); return; } +function connections_clone(&$a) { + + if(! array_key_exists('abook',$a->data)) + return; + $clone = $a->data['abook']; + + unset($clone['abook_id']); + unset($clone['abook_account']); + unset($clone['abook_channel']); + + build_sync_packet(0 /* use the current local_user */, array('abook' => array($clone))); +} function connections_content(&$a) { $sort_type = 0; $o = ''; - nav_set_selected('connections'); if(! local_user()) { notice( t('Permission denied.') . EOL); - return; - } - - if(argc() == 3) { - - $contact_id = intval(argv(1)); - if(! $contact_id) - return; - - $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 ) and not ( abook_flags & %d ) LIMIT 1", - intval($contact_id), - intval(local_user()), - intval(ABOOK_FLAG_SELF), - intval(ABOOK_FLAG_PENDING) - ); - - if(! count($orig_record)) { - notice( t('Could not access address book record.') . EOL); - goaway($a->get_baseurl(true) . '/connections'); - } - - if($cmd === 'update') { - - // pull feed and consume it, which should subscribe to the hub. - proc_run('php',"include/poller.php","$contact_id"); - goaway($a->get_baseurl(true) . '/connections/' . $contact_id); - - } - - if($cmd === 'refresh') { - if(! zot_refresh($orig_record[0],get_app()->get_channel())) - notice( t('Refresh failed - channel is currently unavailable.') ); - goaway($a->get_baseurl(true) . '/connections/' . $contact_id); - } - - 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 ); - else - notice(t('Unable to set address book parameters.') . EOL); - goaway($a->get_baseurl(true) . '/connections/' . $contact_id); - } - - 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 ); - else - notice(t('Unable to set address book parameters.') . EOL); - goaway($a->get_baseurl(true) . '/connections/' . $contact_id); - } - - 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 ); - else - notice(t('Unable to set address book parameters.') . EOL); - goaway($a->get_baseurl(true) . '/connections/' . $contact_id); - } - - 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 ); - else - notice(t('Unable to set address book parameters.') . EOL); - goaway($a->get_baseurl(true) . '/connections/' . $contact_id); - } - - // We'll prevent somebody from unapproving a contact. - - if($cmd === 'approve') { - if($orig_record[0]['abook_flags'] & ABOOK_FLAG_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 ); - else - notice(t('Unable to set address book parameters.') . EOL); - } - goaway($a->get_baseurl(true) . '/connections/' . $contact_id); - } - - - if($cmd === 'drop') { - - require_once('include/Contact.php'); -// FIXME -// terminate_friendship($a->get_channel(),$orig_record[0]); - - contact_remove(local_user(), $orig_record[0]['abook_id']); - info( t('Contact has been removed.') . EOL ); - if(x($_SESSION,'return_url')) - goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']); - goaway($a->get_baseurl(true) . '/contacts'); - - } + return login(); } - if((x($a->data,'abook')) && (is_array($a->data['abook']))) { - - $contact_id = $a->data['abook']['abook_id']; - $contact = $a->data['abook']; - - - $tabs = array( - - array( - 'label' => t('View Profile'), - 'url' => $a->get_baseurl(true) . '/chanview/?f=&cid=' . $contact['abook_id'], - 'sel' => '', - 'title' => sprintf( t('View %s\'s profile'), $contact['xchan_name']), - ), - - array( - 'label' => t('Refresh Permissions'), - 'url' => $a->get_baseurl(true) . '/connections/' . $contact['abook_id'] . '/refresh', - 'sel' => '', - 'title' => t('Fetch updated permissions'), - ), - - array( - 'label' => (($contact['abook_flags'] & ABOOK_FLAG_BLOCKED) ? t('Unblock') : t('Block')), - 'url' => $a->get_baseurl(true) . '/connections/' . $contact['abook_id'] . '/block', - 'sel' => (($contact['abook_flags'] & ABOOK_FLAG_BLOCKED) ? 'active' : ''), - 'title' => t('Block or Unblock this connection'), - ), - - array( - 'label' => (($contact['abook_flags'] & ABOOK_FLAG_IGNORED) ? t('Unignore') : t('Ignore')), - 'url' => $a->get_baseurl(true) . '/connections/' . $contact['abook_id'] . '/ignore', - 'sel' => (($contact['abook_flags'] & ABOOK_FLAG_IGNORED) ? 'active' : ''), - 'title' => t('Ignore or Unignore this connection'), - ), - array( - 'label' => (($contact['abook_flags'] & ABOOK_FLAG_ARCHIVED) ? t('Unarchive') : t('Archive')), - 'url' => $a->get_baseurl(true) . '/connections/' . $contact['abook_id'] . '/archive', - 'sel' => (($contact['abook_flags'] & ABOOK_FLAG_ARCHIVED) ? 'active' : ''), - 'title' => t('Archive or Unarchive this connection'), - ), - array( - 'label' => (($contact['abook_flags'] & ABOOK_FLAG_HIDDEN) ? t('Unhide') : t('Hide')), - 'url' => $a->get_baseurl(true) . '/connections/' . $contact['abook_id'] . '/hide', - 'sel' => (($contact['abook_flags'] & ABOOK_FLAG_HIDDEN) ? 'active' : ''), - 'title' => t('Hide or Unhide this connection'), - ), - - array( - 'label' => t('Delete'), - 'url' => $a->get_baseurl(true) . '/connections/' . $contact['abook_id'] . '/drop', - 'sel' => '', - 'title' => t('Delete this connection'), - ), - - ); - - $self = false; - - if(! ($contact['abook_flags'] & ABOOK_FLAG_SELF)) { - $tab_tpl = get_markup_template('common_tabs.tpl'); - $t = replace_macros($tab_tpl, array('$tabs'=>$tabs)); - } - else - $self = true; - - $a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), array( - '$baseurl' => $a->get_baseurl(true), - '$editselect' => $editselect - )); - - require_once('include/contact_selectors.php'); - - $tpl = get_markup_template("abook_edit.tpl"); - - if(feature_enabled(local_user(),'affinity')) { - - $slider_tpl = get_markup_template('contact_slider.tpl'); - $slide = replace_macros($slider_tpl,array( - '$me' => t('Me'), - '$val' => $contact['abook_closeness'], - '$intimate' => t('Best Friends'), - '$friends' => t('Friends'), - '$oldfriends' => t('Former Friends'), - '$acquaintances' => t('Acquaintances'), - '$world' => t('Unknown') - )); - } - - $perms = array(); - $channel = $a->get_channel(); - - $global_perms = get_perms(); - $existing = get_all_perms(local_user(),$contact); - - $unapproved = array('pending', t('Approve this connection'), '', t('Accept connection to allow communication')); - - foreach($global_perms as $k => $v) { - $perms[] = array('perms_' . $k, $v[3], (($contact['abook_their_perms'] & $v[1]) ? "1" : ""),((($contact['abook_my_perms'] & $v[1]) || $existing[$k]) ? "1" : ""), $v[1], (($channel[$v[0]] == PERMS_SPECIFIC) ? '' : '1'), $v[4]); - } - - $o .= replace_macros($tpl,array( - - '$header' => (($self) ? t('Automatic Permissions Settings') : sprintf( t('Connections: settings for %s'),$contact['xchan_name'])), - '$addr' => $contact['xchan_addr'], - '$notself' => (($self) ? '' : '1'), - '$self' => (($self) ? '1' : ''), - '$autolbl' => t('When receiving a channel introduction, any permissions provided here will be applied to the new connection automatically and the introduction approved. Leave this page if you do not wish to use this feature.'), - '$viewprof' => t('View Profile'), - '$lbl_slider' => t('Slide to adjust your degree of friendship'), - '$slide' => $slide, - '$tabs' => $t, - '$tab_str' => $tab_str, - '$is_pending' => (($contact['abook_flags'] & ABOOK_FLAG_PENDING) ? 1 : ''), - '$unapproved' => $unapproved, - '$approve' => t('Approve this connection'), - '$noperms' => (((! $self) && (! $contact['abook_my_perms'])) ? t('Connection has no permissions!') : ''), - '$submit' => t('Submit'), - '$lbl_vis1' => t('Profile Visibility'), - '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']), - '$lbl_info1' => t('Contact Information / Notes'), - '$infedit' => t('Edit contact notes'), - '$close' => $contact['abook_closeness'], - '$them' => t('Their Settings'), - '$me' => t('My Settings'), - '$perms' => $perms, - '$forum' => t('Forum Members'), - '$soapbox' => t('Soapbox'), - '$full' => t('Full Sharing'), - '$cautious' => t('Cautious Sharing'), - '$follow' => t('Follow Only'), - '$permlbl' => t('Permissions'), - '$advanced' => t('Advanced Permissions'), - '$quick' => t('Quick Links'), - '$common_link' => $a->get_baseurl(true) . '/common/loc/' . local_user() . '/' . $contact['id'], - '$all_friends' => $all_friends, - '$relation_text' => $relation_text, - '$visit' => sprintf( t('Visit %s\'s profile - %s'),$contact['xchan_name'],$contact['xchan_url']), - '$blockunblock' => t('Block/Unblock contact'), - '$ignorecont' => t('Ignore contact'), - '$lblcrepair' => t("Repair URL settings"), - '$lblrecent' => t('View conversations'), - '$lblsuggest' => $lblsuggest, - '$delete' => t('Delete contact'), - '$poll_interval' => contact_poll_interval($contact['priority'],(! $poll_enabled)), - '$poll_enabled' => $poll_enabled, - '$lastupdtext' => t('Last update:'), - '$lost_contact' => $lost_contact, - '$updpub' => t('Update public posts'), - '$last_update' => $last_update, - '$udnow' => t('Update now'), -// '$profile_select' => contact_profile_assign($contact['profile_id'],(($contact['network'] !== NETWORK_DFRN) ? true : false)), - '$contact_id' => $contact['abook_id'], - '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ), - '$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ), - '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''), - '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''), - '$archived' => (($contact['archive']) ? t('Currently archived') : ''), - '$pending' => (($contact['archive']) ? t('Currently pending') : ''), - '$hidden' => array('hidden', t('Hide this contact from others'), ($contact['hidden'] == 1), t('Replies/likes to your public posts <strong>may</strong> still be visible')), - '$photo' => $contact['photo'], - '$name' => $contact['name'], - '$dir_icon' => $dir_icon, - '$alt_text' => $alt_text, - '$sparkle' => $sparkle, - '$url' => $url - - )); - - $arr = array('contact' => $contact,'output' => $o); - - call_hooks('contact_edit', $arr); - - return $arr['output']; - - } - - $blocked = false; - $hidden = false; - $ignored = false; - $archived = false; - $unblocked = false; - $pending = false; - - $all = false; + $blocked = false; + $hidden = false; + $ignored = false; + $archived = false; + $unblocked = false; + $pending = false; + $unconnected = false; + $all = false; $_SESSION['return_url'] = $a->query_string; @@ -469,6 +210,34 @@ function connections_content(&$a) { $search_flags = ABOOK_FLAG_PENDING; $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) and not ((abook_flags & %d) or (xchan_flags & %d))", + intval(local_user()), + intval(ABOOK_FLAG_PENDING), + intval(ABOOK_FLAG_SELF|ABOOK_FLAG_IGNORED), + intval(XCHAN_FLAGS_DELETED|XCHAN_FLAGS_ORPHAN) + ); + if($r && $r[0]['total']) { + $search_flags = ABOOK_FLAG_PENDING; + $head = t('New'); + $pending = true; + nav_set_selected('intros'); + $a->argv[1] = 'pending'; + } + else { + $head = t('All'); + $search_flags = 0; + $all = true; + $a->argc = 1; + unset($a->argv[1]); + } + break; + case 'unconnected': + $search_flags = ABOOK_FLAG_UNCONNECTED; + $head = t('Unconnected'); + $unconnected = true; break; case 'all': @@ -481,7 +250,8 @@ function connections_content(&$a) { } $sql_extra = (($search_flags) ? " and ( abook_flags & " . $search_flags . " ) " : ""); - + if(argv(1) === 'pending') + $sql_extra .= " and not ( abook_flags & " . ABOOK_FLAG_IGNORED . " ) "; } else { @@ -494,57 +264,65 @@ function connections_content(&$a) { $tabs = array( array( 'label' => t('Suggestions'), - 'url' => $a->get_baseurl(true) . '/suggest', + 'url' => z_root() . '/suggest', 'sel' => '', 'title' => t('Suggest new connections'), ), array( 'label' => t('New Connections'), - 'url' => $a->get_baseurl(true) . '/connections/pending', + 'url' => z_root() . '/connections/pending', 'sel' => ($pending) ? 'active' : '', 'title' => t('Show pending (new) connections'), ), array( 'label' => t('All Connections'), - 'url' => $a->get_baseurl(true) . '/connections/all', + 'url' => z_root() . '/connections/all', 'sel' => ($all) ? 'active' : '', 'title' => t('Show all connections'), ), array( 'label' => t('Unblocked'), - 'url' => $a->get_baseurl(true) . '/connections', + 'url' => z_root() . '/connections', 'sel' => (($unblocked) && (! $search) && (! $nets)) ? 'active' : '', 'title' => t('Only show unblocked connections'), ), array( 'label' => t('Blocked'), - 'url' => $a->get_baseurl(true) . '/connections/blocked', + 'url' => z_root() . '/connections/blocked', 'sel' => ($blocked) ? 'active' : '', 'title' => t('Only show blocked connections'), ), array( 'label' => t('Ignored'), - 'url' => $a->get_baseurl(true) . '/connections/ignored', + 'url' => z_root() . '/connections/ignored', 'sel' => ($ignored) ? 'active' : '', 'title' => t('Only show ignored connections'), ), array( 'label' => t('Archived'), - 'url' => $a->get_baseurl(true) . '/connections/archived', + 'url' => z_root() . '/connections/archived', 'sel' => ($archived) ? 'active' : '', 'title' => t('Only show archived connections'), ), array( 'label' => t('Hidden'), - 'url' => $a->get_baseurl(true) . '/connections/hidden', + 'url' => z_root() . '/connections/hidden', 'sel' => ($hidden) ? 'active' : '', 'title' => t('Only show hidden connections'), ), + array( + 'label' => t('Unconnected'), + 'url' => z_root() . '/connections/unconnected', + 'sel' => ($unconnected) ? 'active' : '', + 'title' => t('Only show one-way connections'), + ), + + ); $tab_tpl = get_markup_template('common_tabs.tpl'); @@ -560,19 +338,21 @@ 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) $sql_extra $sql_extra2 ", + where abook_channel = %d and not (abook_flags & %d) and not (xchan_flags & %d ) $sql_extra $sql_extra2 ", intval(local_user()), - intval(ABOOK_FLAG_SELF) + intval(ABOOK_FLAG_SELF), + intval(XCHAN_FLAGS_DELETED|XCHAN_FLAGS_ORPHAN) ); - if(count($r)) { + if($r) { $a->set_pager_total($r[0]['total']); $total = $r[0]['total']; } $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) $sql_extra $sql_extra2 ORDER BY xchan_name LIMIT %d , %d ", + WHERE abook_channel = %d and not (abook_flags & %d) and not ( xchan_flags & %d) $sql_extra $sql_extra2 ORDER BY xchan_name LIMIT %d , %d ", intval(local_user()), intval(ABOOK_FLAG_SELF), + intval(XCHAN_FLAGS_DELETED|XCHAN_FLAGS_ORPHAN), intval($a->pager['start']), intval($a->pager['itemspage']) ); @@ -582,31 +362,26 @@ function connections_content(&$a) { if(count($r)) { foreach($r as $rr) { - - $contacts[] = array( - 'img_hover' => sprintf( t('%1$s [%2$s]'),$rr['xchan_name'],$rr['xchan_url']), - 'edit_hover' => t('Edit contact'), - 'photo_menu' => contact_photo_menu($rr), - 'id' => $rr['abook_id'], - 'alt_text' => $alt_text, - 'dir_icon' => $dir_icon, - 'thumb' => $rr['xchan_photo_m'], - 'name' => $rr['xchan_name'], - 'username' => $rr['xchan_name'], - 'sparkle' => $sparkle, - 'edit' => z_root() . '/connections/' . $rr['abook_id'], - 'url' => $rr['xchan_url'], - 'network' => network_to_name($rr['network']), - ); + if($rr['xchan_url']) { + $contacts[] = array( + 'img_hover' => sprintf( t('%1$s [%2$s]'),$rr['xchan_name'],$rr['xchan_url']), + 'edit_hover' => t('Edit contact'), + 'id' => $rr['abook_id'], + 'alt_text' => $alt_text, + 'dir_icon' => $dir_icon, + 'thumb' => $rr['xchan_photo_m'], + 'name' => $rr['xchan_name'], + 'username' => $rr['xchan_name'], + 'classes' => (($rr['abook_flags'] & ABOOK_FLAG_ARCHIVED) ? 'archived' : ''), + 'link' => z_root() . '/connedit/' . $rr['abook_id'], + 'url' => chanlink_url($rr['xchan_url']), + 'network' => network_to_name($rr['network']), + ); + } } - - - } - - $tpl = get_markup_template("contacts-template.tpl"); - $o .= replace_macros($tpl,array( + $o .= replace_macros(get_markup_template('connections.tpl'),array( '$header' => t('Connections') . (($head) ? ' - ' . $head : ''), '$tabs' => $t, '$total' => $total, @@ -614,6 +389,7 @@ function connections_content(&$a) { '$desc' => t('Search your connections'), '$finding' => (($searching) ? t('Finding: ') . "'" . $search . "'" : ""), '$submit' => t('Find'), + '$edit' => t('Edit'), '$cmd' => $a->cmd, '$contacts' => $contacts, '$paginate' => paginate($a), diff --git a/mod/connedit.php b/mod/connedit.php new file mode 100644 index 000000000..61bb62766 --- /dev/null +++ b/mod/connedit.php @@ -0,0 +1,540 @@ +<?php + +/* @file connedit.php + * @brief In this file the connection-editor form is generated and evaluated. + * + * + */ + +require_once('include/Contact.php'); +require_once('include/socgraph.php'); +require_once('include/contact_selectors.php'); +require_once('include/group.php'); +require_once('include/contact_widgets.php'); +require_once('include/zot.php'); +require_once('include/widgets.php'); + +/* @brief Initialize the connection-editor + * + * + */ + +function connedit_init(&$a) { + + if(! local_user()) + return; + + if((argc() == 2) && intval(argv(1))) { + $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_user()), + intval(argv(1)) + ); + if($r) { + $a->poi = $r[0]; + } + } + + $channel = $a->get_channel(); + if($channel) + head_set_icon($channel['xchan_photo_s']); + +} + +/* @brief Evaluate posted values and set changes + * + */ + +function connedit_post(&$a) { + + if(! local_user()) + return; + + $contact_id = intval(argv(1)); + if(! $contact_id) + return; + + $orig_record = q("SELECT * FROM abook WHERE abook_id = %d AND abook_channel = %d LIMIT 1", + intval($contact_id), + intval(local_user()) + ); + + if(! $orig_record) { + notice( t('Could not access contact record.') . EOL); + goaway($a->get_baseurl(true) . '/connections'); + return; // NOTREACHED + } + + call_hooks('contact_edit_post', $_POST); + + $profile_id = $_POST['profile_assign']; + if($profile_id) { + $r = q("SELECT profile_guid FROM profile WHERE profile_guid = '%s' AND `uid` = %d LIMIT 1", + dbesc($profile_id), + intval(local_user()) + ); + if(! count($r)) { + notice( t('Could not locate selected profile.') . EOL); + return; + } + } + + $hidden = intval($_POST['hidden']); + + $priority = intval($_POST['poll']); + if($priority > 5 || $priority < 0) + $priority = 0; + + $closeness = intval($_POST['closeness']); + if($closeness < 0) + $closeness = 99; + + $abook_my_perms = 0; + + foreach($_POST as $k => $v) { + if(strpos($k,'perms_') === 0) { + $abook_my_perms += $v; + } + } + + $abook_flags = $orig_record[0]['abook_flags']; + $new_friend = false; + + + + if(($_REQUEST['pending']) && ($abook_flags & ABOOK_FLAG_PENDING)) { + $abook_flags = ( $abook_flags ^ ABOOK_FLAG_PENDING ); + $new_friend = true; + } + + $r = q("UPDATE abook SET abook_profile = '%s', abook_my_perms = %d , abook_closeness = %d, abook_flags = %d + where abook_id = %d AND abook_channel = %d LIMIT 1", + dbesc($profile_id), + intval($abook_my_perms), + intval($closeness), + intval($abook_flags), + intval($contact_id), + intval(local_user()) + ); + + if($orig_record[0]['abook_profile'] != $profile_id) { //Update profile photo permissions + + logger('As a new profile was assigned updateing profile photos'); + require_once('mod/profile_photo.php'); + profile_photo_set_profile_perms($profile_id); + + } + + + 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); + } + + if($new_friend) { + $channel = $a->get_channel(); + $default_group = $channel['channel_default_group']; + if($default_group) { + require_once('include/group.php'); + $g = group_rec_byhash(local_user(),$default_group); + if($g) + group_add_member(local_user(),'',$a->poi['abook_xchan'],$g['id']); + } + + + + // Check if settings permit ("post new friend activity" is allowed, and + // friends in general or this friend in particular aren't hidden) + // and send out a new friend activity + // TODO + + // pull in a bit of content if there is any to pull in + proc_run('php','include/onepoll.php',$contact_id); + + } + + // Refresh the structure in memory with the new data + + $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_user()), + intval($contact_id) + ); + if($r) { + $a->poi = $r[0]; + } + + if($new_friend) { + $arr = array('channel_id' => local_user(), 'abook' => $a->poi); + call_hooks('accept_follow', $arr); + } + + connedit_clone($a); + + return; + +} + +/* @brief Clone connection + * + * + */ + +function connedit_clone(&$a) { + + if(! $a->poi) + return; + $clone = $a->poi; + + unset($clone['abook_id']); + unset($clone['abook_account']); + unset($clone['abook_channel']); + + build_sync_packet(0 /* use the current local_user */, array('abook' => array($clone))); +} + +/* @brief Generate content of connection edit page + * + * + */ + +function connedit_content(&$a) { + + $sort_type = 0; + $o = ''; + + // this triggers some javascript to set Full Sharing by default after + // completing a "follow" - which can be changed to something else before + // form submission, but this gives us something useable + + if($_GET['follow'] == 1) { + $o .= '<script>var after_following = 1;</script>'; + } + if(! local_user()) { + notice( t('Permission denied.') . EOL); + return login(); + } + + if(argc() == 3) { + + $contact_id = intval(argv(1)); + if(! $contact_id) + return; + + $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 ) and not ( abook_flags & %d ) LIMIT 1", + intval($contact_id), + intval(local_user()), + intval(ABOOK_FLAG_SELF), + // allow drop even if pending, just duplicate the self query + intval(($cmd === 'drop') ? ABOOK_FLAG_SELF : ABOOK_FLAG_PENDING) + ); + + if(! count($orig_record)) { + notice( t('Could not access address book record.') . EOL); + goaway($a->get_baseurl(true) . '/connections'); + } + + if($cmd === 'update') { + + // pull feed and consume it, which should subscribe to the hub. + proc_run('php',"include/poller.php","$contact_id"); + goaway($a->get_baseurl(true) . '/connedit/' . $contact_id); + + } + + if($cmd === 'refresh') { + if(! zot_refresh($orig_record[0],get_app()->get_channel())) + notice( t('Refresh failed - channel is currently unavailable.') ); + goaway($a->get_baseurl(true) . '/connedit/' . $contact_id); + } + + 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 + notice(t('Unable to set address book parameters.') . EOL); + goaway($a->get_baseurl(true) . '/connedit/' . $contact_id); + } + + 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 + notice(t('Unable to set address book parameters.') . EOL); + goaway($a->get_baseurl(true) . '/connedit/' . $contact_id); + } + + 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 + notice(t('Unable to set address book parameters.') . EOL); + goaway($a->get_baseurl(true) . '/connedit/' . $contact_id); + } + + 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 + notice(t('Unable to set address book parameters.') . EOL); + goaway($a->get_baseurl(true) . '/connedit/' . $contact_id); + } + + // We'll prevent somebody from unapproving a contact. + + if($cmd === 'approve') { + if($orig_record[0]['abook_flags'] & ABOOK_FLAG_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 + notice(t('Unable to set address book parameters.') . EOL); + } + goaway($a->get_baseurl(true) . '/connedit/' . $contact_id); + } + + + if($cmd === 'drop') { + + require_once('include/Contact.php'); +// FIXME +// terminate_friendship($a->get_channel(),$orig_record[0]); + + contact_remove(local_user(), $orig_record[0]['abook_id']); +// FIXME - send to clones + info( t('Connection has been removed.') . EOL ); + if(x($_SESSION,'return_url')) + goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']); + goaway($a->get_baseurl(true) . '/contacts'); + + } + } + + if($a->poi) { + + $contact_id = $a->poi['abook_id']; + $contact = $a->poi; + + + $tabs = array( + + array( + 'label' => t('View Profile'), + 'url' => chanlink_cid($contact['abook_id']), + 'sel' => '', + 'title' => sprintf( t('View %s\'s profile'), $contact['xchan_name']), + ), + + array( + 'label' => t('Refresh Permissions'), + 'url' => $a->get_baseurl(true) . '/connedit/' . $contact['abook_id'] . '/refresh', + 'sel' => '', + 'title' => t('Fetch updated permissions'), + ), + + array( + 'label' => t('Recent Activity'), + 'url' => $a->get_baseurl(true) . '/network/?f=&cid=' . $contact['abook_id'], + 'sel' => '', + 'title' => t('View recent posts and comments'), + ), + + array( + 'label' => (($contact['abook_flags'] & ABOOK_FLAG_BLOCKED) ? t('Unblock') : t('Block')), + 'url' => $a->get_baseurl(true) . '/connedit/' . $contact['abook_id'] . '/block', + 'sel' => (($contact['abook_flags'] & ABOOK_FLAG_BLOCKED) ? 'active' : ''), + 'title' => t('Block or Unblock this connection'), + ), + + array( + 'label' => (($contact['abook_flags'] & ABOOK_FLAG_IGNORED) ? t('Unignore') : t('Ignore')), + 'url' => $a->get_baseurl(true) . '/connedit/' . $contact['abook_id'] . '/ignore', + 'sel' => (($contact['abook_flags'] & ABOOK_FLAG_IGNORED) ? 'active' : ''), + 'title' => t('Ignore or Unignore this connection'), + ), + array( + 'label' => (($contact['abook_flags'] & ABOOK_FLAG_ARCHIVED) ? t('Unarchive') : t('Archive')), + 'url' => $a->get_baseurl(true) . '/connedit/' . $contact['abook_id'] . '/archive', + 'sel' => (($contact['abook_flags'] & ABOOK_FLAG_ARCHIVED) ? 'active' : ''), + 'title' => t('Archive or Unarchive this connection'), + ), + array( + 'label' => (($contact['abook_flags'] & ABOOK_FLAG_HIDDEN) ? t('Unhide') : t('Hide')), + 'url' => $a->get_baseurl(true) . '/connedit/' . $contact['abook_id'] . '/hide', + 'sel' => (($contact['abook_flags'] & ABOOK_FLAG_HIDDEN) ? 'active' : ''), + 'title' => t('Hide or Unhide this connection'), + ), + + array( + 'label' => t('Delete'), + 'url' => $a->get_baseurl(true) . '/connedit/' . $contact['abook_id'] . '/drop', + 'sel' => '', + 'title' => t('Delete this connection'), + ), + + ); + + $self = false; + + if(! ($contact['abook_flags'] & ABOOK_FLAG_SELF)) { + $tab_tpl = get_markup_template('common_tabs.tpl'); + $t = replace_macros($tab_tpl, array('$tabs'=>$tabs)); + } + else + $self = true; + + $a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), array( + '$baseurl' => $a->get_baseurl(true), + '$editselect' => $editselect + )); + + require_once('include/contact_selectors.php'); + + $tpl = get_markup_template("abook_edit.tpl"); + + if(feature_enabled(local_user(),'affinity')) { + + $slider_tpl = get_markup_template('contact_slider.tpl'); + $slide = replace_macros($slider_tpl,array( + '$me' => t('Me'), + '$val' => (($contact['abook_closeness']) ? $contact['abook_closeness'] : 99), + '$intimate' => t('Best Friends'), + '$friends' => t('Friends'), + '$oldfriends' => t('Former Friends'), + '$acquaintances' => t('Acquaintances'), + '$world' => t('Unknown') + )); + } + + $perms = array(); + $channel = $a->get_channel(); + + $global_perms = get_perms(); + $existing = get_all_perms(local_user(),$contact['abook_xchan']); + + $unapproved = array('pending', t('Approve this connection'), '', t('Accept connection to allow communication')); + + foreach($global_perms as $k => $v) { + $thisperm = (($contact['abook_my_perms'] & $v[1]) ? "1" : ''); + + // For auto permissions (when $self is true) we don't want to look at existing + // permissions because they are enabled for the channel owner + + if((! $self) && ($existing[$k])) + $thisperm = "1"; + + $perms[] = array('perms_' . $k, $v[3], (($contact['abook_their_perms'] & $v[1]) ? "1" : ""),$thisperm, $v[1], (($channel[$v[0]] == PERMS_SPECIFIC) ? '' : '1'), $v[4]); + } + + $o .= replace_macros($tpl,array( + + '$header' => (($self) ? t('Automatic Permissions Settings') : sprintf( t('Connections: settings for %s'),$contact['xchan_name'])), + '$addr' => $contact['xchan_addr'], + '$notself' => (($self) ? '' : '1'), + '$self' => (($self) ? '1' : ''), + '$autolbl' => t('When receiving a channel introduction, any permissions provided here will be applied to the new connection automatically and the introduction approved. Leave this page if you do not wish to use this feature.'), + '$viewprof' => t('View Profile'), + '$lbl_slider' => t('Slide to adjust your degree of friendship'), + '$slide' => $slide, + '$tabs' => $t, + '$tab_str' => $tab_str, + '$is_pending' => (($contact['abook_flags'] & ABOOK_FLAG_PENDING) ? 1 : ''), + '$unapproved' => $unapproved, + '$inherited' => t('inherited'), + '$approve' => t('Approve this connection'), + '$noperms' => (((! $self) && (! $contact['abook_my_perms'])) ? t('Connection has no individual permissions!') : ''), + '$noperm_desc' => (((! $self) && (! $contact['abook_my_perms'])) ? t('This may be appropriate based on your <a href="settings">privacy settings</a>, though you may wish to review the "Advanced Permissions".') : ''), + '$submit' => t('Submit'), + '$lbl_vis1' => t('Profile Visibility'), + '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['xchan_name']), + '$lbl_info1' => t('Contact Information / Notes'), + '$infedit' => t('Edit contact notes'), + '$close' => $contact['abook_closeness'], + '$them' => t('Their Settings'), + '$me' => t('My Settings'), + '$perms' => $perms, + '$clear' => t('Clear/Disable Automatic Permissions'), + '$forum' => t('Forum Members'), + '$soapbox' => t('Soapbox'), + '$full' => t('Full Sharing (typical social network permissions)'), + '$cautious' => t('Cautious Sharing '), + '$follow' => t('Follow Only'), + '$permlbl' => t('Individual Permissions'), + '$permnote' => t('Some permissions may be inherited from your channel <a href="settings">privacy settings</a>, which have higher priority than individual settings. Changing those inherited settings on this page will have no effect.'), + '$advanced' => t('Advanced Permissions'), + '$quick' => t('Simple Permissions (select one and submit)'), + '$common_link' => $a->get_baseurl(true) . '/common/loc/' . local_user() . '/' . $contact['id'], + '$all_friends' => $all_friends, + '$relation_text' => $relation_text, + '$visit' => sprintf( t('Visit %s\'s profile - %s'),$contact['xchan_name'],$contact['xchan_url']), + '$blockunblock' => t('Block/Unblock contact'), + '$ignorecont' => t('Ignore contact'), + '$lblcrepair' => t("Repair URL settings"), + '$lblrecent' => t('View conversations'), + '$lblsuggest' => $lblsuggest, + '$delete' => t('Delete contact'), + '$poll_interval' => contact_poll_interval($contact['priority'],(! $poll_enabled)), + '$poll_enabled' => $poll_enabled, + '$lastupdtext' => t('Last update:'), + '$lost_contact' => $lost_contact, + '$updpub' => t('Update public posts'), + '$last_update' => relative_date($contact['abook_connected']), + '$udnow' => t('Update now'), + '$profile_select' => contact_profile_assign($contact['abook_profile']), + '$multiprofs' => feature_enabled(local_user(),'multi_profiles'), + '$contact_id' => $contact['abook_id'], + '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ), + '$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ), + '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''), + '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''), + '$archived' => (($contact['archive']) ? t('Currently archived') : ''), + '$pending' => (($contact['archive']) ? t('Currently pending') : ''), + '$hidden' => array('hidden', t('Hide this contact from others'), ($contact['hidden'] == 1), t('Replies/likes to your public posts <strong>may</strong> still be visible')), + '$photo' => $contact['photo'], + '$name' => $contact['name'], + '$dir_icon' => $dir_icon, + '$alt_text' => $alt_text, + '$sparkle' => $sparkle, + '$url' => $url + + )); + + $arr = array('contact' => $contact,'output' => $o); + + call_hooks('contact_edit', $arr); + + return $arr['output']; + + } + + +} diff --git a/mod/contactgroup.php b/mod/contactgroup.php index 4b46605a6..8b23f9f10 100644 --- a/mod/contactgroup.php +++ b/mod/contactgroup.php @@ -20,7 +20,7 @@ function contactgroup_content(&$a) { if((argc() > 1) && (intval(argv(1)))) { - $r = q("SELECT * FROM `group` WHERE `id` = %d AND `uid` = %d AND `deleted` = 0 LIMIT 1", + $r = q("SELECT * FROM `groups` WHERE `id` = %d AND `uid` = %d AND `deleted` = 0 LIMIT 1", intval(argv(1)), intval(local_user()) ); diff --git a/mod/crepair.php b/mod/crepair.php deleted file mode 100644 index e5ece0f98..000000000 --- a/mod/crepair.php +++ /dev/null @@ -1,171 +0,0 @@ -<?php - -function crepair_init(&$a) { - if(! local_user()) - return; - - $contact_id = 0; - - if(($a->argc == 2) && intval($a->argv[1])) { - $contact_id = intval($a->argv[1]); - $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1", - intval(local_user()), - intval($contact_id) - ); - if(! count($r)) { - $contact_id = 0; - } - } - - if(! x($a->page,'aside')) - $a->page['aside'] = ''; - - if($contact_id) { - $a->data['contact'] = $r[0]; - $o .= '<div class="vcard">'; - $o .= '<div class="fn">' . $a->data['contact']['name'] . '</div>'; - $o .= '<div id="profile-photo-wrapper"><img class="photo" style="width: 175px; height: 175px;" src="' . $a->data['contact']['photo'] . '" alt="' . $a->data['contact']['name'] . '" /></div>'; - $o .= '</div>'; - $a->page['aside'] .= $o; - - } -} - - -function crepair_post(&$a) { - if(! local_user()) - return; - - $cid = (($a->argc > 1) ? intval($a->argv[1]) : 0); - - if($cid) { - $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", - intval($cid), - intval(local_user()) - ); - } - - if(! count($r)) - return; - - $contact = $r[0]; - - $name = ((x($_POST,'name')) ? $_POST['name'] : $contact['name']); - $nick = ((x($_POST,'nick')) ? $_POST['nick'] : ''); - $url = ((x($_POST,'url')) ? $_POST['url'] : ''); - $request = ((x($_POST,'request')) ? $_POST['request'] : ''); - $confirm = ((x($_POST,'confirm')) ? $_POST['confirm'] : ''); - $notify = ((x($_POST,'notify')) ? $_POST['notify'] : ''); - $poll = ((x($_POST,'poll')) ? $_POST['poll'] : ''); - $attag = ((x($_POST,'attag')) ? $_POST['attag'] : ''); - $photo = ((x($_POST,'photo')) ? $_POST['photo'] : ''); - - $r = q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `url` = '%s', `request` = '%s', `confirm` = '%s', `notify` = '%s', `poll` = '%s', `attag` = '%s' - WHERE `id` = %d AND `uid` = %d LIMIT 1", - dbesc($name), - dbesc($nick), - dbesc($url), - dbesc($request), - dbesc($confirm), - dbesc($notify), - dbesc($poll), - dbesc($attag), - intval($contact['id']), - local_user() - ); - - if($photo) { - logger('mod-crepair: updating photo from ' . $photo); - require_once("Photo.php"); - - $photos = import_profile_photo($photo,local_user(),$contact['id']); - - $x = q("UPDATE `contact` SET `photo` = '%s', - `thumb` = '%s', - `micro` = '%s', - `name_date` = '%s', - `uri_date` = '%s', - `avatar_date` = '%s' - WHERE `id` = %d LIMIT 1 - ", - dbesc($photos[0]), - dbesc($photos[1]), - dbesc($photos[2]), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - intval($contact['id']) - ); - } - - if($r) - info( t('Contact settings applied.') . EOL); - else - notice( t('Contact update failed.') . EOL); - - - return; -} - - - -function crepair_content(&$a) { - - if(! local_user()) { - notice( t('Permission denied.') . EOL); - return; - } - - $cid = (($a->argc > 1) ? intval($a->argv[1]) : 0); - - if($cid) { - $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", - intval($cid), - intval(local_user()) - ); - } - - if(! count($r)) { - notice( t('Contact not found.') . EOL); - return; - } - - $contact = $r[0]; - - $msg1 = t('Repair Contact Settings'); - - $msg2 = t('<strong>WARNING: This is highly advanced</strong> and if you enter incorrect information your communications with this contact may stop working.'); - $msg3 = t('Please use your browser \'Back\' button <strong>now</strong> if you are uncertain what to do on this page.'); - - $o .= '<h2>' . $msg1 . '</h2>'; - - $o .= '<div class="error-message">' . $msg2 . EOL . EOL. $msg3 . '</div>'; - - $o .= EOL . '<a href="contacts/' . $cid . '">' . t('Return to contact editor') . '</a>' . EOL; - - $tpl = get_markup_template('crepair.tpl'); - $o .= replace_macros($tpl, array( - '$label_name' => t('Name'), - '$label_nick' => t('Account Nickname'), - '$label_attag' => t('@Tagname - overrides Name/Nickname'), - '$label_url' => t('Account URL'), - '$label_request' => t('Friend Request URL'), - '$label_confirm' => t('Friend Confirm URL'), - '$label_notify' => t('Notification Endpoint URL'), - '$label_poll' => t('Poll/Feed URL'), - '$label_photo' => t('New photo from this URL'), - '$contact_name' => $contact['name'], - '$contact_nick' => $contact['nick'], - '$contact_id' => $contact['id'], - '$contact_url' => $contact['url'], - '$request' => $contact['request'], - '$confirm' => $contact['confirm'], - '$notify' => $contact['notify'], - '$poll' => $contact['poll'], - '$contact_attag' => $contact['attag'], - '$lbl_submit' => t('Submit') - )); - - return $o; - -} diff --git a/mod/directory.php b/mod/directory.php index 21fb14bfc..b11b0d410 100644 --- a/mod/directory.php +++ b/mod/directory.php @@ -1,22 +1,14 @@ <?php require_once('include/dir_fns.php'); +require_once('include/widgets.php'); function directory_init(&$a) { - $a->set_pager_itemspage(60); + $a->set_pager_itemspage(80); } -function directory_aside(&$a) { - - if(local_user()) { - require_once('include/contact_widgets.php'); - $a->set_widget('find_people',findpeople_widget()); - } -} - - function directory_content(&$a) { if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { @@ -24,6 +16,24 @@ function directory_content(&$a) { return; } + $safe_mode = 1; + + $observer = get_observer_hash(); + + if($observer) { + $safe_mode = get_xconfig($observer,'directory','safe_mode'); + } + if($safe_mode === false) + $safe_mode = 1; + else + $safe_mode = intval($safe_mode); + + if(x($_REQUEST,'safe')) + $safe_mode = (intval($_REQUEST['safe'])); + + + + $o = ''; nav_set_selected('directory'); @@ -32,10 +42,13 @@ function directory_content(&$a) { else $search = ((x($_GET,'search')) ? notags(trim(rawurldecode($_GET['search']))) : ''); + $advanced = ((x($_REQUEST,'query')) ? notags(trim($_REQUEST['query'])) : ''); - $tpl = get_markup_template('directory_header.tpl'); + $keywords = (($_GET['keywords']) ? $_GET['keywords'] : ''); + $tpl = get_markup_template('directory_header.tpl'); + $dirmode = intval(get_config('system','directory_mode')); if(($dirmode == DIRECTORY_MODE_PRIMARY) || ($dirmode == DIRECTORY_MODE_STANDALONE)) { @@ -43,22 +56,45 @@ function directory_content(&$a) { } if(! $url) { $directory = find_upstream_directory($dirmode); + $url = $directory['url'] . '/dirsearch'; + } - if($directory) { - $url = $directory['url']; - } - else { - $url = DIRECTORY_FALLBACK_MASTER . '/dirsearch'; + logger('mod_directory: URL = ' . $url, LOGGER_DEBUG); + + $contacts = array(); + + if(local_user()) { + $x = q("select abook_xchan from abook where abook_channel = %d", + intval(local_user()) + ); + if($x) { + foreach($x as $xx) + $contacts[] = $xx['abook_xchan']; } } - logger('mod_directory: URL = ' . $url, LOGGER_DEBUG); + + if($url) { - $query = $url . '?f=' ; + // We might want to make the tagadelic count (&kw=) configurable or turn it off completely. + + $numtags = get_config('system','directorytags'); + + $kw = ((intval($numtags)) ? $numtags : 24); + $query = $url . '?f=&kw=' . $kw . (($safe_mode != 1) ? '&safe=' . $safe_mode : ''); + if($search) - $query .= '&name=' . urlencode($search); + $query .= '&name=' . urlencode($search) . '&keywords=' . urlencode($search); if(strpos($search,'@')) $query .= '&address=' . urlencode($search); + if($keywords) + $query .= '&keywords=' . urlencode($keywords); + if($advanced) + $query .= '&query=' . urlencode($advanced); + + $sort_order = ((x($_REQUEST,'order')) ? $_REQUEST['order'] : ''); + if($sort_order) + $query .= '&order=' . urlencode($sort_order); if($a->pager['page'] != 1) $query .= '&p=' . $a->pager['page']; @@ -66,7 +102,7 @@ function directory_content(&$a) { logger('mod_directory: query: ' . $query); $x = z_fetch_url($query); - logger('directory: return from upstream: ' . print_r($x,true)); + logger('directory: return from upstream: ' . print_r($x,true), LOGGER_DATA); if($x['success']) { $t = 0; @@ -84,7 +120,11 @@ function directory_content(&$a) { $profile_link = chanlink_url($rr['url']); $pdesc = (($rr['description']) ? $rr['description'] . '<br />' : ''); - + $connect_link = ((local_user()) ? z_root() . '/follow?f=&url=' . urlencode($rr['address']) : ''); + + if(in_array($rr['hash'],$contacts)) + $connect_link = ''; + $details = ''; if(strlen($rr['locale'])) $details .= $rr['locale']; @@ -128,32 +168,38 @@ function directory_content(&$a) { 'id' => ++$t, 'profile_link' => $profile_link, 'photo' => $rr['photo'], + 'hash' => $rr['hash'], 'alttext' => $rr['name'] . ' ' . $rr['address'], 'name' => $rr['name'], 'details' => $pdesc . $details, 'profile' => $profile, + 'address' => $rr['address'], 'location' => $location, 'gender' => $gender, 'pdesc' => $pdesc, 'marital' => $marital, 'homepage' => $homepage, 'about' => $about, - + 'conn_label' => t('Connect'), + 'connect' => $connect_link, ); $arr = array('contact' => $rr, 'entry' => $entry); call_hooks('directory_item', $arr); - $entries[] = $entry; - + $entries[] = $arr['entry']; unset($profile); unset($location); } - logger('mod_directory: entries: ' . print_r($entries,true), LOGGER_DATA); + if($j['keywords']) { + $a->data['directory_keywords'] = $j['keywords']; + } + +// logger('mod_directory: entries: ' . print_r($entries,true), LOGGER_DATA); $o .= replace_macros($tpl, array( '$search' => $search, @@ -166,7 +212,7 @@ function directory_content(&$a) { )); - $o .= alt_pager($a,$j['records'], t('more'), t('back')); + $o .= alt_pager($a,$j['records'], t('next page'), t('previous page')); } else { diff --git a/mod/dirfind.php b/mod/dirfind.php deleted file mode 100644 index 54bbf31af..000000000 --- a/mod/dirfind.php +++ /dev/null @@ -1,68 +0,0 @@ -<?php - -function dirfind_init(&$a) { - - require_once('include/contact_widgets.php'); - - if(! x($a->page,'aside')) - $a->page['aside'] = ''; - - $a->page['aside'] .= follow_widget(); - - $a->page['aside'] .= findpeople_widget(); -} - - - -function dirfind_content(&$a) { - - $search = notags(trim($_REQUEST['search'])); - - if(strpos($search,'@') === 0) - $search = substr($search,1); - - $o = ''; - - $o .= '<h2>' . t('People Search') . ' - ' . $search . '</h2>'; - - if($search) { - - $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : ''); - - if(strlen(get_config('system','directory_submit_url'))) - $x = fetch_url('http://dir.friendica.com/lsearch?f=' . $p . '&search=' . urlencode($search)); - -//TODO fallback local search if global dir not available. -// else -// $x = post_url($a->get_baseurl() . '/lsearch', $params); - - $j = json_decode($x); - - if($j->total) { - $a->set_pager_total($j->total); - $a->set_pager_itemspage($j->items_page); - } - - if(count($j->results)) { - - $tpl = get_markup_template('match.tpl'); - foreach($j->results as $jj) { - - $o .= replace_macros($tpl,array( - '$url' => zid($jj->url), - '$name' => $jj->name, - '$photo' => $jj->photo, - '$tags' => $jj->tags - )); - } - } - else { - info( t('No matches') . EOL); - } - - } - - $o .= '<div class="clear"></div>'; - $o .= paginate($a); - return $o; -} diff --git a/mod/dirprofile.php b/mod/dirprofile.php new file mode 100644 index 000000000..e9b12ada7 --- /dev/null +++ b/mod/dirprofile.php @@ -0,0 +1,184 @@ +<?php + +require_once('include/dir_fns.php'); +require_once('include/bbcode.php'); + +function dirprofile_init(&$a) { + + if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { + notice( t('Public access denied.') . EOL); + return; + } + + $hash = $_REQUEST['hash']; + if(! $hash) + return ''; + + $o = ''; + + $dirmode = intval(get_config('system','directory_mode')); + + if(($dirmode == DIRECTORY_MODE_PRIMARY) || ($dirmode == DIRECTORY_MODE_STANDALONE)) { + $url = z_root() . '/dirsearch'; + } + if(! $url) { + $directory = find_upstream_directory($dirmode); + $url = $directory['url'] . '/dirsearch'; + } + logger('mod_directory: URL = ' . $url, LOGGER_DEBUG); + + $contacts = array(); + + if(local_user()) { + $x = q("select abook_xchan from abook where abook_channel = %d", + intval(local_user()) + ); + if($x) { + foreach($x as $xx) + $contacts[] = $xx['abook_xchan']; + } + } + + + + if($url) { + + $query = $url . '?f=&hash=' . $hash; + + $x = z_fetch_url($query); + logger('dirprofile: return from upstream: ' . print_r($x,true), LOGGER_DATA); + + if($x['success']) { + $t = 0; + $j = json_decode($x['body'],true); + if($j) { + + if($j['results']) { + + $entries = array(); + + $photo = 'thumb'; + + foreach($j['results'] as $rr) { + + $profile_link = chanlink_url($rr['url']); + + $pdesc = (($rr['description']) ? $rr['description'] . '<br />' : ''); + + $qrlink = zid($rr['url']); + $connect_link = ((local_user()) ? z_root() . '/follow?f=&url=' . urlencode($rr['address']) : ''); + + $online = remote_online_status($rr['address']); + + + if(in_array($rr['hash'],$contacts)) + $connect_link = ''; + + $details = ''; + if(strlen($rr['locale'])) + $details .= $rr['locale']; + if(strlen($rr['region'])) { + if(strlen($rr['locale'])) + $details .= ', '; + $details .= $rr['region']; + } + if(strlen($rr['country'])) { + if(strlen($details)) + $details .= ', '; + $details .= $rr['country']; + } + if(strlen($rr['birthday'])) { + if(($years = age($rr['birthday'],'UTC','')) != 0) + $details .= '<br />' . t('Age: ') . $years ; + } + if(strlen($rr['gender'])) + $details .= '<br />' . t('Gender: ') . $rr['gender']; + + $page_type = ''; + + $profile = $rr; + + if ((x($profile,'locale') == 1) + || (x($profile,'region') == 1) + || (x($profile,'postcode') == 1) + || (x($profile,'country') == 1)) + $location = t('Location:'); + + + $marital = ((x($profile,'marital') == 1) ? t('Status: ') . $profile['marital'] : False); + $sexual = ((x($profile,'sexual') == 1) ? t('Sexual Preference: ') . $profile['sexual'] : False); + + $homepage = ((x($profile,'homepage') == 1) ? t('Homepage: ') . linkify($profile['homepage']) : False); + $hometown = ((x($profile,'hometown') == 1) ? t('Hometown: ') . $profile['hometown'] : False); + + $about = ((x($profile,'about') == 1) ? t('About: ') . bbcode($profile['about']) : False); + + $keywords = ((x($profile,'keywords')) ? $profile['keywords'] : ''); + if($keywords) { + $keywords = str_replace(',',' ', $keywords); + $keywords = str_replace(' ',' ', $keywords); + $karr = explode(' ', $keywords); + $out = ''; + if($karr) { + if(local_user()) { + $r = q("select keywords from profile where uid = %d and is_default = 1 limit 1", + intval(local_user()) + ); + if($r) { + $keywords = str_replace(',',' ', $r[0]['keywords']); + $keywords = str_replace(' ',' ', $keywords); + $marr = explode(' ', $keywords); + } + } + foreach($karr as $k) { + if(strlen($out)) + $out .= ', '; + if($marr && in_arrayi($k,$marr)) + $out .= '<strong>' . $k . '</strong>'; + else + $out .= $k; + } + } + + } + $entry = replace_macros(get_markup_template('direntry_large.tpl'), array( + '$id' => ++$t, + '$profile_link' => $profile_link, + '$qrlink' => $qrlink, + '$photo' => $rr['photo_l'], + '$alttext' => $rr['name'] . ' ' . $rr['address'], + '$name' => $rr['name'], + '$online' => (($online) ? t('Online Now') : ''), + '$details' => $pdesc . $details, + '$profile' => $profile, + '$address' => $rr['address'], + '$location' => $location, + '$gender' => $gender, + '$pdesc' => $pdesc, + '$marital' => $marital, + '$homepage' => $homepage, + '$hometown' => $hometown, + '$about' => $about, + '$kw' => (($out) ? t('Keywords: ') : ''), + '$keywords' => $out, + '$conn_label' => t('Connect'), + '$connect' => $connect_link, + )); + + + echo $entry; + killme(); + + } + } + else { + info( t("Not found.") . EOL); + } + } + } + } + + + + +}
\ No newline at end of file diff --git a/mod/dirsearch.php b/mod/dirsearch.php index 7e4323da9..0ace4ecae 100644 --- a/mod/dirsearch.php +++ b/mod/dirsearch.php @@ -22,45 +22,115 @@ function dirsearch_content(&$a) { json_return_and_die($ret); } - $name = ((x($_REQUEST,'name')) ? $_REQUEST['name'] : ''); - $address = ((x($_REQUEST,'address')) ? $_REQUEST['address'] : ''); - $locale = ((x($_REQUEST,'locale')) ? $_REQUEST['locale'] : ''); - $region = ((x($_REQUEST,'region')) ? $_REQUEST['region'] : ''); + if(argc() > 1 && argv(1) === 'sites') { + $ret = list_public_sites(); + json_return_and_die($ret); + } + + $sql_extra = ''; + + $tables = array('name','address','locale','region','postcode','country','gender','marital','sexual','keywords'); + + if($_REQUEST['query']) { + $advanced = dir_parse_query($_REQUEST['query']); + if($advanced) { + foreach($advanced as $adv) { + if(in_array($adv['field'],$tables)) { + if($adv['field'] === 'name') + $sql_extra .= dir_query_build($adv['logic'],'xchan_name',$adv['value']); + elseif($adv['field'] === 'address') + $sql_extra .= dir_query_build($adv['logic'],'xchan_addr',$adv['value']); + else + $sql_extra .= dir_query_build($adv['logic'],'xprof_' . $adv['field'],$adv['value']); + } + } + } + } + + $hash = ((x($_REQUEST['hash'])) ? $_REQUEST['hash'] : ''); + + $name = ((x($_REQUEST,'name')) ? $_REQUEST['name'] : ''); + $hub = ((x($_REQUEST,'hub')) ? $_REQUEST['hub'] : ''); + $address = ((x($_REQUEST,'address')) ? $_REQUEST['address'] : ''); + $locale = ((x($_REQUEST,'locale')) ? $_REQUEST['locale'] : ''); + $region = ((x($_REQUEST,'region')) ? $_REQUEST['region'] : ''); $postcode = ((x($_REQUEST,'postcode')) ? $_REQUEST['postcode'] : ''); - $country = ((x($_REQUEST,'country')) ? $_REQUEST['country'] : ''); - $gender = ((x($_REQUEST,'gender')) ? $_REQUEST['gender'] : ''); - $marital = ((x($_REQUEST,'marital')) ? $_REQUEST['marital'] : ''); + $country = ((x($_REQUEST,'country')) ? $_REQUEST['country'] : ''); + $gender = ((x($_REQUEST,'gender')) ? $_REQUEST['gender'] : ''); + $marital = ((x($_REQUEST,'marital')) ? $_REQUEST['marital'] : ''); + $sexual = ((x($_REQUEST,'sexual')) ? $_REQUEST['sexual'] : ''); $keywords = ((x($_REQUEST,'keywords')) ? $_REQUEST['keywords'] : ''); + $agege = ((x($_REQUEST,'agege')) ? intval($_REQUEST['agege']) : 0 ); + $agele = ((x($_REQUEST,'agele')) ? intval($_REQUEST['agele']) : 0 ); + $kw = ((x($_REQUEST,'kw')) ? intval($_REQUEST['kw']) : 0 ); + + // by default use a safe search + $safe = ((x($_REQUEST,'safe'))); // ? intval($_REQUEST['safe']) : 1 ); + if ($safe === false) + $safe = 1; + + if(array_key_exists('sync',$_REQUEST)) { + if($_REQUEST['sync']) + $sync = datetime_convert('UTC','UTC',$_REQUEST['sync']); + else + $sync = datetime_convert('UTC','UTC','2010-01-01 01:01:00'); + } + else + $sync = false; -// TODO - a meta search which joins all of these things to one search string + $sort_order = ((x($_REQUEST,'order')) ? $_REQUEST['order'] : ''); - $sql_extra = ''; + $joiner = ' OR '; + if($_REQUEST['and']) + $joiner = ' AND '; if($name) - $sql_extra .= " OR xchan_name like '" . protect_sprintf( '%' . dbesc($name) . '%' ) . "' "; + $sql_extra .= dir_query_build($joiner,'xchan_name',$name); + if($hub) + $sql_extra .= " $joiner xchan_hash in (select hubloc_hash from hubloc where hubloc_host = '" . protect_sprintf(dbesc($hub)) . "') "; if($address) - $sql_extra .= " OR xchan_addr like '" . protect_sprintf( '%' . dbesc($address) . '%' ) . "' "; + $sql_extra .= dir_query_build($joiner,'xchan_addr',$address); if($city) - $sql_extra .= " OR xprof_locale like '" . protect_sprintf( '%' . dbesc($city) . '%' ) . "' "; + $sql_extra .= dir_query_build($joiner,'xprof_locale',$city); if($region) - $sql_extra .= " OR xprof_region like '" . protect_sprintf( '%' . dbesc($region) . '%' ) . "' "; + $sql_extra .= dir_query_build($joiner,'xprof_region',$region); if($post) - $sql_extra .= " OR xprof_postcode like '" . protect_sprintf( '%' . dbesc($post) . '%' ) . "' "; + $sql_extra .= dir_query_build($joiner,'xprof_postcode',$post); if($country) - $sql_extra .= " OR xprof_country like '" . protect_sprintf( '%' . dbesc($country) . '%' ) . "' "; + $sql_extra .= dir_query_build($joiner,'xprof_country',$country); if($gender) - $sql_extra .= " OR xprof_gender like '" . protect_sprintf( '%' . dbesc($gender) . '%' ) . "' "; + $sql_extra .= dir_query_build($joiner,'xprof_gender',$gender); if($marital) - $sql_extra .= " OR xprof_marital like '" . protect_sprintf( '%' . dbesc($marital) . '%' ) . "' "; + $sql_extra .= dir_query_build($joiner,'xprof_marital',$marital); + if($sexual) + $sql_extra .= dir_query_build($joiner,'xprof_sexual',$sexual); if($keywords) - $sql_extra .= " OR xprof_keywords like '" . protect_sprintf( '%' . dbesc($keywords) . '%' ) . "' "; + $sql_extra .= dir_query_build($joiner,'xprof_keywords',$keywords); + + // we only support an age range currently. You must set both agege + // (greater than or equal) and agele (less than or equal) + + if($agele && $agege) { + $sql_extra .= " $joiner ( xprof_age <= " . intval($agele) . " "; + $sql_extra .= " AND xprof_age >= " . intval($agege) . ") "; + } + - $perpage = (($_REQUEST['n']) ? $_REQUEST['n'] : 80); - $page = (($_REQUEST['p']) ? intval($_REQUEST['p'] - 1) : 0); - $startrec = (($page+1) * $perpage) - $perpage; - $limit = (($_REQUEST['limit']) ? intval($_REQUEST['limit']) : 0); + if($hash) { + $sql_extra = " AND xchan_hash = '" . dbesc($hash) . "' "; + } + + + $perpage = (($_REQUEST['n']) ? $_REQUEST['n'] : 80); + $page = (($_REQUEST['p']) ? intval($_REQUEST['p'] - 1) : 0); + $startrec = (($page+1) * $perpage) - $perpage; + $limit = (($_REQUEST['limit']) ? intval($_REQUEST['limit']) : 0); $return_total = ((x($_REQUEST,'return_total')) ? intval($_REQUEST['return_total']) : 0); + // mtime is not currently working + + $mtime = ((x($_REQUEST,'mtime')) ? datetime_convert('UTC','UTC',$_REQUEST['mtime']) : ''); + // ok a separate tag table won't work. // merge them into xprof @@ -72,13 +142,22 @@ function dirsearch_content(&$a) { $logic = ((strlen($sql_extra)) ? 0 : 1); + if($hash) + $logic = 1; + + $safesql = (($safe > 0) ? " and not ( xchan_flags & " . intval(XCHAN_FLAGS_CENSORED|XCHAN_FLAGS_SELFCENSORED) . " ) " : ''); + if($safe < 0) + $safesql = " and ( xchan_flags & " . intval(XCHAN_FLAGS_CENSORED|XCHAN_FLAGS_SELFCENSORED) . " ) "; + if($limit) $qlimit = " LIMIT $limit "; else { $qlimit = " LIMIT " . intval($startrec) . " , " . intval($perpage); 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 not ( xchan_flags & %d) ", - intval(XCHAN_FLAGS_HIDDEN) + $r = q("SELECT COUNT(xchan_hash) AS `total` FROM xchan left join xprof on xchan_hash = xprof_hash where $logic $sql_extra and not ( xchan_flags & %d) and not ( xchan_flags & %d ) and not ( xchan_flags & %d ) $safesql ", + intval(XCHAN_FLAGS_HIDDEN), + intval(XCHAN_FLAGS_ORPHAN), + intval(XCHAN_FLAGS_DELETED) ); if($r) { $ret['total_items'] = $r[0]['total']; @@ -86,11 +165,46 @@ function dirsearch_content(&$a) { } } - $order = " ORDER BY `xchan_name` ASC "; - $r = q("SELECT xchan.*, xprof.* from xchan left join xprof on xchan_hash = xprof_hash where $logic $sql_extra and not ( xchan_flags & %d ) $order $qlimit ", - intval(XCHAN_FLAGS_HIDDEN) - ); + if($sort_order == 'normal') + $order = " order by xchan_name asc "; + elseif($sort_order == 'reverse') + $order = " order by xchan_name desc "; + else + $order = " order by xchan_name_date desc "; + + + if($sync) { + $spkt = array('transactions' => array()); + $r = q("select * from updates where ud_date >= '%s' and ud_guid != '' order by ud_date desc", + dbesc($sync) + ); + if($r) { + foreach($r as $rr) { + $flags = array(); + if($rr['ud_flags'] & UPDATE_FLAGS_DELETED) + $flags[] = 'deleted'; + if($rr['ud_flags'] & UPDATE_FLAGS_FORCED) + $flags[] = 'forced'; + + $spkt['transactions'][] = array( + 'hash' => $rr['ud_hash'], + 'address' => $rr['ud_addr'], + 'transaction_id' => $rr['ud_guid'], + 'timestamp' => $rr['ud_date'], + 'flags' => $flags + ); + } + } + 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 ) and not ( xchan_flags & %d ) and not ( xchan_flags & %d ) and not ( xchan_flags & %d ) $safesql $order $qlimit ", + intval(XCHAN_FLAGS_HIDDEN), + intval(XCHAN_FLAGS_ORPHAN), + intval(XCHAN_FLAGS_DELETED) + ); + } $ret['page'] = $page + 1; $ret['records'] = count($r); @@ -104,7 +218,10 @@ function dirsearch_content(&$a) { $entry = array(); $entry['name'] = $rr['xchan_name']; + $entry['hash'] = $rr['xchan_hash']; + $entry['url'] = $rr['xchan_url']; + $entry['photo_l'] = $rr['xchan_photo_l']; $entry['photo'] = $rr['xchan_photo_m']; $entry['address'] = $rr['xchan_addr']; $entry['description'] = $rr['xprof_desc']; @@ -113,8 +230,13 @@ function dirsearch_content(&$a) { $entry['postcode'] = $rr['xprof_postcode']; $entry['country'] = $rr['xprof_country']; $entry['birthday'] = $rr['xprof_dob']; + $entry['age'] = $rr['xprof_age']; $entry['gender'] = $rr['xprof_gender']; $entry['marital'] = $rr['xprof_marital']; + $entry['sexual'] = $rr['xprof_sexual']; + $entry['about'] = $rr['xprof_about']; + $entry['homepage'] = $rr['xprof_homepage']; + $entry['hometown'] = $rr['xprof_hometown']; $entry['keywords'] = $rr['xprof_keywords']; $entries[] = $entry; @@ -122,8 +244,122 @@ function dirsearch_content(&$a) { } $ret['results'] = $entries; - + if($kw) { + $k = dir_tagadelic($kw); + if($k) { + $ret['keywords'] = array(); + foreach($k as $kv) { + $ret['keywords'][] = array('term' => $kv[0],'weight' => $kv[1], 'normalise' => $kv[2]); + } + } + } } json_return_and_die($ret); } + +function dir_query_build($joiner,$field,$s) { + $ret = ''; + if(trim($s)) + $ret .= dbesc($joiner) . " " . dbesc($field) . " like '" . protect_sprintf( '%' . dbesc($s) . '%' ) . "' "; + return $ret; +} + +function dir_parse_query($s) { + + $ret = array(); + $curr = array(); + $all = explode(' ',$s); + $quoted_string = false; + + if($all) { + foreach($all as $q) { + if($q === 'and') { + $curr['logic'] = 'and'; + continue; + } + if($q === 'or') { + $curr['logic'] = 'or'; + continue; + } + if($q === 'not') { + $curr['logic'] .= ' not'; + continue; + } + if(strpos($q,'=')) { + if(! isset($curr['logic'])) + $curr['logic'] = 'or'; + $curr['field'] = trim(substr($q,0,strpos($q,'='))); + $curr['value'] = trim(substr($q,strpos($q,'=')+1)); + if(strpos($curr['value'],'"') !== false) { + $quoted_string = true; + $curr['value'] = substr($curr['value'],strpos($curr['value'],'"')+1); + } + else { + $ret[] = $curr; + $curr = array(); + $continue; + } + } + elseif($quoted_string) { + if(strpos($q,'"') !== false) { + $curr['value'] .= ' ' . str_replace('"','',trim($q)); + $ret[] = $curr; + $curr = array(); + $quoted_string = false; + } + else + $curr['value'] .= ' ' . trim(q); + } + } + } + logger('dir_parse_query:' . print_r($ret,true),LOGGER_DATA); + return $ret; +} + + + + + + + +function list_public_sites() { + + + $r = q("select * from site where site_access != 0 and site_register !=0 order by rand()"); + $ret = array('success' => false); + + if($r) { + $ret['success'] = true; + $ret['sites'] = array(); + $insecure = array(); + + foreach($r as $rr) { + + if($rr['site_access'] == ACCESS_FREE) + $access = 'free'; + elseif($rr['site_access'] == ACCESS_PAID) + $access = 'paid'; + elseif($rr['site_access'] == ACCESS_TIERED) + $access = 'tiered'; + else + $access = 'private'; + + if($rr['site_register'] == REGISTER_OPEN) + $register = 'open'; + elseif($rr['site_register'] == REGISTER_APPROVE) + $register = 'approve'; + else + $register = 'closed'; + + if(strpos($rr['site_url'],'https://') !== false) + $ret['sites'][] = array('url' => $rr['site_url'], 'access' => $access, 'register' => $register, 'sellpage' => $rr['site_sellpage'], 'location' => $rr['site_location']); + else + $insecure[] = array('url' => $rr['site_url'], 'access' => $access, 'register' => $register, 'sellpage' => $rr['site_sellpage'], 'location' => $rr['site_location']); + } + if($insecure) { + $ret['sites'] = array_merge($ret['sites'],$insecure); + } + } + return $ret; +} diff --git a/mod/display.php b/mod/display.php index 3c2172c7d..f4d4c38c3 100644 --- a/mod/display.php +++ b/mod/display.php @@ -3,6 +3,8 @@ function display_content(&$a, $update = 0, $load = false) { +// logger("mod-display: update = $update load = $load"); + if(intval(get_config('system','block_public')) && (! local_user()) && (! remote_user())) { notice( t('Public access denied.') . EOL); return; @@ -17,11 +19,12 @@ function display_content(&$a, $update = 0, $load = false) { $a->page['htmlhead'] .= replace_macros(get_markup_template('display-head.tpl'), array()); - if(argc() > 1 && argv(1) !== 'load') $item_hash = argv(1); - if($_REQUEST['uri']) - $item_hash = $_REQUEST['uri']; + + + if($_REQUEST['mid']) + $item_hash = $_REQUEST['mid']; if(! $item_hash) { @@ -32,6 +35,37 @@ function display_content(&$a, $update = 0, $load = false) { $observer_is_owner = false; + + if(local_user() && (! $update)) { + + $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'] + ); + + $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($channel_acl, false), + 'bang' => '', + 'visitor' => true, + 'profile_uid' => local_user(), + 'return_path' => 'channel/' . $channel['channel_address'] + ); + + $o .= status_editor($a,$x); + + } + // This page can be viewed by anybody so the query could be complicated // First we'll see if there is a copy of the item which is owned by us - if we're logged in locally. // If that fails (or we aren't logged in locally), @@ -43,7 +77,7 @@ function display_content(&$a, $update = 0, $load = false) { $target_item = null; - $r = q("select uri, parent_uri from item where uri = '%s' limit 1", + $r = q("select id, uid, mid, parent_mid, item_restrict from item where mid = '%s' limit 1", dbesc($item_hash) ); @@ -51,11 +85,29 @@ function display_content(&$a, $update = 0, $load = false) { $target_item = $r[0]; } + if($target_item['item_restrict'] & ITEM_WEBPAGE) { + $x = q("select * from channel where channel_id = %d limit 1", + intval($target_item['uid']) + ); + $y = q("select * from item_id where uid = %d and service = 'WEBPAGE' and iid = %d limit 1", + intval($target_item['uid']), + intval($target_item['id']) + ); + if($x && $y) { + goaway(z_root() . '/page/' . $x[0]['channel_address'] . '/' . $y[0]['sid']); + } + else { + notice( t('Page not found.') . EOL); + return ''; + } + } + + if((! $update) && (! $load)) { $o .= '<div id="live-display"></div>' . "\r\n"; - $o .= "<script> var profile_uid = " . intval(local_user()) + $o .= "<script> var profile_uid = " . ((intval(local_user())) ? local_user() : (-1)) . "; var netargs = '?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n"; $a->page['htmlhead'] .= replace_macros(get_markup_template("build_query.tpl"),array( @@ -70,16 +122,18 @@ function display_content(&$a, $update = 0, $load = false) { '$liked' => '0', '$conv' => '0', '$spam' => '0', + '$fh' => '0', '$nouveau' => '0', '$wall' => '0', '$page' => (($a->pager['page'] != 1) ? $a->pager['page'] : 1), + '$list' => ((x($_REQUEST,'list')) ? intval($_REQUEST['list']) : 0), '$search' => '', '$order' => '', '$file' => '', '$cats' => '', '$dend' => '', '$dbegin' => '', - '$uri' => $item_hash + '$mid' => $item_hash )); @@ -87,23 +141,42 @@ function display_content(&$a, $update = 0, $load = false) { $sql_extra = public_permissions_sql(get_observer_hash()); + if(($update && $load) || ($_COOKIE['jsAvailable'] != 1)) { - if($update && $load) { + $updateable = false; $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage'])); - if($load) { - - $r = q("SELECT * from item - WHERE item_restrict = 0 - and uri = '%s' - AND ((( `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' - AND `item`.`deny_gid` = '' AND item_private = 0 ) - and uid in ( " . stream_perms_api_uids() . " )) - $sql_extra ) - group by uri limit 1", - dbesc($target_item['parent_uri']) - ); + if($load || ($_COOKIE['jsAvailable'] != 1)) { + $r = null; + if(local_user()) { + $r = q("SELECT * from item + WHERE item_restrict = 0 + and uid = %d + and mid = '%s' + limit 1", + intval(local_user()), + dbesc($target_item['parent_mid']) + ); + if($r) { + $updateable = true; + + } + } + if($r === null) { + + $r = q("SELECT * from item + WHERE item_restrict = 0 + and 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) ? PERMS_NETWORK : PERMS_PUBLIC) . " )) + $sql_extra ) + group by mid limit 1", + dbesc($target_item['parent_mid']) + ); + + } } else { @@ -131,14 +204,31 @@ function display_content(&$a, $update = 0, $load = false) { } - $o .= conversation($a,$items,'display', $update, 'client'); + if ($_COOKIE['jsAvailable'] == 1) { + $o .= conversation($a, $items, 'display', $update, 'client'); + } else { + $o .= conversation($a, $items, 'display', $update, 'traditional'); + } + + if($updateable) { + $x = q("UPDATE item SET item_flags = ( item_flags ^ %d ) + WHERE (item_flags & %d) AND uid = %d and parent = %d ", + intval(ITEM_UNSEEN), + intval(ITEM_UNSEEN), + intval(local_user()), + intval($r[0]['parent']) + ); + } + + $o .= '<div id="content-complete"></div>'; + return $o; /* elseif((! $update) && (! { - $r = q("SELECT `id`, item_flags FROM `item` WHERE `id` = '%s' OR `uri` = '%s' LIMIT 1", + $r = q("SELECT `id`, item_flags FROM `item` WHERE `id` = '%s' OR `mid` = '%s' LIMIT 1", dbesc($item_hash), dbesc($item_hash) ); diff --git a/mod/editblock.php b/mod/editblock.php new file mode 100644 index 000000000..507050eb0 --- /dev/null +++ b/mod/editblock.php @@ -0,0 +1,159 @@ +<?php + + +function editblock_content(&$a) { + + + if(argc() < 2) { + notice( t('Item not found') . EOL); + return; + } + + $channel = get_channel_by_nick(argv(1)); + + if($c) { + $owner = intval($channel['channel_id']); + } + + + $o = ''; + + + // Figure out which post we're editing + $post_id = ((argc() > 2) ? intval(argv(2)) : 0); + + + if(! ($post_id && $channel)) { + notice( t('Item not found') . EOL); + return; + } + + // Now we've got a post and an owner, let's find out if we're allowed to edit it + + if(! perm_is_allowed($channel['channel_id'],get_observer_hash(),'write_pages')) { + notice( t('Permission denied.') . EOL); + return; + } + + + + // We've already figured out which item we want and whose copy we need, so we don't need anything fancy here + $itm = q("SELECT * FROM `item` WHERE `id` = %d and uid = %s LIMIT 1", + intval($post_id), + intval($channel['channel_id']) + ); + if($itm) { + $item_id = q("select * from item_id where service = 'BUILDBLOCK' and iid = %d limit 1", + $itm[0]['id'] + ); + if($item_id) + $block_title = $item_id[0]['sid']; + } + else { + notice( t('Item not found') . EOL); + return; + } + + + $plaintext = true; + + // You may or may not be a local user. + if(local_user() && feature_enabled(local_user(),'richtext')) + $plaintext = false; + + $mimeselect = ''; + $mimetype = $itm[0]['mimetype']; + + if($mimetype != 'text/bbcode') + $plaintext = true; + + if(get_config('system','page_mimetype')) + $mimeselect = '<input type="hidden" name="mimetype" value="' . $mimetype . '" />'; + else + $mimeselect = mimetype_select($itm[0]['uid'],$mimetype); + + + $o .= replace_macros(get_markup_template('edpost_head.tpl'), array( + '$title' => t('Edit Block') + )); + + + $a->page['htmlhead'] .= replace_macros(get_markup_template('jot-header.tpl'), array( + '$baseurl' => $a->get_baseurl(), + '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'), + '$ispublic' => ' ', // t('Visible to <strong>everybody</strong>'), + '$geotag' => '', + '$nickname' => $channel['channel_address'], + '$confirmdelete' => t('Delete block?') + )); + + + $tpl = get_markup_template("jot.tpl"); + + $jotplugins = ''; + $jotnets = ''; + + call_hooks('jot_tool', $jotplugins); + call_hooks('jot_networks', $jotnets); + + + //$tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins)); + + // FIXME A return path with $_SESSION doesn't always work for observer - it may WSoD instead of loading a sensible page. + //So, send folk to the webpage list. + + $rp = 'blocks/' . $channel['channel_address']; + + $o .= replace_macros($tpl,array( + '$return_path' => $rp, + '$action' => 'item', + '$webpage' => ITEM_BUILDBLOCK, + '$share' => t('Edit'), + '$upload' => t('Upload photo'), + '$attach' => t('Attach file'), + '$weblink' => t('Insert web link'), + '$youtube' => t('Insert YouTube video'), + '$video' => t('Insert Vorbis [.ogg] video'), + '$audio' => t('Insert Vorbis [.ogg] audio'), + '$setloc' => t('Set your location'), + '$noloc' => t('Clear browser location'), + '$wait' => t('Please wait'), + '$permset' => t('Permission settings'), + '$ptyp' => $itm[0]['type'], + '$mimeselect' => $mimeselect, + '$content' => undo_post_tagging($itm[0]['body']), + '$post_id' => $post_id, + '$baseurl' => $a->get_baseurl(), + '$defloc' => $channel['channel_location'], + '$visitor' => false, + '$public' => t('Public post'), + '$jotnets' => $jotnets, + '$title' => htmlspecialchars($itm[0]['title'],ENT_COMPAT,'UTF-8'), + '$placeholdertitle' => t('Set title'), + '$pagetitle' => $block_title, + '$category' => '', + '$placeholdercategory' => t('Categories (comma-separated list)'), + '$emtitle' => t('Example: bob@example.com, mary@example.com'), + '$lockstate' => $lockstate, + '$acl' => '', + '$bang' => '', + '$profile_uid' => (intval($channel['channel_id'])), + '$preview' => ((feature_enabled(local_user(),'preview')) ? t('Preview') : ''), + '$jotplugins' => $jotplugins, + '$sourceapp' => $itm[0]['app'], + '$defexpire' => '', + '$feature_expire' => false, + '$expires' => t('Set expiration date'), + )); + + + $ob = get_observer_hash(); + + if(($itm[0]['author_xchan'] === $ob) || ($itm[0]['owner_xchan'] === $ob)) + $o .= '<br /><br /><a class="block-delete-link" href="item/drop/' . $itm[0]['id'] . '" >' . t('Delete Block') . '</a><br />'; + + return $o; + +} + + diff --git a/mod/editlayout.php b/mod/editlayout.php new file mode 100644 index 000000000..da681cf34 --- /dev/null +++ b/mod/editlayout.php @@ -0,0 +1,152 @@ +<?php + +// What is this here for? I think it's cruft, but comment out for now in case it's here for a reason +// require_once('acl_selectors.php'); + +function editlayout_content(&$a) { + +// We first need to figure out who owns the webpage, grab it from an argument + $which = argv(1); + +// $a->get_channel() and stuff don't work here, so we've got to find the owner for ourselves. + $r = q("select channel_id from channel where channel_address = '%s'", + dbesc($which) + ); + if($r) { + $owner = intval($r[0]['channel_id']); + //logger('owner: ' . print_r($owner,true)); + } + + + + + if((local_user()) && (argc() > 2) && (argv(2) === 'view')) { + $which = $channel['channel_address']; + } + + + $o = ''; + + +// Figure out which post we're editing + $post_id = ((argc() > 2) ? intval(argv(2)) : 0); + + + if(! $post_id) { + notice( t('Item not found') . EOL); + return; + } + +// Now we've got a post and an owner, let's find out if we're allowed to edit it + + $observer = $a->get_observer(); + $ob_hash = (($observer) ? $observer['xchan_hash'] : ''); + + $perms = get_all_perms($owner,$ob_hash); + + if(! $perms['write_pages']) { + notice( t('Permission denied.') . EOL); + return; + } + + + +// We've already figured out which item we want and whose copy we need, so we don't need anything fancy here + $itm = q("SELECT * FROM `item` WHERE `id` = %d and uid = %s LIMIT 1", + intval($post_id), + intval($owner) + ); + + $item_id = q("select * from item_id where service = 'PDL' and iid = %d limit 1", + $itm[0]['id'] + ); + if($item_id) + $layout_title = $item_id[0]['sid']; + + $plaintext = true; +// You may or may not be a local user. This won't work, + if(feature_enabled(local_user(),'richtext')) + $plaintext = false; + + $o .= replace_macros(get_markup_template('edpost_head.tpl'), array( + '$title' => t('Edit Layout') + )); + + + $a->page['htmlhead'] .= replace_macros(get_markup_template('jot-header.tpl'), array( + '$baseurl' => $a->get_baseurl(), + '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'), + '$ispublic' => ' ', // t('Visible to <strong>everybody</strong>'), + '$geotag' => $geotag, + '$nickname' => $a->user['nickname'], + '$confirmdelete' => t('Delete layout?') + )); + + + $tpl = get_markup_template("jot.tpl"); + + $jotplugins = ''; + $jotnets = ''; + + call_hooks('jot_tool', $jotplugins); + call_hooks('jot_networks', $jotnets); + + $channel = $a->get_channel(); + + //$tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins)); + +//FIXME A return path with $_SESSION doesn't always work for observer - it may WSoD instead of loading a sensible page. So, send folk to the webpage list. + + $rp = '/layouts/' . $which; + + $o .= replace_macros($tpl,array( + '$return_path' => $rp, + '$action' => 'item', + '$webpage' => ITEM_PDL, + '$share' => t('Edit'), + '$upload' => t('Upload photo'), + '$attach' => t('Attach file'), + '$weblink' => t('Insert web link'), + '$youtube' => t('Insert YouTube video'), + '$video' => t('Insert Vorbis [.ogg] video'), + '$audio' => t('Insert Vorbis [.ogg] audio'), + '$setloc' => t('Set your location'), + '$noloc' => t('Clear browser location'), + '$wait' => t('Please wait'), + '$permset' => t('Permission settings'), + '$ptyp' => $itm[0]['type'], + '$content' => undo_post_tagging($itm[0]['body']), + '$post_id' => $post_id, + '$baseurl' => $a->get_baseurl(), + '$defloc' => $channel['channel_location'], + '$visitor' => false, + '$public' => t('Public post'), + '$jotnets' => $jotnets, + '$title' => htmlspecialchars($itm[0]['title'],ENT_COMPAT,'UTF-8'), + '$placeholdertitle' => t('Set title'), + '$pagetitle' => $layout_title, + '$category' => '', + '$placeholdercategory' => t('Categories (comma-separated list)'), + '$emtitle' => t('Example: bob@example.com, mary@example.com'), + '$lockstate' => $lockstate, + '$acl' => '', + '$bang' => '', + '$profile_uid' => (intval($owner)), + '$preview' => ((feature_enabled(local_user(),'preview')) ? t('Preview') : ''), + '$jotplugins' => $jotplugins, + '$sourceapp' => t($a->sourcename), + '$defexpire' => '', + '$feature_expire' => false, + '$expires' => t('Set expiration date'), + )); + + $ob = get_observer_hash(); + + if(($itm[0]['author_xchan'] === $ob) || ($itm[0]['owner_xchan'] === $ob)) + $o .= '<br /><br /><a class="layout-delete-link" href="item/drop/' . $itm[0]['id'] . '" >' . t('Delete Layout') . '</a><br />'; + + return $o; + +} + + diff --git a/mod/editpost.php b/mod/editpost.php index 43c71ca8a..6556405e3 100644 --- a/mod/editpost.php +++ b/mod/editpost.php @@ -1,6 +1,9 @@ -<?php +<?php /** @file */ require_once('acl_selectors.php'); +require_once('include/crypto.php'); +require_once('include/items.php'); +require_once('include/taxonomy.php'); function editpost_content(&$a) { @@ -18,13 +21,14 @@ function editpost_content(&$a) { return; } - $itm = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1", + $itm = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d and author_xchan = '%s' LIMIT 1", intval($post_id), - intval(local_user()) + intval(local_user()), + dbesc(get_observer_hash()) ); if(! count($itm)) { - notice( t('Item not found') . EOL); + notice( t('Item is not editable') . EOL); return; } @@ -32,6 +36,8 @@ function editpost_content(&$a) { if(feature_enabled(local_user(),'richtext')) $plaintext = false; + $channel = $a->get_channel(); + $o .= replace_macros(get_markup_template('edpost_head.tpl'), array( '$title' => t('Edit post') )); @@ -42,10 +48,21 @@ function editpost_content(&$a) { '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'), '$ispublic' => ' ', // t('Visible to <strong>everybody</strong>'), '$geotag' => $geotag, - '$nickname' => $a->user['nickname'] + '$nickname' => $channel['channel_address'], + '$expireswhen' => t('Expires YYYY-MM-DD HH:MM'), + '$confirmdelete' => t('Delete item?'), )); + + if($itm[0]['item_flags'] & ITEM_OBSCURED) { + $key = get_config('system','prvkey'); + if($itm[0]['title']) + $itm[0]['title'] = crypto_unencapsulate(json_decode_plus($itm[0]['title']),$key); + if($itm[0]['body']) + $itm[0]['body'] = crypto_unencapsulate(json_decode_plus($itm[0]['body']),$key); + } + $tpl = get_markup_template("jot.tpl"); $jotplugins = ''; @@ -59,6 +76,36 @@ function editpost_content(&$a) { //$tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins)); + $category = ''; + $catsenabled = ((feature_enabled(local_user(),'categories')) ? 'categories' : ''); + + if ($catsenabled){ + $itm = fetch_post_tags($itm); + + $cats = get_terms_oftype($itm[0]['term'], TERM_CATEGORY); + + foreach ($cats as $cat) { + if (strlen($category)) + $category .= ', '; + $category .= $cat['term']; + } + + } + + if($itm[0]['attach']) { + $j = json_decode($itm[0]['attach'],true); + if($j) { + foreach($j as $jj) { + $itm[0]['body'] .= "\n" . '[attachment]' . basename($jj['href']) . ',' . $jj['revision'] . '[/attachment]' . "\n"; + } + } + } + + $cipher = get_pconfig(get_app()->profile['profile_uid'],'system','default_cipher'); + if(! $cipher) + $cipher = 'aes256'; + + $o .= replace_macros($tpl,array( '$return_path' => $_SESSION['return_url'], '$action' => 'item', @@ -78,13 +125,12 @@ function editpost_content(&$a) { '$post_id' => $post_id, '$baseurl' => $a->get_baseurl(), '$defloc' => $channel['channel_location'], - '$visitor' => 'none', - '$pvisit' => 'none', + '$visitor' => false, '$public' => t('Public post'), '$jotnets' => $jotnets, - '$title' => $itm[0]['title'], + '$title' => htmlspecialchars($itm[0]['title'],ENT_COMPAT,'UTF-8'), '$placeholdertitle' => t('Set title'), - '$category' => file_tag_file_to_list($itm[0]['file'], 'category'), + '$category' => $category, '$placeholdercategory' => t('Categories (comma-separated list)'), '$emtitle' => t('Example: bob@example.com, mary@example.com'), '$lockstate' => $lockstate, @@ -94,6 +140,15 @@ function editpost_content(&$a) { '$preview' => ((feature_enabled(local_user(),'preview')) ? t('Preview') : ''), '$jotplugins' => $jotplugins, '$sourceapp' => t($a->sourcename), + '$catsenabled' => $catsenabled, + '$defexpire' => datetime_convert('UTC', date_default_timezone_get(),$itm[0]['expires']), + '$feature_expire' => ((feature_enabled(get_app()->profile['profile_uid'],'content_expire') && (! $webpage)) ? true : false), + '$expires' => t('Set expiration date'), + '$feature_encrypt' => ((feature_enabled(get_app()->profile['profile_uid'],'content_encrypt') && (! $webpage)) ? true : false), + '$encrypt' => t('Encrypt text'), + '$cipher' => $cipher, + '$expiryModalOK' => t('OK'), + '$expiryModalCANCEL' => t('Cancel'), )); return $o; diff --git a/mod/editwebpage.php b/mod/editwebpage.php new file mode 100644 index 000000000..38aef4a8b --- /dev/null +++ b/mod/editwebpage.php @@ -0,0 +1,193 @@ +<?php + +// Required for setting permissions. (FIXME) + +require_once('acl_selectors.php'); + +function editwebpage_content(&$a) { + + // We first need to figure out who owns the webpage, grab it from an argument + + $which = argv(1); + + // $a->get_channel() and stuff don't work here, so we've got to find the owner for ourselves. + + $r = q("select channel_id from channel where channel_address = '%s'", + dbesc($which) + ); + if($r) { + $owner = intval($r[0]['channel_id']); + //logger('owner: ' . print_r($owner,true)); + } + + $is_owner = ((local_user() && local_user() == $owner) ? true : false); + + $o = ''; + + // Figure out which post we're editing + $post_id = ((argc() > 2) ? intval(argv(2)) : 0); + + + if(! $post_id) { + notice( t('Item not found') . EOL); + return; + } + + // Now we've got a post and an owner, let's find out if we're allowed to edit it + + $observer = $a->get_observer(); + $ob_hash = (($observer) ? $observer['xchan_hash'] : ''); + + $perms = get_all_perms($owner,$ob_hash); + + if(! $perms['write_pages']) { + notice( t('Permission denied.') . EOL); + return; + } + + + + // We've already figured out which item we want and whose copy we need, so we don't need anything fancy here + $itm = q("SELECT * FROM `item` WHERE `id` = %d and uid = %s LIMIT 1", + intval($post_id), + intval($owner) + ); + + + if($itm[0]['item_flags'] & ITEM_OBSCURED) { + $key = get_config('system','prvkey'); + if($itm[0]['title']) + $itm[0]['title'] = crypto_unencapsulate(json_decode_plus($itm[0]['title']),$key); + if($itm[0]['body']) + $itm[0]['body'] = crypto_unencapsulate(json_decode_plus($itm[0]['body']),$key); + } + + $item_id = q("select * from item_id where service = 'WEBPAGE' and iid = %d limit 1", + $itm[0]['id'] + ); + if($item_id) + $page_title = $item_id[0]['sid']; + + + + + $plaintext = true; + + if(feature_enabled($itm[0]['uid'],'richtext')) + $plaintext = false; + + $mimetype = $itm[0]['mimetype']; + + if($mimetype === 'application/x-php') { + if((! local_user()) || (local_user() != $itm[0]['uid'])) { + notice( t('Permission denied.') . EOL); + return; + } + } + + $mimeselect = ''; + + if($mimetype != 'text/bbcode') + $plaintext = true; + + if(get_config('system','page_mimetype')) + $mimeselect = '<input type="hidden" name="mimetype" value="' . $mimetype . '" />'; + else + $mimeselect = mimetype_select($itm[0]['uid'],$mimetype); + + $layout = get_config('system','page_layout'); + if($layout) + $layoutselect = '<input type="hidden" name="layout_mid" value="' . $layout . '" />'; + else + $layoutselect = layout_select($itm[0]['uid'],$itm[0]['layout_mid']); + + + $o .= replace_macros(get_markup_template('edpost_head.tpl'), array( + '$title' => t('Edit Webpage') + )); + + + $a->page['htmlhead'] .= replace_macros(get_markup_template('jot-header.tpl'), array( + '$baseurl' => $a->get_baseurl(), + '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'), + '$ispublic' => ' ', // t('Visible to <strong>everybody</strong>'), + '$geotag' => $geotag, + '$nickname' => $a->user['nickname'], + '$confirmdelete' => t('Delete webpage?') + )); + + + $tpl = get_markup_template("jot.tpl"); + + $jotplugins = ''; + $jotnets = ''; + + call_hooks('jot_tool', $jotplugins); + call_hooks('jot_networks', $jotnets); + + $channel = $a->get_channel(); + + //$tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins)); + +//FIXME A return path with $_SESSION doesn't always work for observer - it may WSoD instead of loading a sensible page. So, send folk to the webpage list. + + $rp = 'webpages/' . $which; + + $o .= replace_macros($tpl,array( + '$return_path' => $rp, + '$webpage' => ITEM_WEBPAGE, + '$placeholdpagetitle' => t('Page link title'), + '$pagetitle' => $page_title, + + '$action' => 'item', + '$share' => t('Edit'), + '$upload' => t('Upload photo'), + '$attach' => t('Attach file'), + '$weblink' => t('Insert web link'), + '$youtube' => t('Insert YouTube video'), + '$video' => t('Insert Vorbis [.ogg] video'), + '$audio' => t('Insert Vorbis [.ogg] audio'), + '$setloc' => t('Set your location'), + '$noloc' => t('Clear browser location'), + '$wait' => t('Please wait'), + '$permset' => t('Permission settings'), + '$ptyp' => $itm[0]['type'], + '$content' => undo_post_tagging($itm[0]['body']), + '$post_id' => $post_id, + '$baseurl' => $a->get_baseurl(), + '$defloc' => $itm[0]['location'], + '$visitor' => ($is_owner) ? true : false, + '$acl' => populate_acl($itm[0]), + '$showacl' => ($is_owner) ? true : false, + '$public' => t('Public post'), + '$jotnets' => $jotnets, + '$mimeselect' => $mimeselect, + '$layoutselect' => $layoutselect, + '$title' => htmlspecialchars($itm[0]['title'],ENT_COMPAT,'UTF-8'), + '$placeholdertitle' => t('Set title'), + '$category' => '', + '$placeholdercategory' => t('Categories (comma-separated list)'), + '$emtitle' => t('Example: bob@example.com, mary@example.com'), + 'lockstate' => (((strlen($itm[0]['allow_cid'])) || (strlen($itm[0]['allow_gid'])) || (strlen($itm[0]['deny_cid'])) || (strlen($itm[0]['deny_gid']))) ? 'lock' : 'unlock'), + '$acl' => populate_acl($itm[0]), + '$bang' => '', + '$profile_uid' => (intval($owner)), + '$preview' => ((feature_enabled(local_user(),'preview')) ? t('Preview') : ''), + '$jotplugins' => $jotplugins, + '$sourceapp' => t($a->sourcename), + '$defexpire' => '', + '$feature_expire' => false, + '$expires' => t('Set expiration date'), + + )); + + $ob = get_observer_hash(); + + if(($itm[0]['author_xchan'] === $ob) || ($itm[0]['owner_xchan'] === $ob)) + $o .= '<br /><br /><a class="page-delete-link" href="item/drop/' . $itm[0]['id'] . '" >' . t('Delete Webpage') . '</a><br />'; + + return $o; + +} + + diff --git a/mod/events.php b/mod/events.php index 8c509cfea..8bf8c6ce1 100755 --- a/mod/events.php +++ b/mod/events.php @@ -1,5 +1,6 @@ <?php +require_once('include/conversation.php'); require_once('include/bbcode.php'); require_once('include/datetime.php'); require_once('include/event.php'); @@ -11,7 +12,7 @@ function events_post(&$a) { return; $event_id = ((x($_POST,'event_id')) ? intval($_POST['event_id']) : 0); - $cid = ((x($_POST,'cid')) ? intval($_POST['cid']) : 0); + $xchan = ((x($_POST,'xchan')) ? dbesc($_POST['xchan']) : ''); $uid = local_user(); $startyear = intval($_POST['startyear']); $startmonth = intval($_POST['startmonth']); @@ -28,6 +29,11 @@ function events_post(&$a) { $adjust = intval($_POST['adjust']); $nofinish = intval($_POST['nofinish']); + // 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; @@ -102,7 +108,7 @@ function events_post(&$a) { $datarray['start'] = $start; $datarray['finish'] = $finish; $datarray['summary'] = $summary; - $datarray['desc'] = $desc; + $datarray['description'] = $desc; $datarray['location'] = $location; $datarray['type'] = $type; $datarray['adjust'] = $adjust; @@ -135,6 +141,8 @@ function events_content(&$a) { return; } + nav_set_selected('all_events'); + if((argc() > 2) && (argv(1) === 'ignore') && intval(argv(2))) { $r = q("update event set ignore = 1 where id = %d and uid = %d limit 1", intval(argv(2)), @@ -150,12 +158,24 @@ function events_content(&$a) { } + $plaintext = true; + + if(feature_enabled(local_user(),'richtext')) + $plaintext = false; + + $htpl = get_markup_template('event_head.tpl'); - $a->page['htmlhead'] .= replace_macros($htpl,array('$baseurl' => $a->get_baseurl())); + $a->page['htmlhead'] .= replace_macros($htpl,array( + '$baseurl' => $a->get_baseurl(), + '$editselect' => (($plaintext) ? 'none' : 'textareas') + )); $o =""; // tabs - $tabs = profile_tabs($a, True); + + $channel = $a->get_channel(); + + $tabs = profile_tabs($a, True, $channel['channel_address']); @@ -229,9 +249,9 @@ function events_content(&$a) { $adjust_start = datetime_convert('UTC', date_default_timezone_get(), $start); $adjust_finish = datetime_convert('UTC', date_default_timezone_get(), $finish); - if (x($_GET,'id')){ - $r = q("SELECT * from event left join item on resource_id = event_hash where resource_type = 'event' and event.uid = %d and event.id = %d limit 1", + $r = q("SELECT event.*, item.plink, item.item_flags, item.author_xchan, item.owner_xchan + from event left join item on resource_id = event_hash where resource_type = 'event' and event.uid = %d and event.id = %d limit 1", intval(local_user()), intval($_GET['id']) ); @@ -242,8 +262,8 @@ function events_content(&$a) { // Noting this for now - it will need to be fixed here and in Friendica. // Ultimately the finish date shouldn't be involved in the query. - - $r = q("SELECT * from event left join item on event_hash = resource_id + $r = q("SELECT event.*, item.plink, item.item_flags, item.author_xchan, item.owner_xchan + from event left join item on event_hash = resource_id where resource_type = 'event' and event.uid = %d and event.ignore = %d AND (( `adjust` = 0 AND ( `finish` >= '%s' or nofinish ) AND `start` <= '%s' ) OR ( `adjust` = 1 AND ( `finish` >= '%s' or nofinish ) AND `start` <= '%s' )) ", @@ -339,6 +359,7 @@ function events_content(&$a) { else { $tpl = get_markup_template("events-js.tpl"); } + $o = replace_macros($tpl, array( '$baseurl' => $a->get_baseurl(), '$tabs' => $tabs, @@ -346,8 +367,7 @@ function events_content(&$a) { '$new_event'=> array($a->get_baseurl().'/events/new',t('Create New Event'),'',''), '$previus' => array($a->get_baseurl()."/events/$prevyear/$prevmonth",t('Previous'),'',''), '$next' => array($a->get_baseurl()."/events/$nextyear/$nextmonth",t('Next'),'',''), - '$calendar' => cal($y,$m,$links, ' eventcal'), - + '$calendar' => cal($y,$m,$links, ' eventcal'), '$events' => $events, @@ -379,20 +399,17 @@ function events_content(&$a) { $l_orig = ((x($orig_event)) ? $orig_event['location'] : ''); $eid = ((x($orig_event)) ? $orig_event['id'] : 0); $event_xchan = ((x($orig_event)) ? $orig_event['event_xchan'] : $channel['channel_hash']); - $uri = ((x($orig_event)) ? $orig_event['uri'] : ''); + $mid = ((x($orig_event)) ? $orig_event['mid'] : ''); if(! x($orig_event)) $sh_checked = ''; else $sh_checked = (($orig_event['allow_cid'] === '<' . $channel['channel_hash'] . '>' && (! $orig_event['allow_gid']) && (! $orig_event['deny_cid']) && (! $orig_event['deny_gid'])) ? '' : ' checked="checked" ' ); - if($cid) + if($orig_event['event_xchan']) $sh_checked .= ' disabled="disabled" '; - - $tpl = get_markup_template('event_form.tpl'); - $sdt = ((x($orig_event)) ? $orig_event['start'] : 'now'); $fdt = ((x($orig_event)) ? $orig_event['finish'] : 'now'); @@ -423,11 +440,21 @@ 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'] + ); + + $tpl = get_markup_template('event_form.tpl'); + + $o .= replace_macros($tpl,array( '$post' => $a->get_baseurl() . '/events', '$eid' => $eid, '$xchan' => $event_xchan, - '$uri' => $uri, + '$mid' => $mid, '$title' => t('Event details'), '$desc' => sprintf( t('Format is %s %s. Starting date and Title are required.'),$dateformat,$timeformat), @@ -450,8 +477,7 @@ function events_content(&$a) { '$t_orig' => $t_orig, '$sh_text' => t('Share this event'), '$sh_checked' => $sh_checked, -// FIXME - '$acl' => (($cid) ? '' : populate_acl(((x($orig_event)) ? $orig_event : $a->user),false)), + '$acl' => (($orig_event['event_xchan']) ? '' : populate_acl(((x($orig_event)) ? $orig_event : $perm_defaults))), '$submit' => t('Submit') )); diff --git a/mod/fbrowser.php b/mod/fbrowser.php index d10d8021b..19bd77914 100644 --- a/mod/fbrowser.php +++ b/mod/fbrowser.php @@ -5,7 +5,7 @@ * @author Fabio Comuni <fabrixxm@kirgroup.com> */ -require_once('include/Photo.php'); +require_once('include/photo/photo_driver.php'); /** * @param App $a @@ -45,7 +45,7 @@ function fbrowser_content($a){ $path[]=array($a->get_baseurl()."/fbrowser/image/".$a->argv[2]."/", $album); } - $r = q("SELECT `resource_id`, `id`, `filename`, type, min(`scale`) AS `hiq`,max(`scale`) AS `loq`, `desc` + $r = q("SELECT `resource_id`, `id`, `filename`, type, min(`scale`) AS `hiq`,max(`scale`) AS `loq`, `description` FROM `photo` WHERE `uid` = %d $sql_extra GROUP BY `resource_id` $sql_extra2", intval(local_user()) @@ -53,7 +53,8 @@ function fbrowser_content($a){ function files1($rr){ global $a; - $types = Photo::supportedTypes(); + $ph = photo_factory(''); + $types = $ph->supportedTypes(); $ext = $types[$rr['type']]; if($a->get_template_engine() === 'internal') { diff --git a/mod/feed.php b/mod/feed.php index a6adc620e..0f8296ed1 100644 --- a/mod/feed.php +++ b/mod/feed.php @@ -7,13 +7,14 @@ function feed_init(&$a) { $params = array(); - $params['begin'] = ((x($_REQUEST,'date_begin')) ? $_REQUEST['date_begin'] : '0000-00-00 00:00:00'); - $params['end'] = ((x($_REQUEST,'date_end')) ? $_REQUEST['date_end'] : ''); - $params['type'] = ((stristr(argv(0),'json')) ? 'json' : 'xml'); + $params['begin'] = ((x($_REQUEST,'date_begin')) ? $_REQUEST['date_begin'] : '0000-00-00 00:00:00'); + $params['end'] = ((x($_REQUEST,'date_end')) ? $_REQUEST['date_end'] : ''); + $params['type'] = ((stristr(argv(0),'json')) ? 'json' : 'xml'); + $params['pages'] = ((x($_REQUEST,'pages')) ? intval($_REQUEST['pages']) : 0); $channel = ''; if(argc() > 1) { - $r = q("select * from channel where channel_address = '%s' limit 1", + $r = q("select * from channel left join xchan on channel_hash = xchan_hash where channel_address = '%s' limit 1", dbesc(argv(1)) ); if(!($r && count($r))) @@ -21,11 +22,6 @@ function feed_init(&$a) { $channel = $r[0]; - // check site and channel permissions - - if(!($channel['channel_r_stream'] & PERMS_PUBLIC)) - killme(); - if((intval(get_config('system','block_public'))) && (! get_account_id())) killme(); diff --git a/mod/filer.php b/mod/filer.php index adc6245e1..3340fc999 100644 --- a/mod/filer.php +++ b/mod/filer.php @@ -19,6 +19,20 @@ function filer_content(&$a) { if($item_id && strlen($term)){ // file item store_item_tag(local_user(),$item_id,TERM_OBJ_POST,TERM_FILE,$term,''); + + // protect the entire conversation from periodic expiration + + $r = q("select parent from item where id = %d and uid = %d limit 1", + intval($item_id), + intval(local_user()) + ); + if($r) { + $x = q("update item set item_flags = ( item_flags | %d ) where id = %d and uid = %d limit 1", + intval(ITEM_RETAINED), + intval($r[0]['parent']), + intval(local_user()) + ); + } } else { $filetags = array(); diff --git a/mod/filestorage.php b/mod/filestorage.php new file mode 100644 index 000000000..ed7164070 --- /dev/null +++ b/mod/filestorage.php @@ -0,0 +1,183 @@ +<?php + +require_once('include/attach.php'); + +function filestorage_post(&$a) { + + $channel_id = ((x($_POST,'uid')) ? intval($_POST['uid']) : 0); + + if((! $channel_id) || (! local_user()) || ($channel_id != local_user())) { + notice( t('Permission denied.') . EOL); + return; + } + + $recurse = ((x($_POST,'recurse')) ? intval($_POST['recurse']) : 0); + $resource = ((x($_POST,'filehash')) ? notags($_POST['filehash']) : ''); + + if(! $resource) { + notice(t('Item not found.') . EOL); + 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']); + + attach_change_permissions($channel_id,$resource,$str_contact_allow,$str_group_allow,$str_contact_deny,$str_group_deny,$recurse = false); + +} + + + + + +function filestorage_content(&$a) { + + if(argc() > 1) + $which = argv(1); + else { + notice( t('Requested profile is not available.') . EOL ); + $a->error = 404; + return; + } + + $r = q("select * from channel where channel_address = '%s'", + dbesc($which) + ); + if($r) { + $channel = $r[0]; + $owner = intval($r[0]['channel_id']); + } + + $observer = $a->get_observer(); + $ob_hash = (($observer) ? $observer['xchan_hash'] : ''); + + $perms = get_all_perms($owner,$ob_hash); + + if(! $perms['view_storage']) { + notice( t('Permission denied.') . EOL); + return; + } + + // Since we have ACL'd files in the wild, but don't have ACL here yet, we + // need to return for anyone other than the owner, despite the perms check for now. + + $is_owner = (((local_user()) && ($owner == local_user())) ? true : false); + if(! $is_owner) { + info( t('Permission Denied.') . EOL ); + return; + } + + + if(argc() > 3 && argv(3) === 'delete') { + if(! $perms['write_storage']) { + notice( t('Permission denied.') . EOL); + return; + } + + $file = intval(argv(2)); + $r = q("select hash from attach where id = %d and uid = %d limit 1", + dbesc($file), + intval($owner) + ); + if(! $r) { + notice( t('File not found.') . EOL); + goaway(z_root() . '/filestorage/' . $which); + } + + attach_delete($owner,$r[0]['hash']); + + goaway(z_root() . '/filestorage/' . $which); + } + + + if(argc() > 3 && argv(3) === 'edit') { + require_once('include/acl_selectors.php'); + if(! $perms['write_storage']) { + notice( t('Permission denied.') . EOL); + return; + } + $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", + intval($file), + intval($owner) + ); + + $f = $r[0]; + + $channel = $a->get_channel(); + + $cloudpath = get_cloudpath($f) . (($f['flags'] & ATTACH_FLAG_DIR) ? '?f=&davguest=1' : ''); + + $aclselect_e = populate_acl($f); + $is_a_dir = (($f['flags'] & ATTACH_FLAG_DIR) ? true : false); + + $lockstate = (($f['allow_cid'] || $f['allow_gid'] || $f['deny_cid'] || $f['deny_gid']) ? 'lock' : 'unlock'); + + + $o = replace_macros(get_markup_template('attach_edit.tpl'), array( + '$header' => t('Edit file permissions'), + '$file' => $f, + '$cloudpath' => z_root() . '/' . $cloudpath, + '$uid' => $channel['channel_id'], + '$channelnick' => $channel['channel_address'], + '$permissions' => t('Permissions'), + '$aclselect' => $aclselect_e, + '$lockstate' => $lockstate, + '$permset' => t('Set/edit permissions'), + '$recurse' => t('Include all files and sub folders'), + '$backlink' => t('Return to file list'), + '$isadir' => $is_a_dir, + '$cpdesc' => t('Copy/paste this code to attach file to a post'), + '$cpldesc' => t('Copy/paste this URL to link file from a web page'), + '$submit' => t('Submit') + + )); + + return $o; + } + + $r = q("select * from attach where uid = %d order by edited desc", + intval($owner) + ); + + $files = null; + + if($r) { + $files = array(); + foreach($r as $rr) { + $files[$rr['id']][] = array( + 'id' => $rr['id'], + 'download' => $rr['hash'], + 'title' => $rr['filename'], + 'size' => $rr['filesize'], + 'rev' => $rr['revision'], + 'dir' => (($rr['flags'] & ATTACH_FLAG_DIR) ? true : false) + ); + } + } + + $limit = service_class_fetch ($owner,'attach_upload_limit'); + $r = q("select sum(filesize) as total from attach where aid = %d ", + intval($channel['channel_account_id']) + ); + $used = $r[0]['total']; + + $url = z_root() . "/filestorage/" . $which; + return $o . replace_macros(get_markup_template("filestorage.tpl"), array( + '$baseurl' => $url, + '$download' => t('Download'), + '$files' => $files, + '$channel' => $which, + '$edit' => t('Edit'), + '$delete' => t('Delete'), + '$used' => $used, + '$usedlabel' => t('Used: '), + '$directory' => t('[directory]'), + '$limit' => $limit, + '$limitlabel' => t('Limit: '), + )); + +} diff --git a/mod/follow.php b/mod/follow.php index c07c210f6..663fb7536 100644 --- a/mod/follow.php +++ b/mod/follow.php @@ -6,24 +6,37 @@ require_once('include/follow.php'); function follow_init(&$a) { if(! local_user()) { - notice( t('Permission denied.') . EOL); return; } $uid = local_user(); $url = notags(trim($_REQUEST['url'])); $return_url = $_SESSION['return_url']; + $confirm = intval($_REQUEST['confirm']); - $result = new_contact($uid,$url,$a->get_channel(),true); - + $result = new_contact($uid,$url,$a->get_channel(),true,$confirm); + if($result['success'] == false) { if($result['message']) notice($result['message']); goaway($return_url); } - info( t('Channel added') . EOL); + info( t('Channel added.') . EOL); + + // If we can view their stream, pull in some posts + + if($result['abook']['abook_their_perms'] & PERMS_R_STREAM) + proc_run('php','include/onepoll.php',$result['abook']['abook_id']); + - goaway(z_root() . '/connections/' . $result['abook']['abook_id']); + goaway(z_root() . '/connedit/' . $result['abook']['abook_id'] . '?f=&follow=1'); } + +function follow_content(&$a) { + + if(! local_user()) { + return login(); + } +}
\ No newline at end of file diff --git a/mod/fsuggest.php b/mod/fsuggest.php index 9ef8f4c55..8b6f077d3 100644 --- a/mod/fsuggest.php +++ b/mod/fsuggest.php @@ -100,8 +100,9 @@ function fsuggest_content(&$a) { $o .= '<form id="fsuggest-form" action="fsuggest/' . $contact_id . '" method="post" >'; - $o .= contact_selector('suggest','suggest-select', false, - array('size' => 4, 'exclude' => $contact_id, 'networks' => 'DFRN_ONLY', 'single' => true)); +// FIXME contact_selector deprecated, removed +// $o .= contact_selector('suggest','suggest-select', false, +// array('size' => 4, 'exclude' => $contact_id, 'networks' => 'DFRN_ONLY', 'single' => true)); $o .= '<div id="fsuggest-submit-wrapper"><input id="fsuggest-submit" type="submit" name="submit" value="' . t('Submit') . '" /></div>'; diff --git a/mod/group.php b/mod/group.php index 778ecbded..15e4ff2a3 100644 --- a/mod/group.php +++ b/mod/group.php @@ -2,12 +2,6 @@ require_once('include/group.php'); -function group_aside(&$a) { - if(local_user()) { - $a->set_widget('groups_edit',group_side('connections','group',false,(($a->argc > 1) ? intval($a->argv[1]) : 0))); - } -} - function group_post(&$a) { @@ -20,7 +14,8 @@ function group_post(&$a) { check_form_security_token_redirectOnErr('/group/new', 'group_edit'); $name = notags(trim($_POST['groupname'])); - $r = group_add(local_user(),$name); + $public = intval($_POST['public']); + $r = group_add(local_user(),$name,$public); if($r) { info( t('Collection created.') . EOL ); $r = group_byname(local_user(),$name); @@ -35,7 +30,7 @@ function group_post(&$a) { if((argc() == 2) && (intval(argv(1)))) { check_form_security_token_redirectOnErr('/group', 'group_edit'); - $r = q("SELECT * FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1", + $r = q("SELECT * FROM `groups` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval(argv(1)), intval(local_user()) ); @@ -46,14 +41,17 @@ function group_post(&$a) { } $group = $r[0]; $groupname = notags(trim($_POST['groupname'])); - if((strlen($groupname)) && ($groupname != $group['name'])) { - $r = q("UPDATE `group` SET `name` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1", + $public = intval($_POST['public']); + + if((strlen($groupname)) && (($groupname != $group['name']) || ($public != $group['visible']))) { + $r = q("UPDATE `groups` SET `name` = '%s', visible = %d WHERE `uid` = %d AND `id` = %d LIMIT 1", dbesc($groupname), + intval($public), intval(local_user()), intval($group['id']) ); if($r) - info( t('Collection name changed.') . EOL ); + info( t('Collection updated.') . EOL ); } goaway(z_root() . '/group/' . argv(1) . '/' . argv(2)); @@ -85,9 +83,10 @@ function group_content(&$a) { if((argc() == 2) && (argv(1) === 'new')) { return replace_macros($tpl, $context + array( - '$title' => t('Create a collection of connections.'), + '$title' => t('Create a collection of channels.'), '$gname' => array('groupname',t('Collection Name: '), '', ''), '$gid' => 'new', + '$public' => array('public',t('Members are visible to other channels'), false, ''), '$form_security_token' => get_form_security_token("group_edit"), )); @@ -98,7 +97,7 @@ function group_content(&$a) { check_form_security_token_redirectOnErr('/group', 'group_drop', 't'); if(intval(argv(2))) { - $r = q("SELECT `name` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1", + $r = q("SELECT `name` FROM `groups` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval(argv(2)), intval(local_user()) ); @@ -118,10 +117,10 @@ function group_content(&$a) { check_form_security_token_ForbiddenOnErr('group_member_change', 't'); - $r = q("SELECT abook_xchan from abook where abook_xchan = '%s' and abook_channel = %d and not (abook_flags & %d) and not (abook_flags & %d) and not (abook_flags & %d) limit 1", + $r = q("SELECT abook_xchan from abook where abook_xchan = '%s' and abook_channel = %d and not (xchan_flags & %d) and not (abook_flags & %d) and not (abook_flags & %d) limit 1", dbesc(argv(2)), intval(local_user()), - intval(ABOOK_FLAG_SELF), + intval(XCHAN_FLAGS_DELETED), intval(ABOOK_FLAG_BLOCKED), intval(ABOOK_FLAG_PENDING) ); @@ -133,7 +132,7 @@ function group_content(&$a) { if((argc() > 1) && (intval(argv(1)))) { require_once('include/acl_selectors.php'); - $r = q("SELECT * FROM `group` WHERE `id` = %d AND `uid` = %d AND `deleted` = 0 LIMIT 1", + $r = q("SELECT * FROM `groups` WHERE `id` = %d AND `uid` = %d AND `deleted` = 0 LIMIT 1", intval(argv(1)), intval(local_user()) ); @@ -143,12 +142,14 @@ function group_content(&$a) { } $group = $r[0]; + $members = group_get_members($group['id']); $preselected = array(); if(count($members)) { foreach($members as $member) - $preselected[] = $member['xchan_hash']; + if(! in_array($member['xchan_hash'],$preselected)) + $preselected[] = $member['xchan_hash']; } if($change) { @@ -182,6 +183,7 @@ function group_content(&$a) { '$gname' => array('groupname',t('Collection Name: '),$group['name'], ''), '$gid' => $group['id'], '$drop' => $drop_txt, + '$public' => array('public',t('Members are visible to other channels'), $group['visible'], ''), '$form_security_token' => get_form_security_token('group_edit'), ); @@ -208,10 +210,10 @@ function group_content(&$a) { group_rmv_member(local_user(),$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) and not (abook_flags & %d) and not (abook_flags & %d) order by xchan_name asc", + $r = q("SELECT abook.*, xchan.* FROM `abook` left join xchan on abook_xchan = xchan_hash WHERE `abook_channel` = %d AND not (abook_flags & %d) and not (xchan_flags & %d) and not (abook_flags & %d) order by xchan_name asc", intval(local_user()), intval(ABOOK_FLAG_BLOCKED), - intval(ABOOK_FLAG_SELF), + intval(XCHAN_FLAGS_DELETED), intval(ABOOK_FLAG_PENDING) ); diff --git a/mod/hcard.php b/mod/hcard.php deleted file mode 100644 index ab2fa88a1..000000000 --- a/mod/hcard.php +++ /dev/null @@ -1,53 +0,0 @@ -<?php - -function hcard_init(&$a) { - - $blocked = (((get_config('system','block_public')) && (! local_user()) && (! remote_user())) ? true : false); - - if($a->argc > 1) - $which = $a->argv[1]; - else { - notice( t('No profile') . EOL ); - $a->error = 404; - return; - } - - $profile = 0; - if((local_user()) && ($a->argc > 2) && ($a->argv[2] === 'view')) { - $which = $a->user['nickname']; - $profile = $a->argv[1]; - } - - profile_load($a,$which,$profile); - - if((x($a->profile,'page-flags')) && ($a->profile['page-flags'] == PAGE_COMMUNITY)) { - $a->page['htmlhead'] .= '<meta name="friendica.community" content="true" />'; - } - if(x($a->profile,'openidserver')) - $a->page['htmlhead'] .= '<link rel="openid.server" href="' . $a->profile['openidserver'] . '" />' . "\r\n"; - if(x($a->profile,'openid')) { - $delegate = ((strstr($a->profile['openid'],'://')) ? $a->profile['openid'] : 'http://' . $a->profile['openid']); - $a->page['htmlhead'] .= '<link rel="openid.delegate" href="' . $delegate . '" />' . "\r\n"; - } - - if(! $blocked) { - $keywords = ((x($a->profile,'keywords')) ? $a->profile['keywords'] : ''); - $keywords = str_replace(array(',',' ',',,'),array(' ',',',','),$keywords); - if(strlen($keywords)) - $a->page['htmlhead'] .= '<meta name="keywords" content="' . $keywords . '" />' . "\r\n" ; - } - - $a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $a->get_baseurl() . '/dfrn_poll/' . $which .'" />' . "\r\n" ; - $uri = urlencode('acct:' . $a->profile['nickname'] . '@' . $a->get_hostname() . (($a->path) ? '/' . $a->path : '')); - $a->page['htmlhead'] .= '<link rel="lrdd" type="application/xrd+xml" href="' . $a->get_baseurl() . '/xrd/?uri=' . $uri . '" />' . "\r\n"; - header('Link: <' . $a->get_baseurl() . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false); - - $dfrn_pages = array('request', 'confirm', 'notify', 'poll'); - foreach($dfrn_pages as $dfrn) - $a->page['htmlhead'] .= "<link rel=\"dfrn-{$dfrn}\" href=\"".$a->get_baseurl()."/dfrn_{$dfrn}/{$which}\" />\r\n"; - -} - -function hcard_aside(&$a) { - profile_create_sidebar($a); -} diff --git a/mod/help.php b/mod/help.php index af05bd47c..81ecd6ba9 100644 --- a/mod/help.php +++ b/mod/help.php @@ -1,8 +1,19 @@ <?php +/** + * You can create local site resources in doc/Site.md and either link to doc/Home.md for the standard resources + * or use our include mechanism to include it on your local page. + * + * #include doc/Home.md; + * + * The syntax is somewhat strict. + * + */ + + if(! function_exists('load_doc_file')) { function load_doc_file($s) { - global $lang; + $lang = get_app()->language; if(! isset($lang)) $lang = 'en'; $b = basename($s); @@ -21,16 +32,36 @@ function help_content(&$a) { global $lang; + $doctype = 'markdown'; + require_once('library/markdown.php'); $text = ''; - if($a->argc > 1) { + if(argc() > 1) { $text = load_doc_file('doc/' . $a->argv[1] . '.md'); - $a->page['title'] = t('Help:') . ' ' . str_replace('-',' ',notags($a->argv[1])); + $a->page['title'] = t('Help:') . ' ' . ucwords(str_replace('-',' ',notags(argv(1)))); + } + if(! $text) { + $text = load_doc_file('doc/' . $a->argv[1] . '.bb'); + if($text) + $doctype = 'bbcode'; + $a->page['title'] = t('Help:') . ' ' . ucwords(str_replace('_',' ',notags(argv(1)))); + } + if(! $text) { + $text = load_doc_file('doc/' . $a->argv[1] . '.html'); + if($text) + $doctype = 'html'; + $a->page['title'] = t('Help:') . ' ' . ucwords(str_replace('-',' ',notags(argv(1)))); + } + + if(! $text) { + $text = load_doc_file('doc/Site.md'); + $a->page['title'] = t('Help'); } if(! $text) { - $text = load_doc_file('doc/Home.md'); + $doctype = 'bbcode'; + $text = load_doc_file('doc/main.bb'); $a->page['title'] = t('Help'); } @@ -41,7 +72,29 @@ function help_content(&$a) { '$message' => t('Page not found.' ) )); } - - return Markdown($text); + + $text = preg_replace_callback("/#include (.*?)\;/ism", 'preg_callback_help_include', $text); + + if($doctype === 'html') + $content = $text; + if($doctype === 'markdown') + $content = Markdown($text); + if($doctype === 'bbcode') { + require_once('include/bbcode.php'); + $content = bbcode($text); + } + + return replace_macros(get_markup_template("help.tpl"), array( + '$content' => $content + )); } + + +function preg_callback_help_include($matches) { + + if($matches[1]) + return str_replace($matches[0],load_doc_file($matches[1]),$matches[0]); + +} + diff --git a/mod/home.php b/mod/home.php index 1bb0148d2..05626dcb5 100644 --- a/mod/home.php +++ b/mod/home.php @@ -1,6 +1,9 @@ <?php -if(! function_exists('home_init')) { +require_once('include/items.php'); +require_once('include/conversation.php'); + + function home_init(&$a) { $ret = array(); @@ -8,35 +11,86 @@ function home_init(&$a) { $channel = $a->get_channel(); - if(local_user() && $channel && $channel['xchan_url']) - goaway( $channel['xchan_url']); + if(local_user() && $channel && $channel['xchan_url']) { + $dest = get_pconfig(local_user(),'system','startpage'); + if(! $dest) + $dest = z_root() . '/network'; + + goaway($dest); + } if(get_account_id()) { - goaway('new_channel'); + goaway(z_root() . '/new_channel'); } -}} +} -if(! function_exists('home_content')) { function home_content(&$a) { $o = ''; if(x($_SESSION,'theme')) unset($_SESSION['theme']); - if(x($_SESSION,'mobile-theme')) - unset($_SESSION['mobile-theme']); + if(x($_SESSION,'mobile_theme')) + unset($_SESSION['mobile_theme']); - $o .= '<h1>' . ((x($a->config,'sitename')) ? sprintf( t("Welcome to %s") ,$a->config['sitename']) : "" ) . '</h1>'; - if(file_exists('home.html')) - $o .= file_get_contents('home.html'); + $channel_address = get_config("system", "site_channel" ); + if ($channel_address){ - $o .= login(($a->config['system']['register_policy'] == REGISTER_CLOSED) ? 0 : 1); - - call_hooks("home_content",$o); - - return $o; + // We can do better, but until we figure out auto-linkification, let's keep things simple + + $page_id = 'home'; + + $u = q("select channel_id from channel where channel_address = '%s' limit 1", + dbesc($channel_address) + ); + + if(! $u) { + notice( t('Channel not found.') . EOL); + return; + } + + $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 limit 1", + intval($u[0]['channel_id']), + dbesc($page_id), + intval(ITEM_WEBPAGE) + ); + if(! $r) { + notice( t('Item not found.') . EOL); + return; + } + + xchan_query($r); + $r = fetch_post_tags($r,true); + $a->profile = array('profile_uid' => $u[0]['channel_id']); + $o .= prepare_page($r[0]); + return $o; + } + + if(get_config('system','projecthome')) { + $o .= file_get_contents('assets/home.html'); + $a->page['template'] = 'full'; + return $o; + } + + if(file_exists('home.html')) { + $o .= file_get_contents('home.html'); + } + else { + + // If there's no site channel or home contents configured, fallback to the old behaviour + + $sitename = get_config('system','sitename'); + if($sitename) + $o .= '<h1>' . sprintf( t("Welcome to %s") ,$sitename) . '</h1>'; + if (! $a->config['system']['no_login_on_homepage']) + $o .= login(($a->config['system']['register_policy'] == REGISTER_CLOSED) ? 0 : 1); + } -}} + call_hooks('home_content',$o); + return $o; +} diff --git a/mod/hostxrd.php b/mod/hostxrd.php index 0a66dcc84..ef86f2dd9 100644 --- a/mod/hostxrd.php +++ b/mod/hostxrd.php @@ -1,28 +1,16 @@ <?php -require_once('include/crypto.php'); - function hostxrd_init(&$a) { header('Access-Control-Allow-Origin: *'); header("Content-type: text/xml"); - $pubkey = get_config('system','site_pubkey'); - - if(! $pubkey) { - $res = new_keypair(1024); - - set_config('system','site_prvkey', $res['prvkey']); - set_config('system','site_pubkey', $res['pubkey']); - } $tpl = get_markup_template('xrd_host.tpl'); - echo replace_macros($tpl, array( + $x = replace_macros(get_markup_template('xrd_host.tpl'), array( '$zhost' => $a->get_hostname(), - '$zroot' => z_root(), - '$domain' => z_path(), - '$zot_post' => z_root() . '/post', - '$bigkey' => salmon_key(get_config('system','site_pubkey')), + '$zroot' => z_root() )); - session_write_close(); - exit(); - + $arr = array('xrd' => $x); + call_hooks('hostxrd',$arr); + echo $arr['xrd']; + killme(); } diff --git a/mod/import.php b/mod/import.php index f35ca149b..5b3b53156 100644 --- a/mod/import.php +++ b/mod/import.php @@ -4,24 +4,29 @@ // connection to original server. require_once('include/Contact.php'); - +require_once('include/zot.php'); +require_once('include/identity.php'); function import_post(&$a) { + if(! get_account_id()) { + return; + } $data = null; $seize = ((x($_REQUEST,'make_primary')) ? intval($_REQUEST['make_primary']) : 0); - $src = $_FILES['userfile']['tmp_name']; - $filename = basename($_FILES['userfile']['name']); - $filesize = intval($_FILES['userfile']['size']); - $filetype = $_FILES['userfile']['type']; + $src = $_FILES['filename']['tmp_name']; + $filename = basename($_FILES['filename']['name']); + $filesize = intval($_FILES['filename']['size']); + $filetype = $_FILES['filename']['type']; if($src) { if($filesize) { $data = @file_get_contents($src); } + unlink($src); } if(! $src) { @@ -39,7 +44,7 @@ function import_post(&$a) { $servername = substr($old_address,strpos($old_address,'@')+1); $scheme = 'https://'; - $api_path = '/api/export/basic?f=&channel=' . $channelname; + $api_path = '/api/red/channel/export/basic?f=&channel=' . $channelname; $binary = false; $redirects = 0; $opts = array('http_auth' => $email . ':' . $password); @@ -60,6 +65,7 @@ function import_post(&$a) { return; } + $data = json_decode($data,true); // logger('import: data: ' . print_r($data,true)); @@ -113,9 +119,11 @@ function import_post(&$a) { // reset $channel = $r[0]; + set_default_login_identity(get_account_id(),$channel['channel_id'],false); + if($data['photo']) { - require_once('include/Photo.php'); - import_channel_photo(base64url_decode($data['photo']['data']),$data['photo']['type'],get_account_id,$channel['channel_id']); + 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']; @@ -198,10 +206,37 @@ function import_post(&$a) { // import xchans and contact photos + if($seize) { + + // replace our existing xchan if we're seizing control + + $r = q("delete from xchan where xchan_hash = '%s' limit 1", + 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']), + 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()) + ); + } $xchans = $data['xchan']; if($xchans) { foreach($xchans as $xchan) { + $r = q("select xchan_hash from xchan where xchan_hash = '%s' limit 1", dbesc($xchan['xchan_hash']) ); @@ -217,7 +252,7 @@ function import_post(&$a) { . "')" ); - require_once("Photo.php"); + require_once('include/photo/photo_driver.php'); $photos = import_profile_photo($xchan['xchan_photo_l'],$xchan['xchan_hash']); $r = q("update xchan set xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s' where xchan_hash = '%s' limit 1", @@ -250,6 +285,63 @@ function import_post(&$a) { } } + + $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 group (`" + . 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']; + } + } + } + + $group_members = $data['group_member']; + if($groups_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)) + . "')" ); + } + } + // FIXME - ensure we have a self entry if somebody is trying to pull a fast one if($seize) { @@ -257,15 +349,28 @@ function import_post(&$a) { } + // This will indirectly perform a refresh_all *and* update the directory + + proc_run('php', 'include/directory.php', $channel['channel_id']); + // send out refresh requests notice( t('Import completed.') . EOL); + change_channel($channel['channel_id']); + + goaway(z_root() . '/network' ); + + } function import_content(&$a) { + if(! get_account_id()) { + notice( t('You must be logged in to use this feature.')); + return ''; + } $o = replace_macros(get_markup_template('channel_import.tpl'),array( '$title' => t('Import Channel'), @@ -284,4 +389,4 @@ function import_content(&$a) { return $o; -}
\ No newline at end of file +} diff --git a/mod/intro.php b/mod/intro.php deleted file mode 100644 index 5b660485a..000000000 --- a/mod/intro.php +++ /dev/null @@ -1,110 +0,0 @@ -<?php - -function intro_post(&$a) { - if(! local_user()) - return; - if(! intval($_REQUEST['contact_id'])) - return; - - $approved = false; - $flags = 0; - if($_REQUEST['submit'] == t('Approve')) { - $approved = true; - } - elseif($_REQUEST['submit'] == t('Block')) { - $flags = ABOOK_FLAG_BLOCKED; - } - elseif($_REQUEST['submit'] == t('Ignore')) { - $flags = ABOOK_FLAG_IGNORED; - } - if(intval($_REQUEST['hidden'])) - $flags |= ABOOK_FLAG_HIDDEN; - - $r = q("update abook set abook_flags = %d where abook_channel = %d and abook_id = %d limit 1", - intval($flags), - intval(local_user()), - intval($_REQUEST['contact_id']) - ); - if($r) - info( t('Connection updated.') . EOL); - else - notice( t('Connection update failed.') . EOL); - - if($approved) - goaway(z_root() . '/connections/' . $_REQUEST['contact_id']); - - -} - -function intro_aside(&$a) { - require_once('include/contact_widgets.php'); - - $a->set_widget('follow', follow_widget()); - -} - - -function intro_content(&$a) { - - if( ! local_user()) { - notice( t('Permission denied.') . EOL); - return; - } - - - $o = replace_macros(get_markup_template('intros_header.tpl'),array( - '$title' => t('Introductions and Connection Requests') - )); - - $r = q("select count(abook_id) as total from abook where abook_channel = %d and (abook_flags & %d) and not (abook_flags & %d) ", - intval(local_user()), - intval(ABOOK_FLAG_PENDING), - intval(ABOOK_FLAG_SELF) - ); - if($r) { - $a->set_pager_total($r[0]['total']); - if(! intval($r[0]['total'])) { - notice( t('No pending introductions.') . EOL); - return $o; - } - } - else { - notice( t('System error. Please try again later.') . EOL); - return $o; - } - - $r = q("select abook.*, xchan.* from abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d and (abook_flags & %d) and not (abook_flags & %d) LIMIT %d, %d", - intval(local_user()), - intval(ABOOK_FLAG_PENDING), - intval(ABOOK_FLAG_SELF), - intval($a->pager['start']), - intval($a->pager['itemspage']) - ); - - if($r) { - - $tpl = get_markup_template("intros.tpl"); - - foreach($r as $rr) { - $o .= replace_macros($tpl,array( - '$uid' => local_user(), - - '$contact_id' => $rr['abook_id'], - '$photo' => ((x($rr,'xchan_photo_l')) ? $rr['xchan_photo_l'] : "images/person-175.jpg"), - '$fullname' => $rr['xchan_name'], - '$hidden' => array('hidden', t('Hide this contact from others'), ($rr['abook_flags'] & ABOOK_FLAG_HIDDEN), ''), - '$activity' => array('activity', t('Post a new friend activity'), (intval(get_pconfig(local_user(),'system','post_newfriend')) ? '1' : 0), t('if applicable')), - '$url' => zid($rr['xchan_url']), - '$approve' => t('Approve'), - '$block' => t('Block'), - '$ignore' => t('Ignore'), - '$discard' => t('Discard') - - )); - } - } - - $o .= paginate($a); - return $o; - -}
\ No newline at end of file diff --git a/mod/invite.php b/mod/invite.php index 336e20164..9e37d1e6d 100644 --- a/mod/invite.php +++ b/mod/invite.php @@ -42,6 +42,8 @@ function invite_post(&$a) { foreach($recips as $recip) { $recip = trim($recip); + if(! $recip) + continue; if(! valid_email($recip)) { notice( sprintf( t('%s : Not a valid email address.'), $recip) . EOL); @@ -68,9 +70,12 @@ function invite_post(&$a) { else $nmessage = $message; - $res = mail($recip, sprintf( t('Please join us on Friendica'), $a->config['sitename']), + $account = $a->get_account(); + + + $res = mail($recip, sprintf( t('Please join us on Red'), $a->config['sitename']), $nmessage, - "From: " . $a->user['email'] . "\n" + "From: " . $account['account_email'] . "\n" . 'Content-type: text/plain; charset=UTF-8' . "\n" . 'Content-transfer-encoding: 8bit' ); @@ -112,29 +117,42 @@ function invite_content(&$a) { } } - $dirloc = get_config('system','directory_submit_url'); - if(strlen($dirloc)) { - if($a->config['system']['register_policy'] == REGISTER_CLOSED) - $linktxt = sprintf( t('Visit %s for a list of public sites that you can join. Friendica members on other sites can all connect with each other, as well as with members of many other social networks.'), dirname($dirloc) . '/siteinfo'); - elseif($a->config['system']['register_policy'] != REGISTER_CLOSED) - $linktxt = sprintf( t('To accept this invitation, please visit and register at %s or any other public Friendica website.'), $a->get_baseurl()) - . "\r\n" . "\r\n" . sprintf( t('Friendica sites all inter-connect to create a huge privacy-enhanced social web that is owned and controlled by its members. They can also connect with many traditional social networks. See %s for a list of alternate Friendica sites you can join.'),dirname($dirloc) . '/siteinfo'); - } - else { - $o = t('Our apologies. This system is not currently configured to connect with other public sites or invite members.'); +// $dirloc = get_config('system','directory_submit_url'); +// if(strlen($dirloc)) { +// if($a->config['system']['register_policy'] == REGISTER_CLOSED) +// $linktxt = sprintf( t('Visit %s for a list of public sites that you can join. Friendica members on other sites can all connect with each other, as well as with members of many other social networks.'), dirname($dirloc) . '/siteinfo'); +// elseif($a->config['system']['register_policy'] != REGISTER_CLOSED) +// $linktxt = sprintf( t('To accept this invitation, please visit and register at %s or any other public Friendica website.'), $a->get_baseurl()) +// . "\r\n" . "\r\n" . sprintf( t('Friendica sites all inter-connect to create a huge privacy-enhanced social web that is owned and controlled by its members. They can also connect with many traditional social networks. See %s for a list of alternate Friendica sites you can join.'),dirname($dirloc) . '/siteinfo'); +// } +// else { +// $o = t('Our apologies. This system is not currently configured to connect with other public sites or invite members.'); +// return $o; +// } + + $ob = $a->get_observer(); + if(! $ob) return $o; - } + + $channel = $a->get_channel(); $o = replace_macros($tpl, array( '$form_security_token' => get_form_security_token("send_invite"), '$invite' => t('Send invitations'), '$addr_text' => t('Enter email addresses, one per line:'), '$msg_text' => t('Your message:'), - '$default_message' => t('You are cordially invited to join me and other close friends on Friendica - and help us to create a better social web.') . "\r\n" . "\r\n" + '$default_message' => t('You are cordially invited to join me and some other close friends on the Red Matrix - a revolutionary new decentralised communication and information tool.') . "\r\n" . "\r\n" . $linktxt - . "\r\n" . "\r\n" . (($invonly) ? t('You will need to supply this invitation code: $invite_code') . "\r\n" . "\r\n" : '') .t('Once you have registered, please connect with me via my profile page at:') - . "\r\n" . "\r\n" . $a->get_baseurl() . '/channel/' . $a->user['nickname'] - . "\r\n" . "\r\n" . t('For more information about the Friendica project and why we feel it is important, please visit http://friendica.com') . "\r\n" . "\r\n" , + . (($invonly) ? "\r\n" . "\r\n" . t('You will need to supply this invitation code: $invite_code') . "\r\n" . "\r\n" : '') + . t('Please visit my channel at') + . "\r\n" . "\r\n" + . z_root() . "/channel/" . $channel['channel_address'] + . "\r\n" . "\r\n" + . t('Once you have registered (on ANY Red Matrix site - they are all inter-connected), please connect with my Red Matrix channel address:') + . "\r\n" . "\r\n" . $ob['xchan_addr'] + . "\r\n" . "\r\n" . t('Click the [Register] link on the following page to join.') . "\r\n" . "\r\n" . z_root() + + . "\r\n" . "\r\n" . t('For more information about the Red Matrix Project and why it has the potential to change the internet as we know it, please visit http://getzot.com') . "\r\n" . "\r\n" , '$submit' => t('Submit') )); diff --git a/mod/item.php b/mod/item.php index 8298d3dc0..164b345f0 100644 --- a/mod/item.php +++ b/mod/item.php @@ -33,6 +33,8 @@ function item_post(&$a) { $uid = local_user(); + $channel = null; + if(x($_REQUEST,'dropitems')) { require_once('include/items.php'); $arr_drop = explode(',',$_REQUEST['dropitems']); @@ -44,7 +46,7 @@ function item_post(&$a) { call_hooks('post_local_start', $_REQUEST); - logger('postvars ' . print_r($_REQUEST,true), LOGGER_DATA); +// logger('postvars ' . print_r($_REQUEST,true), LOGGER_DATA); $api_source = ((x($_REQUEST,'api_source') && $_REQUEST['api_source']) ? true : false); @@ -58,29 +60,54 @@ function item_post(&$a) { // If you are unsure, it is prudent (and important) to leave it unset. $origin = (($api_source && array_key_exists('origin',$_REQUEST)) ? intval($_REQUEST['origin']) : 1); - $owner_hash = null; + // To represent message-ids on other networks - this will create an item_id record + + $namespace = (($api_source && array_key_exists('namespace',$_REQUEST)) ? strip_tags($_REQUEST['namespace']) : ''); + $remote_id = (($api_source && array_key_exists('remote_id',$_REQUEST)) ? strip_tags($_REQUEST['remote_id']) : ''); - $profile_uid = ((x($_REQUEST,'profile_uid')) ? intval($_REQUEST['profile_uid']) : 0); - $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'] : ''); - $preview = ((x($_REQUEST,'preview')) ? intval($_REQUEST['preview']) : 0); - $categories = ((x($_REQUEST,'category')) ? escape_tags($_REQUEST['category']) : ''); - $webpage = ((x($_REQUEST,'webpage')) ? intval($_REQUEST['webpage']) : 0); - $pagetitle = ((x($_REQUEST,'pagetitle')) ? escape_tags($_REQUEST['pagetitle']): ''); + $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()); + $profile_uid = ((x($_REQUEST,'profile_uid')) ? intval($_REQUEST['profile_uid']) : 0); + $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'] : ''); + $preview = ((x($_REQUEST,'preview')) ? intval($_REQUEST['preview']) : 0); + $categories = ((x($_REQUEST,'category')) ? escape_tags($_REQUEST['category']) : ''); + $webpage = ((x($_REQUEST,'webpage')) ? intval($_REQUEST['webpage']) : 0); + $pagetitle = ((x($_REQUEST,'pagetitle')) ? escape_tags($_REQUEST['pagetitle']) : ''); + $layout_mid = ((x($_REQUEST,'layout_mid')) ? escape_tags($_REQUEST['layout_mid']): ''); + $plink = ((x($_REQUEST,'permalink')) ? escape_tags($_REQUEST['permalink']) : ''); + + + /* + Check service class limits + */ + if (local_user() && !(x($_REQUEST,'parent')) && !(x($_REQUEST,'post_id'))) { + $ret=item_check_service_class(local_user(),x($_REQUEST,'webpage')); + if (!$ret['success']) { + notice( t($ret['message']) . EOL) ; + if(x($_REQUEST,'return')) + goaway($a->get_baseurl() . "/" . $return_path ); + killme(); + } + } if($pagetitle) { require_once('library/urlify/URLify.php'); $pagetitle = strtolower(URLify::transliterate($pagetitle)); } + + $item_flags = $item_restrict = 0; + /** * Is this a reply to something? */ $parent = ((x($_REQUEST,'parent')) ? intval($_REQUEST['parent']) : 0); - $parent_uri = ((x($_REQUEST,'parent_uri')) ? trim($_REQUEST['parent_uri']) : ''); + $parent_mid = ((x($_REQUEST,'parent_mid')) ? trim($_REQUEST['parent_mid']) : ''); $parent_item = null; $parent_contact = null; @@ -88,7 +115,7 @@ function item_post(&$a) { $parid = 0; $r = false; - if($parent || $parent_uri) { + if($parent || $parent_mid) { if(! x($_REQUEST,'type')) $_REQUEST['type'] = 'net-comment'; @@ -98,17 +125,17 @@ function item_post(&$a) { intval($parent) ); } - elseif($parent_uri && local_user()) { + elseif($parent_mid && local_user()) { // This is coming from an API source, and we are logged in - $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", - dbesc($parent_uri), + $r = q("SELECT * FROM `item` WHERE `mid` = '%s' AND `uid` = %d LIMIT 1", + dbesc($parent_mid), intval(local_user()) ); } // if this isn't the real parent of the conversation, find it if($r !== false && count($r)) { $parid = $r[0]['parent']; - $parent_uri = $r[0]['uri']; + $parent_mid = $r[0]['mid']; if($r[0]['id'] != $r[0]['parent']) { $r = q("SELECT * FROM `item` WHERE `id` = `parent` AND `parent` = %d LIMIT 1", intval($parid) @@ -122,32 +149,46 @@ function item_post(&$a) { goaway($a->get_baseurl() . "/" . $return_path ); killme(); } + + // can_comment_on_post() needs info from the following xchan_query + xchan_query($r); + $parent_item = $r[0]; $parent = $r[0]['id']; // multi-level threading - preserve the info but re-parent to our single level threading - //if(($parid) && ($parid != $parent)) - $thr_parent = $parent_uri; - if($parent_item['contact-id'] && $uid) { - $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", - intval($parent_item['contact-id']), - intval($uid) - ); - if(count($r)) - $parent_contact = $r[0]; - } + $thr_parent = $parent_mid; + + } - if($parent) logger('mod_item: item_post parent=' . $parent); $observer = $a->get_observer(); - if(! perm_is_allowed($profile_uid,$observer['xchan_hash'],(($parent) ? 'post_comments' : 'post_wall'))) { - notice( t('Permission denied.') . EOL) ; - if(x($_REQUEST,'return')) - goaway($a->get_baseurl() . "/" . $return_path ); - killme(); + + 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)) + $can_comment = perm_is_allowed($profile_uid,$observer['xchan_hash'],'post_comments'); + else + $can_comment = can_comment_on_post($observer['xchan_hash'],$parent_item); + + if(! $can_comment) { + notice( t('Permission denied.') . EOL) ; + if(x($_REQUEST,'return')) + goaway($a->get_baseurl() . "/" . $return_path ); + killme(); + } + } + else { + if(! perm_is_allowed($profile_uid,$observer['xchan_hash'],'post_wall')) { + notice( t('Permission denied.') . EOL) ; + if(x($_REQUEST,'return')) + goaway($a->get_baseurl() . "/" . $return_path ); + killme(); + } } @@ -155,6 +196,16 @@ function item_post(&$a) { $orig_post = null; + if($namespace && $remote_id) { + // It wasn't an internally generated post - see if we've got an item matching this remote service id + $i = q("select iid from item_id where service = '%s' and sid = '%s' limit 1", + dbesc($namespace), + dbesc($remote_id) + ); + if($i) + $post_id = $i[0]['iid']; + } + if($post_id) { $i = q("SELECT * FROM `item` WHERE `uid` = %d AND `id` = %d LIMIT 1", intval($profile_uid), @@ -165,20 +216,22 @@ function item_post(&$a) { $orig_post = $i[0]; } - $channel = null; - if(local_user() && local_user() == $profile_uid) { - $channel = $a->get_channel(); - } - else { - $r = q("SELECT channel.*, account.* FROM channel left join account on channel.channel_account_id = account.account_id - where channel.channel_id = %d LIMIT 1", - intval($profile_uid) - ); - if(count($r)) - $channel = $r[0]; + if(! $channel) { + if(local_user() && local_user() == $profile_uid) { + $channel = $a->get_channel(); + } + else { + // posting as yourself but not necessarily to a channel you control + $r = q("select * from channel left join account on channel_account_id = account_id where channel_id = %d LIMIT 1", + intval($profile_uid) + ); + if($r) + $channel = $r[0]; + } } + if(! $channel) { logger("mod_item: no channel."); if(x($_REQUEST,'return')) @@ -200,21 +253,37 @@ function item_post(&$a) { goaway($a->get_baseurl() . "/" . $return_path ); killme(); } + + if($observer) { + logger('mod_item: post accepted from ' . $observer['xchan_name'] . ' for ' . $owner_xchan['xchan_name'], LOGGER_DEBUG); + } + + if($orig_post) { - $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']; + $str_group_allow = ((array_key_exists('group_allow',$_REQUEST)) + ? perms2str($_REQUEST['group_allow']) : $orig_post['allow_gid']); + $str_contact_allow = ((array_key_exists('contact_allow',$_REQUEST)) + ? perms2str($_REQUEST['contact_allow']) : $orig_post['allow_cid']); + $str_group_deny = ((array_key_exists('group_deny',$_REQUEST)) + ? perms2str($_REQUEST['group_deny']) : $orig_post['deny_gid']); + $str_contact_deny = ((array_key_exists('contact_deny',$_REQUEST)) + ? perms2str($_REQUEST['contact_deny']) : $orig_post['deny_cid']); $location = $orig_post['location']; $coord = $orig_post['coord']; $verb = $orig_post['verb']; - $app = $orig_post['app']; - $title = escape_tags(trim($_REQUEST['title'])); - $body = escape_tags(trim($_REQUEST['body'])); + $app = $orig_post['app']; + $title = $_REQUEST['title']; + $body = $_REQUEST['body']; $private = $orig_post['item_private']; - + $item_flags = $orig_post['item_flags']; + $item_restrict = $orig_post['item_restrict']; + $postopts = $orig_post['postopts']; + $created = $orig_post['created']; + $mid = $orig_post['mid']; + $parent_mid = $orig_post['parent_mid']; + $plink = $orig_post['plink']; } else { @@ -242,11 +311,13 @@ function item_post(&$a) { $str_contact_deny = perms2str($_REQUEST['contact_deny']); } - $title = escape_tags(trim($_REQUEST['title'])); + $location = notags(trim($_REQUEST['location'])); $coord = notags(trim($_REQUEST['coord'])); $verb = notags(trim($_REQUEST['verb'])); - $body = escape_tags(trim($_REQUEST['body'])); + $title = escape_tags(trim($_REQUEST['title'])); + $body = $_REQUEST['body']; + $postopts = ''; $private = ( ( strlen($str_group_allow) @@ -287,164 +358,227 @@ function item_post(&$a) { $expires = '0000-00-00 00:00:00'; - if(feature_enabled($profile_uid,'expire')) { - // expire_quantity, e.g. '3' - // expire_units, e.g. days, weeks, months - if(x($_REQUEST,'expire_quantity') && (x($_REQUEST,'expire_units'))) { - $expire = datetime_convert(date_default_timezone_get(),'UTC', 'now + ' . $_REQUEST['expire_quantity'] . ' ' . $_REQUEST['expire_units']); + if(feature_enabled($profile_uid,'content_expire')) { + if(x($_REQUEST,'expire')) { + $expires = datetime_convert(date_default_timezone_get(),'UTC', $_REQUEST['expire']); if($expires <= datetime_convert()) $expires = '0000-00-00 00:00:00'; } } + $post_type = notags(trim($_REQUEST['type'])); - // Work around doubled linefeeds in Tinymce 3.5b2 - // First figure out if it's a status post that would've been - // created using tinymce. Otherwise leave it alone. + $mimetype = notags(trim($_REQUEST['mimetype'])); + if(! $mimetype) + $mimetype = 'text/bbcode'; - $plaintext = ((feature_enabled($profile_uid,'richtext')) ? false : true); - if((! $parent) && (! $api_source) && (! $plaintext)) { - $body = fix_mce_lf($body); + if($preview) { + $body = z_input_filter($profile_uid,$body,$mimetype); } + // Verify ability to use html or php!!! - // get contact info for poster - + $execflag = false; -/* - $author = null; - $self = false; - $contact_id = 0; - - if((local_user()) && (local_user() == $profile_uid)) { - $self = true; - $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1", - intval($_SESSION['uid']) + if($mimetype === 'application/x-php') { + $z = q("select account_id, account_roles from account left join channel on channel_account_id = account_id where channel_id = %d limit 1", + intval($profile_uid) ); - } - elseif(remote_user()) { - if(is_array($_SESSION['remote'])) { - foreach($_SESSION['remote'] as $v) { - if($v['uid'] == $profile_uid) { - $contact_id = $v['cid']; - break; - } + if($z && ($z[0]['account_roles'] & ACCOUNT_ROLE_ALLOWCODE)) { + if(local_user() && (get_account_id() == $z[0]['account_id'])) { + $execflag = true; + } + else { + notice( t('Executable content type not permitted to this channel.') . EOL); + if(x($_REQUEST,'return')) + goaway($a->get_baseurl() . "/" . $return_path ); + killme(); } - } - if($contact_id) { - $r = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1", - intval($contact_id) - ); } } - if(count($r)) { - // FIXME - $author = $r[0]; - $contact_id = $author['id']; - } + if($mimetype === 'text/bbcode') { - // get contact info for owner - - if($profile_uid == local_user()) { - $contact_record = $author; - } - else { - $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1", - intval($profile_uid) - ); - if(count($r)) - $contact_record = $r[0]; - } + // BBCODE alert: the following functions assume bbcode input + // and will require alternatives for alternative content-types (text/html, text/markdown, text/plain, etc.) + // we may need virtual or template classes to implement the possible alternatives -*/ + // Work around doubled linefeeds in Tinymce 3.5b2 + // First figure out if it's a status post that would've been + // created using tinymce. Otherwise leave it alone. - $post_type = notags(trim($_REQUEST['type'])); + $plaintext = ((feature_enabled($profile_uid,'richtext')) ? false : true); + if((! $parent) && (! $api_source) && (! $plaintext)) { + $body = fix_mce_lf($body); + } + // If we're sending a private top-level message with a single @-taggable channel as a recipient, @-tag it, if our pconfig is set. - /** - * - * When a photo was uploaded into the message using the (profile wall) ajax - * uploader, The permissions are initially set to disallow anybody but the - * owner from seeing it. This is because the permissions may not yet have been - * set for the post. If it's private, the photo permissions should be set - * appropriately. But we didn't know the final permissions on the post until - * now. So now we'll look for links of uploaded messages that are in the - * post and set them to the same permissions as the post itself. - * - */ - if(! $preview) { - fix_attached_photo_permissions($profile_uid,$owner_xchan['xchan_hash'],$body, - $str_contact_allow,$str_group_allow,$str_contact_deny,$str_group_deny); + if((! $parent) && (get_pconfig($profile_uid,'system','tagifonlyrecip')) && (substr_count($str_contact_allow,'<') == 1) && ($str_group_allow == '') && ($str_contact_deny == '') && ($str_group_deny == '')) { + $x = q("select abook_id, abook_their_perms from abook where abook_xchan = '%s' and abook_channel = %d limit 1", + dbesc(str_replace(array('<','>'),array('',''),$str_contact_allow)), + intval($profile_uid) + ); + if($x && ($x[0]['abook_their_perms'] & PERMS_W_TAGWALL)) + $body .= "\n\n@group+" . $x[0]['abook_id'] . "\n"; + } - fix_attached_file_permissions($channel,$observer['xchan_hash'],$body, - $str_contact_allow,$str_group_allow,$str_contact_deny,$str_group_deny); + /** + * fix naked links by passing through a callback to see if this is a red site + * (already known to us) which will get a zrl, otherwise link with url, add bookmark tag to both. + * First protect any url inside certain bbcode tags so we don't double link it. + */ + + $body = preg_replace_callback('/\[code(.*?)\[\/(code)\]/ism','red_escape_codeblock',$body); + $body = preg_replace_callback('/\[url(.*?)\[\/(url)\]/ism','red_escape_codeblock',$body); + $body = preg_replace_callback('/\[zrl(.*?)\[\/(zrl)\]/ism','red_escape_codeblock',$body); + + $body = preg_replace_callback("/([^\]\='".'"'."]|^|\#\^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\@\_\~\#\%\$\!\+\,]+)/ism", 'red_zrl_callback', $body); + + $body = preg_replace_callback('/\[\$b64zrl(.*?)\[\/(zrl)\]/ism','red_unescape_codeblock',$body); + $body = preg_replace_callback('/\[\$b64url(.*?)\[\/(url)\]/ism','red_unescape_codeblock',$body); + $body = preg_replace_callback('/\[\$b64code(.*?)\[\/(code)\]/ism','red_unescape_codeblock',$body); + + + /** + * + * When a photo was uploaded into the message using the (profile wall) ajax + * uploader, The permissions are initially set to disallow anybody but the + * owner from seeing it. This is because the permissions may not yet have been + * set for the post. If it's private, the photo permissions should be set + * appropriately. But we didn't know the final permissions on the post until + * now. So now we'll look for links of uploaded photos and attachments that are in the + * post and set them to the same permissions as the post itself. + * + * If the post was end-to-end encrypted we can't find images and attachments in the body, + * use our media_str input instead which only contains these elements - but only do this + * when encrypted content exists because the photo/attachment may have been removed from + * the post and we should keep it private. If it's encrypted we have no way of knowing + * so we'll set the permissions regardless and realise that the media may not be + * referenced in the post. + * + * What is preventing us from being able to upload photos into comments is dealing with + * the photo and attachment permissions, since we don't always know who was in the + * distribution for the top level post. + * + * We might be able to provide this functionality with a lot of fiddling: + * - if the top level post is public (make the photo public) + * - if the top level post was written by us or a wall post that belongs to us (match the top level post) + * - if the top level post has privacy mentions, add those to the permissions. + * - otherwise disallow the photo *or* make the photo public. This is the part that gets messy. + */ + + if(! $preview) { + fix_attached_photo_permissions($profile_uid,$owner_xchan['xchan_hash'],((strpos($body,'[/crypt]')) ? $_POST['media_str'] : $body),$str_contact_allow,$str_group_allow,$str_contact_deny,$str_group_deny); + + fix_attached_file_permissions($channel,$observer['xchan_hash'],((strpos($body,'[/crypt]')) ? $_POST['media_str'] : $body),$str_contact_allow,$str_group_allow,$str_contact_deny,$str_group_deny); - } + } - $body = bb_translate_video($body); + $body = bb_translate_video($body); - /** - * Fold multi-line [code] sequences - */ + /** + * Fold multi-line [code] sequences + */ - $body = preg_replace('/\[\/code\]\s*\[code\]/ism',"\n",$body); + $body = preg_replace('/\[\/code\]\s*\[code\]/ism',"\n",$body); - $body = scale_external_images($body,false); + $body = scale_external_images($body,false); - /** - * Look for any tags and linkify them - */ + /** + * Look for any tags and linkify them + */ + + $str_tags = ''; + $inform = ''; + $post_tags = array(); - $str_tags = ''; - $inform = ''; - $post_tags = array(); + $tags = get_tags($body); - $tags = get_tags($body); + $tagged = array(); - $tagged = array(); + if(count($tags)) { + $first_access_tag = true; + foreach($tags as $tag) { - $private_forum = false; + // If we already tagged 'Robert Johnson', don't try and tag 'Robert'. + // Robert Johnson should be first in the $tags array - if(count($tags)) { - foreach($tags as $tag) { + $fullnametagged = false; + for($x = 0; $x < count($tagged); $x ++) { + if(stristr($tagged[$x],$tag . ' ')) { + $fullnametagged = true; + break; + } + } + if($fullnametagged) + continue; - // If we already tagged 'Robert Johnson', don't try and tag 'Robert'. - // Robert Johnson should be first in the $tags array + $success = handle_tag($a, $body, $access_tag, $str_tags, (local_user()) ? local_user() : $profile_uid , $tag); + logger('handle_tag: ' . print_r($success,tue), LOGGER_DATA); + if(($access_tag) && (! $parent_item)) { + logger('access_tag: ' . $tag . ' ' . print_r($access_tag,true), LOGGER_DATA); + if ($first_access_tag) { + $str_contact_allow = ''; + $str_group_allow = ''; + $first_access_tag = false; + } + if(strpos($access_tag,'cid:') === 0) { + $str_contact_allow .= '<' . substr($access_tag,4) . '>'; + $access_tag = ''; + } + elseif(strpos($access_tag,'gid:') === 0) { + $str_group_allow .= '<' . substr($access_tag,4) . '>'; + $access_tag = ''; + } + } - $fullnametagged = false; - for($x = 0; $x < count($tagged); $x ++) { - if(stristr($tagged[$x],$tag . ' ')) { - $fullnametagged = true; - break; + if($success['replaced']) { + $tagged[] = $tag; + $post_tags[] = array( + 'uid' => $profile_uid, + 'type' => $success['termtype'], + 'otype' => TERM_OBJ_POST, + 'term' => $success['term'], + 'url' => $success['url'] + ); } } - if($fullnametagged) - continue; - - $success = handle_tag($a, $body, $inform, $str_tags, (local_user()) ? local_user() : $profile_uid , $tag); - logger('handle_tag: ' . print_r($success,tue)); - - if($success['replaced']) { - $tagged[] = $tag; - $post_tags[] = array( - 'uid' => $profile_uid, - 'type' => $success['termtype'], - 'otype' => TERM_OBJ_POST, - 'term' => $success['term'], - 'url' => $success['url'] - ); - } - if(is_array($success['contact']) && intval($success['contact']['prv'])) { - $private_forum = true; - $private_id = $success['contact']['id']; + } + + +// logger('post_tags: ' . print_r($post_tags,true)); + + + $attachments = ''; + $match = false; + + if(preg_match_all('/(\[attachment\](.*?)\[\/attachment\])/',$body,$match)) { + $attachments = array(); + foreach($match[2] as $mtch) { + $hash = substr($mtch,0,strpos($mtch,',')); + $rev = intval(substr($mtch,strpos($mtch,','))); + $r = attach_by_hash_nodata($hash,$rev); + if($r['success']) { + $attachments[] = array( + 'href' => $a->get_baseurl() . '/attach/' . $r['data']['hash'], + 'length' => $r['data']['filesize'], + 'type' => $r['data']['filetype'], + 'title' => urlencode($r['data']['filename']), + 'revision' => $r['data']['revision'] + ); + } + $body = str_replace($match[1],'',$body); } } } +// BBCODE end alert + + if(strlen($categories)) { $cats = explode(',',$categories); foreach($cats as $cat) { @@ -453,44 +587,12 @@ function item_post(&$a) { 'type' => TERM_CATEGORY, 'otype' => TERM_OBJ_POST, 'term' => trim($cat), - 'url' => '' + 'url' => $owner_xchan['xchan_url'] . '?f=&cat=' . urlencode(trim($cat)) ); } } -// logger('post_tags: ' . print_r($post_tags,true)); - - if(($private_forum) && (! $parent) && (! $private)) { - // we tagged a private forum in a top level post and the message was public. - // Restrict it. - $private = 1; - $str_contact_allow = '<' . $private_id . '>'; - } - - $attachments = ''; - $match = false; - - if(preg_match_all('/(\[attachment\](.*?)\[\/attachment\])/',$body,$match)) { - $attachments = array(); - foreach($match[2] as $mtch) { - $hash = substr($mtch,0,strpos($mtch,',')); - $rev = intval(substr($mtch,strpos($mtch,','))); - $r = attach_by_hash_nodata($hash,$rev); - if($r['success']) { - $attachments[] = array( - 'href' => $a->get_baseurl() . '/attach/' . $r['data']['hash'], - 'length' => $r['data']['filesize'], - 'type' => $r['data']['filetype'], - 'title' => urlencode($r['data']['filename']), - 'revision' => $r['data']['revision'] - ); - } - $body = str_replace($match[1],'',$body); - } - } - - $item_flags = ITEM_UNSEEN; - $item_restrict = ITEM_VISIBLE; + $item_flags |= ITEM_UNSEEN; if($post_type === 'wall' || $post_type === 'wall-comment') $item_flags = $item_flags | ITEM_WALL; @@ -502,9 +604,7 @@ function item_post(&$a) { $item_restrict = $item_restrict | ITEM_MODERATED; if($webpage) - $item_restrict = $item_restrict | ITEM_WEBPAGE; - - + $item_restrict = $item_restrict | $webpage; if(! strlen($verb)) @@ -512,54 +612,65 @@ function item_post(&$a) { $notify_type = (($parent) ? 'comment-new' : 'wall-new' ); - $uri = item_message_id(); - $parent_uri = $uri; + if(! $mid) { + $mid = (($message_id) ? $message_id : item_message_id()); + } + if(! $parent_mid) { + $parent_mid = $mid; + } + if($parent_item) - $parent_uri = $parent_item['uri']; + $parent_mid = $parent_item['mid']; // Fallback so that we alway have a thr_parent if(!$thr_parent) - $thr_parent = $uri; + $thr_parent = $mid; $datarray = array(); if(! $parent) { - $datarray['parent_uri'] = $uri; $item_flags = $item_flags | ITEM_THREAD_TOP; } - - $datarray['aid'] = $channel['channel_account_id']; - $datarray['uid'] = $profile_uid; - - $datarray['owner_xchan'] = (($owner_hash) ? $owner_hash : $owner_xchan['xchan_hash']); - $datarray['author_xchan'] = $observer['xchan_hash']; - $datarray['created'] = datetime_convert(); - $datarray['edited'] = datetime_convert(); - $datarray['expires'] = $expires; - $datarray['commented'] = datetime_convert(); - $datarray['received'] = datetime_convert(); - $datarray['changed'] = datetime_convert(); - $datarray['uri'] = $uri; - $datarray['parent_uri'] = $parent_uri; - $datarray['title'] = $title; - $datarray['body'] = $body; - $datarray['app'] = $app; - $datarray['location'] = $location; - $datarray['coord'] = $coord; - $datarray['inform'] = $inform; - $datarray['verb'] = $verb; - $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['item_private'] = $private; - $datarray['attach'] = $attachments; - $datarray['thr_parent'] = $thr_parent; - $datarray['postopts'] = ''; - $datarray['item_restrict'] = $item_restrict; - $datarray['item_flags'] = $item_flags; + if ((! $plink) && ($item_flags & ITEM_THREAD_TOP)) { + $plink = z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . $mid; + } + + $datarray['aid'] = $channel['channel_account_id']; + $datarray['uid'] = $profile_uid; + + $datarray['owner_xchan'] = (($owner_hash) ? $owner_hash : $owner_xchan['xchan_hash']); + $datarray['author_xchan'] = $observer['xchan_hash']; + $datarray['created'] = $created; + $datarray['edited'] = (($orig_post) ? datetime_convert() : $created); + $datarray['expires'] = $expires; + $datarray['commented'] = (($orig_post) ? datetime_convert() : $created); + $datarray['received'] = (($orig_post) ? datetime_convert() : $created); + $datarray['changed'] = (($orig_post) ? datetime_convert() : $created); + $datarray['mid'] = $mid; + $datarray['parent_mid'] = $parent_mid; + $datarray['mimetype'] = $mimetype; + $datarray['title'] = $title; + $datarray['body'] = $body; + $datarray['app'] = $app; + $datarray['location'] = $location; + $datarray['coord'] = $coord; + $datarray['verb'] = $verb; + $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['item_private'] = $private; + $datarray['attach'] = $attachments; + $datarray['thr_parent'] = $thr_parent; + $datarray['postopts'] = $postopts; + $datarray['item_restrict'] = $item_restrict; + $datarray['item_flags'] = $item_flags; + $datarray['layout_mid'] = $layout_mid; + $datarray['comment_policy'] = map_scope($channel['channel_w_comment']); + $datarray['term'] = $post_tags; + $datarray['plink'] = $plink; // preview mode - prepare the body for display and send it via json @@ -568,11 +679,14 @@ function item_post(&$a) { $datarray['owner'] = $owner_xchan; $datarray['author'] = $observer; + $datarray['attach'] = json_encode($datarray['attach']); $o = conversation($a,array($datarray),'search',false,'preview'); logger('preview: ' . $o, LOGGER_DEBUG); echo json_encode(array('preview' => $o)); killme(); } + if($orig_post) + $datarray['edit'] = true; call_hooks('post_local',$datarray); @@ -591,27 +705,35 @@ function item_post(&$a) { } - if($orig_post) { - $r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `attach` = '%s', `edited` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1", - dbesc($datarray['title']), - dbesc($datarray['body']), - dbesc($datarray['attach']), - dbesc(datetime_convert()), - intval($post_id), - intval($profile_uid) - ); + if(mb_strlen($datarray['title']) > 255) + $datarray['title'] = mb_substr($datarray['title'],0,255); - // remove taxonomy items for this post - we'll recreate them + if(array_key_exists('item_private',$datarray) && $datarray['item_private']) { - q("delete from term where otype = %d and oid = %d and type in (%d, %d, %d, %d) ", - intval(TERM_OBJ_POST), - intval($post_id), - intval(TERM_UNKNOWN), - intval(TERM_HASHTAG), - intval(TERM_MENTION), - intval(TERM_CATEGORY) - ); + $datarray['body'] = z_input_filter($datarray['uid'],$datarray['body'],$datarray['mimetype']); + if(local_user()) { + 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; + } + } + + logger('Encrypting local storage'); + $key = get_config('system','pubkey'); + $datarray['item_flags'] = $datarray['item_flags'] | ITEM_OBSCURED; + if($datarray['title']) + $datarray['title'] = json_encode(aes_encapsulate($datarray['title'],$key)); + if($datarray['body']) + $datarray['body'] = json_encode(aes_encapsulate($datarray['body'],$key)); + } + + if($orig_post) { + $datarray['id'] = $post_id; + + item_store_update($datarray,$execflag); + + update_remote_id($channel,$post_id,$webpage,$pagetitle,$namespace,$remote_id,$mid); proc_run('php', "include/notifier.php", 'edit_post', $post_id); if((x($_REQUEST,'return')) && strlen($return_path)) { @@ -624,60 +746,28 @@ function item_post(&$a) { $post_id = 0; - $post_id = item_store($datarray); + $post = item_store($datarray,$execflag); + + $post_id = $post['item_id']; if($post_id) { logger('mod_item: saved item ' . $post_id); - if(count($post_tags)) { - foreach($post_tags as $tag) { - if(strlen(trim($tag['term']))) { - q("insert into term (uid,oid,otype,type,term,url) values (%d,%d,%d,%d,'%s','%s')", - intval($tag['uid']), - intval($post_id), - intval($tag['otype']), - intval($tag['type']), - dbesc(trim($tag['term'])), - dbesc(trim($tag['url'])) - ); - } - } - } - if($parent) { - - $r = q("UPDATE `item` SET `changed` = '%s' WHERE `parent` = %d ", - dbesc(datetime_convert()), - intval($parent) - ); - - // Inherit ACL's from the parent item. - - $r = q("UPDATE `item` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s', `item_private` = %d - WHERE `id` = %d LIMIT 1", - dbesc($parent_item['allow_cid']), - dbesc($parent_item['allow_gid']), - dbesc($parent_item['deny_cid']), - dbesc($parent_item['deny_gid']), - intval($parent_item['private']), - intval($post_id) - ); - if($datarray['owner_xchan'] != $datarray['author_xchan']) { notification(array( 'type' => NOTIFY_COMMENT, 'from_xchan' => $datarray['author_xchan'], 'to_xchan' => $datarray['owner_xchan'], 'item' => $datarray, - 'link' => $a->get_baseurl() . '/display/' . $datarray['uri'], + 'link' => $a->get_baseurl() . '/display/' . $datarray['mid'], 'verb' => ACTIVITY_POST, 'otype' => 'item', 'parent' => $parent, - 'parent_uri' => $parent_item['uri'] + 'parent_mid' => $parent_item['mid'] )); } - } else { $parent = $post_id; @@ -688,32 +778,17 @@ function item_post(&$a) { 'from_xchan' => $datarray['author_xchan'], 'to_xchan' => $datarray['owner_xchan'], 'item' => $datarray, - 'link' => $a->get_baseurl() . '/display/' . $datarray['uri'], + 'link' => $a->get_baseurl() . '/display/' . $datarray['mid'], 'verb' => ACTIVITY_POST, 'otype' => 'item' )); } } - // fallback so that parent always gets set to non-zero. - - if(! $parent) - $parent = $post_id; - - $r = q("UPDATE `item` SET `parent` = %d, `parent_uri` = '%s', `changed` = '%s' - WHERE `id` = %d LIMIT 1", - intval($parent), - dbesc(($parent == $post_id) ? $uri : $parent_item['uri']), - dbesc(datetime_convert()), - intval($post_id) - ); - // photo comments turn the corresponding item visible to the profile wall // 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. -// fixme set item visible as well - if($parent_item['item_restrict'] & ITEM_HIDDEN) { $r = q("UPDATE `item` SET `item_restrict` = %d WHERE `id` = %d LIMIT 1", intval($parent_item['item_restrict'] - ITEM_HIDDEN), @@ -728,33 +803,11 @@ function item_post(&$a) { // NOTREACHED } - // update the commented timestamp on the parent - - q("UPDATE `item` set `commented` = '%s', `changed` = '%s' WHERE `id` = %d LIMIT 1", - dbesc(datetime_convert()), - dbesc(datetime_convert()), - intval($parent) - ); - - if($webpage) { - - // store page info as an alternate message_id so we can access it via - // https://sitename/page/$channelname/$pagetitle - // if no pagetitle was given or it couldn't be transliterated into a url, use the first - // sixteen bytes of the uri - which makes the link portable and not quite as daunting - // as the entire uri. If it were the post_id the link would be less portable. - // We should have the ability to edit this and arrange pages into menus via the pages module - q("insert into item_id ( iid, uid, sid, service ) values ( %d, %d, '%s','%s' )", - intval($post_id), - intval($channel['channel_id']), - dbesc(($pagetitle) ? $pagetitle : substr($uri,0,16)), - dbesc('WEBPAGE') - ); - } + update_remote_id($channel,$post_id,$webpage,$pagetitle,$namespace,$remote_id,$mid); $datarray['id'] = $post_id; - $datarray['plink'] = $a->get_baseurl() . '/display/' . $channel['channel_address'] . '/' . $post_id; + $datarray['llink'] = $a->get_baseurl() . '/display/' . $channel['channel_address'] . '/' . $post_id; call_hooks('post_local_end', $datarray); @@ -765,7 +818,7 @@ function item_post(&$a) { // figure out how to return, depending on from whence we came if($api_source) - return; + return $post; if($return_path) { goaway($a->get_baseurl() . "/" . $return_path); @@ -793,9 +846,40 @@ function item_content(&$a) { require_once('include/security.php'); - if(($a->argc == 3) && ($a->argv[1] === 'drop') && intval($a->argv[2])) { + if((argc() == 3) && (argv(1) === 'drop') && intval(argv(2))) { require_once('include/items.php'); - drop_item($a->argv[2]); + $i = q("select id, uid, author_xchan, owner_xchan, source_xchan, item_restrict from item where id = %d and uid = %d limit 1", + intval(argv(2)), + intval(local_user()) + ); + + if($i) { + $can_delete = false; + $local_delete = false; + if(local_user() && local_user() == $i[0]['uid']) + $local_delete = true; + + $ob_hash = get_observer_hash(); + if($ob_hash && ($ob_hash === $i[0]['author_xchan'] || $ob_hash === $i[0]['owner_xchan'] || $ob_hash === $i[0]['source_xchan'])) + $can_delete = true; + + if(! ($can_delete || $local_delete)) { + notice( t('Permission denied.') . EOL); + return; + } + + // 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))) { + drop_item($i[0]['id']); + } + else { + // complex deletion that needs to propagate and be performed in phases + drop_item($i[0]['id'],true,DROPITEM_PHASE1); + tag_deliver($i[0]['uid'],$i[0]['id']); + } + } } } @@ -804,36 +888,64 @@ function item_content(&$a) { * the appropiate link. * * @param unknown_type $body the text to replace the tag in - * @param unknown_type $inform a comma-seperated string containing everybody to inform + * @param unknown_type $access_tag - used to return tag ACL exclusions e.g. @!foo * @param unknown_type $str_tags string to add the tag to * @param unknown_type $profile_uid * @param unknown_type $tag the tag to replace * * @return boolean true if replaced, false if not replaced */ -function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag) { +function handle_tag($a, &$body, &$access_tag, &$str_tags, $profile_uid, $tag) { $replaced = false; $r = null; - $termtype = ((strpos($tag,'#') === 0) ? TERM_HASHTAG : TERM_UNKNOWN); - $termtype = ((strpos($tag,'@') === 0) ? TERM_MENTION : $termtype); + + $termtype = ((strpos($tag,'#') === 0) ? TERM_HASHTAG : TERM_UNKNOWN); + $termtype = ((strpos($tag,'@') === 0) ? TERM_MENTION : $termtype); + $termtype = ((strpos($tag,'#^[') === 0) ? TERM_BOOKMARK : $termtype); + //is it a hash tag? if(strpos($tag,'#') === 0) { - //if the tag is replaced... - if(strpos($tag,'[url=')) + if(strpos($tag,'#^[') === 0) { + if(preg_match('/#\^\[(url|zrl)(.*?)\](.*?)\[\/(url|zrl)\]/',$tag,$match)) { + $basetag = $match[3]; + $url = ((substr($match[2],0,1) === '=') ? substr($match[2],1) : $match[3]); + $replaced = true; + + } + } + // if the tag is already replaced... + elseif(strpos($tag,'[zrl=')) { //...do nothing return $replaced; - //base tag has the tags name only - $basetag = str_replace('_',' ',substr($tag,1)); - //create text for link - $url = $a->get_baseurl() . '/search?tag=' . rawurlencode($basetag); - $newtag = '#[url=' . $a->get_baseurl() . '/search?tag=' . rawurlencode($basetag) . ']' . $basetag . '[/url]'; - //replace tag by the link - $body = str_replace($tag, $newtag, $body); - $replaced = true; + } + if($tag == '#getzot') { + $basetag = 'getzot'; + $url = 'https://redmatrix.me'; + $newtag = '#[zrl=' . $url . ']' . $basetag . '[/zrl]'; + $body = str_replace($tag,$newtag,$body); + $replaced = true; + } + if(! $replaced) { + //base tag has the tags name only + + if((substr($tag,0,7) === '#"') && (substr($tag,-6,6) === '"')) { + $basetag = substr($tag,7); + $basetag = substr($basetag,0,-6); + } + else + $basetag = str_replace('_',' ',substr($tag,1)); + + //create text for link + $url = $a->get_baseurl() . '/search?tag=' . rawurlencode($basetag); + $newtag = '#[zrl=' . $a->get_baseurl() . '/search?tag=' . rawurlencode($basetag) . ']' . $basetag . '[/zrl]'; + //replace tag by the link + $body = str_replace($tag, $newtag, $body); + $replaced = true; + } //is the link already in str_tags? if(! stristr($str_tags,$newtag)) { //append or set str_tags @@ -843,107 +955,163 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag) { } return array('replaced' => $replaced, 'termtype' => $termtype, 'term' => $basetag, 'url' => $url, 'contact' => $r[0]); } + //is it a person tag? + if(strpos($tag,'@') === 0) { + + // The @! tag will alter permissions + $exclusive = ((strpos($tag,'!') === 1) ? true : false); + //is it already replaced? - if(strpos($tag,'[url=')) + if(strpos($tag,'[zrl=')) return $replaced; - $stat = false; + //get the person's name - $name = substr($tag,1); - //is it a link or a full dfrn address? - if((strpos($name,'@')) || (strpos($name,'http://'))) { - $newname = $name; - //get the profile links - $links = @lrdd($name); - if(count($links)) { - //for all links, collect how is to inform and how's profile is to link - foreach($links as $link) { - if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') - $profile = $link['@attributes']['href']; - if($link['@attributes']['rel'] === 'salmon') { - if(strlen($inform)) - $inform .= ','; - $inform .= 'url:' . str_replace(',','%2c',$link['@attributes']['href']); - } - } - } - } else { //if it is a name rather than an address - $newname = $name; - $alias = ''; - $tagcid = 0; - //is it some generated name? - if(strrpos($newname,'+')) { - //get the id - $tagcid = intval(substr($newname,strrpos($newname,'+') + 1)); - //remove the next word from tag's name - if(strpos($name,' ')) { - $name = substr($name,0,strpos($name,' ')); - } + + $name = substr($tag,(($exclusive) ? 2 : 1)); // The name or name fragment we are going to replace + $newname = $name; // a copy that we can mess with + $tagcid = 0; + + $r = null; + + // is it some generated name? + + $forum = false; + $trailing_plus_name = false; + + // @channel+ is a forum or network delivery tag + + if(substr($newname,-1,1) === '+') { + $forum = true; + $newname = substr($newname,0,-1); + } + + // Here we're looking for an address book entry as provided by the auto-completer + // of the form something+nnn where nnn is an abook_id or the first chars of xchan_hash + + if(strrpos($newname,'+')) { + //get the id + + if(strrpos($tagcid,' ')) + $tagcid = substr($tagcid,0,strrpos($tagcid,' ')); + + $tagcid = substr($newname,strrpos($newname,'+') + 1); + + if(strlen($tagcid) < 16) + $abook_id = intval($tagcid); + //remove the next word from tag's name + if(strpos($name,' ')) { + $name = substr($name,0,strpos($name,' ')); } - if($tagcid) { //if there was an id - //select contact with that id from the logged in user's contact list + if($abook_id) { // if there was an id + // select channel with that id from the logged in user's address book $r = q("SELECT * FROM abook left join xchan on abook_xchan = xchan_hash WHERE abook_id = %d AND abook_channel = %d LIMIT 1", - intval($tagcid), + intval($abook_id), intval($profile_uid) ); - } else { - $newname = str_replace('_',' ',$name); - - //select someone from this user's contacts by name - $r = q("SELECT * FROM abook left join xchan on abook_xchan - xchan_hash - WHERE xchan_name = '%s' AND abook_channel = %d LIMIT 1", - dbesc($newname), - intval($profile_uid) + $r = q("SELECT * FROM xchan + WHERE xchan_hash like '%s%%' LIMIT 1", + dbesc($tagcid) ); + } + } - if(! $r) { - //select someone by attag or nick and the name passed in -/* $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1", - dbesc($name), - dbesc($name), - intval($profile_uid) - ); -*/ } + if(! $r) { + + // look for matching names in the address book + + // Two ways to deal with spaces - doube quote the name or use underscores + // we see this after input filtering so quotes have been html entity encoded + + if((substr($name,0,6) === '"') && (substr($name,-6,6) === '"')) { + $newname = substr($name,6); + $newname = substr($newname,0,-6); } -/* } elseif(strstr($name,'_') || strstr($name,' ')) { //no id - //get the real name + else $newname = str_replace('_',' ',$name); - //select someone from this user's contacts by name - $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1", - dbesc($newname), + + //select someone from this user's contacts by name + $r = q("SELECT * FROM abook left join xchan on abook_xchan = xchan_hash + WHERE xchan_name = '%s' AND abook_channel = %d LIMIT 1", + dbesc($newname), + intval($profile_uid) + ); + + if(! $r) { + //select someone by attag or nick and the name passed in + $r = q("SELECT * FROM abook left join xchan on abook_xchan = xchan_hash + WHERE xchan_addr like ('%s') AND abook_channel = %d LIMIT 1", + dbesc($newname . '@%'), intval($profile_uid) ); - } else { - //select someone by attag or nick and the name passed in - $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1", - dbesc($name), - dbesc($name), + } + + if(! $r) { + + // it's possible somebody has a name ending with '+', which we stripped off as a forum indicator + // This is very rare but we want to get it right. + + $r = q("SELECT * FROM abook left join xchan on abook_xchan = xchan_hash + WHERE xchan_name = '%s' AND abook_channel = %d LIMIT 1", + dbesc($newname . '+'), intval($profile_uid) ); - }*/ - //$r is set, if someone could be selected - if($r) { - $profile = $r[0]['xchan_url']; - $newname = $r[0]['xchan_name']; - //add person's id to $inform - if(strlen($inform)) - $inform .= ','; - $inform .= 'cid:' . $r[0]['id']; + if($r) + $trailing_plus_name = true; + } + } + + // $r is set if we found something + + if($r) { + $profile = $r[0]['xchan_url']; + $newname = $r[0]['xchan_name']; + // add the channel's xchan_hash to $access_tag if exclusive + if($exclusive) { + $access_tag .= 'cid:' . $r[0]['xchan_hash']; } } - //if there is an url for this persons profile + else { + // check for a group/collection exclusion tag + + // note that we aren't setting $replaced even though we're replacing text. + // This tag isn't going to get a term attached to it. It's only used for + // access control. The link points to out own channel just so it doesn't look + // weird - as all the other tags are linked to something. + + if(local_user() && local_user() == $profile_uid) { + require_once('include/group.php'); + $grp = group_byname($profile_uid,$name); + if($grp) { + $g = q("select hash from groups where id = %d and visible = 1 limit 1", + intval($grp[0]['id']) + ); + if($g && $exclusive) { + $access_tag .= 'gid:' . $g[0]['hash']; + } + $channel = get_app()->get_channel(); + if($channel) { + $newtag = '@' . (($exclusive) ? '!' : '') . '[zrl=' . z_root() . '/channel/' . $channel['channel_address'] . ']' . $newname . '[/zrl]'; + $body = str_replace('@' . (($exclusive) ? '!' : '') . $name, $newtag, $body); + } + } + } + } + + // if there is an url for this channel + if(isset($profile)) { $replaced = true; //create profile link $profile = str_replace(',','%2c',$profile); $url = $profile; - $newtag = '@[url=' . $profile . ']' . $newname . '[/url]'; - $body = str_replace('@' . $name, $newtag, $body); + $newtag = '@' . (($exclusive) ? '!' : '') . '[zrl=' . $profile . ']' . $newname . (($forum && ! $trailing_plus_name) ? '+' : '') . '[/zrl]'; + $body = str_replace('@' . (($exclusive) ? '!' : '') . $name, $newtag, $body); //append tag to str_tags if(! stristr($str_tags,$newtag)) { if(strlen($str_tags)) @@ -952,8 +1120,7 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag) { } } } - - return array('replaced' => $replaced, 'termtype' => $termtype, 'term' => $newname, 'url' => $url, 'contact' => $r[0]); + return array('replaced' => $replaced, 'termtype' => $termtype, 'term' => $newname, 'url' => $url, 'contact' => $r[0]); } @@ -962,15 +1129,18 @@ function fix_attached_photo_permissions($uid,$xchan_hash,$body, $str_contact_allow,$str_group_allow,$str_contact_deny,$str_group_deny) { $match = null; - - if(preg_match_all("/\[img\](.*?)\[\/img\]/",$body,$match)) { - $images = $match[1]; + // match img and zmg image links + if(preg_match_all("/\[[zi]mg(.*?)\](.*?)\[\/[zi]mg\]/",$body,$match)) { + $images = $match[2]; if($images) { foreach($images as $image) { if(! stristr($image,get_app()->get_baseurl() . '/photo/')) continue; $image_uri = substr($image,strrpos($image,'/') + 1); - $image_uri = substr($image_uri,0, strpos($image_uri,'-')); + if(strpos($image_uri,'-') !== false) + $image_uri = substr($image_uri,0, strpos($image_uri,'-')); + if(strpos($image_uri,'.') !== false) + $image_uri = substr($image_uri,0, strpos($image_uri,'.')); if(! strlen($image_uri)) continue; $srch = '<' . $xchan_hash . '>'; @@ -985,14 +1155,13 @@ function fix_attached_photo_permissions($uid,$xchan_hash,$body, if($r) { $r = q("UPDATE photo SET allow_cid = '%s', allow_gid = '%s', deny_cid = '%s', deny_gid = '%s' - WHERE resource_id = '%s' AND uid = %d AND album = '%s' ", + WHERE resource_id = '%s' AND uid = %d ", dbesc($str_contact_allow), dbesc($str_group_allow), dbesc($str_contact_deny), dbesc($str_group_deny), dbesc($image_uri), - intval($uid), - dbesc( t('Wall Photos')) + intval($uid) ); // also update the linked item (which is probably invisible) @@ -1005,12 +1174,15 @@ function fix_attached_photo_permissions($uid,$xchan_hash,$body, intval($uid) ); if($r) { - $r = q("UPDATE item SET allow_cid = '%s', allow_gid = '%s', deny_cid = '%s', deny_gid = '%s' + $private = (($str_contact_allow || $str_group_allow || $str_contact_deny || $str_group_deny) ? true : false); + + $r = q("UPDATE item SET allow_cid = '%s', allow_gid = '%s', deny_cid = '%s', deny_gid = '%s', item_private = %d WHERE id = %d AND uid = %d limit 1", dbesc($str_contact_allow), dbesc($str_group_allow), dbesc($str_contact_deny), dbesc($str_group_deny), + intval($private), intval($r[0]['id']), intval($uid) ); @@ -1045,3 +1217,41 @@ function fix_attached_file_permissions($channel,$observer_hash,$body, } } } +function item_check_service_class($channel_id,$iswebpage) { + $ret = array('success' => false, $message => ''); + if ($iswebpage) { + $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_restrict & %d) and not (i.item_restrict & %d) and i.uid= %d ", + intval(ITEM_WEBPAGE), + intval(ITEM_DELETED), + intval($channel_id) + ); + } + else { + $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_restrict=0) and i.uid= %d ", + intval($channel_id) + ); + } + if(! ($r && count($r))) { + $ret['message'] = t('Unable to obtain identity information from database'); + return $ret; + } + if (!$iswebpage) { + if(! service_class_allows($channel_id,'total_items',$r[0]['total'])) { + $result['message'] .= upgrade_message().sprintf(t("You have reached your limit of %1$.0f top level posts."),$r[0]['total']); + return $result; + } + } + else { + if(! service_class_allows($channel_id,'total_pages',$r[0]['total'])) { + $result['message'] .= upgrade_message().sprintf(t("You have reached your limit of %1$.0f webpages."),$r[0]['total']); + return $result; + } + } + + $ret['success'] = true; + return $ret; +} diff --git a/mod/lang.php b/mod/lang.php new file mode 100644 index 000000000..fba5f9c73 --- /dev/null +++ b/mod/lang.php @@ -0,0 +1,6 @@ +<?php + +function lang_content(&$a) { + return lang_selector(); +} + diff --git a/mod/layouts.php b/mod/layouts.php new file mode 100644 index 000000000..318e6e29f --- /dev/null +++ b/mod/layouts.php @@ -0,0 +1,122 @@ +<?php + +function layouts_content(&$a) { + + if(argc() > 1) + $which = argv(1); + else { + notice( t('Requested profile is not available.') . EOL ); + $a->error = 404; + return; + } + + profile_load($a,$which,0); + + + // Figure out who the page owner is. + $r = q("select channel_id from channel where channel_address = '%s'", + dbesc($which) + ); + if($r) { + $owner = intval($r[0]['channel_id']); + } + + // Block design features from visitors + + if((! local_user()) || (local_user() != $owner)) { + notice( t('Permission denied.') . EOL); + return; + } + + // Get the observer, check their permissions + + $observer = $a->get_observer(); + $ob_hash = (($observer) ? $observer['xchan_hash'] : ''); + + $perms = get_all_perms($owner,$ob_hash); + + if(! $perms['write_pages']) { + notice( t('Permission denied.') . EOL); + return; + } + + if((argc() > 3) && (argv(2) === 'share') && (argv(3))) { + $r = q("select sid, service, mimetype, title, body from item_id left join item on item.id = item_id.iid where item_id.uid = %d and item.mid = '%s' and service = 'PDL' order by sid asc", + intval($owner), + dbesc(argv(3)) + ); + if($r) { + header('Content-type: application/x-redmatrix-layout'); + header('Content-disposition: attachment; filename="' . $r[0]['sid'] . '.pdl"'); + echo json_encode($r); + killme(); + + } + } + + $tabs = array( + array( + 'label' => t('Layout Help'), + 'url' => 'help/Comanche', + 'sel' => '', + 'title' => t('Help with this feature'), + 'id' => 'layout-help-tab', + )); + + + $o .= replace_macros(get_markup_template('common_tabs.tpl'),array('$tabs' => $tabs)); + + + // Create a status editor (for now - we'll need a WYSIWYG eventually) to create pages + // Nickname is set to the observers xchan, and profile_uid to the owners. This lets you post pages at other people's channels. + + require_once ('include/conversation.php'); + + $x = array( + 'webpage' => ITEM_PDL, + 'is_owner' => true, + 'nickname' => $a->profile['channel_address'], + 'lockstate' => (($group || $cid || $channel['channel_allow_cid'] || $channel['channel_allow_gid'] || $channel['channel_deny_cid'] || $channel['channel_deny_gid']) ? 'lock' : 'unlock'), + 'bang' => (($group || $cid) ? '!' : ''), + 'showacl' => false, + 'visitor' => false, + 'nopreview' => 1, + 'ptlabel' => t('Layout Name'), + 'profile_uid' => intval($owner), + ); + + $o .= status_editor($a,$x); + + // Get a list of blocks. We can't display all them because endless scroll makes that unusable, so just list titles and an edit link. + // TODO - this should be replaced with pagelist_widget + + $r = q("select iid, sid, mid from item_id left join item on item.id = item_id.iid where item_id.uid = %d and service = 'PDL' order by sid asc", + intval($owner) + ); + + $pages = null; + + if($r) { + $pages = array(); + foreach($r as $rr) { + $pages[$rr['iid']][] = array('url' => $rr['iid'],'title' => $rr['sid'], 'mid' => $rr['mid']); + } + } + + + //Build the base URL for edit links + $url = z_root() . "/editlayout/" . $which; + + return $o . replace_macros(get_markup_template("layoutlist.tpl"), array( + '$baseurl' => $url, + '$edit' => t('Edit'), + '$share' => t('Share'), + '$pages' => $pages, + '$channel' => $which, + '$view' => t('View'), + '$preview' => '1', + + )); + + +} diff --git a/mod/like.php b/mod/like.php index 7c3df98ba..a76867422 100755 --- a/mod/like.php +++ b/mod/like.php @@ -48,11 +48,20 @@ function like_content(&$a) { $item = $r[0]; + $sys = get_sys_channel(); + $owner_uid = $item['uid']; + $owner_aid = $item['aid']; - if(! perm_is_allowed($owner_uid,$observer['xchan_hash'],'post_comments')) { - notice( t('Permission denied') . EOL); - killme(); + // if this is a "discover" item, (item['uid'] is the sys channel), + // fallback to the item comment policy, which should've been + // respected when generating the conversation thread. + // Even if the activity is rejected by the item owner, it should still get attached + // to the local discover conversation on this site. + + if(($owner_uid != $sys['channel_id']) && (! perm_is_allowed($owner_uid,$observer['xchan_hash'],'post_comments'))) { + notice( t('Permission denied') . EOL); + killme(); } $r = q("select * from xchan where xchan_hash = '%s' limit 1", @@ -78,7 +87,7 @@ function like_content(&$a) { dbesc($activity), dbesc($observer['xchan_hash']), intval($item_id), - dbesc($item['uri']) + dbesc($item['mid']) ); if($r) { $like_item = $r[0]; @@ -97,22 +106,24 @@ function like_content(&$a) { - $uri = item_message_id(); + $mid = item_message_id(); - $post_type = (($item['resource_type'] === 'photo') ? $t('photo') : t('status')); + $post_type = (($item['resource_type'] === 'photo') ? t('photo') : t('status')); - $links = array(array('rel' => 'alternate','type' => 'text/html', - 'href' => z_root() . '/display/' . $item['uri'])); + $links = array(array('rel' => 'alternate','type' => 'text/html', 'href' => $item['plink'])); $objtype = (($item['resource_type'] === 'photo') ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE ); $body = $item['body']; $obj = json_encode(array( 'type' => $objtype, - 'id' => $item['uri'], + 'id' => $item['mid'], + 'parent' => (($item['thr_parent']) ? $item['thr_parent'] : $item['parent_mid']), 'link' => $links, 'title' => $item['title'], 'content' => $item['body'], + 'created' => $item['created'], + 'edited' => $item['edited'], 'author' => array( 'name' => $item_author['xchan_name'], 'address' => $item_author['xchan_addr'], @@ -124,6 +135,9 @@ function like_content(&$a) { ), )); + if(! ($item['item_flags'] & ITEM_THREAD_TOP)) + $post_type = 'comment'; + if($verb === 'like') $bodyverb = t('%1$s likes %2$s\'s %3$s'); if($verb === 'dislike') @@ -132,28 +146,29 @@ function like_content(&$a) { if(! isset($bodyverb)) return; - $item_flags = ITEM_ORIGIN; + $item_flags = ITEM_ORIGIN | ITEM_NOTSHOWN; if($item['item_flags'] & ITEM_WALL) $item_flags |= ITEM_WALL; $arr = array(); - $arr['uri'] = $uri; + $arr['mid'] = $mid; + $arr['aid'] = $owner_aid; $arr['uid'] = $owner_uid; $arr['item_flags'] = $item_flags; $arr['parent'] = $item['id']; - $arr['parent_uri'] = $item['uri']; - $arr['thr_parent'] = $item['uri']; + $arr['parent_mid'] = $item['mid']; + $arr['thr_parent'] = $item['mid']; $arr['owner_xchan'] = $thread_owner['xchan_hash']; $arr['author_xchan'] = $observer['xchan_hash']; - $ulink = '[url=' . $item_owner['xchan_url'] . ']' . $item_owner['xchan_name'] . '[/url]'; - $alink = '[url=' . $observer['xchan_url'] . ']' . $observer['xchan_name'] . '[/url]'; - $plink = '[url=' . $a->get_baseurl() . '/display/' . $item['uri'] . ']' . $post_type . '[/url]'; + $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]'; - $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink ); + $arr['body'] = sprintf( $bodyverb, $alink, $ulink, $plink ); $arr['verb'] = $activity; $arr['obj_type'] = $objtype; @@ -164,7 +179,9 @@ function like_content(&$a) { $arr['deny_cid'] = $item['deny_cid']; $arr['deny_gid'] = $item['deny_gid']; - $post_id = item_store($arr); + + $post = item_store($arr); + $post_id = $post['item_id']; $arr['id'] = $post_id; diff --git a/mod/lockview.php b/mod/lockview.php index 01a6997ee..0ea708c80 100644 --- a/mod/lockview.php +++ b/mod/lockview.php @@ -26,12 +26,14 @@ function lockview_content(&$a) { $item = $r[0]; - if($item['uid'] != local_user()) + if($item['uid'] != local_user()) { + echo '<li>' . t('Remote privacy information not available.') . '</li>'; killme(); + } if(($item['item_private'] == 1) && (! strlen($item['allow_cid'])) && (! strlen($item['allow_gid'])) && (! strlen($item['deny_cid'])) && (! strlen($item['deny_gid']))) { - echo t('Remote privacy information not available.') . '<br />'; + echo '<li>' . t('Remote privacy information not available.') . '</li>'; killme(); } @@ -40,7 +42,7 @@ function lockview_content(&$a) { $deny_users = expand_acl($item['deny_cid']); $deny_groups = expand_acl($item['deny_gid']); - $o = t('Visible to:') . '<br />'; + $o = '<li>' . t('Visible to:') . '</li>'; $l = array(); stringify_array_elms($allowed_groups,true); @@ -49,31 +51,31 @@ function lockview_content(&$a) { stringify_array_elms($deny_users,true); if(count($allowed_groups)) { - $r = q("SELECT name FROM group WHERE hash IN ( " . implode(', ', $allowed_groups) . " )"); + $r = q("SELECT name FROM `groups` WHERE hash IN ( " . implode(', ', $allowed_groups) . " )"); if($r) foreach($r as $rr) - $l[] = '<b>' . $rr['name'] . '</b>'; + $l[] = '<li><b>' . $rr['name'] . '</b></li>'; } if(count($allowed_users)) { $r = q("SELECT xchan_name FROM xchan WHERE xchan_hash IN ( " . implode(', ',$allowed_users) . " )"); if($r) foreach($r as $rr) - $l[] = $rr['xchan_name']; + $l[] = '<li>' . $rr['xchan_name'] . '</li>'; } if(count($deny_groups)) { - $r = q("SELECT name FROM group WHERE hash IN ( " . implode(', ', $deny_groups) . " )"); + $r = q("SELECT name FROM `groups` WHERE hash IN ( " . implode(', ', $deny_groups) . " )"); if($r) foreach($r as $rr) - $l[] = '<b><strike>' . $rr['name'] . '</strike></b>'; + $l[] = '<li><b><strike>' . $rr['name'] . '</strike></b></li>'; } if(count($deny_users)) { $r = q("SELECT xchan_name FROM xchan WHERE xchan_hash IN ( " . implode(', ', $deny_users) . " )"); if($r) foreach($r as $rr) - $l[] = '<strike>' . $rr['xchan_name'] . '</strike>'; + $l[] = '<li><strike>' . $rr['xchan_name'] . '</strike></li>'; } - echo $o . implode(', ', $l); + echo $o . implode($l); killme(); } diff --git a/mod/magic.php b/mod/magic.php index ba9e69a49..aead559a7 100644 --- a/mod/magic.php +++ b/mod/magic.php @@ -4,81 +4,103 @@ function magic_init(&$a) { + $ret = array('success' => false, 'url' => '', 'message' => ''); + logger('mod_magic: invoked', LOGGER_DEBUG); + + logger('mod_magic: args: ' . print_r($_REQUEST,true),LOGGER_DATA); + $addr = ((x($_REQUEST,'addr')) ? $_REQUEST['addr'] : ''); $hash = ((x($_REQUEST,'hash')) ? $_REQUEST['hash'] : ''); $dest = ((x($_REQUEST,'dest')) ? $_REQUEST['dest'] : ''); + $test = ((x($_REQUEST,'test')) ? intval($_REQUEST['test']) : 0); + $rev = ((x($_REQUEST,'rev')) ? intval($_REQUEST['rev']) : 0); - if($hash) { - $x = q("select xchan.xchan_url, hubloc.* from xchan left join hubloc on xchan_hash = hubloc_hash - where hubloc_hash = '%s' and (hubloc_flags & %d) limit 1", - dbesc($hash), - intval(HUBLOC_FLAGS_PRIMARY) - ); - } - elseif($addr) { - $x = q("select hubloc.* from xchan left join hubloc on xchan_hash = hubloc_hash - where xchan_addr = '%s' and (hubloc_flags & %d) limit 1", - dbesc($addr), - intval(HUBLOC_FLAGS_PRIMARY) - ); - } - else { - // See if we know anybody at the dest site that will unlock the door for us - $b = explode('/',$dest); - if(count($b) >= 2) - $u = $b[0] . '//' . $b[2]; - - $x = q("select xchan.xchan_url, hubloc.* from xchan left join hubloc on xchan_hash = hubloc_hash - where hubloc_url = '%s' limit 1", - dbesc($u) - ); + $parsed = parse_url($dest); + if(! $parsed) { + if($test) { + $ret['message'] .= 'could not parse ' . $dest . EOL; + return($ret); + } + goaway($dest); } + $basepath = $parsed['scheme'] . '://' . $parsed['host'] . (($parsed['port']) ? ':' . $parsed['port'] : ''); + $x = q("select * from hubloc where hubloc_url = '%s' order by hubloc_connected desc limit 1", + dbesc($basepath) + ); + if(! $x) { - // Finger them if they've never been seen here before - - if($addr) { - $ret = zot_finger($addr,null); - if($ret['success']) { - $j = json_decode($ret['body'],true); - if($j) - import_xchan($j); - $x = q("select hubloc.* from xchan left join hubloc on xchan_hash = hubloc_hash - where xchan_addr = '%s' and (hubloc_flags & %d) limit 1", - dbesc($addr), - intval(HUBLOC_FLAGS_PRIMARY) - ); - } + /* + * We have no records for, or prior communications with this hub. + * If an address was supplied, let's finger them to create a hub record. + * Otherwise we'll use the special address '[system]' which will return + * either a system channel or the first available normal channel. We don't + * really care about what channel is returned - we need the hub information + * from that response so that we can create signed auth packets destined + * for that hub. + * + */ + + $ret = zot_finger((($addr) ? $addr : '[system]@' . $parsed['host']),null); + if($ret['success']) { + $j = json_decode($ret['body'],true); + if($j) + import_xchan($j); + + // Now try again + + $x = q("select * from hubloc where hubloc_url = '%s' order by hubloc_connected desc limit 1", + dbesc($basepath) + ); } } if(! $x) { - notice( t('Channel not found.') . EOL); - return; + if($rev) + goaway($dest); + else { + logger('mod_magic: no channels found for requested hub.' . print_r($_REQUEST,true)); + if($test) { + $ret['message'] .= 'This site has no previous connections with ' . $basepath . EOL; + return $ret; + } + notice( t('Hub not found.') . EOL); + return; + } } - if($x[0]['hubloc_url'] === z_root()) { - $webbie = substr($x[0]['hubloc_addr'],0,strpos('@',$x[0]['hubloc_addr'])); - switch($dest) { - case 'channel': - $desturl = z_root() . '/channel/' . $webbie; - break; - case 'photos': - $desturl = z_root() . '/photos/' . $webbie; - break; - case 'profile': - $desturl = z_root() . '/profile/' . $webbie; - break; - default: - $desturl = $dest; - break; + // This is ready-made for a plugin that provides a blacklist or "ask me" before blindly authenticating. + // By default, we'll proceed without asking. + + $arr = array( + 'channel_id' => local_user(), + 'xchan' => $x[0], + 'destination' => $dest, + 'proceed' => true + ); + + call_hooks('magic_auth',$arr); + $dest = $arr['destination']; + if(! $arr['proceed']) { + if($test) { + $ret['message'] .= 'cancelled by plugin.' . EOL; + return $ret; } + goaway($dest); + } + + if((get_observer_hash()) && ($x[0]['hubloc_url'] === z_root())) { // We are already authenticated on this site and a registered observer. // Just redirect. - goaway($desturl); + if($test) { + $ret['success'] = true; + $ret['message'] .= 'Local site - you are already authenticated.' . EOL; + return $ret; + } + goaway($dest); } if(local_user()) { @@ -90,25 +112,35 @@ function magic_init(&$a) { $channel['token'] = $token; $channel['token_sig'] = $token_sig; - - $recip = array(array('guid' => $x[0]['hubloc_guid'],'guid_sig' => $x[0]['hubloc_guid_sig'])); - - $hash = random_string(); - $r = q("insert into verify ( type, channel, token, meta, created) values ('%s','%d','%s','%s','%s')", dbesc('auth'), intval($channel['channel_id']), dbesc($token), - dbesc($x[0]['hubloc_hash']), + dbesc($x[0]['hubloc_url']), dbesc(datetime_convert()) ); - goaway($x[0]['hubloc_callback'] . '/' . substr($x[0]['hubloc_addr'],0,strpos($x[0]['hubloc_addr'],'@')) - . '/?f=&auth=' . $channel['channel_address'] . '@' . $a->get_hostname() - . '&sec=' . $token . '&dest=' . $dest . '&version=' . ZOT_REVISION); + $target_url = $x[0]['hubloc_callback'] . '/?f=&auth=' . urlencode($channel['channel_address'] . '@' . $a->get_hostname()) + . '&sec=' . $token . '&dest=' . urlencode($dest) . '&version=' . ZOT_REVISION; + + logger('mod_magic: redirecting to: ' . $target_url, LOGGER_DEBUG); + + if($test) { + $ret['success'] = true; + $ret['url'] = $target_url; + $ret['message'] = 'token ' . $token . ' created for channel ' . $channel['channel_id'] . ' for url ' . $x[0]['hubloc_url'] . EOL; + return $ret; + } + + goaway($target_url); + } - if(strpos($dest,'/')) - goaway($dest); - goaway(z_root()); + if($test) { + $ret['message'] = 'Not authenticated or invalid arguments to mod_magic' . EOL; + return $ret; + } + + goaway($dest); + } diff --git a/mod/mail.php b/mod/mail.php new file mode 100644 index 000000000..9c84872ef --- /dev/null +++ b/mod/mail.php @@ -0,0 +1,349 @@ +<?php + +require_once('include/acl_selectors.php'); +require_once('include/message.php'); +require_once('include/zot.php'); +require_once("include/bbcode.php"); +require_once('include/Contact.php'); + + +function mail_post(&$a) { + + if(! local_user()) + return; + + $replyto = ((x($_REQUEST,'replyto')) ? notags(trim($_REQUEST['replyto'])) : ''); + $subject = ((x($_REQUEST,'subject')) ? notags(trim($_REQUEST['subject'])) : ''); + $body = ((x($_REQUEST,'body')) ? escape_tags(trim($_REQUEST['body'])) : ''); + $recipient = ((x($_REQUEST,'messageto')) ? notags(trim($_REQUEST['messageto'])) : ''); + $rstr = ((x($_REQUEST,'messagerecip')) ? notags(trim($_REQUEST['messagerecip'])) : ''); + $expires = ((x($_REQUEST,'expires')) ? datetime_convert(date_default_timezone_get(),'UTC', $_REQUEST['expires']) : '0000-00-00 00:00:00'); + + // If we have a raw string for a recipient which hasn't been auto-filled, + // it means they probably aren't in our address book, hence we don't know + // if we have permission to send them private messages. + // finger them and find out before we try and send it. + + if(! $recipient) { + $channel = $a->get_channel(); + + $ret = zot_finger($rstr,$channel); + + if(! $ret['success']) { + notice( t('Unable to lookup recipient.') . EOL); + return; + } + $j = json_decode($ret['body'],true); + + logger('message_post: lookup: ' . $url . ' ' . print_r($j,true)); + + if(! ($j['success'] && $j['guid'])) { + notice( t('Unable to communicate with requested channel.')); + return; + } + + $x = import_xchan($j); + + if(! $x['success']) { + notice( t('Cannot verify requested channel.')); + return; + } + + $recipient = $x['hash']; + + $their_perms = 0; + + $global_perms = get_perms(); + + if($j['permissions']['data']) { + $permissions = crypto_unencapsulate($j['permissions'],$channel['channel_prvkey']); + if($permissions) + $permissions = json_decode($permissions); + logger('decrypted permissions: ' . print_r($permissions,true), LOGGER_DATA); + } + else + $permissions = $j['permissions']; + + foreach($permissions as $k => $v) { + if($v) { + $their_perms = $their_perms | intval($global_perms[$k][1]); + } + } + + if(! ($their_perms & PERMS_W_MAIL)) { + notice( t('Selected channel has private message restrictions. Send failed.')); + return; + } + } + + if(feature_enabled(local_user(),'richtext')) { + $body = fix_mce_lf($body); + } + + if(! $recipient) { + notice('No recipient found.'); + $a->argc = 2; + $a->argv[1] = 'new'; + return; + } + + // We have a local_user, let send_message use the session channel and save a lookup + + $ret = send_message(0, $recipient, $body, $subject, $replyto, $expires); + + if(! $ret['success']) { + notice($ret['message']); + } + + goaway(z_root() . '/message'); + +} + +function mail_content(&$a) { + + $o = ''; + nav_set_selected('messages'); + + if(! local_user()) { + notice( t('Permission denied.') . EOL); + return login(); + } + + $channel = $a->get_channel(); + head_set_icon($channel['xchan_photo_s']); + + $cipher = get_pconfig(local_user(),'system','default_cipher'); + 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) === 'drop')) { + if(! intval(argv(2))) + return; + $cmd = argv(1); + + $r = private_messages_drop(local_user(), argv(2)); + if($r) { + info( t('Message deleted.') . EOL ); + } + goaway($a->get_baseurl(true) . '/message' ); + } + + if((argc() == 3) && (argv(1) === 'recall')) { + if(! intval(argv(2))) + return; + $cmd = argv(1); + $r = q("update mail set mail_flags = mail_flags | %d where id = %d and channel_id = %d limit 1", + intval(MAIL_RECALLED), + intval(argv(2)), + intval(local_user()) + ); + proc_run('php','include/notifier.php','mail',intval(argv(2))); + + if($r) { + info( t('Message recalled.') . EOL ); + } + goaway($a->get_baseurl(true) . '/message' ); + + } + + if((argc() > 1) && (argv(1) === 'new')) { + + $o .= $header; + + $plaintext = false; + if(intval(get_pconfig(local_user(),'system','plaintext'))) + $plaintext = true; + if(! feature_enabled(local_user(),'richtext')) + $plaintext = true; + + $tpl = get_markup_template('msg-header.tpl'); + + $a->page['htmlhead'] .= replace_macros($tpl, array( + '$baseurl' => $a->get_baseurl(true), + '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'), + '$nickname' => $channel['channel_address'], + '$linkurl' => t('Please enter a link URL:'), + '$expireswhen' => t('Expires YYYY-MM-DD HH:MM') + )); + + $preselect = (isset($a->argv[2])?array($a->argv[2]):false); + + + $prename = $preurl = $preid = ''; + + 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_user()), + intval(argv(2)) + ); + if($r) { + $prename = $r[0]['xchan_name']; + $preurl = $r[0]['xchan_url']; + $preid = $r[0]['abook_id']; + } + } + + $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( + '$header' => t('Send Private Message'), + '$to' => t('To:'), + '$showinputs' => 'true', + '$prefill' => $prefill, + '$autocomp' => $autocomp, + '$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('Submit'), + '$defexpire' => '', + '$feature_expire' => ((feature_enabled(local_user(),'content_expire')) ? true : false), + '$expires' => t('Set expiration date'), + '$feature_encrypt' => ((feature_enabled(local_user(),'content_encrypt')) ? true : false), + '$encrypt' => t('Encrypt text'), + '$cipher' => $cipher, + + + )); + + return $o; + } + + + if((argc() > 1) && (intval(argv(1)))) { + + $o .= $header; + + $plaintext = true; + if( local_user() && feature_enabled(local_user(),'richtext') ) + $plaintext = false; + + $messages = private_messages_fetch_conversation(local_user(), argv(1), true); + + if(! $messages) { + info( t('Message not found.') . EOL); + return $o; + } + + 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')); + + + $tpl = get_markup_template('msg-header.tpl'); + + $a->page['htmlhead'] .= replace_macros($tpl, array( + '$nickname' => $channel['channel_addr'], + '$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') + )); + + + $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']; + + } + + $recp = (($message['from_xchan'] === $channel['channel_hash']) ? 'to' : 'from'); + +// FIXME - move this HTML to template + + $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, + + // 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_user(),'content_expire')) ? true : false), + '$expires' => t('Set expiration date'), + '$feature_encrypt' => ((feature_enabled(local_user(),'content_encrypt')) ? true : false), + '$encrypt' => t('Encrypt text'), + '$cipher' => $cipher, + + )); + + return $o; + } + +} diff --git a/mod/manage.php b/mod/manage.php index 2cdfce115..0772e2d61 100644 --- a/mod/manage.php +++ b/mod/manage.php @@ -36,8 +36,9 @@ function manage_content(&$a) { $channels = null; if(local_user()) { - $r = q("select channel.*, xchan.* from channel left join xchan on channel.channel_hash = xchan.xchan_hash where channel.channel_account_id = %d order by channel_name ", - intval(get_account_id()) + $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 ) order by channel_name ", + intval(get_account_id()), + intval(PAGE_REMOVED) ); $selected_channel = null; @@ -53,6 +54,18 @@ function manage_content(&$a) { $channels[$x]['default_links'] = '1'; } } + + $r = q("select count(channel_id) as total from channel where channel_account_id = %d and not ( channel_pageflags & %d )", + intval(get_account_id()), + intval(PAGE_REMOVED) + ); + $limit = service_class_fetch(local_user(),'total_identities'); + if($limit !== false) { + $channel_usage_message = sprintf( t("You have created %1$.0f of %2$.0f allowed channels."), $r[0]['total'], $limit); + } + else { + $channel_usage_message = ''; + } } $links = array( @@ -69,6 +82,7 @@ function manage_content(&$a) { '$msg_make_default' => t('Make Default'), '$links' => $links, '$all_channels' => $channels, + '$channel_usage_message' => $channel_usage_message, )); diff --git a/mod/match.php b/mod/match.php index 23eeb9370..5447f755d 100644 --- a/mod/match.php +++ b/mod/match.php @@ -1,5 +1,9 @@ <?php +// FIXME - this has never been properly ported from Friendica +// It takes keywords from your profile and queries the directory server for +// matching keywords from other profiles. + function match_content(&$a) { @@ -30,10 +34,10 @@ function match_content(&$a) { if($a->pager['page'] != 1) $params['p'] = $a->pager['page']; - if(strlen(get_config('system','directory_submit_url'))) - $x = post_url('http://dir.friendica.com/msearch', $params); - else - $x = post_url($a->get_baseurl() . '/msearch', $params); +// if(strlen(get_config('system','directory_submit_url'))) +// $x = post_url('http://dir.friendica.com/msearch', $params); +// else +// $x = post_url($a->get_baseurl() . '/msearch', $params); $j = json_decode($x); diff --git a/mod/menu.php b/mod/menu.php new file mode 100644 index 000000000..a2d0c2385 --- /dev/null +++ b/mod/menu.php @@ -0,0 +1,125 @@ +<?php + +require_once('include/menu.php'); + +function menu_post(&$a) { + + if(! local_user()) + return; + + $_REQUEST['menu_channel_id'] = local_user(); + if($_REQUEST['menu_bookmark']) + $_REQUEST['menu_flags'] |= MENU_BOOKMARK; + if($_REQUEST['menu_system']) + $_REQUEST['menu_flags'] |= MENU_SYSTEM; + + $menu_id = ((argc() > 1) ? intval(argv(1)) : 0); + if($menu_id) { + $_REQUEST['menu_id'] = intval(argv(1)); + $r = menu_edit($_REQUEST); + if($r) { + info( t('Menu updated.') . EOL); + goaway(z_root() . '/mitem/' . $menu_id); + } + else + notice( t('Unable to update menu.'). EOL); + } + else { + $r = menu_create($_REQUEST); + if($r) { + info( t('Menu created.') . EOL); + goaway(z_root() . '/mitem/' . $r); + } + else + notice( t('Unable to create menu.'). EOL); + + } + +} + + +function menu_content(&$a) { + + if(! local_user()) { + notice( t('Permission denied.') . EOL); + return ''; + } + + +// $a->set_widget('design',design_tools()); + + + if(argc() == 1) { + // list menus + $x = menu_list(local_user()); + + $o = replace_macros(get_markup_template('menulist.tpl'),array( + '$title' => t('Manage Menus'), + '$menus' => $x, + '$edit' => t('Edit'), + '$drop' => t('Drop'), + '$new' => t('New'), + '$hintnew' => t('Create a new menu'), + '$hintdrop' => t('Delete this menu'), + '$hintcontent' => t('Edit menu contents'), + '$hintedit' => t('Edit this menu') + )); + + return $o; + + + + + + } + + + if(argc() > 1) { + if(argv(1) === 'new') { + $o = replace_macros(get_markup_template('menuedit.tpl'), array( + '$header' => t('New Menu'), + '$menu_name' => array('menu_name', t('Menu name'), '', t('Must be unique, only seen by you'), '*'), + '$menu_desc' => array('menu_desc', t('Menu title'), '', t('Menu title as seen by others'), ''), + '$menu_bookmark' => array('menu_bookmark', t('Allow bookmarks'), 0 , t('Menu may be used to store saved bookmarks'), ''), + '$submit' => t('Create') + )); + return $o; + } + + elseif(intval(argv(1))) { + $m = menu_fetch_id(intval(argv(1)),local_user()); + if(! $m) { + notice( t('Menu not found.') . EOL); + return ''; + } + if(argc() == 3 && argv(2) == 'drop') { + $r = menu_delete_id(intval(argv(1)),local_user()); + if($r) + info( t('Menu deleted.') . EOL); + else + notice( t('Menu could not be deleted.'). EOL); + + goaway(z_root() . '/menu'); + } + else { + $o = replace_macros(get_markup_template('menuedit.tpl'), array( + '$header' => t('Edit Menu'), + '$menu_id' => intval(argv(1)), + '$hintedit' => t('Add or remove entries to this menu'), + '$editcontents' => t('Edit menu contents'), + '$menu_name' => array('menu_name', t('Menu name'), $m['menu_name'], t('Must be unique, only seen by you'), '*'), + '$menu_desc' => array('menu_desc', t('Menu title'), $m['menu_desc'], t('Menu title as seen by others'), ''), + '$menu_bookmark' => array('menu_bookmark', t('Allow bookmarks'), (($m['menu_flags'] & MENU_BOOKMARK) ? 1 : 0), t('Menu may be used to store saved bookmarks'), ''), + '$menu_system' => (($m['menu_flags'] & MENU_SYSTEM) ? 1 : 0), + '$submit' => t('Modify') + )); + return $o; + } + } + else { + notice( t('Not found.') . EOL); + return; + } + } + +} diff --git a/mod/message.php b/mod/message.php index 98a1067ed..c14bf2161 100644 --- a/mod/message.php +++ b/mod/message.php @@ -7,186 +7,6 @@ require_once("include/bbcode.php"); require_once('include/Contact.php'); -function message_aside(&$a) { - - $a->set_widget('newmessage',replace_macros(get_markup_template('message_side.tpl'), array( - '$tabs'=> array(), - '$new'=>array( - 'label' => t('New Message'), - 'url' => $a->get_baseurl(true) . '/message/new', - 'sel'=> (argv(1) == 'new'), - ) - ))); - -} - -function message_post(&$a) { - - if(! local_user()) - return; - - $replyto = ((x($_REQUEST,'replyto')) ? notags(trim($_REQUEST['replyto'])) : ''); - $subject = ((x($_REQUEST,'subject')) ? notags(trim($_REQUEST['subject'])) : ''); - $body = ((x($_REQUEST,'body')) ? escape_tags(trim($_REQUEST['body'])) : ''); - $recipient = ((x($_REQUEST,'messageto')) ? notags(trim($_REQUEST['messageto'])) : ''); - $rstr = ((x($_REQUEST,'messagerecip')) ? notags(trim($_REQUEST['messagerecip'])) : ''); - - // If we have a raw string for a recipient which hasn't been auto-filled, - // it means they probably aren't in our address book, hence we don't know - // if we have permission to send them private messages. - // finger them and find out before we try and send it. - - if(! $recipient) { - $channel = $a->get_channel(); - - $ret = zot_finger($rstr,$channel); - - if(! $ret) { - notice( t('Unable to lookup recipient.') . EOL); - return; - } - $j = json_decode($ret['body'],true); - - logger('message_post: lookup: ' . $url . ' ' . print_r($j,true)); - - if(! ($j['success'] && $j['guid'])) { - notice( t('Unable to communicate with requested channel.')); - return; - } - - $x = import_xchan($j); - - if(! $x['success']) { - notice( t('Cannot verify requested channel.')); - return; - } - - $recipient = $x['hash']; - - $their_perms = 0; - - $global_perms = get_perms(); - - if($j['permissions']['data']) { - $permissions = aes_unencapsulate($j['permissions'],$channel['channel_prvkey']); - if($permissions) - $permissions = json_decode($permissions); - logger('decrypted permissions: ' . print_r($permissions,true), LOGGER_DATA); - } - else - $permissions = $j['permissions']; - - foreach($permissions as $k => $v) { - if($v) { - $their_perms = $their_perms | intval($global_perms[$k][1]); - } - } - - if(! ($their_perms & PERMS_W_MAIL)) { - notice( t('Selected channel has private message restrictions. Send failed.')); - return; - } - } - - if(feature_enabled(local_user(),'richtext')) { - $body = fix_mce_lf($body); - } - - if(! $recipient) { - notice('No recipient found.'); - $a->argc = 2; - $a->argv[1] = 'new'; - return; - } - - // We have a local_user, let send_message use the session channel and save a lookup - - $ret = send_message(0, $recipient, $body, $subject, $replyto); - - if(! $ret['success']) { - notice($ret['message']); - } - -} - -// Note: the code in 'item_extract_images' and 'item_redir_and_replace_images' -// is identical to the code in include/conversation.php -if(! function_exists('item_extract_images')) { -function item_extract_images($body) { - - $saved_image = array(); - $orig_body = $body; - $new_body = ''; - - $cnt = 0; - $img_start = strpos($orig_body, '[img'); - $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false); - $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false); - while(($img_st_close !== false) && ($img_end !== false)) { - - $img_st_close++; // make it point to AFTER the closing bracket - $img_end += $img_start; - - if(! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) { - // This is an embedded image - - $saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - ($img_start + $img_st_close)); - $new_body = $new_body . substr($orig_body, 0, $img_start) . '[!#saved_image' . $cnt . '#!]'; - - $cnt++; - } - else - $new_body = $new_body . substr($orig_body, 0, $img_end + strlen('[/img]')); - - $orig_body = substr($orig_body, $img_end + strlen('[/img]')); - - if($orig_body === false) // in case the body ends on a closing image tag - $orig_body = ''; - - $img_start = strpos($orig_body, '[img'); - $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false); - $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false); - } - - $new_body = $new_body . $orig_body; - - return array('body' => $new_body, 'images' => $saved_image); -}} - -if(! function_exists('item_redir_and_replace_images')) { -function item_redir_and_replace_images($body, $images, $cid) { - - $origbody = $body; - $newbody = ''; - - for($i = 0; $i < count($images); $i++) { - $search = '/\[url\=(.*?)\]\[!#saved_image' . $i . '#!\]\[\/url\]' . '/is'; - $replace = '[url=' . z_path() . '/redir/' . $cid - . '?f=1&url=' . '$1' . '][!#saved_image' . $i . '#!][/url]' ; - - $img_end = strpos($origbody, '[!#saved_image' . $i . '#!][/url]') + strlen('[!#saved_image' . $i . '#!][/url]'); - $process_part = substr($origbody, 0, $img_end); - $origbody = substr($origbody, $img_end); - - $process_part = preg_replace($search, $replace, $process_part); - $newbody = $newbody . $process_part; - } - $newbody = $newbody . $origbody; - - $cnt = 0; - foreach($images as $image) { - // We're depending on the property of 'foreach' (specified on the PHP website) that - // it loops over the array starting from the first element and going sequentially - // to the last element - $newbody = str_replace('[!#saved_image' . $cnt . '#!]', '[img]' . $image . '[/img]', $newbody); - $cnt++; - } - - return $newbody; -}} - - - function message_content(&$a) { $o = ''; @@ -194,10 +14,17 @@ function message_content(&$a) { if(! local_user()) { notice( t('Permission denied.') . EOL); - return; + return login(); } $channel = $a->get_channel(); + head_set_icon($channel['xchan_photo_s']); + + $cipher = get_pconfig(local_user(),'system','default_cipher'); + if(! $cipher) + $cipher = 'aes256'; + + $tpl = get_markup_template('mail_head.tpl'); $header = replace_macros($tpl, array( @@ -205,93 +32,15 @@ function message_content(&$a) { '$tab_content' => $tab_content )); - if((argc() == 3) && (argv(1) === 'drop' || argv(1) === 'dropconv')) { + if((argc() == 3) && (argv(1) === 'dropconv')) { if(! intval(argv(2))) return; $cmd = argv(1); - if($cmd === 'drop') { - $r = private_messages_drop(local_user(), argv(2)); - if($r) { - info( t('Message deleted.') . EOL ); - } - goaway($a->get_baseurl(true) . '/message' ); - } - else { - $r = private_messages_drop(local_user(), argv(2), true); - if($r) - info( t('Conversation removed.') . EOL ); - goaway($a->get_baseurl(true) . '/message' ); - } - } - - - if((argc() > 1) && ($a->argv[1] === 'new')) { - - $o .= $header; - - $plaintext = false; - if(intval(get_pconfig(local_user(),'system','plaintext'))) - $plaintext = true; - if(! feature_enabled(local_user(),'richtext')) - $plaintext = true; - - $tpl = get_markup_template('msg-header.tpl'); - - $a->page['htmlhead'] .= replace_macros($tpl, array( - '$baseurl' => $a->get_baseurl(true), - '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'), - '$nickname' => $channel['channel_addr'], - '$linkurl' => t('Please enter a link URL:') - )); - - $preselect = (isset($a->argv[2])?array($a->argv[2]):false); - - - $prename = $preurl = $preid = ''; - - 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_user()), - intval(argv(2)) - ); - if($r) { - $prename = $r[0]['xchan_name']; - $preurl = $r[0]['xchan_url']; - $preid = $r[0]['abook_id']; - } - } - - $prefill = (($preselect) ? $prename : ''); - - // 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( - '$header' => t('Send Private Message'), - '$to' => t('To:'), - '$showinputs' => 'true', - '$prefill' => $prefill, - '$autocomp' => $autocomp, - '$preid' => $preid, - '$subject' => t('Subject:'), - '$subjtxt' => ((x($_REQUEST,'subject')) ? strip_tags($_REQUEST['subject']) : ''), - '$text' => ((x($_REQUEST,'body')) ? escape_tags(htmlspecialchars($_REQUEST['body'])) : ''), - '$readonly' => '', - '$yourmessage' => t('Your message:'), - '$select' => $select, - '$parent' => '', - '$upload' => t('Upload photo'), - '$insert' => t('Insert web link'), - '$wait' => t('Please wait'), - '$submit' => t('Submit') - )); - - return $o; + $r = private_messages_drop(local_user(), argv(2), true); + if($r) + info( t('Conversation removed.') . EOL ); + goaway($a->get_baseurl(true) . '/message' ); } - if(argc() == 1) { // list messages @@ -330,99 +79,5 @@ function message_content(&$a) { return $o; } - if((argc() > 1) && (intval(argv(1)))) { - - $o .= $header; - - $plaintext = true; - if( local_user() && feature_enabled(local_user(),'richtext') ) - $plaintext = false; - - $messages = private_messages_fetch_conversation(local_user(), argv(1), true); - - if(! $messages) { - info( t('Message not found.') . EOL); - return $o; - } - - - $tpl = get_markup_template('msg-header.tpl'); - - $a->page['htmlhead'] .= replace_macros($tpl, array( - '$nickname' => $channel['channel_addr'], - '$baseurl' => $a->get_baseurl(true), - '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'), - '$linkurl' => t('Please enter a link URL:') - )); - - - $mails = array(); - $seen = 0; - $unknown = false; - - foreach($messages as $message) { - -// FIXME -// $extracted = item_extract_images($message['body']); -// if($extracted['images']) -// $message['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $message['contact-id']); - - $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'])), - 'delete' => t('Delete message'), - 'date' => datetime_convert('UTC',date_default_timezone_get(),$message['created'],'D, d M Y - g:i A'), - ); - - $seen = $message['seen']; - - } - - logger('mails: ' . print_r($mails,true), LOGGER_DATA); - - $recp = (($message['from_xchan'] === $channel['channel_hash']) ? 'to' : 'from'); - -// FIXME - move this HTML to template - - $select = $message[$recp]['xchan_name'] . '<input type="hidden" name="messageto" value="' . $message[$recp]['xchan_hash'] . '" />'; - $parent = '<input type="hidden" name="replyto" value="' . $message['parent_uri'] . '" />'; - - $tpl = get_markup_template('mail_display.tpl'); - $o = replace_macros($tpl, array( - '$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, - - // 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'), - '$insert' => t('Insert web link'), - '$submit' => t('Submit'), - '$wait' => t('Please wait') - - )); - - return $o; - } } diff --git a/mod/mitem.php b/mod/mitem.php new file mode 100644 index 000000000..e0aa1b87a --- /dev/null +++ b/mod/mitem.php @@ -0,0 +1,197 @@ +<?php + +require_once('include/menu.php'); +require_once('include/acl_selectors.php'); + +function mitem_init(&$a) { + if(! local_user()) + return; + if(argc() < 2) + return; + + $m = menu_fetch_id(intval(argv(1)),local_user()); + if(! $m) { + notice( t('Menu not found.') . EOL); + return ''; + } + $a->data['menu'] = $m; + +} + +function mitem_post(&$a) { + + if(! local_user()) + return; + + if(! $a->data['menu']) + return; + + + $channel = $a->get_channel(); + + $_REQUEST['mitem_channel_id'] = local_user(); + $_REQUEST['menu_id'] = $a->data['menu']['menu_id']; + + $_REQUEST['mitem_flags'] = 0; + if($_REQUEST['usezid']) + $_REQUEST['mitem_flags'] |= MENU_ITEM_ZID; + if($_REQUEST['newwin']) + $_REQUEST['mitem_flags'] |= MENU_ITEM_NEWWIN; + + + $mitem_id = ((argc() > 2) ? intval(argv(2)) : 0); + if($mitem_id) { + $_REQUEST['mitem_id'] = $mitem_id; + $r = menu_edit_item($_REQUEST['menu_id'],local_user(),$_REQUEST); + if($r) { + info( t('Menu element updated.') . EOL); + goaway(z_root() . '/mitem/' . $_REQUEST['menu_id']); + } + else + notice( t('Unable to update menu element.') . EOL); + + } + else { + $r = menu_add_item($_REQUEST['menu_id'],local_user(),$_REQUEST); + if($r) { + info( t('Menu element added.') . EOL); + goaway(z_root() . '/mitem/' . $_REQUEST['menu_id']); + } + else + notice( t('Unable to add menu element.') . EOL); + + } + + + +} + + +function mitem_content(&$a) { + + if(! local_user()) { + notice( t('Permission denied.') . EOL); + return ''; + } + + if(argc() < 2 || (! $a->data['menu'])) { + notice( t('Not found.') . EOL); + return ''; + } + + $channel = $a->get_channel(); + + $m = menu_fetch($a->data['menu']['menu_name'],local_user(), get_observer_hash()); + $a->data['menu_item'] = $m; + + + if(argc() == 2) { + $r = q("select * from menu_item where mitem_menu_id = %d and mitem_channel_id = %d order by mitem_order asc, mitem_desc asc", + intval($a->data['menu']['menu_id']), + local_user() + ); + + + $o .= replace_macros(get_markup_template('mitemlist.tpl'),array( + '$title' => t('Manage Menu Elements'), + '$menuname' => $a->data['menu']['menu_name'], + '$menudesc' => $a->data['menu']['menu_desc'], + '$edmenu' => t('Edit menu'), + '$menu_id' => $a->data['menu']['menu_id'], + '$mlist' => $r, + '$edit' => t('Edit element'), + '$drop' => t('Drop element'), + '$new' => t('New element'), + '$hintmenu' => t('Edit this menu container'), + '$hintnew' => t('Add menu element'), + '$hintdrop' => t('Delete this menu item'), + '$hintedit' => t('Edit this menu item') + )); + + + return $o; + + } + + + if(argc() > 2) { + + + + if(argv(2) === 'new') { + + $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'] + ); + + $o = replace_macros(get_markup_template('mitemedit.tpl'), array( + '$header' => t('New Menu Element'), + '$menu_id' => $a->data['menu']['menu_id'], + '$permissions' => t('Menu Item Permissions'), + '$permdesc' => t("\x28click to open/close\x29"), + '$aclselect' => populate_acl($perm_defaults), + '$mitem_desc' => array('mitem_desc', t('Link text'), '', '','*'), + '$mitem_link' => array('mitem_link', t('URL of link'), '', '', '*'), + '$usezid' => array('usezid', t('Use Red magic-auth if available'), true, ''), + '$newwin' => array('newwin', t('Open link in new window'), false,''), +// permissions go here + '$mitem_order' => array('mitem_order', t('Order in list'),'0',t('Higher numbers will sink to bottom of listing')), + '$submit' => t('Create') + )); + return $o; + } + + + elseif(intval(argv(2))) { + $m = q("select * from menu_item where mitem_id = %d and mitem_channel_id = %d limit 1", + intval(argv(2)), + intval(local_user()) + ); + if(! $m) { + notice( t('Menu item not found.') . EOL); + goaway(z_root() . '/menu'); + } + + $mitem = $m[0]; + + if(argc() == 4 && argv(3) == 'drop') { + $r = menu_del_item($mitem['mitem_menu_id'], local_user(),intval(argv(2))); + if($r) + info( t('Menu item deleted.') . EOL); + else + notice( t('Menu item could not be deleted.'). EOL); + + goaway(z_root() . '/mitem/' . $mitem['mitem_menu_id']); + } + else { + + // edit menu item + + $o = replace_macros(get_markup_template('mitemedit.tpl'), array( + '$header' => t('Edit Menu Element'), + '$menu_id' => $a->data['menu']['menu_id'], + '$permissions' => t('Menu Item Permissions'), + '$permdesc' => t("\x28click to open/close\x29"), + '$aclselect' => populate_acl($mitem), + '$mitem_id' => intval(argv(2)), + '$mitem_desc' => array('mitem_desc', t('Link text'), $mitem['mitem_desc'], '','*'), + '$mitem_link' => array('mitem_link', t('URL of link'), $mitem['mitem_link'], '', '*'), + '$usezid' => array('usezid', t('Use Red magic-auth if available'), (($mitem['mitem_flags'] & MENU_ITEM_ZID) ? 1 : 0), ''), + '$newwin' => array('newwin', t('Open link in new window'), (($mitem['mitem_flags'] & MENU_ITEM_NEWWIN) ? 1 : 0),''), +// permissions go here + '$mitem_order' => array('mitem_order', t('Order in list'),$mitem['mitem_order'],t('Higher numbers will sink to bottom of listing')), + '$submit' => t('Modify') + )); + return $o; + } + } + + } + + + + +} diff --git a/mod/mood.php b/mod/mood.php index 98064beab..5075f622d 100755 --- a/mod/mood.php +++ b/mod/mood.php @@ -11,6 +11,7 @@ function mood_init(&$a) { return; $uid = local_user(); + $channel = $a->get_channel(); $verb = notags(trim($_GET['verb'])); if(! $verb) @@ -30,15 +31,15 @@ function mood_init(&$a) { if($parent) { - $r = q("select uri, owner_xchan, private, allow_cid, allow_gid, deny_cid, deny_gid + $r = q("select mid, owner_xchan, private, allow_cid, allow_gid, deny_cid, deny_gid from item where id = %d and parent = %d and uid = %d limit 1", intval($parent), intval($parent), intval($uid) ); if(count($r)) { - $parent_uri = $r[0]['uri']; - $private = $r[0]['private']; + $parent_mid = $r[0]['mid']; + $private = $r[0]['item_private']; $allow_cid = $r[0]['allow_cid']; $allow_gid = $r[0]['allow_gid']; $deny_cid = $r[0]['deny_cid']; @@ -48,7 +49,6 @@ function mood_init(&$a) { else { $private = 0; - $channel = $a->get_channel(); $allow_cid = $channel['channel_allow_cid']; $allow_gid = $channel['channel_allow_gid']; @@ -58,11 +58,11 @@ function mood_init(&$a) { $poster = $a->get_observer(); - $uri = item_message_id(); + $mid = item_message_id(); - $action = sprintf( t('%1$s is currently %2$s'), '[url=' . $poster['xchan_url'] . ']' . $poster['xchan_name'] . '[/url]' , $verbs[$verb]); + $action = sprintf( t('%1$s is currently %2$s'), '[zrl=' . $poster['xchan_url'] . ']' . $poster['xchan_name'] . '[/zrl]' , $verbs[$verb]); $item_flags = ITEM_WALL|ITEM_ORIGIN|ITEM_UNSEEN; - if(! $parent_uri) + if(! $parent_mid) $item_flags |= ITEM_THREAD_TOP; @@ -70,20 +70,28 @@ function mood_init(&$a) { $arr['aid'] = get_account_id(); $arr['uid'] = $uid; - $arr['uri'] = $uri; - $arr['parent_uri'] = (($parent_uri) ? $parent_uri : $uri); + $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_uri) ? $r[0]['owner_xchan'] : $poster['xchan_hash']); + $arr['owner_xchan'] = (($parent_mid) ? $r[0]['owner_xchan'] : $poster['xchan_hash']); $arr['title'] = ''; $arr['allow_cid'] = $allow_cid; $arr['allow_gid'] = $allow_gid; $arr['deny_cid'] = $deny_cid; $arr['deny_gid'] = $deny_gid; + $arr['item_private'] = $private; $arr['verb'] = $activity; $arr['body'] = $action; - $item_id = item_store($arr); + if ((! $arr['plink']) && ($arr['item_flags'] & ITEM_THREAD_TOP)) { + $arr['plink'] = z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . $arr['mid']; + } + + + $post = item_store($arr); + $item_id = $post['item_id']; + if($item_id) { // q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1", // dbesc($a->get_baseurl() . '/display/' . $poster['nickname'] . '/' . $item_id), diff --git a/mod/network.php b/mod/network.php index dae9fa6be..8202b1044 100644 --- a/mod/network.php +++ b/mod/network.php @@ -1,243 +1,26 @@ <?php require_once('include/items.php'); +require_once('include/group.php'); +require_once('include/contact_widgets.php'); +require_once('include/conversation.php'); +require_once('include/acl_selectors.php'); + function network_init(&$a) { if(! local_user()) { notice( t('Permission denied.') . EOL); return; } - - $is_a_date_query = false; - - if($a->argc > 1) { - for($x = 1; $x < $a->argc; $x ++) { - if(is_a_date_arg($a->argv[$x])) { - $is_a_date_query = true; - break; - } - } - } - - // convert query string to array and remove first element (wich is friendica args) - $query_array = array(); - parse_str($a->query_string, $query_array); - array_shift($query_array); - - // fetch last used tab and redirect if needed - $sel_tabs = network_query_get_sel_tab($a); - $last_sel_tabs = get_pconfig(local_user(), 'network.view','tab.selected'); - if (is_array($last_sel_tabs)){ - $tab_urls = array( - '/network?f=&order=comment',//all - '/network?f=&order=post', //postord - '/network?f=&conv=1', //conv - '/network/new', //new - '/network?f=&star=1', //starred - '/network?f=&spam=1', //spam - ); - - // redirect if current selected tab is 'no_active' and - // last selected tab is _not_ 'all_active'. - // and this isn't a date query - - if ($sel_tabs[0] == 'active' && $last_sel_tabs[0]!='active' && (! $is_a_date_query)) { - $k = array_search('active', $last_sel_tabs); - - // merge tab querystring with request querystring - $dest_qa = array(); - list($dest_url,$dest_qs) = explode("?", $tab_urls[$k]); - parse_str( $dest_qs, $dest_qa); - $dest_qa = array_merge($query_array, $dest_qa); - $dest_qs = build_querystring($dest_qa); - - // groups filter is in form of "network/nnn". Add it to $dest_url, if it's possible - if ($a->argc==2 && is_numeric($a->argv[1]) && strpos($dest_url, "/",1)===false){ - $dest_url .= "/".$a->argv[1]; - } - -// goaway($a->get_baseurl() . $dest_url."?".$dest_qs); - } - } - - $group_id = ((x($_GET,'gid')) ? intval($_GET['gid']) : 0); - - require_once('include/group.php'); - require_once('include/contact_widgets.php'); - require_once('include/items.php'); - - if(! x($a->page,'aside')) - $a->page['aside'] = ''; - - $search = ((x($_GET,'search')) ? $_GET['search'] : ''); - - if(x($_GET,'save')) { - $r = q("select * from `term` where `uid` = %d and `type` = %d and `term` = '%s' limit 1", - intval(local_user()), - intval(TERM_SAVEDSEARCH), - dbesc($search) - ); - if(! count($r)) { - q("insert into `term` ( `uid`,`type`,`term` ) values ( %d, %d, '%s') ", - intval(local_user()), - intval(TERM_SAVEDSEARCH), - dbesc($search) - ); - } - } - if(x($_GET,'remove')) { - q("delete from `term` where `uid` = %d and `type` = %d and `term` = '%s' limit 1", - intval(local_user()), - intval(TERM_SAVEDSEARCH), - dbesc($search) - ); - } - - $a->page['aside'] .= group_side('network','network',true,$group_id); - $a->page['aside'] .= posted_date_widget($a->get_baseurl() . '/network',local_user(),false); - - $a->page['aside'] .= saved_searches($search); - $a->page['aside'] .= fileas_widget($a->get_baseurl(true) . '/network',(x($_GET, 'file') ? $_GET['file'] : '')); - - $base = $a->get_baseurl(); - - $a->page['htmlhead'] .= <<< EOT - -<script>$(document).ready(function() { - var a; - a = $("#search-text").autocomplete({ - serviceUrl: '$base/search_ac', - minChars: 2, - width: 350, - }); -}); -</script> -EOT; - - - -} - -function saved_searches($search) { - - if(! feature_enabled(local_user(),'savedsearch')) - return ''; - - $a = get_app(); - - $srchurl = '/network?f=' - . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : '') - . ((x($_GET,'star')) ? '&star=' . $_GET['star'] : '') - . ((x($_GET,'conv')) ? '&conv=' . $_GET['conv'] : '') - . ((x($_GET,'cmin')) ? '&cmin=' . $_GET['cmin'] : '') - . ((x($_GET,'cmax')) ? '&cmax=' . $_GET['cmax'] : '') - . ((x($_GET,'file')) ? '&file=' . $_GET['file'] : ''); - ; - - $o = ''; - - $r = q("select `tid`,`term` from `term` WHERE `uid` = %d and `type` = %d ", - intval(local_user()), - intval(TERM_SAVEDSEARCH) - ); - - $saved = array(); - - if(count($r)) { - foreach($r as $rr) { - $saved[] = array( - 'id' => $rr['tid'], - 'term' => $rr['term'], - 'displayterm' => htmlspecialchars($rr['term']), - 'encodedterm' => urlencode($rr['term']), - 'delete' => t('Remove term'), - 'selected' => ($search==$rr['term']), - ); - } - } - - - $tpl = get_markup_template("saved_searches_aside.tpl"); - $o = replace_macros($tpl, array( - '$title' => t('Saved Searches'), - '$add' => t('add'), - '$searchbox' => search($search,'netsearch-box',$srchurl,true), - '$saved' => $saved, - )); - - return $o; - -} - -/** - * Return selected tab from query - * - * urls -> returns - * '/network' => $no_active = 'active' - * '/network?f=&order=comment' => $comment_active = 'active' - * '/network?f=&order=post' => $postord_active = 'active' - * '/network?f=&conv=1', => $conv_active = 'active' - * '/network/new', => $new_active = 'active' - * '/network?f=&star=1', => $starred_active = 'active' - * '/network?f=&spam=1', => $spam_active = 'active' - * - * @return Array ( $no_active, $comment_active, $postord_active, $conv_active, $new_active, $starred_active, $spam_active ); - */ -function network_query_get_sel_tab($a) { - $no_active=''; - $starred_active = ''; - $new_active = ''; - $all_active = ''; - $search_active = ''; - $conv_active = ''; - $spam_active = ''; - $postord_active = ''; - - if(x($_GET,'new')) { - $new_active = 'active'; - } - - if(x($_GET,'search')) { - $search_active = 'active'; - } - - if(x($_GET,'star')) { - $starred_active = 'active'; - } - - if(x($_GET,'conv')) { - $conv_active = 'active'; - } - - if(x($_GET,'spam')) { - $spam_active = 'active'; - } - - - - if (($new_active == '') - && ($starred_active == '') - && ($conv_active == '') - && ($search_active == '') - && ($spam_active == '')) { - $no_active = 'active'; - } + $channel = $a->get_channel(); + $a->profile_uid = local_user(); + head_set_icon($channel['xchan_photo_s']); - if ($no_active=='active' && x($_GET,'order')) { - switch($_GET['order']){ - case 'post': $postord_active = 'active'; $no_active=''; break; - case 'comment' : $all_active = 'active'; $no_active=''; break; - } - } - - return array($no_active, $all_active, $postord_active, $conv_active, $new_active, $starred_active, $spam_active); } - function network_content(&$a, $update = 0, $load = false) { - require_once('include/conversation.php'); if(! local_user()) { $_SESSION['return_url'] = $a->query_string; @@ -245,13 +28,31 @@ function network_content(&$a, $update = 0, $load = false) { } - $arr = array('query' => $a->query_string); call_hooks('network_content_init', $arr); $channel = $a->get_channel(); + $search = (($_GET['search']) ? $_GET['search'] : ''); + if($search) { + if(strpos($search,'@') === 0) { + $r = q("select abook_id from abook left join xchan on abook_xchan = xchan_hash where xchan_name = '%s' and abook_channel = %d limit 1", + dbesc(substr($search,1)), + intval(local_user()) + ); + if($r) { + $_GET['cid'] = $r[0]['abook_id']; + $search = $_GET['search'] = ''; + } + } + elseif(strpos($search,'#') === 0) { + $search = $_GET['search'] = substr($search,1); + } + } + + + $datequery = $datequery2 = ''; $group = 0; @@ -268,84 +69,28 @@ function network_content(&$a, $update = 0, $load = false) { $_GET['order'] = 'post'; if($gid) { + $r = q("SELECT * FROM `groups` WHERE id = %d AND uid = %d LIMIT 1", + intval($gid), + intval(local_user()) + ); + if(! $r) { + if($update) + killme(); + notice( t('No such group') . EOL ); + goaway($a->get_baseurl(true) . '/network'); + // NOTREACHED + } + $group = $gid; - $def_acl = array('allow_gid' => '<' . $group . '>'); + $group_hash = $r[0]['hash']; + $def_acl = array('allow_gid' => '<' . $r[0]['hash'] . '>'); } $o = ''; - // item filter tabs - // TODO: fix this logic, reduce duplication - //$a->page['content'] .= '<div class="tabs-wrapper">'; - - list($no_active, $all_active, $postord_active, $conv_active, $new_active, $starred_active, $spam_active) = network_query_get_sel_tab($a); - // if no tabs are selected, defaults to comments - if ($no_active=='active') $all_active='active'; - //echo "<pre>"; var_dump($no_active, $all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active); killme(); - - $cmd = (($datequery) ? '' : $a->cmd); - $len_naked_cmd = strlen(str_replace('/new','',$cmd)); - - // tabs - $tabs = array( - array( - 'label' => t('Commented Order'), - 'url'=>$a->get_baseurl(true) . '/' . $cmd . '?f=&order=comment' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : ''), - 'sel'=>$all_active, - 'title'=> t('Sort by Comment Date'), - ), - array( - 'label' => t('Posted Order'), - 'url'=>$a->get_baseurl(true) . '/' . $cmd . '?f=&order=post' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : ''), - 'sel'=>$postord_active, - 'title' => t('Sort by Post Date'), - ), - - array( - 'label' => t('Personal'), - 'url' => $a->get_baseurl(true) . '/' . $cmd . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '') . '&conv=1', - 'sel' => $conv_active, - 'title' => t('Posts that mention or involve you'), - ), - array( - 'label' => t('New'), - 'url' => $a->get_baseurl(true) . '/' . $cmd . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '') . '&new=1', - 'sel' => $new_active, - 'title' => t('Activity Stream - by date'), - ), - - ); - - if(feature_enabled(local_user(),'star_posts')) - $tabs[] = array( - 'label' => t('Starred'), - 'url'=>$a->get_baseurl(true) . '/' . $cmd . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '') . '&star=1', - 'sel'=>$starred_active, - 'title' => t('Favourite Posts'), - ); - - // Not yet implemented - - if(feature_enabled(local_user(),'spam_filter')) - $tabs[] = array( - 'label' => t('Spam'), - 'url'=>$a->get_baseurl(true) . '/network?f=&spam=1', - 'sel'=> $spam_active, - 'title' => t('Posts flagged as SPAM'), - ); - - - - // save selected tab, but only if not in search or file mode - if(!x($_GET,'search') && !x($_GET,'file')) { - set_pconfig( local_user(), 'network.view','tab.selected',array($all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active) ); - } - - $contact_id = $a->cid; - - require_once('include/acl_selectors.php'); + // if no tabs are selected, defaults to comments $cid = ((x($_GET,'cid')) ? intval($_GET['cid']) : 0); $star = ((x($_GET,'star')) ? intval($_GET['star']) : 0); @@ -355,6 +100,7 @@ function network_content(&$a, $update = 0, $load = false) { $spam = ((x($_GET,'spam')) ? intval($_GET['spam']) : 0); $cmin = ((x($_GET,'cmin')) ? intval($_GET['cmin']) : 0); $cmax = ((x($_GET,'cmax')) ? intval($_GET['cmax']) : 99); + $firehose = ((x($_GET,'fh')) ? intval($_GET['fh']) : 0); $file = ((x($_GET,'file')) ? $_GET['file'] : ''); @@ -366,48 +112,31 @@ function network_content(&$a, $update = 0, $load = false) { if(! $update) { - - if(feature_enabled(local_user(),'affinity')) { - $tpl = get_markup_template('main_slider.tpl'); - $o .= replace_macros($tpl,array( - '$val' => intval($cmin) . ';' . intval($cmax), - '$refresh' => t('Refresh'), - '$me' => t('Me'), - '$intimate' => t('Best Friends'), - '$friends' => t('Friends'), - '$coworkers' => t('Co-workers'), - '$oldfriends' => t('Former Friends'), - '$acquaintances' => t('Acquaintances'), - '$world' => t('Everybody') - )); - } - - $arr = array('tabs' => $tabs); - call_hooks('network_tabs', $arr); - - $o .= replace_macros(get_markup_template('common_tabs.tpl'), array('$tabs'=> $arr['tabs'])); - - // --- end item filter tabs - + $o .= network_tabs(); // search terms header if($search) - $o .= '<h2>' . t('Search Results For:') . ' ' . htmlspecialchars($search) . '</h2>'; + $o .= '<h2>' . t('Search Results For:') . ' ' . htmlspecialchars($search, ENT_COMPAT,'UTF-8') . '</h2>'; nav_set_selected('network'); - $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false); + $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'] + ); + $x = array( 'is_owner' => true, - 'allow_location' => $a->user['allow_location'], // FIXME + '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'), -// FIXME - 'acl' => populate_acl((($group || $cid || $nets) ? $def_acl : $channel), $celeb), + 'acl' => populate_acl((($group || $cid) ? $def_acl : $channel_acl)), 'bang' => (($group || $cid) ? '!' : ''), - 'visitor' => 'block', + 'visitor' => true, 'profile_uid' => local_user() ); @@ -430,45 +159,44 @@ function network_content(&$a, $update = 0, $load = false) { $sql_extra = " AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE (item_flags & " . intval(ITEM_THREAD_TOP) . ") $sql_options ) "; if($group) { - $r = q("SELECT `name`, `id` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1", - intval($group), - intval($_SESSION['uid']) - ); - if(! count($r)) { - if($update) - killme(); - notice( t('No such group') . EOL ); - goaway($a->get_baseurl(true) . '/network'); - // NOTREACHED - } + $contact_str = ''; + $contacts = group_get_members($group); + if($contacts) { + foreach($contacts as $c) { + if($contact_str) + $contact_str .= ','; + $contact_str .= "'" . $c['xchan'] . "'"; + } + } + else { + $contact_str = ' 0 '; + info( t('Collection is empty')); + } - $contacts = expand_groups(array($group)); - if((is_array($contacts)) && count($contacts)) { - $contact_str = implode(',',$contacts); - } - else { - $contact_str = ' 0 '; - info( t('Group 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 ) "; + + $x = group_rec_byhash(local_user(), $group_hash); + + if($x) + $o = '<h2>' . t('Collection: ') . $x['name'] . '</h2>' . $o; + + + } - $sql_extra = " AND `item`.`parent` IN ( SELECT DISTINCT(`parent`) FROM `item` WHERE 1 $sql_options AND ( `contact-id` IN ( $contact_str ) OR `allow_gid` like '" . protect_sprintf('%<' . intval($group) . '>%') . "' ) and deleted = 0 ) "; - $o = '<h2>' . t('Group: ') . $r[0]['name'] . '</h2>' . $o; - } elseif($cid) { - $r = q("SELECT `id`,`name`,`network`,`writable`,`nurl` FROM `contact` WHERE `id` = %d - AND `blocked` = 0 AND `pending` = 0 LIMIT 1", - intval($cid) - ); - if(count($r)) { - $sql_extra = " AND `item`.`parent` IN ( SELECT DISTINCT(`parent`) FROM `item` WHERE 1 $sql_options AND `contact-id` = " . intval($cid) . " and deleted = 0 ) "; - $o = '<h2>' . t('Contact: ') . $r[0]['name'] . '</h2>' . $o; - } - else { - notice( t('Invalid contact.') . EOL); + $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) . ") limit 1", + intval($cid), + intval(local_user()) + ); + if($r) { + $sql_extra = " AND item.parent IN ( SELECT DISTINCT parent FROM item WHERE true $sql_options AND uid = " . intval(local_user()) . " AND ( author_xchan = '" . dbesc($r[0]['abook_xchan']) . "' or owner_xchan = '" . dbesc($r[0]['abook_xchan']) . "' ) and item_restrict = 0 ) "; + $o = '<h2>' . t('Connection: ') . $r[0]['xchan_name'] . '</h2>' . $o; + } + else { + notice( t('Invalid connection.') . EOL); goaway($a->get_baseurl(true) . '/network'); - // NOTREACHED - } + } } @@ -491,10 +219,12 @@ function network_content(&$a, $update = 0, $load = false) { . ((x($_GET,'cmin')) ? '&cmin=' . $_GET['cmin'] : '') . ((x($_GET,'cmax')) ? '&cmax=' . $_GET['cmax'] : '') . ((x($_GET,'file')) ? '&file=' . $_GET['file'] : '') + . ((x($_GET,'fh')) ? '&fh=' . $_GET['fh'] : '') . "'; var profile_page = " . $a->pager['page'] . ";</script>"; + $a->page['htmlhead'] .= replace_macros(get_markup_template("build_query.tpl"),array( '$baseurl' => z_root(), '$pgtype' => 'network', @@ -507,15 +237,17 @@ function network_content(&$a, $update = 0, $load = false) { '$liked' => (($liked) ? $liked : '0'), '$conv' => (($conv) ? $conv : '0'), '$spam' => (($spam) ? $spam : '0'), + '$fh' => (($firehose) ? $firehose : '0'), '$nouveau' => (($nouveau) ? $nouveau : '0'), '$wall' => '0', + '$list' => ((x($_REQUEST,'list')) ? intval($_REQUEST['list']) : 0), '$page' => (($a->pager['page'] != 1) ? $a->pager['page'] : 1), - '$search' => $search, + '$search' => (($search) ? $search : ''), '$order' => $order, '$file' => $file, '$cats' => '', '$dend' => $datequery, - '$uri' => '', + '$mid' => '', '$dbegin' => $datequery2 )); } @@ -587,6 +319,17 @@ function network_content(&$a, $update = 0, $load = false) { } + if($firehose && (! get_config('system','disable_discover_tab'))) { + require_once('include/identity.php'); + $sys = get_sys_channel(); + $uids = " and item.uid = " . intval($sys['channel_id']) . " "; + $a->data['firehose'] = intval($sys['channel_id']); + } + else { + $uids = " and item.uid = " . local_user() . " "; + } + + $simple_update = (($update) ? " and ( item.item_flags & " . intval(ITEM_UNSEEN) . " ) " : ''); if($load) $simple_update = ''; @@ -597,11 +340,10 @@ function network_content(&$a, $update = 0, $load = false) { // "New Item View" - show all items unthreaded in reverse created date order $items = q("SELECT `item`.*, `item`.`id` AS `item_id` FROM `item` - WHERE `item`.`uid` = %d AND item_restrict = 0 + WHERE true $uids AND item_restrict = 0 $simple_update $sql_extra $sql_nets - ORDER BY `item`.`received` DESC $pager_sql ", - intval($_SESSION['uid']) + ORDER BY `item`.`received` DESC $pager_sql " ); require_once('include/items.php'); @@ -625,42 +367,42 @@ function network_content(&$a, $update = 0, $load = false) { $r = q("SELECT distinct item.id AS item_id FROM item left join abook on item.author_xchan = abook.abook_xchan - WHERE item.uid = %d AND item.item_restrict = 0 + WHERE true $uids AND item.item_restrict = 0 AND item.parent = item.id and ((abook.abook_flags & %d) = 0 or abook.abook_flags is null) $sql_extra3 $sql_extra $sql_nets ORDER BY item.$ordering DESC $pager_sql ", - intval(local_user()), intval(ABOOK_FLAG_BLOCKED) ); } else { - // update - $r = q("SELECT item.parent AS item_id FROM item - left join abook on item.author_xchan = abook.abook_xchan - WHERE item.uid = %d 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(local_user()), - intval(ABOOK_FLAG_BLOCKED) - ); - + if(! $firehose) { + // update + $r = q("SELECT item.parent AS item_id FROM item + left join abook on item.author_xchan = abook.abook_xchan + 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) + ); + } } $first = dba_timer(); // Then fetch all the children of the parents that are on this page + $parents_str = ''; + $update_unseen = ''; if($r) { $parents_str = ids_to_querystr($r,'item_id'); $items = q("SELECT `item`.*, `item`.`id` AS `item_id` FROM `item` - WHERE `item`.`uid` = %d AND `item`.`item_restrict` = 0 + WHERE true $uids AND `item`.`item_restrict` = 0 AND `item`.`parent` IN ( %s ) $sql_extra ", - intval(local_user()), dbesc($parents_str) ); @@ -692,7 +434,7 @@ function network_content(&$a, $update = 0, $load = false) { // logger('items: ' . count($items)); - if($update_unseen) + if(($update_unseen) && (! $firehose)) $r = q("UPDATE `item` SET item_flags = ( item_flags ^ %d) WHERE (item_flags & %d) AND `uid` = %d $update_unseen ", intval(ITEM_UNSEEN), @@ -709,10 +451,12 @@ function network_content(&$a, $update = 0, $load = false) { $sixth = dba_timer(); - if(! $update) + if(($items) && (! $update)) $o .= alt_pager($a,count($items)); if($load) { +// logger('mod_network: load: ' . count($items) . ' items', LOGGER_DATA); + profiler($start,$first,'network parents'); profiler($first,$second,'network children'); profiler($second,$third,'network authors'); diff --git a/mod/nogroup.php b/mod/nogroup.php deleted file mode 100644 index bd1ec82ed..000000000 --- a/mod/nogroup.php +++ /dev/null @@ -1,65 +0,0 @@ -<?php - -require_once('include/Contact.php'); -require_once('include/socgraph.php'); -require_once('include/contact_selectors.php'); - -function nogroup_init(&$a) { - - if(! local_user()) - return; - - require_once('include/group.php'); - require_once('include/contact_widgets.php'); - - if(! x($a->page,'aside')) - $a->page['aside'] = ''; - - $a->page['aside'] .= group_side('contacts','group',false,0,$contact_id); -} - - -function nogroup_content(&$a) { - - if(! local_user()) { - notice( t('Permission denied.') . EOL); - return ''; - } - - require_once('include/Contact.php'); - $r = contacts_not_grouped(local_user()); - if(count($r)) { - $a->set_pager_total($r[0]['total']); - } - $r = contacts_not_grouped(local_user(),$a->pager['start'],$a->pager['itemspage']); - if(count($r)) { - foreach($r as $rr) { - - - $contacts[] = array( - 'img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']), - 'edit_hover' => t('Edit contact'), - 'photo_menu' => contact_photo_menu($rr), - 'id' => $rr['id'], - 'alt_text' => $alt_text, - 'dir_icon' => $dir_icon, - 'thumb' => $rr['thumb'], - 'name' => $rr['name'], - 'username' => $rr['name'], - 'sparkle' => $sparkle, - 'itemurl' => $rr['url'], - 'url' => $url, - 'network' => network_to_name($rr['network']), - ); - } - } - $tpl = get_markup_template("nogroup-template.tpl"); - $o .= replace_macros($tpl,array( - '$header' => t('Contacts who are not members of a group'), - '$contacts' => $contacts, - '$paginate' => paginate($a), - )); - - return $o; - -} diff --git a/mod/notes.php b/mod/notes.php new file mode 100644 index 000000000..e21e4386c --- /dev/null +++ b/mod/notes.php @@ -0,0 +1,24 @@ +<?php /** @file */ + +function notes_init(&$a) { + if(! local_user()) + return; + logger('mod_notes: ' . print_r($_REQUEST,true)); + + $ret = array('success' => true); + if($_REQUEST['note_text'] || $_REQUEST['note_text'] == '') { + $body = escape_tags($_REQUEST['note_text']); + set_pconfig(local_user(),'notes','text',$body); + } + + // push updates to channel clones + + if((argc() > 1) && (argv(1) === 'sync')) { + require_once('include/zot.php'); + build_sync_packet(); + } + + logger('notes saved.'); + json_return_and_die($ret); + +} diff --git a/mod/notifications.php b/mod/notifications.php index 7d861037c..09f89e88a 100644 --- a/mod/notifications.php +++ b/mod/notifications.php @@ -70,242 +70,7 @@ function notifications_content(&$a) { nav_set_selected('notifications'); $o = ''; - $tabs = array( - array( - 'label' => t('System'), - 'url'=>$a->get_baseurl(true) . '/notifications/system', - 'sel'=> (($a->argv[1] == 'system') ? 'active' : ''), - ), - array( - 'label' => t('Network'), - 'url'=>$a->get_baseurl(true) . '/notifications/network', - 'sel'=> (($a->argv[1] == 'network') ? 'active' : ''), - ), - array( - 'label' => t('Personal'), - 'url'=>$a->get_baseurl(true) . '/notifications/personal', - 'sel'=> (($a->argv[1] == 'personal') ? 'active' : ''), - ), - array( - 'label' => t('Home'), - 'url' => $a->get_baseurl(true) . '/notifications/home', - 'sel'=> (($a->argv[1] == 'home') ? 'active' : ''), - ), - array( - 'label' => t('Introductions'), - 'url' => $a->get_baseurl(true) . '/notifications/intros', - 'sel'=> (($a->argv[1] == 'intros') ? 'active' : ''), - ), - array( - 'label' => t('Messages'), - 'url' => $a->get_baseurl(true) . '/message', - 'sel'=> '', - ), - ); - - $o = ""; - - - if( (($a->argc > 1) && ($a->argv[1] == 'intros')) || (($a->argc == 1))) { - nav_set_selected('introductions'); - if(($a->argc > 2) && ($a->argv[2] == 'all')) - $sql_extra = ''; - else - $sql_extra = " AND `ignore` = 0 "; - - $notif_tpl = get_markup_template('notifications.tpl'); - - $notif_content .= '<a href="' . ((strlen($sql_extra)) ? 'notifications/intros/all' : 'notifications/intros' ) . '" id="notifications-show-hide-link" >' - . ((strlen($sql_extra)) ? t('Show Ignored Requests') : t('Hide Ignored Requests')) . '</a></div>' . "\r\n"; - - $r = q("SELECT COUNT(*) AS `total` FROM `intro` - WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ", - intval($_SESSION['uid']) - ); - if($r && count($r)) { - $a->set_pager_total($r[0]['total']); - $a->set_pager_itemspage(20); - } - - $r = q("SELECT `intro`.`id` AS `intro_id`, `intro`.*, `contact`.*, `fcontact`.`name` AS `fname`,`fcontact`.`url` AS `furl`,`fcontact`.`photo` AS `fphoto`,`fcontact`.`request` AS `frequest` - FROM `intro` LEFT JOIN `contact` ON `contact`.`id` = `intro`.`contact-id` LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id` - WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ", - intval($_SESSION['uid'])); - - if(($r !== false) && (count($r))) { - - $sugg = get_markup_template('suggestions.tpl'); - $tpl = get_markup_template("intros.tpl"); - - foreach($r as $rr) { - if($rr['fid']) { - $return_addr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname() . (($a->path) ? '/' . $a->path : '')); - $notif_content .= replace_macros($sugg,array( - '$str_notifytype' => t('Notification type: '), - '$notify_type' => t('Friend Suggestion'), - '$intro_id' => $rr['intro_id'], - '$madeby' => sprintf( t('suggested by %s'),$rr['name']), - '$contact_id' => $rr['contact-id'], - '$photo' => ((x($rr,'fphoto')) ? $rr['fphoto'] : "images/person-175.jpg"), - '$fullname' => $rr['fname'], - '$url' => zid($rr['furl']), - '$hidden' => array('hidden', t('Hide this contact from others'), ($rr['hidden'] == 1), ''), - '$activity' => array('activity', t('Post a new friend activity'), (intval(get_pconfig(local_user(),'system','post_newfriend')) ? '1' : 0), t('if applicable')), - - '$knowyou' => $knowyou, - '$approve' => t('Approve'), - '$note' => $rr['note'], - '$request' => $rr['frequest'] . '?addr=' . $return_addr, - '$ignore' => t('Ignore'), - '$discard' => t('Discard') - - )); - - continue; - - } - $friend_selected = (($rr['network'] !== NETWORK_OSTATUS) ? ' checked="checked" ' : ' disabled '); - $fan_selected = (($rr['network'] === NETWORK_OSTATUS) ? ' checked="checked" disabled ' : ''); - $dfrn_tpl = get_markup_template('netfriend.tpl'); - - $knowyou = ''; - $dfrn_text = ''; - - if($rr['network'] === NETWORK_DFRN || $rr['network'] === NETWORK_DIASPORA) { - if($rr['network'] === NETWORK_DFRN) - $knowyou = t('Claims to be known to you: ') . (($rr['knowyou']) ? t('yes') : t('no')); - else - $knowyou = ''; - $dfrn_text = replace_macros($dfrn_tpl,array( - '$intro_id' => $rr['intro_id'], - '$friend_selected' => $friend_selected, - '$fan_selected' => $fan_selected, - '$approve_as' => t('Approve as: '), - '$as_friend' => t('Friend'), - '$as_fan' => (($rr['network'] == NETWORK_DIASPORA) ? t('Sharer') : t('Fan/Admirer')) - )); - } - - $notif_content .= replace_macros($tpl,array( - '$str_notifytype' => t('Notification type: '), - '$notify_type' => (($rr['network'] !== NETWORK_OSTATUS) ? t('Friend/Connect Request') : t('New Follower')), - '$dfrn_text' => $dfrn_text, - '$dfrn_id' => $rr['issued_id'], - '$uid' => $_SESSION['uid'], - '$intro_id' => $rr['intro_id'], - '$contact_id' => $rr['contact-id'], - '$photo' => ((x($rr,'photo')) ? $rr['photo'] : "images/person-175.jpg"), - '$fullname' => $rr['name'], - '$hidden' => array('hidden', t('Hide this contact from others'), ($rr['hidden'] == 1), ''), - '$activity' => array('activity', t('Post a new friend activity'), (intval(get_pconfig(local_user(),'system','post_newfriend')) ? '1' : 0), t('if applicable')), - '$url' => zid($rr['url']), - '$knowyou' => $knowyou, - '$approve' => t('Approve'), - '$note' => $rr['note'], - '$ignore' => t('Ignore'), - '$discard' => t('Discard') - - )); - } - } - else - info( t('No introductions.') . EOL); - - $o .= replace_macros($notif_tpl,array( - '$notif_header' => t('Notifications'), - '$tabs' => $tabs, - '$notif_content' => $notif_content, - )); - - $o .= paginate($a); - return $o; - - } else if (($a->argc > 1) && ($a->argv[1] == 'network')) { - - $notif_tpl = get_markup_template('notifications.tpl'); - - $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, - `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`, - `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink` - FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent` - WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND - `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC" , - intval(local_user()) - ); - - $tpl_item_likes = get_markup_template('notifications_likes_item.tpl'); - $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl'); - $tpl_item_friends = get_markup_template('notifications_friends_item.tpl'); - $tpl_item_comments = get_markup_template('notifications_comments_item.tpl'); - $tpl_item_posts = get_markup_template('notifications_posts_item.tpl'); - - $notif_content = ''; - - if (count($r) > 0) { - - foreach ($r as $it) { - switch($it['verb']){ - case ACTIVITY_LIKE: - $notif_content .= replace_macros($tpl_item_likes,array( - '$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], - '$item_image' => $it['author-avatar'], - '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']), - '$item_when' => relative_date($it['created']) - )); - break; - - case ACTIVITY_DISLIKE: - $notif_content .= replace_macros($tpl_item_dislikes,array( - '$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], - '$item_image' => $it['author-avatar'], - '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']), - '$item_when' => relative_date($it['created']) - )); - break; - - case ACTIVITY_FRIEND: - - $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">"; - $obj = parse_xml_string($xmlhead.$it['object']); - $it['fname'] = $obj->title; - - $notif_content .= replace_macros($tpl_item_friends,array( - '$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], - '$item_image' => $it['author-avatar'], - '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']), - '$item_when' => relative_date($it['created']) - )); - break; - - default: - $item_text = (($it['id'] == $it['parent']) - ? sprintf( t("%s created a new post"), $it['author-name']) - : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname'])); - $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments); - - $notif_content .= replace_macros($tpl,array( - '$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], - '$item_image' => $it['author-avatar'], - '$item_text' => $item_text, - '$item_when' => relative_date($it['created']) - )); - } - } - - } else { - - $notif_content = t('No more network notifications.'); - } - - $o .= replace_macros($notif_tpl,array( - '$notif_header' => t('Network Notifications'), - '$tabs' => $tabs, - '$notif_content' => $notif_content, - )); - - } else if (($a->argc > 1) && ($a->argv[1] == 'system')) { - $notif_tpl = get_markup_template('notifications.tpl'); $not_tpl = get_markup_template('notify.tpl'); @@ -316,6 +81,7 @@ function notifications_content(&$a) { ); if (count($r) > 0) { + $notifications_available =1; foreach ($r as $it) { $notif_content .= replace_macros($not_tpl,array( '$item_link' => $a->get_baseurl(true).'/notify/view/'. $it['id'], @@ -330,187 +96,10 @@ function notifications_content(&$a) { $o .= replace_macros($notif_tpl,array( '$notif_header' => t('System Notifications'), - '$tabs' => $tabs, + '$notif_link_mark_seen' => t('Mark all system notifications seen'), '$notif_content' => $notif_content, + '$notifications_available' => $notifications_available, )); - } else if (($a->argc > 1) && ($a->argv[1] == 'personal')) { - - $notif_tpl = get_markup_template('notifications.tpl'); - - $myurl = $a->get_baseurl(true) . '/channel/'. $a->user['nickname']; - $myurl = substr($myurl,strpos($myurl,'://')+3); - $myurl = str_replace(array('www.','.'),array('','\\.'),$myurl); - $diasp_url = str_replace('/channel/','/u/',$myurl); - $sql_extra .= sprintf(" AND ( `item`.`author-link` regexp '%s' or `item`.`tag` regexp '%s' or `item`.`tag` regexp '%s' ) ", - dbesc($myurl . '$'), - dbesc($myurl . '\\]'), - dbesc($diasp_url . '\\]') - ); - - - $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, - `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`, - `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink` - FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent` - WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 - $sql_extra - AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC" , - intval(local_user()) - ); - - $tpl_item_likes = get_markup_template('notifications_likes_item.tpl'); - $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl'); - $tpl_item_friends = get_markup_template('notifications_friends_item.tpl'); - $tpl_item_comments = get_markup_template('notifications_comments_item.tpl'); - $tpl_item_posts = get_markup_template('notifications_posts_item.tpl'); - - $notif_content = ''; - - if (count($r) > 0) { - - foreach ($r as $it) { - switch($it['verb']){ - case ACTIVITY_LIKE: - $notif_content .= replace_macros($tpl_item_likes,array( - '$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], - '$item_image' => $it['author-avatar'], - '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']), - '$item_when' => relative_date($it['created']) - )); - break; - - case ACTIVITY_DISLIKE: - $notif_content .= replace_macros($tpl_item_dislikes,array( - '$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], - '$item_image' => $it['author-avatar'], - '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']), - '$item_when' => relative_date($it['created']) - )); - break; - - case ACTIVITY_FRIEND: - - $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">"; - $obj = parse_xml_string($xmlhead.$it['object']); - $it['fname'] = $obj->title; - - $notif_content .= replace_macros($tpl_item_friends,array( - '$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], - '$item_image' => $it['author-avatar'], - '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']), - '$item_when' => relative_date($it['created']) - )); - break; - - default: - $item_text = (($it['id'] == $it['parent']) - ? sprintf( t("%s created a new post"), $it['author-name']) - : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname'])); - $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments); - - $notif_content .= replace_macros($tpl,array( - '$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], - '$item_image' => $it['author-avatar'], - '$item_text' => $item_text, - '$item_when' => relative_date($it['created']) - )); - } - } - - } else { - - $notif_content = t('No more personal notifications.'); - } - - $o .= replace_macros($notif_tpl,array( - '$notif_header' => t('Personal Notifications'), - '$tabs' => $tabs, - '$notif_content' => $notif_content, - )); - - - - - - - } else if (($a->argc > 1) && ($a->argv[1] == 'home')) { - - $notif_tpl = get_markup_template('notifications.tpl'); - - $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, - `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`, - `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink` - FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent` - WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND - `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1 ORDER BY `item`.`created` DESC", - intval(local_user()) - ); - - $tpl_item_likes = get_markup_template('notifications_likes_item.tpl'); - $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl'); - $tpl_item_friends = get_markup_template('notifications_friends_item.tpl'); - $tpl_item_comments = get_markup_template('notifications_comments_item.tpl'); - - $notif_content = ''; - - if (count($r) > 0) { - - foreach ($r as $it) { - switch($it['verb']){ - case ACTIVITY_LIKE: - $notif_content .= replace_macros($tpl_item_likes,array( - '$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], - '$item_image' => $it['author-avatar'], - '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']), - '$item_when' => relative_date($it['created']) - )); - - break; - case ACTIVITY_DISLIKE: - $notif_content .= replace_macros($tpl_item_dislikes,array( - '$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], - '$item_image' => $it['author-avatar'], - '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']), - '$item_when' => relative_date($it['created']) - )); - - break; - case ACTIVITY_FRIEND: - - $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">"; - $obj = parse_xml_string($xmlhead.$it['object']); - $it['fname'] = $obj->title; - - $notif_content .= replace_macros($tpl_item_friends,array( - '$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], - '$item_image' => $it['author-avatar'], - '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']), - '$item_when' => relative_date($it['created']) - )); - - break; - default: - $notif_content .= replace_macros($tpl_item_comments,array( - '$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], - '$item_image' => $it['author-avatar'], - '$item_text' => sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']), - '$item_when' => relative_date($it['created']) - )); - } - } - - } else { - $notif_content = t('No more home notifications.'); - } - - $o .= replace_macros($notif_tpl,array( - '$notif_header' => t('Home Notifications'), - '$tabs' => $tabs, - '$notif_content' => $notif_content, - )); - } - - $o .= paginate($a); return $o; } diff --git a/mod/notify.php b/mod/notify.php index 23ba098b7..6ee4260ce 100644 --- a/mod/notify.php +++ b/mod/notify.php @@ -11,7 +11,7 @@ function notify_init(&$a) { intval(local_user()) ); if($r) { - q("update notify set seen = 1 where ( link = '%s' or ( parent != 0 and parent = %d and otype = '%s' )) and uid = %d", + q("update notify set seen = 1 where ( link = '%s' or ( parent != '' and parent = '%s' and otype = '%s' )) and uid = %d", dbesc($r[0]['link']), intval($r[0]['parent']), dbesc($r[0]['otype']), diff --git a/mod/oembed.php b/mod/oembed.php index 720a6d72b..a053a8c98 100644 --- a/mod/oembed.php +++ b/mod/oembed.php @@ -19,8 +19,7 @@ function oembed_init(&$a){ else { echo "<html><body>"; - $url = base64url_decode($argv(1)); - $j = oembed_fetch_url($url); + $j = oembed_fetch_url(base64url_decode(argv(1))); echo $j->html; // logger('mod-oembed ' . $j->html, LOGGER_ALL); echo "</body></html>"; diff --git a/mod/oexchange.php b/mod/oexchange.php index 791a493ff..27c8b388d 100644 --- a/mod/oexchange.php +++ b/mod/oexchange.php @@ -15,6 +15,21 @@ function oexchange_init(&$a) { function oexchange_content(&$a) { if(! local_user()) { + if(remote_user()) { + $observer = $a->get_observer(); + if($observer && $observer['xchan_url']) { + $parsed = @parse_url($observer['xchan_url']); + if(! $parsed) { + notice( t('Unable to find your hub.') . EOL); + return; + } + $url = $parsed['scheme'] . '://' . $parsed['host'] . (($parsed['port']) ? ':' . $parsed['port'] : ''); + $url .= '/oexchange'; + $result = z_post_url($url,$_REQUEST); + json_return_and_die($result); + } + } + return login(false); } @@ -32,18 +47,19 @@ function oexchange_content(&$a) { $tags = (((x($_REQUEST,'tags')) && strlen($_REQUEST['tags'])) ? '&tags=' . urlencode(notags(trim($_REQUEST['tags']))) : ''); - $s = fetch_url($a->get_baseurl() . '/parse_url?f=&url=' . $url . $title . $description . $tags); + $ret = z_fetch_url($a->get_baseurl() . '/parse_url?f=&url=' . $url . $title . $description . $tags); + + if($ret['success']) + $s = $ret['body']; if(! strlen($s)) return; - require_once('include/html2bbcode.php'); - $post = array(); $post['profile_uid'] = local_user(); $post['return'] = '/oexchange/done' ; - $post['body'] = html2bbcode($s); + $post['body'] = $s; $post['type'] = 'wall'; $_REQUEST = $post; diff --git a/mod/online.php b/mod/online.php new file mode 100644 index 000000000..c6500347a --- /dev/null +++ b/mod/online.php @@ -0,0 +1,11 @@ +<?php /** @file */ + +function online_init(&$a) { + + $ret = array('result' => false); + if(argc() != 2) + json_return_and_die($ret); + + $ret = get_online_status(argv(1)); + json_return_and_die($ret); +} diff --git a/mod/openid.php b/mod/openid.php new file mode 100644 index 000000000..2112e0af4 --- /dev/null +++ b/mod/openid.php @@ -0,0 +1,191 @@ +<?php + + +require_once('library/openid/openid.php'); +require_once('include/auth.php'); + +function openid_content(&$a) { + + $noid = get_config('system','disable_openid'); + if($noid) + goaway(z_root()); + + logger('mod_openid ' . print_r($_REQUEST,true), LOGGER_DATA); + + if(x($_REQUEST,'openid_mode')) { + + $openid = new LightOpenID(z_root()); + + if($openid->validate()) { + + logger('openid: validate'); + + $authid = normalise_openid($_REQUEST['openid_identity']); + + if(! strlen($authid)) { + logger( t('OpenID protocol error. No ID returned.') . EOL); + goaway(z_root()); + } + + $x = match_openid($authid); + if($x) { + + $r = q("select * from channel where channel_id = %d limit 1", + intval($x) + ); + if($r) { + $y = q("select * from account where account_id = %d limit 1", + intval($r[0]['channel_account_id']) + ); + if($y) { + foreach($y as $record) { + if(($record['account_flags'] == ACCOUNT_OK) || ($record['account_flags'] == ACCOUNT_UNVERIFIED)) { + logger('mod_openid: openid success for ' . $x[0]['channel_name']); + $_SESSION['uid'] = $r[0]['channel_id']; + $_SESSION['account_id'] = $r[0]['channel_account_id']; + $_SESSION['authenticated'] = true; + authenticate_success($record,true,true,true,true); + goaway(z_root()); + } + } + } + } + } + + // Successful OpenID login - but we can't match it to an existing account. + // See if they've got an xchan + + $r = q("select * from xconfig left join xchan on xchan_hash = xconfig.xchan where cat = 'system' and k = 'openid' and v = '%s' limit 1", + dbesc($authid) + ); + + if($r) { + $_SESSION['authenticated'] = 1; + $_SESSION['visitor_id'] = $r[0]['xchan_hash']; + $_SESSION['my_url'] = $r[0]['xchan_url']; + $_SESSION['my_address'] = $r[0]['xchan_addr']; + $arr = array('xchan' => $r[0], 'session' => $_SESSION); + call_hooks('magic_auth_openid_success',$arr); + $a->set_observer($r[0]); + require_once('include/security.php'); + $a->set_groups(init_groups_visitor($_SESSION['visitor_id'])); + info(sprintf( t('Welcome %s. Remote authentication successful.'),$r[0]['xchan_name'])); + logger('mod_openid: remote auth success from ' . $r[0]['xchan_addr']); + if($_SESSION['return_url']) + goaway($_SESSION['return_url']); + goaway(z_root()); + } + + // no xchan... + // create one. + // We should probably probe the openid url and figure out if they have any kind of social presence we might be able to + // scrape some identifying info from. + + $name = $authid; + $url = trim($_REQUEST['openid_identity'],'/'); + if(strpos($url,'http') === false) + $url = 'https://' . $url; + $pphoto = get_default_profile_photo(); + $parsed = @parse_url($url); + if($parsed) { + $host = $parsed['host']; + } + + $attr = $openid->getAttributes(); + + if(is_array($attr) && count($attr)) { + foreach($attr as $k => $v) { + if($k === 'namePerson/friendly') + $nick = notags(trim($v)); + if($k === 'namePerson/first') + $first = notags(trim($v)); + if($k === 'namePerson') + $name = notags(trim($v)); + if($k === 'contact/email') + $addr = notags(trim($v)); + if($k === 'media/image/aspect11') + $photosq = trim($v); + if($k === 'media/image/default') + $photo_other = trim($v); + } + } + if(! $nick) { + if($first) + $nick = $first; + else + $nick = $name; + } + + require_once('library/urlify/URLify.php'); + $x = strtolower(URLify::transliterate($nick)); + if($nick & $host) + $addr = $nick . '@' . $host; + $network = 'unknown'; + + if($photosq) + $pphoto = $photosq; + elseif($photo_other) + $pphoto = $photo_other; + + $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) ", + dbesc($url), + dbesc(''), + dbesc(''), + dbesc(''), + dbesc('image/jpeg'), + dbesc($pphoto), + dbesc($addr), + dbesc($url), + dbesc(''), + dbesc(''), + dbesc(''), + dbesc($name), + dbesc($network), + dbesc(datetime_convert()), + dbesc(datetime_convert()), + intval(XCHAN_FLAGS_HIDDEN) + ); + if($x) { + $r = q("select * from xchan where xchan_hash = '%s' limit 1", + dbesc($url) + ); + if($r) { + + $photos = import_profile_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' limit 1", + dbesc(datetime_convert()), + dbesc($photos[0]), + dbesc($photos[1]), + dbesc($photos[2]), + dbesc($photos[3]), + dbesc($url) + ); + } + + set_xconfig($url,'system','openid',$authid); + $_SESSION['authenticated'] = 1; + $_SESSION['visitor_id'] = $r[0]['xchan_hash']; + $_SESSION['my_url'] = $r[0]['xchan_url']; + $_SESSION['my_address'] = $r[0]['xchan_addr']; + $arr = array('xchan' => $r[0], 'session' => $_SESSION); + call_hooks('magic_auth_openid_success',$arr); + $a->set_observer($r[0]); + info(sprintf( t('Welcome %s. Remote authentication successful.'),$r[0]['xchan_name'])); + logger('mod_openid: remote auth success from ' . $r[0]['xchan_addr']); + if($_SESSION['return_url']) + goaway($_SESSION['return_url']); + goaway(z_root()); + } + } + + } + } + notice( t('Login failed.') . EOL); + goaway(z_root()); + // NOTREACHED +} diff --git a/mod/page.php b/mod/page.php index 62f9d9204..df17dbf52 100644 --- a/mod/page.php +++ b/mod/page.php @@ -2,9 +2,35 @@ require_once('include/items.php'); require_once('include/conversation.php'); +require_once('include/page_widgets.php'); + +function page_init(&$a) { + // We need this to make sure the channel theme is always loaded. + + $which = argv(1); + $profile = 0; + profile_load($a,$which,$profile); + + if($a->profile['profile_uid']) + head_set_icon($a->profile['thumb']); + +} + + + function page_content(&$a) { + $observer = $a->get_observer(); + $ob_hash = (($observer) ? $observer['xchan_hash'] : ''); + + $perms = get_all_perms($a->profile['profile_uid'],$ob_hash); + + if(! $perms['view_pages']) { + notice( t('Permission denied.') . EOL); + return; + } + if(argc() < 3) { notice( t('Invalid item.') . EOL); return; @@ -22,23 +48,71 @@ function page_content(&$a) { return; } + if($_REQUEST['rev']) + $revision = " and revision = " . intval($_REQUEST['rev']) . " "; + else + $revision = " order by revision desc "; + + require_once('include/security.php'); + $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 limit 1", + item_restrict = %d $sql_options $revision limit 1", intval($u[0]['channel_id']), dbesc($page_id), intval(ITEM_WEBPAGE) ); if(! $r) { - notice( t('Item not found.') . EOL); + + // Check again with no permissions clause to see if it is a permissions issue + + $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", + intval($u[0]['channel_id']), + dbesc($page_id), + intval(ITEM_WEBPAGE) + ); + if($x) { + // Yes, it's there. You just aren't allowed to see it. + notice( t('Permission denied.') . EOL); + } + else { + notice( t('Page not found.') . EOL); + } return; } + if($r[0]['layout_mid']) { + $l = q("select body from item where mid = '%s' and uid = %d limit 1", + dbesc($r[0]['layout_mid']), + intval($u[0]['channel_id']) + ); + + if($l) { + require_once('include/comanche.php'); + comanche_parser(get_app(),$l[0]['body']); + } + } + + + // logger('layout: ' . print_r($a->layout,true)); + + // Use of widgets should be determined by Comanche, but we don't have it on system pages yet, so... + + if ($perms['write_pages']) { + $chan = $a->channel['channel_id']; + $who = $channel_address; + $which = $r[0]['id']; + $o .= writepages_widget($who,$which); + } + xchan_query($r); $r = fetch_post_tags($r,true); - $a->profile = array('profile_uid' => $u[0]['channel_id']); + $o .= prepare_page($r[0]); return $o; -}
\ No newline at end of file +} diff --git a/mod/parse_url.php b/mod/parse_url.php index 600d3dc8b..340e1a67e 100644 --- a/mod/parse_url.php +++ b/mod/parse_url.php @@ -55,34 +55,18 @@ function completeurl($url, $scheme) { function parseurl_getsiteinfo($url) { $siteinfo = array(); - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_HEADER, 1); - curl_setopt($ch, CURLOPT_NOBODY, 0); - curl_setopt($ch, CURLOPT_TIMEOUT, 3); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch,CURLOPT_USERAGENT,'Opera/9.64(Windows NT 5.1; U; de) Presto/2.1.1'); - - $header = curl_exec($ch); - curl_close($ch); - - // Fetch the first mentioned charset. Can be in body or header - if (preg_match('/charset=(.*?)['."'".'"\s\n]/', $header, $matches)) - $charset = trim(array_pop($matches)); - else - $charset = "utf-8"; - $pos = strpos($header, "\r\n\r\n"); + $result = z_fetch_url($url,false,0,array('novalidate' => true)); + if(! $result['success']) + return $siteinfo; - if ($pos) - $body = trim(substr($header, $pos)); - else - $body = $header; + $header = $result['header']; + $body = $result['body']; - $body = mb_convert_encoding($body, "UTF-8", $charset); - $body = mb_convert_encoding($body, 'HTML-ENTITIES', "UTF-8"); + $body = mb_convert_encoding($body, 'UTF-8', 'UTF-8'); + $body = mb_convert_encoding($body, 'HTML-ENTITIES', "UTF-8"); - $doc = new DOMDocument(); + $doc = new DOMDocument(); @$doc->loadHTML($body); deletenode($doc, 'style'); @@ -115,6 +99,9 @@ function parseurl_getsiteinfo($url) { $attr["content"] = html_entity_decode($attr["content"], ENT_QUOTES, "UTF-8"); switch (strtolower($attr["name"])) { + case 'generator': + $siteinfo['generator'] = $attr['content']; + break; case "fulltitle": $siteinfo["title"] = $attr["content"]; break; @@ -245,6 +232,10 @@ function parse_url_content(&$a) { 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'])); @@ -261,7 +252,7 @@ function parse_url_content(&$a) { logger('parse_url: ' . $url); - $template = $br . '[url=%s]%s[/url]%s' . $br; + $template = $br . '#^[url=%s]%s[/url]%s' . $br; $arr = array('url' => $url, 'text' => ''); @@ -290,6 +281,11 @@ function parse_url_content(&$a) { $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'],RED_PLATFORM . ' ') === 0)) + $template = str_replace('url','zrl',$template); + if($siteinfo["title"] == "") { echo sprintf($template,$url,$url,'') . $str_tags; killme(); diff --git a/mod/pdledit.php b/mod/pdledit.php new file mode 100644 index 000000000..36b9a0c14 --- /dev/null +++ b/mod/pdledit.php @@ -0,0 +1,62 @@ +<?php + +function pdledit_post(&$a) { + if(! local_user()) + return; + if(! $_REQUEST['module']) + return; + if(! trim($_REQUEST['content'])) { + del_pconfig(local_user(),'system','mod_' . $_REQUEST['module'] . '.pdl'); + goaway(z_root() . '/pdledit/' . $_REQUEST['module']); + } + set_pconfig(local_user(),'system','mod_' . $_REQUEST['module'] . '.pdl',escape_tags($_REQUEST['content'])); + info( t('Layout updated.') . EOL); + goaway(z_root() . '/pdledit/' . $_REQUEST['module']); +} + + +function pdledit_content(&$a) { + + if(! local_user()) { + notice( t('Permission denied.') . EOL); + return; + } + + if(argc() > 1) + $module = 'mod_' . argv(1) . '.pdl'; + else { + $o .= '<h1>' . t('Edit System Page Description') . '</h1>'; + $files = glob('mod/*'); + if($files) { + foreach($files as $f) { + $name = basename($f,'.php'); + $x = theme_include('mod_' . $name . '.pdl'); + if($x) { + $o .= '<a href="pdledit/' . $name . '" >' . $name . '</a><br />'; + } + } + } + + // list module pdl files + return $o; + } + + $t = get_pconfig(local_user(),'system',$module); + if(! $t) + $t = file_get_contents(theme_include($module)); + if(! $t) { + notice( t('Layout not found.') . EOL); + return ''; + } + + $o = replace_macros(get_markup_template('pdledit.tpl'),array( + '$header' => t('Edit System Page Description'), + '$mname' => t('Module Name:'), + '$help' => t('Layout Help'), + '$module' => argv(1), + '$content' => htmlspecialchars($t,ENT_COMPAT,'UTF-8'), + '$submit' => t('Submit') + )); + + return $o; +} diff --git a/mod/photo.php b/mod/photo.php index aff4dc895..9302278b6 100644 --- a/mod/photo.php +++ b/mod/photo.php @@ -1,7 +1,7 @@ <?php require_once('include/security.php'); -require_once('include/Photo.php'); +require_once('include/photo/photo_driver.php'); function photo_init(&$a) { @@ -22,9 +22,17 @@ 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 = 'images/person-175.jpg'; + $default = get_default_profile_photo(); if(isset($type)) { @@ -38,11 +46,11 @@ function photo_init(&$a) { case 'm': $resolution = 5; - $default = 'images/person-80.jpg'; + $default = get_default_profile_photo(80); break; case 's': $resolution = 6; - $default = 'images/person-48.jpg'; + $default = get_default_profile_photo(48); break; case 'l': default: @@ -72,6 +80,22 @@ function photo_init(&$a) { * Other photos */ + /* Check for a cookie to indicate display pixel density, in order to detect high-resolution + displays. This procedure was derived from the "Retina Images" by Jeremey Worboys, + used in accordance with the Creative Commons Attribution 3.0 Unported License. + Project link: https://github.com/Retina-Images/Retina-Images + License link: http://creativecommons.org/licenses/by/3.0/ + */ + $cookie_value = false; + if (isset($_COOKIE['devicePixelRatio'])) { + $cookie_value = intval($_COOKIE['devicePixelRatio']); + } + else { + // Force revalidation of cache on next request + $cache_directive = 'no-cache'; + $status = 'no cookie'; + } + $resolution = 0; if(strpos($photo,'.') !== false) @@ -80,7 +104,23 @@ function photo_init(&$a) { if(substr($photo,-2,1) == '-') { $resolution = intval(substr($photo,-1,1)); $photo = substr($photo,0,-2); + // If viewing on a high-res screen, attempt to serve a higher resolution image: + if ($resolution == 2 && ($cookie_value > 1)) + { + $resolution = 1; + } } + + // If using resolution 1, make sure it exists before proceeding: + if ($resolution == 1) + { + $r = q("SELECT uid FROM photo WHERE resource_id = '%s' AND scale = %d LIMIT 1", + dbesc($photo), + intval($resolution) + ); + if (!($r)) + $resolution = 2; + } $r = q("SELECT uid FROM photo WHERE resource_id = '%s' AND scale = %d LIMIT 1", dbesc($photo), @@ -112,14 +152,18 @@ function photo_init(&$a) { // There won't be many completely unauthorised people seeing this because // they won't have the photo link, so there's a reasonable chance that the person // might be able to obtain permission to view it. - + $r = q("SELECT * FROM `photo` WHERE `resource_id` = '%s' AND `scale` = %d LIMIT 1", dbesc($photo), intval($resolution) ); + if($r) { - $data = file_get_contents('images/nosign.jpg'); - $mimetype = 'image/jpeg'; + logger('mod_photo: forbidden. ' . $a->query_string); + $observer = $a->get_observer(); + logger('mod_photo: observer = ' . (($observer) ? $observer['xchan_addr'] : '(not authenticated)')); + $data = file_get_contents('images/nosign.png'); + $mimetype = 'image/png'; $prvcachecontrol = true; } } @@ -131,15 +175,15 @@ function photo_init(&$a) { switch($resolution) { case 4: - $data = file_get_contents('images/person-175.jpg'); + $data = file_get_contents(get_default_profile_photo()); $mimetype = 'image/jpeg'; break; case 5: - $data = file_get_contents('images/person-80.jpg'); + $data = file_get_contents(get_default_profile_photo(80)); $mimetype = 'image/jpeg'; break; case 6: - $data = file_get_contents('images/person-48.jpg'); + $data = file_get_contents(get_default_profile_photo(48)); $mimetype = 'image/jpeg'; break; default: @@ -151,7 +195,7 @@ function photo_init(&$a) { } if(isset($res) && intval($res) && $res < 500) { - $ph = new Photo($data, $mimetype); + $ph = photo_factory($data, $mimetype); if($ph->is_valid()) { $ph->scaleImageSquare($res); $data = $ph->imageString(); diff --git a/mod/photos.php b/mod/photos.php index 90b2990aa..2740f91f9 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -1,5 +1,5 @@ <?php -require_once('include/Photo.php'); +require_once('include/photo/photo_driver.php'); require_once('include/photos.php'); require_once('include/items.php'); require_once('include/acl_selectors.php'); @@ -19,30 +19,24 @@ function photos_init(&$a) { if(argc() > 1) { $nick = argv(1); + + profile_load($a,$nick); + $channelx = channelx_by_nick($nick); if(! $channelx) return; - $a->data['channel'] = $channelx[0]; + $a->data['channel'] = $channelx; $observer = $a->get_observer(); $a->data['observer'] = $observer; $observer_xchan = (($observer) ? $observer['xchan_hash'] : ''); - $a->data['perms'] = get_all_perms($channelx[0]['channel_id'],$observer_xchan); - - - - $a->set_widget('vcard',vcard_from_xchan($a->data['channel'],$observer)); - - if($a->data['perms']['view_photos']) { - $a->data['albums'] = photos_albums_list($a->data['channel'],$observer); - $a->set_widget('photo_albums',photos_album_widget($a->data['channel'],$observer,$a->data['albums'])); - } + head_set_icon($a->data['channel']['xchan_photo_s']); - $a->page['htmlhead'] .= "<script> var ispublic = '" . t('everybody') . "';</script>" ; + $a->page['htmlhead'] .= "<script> var ispublic = '" . t('everybody') . "'; var profile_uid = " . (($a->data['channel']) ? $a->data['channel']['channel_id'] : 0) . "; </script>" ; } @@ -59,7 +53,9 @@ function photos_post(&$a) { logger('mod_photos: REQUEST ' . print_r($_REQUEST,true), LOGGER_DATA); logger('mod_photos: FILES ' . print_r($_FILES,true), LOGGER_DATA); - $phototypes = Photo::supportedTypes(); + $ph = photo_factory(''); + + $phototypes = $ph->supportedTypes(); $can_post = false; @@ -161,36 +157,34 @@ function photos_post(&$a) { } if((argc() > 2) && (x($_REQUEST,'delete')) && ($_REQUEST['delete'] === t('Delete Photo'))) { -// FIXME + // same as above but remove single photo - if($visitor) { - $r = q("SELECT `id`, `resource_id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `resource_id` = '%s' LIMIT 1", - intval($visitor), - intval($page_owner_uid), - dbesc($a->argv[2]) - ); - } - else { - $r = q("SELECT `id`, `resource_id` FROM `photo` WHERE `uid` = %d AND `resource_id` = '%s' LIMIT 1", - intval(local_user()), - dbesc($a->argv[2]) - ); - } - if(count($r)) { + $ob_hash = get_observer_hash(); + if(! $ob_hash) + goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']); + + $r = q("SELECT `id`, `resource_id` FROM `photo` WHERE ( xchan = '%s' or `uid` = %d ) AND `resource_id` = '%s' LIMIT 1", + dbesc($ob_hash), + intval(local_user()), + dbesc($a->argv[2]) + ); + + if($r) { q("DELETE FROM `photo` WHERE `uid` = %d AND `resource_id` = '%s'", intval($page_owner_uid), dbesc($r[0]['resource_id']) ); - $i = q("SELECT * FROM `item` WHERE `resource_id` = '%s' AND `uid` = %d LIMIT 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 `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent_uri` = '%s' AND `uid` = %d", + 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]['uri']), + dbesc($i[0]['mid']), intval($page_owner_uid) ); @@ -203,7 +197,6 @@ function photos_post(&$a) { } goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']); - return; // NOTREACHED } if(($a->argc > 2) && ((x($_POST,'desc') !== false) || (x($_POST,'newtag') !== false)) || (x($_POST,'albname') !== false)) { @@ -233,7 +226,7 @@ function photos_post(&$a) { intval($page_owner_uid) ); if(count($r)) { - $ph = new Photo($r[0]['data'], $r[0]['type']); + $ph = photo_factory($r[0]['data'], $r[0]['type']); if($ph->is_valid()) { $rotate_deg = ( (intval($_POST['rotate']) == 1) ? 270 : 90 ); $ph->rotate($rotate_deg); @@ -280,13 +273,16 @@ function photos_post(&$a) { } } - $p = q("SELECT * FROM `photo` WHERE `resource_id` = '%s' AND `uid` = %d ORDER BY `scale` DESC", + $p = q("SELECT * FROM `photo` WHERE `resource_id` = '%s' AND `uid` = %d and ( photo_flags = %d or photo_flags = %d ) ORDER BY `scale` DESC", dbesc($resource_id), - intval($page_owner_uid) + intval($page_owner_uid), + intval(PHOTO_NORMAL), + intval(PHOTO_PROFILE) ); if(count($p)) { $ext = $phototypes[$p[0]['type']]; - $r = q("UPDATE `photo` SET `desc` = '%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', `album` = '%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), @@ -298,10 +294,13 @@ function photos_post(&$a) { ); } + $item_private = (($str_contact_allow || $str_group_allow || $str_contact_deny || $str_group_deny) ? true : false); + + /* Don't make the item visible if the only change was the album name */ $visibility = 0; - if($p[0]['desc'] !== $desc || strlen($rawtags)) + if($p[0]['description'] !== $desc || strlen($rawtags)) $visibility = 1; if(! $item_id) { @@ -315,209 +314,99 @@ function photos_post(&$a) { intval($page_owner_uid) ); } - if(count($r)) { + if($r) { $old_tag = $r[0]['tag']; $old_inform = $r[0]['inform']; } + // 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 limit 1", + dbesc($str_contact_allow), + dbesc($str_group_allow), + dbesc($str_contact_deny), + dbesc($str_group_deny), + intval($item_private), + intval($item_id) + ); + + if(strlen($rawtags)) { $str_tags = ''; $inform = ''; - // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag + // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a mention $x = substr($rawtags,0,1); if($x !== '@' && $x !== '#') - $rawtags = '#' . $rawtags; + $rawtags = '@' . $rawtags; $taginfo = array(); $tags = get_tags($rawtags); if(count($tags)) { foreach($tags as $tag) { - if(isset($profile)) - unset($profile); - if(strpos($tag,'@') === 0) { - $name = substr($tag,1); - if((strpos($name,'@')) || (strpos($name,'http://'))) { - $newname = $name; - $links = @lrdd($name); - if(count($links)) { - foreach($links as $link) { - if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') - $profile = $link['@attributes']['href']; - if($link['@attributes']['rel'] === 'salmon') { - $salmon = '$url:' . str_replace(',','%sc',$link['@attributes']['href']); - if(strlen($inform)) - $inform .= ','; - $inform .= $salmon; - } - } - } - $taginfo[] = array($newname,$profile,$salmon); + + // If we already tagged 'Robert Johnson', don't try and tag 'Robert'. + // Robert Johnson should be first in the $tags array + + $fullnametagged = false; + for($x = 0; $x < count($tagged); $x ++) { + if(stristr($tagged[$x],$tag . ' ')) { + $fullnametagged = true; + break; } - else { - $newname = $name; - $alias = ''; - $tagcid = 0; - if(strrpos($newname,'+')) - $tagcid = intval(substr($newname,strrpos($newname,'+') + 1)); - - if($tagcid) { - $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", - intval($tagcid), - intval($profile_uid) - ); - } - else { - $newname = str_replace('_',' ',$name); - - //select someone from this user's contacts by name - $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1", - dbesc($newname), - intval($page_owner_uid) - ); - - if(! $r) { - //select someone by attag or nick and the name passed in - $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1", - dbesc($name), - dbesc($name), - intval($page_owner_uid) - ); - } - } -/* elseif(strstr($name,'_') || strstr($name,' ')) { - $newname = str_replace('_',' ',$name); - $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1", - dbesc($newname), - intval($page_owner_uid) - ); - } - else { - $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1", - dbesc($name), - dbesc($name), - intval($page_owner_uid) - ); - }*/ - if(count($r)) { - $newname = $r[0]['name']; - $profile = $r[0]['url']; - $notify = 'cid:' . $r[0]['id']; - if(strlen($inform)) - $inform .= ','; - $inform .= $notify; - } + } + if($fullnametagged) + continue; + + require_once('mod/item.php'); + $body = $access_tag = ''; + + $success = handle_tag($a, $body, $access_tag, $str_tags, (local_user()) ? local_user() : $a->profile['profile_uid'] , $tag); + logger('handle_tag: ' . print_r($success,tue), LOGGER_DEBUG); + if($access_tag) { + logger('access_tag: ' . $tag . ' ' . print_r($access_tag,true), LOGGER_DEBUG); + if(strpos($access_tag,'cid:') === 0) { + $str_contact_allow .= '<' . substr($access_tag,4) . '>'; + $access_tag = ''; } - if($profile) { - if(substr($notify,0,4) === 'cid:') - $taginfo[] = array($newname,$profile,$notify,$r[0],'@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]'); - else - $taginfo[] = array($newname,$profile,$notify,null,$str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]'); - if(strlen($str_tags)) - $str_tags .= ','; - $profile = str_replace(',','%2c',$profile); - $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]'; + elseif(strpos($access_tag,'gid:') === 0) { + $str_group_allow .= '<' . substr($access_tag,4) . '>'; + $access_tag = ''; } } + + if($success['replaced']) { + $tagged[] = $tag; + $post_tags[] = array( + 'uid' => $a->profile['profile_uid'], + 'type' => $success['termtype'], + 'otype' => TERM_OBJ_POST, + 'term' => $success['term'], + 'url' => $success['url'] + ); + } } } - - $newtag = $old_tag; - if(strlen($newtag) && strlen($str_tags)) - $newtag .= ','; - $newtag .= $str_tags; - - $newinform = $old_inform; - if(strlen($newinform) && strlen($inform)) - $newinform .= ','; - $newinform .= $inform; - - $r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1", - dbesc($newtag), - dbesc($newinform), - dbesc(datetime_convert()), - dbesc(datetime_convert()), + + $r = q("select * from item where id = %d and uid = %d limit 1", intval($item_id), intval($page_owner_uid) ); - $best = 0; - foreach($p as $scales) { - if(intval($scales['scale']) == 2) { - $best = 2; - break; - } - if(intval($scales['scale']) == 4) { - $best = 4; - break; - } - } - - if(count($taginfo)) { - foreach($taginfo as $tagged) { - - $uri = item_message_id(); - - $arr = array(); - - $arr['uid'] = $page_owner_uid; - $arr['uri'] = $uri; - $arr['parent_uri'] = $uri; - $arr['type'] = 'activity'; - $arr['wall'] = 1; - $arr['contact-id'] = $owner_record['id']; - $arr['owner-name'] = $owner_record['name']; - $arr['owner-link'] = $owner_record['url']; - $arr['owner-avatar'] = $owner_record['thumb']; - $arr['author-name'] = $owner_record['name']; - $arr['author-link'] = $owner_record['url']; - $arr['author-avatar'] = $owner_record['thumb']; - $arr['title'] = ''; - $arr['allow_cid'] = $p[0]['allow_cid']; - $arr['allow_gid'] = $p[0]['allow_gid']; - $arr['deny_cid'] = $p[0]['deny_cid']; - $arr['deny_gid'] = $p[0]['deny_gid']; - $arr['visible'] = 1; - $arr['verb'] = ACTIVITY_TAG; - $arr['obj_type'] = ACTIVITY_OBJ_PERSON; - $arr['tgt_type'] = ACTIVITY_OBJ_PHOTO; - $arr['tag'] = $tagged[4]; - $arr['inform'] = $tagged[2]; - $arr['origin'] = 1; - $arr['body'] = sprintf( t('%1$s was tagged in %2$s by %3$s'), '[url=' . $tagged[1] . ']' . $tagged[0] . '[/url]', '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . ']' . t('a photo') . '[/url]', '[url=' . $owner_record['url'] . ']' . $owner_record['name'] . '[/url]') ; - - $arr['body'] .= "\n\n" . '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource_id'] . ']' . '[img]' . $a->get_baseurl() . "/photo/" . $p[0]['resource_id'] . '-' . $best . '.' . $ext . '[/img][/url]' . "\n" ; - - $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>'; - $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n"); - if($tagged[3]) - $arr['object'] .= xmlify('<link rel="photo" type="'.$p[0]['type'].'" href="' . $tagged[3]['photo'] . '" />' . "\n"); - $arr['object'] .= '</link></object>' . "\n"; - - $arr['target'] = '<target><type>' . ACTIVITY_OBJ_PHOTO . '</type><title>' . $p[0]['desc'] . '</title><id>' - . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource_id'] . '</id>'; - $arr['target'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource_id'] . '" />' . "\n" . '<link rel="preview" type="'.$p[0]['type'].'" href="' . $a->get_baseurl() . "/photo/" . $p[0]['resource_id'] . '-' . $best . '.' . $ext . '" />') . '</link></target>'; - - $item_id = item_store($arr); - if($item_id) { - q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1", - dbesc($a->get_baseurl() . '/display/' . $owner_record['nickname'] . '/' . $item_id), - intval($page_owner_uid), - intval($item_id) - ); - - proc_run('php',"include/notifier.php","tag","$item_id"); - } - } - + if($r) { + $datarray = $r[0]; + $datarray['term'] = $post_tags; + item_store_update($datarray,$execflag); } } + goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']); return; // NOTREACHED + } @@ -565,7 +454,8 @@ function photos_content(&$a) { return; } - $phototypes = Photo::supportedTypes(); + $ph = photo_factory(''); + $phototypes = $ph->supportedTypes(); $_SESSION['photo_return'] = $a->cmd; @@ -573,6 +463,8 @@ function photos_content(&$a) { // Parse arguments // + $can_comment = perm_is_allowed($a->profile['profile_uid'],get_observer_hash(),'post_comments'); + if(argc() > 3) { $datatype = argv(2); $datum = argv(3); @@ -593,85 +485,31 @@ function photos_content(&$a) { $can_post = false; $visitor = 0; - $contact = null; - $remote_contact = false; - $contact_id = 0; + $owner_uid = $a->data['channel']['channel_id']; $owner_aid = $a->data['channel']['channel_account_id']; - $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false); - - if((local_user()) && (local_user() == $owner_uid)) - $can_post = true; - else { - if($community_page && remote_user()) { - if(is_array($_SESSION['remote'])) { - foreach($_SESSION['remote'] as $v) { - if($v['uid'] == $owner_uid) { - $contact_id = $v['cid']; - break; - } - } - } - if($contact_id) { - - $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1", - intval($contact_id), - intval($owner_uid) - ); - if(count($r)) { - $can_post = true; - $contact = $r[0]; - $remote_contact = true; - $visitor = $cid; - } - } - } - } - - // perhaps they're visiting - but not a community page, so they wouldn't have write access + $observer = $a->get_observer(); - if(remote_user() && (! $visitor)) { - $contact_id = 0; - if(is_array($_SESSION['remote'])) { - foreach($_SESSION['remote'] as $v) { - if($v['uid'] == $owner_uid) { - $contact_id = $v['cid']; - break; - } - } - } - if($contact_id) { - $groups = init_groups_visitor($contact_id); - $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1", - intval($contact_id), - intval($owner_uid) - ); - if(count($r)) { - $contact = $r[0]; - $remote_contact = true; - } - } - } + $can_post = perm_is_allowed($owner_uid,$observer['xchan_hash'],'post_photos'); + $can_view = perm_is_allowed($owner_uid,$observer['xchan_hash'],'view_photos'); - if(! $remote_contact) { - if(local_user()) { - $contact_id = $_SESSION['cid']; - $contact = $a->contact; - } - } - if($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) { + if(! $can_view) { notice( t('Access to this item is restricted.') . EOL); return; } - $sql_extra = permissions_sql($owner_uid,$remote_contact,$groups); + $sql_extra = permissions_sql($owner_uid); $o = ""; + $o .= "<script> var profile_uid = " . $a->profile['profile_uid'] + . "; var netargs = '?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n"; + // tabs + $_is_owner = (local_user() && (local_user() == $owner_uid)); $o .= profile_tabs($a,$_is_owner, $a->data['channel']['channel_address']); @@ -679,6 +517,9 @@ function photos_content(&$a) { // dispatch request // + /** + * Display upload form + */ if($datatype === 'upload') { if(! ($can_post)) { @@ -687,19 +528,23 @@ function photos_content(&$a) { } - $selname = (($datum) ? hex2bin($datum) : ''); + + if(array_key_exists('albums', $a->data)) + $albums = get_app()->data['albums']; + else + $albums = photos_albums_list($a->data['channel'],$a->data['observer']); + $selname = (($datum) ? hex2bin($datum) : ''); $albumselect = '<select id="photos-upload-album-select" name="album" size="4">'; - $albumselect .= '<option value="" ' . ((! $selname) ? ' selected="selected" ' : '') . '> </option>'; - if(count($a->data['albums'])) { - foreach($a->data['albums'] as $album) { - if(($album['album'] === '') || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos'))) + if(count($albums)) { + foreach($albums as $album) { + if(! $album['text']) continue; - $selected = (($selname === $album['album']) ? ' selected="selected" ' : ''); - $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>'; + $selected = (($selname === $album['text']) ? ' selected="selected" ' : ''); + $albumselect .= '<option value="' . $album['text'] . '"' . $selected . '>' . $album['text'] . '</option>'; } } @@ -719,9 +564,10 @@ function photos_content(&$a) { $default_upload = '<input id="photos-upload-choose" type="file" name="userfile" /> <div class="photos-upload-submit-wrapper" > <input type="submit" name="submit" value="' . t('Submit') . '" id="photos-upload-submit" /> </div>'; + /* Show space usage */ - $r = q("select sum(size) as total from photo where uid = %d and scale = 0 ", - intval($a->data['channel']['channel_id']) + $r = q("select sum(size) as total from photo where aid = %d and scale = 0 ", + intval($a->data['channel']['channel_account_id']) ); @@ -733,15 +579,19 @@ function photos_content(&$a) { $usage_message = sprintf( t('You have used %1$.2f Mbytes of photo storage.'), $r[0]['total'] / 1024000 ); } + if($_is_owner) { + $channel = $a->get_channel(); - if($a->get_template_engine() === 'internal') { - $albumselect_e = template_escape($albumselect); - $aclselect_e = (($visitor) ? '' : template_escape(populate_acl($a->user, $celeb))); - } - else { - $albumselect_e = $albumselect; - $aclselect_e = (($visitor) ? '' : populate_acl($a->user, $celeb)); - } + $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'] + ); + } + + $albumselect_e = $albumselect; + $aclselect_e = (($_is_owner) ? populate_acl($channel_acl) : ''); $tpl = get_markup_template('photos_upload.tpl'); $o .= replace_macros($tpl,array( @@ -764,18 +614,24 @@ function photos_content(&$a) { return $o; } + /* + * Display a single photo album + */ + if($datatype === 'album') { $album = hex2bin($datum); $r = q("SELECT `resource_id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s' - AND `scale` <= 4 $sql_extra GROUP BY `resource_id`", + AND `scale` <= 4 and (photo_flags = %d or photo_flags = %d ) $sql_extra GROUP BY `resource_id`", intval($owner_uid), - dbesc($album) + dbesc($album), + intval(PHOTO_NORMAL), + intval(PHOTO_PROFILE) ); if(count($r)) { $a->set_pager_total(count($r)); - $a->set_pager_itemspage(20); + $a->set_pager_itemspage(40); } if($_GET['order'] === 'posted') @@ -783,10 +639,12 @@ function photos_content(&$a) { else $order = 'DESC'; - $r = q("SELECT `resource_id`, `id`, `filename`, type, max(`scale`) AS `scale`, `desc` FROM `photo` WHERE `uid` = %d AND `album` = '%s' - AND `scale` <= 4 $sql_extra GROUP BY `resource_id` ORDER BY `created` $order LIMIT %d , %d", + $r = q("SELECT `resource_id`, `id`, `filename`, type, max(`scale`) AS `scale`, `description` 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` ORDER BY `created` $order LIMIT %d , %d", intval($owner_uid), dbesc($album), + intvaL(PHOTO_NORMAL), + intval(PHOTO_PROFILE), intval($a->pager['start']), intval($a->pager['itemspage']) ); @@ -835,11 +693,11 @@ function photos_content(&$a) { $o .= '<div class="photos-upload-link" ><a href="' . $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/upload/' . bin2hex($album) . '" >' . t('Upload New Photos') . '</a></div>'; } - $tpl = get_markup_template('photo_album.tpl'); if(count($r)) $twist = 'rotright'; foreach($r as $rr) { + if($twist == 'rotright') $twist = 'rotleft'; else @@ -847,24 +705,36 @@ function photos_content(&$a) { $ext = $phototypes[$rr['type']]; - if($a->get_template_engine() === 'internal') { - $imgalt_e = template_escape($rr['filename']); - $desc_e = template_escape($rr['desc']); - } - else { - $imgalt_e = $rr['filename']; - $desc_e = $rr['desc']; - } - + $imgalt_e = $rr['filename']; + $desc_e = $rr['description']; + + +// prettyphoto has potential license issues, so we can no longer include it in core +// The following lines would need to be modified so that they are provided in theme specific files +// instead of core modules for themes that wish to make use of prettyphoto. I would suggest +// the feature as a per-theme display option and putting the rel line inside a template. + +// if(feature_enabled($a->data['channel']['channel_id'],'prettyphoto')){ +// $imagelink = ($a->get_baseurl() . '/photo/' . $rr['resource_id'] . '.' . $ext ); +// $rel=("prettyPhoto[pp_gal]"); +// } +// else { + $imagelink = ($a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/image/' . $rr['resource_id'] + . (($_GET['order'] === 'posted') ? '?f=&order=posted' : '')); + $rel=("photo"); +// } + $o .= replace_macros($tpl,array( '$id' => $rr['id'], '$twist' => ' ' . $twist . rand(2,4), - '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/image/' . $rr['resource_id'] - . (($_GET['order'] === 'posted') ? '?f=&order=posted' : ''), + '$photolink' => $imagelink, + '$rel' => $rel, '$phototitle' => t('View Photo'), '$imgsrc' => $a->get_baseurl() . '/photo/' . $rr['resource_id'] . '-' . $rr['scale'] . '.' .$ext, '$imgalt' => $imgalt_e, - '$desc'=> $desc_e + '$desc'=> $desc_e, + '$ext' => $ext, + '$hash'=> $rr['resource_id'], )); } @@ -875,33 +745,44 @@ function photos_content(&$a) { } + /** + * Display one photo + */ if($datatype === 'image') { - - - //$o = ''; // fetch image, item containing image, then comments - $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource_id` = '%s' - $sql_extra ORDER BY `scale` ASC ", + $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' + and (photo_flags = %d or photo_flags = %d ) $sql_extra ORDER BY `scale` ASC ", intval($owner_uid), - dbesc($datum) + dbesc($datum), + intval(PHOTO_NORMAL), + intval(PHOTO_PROFILE) + ); - if(! count($ph)) { - $ph = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource_id` = '%s' + if(! $ph) { + + /* Check again - this time without specifying permissions */ + + $ph = q("SELECT id FROM photo WHERE uid = %d AND resource_id = '%s' + and ( photo_flags = %d or photo_flags = %d ) LIMIT 1", intval($owner_uid), - dbesc($datum) + dbesc($datum), + intval(PHOTO_NORMAL), + intval(PHOTO_PROFILE) ); - if(count($ph)) - notice( t('Permission denied. Access to this item may be restricted.')); + if($ph) + notice( t('Permission denied. Access to this item may be restricted.') . EOL); else notice( t('Photo not available') . EOL ); return; } + + $prevlink = ''; $nextlink = ''; @@ -912,9 +793,11 @@ function photos_content(&$a) { $prvnxt = q("SELECT `resource_id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0 - $sql_extra ORDER BY `created` $order ", + and ( photo_flags = %d or photo_flags = %d ) $sql_extra ORDER BY `created` $order ", dbesc($ph[0]['album']), - intval($owner_uid) + intval($owner_uid), + intval(PHOTO_NORMAL), + intval(PHOTO_PROFILE) ); if(count($prvnxt)) { @@ -929,9 +812,9 @@ function photos_content(&$a) { break; } } - $edit_suffix = ((($cmd === 'edit') && ($can_post)) ? '/edit' : ''); - $prevlink = $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/image/' . $prvnxt[$prv]['resource_id'] . $edit_suffix . (($_GET['order'] === 'posted') ? '?f=&order=posted' : ''); - $nextlink = $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/image/' . $prvnxt[$nxt]['resource_id'] . $edit_suffix . (($_GET['order'] === 'posted') ? '?f=&order=posted' : ''); + + $prevlink = $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/image/' . $prvnxt[$prv]['resource_id'] . (($_GET['order'] === 'posted') ? '?f=&order=posted' : ''); + $nextlink = $a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/image/' . $prvnxt[$nxt]['resource_id'] . (($_GET['order'] === 'posted') ? '?f=&order=posted' : ''); } @@ -954,7 +837,6 @@ function photos_content(&$a) { if($can_post && ($ph[0]['uid'] == $owner_uid)) { $tools = array( - 'edit' => array($a->get_baseurl() . '/photos/' . $a->data['channel']['channel_address'] . '/image/' . $datum . (($cmd === 'edit') ? '' : '/edit'), (($cmd === 'edit') ? t('View photo') : t('Edit photo'))), 'profile'=>array($a->get_baseurl() . '/profile_photo/use/'.$ph[0]['resource_id'], t('Use as profile photo')), ); @@ -967,19 +849,15 @@ function photos_content(&$a) { } - if(! $cmd !== 'edit') { - $a->page['htmlhead'] .= '<script> - $(document).keydown(function(event) {' . "\n"; - - if($prevlink) - $a->page['htmlhead'] .= 'if(event.ctrlKey && event.keyCode == 37) { event.preventDefault(); window.location.href = \'' . $prevlink . '\'; }' . "\n"; - if($nextlink) - $a->page['htmlhead'] .= 'if(event.ctrlKey && event.keyCode == 39) { event.preventDefault(); window.location.href = \'' . $nextlink . '\'; }' . "\n"; - $a->page['htmlhead'] .= '});</script>'; - } + $a->page['htmlhead'] .= '<script>$(document).keydown(function(event) {' . "\n"; + if($prevlink) + $a->page['htmlhead'] .= 'if(event.ctrlKey && event.keyCode == 37) { event.preventDefault(); window.location.href = \'' . $prevlink . '\'; }' . "\n"; + if($nextlink) + $a->page['htmlhead'] .= 'if(event.ctrlKey && event.keyCode == 39) { event.preventDefault(); window.location.href = \'' . $nextlink . '\'; }' . "\n"; + $a->page['htmlhead'] .= '});</script>'; if($prevlink) - $prevlink = array($prevlink, '<div class="icon prev"></div>') ; + $prevlink = array($prevlink, '<i class="icon-backward photo-icons""></i>') ; $photo = array( 'href' => $a->get_baseurl() . '/photo/' . $hires['resource_id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']], @@ -988,110 +866,93 @@ function photos_content(&$a) { ); if($nextlink) - $nextlink = array($nextlink, '<div class="icon next"></div>'); + $nextlink = array($nextlink, '<i class="icon-forward photo-icons"></i>'); // Do we have an item for this photo? - $linked_items = q("SELECT * FROM `item` WHERE `resource_id` = '%s' $sql_extra LIMIT 1", + $linked_items = q("SELECT * FROM item WHERE resource_id = '%s' and resource_type = 'photo' + $sql_extra LIMIT 1", dbesc($datum) ); - if(count($linked_items)) { + + if($linked_items) { + + xchan_query($linked_items); + $linked_items = fetch_post_tags($linked_items,true); + $link_item = $linked_items[0]; - $r = q("SELECT COUNT(*) AS `total` - FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` - WHERE `parent_uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0 - AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 - AND `item`.`uid` = %d - $sql_extra ", - dbesc($link_item['uri']), - dbesc($link_item['uri']), + + $r = q("select * from item where parent_mid = '%s' + and item_restrict = 0 and uid = %d $sql_extra ", + dbesc($link_item['mid']), intval($link_item['uid']) ); - if(count($r)) - $a->set_pager_total($r[0]['total']); - - - $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, - `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`, - `contact`.`rel`, `contact`.`thumb`, `contact`.`self`, - `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid` - FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` - WHERE `parent_uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0 - AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 - AND `item`.`uid` = %d - $sql_extra - ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ", - dbesc($link_item['uri']), - dbesc($link_item['uri']), - intval($link_item['uid']), - intval($a->pager['start']), - intval($a->pager['itemspage']) + if($r) { + xchan_query($r); + $r = fetch_post_tags($r,true); + $r = conv_sort($r,'commented'); + } + + + + $tags = array(); + if($link_item['term']) { + $cnt = 0; + foreach($link_item['term'] as $t) + $tags[$cnt] = array(0 => format_term_for_display($t)); + if($can_post && ($ph[0]['uid'] == $owner_uid)) { + $tags[$cnt][1] = 'tagrm?f=&item=' . $link_item['id']; + $tags[$cnt][2] = t('Remove'); + } + $cnt ++; + } + - ); - if((local_user()) && (local_user() == $link_item['uid'])) { - q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d and `uid` = %d", + q("UPDATE `item` SET item_flags = (item_flags ^ %d) WHERE parent = %d and uid = %d and (item_flags & %d)", + intval(ITEM_UNSEEN), intval($link_item['parent']), - intval(local_user()) + intval(local_user()), + intval(ITEM_UNSEEN) ); } } - $tags=Null; - - if(count($linked_items) && strlen($link_item['tag'])) { - $arr = explode(',',$link_item['tag']); - // parse tags and add links - $tag_str = ''; - foreach($arr as $t) { - if(strlen($tag_str)) - $tag_str .= ', '; - $tag_str .= bbcode($t); - } - $tags = array(t('Tags: '), $tag_str); - if($cmd === 'edit') { - $tags[] = $a->get_baseurl() . '/tagrm/' . $link_item['id']; - $tags[] = t('[Remove any tag]'); - } - } +// logger('mod_photo: link_item' . print_r($link_item,true)); + // FIXME - remove this when we move to conversation module - $edit = Null; - if(($cmd === 'edit') && ($can_post)) { - if($a->get_template_engine() === 'internal') { - $album_e = template_escape($ph[0]['album']); - $caption_e = template_escape($ph[0]['desc']); - $aclselect_e = template_escape(populate_acl($ph[0])); - } - else { - $album_e = $ph[0]['album']; - $caption_e = $ph[0]['desc']; - $aclselect_e = populate_acl($ph[0]); - } + $r = $r[0]['children']; + + $edit = null; + if($can_post) { - $edit_tpl = get_markup_template('photo_edit.tpl'); - $edit = replace_macros($edit_tpl, array( - '$id' => $ph[0]['id'], - '$rotatecw' => t('Rotate CW (right)'), - '$rotateccw' => t('Rotate CCW (left)'), - '$album' => $album_e, - '$newalbum' => t('New album name'), - '$nickname' => $a->data['channel']['channel_address'], - '$resource_id' => $ph[0]['resource_id'], - '$capt_label' => t('Caption'), - '$caption' => $caption_e, - '$tag_label' => t('Add a Tag'), - '$tags' => $link_item['tag'], - '$permissions' => t('Permissions'), - '$aclselect' => $aclselect_e, - '$help_tags' => t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping'), - '$item_id' => ((count($linked_items)) ? $link_item['id'] : 0), - '$submit' => t('Submit'), - '$delete' => t('Delete Photo') - )); + $album_e = $ph[0]['album']; + $caption_e = $ph[0]['description']; + $aclselect_e = populate_acl($ph[0]); + + $edit = array( + 'edit' => t('Edit photo'), + 'id' => $ph[0]['id'], + 'rotatecw' => t('Rotate CW (right)'), + 'rotateccw' => t('Rotate CCW (left)'), + 'album' => $album_e, + 'newalbum' => t('New album name'), + 'nickname' => $a->data['channel']['channel_address'], + 'resource_id' => $ph[0]['resource_id'], + 'capt_label' => t('Caption'), + 'caption' => $caption_e, + 'tag_label' => t('Add a Tag'), + 'permissions' => t('Permissions'), + 'aclselect' => $aclselect_e, + 'help_tags' => t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping'), + 'item_id' => ((count($linked_items)) ? $link_item['id'] : 0), + 'submit' => t('Submit'), + 'delete' => t('Delete Photo') + ); } if(count($linked_items)) { @@ -1104,7 +965,7 @@ function photos_content(&$a) { $likebuttons = ''; - if($can_post || $a->data['perms']['post_comments']) { + if($can_post || $can_comment) { $likebuttons = replace_macros($like_tpl,array( '$id' => $link_item['id'], '$likethis' => t("I like this \x28toggle\x29"), @@ -1116,21 +977,23 @@ function photos_content(&$a) { $comments = ''; if(! count($r)) { - if($can_post || $a->data['perms']['post_comments']) { + if($can_post || $can_comment) { $comments .= replace_macros($cmnt_tpl,array( '$return_path' => '', + '$mode' => 'photos', '$jsreload' => $return_url, '$type' => 'wall-comment', '$id' => $link_item['id'], '$parent' => $link_item['id'], '$profile_uid' => $owner_uid, - '$mylink' => $contact['url'], + '$mylink' => $observer['xchan_url'], '$mytitle' => t('This is you'), - '$myphoto' => $contact['thumb'], + '$myphoto' => $observer['xchan_photo_s'], '$comment' => t('Comment'), '$submit' => t('Submit'), '$preview' => t('Preview'), - '$ww' => '' + '$ww' => '', + '$feature_encrypt' => false )); } } @@ -1142,7 +1005,7 @@ function photos_content(&$a) { $dislike = ''; // display comments - if(count($r)) { + if($r) { foreach($r as $item) { like_puller($a,$item,$alike,'like'); @@ -1154,23 +1017,6 @@ function photos_content(&$a) { - if($can_post || $a->data['perms']['post_comments']) { - $comments .= replace_macros($cmnt_tpl,array( - '$return_path' => '', - '$jsreload' => $return_url, - '$type' => 'wall-comment', - '$id' => $link_item['id'], - '$parent' => $link_item['id'], - '$profile_uid' => $owner_uid, - '$mylink' => $contact['url'], - '$mytitle' => t('This is you'), - '$myphoto' => $contact['thumb'], - '$comment' => t('Comment'), - '$submit' => t('Submit'), - '$ww' => '' - )); - } - foreach($r as $item) { $comment = ''; $template = $tpl; @@ -1181,61 +1027,30 @@ function photos_content(&$a) { $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ; - if($can_post || $a->data['perms']['post_comments']) { - $comments .= replace_macros($cmnt_tpl,array( - '$return_path' => '', - '$jsreload' => $return_url, - '$type' => 'wall-comment', - '$id' => $item['item_id'], - '$parent' => $item['parent'], - '$profile_uid' => $owner_uid, - '$mylink' => $contact['url'], - '$mytitle' => t('This is you'), - '$myphoto' => $contact['thumb'], - '$comment' => t('Comment'), - '$submit' => t('Submit'), - '$sourceapp' => t($a->sourcename), - '$ww' => '' - )); - } + $profile_url = zid($item['author']['xchan_url']); + $sparkle = ''; - if(local_user() && ($item['contact-uid'] == local_user()) - && ($item['network'] == 'dfrn') && (! $item['self'] )) { - $profile_url = $redirect_url; - $sparkle = ' sparkle'; - } - else { - $profile_url = $item['url']; - $sparkle = ''; - } - - $diff_author = (($item['url'] !== $item['author-link']) ? true : false); - $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']); - $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $item['thumb']); + $profile_name = $item['author']['xchan_name']; + $profile_avatar = $item['author']['xchan_photo_m']; $profile_link = $profile_url; $drop = ''; - if(($item['contact-id'] == $contact_id) || ($item['uid'] == local_user())) + if($observer['xchan_hash'] === $item['author_xchan'] || $observer['xchan_hash'] === $item['owner_xchan']) $drop = replace_macros(get_markup_template('photo_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete'))); - if($a->get_template_engine() === 'internal') { - $name_e = template_escape($profile_name); - $title_e = template_escape($item['title']); - $body_e = template_escape(bbcode($item['body'])); - } - else { - $name_e = $profile_name; - $title_e = $item['title']; - $body_e = bbcode($item['body']); - } + $name_e = $profile_name; + $title_e = $item['title']; + unobscure($item); + $body_e = prepare_text($item['body'],$item['mimetype']); $comments .= replace_macros($template,array( '$id' => $item['item_id'], + '$mode' => 'photos', '$profile_url' => $profile_link, '$name' => $name_e, '$thumb' => $profile_avatar, @@ -1247,24 +1062,34 @@ function photos_content(&$a) { '$drop' => $drop, '$comment' => $comment )); + + } + + if($can_post || $can_comment) { + $comments .= replace_macros($cmnt_tpl,array( + '$return_path' => '', + '$jsreload' => $return_url, + '$type' => 'wall-comment', + '$id' => $link_item['id'], + '$parent' => $link_item['id'], + '$profile_uid' => $owner_uid, + '$mylink' => $observer['xchan_url'], + '$mytitle' => t('This is you'), + '$myphoto' => $observer['xchan_photo_s'], + '$comment' => t('Comment'), + '$submit' => t('Submit'), + '$ww' => '' + )); } - } + } $paginate = paginate($a); } - if($a->get_template_engine() === 'internal') { - $album_e = array($album_link,template_escape($ph[0]['album'])); - $tags_e = template_escape($tags); - $like_e = template_escape($like); - $dislike_e = template_escape($dislike); - } - else { - $album_e = array($album_link,$ph[0]['album']); - $tags_e = $tags; - $like_e = $like; - $dislike_e = $dislike; - } + $album_e = array($album_link,$ph[0]['album']); + $like_e = $like; + $dislike_e = $dislike; + $photo_tpl = get_markup_template('photo_view.tpl'); $o .= replace_macros($photo_tpl, array( @@ -1275,8 +1100,9 @@ function photos_content(&$a) { '$photo' => $photo, '$prevlink' => $prevlink, '$nextlink' => $nextlink, - '$desc' => $ph[0]['desc'], - '$tags' => $tags_e, + '$desc' => $ph[0]['description'], + '$tag_hdr' => t('In This Photo:'), + '$tags' => $tags, '$edit' => $edit, '$likebuttons' => $likebuttons, '$like' => $like_e, @@ -1284,6 +1110,8 @@ function photos_content(&$a) { '$comments' => $comments, '$paginate' => $paginate, )); + + $a->data['photo_html'] = $o; return $o; } @@ -1292,10 +1120,12 @@ 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' - $sql_extra GROUP BY `resource_id`", + and ( photo_flags = %d or photo_flags = %d ) $sql_extra GROUP BY `resource_id`", intval($a->data['channel']['channel_id']), dbesc('Contact Photos'), - dbesc( t('Contact Photos')) + dbesc( t('Contact Photos')), + intval(PHOTO_NORMAL), + intval(PHOTO_PROFILE) ); if(count($r)) { $a->set_pager_total(count($r)); @@ -1303,11 +1133,14 @@ function photos_content(&$a) { } $r = q("SELECT `resource_id`, `id`, `filename`, type, `album`, max(`scale`) AS `scale` FROM `photo` - WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' + WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' + and ( photo_flags = %d or photo_flags = %d ) $sql_extra GROUP BY `resource_id` ORDER BY `created` DESC LIMIT %d , %d", intval($a->data['channel']['channel_id']), dbesc('Contact Photos'), dbesc( t('Contact Photos')), + intval(PHOTO_NORMAL), + intval(PHOTO_PROFILE), intval($a->pager['start']), intval($a->pager['itemspage']) ); diff --git a/mod/ping.php b/mod/ping.php index 827992c65..ac12e2fc0 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -43,6 +43,38 @@ function ping_init(&$a) { unset($_SESSION['sysmsg_info']); } + if($a->install) { + echo json_encode($result); + killme(); + } + + + if(get_observer_hash() && (! $result['invalid'])) { + $r = q("select cp_id, cp_room from chatpresence where cp_xchan = '%s' and cp_client = '%s' and cp_room = 0 limit 1", + dbesc(get_observer_hash()), + dbesc($_SERVER['REMOTE_ADDR']) + ); + $basic_presence = false; + if($r) { + $basic_presence = true; + q("update chatpresence set cp_last = '%s' where cp_id = %d limit 1", + dbesc(datetime_convert()), + intval($r[0]['cp_id']) + ); + } + if(! $basic_presence) { + q("insert into chatpresence ( cp_xchan, cp_last, cp_status, cp_client) + values( '%s', '%s', '%s', '%s' ) ", + dbesc(get_observer_hash()), + dbesc(datetime_convert()), + dbesc('online'), + dbesc($_SERVER['REMOTE_ADDR']) + ); + } + } + + q("delete from chatpresence where cp_last < UTC_TIMESTAMP() - INTERVAL 3 MINUTE and cp_client != 'auto' "); + if((! local_user()) || ($result['invalid'])) { echo json_encode($result); killme(); @@ -75,7 +107,7 @@ function ping_init(&$a) { ); break; case 'all_events': - $r = q("update event set ignore = 1 where ignore = 0 and uid = %d", + $r = q("update event set `ignore` = 1 where `ignore` = 0 and uid = %d", intval(local_user()) ); break; @@ -151,7 +183,7 @@ function ping_init(&$a) { foreach($t as $zz) { // $msg = sprintf( t('sent you a private message.'), $zz['xchan_name']); $notifs[] = array( - 'notify_link' => $a->get_baseurl() . '/message/' . $zz['id'], + 'notify_link' => $a->get_baseurl() . '/mail/' . $zz['id'], 'name' => $zz['xchan_name'], 'url' => $zz['xchan_url'], 'photo' => $zz['xchan_photo_s'], @@ -209,7 +241,7 @@ function ping_init(&$a) { if($r) { foreach($r as $rr) { $result[] = array( - 'notify_link' => $a->get_baseurl() . '/intro/' . $rr['abook_id'], + 'notify_link' => $a->get_baseurl() . '/connedit/' . $rr['abook_id'], 'name' => $rr['xchan_name'], 'url' => $rr['xchan_url'], 'photo' => $rr['xchan_photo_s'], @@ -253,7 +285,7 @@ function ping_init(&$a) { $result[] = array( - 'notify_link' => $a->get_baseurl() . '/events/event/' . $rr['event_hash'], + 'notify_link' => $a->get_baseurl() . '/events', // FIXME this takes you to an edit page and it may not be yours, we really want to just view the single event --> '/events/event/' . $rr['event_hash'], 'name' => $rr['xchan_name'], 'url' => $rr['xchan_url'], 'photo' => $rr['xchan_photo_s'], diff --git a/mod/poco.php b/mod/poco.php index a5808b7db..9295f13de 100644 --- a/mod/poco.php +++ b/mod/poco.php @@ -76,6 +76,9 @@ function poco_init(&$a) { $sql_extra ", intval($channel_id) ); + $c = q("select * from menu_item where ( mitem_flags & " . intval(MENU_ITEM_CHATROOM) . " ) and allow_cid = '' and allow_gid = '' and deny_cid = '' and deny_gid = '' and mitem_channel_id = %d", + intval($channel_id) + ); } if($r) $totalResults = intval($r[0]['total']); @@ -115,6 +118,14 @@ function poco_init(&$a) { $ret['startIndex'] = (string) $startIndex; $ret['itemsPerPage'] = (string) $itemsPerPage; $ret['totalResults'] = (string) $totalResults; + + if($c) { + $ret['chatrooms'] = array(); + foreach($c as $d) { + $ret['chatrooms'][] = array('url' => $d['mitem_link'], 'desc' => $d['mitem_desc']); + } + } + $ret['entry'] = array(); diff --git a/mod/poke.php b/mod/poke.php index 163ef0cd8..b22f7d9d5 100755 --- a/mod/poke.php +++ b/mod/poke.php @@ -1,17 +1,30 @@ -<?php +<?php /** @file */ + +/** + * + * Poke, prod, finger, or otherwise do unspeakable things to somebody - who must be a connection in your address book + * This function can be invoked with the required arguments (verb and cid and private and possibly parent) silently via ajax or + * other web request. You must be logged in and connected to a channel. + * If the required arguments aren't present, we'll display a simple form to choose a recipient and a verb. + * parent is a special argument which let's you attach this activity as a comment to an existing conversation, which + * may have started with somebody else poking (etc.) somebody, but this isn't necessary. This can be used in the adult + * plugin version to have entire conversations where Alice poked Bob, Bob fingered Alice, Alice hugged Bob, etc. + * + * private creates a private conversation with the recipient. Otherwise your channel's default post privacy is used. + * + */ -require_once('include/security.php'); -require_once('include/bbcode.php'); require_once('include/items.php'); - function poke_init(&$a) { if(! local_user()) return; $uid = local_user(); - $verb = notags(trim($_GET['verb'])); + $channel = $a->get_channel(); + + $verb = notags(trim($_REQUEST['verb'])); if(! $verb) return; @@ -23,109 +36,86 @@ function poke_init(&$a) { $activity = ACTIVITY_POKE . '#' . urlencode($verbs[$verb][0]); - $contact_id = intval($_GET['cid']); + $contact_id = intval($_REQUEST['cid']); if(! $contact_id) return; - $parent = ((x($_GET,'parent')) ? intval($_GET['parent']) : 0); - + $parent = ((x($_REQUEST,'parent')) ? intval($_REQUEST['parent']) : 0); logger('poke: verb ' . $verb . ' contact ' . $contact_id, LOGGER_DEBUG); - $r = q("SELECT * FROM `contact` WHERE `id` = %d and `uid` = %d LIMIT 1", + $r = q("SELECT * FROM abook left join xchan on xchan_hash = abook_xchan where abook_id = %d and abook_channel = %d LIMIT 1", intval($contact_id), intval($uid) ); - if(! count($r)) { - logger('poke: no contact ' . $contact_id); + if(! $r) { + logger('poke: no target ' . $contact_id); return; } $target = $r[0]; + $parent_item = null; if($parent) { - $r = q("select uri, private, allow_cid, allow_gid, deny_cid, deny_gid + $r = q("select mid, item_private, owner_xchan, allow_cid, allow_gid, deny_cid, deny_gid from item where id = %d and parent = %d and uid = %d limit 1", intval($parent), intval($parent), intval($uid) ); - if(count($r)) { - $parent_uri = $r[0]['uri']; - $private = $r[0]['private']; - $allow_cid = $r[0]['allow_cid']; - $allow_gid = $r[0]['allow_gid']; - $deny_cid = $r[0]['deny_cid']; - $deny_gid = $r[0]['deny_gid']; + if($r) { + $parent_item = $r[0]; + $parent_mid = $r[0]['mid']; + $item_private = $r[0]['item_private']; + $allow_cid = $r[0]['allow_cid']; + $allow_gid = $r[0]['allow_gid']; + $deny_cid = $r[0]['deny_cid']; + $deny_gid = $r[0]['deny_gid']; } } else { - $private = ((x($_GET,'private')) ? intval($_GET['private']) : 0); + $item_private = ((x($_GET,'private')) ? intval($_GET['private']) : 0); - $allow_cid = (($private) ? '<' . $target['id']. '>' : $a->user['allow_cid']); - $allow_gid = (($private) ? '' : $a->user['allow_gid']); - $deny_cid = (($private) ? '' : $a->user['deny_cid']); - $deny_gid = (($private) ? '' : $a->user['deny_gid']); + $allow_cid = (($item_private) ? '<' . $target['abook_xchan']. '>' : $channel['channel_allow_cid']); + $allow_gid = (($item_private) ? '' : $channel['channel_allow_gid']); + $deny_cid = (($item_private) ? '' : $channel['channel_deny_cid']); + $deny_gid = (($item_private) ? '' : $channel['channel_deny_gid']); } - - - $poster = $a->contact; - - $uri = item_message_id(); - $arr = array(); + $arr['item_flags'] = ITEM_WALL | ITEM_ORIGIN; + if($parent_item) + $arr['item_flags'] |= ITEM_THREAD_TOP; - $arr['uid'] = $uid; - $arr['uri'] = $uri; - $arr['parent_uri'] = (($parent_uri) ? $parent_uri : $uri); - $arr['type'] = 'activity'; - $arr['wall'] = 1; - $arr['contact-id'] = $poster['id']; - $arr['owner-name'] = $poster['name']; - $arr['owner-link'] = $poster['url']; - $arr['owner-avatar'] = $poster['thumb']; - $arr['author-name'] = $poster['name']; - $arr['author-link'] = $poster['url']; - $arr['author-avatar'] = $poster['thumb']; + $arr['owner_xchan'] = (($parent_item) ? $parent_item['owner_xchan'] : $channel['channel_hash']); + $arr['parent_mid'] = (($parent_mid) ? $parent_mid : $mid); $arr['title'] = ''; $arr['allow_cid'] = $allow_cid; $arr['allow_gid'] = $allow_gid; $arr['deny_cid'] = $deny_cid; $arr['deny_gid'] = $deny_gid; - $arr['last-child'] = 1; - $arr['visible'] = 1; $arr['verb'] = $activity; - $arr['private'] = $private; - $arr['obj_type'] = ACTIVITY_OBJ_PERSON; - - $arr['origin'] = 1; - $arr['body'] = '[url=' . $poster['url'] . ']' . $poster['name'] . '[/url]' . ' ' . t($verbs[$verb][0]) . ' ' . '[url=' . $target['url'] . ']' . $target['name'] . '[/url]'; - - $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $target['name'] . '</title><id>' . $a->get_baseurl() . '/contact/' . $target['id'] . '</id>'; - $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $target['url'] . '" />' . "\n"); - - $arr['object'] .= xmlify('<link rel="photo" type="image/jpeg" href="' . $target['photo'] . '" />' . "\n"); - $arr['object'] .= '</link></object>' . "\n"; - - $item_id = item_store($arr); - if($item_id) { - q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1", - dbesc($a->get_baseurl() . '/display/' . $poster['nickname'] . '/' . $item_id), - intval($uid), - intval($item_id) - ); - proc_run('php',"include/notifier.php","tag","$item_id"); - } - + $arr['item_private'] = $item_private; + $arr['obj_type'] = ACTIVITY_OBJ_PERSON; + $arr['body'] = '[zrl=' . $channel['xchan_url'] . ']' . $channel['xchan_name'] . '[/zrl]' . ' ' . t($verbs[$verb][0]) . ' ' . '[zrl=' . $target['xchan_url'] . ']' . $target['xchan_name'] . '[/zrl]'; + + $obj = array( + 'type' => ACTIVITY_OBJ_PERSON, + 'title' => $target['xchan_name'], + 'id' => $target['xchan_hash'], + 'link' => array( + array('rel' => 'alternate', 'type' => 'text/html', 'href' => $target['xchan_url']), + array('rel' => 'photo', 'type' => $target['xchan_photo_mimetype'], 'href' => $target['xchan_photo_l']) + ), + ); - call_hooks('post_local_end', $arr); + $arr['object'] = json_encode($obj); - proc_run('php',"include/notifier.php","like","$post_id"); + post_activity_item($arr); return; } @@ -142,43 +132,19 @@ function poke_content(&$a) { $name = ''; $id = ''; - if(intval($_GET['c'])) { - $r = q("select id,name from contact where id = %d and uid = %d limit 1", - intval($_GET['c']), + if(intval($_REQUEST['c'])) { + $r = q("select abook_id, xchan_name from abook left join xchan on abook_xchan = xchan_hash + where abook_id = %d and abook_channel = %d limit 1", + intval($_REQUEST['c']), intval(local_user()) ); - if(count($r)) { - $name = $r[0]['name']; - $id = $r[0]['id']; + if($r) { + $name = $r[0]['xchan_name']; + $id = $r[0]['abook_id']; } } - - $base = $a->get_baseurl(); - - $a->page['htmlhead'] .= <<< EOT - -<script>$(document).ready(function() { - var a; - a = $("#poke-recip").autocomplete({ - serviceUrl: '$base/acl', - minChars: 2, - width: 350, - onSelect: function(value,data) { - $("#poke-recip-complete").val(data); - } - }); - a.setOptions({ params: { type: 'a' }}); - - -}); - -</script> -EOT; - - $parent = ((x($_GET,'parent')) ? intval($_GET['parent']) : '0'); - - + $parent = ((x($_REQUEST,'parent')) ? intval($_REQUEST['parent']) : '0'); $verbs = get_poke_verbs(); diff --git a/mod/post.php b/mod/post.php index e5fa1a418..1f817aa40 100644 --- a/mod/post.php +++ b/mod/post.php @@ -1,4 +1,4 @@ -<?php +<?php /** @file */ /** * Zot endpoint @@ -10,158 +10,515 @@ require_once('include/zot.php'); function post_init(&$a) { - // All other access to this endpoint is via the post method. + // Most access to this endpoint is via the post method. // Here we will pick out the magic auth params which arrive - // as a get request. - - if(argc() > 1) { - - $webbie = argv(1); - - if(array_key_exists('auth',$_REQUEST)) { - - $address = $_REQUEST['auth']; - $dest = $_REQUEST['dest']; - $sec = $_REQUEST['sec']; - $version = $_REQUEST['version']; - - switch($dest) { - case 'channel': - $desturl = z_root() . '/channel/' . $webbie; - break; - case 'photos': - $desturl = z_root() . '/photos/' . $webbie; - break; - case 'profile': - $desturl = z_root() . '/profile/' . $webbie; - break; - default: - $desturl = $dest; - break; - } - $c = q("select * from channel where channel_address = '%s' limit 1", - dbesc($webbie) - ); - if(! $c) { - logger('mod_zot: auth: unable to find channel ' . $webbie); - // They'll get a notice when they hit the page, we don't need two of them. - goaway($desturl); + // as a get request, and the only communications to arrive this way. + +/** + * Magic Auth + * ========== + * + * So-called "magic auth" takes place by a special exchange. On the site where the "channel to be authenticated" lives (e.g. $mysite), + * a redirection is made via $mysite/magic to the zot endpoint of the remote site ($remotesite) with special GET parameters. + * + * The endpoint is typically https://$remotesite/post - or whatever was specified as the callback url in prior communications + * (we will bootstrap an address and fetch a zot info packet if possible where no prior communications exist) + * + * Four GET parameters are supplied: + * + ** auth => the urlencoded webbie (channel@host.domain) of the channel requesting access + ** dest => the desired destination URL (urlencoded) + ** sec => a random string which is also stored on $mysite for use during the verification phase. + ** version => the zot revision + * + * When this packet is received, an "auth-check" zot message is sent to $mysite. + * (e.g. if $_GET['auth'] is foobar@podunk.edu, a zot packet is sent to the podunk.edu zot endpoint, which is typically /post) + * If no information has been recorded about the requesting identity a zot information packet will be retrieved before + * continuing. + * + * The sender of this packet is an arbitrary/random site channel. The recipients will be a single recipient corresponding + * to the guid and guid_sig we have associated with the requesting auth identity + * + * + * { + * "type":"auth_check", + * "sender":{ + * "guid":"kgVFf_...", + * "guid_sig":"PT9-TApz...", + * "url":"http:\/\/podunk.edu", + * "url_sig":"T8Bp7j..." + * }, + * "recipients":{ + * { + * "guid":"ZHSqb...", + * "guid_sig":"JsAAXi..." + * } + * } + * "callback":"\/post", + * "version":1, + * "secret":"1eaa661", + * "secret_sig":"eKV968b1..." + * } + * + * + * auth_check messages MUST use encapsulated encryption. This message is sent to the origination site, which checks the 'secret' to see + * if it is the same as the 'sec' which it passed originally. It also checks the secret_sig which is the secret signed by the + * destination channel's private key and base64url encoded. If everything checks out, a json packet is returned: + * + * { + * "success":1, + * "confirm":"q0Ysovd1u..." + * "service_class":(optional) + * "level":(optional) + * } + * + * 'confirm' in this case is the base64url encoded RSA signature of the concatenation of 'secret' with the + * base64url encoded whirlpool hash of the requestor's guid and guid_sig; signed with the source channel private key. + * This prevents a man-in-the-middle from inserting a rogue success packet. Upon receipt and successful + * verification of this packet, the destination site will redirect to the original destination URL and indicate a successful remote login. + * Service_class can be used by cooperating sites to provide different access rights based on account rights and subscription plans. It is + * a string whose contents are not defined by protocol. Example: "basic" or "gold". + * + * + * + */ + + if(array_key_exists('auth',$_REQUEST)) { + + $ret = array('success' => false, 'message' => ''); + + logger('mod_zot: auth request received.'); + $address = $_REQUEST['auth']; + $desturl = $_REQUEST['dest']; + $sec = $_REQUEST['sec']; + $version = $_REQUEST['version']; + $test = ((x($_REQUEST,'test')) ? intval($_REQUEST['test']) : 0); + + // They are authenticating ultimately to the site and not to a particular channel. + // 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 ) limit 1", + intval(PAGE_REMOVED) + ); + + if(! $c) { + // nobody here + logger('mod_zot: auth: unable to find a response channel'); + if($test) { + $ret['message'] .= 'no local channels found.' . EOL; + json_return_and_die($ret); } - // Try and find a hubloc for the person attempting to auth - $x = q("select * from hubloc left join xchan on xchan_hash = hubloc_hash where hubloc_addr = '%s' limit 1", - dbesc($address) - ); + goaway($desturl); + } - if(! $x) { - // finger them if they can't be found. - $ret = zot_finger($addr,null); - if($ret['success']) { - $j = json_decode($ret['body'],true); - if($j) - import_xchan($j); - $x = q("select * from hubloc left join xchan on xchan_hash = hubloc_hash where hubloc_addr = '%s' limit 1", - dbesc($address) - ); - } + // Try and find a hubloc for the person attempting to auth + $x = q("select * from hubloc left join xchan on xchan_hash = hubloc_hash where hubloc_addr = '%s' order by hubloc_id desc limit 1", + dbesc($address) + ); + + if(! $x) { + // finger them if they can't be found. + $ret = zot_finger($address,null); + if($ret['success']) { + $j = json_decode($ret['body'],true); + if($j) + import_xchan($j); + $x = q("select * from hubloc left join xchan on xchan_hash = hubloc_hash where hubloc_addr = '%s' order by hubloc_id desc limit 1", + dbesc($address) + ); } - if(! $x) { - logger('mod_zot: auth: unable to finger ' . $addr); - goaway($desturl); + } + if(! $x) { + logger('mod_zot: auth: unable to finger ' . $address); + + if($test) { + $ret['message'] .= 'no hubloc found for ' . $address . ' and probing failed.' . EOL; + json_return_and_die($ret); } - logger('mod_zot: auth request received from ' . $x[0]['xchan_addr'] . ' for ' . $webbie); + goaway($desturl); + } + + logger('mod_zot: auth request received from ' . $x[0]['hubloc_addr'] ); + + // check credentials and access + + // If they are already authenticated and haven't changed credentials, + // we can save an expensive network round trip and improve performance. + + $remote = remote_user(); + $result = null; + $remote_service_class = ''; + $remote_level = 0; + $remote_hub = $x[0]['hubloc_url']; + + // Also check that they are coming from the same site as they authenticated with originally. + + $already_authed = ((($remote) && ($x[0]['hubloc_hash'] == $remote) && ($x[0]['hubloc_url'] === $_SESSION['remote_hub'])) ? true : false); - // check credentials and access + $j = array(); - // If they are already authenticated and haven't changed credentials, - // we can save an expensive network round trip and improve performance. + if(! $already_authed) { - $remote = remote_user(); - $result = null; + // Auth packets MUST use ultra top-secret hush-hush mode - e.g. the entire packet is encrypted using the site private key + // The actual channel sending the packet ($c[0]) is not important, but this provides a generic zot packet with a sender + // which can be verified + + $p = zot_build_packet($c[0],$type = 'auth_check', array(array('guid' => $x[0]['hubloc_guid'],'guid_sig' => $x[0]['hubloc_guid_sig'])), $x[0]['hubloc_sitekey'], $sec); + if($test) { + $ret['message'] .= 'auth check packet created using sitekey ' . $x[0]['hubloc_sitekey'] . EOL; + $ret['message'] .= 'packet contents: ' . $p . EOL; + } + + $result = zot_zot($x[0]['hubloc_callback'],$p); - $already_authed = ((($remote) && ($x[0]['hubloc_hash'] == $remote)) ? true : false); - if(! $already_authed) { - // Auth packets MUST use ultra top-secret hush-hush mode - $p = zot_build_packet($c[0],$type = 'auth_check', - array(array('guid' => $x[0]['hubloc_guid'],'guid_sig' => $x[0]['hubloc_guid_sig'])), - $x[0]['hubloc_sitekey'], $sec); - $result = zot_zot($x[0]['hubloc_callback'],$p); - if(! $result['success']) { - logger('mod_zot: auth_check callback failed.'); + if(! $result['success']) { + logger('mod_zot: auth_check callback failed.'); + if($test) { + $ret['message'] .= 'auth check request to your site returned .' . print_r($result, true) . EOL; + json_return_and_die($ret); + } + + goaway($desturl); + } + $j = json_decode($result['body'],true); + if(! $j) { + logger('mod_zot: auth_check json data malformed.'); + if($test) { + $ret['message'] .= 'json malformed: ' . $result['body'] . EOL; + json_return_and_die($ret); + } + } + } + + if($test) { + $ret['message'] .= 'auth check request returned .' . print_r($j, true) . EOL; + } + + if($already_authed || $j['success']) { + if($j['success']) { + // legit response, but we do need to check that this wasn't answered by a man-in-middle + if(! rsa_verify($sec . $x[0]['xchan_hash'],base64url_decode($j['confirm']),$x[0]['xchan_pubkey'])) { + logger('mod_zot: auth: final confirmation failed.'); + if($test) { + $ret['message'] .= 'final confirmation failed. ' . $sec . print_r($j,true) . print_r($x[0],true); + json_return_and_die($ret); + } + goaway($desturl); } - $j = json_decode($result['body'],true); + if(array_key_exists('service_class',$j)) + $remote_service_class = $j['service_class']; + if(array_key_exists('level',$j)) + $remote_level = $j['level']; } + // everything is good... maybe + if(local_user()) { - if($already_authed || $j['result']) { - // everything is good... maybe - if(local_user()) { + // tell them to logout if they're logged in locally as anything but the target remote account + // in which case just shut up because they don't need to be doing this at all. + + if($a->channel['channel_hash'] != $x[0]['xchan_hash']) { + logger('mod_zot: auth: already authenticated locally as somebody else.'); notice( t('Remote authentication blocked. You are logged into this site locally. Please logout and retry.') . EOL); - goaway($desturl); + if($test) { + $ret['message'] .= 'already logged in locally with a conflicting identity.' . EOL; + json_return_and_die($ret); + } + } - // log them in - $_SESSION['authenticated'] = 1; - $_SESSION['visitor_id'] = $x[0]['xchan_hash']; - $a->set_observer($x[0]); - require_once('include/security.php'); - $a->set_groups(init_groups_visitor($_SESSION['visitor_id'])); - info(sprintf( t('Welcome %s. Remote authentication successful.'),$x[0]['xchan_name'])); - logger('mod_zot: auth success from ' . $x[0]['xchan_addr'] . ' for ' . $webbie); + goaway($desturl); + } + // log them in + if($test) { + $ret['success'] = true; + $ret['message'] .= 'Authentication Success!' . EOL; + json_return_and_die($ret); } -// 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 rmagic directly, as it would otherwise send you back here again. -// But z_root() probably isn't where you really want to go. - if(strstr($desturl,z_root() . '/rmagic')) - goaway(z_root()); + $_SESSION['authenticated'] = 1; + $_SESSION['visitor_id'] = $x[0]['xchan_hash']; + $_SESSION['my_url'] = $x[0]['xchan_url']; + $_SESSION['my_address'] = $address; + $_SESSION['remote_service_class'] = $remote_service_class; + $_SESSION['remote_level'] = $remote_level; + $_SESSION['remote_hub'] = $remote_hub; + + $arr = array('xchan' => $x[0], 'url' => $desturl, 'session' => $_SESSION); + call_hooks('magic_auth_success',$arr); + $a->set_observer($x[0]); + require_once('include/security.php'); + $a->set_groups(init_groups_visitor($_SESSION['visitor_id'])); + info(sprintf( t('Welcome %s. Remote authentication successful.'),$x[0]['xchan_name'])); + logger('mod_zot: auth success from ' . $x[0]['xchan_addr']); + q("update hubloc set hubloc_status = (hubloc_status | %d ) where hubloc_id = %d ", + intval(HUBLOC_WORKS), + intval($x[0]['hubloc_id']) + ); + + + } else { + if($test) { + $ret['message'] .= 'auth failure. ' . print_r($_REQUEST,true) . print_r($j,true) . EOL; + json_return_and_die($ret); + } - goaway($desturl); + logger('mod_zot: magic-auth failure - not authenticated: ' . $x[0]['xchan_addr']); + q("update hubloc set hubloc_status = (hubloc_status | %d ) where hubloc_id = %d ", + intval(HUBLOC_RECEIVE_ERROR), + intval($x[0]['hubloc_id']) + ); } - logger('mod_zot: invalid args: ' . print_r($a->argv,true)); - killme(); - } + // 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 rmagic directly, as it would otherwise send you back here again. + // But z_root() probably isn't where you really want to go. + if($test) { + $ret['message'] .= 'auth failure fallthrough ' . print_r($_REQUEST,true) . print_r($j,true) . EOL; + json_return_and_die($ret); + } + + if(strstr($desturl,z_root() . '/rmagic')) + goaway(z_root()); + + goaway($desturl); + } return; } - +/** + * @function post_post(&$a) + * zot communications and messaging + * + * Sender HTTP posts to this endpoint ($site/post typically) with 'data' parameter set to json zot message packet. + * This packet is optionally encrypted, which we will discover if the json has an 'iv' element. + * $contents => array( 'alg' => 'aes256cbc', 'iv' => initialisation vector, 'key' => decryption key, 'data' => encrypted data); + * $contents->iv and $contents->key are random strings encrypted with this site's RSA public key and then base64url encoded. + * Currently only 'aes256cbc' is used, but this is extensible should that algorithm prove inadequate. + * + * Once decrypted, one will find the normal json_encoded zot message packet. + * + * Defined packet types are: notify, purge, refresh, force_refresh, auth_check, ping, and pickup + * + * Standard packet: (used by notify, purge, refresh, force_refresh, and auth_check) + * + * { + * "type": "notify", + * "sender":{ + * "guid":"kgVFf_1...", + * "guid_sig":"PT9-TApzp...", + * "url":"http:\/\/podunk.edu", + * "url_sig":"T8Bp7j5...", + * }, + * "recipients": { optional recipient array }, + * "callback":"\/post", + * "version":1, + * "secret":"1eaa...", + * "secret_sig": "df89025470fac8..." + * } + * + * Signature fields are all signed with the sender channel private key and base64url encoded. + * Recipients are arrays of guid and guid_sig, which were previously signed with the recipients private + * key and base64url encoded and later obtained via channel discovery. Absence of recipients indicates + * a public message or visible to all potential listeners on this site. + * + * "pickup" packet: + * The pickup packet is sent in response to a notify packet from another site + * + * { + * "type":"pickup", + * "url":"http:\/\/example.com", + * "callback":"http:\/\/example.com\/post", + * "callback_sig":"teE1_fLI...", + * "secret":"1eaa...", + * "secret_sig":"O7nB4_..." + * } + * + * In the pickup packet, the sig fields correspond to the respective data element signed with this site's system + * private key and then base64url encoded. + * The "secret" is the same as the original secret from the notify packet. + * + * If verification is successful, a json structure is returned + * containing a success indicator and an array of type 'pickup'. + * Each pickup element contains the original notify request and a message field whose contents are + * dependent on the message type + * + * This JSON array is AES encapsulated using the site public key of the site that sent the initial zot pickup packet. + * Using the above example, this would be example.com. + * + * + * { + * "success":1, + * "pickup":{ + * "notify":{ + * "type":"notify", + * "sender":{ + * "guid":"kgVFf_...", + * "guid_sig":"PT9-TApz...", + * "url":"http:\/\/z.podunk.edu", + * "url_sig":"T8Bp7j5D..." + * }, + * "callback":"\/post", + * "version":1, + * "secret":"1eaa661..." + * }, + * "message":{ + * "type":"activity", + * "message_id":"10b049ce384cbb2da9467319bc98169ab36290b8bbb403aa0c0accd9cb072e76@podunk.edu", + * "message_top":"10b049ce384cbb2da9467319bc98169ab36290b8bbb403aa0c0accd9cb072e76@podunk.edu", + * "message_parent":"10b049ce384cbb2da9467319bc98169ab36290b8bbb403aa0c0accd9cb072e76@podunk.edu", + * "created":"2012-11-20 04:04:16", + * "edited":"2012-11-20 04:04:16", + * "title":"", + * "body":"Hi Nickordo", + * "app":"", + * "verb":"post", + * "object_type":"", + * "target_type":"", + * "permalink":"", + * "location":"", + * "longlat":"", + * "owner":{ + * "name":"Indigo", + * "address":"indigo@podunk.edu", + * "url":"http:\/\/podunk.edu", + * "photo":{ + * "mimetype":"image\/jpeg", + * "src":"http:\/\/podunk.edu\/photo\/profile\/m\/5" + * }, + * "guid":"kgVFf_...", + * "guid_sig":"PT9-TAp...", + * }, + * "author":{ + * "name":"Indigo", + * "address":"indigo@podunk.edu", + * "url":"http:\/\/podunk.edu", + * "photo":{ + * "mimetype":"image\/jpeg", + * "src":"http:\/\/podunk.edu\/photo\/profile\/m\/5" + * }, + * "guid":"kgVFf_...", + * "guid_sig":"PT9-TAp..." + * } + * } + * } + *} + * + * Currently defined message types are 'activity', 'mail', 'profile' and 'channel_sync', which each have + * different content schemas. + * + * Ping packet: + * A ping packet does not require any parameters except the type. It may or may not be encrypted. + * + * { + * "type": "ping" + * } + * + * On receipt of a ping packet a ping response will be returned: + * + * { + * "success" : 1, + * "site" { + * "url":"http:\/\/podunk.edu", + * "url_sig":"T8Bp7j5...", + * "sitekey": "-----BEGIN PUBLIC KEY----- + * MIICIjANBgkqhkiG9w0BAQE..." + * } + * } + * + * The ping packet can be used to verify that a site has not been re-installed, and to + * initiate corrective action if it has. The url_sig is signed with the site private key + * and base64url encoded - and this should verify with the enclosed sitekey. Failure to + * verify indicates the site is corrupt or otherwise unable to communicate using zot. + * This return packet is not otherwise verified, so should be compared with other + * results obtained from this site which were verified prior to taking action. For instance + * if you have one verified result with this signature and key, and other records for this + * url which have different signatures and keys, it indicates that the site was re-installed + * and corrective action may commence (remove or mark invalid any entries with different + * signatures). + * If you have no records which match this url_sig and key - no corrective action should + * be taken as this packet may have been returned by an imposter. + * + */ function post_post(&$a) { - logger('mod_zot: ' . print_r($_REQUEST,true), LOGGER_DEBUG); - $ret = array('result' => false); + $encrypted_packet = false; + $ret = array('success' => false); $data = json_decode($_REQUEST['data'],true); - logger('mod_zot: data: ' . print_r($data,true), LOGGER_DATA); + + /** + * Many message packets will arrive encrypted. The existence of an 'iv' element + * tells us we need to unencapsulate the AES-256-CBC content using the site private key + */ if(array_key_exists('iv',$data)) { - $data = aes_unencapsulate($data,get_config('system','prvkey')); + $encrypted_packet = true; + $data = crypto_unencapsulate($data,get_config('system','prvkey')); logger('mod_zot: decrypt1: ' . $data, LOGGER_DATA); $data = json_decode($data,true); } - logger('mod_zot: decoded data: ' . print_r($data,true), LOGGER_DATA); + if(! $data) { + + // possible Bleichenbacher's attack, just treat it as a + // message we have no handler for. It should fail a bit + // further along with "no hub". Our public key is public + // knowledge. There's no reason why anybody should get the + // encryption wrong unless they're fishing or hacking. If + // they're developing and made a goof, this can be discovered + // in the logs of the destination site. If they're fishing or + // hacking, the bottom line is we can't verify their hub. + // That's all we're going to tell them. + + $data = array('type' => 'bogus'); + } + $msgtype = ((array_key_exists('type',$data)) ? $data['type'] : ''); + if($msgtype === 'ping') { + + // Useful to get a health check on a remote site. + // This will let us know if any important communication details + // that we may have stored are no longer valid, regardless of xchan details. + logger('POST: got ping send pong now back: ' . z_root() , LOGGER_DEBUG ); + + $ret['success'] = true; + $ret['site'] = array(); + $ret['site']['url'] = z_root(); + $ret['site']['url_sig'] = base64url_encode(rsa_sign(z_root(),get_config('system','prvkey'))); + $ret['site']['sitekey'] = get_config('system','pubkey'); + json_return_and_die($ret); + } if($msgtype === 'pickup') { + /** + * The 'pickup' message arrives with a tracking ID which is associated with a particular outq_hash + * First verify that that the returned signatures verify, then check that we have an outbound queue item + * with the correct hash. + * If everything verifies, find any/all outbound messages in the queue for this hubloc and send them back + * + */ + if((! $data['secret']) || (! $data['secret_sig'])) { $ret['message'] = 'no verification signature'; logger('mod_zot: pickup: ' . $ret['message'], LOGGER_DEBUG); json_return_and_die($ret); } - $r = q("select hubloc_sitekey from hubloc where hubloc_url = '%s' and hubloc_callback = '%s' and hubloc_sitekey != '' limit 1", + $r = q("select distinct hubloc_sitekey from hubloc where hubloc_url = '%s' and hubloc_callback = '%s' and hubloc_sitekey != '' group by hubloc_sitekey ", dbesc($data['url']), dbesc($data['callback']) ); @@ -170,23 +527,47 @@ function post_post(&$a) { logger('mod_zot: pickup: ' . $ret['message']); json_return_and_die($ret); } - // verify the url_sig - $sitekey = $r[0]['hubloc_sitekey']; - logger('sitekey: ' . $sitekey); - if(! rsa_verify($data['callback'],base64url_decode($data['callback_sig']),$sitekey)) { + foreach ($r as $hubsite) { + + // verify the url_sig + // If the server was re-installed at some point, there could be multiple hubs with the same url and callback. + // Only one will have a valid key. + + $forgery = true; + $secret_fail = true; + + $sitekey = $hubsite['hubloc_sitekey']; + + logger('mod_zot: Checking sitekey: ' . $sitekey, LOGGER_DATA); + + if(rsa_verify($data['callback'],base64url_decode($data['callback_sig']),$sitekey)) { + $forgery = false; + } + if(rsa_verify($data['secret'],base64url_decode($data['secret_sig']),$sitekey)) { + $secret_fail = false; + } + if((! $forgery) && (! $secret_fail)) + break; + } + + if($forgery) { $ret['message'] = 'possible site forgery'; logger('mod_zot: pickup: ' . $ret['message']); json_return_and_die($ret); } - if(! rsa_verify($data['secret'],base64url_decode($data['secret_sig']),$sitekey)) { + if($secret_fail) { $ret['message'] = 'secret validation failed'; logger('mod_zot: pickup: ' . $ret['message']); json_return_and_die($ret); } - // If we made it to here, we've got a valid pickup. Grab everything for this host and send it. + /** + * If we made it to here, the signatures verify, but we still don't know if the tracking ID is valid. + * It wouldn't be an error if the tracking ID isn't found, because we may have sent this particular + * queue item with another pickup (after the tracking ID for the other pickup was verified). + */ $r = q("select outq_posturl from outq where outq_hash = '%s' and outq_posturl = '%s' limit 1", dbesc($data['secret']), @@ -198,10 +579,17 @@ function post_post(&$a) { json_return_and_die($ret); } + /** + * Everything is good if we made it here, so find all messages that are going to this location + * and send them all. + */ + $r = q("select * from outq where outq_posturl = '%s'", dbesc($data['callback']) ); if($r) { + logger('mod_zot: succesful pickup message received from ' . $data['callback'] . ' ' . count($r) . ' message(s) picked up', LOGGER_DEBUG); + $ret['success'] = true; $ret['pickup'] = array(); foreach($r as $rr) { @@ -212,59 +600,209 @@ function post_post(&$a) { ); } } - $encrypted = aes_encapsulate(json_encode($ret),$sitekey); + + $encrypted = crypto_encapsulate(json_encode($ret),$sitekey); json_return_and_die($encrypted); + + /** pickup: end */ } + + + + /** + * All other message types require us to verify the sender. This is a generic check, so we + * will do it once here and bail if anything goes wrong. + */ + if(array_key_exists('sender',$data)) { $sender = $data['sender']; } + /** Check if the sender is already verified here */ + $hub = zot_gethub($sender); + if(! $hub) { + + /** Have never seen this guid or this guid coming from this location. Check it and register it. */ + // (!!) this will validate the sender $result = zot_register_hub($sender); - if((! $result['success']) || (! zot_gethub($sender))) { + + if((! $result['success']) || (! ($hub = zot_gethub($sender)))) { $ret['message'] = 'Hub not available.'; logger('mod_zot: no hub'); json_return_and_die($ret); } } + + // 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 + + $r = q("update hubloc set hubloc_connected = '%s' where hubloc_id = %d limit 1", + dbesc(datetime_convert()), + intval($hub['hubloc_id']) + ); + + /** + * This hub has now been proven to be valid. + * 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), + dbesc($hub['hubloc_url']), + dbesc($hub['hubloc_sitekey']) + ); + // TODO: check which hub is primary and take action if mismatched if(array_key_exists('recipients',$data)) $recipients = $data['recipients']; - if($msgtype === 'purge') { - if($recipients) { - // basically this means "unfriend" - foreach($recipients as $recip) { + if($msgtype === 'auth_check') { + /** + * Requestor visits /magic/?dest=somewhere on their own site with a browser + * magic redirects them to $destsite/post [with auth args....] + * $destsite sends an auth_check packet to originator site + * The auth_check packet is handled here by the originator's site + * - the browser session is still waiting + * inside $destsite/post for everything to verify + * If everything checks out we'll return a token to $destsite + * and then $destsite will verify the token, authenticate the browser + * session and then redirect to the original destination. + * If authentication fails, the redirection to the original destination + * will still take place but without authentication. + */ + logger('mod_zot: auth_check', LOGGER_DEBUG); + + if(! $encrypted_packet) { + logger('mod_zot: auth_check packet was not encrypted.'); + $ret['message'] .= 'no packet encryption' . EOL; + json_return_and_die($ret); + } + + $arr = $data['sender']; + $sender_hash = base64url_encode(hash('whirlpool',$arr['guid'] . $arr['guid_sig'], true)); + // garbage collect any old unused notifications + q("delete from verify where type = 'auth' and created < UTC_TIMESTAMP() - INTERVAL 10 MINUTE"); + $y = q("select xchan_pubkey from xchan where xchan_hash = '%s' limit 1", + dbesc($sender_hash) + ); + + // We created a unique hash in mod/magic.php when we invoked remote auth, and stored it in + // the verify table. It is now coming back to us as 'secret' and is signed by a channel at the other end. + // First verify their signature. We will have obtained a zot-info packet from them as part of the sender + // verification. + + if((! $y) || (! rsa_verify($data['secret'],base64url_decode($data['secret_sig']),$y[0]['xchan_pubkey']))) { + logger('mod_zot: auth_check: sender not found or secret_sig invalid.'); + $ret['message'] .= 'sender not found or sig invalid ' . print_r($y,true) . EOL; + json_return_and_die($ret); + } + + // There should be exactly one recipient, the original auth requestor + + $ret['message'] .= 'recipients ' . print_r($recipients,true) . EOL; + + if($data['recipients']) { + + $arr = $data['recipients'][0]; + $recip_hash = base64url_encode(hash('whirlpool',$arr['guid'] . $arr['guid_sig'], true)); + $c = q("select channel_id, channel_account_id, channel_prvkey from channel where channel_hash = '%s' limit 1", + dbesc($recip_hash) + ); + if(! $c) { + logger('mod_zot: auth_check: recipient channel not found.'); + $ret['message'] .= 'recipient not found.' . EOL; + json_return_and_die($ret); } + $confirm = base64url_encode(rsa_sign($data['secret'] . $recip_hash,$c[0]['channel_prvkey'])); + // This additionally checks for forged sites since we already stored the expected result in meta + // and we've already verified that this is them via zot_gethub() and that their key signed our token + + $z = q("select id from verify where channel = %d and type = 'auth' and token = '%s' and meta = '%s' limit 1", + intval($c[0]['channel_id']), + dbesc($data['secret']), + dbesc($data['sender']['url']) + ); + if(! $z) { + logger('mod_zot: auth_check: verification key not found.'); + $ret['message'] .= 'verification key not found' . EOL; + json_return_and_die($ret); + } + $r = q("delete from verify where id = %d limit 1", + intval($z[0]['id']) + ); + + $u = q("select account_service_class from account where account_id = %d limit 1", + intval($c[0]['channel_account_id']) + ); + + logger('mod_zot: auth_check: success', LOGGER_DEBUG); + $ret['success'] = true; + $ret['confirm'] = $confirm; + if($u && $u[0]['account_service_class']) + $ret['service_class'] = $u[0]['account_service_class']; + json_return_and_die($ret); + + } + json_return_and_die($ret); + } + + + if($msgtype === 'purge') { + if($recipients) { + // basically this means "unfriend" + foreach($recipients as $recip) { + $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($recip['guid']), + dbesc($recip['guid_sig']) + ); + if($r) { + $r = q("select abook_id from abook where uid = %d and abook_xchan = '%s' limit 1", + intval($r[0]['channel_id']), + dbesc(base64url_encode(hash('whirlpool',$sender['guid'] . $sender['guid_sig'], true))) + ); + if($r) { + contact_remove($r[0]['channel_id'],$r[0]['abook_id']); + } + } + } } else { - // basically this means the channel has committed suicide + // Unfriend everybody - basically this means the channel has committed suicide $arr = $data['sender']; $sender_hash = base64url_encode(hash('whirlpool',$arr['guid'] . $arr['guid_sig'], true)); require_once('include/Contact.php'); remove_all_xchan_resources($sender_hash); - $ret['result'] = true; + $ret['success'] = true; json_return_and_die($ret); } } - if($msgtype === 'refresh') { + + if(($msgtype === 'refresh') || ($msgtype === 'force_refresh')) { // remote channel info (such as permissions or photo or something) // has been updated. Grab a fresh copy and sync it. + // The difference between refresh and force_refresh is that + // force_refresh unconditionally creates a directory update record, + // even if no changes were detected upon processing. if($recipients) { @@ -282,7 +820,7 @@ function post_post(&$a) { 'xchan_guid' => $sender['guid'], 'xchan_guid_sig' => $sender['guid_sig'], 'hubloc_url' => $sender['url'] - ),$r[0]); + ),$r[0], (($msgtype === 'force_refresh') ? true : false)); } } else { @@ -293,9 +831,9 @@ function post_post(&$a) { 'xchan_guid' => $sender['guid'], 'xchan_guid_sig' => $sender['guid_sig'], 'hubloc_url' => $sender['url'] - ),null); + ),null,(($msgtype === 'force_refresh') ? true : false)); } - $ret['result'] = true; + $ret['success'] = true; json_return_and_die($ret); } @@ -311,67 +849,11 @@ function post_post(&$a) { $ret['delivery_report'] = $x; } - $ret['result'] = true; + $ret['success'] = true; json_return_and_die($ret); } - if($msgtype === 'auth_check') { - $arr = $data['sender']; - $sender_hash = base64url_encode(hash('whirlpool',$arr['guid'] . $arr['guid_sig'], true)); - - // garbage collect any old unused notifications - q("delete from verify where type = 'auth' and created < UTC_TIMESTAMP() - INTERVAL 10 MINUTE"); - - $y = q("select xchan_pubkey from xchan where xchan_hash = '%s' limit 1", - dbesc($sender_hash) - ); - // We created a unique hash in mod/magic.php when we invoked remote auth, and stored it in - // the verify table. It is now coming back to us as 'secret' and is signed by the other site. - // First verify their signature. - - if((! $y) || (! rsa_verify($data['secret'],base64url_decode($data['secret_sig']),$y[0]['xchan_pubkey']))) { - logger('mod_zot: auth_check: sender not found or secret_sig invalid.'); - json_return_and_die($ret); - } - - // There should be exactly one recipient - if($data['recipients']) { - - $arr = $data['recipients'][0]; - $recip_hash = base64url_encode(hash('whirlpool',$arr['guid'] . $arr['guid_sig'], true)); - $c = q("select channel_id from channel where channel_hash = '%s' limit 1", - dbesc($recip_hash) - ); - if(! $c) { - logger('mod_zot: auth_check: recipient channel not found.'); - json_return_and_die($ret); - } - - // This additionally checks for forged senders since we already stored the expected result in meta - // and we've already verified that this is them via zot_gethub() and that their key signed our token - - $z = q("select id from verify where channel = %d and type = 'auth' and token = '%s' and meta = '%s' limit 1", - intval($c[0]['channel_id']), - dbesc($data['secret']), - dbesc($sender_hash) - ); - if(! $z) { - logger('mod_zot: auth_check: verification key not found.'); - json_return_and_die($ret); - } - $r = q("delete from verify where id = %d limit 1", - intval($z[0]['id']) - ); - - logger('mod_zot: auth_check: success', LOGGER_DEBUG); - $ret['result'] = true; - json_return_and_die($ret); - - } - json_return_and_die($ret); - } - // catchall json_return_and_die($ret); diff --git a/mod/probe.php b/mod/probe.php index f90728df2..8e0b60dcc 100644 --- a/mod/probe.php +++ b/mod/probe.php @@ -1,6 +1,5 @@ <?php -require_once('include/Scrape.php'); require_once('include/zot.php'); function probe_content(&$a) { @@ -16,11 +15,22 @@ function probe_content(&$a) { if(x($_GET,'addr')) { $channel = $a->get_channel(); $addr = trim($_GET['addr']); - $res = zot_finger($addr,$channel); + $res = zot_finger($addr,$channel,false); $o .= '<pre>'; - $j = json_decode($res['body'],true); + if($res['success']) + $j = json_decode($res['body'],true); + else { + $o .= sprintf( t('Fetching URL returns error: %1$s'),$res['error'] . "\r\n\r\n"); + $o .= "<strong>https connection failed. Trying again with auto failover to http.</strong>\r\n\r\n"; + $res = zot_finger($addr,$channel,true); + if($res['success']) + $j = json_decode($res['body'],true); + else + $o .= sprintf( t('Fetching URL returns error: %1$s'),$res['error'] . "\r\n\r\n"); + + } if($j && $j['permissions'] && $j['permissions']['iv']) - $j['permissions'] = json_decode(aes_unencapsulate($j['permissions'],$channel['channel_prvkey']),true); + $j['permissions'] = json_decode(crypto_unencapsulate($j['permissions'],$channel['channel_prvkey']),true); $o .= str_replace("\n",'<br />',print_r($j,true)); $o .= '</pre>'; } diff --git a/mod/profile.php b/mod/profile.php index 2f869a533..792bf34c5 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -1,4 +1,12 @@ -<?php +<?php /** @file */ + +require_once('include/contact_widgets.php'); +require_once('include/items.php'); +require_once("include/bbcode.php"); +require_once('include/security.php'); +require_once('include/conversation.php'); +require_once('include/acl_selectors.php'); + function profile_init(&$a) { @@ -10,103 +18,64 @@ function profile_init(&$a) { return; } - $profile = 0; + $profile = ''; $channel = $a->get_channel(); if((local_user()) && (argc() > 2) && (argv(2) === 'view')) { $which = $channel['channel_address']; $profile = argv(1); + $r = q("select profile_guid from profile where id = %d and uid = %d limit 1", + intval($profile), + intval(local_user()) + ); + if(! $r) + $profile = ''; + $profile = $r[0]['profile_guid']; } $a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $a->get_baseurl() . '/feed/' . $which .'" />' . "\r\n" ; - $x = q("select channel_id as profile_uid from channel where channel_address = '%s' limit 1", - dbesc(argv(1)) - ); - if($x) { - $a->profile = $x[0]; -// $channel_display = get_pconfig($a->profile['profile_uid'],'system','channel_format'); -// if(! $channel_display) - profile_load($a,$which,$profile); + if(! $profile) { + $x = q("select channel_id as profile_uid from channel where channel_address = '%s' limit 1", + dbesc(argv(1)) + ); + if($x) { + $a->profile = $x[0]; + } } -} - - -function profile_aside(&$a) { - - require_once('include/contact_widgets.php'); - require_once('include/items.php'); + profile_load($a,$which,$profile); - profile_create_sidebar($a); } - function profile_content(&$a, $update = 0) { if(get_config('system','block_public') && (! get_account_id()) && (! remote_user())) { return login(); } - - require_once("include/bbcode.php"); - require_once('include/security.php'); - require_once('include/conversation.php'); - require_once('include/acl_selectors.php'); - require_once('include/items.php'); - $groups = array(); $tab = 'profile'; $o = ''; - - $contact = null; - $remote_contact = false; - - $contact_id = 0; - - if(is_array($_SESSION['remote'])) { - foreach($_SESSION['remote'] as $v) { - if($v['uid'] == $a->profile['profile_uid']) { - $contact_id = $v['cid']; - break; - } - } - } - - if($contact_id) { - $groups = init_groups_visitor($contact_id); - $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", - intval($contact_id), - intval($a->profile['profile_uid']) - ); - if(count($r)) { - $contact = $r[0]; - $remote_contact = true; - } + if(! (perm_is_allowed($a->profile['profile_uid'],get_observer_hash(), 'view_profile'))) { + notice( t('Permission denied.') . EOL); + return; } - if(! $remote_contact) { - if(local_user()) { - $contact_id = $_SESSION['cid']; - $contact = $a->contact; - } - } $is_owner = ((local_user()) && (local_user() == $a->profile['profile_uid']) ? true : false); - if($a->profile['hidewall'] && (! $is_owner) && (! $remote_contact)) { - notice( t('Access to this profile has been restricted.') . EOL); + if($a->profile['hidewall'] && (! $is_owner) && (! remote_user())) { + notice( t('Permission denied.') . EOL); return; } - $o .= profile_tabs($a, $is_owner, $a->profile['channel_address']); - require_once('include/profile_advanced.php'); $o .= advanced_profile($a); call_hooks('profile_advanced',$o); return $o; diff --git a/mod/profile_photo.php b/mod/profile_photo.php index ea7a01bc9..c587b9606 100644 --- a/mod/profile_photo.php +++ b/mod/profile_photo.php @@ -1,28 +1,82 @@ <?php -require_once("Photo.php"); +/* @file profile_photo.php + @brief Module-file with functions for handling of profile-photos -function profile_photo_init(&$a) { +*/ - if(! local_user()) { - return; +require_once('include/photo/photo_driver.php'); + +/* @brief Function for sync'ing permissions of profile-photos and their profile +* +* @param $profileid The id number of the profile to sync +* @return void +*/ + +function profile_photo_set_profile_perms($profileid = '') { + + $allowcid = ''; + if (x($profileid)) { + + $r = q("SELECT photo, profile_guid, id, is_default, uid FROM profile WHERE profile.id = %d OR profile.profile_guid = '%s' LIMIT 1", intval($profileid), dbesc($profileid)); + + } else { + + logger('Resetting permissions on default-profile-photo for user'.local_user()); + $r = q("SELECT photo, profile_guid, id, is_default, uid FROM profile WHERE profile.uid = %d AND is_default = 1 LIMIT 1", intval(local_user()) ); //If no profile is given, we update the default profile } - $channel = $a->get_channel(); - profile_load($a,$channel['channel_address']); + $profile = $r[0]; + if(x($profile['id']) && x($profile['photo'])) { + preg_match("@\w*(?=-\d*$)@i", $profile['photo'], $resource_id); + $resource_id = $resource_id[0]; + + if (intval($profile['is_default']) != 1) { + $r0 = q("SELECT channel_hash FROM channel WHERE channel_id = %d LIMIT 1", intval(local_user()) ); + $r1 = q("SELECT abook.abook_xchan FROM abook WHERE abook_profile = %d ", intval($profile['id'])); //Should not be needed in future. Catches old int-profile-ids. + $r2 = q("SELECT abook.abook_xchan FROM abook WHERE abook_profile = '%s'", dbesc($profile['profile_guid'])); + $allowcid = "<" . $r0[0]['channel_hash'] . ">"; + foreach ($r1 as $entry) { + $allowcid .= "<" . $entry['abook_xchan'] . ">"; + } + foreach ($r2 as $entry) { + $allowcid .= "<" . $entry['abook_xchan'] . ">"; + } + + q("UPDATE `photo` SET allow_cid = '%s' WHERE resource_id = '%s' AND uid = %d",dbesc($allowcid),dbesc($resource_id),intval($profile['uid'])); + + } else { + q("UPDATE `photo` SET allow_cid = '' WHERE profile = 1 AND uid = %d",intval($profile['uid'])); //Reset permissions on default profile picture to public + } + } + return; } +/* @brief Initalize the profile-photo edit view + * + * @param $a Current application + * @return void + * + */ -function profile_photo_aside(&$a) { +function profile_photo_init(&$a) { if(! local_user()) { return; } - profile_create_sidebar($a); + $channel = $a->get_channel(); + profile_load($a,$channel['channel_address']); + } +/* @brief Evaluate posted values + * + * @param $a Current application + * @return void + * + */ function profile_photo_post(&$a) { @@ -42,7 +96,7 @@ function profile_photo_post(&$a) { intval($_REQUEST['profile']), intval(local_user()) ); - if(count($r) && (! intval($r[0]['is_default']))) + if(($r) && (! intval($r[0]['is_default']))) $is_default_profile = 0; } @@ -77,25 +131,30 @@ function profile_photo_post(&$a) { $base_image = $r[0]; - $im = new Photo($base_image['data'], $base_image['type']); + $im = photo_factory($base_image['data'], $base_image['type']); if($im->is_valid()) { $im->cropImage(175,$srcX,$srcY,$srcW,$srcH); $aid = get_account_id(); - $r1 = $im->store($aid, local_user(), '', $base_image['resource_id'],$base_image['filename'], - t('Profile Photos'), 4, $is_default_profile); + $p = array('aid' => $aid, 'uid' => local_user(), 'resource_id' => $base_image['resource_id'], + 'filename' => $base_image['filename'], 'album' => t('Profile Photos')); + + $p['scale'] = 4; + $p['photo_flags'] = (($is_default_profile) ? PHOTO_PROFILE : PHOTO_NORMAL); + + $r1 = $im->save($p); $im->scaleImage(80); + $p['scale'] = 5; - $r2 = $im->store($aid, local_user(), '', $base_image['resource_id'],$base_image['filename'], - t('Profile Photos'), 5, $is_default_profile); + $r2 = $im->save($p); $im->scaleImage(48); + $p['scale'] = 6; - $r3 = $im->store($aid, local_user(), '', $base_image['resource_id'],$base_image['filename'], - t('Profile Photos'), 6, $is_default_profile); + $r3 = $im->save($p); if($r1 === false || $r2 === false || $r3 === false) { // if one failed, delete them all so we can start over. @@ -114,6 +173,13 @@ function profile_photo_post(&$a) { dbesc($base_image['resource_id']), intval(local_user()) ); + $r = q("UPDATE photo SET photo_flags = ( photo_flags ^ %d ) WHERE ( photo_flags & %d ) + AND resource_id != '%s' AND `uid` = %d", + intval(PHOTO_PROFILE), + intval(PHOTO_PROFILE), + dbesc($base_image['resource_id']), + intval(local_user()) + ); } else { $r = q("update profile set photo = '%s', thumb = '%s' where id = %d and uid = %d limit 1", @@ -140,6 +206,11 @@ function profile_photo_post(&$a) { // Update directory in background proc_run('php',"include/directory.php",$channel['channel_id']); + + // Now copy profile-permissions to pictures, to prevent privacyleaks by automatically created folder 'Profile Pictures' + + profile_photo_set_profile_perms($_REQUEST['profile']); + } else notice( t('Unable to process image') . EOL); @@ -164,7 +235,7 @@ function profile_photo_post(&$a) { } $imagedata = @file_get_contents($src); - $ph = new Photo($imagedata, $filetype); + $ph = photo_factory($imagedata, $filetype); if(! $ph->is_valid()) { notice( t('Unable to process image.') . EOL ); @@ -177,6 +248,13 @@ function profile_photo_post(&$a) { } +/* @brief Generate content of profile-photo view + * + * @param $a Current application + * @return void + * + */ + if(! function_exists('profile_photo_content')) { function profile_photo_content(&$a) { @@ -224,24 +302,35 @@ function profile_photo_content(&$a) { // unset any existing profile photos $r = q("UPDATE photo SET profile = 0 WHERE profile = 1 AND uid = %d", intval(local_user())); - + $r = q("UPDATE photo SET photo_flags = (photo_flags ^ %d ) WHERE (photo_flags & %d ) AND uid = %d", + intval(PHOTO_PROFILE), + intval(PHOTO_PROFILE), + intval(local_user())); + // 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_user()), dbesc($resource_id) ); + $r = q("UPDATE photo SET photo_flags = ( photo_flags | %d ) WHERE uid = %d AND resource_id = '%s'", + intval(PHOTO_PROFILE), + intval(local_user()), + dbesc($resource_id) + ); + $r = q("UPDATE xchan set xchan_photo_date = '%s' where xchan_hash = '%s' limit 1", dbesc(datetime_convert()), dbesc($channel['xchan_hash']) ); - proc_run('php','include/directory.php',local_user()); + profile_photo_set_profile_perms(); //Reset default photo permissions to public + proc_run('php','include/directory.php',local_user()); 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` FROM photo WHERE id = %d and uid = %d limit 1", intval($r[0]['id']), intval(local_user()) @@ -251,7 +340,7 @@ function profile_photo_content(&$a) { return; } - $ph = new Photo($r[0]['data'], $r[0]['type']); + $ph = photo_factory($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); } @@ -261,7 +350,7 @@ function profile_photo_content(&$a) { ); if(! x($a->data,'imagecrop')) { - + $tpl = get_markup_template('profile_photo.tpl'); $o .= replace_macros($tpl,array( @@ -298,6 +387,14 @@ function profile_photo_content(&$a) { return; // NOTREACHED }} +/* @brief Generate the UI for photo-cropping + * + * @param $a Current application + * @param $ph Photo-Factory + * @return void + * + */ + if(! function_exists('profile_photo_crop_ui_head')) { function profile_photo_crop_ui_head(&$a, $ph){ @@ -320,7 +417,9 @@ function profile_photo_crop_ui_head(&$a, $ph){ $hash = photo_new_resource(); $smallest = 0; - $r = $ph->store(get_account_id(), local_user(), '', $hash, $filename, t('Profile Photos'), 0 ); + $p = array('aid' => get_account_id(), 'uid' => local_user(), 'resource_id' => $hash, + 'filename' => $filename, 'album' => t('Profile Photos'), 'scale' => 0); + $r = $ph->save($p); if($r) info( t('Image uploaded successfully.') . EOL ); @@ -329,8 +428,10 @@ function profile_photo_crop_ui_head(&$a, $ph){ if($width > 640 || $height > 640) { $ph->scaleImage(640); - $r = $ph->store(get_account_id(), local_user(), '' , $hash, $filename, t('Profile Photos'), 1 ); - + $p['scale'] = 1; + + $r = $ph->save($p); + if($r === false) notice( sprintf(t('Image size reduction [%s] failed.'),"640") . EOL ); else diff --git a/mod/profiles.php b/mod/profiles.php index e857c4216..481680a12 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -47,7 +47,7 @@ function profiles_init(&$a) { if((argc() > 1) && (argv(1) === 'new')) { - check_form_security_token_redirectOnErr('/profiles', 'profile_new', 't'); +// check_form_security_token_redirectOnErr('/profiles', 'profile_new', 't'); $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d", intval(local_user())); @@ -59,7 +59,7 @@ function profiles_init(&$a) { intval(local_user())); $r2 = q("INSERT INTO `profile` (`aid`, `uid` , `profile_guid`, `profile_name` , `name`, `photo`, `thumb`) - VALUES ( %d, '%s', '%s', '%s', '%s' )", + VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s' )", intval(get_account_id()), intval(local_user()), dbesc(random_string()), @@ -146,17 +146,6 @@ function profiles_init(&$a) { } } -function profiles_aside(&$a) { - - if(! local_user()) { - return; - } - - if((argc() > 1) && (intval(argv(1)))) { - profile_create_sidebar($a); - } -} - function profiles_post(&$a) { if(! local_user()) { @@ -200,31 +189,36 @@ function profiles_post(&$a) { $day = intval($_POST['day']); if(($day > $mtab[$month]) || ($day < 0)) $day = 0; + +// if($year && (! ($month && $day))) { +// $month = 1; $day = 1; +// } + $dob = '0000-00-00'; $dob = sprintf('%04d-%02d-%02d',$year,$month,$day); - $name = notags(trim($_POST['name'])); + $name = escape_tags(trim($_POST['name'])); if($orig[0]['name'] != $name) $namechanged = true; - $pdesc = notags(trim($_POST['pdesc'])); - $gender = notags(trim($_POST['gender'])); - $address = notags(trim($_POST['address'])); - $locality = notags(trim($_POST['locality'])); - $region = notags(trim($_POST['region'])); - $postal_code = notags(trim($_POST['postal_code'])); - $country_name = notags(trim($_POST['country_name'])); - $keywords = notags(trim($_POST['keywords'])); - $marital = notags(trim($_POST['marital'])); - $howlong = notags(trim($_POST['howlong'])); - $sexual = notags(trim($_POST['sexual'])); - $homepage = notags(trim($_POST['homepage'])); - $hometown = notags(trim($_POST['hometown'])); - $politic = notags(trim($_POST['politic'])); - $religion = notags(trim($_POST['religion'])); + $pdesc = escape_tags(trim($_POST['pdesc'])); + $gender = escape_tags(trim($_POST['gender'])); + $address = escape_tags(trim($_POST['address'])); + $locality = escape_tags(trim($_POST['locality'])); + $region = escape_tags(trim($_POST['region'])); + $postal_code = escape_tags(trim($_POST['postal_code'])); + $country_name = escape_tags(trim($_POST['country_name'])); + $keywords = escape_tags(trim($_POST['keywords'])); + $marital = escape_tags(trim($_POST['marital'])); + $howlong = escape_tags(trim($_POST['howlong'])); + $sexual = escape_tags(trim($_POST['sexual'])); + $homepage = escape_tags(trim($_POST['homepage'])); + $hometown = escape_tags(trim($_POST['hometown'])); + $politic = escape_tags(trim($_POST['politic'])); + $religion = escape_tags(trim($_POST['religion'])); $likes = fix_mce_lf(escape_tags(trim($_POST['likes']))); $dislikes = fix_mce_lf(escape_tags(trim($_POST['dislikes']))); @@ -232,6 +226,7 @@ function profiles_post(&$a) { $about = fix_mce_lf(escape_tags(trim($_POST['about']))); $interest = fix_mce_lf(escape_tags(trim($_POST['interest']))); $contact = fix_mce_lf(escape_tags(trim($_POST['contact']))); + $channels = fix_mce_lf(escape_tags(trim($_POST['channels']))); $music = fix_mce_lf(escape_tags(trim($_POST['music']))); $book = fix_mce_lf(escape_tags(trim($_POST['book']))); $tv = fix_mce_lf(escape_tags(trim($_POST['tv']))); @@ -242,7 +237,7 @@ function profiles_post(&$a) { $hide_friends = (($_POST['hide_friends'] == 1) ? 1: 0); - $with = ((x($_POST,'with')) ? notags(trim($_POST['with'])) : ''); + $with = ((x($_POST,'with')) ? escape_tags(trim($_POST['with'])) : ''); if(! strlen($howlong)) $howlong = '0000-00-00 00:00:00'; @@ -261,35 +256,23 @@ function profiles_post(&$a) { if(strpos($lookup,'@') === 0) $lookup = substr($lookup,1); $lookup = str_replace('_',' ', $lookup); - if(strpos($lookup,'@') || (strpos($lookup,'http://'))) { - $newname = $lookup; - $links = @lrdd($lookup); - if(count($links)) { - foreach($links as $link) { - if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') { - $prf = $link['@attributes']['href']; - } - } - } - } - else { - $newname = $lookup; - - $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1", - dbesc($newname), + $newname = $lookup; + + $r = q("SELECT * FROM abook left join xchan on abook_xchan = xchan_hash WHERE xchan_name = '%s' AND abook_channel = %d LIMIT 1", + dbesc($newname), + intval(local_user()) + ); + if(! $r) { + $r = q("SELECT * FROM abook left join xchan on abook_xchan = xchan_hash WHERE xchan_addr = '%s' AND abook_channel = %d LIMIT 1", + dbesc($lookup . '@%'), intval(local_user()) ); - if(! $r) { - $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1", - dbesc($lookup), - intval(local_user()) - ); - } - if(count($r)) { - $prf = $r[0]['url']; - $newname = $r[0]['name']; - } } + if($r) { + $prf = $r[0]['xchan_url']; + $newname = $r[0]['xchan_name']; + } + if($prf) { $with = str_replace($lookup,'<a href="' . $prf . '">' . $newname . '</a>', $with); @@ -393,6 +376,7 @@ function profiles_post(&$a) { `about` = '%s', `interest` = '%s', `contact` = '%s', + `channels` = '%s', `music` = '%s', `book` = '%s', `tv` = '%s', @@ -426,6 +410,7 @@ function profiles_post(&$a) { dbesc($about), dbesc($interest), dbesc($contact), + dbesc($channels), dbesc($music), dbesc($book), dbesc($tv), @@ -444,7 +429,7 @@ function profiles_post(&$a) { $channel = $a->get_channel(); if($namechanged && $is_default) { - $r = q("UPDATE xchan SET xchan_name = '%s', xchan_name_date` = '%s' WHERE xchan_hash = '%s' limit 1", + $r = q("UPDATE xchan SET xchan_name = '%s', xchan_name_date = '%s' WHERE xchan_hash = '%s' limit 1", dbesc($name), dbesc(datetime_convert()), dbesc($channel['xchan_hash']) @@ -516,6 +501,7 @@ function profiles_content(&$a) { '$profile_drop_link' => 'profiles/drop/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_drop"), + '$guid' => $r[0]['profile_guid'], '$banner' => t('Edit Profile Details'), '$submit' => t('Submit'), '$viewprof' => t('View this profile'), @@ -550,6 +536,7 @@ function profiles_content(&$a) { '$lbl_about' => t('Tell us about yourself...'), '$lbl_hobbies' => t('Hobbies/Interests'), '$lbl_social' => t('Contact information and Social Networks'), + '$lbl_channels' => t('My other channels'), '$lbl_music' => t('Musical interests'), '$lbl_book' => t('Books, literature'), '$lbl_tv' => t('Television'), @@ -574,7 +561,7 @@ function profiles_content(&$a) { '$age' => ((intval($r[0]['dob'])) ? '(' . t('Age: ') . age($r[0]['dob'],$a->user['timezone'],$a->user['timezone']) . ')' : ''), '$gender' => gender_selector($r[0]['gender']), '$marital' => marital_selector($r[0]['marital']), - '$with' => strip_tags($r[0]['with']), + '$with' => $r[0]['with'], '$howlong' => ($r[0]['howlong'] === '0000-00-00 00:00:00' ? '' : datetime_convert('UTC',date_default_timezone_get(),$r[0]['howlong'])), '$sexual' => sexpref_selector($r[0]['sexual']), '$about' => $r[0]['about'], @@ -593,7 +580,8 @@ function profiles_content(&$a) { '$romance' => $r[0]['romance'], '$work' => $r[0]['work'], '$education' => $r[0]['education'], - '$contact' => $r[0]['contact'] + '$contact' => $r[0]['contact'], + '$channels' => $r[0]['channels'], )); $arr = array('profile' => $r[0], 'entry' => $o); @@ -610,6 +598,8 @@ function profiles_content(&$a) { $tpl_header = get_markup_template('profile_listing_header.tpl'); $o .= replace_macros($tpl_header,array( '$header' => t('Edit/Manage Profiles'), + '$addstuff' => t('Add profile things'), + '$stuff_desc' => t('Include desirable objects in your profile'), '$chg_photo' => t('Change profile photo'), '$cr_new' => t('Create New Profile'), '$cr_new_link' => 'profiles/new?t=' . get_form_security_token("profile_new") diff --git a/mod/profperm.php b/mod/profperm.php index 8054851e8..197062936 100644 --- a/mod/profperm.php +++ b/mod/profperm.php @@ -1,24 +1,19 @@ <?php +require_once('include/Contact.php'); + function profperm_init(&$a) { if(! local_user()) return; - $which = $a->user['nickname']; - $profile = $a->argv[1]; - - profile_load($a,$which,$profile); - -} - + $channel = $a->get_channel(); + $which = $channel['channel_address']; -function profperm_aside(&$a) { + $profile = $a->argv[1]; - if(! local_user()) - return; + profile_load($a,$which,$profile); - profile_create_sidebar($a); } @@ -30,7 +25,7 @@ function profperm_content(&$a) { } - if($a->argc < 2) { + if(argc() < 2) { notice( t('Invalid profile identifier.') . EOL ); return; } @@ -44,59 +39,64 @@ function profperm_content(&$a) { $switchtotext = 400; - if(($a->argc > 2) && intval($a->argv[1]) && intval($a->argv[2])) { - $r = q("SELECT `id` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `self` = 0 - AND `network` = 'dfrn' AND `id` = %d AND `uid` = %d LIMIT 1", - intval($a->argv[2]), + if((argc() > 2) && intval(argv(1)) && intval(argv(2))) { + $r = q("SELECT abook_id FROM abook WHERE abook_id = %d and abook_channel = %d limit 1", + intval(argv(2)), intval(local_user()) ); - if(count($r)) - $change = intval($a->argv[2]); + if($r) + $change = intval(argv(2)); } - if(($a->argc > 1) && (intval($a->argv[1]))) { + if((argc() > 1) && (intval(argv(1)))) { $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is_default` = 0 LIMIT 1", - intval($a->argv[1]), + intval(argv(1)), intval(local_user()) ); - if(! count($r)) { + if(! $r) { notice( t('Invalid profile identifier.') . EOL ); return; } + $profile = $r[0]; - $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `profile_id` = %d", + $r = q("SELECT * FROM abook left join xchan on abook_xchan = xchan_hash WHERE abook_channel = %d AND abook_profile = '%s'", intval(local_user()), - intval($a->argv[1]) + dbesc($profile['profile_guid']) ); $ingroup = array(); - if(count($r)) + if($r) foreach($r as $member) - $ingroup[] = $member['id']; + $ingroup[] = $member['abook_id']; $members = $r; if($change) { if(in_array($change,$ingroup)) { - q("UPDATE `contact` SET `profile_id` = 0 WHERE `id` = %d AND `uid` = %d LIMIT 1", + q("UPDATE abook SET abook_profile = '' WHERE abook_id = %d AND abook_channel = %d LIMIT 1", intval($change), intval(local_user()) ); } else { - q("UPDATE `contact` SET `profile_id` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1", - intval($a->argv[1]), + q("UPDATE abook SET abook_profile = '%s' WHERE abook_id = %d AND abook_channel = %d LIMIT 1", + dbesc($profile['profile_guid']), intval($change), intval(local_user()) ); } - $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `profile_id` = %d", + + //Time to update the permissions on the profile-pictures as well + require_once('mod/profile_photo.php'); + profile_photo_set_profile_perms($profile['id']); + + $r = q("SELECT * FROM abook left join xchan on abook_xchan = xchan_hash WHERE abook_channel = %d AND abook_profile = '%s'", intval(local_user()), - intval($a->argv[1]) + dbesc($profile['profile_guid']) ); $members = $r; @@ -104,7 +104,7 @@ function profperm_content(&$a) { $ingroup = array(); if(count($r)) foreach($r as $member) - $ingroup[] = $member['id']; + $ingroup[] = $member['abook_id']; } $o .= '<h2>' . t('Profile Visibility Editor') . '</h2>'; @@ -116,9 +116,9 @@ function profperm_content(&$a) { } $o .= '<div id="prof-update-wrapper">'; - if($change) + if($change) $o = ''; - + $o .= '<div id="prof-members-title">'; $o .= '<h3>' . t('Visible To') . '</h3>'; $o .= '</div>'; @@ -127,8 +127,8 @@ function profperm_content(&$a) { $textmode = (($switchtotext && (count($members) > $switchtotext)) ? true : false); foreach($members as $member) { - if($member['url']) { - $member['click'] = 'profChangeMember(' . $profile['id'] . ',' . $member['id'] . '); return true;'; + if($member['xchan_url']) { + $member['click'] = 'profChangeMember(' . $profile['id'] . ',' . $member['abook_id'] . '); return false;'; $o .= micropro($member,true,'mpprof', $textmode); } } @@ -136,20 +136,17 @@ function profperm_content(&$a) { $o .= '<hr id="prof-separator" />'; $o .= '<div id="prof-all-contcts-title">'; - $o .= '<h3>' . t("All Contacts \x28with secure profile access\x29") . '</h3>'; + $o .= '<h3>' . t("All Connections") . '</h3>'; $o .= '</div>'; $o .= '<div id="prof-all-contacts">'; - - $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0 and `pending` = 0 and `self` = 0 - AND `network` = 'dfrn' ORDER BY `name` ASC", - intval(local_user()) - ); - if(count($r)) { + $r = abook_connections(local_user()); + + if($r) { $textmode = (($switchtotext && (count($r) > $switchtotext)) ? true : false); foreach($r as $member) { - if(! in_array($member['id'],$ingroup)) { - $member['click'] = 'profChangeMember(' . $profile['id'] . ',' . $member['id'] . '); return true;'; + if(! in_array($member['abook_id'],$ingroup)) { + $member['click'] = 'profChangeMember(' . $profile['id'] . ',' . $member['abook_id'] . '); return false;'; $o .= micropro($member,true,'mpprof',$textmode); } } diff --git a/mod/pubsites.php b/mod/pubsites.php new file mode 100644 index 000000000..c31bbcf97 --- /dev/null +++ b/mod/pubsites.php @@ -0,0 +1,36 @@ +<?php + +function pubsites_content(&$a) { + require_once('include/dir_fns.php'); + $dirmode = intval(get_config('system','directory_mode')); + + if(($dirmode == DIRECTORY_MODE_PRIMARY) || ($dirmode == DIRECTORY_MODE_STANDALONE)) { + $url = z_root() . '/dirsearch'; + } + if(! $url) { + $directory = find_upstream_directory($dirmode); + $url = $directory['url'] . '/dirsearch'; + } + $url .= '/sites'; + + $o .= '<h1>' . t('Public Sites') . '</h1>'; + + $o .= '<div class="descriptive-text">' . + t('The listed sites allow public registration into the Red Matrix. All sites in the matrix are interlinked so membership on any of them conveys membership in the matrix as a whole. Some sites may require subscription or provide tiered service plans. The provider links <strong>may</strong> provide additional details.') . '</div>' . EOL; + + $ret = z_fetch_url($url); + if($ret['success']) { + $j = json_decode($ret['body'],true); + if($j) { + $o .= '<table border="1"><tr><td>' . t('Site URL') . '</td><td>' . t('Access Type') . '</td><td>' . t('Registration Policy') . '</td><td>' . t('Location') . '</td></tr>'; + if($j['sites']) { + foreach($j['sites'] as $jj) { + $o .= '<tr><td>' . '<a href="'. (($jj['sellpage']) ? $jj['sellpage'] : $jj['url'] . '/register' ) . '" >' . $jj['url'] . '</a>' . '</td><td>' . $jj['access'] . '</td><td>' . $jj['register'] . '</td><td>' . $jj['location'] . '</td></tr>'; + } + } + + $o .= '</table>'; + } + } + return $o; +} diff --git a/mod/qsearch.php b/mod/qsearch.php deleted file mode 100644 index c35e253b6..000000000 --- a/mod/qsearch.php +++ /dev/null @@ -1,50 +0,0 @@ -<?php - -function qsearch_init(&$a) { - - if(! local_user()) - killme(); - - $limit = (get_config('system','qsearch_limit') ? intval(get_config('system','qsearch_limit')) : 100); - - $search = ((x($_GET,'s')) ? notags(trim(urldecode($_GET['s']))) : ''); - - if(! strlen($search)) - killme(); - - - if($search) - $search = dbesc($search); - - $results = array(); - - $r = q("SELECT * FROM `group` WHERE `name` REGEXP '$search' AND `deleted` = 0 AND `uid` = %d LIMIT 0, %d ", - intval(local_user()), - intval($limit) - ); - - if(count($r)) { - - foreach($r as $rr) - $results[] = array( 0, (int) $rr['id'], $rr['name'], '', ''); - } - - $sql_extra = ((strlen($search)) ? " AND (`name` REGEXP '$search' OR `nick` REGEXP '$search') " : ""); - - - $r = q("SELECT * FROM `contact` WHERE `uid` = %d $sql_extra ORDER BY `name` ASC LIMIT 0, %d ", - intval(local_user()), - intval($limit) - ); - - - if(count($r)) { - - foreach($r as $rr) - $results[] = array( (int) $rr['id'], 0, $rr['name'],$rr['url'],$rr['photo']); - } - - echo json_encode((object) $results); - killme(); -} - diff --git a/mod/randprof.php b/mod/randprof.php index 0726b231a..bddb3251a 100644 --- a/mod/randprof.php +++ b/mod/randprof.php @@ -5,6 +5,7 @@ function randprof_init(&$a) { require_once('include/Contact.php'); $x = random_profile(); if($x) - goaway(zid($x)); + goaway(chanlink_url($x)); + // FIXME this doesn't work at the moment as a fallback goaway($a->get_baseurl() . '/profile'); } diff --git a/mod/rbmark.php b/mod/rbmark.php new file mode 100644 index 000000000..e35c2494a --- /dev/null +++ b/mod/rbmark.php @@ -0,0 +1,113 @@ +<?php /** @file */ + +require_once('acl_selectors.php'); +require_once('include/crypto.php'); +require_once('include/items.php'); +require_once('include/taxonomy.php'); +require_once('include/conversation.php'); +require_once('include/zot.php'); +require_once('include/bookmarks.php'); + +/** + * remote bookmark + * + * https://yoursite/rbmark?f=&title=&url=&private=&remote_return= + * + * This can be called via either GET or POST, use POST for long body content as suhosin often limits GET parameter length + * + * f= placeholder, often required + * title= link text + * url= URL to bookmark + * ischat=1 if this bookmark is a chatroom + * private= Don't share this link + * remote_return= absolute URL to return after posting is finished + * + */ + +function rbmark_post(&$a) { + if($_POST['submit'] !== t('Save')) + return; + + logger('rbmark_post: ' . print_r($_REQUEST,true)); + + $channel = $a->get_channel(); + + $t = array('url' => escape_tags($_REQUEST['url']),'term' => escape_tags($_REQUEST['title'])); + bookmark_add($channel,$channel,$t,((x($_REQUEST,'private')) ? intval($_REQUEST['private']) : 0), + array('menu_id' => ((x($_REQUEST,'menu_id')) ? intval($_REQUEST['menu_id']) : 0), + 'menu_name' => ((x($_REQUEST,'menu_name')) ? escape_tags($_REQUEST['menu_name']) : ''), + 'ischat' => ((x($_REQUEST['ischat'])) ? intval($_REQUEST['ischat']) : 0) + )); + + goaway(z_root() . '/bookmarks'); + +} + + +function rbmark_content(&$a) { + + $o = ''; + + if(! local_user()) { + + // The login procedure is going to bugger our $_REQUEST variables + // so save them in the session. + + if(array_key_exists('url',$_REQUEST)) { + $_SESSION['bookmark'] = $_REQUEST; + } + return login(); + } + + // If we have saved rbmark session variables, but nothing in the current $_REQUEST, recover the saved variables + + if((! array_key_exists('url',$_REQUEST)) && (array_key_exists('bookmark',$_SESSION))) { + $_REQUEST = $_SESSION['bookmark']; + unset($_SESSION['bookmark']); + } + + if($_REQUEST['remote_return']) { + $_SESSION['remote_return'] = $_REQUEST['remote_return']; + } + if(argc() > 1 && argv(1) === 'return') { + if($_SESSION['remote_return']) + goaway($_SESSION['remote_return']); + goaway(z_root() . '/bookmarks'); + } + + $channel = $a->get_channel(); + + $m = menu_list($channel,'',MENU_BOOKMARK); + $menus = array(); + if($m) { + $menus = array(0 => ''); + foreach($m as $n) { + $menus[$n['menu_id']] = $n['menu_name']; + } + } + $menu_select = array('menu_id',t('Select a bookmark folder'),false,'',$menus); + + + $o .= replace_macros(get_markup_template('rbmark.tpl'), array( + + '$header' => t('Save Bookmark'), + '$url' => array('url',t('URL of bookmark'),escape_tags($_REQUEST['url'])), + '$title' => array('title',t('Description'),escape_tags($_REQUEST['title'])), + '$ischat' => ((x($_REQUEST,'ischat')) ? intval($_REQUEST['ischat']) : 0), + '$private' => ((x($_REQUEST,'private')) ? intval($_REQUEST['private']) : 0), + '$submit' => t('Save'), + '$menu_name' => array('menu_name',t('Or enter new bookmark folder name'),'',''), + '$menus' => $menu_select + + )); + + + + + + + return $o; + +} + + diff --git a/mod/redir.php b/mod/redir.php deleted file mode 100644 index 113f6c200..000000000 --- a/mod/redir.php +++ /dev/null @@ -1,60 +0,0 @@ -<?php - -function redir_init(&$a) { - - $url = ((x($_GET,'url')) ? $_GET['url'] : ''); - - // traditional DFRN - - if(local_user() && $a->argc > 1 && intval($a->argv[1])) { - - $cid = $a->argv[1]; - - $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", - intval($cid), - intval(local_user()) - ); - - if((! count($r)) || ($r[0]['network'] !== NETWORK_DFRN)) - goaway(z_root()); - - $dfrn_id = $orig_id = (($r[0]['issued_id']) ? $r[0]['issued_id'] : $r[0]['dfrn_id']); - - if($r[0]['duplex'] && $r[0]['issued_id']) { - $orig_id = $r[0]['issued_id']; - $dfrn_id = '1:' . $orig_id; - } - if($r[0]['duplex'] && $r[0]['dfrn_id']) { - $orig_id = $r[0]['dfrn_id']; - $dfrn_id = '0:' . $orig_id; - } - - $sec = random_string(); - - q("INSERT INTO `profile_check` ( `uid`, `cid`, `dfrn_id`, `sec`, `expire`) - VALUES( %d, %s, '%s', '%s', %d )", - intval(local_user()), - intval($cid), - dbesc($dfrn_id), - dbesc($sec), - intval(time() + 45) - ); - - logger('mod_redir: ' . $r[0]['name'] . ' ' . $sec, LOGGER_DEBUG); - $dest = (($url) ? '&destination_url=' . $url : ''); - goaway ($r[0]['poll'] . '?dfrn_id=' . $dfrn_id - . '&dfrn_version=' . DFRN_PROTOCOL_VERSION . '&type=profile&sec=' . $sec . $dest ); - } - - if(local_user()) - $handle = $a->user['nickname'] . '@' . substr($a->get_baseurl(),strpos($a->get_baseurl(),'://')+3); - if(remote_user()) - $handle = $_SESSION['handle']; - - if($url) { - $url = str_replace('{zid}','&zid=' . $handle,$url); - goaway($url); - } - - goaway(z_root()); -} diff --git a/mod/register.php b/mod/register.php index 3ba714c74..990cce2ed 100644 --- a/mod/register.php +++ b/mod/register.php @@ -7,6 +7,14 @@ function register_init(&$a) { $result = null; $cmd = ((argc() > 1) ? argv(1) : ''); + // Provide a stored request for somebody desiring a connection + // when they first need to register someplace. Once they've + // created a channel, we'll try to revive the connection request + // and process it. + + if($_REQUEST['connect']) + $_SESSION['connect'] = $_REQUEST['connect']; + switch($cmd) { case 'invite_check.json': $result = check_account_invite($_REQUEST['invite_code']); @@ -64,6 +72,12 @@ function register_post(&$a) { break; } + + if((! $_POST['password']) || ($_POST['password'] !== $_POST['password2'])) { + notice( t('Passwords do not match.') . EOL); + return; + } + $arr = $_POST; $arr['account_flags'] = $flags; @@ -121,10 +135,17 @@ function register_post(&$a) { function register_content(&$a) { + $registration_is = ''; + $other_sites = ''; if(get_config('system','register_policy') == REGISTER_CLOSED) { - notice("Permission denied." . EOL); - return; + require_once('mod/pubsites.php'); + return pubsites_content($a); + } + + if(get_config('system','register_policy') == REGISTER_APPROVE) { + $registration_is = t('Registration on this site/hub is by approval only.'); + $other_sites = t('<a href="pubsites">Register at another affiliated site/hub</a>'); } $max_dailies = intval(get_config('system','max_daily_registrations')); @@ -161,10 +182,14 @@ function register_content(&$a) { $invite_code = ((x($_REQUEST,'invite_code')) ? strip_tags(trim($_REQUEST['invite_code'])) : "" ); + + $o = replace_macros(get_markup_template('register.tpl'), array( '$title' => t('Registration'), + '$reg_is' => $registration_is, '$registertext' => get_config('system','register_text'), + '$other_sites' => $other_sites, '$invitations' => get_config('system','invitation_only'), '$invite_desc' => t('Membership on this site is by invitation only.'), '$label_invite' => t('Please enter your invitation code'), diff --git a/mod/removeme.php b/mod/removeme.php index ee88bd76a..f0b4ae3c0 100644 --- a/mod/removeme.php +++ b/mod/removeme.php @@ -17,13 +17,17 @@ function removeme_post(&$a) { if($_POST['verify'] !== $_SESSION['remove_account_verify']) return; - $encrypted = hash('whirlpool',trim($_POST['qxz_password'])); - if((strlen($a->user['password'])) && ($encrypted === $a->user['password'])) { - require_once('include/Contact.php'); - user_remove($a->user['uid']); - // NOTREACHED - } + $account = $a->get_account(); + + if(! account_verify_password($account['account_email'],$_POST['qxz_password'])) + return; + + require_once('include/Contact.php'); + + $global_remove = intval($_POST['global']); + + channel_remove(local_user(),1 - $global_remove); } @@ -42,10 +46,11 @@ function removeme_content(&$a) { $o .= replace_macros($tpl, array( '$basedir' => $a->get_baseurl(), '$hash' => $hash, - '$title' => t('Remove My Account'), - '$desc' => t('This will completely remove your account. Once this has been done it is not recoverable.'), + '$title' => t('Remove This Channel'), + '$desc' => t('This will completely remove this channel from the network. Once this has been done it is not recoverable.'), '$passwd' => t('Please enter your password for verification:'), - '$submit' => t('Remove My Account') + '$global' => array('global', t('Remove this channel and all its clones from the network'), false, t('By default only the instance of the channel located on this hub will be removed from the network')), + '$submit' => t('Remove Channel') )); return $o; diff --git a/mod/rmagic.php b/mod/rmagic.php index b8c1c6553..946277327 100644 --- a/mod/rmagic.php +++ b/mod/rmagic.php @@ -22,31 +22,53 @@ function rmagic_init(&$a) { function rmagic_post(&$a) { - $address = $_REQUEST['address']; + $address = trim($_REQUEST['address']); + if(strpos($address,'@') === false) { - notice('Invalid address.'); - return; - } + $arr = array('address' => $address); + call_hooks('reverse_magic_auth', $arr); - $r = null; - if($address) { - $r = q("select hubloc_url from hubloc where hubloc_addr = '%s' limit 1", - dbesc($address) - ); - } - if($r) { - $url = $r[0]['hubloc_url']; + try { + require_once('library/openid/openid.php'); + $openid = new LightOpenID(z_root()); + $openid->identity = $address; + $openid->returnUrl = z_root() . '/openid'; + goaway($openid->authUrl()); + } catch (Exception $e) { + notice( t('We encountered a problem while logging in with the OpenID you provided. Please check the correct spelling of the ID.').'<br /><br >'. t('The error message was:').' '.$e->getMessage()); + } + + // if they're still here... + notice( t('Authentication failed.') . EOL); + return; } else { - $url = 'https://' . substr($address,strpos($address,'@')+1); - } - if($url) { - $dest = z_root() . '/' . str_replace('zid=','zid_=',$a->query_string); - goaway($url . '/magic' . '?f=&dest=' . $dest); - } + // Presumed Red identity. Perform reverse magic auth + + if(strpos($address,'@') === false) { + notice('Invalid address.'); + return; + } + $r = null; + if($address) { + $r = q("select hubloc_url from hubloc where hubloc_addr = '%s' limit 1", + dbesc($address) + ); + } + if($r) { + $url = $r[0]['hubloc_url']; + } + else { + $url = 'https://' . substr($address,strpos($address,'@')+1); + } + if($url) { + $dest = z_root() . '/' . str_replace('zid=','zid_=',$a->query_string); + goaway($url . '/magic' . '?f=&dest=' . $dest); + } + } } diff --git a/mod/rpost.php b/mod/rpost.php new file mode 100644 index 000000000..dc25444a3 --- /dev/null +++ b/mod/rpost.php @@ -0,0 +1,125 @@ +<?php /** @file */ + +require_once('acl_selectors.php'); +require_once('include/crypto.php'); +require_once('include/items.php'); +require_once('include/taxonomy.php'); +require_once('include/conversation.php'); +require_once('include/zot.php'); + +/** + * remote post + * + * https://yoursite/rpost?f=&title=&body=&remote_return= + * + * This can be called via either GET or POST, use POST for long body content as suhosin often limits GET parameter length + * + * f= placeholder, often required + * title= Title of post + * body= Body of post + * source= Source application + * remote_return= absolute URL to return after posting is finished + * type= choices are 'html' or 'bbcode', default is 'bbcode' + * + */ + + + +function rpost_content(&$a) { + + $o = ''; + + if(! local_user()) { + if(remote_user()) { + // redirect to your own site. + // We can only do this with a GET request so you'll need to keep the text short or risk getting truncated + // by the wretched beast called 'suhosin'. All the browsers now allow long GET requests, but suhosin + // blocks them. + + $url = get_rpost_path($a->get_observer()); + // make sure we're not looping to our own hub + if(($url) && (! stristr($url, $a->get_hostname()))) { + foreach($_REQUEST as $key => $arg) { + $url .= '&' . $key . '=' . $arg; + } + goaway($url); + } + } + + // The login procedure is going to bugger our $_REQUEST variables + // so save them in the session. + + if(array_key_exists('body',$_REQUEST)) { + $_SESSION['rpost'] = $_REQUEST; + } + return login(); + } + + // If we have saved rpost session variables, but nothing in the current $_REQUEST, recover the saved variables + + if((! array_key_exists('body',$_REQUEST)) && (array_key_exists('rpost',$_SESSION))) { + $_REQUEST = $_SESSION['rpost']; + unset($_SESSION['rpost']); + } + + if($_REQUEST['remote_return']) { + $_SESSION['remote_return'] = $_REQUEST['remote_return']; + } + if(argc() > 1 && argv(1) === 'return') { + if($_SESSION['remote_return']) + goaway($_SESSION['remote_return']); + goaway(z_root() . '/network'); + } + + $plaintext = true; + if(feature_enabled(local_user(),'richtext')) + $plaintext = false; + + if(array_key_exists('type', $_REQUEST) && $_REQUEST['type'] === 'html') { + require_once('include/html2bbcode.php'); + $_REQUEST['body'] = html2bbcode($_REQUEST['body']); + } + + $channel = $a->get_channel(); + + $o .= replace_macros(get_markup_template('edpost_head.tpl'), array( + '$title' => t('Edit post') + )); + + +// $a->page['htmlhead'] .= replace_macros(get_markup_template('jot-header.tpl'), array( +// '$baseurl' => $a->get_baseurl(), +// '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'), +// '$ispublic' => ' ', // t('Visible to <strong>everybody</strong>'), +// '$geotag' => $geotag, +// '$nickname' => $channel['channel_address'] +// )); + + + + $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' => (($channel['channel_allow_cid'] || $channel['channel_allow_gid'] + || $channel['channel_deny_cid'] || $channel['channel_deny_gid']) ? 'lock' : 'unlock'), + 'acl' => populate_acl($channel, $false), + 'bang' => '', +// 'channel_select' => true, + 'visitor' => true, + 'profile_uid' => local_user(), + 'title' => $_REQUEST['title'], + 'body' => $_REQUEST['body'], + 'source' => ((x($_REQUEST,'source')) ? strip_tags($_REQUEST['source']) : ''), + 'return_path' => 'rpost/return' + ); + + + $o .= status_editor($a,$x); + + return $o; + +} + + diff --git a/mod/search.php b/mod/search.php index 1bea720a6..82990913b 100644 --- a/mod/search.php +++ b/mod/search.php @@ -1,86 +1,19 @@ <?php -function search_saved_searches() { - - if(! feature_enabled(local_user(),'savedsearch')) - return ''; - - $o = ''; - - $r = q("select `tid`,`term` from `term` WHERE `uid` = %d and type = %d", - intval(local_user()), - intval(TERM_SAVEDSEARCH) - ); - - if(count($r)) { - $o .= '<div id="saved-search-list" class="widget">'; - $o .= '<h3>' . t('Saved Searches') . '</h3>' . "\r\n"; - $o .= '<ul id="saved-search-ul">' . "\r\n"; - foreach($r as $rr) { - $o .= '<li class="saved-search-li clear"><a href="search/?f=&remove=1&search=' . $rr['term'] . '" class="icon drophide savedsearchdrop" title="' . t('Remove term') . '" onclick="return confirmDelete();" onmouseover="imgbright(this);" onmouseout="imgdull(this);" ></a> <a href="search/?f=&search=' . $rr['term'] . '" class="savedsearchterm" >' . htmlspecialchars($rr['term']) . '</a></li>' . "\r\n"; - } - $o .= '</ul><div class="clear"></div></div>' . "\r\n"; - } - - return $o; - -} - - function search_init(&$a) { - - $search = ((x($_GET,'search')) ? trim(rawurldecode($_GET['search'])) : ''); - - if(local_user()) { - if(x($_GET,'save') && $search) { - $r = q("select `tid` from `term` where `uid` = %d and `type` = %d and `term` = '%s' limit 1", - intval(local_user()), - intval(TERM_SAVEDSEARCH), - dbesc($search) - ); - if(! count($r)) { - q("insert into `term` ( `uid`,`type`,`term` ) values ( %d, %d, '%s') ", - intval(local_user()), - intval(TERM_SAVEDSEARCH), - dbesc($search) - ); - } - } - if(x($_GET,'remove') && $search) { - q("delete from `term` where `uid` = %d and `type` = %d and `term` = '%s' limit 1", - intval(local_user()), - intval(TERM_SAVEDSEARCH), - dbesc($search) - ); - } - - $a->page['aside'] .= search_saved_searches(); - - } - else { - unset($_SESSION['theme']); - unset($_SESSION['mobile-theme']); - } - - - -} - - - -function search_post(&$a) { - if(x($_POST,'search')) - $a->data['search'] = $_POST['search']; + if(x($_REQUEST,'search')) + $a->data['search'] = $_REQUEST['search']; } -function search_content(&$a) { +function search_content(&$a,$update = 0, $load = false) { - if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { - notice( t('Public access denied.') . EOL); + if((get_config('system','block_public')) || (get_config('system','block_public_search'))) { + if ((! local_user()) && (! remote_user())) { + notice( t('Public access denied.') . EOL); return; + } } - nav_set_selected('search'); require_once("include/bbcode.php"); @@ -133,10 +66,7 @@ function search_content(&$a) { ); } else { - if (get_config('system','use_fulltext_engine')) - $sql_extra = sprintf(" AND MATCH (`item`.`body`) AGAINST ('".'"%s"'."' in boolean mode) ", dbesc(protect_sprintf($search))); - else - $sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search)))); + $sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search)))); } // Here is the way permissions work in the search module... @@ -144,16 +74,13 @@ function search_content(&$a) { // OR your own posts if you are a logged in member // No items will be shown if the member has a blocked profile wall. - - - if((! $update) && (! $load)) { // This is ugly, but we can't pass the profile_uid through the session to the ajax updater, // because browser prefetching might change it on us. We have to deliver it with the page. $o .= '<div id="live-search"></div>' . "\r\n"; - $o .= "<script> var profile_uid = " . $a->profile['profile_uid'] + $o .= "<script> var profile_uid = " . ((intval(local_user())) ? local_user() : (-1)) . "; var netargs = '?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n"; $a->page['htmlhead'] .= replace_macros(get_markup_template("build_query.tpl"),array( @@ -168,14 +95,16 @@ function search_content(&$a) { '$liked' => '0', '$conv' => '0', '$spam' => '0', + '$fh' => '0', '$nouveau' => '0', '$wall' => '0', + '$list' => ((x($_REQUEST,'list')) ? intval($_REQUEST['list']) : 0), '$page' => (($a->pager['page'] != 1) ? $a->pager['page'] : 1), - '$search' => (($tag) ? '#' : '') . $search, + '$search' => (($tag) ? urlencode('#') : '') . $search, '$order' => '', '$file' => '', '$cats' => '', - '$uri' => '', + '$mid' => '', '$dend' => '', '$dbegin' => '' )); @@ -183,23 +112,39 @@ function search_content(&$a) { } - + $pub_sql = public_permissions_sql(get_observer_hash()); if(($update) && ($load)) { - + $itemspage = get_pconfig(local_user(),'system','itemspage'); + $a->set_pager_itemspage(((intval($itemspage)) ? $itemspage : 20)); $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage'])); if($load) { - $r = q("SELECT distinct(uri), item.* from item - WHERE item_restrict = 0 - AND (( `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' AND item_private = 0 ) - OR ( `item`.`uid` = %d )) - $sql_extra - group by uri ORDER BY created DESC $pager_sql ", - intval(local_user()), - intval(ABOOK_FLAG_BLOCKED) - - ); + $r = null; + + if(local_user()) { + $r = q("SELECT distinct mid, item.id as item_id, item.* from item + WHERE item_restrict = 0 + AND (( `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' AND item_private = 0 ) + OR ( `item`.`uid` = %d )) + $sql_extra + group by mid ORDER BY created DESC $pager_sql ", + intval(local_user()), + intval(ABOOK_FLAG_BLOCKED) + + ); + } + if($r === null) { + $r = q("SELECT distinct mid, item.id as item_id, item.* from item + WHERE item_restrict = 0 + 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) ? PERMS_NETWORK : PERMS_PUBLIC) . " )) + $pub_sql ) + $sql_extra + group by mid ORDER BY created DESC $pager_sql" + ); + } } else { $r = array(); @@ -207,64 +152,18 @@ function search_content(&$a) { } if($r) { - - $parents_str = ids_to_querystr($r,'item_id'); - - $items = q("SELECT `item`.*, `item`.`id` AS `item_id` - FROM `item` - WHERE item_restrict = 0 and - $sql_extra ", - intval($a->profile['profile_uid']), - dbesc($parents_str) - ); - - xchan_query($items); - $items = fetch_post_tags($items,true); - $items = conv_sort($items,'created'); - + xchan_query($r); + $items = fetch_post_tags($r,true); } else { $items = array(); } - - - $r = q("SELECT distinct(`item`.`uri`), `item`.*, `item`.`id` AS `item_id`, - `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`alias`, `contact`.`rel`, - `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, - `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`, - `user`.`nickname` - FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` - LEFT JOIN `user` ON `user`.`uid` = `item`.`uid` - WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0 - AND (( `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' AND `item`.`private` = 0 AND `user`.`hidewall` = 0 ) - OR `item`.`uid` = %d ) - AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0 - $sql_extra - group by `item`.`uri` - ORDER BY `received` DESC LIMIT %d , %d ", - intval(local_user()), - intval($a->pager['start']), - intval($a->pager['itemspage']) - - ); - - -// $a = fetch_post_tags($a,true); - - if(! count($r)) { - info( t('No results.') . EOL); - return $o; - } - - if($tag) - $o .= '<h2>Items tagged with: ' . htmlspecialchars($search) . '</h2>'; + $o .= '<h2>Items tagged with: ' . htmlspecialchars($search, ENT_COMPAT,'UTF-8') . '</h2>'; else - $o .= '<h2>Search results for: ' . htmlspecialchars($search) . '</h2>'; - - $o .= conversation($a,$r,'search',false); + $o .= '<h2>Search results for: ' . htmlspecialchars($search, ENT_COMPAT,'UTF-8') . '</h2>'; - $o .= alt_pager($a,count($r)); + $o .= conversation($a,$items,'search',$update,'client'); return $o; } diff --git a/mod/search_ac.php b/mod/search_ac.php index 5bc3c1c0b..36da21376 100644 --- a/mod/search_ac.php +++ b/mod/search_ac.php @@ -27,43 +27,27 @@ function search_ac_init(&$a){ // Priority to people searches if ($search) { - $people_sql_extra = protect_sprintf(" AND `name` LIKE '%". dbesc($search) . "%' "); + $people_sql_extra = protect_sprintf(" AND `xchan_name` LIKE '%". dbesc($search) . "%' "); $tag_sql_extra = protect_sprintf(" AND term LIKE '%". dbesc($search) . "%' "); } - $r = q("SELECT `id`, `name`, `micro`, `url` FROM `contact` - WHERE `uid` = %d AND `pending` = 0 + + $r = q("SELECT `abook_id`, `xchan_name`, `xchan_photo_s`, `xchan_url` FROM `abook` left join xchan on abook_xchan = xchan_hash WHERE abook_channel = %d $people_sql_extra - ORDER BY `name` ASC ", + ORDER BY `xchan_name` ASC ", intval(local_user()) ); - if(count($r)) { + if($r) { foreach($r as $g) { - $x['photos'][] = $g['micro']; - $x['links'][] = $g['url']; - $x['suggestions'][] = '@' . $g['name']; - $x['data'][] = intval($g['id']); - } - } - else { - - $r = q("SELECT `id`, `name`, `photo`, `url` FROM `gcontact` where 1 - $people_sql_extra - ORDER BY `name` ASC " - ); - - if(count($r)) { - foreach($r as $g) { - $x['photos'][] = $g['photo']; - $x['links'][] = $g['url']; - $x['suggestions'][] = '@' . $g['name']; - $x['data'][] = intval($g['id']); - } + $x['photos'][] = $g['xchan_photo_s']; + $x['links'][] = $g['xchan_url']; + $x['suggestions'][] = '@' . $g['xchan_name']; + $x['data'][] = 'cid=' . intval($g['abook_id']); } } - $r = q("select tid, term, url from term where type = %d $tag_sql_extra order by term asc", + $r = q("select distinct term, tid, url from term where type = %d $tag_sql_extra group by term order by term asc", intval(TERM_HASHTAG) ); diff --git a/mod/settings.php b/mod/settings.php index da6cf709c..3ab34f145 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -1,5 +1,6 @@ -<?php +<?php /** @file */ +require_once('include/zot.php'); function get_theme_config_file($theme){ @@ -14,8 +15,11 @@ function get_theme_config_file($theme){ return null; } -function settings_aside(&$a) { +function settings_init(&$a) { + if(! local_user()) + return; + $a->profile_uid = local_user(); // default is channel settings in the absence of other arguments @@ -25,84 +29,8 @@ function settings_aside(&$a) { $a->argv[] = 'channel'; } - $abook_self_id = 0; - - // Retrieve the 'self' address book entry for use in the auto-permissions link - if(local_user()) { - $abk = q("select abook_id from abook where abook_channel = %d and ( abook_flags & %d ) limit 1", - intval(local_user()), - intval(ABOOK_FLAG_SELF) - ); - if($abk) - $abook_self_id = $abk[0]['abook_id']; - } - $tabs = array( - array( - 'label' => t('Account settings'), - 'url' => $a->get_baseurl(true).'/settings/account', - 'selected' => ((argv(1) === 'account') ? 'active' : ''), - ), - - array( - 'label' => t('Channel settings'), - 'url' => $a->get_baseurl(true).'/settings/channel', - 'selected' => ((argv(1) === 'channel') ? 'active' : ''), - ), - - array( - 'label' => t('Additional features'), - 'url' => $a->get_baseurl(true).'/settings/features', - 'selected' => ((argv(1) === 'features') ? 'active' : ''), - ), - - array( - 'label' => t('Feature settings'), - 'url' => $a->get_baseurl(true).'/settings/featured', - 'selected' => ((argv(1) === 'featured') ? 'active' : ''), - ), - - array( - 'label' => t('Display settings'), - 'url' => $a->get_baseurl(true).'/settings/display', - 'selected' => ((argv(1) === 'display') ? 'active' : ''), - ), - - array( - 'label' => t('Connected apps'), - 'url' => $a->get_baseurl(true) . '/settings/oauth', - 'selected' => ((argv(1) === 'oauth') ? 'active' : ''), - ), - - array( - 'label' => t('Export channel'), - 'url' => $a->get_baseurl(true) . '/uexport/basic', - 'selected' => '' - ), - -// array( -// 'label' => t('Export account'), -// 'url' => $a->get_baseurl(true) . '/uexport/complete', -// 'selected' => '' -// ), - - array( - 'label' => t('Automatic Permissions (Advanced)'), - 'url' => $a->get_baseurl(true) . '/connections/' . $abook_self_id, - 'selected' => '' - ), - - - ); - - $tabtpl = get_markup_template("generic_links_widget.tpl"); - $a->page['aside'] = replace_macros($tabtpl, array( - '$title' => t('Settings'), - '$class' => 'settings-widget', - '$items' => $tabs, - )); - } @@ -111,17 +39,12 @@ function settings_post(&$a) { if(! local_user()) return; + // logger('mod_settings: ' . print_r($_REQUEST,true)); + if(x($_SESSION,'submanage') && intval($_SESSION['submanage'])) return; -// if(count($a->user) && x($a->user,'uid') && $a->user['uid'] != local_user()) { -// notice( t('Permission denied.') . EOL); -// return; -// } - - $old_page_flags = $a->user['page-flags']; - if((argc() > 1) && (argv(1) === 'oauth') && x($_POST,'remove')){ check_form_security_token_redirectOnErr('/settings/oauth', 'settings_oauth'); @@ -142,10 +65,17 @@ function settings_post(&$a) { $secret = ((x($_POST,'secret')) ? $_POST['secret'] : ''); $redirect = ((x($_POST,'redirect')) ? $_POST['redirect'] : ''); $icon = ((x($_POST,'icon')) ? $_POST['icon'] : ''); - if ($name=="" || $key=="" || $secret==""){ - notice(t("Missing some important data!")); - - } else { + $ok = true; + if($name == '') { + $ok = false; + notice( t('Name is required') . EOL); + } + if($key == '' || $secret == '') { + $ok = false; + notice( t('Key and Secret are required') . EOL); + } + + if($ok) { if ($_POST['submit']==t("Update")){ $r = q("UPDATE clients SET client_id='%s', @@ -182,6 +112,7 @@ function settings_post(&$a) { check_form_security_token_redirectOnErr('/settings/featured', 'settings_featured'); call_hooks('feature_settings_post', $_POST); + build_sync_packet(); return; } @@ -194,6 +125,7 @@ function settings_post(&$a) { set_pconfig(local_user(),'feature',substr($k,8),((intval($v)) ? 1 : 0)); } } + build_sync_packet(); return; } @@ -218,9 +150,12 @@ function settings_post(&$a) { set_pconfig(local_user(),'system','mobile_theme',$mobile_theme); } + $chanview_full = ((x($_POST,'chanview_full')) ? intval($_POST['chanview_full']) : 0); + set_pconfig(local_user(),'system','update_interval', $browser_update); set_pconfig(local_user(),'system','itemspage', $itemspage); set_pconfig(local_user(),'system','no_smilies',$nosmile); + set_pconfig(local_user(),'system','chanview_full',$chanview_full); if ($theme == $a->channel['channel_theme']){ @@ -237,6 +172,7 @@ function settings_post(&$a) { ); call_hooks('display_settings_post', $_POST); + build_sync_packet(); goaway($a->get_baseurl(true) . '/settings/display' ); return; // NOTREACHED } @@ -286,13 +222,13 @@ function settings_post(&$a) { } $email = ((x($_POST,'email')) ? trim(notags($_POST['email'])) : ''); + $account = $a->get_account(); if($email != $account['account_email']) { - $account = $a->get_account(); if(! valid_email($email)) $errs[] = t('Not valid email.'); $adm = trim(get_config('system','admin_email')); if(($adm) && (strcasecmp($email,$adm) == 0)) { - $errs[] = t('Protected email. Cannot change to that email.'); + $errs[] = t('Protected email address. Cannot change to that email.'); $email = $a->user['email']; } if(! $errs) { @@ -324,16 +260,17 @@ function settings_post(&$a) { $openid = ((x($_POST,'openid_url')) ? notags(trim($_POST['openid_url'])) : ''); $maxreq = ((x($_POST,'maxreq')) ? intval($_POST['maxreq']) : 0); $expire = ((x($_POST,'expire')) ? intval($_POST['expire']) : 0); - $def_gid = ((x($_POST,'group-selection')) ? intval($_POST['group-selection']) : 0); - + $def_group = ((x($_POST,'group-selection')) ? notags(trim($_POST['group-selection'])) : ''); + $channel_menu = ((x($_POST['channel_menu'])) ? htmlspecialchars_decode(trim($_POST['channel_menu']),ENT_QUOTES) : ''); $expire_items = ((x($_POST,'expire_items')) ? intval($_POST['expire_items']) : 0); - $expire_notes = ((x($_POST,'expire_notes')) ? intval($_POST['expire_notes']) : 0); $expire_starred = ((x($_POST,'expire_starred')) ? intval($_POST['expire_starred']) : 0); $expire_photos = ((x($_POST,'expire_photos'))? intval($_POST['expire_photos']) : 0); $expire_network_only = ((x($_POST,'expire_network_only'))? intval($_POST['expire_network_only']) : 0); $allow_location = (((x($_POST,'allow_location')) && (intval($_POST['allow_location']) == 1)) ? 1: 0); + $hide_presence = (((x($_POST,'hide_presence')) && (intval($_POST['hide_presence']) == 1)) ? 1: 0); + $publish = (((x($_POST,'profile_in_directory')) && (intval($_POST['profile_in_directory']) == 1)) ? 1: 0); $page_flags = (((x($_POST,'page-flags')) && (intval($_POST['page-flags']))) ? intval($_POST['page-flags']) : 0); $blockwall = (((x($_POST,'blockwall')) && (intval($_POST['blockwall']) == 1)) ? 0: 1); // this setting is inverted! @@ -346,25 +283,34 @@ function settings_post(&$a) { $post_newfriend = (($_POST['post_newfriend'] == 1) ? 1: 0); $post_joingroup = (($_POST['post_joingroup'] == 1) ? 1: 0); $post_profilechange = (($_POST['post_profilechange'] == 1) ? 1: 0); + $adult = (($_POST['adult'] == 1) ? 1 : 0); - $arr = array(); - $arr['channel_r_stream'] = (($_POST['view_stream']) ? $_POST['view_stream'] : 0); - $arr['channel_r_profile'] = (($_POST['view_profile']) ? $_POST['view_profile'] : 0); - $arr['channel_r_photos'] = (($_POST['view_photos']) ? $_POST['view_photos'] : 0); - $arr['channel_r_abook'] = (($_POST['view_contacts']) ? $_POST['view_contacts'] : 0); - $arr['channel_w_stream'] = (($_POST['send_stream']) ? $_POST['send_stream'] : 0); - $arr['channel_w_wall'] = (($_POST['post_wall']) ? $_POST['post_wall'] : 0); - $arr['channel_w_tagwall'] = (($_POST['tag_deliver']) ? $_POST['tag_deliver'] : 0); - $arr['channel_w_comment'] = (($_POST['post_comments']) ? $_POST['post_comments'] : 0); - $arr['channel_w_mail'] = (($_POST['post_mail']) ? $_POST['post_mail'] : 0); - $arr['channel_w_photos'] = (($_POST['post_photos']) ? $_POST['post_photos'] : 0); - $arr['channel_w_chat'] = (($_POST['chat']) ? $_POST['chat'] : 0); - $arr['channel_a_delegate'] = (($_POST['delegate']) ? $_POST['delegate'] : 0); - $arr['channel_r_storage'] = (($_POST['view_storage']) ? $_POST['view_storage'] : 0); - $arr['channel_w_storage'] = (($_POST['write_storage']) ? $_POST['write_storage'] : 0); - $arr['channel_r_pages'] = (($_POST['view_pages']) ? $_POST['view_pages'] : 0); - $arr['channel_w_pages'] = (($_POST['write_pages']) ? $_POST['write_pages'] : 0); + $channel = $a->get_channel(); + $pageflags = $channel['channel_pageflags']; + $existing_adult = (($pageflags & PAGE_ADULT) ? 1 : 0); + if($adult != $existing_adult) + $pageflags = ($pageflags ^ PAGE_ADULT); + $arr = array(); + $arr['channel_r_stream'] = (($_POST['view_stream']) ? $_POST['view_stream'] : 0); + $arr['channel_r_profile'] = (($_POST['view_profile']) ? $_POST['view_profile'] : 0); + $arr['channel_r_photos'] = (($_POST['view_photos']) ? $_POST['view_photos'] : 0); + $arr['channel_r_abook'] = (($_POST['view_contacts']) ? $_POST['view_contacts'] : 0); + $arr['channel_w_stream'] = (($_POST['send_stream']) ? $_POST['send_stream'] : 0); + $arr['channel_w_wall'] = (($_POST['post_wall']) ? $_POST['post_wall'] : 0); + $arr['channel_w_tagwall'] = (($_POST['tag_deliver']) ? $_POST['tag_deliver'] : 0); + $arr['channel_w_comment'] = (($_POST['post_comments']) ? $_POST['post_comments'] : 0); + $arr['channel_w_mail'] = (($_POST['post_mail']) ? $_POST['post_mail'] : 0); + $arr['channel_w_photos'] = (($_POST['post_photos']) ? $_POST['post_photos'] : 0); + $arr['channel_w_chat'] = (($_POST['chat']) ? $_POST['chat'] : 0); + $arr['channel_a_delegate'] = (($_POST['delegate']) ? $_POST['delegate'] : 0); + $arr['channel_r_storage'] = (($_POST['view_storage']) ? $_POST['view_storage'] : 0); + $arr['channel_w_storage'] = (($_POST['write_storage']) ? $_POST['write_storage'] : 0); + $arr['channel_r_pages'] = (($_POST['view_pages']) ? $_POST['view_pages'] : 0); + $arr['channel_w_pages'] = (($_POST['write_pages']) ? $_POST['write_pages'] : 0); + $arr['channel_a_republish'] = (($_POST['republish']) ? $_POST['republish'] : 0); + $arr['channel_a_bookmark'] = (($_POST['bookmark']) ? $_POST['bookmark'] : 0); + $defperms = 0; if(x($_POST['def_view_stream'])) $defperms += $_POST['def_view_stream']; @@ -398,6 +344,10 @@ function settings_post(&$a) { $defperms += $_POST['def_view_pages']; if(x($_POST['def_write_pages'])) $defperms += $_POST['def_write_pages']; + if(x($_POST['def_republish'])) + $defperms += $_POST['def_republish']; + if(x($_POST['def_bookmark'])) + $defperms += $_POST['def_bookmark']; $notify = 0; @@ -446,66 +396,25 @@ function settings_post(&$a) { $str_group_deny = perms2str($_POST['group_deny']); $str_contact_deny = perms2str($_POST['contact_deny']); - set_pconfig(local_user(),'expire','items', $expire_items); - set_pconfig(local_user(),'expire','notes', $expire_notes); - set_pconfig(local_user(),'expire','starred', $expire_starred); - set_pconfig(local_user(),'expire','photos', $expire_photos); - set_pconfig(local_user(),'expire','network_only', $expire_network_only); set_pconfig(local_user(),'system','use_browser_location',$allow_location); set_pconfig(local_user(),'system','suggestme', $suggestme); set_pconfig(local_user(),'system','post_newfriend', $post_newfriend); set_pconfig(local_user(),'system','post_joingroup', $post_joingroup); set_pconfig(local_user(),'system','post_profilechange', $post_profilechange); + set_pconfig(local_user(),'system','blocktags',$blocktags); + set_pconfig(local_user(),'system','hide_online_status',$hide_presence); + set_pconfig(local_user(),'system','channel_menu',$channel_menu); -/* - if($page_flags == PAGE_PRVGROUP) { - $hidewall = 1; - if((! $str_contact_allow) && (! $str_group_allow) && (! $str_contact_deny) && (! $str_group_deny)) { - if($def_gid) { - info( t('Private forum has no privacy permissions. Using default privacy group.'). EOL); - $str_group_allow = '<' . $def_gid . '>'; - } - else { - notice( t('Private forum has no privacy permissions and no default privacy group.') . EOL); - } - } - } - -*/ - -/* - $r = q("UPDATE `user` SET `username` = '%s', `email` = '%s', `openid` = '%s', `timezone` = '%s', `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s', `notify-flags` = %d, `page-flags` = %d, `default-location` = '%s', `allow_location` = %d, `maxreq` = %d, `expire` = %d, `openidserver` = '%s', `def_gid` = %d, `blockwall` = %d, `hidewall` = %d, `blocktags` = %d, `unkmail` = %d, `cntunkmail` = %d WHERE `uid` = %d LIMIT 1", - dbesc($username), - dbesc($email), - dbesc($openid), - dbesc($timezone), - dbesc($str_contact_allow), - dbesc($str_group_allow), - dbesc($str_contact_deny), - dbesc($str_group_deny), - intval($notify), - intval($page_flags), - dbesc($defloc), - intval($allow_location), - intval($maxreq), - intval($expire), - dbesc($openidserver), - intval($def_gid), - intval($blockwall), - intval($hidewall), - intval($blocktags), - intval($unkmail), - intval($cntunkmail), - intval(local_user()) - ); -*/ - - $r = q("update channel set channel_name = '%s', channel_timezone = '%s', channel_max_anon_mail = %d, channel_max_friend_req = %d, channel_expire_days = %d, channel_r_stream = %d, channel_r_profile = %d, channel_r_photos = %d, channel_r_abook = %d, channel_w_stream = %d, channel_w_wall = %d, channel_w_tagwall = %d, channel_w_comment = %d, channel_w_mail = %d, channel_w_photos = %d, channel_w_chat = %d, channel_a_delegate = %d, channel_r_storage = %d, channel_w_storage = %d, channel_r_pages = %d, channel_w_pages = %d where channel_id = %d limit 1", + $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, channel_default_group = '%s', channel_r_stream = %d, channel_r_profile = %d, channel_r_photos = %d, channel_r_abook = %d, channel_w_stream = %d, channel_w_wall = %d, channel_w_tagwall = %d, channel_w_comment = %d, channel_w_mail = %d, channel_w_photos = %d, channel_w_chat = %d, channel_a_delegate = %d, channel_r_storage = %d, channel_w_storage = %d, channel_r_pages = %d, channel_w_pages = %d, channel_a_republish = %d, channel_a_bookmark = %d, channel_allow_cid = '%s', channel_allow_gid = '%s', channel_deny_cid = '%s', channel_deny_gid = '%s' where channel_id = %d limit 1", dbesc($username), + intval($pageflags), dbesc($timezone), + dbesc($defloc), + intval($notify), intval($unkmail), intval($maxreq), intval($expire), + dbesc($def_group), intval($arr['channel_r_stream']), intval($arr['channel_r_profile']), intval($arr['channel_r_photos']), @@ -522,9 +431,14 @@ function settings_post(&$a) { intval($arr['channel_w_storage']), intval($arr['channel_r_pages']), intval($arr['channel_w_pages']), + intval($arr['channel_a_republish']), + intval($arr['channel_a_bookmark']), + dbesc($str_contact_allow), + dbesc($str_group_allow), + dbesc($str_contact_deny), + dbesc($str_group_deny), intval(local_user()) ); - if($r) info( t('Settings updated.') . EOL); @@ -547,11 +461,12 @@ function settings_post(&$a) { dbesc($username), intval($channel['channel_id']) ); - // we really need to send out notifications to all our friends } proc_run('php','include/directory.php',local_user()); + build_sync_packet(); + //$_SESSION['theme'] = $theme; if($email_changed && $a->config['system']['register_policy'] == REGISTER_VERIFY) { @@ -575,9 +490,14 @@ function settings_content(&$a) { if(! local_user()) { notice( t('Permission denied.') . EOL ); - return; + return login(); } + + $channel = $a->get_channel(); + if($channel) + head_set_icon($channel['xchan_photo_s']); + // if(x($_SESSION,'submanage') && intval($_SESSION['submanage'])) { // notice( t('Permission denied.') . EOL ); // return; @@ -594,11 +514,11 @@ function settings_content(&$a) { '$title' => t('Add application'), '$submit' => t('Submit'), '$cancel' => t('Cancel'), - '$name' => array('name', t('Name'), '', ''), - '$key' => array('key', t('Consumer Key'), '', ''), - '$secret' => array('secret', t('Consumer Secret'), '', ''), - '$redirect' => array('redirect', t('Redirect'), '', ''), - '$icon' => array('icon', t('Icon url'), '', ''), + '$name' => array('name', t('Name'), '', t('Name of application')), + '$key' => array('key', t('Consumer Key'), random_string(16), t('Automatically generated - change if desired. Max length 20')), + '$secret' => array('secret', t('Consumer Secret'), random_string(16), t('Automatically generated - change if desired. Max length 20')), + '$redirect' => array('redirect', t('Redirect'), '', t('Redirect URI - leave blank unless your application specifically requires this')), + '$icon' => array('icon', t('Icon url'), '', t('Optional')), )); return $o; } @@ -716,7 +636,6 @@ function settings_content(&$a) { if((argc() > 1) && (argv(1) === 'features')) { - $arr = array(); $features = get_features(); @@ -724,7 +643,7 @@ function settings_content(&$a) { $arr[$fname] = array(); $arr[$fname][0] = $fdata[0]; foreach(array_slice($fdata,1) as $f) { - $arr[$fname][1][] = array('feature_' .$f[0],$f[1],((intval(get_pconfig(local_user(),'feature',$f[0]))) ? "1" : ''),$f[2],array(t('Off'),t('On'))); + $arr[$fname][1][] = array('feature_' .$f[0],$f[1],((intval(feature_enabled(local_user(),$f[0]))) ? "1" : ''),$f[2],array(t('Off'),t('On'))); } } @@ -736,6 +655,7 @@ function settings_content(&$a) { '$submit' => t('Submit'), '$field_yesno' => 'field_yesno.tpl', )); + return $o; } @@ -771,7 +691,7 @@ function settings_content(&$a) { $default_theme = get_config('system','theme'); if(! $default_theme) $default_theme = 'default'; - $default_mobile_theme = get_config('system','mobile-theme'); + $default_mobile_theme = get_config('system','mobile_theme'); if(! $mobile_default_theme) $mobile_default_theme = 'none'; @@ -805,7 +725,7 @@ function settings_content(&$a) { } } $theme_selected = (!x($_SESSION,'theme')? $default_theme : $_SESSION['theme']); - $mobile_theme_selected = (!x($_SESSION,'mobile-theme')? $default_mobile_theme : $_SESSION['mobile-theme']); + $mobile_theme_selected = (!x($_SESSION,'mobile_theme')? $default_mobile_theme : $_SESSION['mobile_theme']); $browser_update = intval(get_pconfig(local_user(), 'system','update_interval')); $browser_update = (($browser_update == 0) ? 40 : $browser_update / 1000); // default if not set: 40 seconds @@ -816,6 +736,7 @@ function settings_content(&$a) { $nosmile = get_pconfig(local_user(),'system','no_smilies'); $nosmile = (($nosmile===false)? '0': $nosmile); // default if not set: 0 + $chanview = intval(get_pconfig(local_user(),'system','chanview_full')); $theme_config = ""; if( ($themeconfigfile = get_theme_config_file($theme_selected)) != null){ @@ -836,7 +757,8 @@ function settings_content(&$a) { '$ajaxint' => array('browser_update', t("Update browser every xx seconds"), $browser_update, t('Minimum of 10 seconds, no maximum')), '$itemspage' => array('itemspage', t("Maximum number of conversations to load at any time:"), $itemspage, t('Maximum of 100 items')), '$nosmile' => array('nosmile', t("Don't show emoticons"), $nosmile, ''), - + '$chanview_full' => array('chanview_full', t('Do not view remote profiles in frames'), $chanview, t('By default open in a sub-window of your own site')), + '$layout_editor' => t('System Page Layout Editor - (advanced)'), '$theme_config' => $theme_config, )); @@ -876,6 +798,7 @@ function settings_content(&$a) { array( t('Anybody in your address book'), PERMS_CONTACTS), array( t('Anybody on this website'), PERMS_SITE), array( t('Anybody in this network'), PERMS_NETWORK), + array( t('Anybody authenticated'), PERMS_AUTHED), array( t('Anybody on the internet'), PERMS_PUBLIC) ); @@ -903,12 +826,15 @@ function settings_content(&$a) { $maxreq = $channel['channel_max_friend_req']; $expire = $channel['channel_expire_days']; + $adult_flag = intval($channel['channel_pageflags'] & PAGE_ADULT); $blockwall = $a->user['blockwall']; - $blocktags = $a->user['blocktags']; $unkmail = $a->user['unkmail']; $cntunkmail = $a->user['cntunkmail']; + $hide_presence = intval(get_pconfig(local_user(), 'system','hide_online_status')); + + $expire_items = get_pconfig(local_user(), 'expire','items'); $expire_items = (($expire_items===false)? '1' : $expire_items); // default if not set: 1 @@ -937,6 +863,8 @@ function settings_content(&$a) { $post_profilechange = get_pconfig(local_user(), 'system','post_profilechange'); $post_profilechange = (($post_profilechange===false)? '0': $post_profilechange); // default if not set: 0 + $blocktags = get_pconfig(local_user(),'system','blocktags'); + $blocktags = (($blocktags===false) ? '0' : $blocktags); $timezone = date_default_timezone_get(); @@ -970,25 +898,30 @@ function settings_content(&$a) { $stpl = get_markup_template('settings.tpl'); - $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false); - - $expire_arr = array( - 'days' => array('expire', t("Automatically expire posts after this many days:"), $expire, t('If empty, posts will not expire. Expired posts will be deleted')), - 'advanced' => t('Advanced expiration settings'), - 'label' => t('Advanced Expiration'), - 'items' => array('expire_items', t("Expire posts:"), $expire_items, '', array(t('No'),t('Yes'))), - - 'starred' => array('expire_starred', t("Expire starred posts:"), $expire_starred, '', array(t('No'),t('Yes'))), - 'photos' => array('expire_photos', t("Expire photos:"), $expire_photos, '', array(t('No'),t('Yes'))), - 'network_only' => array('expire_network_only', t("Only expire posts by others:"), $expire_network_only, '', array(t('No'),t('Yes'))), - ); - - + $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'] + ); require_once('include/group.php'); - $group_select = mini_group_select(local_user(),$a->user['def_gid']); + $group_select = mini_group_select(local_user(),$channel['channel_default_group']); + + require_once('include/menu.php'); + $m1 = menu_list(local_user()); + $menu = false; + if($m1) { + $menu = array(); + $current = get_pconfig(local_user(),'system','channel_menu'); + $menu[] = array('name' => '', 'selected' => ((! $current) ? true : false)); + foreach($m1 as $m) { + $menu[] = array('name' => htmlspecialchars($m['menu_name'],ENT_COMPAT,'UTF-8'), 'selected' => (($m['menu_name'] === $current) ? ' selected="selected" ' : false)); + } + } $o .= replace_macros($stpl,array( '$ptitle' => t('Channel Settings'), @@ -1004,25 +937,35 @@ function settings_content(&$a) { '$username' => array('username', t('Full Name:'), $username,''), '$email' => array('email', t('Email Address:'), $email, ''), '$timezone' => array('timezone_select' , t('Your Timezone:'), select_timezone($timezone), ''), - '$defloc' => array('defloc', t('Default Post Location:'), $defloc, ''), - '$allowloc' => array('allow_location', t('Use Browser Location:'), (intval(get_pconfig(local_user(),'system','use_browser_location')) == 1), ''), + '$defloc' => array('defloc', t('Default Post Location:'), $defloc, t('Geographical location to display on your posts')), + '$allowloc' => array('allow_location', t('Use Browser Location:'), ((get_pconfig(local_user(),'system','use_browser_location')) ? 1 : ''), ''), + '$adult' => array('adult', t('Adult Content'), $adult_flag, t('This channel frequently or regularly publishes adult content. (Please tag any adult material and/or nudity with #NSFW)')), '$h_prv' => t('Security and Privacy Settings'), + '$hide_presence' => array('hide_presence', t('Hide my online presence'),$hide_presence, t('Prevents displaying in your profile that you are online')), + + '$lbl_pmacro' => t('Simple Privacy Settings:'), + '$pmacro3' => t('Very Public - <em>extremely permissive (should be used with caution)</em>'), + '$pmacro2' => t('Typical - <em>default public, privacy when desired (similar to social network permissions but with improved privacy)</em>'), + '$pmacro1' => t('Private - <em>default private, never open or public</em>'), + '$pmacro0' => t('Blocked - <em>default blocked to/from everybody</em>'), '$permiss_arr' => $permiss, + '$blocktags' => array('blocktags',t('Allow others to tag your posts'), 1-$blocktags, t('Often used by the community to retro-actively flag inappropriate content'),array(t('No'),t('Yes'))), + '$lbl_p2macro' => t('Advanced Privacy Settings'), + + '$expire' => array('expire',t('Expire other channel content after this many days'),$expire,t('0 or blank prevents expiration')), '$maxreq' => array('maxreq', t('Maximum Friend Requests/Day:'), intval($channel['channel_max_friend_req']) , t('May reduce spam activity')), '$permissions' => t('Default Post Permissions'), '$permdesc' => t("\x28click to open/close\x29"), - '$aclselect' => populate_acl($a->user,$celeb), + '$aclselect' => populate_acl($perm_defaults), '$suggestme' => $suggestme, '$group_select' => $group_select, - '$expire' => $expire_arr, - '$profile_in_dir' => $profile_in_dir, '$hide_friends' => $hide_friends, '$hide_wall' => $hide_wall, @@ -1036,8 +979,8 @@ function settings_content(&$a) { '$post_joingroup' => array('post_joingroup', t('joining a forum/community'), $post_joingroup, ''), '$post_profilechange' => array('post_profilechange', t('making an <em>interesting</em> profile change'), $post_profilechange, ''), '$lbl_not' => t('Send a notification email when:'), - '$notify1' => array('notify1', t('You receive an introduction'), ($notify & NOTIFY_INTRO), NOTIFY_INTRO, ''), - '$notify2' => array('notify2', t('Your introductions are confirmed'), ($notify & NOTIFY_CONFIRM), NOTIFY_CONFIRM, ''), + '$notify1' => array('notify1', t('You receive a connection request'), ($notify & NOTIFY_INTRO), NOTIFY_INTRO, ''), + '$notify2' => array('notify2', t('Your connections are confirmed'), ($notify & NOTIFY_CONFIRM), NOTIFY_CONFIRM, ''), '$notify3' => array('notify3', t('Someone writes on your profile wall'), ($notify & NOTIFY_WALL), NOTIFY_WALL, ''), '$notify4' => array('notify4', t('Someone writes a followup comment'), ($notify & NOTIFY_COMMENT), NOTIFY_COMMENT, ''), '$notify5' => array('notify5', t('You receive a private message'), ($notify & NOTIFY_MAIL), NOTIFY_MAIL, ''), @@ -1049,7 +992,11 @@ function settings_content(&$a) { '$h_advn' => t('Advanced Account/Page Type Settings'), '$h_descadvn' => t('Change the behaviour of this account for special situations'), '$pagetype' => $pagetype, - + '$expert' => feature_enabled(local_user(),'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, + '$menu_desc' => t('Personal menu to display in your channel pages'), )); call_hooks('settings_form',$o); diff --git a/mod/setup.php b/mod/setup.php index b05b0cec3..9eccffe75 100755 --- a/mod/setup.php +++ b/mod/setup.php @@ -4,7 +4,25 @@ $install_wizard_pass=1; function setup_init(&$a){ + + // Ensure that if somebody hasn't read the install documentation and doesn't have all + // the required modules or has a totally borked shared hosting provider and they can't + // figure out what the hell is going on - that we at least spit out an error message which + // we can inquire about when they write to tell us that our software doesn't work. + + // The worst thing we can do at this point is throw a white screen of death and rely on + // them knowing about servers and php modules and logfiles enough so that we can guess + // at the source of the problem. As ugly as it may be, we need to throw a technically worded + // PHP error message in their face. Once installation is complete application errors will + // throw a white screen because these error messages divulge information which can + // potentially be useful to hackers. + + error_reporting(E_ERROR | E_WARNING | E_PARSE ); + ini_set('log_errors','0'); + ini_set('display_errors', '1'); + + // $baseurl/setup/testrwrite to test if rewite in .htaccess is working if (argc() ==2 && argv(1)=="testrewrite") { echo "ok"; @@ -14,6 +32,7 @@ function setup_init(&$a){ if (x($_POST,'pass')) $install_wizard_pass = intval($_POST['pass']); + } function setup_post(&$a) { @@ -27,6 +46,7 @@ function setup_post(&$a) { case 3: $urlpath = $a->get_path(); $dbhost = notags(trim($_POST['dbhost'])); + $dbport = intval(notags(trim($_POST['dbport']))); $dbuser = notags(trim($_POST['dbuser'])); $dbpass = notags(trim($_POST['dbpass'])); $dbdata = notags(trim($_POST['dbdata'])); @@ -34,12 +54,16 @@ function setup_post(&$a) { $adminmail = notags(trim($_POST['adminmail'])); $siteurl = notags(trim($_POST['siteurl'])); - require_once("dba.php"); + require_once('include/dba/dba_driver.php'); unset($db); - $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true); + $db = dba_factory($dbhost, $dbport, $dbuser, $dbpass, $dbdata, true); + if(! $db->connected) { + echo "Database Connect failed: " . $db->error; + killme(); + } /*if(get_db_errno()) { unset($db); - $db = new dba($dbhost, $dbuser, $dbpass, '', true); + $db = dba_factory($dbhost, $dbport, $dbuser, $dbpass, '', true); if(! get_db_errno()) { $r = q("CREATE DATABASE '%s'", @@ -47,7 +71,7 @@ function setup_post(&$a) { ); if($r) { unset($db); - $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true); + $db = new dba($dbhost, $dbport, $dbuser, $dbpass, $dbdata, true); } else { $a->data['db_create_failed']=true; } @@ -65,6 +89,7 @@ function setup_post(&$a) { case 4: $urlpath = $a->get_path(); $dbhost = notags(trim($_POST['dbhost'])); + $dbport = intval(notags(trim($_POST['dbport']))); $dbuser = notags(trim($_POST['dbuser'])); $dbpass = notags(trim($_POST['dbpass'])); $dbdata = notags(trim($_POST['dbdata'])); @@ -74,13 +99,27 @@ function setup_post(&$a) { $siteurl = notags(trim($_POST['siteurl'])); + if($siteurl != z_root()) { + $test = z_fetch_url($siteurl."/setup/testrewrite"); + if((! $test['success']) || ($test['body'] != 'ok')) { + $a->data['url_fail'] = true; + $a->data['url_error'] = $test['error']; + return; + } + } // connect to db - $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true); + $db = dba_factory($dbhost, $dbport, $dbuser, $dbpass, $dbdata, true); + + if(! $db->connected) { + echo 'CRITICAL: DB not connected.'; + killme(); + } $tpl = get_intltext_template('htconfig.tpl'); $txt = replace_macros($tpl,array( '$dbhost' => $dbhost, + '$dbport' => $dbport, '$dbuser' => $dbuser, '$dbpass' => $dbpass, '$dbdata' => $dbdata, @@ -120,7 +159,7 @@ function setup_content(&$a) { global $install_wizard_pass, $db; $o = ''; $wizard_status = ""; - $install_title = t('Friendica Red Communications Server - Setup'); + $install_title = t('Red Matrix Server - Setup'); @@ -128,6 +167,13 @@ function setup_content(&$a) { $install_wizard_pass = 2; $wizard_status = t('Could not connect to database.'); } + if(x($a->data,'url_fail')) { + $install_wizard_pass = 3; + $wizard_status = t('Could not connect to specified site URL. Possible SSL certificate or DNS issue.'); + if($a->data['url_error']) + $wizard_status .= ' ' . $a->data['url_error']; + } + if(x($a->data,'db_create_failed')) { $install_wizard_pass = 2; $wizard_status = t('Could not create table.'); @@ -136,7 +182,7 @@ function setup_content(&$a) { $db_return_text=""; if(x($a->data,'db_installed')) { $txt = '<p style="font-size: 130%;">'; - $txt .= t('Your Friendica site database has been installed.') . EOL; + $txt .= t('Your site database has been installed.') . EOL; $db_return_text .= $txt; } @@ -148,7 +194,7 @@ function setup_content(&$a) { } if($db && $db->connected) { - $r = q("SELECT COUNT(*) as `total` FROM `user`"); + $r = q("SELECT COUNT(*) as `total` FROM `account`"); if($r && count($r) && $r[0]['total']) { $tpl = get_markup_template('install.tpl'); return replace_macros($tpl, array( @@ -185,6 +231,8 @@ function setup_content(&$a) { check_smarty3($checks); + check_store($checks); + check_keys($checks); if(x($_POST,'phpath')) @@ -222,6 +270,7 @@ function setup_content(&$a) { $dbhost = ((x($_POST,'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost'); $dbuser = notags(trim($_POST['dbuser'])); + $dbport = intval(notags(trim($_POST['dbport']))); $dbpass = notags(trim($_POST['dbpass'])); $dbdata = notags(trim($_POST['dbdata'])); $phpath = notags(trim($_POST['phpath'])); @@ -233,13 +282,14 @@ function setup_content(&$a) { $o .= replace_macros($tpl, array( '$title' => $install_title, '$pass' => t('Database connection'), - '$info_01' => t('In order to install Friendica we need to know how to connect to your database.'), + '$info_01' => t('In order to install Red Matrix we need to know how to connect to your database.'), '$info_02' => t('Please contact your hosting provider or site administrator if you have questions about these settings.'), '$info_03' => t('The database you specify below should already exist. If it does not, please create it before continuing.'), '$status' => $wizard_status, - '$dbhost' => array('dbhost', t('Database Server Name'), $dbhost, ''), + '$dbhost' => array('dbhost', t('Database Server Name'), $dbhost, t('Default is localhost')), + '$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, ''), '$dbdata' => array('dbdata', t('Database Name'), $dbdata, ''), @@ -260,8 +310,9 @@ function setup_content(&$a) { return $o; }; break; case 3: { // Site settings - require_once('datetime.php'); + require_once('include/datetime.php'); $dbhost = ((x($_POST,'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost'); + $dbport = intval(notags(trim($_POST['dbuser']))); $dbuser = notags(trim($_POST['dbuser'])); $dbpass = notags(trim($_POST['dbpass'])); $dbdata = notags(trim($_POST['dbdata'])); @@ -279,6 +330,7 @@ function setup_content(&$a) { '$status' => $wizard_status, '$dbhost' => $dbhost, + '$dbport' => $dbport, '$dbuser' => $dbuser, '$dbpass' => $dbpass, '$dbdata' => $dbdata, @@ -324,13 +376,16 @@ function check_php(&$phpath, &$checks) { if (strlen($phpath)){ $passed = file_exists($phpath); } else { - $phpath = trim(shell_exec('which php')); + if(is_windows()) + $phpath = trim(shell_exec('where php')); + else + $phpath = trim(shell_exec('which php')); $passed = strlen($phpath); } $help = ""; if(!$passed) { $help .= t('Could not find a command line version of PHP in the web server PATH.'). EOL; - $help .= t("If you don't have a command line version of PHP installed on server, you will not be able to run background polling via cron. See <a href='http://friendica.com/node/27'>'Activating scheduled tasks'</a>") . EOL ; + $help .= t("If you don't have a command line version of PHP installed on server, you will not be able to run background polling via cron.") . EOL; $help .= EOL . EOL ; $tpl = get_markup_template('field_input.tpl'); $help .= replace_macros($tpl, array( @@ -397,6 +452,12 @@ function check_funcs(&$checks) { check_add($ck_funcs, t('Apache mod_rewrite module'), true, true, ""); } } + if((! function_exists('proc_open')) || strstr(ini_get('disable_functions'),'proc_open')) { + check_add($ck_funcs, t('proc_open'), false, true, t('Error: proc_open is required but is either not installed or has been disabled in php.ini')); + } + else { + check_add($ck_funcs, t('proc_open'), true, true, ""); + } if(! function_exists('curl_init')){ $ck_funcs[0]['status']= false; @@ -419,8 +480,8 @@ function check_funcs(&$checks) { $ck_funcs[4]['help']= t('Error: mb_string PHP module required but not installed.'); } if(! function_exists('mcrypt_encrypt')){ - $ck_funcs[4]['status']= false; - $ck_funcs[4]['help']= t('Error: mcrypt PHP module required but not installed.'); + $ck_funcs[5]['status']= false; + $ck_funcs[5]['help']= t('Error: mcrypt PHP module required but not installed.'); } $checks = array_merge($checks, $ck_funcs); @@ -438,7 +499,7 @@ function check_htconfig(&$checks) { $status=false; $help = t('The web installer needs to be able to create a file called ".htconfig.php" in the top folder of your web server and it is unable to do so.') .EOL; $help .= t('This is most often a permission setting, as the web server may not be able to write files in your folder - even if you can.').EOL; - $help .= t('At the end of this procedure, we will give you a text to save in a file named .htconfig.php in your Friendica top folder.').EOL; + $help .= t('At the end of this procedure, we will give you a text to save in a file named .htconfig.php in your Red top folder.').EOL; $help .= t('You can alternatively skip this procedure and perform a manual installation. Please see the file "install/INSTALL.txt" for instructions.').EOL; } @@ -452,8 +513,8 @@ function check_smarty3(&$checks) { if( !is_writable('view/tpl/smarty3') ) { $status=false; - $help = t('Friendica uses the Smarty3 template engine to render its web views. Smarty3 compiles templates to PHP to speed up rendering.') .EOL; - $help .= t('In order to store these compiled templates, the web server needs to have write access to the directory view/tpl/smarty3/ under the Friendica top level folder.').EOL; + $help = t('Red uses the Smarty3 template engine to render its web views. Smarty3 compiles templates to PHP to speed up rendering.') .EOL; + $help .= t('In order to store these compiled templates, the web server needs to have write access to the directory view/tpl/smarty3/ under the Red top level folder.').EOL; $help .= t('Please ensure that the user that your web server runs as (e.g. www-data) has write access to this folder.').EOL; $help .= t('Note: as a security measure, you should give the web server write access to view/tpl/smarty3/ only--not the template files (.tpl) that it contains.').EOL; } @@ -462,13 +523,61 @@ function check_smarty3(&$checks) { } +function check_store(&$checks) { + $status = true; + $help = ""; + + @mkdir('store',STORAGE_DEFAULT_PERMISSIONS); + + if( !is_writable('store') ) { + + $status=false; + $help = t('Red uses the store directory to save uploaded files. The web server needs to have write access to the store directory under the Red top level folder') . EOL; + $help .= t('Please ensure that the user that your web server runs as (e.g. www-data) has write access to this folder.').EOL; + } + + check_add($checks, t('store is writable'), $status, true, $help); + +} + + function check_htaccess(&$checks) { $a = get_app(); $status = true; $help = ""; + $ssl_error = false; + + $url = $a->get_baseurl() . '/test/rewrite'; + if (function_exists('curl_init')){ - $test = fetch_url($a->get_baseurl()."/setup/testrewrite"); - if ($test!="ok") { + $test = z_fetch_url($url); + if(! $test['success']) { + if(strstr($url,'https://')) { + $test = z_fetch_url($url,false,0,array('novalidate' => true)); + if($test['success']) { + $ssl_error = true; + } + } + else { + $test = z_fetch_url(str_replace('http://','https://',$url),false,0,array('novalidate' => true)); + if($test['success']) { + $ssl_error = true; + } + } + + if($ssl_error) { + $help = t('SSL certificate cannot be validated. Fix certificate or disable https access to this site.') . EOL; + $help .= t('If you have https access to your website or allow connections to TCP port 443 (the https: port), you MUST use a browser-valid certificate. You MUST NOT use self-signed certificates!') . EOL; + $help .= t('This restriction is incorporated because public posts from you may for example contain references to images on your own hub.') . EOL; + $help .= t('If your certificate is not recognised, members of other sites (who may themselves have valid certificates) will get a warning message on their own site complaining about security issues.') . EOL; + $help .= t('This can cause usability issues elsewhere (not just on your own site) so we must insist on this requirement.') .EOL; + $help .= t('Providers are available that issue free certificates which are browser-valid.'). EOL; + + check_add($checks, t('SSL certificate validation'),false,true, $help); + } + } + + if ((! $test['success']) || ($test['body'] != "ok")) { $status = false; $help = t('Url rewrite in .htaccess is not working. Check your server configuration.'); } @@ -481,7 +590,7 @@ function check_htaccess(&$checks) { function manual_config(&$a) { - $data = htmlentities($a->data['txt']); + $data = htmlspecialchars($a->data['txt'],ENT_COMPAT,'UTF-8'); $o = t('The database configuration file ".htconfig.php" could not be written. Please use the enclosed text to create a configuration file in your web server root.'); $o .= "<textarea rows=\"24\" cols=\"80\" >$data</textarea>"; return $o; @@ -515,13 +624,37 @@ function load_database($db) { function what_next() { $a = get_app(); + // install the standard theme + set_config('system','allowed_themes','redbasic'); + + // Set a lenient list of ciphers if using openssl. Other ssl engines + // (e.g. NSS used in RedHat) require different syntax, so hopefully + // the default curl cipher list will work for most sites. If not, + // this can set via config. Many distros are now disabling RC4, + // but many Red sites still use it and are unable to change it. + // We do not use SSL for encryption, only to protect session cookies. + // z_fetch_url() is also used to import shared links and other content + // so in theory most any cipher could show up and we should do our best + // to make the content available rather than tell folks that there's a + // weird SSL error which they can't do anything about. + + $x = curl_version(); + if(stristr($x['ssl_version'],'openssl')) + set_config('system','curl_ssl_ciphers','ALL:!eNULL'); + + + // Create a system channel + require_once ('include/identity.php'); + create_sys_channel(); + + $baseurl = $a->get_baseurl(); return t('<h1>What next</h1>') ."<p>".t('IMPORTANT: You will need to [manually] setup a scheduled task for the poller.') .t('Please see the file "install/INSTALL.txt".') ."</p><p>" - .t("Go to your new Friendica node <a href='$baseurl/register'>registration page</a> and register as new user. Remember to use the same email you have entered as administrator email. This will allow you to enter the site admin panel.") + .t("Go to your new Red node <a href='$baseurl/register'>registration page</a> and register as new user. Remember to use the same email you have entered as administrator email. This will allow you to enter the site admin panel.") ."</p>"; } diff --git a/mod/share.php b/mod/share.php index 33aa9eede..8b0403663 100644 --- a/mod/share.php +++ b/mod/share.php @@ -1,31 +1,81 @@ <?php +require_once('include/security.php'); require_once('bbcode.php'); function share_init(&$a) { $post_id = ((argc() > 1) ? intval(argv(1)) : 0); - if((! $post_id) || (! local_user())) + + if(! $post_id) + killme(); + + if(! (local_user() || remote_user())) killme(); - $r = q("SELECT * from item WHERE id = %d AND uid = %d and item_restrict = 0 LIMIT 1", - intval($post_id), - intval(local_user()) + + $r = q("SELECT * from item WHERE id = %d LIMIT 1", + intval($post_id) ); if((! $r) || $r[0]['item_private']) killme(); + $sql_extra = item_permissions_sql($r[0]['uid']); + + $r = q("select * from item where id = %d $sql_extra", + intval($post_id) + ); + if(! $r) + killme(); + + // FIXME - we only share bbcode + + if($r[0]['mimetype'] !== 'text/bbcode') + killme(); + + // FIXME - eventually we want to post remotely via rpost + // on your home site. + // When that works remove this next bit: + + if(! local_user()) + killme(); + xchan_query($r); - $o = '[share]' . "\n"; + if (strpos($r[0]['body'], "[/share]") !== false) { + $pos = strpos($r[0]['body'], "[share"); + $o = substr($r[0]['body'], $pos); + } else { + $o = "[share author='".urlencode($r[0]['author']['xchan_name']). + "' profile='".$r[0]['author']['xchan_url'] . + "' avatar='".$r[0]['author']['xchan_photo_s']. + "' link='".$r[0]['plink']. + "' posted='".$r[0]['created']. + "' message_id='".$r[0]['mid']."']\n"; + if($r[0]['title']) + $o .= '[b]'.$r[0]['title'].'[/b]'."\n"; + $o .= $r[0]['body']; + $o.= "[/share]"; + } - $o .= "\xE2\x99\xb2" . ' [url=' . $r[0]['author']['xchan_url'] . ']' . $r[0]['author']['xchan_name'] . '[/url]' . "\n"; - if($r[0]['title']) - $o .= '[b]' . $r[0]['title'] . '[/b]' . "\n"; - $o .= $r[0]['body'] . "\n" ; + if(local_user()) { + echo $o; + killme(); + } + + $observer = $a->get_observer(); + $parsed = $observer['xchan_url']; + if($parsed) { + $post_url = $parsed['scheme'] . ':' . $parsed['host'] . (($parsed['port']) ? ':' . $parsed['port'] : '') + . '/rpost'; + // FIXME - we were probably called from JS + // so we don't know the return page. + // in fact we won't be able to load the remote page. + // we might need an iframe - $o .= (($r[0]['plink']) ? '[url=' . $r[0]['plink'] . ']' . t('link') . '[/url]' . "\n" : '') . '[/share]'; + $x = z_post_url($post_url, array('f' => '', 'body' => $o )); + killme(); + } + - echo $o; - killme(); } diff --git a/mod/siteinfo.php b/mod/siteinfo.php index 0cd569d20..bdf9b1af6 100644 --- a/mod/siteinfo.php +++ b/mod/siteinfo.php @@ -27,14 +27,20 @@ function siteinfo_init(&$a) { $visible_plugins[] = $rr['name']; } + if(@is_dir('.git') && function_exists('shell_exec')) + $commit = @shell_exec('git log -1 --format="%h"'); + if(! isset($commit) || strlen($commit) > 16) + $commit = ''; + $data = Array( - 'version' => FRIENDICA_VERSION, + 'version' => RED_VERSION, + 'commit' => $commit, 'url' => z_root(), 'plugins' => $visible_plugins, 'register_policy' => $register_policy[$a->config['system']['register_policy']], 'admin' => $admin, 'site_name' => $a->config['sitename'], - 'platform' => FRIENDICA_PLATFORM, + 'platform' => RED_PLATFORM, 'info' => ((x($a->config,'info')) ? $a->config['info'] : '') ); @@ -47,27 +53,16 @@ function siteinfo_init(&$a) { function siteinfo_content(&$a) { - // FIXME Gak - this needs to be a template. - - $o = ''; - $o .= '<h3>' . t('Red') . '</h3>'; - - - $o .= '<p></p><p>'; - - $o .= t('This is Red - another decentralized, distributed communications project by the folks at Friendica.'); - if(! get_config('system','hidden_version_siteinfo')) - $o .= '</p><p>' . sprintf( t('Version %s'), FRIENDICA_VERSION ) . '</p><p>'; - $o .= '</p><p>'; - $o .= t('Running at web location') . ' ' . z_root() . '</p><p>'; - - $o .= t('Please visit <a href="http://friendica.com">Friendica.com</a> to learn more about the Friendica and/or Red project.') . '</p><p>'; - - $o .= t('Bug reports and issues: please visit') . ' ' . '<a href="http://bugs.friendica.com">Bugs.Friendica.com</a></p><p>'; - $o .= t('Suggestions, praise, donations, etc. - please email "Info" at Friendica - dot com') . '</p>'; - - $o .= '<p></p>'; - + if(! get_config('system','hidden_version_siteinfo')) { + $version = sprintf( t('Version %s'), RED_VERSION ); + if(@is_dir('.git') && function_exists('shell_exec')) + $commit = @shell_exec('git log -1 --format="%h"'); + if(! isset($commit) || strlen($commit) > 16) + $commit = ''; + } + else { + $version = $commit = ''; + } $visible_plugins = array(); if(is_array($a->plugins) && count($a->plugins)) { $r = q("select * from addon where hidden = 0"); @@ -76,9 +71,9 @@ function siteinfo_content(&$a) { $visible_plugins[] = $rr['name']; } - + $plugins_list = ''; if(count($visible_plugins)) { - $o .= '<p>' . t('Installed plugins/addons/apps:') . '</p>'; + $plugins_text = t('Installed plugins/addons/apps:'); $sorted = $visible_plugins; $s = ''; sort($sorted); @@ -88,10 +83,33 @@ function siteinfo_content(&$a) { $s .= $p; } } - $o .= '<div style="margin-left: 25px; margin-right: 25px;">' . $s . '</div>'; + $plugins_list .= $s; } else - $o .= '<p>' . t('No installed plugins/addons/apps') . '</p>'; + $plugins_text = t('No installed plugins/addons/apps'); + + $admininfo = bbcode(get_config('system','admininfo')); + + if(file_exists('doc/site_donate.html')) + $donate .= file_get_contents('doc/site_donate.html'); + + $o = replace_macros(get_markup_template('siteinfo.tpl'), array( + '$title' => t('Red'), + '$description' => t('This is a hub of the Red Matrix - a global cooperative network of decentralised privacy enhanced websites.'), + '$version' => $version, + '$commit' => $commit, + '$web_location' => t('Running at web location') . ' ' . z_root(), + '$visit' => t('Please visit <a href="http://getzot.com">GetZot.com</a> to learn more about the Red Matrix.'), + '$bug_text' => t('Bug reports and issues: please visit'), + '$bug_link_url' => 'https://github.com/friendica/red/issues', + '$bug_link_text' => 'redmatrix issues', + '$contact' => t('Suggestions, praise, etc. - please email "redmatrix" at librelist - dot com'), + '$donate' => $donate, + '$adminlabel' => t('Site Administrators'), + '$admininfo' => $admininfo, + '$plugins_text' => $plugins_text, + '$plugins_list' => $plugins_list + )); call_hooks('about_hook', $o); diff --git a/mod/sitelist.php b/mod/sitelist.php new file mode 100644 index 000000000..1e6d0fcfb --- /dev/null +++ b/mod/sitelist.php @@ -0,0 +1,51 @@ +<?php /** @file */ + +function sitelist_init(&$a) { + + $start = (($_REQUEST['start']) ? intval($_REQUEST['start']) : 0); + $limit = ((intval($_REQUEST['limit'])) ? intval($_REQUEST['limit']) : 30); + $order = (($_REQUEST['order']) ? $_REQUEST['order'] : 'random'); + $open = (($_REQUEST['open']) ? intval($_REQUEST['open']) : false); + + + $sql_order = " order by site_url "; + if($order == 'random') + $sql_order = " order by rand() "; + + $sql_limit = " limit $start, $limit "; + + $sql_extra = ""; + if($open) + $sql_extra = " and site_register = " . intval(REGISTER_OPEN) . " "; + + + $result = array('success' => false); + + $r = q("select count(site_url) as total from site where 1 $sql_extra "); + + if($r) + $result['total'] = intval($r[0]['total']); + + $result['start'] = $start; + $result['limit'] = $limit; + + $r = q("select * from site where true $sql_extra $sql_order $sql_limit"); + + $result['results'] = 0; + $result['entries'] = array(); + + if($r) { + $result['success'] = true; + $result['results'] = count($r); + + foreach($r as $rr) { + $result['entries'][] = array('url' => $rr['site_url']); + } + + } + + echo json_encode($result); + killme(); + + +}
\ No newline at end of file diff --git a/mod/sources.php b/mod/sources.php new file mode 100644 index 000000000..f4b36508f --- /dev/null +++ b/mod/sources.php @@ -0,0 +1,168 @@ +<?php /** @file */ + +function sources_post(&$a) { + if(! local_user()) + return; + + if(! feature_enabled(local_user(),'channel_sources')) + return ''; + + $source = intval($_REQUEST['source']); + $xchan = $_REQUEST['xchan']; + $abook = intval($_REQUEST['abook']); + $words = $_REQUEST['words']; + $frequency = $_REQUEST['frequency']; + $name = $_REQUEST['name']; + + $channel = $a->get_channel(); + + if($name == '*') + $xchan = '*'; + + if($abook) { + $r = q("select abook_xchan from abook where abook_id = %d and abook_channel = %d limit 1", + intval($abook), + intval(local_user()) + ); + if($r) + $xchan = $r[0]['abook_xchan']; + } + + if(! $xchan) { + notice ( t('Failed to create source. No channel selected.') . EOL); + return; + } + + if(! $source) { + $r = q("insert into source ( src_channel_id, src_channel_xchan, src_xchan, src_patt ) + values ( %d, '%s', '%s', '%s' ) ", + intval(local_user()), + dbesc($channel['channel_hash']), + dbesc($xchan), + dbesc($words) + ); + if($r) { + info( t('Source created.') . EOL); + } + goaway(z_root() . '/sources'); + } + else { + $r = q("update source set src_xchan = '%s', src_patt = '%s' where src_channel_id = %d and src_id = %d limit 1", + dbesc($xchan), + dbesc($words), + intval(local_user()), + intval($source) + ); + if($r) { + info( t('Source updated.') . EOL); + } + + } +} + + +function sources_content(&$a) { + if(! local_user()) { + notice( t('Permission denied.') . EOL); + return ''; + } + + if(! feature_enabled(local_user(),'channel_sources')) { + return ''; + } + + // list sources + if(argc() == 1) { + $r = q("select source.*, xchan.* from source left join xchan on src_xchan = xchan_hash where src_channel_id = %d", + intval(local_user()) + ); + if($r) { + for($x = 0; $x < count($r); $x ++) { + if($r[$x]['src_xchan'] == '*') { + $r[$x]['xchan_name'] = t('*'); + } + $r[$x]['src_patt'] = htmlspecialchars($r[$x]['src_patt'], ENT_COMPAT,'UTF-8'); + } + } + $o = replace_macros(get_markup_template('sources_list.tpl'), array( + '$title' => t('Channel Sources'), + '$desc' => t('Manage remote sources of content for your channel.'), + '$new' => t('New Source'), + '$sources' => $r + )); + return $o; + } + + if(argc() == 2 && argv(1) === 'new') { + // TODO add the words 'or RSS feed' and corresponding code to manage feeds and frequency + + $o = replace_macros(get_markup_template('sources_new.tpl'), array( + '$title' => t('New Source'), + '$desc' => t('Import all or selected content from the following channel into this channel and distribute it according to your channel settings.'), + '$words' => array( 'words', t('Only import content with these words (one per line)'),'',t('Leave blank to import all public content')), + '$name' => array( 'name', t('Channel Name'), '', ''), + '$submit' => t('Submit') + )); + return $o; + + } + + if(argc() == 2 && intval(argv(1))) { + // edit source + $r = q("select source.*, xchan.* from source left join xchan on src_xchan = xchan_hash where src_id = %d and src_channel_id = %d limit 1", + intval(argv(1)), + intval(local_user()) + ); + if($r) { + $x = q("select abook_id from abook where abook_xchan = '%s' and abook_channel = %d limit 1", + dbesc($r[0]['src_xchan']), + intval(local_user()) + ); + } + if(! $r) { + notice( t('Source not found.') . EOL); + return ''; + } + + $r[0]['src_patt'] = htmlspecialchars($r[0]['src_patt'], ENT_QUOTES,'UTF-8'); + + $o = replace_macros(get_markup_template('sources_edit.tpl'), array( + '$title' => t('Edit Source'), + '$drop' => t('Delete Source'), + '$id' => $r[0]['src_id'], + '$desc' => t('Import all or selected content from the following channel into this channel and distribute it according to your channel settings.'), + '$words' => array( 'words', t('Only import content with these words (one per line)'),$r[0]['src_patt'],t('Leave blank to import all public content')), + '$xchan' => $r[0]['src_xchan'], + '$abook' => $x[0]['abook_id'], + '$name' => array( 'name', t('Channel Name'), $r[0]['xchan_name'], ''), + '$submit' => t('Submit') + )); + return $o; + + } + + if(argc() == 3 && intval(argv(1)) && argv(2) === 'drop') { + $r = q("select * from source where src_id = %d and src_channel_id = %d limit 1", + intval(argv(1)), + intval(local_user()) + ); + if(! $r) { + notice( t('Source not found.') . EOL); + return ''; + } + $r = q("delete from source where src_id = %d and src_channel_id = %d limit 1", + intval(argv(1)), + intval(local_user()) + ); + if($r) + info( t('Source removed') . EOL); + else + notice( t('Unable to remove source.') . EOL); + + goaway(z_root() . '/sources'); + + } + + // shouldn't get here. + +}
\ No newline at end of file diff --git a/mod/sslify.php b/mod/sslify.php new file mode 100644 index 000000000..ed06d87c1 --- /dev/null +++ b/mod/sslify.php @@ -0,0 +1,24 @@ +<?php + +function sslify_init(&$a) { + $x = z_fetch_url($_REQUEST['url']); + if($x['success']) { + $h = explode("\n",$x['headers']); + 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']; + + header('Content-Type: ' . $type); + echo $x['body']; + killme(); + } + killme(); + // for some reason when this fallback is in place - it gets triggered + // often, (creating mixed content exceptions) even though there is + // nothing obvious missing on the page when we bypass it. + goaway($_REQUEST['url']); +} + diff --git a/mod/starred.php b/mod/starred.php index 530c5c7e0..ca7621b0f 100644 --- a/mod/starred.php +++ b/mod/starred.php @@ -19,13 +19,7 @@ function starred_init(&$a) { if(! count($r)) killme(); - $item_flags = $r[0]['item_flags']; - - if($item_flags & ITEM_STARRED) - $item_flags -= ITEM_STARRED; - else - $item_flags += ITEM_STARRED; - + $item_flags = ( $r[0]['item_flags'] ^ ITEM_STARRED ); $r = q("UPDATE item SET item_flags = %d WHERE uid = %d and id = %d LIMIT 1", intval($item_flags), diff --git a/mod/subthread.php b/mod/subthread.php index f8918e25d..5ef0615b1 100755 --- a/mod/subthread.php +++ b/mod/subthread.php @@ -7,20 +7,20 @@ require_once('include/items.php'); function subthread_content(&$a) { - if(! local_user() && ! remote_user()) { + if((! local_user()) && (! remote_user())) { return; } $activity = ACTIVITY_FOLLOW; - $item_id = (($a->argc > 1) ? notags(trim($a->argv[1])) : 0); + $item_id = ((argc() > 1) ? notags(trim(argv(1))) : 0); - $r = q("SELECT * FROM `item` WHERE `parent` = '%s' OR `parent-uri` = '%s' and parent = id LIMIT 1", + $r = q("SELECT * FROM `item` WHERE `parent` = '%s' OR `parent_mid` = '%s' and parent = id LIMIT 1", dbesc($item_id), dbesc($item_id) ); - if(! $item_id || (! count($r))) { + if((! $item_id) || (! $r)) { logger('subthread: no item ' . $item_id); return; } @@ -34,60 +34,146 @@ function subthread_content(&$a) { if(! perm_is_allowed($owner_uid,$ob_hash,'post_comments')) return; + $sys = get_sys_channel(); - $remote_owner = null; + $owner_uid = $item['uid']; + $owner_aid = $item['aid']; - if(! $item['wall']) { - // The top level post may have been written by somebody on another system - $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", - intval($item['contact-id']), - intval($item['uid']) - ); - if(! count($r)) - return; - if(! $r[0]['self']) - $remote_owner = $r[0]; + // if this is a "discover" item, (item['uid'] is the sys channel), + // fallback to the item comment policy, which should've been + // respected when generating the conversation thread. + // Even if the activity is rejected by the item owner, it should still get attached + // to the local discover conversation on this site. + + if(($owner_uid != $sys['channel_id']) && (! perm_is_allowed($owner_uid,$observer['xchan_hash'],'post_comments'))) { + notice( t('Permission denied') . EOL); + killme(); } - // this represents the post owner on this system. + $r = q("select * from xchan where xchan_hash = '%s' limit 1", + dbesc($item['owner_xchan']) + ); + if($r) + $thread_owner = $r[0]; + else + killme(); - $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid` - WHERE `contact`.`self` = 1 AND `contact`.`uid` = %d LIMIT 1", - intval($owner_uid) + $r = q("select * from xchan where xchan_hash = '%s' limit 1", + dbesc($item['author_xchan']) ); - if(count($r)) - $owner = $r[0]; + if($r) + $item_author = $r[0]; + else + killme(); + + + $mid = item_message_id(); + + $post_type = (($item['resource_type'] === 'photo') ? t('photo') : t('status')); + + $links = array(array('rel' => 'alternate','type' => 'text/html', 'href' => $item['plink'])); + $objtype = (($item['resource_type'] === 'photo') ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE ); + + $body = $item['body']; + + $obj = json_encode(array( + 'type' => $objtype, + 'id' => $item['mid'], + 'parent' => (($item['thr_parent']) ? $item['thr_parent'] : $item['parent_mid']), + 'link' => $links, + 'title' => $item['title'], + 'content' => $item['body'], + 'created' => $item['created'], + 'edited' => $item['edited'], + 'author' => array( + 'name' => $item_author['xchan_name'], + 'address' => $item_author['xchan_addr'], + 'guid' => $item_author['xchan_guid'], + 'guid_sig' => $item_author['xchan_guid_sig'], + 'link' => array( + array('rel' => 'alternate', 'type' => 'text/html', 'href' => $item_author['xchan_url']), + array('rel' => 'photo', 'type' => $item_author['xchan_photo_mimetype'], 'href' => $item_author['xchan_photo_m'])), + ), + )); + + if(! ($item['item_flags'] & ITEM_THREAD_TOP)) + $post_type = 'comment'; + + + $bodyverb = t('%1$s is following %2$s\'s %3$s'); + + $item_flags = ITEM_ORIGIN | ITEM_NOTSHOWN; + if($item['item_flags'] & ITEM_WALL) + $item_flags |= ITEM_WALL; + + + $arr = array(); + + $arr['mid'] = $mid; + $arr['aid'] = $owner_aid; + $arr['uid'] = $owner_uid; + $arr['item_flags'] = $item_flags; + $arr['parent'] = $item['id']; + $arr['parent_mid'] = $item['mid']; + $arr['thr_parent'] = $item['mid']; + $arr['owner_xchan'] = $thread_owner['xchan_hash']; + $arr['author_xchan'] = $observer['xchan_hash']; + + + $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]'; + + $arr['body'] = sprintf( $bodyverb, $alink, $ulink, $plink ); + + $arr['verb'] = $activity; + $arr['obj_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']; + + + $post = item_store($arr); + $post_id = $post['item_id']; + + $arr['id'] = $post_id; + + call_hooks('post_local_end', $arr); + + killme(); + + + + + + + + + + + + + + + + + + + + - if(! $owner) { - logger('like: no owner'); - return; - } - if(! $remote_owner) - $remote_owner = $owner; - // This represents the person posting - if((local_user()) && (local_user() == $owner_uid)) { - $contact = $owner; - } - else { - $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", - intval($_SESSION['visitor_id']), - intval($owner_uid) - ); - if(count($r)) - $contact = $r[0]; - } - if(! $contact) { - return; - } - $uri = item_message_id(); $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']; @@ -96,20 +182,16 @@ function subthread_content(&$a) { <object> <type>$objtype</type> <local>1</local> - <id>{$item['uri']}</id> + <id>{$item['mid']}</id> <link>$link</link> <title></title> <content>$body</content> </object> EOT; - $bodyverb = t('%1$s is following %2$s\'s %3$s'); - - if(! isset($bodyverb)) - return; $arr = array(); - $arr['uri'] = $uri; + $arr['mid'] = $mid; $arr['uid'] = $owner_uid; $arr['contact-id'] = $contact['id']; $arr['type'] = 'activity'; @@ -117,8 +199,8 @@ EOT; $arr['origin'] = 1; $arr['gravity'] = GRAVITY_LIKE; $arr['parent'] = $item['id']; - $arr['parent-uri'] = $item['uri']; - $arr['thr_parent'] = $item['uri']; + $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']; @@ -126,9 +208,9 @@ EOT; $arr['author-link'] = $contact['url']; $arr['author-avatar'] = $contact['thumb']; - $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]'; - $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]'; - $plink = '[url=' . $a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . ']' . $post_type . '[/url]'; + $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; @@ -142,7 +224,8 @@ EOT; $arr['unseen'] = 1; $arr['last-child'] = 0; - $post_id = item_store($arr); + $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 LIMIT 1", diff --git a/mod/suggest.php b/mod/suggest.php index 4aed2e61a..8a6b50b22 100644 --- a/mod/suggest.php +++ b/mod/suggest.php @@ -2,25 +2,23 @@ require_once('include/socgraph.php'); require_once('include/contact_widgets.php'); +require_once('include/widgets.php'); function suggest_init(&$a) { if(! local_user()) return; - if(x($_GET,'ignore') && intval($_GET['ignore'])) { - q("insert into gcign ( uid, gcid ) values ( %d, %d ) ", + if(x($_GET,'ignore')) { + q("insert into xign ( uid, xchan ) values ( %d, '%s' ) ", intval(local_user()), - intval($_GET['ignore']) + dbesc($_GET['ignore']) ); } } - - - function suggest_content(&$a) { $o = ''; @@ -31,38 +29,37 @@ function suggest_content(&$a) { $_SESSION['return_url'] = $a->get_baseurl() . '/' . $a->cmd; - $a->page['aside'] .= follow_widget(); - $a->page['aside'] .= findpeople_widget(); - - - $o .= '<h2>' . t('Friend Suggestions') . '</h2>'; - + $r = suggestion_query(local_user(),get_observer_hash()); - $r = suggestion_query(local_user()); - - if(! count($r)) { - $o .= t('No suggestions available. If this is a new site, please try again in 24 hours.'); - return $o; + if(! $r) { + info( t('No suggestions available. If this is a new site, please try again in 24 hours.')); + return; } - $tpl = get_markup_template('suggest_friends.tpl'); + $arr = array(); foreach($r as $rr) { - $connlnk = $a->get_baseurl() . '/follow/?url=' . (($rr['connect']) ? $rr['connect'] : $rr['url']); - - $o .= replace_macros($tpl,array( - '$url' => zid($rr['url']), - '$name' => $rr['name'], - '$photo' => $rr['photo'], - '$ignlnk' => $a->get_baseurl() . '/suggest?ignore=' . $rr['id'], - '$conntxt' => t('Connect'), - '$connlnk' => $connlnk, - '$ignore' => t('Ignore/Hide') - )); + $connlnk = $a->get_baseurl() . '/follow/?url=' . $rr['xchan_addr']; + + $arr[] = array( + 'url' => chanlink_url($rr['xchan_url']), + 'profile' => $rr['xchan_url'], + 'name' => $rr['xchan_name'], + 'photo' => $rr['xchan_photo_m'], + 'ignlnk' => $a->get_baseurl() . '/suggest?ignore=' . $rr['xchan_hash'], + 'conntxt' => t('Connect'), + 'connlnk' => $connlnk, + 'ignore' => t('Ignore/Hide') + ); } - $o .= cleardiv(); -// $o .= paginate($a); + + $o = replace_macros(get_markup_template('suggest_page.tpl'),array( + '$title' => t('Channel Suggestions'), + '$entries' => $arr + )); + return $o; + } diff --git a/mod/tagger.php b/mod/tagger.php index 9c36a8b09..ec5c92184 100644 --- a/mod/tagger.php +++ b/mod/tagger.php @@ -11,6 +11,8 @@ function tagger_content(&$a) { return; } + $observer_hash = get_observer_hash(); + $term = notags(trim($_GET['term'])); // no commas allowed $term = str_replace(array(',',' '),array('','_'),$term); @@ -23,11 +25,12 @@ function tagger_content(&$a) { logger('tagger: tag ' . $term . ' item ' . $item_id); - $r = q("SELECT * FROM `item` WHERE `id` = '%s' LIMIT 1", - dbesc($item_id) + $r = q("SELECT * FROM item left join xchan on xchan_hash = author_xchan WHERE id = '%s' and uid = %d LIMIT 1", + dbesc($item_id), + intval(local_user()) ); - if(! $item_id || (! count($r))) { + if((! $item_id) || (! $r)) { logger('tagger: no item ' . $item_id); return; } @@ -36,89 +39,82 @@ function tagger_content(&$a) { $owner_uid = $item['uid']; - $r = q("select `nickname`,`blocktags` from user where uid = %d limit 1", - intval($owner_uid) - ); - if(count($r)) { - $owner_nick = $r[0]['nickname']; - $blocktags = $r[0]['blocktags']; + switch($item['resource_type']) { + case 'photo': + $targettype = ACTIVITY_OBJ_PHOTO; + $post_type = t('photo'); + break; + case 'event': + $targgettype = ACTIVITY_OBJ_EVENT; + $post_type = t('event'); + break; + default: + $targettype = ACTIVITY_OBJ_NOTE; + $post_type = t('status'); + if($item['mid'] != $item['parent_mid']) + $post_type = t('comment'); + break; } - if(local_user() != $owner_uid) - return; - $r = q("select * from contact where self = 1 and uid = %d limit 1", - intval(local_user()) - ); - if(count($r)) - $contact = $r[0]; - else { - logger('tagger: no contact_id'); - return; - } + $links = array(array('rel' => 'alternate','type' => 'text/html', + 'href' => z_root() . '/display/' . $item['mid'])); - $uri = item_message_id(); - $xterm = xmlify($term); - $post_type = (($item['resource_id']) ? t('photo') : t('status')); - $targettype = (($item['resource_id']) ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE ); + $target = json_encode(array( + 'type' => $targettype, + 'id' => $item['mid'], + 'link' => $links, + 'title' => $item['title'], + 'content' => $item['body'], + 'created' => $item['created'], + 'edited' => $item['edited'], + 'author' => array( + 'name' => $item['xchan_name'], + 'address' => $item['xchan_addr'], + 'guid' => $item['xchan_guid'], + 'guid_sig' => $item['xchan_guid_sig'], + 'link' => array( + array('rel' => 'alternate', 'type' => 'text/html', 'href' => $item['xchan_url']), + array('rel' => 'photo', 'type' => $item['xchan_photo_mimetype'], 'href' => $item['xchan_photo_m'])), + ), + )); - $link = xmlify('<link rel="alternate" type="text/html" href="' - . $a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . '" />' . "\n") ; - $body = xmlify($item['body']); - $target = <<< EOT - <target> - <type>$targettype</type> - <local>1</local> - <id>{$item['uri']}</id> - <link>$link</link> - <title></title> - <content>$body</content> - </target> -EOT; + $link = xmlify('<link rel="alternate" type="text/html" href="' + . $a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . '" />' . "\n") ; $tagid = $a->get_baseurl() . '/search?tag=' . $term; $objtype = ACTIVITY_OBJ_TAGTERM; - $obj = <<< EOT - <object> - <type>$objtype</type> - <local>1</local> - <id>$tagid</id> - <link>$tagid</link> - <title>$xterm</title> - <content>$xterm</content> - </object> -EOT; + $obj = json_encode(array( + 'type' => $objtype, + 'id' => $tagid, + 'link' => array(array('rel' => 'alternate','type' => 'text/html', 'href' => $tagid)), + 'title' => $term, + 'content' => $term + )); $bodyverb = t('%1$s tagged %2$s\'s %3$s with %4$s'); - if(! isset($bodyverb)) - return; + $termlink = html_entity_decode('⌗') . '[zrl=' . $a->get_baseurl() . '/search?tag=' . urlencode($term) . ']'. $term . '[/zrl]'; - $termlink = html_entity_decode('⌗') . '[url=' . $a->get_baseurl() . '/search?tag=' . urlencode($term) . ']'. $term . '[/url]'; + $channel = $a->get_channel(); $arr = array(); - $arr['uri'] = $uri; - $arr['uid'] = $owner_uid; - $arr['contact-id'] = $contact['id']; - $arr['type'] = 'activity'; - $arr['wall'] = $item['wall']; - $arr['gravity'] = GRAVITY_COMMENT; - $arr['parent'] = $item['id']; - $arr['parent_uri'] = $item['uri']; - $arr['owner-name'] = $item['author-name']; - $arr['owner-link'] = $item['author-link']; - $arr['owner-avatar'] = $item['author-avatar']; - $arr['author-name'] = $contact['name']; - $arr['author-link'] = $contact['url']; - $arr['author-avatar'] = $contact['thumb']; + $arr['owner_xchan'] = $item['owner_xchan']; + $arr['author_xchan'] = $channel['channel_hash']; + + + $arr['item_flags'] = ITEM_ORIGIN; + if($item['item_flags'] & ITEM_WALL) + $arr['item_flags'] |= ITEM_WALL; - $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]'; - $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]'; - $plink = '[url=' . $item['plink'] . ']' . $post_type . '[/url]'; + $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]'; + $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink, $termlink ); $arr['verb'] = ACTIVITY_TAG; @@ -126,65 +122,14 @@ EOT; $arr['target'] = $target; $arr['obj_type'] = $objtype; $arr['object'] = $obj; - $arr['private'] = $item['private']; - $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['origin'] = 1; - - $post_id = item_store($arr); - - q("UPDATE `item` set plink = '%s' where id = %d limit 1", - dbesc($a->get_baseurl() . '/display/' . $owner_nick . '/' . $post_id), - intval($post_id) - ); - - - if(! $item['visible']) { - $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d AND `uid` = %d LIMIT 1", - intval($item['id']), - intval($owner_uid) - ); - } - - if((! $blocktags) && (! stristr($item['tag'], ']' . $term . '[' ))) { - q("update item set tag = '%s' where id = %d limit 1", - dbesc($item['tag'] . (strlen($item['tag']) ? ',' : '') . '#[url=' . $a->get_baseurl() . '/search?tag=' . $term . ']'. $term . '[/url]'), - intval($item['id']) - ); - } - - // if the original post is on this site, update it. - - $r = q("select `tag`,`id`,`uid` from item where `origin` = 1 AND `uri` = '%s' LIMIT 1", - dbesc($item['uri']) - ); - if(count($r)) { - $x = q("SELECT `blocktags` FROM `user` WHERE `uid` = %d limit 1", - intval($r[0]['uid']) - ); - if(count($x) && !$x[0]['blocktags'] && (! stristr($r[0]['tag'], ']' . $term . '['))) { - q("update item set tag = '%s' where id = %d limit 1", - dbesc($r[0]['tag'] . (strlen($r[0]['tag']) ? ',' : '') . '#[url=' . $a->get_baseurl() . '/search?tag=' . $term . ']'. $term . '[/url]'), - intval($r[0]['id']) - ); - } - - } - - - $arr['id'] = $post_id; - - call_hooks('post_local_end', $arr); + $arr['parent_mid'] = $item['mid']; + + store_item_tag($item['uid'],$item['id'],TERM_OBJ_POST,TERM_HASHTAG,$term,$tagid); + $ret = post_activity_item($arr); - proc_run('php',"include/notifier.php","tag","$post_id"); + if($ret['success']) + proc_run('php','include/notifier.php','tag',$ret['activity']['id']); killme(); - return; // NOTREACHED - - }
\ No newline at end of file diff --git a/mod/thing.php b/mod/thing.php new file mode 100644 index 000000000..cbf83fdf8 --- /dev/null +++ b/mod/thing.php @@ -0,0 +1,332 @@ +<?php /** @file */ + +require_once('include/items.php'); +require_once('include/contact_selectors.php'); + + +function thing_init(&$a) { + + if(! local_user()) + return; + + + + + $account_id = $a->get_account(); + $channel = $a->get_channel(); + + $term_hash = (($_REQUEST['term_hash']) ? $_REQUEST['term_hash'] : ''); + + $name = escape_tags($_REQUEST['term']); + $verb = escape_tags($_REQUEST['verb']); + $activity = intval($_REQUEST['activity']); + $profile_guid = escape_tags($_REQUEST['profile_assign']); + $url = $_REQUEST['link']; + $photo = $_REQUEST['img']; + + $hash = random_string(); + + + $verbs = obj_verbs(); + + /** + * verbs: [0] = first person singular, e.g. "I want", [1] = 3rd person singular, e.g. "Bill wants" + * We use the first person form when creating an activity, but the third person for use in activities + * FIXME: There is no accounting for verb gender for languages where this is significant. We may eventually + * require obj_verbs() to provide full conjugations and specify which form to use in the $_REQUEST params to this module. + */ + + $translated_verb = $verbs[$verb][1]; + + /** + * The site administrator can do things that normals cannot. + * This is restricted because it will likely cause + * an activitystreams protocol violation and the activity might + * choke in some other network and result in unnecessary + * support requests. It isn't because we're trying to be heavy-handed + * about what you can and can't do. + */ + + if(! $translated_verb) { + if(is_site_admin()) + $translated_verb = $verb; + } + + /** + * Things, objects: We do not provide definite (a, an) or indefinite (the) articles or singular/plural designators + * That needs to be specified in your thing. e.g. Mike has "a carrot", Greg wants "balls", Bob likes "the Boston Red Sox". + */ + + /** + * Future work on this module might produce more complex activities with targets, e.g. Phillip likes Karen's moustache + * and to describe other non-thing objects like channels, such as Karl wants Susan - where Susan represents a channel profile. + */ + + if((! $name) || (! $translated_verb)) + return; + + + + + + 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) + ); + 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); + $local_photo = $arr[0]; + $local_photo_type = $arr[3]; + } + else + $local_photo = $orig_record['imgurl']; + + $r = q("update term set term = '%s', url = '%s', imgurl = '%s' where term_hash = '%s' and uid = %d limit 1", + dbesc($name), + dbesc(($url) ? $url : z_root() . '/thing/' . $term_hash), + dbesc($local_photo), + dbesc($term_hash), + intval(local_user()) + ); + + info( t('Thing updated') . EOL); + return; + } + + $sql = (($profile_guid) ? " and profile_guid = '" . dbesc($profile_guid) . "' " : " and is_default = 1 "); + $p = q("select profile_guid, is_default from profile where uid = %d $sql limit 1", + intval(local_user()) + ); + + if($p) + $profile = $p[0]; + else + return; + + $local_photo = null; + + if($photo) { + $arr = import_profile_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_user()), + 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_user()), + 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_user()), + intval(TERM_OBJ_THING), + intval(TERM_THING), + dbesc($name) + ); + } + $term = $r[0]; + + $r = q("insert into obj ( obj_page, obj_verb, obj_type, obj_channel, obj_obj) values ('%s','%s', %d, %d, '%s') ", + dbesc($profile['profile_guid']), + dbesc($verb), + intval(TERM_OBJ_THING), + intval(local_user()), + dbesc($term['term_hash']) + ); + + if(! $r) { + notice( t('Object store: failed')); + return; + } + + info( t('Thing added')); + + + if($activity) { + $arr = array(); + $links = array(array('rel' => 'alternate','type' => 'text/html', 'href' => $term['url'])); + if($local_photo) + $links[] = array('rel' => 'photo', 'type' => $local_photo_type, 'href' => $local_photo); + + + $objtype = ACTIVITY_OBJ_THING; + + $obj = json_encode(array( + 'type' => $objtype, + 'id' => $term['url'], + 'link' => $links, + 'title' => $term['term'], + 'content' => $term['term'] + )); + + $bodyverb = str_replace('OBJ: ', '',t('OBJ: %1$s %2$s %3$s')); + + $arr['owner_xchan'] = $channel['channel_hash']; + $arr['author_xchan'] = $channel['channel_hash']; + + + $arr['item_flags'] = ITEM_ORIGIN|ITEM_WALL|ITEM_THREAD_TOP; + + $ulink = '[zrl=' . $channel['xchan_url'] . ']' . $channel['channel_name'] . '[/zrl]'; + $plink = '[zrl=' . $term['url'] . ']' . $term['term'] . '[/zrl]'; + + $arr['body'] = sprintf( $bodyverb, $ulink, $translated_verb, $plink ); + + if($local_photo) + $arr['body'] .= "\n\n[zmg]" . $local_photo . "[/zmg]"; + + $arr['verb'] = $verb; + $arr['obj_type'] = $objtype; + $arr['object'] = $obj; + + if(! $profile['is_default']) { + $arr['item_private'] = true; + $str = ''; + $r = q("select abook_xchan from abook where abook_channel = %d and abook_profile = '%s'", + intval(local_user()), + dbesc($profile_guid) + ); + if($r) { + $arr['allow_cid'] = ''; + foreach($r as $rr) + $arr['allow_cid'] .= '<' . $rr['abook_xchan'] . '>'; + } + else + $arr['allow_cid'] = '<' . get_observer_hash() . '>'; + } + + $ret = post_activity_item($arr); + } +} + + +function thing_content(&$a) { + + 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", + intval(TERM_OBJ_THING), + dbesc(argv(1)) + ); + + if($r) { + return replace_macros(get_markup_template('show_thing.tpl'), array( + '$header' => t('Show Thing'), + '$edit' => t('Edit'), + '$delete' => t('Delete'), + '$canedit' => ((local_user() && local_user() == $r[0]['obj_channel']) ? true : false), + '$thing' => $r[0] )); + } + else { + notice( t('item not found.') . EOL); + return; + } + } + + if(! local_user()) { + notice( t('Permission denied.') . EOL); + return; + } + + $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", + intval(TERM_OBJ_THING), + dbesc($thing_hash) + ); + + if((! $r) || ($r[0]['obj_channel'] != local_user())) { + notice( t('Permission denied.') . EOL); + return ''; + } + + + $o .= replace_macros(get_markup_template('thing_edit.tpl'),array( + '$thing_hdr' => t('Edit Thing'), + '$multiprof' => feature_enabled(local_user(),'multi_profiles'), + '$profile_lbl' => t('Select a profile'), + '$profile_select' => contact_profile_assign($r[0]['obj_page']), + '$verb_lbl' => t('Select a category of stuff. e.g. I ______ something'), + '$verb_select' => obj_verb_selector($r[0]['obj_verb']), + '$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'], + '$url_lbl' => t('URL of thing (optional)'), + '$theurl' => $r[0]['url'], + '$img_lbl' => t('URL for photo of thing (optional)'), + '$imgurl' => $r[0]['imgurl'], + '$submit' => t('Submit') + )); + + return $o; + } + + 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", + intval(TERM_OBJ_THING), + dbesc($thing_hash) + ); + + if((! $r) || ($r[0]['obj_channel'] != local_user())) { + notice( t('Permission denied.') . EOL); + return ''; + } + + + $x = q("delete from obj where obj_obj = '%s' and obj_type = %d and obj_channel = %d limit 1", + dbesc($thing_hash), + intval(TERM_OBJ_THING), + intval(local_user()) + ); + $x = q("delete from term where term_hash = '%s' and uid = %d limit 1", + dbesc($thing_hash), + intval(local_user()) + ); + return $o; + } + + $o .= replace_macros(get_markup_template('thing_input.tpl'),array( + '$thing_hdr' => t('Add Thing to your Profile'), + '$multiprof' => feature_enabled(local_user(),'multi_profiles'), + '$profile_lbl' => t('Select a profile'), + '$profile_select' => contact_profile_assign(''), + '$verb_lbl' => t('Select a category of stuff. e.g. I ______ something'), + '$activity' => array('activity',t('Post an activity'),true,t('Only sends to viewers of the applicable profile')), + '$verb_select' => obj_verb_selector(), + '$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)'), + '$submit' => t('Submit') + )); + + return $o; + + +} diff --git a/mod/toggle_mobile.php b/mod/toggle_mobile.php index 00991e44c..06dadca04 100644 --- a/mod/toggle_mobile.php +++ b/mod/toggle_mobile.php @@ -3,9 +3,9 @@ function toggle_mobile_init(&$a) { if(isset($_GET['off'])) - $_SESSION['show-mobile'] = false; + $_SESSION['show_mobile'] = false; else - $_SESSION['show-mobile'] = true; + $_SESSION['show_mobile'] = true; if(isset($_GET['address'])) $address = $_GET['address']; diff --git a/mod/toggle_safesearch.php b/mod/toggle_safesearch.php new file mode 100644 index 000000000..3c800c4f3 --- /dev/null +++ b/mod/toggle_safesearch.php @@ -0,0 +1,25 @@ +<?php + +function toggle_safesearch_init(&$a) { + +$observer = get_observer_hash(); +if (! $observer) + return; + +if($observer) + $safe_mode = get_xconfig($observer,'directory','safe_mode'); +if ($safe_mode == '') + set_xconfig($observer,'directory','safe_mode', '0'); +elseif($safe_mode == '0') + set_xconfig($observer,'directory','safe_mode', '1'); +elseif($safe_mode == '1') + set_xconfig($observer,'directory','safe_mode', '0'); + +if(isset($_GET['address'])) + $address = $_GET['address']; +else + $address = z_root() . '/directory'; + + goaway($address); +} + diff --git a/mod/update_channel.php b/mod/update_channel.php index 19226297b..bdde0a3be 100644 --- a/mod/update_channel.php +++ b/mod/update_channel.php @@ -39,15 +39,17 @@ function update_channel_content(&$a) { $replace = "<img\${1} dst=\"\${2}\""; $text = preg_replace($pattern, $replace, $text); - $replace = '<br />' . t('[Embedded content - reload page to view]') . '<br />'; - $pattern = "/<\s*audio[^>]*>(.*?)<\s*\/\s*audio>/i"; - $text = preg_replace($pattern, $replace, $text); - $pattern = "/<\s*video[^>]*>(.*?)<\s*\/\s*video>/i"; - $text = preg_replace($pattern, $replace, $text); - $pattern = "/<\s*embed[^>]*>(.*?)<\s*\/\s*embed>/i"; - $text = preg_replace($pattern, $replace, $text); - $pattern = "/<\s*iframe[^>]*>(.*?)<\s*\/\s*iframe>/i"; - $text = preg_replace($pattern, $replace, $text); + if(! $load) { + $replace = '<br />' . t('[Embedded content - reload page to view]') . '<br />'; + $pattern = "/<\s*audio[^>]*>(.*?)<\s*\/\s*audio>/i"; + $text = preg_replace($pattern, $replace, $text); + $pattern = "/<\s*video[^>]*>(.*?)<\s*\/\s*video>/i"; + $text = preg_replace($pattern, $replace, $text); + $pattern = "/<\s*embed[^>]*>(.*?)<\s*\/\s*embed>/i"; + $text = preg_replace($pattern, $replace, $text); + $pattern = "/<\s*iframe[^>]*>(.*?)<\s*\/\s*iframe>/i"; + $text = preg_replace($pattern, $replace, $text); + } /** * reportedly some versions of MSIE don't handle tabs in XMLHttpRequest documents very well diff --git a/mod/update_community.php b/mod/update_community.php deleted file mode 100644 index 3dcbce6b1..000000000 --- a/mod/update_community.php +++ /dev/null @@ -1,33 +0,0 @@ -<?php - -// See update_profile.php for documentation - -require_once('mod/community.php'); - -function update_community_content(&$a) { - - header("Content-type: text/html"); - echo "<!DOCTYPE html><html><body>\r\n"; - echo (($_GET['msie'] == 1) ? '<div>' : '<section>'); - - $text = community_content($a,true); - $pattern = "/<img([^>]*) src=\"([^\"]*)\"/"; - $replace = "<img\${1} dst=\"\${2}\""; - $text = preg_replace($pattern, $replace, $text); - - $replace = '<br />' . t('[Embedded content - reload page to view]') . '<br />'; - $pattern = "/<\s*audio[^>]*>(.*?)<\s*\/\s*audio>/i"; - $text = preg_replace($pattern, $replace, $text); - $pattern = "/<\s*video[^>]*>(.*?)<\s*\/\s*video>/i"; - $text = preg_replace($pattern, $replace, $text); - $pattern = "/<\s*embed[^>]*>(.*?)<\s*\/\s*embed>/i"; - $text = preg_replace($pattern, $replace, $text); - $pattern = "/<\s*iframe[^>]*>(.*?)<\s*\/\s*iframe>/i"; - $text = preg_replace($pattern, $replace, $text); - - echo str_replace("\t",' ',$text); - echo (($_GET['msie'] == 1) ? '</div>' : '</section>'); - echo "</body></html>\r\n"; - killme(); - -}
\ No newline at end of file diff --git a/mod/update_display.php b/mod/update_display.php index c8eb9c3a3..5802852bb 100644 --- a/mod/update_display.php +++ b/mod/update_display.php @@ -16,11 +16,12 @@ function update_display_content(&$a) { echo (($_GET['msie'] == 1) ? '<div>' : '<section>'); - $text = display_content($a,$profile_uid, $load); - $pattern = "/<img([^>]*) src=\"([^\"]*)\"/"; - $replace = "<img\${1} dst=\"\${2}\""; - $text = preg_replace($pattern, $replace, $text); + $text = display_content($a,$profile_uid, $load); + $pattern = "/<img([^>]*) src=\"([^\"]*)\"/"; + $replace = "<img\${1} dst=\"\${2}\""; + $text = preg_replace($pattern, $replace, $text); + if(! $load) { $replace = '<br />' . t('[Embedded content - reload page to view]') . '<br />'; $pattern = "/<\s*audio[^>]*>(.*?)<\s*\/\s*audio>/i"; $text = preg_replace($pattern, $replace, $text); @@ -30,9 +31,9 @@ function update_display_content(&$a) { $text = preg_replace($pattern, $replace, $text); $pattern = "/<\s*iframe[^>]*>(.*?)<\s*\/\s*iframe>/i"; $text = preg_replace($pattern, $replace, $text); + } - - echo str_replace("\t",' ',$text); + echo str_replace("\t",' ',$text); echo (($_GET['msie'] == 1) ? '</div>' : '</section>'); echo "</body></html>\r\n"; // logger('update_display: ' . $text); diff --git a/mod/update_network.php b/mod/update_network.php index 16de19365..0021af876 100644 --- a/mod/update_network.php +++ b/mod/update_network.php @@ -11,7 +11,7 @@ function update_network_content(&$a) { $load = (((argc() > 1) && (argv(1) == 'load')) ? 1 : 0); header("Content-type: text/html"); echo "<!DOCTYPE html><html><body>\r\n"; - echo (($_GET['msie'] == 1) ? '<div>' : '<section>'); + echo ((array_key_exists('msie',$_GET) && $_GET['msie'] == 1) ? '<div>' : '<section>'); $text = network_content($a,$profile_uid, $load); @@ -19,19 +19,20 @@ function update_network_content(&$a) { $replace = "<img\${1} dst=\"\${2}\""; $text = preg_replace($pattern, $replace, $text); - $replace = '<br />' . t('[Embedded content - reload page to view]') . '<br />'; - $pattern = "/<\s*audio[^>]*>(.*?)<\s*\/\s*audio>/i"; - $text = preg_replace($pattern, $replace, $text); - $pattern = "/<\s*video[^>]*>(.*?)<\s*\/\s*video>/i"; - $text = preg_replace($pattern, $replace, $text); - $pattern = "/<\s*embed[^>]*>(.*?)<\s*\/\s*embed>/i"; - $text = preg_replace($pattern, $replace, $text); - $pattern = "/<\s*iframe[^>]*>(.*?)<\s*\/\s*iframe>/i"; - $text = preg_replace($pattern, $replace, $text); - + if(! $load) { + $replace = '<br />' . t('[Embedded content - reload page to view]') . '<br />'; + $pattern = "/<\s*audio[^>]*>(.*?)<\s*\/\s*audio>/i"; + $text = preg_replace($pattern, $replace, $text); + $pattern = "/<\s*video[^>]*>(.*?)<\s*\/\s*video>/i"; + $text = preg_replace($pattern, $replace, $text); + $pattern = "/<\s*embed[^>]*>(.*?)<\s*\/\s*embed>/i"; + $text = preg_replace($pattern, $replace, $text); + $pattern = "/<\s*iframe[^>]*>(.*?)<\s*\/\s*iframe>/i"; + $text = preg_replace($pattern, $replace, $text); + } echo str_replace("\t",' ',$text); - echo (($_GET['msie'] == 1) ? '</div>' : '</section>'); + echo ((array_key_exists('msie',$_GET) && $_GET['msie'] == 1) ? '</div>' : '</section>'); echo "</body></html>\r\n"; // logger('update_network: ' . $text); killme(); diff --git a/mod/update_search.php b/mod/update_search.php new file mode 100644 index 000000000..ec7599b79 --- /dev/null +++ b/mod/update_search.php @@ -0,0 +1,66 @@ +<?php + +/** + * Module: update_profile + * Purpose: AJAX synchronisation of search page + * + */ + + +require_once('mod/search.php'); + +function update_search_content(&$a) { + + $profile_uid = intval($_GET['p']); + if(! $profile_uid) + $profile_uid = (-1); + + $load = (((argc() > 1) && (argv(1) == 'load')) ? 1 : 0); + + header("Content-type: text/html"); + echo "<!DOCTYPE html><html><body>\r\n"; + + /** + * We can remove this hack once Internet Explorer recognises HTML5 natively + */ + + echo (($_GET['msie'] == 1) ? '<div>' : '<section>'); + + /** + * + * Grab the page inner contents by calling the content function from the profile module directly, + * but move any image src attributes to another attribute name. This is because + * some browsers will prefetch all the images for the page even if we don't need them. + * The only ones we need to fetch are those for new page additions, which we'll discover + * on the client side and then swap the image back. + * + */ + + $text = search_content($a,$profile_uid,$load); + + $pattern = "/<img([^>]*) src=\"([^\"]*)\"/"; + $replace = "<img\${1} dst=\"\${2}\""; + $text = preg_replace($pattern, $replace, $text); + + if(! $load) { + $replace = '<br />' . t('[Embedded content - reload page to view]') . '<br />'; + $pattern = "/<\s*audio[^>]*>(.*?)<\s*\/\s*audio>/i"; + $text = preg_replace($pattern, $replace, $text); + $pattern = "/<\s*video[^>]*>(.*?)<\s*\/\s*video>/i"; + $text = preg_replace($pattern, $replace, $text); + $pattern = "/<\s*embed[^>]*>(.*?)<\s*\/\s*embed>/i"; + $text = preg_replace($pattern, $replace, $text); + $pattern = "/<\s*iframe[^>]*>(.*?)<\s*\/\s*iframe>/i"; + $text = preg_replace($pattern, $replace, $text); + } + + /** + * reportedly some versions of MSIE don't handle tabs in XMLHttpRequest documents very well + */ + + echo str_replace("\t",' ',$text); + echo (($_GET['msie'] == 1) ? '</div>' : '</section>'); + echo "</body></html>\r\n"; + killme(); + +}
\ No newline at end of file diff --git a/mod/view.php b/mod/view.php index 9e5eff962..d4381743c 100644 --- a/mod/view.php +++ b/mod/view.php @@ -1,6 +1,6 @@ <?php /** - * load view/theme/$current_theme/style.php with friendica contex + * load view/theme/$current_theme/style.php with Red context */ function view_init($a){ diff --git a/mod/viewconnections.php b/mod/viewconnections.php index e6c739562..b6a6b483c 100644 --- a/mod/viewconnections.php +++ b/mod/viewconnections.php @@ -11,17 +11,6 @@ function viewconnections_init(&$a) { profile_load($a,argv(1)); } - -function viewconnections_aside(&$a) { - - if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { - return; - } - - profile_create_sidebar($a); -} - - function viewconnections_content(&$a) { if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) { @@ -39,16 +28,28 @@ function viewconnections_content(&$a) { return; } + $is_owner = ((local_user() && local_user() == $a->profile['uid']) ? true : false); + $abook_flags = ABOOK_FLAG_PENDING|ABOOK_FLAG_SELF; + $xchan_flags = XCHAN_FLAGS_ORPHAN|XCHAN_FLAGS_DELETED; + if(! $is_owner) { + $abook_flags = $abook_flags | ABOOK_FLAGS_HIDDEN; + $xchan_flags = $xchan_flags | XCHAN_FLAGS_HIDDEN; + } - $r = q("SELECT COUNT(abook_id) as total FROM abook WHERE abook_channel = %d AND abook_flags = 0 ", - intval($a->profile['uid']) + $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 ) and not ( xchan_flags & %d ) ", + intval($a->profile['uid']), + intval($abook_flags), + intval($xchan_flags) ); - if($r) + 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 abook_flags = 0 order by xchan_name LIMIT %d , %d ", + $r = q("SELECT * FROM abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d and not ( abook_flags & %d ) and not ( xchan_flags & %d ) order by xchan_name LIMIT %d , %d ", intval($a->profile['uid']), + intval($abook_flags), + intval($xchan_flags), intval($a->pager['start']), intval($a->pager['itemspage']) ); @@ -62,19 +63,20 @@ function viewconnections_content(&$a) { foreach($r as $rr) { - $url = zid($rr['xchan_url']); - - $contacts[] = array( - 'id' => $rr['abook_id'], - '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), - 'username' => $rr['xchan_addr'], - 'url' => $url, - 'sparkle' => '', - 'itemurl' => $rr['url'], - 'network' => '', - ); + $url = chanlink_url($rr['xchan_url']); + if($url) { + $contacts[] = array( + 'id' => $rr['abook_id'], + '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), + 'username' => $rr['xchan_addr'], + 'link' => $url, + 'sparkle' => '', + 'itemurl' => $rr['url'], + 'network' => '', + ); + } } diff --git a/mod/wall_attach.php b/mod/wall_attach.php index 6e9443f12..47c097416 100644 --- a/mod/wall_attach.php +++ b/mod/wall_attach.php @@ -1,23 +1,12 @@ <?php require_once('include/attach.php'); -require_once('include/datetime.php'); +require_once('include/identity.php'); function wall_attach_post(&$a) { - // Figure out who owns the page and if they allow attachments - - if(argc() > 1) { - $nick = argv(1); - $r = q("SELECT channel.* from channel where channel_address = '%s' limit 1", - dbesc($nick) - ); - if(! $r) - killme(); - $channel = $r[0]; - - } - + if(argc() > 1) + $channel = get_channel_by_nick(argv(1)); else killme(); diff --git a/mod/wall_upload.php b/mod/wall_upload.php index cee40744f..f83f4f7cf 100644 --- a/mod/wall_upload.php +++ b/mod/wall_upload.php @@ -1,6 +1,7 @@ <?php -require_once('Photo.php'); +require_once('include/photo/photo_driver.php'); +require_once('include/identity.php'); require_once('include/photos.php'); @@ -19,15 +20,7 @@ function wall_upload_post(&$a) { $nick = argv(1); } - $channel = null; - - if($nick) { - $r = q("SELECT channel.* from channel where channel_address = '%s' limit 1", - dbesc($nick) - ); - if($r) - $channel = $r[0]; - } + $channel = (($nick) ? get_channel_by_nick($nick) : false); if(! $channel) { if($using_api) @@ -52,8 +45,10 @@ function wall_upload_post(&$a) { $m = $ret['body']; + + if($using_api) - return($ret['body']); + return("\n\n" . $ret['body'] . "\n\n"); else echo "\n\n" . $ret['body'] . "\n\n"; killme(); diff --git a/mod/webpages.php b/mod/webpages.php new file mode 100644 index 000000000..dea034357 --- /dev/null +++ b/mod/webpages.php @@ -0,0 +1,133 @@ +<?php + +function webpages_content(&$a) { + + if(argc() > 1) + $which = argv(1); + else { + notice( t('Requested profile is not available.') . EOL ); + $a->error = 404; + return; + } + + $profile = 0; + $channel = $a->get_channel(); + + if((local_user()) && (argc() > 2) && (argv(2) === 'view')) { + $which = $channel['channel_address']; + $profile = argv(1); + } + + profile_load($a,$which,$profile); + + + // Figure out who the page owner is. + $r = q("select channel_id from channel where channel_address = '%s'", + dbesc($which) + ); + if($r) { + $owner = intval($r[0]['channel_id']); + } + + // Get the observer, check their permissions + + $observer = $a->get_observer(); + $ob_hash = (($observer) ? $observer['xchan_hash'] : ''); + + $perms = get_all_perms($owner,$ob_hash); + + if(! $perms['write_pages']) { + notice( t('Permission denied.') . EOL); + return; + } + +// if(local_user() && local_user() == $owner) { +// $a->set_widget('design',design_tools()); +// } + + + $mimetype = get_config('system','page_mimetype'); + if(! $mimetype) + $mimetype = 'choose'; + + $layout = get_config('system','page_layout'); + if(! $layout) + $layout = 'choose'; + + +// Create a status editor (for now - we'll need a WYSIWYG eventually) to create pages +// Nickname is set to the observers xchan, and profile_uid to the owners. This lets you post pages at other people's channels. + require_once ('include/conversation.php'); + require_once('include/acl_selectors.php'); + + + if(local_user() && local_user() == $a->profile_uid) { + $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'] + ); + } + else + $channel_acl = array(); + + require_once('include/conversation.php'); + $o = profile_tabs($a,true); + + $o .= '<h2>' . t('Webpages') . '</h2>'; + + $x = array( + 'webpage' => ITEM_WEBPAGE, + 'is_owner' => true, + 'nickname' => $a->profile['channel_address'], + 'lockstate' => (($group || $cid || $channel['channel_allow_cid'] || $channel['channel_allow_gid'] || $channel['channel_deny_cid'] || $channel['channel_deny_gid']) ? 'lock' : 'unlock'), + 'bang' => (($group || $cid) ? '!' : ''), + 'acl' => ((local_user() && local_user() == $owner) ? populate_acl($channel_acl) : ''), + 'visitor' => true, + 'profile_uid' => intval($owner), + 'mimetype' => $mimetype, + 'layout' => $layout, + ); + + $o .= status_editor($a,$x); + + + // Get a list of webpages. We can't display all them because endless scroll makes that unusable, so just list titles and an edit link. + //TODO - this should be replaced with pagelist_widget + + $r = q("select * from item_id left join item on item_id.iid = item.id where item_id.uid = %d and service = 'WEBPAGE' order by item.created desc", + intval($owner) + ); + + $pages = null; + + if($r) { + $pages = array(); + foreach($r as $rr) { + $pages[$rr['iid']][] = array('url' => $rr['iid'],'pagetitle' => $rr['sid'],'title' => $rr['title'],'created' => datetime_convert('UTC',date_default_timezone_get(),$rr['created']),'edited' => datetime_convert('UTC',date_default_timezone_get(),$rr['edited'])); + } + } + + +//Build the base URL for edit links + $url = z_root() . "/editwebpage/" . $which; +// This isn't pretty, but it works. Until I figure out what to do with the UI, it's Good Enough(TM). + return $o . replace_macros(get_markup_template("webpagelist.tpl"), array( + '$baseurl' => $url, + '$edit' => t('Edit'), + '$pages' => $pages, + '$channel' => $which, + '$view' => t('View'), + '$preview' => t('Preview'), + '$actions_txt' => t('Actions'), + '$pagelink_txt' => t('Page Link'), + '$title_txt' => t('Title'), + '$created_txt' => t('Created'), + '$edited_txt' => t('Edited') + +)); + + +} diff --git a/mod/wfinger.php b/mod/wfinger.php new file mode 100644 index 000000000..bdec92b54 --- /dev/null +++ b/mod/wfinger.php @@ -0,0 +1,111 @@ +<?php + +function wfinger_init(&$a) { + + $result = array(); + + $scheme = ''; + + if(x($_SERVER,'HTTPS') && $_SERVER['HTTPS']) + $scheme = 'https'; + elseif(x($_SERVER,'SERVER_PORT') && (intval($_SERVER['SERVER_PORT']) == 443)) + $scheme = 'https'; + + // Don't complain to me - I'm just implementing the spec. + + if($scheme !== 'https') { + header($_SERVER["SERVER_PROTOCOL"] . ' ' . 500 . ' ' . 'Webfinger requires HTTPS'); + killme(); + } + + $resource = $_REQUEST['resource']; + + + $r = null; + + if($resource) { + + if(strpos($resource,'acct:') === 0) { + $channel = str_replace('acct:','',$resource); + 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); + } + $channel = substr($channel,0,strpos($channel,'@')); + } + } + if(strpos($resource,'http') === 0) { + $channel = str_replace('~','',basename($resource)); + } + + $r = q("select * from channel left join xchan on channel_hash = xchan_hash + where channel_address = '%s' limit 1", + dbesc($channel) + ); + + } + + + header('Access-Control-Allow-Origin: *'); + + header('Content-type: application/jrd+json'); + + + + if($resource && $r) { + + $result['subject'] = $resource; + + $aliases = array( + 'acct:' . $r[0]['channel_address'] . '@' . $a->get_hostname(), + z_root() . '/channel/' . $r[0]['channel_address'], + z_root() . '/~' . $r[0]['channel_address'] + ); + + $result['aliases'] = array(); + + $result['properties'] = array('http://webfinger.example/ns/name' => $r[0]['channel_name']); + + foreach($aliases as $alias) + if($alias != $resource) + $result['aliases'][] = $alias; + + + $result['links'] = array( + + array( + 'rel' => 'http://webfinger.example/rel/avatar', + 'type' => $r[0]['xchan_photo_mimetype'], + 'href' => $r[0]['xchan_photo_l'] + ), + + array( + 'rel' => 'http://webfinger.example/rel/profile-page', + 'href' => z_root() . '/profile/' . $r[0]['channel_address'], + ), + + array( + 'rel' => 'http://webfinger.example/rel/blog', + 'href' => z_root() . '/channel/' . $r[0]['channel_address'], + ), + + array( + 'rel' => 'http://purl.org/zot/protocol', + 'href' => z_root() . '/.well-known/zot-info' . '?address=' . $r[0]['xchan_addr'], + ) + ); + + } + else { + header($_SERVER["SERVER_PROTOCOL"] . ' ' . 400 . ' ' . 'Bad Request'); + killme(); + } + + $arr = array('channel' => $r[0], 'request' => $_REQUEST, 'result' => $result); + call_hooks('webfinger',$arr); + + echo json_encode($arr['result']); + killme(); + +}
\ No newline at end of file diff --git a/mod/xchan.php b/mod/xchan.php index 984a62f95..9d4cdcc22 100644 --- a/mod/xchan.php +++ b/mod/xchan.php @@ -14,9 +14,11 @@ function xchan_content(&$a) { if(x($_GET,'addr')) { $addr = trim($_GET['addr']); + $r = q("select xchan_name from xchan where xchan_hash like '%s%%'", - dbesc(addr) + dbesc($addr) ); + if($r) { foreach($r as $rr) $o .= $rr['xchan_name'] . EOL; diff --git a/mod/xrd.php b/mod/xrd.php index a576f76c4..4d6a530e4 100644 --- a/mod/xrd.php +++ b/mod/xrd.php @@ -16,35 +16,34 @@ function xrd_init(&$a) { $name = substr($local,0,strpos($local,'@')); } - $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' LIMIT 1", + $r = q("SELECT * FROM channel WHERE channel_address = '%s' LIMIT 1", dbesc($name) ); - if(! count($r)) + if(! $r) killme(); - $salmon_key = salmon_key($r[0]['pubkey']); +// $salmon_key = salmon_key($r[0]['pubkey']); header('Access-Control-Allow-Origin: *'); header("Content-type: text/xml"); - $dspr = ''; $tpl = get_markup_template('view/xrd_person.tpl'); - $o = replace_macros($tpl, array( - '$nick' => $r[0]['nickname'], + $o = replace_macros(get_markup_template('xrd_person.tpl'), array( + '$nick' => $r[0]['channel_address'], '$accturi' => $uri, - '$profile_url' => $a->get_baseurl() . '/channel/' . $r[0]['nickname'], - '$hcard_url' => $a->get_baseurl() . '/hcard/' . $r[0]['nickname'], - '$atom' => $a->get_baseurl() . '/dfrn_poll/' . $r[0]['nickname'], - '$zot_post' => $a->get_baseurl() . '/post/' . $r[0]['nickname'], - '$poco_url' => $a->get_baseurl() . '/poco/' . $r[0]['nickname'], - '$photo' => $a->get_baseurl() . '/photo/profile/' . $r[0]['uid'], - '$dspr' => $dspr, - '$salmon' => $a->get_baseurl() . '/salmon/' . $r[0]['nickname'], - '$salmen' => $a->get_baseurl() . '/salmon/' . $r[0]['nickname'] . '/mention', - '$modexp' => 'data:application/magic-public-key,' . $salmon_key, - '$bigkey' => salmon_key($r[0]['pubkey']) + '$profile_url' => $a->get_baseurl() . '/channel/' . $r[0]['channel_address'], +// '$hcard_url' => $a->get_baseurl() . '/hcard/' . $r[0]['channel_address'], + '$atom' => $a->get_baseurl() . '/feed/' . $r[0]['channel_address'], + '$zot_post' => $a->get_baseurl() . '/post/' . $r[0]['channel_address'], + '$poco_url' => $a->get_baseurl() . '/poco/' . $r[0]['channel_address'], + '$photo' => $a->get_baseurl() . '/photo/profile/l/' . $r[0]['channel_id'], +// '$dspr' => $dspr, +// '$salmon' => $a->get_baseurl() . '/salmon/' . $r[0]['channel_address'], +// '$salmen' => $a->get_baseurl() . '/salmon/' . $r[0]['channel_address'] . '/mention', +// '$modexp' => 'data:application/magic-public-key,' . $salmon_key, +// '$bigkey' => salmon_key($r[0]['pubkey']) )); diff --git a/mod/xref.php b/mod/xref.php new file mode 100644 index 000000000..95cc22aa7 --- /dev/null +++ b/mod/xref.php @@ -0,0 +1,20 @@ +<?php + +function xref_init(&$a) { + // Sets a referral URL using an xchan directly + // Link format: example.com/xref/[xchan]/[TargetURL] + // Target URL is optional. + // Cookie lasts 24 hours to survive a browser restart. Contains no personal + // information at all - just somebody else's xchan. + $referrer = argv(1); + $expire=time()+60*60*2; + $path = 'xref'; + setcookie($path, $referrer, $expire, "/"); + $url = ''; + + if (argc() > 2) + $url = argv(2); + + goaway (z_root() . '/' . $url); + +} diff --git a/mod/zfinger.php b/mod/zfinger.php index 74353e8f9..dcc755992 100644 --- a/mod/zfinger.php +++ b/mod/zfinger.php @@ -52,10 +52,33 @@ function zfinger_init(&$a) { ); } elseif(strlen($zaddr)) { - $r = q("select channel.*, xchan.* from channel left join xchan on channel_hash = xchan_hash - where channel_address = '%s' limit 1", - dbesc($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 ) or not ( channel_pageflags & %d )) order by channel_id limit 1", + intval(PAGE_SYSTEM), + intval(PAGE_REMOVED) + ); + } } else { $ret['message'] = 'Invalid request'; @@ -71,8 +94,12 @@ function zfinger_init(&$a) { $id = $e['channel_id']; - $searchable = (($e['channel_pageflags'] & PAGE_HIDDEN) ? false : true); - if($e['xchan_flags'] & XCHAN_FLAGS_HIDDEN) + $special_channel = (($e['channel_pageflags'] & PAGE_PREMIUM) ? true : false); + $adult_channel = (($e['channel_pageflags'] & PAGE_ADULT) ? true : false); + $searchable = (($e['channel_pageflags'] & PAGE_HIDDEN) ? false : true); + $deleted = (($e['xchan_flags'] & XCHAN_FLAGS_DELETED) ? true : false); + + if(($e['xchan_flags'] & XCHAN_FLAGS_HIDDEN) || $deleted) $searchable = false; // This is for birthdays and keywords, but must check access permissions @@ -91,6 +118,9 @@ function zfinger_init(&$a) { $profile['birthday'] = $p[0]['dob']; if($profile['birthday'] != '0000-00-00') $profile['next_birthday'] = z_birthday($p[0]['dob'],$e['channel_timezone']); + + 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']; @@ -98,13 +128,20 @@ function zfinger_init(&$a) { $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)) - $tags[] = trim($kk); + 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; } @@ -125,16 +162,38 @@ function zfinger_init(&$a) { $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['name_updated'] = $e['xchan_name_date']; $ret['target'] = $ztarget; $ret['target_sig'] = $zsig; $ret['searchable'] = $searchable; + $ret['adult_content'] = $adult_channel; + 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 - $permissions = get_all_perms($e['channel_id'],(($ztarget && $zsig) + $ret['follow_url'] = z_root() . '/follow?f=&url=%s'; + + $ztarget_hash = (($ztarget && $zsig) ? base64url_encode(hash('whirlpool',$ztarget . $zsig,true)) - : '' ),false); + : '' ); + $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) ? aes_encapsulate(json_encode($permissions),$zkey) : $permissions); @@ -145,7 +204,8 @@ function zfinger_init(&$a) { // array of (verified) hubs this channel uses $ret['locations'] = array(); - $x = zot_get_hubloc(array($e['channel_hash'])); + + $x = zot_get_hublocs($e['channel_hash']); if($x && count($x)) { foreach($x as $hub) { if(! ($hub['hubloc_flags'] & HUBLOC_FLAGS_UNVERIFIED)) { @@ -156,7 +216,8 @@ function zfinger_init(&$a) { 'url' => $hub['hubloc_url'], 'url_sig' => $hub['hubloc_url_sig'], 'callback' => $hub['hubloc_callback'], - 'sitekey' => $hub['hubloc_sitekey'] + 'sitekey' => $hub['hubloc_sitekey'], + 'deleted' => (($hub['hubloc_flags'] & HUBLOC_FLAGS_DELETED) ? true : false) ); } } @@ -164,6 +225,8 @@ function zfinger_init(&$a) { $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'; @@ -175,7 +238,61 @@ function zfinger_init(&$a) { $ret['site']['directory_mode'] = 'standalone'; if($dirmode != DIRECTORY_MODE_NORMAL) $ret['site']['directory_url'] = z_root() . '/dirsearch'; - + + + // hide detailed site information if you're off the grid + + if($dirmode != DIRECTORY_MODE_STANDALONE) { + + $register_policy = intval(get_config('system','register_policy')); + + + if($register_policy == REGISTER_CLOSED) + $ret['site']['register_policy'] = 'closed'; + if($register_policy == REGISTER_APPROVE) + $ret['site']['register_policy'] = 'approve'; + if($register_policy == REGISTER_OPEN) + $ret['site']['register_policy'] = 'open'; + + + $access_policy = intval(get_config('system','access_policy')); + + if($access_policy == ACCESS_PRIVATE) + $ret['site']['access_policy'] = 'private'; + if($access_policy == ACCESS_PAID) + $ret['site']['access_policy'] = 'paid'; + if($access_policy == ACCESS_FREE) + $ret['site']['access_policy'] = 'free'; + if($access_policy == ACCESS_TIERED) + $ret['site']['access_policy'] = 'tiered'; + + require_once('include/account.php'); + $ret['site']['accounts'] = account_total(); + + require_once('include/identity.php'); + $ret['site']['channels'] = channel_total(); + + + $ret['site']['version'] = RED_PLATFORM . ' ' . 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'); + + } + call_hooks('zot_finger',$ret); json_return_and_die($ret); -}
\ No newline at end of file +} diff --git a/mod/zotfeed.php b/mod/zotfeed.php index 76a860139..480e886cd 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 = '0000-00-00 00:00:00'; + $mindate = datetime_convert('UTC','UTC', 'now - 1 month'); if(get_config('system','block_public') && (! get_account_id()) && (! remote_user())) { $result['message'] = 'Public access denied'; @@ -21,15 +21,23 @@ function zotfeed_init(&$a) { $channel_address = ((argc() > 1) ? argv(1) : ''); if($channel_address) { - $r = q("select channel_id from channel where channel_address = '%s' limit 1", - dbesc(argv(1)) + $r = q("select channel_id, channel_name from channel where channel_address = '%s' and not (channel_pageflags & %d) limit 1", + dbesc(argv(1)), + intval(PAGE_REMOVED) ); } + else { + $x = get_sys_channel(); + if($x) + $r = array($x); + } if(! $r) { $result['message'] = 'Channel not found.'; json_return_and_die($result); } + logger('zotfeed request: ' . $r[0]['channel_name'], LOGGER_DEBUG); + $result['messages'] = zot_feed($r[0]['channel_id'],$observer['xchan_hash'],$mindate); $result['success'] = true; json_return_and_die($result); diff --git a/mod/zperms.php b/mod/zperms.php deleted file mode 100644 index 6a7097cd6..000000000 --- a/mod/zperms.php +++ /dev/null @@ -1,84 +0,0 @@ -<?php - -function zperms_init(&$a) { - - require_once('include/zot.php'); - require_once('include/Contact.php'); - require_once('include/crypto.php'); - - $ret = array('success' => false); - - $zguid = ((x($_REQUEST,'guid')) ? $_REQUEST['guid'] : ''); - $zaddr = ((x($_REQUEST,'address')) ? $_REQUEST['address'] : ''); - $ztarget = ((x($_REQUEST,'target')) ? $_REQUEST['target'] : ''); - $zsig = ((x($_REQUEST,'target_sig')) ? $_REQUEST['target_sig'] : ''); - - $r = null; - - if(strlen($zguid)) { - $r = q("select * from channel where channel_guid = '%s' limit 1", - dbesc($zguid) - ); - } - elseif(strlen($zaddr)) { - $r = q("select * from channel where channel_address = '%s' limit 1", - dbesc($zaddr) - ); - } - else { - $ret['message'] = 'Invalid request'; - json_return_and_die($ret); - } - - if(! ($r && count($r))) { - $ret['message'] = 'Item not found.'; - json_return_and_die($ret); - } - $e = $r[0]; - - $id = $e['channel_id']; - $r = q("select contact.*, profile.* - from contact left join profile on contact.uid = profile.uid - where contact.uid = %d && contact.self = 1 and profile.is_default = 1 limit 1", - intval($id) - ); - if($r && count($r)) { - $profile = $r[0]; - } - - - - $ret['success'] = true; - $ret['guid'] = $e['channel_guid']; - $ret['guid_sig'] = base64url_encode(rsa_sign($e['channel_guid'],$e['channel_prvkey'])); - $ret['key'] = $e['channel_pubkey']; - $ret['name'] = $e['channel_name']; - $ret['address'] = $e['channel_address']; - $ret['target'] = $ztarget; - $ret['target_sig'] = $zsig; - $ret['permissions'] = map_perms($r[0],$ztarget,$zsig); - - $ret['profile'] = $profile; - - // array of (verified) hubs this channel uses - - $ret['hubs'] = array(); - $x = zot_get_hubloc(array($e['channel_guid'])); - if($x && count($x)) { - foreach($x as $hub) { - if(! ($hub['hubloc_flags'] & HUBLOC_FLAGS_UNVERIFIED)) { - $ret['hubs'][] = array( - 'primary' => (($hub['hubloc_flags'] & HUBLOC_FLAGS_PRIMARY) ? true : false), - 'url' => $hub['hubloc_url'], - /// hmmm we probably shouldn't sign somebody else's hub. FIXME - 'url_sig' => base64url_encode(rsa_sign($hub['hubloc_url'],$e['channel_prvkey'])), - 'callback' => $hub['hubloc_callback'], - 'sitekey' => $hub['hubloc_sitekey'] - ); - } - } - } - - json_return_and_die($ret); - -} diff --git a/mod/zping.php b/mod/zping.php new file mode 100644 index 000000000..76f4470c1 --- /dev/null +++ b/mod/zping.php @@ -0,0 +1,28 @@ +<?php /** @file */ + +require_once('include/zot.php'); + +function zping_content(&$a) { + + // This is just a test utility function and may go away once we build these tools into + // the address book and directory to do dead site discovery. + + // The response packet include the current URL and key so we can discover if the server + // has been re-installed and clean up (e.g. get rid of) any old hublocs and xchans. + + // Remember to add '/post' to the url + + if(! local_user()) + return; + + $url = $_REQUEST['url']; + + if(! $url) + return; + + + $m = zot_build_packet($a->get_channel(),'ping'); + $r = zot_zot($url,$m); + return print_r($r,true); + +}
\ No newline at end of file |