From 80840a5f08c530d91f147c1bded1c316c2a73d0f Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 7 Jan 2012 20:51:03 +0100 Subject: [feature/event-dispatcher] Introduce a port of Symfony2 EventDispatcher PHPBB3-9550 --- phpBB/includes/event/dispatcher.php | 185 ++++++++++++++++++++++++++ phpBB/includes/event/dispatcher_interface.php | 96 +++++++++++++ phpBB/includes/event/event.php | 123 +++++++++++++++++ phpBB/includes/event/subscriber_interface.php | 50 +++++++ 4 files changed, 454 insertions(+) create mode 100644 phpBB/includes/event/dispatcher.php create mode 100644 phpBB/includes/event/dispatcher_interface.php create mode 100644 phpBB/includes/event/event.php create mode 100644 phpBB/includes/event/subscriber_interface.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/event/dispatcher.php b/phpBB/includes/event/dispatcher.php new file mode 100644 index 0000000000..c3b8dc5790 --- /dev/null +++ b/phpBB/includes/event/dispatcher.php @@ -0,0 +1,185 @@ + + * @author Jonathan Wage + * @author Roman Borschel + * @author Bernhard Schussek + * @author Fabien Potencier + * @author Jordi Boggiano + * @author Jordan Alliot + */ +class phpbb_event_dispatcher +{ + private $listeners = array(); + private $sorted = array(); + + /** + * @see EventDispatcherInterface::dispatch + * + * @api + */ + public function dispatch($event_name, phpbb_event $event = null) + { + if (!isset($this->listeners[$event_name])) { + return; + } + + if (null === $event) { + $event = new phpbb_event(); + } + + $event->set_dispatcher($this); + $event->set_name($event_name); + + $this->do_dispatch($this->get_listeners($event_name), $event_name, $event); + } + + /** + * @see EventDispatcherInterface::get_listeners + */ + public function get_listeners($event_name = null) + { + if (null !== $event_name) { + if (!isset($this->sorted[$event_name])) { + $this->sort_listeners($event_name); + } + + return $this->sorted[$event_name]; + } + + foreach (array_keys($this->listeners) as $event_name) { + if (!isset($this->sorted[$event_name])) { + $this->sort_listeners($event_name); + } + } + + return $this->sorted; + } + + /** + * @see EventDispatcherInterface::has_listeners + */ + public function has_listeners($event_name = null) + { + return (Boolean) count($this->get_listeners($event_name)); + } + + /** + * @see EventDispatcherInterface::add_listener + * + * @api + */ + public function add_listener($event_name, $listener, $priority = 0) + { + $this->listeners[$event_name][$priority][] = $listener; + unset($this->sorted[$event_name]); + } + + /** + * @see EventDispatcherInterface::remove_listener + */ + public function remove_listener($event_name, $listener) + { + if (!isset($this->listeners[$event_name])) { + return; + } + + foreach ($this->listeners[$event_name] as $priority => $listeners) { + if (false !== ($key = array_search($listener, $listeners))) { + unset($this->listeners[$event_name][$priority][$key], $this->sorted[$event_name]); + } + } + } + + /** + * @see EventDispatcherInterface::add_subscriber + * + * @api + */ + public function add_subscriber(phpbb_event_subscriber_interface $subscriber) + { + foreach ($subscriber->get_subscribed_events() as $event_name => $params) { + if (is_string($params)) { + $this->add_listener($event_name, array($subscriber, $params)); + } elseif (is_string($params[0])) { + $this->add_listener($event_name, array($subscriber, $params[0]), $params[1]); + } else { + foreach ($params as $listener) { + $this->add_listener($event_name, array($subscriber, $listener[0]), isset($listener[1]) ? $listener[1] : 0); + } + } + } + } + + /** + * @see EventDispatcherInterface::remove_subscriber + */ + public function remove_subscriber(phpbb_event_subscriber_interface $subscriber) + { + foreach ($subscriber->get_subscribed_events() as $event_name => $params) { + if (is_array($params) && is_array($params[0])) { + foreach ($params as $listener) { + $this->remove_listener($event_name, array($subscriber, $listener[0])); + } + } else { + $this->remove_listener($event_name, array($subscriber, is_string($params) ? $params : $params[0])); + } + } + } + + /** + * Triggers the listeners of an event. + * + * This method can be overridden to add functionality that is executed + * for each listener. + * + * @param array[callback] $listeners The event listeners. + * @param string $event_name The name of the event to dispatch. + * @param Event $event The event object to pass to the event handlers/listeners. + */ + protected function do_dispatch($listeners, $event_name, phpbb_event $event) + { + foreach ($listeners as $listener) { + call_user_func($listener, $event); + if ($event->is_propagation_stopped()) { + break; + } + } + } + + /** + * Sorts the internal list of listeners for the given event by priority. + * + * @param string $event_name The name of the event. + */ + private function sort_listeners($event_name) + { + $this->sorted[$event_name] = array(); + + if (isset($this->listeners[$event_name])) { + krsort($this->listeners[$event_name]); + $this->sorted[$event_name] = call_user_func_array('array_merge', $this->listeners[$event_name]); + } + } +} diff --git a/phpBB/includes/event/dispatcher_interface.php b/phpBB/includes/event/dispatcher_interface.php new file mode 100644 index 0000000000..2564591ed7 --- /dev/null +++ b/phpBB/includes/event/dispatcher_interface.php @@ -0,0 +1,96 @@ + + */ +interface phpbb_event_dispatcher_interface +{ + /** + * Dispatches an event to all registered listeners. + * + * @param string $event_name The name of the event to dispatch. The name of + * the event is the name of the method that is + * invoked on listeners. + * @param Event $event The event to pass to the event handlers/listeners. + * If not supplied, an empty Event instance is created. + * + * @api + */ + function dispatch($event_name, Event $event = null); + + /** + * Adds an event listener that listens on the specified events. + * + * @param string $event_name The event to listen on + * @param callable $listener The listener + * @param integer $priority The higher this value, the earlier an event + * listener will be triggered in the chain (defaults to 0) + * + * @api + */ + function add_listener($event_name, $listener, $priority = 0); + + /** + * Adds an event subscriber. The subscriber is asked for all the events he is + * interested in and added as a listener for these events. + * + * @param EventSubscriberInterface $subscriber The subscriber. + * + * @api + */ + function add_subscriber(phpbb_event_subscriber_interface $subscriber); + + /** + * Removes an event listener from the specified events. + * + * @param string|array $event_name The event(s) to remove a listener from. + * @param object $listener The listener object to remove. + */ + function remove_listener($event_name, $listener); + + /** + * Removes an event subscriber. + * + * @param EventSubscriberInterface $subscriber The subscriber. + */ + function remove_subscriber(phpbb_event_subscriber_interface $subscriber); + + /** + * Gets the listeners of a specific event or all listeners. + * + * @param string $event_name The name of the event. + * + * @return array The event listeners for the specified event, or all event + * listeners by event name. + */ + function get_listeners($event_name = null); + + /** + * Checks whether an event has any registered listeners. + * + * @param string $event_name The name of the event. + * + * @return Boolean TRUE if the specified event has any listeners, FALSE + * otherwise. + */ + function has_listeners($event_name = null); +} diff --git a/phpBB/includes/event/event.php b/phpBB/includes/event/event.php new file mode 100644 index 0000000000..f74370618b --- /dev/null +++ b/phpBB/includes/event/event.php @@ -0,0 +1,123 @@ + + * @author Jonathan Wage + * @author Roman Borschel + * @author Bernhard Schussek + */ +class phpbb_event +{ + /** + * @var Boolean Whether no further event listeners should be triggered + */ + private $propagation_stopped = false; + + /** + * @var EventDispatcher Dispatcher that dispatched this event + */ + private $dispatcher; + + /** + * @var string This event's name + */ + private $name; + + /** + * Returns whether further event listeners should be triggered. + * + * @see Event::stop_propagation + * @return Boolean Whether propagation was already stopped for this event. + * + * @api + */ + public function is_propagation_stopped() + { + return $this->propagation_stopped; + } + + /** + * Stops the propagation of the event to further event listeners. + * + * If multiple event listeners are connected to the same event, no + * further event listener will be triggered once any trigger calls + * stop_propagation(). + * + * @api + */ + public function stop_propagation() + { + $this->propagation_stopped = true; + } + + /** + * Stores the EventDispatcher that dispatches this Event + * + * @param EventDispatcher $dispatcher + * + * @api + */ + public function set_dispatcher(phpbb_event_dispatcher $dispatcher) + { + $this->dispatcher = $dispatcher; + } + + /** + * Returns the EventDispatcher that dispatches this Event + * + * @return EventDispatcher + * + * @api + */ + public function get_dispatcher() + { + return $this->dispatcher; + } + + /** + * Gets the event's name. + * + * @return string + * + * @api + */ + public function get_name() + { + return $this->name; + } + + /** + * Sets the event's name property. + * + * @param string $name The event name. + * + * @api + */ + public function set_name($name) + { + $this->name = $name; + } +} diff --git a/phpBB/includes/event/subscriber_interface.php b/phpBB/includes/event/subscriber_interface.php new file mode 100644 index 0000000000..4e7b23f596 --- /dev/null +++ b/phpBB/includes/event/subscriber_interface.php @@ -0,0 +1,50 @@ + + * @author Jonathan Wage + * @author Roman Borschel + * @author Bernhard Schussek + */ +interface phpbb_event_subscriber_interface +{ + /** + * Returns an array of event names this subscriber wants to listen to. + * + * The array keys are event names and the value can be: + * + * * The method name to call (priority defaults to 0) + * * An array composed of the method name to call and the priority + * * An array of arrays composed of the method names to call and respective + * priorities, or 0 if unset + * + * For instance: + * + * * array('event_name' => 'method_name') + * * array('event_name' => array('method_name', $priority)) + * * array('event_name' => array(array('method_name1', $priority), array('method_name2')) + * + * @return array The event names to listen to + */ + static function get_subscribed_events(); +} -- cgit v1.2.1 From 581b5624f7be3675a35fc61ca6b67b409ae6e8c6 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 7 Jan 2012 20:53:04 +0100 Subject: [feature/event-dispatcher] Allow subscribers to be loaded from extensions PHPBB3-9550 --- .../includes/event/extension_subscriber_loader.php | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 phpBB/includes/event/extension_subscriber_loader.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/event/extension_subscriber_loader.php b/phpBB/includes/event/extension_subscriber_loader.php new file mode 100644 index 0000000000..2a53af1249 --- /dev/null +++ b/phpBB/includes/event/extension_subscriber_loader.php @@ -0,0 +1,43 @@ +dispatcher = $dispatcher; + $this->extension_manager = $extension_manager; + } + + public function load() + { + $finder = $this->extension_manager->get_finder(); + $subscriber_classes = $finder + ->extension_directory('/event') + ->suffix('subscriber') + ->core_path('event/') + ->get_classes(); + + foreach ($subscriber_classes as $class) { + $subscriber = new $class(); + $this->dispatcher->add_subscriber($subscriber); + } + } +} -- cgit v1.2.1 From 58a99c97cadd6a16b138e4de4f8fd1aa172e4eed Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 7 Jan 2012 20:54:01 +0100 Subject: [feature/event-dispatcher] Add a sample hook in page_header PHPBB3-9550 --- phpBB/includes/functions.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 753795b7cf..03376bf906 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4461,6 +4461,7 @@ function phpbb_http_login($param) function page_header($page_title = '', $display_online_list = true, $item_id = 0, $item = 'forum') { global $db, $config, $template, $SID, $_SID, $_EXTRA_URL, $user, $auth, $phpEx, $phpbb_root_path; + global $phpbb_dispatcher; if (defined('HEADER_INC')) { @@ -4744,6 +4745,9 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 'A_COOKIE_SETTINGS' => addslashes('; path=' . $config['cookie_path'] . ((!$config['cookie_domain'] || $config['cookie_domain'] == 'localhost' || $config['cookie_domain'] == '127.0.0.1') ? '' : '; domain=' . $config['cookie_domain']) . ((!$config['cookie_secure']) ? '' : '; secure')), )); + $event = new phpbb_event(); + $phpbb_dispatcher->dispatch('page_header', $event); + // application/xhtml+xml not used because of IE header('Content-type: text/html; charset=UTF-8'); -- cgit v1.2.1 From 03be9761375a082c2a43aceaa1b34661f87d702b Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 7 Jan 2012 21:42:19 +0100 Subject: [feature/event-dispatcher] Support setting data on an event PHPBB3-9550 --- phpBB/includes/event/data.php | 56 +++++++++++++++++++++++++++++++++++++++++++ phpBB/includes/functions.php | 3 ++- 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 phpBB/includes/event/data.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/event/data.php b/phpBB/includes/event/data.php new file mode 100644 index 0000000000..754876c119 --- /dev/null +++ b/phpBB/includes/event/data.php @@ -0,0 +1,56 @@ +set_data($data); + } + + public function set_data(array $data = array()) + { + $this->data = $data; + } + + public function get_data() + { + return $this->data; + } + + public function offsetExists($offset) + { + return isset($this->data[$offset]); + } + + public function offsetGet($offset) + { + return isset($this->data[$offset]) ? $this->data[$offset] : null; + } + + public function offsetSet($offset, $value) + { + $this->data[$offset] = $value; + } + + public function offsetUnset($offset) + { + unset($this->data[$offset]); + } +} diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 03376bf906..109f5b0366 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4745,7 +4745,8 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 'A_COOKIE_SETTINGS' => addslashes('; path=' . $config['cookie_path'] . ((!$config['cookie_domain'] || $config['cookie_domain'] == 'localhost' || $config['cookie_domain'] == '127.0.0.1') ? '' : '; domain=' . $config['cookie_domain']) . ((!$config['cookie_secure']) ? '' : '; secure')), )); - $event = new phpbb_event(); + $event = new phpbb_event_data(); + $event->set_data(compact('page_title', 'display_online_list', 'item_id', 'item')); $phpbb_dispatcher->dispatch('page_header', $event); // application/xhtml+xml not used because of IE -- cgit v1.2.1 From 80f6f2b96f1ef0c3a3bf5637cac85a3c1fa229db Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 7 Jan 2012 21:50:16 +0100 Subject: [feature/event-dispatcher] Prefix event name with 'core.' PHPBB3-9550 --- phpBB/includes/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 109f5b0366..45958d1a0d 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4747,7 +4747,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 $event = new phpbb_event_data(); $event->set_data(compact('page_title', 'display_online_list', 'item_id', 'item')); - $phpbb_dispatcher->dispatch('page_header', $event); + $phpbb_dispatcher->dispatch('core.page_header', $event); // application/xhtml+xml not used because of IE header('Content-type: text/html; charset=UTF-8'); -- cgit v1.2.1 From 82422968796188d4284d7cba0f837ee8f333bf11 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 8 Jan 2012 00:48:21 +0100 Subject: [feature/event-dispatcher] Fix event class name in dispatcher interface PHPBB3-9550 --- phpBB/includes/event/dispatcher_interface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/event/dispatcher_interface.php b/phpBB/includes/event/dispatcher_interface.php index 2564591ed7..0a4881b3ba 100644 --- a/phpBB/includes/event/dispatcher_interface.php +++ b/phpBB/includes/event/dispatcher_interface.php @@ -35,7 +35,7 @@ interface phpbb_event_dispatcher_interface * * @api */ - function dispatch($event_name, Event $event = null); + function dispatch($event_name, phpbb_event $event = null); /** * Adds an event listener that listens on the specified events. -- cgit v1.2.1 From 4c62dcd0ffc36a1c4bea203d7dcabbdd1f6143a3 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 8 Jan 2012 13:20:44 +0100 Subject: [feature/event-dispatcher] Correct copyright statement for Symfony2 files Also add a notice to the files that were taken from Symfony2. PHPBB3-9550 --- phpBB/includes/event/dispatcher.php | 7 ++++++- phpBB/includes/event/dispatcher_interface.php | 7 ++++++- phpBB/includes/event/event.php | 7 ++++++- phpBB/includes/event/subscriber_interface.php | 7 ++++++- 4 files changed, 24 insertions(+), 4 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/event/dispatcher.php b/phpBB/includes/event/dispatcher.php index c3b8dc5790..6f7d61c83b 100644 --- a/phpBB/includes/event/dispatcher.php +++ b/phpBB/includes/event/dispatcher.php @@ -2,7 +2,7 @@ /** * * @package phpBB3 -* @copyright (c) 2011 phpBB Group +* @copyright (c) Fabien Potencier * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ @@ -15,6 +15,11 @@ if (!defined('IN_PHPBB')) exit; } +/** + * This file has been taken from Symfony2 and adjusted for + * phpBB's coding standards. + */ + /** * The EventDispatcherInterface is the central point of Symfony's event listener system. * diff --git a/phpBB/includes/event/dispatcher_interface.php b/phpBB/includes/event/dispatcher_interface.php index 0a4881b3ba..37e6bd4cf1 100644 --- a/phpBB/includes/event/dispatcher_interface.php +++ b/phpBB/includes/event/dispatcher_interface.php @@ -2,7 +2,7 @@ /** * * @package phpBB3 -* @copyright (c) 2011 phpBB Group +* @copyright (c) Fabien Potencier * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ @@ -15,6 +15,11 @@ if (!defined('IN_PHPBB')) exit; } +/** + * This file has been taken from Symfony2 and adjusted for + * phpBB's coding standards. + */ + /** * The EventDispatcherInterface is the central point of Symfony's event listener system. * Listeners are registered on the manager and events are dispatched through the diff --git a/phpBB/includes/event/event.php b/phpBB/includes/event/event.php index f74370618b..6ee144bc68 100644 --- a/phpBB/includes/event/event.php +++ b/phpBB/includes/event/event.php @@ -2,7 +2,7 @@ /** * * @package phpBB3 -* @copyright (c) 2011 phpBB Group +* @copyright (c) Fabien Potencier * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ @@ -15,6 +15,11 @@ if (!defined('IN_PHPBB')) exit; } +/** + * This file has been taken from Symfony2 and adjusted for + * phpBB's coding standards. + */ + /** * Event is the base class for classes containing event data. * diff --git a/phpBB/includes/event/subscriber_interface.php b/phpBB/includes/event/subscriber_interface.php index 4e7b23f596..081d4f0210 100644 --- a/phpBB/includes/event/subscriber_interface.php +++ b/phpBB/includes/event/subscriber_interface.php @@ -2,7 +2,7 @@ /** * * @package phpBB3 -* @copyright (c) 2011 phpBB Group +* @copyright (c) Fabien Potencier * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ @@ -15,6 +15,11 @@ if (!defined('IN_PHPBB')) exit; } +/** + * This file has been taken from Symfony2 and adjusted for + * phpBB's coding standards. + */ + /** * An EventSubscriber knows himself what events he is interested in. * If an EventSubscriber is added to an EventDispatcherInterface, the manager invokes -- cgit v1.2.1 From 162f9b738aaa74684ea42e3ce4d6a911a183a996 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sat, 18 Feb 2012 16:35:43 +0200 Subject: [feature/purge-cache] Allow all admins to purge cache Allow all administrators to purge cache PHPBB3-10659 --- phpBB/includes/acp/acp_main.php | 5 ----- 1 file changed, 5 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_main.php b/phpBB/includes/acp/acp_main.php index b30c294ce2..7cdf734973 100644 --- a/phpBB/includes/acp/acp_main.php +++ b/phpBB/includes/acp/acp_main.php @@ -330,11 +330,6 @@ class acp_main break; case 'purge_cache': - if ((int) $user->data['user_type'] !== USER_FOUNDER) - { - trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING); - } - global $cache; $cache->purge(); -- cgit v1.2.1 From 5dd5df46a497631b905f6595707b0d1b0c302749 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 11 Mar 2012 14:55:01 +0100 Subject: [feature/event-dispatcher] Remove copied EventDispatcher code PHPBB3-9550 --- phpBB/includes/event/dispatcher.php | 190 -------------------------- phpBB/includes/event/dispatcher_interface.php | 101 -------------- phpBB/includes/event/event.php | 128 ----------------- phpBB/includes/event/subscriber_interface.php | 55 -------- 4 files changed, 474 deletions(-) delete mode 100644 phpBB/includes/event/dispatcher.php delete mode 100644 phpBB/includes/event/dispatcher_interface.php delete mode 100644 phpBB/includes/event/event.php delete mode 100644 phpBB/includes/event/subscriber_interface.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/event/dispatcher.php b/phpBB/includes/event/dispatcher.php deleted file mode 100644 index 6f7d61c83b..0000000000 --- a/phpBB/includes/event/dispatcher.php +++ /dev/null @@ -1,190 +0,0 @@ - -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 -* -*/ - -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - -/** - * This file has been taken from Symfony2 and adjusted for - * phpBB's coding standards. - */ - -/** - * The EventDispatcherInterface is the central point of Symfony's event listener system. - * - * Listeners are registered on the manager and events are dispatched through the - * manager. - * - * @author Guilherme Blanco - * @author Jonathan Wage - * @author Roman Borschel - * @author Bernhard Schussek - * @author Fabien Potencier - * @author Jordi Boggiano - * @author Jordan Alliot - */ -class phpbb_event_dispatcher -{ - private $listeners = array(); - private $sorted = array(); - - /** - * @see EventDispatcherInterface::dispatch - * - * @api - */ - public function dispatch($event_name, phpbb_event $event = null) - { - if (!isset($this->listeners[$event_name])) { - return; - } - - if (null === $event) { - $event = new phpbb_event(); - } - - $event->set_dispatcher($this); - $event->set_name($event_name); - - $this->do_dispatch($this->get_listeners($event_name), $event_name, $event); - } - - /** - * @see EventDispatcherInterface::get_listeners - */ - public function get_listeners($event_name = null) - { - if (null !== $event_name) { - if (!isset($this->sorted[$event_name])) { - $this->sort_listeners($event_name); - } - - return $this->sorted[$event_name]; - } - - foreach (array_keys($this->listeners) as $event_name) { - if (!isset($this->sorted[$event_name])) { - $this->sort_listeners($event_name); - } - } - - return $this->sorted; - } - - /** - * @see EventDispatcherInterface::has_listeners - */ - public function has_listeners($event_name = null) - { - return (Boolean) count($this->get_listeners($event_name)); - } - - /** - * @see EventDispatcherInterface::add_listener - * - * @api - */ - public function add_listener($event_name, $listener, $priority = 0) - { - $this->listeners[$event_name][$priority][] = $listener; - unset($this->sorted[$event_name]); - } - - /** - * @see EventDispatcherInterface::remove_listener - */ - public function remove_listener($event_name, $listener) - { - if (!isset($this->listeners[$event_name])) { - return; - } - - foreach ($this->listeners[$event_name] as $priority => $listeners) { - if (false !== ($key = array_search($listener, $listeners))) { - unset($this->listeners[$event_name][$priority][$key], $this->sorted[$event_name]); - } - } - } - - /** - * @see EventDispatcherInterface::add_subscriber - * - * @api - */ - public function add_subscriber(phpbb_event_subscriber_interface $subscriber) - { - foreach ($subscriber->get_subscribed_events() as $event_name => $params) { - if (is_string($params)) { - $this->add_listener($event_name, array($subscriber, $params)); - } elseif (is_string($params[0])) { - $this->add_listener($event_name, array($subscriber, $params[0]), $params[1]); - } else { - foreach ($params as $listener) { - $this->add_listener($event_name, array($subscriber, $listener[0]), isset($listener[1]) ? $listener[1] : 0); - } - } - } - } - - /** - * @see EventDispatcherInterface::remove_subscriber - */ - public function remove_subscriber(phpbb_event_subscriber_interface $subscriber) - { - foreach ($subscriber->get_subscribed_events() as $event_name => $params) { - if (is_array($params) && is_array($params[0])) { - foreach ($params as $listener) { - $this->remove_listener($event_name, array($subscriber, $listener[0])); - } - } else { - $this->remove_listener($event_name, array($subscriber, is_string($params) ? $params : $params[0])); - } - } - } - - /** - * Triggers the listeners of an event. - * - * This method can be overridden to add functionality that is executed - * for each listener. - * - * @param array[callback] $listeners The event listeners. - * @param string $event_name The name of the event to dispatch. - * @param Event $event The event object to pass to the event handlers/listeners. - */ - protected function do_dispatch($listeners, $event_name, phpbb_event $event) - { - foreach ($listeners as $listener) { - call_user_func($listener, $event); - if ($event->is_propagation_stopped()) { - break; - } - } - } - - /** - * Sorts the internal list of listeners for the given event by priority. - * - * @param string $event_name The name of the event. - */ - private function sort_listeners($event_name) - { - $this->sorted[$event_name] = array(); - - if (isset($this->listeners[$event_name])) { - krsort($this->listeners[$event_name]); - $this->sorted[$event_name] = call_user_func_array('array_merge', $this->listeners[$event_name]); - } - } -} diff --git a/phpBB/includes/event/dispatcher_interface.php b/phpBB/includes/event/dispatcher_interface.php deleted file mode 100644 index 37e6bd4cf1..0000000000 --- a/phpBB/includes/event/dispatcher_interface.php +++ /dev/null @@ -1,101 +0,0 @@ - -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 -* -*/ - -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - -/** - * This file has been taken from Symfony2 and adjusted for - * phpBB's coding standards. - */ - -/** - * The EventDispatcherInterface is the central point of Symfony's event listener system. - * Listeners are registered on the manager and events are dispatched through the - * manager. - * - * @author Bernhard Schussek - */ -interface phpbb_event_dispatcher_interface -{ - /** - * Dispatches an event to all registered listeners. - * - * @param string $event_name The name of the event to dispatch. The name of - * the event is the name of the method that is - * invoked on listeners. - * @param Event $event The event to pass to the event handlers/listeners. - * If not supplied, an empty Event instance is created. - * - * @api - */ - function dispatch($event_name, phpbb_event $event = null); - - /** - * Adds an event listener that listens on the specified events. - * - * @param string $event_name The event to listen on - * @param callable $listener The listener - * @param integer $priority The higher this value, the earlier an event - * listener will be triggered in the chain (defaults to 0) - * - * @api - */ - function add_listener($event_name, $listener, $priority = 0); - - /** - * Adds an event subscriber. The subscriber is asked for all the events he is - * interested in and added as a listener for these events. - * - * @param EventSubscriberInterface $subscriber The subscriber. - * - * @api - */ - function add_subscriber(phpbb_event_subscriber_interface $subscriber); - - /** - * Removes an event listener from the specified events. - * - * @param string|array $event_name The event(s) to remove a listener from. - * @param object $listener The listener object to remove. - */ - function remove_listener($event_name, $listener); - - /** - * Removes an event subscriber. - * - * @param EventSubscriberInterface $subscriber The subscriber. - */ - function remove_subscriber(phpbb_event_subscriber_interface $subscriber); - - /** - * Gets the listeners of a specific event or all listeners. - * - * @param string $event_name The name of the event. - * - * @return array The event listeners for the specified event, or all event - * listeners by event name. - */ - function get_listeners($event_name = null); - - /** - * Checks whether an event has any registered listeners. - * - * @param string $event_name The name of the event. - * - * @return Boolean TRUE if the specified event has any listeners, FALSE - * otherwise. - */ - function has_listeners($event_name = null); -} diff --git a/phpBB/includes/event/event.php b/phpBB/includes/event/event.php deleted file mode 100644 index 6ee144bc68..0000000000 --- a/phpBB/includes/event/event.php +++ /dev/null @@ -1,128 +0,0 @@ - -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 -* -*/ - -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - -/** - * This file has been taken from Symfony2 and adjusted for - * phpBB's coding standards. - */ - -/** - * Event is the base class for classes containing event data. - * - * This class contains no event data. It is used by events that do not pass - * state information to an event handler when an event is raised. - * - * You can call the method stop_propagation() to abort the execution of - * further listeners in your event listener. - * - * @author Guilherme Blanco - * @author Jonathan Wage - * @author Roman Borschel - * @author Bernhard Schussek - */ -class phpbb_event -{ - /** - * @var Boolean Whether no further event listeners should be triggered - */ - private $propagation_stopped = false; - - /** - * @var EventDispatcher Dispatcher that dispatched this event - */ - private $dispatcher; - - /** - * @var string This event's name - */ - private $name; - - /** - * Returns whether further event listeners should be triggered. - * - * @see Event::stop_propagation - * @return Boolean Whether propagation was already stopped for this event. - * - * @api - */ - public function is_propagation_stopped() - { - return $this->propagation_stopped; - } - - /** - * Stops the propagation of the event to further event listeners. - * - * If multiple event listeners are connected to the same event, no - * further event listener will be triggered once any trigger calls - * stop_propagation(). - * - * @api - */ - public function stop_propagation() - { - $this->propagation_stopped = true; - } - - /** - * Stores the EventDispatcher that dispatches this Event - * - * @param EventDispatcher $dispatcher - * - * @api - */ - public function set_dispatcher(phpbb_event_dispatcher $dispatcher) - { - $this->dispatcher = $dispatcher; - } - - /** - * Returns the EventDispatcher that dispatches this Event - * - * @return EventDispatcher - * - * @api - */ - public function get_dispatcher() - { - return $this->dispatcher; - } - - /** - * Gets the event's name. - * - * @return string - * - * @api - */ - public function get_name() - { - return $this->name; - } - - /** - * Sets the event's name property. - * - * @param string $name The event name. - * - * @api - */ - public function set_name($name) - { - $this->name = $name; - } -} diff --git a/phpBB/includes/event/subscriber_interface.php b/phpBB/includes/event/subscriber_interface.php deleted file mode 100644 index 081d4f0210..0000000000 --- a/phpBB/includes/event/subscriber_interface.php +++ /dev/null @@ -1,55 +0,0 @@ - -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 -* -*/ - -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - -/** - * This file has been taken from Symfony2 and adjusted for - * phpBB's coding standards. - */ - -/** - * An EventSubscriber knows himself what events he is interested in. - * If an EventSubscriber is added to an EventDispatcherInterface, the manager invokes - * {@link get_subscribed_events} and registers the subscriber as a listener for all - * returned events. - * - * @author Guilherme Blanco - * @author Jonathan Wage - * @author Roman Borschel - * @author Bernhard Schussek - */ -interface phpbb_event_subscriber_interface -{ - /** - * Returns an array of event names this subscriber wants to listen to. - * - * The array keys are event names and the value can be: - * - * * The method name to call (priority defaults to 0) - * * An array composed of the method name to call and the priority - * * An array of arrays composed of the method names to call and respective - * priorities, or 0 if unset - * - * For instance: - * - * * array('event_name' => 'method_name') - * * array('event_name' => array('method_name', $priority)) - * * array('event_name' => array(array('method_name1', $priority), array('method_name2')) - * - * @return array The event names to listen to - */ - static function get_subscribed_events(); -} -- cgit v1.2.1 From e02d92ac62fbe1dc08994444c18a7447d72c56e6 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 11 Mar 2012 15:14:13 +0100 Subject: [feature/event-dispatcher] Use real EventDispatcher through composer * replace the copy-pasta EventDispatcher with the real one from Symfony2 * use composer for managing this dependency, use composer autoloading PHPBB3-9550 --- phpBB/includes/event/data.php | 4 +++- phpBB/includes/event/extension_subscriber_loader.php | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/event/data.php b/phpBB/includes/event/data.php index 754876c119..62e2f2312e 100644 --- a/phpBB/includes/event/data.php +++ b/phpBB/includes/event/data.php @@ -15,7 +15,9 @@ if (!defined('IN_PHPBB')) exit; } -class phpbb_event_data extends phpbb_event implements ArrayAccess +use Symfony\Component\EventDispatcher\Event; + +class phpbb_event_data extends Event implements ArrayAccess { private $data; diff --git a/phpBB/includes/event/extension_subscriber_loader.php b/phpBB/includes/event/extension_subscriber_loader.php index 2a53af1249..aa32ca9686 100644 --- a/phpBB/includes/event/extension_subscriber_loader.php +++ b/phpBB/includes/event/extension_subscriber_loader.php @@ -15,12 +15,14 @@ if (!defined('IN_PHPBB')) exit; } +use Symfony\Component\EventDispatcher\EventDispatcher; + class phpbb_event_extension_subscriber_loader { private $dispatcher; private $extension_manager; - public function __construct(phpbb_event_dispatcher $dispatcher, phpbb_extension_manager $extension_manager) + public function __construct(EventDispatcher $dispatcher, phpbb_extension_manager $extension_manager) { $this->dispatcher = $dispatcher; $this->extension_manager = $extension_manager; @@ -37,7 +39,7 @@ class phpbb_event_extension_subscriber_loader foreach ($subscriber_classes as $class) { $subscriber = new $class(); - $this->dispatcher->add_subscriber($subscriber); + $this->dispatcher->addSubscriber($subscriber); } } } -- cgit v1.2.1 From 4f59990d900b699cdd2cfe4b43e6972bf99d977b Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Fri, 9 Mar 2012 07:34:52 +0000 Subject: [ticket/10510] Added phpbb_add_quickmod_option and moved existing to it. PHPBB3-10510 --- phpBB/includes/functions_content.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index 3a0124934e..b9ab2d8a7a 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -1103,8 +1103,8 @@ function extension_allowed($forum_id, $extension, &$extensions) * @param string $string The text to truncate to the given length. String is specialchared. * @param int $max_length Maximum length of string (multibyte character count as 1 char / Html entity count as 1 char) * @param int $max_store_length Maximum character length of string (multibyte character count as 1 char / Html entity count as entity chars). -* @param bool $allow_reply Allow Re: in front of string -* NOTE: This parameter can cause undesired behavior (returning strings longer than $max_store_length) and is deprecated. +* @param bool $allow_reply Allow Re: in front of string +* NOTE: This parameter can cause undesired behavior (returning strings longer than $max_store_length) and is deprecated. * @param string $append String to be appended */ function truncate_string($string, $max_length = 60, $max_store_length = 255, $allow_reply = false, $append = '') @@ -1258,6 +1258,21 @@ function get_username_string($mode, $user_id, $username, $username_colour = '', return str_replace(array('{PROFILE_URL}', '{USERNAME_COLOUR}', '{USERNAME}'), array($profile_url, $username_colour, $username), (!$username_colour) ? $_profile_cache['tpl_profile'] : $_profile_cache['tpl_profile_colour']); } +/** + * Add an option to the quick-mod tools. + * + * @param string $option The value of the option. + * @param string $lang_string The language string to use. + */ +function phpbb_add_quickmod_option($option, $lang_string, $condition = true) +{ + global $template; + $template->assign_block_vars('quickmod', array( + 'VALUE' => $option, + 'TITLE' => $lang_string, + )); +} + /** * @package phpBB3 */ -- cgit v1.2.1 From 784c9725f3394ce866ab260485b32d501e07a628 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Sun, 11 Mar 2012 19:20:13 +0000 Subject: [ticket/10510] Made a couple improvements to phpbb_add_quickmod_option. PHPBB3-10510 --- phpBB/includes/functions_content.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index b9ab2d8a7a..872d071b91 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -1264,7 +1264,7 @@ function get_username_string($mode, $user_id, $username, $username_colour = '', * @param string $option The value of the option. * @param string $lang_string The language string to use. */ -function phpbb_add_quickmod_option($option, $lang_string, $condition = true) +function phpbb_add_quickmod_option($option, $lang_string) { global $template; $template->assign_block_vars('quickmod', array( -- cgit v1.2.1 From 79a987ffcb19832e1ddefe8be535b181f8acbd73 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Mon, 12 Mar 2012 07:43:01 +0000 Subject: [ticket/10510] Moved a $user->lang call into the function. PHPBB3-10510 --- phpBB/includes/functions_content.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index 872d071b91..f2faf20f43 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -1261,12 +1261,13 @@ function get_username_string($mode, $user_id, $username, $username_colour = '', /** * Add an option to the quick-mod tools. * - * @param string $option The value of the option. + * @param string $option The language key for the value of the option. * @param string $lang_string The language string to use. */ function phpbb_add_quickmod_option($option, $lang_string) { - global $template; + global $template, $user; + $lang_string = $user->lang($lang_string); $template->assign_block_vars('quickmod', array( 'VALUE' => $option, 'TITLE' => $lang_string, -- cgit v1.2.1 From fbf34f16ab5526669dae5b7eb130aac0803e3aed Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 18 Mar 2012 00:48:30 -0400 Subject: [feature/event-dispatcher] Implement configurable autoloader selection. The code is in startup.php which should be used by all scripts. PHPBB3-9550 --- phpBB/includes/startup.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/startup.php b/phpBB/includes/startup.php index 2100fbd97e..de55db2960 100644 --- a/phpBB/includes/startup.php +++ b/phpBB/includes/startup.php @@ -146,5 +146,26 @@ if (function_exists('date_default_timezone_set') && function_exists('date_defaul date_default_timezone_set(@date_default_timezone_get()); } +// Autoloading of dependencies. +// Three options are supported: +// 1. Specify PHPBB_AUTOLOAD=/path/to/autoload.php in the environment. +// This is useful for running CLI scripts and tests. +// /path/to/autoload.php should define and register class loaders +// for all of phpBB's dependencies. +// 2. If dependencies are installed with Composer, Composer will create a +// vendor/.composer/autoload.php. If this file exists it will be +// automatically used by phpBB. +// 3. Failing that phpBB assumes that autoloading has been set up in +// some other way. This might be useful in cases when phpBB is integrated +// into a larger program. +if (getenv('PHPBB_AUTOLOAD')) +{ + require(getenv('PHPBB_AUTOLOAD')); +} +else if (file_exists($phpbb_root_path . 'vendor/.composer/autoload.php')) +{ + require($phpbb_root_path . 'vendor/.composer/autoload.php'); +} + $starttime = explode(' ', microtime()); $starttime = $starttime[1] + $starttime[0]; -- cgit v1.2.1 From be23445b8c40b99c0d27bfb99521022d7b4705e8 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 3 Feb 2012 02:17:49 -0500 Subject: [feature/event-dispatcher] Add get_data_filtered function to event data. Its purpose is to discard any keys added by hooks to data stored in the event, such that only keys that the ledge knows how to handle are processed. PHPBB3-9550 --- phpBB/includes/event/data.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/event/data.php b/phpBB/includes/event/data.php index 62e2f2312e..5780ddbfff 100644 --- a/phpBB/includes/event/data.php +++ b/phpBB/includes/event/data.php @@ -36,6 +36,16 @@ class phpbb_event_data extends Event implements ArrayAccess return $this->data; } + /* + * Returns data filtered to only include specified keys. + * + * This effectively discards any keys added to data by hooks. + */ + public function get_data_filtered($keys) + { + return array_intersect_key($this->data, array_flip($keys)); + } + public function offsetExists($offset) { return isset($this->data[$offset]); -- cgit v1.2.1 From 43899ffdf3e36cf2d107bf5a09c5f37faffdf3c2 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 3 Feb 2012 02:25:32 -0500 Subject: [feature/event-dispatcher] Implement mutation for page_header ledge. PHPBB3-9550 --- phpBB/includes/functions.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 024fa612f0..bd7ed71dcb 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4762,9 +4762,10 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 'A_COOKIE_SETTINGS' => addslashes('; path=' . $config['cookie_path'] . ((!$config['cookie_domain'] || $config['cookie_domain'] == 'localhost' || $config['cookie_domain'] == '127.0.0.1') ? '' : '; domain=' . $config['cookie_domain']) . ((!$config['cookie_secure']) ? '' : '; secure')), )); - $event = new phpbb_event_data(); - $event->set_data(compact('page_title', 'display_online_list', 'item_id', 'item')); + $vars = array('page_title', 'display_online_list', 'item_id', 'item'); + $event = new phpbb_event_data(compact($vars)); $phpbb_dispatcher->dispatch('core.page_header', $event); + extract($event->get_data_filtered($vars)); // application/xhtml+xml not used because of IE header('Content-type: text/html; charset=UTF-8'); -- cgit v1.2.1 From 847d47a533a1288aa0fcc701ce86abf970184608 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 18 Mar 2012 23:12:17 +0100 Subject: [feature/event-dispatcher] Change subscriber naming {subscriber => listener}.php This is more consistent with what Symfony2 uses (EventListener/FooListener.php). PHPBB3-9550 --- phpBB/includes/event/extension_subscriber_loader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/event/extension_subscriber_loader.php b/phpBB/includes/event/extension_subscriber_loader.php index aa32ca9686..60e7fe2382 100644 --- a/phpBB/includes/event/extension_subscriber_loader.php +++ b/phpBB/includes/event/extension_subscriber_loader.php @@ -33,7 +33,7 @@ class phpbb_event_extension_subscriber_loader $finder = $this->extension_manager->get_finder(); $subscriber_classes = $finder ->extension_directory('/event') - ->suffix('subscriber') + ->suffix('listener') ->core_path('event/') ->get_classes(); -- cgit v1.2.1 From b4b586ae10ce34d1c7d00d784fac7a51804eff3e Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 21 Mar 2012 13:09:39 +0100 Subject: [feature/event-dispatcher] Switch subscriber loader to EventDispatcherInterface Do not hardcode the implementation of EventDispatcher. PHPBB3-9550 --- phpBB/includes/event/extension_subscriber_loader.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/event/extension_subscriber_loader.php b/phpBB/includes/event/extension_subscriber_loader.php index 60e7fe2382..155846d53d 100644 --- a/phpBB/includes/event/extension_subscriber_loader.php +++ b/phpBB/includes/event/extension_subscriber_loader.php @@ -15,14 +15,14 @@ if (!defined('IN_PHPBB')) exit; } -use Symfony\Component\EventDispatcher\EventDispatcher; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; class phpbb_event_extension_subscriber_loader { private $dispatcher; private $extension_manager; - public function __construct(EventDispatcher $dispatcher, phpbb_extension_manager $extension_manager) + public function __construct(EventDispatcherInterface $dispatcher, phpbb_extension_manager $extension_manager) { $this->dispatcher = $dispatcher; $this->extension_manager = $extension_manager; -- cgit v1.2.1 From baefbdb8825a37051a200203a0191d34caa12229 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 21 Mar 2012 13:15:45 +0100 Subject: [feature/event-dispatcher] Add phpbb_event_dispatcher_wrapper PHPBB3-9550 --- phpBB/includes/event/dispatcher_wrapper.php | 88 +++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 phpBB/includes/event/dispatcher_wrapper.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/event/dispatcher_wrapper.php b/phpBB/includes/event/dispatcher_wrapper.php new file mode 100644 index 0000000000..5f5d653c3c --- /dev/null +++ b/phpBB/includes/event/dispatcher_wrapper.php @@ -0,0 +1,88 @@ +trigger_event('core.index', compact($vars))); +* +* Apart from that it implements the EventDispatcherInterface +* and proxies all method calls to the member dispatcher. +*/ +class phpbb_event_dispatcher_wrapper implements EventDispatcherInterface +{ + private $dispatcher; + + public function __construct(EventDispatcherInterface $dispatcher) + { + $this->dispatcher = $dispatcher; + } + + public function dispatch($eventName, Event $event = null) + { + $this->dispatcher->dispatch($eventName, $event); + } + + public function addListener($eventName, $listener, $priority = 0) + { + $this->dispatcher->addListener($eventName, $listener, $priority); + } + + public function addSubscriber(EventSubscriberInterface $subscriber) + { + $this->dispatcher->addSubscriber($subscriber); + } + + public function removeListener($eventName, $listener) + { + $this->dispatcher->removeListener($eventName, $listener); + } + + public function removeSubscriber(EventSubscriberInterface $subscriber) + { + $this->dispatcher->removeSubscriber($subscriber); + } + + public function getListeners($eventName = null) + { + return $this->dispatcher->getListeners($eventName); + } + + public function hasListeners($eventName = null) + { + return $this->dispatcher->hasListeners($eventName); + } + + public function trigger_event($eventName, $data = array()) + { + $event = new phpbb_event_data($data); + $this->dispatch($eventName, $event); + return $event->get_data_filtered(array_keys($data)); + } +} -- cgit v1.2.1 From 400277c03624788e6a31f9aa4a15b883478f58cc Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 24 Mar 2012 15:45:18 +0100 Subject: [feature/event-dispatcher] Change phpbb_event_dispatcher to inheritance, tests PHPBB3-9550 --- phpBB/includes/event/dispatcher.php | 42 ++++++++++++++ phpBB/includes/event/dispatcher_wrapper.php | 88 ----------------------------- 2 files changed, 42 insertions(+), 88 deletions(-) create mode 100644 phpBB/includes/event/dispatcher.php delete mode 100644 phpBB/includes/event/dispatcher_wrapper.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/event/dispatcher.php b/phpBB/includes/event/dispatcher.php new file mode 100644 index 0000000000..2bf46b9b06 --- /dev/null +++ b/phpBB/includes/event/dispatcher.php @@ -0,0 +1,42 @@ +trigger_event('core.index', compact($vars))); +* +*/ +class phpbb_event_dispatcher extends EventDispatcher +{ + public function trigger_event($eventName, $data = array()) + { + $event = new phpbb_event_data($data); + $this->dispatch($eventName, $event); + return $event->get_data_filtered(array_keys($data)); + } +} diff --git a/phpBB/includes/event/dispatcher_wrapper.php b/phpBB/includes/event/dispatcher_wrapper.php deleted file mode 100644 index 5f5d653c3c..0000000000 --- a/phpBB/includes/event/dispatcher_wrapper.php +++ /dev/null @@ -1,88 +0,0 @@ -trigger_event('core.index', compact($vars))); -* -* Apart from that it implements the EventDispatcherInterface -* and proxies all method calls to the member dispatcher. -*/ -class phpbb_event_dispatcher_wrapper implements EventDispatcherInterface -{ - private $dispatcher; - - public function __construct(EventDispatcherInterface $dispatcher) - { - $this->dispatcher = $dispatcher; - } - - public function dispatch($eventName, Event $event = null) - { - $this->dispatcher->dispatch($eventName, $event); - } - - public function addListener($eventName, $listener, $priority = 0) - { - $this->dispatcher->addListener($eventName, $listener, $priority); - } - - public function addSubscriber(EventSubscriberInterface $subscriber) - { - $this->dispatcher->addSubscriber($subscriber); - } - - public function removeListener($eventName, $listener) - { - $this->dispatcher->removeListener($eventName, $listener); - } - - public function removeSubscriber(EventSubscriberInterface $subscriber) - { - $this->dispatcher->removeSubscriber($subscriber); - } - - public function getListeners($eventName = null) - { - return $this->dispatcher->getListeners($eventName); - } - - public function hasListeners($eventName = null) - { - return $this->dispatcher->hasListeners($eventName); - } - - public function trigger_event($eventName, $data = array()) - { - $event = new phpbb_event_data($data); - $this->dispatch($eventName, $event); - return $event->get_data_filtered(array_keys($data)); - } -} -- cgit v1.2.1 From a44423baee5d0d5e0fd8899204a71e4a292dc6bf Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 24 Mar 2012 21:37:45 +0100 Subject: [feature/event-dispatcher] Change composer autoloading options Check if composer's generated autoloader is present, and if not give an error. PHPBB3-9550 --- phpBB/includes/startup.php | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/startup.php b/phpBB/includes/startup.php index 9c4e1374ba..45eaff6fc7 100644 --- a/phpBB/includes/startup.php +++ b/phpBB/includes/startup.php @@ -149,22 +149,32 @@ if (function_exists('date_default_timezone_set') && function_exists('date_defaul // Autoloading of dependencies. // Three options are supported: -// 1. Specify PHPBB_AUTOLOAD=/path/to/autoload.php in the environment. -// This is useful for running CLI scripts and tests. +// 1. If dependencies are installed with Composer, Composer will create a +// vendor/.composer/autoload.php. If this file exists it will be +// automatically used by phpBB. This is the default mode that phpBB +// will use when shipped. +// 2. To disable composer autoloading, PHPBB_NO_AUTOLOAD can be specified. +// Additionally specify PHPBB_AUTOLOAD=/path/to/autoload.php in the +// environment. This is useful for running CLI scripts and tests. // /path/to/autoload.php should define and register class loaders // for all of phpBB's dependencies. -// 2. If dependencies are installed with Composer, Composer will create a -// vendor/.composer/autoload.php. If this file exists it will be -// automatically used by phpBB. -// 3. Failing that phpBB assumes that autoloading has been set up in -// some other way. This might be useful in cases when phpBB is integrated -// into a larger program. -if (getenv('PHPBB_AUTOLOAD')) +// 3. You can also set PHPBB_NO_AUTOLOAD without setting PHPBB_AUTOLOAD. +// In this case autoloading needs to be defined before running any phpBB +// script. This might be useful in cases when phpBB is integrated into a +// larger program. +if (getenv('PHPBB_NO_AUTOLOAD')) { - require(getenv('PHPBB_AUTOLOAD')); + if (getenv('PHPBB_AUTOLOAD')) + { + require(getenv('PHPBB_AUTOLOAD')); + } } -else if (file_exists($phpbb_root_path . 'vendor/.composer/autoload.php')) +else { + if (!file_exists($phpbb_root_path . 'vendor/.composer/autoload.php')) + { + trigger_error('You have not set up composer dependencies. See http://getcomposer.org/.', E_USER_ERROR); + } require($phpbb_root_path . 'vendor/.composer/autoload.php'); } -- cgit v1.2.1 From 138e7dae0087e683fcb170df1e806b8e4f4b86cd Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 28 Mar 2012 21:48:46 +0200 Subject: [feature/event-dispatcher] Rename PHPBB_NO_AUTOLOAD=>PHPBB_NO_COMPOSER_AUTOLOAD PHPBB3-9550 --- phpBB/includes/startup.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/startup.php b/phpBB/includes/startup.php index 45eaff6fc7..f75d70e366 100644 --- a/phpBB/includes/startup.php +++ b/phpBB/includes/startup.php @@ -153,16 +153,16 @@ if (function_exists('date_default_timezone_set') && function_exists('date_defaul // vendor/.composer/autoload.php. If this file exists it will be // automatically used by phpBB. This is the default mode that phpBB // will use when shipped. -// 2. To disable composer autoloading, PHPBB_NO_AUTOLOAD can be specified. +// 2. To disable composer autoloading, PHPBB_NO_COMPOSER_AUTOLOAD can be specified. // Additionally specify PHPBB_AUTOLOAD=/path/to/autoload.php in the // environment. This is useful for running CLI scripts and tests. // /path/to/autoload.php should define and register class loaders // for all of phpBB's dependencies. -// 3. You can also set PHPBB_NO_AUTOLOAD without setting PHPBB_AUTOLOAD. +// 3. You can also set PHPBB_NO_COMPOSER_AUTOLOAD without setting PHPBB_AUTOLOAD. // In this case autoloading needs to be defined before running any phpBB // script. This might be useful in cases when phpBB is integrated into a // larger program. -if (getenv('PHPBB_NO_AUTOLOAD')) +if (getenv('PHPBB_NO_COMPOSER_AUTOLOAD')) { if (getenv('PHPBB_AUTOLOAD')) { -- cgit v1.2.1 From cb7dabbffc7ea5e2acffaa6fed96ea682f93581d Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 28 Mar 2012 16:13:59 -0400 Subject: [ticket/10586] Change the interface to an abstract class This allows the common phpBB objects to be automatically accessible to extensions without the author having to globalize and assign each one himself. This is better because it also gives purpose to the phpbb_extension_controller class; instead of just being the way to ensure a handle() method is present, it also does this work for us. PHPBB3-10586 --- phpBB/includes/extension/controller.php | 85 +++++++++++++++++++++++ phpBB/includes/extension/controller_interface.php | 31 --------- 2 files changed, 85 insertions(+), 31 deletions(-) create mode 100644 phpBB/includes/extension/controller.php delete mode 100644 phpBB/includes/extension/controller_interface.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/extension/controller.php b/phpBB/includes/extension/controller.php new file mode 100644 index 0000000000..985aded862 --- /dev/null +++ b/phpBB/includes/extension/controller.php @@ -0,0 +1,85 @@ +request =& $request; + $this->db =& $db; + $this->user =& $user; + $this->template =& $template; + $this->config =& $config; + + $this->phpEx = $phpEx; + $this->phpbb_root_path = $phpbb_root_path; + } + + /** + * Handle the request to display a page from an extension + * + * @return null + */ + abstract public function handle(); +} diff --git a/phpBB/includes/extension/controller_interface.php b/phpBB/includes/extension/controller_interface.php deleted file mode 100644 index bcc8972db4..0000000000 --- a/phpBB/includes/extension/controller_interface.php +++ /dev/null @@ -1,31 +0,0 @@ - Date: Wed, 28 Mar 2012 16:21:17 -0400 Subject: [ticket/10586] Make the abstract class implement the original interface PHPBB3-10586 --- phpBB/includes/extension/controller.php | 2 +- phpBB/includes/extension/controller_interface.php | 31 +++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 phpBB/includes/extension/controller_interface.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/extension/controller.php b/phpBB/includes/extension/controller.php index 985aded862..e7d4427c87 100644 --- a/phpBB/includes/extension/controller.php +++ b/phpBB/includes/extension/controller.php @@ -20,7 +20,7 @@ if (!defined('IN_PHPBB')) * * @package extension */ -abstract class phpbb_extension_controller +abstract class phpbb_extension_controller implements phpbb_extension_controller_interface { /** * @var phpbb_request Request class object diff --git a/phpBB/includes/extension/controller_interface.php b/phpBB/includes/extension/controller_interface.php new file mode 100644 index 0000000000..bcc8972db4 --- /dev/null +++ b/phpBB/includes/extension/controller_interface.php @@ -0,0 +1,31 @@ + Date: Wed, 28 Mar 2012 16:23:40 -0400 Subject: [ticket/10586] Do not pass as reference PHPBB3-10586 --- phpBB/includes/extension/controller.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/extension/controller.php b/phpBB/includes/extension/controller.php index e7d4427c87..6e47948156 100644 --- a/phpBB/includes/extension/controller.php +++ b/phpBB/includes/extension/controller.php @@ -66,12 +66,11 @@ abstract class phpbb_extension_controller implements phpbb_extension_controller_ global $request, $db, $user, $template, $config; global $phpEx, $phpbb_root_path; - $this->request =& $request; - $this->db =& $db; - $this->user =& $user; - $this->template =& $template; - $this->config =& $config; - + $this->request = $request; + $this->db = $db; + $this->user = $user; + $this->template = $template; + $this->config = $config; $this->phpEx = $phpEx; $this->phpbb_root_path = $phpbb_root_path; } -- cgit v1.2.1 From 7b091f18a83f4bc31fc00ef067b55db48137ef47 Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 28 Mar 2012 16:37:42 -0400 Subject: [ticket/10586] Remove handle() from abstract class, undo change in index.php PHPBB3-10586 --- phpBB/includes/extension/controller.php | 7 ------- phpBB/includes/extension/controller_interface.php | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/extension/controller.php b/phpBB/includes/extension/controller.php index 6e47948156..8861ec2696 100644 --- a/phpBB/includes/extension/controller.php +++ b/phpBB/includes/extension/controller.php @@ -74,11 +74,4 @@ abstract class phpbb_extension_controller implements phpbb_extension_controller_ $this->phpEx = $phpEx; $this->phpbb_root_path = $phpbb_root_path; } - - /** - * Handle the request to display a page from an extension - * - * @return null - */ - abstract public function handle(); } diff --git a/phpBB/includes/extension/controller_interface.php b/phpBB/includes/extension/controller_interface.php index bcc8972db4..2b88925388 100644 --- a/phpBB/includes/extension/controller_interface.php +++ b/phpBB/includes/extension/controller_interface.php @@ -23,7 +23,7 @@ if (!defined('IN_PHPBB')) interface phpbb_extension_controller_interface { /** - * handle the request to display a page from an extension + * Handle the request to display a page from an extension * * @return null */ -- cgit v1.2.1 From afc55b4c08ca891e11e2aba15dce1f9b5b7c481a Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 28 Mar 2012 16:50:18 -0400 Subject: [ticket/10586] Added visibility indication to __construct() PHPBB3-10586 --- phpBB/includes/extension/controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/extension/controller.php b/phpBB/includes/extension/controller.php index 8861ec2696..c7fd439a19 100644 --- a/phpBB/includes/extension/controller.php +++ b/phpBB/includes/extension/controller.php @@ -61,7 +61,7 @@ abstract class phpbb_extension_controller implements phpbb_extension_controller_ * Constructor method that provides the common phpBB objects as inherited class * properties for automatic availability in extension controllers */ - function __construct() + public function __construct() { global $request, $db, $user, $template, $config; global $phpEx, $phpbb_root_path; -- cgit v1.2.1 From 28b67d24e4164d4da511af42f26170ddc7376c90 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Thu, 29 Mar 2012 08:43:42 +0200 Subject: [feature/event-dispatcher] Fix docblock in phpbb_event_data PHPBB3-10732 --- phpBB/includes/event/data.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/event/data.php b/phpBB/includes/event/data.php index 5780ddbfff..47cb2d5a30 100644 --- a/phpBB/includes/event/data.php +++ b/phpBB/includes/event/data.php @@ -36,11 +36,11 @@ class phpbb_event_data extends Event implements ArrayAccess return $this->data; } - /* - * Returns data filtered to only include specified keys. - * - * This effectively discards any keys added to data by hooks. - */ + /** + * Returns data filtered to only include specified keys. + * + * This effectively discards any keys added to data by hooks. + */ public function get_data_filtered($keys) { return array_intersect_key($this->data, array_flip($keys)); -- cgit v1.2.1 From 7aef3eb7b3dae478fe90c5dfdb276b693c726272 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Thu, 29 Mar 2012 21:29:56 +0200 Subject: [feature/event-dispatcher] Braces CS fix PHPBB3-9550 --- phpBB/includes/event/extension_subscriber_loader.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/event/extension_subscriber_loader.php b/phpBB/includes/event/extension_subscriber_loader.php index 155846d53d..71b16b8371 100644 --- a/phpBB/includes/event/extension_subscriber_loader.php +++ b/phpBB/includes/event/extension_subscriber_loader.php @@ -37,7 +37,8 @@ class phpbb_event_extension_subscriber_loader ->core_path('event/') ->get_classes(); - foreach ($subscriber_classes as $class) { + foreach ($subscriber_classes as $class) + { $subscriber = new $class(); $this->dispatcher->addSubscriber($subscriber); } -- cgit v1.2.1 From 0d6a5cb6ae29348a247c8f42e2046c8b84741aa5 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Fri, 30 Mar 2012 11:02:48 +0100 Subject: [feature/event-dispatcher] Update core.page_header event Update it to the new correct format. PHPBB3-9550 --- phpBB/includes/functions.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index bd7ed71dcb..7a96dd3609 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4763,9 +4763,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 )); $vars = array('page_title', 'display_online_list', 'item_id', 'item'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.page_header', $event); - extract($event->get_data_filtered($vars)); + extract($phpbb_dispatcher->trigger_event('core.page_header', compact($vars))); // application/xhtml+xml not used because of IE header('Content-type: text/html; charset=UTF-8'); -- cgit v1.2.1 From 951e2c8d0c32e6c2bcae02e2f2ff8be35af35b36 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Fri, 30 Mar 2012 14:22:20 +0200 Subject: [feature/event-dispatcher] Fix copyright years PHPBB3-9550 --- phpBB/includes/event/data.php | 2 +- phpBB/includes/event/extension_subscriber_loader.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/event/data.php b/phpBB/includes/event/data.php index 47cb2d5a30..70718ff0ae 100644 --- a/phpBB/includes/event/data.php +++ b/phpBB/includes/event/data.php @@ -2,7 +2,7 @@ /** * * @package phpBB3 -* @copyright (c) 2011 phpBB Group +* @copyright (c) 2012 phpBB Group * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ diff --git a/phpBB/includes/event/extension_subscriber_loader.php b/phpBB/includes/event/extension_subscriber_loader.php index 71b16b8371..d933b943d7 100644 --- a/phpBB/includes/event/extension_subscriber_loader.php +++ b/phpBB/includes/event/extension_subscriber_loader.php @@ -2,7 +2,7 @@ /** * * @package phpBB3 -* @copyright (c) 2011 phpBB Group +* @copyright (c) 2012 phpBB Group * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ -- cgit v1.2.1 From d420ceb9c717b83ba29dde3734b563881051e51a Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Thu, 14 Jul 2011 13:33:42 +0100 Subject: [ticket/10270] Added JavaScript popups and basic AJAX functionality to PHP. This commit adds the phpbb object (JavaScript), and alert and confirm box methods. It also adds the first basic AJAX functionality, to deleting posts in viewtopic. PHPBB3-10270 --- phpBB/includes/functions.php | 53 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 7 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 7a96dd3609..572986bb4b 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2448,15 +2448,25 @@ function build_url($strip_vars = false) */ function meta_refresh($time, $url, $disable_cd_check = false) { - global $template; + global $template, $refresh_data; - $url = redirect($url, true, $disable_cd_check); - $url = str_replace('&', '&', $url); + if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') + { + $refresh_data = array( + 'time' => $time, + 'url' => str_replace('&', '&', $url) + ); + } + else + { + $url = redirect($url, true, $disable_cd_check); + $url = str_replace('&', '&', $url); - // For XHTML compatibility we change back & to & - $template->assign_vars(array( - 'META' => '') - ); + // For XHTML compatibility we change back & to & + $template->assign_vars(array( + 'META' => '') + ); + } return $url; } @@ -2699,6 +2709,21 @@ function confirm_box($check, $title = '', $hidden = '', $html_body = 'confirm_bo WHERE user_id = " . $user->data['user_id']; $db->sql_query($sql); + + if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') + { + $u_action .= '&confirm_uid=' . $user->data['user_id'] . '&sess=' . $user->session_id . '&sid=' . $user->session_id; + echo json_encode(array( + 'MESSAGE_TITLE' => (!isset($user->lang[$title])) ? $user->lang['CONFIRM'] : $user->lang[$title], + 'MESSAGE_TEXT' => (!isset($user->lang[$title . '_CONFIRM'])) ? $title : $user->lang[$title . '_CONFIRM'], + + 'YES_VALUE' => $user->lang['YES'], + 'S_CONFIRM_ACTION' => str_replace('&', '&', $u_action), //inefficient, rewrite whole function + 'S_HIDDEN_FIELDS' => $hidden . $s_hidden_fields + )); + exit; + } + if (defined('IN_ADMIN') && isset($user->data['session_admin']) && $user->data['session_admin']) { adm_page_footer(); @@ -3922,6 +3947,20 @@ function msg_handler($errno, $msg_text, $errfile, $errline) 'S_USER_NOTICE' => ($errno == E_USER_NOTICE) ? true : false) ); + if ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') + { + global $refresh_data; + + echo json_encode(array( + 'MESSAGE_TITLE' => $msg_title, + 'MESSAGE_TEXT' => $msg_text, + 'S_USER_WARNING' => ($errno == E_USER_WARNING) ? true : false, + 'S_USER_NOTICE' => ($errno == E_USER_NOTICE) ? true : false, + 'REFRESH_DATA' => (!empty($refresh_data)) ? $refresh_data : null + )); + exit; + } + // We do not want the cron script to be called on error messages define('IN_CRON', true); -- cgit v1.2.1 From bb7a03f738c97dc225873691c459f2bf9e612ef6 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Wed, 27 Jul 2011 12:57:58 +0100 Subject: [ticket/10281] AJAXified reordering forums in the ACP. PHPBB3-10281 --- phpBB/includes/acp/acp_forums.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index fad22fc285..d3e2dbd904 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -255,6 +255,12 @@ class acp_forums add_log('admin', 'LOG_FORUM_' . strtoupper($action), $row['forum_name'], $move_forum_name); $cache->destroy('sql', FORUMS_TABLE); } + + if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') + { + echo json_encode(array('success' => ($move_forum_name !== false))); + exit; + } break; -- cgit v1.2.1 From 94172b54dd09b28e19b4b12933b3f96e498d264a Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Fri, 19 Aug 2011 09:38:57 +0100 Subject: [ticket/10271] Changed AJAX functions to $request->is_ajax(). PHPBB3-10271 --- phpBB/includes/acp/acp_forums.php | 4 ++-- phpBB/includes/functions.php | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index d3e2dbd904..cb410e361a 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -25,7 +25,7 @@ class acp_forums function main($id, $mode) { - global $db, $user, $auth, $template, $cache; + global $db, $user, $auth, $template, $cache, $request; global $config, $phpbb_admin_path, $phpbb_root_path, $phpEx; $user->add_lang('acp/forums'); @@ -256,7 +256,7 @@ class acp_forums $cache->destroy('sql', FORUMS_TABLE); } - if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') + if ($request->is_ajax()) { echo json_encode(array('success' => ($move_forum_name !== false))); exit; diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 572986bb4b..b126fcc709 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2448,9 +2448,9 @@ function build_url($strip_vars = false) */ function meta_refresh($time, $url, $disable_cd_check = false) { - global $template, $refresh_data; + global $template, $refresh_data, $request; - if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') + if ($request->is_ajax()) { $refresh_data = array( 'time' => $time, @@ -2629,7 +2629,7 @@ function check_form_key($form_name, $timespan = false, $return_page = '', $trigg */ function confirm_box($check, $title = '', $hidden = '', $html_body = 'confirm_body.html', $u_action = '') { - global $user, $template, $db; + global $user, $template, $db, $request; global $phpEx, $phpbb_root_path, $request; if (isset($_POST['cancel'])) @@ -2710,7 +2710,7 @@ function confirm_box($check, $title = '', $hidden = '', $html_body = 'confirm_bo $db->sql_query($sql); - if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') + if ($request->is_ajax()) { $u_action .= '&confirm_uid=' . $user->data['user_id'] . '&sess=' . $user->session_id . '&sid=' . $user->session_id; echo json_encode(array( @@ -3748,7 +3748,7 @@ function phpbb_checkdnsrr($host, $type = 'MX') */ function msg_handler($errno, $msg_text, $errfile, $errline) { - global $cache, $db, $auth, $template, $config, $user; + global $cache, $db, $auth, $template, $config, $user, $request; global $phpEx, $phpbb_root_path, $msg_title, $msg_long_text; // Do not display notices if we suppress them via @ @@ -3947,7 +3947,7 @@ function msg_handler($errno, $msg_text, $errfile, $errline) 'S_USER_NOTICE' => ($errno == E_USER_NOTICE) ? true : false) ); - if ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') + if ($request->is_ajax()) { global $refresh_data; -- cgit v1.2.1 From dce38f44de04bd7a1f91f8e57f6d266bd5e1af86 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Fri, 19 Aug 2011 10:45:03 +0100 Subject: [ticket/10328] Added a JSON class. The JSON class adds a consistent way to send JSON to the client, making it perfect for AJAX (jQuery automatically parses it). PHPBB3-10328 --- phpBB/includes/acp/acp_forums.php | 3 +- phpBB/includes/functions.php | 6 ++-- phpBB/includes/json.php | 59 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 phpBB/includes/json.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index cb410e361a..6c05b1e108 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -258,8 +258,7 @@ class acp_forums if ($request->is_ajax()) { - echo json_encode(array('success' => ($move_forum_name !== false))); - exit; + JSON::send(array('success' => ($move_forum_name !== false))); } break; diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index b126fcc709..b9ca30279f 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2713,7 +2713,7 @@ function confirm_box($check, $title = '', $hidden = '', $html_body = 'confirm_bo if ($request->is_ajax()) { $u_action .= '&confirm_uid=' . $user->data['user_id'] . '&sess=' . $user->session_id . '&sid=' . $user->session_id; - echo json_encode(array( + JSON::send(array( 'MESSAGE_TITLE' => (!isset($user->lang[$title])) ? $user->lang['CONFIRM'] : $user->lang[$title], 'MESSAGE_TEXT' => (!isset($user->lang[$title . '_CONFIRM'])) ? $title : $user->lang[$title . '_CONFIRM'], @@ -2721,7 +2721,6 @@ function confirm_box($check, $title = '', $hidden = '', $html_body = 'confirm_bo 'S_CONFIRM_ACTION' => str_replace('&', '&', $u_action), //inefficient, rewrite whole function 'S_HIDDEN_FIELDS' => $hidden . $s_hidden_fields )); - exit; } if (defined('IN_ADMIN') && isset($user->data['session_admin']) && $user->data['session_admin']) @@ -3951,14 +3950,13 @@ function msg_handler($errno, $msg_text, $errfile, $errline) { global $refresh_data; - echo json_encode(array( + JSON::send(array( 'MESSAGE_TITLE' => $msg_title, 'MESSAGE_TEXT' => $msg_text, 'S_USER_WARNING' => ($errno == E_USER_WARNING) ? true : false, 'S_USER_NOTICE' => ($errno == E_USER_NOTICE) ? true : false, 'REFRESH_DATA' => (!empty($refresh_data)) ? $refresh_data : null )); - exit; } // We do not want the cron script to be called on error messages diff --git a/phpBB/includes/json.php b/phpBB/includes/json.php new file mode 100644 index 0000000000..04472080d9 --- /dev/null +++ b/phpBB/includes/json.php @@ -0,0 +1,59 @@ + Date: Fri, 19 Aug 2011 18:11:58 +0100 Subject: [ticket/10272] Zebra operations using AJAX are now less hacky. Before, they were splitting stuff by the
, and now JSON::add() is being used. PHPBB3-10272 --- phpBB/includes/ucp/ucp_zebra.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/ucp/ucp_zebra.php b/phpBB/includes/ucp/ucp_zebra.php index 004f3b80aa..3f0e97b48a 100644 --- a/phpBB/includes/ucp/ucp_zebra.php +++ b/phpBB/includes/ucp/ucp_zebra.php @@ -201,6 +201,10 @@ class ucp_zebra if ($updated) { + JSON::add(array( + 'message' => $user->lang[$l_mode . '_UPDATED'], + 'success' => true + )); meta_refresh(3, $this->u_action); $message = $user->lang[$l_mode . '_UPDATED'] . '
' . implode('
', $error) . ((sizeof($error)) ? '
' : '') . '
' . sprintf($user->lang['RETURN_UCP'], '', ''); trigger_error($message); -- cgit v1.2.1 From 7a933bdb5ad4a9bc4877a7d4d516fa0b21d9e4c0 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Wed, 24 Aug 2011 12:25:54 +0100 Subject: [ticket/10328] Renamed the JSON class, also now using autoloading. It is no longer static, and uses autoloading. It has also been renamed from JSON to phpbb_json_response. PHPBB3-10328 --- phpBB/includes/acp/acp_forums.php | 3 +- phpBB/includes/functions.php | 6 ++-- phpBB/includes/json.php | 59 --------------------------------------- phpBB/includes/json_response.php | 42 ++++++++++++++++++++++++++++ phpBB/includes/ucp/ucp_zebra.php | 24 ++++++++++++---- 5 files changed, 66 insertions(+), 68 deletions(-) delete mode 100644 phpBB/includes/json.php create mode 100644 phpBB/includes/json_response.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index 6c05b1e108..3a3b2021eb 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -258,7 +258,8 @@ class acp_forums if ($request->is_ajax()) { - JSON::send(array('success' => ($move_forum_name !== false))); + $json_response = new phpbb_json_response; + $json_response->send(array('success' => ($move_forum_name !== false))); } break; diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index b9ca30279f..afd901a296 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2713,7 +2713,8 @@ function confirm_box($check, $title = '', $hidden = '', $html_body = 'confirm_bo if ($request->is_ajax()) { $u_action .= '&confirm_uid=' . $user->data['user_id'] . '&sess=' . $user->session_id . '&sid=' . $user->session_id; - JSON::send(array( + $json_response = new phpbb_json_response; + $json_response->send(array( 'MESSAGE_TITLE' => (!isset($user->lang[$title])) ? $user->lang['CONFIRM'] : $user->lang[$title], 'MESSAGE_TEXT' => (!isset($user->lang[$title . '_CONFIRM'])) ? $title : $user->lang[$title . '_CONFIRM'], @@ -3950,7 +3951,8 @@ function msg_handler($errno, $msg_text, $errfile, $errline) { global $refresh_data; - JSON::send(array( + $json_response = new phpbb_json_response; + $json_response->send(array( 'MESSAGE_TITLE' => $msg_title, 'MESSAGE_TEXT' => $msg_text, 'S_USER_WARNING' => ($errno == E_USER_WARNING) ? true : false, diff --git a/phpBB/includes/json.php b/phpBB/includes/json.php deleted file mode 100644 index 04472080d9..0000000000 --- a/phpBB/includes/json.php +++ /dev/null @@ -1,59 +0,0 @@ -is_ajax()) { - JSON::add(array( - 'message' => $user->lang[$l_mode . '_UPDATED'], - 'success' => true + $message = ($updated) ? $user->lang[$l_mode . '_UPDATED'] : implode('
', $error); + + $json_response = new phpbb_json_response; + $json_response->send(array( + 'success' => $updated, + + 'MESSAGE_TITLE' => $user->lang['INFORMATION'], + 'MESSAGE_TEXT' => $message, + 'REFRESH_DATA' => array( + 'time' => 3, + 'url' => $this->u_action + ) )); + } + else if ($updated) + { meta_refresh(3, $this->u_action); $message = $user->lang[$l_mode . '_UPDATED'] . '
' . implode('
', $error) . ((sizeof($error)) ? '
' : '') . '
' . sprintf($user->lang['RETURN_UCP'], '', ''); trigger_error($message); -- cgit v1.2.1 From 11112314f757f4a6c65852817fba0f1a2f4526d2 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Wed, 24 Aug 2011 12:46:33 +0100 Subject: [ticket/10271] AJAXified various deletions in the ACP. The following places have had deletion AJAXified: * Smilies and icons * Word censors * BBCodes * Attachment groups * Groups * Admin / User / Moderator / Forum roles * Report / denial reasons * Module management * Custom profile fields PHPBB3-10271 --- phpBB/includes/acp/acp_bbcodes.php | 14 +++++++++++++- phpBB/includes/acp/acp_icons.php | 12 ++++++++++++ phpBB/includes/acp/acp_ranks.php | 14 +++++++++++++- 3 files changed, 38 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_bbcodes.php b/phpBB/includes/acp/acp_bbcodes.php index a3822a982a..e537d7a8b9 100644 --- a/phpBB/includes/acp/acp_bbcodes.php +++ b/phpBB/includes/acp/acp_bbcodes.php @@ -24,7 +24,7 @@ class acp_bbcodes function main($id, $mode) { - global $db, $user, $auth, $template, $cache; + global $db, $user, $auth, $template, $cache, $request; global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx; $user->add_lang('acp/posting'); @@ -272,6 +272,18 @@ class acp_bbcodes $db->sql_query('DELETE FROM ' . BBCODES_TABLE . " WHERE bbcode_id = $bbcode_id"); $cache->destroy('sql', BBCODES_TABLE); add_log('admin', 'LOG_BBCODE_DELETE', $row['bbcode_tag']); + + if ($request->is_ajax()) + { + $json_response = new phpbb_json_response; + $json_response->send(array( + 'MESSAGE_TITLE' => $user->lang['INFORMATION'], + 'MESSAGE_TEXT' => $user->lang['BBCODE_DELETED'], + 'REFRESH_DATA' => array( + 'time' => 3 + ) + )); + } } else { diff --git a/phpBB/includes/acp/acp_icons.php b/phpBB/includes/acp/acp_icons.php index 49a092f16b..bfe17c5007 100644 --- a/phpBB/includes/acp/acp_icons.php +++ b/phpBB/includes/acp/acp_icons.php @@ -782,6 +782,18 @@ class acp_icons $cache->destroy('_icons'); $cache->destroy('sql', $table); + + if ($request->is_ajax()) + { + $json_response = new phpbb_json_response; + $json_response->send(array( + 'MESSAGE_TITLE' => $user->lang['INFORMATION'], + 'MESSAGE_TEXT' => $notice, + 'REFRESH_DATA' => array( + 'time' => 3 + ) + )); + } } else { diff --git a/phpBB/includes/acp/acp_ranks.php b/phpBB/includes/acp/acp_ranks.php index ec5a76df87..d9ed5b17f1 100644 --- a/phpBB/includes/acp/acp_ranks.php +++ b/phpBB/includes/acp/acp_ranks.php @@ -24,7 +24,7 @@ class acp_ranks function main($id, $mode) { - global $db, $user, $auth, $template, $cache; + global $db, $user, $auth, $template, $cache, $request; global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx; $user->add_lang('acp/posting'); @@ -122,6 +122,18 @@ class acp_ranks $cache->destroy('_ranks'); add_log('admin', 'LOG_RANK_REMOVED', $rank_title); + + if ($request->is_ajax()) + { + $json_response = new phpbb_json_response; + $json_response->send(array( + 'MESSAGE_TITLE' => $user->lang['INFORMATION'], + 'MESSAGE_TEXT' => $user->lang['RANK_REMOVED'], + 'REFRESH_DATA' => array( + 'time' => 3 + ) + )); + } } else { -- cgit v1.2.1 From 1cb3b595ec70730429a9c8654b248fc6d50cf1b3 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Wed, 24 Aug 2011 15:45:51 +0100 Subject: [ticket/10271] AJAXified the styles tab in the ACP. PHPBB3-10271 --- phpBB/includes/acp/acp_styles.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index 7b449d3b35..a241dd3d10 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -28,7 +28,7 @@ class acp_styles function main($id, $mode) { - global $db, $user, $auth, $template, $cache; + global $db, $user, $auth, $template, $cache, $request; global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx; // Hardcoded template bitfield to add for new templates @@ -185,6 +185,18 @@ inherit_from = {INHERIT_FROM} WHERE forum_style = ' . $style_id; $db->sql_query($sql); } + if ($request->is_ajax()) + { + $json_response = new phpbb_json_response; + $json_response->send(array( + 'text' => $user->lang['STYLE_' . (($action == 'activate') ? 'DE' : '') . 'ACTIVATE'], + 'MESSAGE_TITLE' => $user->lang['INFORMATION'], + 'MESSAGE_TEXT' => $user->lang['STYLE_' . strtoupper($action) . 'D'], + 'REFRESH_DATA' => array( + 'time' => 3 + ) + )); + } } else if ($action == 'deactivate') { @@ -335,7 +347,8 @@ inherit_from = {INHERIT_FROM} $s_actions = array(); foreach ($actions as $option) { - $s_actions[] = '' . $user->lang[strtoupper($option)] . ''; + $data_ajax = ($option == 'refresh') ? ' data-ajax="true"' : ''; + $s_actions[] = '' . $user->lang[strtoupper($option)] . ''; } $template->assign_block_vars('installed', array( -- cgit v1.2.1 From 4ae74cd4b450ae4cca956f6f3e2371429f67deec Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Wed, 24 Aug 2011 16:06:06 +0100 Subject: [ticket/10271] AJAXified buttons on acp_main. PHPBB3-10271 --- phpBB/includes/acp/acp_main.php | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_main.php b/phpBB/includes/acp/acp_main.php index 4c9ee85982..144b225766 100644 --- a/phpBB/includes/acp/acp_main.php +++ b/phpBB/includes/acp/acp_main.php @@ -24,7 +24,7 @@ class acp_main function main($id, $mode) { - global $config, $db, $user, $auth, $template; + global $config, $db, $user, $auth, $template, $request; global $phpbb_root_path, $phpbb_admin_path, $phpEx; // Show restore permissions notice @@ -129,6 +129,11 @@ class acp_main set_config('record_online_users', 1, true); set_config('record_online_date', time(), true); add_log('admin', 'LOG_RESET_ONLINE'); + + if ($request->is_ajax()) + { + trigger_error('RESET_ONLINE_SUCCESS'); + } break; case 'stats': @@ -179,6 +184,11 @@ class acp_main update_last_username(); add_log('admin', 'LOG_RESYNC_STATS'); + + if ($request->is_ajax()) + { + trigger_error('RESYNC_STATS_SUCCESS'); + } break; case 'user': @@ -241,7 +251,11 @@ class acp_main } add_log('admin', 'LOG_RESYNC_POSTCOUNTS'); - + + if ($request->is_ajax()) + { + trigger_error('RESYNC_POSTCOUNTS_SUCCESS'); + } break; case 'date': @@ -252,6 +266,11 @@ class acp_main set_config('board_startdate', time() - 1); add_log('admin', 'LOG_RESET_DATE'); + + if ($request->is_ajax()) + { + trigger_error('RESET_DATE_SUCCESS'); + } break; case 'db_track': @@ -327,6 +346,11 @@ class acp_main } add_log('admin', 'LOG_RESYNC_POST_MARKING'); + + if ($request->is_ajax()) + { + trigger_error('RESYNC_POST_MARKING_SUCCESS'); + } break; case 'purge_cache': @@ -338,6 +362,11 @@ class acp_main cache_moderators(); add_log('admin', 'LOG_PURGE_CACHE'); + + if ($request->is_ajax()) + { + trigger_error('PURGE_CACHE_SUCCESS'); + } break; case 'purge_sessions': @@ -384,6 +413,11 @@ class acp_main $db->sql_query($sql); add_log('admin', 'LOG_PURGE_SESSIONS'); + + if ($request->is_ajax()) + { + trigger_error('PURGE_SESSIONS_SUCCESS'); + } break; } } -- cgit v1.2.1 From e7e09f8da26abf0d4e625653d14d68774050a244 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Wed, 24 Aug 2011 16:39:25 +0100 Subject: [ticket/10272] AJAXified the bots page in the ACP. PHPBB3-10272 --- phpBB/includes/acp/acp_bots.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_bots.php b/phpBB/includes/acp/acp_bots.php index f080b3c9fb..b9dd6664f4 100644 --- a/phpBB/includes/acp/acp_bots.php +++ b/phpBB/includes/acp/acp_bots.php @@ -24,7 +24,7 @@ class acp_bots function main($id, $mode) { - global $config, $db, $user, $auth, $template, $cache; + global $config, $db, $user, $auth, $template, $cache, $request; global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix; $action = request_var('action', ''); @@ -352,6 +352,14 @@ class acp_bots break; } + + if ($request->is_ajax() && ($action == 'activate' || $action == 'deactivate')) + { + $json_response = new phpbb_json_response; + $json_response->send(array( + 'text' => $user->lang['BOT_' . (($action == 'activate') ? 'DE' : '') . 'ACTIVATE'], + )); + } $s_options = ''; $_options = array('activate' => 'BOT_ACTIVATE', 'deactivate' => 'BOT_DEACTIVATE', 'delete' => 'DELETE'); -- cgit v1.2.1 From dbb81fbd2bfadf52502f2200b0420953d98ffb56 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Sat, 24 Sep 2011 16:35:46 +0100 Subject: [ticket/10328] Added capital to "Content-type" in phpbb_json_response. It was originally Content-type, but has been replaced with Content-Type, which is correct. PHPBB3-10328 --- phpBB/includes/json_response.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/json_response.php b/phpBB/includes/json_response.php index 95d02e3c0e..dfddea98f2 100644 --- a/phpBB/includes/json_response.php +++ b/phpBB/includes/json_response.php @@ -30,7 +30,7 @@ class phpbb_json_response */ public function send($data, $exit = true) { - header('Content-type: application/json'); + header('Content-Type: application/json'); echo json_encode($data); if ($exit) -- cgit v1.2.1 From e5d0f2c6ad5af0bf00303dfc15f4a11b1709eb4b Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Thu, 17 Nov 2011 17:13:35 +0000 Subject: [ticket/10328] Fixed the header of json_response.php. PHPBB3-10328 --- phpBB/includes/json_response.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/json_response.php b/phpBB/includes/json_response.php index dfddea98f2..5dd904da09 100644 --- a/phpBB/includes/json_response.php +++ b/phpBB/includes/json_response.php @@ -2,8 +2,7 @@ /** * * @package phpBB3 -* @version $Id$ -* @copyright (c) 2005 phpBB Group +* @copyright (c) 2011 phpBB Group * @license http://opensource.org/licenses/gpl-license.php GNU Public License * */ -- cgit v1.2.1 From e73426fe267a13e2964273e31391dcd93e50ad1b Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 15 Feb 2012 22:45:04 +0100 Subject: [feature/ajax] Handle acp_modules error cases with JSON response PHPBB3-10270 --- phpBB/includes/acp/acp_modules.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_modules.php b/phpBB/includes/acp/acp_modules.php index 9d87bbbfbb..427a3e1e71 100644 --- a/phpBB/includes/acp/acp_modules.php +++ b/phpBB/includes/acp/acp_modules.php @@ -36,7 +36,7 @@ class acp_modules function main($id, $mode) { - global $db, $user, $auth, $template, $module; + global $db, $user, $auth, $template, $module, $request; global $config, $phpbb_admin_path, $phpbb_root_path, $phpEx; // Set a global define for modules we might include (the author is able to prevent execution of code by checking this constant) @@ -373,6 +373,14 @@ class acp_modules // Default management page if (sizeof($errors)) { + if ($request->is_ajax()) + { + phpbb_json_response::send(array( + 'MESSAGE_TITLE' => $user->lang('ERROR'), + 'MESSAGE_TEXT' => implode('
', $errors), + )); + } + $template->assign_vars(array( 'S_ERROR' => true, 'ERROR_MSG' => implode('
', $errors)) -- cgit v1.2.1 From d8e21952fa4660ba2ccc6587bef6275c8cddab37 Mon Sep 17 00:00:00 2001 From: Callum Macrae Date: Sun, 19 Feb 2012 17:07:24 +0000 Subject: [ticket/10273] Fixed accepting / denying posts AJAX. PHPBB3-10273 --- phpBB/includes/mcp/mcp_queue.php | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index ef32b5f03c..59fa8b7263 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -451,6 +451,7 @@ function approve_post($post_id_list, $id, $mode) { global $db, $template, $user, $config; global $phpEx, $phpbb_root_path; + global $request; if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve'))) { @@ -709,7 +710,20 @@ function approve_post($post_id_list, $id, $mode) $add_message = '

' . sprintf($user->lang['RETURN_POST'], '', ''); } - trigger_error($user->lang[$success_msg] . '

' . sprintf($user->lang['RETURN_PAGE'], "", '') . $add_message); + $message = $user->lang[$success_msg] . '

' . sprintf($user->lang['RETURN_PAGE'], "", '') . $add_message; + + if ($request->is_ajax()) + { + $json_response = new phpbb_json_response; + $json_response->send(array( + 'MESSAGE_TITLE' => $user->lang['INFORMATION'], + 'MESSAGE_TEXT' => $message, + 'REFRESH_DATA' => null, + 'approved' => true + )); + } + + trigger_error($message); } } @@ -968,7 +982,20 @@ function disapprove_post($post_id_list, $id, $mode) } else { + $message = $user->lang[$success_msg] . '

' . sprintf($user->lang['RETURN_PAGE'], "", ''); + + if ($request->is_ajax()) + { + $json_response = new phpbb_json_response; + $json_response->send(array( + 'MESSAGE_TITLE' => $user->lang['INFORMATION'], + 'MESSAGE_TEXT' => $message, + 'REFRESH_DATA' => null, + 'approved' => false + )); + } + meta_refresh(3, $redirect); - trigger_error($user->lang[$success_msg] . '

' . sprintf($user->lang['RETURN_PAGE'], "", '')); + trigger_error($message); } } -- cgit v1.2.1 From 9b971c9fb17f284cda413eacc6665f5cdf837cbd Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 31 Mar 2012 00:59:27 +0200 Subject: [feature/ajax] Replace static call to phpbb_request with OO PHPBB3-10270 --- phpBB/includes/acp/acp_modules.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_modules.php b/phpBB/includes/acp/acp_modules.php index 427a3e1e71..e7cd057361 100644 --- a/phpBB/includes/acp/acp_modules.php +++ b/phpBB/includes/acp/acp_modules.php @@ -375,7 +375,8 @@ class acp_modules { if ($request->is_ajax()) { - phpbb_json_response::send(array( + $json_response = new phpbb_json_response(); + $json_response->send(array( 'MESSAGE_TITLE' => $user->lang('ERROR'), 'MESSAGE_TEXT' => implode('
', $errors), )); -- cgit v1.2.1 From 8138103c6b5695b07c2f98d7ff9942e22903591a Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 31 Mar 2012 01:09:41 +0200 Subject: [feature/ajax] Send correct activate/deactivate JSON response in acp_profile PHPBB3-10270 --- phpBB/includes/acp/acp_profile.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_profile.php b/phpBB/includes/acp/acp_profile.php index 511148baf9..3ffffd3047 100644 --- a/phpBB/includes/acp/acp_profile.php +++ b/phpBB/includes/acp/acp_profile.php @@ -242,6 +242,15 @@ class acp_profile $db->sql_freeresult($result); add_log('admin', 'LOG_PROFILE_FIELD_ACTIVATE', $field_ident); + + if ($request->is_ajax()) + { + $json_response = new phpbb_json_response(); + $json_response->send(array( + 'text' => $user->lang('DEACTIVATE'), + )); + } + trigger_error($user->lang['PROFILE_FIELD_ACTIVATED'] . adm_back_link($this->u_action)); break; @@ -266,7 +275,16 @@ class acp_profile $field_ident = (string) $db->sql_fetchfield('field_ident'); $db->sql_freeresult($result); + if ($request->is_ajax()) + { + $json_response = new phpbb_json_response(); + $json_response->send(array( + 'text' => $user->lang('ACTIVATE'), + )); + } + add_log('admin', 'LOG_PROFILE_FIELD_DEACTIVATE', $field_ident); + trigger_error($user->lang['PROFILE_FIELD_DEACTIVATED'] . adm_back_link($this->u_action)); break; -- cgit v1.2.1 From 4a5172c9f74047c5917a0356f8537da2fe1550f4 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 31 Mar 2012 01:17:35 +0200 Subject: [feature/ajax] Unify phpbb_json_response instantiation PHPBB3-10270 --- phpBB/includes/acp/acp_modules.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_modules.php b/phpBB/includes/acp/acp_modules.php index e7cd057361..8528dc91c4 100644 --- a/phpBB/includes/acp/acp_modules.php +++ b/phpBB/includes/acp/acp_modules.php @@ -375,7 +375,7 @@ class acp_modules { if ($request->is_ajax()) { - $json_response = new phpbb_json_response(); + $json_response = new phpbb_json_response; $json_response->send(array( 'MESSAGE_TITLE' => $user->lang('ERROR'), 'MESSAGE_TEXT' => implode('
', $errors), -- cgit v1.2.1 From 41d8a777dc73350a2f3bba6aaae2686921110d08 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 31 Mar 2012 01:26:04 +0200 Subject: [feature/ajax] Add entirely unrelated but nice newlines PHPBB3-10270 --- phpBB/includes/acp/acp_styles.php | 1 + phpBB/includes/functions_display.php | 1 + 2 files changed, 2 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index a241dd3d10..26939080bc 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -185,6 +185,7 @@ inherit_from = {INHERIT_FROM} WHERE forum_style = ' . $style_id; $db->sql_query($sql); } + if ($request->is_ajax()) { $json_response = new phpbb_json_response; diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 9335cabc15..18db64cc68 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -273,6 +273,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod markread('topics', $forum_ids); $message = sprintf($user->lang['RETURN_FORUM'], '', ''); meta_refresh(3, $redirect); + trigger_error($user->lang['FORUMS_MARKED'] . '

' . $message); } else -- cgit v1.2.1