mirror of
				https://github.com/Mibew/mibew.git
				synced 2025-10-26 00:06:55 +03:00 
			
		
		
		
	Don't use global environment in "setup_chatview_for_user" func
This commit is contained in:
		
							parent
							
								
									896e0d924b
								
							
						
					
					
						commit
						f61ef23e3f
					
				| @ -488,11 +488,16 @@ function setup_chatview(Thread $thread) | ||||
| /** | ||||
|  * Prepare some data for chat for user | ||||
|  * | ||||
|  * @param UrlGeneratorInterface $url_generator A URL generator object. | ||||
|  * @param Request $request The current request. | ||||
|  * @param Thread $thread thread object that will be used | ||||
|  * @return array Array of chat view data | ||||
|  */ | ||||
| function setup_chatview_for_user(Thread $thread) | ||||
| { | ||||
| function setup_chatview_for_user( | ||||
|     UrlGeneratorInterface $url_generator, | ||||
|     Request $request, | ||||
|     Thread $thread | ||||
| ) { | ||||
|     $data = setup_chatview($thread); | ||||
| 
 | ||||
|     // Load JavaScript plugins and JavaScripts, CSS files required by them
 | ||||
| @ -508,13 +513,24 @@ function setup_chatview_for_user(Thread $thread) | ||||
|     ); | ||||
| 
 | ||||
|     // Set link to send mail page
 | ||||
|     $data['chat']['links']['mail'] = MIBEW_WEB_ROOT . "/chat" | ||||
|         . '/' . $thread->id . '/' . $thread->lastToken . '/mail'; | ||||
|     $data['chat']['links']['mail'] = $url_generator->generate( | ||||
|         'chat_user_mail', | ||||
|         array( | ||||
|             'thread_id' => $thread->id, | ||||
|             'token' => $thread->lastToken, | ||||
|         ) | ||||
|     ); | ||||
| 
 | ||||
|     // Set SSL link
 | ||||
|     if (Settings::get('enablessl') == "1" && !is_secure_request()) { | ||||
|         $data['chat']['links']['ssl'] = get_app_location(true, true) | ||||
|             . '/chat/' . $thread->id . '/' . $thread->lastToken; | ||||
|     if (Settings::get('enablessl') == "1" && $request->isSecure()) { | ||||
|         $data['chat']['links']['ssl'] = $url_generator->generateSecure( | ||||
|             'chat_user', | ||||
|             array( | ||||
|                 'thread_id' => $thread->id, | ||||
|                 'token' => $thread->lastToken, | ||||
|             ), | ||||
|             UrlGeneratorInterface::ABSOLUTE_URL | ||||
|         ); | ||||
|     } | ||||
| 
 | ||||
|     // Set default operator's avatar
 | ||||
|  | ||||
| @ -37,6 +37,7 @@ class ThreadController extends AbstractController | ||||
|     public function updateAction(Request $request) | ||||
|     { | ||||
|         $processor = ThreadProcessor::getInstance(); | ||||
|         $processor->setRouter($this->getRouter()); | ||||
| 
 | ||||
|         return $processor->handleRequest($request); | ||||
|     } | ||||
|  | ||||
| @ -47,7 +47,11 @@ class UserChatController extends AbstractController | ||||
|             throw new NotFoundException('The thread is not found.'); | ||||
|         } | ||||
| 
 | ||||
|         $page = setup_chatview_for_user($thread); | ||||
|         $page = setup_chatview_for_user( | ||||
|             $this->getRouter(), | ||||
|             $request, | ||||
|             $thread | ||||
|         ); | ||||
| 
 | ||||
|         // Build js application options
 | ||||
|         $page['chatOptions'] = json_encode($page['chat']); | ||||
|  | ||||
| @ -24,6 +24,9 @@ use Mibew\Settings; | ||||
| use Mibew\Thread; | ||||
| use Mibew\API\API as MibewAPI; | ||||
| use Mibew\RequestProcessor\Exception\ThreadProcessorException; | ||||
| use Mibew\Routing\RouterAwareInterface; | ||||
| use Mibew\Routing\RouterInterface; | ||||
| use Symfony\Component\HttpFoundation\Request; | ||||
| 
 | ||||
| /** | ||||
|  * Incapsulates thread api and thread processing functions. | ||||
| @ -38,9 +41,25 @@ use Mibew\RequestProcessor\Exception\ThreadProcessorException; | ||||
|  * WARNING: | ||||
|  *  threadResponseReceived registered but never called because of asynchronous | ||||
|  *  nature of Core-to-Window interaction | ||||
|  * | ||||
|  * @todo Move all API functions to another place. | ||||
|  */ | ||||
| class ThreadProcessor extends ClientSideProcessor | ||||
| class ThreadProcessor extends ClientSideProcessor implements RouterAwareInterface | ||||
| { | ||||
|     /** | ||||
|      * The request which is hadled now. | ||||
|      * | ||||
|      * @var Request|null | ||||
|      */ | ||||
|     protected $currentRequest = null; | ||||
| 
 | ||||
|     /** | ||||
|      * A Router instance. | ||||
|      * | ||||
|      * @var RouterInterface|null | ||||
|      */ | ||||
|     protected $router = null; | ||||
| 
 | ||||
|     /** | ||||
|      * Loads thread by id and token and checks if thread loaded | ||||
|      * | ||||
| @ -108,6 +127,34 @@ class ThreadProcessor extends ClientSideProcessor | ||||
|         return $operator; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * {@inheritdoc} | ||||
|      */ | ||||
|     public function handleRequest($request) | ||||
|     { | ||||
|         $this->currentRequest = $request; | ||||
|         $response = parent::handleRequest($request); | ||||
|         $this->currentRequest = null; | ||||
| 
 | ||||
|         return $response; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * {@inheritdoc} | ||||
|      */ | ||||
|     public function getRouter() | ||||
|     { | ||||
|         return $this->router; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * {@inheritdoc} | ||||
|      */ | ||||
|     public function setRouter(RouterInterface $router) | ||||
|     { | ||||
|         $this->router = $router; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Class constructor | ||||
|      */ | ||||
| @ -520,7 +567,11 @@ class ThreadProcessor extends ClientSideProcessor | ||||
|         } | ||||
| 
 | ||||
|         // Prepare chat options
 | ||||
|         $client_data = setup_chatview_for_user($thread); | ||||
|         $client_data = setup_chatview_for_user( | ||||
|             $this->getRouter(), | ||||
|             $this->currentRequest, | ||||
|             $thread | ||||
|         ); | ||||
|         $options = $client_data['chat']; | ||||
|         $options['page'] += setup_logo($group); | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user