Exemple #1
0
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;
}
Exemple #2
0
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 $client;
    // The array '$transtab_refbase_ascii' contains search & replace patterns for conversion from refbase markup to plain text
    global $transtab_refbase_ascii;
    // defined in 'transtab_refbase_ascii.inc.php'
    $plainTextData = "";
    // make sure that our buffer variable is empty
    // Header:
    if (!empty($headerMsg)) {
        // 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 plain text:
        $headerMsg = searchReplaceText($transtab_refbase_ascii, $headerMsg, true);
        // function 'searchReplaceText()' is defined in 'include.inc.php'
        $plainTextData .= "{$headerMsg}\n\n";
        // prefix any passed header message
    }
    // Initialize array variables:
    $yearsArray = array();
    $typeTitlesArray = array();
    // Define inline text markup to be used by the 'citeRecord()' function:
    $markupPatternsArray = array("bold-prefix" => "", "bold-suffix" => "", "italic-prefix" => "", "italic-suffix" => "", "underline-prefix" => "", "underline-suffix" => "", "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 TEXT output to all those refbase fields that are listed
    // in the corresponding 'fields' element:
    $plainTextSearchReplaceActionsArray = array(array('fields' => array("title", "publication", "abbrev_journal", "address", "keywords", "abstract", "orig_title", "series_title", "abbrev_series_title", "notes"), 'actions' => $transtab_refbase_ascii));
    // 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
    // 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 '$plainTextSearchReplaceActionsArray':
            foreach ($plainTextSearchReplaceActionsArray 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, "", "", "", "\n\n", "", "\n\n");
                // function 'generateSectionHeading()' is defined in 'cite.inc.php'
                $plainTextData .= $sectionHeading;
            }
            // Write plain TEXT paragraph:
            if (preg_match("/^cli/i", $client)) {
                // 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'
                $plainTextData .= "[" . $row['serial'] . "] ";
                if (!empty($citeKey)) {
                    // Use the custom cite key that's been build according to the user's individual export options:
                    $plainTextData .= "{" . $citeKey . "} ";
                }
            }
            $plainTextData .= $record . "\n\n";
            // create paragraph with encoded record text
        }
    }
    if (preg_match("/^cli/i", $client)) {
        // Calculate the maximum result number on each page:
        if ($rowOffset + $showRows < $rowsFound) {
            $showMaxRow = $rowOffset + $showRows;
        } else {
            $showMaxRow = $rowsFound;
        }
        // for the last results page, correct the maximum result number if necessary
        if ($rowsFound == 1) {
            $footerInfoPart = " record found";
        } else {
            $footerInfoPart = " records found";
        }
        $rowsFoundInfo = $rowOffset + 1 . "-" . $showMaxRow . " of " . $rowsFound . $footerInfoPart;
        // prints e.g. "1-5 of 23 records found"
        $rowsFoundDelimiter = preg_replace("/./i", "-", $rowsFoundInfo);
        // generate a line of hyphens which has the same length as the string in '$rowsFoundInfo' (e.g. "-----------------------")
        $plainTextData .= $rowsFoundDelimiter . "\n" . $rowsFoundInfo . "\n\n";
        // append info about rows displayed/found
        $plainTextData .= $officialDatabaseName . "\n" . $databaseBaseURL . "\n\n";
        // append database name and URL (comment this line if you don't like that)
        if ($showQuery == "1") {
            // display SQL query:
            $plainTextData .= "Query: " . $query . "\n\n";
        }
    }
    return $plainTextData;
}
Exemple #3
0
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();
}
Exemple #4
0
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;
}
Exemple #5
0
function citeRecords($result, $rowsFound, $query, $queryURL, $showQuery, $showLinks, $rowOffset, $showRows, $previousOffset, $nextOffset, $wrapResults, $citeStyle, $citeOrder, $citeType, $orderBy, $headerMsg, $userID, $viewType)
{
    global $databaseBaseURL;
    // these variables are defined in 'ini.inc.php'
    global $useVisualEffects;
    global $defaultDropDownFieldsEveryone;
    global $defaultDropDownFieldsLogin;
    global $defaultCiteStyle;
    global $additionalFieldsCitationView;
    global $displayResultsHeaderDefault;
    global $displayResultsFooterDefault;
    global $showLinkTypesInCitationView;
    global $showFieldItemLinks;
    global $maximumBrowseLinks;
    global $loc;
    // '$loc' is made globally available in 'core.php'
    global $client;
    global $displayType;
    $htmlData = "";
    // make sure that our buffer variables are empty
    $recordData = "";
    // First, initialize some variables that we'll need later on
    // Calculate the number of all visible columns (which is needed as colspan value inside some TD tags)
    if ($showLinks == "1" && preg_match("/^(type|type-year|year)\$/i", $citeOrder)) {
        // in citation layout, we simply set it to a fixed value (either '1' or '2', depending on the values of '$showLinks' and '$citeOrder')
        $NoColumns = 2;
    } else {
        $NoColumns = 1;
    }
    if (empty($displayType)) {
        $displayType = $_SESSION['userDefaultView'];
    }
    // get the default view for the current user
    // If the results footer is displayed, we increase the colspan value by 1 to account for the checkbox column:
    if (!preg_match("/^(Print|Mobile)\$/i", $viewType) and !preg_match("/^cli/i", $client) and $wrapResults != "0" and (!isset($displayResultsFooterDefault[$displayType]) or isset($displayResultsFooterDefault[$displayType]) and $displayResultsFooterDefault[$displayType] != "hidden")) {
        $NoColumns++;
    }
    // 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" => "&#8211;", "emdash" => "&#8212;", "ampersand" => "&", "double-quote" => '"', "double-quote-left" => "&ldquo;", "double-quote-right" => "&rdquo;", "single-quote" => "'", "single-quote-left" => "&lsquo;", "single-quote-right" => "&rsquo;", "less-than" => "<", "greater-than" => ">", "newline" => "\n<br>\n");
    // Defines field-specific search & replace 'actions' that will be applied to the actual citation
    // for all those refbase fields that are listed in the corresponding 'fields' element:
    // (These search and replace actions will be performed *in addition* to those specified globally
    //  in '$searchReplaceActionsArray' (defined in 'ini.inc.php'). Same rules apply as for
    //  '$searchReplaceActionsArray'.)
    $fieldSpecificSearchReplaceActionsArray = array(array('fields' => array("abstract"), 'actions' => array("/[\r\n]+/" => "\n<br>\n")));
    // In addition, for the "more info" section, we also substitute contents of the below 'fields'
    // with localized field values from variable '$loc'. Since the locales in '$loc' are already
    // HTML encoded, we have to exclude these fields from any further HTML encoding (done below).
    $fieldSpecificSearchReplaceActionsArray2 = $fieldSpecificSearchReplaceActionsArray;
    $fieldSpecificSearchReplaceActionsArray2[] = array('fields' => array("thesis", "approved", "marked", "copy", "selected"), 'actions' => array("/(.+)/e" => "\$loc['\\1']"));
    static $encodingExceptionsArray = array("thesis", "approved", "marked", "copy", "selected");
    // LOOP OVER EACH RECORD:
    // Fetch one page of results (or less if on the last page)
    // (i.e., upto the limit specified in $showRows) fetch a row into the $row array and ...
    for ($rowCounter = 0; $rowCounter < $showRows && ($row = @mysql_fetch_array($result)); $rowCounter++) {
        $encodedRowData = $row;
        // we keep '$row' in its original (unencoded) form since unencoded data will be required by function 'linkifyFieldItems()' below
        // NOTES: - Currently, HTML encoding and search & replace actions are applied separately
        //          for the citation and the "more info" section underneath the citation. The
        //          actions in this 'foreach' block concern the actual citation
        //        - It might be better to pass the unencoded '$row' data to function 'citeRecord()'
        //          which would then make calls to function 'encodeField()' individually for each
        //          field (similar to as it is done it 'modsxml.inc.php')
        foreach ($encodedRowData as $rowFieldName => $rowFieldValue) {
            // NOTES: - We HTML encode non-ASCII chars for all but the author & editor fields. The author & editor
            //          fields are excluded here since these fields must be passed *without* HTML entities to the
            //          'reArrangeAuthorContents()' function (which will then handle the HTML encoding by itself)
            //        - Function 'encodeField()' will also apply any field-specific search & replace actions
            $encodedRowData[$rowFieldName] = encodeField($rowFieldName, $rowFieldValue, $fieldSpecificSearchReplaceActionsArray, array("author", "editor"));
            // function 'encodeField()' is defined in 'include.inc.php'
        }
        // Order attributes according to the chosen output style & record type:
        $record = citeRecord($encodedRowData, $citeStyle, $citeType, $markupPatternsArray, true);
        // 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)) {
                if (preg_match("/^Mobile\$/i", $viewType)) {
                    $headingPrefix = "\n<div class=\"sect\">";
                    $headingSuffix = "</div>";
                } else {
                    $headingPrefix = "\n<tr>" . "\n\t<td valign=\"top\" colspan=\"{$NoColumns}\">";
                    $headingSuffix = "</td>" . "\n</tr>";
                }
                list($yearsArray, $typeTitlesArray, $sectionHeading) = generateSectionHeading($yearsArray, $typeTitlesArray, $row, $citeOrder, $headingPrefix, $headingSuffix, "<h4>", "</h4>", "<h5>", "</h5>");
                // function 'generateSectionHeading()' is defined in 'cite.inc.php'
                $recordData .= $sectionHeading;
            }
            // Print out the record:
            if (is_integer($rowCounter / 2)) {
                // if we currently are at an even number of rows
                $rowClass = "even";
            } else {
                $rowClass = "odd";
            }
            if (preg_match("/^(cli|inc)/i", $client) or $wrapResults == "0") {
                // we use absolute links for CLI clients, for include mechanisms, or when returning only a partial document structure
                $baseURL = $databaseBaseURL;
            } else {
                $baseURL = "";
            }
            $recordPermaLink = $databaseBaseURL . "show.php?record=" . $row["serial"];
            // generate a permanent link for the current record
            if (preg_match("/^Mobile\$/i", $viewType)) {
                $recordData .= "\n<div class=\"" . $rowClass . "\">" . "\n\t<div class=\"citation\">" . $record . "</div>";
            } else {
                $recordData .= "\n<tr class=\"" . $rowClass . "\">";
                // Print a column with a checkbox:
                // Note: we omit the results footer in print/mobile view ('viewType=Print' or 'viewType=Mobile'), for CLI clients, and when outputting only a partial document structure ('wrapResults=0')!
                if (!preg_match("/^Print\$/i", $viewType) and !preg_match("/^cli/i", $client) and $wrapResults != "0" and (!isset($displayResultsFooterDefault[$displayType]) or isset($displayResultsFooterDefault[$displayType]) and $displayResultsFooterDefault[$displayType] != "hidden")) {
                    $recordData .= "\n\t<td align=\"center\" valign=\"top\" width=\"10\">";
                    // - Print a checkbox form element:
                    if (!isset($displayResultsFooterDefault[$displayType]) or isset($displayResultsFooterDefault[$displayType]) and $displayResultsFooterDefault[$displayType] != "hidden") {
                        $recordData .= "\n\t\t<input type=\"checkbox\" onclick=\"updateAllRecs();\" name=\"marked[]\" value=\"" . $row["serial"] . "\" title=\"" . $loc["selectRecord"] . "\">";
                    }
                    if (!empty($row["orig_record"])) {
                        if (!isset($displayResultsFooterDefault[$displayType]) or isset($displayResultsFooterDefault[$displayType]) and $displayResultsFooterDefault[$displayType] != "hidden") {
                            $recordData .= "\n\t\t<br>";
                        }
                        if ($row["orig_record"] < 0) {
                            $recordData .= "\n\t\t<img src=\"" . $baseURL . "img/ok.gif\" alt=\"(" . $loc["original"] . ")\" title=\"" . $loc["originalRecord"] . "\" width=\"14\" height=\"16\" hspace=\"0\" border=\"0\">";
                        } else {
                            // $row["orig_record"] > 0
                            $recordData .= "\n\t\t<img src=\"" . $baseURL . "img/caution.gif\" alt=\"(" . $loc["duplicate"] . ")\" title=\"" . $loc["duplicateRecord"] . "\" width=\"5\" height=\"16\" hspace=\"0\" border=\"0\">";
                        }
                    }
                    // - Add <abbr> block which works as a microformat that allows applications to identify objects on web pages; see <http://unapi.info/specs/> for more info
                    $recordData .= "\n\t\t<div class=\"unapi\"><abbr class=\"unapi-id\" title=\"" . $recordPermaLink . "\"></abbr></div>";
                    $recordData .= "\n\t</td>";
                }
                // Print record data as a citation:
                $recordData .= "\n\t<td id=\"ref" . $row["serial"] . "\" class=\"citation\" valign=\"top\">" . "\n\t\t" . $record;
                // Display a triangle widget to show more info (keywords, abstract, etc) under each citation:
                if (!empty($additionalFieldsCitationView)) {
                    // Map MySQL field names to localized column names:
                    $fieldNamesArray = mapFieldNames();
                    // function 'mapFieldNames()' is defined in 'include.inc.php'
                    if ($useVisualEffects == "yes") {
                        $toggleVisibilityFunction = "toggleVisibilitySlide";
                    } else {
                        $toggleVisibilityFunction = "toggleVisibility";
                    }
                    $recordData .= "\n\t\t<div class=\"showhide\">" . "\n\t\t\t<a href=\"javascript:" . $toggleVisibilityFunction . "('moreinfo" . $row["serial"] . "','toggleimg" . $row["serial"] . "','toggletxt" . $row["serial"] . "','more%20info')\" title=\"" . $loc["LinkTitle_ToggleVisibility"] . "\">" . "<img id=\"toggleimg" . $row["serial"] . "\" class=\"toggleimg\" src=\"" . $baseURL . "img/closed.gif\" alt=\"" . $loc["LinkTitle_ToggleVisibility"] . "\" width=\"9\" height=\"9\" hspace=\"0\" border=\"0\">" . "</a>" . "\n\t\t</div>" . "\n\t\t<div id=\"moreinfo" . $row["serial"] . "\" class=\"moreinfo\" style=\"display: none;\">";
                    // Print additional fields:
                    foreach ($additionalFieldsCitationView as $field) {
                        if (isset($row[$field]) and !empty($row[$field])) {
                            $recordData .= "\n\t\t\t<div class=\"" . $field . "\"><strong>" . $fieldNamesArray[$field] . ":</strong> ";
                            // Make field items into clickable search links:
                            if (in_array($displayType, $showFieldItemLinks)) {
                                // Note: Function 'linkifyFieldItems()' will also call function 'encodeField()' to HTML
                                //       encode non-ASCII chars and to apply any field-specific search & replace actions
                                $recordData .= linkifyFieldItems($field, $row[$field], $userID, $fieldSpecificSearchReplaceActionsArray2, $encodingExceptionsArray, "/\\s*[;]+\\s*/", "; ", $showQuery, $showLinks, $showRows, $citeStyle, $citeOrder, $wrapResults, $displayType, $viewType);
                            } else {
                                // don't hotlink field items
                                $recordData .= encodeField($field, $row[$field], $fieldSpecificSearchReplaceActionsArray2, $encodingExceptionsArray);
                            }
                            // function 'encodeField()' is defined in 'include.inc.php'
                            $recordData .= "</div>";
                        }
                    }
                    // Print a row with links for the current record:
                    $recordData .= "\n\t\t\t<div class=\"reflinks\">";
                    // - Print the record's permanent URL:
                    if (preg_match("/^inc/i", $client)) {
                        // we open links in a new browser window if refbase data are included somewhere else:
                        $target = " target=\"_blank\"";
                    } else {
                        $target = "";
                    }
                    $recordData .= "\n\t\t\t\t<div class=\"permalink\"><a href=\"" . $recordPermaLink . "\"" . $target . " title=\"" . $loc["LinkTitle_Permalink"] . "\">";
                    if (preg_match("/^Print\$/i", $viewType)) {
                        // for print view, we use the URL as link title
                        $recordData .= $recordPermaLink;
                    } else {
                        $recordData .= $loc["PermalinkShort"];
                    }
                    $recordData .= "</a></div>";
                    // - Print additional links to cite/export the current record:
                    //   Note: we omit the additional links in print view ('viewType=Print')
                    if (!preg_match("/^Print\$/i", $viewType)) {
                        // -- Print cite links:
                        if (isset($_SESSION['user_permissions']) and preg_match("/allow_cite/", $_SESSION['user_permissions']) and isset($_SESSION['user_cite_formats'])) {
                            $userCiteFormatsArray = preg_split("/ *; */", $_SESSION['user_cite_formats'], -1, PREG_SPLIT_NO_EMPTY);
                            // get a list of the user's cite formats (the 'PREG_SPLIT_NO_EMPTY' flag causes only non-empty pieces to be returned)
                            $recordData .= "\n\t\t\t\t<div class=\"citelinks\">" . "&nbsp;|&nbsp;" . $loc["SaveCitation"] . ":";
                            foreach ($userCiteFormatsArray as $citeFormat) {
                                if (!preg_match("/^html\$/i", $citeFormat)) {
                                    // for now, we exclude the "HTML" cite format (as it's not any different to the regular Citation view HTML output)
                                    $recordData .= "\n\t\t\t\t\t&nbsp;<a href=\"" . $baseURL . generateURL("show.php", $citeFormat, array("record" => $row['serial']), true, "", "", $citeStyle, $citeOrder) . "\" title=\"" . $loc["LinkTitle_SaveCitationFormat_Prefix"] . $citeFormat . $loc["LinkTitle_SaveCitationFormat_Suffix"] . "\">" . $citeFormat . "</a>";
                                }
                            }
                            $recordData .= "\n\t\t\t\t</div>";
                        }
                        // -- Print export links:
                        if (isset($_SESSION['user_permissions']) and preg_match("/allow_export|allow_batch_export/", $_SESSION['user_permissions']) and isset($_SESSION['user_export_formats'])) {
                            $userExportFormatsArray = preg_split("/ *; */", $_SESSION['user_export_formats'], -1, PREG_SPLIT_NO_EMPTY);
                            // get a list of the user's export formats
                            $recordData .= "\n\t\t\t\t<div class=\"exportlinks\">" . "&nbsp;|&nbsp;" . $loc["ExportRecord"] . ":";
                            foreach ($userExportFormatsArray as $exportFormat) {
                                $recordData .= "\n\t\t\t\t\t&nbsp;<a href=\"" . $baseURL . generateURL("show.php", $exportFormat, array("record" => $row['serial'], "exportType" => "file"), true, "", "", $citeStyle) . "\" title=\"" . $loc["LinkTitle_ExportRecordFormat_Prefix"] . $exportFormat . $loc["LinkTitle_ExportRecordFormat_Suffix"] . "\">" . $exportFormat . "</a>";
                            }
                            $recordData .= "\n\t\t\t\t</div>";
                        }
                    }
                    $recordData .= "\n\t\t\t</div>" . "\n\t\t</div>";
                }
                $recordData .= "\n\t</td>";
            }
            // Display the regular links column:
            if ($showLinks == "1") {
                if (preg_match("/^Mobile\$/i", $viewType)) {
                    $recordData .= "\n\t<div class=\"links\">";
                } else {
                    $recordData .= "\n\t<td class=\"links\" valign=\"top\" width=\"42\">";
                }
                // Print out available links:
                // for Citation view, we'll use the '$showLinkTypesInCitationView' array that's defined in 'ini.inc.php'
                // to specify which links shall be displayed (if available and if 'showLinks == 1')
                // (for links of type DOI/URL/ISBN/XREF, only one link will be printed; order of preference: DOI, URL, ISBN, XREF)
                $recordData .= printLinks($showLinkTypesInCitationView, $row, $showQuery, $showLinks, $wrapResults, $userID, $viewType, $orderBy);
                // function 'printLinks()' is defined in 'search.php'
                if (preg_match("/^Mobile\$/i", $viewType)) {
                    $recordData .= "\n\t</div>";
                } else {
                    $recordData .= "\n\t</td>";
                }
            }
            if (preg_match("/^Mobile\$/i", $viewType)) {
                $recordData .= "\n</div>";
            } else {
                $recordData .= "\n</tr>";
            }
        }
    }
    // OUTPUT RESULTS:
    // Note: we omit the results header, browse links & query form for CLI clients, and when outputting only a partial document structure ('wrapResults=0')
    if (!preg_match("/^cli/i", $client) and $wrapResults != "0") {
        // Note: we also omit the results header in print/mobile view ('viewType=Print' or 'viewType=Mobile')
        if (!preg_match("/^(Print|Mobile)\$/i", $viewType) and (!isset($displayResultsHeaderDefault[$displayType]) or isset($displayResultsHeaderDefault[$displayType]) and $displayResultsHeaderDefault[$displayType] != "hidden")) {
            // Extract the first field from the 'WHERE' clause:
            if (preg_match("/ WHERE [ ()]*(\\w+)/i", $query)) {
                $selectedField = preg_replace("/.+ WHERE [ ()]*(\\w+).*/i", "\\1", $query);
            } else {
                $selectedField = "author";
            }
            // in the 'Search within Results" form, we'll select the 'author' field by default
            // Map MySQL field names to localized column names:
            $fieldNamesArray = mapFieldNames(true);
            $localizedDropDownFieldsArray = array();
            if (isset($_SESSION['loginEmail']) and !empty($defaultDropDownFieldsLogin)) {
                // if a user is logged in -AND- there were any additional fields specified...
                $dropDownFieldsArray = array_merge($defaultDropDownFieldsEveryone, $defaultDropDownFieldsLogin);
            } else {
                $dropDownFieldsArray = $defaultDropDownFieldsEveryone;
            }
            foreach ($dropDownFieldsArray as $field) {
                if (isset($fieldNamesArray[$field])) {
                    $localizedDropDownFieldsArray[$field] = $fieldNamesArray[$field];
                } else {
                    // no localized field name exists, so we use the original field name
                    $localizedDropDownFieldsArray[$field] = $field;
                }
            }
            // Get all citation styles for the current user:
            if (!isset($_SESSION['user_styles'])) {
                $citationStylesArray = array($defaultCiteStyle);
            } else {
                $citationStylesArray = array();
                $citationStylesTempArray = preg_split("/ *; */", $_SESSION['user_styles']);
                // get the user's list of citation styles
                foreach ($citationStylesTempArray as $citationStyle) {
                    $citationStylesArray[$citationStyle] = $citationStyle;
                }
            }
            // 2) Build forms containing options to show the user's groups, refine the search results or change the displayed columns:
            //    TODO for 2b+2c: should we allow users to choose via the web interface which columns are included in the popup menus?
            //    2a) Build a FORM with a popup containing the user's groups:
            $formElementsGroup = buildGroupSearchElements("search.php", $queryURL, $query, $showQuery, $showLinks, $showRows, $citeStyle, $citeOrder, $displayType);
            // function 'buildGroupSearchElements()' is defined in 'include.inc.php'
            //    2b) Build a FORM containing options to refine the search results:
            //        Call the 'buildRefineSearchElements()' function (defined in 'include.inc.php') which does the actual work:
            $formElementsRefine = buildRefineSearchElements("search.php", $queryURL, $showQuery, $showLinks, $showRows, $citeStyle, $citeOrder, $localizedDropDownFieldsArray, $selectedField, $displayType);
            //    2c) Build a FORM containing display options (change citation style & sort order, or change the number of records displayed per page):
            //        Call the 'buildDisplayOptionsElements()' function (defined in 'include.inc.php') which does the actual work:
            $formElementsDisplayOptions = buildDisplayOptionsElements("search.php", $queryURL, $showQuery, $showLinks, $rowOffset, $showRows, $citeStyle, $citeOrder, $citationStylesArray, $citeStyle, 2, $displayType, $headerMsg);
            $htmlData .= displayResultsHeader("search.php", $formElementsGroup, $formElementsRefine, $formElementsDisplayOptions, $displayType);
            // function 'displayResultsHeader()' is defined in 'results_header.inc.php'
            //    and insert a divider line (which separates the results header from the browse links & results data below):
            $htmlData .= "\n<hr class=\"resultsheader\" align=\"center\" width=\"93%\">";
        }
        // Build a TABLE with links for "previous" & "next" browsing, as well as links to intermediate pages
        // call the 'buildBrowseLinks()' function (defined in 'include.inc.php'):
        $BrowseLinks = buildBrowseLinks("search.php", $query, $NoColumns, $rowsFound, $showQuery, $showLinks, $showRows, $rowOffset, $previousOffset, $nextOffset, $wrapResults, $maximumBrowseLinks, "sqlSearch", "Cite", $citeStyle, $citeOrder, $orderBy, $headerMsg, $viewType);
        $htmlData .= $BrowseLinks;
        if (preg_match("/^Mobile\$/i", $viewType)) {
            // Extract the original OpenSearch/CQL query that was saved by 'opensearch.php' as a session variable:
            if (isset($_SESSION['cqlQuery'])) {
                $cqlQuery = $_SESSION['cqlQuery'];
            } else {
                $cqlQuery = "";
            }
            // Include an OpenSearch-style (CQL) query form:
            $htmlData .= "\n<div id=\"queryform\">" . "\n\t<form action=\"opensearch.php\" method=\"GET\" name=\"openSearch\">" . "\n\t\t<input type=\"hidden\" name=\"formType\" value=\"openSearch\">" . "\n\t\t<input type=\"hidden\" name=\"submit\" value=\"" . $loc["ButtonTitle_Search"] . "\">" . "\n\t\t<input type=\"hidden\" name=\"viewType\" value=\"" . $viewType . "\">" . "\n\t\t<input type=\"hidden\" name=\"startRecord\" value=\"1\">" . "\n\t\t<input type=\"hidden\" name=\"maximumRecords\" value=\"" . $showRows . "\">" . "\n\t\t<input type=\"hidden\" name=\"recordSchema\" value=\"html\">" . "\n\t\t<input type=\"text\" name=\"query\" value=\"" . $cqlQuery . "\" size=\"25\" title=\"" . $loc["DescriptionEnterSearchString"] . "\">" . "\n\t\t<input type=\"submit\" name=\"submit\" value=\"" . $loc["ButtonTitle_Search"] . "\" title=\"" . $loc["DescriptionSearchDB"] . "\">" . "\n\t</form>" . "\n</div>";
        } elseif (!preg_match("/^Print\$/i", $viewType) and (!isset($displayResultsFooterDefault[$displayType]) or isset($displayResultsFooterDefault[$displayType]) and $displayResultsFooterDefault[$displayType] != "hidden")) {
            // Include the 'queryResults' form:
            $htmlData .= "\n<form action=\"search.php\" method=\"GET\" name=\"queryResults\">" . "\n<input type=\"hidden\" name=\"formType\" value=\"queryResults\">" . "\n<input type=\"hidden\" name=\"submit\" value=\"Cite\">" . "\n<input type=\"hidden\" name=\"originalDisplayType\" value=\"" . $displayType . "\">" . "\n<input type=\"hidden\" name=\"orderBy\" value=\"" . rawurlencode($orderBy) . "\">" . "\n<input type=\"hidden\" name=\"showQuery\" value=\"" . $showQuery . "\">" . "\n<input type=\"hidden\" name=\"showLinks\" value=\"" . $showLinks . "\">" . "\n<input type=\"hidden\" name=\"showRows\" value=\"" . $showRows . "\">" . "\n<input type=\"hidden\" name=\"rowOffset\" value=\"" . $rowOffset . "\">" . "\n<input type=\"hidden\" name=\"sqlQuery\" value=\"" . $queryURL . "\">";
            // embed the current sqlQuery so that it can be re-applied after the user pressed either of the 'Add' or 'Remove' buttons within the 'queryResults' form
        }
    }
    // Output query results:
    if (preg_match("/^Mobile\$/i", $viewType)) {
        $htmlData .= "\n<div id=\"citations\" class=\"results\">" . $recordData . "\n</div>";
    } else {
        $htmlData .= "\n<table id=\"citations\" class=\"results\" align=\"center\" width=\"100%\" summary=\"This table holds the database results for your query\">" . $recordData . "\n</table>";
    }
    // Append the footer:
    // Note: we omit the results footer & browse links in print/mobile view ('viewType=Print' or 'viewType=Mobile'), for CLI clients, and when outputting only a partial document structure ('wrapResults=0')!
    if (!preg_match("/^(Print|Mobile)\$/i", $viewType) and !preg_match("/^cli/i", $client) and $wrapResults != "0") {
        // Again, insert the (already constructed) BROWSE LINKS
        // (i.e., a TABLE with links for "previous" & "next" browsing, as well as links to intermediate pages)
        $htmlData .= $BrowseLinks;
        // Build a results footer with form elements to cite, group or export all/selected records:
        if (!isset($displayResultsFooterDefault[$displayType]) or isset($displayResultsFooterDefault[$displayType]) and $displayResultsFooterDefault[$displayType] != "hidden") {
            if (isset($_SESSION['user_permissions']) and (isset($_SESSION['loginEmail']) and preg_match("/allow_cite|allow_user_groups|allow_export|allow_batch_export/", $_SESSION['user_permissions']) or !isset($_SESSION['loginEmail']) and preg_match("/allow_cite/", $_SESSION['user_permissions']))) {
                // if the 'user_permissions' session variable does contain any of the following: 'allow_cite' -AND- if logged in, aditionally: 'allow_user_groups', 'allow_export', 'allow_batch_export'...
                // ...Insert a divider line (which separates the results data from the forms in the footer):
                $htmlData .= "\n<hr class=\"resultsfooter\" align=\"center\">";
            }
            // Call the 'buildResultsFooter()' function (which does the actual work):
            $htmlData .= buildResultsFooter($showRows, $citeStyle, $citeOrder, $displayType, $headerMsg);
        }
    }
    if (!preg_match("/^(Print|Mobile)\$/i", $viewType) and !preg_match("/^cli/i", $client) and $wrapResults != "0" and (!isset($displayResultsFooterDefault[$displayType]) or isset($displayResultsFooterDefault[$displayType]) and $displayResultsFooterDefault[$displayType] != "hidden")) {
        // Finish the form:
        $htmlData .= "\n</form>";
    }
    return $htmlData;
}
Exemple #6
0
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_markdown' contains search & replace patterns for conversion from refbase markup to Markdown markup & entities
    global $transtab_refbase_markdown;
    // defined in 'transtab_refbase_markdown.inc.php'
    $markdownData = "";
    // make sure that our buffer variable is empty
    // Header:
    if (!empty($headerMsg)) {
        // 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 Markdown markup & entities:
        $headerMsg = searchReplaceText($transtab_refbase_markdown, $headerMsg, true);
        // function 'searchReplaceText()' is defined in 'include.inc.php'
        $markdownData .= "# {$headerMsg} #\n\n";
    }
    // Initialize array variables:
    $yearsArray = array();
    $typeTitlesArray = array();
    // Define inline text markup to be used by the 'citeRecord()' function:
    $markupPatternsArray = array("bold-prefix" => "**", "bold-suffix" => "**", "italic-prefix" => "_", "italic-suffix" => "_", "underline-prefix" => "<u>", "underline-suffix" => "</u>", "endash" => "&ndash;", "emdash" => "&mdash;", "ampersand" => "&", "double-quote" => '"', "double-quote-left" => "&ldquo;", "double-quote-right" => "&rdquo;", "single-quote" => "'", "single-quote-left" => "&lsquo;", "single-quote-right" => "&rsquo;", "less-than" => "<", "greater-than" => ">", "newline" => "  \n");
    // Defines search & replace 'actions' that will be applied upon Markdown output to all those refbase fields that are listed
    // in the corresponding 'fields' element:
    $markdownSearchReplaceActionsArray = array(array('fields' => array("title", "publication", "abbrev_journal", "address", "keywords", "abstract", "orig_title", "series_title", "abbrev_series_title", "notes"), 'actions' => $transtab_refbase_markdown));
    // 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
    // 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 '$markdownSearchReplaceActionsArray':
            foreach ($markdownSearchReplaceActionsArray 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 = "";
                if (!empty($headerMsg)) {
                    $sectionMarkupPrefix = "## ";
                    $sectionMarkupSuffix = " ##\n\n";
                    $subSectionMarkupPrefix = "### ";
                    $subSectionMarkupSuffix = " ###\n\n";
                } else {
                    $sectionMarkupPrefix = "# ";
                    $sectionMarkupSuffix = " #\n\n";
                    $subSectionMarkupPrefix = "## ";
                    $subSectionMarkupSuffix = " ##\n\n";
                }
                list($yearsArray, $typeTitlesArray, $sectionHeading) = generateSectionHeading($yearsArray, $typeTitlesArray, $row, $citeOrder, $headingPrefix, $headingSuffix, $sectionMarkupPrefix, $sectionMarkupSuffix, $subSectionMarkupPrefix, $subSectionMarkupSuffix);
                // function 'generateSectionHeading()' is defined in 'cite.inc.php'
                $markdownData .= $sectionHeading;
            }
            // Write plain TEXT paragraph:
            $markdownData .= $record . "\n\n";
            // create paragraph with encoded record text
        }
    }
    return $markdownData;
}