Example #1
0
 private function createNewFolder()
 {
     try {
         // Create the folder in both the sandbox AND the publishing locations --
         mkdir(File::getUserSandboxPath() . $this->pageState['newFolderName'], 0775);
         mkdir(File::getUserPublishingPath() . $this->pageState['newFolderName'], 0775);
         // Navigate to the welcome page
         header('Location:/manage/welcome');
     } catch (Exception $e) {
         $errors[] = 'Cannot create folder. Do you already have a folder with this name?';
         $this->view->errors = $errors;
         $this->get();
     }
 }
Example #2
0
 private function getPublished()
 {
     $path = File::getUserPublishingPath();
     $published = array();
     // Loop through all the .html files in the published folder
     foreach (scandir($path) as $file) {
         // We only want to show the files that the user can edit (html files)
         if (File::fileExtension($file) == "html") {
             $published[] = array("name" => urlencode(File::fileName($file)), "path" => $_SESSION['cwd'] . '/' . $file);
         }
     }
     return $published;
 }
Example #3
0
 public function save()
 {
     // Grab the HTML block from the page editor
     $fileName = $this->pageState['fileName'];
     $htmlBlock = stripslashes($this->pageState['pageEditor']);
     // Determine if the page is already published
     $isPublished = false;
     $fileExt = '.html';
     if ($this->pageState['publish'] == '1') {
         $isPublished = true;
         $fileExt = '.published';
     }
     // Save to the Sandbox file
     file_put_contents(File::getUserSandboxPath() . $fileName . $fileExt, $htmlBlock);
     // Load up existing page metadata information (if it exists)
     $handle = @fopen(File::getUserSandboxPath() . $currentPageName . '.config', "r");
     if ($handle) {
         // Read the title
         if (!feof($handle)) {
             $a = explode("|", fgets($handle));
             $pageTitle = $a[1];
         }
         // Read the description
         if (!feof($handle)) {
             $a = explode("|", fgets($handle));
             $pageDescription = $a[1];
         }
         // Read the keywords
         if (!feof($handle)) {
             $a = explode("|", fgets($handle));
             $pageKeywords = $a[1];
         }
         fclose($handle);
     }
     // Grab the page metadata that the user entered
     // Page title
     $pageTitle = stripslashes($this->pageState['pageTitle']);
     if ($_SESSION['editorMode'] != 'BASIC') {
         // Grab the metatag information
         $pageDescription = stripslashes($this->pageState['pageDescription']);
         $pageKeywords = stripslashes($this->pageState['pageKeywords']);
     }
     // Assemble the metadata into a string
     $pageMetadata = "PAGE_TITLE|" . $pageTitle . "\n";
     $pageMetadata .= "PAGE_DESCRIPTION|" . $pageDescription . "\n";
     $pageMetadata .= "PAGE_KEYWORDS|" . $pageKeywords . "\n";
     // Store the page metadata in the config file (creating one if it doesn't exist)
     file_put_contents(File::getUserSandboxPath() . $fileName . '.config', $pageMetadata);
     // If the page has already been published, then run it through the publishing steps
     if ($isPublished) {
         // Load up the page template data
         $templatePageData = file_get_contents(Constants::$ROOT_DIR . 'templates/site/pageTemplate.html');
         // Place the data in the template and write the new file to the live site
         $publishedPageContent = str_replace('[[PAGE_CONTENT]]', $htmlBlock, $templatePageData);
         $publishedPageContent = str_replace('[[PAGE_TITLE]]', $pageTitle, $publishedPageContent);
         $publishedPageContent = str_replace('[[PAGE_DESCRIPTION]]', $pageDescription, $publishedPageContent);
         $publishedPageContent = str_replace('[[PAGE_KEYWORDS]]', $pageKeywords, $publishedPageContent);
         file_put_contents(File::getUserPublishingPath() . $fileName . '.html', $publishedPageContent);
     }
     // Then return to the Welcome page
     header("Location:/manage/welcome");
 }
 private function createNewTemplatePage()
 {
     // Load up the template
     $templateHTML = file_get_contents(Constants::$ROOT_DIR . 'templates/sandbox/' . $this->pageState['templateName'] . '.html');
     // Open the config file for the current template
     $handle = @fopen(Constants::$ROOT_DIR . 'templates/sandbox/' . $this->pageState['templateName'] . '.config', "r");
     if ($handle) {
         // Loop through the fields, replacing the tokens in the template with the user-provided data
         while (!feof($handle)) {
             // Read a line describing a template field
             $templateLine = fgets($handle);
             // Parse it out
             $fieldDefinition = explode("|", $templateLine);
             // Generate HTML to request that information
             $fieldName = $fieldDefinition[0];
             // Replace the token with the user data
             $templateHTML = str_replace("[[" . $fieldName . "]]", $this->pageState[$fieldName], $templateHTML);
         }
         // Replace special "reserved" template tokens
         $templateHTML = str_replace("[[CURRENT_PUBLISH_PATH]]", File::getUserPublishingPath(), $templateHTML);
         fclose($handle);
     }
     // Save the generated page
     file_put_contents(File::getUserSandboxPath() . $this->pageState['pageName'] . '.html', $templateHTML);
     // Send the user to the editor page to edit the new page
     header("Location:/manage/editPage/get/page/" . $this->pageState['pageName']);
 }