@@ -30,28 +30,28 @@ |
||
30 | 30 | |
31 | 31 | class ActionFactory implements IActionFactory { |
32 | 32 | |
33 | - /** |
|
34 | - * @param string $icon |
|
35 | - * @param string $name |
|
36 | - * @param string $href |
|
37 | - * @return ILinkAction |
|
38 | - */ |
|
39 | - public function newLinkAction($icon, $name, $href) { |
|
40 | - $action = new LinkAction(); |
|
41 | - $action->setName($name); |
|
42 | - $action->setIcon($icon); |
|
43 | - $action->setHref($href); |
|
44 | - return $action; |
|
45 | - } |
|
33 | + /** |
|
34 | + * @param string $icon |
|
35 | + * @param string $name |
|
36 | + * @param string $href |
|
37 | + * @return ILinkAction |
|
38 | + */ |
|
39 | + public function newLinkAction($icon, $name, $href) { |
|
40 | + $action = new LinkAction(); |
|
41 | + $action->setName($name); |
|
42 | + $action->setIcon($icon); |
|
43 | + $action->setHref($href); |
|
44 | + return $action; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * @param string $icon |
|
49 | - * @param string $name |
|
50 | - * @param string $email |
|
51 | - * @return ILinkAction |
|
52 | - */ |
|
53 | - public function newEMailAction($icon, $name, $email) { |
|
54 | - return $this->newLinkAction($icon, $name, 'mailto:' . urlencode($email)); |
|
55 | - } |
|
47 | + /** |
|
48 | + * @param string $icon |
|
49 | + * @param string $name |
|
50 | + * @param string $email |
|
51 | + * @return ILinkAction |
|
52 | + */ |
|
53 | + public function newEMailAction($icon, $name, $email) { |
|
54 | + return $this->newLinkAction($icon, $name, 'mailto:' . urlencode($email)); |
|
55 | + } |
|
56 | 56 | |
57 | 57 | } |
@@ -51,7 +51,7 @@ |
||
51 | 51 | * @return ILinkAction |
52 | 52 | */ |
53 | 53 | public function newEMailAction($icon, $name, $email) { |
54 | - return $this->newLinkAction($icon, $name, 'mailto:' . urlencode($email)); |
|
54 | + return $this->newLinkAction($icon, $name, 'mailto:'.urlencode($email)); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | } |
@@ -28,76 +28,76 @@ |
||
28 | 28 | |
29 | 29 | class LinkAction implements ILinkAction { |
30 | 30 | |
31 | - /** @var string */ |
|
32 | - private $icon; |
|
33 | - |
|
34 | - /** @var string */ |
|
35 | - private $name; |
|
36 | - |
|
37 | - /** @var string */ |
|
38 | - private $href; |
|
39 | - |
|
40 | - /** @var int */ |
|
41 | - private $priority = 10; |
|
42 | - |
|
43 | - /** |
|
44 | - * @param string $icon absolute URI to an icon |
|
45 | - */ |
|
46 | - public function setIcon($icon) { |
|
47 | - $this->icon = $icon; |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * @param string $name |
|
52 | - */ |
|
53 | - public function setName($name) { |
|
54 | - $this->name = $name; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @return string |
|
59 | - */ |
|
60 | - public function getName() { |
|
61 | - return $this->name; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * @param int $priority |
|
66 | - */ |
|
67 | - public function setPriority($priority) { |
|
68 | - $this->priority = $priority; |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * @return int |
|
73 | - */ |
|
74 | - public function getPriority() { |
|
75 | - return $this->priority; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * @param string $href |
|
80 | - */ |
|
81 | - public function setHref($href) { |
|
82 | - $this->href = $href; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * @return string |
|
87 | - */ |
|
88 | - public function getHref() { |
|
89 | - return $this->href; |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * @return array |
|
94 | - */ |
|
95 | - public function jsonSerialize() { |
|
96 | - return [ |
|
97 | - 'title' => $this->name, |
|
98 | - 'icon' => $this->icon, |
|
99 | - 'hyperlink' => $this->href, |
|
100 | - ]; |
|
101 | - } |
|
31 | + /** @var string */ |
|
32 | + private $icon; |
|
33 | + |
|
34 | + /** @var string */ |
|
35 | + private $name; |
|
36 | + |
|
37 | + /** @var string */ |
|
38 | + private $href; |
|
39 | + |
|
40 | + /** @var int */ |
|
41 | + private $priority = 10; |
|
42 | + |
|
43 | + /** |
|
44 | + * @param string $icon absolute URI to an icon |
|
45 | + */ |
|
46 | + public function setIcon($icon) { |
|
47 | + $this->icon = $icon; |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * @param string $name |
|
52 | + */ |
|
53 | + public function setName($name) { |
|
54 | + $this->name = $name; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @return string |
|
59 | + */ |
|
60 | + public function getName() { |
|
61 | + return $this->name; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * @param int $priority |
|
66 | + */ |
|
67 | + public function setPriority($priority) { |
|
68 | + $this->priority = $priority; |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * @return int |
|
73 | + */ |
|
74 | + public function getPriority() { |
|
75 | + return $this->priority; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * @param string $href |
|
80 | + */ |
|
81 | + public function setHref($href) { |
|
82 | + $this->href = $href; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * @return string |
|
87 | + */ |
|
88 | + public function getHref() { |
|
89 | + return $this->href; |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * @return array |
|
94 | + */ |
|
95 | + public function jsonSerialize() { |
|
96 | + return [ |
|
97 | + 'title' => $this->name, |
|
98 | + 'icon' => $this->icon, |
|
99 | + 'hyperlink' => $this->href, |
|
100 | + ]; |
|
101 | + } |
|
102 | 102 | |
103 | 103 | } |
@@ -33,33 +33,33 @@ |
||
33 | 33 | */ |
34 | 34 | interface IAction extends JsonSerializable { |
35 | 35 | |
36 | - /** |
|
37 | - * @param string $icon absolute URI to an icon |
|
38 | - * @since 12.0 |
|
39 | - */ |
|
40 | - public function setIcon($icon); |
|
36 | + /** |
|
37 | + * @param string $icon absolute URI to an icon |
|
38 | + * @since 12.0 |
|
39 | + */ |
|
40 | + public function setIcon($icon); |
|
41 | 41 | |
42 | - /** |
|
43 | - * @return string localized action name, e.g. 'Call' |
|
44 | - * @since 12.0 |
|
45 | - */ |
|
46 | - public function getName(); |
|
42 | + /** |
|
43 | + * @return string localized action name, e.g. 'Call' |
|
44 | + * @since 12.0 |
|
45 | + */ |
|
46 | + public function getName(); |
|
47 | 47 | |
48 | - /** |
|
49 | - * @param string $name localized action name, e.g. 'Call' |
|
50 | - * @since 12.0 |
|
51 | - */ |
|
52 | - public function setName($name); |
|
48 | + /** |
|
49 | + * @param string $name localized action name, e.g. 'Call' |
|
50 | + * @since 12.0 |
|
51 | + */ |
|
52 | + public function setName($name); |
|
53 | 53 | |
54 | - /** |
|
55 | - * @param int $priority priorize actions, high order ones are shown on top |
|
56 | - * @since 12.0 |
|
57 | - */ |
|
58 | - public function setPriority($priority); |
|
54 | + /** |
|
55 | + * @param int $priority priorize actions, high order ones are shown on top |
|
56 | + * @since 12.0 |
|
57 | + */ |
|
58 | + public function setPriority($priority); |
|
59 | 59 | |
60 | - /** |
|
61 | - * @return int priority to priorize actions, high order ones are shown on top |
|
62 | - * @since 12.0 |
|
63 | - */ |
|
64 | - public function getPriority(); |
|
60 | + /** |
|
61 | + * @return int priority to priorize actions, high order ones are shown on top |
|
62 | + * @since 12.0 |
|
63 | + */ |
|
64 | + public function getPriority(); |
|
65 | 65 | } |
@@ -28,27 +28,27 @@ |
||
28 | 28 | */ |
29 | 29 | interface IActionFactory { |
30 | 30 | |
31 | - /** |
|
32 | - * Construct and return a new link action for the contacts menu |
|
33 | - * |
|
34 | - * @since 12.0 |
|
35 | - * |
|
36 | - * @param string $icon full path to the action's icon |
|
37 | - * @param string $name localized name of the action |
|
38 | - * @param string $href target URL |
|
39 | - * @return ILinkAction |
|
40 | - */ |
|
41 | - public function newLinkAction($icon, $name, $href); |
|
31 | + /** |
|
32 | + * Construct and return a new link action for the contacts menu |
|
33 | + * |
|
34 | + * @since 12.0 |
|
35 | + * |
|
36 | + * @param string $icon full path to the action's icon |
|
37 | + * @param string $name localized name of the action |
|
38 | + * @param string $href target URL |
|
39 | + * @return ILinkAction |
|
40 | + */ |
|
41 | + public function newLinkAction($icon, $name, $href); |
|
42 | 42 | |
43 | - /** |
|
44 | - * Construct and return a new email action for the contacts menu |
|
45 | - * |
|
46 | - * @since 12.0 |
|
47 | - * |
|
48 | - * @param string $icon full path to the action's icon |
|
49 | - * @param string $name localized name of the action |
|
50 | - * @param string $email target e-mail address |
|
51 | - * @return ILinkAction |
|
52 | - */ |
|
53 | - public function newEMailAction($icon, $name, $email); |
|
43 | + /** |
|
44 | + * Construct and return a new email action for the contacts menu |
|
45 | + * |
|
46 | + * @since 12.0 |
|
47 | + * |
|
48 | + * @param string $icon full path to the action's icon |
|
49 | + * @param string $name localized name of the action |
|
50 | + * @param string $email target e-mail address |
|
51 | + * @return ILinkAction |
|
52 | + */ |
|
53 | + public function newEMailAction($icon, $name, $email); |
|
54 | 54 | } |
@@ -29,15 +29,15 @@ |
||
29 | 29 | */ |
30 | 30 | interface ILinkAction extends IAction { |
31 | 31 | |
32 | - /** |
|
33 | - * @since 12.0 |
|
34 | - * @param string $href the target URL of the action |
|
35 | - */ |
|
36 | - public function setHref($href); |
|
32 | + /** |
|
33 | + * @since 12.0 |
|
34 | + * @param string $href the target URL of the action |
|
35 | + */ |
|
36 | + public function setHref($href); |
|
37 | 37 | |
38 | - /** |
|
39 | - * @since 12.0 |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - public function getHref(); |
|
38 | + /** |
|
39 | + * @since 12.0 |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + public function getHref(); |
|
43 | 43 | } |
@@ -29,141 +29,141 @@ |
||
29 | 29 | |
30 | 30 | class Entry implements IEntry { |
31 | 31 | |
32 | - /** @var string|int|null */ |
|
33 | - private $id = null; |
|
34 | - |
|
35 | - /** @var string */ |
|
36 | - private $fullName = ''; |
|
37 | - |
|
38 | - /** @var string[] */ |
|
39 | - private $emailAddresses = []; |
|
40 | - |
|
41 | - /** @var string|null */ |
|
42 | - private $avatar; |
|
43 | - |
|
44 | - /** @var IAction[] */ |
|
45 | - private $actions = []; |
|
46 | - |
|
47 | - /** @var array */ |
|
48 | - private $properties = []; |
|
49 | - |
|
50 | - /** |
|
51 | - * @param string $id |
|
52 | - */ |
|
53 | - public function setId($id) { |
|
54 | - $this->id = $id; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @param string $displayName |
|
59 | - */ |
|
60 | - public function setFullName($displayName) { |
|
61 | - $this->fullName = $displayName; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - public function getFullName() { |
|
68 | - return $this->fullName; |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * @param string $address |
|
73 | - */ |
|
74 | - public function addEMailAddress($address) { |
|
75 | - $this->emailAddresses[] = $address; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * @return string |
|
80 | - */ |
|
81 | - public function getEMailAddresses() { |
|
82 | - return $this->emailAddresses; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * @param string $avatar |
|
87 | - */ |
|
88 | - public function setAvatar($avatar) { |
|
89 | - $this->avatar = $avatar; |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * @return string |
|
94 | - */ |
|
95 | - public function getAvatar() { |
|
96 | - return $this->avatar; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * @param IAction $action |
|
101 | - */ |
|
102 | - public function addAction(IAction $action) { |
|
103 | - $this->actions[] = $action; |
|
104 | - $this->sortActions(); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @return IAction[] |
|
109 | - */ |
|
110 | - public function getActions() { |
|
111 | - return $this->actions; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * sort the actions by priority and name |
|
116 | - */ |
|
117 | - private function sortActions() { |
|
118 | - usort($this->actions, function(IAction $action1, IAction $action2) { |
|
119 | - $prio1 = $action1->getPriority(); |
|
120 | - $prio2 = $action2->getPriority(); |
|
121 | - |
|
122 | - if ($prio1 === $prio2) { |
|
123 | - // Ascending order for same priority |
|
124 | - return strcasecmp($action1->getName(), $action2->getName()); |
|
125 | - } |
|
126 | - |
|
127 | - // Descending order when priority differs |
|
128 | - return $prio2 - $prio1; |
|
129 | - }); |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * @param array $contact key-value array containing additional properties |
|
134 | - */ |
|
135 | - public function setProperties(array $contact) { |
|
136 | - $this->properties = $contact; |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * @param string $key |
|
141 | - * @return mixed |
|
142 | - */ |
|
143 | - public function getProperty($key) { |
|
144 | - if (!isset($this->properties[$key])) { |
|
145 | - return null; |
|
146 | - } |
|
147 | - return $this->properties[$key]; |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * @return array |
|
152 | - */ |
|
153 | - public function jsonSerialize() { |
|
154 | - $topAction = !empty($this->actions) ? $this->actions[0]->jsonSerialize() : null; |
|
155 | - $otherActions = array_map(function(IAction $action) { |
|
156 | - return $action->jsonSerialize(); |
|
157 | - }, array_slice($this->actions, 1)); |
|
158 | - |
|
159 | - return [ |
|
160 | - 'id' => $this->id, |
|
161 | - 'fullName' => $this->fullName, |
|
162 | - 'avatar' => $this->getAvatar(), |
|
163 | - 'topAction' => $topAction, |
|
164 | - 'actions' => $otherActions, |
|
165 | - 'lastMessage' => '', |
|
166 | - ]; |
|
167 | - } |
|
32 | + /** @var string|int|null */ |
|
33 | + private $id = null; |
|
34 | + |
|
35 | + /** @var string */ |
|
36 | + private $fullName = ''; |
|
37 | + |
|
38 | + /** @var string[] */ |
|
39 | + private $emailAddresses = []; |
|
40 | + |
|
41 | + /** @var string|null */ |
|
42 | + private $avatar; |
|
43 | + |
|
44 | + /** @var IAction[] */ |
|
45 | + private $actions = []; |
|
46 | + |
|
47 | + /** @var array */ |
|
48 | + private $properties = []; |
|
49 | + |
|
50 | + /** |
|
51 | + * @param string $id |
|
52 | + */ |
|
53 | + public function setId($id) { |
|
54 | + $this->id = $id; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @param string $displayName |
|
59 | + */ |
|
60 | + public function setFullName($displayName) { |
|
61 | + $this->fullName = $displayName; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + public function getFullName() { |
|
68 | + return $this->fullName; |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * @param string $address |
|
73 | + */ |
|
74 | + public function addEMailAddress($address) { |
|
75 | + $this->emailAddresses[] = $address; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * @return string |
|
80 | + */ |
|
81 | + public function getEMailAddresses() { |
|
82 | + return $this->emailAddresses; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * @param string $avatar |
|
87 | + */ |
|
88 | + public function setAvatar($avatar) { |
|
89 | + $this->avatar = $avatar; |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * @return string |
|
94 | + */ |
|
95 | + public function getAvatar() { |
|
96 | + return $this->avatar; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * @param IAction $action |
|
101 | + */ |
|
102 | + public function addAction(IAction $action) { |
|
103 | + $this->actions[] = $action; |
|
104 | + $this->sortActions(); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @return IAction[] |
|
109 | + */ |
|
110 | + public function getActions() { |
|
111 | + return $this->actions; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * sort the actions by priority and name |
|
116 | + */ |
|
117 | + private function sortActions() { |
|
118 | + usort($this->actions, function(IAction $action1, IAction $action2) { |
|
119 | + $prio1 = $action1->getPriority(); |
|
120 | + $prio2 = $action2->getPriority(); |
|
121 | + |
|
122 | + if ($prio1 === $prio2) { |
|
123 | + // Ascending order for same priority |
|
124 | + return strcasecmp($action1->getName(), $action2->getName()); |
|
125 | + } |
|
126 | + |
|
127 | + // Descending order when priority differs |
|
128 | + return $prio2 - $prio1; |
|
129 | + }); |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * @param array $contact key-value array containing additional properties |
|
134 | + */ |
|
135 | + public function setProperties(array $contact) { |
|
136 | + $this->properties = $contact; |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * @param string $key |
|
141 | + * @return mixed |
|
142 | + */ |
|
143 | + public function getProperty($key) { |
|
144 | + if (!isset($this->properties[$key])) { |
|
145 | + return null; |
|
146 | + } |
|
147 | + return $this->properties[$key]; |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * @return array |
|
152 | + */ |
|
153 | + public function jsonSerialize() { |
|
154 | + $topAction = !empty($this->actions) ? $this->actions[0]->jsonSerialize() : null; |
|
155 | + $otherActions = array_map(function(IAction $action) { |
|
156 | + return $action->jsonSerialize(); |
|
157 | + }, array_slice($this->actions, 1)); |
|
158 | + |
|
159 | + return [ |
|
160 | + 'id' => $this->id, |
|
161 | + 'fullName' => $this->fullName, |
|
162 | + 'avatar' => $this->getAvatar(), |
|
163 | + 'topAction' => $topAction, |
|
164 | + 'actions' => $otherActions, |
|
165 | + 'lastMessage' => '', |
|
166 | + ]; |
|
167 | + } |
|
168 | 168 | |
169 | 169 | } |
@@ -31,36 +31,36 @@ |
||
31 | 31 | */ |
32 | 32 | interface IEntry extends JsonSerializable { |
33 | 33 | |
34 | - /** |
|
35 | - * @since 12.0 |
|
36 | - * @return string |
|
37 | - */ |
|
38 | - public function getFullName(); |
|
34 | + /** |
|
35 | + * @since 12.0 |
|
36 | + * @return string |
|
37 | + */ |
|
38 | + public function getFullName(); |
|
39 | 39 | |
40 | - /** |
|
41 | - * @since 12.0 |
|
42 | - * @return string[] |
|
43 | - */ |
|
44 | - public function getEMailAddresses(); |
|
40 | + /** |
|
41 | + * @since 12.0 |
|
42 | + * @return string[] |
|
43 | + */ |
|
44 | + public function getEMailAddresses(); |
|
45 | 45 | |
46 | - /** |
|
47 | - * @since 12.0 |
|
48 | - * @return string|null image URI |
|
49 | - */ |
|
50 | - public function getAvatar(); |
|
46 | + /** |
|
47 | + * @since 12.0 |
|
48 | + * @return string|null image URI |
|
49 | + */ |
|
50 | + public function getAvatar(); |
|
51 | 51 | |
52 | - /** |
|
53 | - * @since 12.0 |
|
54 | - * @param IAction $action an action to show in the contacts menu |
|
55 | - */ |
|
56 | - public function addAction(IAction $action); |
|
52 | + /** |
|
53 | + * @since 12.0 |
|
54 | + * @param IAction $action an action to show in the contacts menu |
|
55 | + */ |
|
56 | + public function addAction(IAction $action); |
|
57 | 57 | |
58 | - /** |
|
59 | - * Get an arbitrary property from the contact |
|
60 | - * |
|
61 | - * @since 12.0 |
|
62 | - * @param string $key |
|
63 | - * @return mixed the value of the property or null |
|
64 | - */ |
|
65 | - public function getProperty($key); |
|
58 | + /** |
|
59 | + * Get an arbitrary property from the contact |
|
60 | + * |
|
61 | + * @since 12.0 |
|
62 | + * @param string $key |
|
63 | + * @return mixed the value of the property or null |
|
64 | + */ |
|
65 | + public function getProperty($key); |
|
66 | 66 | } |
@@ -35,36 +35,36 @@ discard block |
||
35 | 35 | |
36 | 36 | $application = new Application(); |
37 | 37 | $application->registerRoutes($this, [ |
38 | - 'routes' => [ |
|
39 | - ['name' => 'lost#email', 'url' => '/lostpassword/email', 'verb' => 'POST'], |
|
40 | - ['name' => 'lost#resetform', 'url' => '/lostpassword/reset/form/{token}/{userId}', 'verb' => 'GET'], |
|
41 | - ['name' => 'lost#setPassword', 'url' => '/lostpassword/set/{token}/{userId}', 'verb' => 'POST'], |
|
42 | - ['name' => 'user#getDisplayNames', 'url' => '/displaynames', 'verb' => 'POST'], |
|
43 | - ['name' => 'avatar#getAvatar', 'url' => '/avatar/{userId}/{size}', 'verb' => 'GET'], |
|
44 | - ['name' => 'avatar#deleteAvatar', 'url' => '/avatar/', 'verb' => 'DELETE'], |
|
45 | - ['name' => 'avatar#postCroppedAvatar', 'url' => '/avatar/cropped', 'verb' => 'POST'], |
|
46 | - ['name' => 'avatar#getTmpAvatar', 'url' => '/avatar/tmp', 'verb' => 'GET'], |
|
47 | - ['name' => 'avatar#postAvatar', 'url' => '/avatar/', 'verb' => 'POST'], |
|
48 | - ['name' => 'login#tryLogin', 'url' => '/login', 'verb' => 'POST'], |
|
49 | - ['name' => 'login#confirmPassword', 'url' => '/login/confirm', 'verb' => 'POST'], |
|
50 | - ['name' => 'login#showLoginForm', 'url' => '/login', 'verb' => 'GET'], |
|
51 | - ['name' => 'login#logout', 'url' => '/logout', 'verb' => 'GET'], |
|
52 | - ['name' => 'TwoFactorChallenge#selectChallenge', 'url' => '/login/selectchallenge', 'verb' => 'GET'], |
|
53 | - ['name' => 'TwoFactorChallenge#showChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'GET'], |
|
54 | - ['name' => 'TwoFactorChallenge#solveChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'POST'], |
|
55 | - ['name' => 'OCJS#getConfig', 'url' => '/core/js/oc.js', 'verb' => 'GET'], |
|
56 | - ['name' => 'Preview#getPreview', 'url' => '/core/preview', 'verb' => 'GET'], |
|
57 | - ['name' => 'Preview#getPreview', 'url' => '/core/preview.png', 'verb' => 'GET'], |
|
58 | - ['name' => 'Css#getCss', 'url' => '/css/{appName}/{fileName}', 'verb' => 'GET'], |
|
59 | - ['name' => 'Js#getJs', 'url' => '/js/{appName}/{fileName}', 'verb' => 'GET'], |
|
60 | - ['name' => 'contactsMenu#index', 'url' => '/contactsmenu/contacts', 'verb' => 'GET'], |
|
61 | - ], |
|
62 | - 'ocs' => [ |
|
63 | - ['root' => '/cloud', 'name' => 'OCS#getCapabilities', 'url' => '/capabilities', 'verb' => 'GET'], |
|
64 | - ['root' => '', 'name' => 'OCS#getConfig', 'url' => '/config', 'verb' => 'GET'], |
|
65 | - ['root' => '/person', 'name' => 'OCS#personCheck', 'url' => '/check', 'verb' => 'POST'], |
|
66 | - ['root' => '/identityproof', 'name' => 'OCS#getIdentityProof', 'url' => '/key/{cloudId}', 'verb' => 'GET'], |
|
67 | - ], |
|
38 | + 'routes' => [ |
|
39 | + ['name' => 'lost#email', 'url' => '/lostpassword/email', 'verb' => 'POST'], |
|
40 | + ['name' => 'lost#resetform', 'url' => '/lostpassword/reset/form/{token}/{userId}', 'verb' => 'GET'], |
|
41 | + ['name' => 'lost#setPassword', 'url' => '/lostpassword/set/{token}/{userId}', 'verb' => 'POST'], |
|
42 | + ['name' => 'user#getDisplayNames', 'url' => '/displaynames', 'verb' => 'POST'], |
|
43 | + ['name' => 'avatar#getAvatar', 'url' => '/avatar/{userId}/{size}', 'verb' => 'GET'], |
|
44 | + ['name' => 'avatar#deleteAvatar', 'url' => '/avatar/', 'verb' => 'DELETE'], |
|
45 | + ['name' => 'avatar#postCroppedAvatar', 'url' => '/avatar/cropped', 'verb' => 'POST'], |
|
46 | + ['name' => 'avatar#getTmpAvatar', 'url' => '/avatar/tmp', 'verb' => 'GET'], |
|
47 | + ['name' => 'avatar#postAvatar', 'url' => '/avatar/', 'verb' => 'POST'], |
|
48 | + ['name' => 'login#tryLogin', 'url' => '/login', 'verb' => 'POST'], |
|
49 | + ['name' => 'login#confirmPassword', 'url' => '/login/confirm', 'verb' => 'POST'], |
|
50 | + ['name' => 'login#showLoginForm', 'url' => '/login', 'verb' => 'GET'], |
|
51 | + ['name' => 'login#logout', 'url' => '/logout', 'verb' => 'GET'], |
|
52 | + ['name' => 'TwoFactorChallenge#selectChallenge', 'url' => '/login/selectchallenge', 'verb' => 'GET'], |
|
53 | + ['name' => 'TwoFactorChallenge#showChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'GET'], |
|
54 | + ['name' => 'TwoFactorChallenge#solveChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'POST'], |
|
55 | + ['name' => 'OCJS#getConfig', 'url' => '/core/js/oc.js', 'verb' => 'GET'], |
|
56 | + ['name' => 'Preview#getPreview', 'url' => '/core/preview', 'verb' => 'GET'], |
|
57 | + ['name' => 'Preview#getPreview', 'url' => '/core/preview.png', 'verb' => 'GET'], |
|
58 | + ['name' => 'Css#getCss', 'url' => '/css/{appName}/{fileName}', 'verb' => 'GET'], |
|
59 | + ['name' => 'Js#getJs', 'url' => '/js/{appName}/{fileName}', 'verb' => 'GET'], |
|
60 | + ['name' => 'contactsMenu#index', 'url' => '/contactsmenu/contacts', 'verb' => 'GET'], |
|
61 | + ], |
|
62 | + 'ocs' => [ |
|
63 | + ['root' => '/cloud', 'name' => 'OCS#getCapabilities', 'url' => '/capabilities', 'verb' => 'GET'], |
|
64 | + ['root' => '', 'name' => 'OCS#getConfig', 'url' => '/config', 'verb' => 'GET'], |
|
65 | + ['root' => '/person', 'name' => 'OCS#personCheck', 'url' => '/check', 'verb' => 'POST'], |
|
66 | + ['root' => '/identityproof', 'name' => 'OCS#getIdentityProof', 'url' => '/key/{cloudId}', 'verb' => 'GET'], |
|
67 | + ], |
|
68 | 68 | ]); |
69 | 69 | |
70 | 70 | // Post installation check |
@@ -73,62 +73,62 @@ discard block |
||
73 | 73 | // Core ajax actions |
74 | 74 | // Search |
75 | 75 | $this->create('search_ajax_search', '/core/search') |
76 | - ->actionInclude('core/search/ajax/search.php'); |
|
76 | + ->actionInclude('core/search/ajax/search.php'); |
|
77 | 77 | // Routing |
78 | 78 | $this->create('core_ajax_update', '/core/ajax/update.php') |
79 | - ->actionInclude('core/ajax/update.php'); |
|
79 | + ->actionInclude('core/ajax/update.php'); |
|
80 | 80 | |
81 | 81 | // File routes |
82 | 82 | $this->create('files.viewcontroller.showFile', '/f/{fileid}')->action(function($urlParams) { |
83 | - $app = new \OCA\Files\AppInfo\Application($urlParams); |
|
84 | - $app->dispatch('ViewController', 'index'); |
|
83 | + $app = new \OCA\Files\AppInfo\Application($urlParams); |
|
84 | + $app->dispatch('ViewController', 'index'); |
|
85 | 85 | }); |
86 | 86 | |
87 | 87 | // Call routes |
88 | 88 | $this->create('spreed.pagecontroller.showCall', '/call/{token}')->action(function($urlParams) { |
89 | - if (class_exists(\OCA\Spreed\AppInfo\Application::class, false)) { |
|
90 | - $app = new \OCA\Spreed\AppInfo\Application($urlParams); |
|
91 | - $app->dispatch('PageController', 'index'); |
|
92 | - } else { |
|
93 | - throw new \OC\HintException('App spreed is not enabled'); |
|
94 | - } |
|
89 | + if (class_exists(\OCA\Spreed\AppInfo\Application::class, false)) { |
|
90 | + $app = new \OCA\Spreed\AppInfo\Application($urlParams); |
|
91 | + $app->dispatch('PageController', 'index'); |
|
92 | + } else { |
|
93 | + throw new \OC\HintException('App spreed is not enabled'); |
|
94 | + } |
|
95 | 95 | }); |
96 | 96 | |
97 | 97 | // Sharing routes |
98 | 98 | $this->create('files_sharing.sharecontroller.showShare', '/s/{token}')->action(function($urlParams) { |
99 | - if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) { |
|
100 | - $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams); |
|
101 | - $app->dispatch('ShareController', 'showShare'); |
|
102 | - } else { |
|
103 | - throw new \OC\HintException('App file sharing is not enabled'); |
|
104 | - } |
|
99 | + if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) { |
|
100 | + $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams); |
|
101 | + $app->dispatch('ShareController', 'showShare'); |
|
102 | + } else { |
|
103 | + throw new \OC\HintException('App file sharing is not enabled'); |
|
104 | + } |
|
105 | 105 | }); |
106 | 106 | $this->create('files_sharing.sharecontroller.authenticate', '/s/{token}/authenticate')->post()->action(function($urlParams) { |
107 | - if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) { |
|
108 | - $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams); |
|
109 | - $app->dispatch('ShareController', 'authenticate'); |
|
110 | - } else { |
|
111 | - throw new \OC\HintException('App file sharing is not enabled'); |
|
112 | - } |
|
107 | + if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) { |
|
108 | + $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams); |
|
109 | + $app->dispatch('ShareController', 'authenticate'); |
|
110 | + } else { |
|
111 | + throw new \OC\HintException('App file sharing is not enabled'); |
|
112 | + } |
|
113 | 113 | }); |
114 | 114 | $this->create('files_sharing.sharecontroller.showAuthenticate', '/s/{token}/authenticate')->get()->action(function($urlParams) { |
115 | - if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) { |
|
116 | - $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams); |
|
117 | - $app->dispatch('ShareController', 'showAuthenticate'); |
|
118 | - } else { |
|
119 | - throw new \OC\HintException('App file sharing is not enabled'); |
|
120 | - } |
|
115 | + if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) { |
|
116 | + $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams); |
|
117 | + $app->dispatch('ShareController', 'showAuthenticate'); |
|
118 | + } else { |
|
119 | + throw new \OC\HintException('App file sharing is not enabled'); |
|
120 | + } |
|
121 | 121 | }); |
122 | 122 | $this->create('files_sharing.sharecontroller.downloadShare', '/s/{token}/download')->get()->action(function($urlParams) { |
123 | - if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) { |
|
124 | - $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams); |
|
125 | - $app->dispatch('ShareController', 'downloadShare'); |
|
126 | - } else { |
|
127 | - throw new \OC\HintException('App file sharing is not enabled'); |
|
128 | - } |
|
123 | + if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) { |
|
124 | + $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams); |
|
125 | + $app->dispatch('ShareController', 'downloadShare'); |
|
126 | + } else { |
|
127 | + throw new \OC\HintException('App file sharing is not enabled'); |
|
128 | + } |
|
129 | 129 | }); |
130 | 130 | |
131 | 131 | // used for heartbeat |
132 | 132 | $this->create('heartbeat', '/heartbeat')->action(function(){ |
133 | - // do nothing |
|
133 | + // do nothing |
|
134 | 134 | }); |
@@ -44,330 +44,330 @@ |
||
44 | 44 | */ |
45 | 45 | class OC_Template extends \OC\Template\Base { |
46 | 46 | |
47 | - /** @var string */ |
|
48 | - private $renderAs; // Create a full page? |
|
49 | - |
|
50 | - /** @var string */ |
|
51 | - private $path; // The path to the template |
|
52 | - |
|
53 | - /** @var array */ |
|
54 | - private $headers = array(); //custom headers |
|
55 | - |
|
56 | - /** @var string */ |
|
57 | - protected $app; // app id |
|
58 | - |
|
59 | - protected static $initTemplateEngineFirstRun = true; |
|
60 | - |
|
61 | - /** |
|
62 | - * Constructor |
|
63 | - * |
|
64 | - * @param string $app app providing the template |
|
65 | - * @param string $name of the template file (without suffix) |
|
66 | - * @param string $renderAs If $renderAs is set, OC_Template will try to |
|
67 | - * produce a full page in the according layout. For |
|
68 | - * now, $renderAs can be set to "guest", "user" or |
|
69 | - * "admin". |
|
70 | - * @param bool $registerCall = true |
|
71 | - */ |
|
72 | - public function __construct( $app, $name, $renderAs = "", $registerCall = true ) { |
|
73 | - // Read the selected theme from the config file |
|
74 | - self::initTemplateEngine($renderAs); |
|
75 | - |
|
76 | - $theme = OC_Util::getTheme(); |
|
77 | - |
|
78 | - $requestToken = (OC::$server->getSession() && $registerCall) ? \OCP\Util::callRegister() : ''; |
|
79 | - |
|
80 | - $parts = explode('/', $app); // fix translation when app is something like core/lostpassword |
|
81 | - $l10n = \OC::$server->getL10N($parts[0]); |
|
82 | - $themeDefaults = \OC::$server->getThemingDefaults(); |
|
83 | - |
|
84 | - list($path, $template) = $this->findTemplate($theme, $app, $name); |
|
85 | - |
|
86 | - // Set the private data |
|
87 | - $this->renderAs = $renderAs; |
|
88 | - $this->path = $path; |
|
89 | - $this->app = $app; |
|
90 | - |
|
91 | - parent::__construct($template, $requestToken, $l10n, $themeDefaults); |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * @param string $renderAs |
|
96 | - */ |
|
97 | - public static function initTemplateEngine($renderAs) { |
|
98 | - if (self::$initTemplateEngineFirstRun){ |
|
99 | - |
|
100 | - //apps that started before the template initialization can load their own scripts/styles |
|
101 | - //so to make sure this scripts/styles here are loaded first we use OC_Util::addScript() with $prepend=true |
|
102 | - //meaning the last script/style in this list will be loaded first |
|
103 | - if (\OC::$server->getSystemConfig()->getValue ('installed', false) && $renderAs !== 'error' && !\OCP\Util::needUpgrade()) { |
|
104 | - if (\OC::$server->getConfig ()->getAppValue ( 'core', 'backgroundjobs_mode', 'ajax' ) == 'ajax') { |
|
105 | - OC_Util::addScript ( 'backgroundjobs', null, true ); |
|
106 | - } |
|
107 | - } |
|
108 | - |
|
109 | - OC_Util::addStyle('jquery-ui-fixes',null,true); |
|
110 | - OC_Util::addVendorStyle('jquery-ui/themes/base/jquery-ui',null,true); |
|
111 | - OC_Util::addStyle('server', null, true); |
|
112 | - OC_Util::addVendorStyle('select2/select2', null, true); |
|
113 | - OC_Util::addStyle('jquery.ocdialog'); |
|
114 | - OC_Util::addTranslations("core", null, true); |
|
115 | - OC_Util::addScript('search', 'search', true); |
|
116 | - OC_Util::addScript('merged-template-prepend', null, true); |
|
117 | - OC_Util::addScript('jquery-ui-fixes'); |
|
118 | - OC_Util::addScript('files/fileinfo'); |
|
119 | - OC_Util::addScript('files/client'); |
|
120 | - OC_Util::addScript('contactsmenu'); |
|
121 | - |
|
122 | - if (\OC::$server->getConfig()->getSystemValue('debug')) { |
|
123 | - // Add the stuff we need always |
|
124 | - // following logic will import all vendor libraries that are |
|
125 | - // specified in core/js/core.json |
|
126 | - $fileContent = file_get_contents(OC::$SERVERROOT . '/core/js/core.json'); |
|
127 | - if($fileContent !== false) { |
|
128 | - $coreDependencies = json_decode($fileContent, true); |
|
129 | - foreach(array_reverse($coreDependencies['vendor']) as $vendorLibrary) { |
|
130 | - //remove trailing ".js" as addVendorScript will append it |
|
131 | - OC_Util::addVendorScript( |
|
132 | - substr($vendorLibrary, 0, strlen($vendorLibrary) - 3),null,true); |
|
133 | - } |
|
134 | - } else { |
|
135 | - throw new \Exception('Cannot read core/js/core.json'); |
|
136 | - } |
|
137 | - } else { |
|
138 | - // Import all (combined) default vendor libraries |
|
139 | - OC_Util::addVendorScript('core', null, true); |
|
140 | - } |
|
141 | - |
|
142 | - if (\OC::$server->getRequest()->isUserAgent([\OC\AppFramework\Http\Request::USER_AGENT_IE])) { |
|
143 | - // polyfill for btoa/atob for IE friends |
|
144 | - OC_Util::addVendorScript('base64/base64'); |
|
145 | - // shim for the davclient.js library |
|
146 | - \OCP\Util::addScript('files/iedavclient'); |
|
147 | - } |
|
148 | - |
|
149 | - self::$initTemplateEngineFirstRun = false; |
|
150 | - } |
|
151 | - |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * find the template with the given name |
|
157 | - * @param string $name of the template file (without suffix) |
|
158 | - * |
|
159 | - * Will select the template file for the selected theme. |
|
160 | - * Checking all the possible locations. |
|
161 | - * @param string $theme |
|
162 | - * @param string $app |
|
163 | - * @return string[] |
|
164 | - */ |
|
165 | - protected function findTemplate($theme, $app, $name) { |
|
166 | - // Check if it is a app template or not. |
|
167 | - if( $app !== '' ) { |
|
168 | - $dirs = $this->getAppTemplateDirs($theme, $app, OC::$SERVERROOT, OC_App::getAppPath($app)); |
|
169 | - } else { |
|
170 | - $dirs = $this->getCoreTemplateDirs($theme, OC::$SERVERROOT); |
|
171 | - } |
|
172 | - $locator = new \OC\Template\TemplateFileLocator( $dirs ); |
|
173 | - $template = $locator->find($name); |
|
174 | - $path = $locator->getPath(); |
|
175 | - return array($path, $template); |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Add a custom element to the header |
|
180 | - * @param string $tag tag name of the element |
|
181 | - * @param array $attributes array of attributes for the element |
|
182 | - * @param string $text the text content for the element. If $text is null then the |
|
183 | - * element will be written as empty element. So use "" to get a closing tag. |
|
184 | - */ |
|
185 | - public function addHeader($tag, $attributes, $text=null) { |
|
186 | - $this->headers[]= array( |
|
187 | - 'tag' => $tag, |
|
188 | - 'attributes' => $attributes, |
|
189 | - 'text' => $text |
|
190 | - ); |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * Process the template |
|
195 | - * @return boolean|string |
|
196 | - * |
|
197 | - * This function process the template. If $this->renderAs is set, it |
|
198 | - * will produce a full page. |
|
199 | - */ |
|
200 | - public function fetchPage($additionalParams = null) { |
|
201 | - $data = parent::fetchPage($additionalParams); |
|
202 | - |
|
203 | - if( $this->renderAs ) { |
|
204 | - $page = new TemplateLayout($this->renderAs, $this->app); |
|
205 | - |
|
206 | - // Add custom headers |
|
207 | - $headers = ''; |
|
208 | - foreach(OC_Util::$headers as $header) { |
|
209 | - $headers .= '<'.\OCP\Util::sanitizeHTML($header['tag']); |
|
210 | - foreach($header['attributes'] as $name=>$value) { |
|
211 | - $headers .= ' '.\OCP\Util::sanitizeHTML($name).'="'.\OCP\Util::sanitizeHTML($value).'"'; |
|
212 | - } |
|
213 | - if ($header['text'] !== null) { |
|
214 | - $headers .= '>'.\OCP\Util::sanitizeHTML($header['text']).'</'.\OCP\Util::sanitizeHTML($header['tag']).'>'; |
|
215 | - } else { |
|
216 | - $headers .= '/>'; |
|
217 | - } |
|
218 | - } |
|
219 | - |
|
220 | - $page->assign('headers', $headers); |
|
221 | - |
|
222 | - $page->assign('content', $data); |
|
223 | - return $page->fetchPage(); |
|
224 | - } |
|
225 | - |
|
226 | - return $data; |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * Include template |
|
231 | - * |
|
232 | - * @param string $file |
|
233 | - * @param array|null $additionalParams |
|
234 | - * @return string returns content of included template |
|
235 | - * |
|
236 | - * Includes another template. use <?php echo $this->inc('template'); ?> to |
|
237 | - * do this. |
|
238 | - */ |
|
239 | - public function inc( $file, $additionalParams = null ) { |
|
240 | - return $this->load($this->path.$file.'.php', $additionalParams); |
|
241 | - } |
|
242 | - |
|
243 | - /** |
|
244 | - * Shortcut to print a simple page for users |
|
245 | - * @param string $application The application we render the template for |
|
246 | - * @param string $name Name of the template |
|
247 | - * @param array $parameters Parameters for the template |
|
248 | - * @return boolean|null |
|
249 | - */ |
|
250 | - public static function printUserPage( $application, $name, $parameters = array() ) { |
|
251 | - $content = new OC_Template( $application, $name, "user" ); |
|
252 | - foreach( $parameters as $key => $value ) { |
|
253 | - $content->assign( $key, $value ); |
|
254 | - } |
|
255 | - print $content->printPage(); |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * Shortcut to print a simple page for admins |
|
260 | - * @param string $application The application we render the template for |
|
261 | - * @param string $name Name of the template |
|
262 | - * @param array $parameters Parameters for the template |
|
263 | - * @return bool |
|
264 | - */ |
|
265 | - public static function printAdminPage( $application, $name, $parameters = array() ) { |
|
266 | - $content = new OC_Template( $application, $name, "admin" ); |
|
267 | - foreach( $parameters as $key => $value ) { |
|
268 | - $content->assign( $key, $value ); |
|
269 | - } |
|
270 | - return $content->printPage(); |
|
271 | - } |
|
272 | - |
|
273 | - /** |
|
274 | - * Shortcut to print a simple page for guests |
|
275 | - * @param string $application The application we render the template for |
|
276 | - * @param string $name Name of the template |
|
277 | - * @param array|string $parameters Parameters for the template |
|
278 | - * @return bool |
|
279 | - */ |
|
280 | - public static function printGuestPage( $application, $name, $parameters = array() ) { |
|
281 | - $content = new OC_Template( $application, $name, "guest" ); |
|
282 | - foreach( $parameters as $key => $value ) { |
|
283 | - $content->assign( $key, $value ); |
|
284 | - } |
|
285 | - return $content->printPage(); |
|
286 | - } |
|
287 | - |
|
288 | - /** |
|
289 | - * Print a fatal error page and terminates the script |
|
290 | - * @param string $error_msg The error message to show |
|
291 | - * @param string $hint An optional hint message - needs to be properly escaped |
|
292 | - */ |
|
293 | - public static function printErrorPage( $error_msg, $hint = '' ) { |
|
294 | - if ($error_msg === $hint) { |
|
295 | - // If the hint is the same as the message there is no need to display it twice. |
|
296 | - $hint = ''; |
|
297 | - } |
|
298 | - |
|
299 | - try { |
|
300 | - $content = new \OC_Template( '', 'error', 'error', false ); |
|
301 | - $errors = array(array('error' => $error_msg, 'hint' => $hint)); |
|
302 | - $content->assign( 'errors', $errors ); |
|
303 | - $content->printPage(); |
|
304 | - } catch (\Exception $e) { |
|
305 | - $logger = \OC::$server->getLogger(); |
|
306 | - $logger->error("$error_msg $hint", ['app' => 'core']); |
|
307 | - $logger->logException($e, ['app' => 'core']); |
|
308 | - |
|
309 | - header(self::getHttpProtocol() . ' 500 Internal Server Error'); |
|
310 | - header('Content-Type: text/plain; charset=utf-8'); |
|
311 | - print("$error_msg $hint"); |
|
312 | - } |
|
313 | - die(); |
|
314 | - } |
|
315 | - |
|
316 | - /** |
|
317 | - * print error page using Exception details |
|
318 | - * @param Exception | Throwable $exception |
|
319 | - */ |
|
320 | - public static function printExceptionErrorPage($exception, $fetchPage = false) { |
|
321 | - try { |
|
322 | - $request = \OC::$server->getRequest(); |
|
323 | - $content = new \OC_Template('', 'exception', 'error', false); |
|
324 | - $content->assign('errorClass', get_class($exception)); |
|
325 | - $content->assign('errorMsg', $exception->getMessage()); |
|
326 | - $content->assign('errorCode', $exception->getCode()); |
|
327 | - $content->assign('file', $exception->getFile()); |
|
328 | - $content->assign('line', $exception->getLine()); |
|
329 | - $content->assign('trace', $exception->getTraceAsString()); |
|
330 | - $content->assign('debugMode', \OC::$server->getSystemConfig()->getValue('debug', false)); |
|
331 | - $content->assign('remoteAddr', $request->getRemoteAddress()); |
|
332 | - $content->assign('requestID', $request->getId()); |
|
333 | - if ($fetchPage) { |
|
334 | - return $content->fetchPage(); |
|
335 | - } |
|
336 | - $content->printPage(); |
|
337 | - } catch (\Exception $e) { |
|
338 | - $logger = \OC::$server->getLogger(); |
|
339 | - $logger->logException($exception, ['app' => 'core']); |
|
340 | - $logger->logException($e, ['app' => 'core']); |
|
341 | - |
|
342 | - header(self::getHttpProtocol() . ' 500 Internal Server Error'); |
|
343 | - header('Content-Type: text/plain; charset=utf-8'); |
|
344 | - print("Internal Server Error\n\n"); |
|
345 | - print("The server encountered an internal error and was unable to complete your request.\n"); |
|
346 | - print("Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.\n"); |
|
347 | - print("More details can be found in the server log.\n"); |
|
348 | - } |
|
349 | - die(); |
|
350 | - } |
|
351 | - |
|
352 | - /** |
|
353 | - * This is only here to reduce the dependencies in case of an exception to |
|
354 | - * still be able to print a plain error message. |
|
355 | - * |
|
356 | - * Returns the used HTTP protocol. |
|
357 | - * |
|
358 | - * @return string HTTP protocol. HTTP/2, HTTP/1.1 or HTTP/1.0. |
|
359 | - * @internal Don't use this - use AppFramework\Http\Request->getHttpProtocol instead |
|
360 | - */ |
|
361 | - protected static function getHttpProtocol() { |
|
362 | - $claimedProtocol = strtoupper($_SERVER['SERVER_PROTOCOL']); |
|
363 | - $validProtocols = [ |
|
364 | - 'HTTP/1.0', |
|
365 | - 'HTTP/1.1', |
|
366 | - 'HTTP/2', |
|
367 | - ]; |
|
368 | - if(in_array($claimedProtocol, $validProtocols, true)) { |
|
369 | - return $claimedProtocol; |
|
370 | - } |
|
371 | - return 'HTTP/1.1'; |
|
372 | - } |
|
47 | + /** @var string */ |
|
48 | + private $renderAs; // Create a full page? |
|
49 | + |
|
50 | + /** @var string */ |
|
51 | + private $path; // The path to the template |
|
52 | + |
|
53 | + /** @var array */ |
|
54 | + private $headers = array(); //custom headers |
|
55 | + |
|
56 | + /** @var string */ |
|
57 | + protected $app; // app id |
|
58 | + |
|
59 | + protected static $initTemplateEngineFirstRun = true; |
|
60 | + |
|
61 | + /** |
|
62 | + * Constructor |
|
63 | + * |
|
64 | + * @param string $app app providing the template |
|
65 | + * @param string $name of the template file (without suffix) |
|
66 | + * @param string $renderAs If $renderAs is set, OC_Template will try to |
|
67 | + * produce a full page in the according layout. For |
|
68 | + * now, $renderAs can be set to "guest", "user" or |
|
69 | + * "admin". |
|
70 | + * @param bool $registerCall = true |
|
71 | + */ |
|
72 | + public function __construct( $app, $name, $renderAs = "", $registerCall = true ) { |
|
73 | + // Read the selected theme from the config file |
|
74 | + self::initTemplateEngine($renderAs); |
|
75 | + |
|
76 | + $theme = OC_Util::getTheme(); |
|
77 | + |
|
78 | + $requestToken = (OC::$server->getSession() && $registerCall) ? \OCP\Util::callRegister() : ''; |
|
79 | + |
|
80 | + $parts = explode('/', $app); // fix translation when app is something like core/lostpassword |
|
81 | + $l10n = \OC::$server->getL10N($parts[0]); |
|
82 | + $themeDefaults = \OC::$server->getThemingDefaults(); |
|
83 | + |
|
84 | + list($path, $template) = $this->findTemplate($theme, $app, $name); |
|
85 | + |
|
86 | + // Set the private data |
|
87 | + $this->renderAs = $renderAs; |
|
88 | + $this->path = $path; |
|
89 | + $this->app = $app; |
|
90 | + |
|
91 | + parent::__construct($template, $requestToken, $l10n, $themeDefaults); |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * @param string $renderAs |
|
96 | + */ |
|
97 | + public static function initTemplateEngine($renderAs) { |
|
98 | + if (self::$initTemplateEngineFirstRun){ |
|
99 | + |
|
100 | + //apps that started before the template initialization can load their own scripts/styles |
|
101 | + //so to make sure this scripts/styles here are loaded first we use OC_Util::addScript() with $prepend=true |
|
102 | + //meaning the last script/style in this list will be loaded first |
|
103 | + if (\OC::$server->getSystemConfig()->getValue ('installed', false) && $renderAs !== 'error' && !\OCP\Util::needUpgrade()) { |
|
104 | + if (\OC::$server->getConfig ()->getAppValue ( 'core', 'backgroundjobs_mode', 'ajax' ) == 'ajax') { |
|
105 | + OC_Util::addScript ( 'backgroundjobs', null, true ); |
|
106 | + } |
|
107 | + } |
|
108 | + |
|
109 | + OC_Util::addStyle('jquery-ui-fixes',null,true); |
|
110 | + OC_Util::addVendorStyle('jquery-ui/themes/base/jquery-ui',null,true); |
|
111 | + OC_Util::addStyle('server', null, true); |
|
112 | + OC_Util::addVendorStyle('select2/select2', null, true); |
|
113 | + OC_Util::addStyle('jquery.ocdialog'); |
|
114 | + OC_Util::addTranslations("core", null, true); |
|
115 | + OC_Util::addScript('search', 'search', true); |
|
116 | + OC_Util::addScript('merged-template-prepend', null, true); |
|
117 | + OC_Util::addScript('jquery-ui-fixes'); |
|
118 | + OC_Util::addScript('files/fileinfo'); |
|
119 | + OC_Util::addScript('files/client'); |
|
120 | + OC_Util::addScript('contactsmenu'); |
|
121 | + |
|
122 | + if (\OC::$server->getConfig()->getSystemValue('debug')) { |
|
123 | + // Add the stuff we need always |
|
124 | + // following logic will import all vendor libraries that are |
|
125 | + // specified in core/js/core.json |
|
126 | + $fileContent = file_get_contents(OC::$SERVERROOT . '/core/js/core.json'); |
|
127 | + if($fileContent !== false) { |
|
128 | + $coreDependencies = json_decode($fileContent, true); |
|
129 | + foreach(array_reverse($coreDependencies['vendor']) as $vendorLibrary) { |
|
130 | + //remove trailing ".js" as addVendorScript will append it |
|
131 | + OC_Util::addVendorScript( |
|
132 | + substr($vendorLibrary, 0, strlen($vendorLibrary) - 3),null,true); |
|
133 | + } |
|
134 | + } else { |
|
135 | + throw new \Exception('Cannot read core/js/core.json'); |
|
136 | + } |
|
137 | + } else { |
|
138 | + // Import all (combined) default vendor libraries |
|
139 | + OC_Util::addVendorScript('core', null, true); |
|
140 | + } |
|
141 | + |
|
142 | + if (\OC::$server->getRequest()->isUserAgent([\OC\AppFramework\Http\Request::USER_AGENT_IE])) { |
|
143 | + // polyfill for btoa/atob for IE friends |
|
144 | + OC_Util::addVendorScript('base64/base64'); |
|
145 | + // shim for the davclient.js library |
|
146 | + \OCP\Util::addScript('files/iedavclient'); |
|
147 | + } |
|
148 | + |
|
149 | + self::$initTemplateEngineFirstRun = false; |
|
150 | + } |
|
151 | + |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * find the template with the given name |
|
157 | + * @param string $name of the template file (without suffix) |
|
158 | + * |
|
159 | + * Will select the template file for the selected theme. |
|
160 | + * Checking all the possible locations. |
|
161 | + * @param string $theme |
|
162 | + * @param string $app |
|
163 | + * @return string[] |
|
164 | + */ |
|
165 | + protected function findTemplate($theme, $app, $name) { |
|
166 | + // Check if it is a app template or not. |
|
167 | + if( $app !== '' ) { |
|
168 | + $dirs = $this->getAppTemplateDirs($theme, $app, OC::$SERVERROOT, OC_App::getAppPath($app)); |
|
169 | + } else { |
|
170 | + $dirs = $this->getCoreTemplateDirs($theme, OC::$SERVERROOT); |
|
171 | + } |
|
172 | + $locator = new \OC\Template\TemplateFileLocator( $dirs ); |
|
173 | + $template = $locator->find($name); |
|
174 | + $path = $locator->getPath(); |
|
175 | + return array($path, $template); |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Add a custom element to the header |
|
180 | + * @param string $tag tag name of the element |
|
181 | + * @param array $attributes array of attributes for the element |
|
182 | + * @param string $text the text content for the element. If $text is null then the |
|
183 | + * element will be written as empty element. So use "" to get a closing tag. |
|
184 | + */ |
|
185 | + public function addHeader($tag, $attributes, $text=null) { |
|
186 | + $this->headers[]= array( |
|
187 | + 'tag' => $tag, |
|
188 | + 'attributes' => $attributes, |
|
189 | + 'text' => $text |
|
190 | + ); |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * Process the template |
|
195 | + * @return boolean|string |
|
196 | + * |
|
197 | + * This function process the template. If $this->renderAs is set, it |
|
198 | + * will produce a full page. |
|
199 | + */ |
|
200 | + public function fetchPage($additionalParams = null) { |
|
201 | + $data = parent::fetchPage($additionalParams); |
|
202 | + |
|
203 | + if( $this->renderAs ) { |
|
204 | + $page = new TemplateLayout($this->renderAs, $this->app); |
|
205 | + |
|
206 | + // Add custom headers |
|
207 | + $headers = ''; |
|
208 | + foreach(OC_Util::$headers as $header) { |
|
209 | + $headers .= '<'.\OCP\Util::sanitizeHTML($header['tag']); |
|
210 | + foreach($header['attributes'] as $name=>$value) { |
|
211 | + $headers .= ' '.\OCP\Util::sanitizeHTML($name).'="'.\OCP\Util::sanitizeHTML($value).'"'; |
|
212 | + } |
|
213 | + if ($header['text'] !== null) { |
|
214 | + $headers .= '>'.\OCP\Util::sanitizeHTML($header['text']).'</'.\OCP\Util::sanitizeHTML($header['tag']).'>'; |
|
215 | + } else { |
|
216 | + $headers .= '/>'; |
|
217 | + } |
|
218 | + } |
|
219 | + |
|
220 | + $page->assign('headers', $headers); |
|
221 | + |
|
222 | + $page->assign('content', $data); |
|
223 | + return $page->fetchPage(); |
|
224 | + } |
|
225 | + |
|
226 | + return $data; |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * Include template |
|
231 | + * |
|
232 | + * @param string $file |
|
233 | + * @param array|null $additionalParams |
|
234 | + * @return string returns content of included template |
|
235 | + * |
|
236 | + * Includes another template. use <?php echo $this->inc('template'); ?> to |
|
237 | + * do this. |
|
238 | + */ |
|
239 | + public function inc( $file, $additionalParams = null ) { |
|
240 | + return $this->load($this->path.$file.'.php', $additionalParams); |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * Shortcut to print a simple page for users |
|
245 | + * @param string $application The application we render the template for |
|
246 | + * @param string $name Name of the template |
|
247 | + * @param array $parameters Parameters for the template |
|
248 | + * @return boolean|null |
|
249 | + */ |
|
250 | + public static function printUserPage( $application, $name, $parameters = array() ) { |
|
251 | + $content = new OC_Template( $application, $name, "user" ); |
|
252 | + foreach( $parameters as $key => $value ) { |
|
253 | + $content->assign( $key, $value ); |
|
254 | + } |
|
255 | + print $content->printPage(); |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * Shortcut to print a simple page for admins |
|
260 | + * @param string $application The application we render the template for |
|
261 | + * @param string $name Name of the template |
|
262 | + * @param array $parameters Parameters for the template |
|
263 | + * @return bool |
|
264 | + */ |
|
265 | + public static function printAdminPage( $application, $name, $parameters = array() ) { |
|
266 | + $content = new OC_Template( $application, $name, "admin" ); |
|
267 | + foreach( $parameters as $key => $value ) { |
|
268 | + $content->assign( $key, $value ); |
|
269 | + } |
|
270 | + return $content->printPage(); |
|
271 | + } |
|
272 | + |
|
273 | + /** |
|
274 | + * Shortcut to print a simple page for guests |
|
275 | + * @param string $application The application we render the template for |
|
276 | + * @param string $name Name of the template |
|
277 | + * @param array|string $parameters Parameters for the template |
|
278 | + * @return bool |
|
279 | + */ |
|
280 | + public static function printGuestPage( $application, $name, $parameters = array() ) { |
|
281 | + $content = new OC_Template( $application, $name, "guest" ); |
|
282 | + foreach( $parameters as $key => $value ) { |
|
283 | + $content->assign( $key, $value ); |
|
284 | + } |
|
285 | + return $content->printPage(); |
|
286 | + } |
|
287 | + |
|
288 | + /** |
|
289 | + * Print a fatal error page and terminates the script |
|
290 | + * @param string $error_msg The error message to show |
|
291 | + * @param string $hint An optional hint message - needs to be properly escaped |
|
292 | + */ |
|
293 | + public static function printErrorPage( $error_msg, $hint = '' ) { |
|
294 | + if ($error_msg === $hint) { |
|
295 | + // If the hint is the same as the message there is no need to display it twice. |
|
296 | + $hint = ''; |
|
297 | + } |
|
298 | + |
|
299 | + try { |
|
300 | + $content = new \OC_Template( '', 'error', 'error', false ); |
|
301 | + $errors = array(array('error' => $error_msg, 'hint' => $hint)); |
|
302 | + $content->assign( 'errors', $errors ); |
|
303 | + $content->printPage(); |
|
304 | + } catch (\Exception $e) { |
|
305 | + $logger = \OC::$server->getLogger(); |
|
306 | + $logger->error("$error_msg $hint", ['app' => 'core']); |
|
307 | + $logger->logException($e, ['app' => 'core']); |
|
308 | + |
|
309 | + header(self::getHttpProtocol() . ' 500 Internal Server Error'); |
|
310 | + header('Content-Type: text/plain; charset=utf-8'); |
|
311 | + print("$error_msg $hint"); |
|
312 | + } |
|
313 | + die(); |
|
314 | + } |
|
315 | + |
|
316 | + /** |
|
317 | + * print error page using Exception details |
|
318 | + * @param Exception | Throwable $exception |
|
319 | + */ |
|
320 | + public static function printExceptionErrorPage($exception, $fetchPage = false) { |
|
321 | + try { |
|
322 | + $request = \OC::$server->getRequest(); |
|
323 | + $content = new \OC_Template('', 'exception', 'error', false); |
|
324 | + $content->assign('errorClass', get_class($exception)); |
|
325 | + $content->assign('errorMsg', $exception->getMessage()); |
|
326 | + $content->assign('errorCode', $exception->getCode()); |
|
327 | + $content->assign('file', $exception->getFile()); |
|
328 | + $content->assign('line', $exception->getLine()); |
|
329 | + $content->assign('trace', $exception->getTraceAsString()); |
|
330 | + $content->assign('debugMode', \OC::$server->getSystemConfig()->getValue('debug', false)); |
|
331 | + $content->assign('remoteAddr', $request->getRemoteAddress()); |
|
332 | + $content->assign('requestID', $request->getId()); |
|
333 | + if ($fetchPage) { |
|
334 | + return $content->fetchPage(); |
|
335 | + } |
|
336 | + $content->printPage(); |
|
337 | + } catch (\Exception $e) { |
|
338 | + $logger = \OC::$server->getLogger(); |
|
339 | + $logger->logException($exception, ['app' => 'core']); |
|
340 | + $logger->logException($e, ['app' => 'core']); |
|
341 | + |
|
342 | + header(self::getHttpProtocol() . ' 500 Internal Server Error'); |
|
343 | + header('Content-Type: text/plain; charset=utf-8'); |
|
344 | + print("Internal Server Error\n\n"); |
|
345 | + print("The server encountered an internal error and was unable to complete your request.\n"); |
|
346 | + print("Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.\n"); |
|
347 | + print("More details can be found in the server log.\n"); |
|
348 | + } |
|
349 | + die(); |
|
350 | + } |
|
351 | + |
|
352 | + /** |
|
353 | + * This is only here to reduce the dependencies in case of an exception to |
|
354 | + * still be able to print a plain error message. |
|
355 | + * |
|
356 | + * Returns the used HTTP protocol. |
|
357 | + * |
|
358 | + * @return string HTTP protocol. HTTP/2, HTTP/1.1 or HTTP/1.0. |
|
359 | + * @internal Don't use this - use AppFramework\Http\Request->getHttpProtocol instead |
|
360 | + */ |
|
361 | + protected static function getHttpProtocol() { |
|
362 | + $claimedProtocol = strtoupper($_SERVER['SERVER_PROTOCOL']); |
|
363 | + $validProtocols = [ |
|
364 | + 'HTTP/1.0', |
|
365 | + 'HTTP/1.1', |
|
366 | + 'HTTP/2', |
|
367 | + ]; |
|
368 | + if(in_array($claimedProtocol, $validProtocols, true)) { |
|
369 | + return $claimedProtocol; |
|
370 | + } |
|
371 | + return 'HTTP/1.1'; |
|
372 | + } |
|
373 | 373 | } |