diff options
-rwxr-xr-x | boot.php | 2 | ||||
-rw-r--r-- | include/zot.php | 19 | ||||
-rw-r--r-- | install/database.sql | 2 | ||||
-rw-r--r-- | install/update.php | 11 | ||||
-rw-r--r-- | mod/dirsearch.php | 36 | ||||
-rw-r--r-- | mod/pubsites.php | 37 |
6 files changed, 102 insertions, 5 deletions
@@ -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', '<br />' . "\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 @@ <?php -define( 'UPDATE_VERSION' , 1066 ); +define( 'UPDATE_VERSION' , 1067 ); /** * @@ -766,3 +766,12 @@ ADD INDEX ( `layout_mid` ) "); return UPDATE_SUCCESS; return UPDATE_FAILED; } + +function update_r1066() { + $r = q("ALTER TABLE `site` ADD `site_access` INT NOT NULL DEFAULT '0' AFTER `site_url` , +ADD INDEX ( `site_access` )"); + if($r) + return UPDATE_SUCCESS; + return UPDATE_FAILED; +} + diff --git a/mod/dirsearch.php b/mod/dirsearch.php index 524f55cc1..7bf430bec 100644 --- a/mod/dirsearch.php +++ b/mod/dirsearch.php @@ -22,6 +22,12 @@ function dirsearch_content(&$a) { json_return_and_die($ret); } + if(argc > 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 @@ +<?php + +function pubsites_content(&$a) { + + $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); + + if($directory) { + $url = $directory['url'] . '/dirsearch'; + } + else { + $url = DIRECTORY_FALLBACK_MASTER . '/dirsearch'; + } + } + $url .= '/sites'; + + $o .= '<h1>' . t('Public Sites') . '</h1>'; + + $ret = z_fetch_url($url); + if($ret['success']) { + $j = json_decode($ret['body'],true); + if($j) { + $o .= '<table><tr><td>' . t('Site URL') . '</td><td>' . t('Access Type') . '</td><td>' . t('Registration Policy') . '</td></tr>'; + foreach($j as $jj) { + $o .= '<tr><td>' . $jj['url'] . '</td><td>' . $jj['access'] . '</td><td>' . $jj['register'] . '</td></tr>'; + } + + $o .= '</table>'; + } + } + return $o; +} |