array(), 'extracted_files' => array());
if ( is_array($result['extracted_files']) and count($result['extracted_files']) > 0 )
{
$nfo_file = DATA_PATH . str_replace(' ','_',$info['title']) . ".nfo";
$install_nfo = $info['timestamp']."\n$nfo_file\n";
// Check file by file if already exists, if it matches, compares both files
// looking for changes determining if the file needs to be updated.
// Also determines if the file is writable
$i = 0;
$i2 = 0;
foreach( $result['extracted_files'] as $file )
{
if( DIRECTORY_SEPARATOR == '\\')
$filename = str_replace('/', '\\', $file['filename']);
else
$filename = $file['filename'];
$fullFilename = $filename;
$filename = preg_replace( "/".preg_quote($info['remove_path'])."/", "", $filename);
$install_nfo .= realpath($base_dir) . $filename . "\n";
$temp_file = $temp_dir . DIRECTORY_SEPARATOR . $fullFilename;
$web_file = $base_dir . $filename;
if(file_exists($temp_file)){
if(file_exists($web_file))
{
if(!in_array($filename, $current_blacklist)){
$temp = file_get_contents($temp_file);
$web = file_get_contents($web_file);
if( $temp != $web )
{
if( !is_writable( $web_file ) )
{
if ( ! @chmod( $web_file, 0644 ) )
{
$all_writable = FALSE;
$not_writable .= $web_file."\n";
}
else
{
$newResult["extracted_files"][$i]["filename"] = $filename;
copy($temp_file, $web_file);
$i++;
$overwritten_files .= $filename . "\n";
$overwritten++;
}
}
else
{
$newResult["extracted_files"][$i]["filename"] = $filename;
copy($temp_file, $web_file);
$i++;
$overwritten_files .= $filename . "\n";
$overwritten++;
}
}
}else{
$newResult["ignored_files"][$i2] = $filename;
$i2++;
$not_overwritten_files .= $filename . "\n";
$not_overwritten++;
}
}
else
{
$newResult["extracted_files"][$i]["filename"] = $filename;
$webDir = dirname($web_file);
@mkdir($webDir, 0775, true);
@copy($temp_file, $web_file);
$i++;
$new_files .= $filename . "\n";
$new++;
}
}
}
}
else
{
echo $result;
// Remove the downloaded package
if( file_exists( $temp_dwl ) )
unlink( $temp_dwl );
return FALSE;
}
// Once checkings are done the temp folder is removed
if( file_exists( $temp_dir ) )
{
rmdir_recurse( $temp_dir );
}
if( $all_writable )
{
if( is_array( $newResult['extracted_files'] ) )
{
// Updated files
if ( $overwritten > 0 )
{
echo get_lang_f('files_overwritten',$overwritten).":\n\n".$overwritten_files;
echo "\n\n";
}
if ( $new > 0 )
{
echo get_lang_f('new_files',$new).":\n\n".$new_files;
echo "\n\n";
}
if ( $not_overwritten > 0 )
{
echo get_lang_f('files_not_overwritten',$not_overwritten).":\n\n".$not_overwritten_files;
echo "\n\n";
}
// Add install.nfo file to the module/theme directory so we can remove the installed files later and check the installed files timestamp.
file_put_contents($nfo_file, $install_nfo);
// Remove the downloaded package
if( file_exists( $temp_dwl ) )
unlink( $temp_dwl );
return TRUE;
}
else
{
// Remove the downloaded package
if( file_exists( $temp_dwl ) )
unlink( $temp_dwl );
return FALSE;
}
}
else
{
echo $info['title'].":\n$not_writable";
// Remove the downloaded package
if( file_exists( $temp_dwl ) )
unlink( $temp_dwl );
return FALSE;
}
}
function rglob($pattern, $flags = 0) {
$files = glob($pattern, $flags);
foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) {
$files = array_merge($files, rglob($dir.'/'.basename($pattern), $flags));
}
return $files;
}
function deeperPathFirst($a, $b)
{
$al = count(explode(DIRECTORY_SEPARATOR,$a));
$bl = count(explode(DIRECTORY_SEPARATOR,$b));
if ($al == $bl) {
return strcmp($a,$b);
}
return ($al > $bl) ? -1 : +1;
}
function exec_ogp_module()
{
global $db, $settings;
// Get blacklisted files
$current_blacklist = array();
$blacklisted_files = $db->resultQuery('SELECT file_path FROM `OGP_DB_PREFIXupdate_blacklist`;');
if($blacklisted_files !== FALSE)
{
$current_blacklist = array();
foreach($blacklisted_files as $blacklisted_file)
{
$current_blacklist[] = $blacklisted_file['file_path'];
}
}
// GitHub URL
if(function_exists("getOGPGitHubURLUnstrict") && function_exists("getGitHubOrganization")){
$gitHubUsername = $settings["custom_github_update_username"];
$gitHubURL = getOGPGitHubURLUnstrict($gitHubUsername);
$gitHubOrganization = getGitHubOrganization($gitHubURL);
}else{
$gitHubURL = "https://github.com/OpenGamePanel/";
$gitHubOrganization = "OpenGamePanel";
}
if($gitHubOrganization == "OpenGamePanel"){
$gitAPICont = "orgs";
}else{
$gitAPICont = "users";
}
set_time_limit(0);
$baseDir = str_replace( "modules" . DIRECTORY_SEPARATOR . $_GET['m'],"",dirname(__FILE__) );
define('DATA_PATH', realpath('modules/'.$_GET['m'].'/') . DIRECTORY_SEPARATOR . "data" . DIRECTORY_SEPARATOR);
if(!file_exists(DATA_PATH))
{
if(!mkdir(DATA_PATH))
{
print_failure("Need create folder: " . DATA_PATH . '
But ' . dirname(DATA_PATH) . ' is not writable.
The command:
chmod -R ' . dirname(DATA_PATH) . 'would fix it.'); return; } $back_compatibility = array ( 'Util', 'RCON', 'DSi', 'Cron', 'LGSL_with_Img_Mod', 'Simple-billing', 'Support', 'TeamSpeak3', 'DarkNature', 'expand-soft', 'Katiuska', 'mobile', 'Light', 'Silver', 'Soft', 'Uprise' ); $installed = rglob('*/*/install.nfo'); foreach($installed as $nfo) { $nfo_new = preg_replace('#^([m|t]{1})(odule|heme){1}s/([^?/]+)/install.nfo#','\3',$nfo); #echo $nfo_new.'
| ";
# MODULES
echo " ".
" ".get_lang("extra_modules")."". "";
if (!empty($moduleErrors['modules'])) {
foreach($moduleErrors['modules'] as $module) {
echo '',$module,' - Unable to retrieve XML data. '; } } foreach ( $installed_modules as $installed_module ) { $folder = $installed_module['folder']; $installed_modules_by_folder[$folder] = $installed_module['id']; } foreach($modules as $key => $module) { $local_repo_file = DATA_PATH . $module['reponame'] . '.atom'; $install_nfo = DATA_PATH . str_replace(' ','_',$module['title']) . ".nfo"; $on_disk = file_exists($install_nfo); $is_old = $on_disk && (strtotime('+1 hour', filemtime($local_repo_file)) <= time()); //echo $install_nfo; $folder = str_replace(' ','_',strtolower($module['title'])); $installed = array_key_exists($folder,$installed_modules_by_folder); $installed_str = $on_disk ? $installed ? "".get_lang("uninstall")."" : "".get_lang("install")." - ". "".get_lang("remove")."" : "".get_lang("not_installed").""; $uptodate = FALSE; if($on_disk) { $install_nfo = file_get_contents($install_nfo); list($timestamp, $files) = explode("\n", $install_nfo); $uptodate = ($timestamp == $module['timestamp']) ? TRUE : FALSE; } $updated_str = $on_disk ? $uptodate ? $is_old ? " - ".get_lang("search_for_updates")."" : " - ".get_lang("uptodate")."" : " - ".get_lang("update_available")." (".$module['date'].")" : ""; $disabled = $uptodate ? "disabled=disabled" : ""; echo '"; echo ''.$module['title']." - $installed_str$updated_str "; } echo " | ";
# THEMES
echo " ".
" ".get_lang("extra_themes")."". "";
if (!empty($moduleErrors['themes'])) {
foreach($moduleErrors['themes'] as $theme) {
echo '',$theme,' - Unable to retrieve XML data. '; } } foreach($themes as $key => $theme) { $local_repo_file = DATA_PATH . $theme['reponame'] . '.atom'; $install_nfo = DATA_PATH . str_replace(' ','_',$theme['title']) . ".nfo"; $on_disk = file_exists($install_nfo); $is_old = $on_disk && (strtotime('+1 hour', filemtime($local_repo_file)) <= time()); $installed_str = $on_disk ? "".get_lang("installed")." - ". "".get_lang("remove")."": "".get_lang("not_installed").""; $uptodate = FALSE; if($on_disk) { $install_nfo = file_get_contents($install_nfo); list($timestamp, $files) = explode("\n", $install_nfo); $uptodate = ($timestamp == $theme['timestamp']) ? TRUE : FALSE; } $updated_str = $on_disk ? $uptodate ? $is_old ? " - ".get_lang("search_for_updates")."" : " - ".get_lang("uptodate")."" : " - ".get_lang("update_available")." (".$theme['date'].")" : ""; $disabled = $uptodate ? "disabled=disabled" : ""; echo '"; echo ''.$theme['title']." - $installed_str$updated_str "; } echo " |