From c65ea0b97b2dc6fcefa0d2da489f32bdd7d05b65 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 5 Sep 2013 22:00:06 -0700 Subject: [PATCH] public site list (will take a few days to populate, assuming folks have updated their site access policy which old sites do not have) --- boot.php | 2 +- include/zot.php | 19 ++++++++++++++++--- install/database.sql | 2 ++ install/update.php | 11 ++++++++++- mod/dirsearch.php | 36 ++++++++++++++++++++++++++++++++++++ mod/pubsites.php | 37 +++++++++++++++++++++++++++++++++++++ 6 files changed, 102 insertions(+), 5 deletions(-) create mode 100644 mod/pubsites.php diff --git a/boot.php b/boot.php index 9bf586caf..483e98bba 100755 --- a/boot.php +++ b/boot.php @@ -43,7 +43,7 @@ require_once('include/taxonomy.php'); define ( 'RED_PLATFORM', 'Red Matrix' ); define ( 'RED_VERSION', trim(file_get_contents('version.inc')) . 'R'); define ( 'ZOT_REVISION', 1 ); -define ( 'DB_UPDATE_VERSION', 1066 ); +define ( 'DB_UPDATE_VERSION', 1067 ); define ( 'EOL', '
' . "\r\n" ); define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' ); diff --git a/include/zot.php b/include/zot.php index 49f58c3bd..33522b485 100644 --- a/include/zot.php +++ b/include/zot.php @@ -1523,10 +1523,22 @@ function import_site($arr,$pubkey) { if($arr['register_policy'] == 'approve') $register_policy = REGISTER_APPROVE; + $access_policy = 0; + if(array_key_exists('access_policy',$arr)) { + if($arr['access_policy'] === 'private') + $access_policy = ACCESS_PRIVATE; + if($arr['access_policy'] === 'paid') + $access_policy = ACCESS_PAID; + if($arr['access_policy'] === 'free') + $access_policy = ACCESS_FREE; + } + + if($update) { - $r = q("update site set site_flags = %d, site_directory = '%s', site_register = %d, site_update = '%s' + $r = q("update site set site_flags = %d, site_access = %d, site_directory = '%s', site_register = %d, site_update = '%s' where site_url = '%s' limit 1", intval($site_directory), + intval($access_policy), dbesc(htmlentities($arr['directory_url'],ENT_COMPAT,'UTF-8',false)), intval($register_policy), dbesc(datetime_convert()), @@ -1537,10 +1549,11 @@ function import_site($arr,$pubkey) { } } else { - $r = q("insert into site ( site_url, site_flags, site_update, site_directory, site_register ) - values ( '%s', %d, '%s', '%s', %d )", + $r = q("insert into site ( site_url, site_acccess, site_flags, site_update, site_directory, site_register ) + values ( '%s', %d, %d, '%s', '%s', %d )", dbesc(htmlentities($arr['url'],ENT_COMPAT,'UTF-8',false)), intval($site_directory), + intval($access_policy), dbesc(datetime_convert()), dbesc(htmlentities($arr['directory_url'],ENT_COMPAT,'UTF-8',false)), intval($register_policy) diff --git a/install/database.sql b/install/database.sql index 176b3610f..ce46149c4 100644 --- a/install/database.sql +++ b/install/database.sql @@ -818,11 +818,13 @@ CREATE TABLE IF NOT EXISTS `shares` ( CREATE TABLE IF NOT EXISTS `site` ( `site_url` char(255) NOT NULL, + `site_access` int(11) NOT NULL DEFAULT '0', `site_flags` int(11) NOT NULL DEFAULT '0', `site_update` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `site_directory` char(255) NOT NULL DEFAULT '', `site_register` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`site_url`), + KEY `site_access` (`site_access`), KEY `site_flags` (`site_flags`), KEY `site_update` (`site_update`), KEY `site_directory` (`site_directory`), diff --git a/install/update.php b/install/update.php index 4f004e651..36a85afec 100644 --- a/install/update.php +++ b/install/update.php @@ -1,6 +1,6 @@ 1 && argv(1) === 'sites') { + $ret = list_public_sites(); + json_return_and_die($ret); + } + + $name = ((x($_REQUEST,'name')) ? $_REQUEST['name'] : ''); $hub = ((x($_REQUEST,'hub')) ? $_REQUEST['hub'] : ''); $address = ((x($_REQUEST,'address')) ? $_REQUEST['address'] : ''); @@ -163,3 +169,33 @@ function dirsearch_content(&$a) { json_return_and_die($ret); } + + +function list_public_sites() { + $r = q("select * from site where site_access != 0 order by rand()"); + $ret = array('success' => false); + + if($r) { + $ret['success'] = true; + $ret['sites'] = array(); + foreach($r as $rr) { + + if($rr['site_access'] == ACCESS_FREE) + $access = 'free'; + elseif($rr['site_access'] == ACCESS_PAID) + $access = 'paid'; + else + $access = 'private'; + + if($rr['site_register'] == REGISTER_OPEN) + $register = 'open'; + elseif($rr['site_register'] == REGISTER_APPROVE) + $register = 'approve'; + else + $register = 'closed'; + + $ret['sites'][] = array('url' => $rr['site_url'], 'access' => $access, 'register' => $register); + } + } + return $ret; +} \ No newline at end of file diff --git a/mod/pubsites.php b/mod/pubsites.php new file mode 100644 index 000000000..3e8833a9d --- /dev/null +++ b/mod/pubsites.php @@ -0,0 +1,37 @@ +' . t('Public Sites') . ''; + + $ret = z_fetch_url($url); + if($ret['success']) { + $j = json_decode($ret['body'],true); + if($j) { + $o .= ''; + foreach($j as $jj) { + $o .= ''; + } + + $o .= '
' . t('Site URL') . '' . t('Access Type') . '' . t('Registration Policy') . '
' . $jj['url'] . '' . $jj['access'] . '' . $jj['register'] . '
'; + } + } + return $o; +}