Skip to content

Commit

Permalink
Merge branch '1.9/develop' back into 1.8/master
Browse files Browse the repository at this point in the history
  • Loading branch information
WanWizard committed Jan 15, 2017
2 parents 6cfe7d6 + 5cbb296 commit cb83a0c
Show file tree
Hide file tree
Showing 32 changed files with 1,087 additions and 494 deletions.
1 change: 1 addition & 0 deletions bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ function setup_autoloader()
'Fuel\\Core\\Inflector' => COREPATH.'classes/inflector.php',

'Fuel\\Core\\Input' => COREPATH.'classes/input.php',
'Fuel\\Core\\Input_Instance' => COREPATH.'classes/input/instance.php',

'Fuel\\Core\\Lang' => COREPATH.'classes/lang.php',
'Fuel\\Core\\LangException' => COREPATH.'classes/lang.php',
Expand Down
8 changes: 5 additions & 3 deletions classes/asset/instance.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,8 @@ public function render($group = null, $raw = false)
$result[$type] = '';
}

// only do a file search if the asset is not a URI
if ($this->_always_resolve or ! preg_match('|^(\w+:)?//|', $filename))
// only do a file search if the asset is not a URL
if ( ! preg_match('|^(\w+:)?//|', $filename))
{
// and only if the asset is local to the applications base_url
if ($this->_always_resolve or ! preg_match('|^(\w+:)?//|', $this->_asset_url) or strpos($this->_asset_url, \Config::get('base_url')) === 0)
Expand Down Expand Up @@ -528,8 +528,10 @@ protected function render_js($file, $attr, $inline)
// storage for the result
$result = '';

// make sure we have a type
isset($attr['type']) or $attr['type'] = 'text/javascript';

// render inline. or not
$attr['type'] = 'text/javascript';
if ($inline)
{
$result = html_tag('script', $attr, PHP_EOL.$file.PHP_EOL).PHP_EOL;
Expand Down
2 changes: 1 addition & 1 deletion classes/database/mysql/connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected function _connect()
// add the charset to the DSN if needed
if ($this->_config['charset'] and strpos($this->_config['connection']['dsn'], ';charset=') === false)
{
$config['dsn'] .= ';charset='.$this->_config['charset'];
$this->_config['connection']['dsn'] .= ';charset='.$this->_config['charset'];
}

// create the PDO instance
Expand Down
2 changes: 1 addition & 1 deletion classes/database/mysqli/connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public function query($type, $sql, $as_object)
$this->connect();
}

if ( ! empty($this->_config['profiling']))
if (\Fuel::$profiling and ! empty($this->_config['profiling']))
{
// Get the paths defined in config
$paths = \Config::get('profiling_paths');
Expand Down
13 changes: 5 additions & 8 deletions classes/database/pdo/connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function connect()
return;
}

// make sure we have all connection parameters
// make sure we have all connection parameters, add defaults for those missing
$this->_config = array_merge(array(
'connection' => array(
'dsn' => '',
Expand All @@ -75,14 +75,11 @@ public function connect()
'enable_cache' => true,
'profiling' => false,
'readonly' => false,
'attrs' => array(),
'attrs' => array(
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
),
), $this->_config);

// Force PDO to use exceptions for all errors
$this->_config['attrs'] = array(
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION
);

if ( ! empty($this->_config['connection']['persistent']))
{
// Make the connection persistent
Expand Down Expand Up @@ -173,7 +170,7 @@ public function query($type, $sql, $as_object)
// Make sure the database is connected
$this->_connection or $this->connect();

if ( ! empty($this->_config['profiling']))
if (\Fuel::$profiling and ! empty($this->_config['profiling']))
{
// Get the paths defined in config
$paths = \Config::get('profiling_paths');
Expand Down
50 changes: 42 additions & 8 deletions classes/database/query/builder/join.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@ class Database_Query_Builder_Join extends \Database_Query_Builder
/**
* @var string $_type join type
*/
protected $_type;
protected $_type = null;

/**
* @var string $_table join table
*/
protected $_table;
protected $_table = null;

/**
* @var string $_alias join table alias
*/
protected $_alias = null;

/**
* @var array $_on ON clauses
Expand All @@ -39,8 +44,17 @@ class Database_Query_Builder_Join extends \Database_Query_Builder
*/
public function __construct($table, $type = null)
{
// Set the table to JOIN on
$this->_table = $table;
// Set the table and alias to JOIN on
if (is_array($table))
{
$this->_table = array_shift($table);
$this->_alias = array_shift($table);
}
else
{
$this->_table = $table;
$this->_alias = null;
}

if ($type !== null)
{
Expand Down Expand Up @@ -119,8 +133,27 @@ public function compile($db = null)
$sql = 'JOIN';
}

// Quote the table name that is being joined
$sql .= ' '.$db->quote_table($this->_table);
if ($this->_table instanceof \Database_Query_Builder_Select)
{
// Compile the subquery and add it
$sql .= ' ('.$this->_table->compile().')';
}
elseif ($this->_table instanceof \Database_Expression)
{
// Compile the expression and add its value
$sql .= ' ('.trim($this->_table->value(), ' ()').')';
}
else
{
// Quote the table name that is being joined
$sql .= ' '.$db->quote_table($this->_table);
}

// Add the alias if needed
if ($this->_alias)
{
$sql .= ' AS '.$db->quote_table($this->_alias);
}

$conditions = array();

Expand Down Expand Up @@ -158,8 +191,9 @@ public function compile($db = null)
*/
public function reset()
{
$this->_type =
$this->_table = NULL;
$this->_type = null;
$this->_table = null;
$this->_alias = null;
$this->_on = array();
}
}
8 changes: 7 additions & 1 deletion classes/errorhandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,13 @@ protected static function show_php_error($e)
\Cli::write('Stack trace:');
\Cli::write(\Debug::backtrace($e->getTrace()));
}
return;

if ( ! $fatal)
{
return;
}

exit(1);
}

if ($fatal)
Expand Down
20 changes: 15 additions & 5 deletions classes/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,12 @@ public static function create_dir($basepath, $name, $chmod = null, $area = null)
}

// unify the path separators, and get the part we need to add to the basepath
$new_dir = str_replace(array('\\', '/'), DS, $new_dir);
$segments = explode(DS, str_replace(array('\\', '/'), DS, $new_dir));

// recursively create the directory. we can't use mkdir permissions or recursive
// due to the fact that mkdir is restricted by the current users umask
$path = '';
foreach (explode(DS, $new_dir) as $dir)
$path = array_shift($segments);
foreach ($segments as $dir)
{
// some security checking
if ($dir == '.' or $dir == '..')
Expand All @@ -211,7 +211,11 @@ public static function create_dir($basepath, $name, $chmod = null, $area = null)
}
catch (\PHPErrorException $e)
{
return false;
if ( ! is_dir($path))
{
return false;
}
chmod($path, $chmod);
}
}
}
Expand Down Expand Up @@ -575,7 +579,13 @@ public static function copy($path, $new_path, $source_area = null, $target_area
{
throw new \FileAccessException('Cannot copy file: new path: "'.$new_path.'" already exists.');
}
return copy($path, $new_path);

if (copy($path, $new_path))
{
return chmod($new_path, fileperms($path));
}

return false;
}

/**
Expand Down
102 changes: 73 additions & 29 deletions classes/fuel.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,12 @@ public static function init($config)
\Finder::instance()->read_cache('FuelFileFinder');
}

// Enable profiling if needed
static::$profiling = \Config::get('profiling', false);
static::$profiling and \Profiler::init();
if (static::$profiling or \Config::get('log_profile_data', false))
{
\Profiler::init();
}

// set a default timezone if one is defined
try
Expand Down Expand Up @@ -232,44 +236,70 @@ class_alias('Error', 'Errorhandler');
*/
public static function finish()
{
// caching enabled? then save the finder cache
if (\Config::get('caching', false))
{
\Finder::instance()->write_cache('FuelFileFinder');
}

if (static::$profiling and ! static::$is_cli and ! \Input::is_ajax())
// profiling enabled?
if (static::$profiling)
{
// Grab the output buffer and flush it, we will rebuffer later
$output = ob_get_clean();
\Profiler::mark('End of Fuel Execution');

$headers = headers_list();
$show = true;

foreach ($headers as $header)
// write profile data to a logfile if configured
if (\Config::get('log_profile_data', false))
{
if (stripos($header, 'content-type') === 0 and stripos($header, 'text/html') === false)
$file = \Log::logfile('', '-profiler-'.date('YmdHis'));
if ($handle = @fopen($file, 'w'))
{
$show = false;
if (\Input::is_ajax())
{
$content = \Format::forge()->to_json(\Profiler::output(true), true);
}
else
{
$content = 'return '.var_export(\Profiler::output(true), true);
}
fwrite($handle, $content);
fclose($handle);
}
}

if ($show)
// for interactive sessions, check if we need to output profiler data
if ( ! \Fuel::$is_cli)
{
\Profiler::mark('End of Fuel Execution');
if (preg_match("|</body>.*?</html>|is", $output))
$headers = headers_list();
$show = true;

foreach ($headers as $header)
{
$output = preg_replace("|</body>.*?</html>|is", '', $output);
$output .= \Profiler::output();
$output .= '</body></html>';
if (stripos($header, 'content-type') === 0 and stripos($header, 'text/html') === false)
{
$show = false;
}
}
else

if ($show)
{
$output .= \Profiler::output();
$output = ob_get_clean();

if (preg_match("|</body>.*?</html>|is", $output))
{
$output = preg_replace("|</body>.*?</html>|is", '', $output);
$output .= \Profiler::output();
$output .= '</body></html>';
}
else
{
$output .= \Profiler::output();
}

// restart the output buffer and send the new output
ob_start(\Config::get('ob_callback'));
echo $output;
}
}
// Restart the output buffer and send the new output
ob_start(\Config::get('ob_callback'));
echo $output;
}
}

Expand Down Expand Up @@ -374,15 +404,29 @@ public static function value($var)
public static function clean_path($path)
{
// framework default paths
static $search = array('\\', APPPATH, COREPATH, PKGPATH, DOCROOT);
static $replace = array('/', 'APPPATH/', 'COREPATH/', 'PKGPATH/', 'DOCROOT/');

// additional paths configured than need cleaning
$extra = \Config::get('security.clean_paths', array());
foreach ($extra as $r => $s)
static $paths = array(
'APPPATH/' => APPPATH,
'DOCROOT/' => DOCROOT,
'COREPATH/' => COREPATH,
'PKGPATH/' => PKGPATH,
'VENDORPATH/' => VENDORPATH,
);

// storage for the search/replace strings
static $search = array();
static $replace = array();

// only do this once
if (empty($search))
{
$search[] = $s;
$replace[] = $r.'/';
// additional paths configured than need cleaning
$extra = \Config::get('security.clean_paths', array());

foreach ($paths + $extra as $r => $s)
{
$search[] = rtrim($s, DS).DS;
$replace[] = rtrim($r, DS).DS;
}
}

// clean up and return it
Expand Down
Loading

0 comments on commit cb83a0c

Please sign in to comment.