Пример #1
0
 function validateData()
 {
     $loc = new Localize(OBIB_LOCALE, "classes");
     $valid = true;
     if ($this->_isRequired and $this->_fieldData == "") {
         $valid = false;
         $this->_fieldDataError = $loc->getText("biblioFieldError1");
     }
     if ($this->_tag == "") {
         $valid = false;
         $this->_tagError = $loc->getText("biblioFieldError1");
     } else {
         if (!is_numeric($this->_tag)) {
             $valid = false;
             $this->_tagError = $loc->getText("biblioFieldError2");
         }
     }
     if ($this->_subfieldCd == "") {
         $valid = false;
         $this->_subfieldCdError = $loc->getText("biblioFieldError1");
     }
     // Check for image
     if ($this->getTag() == "902" && $this->getSubfieldCd() == "a") {
         $fieldData = $this->getFieldData();
         if (!empty($fieldData)) {
             if ($fieldData['uselookup'] === true) {
                 // Override with cover lookup
                 $isbn = $fieldData['isbn'];
                 require_once "BiblioCoverQuery.php";
                 $cq = new BiblioCoverQuery();
                 $path = $cq->lookup($isbn, "large");
                 if (!$path) {
                     $this->_fieldDataError = $loc->getText("biblioFieldErrorCoverLookupFailed");
                     $valid = false;
                 } else {
                     $filename = $cq->save($path, 0);
                     $this->setFieldData($filename);
                 }
             } else {
                 $index = $this->getTag() . $this->getSubfieldCd();
                 if (!empty($fieldData["tmp_name"][$index])) {
                     if ($info = getimagesize($fieldData["tmp_name"][$index])) {
                         $filename = $fieldData["name"][$index];
                         $filename_parts = explode(".", $filename);
                         unset($filename_parts[count($filename_parts) - 1]);
                         $filename = implode("-", $filename_parts);
                         $allow_types = array('image/jpeg', 'image/png', 'image/gif');
                         // If file type is allowed
                         if (in_array($info["mime"], $allow_types)) {
                             // Create directory when necessary, raise error when failed to create "not exist" one.
                             if (!(is_dir('../' . COVER_PATH) || is_dir('../' . COVER_PATH_TMP))) {
                                 $dir_error = FALSE;
                                 if (is_dir('../' . dirname(COVER_PATH))) {
                                     // Create new one.
                                     $cover_path = @mkdir('../' . COVER_PATH, 0777);
                                     $tmp_path = @mkdir('../' . COVER_PATH_TMP, 0777);
                                     if (!$cover_path) {
                                         if (is_dir('../' . COVER_PATH)) {
                                             if (decoct(fileperms('../' . COVER_PATH)) != 0777) {
                                                 $force_chmod = @chmod('../' . COVER_PATH, 0777);
                                                 if (!$force_chmod) {
                                                     $dir_error = TRUE;
                                                 }
                                             }
                                         } else {
                                             $dir_error = TRUE;
                                         }
                                     }
                                     if (!$tmp_path) {
                                         if (is_dir('../' . COVER_PATH_TMP)) {
                                             if (decoct(fileperms('../' . COVER_PATH_TMP)) != 0777) {
                                                 $force_chmod = @chmod('../' . COVER_PATH_TMP, 0777);
                                                 if (!$force_chmod) {
                                                     $dir_error = TRUE;
                                                 }
                                             }
                                         } else {
                                             $dir_error = TRUE;
                                         }
                                     }
                                     if ($dir_error) {
                                         print_r('<span style="color: red"><strong>Error:</strong> Failed to save book cover! please set chmod 777 to /media directory.</span><br />');
                                         return false;
                                     }
                                 }
                             }
                             $ext = image_type_to_extension($info[2]);
                             $tmp = md5($filename . session_id() . time());
                             $filename = $filename . "_" . substr($tmp, strlen($tmp) - 7, strlen($tmp)) . $ext;
                             $filepath = "../" . COVER_PATH . "/{$filename}";
                             copy($fieldData["tmp_name"][$index], $filepath);
                             make_thumbnail($filepath, array('height' => 160));
                             $this->setFieldData($filename);
                         } else {
                             $valid = false;
                             $this->_fieldDataError = $loc->getText("biblioFieldErrorPictureType");
                         }
                     } else {
                         $valid = false;
                         $this->_fieldDataError = $loc->getText("biblioFieldErrorPictureLoadFailed");
                     }
                 }
             }
         } else {
         }
     } else {
         if ($this->getTag() == "20" && $this->getSubfieldCd() == "a") {
             require_once "../classes/BiblioQuery.php";
             $biblio = new BiblioQuery();
             $existBibId = $biblio->ISBNExists($this->getFieldData());
             if ($existBibId && $this->_bibid != $existBibId) {
                 $valid = false;
                 $this->_fieldDataError = $loc->getText("biblioFieldErrorDuplicatedISBN") . ' <a href="../shared/biblio_view.php?bibid=' . $existBibId . '&tab=cataloging">' . $loc->getText("biblioFieldViewExistingISBN") . '</a>';
             }
         }
     }
     unset($loc);
     return $valid;
 }
Пример #2
0
 function saveResults($results)
 {
     if (!is_array($results)) {
         return false;
     }
     foreach ($results as $isbn => $info) {
         if (isset($info['data'])) {
             $this->_formatResults($info['data']);
             $bib = $this->_getBiblio($info['data']);
             $insert_bib[$isbn]['bibid'] = 0 + $this->_insertBiblio($bib);
             if ($insert_bib[$isbn]['bibid'] > 0) {
                 $amount = 0 + $info['amount'];
                 if ($amount < 1) {
                     $amount = 1;
                 }
                 for ($i = 0; $i < $amount; $i++) {
                     $this->addCopy($insert_bib[$isbn]['bibid']);
                 }
                 // Cover lookup
                 require_once "BiblioCoverQuery.php";
                 $cq = new BiblioCoverQuery();
                 $img_path = $cq->lookup($isbn);
                 if ($img_path) {
                     if ($cq->save($img_path, $insert_bib[$isbn]['bibid'])) {
                         $this->setLookupStatus('cover', $isbn);
                     } else {
                         $this->setLookupStatus('publish', $isbn);
                     }
                 } else {
                     $this->setLookupStatus('publish', $isbn);
                 }
             }
         }
     }
 }
Пример #3
0
<?php

require_once '../classes/BiblioCoverQuery.php';
$cq = new BiblioCoverQuery();
$path = $cq->lookup($_GET['isbn']);
echo $path ? $path : $cq->getLookupError();
die;