Exemple #1
0
 public function isInstanceof($type)
 {
     $type = fx::getComponentFullName($type);
     if ($this['type'] == $type) {
         return true;
     }
     $chain = $this->getComponent()->getChain();
     foreach ($chain as $com) {
         if ($com['keyword'] == $type) {
             return true;
         }
     }
     return false;
 }
Exemple #2
0
 public static function import($tpl_name)
 {
     $is_aliased = preg_match("~^\\@(.+)~", $tpl_name, $real_name);
     if ($is_aliased) {
         $tpl_name = $real_name[1];
     } else {
         $tpl_name = fx::getComponentFullName($tpl_name);
     }
     if (isset(self::$imported_classes[$tpl_name])) {
         return self::$imported_classes[$tpl_name];
     }
     $processor = new self();
     $processor->setTemplateName($tpl_name);
     if ($is_aliased) {
         $processor->isAliased(true);
     }
     $classname = $processor->getCompiledClassName();
     $processor->addDefaultSourceDirs();
     try {
         $processor->process();
     } catch (\Exception $e) {
         self::$imported_classes[$tpl_name] = false;
         return false;
     }
     self::$imported_classes[$tpl_name] = $classname;
     $classname::init();
     return $classname;
 }
Exemple #3
0
 public function isAvailableOnPage($page)
 {
     if ($this['site_id'] != $page['site_id']) {
         return;
     }
     if ($page->hasVirtualPath()) {
         $ids = $page->getPath()->getValues('id');
     } else {
         $ids = $page->getParentIds();
     }
     $ids[] = $page['id'];
     $ids[] = 0;
     // root
     if (!in_array($this['page_id'], $ids)) {
         return false;
     }
     // if page_id=0 blunt - all pages, ignored by the filter scope.pages
     if ($this['page_id'] != 0) {
         // scope - "this page only"
         if (fx::dig($this, 'scope.pages') == 'this' && $this['page_id'] != $page['id']) {
             return false;
         }
         // scope - "this level, and we look parent
         if (fx::dig($this, 'scope.pages') == 'children' && $this['page_id'] == $page['id']) {
             return false;
         }
     }
     // check for compliance with the filter type page
     $scope_page_type = fx::dig($this, 'scope.page_type');
     if ($scope_page_type && fx::getComponentFullName($scope_page_type) != fx::getComponentFullName($page['type'])) {
         return false;
     }
     return true;
 }
Exemple #4
0
 protected function getTemplateProps(Token $token)
 {
     $tpl_props = array();
     $com_name = $this->template_set_name;
     $tpl_id = $token->getProp('id');
     if (preg_match("~#(.+)\$~", $tpl_id, $tpl_tags)) {
         $tpl_id = preg_replace("~#.+\$~", '', $tpl_id);
         $tags = preg_split("~\\,\\s*~", $tpl_tags[1]);
         if (count($tags) > 0) {
             $tpl_props['tags'] = $tags;
         }
     }
     if (preg_match("~(^.+?)\\:(.+)~", $tpl_id, $id_parts)) {
         $external_com_name = $id_parts[1];
         $own_name = $id_parts[2];
         if ($external_com_name == $com_name) {
             $tpl_id = $own_name;
         } else {
             $tpl_props['overrides'] = $tpl_id;
             $tpl_id = str_replace(".", '_', $external_com_name) . '__' . $own_name;
         }
     }
     $tpl_props['id'] = $tpl_id;
     $tpl_props['file'] = fx::path()->http($this->current_source_file);
     $tpl_props['is_imported'] = $this->current_source_is_imported;
     $i_level = $this->current_source_import_level;
     $tpl_props['import_level'] = $i_level;
     if ($this->current_source_is_imported) {
         if (!isset($tpl_props['tags']) || !$tpl_props['tags']) {
             $tpl_props['tags'] = array();
         }
         $tpl_props['tags'][] = 'imported' . ($i_level > 0 ? $i_level : '');
     }
     if ($offset = $token->getProp('offset')) {
         $tpl_props['offset'] = $offset;
     }
     if ($size = $token->getProp('size')) {
         $tpl_props['size'] = $size;
     }
     if ($suit = $token->getProp('suit')) {
         $tpl_props['suit'] = $suit;
     }
     if ($area_id = $token->getProp('area')) {
         $tpl_props['area'] = $area_id;
     }
     if (!($name = $token->getProp('name'))) {
         $name = $token->getProp('id');
     }
     $tpl_props['full_id'] = $com_name . ':' . $tpl_props['id'];
     $of = $token->getProp('of');
     // todo: psr0 need fix
     $of_map = array('menu' => 'section:list', 'wrapper' => 'floxim.layout.wrapper:show', 'blockset' => 'blockset:show', 'grid' => 'grid:show', 'block' => 'block:show');
     $of_priority = array();
     if ($of and $of != 'false') {
         // $of is array when copied to {preset} from the extended template
         if (!is_array($of)) {
             $of_parts = explode(',', $of);
             array_walk($of_parts, function (&$v) {
                 $v = trim($v);
             });
             foreach ($of_parts as $key => $value) {
                 $value_parts = explode('#', $value);
                 if (count($value_parts) === 1) {
                     $value_prior = 1;
                 } else {
                     $value = $value_parts[0];
                     $value_prior = (int) $value_parts[1];
                 }
                 if (isset($of_map[$value])) {
                     $value = $of_map[$value];
                 }
                 $c_of = explode(":", $value);
                 // no component, e.g. fx:of="list"
                 if (count($c_of) === 1) {
                     $of_parts[$key] = fx::getComponentFullName($com_name) . ':' . $value;
                 } else {
                     $of_parts[$key] = fx::getComponentFullName($c_of[0]) . ':' . $c_of[1];
                 }
                 $of_priority[$of_parts[$key]] = $value_prior;
             }
             $of = join(',', $of_parts);
         } else {
             $of_priority = $of;
         }
     } else {
         $of = array();
     }
     $tpl_props += array('name' => $name, 'of' => $of_priority, 'is_preset_of' => $token->getProp('is_preset_of'), 'replace_original' => $token->getProp('replace_original'), 'is_abstract' => $token->getProp('is_abstract'), '_token' => $token);
     return $tpl_props;
 }