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