Changeset - fcf10ab116db
[Not reviewed]
default
0 1 0
Nathan Brink (binki) - 15 years ago 2011-03-24 12:06:54
ohnobinki@ohnopublishing.net
New functions which may be useful for crawlers.
1 file changed with 48 insertions and 0 deletions:
0 comments (0 inline, 0 general)
inc/school.crawl.inc
Show inline comments
 
@@ -448,6 +448,14 @@ function school_crawl_form(DOMElement $f
 
    {
 
      if ($input_node->hasAttribute('name'))
 
	{
 
	  /*
 
	   * Skip over checkboxes which are not ``successful''
 
	   * (http://w3.org/ terminology).
 
	   */
 
	  if (!stricmp($input_node->getAttribute('type'), 'checkbox')
 
	      && !$input_node->hasAttribute('checked'))
 
	    continue;
 

	
 
	  $input_name = $input_node->getAttribute('name');
 
	  if (!isset($form[$input_name]))
 
	    $form[$input_name] = array();
 
@@ -477,6 +485,46 @@ function school_crawl_form(DOMElement $f
 

	
 
/**
 
 * \brief
 
 *   Parses a <select />'s <option />s into an associative array.
 
 *
 
 * \param $select
 
 *   The DOMElement representing the <select />.
 
 * \param $get_textcontent
 
 *   Whether or not the returned array should point at DOMElements or
 
 *   at the textcontent of each <option /> node. Defaults to
 
 *   textcontent.
 
 * \param $selected
 
 *   Will be set to an array of the currently selected keys if passed.
 
 * \return
 
 *   An associative array mapping an <option />'s name attribute onto
 
 *   either the <option />'s textcontent (if $get_textcontent is TRUE)
 
 *   or onto the <option /> DOMElement itself.
 
 */
 
function school_crawl_form_select_array(DOMElement $select, $get_textcontent = TRUE, &$selected = NULL)
 
{
 
  $selected = array();
 
  $options = array();
 

	
 
  foreach ($select->childNodes as $child_node)
 
    if ($child_node->nodeType == XML_ELEMENT_NODE
 
	&& !stricmp($child_node->tagName, 'options')
 
	&& $child_node->hasAttribute('name'))
 
      {
 
	$name = $child_node->getAttribute('name');
 
	if ($child_node->hasAttribute('selected'))
 
	  $selected[] = $name;
 

	
 
	if ($get_textcontent)
 
	  $options[$name] = $child_node->textContent;
 
	else
 
	  $options[$name] = $child_node;
 
      }
 

	
 
  return $options;
 
}
 

	
 
/**
 
 * \brief
 
 *   Resolve a relativish URL.
 
 *
 
 * \param $orig_url
0 comments (0 inline, 0 general)