Advertisement
Guest User

php file

a guest
Sep 19th, 2013
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. <?php
  2.  
  3. //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
  4.  
  5. // THIS CLASS CHECKS THE URL VARIABLES, AND DECIDES WHETHER TO RUN THE SPIDER, OR DISPLAY THE XML FILE
  6. class mainHandler {
  7.  
  8. public function __construct() {
  9.  
  10. $insert = '';
  11.  
  12. $action = $_GET['action'];
  13.  
  14. if ($action == "scrape") {
  15. $obj = new spider('single');
  16. }
  17.  
  18. elseif ($action == "display") {
  19. $obj = new outputXML("data.xml");
  20. }
  21.  
  22. $obj->outputPage();
  23.  
  24. }
  25.  
  26. }
  27.  
  28. class pageDisplay {
  29.  
  30. protected $page_body;
  31.  
  32. function outputPage() {
  33.  
  34. echo '<h1>Scraper</h1>';
  35.  
  36. $page_body = $this->getProperty("page_body");
  37.  
  38. echo $page_body;
  39.  
  40. }
  41.  
  42. public function setPageBody($page_body,$value) {
  43.  
  44. $this->$page_body .= $value;
  45.  
  46. }
  47.  
  48. public function getPageBody() {
  49.  
  50. return $this->$page_body;
  51.  
  52. }
  53.  
  54. }
  55.  
  56. class spider extends pageDisplay {
  57.  
  58. // 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
  59. function configData() {
  60.  
  61. $file_data['xml_name'] = "chemistry1";
  62. $file_data['cats'] = array('science','chemistry');
  63. $file_data['doc_type'] = "book";
  64. $file_data['root_dir'] = "/home/files/books";
  65.  
  66. return $file_data;
  67.  
  68. }
  69.  
  70. public function __construct() {
  71.  
  72. $this->mainHandler();
  73.  
  74. }
  75.  
  76. function mainHandler() {
  77.  
  78. // THE MAIN FUNCTION THAT RUNS ALL THE OTHER FUNCTIONS
  79.  
  80. $file_data = $this->configData();
  81.  
  82. $cmd = "sudo ls -A " . $file_data['root_dir'];
  83.  
  84. $scraped_data = $this->runSudoCommand($cmd,'password');
  85.  
  86. $files = $this->generateFileList($file_data['root_dir'],$scraped_data);
  87.  
  88. $this->generateXML($files,$file_data['xml_name'],$file_data);
  89.  
  90. $this->displayOutput($files);
  91.  
  92. }
  93.  
  94.  
  95.  
  96. function runSudoCommand($cmd,$pwd) {
  97.  
  98. // CODE OMITTED: THIS FUNCTION JUST RUNS THE LINUX LS COMMAND AND RETURNS THE OUTPUT
  99.  
  100. return $cmd_output;
  101.  
  102. }
  103.  
  104.  
  105.  
  106. function generateFileList($cmd_dir,$scraped_data) {
  107.  
  108. // CODE OMITTED: THIS FUNCTION JUST LOADS THE LIST OF FILES INTO AN ARRAY
  109.  
  110. return $output;
  111.  
  112. }
  113.  
  114.  
  115. function displayOutput($items) {
  116.  
  117. $num_dirs = count($items['dir']);
  118. $num_docs = count($items['doc']);
  119.  
  120. $this->setProperty("page_body","<p>Number of directories: $num_dirs</p>");
  121.  
  122.  
  123. }
  124.  
  125. function generateXML($files,$xml_name,$file_data) {
  126.  
  127. // CODE OMITTED: THIS FUNCTION LOADS THE FILES INTO AN XML FILE
  128.  
  129. }
  130.  
  131.  
  132. }
  133.  
  134.  
  135. // THIS FUNCTION IS TO DISPLAY THE CONTENTS ON THE XML FILE, HAVENT MADE IT YET
  136. class outputXML extends pageDisplay {
  137.  
  138. public function __construct($xml_file) {
  139.  
  140. }
  141.  
  142. }
  143.  
  144. $obj = new mainHandler();
  145. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement