public function stopQuery() { $query = $this->currentQuery; $query['time'] = microtime(true) - $this->start; $zevent = new Zikula_Event('log.sql', null, $query); EventUtil::notify($zevent); }
/** * Gets all registered widgets * * @return array Collection of Dashboard_AbstractWidget */ public function getRegisteredWidgets($uid) { $dbWidgets = $this->em->getRepository('Dashboard_Entity_Widget')->findAll(); $widgets = array(); /* @var Dashboard_Entity_Widget $dbWidget */ foreach ($dbWidgets as $dbWidget) { if (!SecurityUtil::checkPermission('Dashboard::', "{$dbWidget->getId()}:{$dbWidget->getModule()}:{$uid}", ACCESS_READ)) { continue; // error } $event = new Zikula_Event(new Zikula_Event(Dashboard_Events::FILTER_WIDGET_CLASS, null, array(), $dbWidget->getClass())); $class = EventUtil::notify($event)->getData(); if (!class_exists($class)) { continue; } /* @var Dashboard_AbstractWidget $widget */ $widget = new $class(); $widget->setId($dbWidget->getId()); $widgets[] = $widget; } return $widgets; }
/** * Unregister all subscribers from the system. * * This cascades to remove all event handlers, sorting data and update bindings table. * * @param array $bundles Module's bundles object. * * @return void */ public static function unregisterSubscriberBundles(array $bundles) { $hookManager = ServiceUtil::getManager()->getService('zikula.hookmanager'); foreach ($bundles as $bundle) { $hookManager->unregisterSubscriberBundle($bundle); $event = new Zikula_Event('installer.subscriberbundle.uninstalled', $bundle, array('areaid' => $hookManager->getAreaId($bundle->getArea()))); EventUtil::notify($event); } }
/** * Executed following a Doctrine statement exec query. * * @param Doctrine_Event $event The Doctrine event instance. * * @return void */ public function postStmtExecute(Doctrine_Event $event) { $event->end(); $zevent = new Zikula_Event('log.sql', null, array('time' => $event->getElapsedSecs(), 'query' => $event->getQuery())); EventUtil::notify($zevent); }
/** * Run a module function. * * @param string $modname The name of the module. * @param string $type The type of function to run. * @param string $func The specific function to run. * @param array $args The arguments to pass to the function. * @param boolean $api Whether or not to execute an API (or regular) function. * @param string $instanceof Perform instanceof checking of target class. * * @throws Zikula_Exception_NotFound If method was not found. * @throws InvalidArgumentException If the controller is not an instance of the class specified in $instanceof. * * @return mixed. */ public static function exec($modname, $type = 'user', $func = 'main', $args = array(), $api = false, $instanceof = null) { // define input, all numbers and booleans to strings $modname = isset($modname) ? (string) $modname : ''; $ftype = $api ? 'api' : ''; $loadfunc = $api ? 'ModUtil::loadApi' : 'ModUtil::load'; // validate if (!System::varValidate($modname, 'mod')) { return null; } // Remove from 1.4 if (System::isLegacyMode() && $modname == 'Modules') { LogUtil::log(__('Warning! "Modules" module has been renamed to "Extensions". Please update your ModUtil::func() and ModUtil::apiFunc() calls.')); $modname = 'Extensions'; } $modinfo = self::getInfo(self::getIDFromName($modname)); $path = $modinfo['type'] == self::TYPE_SYSTEM ? 'system' : 'modules'; $controller = null; $modfunc = null; $loaded = call_user_func_array($loadfunc, array($modname, $type)); if (self::isOO($modname)) { $result = self::getCallable($modname, $type, $func, $api); if ($result) { $modfunc = $result['callable']; $controller = $modfunc[0]; if (!is_null($instanceof)) { if (!$controller instanceof $instanceof) { throw new InvalidArgumentException(__f('%1$s must be an instance of $2$s', array(get_class($controller), $instanceof))); } } } } $modfunc = $modfunc ? $modfunc : "{$modname}_{$type}{$ftype}_{$func}"; $eventManager = EventUtil::getManager(); if ($loaded) { $preExecuteEvent = new Zikula_Event('module_dispatch.preexecute', $controller, array('modname' => $modname, 'modfunc' => $modfunc, 'args' => $args, 'modinfo' => $modinfo, 'type' => $type, 'api' => $api)); $postExecuteEvent = new Zikula_Event('module_dispatch.postexecute', $controller, array('modname' => $modname, 'modfunc' => $modfunc, 'args' => $args, 'modinfo' => $modinfo, 'type' => $type, 'api' => $api)); if (is_callable($modfunc)) { $eventManager->notify($preExecuteEvent); // Check $modfunc is an object instance (OO) or a function (old) if (is_array($modfunc)) { if ($modfunc[0] instanceof Zikula_AbstractController) { $reflection = call_user_func(array($modfunc[0], 'getReflection')); $subclassOfReflection = new ReflectionClass($reflection->getParentClass()); if ($subclassOfReflection->hasMethod($modfunc[1])) { // Don't allow front controller to access any public methods inside the controller's parents throw new Zikula_Exception_NotFound(); } $modfunc[0]->preDispatch(); } $postExecuteEvent->setData(call_user_func($modfunc, $args)); if ($modfunc[0] instanceof Zikula_AbstractController) { $modfunc[0]->postDispatch(); } } else { $postExecuteEvent->setData($modfunc($args)); } return $eventManager->notify($postExecuteEvent)->getData(); } // get the theme if (ServiceUtil::getManager()->getService('zikula')->getStage() & Zikula_Core::STAGE_THEME) { $theme = ThemeUtil::getInfo(ThemeUtil::getIDFromName(UserUtil::getTheme())); if (file_exists($file = 'themes/' . $theme['directory'] . '/functions/' . $modname . "/{$type}{$ftype}/{$func}.php") || file_exists($file = 'themes/' . $theme['directory'] . '/functions/' . $modname . "/pn{$type}{$ftype}/{$func}.php")) { include_once $file; if (function_exists($modfunc)) { EventUtil::notify($preExecuteEvent); $postExecuteEvent->setData($modfunc($args)); return EventUtil::notify($postExecuteEvent)->getData(); } } } if (file_exists($file = "config/functions/{$modname}/{$type}{$ftype}/{$func}.php") || file_exists($file = "config/functions/{$modname}/pn{$type}{$ftype}/{$func}.php")) { include_once $file; if (is_callable($modfunc)) { $eventManager->notify($preExecuteEvent); $postExecuteEvent->setData($modfunc($args)); return $eventManager->notify($postExecuteEvent)->getData(); } } if (file_exists($file = "{$path}/{$modname}/{$type}{$ftype}/{$func}.php") || file_exists($file = "{$path}/{$modname}/pn{$type}{$ftype}/{$func}.php")) { include_once $file; if (is_callable($modfunc)) { $eventManager->notify($preExecuteEvent); $postExecuteEvent->setData($modfunc($args)); return $eventManager->notify($postExecuteEvent)->getData(); } } // try to load plugin // This kind of eventhandler should // 1. Check $event['modfunc'] to see if it should run else exit silently. // 2. Do something like $result = {$event['modfunc']}({$event['args'}); // 3. Save the result $event->setData($result). // 4. $event->setNotify(). // return void // This event means that no $type was found $event = new Zikula_Event('module_dispatch.type_not_found', null, array('modfunc' => $modfunc, 'args' => $args, 'modinfo' => $modinfo, 'type' => $type, 'api' => $api), false); $eventManager->notify($event); if ($preExecuteEvent->isStopped()) { return $preExecuteEvent->getData(); } return false; } // Issue not found exception for controller requests if (!System::isLegacyMode() && !$api) { throw new Zikula_Exception_NotFound(__f('The requested controller action %s_Controller_%s::%s() could not be found', array($modname, $type, $func))); } }
public static function moduleservices(Zikula_Event $event) { // check if this is for this handler $subject = $event->getSubject(); if (!($event['method'] == 'moduleservices' && strrpos(get_class($subject), '_Controller_Admin'))) { return; } $moduleName = $subject->getName(); if (!SecurityUtil::checkPermission($moduleName.'::', '::', ACCESS_ADMIN)) { return LogUtil::registerPermissionError(); } $view = Zikula_View::getInstance('Extensions', false); $view->assign('currentmodule', $moduleName); // notify EVENT here to gather any system service links $localevent = new Zikula_Event('module_dispatch.service_links', $subject, array('modname' => $moduleName)); EventUtil::notify($localevent); $sublinks = $localevent->getData(); $view->assign('sublinks', $sublinks); $event->setData($view->fetch('extensions_hookui_moduleservices.tpl')); $event->stop(); }
/** * Filter results for a given getTheme() type. * * @param string $themeName Theme name. * @param string $type Event type. * * @return string Theme name */ private static function _getThemeFilterEvent($themeName, $type) { $event = new Zikula_Event('user.gettheme', null, array('type' => $type), $themeName); return EventUtil::notify($event)->getData(); }
/** * Post-Process the basic object validation with class specific logic. * * Subclasses can define appropriate implementations. * * @param string $type Controller type. * @param array $data Data to be used for validation. * * @return boolean */ public function validatePostProcess($type = 'user', $data = null) { // empty function, should be implemented by child classes. EventUtil::notify(new Zikula_Event('dbobjectarray.validatepostprocess', $this)); return true; }
/** * Post-Process the basic object validation with class specific logic. * * Subclasses can define appropriate implementations. * * @param string $type Controller type. * @param array $data Data to be used for validation. * * @return boolean */ public function validatePostProcess($type = 'user', $data = null) { EventUtil::notify(new Zikula_Event('dbobject.validatepostprocess', $this)); return true; }
/** * Format a variable for HTML display. This method is recursive array safe. * * @param string $var The variable to format. * * @return string The formatted variable. */ public static function formatForDisplayHTML($var) { // This search and replace finds the text 'x@y' and replaces // it with HTML entities, this provides protection against // email harvesters // // Note that the use of \024 and \022 are needed to ensure that // this does not break HTML tags that might be around either // the username or the domain name static $search = array( '/([^\024])@([^\022])/se'); static $replace = array('"&#" . sprintf("%03d", ord("\\1")) . ";@&#" . sprintf("%03d", ord("\\2")) . ";";'); static $allowedtags = null; static $outputfilter; static $event; if (!$event) { $event = new Zikula_Event('system.outputfilter'); } if (!isset($allowedtags)) { $allowedHTML = array(); $allowableHTML = System::getVar('AllowableHTML'); if (is_array($allowableHTML)) { foreach ($allowableHTML as $k => $v) { if ($k == '!--') { if ($v != 0) { $allowedHTML[] = "$k.*?--"; } } else { switch ($v) { case 0: break; case 1: $allowedHTML[] = "/?$k\s*/?"; break; case 2: $allowedHTML[] = "/?\s*$k" . "(\s+[\w:]+\s*=\s*(\"[^\"]*\"|'[^']*'))*" . '\s*/?'; break; } } } } if (count($allowedHTML) > 0) { $allowedtags = '~<\s*(' . implode('|', $allowedHTML) . ')\s*>~is'; } else { $allowedtags = ''; } } if (!isset($outputfilter)) { if (ModUtil::available('SecurityCenter') && !System::isInstalling()) { $outputfilter = System::getVar('outputfilter'); } else { $outputfilter = 0; } } if (is_array($var)) { foreach ($var as $k => $v) { $var[$k] = self::formatForDisplayHTML($v); } } else { // Run additional filters if ($outputfilter > 0) { $event->setData($var)->setArg('filter', $outputfilter); $var = EventUtil::notify($event)->getData(); } // Preparse var to mark the HTML that we want if (!empty($allowedtags)) { $var = preg_replace($allowedtags, "\022\\1\024", $var); } // Encode email addresses $var = preg_replace($search, $replace, $var); // Fix html entities $var = htmlspecialchars($var); // Fix the HTML that we want $var = preg_replace_callback('#\022([^\024]*)\024#', create_function('$m', 'return DataUtil::formatForDisplayHTML_callback($m);'), $var); // Fix entities if required if (System::getVar('htmlentities')) { $var = preg_replace('/&([a-z#0-9]+);/i', "&\\1;", $var); } } return $var; }