added the script link or tag html helper to new CI3 framweork * new function script_js that just sourcered a tag with embebed one * addressed at https://github.com/codeigniter4/CodeIgniter4/issues/209#issuecomment-238702066 * backported from https://github.com/codeigniter4/CodeIgniter4/commit/caf9f2330e9686a478a915d7bc9868abf813e151 * solves the original idea of PR https://github.com/bcit-ci/CodeIgniter/pull/2335
fix error extra semi colon in script_tag
implement string single parameters in loader class * bcit-ci/CodeIgniter#216 backported the commit allowing library constructs to take query strings for parameters, as well as an array. * backported commit bcit-ci/CodeIgniter@aab4f59 but in better way.. more didactically * take from codeigniterpowered commit c0c29eba031b0f3b09682e75889a82423697cd43
fix profiler lib for CI3 .. * TODO pending to backport to the profiler project
fix default controler and route for CI3
| ... | ... | @@ -211,9 +211,11 @@ class CI_Loader { |
| 211 | 211 | return $this;
|
| 212 | 212 | }
|
| 213 | 213 | |
| 214 | - if ($params !== NULL && ! is_array($params))
|
|
| 214 | + if ( $params !== NULL && ! is_array($params))
|
|
| 215 | 215 | {
|
| 216 | - $params = NULL;
|
|
| 216 | + $newparms = array();
|
|
| 217 | + parse_str($newparams, $params); // https://github.com/bcit-ci/CodeIgniter/issues/216
|
|
| 218 | + $params = $newparms;
|
|
| 217 | 219 | }
|
| 218 | 220 | |
| 219 | 221 | $this->_ci_load_library($library, $params, $object_name);
|
| ... | ... | @@ -260,6 +260,83 @@ if ( ! function_exists('doctype')) |
| 260 | 260 | |
| 261 | 261 | // ------------------------------------------------------------------------
|
| 262 | 262 | |
| 263 | +if (! function_exists('script_js')) {
|
|
| 264 | + /**
|
|
| 265 | + * Script
|
|
| 266 | + *
|
|
| 267 | + * Generates tags of javascript embebed codes
|
|
| 268 | + *
|
|
| 269 | + * @param array|string $src Script source or an array of scrits sources
|
|
| 270 | + * @param array|string $atributes Sabtibutes or array of atributes taht will be put in all the tags
|
|
| 271 | + * @param bool $xhtml will be XHTML or just simple HTML one to put CDATA inside
|
|
| 272 | + */
|
|
| 273 | + function script_js($src = '', $atributes = '', $xhtml = FALSE)
|
|
| 274 | + {
|
|
| 275 | + $script = '';
|
|
| 276 | + |
|
| 277 | + if ( ! is_array($src)) {
|
|
| 278 | + $src = ['src' => $src];
|
|
| 279 | + }
|
|
| 280 | + |
|
| 281 | + if ( ! is_array($src)) {
|
|
| 282 | + $satribs = $atributes;
|
|
| 283 | + }
|
|
| 284 | + else {
|
|
| 285 | + foreach ($atributes as $k => $v) {
|
|
| 286 | + // for attributes without values, like async or defer, use NULL.
|
|
| 287 | + $satribs .= $k . (null === $v ? ' ' : '="' . $v . '" ');
|
|
| 288 | + }
|
|
| 289 | + }
|
|
| 290 | + |
|
| 291 | + foreach ($src as $k => $v) {
|
|
| 292 | + $script .= '<script type="text/javascript"' . $satribs . '>' . PHP_EOL;
|
|
| 293 | + if ( $xtml ) $script .= '//<![CDATA[' . PHP_EOL;
|
|
| 294 | + $script .= $v . PHP_EOL;
|
|
| 295 | + if ( $xtml ) $script .= '//]]>' . PHP_EOL;
|
|
| 296 | + $script .= '</script>' . PHP_EOL;
|
|
| 297 | + }
|
|
| 298 | + |
|
| 299 | + return $script;
|
|
| 300 | + }
|
|
| 301 | +}
|
|
| 302 | + |
|
| 303 | +// ------------------------------------------------------------------------
|
|
| 304 | + |
|
| 305 | +if (! function_exists('script_tag')) {
|
|
| 306 | + /**
|
|
| 307 | + * Script
|
|
| 308 | + *
|
|
| 309 | + * Generates link to a JS file
|
|
| 310 | + *
|
|
| 311 | + * @param array|string $src Script source or an array of attributes
|
|
| 312 | + * @param bool $indexPage Should indexPage be added to the JS path
|
|
| 313 | + */
|
|
| 314 | + function script_tag($src = '', bool $indexPage = FALSE)
|
|
| 315 | + {
|
|
| 316 | + $script = '<script';
|
|
| 317 | + if (! is_array($src)) {
|
|
| 318 | + if ( strpos($src, 'src') )
|
|
| 319 | +
|
|
| 320 | + $src = ['src' => $src];
|
|
| 321 | + }
|
|
| 322 | + |
|
| 323 | + foreach ($src as $k => $v) {
|
|
| 324 | + if ($k === 'src' && ! preg_match('#^([a-z]+:)?//#i', $v)) {
|
|
| 325 | + if ($indexPage === true) {
|
|
| 326 | + $script .= 'src="' . site_url($v) . '" ';
|
|
| 327 | + }
|
|
| 328 | + } else {
|
|
| 329 | + // for attributes without values, like async or defer, use NULL.
|
|
| 330 | + $script .= $k . (null === $v ? ' ' : '="' . $v . '" ');
|
|
| 331 | + }
|
|
| 332 | + }
|
|
| 333 | + |
|
| 334 | + return $script . 'type="text/javascript"></script>';
|
|
| 335 | + }
|
|
| 336 | +}
|
|
| 337 | + |
|
| 338 | +// ------------------------------------------------------------------------
|
|
| 339 | + |
|
| 263 | 340 | if ( ! function_exists('link_tag'))
|
| 264 | 341 | {
|
| 265 | 342 | /**
|
| 1 | +<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
|
|
| 2 | + |
|
| 3 | +/*
|
|
| 4 | + Class: Console
|
|
| 5 | +
|
|
| 6 | + Provides several additional logging features designed to work
|
|
| 7 | + with the Forensics Profiler.
|
|
| 8 | +
|
|
| 9 | + Inspired by ParticleTree's PHPQuickProfiler. (http://particletree.com)
|
|
| 10 | +
|
|
| 11 | + Package:
|
|
| 12 | + Forensics
|
|
| 13 | +
|
|
| 14 | + Author:
|
|
| 15 | + Lonnie Ezell (http://lonnieezell.com)
|
|
| 16 | +
|
|
| 17 | + License:
|
|
| 18 | + MIT
|
|
| 19 | +*/
|
|
| 20 | +class CI_Console {
|
|
| 21 | + |
|
| 22 | + /*
|
|
| 23 | + Var: $logs
|
|
| 24 | + Contains all of the logs that are collected.
|
|
| 25 | + */
|
|
| 26 | + private static $logs = array(
|
|
| 27 | + 'console' => array(),
|
|
| 28 | + 'log_count' => 0,
|
|
| 29 | + 'memory_count' => 0,
|
|
| 30 | + );
|
|
| 31 | + |
|
| 32 | + /*
|
|
| 33 | + Var: $ci
|
|
| 34 | + An instance of the CI super object.
|
|
| 35 | + */
|
|
| 36 | + private static $ci;
|
|
| 37 | + |
|
| 38 | + //--------------------------------------------------------------------
|
|
| 39 | +
|
|
| 40 | + /*
|
|
| 41 | + Method: __construct()
|
|
| 42 | +
|
|
| 43 | + This constructor is here purely for CI's benefit, as this is a
|
|
| 44 | + static class.
|
|
| 45 | +
|
|
| 46 | + Return:
|
|
| 47 | + void
|
|
| 48 | + */
|
|
| 49 | + public function __construct()
|
|
| 50 | + {
|
|
| 51 | + self::init();
|
|
| 52 | +
|
|
| 53 | + log_message('debug', 'Forensics Console library loaded');
|
|
| 54 | + }
|
|
| 55 | +
|
|
| 56 | + //--------------------------------------------------------------------
|
|
| 57 | +
|
|
| 58 | + /*
|
|
| 59 | + Method: init()
|
|
| 60 | +
|
|
| 61 | + Grabs an instance of CI and gets things ready to run.
|
|
| 62 | + */
|
|
| 63 | + public static function init()
|
|
| 64 | + {
|
|
| 65 | + self::$ci =& get_instance();
|
|
| 66 | + }
|
|
| 67 | +
|
|
| 68 | + //--------------------------------------------------------------------
|
|
| 69 | +
|
|
| 70 | + /*
|
|
| 71 | + Method: log()
|
|
| 72 | +
|
|
| 73 | + Logs a variable to the console.
|
|
| 74 | +
|
|
| 75 | + Parameters:
|
|
| 76 | + $data - The variable to log.
|
|
| 77 | + */
|
|
| 78 | + public static function log($data=null)
|
|
| 79 | + {
|
|
| 80 | + if ($data !== 0 && empty($data))
|
|
| 81 | + {
|
|
| 82 | + $data = 'empty';
|
|
| 83 | + }
|
|
| 84 | +
|
|
| 85 | + $log_item = array(
|
|
| 86 | + 'data' => print_r($data,true),
|
|
| 87 | + 'type' => 'log'
|
|
| 88 | + );
|
|
| 89 | +
|
|
| 90 | + self::add_to_console('log_count', $log_item);
|
|
| 91 | + }
|
|
| 92 | +
|
|
| 93 | + //--------------------------------------------------------------------
|
|
| 94 | +
|
|
| 95 | + /*
|
|
| 96 | + Method: log_memory()
|
|
| 97 | +
|
|
| 98 | + Logs the memory usage a single variable, or the entire script.
|
|
| 99 | +
|
|
| 100 | + Parameters:
|
|
| 101 | + $object - The object to store the memory usage of.
|
|
| 102 | + $name - The name to be displayed in the console.
|
|
| 103 | + */
|
|
| 104 | + public static function log_memory($object=false, $name='PHP')
|
|
| 105 | + {
|
|
| 106 | + $memory = memory_get_usage();
|
|
| 107 | +
|
|
| 108 | + if ($object)
|
|
| 109 | + {
|
|
| 110 | + $memory = strlen(serialize($object));
|
|
| 111 | + }
|
|
| 112 | +
|
|
| 113 | + $log_item = array(
|
|
| 114 | + 'data' => $memory,
|
|
| 115 | + 'type' => 'memory',
|
|
| 116 | + 'name' => $name,
|
|
| 117 | + 'data_type' => gettype($object)
|
|
| 118 | + );
|
|
| 119 | + |
|
| 120 | + self::add_to_console('memory_count', $log_item);
|
|
| 121 | + }
|
|
| 122 | +
|
|
| 123 | + //--------------------------------------------------------------------
|
|
| 124 | +
|
|
| 125 | + /*
|
|
| 126 | + Method: get_logs()
|
|
| 127 | +
|
|
| 128 | + Returns the logs array for use in external classes. (Namely the
|
|
| 129 | + Forensics Profiler.
|
|
| 130 | + */
|
|
| 131 | + public static function get_logs()
|
|
| 132 | + {
|
|
| 133 | + return self::$logs;
|
|
| 134 | + }
|
|
| 135 | +
|
|
| 136 | + //--------------------------------------------------------------------
|
|
| 137 | +
|
|
| 138 | + //--------------------------------------------------------------------
|
|
| 139 | + // !PRIVATE METHODS
|
|
| 140 | + //--------------------------------------------------------------------
|
|
| 141 | +
|
|
| 142 | + public static function add_to_console($log=null, $item=null)
|
|
| 143 | + {
|
|
| 144 | + if (empty($log) || empty($item))
|
|
| 145 | + {
|
|
| 146 | + return;
|
|
| 147 | + }
|
|
| 148 | +
|
|
| 149 | + self::$logs['console'][] = $item;
|
|
| 150 | + self::$logs[$log] += 1;
|
|
| 151 | + }
|
|
| 152 | +
|
|
| 153 | + //--------------------------------------------------------------------
|
|
| 154 | +
|
|
| 155 | +}
|
|
| 156 | + |
|
| 157 | +// End Console class |
| ... | ... | @@ -71,10 +71,7 @@ class CI_Profiler extends CI_Loader { |
| 71 | 71 | }
|
| 72 | 72 | |
| 73 | 73 | // Make sure the Console is loaded.
|
| 74 | - if (!class_exists('Console'))
|
|
| 75 | - {
|
|
| 76 | - $this->CI->load->library('Console');
|
|
| 77 | - }
|
|
| 74 | + $this->CI->load->library('console');
|
|
| 78 | 75 | |
| 79 | 76 | $this->set_sections($config);
|
| 80 | 77 | // default all sections to display
|
| ... | ... | @@ -535,9 +532,9 @@ class CI_Profiler extends CI_Loader { |
| 535 | 532 | {
|
| 536 | 533 | |
| 537 | 534 | // Make sure the Console is loaded.
|
| 538 | - $this->CI->load->library('Console');
|
|
| 535 | + $this->CI->load->library('console');
|
|
| 539 | 536 | |
| 540 | - $logs = Console::get_logs();
|
|
| 537 | + $logs = $this->CI->console->get_logs();
|
|
| 541 | 538 | |
| 542 | 539 | if ($logs['console'])
|
| 543 | 540 | {
|
| ... | ... | @@ -49,6 +49,6 @@ defined('BASEPATH') OR exit('No direct script access allowed'); |
| 49 | 49 | | Examples: my-controller/index -> my_controller/index
|
| 50 | 50 | | my-controller/my-method -> my_controller/my_method
|
| 51 | 51 | */
|
| 52 | -$route['default_controller'] = 'welcome';
|
|
| 52 | +$route['default_controller'] = 'indexcontroller';
|
|
| 53 | 53 | $route['404_override'] = '';
|
| 54 | 54 | $route['translate_uri_dashes'] = FALSE; |
—
View it on GitLab.
You're receiving this email because of your account on gitlab.com. Manage all notifications · Help