本文整理汇总了PHP中phpbb\request\request_interface::is_ajax方法的典型用法代码示例。如果您正苦于以下问题:PHP request_interface::is_ajax方法的具体用法?PHP request_interface::is_ajax怎么用?PHP request_interface::is_ajax使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类phpbb\request\request_interface
的用法示例。
在下文中一共展示了request_interface::is_ajax方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: like_post
/**
* Likes controller for route /like_post/{like}
*
* @param int @post_id The post to be edited.
*/
public function like_post($post_id)
{
// If unknown user or bot, cannot like.
if ($this->user->data['user_id'] == ANONYMOUS || $this->user->data['is_bot']) {
return;
}
// Add language variables for response.
$this->user->add_lang_ext('nuleaf/likes', 'likes');
// Grab forum id for permission.
$sql = 'SELECT forum_id
FROM ' . POSTS_TABLE . '
WHERE post_id = ' . $post_id;
$result = $this->db->sql_query_limit($sql, 1);
$forum_id = $this->db->sql_fetchrow($result)['forum_id'];
$this->db->sql_freeresult($result);
// Does the user have permission to like posts in this forum?
if ($this->auth->acl_get('!f_like', $forum_id)) {
$json_response = new json_response();
$json_response->send(array('error' => $this->user->lang('LIKE_NOT_AUTHORIZED')));
return;
}
if ($this->request->is_ajax()) {
$liked = $this->likes_manager->is_liked($post_id);
if ($liked) {
// If post is already liked, unlike it.
$likes_count = $this->likes_manager->unlike($post_id);
} else {
// Else like the post.
$likes_count = $this->likes_manager->like($post_id);
}
// Since the post has now been liked/unliked, $liked is reversed.
$json_response = new json_response();
$json_response->send(array('likes_count' => $likes_count, 'liked' => !$liked, 'LIKE_POST' => $this->user->lang('LIKE_POST'), 'UNLIKE_POST' => $this->user->lang('UNLIKE_POST'), 'LIKE_BUTTON' => $this->user->lang('LIKE_BUTTON'), 'UNLIKE_BUTTON' => $this->user->lang('UNLIKE_BUTTON')));
}
}
示例2: edit
/**
* Edit an existing post
*
* @param int $post_id
* @return JsonResponse|Response
*/
public function edit($post_id)
{
if ($this->request->is_ajax() && !$this->request->header('X-PHPBB-USING-PLUPLOAD', false)) {
return $this->quick_edit($post_id);
}
if (!$this->auth->acl_get('u_titania_post')) {
return $this->controller_helper->needs_auth();
}
// Load the stuff we need
$post = $this->load_post($post_id);
// Check permissions
if (!$post->acl_get('edit')) {
return $this->controller_helper->needs_auth();
}
// Some more complicated permissions for stickes in support
$can_moderate_own = $this->auth->acl_get('u_titania_post_mod_own');
$is_moderator = $this->auth->acl_get('u_titania_mod_post_mod');
$is_author = false;
if ($post->post_type == TITANIA_SUPPORT) {
$is_author = $this->get_contrib($post->topic->parent_id)->is_author();
}
$can_lock_topic = $is_moderator || $is_author && $can_moderate_own;
$can_sticky = ($is_moderator || $is_author) && $post->post_id == $post->topic->topic_first_post_id;
$can_lock_post = $is_moderator && $post->post_user_id != $this->user->data['user_id'];
// Load the message object
$this->setup_message($post, array('lock' => $can_lock_post, 'sticky_topic' => $can_sticky, 'lock_topic' => $can_lock_topic));
// Call our common posting handler
$response = $this->common_post('edit', $post, $this->message);
if ($response) {
return $response;
}
// Common stuff
$this->template->assign_vars(array('S_POST_ACTION' => $post->get_url('edit'), 'L_POST_A' => $this->user->lang['EDIT_POST']));
return $this->controller_helper->render($this->template_file, 'EDIT_POST');
}
示例3: handle_ajax_request
/**
* Handle ajax request.
* Method will return supplied data if request is an ajax request
*
* @param array $data Data to send
*
* @return null
*/
public function handle_ajax_request($data)
{
if ($this->request->is_ajax()) {
$json_response = new \phpbb\json_response();
$json_response->send($data);
}
}
示例4: handle
public function handle($action)
{
$return_data = array();
if ($this->request->is_ajax() === false) {
redirect(generate_board_url(), $this->return_url);
$return_data['message'] = $this->user->lang('NOT_AUTHORISED');
return new Response(json_encode($return_data), 401);
}
try {
$command = $this->action_handler->create($action);
$return_data = $command->execute();
$this->action_handler->clear_cache();
} catch (\blitze\sitemaker\exception\base $e) {
$return_data['message'] = $e->get_message($this->user);
} catch (\Exception $e) {
$return_data['message'] = $this->user->lang($e->getMessage());
}
return new Response(json_encode($return_data));
}
示例5: output_response
/**
* Outputs correct response: standard/JSON
*
* @param string $message Status message
* @param string $return_link Standard only
* @param string $url Standard only
*/
public function output_response($message, $return_link, $url)
{
if ($this->request->is_ajax()) {
$json_response = new \phpbb\json_response();
$json_response->send(array('title' => $this->user->lang("INFORMATION"), 'message' => $message));
} else {
meta_refresh(3, $url);
trigger_error($message . $return_link);
}
}
示例6: handle
/**
* Handle running tool.
*
* @return JsonResponse
*/
public function handle()
{
$this->user->add_lang_ext('phpbb/titania', 'manage_tools');
$this->check_auth();
$result = $this->run();
$result['message'] = $this->user->lang($result['message']);
$next_call = null;
if ($result['next_batch'] !== false) {
$params = $this->get_next_params($result);
$next_call = $this->helper->route($this->tool->get_route(), $params);
}
if ($this->request->is_ajax()) {
return new JsonResponse(array_merge($result, array('next_call' => str_replace('&', '&', $next_call))));
}
if ($next_call) {
meta_refresh(3, $next_call);
}
return $this->helper->message($result['message']);
}
示例7: render_error
/**
* Renders an error form
*
* @param string $msg
* @param string|bool $desc
*/
public function render_error($msg, $desc = false)
{
if ($this->request->is_ajax()) {
$this->iohandler->add_error_message($msg, $desc);
$this->iohandler->send_response();
} else {
$this->template->assign_vars(array('S_ERROR_BOX' => true, 'ERROR_TITLE' => $this->language->lang($msg)));
if ($desc) {
$this->template->assign_var('ERROR_MSG', $this->language->lang($desc));
}
}
}
示例8: handle
/**
* Controller logic
*
* @return Response|StreamedResponse
*/
public function handle()
{
if ($this->install_helper->is_phpbb_installed()) {
die('phpBB is already installed');
}
$this->template->assign_vars(array('U_ACTION' => $this->controller_helper->route('phpbb_installer_install')));
// Set up input-output handler
if ($this->request->is_ajax()) {
$this->iohandler_factory->set_environment('ajax');
} else {
$this->iohandler_factory->set_environment('nojs');
}
// Set the appropriate input-output handler
$this->installer->set_iohandler($this->iohandler_factory->get());
// Set up navigation
$nav_data = $this->installer_config->get_navigation_data();
/** @var \phpbb\install\helper\iohandler\iohandler_interface $iohandler */
$iohandler = $this->iohandler_factory->get();
// Set active navigation stage
if (isset($nav_data['active']) && is_array($nav_data['active'])) {
$iohandler->set_active_stage_menu($nav_data['active']);
$this->menu_provider->set_nav_property($nav_data['active'], array('selected' => true, 'completed' => false));
}
// Set finished navigation stages
if (isset($nav_data['finished']) && is_array($nav_data['finished'])) {
foreach ($nav_data['finished'] as $finished_stage) {
$iohandler->set_finished_stage_menu($finished_stage);
$this->menu_provider->set_nav_property($finished_stage, array('selected' => false, 'completed' => true));
}
}
if ($this->request->is_ajax()) {
$installer = $this->installer;
$response = new StreamedResponse();
$response->setCallback(function () use($installer) {
$installer->run();
});
// Try to bypass any server output buffers
$response->headers->set('X-Accel-Buffering', 'no');
return $response;
} else {
// Determine whether the installation was started or not
if (true) {
$this->controller_helper->handle_language_select();
// Set active stage
$this->menu_provider->set_nav_property(array('install', 0, 'introduction'), array('selected' => true, 'completed' => false));
// If not, let's render the welcome page
$this->template->assign_vars(array('SHOW_INSTALL_START_FORM' => true, 'TITLE' => $this->language->lang('INSTALL_INTRO'), 'CONTENT' => $this->language->lang('INSTALL_INTRO_BODY')));
return $this->controller_helper->render('installer_install.html', 'INSTALL', true);
}
// @todo: implement no js controller logic
}
}
示例9: handle
public function handle($action)
{
$this->user->add_lang_ext('blitze/sitemaker', 'block_manager');
$return_data = array();
$json_data = array('id' => '', 'title' => '', 'content' => '', 'message' => '', 'errors' => '');
if (!$this->auth->acl_get('a_sm_manage_blocks') || $this->request->is_ajax() === false) {
if ($this->request->is_ajax() === false) {
redirect(generate_board_url(), $this->return_url);
}
$json_data['message'] = $this->user->lang('NOT_AUTHORISED');
return new Response(json_encode($json_data), 401);
}
$style_id = $this->request->variable('style', 0);
try {
$command = $this->action_handler->create($action);
$return_data = $command->execute($style_id);
$this->action_handler->clear_cache();
} catch (\blitze\sitemaker\exception\base $e) {
$json_data['message'] = $e->get_message($this->user);
}
return new Response(json_encode(array_merge($json_data, $return_data)));
}
示例10: get_category_urls
/**
* Get category URL's.
*
* @return array
*/
protected function get_category_urls()
{
$category = new \titania_category();
$url = $this->get_index_url($this->params);
$urls = array(0 => $this->request->is_ajax() ? str_replace('&', '&', $url) : $url);
foreach ($this->cache->get_categories() as $data) {
if (!$category->category_visible) {
continue;
}
$category->__set_array($data);
$url = $category->get_url($this->params);
$urls[$category->category_id] = $this->request->is_ajax() ? str_replace('&', '&', $url) : $url;
}
return $urls;
}
示例11: handle
/**
* Controller entry point
*
* @return Response|StreamedResponse
*
* @throws http_exception When phpBB is not installed
*/
public function handle()
{
if (!$this->install_helper->is_phpbb_installed()) {
throw new http_exception(403, 'INSTALL_PHPBB_NOT_INSTALLED');
}
$this->template->assign_vars(array('U_ACTION' => $this->controller_helper->route('phpbb_installer_update')));
// Set up input-output handler
if ($this->request->is_ajax()) {
$this->iohandler_factory->set_environment('ajax');
} else {
$this->iohandler_factory->set_environment('nojs');
}
// Set the appropriate input-output handler
$this->installer->set_iohandler($this->iohandler_factory->get());
$this->controller_helper->handle_language_select();
// Render the intro page
if ($this->request->is_ajax()) {
$installer = $this->installer;
$response = new StreamedResponse();
$response->setCallback(function () use($installer) {
$installer->run();
});
// Try to bypass any server output buffers
$response->headers->set('X-Accel-Buffering', 'no');
$response->headers->set('Content-type', 'application/json');
return $response;
} else {
// Set active stage
$this->menu_provider->set_nav_property(array('update', 0, 'introduction'), array('selected' => true, 'completed' => false));
$this->template->assign_vars(array('SHOW_INSTALL_START_FORM' => true, 'TITLE' => $this->language->lang('UPDATE_INSTALLATION'), 'CONTENT' => $this->language->lang('UPDATE_INSTALLATION_EXPLAIN')));
/** @var \phpbb\install\helper\iohandler\iohandler_interface $iohandler */
$iohandler = $this->iohandler_factory->get();
$this->controller_helper->handle_navigation($iohandler);
return $this->controller_helper->render('installer_update.html', 'UPDATE_INSTALLATION', true);
}
}
示例12: get_web_root_path
/**
* Get a relative root path from the current URL
*
* @return string
*/
public function get_web_root_path()
{
if ($this->symfony_request === null) {
return $this->phpbb_root_path;
}
if (null !== $this->web_root_path) {
return $this->web_root_path;
}
// We do not need to escape $path_info, $request_uri and $script_name because we can not find their content in the result.
// Path info (e.g. /foo/bar)
$path_info = $this->filesystem->clean_path($this->symfony_request->getPathInfo());
// Full request URI (e.g. phpBB/app.php/foo/bar)
$request_uri = $this->symfony_request->getRequestUri();
// Script name URI (e.g. phpBB/app.php)
$script_name = $this->symfony_request->getScriptName();
/*
* If the path info is empty but we're using app.php, then we
* might be using an empty route like app.php/ which is
* supported by symfony's routing
*/
if ($path_info === '/' && preg_match('/app\\.' . $this->php_ext . '\\/$/', $request_uri)) {
return $this->web_root_path = $this->filesystem->clean_path('./../' . $this->phpbb_root_path);
}
/*
* If the path info is empty (single /), then we're not using
* a route like app.php/foo/bar
*/
if ($path_info === '/') {
return $this->web_root_path = $this->phpbb_root_path;
}
/*
* Check AJAX request:
* If the current request is a AJAX we need to fix the paths.
* We need to get the root path based on the Referer, so we can use
* the generated URLs in the template of the Referer. If we do not
* generate the relative path based on the Referer, but based on the
* currently requested URL, the generated URLs will not point to the
* intended locations:
* Referer desired URL desired relative root path
* memberlist.php faq.php ./
* memberlist.php app.php/foo/bar ./
* app.php/foo memberlist.php ../
* app.php/foo app.php/fox ../
* app.php/foo/bar memberlist.php ../../
* ../page.php memberlist.php ./phpBB/
* ../sub/page.php memberlist.php ./../phpBB/
*
* The referer must be specified as a parameter in the query.
*/
if ($this->request->is_ajax() && $this->symfony_request->get('_referer')) {
// We need to escape $absolute_board_url because it can be partially concatenated to the result.
$absolute_board_url = $this->request->escape($this->symfony_request->getSchemeAndHttpHost() . $this->symfony_request->getBasePath(), true);
$referer_web_root_path = $this->get_web_root_path_from_ajax_referer($this->symfony_request->get('_referer'), $absolute_board_url);
return $this->web_root_path = $this->phpbb_root_path . $referer_web_root_path;
}
// How many corrections might we need?
$corrections = substr_count($path_info, '/');
/*
* If the script name (e.g. phpBB/app.php) does not exists in the
* requestUri (e.g. phpBB/app.php/foo/template), then we are rewriting
* the URL. So we must reduce the slash count by 1.
*/
if (strpos($request_uri, $script_name) !== 0) {
$corrections--;
}
// Prepend ../ to the phpbb_root_path as many times as / exists in path_info
$this->web_root_path = $this->filesystem->clean_path('./' . str_repeat('../', $corrections) . $this->phpbb_root_path);
return $this->web_root_path;
}