'.htmlspecialchars($target_file_path).' copy from ' . htmlspecialchars($file) . '
';
} else {
$msgs[] = 'ERROR: Could not copy template '.htmlspecialchars($target_file_name).' from ' . htmlspecialchars($file). '(check templates directory permision (777))
';
}
}
}
closedir( $handler ) ;
}
// template added to the database.
if( $handler = @opendir( $tpl_path . '/' ) ) {
while( ( $file = readdir( $handler ) ) !== false ) {
if( substr( $file , 0 , 1 ) == '.' ) continue ;
$file_path = $tpl_path . '/' . $file ;
$file_name = $file ;
$pattern = '^' . $mydirname . '_';
if (preg_match('/' . $pattern . '/' , $file_name, $match)){
if( is_file( $file_path ) ) {
$msgs[] = xpress_create_db_template($file_name,$file_path,$mydirname,$mid);
}
}
}
closedir( $handler ) ;
}
include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php' ;
include_once XOOPS_ROOT_PATH.'/class/template.php' ;
xoops_template_clear_module_cache( $mid ) ;
return $msgs;
}
function xpress_create_db_template($file_name,$file_path,$mydirname,$mid){
if( is_file( $file_path ) ) {
$tplfile_handler =& xoops_gethandler( 'tplfile' ) ;
$tplfile =& $tplfile_handler->create() ;
$mtime = intval( @filemtime( $file_path ) ) ;
$tplfile->setVar( 'tpl_source' , file_get_contents( $file_path ) , true ) ;
$tplfile->setVar( 'tpl_refid' , $mid ) ;
$tplfile->setVar( 'tpl_tplset' , 'default' ) ;
$tplfile->setVar( 'tpl_file' , $file_name ) ;
$tplfile->setVar( 'tpl_desc' , '' , true ) ;
$tplfile->setVar( 'tpl_module' , $mydirname ) ;
$tplfile->setVar( 'tpl_lastmodified' , $mtime ) ;
$tplfile->setVar( 'tpl_lastimported' , 0 ) ;
$tplfile->setVar( 'tpl_type' , 'module' ) ;
if( ! $tplfile_handler->insert( $tplfile ) ) {
$msg = 'ERROR: Template Could not added to the database. '.htmlspecialchars($file_name).' to the database.
';
} else {
$tplid = $tplfile->getVar( 'tpl_id' ) ;
$msg = 'Template '.htmlspecialchars($file_name) .' added to the database. (ID: '.$tplid.')
';
// generate compiled file
include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php' ;
include_once XOOPS_ROOT_PATH.'/class/template.php' ;
if( ! xoops_template_touch( $tplid ) ) {
$msg = 'ERROR: Failed compiling template '.htmlspecialchars($file_name).'.
';
} else {
$msg = 'Template '.htmlspecialchars($file_name).' compiled.
';
}
}
}
return $msg;
}
function is_template($file_name){
if (empty($file_name)) return false;
$temp_list = array(
'recent_comments_block.html',
'recent_posts_content_block.html',
'recent_posts_list_block.html',
'calender_block.html',
'popular_posts_block.html',
'archives_block.html',
'authors_block.html',
'page_block.html',
'search_block.html',
'tag_cloud_block.html',
'category_block.html',
'meta_block.html' ,
'sidebar_block.html' ,
'widget_block.html' ,
'enhanced_block.html' ,
'blog_list_block.html' ,
'global_recent_posts_list_block.html' ,
'index.html',
);
foreach($temp_list as $ck_file){
if (strcmp($ck_file,$file_name) == 0) return true;
}
return false;
}
function xpress_clean_templates_file($mydirname,$mod_version)
{
$tpl_path = XOOPS_ROOT_PATH . '/modules/' . $mydirname . '/templates/' ;
$msgs = array();
if( $handler = @opendir( $tpl_path) ) {
while( ( $file = readdir( $handler ) ) !== false ) {
if( substr( $file , 0 , 1 ) == '.' ) continue ;
if ( strcmp($file,'source')==0 ) continue ;
if ( strcmp($file,'index.html')==0 ) continue ;
$target_file_path = $tpl_path . $file;
if (is_dir($target_file_path)){
rmDirectory($target_file_path);
$msgs[] = 'Template '.htmlspecialchars($file).' directory deleted.
';
} else {
if ($mod_version >= 200){
$pattern = '^' . $mydirname . '_';
if (preg_match('/' . $pattern . '/' , $file, $match)) continue ;
}
$rcd = @unlink($target_file_path);
$msgs[] = 'Template '.htmlspecialchars($file).' file deleted.
';
}
}
closedir( $handler ) ;
}
return $msgs;
}
function rmDirectory($dir){
if ($handle = opendir("$dir")){
while (false !== ($item = readdir($handle))){
if ($item != "." && $item != ".."){
if (is_dir("$dir/$item")){
rmDirectory("$dir/$item");
}else{
unlink("$dir/$item");
}
}
}
closedir($handle);
rmdir($dir);
}
}
?>