From 9026810496d64290ab7926345f7fae9b82d07987 Mon Sep 17 00:00:00 2001 From: Beanow Date: Sun, 10 Aug 2014 12:45:34 +0200 Subject: [PATCH] Added noscrape feature. --- mod/admin.php | 7 +++-- mod/friendica.php | 6 ++++- mod/noscrape.php | 51 +++++++++++++++++++++++++++++++++++ view/templates/admin_site.tpl | 1 + 4 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 mod/noscrape.php diff --git a/mod/admin.php b/mod/admin.php index 3b22811d14..265397a20f 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -360,6 +360,7 @@ function admin_page_site_post(&$a){ $temppath = ((x($_POST,'temppath')) ? notags(trim($_POST['temppath'])) : ''); $basepath = ((x($_POST,'basepath')) ? notags(trim($_POST['basepath'])) : ''); $singleuser = ((x($_POST,'singleuser')) ? notags(trim($_POST['singleuser'])) : ''); + $enable_noscrape = ((x($_POST,'enable_noscrape')) ? true : false); if($ssl_policy != intval(get_config('system','ssl_policy'))) { if($ssl_policy == SSL_POLICY_FULL) { q("update `contact` set @@ -483,6 +484,7 @@ function admin_page_site_post(&$a){ set_config('system','lockpath', $lockpath); set_config('system','temppath', $temppath); set_config('system','basepath', $basepath); + set_config('system','enable_noscrape', $enable_noscrape); info( t('Site settings updated.') . EOL); goaway($a->get_baseurl(true) . '/admin/site' ); @@ -643,8 +645,9 @@ function admin_page_site(&$a) { '$basepath' => array('basepath', t("Base path to installation"), get_config('system','basepath'), "If the system cannot detect the correct path to your installation, enter the correct path here. This setting should only be set if you are using a restricted system and symbolic links to your webroot."), '$relocate_url' => array('relocate_url', t("New base url"), $a->get_baseurl(), "Change base url for this server. Sends relocate message to all DFRN contacts of all users."), - - '$form_security_token' => get_form_security_token("admin_site"), + + '$enable_noscrape'=> array('enable_noscrape', t("Enable noscrape"), get_config('system','enable_noscrape'), t("The noscrape feature speeds up directory submissions by using JSON data instead of HTML scraping.")), + '$form_security_token' => get_form_security_token("admin_site") )); diff --git a/mod/friendica.php b/mod/friendica.php index b0d3892de8..47d815dea9 100644 --- a/mod/friendica.php +++ b/mod/friendica.php @@ -37,8 +37,12 @@ function friendica_init(&$a) { 'admin' => $admin, 'site_name' => $a->config['sitename'], 'platform' => FRIENDICA_PLATFORM, - 'info' => ((x($a->config,'info')) ? $a->config['info'] : '') + 'info' => ((x($a->config,'info')) ? $a->config['info'] : ''), ); + + //Enable noscrape? + if(!!get_config('system','enable_noscrape')) + $data['no_scrape_url'] = $a->get_baseurl().'/noscrape'; echo json_encode($data); killme(); diff --git a/mod/noscrape.php b/mod/noscrape.php new file mode 100644 index 0000000000..41ccc30adc --- /dev/null +++ b/mod/noscrape.php @@ -0,0 +1,51 @@ +argc > 1) + $which = $a->argv[1]; + else + killme(); + + $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(!$a->profile['net-publish']) + killme(); + + $keywords = ((x($a->profile,'pub_keywords')) ? $a->profile['pub_keywords'] : ''); + $keywords = str_replace(array('#',',',' ',',,'),array('',' ',',',','),$keywords); + $keywords = explode(',', $keywords); + + $json_info = array( + 'fn' => $a->profile['name'], + 'key' => $a->profile['pubkey'], + 'homepage' => $a->get_baseurl()."/profile/{$which}", + 'comm' => (x($a->profile,'page-flags')) && ($a->profile['page-flags'] == PAGE_COMMUNITY), + 'photo' => $a->profile['photo'], + 'tags' => $keywords + ); + + //These are optional fields. + $profile_fields = array('pdesc', 'locality', 'region', 'postal-code', 'country-name', 'gender', 'marital'); + foreach($profile_fields as $field) + if(!empty($a->profile[$field])) $json_info["$field"] = $a->profile[$field]; + + $dfrn_pages = array('request', 'confirm', 'notify', 'poll'); + foreach($dfrn_pages as $dfrn) + $json_info["dfrn-{$dfrn}"] = $a->get_baseurl()."/dfrn_{$dfrn}/{$which}"; + + //Output all the JSON! + header('Content-type: application/json; charset=utf-8'); + echo json_encode($json_info); + exit; + +} \ No newline at end of file diff --git a/view/templates/admin_site.tpl b/view/templates/admin_site.tpl index 835b027fe8..36b0f6c358 100644 --- a/view/templates/admin_site.tpl +++ b/view/templates/admin_site.tpl @@ -108,6 +108,7 @@ {{include file="field_checkbox.tpl" field=$suppress_language}}

{{$performance}}

+ {{include file="field_checkbox.tpl" field=$enable_noscrape}} {{include file="field_checkbox.tpl" field=$use_fulltext_engine}} {{include file="field_input.tpl" field=$itemcache}} {{include file="field_input.tpl" field=$itemcache_duration}}