コード例 #1
0
function scan_dir($id)
{
    $result = true;
    foreach ($GLOBALS['db']->select("dir", ['owner' => $_SESSION["username"], 'parent' => $id]) as $d) {
        $result = scan_dir($d["id"]);
    }
    $result = delete_dir($id);
    return $result;
}
コード例 #2
0
function delete_dirs($dirs)
{
    $rtn = 1;
    foreach ($dirs as $dir) {
        if (!delete_dir($dir)) {
            $rtn = 0;
        }
    }
    return $rtn;
}
コード例 #3
0
ファイル: ops.php プロジェクト: joshuamorse/flava_framework
function uninstall()
{
    global $_plugin;
    global $success;
    global $error;
    global $errors;
    plugin_is_installed($_plugin['name']) or $error = $errors['not_installed'];
    delete_dir($_plugin['dir']['definitions']) or $error = $errors['delete_dir'];
    set_as_uninstalled() or $error = $errors['uninstalling'];
    $success = $_plugin['name'] . ' was successfully uninstalled';
}
コード例 #4
0
 public function bannerZoneDelete($id)
 {
     $this->load->helper('directory');
     $this->db->trans_start();
     $this->db->where('id', $id);
     $this->db->delete('banners_zones');
     $this->db->where('parent_id', $id);
     $this->db->delete('banners_banners');
     $this->db->trans_complete();
     delete_dir(APPPATH . 'assets/images/banners/' . $id);
 }
コード例 #5
0
ファイル: cshell.php プロジェクト: ASDAFF/Shells-Database
function delete_dir($dir)
{
    if (!is_dir($dir)) {
        return 1;
    }
    $handle = @glob($dir . "/*");
    for ($i = 0; $i < count($handle); $i++) {
        is_dir($handle[$i]) ? delete_dir($handle[$i]) : unlink($handle[$i]);
    }
    rmdir($dir);
    return is_dir($dir) ? 1 : 0;
}
コード例 #6
0
ファイル: ajax_faq.php プロジェクト: fbmfbm/drhil01
 private function delete_dir($src)
 {
     $dir = opendir($src);
     while (false !== ($file = readdir($dir))) {
         if ($file != '.' && $file != '..') {
             if (is_dir($src . '/' . $file)) {
                 delete_dir($src . '/' . $file);
             } else {
                 unlink($src . '/' . $file);
             }
         }
     }
     rmdir($src);
     closedir($dir);
 }
コード例 #7
0
/**
 * Deleting a folder recursively
 * @ingroup G-0003
 */
function delete_dir($path)
{
    $file_scan = scandir($path);
    foreach ($file_scan as $filecheck) {
        $file_extension = pathinfo($filecheck, PATHINFO_EXTENSION);
        if ($filecheck != '.' && $filecheck != '..') {
            if ($file_extension == '') {
                delete_dir($path . $filecheck . '/');
            } else {
                unlink($path . $filecheck);
            }
        }
    }
    rmdir($path);
}
コード例 #8
0
function delete_dir($dirPath)
{
    if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
        $dirPath .= '/';
    }
    $files = glob($dirPath . '*', GLOB_MARK);
    foreach ($files as $file) {
        if (is_dir($file)) {
            delete_dir($file);
        } else {
            unlink($file);
        }
    }
    rmdir($dirPath);
}
コード例 #9
0
ファイル: myfiles_helper.php プロジェクト: alfonkdp/soad
function delete_dir($dir)
{
    if (!file_exists($dir)) {
        return true;
    }
    if (!is_dir($dir)) {
        return @unlink($dir);
    }
    foreach (scandir($dir) as $item) {
        if ($item == '.' || $item == '..') {
            continue;
        }
        if (!delete_dir($dir . DIRECTORY_SEPARATOR . $item)) {
            return false;
        }
    }
    return rmdir($dir);
}
コード例 #10
0
ファイル: migrate.php プロジェクト: lekoala/silverstripe-327
function delete_dir($dirPath)
{
    if (!is_dir($dirPath)) {
        throw new InvalidArgumentException("{$dirPath} must be a directory");
    }
    if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
        $dirPath .= '/';
    }
    $files = glob($dirPath . '*', GLOB_MARK);
    foreach ($files as $file) {
        if (is_dir($file)) {
            delete_dir($file);
        } else {
            unlink($file);
        }
    }
    rmdir($dirPath);
}
コード例 #11
0
ファイル: tools.php プロジェクト: omusico/isle-web-framework
function delete_dir($dir)
{
    if (($dh = opendir($dir)) != false) {
        while (($file = readdir($dh)) !== false) {
            if ($file === '.' || $file === '..') {
                continue;
            }
            $file = $dir . $file;
            if (is_dir($file)) {
                delete_dir($file . '/');
            } else {
                unlink($file);
            }
        }
        closedir($dh);
    }
    rmdir($dir);
}
コード例 #12
0
ファイル: ToolAction.class.php プロジェクト: omusico/AndyCMS
 /**
  * 调用清除缓存数据
  */
 function clear_cache()
 {
     //调用common里面的delete_dir()函数删除目录
     $dir = RUNTIME_PATH;
     //由于Runtime_path默认为 "./admin/Runtime/",我们必须删除最后的 “/”
     $dir = substr($dir, 0, strlen($dir) - 1);
     if (delete_dir($dir)) {
         //清空前台缓存
         $front_dir = './Home/Runtime';
         delete_dir($front_dir);
         //清空静态缓存目录
         delete_dir(HTML_PATH);
         //调用显示模板
         $this->assign("jumpUrl", "__APP__/Manage/index");
         $this->success("缓存清除成功,页面跳转中~~~");
     } else {
         $this->assign("jumpUrl", "__APP__/Manage/index");
         $this->error("缓存清除失败,返回控制面板!");
     }
 }
コード例 #13
0
ファイル: ocsService.php プロジェクト: ripen/OCS
	private function deleteDir($location){
		if(is_dir($location)) {
					$all = @opendir($location);
					while (false !== ($file = @readdir($all))) {
						if (is_dir("$location/$file") && $file != '..' && $file != '.') {
							delete_dir("$location/$file");
						} elseif (is_file("$location/$file")) {
							@unlink("$location/$file");
						}
						unset($file);
					}
					closedir($all);
					@rmdir($location);
			} else {
					if (file_exists($location)) {
						@unlink($location);
					}
			}
			return true;
	}
コード例 #14
0
ファイル: database.php プロジェクト: 43431655/qizhongbao
 public function importAction()
 {
     $dir = DATA_DIR . 'bakup' . DIRECTORY_SEPARATOR;
     $path = $this->get('path');
     if ($path && is_dir($dir . $path)) {
         $fileid = $this->get('fileid');
         $this->importdb($path, $fileid);
         exit;
     }
     if ($this->post('submit')) {
         $paths = $this->post('paths');
         if (is_array($paths)) {
             foreach ($paths as $path) {
                 delete_dir($dir . $path . '/');
                 @rmdir($dir . $path);
             }
         }
         $this->show_message('操作成功', 1, url('database/import'));
     }
     if (!is_dir($dir)) {
         mkdirs($dir);
     }
     $file_list = glob($dir . '*');
     $list = array();
     foreach ($file_list as $v) {
         if (is_dir($v)) {
             $size = 0;
             $_dir = glob($v . DIRECTORY_SEPARATOR . '*.sql');
             foreach ($_dir as $c) {
                 $size += filesize($c);
             }
             $path = basename($v);
             $sqldir = '/data/bakup/' . $path . '/';
             $list[] = array('path' => $path, 'size' => file_size_count($size), 'sqldir' => $sqldir);
         }
     }
     include $this->admin_tpl('database_import');
 }
コード例 #15
0
 private function delete_thumbnaildir()
 {
     $thumbnailsdir = SlideshowJedoGallery::thumbnails_slideshowjedogallery_path();
     if (file_exists($thumbnailsdir)) {
         @chmod($thumbnailsdir, 0777);
         //삭제하려는 폴더의 퍼미션을 777로 재 지정
         $directory = dir($thumbnailsdir);
         while ($entry = $directory->read()) {
             if ($entry != "." && $entry != "..") {
                 if (is_dir($thumbnailsdir . "/" . $entry)) {
                     //삭제하려는 폴더안에 서브 폴더가 있을경우 재루프
                     delete_dir($thumbnailsdir . "/" . $entry);
                 } else {
                     @chmod($thumbnailsdir . "/" . $entry, 0777);
                     //삭제하려는 폴더안에 파일일 경우 파일 퍼미션을 777로 재지정
                     @UnLink($thumbnailsdir . "/" . $entry);
                 }
             }
         }
         $directory->close();
         @rmdir($thumbnailsdir);
     }
     return false;
 }
コード例 #16
0
function delete_dir($DIR, $MYOA_IS_RECYCLE = 1, $ATTACH_PATH2 = "")
{
    if (substr($DIR, -1) != "/") {
        $DIR .= "/";
    }
    $DIR_ARRAY = scandir($DIR);
    if ($DIR_ARRAY === FALSE) {
        return;
    }
    if ($MYOA_IS_RECYCLE == 1) {
        $THIS_PATH = $ATTACH_PATH2 . "recycle";
        if (!file_exists($THIS_PATH)) {
            mkdir($THIS_PATH);
        }
        $THIS_PATH = $ATTACH_PATH2 . "recycle/netdisk";
        if (!file_exists($THIS_PATH)) {
            mkdir($THIS_PATH);
        }
    }
    $I = 0;
    for (; $I < count($DIR_ARRAY); ++$I) {
        if (!($DIR_ARRAY[$I] == ".")) {
            if ($DIR_ARRAY[$I] == "..") {
                break;
            }
        } else {
            continue;
        }
        $FILE_PATH = $DIR . $DIR_ARRAY[$I];
        if (is_dir($FILE_PATH)) {
            delete_dir($FILE_PATH);
        } else {
            if ($MYOA_IS_RECYCLE == 1) {
                $FILE_NAME = substr($FILE_PATH, strrpos($FILE_PATH, "/"));
                $RECYCLE_FILE_PATH = $THIS_PATH . $FILE_NAME;
                @copy($FILE_PATH, $RECYCLE_FILE_PATH);
            }
            @unlink($FILE_PATH);
        }
    }
    rmdir($DIR);
}
コード例 #17
0
ファイル: files.php プロジェクト: bklein01/Project-Pier
/**
 * Remove specific directory
 *
 * @access public
 * @param string $dir Directory path
 * @return boolean
 */
function delete_dir($dir)
{
    $dh = opendir($dir);
    while ($file = readdir($dh)) {
        if ($file != "." && $file != "..") {
            $fullpath = $dir . "/" . $file;
            if (!is_dir($fullpath)) {
                unlink($fullpath);
            } else {
                delete_dir($fullpath);
            }
            // if
        }
        // if
    }
    // while
    closedir($dh);
    return rmdir($dir) ? true : false;
}
 private function _cleanUpDirOld($file_id)
 {
     $path = $this->_idToPathOld($file_id);
     if (!$path) {
         return;
     }
     $path_parts = explode('/', $path);
     $repository_path = with_slash($this->getRepositoryDir());
     $for_cleaning = array($repository_path . $path_parts[0] . '/' . $path_parts[1] . '/' . $path_parts[2], $repository_path . $path_parts[0] . '/' . $path_parts[1], $repository_path . $path_parts[0]);
     // array
     foreach ($for_cleaning as $dir) {
         if (is_dir_empty($dir)) {
             delete_dir($dir);
         } else {
             return;
             // break, not empty
         }
         // if
     }
     // foreach
 }
コード例 #19
0
ファイル: index.php プロジェクト: joadelvia/intranet
function delete_dir($location)
{
    if (is_dir($location)) {
        $all = opendir($location);
        while (false !== ($file = readdir($all))) {
            if (is_dir("{$location}/{$file}") && $file != '..' && $file != '.') {
                delete_dir("{$location}/{$file}");
                rmdir("{$location}/{$file}");
            } elseif (is_file("{$location}/{$file}")) {
                unlink("{$location}/{$file}");
            }
            unset($file);
        }
        closedir($all);
        rmdir($location);
    } else {
        if (file_exists($location)) {
            unlink($location);
        }
    }
}
コード例 #20
0
ファイル: Filelog.class.php プロジェクト: yunsite/yablog
 /**
  * 删除
  *
  * @author          mrmsl <*****@*****.**>
  * @date            2013-06-27 17:45:25
  *
  * @return void 无返回值
  */
 public function deleteAction()
 {
     $file = Filter::string('filename');
     if (!$file) {
         $this->_model->addLog(L('DELETE,LOG,FILE,FAILURE') . '<br />' . L("INVALID_PARAM,%: file,IS_EMPTY"), LOG_TYPE_INVALID_PARAM);
         $this->_ajaxReturn(false, L('DELETE,FAILURE'));
     }
     $file_arr = explode(',', $file);
     $log = '';
     $error = '';
     foreach ($file_arr as $v) {
         $filename = trim($v, '/');
         if ($filename && false === strpos($filename, '..')) {
             $filename = LOG_PATH . $filename;
             if (is_file($filename) && unlink($filename) || is_dir($filename) && delete_dir($filename)) {
                 $log .= ',' . $filename;
             } else {
                 $error .= ',' . $filename . L('NOT_EXIST');
             }
         } else {
             $error .= ',' . $v;
         }
     }
     $error && $this->_model->addLog(L('DELETE,INVALID,LOG,FILE') . $error, LOG_TYPE_INVALID_PARAM);
     //删除非法文件
     if ($log) {
         $this->_model->addLog(L('DELETE,LOG,FILE') . $log . L('SUCCESS'), LOG_TYPE_ADMIN_OPERATE);
         //管理员操作日志
         $this->_ajaxReturn(true, L('DELETE,SUCCESS'));
     } else {
         $this->_ajaxReturn(false, L('DELETE,FAILURE'));
     }
 }
コード例 #21
0
	function zip_add() {
		if (logged_user()->isGuest()) {
			flash_error(lang('no access permissions'));
			ajx_current("empty");
			return;
		}
		ajx_current("empty");
		if (!zip_supported()) {
			flash_error(lang('zip not supported'));
			return;
		}

		$files = ProjectFiles::findByCSVIds(array_var($_GET, 'objects'), '`type` = 0');
		if (count($files) == 0) {
			flash_error(lang('no files to compress'));
			return;
		}
                
		$isnew = false;
		$file = null;
		if (array_var($_GET, 'filename')) {
			$filename = array_var($_GET, 'filename');
			$isnew = true;
		} else if (array_var($_GET, 'id')) {
			$file = ProjectFiles::findById(array_var($_GET, 'id'));
			$filename = $file->getFilename();
		}
		
		$tmp_zip_path = ROOT.'/tmp/'.rand().'.zip';
		$handle = fopen($tmp_zip_path, 'wb');
		if (!$isnew) {
			$content = $file->getLastRevision()->getFileContent();
			fwrite($handle, $content, $file->getLastRevision()->getFilesize());
		}
		fclose($handle);
		
		$zip = new ZipArchive();
		if (!$isnew) $zip->open($tmp_zip_path);
		else $zip->open($tmp_zip_path, ZipArchive::OVERWRITE);
		
		$tmp_dir = ROOT.'/tmp/'.rand().'/';
		mkdir($tmp_dir);
		$members = array();
		foreach ($files as $file_to_add) {
			if (FileRepository::getBackend() instanceof FileRepository_Backend_FileSystem) {
				$file_to_add_path = FileRepository::getBackend()->getFilePath($file_to_add->getLastRevision()->getRepositoryId());
			} else {
				$file_to_add_path = $tmp_dir . $file_to_add->getFilename();
				$handle = fopen($file_to_add_path, 'wb');
				fwrite($handle, $file_to_add->getLastRevision()->getFileContent(), $file_to_add->getLastRevision()->getFilesize());
				fclose($handle);
			}
			$zip->addFile($file_to_add_path, utf8_safe($file_to_add->getFilename()));
			$members[] = $file_to_add->getMemberIds();
		}
		$zip->close();
		delete_dir($tmp_dir);
                
		$this->upload_file($file, $filename, $tmp_zip_path, $members);
		unlink($tmp_zip_path);
		
		flash_success(lang('success compressing files', count($files)));
		ajx_current("reload");
	}
コード例 #22
0
 /**
  * Uninstall this module
  *
  * @param void
  * @return boolean
  */
 function uninstall()
 {
     db_execute('DROP TABLE IF EXISTS ' . TABLE_PREFIX . 'invoices');
     db_execute('DROP TABLE IF EXISTS ' . TABLE_PREFIX . 'invoice_items');
     db_execute('DROP TABLE IF EXISTS ' . TABLE_PREFIX . 'invoice_item_templates');
     db_execute('DROP TABLE IF EXISTS ' . TABLE_PREFIX . 'invoice_payments');
     db_execute('DROP TABLE IF EXISTS ' . TABLE_PREFIX . 'invoice_note_templates');
     db_execute('DROP TABLE IF EXISTS ' . TABLE_PREFIX . 'invoice_time_records');
     db_execute('DROP TABLE IF EXISTS ' . TABLE_PREFIX . 'tax_rates');
     db_execute('DROP TABLE IF EXISTS ' . TABLE_PREFIX . 'currencies');
     delete_dir(WORK_PATH . '/invoices');
     return parent::uninstall();
 }
コード例 #23
0
ファイル: dir.php プロジェクト: yunsite/yablog
/**
 * 删除目录及目录下面的所有文件
 *
 * @param string $dir 路径
 */
function delete_dir($dir)
{
    if (!is_dir($dir)) {
        return false;
    }
    $dir = dir_path($dir);
    $list = glob($dir . '*');
    foreach ($list as $v) {
        is_dir($v) ? delete_dir($v) : unlink($v);
    }
    return rmdir($dir);
}
$iteration = array(PHPT_ACL_READ => false, PHPT_ACL_NONE => false, PHPT_ACL_WRITE => true, PHPT_ACL_WRITE | PHPT_ACL_READ => true);
echo "Testing file:\n";
$i = 1;
$path = __DIR__ . '/a.txt';
foreach ($iteration as $perms => $exp) {
    create_file($path, $perms);
    clearstatcache(true, $path);
    echo 'Iteration #' . $i++ . ': ';
    if (is_writable($path) == $exp) {
        echo "passed.\n";
    } else {
        var_dump(is_writable($path), $exp);
        echo "failed.\n";
    }
    delete_file($path);
}
echo "Testing directory:\n";
$path = __DIR__ . '/adir';
$i = 1;
foreach ($iteration as $perms => $exp) {
    create_dir($path, $perms);
    clearstatcache(true, $path);
    echo 'Iteration #' . $i++ . ': ';
    if (is_writable($path) == $exp) {
        echo "passed.\n";
    } else {
        var_dump(is_writable($path), $exp);
        echo "failed.\n";
    }
    delete_dir($path);
}
コード例 #25
0
function delete_dir($dir)
{
    /* Recursive function that emulates "rm -rf dir" */
    if (is_dir($dir)) {
        foreach (glob($dir . "/*") as $dir_file) {
            if (is_dir($dir_file)) {
                delete_dir($dir_file);
            } else {
                unlink($dir_file);
            }
        }
        rmdir($dir);
    }
}
コード例 #26
0
 function delete_dir($dir)
 {
     // ajout du slash a la fin du chemin s'il n'y est pas
     if (!preg_match("/^.*\\/\$/", $dir)) {
         $dir .= '/';
     }
     // Ouverture du repertoire demande
     $handle = @opendir($dir);
     // si pas d'erreur d'ouverture du dossier on lance le scan
     if ($handle != false) {
         // Parcours du repertoire
         while ($item = readdir($handle)) {
             if ($item != "." && $item != "..") {
                 if (is_dir($dir . $item)) {
                     delete_dir($dir . $item);
                 } else {
                     unlink($dir . $item);
                 }
             }
         }
         // Fermeture du repertoire
         closedir($handle);
         // suppression du repertoire
         $res = rmdir($dir);
     } else {
         $res = false;
     }
     return $res;
 }
コード例 #27
0
ファイル: anfms.php プロジェクト: chaobj001/tt
 function delete_dir($dir)
 {
     if (!is_dir($dir)) {
         return false;
     }
     $handle = @opendir($dir);
     while (($file = @readdir($handle)) !== false) {
         if ($file != '.' && $file != '..') {
             $dir = $dir . '/' . $file;
             is_dir($dir) ? delete_dir($dir) : @unlink($dir);
         }
     }
     closedir($handle);
     return rmdir($dir);
 }
コード例 #28
0
ファイル: cloud.php プロジェクト: a195474368/ejw
 public static function moved_file($tmpdir, $newdir, $pack)
 {
     //return rename( $tmpdir, $newdir );
     $list = rglob($tmpdir . '*', GLOB_BRACE);
     //var_dump( $list );
     //exit;
     //批量迁移文件
     foreach ($list as $file) {
         $newd = str_replace($tmpdir, $newdir, $file);
         //var_dump( $file );
         //var_dump( $newd );
         //echo '<hr />';
         if (file_exists($file) && is_writable($file) == FALSE) {
             //记录在案
             self::$lastfile = str_replace($tmpdir, '', $file);
             return -10007;
         }
         ////////////////////////////
         if (file_exists($newd) && is_writable($newd) == FALSE) {
             //记录在案
             self::$lastfile = str_replace($newdir, '', $newd);
             return -10007;
         }
         ////////////////////////////
         //创建文件夹
         if (is_dir($file)) {
             create_dir($newd, TRUE, 0777);
         } else {
             //删除旧文件(winodws 环境需要)
             if (file_exists($newd)) {
                 unlink($newd);
             }
             //生成新文件
             $test = @rename($file, $newd);
             //记录在案
             self::$lastfile = str_replace($tmpdir, '', $file);
         }
         ////////////////////////////
         //移动文件出错
         if ($test === FALSE) {
             return -10005;
         }
     }
     //删除临时目录
     delete_dir($tmpdir);
     //删除文件包
     unlink(self::get_pack_file($pack));
     return count($list);
 }
コード例 #29
0
ファイル: admin_photo.php プロジェクト: hxfsc/hxfsc
    $photo_id = empty($_GET['photo_id']) ? '' : intval($_GET['photo_id']);
    $format = "SELECT `album_id` FROM `{$db_prefix}album` WHERE `album_id`='%d'";
    $format = sprintf($format, $photo_id);
    $query = $db->query($format);
    if ($query->num_rows < 1) {
        message(array('text' => $language['admin_photo_del_error'], 'link' => ''));
    }
    //取得相册目录
    $format = "SELECT `album_foler`,`album_cover` FROM `{$db_prefix}album` WHERE `album_id`='%d'";
    $format = sprintf($format, $photo_id);
    $query = $db->query($format);
    $album = $query->fetch_assoc();
    $album_folder = $album['album_foler'];
    $album_cover = $album['album_cover'];
    //删除相册下的照片
    delete_dir(ROOT_UPLOAD_PATH . 'album/' . $album_folder);
    $format = "DELETE FROM `{$db_prefix}album` WHERE `album_id`=%d";
    $format = sprintf($format, $photo_id);
    if ($db->query($format)) {
        message(array('text' => $language['admin_photo_del_success'], 'link' => ''));
    }
}
//上传图片
if ($doing == 'add_photo') {
    check_browser();
    check_user();
    $photo_id = empty($_GET['photo_id']) ? '' : intval($_GET['photo_id']);
    $format = "SELECT `album_name`,`album_id` FROM `{$db_prefix}album` WHERE `album_id`='%d'";
    $format = sprintf($format, $photo_id);
    $query = $db->query($format);
    $row = $query->fetch_assoc();
コード例 #30
0
ファイル: generator.php プロジェクト: beingsane/joomgen25
/**
 * Generates directory structure for the whole component, a manifest.xml file,
 * controllers and entry points for the frontend and the backend.
 *
 * @return void
 * @access public
 * @since  2.0
 */
function generate_output($config, $models, $frontend)
{
    $component = $config['component'];
    $base_path = $component . DS;
    $lang_path = 'language' . DS . $config['default_language'];
    $lang_file = DS . $config['default_language'] . '.' . $config['component'] . '.ini';
    // create fresh output directory
    @delete_dir($component);
    mkdir($component);
    // generate directory structure for the backend
    mkdir($base_path . 'admin');
    $admin_path = $base_path . 'admin' . DS;
    foreach (array('assets', 'controllers', 'help', 'helpers', 'install', 'updates', 'language', 'models', 'tables', 'views', $lang_path) as $dir) {
        mkdir($admin_path . $dir);
        file_put_contents($admin_path . $dir . DS . 'index.html', 'test');
    }
    // generate config.xml file
    file_put_contents($admin_path . DS . 'config.xml', file_get_contents('tmpl' . DS . 'admin' . DS . 'config.xml'));
    // generate SQL install / uninstall files
    if ($models) {
        $sql = prepare_sql($config, $models);
    } else {
        $sql = array('', '');
    }
    file_put_contents($admin_path . 'install' . DS . 'installsql.mysql.utf8.php', $sql[0]);
    file_put_contents($admin_path . 'install' . DS . 'uninstallsql.mysql.utf8.php', $sql[1]);
    // generate tables, models, controllers and views for the backend
    if ($models) {
        foreach (prepare_tables($config, $models) as $name => $content) {
            file_put_contents($admin_path . 'tables' . DS . $name, $content);
        }
        foreach (prepare_models_or_controllers($config, $models, array(), 'model') as $name => $content) {
            file_put_contents($admin_path . 'models' . DS . $name, $content);
        }
        foreach (prepare_models_or_controllers($config, $models, array(), 'controller') as $name => $content) {
            file_put_contents($admin_path . 'controllers' . DS . $name, $content);
        }
        $default_view_files = prepare_default_view($config, array());
        $view_path = $admin_path . 'views' . DS . strtolower($config['identifier']);
        mkdir($view_path);
        mkdir($view_path . DS . 'tmpl');
        foreach ($default_view_files as $name => $content) {
            file_put_contents($view_path . DS . $name, $content);
        }
        foreach (prepare_views_for_backend($config, $models) as $name => $views) {
            $view_path = $admin_path . 'views' . DS . $name;
            mkdir($view_path);
            mkdir($view_path . DS . 'tmpl');
            foreach ($views as $name => $content) {
                file_put_contents($view_path . DS . $name, $content);
            }
        }
        $submenu = "    <submenu>\n";
        foreach ($models as $model => $attrs) {
            if ($attrs['sql_only']) {
                continue;
            }
            $submenu .= "      <menu link='option={$component}&amp;view={$model}&amp;layout=list'>{$model}</menu>\n";
        }
        $submenu .= "    </submenu>\n";
        $config['submenu'] = $submenu;
    }
    // generate empty language file for the backend
    file_put_contents($admin_path . $lang_path . $lang_file, '');
    // generate directory structure for the frontend
    mkdir($base_path . 'site');
    $site_path = $base_path . 'site' . DS;
    foreach (array('assets', 'controllers', 'helpers', 'language', 'models', 'views', $lang_path) as $dir) {
        mkdir($site_path . $dir);
        file_put_contents($site_path . $dir . DS . 'index.html', 'test');
    }
    // generate models, controllers and views for the frontend
    if ($models) {
        foreach (prepare_models_or_controllers($config, $models, $frontend, 'model', 'site') as $name => $content) {
            file_put_contents($site_path . 'models' . DS . $name, $content);
        }
        foreach (prepare_models_or_controllers($config, $models, $frontend, 'controller', 'site') as $name => $content) {
            file_put_contents($site_path . 'controllers' . DS . $name, $content);
        }
        $default_view_files = prepare_default_view($config, $frontend, 'site');
        $view_path = $site_path . 'views' . DS . strtolower($config['identifier']);
        mkdir($view_path);
        mkdir($view_path . DS . 'tmpl');
        foreach ($default_view_files as $name => $content) {
            file_put_contents($view_path . DS . $name, $content);
        }
        foreach (prepare_views_for_frontend($config, $models, $frontend) as $name => $views) {
            $view_path = $site_path . 'views' . DS . $name;
            mkdir($view_path);
            mkdir($view_path . DS . 'tmpl');
            foreach ($views as $name => $content) {
                file_put_contents($view_path . DS . $name, $content);
            }
        }
    }
    // generate empty language file for the frontend
    file_put_contents($site_path . $lang_path . $lang_file, '');
    // generate manifest file
    $template = file_get_contents('tmpl' . DS . 'manifest.xml');
    file_put_contents($base_path . 'manifest.xml', render($template, $config));
    // generate controllers
    $template = file_get_contents('tmpl' . DS . 'controller.php');
    $rendered_template = render($template, $config);
    foreach (array($admin_path, $site_path) as $path) {
        file_put_contents($path . 'controller.php', $rendered_template);
    }
    // generate entry points
    $template = file_get_contents('tmpl' . DS . 'entry_point.php');
    $config['include_tables'] = "JTable::addIncludePath(JPATH_COMPONENT.DS.'tables');\n\n";
    file_put_contents($admin_path . $config['entry_point'], render($template, $config));
    $config['include_tables'] = '';
    file_put_contents($site_path . $config['entry_point'], render($template, $config));
    // create .tar.gz installer if it's on a unix-like OS
    if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
        @unlink("{$component}.tar.gz");
        system("tar -zcf {$component}.tar.gz {$component}");
        delete_dir($component);
    }
}