@phenomlab Awesome, thanks!
Add PHP API
-
I need php api, and i start it make. I take library predis for it. I added class topic_add and saw how it hard ) But i think what can be variants easier. Please tell me in the right way in me?
code:
class pr{ function topic_add($title='', $content='', $category=2, $link='', $user=1){ global $trans, $redis, $char_restrict, $word_separator; // get topics and last index $m = array(); foreach ( $redis->keys('topic:*') as $v ){ $n = explode(':', $v)[1]; $m[] = $n; } sort($m); $tli = end($m)+1; // get posts and last index $m = array(); foreach ( $redis->keys('post:*') as $v ){ $n = explode(':', $v)[1]; $m[] = $n; } sort($m); $pli = end($m)+1; // vals $ut = time().'000'; $title = isset($title) && trim($title) != '' ? $title : 'ะะพะฒัะน ัะพะฟะธะบ'.$tli; $link = isset($link) && trim($link) != '' ? $trans->stripAlias($link, $char_restrict, $word_separator) : $trans->stripAlias($title, $char_restrict, $word_separator); $category = isset($category) && trim($category) != '' ? $category : 1; $content = isset($content) && trim($content) != '' ? $content : 'ะ ะฑะปะธะถะฐะนัะตะต ะฒัะตะผั ัะตะผะฐ ะพะฑัะทะฐัะตะปัะฝะพ ะฑัะดะตั ะพะฟะธัะฐะฝะฐ'; $user = isset($user) && trim($user) != '' ? $user : 1; $topics = array( tid => $tli, uid => $user, cid => $category, mainPid => $pli, title => $title, slug => $tli.'/'.$link, timestamp => $ut, lastposttime => $ut, postcount => 0, viewcount => 0, locked => 0, deleted => 0, pinned => 0 ); foreach ($topics as $k => $v) { $redis->hset('topic:'.($tli), $k, $v); } $posts = array( pid => $pli, uid => $user, tid => $tli, content => $content, timestamp => $ut, reputation => 0, votes => 0, editor => '', edited => '0', deleted => 0 ); foreach ($posts as $k => $v) { $redis->hset('post:'.($pli), $k, $v); } $redis->zadd('cid:'.$category.':tids', $ut, $tli); $redis->zadd('cid:'.$category.':pids', $ut, $pli); $redis->zadd('topics:posts', 1, $tli); $redis->zadd('topics:recent', $ut, $tli); $redis->zadd('topics:tid', $ut, $tli); } function category_get ($what=''){ } function category_add ($name='', $parent='', $link='', $class='col-md-12 col-xs-6 '){ global $trans, $redis, $char_restrict, $word_separator; // get categories and last index $m = array(); foreach ( $redis->keys('category:*') as $v ){ $n = explode(':', $v)[1]; $m[] = $n; } sort($m); $cli = end($m)+1; } } $pr = new pr;
I think it would be useful to many.
-
Need understand, which fields need to create in which areas of the database. Is there somewhere in the documentation on this subject?
-
@sergej-saveljev Don't bother, use this write api instead
Let me know what endpoints you need.
-
Cool! I certainly reading!
Until I not find how to create categories.Is it possible to make the url topics were not in the form id categories? To use the category names. To make them more friendly for search systems.
-
I need it class methods for create complex structure, based on the data site.
Categories are highway subcategories are villages in which users of the forum will create your own posts. That is the work of the categories is particularly important.
-
@julian link in github readme https://community.nodebb.org/api/topic/687/help-translate-nodebb/2 not work
-
The write API is useful if you don't want to have to interact with redis directly (especially if the schema of NodeBB changes).
-
@julian Is it possible now with the API to create a category?
-
Im sorry i cried a little when i saw the request PHP in NodeBB
-
@xCausxn LOL
@sergej-saveljev Yes, I can add that in today.
-
-
-
v1.0.2 of the write-api exposes the new routes, but it requires the latest commit from NodeBB.
-
Thanks! But i have problems. I not understand how run curl command. Please, tell me how you would use them. Run in linux terminal:
curl -H "Authorization: Bearer {fb66eb42-8206-475e-fsdg-7ddabde551e5}" --data "title={Test post}&content=={Content test post}&cid={1}" http://localhost:4567/api/v1/topics
Output:
Forbidden
-
In top code hidden {2} in value cid. Markdown is hiding.
-
- No curly braces.
- Encode your post body data
curl -H "Authorization: Bearer fb66eb42-8206-475e-fsdg-7ddabde551e5" --data "title=Test%20post&content=Content%20test%20post&cid=1" http://localhost:4567/api/v1/topics
-
@julian said:
- No curly braces.
- Encode your post body data
curl -H "Authorization: Bearer fb66eb42-8206-475e-fsdg-7ddabde551e5" --data "title=Test%20post&content=Content%20test%20post&cid=1" http://localhost:4567/api/v1/topics
Forbidden
-
I tried user token and master token
-
What version of NodeBB?
-