Esempio n. 1
0
 /**
  * Returns an instance.
  *
  * Singleton pattern implementation.
  *
  * @return Manager_File_Rackspace
  */
 public static function getInstance()
 {
     if (null === self::$_instance) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Esempio n. 2
0
 /**
  * Copy cloud folder to cloud folder.
  *
  * @param string $src
  * @param string $dst
  * @return void
  */
 public static function copy_cloud_to_cloud($container, $src, $dst)
 {
     $objectList = Manager_File_Rackspace::getInstance()->getObjectList($src, $container);
     foreach ($objectList as $_o) {
         $_srcName = $_o->getName();
         $_dstName = str_replace($src, $dst, $_srcName);
         Manager_File_Rackspace::getInstance()->copyFile($_srcName, $_dstName, $container);
     }
 }
Esempio n. 3
0
 /**
  * Generate a thumb of an image and save it to the specific path.
  *
  * @param string $sourceFile
  * @param string $destFile
  * @param boolean $isCloud
  * @return boolean
  */
 public function thumb($sourceFile, $destFile, $isCloud = false, $cloudFileName = '')
 {
     if (!file_exists($sourceFile)) {
         return false;
     }
     if (file_exists($destFile)) {
         unlink($destFile);
     }
     $size = new \Imagine\Image\Box(self::THUMB_WIDTH, self::THUMB_HEIGHT);
     $mode = \Imagine\Image\ImageInterface::THUMBNAIL_OUTBOUND;
     try {
         $this->_imagine->open($sourceFile)->thumbnail($size, $mode)->save($destFile);
     } catch (Exception $e) {
         return false;
     }
     // Save to cloud
     if ($isCloud) {
         Manager_File_Rackspace::getInstance()->saveFile($destFile, $cloudFileName, false, 'image/jpeg');
     }
     return true;
 }
Esempio n. 4
0
 /**
  * Generate pages based on the language folder.
  *
  * @param string $folderPath
  * @param string $language
  * @return false array
  */
 protected function _generatePagesForLanguageFolder($folderPath, $language)
 {
     // Set client id
     Manager_File_Rackspace::getInstance()->setClientId($this->_currentClientId);
     $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, Manager_File_Rackspace::getInstance()->getGeneralContainer());
         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->version++;
             $_existingPage->cloud_file_container = Manager_File_Rackspace::getInstance()->getGeneralContainer();
             $_existingPage->save();
         }
         // Copy to a path
         $_pageStorageFolder = $this->getClientFolderPath($this->_currentClientId) . self::PS . parent::getPageFolderName($_pageId);
         // Cleanup first
         Manager_File_Rackspace::getInstance()->deletePeudoFolder($_pageStorageFolder);
         // Store
         Functions_File::recurse_copy_cloud($_pageFolder, $_pageStorageFolder . self::PS . $_pageId);
         // Check whether successfully
         $pages[] = $_id;
         // In case we upload a thumb image, use it.
         $page = new Object_Page($_id);
         $page->useStaticThumb();
     }
     $dir->close();
     return $pages;
 }