]> git.mxchange.org Git - friendica.git/commitdiff
Added noscrape feature.
authorBeanow <beanow@project-virality.com>
Sun, 10 Aug 2014 10:45:34 +0000 (12:45 +0200)
committerBeanow <beanow@project-virality.com>
Sun, 10 Aug 2014 10:45:34 +0000 (12:45 +0200)
mod/admin.php
mod/friendica.php
mod/noscrape.php [new file with mode: 0644]
view/templates/admin_site.tpl

index 3b22811d146d28425926fc5fa53bfee4cda292da..265397a20fd1f66c7aff0e9fac966aeb9463e703 100644 (file)
@@ -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")
 
        ));
 
index b0d3892de8cdd3211e85941284dab64ae0049640..47d815dea91924d6c86f6494ab53e142facd3f34 100644 (file)
@@ -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 (file)
index 0000000..41ccc30
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+
+function noscrape_init(&$a) {
+       
+       if(!get_config('system','enable_noscrape'))
+               killme();
+       
+       if($a->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
index 835b027fe8ab30b0a66b07e8212710132b4570ad..36b0f6c358abaf419bfadb1a53b1cb286f10a9c3 100644 (file)
        {{include file="field_checkbox.tpl" field=$suppress_language}}
 
        <h3>{{$performance}}</h3>
+       {{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}}