/** * Returns an instance. * * Singleton pattern implementation. * * @return Manager_Page_StaticContent */ public static function getInstance() { if (null === self::$_instance) { self::$_instance = new self(); } return self::$_instance; }
/** * Generate a page manifest. * * @param integer $pageId * @return array | false */ protected function _generateManifest($pageId) { $page = new Object_Page($pageId); if (!$page->getId()) { return false; } $pageVersion = $page->getMostLatestApprovedVersionAsActive(); $version = $pageVersion ? $pageVersion->version : false; $cloudFileContainer = $pageVersion ? $pageVersion->cloud_file_container : $page->cloud_file_container; if ($cloudFileContainer) { $files = $page->getCloudFilePaths($version, $cloudFileContainer); } else { // Get the files $files = $this->_folderFilePaths($page->getStaticContentFolder() . DS . $page->page_id, $page->page_id . '.html'); } // Prepare the pdf templates $pdfTemplateRows = Repo_PagePdfTemplate::getInstance()->getPagePdfTemplates($page->getId()); $pdfTemplates = array(); if ($pdfTemplateRows && $pdfTemplateRows->count()) { foreach ($pdfTemplateRows as $_tRow) { $_template = new Object_PdfTemplate($_tRow->id); $pdfTemplates[] = array('id' => $_template->getId(), 'name' => $_template->name, 'tokens' => $_template->getTokens(), 'preview' => $_template->getManifestPreviewFilePath()); } } return array('version' => $pageVersion ? $pageVersion->version : $page->version, 'id' => $page->page_id, 'uid' => $page->id, 'legalPageUid' => (int) $page->legal_page_id > 0 ? (int) $page->legal_page_id : '', 'linkedPageUids' => $page->getManifestPageGroupPages(), 'title' => $page->name, 'fileType' => 'htmlEdge', 'type' => 'html', 'typename' => $page->type, 'baseHost' => $page->getBaseHost($cloudFileContainer), 'baseUri' => $page->getBaseUrl($version), 'hash' => Manager_Page_StaticContent::getPageFolderName($page->page_id, $version), 'instructions' => $page->description ? $page->description : '', 'description' => $page->internal_desc ? $page->internal_desc : '', 'navigation' => array(), 'language' => $page->page_language, 'defaultPath' => $page->page_id . '.html', 'width' => $page->getWidth(), 'height' => $page->getHeight(), 'transcript' => $page->transcript ? $page->transcript : '', 'audio' => $page->audio_url, 'filePaths' => $files, 'navigation' => $page->navigation ? unserialize($page->navigation) : array(), 'content_type' => $page->content_type ? Repo_Page::$contentTypeLabels[$page->content_type] : Repo_Page::$contentTypeLabels[Repo_Page::PAGE_CONTENT_TYPE_DEFAULT], 'editor_behaviors' => $page->editor_behaviors ? $page->editor_behaviors : '', 'pdf_templates' => $pdfTemplates, 'tags' => $page->getTags()); }
/** * 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; }