Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //NOTE: THIS IS A SIMPLE SCRIPT I MADE WHICH GETS A LIST OF PDF FILES IN A DIRECTORY AND LOADS THE FILENAMES INTO AN XML DOCUMENT
- // THIS CLASS CHECKS THE URL VARIABLES, AND DECIDES WHETHER TO RUN THE SPIDER, OR DISPLAY THE XML FILE
- class mainHandler {
- public function __construct() {
- $insert = '';
- $action = $_GET['action'];
- if ($action == "scrape") {
- $obj = new spider('single');
- }
- elseif ($action == "display") {
- $obj = new outputXML("data.xml");
- }
- $obj->outputPage();
- }
- }
- class pageDisplay {
- protected $page_body;
- function outputPage() {
- echo '<h1>Scraper</h1>';
- $page_body = $this->getProperty("page_body");
- echo $page_body;
- }
- public function setPageBody($page_body,$value) {
- $this->$page_body .= $value;
- }
- public function getPageBody() {
- return $this->$page_body;
- }
- }
- class spider extends pageDisplay {
- // THIS IS LIKE THE OPTIONS LIST WHERE THE USER CAN CHANGE THE WAY THE APPLICATION RUNS, I STILL DONT KNOW THE CORRECT WAY TO DO THIS
- function configData() {
- $file_data['xml_name'] = "chemistry1";
- $file_data['cats'] = array('science','chemistry');
- $file_data['doc_type'] = "book";
- $file_data['root_dir'] = "/home/files/books";
- return $file_data;
- }
- public function __construct() {
- $this->mainHandler();
- }
- function mainHandler() {
- // THE MAIN FUNCTION THAT RUNS ALL THE OTHER FUNCTIONS
- $file_data = $this->configData();
- $cmd = "sudo ls -A " . $file_data['root_dir'];
- $scraped_data = $this->runSudoCommand($cmd,'password');
- $files = $this->generateFileList($file_data['root_dir'],$scraped_data);
- $this->generateXML($files,$file_data['xml_name'],$file_data);
- $this->displayOutput($files);
- }
- function runSudoCommand($cmd,$pwd) {
- // CODE OMITTED: THIS FUNCTION JUST RUNS THE LINUX LS COMMAND AND RETURNS THE OUTPUT
- return $cmd_output;
- }
- function generateFileList($cmd_dir,$scraped_data) {
- // CODE OMITTED: THIS FUNCTION JUST LOADS THE LIST OF FILES INTO AN ARRAY
- return $output;
- }
- function displayOutput($items) {
- $num_dirs = count($items['dir']);
- $num_docs = count($items['doc']);
- $this->setProperty("page_body","<p>Number of directories: $num_dirs</p>");
- }
- function generateXML($files,$xml_name,$file_data) {
- // CODE OMITTED: THIS FUNCTION LOADS THE FILES INTO AN XML FILE
- }
- }
- // THIS FUNCTION IS TO DISPLAY THE CONTENTS ON THE XML FILE, HAVENT MADE IT YET
- class outputXML extends pageDisplay {
- public function __construct($xml_file) {
- }
- }
- $obj = new mainHandler();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement