function get_subfolder($idparent, $spasi, $spasis) { $result = mysql_query("select * from pohon_keputusan where id_parent= '{$idparent}'"); // $no = 1; while ($row = mysql_fetch_row($result)) { if ($row[6] === 'Ya') { $kelancaran = "<font color=blue>{$row['6']}</font>"; } elseif ($row[6] === 'Tidak') { $kelancaran = "<font color=red>{$row['6']}</font>"; } elseif ($row[6] === '?') { $kelancaran = "<font color=orange>{$row['6']}</font>"; $spasis = $spasis - 1; } else { $kelancaran = "<b>{$row['6']}</b>"; $spasis = $spasis - 1; } $no = 1; $nos = 1; for ($i = 1; $i <= $spasi; $i++) { // echo "<i class='md md-remove' style='margin: -3px;'></i><i class='md md-remove' style='margin: -3px;'></i><i class='md md-remove' style='margin: -3px 5px -3px -3px;'></i>"; // echo "<i class='md md-battery-std' style='margin: -3px;'></i><i class='md md-battery-std' style='margin: -3px;'></i><i class='md md-battery-std' style='margin: -3px 5px -3px -3px;'></i>"; if ($spasi <= $nos) { echo "<img class='img-pohon-vertical' >"; } else { echo "<img class='img-pohon-vertical' ><img class='img-pohon-vertical' src='img/square.png'>"; } $nos++; } echo "<img class='img-pohon-vertical' src='img/square.png'><img class='img-pohon-horizontal' src='img/square.png'><img class='img-pohon-arrow' src='img/arrow.png'>\n\t\t\t\t\t \t </i><span class='badge m-5'>{$row['1']}</span> = {$row['2']} (Tidak = {$row['4']}, Ya = {$row['5']}) : <b>{$kelancaran}</b><br>"; $no++; $nos++; /*panggil dirinya sendiri*/ get_subfolder($row[0], $spasi + 1, $spasis + 1); } }
function get_subfolder($idparent, $spasi) { $result = mysql_query("select * from pohon_keputusan where id_parent= '{$idparent}'"); while ($row = mysql_fetch_row($result)) { for ($i = 1; $i <= $spasi; $i++) { echo "- "; } if ($row[6] === 'Ya') { $kelancaran = "<font color=blue>{$row['6']}</font>"; } elseif ($row[6] === 'Tidak') { $kelancaran = "<font color=#000000>{$row['6']}</font>"; } elseif ($row[6] === '?') { $kelancaran = "<font color=#FF00FF>{$row['6']}</font>"; } else { $kelancaran = "<b>{$row['6']}</b>"; } echo "<font color=green>{$row['1']}</font> = {$row['2']} (Tidak = {$row['4']}, Ya = {$row['5']}) : <b>{$kelancaran}</b><br>"; /*panggil dirinya sendiri*/ get_subfolder($row[0], $spasi + 1); } }
function get_subfolder($idparent, $spasi) { $result = mysql_query("SELECT *, v.variable_name as variable_name FROM pohon_keputusan pk JOIN variable v ON pk.variabel = v.variable_name where id_parent= '{$idparent}'"); while ($row = mysql_fetch_array($result)) { if ($row[6] === 'Ya') { $kelancaran = "<font color=blue>{$row['6']}</font>"; } elseif ($row[6] === 'Tidak') { $kelancaran = "<font color=red>{$row['6']}</font>"; } elseif ($row[6] === '?') { $kelancaran = "<font color=orange>{$row['6']}</font>"; } else { $kelancaran = "<b>{$row['6']}</b>"; } for ($i = 1; $i <= $spasi; $i++) { // echo "<i class='md md-remove' style='margin: -3px;'></i><i class='md md-remove' style='margin: -3px;'></i><i class='md md-remove' style='margin: -3px 5px -3px -3px;'></i>"; // echo "<i class='md md-battery-std' style='margin: -3px;'></i><i class='md md-battery-std' style='margin: -3px;'></i><i class='md md-battery-std' style='margin: -3px 5px -3px -3px;'></i>"; echo "<img class='img-pohon-vertical' src='img/square.png'>"; } echo "<img class='img-pohon-vertical' src='img/square.png'><img class='img-pohon-horizontal' src='img/square.png'><img class='img-pohon-arrow' src='img/arrow.png'>\n\t\t\t\t\t \t </i><span class='badge m-5'>{$row['variable_alias']}</span> = {$row['2']} (Tidak = {$row['4']}, Ya = {$row['5']}) : <b>{$kelancaran}</b><br>"; /*panggil dirinya sendiri*/ get_subfolder($row[0], $spasi + 1); } }
$author_ascii_array = explode(";", $authors_ascii); $author_ascii_array2 = explode(",", $author_ascii_array[0]); if (!empty($author_ascii_array2[0])) { $bibtex_author = substr($author_ascii_array2[0], 3, -1); } } empty($year) ? $bibtex_year = '0000' : ($bibtex_year = substr($year, 0, 4)); $bibtex = $bibtex_author . '-' . $bibtex_year . '-ID' . $new_id; $insert = $stmt6->execute(); $insert = null; } //RENAME TEMP PDFS if (is_writable(IL_PDF_PATH . DIRECTORY_SEPARATOR . $tmprow['file'])) { $dbHandle->exec("UPDATE tempfdb.full_text SET fileID=" . $new_id . " WHERE fileID=" . $tmprow['id']); copy(IL_PDF_PATH . DIRECTORY_SEPARATOR . $tmprow['file'], IL_PDF_PATH . DIRECTORY_SEPARATOR . get_subfolder($new_file) . DIRECTORY_SEPARATOR . $new_file); $hashes[$new_id] = md5_file(IL_PDF_PATH . DIRECTORY_SEPARATOR . get_subfolder($new_file) . DIRECTORY_SEPARATOR . $new_file); @unlink(IL_PDF_PATH . DIRECTORY_SEPARATOR . $tmprow['file']); } $tmprow = null; } $dbHandle->exec("COMMIT"); $tmpresult = null; $tmprow = null; } $stmt = null; $stmt2 = null; $stmt3 = null; $stmt4 = null; $stmt5 = null; $dbHandle->exec("DETACH DATABASE tempdb"); $dbHandle->exec("DETACH DATABASE tempfdb");
public function downloadPDF($mode = null, $attachments = array()) { // Add watermarks. if (!empty($_SESSION['watermarks'])) { if ($_SESSION['watermarks'] == 'nocopy') { $watermark = 'nocopy'; $message = str_repeat('DO NOT COPY ', 5); } elseif ($_SESSION['watermarks'] == 'confidential') { $watermark = 'confidential'; $message = str_repeat('CONFIDENTIAL ', 5); } $pdfmark = '<<' . ' /EndPage' . ' {' . ' 2 eq { pop false }' . ' {' . ' gsave' . ' /Helvetica_Bold 30 selectfont' . ' 1 0 0 setrgbcolor 10 5 moveto (' . $message . ') show' . ' grestore' . ' true' . ' } ifelse' . ' } bind' . ' >> setpagedevice'; $pdfmark_file = $this->temp_path . DIRECTORY_SEPARATOR . 'lib_' . session_id() . DIRECTORY_SEPARATOR . $watermark . '.ps'; file_put_contents($pdfmark_file, $pdfmark); $temp_file = $this->temp_path . DIRECTORY_SEPARATOR . $this->file_name . $watermark . '.pdf'; exec(select_ghostscript() . ' -o "' . $temp_file . '" -dPDFSETTINGS=/prepress -sDEVICE=pdfwrite "' . $pdfmark_file . '" "' . $this->pdf_full_path . '"'); $this->pdf_full_path = $temp_file; } // Attach PDF annotations. if (isset($attachments) && in_array('notes', $attachments)) { // Get page sizes. $pages = $this->getPageInfo(); $page_sizes = $pages['page_sizes']; $dbHandle = database_connect($this->database_path, 'library'); $user_id_q = $dbHandle->quote($_SESSION['user_id']); $user_name_q = $dbHandle->quote($_SESSION['user']); $file_name_q = $dbHandle->quote($this->file_name); // Attach from all users. if (in_array('allusers', $attachments)) { $quoted_path = $dbHandle->quote($this->database_path . DIRECTORY_SEPARATOR . 'users.sq3'); $dbHandle->exec("ATTACH DATABASE {$quoted_path} AS userdatabase"); $result = $dbHandle->query("SELECT id,annotation,page,top,left,userdatabase.users.username AS username FROM annotations\n JOIN userdatabase.users ON userdatabase.users.userID=annotations.userID\n WHERE filename={$file_name_q}\n ORDER BY CAST(page AS INTEGER) ASC, CAST(top AS INTEGER) ASC"); $dbHandle->exec("DETACH DATABASE userdatabase"); } else { // Attach from this user. $result = $dbHandle->query("SELECT id,annotation,page,top,left," . $user_name_q . " AS username FROM annotations\n WHERE filename={$file_name_q}\n AND userID={$user_id_q}\n ORDER BY CAST(page AS INTEGER) ASC, CAST(top AS INTEGER) ASC"); } $pdfmark = ''; while ($annotations = $result->fetch(PDO::FETCH_NAMED)) { // Calculate width and height in points for each page. $w = round($page_sizes[$annotations['page'] + 1][0] * 72 / $this->page_resolution); $h = round($page_sizes[$annotations['page'] + 1][1] * 72 / $this->page_resolution); $bottomx = round($w * ($annotations['left'] / 100)); $bottomy = round($h * (1 - $annotations['top'] / 100) - 20); $annotation = strtoupper(bin2hex(iconv('UTF-8', 'UCS-2BE', $annotations['annotation']))); $pdfmark .= '[ /Contents <FEFF' . $annotation . '> /Rect [' . $bottomx . ' ' . $bottomy . ' ' . (20 + $bottomx) . ' ' . (20 + $bottomy) . '] /Subtype /Text /Name /Comment /SrcPg ' . $annotations['page'] . ' /Open false /Title (Comment #' . $annotations['id'] . ' by ' . $annotations['username'] . ') /Color [0.6 0.65 0.9] /ANN pdfmark' . PHP_EOL; } $result = null; // Attach highlights. if (in_array('allusers', $attachments)) { // Attach from all users $quoted_path = $dbHandle->quote($this->database_path . DIRECTORY_SEPARATOR . 'users.sq3'); $dbHandle->exec("ATTACH DATABASE {$quoted_path} AS userdatabase"); $result = $dbHandle->query("SELECT id,page,top,left,width,userdatabase.users.username AS username FROM yellowmarkers\n JOIN userdatabase.users ON userdatabase.users.userID=yellowmarkers.userID\n WHERE filename=" . $file_name_q); $dbHandle->exec("DETACH DATABASE userdatabase"); } else { // Attach from this user. $result = $dbHandle->query("SELECT id,page,top,left,width," . $user_name_q . " AS username FROM yellowmarkers\n WHERE filename={$file_name_q}\n AND userID={$user_id_q}"); } // Compile Pdfmark for highlights. while ($annotations = $result->fetch(PDO::FETCH_NAMED)) { // Calculate width and height in points for each page. $w = round($page_sizes[$annotations['page'] + 1][0] * 72 / $this->page_resolution); $h = round($page_sizes[$annotations['page'] + 1][1] * 72 / $this->page_resolution); $bottomx = round($w * ($annotations['left'] / 100)); $bottomy = round($h * (1 - $annotations['top'] / 100) - 0.012 * $h); $topx = round($w * ($annotations['left'] / 100) + $annotations['width'] / 100 * $w); $topy = round($h * (1 - $annotations['top'] / 100)); $pdfmark .= '[ /Subtype /Highlight /Rect [ ' . $bottomx . ' ' . $bottomy . ' ' . $topx . ' ' . $topy . ' ] /QuadPoints [ ' . $bottomx . ' ' . $topy . ' ' . $topx . ' ' . $topy . ' ' . $bottomx . ' ' . $bottomy . ' ' . $topx . ' ' . $bottomy . ' ] /SrcPg ' . $annotations['page'] . ' /Color [0.78 0.8 1] /Title (Highlight by ' . $annotations['username'] . ') /ANN pdfmark' . PHP_EOL; } $result = null; // Write all annotations to the PDF. if (!empty($pdfmark)) { $pdfmark_file = $this->temp_path . DIRECTORY_SEPARATOR . 'lib_' . session_id() . DIRECTORY_SEPARATOR . 'pdfmark.txt'; file_put_contents($pdfmark_file, $pdfmark); $temp_file = $this->temp_path . DIRECTORY_SEPARATOR . 'lib_' . session_id() . DIRECTORY_SEPARATOR . $this->file_name . '-annotated.pdf'; exec(select_ghostscript() . ' -o "' . $temp_file . '" -dPDFSETTINGS=/prepress -sDEVICE=pdfwrite "' . $this->pdf_full_path . '" "' . $pdfmark_file . '"'); $this->pdf_full_path = $temp_file; } } // Attach files. $supfile_arr = array(); // Attach rich-text notes. if (isset($attachments) && in_array('richnotes', $attachments)) { $dbHandle = database_connect($this->database_path, 'library'); $user_id_q = $dbHandle->quote($_SESSION['user_id']); $file_name_q = $dbHandle->quote($this->file_name); $result = $dbHandle->query("SELECT notes FROM notes\n WHERE fileID=(SELECT id FROM library WHERE file={$file_name_q})\n AND userID={$user_id_q}"); $notetxt = $result->fetchColumn(); if (!empty($notetxt)) { $notetxt = '<!DOCTYPE html><html style="width:100%;height:100%"><head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>I, Librarian - Notes</title></head><body>' . $notetxt . '</body></html>'; file_put_contents($this->temp_path . DIRECTORY_SEPARATOR . 'lib_' . session_id() . DIRECTORY_SEPARATOR . 'richnotes.html', $notetxt); $supfile_arr[] = $this->temp_path . DIRECTORY_SEPARATOR . 'lib_' . session_id() . DIRECTORY_SEPARATOR . 'richnotes.html'; } } // Attach supplementary files. if (isset($attachments) && in_array('supp', $attachments)) { $supfiles = array(); $integer = substr($this->file_name, 0, strpos($this->file_name, '.')); $supfiles = glob($this->supplement_path . DIRECTORY_SEPARATOR . get_subfolder($integer) . DIRECTORY_SEPARATOR . $integer . '*'); $supfile_arr = array_merge((array) $supfiles, $supfile_arr); } // Ghostscript can attach files to PDF, but let's do it with Zip. if (!empty($supfile_arr) && extension_loaded('zip')) { $temp_file = $this->temp_path . DIRECTORY_SEPARATOR . 'lib_' . session_id() . DIRECTORY_SEPARATOR . 'output.zip'; $zip = new ZipArchive(); $zip->open($temp_file, ZIPARCHIVE::OVERWRITE); // Add PDF. $zip->addFile($this->pdf_full_path, basename($this->file_name)); // Add supplementary files. foreach ($supfile_arr as $supfile) { $zip->addFile($supfile, basename($supfile)); } $zip->close(); $this->pdf_full_path = $temp_file; $this->file_name = $this->file_name . '.zip'; } ob_end_clean(); // Output finished PDF. if (!empty($supfile_arr) && extension_loaded('zip')) { header("Content-type: application/zip"); } else { header("Content-type: application/pdf"); } if (isset($mode) && $mode == 'download') { header("Content-Disposition: attachment; filename=\"{$this->file_name}\""); } else { header("Content-Disposition: inline"); } header("Pragma: no-cache"); header("Expires: 0"); header('Content-Length: ' . filesize($this->pdf_full_path)); readfile($this->pdf_full_path); }
} } rmdir($unpack_dir); } ########## record graphical abstract ########## if (isset($_FILES['form_graphical_abstract']) && is_uploaded_file($_FILES['form_graphical_abstract']['tmp_name'])) { $extension = pathinfo($_FILES['form_graphical_abstract']['name'], PATHINFO_EXTENSION); if (empty($extension)) { $extension = 'jpg'; } $new_name = sprintf("%05d", intval($new_file)) . 'graphical_abstract.' . $extension; move_uploaded_file($_FILES['form_graphical_abstract']['tmp_name'], IL_SUPPLEMENT_PATH . DIRECTORY_SEPARATOR . get_subfolder($new_file) . DIRECTORY_SEPARATOR . $new_name); } ########## extract text from pdf ########## if (isset($copy) && $copy || isset($move) && $move) { system(select_pdftotext() . ' -enc UTF-8 "' . IL_PDF_PATH . DIRECTORY_SEPARATOR . get_subfolder($new_file) . DIRECTORY_SEPARATOR . $new_file . '" "' . IL_TEMP_PATH . DIRECTORY_SEPARATOR . $new_file . '.txt"', $ret); if (is_file(IL_TEMP_PATH . DIRECTORY_SEPARATOR . $new_file . ".txt")) { $string = file_get_contents(IL_TEMP_PATH . DIRECTORY_SEPARATOR . $new_file . ".txt"); unlink(IL_TEMP_PATH . DIRECTORY_SEPARATOR . $new_file . ".txt"); if (!empty($string)) { $string = preg_replace('/[^\\x{0009}\\x{000a}\\x{000d}\\x{0020}-\\x{D7FF}\\x{E000}-\\x{FFFD}]+/u', ' ', $string); $order = array("\r\n", "\n", "\r"); $string = str_replace($order, ' ', $string); $string = preg_replace('/\\s{2,}/ui', ' ', $string); database_connect(IL_DATABASE_PATH, 'fulltext'); $file_query = $dbHandle->quote($id); $fulltext_query = $dbHandle->quote($string); $dbHandle->beginTransaction(); $dbHandle->exec("DELETE FROM full_text WHERE fileID={$file_query}"); $dbHandle->exec("INSERT INTO full_text (fileID,full_text) VALUES ({$file_query},{$fulltext_query})"); $dbHandle->commit();
echo '<div style="padding:8px 8px"><input type="submit" name="submit" value="Delete selected"><br>' . '<b>Warning! This action cannot be undone. Inspect the items you want to delete for supplementary files and important notes.</b></div>'; } else { echo '<div style="padding:4px 8px">No duplicates found.</div>'; } echo '</form>'; } elseif (isset($_GET['find_duplicates']) && $_GET['find_duplicates'] == 'hash') { ini_set('max_execution_time', 900); echo '<div class="details alternating_row" style="font-weight:bold">Possible Duplicates:</div>' . '<div style="padding:4px 8px"><input type="checkbox" style="visibility:hidden">' . '<span style="display:inline-block;margin-left:1em;width:4em">ID</span><span style="margin-left:1em">File hash</span></div>'; echo '<form action="duplicates.php" method="POST">'; database_connect(IL_DATABASE_PATH, 'library'); //CALCULATE MD5 HASH FOR EACH PDF IF EMPTY $result = $dbHandle->query("SELECT id,file,filehash FROM library"); $hashes = array(); while ($row = $result->fetch(PDO::FETCH_NAMED)) { if (empty($row['filehash']) && is_file(IL_PDF_PATH . DIRECTORY_SEPARATOR . get_subfolder($row['file']) . DIRECTORY_SEPARATOR . $row['file'])) { $hashes[$row['id']] = md5_file(IL_PDF_PATH . DIRECTORY_SEPARATOR . get_subfolder($row['file']) . DIRECTORY_SEPARATOR . $row['file']); } } //SAVE NEW HASHES $dbHandle->beginTransaction(); while (list($id, $hash) = each($hashes)) { $hash = $dbHandle->quote($hash); $id = $dbHandle->quote($id); $dbHandle->exec("UPDATE library SET filehash=" . $hash . " WHERE id=" . $id); } $dbHandle->commit(); $result = null; $row = null; $result = $dbHandle->query("SELECT id,filehash FROM library" . " WHERE filehash IN (SELECT filehash FROM library WHERE filehash!='' GROUP BY filehash HAVING count(*) > 1)" . " ORDER BY filehash"); $dbHandle = null; $is_duplicate = false;
<?php include_once 'data.php'; include_once 'functions.php'; $text = ''; $filename = sprintf('%05d', intval($_GET['file'])) . '.pdf'; if (!empty($_GET['file'])) { database_connect(IL_DATABASE_PATH, 'fulltext'); $query = $dbHandle->quote($_GET['file']); $result = $dbHandle->query("SELECT full_text FROM full_text WHERE fileID={$query}"); $dbHandle = null; $text = $result->fetchColumn(); } if (!empty($text)) { $text_size = round(strlen(utf8_decode($text)) / 1024, 1); $pdf_size = round(filesize(IL_PDF_PATH . DIRECTORY_SEPARATOR . get_subfolder($filename) . DIRECTORY_SEPARATOR . $filename) / 1024, 1); } else { print '<h3>No text found.</h3>'; die; } include_once 'index.inc.php'; ?> <body style="padding:20px"> <h3>Extracted text from the file <?php print $filename; ?> :</h3> <div class="ui-corner-all alternating_row" style="float:left;width:75%;text-align:justify;padding:10px;text-shadow:none"> <?php print htmlspecialchars($text); ?>
<?php include_once 'data.php'; include_once 'functions.php'; session_write_close(); if (!empty($_GET['file'])) { $pdf_path = IL_PDF_PATH . DIRECTORY_SEPARATOR . get_subfolder($_GET['file']); database_connect(IL_DATABASE_PATH, 'library'); $file_query = $dbHandle->quote(intval($_GET['file'])); $result = $dbHandle->query("SELECT file FROM library WHERE id={$file_query} LIMIT 1"); $filename = $result->fetchColumn(); $dbHandle = null; ########## extract text from pdf ########## if (is_file($pdf_path . DIRECTORY_SEPARATOR . $filename)) { system(select_pdftotext() . ' -enc UTF-8 "' . $pdf_path . DIRECTORY_SEPARATOR . $filename . '" "' . IL_TEMP_PATH . DIRECTORY_SEPARATOR . $filename . '.txt"', $ret); if (is_file(IL_TEMP_PATH . DIRECTORY_SEPARATOR . $filename . ".txt")) { $string = trim(file_get_contents(IL_TEMP_PATH . DIRECTORY_SEPARATOR . $filename . ".txt")); unlink(IL_TEMP_PATH . DIRECTORY_SEPARATOR . $filename . ".txt"); $string = preg_replace('/[^\\x{0009}\\x{000a}\\x{000d}\\x{0020}-\\x{D7FF}\\x{E000}-\\x{FFFD}]+/u', ' ', $string); $string = trim($string); if (!empty($string)) { $order = array("\r\n", "\n", "\r"); $string = str_replace($order, ' ', $string); $string = preg_replace('/\\s{2,}/ui', ' ', $string); $output = null; database_connect(IL_DATABASE_PATH, 'fulltext'); $file_query = $dbHandle->quote(intval($_GET['file'])); $fulltext_query = $dbHandle->quote($string); $dbHandle->beginTransaction(); $dbHandle->exec("DELETE FROM full_text WHERE fileID={$file_query}"); $output = $dbHandle->exec("INSERT INTO full_text (fileID,full_text) VALUES ({$file_query},{$fulltext_query})");
$string = preg_replace('/\\s{2,}/', " ", $string); database_connect(IL_DATABASE_PATH, 'fulltext'); $file_query = $dbHandle->quote($id); $fulltext_query = $dbHandle->quote($string); $dbHandle->beginTransaction(); $dbHandle->exec("DELETE FROM full_text WHERE fileID={$file_query}"); $insert = $dbHandle->exec("INSERT INTO full_text (fileID,full_text) VALUES ({$file_query},{$fulltext_query})"); $dbHandle->commit(); $dbHandle = null; $unpack_dir = IL_TEMP_PATH . DIRECTORY_SEPARATOR . $new_file; mkdir($unpack_dir); exec(select_pdfdetach() . ' -saveall -o "' . $unpack_dir . '" "' . IL_PDF_PATH . DIRECTORY_SEPARATOR . get_subfolder($new_file) . DIRECTORY_SEPARATOR . $new_file . '"'); $unpacked_files = scandir($unpack_dir); foreach ($unpacked_files as $unpacked_file) { if (is_file($unpack_dir . DIRECTORY_SEPARATOR . $unpacked_file)) { rename($unpack_dir . DIRECTORY_SEPARATOR . $unpacked_file, IL_SUPPLEMENT_PATH . DIRECTORY_SEPARATOR . get_subfolder($new_file) . DIRECTORY_SEPARATOR . sprintf("%05d", intval($new_file)) . $unpacked_file); } } rmdir($unpack_dir); $put = basename($orig_filename) . ": Recorded.<br>"; } } } } else { $put = basename($orig_filename) . ": Not readable.<br>"; } } ####if ########## ANALYZE ########## if (rand(1, 1000) == 500) { database_connect(IL_DATABASE_PATH, 'library');
<?php include_once 'data.php'; include_once 'functions.php'; $id = sprintf("%05d", $_GET['id']); $output_arr = array(); $directory = IL_SUPPLEMENT_PATH . DIRECTORY_SEPARATOR . get_subfolder($id); if (is_dir($directory)) { $files = glob($directory . DIRECTORY_SEPARATOR . $id . '*'); if (is_array($files)) { foreach ($files as $file) { $file = basename($file); $isimage = false; $image_array = array(); $image_array = @getimagesize(IL_SUPPLEMENT_PATH . DIRECTORY_SEPARATOR . get_subfolder($file) . DIRECTORY_SEPARATOR . $file); $image_mime = $image_array['mime']; if ($image_mime == 'image/jpeg' || $image_mime == 'image/gif' || $image_mime == 'image/png') { $isimage = true; } if ($isimage) { $output_arr[] = array('title' => substr($file, 5), 'value' => 'attachment.php?attachment=' . $file); } } } } echo json_encode($output_arr);
} else { // SUPPLEMENTARY FILE LIST $integer = sprintf("%05d", intval($paper['file'])); $files_to_display = glob(IL_SUPPLEMENT_PATH . DIRECTORY_SEPARATOR . get_subfolder($integer) . DIRECTORY_SEPARATOR . $integer . '*'); $url_filename = '<div style="font-size:0.8em">No supplementary files.</div>'; $url_filenames = array(); if (is_array($files_to_display)) { foreach ($files_to_display as $supplementary_file) { $url_filenames[] = '<li><a style="font-size:0.85em" href="' . htmlspecialchars('attachment.php?attachment=' . basename($supplementary_file)) . '" target="_blank">' . substr(basename($supplementary_file), 5) . '</a></li>'; } $url_filename = join(PHP_EOL, $url_filenames); $url_filename = '<ul data-role="listview">' . $url_filename . '</ul>'; } // TOP ROW - PDF BUTTON, CLIPBOARD BUTTON print '<table style="width:100%"><tr><td style="width:50%">'; if (is_file(IL_PDF_PATH . DIRECTORY_SEPARATOR . get_subfolder($integer) . DIRECTORY_SEPARATOR . $paper['file']) && isset($_SESSION['auth'])) { print '<a class="ui-btn ui-mini ui-corner-all" href="' . htmlspecialchars('pdfcontroller.php?downloadpdf=1&file=' . urlencode($paper['file']) . '#pagemode=none&scrollbar=1&navpanes=0&toolbar=1&statusbar=0&page=1&view=FitH,0') . '" target="_blank"> PDF</a>'; } else { print '<button class="ui-btn ui-mini ui-corner-all" disabled>PDF</button>'; } print '</td><td>'; print '<form><input class="update_clipboard" name="checkbox-clipboard" id="checkbox-clipboard-' . $paper['id'] . '" type="checkbox" data-mini="true"'; if ($paper['id'] == $clip_files) { print ' checked="checked"'; } print '><label for="checkbox-clipboard-' . $paper['id'] . '">Clipboard</label></form>'; print '</td></tr></table>'; // SECOND ROW - TITLE, JOURNAL, YEAR, AUTHOR print PHP_EOL . '<div class="ui-body ui-body-a" style="margin:0.75em 0;font-size:0.9em">' . $paper['title'] . '<br><span style="font-weight:normal">';
<div class="file-grid" style="border-bottom:0"> <div class="ui-dialog-titlebar ui-state-default" style="border:0;border-radius:0">Graphical Abstract</div> <div class="separator" style="margin:0"></div> <div class="alternating_row" style="height:188px;overflow:auto">'; if (isset($_SESSION['auth']) && is_file(graphical_abstract($paper['file']))) { echo '<a href="' . htmlspecialchars('attachment.php?mode=inline&attachment=' . basename(graphical_abstract($paper['file']))) . '" target="_blank"><img src="' . htmlspecialchars('attachment.php?mode=inline&attachment=' . basename(graphical_abstract($paper['file']))) . '" style="width:100%"></a>'; } print '</div> </div> <div class="file-grid" style="border-bottom:0"> <div class="ui-dialog-titlebar ui-state-default" style="border:0;border-radius:0;position:relative"> Files </div> <div class="separator" style="margin:0"></div> <div class="alternating_row" style="padding:4px 10px;overflow:auto;height:180px">'; if (is_file(IL_PDF_PATH . DIRECTORY_SEPARATOR . get_subfolder($paper['file']) . DIRECTORY_SEPARATOR . $paper['file'])) { print '<a href="' . htmlspecialchars('pdfcontroller.php?downloadpdf=1&file=' . $paper['file']) . '" target="_blank">' . '<i class="fa fa-external-link" style="color:inherit;margin-right:0.5em"></i></a>' . '<a href="' . htmlspecialchars('pdfcontroller.php?downloadpdf=1&mode=download&file=' . $paper['file']) . '">' . $paper['file'] . '</a><br>'; } print $url_filename . '</div> </div> <div class="file-grid" style="border-right:0;width:33.33%;border-bottom:0"> <div class="ui-dialog-titlebar ui-state-default" style="border:0;border-radius:0">IDs</div> <div class="separator" style="margin:0"></div> <div class="alternating_row" style="padding:4px 10px;overflow:auto;height:180px">'; print "<u>I, Librarian ID:</u> <a href=\"stable.php?id={$paper['id']}\" target=\"_blank\">" . $paper['id'] . " (stable link)</a>"; $uid_array = explode("|", $paper['uid']); foreach ($uid_array as $uid) { $uids[] = $uid; } print "<br><u>External IDs:</u> " . htmlspecialchars(implode(", ", $uids)); print '<br><u>DOI:</u> <span id="file-doi">' . htmlspecialchars($paper['doi']) . '</span>';
<a href="' . htmlspecialchars('attachment.php?attachment=' . basename($gr_abs[0])) . '">' . $url_filename . '</a> <a href="' . htmlspecialchars('attachment.php?mode=inline&attachment=' . basename($gr_abs[0])) . '" target="_blank"> <i class="fa fa-external-link" style="color:inherit;margin-left:0.5em"></i></a> </td> <td style="height:22px;line-height:22px"> <div class="ui-state-default file-remove" style="float:right;padding:1px 4px"><i class="fa fa-trash-o"></i> Remove</div> </td> </tr> </table>'; } ?> <div style="width:100%;margin-top:1em;border-bottom:1px solid #cfcecc;font-weight:bold">Supplementary files:</div> <table cellspacing=0 style="width:100%"> <tr><td></td><td></td><td></td></tr> <?php $files_to_display = glob(IL_SUPPLEMENT_PATH . DIRECTORY_SEPARATOR . get_subfolder($integer) . DIRECTORY_SEPARATOR . $integer . '*'); if (is_array($files_to_display)) { foreach ($files_to_display as $supplementary_file) { $url_filename = substr(basename($supplementary_file), 5); if (strstr($url_filename, 'graphical_abstract') === false) { //TODO: REWRITE USING FILEINFO FUNCTION $extension = pathinfo($supplementary_file, PATHINFO_EXTENSION); $isimage = null; if ($extension == 'jpg' || $extension == 'jpeg' || $extension == 'gif' || $extension == 'png') { $image_array = array(); $image_array = @getimagesize($supplementary_file); $image_mime = $image_array['mime']; if ($image_mime == 'image/jpeg' || $image_mime == 'image/gif' || $image_mime == 'image/png') { $isimage = true; } }
<?php include_once 'data.php'; include_once 'functions.php'; include_once 'pdfclass.php'; session_write_close(); // Files $file = preg_replace('/^0-9\\.pdf/', '', $_GET['file']); $image = IL_IMAGE_PATH . DIRECTORY_SEPARATOR . $file . '.1.jpg'; $icon = IL_TEMP_PATH . DIRECTORY_SEPARATOR . $file . '.1.icon.jpg'; // Paths $pdf_path = IL_PDF_PATH . DIRECTORY_SEPARATOR . get_subfolder($file); //CACHE THIS FILE $seconds_to_cache = 604800; $ts = gmdate("D, d M Y H:i:s", time() + $seconds_to_cache) . " GMT"; header("Expires: {$ts}"); header("Pragma: private"); header("Cache-Control: max-age={$seconds_to_cache}"); header("Cache-Control: private"); header('Last-Modified: ' . gmdate(DATE_RFC1123, filemtime($pdf_path . DIRECTORY_SEPARATOR . $file))); // Content type header('Content-Type: image/jpeg'); header("Content-Disposition: inline"); // Output from cache if (is_readable($icon) && filemtime($pdf_path . DIRECTORY_SEPARATOR . $file) < filemtime($icon)) { ob_clean(); flush(); readfile($icon); die; } // Make big image if not found
function mobile_show_search_results($result, $clip_files) { $i = 0; $display = $_SESSION['display']; if ($display == 'icons') { print '<table id="icon-container"> <tr><td>'; } else { print '<div data-role="collapsible-set" data-inset="false" data-theme="a" data-content-theme="a">'; } while (list($key, $paper) = each($result)) { if (!empty($paper['authors'])) { $array = array(); $new_authors = array(); $array = explode(';', $paper['authors']); $array = array_filter($array); if (!empty($array)) { foreach ($array as $author) { $array2 = explode(',', $author); $last = trim($array2[0]); $last = substr($array2[0], 3, -1); $first = ''; if (isset($array2[1])) { $first = trim($array2[1]); $first = substr($array2[1], 3, -1); } $new_authors[] = $last . ', ' . $first; } $paper['authors'] = join('; ', $new_authors); } } $paper['authors'] = htmlspecialchars($paper['authors']); $paper['title'] = htmlspecialchars($paper['title']); $paper['year'] = htmlspecialchars($paper['year']); $first_author = ' '; $auth_arr = explode(';', $paper['authors']); $auth_arr2 = explode(',', $auth_arr[0]); if (!empty($auth_arr2[0])) { $first_author = $auth_arr2[0]; } $etal = ''; if (count($auth_arr) > 1) { $etal = ', et al.'; } #######new date######### $date = ''; if (!empty($paper['year'])) { $date_array = array(); $date_array = explode('-', $paper['year']); if (count($date_array) == 1) { $date = $paper['year']; } else { if (empty($date_array[0])) { $date_array[0] = '1969'; } if (empty($date_array[1])) { $date_array[1] = '01'; } if (empty($date_array[2])) { $date_array[2] = '01'; } $date = date('Y M j', mktime(0, 0, 0, $date_array[1], $date_array[2], $date_array[0])); } } $i = $i + 1; if ($display == 'icons') { if (!extension_loaded('gd')) { die('<p> Error! Icon view requires GD extension and Ghostscript.</p>'); } print '<div class="thumb-items">'; if (is_readable(IL_PDF_PATH . DIRECTORY_SEPARATOR . get_subfolder($paper['file']) . DIRECTORY_SEPARATOR . $paper['file'])) { print '<a href="' . htmlspecialchars('pdfcontroller.php?downloadpdf=1&file=' . urlencode($paper['file']) . '#pagemode=none&scrollbar=1&navpanes=0&toolbar=1&statusbar=0&page=1&view=FitH,0&zoom=page-width') . '" target="_blank" style="display:block;text-decoration:none">'; } print '<div class="thumb-items-top"><div class="thumb-titles"><div>' . $paper['title'] . '<br>'; if (!empty($paper['year'])) { print '(' . substr($paper['year'], 0, 4) . ')'; } print '</div></div>'; if (is_readable(IL_PDF_PATH . DIRECTORY_SEPARATOR . get_subfolder($paper['file']) . DIRECTORY_SEPARATOR . $paper['file'])) { print '</a><a href="' . htmlspecialchars('pdfcontroller.php?downloadpdf=1&file=' . urlencode($paper['file']) . '#pagemode=none&scrollbar=1&navpanes=0&toolbar=1&statusbar=0&page=1&view=FitH,0&zoom=page-width') . '" target="_blank" style="display:block">'; print '<img src="icon.php?file=' . $paper['file'] . '" style="width:100%;border:0" alt="Loading PDF..."></a>'; } else { print '<div style="text-align:center;margin-top:90px;font-size:18px;color:#b5b6b8">No PDF</div>'; } print '</div>'; print '<form><input class="update_clipboard" name="checkbox-clipboard" id="checkbox-clipboard-' . $paper['id'] . '" type="checkbox" data-mini="false"'; if (in_array($paper['id'], $clip_files)) { print ' checked="checked"'; } print '><label for="checkbox-clipboard-' . $paper['id'] . '"><span style="font-size:0.8em">Clipboard</span></label></form>'; print PHP_EOL . '</div></div>'; } else { print PHP_EOL . '<div data-role="collapsible">'; print PHP_EOL . '<h4 class="accordeon" data-fileid="' . $paper['id'] . '">' . $paper['title'] . '</h4>'; print '<div style="padding:0 0px"></div></div>'; } } if ($display == 'icons') { print '</td></tr></table>'; } else { print '</div>'; } }
} else { $error = "This is not a PDF."; } //RECORD FILE HASH FOR DUPLICATE DETECTION if (!empty($hash)) { database_connect(IL_DATABASE_PATH, 'library'); $hash = $dbHandle->quote($hash); $file = $dbHandle->quote($_POST['filename']); $dbHandle->exec('UPDATE library SET filehash=' . $hash . ' WHERE file=' . $file); $dbHandle = null; } ########## extract text from pdf ########## if (!isset($error)) { $filename = $_POST['filename']; if (is_file(IL_PDF_PATH . DIRECTORY_SEPARATOR . get_subfolder($filename) . DIRECTORY_SEPARATOR . $filename)) { system(select_pdftotext() . ' -enc UTF-8 "' . IL_PDF_PATH . DIRECTORY_SEPARATOR . get_subfolder($filename) . DIRECTORY_SEPARATOR . $filename . '" "' . IL_TEMP_PATH . DIRECTORY_SEPARATOR . 'lib_' . session_id() . DIRECTORY_SEPARATOR . $filename . '.txt"', $ret); if (is_file(IL_TEMP_PATH . DIRECTORY_SEPARATOR . 'lib_' . session_id() . DIRECTORY_SEPARATOR . $filename . ".txt")) { $string = file_get_contents(IL_TEMP_PATH . DIRECTORY_SEPARATOR . 'lib_' . session_id() . DIRECTORY_SEPARATOR . $filename . ".txt"); unlink(IL_TEMP_PATH . DIRECTORY_SEPARATOR . 'lib_' . session_id() . DIRECTORY_SEPARATOR . $filename . ".txt"); if (!empty($string)) { $string = preg_replace('/[^\\x{0009}\\x{000a}\\x{000d}\\x{0020}-\\x{D7FF}\\x{E000}-\\x{FFFD}]+/u', ' ', $string); $order = array("\r\n", "\n", "\r"); $string = str_replace($order, ' ', $string); $string = preg_replace('/\\s{2,}/ui', ' ', $string); $output = null; database_connect(IL_DATABASE_PATH, 'fulltext'); $file_query = $dbHandle->quote(intval($_POST['file'])); $fulltext_query = $dbHandle->quote($string); $dbHandle->beginTransaction(); $dbHandle->exec("DELETE FROM full_text WHERE fileID={$file_query}"); $output = $dbHandle->exec("INSERT INTO full_text (fileID,full_text) VALUES ({$file_query},{$fulltext_query})");
<?php include_once 'data.php'; include_once 'functions.php'; session_write_close(); database_connect(IL_DATABASE_PATH, 'library'); $file_query = $dbHandle->quote(intval($_GET['file'])); $result = $dbHandle->query("SELECT file FROM library WHERE id={$file_query} LIMIT 1"); $file = $result->fetchColumn(); $dbHandle = null; if (is_file(IL_PDF_PATH . get_subfolder($file) . DIRECTORY_SEPARATOR . $file)) { exec(select_ghostscript() . ' -dSAFER -dBATCH -dNOPAUSE -sDEVICE=bmp16m -r300 -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -dDOINTERPOLATE -o "' . IL_TEMP_PATH . DIRECTORY_SEPARATOR . $file . '.%03d.bmp" "' . IL_PDF_PATH . DIRECTORY_SEPARATOR . get_subfolder($file) . DIRECTORY_SEPARATOR . $file . '"'); $file_arr = glob(IL_TEMP_PATH . DIRECTORY_SEPARATOR . '*.bmp'); if (is_array($file_arr)) { set_time_limit(600); for ($i = 0; $i < count($file_arr); $i++) { exec(select_tesseract() . ' "' . $file_arr[$i] . '" "' . IL_TEMP_PATH . DIRECTORY_SEPARATOR . $file . '.' . $i . '"'); if (is_file(IL_TEMP_PATH . DIRECTORY_SEPARATOR . $file . '.' . $i . '.txt')) { file_put_contents(IL_TEMP_PATH . DIRECTORY_SEPARATOR . $file . 'final.txt', file_get_contents(IL_TEMP_PATH . DIRECTORY_SEPARATOR . $file . '.' . $i . '.txt'), FILE_APPEND); unlink(IL_TEMP_PATH . DIRECTORY_SEPARATOR . $file . '.' . $i . '.txt'); unlink($file_arr[$i]); } else { die('OCR software not functional.'); } } $string = file_get_contents(IL_TEMP_PATH . DIRECTORY_SEPARATOR . $file . 'final.txt'); unlink(IL_TEMP_PATH . DIRECTORY_SEPARATOR . $file . 'final.txt'); $string = preg_replace('/[^\\x{0009}\\x{000a}\\x{000d}\\x{0020}-\\x{D7FF}\\x{E000}-\\x{FFFD}]+/u', ' ', $string); $string = trim($string); if (!empty($string)) { $order = array("\r\n", "\n", "\r");
<?php include_once '../data.php'; include_once '../functions.php'; session_write_close(); $path = IL_SUPPLEMENT_PATH . DIRECTORY_SEPARATOR . get_subfolder($_GET['attachment']) . DIRECTORY_SEPARATOR; if (!empty($_GET['attachment']) && is_file($path . $_GET['attachment']) && strstr($_GET['attachment'], "\\") === FALSE && strstr($_GET['attachment'], "/") === FALSE) { $filename = substr(urldecode($_GET['attachment']), 5); $type = 'application/octet-stream'; if (extension_loaded('fileinfo')) { $finfo = new finfo(FILEINFO_MIME); $type = $finfo->file($path . $_GET['attachment']); } header("Content-Type: " . $type); header("Content-Disposition: attachment; filename=\"{$filename}\""); header("Pragma: no-cache"); header("Expires: 0"); header('Content-Length: ' . filesize($path . $_GET['attachment'])); ob_clean(); flush(); readfile($path . $_GET['attachment']); }
$ris_name = array_search($key, $ris_translation); if ($ris_name && !empty($value)) { $columns[] = $ris_name . $value; } } reset($add_item); $type = convert_type($item['reference_type'], 'ilib', 'ris'); $line = join(PHP_EOL, $columns); $paper .= 'TY - ' . $type . PHP_EOL; $paper .= $line . PHP_EOL; if ($hosted == false && is_file(IL_PDF_PATH . DIRECTORY_SEPARATOR . get_subfolder($item['file']) . DIRECTORY_SEPARATOR . $item['file'])) { $paper .= 'L1 - file://'; if (substr(strtoupper(PHP_OS), 0, 3) == 'WIN') { $paper .= '/'; } $paper .= IL_PDF_PATH . DIRECTORY_SEPARATOR . get_subfolder($item['file']) . DIRECTORY_SEPARATOR . $item['file'] . PHP_EOL; } $paper .= 'ER - ' . PHP_EOL . PHP_EOL; $columns = null; } } if ($_GET['format'] == 'citations') { // encode items in JSON $content = json_encode($json, JSON_HEX_APOS); $content = str_replace('"', '\\"', $content); // fetch citation style $dbHandle = database_connect(__DIR__, 'styles'); $title_q = $dbHandle->quote(strtolower($_GET['citation-style'])); $result = $dbHandle->query('SELECT style FROM styles WHERE title=' . $title_q); $style = $result->fetchColumn(); if (empty($style)) {