/**
  * Create zip install package for this component
  * @param string $path Path to store zip file at
  * @todo add data files (db)
  * @todo create meta.yml
  * @todo allow template files
  * @todo test $customized
  */
 public function pack($path, $customized = false)
 {
     $pathParts = explode('.', $path);
     if (empty($path) || end($pathParts) != 'zip') {
         throw new ReflectionComponentException('Invalid file name passed. Provide a valid zip file name');
     }
     $websitePath = \Env::get('cx')->getWebsiteDocumentRootPath();
     // Create temp working folder and copy ZIP contents
     $filesystem = new \Cx\Lib\FileSystem\FileSystem();
     // clean up tmp dir
     $filesystem->delete_folder(ASCMS_APP_CACHE_FOLDER, true);
     echo "Copying files ... ";
     $filesystem->make_folder(ASCMS_APP_CACHE_FOLDER . '/DLC_FILES' . SystemComponent::getPathForType($this->componentType), true);
     $cacheComponentFolderPath = ASCMS_APP_CACHE_FOLDER . '/DLC_FILES' . SystemComponent::getPathForType($this->componentType) . '/' . $this->componentName;
     $cacheComponentFolderWebPath = ASCMS_APP_CACHE_FOLDER_WEB_PATH . '/DLC_FILES' . SystemComponent::getPathForType($this->componentType) . '/' . $this->componentName;
     $filesystem->copyDir($this->getDirectory(false), preg_replace('#' . $websitePath . '#', '', $this->getDirectory(false)), '', $cacheComponentFolderPath, $cacheComponentFolderWebPath, '', true);
     echo "Done \n";
     if ($customized) {
         // overwrite with contents of $this->getDirectory(true, true)
         echo "Copying customizing files ... ";
         $filesystem->copyDir($this->getDirectory(true, true), preg_replace('#' . $websitePath . '#', '', $this->getDirectory(true, true)), '', $cacheComponentFolderPath, $cacheComponentFolderWebPath, '', true);
         echo "Done \n";
     }
     echo "Writing component data (structure & data) ... ";
     $this->writeDatabaseStructureAndData();
     echo "Done \n";
     $componentFolder = $this->getDirectory($customized);
     if (!file_exists($componentFolder . '/meta.yml')) {
         echo "Meta file not exist. \n";
         echo "Creating meta file ... ";
         // Create meta.yml
         $this->writeMetaDataToFile($cacheComponentFolderPath . '/meta.yml');
         echo "Done \n";
     } else {
         echo "Copying additional files ...";
         // Read meta file
         $yaml = new \Symfony\Component\Yaml\Yaml();
         $content = file_get_contents($componentFolder . '/meta.yml');
         $meta = $yaml->load($content);
         if (isset($meta['DlcInfo']['additionalFiles'])) {
             foreach ($meta['DlcInfo']['additionalFiles'] as $additionalFile) {
                 $srcPath = $websitePath . '/' . $additionalFile;
                 if ($filesystem->exists($srcPath)) {
                     if (is_dir($srcPath)) {
                         $filesystem->copyDir($srcPath, preg_replace('#' . $websitePath . '#', '', $srcPath), '', ASCMS_APP_CACHE_FOLDER . '/DLC_FILES/' . $additionalFile, ASCMS_APP_CACHE_FOLDER_WEB_PATH . '/DLC_FILES/' . $additionalFile, '', true);
                     } else {
                         $folder = dirname($srcPath);
                         $folderPath = preg_replace('#' . $websitePath . '#', '', $folder);
                         $filesystem->make_folder(ASCMS_APP_CACHE_FOLDER . '/DLC_FILES' . $folderPath, true);
                         $filesystem->copy_file($srcPath, ASCMS_APP_CACHE_FOLDER . '/DLC_FILES/' . $additionalFile);
                     }
                 } else {
                     echo "WARNING: File missing - " . $additionalFile;
                 }
             }
         }
         echo "Done \n";
     }
     $filesystem->copy_file($cacheComponentFolderPath . '/meta.yml', ASCMS_APP_CACHE_FOLDER . '/meta.yml');
     $filesystem->copy_file($websitePath . '/core/Core/Data/README.txt', ASCMS_APP_CACHE_FOLDER . '/README.txt');
     echo "Exporting component ... ";
     // Compress
     $file = new \PclZip($path);
     $file->create(ASCMS_APP_CACHE_FOLDER, PCLZIP_OPT_REMOVE_PATH, ASCMS_APP_CACHE_FOLDER);
     echo "Done \n";
 }
示例#2
0
 /**
  * get the shared files by upload id
  *
  * @param integer $uploadId the upload id of the upload
  *
  * @return array with files of the last upload
  *
  * @access private
  */
 private function getSharedFiles($uploadId)
 {
     global $objDatabase;
     $cx = \Cx\Core\Core\Controller\Cx::instanciate();
     $fileSystem = new \Cx\Lib\FileSystem\FileSystem();
     $imageUrl = clone \Env::get("Resolver")->getUrl();
     // get the image url
     $files = array();
     $directory = \Env::get('Resolver')->getCmd();
     if ($directory != 'Downloads') {
         $targetPath = $cx->getWebsiteMediaFileSharingPath() . '/' . (!empty($directory) ? $directory . '/' : '');
         $targetPathWeb = $cx->getWebsiteMediaFileSharingWebPath() . '/' . (!empty($directory) ? $directory . '/' : '');
     } else {
         $targetPath = $cx->getWebsiteImagesDownloadsPath() . '/';
         $targetPathWeb = $cx->getWebsiteImagesDownloadsWebPath() . '/';
     }
     $tup = FileSharingLib::getTemporaryFilePaths($uploadId);
     $dirTempPath = $tup[0] . '/' . $tup[2] . '/';
     //get the tmp/$uploadId files
     foreach (glob($dirTempPath . '/*') as $uploadedFile) {
         $file = basename($uploadedFile);
         $uploadedFileName = $fileSystem->copyFile($dirTempPath, $file, $targetPath, $file, false);
         if ($uploadedFileName === 'error') {
             continue;
         }
         \Cx\Lib\FileSystem\FileSystem::delete_file($dirTempPath . '/' . $file);
         $uploadedFileSource = $targetPathWeb . $uploadedFileName;
         $hash = self::createHash();
         $check = self::createCheck($hash);
         $objResult = $objDatabase->Execute("INSERT INTO " . DBPREFIX . "module_filesharing (`file`, `source`, `cmd`, `hash`, `check`, `upload_id`)\n                                VALUES (\n                                    '" . contrexx_raw2db($uploadedFileName) . "',\n                                    '" . contrexx_raw2db($uploadedFileSource) . "',\n                                    '" . contrexx_raw2db($directory) . "',\n                                    '" . contrexx_raw2db($hash) . "',\n                                    '" . contrexx_raw2db($check) . "',\n                                    '" . contrexx_input2int($uploadId) . "'\n                                )");
         if (!$objResult) {
             continue;
         }
         $imageUrl->setParam("act", "image");
         $imageUrl->setParam("hash", $hash);
         $info = pathinfo($cx->getWebsiteOffsetPath() . $uploadedFileSource, PATHINFO_EXTENSION);
         // if the file is an image show a thumbnail of the image
         if (!in_array(strtoupper($info), array('JPEG', 'JPG', 'TIFF', 'GIF', 'BMP', 'PNG'))) {
             $imageUrl = false;
         }
         $fieldId = $objDatabase->Insert_ID();
         $files[] = array("name" => $uploadedFileName, "image" => $imageUrl->toString(), "download" => parent::getDownloadLink($fieldId), "delete" => parent::getDeleteLink($fieldId));
     }
     return $files;
 }
示例#3
0
 /**
  * get the shared files by upload id
  *
  * @param integer $uploadId the upload id of the upload
  *
  * @return array with files of the last upload
  *
  * @access private
  */
 private function getSharedFiles($uploadId)
 {
     global $objDatabase;
     $files = array();
     $tup = FileSharingLib::getTemporaryFilePaths($uploadId);
     // loop through the uploaded files
     $objResult = $objDatabase->Execute("SELECT `id`, `file`, `source`, `hash`, `check` FROM " . DBPREFIX . "module_filesharing WHERE `upload_id` = " . intval($uploadId));
     if ($objResult !== false && $objResult->RecordCount() > 0) {
         $cx = \Cx\Core\Core\Controller\Cx::instanciate();
         while (!$objResult->EOF) {
             $filePath = explode("/", $objResult->fields["source"]);
             $fileNameSource = end($filePath);
             $fileSystem = new \Cx\Lib\FileSystem\FileSystem();
             $directory = \Env::get('Resolver')->getCmd();
             if ($directory != 'Downloads') {
                 $newPath = $cx->getWebsiteMediaFileSharingPath() . '/' . $directory . '/';
             } else {
                 $newPath = $cx->getWebsiteImagesDownloadsPath() . '/';
             }
             $fileSystem->copyFile($tup[0] . '/' . $tup[2] . '/', $fileNameSource, $newPath, $fileNameSource, false);
             // get file name
             $fileName = $objResult->fields["file"];
             // get the image url
             $imageUrl = clone \Env::get("Resolver")->getUrl();
             $imageUrl->setParam("act", "image");
             $imageUrl->setParam("hash", $objResult->fields["hash"]);
             $info = pathinfo($cx->getWebsiteOffsetPath() . $objResult->fields["source"]);
             // if the file is an image show a thumbnail of the image
             if (!in_array(strtolower($info["extension"]), array("jpeg", "jpg", "png", "gif"))) {
                 $imageUrl = false;
             }
             $files[] = array("name" => $fileName, "image" => $imageUrl, "download" => parent::getDownloadLink($objResult->fields["id"]), "delete" => parent::getDeleteLink($objResult->fields["id"]));
             $objResult->moveNext();
         }
     }
     return $files;
 }