config = $config + array('ignore_emoticons' => false); } /** * The plugin does not need extra initialization thus it is always ready to * work. * * @return boolean */ public function initialized() { return true; } /** * The main entry point of a plugin. */ public function run() { // Attach CSS and JS files of the plugin to chat window. $dispatcher = \Mibew\EventDispatcher::getInstance(); $dispatcher->attachListener('pageAddCSS', $this, 'attachCssFiles'); $dispatcher->attachListener('pageAddJS', $this, 'attachJsFiles'); $dispatcher->attachListener('pageAddJSPluginOptions', $this, 'attachPluginOptions'); } /** * Event handler for "pageAddJS" event. * * @param array $args */ public function attachJSFiles(&$args) { if ($this->isAppropriatePage($args['request'])) { $base_path = $this->getFilesPath(); $args['js'][] = $base_path . '/vendor/es5-shim/es5-shim.js'; $args['js'][] = $base_path . '/vendor/emojify.js/emojify.js'; $args['js'][] = $base_path . '/js/plugin.js'; } } /** * Event handler for "pageAddCSS" event. * * @param array $args */ public function attachCssFiles(&$args) { if ($this->isAppropriatePage($args['request'])) { $args['css'][] = $this->getFilesPath() . '/css/styles.css'; } } /** * Event handler for "pageAddJSPluginOptions" event. * * @param array $args */ public function attachPluginOptions(&$args) { $request = $args['request']; if ($this->isAppropriatePage($request)) { $args['plugins']['MibewEmoji'] = array( 'imagesDir' => ($request->getBasePath() . '/' . $this->getFilesPath() . '/vendor/emojify.js/images/emoji'), 'ignoreEmoticons' => $this->config['ignore_emoticons'], ); } } /** * Specify dependencies of the plugin. * * @return array List of dependencies */ public static function getDependencies() { // This plugin does not depend on others so return an empty array. return array(); } /** * Checks if plugins data should be attached to the page. * * @param Request $request Incoming request * @return boolean */ protected function isAppropriatePage(Request $request) { $route = $request->attributes->get('_route'); return in_array( $route, array( 'chat_operator', 'chat_user_start', 'chat_user', 'chat_user_invitation', ) ); } }