Skip to content

Commit

Permalink
fix for issue #217; contains some more enhancements, too
Browse files Browse the repository at this point in the history
  • Loading branch information
Bianka Martinovic committed Mar 28, 2014
1 parent eb8c60d commit 4d3ef22
Showing 1 changed file with 41 additions and 8 deletions.
49 changes: 41 additions & 8 deletions upload/backend/addons/ajax_create.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
}
else
{
$dir = strtoupper($dir);
$full = CAT_PATH.'/languages/'.$dir.'.php';
if( file_exists($full) )
$err = $backend->lang()->translate('A language file with the same name already exists');
Expand Down Expand Up @@ -120,8 +121,8 @@
$func = 'language';
$pre = 'language_';
break;
case 'page':
$type = 'module';
case 'module':
$func = 'page';
break;
}

Expand Down Expand Up @@ -169,20 +170,34 @@
$message = $backend->lang()->translate('Unable to create info.php!');
printResult();
}
writeHeader($fh,$name,$author);
writeHeader($fh,$name,$author,$type);
foreach($info as $key => $value )
{
if($type=='language' && $key == 'language_directory') continue;
fwrite($fh,'$'.$key.' = "'.$value.'";'."\n");
}
if($type == 'language')
{
fwrite($fh,'
$LANG = array(
);
');
}
fclose($fh);

if($type=='language')
{
$fh = fopen(CAT_PATH.'/languages/old/'.$dir.'.php','w');
writeHeader($fh,$name,$author,$type);
fwrite($fh,'$MENU = array();'."\n");
fwrite($fh,'$TEXT = array();'."\n");
fwrite($fh,'$HEADING = array();'."\n");
fwrite($fh,'$MESSAGE = array();'."\n");
fwrite($fh,'$OVERVIEW = array();'."\n");
fclose($fh);
}

// create some more default files
if($type=='module')
{
Expand All @@ -191,19 +206,37 @@
$fh = fopen($full.'/'.$n.'.php','w');
if($fh)
{
writeHeader($fh,$name,$author);
writeHeader($fh,$name,$author,$type);
fclose($fh);
}
}
}

// if it's a template...
if($type=='template')
{
$contents = file_get_contents($full.'/index.php');
$contents .= "
\$dwoodata = array(); // if you need to set some additional template vars, add them here
\$variant = CAT_Helper_Page::getPageSettings(\$page_id,'internal','template_variant');
if(!\$variant)
\$variant = 'default';
\$parser->setPath(CAT_TEMPLATE_DIR.'/templates/'.\$variant);
\$parser->setFallbackPath(CAT_TEMPLATE_DIR.'/templates/default');
\$parser->output('index.tpl',\$dwoodata);
";
file_put_contents($full.'/index.php', $contents);
CAT_Helper_Directory::createDirectory($full.'/templates/default');
CAT_Helper_Directory::recursiveCreateIndex($full.'/templates');
}

// insert module into DB
foreach($info as $key => $value)
{
$key = str_replace($pre,'module_',$key);
$info[$key] = $value;
}
$info['addon_function'] = $info[$pre.'function'];
$info['addon_function'] = $type;

CAT_Helper_Addons::loadModuleIntoDB( $dir, 'install', $info);

Expand All @@ -222,7 +255,7 @@ function printResult()
exit();
}

function writeHeader($fh,$name,$author)
function writeHeader($fh,$name,$author,$type)
{
fwrite($fh,'<'.'?'.'php
Expand All @@ -241,10 +274,10 @@ function writeHeader($fh,$name,$author)
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*
* @author '.$author.'
* @copyright 2013, Black Cat Development
* @copyright '.date('Y').', '.$author.'
* @link http://blackcat-cms.org
* @license http://www.gnu.org/licenses/gpl.html
* @category CAT_Modules
* @category CAT_'.ucfirst($type).'s
* @package '.$name.'
*
*/
Expand Down

0 comments on commit 4d3ef22

Please sign in to comment.