public function FeedsCrawler::sourceFormValidate in Feeds Crawler 6.2
Same name and namespace in other branches
- 7 FeedsCrawler.inc \FeedsCrawler::sourceFormValidate()
Override parent::sourceFormValidate().
Overrides FeedsHTTPFetcher::sourceFormValidate
1 call to FeedsCrawler::sourceFormValidate()
- FeedsCrawler::configFormValidate in ./
FeedsCrawler.inc - Validation handler for configForm().
File
- ./
FeedsCrawler.inc, line 221 - Home of the FeedsCrawler.
Class
- FeedsCrawler
- Fetches data via HTTP.
Code
public function sourceFormValidate(&$values) {
$vs =& $values['crawler'];
array_walk_recursive($vs, array(
$this,
'trim',
));
if (empty($vs['num_pages'])) {
$vs['num_pages'] = 0;
}
if (empty($vs['delay'])) {
$vs['delay'] = 0;
}
if (!empty($vs['xpath'])) {
$xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?>' . "\n<items></items>");
$use_errors = libxml_use_internal_errors(TRUE);
$result = $xml
->xpath($vs['xpath']);
$error = libxml_get_last_error();
libxml_clear_errors();
libxml_use_internal_errors($use_errors);
if ($error) {
form_set_error('crawler][xpath', t('There was an error with the XPath selector: ') . $error->message);
}
}
if (!empty($vs['url']['url_pattern']) && !(stripos($vs['url']['url_pattern'], 'http://') === 0 || stripos($vs['url']['url_pattern'], 'https://') === 0)) {
form_set_error('crawler][url][url_pattern', t('The url pattern must be an absolute url. It must start with http:// or https://'));
}
if (!empty($vs['num_pages']) && !is_int($vs['num_pages']) && !ctype_digit($vs['num_pages'])) {
form_set_error('crawler][num_pages', t('Must be an integer.'));
}
if (!empty($vs['delay']) && !is_numeric($vs['delay'])) {
form_set_error('crawler][delay', t('Must be a number.'));
}
if (!empty($vs['url']['initial']) && !is_numeric($vs['url']['initial'])) {
form_set_error('crawler][url][initial', t('Must be a number.'));
}
if (!empty($vs['url']['increment']) && !is_numeric($vs['url']['increment'])) {
form_set_error('crawler][url][increment', t('Must be a number.'));
}
}