Plugin Directory

Changeset 2111833


Ignore:
Timestamp:
06/25/2019 04:17:56 AM (7 years ago)
Author:
jimhu
Message:

update trunk to 1.3

Location:
wp-pubmed-reflist/trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • wp-pubmed-reflist/trunk/class.wpPubMedRefList.php

    r1830696 r2111833  
    190190   
    191191    function fetchXML($url){
     192        $delay = 400000; # 0.4 seconds in microseconds
     193        $apikey = trim(get_option('wp_pubmed_reflist_api'));
     194        if(isset($apikey) && $apikey != ''){
     195            $delay = 100000; # 0.1 seconds in microseconds
     196            $url .= "&api_key=$apikey";
     197        }
     198        #trigger_error("url:$url");
     199        usleep($delay);
    192200        switch($this->remote_method){
    193201            case 'allow_url_fopen':
  • wp-pubmed-reflist/trunk/class.wpPubMedRefListSettings.php

    r1822314 r2111833  
    7272   
    7373    function admin_init(){
    74         global $new_whitelist_options;
    7574        $this->options = get_option('wp_pubmed_reflist');
    7675        $this->formats = get_option('wp_pubmed_reflist_styles');
     76        $this->apikey = get_option('wp_pubmed_reflist_api');
    7777        # stylelist will be empty on first install or upgrade from < 0.9; initialize to squelch warning in set_default_styles
    7878        # if the styles don't exist set the default ones here so they are available even if the user never hits the styles tab.
     
    9696        # add new section for adding keys
    9797        add_settings_section(
    98             'wp_pubmed_reflist_faclist',           
    99             'New key',
    100             'wpPubMedReflistViews::faclist_text',
    101             'wp_pubmed_reflist'
     98            'wp_pubmed_reflist_faclist',            # id   
     99            'New key',                              # title
     100            'wpPubMedReflistViews::faclist_text',   # callback
     101            'wp_pubmed_reflist'                     # page
    102102            );
    103103        add_settings_field(
    104104            'wp_pubmed_reflist_faclist',
    105             '', array($this, 'faclist_form'),
     105            '',
     106            array($this, 'faclist_form'),
    106107            'wp_pubmed_reflist',
    107108            'wp_pubmed_reflist_faclist'
     
    197198            'wp_pubmed_bolds'               # section
    198199            );
     200        /*
     201        Registry for NCBI api key managment tab
     202        */
     203   
     204        register_setting(
     205            'pubmed_ref_api',                       # option group
     206            'wp_pubmed_reflist_api',                    # option name
     207            array($this, 'pubmed_formats_validate')     # sanitize callback
     208            );
     209        add_settings_section(
     210            'wp_pubmed_reflist_apikey',         # id
     211            'Add NCBI API key',                         # title
     212            'wpPubMedReflistViews::api_key_form_text',  # callback
     213            'wp_pubmed_reflist_api'                 # page
     214            );
     215        add_settings_field(
     216            'wp_pubmed_reflist_api',        # id
     217            '',                                 # title
     218            array($this, 'api_form'),       # callback
     219            'wp_pubmed_reflist_api',            # page
     220            'wp_pubmed_reflist_apikey'                  # section   
     221            );         
    199222    }
    200223
     
    212235    */
    213236    function options_page(){
    214         global $new_whitelist_options;
    215237        echo "<h2>PubMed Reflist</h2>
    216238        Manage PubMed queries for use with the [pmid-refs key=<key> limit=<number>] shorttag.";
     
    240262            $active_tab = $_GET[ 'tab' ];
    241263        } // end if
    242         $query_tab_class = $format_tab_class = $help_tab_class = 'nav-tab';
     264        $query_tab_class = $format_tab_class = $api_tab_class = $help_tab_class = 'nav-tab';
    243265        $active_tab_class = $active_tab.'_tab_class';
    244266        # commented out until I can figure out weird reordering and layout behavior of the tabs
     
    247269            <a href='?page=wp_pubmed_reflist&tab=query' class='$query_tab_class'>Queries</a>
    248270            <a href='?page=wp_pubmed_reflist&tab=format' class='$format_tab_class'>Reference Styles</a>
     271            <a href='?page=wp_pubmed_reflist&tab=api' class='$api_tab_class'>NCBI API key</a>
    249272            <a href='?page=wp_pubmed_reflist&tab=help' class='$help_tab_class'>Help</a>
    250273        </h2>";
     
    259282                submit_button('Save Changes','submit', true, array('tab'=>'format'));
    260283                break;
     284            case 'api':
     285                settings_fields('pubmed_ref_api');
     286                do_settings_sections('wp_pubmed_reflist_api'); # param is a page name, not a section id
     287                submit_button('Save Changes','submit', true, array('tab'=>'api'));
     288                break;
    261289            case 'query':
    262290            default:
    263         settings_fields('pubmed_refs_options');
    264         do_settings_sections('wp_pubmed_reflist');
     291                settings_fields('pubmed_refs_options');
     292                do_settings_sections('wp_pubmed_reflist');
    265293                submit_button('Save Changes','submit', true, array('tab'=>'query'));
    266294    }
     
    274302    function query_form(){
    275303        require_once(__DIR__."/settings/query_form.php");   
     304    }
     305
     306    function api_form(){
     307        require_once(__DIR__."/settings/api_form.php");
    276308    }
    277309
  • wp-pubmed-reflist/trunk/class.wpPubMedRefListViews.php

    r1822314 r2111833  
    3939        echo "List of items that should be get the html <strong>strong</strong> tag in article author lists (e.g. author names). Enter one item per line";
    4040    }
     41
     42    public static function api_key_form_text(){
     43        echo "
     44        <h2>Setting an NCBI API key</h2>
     45        <p>After May 1, 2018. NCBI began throttling anonymous queries to the E-utilities API, which is what WP Pubmed Reflist uses to do queries and fetch results. Anonymous requests are limited to 3/second while those with an API key can do 10/sec. The anonymous number may be enough for users of WP Pubmed Reflist, but if you want faster performance, get an API key for your NCBI account as described <a href='https://ncbiinsights.ncbi.nlm.nih.gov/2017/11/02/new-api-keys-for-the-e-utilities/'>here</a> and enter it below:        </p>
     46        ";
     47    }
     48
    4149
    4250    public static function noFetchMethod(){
     
    8290            if($extra != '') $reflist[] = $extra;
    8391        }
    84         if ($limit < 0){   
     92        if ($limit < 0){
    8593            $limit = abs($limit) - 1;
    8694            if(count($reflist) < $limit) $limit = count($reflist);
     
    151159                    $text = "$prefix<a href='http://www.ncbi.nlm.nih.gov/pmc/articles/$pmcid'>$pmcid</a>";
    152160                }
    153                 break; 
     161                break;
    154162            case '_TitleL':
    155163                if(isset($ref['PMID'])){
     
    189197        return $text;
    190198    }
    191    
     199       
    192200    /*
    193201    Display the help tab
  • wp-pubmed-reflist/trunk/readme.txt

    r1830696 r2111833  
    33Tags: shortcodes, pubmed, references
    44Requires at least: 3.0
    5 Tested up to: 4.9.4
     5Tested up to: 5.2.2
    66Donate link:http://biochemistry.tamu.edu/index.php/alum/giving/
    7 Stable tag: 1.2
     7Stable tag: 1.3
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    6363* input validation for the admin page
    6464* jquery datatables for settings view
     65= 1.3 =
     66* Change handling of disallowed characters in query keys in hopes of dealing with a mysterious problem where on some installations keys are showing illegal chars when the chars are all legal.
     67* Add support for NCBI API keys (optional)
     68
    6569= 1.2 =
    6670* Preprocess ArticleTitle and AbstractText wrap them in CDATA sections. This preserves HTML inside the Titles and Abstracts, such as superscripts.
  • wp-pubmed-reflist/trunk/settings/query_form.php

    r1822314 r2111833  
    88        $facprops = @$this->options['facprops'];
    99        #echo "<pre>options: \nfaclist\n"; var_dump($faclist);echo "facprops\n";var_dump($facprops);echo "</pre>"; 
    10         echo "<table><tr><th>Search Key</th><th>Query</th><th>Extras</th><th>Delete?</th></tr>";
     10        $hiddens = ''; 
     11        $formTable = "<table><tr><th>Search Key</th><th>Query</th><th>Extras</th><th>Delete?</th></tr>";
    1112        if($faclist){
    1213            sort($faclist);
    1314            foreach($faclist as $name){
    1415                # sanitize the faclist name
    15                 $sanitizedName = preg_replace('/[^a-zA-Z0-9\s-_\(\)]/', '', $name);
     16                $name = trim($name);
     17                $sanitizedName = preg_replace('/[^a-zA-Z0-9\s-_\(\)]/', '_', $name);
    1618                if($sanitizedName != $name){
    17                     echo "$name contains characters not allowed in the key";
     19                    $name = $sanitizedName;
     20                /*  echo "$name contains characters not allowed in the key<br />";
    1821                    # delete it if it is already in the db.
    1922                    if(($key = array_search($name, $this->options['faclist'])) !== false) {
     
    2427                        unset ($facprops[$name]['query']);
    2528                    }                           
    26                     continue;
     29                    continue; */
    2730                }
    2831                if ($name == '' || (isset($facprops[$name]['delete']) && $facprops[$name]['delete'] == 'on')) continue;
    29                 $name = strtolower($name);
     32                #$name = strtolower($name);
    3033                $val = $extras = "";
    31                 echo "<tr><td>$name</td>";
     34                $formTable .= "<tr><td>$name</td>";
    3235                # query
    3336                if(isset($facprops[$name]['query'])) $val = $facprops[$name]['query'];
    34                 echo "<td><textarea id='wp_pubmed_reflist_qlist' ".
     37                $formTable .= "<td><textarea id='wp_pubmed_reflist_qlist' ".
    3538                "name='wp_pubmed_reflist[facprops][$name][query]'
    3639                cols='60' rows='2' >$val</textarea></td>";
    3740                # extra citations not in pubmed
    3841                if(isset($facprops[$name]['extras'])) $extras = $facprops[$name]['extras'];
    39                 echo "<td><textarea id='wp_pubmed_reflist_qlist' ".
     42                $formTable .= "<td><textarea id='wp_pubmed_reflist_qlist' ".
    4043                "name='wp_pubmed_reflist[facprops][$name][extras]'
    4144                cols='60' rows='2' >$extras</textarea></td>";
    4245                # delete?
    43                 echo "<td><input type='checkbox' id='wp_pubmed_reflist_qlist' ".
     46                $formTable .= "<td><input type='checkbox' id='wp_pubmed_reflist_qlist' ".
    4447                "name='wp_pubmed_reflist[facprops][$name][delete]' /></td>
    4548                <tr>";
    4649               
    47                 echo "<input id='wp_pubmed_reflist_faclist' name='wp_pubmed_reflist[facprops][$name][last_update]' type='hidden' value='0' />";
     50                $hiddens .= "<input id='wp_pubmed_reflist_faclist' name='wp_pubmed_reflist[facprops][$name][last_update]' type='hidden' value='0' />\n";
    4851
    4952            }
    5053        }   
    51         echo "</table>";
     54        $formTable .= "</table>";
     55        echo $formTable.$hiddens;
Note: See TracChangeset for help on using the changeset viewer.