public function display($index) { $index = url_title($index); $module_name = $this->config->segments_url[0]; $base_url = implode('/', in_array($index, $segments = array_offset_left($this->config->segments_url)) ? $this->_url_position == 'end' ? array_offset_right($segments) : array_offset_left($segments) : $segments); $tabs = array('panes' => array(), 'sections' => array()); $i = 0; foreach ($this->_tabs as $tab) { if (isset($tab['url'])) { $tab['url'] = url_title($tab['url']); $tabs['sections'][] = array('active' => $tab['url'] == $index, 'url' => $tab['url'] == $this->_default_tab ? '' : $tab['url'], 'name' => $tab['name']); if ($tab['url'] == $index) { $tabs['panes'][] = array('args' => $tab['args'], 'id' => $tab['url'], 'function' => $tab['function']); } $i++; } else { $languages = $this->db->select('code', 'name', 'flag')->from('nf_settings_languages')->order_by('`order`')->get(); foreach ($languages as $lang) { $code = $index; if ($i == 0) { if ($index != array_last($this->config->segments_url)) { $index = $code = $lang['code']; } else { $code = NULL; } } $tabs['sections'][] = array('active' => $lang['code'] == $code, 'url' => $i == 0 ? '' : $lang['code'], 'name' => '<img src="' . image('flags/' . $lang['flag']) . '" alt="" />' . $lang['name']); if ($lang['code'] == $index) { $tabs['panes'][] = array('args' => array_merge($tab['args'], array($index)), 'id' => $lang['code'], 'function' => $tab['function']); } $i++; } } } foreach ($tabs['sections'] as $section) { if ($is_good = $section['active']) { break; } } if (!isset($is_good) || !$is_good || array_last($this->config->segments_url) == $this->_default_tab) { throw new Exception(NeoFrag::UNFOUND); } $output = ' <div class="tabbable"> <ul class="nav nav-tabs">'; foreach ($tabs['sections'] as $section) { $output .= ' <li' . ($section['active'] ? ' class="active"' : '') . '><a href="' . url($module_name . '/' . trim($this->_url_position == 'end' ? $base_url . '/' . $section['url'] : $section['url'] . '/' . $base_url, '/') . '.html') . '">' . $section['name'] . '</a></li>'; } $output .= ' </ul> <div class="tab-content">'; $caller = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 2)[1]['object']; foreach ($tabs['panes'] as $pane) { $output .= ' <div class="tab-pane active" id="' . $pane['id'] . '"> ' . (string) $caller->method($pane['function'], $pane['args']) . ' </div>'; } $output .= ' </div> </div>'; return $output; }
public function phpinfo() { $this->title($this('server'))->subtitle('PHP ' . phpversion())->css('phpinfo'); $extensions = get_loaded_extensions(); natcasesort($extensions); ob_start(); phpinfo(); $output = array(new Panel(array('content' => $this->load->view('phpinfo', array('extensions' => $extensions))))); if (preg_match_all('#(?:<h2>(.*?)</h2>.*?)?<table.*?>(.*?)</table>#s', ob_get_clean(), $matches, PREG_SET_ORDER)) { foreach (array_offset_left($matches) as $match) { $output[] = new Panel(array('title' => $match[1], 'content' => '<table class="table table-hover table-striped">' . $match[2] . '</table>')); } } return $output; }
public function __construct() { parent::__construct(); $segments = $this->config->segments_url; if ($segments[0] == 'index') { $segments[0] = $this->config->nf_default_page; } if ($this->config->admin_url && $this->config->request_url != 'admin.html') { $segments = array_offset_left($segments); } if ($this->config->ajax_url) { $segments = array_offset_left($segments); } $this->load->theme($this->user('theme') ?: $this->config->nf_default_theme); $this->_check_invalid_characters(); $this->_check_consecutive_slashes(); $this->_check_extension(); if ($this->_invalid_characters && $this->_consecutive_slashes) { if ($this->_extension) { if ($this->config->site != 'default' && $this->config->segments_url[0] != 'index') { array_unshift($segments, $this->config->nf_default_page); } $this->load->module(array_shift($segments), $segments); if ($this->config->admin_url) { $this->load->theme('admin'); } return; } } if (!$this->_invalid_characters || !$this->_consecutive_slashes || !$this->_extension) { /* TODO * Charger le module d'erreur pour proposer une URL correcte ou des éléments de recherche * Mettre un HEADER HTTP de redirection vers la page corrigée (si elle existe et qu'elle est unique) */ $this->load->module('error'); } }
function trim_word($string, $word) { $word = implode('|', array_map(create_function('$a', 'return preg_quote($a, \'/\');'), array_offset_left(func_get_args()))); return preg_replace('/^(' . $word . ')*(.*?)(' . $word . ')*$/', '\\2', $string); }
public function get_method(&$args, $ignore_ajax = FALSE) { $url = ''; if ($this->config->admin_url) { $url .= 'admin'; } if ($this->config->ajax_url && !$ignore_ajax) { $url .= '/ajax'; } $url = ltrim($url, '/'); if ($url) { foreach (array_keys($this->routes) as $route) { if (!preg_match('#^' . $url . '#', $route)) { unset($this->routes[$route]); } } $url .= '/'; } $url .= implode('/', $args); $method = NULL; foreach ($this->routes as $route => $function) { if (preg_match('#^' . str_replace(array_map(function ($a) { return '{' . $a . '}'; }, array_keys(self::$patterns)) + array('#'), array_values(self::$patterns) + array('\\#'), $route) . '$#', $url, $matches)) { $args = array(); if (in_string('{url_title*}', $route)) { foreach (array_offset_left($matches) as $arg) { $args = array_merge($args, explode('/', $arg)); } } else { $args = array_offset_left($matches); } $args = array_map(function ($a) { return trim($a, '/'); }, $args); $method = $function; break; } } return $method; }
public function module($name) { $args = array(); foreach (array_offset_left(func_get_args()) as $arg) { if (is_array($arg)) { $args = array_merge($args, $arg); } else { $args[] = $arg; } } if (func_num_args() == 1 && in_string('/', $name)) { $args = explode('/', $name); $name = $args[0]; $args = array_offset_left($args); } $init = ($backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3)) && isset($backtrace[2]['function']) && $backtrace[2]['function'] == 'init_module'; $module_name = str_replace('-', '_', $name); if (in_array($module_name, array_keys(array_filter($this->addons('module'))))) { reset($this->paths['modules']); while (list(, $path) = each($this->paths['modules'])) { if (!file_exists($module_path = $path . '/' . $module_name . '/' . $module_name . '.php')) { continue; } if (!$init) { $this->profiler->log('Module ' . $module_name . ' chargé : ' . $path, Profiler::INFO); } $module_class = 'm_' . $module_name; if (in_string('/overrides/', $module_path)) { while (list(, $path) = each($this->paths['modules'])) { if (!file_exists($o_module_path = $path . '/' . $module_name . '/' . $module_name . '.php')) { continue; } include_once $o_module_path; break; } $module_class = 'o_' . $module_class; } include_once $module_path; $module = new $module_class($module_name); if (method_exists($module, 'load') && !$init) { $module->load(); } if (is_null(NeoFrag::loader()->module) && !$init) { NeoFrag::loader()->module =& $module; $module->run($args); } return $module; } } if ($init) { return NULL; } if ($this->config->admin_url) { return call_user_func_array(array($this, 'module'), array_merge(array('admin', $module_name), $args)); } if (!$this->config->admin_url && !$this->config->ajax_url) { return $this->module('pages', $name); } return $this->module('error'); }
public function display($base_url, $nb_pages, $size = 'sm', $items_per_page = 0, $fixed = TRUE, $current_page = 0) { if (!in_array($size, array('xs', 'sm', 'lg'))) { $size = 'sm'; } if ($items_per_page) { $nb_pages = ceil($nb_pages / $items_per_page); } $range = range(1, $nb_pages); if ($nb_pages >= 7) { if ($current_page >= 5 && $nb_pages - $current_page >= 5) { $range = array_merge(array(1, 2, '...'), range($current_page - 1, $current_page + 1), array('...'), array_offset_left($range, -2)); } else { if ($current_page > 1 && $current_page < 5) { $range = array_merge(range(1, $current_page + 1), array('...'), array_offset_left($range, -2)); } else { if ($current_page < $nb_pages && $nb_pages - $current_page < 5) { $range = array_merge(range(1, 2), array('...'), array_offset_left($range, $current_page - 2)); } else { $range = array_merge(array(1, 2, '...'), array_offset_left($range, -2)); } } } } $buttons = array(); foreach ($range as $p) { if ($p == '...') { $buttons[] = '<span class="btn btn-default btn-' . $size . '">' . $p . '</span>'; } else { $buttons[] = '<a class="btn btn-default btn-' . $size . ($current_page == $p ? ' active' : '') . '" href="' . $base_url . ($p > 1 ? '/page/' . $p . (!$fixed ? '/' . $items_per_page : '') : '') . '.html">' . $p . '</a>'; } } return '<div class="pagination">' . implode(' ', $buttons) . '</div>'; }
public function query($query) { $args = array(); foreach (array_offset_left(func_get_args()) as $arg) { $args[] = $this->_driver->escape_string($arg); } $this->_request['query'] = vsprintf($query, $args); return $this; }