/** * fires actions bound to body class routes */ function route() { do_action("WXP.DomRoute.before"); $body_class = get_body_class(); //add 'common' to the body class array array_unshift($body_class, 'common'); //apply filters to body classes $body_class = apply_filters("WXP.DomRoute.body_classes", $body_class); //return false if no routes set if (empty($this->routes)) { return false; } foreach ($this->routes as $route_hook => $actions) { //if $action has the class key that means an action //was bound to multiple classes and wont be fired unless //all of those classes are present if (isset($actions["class"])) { $found = true; foreach ($actions["class"] as $cls) { $found = in_array($cls, $body_class); if (!$found) { break; } } //if all classes are not found skip to next route if (!$found) { continue; } //else if all classes are found set $actions with the value $actions = (array) $actions['action']; } else { if (!in_array($route_hook, $body_class)) { continue; } } //fire actions if not in $called_callbacks array foreach ($actions as $action) { if (is_string($action) && isset($this->called_callbacks[$action])) { //if value is set to true, that means the //callback has been called already //skip to next action if ($this->called_callbacks[$action] === true) { continue; } //else the callback has not been fired yet //set value to true to prevent it from being fired //again in another route $this->called_callbacks[$action] = true; } //finally fire the callback/action WXP::call_target($action, array(View::getInstance()), true); } } do_action("WXP.DomRoute.after"); }