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