Skip to content

Commit

Permalink
Removed REST API v1, closes #1617
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Feb 16, 2020
1 parent 8510b54 commit 1e4a851
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 247 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This is a log of major user-visible changes in each phpMyFAQ release.
Version 3.1.0-dev
- changed PHP requirement to PHP 7.3+ (Thorsten)
- added support for Elasticsearch v6+ (Thorsten)
- removed REST API v1 (Thorsten)

Version 3.0.0 - 2020-02-16
- changed PHP requirement to PHP 7.2+ (Thorsten)
Expand Down
24 changes: 0 additions & 24 deletions nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -116,30 +116,6 @@ server {
# * http://[...]/tags/<ID>/<HEADER>.htm
rewrite tags/([0-9]+)/([^\/]+).htm(l?)$ /index.php?action=search&tagging_id=$1 last;


# REST/JSON API v1
# * http://[...]/api/<ACTION>/<LANGUAGE CODE>/<...>
# @deprecated These APIs will be removed in phpMyFAQ 3.1
rewrite api/getVersion /api.php?action=getVersion last;
rewrite api/getApiVersion /api.php?action=getApiVersion last;
rewrite api/getCount /api.php?action=getCount last;
rewrite api/getDefaultLanguage /api.php?action=getDefaultLanguage last;
rewrite api/search/([a-z\-]+)/([a-z\-]+)$ /api.php?action=search&lang=$1&q=$2 last;
rewrite api/getCategories/([a-z\-]+) /api.php?action=getCategories&lang=$1 last;
rewrite api/getFaqs/([a-z\-]+)/([0-9]+) /api.php?action=getFaqs&lang=$1&categoryId=$2 last;
rewrite api/getFaq/([a-z\-]+)/([0-9]+) /api.php?action=getFaq&lang=$1&recordId=$2 last;
rewrite api/getComments/([0-9]+) /api.php?action=getComments&recordId=$1 last;
rewrite api/getAllFaqs/([a-z\-]+)/ /api.php?action=getAllFaqs&lang=$1 last;
rewrite api/getFaqAsPdf/([a-z\-]+)/([0-9]+)/([0-9]+) /api.php?action=getFaq&lang=$1&categoryId=$2&recordId=$3 last;
rewrite api/getAttachmentsFromFaq/([a-z\-]+)/([0-9]+) /api.php?action=getAttachmentsFromFaq&lang=$1&recordId=$2 last;
rewrite api/getPopular/([a-z\-]+) /api.php?action=getPopular&lang=$1 last;
rewrite api/getLatest/([a-z\-]+) /api.php?action=getLatest&lang=$1 last;
rewrite api/getNews/([a-z\-]+) /api.php?action=getNews&lang=$1 last;
rewrite api/getPopularSearches/([a-z\-]+) /api.php?action=getPopularSearches&lang=$1 last;
rewrite api/getPopularTags /api.php?action=getPopularTags last;
rewrite api/getFAQsByTag/([a-z\-]+)/([0-9]+) /api.php?action=getFAQsByTag&lang=$1&tagId=$2 last;
rewrite api/login /api.php?action=login last;

# REST API v2.0
# * http://[...]/api/v2.0/<ACTION>
rewrite api/v2.0/version /api.php?action=version last;
Expand Down
23 changes: 0 additions & 23 deletions phpmyfaq/.htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -125,29 +125,6 @@ RewriteRule tags/([0-9]+)/([0-9]+)/(.+)\.htm(l?)$ index.php?action=search&tagg
# * http://[...]/tags/<ID>/<HEADER>.htm
RewriteRule tags/([0-9]+)/([^\/]+)\.htm(l?)$ index.php?action=search&tagging_id=$1 [L,QSA]

# REST/JSON API v1
# * http://[...]/api/<ACTION>/<LANGUAGE CODE>/<...>
# @deprecated These APIs will be removed in phpMyFAQ 3.1
RewriteRule api/getVersion api.php?action=getVersion [L,QSA]
RewriteRule api/getApiVersion api.php?action=getApiVersion [L,QSA]
RewriteRule api/getCount api.php?action=getCount [L,QSA]
RewriteRule api/getDefaultLanguage api.php?action=getDefaultLanguage [L,QSA]
RewriteRule api/search/([a-z\-]+)/([a-z\-]+)$ api.php?action=search&lang=$1&q=$2 [L,QSA]
RewriteRule api/getCategories/([a-z\-]+) api.php?action=getCategories&lang=$1 [L,QSA]
RewriteRule api/getFaqs/([a-z\-]+)/([0-9]+) api.php?action=getFaqs&lang=$1&categoryId=$2 [L,QSA]
RewriteRule api/getFaq/([a-z\-]+)/([0-9]+) api.php?action=getFaq&lang=$1&recordId=$2 [L,QSA]
RewriteRule api/getComments/([0-9]+) api.php?action=getComments&recordId=$1 [L,QSA]
RewriteRule api/getAllFaqs/([a-z\-]+) api.php?action=getAllFaqs&lang=$1 [L,QSA]
RewriteRule api/getFaqAsPdf/([a-z\-]+)/([0-9]+)/([0-9]+) api.php?action=getFaqAsPdf&lang=$1&categoryId=$2&recordId=$3 [L,QSA]
RewriteRule api/getAttachmentsFromFaq/([a-z\-]+)/([0-9]+) api.php?action=getAttachmentsFromFaq&lang=$1&recordId=$2 [L,QSA]
RewriteRule api/getPopular/([a-z\-]+) api.php?action=getPopular&lang=$1 [L,QSA]
RewriteRule api/getLatest/([a-z\-]+) api.php?action=getLatest&lang=$1 [L,QSA]
RewriteRule api/getNews/([a-z\-]+) api.php?action=getNews&lang=$1 [L,QSA]
RewriteRule api/getPopularSearches/([a-z\-]+) api.php?action=getPopularSearches&lang=$1 [L,QSA]
RewriteRule api/getPopularTags api.php?action=getPopularTags [L,QSA]
RewriteRule api/getFAQsByTag/([a-z\-]+)/([0-9]+) api.php?action=getFAQsByTag&lang=$1&tagId=$2 [L,QSA]
RewriteRule api/login api.php?action=login [L,QSA]

# REST API v2.0
# * http://[...]/api/v2.0/<ACTION>
RewriteRule api/v2.0/version api.php?action=version [L,QSA]
Expand Down
147 changes: 1 addition & 146 deletions phpmyfaq/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,153 +126,8 @@
// Handle actions
//
switch ($action) {

//
// v1 - @deprecated These APIs will be removed in phpMyFAQ 3.1
//
case 'getVersion':
// @deprecated This API will be removed in phpMyFAQ 3.1
$result = ['version' => $faqConfig->get('main.currentVersion')];
break;

case 'getApiVersion':
// @deprecated This API will be removed in phpMyFAQ 3.1
$result = ['apiVersion' => $faqConfig->get('main.currentApiVersion')];
break;

case 'getCount':
// @deprecated This API will be removed in phpMyFAQ 3.1
$faq = new Faq($faqConfig);
$faq->setUser($currentUser);
$faq->setGroups($currentGroups);
$result = ['faqCount' => $faq->getNumberOfRecords($currentLanguage)];
break;

case 'getDefaultLanguage':
// @deprecated This API will be removed in phpMyFAQ 3.1
$result = ['defaultLanguage' => $faqConfig->getLanguage()->getLanguage()];
break;

case 'getCategories':
// @deprecated This API will be removed in phpMyFAQ 3.1
$category = new Category($faqConfig, $currentGroups, true);
$category->setUser($currentUser);
$category->setGroups($currentGroups);
$result = array_values($category->getAllCategories());
break;

case 'getPopularTags':
// @deprecated This API will be removed in phpMyFAQ 3.1
$tags = new Tags($faqConfig);
$result = $tags->getPopularTagsAsArray(16);
break;

case 'getPopularSearches':
// @deprecated This API will be removed in phpMyFAQ 3.1
$search = new Search($faqConfig);
$result = $search->getMostPopularSearches(7, true);
break;

case 'getComments':
// @deprecated This API will be removed in phpMyFAQ 3.1
$comment = new Comments($faqConfig);
$result = $comment->getCommentsData($recordId, 'faq');
break;

case 'getAttachmentsFromFaq':
// @deprecated This API will be removed in phpMyFAQ 3.1
$attachments = [];
try {
$attachments = AttachmentFactory::fetchByRecordId($faqConfig, $recordId);
} catch (AttachmentException $e) {
$result = ['error' => $e->getMessage()];
}
foreach ($attachments as $attachment) {
$result[] = [
'filename' => $attachment->getFilename(),
'url' => $faqConfig->getDefaultUrl() . $attachment->buildUrl(),
];
}
break;

case 'getNews':
// @deprecated This API will be removed in phpMyFAQ 3.1
$news = new News($faqConfig);
$result = $news->getLatestData(false, true, true);
break;

case 'getFaqs':
// @deprecated This API will be removed in phpMyFAQ 3.1
$faq = new Faq($faqConfig);
$faq->setUser($currentUser);
$faq->setGroups($currentGroups);
try {
$result = $faq->getAllRecordPerCategory($categoryId);
} catch (Exception $e) {
// @todo Handle exception
}
break;

case 'getAllFaqs':
// @deprecated This API will be removed in phpMyFAQ 3.1
$faq = new Faq($faqConfig);
$faq->setUser($currentUser);
$faq->setGroups($currentGroups);
$faq->getAllRecords(FAQ_SORTING_TYPE_CATID_FAQID, ['lang' => $currentLanguage]);
$result = $faq->faqRecords;
break;

case 'getPopular':
// @deprecated This API will be removed in phpMyFAQ 3.1
$faq = new Faq($faqConfig);
$faq->setUser($currentUser);
$faq->setGroups($currentGroups);
$result = array_values($faq->getTopTenData(PMF_NUMBER_RECORDS_TOPTEN));
break;

case 'getLatest':
// @deprecated This API will be removed in phpMyFAQ 3.1
$faq = new Faq($faqConfig);
$faq->setUser($currentUser);
$faq->setGroups($currentGroups);
$result = array_values($faq->getLatestData(PMF_NUMBER_RECORDS_LATEST));
break;

case 'getFaq':
// @deprecated This API will be removed in phpMyFAQ 3.1
$faq = new Faq($faqConfig);
$faq->setUser($currentUser);
$faq->setGroups($currentGroups);
$faq->getRecord($recordId);
$result = $faq->faqRecord;
break;

case 'getFAQsByTag':
// @deprecated This API will be removed in phpMyFAQ 3.1
$tags = new Tags($faqConfig);
$recordIds = $tags->getFaqsByTagId($tagId);
$faq = new Faq($faqConfig);
$faq->setUser($currentUser);
$faq->setGroups($currentGroups);
try {
$result = $faq->getRecordsByIds($recordIds);
} catch (Exception $e) {
// @todo Handle exception
}
break;

case 'getFaqAsPdf':
// @deprecated This API will be removed in phpMyFAQ 3.1
$service = new Services($faqConfig);
$service->setFaqId($recordId);
$service->setLanguage($currentLanguage);
$service->setCategoryId($categoryId);

$result = ['pdfUrl' => $service->getPdfApiLink()];
break;

//
// v2
// v2.0
//
case 'version':
$result = $faqConfig->get('main.currentVersion');
Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/src/phpMyFAQ/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class System
/**
* API version.
*/
private const VERSION_API = '2.0';
private const VERSION_API = '2.1';

/**
* Minimum required PHP version.
Expand Down
83 changes: 30 additions & 53 deletions web.config
Original file line number Diff line number Diff line change
Expand Up @@ -129,104 +129,81 @@
<action type="Rewrite" url="/phpmyfaq/index.php?action=instantresponse" appendQueryString="true"/>
</rule>
<!--
# REST/JSON API v1
# * http://[...]/api/<ACTION>/<LANGUAGE CODE>/<...>
# REST API v2.0
# * http://[...]/api/v2.0/<ACTION>
-->
<rule name="rule 27L" stopProcessing="true">
<match url="phpmyfaq/api/getVersion"/>
<action type="Rewrite" url="/phpmyfaq/api.php?action=getVersion" appendQueryString="true"/>
</rule>
<rule name="rule 28L" stopProcessing="true">
<match url="phpmyfaq/api/getApiVersion"/>
<action type="Rewrite" url="/phpmyfaq/api.php?action=getApiVersion" appendQueryString="true"/>
<match url="phpmfaq/api/v2.0/version"/>
<action type="Rewrite" url="/phpmyfaq/api.php?action=version" appendQueryString="true"/>
</rule>
<rule name="rule 29L" stopProcessing="true">
<match url="phpmyfaq/api/search/([a-z\-]+)/([a-z\-]+)$"/>
<action type="Rewrite" url="/phpmyfaq/api.php?action=search&amp;lang={R:1}&amp;q={R:2}"
<match url="phpmfaq/api/v2.0/search"/>
<action type="Rewrite" url="/phpmyfaq/api.php?action=search"
appendQueryString="true"/>
</rule>
<rule name="rule 30L" stopProcessing="true">
<match url="phpmyfaq/api/getCategories/([a-z\-]+)"/>
<action type="Rewrite" url="/phpmyfaq/api.php?action=getCategories&amp;lang={R:1}" appendQueryString="true"/>
<match url="phpmfaq/api/v2.0/categories"/>
<action type="Rewrite" url="/phpmyfaq/api.php?action=categories" appendQueryString="true"/>
</rule>
<rule name="rule 31L" stopProcessing="true">
<match url="phpmyfaq/api/getFaqs/([a-z\-]+)/([0-9]+)"/>
<action type="Rewrite" url="/phpmyfaq/api.php?action=getFaqs&amp;lang={R:1}&amp;categoryId={R:2}"
<match url="phpmfaq/api/v2.0/faqs/([0-9]+)"/>
<action type="Rewrite" url="/phpmyfaq/api.php?action=faqs&amp;categoryId={R:1}"
appendQueryString="true"/>
</rule>
<rule name="rule 32L" stopProcessing="true">
<match url="phpmyfaq/api/getFaq/([a-z\-]+)/([0-9]+)"/>
<action type="Rewrite" url="/phpmyfaq/api.php?action=getFaq&amp;lang={R:1}&amp;recordId={R:2}"
<match url="phpmfaq/api/v2.0/faq/([0-9]+)/([0-9]+)"/>
<action type="Rewrite" url="/phpmyfaq/api.php?action=faq&amp;categoryId={R:1}&amp;recordId={R:2}"
appendQueryString="true"/>
</rule>
<rule name="rule 33L" stopProcessing="true">
<match url="phpmyfaq/api/getCount"/>
<action type="Rewrite" url="/phpmyfaq/api.php?action=getCount" appendQueryString="true"/>
</rule>
<rule name="rule 34L" stopProcessing="true">
<match url="phpmyfaq/api/getDefaultLanguage"/>
<action type="Rewrite" url="/phpmyfaq/api.php?action=getDefaultLanguage" appendQueryString="true"/>
</rule>
<rule name="rule 35L" stopProcessing="true">
<match url="phpmyfaq/api/getAttachmentsFromFaq/([a-z\-]+)/([0-9]+)"/>
<action type="Rewrite" url="/phpmyfaq/api.php?action=getAttachmentsFromFaq&amp;lang={R:1}&amp;recordId={R:2}"
appendQueryString="true"/>
</rule>
<rule name="rule 36L" stopProcessing="true">
<match url="phpmyfaq/api/getFaqAsPdf/([a-z\-]+)/([0-9]+)/([0-9]+)"/>
<action type="Rewrite" url="/phpmyfaq/api.php?action=getFaqAsPdf&amp;lang={R:1}&amp;categoryId={R:2}&amp;recordId={R:3}"
<match url="phpmfaq/api/v2.0/attachments/([0-9]+)"/>
<action type="Rewrite" url="/phpmyfaq/api.php?action=attachments&amp;recordId={R:1}"
appendQueryString="true"/>
</rule>
<rule name="rule 37L" stopProcessing="true">
<match url="phpmyfaq/api/getPopular/([a-z\-]+)"/>
<action type="Rewrite" url="/phpmyfaq/api.php?action=getPopular&amp;lang={R:1}" appendQueryString="true"/>
<match url="phpmfaq/api/v2.0/faqs/popular"/>
<action type="Rewrite" url="/phpmyfaq/api.php?action=faqs&amp;filter=popular" appendQueryString="true"/>
</rule>
<rule name="rule 38L" stopProcessing="true">
<match url="phpmyfaq/api/getLatest/([a-z\-]+)"/>
<action type="Rewrite" url="/phpmyfaq/api.php?action=getLatest&amp;lang={R:1}" appendQueryString="true"/>
<match url="phpmfaq/api/v2.0/faqs/latest"/>
<action type="Rewrite" url="/phpmyfaq/api.php?action=faqs&amp;filter=latest" appendQueryString="true"/>
</rule>
<rule name="rule 39L" stopProcessing="true">
<match url="phpmyfaq/api/getNews/([a-z\-]+)"/>
<action type="Rewrite" url="/phpmyfaq/api.php?action=getNews&amp;lang={R:1}"
appendQueryString="true"/>
<match url="phpmfaq/api/v2.0/news"/>
<action type="Rewrite" url="/phpmyfaq/api.php?action=news" appendQueryString="true"/>
</rule>
<rule name="rule 40L" stopProcessing="true">
<match url="phpmyfaq/api/getAllFaqs/([a-z\-]+)"/>
<action type="Rewrite" url="/phpmyfaq/api.php?action=getAllFaqs&amp;lang={R:1}"
appendQueryString="true"/>
<match url="phpmfaq/api/v2.0/faqs"/>
<action type="Rewrite" url="/phpmyfaq/api.php?action=faqs" appendQueryString="true"/>
</rule>
<rule name="rule 41L" stopProcessing="true">
<match url="phpmyfaq/api/getPopularSearches/([a-z\-]+)"/>
<action type="Rewrite" url="/phpmyfaq/api.php?action=getPopularSearches&amp;lang={R:1}"
<match url="phpmfaq/api/v2.0/faqs/popular"/>
<action type="Rewrite" url="/phpmyfaq/api.php?action=faqs&amp;filter=popular"
appendQueryString="true"/>
</rule>
<rule name="rule 42L" stopProcessing="true">
<match url="^phpmyfaq/(.*)$"/>
<action type="Rewrite" url="/phpmyfaq/index.php?action=overview" appendQueryString="true"/>
</rule>
<rule name="rule 43L" stopProcessing="true">
<match url="phpmyfaq/api/getPopularTags"/>
<action type="Rewrite" url="/phpmyfaq/api.php?action=getPopularTags"
<match url="phpmfaq/api/v2.0/tags"/>
<action type="Rewrite" url="/phpmyfaq/api.php?action=tags"
appendQueryString="true"/>
</rule>
<rule name="rule 44L" stopProcessing="true">
<match url="phpmyfaq/api/getFAQsByTag/([a-z\-]+)/([0-9]+)"/>
<action type="Rewrite" url="/phpmyfaq/api.php?action=getFAQsByTag&amp;lang={R:1}&amp;tagId={R:2}"
<match url="phpmfaq/api/v2.0faqs/tags/([0-9]+)"/>
<action type="Rewrite" url="/phpmyfaq/api.php?action=faqs&amp;tagId={R:1}"
appendQueryString="true"/>
</rule>
<rule name="rule 45L" stopProcessing="true">
<match url="phpmyfaq/api/getComments/([0-9]+)"/>
<action type="Rewrite" url="/phpmyfaq/api.php?action=getComments&amp;recordId={R:1}"
<match url="phpmfaq/api/v2.0/comments"/>
<action type="Rewrite" url="/phpmyfaq/api.php?action=comments&amp;recordId={R:1}"
appendQueryString="true"/>
</rule>
<rule name="rule 46L" stopProcessing="true">
<match url="^phpmyfaq/(.*)$"/>
<action type="Rewrite" url="/phpmyfaq/index.php?action=login" appendQueryString="true"/>
</rule>
<!--
# REST API v2.0
# * http://[...]/api/v2.0/<ACTION>
-->

</rules>
</rewrite>
Expand Down

0 comments on commit 1e4a851

Please sign in to comment.