function citeRecords($result, $rowsFound, $query, $queryURL, $showQuery, $showLinks, $rowOffset, $showRows, $previousOffset, $nextOffset, $wrapResults, $citeStyle, $citeOrder, $citeType, $orderBy, $headerMsg, $userID, $viewType) { global $contentTypeCharset; // defined in 'ini.inc.php' global $client; // The array '$transtab_refbase_rtf' contains search & replace patterns for conversion from refbase markup to RTF markup & entities global $transtab_refbase_rtf; // defined in 'transtab_refbase_rtf.inc.php' // Initialize array variables: $yearsArray = array(); $typeTitlesArray = array(); // Define inline text markup to be used by the 'citeRecord()' function: $markupPatternsArray = array("bold-prefix" => "{\\b ", "bold-suffix" => "}", "italic-prefix" => "{\\i ", "italic-suffix" => "}", "underline-prefix" => "{\\ul ", "underline-suffix" => "}", "endash" => "\\endash ", "emdash" => "\\emdash ", "ampersand" => "&", "double-quote" => '"', "double-quote-left" => "\\ldblquote ", "double-quote-right" => "\\rdblquote ", "single-quote" => "'", "single-quote-left" => "\\lquote ", "single-quote-right" => "\\rquote ", "less-than" => "<", "greater-than" => ">", "newline" => "\n{\\f1\\fs24 \\par}\n"); // Defines search & replace 'actions' that will be applied upon RTF output to all those refbase fields that are listed // in the corresponding 'fields' element: $rtfSearchReplaceActionsArray = array(array('fields' => array("title", "publication", "abbrev_journal", "address", "keywords", "abstract", "orig_title", "series_title", "abbrev_series_title", "notes"), 'actions' => $transtab_refbase_rtf)); // For CLI queries, we'll allow paging thru the result set, i.e. we honour the values of the CLI options '-S|--start' ('$rowOffset') // and '-R|--rows' ('$showRows') ('$rowOffset' and '$showRows' are re-assigned in function 'seekInMySQLResultsToOffset()' in 'include.inc.php') 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") $showMaxRows = $showRows; } else { $showMaxRows = $rowsFound; } // otherwise show all rows // Setup the basic RTF document structure (RTF functions defined in 'MINIMALRTF.php'): $rtf = new MINIMALRTF(); // initialize RTF object $rtfData = $rtf->openRtf(); // create RTF opening tag $rtf->createFontBlock(0, "Arial"); // create & set RTF font blocks $rtf->createFontBlock(1, "Times New Roman"); $rtfData .= $rtf->setFontBlock(); // Header: if (!empty($headerMsg)) { // Remove any colon (":") from end of header message: $headerMsg = trimTextPattern($headerMsg, ":", false, true); // function 'trimTextPattern()' is defined in 'include.inc.php' // Decode any HTML entities: // (these may occur in the header message e.g. if the user's preferred display language is not English but German or French, etc) $headerMsg = decodeHTML($contentTypeCharset, $headerMsg); // function 'decodeHTML()' is defined in 'include.inc.php', and '$contentTypeCharset' is defined in 'ini.inc.php' // Convert refbase markup in the header message into appropriate RTF markup & entities: $headerMsg = searchReplaceText($transtab_refbase_rtf, $headerMsg, true); // function 'searchReplaceText()' is defined in 'include.inc.php' $rtfData .= "{\\header\\pard\\qc {$headerMsg}\\par}\n"; } $rtfData .= $rtf->justify("full", 0.5, 0, -0.5); // by default, we'll justify text and set a hanging indent (left indent: 0.5, right indent: 0, first-line indent: -0.5) // LOOP OVER EACH RECORD: // Fetch one page of results (or less if on the last page) // (i.e., upto the limit specified in $showMaxRows) fetch a row into the $row array and ... for ($rowCounter = 0; $rowCounter < $showMaxRows && ($row = @mysql_fetch_array($result)); $rowCounter++) { foreach ($row as $rowFieldName => $rowFieldValue) { // Apply search & replace 'actions' to all fields that are listed in the 'fields' element of the arrays contained in '$rtfSearchReplaceActionsArray': foreach ($rtfSearchReplaceActionsArray as $fieldActionsArray) { if (in_array($rowFieldName, $fieldActionsArray['fields'])) { $row[$rowFieldName] = searchReplaceText($fieldActionsArray['actions'], $row[$rowFieldName], true); } } } // function 'searchReplaceText()' is defined in 'include.inc.php' // Order attributes according to the chosen output style & record type: $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()' // Print out the current record: if (!empty($record)) { // Print any section heading(s): if (preg_match("/year|type/i", $citeOrder)) { $headingPrefix = $rtf->justify("left", 0, 0, 0) . $rtf->paragraph(0, 12); // create empty paragraph in front of heading using "Arial" (font block 0) and a font size of 12pt $headingSuffix = $rtf->justify("full", 0.5, 0, -0.5); // justify any following text and set a hanging indent (left indent: 0.5, right indent: 0, first-line indent: -0.5) if ($citeOrder == "type") { // for 'citeOrder=type' we'll always print an empty paragraph after the heading $headingSuffix .= $rtf->paragraph(0, 12); } // create empty paragraph using "Arial" (font block 0) and a font size of 12pt list($yearsArray, $typeTitlesArray, $sectionHeading) = generateSectionHeading($yearsArray, $typeTitlesArray, $row, $citeOrder, $headingPrefix, $headingSuffix, "{\\f0\\fs28 {\\b ", "}\\par}\n", "{\\f0\\fs24 {\\b ", "}\\par}\n"); // function 'generateSectionHeading()' is defined in 'cite.inc.php' // Note that we pass raw RTF commands to the above function instead of using the 'textBlock()' function from 'MINIMALRTF.php'. This is due to a current limitation of the 'generateSectionHeading()' function. // For 'citeOrder=year', the appropriate call to the 'textBlock()' function would look like this: // $rtfData .= $rtf->textBlock(0, 14, $rtf->bold($row['year'])); // create major heading with the current year using "Arial" (font block 0) and a font size of 14pt, printed in bold $rtfData .= $sectionHeading; } // If character encoding is not UTF-8 already, convert record text to UTF-8: if ($contentTypeCharset != "UTF-8") { $record = convertToCharacterEncoding("UTF-8", "IGNORE", $record); } // function 'convertToCharacterEncoding()' is defined in 'include.inc.php' // Encode characters with an ASCII value of >= 128 in RTF 1.16 unicode format: $recordUnicodeCharEncoded = $rtf->utf8_2_unicode($record); // converts UTF-8 chars to unicode character codes // Write RTF paragraph: $rtfData .= $rtf->textBlock(1, 12, $recordUnicodeCharEncoded); // create text block with encoded record text using "Times New Roman" (font block 1) and a font size of 12pt } } $rtfData .= $rtf->closeRtf(); // create RTF closing tag return $rtfData; }
function citeRecords($result, $rowsFound, $query, $queryURL, $showQuery, $showLinks, $rowOffset, $showRows, $previousOffset, $nextOffset, $wrapResults, $citeStyle, $citeOrder, $citeType, $orderBy, $headerMsg, $userID, $viewType) { global $officialDatabaseName; // these variables are defined in 'ini.inc.php' global $databaseBaseURL; global $contentTypeCharset; global $pdfPageSize; global $client; // The array '$transtab_refbase_pdf' contains search & replace patterns for conversion from refbase markup to PDf markup & entities global $transtab_refbase_pdf; // defined in 'transtab_refbase_pdf.inc.php' // Initialize array variables: $yearsArray = array(); $typeTitlesArray = array(); // Define inline text markup to be used by the 'citeRecord()' function: $markupPatternsArray = array("bold-prefix" => "<b>", "bold-suffix" => "</b>", "italic-prefix" => "<i>", "italic-suffix" => "</i>", "underline-prefix" => "<u>", "underline-suffix" => "</u>", "endash" => "¦", "emdash" => "©", "ampersand" => "&", "double-quote" => '"', "double-quote-left" => "ª", "double-quote-right" => "¬", "single-quote" => "'", "single-quote-left" => "®", "single-quote-right" => "¶", "less-than" => "<", "greater-than" => ">", "newline" => "\n"); // Defines search & replace 'actions' that will be applied upon PDF output to all those refbase fields that are listed // in the corresponding 'fields' element: $pdfSearchReplaceActionsArray = array(array('fields' => array("title", "publication", "abbrev_journal", "address", "keywords", "abstract", "orig_title", "series_title", "abbrev_series_title", "notes"), 'actions' => $transtab_refbase_pdf)); // For CLI queries, we'll allow paging thru the result set, i.e. we honour the values of the CLI options '-S|--start' ('$rowOffset') // and '-R|--rows' ('$showRows') ('$rowOffset' and '$showRows' are re-assigned in function 'seekInMySQLResultsToOffset()' in 'include.inc.php') 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") $showMaxRows = $showRows; } else { $showMaxRows = $rowsFound; } // otherwise show all rows // Setup the basic PDF document structure (PDF functions defined in 'class.ezpdf.php'): $pdf = new Cezpdf($pdfPageSize, 'portrait'); // initialize PDF object if (!empty($headerMsg)) { // adjust upper page margin if a custom header message was given $pageMarginTop = "70"; } else { $pageMarginTop = "50"; } $pdf->ezSetMargins($pageMarginTop, 70, 50, 50); // set document margins (top, bottom, left, right) // Set fonts: $headingFont = 'includes/classes/org/pdf-php/fonts/Helvetica.afm'; $textBodyFont = 'includes/classes/org/pdf-php/fonts/Times-Roman.afm'; // Re-map character numbers from the 0->255 range to a named character, i.e. replace an (unused) character for any other PostScript char; // see the PDF reference for a list of supported PostScript/PDF character names: <http://www.adobe.com/devnet/pdf/pdf_reference.html>; // for the decimal code numbers of the ISO-8859-1 character set, see e.g.: <http://www.ramsch.org/martin/uni/fmi-hp/iso8859-1.html> $diff = array(166 => 'endash', 169 => 'emdash', 170 => 'quotedblleft', 172 => 'quotedblright', 174 => 'quoteleft', 182 => 'quoteright'); // Select a font: $pdf->selectFont($textBodyFont, array('encoding' => 'WinAnsiEncoding', 'differences' => $diff)); $pdf->openHere('Fit'); // Put a footer (and optionally a header) on all the pages: $all = $pdf->openObject(); // start an independent object; all further writes to a page will actually go into this object, until a 'closeObject()' call is made $pdf->saveState(); $pdf->setStrokeColor(0, 0, 0, 1); // set line color $pdf->setLineStyle(0.5); // set line width // - print header line and header message at the specified x/y position: if (!empty($headerMsg)) { // Remove any colon (":") from end of header message: $headerMsg = trimTextPattern($headerMsg, ":", false, true); // function 'trimTextPattern()' is defined in 'include.inc.php' // Decode any HTML entities: // (these may occur in the header message e.g. if the user's preferred display language is not English but German or French, etc) $headerMsg = decodeHTML($contentTypeCharset, $headerMsg); // function 'decodeHTML()' is defined in 'include.inc.php', and '$contentTypeCharset' is defined in 'ini.inc.php' // Convert refbase markup in the header message into appropriate PDF markup & entities: $headerMsg = searchReplaceText($transtab_refbase_pdf, $headerMsg, true); // function 'searchReplaceText()' is defined in 'include.inc.php' if ($pdfPageSize == 'a4') { $pdf->line(20, 800, 575, 800); $pdf->addText(50, 805, 10, $headerMsg); } elseif ($pdfPageSize == 'letter') { $pdf->line(20, 750, 592, 750); $pdf->addText(50, 755, 10, $headerMsg); } } // - print footer line and footer text at the specified x/y position: if ($pdfPageSize == 'a4') { $pdf->line(20, 40, 575, 40); $pdf->addText(50, 28, 10, $officialDatabaseName . ' ¦ ' . $databaseBaseURL); // w.r.t. the endash, see notes at '$markupPatternsArray' and '$diff' above } elseif ($pdfPageSize == 'letter') { $pdf->line(20, 40, 592, 40); $pdf->addText(50, 28, 10, $officialDatabaseName . ' ¦ ' . $databaseBaseURL); } $pdf->restoreState(); $pdf->closeObject(); // close the currently open object; further writes will now go to the current page $pdf->addObject($all, 'all'); // note that object can be told to appear on just odd or even pages by changing 'all' to 'odd' or 'even' // Start printing page numbers: if ($pdfPageSize == 'a4') { $pdf->ezStartPageNumbers(550, 28, 10, '', '', 1); } elseif ($pdfPageSize == 'letter') { $pdf->ezStartPageNumbers(567, 28, 10, '', '', 1); } // LOOP OVER EACH RECORD: // Fetch one page of results (or less if on the last page) // (i.e., upto the limit specified in $showMaxRows) fetch a row into the $row array and ... for ($rowCounter = 0; $rowCounter < $showMaxRows && ($row = @mysql_fetch_array($result)); $rowCounter++) { foreach ($row as $rowFieldName => $rowFieldValue) { // Apply search & replace 'actions' to all fields that are listed in the 'fields' element of the arrays contained in '$pdfSearchReplaceActionsArray': foreach ($pdfSearchReplaceActionsArray as $fieldActionsArray) { if (in_array($rowFieldName, $fieldActionsArray['fields'])) { $row[$rowFieldName] = searchReplaceText($fieldActionsArray['actions'], $row[$rowFieldName], true); } } } // function 'searchReplaceText()' is defined in 'include.inc.php' // Order attributes according to the chosen output style & record type: $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()' // Print out the current record: if (!empty($record)) { // Print any section heading(s): if (preg_match("/year|type/i", $citeOrder)) { $headingPrefix = ""; $headingSuffix = ""; $sectionMarkupPrefix = "<b>"; $sectionMarkupSuffix = "</b>\n"; $subSectionMarkupPrefix = ""; $subSectionMarkupSuffix = "\n"; if ($citeOrder == "type-year") { $sectionMarkupSuffix .= "\n"; } list($yearsArray, $typeTitlesArray, $sectionHeading) = generateSectionHeading($yearsArray, $typeTitlesArray, $row, $citeOrder, $headingPrefix, $headingSuffix, $sectionMarkupPrefix, $sectionMarkupSuffix, $subSectionMarkupPrefix, $subSectionMarkupSuffix); // function 'generateSectionHeading()' is defined in 'cite.inc.php' if (!empty($sectionHeading)) { $pdf->selectFont($headingFont, array('encoding' => 'WinAnsiEncoding', 'differences' => $diff)); // use Helvetica $pdf->ezText($sectionHeading, '14', array('justification' => 'left')); // create heading using a font size of 14pt } } // If character encoding is not UTF-8 already, convert record text to UTF-8: // if ($contentTypeCharset != "UTF-8") // $record = convertToCharacterEncoding("UTF-8", "IGNORE", $record); // function 'convertToCharacterEncoding()' is defined in 'include.inc.php' // NOTE: Export of cited references to PDF does currently only work with a latin1 database but not with UTF-8 (since I don't know how to write Unicode characters to PDF). // As a workaround, we could convert UTF-8 characters to latin1 if possible (and omit any other higher ASCII chars) // TODO: While this workaround indeed fixes display issues with higher ASCII chars that have equivalents in the latin1 charset, this will currently swallow higher ASCII // hyphens/dashes such as endashes (which display correctly without this workaround). // if ($contentTypeCharset == "UTF-8") // $record = convertToCharacterEncoding("ISO-8859-1", "TRANSLIT", $record, "UTF-8"); // function 'convertToCharacterEncoding()' is defined in 'include.inc.php' // Set paragraph text options: $textOptions = array('justification' => 'full'); // possible array options: // 'left'=> number, gap to leave from the left margin // 'right'=> number, gap to leave from the right margin // 'aleft'=> number, absolute left position (overrides 'left') // 'aright'=> number, absolute right position (overrides 'right') // 'justification' => 'left','right','center','centre','full' // // only set one of the next two items (leading overrides spacing) // 'leading' => number, defines the total height taken by the line, independent of the font height. // 'spacing' => a real number, though usually set to one of 1, 1.5, 2 (line spacing as used in word processing) // Write PDF paragraph: $pdf->selectFont($textBodyFont, array('encoding' => 'WinAnsiEncoding')); // use Times-Roman $pdf->ezText($record . "\n", '12', $textOptions); // create text block with record text using "Times Roman" and a font size of 12pt } } return $pdf->ezStream(); }
function citeRecords($result, $rowsFound, $query, $queryURL, $showQuery, $showLinks, $rowOffset, $showRows, $previousOffset, $nextOffset, $wrapResults, $citeStyle, $citeOrder, $citeType, $orderBy, $headerMsg, $userID, $viewType) { global $contentTypeCharset; // defined in 'ini.inc.php' global $client; // The array '$transtab_refbase_latex' contains search & replace patterns for conversion from refbase markup to LaTeX markup & entities. // Converts refbase fontshape markup (italic, bold) into LaTeX commands of the 'textcomp' package, super- and subscript as well as greek // symbols get converted into the respective commands in math mode. You may need to adopt the LaTeX markup to suit your individual needs. global $transtab_refbase_latex; // defined in 'transtab_refbase_latex.inc.php' // The arrays '$transtab_latin1_latex' and '$transtab_unicode_latex' provide translation tables for best-effort conversion of higher ASCII // characters from ISO-8859-1 (or Unicode, respectively) to LaTeX entities. global $transtab_latin1_latex; // defined in 'transtab_latin1_latex.inc.php' global $transtab_unicode_latex; // defined in 'transtab_unicode_latex.inc.php' // Initialize array variables: $yearsArray = array(); $typeTitlesArray = array(); // Define inline text markup to be used by the 'citeRecord()' function: $markupPatternsArray = array("bold-prefix" => "\\textbf{", "bold-suffix" => "}", "italic-prefix" => "\\textit{", "italic-suffix" => "}", "underline-prefix" => "\\ul{", "underline-suffix" => "}", "endash" => "--", "emdash" => "---", "ampersand" => "&", "double-quote" => '"', "double-quote-left" => "{\\textquotedblleft}", "double-quote-right" => "{\\textquotedblright}", "single-quote" => "'", "single-quote-left" => "{\\textquoteleft}", "single-quote-right" => "{\\textquoteright}", "less-than" => "<", "greater-than" => ">", "newline" => "\n\n"); // Defines search & replace 'actions' that will be applied upon LaTeX output to all those refbase fields that are listed // in the corresponding 'fields' element: $latexSearchReplaceActionsArray = array(array('fields' => array("title", "publication", "abbrev_journal", "address", "keywords", "abstract", "orig_title", "series_title", "abbrev_series_title", "notes"), 'actions' => $transtab_refbase_latex)); // For CLI queries, we'll allow paging thru the result set, i.e. we honour the values of the CLI options '-S|--start' ('$rowOffset') // and '-R|--rows' ('$showRows') ('$rowOffset' and '$showRows' are re-assigned in function 'seekInMySQLResultsToOffset()' in 'include.inc.php') 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") $showMaxRows = $showRows; } else { $showMaxRows = $rowsFound; } // otherwise show all rows // Setup the basic LaTeX document structure: $latexData = "%&LaTeX\n" . "\\documentclass{article}\n\n"; // NOTE: the "Vancouver" & "Harvard 1" citation styles make use of the '\ul' command which requires '\usepackage{soul}' // TODO: figure out a better logic when to include the '\usepackage{soul}' statement (or should we simply always include it?) if (preg_match("/^(Vancouver|Harvard 1)\$/i", $citeStyle)) { $latexData .= "\\usepackage{soul}\n"; } if ($contentTypeCharset == "UTF-8") { $latexData .= "\\usepackage[utf8]{inputenc}\n"; } else { $latexData .= "\\usepackage[latin1]{inputenc}\n"; } $latexData .= "\\usepackage[T1]{fontenc}\n" . "\\usepackage{textcomp}\n\n"; $latexData .= "\\begin{document}\n\n"; // Header: if (!empty($headerMsg)) { // Remove any colon (":") from end of header message: $headerMsg = trimTextPattern($headerMsg, ":", false, true); // function 'trimTextPattern()' is defined in 'include.inc.php' // Decode any HTML entities: // (these may occur in the header message e.g. if the user's preferred display language is not English but German or French, etc) $headerMsg = decodeHTML($contentTypeCharset, $headerMsg); // function 'decodeHTML()' is defined in 'include.inc.php', and '$contentTypeCharset' is defined in 'ini.inc.php' // Convert refbase markup in the header message into appropriate LaTeX markup & entities: $headerMsg = searchReplaceText($transtab_refbase_latex, $headerMsg, true); // function 'searchReplaceText()' is defined in 'include.inc.php' // Attempt to convert higher ASCII chars (i.e., characters with an ASCII value of >= 128) in the header message to their corresponding LaTeX entities: if ($contentTypeCharset == "UTF-8") { $headerMsg = searchReplaceText($transtab_unicode_latex, $headerMsg, false); } else { $headerMsg = searchReplaceText($transtab_latin1_latex, $headerMsg, false); } $latexData .= "\\title{" . $headerMsg . "}\n\n" . "\\maketitle\n\n"; } if (!preg_match("/type|year/i", $citeOrder)) { $latexData .= "\\begin{thebibliography}{" . $showMaxRows . "}\n\n"; } // LOOP OVER EACH RECORD: // Fetch one page of results (or less if on the last page) // (i.e., upto the limit specified in $showMaxRows) fetch a row into the $row array and ... for ($rowCounter = 0; $rowCounter < $showMaxRows && ($row = @mysql_fetch_array($result)); $rowCounter++) { foreach ($row as $rowFieldName => $rowFieldValue) { // Apply search & replace 'actions' to all fields that are listed in the 'fields' element of the arrays contained in '$latexSearchReplaceActionsArray': foreach ($latexSearchReplaceActionsArray as $fieldActionsArray) { if (in_array($rowFieldName, $fieldActionsArray['fields'])) { $row[$rowFieldName] = searchReplaceText($fieldActionsArray['actions'], $row[$rowFieldName], true); } } } // function 'searchReplaceText()' is defined in 'include.inc.php' // Order attributes according to the chosen output style & record type: $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()' // Print out the current record: if (!empty($record)) { // Print any section heading(s): if (preg_match("/year|type/i", $citeOrder)) { list($yearsArray, $typeTitlesArray, $sectionHeading) = generateSectionHeading($yearsArray, $typeTitlesArray, $row, $citeOrder, "", "", "\\section*{", "}\n\n", "\\subsection*{", "}\n\n"); // function 'generateSectionHeading()' is defined in 'cite.inc.php' $latexData .= $sectionHeading; } // Attempt to convert higher ASCII chars (i.e., characters with an ASCII value of >= 128) to their corresponding LaTeX entities: if ($contentTypeCharset == "UTF-8") { $recordEncoded = searchReplaceText($transtab_unicode_latex, $record, false); } else { $recordEncoded = searchReplaceText($transtab_latin1_latex, $record, false); } // Write LaTeX paragraph: if (!preg_match("/type|year/i", $citeOrder)) { // This is a stupid hack that maps the names of the '$row' array keys to those used // by the '$formVars' array (which is required by function 'generateCiteKey()') // (eventually, the '$formVars' array should use the MySQL field names as names for its array keys) $formVars = buildFormVarsArray($row); // function 'buildFormVarsArray()' is defined in 'include.inc.php' // Generate or extract the cite key for this record: // NOTE: currently, the following placeholders are not available for citation output: // <:keywords:>, <:issn:>, <:area:>, <:notes:>, <:userKeys:> // if the cite key specification uses one of these placeholders, it will get ignored $citeKey = generateCiteKey($formVars); // function 'generateCiteKey()' is defined in 'include.inc.php' if (!empty($citeKey)) { // Use the custom cite key that's been build according to the user's individual export options: $latexData .= "\\bibitem{" . $citeKey . "} "; } else { // The '\bibitem' command requires a cite key, which is why we'll include the record's serial number // even when the user's export options specify 'export_cite_keys=no' or 'autogenerate_cite_keys=no': $latexData .= "\\bibitem{" . $row['serial'] . "} "; } } $latexData .= $recordEncoded . "\n\n"; // create paragraph with encoded record text } } if (!preg_match("/type|year/i", $citeOrder)) { $latexData .= "\\end{thebibliography}\n\n"; } $latexData .= "\\end{document}\n\n"; return $latexData; }
function handleFileUploads($uploadFile, $formVars) { global $filesBaseDir; // these variables are defined in 'ini.inc.php' global $moveFilesIntoSubDirectories; global $dirNamingScheme; global $renameUploadedFiles; global $fileNamingScheme; global $handleNonASCIIChars; global $allowedFileNameCharacters; global $allowedDirNameCharacters; global $changeCaseInFileNames; global $changeCaseInDirNames; $tmpFilePath = $uploadFile["tmp_name"]; // Generate file name: if ($renameUploadedFiles == "yes") { if (preg_match("/.+\\.[^.]+\$/i", $uploadFile["name"])) { // preserve any existing file name extension $fileNameExtension = preg_replace("/.+(\\.[^.]+)\$/i", "\\1", $uploadFile["name"]); } else { $fileNameExtension = ""; } // auto-generate a file name according to the naming scheme given in '$fileNamingScheme': $newFileName = parsePlaceholderString($formVars, $fileNamingScheme, "<:serial:>"); // function 'parsePlaceholderString()' is defined in 'include.inc.php' // handle non-ASCII and unwanted characters: $newFileName = handleNonASCIIAndUnwantedCharacters($newFileName, $allowedFileNameCharacters, $handleNonASCIIChars); // function 'handleNonASCIIAndUnwantedCharacters()' is defined in 'include.inc.php' // add original file name extension: $newFileName .= $fileNameExtension; } else { // take the file name as given by the user: $newFileName = $uploadFile["name"]; } // Generate directory structure: if ($moveFilesIntoSubDirectories != "never") { // remove any slashes (i.e., directory delimiter(s)) from the beginning or end of '$dirNamingScheme': $dirNamingScheme = trimTextPattern($dirNamingScheme, "[\\/\\\\]+", true, true); // function 'trimTextPattern()' is defined in 'include.inc.php' $dirNamingSchemePartsArray = preg_split("#[/\\\\]+#", $dirNamingScheme); // split on slashes to separate between multiple sub-directories $subDirNamesArray = array(); // initialize array variable which will hold the generated sub-directory names // auto-generate a directory name according to the naming scheme given in '$dirNamingScheme' // and handle non-ASCII chars plus unwanted characters: foreach ($dirNamingSchemePartsArray as $dirNamingSchemePart) { // parse given placeholder string: $subDirName = parsePlaceholderString($formVars, $dirNamingSchemePart, ""); // function 'parsePlaceholderString()' is defined in 'include.inc.php' // handle non-ASCII and unwanted characters: $subDirName = handleNonASCIIAndUnwantedCharacters($subDirName, $allowedDirNameCharacters, $handleNonASCIIChars); // function 'handleNonASCIIAndUnwantedCharacters()' is defined in 'include.inc.php' if (!empty($subDirName)) { $subDirNamesArray[] = $subDirName; } } if (!empty($subDirNamesArray)) { $subDirName = implode("/", $subDirNamesArray) . "/"; } else { $subDirName = ""; } } else { $subDirName = ""; } // Perform any case transformations: // change case of file name: if (preg_match("/^(lower|upper)\$/i", $changeCaseInFileNames)) { $newFileName = changeCase($changeCaseInFileNames, $newFileName); } // function 'changeCase()' is defined in 'include.inc.php' // change case of DIR name: if (preg_match("/^(lower|upper)\$/i", $changeCaseInDirNames) && !empty($subDirName)) { $subDirName = changeCase($changeCaseInDirNames, $subDirName); } // Generate full destination path: // - if '$moveFilesIntoSubDirectories = "existing"' and there's an existing sub-directory (within the default files directory '$filesBaseDir') // whose name equals '$subDirName' we'll copy the new file into that sub-directory // - if '$moveFilesIntoSubDirectories = "always"' and '$subDirName' isn't empty, we'll generate an appropriately named sub-directory if it // doesn't exist yet // - otherwise we just copy the file to the root-level of '$filesBaseDir': if (!empty($subDirName) && ($moveFilesIntoSubDirectories == "existing" and is_dir($filesBaseDir . $subDirName) or $moveFilesIntoSubDirectories == "always")) { $destFilePath = $filesBaseDir . $subDirName . $newFileName; // new file will be copied into sub-directory within '$filesBaseDir'... // copy the new subdir name & file name to the 'file' field variable: // Note: if a user uploads a file and there was already a file specified within the 'file' field, the old file will NOT get removed // from the files directory! Automatic file removal is omitted on purpose since it's way more difficult to recover an // inadvertently deleted file than to delete it manually. However, future versions should introduce a smarter way of handling // orphaned files... $fileName = $subDirName . $newFileName; if ($moveFilesIntoSubDirectories == "always" and !is_dir($filesBaseDir . $subDirName)) { // make sure the directory we're moving the file to exists before proceeding: recursiveMkdir($filesBaseDir . $subDirName); } } else { $destFilePath = $filesBaseDir . $newFileName; // new file will be copied to root-level of '$filesBaseDir'... $fileName = $newFileName; // copy the new file name to the 'file' field variable (see note above!) } // Copy uploaded file from temporary location to the default file directory specified in '$filesBaseDir': // (for more on PHP file uploads see <http://www.php.net/manual/en/features.file-upload.php>) move_uploaded_file($tmpFilePath, $destFilePath); return $fileName; }
function createNewTableWithParsedTableData($fieldName, $delim) { global $loginUserID; // saved as session variable on login global $tableRefs, $tableUserData; // defined in 'db.inc.php' if (preg_match("/^(user_keys|user_notes|user_file|user_groups)\$/", $fieldName)) { $query = "SELECT {$fieldName}, record_id, user_id FROM {$tableUserData}"; // WHERE user_id = " . $loginUserID $userIDTableSpec = "ref_user_id MEDIUMINT UNSIGNED NOT NULL, "; } else { $query = "SELECT {$fieldName}, serial FROM {$tableRefs}"; $userIDTableSpec = ""; } $result = queryMySQLDatabase($query); $fieldValuesArray = array(); // initialize array variable which will hold the splitted sub-items // split field values on the given delimiter: for ($i = 0; $row = @mysql_fetch_array($result); $i++) { $fieldSubValuesArray = preg_split($delim, $row[$fieldName]); // split field contents on '$delim' (which is interpreted as perl-style regular expression!) foreach ($fieldSubValuesArray as $fieldSubValue) { // // NOTE: we include empty values so that any Browse view query will also display the number of records where the given field is empty // if (!empty($fieldSubValue)) // { $fieldSubValue = trim($fieldSubValue); if ($fieldName == "author") { $fieldSubValue = trimTextPattern($fieldSubValue, " *\\(eds?\\)", false, true); } // remove any existing editor info from the 'author' string, i.e., kill any trailing " (ed)" or " (eds)" // copy the individual item (as string, ready for database insertion) to the array: if (preg_match("/^(user_keys|user_notes|user_file|user_groups)\$/", $fieldName)) { $fieldValuesArray[] = "(NULL, \"" . addslashes($fieldSubValue) . "\", {$row['record_id']}, {$row['user_id']})"; } else { $fieldValuesArray[] = "(NULL, \"" . addslashes($fieldSubValue) . "\", {$row['serial']})"; } // } } } // build correct 'ref_...' table and field names: list($tableName, $fieldName) = buildRefTableAndFieldNames($fieldName); // NOTE: the below query will only work if the current MySQL user is allowed to CREATE tables ('Create_priv = Y') // therefore, the CREATE statements should be moved to 'update.sql'! $queryArray[] = "CREATE TABLE " . $tableName . " (" . $fieldName . "_id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, " . $fieldName . " VARCHAR(255), " . "ref_id MEDIUMINT UNSIGNED NOT NULL, " . $userIDTableSpec . "INDEX (" . $fieldName . "_id, " . $fieldName . ", ref_id))"; // TODO: Sanitize with quote_smart foreach ($fieldValuesArray as $fieldValue) { $queryArray[] = "INSERT INTO " . $tableName . " VALUES " . $fieldValue; } // inserting all values at once may cause 'URL too long' server errors: // $fieldValuesString = implode(", ", $fieldValuesArray); // merge array // $queryArray[] = "INSERT INTO " . $tableName . " VALUES " . $fieldValuesString; // RUN the queries on the database through the connection: foreach ($queryArray as $query) { $result = queryMySQLDatabase($query); } return $tableName; }