until() public static method

Fire an event until the first non-null response is returned.
public static until ( string | object $event, array $payload = [] ) : mixed
$event string | object
$payload array
return mixed
Example #1
0
 function get_dl($id = null)
 {
     $digitless = ltrim($id, '0..9');
     // file link can be either
     if ($digitless === '' or $digitless[0] === '.') {
         $file = File::find(strtok($id, '.'));
     } else {
         $file = File::where('name', '=', $id)->get();
     }
     if (!$file) {
         return;
     } elseif ($this->can('file.dl.deny.' . $file->id)) {
         return false;
     } else {
         $path = $file->file();
         $override = Event::until('file.dl.before', array(&$path, &$file, $this));
         if ($override !== null) {
             return $override;
         } elseif (!$file instanceof File) {
             return E_SERVER;
         } else {
             // In case the model was changed during event firing.
             $file->save();
             return Event::until('file.dl.response', array(&$path, $file, $this));
         }
     }
 }
Example #2
0
 function prereq()
 {
     if (!Cart::has()) {
         return $this->back();
     } elseif ($this->can('checkout.deny')) {
         return false;
     } elseif (Event::until('checkout.can', $this) === false) {
         return $this->back();
     }
 }
Example #3
0
 static function initMiMeil()
 {
     $prefix = static::$eventPrefix;
     static::$onEvent = function ($event, $args) use($prefix) {
         return Event::until($prefix . $event, $args);
     };
     static::registerEventsUsing(array(get_called_class(), 'listen'));
     // saves outgoing messages in a local folder if enabled in the config.
     static::listen('transmit', function (&$subject, &$headers, &$body, $mail) {
         if ($path = $mail->echoPath) {
             $mail->saveEML($subject, $headers, $body, rtrim($path, '\\/') . '/');
         }
     });
 }
Example #4
0
 public function get_nav($menu = '', $partial_path = null)
 {
     if (\Event::listeners("menu.render.navigation: {$menu}")) {
         $result = \Event::until("menu.render.navigation: {$menu}");
         if (!is_null($result)) {
             if ($result instanceof \DOMDocument) {
                 return $result->saveHTML();
             } elseif (is_string($result)) {
                 return $result;
             } elseif (is_array($result)) {
                 return Dom::arrayToDOMDocument($result)->saveHTML();
             } else {
                 throw new \Exception("Menu event response is invalid. Supported responses are: [DOMDocument], [String], [Array]");
             }
         }
     }
     $navigation_group = \Navigation\Model\Group::with(array('links' => function ($query) {
         $query->order_by('order', 'asc');
     }))->where('slug', '=', $menu)->first();
     // This navigation group is available?
     if (isset($navigation_group) and !empty($navigation_group)) {
         $items = $navigation_group->get_links();
         if (\Event::listeners("menu.merge.navigation: {$menu}", array($items))) {
             $result = \Event::until("menu.merge.navigation: {$menu}", array($items));
             $items = array_merge_recursive($items, $result);
             sort($items);
         }
         if (\Event::listeners("menu.make.navigation: {$menu}", array($items))) {
             $items = \Event::until("menu.make.navigation: {$menu}", array($items));
         }
         if (\Event::listeners("menu.make.navigation", array($items))) {
             $items = \Event::until("menu.make.navigation", array($items));
         }
         return $this->make($items, '', $partial_path);
     } else {
         return 'ERROR: The navigation group [' . $menu . '] does not exist.';
     }
 }
Example #5
0
 static function isTooSmall($subtotal = null)
 {
     isset($subtotal) or $subtotal = static::subtotal();
     $min = Event::until('cart.is_small', array(&$subtotal));
     if (is_int($min) or is_float($min)) {
         return $min;
     }
 }
Example #6
0
 static function not_found(array $info, $page)
 {
     $page404 = static::option('404', '_404');
     $response = null;
     if (is_callable($page404)) {
         $response = call_user_func($page404, $info, $page);
         if (is_array($response)) {
             $response = static::render($response, $info + static::options());
         }
     } elseif ($page404 !== false) {
         $info = array('cache' => false, 'page_404' => $page) + $info;
         $parts = explode('/', str_replace('\\', '/', $page));
         do {
             array_pop($parts);
             $error = join(DS, $parts) . DS . $page404;
             $response = static::serve($info, $error);
         } while ($parts and !$response);
         $response and $response = static::format_404($response, $info, $page, $error);
     }
     if (!isset($response) or $response === false) {
         $response = Event::until(404);
     }
     return $response;
 }
Example #7
0
 function used()
 {
     if (Event::until('file.used', $this)) {
         return $this;
     } else {
         throw new Error("Cannot update usage counter of File [{$model->id}].");
     }
 }
Example #8
0
 function ajax_post_add($type = null, $object = null)
 {
     $object = (int) $object;
     $parent = $this->in('parent', 0) ?: null;
     $eventOptions = compact('type', 'object') + array('block' => $this);
     if (!$this->in('body', '')) {
         $body = Event::until('post.bodyless', array($eventOptions));
         if (isset($this->input)) {
             $this->input['body'] = $body;
         } else {
             Input::merge(compact('body'));
         }
     }
     $valid = Validator::make($this->in(), array('parent' => 'int', 'title' => 'max:50', 'body' => 'required'));
     if (!$type) {
         return E_INPUT;
     } elseif (!$this->accessible('add', $object, $parent)) {
         return false;
     } elseif ($valid->fails()) {
         return $valid;
     } else {
         $model = with(new Post())->fill_raw(Input::only(array('title', 'body')))->fill_raw(compact('type') + array('object' => $object, 'parent' => $parent, 'flags' => $this->can('manager') ? 'manager' : '', 'html' => format('post', $this->in('body')), 'author' => $this->user()->id, 'ip' => Request::ip()));
         $eventOptions['post'] = $model = Event::insertModel($model, 'post');
         if (!$model) {
             return E_SERVER;
         }
         try {
             $attachments = array();
             Event::fire('post.attach', array(&$attachments, $eventOptions));
         } catch (\Exception $e) {
             $model->delete();
             throw $e;
         }
         $eventOptions += compact('attachments');
         Event::fire('post.added', array($eventOptions));
         if ($type and $object and $object = $model->object()->first()) {
             Event::fire('post.object_ref', array(&$object, $eventOptions));
             $object instanceof LaravelModel and $object->save();
         }
         return $model;
     }
 }
Example #9
0
 public function get_index()
 {
     $opensim_db_is_ready = Config::get('settings::core.passes_db_settings');
     if (!(bool) $opensim_db_is_ready) {
         return Redirect::to('404');
     }
     $show_regions_list = Config::get('settings::core.splashscreen_show_regions_list');
     $this->data['regions'] = array();
     if ($show_regions_list == 'yes') {
         $this->data['regions'] = Opensim\Model\Os\Region::order_by('last_seen', 'desc')->get();
     }
     $show_grid_status_block = Config::get('settings::core.splashscreen_show_grid_status_block');
     $this->data['grid_status_block'] = array();
     if ($show_grid_status_block == 'yes') {
         $show_grid_status = Config::get('settings::core.splashscreen_grid_status');
         if ($show_grid_status) {
             $this->data['grid_status_block']['grid_status'] = Config::get('settings::core.splashscreen_grid_status');
             $show_total_users = Config::get('settings::core.splashscreen_show_total_users');
             if ($show_total_users == 'yes') {
                 $this->data['grid_status_block']['total_users'] = Opensim\Model\Os\UserAccount::count();
             }
             $show_total_regions = Config::get('settings::core.splashscreen_show_total_regions');
             if ($show_total_regions == 'yes') {
                 $this->data['grid_status_block']['total_regions'] = Opensim\Model\Os\Region::count();
             }
             $show_active_users = Config::get('settings::core.splashscreen_show_active_users');
             if ($show_active_users == 'yes') {
                 $this->data['grid_status_block']['active_users'] = DB::connection('opensim')->table('GridUser')->where('Login', '>=', strtotime("-30 days"))->count();
                 //time()-2592000);
             }
             $show_users_online = Config::get('settings::core.splashscreen_show_online_users');
             if ($show_users_online == 'yes') {
                 // Because users can get stuck
                 // we will just count presences
                 // newer then 2 days ago
                 $this->data['grid_status_block']['users_online'] = \DB::connection('opensim')->table('Presence')->join('GridUser', 'GridUser.UserID', '=', 'Presence.UserID')->where('Presence.LastSeen', '>', strtotime("-2 days"))->where('GridUser.Online', '=', 'true')->count();
             }
         }
     }
     $show_status_block_message = Config::get('settings::core.splashscreen_show_grid_status_message_block');
     if ($show_status_block_message == 'yes') {
         $this->data['status_message_block'] = array('color' => Config::get('settings::core.splashscreen_grid_status_message_block_color'), 'title' => Config::get('settings::core.splashscreen_grid_status_message_block_title'), 'text' => Config::get('settings::core.splashscreen_grid_status_message_block_body'));
     }
     $show_left_block = Config::get('settings::core.splashscreen_show_top_left_block');
     if ($show_left_block == 'yes') {
         $this->data['grid_status_block']['status_top_left_block'] = array('title' => Config::get('settings::core.splashscreen_top_left_block_title'), 'text' => Config::get('settings::core.splashscreen_top_left_block_body'));
     }
     //Get images for effect
     $this->data['effect'] = Config::get('settings::core.splashscreen_effect');
     $this->data['effect_delay'] = Config::get('settings::core.splashscreen_effect_time');
     // Find images for background effect
     if ($this->data['effect'] == 'loop_background') {
         $background_images_path = path('public') . 'bundles/splashscreen/img/backgrounds/';
         $background_images = array();
         foreach (glob($background_images_path . "*") as $filename) {
             $name = explode('/', $filename);
             $background_images[] = URL::base() . '/bundles/splashscreen/img/backgrounds/' . $name[count($name) - 1];
         }
         $this->data['images'] = $background_images;
     }
     if ($this->data['effect'] == 'time_of_day') {
         $background_images_path = path('public') . 'bundles/splashscreen/img/day_time_bkgs/';
         $background_images = array();
         foreach (glob($background_images_path . "*") as $filename) {
             $name = explode('/', $filename);
             $background_images[] = URL::base() . '/bundles/splashscreen/img/day_time_bkgs/' . $name[count($name) - 1];
         }
         $this->data['images'] = $background_images;
     }
     // Find logo image
     $logo_path = path('public') . 'bundles/splashscreen/img/logo/';
     $logo = '';
     foreach (glob($logo_path . "logo.*") as $filename) {
         $name = explode('/', $filename);
         $logo = $name[count($name) - 1];
     }
     $this->data['logo'] = $logo;
     $show_flash_news = Config::get('settings::core.splashscreen_show_flash_news');
     if ($show_flash_news == 'yes') {
         // We delegate the determination of news to the news loader event
         // so that the developer is free to override the news.
         $news = Event::until('splashscreen.load_news');
         if (!is_null($news)) {
             $this->data['news_handler'] = $news['handler'];
             $this->data['news'] = $news;
         } else {
             $news_handler = Config::get('settings::core.splashscreen_flash_news_handler');
             $this->data['news_handler'] = URL::base() . '/' . $news_handler . '/';
             $this->data['news'] = Splashscreen\Model\News::where_is_enabled(1)->order_by('created_at', 'desc')->take(4)->get();
         }
     }
     return View::make('splashscreen::frontend.splash_screen', $this->data);
 }
Example #10
0
function format($type, $text)
{
    return (string) Event::until('format.' . $type, array(&$text));
}
Example #11
0
 /**
  * Return partial view rendered
  * 
  * @param string $partial
  * @param array $data
  */
 public function render_partial($partial, $data = array())
 {
     if (\Event::listeners("themes.render.partial: {$partial}")) {
         $result = \Event::until("themes.render.partial: {$partial}", array($view));
         if (!is_null($result)) {
             if ($result instanceof \DOMDocument) {
                 $view = $result->saveHTML();
             } elseif (is_string($result)) {
                 $view = $result;
             } elseif (is_array($result)) {
                 // array to dom
                 $view = '<!DOCTYPE html>';
                 $view .= Dom::arrayToDOMDocument($result, 'html')->saveHTML();
             } else {
                 // trow exception
             }
         }
     }
     $data = $this->_share_data($data);
     $bundle_parts = \Bundle::parse($partial);
     $bundle_name = $bundle_parts['0'] == 'application' ? '' : $bundle_parts['0'] . DS;
     $partial_path = str_replace('.', DS, $bundle_parts['1']);
     $theme_view_folder = $this->_theme_absolute_path . DS . 'views' . DS;
     // Check for a custom path
     $has_partial = $this->_view_exists(str_replace('.', DS, $partial));
     if ($has_partial) {
         return View::make($has_partial, $data);
     }
     // Check on the themes views folder
     $has_partial = $this->_view_exists($theme_view_folder . $bundle_name . 'partials' . DS . $partial_path);
     if ($has_partial) {
         return View::make($has_partial, $data);
     }
     // Check on custom folder (fallback for all themes)
     $has_partial = $this->_view_exists(path('public') . 'custom' . DS . 'views' . DS . $bundle_name . 'partials' . DS . $partial_path);
     if ($has_partial) {
         return View::make($has_partial, $data);
     }
     // bundles folder
     $has_partial = $this->_view_exists($partial);
     if ($has_partial) {
         return View::make($has_partial, $data);
     }
     // try to load from application views folder
     $has_partial = $this->_view_exists('partials' . DS . $partial_path);
     if ($has_partial) {
         return View::make($has_partial, $data);
     }
     Log::error('Failed to render partial from ' . $partial);
     throw new \Exception("Failed to render partial. Partial [{$partial}] doesn't exist. ");
 }
Example #12
0
 function editable(Order $order)
 {
     return Event::until('order.editable', array($order, $this)) !== false;
 }
Example #13
0
 function isOf(User $user = null)
 {
     return Event::until('order.belongs', array($this, $user)) !== false;
 }