router.php 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * URL routing utilities
  6. *
  7. * PHP version 5
  8. *
  9. * LICENCE: This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. * @category URL
  23. * @package StatusNet
  24. * @author Evan Prodromou <evan@status.net>
  25. * @copyright 2009 StatusNet, Inc.
  26. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  27. * @link http://status.net/
  28. */
  29. if (!defined('GNUSOCIAL')) {
  30. exit(1);
  31. }
  32. /**
  33. * URL Router
  34. *
  35. * Cheap wrapper around Net_URL_Mapper
  36. *
  37. * @category URL
  38. * @package StatusNet
  39. * @author Evan Prodromou <evan@status.net>
  40. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  41. * @link http://status.net/
  42. */
  43. class Router
  44. {
  45. public $m = null;
  46. public static $inst = null;
  47. const REGEX_TAG = '[^\/]+'; // [\pL\pN_\-\.]{1,64} better if we can do unicode regexes
  48. public static function get()
  49. {
  50. if (!Router::$inst) {
  51. Router::$inst = new Router();
  52. }
  53. return Router::$inst;
  54. }
  55. /**
  56. * Clear the global singleton instance for this class.
  57. * Needed to ensure reset when switching site configurations.
  58. */
  59. public static function clear()
  60. {
  61. Router::$inst = null;
  62. }
  63. public function __construct()
  64. {
  65. if (empty($this->m)) {
  66. $this->m = $this->initialize();
  67. }
  68. }
  69. /**
  70. * Create a unique hashkey for the router.
  71. *
  72. * The router's url map can change based on the version of the software
  73. * you're running and the plugins that are enabled. To avoid having bad routes
  74. * get stuck in the cache, the key includes a list of plugins and the software
  75. * version.
  76. *
  77. * There can still be problems with a) differences in versions of the plugins and
  78. * b) people running code between official versions, but these tend to be more
  79. * sophisticated users who can grok what's going on and clear their caches.
  80. *
  81. * @return string cache key string that should uniquely identify a router
  82. */
  83. public static function cacheKey()
  84. {
  85. $parts = array('router');
  86. // Many router paths depend on this setting.
  87. if (common_config('singleuser', 'enabled')) {
  88. $parts[] = '1user';
  89. } else {
  90. $parts[] = 'multi';
  91. }
  92. return Cache::codeKey(implode(':', $parts));
  93. }
  94. public function initialize()
  95. {
  96. $m = new URLMapper();
  97. if (Event::handle('StartInitializeRouter', [&$m])) {
  98. // top of the menu hierarchy, sometimes "Home"
  99. $m->connect('', ['action' => 'top']);
  100. // public endpoints
  101. $m->connect('robots.txt', ['action' => 'robotstxt']);
  102. $m->connect(
  103. 'opensearch/people',
  104. ['action' => 'opensearch',
  105. 'type' => 'people']
  106. );
  107. $m->connect(
  108. 'opensearch/notice',
  109. ['action' => 'opensearch',
  110. 'type' => 'notice']
  111. );
  112. // docs
  113. $m->connect('doc/:title', ['action' => 'doc']);
  114. $m->connect(
  115. 'main/otp/:user_id/:token',
  116. ['action' => 'otp'],
  117. ['user_id' => '[0-9]+',
  118. 'token' => '.+']
  119. );
  120. // these take a code; before the main part
  121. foreach (['register', 'confirmaddress', 'recoverpassword'] as $c) {
  122. $m->connect('main/'.$c.'/:code', ['action' => $c]);
  123. }
  124. // Also need a block variant accepting ID on URL for mail links
  125. $m->connect(
  126. 'main/block/:profileid',
  127. ['action' => 'block'],
  128. ['profileid' => '[0-9]+']
  129. );
  130. $m->connect(
  131. 'main/sup/:seconds',
  132. ['action' => 'sup'],
  133. ['seconds' => '[0-9]+']
  134. );
  135. // main stuff is repetitive
  136. $main = ['login', 'logout', 'register', 'subscribe',
  137. 'unsubscribe', 'cancelsubscription', 'approvesub',
  138. 'confirmaddress', 'recoverpassword',
  139. 'invite', 'sup',
  140. 'block', 'unblock', 'subedit',
  141. 'groupblock', 'groupunblock',
  142. 'sandbox', 'unsandbox',
  143. 'silence', 'unsilence',
  144. 'grantrole', 'revokerole',
  145. 'deleteuser',
  146. 'geocode',
  147. 'version',
  148. 'backupaccount',
  149. 'deleteaccount',
  150. 'restoreaccount',
  151. 'top',
  152. 'public'];
  153. foreach ($main as $a) {
  154. $m->connect('main/'.$a, ['action' => $a]);
  155. }
  156. $m->connect('main/all', ['action' => 'networkpublic']);
  157. $m->connect(
  158. 'main/tagprofile/:id',
  159. ['action' => 'tagprofile'],
  160. ['id' => '[0-9]+']
  161. );
  162. $m->connect('main/tagprofile', ['action' => 'tagprofile']);
  163. $m->connect(
  164. 'main/xrds',
  165. ['action' => 'publicxrds']
  166. );
  167. // settings
  168. foreach (['profile', 'avatar', 'password', 'im', 'oauthconnections',
  169. 'oauthapps', 'email', 'sms', 'url'] as $s) {
  170. $m->connect('settings/'.$s, ['action' => $s.'settings']);
  171. }
  172. if (common_config('oldschool', 'enabled')) {
  173. $m->connect('settings/oldschool', ['action' => 'oldschoolsettings']);
  174. }
  175. $m->connect(
  176. 'settings/oauthapps/show/:id',
  177. ['action' => 'showapplication'],
  178. ['id' => '[0-9]+']
  179. );
  180. $m->connect(
  181. 'settings/oauthapps/new',
  182. ['action' => 'newapplication']
  183. );
  184. $m->connect(
  185. 'settings/oauthapps/edit/:id',
  186. ['action' => 'editapplication'],
  187. ['id' => '[0-9]+']
  188. );
  189. $m->connect(
  190. 'settings/oauthapps/delete/:id',
  191. ['action' => 'deleteapplication'],
  192. ['id' => '[0-9]+']
  193. );
  194. // search
  195. foreach (['group', 'people', 'notice'] as $s) {
  196. $m->connect(
  197. 'search/'.$s.'?q=:q',
  198. ['action' => $s.'search'],
  199. ['q' => '.+']
  200. );
  201. $m->connect('search/'.$s, ['action' => $s.'search']);
  202. }
  203. // The second of these is needed to make the link work correctly
  204. // when inserted into the page. The first is needed to match the
  205. // route on the way in. Seems to be another Net_URL_Mapper bug to me.
  206. $m->connect(
  207. 'search/notice/rss?q=:q',
  208. ['action' => 'noticesearchrss'],
  209. ['q' => '.+']
  210. );
  211. $m->connect('search/notice/rss', ['action' => 'noticesearchrss']);
  212. foreach (['' => 'attachment',
  213. '/view' => 'attachment_view',
  214. '/download' => 'attachment_download',
  215. '/thumbnail' => 'attachment_thumbnail'] as $postfix => $action) {
  216. foreach (['filehash' => '[A-Za-z0-9._-]{64}',
  217. 'attachment' => '[0-9]+'] as $type => $match) {
  218. $m->connect(
  219. "attachment/:{$type}{$postfix}",
  220. ['action' => $action],
  221. [$type => $match]
  222. );
  223. }
  224. }
  225. $m->connect(
  226. 'notice/new?replyto=:replyto&inreplyto=:inreplyto',
  227. ['action' => 'newnotice'],
  228. ['replyto' => Nickname::DISPLAY_FMT,
  229. 'inreplyto' => '[0-9]+']
  230. );
  231. $m->connect(
  232. 'notice/new?replyto=:replyto',
  233. ['action' => 'newnotice'],
  234. ['replyto' => Nickname::DISPLAY_FMT]
  235. );
  236. $m->connect('notice/new', ['action' => 'newnotice']);
  237. $m->connect(
  238. 'notice/:notice',
  239. ['action' => 'shownotice'],
  240. ['notice' => '[0-9]+']
  241. );
  242. $m->connect(
  243. 'notice/:notice/delete',
  244. ['action' => 'deletenotice'],
  245. ['notice' => '[0-9]+']
  246. );
  247. // conversation
  248. $m->connect(
  249. 'conversation/:id',
  250. ['action' => 'conversation'],
  251. ['id' => '[0-9]+']
  252. );
  253. $m->connect(
  254. 'user/:id',
  255. ['action' => 'userbyid'],
  256. ['id' => '[0-9]+']
  257. );
  258. $m->connect(
  259. 'tag/:tag/rss',
  260. ['action' => 'tagrss'],
  261. ['tag' => self::REGEX_TAG]
  262. );
  263. $m->connect(
  264. 'tag/:tag',
  265. ['action' => 'tag'],
  266. ['tag' => self::REGEX_TAG]
  267. );
  268. // groups
  269. $m->connect('group/new', ['action' => 'newgroup']);
  270. foreach (['edit', 'join', 'leave', 'delete', 'cancel', 'approve'] as $v) {
  271. $m->connect(
  272. 'group/:nickname/'.$v,
  273. ['action' => $v.'group'],
  274. ['nickname' => Nickname::DISPLAY_FMT]
  275. );
  276. $m->connect(
  277. 'group/:id/id/'.$v,
  278. ['action' => $v.'group'],
  279. ['id' => '[0-9]+']
  280. );
  281. }
  282. foreach (['members', 'logo', 'rss'] as $n) {
  283. $m->connect(
  284. 'group/:nickname/'.$n,
  285. ['action' => 'group'.$n],
  286. ['nickname' => Nickname::DISPLAY_FMT]
  287. );
  288. }
  289. $m->connect(
  290. 'group/:nickname/foaf',
  291. ['action' => 'foafgroup'],
  292. ['nickname' => Nickname::DISPLAY_FMT]
  293. );
  294. $m->connect(
  295. 'group/:nickname/blocked',
  296. ['action' => 'blockedfromgroup'],
  297. ['nickname' => Nickname::DISPLAY_FMT]
  298. );
  299. $m->connect(
  300. 'group/:nickname/makeadmin',
  301. ['action' => 'makeadmin'],
  302. ['nickname' => Nickname::DISPLAY_FMT]
  303. );
  304. $m->connect(
  305. 'group/:nickname/members/pending',
  306. ['action' => 'groupqueue'],
  307. ['nickname' => Nickname::DISPLAY_FMT]
  308. );
  309. $m->connect(
  310. 'group/:id/id',
  311. ['action' => 'groupbyid'],
  312. ['id' => '[0-9]+']
  313. );
  314. $m->connect(
  315. 'group/:nickname',
  316. ['action' => 'showgroup'],
  317. ['nickname' => Nickname::DISPLAY_FMT]
  318. );
  319. $m->connect(
  320. 'group/:nickname/',
  321. ['action' => 'showgroup'],
  322. ['nickname' => Nickname::DISPLAY_FMT]
  323. );
  324. $m->connect('group/', ['action' => 'groups']);
  325. $m->connect('group', ['action' => 'groups']);
  326. $m->connect('groups/', ['action' => 'groups']);
  327. $m->connect('groups', ['action' => 'groups']);
  328. // Twitter-compatible API
  329. // statuses API
  330. $m->connect(
  331. 'api',
  332. ['action' => 'Redirect',
  333. 'nextAction' => 'doc',
  334. 'args' => ['title' => 'api']]
  335. );
  336. $m->connect(
  337. 'api/statuses/public_timeline.:format',
  338. ['action' => 'ApiTimelinePublic'],
  339. ['format' => '(xml|json|rss|atom|as)']
  340. );
  341. // this is not part of the Twitter API. Also may require authentication depending on server config!
  342. $m->connect(
  343. 'api/statuses/networkpublic_timeline.:format',
  344. ['action' => 'ApiTimelineNetworkPublic'],
  345. ['format' => '(xml|json|rss|atom|as)']
  346. );
  347. $m->connect(
  348. 'api/statuses/friends_timeline/:id.:format',
  349. ['action' => 'ApiTimelineFriends'],
  350. ['id' => Nickname::INPUT_FMT,
  351. 'format' => '(xml|json|rss|atom|as)']
  352. );
  353. $m->connect(
  354. 'api/statuses/friends_timeline.:format',
  355. ['action' => 'ApiTimelineFriends'],
  356. ['format' => '(xml|json|rss|atom|as)']
  357. );
  358. $m->connect(
  359. 'api/statuses/home_timeline/:id.:format',
  360. ['action' => 'ApiTimelineHome'],
  361. ['id' => Nickname::INPUT_FMT,
  362. 'format' => '(xml|json|rss|atom|as)']
  363. );
  364. $m->connect(
  365. 'api/statuses/home_timeline.:format',
  366. ['action' => 'ApiTimelineHome'],
  367. ['format' => '(xml|json|rss|atom|as)']
  368. );
  369. $m->connect(
  370. 'api/statuses/user_timeline/:id.:format',
  371. ['action' => 'ApiTimelineUser'],
  372. ['id' => Nickname::INPUT_FMT,
  373. 'format' => '(xml|json|rss|atom|as)']
  374. );
  375. $m->connect(
  376. 'api/statuses/user_timeline.:format',
  377. ['action' => 'ApiTimelineUser'],
  378. ['format' => '(xml|json|rss|atom|as)']
  379. );
  380. $m->connect(
  381. 'api/statuses/mentions/:id.:format',
  382. ['action' => 'ApiTimelineMentions'],
  383. ['id' => Nickname::INPUT_FMT,
  384. 'format' => '(xml|json|rss|atom|as)']
  385. );
  386. $m->connect(
  387. 'api/statuses/mentions.:format',
  388. ['action' => 'ApiTimelineMentions'],
  389. ['format' => '(xml|json|rss|atom|as)']
  390. );
  391. $m->connect(
  392. 'api/statuses/replies/:id.:format',
  393. ['action' => 'ApiTimelineMentions'],
  394. ['id' => Nickname::INPUT_FMT,
  395. 'format' => '(xml|json|rss|atom|as)']
  396. );
  397. $m->connect(
  398. 'api/statuses/replies.:format',
  399. ['action' => 'ApiTimelineMentions'],
  400. ['format' => '(xml|json|rss|atom|as)']
  401. );
  402. $m->connect(
  403. 'api/statuses/mentions_timeline/:id.:format',
  404. ['action' => 'ApiTimelineMentions'],
  405. ['id' => Nickname::INPUT_FMT,
  406. 'format' => '(xml|json|rss|atom|as)']
  407. );
  408. $m->connect(
  409. 'api/statuses/mentions_timeline.:format',
  410. ['action' => 'ApiTimelineMentions'],
  411. ['format' => '(xml|json|rss|atom|as)']
  412. );
  413. $m->connect(
  414. 'api/statuses/friends/:id.:format',
  415. ['action' => 'ApiUserFriends'],
  416. ['id' => Nickname::INPUT_FMT,
  417. 'format' => '(xml|json)']
  418. );
  419. $m->connect(
  420. 'api/statuses/friends.:format',
  421. ['action' => 'ApiUserFriends'],
  422. ['format' => '(xml|json)']
  423. );
  424. $m->connect(
  425. 'api/statuses/followers/:id.:format',
  426. ['action' => 'ApiUserFollowers'],
  427. ['id' => Nickname::INPUT_FMT,
  428. 'format' => '(xml|json)']
  429. );
  430. $m->connect(
  431. 'api/statuses/followers.:format',
  432. ['action' => 'ApiUserFollowers'],
  433. ['format' => '(xml|json)']
  434. );
  435. $m->connect(
  436. 'api/statuses/show/:id.:format',
  437. ['action' => 'ApiStatusesShow'],
  438. ['id' => '[0-9]+',
  439. 'format' => '(xml|json|atom)']
  440. );
  441. $m->connect(
  442. 'api/statuses/show.:format',
  443. ['action' => 'ApiStatusesShow'],
  444. ['format' => '(xml|json|atom)']
  445. );
  446. $m->connect(
  447. 'api/statuses/update.:format',
  448. ['action' => 'ApiStatusesUpdate'],
  449. ['format' => '(xml|json|atom)']
  450. );
  451. $m->connect(
  452. 'api/statuses/destroy/:id.:format',
  453. ['action' => 'ApiStatusesDestroy'],
  454. ['id' => '[0-9]+',
  455. 'format' => '(xml|json)']
  456. );
  457. $m->connect(
  458. 'api/statuses/destroy.:format',
  459. ['action' => 'ApiStatusesDestroy'],
  460. ['format' => '(xml|json)']
  461. );
  462. // START qvitter API additions
  463. $m->connect(
  464. 'api/attachment/:id.:format',
  465. ['action' => 'ApiAttachment'],
  466. ['id' => '[0-9]+',
  467. 'format' => '(xml|json)']
  468. );
  469. $m->connect(
  470. 'api/checkhub.:format',
  471. ['action' => 'ApiCheckHub'],
  472. ['format' => '(xml|json)']
  473. );
  474. $m->connect(
  475. 'api/externalprofile/show.:format',
  476. ['action' => 'ApiExternalProfileShow'],
  477. ['format' => '(xml|json)']
  478. );
  479. $m->connect(
  480. 'api/statusnet/groups/admins/:id.:format',
  481. ['action' => 'ApiGroupAdmins'],
  482. ['id' => Nickname::INPUT_FMT,
  483. 'format' => '(xml|json)']
  484. );
  485. $m->connect(
  486. 'api/account/update_link_color.:format',
  487. ['action' => 'ApiAccountUpdateLinkColor'],
  488. ['format' => '(xml|json)']
  489. );
  490. $m->connect(
  491. 'api/account/update_background_color.:format',
  492. ['action' => 'ApiAccountUpdateBackgroundColor'],
  493. ['format' => '(xml|json)']
  494. );
  495. $m->connect(
  496. 'api/account/register.:format',
  497. ['action' => 'ApiAccountRegister'],
  498. ['format' => '(xml|json)']
  499. );
  500. $m->connect(
  501. 'api/check_nickname.:format',
  502. ['action' => 'ApiCheckNickname'],
  503. ['format' => '(xml|json)']
  504. );
  505. // END qvitter API additions
  506. // users
  507. $m->connect(
  508. 'api/users/show/:id.:format',
  509. ['action' => 'ApiUserShow'],
  510. ['id' => Nickname::INPUT_FMT,
  511. 'format' => '(xml|json)']
  512. );
  513. $m->connect(
  514. 'api/users/show.:format',
  515. ['action' => 'ApiUserShow'],
  516. ['format' => '(xml|json)']
  517. );
  518. $m->connect(
  519. 'api/users/profile_image/:screen_name.:format',
  520. ['action' => 'ApiUserProfileImage'],
  521. ['screen_name' => Nickname::DISPLAY_FMT,
  522. 'format' => '(xml|json)']
  523. );
  524. // friendships
  525. $m->connect(
  526. 'api/friendships/show.:format',
  527. ['action' => 'ApiFriendshipsShow'],
  528. ['format' => '(xml|json)']
  529. );
  530. $m->connect(
  531. 'api/friendships/exists.:format',
  532. ['action' => 'ApiFriendshipsExists'],
  533. ['format' => '(xml|json)']
  534. );
  535. $m->connect(
  536. 'api/friendships/create/:id.:format',
  537. ['action' => 'ApiFriendshipsCreate'],
  538. ['id' => Nickname::INPUT_FMT,
  539. 'format' => '(xml|json)']
  540. );
  541. $m->connect(
  542. 'api/friendships/create.:format',
  543. ['action' => 'ApiFriendshipsCreate'],
  544. ['format' => '(xml|json)']
  545. );
  546. $m->connect(
  547. 'api/friendships/destroy/:id.:format',
  548. ['action' => 'ApiFriendshipsDestroy'],
  549. ['id' => Nickname::INPUT_FMT,
  550. 'format' => '(xml|json)']
  551. );
  552. $m->connect(
  553. 'api/friendships/destroy.:format',
  554. ['action' => 'ApiFriendshipsDestroy'],
  555. ['format' => '(xml|json)']
  556. );
  557. // Social graph
  558. $m->connect(
  559. 'api/friends/ids/:id.:format',
  560. ['action' => 'ApiUserFriends',
  561. 'ids_only' => true],
  562. ['id' => Nickname::INPUT_FMT,
  563. 'format' => '(xml|json)']
  564. );
  565. $m->connect(
  566. 'api/followers/ids/:id.:format',
  567. ['action' => 'ApiUserFollowers',
  568. 'ids_only' => true],
  569. ['id' => Nickname::INPUT_FMT,
  570. 'format' => '(xml|json)']
  571. );
  572. $m->connect(
  573. 'api/friends/ids.:format',
  574. ['action' => 'ApiUserFriends',
  575. 'ids_only' => true],
  576. ['format' => '(xml|json)']
  577. );
  578. $m->connect(
  579. 'api/followers/ids.:format',
  580. ['action' => 'ApiUserFollowers',
  581. 'ids_only' => true],
  582. ['format' => '(xml|json)']
  583. );
  584. // account
  585. $m->connect(
  586. 'api/account/verify_credentials.:format',
  587. ['action' => 'ApiAccountVerifyCredentials'],
  588. ['format' => '(xml|json)']
  589. );
  590. $m->connect(
  591. 'api/account/update_profile.:format',
  592. ['action' => 'ApiAccountUpdateProfile'],
  593. ['format' => '(xml|json)']
  594. );
  595. $m->connect(
  596. 'api/account/update_profile_image.:format',
  597. ['action' => 'ApiAccountUpdateProfileImage'],
  598. ['format' => '(xml|json)']
  599. );
  600. $m->connect(
  601. 'api/account/update_delivery_device.:format',
  602. ['action' => 'ApiAccountUpdateDeliveryDevice'],
  603. ['format' => '(xml|json)']
  604. );
  605. // special case where verify_credentials is called w/out a format
  606. $m->connect(
  607. 'api/account/verify_credentials',
  608. ['action' => 'ApiAccountVerifyCredentials']
  609. );
  610. $m->connect(
  611. 'api/account/rate_limit_status.:format',
  612. ['action' => 'ApiAccountRateLimitStatus'],
  613. ['format' => '(xml|json)']
  614. );
  615. // blocks
  616. $m->connect(
  617. 'api/blocks/create/:id.:format',
  618. ['action' => 'ApiBlockCreate'],
  619. ['id' => Nickname::INPUT_FMT,
  620. 'format' => '(xml|json)']
  621. );
  622. $m->connect(
  623. 'api/blocks/create.:format',
  624. ['action' => 'ApiBlockCreate'],
  625. ['format' => '(xml|json)']
  626. );
  627. $m->connect(
  628. 'api/blocks/destroy/:id.:format',
  629. ['action' => 'ApiBlockDestroy'],
  630. ['id' => Nickname::INPUT_FMT,
  631. 'format' => '(xml|json)']
  632. );
  633. $m->connect(
  634. 'api/blocks/destroy.:format',
  635. ['action' => 'ApiBlockDestroy'],
  636. ['format' => '(xml|json)']
  637. );
  638. // help
  639. $m->connect(
  640. 'api/help/test.:format',
  641. ['action' => 'ApiHelpTest'],
  642. ['format' => '(xml|json)']
  643. );
  644. // statusnet
  645. $m->connect(
  646. 'api/statusnet/version.:format',
  647. ['action' => 'ApiGNUsocialVersion'],
  648. ['format' => '(xml|json)']
  649. );
  650. $m->connect(
  651. 'api/statusnet/config.:format',
  652. ['action' => 'ApiGNUsocialConfig'],
  653. ['format' => '(xml|json)']
  654. );
  655. // For our current software name, we provide "gnusocial" base action
  656. $m->connect(
  657. 'api/gnusocial/version.:format',
  658. ['action' => 'ApiGNUsocialVersion'],
  659. ['format' => '(xml|json)']
  660. );
  661. $m->connect(
  662. 'api/gnusocial/config.:format',
  663. ['action' => 'ApiGNUsocialConfig'],
  664. ['format' => '(xml|json)']
  665. );
  666. // Groups and tags are newer than 0.8.1 so no backward-compatibility
  667. // necessary
  668. // Groups
  669. //'list' has to be handled differently, as php will not allow a method to be named 'list'
  670. $m->connect(
  671. 'api/statusnet/groups/timeline/:id.:format',
  672. ['action' => 'ApiTimelineGroup'],
  673. ['id' => Nickname::INPUT_FMT,
  674. 'format' => '(xml|json|rss|atom|as)']
  675. );
  676. $m->connect(
  677. 'api/statusnet/groups/show/:id.:format',
  678. ['action' => 'ApiGroupShow'],
  679. ['id' => Nickname::INPUT_FMT,
  680. 'format' => '(xml|json)']
  681. );
  682. $m->connect(
  683. 'api/statusnet/groups/show.:format',
  684. ['action' => 'ApiGroupShow'],
  685. ['format' => '(xml|json)']
  686. );
  687. $m->connect(
  688. 'api/statusnet/groups/join/:id.:format',
  689. ['action' => 'ApiGroupJoin'],
  690. ['id' => Nickname::INPUT_FMT,
  691. 'format' => '(xml|json)']
  692. );
  693. $m->connect(
  694. 'api/statusnet/groups/join.:format',
  695. ['action' => 'ApiGroupJoin'],
  696. ['format' => '(xml|json)']
  697. );
  698. $m->connect(
  699. 'api/statusnet/groups/leave/:id.:format',
  700. ['action' => 'ApiGroupLeave'],
  701. ['id' => Nickname::INPUT_FMT,
  702. 'format' => '(xml|json)']
  703. );
  704. $m->connect(
  705. 'api/statusnet/groups/leave.:format',
  706. ['action' => 'ApiGroupLeave'],
  707. ['format' => '(xml|json)']
  708. );
  709. $m->connect(
  710. 'api/statusnet/groups/is_member.:format',
  711. ['action' => 'ApiGroupIsMember'],
  712. ['format' => '(xml|json)']
  713. );
  714. $m->connect(
  715. 'api/statusnet/groups/list/:id.:format',
  716. ['action' => 'ApiGroupList'],
  717. ['id' => Nickname::INPUT_FMT,
  718. 'format' => '(xml|json|rss|atom)']
  719. );
  720. $m->connect(
  721. 'api/statusnet/groups/list.:format',
  722. ['action' => 'ApiGroupList'],
  723. ['format' => '(xml|json|rss|atom)']
  724. );
  725. $m->connect(
  726. 'api/statusnet/groups/list_all.:format',
  727. ['action' => 'ApiGroupListAll'],
  728. ['format' => '(xml|json|rss|atom)']
  729. );
  730. $m->connect(
  731. 'api/statusnet/groups/membership/:id.:format',
  732. ['action' => 'ApiGroupMembership'],
  733. ['id' => Nickname::INPUT_FMT,
  734. 'format' => '(xml|json)']
  735. );
  736. $m->connect(
  737. 'api/statusnet/groups/membership.:format',
  738. ['action' => 'ApiGroupMembership'],
  739. ['format' => '(xml|json)']
  740. );
  741. $m->connect(
  742. 'api/statusnet/groups/create.:format',
  743. ['action' => 'ApiGroupCreate'],
  744. ['format' => '(xml|json)']
  745. );
  746. $m->connect(
  747. 'api/statusnet/groups/update/:id.:format',
  748. ['action' => 'ApiGroupProfileUpdate'],
  749. ['id' => '[a-zA-Z0-9]+',
  750. 'format' => '(xml|json)']
  751. );
  752. $m->connect(
  753. 'api/statusnet/conversation/:id.:format',
  754. ['action' => 'apiconversation'],
  755. ['id' => '[0-9]+',
  756. 'format' => '(xml|json|rss|atom|as)']
  757. );
  758. // Lists (people tags)
  759. $m->connect(
  760. 'api/lists/list.:format',
  761. ['action' => 'ApiListSubscriptions'],
  762. ['format' => '(xml|json)']
  763. );
  764. $m->connect(
  765. 'api/lists/memberships.:format',
  766. ['action' => 'ApiListMemberships'],
  767. ['format' => '(xml|json)']
  768. );
  769. $m->connect(
  770. 'api/:user/lists/memberships.:format',
  771. ['action' => 'ApiListMemberships'],
  772. ['user' => '[a-zA-Z0-9]+',
  773. 'format' => '(xml|json)']
  774. );
  775. $m->connect(
  776. 'api/lists/subscriptions.:format',
  777. ['action' => 'ApiListSubscriptions'],
  778. ['format' => '(xml|json)']
  779. );
  780. $m->connect(
  781. 'api/:user/lists/subscriptions.:format',
  782. ['action' => 'ApiListSubscriptions'],
  783. ['user' => '[a-zA-Z0-9]+',
  784. 'format' => '(xml|json)']
  785. );
  786. $m->connect(
  787. 'api/lists.:format',
  788. ['action' => 'ApiLists'],
  789. ['format' => '(xml|json)']
  790. );
  791. $m->connect(
  792. 'api/:user/lists/:id.:format',
  793. ['action' => 'ApiList'],
  794. ['user' => '[a-zA-Z0-9]+',
  795. 'id' => '[a-zA-Z0-9]+',
  796. 'format' => '(xml|json)']
  797. );
  798. $m->connect(
  799. 'api/:user/lists.:format',
  800. ['action' => 'ApiLists'],
  801. ['user' => '[a-zA-Z0-9]+',
  802. 'format' => '(xml|json)']
  803. );
  804. $m->connect(
  805. 'api/:user/lists/:id/statuses.:format',
  806. ['action' => 'ApiTimelineList'],
  807. ['user' => '[a-zA-Z0-9]+',
  808. 'id' => '[a-zA-Z0-9]+',
  809. 'format' => '(xml|json|rss|atom)']
  810. );
  811. $m->connect(
  812. 'api/:user/:list_id/members/:id.:format',
  813. ['action' => 'ApiListMember'],
  814. ['user' => '[a-zA-Z0-9]+',
  815. 'list_id' => '[a-zA-Z0-9]+',
  816. 'id' => '[a-zA-Z0-9]+',
  817. 'format' => '(xml|json)']
  818. );
  819. $m->connect(
  820. 'api/:user/:list_id/members.:format',
  821. ['action' => 'ApiListMembers'],
  822. ['user' => '[a-zA-Z0-9]+',
  823. 'list_id' => '[a-zA-Z0-9]+',
  824. 'format' => '(xml|json)']
  825. );
  826. $m->connect(
  827. 'api/:user/:list_id/subscribers/:id.:format',
  828. ['action' => 'ApiListSubscriber'],
  829. ['user' => '[a-zA-Z0-9]+',
  830. 'list_id' => '[a-zA-Z0-9]+',
  831. 'id' => '[a-zA-Z0-9]+',
  832. 'format' => '(xml|json)']
  833. );
  834. $m->connect(
  835. 'api/:user/:list_id/subscribers.:format',
  836. ['action' => 'ApiListSubscribers'],
  837. ['user' => '[a-zA-Z0-9]+',
  838. 'list_id' => '[a-zA-Z0-9]+',
  839. 'format' => '(xml|json)']
  840. );
  841. // Tags
  842. $m->connect(
  843. 'api/statusnet/tags/timeline/:tag.:format',
  844. ['action' => 'ApiTimelineTag'],
  845. ['tag' => self::REGEX_TAG,
  846. 'format' => '(xml|json|rss|atom|as)']
  847. );
  848. // media related
  849. $m->connect(
  850. 'api/statusnet/media/upload',
  851. ['action' => 'ApiMediaUpload']
  852. );
  853. $m->connect(
  854. 'api/statuses/update_with_media.json',
  855. ['action' => 'ApiMediaUpload']
  856. );
  857. // Twitter Media upload API v1.1
  858. $m->connect(
  859. 'api/media/upload.:format',
  860. ['action' => 'ApiMediaUpload'],
  861. ['format' => '(xml|json)']
  862. );
  863. // search
  864. $m->connect('api/search.atom', ['action' => 'ApiSearchAtom']);
  865. $m->connect('api/search.json', ['action' => 'ApiSearchJSON']);
  866. $m->connect('api/trends.json', ['action' => 'ApiTrends']);
  867. $m->connect(
  868. 'api/oauth/request_token',
  869. ['action' => 'ApiOAuthRequestToken']
  870. );
  871. $m->connect(
  872. 'api/oauth/access_token',
  873. ['action' => 'ApiOAuthAccessToken']
  874. );
  875. $m->connect(
  876. 'api/oauth/authorize',
  877. ['action' => 'ApiOAuthAuthorize']
  878. );
  879. // Admin
  880. $m->connect('panel/site', ['action' => 'siteadminpanel']);
  881. $m->connect('panel/user', ['action' => 'useradminpanel']);
  882. $m->connect('panel/access', ['action' => 'accessadminpanel']);
  883. $m->connect('panel/paths', ['action' => 'pathsadminpanel']);
  884. $m->connect('panel/sessions', ['action' => 'sessionsadminpanel']);
  885. $m->connect('panel/sitenotice', ['action' => 'sitenoticeadminpanel']);
  886. $m->connect('panel/license', ['action' => 'licenseadminpanel']);
  887. $m->connect('panel/plugins', ['action' => 'pluginsadminpanel']);
  888. $m->connect(
  889. 'panel/plugins/enable/:plugin',
  890. ['action' => 'pluginenable'],
  891. ['plugin' => '[A-Za-z0-9_]+']
  892. );
  893. $m->connect(
  894. 'panel/plugins/disable/:plugin',
  895. ['action' => 'plugindisable'],
  896. ['plugin' => '[A-Za-z0-9_]+']
  897. );
  898. $m->connect(
  899. 'panel/plugins/delete/:plugin',
  900. ['action' => 'plugindelete'],
  901. ['plugin' => '[A-Za-z0-9_]+']
  902. );
  903. $m->connect(
  904. 'panel/plugins/install',
  905. ['action' => 'plugininstall']
  906. );
  907. // Common people-tag stuff
  908. $m->connect(
  909. 'peopletag/:tag',
  910. ['action' => 'peopletag'],
  911. ['tag' => self::REGEX_TAG]
  912. );
  913. $m->connect(
  914. 'selftag/:tag',
  915. ['action' => 'selftag'],
  916. ['tag' => self::REGEX_TAG]
  917. );
  918. $m->connect('main/addpeopletag', ['action' => 'addpeopletag']);
  919. $m->connect('main/removepeopletag', ['action' => 'removepeopletag']);
  920. $m->connect('main/profilecompletion', ['action' => 'profilecompletion']);
  921. $m->connect('main/peopletagautocomplete', ['action' => 'peopletagautocomplete']);
  922. // In the "root"
  923. if (common_config('singleuser', 'enabled')) {
  924. $nickname = User::singleUserNickname();
  925. foreach (['subscriptions', 'subscribers', 'all', 'foaf', 'replies'] as $a) {
  926. $m->connect(
  927. $a,
  928. ['action' => $a,
  929. 'nickname' => $nickname]
  930. );
  931. }
  932. foreach (['subscriptions', 'subscribers'] as $a) {
  933. $m->connect(
  934. $a.'/:tag',
  935. ['action' => $a,
  936. 'nickname' => $nickname],
  937. ['tag' => self::REGEX_TAG]
  938. );
  939. }
  940. $m->connect(
  941. 'subscribers/pending',
  942. ['action' => 'subqueue',
  943. 'nickname' => $nickname]
  944. );
  945. foreach (['rss', 'groups'] as $a) {
  946. $m->connect(
  947. $a,
  948. ['action' => 'user'.$a,
  949. 'nickname' => $nickname]
  950. );
  951. }
  952. foreach (['all', 'replies'] as $a) {
  953. $m->connect(
  954. $a.'/rss',
  955. ['action' => $a.'rss',
  956. 'nickname' => $nickname]
  957. );
  958. }
  959. $m->connect(
  960. 'avatar',
  961. ['action' => 'avatarbynickname',
  962. 'nickname' => $nickname]
  963. );
  964. $m->connect(
  965. 'avatar/:size',
  966. ['action' => 'avatarbynickname',
  967. 'nickname' => $nickname],
  968. ['size' => '(|original|\d+)']
  969. );
  970. $m->connect(
  971. 'tag/:tag/rss',
  972. ['action' => 'userrss',
  973. 'nickname' => $nickname],
  974. ['tag' => self::REGEX_TAG]
  975. );
  976. $m->connect(
  977. 'tag/:tag',
  978. ['action' => 'showstream',
  979. 'nickname' => $nickname],
  980. ['tag' => self::REGEX_TAG]
  981. );
  982. $m->connect(
  983. 'rsd.xml',
  984. ['action' => 'rsd',
  985. 'nickname' => $nickname]
  986. );
  987. // peopletags
  988. $m->connect(
  989. 'peopletags',
  990. ['action' => 'peopletagsbyuser']
  991. );
  992. $m->connect(
  993. 'peopletags/private',
  994. ['action' => 'peopletagsbyuser',
  995. 'private' => 1]
  996. );
  997. $m->connect(
  998. 'peopletags/public',
  999. ['action' => 'peopletagsbyuser',
  1000. 'public' => 1]
  1001. );
  1002. $m->connect(
  1003. 'othertags',
  1004. ['action' => 'peopletagsforuser']
  1005. );
  1006. $m->connect(
  1007. 'peopletagsubscriptions',
  1008. ['action' => 'peopletagsubscriptions']
  1009. );
  1010. $m->connect(
  1011. 'all/:tag/subscribers',
  1012. ['action' => 'peopletagsubscribers'],
  1013. ['tag' => self::REGEX_TAG]
  1014. );
  1015. $m->connect(
  1016. 'all/:tag/tagged',
  1017. ['action' => 'peopletagged'],
  1018. ['tag' => self::REGEX_TAG]
  1019. );
  1020. $m->connect(
  1021. 'all/:tag/edit',
  1022. ['action' => 'editpeopletag'],
  1023. ['tag' => self::REGEX_TAG]
  1024. );
  1025. foreach (['subscribe', 'unsubscribe'] as $v) {
  1026. $m->connect(
  1027. 'peopletag/:id/'.$v,
  1028. ['action' => $v.'peopletag'],
  1029. ['id' => '[0-9]{1,64}']
  1030. );
  1031. }
  1032. $m->connect(
  1033. 'user/:tagger_id/profiletag/:id/id',
  1034. ['action' => 'profiletagbyid'],
  1035. ['tagger_id' => '[0-9]+',
  1036. 'id' => '[0-9]+']
  1037. );
  1038. $m->connect(
  1039. 'all/:tag',
  1040. ['action' => 'showprofiletag',
  1041. 'tagger' => $nickname],
  1042. ['tag' => self::REGEX_TAG]
  1043. );
  1044. foreach (['subscriptions', 'subscribers'] as $a) {
  1045. $m->connect(
  1046. $a.'/:tag',
  1047. ['action' => $a],
  1048. ['tag' => self::REGEX_TAG]
  1049. );
  1050. }
  1051. }
  1052. $m->connect('rss', ['action' => 'publicrss']);
  1053. $m->connect('featuredrss', ['action' => 'featuredrss']);
  1054. $m->connect('featured/', ['action' => 'featured']);
  1055. $m->connect('featured', ['action' => 'featured']);
  1056. $m->connect('rsd.xml', ['action' => 'rsd']);
  1057. foreach (['subscriptions', 'subscribers',
  1058. 'nudge', 'all', 'foaf', 'replies',
  1059. 'inbox', 'outbox'] as $a) {
  1060. $m->connect(
  1061. ':nickname/'.$a,
  1062. ['action' => $a],
  1063. ['nickname' => Nickname::DISPLAY_FMT]
  1064. );
  1065. }
  1066. $m->connect(
  1067. ':nickname/subscribers/pending',
  1068. ['action' => 'subqueue'],
  1069. ['nickname' => Nickname::DISPLAY_FMT]
  1070. );
  1071. // some targeted RSS 1.0 actions (extends TargetedRss10Action)
  1072. foreach (['all', 'replies'] as $a) {
  1073. $m->connect(
  1074. ':nickname/'.$a.'/rss',
  1075. ['action' => $a.'rss'],
  1076. ['nickname' => Nickname::DISPLAY_FMT]
  1077. );
  1078. }
  1079. // people tags
  1080. $m->connect(
  1081. ':nickname/peopletags',
  1082. ['action' => 'peopletagsbyuser'],
  1083. ['nickname' => Nickname::DISPLAY_FMT]
  1084. );
  1085. $m->connect(
  1086. ':nickname/peopletags/private',
  1087. ['action' => 'peopletagsbyuser',
  1088. 'private' => 1],
  1089. ['nickname' => Nickname::DISPLAY_FMT]
  1090. );
  1091. $m->connect(
  1092. ':nickname/peopletags/public',
  1093. ['action' => 'peopletagsbyuser',
  1094. 'public' => 1],
  1095. ['nickname' => Nickname::DISPLAY_FMT]
  1096. );
  1097. $m->connect(
  1098. ':nickname/othertags',
  1099. ['action' => 'peopletagsforuser'],
  1100. ['nickname' => Nickname::DISPLAY_FMT]
  1101. );
  1102. $m->connect(
  1103. ':nickname/peopletagsubscriptions',
  1104. ['action' => 'peopletagsubscriptions'],
  1105. ['nickname' => Nickname::DISPLAY_FMT]
  1106. );
  1107. $m->connect(
  1108. ':tagger/all/:tag/subscribers',
  1109. ['action' => 'peopletagsubscribers'],
  1110. ['tagger' => Nickname::DISPLAY_FMT,
  1111. 'tag' => self::REGEX_TAG]
  1112. );
  1113. $m->connect(
  1114. ':tagger/all/:tag/tagged',
  1115. ['action' => 'peopletagged'],
  1116. ['tagger' => Nickname::DISPLAY_FMT,
  1117. 'tag' => self::REGEX_TAG]
  1118. );
  1119. $m->connect(
  1120. ':tagger/all/:tag/edit',
  1121. ['action' => 'editpeopletag'],
  1122. ['tagger' => Nickname::DISPLAY_FMT,
  1123. 'tag' => self::REGEX_TAG]
  1124. );
  1125. foreach (['subscribe', 'unsubscribe'] as $v) {
  1126. $m->connect(
  1127. 'peopletag/:id/'.$v,
  1128. ['action' => $v.'peopletag'],
  1129. ['id' => '[0-9]{1,64}']
  1130. );
  1131. }
  1132. $m->connect(
  1133. 'user/:tagger_id/profiletag/:id/id',
  1134. ['action' => 'profiletagbyid'],
  1135. ['tagger_id' => '[0-9]+',
  1136. 'id' => '[0-9]+']
  1137. );
  1138. $m->connect(
  1139. ':nickname/all/:tag',
  1140. ['action' => 'showprofiletag'],
  1141. ['nickname' => Nickname::DISPLAY_FMT,
  1142. 'tag' => self::REGEX_TAG]
  1143. );
  1144. foreach (['subscriptions', 'subscribers'] as $a) {
  1145. $m->connect(
  1146. ':nickname/'.$a.'/:tag',
  1147. ['action' => $a],
  1148. ['tag' => self::REGEX_TAG,
  1149. 'nickname' => Nickname::DISPLAY_FMT]
  1150. );
  1151. }
  1152. foreach (['rss', 'groups'] as $a) {
  1153. $m->connect(
  1154. ':nickname/'.$a,
  1155. ['action' => 'user'.$a],
  1156. ['nickname' => Nickname::DISPLAY_FMT]
  1157. );
  1158. }
  1159. $m->connect(
  1160. ':nickname/avatar',
  1161. ['action' => 'avatarbynickname'],
  1162. ['nickname' => Nickname::DISPLAY_FMT]
  1163. );
  1164. $m->connect(
  1165. ':nickname/avatar/:size',
  1166. ['action' => 'avatarbynickname'],
  1167. ['size' => '(|original|\d+)',
  1168. 'nickname' => Nickname::DISPLAY_FMT]
  1169. );
  1170. $m->connect(
  1171. ':nickname/tag/:tag/rss',
  1172. ['action' => 'userrss'],
  1173. ['nickname' => Nickname::DISPLAY_FMT,
  1174. 'tag' => self::REGEX_TAG]
  1175. );
  1176. $m->connect(
  1177. ':nickname/tag/:tag',
  1178. ['action' => 'showstream'],
  1179. ['nickname' => Nickname::DISPLAY_FMT,
  1180. 'tag' => self::REGEX_TAG]
  1181. );
  1182. $m->connect(
  1183. ':nickname/rsd.xml',
  1184. ['action' => 'rsd'],
  1185. ['nickname' => Nickname::DISPLAY_FMT]
  1186. );
  1187. $m->connect(
  1188. ':nickname',
  1189. ['action' => 'showstream'],
  1190. ['nickname' => Nickname::DISPLAY_FMT]
  1191. );
  1192. $m->connect(
  1193. ':nickname/',
  1194. ['action' => 'showstream'],
  1195. ['nickname' => Nickname::DISPLAY_FMT]
  1196. );
  1197. // AtomPub API
  1198. $m->connect(
  1199. 'api/statusnet/app/service/:id.xml',
  1200. ['action' => 'ApiAtomService'],
  1201. ['id' => Nickname::DISPLAY_FMT]
  1202. );
  1203. $m->connect(
  1204. 'api/statusnet/app/service.xml',
  1205. ['action' => 'ApiAtomService']
  1206. );
  1207. $m->connect(
  1208. 'api/statusnet/app/subscriptions/:subscriber/:subscribed.atom',
  1209. ['action' => 'AtomPubShowSubscription'],
  1210. ['subscriber' => '[0-9]+',
  1211. 'subscribed' => '[0-9]+']
  1212. );
  1213. $m->connect(
  1214. 'api/statusnet/app/subscriptions/:subscriber.atom',
  1215. ['action' => 'AtomPubSubscriptionFeed'],
  1216. ['subscriber' => '[0-9]+']
  1217. );
  1218. $m->connect(
  1219. 'api/statusnet/app/memberships/:profile/:group.atom',
  1220. ['action' => 'AtomPubShowMembership'],
  1221. ['profile' => '[0-9]+',
  1222. 'group' => '[0-9]+']
  1223. );
  1224. $m->connect(
  1225. 'api/statusnet/app/memberships/:profile.atom',
  1226. ['action' => 'AtomPubMembershipFeed'],
  1227. ['profile' => '[0-9]+']
  1228. );
  1229. // URL shortening
  1230. $m->connect(
  1231. 'url/:id',
  1232. ['action' => 'redirecturl'],
  1233. ['id' => '[0-9]+']
  1234. );
  1235. // user stuff
  1236. Event::handle('RouterInitialized', [$m]);
  1237. }
  1238. return $m;
  1239. }
  1240. public function map($path)
  1241. {
  1242. try {
  1243. return $this->m->match($path);
  1244. } catch (NoRouteMapException $e) {
  1245. common_debug($e->getMessage());
  1246. // TRANS: Client error on action trying to visit a non-existing page.
  1247. throw new ClientException(_('Page not found.'), 404);
  1248. }
  1249. }
  1250. public function build($action, $args=null, $params=null, $fragment=null)
  1251. {
  1252. $action_arg = array('action' => $action);
  1253. if ($args) {
  1254. $args = array_merge($action_arg, $args);
  1255. } else {
  1256. $args = $action_arg;
  1257. }
  1258. $url = $this->m->generate($args, $params, $fragment);
  1259. // Due to a bug in the Net_URL_Mapper code, the returned URL may
  1260. // contain a malformed query of the form ?p1=v1?p2=v2?p3=v3. We
  1261. // repair that here rather than modifying the upstream code...
  1262. $qpos = strpos($url, '?');
  1263. if ($qpos !== false) {
  1264. $url = substr($url, 0, $qpos+1) .
  1265. str_replace('?', '&', substr($url, $qpos+1));
  1266. // @fixme this is a hacky workaround for http_build_query in the
  1267. // lower-level code and bad configs that set the default separator
  1268. // to &amp; instead of &. Encoded &s in parameters will not be
  1269. // affected.
  1270. $url = substr($url, 0, $qpos+1) .
  1271. str_replace('&amp;', '&', substr($url, $qpos+1));
  1272. }
  1273. return $url;
  1274. }
  1275. }