mostly filebased Content Presentation System

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace Modules;
  3. class Ography {
  4. public $entries = array();
  5. function __construct($path="./default.csv",$header=TRUE) {
  6. $raw = array();
  7. $row = 0;
  8. if(is_file($path))
  9. $file_handle = fopen($path,"r");
  10. if($file_handle) {
  11. while(($data = fgetcsv($file_handle,1000, ",")) !== FALSE) {
  12. if(!$row) {
  13. if($header) {
  14. $keys = $data;
  15. $row++;
  16. continue;
  17. } else {
  18. $keys = FALSE;
  19. }
  20. }
  21. if(is_array($keys)) {
  22. $num = count($data);
  23. $temp = array();
  24. for($c=0; $c<$num; $c++) {
  25. $temp[$keys[$c]] = $data[$c];
  26. }
  27. array_push($this->entries, $temp);
  28. $row++;
  29. unset($temp);
  30. } else {
  31. array_push($this->entries, $data);
  32. }
  33. }
  34. fclose($file_handle);
  35. }
  36. }
  37. static function filter_field($key,$function) {
  38. if(function_exists($function)) {
  39. foreach ($this->entries as $k=>$entry) {
  40. $this->entries[$k][$key]=call_user_func($function,$entry[$key]);
  41. }
  42. return TRUE;
  43. } else {
  44. return FALSE;
  45. }
  46. }
  47. static function get_item() {
  48. return array();
  49. }
  50. }