public function setUp()
 {
     parent::setUp();
     $pluginHelper = new Omeka_Test_Helper_Plugin();
     $pluginHelper->setUp(self::PLUGIN_NAME);
     define('TEST_FILES_DIR', ARCHIVE_REPERTORY_DIR . '/tests/suite/_files');
     // Add constraints if derivatives have been added in the config file.
     $fileDerivatives = Zend_Registry::get('bootstrap')->getResource('Config')->fileDerivatives;
     if (!empty($fileDerivatives) && !empty($fileDerivatives->paths)) {
         foreach ($fileDerivatives->paths->toArray() as $type => $path) {
             set_option($type . '_constraint', 1);
         }
     }
     // Prepare config and set a test temporary storage in registry.
     $config = new Omeka_Test_Resource_Config();
     $configIni = $config->init();
     if (isset($configIni->paths->imagemagick)) {
         $this->convertDir = $configIni->paths->imagemagick;
     } else {
         $this->convertDir = dirname(`which convert`);
     }
     $storage = Zend_Registry::get('storage');
     $adapter = $storage->getAdapter();
     $adapterOptions = $adapter->getOptions();
     $this->_storagePath = $adapterOptions['localDir'];
     // Set default strategy for the creation of derivative files.
     $this->strategy = new Omeka_File_Derivative_Strategy_ExternalImageMagick();
     $this->strategy->setOptions(array('path_to_convert' => $this->convertDir));
     $this->creator = new Omeka_File_Derivative_Creator();
     $this->creator->setStrategy($this->strategy);
     Zend_Registry::set('file_derivative_creator', $this->creator);
     // Create one item on which attach files.
     $this->item = insert_item(array('public' => true));
     set_option('disable_default_file_validation', 1);
 }
예제 #2
0
 protected function importItem($collectionObject)
 {
     $itemMetadataArray = array();
     $itemMetadataArray = $this->fetchItemMetadata($collectionObject, $itemMetadataArray);
     $item = insert_item($metadata, $itemMetadataArray, $fileMetadataArray);
     $importRecord = new ImportRecord();
     $itemporRecord->csid = $whatever;
     $importRecord->item_id = $item->id;
     $importRecord->save();
 }
 /**
  * Search queries should match indexed elements.
  */
 public function testSearchIndexedElements()
 {
     $this->fieldTable->setElementIndexed('Dublin Core', 'Description');
     $item1 = insert_item(array('public' => true), array('Dublin Core' => array('Title' => array(array('text' => 'Item 1', 'html' => false)), 'Description' => array(array('text' => 'desc1', 'html' => false)))));
     $item2 = insert_item(array('public' => true), array('Dublin Core' => array('Title' => array(array('text' => 'Item 2', 'html' => false)), 'Description' => array(array('text' => 'desc2', 'html' => false)))));
     $_GET['q'] = 'desc1';
     $this->dispatch('solr-search');
     // Should match item 1, but not item 2.
     $this->_assertResultLink(record_url($item1), 'Item 1');
     $this->_assertNotResultLink(record_url($item2));
 }
예제 #4
0
 public function testCanInsertItem()
 {
     $db = $this->db;
     // Insert an item and verify with a second query.
     $item = insert_item(array('public' => true), array('Dublin Core' => array('Title' => array(array('text' => 'foobar', 'html' => true)))));
     $sql = "SELECT public FROM {$db->Item} WHERE id = {$item->id}";
     $row = $db->fetchRow($sql);
     $this->assertEquals(array('public' => 1), $row);
     // Verify that element texts are inserted correctly into the database.
     $sql = "SELECT COUNT(id) FROM {$db->ElementText} WHERE html = 1 AND " . "text = 'foobar' AND record_id = {$item->id}";
     $this->assertEquals(1, $db->fetchOne($sql));
     release_object($item);
 }
예제 #5
0
 public function doImport()
 {
     _log("Feed Import Started at " . date('c'));
     $db = get_db();
     $hasError = false;
     require_once PLUGIN_DIR . "/FeedImporter/libraries/SimplePie/simplepie.inc";
     $this->fi_feed = $db->getTable('FeedImporter_Feed')->find($this->feed_id);
     $this->fi_tags = $db->getTable('FeedImporter_TagConfig')->findByFeedId($this->feed_id, true);
     if ($this->fi_feed->map_authors) {
         $this->authorsMap = unserialize($this->fi_feed->authors_map);
     }
     $sp_feed = new SimplePie();
     $sp_feed->enable_cache(false);
     $sp_feed->set_feed_url($this->fi_feed->feed_url);
     $sp_feed->handle_content_type();
     // Run SimplePie.
     $sp_feed->init();
     if ($sp_feed->error()) {
         $hasError = true;
         $this->status = self::STATUS_FEED_ERRORS;
         $this->sp_error = $sp_feed->error();
         $this->save();
         return false;
     }
     if (!$hasError) {
         foreach ($sp_feed->get_items() as $sp_item) {
             if ($this->_needsImport($sp_item)) {
                 $this->processItemTags($sp_item);
                 $metadataArray = $this->buildFeedItemMetadata($sp_item);
                 $elementTextsArray = $this->buildFeedItemElementTexts($sp_item);
                 $newOmekaItem = insert_item($metadataArray, $elementTextsArray);
                 $newImportedItem = new FeedImporter_ImportedItem();
                 $newImportedItem->item_id = $newOmekaItem->id;
                 $newImportedItem->feed_id = $this->fi_feed->id;
                 $newImportedItem->import_id = $this->id;
                 $newImportedItem->sp_id = $sp_item->get_id();
                 $newImportedItem->save();
                 $this->_buildFeedItemItemTypeData($sp_item, $newOmekaItem);
                 $license = $sp_item->get_link(0, 'license');
                 if ($this->fi_feed->import_media && !empty($license)) {
                     $this->_doFileImportForItem($sp_item, $newOmekaItem);
                 }
             }
         }
     }
     $this->status = self::STATUS_COMPLETED_IMPORT;
     $this->save();
     return true;
 }
 /**
  * When a new private item is added, it should not be indexed in Solr.
  */
 public function testNoDisplayPrivate()
 {
     $opt = get_option('solr_search_display_private_items');
     set_option('solr_search_display_private_items', '0');
     try {
         $item = insert_item(array('public' => false), array('Dublin Core' => array('Title' => array(array('text' => 'testNoDisplayPrivate', 'html' => false)))));
         $this->_assertRecordInSolr($item);
         $_GET['q'] = 'testNoDisplayPrivate';
         $this->dispatch('solr-search');
         $this->assertNotQueryContentContains('.result-title', 'testNoDisplayPrivate');
     } catch (Exception $e) {
         throw $e;
     } finally {
         set_option('solr_search_display_private_items', $opt);
     }
 }
예제 #7
0
파일: HooksTest.php 프로젝트: kyfr59/cg35
 public function testItemsShowPanel()
 {
     $this->_authenticateUser($this->_getDefaultUser());
     $orig = insert_item();
     $dup1 = insert_item();
     $dup2 = insert_item();
     $identifier = 'my-fake-id';
     $datestamp = '2011-07-24';
     $harvestId = 10000;
     foreach (array($orig, $dup1, $dup2) as $item) {
         $record = new OaipmhHarvester_Record();
         $record->setArray(array('identifier' => $identifier, 'item_id' => $item->id, 'datestamp' => $datestamp, 'harvest_id' => $harvestId));
         $record->save();
     }
     $this->dispatch('/items/show/' . $orig->id);
     $this->assertQuery('div#harvester-duplicates');
     $this->assertQueryCount('div#harvester-duplicates li', 2, "Should be 2 duplicates of this item.");
 }
예제 #8
0
 public function import()
 {
     //grab the data needed for using update_item or insert_item
     $elementTexts = $this->elementTexts();
     $itemMetadata = $this->itemMetadata();
     //avoid accidental duplications
     if ($this->record && $this->record->exists()) {
         $itemMetadata['overwriteElementTexts'] = true;
         update_item($this->record, $itemMetadata, $elementTexts);
         $this->updateItemOwner($this->record);
     } else {
         $this->record = insert_item($itemMetadata, $elementTexts);
         //dig up the correct owner information, importing the user if needed
         $this->updateItemOwner($this->record);
         $this->addOmekaApiImportRecordIdMap();
     }
     //import files after the item is there, so the file has an item id to use
     //we're also keeping track of the correspondences between local and remote
     //file ids, so we have to introduce this little inefficiency of not passing
     //the file data
     $this->importFiles($this->record);
 }
예제 #9
0
 public function testRecordExists()
 {
     $record = new OaipmhHarvester_Record();
     $item = insert_item(array('public' => true));
     $harvest = new OaipmhHarvester_Harvest();
     $record->item_id = $item->id;
     $record->identifier = 'foo-bar';
     $record->datestamp = '2010-04-28';
     $harvest->base_url = 'http://example.com';
     $harvest->metadata_prefix = 'oai_dc';
     $harvest->status = OaipmhHarvester_Harvest::STATUS_COMPLETED;
     $request = new OaipmhHarvester_Request_Mock();
     $xmlFile = dirname(__FILE__) . '/_files/ListRecords.xml';
     $request->setResponseXml(file_get_contents($xmlFile));
     $harvest->setRequest($request);
     $harvest->save();
     $record->harvest_id = $harvest->id;
     $record->save();
     $harvester = new OaipmhHarvester_Harvest_OaiDc($harvest);
     $harvester->harvest();
     $item = $this->db->getTable('Item')->find($record->item_id);
     $this->assertEquals("Record Title", metadata($item, array('Dublin Core', 'Title')));
 }
예제 #10
0
 /**
  * Create a new Item for each of the given files.
  *
  * @param array $filenames
  * @return array An array of errors that occurred when creating the
  *  Items, indexed by the filename that caused the error.
  */
 protected function _uploadFiles($fileNames)
 {
     if (!dropbox_can_access_files_dir()) {
         throw new Dropbox_Exception('The Dropbox files directory must be both readable and writable.');
     }
     $fileErrors = array();
     foreach ($fileNames as $fileName) {
         $item = null;
         try {
             $filePath = dropbox_validate_file($fileName);
             $itemMetadata = array('public' => $_POST['dropbox-public'], 'featured' => $_POST['dropbox-featured'], 'collection_id' => $_POST['dropbox-collection-id'] ? $_POST['dropbox-collection-id'] : null, 'tags' => $_POST['dropbox-tags']);
             $elementTexts = array('Dublin Core' => array('Title' => array(array('text' => $fileName, 'html' => false))));
             $fileMetadata = array('file_transfer_type' => 'Filesystem', 'file_ingest_options' => array('ignore_invalid_files' => false), 'files' => array($filePath));
             $item = insert_item($itemMetadata, $elementTexts, $fileMetadata);
             release_object($item);
             // delete the file from the dropbox folder
             unlink($filePath);
         } catch (Exception $e) {
             release_object($item);
             $fileErrors[$fileName] = $e->getMessage();
         }
     }
     return $fileErrors;
 }
 /**
  * Set some records with identifier to test.
  */
 protected function _prepareRecords()
 {
     // Remove default records.
     $this->_deleteAllRecords();
     $metadata = array('public' => true);
     $isHtml = false;
     $collections = array();
     $items = array();
     $files = array();
     foreach ($this->_recordsByType as $type => $recordsMetadata) {
         foreach ($recordsMetadata as $recordMetadata) {
             $identifiers = array();
             foreach ($recordMetadata['Identifier'] as $identifier) {
                 $identifiers[] = array('text' => $identifier, 'html' => $isHtml);
             }
             $elementTexts = array('Dublin Core' => array('Title' => array(array('text' => $recordMetadata['Title'], 'html' => $isHtml)), 'Identifier' => $identifiers));
             switch ($type) {
                 case 'Collection':
                     $collections[$recordMetadata['collection_id']] = insert_collection($metadata, $elementTexts);
                     break;
                 case 'Item':
                     $metadataItem = $metadata;
                     if (!empty($recordMetadata['collection_id'])) {
                         $metadataItem['collection_id'] = $collections[$recordMetadata['collection_id']]->id;
                     }
                     $record = insert_item($metadataItem, $elementTexts);
                     if (!empty($recordMetadata['files'])) {
                         $fileUrl = TEST_DIR . '/_files/test.txt';
                         $files[$recordMetadata['item_id']] = insert_files_for_item($record, 'Filesystem', array_fill(0, $recordMetadata['files'], $fileUrl));
                     }
                     break;
                 case 'File':
                     $record = $files[$recordMetadata['item_id']][$recordMetadata['file_key']];
                     $record->addElementTextsByArray($elementTexts);
                     $record->save();
                     break;
             }
         }
     }
 }
예제 #12
0
<?php

require_once 'db.php';
if ($_POST) {
    // eсли пeрeдaн мaссив POST
    $entity_type = $_POST["content_type"];
    if ($entity_type == "item") {
        $title = htmlspecialchars($_POST["title"]);
        // пишeм дaнныe в пeрeмeнныe и экрaнируeм спeцсимвoлы
        $description = htmlspecialchars($_POST["description"]);
        $photo = htmlspecialchars($_FILES['file']['name']);
        $json = array();
        // пoдгoтoвим мaссив oтвeтa
        if (!$title or !$description or !$photo) {
            // eсли хoть oднo пoлe oкaзaлoсь пустым
            $json['error'] = 'Вы зaпoлнили нe всe пoля! oбмaнуть рeшили? =)';
            // пишeм oшибку в мaссив
            echo json_encode($json);
            // вывoдим мaссив oтвeтa
            die;
            // умирaeм
        }
        $sourcePath = $_FILES['file']['tmp_name'];
        // Storing source path of the file in a variable
        $targetPath = "gallery/" . $_FILES['file']['name'];
        // Target path where file is to be stored
        move_uploaded_file($sourcePath, $targetPath);
        insert_item($title, $description, $photo);
    }
}
예제 #13
0
 protected function _addOneItem()
 {
     $item = insert_item();
     $this->assertTrue($item->exists());
     return $item;
 }
예제 #14
0
function handle_item_insert(&$item_r, $HTTP_VARS, &$errors)
{
    if (is_user_granted_permission(PERM_ITEM_OWNER) && $item_r['owner_id'] == get_opendb_session_var('user_id') || is_user_granted_permission(PERM_ITEM_ADMIN)) {
        // Before trying to insert items into this structure, first ensure it is valid.
        if (is_valid_item_type_structure($item_r['s_item_type'])) {
            // We need to get the title
            if (validate_item_attributes('insert', $item_r['s_item_type'], $HTTP_VARS, $errors)) {
                $fieldname = 'title';
                if (!is_array($HTTP_VARS[$fieldname])) {
                    if (preg_match("/new([0-9]+)/", $HTTP_VARS[$fieldname], $matches) && isset($HTTP_VARS[$fieldname . '_' . $matches[0]])) {
                        $fieldname = $fieldname . '_' . $matches[0];
                    }
                }
                $item_r['title'] = $HTTP_VARS[$fieldname];
                $is_exists_owner_title = FALSE;
                $is_exists_title = FALSE;
                // Check owner context
                if (get_opendb_config_var('item_input', 'duplicate_title_support') !== TRUE || $HTTP_VARS['confirmed'] != 'true' && get_opendb_config_var('item_input', 'confirm_duplicate_owner_insert') !== FALSE) {
                    $is_exists_owner_title = is_exists_title($item_r['title'], $item_r['s_item_type'], $item_r['owner_id']);
                }
                // Only check title/s_item_type context
                if (get_opendb_config_var('item_input', 'duplicate_title_support') !== TRUE || $HTTP_VARS['confirmed'] != 'true' && get_opendb_config_var('item_input', 'confirm_duplicate_insert') !== FALSE) {
                    $is_exists_title = is_exists_title($item_r['title'], $item_r['s_item_type']);
                }
                // Unless duplicate title support is allowed we cannot continue.
                if (!$is_exists_title && !$is_exists_owner_title || get_opendb_config_var('item_input', 'duplicate_title_support') !== FALSE) {
                    if (!$is_exists_title && !$is_exists_owner_title) {
                        if ($HTTP_VARS['trial_run'] != 'true') {
                            $new_item_id = insert_item($item_r['s_item_type'], $item_r['title']);
                            if ($new_item_id !== FALSE) {
                                $item_r['item_id'] = $new_item_id;
                                // insert any item level attributes
                                handle_item_attributes('insert', $item_r, $HTTP_VARS, $errors);
                                return TRUE;
                            } else {
                                $db_error = db_error();
                                $errors = array('error' => get_opendb_lang_var('item_not_added'), 'detail' => $db_error);
                                return FALSE;
                            }
                        } else {
                            //if($HTTP_VARS['trial_run'] != 'true')
                            return TRUE;
                        }
                    } else {
                        if ($HTTP_VARS['confirmed'] != 'false') {
                            // if explicitly false, then we are aborting insert.
                            if ($is_exists_owner_title) {
                                $errors = array('error' => get_opendb_lang_var('title_same_type_and_owner_exists', array('title' => $item_r['title'], 's_item_type' => $item_r['s_item_type'])), 'detail' => '');
                                return "__CONFIRM_EXISTS_OWNER_TITLE__";
                            } else {
                                if ($is_exists_title) {
                                    $errors = array('error' => get_opendb_lang_var('title_same_type_exists', array('title' => $item_r['title'], 's_item_type' => $item_r['s_item_type'])), 'detail' => '');
                                    return "__CONFIRM_EXISTS_TITLE__";
                                }
                            }
                        } else {
                            //insert aborted.
                            return "__ABORTED__";
                        }
                    }
                } else {
                    // cannot insert duplicate.
                    if ($is_exists_owner_title) {
                        $errors = array('error' => get_opendb_lang_var('title_same_type_and_owner_exists', array('title' => $item_r['title'], 's_item_type' => $item_r['s_item_type'])), 'detail' => '');
                    } else {
                        if ($is_exists_title) {
                            $errors = array('error' => get_opendb_lang_var('title_same_type_exists', array('title' => $item_r['title'], 's_item_type' => $item_r['s_item_type'])), 'detail' => '');
                        }
                    }
                    return FALSE;
                }
            } else {
                //if(validate_item_attributes("insert", $item_r['s_item_type'], $errors))
                return "__INVALID_DATA__";
            }
        } else {
            // if(is_valid_item_type_structure($item_r['s_item_type']))
            $errors = array('error' => get_opendb_lang_var('invalid_item_type_structure', 's_item_type', $item_r['s_item_type']), 'detail' => '');
            // An error like this is a big problem, and should be dealt with quickly, but there is no sense in alarming the
            // user by sending back an error.
            return FALSE;
        }
    } else {
        // non-admin user attempting to insert item for someone else.
        $errors = array('error' => get_opendb_lang_var('operation_not_available'));
        opendb_logger(OPENDB_LOG_WARN, __FILE__, __FUNCTION__, 'User attemped to insert an item for another user', $item_r);
        return FALSE;
    }
}
예제 #15
0
 /**
  * Insert a new item into the Omeka database.
  *
  * Post data can be added, unlike insert_item().
  *
  * @see insert_item()
  *
  * @param array $metadata
  * @param array $elementTexts
  * @param array $fileMetadata
  * @param array $postData
  * @return Item
  */
 private function _insertItem($metadata = array(), $elementTexts = array(), $fileMetadata = array(), $postData = array())
 {
     $record = insert_item($metadata, $elementTexts, $fileMetadata);
     $result = $this->_setExtraData($record, $postData, CsvImport_ColumnMap_Action::ACTION_ADD);
     return $record;
 }
예제 #16
0
 public function setUp()
 {
     parent::setUp();
     $this->item = insert_item(array('public' => '0'));
 }
예제 #17
0
 protected function parseFrontPageData($issueJson, $issue, $newspaper)
 {
     $frontpageJson = $this->fetchData($issueJson['pages'][0]['url']);
     $frontPage = $this->frontPagesTable->findByLocUri($issueJson['pages'][0]['url']);
     if (!$frontPage) {
         $frontpage = new NewspapersFrontPage();
         $itemElementMetadata = array('Dublin Core' => array(), 'Newspaper Metadata' => array());
         $itemMetadata = array('collection_id' => $newspaper->collection_id, 'public' => true);
         //fake @todo
         $altoUrl = $frontpageJson['ocr'];
         $pdfUrl = $frontpageJson['pdf'];
         $date = $frontpageJson['issue']['date_issued'];
         $title = $issueJson['title']['name'] . ' ' . $date;
         $itemElementMetadata['Dublin Core']['Title'] = array(array('text' => $title, 'html' => false));
         $itemElementMetadata['Dublin Core']['Date'] = array(array('text' => $date, 'html' => false));
         try {
             $item = insert_item($itemMetadata, $itemElementMetadata);
         } catch (Exception $e) {
             debug($e->getMessage());
             $item = false;
         }
         if ($item) {
             $altoDoc = new AltoDoc($altoUrl);
             if ($altoDoc->error) {
                 debug('failed loading ' . $altoUrl);
                 return;
             }
             //begin voodoo
             try {
                 $bottomTls = $altoDoc->filterTlsByVpos(null, 0.5);
                 $tls = $altoDoc->filterTlsByHeightSd($bottomTls, 1.1);
                 $tls = $altoDoc->filterTlsByWidthSd($tls);
                 $columnsGuess = $altoDoc->guessColumnsFromTls($tls, 0.7, null, 1.12);
             } catch (Exception $e) {
                 echo 'bad xml in ';
                 echo $issueJson['pages'][0]['url'];
             }
             //end voodoo
             $frontpage->columns = $columnsGuess;
             $frontpage->item_id = $item->id;
             $frontpage->issue_id = $issue->id;
             $frontpage->ca_import_id = 1;
             //fake @todo
             $frontpage->page_height = $altoDoc->pageLayout['page']['height'];
             $frontpage->page_width = $altoDoc->pageLayout['page']['width'];
             $frontpage->printspace_height = $altoDoc->pageLayout['printSpace']['height'];
             $frontpage->printspace_width = $altoDoc->pageLayout['printSpace']['width'];
             $frontpage->printspace_vpos = $altoDoc->pageLayout['printSpace']['hpos'];
             $frontpage->printspace_hpos = $altoDoc->pageLayout['printSpace']['hpos'];
             $frontpage->loc_uri = $issueJson['pages'][0]['url'];
             $frontpage->pdf_url = $pdfUrl;
             $frontpage->save();
         }
     }
 }
예제 #18
0
파일: Abstract.php 프로젝트: kyfr59/cg35
 /**
  * Convenience method for inserting an item and its files.
  * 
  * Method used by map writers that encapsulates item and file insertion. 
  * Items are inserted first, then files are inserted individually. This is 
  * done so Item and File objects can be released from memory, avoiding 
  * memory allocation issues.
  * 
  * @see insert_item()
  * @see insert_files_for_item()
  * @param mixed $metadata Item metadata
  * @param mixed $elementTexts The item's element texts
  * @param mixed $fileMetadata The item's file metadata
  * @return true
  */
 protected final function _insertItem($metadata = array(), $elementTexts = array(), $fileMetadata = array())
 {
     // Insert the item.
     $item = insert_item($metadata, $elementTexts);
     // Retrieve the inserted ID
     $insertedId = $item->id;
     // Insert the record after the item is saved. The idea here is that the
     // OaipmhHarvester_Records table should only contain records that have
     // corresponding items.
     $this->_insertRecord($item);
     // If there are files, insert one file at a time so the file objects can
     // be released individually.
     if (isset($fileMetadata['files'])) {
         // The default file transfer type is URL.
         $fileTransferType = isset($fileMetadata['file_transfer_type']) ? $fileMetadata['file_transfer_type'] : 'Url';
         // The default option is ignore invalid files.
         $fileOptions = isset($fileMetadata['file_ingest_options']) ? $fileMetadata['file_ingest_options'] : array('ignore_invalid_files' => true);
         // Prepare the files value for one-file-at-a-time iteration.
         $files = array($fileMetadata['files']);
         foreach ($files as $file) {
             $fileOb = insert_files_for_item($item, $fileTransferType, $file, $fileOptions);
             $fileObject = $fileOb;
             if (!empty($file['metadata'])) {
                 $fileObject->addElementTextsByArray($file['metadata']);
                 $fileObject->save();
             }
             /* CG35 : deleting temporary files */
             foreach ($fileMetadata['files'] as $files) {
                 $cmd = "rm " . $files;
                 shell_exec($cmd);
             }
             // Release the File object from memory.
             release_object($fileObject);
         }
     }
     // Release the Item object from memory.
     release_object($item);
     return $insertedId;
 }
예제 #19
0
 /**
  * Insert a new item into the Omeka database.
  *
  * Post data can be added, unlike insert_item().
  *
  * @see insert_item()
  *
  * @param array $metadata
  * @param array $elementTexts
  * @param array $fileMetadata
  * @param array $postData
  * @return Item
  */
 private function _insertItem($metadata = array(), $elementTexts = array(), $fileMetadata = array(), $postData = array())
 {
     $record = insert_item($metadata, $elementTexts, $fileMetadata);
     $result = $this->_setExtraData($record, $postData, ArchiveFolder_Importer::ACTION_ADD);
     return $record;
 }
 /**
  * Create an item.
  *
  * @param boolean $public True if the item is public.
  * @param string $title The Dublin Core "Title".
  * @return Item
  */
 protected function _item($public = true, $title = 'Test Title')
 {
     return insert_item(array('public' => true), array('Dublin Core' => array('Title' => array(array('text' => $title, 'html' => false)))));
 }
 /**
  * Insert an item of a given type.
  *
  * @param string $title The item title.
  * @param ItemType $type The item type.
  * @return Item
  */
 protected function _collitem($title, $type)
 {
     return insert_item(array('item_type_id' => $type->id, 'public' => true), array('Dublin Core' => array('Title' => array(array('text' => $title, 'html' => false)))));
 }
 /**
  * Performs the import by iterating the Zotero API Atom feeds and mapping 
  * each entry to an Omeka item.
  */
 protected function _import()
 {
     do {
         // Initialize the start parameter on the first library feed iteration.
         if (!isset($start)) {
             $start = 0;
         }
         // Get the library feed.
         if ($this->_libraryCollectionId) {
             $method = "{$this->_libraryType}CollectionItemsTop";
             $feed = $this->_client->{$method}($this->_libraryId, $this->_libraryCollectionId, array('start' => $start));
         } else {
             $method = "{$this->_libraryType}ItemsTop";
             $feed = $this->_client->{$method}($this->_libraryId, array('start' => $start));
         }
         // Set the start parameter for the next page iteration.
         if ($feed->link('next')) {
             $query = parse_url($feed->link('next'), PHP_URL_QUERY);
             parse_str($query, $query);
             $start = $query['start'];
         }
         // Iterate through this page's entries/items.
         foreach ($feed->entry as $item) {
             // Set default insert_item() arguments.
             $this->_itemMetadata = array('collection_id' => $this->_collectionId, 'public' => true);
             $this->_elementTexts = array();
             $this->_fileMetadata = array('file_transfer_type' => 'Url', 'file_ingest_options' => array('ignore_invalid_files' => true));
             // Map the title.
             $this->_elementTexts['Dublin Core']['Title'][] = array('text' => $item->title(), 'html' => false);
             $this->_elementTexts['Zotero']['Title'][] = array('text' => $item->title(), 'html' => false);
             // Map top-level attachment item.
             if ('attachment' == $item->itemType()) {
                 $this->_mapAttachment($item, true);
             }
             // Map the Zotero API field nodes to Omeka elements.
             if (is_array($item->content->div->table->tr)) {
                 foreach ($item->content->div->table->tr as $tr) {
                     $this->_mapFields($tr);
                 }
             } else {
                 $this->_mapFields($item->content->div->table->tr);
             }
             // Map Zotero tags to Omeka tags, comma-delimited.
             if ($item->numTags()) {
                 $method = "{$this->_libraryType}ItemTags";
                 $tags = $this->_client->{$method}($this->_libraryId, $item->key());
                 $tagArray = array();
                 foreach ($tags->entry as $tag) {
                     // Remove commas from Zotero tags, or Omeka will assume
                     // they are separate tags.
                     $tagArray[] = str_replace(',', ' ', $tag->title);
                 }
                 $this->_itemMetadata['tags'] = join(',', $tagArray);
             }
             // Map Zotero children (notes & attachments).
             if ($item->numChildren()) {
                 $method = "{$this->_libraryType}ItemChildren";
                 $children = $this->_client->{$method}($this->_libraryId, $item->key());
                 foreach ($children->entry as $child) {
                     // Map a Zotero child note to an Omeka item.
                     if ('note' == $child->itemType()) {
                         $noteXpath = '//default:tr[@class="note"]/default:td';
                         $note = $this->_contentXpath($child->content, $noteXpath, true);
                         // Prepare the note for import.
                         if ($note instanceof SimpleXMLElement) {
                             $note = trim(preg_replace('#^<td>(.*)</td>$#', '$1', $note->asXML()));
                         }
                         $this->_elementTexts['Zotero']['Note'][] = array('text' => (string) $note, 'html' => true);
                         // Map a Zotero child attachment (file) to a file
                         // assigned to the Omeka parent item.
                     } else {
                         if ('attachment' == $child->itemType()) {
                             $this->_mapAttachment($child);
                             // Unknown child. Do not map.
                         } else {
                             continue;
                         }
                     }
                     // Save the Zotero child item.
                     $this->_insertZoteroImportItem(null, $child->key(), $item->key(), $child->itemType(), $child->updated());
                 }
             }
             // Insert the item.
             $omekaItem = insert_item($this->_itemMetadata, $this->_elementTexts, $this->_fileMetadata);
             // Save the Zotero item.
             $this->_insertZoteroImportItem($omekaItem->id, $item->key(), null, $item->itemType(), $item->updated());
             release_object($item);
             release_object($omekaItem);
         }
     } while ($feed->link('self') != $feed->link('last'));
 }
예제 #23
0
 public function testIndexFeatured()
 {
     $item = insert_item(array('featured' => true, 'public' => true), array('Dublin Core' => array('Title' => array(array('text' => 'test index featured', 'html' => false)))));
     $doc = $this->_getRecordDocument($item);
     $this->assertEquals(true, $doc->featured);
 }
예제 #24
0
 /**
  * Adds a new item based on a row string in the CSV file and returns it.
  *
  * @param string $row A row string in the CSV file
  * @return Item|boolean The inserted item or false if an item could not be added.
  */
 protected function _addItemFromRow($row)
 {
     $result = $this->getColumnMaps()->map($row);
     $tags = $result[CsvImport_ColumnMap::TYPE_TAG];
     $itemMetadata = array(Builder_Item::IS_PUBLIC => $this->is_public, Builder_Item::IS_FEATURED => $this->is_featured, Builder_Item::ITEM_TYPE_ID => $this->item_type_id, Builder_Item::COLLECTION_ID => $this->collection_id, Builder_Item::TAGS => $tags);
     // If this is coming from CSV Report, bring in the itemmetadata coming from the report
     if (!is_null($result[CsvImport_ColumnMap::TYPE_COLLECTION])) {
         $itemMetadata[Builder_Item::COLLECTION_ID] = $result[CsvImport_ColumnMap::TYPE_COLLECTION];
     }
     if (!is_null($result[CsvImport_ColumnMap::TYPE_PUBLIC])) {
         $itemMetadata[Builder_Item::IS_PUBLIC] = $result[CsvImport_ColumnMap::TYPE_PUBLIC];
     }
     if (!is_null($result[CsvImport_ColumnMap::TYPE_FEATURED])) {
         $itemMetadata[Builder_Item::IS_FEATURED] = $result[CsvImport_ColumnMap::TYPE_FEATURED];
     }
     if (!empty($result[CsvImport_ColumnMap::TYPE_ITEM_TYPE])) {
         $itemMetadata[Builder_Item::ITEM_TYPE_NAME] = $result[CsvImport_ColumnMap::TYPE_ITEM_TYPE];
     }
     $elementTexts = $result[CsvImport_ColumnMap::TYPE_ELEMENT];
     try {
         $item = insert_item($itemMetadata, $elementTexts);
     } catch (Omeka_Validator_Exception $e) {
         $this->_log($e, Zend_Log::ERR);
         return false;
     } catch (Omeka_Record_Builder_Exception $e) {
         $this->_log($e, Zend_Log::ERR);
         return false;
     }
     $fileUrls = $result[CsvImport_ColumnMap::TYPE_FILE];
     foreach ($fileUrls as $url) {
         try {
             $file = insert_files_for_item($item, 'Url', $url, array('ignore_invalid_files' => false));
         } catch (Omeka_File_Ingest_InvalidException $e) {
             $msg = "Invalid file URL '{$url}': " . $e->getMessage();
             $this->_log($msg, Zend_Log::ERR);
             $item->delete();
             release_object($item);
             return false;
         } catch (Omeka_File_Ingest_Exception $e) {
             $msg = "Could not import file '{$url}': " . $e->getMessage();
             $this->_log($msg, Zend_Log::ERR);
             $item->delete();
             release_object($item);
             return false;
         }
         release_object($file);
     }
     // Makes it easy to unimport the item later.
     $this->_recordImportedItemId($item->id);
     return $item;
 }
예제 #25
0
파일: found.php 프로젝트: kkoves/limbo
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.3/css/materialize.min.css">
        <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

        <!-- Compiled and minified JavaScript -->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.3/js/materialize.min.js"></script>
        <script>
            $(".button-collapse show-on-large").sideNav();
        </script>
        <?php 
require 'includes/helpers.php';
require 'includes/connect_db.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    if (valid_form()) {
        // if form is valid
        insert_item('Found', date('Y-m-d H:i:s'));
        // insert the values from the form into the database, with item status and current timestamp
        $_POST = array();
        echo '<script>$(document).ready(function () {$("#success").html("Success! Your found item has been submitted.");});</script>';
    }
}
?>
        <script>
            $(document).ready(function () {
                var date = new Date();
				var year = date.getFullYear();
				
                $('select').material_select();
                $('.datepicker').pickadate({
                    selectMonths: true, // Creates a dropdown to control month
                    selectYears: 2, // Creates a dropdown of 2 years to control year
예제 #26
0
            // Checks for redundant filename
            if (file_exists($_FILES["imgfile"]["name"])) {
                echo "<p style='color:red;'>Image file name exists.</p>";
            } else {
                // Uploads file and inserts listing since everything is valid
                move_uploaded_file($_FILES["imgfile"]["tmp_name"], "uploads/{$filename}");
                echo "Image upload Successful . <a href='uploads/{$filename}'>Click here</a> to view the uploaded image";
                insert_item($dbc, $item, $location, $type, $color, $descr, $date, $email, $status, $image);
                $_SESSION['inserted'] = true;
                header('Location: index.php');
                die("Unauthorized User!");
            }
        } else {
            if (empty($_FILES["imgfile"]["name"])) {
                // Inserts the listing if valid (no image)
                insert_item($dbc, $item, $location, $type, $color, $descr, $date, $email, $status, $image);
                $_SESSION['inserted'] = true;
                header('Location: index.php');
                die("Unauthorized User!");
            } else {
                echo "<p style='color:red;'>Invalid image file type.</p>";
            }
        }
    }
}
?>

        <!--text field for listing name-->
        <p><input type="text" name="listing-name" placeholder="Listing Name"><span class="required">*</span></p>
        <!--drop down with item types -->
        <p><select name="item-type">
예제 #27
0
 public function setUp()
 {
     parent::setUp();
     $this->item = insert_item(array('public' => true));
     $this->_logout();
 }
 /**
  * Create an Item.
  *
  * @param string $title The exhibit title.
  * @return Item $item The item.
  */
 protected function _item($title = 'Test Title')
 {
     return $item = insert_item(array(), array('Dublin Core' => array('Title' => array(array('text' => $title, 'html' => false)))));
 }
예제 #29
0
<!-- insert_item.php
   A PHP script to insert a new item into the database
-->
<?php 
/**
 * Created by PhpStorm.
 * User: Ryan
 * Date: 10/21/2015
 * Time: 3:12 PM
 */
require 'db_cn.inc';
//This file contains php code that will be executed after the
//insert operation is done.
require 'item_insert_result_ui.inc';
// Main control logic
insert_item();
//-------------------------------------------------------------
function insert_item()
{
    // Connect to the 'test' database
    // The parameters are defined in the teach_cn.inc file
    // These are global constants
    connect_and_select_db(DB_SERVER, DB_UN, DB_PWD, DB_NAME);
    // Get the information entered into the webpage by the user
    // These are available in the super global variable $_POST
    // This is actually an associative array, indexed by a string
    $itemNumber = mysql_real_escape_string($_POST['itemNumber']);
    $itemDescription = mysql_real_escape_string($_POST['itemDescription']);
    $category = mysql_real_escape_string($_POST['category']);
    $departmentName = mysql_real_escape_string($_POST['departmentName']);
    $purchaseCost = mysql_real_escape_string($_POST['purchaseCost']);
예제 #30
0
 public function setUp()
 {
     parent::setUp();
     $this->item = insert_item(array('public' => true));
     set_option('disable_default_file_validation', 1);
 }