@@ -26,79 +26,79 @@ |
||
26 | 26 | use OCP\Diagnostics\IEvent; |
27 | 27 | |
28 | 28 | class Event implements IEvent { |
29 | - /** |
|
30 | - * @var string |
|
31 | - */ |
|
32 | - protected $id; |
|
29 | + /** |
|
30 | + * @var string |
|
31 | + */ |
|
32 | + protected $id; |
|
33 | 33 | |
34 | - /** |
|
35 | - * @var float |
|
36 | - */ |
|
37 | - protected $start; |
|
34 | + /** |
|
35 | + * @var float |
|
36 | + */ |
|
37 | + protected $start; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @var float |
|
41 | - */ |
|
42 | - protected $end; |
|
39 | + /** |
|
40 | + * @var float |
|
41 | + */ |
|
42 | + protected $end; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @var string |
|
46 | - */ |
|
47 | - protected $description; |
|
44 | + /** |
|
45 | + * @var string |
|
46 | + */ |
|
47 | + protected $description; |
|
48 | 48 | |
49 | - /** |
|
50 | - * @param string $id |
|
51 | - * @param string $description |
|
52 | - * @param float $start |
|
53 | - */ |
|
54 | - public function __construct($id, $description, $start) { |
|
55 | - $this->id = $id; |
|
56 | - $this->description = $description; |
|
57 | - $this->start = $start; |
|
58 | - } |
|
49 | + /** |
|
50 | + * @param string $id |
|
51 | + * @param string $description |
|
52 | + * @param float $start |
|
53 | + */ |
|
54 | + public function __construct($id, $description, $start) { |
|
55 | + $this->id = $id; |
|
56 | + $this->description = $description; |
|
57 | + $this->start = $start; |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * @param float $time |
|
62 | - */ |
|
63 | - public function end($time) { |
|
64 | - $this->end = $time; |
|
65 | - } |
|
60 | + /** |
|
61 | + * @param float $time |
|
62 | + */ |
|
63 | + public function end($time) { |
|
64 | + $this->end = $time; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * @return float |
|
69 | - */ |
|
70 | - public function getStart() { |
|
71 | - return $this->start; |
|
72 | - } |
|
67 | + /** |
|
68 | + * @return float |
|
69 | + */ |
|
70 | + public function getStart() { |
|
71 | + return $this->start; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @return string |
|
76 | - */ |
|
77 | - public function getId() { |
|
78 | - return $this->id; |
|
79 | - } |
|
74 | + /** |
|
75 | + * @return string |
|
76 | + */ |
|
77 | + public function getId() { |
|
78 | + return $this->id; |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @return string |
|
83 | - */ |
|
84 | - public function getDescription() { |
|
85 | - return $this->description; |
|
86 | - } |
|
81 | + /** |
|
82 | + * @return string |
|
83 | + */ |
|
84 | + public function getDescription() { |
|
85 | + return $this->description; |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * @return float |
|
90 | - */ |
|
91 | - public function getEnd() { |
|
92 | - return $this->end; |
|
93 | - } |
|
88 | + /** |
|
89 | + * @return float |
|
90 | + */ |
|
91 | + public function getEnd() { |
|
92 | + return $this->end; |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * @return float |
|
97 | - */ |
|
98 | - public function getDuration() { |
|
99 | - if (!$this->end) { |
|
100 | - $this->end = microtime(true); |
|
101 | - } |
|
102 | - return $this->end - $this->start; |
|
103 | - } |
|
95 | + /** |
|
96 | + * @return float |
|
97 | + */ |
|
98 | + public function getDuration() { |
|
99 | + if (!$this->end) { |
|
100 | + $this->end = microtime(true); |
|
101 | + } |
|
102 | + return $this->end - $this->start; |
|
103 | + } |
|
104 | 104 | } |
@@ -29,100 +29,100 @@ |
||
29 | 29 | use OCP\ISession; |
30 | 30 | |
31 | 31 | class DateTimeZone implements IDateTimeZone { |
32 | - /** @var IConfig */ |
|
33 | - protected $config; |
|
32 | + /** @var IConfig */ |
|
33 | + protected $config; |
|
34 | 34 | |
35 | - /** @var ISession */ |
|
36 | - protected $session; |
|
35 | + /** @var ISession */ |
|
36 | + protected $session; |
|
37 | 37 | |
38 | - /** |
|
39 | - * Constructor |
|
40 | - * |
|
41 | - * @param IConfig $config |
|
42 | - * @param ISession $session |
|
43 | - */ |
|
44 | - public function __construct(IConfig $config, ISession $session) { |
|
45 | - $this->config = $config; |
|
46 | - $this->session = $session; |
|
47 | - } |
|
38 | + /** |
|
39 | + * Constructor |
|
40 | + * |
|
41 | + * @param IConfig $config |
|
42 | + * @param ISession $session |
|
43 | + */ |
|
44 | + public function __construct(IConfig $config, ISession $session) { |
|
45 | + $this->config = $config; |
|
46 | + $this->session = $session; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Get the timezone of the current user, based on his session information and config data |
|
51 | - * |
|
52 | - * @param bool|int $timestamp |
|
53 | - * @return \DateTimeZone |
|
54 | - */ |
|
55 | - public function getTimeZone($timestamp = false) { |
|
56 | - $timeZone = $this->config->getUserValue($this->session->get('user_id'), 'core', 'timezone', null); |
|
57 | - if ($timeZone === null) { |
|
58 | - if ($this->session->exists('timezone')) { |
|
59 | - return $this->guessTimeZoneFromOffset($this->session->get('timezone'), $timestamp); |
|
60 | - } |
|
61 | - $timeZone = $this->getDefaultTimeZone(); |
|
62 | - } |
|
49 | + /** |
|
50 | + * Get the timezone of the current user, based on his session information and config data |
|
51 | + * |
|
52 | + * @param bool|int $timestamp |
|
53 | + * @return \DateTimeZone |
|
54 | + */ |
|
55 | + public function getTimeZone($timestamp = false) { |
|
56 | + $timeZone = $this->config->getUserValue($this->session->get('user_id'), 'core', 'timezone', null); |
|
57 | + if ($timeZone === null) { |
|
58 | + if ($this->session->exists('timezone')) { |
|
59 | + return $this->guessTimeZoneFromOffset($this->session->get('timezone'), $timestamp); |
|
60 | + } |
|
61 | + $timeZone = $this->getDefaultTimeZone(); |
|
62 | + } |
|
63 | 63 | |
64 | - try { |
|
65 | - return new \DateTimeZone($timeZone); |
|
66 | - } catch (\Exception $e) { |
|
67 | - \OCP\Util::writeLog('datetimezone', 'Failed to created DateTimeZone "' . $timeZone . "'", \OCP\Util::DEBUG); |
|
68 | - return new \DateTimeZone($this->getDefaultTimeZone()); |
|
69 | - } |
|
70 | - } |
|
64 | + try { |
|
65 | + return new \DateTimeZone($timeZone); |
|
66 | + } catch (\Exception $e) { |
|
67 | + \OCP\Util::writeLog('datetimezone', 'Failed to created DateTimeZone "' . $timeZone . "'", \OCP\Util::DEBUG); |
|
68 | + return new \DateTimeZone($this->getDefaultTimeZone()); |
|
69 | + } |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * Guess the DateTimeZone for a given offset |
|
74 | - * |
|
75 | - * We first try to find a Etc/GMT* timezone, if that does not exist, |
|
76 | - * we try to find it manually, before falling back to UTC. |
|
77 | - * |
|
78 | - * @param mixed $offset |
|
79 | - * @param bool|int $timestamp |
|
80 | - * @return \DateTimeZone |
|
81 | - */ |
|
82 | - protected function guessTimeZoneFromOffset($offset, $timestamp) { |
|
83 | - try { |
|
84 | - // Note: the timeZone name is the inverse to the offset, |
|
85 | - // so a positive offset means negative timeZone |
|
86 | - // and the other way around. |
|
87 | - if ($offset > 0) { |
|
88 | - $timeZone = 'Etc/GMT-' . $offset; |
|
89 | - } else { |
|
90 | - $timeZone = 'Etc/GMT+' . abs($offset); |
|
91 | - } |
|
72 | + /** |
|
73 | + * Guess the DateTimeZone for a given offset |
|
74 | + * |
|
75 | + * We first try to find a Etc/GMT* timezone, if that does not exist, |
|
76 | + * we try to find it manually, before falling back to UTC. |
|
77 | + * |
|
78 | + * @param mixed $offset |
|
79 | + * @param bool|int $timestamp |
|
80 | + * @return \DateTimeZone |
|
81 | + */ |
|
82 | + protected function guessTimeZoneFromOffset($offset, $timestamp) { |
|
83 | + try { |
|
84 | + // Note: the timeZone name is the inverse to the offset, |
|
85 | + // so a positive offset means negative timeZone |
|
86 | + // and the other way around. |
|
87 | + if ($offset > 0) { |
|
88 | + $timeZone = 'Etc/GMT-' . $offset; |
|
89 | + } else { |
|
90 | + $timeZone = 'Etc/GMT+' . abs($offset); |
|
91 | + } |
|
92 | 92 | |
93 | - return new \DateTimeZone($timeZone); |
|
94 | - } catch (\Exception $e) { |
|
95 | - // If the offset has no Etc/GMT* timezone, |
|
96 | - // we try to guess one timezone that has the same offset |
|
97 | - foreach (\DateTimeZone::listIdentifiers() as $timeZone) { |
|
98 | - $dtz = new \DateTimeZone($timeZone); |
|
99 | - $dateTime = new \DateTime(); |
|
93 | + return new \DateTimeZone($timeZone); |
|
94 | + } catch (\Exception $e) { |
|
95 | + // If the offset has no Etc/GMT* timezone, |
|
96 | + // we try to guess one timezone that has the same offset |
|
97 | + foreach (\DateTimeZone::listIdentifiers() as $timeZone) { |
|
98 | + $dtz = new \DateTimeZone($timeZone); |
|
99 | + $dateTime = new \DateTime(); |
|
100 | 100 | |
101 | - if ($timestamp !== false) { |
|
102 | - $dateTime->setTimestamp($timestamp); |
|
103 | - } |
|
101 | + if ($timestamp !== false) { |
|
102 | + $dateTime->setTimestamp($timestamp); |
|
103 | + } |
|
104 | 104 | |
105 | - $dtOffset = $dtz->getOffset($dateTime); |
|
106 | - if ($dtOffset == 3600 * $offset) { |
|
107 | - return $dtz; |
|
108 | - } |
|
109 | - } |
|
105 | + $dtOffset = $dtz->getOffset($dateTime); |
|
106 | + if ($dtOffset == 3600 * $offset) { |
|
107 | + return $dtz; |
|
108 | + } |
|
109 | + } |
|
110 | 110 | |
111 | - // No timezone found, fallback to UTC |
|
112 | - \OCP\Util::writeLog('datetimezone', 'Failed to find DateTimeZone for offset "' . $offset . "'", \OCP\Util::DEBUG); |
|
113 | - return new \DateTimeZone($this->getDefaultTimeZone()); |
|
114 | - } |
|
115 | - } |
|
111 | + // No timezone found, fallback to UTC |
|
112 | + \OCP\Util::writeLog('datetimezone', 'Failed to find DateTimeZone for offset "' . $offset . "'", \OCP\Util::DEBUG); |
|
113 | + return new \DateTimeZone($this->getDefaultTimeZone()); |
|
114 | + } |
|
115 | + } |
|
116 | 116 | |
117 | - /** |
|
118 | - * Get the default timezone of the server |
|
119 | - * |
|
120 | - * Falls back to UTC if it is not yet set. |
|
121 | - * |
|
122 | - * @return string |
|
123 | - */ |
|
124 | - protected function getDefaultTimeZone() { |
|
125 | - $serverTimeZone = date_default_timezone_get(); |
|
126 | - return $serverTimeZone ?: 'UTC'; |
|
127 | - } |
|
117 | + /** |
|
118 | + * Get the default timezone of the server |
|
119 | + * |
|
120 | + * Falls back to UTC if it is not yet set. |
|
121 | + * |
|
122 | + * @return string |
|
123 | + */ |
|
124 | + protected function getDefaultTimeZone() { |
|
125 | + $serverTimeZone = date_default_timezone_get(); |
|
126 | + return $serverTimeZone ?: 'UTC'; |
|
127 | + } |
|
128 | 128 | } |
@@ -42,199 +42,199 @@ |
||
42 | 42 | * Class to generate URLs |
43 | 43 | */ |
44 | 44 | class URLGenerator implements IURLGenerator { |
45 | - /** @var IConfig */ |
|
46 | - private $config; |
|
47 | - /** @var ICacheFactory */ |
|
48 | - private $cacheFactory; |
|
49 | - |
|
50 | - /** |
|
51 | - * @param IConfig $config |
|
52 | - * @param ICacheFactory $cacheFactory |
|
53 | - */ |
|
54 | - public function __construct(IConfig $config, |
|
55 | - ICacheFactory $cacheFactory) { |
|
56 | - $this->config = $config; |
|
57 | - $this->cacheFactory = $cacheFactory; |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Creates an url using a defined route |
|
62 | - * @param string $route |
|
63 | - * @param array $parameters args with param=>value, will be appended to the returned url |
|
64 | - * @return string the url |
|
65 | - * |
|
66 | - * Returns a url to the given route. |
|
67 | - */ |
|
68 | - public function linkToRoute($route, $parameters = array()) { |
|
69 | - // TODO: mock router |
|
70 | - $urlLinkTo = \OC::$server->getRouter()->generate($route, $parameters); |
|
71 | - return $urlLinkTo; |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Creates an absolute url using a defined route |
|
76 | - * @param string $routeName |
|
77 | - * @param array $arguments args with param=>value, will be appended to the returned url |
|
78 | - * @return string the url |
|
79 | - * |
|
80 | - * Returns an absolute url to the given route. |
|
81 | - */ |
|
82 | - public function linkToRouteAbsolute($routeName, $arguments = array()) { |
|
83 | - return $this->getAbsoluteURL($this->linkToRoute($routeName, $arguments)); |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Creates an url |
|
88 | - * @param string $app app |
|
89 | - * @param string $file file |
|
90 | - * @param array $args array with param=>value, will be appended to the returned url |
|
91 | - * The value of $args will be urlencoded |
|
92 | - * @return string the url |
|
93 | - * |
|
94 | - * Returns a url to the given app and file. |
|
95 | - */ |
|
96 | - public function linkTo( $app, $file, $args = array() ) { |
|
97 | - $frontControllerActive = ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true'); |
|
98 | - |
|
99 | - if( $app != '' ) { |
|
100 | - $app_path = \OC_App::getAppPath($app); |
|
101 | - // Check if the app is in the app folder |
|
102 | - if ($app_path && file_exists($app_path . '/' . $file)) { |
|
103 | - if (substr($file, -3) == 'php') { |
|
104 | - |
|
105 | - $urlLinkTo = \OC::$WEBROOT . '/index.php/apps/' . $app; |
|
106 | - if ($frontControllerActive) { |
|
107 | - $urlLinkTo = \OC::$WEBROOT . '/apps/' . $app; |
|
108 | - } |
|
109 | - $urlLinkTo .= ($file != 'index.php') ? '/' . $file : ''; |
|
110 | - } else { |
|
111 | - $urlLinkTo = \OC_App::getAppWebPath($app) . '/' . $file; |
|
112 | - } |
|
113 | - } else { |
|
114 | - $urlLinkTo = \OC::$WEBROOT . '/' . $app . '/' . $file; |
|
115 | - } |
|
116 | - } else { |
|
117 | - if (file_exists(\OC::$SERVERROOT . '/core/' . $file)) { |
|
118 | - $urlLinkTo = \OC::$WEBROOT . '/core/' . $file; |
|
119 | - } else { |
|
120 | - if ($frontControllerActive && $file === 'index.php') { |
|
121 | - $urlLinkTo = \OC::$WEBROOT . '/'; |
|
122 | - } else { |
|
123 | - $urlLinkTo = \OC::$WEBROOT . '/' . $file; |
|
124 | - } |
|
125 | - } |
|
126 | - } |
|
127 | - |
|
128 | - if ($args && $query = http_build_query($args, '', '&')) { |
|
129 | - $urlLinkTo .= '?' . $query; |
|
130 | - } |
|
131 | - |
|
132 | - return $urlLinkTo; |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * Creates path to an image |
|
137 | - * @param string $app app |
|
138 | - * @param string $image image name |
|
139 | - * @throws \RuntimeException If the image does not exist |
|
140 | - * @return string the url |
|
141 | - * |
|
142 | - * Returns the path to the image. |
|
143 | - */ |
|
144 | - public function imagePath($app, $image) { |
|
145 | - $cache = $this->cacheFactory->create('imagePath'); |
|
146 | - $cacheKey = $app.'-'.$image; |
|
147 | - if($key = $cache->get($cacheKey)) { |
|
148 | - return $key; |
|
149 | - } |
|
150 | - |
|
151 | - // Read the selected theme from the config file |
|
152 | - $theme = \OC_Util::getTheme(); |
|
153 | - |
|
154 | - //if a theme has a png but not an svg always use the png |
|
155 | - $basename = substr(basename($image),0,-4); |
|
156 | - |
|
157 | - $appPath = \OC_App::getAppPath($app); |
|
158 | - |
|
159 | - // Check if the app is in the app folder |
|
160 | - $path = ''; |
|
161 | - $themingEnabled = $this->config->getSystemValue('installed', false) && \OCP\App::isEnabled('theming') && \OC_App::isAppLoaded('theming'); |
|
162 | - if($themingEnabled && $image === "favicon.ico" && \OC::$server->getThemingDefaults()->shouldReplaceIcons()) { |
|
163 | - $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
164 | - if($app==="") { $app = "core"; } |
|
165 | - $path = $this->linkToRoute('theming.Icon.getFavicon', [ 'app' => $app ]) . '?v='. $cacheBusterValue; |
|
166 | - } elseif($themingEnabled && $image === "favicon-touch.png" && \OC::$server->getThemingDefaults()->shouldReplaceIcons()) { |
|
167 | - $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
168 | - if($app==="") { $app = "core"; } |
|
169 | - $path = $this->linkToRoute('theming.Icon.getTouchIcon', [ 'app' => $app ]) . '?v='. $cacheBusterValue; |
|
170 | - } elseif (file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$image")) { |
|
171 | - $path = \OC::$WEBROOT . "/themes/$theme/apps/$app/img/$image"; |
|
172 | - } elseif (!file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$basename.svg") |
|
173 | - && file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$basename.png")) { |
|
174 | - $path = \OC::$WEBROOT . "/themes/$theme/apps/$app/img/$basename.png"; |
|
175 | - } elseif (!empty($app) and file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$image")) { |
|
176 | - $path = \OC::$WEBROOT . "/themes/$theme/$app/img/$image"; |
|
177 | - } elseif (!empty($app) and (!file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$basename.svg") |
|
178 | - && file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$basename.png"))) { |
|
179 | - $path = \OC::$WEBROOT . "/themes/$theme/$app/img/$basename.png"; |
|
180 | - } elseif (file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$image")) { |
|
181 | - $path = \OC::$WEBROOT . "/themes/$theme/core/img/$image"; |
|
182 | - } elseif (!file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$basename.svg") |
|
183 | - && file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$basename.png")) { |
|
184 | - $path = \OC::$WEBROOT . "/themes/$theme/core/img/$basename.png"; |
|
185 | - } elseif ($appPath && file_exists($appPath . "/img/$image")) { |
|
186 | - $path = \OC_App::getAppWebPath($app) . "/img/$image"; |
|
187 | - } elseif ($appPath && !file_exists($appPath . "/img/$basename.svg") |
|
188 | - && file_exists($appPath . "/img/$basename.png")) { |
|
189 | - $path = \OC_App::getAppWebPath($app) . "/img/$basename.png"; |
|
190 | - } elseif (!empty($app) and file_exists(\OC::$SERVERROOT . "/$app/img/$image")) { |
|
191 | - $path = \OC::$WEBROOT . "/$app/img/$image"; |
|
192 | - } elseif (!empty($app) and (!file_exists(\OC::$SERVERROOT . "/$app/img/$basename.svg") |
|
193 | - && file_exists(\OC::$SERVERROOT . "/$app/img/$basename.png"))) { |
|
194 | - $path = \OC::$WEBROOT . "/$app/img/$basename.png"; |
|
195 | - } elseif (file_exists(\OC::$SERVERROOT . "/core/img/$image")) { |
|
196 | - $path = \OC::$WEBROOT . "/core/img/$image"; |
|
197 | - } elseif (!file_exists(\OC::$SERVERROOT . "/core/img/$basename.svg") |
|
198 | - && file_exists(\OC::$SERVERROOT . "/core/img/$basename.png")) { |
|
199 | - $path = \OC::$WEBROOT . "/themes/$theme/core/img/$basename.png"; |
|
200 | - } |
|
201 | - |
|
202 | - if($path !== '') { |
|
203 | - $cache->set($cacheKey, $path); |
|
204 | - return $path; |
|
205 | - } else { |
|
206 | - throw new RuntimeException('image not found: image:' . $image . ' webroot:' . \OC::$WEBROOT . ' serverroot:' . \OC::$SERVERROOT); |
|
207 | - } |
|
208 | - } |
|
209 | - |
|
210 | - |
|
211 | - /** |
|
212 | - * Makes an URL absolute |
|
213 | - * @param string $url the url in the ownCloud host |
|
214 | - * @return string the absolute version of the url |
|
215 | - */ |
|
216 | - public function getAbsoluteURL($url) { |
|
217 | - $separator = $url[0] === '/' ? '' : '/'; |
|
218 | - |
|
219 | - if (\OC::$CLI && !defined('PHPUNIT_RUN')) { |
|
220 | - return rtrim($this->config->getSystemValue('overwrite.cli.url'), '/') . '/' . ltrim($url, '/'); |
|
221 | - } |
|
222 | - |
|
223 | - // The ownCloud web root can already be prepended. |
|
224 | - $webRoot = substr($url, 0, strlen(\OC::$WEBROOT)) === \OC::$WEBROOT |
|
225 | - ? '' |
|
226 | - : \OC::$WEBROOT; |
|
227 | - |
|
228 | - $request = \OC::$server->getRequest(); |
|
229 | - return $request->getServerProtocol() . '://' . $request->getServerHost() . $webRoot . $separator . $url; |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * @param string $key |
|
234 | - * @return string url to the online documentation |
|
235 | - */ |
|
236 | - public function linkToDocs($key) { |
|
237 | - $theme = \OC::$server->getThemingDefaults(); |
|
238 | - return $theme->buildDocLinkToKey($key); |
|
239 | - } |
|
45 | + /** @var IConfig */ |
|
46 | + private $config; |
|
47 | + /** @var ICacheFactory */ |
|
48 | + private $cacheFactory; |
|
49 | + |
|
50 | + /** |
|
51 | + * @param IConfig $config |
|
52 | + * @param ICacheFactory $cacheFactory |
|
53 | + */ |
|
54 | + public function __construct(IConfig $config, |
|
55 | + ICacheFactory $cacheFactory) { |
|
56 | + $this->config = $config; |
|
57 | + $this->cacheFactory = $cacheFactory; |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Creates an url using a defined route |
|
62 | + * @param string $route |
|
63 | + * @param array $parameters args with param=>value, will be appended to the returned url |
|
64 | + * @return string the url |
|
65 | + * |
|
66 | + * Returns a url to the given route. |
|
67 | + */ |
|
68 | + public function linkToRoute($route, $parameters = array()) { |
|
69 | + // TODO: mock router |
|
70 | + $urlLinkTo = \OC::$server->getRouter()->generate($route, $parameters); |
|
71 | + return $urlLinkTo; |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Creates an absolute url using a defined route |
|
76 | + * @param string $routeName |
|
77 | + * @param array $arguments args with param=>value, will be appended to the returned url |
|
78 | + * @return string the url |
|
79 | + * |
|
80 | + * Returns an absolute url to the given route. |
|
81 | + */ |
|
82 | + public function linkToRouteAbsolute($routeName, $arguments = array()) { |
|
83 | + return $this->getAbsoluteURL($this->linkToRoute($routeName, $arguments)); |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Creates an url |
|
88 | + * @param string $app app |
|
89 | + * @param string $file file |
|
90 | + * @param array $args array with param=>value, will be appended to the returned url |
|
91 | + * The value of $args will be urlencoded |
|
92 | + * @return string the url |
|
93 | + * |
|
94 | + * Returns a url to the given app and file. |
|
95 | + */ |
|
96 | + public function linkTo( $app, $file, $args = array() ) { |
|
97 | + $frontControllerActive = ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true'); |
|
98 | + |
|
99 | + if( $app != '' ) { |
|
100 | + $app_path = \OC_App::getAppPath($app); |
|
101 | + // Check if the app is in the app folder |
|
102 | + if ($app_path && file_exists($app_path . '/' . $file)) { |
|
103 | + if (substr($file, -3) == 'php') { |
|
104 | + |
|
105 | + $urlLinkTo = \OC::$WEBROOT . '/index.php/apps/' . $app; |
|
106 | + if ($frontControllerActive) { |
|
107 | + $urlLinkTo = \OC::$WEBROOT . '/apps/' . $app; |
|
108 | + } |
|
109 | + $urlLinkTo .= ($file != 'index.php') ? '/' . $file : ''; |
|
110 | + } else { |
|
111 | + $urlLinkTo = \OC_App::getAppWebPath($app) . '/' . $file; |
|
112 | + } |
|
113 | + } else { |
|
114 | + $urlLinkTo = \OC::$WEBROOT . '/' . $app . '/' . $file; |
|
115 | + } |
|
116 | + } else { |
|
117 | + if (file_exists(\OC::$SERVERROOT . '/core/' . $file)) { |
|
118 | + $urlLinkTo = \OC::$WEBROOT . '/core/' . $file; |
|
119 | + } else { |
|
120 | + if ($frontControllerActive && $file === 'index.php') { |
|
121 | + $urlLinkTo = \OC::$WEBROOT . '/'; |
|
122 | + } else { |
|
123 | + $urlLinkTo = \OC::$WEBROOT . '/' . $file; |
|
124 | + } |
|
125 | + } |
|
126 | + } |
|
127 | + |
|
128 | + if ($args && $query = http_build_query($args, '', '&')) { |
|
129 | + $urlLinkTo .= '?' . $query; |
|
130 | + } |
|
131 | + |
|
132 | + return $urlLinkTo; |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * Creates path to an image |
|
137 | + * @param string $app app |
|
138 | + * @param string $image image name |
|
139 | + * @throws \RuntimeException If the image does not exist |
|
140 | + * @return string the url |
|
141 | + * |
|
142 | + * Returns the path to the image. |
|
143 | + */ |
|
144 | + public function imagePath($app, $image) { |
|
145 | + $cache = $this->cacheFactory->create('imagePath'); |
|
146 | + $cacheKey = $app.'-'.$image; |
|
147 | + if($key = $cache->get($cacheKey)) { |
|
148 | + return $key; |
|
149 | + } |
|
150 | + |
|
151 | + // Read the selected theme from the config file |
|
152 | + $theme = \OC_Util::getTheme(); |
|
153 | + |
|
154 | + //if a theme has a png but not an svg always use the png |
|
155 | + $basename = substr(basename($image),0,-4); |
|
156 | + |
|
157 | + $appPath = \OC_App::getAppPath($app); |
|
158 | + |
|
159 | + // Check if the app is in the app folder |
|
160 | + $path = ''; |
|
161 | + $themingEnabled = $this->config->getSystemValue('installed', false) && \OCP\App::isEnabled('theming') && \OC_App::isAppLoaded('theming'); |
|
162 | + if($themingEnabled && $image === "favicon.ico" && \OC::$server->getThemingDefaults()->shouldReplaceIcons()) { |
|
163 | + $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
164 | + if($app==="") { $app = "core"; } |
|
165 | + $path = $this->linkToRoute('theming.Icon.getFavicon', [ 'app' => $app ]) . '?v='. $cacheBusterValue; |
|
166 | + } elseif($themingEnabled && $image === "favicon-touch.png" && \OC::$server->getThemingDefaults()->shouldReplaceIcons()) { |
|
167 | + $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
168 | + if($app==="") { $app = "core"; } |
|
169 | + $path = $this->linkToRoute('theming.Icon.getTouchIcon', [ 'app' => $app ]) . '?v='. $cacheBusterValue; |
|
170 | + } elseif (file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$image")) { |
|
171 | + $path = \OC::$WEBROOT . "/themes/$theme/apps/$app/img/$image"; |
|
172 | + } elseif (!file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$basename.svg") |
|
173 | + && file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$basename.png")) { |
|
174 | + $path = \OC::$WEBROOT . "/themes/$theme/apps/$app/img/$basename.png"; |
|
175 | + } elseif (!empty($app) and file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$image")) { |
|
176 | + $path = \OC::$WEBROOT . "/themes/$theme/$app/img/$image"; |
|
177 | + } elseif (!empty($app) and (!file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$basename.svg") |
|
178 | + && file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$basename.png"))) { |
|
179 | + $path = \OC::$WEBROOT . "/themes/$theme/$app/img/$basename.png"; |
|
180 | + } elseif (file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$image")) { |
|
181 | + $path = \OC::$WEBROOT . "/themes/$theme/core/img/$image"; |
|
182 | + } elseif (!file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$basename.svg") |
|
183 | + && file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$basename.png")) { |
|
184 | + $path = \OC::$WEBROOT . "/themes/$theme/core/img/$basename.png"; |
|
185 | + } elseif ($appPath && file_exists($appPath . "/img/$image")) { |
|
186 | + $path = \OC_App::getAppWebPath($app) . "/img/$image"; |
|
187 | + } elseif ($appPath && !file_exists($appPath . "/img/$basename.svg") |
|
188 | + && file_exists($appPath . "/img/$basename.png")) { |
|
189 | + $path = \OC_App::getAppWebPath($app) . "/img/$basename.png"; |
|
190 | + } elseif (!empty($app) and file_exists(\OC::$SERVERROOT . "/$app/img/$image")) { |
|
191 | + $path = \OC::$WEBROOT . "/$app/img/$image"; |
|
192 | + } elseif (!empty($app) and (!file_exists(\OC::$SERVERROOT . "/$app/img/$basename.svg") |
|
193 | + && file_exists(\OC::$SERVERROOT . "/$app/img/$basename.png"))) { |
|
194 | + $path = \OC::$WEBROOT . "/$app/img/$basename.png"; |
|
195 | + } elseif (file_exists(\OC::$SERVERROOT . "/core/img/$image")) { |
|
196 | + $path = \OC::$WEBROOT . "/core/img/$image"; |
|
197 | + } elseif (!file_exists(\OC::$SERVERROOT . "/core/img/$basename.svg") |
|
198 | + && file_exists(\OC::$SERVERROOT . "/core/img/$basename.png")) { |
|
199 | + $path = \OC::$WEBROOT . "/themes/$theme/core/img/$basename.png"; |
|
200 | + } |
|
201 | + |
|
202 | + if($path !== '') { |
|
203 | + $cache->set($cacheKey, $path); |
|
204 | + return $path; |
|
205 | + } else { |
|
206 | + throw new RuntimeException('image not found: image:' . $image . ' webroot:' . \OC::$WEBROOT . ' serverroot:' . \OC::$SERVERROOT); |
|
207 | + } |
|
208 | + } |
|
209 | + |
|
210 | + |
|
211 | + /** |
|
212 | + * Makes an URL absolute |
|
213 | + * @param string $url the url in the ownCloud host |
|
214 | + * @return string the absolute version of the url |
|
215 | + */ |
|
216 | + public function getAbsoluteURL($url) { |
|
217 | + $separator = $url[0] === '/' ? '' : '/'; |
|
218 | + |
|
219 | + if (\OC::$CLI && !defined('PHPUNIT_RUN')) { |
|
220 | + return rtrim($this->config->getSystemValue('overwrite.cli.url'), '/') . '/' . ltrim($url, '/'); |
|
221 | + } |
|
222 | + |
|
223 | + // The ownCloud web root can already be prepended. |
|
224 | + $webRoot = substr($url, 0, strlen(\OC::$WEBROOT)) === \OC::$WEBROOT |
|
225 | + ? '' |
|
226 | + : \OC::$WEBROOT; |
|
227 | + |
|
228 | + $request = \OC::$server->getRequest(); |
|
229 | + return $request->getServerProtocol() . '://' . $request->getServerHost() . $webRoot . $separator . $url; |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * @param string $key |
|
234 | + * @return string url to the online documentation |
|
235 | + */ |
|
236 | + public function linkToDocs($key) { |
|
237 | + $theme = \OC::$server->getThemingDefaults(); |
|
238 | + return $theme->buildDocLinkToKey($key); |
|
239 | + } |
|
240 | 240 | } |
@@ -33,47 +33,47 @@ |
||
33 | 33 | */ |
34 | 34 | class TagMapper extends Mapper { |
35 | 35 | |
36 | - /** |
|
37 | - * Constructor. |
|
38 | - * |
|
39 | - * @param IDBConnection $db Instance of the Db abstraction layer. |
|
40 | - */ |
|
41 | - public function __construct(IDBConnection $db) { |
|
42 | - parent::__construct($db, 'vcategory', 'OC\Tagging\Tag'); |
|
43 | - } |
|
36 | + /** |
|
37 | + * Constructor. |
|
38 | + * |
|
39 | + * @param IDBConnection $db Instance of the Db abstraction layer. |
|
40 | + */ |
|
41 | + public function __construct(IDBConnection $db) { |
|
42 | + parent::__construct($db, 'vcategory', 'OC\Tagging\Tag'); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Load tags from the database. |
|
47 | - * |
|
48 | - * @param array|string $owners The user(s) whose tags we are going to load. |
|
49 | - * @param string $type The type of item for which we are loading tags. |
|
50 | - * @return array An array of Tag objects. |
|
51 | - */ |
|
52 | - public function loadTags($owners, $type) { |
|
53 | - if(!is_array($owners)) { |
|
54 | - $owners = array($owners); |
|
55 | - } |
|
45 | + /** |
|
46 | + * Load tags from the database. |
|
47 | + * |
|
48 | + * @param array|string $owners The user(s) whose tags we are going to load. |
|
49 | + * @param string $type The type of item for which we are loading tags. |
|
50 | + * @return array An array of Tag objects. |
|
51 | + */ |
|
52 | + public function loadTags($owners, $type) { |
|
53 | + if(!is_array($owners)) { |
|
54 | + $owners = array($owners); |
|
55 | + } |
|
56 | 56 | |
57 | - $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` ' |
|
58 | - . 'WHERE `uid` IN (' . str_repeat('?,', count($owners)-1) . '?) AND `type` = ? ORDER BY `category`'; |
|
59 | - return $this->findEntities($sql, array_merge($owners, array($type))); |
|
60 | - } |
|
57 | + $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` ' |
|
58 | + . 'WHERE `uid` IN (' . str_repeat('?,', count($owners)-1) . '?) AND `type` = ? ORDER BY `category`'; |
|
59 | + return $this->findEntities($sql, array_merge($owners, array($type))); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Check if a given Tag object already exists in the database. |
|
64 | - * |
|
65 | - * @param Tag $tag The tag to look for in the database. |
|
66 | - * @return bool |
|
67 | - */ |
|
68 | - public function tagExists($tag) { |
|
69 | - $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` ' |
|
70 | - . 'WHERE `uid` = ? AND `type` = ? AND `category` = ?'; |
|
71 | - try { |
|
72 | - $this->findEntity($sql, array($tag->getOwner(), $tag->getType(), $tag->getName())); |
|
73 | - } catch (DoesNotExistException $e) { |
|
74 | - return false; |
|
75 | - } |
|
76 | - return true; |
|
77 | - } |
|
62 | + /** |
|
63 | + * Check if a given Tag object already exists in the database. |
|
64 | + * |
|
65 | + * @param Tag $tag The tag to look for in the database. |
|
66 | + * @return bool |
|
67 | + */ |
|
68 | + public function tagExists($tag) { |
|
69 | + $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` ' |
|
70 | + . 'WHERE `uid` = ? AND `type` = ? AND `category` = ?'; |
|
71 | + try { |
|
72 | + $this->findEntity($sql, array($tag->getOwner(), $tag->getType(), $tag->getName())); |
|
73 | + } catch (DoesNotExistException $e) { |
|
74 | + return false; |
|
75 | + } |
|
76 | + return true; |
|
77 | + } |
|
78 | 78 | } |
79 | 79 |
@@ -37,54 +37,54 @@ |
||
37 | 37 | */ |
38 | 38 | class Tag extends Entity { |
39 | 39 | |
40 | - protected $owner; |
|
41 | - protected $type; |
|
42 | - protected $name; |
|
40 | + protected $owner; |
|
41 | + protected $type; |
|
42 | + protected $name; |
|
43 | 43 | |
44 | - /** |
|
45 | - * Constructor. |
|
46 | - * |
|
47 | - * @param string $owner The tag's owner |
|
48 | - * @param string $type The type of item this tag is used for |
|
49 | - * @param string $name The tag's name |
|
50 | - */ |
|
51 | - public function __construct($owner = null, $type = null, $name = null) { |
|
52 | - $this->setOwner($owner); |
|
53 | - $this->setType($type); |
|
54 | - $this->setName($name); |
|
55 | - } |
|
44 | + /** |
|
45 | + * Constructor. |
|
46 | + * |
|
47 | + * @param string $owner The tag's owner |
|
48 | + * @param string $type The type of item this tag is used for |
|
49 | + * @param string $name The tag's name |
|
50 | + */ |
|
51 | + public function __construct($owner = null, $type = null, $name = null) { |
|
52 | + $this->setOwner($owner); |
|
53 | + $this->setType($type); |
|
54 | + $this->setName($name); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Transform a database columnname to a property |
|
59 | - * |
|
60 | - * @param string $columnName the name of the column |
|
61 | - * @return string the property name |
|
62 | - * @todo migrate existing database columns to the correct names |
|
63 | - * to be able to drop this direct mapping |
|
64 | - */ |
|
65 | - public function columnToProperty($columnName){ |
|
66 | - if ($columnName === 'category') { |
|
67 | - return 'name'; |
|
68 | - } elseif ($columnName === 'uid') { |
|
69 | - return 'owner'; |
|
70 | - } else { |
|
71 | - return parent::columnToProperty($columnName); |
|
72 | - } |
|
73 | - } |
|
57 | + /** |
|
58 | + * Transform a database columnname to a property |
|
59 | + * |
|
60 | + * @param string $columnName the name of the column |
|
61 | + * @return string the property name |
|
62 | + * @todo migrate existing database columns to the correct names |
|
63 | + * to be able to drop this direct mapping |
|
64 | + */ |
|
65 | + public function columnToProperty($columnName){ |
|
66 | + if ($columnName === 'category') { |
|
67 | + return 'name'; |
|
68 | + } elseif ($columnName === 'uid') { |
|
69 | + return 'owner'; |
|
70 | + } else { |
|
71 | + return parent::columnToProperty($columnName); |
|
72 | + } |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Transform a property to a database column name |
|
77 | - * |
|
78 | - * @param string $property the name of the property |
|
79 | - * @return string the column name |
|
80 | - */ |
|
81 | - public function propertyToColumn($property){ |
|
82 | - if ($property === 'name') { |
|
83 | - return 'category'; |
|
84 | - } elseif ($property === 'owner') { |
|
85 | - return 'uid'; |
|
86 | - } else { |
|
87 | - return parent::propertyToColumn($property); |
|
88 | - } |
|
89 | - } |
|
75 | + /** |
|
76 | + * Transform a property to a database column name |
|
77 | + * |
|
78 | + * @param string $property the name of the property |
|
79 | + * @return string the column name |
|
80 | + */ |
|
81 | + public function propertyToColumn($property){ |
|
82 | + if ($property === 'name') { |
|
83 | + return 'category'; |
|
84 | + } elseif ($property === 'owner') { |
|
85 | + return 'uid'; |
|
86 | + } else { |
|
87 | + return parent::propertyToColumn($property); |
|
88 | + } |
|
89 | + } |
|
90 | 90 | } |
@@ -32,127 +32,127 @@ |
||
32 | 32 | use Symfony\Component\Routing\Route as SymfonyRoute; |
33 | 33 | |
34 | 34 | class Route extends SymfonyRoute implements IRoute { |
35 | - /** |
|
36 | - * Specify the method when this route is to be used |
|
37 | - * |
|
38 | - * @param string $method HTTP method (uppercase) |
|
39 | - * @return \OC\Route\Route |
|
40 | - */ |
|
41 | - public function method($method) { |
|
42 | - $this->setMethods($method); |
|
43 | - return $this; |
|
44 | - } |
|
35 | + /** |
|
36 | + * Specify the method when this route is to be used |
|
37 | + * |
|
38 | + * @param string $method HTTP method (uppercase) |
|
39 | + * @return \OC\Route\Route |
|
40 | + */ |
|
41 | + public function method($method) { |
|
42 | + $this->setMethods($method); |
|
43 | + return $this; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Specify POST as the method to use with this route |
|
48 | - * @return \OC\Route\Route |
|
49 | - */ |
|
50 | - public function post() { |
|
51 | - $this->method('POST'); |
|
52 | - return $this; |
|
53 | - } |
|
46 | + /** |
|
47 | + * Specify POST as the method to use with this route |
|
48 | + * @return \OC\Route\Route |
|
49 | + */ |
|
50 | + public function post() { |
|
51 | + $this->method('POST'); |
|
52 | + return $this; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Specify GET as the method to use with this route |
|
57 | - * @return \OC\Route\Route |
|
58 | - */ |
|
59 | - public function get() { |
|
60 | - $this->method('GET'); |
|
61 | - return $this; |
|
62 | - } |
|
55 | + /** |
|
56 | + * Specify GET as the method to use with this route |
|
57 | + * @return \OC\Route\Route |
|
58 | + */ |
|
59 | + public function get() { |
|
60 | + $this->method('GET'); |
|
61 | + return $this; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Specify PUT as the method to use with this route |
|
66 | - * @return \OC\Route\Route |
|
67 | - */ |
|
68 | - public function put() { |
|
69 | - $this->method('PUT'); |
|
70 | - return $this; |
|
71 | - } |
|
64 | + /** |
|
65 | + * Specify PUT as the method to use with this route |
|
66 | + * @return \OC\Route\Route |
|
67 | + */ |
|
68 | + public function put() { |
|
69 | + $this->method('PUT'); |
|
70 | + return $this; |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * Specify DELETE as the method to use with this route |
|
75 | - * @return \OC\Route\Route |
|
76 | - */ |
|
77 | - public function delete() { |
|
78 | - $this->method('DELETE'); |
|
79 | - return $this; |
|
80 | - } |
|
73 | + /** |
|
74 | + * Specify DELETE as the method to use with this route |
|
75 | + * @return \OC\Route\Route |
|
76 | + */ |
|
77 | + public function delete() { |
|
78 | + $this->method('DELETE'); |
|
79 | + return $this; |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * Specify PATCH as the method to use with this route |
|
84 | - * @return \OC\Route\Route |
|
85 | - */ |
|
86 | - public function patch() { |
|
87 | - $this->method('PATCH'); |
|
88 | - return $this; |
|
89 | - } |
|
82 | + /** |
|
83 | + * Specify PATCH as the method to use with this route |
|
84 | + * @return \OC\Route\Route |
|
85 | + */ |
|
86 | + public function patch() { |
|
87 | + $this->method('PATCH'); |
|
88 | + return $this; |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * Defaults to use for this route |
|
93 | - * |
|
94 | - * @param array $defaults The defaults |
|
95 | - * @return \OC\Route\Route |
|
96 | - */ |
|
97 | - public function defaults($defaults) { |
|
98 | - $action = $this->getDefault('action'); |
|
99 | - $this->setDefaults($defaults); |
|
100 | - if (isset($defaults['action'])) { |
|
101 | - $action = $defaults['action']; |
|
102 | - } |
|
103 | - $this->action($action); |
|
104 | - return $this; |
|
105 | - } |
|
91 | + /** |
|
92 | + * Defaults to use for this route |
|
93 | + * |
|
94 | + * @param array $defaults The defaults |
|
95 | + * @return \OC\Route\Route |
|
96 | + */ |
|
97 | + public function defaults($defaults) { |
|
98 | + $action = $this->getDefault('action'); |
|
99 | + $this->setDefaults($defaults); |
|
100 | + if (isset($defaults['action'])) { |
|
101 | + $action = $defaults['action']; |
|
102 | + } |
|
103 | + $this->action($action); |
|
104 | + return $this; |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * Requirements for this route |
|
109 | - * |
|
110 | - * @param array $requirements The requirements |
|
111 | - * @return \OC\Route\Route |
|
112 | - */ |
|
113 | - public function requirements($requirements) { |
|
114 | - $method = $this->getMethods(); |
|
115 | - $this->setRequirements($requirements); |
|
116 | - if (isset($requirements['_method'])) { |
|
117 | - $method = $requirements['_method']; |
|
118 | - } |
|
119 | - if ($method) { |
|
120 | - $this->method($method); |
|
121 | - } |
|
122 | - return $this; |
|
123 | - } |
|
107 | + /** |
|
108 | + * Requirements for this route |
|
109 | + * |
|
110 | + * @param array $requirements The requirements |
|
111 | + * @return \OC\Route\Route |
|
112 | + */ |
|
113 | + public function requirements($requirements) { |
|
114 | + $method = $this->getMethods(); |
|
115 | + $this->setRequirements($requirements); |
|
116 | + if (isset($requirements['_method'])) { |
|
117 | + $method = $requirements['_method']; |
|
118 | + } |
|
119 | + if ($method) { |
|
120 | + $this->method($method); |
|
121 | + } |
|
122 | + return $this; |
|
123 | + } |
|
124 | 124 | |
125 | - /** |
|
126 | - * The action to execute when this route matches |
|
127 | - * |
|
128 | - * @param string|callable $class the class or a callable |
|
129 | - * @param string $function the function to use with the class |
|
130 | - * @return \OC\Route\Route |
|
131 | - * |
|
132 | - * This function is called with $class set to a callable or |
|
133 | - * to the class with $function |
|
134 | - */ |
|
135 | - public function action($class, $function = null) { |
|
136 | - $action = array($class, $function); |
|
137 | - if (is_null($function)) { |
|
138 | - $action = $class; |
|
139 | - } |
|
140 | - $this->setDefault('action', $action); |
|
141 | - return $this; |
|
142 | - } |
|
125 | + /** |
|
126 | + * The action to execute when this route matches |
|
127 | + * |
|
128 | + * @param string|callable $class the class or a callable |
|
129 | + * @param string $function the function to use with the class |
|
130 | + * @return \OC\Route\Route |
|
131 | + * |
|
132 | + * This function is called with $class set to a callable or |
|
133 | + * to the class with $function |
|
134 | + */ |
|
135 | + public function action($class, $function = null) { |
|
136 | + $action = array($class, $function); |
|
137 | + if (is_null($function)) { |
|
138 | + $action = $class; |
|
139 | + } |
|
140 | + $this->setDefault('action', $action); |
|
141 | + return $this; |
|
142 | + } |
|
143 | 143 | |
144 | - /** |
|
145 | - * The action to execute when this route matches, includes a file like |
|
146 | - * it is called directly |
|
147 | - * @param string $file |
|
148 | - * @return void |
|
149 | - */ |
|
150 | - public function actionInclude($file) { |
|
151 | - $function = create_function('$param', |
|
152 | - 'unset($param["_route"]);' |
|
153 | - .'$_GET=array_merge($_GET, $param);' |
|
154 | - .'unset($param);' |
|
155 | - .'require_once "'.$file.'";'); |
|
156 | - $this->action($function); |
|
157 | - } |
|
144 | + /** |
|
145 | + * The action to execute when this route matches, includes a file like |
|
146 | + * it is called directly |
|
147 | + * @param string $file |
|
148 | + * @return void |
|
149 | + */ |
|
150 | + public function actionInclude($file) { |
|
151 | + $function = create_function('$param', |
|
152 | + 'unset($param["_route"]);' |
|
153 | + .'$_GET=array_merge($_GET, $param);' |
|
154 | + .'unset($param);' |
|
155 | + .'require_once "'.$file.'";'); |
|
156 | + $this->action($function); |
|
157 | + } |
|
158 | 158 | } |
@@ -28,38 +28,38 @@ |
||
28 | 28 | use OCP\ILogger; |
29 | 29 | |
30 | 30 | class CachingRouter extends Router { |
31 | - /** |
|
32 | - * @var \OCP\ICache |
|
33 | - */ |
|
34 | - protected $cache; |
|
31 | + /** |
|
32 | + * @var \OCP\ICache |
|
33 | + */ |
|
34 | + protected $cache; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param \OCP\ICache $cache |
|
38 | - * @param ILogger $logger |
|
39 | - */ |
|
40 | - public function __construct($cache, ILogger $logger) { |
|
41 | - $this->cache = $cache; |
|
42 | - parent::__construct($logger); |
|
43 | - } |
|
36 | + /** |
|
37 | + * @param \OCP\ICache $cache |
|
38 | + * @param ILogger $logger |
|
39 | + */ |
|
40 | + public function __construct($cache, ILogger $logger) { |
|
41 | + $this->cache = $cache; |
|
42 | + parent::__construct($logger); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Generate url based on $name and $parameters |
|
47 | - * |
|
48 | - * @param string $name Name of the route to use. |
|
49 | - * @param array $parameters Parameters for the route |
|
50 | - * @param bool $absolute |
|
51 | - * @return string |
|
52 | - */ |
|
53 | - public function generate($name, $parameters = array(), $absolute = false) { |
|
54 | - asort($parameters); |
|
55 | - $key = $this->context->getHost() . '#' . $this->context->getBaseUrl() . $name . sha1(json_encode($parameters)) . intval($absolute); |
|
56 | - $cachedKey = $this->cache->get($key); |
|
57 | - if ($cachedKey) { |
|
58 | - return $cachedKey; |
|
59 | - } else { |
|
60 | - $url = parent::generate($name, $parameters, $absolute); |
|
61 | - $this->cache->set($key, $url, 3600); |
|
62 | - return $url; |
|
63 | - } |
|
64 | - } |
|
45 | + /** |
|
46 | + * Generate url based on $name and $parameters |
|
47 | + * |
|
48 | + * @param string $name Name of the route to use. |
|
49 | + * @param array $parameters Parameters for the route |
|
50 | + * @param bool $absolute |
|
51 | + * @return string |
|
52 | + */ |
|
53 | + public function generate($name, $parameters = array(), $absolute = false) { |
|
54 | + asort($parameters); |
|
55 | + $key = $this->context->getHost() . '#' . $this->context->getBaseUrl() . $name . sha1(json_encode($parameters)) . intval($absolute); |
|
56 | + $cachedKey = $this->cache->get($key); |
|
57 | + if ($cachedKey) { |
|
58 | + return $cachedKey; |
|
59 | + } else { |
|
60 | + $url = parent::generate($name, $parameters, $absolute); |
|
61 | + $this->cache->set($key, $url, 3600); |
|
62 | + return $url; |
|
63 | + } |
|
64 | + } |
|
65 | 65 | } |
@@ -45,339 +45,339 @@ |
||
45 | 45 | use Symfony\Component\Routing\Exception\ResourceNotFoundException; |
46 | 46 | |
47 | 47 | class Router implements IRouter { |
48 | - /** @var RouteCollection[] */ |
|
49 | - protected $collections = []; |
|
50 | - /** @var null|RouteCollection */ |
|
51 | - protected $collection = null; |
|
52 | - /** @var null|string */ |
|
53 | - protected $collectionName = null; |
|
54 | - /** @var null|RouteCollection */ |
|
55 | - protected $root = null; |
|
56 | - /** @var null|UrlGenerator */ |
|
57 | - protected $generator = null; |
|
58 | - /** @var string[] */ |
|
59 | - protected $routingFiles; |
|
60 | - /** @var bool */ |
|
61 | - protected $loaded = false; |
|
62 | - /** @var array */ |
|
63 | - protected $loadedApps = []; |
|
64 | - /** @var ILogger */ |
|
65 | - protected $logger; |
|
66 | - /** @var RequestContext */ |
|
67 | - protected $context; |
|
48 | + /** @var RouteCollection[] */ |
|
49 | + protected $collections = []; |
|
50 | + /** @var null|RouteCollection */ |
|
51 | + protected $collection = null; |
|
52 | + /** @var null|string */ |
|
53 | + protected $collectionName = null; |
|
54 | + /** @var null|RouteCollection */ |
|
55 | + protected $root = null; |
|
56 | + /** @var null|UrlGenerator */ |
|
57 | + protected $generator = null; |
|
58 | + /** @var string[] */ |
|
59 | + protected $routingFiles; |
|
60 | + /** @var bool */ |
|
61 | + protected $loaded = false; |
|
62 | + /** @var array */ |
|
63 | + protected $loadedApps = []; |
|
64 | + /** @var ILogger */ |
|
65 | + protected $logger; |
|
66 | + /** @var RequestContext */ |
|
67 | + protected $context; |
|
68 | 68 | |
69 | - /** |
|
70 | - * @param ILogger $logger |
|
71 | - */ |
|
72 | - public function __construct(ILogger $logger) { |
|
73 | - $this->logger = $logger; |
|
74 | - $baseUrl = \OC::$WEBROOT; |
|
75 | - if(!(\OC::$server->getConfig()->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true')) { |
|
76 | - $baseUrl = \OC::$server->getURLGenerator()->linkTo('', 'index.php'); |
|
77 | - } |
|
78 | - if (!\OC::$CLI) { |
|
79 | - $method = $_SERVER['REQUEST_METHOD']; |
|
80 | - } else { |
|
81 | - $method = 'GET'; |
|
82 | - } |
|
83 | - $request = \OC::$server->getRequest(); |
|
84 | - $host = $request->getServerHost(); |
|
85 | - $schema = $request->getServerProtocol(); |
|
86 | - $this->context = new RequestContext($baseUrl, $method, $host, $schema); |
|
87 | - // TODO cache |
|
88 | - $this->root = $this->getCollection('root'); |
|
89 | - } |
|
69 | + /** |
|
70 | + * @param ILogger $logger |
|
71 | + */ |
|
72 | + public function __construct(ILogger $logger) { |
|
73 | + $this->logger = $logger; |
|
74 | + $baseUrl = \OC::$WEBROOT; |
|
75 | + if(!(\OC::$server->getConfig()->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true')) { |
|
76 | + $baseUrl = \OC::$server->getURLGenerator()->linkTo('', 'index.php'); |
|
77 | + } |
|
78 | + if (!\OC::$CLI) { |
|
79 | + $method = $_SERVER['REQUEST_METHOD']; |
|
80 | + } else { |
|
81 | + $method = 'GET'; |
|
82 | + } |
|
83 | + $request = \OC::$server->getRequest(); |
|
84 | + $host = $request->getServerHost(); |
|
85 | + $schema = $request->getServerProtocol(); |
|
86 | + $this->context = new RequestContext($baseUrl, $method, $host, $schema); |
|
87 | + // TODO cache |
|
88 | + $this->root = $this->getCollection('root'); |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * Get the files to load the routes from |
|
93 | - * |
|
94 | - * @return string[] |
|
95 | - */ |
|
96 | - public function getRoutingFiles() { |
|
97 | - if (!isset($this->routingFiles)) { |
|
98 | - $this->routingFiles = []; |
|
99 | - foreach (\OC_APP::getEnabledApps() as $app) { |
|
100 | - $appPath = \OC_App::getAppPath($app); |
|
101 | - if($appPath !== false) { |
|
102 | - $file = $appPath . '/appinfo/routes.php'; |
|
103 | - if (file_exists($file)) { |
|
104 | - $this->routingFiles[$app] = $file; |
|
105 | - } |
|
106 | - } |
|
107 | - } |
|
108 | - } |
|
109 | - return $this->routingFiles; |
|
110 | - } |
|
91 | + /** |
|
92 | + * Get the files to load the routes from |
|
93 | + * |
|
94 | + * @return string[] |
|
95 | + */ |
|
96 | + public function getRoutingFiles() { |
|
97 | + if (!isset($this->routingFiles)) { |
|
98 | + $this->routingFiles = []; |
|
99 | + foreach (\OC_APP::getEnabledApps() as $app) { |
|
100 | + $appPath = \OC_App::getAppPath($app); |
|
101 | + if($appPath !== false) { |
|
102 | + $file = $appPath . '/appinfo/routes.php'; |
|
103 | + if (file_exists($file)) { |
|
104 | + $this->routingFiles[$app] = $file; |
|
105 | + } |
|
106 | + } |
|
107 | + } |
|
108 | + } |
|
109 | + return $this->routingFiles; |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * Loads the routes |
|
114 | - * |
|
115 | - * @param null|string $app |
|
116 | - */ |
|
117 | - public function loadRoutes($app = null) { |
|
118 | - if(is_string($app)) { |
|
119 | - $app = \OC_App::cleanAppId($app); |
|
120 | - } |
|
112 | + /** |
|
113 | + * Loads the routes |
|
114 | + * |
|
115 | + * @param null|string $app |
|
116 | + */ |
|
117 | + public function loadRoutes($app = null) { |
|
118 | + if(is_string($app)) { |
|
119 | + $app = \OC_App::cleanAppId($app); |
|
120 | + } |
|
121 | 121 | |
122 | - $requestedApp = $app; |
|
123 | - if ($this->loaded) { |
|
124 | - return; |
|
125 | - } |
|
126 | - if (is_null($app)) { |
|
127 | - $this->loaded = true; |
|
128 | - $routingFiles = $this->getRoutingFiles(); |
|
129 | - } else { |
|
130 | - if (isset($this->loadedApps[$app])) { |
|
131 | - return; |
|
132 | - } |
|
133 | - $file = \OC_App::getAppPath($app) . '/appinfo/routes.php'; |
|
134 | - if ($file !== false && file_exists($file)) { |
|
135 | - $routingFiles = [$app => $file]; |
|
136 | - } else { |
|
137 | - $routingFiles = []; |
|
138 | - } |
|
139 | - } |
|
140 | - \OC::$server->getEventLogger()->start('loadroutes' . $requestedApp, 'Loading Routes'); |
|
141 | - foreach ($routingFiles as $app => $file) { |
|
142 | - if (!isset($this->loadedApps[$app])) { |
|
143 | - if (!\OC_App::isAppLoaded($app)) { |
|
144 | - // app MUST be loaded before app routes |
|
145 | - // try again next time loadRoutes() is called |
|
146 | - $this->loaded = false; |
|
147 | - continue; |
|
148 | - } |
|
149 | - $this->loadedApps[$app] = true; |
|
150 | - $this->useCollection($app); |
|
151 | - $this->requireRouteFile($file, $app); |
|
152 | - $collection = $this->getCollection($app); |
|
153 | - $collection->addPrefix('/apps/' . $app); |
|
154 | - $this->root->addCollection($collection); |
|
122 | + $requestedApp = $app; |
|
123 | + if ($this->loaded) { |
|
124 | + return; |
|
125 | + } |
|
126 | + if (is_null($app)) { |
|
127 | + $this->loaded = true; |
|
128 | + $routingFiles = $this->getRoutingFiles(); |
|
129 | + } else { |
|
130 | + if (isset($this->loadedApps[$app])) { |
|
131 | + return; |
|
132 | + } |
|
133 | + $file = \OC_App::getAppPath($app) . '/appinfo/routes.php'; |
|
134 | + if ($file !== false && file_exists($file)) { |
|
135 | + $routingFiles = [$app => $file]; |
|
136 | + } else { |
|
137 | + $routingFiles = []; |
|
138 | + } |
|
139 | + } |
|
140 | + \OC::$server->getEventLogger()->start('loadroutes' . $requestedApp, 'Loading Routes'); |
|
141 | + foreach ($routingFiles as $app => $file) { |
|
142 | + if (!isset($this->loadedApps[$app])) { |
|
143 | + if (!\OC_App::isAppLoaded($app)) { |
|
144 | + // app MUST be loaded before app routes |
|
145 | + // try again next time loadRoutes() is called |
|
146 | + $this->loaded = false; |
|
147 | + continue; |
|
148 | + } |
|
149 | + $this->loadedApps[$app] = true; |
|
150 | + $this->useCollection($app); |
|
151 | + $this->requireRouteFile($file, $app); |
|
152 | + $collection = $this->getCollection($app); |
|
153 | + $collection->addPrefix('/apps/' . $app); |
|
154 | + $this->root->addCollection($collection); |
|
155 | 155 | |
156 | - // Also add the OCS collection |
|
157 | - $collection = $this->getCollection($app.'.ocs'); |
|
158 | - $collection->addPrefix('/ocsapp'); |
|
159 | - $this->root->addCollection($collection); |
|
160 | - } |
|
161 | - } |
|
162 | - if (!isset($this->loadedApps['core'])) { |
|
163 | - $this->loadedApps['core'] = true; |
|
164 | - $this->useCollection('root'); |
|
165 | - require_once __DIR__ . '/../../../settings/routes.php'; |
|
166 | - require_once __DIR__ . '/../../../core/routes.php'; |
|
156 | + // Also add the OCS collection |
|
157 | + $collection = $this->getCollection($app.'.ocs'); |
|
158 | + $collection->addPrefix('/ocsapp'); |
|
159 | + $this->root->addCollection($collection); |
|
160 | + } |
|
161 | + } |
|
162 | + if (!isset($this->loadedApps['core'])) { |
|
163 | + $this->loadedApps['core'] = true; |
|
164 | + $this->useCollection('root'); |
|
165 | + require_once __DIR__ . '/../../../settings/routes.php'; |
|
166 | + require_once __DIR__ . '/../../../core/routes.php'; |
|
167 | 167 | |
168 | - // Also add the OCS collection |
|
169 | - $collection = $this->getCollection('root.ocs'); |
|
170 | - $collection->addPrefix('/ocsapp'); |
|
171 | - $this->root->addCollection($collection); |
|
172 | - } |
|
173 | - if ($this->loaded) { |
|
174 | - // include ocs routes, must be loaded last for /ocs prefix |
|
175 | - require_once __DIR__ . '/../../../ocs/routes.php'; |
|
176 | - $collection = $this->getCollection('ocs'); |
|
177 | - $collection->addPrefix('/ocs'); |
|
178 | - $this->root->addCollection($collection); |
|
179 | - } |
|
180 | - \OC::$server->getEventLogger()->end('loadroutes' . $requestedApp); |
|
181 | - } |
|
168 | + // Also add the OCS collection |
|
169 | + $collection = $this->getCollection('root.ocs'); |
|
170 | + $collection->addPrefix('/ocsapp'); |
|
171 | + $this->root->addCollection($collection); |
|
172 | + } |
|
173 | + if ($this->loaded) { |
|
174 | + // include ocs routes, must be loaded last for /ocs prefix |
|
175 | + require_once __DIR__ . '/../../../ocs/routes.php'; |
|
176 | + $collection = $this->getCollection('ocs'); |
|
177 | + $collection->addPrefix('/ocs'); |
|
178 | + $this->root->addCollection($collection); |
|
179 | + } |
|
180 | + \OC::$server->getEventLogger()->end('loadroutes' . $requestedApp); |
|
181 | + } |
|
182 | 182 | |
183 | - /** |
|
184 | - * @return string |
|
185 | - * @deprecated |
|
186 | - */ |
|
187 | - public function getCacheKey() { |
|
188 | - return ''; |
|
189 | - } |
|
183 | + /** |
|
184 | + * @return string |
|
185 | + * @deprecated |
|
186 | + */ |
|
187 | + public function getCacheKey() { |
|
188 | + return ''; |
|
189 | + } |
|
190 | 190 | |
191 | - /** |
|
192 | - * @param string $name |
|
193 | - * @return \Symfony\Component\Routing\RouteCollection |
|
194 | - */ |
|
195 | - protected function getCollection($name) { |
|
196 | - if (!isset($this->collections[$name])) { |
|
197 | - $this->collections[$name] = new RouteCollection(); |
|
198 | - } |
|
199 | - return $this->collections[$name]; |
|
200 | - } |
|
191 | + /** |
|
192 | + * @param string $name |
|
193 | + * @return \Symfony\Component\Routing\RouteCollection |
|
194 | + */ |
|
195 | + protected function getCollection($name) { |
|
196 | + if (!isset($this->collections[$name])) { |
|
197 | + $this->collections[$name] = new RouteCollection(); |
|
198 | + } |
|
199 | + return $this->collections[$name]; |
|
200 | + } |
|
201 | 201 | |
202 | - /** |
|
203 | - * Sets the collection to use for adding routes |
|
204 | - * |
|
205 | - * @param string $name Name of the collection to use. |
|
206 | - * @return void |
|
207 | - */ |
|
208 | - public function useCollection($name) { |
|
209 | - $this->collection = $this->getCollection($name); |
|
210 | - $this->collectionName = $name; |
|
211 | - } |
|
202 | + /** |
|
203 | + * Sets the collection to use for adding routes |
|
204 | + * |
|
205 | + * @param string $name Name of the collection to use. |
|
206 | + * @return void |
|
207 | + */ |
|
208 | + public function useCollection($name) { |
|
209 | + $this->collection = $this->getCollection($name); |
|
210 | + $this->collectionName = $name; |
|
211 | + } |
|
212 | 212 | |
213 | - /** |
|
214 | - * returns the current collection name in use for adding routes |
|
215 | - * |
|
216 | - * @return string the collection name |
|
217 | - */ |
|
218 | - public function getCurrentCollection() { |
|
219 | - return $this->collectionName; |
|
220 | - } |
|
213 | + /** |
|
214 | + * returns the current collection name in use for adding routes |
|
215 | + * |
|
216 | + * @return string the collection name |
|
217 | + */ |
|
218 | + public function getCurrentCollection() { |
|
219 | + return $this->collectionName; |
|
220 | + } |
|
221 | 221 | |
222 | 222 | |
223 | - /** |
|
224 | - * Create a \OC\Route\Route. |
|
225 | - * |
|
226 | - * @param string $name Name of the route to create. |
|
227 | - * @param string $pattern The pattern to match |
|
228 | - * @param array $defaults An array of default parameter values |
|
229 | - * @param array $requirements An array of requirements for parameters (regexes) |
|
230 | - * @return \OC\Route\Route |
|
231 | - */ |
|
232 | - public function create($name, |
|
233 | - $pattern, |
|
234 | - array $defaults = [], |
|
235 | - array $requirements = []) { |
|
236 | - $route = new Route($pattern, $defaults, $requirements); |
|
237 | - $this->collection->add($name, $route); |
|
238 | - return $route; |
|
239 | - } |
|
223 | + /** |
|
224 | + * Create a \OC\Route\Route. |
|
225 | + * |
|
226 | + * @param string $name Name of the route to create. |
|
227 | + * @param string $pattern The pattern to match |
|
228 | + * @param array $defaults An array of default parameter values |
|
229 | + * @param array $requirements An array of requirements for parameters (regexes) |
|
230 | + * @return \OC\Route\Route |
|
231 | + */ |
|
232 | + public function create($name, |
|
233 | + $pattern, |
|
234 | + array $defaults = [], |
|
235 | + array $requirements = []) { |
|
236 | + $route = new Route($pattern, $defaults, $requirements); |
|
237 | + $this->collection->add($name, $route); |
|
238 | + return $route; |
|
239 | + } |
|
240 | 240 | |
241 | - /** |
|
242 | - * Find the route matching $url |
|
243 | - * |
|
244 | - * @param string $url The url to find |
|
245 | - * @throws \Exception |
|
246 | - * @return void |
|
247 | - */ |
|
248 | - public function match($url) { |
|
249 | - if (substr($url, 0, 6) === '/apps/') { |
|
250 | - // empty string / 'apps' / $app / rest of the route |
|
251 | - list(, , $app,) = explode('/', $url, 4); |
|
241 | + /** |
|
242 | + * Find the route matching $url |
|
243 | + * |
|
244 | + * @param string $url The url to find |
|
245 | + * @throws \Exception |
|
246 | + * @return void |
|
247 | + */ |
|
248 | + public function match($url) { |
|
249 | + if (substr($url, 0, 6) === '/apps/') { |
|
250 | + // empty string / 'apps' / $app / rest of the route |
|
251 | + list(, , $app,) = explode('/', $url, 4); |
|
252 | 252 | |
253 | - $app = \OC_App::cleanAppId($app); |
|
254 | - \OC::$REQUESTEDAPP = $app; |
|
255 | - $this->loadRoutes($app); |
|
256 | - } else if (substr($url, 0, 13) === '/ocsapp/apps/') { |
|
257 | - // empty string / 'ocsapp' / 'apps' / $app / rest of the route |
|
258 | - list(, , , $app,) = explode('/', $url, 5); |
|
253 | + $app = \OC_App::cleanAppId($app); |
|
254 | + \OC::$REQUESTEDAPP = $app; |
|
255 | + $this->loadRoutes($app); |
|
256 | + } else if (substr($url, 0, 13) === '/ocsapp/apps/') { |
|
257 | + // empty string / 'ocsapp' / 'apps' / $app / rest of the route |
|
258 | + list(, , , $app,) = explode('/', $url, 5); |
|
259 | 259 | |
260 | - $app = \OC_App::cleanAppId($app); |
|
261 | - \OC::$REQUESTEDAPP = $app; |
|
262 | - $this->loadRoutes($app); |
|
263 | - } else if (substr($url, 0, 6) === '/core/' or substr($url, 0, 10) === '/settings/') { |
|
264 | - \OC::$REQUESTEDAPP = $url; |
|
265 | - if (!\OC::$server->getConfig()->getSystemValue('maintenance', false) && !Util::needUpgrade()) { |
|
266 | - \OC_App::loadApps(); |
|
267 | - } |
|
268 | - $this->loadRoutes('core'); |
|
269 | - } else { |
|
270 | - $this->loadRoutes(); |
|
271 | - } |
|
260 | + $app = \OC_App::cleanAppId($app); |
|
261 | + \OC::$REQUESTEDAPP = $app; |
|
262 | + $this->loadRoutes($app); |
|
263 | + } else if (substr($url, 0, 6) === '/core/' or substr($url, 0, 10) === '/settings/') { |
|
264 | + \OC::$REQUESTEDAPP = $url; |
|
265 | + if (!\OC::$server->getConfig()->getSystemValue('maintenance', false) && !Util::needUpgrade()) { |
|
266 | + \OC_App::loadApps(); |
|
267 | + } |
|
268 | + $this->loadRoutes('core'); |
|
269 | + } else { |
|
270 | + $this->loadRoutes(); |
|
271 | + } |
|
272 | 272 | |
273 | - $matcher = new UrlMatcher($this->root, $this->context); |
|
274 | - try { |
|
275 | - $parameters = $matcher->match($url); |
|
276 | - } catch (ResourceNotFoundException $e) { |
|
277 | - if (substr($url, -1) !== '/') { |
|
278 | - // We allow links to apps/files? for backwards compatibility reasons |
|
279 | - // However, since Symfony does not allow empty route names, the route |
|
280 | - // we need to match is '/', so we need to append the '/' here. |
|
281 | - try { |
|
282 | - $parameters = $matcher->match($url . '/'); |
|
283 | - } catch (ResourceNotFoundException $newException) { |
|
284 | - // If we still didn't match a route, we throw the original exception |
|
285 | - throw $e; |
|
286 | - } |
|
287 | - } else { |
|
288 | - throw $e; |
|
289 | - } |
|
290 | - } |
|
273 | + $matcher = new UrlMatcher($this->root, $this->context); |
|
274 | + try { |
|
275 | + $parameters = $matcher->match($url); |
|
276 | + } catch (ResourceNotFoundException $e) { |
|
277 | + if (substr($url, -1) !== '/') { |
|
278 | + // We allow links to apps/files? for backwards compatibility reasons |
|
279 | + // However, since Symfony does not allow empty route names, the route |
|
280 | + // we need to match is '/', so we need to append the '/' here. |
|
281 | + try { |
|
282 | + $parameters = $matcher->match($url . '/'); |
|
283 | + } catch (ResourceNotFoundException $newException) { |
|
284 | + // If we still didn't match a route, we throw the original exception |
|
285 | + throw $e; |
|
286 | + } |
|
287 | + } else { |
|
288 | + throw $e; |
|
289 | + } |
|
290 | + } |
|
291 | 291 | |
292 | - \OC::$server->getEventLogger()->start('run_route', 'Run route'); |
|
293 | - if (isset($parameters['action'])) { |
|
294 | - $action = $parameters['action']; |
|
295 | - if (!is_callable($action)) { |
|
296 | - throw new \Exception('not a callable action'); |
|
297 | - } |
|
298 | - unset($parameters['action']); |
|
299 | - call_user_func($action, $parameters); |
|
300 | - } elseif (isset($parameters['file'])) { |
|
301 | - include $parameters['file']; |
|
302 | - } else { |
|
303 | - throw new \Exception('no action available'); |
|
304 | - } |
|
305 | - \OC::$server->getEventLogger()->end('run_route'); |
|
306 | - } |
|
292 | + \OC::$server->getEventLogger()->start('run_route', 'Run route'); |
|
293 | + if (isset($parameters['action'])) { |
|
294 | + $action = $parameters['action']; |
|
295 | + if (!is_callable($action)) { |
|
296 | + throw new \Exception('not a callable action'); |
|
297 | + } |
|
298 | + unset($parameters['action']); |
|
299 | + call_user_func($action, $parameters); |
|
300 | + } elseif (isset($parameters['file'])) { |
|
301 | + include $parameters['file']; |
|
302 | + } else { |
|
303 | + throw new \Exception('no action available'); |
|
304 | + } |
|
305 | + \OC::$server->getEventLogger()->end('run_route'); |
|
306 | + } |
|
307 | 307 | |
308 | - /** |
|
309 | - * Get the url generator |
|
310 | - * |
|
311 | - * @return \Symfony\Component\Routing\Generator\UrlGenerator |
|
312 | - * |
|
313 | - */ |
|
314 | - public function getGenerator() { |
|
315 | - if (null !== $this->generator) { |
|
316 | - return $this->generator; |
|
317 | - } |
|
308 | + /** |
|
309 | + * Get the url generator |
|
310 | + * |
|
311 | + * @return \Symfony\Component\Routing\Generator\UrlGenerator |
|
312 | + * |
|
313 | + */ |
|
314 | + public function getGenerator() { |
|
315 | + if (null !== $this->generator) { |
|
316 | + return $this->generator; |
|
317 | + } |
|
318 | 318 | |
319 | - return $this->generator = new UrlGenerator($this->root, $this->context); |
|
320 | - } |
|
319 | + return $this->generator = new UrlGenerator($this->root, $this->context); |
|
320 | + } |
|
321 | 321 | |
322 | - /** |
|
323 | - * Generate url based on $name and $parameters |
|
324 | - * |
|
325 | - * @param string $name Name of the route to use. |
|
326 | - * @param array $parameters Parameters for the route |
|
327 | - * @param bool $absolute |
|
328 | - * @return string |
|
329 | - */ |
|
330 | - public function generate($name, |
|
331 | - $parameters = [], |
|
332 | - $absolute = false) { |
|
333 | - $this->loadRoutes(); |
|
334 | - try { |
|
335 | - $referenceType = UrlGenerator::ABSOLUTE_URL; |
|
336 | - if ($absolute === false) { |
|
337 | - $referenceType = UrlGenerator::ABSOLUTE_PATH; |
|
338 | - } |
|
339 | - return $this->getGenerator()->generate($name, $parameters, $referenceType); |
|
340 | - } catch (RouteNotFoundException $e) { |
|
341 | - $this->logger->logException($e); |
|
342 | - return ''; |
|
343 | - } |
|
344 | - } |
|
322 | + /** |
|
323 | + * Generate url based on $name and $parameters |
|
324 | + * |
|
325 | + * @param string $name Name of the route to use. |
|
326 | + * @param array $parameters Parameters for the route |
|
327 | + * @param bool $absolute |
|
328 | + * @return string |
|
329 | + */ |
|
330 | + public function generate($name, |
|
331 | + $parameters = [], |
|
332 | + $absolute = false) { |
|
333 | + $this->loadRoutes(); |
|
334 | + try { |
|
335 | + $referenceType = UrlGenerator::ABSOLUTE_URL; |
|
336 | + if ($absolute === false) { |
|
337 | + $referenceType = UrlGenerator::ABSOLUTE_PATH; |
|
338 | + } |
|
339 | + return $this->getGenerator()->generate($name, $parameters, $referenceType); |
|
340 | + } catch (RouteNotFoundException $e) { |
|
341 | + $this->logger->logException($e); |
|
342 | + return ''; |
|
343 | + } |
|
344 | + } |
|
345 | 345 | |
346 | - /** |
|
347 | - * To isolate the variable scope used inside the $file it is required in it's own method |
|
348 | - * |
|
349 | - * @param string $file the route file location to include |
|
350 | - * @param string $appName |
|
351 | - */ |
|
352 | - private function requireRouteFile($file, $appName) { |
|
353 | - $this->setupRoutes(include_once $file, $appName); |
|
354 | - } |
|
346 | + /** |
|
347 | + * To isolate the variable scope used inside the $file it is required in it's own method |
|
348 | + * |
|
349 | + * @param string $file the route file location to include |
|
350 | + * @param string $appName |
|
351 | + */ |
|
352 | + private function requireRouteFile($file, $appName) { |
|
353 | + $this->setupRoutes(include_once $file, $appName); |
|
354 | + } |
|
355 | 355 | |
356 | 356 | |
357 | - /** |
|
358 | - * If a routes.php file returns an array, try to set up the application and |
|
359 | - * register the routes for the app. The application class will be chosen by |
|
360 | - * camelcasing the appname, e.g.: my_app will be turned into |
|
361 | - * \OCA\MyApp\AppInfo\Application. If that class does not exist, a default |
|
362 | - * App will be intialized. This makes it optional to ship an |
|
363 | - * appinfo/application.php by using the built in query resolver |
|
364 | - * |
|
365 | - * @param array $routes the application routes |
|
366 | - * @param string $appName the name of the app. |
|
367 | - */ |
|
368 | - private function setupRoutes($routes, $appName) { |
|
369 | - if (is_array($routes)) { |
|
370 | - $appNameSpace = App::buildAppNamespace($appName); |
|
357 | + /** |
|
358 | + * If a routes.php file returns an array, try to set up the application and |
|
359 | + * register the routes for the app. The application class will be chosen by |
|
360 | + * camelcasing the appname, e.g.: my_app will be turned into |
|
361 | + * \OCA\MyApp\AppInfo\Application. If that class does not exist, a default |
|
362 | + * App will be intialized. This makes it optional to ship an |
|
363 | + * appinfo/application.php by using the built in query resolver |
|
364 | + * |
|
365 | + * @param array $routes the application routes |
|
366 | + * @param string $appName the name of the app. |
|
367 | + */ |
|
368 | + private function setupRoutes($routes, $appName) { |
|
369 | + if (is_array($routes)) { |
|
370 | + $appNameSpace = App::buildAppNamespace($appName); |
|
371 | 371 | |
372 | - $applicationClassName = $appNameSpace . '\\AppInfo\\Application'; |
|
372 | + $applicationClassName = $appNameSpace . '\\AppInfo\\Application'; |
|
373 | 373 | |
374 | - if (class_exists($applicationClassName)) { |
|
375 | - $application = new $applicationClassName(); |
|
376 | - } else { |
|
377 | - $application = new App($appName); |
|
378 | - } |
|
374 | + if (class_exists($applicationClassName)) { |
|
375 | + $application = new $applicationClassName(); |
|
376 | + } else { |
|
377 | + $application = new App($appName); |
|
378 | + } |
|
379 | 379 | |
380 | - $application->registerRoutes($this, $routes); |
|
381 | - } |
|
382 | - } |
|
380 | + $application->registerRoutes($this, $routes); |
|
381 | + } |
|
382 | + } |
|
383 | 383 | } |
@@ -40,53 +40,53 @@ |
||
40 | 40 | |
41 | 41 | class TagManager implements \OCP\ITagManager { |
42 | 42 | |
43 | - /** |
|
44 | - * User session |
|
45 | - * |
|
46 | - * @var \OCP\IUserSession |
|
47 | - */ |
|
48 | - private $userSession; |
|
43 | + /** |
|
44 | + * User session |
|
45 | + * |
|
46 | + * @var \OCP\IUserSession |
|
47 | + */ |
|
48 | + private $userSession; |
|
49 | 49 | |
50 | - /** |
|
51 | - * TagMapper |
|
52 | - * |
|
53 | - * @var TagMapper |
|
54 | - */ |
|
55 | - private $mapper; |
|
50 | + /** |
|
51 | + * TagMapper |
|
52 | + * |
|
53 | + * @var TagMapper |
|
54 | + */ |
|
55 | + private $mapper; |
|
56 | 56 | |
57 | - /** |
|
58 | - * Constructor. |
|
59 | - * |
|
60 | - * @param TagMapper $mapper Instance of the TagMapper abstraction layer. |
|
61 | - * @param \OCP\IUserSession $userSession the user session |
|
62 | - */ |
|
63 | - public function __construct(TagMapper $mapper, \OCP\IUserSession $userSession) { |
|
64 | - $this->mapper = $mapper; |
|
65 | - $this->userSession = $userSession; |
|
57 | + /** |
|
58 | + * Constructor. |
|
59 | + * |
|
60 | + * @param TagMapper $mapper Instance of the TagMapper abstraction layer. |
|
61 | + * @param \OCP\IUserSession $userSession the user session |
|
62 | + */ |
|
63 | + public function __construct(TagMapper $mapper, \OCP\IUserSession $userSession) { |
|
64 | + $this->mapper = $mapper; |
|
65 | + $this->userSession = $userSession; |
|
66 | 66 | |
67 | - } |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * Create a new \OCP\ITags instance and load tags from db. |
|
71 | - * |
|
72 | - * @see \OCP\ITags |
|
73 | - * @param string $type The type identifier e.g. 'contact' or 'event'. |
|
74 | - * @param array $defaultTags An array of default tags to be used if none are stored. |
|
75 | - * @param boolean $includeShared Whether to include tags for items shared with this user by others. |
|
76 | - * @param string $userId user for which to retrieve the tags, defaults to the currently |
|
77 | - * logged in user |
|
78 | - * @return \OCP\ITags |
|
79 | - */ |
|
80 | - public function load($type, $defaultTags = array(), $includeShared = false, $userId = null) { |
|
81 | - if (is_null($userId)) { |
|
82 | - $user = $this->userSession->getUser(); |
|
83 | - if ($user === null) { |
|
84 | - // nothing we can do without a user |
|
85 | - return null; |
|
86 | - } |
|
87 | - $userId = $this->userSession->getUser()->getUId(); |
|
88 | - } |
|
89 | - return new Tags($this->mapper, $userId, $type, $defaultTags, $includeShared); |
|
90 | - } |
|
69 | + /** |
|
70 | + * Create a new \OCP\ITags instance and load tags from db. |
|
71 | + * |
|
72 | + * @see \OCP\ITags |
|
73 | + * @param string $type The type identifier e.g. 'contact' or 'event'. |
|
74 | + * @param array $defaultTags An array of default tags to be used if none are stored. |
|
75 | + * @param boolean $includeShared Whether to include tags for items shared with this user by others. |
|
76 | + * @param string $userId user for which to retrieve the tags, defaults to the currently |
|
77 | + * logged in user |
|
78 | + * @return \OCP\ITags |
|
79 | + */ |
|
80 | + public function load($type, $defaultTags = array(), $includeShared = false, $userId = null) { |
|
81 | + if (is_null($userId)) { |
|
82 | + $user = $this->userSession->getUser(); |
|
83 | + if ($user === null) { |
|
84 | + // nothing we can do without a user |
|
85 | + return null; |
|
86 | + } |
|
87 | + $userId = $this->userSession->getUser()->getUId(); |
|
88 | + } |
|
89 | + return new Tags($this->mapper, $userId, $type, $defaultTags, $includeShared); |
|
90 | + } |
|
91 | 91 | |
92 | 92 | } |