Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XenForo 2 #40

Open
wants to merge 262 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
262 commits
Select commit Hold shift + click to select a range
09fd984
Fix conflict with boardUrlCanonical option
daohoangson May 30, 2018
f629608
Improve custom field / definition transformation
daohoangson May 30, 2018
12b5ea2
Fix bug assertCanonicalUrl does not work
daohoangson Jun 7, 2018
81c26e3
Implement GET `/users/me`
daohoangson Jun 7, 2018
f75fd59
Add support for not found message in transform handlers
daohoangson Jun 7, 2018
7803c4a
Add add-on version check
daohoangson Jun 7, 2018
9105574
Simplify dispatcher, improve rendering of XF\ControllerPlugin\Error r…
daohoangson Jun 7, 2018
1d9d672
Fix bug grant_type=password: invalid password gets token with user_id=0
daohoangson Jun 7, 2018
a62539f
Use phrases for OAuth2 errors
daohoangson Jun 7, 2018
d395652
Update DevHelper
daohoangson Jul 9, 2018
cac954d
Simplify Param implementation
daohoangson Jul 10, 2018
6e9b5e4
Remove Xfrocks\Api\Controller\AbstractController::param()
daohoangson Jul 10, 2018
9645081
Add api /threads and /posts (#49)
luutruong Jul 10, 2018
cd516e6
Re-organize controllers
daohoangson Jul 10, 2018
f17ab02
Re-organize transformers
daohoangson Jul 10, 2018
461a21c
Fix bug GET /posts?thread_id
daohoangson Jul 10, 2018
2611c9d
Improvement api get /posts
luutruong Jul 10, 2018
8414ee2
Merge pull request #51 from luutruong/xenforo-2
daohoangson Jul 11, 2018
8103931
Add api /search
luutruong Jul 11, 2018
32d354d
Ignore composer.lock
luutruong Jul 11, 2018
e03f89e
Implement \JsonSerializable interface.
luutruong Jul 11, 2018
3109e6c
Add new toArray() method.
luutruong Jul 11, 2018
5ca01c8
Do not append action with reroute action.
luutruong Jul 11, 2018
726af9c
Search threads
luutruong Jul 11, 2018
ec97c7e
Add link data to pageNav
luutruong Jul 11, 2018
538195e
Add api /search/posts
luutruong Jul 11, 2018
2fbfa97
Fixed search with forum_id not work.
luutruong Jul 11, 2018
25c314f
Fixed query with thread_id not working
luutruong Jul 11, 2018
878ef36
Coding convention
luutruong Jul 11, 2018
9d23b91
Remove unused import
luutruong Jul 11, 2018
7a877fc
Include composer.lock
luutruong Jul 12, 2018
d152fd7
Improvement get $page, $perPage
luutruong Jul 12, 2018
0d2c406
Improvement reroute params
luutruong Jul 12, 2018
0ef1bde
Fixed invalid conditional.
luutruong Jul 12, 2018
456b185
Switch batchJob to search handler.
luutruong Jul 12, 2018
9e80ae3
Coding convention
luutruong Jul 12, 2018
8a490ef
Make Xfrocks\Api\Transform\AbstractHandler stateless
daohoangson Jul 12, 2018
babdfa4
Remove support pageNav for search/threads, search/posts
luutruong Jul 13, 2018
6f906c0
Add missing phrase.
luutruong Jul 13, 2018
3a8b2e9
Improvement prepare data for search
luutruong Jul 13, 2018
7eff793
Coding convention
luutruong Jul 13, 2018
4126186
Re-order method.
luutruong Jul 13, 2018
17e548b
Improvement description.
luutruong Jul 13, 2018
4e277bf
Remove unneccessary method
luutruong Jul 13, 2018
19afc8a
Improvement map data.
luutruong Jul 13, 2018
f462ade
Add api /forums
luutruong Jul 13, 2018
f5b79a3
Fixed invalid route build
luutruong Jul 13, 2018
f0274a3
Added api `/forums/:forumId`
luutruong Jul 13, 2018
f8ff0f6
Add api `/categories`
luutruong Jul 13, 2018
7d811e1
Coding convention
luutruong Jul 13, 2018
93a421f
Remove transform entities methods to avoid array of unrelated entities
daohoangson Jul 13, 2018
6d70ff9
Restructure TransformContext + remove selector name support
daohoangson Jul 13, 2018
317c7c9
Merge pull request #56 from xfrocks/transform_context
daohoangson Jul 13, 2018
8bd0426
Merge pull request #52 from luutruong/xenforo2_api_search
daohoangson Jul 13, 2018
8a9a931
Merge pull request #55 from luutruong/xenforo2_api_forums
daohoangson Jul 13, 2018
9ac0f80
Apply transformer $with at entity manager getFinder() directly
daohoangson Jul 14, 2018
4259404
Fix incompatibility for forum/category transformers.
daohoangson Jul 14, 2018
fc2d7af
Update DevHelper (phpstan)
daohoangson Jul 16, 2018
62ea4f2
Include custon fields into api `/threads`
luutruong Jul 17, 2018
35c361c
Merge pull request #58 from luutruong/xenforo2_api_thread_fields
daohoangson Jul 17, 2018
f0d1657
Xenforo2 api conversations (#59)
luutruong Jul 18, 2018
734ec5d
Use token from query for all requests
daohoangson Jul 18, 2018
c945ad0
Use the same request parsing logic for api server and xf app
daohoangson Jul 19, 2018
b07f977
Cannot view conversation in API
luutruong Jul 19, 2018
39f4567
Merge pull request #61 from luutruong/xenforo2_cannot_view_convo
daohoangson Jul 19, 2018
1e4bd73
Fix bug batch does not transform reply
daohoangson Aug 1, 2018
407ef5a
Xf2 api threads (#62)
luutruong Aug 2, 2018
435b557
Xf2 api users (#63)
luutruong Aug 10, 2018
f921368
Fix password_algo support for POST oauth/token
daohoangson Aug 10, 2018
c97b2f2
Add scope default for POST oauth/token with grant_type password
daohoangson Aug 10, 2018
d1f4aee
Implement POST tools/link
daohoangson Aug 16, 2018
7d84dc6
Implement one time token
daohoangson Aug 16, 2018
199609d
Fix scope for guest ott
daohoangson Aug 17, 2018
fe093c9
Fix batch job reply transformation
daohoangson Aug 17, 2018
921daff
Restore `scope` data in oauth/token response for legacy support
daohoangson Aug 17, 2018
f30f855
Xf2 fix upload attachment (#65)
luutruong Aug 17, 2018
cfc98cf
Merge commit '921daff83df421574bb8fc89c8c505ec9990d528' into xenforo2
daohoangson Aug 17, 2018
4ea41bb
Fix wrong context (#66)
luutruong Aug 18, 2018
19d6e39
Legacy support (#67)
daohoangson Aug 18, 2018
af88878
v2.0.0 Alpha 4 -- version bump
daohoangson Aug 18, 2018
a31fbda
Add gitlab-ci (mirror at https://gitlab.com/xfrocks/bdApi)
daohoangson Aug 19, 2018
dcb164a
Use Guzzle 5 (bundled with XF2)
daohoangson Aug 20, 2018
e39f55a
Xf2 api threads fix attachments (#68)
luutruong Aug 21, 2018
9932ad6
Add params testing
daohoangson Aug 21, 2018
84da3e1
Fix gitlab-ci
daohoangson Aug 21, 2018
557c089
Xf2 api posts (#69)
luutruong Aug 21, 2018
e3c5e30
Reimplement `newAccessToken`
daohoangson Aug 22, 2018
2b47b54
Improve batch job reply transform.
daohoangson Aug 23, 2018
6489600
Implement users/:userId/default-avatar
daohoangson Aug 23, 2018
01599bb
XF2 API (#70)
luutruong Aug 24, 2018
cd222f0
Fix GET /attachment/:atttachmentId
daohoangson Aug 25, 2018
12365db
Fix GET assets/sdk on non-development server with debug mode on
daohoangson Aug 25, 2018
484a5c1
Xf2 api notifications (#72)
luutruong Aug 31, 2018
dfae68c
Added api subscriptions
luutruong Sep 3, 2018
330443e
Update response method
luutruong Sep 3, 2018
b4f4fde
Added subscription callback for notifications
luutruong Sep 3, 2018
b30d6e6
Update option
luutruong Sep 3, 2018
9a7ea21
Added phrases
luutruong Sep 3, 2018
fd12344
Fixed some bugs
luutruong Sep 4, 2018
7f48964
Fixed run ping notification
luutruong Sep 4, 2018
3e5a531
Remove unused code block
luutruong Sep 4, 2018
a640eae
Ping subscription
luutruong Sep 4, 2018
250dc58
Fix for ping queue job
daohoangson Sep 4, 2018
7b66cb1
Merge pull request #1 from xfrocks/fix/ping_queue_job
luutruong Sep 4, 2018
2d4b9c1
Move event listeners to class extensions
luutruong Sep 5, 2018
f6d57fe
Improvement 20180906 (#74)
daohoangson Sep 6, 2018
1cea239
Improvement notification load data
luutruong Sep 7, 2018
bcd4e60
Fixed load invalid column
luutruong Sep 7, 2018
e7df9af
Safe register column and improvement invoke repo
luutruong Sep 7, 2018
15df0fd
Remove pingQueueDefer option
luutruong Sep 7, 2018
b871731
Merge remote-tracking branch 'upstream/xenforo2' into xf2_api_subscri…
luutruong Sep 7, 2018
25cdab9
Improve performance for `actionSingle`s
daohoangson Sep 7, 2018
1a7843d
Enable subscriptions for tests
daohoangson Sep 7, 2018
afc298a
Workaround for non-empty default subscription column name
daohoangson Sep 7, 2018
685011d
Fix api test json file path
daohoangson Sep 7, 2018
2199beb
Remove default value
luutruong Sep 7, 2018
f8631a8
Remove verify callback for option bdApi_userNotificationConversation
luutruong Sep 7, 2018
a2a28c2
Coding convention
luutruong Sep 7, 2018
02a0046
Xf2 api subscriptions (#73)
daohoangson Sep 7, 2018
abd9587
v2.0.0 Alpha 5 -- version bump
daohoangson Sep 7, 2018
fa62a86
Added missing canView methods (#75)
luutruong Sep 8, 2018
1012941
Complete all api (#76)
luutruong Sep 14, 2018
c9f5124
Make use of DevHelper's new config `addon_ids_auto_enable`
daohoangson Sep 15, 2018
74caa5a
Implement workaround for unzip warning: stripped absolute path spec …
daohoangson Sep 15, 2018
2a637fd
Include user_id in token response
daohoangson Sep 17, 2018
50857bd
Xf2 api phptestunit (#77)
luutruong Sep 18, 2018
ea718d5
Xf2 admin (#78)
luutruong Sep 23, 2018
be93fa8
Generate refresh token for POST /users
daohoangson Sep 24, 2018
9abf292
Update DevHelper (autogen@2018092102)
daohoangson Sep 24, 2018
9423cb5
Xf2 bug api (#79)
luutruong Sep 24, 2018
989b60c
Fix refresh token for POST /users
daohoangson Sep 25, 2018
bda27a0
Generate refresh token for POST /oauth/token/facebook
daohoangson Sep 25, 2018
295ad9f
Fix bug attachment uploading does not return data
daohoangson Sep 25, 2018
908deba
Split add-on and tests dependencies
daohoangson Sep 25, 2018
fbc47cb
Fix CI
daohoangson Sep 25, 2018
a976427
Fix bug DELETE /attachments/:id
daohoangson Sep 25, 2018
842911e
Detect PUT /threads/:id and use appropriate attachment content data
daohoangson Sep 25, 2018
6c64cb0
Xf2 api user report (#80)
luutruong Sep 26, 2018
775fb3c
Fix CI test job: add api test user with bypass flood check permission
daohoangson Sep 26, 2018
15d3957
Change PUT `/threads/:id` to return thread data instead of post's
daohoangson Sep 26, 2018
71f52d6
Implement POST /tools/crypt for testing
daohoangson Sep 26, 2018
56ad71f
Support TFA (#81)
luutruong Sep 27, 2018
0c3b290
Subscription link bug (#82)
luutruong Oct 1, 2018
379039b
Improve data handling on user deletion
daohoangson Oct 1, 2018
e5db0ee
Improve AdminCP UI consistency
daohoangson Oct 1, 2018
f6e6d54
Fix bug ott for guest with invalid client_id may cause exception
daohoangson Oct 1, 2018
763ab75
Xf2 client delete clean (#84)
luutruong Oct 1, 2018
238aec5
Use api link for attachment data
daohoangson Oct 1, 2018
eae59dc
Xf2 api log requests (#85)
luutruong Oct 2, 2018
8868523
Support conversation notification (#83)
luutruong Oct 2, 2018
cfd11dd
v2.0.0 Beta 1 -- version bump
daohoangson Oct 2, 2018
5c43003
Remove debug code (#86)
luutruong Oct 2, 2018
d4b9569
Xf2 tests ott (#87)
luutruong Oct 10, 2018
56d727c
Check attachment witdth & height then output html (#89)
luutruong Oct 12, 2018
ba68eaa
Fix bug entity not has simple ID (#90)
luutruong Oct 17, 2018
cf99309
Fixed call member function on array (#92)
luutruong Nov 16, 2018
107be9c
Fixed incompatible with lazyload add-on (#93)
luutruong Nov 16, 2018
6184658
Added user_followers_total & user_followings_total (#94)
luutruong Nov 23, 2018
deae262
Remove click to expand quote (#95)
luutruong Nov 25, 2018
9cd0424
Fix some bugs (#99)
luutruong Nov 30, 2018
e469d19
Api lost password (#101)
luutruong Nov 30, 2018
5fd015c
Add fields data in api users (#102)
luutruong Dec 6, 2018
d60ad3e
Fix bug not save fields (#103)
luutruong Dec 7, 2018
e0e29db
Bug subscriptions convo (#105)
luutruong Dec 12, 2018
9ef351d
Added missing templates (#107)
luutruong Jan 18, 2019
c86a755
Add support for config.php values
daohoangson Feb 12, 2019
07f8fdb
Update phpdoc
daohoangson Feb 12, 2019
b1b69ac
Add support for Reaction
daohoangson Feb 13, 2019
59d9930
Fix Dispatcher
daohoangson Feb 12, 2019
422d18e
Update http client usages
daohoangson Feb 13, 2019
8271f2c
Update tests for new version of GuzzleHttp
daohoangson Feb 13, 2019
dd8a5cc
Add support for XenForo 2.1 (#110)
daohoangson Feb 13, 2019
f27a2bb
v2.0.0 Beta 2 -- version bump
daohoangson Feb 13, 2019
fe9d681
Merge branch 'xenforo2' of github.com:xfrocks/bdApi into xenforo2_1_n…
daohoangson Feb 18, 2019
82b70bd
Use XfrocksApi as router type to avoid conflict with XF2.1
daohoangson Feb 18, 2019
c5ecc9b
Exclude /api/ from release hashes
daohoangson Feb 18, 2019
69a2a38
v2.0.0 Beta 3 -- version bump
daohoangson Feb 18, 2019
df5f7d1
Improvement transform node
luutruong Feb 28, 2019
49b8779
Improvement extends
luutruong Feb 28, 2019
2b4caa5
Improvement transform node (#113)
daohoangson Feb 28, 2019
f6715ec
Fixed missing call parent (#114)
luutruong Feb 28, 2019
35f9352
Improve error handling for `findAndTransformLazily`
daohoangson Mar 1, 2019
5855627
Update coding convention
daohoangson Mar 1, 2019
51ac917
Mark read conversation when request GET /conversation-messages (#116)
luutruong Mar 8, 2019
54e7534
Merge branch 'xenforo2' of github.com:xfrocks/bdApi into xenforo2_1_n…
daohoangson Mar 8, 2019
b2fecc3
Improve log data filtering
daohoangson Mar 8, 2019
7ab287f
Fix user scopes logic
daohoangson Mar 8, 2019
2fb9b6f
Improve log data filtering
daohoangson Mar 8, 2019
9cbb176
Fix user scopes logic
daohoangson Mar 8, 2019
1819ae5
v2.0.0 Beta 4 -- version bump
daohoangson Mar 8, 2019
cf1dc57
Fix missing POST /users/:id/groups entrypoint
daohoangson Mar 11, 2019
917ba7c
Fixed permission bug on GET `/users/:id/groups` (#117)
luutruong Mar 12, 2019
6e3cd7b
Update coding convention
daohoangson Mar 13, 2019
8bcf496
Fixed invalid state when admin creating user (#118)
luutruong Apr 4, 2019
080e1ca
Use VARBINARY instead of VARCHAR for db columns
daohoangson Apr 9, 2019
4d716ad
v2.0.0 Beta 5 -- version bump
daohoangson Apr 10, 2019
a05d537
Fix renderer exception being swallowed
daohoangson Jun 11, 2019
3687fcd
Merge branch 'xenforo2_1_not_backward_compatible' into xenforo2
daohoangson Jun 11, 2019
30da3da
Update addon.json to require XF 2.1.0
daohoangson Jun 11, 2019
8b6b30f
Update coding convention
daohoangson Jun 11, 2019
45f7137
Add support for XFRM resource followers
daohoangson Jun 11, 2019
0638b9b
v2.0.0 Beta 6
daohoangson Jun 11, 2019
042ec58
Fix toggle like actions
daohoangson Jul 25, 2019
05159c5
v2.0.0 Beta 7
daohoangson Jul 25, 2019
bb21dfd
Disable db transaction for logging
daohoangson Aug 15, 2019
945ead6
Adjust Attachment transform to ignore `canView` permission
daohoangson Aug 15, 2019
af1edc5
Optimize queries for viewable assertions
daohoangson Aug 15, 2019
fe4db7f
Fix bug pinging user without callbacks
daohoangson Aug 15, 2019
18fda70
Add link `followers` for thread data
daohoangson Aug 15, 2019
8f526fe
Deduplicate `actionGetLikes`
daohoangson Aug 15, 2019
60bf8d7
Xenforo2 api tags (#121)
luutruong Aug 28, 2019
14c9e11
Cli enable tagging option (#122)
luutruong Sep 17, 2019
0e10884
Implement `UserEntity.canAddApiClient()`
daohoangson Nov 25, 2019
e6daa7a
Adjust GET `/threads/new` and `/threads/recent` for response data con…
daohoangson Nov 25, 2019
d37324d
v2.0.1 Beta 1 -- version bump
daohoangson Nov 25, 2019
2bd768f
Add missing attachment fields:
daohoangson Jun 22, 2020
5c6492f
Fix attachment `src` being rendered in html
daohoangson Jun 22, 2020
e99b462
Update coding convention
daohoangson Jun 25, 2020
a0991b8
Include `forum` in thread data
daohoangson Jun 25, 2020
6a175ad
Add support for GET `/threads/:id/navigation`
daohoangson Jun 25, 2020
ba7ab82
v2.0.1 Beta 2 -- version bump
daohoangson Jun 25, 2020
0357fb5
Fix `Entity\Client::setClientOptions`
daohoangson Jun 25, 2020
40cfe3d
Update `leage/[email protected]` to fix `Authorization` header check
daohoangson Jun 25, 2020
cd228ee
Update XFRM documents (#131)
luutruong Jul 6, 2020
e3901eb
Add support for POST `/search/resources`
daohoangson Jul 2, 2020
8335d95
Include `content_type` and `content_id` in prepared search result data
daohoangson Jul 2, 2020
f0bf2c4
Remove manual extension hint for XFRM classes
daohoangson Jul 2, 2020
0257044
Add support for GET `/tools/parse-link`
daohoangson Jul 2, 2020
59f0b76
Allow POST `/search/xxx` to handle `user_id` only request
daohoangson Jul 2, 2020
18cdf95
Fix batch job exception shorts circuit the entire batch
daohoangson Jul 6, 2020
d37e898
Include stickied threads on top of the GET /threads?forum_id=xxx
daohoangson Aug 20, 2020
1a92dd3
Improve bb code attach HTML:
daohoangson Aug 20, 2020
8a2b2c7
Add support for early versions of XF2 without `thumbnail_url_full`
daohoangson Aug 20, 2020
fe749ed
Include required externals in bb code HTML
daohoangson Aug 21, 2020
8b1941f
Add support for `Api-Bb-Code-Chr` header
daohoangson Aug 21, 2020
db0fbf5
Update coding convention
daohoangson Aug 21, 2020
85f31cf
Skip CHR if html has no externals, no inline script
daohoangson Aug 22, 2020
9387f52
Fix CHR login not working
daohoangson Aug 22, 2020
4e502b3
v2.0.1 Beta 3 -- version bump
daohoangson Aug 22, 2020
39920a0
Update coding convention
daohoangson Aug 24, 2020
42ce7cc
Update incompatible with xf22
daohoangson Aug 24, 2020
6cd7c19
v2.2.0 Alpha 1 -- version bump
daohoangson Aug 24, 2020
e783a05
Initialize `api.server` early to avoid conflict with XLink add-on
daohoangson Sep 13, 2020
0dd3a07
v2.0.1 Beta 4 -- version bump
daohoangson Sep 13, 2020
be63058
Requires XF 2.1.4 for `Templater::func`.
daohoangson Sep 20, 2020
4ef2937
Merge commit 'e783a0549f8d77bf2cf6571c858d0eca6af718f4' into xenforo22
daohoangson Oct 14, 2020
93d0a9e
v2.2.0 Beta 1 -- version bump
daohoangson Oct 14, 2020
d4ba6a8
Add support for XenForo 2.2 (#141)
daohoangson Oct 14, 2020
eff9b3b
Xenforo2 user edit revoke perms (#140)
luutruong Apr 26, 2021
e098ee7
v2.2.0 Beta 2 -- version bump
daohoangson Apr 27, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add support for Api-Bb-Code-Chr header
  • Loading branch information
daohoangson committed Aug 21, 2020
commit 8b1941f0ac10f41f71e88a74d931d914e73835dd
25 changes: 25 additions & 0 deletions Controller/Tool.php
Original file line number Diff line number Diff line change
@@ -9,6 +9,31 @@

class Tool extends AbstractController
{
/**
* @return \XF\Mvc\Reply\AbstractReply|\XF\Mvc\Reply\Redirect
* @throws \XF\PrintableException
*/
public function actionGetChr()
{
$params = $this->params()
->define('html', 'str')
->define('required_externals', 'str')
->define('timestamp', 'int');
$link = $this->buildLink('misc/api-chr', null, [
'html' => $params['html'],
'required_externals' => $params['required_externals'],
'timestamp' => $params['timestamp'],
]);

if (\XF::visitor()->user_id > 0) {
/** @var Login $loginPlugin */
$loginPlugin = $this->plugin('Xfrocks\Api:Login');
return $loginPlugin->initiate('misc/api-login', $link);
}

return $this->redirect($link, '', 'permanent');
}

/**
* @return \XF\Mvc\Reply\AbstractReply|\XF\Mvc\Reply\Redirect
* @throws \XF\PrintableException
12 changes: 8 additions & 4 deletions ControllerPlugin/Login.php
Original file line number Diff line number Diff line change
@@ -13,17 +13,21 @@ class Login extends AbstractPlugin

/**
* @param string $publicLink
* @param null|string $redirectUri
* @return \XF\Mvc\Reply\AbstractReply|\XF\Mvc\Reply\Redirect
* @throws \XF\PrintableException
*/
public function initiate($publicLink)
public function initiate($publicLink, $redirectUri = null)
{
/** @var AbstractController $apiController */
$apiController = $this->controller;
$params = $apiController->params()
->define('redirect_uri', 'str', 'URI to redirect afterwards');

if ($params['redirect_uri'] === '') {
if ($redirectUri === null) {
$redirectUri = $params['redirect_uri'];
}
if ($redirectUri === '') {
return $this->noPermission();
}

@@ -34,7 +38,7 @@ public function initiate($publicLink)
}

$client = $token->Client;
if ($client === null || !$client->isValidRedirectUri($params['redirect_uri'])) {
if ($client === null || !$client->isValidRedirectUri($redirectUri)) {
return $this->noPermission();
}

@@ -45,7 +49,7 @@ public function initiate($publicLink)

$timestamp = time() + self::INITIATE_TTL;
$linkParams = array(
'_xfRedirect' => Crypt::encryptTypeOne($params['redirect_uri'], $timestamp),
'_xfRedirect' => Crypt::encryptTypeOne($redirectUri, $timestamp),
'timestamp' => $timestamp,
'user_id' => Crypt::encryptTypeOne(strval($userId), $timestamp)
);
99 changes: 97 additions & 2 deletions XF/ApiOnly/BbCode/Renderer/Html.php
Original file line number Diff line number Diff line change
@@ -2,25 +2,120 @@

namespace Xfrocks\Api\XF\ApiOnly\BbCode\Renderer;

use Xfrocks\Api\Listener;
use Xfrocks\Api\Util\Crypt;
use Xfrocks\Api\XF\ApiOnly\Template\Templater;

class Html extends XFCP_Html
{
const CHR_TTL = 86400;

/** @var null|array */
private $XfrocksApiChr = null;

public function renderAst(array $ast, \XF\BbCode\RuleSet $rules, array $options = [])
{
/** @var Templater $templater */
$templater = $this->getTemplater();
$templater->clearRequiredExternalsForApi();
$templater->requiredExternalsReset();

$rendered = parent::renderAst($ast, $rules, $options);

$requiredExternalsHtml = $templater->getRequiredExternalsAsHtmlForApi();
$requiredExternalsHtml = $templater->requiredExternalsGetHtml();
if (strlen($requiredExternalsHtml) > 0) {
$rendered = sprintf('<!--%s-->%s', $requiredExternalsHtml, $rendered);
}

return $rendered;
}

/**
* @param array $children
* @param mixed $option
* @param array $tag
* @param array $options
* @return string
* @throws \XF\PrintableException
*/
public function renderTagMedia(array $children, $option, array $tag, array $options)
{
if ($this->XfrocksApiChr === null) {
return parent::renderTagMedia($children, $option, $tag, $options);
}

/** @var Templater $templater */
$templater = $this->getTemplater();
$backup = $templater->requiredExternalsReset();

$html = parent::renderTagMedia($children, $option, $tag, $options);
$requiredExternals = $templater->requiredExternalsReset($backup);

return $this->renderXfrocksApiChr($html, $requiredExternals);
}

/**
* @param string $html
* @param array $requiredExternals
* @return string
* @throws \XF\PrintableException
*/
public function renderXfrocksApiChr($html, array $requiredExternals)
{
$requiredExternalsTrimmed = [];
foreach ($requiredExternals as $key => $value) {
if (is_array($value) && count($value) === 0) {
continue;
}
$requiredExternalsTrimmed[$key] = $value;
}

$timestamp = time() + self::CHR_TTL;
$linkParams = [
'html' => Crypt::encryptTypeOne($html, $timestamp),
'required_externals' => count($requiredExternalsTrimmed) > 0 ? Crypt::encryptTypeOne(
\GuzzleHttp\json_encode($requiredExternalsTrimmed),
$timestamp
) : null,
'timestamp' => $timestamp,
];
$templater = $this->getTemplater();
$link = $templater->fnLinkType($templater, $escape, Listener::$routerType, 'tools/chr', null, $linkParams);

$attributes = 'data-chr="true"';
$label = '';
if (preg_match('#https?://([^/]+)/#', $html, $domainMatches) === 1) {
$domain = htmlentities($domainMatches[1]);
$attributes .= sprintf(' data-chr-domain="%s"', $domain);
$label = $domain;
}
if ($label === '') {
$label = md5($html);
}

/** @noinspection HtmlUnknownAttribute, HtmlUnknownTarget */
return sprintf(
"<div class=\"XfrocksApiChr\"><a %s href=\"%s\">%s</a></div>\n",
$attributes,
htmlentities($link),
$label
);
}

public static function factory(\XF\App $app)
{
$renderer = parent::factory($app);

// get Api-Bb-Code-Chr header
$chrHeader = $app->request()->getServer('HTTP_API_BB_CODE_CHR');
if (is_string($chrHeader)) {
$parts = preg_split('/,/', $chrHeader, -1, PREG_SPLIT_NO_EMPTY);
if (is_array($parts) && count($parts) > 0) {
$renderer->XfrocksApiChr = $parts;
}
}

return $renderer;
}
}

if (false) {
94 changes: 51 additions & 43 deletions XF/ApiOnly/Template/Templater.php
Original file line number Diff line number Diff line change
@@ -6,14 +6,6 @@

class Templater extends XFCP_Templater
{
public function clearRequiredExternalsForApi()
{
$this->includeCss = [];
$this->inlineCss = [];
$this->includeJs = [];
$this->inlineJs = [];
}

/**
* @param string $username
* @return array
@@ -23,41 +15,6 @@ public function getDefaultAvatarStylingForApi($username)
return $this->getDefaultAvatarStyling($username);
}

public function getRequiredExternalsAsHtmlForApi()
{
$html = '';

$includedCss = $this->getIncludedCss();
if (count($includedCss) > 0) {
$html .= '<link rel="stylesheet" href="'
. htmlspecialchars($this->getCssLoadUrl($includedCss))
. '" />';
}

$inlineCss = $this->getInlineCss();
if (count($inlineCss) > 0) {
foreach ($inlineCss as $inline) {
$html .= "<style>$inline</style>";
}
}

$includedJs = $this->getIncludedJs();
if (count($includedJs) > 0) {
foreach ($includedJs as $js) {
$html .= '<script src="' . htmlspecialchars($js) . '"></script>';
}
}

$inlineJs = $this->getInlineJs();
if (count($inlineJs) > 0) {
foreach ($inlineJs as $inline) {
$html .= "<script>$inline</script>";
}
}

return $html;
}

public function renderTemplate($template, array $params = [], $addDefaultParams = true)
{
$output = parent::renderTemplate($template, $params, $addDefaultParams);
@@ -108,6 +65,57 @@ public function renderTemplate($template, array $params = [], $addDefaultParams
return $output;
}

private static $requiredExternalKeys = ['includeCss', 'inlineCss', 'includeJs', 'inlineJs', 'pageParams'];

public function requiredExternalsGetHtml()
{
$html = '';

$includedCss = $this->getIncludedCss();
if (count($includedCss) > 0) {
$html .= '<link rel="stylesheet" href="'
. htmlspecialchars($this->getCssLoadUrl($includedCss))
. '" />';
}

$inlineCss = $this->getInlineCss();
if (count($inlineCss) > 0) {
foreach ($inlineCss as $inline) {
$html .= "<style>$inline</style>";
}
}

$includedJs = $this->getIncludedJs();
if (count($includedJs) > 0) {
foreach ($includedJs as $js) {
$html .= '<script src="' . htmlspecialchars($js) . '"></script>';
}
}

$inlineJs = $this->getInlineJs();
if (count($inlineJs) > 0) {
foreach ($inlineJs as $inline) {
$html .= "<script>$inline</script>";
}
}

return $html;
}

public function requiredExternalsReset(array $values = null)
{
$backup = [];

foreach (self::$requiredExternalKeys as $key) {
// @phpstan-ignore-next-line
$backup[$key] = $this->$key;
// @phpstan-ignore-next-line
$this->$key = $values != null ? $values[$key] : [];
}

return $backup;
}

private static function _addDimensionsBySrc($html, $src, $height, $width)
{
if (substr_count($html, $src) !== 1) {
26 changes: 26 additions & 0 deletions XF/Pub/Controller/Misc.php
Original file line number Diff line number Diff line change
@@ -7,9 +7,35 @@
use Xfrocks\Api\Entity\Client;
use Xfrocks\Api\Listener;
use Xfrocks\Api\OAuth2\Server;
use Xfrocks\Api\Util\Crypt;

class Misc extends XFCP_Misc
{
/**
* @throws \XF\PrintableException
*/
public function actionApiChr()
{
$input = $this->filter([
'html' => 'str',
'required_externals' => 'str',
'timestamp' => 'int',
]);

$html = Crypt::decryptTypeOne($input['html'], $input['timestamp']);

$requiredExternals = [];
if (strlen($input['required_externals']) > 0) {
$requiredExternals = \GuzzleHttp\json_decode(
Crypt::decryptTypeOne($input['required_externals'], $input['timestamp']),
true
);
}

$viewParams = compact('html', 'requiredExternals');
return $this->view('Xfrocks\Api:Misc\Api\Chr', 'bdapi_misc_chr', $viewParams);
}

/**
* @return \XF\Mvc\Reply\View
* @throws \XF\Mvc\Reply\Exception
10 changes: 10 additions & 0 deletions _output/templates/_metadata.json
Original file line number Diff line number Diff line change
@@ -63,5 +63,15 @@
"version_id": 2000015,
"version_string": "2.0.0 Alpha 5",
"hash": "c8ede50f973589cb68608746320a2411"
},
"public/bdapi_misc_chr.html": {
"version_id": 2000132,
"version_string": "2.0.1 Beta 2",
"hash": "fdb22cdc038b213a303c7a835e82450e"
},
"public/bdapi_misc_chr_container.html": {
"version_id": 2000132,
"version_string": "2.0.1 Beta 2",
"hash": "59ee621597c8a9b6ff52d87b79fbb9fe"
}
}
Loading