Beispiel #1
0
 /**
  * Unzip the form template and its dependencies to the client folder
  *
  * @param string $zipFilePath Temp zip file path.
  * @param integer $clientId
  * @param integer $_pageId
  * @return true | false
  */
 public function generateSurvey($zipFilePath, $clientId, $_pageId)
 {
     $this->_currentClientId = (int) $clientId;
     if ($this->_currentClientId <= 0) {
         return false;
     }
     if (!file_exists($zipFilePath)) {
         return false;
     }
     $_pageStorageFolder = $this->getClientFolderPath($this->_currentClientId) . DS . self::getPageFolderName($_pageId);
     $indexFileName = $_pageStorageFolder . DS . $_pageId . DS . $_pageId . ".html";
     // this is a one-time only copy
     if (!file_exists($indexFileName)) {
         $zip = new ZipArchive();
         $res = $zip->open($zipFilePath);
         if ($res !== TRUE) {
             return false;
         }
         // Extract to a temp folder
         $this->_currentTempFolder = $this->_tempPath . DS . time();
         //override server permission settings
         $old = umask(0);
         mkdir($this->_currentTempFolder, 0777);
         $zip->extractTo($this->_currentTempFolder);
         mkdir($_pageStorageFolder, 0777);
         //restore
         umask($old);
         Functions_File::recurse_copy($this->_currentTempFolder, $_pageStorageFolder . DS . $_pageId);
         // rename the index file
         $_templateIndexFile = $_pageStorageFolder . DS . $_pageId . DS . "index.html";
         if (file_exists($_templateIndexFile)) {
             rename($_templateIndexFile, $indexFileName);
         }
         // Close zip and remove temp working folder.
         $zip->close();
         Functions_File::rrmdir($this->_currentTempFolder);
         return $_pageStorageFolder;
     } else {
         return $_pageStorageFolder;
     }
 }
 /**
  * Generate pages based on the language folder.
  *
  * @param string $folderPath
  * @param string $language
  * @return false array
  */
 protected function _generatePagesForLanguageFolder($folderPath, $language)
 {
     $pages = array();
     $dir = dir($folderPath);
     while (false !== ($entry = $dir->read())) {
         if ($entry == '.' || $entry == '..' || $entry == '.DS_Store') {
             continue;
         }
         // We deal with each page
         $_pageFolder = $folderPath . DS . $entry;
         $_pageId = $entry;
         $_id = (int) Repo_Page::getInstance()->addNew($this->_currentClientId, $_pageId, Repo_Page::PAGE_TYPE_STATIC, Repo_Page::PAGE_STATUS_IN_PROGRESS, '', false, false, false, false, $language, $_pageId, false);
         if (empty($_id)) {
             // OK, we are deal with existing page
             $_id = Repo_Page::getInstance()->clientPageExists($this->_currentClientId, $_pageId, $language);
             $_existingPage = new Object_Page($_id);
             $_existingPage->cloud_file_container = null;
             $_existingPage->version++;
             $_existingPage->save();
         }
         // Copy to a path
         $_pageStorageFolder = $this->getClientFolderPath($this->_currentClientId) . DS . self::getPageFolderName($_pageId);
         if (!file_exists($_pageStorageFolder)) {
             mkdir($_pageStorageFolder, 0777);
         } else {
             // Remove the existing content since we are updating.
             if (file_exists($_pageStorageFolder . DS . $_pageId)) {
                 Functions_File::rrmdir($_pageStorageFolder . DS . $_pageId);
             }
         }
         Functions_File::recurse_copy($_pageFolder, $_pageStorageFolder . DS . $_pageId);
         // Check whether successfully
         if (!file_exists($_pageStorageFolder . DS . $_pageId)) {
             throw new Zend_Exception('Can not copy page content from a zip file: ' . $_pageStorageFolder);
         }
         $pages[] = $_id;
         // In case we upload a thumb image, use it.
         $page = new Object_Page($_id);
         $page->useStaticThumb();
     }
     $dir->close();
     return $pages;
 }