Example #1
0
/**
 * Requires (includes) a file at the given path, only if it exists 
 * @param string $path The file path
 * @return boolean Returns true if the file was found
 */
function RequireIfExists($path)
{
    if (File::Exists($path)) {
        require $path;
        return true;
    }
    return false;
}
Example #2
0
 /**
  * Gets the current status
  * @return \stdClass Returns an object with progress, progressCount and optional progressDescription
  */
 function GetStatus()
 {
     if (IO\File::Exists($this->targetFile)) {
         $json = IO\File::GetContents($this->targetFile);
         return json_decode($json);
     }
     return null;
 }
Example #3
0
 protected function BeforeRemove(Layout $layout)
 {
     $layoutFile = PathUtil::LayoutTemplate($layout);
     if (File::Exists($layoutFile)) {
         File::Delete($layoutFile);
     }
     $logger = new Logger(self::Guard()->GetUser());
     $logger->ReportLayoutAction($layout, Action::Delete());
 }
Example #4
0
 /**
  * Renders a block by name
  * @param string $block
  * @return string
  */
 public function RenderBlock($block)
 {
     $templateFile = $this->BuiltInTemplateFile();
     $blockFile = Path::AddExtension($templateFile, $block, true);
     $blockFileExt = Path::AddExtension($blockFile, 'phtml');
     if (!File::Exists($blockFileExt)) {
         return '';
     }
     ob_start();
     require $blockFileExt;
     return ob_get_clean();
 }
Example #5
0
 function RenderEndScript()
 {
     $templateDir = Path::Combine(__DIR__, 'Templates');
     $templateFile = Path::FilenameNoExtension($this->ClassFile()) . '.endscript.phtml';
     $template = Path::Combine($templateDir, $templateFile);
     if (File::Exists($template)) {
         ob_start();
         require $template;
         return ob_get_clean();
     }
     return '';
 }
Example #6
0
 /**
  * Remove htaccess page commands before page is deleted
  */
 protected function BeforeDelete()
 {
     foreach (self::$deleteHooks as $hook) {
         $hook->BeforeDelete($this->item);
     }
     $logger = new Logger(BackendModule::Guard()->GetUser());
     $logger->ReportPageAction($this->item, Action::Delete());
     $file = Path::Combine(PHINE_PATH, 'Public/.htaccess');
     if (!File::Exists($file)) {
         return;
     }
     $this->UpdateHtaccess($file);
 }
 protected function BeforeInit()
 {
     $this->layout = Layout::Schema()->ByID(Request::GetData('layout'));
     if (!$this->layout) {
         //TODO: Message
         Response::Redirect($this->BackLink());
     }
     $this->file = PathUtil::LayoutTemplate($this->layout);
     if (!File::Exists($this->file)) {
         //TODO: Message
         Response::Redirect($this->BackLink());
     }
     $this->contents = File::GetContents($this->file);
     return parent::BeforeInit();
 }
Example #8
0
 /**
  * Calculates if the cache content needs to be used
  * @return boolean
  */
 function MustUseCache()
 {
     if ($this->cacheLifetime == 0) {
         return false;
     }
     if (!File::Exists($this->file)) {
         return false;
     }
     $now = Date::Now();
     $lastMod = File::GetLastModified($this->file);
     if ($now->TimeStamp() - $lastMod->TimeStamp() < $this->cacheLifetime) {
         return true;
     }
     return false;
 }
Example #9
0
 /**
  * Loads backend translations of the bundle
  */
 private function LoadFrontendTranslations(Site $site)
 {
     $language = $site->GetLanguage()->GetCode();
     $frontendTranslations = PathUtil::FrontendBundleTranslationFile($this->BundleName(), $language);
     if (File::Exists($frontendTranslations)) {
         require_once $frontendTranslations;
     }
 }
Example #10
0
 /**
  * Saves the template into the given file name
  */
 protected function OnSuccess()
 {
     $newTemplate = $this->Value('Name');
     $action = Action::Create();
     if ($this->template) {
         $action = Action::Update();
         $this->UpdateUsages($newTemplate);
         $oldFile = $this->CalcFile($this->template);
         if (File::Exists($oldFile)) {
             File::Delete($oldFile);
         }
     }
     $logger = new Logger(self::Guard()->GetUser());
     $logger->ReportTemplateAction($this->module->MyType(), $newTemplate, $action);
     if (!Folder::Exists($this->folder)) {
         Folder::Create($this->folder);
     }
     File::CreateWithText($this->CalcFile($newTemplate), $this->Value('Contents', false));
     Response::Redirect($this->BackLink());
 }
Example #11
0
 private function RemoveTemplate()
 {
     $id = Request::PostData('delete');
     if (!$id) {
         return false;
     }
     $idParts = \explode('/', $id);
     $module = $this->RemovalTemplateModule($idParts);
     $templateName = trim($idParts[1]);
     if (!$module || !$templateName) {
         return false;
     }
     $logger = new Logger(self::Guard()->GetUser());
     $logger->ReportTemplateAction($module->MyType(), $templateName, Action::Delete());
     $folder = PathUtil::ModuleCustomTemplatesFolder($module);
     $template = Path::Combine($folder, Path::AddExtension($templateName, 'phtml'));
     if (File::Exists($template)) {
         File::Delete($template);
     }
     $this->DeleteUsages($module, $templateName);
     return true;
 }
Example #12
0
 /**
  * Adds necessary rewrite commands
  */
 private function AdjustHtaccess()
 {
     $file = Path::Combine(PHINE_PATH, 'Public/.htaccess');
     if (!File::Exists($file)) {
         return;
     }
     $writer = new Writer();
     $rewriter = new Rewriter($writer);
     $text = File::GetContents($file);
     $startPos = strpos($text, (string) $rewriter->PageStartComment($this->page));
     $endPos = false;
     $pageFound = false;
     if ($startPos === false) {
         $startPos = strpos($text, (string) $rewriter->EndComment());
         $endPos = $startPos;
     } else {
         $endPos = strpos($text, (string) $rewriter->PageEndComment($this->page));
         if ($endPos !== false) {
             $pageFound = true;
             $endPos += strlen((string) $rewriter->PageEndComment($this->page));
         }
     }
     if ($startPos === false || $endPos === false) {
         return;
     }
     $rewriter->AddPageCommands($this->page);
     $newText = substr($text, 0, $startPos) . $writer->ToString() . substr($text, $endPos);
     File::CreateWithText($file, $newText);
 }
Example #13
0
 /**
  * True if cache file contents must be used
  * @param strinh $cacheFile The cache file
  * @return boolean
  */
 private function MustUseCache($cacheFile)
 {
     $seconds = $this->content->GetCacheLifetime();
     if ($seconds == 0) {
         return false;
     }
     if (!File::Exists($cacheFile)) {
         return false;
     }
     $now = Date::Now();
     $lastMod = File::GetLastModified($cacheFile);
     if ($now->TimeStamp() - $lastMod->TimeStamp() < $seconds) {
         return true;
     }
     return false;
 }