protected function OnSuccess()
 {
     File::CreateWithText($this->file, $this->Value('Contents', false));
     $logger = new Logger(self::Guard()->GetUser());
     $logger->ReportLayoutAction($this->layout, Action::Update());
     Response::Redirect($this->BackLink());
 }
 function Parse($file)
 {
     $contents = File::GetContents($file);
     foreach ($this->replacements as $placeholder => $text) {
         $contents = String::Replace($this->phStart . $placeholder . $this->phEnd, $text, $contents);
     }
     return $contents;
 }
Example #3
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 #4
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 #5
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 #6
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 #7
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 #8
0
 private function UpdateHtaccess($file)
 {
     $rewriter = new Rewriter(new Writer());
     $text = File::GetContents($file);
     $startPos = strpos($text, (string) $rewriter->PageStartComment($this->item));
     $endPos = false;
     if ($startPos !== false) {
         $endPos = strpos($text, (string) $rewriter->PageEndComment($this->item));
         if ($endPos !== false) {
             $endPos += strlen((string) $rewriter->PageEndComment($this->item));
         }
     }
     if ($startPos === false || $endPos === false) {
         return;
     }
     $newText = substr($text, 0, $startPos) . substr($text, $endPos);
     File::CreateWithText($file, $newText);
 }
 /**
  * Executes all necessary scripts in the engine folder
  * @param  string $engineFolder The folder
  * @throws \Exception Raises error if any of the scripts fail
  */
 private function ExecuteScripts($engineFolder)
 {
     $files = $this->SortFilesByVersion(Folder::GetFiles($engineFolder));
     $completeSql = '';
     foreach ($files as $file) {
         $sqlFile = Path::Combine($engineFolder, $file);
         $completeSql .= "\r\n" . File::GetContents($sqlFile);
     }
     try {
         $this->CleanAllForeignKeys();
         //$this->connection->StartTransaction();
         $this->connection->ExecuteMultiQuery($completeSql);
     } catch (\Exception $exc) {
         //$this->connection->RollBack();
         throw $exc;
         //throw new \Exception("Error executing SQL in folder $engineFolder: " . $completeSql, null, $exc);
     }
     //$this->connection->Commit();
 }
Example #10
0
 /**
  * 
  * @param string $filename
  * @return Image Returns null on failure (file no image)
  */
 static function FromFile($filename)
 {
     $result = null;
     switch (File::GetMimeType($filename)) {
         case MimeType::Jpeg():
             $result = new self(@\imagecreatefromjpeg($filename));
             break;
         case MimeType::Png():
             $result = new self(@\imagecreatefrompng($filename));
             break;
         case MimeType::Gif():
             $result = new self(@\imagecreatefromgif($filename));
             break;
     }
     return $result;
 }
Example #11
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 #12
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 #13
0
 /**
  * Pulls content from the cache
  * @return string Gets the contents of the cache file
  */
 function GetFromCache()
 {
     return File::GetContents($this->file);
 }
Example #14
0
 private function InvalidMimeType()
 {
     if (count($this->mimeTypes) == 0) {
         return true;
     }
     $mimeType = IO\File::GetMimeType($this->upload->TempPath());
     return !in_array($mimeType, $this->mimeTypes);
 }
Example #15
0
 private function TemplateContent()
 {
     $areaCodes = '';
     $writer = new Writer();
     $this->InitAreas();
     $template = PathUtil::CodeTemplate($this->MyBundle(), 'Layout.phtml');
     $templateCode = File::GetContents($template);
     $indent = $this->GetIndent($templateCode, '_{areas}_');
     for ($idx = 0; $idx < count($this->areaNames); ++$idx) {
         $name = $this->areaNames[$idx];
         $writer->StartPhpInline();
         $writer->AddCommandInline('echo $this->RenderArea(\'' . $name . '\')');
         if ($idx < count($this->areaNames) - 1) {
             $writer->EndPhp();
         } else {
             $writer->EndPhpInline();
         }
         if ($idx > 0) {
             $areaCodes .= $indent;
         }
         $areaCodes .= $writer->Flush();
     }
     return str_replace('_{areas}_', $areaCodes, $templateCode);
 }
Example #16
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 #17
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;
 }
Example #18
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);
 }