develop core Hooks, remain hooks is defined but not develop
This commit is contained in:
+12
-5
@@ -7,6 +7,7 @@ import com.sisvietnamvn.web.domain.Page;
|
||||
import com.sisvietnamvn.web.security.AuthoritiesConstants;
|
||||
import com.sisvietnamvn.web.security.SecurityUtils;
|
||||
import com.sisvietnamvn.web.service.PageService;
|
||||
import com.sisvietnamvn.web.hook.HookManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -31,19 +32,25 @@ public class PageController {
|
||||
|
||||
private final PageService pageService;
|
||||
private final ObjectMapper objectMapper;
|
||||
private final HookManager hookManager;
|
||||
|
||||
public PageController(PageService pageService, ObjectMapper objectMapper) {
|
||||
public PageController(PageService pageService, ObjectMapper objectMapper, HookManager hookManager) {
|
||||
this.pageService = pageService;
|
||||
this.objectMapper = objectMapper;
|
||||
this.hookManager = hookManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /page/{slug} : Render a page dynamically by slug.
|
||||
*/
|
||||
@GetMapping("/page/{slug}")
|
||||
public String getPage(@PathVariable("slug") String slug, Model model) {
|
||||
LOG.debug("REST request to get public Page : {}", slug);
|
||||
return renderPage(pageService.findBySlug(slug), model);
|
||||
Page page = pageService.findBySlug(slug)
|
||||
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND));
|
||||
|
||||
// Apply WordPress-style Content Filters
|
||||
page.setTitle(hookManager.applyFilters("the_title", page.getTitle()));
|
||||
page.setContent(hookManager.applyFilters("the_content", page.getContent()));
|
||||
|
||||
return renderPage(Optional.of(page), model);
|
||||
}
|
||||
|
||||
@GetMapping("/")
|
||||
|
||||
+11
-1
@@ -3,6 +3,7 @@ package com.sisvietnamvn.web.controller;
|
||||
import com.sisvietnamvn.web.domain.PageStatus;
|
||||
import com.sisvietnamvn.web.domain.Post;
|
||||
import com.sisvietnamvn.web.repository.PostRepository;
|
||||
import com.sisvietnamvn.web.hook.HookManager;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
@@ -16,9 +17,11 @@ import org.springframework.web.server.ResponseStatusException;
|
||||
public class PostController {
|
||||
|
||||
private final PostRepository postRepository;
|
||||
private final HookManager hookManager;
|
||||
|
||||
public PostController(PostRepository postRepository) {
|
||||
public PostController(PostRepository postRepository, HookManager hookManager) {
|
||||
this.postRepository = postRepository;
|
||||
this.hookManager = hookManager;
|
||||
}
|
||||
|
||||
@GetMapping("/{slug}")
|
||||
@@ -31,6 +34,13 @@ public class PostController {
|
||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
// Apply WordPress-style Content Filters
|
||||
post.setTitle(hookManager.applyFilters("the_title", post.getTitle()));
|
||||
post.setContent(hookManager.applyFilters("the_content", post.getContent()));
|
||||
if (post.getExcerpt() != null) {
|
||||
post.setExcerpt(hookManager.applyFilters("the_excerpt", post.getExcerpt()));
|
||||
}
|
||||
|
||||
model.addAttribute("post", post);
|
||||
|
||||
// Safely format the Instant to avoid Thymeleaf parsing errors
|
||||
|
||||
@@ -47,6 +47,16 @@ public class HookManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes an action and returns an empty string.
|
||||
* This is useful for invoking actions directly within Thymeleaf templates
|
||||
* (e.g., <th:block th:text="${@hookManager.doActionAndReturn('wp_head')}"></th:block>).
|
||||
*/
|
||||
public String doActionAndReturn(String hookName, Object... args) {
|
||||
doAction(hookName, args);
|
||||
return "";
|
||||
}
|
||||
|
||||
// --- Filters ---
|
||||
|
||||
public <T> void addFilter(String hookName, FilterCallback<T> callback, int priority) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -41,16 +41,20 @@ public class UserService {
|
||||
|
||||
private final CacheManager cacheManager;
|
||||
|
||||
private final com.sisvietnamvn.web.hook.HookManager hookManager;
|
||||
|
||||
public UserService(
|
||||
UserRepository userRepository,
|
||||
PasswordEncoder passwordEncoder,
|
||||
AuthorityRepository authorityRepository,
|
||||
CacheManager cacheManager
|
||||
CacheManager cacheManager,
|
||||
com.sisvietnamvn.web.hook.HookManager hookManager
|
||||
) {
|
||||
this.userRepository = userRepository;
|
||||
this.passwordEncoder = passwordEncoder;
|
||||
this.authorityRepository = authorityRepository;
|
||||
this.cacheManager = cacheManager;
|
||||
this.hookManager = hookManager;
|
||||
}
|
||||
|
||||
public Optional<User> activateRegistration(String key) {
|
||||
@@ -126,6 +130,10 @@ public class UserService {
|
||||
userRepository.save(newUser);
|
||||
this.clearUserCaches(newUser);
|
||||
LOG.debug("Created Information for User: {}", newUser);
|
||||
|
||||
// Trigger WordPress-style hook
|
||||
hookManager.doAction("user_register", newUser.getId());
|
||||
|
||||
return newUser;
|
||||
}
|
||||
|
||||
@@ -207,6 +215,10 @@ public class UserService {
|
||||
userRepository.save(user);
|
||||
this.clearUserCaches(user);
|
||||
LOG.debug("Changed Information for User: {}", user);
|
||||
|
||||
// Trigger WordPress-style hook
|
||||
hookManager.doAction("profile_update", user.getId());
|
||||
|
||||
return user;
|
||||
})
|
||||
.map(AdminUserDTO::new);
|
||||
|
||||
Reference in New Issue
Block a user