diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b43a831 --- /dev/null +++ b/.gitignore @@ -0,0 +1,49 @@ +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio + +*.iml + +## Directory-based project format: +.idea/ +# if you remove the above rule, at least ignore the following: + +# User-specific stuff: +# .idea/workspace.xml +# .idea/tasks.xml +# .idea/dictionaries + +# Sensitive or high-churn files: +# .idea/dataSources.ids +# .idea/dataSources.xml +# .idea/sqlDataSources.xml +# .idea/dynamic.xml +# .idea/uiDesigner.xml + +# Gradle: +# .idea/gradle.xml +# .idea/libraries + +# Mongo Explorer plugin: +# .idea/mongoSettings.xml + +## File-based project format: +*.ipr +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties + +# Created by .ignore support plugin (hsz.mobi) diff --git a/README.md b/README.md index 2c0b97d..5e3c34a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ [![License](https://img.shields.io/github/license/ImpressCMS/impresscms-module-imbuilding.svg?maxAge=2592000)](License.txt) [![GitHub release](https://img.shields.io/github/release/ImpressCMS/impresscms-module-imbuilding.svg?maxAge=2592000)](https://github.com/ImpressCMS/impresscms-module-imbuilding/releases) [![This is ImpressCMS module](https://img.shields.io/badge/ImpressCMS-module-F3AC03.svg?maxAge=2592000)](http://impresscms.org) + #imBuilding Module to generate base code of new modules :-) + diff --git a/SUMMARY.md b/SUMMARY.md new file mode 100644 index 0000000..df6f151 --- /dev/null +++ b/SUMMARY.md @@ -0,0 +1,3 @@ +# Summary + + diff --git a/book.json b/book.json new file mode 100644 index 0000000..e9c87ad --- /dev/null +++ b/book.json @@ -0,0 +1,6 @@ +{ + "plugins": [ + "add-header" + ], + "pluginsConfig": {} +} \ No newline at end of file diff --git a/class/Newmodule.php b/class/Newmodule.php index 685f4f3..7548733 100644 --- a/class/Newmodule.php +++ b/class/Newmodule.php @@ -672,16 +672,45 @@ private function getAdminMenuItems() { } /** - * Generate zip archive of generated module source + * Generate zip archive of generated module source - based heavily on + * this response in stackoverflow : + * http://stackoverflow.com/questions/4914750/how-to-zip-a-whole-folder-using-php */ private function createArchive() { //icms::$logger->disableLogger(); - include_once IMBUILDING_ROOT_PATH . 'include/easyarchives/EasyArchive.class.php'; - $arch = new archive; + + $zip = new ZipArchive(); + $fileName = $this->moduleinfo['modulename'] . '_' . time() . '.zip'; $archiveFilePath = ICMS_UPLOAD_PATH . '/imbuilding/packages/' . $fileName; $archiveSource = ICMS_CACHE_PATH . '/imbuilding/' . $this->moduleinfo['modulename']; - $arch->make($archiveSource, $archiveFilePath); + + $zip->open($archiveFilePath, ZipArchive::CREATE | ZipArchive::OVERWRITE); + + // Create recursive directory iterator + /** @var SplFileInfo[] $files */ + $files = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($archiveSource), + RecursiveIteratorIterator::LEAVES_ONLY + ); + + foreach ($files as $name => $file) + { + // Skip directories (they would be added automatically) + if (!$file->isDir()) + { + // Get real and relative path for current file + $filePath = $file->getRealPath(); + $relativePath = substr($filePath, strlen($rootPath) + 1); + + // Add current file to archive + $zip->addFile($filePath, $relativePath); + } + } + + // Zip archive will be created only after closing object + $zip->close(); + $this->archiveUrl = ICMS_UPLOAD_URL . '/imbuilding/packages/' . $fileName; } diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..92d7e68 --- /dev/null +++ b/composer.json @@ -0,0 +1,27 @@ +{ + "name": "impresscms/impresscms-module-imbuilding", + "description": "A module to help you jumpstart development of ImpressCMS modules", + "minimum-stability": "beta", + "license": "GPL", + "authors": [ + { + "name": "David Janssens (fiammybe)", + "email": "david.j@impresscms.org" + }, + { + "name": "INBOX International Inc.", + "email": "info@inboxintl.com" + }, + { + "name": "Steve Kenow (skenow)", + "email": "skenow@impresscms.org" + }, + { + "name": "René Sato (sato-san)", + "email": "sato-san@impresscms.org" + }, + { + "name": "Steffen Floher (QM-B)" + } + ] +} \ No newline at end of file diff --git a/include/easyarchives/EasyArchive.class.php b/include/easyarchives/EasyArchive.class.php deleted file mode 100755 index fdabf76..0000000 --- a/include/easyarchives/EasyArchive.class.php +++ /dev/null @@ -1,189 +0,0 @@ -make('./', './archive.tar.gzip'); -var_export($arch->infos('./toto.bzip2')); -$arch->extract('./toto.zip', './my_dir/'); -$arch->download('./my_dir/'); -**/ - -class archive { - var $WathArchive = array ( - '.zip' =>'zip', - '.tar' =>'tar', - '.gz' =>'gz', - '.gzip' =>'gz', - '.bzip' =>'bz', - '.bz' =>'bz', - '.bzip2' =>'bz', - '.bz2' =>'bz', - '.tgz' =>'gz', - '.tgzip' =>'gz', - '.tbzip' =>'bz', - '.tbz' =>'bz', - '.tbzip2' =>'bz', - '.tbz2' =>'bz', - ); - function download ($src, $name) - { - header('Content-Type: application/force-download'); - header("Content-Transfer-Encoding: binary"); - header("Cache-Control: no-cache, must-revalidate, max-age=60"); - header("Expires: Sat, 01 Jan 2000 12:00:00 GMT"); - header('Content-Disposition: attachment;filename="'.$name."\"\n"); - $data = $this->make($src, $name, FALSE); - header("Content-Length: ".strlen($data)); - print($data); - } - function make ($src, $name="Archive.tgz", $returnFile=TRUE) - { - $ext = '.'.pathinfo ($name, PATHINFO_EXTENSION); - foreach ($this->WathArchive as $key=>$val) - if (stripos($ext, $key)!==FALSE) $comp=$val; - if ($comp == 'zip') - { - $zip = new zip; - if ($returnFile) - $result = $zip->makeZip($src, $name); - else - { - $tmpZip = './'.md5(serialize($src)).'.zip'; - $result = $zip->makeZip($src, $tmpZip); - $result = file_get_contents($tmpZip); - unlink($tmpZip); - } - return $result; - } - elseif (strlen($comp)>1) - { - if (count($src)>1 || is_dir($src[0]) || $comp == 'tar') - { - $tar = new tar; - $src = $tar->makeTar($src); - } - if ($comp == 'bz') - { - $bzip2 = new bzip2; - $src = $bzip2->makeBzip2($src); - } - elseif ($comp == 'gz') - { - $gzip = new gzip; - $src = $gzip->makeGzip($src); - } - if ($returnFile) - { - file_put_contents($dest, $src); - return $dest; - } - return $src; - } - else return 'Specifie a valid format at the end of '.$name.' filename ! '; - } - function infos ($src, $data=FALSE) - { - $ext = '.'.pathinfo ($src, PATHINFO_EXTENSION); - foreach ($this->WathArchive as $key=>$val) - if (stripos($ext, $key)!==FALSE) $comp=$val; - if ($comp == 'zip') - { - $zip = new zip; - $zipresult = $zip->infosZip($src, $data); - $result ['Items'] = count($zipresult); - foreach($zipresult as $key=>$val) - $result['UnCompSize'] += $zipresult[$key]['UnCompSize']; - $result['Size']=filesize($src); - $result['Ratio'] = $result['UnCompSize'] ? round(100 - $result['Size'] / $result['UnCompSize']*100, 1) : FALSE; - } - elseif (strlen($comp)>1) - { - $tar = new tar; - if ($comp == 'bz') - { - $bzip2 = new bzip2; - $result = $bzip2->infosBzip2($src, TRUE); - $src=$result['Data']; - } - elseif ($comp == 'gz') - { - $gzip = new gzip; - $result = $gzip->infosGzip($src, TRUE); - $src=$result['Data']; - } - if ($tar->is_tar($src) || is_file($src)) - { - $tarresult = $tar->infosTar($src, FALSE); - $result ['Items'] = count($tarresult); - $result ['UnCompSize'] = 0; - if (empty($result['Size'])) - $result['Size']=is_file($src)?filesize($src):strlen($src); - foreach($tarresult as $key=>$val) - $result['UnCompSize'] += $tarresult[$key]['size']; - $result['Ratio'] = $result['UnCompSize'] ? round(100 - $result['Size'] / $result['UnCompSize']*100, 1) : FALSE; - - } - if (!$data) unset($result['Data']); - } - else return FALSE; - return array('Items'=>$result['Items'], 'UnCompSize'=>$result['UnCompSize'], 'Size'=>$result['Size'], 'Ratio'=>$result['Ratio'],); - } - function extract ($src, $dest=FALSE) - { - $path_parts = pathinfo ($src); - if (!$dest) - $dest = $path_parts['dirname'].'/'; - $ext = '.'.$path_parts['extension']; - $name = $path_parts['filename']; - foreach ($this->WathArchive as $key=>$val) - if (stripos($ext, $key)!==FALSE) $comp=$val; - if ($comp == 'zip') - { - $zip = new zip; - return $zip->extractZip($src, $dest); - } - elseif (strlen($comp)>1) - { - $tar = new tar; - if ($comp == 'bz') - { - $bzip2 = new bzip2; - $src = $bzip2->extractBzip2($src); - } - elseif ($comp == 'gz') - { - $gzip = new gzip; - $src = $gzip->extractGzip($src); - } - if ($tar->is_tar($src) || is_file($src)) - { - return $tar->extractTar($src, $dest); - } - else file_put_contents($dest.$name, $src); - return $dest; - } - return FALSE; - } -} \ No newline at end of file diff --git a/include/easyarchives/EasyBzip2.class.php b/include/easyarchives/EasyBzip2.class.php deleted file mode 100755 index 144bfeb..0000000 --- a/include/easyarchives/EasyBzip2.class.php +++ /dev/null @@ -1,55 +0,0 @@ -makeBzip2('./','./toto.bzip2'); -var_export($test->infosBzip2('./toto.bzip2')); -$test->extractBzip2('./toto.bzip2', './new/'); -**/ - function makeBzip2($src, $dest=FALSE) - { - $Bzip2 = bzcompress((strpos(chr(0),$src) ? file_get_contents ($src) : $src), 6); - if (empty($dest)) return $Bzip2; - elseif (file_put_contents($dest, $Bzip2)) return $dest; - return FALSE; - } - function infosBzip2 ($src, $data=TRUE) - { - $data = $this->extractBzip2 ($src); - $content = array( - 'UnCompSize'=>strlen($data), - 'Size'=>filesize($src), - 'Ratio'=>strlen($data) ? round(100 - filesize($src) / strlen($data)*100, 1) : FALSE,); - if ($data) $content['Data'] = $data; - return $content; - } - function extractBzip2($src, $dest=FALSE) - { - $bz = bzopen($src, "r"); - $data = ''; - while (!feof($bz)) - $data .= bzread($bz, 1024*1024); - bzclose($bz); - if (empty($dest)) return $data; - elseif (file_put_contents($dest, $data)) return $dest; - return FALSE; - } -} \ No newline at end of file diff --git a/include/easyarchives/EasyGzip.class.php b/include/easyarchives/EasyGzip.class.php deleted file mode 100755 index 6b4704e..0000000 --- a/include/easyarchives/EasyGzip.class.php +++ /dev/null @@ -1,55 +0,0 @@ -makeGzip('./','./toto.gzip'); -var_export($test->infosGzip('./toto.gzip')); -$test->extractGzip('./toto.gzip', './new/'); -**/ - function makeGzip($src, $dest=FALSE) - { - $Gzip = gzencode((strpos(chr(0),$src) ? file_get_contents ($src) : $src), 6); - if (empty($dest)) return $Gzip; - elseif (file_put_contents($dest, $Gzip)) return $dest; - return FALSE; - } - function infosGzip ($src, $data=TRUE) - { - $data = $this->extractGzip ($src); - $content = array( - 'UnCompSize'=>strlen($data), - 'Size'=>filesize($src), - 'Ratio'=>strlen($data) ? round(100 - filesize($src) / strlen($data)*100, 1) : FALSE,); - if ($data) $content['Data'] = $data; - return $content; - } - function extractGzip ($src, $dest=FALSE) - { - $zp = gzopen( $src, "r" ); - $data = ''; - while (!gzeof($zp)) - $data .= gzread($zp, 1024*1024); - gzclose( $zp ); - if (empty($dest)) return $data; - elseif (file_put_contents($dest, $data)) return $dest; - return FALSE; - } -} \ No newline at end of file diff --git a/include/easyarchives/EasyTar.class.php b/include/easyarchives/EasyTar.class.php deleted file mode 100755 index e21cde3..0000000 --- a/include/easyarchives/EasyTar.class.php +++ /dev/null @@ -1,202 +0,0 @@ -makeTar('./','./toto.Tar'); -var_export($test->infosTar('./toto.Tar')); -$test->extractTar('./toto.Tar', './new/'); -**/ - function infosTar ($src, $data=TRUE) - { - if ($this->is_tar($src)) - { - file_put_contents ($tmp='~tmp('.microtime().').tar', $src); - $src = $tmp; - } - $ptr = fopen($src, 'r'); - while (!feof($ptr)) - { - $infos = $this->readTarHeader ($ptr); - if ($infos['name']) - { - if (!$data) unset($infos['data']); - $result[$infos['name']]=$infos; - } - } - if (is_file($tmp)) unlink($tmp); - return $result; - } - function makeTar($src, $dest=FALSE) - { - $src = is_array($src) ? $src : array($src); - $src = array_map('realpath', $src); - foreach ($src as $item) - $Tar .= $this->addTarItem($item.((is_dir($item) && substr($item, -1)!='/')?'/':''), dirname($item).'/'); - - $Tar = str_pad($Tar, floor((strlen($Tar) + 10240 - 1) / 10240) * 10240, "\0"); - if (empty($dest)) return $Tar; - elseif (file_put_contents($dest, $Tar)) return $dest; - else FALSE; - } - function extractTar ($src, $dest) - { - if ($this->is_tar($src)) - { - file_put_contents ($tmp='~tmp('.microtime().').tar', $src); - $src = $tmp; - } - $ptr = fopen($src, 'r'); - while (!feof($ptr)) - { - $infos = $this->readTarHeader ($ptr); - if ($infos['type']=='5' && @mkdir($dest.$infos['name'], 0775, TRUE)) - $result[]=$dest.$infos['name']; - elseif (($infos['type']=='0' || $infos['type']==chr(0)) && file_put_contents($dest.$infos['name'], $infos['data'])) - $result[]=$dest.$infos['name']; - if ($infos) - chmod($dest.$infos['name'], 0775); -// chmod(, $infos['mode']); -// chgrp(, $infos['uname']); -// chown(, $infos['gname']); - } - if (is_file($tmp)) unlink($tmp); - return $result; - } - function is_tar($str) - { - $block = substr($str,0, 512); - if (strlen($block)!=512) return FALSE; - $realchecksum = octdec(substr($str,148,8)); - $checksum = 0; - $block = substr_replace($block, ' ', 148, 8); - for ($i = 0; $i < 512; $i++) - $checksum += ord(substr($block, $i, 1)); - if ($realchecksum==$checksum) return TRUE; - return FALSE; - } - function tarHeader512($infos) - { /* http://www.mkssoftware.com/docs/man4/tar.4.asp */ - $bigheader = $header = ''; - if (strlen($infos['name100'])>100) - { - $bigheader = pack("a100a8a8a8a12a12a8a1a100a6a2a32a32a8a8a155a12", - '././@LongLink','0000000','0000000','0000000', - sprintf("%011o", strlen($infos['name100'])),'00000000000', - ' ', 'L', '', 'ustar ', '0', - $infos['userName32'], - $infos['groupName32'],'','','',''); - - $bigheader .= str_pad($infos['name100'], floor((strlen($infos['name100']) + 512 - 1) / 512) * 512, "\0"); - - $checksum = 0; - for ($i = 0; $i < 512; $i++) - $checksum += ord(substr($bigheader, $i, 1)); - $bigheader = substr_replace($bigheader, sprintf("%06o", $checksum)."\0 ", 148, 8); - } - $header = pack("a100a8a8a8a12a12a8a1a100a6a2a32a32a8a8a155a12", // book the memorie area - substr($infos['name100'],0,100), // 0 100 File name - str_pad(substr(sprintf("%07o",$infos['mode8']),-4), 7, '0', STR_PAD_LEFT), // 100 8 File mode - sprintf("%07o", $infos['uid8']), // 108 8 Owner user ID - sprintf("%07o", $infos['gid8']), // 116 8 Group user ID - sprintf("%011o", $infos['size12']), // 124 12 File size in bytes - sprintf("%011o", $infos['mtime12']), // 136 12 Last modification time - ' ', // 148 8 Check sum for header block - $infos['link1'], // 156 1 Link indicator / ustar Type flag - $infos['link100'], // 157 100 Name of linked file - 'ustar ', // 257 6 USTAR indicator "ustar" - ' ', // 263 2 USTAR version "00" - $infos['userName32'], // 265 32 Owner user name - $infos['groupName32'], // 297 32 Owner group name - '', // 329 8 Device major number - '', // 337 8 Device minor number - $infos['prefix155'], // 345 155 Filename prefix - ''); // 500 12 ?? - - $checksum = 0; - for ($i = 0; $i < 512; $i++) - $checksum += ord(substr($header, $i, 1)); - $header = substr_replace($header, sprintf("%06o", $checksum)."\0 ", 148, 8); - - return $bigheader.$header; - } - function addTarItem ($item, $racine) - { - $infos['name100'] = str_replace($racine, '', $item); - list (, , $infos['mode8'], , $infos['uid8'], $infos['gid8'], , , , $infos['mtime12'] ) = stat($item); - $infos['size12'] = is_dir($item) ? 0 : filesize($item); - $infos['link1'] = is_link($item) ? 2 : is_dir ($item) ? 5 : 0; - $infos['link100'] == 2 ? readlink($item) : ""; - - $a=function_exists('posix_getpwuid')?posix_getpwuid (fileowner($item)):array('name'=>'Unknown'); - $infos['userName32'] = $a['name']; - - $a=function_exists('posix_getgrgid')?posix_getgrgid (filegroup($item)):array('name'=>'Unknown'); - $infos['groupName32'] = $a['name']; - $infos['prefix155'] = ''; - - $header = $this->tarHeader512($infos); - $data = str_pad(file_get_contents($item), floor(($infos['size12'] + 512 - 1) / 512) * 512, "\0"); - if (is_dir($item)) - { - $lst = scandir($item); - array_shift($lst); // remove ./ of $lst - array_shift($lst); // remove ../ of $lst - foreach ($lst as $subitem) - $sub .= $this->addTarItem($item.$subitem.(is_dir($item.$subitem)?'/':''), $racine); - } - return $header.$data.$sub; - } - function readTarHeader ($ptr) - { - $block = fread($ptr, 512); - if (strlen($block)!=512) return FALSE; - $hdr = unpack ("a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2version/a32uname/a32gname/a8devmajor/a8devminor/a155prefix/a12temp", $block); - $hdr['mode']=$hdr['mode']+0; - $hdr['uid']=octdec($hdr['uid']); - $hdr['gid']=octdec($hdr['gid']); - $hdr['size']=octdec($hdr['size']); - $hdr['mtime']=octdec($hdr['mtime']); - $hdr['checksum']=octdec($hdr['checksum']); - $checksum = 0; - $block = substr_replace($block, ' ', 148, 8); - for ($i = 0; $i < 512; $i++) - $checksum += ord(substr($block, $i, 1)); - if (isset($hdr['name']) && $hdr['checksum']==$checksum) - { - if ($hdr['name']=='././@LongLink' && $hdr['type']=='L') - { - $realName = substr(fread($ptr, floor(($hdr['size'] + 512 - 1) / 512) * 512), 0, $hdr['size']-1); - $hdr2 = $this->readTarHeader ($ptr); - $hdr2['name'] = $realName; - return $hdr2; - } - elseif (strtolower(substr($hdr['magic'], 0, 5) == 'ustar')) - { - if ($hdr['size']>0) - $hdr['data'] = substr(fread($ptr, floor(($hdr['size'] + 512 - 1) / 512) * 512), 0, $hdr['size']); - else $hdr['data'] = ''; - return $hdr; - } - else return FALSE; - } - else return FALSE; - } -} \ No newline at end of file diff --git a/include/easyarchives/EasyZip.class.php b/include/easyarchives/EasyZip.class.php deleted file mode 100755 index 816a8ca..0000000 --- a/include/easyarchives/EasyZip.class.php +++ /dev/null @@ -1,95 +0,0 @@ -makeZip('./','./toto.zip'); -var_export($test->infosZip('./toto.zip')); -$test->extractZip('./toto.zip', './new/'); -**/ - function infosZip ($src, $data=TRUE) - { - if (($zip = zip_open(realpath($src)))) - { - while (($zip_entry = zip_read($zip))) - { - $path = zip_entry_name($zip_entry); - if (zip_entry_open($zip, $zip_entry, "r")) - { - $content[$path] = array ( - 'Ratio' => zip_entry_filesize($zip_entry) ? round(100-zip_entry_compressedsize($zip_entry) / zip_entry_filesize($zip_entry)*100, 1) : FALSE, - 'Size' => zip_entry_compressedsize($zip_entry), - 'UnCompSize' => zip_entry_filesize($zip_entry)); - if ($data) - $content[$path]['Data'] = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); - zip_entry_close($zip_entry); - } - else - $content[$path] = FALSE; - } - zip_close($zip); - return $content; - } - return FALSE; - } - function extractZip ($src, $dest) - { - $zip = new ZipArchive; - if ($zip->open($src)===TRUE) - { - $zip->extractTo($dest); - $zip->close(); - return TRUE; - } - return FALSE; - } - function makeZip ($src, $dest) - { - $zip = new ZipArchive; - $src = is_array($src) ? $src : array($src); - if ($zip->open($dest, ZipArchive::CREATE) === TRUE) - { - foreach ($src as $item) - { - if (is_dir($item)) - $this->addZipItem($zip, realpath(dirname($item)).'/', realpath($item).'/'); - elseif(is_file($item)) - $zip->addFile(realpath($item), basename(realpath($item))); - } - $zip->close(); - return TRUE; - } - return FALSE; - } - function addZipItem ($zip, $racine, $dir) - { - if (is_dir($dir)) - { - $zip->addEmptyDir(str_replace($racine, '', $dir)); - $lst = scandir($dir); - array_shift($lst); - array_shift($lst); - foreach ($lst as $item) - $this->addZipItem($zip, $racine, $dir.$item.(is_dir($dir.$item)?'/':'')); - } - elseif (is_file($dir)) - $zip->addFile($dir, str_replace($racine, '', $dir)); - } -} \ No newline at end of file diff --git a/include/easyarchives/index.html b/include/easyarchives/index.html deleted file mode 100644 index 990cbd6..0000000 --- a/include/easyarchives/index.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file