function parse_html($url)
{
    echo "Scraping {$url}\n";
    //create an array of items to be parsed from HTML
    $fields = array();
    $html = file_get_contents($url);
    $dom = new DOMDocument();
    @$dom->loadHTML($html);
    $xpath = new DOMXpath($dom);
    //find the reference numbers
    $refNode = $xpath->query("//p[@class='ttag'][contains(text(), 'Alternative')]/following-sibling::p[1]");
    if ($refNode->length > 0) {
        //parse as text and clean to generate an array of reference numbers
        $refText = $dom->saveHTML($refNode->item(0));
        $refText = str_replace('<p class="vtag">', '', str_replace('</p>', '', $refText));
        $refs = explode('<br>', trim($refText));
        foreach ($refs as $ref) {
            $ref = trim($ref);
            if (strpos($ref, 'RRC') !== FALSE || strpos($ref, 'Crawford') !== FALSE) {
                echo "Parsing {$ref}\n";
                $fields['reference'] = $ref;
                $pieces = explode(' ', $ref);
                $num = str_replace('/', '.', $pieces[1]);
                $uri = "http://numismatics.org/crro/id/rrc-{$num}";
                $typeValid = check_uri($uri);
                if ($typeValid == true) {
                    $fields['coinType'] = $uri;
                }
            } else {
                if (strpos($ref, 'price') !== FALSE) {
                    echo "Parsing {$ref}\n";
                    $fields['reference'] = $ref;
                    $pieces = explode(' ', $ref);
                    $num = $pieces[1];
                    $uri = "http://numismatics.org/pella/id/price.{$num}";
                    $typeValid = check_uri($uri);
                    if ($typeValid == true) {
                        $fields['coinType'] = $uri;
                    }
                }
            }
        }
    } else {
        echo "No references.\n";
    }
    //parse measurements
    $measurementsNode = $xpath->query("//p[@class='ttag'][contains(text(), 'Dimension')]/following-sibling::p[1]");
    if ($measurementsNode->length > 0) {
        $text = $dom->saveHTML($measurementsNode->item(0));
        $text = str_replace('<p class="vtag">', '', str_replace('</p>', '', $text));
        $measurements = explode('<br>', trim($text));
        foreach ($measurements as $measurement) {
            if (strpos($measurement, 'weight') !== FALSE) {
                preg_match('/(\\d+\\.\\d+)/', $measurement, $matches);
                if (is_numeric($matches[1])) {
                    $fields['weight'] = (double) $matches[1];
                }
            } elseif (strpos($measurement, 'axis') !== FALSE) {
                preg_match('/(d+)/', $measurement, $matches);
                $axis360 = $matches[1];
                //round the 360 degree axis to the nearest clock integer
                $axis = round($axis360 / 360 * 12);
                //if axis is between 0 and 12, reset 0 to 12 and return the value
                if ($axis <= 12 && $axis >= 0) {
                    if ($axis == 0) {
                        $axis = 12;
                    }
                    $fields['axis'] = $axis;
                }
            }
        }
        //var_dump($measurements);
    }
    return $fields;
}
    if (is_numeric($row['Diameter'])) {
        $record['diameter'] = $row['Diameter'];
    }
    if (is_numeric($row['Weight'])) {
        $record['weight'] = $row['Weight'];
    }
    if (strlen($row['Hoard URI']) > 0) {
        $record['hoard'] = $row['Hoard URI'];
    }
    //images
    $id = str_replace('HCR', '', $row['Accession number']);
    $record['obv_image'] = "http://hcr.ashmus.ox.ac.uk/images/coin/{$id}of.jpg";
    $record['rev_image'] = "http://hcr.ashmus.ox.ac.uk/images/coin/{$id}rf.jpg";
    //validate Price number
    $uri = "http://numismatics.org/pella/id/price.{$row['Price number']}";
    $typeValid = check_uri($uri);
    if ($typeValid == true) {
        $record['cointype'] = $uri;
    }
    $records[] = $record;
    $count++;
}
//after the CSV has been parsed, then process the resulting records array into Nomisma-conformant RDF
generate_csv($records, $project);
generate_rdf($records, $project);
function check_uri($uri)
{
    global $coinTypes;
    //if the URI is in the array
    if (array_key_exists($uri, $coinTypes)) {
        if ($coinTypes[$uri] == true) {
            } else {
                $active = 'no';
            }
            $new_user->setActive($active);
            $new_user->setData($_POST['userdata']);
            if (!$new_user->save()) {
                $msg = 'error_user_not_created';
            } else {
                SimpleSAML_Utilities::redirect(SimpleSAML_Utilities::selfURLNoQuery(), array('selectedtab' => $selectedtab));
            }
        }
    }
}
if (isset($_POST['submit'])) {
    if (!empty($_POST['entityid'])) {
        if (check_uri($_POST['entityid'])) {
            if (!isset($_POST['entityid']) || empty($_POST['entitytype'])) {
                $msg = 'error_no_type';
                $old_entityid = $_POST['entityid'];
                $old_entitytype = $_POST['entitytype'];
            } else {
                $msg = $mcontrol->createNewEntity($_POST['entityid'], $_POST['entitytype']);
                if (is_int($msg)) {
                    $entity = new sspmod_janus_Entity($janus_config);
                    $pm->subscribe($user->getUid(), 'ENTITYUPDATE-' . $msg);
                    $directlink = SimpleSAML_Module::getModuleURL('janus/editentity.php', array('eid' => $msg));
                    $pm->post('New entity created', 'Permalink: <a href="' . $directlink . '">' . $directlink . '</a><br /><br />A new entity has been created.<br />Entityid: ' . $_POST['entityid'] . '<br />Entity type: ' . $_POST['entitytype'], 'ENTITYCREATE', $user->getUid());
                    SimpleSAML_Utilities::redirect(SimpleSAML_Module::getModuleURL('janus/editentity.php'), array('eid' => $msg));
                }
            }
        } else {
Example #4
0
                redirectTrustedUrl(SimpleSAML_Utilities::selfURLNoQuery(), array(), IS_AJAX);
            }
        }
    }
}
/* END TAB ADMIN POST HANDLER *****************************************************************************************/
/* START ENTITIES POST HANDLER ****************************************************************************************/
if (isset($_POST['submit'])) {
    if (!isset($_POST['csrf_token']) || !$csrf_provider->isCsrfTokenValid('entity_create', $_POST['csrf_token'])) {
        SimpleSAML_Logger::warning('Janus: [SECURITY] CSRF token not found or invalid');
        throw new SimpleSAML_Error_BadRequest('Missing valid csrf token!');
    }
    $selectedtab = SELECTED_TAB_ENTITIES;
    if (!empty($_POST['entityid'])) {
        $validateEntityId = $janus_config->getValue('entity.validateEntityId', true);
        if (!$validateEntityId || $validateEntityId && check_uri($_POST['entityid'])) {
            if (!isset($_POST['entityid']) || empty($_POST['entitytype'])) {
                $msg = 'error_no_type';
                $old_entityid = $_POST['entityid'];
                $old_entitytype = $_POST['entitytype'];
            } else {
                $msg = $userController->createNewEntity($_POST['entityid'], $_POST['entitytype']);
                if (is_int($msg)) {
                    $entity = new sspmod_janus_Entity($janus_config);
                    $pm->subscribe($user->getUid(), 'ENTITYUPDATE-' . $msg);
                    $directlink = SimpleSAML_Module::getModuleURL('janus/editentity.php', array('eid' => $msg));
                    $pm->post('New entity created', 'Permalink: ' . '<a href="' . htmlspecialchars($directlink) . '">' . htmlspecialchars($directlink) . '</a>' . '<br /><br />A new entity has been created.<br />' . 'Entityid: ' . htmlspecialchars($_POST['entityid']) . '<br />' . 'Entity type: ' . htmlspecialchars($_POST['entitytype']), 'ENTITYCREATE', $user->getUid());
                    redirectTrustedUrl(SimpleSAML_Module::getModuleURL('janus/editentity.php'), array('eid' => $msg), IS_AJAX);
                }
            }
        } else {
Example #5
0
         } else {
             $response_http = response_http(403);
         }
     } else {
         $response_http = response_http(403);
     }
     break;
     ////////////////////////////////////////////////////////////////////////////////
     // DELETE
     ////////////////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////////////////
 // DELETE
 ////////////////////////////////////////////////////////////////////////////////
 case 'DELETE':
     //check if the uri is valid
     if (check_uri($uri, $valid_uri['DELETE'])) {
         // generate query
         switch (sizeof($loc)) {
             case 2:
                 $query = sprintf("DELETE FROM %s WHERE id=%s", $loc[0], $loc[1]);
                 break;
             case 3:
                 $query = sprintf("DELETE FROM  %s WHERE %s='%s'", $loc[0], $loc[1], $loc[2]);
                 break;
             case 5:
                 $query = sprintf("DELETE FROM  %s WHERE %s='%s' AND %s='%s'", $loc[0], $loc[1], $loc[2], $loc[3], $loc[4]);
                 break;
         }
         $stmt = $db->prepare($query);
         $stmt->execute();
         $response_http = response_http(201);
// Check if user is allowed to se entity
$guard = new sspmod_janus_UIguard($janus_config->getArray('access', array()));
$allowedUsers = $mcontroller->getUsers();
if (!(array_key_exists($userid, $allowedUsers) || $guard->hasPermission('allentities', null, $user->getType(), TRUE))) {
    SimpleSAML_Utilities::redirect(SimpleSAML_Module::getModuleURL('janus/index.php'));
}
$et = new SimpleSAML_XHTML_Template($config, 'janus:editentity.php', 'janus:editentity');
$language = $et->getLanguage();
$update = FALSE;
$note = '';
if (!empty($_POST)) {
    // Array for collecting addresses to notify
    $addresses = array();
    // Change entityID
    if (isset($_POST['entityid']) && $guard->hasPermission('changeentityid', $entity->getWorkflow(), $user->getType())) {
        if (check_uri($_POST['entityid']) || true) {
            # HACK: For SURFnetGuests : https://espee-test.surfnet.nl/federate/metadata/saml20/SURFnetGuests
            $entityIdNeedsUpdating = $_POST['entityid'] != $entity->getEntityid();
            if ($entityIdNeedsUpdating) {
                $userController = new sspmod_janus_UserController($janus_config);
                if ($userController->isEntityIdInUse($_POST['entityid'], $errorMessage)) {
                    $msg = $errorMessage;
                } else {
                    if ($entity->setEntityid($_POST['entityid'])) {
                        $update = TRUE;
                        $note .= 'Changed entityID: ' . $_POST['entityid'] . '<br />';
                        $addresses[] = 'ENTITYUPDATE-' . $eid . '-CHANGEENTITYID';
                    }
                }
            }
        } else {