コード例 #1
0
ファイル: hours.php プロジェクト: AdrianBav/boomersparks
 public function index()
 {
     // Get the year and month from the URL
     $year = $this->uri->segment(3, $this->current_year);
     $month = $this->uri->segment(4, $this->current_month);
     if (!is_numeric($year) || !is_numeric($month)) {
         return show_404();
     }
     // Disallow users to view any time period before the current month
     $when = calendar_when($year, $month, $this->current_year, $this->current_month);
     if ($when == 'past') {
         $year = $this->current_year;
         $month = $this->current_month;
     }
     // If current month has no events, find next active month
     if (!has_events($year, $month)) {
         $next_active_date = get_next_active_date($year, $month);
         if ($next_active_date === false) {
             // No future dates in the database
             $calendar_html = '<h2>No future dates.</h2>';
             $this->render($calendar_html, $when);
             return;
         } else {
             // Jump to next active month
             $year = $next_active_date['year'];
             $month = $next_active_date['month'];
             // Set a flag indicating that we have skipped blank months
             if (!$this->session->userdata('skipped_blank_months')) {
                 $jump_data = array('skipped_blank_months' => TRUE, 'jumped_to_year' => $year, 'jumped_to_month' => $month);
                 $this->session->set_userdata($jump_data);
             }
             $slugs = $this->uri->slash_segment(1, 'leading') . $this->uri->slash_segment(2, 'leading');
             redirect("{$slugs}/{$year}/{$month}");
         }
     }
     if ($this->session->userdata('skipped_blank_months')) {
         $jumped_to_year = $this->session->userdata('jumped_to_year');
         $jumped_to_month = $this->session->userdata('jumped_to_month');
         if ($jumped_to_year == $year && $jumped_to_month == $month) {
             $when .= ' skipped';
         }
     }
     // Load the park hours and events
     $this->load->model('park_events_model');
     $events_html = $this->park_events_model->get_events_html($year, $month, $this->settings->site_id);
     // Generate the calendar
     $prefs = array('day_type' => $this->config->item('calendar_day_type'), 'show_next_prev' => $this->config->item('calendar_show_next_prev'), 'next_prev_url' => base_url() . $this->uri->slash_segment(1, 'trailing') . $this->uri->slash_segment(2, 'trailing'), 'template' => $this->config->item('calendar_template'));
     $this->load->library('calendar', $prefs);
     $calendar_html = $this->calendar->generate($year, $month, $events_html);
     // Render the calendar
     $this->render($calendar_html, $when);
 }
コード例 #2
0
/**
 *	get_item( 'namespace' , 'associated_items' );
 *	events : set_items_vars
 **/
function get_items($namespace)
{
    $saved_items = get_active_theme_vars('theme_items');
    $style = return_if_array_key_exists($namespace, $saved_items);
    if ($style) {
        $has_loop = return_if_array_key_exists('has_loop', $style);
        $before_loop = return_if_array_key_exists('before_loop', $style);
        $after_loop = return_if_array_key_exists('after_loop', $style);
        $the_loop_item = return_if_array_key_exists('the_loop_item', $style);
        $is_static = return_if_array_key_exists('item_loopable_fields', $style) || return_if_array_key_exists('item_global_fields', $style);
        // Si l'élément est statique
        if ($is_static) {
            // $datas		=	$style;
            $th_setting = get_active_theme_vars('theme_settings');
            $datas = return_if_array_key_exists($namespace, $th_setting);
        } else {
            // Recupération depuis l'API
            $global_data = get_active_theme_vars("items_datas");
            // Recupérations depuis les données renvoyés
            $datas = return_if_array_key_exists($namespace, $global_data);
        }
        if (is_array($datas)) {
            if (has_events('handle_' . $namespace)) {
                return trigger_events('handle_' . $namespace, $datas);
            } else {
                echo $before_loop;
                if ($has_loop === true) {
                    // Looping Defined Vars and set them as variables
                    foreach ($datas as $value) {
                        if (is_array($value)) {
                            foreach ($value as $key => $value) {
                                // les key sont celles sur le tableau renvoyé par l'API
                                ${$key} = $value;
                                // If there are events declared
                                if (has_events('set_' . $namespace . '_items_vars')) {
                                    ${$key} = trigger_events('set_' . $namespace . '_items_vars', array($key, $value));
                                    // if triggered events return null, we don't consider events
                                    if (${$key} == null) {
                                        ${$key} = $value;
                                    }
                                }
                            }
                        }
                        // Looping the_loop_item as set on declare_items
                        if (is_array($the_loop_item)) {
                            foreach ($the_loop_item as $lines) {
                                if (has_events('loop_' . $namespace . '_lines')) {
                                    $result = trigger_events('loop_' . $namespace . '_lines', array($lines));
                                    $lines = $result == null ? $lines : $result;
                                }
                                if (substr($lines, 0, 1) == "[" && substr($lines, -1) == "]") {
                                    $var = substr($lines, 1, -1);
                                    echo isset(${$var}) ? ${$var} : $lines;
                                } else {
                                    echo $lines;
                                }
                            }
                        }
                    }
                }
                echo $after_loop;
            }
        }
    }
}
コード例 #3
0
/**
 *	trigger_events() : déclenche les évenements attachés
 **/
function trigger_events($events, $params = array())
{
    if ($current_events = has_events($events)) {
        $result;
        foreach ($current_events as $event) {
            if (is_string($event)) {
                if (function_exists($event)) {
                    $result = $event($params);
                }
            } else {
                if (is_array($event)) {
                    if (is_object($event[0])) {
                        if (method_exists($event[0], $event[1])) {
                            $result = $event[0]->{$event}[1]($params);
                        }
                    }
                }
            }
        }
        return $result != null ? $result : false;
    }
    return false;
}