public function bomAction() { if (IS_POST) { $f = I('post.file'); if (!empty($f)) { $fname = MB_ROOT . $f; if (is_file($fname)) { $data = file_get_contents($fname); $bom = substr($data, 0, 3); if ($bom == "") { $data = substr($data, 3); file_put_contents($fname, $data); exit('success'); } } exit; } $path = MB_ROOT; $tree = File::tree($path); $ds = array(); foreach ($tree as $t) { $t = str_replace($path, '', $t); $t = str_replace('\\', '/', $t); if (preg_match('/^.*\\.php$/', $t)) { $fname = $path . $t; $fp = fopen($fname, 'r'); if (!empty($fp)) { $bom = fread($fp, 3); fclose($fp); if ($bom == "") { $ds[] = $t; } } } } $this->assign('ds', $ds); } C('FRAME_CURRENT', U('control/site/flush')); $this->display(); }
public function addonsAction() { $addons = array(); $path = MB_ROOT . 'addons/'; if (is_dir($path)) { if ($handle = opendir($path)) { while (false !== ($addonpath = readdir($handle))) { if ($addonpath != '.' && $addonpath != '..') { $define = Addon::getAddon($addonpath, true); if (!is_error($define)) { $addons[] = $define; } } } } } if (IS_POST) { $a = I('post.addon'); $addons = coll_key($addons, 'name'); $addon = $addons[$a]; if (!empty($addon)) { $zip = new \ZipArchive(); $tmpFile = ADDON_CURRENT_PATH . 'Data/package.zip'; @unlink($tmpFile); $zip->open($tmpFile, \ZipArchive::CREATE); $root = MB_ROOT . "addons/{$a}"; $files = File::tree($root); foreach ($files as $file) { $local = substr($file, strlen($root)); if (substr($local, -4) == '.php') { if (I('post.trim') != '') { $content = $this->trimComments($file, I('post.license')); } $zip->addFromString("{$a}{$local}", $content); } else { $zip->addFile($file, "{$a}{$local}"); } } $zip->close(); $version = MB_VERSION; $filename = "{$a}-v{$addon['version']} (for MB-{$version})"; header('content-type: application/zip'); header('content-disposition: attachment; filename="' . $filename . '.zip"'); readfile($tmpFile); @unlink($tmpFile); } } $this->assign('addons', $addons); $this->display('addons'); }