Elgg  Version 1.11
ViewComponent.php
Go to the documentation of this file.
1 <?php
2 
4 
14 
18  public $location;
19 
23  public $view;
24 
28  public $extension = null;
29 
33  public $overridden = false;
34 
38  public function getFile() {
39  $ext = pathinfo($this->view, PATHINFO_EXTENSION);
40  if ($ext) {
41  // view is filename
42  return "{$this->location}{$this->view}";
43  }
44 
45  $str = "{$this->location}{$this->view}.{$this->extension}";
46  if ($this->extension === null) {
47  // try to guess from filesystem
48  $files = glob("{$this->location}{$this->view}.*");
49  if (count($files) === 1) {
50  $str = $files[0];
51  } else {
52  $str = "{$this->location}{$this->view}.?";
53  }
54  }
55 
56  return $str;
57  }
58 
67  public static function fromPaths($path, $location) {
68  $component = new self();
69  $component->location = $location;
70 
71  // cut location off
72  $file = substr($path, strlen($location));
73  $component->file = $file;
74 
75  $basename = basename($file);
76  $period = strpos($basename, '.');
77  if ($period === false) {
78  // file with no extension? shouldn't happen
79  $component->view = $file;
80  $component->extension = '';
81  } else {
82  $cut_off_end = strlen($basename) - $period;
83  $component->view = substr($file, 0, -$cut_off_end);
84  $component->extension = substr($basename, $period + 1);
85  }
86 
87  return $component;
88  }
89 }
$CONFIG view
The current view type.
Definition: config.php:192
$files
Definition: crop.php:36
static fromPaths($path, $location)
Get a component from the path and location.
$path
Definition: invalid.php:17