Esempio n. 1
0
 public function validate()
 {
     // check homepage
     if (!PageSettings::pageExists($this->homepage)) {
         // make sure the specified homepage exists
         throw new SalicSettingsException("Page '{$this->homepage}' not found found in pages/", $this->file . self::fis . 'homepage');
     }
     // check displayed pages
     $externals = array_keys($this->external_links);
     foreach ($this->displayed as $page) {
         if (in_array($page, $externals)) {
             continue;
         }
         // if it is an external link, it doesn't need to exist
         if (!PageSettings::pageExists($page)) {
             // make sure the specified page exists
             throw new SalicSettingsException("Page '{$page}' is neither in data/ nor an external_link", $this->file . self::fis . 'displayed');
         }
     }
 }
Esempio n. 2
0
 /**
  * Gets the pagelist for nav
  * - without hidden pages
  * - with title and href values generated
  *
  * eg: ['page1' => ['title' => "Page 1", 'href' => "/page1"]]
  *
  * @param $baseUrl
  * @param $lang
  * @return array
  * @throws SalicSettingsException
  */
 public static function getNavPageList($baseUrl, $lang)
 {
     $navSettings = NavSettings::get();
     $nav_array = array();
     $pages = $navSettings->displayed;
     $external = $navSettings->external_links;
     foreach ($pages as $key) {
         $title = PageSettings::get($key)->title->get($lang);
         //TODO: what to do about titles for external pages
         $href = array_key_exists($key, $external) ? $external[$key] : $baseUrl . $key . "/";
         $nav_array[$key] = array('key' => $key, 'title' => $title, 'href' => $href);
     }
     return $nav_array;
 }
Esempio n. 3
0
 /**
  * Load the content for $area
  *
  * @param string $area - the area name
  * @param string $pagekey
  * @return string - the html content
  * @throws SalicException - if it fails
  */
 private function loadArea($area, $pagekey)
 {
     if (!is_dir("site/data/{$pagekey}")) {
         throw new SalicException("No data for page '{$pagekey}'");
     }
     $blocks = Settings\PageSettings::get($pagekey)->areas[$area];
     $rendered = "";
     // fetch all blocks for this area
     foreach ($blocks as $block) {
         $pageDir = "site/data/{$pagekey}/";
         //$area" . "_" . $block['key'] . "_" . $this->current_lang . self::dataFileExtension;
         $salicName = $area . "_" . $block['key'];
         $rendered .= $this->loadBlock($pageDir, $block, $salicName);
     }
     return $rendered;
 }
Esempio n. 4
0
 /**
  * Load the value for $var, or throws an exception
  * if it fails AND $default is not set.
  *
  * @param string $var
  * @param $defaultVal
  * @param string $pagekey
  * @return mixed The value
  */
 public function loadVar($var, $defaultVal, $pagekey)
 {
     $pageVars = PageSettings::get($pagekey)->variables;
     if (array_key_exists($var, $pageVars)) {
         return $pageVars[$var];
     } else {
         return $defaultVal;
     }
 }
Esempio n. 5
0
require_once 'Salic.php';
if (!Utils::validAuthentication()) {
    exit;
    // Utils should call exit(), but just to be sure...
}
// TODO: ? backend language support
$salic = new SalicMng(LangSettings::get()->default);
$salic->initTwig();
try {
    $section = @$_GET['section'];
    if (empty($section)) {
        // no section selected
        $salic->renderBackendPage('@salic/backend.html.twig');
        exit;
    }
    if ($section == 'nav') {
        $salic->renderBackendPage('@salic/backend_nav.html.twig', array('navSettings' => NavSettings::get(), 'available_pages' => PageSettings::listAvailablePages()));
        exit;
    } else {
        if ($section == 'pages') {
            if (empty($_GET['page'])) {
                $salic->renderBackendPage('@salic/backend_pages.html.twig', array());
            }
        } else {
            throw new \Exception("Invalid section: '{$section}'");
        }
    }
} catch (\Exception $e) {
    Utils::dieWithError($e, 'Rendering backend', $salic);
    exit;
}
Esempio n. 6
0
 public function doSavePage($pagekey, array $regions)
 {
     foreach ($regions as $key => $val) {
         $page_dir = "site/data/{$pagekey}/";
         if (!is_dir($page_dir)) {
             if (!mkdir($page_dir, 0750, true)) {
                 // rwxr-x---, TODO: configurable directory permissions
                 throw new \Exception("Failed to create directory '{$page_dir}'");
             }
         }
         $pageSettings = PageSettings::get($pagekey);
         $blockSettings = BlockSettings::get();
         $templateSettings = TemplateSettings::data2($pageSettings->template);
         // possible key formats:
         // - '_field'
         // - 'area_block'
         // - 'area_block.subblock'
         if ($key[0] === '_') {
             // we have a field
             if (preg_match('/^_([a-z0-9-]+)$/', $key, $matches) !== 1) {
                 // matches 'area-name_block-name'
                 throw new SalicApiException("Invalid field-key format: '{$key}'");
             }
             $fieldKey = $matches[1];
             if ($fieldKey && !in_array($fieldKey, $templateSettings->fields)) {
                 throw new SalicApiException("Invalid field: '{$fieldKey}'", $templateSettings->fields);
             }
             // save as '_field-key_lang.ext'
             $filename = '_' . $fieldKey . '_' . $this->current_lang . self::dataFileExtension;
         } else {
             // we have a block
             if (preg_match('/^([a-z0-9-]+)_([a-z0-9-]+)(?:\\.([a-z0-9-]+))?$/', $key, $matches) !== 1) {
                 // matches 'area-name_block-name' or 'area_block.sub-block'
                 throw new SalicApiException("Invalid block-key format: '{$key}'");
             }
             $areaKey = $matches[1];
             $blockKey = $matches[2];
             $subblock = @$matches[3];
             // subblock is optional
             if (!array_key_exists($areaKey, $pageSettings->areas)) {
                 throw new SalicApiException("Invalid area: '{$areaKey}'", $pageSettings->areas);
             }
             if (($myBlock = PageSettings::getBlock($pageSettings->areas[$areaKey], $blockKey)) == null) {
                 throw new SalicApiException("Invalid block: '{$blockKey}'", $pageSettings->areas[$areaKey]);
             }
             $blockType = $blockSettings->data($myBlock['type']);
             if ($subblock) {
                 if ($blockType->subblocks === true ? !is_numeric($subblock) : !in_array($subblock, $blockType->subblocks)) {
                     throw new SalicApiException("Invalid subblock: '{$subblock}'[type={$myBlock['type']}]", $blockType->subblocks);
                 }
             }
             if (!$blockType->editable) {
                 throw new SalicApiException("Block not editable: '{$blockKey}'[type={$myBlock['type']}]");
             }
             // save as 'area_block/subblock_lang.ext'
             if (!$subblock) {
                 $filename = $areaKey . '_' . $blockKey . '_' . $this->current_lang . self::dataFileExtension;
             } else {
                 Utils::mkdirs($page_dir . $areaKey . '_' . $blockKey);
                 $filename = $areaKey . '_' . $blockKey . '/' . $subblock . '_' . $this->current_lang . self::dataFileExtension;
             }
         }
         $flag = file_put_contents($page_dir . $filename, $val, LOCK_EX);
         // lock the file exclusively while writing
         if ($flag === false) {
             throw new \Exception("Failed to write file '{$page_dir}{$filename}" . self::dataFileExtension . "'");
         }
         //TODO: set file permissions
     }
 }