Exemplo n.º 1
0
 $secondary_title = '';
 if (!empty($secondary_title_match[0])) {
     $secondary_title = trim($secondary_title_match[0]);
 }
 $editor = '';
 if (!empty($editors_match[0])) {
     $order = array("\r\n", "\n", "\r");
     $editors_match[0] = str_replace($order, ' ', $editors_match[0]);
     $editors_match[0] = join("#", $editors_match[0]);
     $patterns = array(',', '.', '#', '  ');
     $replacements = array(' ', '', ', ', ' ');
     $editor = str_replace($patterns, $replacements, $editors_match[0]);
 }
 $reference_type = 'article';
 if (!empty($type_match[0])) {
     $reference_type = convert_type(trim($type_match[0]), 'ris', 'ilib');
 }
 $keywords = '';
 if (!empty($keywords_match[0])) {
     $order = array("\r\n", "\n", "\r");
     $keywords_match[0] = str_replace($order, ' ', $keywords_match[0]);
     $patterns = array('[', ']', '|', '"', '/', '*');
     $keywords_match[0] = str_replace($patterns, ' ', $keywords_match[0]);
     array_walk($keywords_match[0], 'trim');
     $keywords_match[0] = join("#", $keywords_match[0]);
     $keywords = str_replace("#", " / ", $keywords_match[0]);
 }
 $doi = '';
 if (!empty($doi_match[0])) {
     $doi = trim($doi_match[0]);
 }
Exemplo n.º 2
0
         }
         if (isset($add_item['year'])) {
             if (is_numeric($add_item['year'])) {
                 $add_item['year'] = $add_item['year'] . "///";
             } else {
                 $add_item['year'] = str_replace('-', '/', $add_item['year']) . '/';
             }
         }
         while (list($key, $value) = each($add_item)) {
             $ris_name = array_search($key, $ris_translation);
             if ($ris_name && !empty($value)) {
                 $columns[] = $ris_name . $value;
             }
         }
         reset($add_item);
         $type = convert_type($item['reference_type'], 'ilib', 'ris');
         $line = join(PHP_EOL, $columns);
         $paper .= 'TY  - ' . $type . PHP_EOL;
         $paper .= $line . PHP_EOL;
         if ($hosted == false && is_file(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'library' . DIRECTORY_SEPARATOR . $item['file'])) {
             $paper .= 'L1  - file://';
             if (substr(strtoupper(PHP_OS), 0, 3) == 'WIN') {
                 $paper .= '/';
             }
             $paper .= dirname(__FILE__) . DIRECTORY_SEPARATOR . 'library' . DIRECTORY_SEPARATOR . $item['file'] . PHP_EOL;
         }
         $paper .= 'ER  - ' . PHP_EOL . PHP_EOL;
         $columns = null;
     }
 }
 if ($_GET['format'] == 'list') {
Exemplo n.º 3
0
 /**
  * HTTP Content Negotiation
  * 
  * Using the content negotiation algorithm specified in 
  * {@link http://cidr-report.org/ietf/all-ids/draft-ietf-http-v11-spec-00.txt draft-ietf-http-v11-spec-00}, 
  * will return the most appropriate variants (may be more then one that
  * works) based on the provided request headers. This function is based
  * off of {@link http://search.cpan.org/dist/libwww-perl/lib/HTTP/Negotiate.pm libwww-perl, HTTP::Negotiate, choose()}.
  *
  * Usage:
  * <code>
  *  $variants = array(
  *    array(
  *      id => 'var1',
  *      qs => 1.000,
  *      type => 'text/html',
  *      encoding => null,
  *      charset => 'iso-8859-1',
  *      language => 'en',
  *      size => 3000
  *    ),
  *    array(
  *      id => 'var2',
  *      qs => 1.000,
  *      type => 'application/xhtml+xml',
  *      encoding => null,
  *      charset => 'iso-8859-1',
  *      language => 'en',
  *      size => 3000
  *    ),
  *  );
  *  
  *  $request_headers = array(
  *    HTTP_ACCEPT => 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,{@*}*;q=0.5',
  *    HTTP_ACCEPT_LANGUAGE => 'en-us,en;q=0.5',
  *    HTTP_ACCEPT_CHARSET => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7', 
  *    HTTP_ACCEPT_ENCODING => 'gzip,deflate'
  *  );
  *  
  *  $results = HTTP_Negotiate::choose($variants, $request_headers);
  *  assertTrue(count($results) == 1 && $results[0]['id'] == 'var2');
  * </code>
  *
  * More information on accept headers can be found at 
  * {@link http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html}
  *
  * @access public
  * @author Gary Court <*****@*****.**>
  * @param array $variants Array of array of strings which contain the supported parameters of each variant (supported keys: id, qs, type, encoding, charset, language, size)
  * @param array $request_headers Array of strings which contain the request header (supported keys: HTTP_ACCEPT, HTTP_ACCEPT_LANGUAGE, HTTP_ACCEPT_CHARSET, HTTP_ACCEPT_ENCODING). If null, $_SERVER is used.
  * @return array The acceptable variants (from $variants) based on the request headers. May return more then one acceptable variant (in original order) or may return null (if no acceptable variant was found). 
  * @static
  * @version 1.0
  * @todo Support for parameters in variant->type.
  */
 function choose($variants, $request_headers = null)
 {
     //check arguments
     if (!is_array($variants)) {
         return false;
     }
     if ($request_headers === null) {
         $request_headers = $_SERVER;
     } elseif (!is_array($request_headers)) {
         return false;
     }
     //parse all accept values
     $request = array();
     $request_header_keys = array_keys($request_headers);
     foreach ($request_header_keys as $request_header_key) {
         $accept_type = null;
         if (strpos($request_header_key, 'HTTP_ACCEPT_') !== false) {
             $accept_type = strtolower(substr($request_header_key, strlen('HTTP_ACCEPT_')));
         } elseif ($request_header_key == 'HTTP_ACCEPT') {
             $accept_type = 'type';
         }
         if ($accept_type) {
             $request[$accept_type] = array();
             $accept_variants = array_trim(explode(',', $request_headers[$request_header_key]));
             foreach ($accept_variants as $accept_variant) {
                 if ($accept_variant) {
                     $accept_variant_parameters = array_trim(explode(';', $accept_variant));
                     $request[$accept_type][$accept_variant_parameters[0]] = array();
                     for ($i = 1; $i < count($accept_variant_parameters); $i++) {
                         if (strpos($accept_variant_parameters[$i], '=') !== false) {
                             $accept_variant_parameter_values = array_trim(explode('=', $accept_variant_parameters[$i]));
                             $accept_variant_parameter_values[1] = convert_type($accept_variant_parameter_values[1]);
                             if ($accept_variant_parameter_values[0] == 'q') {
                                 if ($accept_variant_parameter_values[1] > 1.0) {
                                     $accept_variant_parameter_values[1] = 1.0;
                                 } elseif ($accept_variant_parameter_values[1] < 0.0) {
                                     $accept_variant_parameter_values[1] = 0.0;
                                 }
                             }
                             if ($accept_variant_parameter_values[0] == 'mxb' && $accept_variant_parameter_values[1] < 0) {
                                 $accept_variant_parameter_values[1] = 0;
                             }
                             $request[$accept_type][$accept_variant_parameters[0]][$accept_variant_parameter_values[0]] = $accept_variant_parameter_values[1];
                         }
                     }
                     if (!isset($request[$accept_type][$accept_variant_parameters[0]]['q'])) {
                         $request[$accept_type][$accept_variant_parameters[0]]['q'] = 1.0;
                     }
                 }
             }
         }
     }
     //determine if at least one variant specifies a language
     $language_variant_specified = false;
     foreach ($variants as $variant) {
         if (isset($variant['language'])) {
             $language_variant_specified = true;
             break;
         }
     }
     //determine the best variant for the request
     $results = array();
     foreach ($variants as $variant) {
         //calculate qs
         if (!isset($variant['qs']) || !is_numeric($variant['qs'])) {
             $qs = 1.0;
         } else {
             $qs = (double) convert_type($variant['qs']);
         }
         //calculate qe
         if (!isset($request['encoding'])) {
             $qe = 1.0;
         } elseif (!isset($variant['encoding']) || !count($request['encoding'])) {
             $qe = 1.0;
         } elseif (array_key_exists($variant['encoding'], $request['encoding'])) {
             $qe = (double) $request['encoding'][$variant['encoding']]['q'];
         } elseif ($variant['encoding'] == 'identity') {
             $qe = 1.0;
         } elseif (isset($request['encoding']['*'])) {
             $qe = (double) $request['encoding']['*']['q'];
         } else {
             $qe = 0.0;
         }
         // ---------
         // hack by Brian
         // changed !count(... to !isset($request['charset'])
         // ---------
         //calculate qc
         if (!isset($request['charset'])) {
             $qc = 1.0;
         } elseif (!isset($variant['charset']) || $variant['charset'] == 'US-ASCII' || !isset($request['charset'])) {
             $qc = 1.0;
         } elseif (array_key_exists($variant['charset'], $request['charset'])) {
             $qc = (double) $request['charset'][$variant['charset']]['q'];
         } elseif (isset($request['charset']['*'])) {
             $qc = (double) $request['charset']['*']['q'];
         } else {
             $qc = 0.0;
         }
         //calculate ql
         if (!isset($request['language'])) {
             $ql = 1.0;
         } elseif (!$language_variant_specified || !count($request['language'])) {
             $ql = 1.0;
         } elseif (!isset($variant['language'])) {
             $ql = 0.5;
         } elseif (array_key_exists($variant['language'], $request['language'])) {
             $ql = (double) $request['language'][$variant['language']]['q'];
         } elseif (array_key_exists(substr($variant['language'], 0, 2), $request['language'])) {
             $ql = (double) $request['language'][substr($variant['language'], 0, 2)]['q'];
         } elseif (isset($request['language']['*'])) {
             $ql = (double) $request['language']['*']['q'];
         } else {
             $ql = 0.001;
         }
         //calculate q & mxb
         $mxb = null;
         // ---------
         // hack by Brian below added (6) !(isset...
         // to prevent warnings on strict php setups
         // ---------
         if (!isset($request['type'])) {
             $q = 0.0;
         } elseif (!isset($variant['type'])) {
             $q = 0.0;
         } elseif (!count($request['type'])) {
             $q = 1.0;
         } elseif (array_key_exists($variant['type'], $request['type'])) {
             if (!isset($request['type'][$variant['type']]['q'])) {
                 $request['type'][$variant['type']]['q'] = $q;
             }
             $q = (double) $request['type'][$variant['type']]['q'];
             if (!isset($request['type'][$variant['type']]['mxb'])) {
                 $request['type'][$variant['type']]['mxb'] = $mxb;
             }
             $mxb = $request['type'][$variant['type']]['mxb'];
         } elseif (array_key_exists(strtok($variant['type'], '/') . '/*', $request['type'])) {
             if (!isset($request['type'][strtok($variant['type'], '/') . '/*']['q'])) {
                 $request['type'][strtok($variant['type'], '/') . '/*']['q'] = $q;
             }
             $q = (double) $request['type'][strtok($variant['type'], '/') . '/*']['q'];
             if (!isset($request['type'][strtok($variant['type'], '/') . '/*']['mxb'])) {
                 $request['type'][strtok($variant['type'], '/') . '/*']['mxb'] = $mxb;
             }
             $mxb = $request['type'][strtok($variant['type'], '/') . '/*']['mxb'];
         } elseif (array_key_exists('*/*', $request['type'])) {
             if (!isset($request['type']['*/*']['q'])) {
                 $request['type']['*/*']['q'] = $q;
             }
             $q = (double) $request['type']['*/*']['q'];
             if (!isset($request['type']['*/*']['mxb'])) {
                 $request['type']['*/*']['mxb'] = $mxb;
             }
             $mxb = $request['type']['*/*']['mxb'];
         } else {
             $q = 0.0;
         }
         //calculate bs
         $bs = $variant['size'];
         //calculate Q
         if ($mxb === null || $bs === null || $mxb >= $bs) {
             $Q = $qs * $qe * $qc * $ql * $q;
         } else {
             $Q = 0.0;
         }
         //keep track of the highest Q values
         $variant['Q'] = $Q;
         if (!count($results) || $variant['Q'] > $results[0]['Q']) {
             $results = array($variant);
         } elseif ($variant['Q'] == $results[0]['Q']) {
             array_push($results, $variant);
         }
     }
     //sort results (which all have same Q) by smallest filesize, ascending
     if (!function_exists('compareVariants')) {
         function compareVariants($a, $b)
         {
             if ($a['Q'] == $b['Q']) {
                 if (isset($a['size'])) {
                     if (isset($b['size'])) {
                         if ($a['size'] == $b['size']) {
                             return 0;
                         }
                         return $a['size'] < $b['size'] ? -1 : 1;
                     }
                     return -1;
                 }
                 if (isset($b['size'])) {
                     return 1;
                 }
                 return 0;
             }
             return $a['Q'] < $b['Q'] ? 1 : -1;
         }
     }
     mergesort($results, 'compareVariants');
     //return variants ordered by best choice
     return $results;
 }
Exemplo n.º 4
0
         foreach ($array as $editor) {
             $array2 = explode(',', $editor);
             $last = trim($array2[0]);
             $last = substr($array2[0], 3, -1);
             $first = '';
             if (isset($array2[1])) {
                 $first = trim($array2[1]);
                 $first = substr($array2[1], 3, -1);
             }
             $new_editors[$i]['family'] = $last;
             $new_editors[$i]['given'] = $first;
             $i++;
         }
     }
     $date_parts['date-parts'][] = explode("-", $year);
     $type = convert_type($reference_type, 'ilib', 'csl');
     // CSL book type, shift secondary title to tertiary title
     if ($reference_type == 'book') {
         $tertiary_title = $secondary_title;
         $secondary_title = '';
     }
     $json['ID' . $id] = array("id" => 'ID' . $id, "type" => $type, "title" => $title, "container-title" => $secondary_title, "collection-title" => $tertiary_title, "page" => $pages, "volume" => $volume, "issue" => $issue, "DOI" => $doi, "journalAbbreviation" => $journal, "author" => $new_authors, "editor" => $new_editors, "issued" => $date_parts, "publisher" => $publisher, "publisher-place" => $place_published);
 }
 $response['references'] = $json;
 //FORMAT CITATION ARRAY FOR CITEPROC-JS
 foreach ($cites_ordered as $key => $id) {
     if (isset($json['ID' . $id])) {
         $citations[] = array("citationItems" => array(array('id' => 'ID' . $id)), "properties" => array('noteIndex' => $key + 1));
     } else {
         $errors[] = 'Error! Reference ' . $id . ' not found.';
     }