May
08
Download CSIS Notes quickly!
This handy little script will download all your coursework in a jip
youll need php 5 and mod php_curl!
<?php
class csisDownloader
{
private $courseTitles;
private $courseLinks;
private $moduleTitles;
private $moduleLinks;
private $documentCourseTitles;
private $documentModulesTitles;
private $documentTitles;
private $documentLinks;
public function __construct( $course , $modules )
{
if( strlen($course) != 0 )
{
$this->selectedCourse = $course;
}
if( count($modules) > 0 )
{
$this->selectedModules = $modules;
}
$this->fetchCourses();
}
private function fetchCourses()
{
echo "Start\n";
$this->downloader = curl_init();
curl_setopt( $this->downloader , CURLOPT_URL , "http://www.csis.ul.ie/currentstudents/" );
curl_setopt( $this->downloader , CURLOPT_USERAGENT , "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.4pre) Gecko/20090829 Ubuntu/9.04 (jaunty) Shiretoko/3.5.4pre" );
curl_setopt( $this->downloader , CURLOPT_TIMEOUT , '10' );
curl_setopt( $this->downloader , CURLOPT_FOLLOWLOCATION , 1 );
curl_setopt( $this->downloader , CURLOPT_RETURNTRANSFER , 1 );
$this->store = curl_exec( $this->downloader );
curl_close( $this->downloader );
echo "Got courses\n";
$data = explode( "UNDERGRADUATE COURSES" , $this->store );
$data = explode( "</div>" , $data[1] );
$data = preg_match_all( "/(<li>.*<\/li>)/" , $data[0] , $matches);
preg_match_all( "/<a href=\"([^\"]*)\">(.*)<\/a>/iU" ,$matches[0][0] , $temp1 );
preg_match_all( "/<a href=\"([^\"]*)\">(.*)<\/a>/iU" , $matches[1][1] , $temp2 );
$courses = array_merge( $temp1 , $temp2 );
$this->courseLinks = array_merge( $courses[1] , $courses[4] );
$this->courseTitles = array_merge( $courses[2] , $courses[5] );
for( $u = 0 ; $u < count( $this->courseLinks ); $u++ )
{
if( isset( $this->selectedCourse ) )
{
if( !stristr( $this->courseLinks[$u] , $this->selectedCourse ) )
{
continue;
}
}
$this->downloader = curl_init();
$url = "http://www.csis.ul.ie" . $this->courseLinks[$u];
curl_setopt( $this->downloader , CURLOPT_URL , $url );
curl_setopt( $this->downloader , CURLOPT_USERAGENT , "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.4pre) Gecko/20090829 Ubuntu/9.04 (jaunty) Shiretoko/3.5.4pre" );
curl_setopt( $this->downloader , CURLOPT_TIMEOUT , '10' );
curl_setopt( $this->downloader , CURLOPT_FOLLOWLOCATION , 1 );
curl_setopt( $this->downloader , CURLOPT_RETURNTRANSFER , 1 );
$this->store = curl_exec( $this->downloader );
$data = explode( "COURSE STRUCTURE SECTION STARTS" , $this->store );
$data = explode( "COURSE STRUCTURE SECTION ENDS" , $data[1] );
preg_match_all( "/<a href=\"([^\"]*)\">(.*)<\/a>/iUms" , $data[0] , $mods );
for( $y= 0 ; $y < count($mods[2]); $y++ )
{
$mods[2][$y] = trim( $mods[2][$y] );
}
$this->moduleLinks[$u] = $mods[1];
$this->moduleTitles[$u] = $mods[2];
curl_close( $this->downloader );
echo "Starting the modules\n";
for( $z = 0 ; $z < count( $this->moduleLinks[$u] ); $z++ )
{
print $this->courseLinks[$u] . " - " . $this->moduleLinks[$u][$z] . "\n";
$moduletitle = preg_replace( "/\/coursemodule\//" , "" , $this->moduleLinks[$u][$z] );
if( isset( $this->selectedModules ) )
{
if( !in_array( $moduletitle , $this->selectedModules ) )
{
continue;
}
}
for( $w = 1 ; $w < 17; $w++ )
{
$url = "http://www.csis.ul.ie" . $this->moduleLinks[$u][$z] . "/?wkid=" . $w;
$this->downloader = curl_init();
curl_setopt( $this->downloader , CURLOPT_URL , $url );
curl_setopt( $this->downloader , CURLOPT_USERAGENT , "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.4pre) Gecko/20090829 Ubuntu/9.04 (jaunty) Shiretoko/3.5.4pre" );
curl_setopt( $this->downloader , CURLOPT_TIMEOUT , '10' );
curl_setopt( $this->downloader , CURLOPT_FOLLOWLOCATION , 1 );
curl_setopt( $this->downloader , CURLOPT_RETURNTRANSFER , 1 );
$this->store = curl_exec( $this->downloader );
curl_close( $this->downloader );
$data = explode( "MODULE MATERIAL SECTION STARTS" , $this->store );
$data = explode( "MODULE MATERIAL SECTION ENDS" , $data[1] );
$data = explode( "<h2>" , $data[0] );
foreach( $data as $dt )
{
preg_match_all( '/<(a.*) href="(.*?)"(.*)>(.*)(<\/a>)/i' , $dt , $docs );
if( isset($docs[2][0]) != "" )
{
$this->documentTitles[] = substr( trim( $docs[4][0]) , 1 , -1 );
$this->documentLinks[] = trim( $docs[2][0] );
$this->documentCourseTitles[] = $this->courseTitles[$u];
$this->documentModulesTitles[] = $this->moduleTitles[$u][$z];
}
}
print $this->courseLinks[$u] . " - " . $this->moduleLinks[$u][$z] . " - " . $url . "\n";
}
for( $t = 0 ; $t < count( $this->documentCourseTitles ); $t++)
{
$this->downloadFile( $this->documentCourseTitles[$t] ,$this->documentModulesTitles[$t] , $this->documentTitles[$t] , $this->documentLinks[$t] );
}
unset($this->documentCourseTitles);
unset($this->documentModulesTitles);
unset($this->documentTitles);
unset($this->documentLinks);
}
}
}
private function downloadFile( $course , $module , $docTitle , $docUrl )
{
$course = preg_replace( "/\//" , "" , $course);
$moduletitle = $module;
$doc = $docTitle;
$url = $docUrl;
if( !file_exists( "coursework" ) )
{
mkdir( "coursework" );
}
if( !file_exists( "coursework/$course" ) )
{
mkdir( "coursework/$course" );
}
if( !file_exists( "coursework/$course/$moduletitle" ) )
{
mkdir( "coursework/$course/$moduletitle" );
}
$dir = "coursework/$course/$moduletitle";
if( !file_exists( $dir . "/" . $doc ) )
{
$url = preg_replace( "/&/i" , "&" , $url );
$url = preg_replace( "/amp;/i" , "" , $url );
$url = "http://www.csis.ul.ie" . $url;
$this->downloader = curl_init();
curl_setopt( $this->downloader , CURLOPT_URL , $url );
curl_setopt( $this->downloader , CURLOPT_USERAGENT , "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.4pre) Gecko/20090829 Ubuntu/9.04 (jaunty) Shiretoko/3.5.4pre" );
curl_setopt( $this->downloader , CURLOPT_TIMEOUT , '10' );
curl_setopt( $this->downloader , CURLOPT_FOLLOWLOCATION , 1 );
curl_setopt( $this->downloader , CURLOPT_RETURNTRANSFER , 1 );
$this->store = curl_exec ( $this->downloader );
curl_close( $this->downloader );
$docurl = preg_match( "/action=\"(.*)\" /" , $this->store , $matches );
$match = explode( "\"", $matches[1] );
$match = preg_replace( "/&/i" , "&" , $match[0] );
$match = preg_replace( "/amp;/i" , "" , $match );
$fp = fopen( $dir . "/" . $doc , 'w' );
$this->downloader = curl_init();
curl_setopt( $this->downloader , CURLOPT_URL , $match );
curl_setopt( $this->downloader , CURLOPT_USERAGENT , "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.4pre) Gecko/20090829 Ubuntu/9.04 (jaunty) Shiretoko/3.5.4pre" );
curl_setopt( $this->downloader , CURLOPT_HEADER, 0);
curl_setopt( $this->downloader , CURLOPT_FILE , $fp );
curl_exec( $this->downloader );
curl_close( $this->downloader );
fclose( $fp );
}
}
}
$course = "LM051";
$modules = array( "CS4416" );
new csisDownloader( $course , $modules );
?>

It’s awesome but if you try to copy and paste it the line numbers are included. Had to stop the page mid-load so that it didn’t load that code viewer widget in order to copy it.
Any chance of a source link? I don’t think most people will bother deleting the numbers.
hey up at the top of the code on the right hand side are four little icons
Click on the one on the left