symphonycms /
symphony-2
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * @package content |
||
| 4 | */ |
||
| 5 | /** |
||
| 6 | * The AjaxParameters returns an JSON array of all available parameters. |
||
| 7 | */ |
||
| 8 | |||
| 9 | class contentAjaxParameters extends JSONPage |
||
|
0 ignored issues
–
show
|
|||
| 10 | { |
||
| 11 | private $template = '$%s'; |
||
| 12 | |||
| 13 | public function view() |
||
| 14 | { |
||
| 15 | $params = array(); |
||
| 16 | $filter = $_GET['query']; |
||
| 17 | |||
| 18 | if ($_GET['template']) { |
||
| 19 | $this->template = General::sanitize($_GET['template']); |
||
| 20 | } |
||
| 21 | |||
| 22 | // Environment parameters |
||
| 23 | if ($filter == 'env') { |
||
| 24 | $params = array_merge($params, $this->__getEnvParams()); |
||
| 25 | |||
| 26 | // Page parameters |
||
| 27 | } elseif ($filter == 'page') { |
||
| 28 | $params = array_merge($params, $this->__getPageParams()); |
||
| 29 | |||
| 30 | // Data source parameters |
||
| 31 | } elseif ($filter == 'ds') { |
||
| 32 | $params = array_merge($params, $this->__getDSParams()); |
||
| 33 | |||
| 34 | // All parameters |
||
| 35 | } else { |
||
| 36 | $params = array_merge($params, $this->__getEnvParams()); |
||
| 37 | $params = array_merge($params, $this->__getPageParams()); |
||
| 38 | $params = array_merge($params, $this->__getDSParams()); |
||
| 39 | } |
||
| 40 | |||
| 41 | foreach ($params as $param) { |
||
| 42 | if (empty($filter) || strripos($param, $filter) !== false) { |
||
| 43 | $this->_Result[] = $param; |
||
| 44 | } |
||
| 45 | } |
||
| 46 | |||
| 47 | sort($this->_Result); |
||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Utilities |
||
| 52 | */ |
||
| 53 | private function __getEnvParams() |
||
| 54 | { |
||
| 55 | $params = array(); |
||
| 56 | $env = array('today', 'current-time', 'this-year', 'this-month', 'this-day', 'timezone', 'website-name', 'page-title', 'root', 'workspace', 'root-page', 'current-page', 'current-page-id', 'current-path', 'current-query-string', 'current-url', 'cookie-username', 'cookie-pass', 'page-types', 'upload-limit'); |
||
| 57 | |||
| 58 | foreach ($env as $param) { |
||
| 59 | $params[] = sprintf($this->template, $param); |
||
| 60 | } |
||
| 61 | |||
| 62 | return $params; |
||
| 63 | } |
||
| 64 | |||
| 65 | private function __getPageParams() |
||
| 66 | { |
||
| 67 | $params = array(); |
||
| 68 | $pages = PageManager::fetch(true, array('params')); |
||
| 69 | |||
| 70 | foreach ($pages as $key => $pageparams) { |
||
| 71 | if (empty($pageparams['params'])) { |
||
| 72 | continue; |
||
| 73 | } |
||
| 74 | |||
| 75 | $pageparams = explode('/', $pageparams['params']); |
||
| 76 | |||
| 77 | foreach ($pageparams as $pageparam) { |
||
| 78 | $param = sprintf($this->template, $pageparam); |
||
| 79 | |||
| 80 | if (!in_array($param, $params)) { |
||
| 81 | $params[] = $param; |
||
| 82 | } |
||
| 83 | } |
||
| 84 | } |
||
| 85 | |||
| 86 | return $params; |
||
| 87 | } |
||
| 88 | |||
| 89 | private function __getDSParams() |
||
| 90 | { |
||
| 91 | $params = array(); |
||
| 92 | $datasources = DatasourceManager::listAll(); |
||
| 93 | |||
| 94 | foreach ($datasources as $datasource) { |
||
| 95 | $current = DatasourceManager::create($datasource['handle'], array(), false); |
||
| 96 | |||
| 97 | // Get parameters |
||
| 98 | if (is_array($current->dsParamPARAMOUTPUT)) { |
||
| 99 | foreach ($current->dsParamPARAMOUTPUT as $id => $param) { |
||
| 100 | $params[] = sprintf($this->template, 'ds-' . Lang::createHandle($datasource['name']) . '.' . Lang::createHandle($param)); |
||
| 101 | } |
||
| 102 | } |
||
| 103 | } |
||
| 104 | |||
| 105 | return $params; |
||
| 106 | } |
||
| 107 | } |
||
| 108 |
Classes in PHP are usually named in CamelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.
Thus the name database provider becomes
DatabaseProvider.