Elgg  Version 3.0
ViewFilter.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Amd;
4 
16 class ViewFilter {
24  private function getAmdName($name) {
25  if (preg_match('~^(js/)?(.+)\\.js\\z~', $name, $m)) {
26  // "js/foo/bar.js" or "foo/bar.js"
27  return $m[2];
28  }
29 
30  // must be in "js/" dir
31  if (0 !== strpos($name, 'js/')) {
32  return '';
33  }
34  $name = substr($name, 3);
35 
36  // Don't allow extension. We matched ".js" above
37  if (pathinfo($name, PATHINFO_EXTENSION) !== null) {
38  return '';
39  }
40 
41  // "foo/bar"
42  return $name;
43  }
44 
53  public function filter($viewName, $content) {
54  $amdName = $this->getAmdName($viewName);
55 
56  if (!empty($amdName)) {
57  $content = preg_replace('/^(\s*)define\(([^\'"])/m', "\${1}define(\"$amdName\", \$2", $content, 1);
58  }
59 
60  return $content;
61  }
62 }
if(!$user||!$user->canDelete()) $name
Definition: delete.php:22
filter($viewName, $content)
Inserts the AMD name into $content and returns the new value.
Definition: ViewFilter.php:53
$content
Set robots.txt action.
Definition: set_robots.php:6