You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

176 lines
9.4 KiB

  1. <?php
  2. // Project: Web Reference Database (refbase) <http://www.refbase.net>
  3. // Copyright: Matthias Steffens <mailto:refbase@extracts.de> and the file's
  4. // original author(s).
  5. //
  6. // This code is distributed in the hope that it will be useful,
  7. // but WITHOUT ANY WARRANTY. Please see the GNU General Public
  8. // License for more details.
  9. //
  10. // File: ./cite/formats/cite_ascii.php
  11. // Repository: $HeadURL: file:///svn/p/refbase/code/branches/bleeding-edge/cite/formats/cite_ascii.php $
  12. // Author(s): Matthias Steffens <mailto:refbase@extracts.de>
  13. //
  14. // Created: 10-Jun-06, 02:54
  15. // Modified: $Date: 2017-04-13 02:00:18 +0000 (Thu, 13 Apr 2017) $
  16. // $Author: karnesky $
  17. // $Revision: 1416 $
  18. // This is a citation format file (which must reside within the 'cite/formats/' sub-directory of your refbase root directory). It contains a
  19. // version of the 'citeRecords()' function that outputs a reference list from selected records in plain text format. Plain text output is
  20. // mainly meant for command line interfaces such as the refbase command line client (<http://cli.refbase.net/>).
  21. // --------------------------------------------------------------------
  22. // --- BEGIN CITATION FORMAT ---
  23. function citeRecords($result, $rowsFound, $query, $queryURL, $showQuery, $showLinks, $rowOffset, $showRows, $previousOffset, $nextOffset, $wrapResults, $citeStyle, $citeOrder, $citeType, $orderBy, $headerMsg, $userID, $viewType)
  24. {
  25. global $officialDatabaseName; // these variables are defined in 'ini.inc.php'
  26. global $databaseBaseURL;
  27. global $contentTypeCharset;
  28. global $client;
  29. // The array '$transtab_refbase_ascii' contains search & replace patterns for conversion from refbase markup to plain text
  30. global $transtab_refbase_ascii; // defined in 'transtab_refbase_ascii.inc.php'
  31. $plainTextData = ""; // make sure that our buffer variable is empty
  32. // Header:
  33. if (!empty($headerMsg))
  34. {
  35. // Decode any HTML entities:
  36. // (these may occur in the header message e.g. if the user's preferred display language is not English but German or French, etc)
  37. $headerMsg = decodeHTML($contentTypeCharset, $headerMsg); // function 'decodeHTML()' is defined in 'include.inc.php', and '$contentTypeCharset' is defined in 'ini.inc.php'
  38. // Convert refbase markup in the header message into plain text:
  39. $headerMsg = searchReplaceText($transtab_refbase_ascii, $headerMsg, true); // function 'searchReplaceText()' is defined in 'include.inc.php'
  40. $plainTextData .= "$headerMsg\n\n"; // prefix any passed header message
  41. }
  42. // Initialize array variables:
  43. $yearsArray = array();
  44. $typeTitlesArray = array();
  45. // Define inline text markup to be used by the 'citeRecord()' function:
  46. $markupPatternsArray = array("bold-prefix" => "", // for plain text output, we'll omit any font-shape markup
  47. "bold-suffix" => "",
  48. "italic-prefix" => "",
  49. "italic-suffix" => "",
  50. "underline-prefix" => "",
  51. "underline-suffix" => "",
  52. "endash" => "-",
  53. "emdash" => "-",
  54. "ampersand" => "&",
  55. "double-quote" => '"',
  56. "double-quote-left" => '"',
  57. "double-quote-right" => '"',
  58. "single-quote" => "'",
  59. "single-quote-left" => "'",
  60. "single-quote-right" => "'",
  61. "less-than" => "<",
  62. "greater-than" => ">",
  63. "newline" => "\n"
  64. );
  65. // Defines search & replace 'actions' that will be applied upon TEXT output to all those refbase fields that are listed
  66. // in the corresponding 'fields' element:
  67. $plainTextSearchReplaceActionsArray = array(
  68. array('fields' => array("title", "publication", "abbrev_journal", "address", "keywords", "abstract", "orig_title", "series_title", "abbrev_series_title", "notes"),
  69. 'actions' => $transtab_refbase_ascii
  70. )
  71. );
  72. // For CLI queries, we'll allow paging thru the result set, i.e. we honour the values of the CLI options '-S|--start' ('$rowOffset')
  73. // and '-R|--rows' ('$showRows') ('$rowOffset' and '$showRows' are re-assigned in function 'seekInMySQLResultsToOffset()' in 'include.inc.php')
  74. if (preg_match("/^cli/i", $client)) // if the query originated from a command line client such as the "refbase" CLI client ("cli-refbase-1.0")
  75. $showMaxRows = $showRows; // show only rows up to the value given in '$showRows'
  76. else
  77. $showMaxRows = $rowsFound; // otherwise show all rows
  78. // LOOP OVER EACH RECORD:
  79. // Fetch one page of results (or less if on the last page)
  80. // (i.e., upto the limit specified in $showMaxRows) fetch a row into the $row array and ...
  81. for ($rowCounter=0; (($rowCounter < $showMaxRows) && ($row = @ mysqli_fetch_array($result))); $rowCounter++)
  82. {
  83. foreach ($row as $rowFieldName => $rowFieldValue)
  84. // Apply search & replace 'actions' to all fields that are listed in the 'fields' element of the arrays contained in '$plainTextSearchReplaceActionsArray':
  85. foreach ($plainTextSearchReplaceActionsArray as $fieldActionsArray)
  86. if (in_array($rowFieldName, $fieldActionsArray['fields']))
  87. $row[$rowFieldName] = searchReplaceText($fieldActionsArray['actions'], $row[$rowFieldName], true); // function 'searchReplaceText()' is defined in 'include.inc.php'
  88. // Order attributes according to the chosen output style & record type:
  89. $record = citeRecord($row, $citeStyle, $citeType, $markupPatternsArray, false); // function 'citeRecord()' is defined in the citation style file given in '$citeStyleFile' (which, in turn, must reside in the 'cite' directory of the refbase root directory), see function 'generateCitations()'
  90. // Print out the current record:
  91. if (!empty($record)) // unless the record buffer is empty...
  92. {
  93. // Print any section heading(s):
  94. if (preg_match("/year|type/i", $citeOrder))
  95. {
  96. list($yearsArray, $typeTitlesArray, $sectionHeading) = generateSectionHeading($yearsArray, $typeTitlesArray, $row, $citeOrder, "", "", "", "\n\n", "", "\n\n"); // function 'generateSectionHeading()' is defined in 'cite.inc.php'
  97. $plainTextData .= $sectionHeading;
  98. }
  99. // Write plain TEXT paragraph:
  100. if (preg_match("/^cli/i", $client)) // when outputting results to a command line client, we'll prefix the record with it's serial number (and it's user-specific cite key, if available)
  101. {
  102. // This is a stupid hack that maps the names of the '$row' array keys to those used
  103. // by the '$formVars' array (which is required by function 'generateCiteKey()')
  104. // (eventually, the '$formVars' array should use the MySQL field names as names for its array keys)
  105. $formVars = buildFormVarsArray($row); // function 'buildFormVarsArray()' is defined in 'include.inc.php'
  106. // Generate or extract the cite key for this record:
  107. // NOTE: currently, the following placeholders are not available for citation output:
  108. // <:keywords:>, <:issn:>, <:area:>, <:notes:>, <:userKeys:>
  109. // if the cite key specification uses one of these placeholders, it will get ignored
  110. $citeKey = generateCiteKey($formVars); // function 'generateCiteKey()' is defined in 'include.inc.php'
  111. $plainTextData .= "[" . $row['serial'] . "] ";
  112. if (!empty($citeKey))
  113. // Use the custom cite key that's been build according to the user's individual export options:
  114. $plainTextData .= "{" . $citeKey . "} ";
  115. }
  116. $plainTextData .= $record . "\n\n"; // create paragraph with encoded record text
  117. }
  118. }
  119. if (preg_match("/^cli/i", $client)) // when outputting results to a command line client, we'll append some info about the number of rows displayed/found, the database name/URL and optionally display the SQL query
  120. {
  121. // Calculate the maximum result number on each page:
  122. if (($rowOffset + $showRows) < $rowsFound)
  123. $showMaxRow = ($rowOffset + $showRows); // maximum result number on each page
  124. else
  125. $showMaxRow = $rowsFound; // for the last results page, correct the maximum result number if necessary
  126. if ($rowsFound == 1)
  127. $footerInfoPart = " record found";
  128. else
  129. $footerInfoPart = " records found";
  130. $rowsFoundInfo = ($rowOffset + 1) . "-" . $showMaxRow . " of " . $rowsFound . $footerInfoPart; // prints e.g. "1-5 of 23 records found"
  131. $rowsFoundDelimiter = preg_replace("/./i", "-", $rowsFoundInfo); // generate a line of hyphens which has the same length as the string in '$rowsFoundInfo' (e.g. "-----------------------")
  132. $plainTextData .= $rowsFoundDelimiter . "\n" . $rowsFoundInfo . "\n\n"; // append info about rows displayed/found
  133. $plainTextData .= $officialDatabaseName . "\n" . $databaseBaseURL . "\n\n"; // append database name and URL (comment this line if you don't like that)
  134. if ($showQuery == "1") // display SQL query:
  135. $plainTextData .= "Query: " . $query . "\n\n";
  136. }
  137. return $plainTextData;
  138. }
  139. // --- END CITATION FORMAT ---
  140. ?>