TYPO3 CMS  TYPO3_6-2
AbstractNode.php
Go to the documentation of this file.
1 <?php
3 
18 
22 abstract class AbstractNode {
23 
27  protected $name = '';
28 
32  protected $targetPermission = NULL;
33 
37  protected $parent = NULL;
38 
42  protected $children = array();
43 
49  public function getName() {
50  return $this->name;
51  }
52 
60  protected function getTargetPermission() {
62  }
63 
71  protected function setTargetPermission($permission) {
72  // Normalize the permission string to "4 characters", padding with leading "0" if necessary:
73  $permission = substr($permission, 0, 4);
74  $permission = str_pad($permission, 4, '0', STR_PAD_LEFT);
75  $this->targetPermission = $permission;
76  }
77 
83  protected function getChildren() {
84  return $this->children;
85  }
86 
92  protected function getParent() {
93  return $this->parent;
94  }
95 
101  public function getAbsolutePath() {
102  return $this->getParent()->getAbsolutePath() . '/' . $this->name;
103  }
104 
110  public function isWritable() {
111  return $this->getParent()->isWritable();
112  }
113 
121  protected function exists() {
122  if (@is_link($this->getAbsolutePath())) {
123  return TRUE;
124  } else {
125  return @file_exists($this->getAbsolutePath());
126  }
127  }
128 
135  protected function fixPermission() {
136  if ($this->isPermissionCorrect()) {
137  throw new Exception(
138  'Permission on ' . $this->getAbsolutePath() . ' are already ok',
139  1366744035
140  );
141  }
142  $result = @chmod($this->getAbsolutePath(), octdec($this->getTargetPermission()));
143  if ($result === TRUE) {
144  $status = new Status\OkStatus();
145  $status->setTitle('Fixed permission on ' . $this->getRelativePathBelowSiteRoot() . '.');
146  } else {
147  $status = new Status\NoticeStatus();
148  $status->setTitle('Permission change on ' . $this->getRelativePathBelowSiteRoot() . ' not successful');
149  $status->setMessage(
150  'Permissions could not be changed to ' . $this->getTargetPermission() .
151  '. This only is a problem if files and folders within this node cannot be written.'
152  );
153  }
154  return $status;
155  }
156 
162  protected function isPermissionCorrect() {
163  if ($this->isWindowsOs()) {
164  return TRUE;
165  }
166  if ($this->getCurrentPermission() === $this->getTargetPermission()) {
167  return TRUE;
168  } else {
169  return FALSE;
170  }
171  }
172 
178  protected function getCurrentPermission() {
179  $permissions = decoct(fileperms($this->getAbsolutePath()));
180  return substr($permissions, -4);
181  }
182 
188  protected function isWindowsOs() {
189  if (TYPO3_OS === 'WIN') {
190  return TRUE;
191  }
192  return FALSE;
193  }
194 
202  protected function getRelativePathBelowSiteRoot($path = NULL) {
203  if (is_null($path)) {
204  $path = $this->getAbsolutePath();
205  }
206  $pathSiteWithoutTrailingSlash = substr(PATH_site, 0, -1);
207  if (strpos($path, $pathSiteWithoutTrailingSlash, 0) !== 0) {
208  throw new \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException(
209  'PATH_site is not first part of given path',
210  1366398198
211  );
212  }
213  $relativePath = substr($path, strlen($pathSiteWithoutTrailingSlash), strlen($path));
214  // Add a forward slash again, so we don't end up with an empty string
215  if (strlen($relativePath) === 0) {
216  $relativePath = '/';
217  }
218  return $relativePath;
219  }
220 }
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren&#39;t numeric.