function views_oai_pmh_plugin_display::oai_check_args in Views OAI-PMH 7
Same name and namespace in other branches
- 6.2 plugins/views_oai_pmh_plugin_display.inc \views_oai_pmh_plugin_display::oai_check_args()
- 6 plugins/views_oai_pmh_plugin_display.inc \views_oai_pmh_plugin_display::oai_check_args()
- 7.2 plugins/views_oai_pmh_plugin_display.inc \views_oai_pmh_plugin_display::oai_check_args()
1 call to views_oai_pmh_plugin_display::oai_check_args()
File
- plugins/
views_oai_pmh_plugin_display.inc, line 283 - Contains the OAI-PMH display plugin.
Class
- views_oai_pmh_plugin_display
- We are based on a feed display for compatibility.
Code
function oai_check_args($args, $required = array(), $optional = array()) {
$values = array();
unset($args['verb']);
if (isset($args['resumptionToken']) && count($args) > 1) {
$this
->oai_error('exclusiveArgument');
return array();
}
elseif (isset($args['resumptionToken']) && count($args) == 1) {
$this->oai_args['resumptionToken'] = $this
->get_oai_resumption_token($args['resumptionToken']);
return array();
}
if (count($args) < count($required)) {
foreach ($required as $arg) {
if (!isset($args[$arg])) {
$this
->oai_error('missingArgument', $arg);
return array();
}
}
}
$possible = array_merge($required, $optional);
$supplied = array_keys($args);
if (count($bad_args = array_diff($supplied, $possible))) {
foreach ($bad_args as $arg) {
$this
->oai_error('badArgument', $arg, $args[$arg]);
}
return array();
}
if (isset($args['from'])) {
if (!($fromgran = $this
->check_date_format($args['from']))) {
$this
->oai_error('badGranularity', 'from', $args['from']);
}
}
if (isset($args['until'])) {
if (!($untilgran = $this
->check_date_format($args['until']))) {
$this
->oai_error('badGranularity', 'until', $args['until']);
}
$min_datestamp = db_query("SELECT min(changed) FROM {node} ")
->fetchField();
if ($min_datestamp > strtotime($args['until'])) {
$this
->oai_error('noRecordsMatch');
}
}
if (isset($args['from']) && isset($args['until'])) {
if (strtotime($args['from']) > strtotime($args['until'])) {
$this
->oai_error('noRecordsMatch');
}
}
if (isset($fromgran) && isset($untilgran) && $fromgran != $untilgran) {
$this
->oai_error('badGranularity', 'mismatched Granularity', $until);
}
if (isset($args['identifier'])) {
$id = substr(strrchr($args['identifier'], ":"), 1);
if (!$this
->oai_check_identifier($id)) {
$this
->oai_error('idDoesNotExist', 'badArgument', $id);
}
}
if (!count($this
->get_oai_errors())) {
foreach ($possible as $key) {
if (isset($args[$key])) {
$values[$key] = $args[$key];
}
}
}
return $values;
}