@@ -13,97 +13,97 @@ |
||
13 | 13 | |
14 | 14 | abstract class PagedInternalPageBase extends InternalPageBase |
15 | 15 | { |
16 | - /** @var SearchHelperBase */ |
|
17 | - private $searchHelper; |
|
18 | - private $page; |
|
19 | - private $limit; |
|
20 | - |
|
21 | - /** |
|
22 | - * Sets up the pager with the current page, current limit, and total number of records. |
|
23 | - * |
|
24 | - * @param int $count |
|
25 | - * @param array $formParameters |
|
26 | - */ |
|
27 | - protected function setupPageData($count, $formParameters) |
|
28 | - { |
|
29 | - $page = $this->page; |
|
30 | - $limit = $this->limit; |
|
31 | - |
|
32 | - // The number of pages on the pager to show. Must be odd |
|
33 | - $pageLimit = 9; |
|
34 | - |
|
35 | - $pageData = array( |
|
36 | - // Can the user go to the previous page? |
|
37 | - 'canprev' => $page != 1, |
|
38 | - // Can the user go to the next page? |
|
39 | - 'cannext' => ($page * $limit) < $count, |
|
40 | - // Maximum page number |
|
41 | - 'maxpage' => max(1, ceil($count / $limit)), |
|
42 | - // Limit to the number of pages to display |
|
43 | - 'pagelimit' => $pageLimit, |
|
44 | - ); |
|
45 | - |
|
46 | - // number of pages either side of the current to show |
|
47 | - $pageMargin = (($pageLimit - 1) / 2); |
|
48 | - |
|
49 | - // Calculate the number of pages either side to show - this is for situations like: |
|
50 | - // [1] [2] [[3]] [4] [5] [6] [7] [8] [9] - where you can't just use the page margin calculated |
|
51 | - $pageData['lowpage'] = max(1, $page - $pageMargin); |
|
52 | - $pageData['hipage'] = min($pageData['maxpage'], $page + $pageMargin); |
|
53 | - $pageCount = ($pageData['hipage'] - $pageData['lowpage']) + 1; |
|
54 | - |
|
55 | - if ($pageCount < $pageLimit) { |
|
56 | - if ($pageData['lowpage'] == 1 && $pageData['hipage'] < $pageData['maxpage']) { |
|
57 | - $pageData['hipage'] = min($pageLimit, $pageData['maxpage']); |
|
58 | - } |
|
59 | - elseif ($pageData['lowpage'] > 1 && $pageData['hipage'] == $pageData['maxpage']) { |
|
60 | - $pageData['lowpage'] = max(1, $pageData['maxpage'] - $pageLimit + 1); |
|
61 | - } |
|
62 | - } |
|
63 | - |
|
64 | - // Put the range of pages into the page data |
|
65 | - $pageData['pages'] = range($pageData['lowpage'], $pageData['hipage']); |
|
66 | - |
|
67 | - $this->assign("pagedata", $pageData); |
|
68 | - |
|
69 | - $this->assign("limit", $limit); |
|
70 | - $this->assign("page", $page); |
|
71 | - |
|
72 | - $this->setupFormParameters($formParameters); |
|
73 | - } |
|
74 | - |
|
75 | - protected function setSearchHelper(SearchHelperBase $searchHelper) |
|
76 | - { |
|
77 | - $this->searchHelper = $searchHelper; |
|
78 | - } |
|
79 | - |
|
80 | - protected function setupLimits() |
|
81 | - { |
|
82 | - $limit = WebRequest::getInt('limit'); |
|
83 | - if ($limit === null) { |
|
84 | - $limit = 100; |
|
85 | - } |
|
86 | - |
|
87 | - $page = WebRequest::getInt('page'); |
|
88 | - if ($page === null) { |
|
89 | - $page = 1; |
|
90 | - } |
|
91 | - |
|
92 | - $offset = ($page - 1) * $limit; |
|
93 | - |
|
94 | - $this->searchHelper->limit($limit, $offset); |
|
95 | - |
|
96 | - $this->page = $page; |
|
97 | - $this->limit = $limit; |
|
98 | - } |
|
99 | - |
|
100 | - private function setupFormParameters($formParameters) |
|
101 | - { |
|
102 | - $formParameters['limit'] = $this->limit; |
|
103 | - $this->assign('searchParamsUrl', http_build_query($formParameters, '', '&')); |
|
104 | - |
|
105 | - foreach ($formParameters as $key => $value) { |
|
106 | - $this->assign($key, $value); |
|
107 | - } |
|
108 | - } |
|
16 | + /** @var SearchHelperBase */ |
|
17 | + private $searchHelper; |
|
18 | + private $page; |
|
19 | + private $limit; |
|
20 | + |
|
21 | + /** |
|
22 | + * Sets up the pager with the current page, current limit, and total number of records. |
|
23 | + * |
|
24 | + * @param int $count |
|
25 | + * @param array $formParameters |
|
26 | + */ |
|
27 | + protected function setupPageData($count, $formParameters) |
|
28 | + { |
|
29 | + $page = $this->page; |
|
30 | + $limit = $this->limit; |
|
31 | + |
|
32 | + // The number of pages on the pager to show. Must be odd |
|
33 | + $pageLimit = 9; |
|
34 | + |
|
35 | + $pageData = array( |
|
36 | + // Can the user go to the previous page? |
|
37 | + 'canprev' => $page != 1, |
|
38 | + // Can the user go to the next page? |
|
39 | + 'cannext' => ($page * $limit) < $count, |
|
40 | + // Maximum page number |
|
41 | + 'maxpage' => max(1, ceil($count / $limit)), |
|
42 | + // Limit to the number of pages to display |
|
43 | + 'pagelimit' => $pageLimit, |
|
44 | + ); |
|
45 | + |
|
46 | + // number of pages either side of the current to show |
|
47 | + $pageMargin = (($pageLimit - 1) / 2); |
|
48 | + |
|
49 | + // Calculate the number of pages either side to show - this is for situations like: |
|
50 | + // [1] [2] [[3]] [4] [5] [6] [7] [8] [9] - where you can't just use the page margin calculated |
|
51 | + $pageData['lowpage'] = max(1, $page - $pageMargin); |
|
52 | + $pageData['hipage'] = min($pageData['maxpage'], $page + $pageMargin); |
|
53 | + $pageCount = ($pageData['hipage'] - $pageData['lowpage']) + 1; |
|
54 | + |
|
55 | + if ($pageCount < $pageLimit) { |
|
56 | + if ($pageData['lowpage'] == 1 && $pageData['hipage'] < $pageData['maxpage']) { |
|
57 | + $pageData['hipage'] = min($pageLimit, $pageData['maxpage']); |
|
58 | + } |
|
59 | + elseif ($pageData['lowpage'] > 1 && $pageData['hipage'] == $pageData['maxpage']) { |
|
60 | + $pageData['lowpage'] = max(1, $pageData['maxpage'] - $pageLimit + 1); |
|
61 | + } |
|
62 | + } |
|
63 | + |
|
64 | + // Put the range of pages into the page data |
|
65 | + $pageData['pages'] = range($pageData['lowpage'], $pageData['hipage']); |
|
66 | + |
|
67 | + $this->assign("pagedata", $pageData); |
|
68 | + |
|
69 | + $this->assign("limit", $limit); |
|
70 | + $this->assign("page", $page); |
|
71 | + |
|
72 | + $this->setupFormParameters($formParameters); |
|
73 | + } |
|
74 | + |
|
75 | + protected function setSearchHelper(SearchHelperBase $searchHelper) |
|
76 | + { |
|
77 | + $this->searchHelper = $searchHelper; |
|
78 | + } |
|
79 | + |
|
80 | + protected function setupLimits() |
|
81 | + { |
|
82 | + $limit = WebRequest::getInt('limit'); |
|
83 | + if ($limit === null) { |
|
84 | + $limit = 100; |
|
85 | + } |
|
86 | + |
|
87 | + $page = WebRequest::getInt('page'); |
|
88 | + if ($page === null) { |
|
89 | + $page = 1; |
|
90 | + } |
|
91 | + |
|
92 | + $offset = ($page - 1) * $limit; |
|
93 | + |
|
94 | + $this->searchHelper->limit($limit, $offset); |
|
95 | + |
|
96 | + $this->page = $page; |
|
97 | + $this->limit = $limit; |
|
98 | + } |
|
99 | + |
|
100 | + private function setupFormParameters($formParameters) |
|
101 | + { |
|
102 | + $formParameters['limit'] = $this->limit; |
|
103 | + $this->assign('searchParamsUrl', http_build_query($formParameters, '', '&')); |
|
104 | + |
|
105 | + foreach ($formParameters as $key => $value) { |
|
106 | + $this->assign($key, $value); |
|
107 | + } |
|
108 | + } |
|
109 | 109 | } |
@@ -14,68 +14,68 @@ |
||
14 | 14 | |
15 | 15 | abstract class JsonApiPageBase extends ApiPageBase implements IJsonApiAction |
16 | 16 | { |
17 | - /** |
|
18 | - * Main function for this page, when no specific actions are called. |
|
19 | - * |
|
20 | - * @return void |
|
21 | - * @throws ApiException |
|
22 | - */ |
|
23 | - final protected function main() |
|
24 | - { |
|
25 | - if (headers_sent()) { |
|
26 | - throw new ApiException('Headers have already been sent - this indicates a bug in the application!'); |
|
27 | - } |
|
17 | + /** |
|
18 | + * Main function for this page, when no specific actions are called. |
|
19 | + * |
|
20 | + * @return void |
|
21 | + * @throws ApiException |
|
22 | + */ |
|
23 | + final protected function main() |
|
24 | + { |
|
25 | + if (headers_sent()) { |
|
26 | + throw new ApiException('Headers have already been sent - this indicates a bug in the application!'); |
|
27 | + } |
|
28 | 28 | |
29 | - // javascript access control |
|
30 | - $httpOrigin = WebRequest::origin(); |
|
29 | + // javascript access control |
|
30 | + $httpOrigin = WebRequest::origin(); |
|
31 | 31 | |
32 | - if ($httpOrigin !== null) { |
|
33 | - $CORSallowed = $this->getSiteConfiguration()->getCrossOriginResourceSharingHosts(); |
|
32 | + if ($httpOrigin !== null) { |
|
33 | + $CORSallowed = $this->getSiteConfiguration()->getCrossOriginResourceSharingHosts(); |
|
34 | 34 | |
35 | - if (in_array($httpOrigin, $CORSallowed)) { |
|
36 | - header("Access-Control-Allow-Origin: " . $httpOrigin); |
|
37 | - } |
|
38 | - } |
|
35 | + if (in_array($httpOrigin, $CORSallowed)) { |
|
36 | + header("Access-Control-Allow-Origin: " . $httpOrigin); |
|
37 | + } |
|
38 | + } |
|
39 | 39 | |
40 | - $responseData = $this->runApiPage(); |
|
40 | + $responseData = $this->runApiPage(); |
|
41 | 41 | |
42 | - ob_end_clean(); |
|
43 | - print($responseData); |
|
44 | - ob_start(); |
|
45 | - } |
|
42 | + ob_end_clean(); |
|
43 | + print($responseData); |
|
44 | + ob_start(); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Method that runs API action |
|
49 | - * |
|
50 | - * @return object|array The modified API document |
|
51 | - */ |
|
52 | - public abstract function executeApiAction(); |
|
47 | + /** |
|
48 | + * Method that runs API action |
|
49 | + * |
|
50 | + * @return object|array The modified API document |
|
51 | + */ |
|
52 | + public abstract function executeApiAction(); |
|
53 | 53 | |
54 | - /** |
|
55 | - * @return string |
|
56 | - */ |
|
57 | - final public function runApiPage() |
|
58 | - { |
|
54 | + /** |
|
55 | + * @return string |
|
56 | + */ |
|
57 | + final public function runApiPage() |
|
58 | + { |
|
59 | 59 | |
60 | - try { |
|
61 | - $apiDocument = $this->executeApiAction(); |
|
62 | - } |
|
63 | - catch (ApiException $ex) { |
|
64 | - $apiDocument = [ |
|
65 | - 'error' => $ex->getMessage(), |
|
66 | - ]; |
|
67 | - } |
|
60 | + try { |
|
61 | + $apiDocument = $this->executeApiAction(); |
|
62 | + } |
|
63 | + catch (ApiException $ex) { |
|
64 | + $apiDocument = [ |
|
65 | + 'error' => $ex->getMessage(), |
|
66 | + ]; |
|
67 | + } |
|
68 | 68 | |
69 | - $data = json_encode($apiDocument, JSON_UNESCAPED_UNICODE); |
|
69 | + $data = json_encode($apiDocument, JSON_UNESCAPED_UNICODE); |
|
70 | 70 | |
71 | - $targetVar = WebRequest::getString('targetVariable'); |
|
72 | - if ($targetVar !== null && preg_match('/^[a-z]+$/', $targetVar)) { |
|
73 | - $data = $targetVar . ' = ' . $data . ';'; |
|
74 | - header("Content-Type: text/javascript"); |
|
75 | - } else { |
|
76 | - header("Content-Type: application/json"); |
|
77 | - } |
|
71 | + $targetVar = WebRequest::getString('targetVariable'); |
|
72 | + if ($targetVar !== null && preg_match('/^[a-z]+$/', $targetVar)) { |
|
73 | + $data = $targetVar . ' = ' . $data . ';'; |
|
74 | + header("Content-Type: text/javascript"); |
|
75 | + } else { |
|
76 | + header("Content-Type: application/json"); |
|
77 | + } |
|
78 | 78 | |
79 | - return $data; |
|
80 | - } |
|
79 | + return $data; |
|
80 | + } |
|
81 | 81 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | $CORSallowed = $this->getSiteConfiguration()->getCrossOriginResourceSharingHosts(); |
34 | 34 | |
35 | 35 | if (in_array($httpOrigin, $CORSallowed)) { |
36 | - header("Access-Control-Allow-Origin: " . $httpOrigin); |
|
36 | + header("Access-Control-Allow-Origin: ".$httpOrigin); |
|
37 | 37 | } |
38 | 38 | } |
39 | 39 | |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | |
71 | 71 | $targetVar = WebRequest::getString('targetVariable'); |
72 | 72 | if ($targetVar !== null && preg_match('/^[a-z]+$/', $targetVar)) { |
73 | - $data = $targetVar . ' = ' . $data . ';'; |
|
73 | + $data = $targetVar.' = '.$data.';'; |
|
74 | 74 | header("Content-Type: text/javascript"); |
75 | 75 | } else { |
76 | 76 | header("Content-Type: application/json"); |
@@ -72,7 +72,8 @@ |
||
72 | 72 | if ($targetVar !== null && preg_match('/^[a-z]+$/', $targetVar)) { |
73 | 73 | $data = $targetVar . ' = ' . $data . ';'; |
74 | 74 | header("Content-Type: text/javascript"); |
75 | - } else { |
|
75 | + } |
|
76 | + else { |
|
76 | 77 | header("Content-Type: application/json"); |
77 | 78 | } |
78 | 79 |