Skip to content

Commit

Permalink
Merge pull request civicrm#21 from totten/4.3-smarty-crm-5890
Browse files Browse the repository at this point in the history
CRM-12750 - Smarty - Restore patches from CRM-5890
  • Loading branch information
kurund committed Jun 6, 2013
2 parents 852073d + 38c1e7c commit 8e1759a
Show file tree
Hide file tree
Showing 2 changed files with 2,001 additions and 2 deletions.
41 changes: 39 additions & 2 deletions Smarty/Smarty.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1511,8 +1511,45 @@ function _compile_source($resource_name, &$source_content, &$compiled_content, $
*/
function _get_compile_path($resource_name)
{
return $this->_get_auto_filename($this->compile_dir, $resource_name,
$this->_compile_id) . '.php';
$compilePath = $this->_get_auto_filename( $this->compile_dir,
$resource_name,
$this->_compile_id );
$compilePath .= '.php';

//for 'string:' resource smarty might going to fail to create
//compile file, so make sure we should have valid path, CRM-5890
$matches = array( );
if ( preg_match( '/^(\s+)?string:/', $resource_name, $matches ) ) {
if ( !$this->validateCompilePath( $compilePath ) ) {
$compilePath = $this->_get_auto_filename( $this->compile_dir,
time().rand(),
$this->_compile_id );
$compilePath .= '.php';
}
}

return $compilePath;
}

/**
* do check can smarty create a file w/ given path.
*/
function validateCompilePath( $compilePath ) {
//first check for directory.
$dirname = dirname( $compilePath );
if ( !is_dir( $dirname ) ) {
require_once(SMARTY_CORE_DIR . 'core.create_dir_structure.php');
smarty_core_create_dir_structure( array('dir' => $dirname ), $this );
}

$isValid = false;
if ( $fd = @fopen( $compilePath, 'wb') ) {
$isValid = true;
@fclose( $fd );
@unlink($compilePath);
}

return $isValid;
}

/**
Expand Down
Loading

0 comments on commit 8e1759a

Please sign in to comment.