mirror of
https://github.com/Relintai/wp_saver_rcpp_fw.git
synced 2024-11-14 04:57:23 +01:00
Blog entry view.
This commit is contained in:
parent
0f28f3bb22
commit
0b08069895
@ -83,7 +83,22 @@ void WPApplication::blog(Request *request) {
|
|||||||
|
|
||||||
page = request->get_current_path_segment().to_int();
|
page = request->get_current_path_segment().to_int();
|
||||||
} else if (action_segment == "post") {
|
} else if (action_segment == "post") {
|
||||||
request->body += "test blog post";
|
request->push_path();
|
||||||
|
|
||||||
|
int post_id = request->get_current_path_segment().to_int();
|
||||||
|
|
||||||
|
PostData *p = get_post(db, post_id);
|
||||||
|
|
||||||
|
if (!p) {
|
||||||
|
request->send_error(404);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
b.div("content");
|
||||||
|
b.div("blog_content")->f()->w(p->data)->cdiv();
|
||||||
|
b.cdiv();
|
||||||
|
|
||||||
|
request->body += b.result;
|
||||||
request->compile_and_send_body();
|
request->compile_and_send_body();
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
@ -109,8 +124,8 @@ void WPApplication::blog(Request *request) {
|
|||||||
PostData *p = posts[i];
|
PostData *p = posts[i];
|
||||||
|
|
||||||
b.div("blog_content_row");
|
b.div("blog_content_row");
|
||||||
b.div("blog_entry_link")->f()->fa(request->get_url_root_current() + "post/" + String::num(p->id), "Open")->cdiv();
|
b.div("blog_entry_link")->f()->fa("/blog/" + blog + "/post/" + String::num(p->id), "Open")->cdiv();
|
||||||
b.w(p->data);
|
b.div("blog_content")->f()->w(p->data)->cdiv();
|
||||||
b.cdiv();
|
b.cdiv();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -159,6 +174,25 @@ int WPApplication::get_post_count(Database *db) {
|
|||||||
return res->get_cell_int(0);
|
return res->get_cell_int(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WPApplication::PostData *WPApplication::get_post(Database *db, const int id) {
|
||||||
|
Ref<QueryBuilder> qb = db->get_query_builder();
|
||||||
|
|
||||||
|
qb->select("id,url,extracted_data")->from("data")->where()->wp("id", id)->end_command();
|
||||||
|
Ref<QueryResult> res = qb->run();
|
||||||
|
|
||||||
|
if (!res->next_row()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
PostData *p = new PostData();
|
||||||
|
|
||||||
|
p->id = res->get_cell_int(0);
|
||||||
|
p->url = res->get_cell(1);
|
||||||
|
p->data = res->get_cell(2);
|
||||||
|
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
void WPApplication::routing_middleware(Object *instance, Request *request) {
|
void WPApplication::routing_middleware(Object *instance, Request *request) {
|
||||||
String path = request->get_path_full();
|
String path = request->get_path_full();
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
Vector<PostData *> get_posts(Database *db, const int page, const int num_per_page = 5);
|
Vector<PostData *> get_posts(Database *db, const int page, const int num_per_page = 5);
|
||||||
|
PostData * get_post(Database *db, const int id);
|
||||||
int get_post_count(Database *db);
|
int get_post_count(Database *db);
|
||||||
|
|
||||||
static void routing_middleware(Object *instance, Request *request);
|
static void routing_middleware(Object *instance, Request *request);
|
||||||
|
Loading…
Reference in New Issue
Block a user