Files @ b183b9a9baeb
Branch filter:

Location: SlatePermutate/school.d/ccbcmd.crawl.inc

binki
Support detecting and removing outliers in semester start/end points when crawling. Only enabled for calvin, whose data caused the wrong semester to be selected.
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
<?php /* -*- mode: php; -*- */
/*
 * Copyright 2011 Nathan Phillip Brink <ohnobinki@ohnopublishing.net>
 *
 * This file is a part of slate_permutate.
 *
 * slate_permutate is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * slate_permutate is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with slate_permutate.  If not, see <http://www.gnu.org/licenses/>.
 */

define('CCBCMD_CRAWL_URI', 'http://ccbcmd.edu/schedule/sched.html');

/**
 * \brief
 *   Obtain list of crawlable semesters offered by CCBCMD.
 *
 * \parram $school
 *   The CCBCMD school handle.
 * \param $semesters
 *   Array to populate with available semesters.
 * \return
 *   0 on success.
 */
function ccbcmd_crawl_semester_list(array $school, array &$semesters, &$school_crawl_log)
{
  $cookies = array();

  /*
   * It seems that http://ccbcmd.edu/schedule/sched.html is what we're
   * meant to start from. That's just a redirect to some other page
   * from which we get a listing of available semesters and choose
   * one.
   */
  $uri = CCBCMD_CRAWL_URI;
  $semesters_dom = new DOMDocument();
  $semesters_dom->loadHTML(school_crawl_geturi($uri, $cookies, $school_crawl_log, NULL, TRUE, 'ccbcmd_crawl_curlhook'));
  $semesters_select_node = $semesters_dom->getElementById('term_input_id');
  if ($semesters_select_node === NULL)
    {
      school_crawl_logf($school_crawl_log, 0, "Could not get list of available semesters to choose from.");
      return 1;
    }

  foreach ($semesters_select_node->childNodes as $semesters_option_node)
    {
      $semester_text = $semesters_option_node->textContent;
      $semester_value = $semesters_option_node->getAttribute('value');
      if (empty($semester_value))
	/* skip the empty ``None'' semester */
	continue;

      if (stripos($semester_text, 'continuing') !== FALSE)
	/* skip the year-long semesters dedicated to continuing education */
	continue;

      list($semester_season, $semester_year) = explode(' ', $semester_text);

      /* the college has two separate summer sessions, so distinguish between them */
      if (preg_match(';session ([0-9]+);i', $semester_text, $matches))
	$semester_season .= '_' . $matches[1];

      $semesters[] = new Semester($semester_year, strtolower($semester_season));
    }

  return 0;
}

/**
 * \brief
 *   Crawl a CCBCMD semester.
 *
 * \param $school
 *   The CCBCMD school handle.
 * \param $semester
 *   The semester to fill with courses.
 */
function ccbcmd_crawl_semester($school, $semester, &$school_crawl_log)
{
  $cookies = array();
  $uri = CCBCMD_CRAWL_URI;
  $semesters_dom = new DOMDocument();
  $semesters_dom->loadHTML(school_crawl_geturi($uri, $cookies, $school_crawl_log, NULL, TRUE, 'ccbcmd_crawl_curlhook'));
  $semesters_select_node = $semesters_dom->getElementById('term_input_id');
  if (empty($semesters_select_node))
    {
      school_crawl_logf($school_crawl_log, 0, "Could not locate the list of semesters from which to choose.");
      return 1;
    }

  $semesters_form = school_crawl_element_ancestor($semesters_select_node, 'form');
  if ($semesters_form === NULL)
    {
      school_crawl_logf($school_crawl_log, 0, "Unable to find <form /> associated with semester.");
      return 1;
    }
  $semesters_post = school_crawl_form($semesters_form);

  $semester_found = FALSE;
  foreach ($semesters_select_node->childNodes as $semesters_option_node)
    {
      $semester_text = $semesters_option_node->textContent;
      $semester_value = $semesters_option_node->getAttribute('value');
      if (empty($semester_value))
	continue;

      list($semester_season, $semester_year) = explode(' ', $semester_text);
      if (preg_match(';session ([0-9]+);i', $semester_text, $matches))
	$semester_season .= '_' . $matches[1];
      $semester_season = strtolower($semester_season);

      if ($semester_year == $semester->year_get()
	  && $semester_season == $semester->season_get())
	{
	  $semester_found = TRUE;
	  break;
	}
    }
  if (!$semester_found)
    {
      school_crawl_logf($school_crawl_log, 1, "Unable to find the entry for semester %s.", $semester);
      return 1;
    }

  $semesters_post[$semesters_select_node->getAttribute('name')] = $semester_value;

  $subjects_dom = new DOMDocument();
  $uri = school_crawl_url($uri, $semesters_form->getAttribute('action'));
  $subjects_dom->loadHTML(school_crawl_geturi($uri, $cookies, $school_crawl_log, $semesters_post, TRUE, 'ccbcmd_crawl_curlhook'));

  $subjects_form_nodelist = $subjects_dom->getElementsByTagName('form');
  if (!$subjects_form_nodelist->length)
    {
      school_crawl_logf($school_crawl_log, 0, "Unable to find <form /> to submit for the subjects-choosing page.");
      return 1;
    }
  $subjects_form_node = $subjects_form_nodelist->item(0);
  $subjects_post = school_crawl_form($subjects_form_node);

  $subjects_select_node = $subjects_dom->getElementById('subj_id');
  foreach ($subjects_select_node->childNodes as $subjects_option_node)
    if (!strcasecmp('all', trim($subjects_option_node->textContent)))
      $subjects_post[$subjects_select_node->getAttribute('name')][] = $subjects_option_node->getAttribute('value');

  $courses_dom = new DOMDocument();
  $uri = school_crawl_url($uri, $subjects_form_node->getAttribute('action'));
  $courses_dom->loadHTML(school_crawl_geturi($uri, $cookies, $school_crawl_log, $subjects_post, TRUE, 'ccbcmd_crawl_curlhook'));

  $courses_xpath = new DOMXPath($courses_dom);

  /* The second row of the table has all of the headers in it */
  $tr_header_nodelist = $courses_xpath->query('//table[@class="datadisplaytable" and position()=1]//tr[position()=2]');
  if (!$tr_header_nodelist->length)
    {
      school_crawl_logf($school_crawl_log, 0, "Unable to find the row of the course/section data table which gives us the mappings of column names onto columns.");
      return 1;
    }
  $tr_header_node = $tr_header_nodelist->item(0);

  $section_offsets = array(
			   'registration_number' => school_crawl_table_resolve_column($tr_header_node, 'CRN'),
			   'section_id' => school_crawl_table_resolve_column($tr_header_node, 'subj/crse/sec'),
			   /* there's a boolean column which says whether or not the course has any prerequisites/corequisites.... */
			   'credits' => school_crawl_table_resolve_column($tr_header_node, 'credhrs'),
			   /* there's a column for the number of contact hours, vs. credit hours */
			   'dates' => school_crawl_table_resolve_column($tr_header_node, 'sessiondates'),
			   );
  foreach (array('title', 'days', 'times', 'instructor', 'location') as $column_key)
    $section_offsets[$column_key] = school_crawl_table_resolve_column($tr_header_node, $column_key);
  /* there's also a column for ``session dates'' */

  /* error check and calculate the number of children that a node must have to be  */
  $max_offset = 0;
  foreach ($section_offsets as $name => $value)
    {
      if ($value === FALSE)
	{
	  school_crawl_logf($school_crawl_log, 0, "Unable to find column offset for `%s'.",
		  $name);
	  return 1;
	}
      else
	school_crawl_logf($school_crawl_log, 9, "%s -> %s", $name, $value);

      $max_offset = max($max_offset, $value);
    }
      
  foreach ($courses_xpath->query('//table[@class="datadisplaytable" and position()=1]//tr') as $tr_node)
    {
      $children = school_crawl_table_rownodes($tr_node);
      if ($children->length < $max_offset)
	/*
	 * Skip this row because it doesn't have all of the columns we
	 * want and thus it can't be a row containing information
	 * about a section.
	 */
	continue;
      if (!strcmp($children->item($section_offsets['section_id'])->tagName, 'th'))
	/*
	 * We've hit one of the <tr/>s filled with <th/>s. Skip this one.
	 */
	continue;

      /*
       * There are some rows with the time set to TBA and with empty
       * section_id columns. Respond to this by skipping empty
       * section_id columns since there's no useful data in these
       * rows. We use strlen() < 3 because trim() doesn't take care of
       * &nbsp; :-/
       */
      $section_id = trim($children->item($section_offsets['section_id'])->textContent);
      if (strlen($section_id) < 3)
	continue;

      $section_id_parts = Section::parse($section_id);

      $registration_number = $children->item($section_offsets['registration_number'])->textContent;
      $instructor = $children->item($section_offsets['instructor'])->textContent;

      $section_meetings = array();
      {
	$time_range_text = $children->item($section_offsets['times'])->textContent;
	if (strpos($time_range_text, 'TBA') !== FALSE)
	  {
	    /*
	     * Add the section to the autocomplete list, just without
	     * any meeting info (i.e., $section_meetings is still
	     * empty now).
	     */
	    $semester->section_add($section_id_parts['department'], $section_id_parts['course'],
				   new Section($section_id_parts['section'], $section_meetings, $registration_number));
	    continue;

	  }
	if (($dash_pos = strpos($time_range_text, '-')) === FALSE)
	  {
	    school_crawl_logf($school_crawl_log, 0, "Unable to understand course's time range format, cannot find dash: ``%s''.",
		    $time_range_text);
	    return 1;
	  }

	$time_start_text = substr($time_range_text, 0, $dash_pos);
	$time_start = strptime($time_start_text, '%I:%M %p');
	$time_end_text = substr($time_range_text, $dash_pos + 1);
	/*
	 * Make sure that _only_ one date range is specified to ensure
	 * data integrity. I.e., make sure that the college doesn't
	 * suddenly support multiple meeting times without our
	 * anticipating that and then cause us to have invalid
	 * data. ;-). --binki
	 */
	if (strpos($time_end_text, '-') !== FALSE)
	  {
	    school_crawl_logf($school_crawl_log, 0, "College seems to support multiple meeting times per semester which we don't know how to parse (even though slate_permutate itself can handle this situation): ``%s'' time_end_text: ``%s''.",
		    $time_range_text, $time_end_text);
	    return 1;
	  }
	$time_end = strptime($time_end_text, '%I:%M %p');
	if ($time_end === FALSE || $time_start === FALSE)
	  {
	    school_crawl_logf($school_crawl_log, 0, "Error parsing start or end time: start: ``%s'' end: ``%s''.",
		    $time_start_text, $time_end_text);
	    return 1;
	  }

	$days = school_crawl_days_str_format($school_crawl_log, $children->item($section_offsets['days'])->textContent);

	$section_meetings[] = new SectionMeeting($days, school_crawl_time_format($time_start), school_crawl_time_format($time_end),
						 $children->item($section_offsets['location'])->textContent,
						 $instructor);

	/* check if a semester's date range should be increased */
	$section_dates = $children->item($section_offsets['dates'])->textContent;
	if (preg_match(';^([0-9]+)/([0-9]+)-([0-9]+)/([0-9]+)$;', $section_dates, $section_dates_matches))
	  {
	    $semester->time_start_set_test(gmmktime(0, 0, 0, $section_dates_matches[1], $section_dates_matches[2], $semester->year_get()));
	    $semester->time_end_set_test(gmmktime(0, 0, 0, $section_dates_matches[3], $section_dates_matches[4], $semester->year_get()));
	  }
      }

      $semester->section_add($section_id_parts['department'], $section_id_parts['course'],
			     new Section($section_id_parts['section'], $section_meetings, $registration_number));
    }

  return 0;
}

/**
 * \brief
 *   Crawl CCBCMD's registration stuffage.
 *
 * \param $semesters
 *   The array of Semester objects which I should populate.
 * \param $school_crawl_log
 *   The school_crawl_log handle.
 * \return
 *   1 on failure, 0 on success.
 */
function ccbcmd_crawl(array &$semesters, &$school_crawl_log)
{
  $cookies = array();

  /*
   * It seems that http://ccbcmd.edu/schedule/sched.html is what we're
   * meant to start from. That's just a redirect to some other page
   * from which we get a listing of available semesters and choose
   * one.
   */
  $uri = 'http://ccbcmd.edu/schedule/sched.html';
  $semesters_dom = new DOMDocument();
  $semesters_dom->loadHTML(school_crawl_geturi($uri, $cookies, $school_crawl_log, NULL, TRUE, 'ccbcmd_crawl_curlhook'));
  $semesters_select_node = $semesters_dom->getElementById('term_input_id');
  if ($semesters_select_node === NULL)
    {
      school_crawl_logf($school_crawl_log, 0, "Could not get list of available semesters to choose from.");
      return 1;
    }

  $semester_stage_uri = $uri;

  $semesters_form = school_crawl_element_ancestor($semesters_select_node, 'form');
  if ($semesters_form === NULL)
    {
      school_crawl_logf($school_crawl_log, 0, "Unable to find <form /> associated with semester.");
      return 1;
    }
  $semesters_post_save = school_crawl_form($semesters_form);

  foreach ($semesters_select_node->childNodes as $semesters_option_node)
    {
      $semester_text = $semesters_option_node->textContent;
      $semester_value = $semesters_option_node->getAttribute('value');
      if (empty($semester_value))
	/* skip the empty ``None'' semester */
	continue;

      if (stripos($semester_text, 'continuing') !== FALSE)
	/* skip the year-long semesters dedicated to continuing education */
	continue;

      $semester_text_parts = explode(' ', $semester_text);
      $semester_season = $semester_text_parts[0];
      $semester_year = $semester_text_parts[1];

      /* the college has two separate summer sessions, so distinguish between them */
      if (preg_match(';session ([0-9]+);i', $semester_text, $matches))
	$semester_season .= '_' . $matches[1];

      school_crawl_logf($school_crawl_log, 6, "Crawling semester %s:%s -> %s.", $semester_year, $semester_season, trim($semester_text));
      $semester = new Semester($semester_year, strtolower($semester_season));

      school_crawl_logf($school_crawl_log, 8, "Found semester: %s=``%s''=``%s''.",
			$semester_value, $semester->id(), trim($semesters_option_node->textContent));
  /* load stored semester-page URI / form data */
  $semesters_post = $semesters_post_save;
  $uri = $semester_stage_uri;
  $semesters_post[$semesters_select_node->getAttribute('name')] = $semester_value;

  $subjects_dom = new DOMDocument();
  $uri = school_crawl_url($uri, $semesters_form->getAttribute('action'));
  $subjects_dom->loadHTML(school_crawl_geturi($uri, $cookies, $school_crawl_log, $semesters_post, TRUE, 'ccbcmd_crawl_curlhook'));

  $subjects_form_nodelist = $subjects_dom->getElementsByTagName('form');
  if (!$subjects_form_nodelist->length)
    {
      school_crawl_logf($school_crawl_log, 0, "Unable to find <form /> to submit for the subjects-choosing page.");
      return 1;
    }
  $subjects_form_node = $subjects_form_nodelist->item(0);
  $subjects_post = school_crawl_form($subjects_form_node);

  $subjects_select_node = $subjects_dom->getElementById('subj_id');
  foreach ($subjects_select_node->childNodes as $subjects_option_node)
    if (!strcasecmp('all', trim($subjects_option_node->textContent)))
      $subjects_post[$subjects_select_node->getAttribute('name')][] = $subjects_option_node->getAttribute('value');

  $courses_dom = new DOMDocument();
  $uri = school_crawl_url($uri, $subjects_form_node->getAttribute('action'));
  $courses_dom->loadHTML(school_crawl_geturi($uri, $cookies, $school_crawl_log, $subjects_post, TRUE, 'ccbcmd_crawl_curlhook'));

  $courses_xpath = new DOMXPath($courses_dom);

  /* The second row of the table has all of the headers in it */
  $tr_header_nodelist = $courses_xpath->query('//table[@class="datadisplaytable" and position()=1]//tr[position()=2]');
  if (!$tr_header_nodelist->length)
    {
      school_crawl_logf($school_crawl_log, 0, "Unable to find the row of the course/section data table which gives us the mappings of column names onto columns.");
      return 1;
    }
  $tr_header_node = $tr_header_nodelist->item(0);

  $section_offsets = array(
			   'registration_number' => school_crawl_table_resolve_column($tr_header_node, 'CRN'),
			   'section_id' => school_crawl_table_resolve_column($tr_header_node, 'subj/crse/sec'),
			   /* there's a boolean column which says whether or not the course has any prerequisites/corequisites.... */
			   'credits' => school_crawl_table_resolve_column($tr_header_node, 'credhrs'),
			   /* there's a column for the number of contact hours, vs. credit hours */
			   'dates' => school_crawl_table_resolve_column($tr_header_node, 'sessiondates'),
			   );
  foreach (array('title', 'days', 'times', 'instructor', 'location') as $column_key)
    $section_offsets[$column_key] = school_crawl_table_resolve_column($tr_header_node, $column_key);
  /* there's also a column for ``session dates'' */

  /* error check and calculate the number of children that a node must have to be  */
  $max_offset = 0;
  foreach ($section_offsets as $name => $value)
    {
      if ($value === FALSE)
	{
	  school_crawl_logf($school_crawl_log, 0, "Unable to find column offset for `%s'.",
		  $name);
	  return 1;
	}
      else
	school_crawl_logf($school_crawl_log, 9, "%s -> %s", $name, $value);

      $max_offset = max($max_offset, $value);
    }
      
  foreach ($courses_xpath->query('//table[@class="datadisplaytable" and position()=1]//tr') as $tr_node)
    {
      $children = school_crawl_table_rownodes($tr_node);
      if ($children->length < $max_offset)
	/*
	 * Skip this row because it doesn't have all of the columns we
	 * want and thus it can't be a row containing information
	 * about a section.
	 */
	continue;
      if (!strcmp($children->item($section_offsets['section_id'])->tagName, 'th'))
	/*
	 * We've hit one of the <tr/>s filled with <th/>s. Skip this one.
	 */
	continue;

      /*
       * There are some rows with the time set to TBA and with empty
       * section_id columns. Respond to this by skipping empty
       * section_id columns since there's no useful data in these
       * rows. We use strlen() < 3 because trim() doesn't take care of
       * &nbsp; :-/
       */
      $section_id = trim($children->item($section_offsets['section_id'])->textContent);
      if (strlen($section_id) < 3)
	continue;

      $section_id_parts = Section::parse($section_id);

      $registration_number = $children->item($section_offsets['registration_number'])->textContent;
      $instructor = $children->item($section_offsets['instructor'])->textContent;

      $section_meetings = array();
      {
	$time_range_text = $children->item($section_offsets['times'])->textContent;
	if (strpos($time_range_text, 'TBA') !== FALSE)
	  {
	    /*
	     * Add the section to the autocomplete list, just without
	     * any meeting info (i.e., $section_meetings is still
	     * empty now).
	     */
	    $semester->section_add($section_id_parts['department'], $section_id_parts['course'],
				   new Section($section_id_parts['section'], $section_meetings, $registration_number));
	    continue;

	  }
	if (($dash_pos = strpos($time_range_text, '-')) === FALSE)
	  {
	    school_crawl_logf($school_crawl_log, 0, "Unable to understand course's time range format, cannot find dash: ``%s''.",
		    $time_range_text);
	    return 1;
	  }

	$time_start_text = substr($time_range_text, 0, $dash_pos);
	$time_start = strptime($time_start_text, '%I:%M %p');
	$time_end_text = substr($time_range_text, $dash_pos + 1);
	/*
	 * Make sure that _only_ one date range is specified to ensure
	 * data integrity. I.e., make sure that the college doesn't
	 * suddenly support multiple meeting times without our
	 * anticipating that and then cause us to have invalid
	 * data. ;-). --binki
	 */
	if (strpos($time_end_text, '-') !== FALSE)
	  {
	    school_crawl_logf($school_crawl_log, 0, "College seems to support multiple meeting times per semester which we don't know how to parse (even though slate_permutate itself can handle this situation): ``%s'' time_end_text: ``%s''.",
		    $time_range_text, $time_end_text);
	    return 1;
	  }
	$time_end = strptime($time_end_text, '%I:%M %p');
	if ($time_end === FALSE || $time_start === FALSE)
	  {
	    school_crawl_logf($school_crawl_log, 0, "Error parsing start or end time: start: ``%s'' end: ``%s''.",
		    $time_start_text, $time_end_text);
	    return 1;
	  }

	$days = school_crawl_days_str_format($school_crawl_log, $children->item($section_offsets['days'])->textContent);

	$section_meetings[] = new SectionMeeting($days, school_crawl_time_format($time_start), school_crawl_time_format($time_end),
						 $children->item($section_offsets['location'])->textContent,
						 $instructor);

	/* check if a semester's date range should be increased */
	$section_dates = $children->item($section_offsets['dates'])->textContent;
	if (preg_match(';^([0-9]+)/([0-9]+)-([0-9]+)/([0-9]+)$;', $section_dates, $section_dates_matches))
	  {
	    $semester->time_start_set_test(mktime(0, 0, 0, $section_dates_matches[1], $section_dates_matches[2], $semester->year_get()));
	    $semester->time_end_set_test(  mktime(0, 0, 0, $section_dates_matches[3], $section_dates_matches[4], $semester->year_get()));
	  }
      }

      $semester->section_add($section_id_parts['department'], $section_id_parts['course'],
			     new Section($section_id_parts['section'], $section_meetings, $registration_number));
    }

  $semesters[] = $semester;
    }

  return 0;
}

function ccbcmd_crawl_curlhook(&$curl)
{
  /*
   * OK, so this must be set to SSLv2 or SSLv3 because of how the
   * server's SSL junk is messed up. When curl is built against
   * gnutls, though, we can't use SSL2 since it doesn't support that
   * old of a protocol. So, we use 3 which works. Apparently, the
   * server can't handle gnutls's attempt to use TLS. Even openssl's
   * s_client command fails without manually specifying --ssl2 or
   * --ssl3. So, this must be a _really_ weird server setup...
   */
  curl_setopt($curl, CURLOPT_SSLVERSION, 3);
}